From: <abe...@us...> - 2014-01-04 18:08:22
|
Revision: 6342 http://sourceforge.net/p/astlinux/code/6342 Author: abelbeck Date: 2014-01-04 18:08:18 +0000 (Sat, 04 Jan 2014) Log Message: ----------- web interface, add support for NUT UPS Monitoring Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/edit.php branches/1.0/package/webinterface/altweb/admin/network.php branches/1.0/package/webinterface/altweb/admin/prefs.php branches/1.0/package/webinterface/altweb/admin/system.php branches/1.0/package/webinterface/altweb/common/functions.php branches/1.0/package/webinterface/altweb/common/license-packages.txt branches/1.0/package/webinterface/altweb/common/status.inc Modified: branches/1.0/package/webinterface/altweb/admin/edit.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/edit.php 2014-01-04 17:02:55 UTC (rev 6341) +++ branches/1.0/package/webinterface/altweb/admin/edit.php 2014-01-04 18:08:18 UTC (rev 6342) @@ -1,6 +1,6 @@ <?php -// Copyright (C) 2008-2013 Lonnie Abelbeck +// Copyright (C) 2008-2014 Lonnie Abelbeck // This is free software, licensed under the GNU General Public License // version 3 as published by the Free Software Foundation; you can // redistribute it and/or modify it under the terms of the GNU @@ -35,7 +35,7 @@ 'snmpd' => 'Restart SNMP Server', 'stunnel' => 'Restart Stunnel Proxy', 'miniupnpd' => 'Restart Univ. Plug\'n\'Play', - 'apcupsd' => 'Restart UPS Daemon', + 'ups' => 'Restart UPS Daemon', 'prosody' => 'Restart XMPP Server', 'zabbix' => 'Restart Zabbix Monitor', 'asterisk' => 'Restart Asterisk' @@ -221,7 +221,7 @@ $result = restartPROCESS($process, 33, $result, 'init'); } elseif ($process === 'miniupnpd') { $result = restartPROCESS($process, 34, $result, 'init'); - } elseif ($process === 'apcupsd') { + } elseif ($process === 'ups') { $result = restartPROCESS($process, 35, $result, 'init'); } elseif ($process === 'zabbix') { $result = restartPROCESS($process, 36, $result, 'init', 4); @@ -282,7 +282,7 @@ $dir === '/mnt/kd/crontabs' || $dir === '/mnt/kd/snmp' || $dir === '/mnt/kd/fop2' || - $dir === '/mnt/kd/apcupsd' || + $dir === '/mnt/kd/ups' || $dir === '/mnt/kd/prosody' || $dir === '/mnt/kd/docs' || $dir === '/mnt/kd/arno-iptables-firewall' || @@ -350,7 +350,7 @@ } elseif ($result == 34) { putHtml('<p style="color: green;">Universal Plug\'n\'Play'.statusPROCESS('miniupnpd').'.</p>'); } elseif ($result == 35) { - putHtml('<p style="color: green;">UPS Daemon'.statusPROCESS('apcupsd').'.</p>'); + putHtml('<p style="color: green;">UPS Daemon'.statusPROCESS('ups').'.</p>'); } elseif ($result == 36) { putHtml('<p style="color: green;">Zabbix Monitoring'.statusPROCESS('zabbix').'.</p>'); } elseif ($result == 37) { @@ -475,10 +475,6 @@ $sel = ($file === $openfile) ? ' selected="selected"' : ''; putHtml('<option value="'.$file.'"'.$sel.'>crontabs/'.basename($file).' - Cron Jobs for root</option>'); } - if (is_writable($file = '/mnt/kd/apcupsd/apcupsd.conf')) { - $sel = ($file === $openfile) ? ' selected="selected"' : ''; - putHtml('<option value="'.$file.'"'.$sel.'>apcupsd/'.basename($file).' - APC UPS Configuration</option>'); - } if (is_writable($file = '/mnt/kd/ast-crash')) { $sel = ($file === $openfile) ? ' selected="selected"' : ''; putHtml('<option value="'.$file.'"'.$sel.'>'.basename($file).' - Safe Asterisk Crash Shell Script</option>'); @@ -533,6 +529,20 @@ } putHtml('</optgroup>'); } + if (is_dir('/mnt/kd/ups') && count($globfiles = glob('/mnt/kd/ups/*.conf')) > 0) { + putHtml('<optgroup label="———— UPS Monitoring Configs ————">'); + foreach ($globfiles as $globfile) { + if (is_file($globfile) && is_writable($globfile)) { + $sel = ($globfile === $openfile) ? ' selected="selected"' : ''; + putHtml('<option value="'.$globfile.'"'.$sel.'>'.basename($globfile).' - NUT UPS Configuration</option>'); + } + } + if (is_writable($file = '/mnt/kd/ups/upsd.users')) { + $sel = ($file === $openfile) ? ' selected="selected"' : ''; + putHtml('<option value="'.$file.'"'.$sel.'>'.basename($file).' - NUT UPS Configuration</option>'); + } + putHtml('</optgroup>'); + } if (is_dir('/mnt/kd/docs') && count($globfiles = glob('/mnt/kd/docs/*')) > 0) { putHtml('<optgroup label="———— Documentation ————">'); foreach ($globfiles as $globfile) { Modified: branches/1.0/package/webinterface/altweb/admin/network.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/network.php 2014-01-04 17:02:55 UTC (rev 6341) +++ branches/1.0/package/webinterface/altweb/admin/network.php 2014-01-04 18:08:18 UTC (rev 6342) @@ -1,6 +1,6 @@ <?php -// Copyright (C) 2008-2013 Lonnie Abelbeck +// Copyright (C) 2008-2014 Lonnie Abelbeck // This is free software, licensed under the GNU General Public License // version 3 as published by the Free Software Foundation; you can // redistribute it and/or modify it under the terms of the GNU @@ -33,6 +33,7 @@ // 07-07-2012, Added Universal Plug & Play support // 09-23-2013, Added ddclient support // 10-21-2013, Added LDAP server support +// 01-04-2014, Added NUT UPS Monitoring support // // System location of rc.conf file $CONFFILE = '/etc/rc.conf'; @@ -98,24 +99,18 @@ 'demand' => 'demand' ); -$select_ups_type = array ( - 'disabled' => '', - 'usb' => 'usb', - 'net' => 'net', - 'pcnet' => 'pcnet', - 'snmp' => 'snmp', - 'apcsmart' => 'apcsmart', - 'dumb' => 'dumb' +$select_ups_driver = array ( + 'No direct connected "master" UPS' => '', + '[usbhid-ups] Generic USB HID' => 'usbhid-ups', + '[bcmxcp_usb] BCM/XCP protocol over USB' => 'bcmxcp_usb', + '[blazer_usb] Megatec/Q1 protocol USB' => 'blazer_usb', + '[richcomm_usb] Richcomm contact to USB' => 'richcomm_usb', + '[riello_usb] Riello USB' => 'riello_usb', + '[tripplite_usb] Tripp Lite OMNIVS/SMARTPRO' => 'tripplite_usb', + '[snmp-ups] Generic SNMP' => 'snmp-ups', + '[netxml-ups] Network XML' => 'netxml-ups' ); -$select_ups_cable = array ( - 'disabled' => '', - 'usb' => 'usb', - 'ethernet' => 'ether', - 'smart' => 'smart', - 'simple' => 'simple' -); - $select_upnp = array ( 'disabled' => 'no:no', 'NAT-PMP only' => 'yes:no', @@ -611,26 +606,35 @@ fwrite($fp, $value."\n"); } - fwrite($fp, "### APC UPS Monitoring - Shutdown\n"); - if (isset($_POST['ups_type'], $_POST['ups_cable'], $_POST['ups_device'])) { - $value = 'UPSTYPE="'.$_POST['ups_type'].'"'; + fwrite($fp, "### UPS Monitoring - Shutdown\n"); + if (isset($_POST['ups_driver'], $_POST['ups_driver_port'])) { + $value = 'UPS_DRIVER="'.$_POST['ups_driver'].'"'; fwrite($fp, $value."\n"); - $value = 'UPSCABLE="'.$_POST['ups_cable'].'"'; - fwrite($fp, $value."\n"); - if ($_POST['ups_type'] === 'usb') { - $value = 'UPSDEVICE=""'; + if ($_POST['ups_driver'] === 'snmp-ups' || $_POST['ups_driver'] === 'netxml-ups' || $_POST['ups_driver'] === '') { + $value = 'UPS_DRIVER_PORT="'.tuq($_POST['ups_driver_port']).'"'; } else { - $value = 'UPSDEVICE="'.tuq($_POST['ups_device']).'"'; + $value = 'UPS_DRIVER_PORT=""'; } fwrite($fp, $value."\n"); } else { - $value = 'UPSTYPE=""'; + $value = 'UPS_DRIVER=""'; fwrite($fp, $value."\n"); - $value = 'UPSCABLE=""'; + $value = 'UPS_DRIVER_PORT=""'; fwrite($fp, $value."\n"); - $value = 'UPSDEVICE=""'; - fwrite($fp, $value."\n"); } + $value = 'UPS_LISTEN_ALL="'.$_POST['ups_listen_all'].'"'; + fwrite($fp, $value."\n"); + if (isset($_POST['ups_driver']) && $_POST['ups_driver'] === '') { + $value = 'UPS_MONITOR_HOST="'.tuq($_POST['ups_monitor_host']).'"'; + } else { + $value = 'UPS_MONITOR_HOST=""'; + } + fwrite($fp, $value."\n"); + $value = 'UPS_MONITOR_USER="'.tuq($_POST['ups_monitor_user']).'"'; + fwrite($fp, $value."\n"); + $value = 'UPS_MONITOR_PASS="'.string2RCconfig(trim($_POST['ups_monitor_pass'])).'"'; + fwrite($fp, $value."\n"); + $value = 'UPS_NOTIFY="'.tuq($_POST['ups_notify']).'"'; fwrite($fp, $value."\n"); $value = 'UPS_NOTIFY_FROM="'.tuq($_POST['ups_notify_from']).'"'; @@ -904,7 +908,7 @@ } } elseif (isset($_POST['submit_edit_ups'])) { $result = saveNETWORKsettings($NETCONFDIR, $NETCONFFILE); - if (is_writable($file = '/mnt/kd/apcupsd/apcupsd.conf')) { + if (is_writable($file = '/mnt/kd/ups/ups.conf')) { header('Location: /admin/edit.php?file='.$file); exit; } @@ -971,7 +975,7 @@ $result = restartPROCESS($process, 33, $result, 'init'); } elseif ($process === 'miniupnpd') { $result = restartPROCESS($process, 34, $result, 'init'); - } elseif ($process === 'apcupsd') { + } elseif ($process === 'ups') { $result = restartPROCESS($process, 35, $result, 'init'); } elseif ($process === 'zabbix') { $result = restartPROCESS($process, 36, $result, 'init', 4); @@ -1058,7 +1062,7 @@ } elseif ($result == 34) { putHtml('<p style="color: green;">Universal Plug\'n\'Play'.statusPROCESS('miniupnpd').'.</p>'); } elseif ($result == 35) { - putHtml('<p style="color: green;">UPS Daemon'.statusPROCESS('apcupsd').'.</p>'); + putHtml('<p style="color: green;">UPS Daemon'.statusPROCESS('ups').'.</p>'); } elseif ($result == 36) { putHtml('<p style="color: green;">Zabbix Monitoring'.statusPROCESS('zabbix').'.</p>'); } elseif ($result == 37) { @@ -1166,8 +1170,8 @@ putHtml('<option value="stunnel"'.$sel.'>Restart Stunnel Proxy</option>'); $sel = ($reboot_restart === 'miniupnpd') ? ' selected="selected"' : ''; putHtml('<option value="miniupnpd"'.$sel.'>Restart Univ. Plug\'n\'Play</option>'); - $sel = ($reboot_restart === 'apcupsd') ? ' selected="selected"' : ''; - putHtml('<option value="apcupsd"'.$sel.'>Restart UPS Daemon</option>'); + $sel = ($reboot_restart === 'ups') ? ' selected="selected"' : ''; + putHtml('<option value="ups"'.$sel.'>Restart UPS Daemon</option>'); $sel = ($reboot_restart === 'prosody') ? ' selected="selected"' : ''; putHtml('<option value="prosody"'.$sel.'>Restart XMPP Server</option>'); $sel = ($reboot_restart === 'zabbix') ? ' selected="selected"' : ''; @@ -1901,31 +1905,50 @@ putHtml('<tr class="dtrow0"><td class="dialogText" style="text-align: left;" colspan="6">'); - putHtml('<strong>APC UPS Monitoring & Shutdown:</strong>'); + putHtml('<strong>UPS Monitoring & Shutdown:</strong>'); putHtml('</td></tr>'); - putHtml('<tr class="dtrow1"><td style="text-align: left;" colspan="6">'); - putHtml('UPS Type:'); - if (! is_file('/mnt/kd/apcupsd/apcupsd.conf')) { - $ups_type = getVARdef($db, 'UPSTYPE', $cur_db); - putHtml('<select name="ups_type">'); - foreach ($select_ups_type as $key => $value) { - $sel = ($ups_type === $value) ? ' selected="selected"' : ''; + if (! is_file('/mnt/kd/ups/ups.conf')) { + putHtml('<tr class="dtrow1"><td style="text-align: left;" colspan="3">'); + putHtml('UPS Driver:'); + $ups_driver = getVARdef($db, 'UPS_DRIVER', $cur_db); + putHtml('<select name="ups_driver">'); + foreach ($select_ups_driver as $key => $value) { + $sel = ($ups_driver === $value) ? ' selected="selected"' : ''; putHtml('<option value="'.$value.'"'.$sel.'>'.$key.'</option>'); } putHtml('</select>'); - putHtml('– UPS Cable:'); - $ups_cable = getVARdef($db, 'UPSCABLE', $cur_db); - putHtml('<select name="ups_cable">'); - foreach ($select_ups_cable as $key => $value) { - $sel = ($ups_cable === $value) ? ' selected="selected"' : ''; - putHtml('<option value="'.$value.'"'.$sel.'>'.$key.'</option>'); - } - putHtml('</select>'); - $value = getVARdef($db, 'UPSDEVICE', $cur_db); - putHtml('– Device:<input type="text" size="36" maxlength="200" value="'.$value.'" name="ups_device" /></td></tr>'); + putHtml('</td><td style="text-align: left;" colspan="3">'); + $value = getVARdef($db, 'UPS_DRIVER_PORT', $cur_db); + putHtml('Driver Data:<input type="text" size="36" maxlength="200" value="'.$value.'" name="ups_driver_port" />'); + putHtml('</td></tr>'); } else { + putHtml('<tr class="dtrow1"><td style="text-align: left;" colspan="6">'); + putHtml('UPS Driver Configuration File:'); putHtml('<input type="submit" value="UPS Configuration" name="submit_edit_ups" class="button" /></td></tr>'); } + putHtml('<tr class="dtrow1"><td style="text-align: left;" colspan="3">'); + putHtml('Network UPS Server:'); + putHtml('<select name="ups_listen_all">'); + putHtml('<option value="no">disabled</option>'); + $sel = (getVARdef($db, 'UPS_LISTEN_ALL', $cur_db) === 'yes') ? ' selected="selected"' : ''; + putHtml('<option value="yes"'.$sel.'>enabled</option>'); + putHtml('</select>'); + putHtml('</td><td style="text-align: left;" colspan="3">'); + $value = getVARdef($db, 'UPS_MONITOR_HOST', $cur_db); + putHtml('Slave ups@host:<input type="text" size="36" maxlength="256" value="'.$value.'" name="ups_monitor_host" /></td></tr>'); + + putHtml('<tr class="dtrow1"><td style="text-align: left;" colspan="3">'); + if (($value = getVARdef($db, 'UPS_MONITOR_USER', $cur_db)) === '') { + $value = 'monuser'; + } + putHtml('UPS Username:<input type="text" size="24" maxlength="64" value="'.$value.'" name="ups_monitor_user" /></td>'); + putHtml('<td style="text-align: left;" colspan="3">'); + if (($value = getVARdef($db, 'UPS_MONITOR_PASS', $cur_db)) === '') { + $value = 'astlinux'; + } + $value = htmlspecialchars(RCconfig2string($value)); + putHtml('UPS Password:<input type="password" size="24" maxlength="64" value="'.$value.'" name="ups_monitor_pass" /></td></tr>'); + putHtml('<tr class="dtrow1"><td style="text-align: left;" colspan="6">'); $value = getVARdef($db, 'UPS_NOTIFY', $cur_db); putHtml('Notify Email Addresses To:<input type="text" size="72" maxlength="256" value="'.$value.'" name="ups_notify" /></td></tr>'); Modified: branches/1.0/package/webinterface/altweb/admin/prefs.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/prefs.php 2014-01-04 17:02:55 UTC (rev 6341) +++ branches/1.0/package/webinterface/altweb/admin/prefs.php 2014-01-04 18:08:18 UTC (rev 6342) @@ -1,6 +1,6 @@ <?php -// Copyright (C) 2008-2013 Lonnie Abelbeck +// Copyright (C) 2008-2014 Lonnie Abelbeck // This is free software, licensed under the GNU General Public License // version 3 as published by the Free Software Foundation; you can // redistribute it and/or modify it under the terms of the GNU @@ -639,7 +639,7 @@ putHtml('<tr class="dtrow1"><td style="text-align: right;">'); $sel = (getPREFdef($global_prefs, 'status_ups_show_status') !== 'no') ? ' checked="checked"' : ''; - putHtml('<input type="checkbox" value="ups_status" name="ups_status"'.$sel.' /></td><td colspan="5">Show APC UPS Status</td></tr>'); + putHtml('<input type="checkbox" value="ups_status" name="ups_status"'.$sel.' /></td><td colspan="5">Show UPS Monitoring Status</td></tr>'); putHtml('<tr class="dtrow1"><td style="text-align: right;">'); $sel = (getPREFdef($global_prefs, 'status_show_hardware_monitoring') === 'yes') ? ' checked="checked"' : ''; putHtml('<input type="checkbox" value="hardware_monitoring" name="hardware_monitoring"'.$sel.' /></td><td colspan="5">Show Hardware Monitoring</td></tr>'); Modified: branches/1.0/package/webinterface/altweb/admin/system.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/system.php 2014-01-04 17:02:55 UTC (rev 6341) +++ branches/1.0/package/webinterface/altweb/admin/system.php 2014-01-04 18:08:18 UTC (rev 6342) @@ -1,6 +1,6 @@ <?php -// Copyright (C) 2008-2013 Lonnie Abelbeck +// Copyright (C) 2008-2014 Lonnie Abelbeck // This is free software, licensed under the GNU General Public License // version 3 as published by the Free Software Foundation; you can // redistribute it and/or modify it under the terms of the GNU @@ -189,7 +189,7 @@ $srcfile .= ' -e "s/^blocked-hosts$/&/p" -e "s/^dnsmasq.static$/&/p" -e "s/^hosts$/&/p" -e "s/^ethers$/&/p"'; $srcfile .= ' -e "s/^rc.local$/&/p" -e "s/^rc.local.stop$/&/p" -e "s/^rc.elocal$/&/p" -e "s/^rc.ledcontrol$/&/p"'; $srcfile .= ' -e "s/^crontabs$/&/p" -e "s/^snmp$/&/p" -e "s/^fop2$/&/p"'; - $srcfile .= ' -e "s/^openvpn$/&/p" -e "s/^ipsec$/&/p" -e "s/^dahdi$/&/p" -e "s/^ssl$/&/p" -e "s/^apcupsd$/&/p")'; + $srcfile .= ' -e "s/^openvpn$/&/p" -e "s/^ipsec$/&/p" -e "s/^dahdi$/&/p" -e "s/^ssl$/&/p" -e "s/^ups$/&/p")'; $srcfile .= $firewall; } elseif ($backup_type === 'cdr') { $srcfile = '$(ls -1 /mnt/kd/ | sed -n -e "s/^cdr-.*/&/p")'; @@ -591,6 +591,9 @@ if (is_file($file = '/var/log/openvpnclient.log')) { putHtml('<option value="'.$file.'">OpenVPN Client log</option>'); } + if (is_file($file = '/var/log/ups.log')) { + putHtml('<option value="'.$file.'">UPS Daemon Startup log</option>'); + } if (is_file($file = '/var/log/zabbix_agentd.log')) { putHtml('<option value="'.$file.'">Zabbix Agent log</option>'); } @@ -855,6 +858,7 @@ $var === 'PPTP_USER_PASS' || $var === 'OVPN_USER_PASS' || $var === 'OVPNC_USER_PASS' || + $var === 'UPS_MONITOR_PASS' || $var === 'IPSECM_XAUTH_USER_PASS' || $var === 'IPSEC_PSK_ASSOCIATIONS') { $value = '********'; Modified: branches/1.0/package/webinterface/altweb/common/functions.php =================================================================== --- branches/1.0/package/webinterface/altweb/common/functions.php 2014-01-04 17:02:55 UTC (rev 6341) +++ branches/1.0/package/webinterface/altweb/common/functions.php 2014-01-04 18:08:18 UTC (rev 6342) @@ -1,6 +1,6 @@ <?php -// Copyright (C) 2008-2012 Lonnie Abelbeck +// Copyright (C) 2008-2014 Lonnie Abelbeck // This is free software, licensed under the GNU General Public License // version 3 as published by the Free Software Foundation; you can // redistribute it and/or modify it under the terms of the GNU @@ -16,6 +16,7 @@ // 09-06-2008, Added restartPROCESS() // 12-12-2009, Added systemSHUTDOWN() // 01-12-2012, Added asteriskURLrepo() +// 01-04-2014, Added statusPROCESS() // // System location of prefs file $KD_PREFS_LOCATION = '/mnt/kd/webgui-prefs.txt'; @@ -115,6 +116,12 @@ } else { $str = $stopped; } + } elseif ($process === 'ups') { + if (is_file($path.'upsmon.pid')) { + $str = $running; + } else { + $str = $stopped; + } } elseif ($process === 'zabbix') { if (is_file($path.'zabbix_agentd.pid')) { $str = $running; @@ -522,9 +529,9 @@ $value = '#NTP server is specified in /mnt/kd/ntpd.conf'; } } - if ($var === 'UPSTYPE' || $var === 'UPSCABLE' || $var === 'UPSDEVICE') { - if (is_file('/mnt/kd/apcupsd/apcupsd.conf')) { - $value = '#UPS is specified in /mnt/kd/apcupsd/apcupsd.conf'; + if ($var === 'UPS_DRIVER' || $var === 'UPS_DRIVER_PORT') { + if (is_file('/mnt/kd/ups/ups.conf')) { + $value = '#UPS driver is specified in /mnt/kd/ups/ups.conf'; } } if ($var === 'ASTBACK_PATHS' || Modified: branches/1.0/package/webinterface/altweb/common/license-packages.txt =================================================================== --- branches/1.0/package/webinterface/altweb/common/license-packages.txt 2014-01-04 17:02:55 UTC (rev 6341) +++ branches/1.0/package/webinterface/altweb/common/license-packages.txt 2014-01-04 18:08:18 UTC (rev 6342) @@ -15,7 +15,7 @@ DAHDI~Copyright (c) 2001-2014 Digium, Inc. libPRI~Copyright (c) 2001-2012 Digium, Inc. Arno's Firewall~Copyright (c) 2001-2014 by Arno van Amersfoort. -dnsmasq~Copyright (c) 2000-2012 Simon Kelley. +dnsmasq~Copyright (c) 2000-2014 Simon Kelley. OpenSSL~Copyright (c) 1998-2012 The OpenSSL Project. All rights reserved. OpenSSH~Copyright (c) 1995 Tatu Ylonen <yl...@cs...>, Espoo, Finland. All rights reserved. OpenVPN~Copyright (c) 2002-2012 OpenVPN Technologies, Inc. <sa...@op...> @@ -47,3 +47,4 @@ vCard converter~Copyright (c) 2006-2013 Thomas Bruederli <th...@br...> OpenLDAP~Copyright (c) 1998-2013 The OpenLDAP Foundation. All rights reserved. darkstat~Copyright (c) 2001-2013 Emil Mikulic, et al. +NUT~Copyright (c) 1999-2013 Russell Kroll, Arnaud Quette, et al. Modified: branches/1.0/package/webinterface/altweb/common/status.inc =================================================================== --- branches/1.0/package/webinterface/altweb/common/status.inc 2014-01-04 17:02:55 UTC (rev 6341) +++ branches/1.0/package/webinterface/altweb/common/status.inc 2014-01-04 18:08:18 UTC (rev 6342) @@ -1,6 +1,6 @@ <?php -// Copyright (C) 2008-2013 Lonnie Abelbeck +// Copyright (C) 2008-2014 Lonnie Abelbeck // This is free software, licensed under the GNU General Public License // version 3 as published by the Free Software Foundation; you can // redistribute it and/or modify it under the terms of the GNU @@ -30,6 +30,7 @@ // 09-28-2012, Added Latest System Logs/Hide Log Words // 09-28-2012, Added Custom Asterisk Command // 01-20-2013, Added XMPP Server Status +// 01-03-2014, Added NUT UPS Monitoring Status // // System location of OpenVPN Client logfile $OVPNCLOGFILE = '/var/log/openvpnclient-status.log'; @@ -72,7 +73,7 @@ $status['openvpn'] = 0; $status['racoon'] = 0; $status['pptpd'] = 0; - $status['apcupsd'] = 0; + $status['upsmon'] = 0; $status['syslogd'] = 0; $status['zabbix_agentd'] = 0; $status['zabbix_proxy'] = 0; @@ -99,8 +100,8 @@ $status['racoon']++; } elseif (strpos($line, ' pptpd') !== FALSE || strpos($line, '/pptpd') !== FALSE) { $status['pptpd']++; - } elseif (strpos($line, ' apcupsd') !== FALSE || strpos($line, '/apcupsd') !== FALSE) { - $status['apcupsd']++; + } elseif (strpos($line, ' upsmon') !== FALSE || strpos($line, '/upsmon') !== FALSE) { + $status['upsmon']++; } elseif (strpos($line, ' zabbix_agentd ') !== FALSE || strpos($line, '/zabbix_agentd ') !== FALSE) { $status['zabbix_agentd']++; } elseif (strpos($line, ' zabbix_proxy ') !== FALSE || strpos($line, '/zabbix_proxy ') !== FALSE) { @@ -124,15 +125,15 @@ if (($ph = @fopen($log, "r")) !== FALSE) { while (! feof($ph)) { if ($line = rtrim(fgets($ph, 1024))) { - if (preg_match('/^([A-Z][A-Z]*)[ :]*(.*)$/', $line, $ips)) { + if (preg_match('/^([a-z][a-z.]*)[ :]*(.*)$/', $line, $ips)) { switch ($ips[1]) { - case 'MODEL': - case 'STATUS': - case 'LINEV': - case 'LOADPCT': - case 'BCHARGE': - case 'TIMELEFT': - $status['status'][$cid]["$ips[1]"] = str_replace('Percent', '%', $ips[2]); + case 'ups.model': + case 'ups.status': + case 'input.voltage': + case 'ups.load': + case 'battery.charge': + case 'battery.runtime': + $status['status'][$cid]["$ips[1]"] = $ips[2]; break; } } @@ -1127,20 +1128,20 @@ } } -if ($daemon['apcupsd'] > 0) { +if ($daemon['upsmon'] > 0) { if (getPREFdef($global_prefs, 'status_ups_show_status') !== 'no') { - putHtml("<h2>APC UPS Status:</h2>"); + putHtml("<h2>UPS Monitoring Status:</h2>"); putHtml("<pre>"); $tmpfile = tempnam("/tmp", "PHP_"); - shell('/usr/sbin/apcaccess status >'.$tmpfile, $status); + shell('/usr/bin/upsc $(awk \'/^MONITOR / { print $2; nextfile; }\' /etc/ups/upsmon.conf) >'.$tmpfile, $status); - if (is_null($apcupsd = parseUPSstatus($tmpfile))) { + if (is_null($upsmon = parseUPSstatus($tmpfile))) { putText('No UPS Status available'); putText(''); } else { putHtml('<table class="statusdatatable">'); putHtml("<tr>"); - if (($n = count($apcupsd['status'])) > 0) { + if (($n = count($upsmon['status'])) > 0) { echo "<td>", "Model", "</td>"; echo "<td>", "Status", "</td>"; echo "<td>", "Utility", "</td>"; @@ -1149,12 +1150,12 @@ echo "<td>", "Batt. Runtime", "</td>"; for ($i = 0; $i < $n; $i++) { putHtml("</tr><tr>"); - echo "<td>", $apcupsd['status'][$i]['MODEL'], "</td>"; - echo "<td>", $apcupsd['status'][$i]['STATUS'], "</td>"; - echo "<td>", $apcupsd['status'][$i]['LINEV'], "</td>"; - echo "<td>", $apcupsd['status'][$i]['LOADPCT'], "</td>"; - echo "<td>", $apcupsd['status'][$i]['BCHARGE'], "</td>"; - echo "<td>", $apcupsd['status'][$i]['TIMELEFT'], "</td>"; + echo "<td>", $upsmon['status'][$i]['ups.model'], "</td>"; + echo "<td>", $upsmon['status'][$i]['ups.status'], "</td>"; + echo "<td>", $upsmon['status'][$i]['input.voltage'].' Volts', "</td>"; + echo "<td>", $upsmon['status'][$i]['ups.load'].' %', "</td>"; + echo "<td>", $upsmon['status'][$i]['battery.charge'].' %', "</td>"; + echo "<td>", (int)(((int)$upsmon['status'][$i]['battery.runtime'] + 30) / 60).' Minutes', "</td>"; } } putHtml("</tr>"); @@ -1163,7 +1164,7 @@ putText('Recent UPS Events:'); putText('=================='); - shell('tail -n4 /var/log/apcupsd.events >'.$tmpfile, $status); + shell('tail -n4 /var/log/ups-status.log >'.$tmpfile, $status); $ph = @fopen($tmpfile, "r"); while (! feof($ph)) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |