luci-app-sqm: fix JS error if service is disabled
authorDirk Brenken <dev@brenken.org>
Sat, 5 Jun 2021 07:43:46 +0000 (09:43 +0200)
committerJo-Philipp Wich <jo@mein.io>
Wed, 7 Jul 2021 15:20:09 +0000 (17:20 +0200)
* fix a 'resource not found error' if the sqm service has been disabled
  and the dir '/var/run/sqm/available_qdiscs' not exist
* inform the user about this issue and provide a button
  to enable & start the service

Signed-off-by: Dirk Brenken <dev@brenken.org>
(cherry picked from commit e76d9cc7673ffbebd8887bcfc14542c1269288e0)

applications/luci-app-sqm/htdocs/luci-static/resources/view/network/sqm.js
applications/luci-app-sqm/root/usr/share/rpcd/acl.d/luci-app-sqm.json

index 337911ac5e6e082f53c967bd1f81d9366d4cdcb6..d115ca973b61dacdcd15107af1fabc22cec39d02 100644 (file)
@@ -1,5 +1,6 @@
 'use strict';
 'require fs';
+'require ui';
 'require rpc';
 'require uci';
 'require view';
@@ -23,8 +24,8 @@ return view.extend({
 
        load: function() {
                return Promise.all([
-                       fs.list("/var/run/sqm/available_qdiscs"),
-                       fs.list("/usr/lib/sqm").then(L.bind(function(scripts) {
+                       L.resolveDefault(fs.list('/var/run/sqm/available_qdiscs'), []),
+                       L.resolveDefault(fs.list('/usr/lib/sqm'), []).then(L.bind(function(scripts) {
                                var tasks = [], scriptHelpTbl = {};
 
                                for (var i = 0; i < scripts.length; i++)
@@ -41,6 +42,21 @@ return view.extend({
                var qdiscs = data[0],
                    scripts = data[1];
 
+               if (qdiscs.length === 0) {
+                       ui.addNotification(null, 
+                               E('div', { 'class': 'left' }, [
+                               E('p', _("The SQM service seems to be disabled. Please use the button below to activate this service.")),
+                               E('button', {
+                                       'class': 'btn cbi-button-active',
+                                       'click': ui.createHandlerFn(this, function() {
+                                               fs.exec_direct('/etc/init.d/sqm', ['enable']);
+                                               fs.exec_direct('/etc/init.d/sqm', ['start']);
+                                               location.reload();
+                                       })
+                               }, _('Enable SQM'))
+                       ]));
+               }
+
                var m, s, o;
 
                m = new form.Map('sqm', _('Smart Queue Management'));
@@ -62,7 +78,7 @@ return view.extend({
                o.write = L.bind(function(section, value) {
                        if (value == "1") {
                                this.handleEnableSQM();
-                               L.ui.addNotification(null, E('p', _("The SQM GUI has just enabled the sqm initscript on your behalf. Remember to disable the sqm initscript manually under System Startup menu in case this change was not wished for.")));
+                               ui.addNotification(null, E('p', _("The SQM GUI has just enabled the sqm initscript on your behalf. Remember to disable the sqm initscript manually under System Startup menu in case this change was not wished for.")));
                        }
 
                        return uci.set("sqm", section, "enabled", value);
index 2b56b1fc780b921f46e04370f43e336c2f8ed3b5..13c702449f78a66fad1c25b6370a9d16cfe804e2 100644 (file)
@@ -4,7 +4,9 @@
                "read": {
                        "file": {
                                "/var/run/sqm/available_qdiscs": [ "list" ],
-                               "/usr/lib/sqm/*.qos.help": [ "read" ]
+                               "/usr/lib/sqm/*.qos.help": [ "read" ],
+                               "/etc/init.d/sqm enable" : [ "exec" ],
+                               "/etc/init.d/sqm start" : [ "exec" ]
                        },
                        "uci": [ "sqm" ],
                        "ubus": {