diff --git a/README.md b/README.md index bde7dd4..fd31dc8 100644 --- a/README.md +++ b/README.md @@ -11,16 +11,16 @@ Dependences: lua, luci-lib-nixio, libuci-lua opkg install /tmp/internet-detector_0.3.0-1_all.ipk rm /tmp/internet-detector_0.3.0-1_all.ipk - wget --no-check-certificate -O /tmp/luci-app-internet-detector_0.3.0-1_all.ipk https://github.com/gSpotx2f/luci-app-internet-detector/raw/master/packages/19.07/luci-app-internet-detector_0.3.0-1_all.ipk - opkg install /tmp/luci-app-internet-detector_0.3.0-1_all.ipk - rm /tmp/luci-app-internet-detector_0.3.0-1_all.ipk + wget --no-check-certificate -O /tmp/luci-app-internet-detector_0.3.0-2_all.ipk https://github.com/gSpotx2f/luci-app-internet-detector/raw/master/packages/19.07/luci-app-internet-detector_0.3.0-2_all.ipk + opkg install /tmp/luci-app-internet-detector_0.3.0-2_all.ipk + rm /tmp/luci-app-internet-detector_0.3.0-2_all.ipk /etc/init.d/rpcd reload **i18n-ru:** - wget --no-check-certificate -O /tmp/luci-i18n-internet-detector-ru_0.3.0-1_all.ipk https://github.com/gSpotx2f/luci-app-internet-detector/raw/master/packages/19.07/luci-i18n-internet-detector-ru_0.3.0-1_all.ipk - opkg install /tmp/luci-i18n-internet-detector-ru_0.3.0-1_all.ipk - rm /tmp/luci-i18n-internet-detector-ru_0.3.0-1_all.ipk + wget --no-check-certificate -O /tmp/luci-i18n-internet-detector-ru_0.3.0-2_all.ipk https://github.com/gSpotx2f/luci-app-internet-detector/raw/master/packages/19.07/luci-i18n-internet-detector-ru_0.3.0-2_all.ipk + opkg install /tmp/luci-i18n-internet-detector-ru_0.3.0-2_all.ipk + rm /tmp/luci-i18n-internet-detector-ru_0.3.0-2_all.ipk **Script for LED control:** diff --git a/luci-app-internet-detector/Makefile b/luci-app-internet-detector/Makefile index 9a80e67..0f5458d 100644 --- a/luci-app-internet-detector/Makefile +++ b/luci-app-internet-detector/Makefile @@ -5,7 +5,7 @@ include $(TOPDIR)/rules.mk PKG_VERSION:=0.3.0 -PKG_RELEASE:=1 +PKG_RELEASE:=2 LUCI_TITLE:=LuCI support for internet-detector LUCI_DEPENDS:=+internet-detector LUCI_PKGARCH:=all diff --git a/luci-app-internet-detector/htdocs/luci-static/resources/view/internet-detector.js b/luci-app-internet-detector/htdocs/luci-static/resources/view/internet-detector.js index c31c130..faa000f 100644 --- a/luci-app-internet-detector/htdocs/luci-static/resources/view/internet-detector.js +++ b/luci-app-internet-detector/htdocs/luci-static/resources/view/internet-detector.js @@ -11,7 +11,6 @@ const btnStyleApply = 'btn cbi-button-apply'; return L.view.extend({ execPath : '/usr/bin/internet-detector', - initPath : '/etc/init.d/internet-detector', upScriptPath : '/etc/internet-detector/up-script', downScriptPath : '/etc/internet-detector/down-script', runScriptPath : '/etc/internet-detector/run-script', @@ -30,6 +29,26 @@ return L.view.extend({ uiCheckIntervalDown : null, currentAppMode : '0', + callInitStatus: rpc.declare({ + object: 'luci', + method: 'getInitList', + params: [ 'name' ], + expect: { '': {} } + }), + + getInitStatus: function() { + return this.callInitStatus('internet-detector').then(res => { + if(res) { + return res['internet-detector'].enabled; + } else { + throw _('Command failed'); + } + }).catch(e => { + ui.addNotification(null, + E('p', _('Failed to get %s init status: %s').format('internet-detector', e))); + }); + }, + callInitAction: rpc.declare({ object: 'luci', method: 'setInitAction', @@ -45,7 +64,7 @@ return L.view.extend({ return true; }).catch(e => { ui.addNotification(null, - E('p', _('Failed to execute "%s %s": %s').format(this.initPath, action, e))); + E('p', _('Service action failed "%s %s": %s').format('internet-detector', action, e))); }); }, @@ -191,27 +210,27 @@ return L.view.extend({ 'click': ui.createHandlerFn(this.ctx, this.ctx.serviceRestart), }, _('Restart')); this.ctx.initButton = E('button', { - 'class': (this.ctx.initStatus === 1) ? btnStyleDisabled : btnStyleEnabled, + 'class': (!this.ctx.initStatus) ? btnStyleDisabled : btnStyleEnabled, 'click': ui.createHandlerFn(this, () => { return this.ctx.handleServiceAction( - (this.ctx.initStatus === 1) ? 'enable' : 'disable' + (!this.ctx.initStatus) ? 'enable' : 'disable' ).then(success => { if(!success) { return; }; - if(this.ctx.initStatus === 1) { + if(!this.ctx.initStatus) { this.ctx.initButton.textContent = _('Enabled'); this.ctx.initButton.className = btnStyleEnabled; - this.ctx.initStatus = 0; + this.ctx.initStatus = true; } else { this.ctx.initButton.textContent = _('Disabled'); this.ctx.initButton.className = btnStyleDisabled; - this.ctx.initStatus = 1; + this.ctx.initStatus = false; }; }); }), - }, (this.ctx.initStatus == 1) ? _('Disabled') : _('Enabled')); + }, (!this.ctx.initStatus) ? _('Disabled') : _('Enabled')); this.ctx.setInternetStatus(true); @@ -316,7 +335,7 @@ return L.view.extend({ load: function() { return Promise.all([ fs.exec(this.execPath, [ 'status' ]), - fs.exec(this.initPath, [ 'enabled' ]), + this.getInitStatus(), uci.load('internet-detector'), ]).catch(e => { ui.addNotification(null, E('p', _('An error has occurred') + ': %s'.format(e.message))); @@ -328,7 +347,7 @@ return L.view.extend({ return; }; this.appStatus = (data[0].code === 0) ? data[0].stdout.trim() : null; - this.initStatus = data[1].code; + this.initStatus = data[1]; this.currentAppMode = uci.get('internet-detector', 'config', 'mode'); this.uiCheckIntervalUp = Number(uci.get('internet-detector', 'config', 'ui_interval_up')); this.uiCheckIntervalDown = Number(uci.get('internet-detector', 'config', 'ui_interval_down')); diff --git a/luci-app-internet-detector/po/ru/internet-detector.po b/luci-app-internet-detector/po/ru/internet-detector.po index de47677..0d1a469 100644 --- a/luci-app-internet-detector/po/ru/internet-detector.po +++ b/luci-app-internet-detector/po/ru/internet-detector.po @@ -93,8 +93,8 @@ msgstr "Выполнение команд при подключении к Ин msgid "Execute commands when the Internet is disconnected" msgstr "Выполнение команд при отключении от Интернет" -msgid "Failed to execute \"%s %s\": %s" -msgstr "Не удалось выполнить \"%s %s\": %s" +msgid "Failed to get %s init status: %s" +msgstr "Не удалось получить статус инициализации %s: %s" msgid "Host availability check type" msgstr "Тип проверки доступности хоста" @@ -156,6 +156,9 @@ msgstr "Сохранить" msgid "Service" msgstr "Служба" +msgid "Service action failed \"%s %s\": %s" +msgstr "Не удалось выполнить действие службы \"%s %s\": %s" + msgid "Service configuration" msgstr "Конфигурация службы" diff --git a/luci-app-internet-detector/po/templates/internet-detector.pot b/luci-app-internet-detector/po/templates/internet-detector.pot index d858368..ad584b7 100644 --- a/luci-app-internet-detector/po/templates/internet-detector.pot +++ b/luci-app-internet-detector/po/templates/internet-detector.pot @@ -82,7 +82,7 @@ msgstr "" msgid "Execute commands when the Internet is disconnected" msgstr "" -msgid "Failed to execute \"%s %s\": %s" +msgid "Failed to get %s init status: %s" msgstr "" msgid "Host availability check type" @@ -142,6 +142,9 @@ msgstr "" msgid "Service" msgstr "" +msgid "Service action failed \"%s %s\": %s" +msgstr "" + msgid "Service configuration" msgstr "" diff --git a/luci-app-internet-detector/root/usr/share/rpcd/acl.d/luci-app-internet-detector.json b/luci-app-internet-detector/root/usr/share/rpcd/acl.d/luci-app-internet-detector.json index f1f486f..cf1da28 100644 --- a/luci-app-internet-detector/root/usr/share/rpcd/acl.d/luci-app-internet-detector.json +++ b/luci-app-internet-detector/root/usr/share/rpcd/acl.d/luci-app-internet-detector.json @@ -6,12 +6,11 @@ "/etc/internet-detector/up-script": [ "read" ], "/etc/internet-detector/down-script": [ "read" ], "/etc/internet-detector/run-script": [ "read" ], - "/etc/init.d/internet-detector": [ "exec" ], "/usr/bin/internet-detector*": [ "exec" ] }, "uci": [ "internet-detector" ], "ubus": { - "luci": [ "setInitAction" ] + "luci": [ "getInitList", "setInitAction" ] } }, "write": { diff --git a/packages/19.07/luci-app-internet-detector_0.3.0-1_all.ipk b/packages/19.07/luci-app-internet-detector_0.3.0-1_all.ipk deleted file mode 100644 index a5ca034..0000000 Binary files a/packages/19.07/luci-app-internet-detector_0.3.0-1_all.ipk and /dev/null differ diff --git a/packages/19.07/luci-app-internet-detector_0.3.0-2_all.ipk b/packages/19.07/luci-app-internet-detector_0.3.0-2_all.ipk new file mode 100644 index 0000000..14c0d9b Binary files /dev/null and b/packages/19.07/luci-app-internet-detector_0.3.0-2_all.ipk differ diff --git a/packages/19.07/luci-i18n-internet-detector-ru_0.3.0-1_all.ipk b/packages/19.07/luci-i18n-internet-detector-ru_0.3.0-1_all.ipk deleted file mode 100644 index 0eb2719..0000000 Binary files a/packages/19.07/luci-i18n-internet-detector-ru_0.3.0-1_all.ipk and /dev/null differ diff --git a/packages/19.07/luci-i18n-internet-detector-ru_0.3.0-2_all.ipk b/packages/19.07/luci-i18n-internet-detector-ru_0.3.0-2_all.ipk new file mode 100644 index 0000000..f1c81de Binary files /dev/null and b/packages/19.07/luci-i18n-internet-detector-ru_0.3.0-2_all.ipk differ