diff --git a/sysutils/nut/Makefile b/sysutils/nut/Makefile index 7863e03f5..9a21905ea 100644 --- a/sysutils/nut/Makefile +++ b/sysutils/nut/Makefile @@ -1,5 +1,5 @@ PLUGIN_NAME= nut -PLUGIN_VERSION= 0.3 +PLUGIN_VERSION= 0.4 PLUGIN_COMMENT= Network UPS Tools PLUGIN_DEPENDS= nut PLUGIN_MAINTAINER= m.muenz@gmail.com diff --git a/sysutils/nut/src/etc/inc/plugins.inc.d/nut.inc b/sysutils/nut/src/etc/inc/plugins.inc.d/nut.inc index 9dcb6149b..f39ca4d3e 100644 --- a/sysutils/nut/src/etc/inc/plugins.inc.d/nut.inc +++ b/sysutils/nut/src/etc/inc/plugins.inc.d/nut.inc @@ -59,7 +59,7 @@ function nut_services() 'stop' => array('nut stop'), ), 'name' => 'nut', - 'pidfile' => '/var/run/nut.pid' + 'pidfile' => '/var/db/nut/upsd.pid' ); } if (nut_netclient()) { @@ -70,7 +70,8 @@ function nut_services() 'start' => array('nut start'), 'stop' => array('nut stop'), ), - 'name' => 'upsmon' + 'name' => 'upsmon', + 'pidfile' => '/var/db/nut/upsmon.pid' ); } diff --git a/sysutils/nut/src/opnsense/mvc/app/controllers/OPNsense/Nut/Api/ServiceController.php b/sysutils/nut/src/opnsense/mvc/app/controllers/OPNsense/Nut/Api/ServiceController.php index 48befe674..174623cee 100644 --- a/sysutils/nut/src/opnsense/mvc/app/controllers/OPNsense/Nut/Api/ServiceController.php +++ b/sysutils/nut/src/opnsense/mvc/app/controllers/OPNsense/Nut/Api/ServiceController.php @@ -140,4 +140,10 @@ class ServiceController extends ApiControllerBase return array('response' => array()); } } + public function upsstatusAction() + { + $backend = new Backend(); + $response = $backend->configdRun("nut upsstatus"); + return array("response" => $response); + } } diff --git a/sysutils/nut/src/opnsense/mvc/app/controllers/OPNsense/Nut/forms/settings.xml b/sysutils/nut/src/opnsense/mvc/app/controllers/OPNsense/Nut/forms/settings.xml index 4bb232bce..034e057dc 100644 --- a/sysutils/nut/src/opnsense/mvc/app/controllers/OPNsense/Nut/forms/settings.xml +++ b/sysutils/nut/src/opnsense/mvc/app/controllers/OPNsense/Nut/forms/settings.xml @@ -13,6 +13,12 @@ dropdown Set the service mode. Currently only standalone and netclient are available. + + nut.general.name + + text + Set a name for your UPS. + @@ -37,12 +43,6 @@ checkbox Enable the USBHID driver. - - nut.usbhid.name - - text - Set a name for your UPS. - nut.usbhid.args @@ -57,12 +57,6 @@ checkbox Enable the Netclient driver. - - nut.netclient.name - - text - Set a name for your UPS. - nut.netclient.address diff --git a/sysutils/nut/src/opnsense/mvc/app/models/OPNsense/Nut/Menu/Menu.xml b/sysutils/nut/src/opnsense/mvc/app/models/OPNsense/Nut/Menu/Menu.xml index 3d23309cc..0f9883948 100644 --- a/sysutils/nut/src/opnsense/mvc/app/models/OPNsense/Nut/Menu/Menu.xml +++ b/sysutils/nut/src/opnsense/mvc/app/models/OPNsense/Nut/Menu/Menu.xml @@ -1,5 +1,8 @@ - + + + + diff --git a/sysutils/nut/src/opnsense/mvc/app/models/OPNsense/Nut/Nut.xml b/sysutils/nut/src/opnsense/mvc/app/models/OPNsense/Nut/Nut.xml index 484ed8f9f..d53bbde73 100644 --- a/sysutils/nut/src/opnsense/mvc/app/models/OPNsense/Nut/Nut.xml +++ b/sysutils/nut/src/opnsense/mvc/app/models/OPNsense/Nut/Nut.xml @@ -1,6 +1,7 @@ //OPNsense/Nut Network UPS Tools + 0.1.0 @@ -15,6 +16,10 @@ netclient + + UPSName + Y + @@ -33,10 +38,6 @@ Y 0 - - UPS-Name - Y - port=auto N @@ -47,10 +48,6 @@ Y 0 - - UPS-Name - Y -
N diff --git a/sysutils/nut/src/opnsense/mvc/app/views/OPNsense/Nut/index.volt b/sysutils/nut/src/opnsense/mvc/app/views/OPNsense/Nut/index.volt index 3c0ec137d..d5c60663a 100644 --- a/sysutils/nut/src/opnsense/mvc/app/views/OPNsense/Nut/index.volt +++ b/sysutils/nut/src/opnsense/mvc/app/views/OPNsense/Nut/index.volt @@ -55,26 +55,15 @@ var frm_title = $(this).closest("form").attr("data-title"); // save data for General TAB saveFormToEndpoint(url="/api/nut/settings/set", formid=frm_id, callback_ok=function(){ - // on correct save, perform reconfigure. set progress animation when reloading + // on correct save, perform restart, set progress animation when reloading $("#"+frm_id+"_progress").addClass("fa fa-spinner fa-pulse"); - ajaxCall(url="/api/nut/service/reconfigure", sendData={}, callback=function(data,status){ + ajaxCall(url="/api/nut/service/restart", sendData={}, callback=function(data,status){ // when done, disable progress animation. $("#"+frm_id+"_progress").removeClass("fa fa-spinner fa-pulse"); - - if (status != "success" || data['status'] != 'ok' ) { - // fix error handling - BootstrapDialog.show({ - type:BootstrapDialog.TYPE_WARNING, - title: frm_title, - message: JSON.stringify(data), - draggable: true - }); - } else { ajaxCall(url="/api/nut/service/status", sendData={}, callback=function(data,status) { updateServiceStatusUI(data['status']); }); - } }); }); }); diff --git a/sysutils/nut/src/opnsense/service/conf/actions.d/actions_nut.conf b/sysutils/nut/src/opnsense/service/conf/actions.d/actions_nut.conf index 994fd034b..726dc3136 100644 --- a/sysutils/nut/src/opnsense/service/conf/actions.d/actions_nut.conf +++ b/sysutils/nut/src/opnsense/service/conf/actions.d/actions_nut.conf @@ -21,3 +21,9 @@ command:/usr/local/etc/rc.d/nut status;exit 0 parameters: type:script_output message:request nut status + +[upsstatus] +command:/usr/local/bin/upsc -l +parameters: %s +type:script_output +message:retrieve ups status diff --git a/sysutils/nut/src/opnsense/service/templates/OPNsense/Nut/nut_upsmon b/sysutils/nut/src/opnsense/service/templates/OPNsense/Nut/nut_upsmon index 6c93b51f4..f6d70ed95 100644 --- a/sysutils/nut/src/opnsense/service/templates/OPNsense/Nut/nut_upsmon +++ b/sysutils/nut/src/opnsense/service/templates/OPNsense/Nut/nut_upsmon @@ -1,7 +1,5 @@ {% if helpers.exists('OPNsense.Nut.general.enable') and OPNsense.Nut.general.enable == '1' %} -{% if helpers.exists('OPNsense.Nut.general.mode') and OPNsense.Nut.general.mode == 'netclient' %} nut_upsmon_enable="YES" -{% else %} +{% else %} nut_upsmon_enable="NO" -{% endif %} {% endif %} diff --git a/sysutils/nut/src/opnsense/service/templates/OPNsense/Nut/ups.conf b/sysutils/nut/src/opnsense/service/templates/OPNsense/Nut/ups.conf index e9b4e204a..403c41dd6 100644 --- a/sysutils/nut/src/opnsense/service/templates/OPNsense/Nut/ups.conf +++ b/sysutils/nut/src/opnsense/service/templates/OPNsense/Nut/ups.conf @@ -3,7 +3,7 @@ # {% if helpers.exists('OPNsense.Nut.general.enable') and OPNsense.Nut.general.enable == '1' %} {% if helpers.exists('OPNsense.Nut.usbhid.enable') and OPNsense.Nut.usbhid.enable == '1' %} -[{{ OPNsense.Nut.usbhid.name }}] +[{{ OPNsense.Nut.general.name }}] driver=usbhid-ups {% if helpers.exists('OPNsense.Nut.usbhid.args') and OPNsense.Nut.usbhid.args != '' %} {{ OPNsense.Nut.usbhid.args }} diff --git a/sysutils/nut/src/opnsense/service/templates/OPNsense/Nut/upsmon.conf b/sysutils/nut/src/opnsense/service/templates/OPNsense/Nut/upsmon.conf index 955c16f58..4b6ce6fb5 100644 --- a/sysutils/nut/src/opnsense/service/templates/OPNsense/Nut/upsmon.conf +++ b/sysutils/nut/src/opnsense/service/templates/OPNsense/Nut/upsmon.conf @@ -2,12 +2,12 @@ # the next update. # {% if helpers.exists('OPNsense.Nut.usbhid.enable') and OPNsense.Nut.usbhid.enable == '1' %} -MONITOR {{ OPNsense.Nut.usbhid.name }} 1 monuser {{ OPNsense.Nut.account.mon_password }} master -SHUTDOWNCMD "/sbin/shutdown -p +0" +MONITOR {{ OPNsense.Nut.general.name }} 1 monuser {{ OPNsense.Nut.account.mon_password }} master +SHUTDOWNCMD "/usr/local/etc/rc.halt" POWERDOWNFLAG /etc/killpower {% endif %} {% if helpers.exists('OPNsense.Nut.netclient.enable') and OPNsense.Nut.netclient.enable == '1' %} -MONITOR {{ OPNsense.Nut.netclient.name }}@{{ OPNsense.Nut.netclient.address }} 1 {{ OPNsense.Nut.netclient.user }} {{ OPNsense.Nut.netclient.password }} slave -SHUTDOWNCMD "/sbin/shutdown -p +0" +MONITOR {{ OPNsense.Nut.general.name }}@{{ OPNsense.Nut.netclient.address }} 1 {{ OPNsense.Nut.netclient.user }} {{ OPNsense.Nut.netclient.password }} slave +SHUTDOWNCMD "/usr/local/etc/rc.halt" POWERDOWNFLAG /etc/killpower {% endif %}