diff options
-rw-r--r-- | packages/lcdproc/lcdproc.inc | 54 | ||||
-rw-r--r-- | packages/lcdproc/lcdproc.xml | 7 | ||||
-rw-r--r-- | packages/lcdproc/lcdproc_client.php | 84 |
3 files changed, 115 insertions, 30 deletions
diff --git a/packages/lcdproc/lcdproc.inc b/packages/lcdproc/lcdproc.inc index 79a04cc2..d6c3d530 100644 --- a/packages/lcdproc/lcdproc.inc +++ b/packages/lcdproc/lcdproc.inc @@ -1,5 +1,5 @@ <?php - +/* $Id$ */ /* lcdproc.inc Copyright (C) 2007 Seth Mos <seth.mos@xs4all.nl> @@ -32,8 +32,9 @@ /* LCDproc */ define('LCDPROC_RCFILE', '/usr/local/etc/rc.d/lcdproc.sh'); + define('LCDPROC_CLIENT', '/tmp/lcdprocc.sh'); define('LCDPROC_CONFIG','/usr/local/etc/LCDd.conf'); - define('LCDPROC_PORT','localhost'); + define('LCDPROC_HOST','localhost'); define('LCDPROC_PORT','13666'); function lcdproc_notice ($msg) { syslog(LOG_NOTICE, "lcdproc: {$msg}"); } @@ -45,7 +46,7 @@ } function lcdproc_running () { - if((int)exec('pgrep lcdproc | wc -l') > 0) + if((int)exec('pgrep LCDd | wc -l') > 0) return true; return false; } @@ -216,20 +217,39 @@ } /* generate rc file start and stop */ + $client_script = <<<EOD +#!/bin/sh + +counter=1 +while [ "$counter" -ne 0 ] +do + /usr/local/bin/php -f /usr/local/pkg/lcdproc_client.php + sleep 10 +done + +EOD; + + /* generate rc file start and stop */ $stop = <<<EOD if [ `pgrep LCDd | wc -l` != 0 ]; then /usr/bin/killall LCDd + /usr/bin/killall lcdprocc.sh while [ `pgrep LCDd | wc -l` != 0 ]; do sleep 1 done + while [ `pgrep lcdprocc.sh | wc -l` != 0 ]; do + sleep 1 + done fi EOD; - $start = $stop."\n\t/usr/local/sbin/LCDd -c ".LCDPROC_CONFIG; + $start = $stop ."\n"; + $start .= "\t/usr/local/sbin/LCDd -c ". LCDPROC_CONFIG ."\n"; /* write out the configuration */ conf_mount_rw(); + lcdproc_write_config(LCDPROC_CLIENT, $client_script); lcdproc_write_config(LCDPROC_CONFIG, $config_text); write_rcfile(array( 'file' => 'lcdproc.sh', @@ -263,6 +283,7 @@ EOD; lcdproc_action('stop'); conf_mount_rw(); unlink(LCDPROC_RCFILE); + unlink(LCDPROC_CLIENT); unlink(LCDPROC_CONFIG); conf_mount_ro(); } @@ -270,29 +291,4 @@ EOD; config_unlock(); } - /* Connect to the LCDd port and interface with the LCD */ - function send_lcd_commands($lcd_cmds) { - if(!is_array($lcd_cmds) || (empty($lcd_cmds))) { - lcdproc_warn("Failed to interpret lcd commands"); - return; - } - $lcd = fsockopen($LCDPROC_HOST, $LCDPROC_PORT, $errno, $errstr, 30); - if (!$lcd) { - lcdproc_warn("Failed to connect to LCDd process $errstr ($errno)"); - } else { - foreach($lcd_cmds as $lcd_cmd) { - $cmd_output = ""; - fwrite($lcd, $lcd_cmd); - while (!feof($lcd)) { - $cmd_output .= fgets($lcd, 128); - } - lcdproc_notice("LCDd output for cmd $lcd_cmd is: $cmd_output"); - usleep(100); - } - fclose($lcd); - } - } - - - ?> diff --git a/packages/lcdproc/lcdproc.xml b/packages/lcdproc/lcdproc.xml index 90ec1ff2..34dc7fa4 100644 --- a/packages/lcdproc/lcdproc.xml +++ b/packages/lcdproc/lcdproc.xml @@ -2,7 +2,7 @@ <packagegui> <title>Services: LCDproc</title> <name>lcdproc</name> - <version>0.5.2_1-p1</version> + <version>0.5.2_1-p2</version> <savetext>Save</savetext> <include_file>/usr/local/pkg/lcdproc.inc</include_file> <menu> @@ -16,6 +16,11 @@ <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> <service> <name>lcdproc</name> <rcfile>lcdproc.sh</rcfile> diff --git a/packages/lcdproc/lcdproc_client.php b/packages/lcdproc/lcdproc_client.php new file mode 100644 index 00000000..ea9d8c97 --- /dev/null +++ b/packages/lcdproc/lcdproc_client.php @@ -0,0 +1,84 @@ +<?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. +*/ + + require_once("config.inc"); + require_once("functions.inc"); + require_once("/usr/local/pkg/lcdproc.inc"); + + /* 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 = ""; + fwrite($lcd, $lcd_cmd); + $cmd_output .= fgets($lcd, 128); + lcdproc_notice("LCDd output for cmd $lcd_cmd is: $cmd_output"); + sleep(1); + } + } + + function loop_status($lcd) { + /* keep a counter to see how many times we can loop */ + $i = 0; + while(1) { + $time = time(); + $lcd_cmds = array(); + $lcd_cmds[] = "client_set -name \"Parenttest\"\n"; + $lcd_cmds[] = "screen_add status\n"; + $lcd_cmds[] = "screen_set status -heartbeat off\n"; + $lcd_cmds[] = "widget_add status title title\n"; + $lcd_cmds[] = "widget_add status date scroller\n"; + $lcd_cmds[] = "widget_set status title $i\n"; + $lcd_cmds[] = "widget_set status date left right h 1 $time\n"; + send_lcd_commands($lcd, $lcd_cmds); + $i++; + } + } + + function send_hello($lcd) { + $lcd_cmds = array(); + $lcd_cmds[] = "hello\n"; + send_lcd_commands($lcd, $lcd_cmds); + } + + /* 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 { + send_hello($lcd); + loop_status($lcd); + /* loop exited? Close fd and wait for the script to kick in again */ + sleep(1); + } + fclose($lcd); +?> |