aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config/nut/nut.xml14
-rw-r--r--config/nut/ups_status.inc7
-rw-r--r--config/nut/ups_status.js81
-rw-r--r--config/nut/ups_status.widget.php216
-rw-r--r--pkg_config.10.xml2
-rw-r--r--pkg_config.8.xml2
-rw-r--r--pkg_config.8.xml.amd642
7 files changed, 320 insertions, 4 deletions
diff --git a/config/nut/nut.xml b/config/nut/nut.xml
index ca7ca956..e066bc83 100644
--- a/config/nut/nut.xml
+++ b/config/nut/nut.xml
@@ -41,7 +41,7 @@
]]>
</copyright>
<name>nut</name>
- <version>2.0.5</version>
+ <version>2.1.1</version>
<title>Services: NUT</title>
<savetext>Change</savetext>
<aftersaveredirect>/status_nut.php</aftersaveredirect>
@@ -77,6 +77,18 @@
<prefix>/usr/local/www/</prefix>
<item>https://packages.pfsense.org/packages/config/nut/status_nut.php</item>
</additional_files_needed>
+ <additional_files_needed>
+ <prefix>/usr/local/www/widgets/widgets/</prefix>
+ <item>https://packages.pfsense.org/packages/config/nut/ups_status.widget.php</item>
+ </additional_files_needed>
+ <additional_files_needed>
+ <prefix>/usr/local/www/widgets/javascript/</prefix>
+ <item>https://packages.pfsense.org/packages/config/nut/ups_status.js</item>
+ </additional_files_needed>
+ <additional_files_needed>
+ <prefix>/usr/local/www/widgets/include/</prefix>
+ <item>https://packages.pfsense.org/packages/config/nut/ups_status.inc</item>
+ </additional_files_needed>
<advanced_options>enabled</advanced_options>
<fields>
<field>
diff --git a/config/nut/ups_status.inc b/config/nut/ups_status.inc
new file mode 100644
index 00000000..8953ff94
--- /dev/null
+++ b/config/nut/ups_status.inc
@@ -0,0 +1,7 @@
+<?php
+
+// set variable for custom title
+$ups_status_title = "UPS Status";
+$ups_status_title_link = "status_nut.php";
+
+?>
diff --git a/config/nut/ups_status.js b/config/nut/ups_status.js
new file mode 100644
index 00000000..4c64498f
--- /dev/null
+++ b/config/nut/ups_status.js
@@ -0,0 +1,81 @@
+/*
+ ups_status.js
+ part of pfSense (https://www.pfSense.org/)
+ Copyright (C) 2015 SunStroke <andrey.b.nikitin@gmail.com>
+ Copyright (C) 2015 ESF, LLC
+ 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.
+*/
+//should be called from "ups_status.widget.php"
+function showUPSData() {
+
+ //get data from ups_status.widget.php
+ url = "/widgets/widgets/ups_status.widget.php?getUPSData=1"
+ //IE fix to disable cache when using http:// , just append timespan
+ + new Date().getTime();
+
+ jQuery.ajax(url, {
+ type: 'get',
+ success: function(data) {
+ var upsData = data || "";
+ updateUPSWidgetContent(upsData);
+ },
+ error: function(jqXHR, status, error){
+ updateUPSWidgetContent("Error getting data from [ups_status.widget.php]");
+ }
+ });
+
+ //call itself in 11 seconds
+ window.setTimeout(showUPSData, 11000);
+}
+
+function updateUPSWidgetContent(upsData) {
+
+ upsdata_array = upsData.split(":");
+
+ if(upsdata_array.length > 1) {
+ jQuery("#ups_monitoring").html(upsdata_array[0]);
+ jQuery("#ups_model").html(upsdata_array[1]);
+ jQuery("#ups__status").html(upsdata_array[2]);
+ jQuery("#ups_batmeter_graph").css('width', upsdata_array[3]);
+ jQuery("#ups_batmeter").html(upsdata_array[3]);
+ jQuery("#ups_runtime").html(upsdata_array[4]);
+ // Change title to "Battery Voltage" or "Battery Temp"
+ if(upsdata_array[5].indexOf("V")) {
+ jQuery("#ups_celltitle_VT").html("Battery Voltage");
+ } else if(upsdata_array[5].indexOf("C")) {
+ jQuery("#ups_celltitle_VT").html("Battery Temp");
+ }
+ jQuery("#ups_bvoltage").html(upsdata_array[5]);
+ jQuery("#ups_loadmeter_graph").css('width', upsdata_array[6]);
+ jQuery("#ups_loadmeter").html(upsdata_array[6]);
+ jQuery("#ups_inputv").html(upsdata_array[7]);
+ jQuery("#ups_outputv").html(upsdata_array[8]);
+ jQuery("#ups_widget").css('opacity', '1');
+ jQuery("#ups_error_description").html("");
+ } else {
+ // print error description ($condition variable from ups_status.widget.php)
+ jQuery("#ups_widget").css('opacity', '0.2');
+ jQuery("#ups_error_description").html("ERROR: " + upsdata_array[0]);
+ }
+}
diff --git a/config/nut/ups_status.widget.php b/config/nut/ups_status.widget.php
new file mode 100644
index 00000000..f2a766e1
--- /dev/null
+++ b/config/nut/ups_status.widget.php
@@ -0,0 +1,216 @@
+<?php
+/*
+ ups_status.widget.php
+ part of pfSense (https://www.pfsense.org/)
+ Copyright (C) 2015 SunStroke <andrey.b.nikitin@gmail.com>
+ Copyright (C) 2015 ESF, LLC
+ 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.
+*/
+require_once("guiconfig.inc"); // NOTE: maybe not needed (no GUI settings)? Remove if so.
+require_once("/usr/local/www/widgets/include/ups_status.inc");
+
+//called by showUPSData() (jQuery Ajax call) in ups_status.js
+if (isset($_GET["getUPSData"])) {
+ //get UPS data and return it in ajax response
+ echo getUPSData();
+ return;
+}
+
+function getUPSData() {
+
+ global $config;
+ $data = "";
+ $cmd = "";
+ $nut_config = $config['installedpackages']['nut']['config'][0];
+
+ if ($nut_config['monitor'] == "local") {
+ // "Monitoring" field - upsdata_array[0]
+ $data = gettext("Local UPS");
+ $cmd = "upsc {$nut_config['name']}@localhost";
+ } elseif ($nut_config['monitor'] == "remote") {
+ // "Monitoring" field - upsdata_array[0]
+ $data = gettext("Remote UPS");
+ $cmd = "upsc {$nut_config['remotename']}@{$nut_config['remoteaddr']}";
+ } elseif ($nut_config['monitor'] == "snmp") {
+ // "Monitoring" field - upsdata_array[0]
+ $data = gettext("SNMP UPS");
+ $cmd = "upsc {$nut_config['snmpname']}@localhost";
+ }
+
+ if (is_process_running('upsmon')) {
+ $handle = popen($cmd, 'r');
+ if ($handle) {
+ $read = fread($handle, 4096);
+ pclose($handle);
+ $lines = explode("\n", $read);
+ if (count($lines) == 1) {
+ $condition = gettext("Data stale!");
+ } else {
+ $ups = array();
+ foreach ($lines as $line) {
+ $line = explode(':', $line);
+ $ups[$line[0]] = trim($line[1]);
+ }
+ }
+ }
+ } else {
+ $condition = gettext("NUT enabled, but service not running!");
+ if ($nut_config['monitor'] == "snmp") {
+ $condition .= gettext("\nSNMP UPS may be unreachable.");
+ }
+ }
+ if (isset($condition)) {
+ // Return error description
+ return $condition;
+ }
+ // "Model" field - upsdata_array[1]
+ $data .= ":" . (($ups['ups.model'] != "") ? $ups['ups.model'] : gettext("n/a"));
+ // "Status" field - upsdata_array[2]
+ $status = explode(" ", $ups['ups.status']);
+ foreach($status as $condition) {
+ if($disp_status) $disp_status .= ", ";
+ switch ($condition) {
+ case "WAIT":
+ $disp_status .= gettext("Waiting");
+ break;
+ case "OFF":
+ $disp_status .= gettext("Off Line");
+ break;
+ case "OL":
+ $disp_status .= gettext("On Line");
+ break;
+ case "OB":
+ $disp_status .= gettext("On Battery");
+ break;
+ case "TRIM":
+ $disp_status .= gettext("SmartTrim");
+ break;
+ case "BOOST":
+ $disp_status .= gettext("SmartBoost");
+ break;
+ case "OVER":
+ $disp_status .= gettext("Overload");
+ break;
+ case "LB":
+ $disp_status .= gettext("Battery Low");
+ break;
+ case "RB":
+ $disp_status .= gettext("Replace Battery");
+ break;
+ case "CAL":
+ $disp_status .= gettext("Calibration");
+ break;
+ case "CHRG":
+ $disp_status .= gettext("Charging");
+ break;
+ default:
+ $disp_status .= $condition;
+ break;
+ }
+ }
+ $data .= ":" . $disp_status;
+ // "Battery Charge" bars and field - upsdata_array[3]
+ $data .= ":" . $ups['battery.charge'] . "%";
+ // "Time Remaning" field - upsdata_array[4]
+ $secs = $ups['battery.runtime'];
+ if ($secs < 0 || $secs == "") {
+ $data .= ":" . gettext("n/a");
+ } else {
+ $m = (int)($secs / 60);
+ $h = (int)($m / 60) % 24;
+ $m = $m % 60;
+ $s = $secs % 60;
+ $data .= ":" . $h."h " . $m."m " . $s."s";
+ }
+ // "Battery Voltage or Battery Temp" field - upsdata_array[5]
+ if($ups['battery.voltage'] > 0) {
+ $data .= ":" . $ups['battery.voltage'] . "&nbsp;V";
+ } elseif ($ups['ups.temperature'] > 0) {
+ $data .= ":" . $ups['ups.temperature'] . "&#38;#176;C";
+ } else {
+ $data .= ":" . "";
+ }
+ // "Load" bars and field - upsdata_array[6]
+ $data .= ":" . $ups['ups.load'] . "%";
+ // "Input Voltage" field - upsdata_array[7]
+ $data .= ":" . $ups['input.voltage'] . "&nbsp;V";
+ // "Output Voltage" field - upsdata_array[8]
+ $data .= ":" . $ups['output.voltage'] . "&nbsp;V";
+
+ return $data;
+
+}
+?>
+
+<script type="text/javascript">
+//<![CDATA[
+ //start showing ups data
+ //NOTE: the refresh interval will be reset to a proper value in showUPSData() (ups_status.js).
+ jQuery(document).ready(function() {
+ showUPSData();
+ });
+//]]>
+</script>
+
+<div id="UPSWidgetContainer">
+ <table id="ups_widget" bgcolor="#990000" width="100%" border="0" cellspacing="0" cellpadding="0" summary="UPS status">
+ <tr>
+ <td class="widgetsubheader" align="center"><strong><?php echo gettext("Monitoring"); ?></strong></td>
+ <td class="widgetsubheader" align="center"><strong><?php echo gettext("Model"); ?></strong></td>
+ <td class="widgetsubheader" align="center"><strong><?php echo gettext("Status"); ?></strong></td>
+ </tr>
+ <tr>
+ <td class="listlr" align="center" id="ups_monitoring"></td>
+ <td class="listr" align="center" id="ups_model"></td>
+ <td class="listr" align="center" id="ups__status"></td>
+ </tr>
+ <tr>
+ <td class="widgetsubheader" align="center"><?php echo gettext("Battery Charge"); ?></td>
+ <td class="widgetsubheader" align="center"><?php echo gettext("Time Remain"); ?></td>
+ <td class="widgetsubheader" align="center" id="ups_celltitle_VT"></td>
+ </tr>
+ <tr>
+ <td class="listlr" align="center" id="ups_charge">
+ <div class="ui-progressbar ui-widget ui-widget-content ui-corner-all" role="progressbar"><div id="ups_batmeter_graph" class="ui-progressbar-value ui-widget-header ui-corner-left"></div></div>
+ <span id="ups_batmeter"></span>
+ </td>
+ <td class="listr" align="center" id="ups_runtime"></td>
+ <td class="listr" align="center" id="ups_bvoltage"></td>
+ </tr>
+ <tr>
+ <td class="widgetsubheader" align="center"><?php echo gettext("Load"); ?></td>
+ <td class="widgetsubheader" align="center"><?php echo gettext("Input Voltage"); ?></td>
+ <td class="widgetsubheader" align="center"><?php echo gettext("Output Voltage"); ?></td>
+ </tr>
+ <tr>
+ <td class="listlr" align="center" id="ups_load">
+ <div class="ui-progressbar ui-widget ui-widget-content ui-corner-all" role="progressbar"><div id="ups_loadmeter_graph" class="ui-progressbar-value ui-widget-header ui-corner-left"></div></div>
+ <span id="ups_loadmeter"></span>
+ </td>
+ <td class="listr" align="center" id="ups_inputv"></td>
+ <td class="listr" align="center" id="ups_outputv"></td>
+ </tr>
+ </table>
+ <span id="ups_error_description"></span>
+</div>
diff --git a/pkg_config.10.xml b/pkg_config.10.xml
index 1e9b6f94..9f30c470 100644
--- a/pkg_config.10.xml
+++ b/pkg_config.10.xml
@@ -815,7 +815,7 @@
<descr>Network UPS Tools.</descr>
<website>http://www.networkupstools.org/</website>
<category>Network Management</category>
- <version>2.1.0</version>
+ <version>2.1.1</version>
<status>BETA</status>
<required_version>2.2</required_version>
<maintainer>rswagoner@gmail.com</maintainer>
diff --git a/pkg_config.8.xml b/pkg_config.8.xml
index 230a0796..47f0eeca 100644
--- a/pkg_config.8.xml
+++ b/pkg_config.8.xml
@@ -897,7 +897,7 @@
<descr>Network UPS Tools</descr>
<website>http://www.networkupstools.org/</website>
<category>Network Management</category>
- <version>2.6.5_1 pkg 2.1.0</version>
+ <version>2.6.5_1 pkg 2.1.1</version>
<status>BETA</status>
<required_version>2.0</required_version>
<maintainer>rswagoner@gmail.com</maintainer>
diff --git a/pkg_config.8.xml.amd64 b/pkg_config.8.xml.amd64
index 1c65f72a..3d8eb4e1 100644
--- a/pkg_config.8.xml.amd64
+++ b/pkg_config.8.xml.amd64
@@ -884,7 +884,7 @@
<descr>Network UPS Tools</descr>
<website>http://www.networkupstools.org/</website>
<category>Network Management</category>
- <version>2.6.5_1 pkg 2.1.0</version>
+ <version>2.6.5_1 pkg 2.1.1</version>
<status>BETA</status>
<required_version>2.0</required_version>
<maintainer>rswagoner@gmail.com</maintainer>