diff options
author | Michele Di Maria <michele@nt2.it> | 2011-12-16 19:25:50 +0100 |
---|---|---|
committer | Michele Di Maria <michele@nt2.it> | 2011-12-16 19:25:50 +0100 |
commit | a384a219085afdae14b50a5b5bd922ad7db88088 (patch) | |
tree | d4385957f6ca8f111ca052ece63e9c6f79f92848 /config/lcdproc-dev | |
parent | d027619121e1c73c361b3cf8191b3015e9c42379 (diff) | |
download | pfsense-packages-a384a219085afdae14b50a5b5bd922ad7db88088.tar.gz pfsense-packages-a384a219085afdae14b50a5b5bd922ad7db88088.tar.bz2 pfsense-packages-a384a219085afdae14b50a5b5bd922ad7db88088.zip |
Updates LCDProc to version 0.5.4.
Include a full list of all the drivers available (default build).
This is a development version under test, it's not granted it works in all conditions.
Reference: http://redmine.pfsense.org/issues/1406
Diffstat (limited to 'config/lcdproc-dev')
-rw-r--r-- | config/lcdproc-dev/lcdproc.inc | 425 | ||||
-rw-r--r-- | config/lcdproc-dev/lcdproc.xml | 327 | ||||
-rw-r--r-- | config/lcdproc-dev/lcdproc_client.php | 721 | ||||
-rw-r--r-- | config/lcdproc-dev/lcdproc_screens.xml | 101 |
4 files changed, 1574 insertions, 0 deletions
diff --git a/config/lcdproc-dev/lcdproc.inc b/config/lcdproc-dev/lcdproc.inc new file mode 100644 index 00000000..d4ff92fa --- /dev/null +++ b/config/lcdproc-dev/lcdproc.inc @@ -0,0 +1,425 @@ +<?php +/* $Id$ */ +/* + lcdproc.inc + Copyright (C) 2007 Seth Mos <seth.mos@xs4all.nl> + 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"); + + /* LCDproc */ + define('LCDPROC_RCFILE', '/usr/local/etc/rc.d/lcdproc.sh'); + define('LCDPROC_CLIENT', '/tmp/lcdclient.sh'); + define('LCDPROC_CONFIG','/usr/local/etc/LCDd.conf'); + define('LCDPROC_HOST','localhost'); + define('LCDPROC_PORT','13666'); + + function lcdproc_notice ($msg) { syslog(LOG_NOTICE, "lcdproc: {$msg}"); } + function lcdproc_warn ($msg) { syslog(LOG_WARNING, "lcdproc: {$msg}"); } + + function lcdproc_action ($action) { + if (file_exists(LCDPROC_RCFILE)) + mwexec(LCDPROC_RCFILE.' '.$action); + } + + function lcdproc_running () { + if((int)exec('pgrep LCDd | wc -l') > 0) + return true; + return false; + } + + function lcdproc_write_config($file, $text) { + $handle = fopen($file, 'w'); + if(!$handle) { + lcdproc_warn("Could not open {$file} for writing."); + exit; + } + fwrite($handle, $text); + fclose($handle); + } + + function lcdproc_write_script($file, $text) { + $handle = fopen($file, 'wx'); + if(!$handle) { + lcdproc_warn("Could not open {$file} for writing."); + exit; + } + fwrite($handle, $text); + fclose($handle); + chmod($file, 0755); + } + + function before_form_lcdproc($pkg) { + global $config; + + config_lock(); + + config_unlock(); + } + + function before_form_lcdproc_screens($pkg) { + global $config; + + config_lock(); + + config_unlock(); + } + + function validate_form_lcdproc($post, $input_errors) { + if($post['comport']) { + switch($post['comport']) { + case "none": + continue; + break; + case "com2": + continue; + break; + case "ucom1": + continue; + break; + case "ucom2": + continue; + break; + case "lpt1": + continue; + break; + case "ugen0.2": + continue; + break; + case "ugen1.2": + continue; + break; + case "ugen2.2": + continue; + break; + default: + $input_errors[] = "The chosen com port is not valid"; + break; + } + } + if($post['size']) { + switch($post['size']) { + case "12x1": + continue; + break; + case "12x2": + continue; + break; + case "12x4": + continue; + break; + case "16x1": + continue; + break; + case "16x2": + continue; + break; + case "16x4": + continue; + break; + case "20x1": + continue; + break; + case "20x2": + continue; + break; + case "20x4": + continue; + break; + default: + $input_errors[] = "The chosen display size is not valid"; + break; + } + } + } + function validate_form_lcdproc_screens($post, $input_errors) { + // No validation required ?! + } + + function sync_package_lcdproc_screens() { + sync_package_lcdproc(); + } + function sync_package_lcdproc() { + global $g; + global $config; + global $input_errors; + + config_lock(); + + $lcdproc_config = $config['installedpackages']['lcdproc']['config'][0]; + $lcdproc_screens_config = $config['installedpackages']['lcdprocscreens']['config'][0]; + + /* since config is written before this file invoked we don't need to read post data */ + if($lcdproc_config['enable'] && ($lcdproc_config['comport'] != "none")) { + switch($lcdproc_config['comport']) { + case "com2": + $realport = "/dev/cua1"; + break; + case "ucom1": + $realport = "/dev/cuaU0"; + break; + case "ucom2": + $realport = "/dev/cuaU1"; + break; + case "lpt1": + $realport = "/dev/lpt0"; + break; + case "ugen0.2": + $realport = "/dev/ugen0.2"; + break; + case "ugen1.2": + $realport = "/dev/ugen1.2"; + break; + case "ugen2.2": + $realport = "/dev/ugen2.2"; + break; + default: + lcdproc_warn("The selected com port is not valid!"); + return; + } + + $config_text = "[server]\n"; + $config_text .= "Driver={$lcdproc_config[driver]}\n"; + $config_text .= "Bind=127.0.0.1\n"; + $config_text .= "Port=13666\n"; + $config_text .= "ReportLevel=3\n"; + $config_text .= "ReportToSyslog=yes\n"; + $config_text .= "WaitTime={$lcdproc_config[refresh_frequency]}\n"; + $config_text .= "User=nobody\n"; + $config_text .= "ServerScreen=no\n"; + $config_text .= "Foreground=no\n"; + $config_text .= "DriverPath=/usr/local/lib/lcdproc/\n"; + $config_text .= "GoodBye=\"Thanks for using\"\n"; + $config_text .= "GoodBye=\" {$g['product_name']} \"\n"; + /* FIXME: Specific to the pyramid project */ + $config_text .= "ToggleRotateKey=Enter\n"; + $config_text .= "PrevScreenKey=Left\n"; + $config_text .= "NextScreenKey=Right\n"; + $config_text .= "ScrollUpKey=Up\n"; + $config_text .= "ScrollDownKey=Down\n"; + /* FIXME: pyramid test menu */ + $config_text .= "[menu]\n"; + $config_text .= "MenuKey=Escape\n"; + $config_text .= "EnterKey=Enter\n"; + $config_text .= "UpKey=Up\n"; + $config_text .= "DownKey=Down\n"; + + /* lcdproc default driver definitions */ + switch($lcdproc_config[driver]) { + case "bayrad": + $config_text .= "[{$lcdproc_config['driver']}]\n"; + $config_text .= "Device={$realport}\n"; + $config_text .= "Speed=9600\n"; + break; + case "CFontz": + $config_text .= "[{$lcdproc_config['driver']}]\n"; + $config_text .= "Device={$realport}\n"; + $config_text .= "Size={$lcdproc_config['size']}\n"; + $config_text .= "Contrast=350\n"; + $config_text .= "Brightness=1000\n"; + $config_text .= "OffBrightness=50\n"; + $config_text .= "Speed=9600\n"; + $config_text .= "NewFirmware=no\n"; + $config_text .= "Reboot=no\n"; + break; + case "CFontz633": + $config_text .= "[{$lcdproc_config['driver']}]\n"; + $config_text .= "Device={$realport}\n"; + $config_text .= "Size={$lcdproc_config['size']}\n"; + $config_text .= "Contrast=350\n"; + $config_text .= "Brightness=1000\n"; + $config_text .= "OffBrightness=50\n"; + $config_text .= "Speed=19200\n"; + $config_text .= "NewFirmware=yes\n"; + $config_text .= "Reboot=yes\n"; + break; + case "CFontzPacket": + $config_text .= "[{$lcdproc_config['driver']}]\n"; + $config_text .= "Device={$realport}\n"; + $config_text .= "Model=635\n"; + $config_text .= "Size={$lcdproc_config['size']}\n"; + $config_text .= "Contrast=350\n"; + $config_text .= "Brightness=1000\n"; + $config_text .= "OffBrightness=50\n"; + $config_text .= "Speed=115200\n"; + $config_text .= "NewFirmware=yes\n"; + $config_text .= "Reboot=yes\n"; + break; + case "curses": + $config_text .= "[{$lcdproc_config['driver']}]\n"; + $config_text .= "Foreground=blue\n"; + $config_text .= "Background=cyan\n"; + $config_text .= "Backlight=red\n"; + $config_text .= "Size={$lcdproc_config['size']}\n"; + $config_text .= "TopLeftX=7\n"; + $config_text .= "TopLeftY=7\n"; + $config_text .= "UseACS=no\n"; + break; + case "CwLnx": + $config_text .= "[{$lcdproc_config['driver']}]\n"; + $config_text .= "Model=12232\n"; + $config_text .= "Device={$realport}\n"; + $config_text .= "Size={$lcdproc_config['size']}\n"; + $config_text .= "Speed=19200\n"; + $config_text .= "Reboot=no\n"; + break; + case "ea65": + $config_text .= "[{$lcdproc_config['driver']}]\n"; + $config_text .= "Device={$realport}\n"; + $config_text .= "OffBrightness=0\n"; + $config_text .= "Brightness=500\n"; + break; + case "hd44780": + $config_text .= "[{$lcdproc_config['driver']}]\n"; + $config_text .= "driverpath=/usr/local/lib/lcdproc/\n"; + $config_text .= "ConnectionType=lcd2usb\n"; + $config_text .= "Speed=0\n"; + $config_text .= "Keypad=no\n"; + $config_text .= "Contrast=850\n"; + $config_text .= "Brightness=800\n"; + $config_text .= "OffBrightness=0\n"; + $config_text .= "Backlight=yes\n"; + $config_text .= "OutputPort=no\n"; + $config_text .= "Charmap=hd44780_default\n"; + $config_text .= "DelayMult=1\n"; + $config_text .= "DelayBus=true\n"; + $config_text .= "Size={$lcdproc_config['size']}\n"; + break; + case "nexcom": + $config_text .= "[{$lcdproc_config['driver']}]\n"; + $config_text .= "driverpath =/usr/local/lib/lcdproc/\n"; + $config_text .= "Device={$realport}\n"; + $config_text .= "Size={$lcdproc_config['size']}\n"; + break; + case "picolcd": + $config_text .= "[{$lcdproc_config['driver']}]\n"; + $config_text .= "driverpath=/usr/local/lib/lcdproc/\n"; + $config_text .= "Device={$realport}\n"; + $config_text .= "Size={$lcdproc_config['size']}\n"; + $config_text .= "KeyTimeout=500\n"; + $config_text .= "Brightness=1000\n"; + $config_text .= "Blacklight_Timer=60\n"; + $config_text .= "Contrast=1000\n"; + $config_text .= "Keylights=on\n"; + $config_text .= "Key0Light=on\n"; + $config_text .= "Key1Light=off\n"; + $config_text .= "Key2Light=off\n"; + $config_text .= "Key3Light=off\n"; + $config_text .= "Key4Light=off\n"; + $config_text .= "Key5Light=off\n"; + break; + case "pyramid": + $config_text .= "[{$lcdproc_config['driver']}]\n"; + $config_text .= "Device={$realport}\n"; + $config_text .= "Size={$lcdproc_config['size']}\n"; + break; + case "SureElec": + $config_text .= "[{$lcdproc_config['driver']}]\n"; + $config_text .= "driverpath =/usr/local/lib/lcdproc/\n"; + $config_text .= "Device={$realport}\n"; + $config_text .= "Size={$lcdproc_config['size']}\n"; + $config_text .= "Edition=2\n"; + $config_text .= "Contrast=200\n"; + $config_text .= "Brightness=480\n"; + $config_text .= "Speed=19200\n"; + break; + default: + lcdproc_warn("The chosen lcdproc driver is not a valid choice"); + unset($lcdproc_config[driver]); + } + + /* generate rc file start and stop */ + $client_script = <<<EOD +#!/bin/sh + +# script starts a lcd client and always keeps it active. +counter=1 +while [ "\$counter" -ne 0 ] +do + # loop the client to drive the display + /usr/local/bin/php -f /usr/local/pkg/lcdproc_client.php + sleep 1 +done + +EOD; + + /* generate rc file start and stop */ + $stop = <<<EOD + +if [ `ps auxw |awk '/LCD[d]/ {print $2}'| wc -l` != 0 ]; then + ps auxw |awk '/LCD[d]/ {print $2}'|xargs kill + sleep 1 +fi +if [ `ps auxw |awk '/lcdclient.s[h]/ {print $2}'| wc -l` != 0 ]; then + ps auxw |awk '/lcdclient.s[h]/ {print $2}'|xargs kill + sleep 1 +fi + +EOD; + $start = $stop ."\n"; + $start .= "\t/usr/local/sbin/LCDd -c ". LCDPROC_CONFIG ."\n"; + $start .= "\t". LCDPROC_CLIENT ." &\n"; + + /* write out the configuration */ + conf_mount_rw(); + lcdproc_write_script(LCDPROC_CLIENT, $client_script); + lcdproc_write_config(LCDPROC_CONFIG, $config_text); + write_rcfile(array( + 'file' => 'lcdproc.sh', + 'start' => $start, + 'stop' => $stop + )); + conf_mount_ro(); + + /* or restart lcdproc if settings were changed */ + if(lcdproc_running($_POST['comport'])) { + lcdproc_notice("Restarting service lcdproc"); + lcdproc_action('restart'); + } + } + + if((! $lcdproc_config['driver']) || ($lcdproc_config['comport'] == "none")) { + /* no parameters user does not want lcdproc running */ + /* lets stop the service and remove the rc file */ + + if(file_exists(LCDPROC_RCFILE)) { + if(!$lcdproc_config['enable']) { + lcdproc_notice('Stopping service: lcdproc disabled'); + } else { + lcdproc_notice('Stopping service: no com port selected'); + } + lcdproc_action('stop'); + conf_mount_rw(); + unlink(LCDPROC_RCFILE); + unlink(LCDPROC_CLIENT); + unlink(LCDPROC_CONFIG); + conf_mount_ro(); + } + } + config_unlock(); + } + +?>
\ No newline at end of file diff --git a/config/lcdproc-dev/lcdproc.xml b/config/lcdproc-dev/lcdproc.xml new file mode 100644 index 00000000..c5040451 --- /dev/null +++ b/config/lcdproc-dev/lcdproc.xml @@ -0,0 +1,327 @@ +<?xml version="1.0" encoding="utf-8" ?> +<packagegui> + <title>Services: LCDproc 0.5.4 pkg v. 0.1</title> + <name>lcdproc</name> + <version>0.5.4 pkg v. 0.1</version> + <savetext>Save</savetext> + <include_file>/usr/local/pkg/lcdproc.inc</include_file> + <tabs> + <tab> + <text>Server</text> + <url>/pkg_edit.php?xml=lcdproc.xml&id=0</url> + <active/> + </tab> + <tab> + <text>Screens</text> + <url>/pkg_edit.php?xml=lcdproc_screens.xml&id=0</url> + </tab> + </tabs> + <menu> + <name>LCDproc</name> + <tooltiptext>Set LCDproc settings such as display driver and com port</tooltiptext> + <section>Services</section> + <url>/pkg_edit.php?xml=lcdproc.xml&id=0</url> + </menu> + <additional_files_needed> + <item>http://www.pfsense.org/packages/config/lcdproc/lcdproc.inc</item> + <prefix>/usr/local/pkg/</prefix> + <chmod>0755</chmod> + </additional_files_needed> + <additional_files_needed> + <item>http://www.pfsense.org/packages/config/lcdproc/lcdproc_screens.xml</item> + <prefix>/usr/local/pkg/</prefix> + <chmod>0755</chmod> + </additional_files_needed> + <additional_files_needed> + <item>http://www.pfsense.org/packages/config/lcdproc/lcdproc_client.php</item> + <prefix>/usr/local/pkg/</prefix> + <chmod>0755</chmod> + </additional_files_needed> + <additional_files_needed> + <item>http://files.pfsense.org/misc/nexcom.so</item> + <prefix>/usr/local/lib/lcdproc/</prefix> + <chmod>0755</chmod> + </additional_files_needed> + <service> + <name>lcdproc</name> + <rcfile>lcdproc.sh</rcfile> + <executable>LCDd</executable> + <description>LCD Driver</description> + </service> + <fields> + <field> + <fielddescr>Enable LCDproc</fielddescr> + <fieldname>enable</fieldname> + <type>checkbox</type> + </field> + <field> + <fieldname>comport</fieldname> + <fielddescr>Com Port</fielddescr> + <description>Set the com port LCDproc should use.</description> + <type>select</type> + <options> + <option> + <value>none</value> + <name>none</name> + </option> + <option> + <value>com2</value> + <name>Serial Com port 2 (/dev/cua1)</name> + </option> + <option> + <value>ucom1</value> + <name>USB Com port 1 (/dev/cuaU0)</name> + </option> + <option> + <value>ucom2</value> + <name>USB Com port 2 (/dev/cuaU1)</name> + </option> + <option> + <value>lpt1</value> + <name>Parallel port 1 (/dev/lpt0)</name> + </option> + <option> + <value>ugen0.2</value> + <name>USB Com port 1 alternate (/dev/ugen0.2)</name> + </option> + <option> + <value>ugen1.2</value> + <name>USB Com port 2 alternate (/dev/ugen1.2)</name> + </option> + <option> + <value>ugen2.2</value> + <name>USB Com port 3 alternate (/dev/ugen2.2)</name> + </option> + </options> + <default_value>ucom1</default_value> + </field> + <field> + <fieldname>size</fieldname> + <fielddescr>Display Size</fielddescr> + <description>Set the display size lcdproc should use.</description> + <type>select</type> + <options> + <option> + <value>12x1</value> + <name>1 rows 12 colums</name> + </option> + <option> + <value>12x2</value> + <name>2 rows 12 colums</name> + </option> + <option> + <value>12x4</value> + <name>4 rows 12 colums</name> + </option> + <option> + <value>16x1</value> + <name>1 row 16 colums</name> + </option> + <option> + <value>16x2</value> + <name>2 rows 16 colums</name> + </option> + <option> + <value>16x4</value> + <name>4 rows 16 colums</name> + </option> + <option> + <value>20x1</value> + <name>1 row 20 colums</name> + </option> + <option> + <value>20x2</value> + <name>2 rows 20 colums</name> + </option> + <option> + <value>20x4</value> + <name>4 rows 20 colums</name> + </option> + </options> + <default_value>16x2</default_value> + </field> + <field> + <fieldname>driver</fieldname> + <fielddescr>Driver</fielddescr> + <description>Set the LCD driver LCDproc should use.</description> + <type>select</type> + <options> + <option> + <value>bayrad</value> + <name>bayrad</name> + </option> + <option> + <value>CFontz</value> + <name>CrystalFontz</name> + </option> + <option> + <value>CFontz633</value> + <name>CrystalFontz 633</name> + </option> + <option> + <value>CFontzPacket</value> + <name>CrystalFontz Packet</name> + </option> + <option> + <value>curses</value> + <name>curses</name> + </option> + <option> + <value>CwLnx</value> + <name>CwLnx</name> + </option> + <option> + <value>ea65</value> + <name>ea65</name> + </option> + <option> + <value>EyeboxOne</value> + <name>EyeboxOne</name> + </option> + <option> + <value>glk</value> + <name>glk</name> + </option> + <option> + <value>hd44780</value> + <name>hd44780</name> + </option> + <option> + <value>icp_a106</value> + <name>icp_a106</name> + </option> + <option> + <value>IOWarrior</value> + <name>IOWarrior</name> + </option> + <option> + <value>lb216</value> + <name>lb216</name> + </option> + <option> + <value>lcdm001</value> + <name>lcdm001</name> + </option> + <option> + <value>lcterm</value> + <name>lcterm</name> + </option> + <option> + <value>MD8800</value> + <name>MD8800</name> + </option> + <option> + <value>ms6931</value> + <name>ms6931</name> + </option> + <option> + <value>mtc_s16209x</value> + <name>mtc_s16209x</name> + </option> + <option> + <value>MtxOrb</value> + <name>MtxOrb</name> + </option> + <option> + <value>nexcom</value> + <name>nexcom</name> + </option> + <option> + <value>NoritakeVFD</value> + <name>NoritakeVFD</name> + </option> + <option> + <value>picolcd</value> + <name>picolcd</name> + </option> + <option> + <value>pyramid</value> + <name>pyramid</name> + </option> + <option> + <value>sed1330</value> + <name>sed1330</name> + </option> + <option> + <value>sed1520</value> + <name>sed1520</name> + </option> + <option> + <value>serialPOS</value> + <name>serialPOS</name> + </option> + <option> + <value>serialVFD</value> + <name>serialVFD</name> + </option> + <option> + <value>shuttleVFD</value> + <name>shuttleVFD</name> + </option> + <option> + <value>sli</value> + <name>sli</name> + </option> + <option> + <value>stv5730</value> + <name>stv5730</name> + </option> + <option> + <value>SureElec</value> + <name>SureElec</name> + </option> + <option> + <value>t6963</value> + <name>t6963</name> + </option> + <option> + <value>text</value> + <name>text</name> + </option> + <option> + <value>tyan</value> + <name>tyan</name> + </option> + </options> + <default_value>pyramid</default_value> + </field> + <field> + <fieldname>refresh_frequency</fieldname> + <fielddescr>Refresh frequency</fielddescr> + <description>Set the refresh frequency of the information on the LCD Panel</description> + <type>select</type> + <options> + <option> + <value>1</value> + <name>1 second</name> + </option> + <option> + <value>2</value> + <name>2 seconds</name> + </option> + <option> + <value>3</value> + <name>3 seconds</name> + </option> + <option> + <value>5</value> + <name>5 seconds</name> + </option> + <option> + <value>10</value> + <name>10 seconds</name> + </option> + </options> + <default_value>5</default_value> + </field> + </fields> + <custom_php_command_before_form> + before_form_lcdproc(&$pkg); + </custom_php_command_before_form> + <custom_php_validation_command> + validate_form_lcdproc($_POST, &$input_errors); + </custom_php_validation_command> + <custom_php_resync_config_command> + sync_package_lcdproc(); + </custom_php_resync_config_command> +</packagegui> diff --git a/config/lcdproc-dev/lcdproc_client.php b/config/lcdproc-dev/lcdproc_client.php new file mode 100644 index 00000000..526aee00 --- /dev/null +++ b/config/lcdproc-dev/lcdproc_client.php @@ -0,0 +1,721 @@ +<?php +/* $Id$ */ +/* + lcdproc_client.php + Copyright (C) 2007 Seth Mos <seth.mos@xs4all.nl> + 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. +*/ + + /* trick interface into running this. we are only + * calling from useland so this is not a security issue + */ + require_once("config.inc"); + require_once("functions.inc"); + require_once("/usr/local/pkg/lcdproc.inc"); + + function get_pfstate() { + global $config; + $matches = ""; + if (isset($config['system']['maximumstates']) and $config['system']['maximumstates'] > 0) + $maxstates="/{$config['system']['maximumstates']}"; + else + $maxstates="/10000"; + + $curentries = `/sbin/pfctl -si |grep current`; + if (preg_match("/([0-9]+)/", $curentries, $matches)) { + $curentries = $matches[1]; + } + return $curentries . $maxstates; + } + + function disk_usage() { + $dfout = ""; + exec("/bin/df -h | /usr/bin/grep -w '/' | /usr/bin/awk '{ print $5 }' | /usr/bin/cut -d '%' -f 1", $dfout); + $diskusage = trim($dfout[0]); + + return $diskusage; + } + + function mem_usage() { + $memory = ""; + exec("/sbin/sysctl -n vm.stats.vm.v_page_count vm.stats.vm.v_inactive_count " . + "vm.stats.vm.v_cache_count vm.stats.vm.v_free_count", $memory); + + $totalMem = $memory[0]; + $availMem = $memory[1] + $memory[2] + $memory[3]; + $usedMem = $totalMem - $availMem; + $memUsage = round(($usedMem * 100) / $totalMem, 0); + + return $memUsage; + } + + /*function array_combine($arr1, $arr2) { + $out = array(); + + $arr1 = array_values($arr1); + $arr2 = array_values($arr2); + + foreach($arr1 as $key1 => $value1) { + $out[(string)$value1] = $arr2[$key1]; + } + + return $out; + }*/ + + /* Calculates non-idle CPU time and returns as a percentage */ + function cpu_usage() { + $duration = 1; + $diff = array('user', 'nice', 'sys', 'intr', 'idle'); + $cpuTicks = array_combine($diff, explode(" ", `/sbin/sysctl -n kern.cp_time`)); + sleep($duration); + $cpuTicks2 = array_combine($diff, explode(" ", `/sbin/sysctl -n kern.cp_time`)); + + $totalStart = array_sum($cpuTicks); + $totalEnd = array_sum($cpuTicks2); + + // Something wrapped ?!?! + if ($totalEnd <= $totalStart) + return 0; + + // Calculate total cycles used + $totalUsed = ($totalEnd - $totalStart) - ($cpuTicks2['idle'] - $cpuTicks['idle']); + + // Calculate the percentage used + $cpuUsage = floor(100 * ($totalUsed / ($totalEnd - $totalStart))); + + return $cpuUsage; + } + + function get_uptime_stats() { + exec("/usr/bin/uptime", $output, $ret); + if(stristr($output[0], "day")) { + $temp = explode(" ", $output[0]); + $status = "$temp[2] $temp[3] $temp[4] $temp[5] $temp[6] $temp[7] ". substr($temp[8], 0, -1); + } else { + $temp = explode(" ", $output[0]); + $status = "$temp[2] $temp[3] $temp[4] $temp[5] $temp[6] ". substr($temp[7], 0, -1); + } + return($status); + } + + function get_loadavg_stats() { + exec("/usr/bin/uptime", $output, $ret); + if(stristr($output[0], "day")) { + $temp = explode(" ", $output[0]); + $status = "$temp[11] $temp[12] $temp[13]"; + } else { + $temp = explode(" ", $output[0]); + $status = "$temp[10] $temp[11] $temp[12]"; + } + return($status); + } + + function get_mbuf_stats() { + exec("netstat -mb | grep \"mbufs in use\" | awk '{ print $1 }' | cut -d\"/\" -f1", $mbufs_inuse); + exec("netstat -mb | grep \"mbufs in use\" | awk '{ print $1 }' | cut -d\"/\" -f3", $mbufs_total); + $status = "$mbufs_inuse[0] \/ $mbufs_total[0]"; + return($status); + } + + function get_cpufrequency(){ + $cpufreqs = ""; + exec("/sbin/sysctl -n dev.cpu.0.freq_levels", $cpufreqs); + $cpufreqs = explode(" ", trim($cpufreqs[0])); + $maxfreq = explode("/", $cpufreqs[0]); + $maxfreq = $maxfreq[0]; + $curfreq = ""; + exec("/sbin/sysctl -n dev.cpu.0.freq", $curfreq); + $curfreq = trim($curfreq[0]); + $status = "$curfreq\/$maxfreq Mhz"; + return($status); + } + + function get_interfaces_stats() { + global $g; + global $config; + $ifstatus = array(); + $i = 0; + $ifdescrs = array('wan' => 'WAN', 'lan' => 'LAN'); + for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++) { + $ifdescrs['opt' . $j] = $config['interfaces']['opt' . $j]['descr']; + } + foreach ($ifdescrs as $ifdescr => $ifname){ + $ifinfo = get_interface_info($ifdescr); + if($ifinfo['status'] == "up") { + $online = "Up"; + } else { + $online = "Down"; + } + if(!empty($ifinfo['ipaddr'])) { + $ip = htmlspecialchars($ifinfo['ipaddr']); + } else { + $ip = "-"; + } + $ifstatus[] = htmlspecialchars($ifname) ." [$online]"; + } + $status = " ". implode(", ", $ifstatus); + return($status); + } + + function get_slbd_stats() { + global $g; + global $config; + + if (!is_array($config['load_balancer']['lbpool'])) { + $config['load_balancer']['lbpool'] = array(); + } + $a_pool = &$config['load_balancer']['lbpool']; + + $slbd_logfile = "{$g['varlog_path']}/slbd.log"; + + $nentries = $config['syslog']['nentries']; + if (!$nentries) + $nentries = 50; + + $now = time(); + $year = date("Y"); + $pstatus = ""; + $i = 0; + foreach ($a_pool as $vipent) { + $pstatus[] = "{$vipent['name']}"; + if ($vipent['type'] == "gateway") { + $poolfile = "{$g['tmp_path']}/{$vipent['name']}.pool"; + if(file_exists("$poolfile")) { + $poolstatus = file_get_contents("$poolfile"); + } else { + continue; + } + foreach ((array) $vipent['servers'] as $server) { + $lastchange = ""; + $svr = split("\|", $server); + $monitorip = $svr[1]; + if(stristr($poolstatus, $monitorip)) { + $online = "Up"; + } else { + $online = "Down"; + } + $pstatus[] = strtoupper($svr[0]) ." [{$online}]"; + } + } else { + $pstatus[] = "{$vipent['monitor']}"; + } + } + if(count($a_pool) == 0) { + $pstatus[] = "Disabled"; + } + $status = implode(", ", $pstatus); + return($status); + } + + function get_carp_stats () { + global $g; + global $config; + + if(is_array($config['virtualip']['vip'])) { + $carpint = 0; + $initcount = 0; + $mastercount = 0; + $backupcount = 0; + foreach($config['virtualip']['vip'] as $carp) { + if ($carp['mode'] != "carp") { + continue; + } + $ipaddress = $carp['subnet']; + $password = $carp['password']; + $netmask = $carp['subnet_bits']; + $vhid = $carp['vhid']; + $advskew = $carp['advskew']; + $carp_int = find_carp_interface($ipaddress); + $status = get_carp_interface_status($carp_int); + switch($status) { + case "MASTER": + $mastercount++; + break; + case "BACKUP": + $backupcount++; + break; + case "INIT": + $initcount++; + break; + } + } + $status = "M/B/I {$mastercount}/{$backupcount}/{$initcount}"; + } else { + $status = "CARP Disabled"; + } + return($status); + } + + function get_ipsec_tunnel_sad() { + /* query SAD */ + if(file_exists("/usr/local/sbin/setkey")) + $fd = @popen("/usr/local/sbin/setkey -D", "r"); + else + $fd = @popen("/sbin/setkey -D", "r"); + $sad = array(); + if ($fd) { + while (!feof($fd)) { + $line = chop(fgets($fd)); + if (!$line) + continue; + if ($line == "No SAD entries.") + break; + if ($line[0] != "\t") { + if (is_array($cursa)) + $sad[] = $cursa; + $cursa = array(); + list($cursa['src'],$cursa['dst']) = explode(" ", $line); + $i = 0; + } else { + $linea = explode(" ", trim($line)); + if ($i == 1) { + $cursa['proto'] = $linea[0]; + $cursa['spi'] = substr($linea[2], strpos($linea[2], "x")+1, -1); + } else if ($i == 2) { + $cursa['ealgo'] = $linea[1]; + } else if ($i == 3) { + $cursa['aalgo'] = $linea[1]; + } + } + $i++; + } + if (is_array($cursa) && count($cursa)) + $sad[] = $cursa; + pclose($fd); + } + return($sad); + } + + function get_ipsec_tunnel_src($tunnel) { + global $g, $config, $sad; + $if = "WAN"; + if ($tunnel['interface']) { + $if = $tunnel['interface']; + $realinterface = convert_friendly_interface_to_real_interface_name($if); + $interfaceip = find_interface_ip($realinterface); + } + return $interfaceip; + } + + function output_ipsec_tunnel_status($tunnel) { + global $g, $config, $sad; + $if = "WAN"; + $interfaceip = get_ipsec_tunnel_src($tunnel); + $foundsrc = false; + $founddst = false; + + if(!is_array($sad)) { + /* we have no sad array, bail */ + return(false); + } + foreach($sad as $sa) { + if($sa['src'] == $interfaceip) + $foundsrc = true; + if($sa['dst'] == $tunnel['remote-gateway']) + $founddst = true; + } + if($foundsrc && $founddst) { + /* tunnel is up */ + $iconfn = "pass"; + return(true); + } else { + /* tunnel is down */ + $iconfn = "reject"; + return(false); + } + } + + function get_ipsec_stats() { + global $g, $config, $sad; + $sad = array(); + $sad = get_ipsec_tunnel_sad(); + + $activecounter = 0; + $inactivecounter = 0; + + if($config['ipsec']['tunnel']) { + foreach ($config['ipsec']['tunnel'] as $tunnel){ + $ipsecstatus = false; + + $tun_disabled = "false"; + $foundsrc = false; + $founddst = false; + + if (isset($tunnel['disabled'])) { + $tun_disabled = "true"; + continue; + } + + if(output_ipsec_tunnel_status($tunnel)) { + /* tunnel is up */ + $iconfn = "true"; + $activecounter++; + } else { + /* tunnel is down */ + $iconfn = "false"; + $inactivecounter++; + } + } + } + + if (is_array($config['ipsec']['tunnel'])) { + $status = "Up/Down $activecounter/$inactivecounter"; + } else { + $status = "IPSEC Disabled"; + } + return($status); + } + + + /* Define functions */ + function send_lcd_commands($lcd, $lcd_cmds) { + if(!is_array($lcd_cmds) || (empty($lcd_cmds))) { + lcdproc_warn("Failed to interpret lcd commands"); + return; + } + foreach($lcd_cmds as $lcd_cmd) { + $cmd_output = ""; + if(! fwrite($lcd, "$lcd_cmd\n")) { + lcdproc_warn("Connection to LCDd process lost $errstr ($errno)"); + die(); + } + $cmd_output = fgets($lcd, 256); + // FIXME: add support for interpreting menu commands here. + if(preg_match("/^huh?/", $cmd_output)) { + lcdproc_notice("LCDd output: \"$cmd_output\". Executed \"$lcd_cmd\""); + } + } + } + + function get_lcdpanel_width(){ + global $config; + $lcdproc_size_config = $config['installedpackages']['lcdproc']['config'][0]; + if (is_null($lcdproc_size_config['size'])) { + return "16"; + } + else + { + $dimensions = split("x", $lcdproc_size_config['size']); + return $dimensions[0]; + } + } + + function get_lcdpanel_height(){ + global $config; + $lcdproc_size_config = $config['installedpackages']['lcdproc']['config'][0]; + if (is_null($lcdproc_size_config['size'])) { + return "2"; + } + else + { + $dimensions = split("x", $lcdproc_size_config['size']); + return $dimensions[1]; + } + } + + function get_lcdpanel_refresh_frequency(){ + global $config; + $lcdproc_size_config = $config['installedpackages']['lcdproc']['config'][0]; + $value = $lcdproc_size_config['refresh_frequency']; + if (is_null($value)) { + return "5"; + } + else + { + return $value; + } + } + + function add_summary_declaration(&$lcd_cmds, $name) { + $lcdpanel_height = get_lcdpanel_height(); + if ($lcdpanel_height >= "4") + { + $lcd_cmds[] = "widget_add $name title_summary scroller"; + $lcd_cmds[] = "widget_add $name text_summary scroller"; + } + } + + function add_summary_values(&$lcd_cmds, $name, $lcd_summary_data, $lcdpanel_width) { + if ($lcd_summary_data != "") + { + $lcd_cmds[] = "widget_set $name title_summary 1 3 $lcdpanel_width 3 h 2 \"CPU MEM STATES\""; + $lcd_cmds[] = "widget_set $name text_summary 1 4 $lcdpanel_width 4 h 2 \"{$lcd_summary_data}\""; + } + } + + function build_interface($lcd) { + global $g; + global $config; + $lcdproc_screens_config = $config['installedpackages']['lcdprocscreens']['config'][0]; + $refresh_frequency = get_lcdpanel_refresh_frequency() * 10; + + $lcd_cmds = array(); + $lcd_cmds[] = "hello"; + $lcd_cmds[] = "client_set name pfSense"; + $lcd_cmds[] = "screen_add welcome_scr"; + $lcd_cmds[] = "screen_set welcome_scr heartbeat off"; + $lcd_cmds[] = "screen_set welcome_scr name welcome"; + $lcd_cmds[] = "screen_set welcome_scr duration $refresh_frequency"; + $lcd_cmds[] = "widget_add welcome_scr title_wdgt title"; + $lcd_cmds[] = "widget_add welcome_scr text_wdgt scroller"; + add_summary_declaration($lcd_cmds, "welcome_scr"); + + /* process screens to display */ + if(is_array($lcdproc_screens_config)) { + foreach($lcdproc_screens_config as $name => $screen) { + if($screen == "on") { + switch($name) { + case "scr_time": + $lcd_cmds[] = "screen_add $name"; + $lcd_cmds[] = "screen_set $name heartbeat off"; + $lcd_cmds[] = "screen_set $name name $name"; + $lcd_cmds[] = "screen_set $name duration $refresh_frequency"; + $lcd_cmds[] = "widget_add $name title_wdgt string"; + $lcd_cmds[] = "widget_add $name text_wdgt scroller"; + break; + case "scr_uptime": + $lcd_cmds[] = "screen_add $name"; + $lcd_cmds[] = "screen_set $name heartbeat off"; + $lcd_cmds[] = "screen_set $name name $name"; + $lcd_cmds[] = "screen_set $name duration $refresh_frequency"; + $lcd_cmds[] = "widget_add $name title_wdgt string"; + $lcd_cmds[] = "widget_add $name text_wdgt scroller"; + break; + case "scr_hostname": + $lcd_cmds[] = "screen_add $name"; + $lcd_cmds[] = "screen_set $name heartbeat off"; + $lcd_cmds[] = "screen_set $name name $name"; + $lcd_cmds[] = "screen_set $name duration $refresh_frequency"; + $lcd_cmds[] = "widget_add $name title_wdgt string"; + $lcd_cmds[] = "widget_add $name text_wdgt scroller"; + break; + case "scr_system": + $lcd_cmds[] = "screen_add $name"; + $lcd_cmds[] = "screen_set $name heartbeat off"; + $lcd_cmds[] = "screen_set $name name $name"; + $lcd_cmds[] = "screen_set $name duration $refresh_frequency"; + $lcd_cmds[] = "widget_add $name title_wdgt string"; + $lcd_cmds[] = "widget_add $name text_wdgt scroller"; + break; + case "scr_disk": + $lcd_cmds[] = "screen_add $name"; + $lcd_cmds[] = "screen_set $name heartbeat off"; + $lcd_cmds[] = "screen_set $name name $name"; + $lcd_cmds[] = "screen_set $name duration $refresh_frequency"; + $lcd_cmds[] = "widget_add $name title_wdgt string"; + $lcd_cmds[] = "widget_add $name text_wdgt scroller"; + break; + case "scr_load": + $lcd_cmds[] = "screen_add $name"; + $lcd_cmds[] = "screen_set $name heartbeat off"; + $lcd_cmds[] = "screen_set $name name $name"; + $lcd_cmds[] = "screen_set $name duration $refresh_frequency"; + $lcd_cmds[] = "widget_add $name title_wdgt string"; + $lcd_cmds[] = "widget_add $name text_wdgt scroller"; + break; + case "scr_states": + $lcd_cmds[] = "screen_add $name"; + $lcd_cmds[] = "screen_set $name heartbeat off"; + $lcd_cmds[] = "screen_set $name name $name"; + $lcd_cmds[] = "screen_set $name duration $refresh_frequency"; + $lcd_cmds[] = "widget_add $name title_wdgt string"; + $lcd_cmds[] = "widget_add $name text_wdgt scroller"; + break; + case "scr_carp": + $lcd_cmds[] = "screen_add $name"; + $lcd_cmds[] = "screen_set $name heartbeat off"; + $lcd_cmds[] = "screen_set $name name $name"; + $lcd_cmds[] = "screen_set $name duration $refresh_frequency"; + $lcd_cmds[] = "widget_add $name title_wdgt string"; + $lcd_cmds[] = "widget_add $name text_wdgt scroller"; + break; + case "scr_ipsec": + $lcd_cmds[] = "screen_add $name"; + $lcd_cmds[] = "screen_set $name heartbeat off"; + $lcd_cmds[] = "screen_set $name name $name"; + $lcd_cmds[] = "screen_set $name duration $refresh_frequency"; + $lcd_cmds[] = "widget_add $name title_wdgt string"; + $lcd_cmds[] = "widget_add $name text_wdgt scroller"; + break; + case "scr_slbd": + $lcd_cmds[] = "screen_add $name"; + $lcd_cmds[] = "screen_set $name heartbeat off"; + $lcd_cmds[] = "screen_set $name name $name"; + $lcd_cmds[] = "screen_set $name duration $refresh_frequency"; + $lcd_cmds[] = "widget_add $name title_wdgt string"; + $lcd_cmds[] = "widget_add $name text_wdgt scroller"; + break; + case "scr_interfaces": + $lcd_cmds[] = "screen_add $name"; + $lcd_cmds[] = "screen_set $name heartbeat off"; + $lcd_cmds[] = "screen_set $name name $name"; + $lcd_cmds[] = "screen_set $name duration $refresh_frequency"; + $lcd_cmds[] = "widget_add $name title_wdgt string"; + $lcd_cmds[] = "widget_add $name text_wdgt scroller"; + break; + case "scr_mbuf": + $lcd_cmds[] = "screen_add $name"; + $lcd_cmds[] = "screen_set $name heartbeat off"; + $lcd_cmds[] = "screen_set $name name $name"; + $lcd_cmds[] = "screen_set $name duration $refresh_frequency"; + $lcd_cmds[] = "widget_add $name title_wdgt string"; + $lcd_cmds[] = "widget_add $name text_wdgt scroller"; + break; + case "scr_cpufrequency": + $lcd_cmds[] = "screen_add $name"; + $lcd_cmds[] = "screen_set $name heartbeat off"; + $lcd_cmds[] = "screen_set $name name $name"; + $lcd_cmds[] = "screen_set $name duration $refresh_frequency"; + $lcd_cmds[] = "widget_add $name title_wdgt string"; + $lcd_cmds[] = "widget_add $name text_wdgt scroller"; + break; + } + add_summary_declaration($lcd_cmds, $name); + } + } + } + send_lcd_commands($lcd, $lcd_cmds); + } + + function loop_status($lcd) { + global $g; + global $config; + $lcdproc_screens_config = $config['installedpackages']['lcdprocscreens']['config'][0]; + $lcdpanel_width = get_lcdpanel_width(); + $lcdpanel_height = get_lcdpanel_height(); + if(empty($g['product_name'])) { + $g['product_name'] = "pfSense"; + } + $version = @file_get_contents("/etc/version"); + $version = trim($version); + $refresh_frequency = get_lcdpanel_refresh_frequency(); + /* keep a counter to see how many times we can loop */ + $i = 1; + while($i) { + /* prepare the summary data */ + if ($lcdpanel_height >= "4") { + $summary_states = split("/",get_pfstate()); + $lcd_summary_data = sprintf("%02d%% %02d%% %6d", cpu_usage(), mem_usage(), $summary_states[0]); + } + else { + $lcd_summary_data = "";} + + $lcd_cmds = array(); + $lcd_cmds[] = "widget_set welcome_scr title_wdgt \"Welcome to\""; + $lcd_cmds[] = "widget_set welcome_scr text_wdgt 1 2 $lcdpanel_width 2 h 2 \"{$g['product_name']} {$version}\""; + add_summary_values($lcd_cmds, "welcome_scr", $lcd_summary_data, $lcdpanel_width); + + /* process screens to display */ + foreach((array) $lcdproc_screens_config as $name => $screen) { + if($screen != "on") { + continue; + } + switch($name) { + case "scr_time": + $time = date("n/j/Y H:i"); + $lcd_cmds[] = "widget_set $name title_wdgt 1 1 \"+ System Time\""; + $lcd_cmds[] = "widget_set $name text_wdgt 1 2 $lcdpanel_width 2 h 2 \"{$time}\""; + break; + case "scr_uptime": + $uptime = get_uptime_stats(); + $lcd_cmds[] = "widget_set $name title_wdgt 1 1 \"+ System Uptime\""; + $lcd_cmds[] = "widget_set $name text_wdgt 1 2 $lcdpanel_width 2 h 2 \"{$uptime}\""; + break; + case "scr_hostname": + exec("/bin/hostname", $output, $ret); + $hostname = $output[0]; + $lcd_cmds[] = "widget_set $name title_wdgt 1 1 \"+ System Name\""; + $lcd_cmds[] = "widget_set $name text_wdgt 1 2 $lcdpanel_width 2 h 2 \"{$hostname}\""; + break; + case "scr_system": + $processor = cpu_usage(); + $memory = mem_usage(); + $lcd_cmds[] = "widget_set $name title_wdgt 1 1 \"+ System Stats\""; + $lcd_cmds[] = "widget_set $name text_wdgt 1 2 $lcdpanel_width 2 h 2 \"CPU {$processor}%, Mem {$memory}%\""; + break; + case "scr_disk": + $disk = disk_usage(); + $lcd_cmds[] = "widget_set $name title_wdgt 1 1 \"+ Disk Use\""; + $lcd_cmds[] = "widget_set $name text_wdgt 1 2 $lcdpanel_width 2 h 2 \"Disk {$disk}%\""; + break; + case "scr_load": + $loadavg = get_loadavg_stats(); + $lcd_cmds[] = "widget_set $name title_wdgt 1 1 \"+ Load Averages\""; + $lcd_cmds[] = "widget_set $name text_wdgt 1 2 $lcdpanel_width 2 h 2 \"{$loadavg}\""; + break; + case "scr_states": + $states = get_pfstate(); + $lcd_cmds[] = "widget_set $name title_wdgt 1 1 \"+ Traffic States\""; + $lcd_cmds[] = "widget_set $name text_wdgt 1 2 $lcdpanel_width 2 h 2 \"Curr/Max {$states}\""; + break; + case "scr_carp": + $carp = get_carp_stats(); + $lcd_cmds[] = "widget_set $name title_wdgt 1 1 \"+ CARP State\""; + $lcd_cmds[] = "widget_set $name text_wdgt 1 2 $lcdpanel_width 2 h 2 \"{$carp}\""; + break; + case "scr_ipsec": + $ipsec = get_ipsec_stats(); + $lcd_cmds[] = "widget_set $name title_wdgt 1 1 \"+ IPsec Tunnels\""; + $lcd_cmds[] = "widget_set $name text_wdgt 1 2 $lcdpanel_width 2 h 2 \"{$ipsec}\""; + break; + case "scr_slbd": + $slbd = get_slbd_stats(); + $lcd_cmds[] = "widget_set $name title_wdgt 1 1 \"+ Load Balancer\""; + $lcd_cmds[] = "widget_set $name text_wdgt 1 2 $lcdpanel_width 2 h 2 \"{$slbd}\""; + break; + case "scr_interfaces": + $interfaces = get_interfaces_stats(); + $lcd_cmds[] = "widget_set $name title_wdgt 1 1 \"+ Interfaces\""; + $lcd_cmds[] = "widget_set $name text_wdgt 1 2 $lcdpanel_width 2 h 2 \"{$interfaces}\""; + break; + case "scr_mbuf": + $mbufstats = get_mbuf_stats(); + $lcd_cmds[] = "widget_set $name title_wdgt 1 1 \"+ MBuf Usage\""; + $lcd_cmds[] = "widget_set $name text_wdgt 1 2 $lcdpanel_width 2 h 2 \"{$mbufstats}\""; + break; + case "scr_cpufrequency": + $cpufreq = get_cpufrequency(); + $lcd_cmds[] = "widget_set $name title_wdgt 1 1 \"+ CPU Frequency\""; + $lcd_cmds[] = "widget_set $name text_wdgt 1 2 $lcdpanel_width 2 h 2 \"{$cpufreq}\""; + break; + } + add_summary_values($lcd_cmds, $name, $lcd_summary_data, $lcdpanel_width); + } + send_lcd_commands($lcd, $lcd_cmds); + sleep($refresh_frequency); + $i++; + } + } + + /* Connect to the LCDd port and interface with the LCD */ + $lcd = fsockopen(LCDPROC_HOST, LCDPROC_PORT, $errno, $errstr, 10); + if (!$lcd) { + lcdproc_warn("Failed to connect to LCDd process $errstr ($errno)"); + } else { + build_interface($lcd); + loop_status($lcd); + /* loop exited? Close fd and wait for the script to kick in again */ + fclose($lcd); + } +?> diff --git a/config/lcdproc-dev/lcdproc_screens.xml b/config/lcdproc-dev/lcdproc_screens.xml new file mode 100644 index 00000000..b807d9f0 --- /dev/null +++ b/config/lcdproc-dev/lcdproc_screens.xml @@ -0,0 +1,101 @@ +<?xml version="1.0" encoding="utf-8" ?> +<packagegui> + <title>Services: LCDproc: Screens</title> + <name>lcdproc_screens</name> + <version>0.5.2_1-p9</version> + <savetext>Save</savetext> + <include_file>/usr/local/pkg/lcdproc.inc</include_file> + <tabs> + <tab> + <text>Server</text> + <url>/pkg_edit.php?xml=lcdproc.xml&id=0</url> + </tab> + <tab> + <text>Screens</text> + <url>/pkg_edit.php?xml=lcdproc_screens.xml&id=0</url> + <active/> + </tab> + </tabs> + <menu> + <name>LCDproc</name> + <tooltiptext>Set LCDproc settings such as display driver and com port</tooltiptext> + <section>Services</section> + <url>/pkg_edit.php?xml=lcdproc.xml&id=0</url> + </menu> + <fields> + <field> + <fielddescr>Enable Time</fielddescr> + <fieldname>scr_time</fieldname> + <type>checkbox</type> + </field> + <field> + <fielddescr>Enable Uptime</fielddescr> + <fieldname>scr_uptime</fieldname> + <type>checkbox</type> + </field> + <field> + <fielddescr>Enable Hostname</fielddescr> + <fieldname>scr_hostname</fieldname> + <type>checkbox</type> + </field> + <field> + <fielddescr>Enable System</fielddescr> + <fieldname>scr_system</fieldname> + <type>checkbox</type> + </field> + <field> + <fielddescr>Enable Disk</fielddescr> + <fieldname>scr_disk</fieldname> + <type>checkbox</type> + </field> + <field> + <fielddescr>Enable Load</fielddescr> + <fieldname>scr_load</fieldname> + <type>checkbox</type> + </field> + <field> + <fielddescr>Enable States</fielddescr> + <fieldname>scr_states</fieldname> + <type>checkbox</type> + </field> + <field> + <fielddescr>Enable Carp</fielddescr> + <fieldname>scr_carp</fieldname> + <type>checkbox</type> + </field> + <field> + <fielddescr>Enable IPsec</fielddescr> + <fieldname>scr_ipsec</fieldname> + <type>checkbox</type> + </field> + <field> + <fielddescr>Enable Load Balancer</fielddescr> + <fieldname>scr_slbd</fieldname> + <type>checkbox</type> + </field> + <field> + <fielddescr>Enable Interfaces</fielddescr> + <fieldname>scr_interfaces</fieldname> + <type>checkbox</type> + </field> + <field> + <fielddescr>Enable Mbuf</fielddescr> + <fieldname>scr_mbuf</fieldname> + <type>checkbox</type> + </field> + <field> + <fielddescr>Enable CPU Frequency</fielddescr> + <fieldname>scr_cpufrequency</fieldname> + <type>checkbox</type> + </field> + </fields> + <custom_php_command_before_form> + before_form_lcdproc_screens(&$pkg); + </custom_php_command_before_form> + <custom_php_validation_command> + validate_form_lcdproc_screens($_POST, &$input_errors); + </custom_php_validation_command> + <custom_php_resync_config_command> + sync_package_lcdproc_screens(); + </custom_php_resync_config_command> +</packagegui> |