sysutils/nut: a bit of tweaking for @mimugmail

This commit is contained in:
Franco Fichtner
2018-04-17 17:27:04 +00:00
parent 8b3daf8439
commit 5b110ffbe1
3 changed files with 33 additions and 45 deletions

View File

@@ -1,49 +1,43 @@
<?php
/*
Copyright (C) 2017-2018 Michael Muenz
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
* Copyright (C) 2017-2018 Michael Muenz
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function nut_enabled()
{
$model = new \OPNsense\Nut\Nut();
if ((string)$model->general->enabled == '1') {
return true;
}
return false;
return (string)$model->general->enable == '1';
}
function nut_netclient()
{
$model = new \OPNsense\Nut\Nut();
if ((string)$model->general->mode == 'netclient') {
return true;
}
return false;
return (string)$model->general->mode == 'netclient';
}
function nut_services()
@@ -62,7 +56,7 @@ function nut_services()
'pidfile' => '/var/db/nut/upsd.pid'
);
}
if (nut_netclient()) {
if (nut_enabled() && nut_netclient()) {
$services[] = array(
'description' => gettext('Network UPS Monitor'),
'configd' => array(

View File

@@ -34,7 +34,7 @@ class ServiceController extends ApiMutableServiceControllerBase
{
static protected $internalServiceClass = '\OPNsense\Nut\Nut';
static protected $internalServiceTemplate = 'OPNsense/Nut';
static protected $internalServiceEnabled = 'general.enabled';
static protected $internalServiceEnabled = 'general.enable';
static protected $internalServiceName = 'nut';
public function upsstatusAction()

View File

@@ -34,12 +34,10 @@
mapDataToFormUI(data_get_map).done(function(){
formatTokenizersUI();
$('.selectpicker').selectpicker('refresh');
// request service status on load and update status box
ajaxCall(url="/api/nut/service/status", sendData={}, callback=function(data,status) {
updateServiceStatusUI(data['status']);
});
});
updateServiceControlUI('nut');
// update history on tab state and implement navigation
if(window.location.hash != "") {
$('a[href="' + window.location.hash + '"]').click()
@@ -58,13 +56,9 @@
// 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");
ajaxCall(url="/api/nut/service/status", sendData={}, callback=function(data,status) {
updateServiceStatusUI(data['status']);
});
});
// when done, disable progress animation.
$("#"+frm_id+"_progress").removeClass("fa fa-spinner fa-pulse");
updateServiceControlUI('nut');
});
});
});