diff options
author | Seth Mos <seth.mos@xs4all.nl> | 2007-11-26 20:18:11 +0000 |
---|---|---|
committer | Seth Mos <seth.mos@xs4all.nl> | 2007-11-26 20:18:11 +0000 |
commit | f3a11b7384b90c1014e86337bfd84f0d8b3d5583 (patch) | |
tree | 9c718d089414e708b6a55ab07cbfcfd54801bca7 /packages/lcdproc/lcdproc.inc | |
parent | a55d59d5f8c4840dea6c148418c07156c7be79e0 (diff) | |
download | pfsense-packages-f3a11b7384b90c1014e86337bfd84f0d8b3d5583.tar.gz pfsense-packages-f3a11b7384b90c1014e86337bfd84f0d8b3d5583.tar.bz2 pfsense-packages-f3a11b7384b90c1014e86337bfd84f0d8b3d5583.zip |
Start lcdproc package
Diffstat (limited to 'packages/lcdproc/lcdproc.inc')
-rw-r--r-- | packages/lcdproc/lcdproc.inc | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/packages/lcdproc/lcdproc.inc b/packages/lcdproc/lcdproc.inc new file mode 100644 index 00000000..b453dccd --- /dev/null +++ b/packages/lcdproc/lcdproc.inc @@ -0,0 +1,99 @@ +<?php + require_once("config.inc"); + require_once("functions.inc"); + + /* LCDproc */ + + function lcdproc_notice ($msg) { syslog(LOG_NOTICE, "lcdproc: {$msg}"); } + function lcdproc_warn ($msg) { syslog(LOG_WARNING, "lcdproc: {$msg}"); } + + function lcdproc_running () { + if((int)exec('pgrep lcdproc | 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 before_form_lcdproc($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; + default: + $input_errors[] = "The chosen com port is not valid"; + break; + } + } + } + + function sync_package_lcdproc() { + global $config; + global $input_errors; + + config_lock(); + + $lcdproc_config = $config['installedpackages']['lcdproc']['config'][0]; + $config_file = '/var/etc/lcdd.conf'; + + + /* since config is written before this file invoked we don't need to read post data */ + if($lcdproc_config['enable'] && ($lcdproc_config['comport'] != "none")) { + $config_text = "[server]\n"; + $config_text .= "Driver={$lcdproc_config[driver]}\n"; + + /* if lcdproc not running start it */ + if(!lcdproc_running()) { + lcdproc_notice("Starting service lcdproc"); + lcdproc_action('start'); + } + /* or restart lcdproc if settings were changed */ + elseif($_POST['comport']) { + lcdproc_notice("Restarting service lcdproc"); + lcdproc_action('restart'); + } + } + + if((! $lcdproc_config['comport']) || ($lcdproc_config['comport'] == "none")) { + /* no parameters user does not want lcdproc running */ + /* lets stop the service and remove the rc file */ + + if(file_exists($config_file)) { + if(!$lcdproc_config['enable']) { + lcdproc_notice('Stopping service: lcdproc disabled'); + } else { + lcdproc_notice('Stopping service: no com port selected'); + } + lcdproc_action('stop'); + unlink($config_file); + } + } + config_unlock(); + } +?> |