diff options
author | doktornotor <notordoktor@gmail.com> | 2015-08-06 14:54:12 +0200 |
---|---|---|
committer | doktornotor <notordoktor@gmail.com> | 2015-08-06 14:54:12 +0200 |
commit | da8153456768f29b1be91039dbc617b347ac7684 (patch) | |
tree | 1c6b5efcaac78b8ced3de48d5aa70a593570b0e5 /config/blinkled8 | |
parent | 094cdae2d52be888ae17dd82d091f51e67ad1a0d (diff) | |
download | pfsense-packages-da8153456768f29b1be91039dbc617b347ac7684.tar.gz pfsense-packages-da8153456768f29b1be91039dbc617b347ac7684.tar.bz2 pfsense-packages-da8153456768f29b1be91039dbc617b347ac7684.zip |
blinkled.inc - style fixes and code rework
- Add copyright headers
- Code style fixes
- use is_process_running() instead of blinkled_running ()
- remove blinkled_stop() and blinkled_start in favour of start_service()/stop_service() in order to actually utilize the service in a meaningful way
Diffstat (limited to 'config/blinkled8')
-rw-r--r-- | config/blinkled8/blinkled.inc | 81 |
1 files changed, 51 insertions, 30 deletions
diff --git a/config/blinkled8/blinkled.inc b/config/blinkled8/blinkled.inc index 6d0da039..0980b253 100644 --- a/config/blinkled8/blinkled.inc +++ b/config/blinkled8/blinkled.inc @@ -1,4 +1,33 @@ <?php +/* + blinkled.inc + part of pfSense (https://www.pfSense.org/) + Copyright (C) 2009 Jim Pingle + Copyright (C) 2015 ESF, LLC + 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"); function blinkled_rcfile() { @@ -28,53 +57,45 @@ EOD; conf_mount_ro(); } -function blinkled_running () { - return ((int)exec('pgrep blinkled | wc -l') > 0); -} function sync_package_blinkled() { global $config; + + blinkled_rcfile(); + $blinkled_config = $config['installedpackages']['blinkled']['config'][0]; - /* kill all instances of blinkled */ - if(blinkled_running()) { - blinkled_stop(); + /* If the service is not enabled, do nothing */ + if (!($blinkled_config['enable'])) { + if (is_process_running("blinkled")) { + stop_service("blinkled"); + } + return; } - /* if blinkled not running start it */ - if(!blinkled_running()) { - blinkled_start(); + /* Kill all instances of blinkled */ + if (is_process_running("blinkled")) { + stop_service("blinkled"); + } + /* If blinkled is not running, start it */ + if (!is_process_running("blinkled")) { + start_service("blinkled"); } - blinkled_rcfile(); } function blinkled_launch($int, $led, $return = false) { $cmd = "/usr/local/bin/blinkled -i " . escapeshellarg($int) . " -l " . escapeshellarg("/dev/led/led{$led}"); - if ($return) + if ($return) { return $cmd; - else + } else { mwexec($cmd); -} - -function blinkled_start() { - global $config; - $blinkled_config = $config['installedpackages']['blinkled']['config'][0]; - if (!($blinkled_config['enable'])) - return; - - if (($blinkled_config['enable_led2']) && ($blinkled_config['iface_led2'])) - blinkled_launch(convert_friendly_interface_to_real_interface_name($blinkled_config['iface_led2']), 2); - if (($blinkled_config['enable_led3']) && ($blinkled_config['iface_led3'])) - blinkled_launch(convert_friendly_interface_to_real_interface_name($blinkled_config['iface_led3']), 3); -} - -function blinkled_stop() { - mwexec("/usr/bin/killall -9 blinkled"); + } } function validate_form_blinkled($post, &$input_errors) { /* Make sure both aren't using the same interface */ - if (($post['iface_led2']) && ($post['iface_led3']) && + if (($post['iface_led2']) && ($post['iface_led3']) && (($post['enable_led2']) && ($post['enable_led3'])) && - ($post['iface_led2'] == $post['iface_led3'])) + ($post['iface_led2'] == $post['iface_led3'])) { $input_errors[] = 'You cannot set two LEDs for a single interface. Please choose seperate interfaces.'; + } } ?> |