Skip to content

Commit

Permalink
Prevent service startup after reboot if Disable service in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
zerolabnet committed Aug 16, 2024
1 parent e407966 commit b60a32b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions rootfs/usr/share/rpcd/acl.d/luci-app-ssclash.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"/opt/clash/config.yaml": [ "write" ],
"/etc/init.d/clash start": [ "exec" ],
"/etc/init.d/clash stop": [ "exec" ],
"/etc/init.d/clash enable": [ "exec" ],
"/etc/init.d/clash disable": [ "exec" ],
"/etc/init.d/clash reload": [ "exec" ]
},
"ubus": {
Expand Down
12 changes: 9 additions & 3 deletions rootfs/www/luci-static/resources/view/ssclash/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ async function getServiceStatus() {
async function startService() {
if (startStopButton) startStopButton.disabled = true;
return fs.exec('/etc/init.d/clash', ['start'])
.then(() => fs.exec('/etc/init.d/clash', ['enable']))
.catch(function(e) {
ui.addNotification(null, E('p', _('Unable to start service: %s').format(e.message)), 'error');
ui.addNotification(null, E('p', _('Unable to start and enable service: %s').format(e.message)), 'error');
})
.finally(() => {
if (startStopButton) startStopButton.disabled = false;
Expand All @@ -36,8 +37,9 @@ async function startService() {
async function stopService() {
if (startStopButton) startStopButton.disabled = true;
return fs.exec('/etc/init.d/clash', ['stop'])
.then(() => fs.exec('/etc/init.d/clash', ['disable']))
.catch(function(e) {
ui.addNotification(null, E('p', _('Unable to stop service: %s').format(e.message)), 'error');
ui.addNotification(null, E('p', _('Unable to stop and disable service: %s').format(e.message)), 'error');
})
.finally(() => {
if (startStopButton) startStopButton.disabled = false;
Expand All @@ -58,7 +60,11 @@ async function openDashboard() {
let newWindow = window.open('', '_blank');
const running = await getServiceStatus();
if (running) {
let url = `http://${window.location.hostname}:9090/ui/?hostname=${window.location.hostname}&port=9090`;
let port = '9090';
let path = 'ui';
let protocol = window.location.protocol;
let hostname = window.location.hostname;
let url = `${protocol}//${hostname}:${port}/${path}/?hostname=${hostname}&port=${port}`;
newWindow.location.href = url;
} else {
newWindow.close();
Expand Down

0 comments on commit b60a32b

Please sign in to comment.