diff options
author | Bill Marquette <bill.marquette@gmail.com> | 2009-02-06 19:18:00 -0600 |
---|---|---|
committer | Bill Marquette <bill.marquette@gmail.com> | 2009-02-06 19:18:00 -0600 |
commit | 55eddd7accf2c5f9b0f52b22a010c4c4b7c130d1 (patch) | |
tree | ba4783bab1dd65f1ceef2dfac9fdbd515531d18b /config/nut | |
parent | 67780cc9d469288742aea5bc378c29a54edd5ec5 (diff) | |
download | pfsense-packages-55eddd7accf2c5f9b0f52b22a010c4c4b7c130d1.tar.gz pfsense-packages-55eddd7accf2c5f9b0f52b22a010c4c4b7c130d1.tar.bz2 pfsense-packages-55eddd7accf2c5f9b0f52b22a010c4c4b7c130d1.zip |
mv packages to config dir to match web layout
Diffstat (limited to 'config/nut')
-rw-r--r-- | config/nut/nut.inc | 394 | ||||
-rw-r--r-- | config/nut/nut.xml | 518 | ||||
-rw-r--r-- | config/nut/status_nut.php | 242 |
3 files changed, 1154 insertions, 0 deletions
diff --git a/config/nut/nut.inc b/config/nut/nut.inc new file mode 100644 index 00000000..a8465dce --- /dev/null +++ b/config/nut/nut.inc @@ -0,0 +1,394 @@ +<?php +/* + nut.inc + part of pfSense (http://www.pfsense.com/) + + Copyright (C) 2007 Ryan Wagoner <rswagoner@gmail.com>. + 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("config.inc"); + require_once("functions.inc"); + + /* Nut */ + + define('NUT_RCFILE', '/usr/local/etc/rc.d/nut.sh'); + define('NUT_DIR','/usr/local/etc/nut'); + + function nut_notice ($msg) { syslog(LOG_NOTICE, "nut: {$msg}"); return; } + function nut_warn ($msg) { syslog(LOG_WARNING, "nut: {$msg}"); return; } + + function nut_action ($action) { + if (file_exists(NUT_RCFILE)) + mwexec(NUT_RCFILE.' '.$action); + } + + function nut_config ($name) { + global $config; + if($config['installedpackages']['nut']['config'][0]["{$name}"]) + return $config['installedpackages']['nut']['config'][0]["{$name}"]; + return null; + } + + function nut_config_sub ($name,$len) { + global $config; + if(nut_config($name)) + return substr(nut_config($name),0,strlen(nut_config($name))-$len); + return null; + } + + function nut_write_config($file, $text, $mask = null, $uid = null) { + $conf = fopen($file, "w"); + if(!$conf) { + nut_warn("Could not open {$file} for writing."); + exit; + } + fwrite($conf, $text); + fclose($conf); + if($mask) chmod($file, $mask); + if($uid) chown($file, $uid); + } + + function nut_validate_ip($ip,$check_cdir) { + /* validate cdir */ + if($check_cdir) { + $ip_array = explode("/",$ip); + if(count($ip_array) == 2) { + if($ip_array[1] < 1 || $ip_array[1] > 32) + return false; + } else + if(count($ip_array) != 1) + return false; + } else + $ip_array[] = $ip; + + /* validate ip */ + if(!eregi("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$", $ip_array[0])) + return false; + foreach(explode(".", $ip_array[0]) as $sub) + if($sub < 0 || $sub > 256) + return false; + return true; + } + + function before_form_nut($pkg) { + /* return available serial ports */ + $handle = popen('dmesg | grep \'^sio[0-9]: type\'','r'); + $read = fread($handle, 2096); + pclose($handle); + + /* explode at the newlines */ + $read = explode("\n",$read); + + /* parse resulting text */ + foreach($read as $line) { + if($line!= '') { + $names[] = 'ttyd'.$line{3}.' (COM'.($line{3}+1).')'; + $values[] = '/dev/ttyd'.$line{3}; + } + } + + /* find correct field */ + $i = 0; + foreach ($pkg['fields']['field'] as $field) { + if ($field['fieldname'] == 'port') + break; + $i++; + } + $field = &$pkg['fields']['field'][$i]; + + /* add available serial ports */ + for ($i = 0; $i < count($values) ; $i++) + $field['options']['option'][] = array('name' => $names[$i], 'value' => $values[$i]); + } + + function validate_form_nut($post, $input_errors) { + global $config; + + /* monitor remote validation */ + if($post['monitor'] == 'remote') { + if(!$post['remotename']) + $input_errors[] = 'You must specify a name in the \'Remote UPS Name\' field'; + if($post['remotename'] && !eregi('^[a-z0-9_.-]+$', $post['remotename'])) + $input_errors[] = 'Only [Aa-Zz], [0-9], and [-_] accepted in the \'Remote UPS Name\' field'; + if(!$post['remoteaddr'] || !nut_validate_ip($post['remoteaddr'],false)) + $input_errors[] = 'You must specify a valid address \'Remote UPS Address\' field'; + if(!$post['remoteuser']) + $input_errors[] = 'You must specify a name in the \'Remote UPS User\' field'; + if(!$post['remotepass']) + $input_errors[] = 'You must specify a name in the \'Remote UPS Password\' field'; + } + + /* monitor local validation */ + elseif($post['monitor'] == 'local') { + if(!$post['name']) + $input_errors[] = 'You must specify a name in the \'Local UPS Name\' field'; + if($post['name'] && !eregi('^[a-z0-9_.-]+$', $post['name'])) + $input_errors[] = 'Only [Aa-Zz], [0-9], and [-_] accepted in the \'Local UPS Name\' field'; + if(!$post['driver']) + $input_errors[] = 'You must select a driver in the \'Local UPS Driver\' field'; + if(!$post['port']) + $input_errors[] = 'You must select a port in the \'Local UPS Port\' field'; + if($post['allowaddr'] && !nut_validate_ip($post['allowaddr'],true)) + $input_errors[] = 'You must specify a valid address \'Local Remote Access Address\' field'; + } + } + + function deinstall_package_nut() { + nut_action('stop'); + + @unlink(NUT_RCFILE); + @unlink(NUT_DIR.'/upsmon.conf'); + @unlink(NUT_DIR.'/ups.conf'); + @unlink(NUT_DIR.'/upsd.conf'); + @unlink(NUT_DIR.'/upsd.users'); + + exec('rm -rf /var/db/nut'); + } + + function sync_package_nut_remote() { + $remotename = nut_config('remotename'); + $remoteaddr = nut_config('remoteaddr'); + $remoteuser = nut_config('remoteuser'); + $remotepass = nut_config('remotepass'); + + if(!($remotename && $remoteaddr && $remoteuser && $remotepass)) + return false; + + /* upsmon.conf */ + $upsmon_conf = <<<EOD +MONITOR {$remotename}@{$remoteaddr} 1 {$remoteuser} {$remotepass} slave +MINSUPPLIES 1 +SHUTDOWNCMD "/sbin/shutdown -h +0" +POWERDOWNFLAG /etc/killpower +EOD; + + $stop = <<<EOD +if [ `pgrep upsmon | wc -l` != 0 ]; then + /usr/bin/killall upsmon + while [ `pgrep upsmon | wc -l` != 0 ]; do + sleep 1 + done + fi +EOD; + + $start = $stop."\n\t/usr/local/sbin/upsmon {$remotename}@{$remoteaddr}\n"; + + /* write out configuration */ + conf_mount_rw(); + nut_write_config(NUT_DIR.'/upsmon.conf', $upsmon_conf, 0640, 'uucp'); + write_rcfile(array( + 'file' => 'nut.sh', + 'start' => $start, + 'stop' => $stop + ) + ); + conf_mount_ro(); + + return true; + } + + function sync_package_nut_local() { + $name = nut_config('name'); + $driver = nut_config_sub('driver', 2); + $port = nut_config('port'); + $upstype = nut_config_sub('upstype', 3); + $cable = nut_config_sub('cable', 3); + $allowaddr = nut_config('allowaddr'); + $allowuser = nut_config('allowuser'); + $allowpass = nut_config('allowpass'); + + if(!($name && $driver && $port)) + return false; + + /* some installs are missing the lock dir */ + if(!is_dir('/var/spool/lock')) { + @mkdir('/var/spool'); + mkdir('/var/spool/lock'); + chown('/var/spool/lock', 'uucp'); + chgrp('/var/spool/lock', 'dialer'); + } + + /* determine permissions for port */ + if($port != 'auto') { + $port_rel = "chown root {$port}"; + $port_set = "chown uucp {$port}"; + } + + /* ups.conf */ + /* for usb ups run as root */ + if($port == 'auto') { + $ups_conf = "user=root\n"; + $ovr_user = '-u root'; + } + $ups_conf .= "[{$name}]\n"; + $ups_conf .= "driver={$driver}\n"; + $ups_conf .= "port={$port}\n"; + if($cable) + $ups_conf .= "cable={$cable}\n"; + if($upstype) + $ups_conf .= "upstype={$upstype}\n"; + + /* upsd.conf */ + $upsd_conf = "ACL all 0.0.0.0/0\n"; + $upsd_conf .= "ACL localhost 127.0.0.1/32\n"; + if($allowaddr && $allowuser) { + $upsd_conf .= "ACL remote {$allowaddr}\n"; + $upsd_conf .= "ACCEPT remote\n"; + } + $upsd_conf .= "ACCEPT localhost\n"; + $upsd_conf .= "REJECT all\n"; + + /* upsd.users */ + $upsd_users = "[monuser]\n"; + $upsd_users .= "password = mypass\n"; + $upsd_users .= "allowfrom = localhost\n"; + $upsd_users .= "upsmon master\n"; + if($allowaddr && $allowuser) { + $upsd_users .= "\n[$allowuser]\n"; + $upsd_users .= "password = $allowpass\n"; + $upsd_users .= "allowfrom = remote\n"; + $upsd_users .= "upsmon master\n"; + } + + /* upsmon.conf */ + $upsmon_conf = <<<EOD +MONITOR {$name}@localhost 1 monuser mypass master +MINSUPPLIES 1 +SHUTDOWNCMD "/sbin/shutdown -h +0" +POWERDOWNFLAG /etc/killpower +EOD; + + $stop = <<<EOD + if [ `pgrep upsmon | wc -l` != 0 ]; then + echo stopping upsmon + /usr/bin/killall upsmon + while [ `pgrep upsmon | wc -l` != 0 ]; do + sleep 1 + done + fi + if [ `pgrep upsd | wc -l` != 0 ]; then + echo stopping upsd + /usr/bin/killall upsd + fi + if [ `pgrep {$driver} | wc -l` != 0 ]; then + echo stopping {$driver} + /usr/local/libexec/nut/upsdrvctl stop + fi + sleep 1 + if [ `pgrep {$driver} | wc -l` != 0 ]; then + echo forcing {$driver} termination + /usr/bin/killall {$driver} + while [ `pgrep {$driver} | wc -l` != 0 ]; do + sleep 1 + done + fi + {$port_rel} +EOD; + + $start = <<<EOD +if [ `pgrep {$driver} | wc -l` != 0 ]; then + {$stop} + fi + {$port_set} + echo starting {$driver} + if /usr/local/libexec/nut/upsdrvctl start; then + echo starting upsd + /usr/local/sbin/upsd {$ovr_user} + echo starting upsmon + /usr/local/sbin/upsmon {$name}@localhost + else + echo {$driver} failed to start + fi +EOD; + + /* write out configuration */ + conf_mount_rw(); + nut_write_config(NUT_DIR.'/ups.conf', $ups_conf); + nut_write_config(NUT_DIR.'/upsd.conf', $upsd_conf, 0640, 'uucp'); + nut_write_config(NUT_DIR.'/upsd.users', $upsd_users, 0640, 'uucp'); + nut_write_config(NUT_DIR.'/upsmon.conf', $upsmon_conf, 0640, 'uucp'); + write_rcfile(array( + 'file' => 'nut.sh', + 'start' => $start, + 'stop' => $stop + ) + ); + conf_mount_ro(); + + return true; + } + + function sync_package_nut() { + global $config; + global $input_errors; + + config_lock(); + + nut_action('stop'); + + /* create state path */ + if(!is_dir('/var/db/nut')) { + mkdir('/var/db/nut'); + chmod('/var/db/nut', 0700); + chown('/var/db/nut', 'uucp'); + } + + if(nut_config('monitor') == 'remote') + $return = sync_package_nut_remote(); + elseif(nut_config('monitor') == 'local') + $return = sync_package_nut_local(); + + if($return && $_POST['monitor']) { + /* only start if changing settings as we have a startup script for system boot */ + /* this prevents service from starting / stopping / starting on boot */ + + nut_notice('Starting service'); + nut_action('start'); + if((int)exec('pgrep upsmon | wc -l') == 0) + nut_notice('Service failed to start: check configuration'); + + } elseif(!$return && file_exists(NUT_RCFILE)) { + /* no parameters user does not want nut running */ + /* lets stop the service and remove the rc file */ + + if(!nut_config('monitor')) + nut_notice('Service stopped: nut disabled'); + else + nut_notice('Service stopped: check configuration'); + + conf_mount_rw(); + unlink(NUT_RCFILE); + unlink(NUT_DIR.'/upsmon.conf'); + /* might not always exist */ + @unlink(NUT_DIR.'/ups.conf'); + @unlink(NUT_DIR.'/upsd.conf'); + @unlink(NUT_DIR.'/upsd.users'); + exec('rm -rf /var/db/nut'); + conf_mount_ro(); + } + + config_unlock(); + } +?> diff --git a/config/nut/nut.xml b/config/nut/nut.xml new file mode 100644 index 00000000..fdaa6295 --- /dev/null +++ b/config/nut/nut.xml @@ -0,0 +1,518 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!DOCTYPE packagegui SYSTEM "../schema/packages.dtd"> +<?xml-stylesheet type="text/xsl" href="../xsl/package.xsl"?> +<packagegui> + <copyright> + <![CDATA[ +/* $Id$ */ +/* ========================================================================== */ +/* + authng.xml + part of pfSense (http://www.pfSense.com) + Copyright (C) 2007 to whom it may belong + All rights reserved. + + Based on m0n0wall (http://m0n0.ch/wall) + Copyright (C) 2003-2006 Manuel Kasper <mk@neon1.net>. + 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> + <description>Describe your package here</description> + <requirements>Describe your package requirements here</requirements> + <faq>Currently there are no FAQ items provided.</faq> + <name>nut</name> + <version>2.0.4</version> + <title>Services: NUT</title> + <savetext>Change</savetext> + <aftersaveredirect>/status_nut.php</aftersaveredirect> + <include_file>/usr/local/pkg/nut.inc</include_file> + <menu> + <name>NUT</name> + <tooltiptext>Set Network UPS Tools settings.</tooltiptext> + <section>Services</section> + <url>/status_nut.php</url> + </menu> + <service> + <name>nut</name> + <rcfile>nut.sh</rcfile> + <executable>upsmon</executable> + </service> + <tabs> + <tab> + <text>NUT Status</text> + <url>/status_nut.php</url> + </tab> + <tab> + <text>NUT Settings</text> + <url>/pkg_edit.php?xml=nut.xml&id=0</url> + <active/> + </tab> + </tabs> + <additional_files_needed> + <prefix>/usr/local/pkg/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/nut/nut.inc</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/nut/status_nut.php</item> + </additional_files_needed> + <fields> + <field> + <fielddescr>UPS Monitoring</fielddescr> + <fieldname>monitor</fieldname> + <type>select</type> + <required/> + <options> + <option> + <name>Disabled</name> + <value></value> + </option> + <option> + <name>Local UPS</name> + <value>local</value> + </option> + <option> + <name>Remote UPS</name> + <value>remote</value> + </option> + </options> + </field> + <field> + <fielddescr><strong>Local UPS Name</strong></fielddescr> + <fieldname>name</fieldname> + <type>input</type> + </field> + <field> + <fielddescr><strong>Local UPS Model</strong></fielddescr> + <fieldname>driver</fieldname> + <description>If generic or cable specified in parenthesis you need + to select the appropriate option below.</description> + <type>select</type> + <options> + <option> + <name>APC Back-UPS (Generic)</name> + <value>genericups00</value> + </option> + <option> + <name>APC Back-UPS RS (Generic)</name> + <value>genericups01</value> + </option> + <option> + <name>APC Back-UPS Pro (Cable)</name> + <value>apcsmart00</value> + </option> + <option> + <name>APC Smart-UPS (Cable)</name> + <value>apcsmart01</value> + </option> + <option> + <name>APC Matrix-UPS</name> + <value>apcsmart02</value> + </option> + <option> + <name>APC Masterswitch (Generic)</name> + <value>genericups02</value> + </option> + <option> + <name>APC Back-UPS USB</name> + <value>newhidups00</value> + </option> + <option> + <name>APC Back-UPS LS USB</name> + <value>newhidups01</value> + </option> + <option> + <name>APC Back-UPS ES USB</name> + <value>newhidups02</value> + </option> + <option> + <name>APC Back-UPS RS USB</name> + <value>newhidups03</value> + </option> + <option> + <name>APC Back-UPS Pro USB</name> + <value>newhidups04</value> + </option> + <option> + <name>APC Smart-UPS USB</name> + <value>newhidups05</value> + </option> + <option> + <name>Belkin Regulator Pro</name> + <value>belkin00</value> + </option> + <option> + <name>Belkin Universal UPS</name> + <value>belkinunv00</value> + </option> + <option> + <name>Belkin Universal UPS USB</name> + <value>newhidups06</value> + </option> + <option> + <name>Best Power Fortress</name> + <value>bestups00</value> + </option> + <option> + <name>Best Power Fortress Telecom</name> + <value>bestups01</value> + </option> + <option> + <name>Best Power Axxium Rackmount</name> + <value>bestups02</value> + </option> + <option> + <name>Best Power Patriot Pro</name> + <value>bestups03</value> + </option> + <option> + <name>Best Power Patriot (Generic/Cable)</name> + <value>genericups03</value> + </option> + <option> + <name>Best Power Micro-Ferrups</name> + <value>bestuferrups00</value> + </option> + <option> + <name>Best Power Fortress/Ferrups</name> + <value>bestfcom00</value> + </option> + <option> + <name>Cyber Power Systems 320AVR</name> + <value>cyberpower00</value> + </option> + <option> + <name>Cyber Power Systems 500AVR</name> + <value>cyberpower01</value> + </option> + <option> + <name>Cyber Power Systems 650AVR</name> + <value>cyberpower02</value> + </option> + <option> + <name>Cyber Power Systems 700AVR</name> + <value>cyberpower03</value> + </option> + <option> + <name>Cyber Power Systems 800AVR</name> + <value>cyberpower04</value> + </option> + <option> + <name>Cyber Power Systems 850AVR</name> + <value>cyberpower05</value> + </option> + <option> + <name>Cyber Power Systems 900AVR</name> + <value>cyberpower06</value> + </option> + <option> + <name>Cyber Power Systems 1250AVR</name> + <value>cyberpower07</value> + </option> + <option> + <name>Cyber Power Systems 1500AVR</name> + <value>cyberpower08</value> + </option> + <option> + <name>Inform GUARD Line Interactive</name> + <value>powercom00</value> + </option> + <option> + <name>Meta System HF Line</name> + <value>metasys00</value> + </option> + <option> + <name>Meta System HF Millennium</name> + <value>metasys01</value> + </option> + <option> + <name>Meta System HF TOP Line</name> + <value>metasys02</value> + </option> + <option> + <name>Meta System ECO Network</name> + <value>metasys03</value> + </option> + <option> + <name>Meta System ECO</name> + <value>metasys04</value> + </option> + <option> + <name>Meta System ally HF</name> + <value>metasys05</value> + </option> + <option> + <name>Meta System Megaline</name> + <value>metasys06</value> + </option> + <option> + <name>MGE UPS SYSTEMS NOVA AVR</name> + <value>mge-shut00</value> + </option> + <option> + <name>MGE UPS SYSTEMS Pulsar Ellipse</name> + <value>mge-shut01</value> + </option> + <option> + <name>MGE UPS SYSTEMS Ellipse Office</name> + <value>mge-shut02</value> + </option> + <option> + <name>MGE UPS SYSTEMS Pulsar EXtreme</name> + <value>mge-shut03</value> + </option> + <option> + <name>MGE UPS SYSTEMS Comet</name> + <value>mge-shut04</value> + </option> + <option> + <name>MGE UPS SYSTEMS Pulsar Esprit</name> + <value>mge-shut05</value> + </option> + <option> + <name>MGE UPS SYSTEMS Evolution</name> + <value>mge-shut06</value> + </option> + <option> + <name>MGE UPS SYSTEMS Comet USB</name> + <value>newhidups07</value> + </option> + <option> + <name>MGE UPS SYSTEMS Protection Center USB</name> + <value>newhidups08</value> + </option> + <option> + <name>MGE UPS SYSTEMS NOVA AVR USB</name> + <value>newhidups09</value> + </option> + <option> + <name>MGE UPS SYSTEMS Pulsar Ellipse USB</name> + <value>newhidups10</value> + </option> + <option> + <name>MGE UPS SYSTEMS Ellipse Office USB</name> + <value>newhidups11</value> + </option> + <option> + <name>MGE UPS SYSTEMS Pulsar Evolution USB</name> + <value>newhidups12</value> + </option> + <option> + <name>MGE UPS SYSTEMS Evolution USB</name> + <value>newhidups13</value> + </option> + <option> + <name>MGE UPS SYSTEMS Pulsar USB</name> + <value>newhidups14</value> + </option> + <option> + <name>MicroDowell B.Box BP</name> + <value>cpsups00</value> + </option> + <option> + <name>Microsol Solis</name> + <value>solis00</value> + </option> + <option> + <name>Microsol Rhino</name> + <value>rhino00</value> + </option> + <option> + <name>Mustek Various</name> + <value>megatec00</value> + </option> + <option> + <name>Mustek Powermust</name> + <value>megatec01</value> + </option> + <option> + <name>Mustek Powermust USB</name> + <value>megatec02</value> + </option> + <option> + <name>Powercom SMK</name> + <value>megatec03</value> + </option> + <option> + <name>Powercom ULT</name> + <value>megatec04</value> + </option> + <option> + <name>Powercom Trust</name> + <value>powercom01</value> + </option> + <option> + <name>Powercom Various</name> + <value>powercom02</value> + </option> + <option> + <name>Tripp-Lite SmartUPS</name> + <value>tripplite00</value> + </option> + <option> + <name>Tripp-Lite SmartOnline</name> + <value>tripplitesu00</value> + </option> + <option> + <name>Tripp-Lite AVR USB</name> + <value>newhidups15</value> + </option> + <option> + <name>Tripp-Lite OMNI USB</name> + <value>newhidups16</value> + </option> + <option> + <name>Tripp-Lite OMNIVUS USB</name> + <value>tripplite_usb00</value> + </option> + <option> + <name>Tripp-Lite SMART USB</name> + <value>tripplite_usb01</value> + </option> + </options> + </field> + <field> + <fielddescr><strong>Local UPS Port</strong></fielddescr> + <fieldname>port</fieldname> + <type>select</type> + <options> + <option> + <name>auto (USB only)</name> + <value>auto</value> + </option> + </options> + </field> + <field> + <fielddescr>Local UPS Generic Type</fielddescr> + <fieldname>upstype</fieldname> + <type>select</type> + <options> + <option> + <name></name> + <value></value> + </option> + <option> + <name>1 (APC Back-UPS using 940-0095A/C cables)</name> + <value>1 00</value> + </option> + <option> + <name>2 (APC Back-UPS using 940-0020B/C cables)</name> + <value>2 00</value> + </option> + <option> + <name>9 (APC Back-UPS using 940-0023A cable)</name> + <value>9 00</value> + </option> + <option> + <name>12 (APC Back-UPS Office using 940-0119A cable)</name> + <value>12 00</value> + </option> + <option> + <name>12 (APC Masterswitch using 940-0020 cable)</name> + <value>12 01</value> + </option> + <option> + <name>20 (APC Back-UPS RS)</name> + <value>20 00</value> + </option> + <option> + <name>6 (Best Power Patriot using INT51 cable)</name> + <value>6 00</value> + </option> + </options> + </field> + <field> + <fielddescr>Local UPS Cable Type</fielddescr> + <fieldname>cable</fieldname> + <type>select</type> + <options> + <option> + <name></name> + <value></value> + </option> + <option> + <name>940-0095B (Gray Cable)</name> + <value>940-0095B 00</value> + </option> + <option> + <name>940-0024C (Black Cable)</name> + <value>940-0024C 00</value> + </option> + </options> + </field> + <field> + <fielddescr>Local Remote Access Address <br>(ex: 192.168.1.0/24)</fielddescr> + <fieldname>allowaddr</fieldname> + <type>input</type> + </field> + <field> + <fielddescr>Local Remote Access User</fielddescr> + <fieldname>allowuser</fieldname> + <type>input</type> + </field> + <field> + <fielddescr>Local Remote Acces Password</fielddescr> + <fieldname>allowpass</fieldname> + <type>password</type> + </field> + <field> + <fielddescr><strong>Remote UPS Name</strong></fielddescr> + <fieldname>remotename</fieldname> + <type>input</type> + </field> + <field> + <fielddescr><strong>Remote UPS Address</strong> <br>(ex: 192.168.1.10)</fielddescr> + <fieldname>remoteaddr</fieldname> + <type>input</type> + </field> + <field> + <fielddescr><strong>Remote UPS User</strong></fielddescr> + <fieldname>remoteuser</fieldname> + <type>input</type> + </field> + <field> + <fielddescr><strong>Remote UPS Password</strong></fielddescr> + <fieldname>remotepass</fieldname> + <type>password</type> + </field> + </fields> + <custom_php_command_before_form> + before_form_nut(&$pkg); + </custom_php_command_before_form> + <custom_php_validation_command> + validate_form_nut($_POST, &$input_errors); + </custom_php_validation_command> + <custom_php_resync_config_command> + sync_package_nut(); + </custom_php_resync_config_command> + <custom_php_deinstall_command> + deinstall_package_nut(); + </custom_php_deinstall_command> +</packagegui> diff --git a/config/nut/status_nut.php b/config/nut/status_nut.php new file mode 100644 index 00000000..a181734f --- /dev/null +++ b/config/nut/status_nut.php @@ -0,0 +1,242 @@ +<?php +/* + status_nut.php + part of pfSense (http://www.pfsense.com/) + + Copyright (C) 2007 Ryan Wagoner <rswagoner@gmail.com>. + 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("guiconfig.inc"); + +$nut_config = $config['installedpackages']['nut']['config'][0]; + +/* functions */ + +function tblopen () { + print('<table width="100%" class="tabcont" cellspacing="0" cellpadding="6">'."\n"); +} + +function tblclose () { + print("</table>\n"); +} + +function tblrow ($name, $value, $symbol = null) { + if(!$value) return; + + if($symbol == '°') + $value = sprintf("%.1f", $value); + + if($symbol == 'Hz') + $value = sprintf("%d", $value); + + print(<<<EOD +<tr> + <td class="vncellreq" width="100px">{$name}</td> + <td class="vtable">{$value}{$symbol}</td> +<tr> +EOD + ."\n"); +} + +function tblrowbar ($name, $value, $symbol, $red, $yellow, $green) { + if(!$value) return; + + $value = sprintf("%.1f", $value); + + $red = explode('-', $red); + $yellow = explode('-', $yellow); + $green = explode('-', $green); + + sort($red); + sort($yellow); + sort($green); + + if($value >= $red[0] && $value <= ($red[0]+9)) { + $color = 'black'; + $bgcolor = 'red'; + } + if($value >= ($red[0]+10) && $value <= $red[1]) { + $color = 'white'; + $bgcolor = 'red'; + } + if($value >= $yellow[0] && $value <= $yellow[1]) { + $color = 'black'; + $bgcolor = 'yellow'; + } + if($value >= $green[0] && $value <= ($green[0]+9)) { + $color = 'black'; + $bgcolor = 'green'; + } + if($value >= ($green[0]+10) && $value <= $green[1]) { + $color = 'white'; + $bgcolor = 'green'; + } + + print(<<<EOD +<tr> + <td class="vncellreq" width="100px">{$name}</td> + <td class="vtable"> + <div style="width: 125px; height: 12px; border-top: thin solid gray; border-bottom: thin solid gray;"> + <div style="width: {$value}{$symbol}; height: 12px; background-color: {$bgcolor};"> + <div style="text-align: center; color: {$color}">{$value}{$symbol}</div> + </div> + </div> + </td> +<tr> +EOD + ."\n"); +} + +/* defaults to this page but if no settings are present, redirect to setup page */ +if(!$nut_config['monitor']) + Header("Location: /pkg_edit.php?xml=nut.xml&id=0"); + +$pgtitle = "Status: NUT Status"; +include("head.inc"); +/* put your custom HTML head content here */ +/* using some of the $pfSenseHead function calls */ +//$pfSenseHead->addMeta("<meta http-equiv=\"refresh\" content=\"120;url={$_SERVER['SCRIPT_NAME']}\" />"); +//echo $pfSenseHead->getHTML(); + +?> +<body link="#0000CC" vlink="#0000CC" alink="#0000CC"> +<?php include("fbegin.inc"); ?> +<p class="pgtitle"><?=$pgtitle?></font></p> +<?php if ($savemsg) print_info_box($savemsg); ?> + +<div id="mainlevel"> +<table width="100%" border="0" cellpadding="0" cellspacing="0"> +<?php + $tab_array = array(); + $tab_array[] = array(gettext("NUT Status "), true, "/status_nut.php"); + $tab_array[] = array(gettext("NUT Settings "), false, "/pkg_edit.php?xml=nut.xml&id=0"); + display_top_tabs($tab_array); +?> +</table> +<table width="100%" border="0" cellpadding="0" cellspacing="0"> + <tr> + <td> +<?php + tblopen(); + + $running = ((int)exec('pgrep upsmon | wc -l') > 0) ? true : false; + + if($nut_config['monitor'] == 'local') { + tblrow('Monitoring:','Local UPS'); + $cmd = "upsc {$nut_config['name']}@localhost"; + } else { + tblrow('Monitoring:','Remote UPS'); + $cmd = "upsc {$nut_config['remotename']}@{$nut_config['remoteaddr']}"; + } + + if($running) + $handle = popen($cmd, 'r'); + else + tblrow('ERROR:','NUT is enabled, however the service is not running!'); + + if($handle) { + $read = fread($handle, 4096); + pclose($handle); + + $lines = explode("\n", $read); + $ups = array(); + foreach($lines as $line) { + $line = explode(':', $line); + $ups[$line[0]] = trim($line[1]); + } + + if(count($lines) == 1) + tblrow('ERROR:', 'Data stale!'); + + tblrow('Model:', $ups['ups.model']); + + $status = explode(' ', $ups['ups.status']); + foreach($status as $condition) { + if($disp_status) $disp_status .= ', '; + switch ($condition) { + case 'WAIT': + $disp_status .= 'Waiting'; + break; + case 'OFF': + $disp_status .= 'Off Line'; + break; + case 'OL': + $disp_status .= 'On Line'; + break; + case 'OB': + $disp_status .= 'On Battery'; + break; + case 'TRIM': + $disp_status .= 'SmartTrim'; + break; + case 'BOOST': + $disp_status .= 'SmartBoost'; + break; + case 'OVER': + $disp_status .= 'Overload'; + break; + case 'LB': + $disp_status .= 'Battery Low'; + break; + case 'RB': + $disp_status .= 'Replace Battery'; + break; + case 'CAL': + $disp_status .= 'Calibration'; + break; + default: + $disp_status .= $condition; + break; + } + } + tblrow('Status:', $disp_status); + + tblrowbar('Load:', $ups['ups.load'], '%', '100-80', '79-60', '59-0'); + tblrowbar('Battery Charge:', $ups['battery.charge'], '%', '0-29' ,'30-79', '80-100'); + + tblclose(); + tblopen(); + + tblrow('Runtime Remaining:', $ups['battery.runtime'], ' seconds'); + tblrow('Battery Voltage:', $ups['battery.voltage'], 'V'); + tblrow('Input Voltage:', $ups['input.voltage'], 'V'); + tblrow('Input Frequency:', $ups['input.frequency'], 'Hz'); + tblrow('Output Voltage:', $ups['output.voltage'], 'V'); + tblrow('Temperature:', $ups['ups.temperature'], '°'); + } + + tblclose(); +?> + </td> + </tr> +</table> +<?php + /* display upsc array */ + /*print('<pre>'); print_r($ups); print('</pre>');*/ +?> +</div> +<?php include("fend.inc"); ?> +</body> +</html> |