Skip to content

Commit

Permalink
sysutils/nut: a bit of tweaking for @mimugmail
Browse files Browse the repository at this point in the history
  • Loading branch information
fichtner committed Apr 17, 2018
1 parent 8b3daf8 commit 5b110ff
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 45 deletions.
60 changes: 27 additions & 33 deletions sysutils/nut/src/etc/inc/plugins.inc.d/nut.inc
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -62,7 +56,7 @@ function nut_services()
'pidfile' => '/var/db/nut/upsd.pid'
);
}
if (nut_netclient()) {
if (nut_enabled() && nut_netclient()) {

This comment has been minimized.

Copy link
@fichtner

fichtner Apr 17, 2018

Author Member

not sure if I did the right thing here, but it seems likely: only use netclient if nut is enabled?

This comment has been minimized.

Copy link
@fichtner

fichtner Apr 17, 2018

Author Member

@mimugmail ^^^^^^^

$services[] = array(
'description' => gettext('Network UPS Monitor'),
'configd' => array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
16 changes: 5 additions & 11 deletions sysutils/nut/src/opnsense/mvc/app/views/OPNsense/Nut/index.volt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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');
});
});
});
Expand Down

4 comments on commit 5b110ff

@mimugmail
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you remove restart?

@fichtner
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reconfigure restarts in mutable controller

@mimugmail
Copy link
Member

@mimugmail mimugmail commented on 5b110ff Apr 17, 2018 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fichtner
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, yep

Please sign in to comment.