mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-09-14 04:15:06 +08:00
🐤 Sync 2026-03-30 12:52:58
This commit is contained in:
@@ -49,20 +49,22 @@ function checkProcess(quick = false) {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function controlService(action, port) {
|
||||
if (action === 'start') {
|
||||
return fs.exec('/usr/bin/killall', ['homebox'])
|
||||
.catch(function() { return Promise.resolve(); })
|
||||
.then(function() {
|
||||
var command = 'nohup /usr/bin/homebox serve --port ' + port + ' > ' + logPath + ' 2>&1 &';
|
||||
var command = '/usr/bin/homebox serve --port ' + port + ' > ' + logPath + ' 2>&1 &';
|
||||
return fs.exec('/bin/sh', ['-c', command]);
|
||||
});
|
||||
} else {
|
||||
fs.exec('/usr/bin/killall', ['homebox']);
|
||||
return fs.exec('/etc/init.d/netspeedtest', ['stop']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function saveConfiguration(newPort, enabled) {
|
||||
const uciContent = `config netspeedtest 'config'
|
||||
\toption homebox_port '${newPort}'
|
||||
@@ -174,14 +176,12 @@ return view.extend({
|
||||
}
|
||||
toggleBtn.disabled = true;
|
||||
if (state.operationType === 'stop' && !state.running) {
|
||||
console.log('Stop confirmed - operation complete');
|
||||
state.operationInProgress = false;
|
||||
state.operationType = null;
|
||||
toggleBtn.textContent = state.running ? _('Stop Server') : _('Start Server');
|
||||
toggleBtn.className = 'btn cbi-button cbi-button-' + (state.running ? 'reset' : 'apply');
|
||||
toggleBtn.disabled = false;
|
||||
} else if (state.operationType === 'start' && state.running) {
|
||||
console.log('Start confirmed - operation complete');
|
||||
state.operationInProgress = false;
|
||||
state.operationType = null;
|
||||
toggleBtn.textContent = state.running ? _('Stop Server') : _('Start Server');
|
||||
@@ -234,16 +234,13 @@ return view.extend({
|
||||
function doCheck() {
|
||||
checkProcess(true).then(function(isRunning) {
|
||||
if (action === 'stop' && !isRunning) {
|
||||
console.log('Stop success after', Date.now() - startTime, 'ms');
|
||||
resolve({ running: false });
|
||||
} else if (action === 'start' && isRunning) {
|
||||
console.log('Start success after', Date.now() - startTime, 'ms');
|
||||
checkProcess().then(resolve).catch(resolve);
|
||||
} else if (checkCount < maxChecks) {
|
||||
checkCount++;
|
||||
setTimeout(doCheck, 200);
|
||||
} else {
|
||||
console.log('Check timeout, using full check');
|
||||
|
||||
checkProcess().then(resolve).catch(resolve);
|
||||
}
|
||||
@@ -283,7 +280,6 @@ return view.extend({
|
||||
.catch(function(err) {
|
||||
console.error('Service control error:', err);
|
||||
|
||||
// 发生错误时重新检查
|
||||
checkProcess().then(function(res) {
|
||||
state.running = res.running || false;
|
||||
if (res.port) state.port = res.port;
|
||||
|
||||
@@ -21,7 +21,6 @@ async function checkProcess() {
|
||||
return { running: true, pid: res.stdout.trim() };
|
||||
}
|
||||
|
||||
// 回退检查
|
||||
const psRes = await fs.exec('/bin/ps', ['-w', '-C', 'iperf3', '-o', 'pid=']);
|
||||
const pid = psRes.stdout.trim();
|
||||
return {
|
||||
@@ -57,7 +56,6 @@ function saveConfiguration(newPort, enabled) {
|
||||
|
||||
return fs.write('/etc/config/netspeedtest', uciContent)
|
||||
.then(() => {
|
||||
// 更新开机自启
|
||||
if (enabled) {
|
||||
return fs.exec('/etc/init.d/netspeedtest', ['enable']);
|
||||
} else {
|
||||
|
||||
+20
-16
@@ -10,7 +10,7 @@
|
||||
'require ui';
|
||||
'require form';
|
||||
|
||||
var Timeout = 300 * 1000;
|
||||
var Timeout = 300 * 1000;
|
||||
var ResultFile = '/tmp/netspeedtest_result';
|
||||
var SpeedtestScript = '/usr/bin/netspeedtest.sh';
|
||||
|
||||
@@ -81,6 +81,7 @@ return view.extend({
|
||||
if (firstLine.match(/Download:/i) || firstLine.match(/Upload:/i)) {
|
||||
return { type: 'speed', data: content.join('\n') };
|
||||
}
|
||||
|
||||
var hasDownload = false;
|
||||
var hasUpload = false;
|
||||
for (var j = 0; j < content.length; j++) {
|
||||
@@ -95,6 +96,22 @@ return view.extend({
|
||||
return { type: 'unknown', data: content.join('\n') };
|
||||
},
|
||||
|
||||
startSpeedTest: function(version) {
|
||||
return fs.write(ResultFile, 'Testing\n')
|
||||
.then(function() {
|
||||
var shellCmd = SpeedtestScript;
|
||||
if (version) {
|
||||
shellCmd += ' --version ' + version;
|
||||
}
|
||||
shellCmd += ' > /dev/null 2>&1 &';
|
||||
console.log('Starting test with sh -c:', shellCmd);
|
||||
return fs.exec('/bin/ash', ['-c', shellCmd])
|
||||
.catch(function() {
|
||||
return fs.exec('/bin/sh', ['-c', shellCmd]);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
poll_status(nodes, res) {
|
||||
var result_content = res[2] ? res[2].trim().split("\n") : [];
|
||||
var result_mtime = res[3] ? res[3].mtime * 1000 : 0;
|
||||
@@ -129,7 +146,6 @@ return view.extend({
|
||||
if (!imageUrl.match(/\.png$/)) {
|
||||
imageUrl = imageUrl + '.png';
|
||||
}
|
||||
// 处理speedtest.net的特殊URL
|
||||
if (imageUrl.includes('speedtest.net/result/')) {
|
||||
imageUrl = imageUrl.replace('/result/c/', '/result/');
|
||||
}
|
||||
@@ -137,7 +153,6 @@ return view.extend({
|
||||
result_stat.innerHTML = "<div style='max-width:500px; margin-left:20px'>" +
|
||||
"<a href='" + result.data + "' target='_blank'>" +
|
||||
"<img src='" + result.data + "' style='max-width:100%; border-radius:4px; box-shadow:0 2px 4px rgba(0,0,0,0.1)' " +
|
||||
"onerror='this.onerror=null; this.src=\"/luci-static/resources/icons/error.png\"'/>" +
|
||||
"</a><br>" +
|
||||
"</div>";
|
||||
break;
|
||||
@@ -393,22 +408,11 @@ return view.extend({
|
||||
}
|
||||
var version = versionSelect ? versionSelect.value : (has_ookla ? 'ookla' : 'python');
|
||||
|
||||
return fs.write(ResultFile, 'Testing\n')
|
||||
|
||||
self.startSpeedTest(version)
|
||||
.then(function() {
|
||||
var cmd = 'nohup ' + SpeedtestScript;
|
||||
if (version) {
|
||||
cmd += ' --version ' + version;
|
||||
}
|
||||
cmd += ' > /dev/null 2>&1 &';
|
||||
|
||||
return fs.exec('/bin/sh', ['-c', cmd]);
|
||||
})
|
||||
.then(function() {
|
||||
ui.addNotification(null, E('p', _('Speed test started. Please wait...')), 'info');
|
||||
})
|
||||
.catch(function(e) {
|
||||
console.error('Failed to start test:', e);
|
||||
ui.addNotification(null, E('p', _('Failed to start speed test: ') + e.message), 'error');
|
||||
});
|
||||
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user