🌴 Sync 2026-03-05 23:51:42

This commit is contained in:
github-actions[bot] committed 2026-03-05 23:51:42 +08:00
1 parent 0d155c70be
commit 32600acc60
14258 files changed
+3954570

No files matched your search

@@ -0,0 +1,105 @@
/*
* This is open source software, licensed under the MIT License.
*
* Copyright (C) 2024 BobbyUnknown
*
* Description:
* This software provides a RAM release scheduling application for OpenWrt.
* The application allows users to configure and automate the process of
* releasing RAM on their OpenWrt router at specified intervals, helping
* to optimize system performance and resource management through a
* user-friendly web interface.
*/
'use strict';
'require form';
'require view';
'require uci';
'require ui';
'require fs';
'require tools.widgets as widgets';
return view.extend({
render: function() {
var m, s, o, footerSection;
m = new form.Map('77_syscontrol', _('RAM Release Schedule'),
_('Configure schedule for automatic RAM release.'));
s = m.section(form.NamedSection, 'schedule', 'ram_release', _('Schedule Settings'));
s.anonymous = true;
s.addremove = false;
o = s.option(form.Flag, 'enabled', _('Enable'),
_('Enable automatic RAM release schedule'));
o.rmempty = false;
o.write = function(section_id, value) {
form.Flag.prototype.write.apply(this, arguments);
return fs.exec('/etc/init.d/ram_release', [value === '1' ? 'enable' : 'disable'])
.then(function() {
return fs.exec('/etc/init.d/ram_release', [value === '1' ? 'start' : 'stop']);
});
};
o = s.option(form.DummyValue, '_status', _('Service Status'));
o.rawhtml = true;
o.load = function(section_id) {
return fs.exec('/etc/init.d/ram_release', ['status']).then(function(res) {
if (res.code === 0) {
return '<span style="color:green;font-weight:bold;">Running</span>';
} else {
return '<span style="color:red;font-weight:bold;">Stopped</span>';
}
}).catch(function(err) {
ui.addNotification(null, E('p', _('Error checking service status: ') + err.message), 'error');
return '<span style="color:gray;font-weight:bold;">Unknown</span>';
});
};
o = s.option(form.Value, 'time', _('Time'),
_('Enter time for RAM release (24-hour format, e.g. 23:30)'));
o.datatype = 'string';
o.validate = function(section_id, value) {
if (!/^([01]\d|2[0-3]):([0-5]\d)$/.test(value)) {
return _('Invalid time format. Please use HH:MM (24-hour format).');
}
return true;
};
o = s.option(form.MultiValue, 'days', _('Days'),
_('Select days for RAM release'));
o.multiple = true;
o.value('mon', _('Monday'));
o.value('tue', _('Tuesday'));
o.value('wed', _('Wednesday'));
o.value('thu', _('Thursday'));
o.value('fri', _('Friday'));
o.value('sat', _('Saturday'));
o.value('sun', _('Sunday'));
footerSection = m.section(form.NamedSection, 'footer', 'footer');
footerSection.render = function() {
return E('div', { 'style': 'text-align: center; padding: 10px; font-style: italic;' }, [
E('span', {}, [
_('© Dibuat oleh '),
E('a', {
'href': 'https://github.com/bobbyunknow',
'target': '_blank',
'style': 'text-decoration: none;'
}, 'BobbyUnknown')
])
]);
};
return m.render().then(function(rendered) {
console.log('Form rendered:', rendered);
console.log('Enabled:', uci.get('77_syscontrol', 'schedule', 'enabled'));
console.log('Time:', uci.get('77_syscontrol', 'schedule', 'time'));
console.log('Days:', uci.get('77_syscontrol', 'schedule', 'days'));
return rendered;
}).catch(function(err) {
console.error('Error rendering form:', err);
ui.addNotification(null, E('p', _('Error loading configuration: ' + err.message)), 'error');
});
}
});
@@ -0,0 +1,98 @@
/*
* This is open source software, licensed under the MIT License.
*
* Copyright (C) 2024 BobbyUnknown
*
* Description:
* This software provides a RAM release scheduling application for OpenWrt.
* The application allows users to configure and automate the process of
* releasing RAM on their OpenWrt router at specified intervals, helping
* to optimize system performance and resource management through a
* user-friendly web interface.
*/
'use strict';
'require view';
'require fs';
'require ui';
'require poll';
return view.extend({
handleSaveApply: null,
handleSave: null,
handleReset: null,
loadLog: function() {
return fs.read('/var/log/ram_release.log')
.then(function(log) {
return log.trim() || _('No log entries found');
})
.catch(function(err) {
console.error('Error reading log:', err);
return _('Error reading log file or file is empty');
});
},
createDefaultLog: function() {
var defaultMessage = 'No log found';
return fs.write('/var/log/ram_release.log', defaultMessage + '\n')
.then(function() {
return defaultMessage;
})
.catch(function(err) {
console.error('Error creating default log:', err);
return 'Error: Unable to initialize log file';
});
},
render: function() {
var logContainer = E('div', { 'class': 'cbi-section' });
var updateLog = function() {
this.loadLog().then(function(log) {
logContainer.innerHTML = '<pre style="white-space: pre-wrap; word-wrap: break-word;">' + log + '</pre>';
});
}.bind(this);
updateLog();
poll.add(updateLog, 5);
return E('div', { 'class': 'cbi-map' }, [
E('h2', _('RAM Release Log')),
logContainer,
E('div', { 'class': 'cbi-section-actions' }, [
E('button', {
'class': 'btn cbi-button cbi-button-remove',
'click': ui.createHandlerFn(this, function(ev) {
var button = ev.target;
button.disabled = true;
button.textContent = _('Clearing...');
return fs.write('/var/log/ram_release.log', 'Log cleared\n')
.then(function() {
updateLog();
})
.catch(function(err) {
console.error('Error clearing log:', err);
})
.finally(function() {
button.disabled = false;
button.textContent = _('Clear Log');
});
})
}, _('Clear Log'))
]),
E('div', { 'style': 'text-align: center; padding: 10px; font-style: italic;' }, [
E('span', {}, [
_('© Dibuat oleh '),
E('a', {
'href': 'https://github.com/bobbyunknow',
'target': '_blank',
'style': 'text-decoration: none;'
}, 'BobbyUnknown')
])
])
]);
}
});
@@ -0,0 +1,122 @@
/*
* This is open source software, licensed under the MIT License.
*
* Copyright (C) 2024 BobbyUnknown
*
* Description:
* This software provides a RAM release scheduling application for OpenWrt.
* The application allows users to configure and automate the process of
* releasing RAM on their OpenWrt router at specified intervals, helping
* to optimize system performance and resource management through a
* user-friendly web interface.
*/
'use strict';
'require view';
'require ui';
'require rpc';
'require poll';
var callSystemInfo = rpc.declare({
object: 'system',
method: 'info'
});
return view.extend({
load: function() {
console.log('Load function called');
return callSystemInfo().then(function(data) {
console.log('RAM information loaded:', JSON.stringify(data.memory));
return {
memory: data.memory
};
}).catch(function(error) {
console.error('Error loading RAM information:', error);
throw error;
});
},
updateMemoryStatus: function(memory) {
console.log('Updating memory status with:', memory);
if (!memory) {
console.error('Memory information is missing');
return;
}
var totalMB = Math.round(memory.total / 1024 / 1024);
var freeMB = Math.round(memory.free / 1024 / 1024);
var cachedMB = Math.round(memory.cached / 1024 / 1024);
var usedMB = totalMB - freeMB - cachedMB;
var usedPercent = Math.round((usedMB / totalMB) * 100);
var memoryStatusElement = document.getElementById('memory-status');
if (memoryStatusElement) {
memoryStatusElement.innerHTML = '';
memoryStatusElement.appendChild(
E('div', { 'class': 'table' }, [
E('div', { 'class': 'tr' }, [
E('div', { 'class': 'td left' }, _('Total RAM:')),
E('div', { 'class': 'td left' }, totalMB + ' MB')
]),
E('div', { 'class': 'tr' }, [
E('div', { 'class': 'td left' }, _('Used RAM:')),
E('div', { 'class': 'td left' }, usedMB + ' MB (' + usedPercent + '%)')
]),
E('div', { 'class': 'tr' }, [
E('div', { 'class': 'td left' }, _('Cached RAM:')),
E('div', { 'class': 'td left' }, cachedMB + ' MB')
]),
E('div', { 'class': 'tr' }, [
E('div', { 'class': 'td left' }, _('Free RAM:')),
E('div', { 'class': 'td left' }, freeMB + ' MB')
])
])
);
} else {
console.error('Memory status element not found');
}
},
render: function(data) {
console.log('Render function called with:', JSON.stringify(data));
var view = E('div', { 'class': 'cbi-map' }, [
E('h2', _('RAM Status')),
E('div', { 'class': 'cbi-section' }, [
E('div', { 'id': 'memory-status' })
]),
E('div', { 'style': 'text-align: center; padding: 10px; font-style: italic;' }, [
E('span', {}, [
_('© Dibuat oleh '),
E('a', {
'href': 'https://github.com/bobbyunknow',
'target': '_blank',
'style': 'text-decoration: none;'
}, 'BobbyUnknown')
])
])
]);
requestAnimationFrame(L.bind(function() {
this.updateMemoryStatus(data.memory);
}, this));
return view;
},
handleSaveApply: null,
handleSave: null,
handleReset: null,
poll: {
interval: 5,
task: function() {
console.log('Polling task running');
return callSystemInfo().then(L.bind(function(data) {
console.log('Polling task received RAM information:', JSON.stringify(data.memory));
this.updateMemoryStatus(data.memory);
}, this)).catch(function(error) {
console.error('Error in polling task:', error);
});
}
}
});
@@ -0,0 +1,130 @@
/*
* This is open source software, licensed under the MIT License.
*
* Copyright (C) 2024 BobbyUnknown
*
* Description:
* This software provides a RAM release scheduling application for OpenWrt.
* The application allows users to configure and automate the process of
* releasing RAM on their OpenWrt router at specified intervals, helping
* to optimize system performance and resource management through a
* user-friendly web interface.
*/
'use strict';
'require view';
'require rpc';
'require ui';
'require uci';
var callReboot = rpc.declare({
object: 'system',
method: 'reboot',
expect: { result: 0 }
});
var callForceReboot = rpc.declare({
object: 'system',
method: 'reboot',
params: [ '-f' ],
expect: { result: 0 }
});
return view.extend({
load: function() {
return uci.changes();
},
render: function(changes) {
var body = E([
E('h2', _('System reboot')),
E('p', {}, _('Reboots the operating system of your device'))
]);
for (var config in (changes || {})) {
body.appendChild(E('p', { 'class': 'alert-message warning' },
_('Warning: There are unsaved changes that will get lost on reboot!')));
break;
}
body.appendChild(E('hr'));
body.appendChild(E('button', {
'class': 'cbi-button cbi-button-action important',
'click': ui.createHandlerFn(this, 'handleReboot', false)
}, _('Normal Reboot')));
body.appendChild(E('button', {
'class': 'cbi-button cbi-button-negative important',
'click': ui.createHandlerFn(this, 'handleReboot', true)
}, _('Force Reboot')));
body.appendChild(E('div', { 'style': 'text-align: center; padding: 10px; font-style: italic;' }, [
E('span', {}, [
_('© Dibuat oleh '),
E('a', {
'href': 'https://github.com/bobbyunknow',
'target': '_blank',
'style': 'text-decoration: none;'
}, 'BobbyUnknown')
])
]));
return body;
},
handleReboot: function(ev, force) {
var rebootCall = force ? callForceReboot : callReboot;
var rebootType = force ? _('Force Reboot') : _('Normal Reboot');
ui.showModal(_('Confirm Reboot'), [
E('h4', { style: 'color: #d9534f; text-align: center;' }, _('Are you absolutely sure you want to reboot the system?')),
E('p', { style: 'text-align: center;' }, _('This will restart your device. All running processes will be stopped.')),
E('div', { class: 'right' }, [
E('button', {
'class': 'btn',
'click': ui.hideModal
}, _('Cancel')),
' ',
E('button', {
'class': 'btn btn-danger',
'click': ui.createHandlerFn(this, function() {
ui.hideModal();
return rebootCall().then(function(res) {
if (res != 0) {
ui.addNotification(null, E('p', _('The reboot command failed with code %d').format(res)));
throw new Error('Reboot failed');
}
ui.showModal(_('Rebooting…'), [
E('p', { 'class': 'spinning' }, _('Waiting for device...'))
]);
var checkInterval = window.setInterval(function() {
fetch(window.location.href, { method: 'HEAD', cache: 'no-cache' })
.then(function() {
window.clearInterval(checkInterval);
window.location.reload();
})
.catch(function() {});
}, 5000);
window.setTimeout(function() {
ui.showModal(_('Rebooting…'), [
E('p', { 'class': 'spinning alert-message warning' },
_('Device unreachable! Still waiting for device...'))
]);
}, 150000);
}).catch(function(e) {
ui.addNotification(null, E('p', e.message));
});
})
}, rebootType)
])
]);
},
handleSaveApply: null,
handleSave: null,
handleReset: null
});
@@ -0,0 +1,35 @@
/*
* This is open source software, licensed under the MIT License.
*
* Copyright (C) 2024 BobbyUnknown
*
* Description:
* This software provides a RAM release scheduling application for OpenWrt.
* The application allows users to configure and automate the process of
* releasing RAM on their OpenWrt router at specified intervals, helping
* to optimize system performance and resource management through a
* user-friendly web interface.
*/
'use strict';
'require fs';
'require view';
return view.extend({
handleSaveApply: null,
handleSave: null,
handleReset: null,
load: function() {
fs.exec('/usr/bin/ram_release.sh', ['release']);
return null;
},
render: function() {
window.location.href = '/cgi-bin/luci/admin/system/syscontrol';
return E('div');
}
});
@@ -0,0 +1,75 @@
/*
* This is open source software, licensed under the MIT License.
*
* Copyright (C) 2024 BobbyUnknown
*
* Description:
* This software provides a RAM release scheduling application for OpenWrt.
* The application allows users to configure and automate the process of
* releasing RAM on their OpenWrt router at specified intervals, helping
* to optimize system performance and resource management through a
* user-friendly web interface.
*/
'use strict';
'require view';
'require ui';
'require fs';
return view.extend({
render: function() {
return E('div', { class: 'cbi-map' }, [
E('h2', _('System shutdown')),
E('div', { class: 'cbi-section' }, [
E('p', _('Shutting down the system will power off your device. Make sure all important processes are completed before proceeding.')),
E('div', { class: 'cbi-section-actions' }, [
E('button', {
class: 'btn cbi-button cbi-button-negative',
click: ui.createHandlerFn(this, 'handleShutdown')
}, _('Shutdown System'))
])
]),
E('div', { 'style': 'text-align: center; padding: 10px; font-style: italic;' }, [
E('span', {}, [
_('© Dibuat oleh '),
E('a', {
'href': 'https://github.com/bobbyunknow',
'target': '_blank',
'style': 'text-decoration: none;'
}, 'BobbyUnknown')
])
])
]);
},
handleShutdown: function() {
return ui.showModal(_('Confirm Shutdown'), [
E('h4', { style: 'color: #d9534f; text-align: center;' }, _('Are you absolutely sure you want to shut down the system?')),
E('p', { style: 'text-align: center;' }, _('This will power off your device. All running processes will be stopped.')),
E('div', { class: 'right' }, [
E('button', {
'class': 'btn',
'click': ui.hideModal
}, _('Cancel')),
' ',
E('button', {
'class': 'btn btn-danger',
'click': ui.createHandlerFn(this, function() {
ui.hideModal();
ui.showModal(_('Shutting down...'), [
E('p', { 'class': 'spinning' }, _('The system is shutting down. GoodBye :)...'))
]);
return fs.exec('/sbin/poweroff').catch(function(e) {
ui.addNotification(null, E('p', e.message));
});
})
}, _('Shutdown'))
])
]);
},
handleSaveApply: null,
handleSave: null,
handleReset: null
});