From 1272f8a397f97da9ae6e75b2592ef465248fd018 Mon Sep 17 00:00:00 2001 From: "Ycarus (Yannick Chabanois)" Date: Thu, 23 Apr 2020 19:03:36 +0200 Subject: [PATCH] Add shutdown app --- luci-app-shutdown/Makefile | 14 +++++++ .../resources/view/system/shutdown.js | 41 +++++++++++++++++++ .../share/luci/menu.d/luci-app-shutdown.json | 10 +++++ .../share/rpcd/acl.d/luci-app-shutdown.json | 13 ++++++ 4 files changed, 78 insertions(+) create mode 100644 luci-app-shutdown/Makefile create mode 100644 luci-app-shutdown/htdocs/luci-static/resources/view/system/shutdown.js create mode 100644 luci-app-shutdown/root/usr/share/luci/menu.d/luci-app-shutdown.json create mode 100644 luci-app-shutdown/root/usr/share/rpcd/acl.d/luci-app-shutdown.json diff --git a/luci-app-shutdown/Makefile b/luci-app-shutdown/Makefile new file mode 100644 index 000000000..2b09da9df --- /dev/null +++ b/luci-app-shutdown/Makefile @@ -0,0 +1,14 @@ +# +# Copyright (C) 2020 Ycarus (Yannick Chabanois) +# +# + +include $(TOPDIR)/rules.mk + +LUCI_TITLE:=LuCI Shutdown device app + +PKG_LICENSE:=GPLv3 + +include $(TOPDIR)/feeds/luci/luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/luci-app-shutdown/htdocs/luci-static/resources/view/system/shutdown.js b/luci-app-shutdown/htdocs/luci-static/resources/view/system/shutdown.js new file mode 100644 index 000000000..82ce6e1fe --- /dev/null +++ b/luci-app-shutdown/htdocs/luci-static/resources/view/system/shutdown.js @@ -0,0 +1,41 @@ +'use strict'; +'require fs'; +'require uci'; +'require ui'; + +return L.view.extend({ + render: function(changes) { + var body = E([ + E('h2', _('Shutdown')), + E('p', {}, _('Shutdown 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 shutdown!'))); + break; + } + + body.appendChild(E('hr')); + body.appendChild(E('button', { + 'class': 'cbi-button cbi-button-action important', + 'click': ui.createHandlerFn(this, 'handleShutdown') + }, _('Perform shutdown'))); + + return body; + }, + + handleShutdown: function(ev) { + return fs.exec('/sbin/poweroff').then(function(res) { + if (res.code != 0) { + L.ui.addNotification(null, E('p', _('The poweroff command failed with code %d').format(res.code))); + L.raise('Error', 'Poweroff failed'); + } + }) + .catch(function(e) { L.ui.addNotification(null, E('p', e.message)) }); + }, + + handleSaveApply: null, + handleSave: null, + handleReset: null +}); diff --git a/luci-app-shutdown/root/usr/share/luci/menu.d/luci-app-shutdown.json b/luci-app-shutdown/root/usr/share/luci/menu.d/luci-app-shutdown.json new file mode 100644 index 000000000..3cad13fcf --- /dev/null +++ b/luci-app-shutdown/root/usr/share/luci/menu.d/luci-app-shutdown.json @@ -0,0 +1,10 @@ +{ + "admin/system/shutdown": { + "title": "Shutdown", + "order": 60, + "action": { + "type": "view", + "path": "system/shutdown" + } + } +} diff --git a/luci-app-shutdown/root/usr/share/rpcd/acl.d/luci-app-shutdown.json b/luci-app-shutdown/root/usr/share/rpcd/acl.d/luci-app-shutdown.json new file mode 100644 index 000000000..6028a1cdf --- /dev/null +++ b/luci-app-shutdown/root/usr/share/rpcd/acl.d/luci-app-shutdown.json @@ -0,0 +1,13 @@ +{ + "luci-app-shutdown": { + "description": "Allow shutdown the device", + "read": { + "file": { + "/sbin/poweroff": [ "exec" ] + }, + "ubus": { + "file": [ "exec" ] + } + } + } +} \ No newline at end of file