aboutsummaryrefslogtreecommitdiffstats
path: root/config/gwled
diff options
context:
space:
mode:
authorjim-p <jimp@pfsense.org>2011-08-10 16:32:07 -0400
committerjim-p <jimp@pfsense.org>2011-08-10 16:32:07 -0400
commita2b3c8ca6bdbaadf032513d354c3c2658e49fa28 (patch)
treef5ece99ef1da4ade233a2885ef170cc19fc4d70b /config/gwled
parente59953342fc399c119766363a3815f7335b07951 (diff)
downloadpfsense-packages-a2b3c8ca6bdbaadf032513d354c3c2658e49fa28.tar.gz
pfsense-packages-a2b3c8ca6bdbaadf032513d354c3c2658e49fa28.tar.bz2
pfsense-packages-a2b3c8ca6bdbaadf032513d354c3c2658e49fa28.zip
Add gwled package that lets you use LED2/3 to show a gateway's status.
Diffstat (limited to 'config/gwled')
-rw-r--r--config/gwled/gwled.inc70
-rw-r--r--config/gwled/gwled.php18
-rw-r--r--config/gwled/gwled.xml74
3 files changed, 162 insertions, 0 deletions
diff --git a/config/gwled/gwled.inc b/config/gwled/gwled.inc
new file mode 100644
index 00000000..35038034
--- /dev/null
+++ b/config/gwled/gwled.inc
@@ -0,0 +1,70 @@
+<?php
+require_once("functions.inc");
+
+function gwled_running () {
+ return ((int)exec('pgrep -f gwled | wc -l') > 0);
+}
+
+function sync_package_gwled() {
+ global $config;
+ $gwled_config = $config['installedpackages']['gwled']['config'][0];
+ /* kill all instances of gwled */
+ if(gwled_running()) {
+ gwled_stop();
+ }
+ gwled_start();
+}
+
+function gwled_start() {
+ global $config;
+ $gwled_config = $config['installedpackages']['gwled']['config'][0];
+ if (!($gwled_config['enable']))
+ return;
+
+ if (($gwled_config['enable_led2']) && ($gwled_config['gw_led2'])
+ || ($gwled_config['enable_led3']) && ($gwled_config['gw_led3']))
+ mwexec("/usr/local/bin/minicron 30 /var/run/gwled.pid /usr/local/bin/gwled.php");
+}
+
+function gwled_stop() {
+ exec("/bin/pkill -9 -f gwled");
+}
+
+function validate_form_gwled($post, $input_errors) {
+ /* Make sure both aren't using the same interface */
+ if (($post['gw_led2']) && ($post['gw_led3']) &&
+ (($post['enable_led2']) && ($post['enable_led3'])) &&
+ ($post['gw_led2'] == $post['gw_led3']))
+ $input_errors[] = 'You cannot set two LEDs for a single gateway. Please choose seperate interfaces.';
+}
+
+function gwled_get_gateways() {
+ $gateways = return_gateways_array();
+
+ foreach ($gateways as $gateway) {
+ $tmp["name"] = "{$gateway['name']} (Monitor: {$gateway['monitor']})";
+ $tmp["value"] = $gateway['name'];
+ $gws[] = $tmp;
+ }
+ return $gws;
+}
+
+function gwled_set_status($gateway, $led) {
+ $a_gateways = return_gateways_array();
+ $gateways_status = array();
+ $gateways_status = return_gateways_status(true);
+ if ($gateways_status[$gateway]) {
+ $status = $gateways_status[$gateway]['status'];
+ if (stristr($status, "down"))
+ led_blink($led, "veryfast");
+ elseif (stristr($status, "loss"))
+ led_blink($led, "fast");
+ elseif (stristr($status, "delay"))
+ led_blink($led, "medium");
+ elseif ($status == "none")
+ led_on($led);
+ } else
+ led_on($led);
+}
+
+?>
diff --git a/config/gwled/gwled.php b/config/gwled/gwled.php
new file mode 100644
index 00000000..efcb73dd
--- /dev/null
+++ b/config/gwled/gwled.php
@@ -0,0 +1,18 @@
+#!/usr/local/bin/php -q
+<?php
+require_once("config.inc");
+require_once("functions.inc");
+require_once("gwled.inc");
+require_once("led.inc");
+require_once("gwlb.inc");
+
+global $config;
+$gwled_config = $config['installedpackages']['gwled']['config'][0];
+
+if (($gwled_config['enable_led2']) && ($gwled_config['gw_led2'])) {
+ gwled_set_status($gwled_config['gw_led2'], 2);
+}
+if (($gwled_config['enable_led3']) && ($gwled_config['gw_led3'])) {
+ gwled_set_status($gwled_config['gw_led3'], 3);
+}
+?>
diff --git a/config/gwled/gwled.xml b/config/gwled/gwled.xml
new file mode 100644
index 00000000..7388230c
--- /dev/null
+++ b/config/gwled/gwled.xml
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<packagegui>
+ <title>Interfaces: Gateway Status LEDs</title>
+ <name>gwled</name>
+ <version>20110810</version>
+ <savetext>Save</savetext>
+ <include_file>/usr/local/pkg/gwled.inc</include_file>
+ <menu>
+ <name>Gateway Status LEDs</name>
+ <tooltiptext>Assign LEDs to indicate Gateway status.</tooltiptext>
+ <section>Interfaces</section>
+ <url>/pkg_edit.php?xml=gwled.xml&amp;id=0</url>
+ </menu>
+ <additional_files_needed>
+ <item>http://www.pfsense.org/packages/config/gwled/gwled.inc</item>
+ <prefix>/usr/local/pkg/</prefix>
+ <chmod>0644</chmod>
+ </additional_files_needed>
+ <additional_files_needed>
+ <prefix>/usr/local/bin/</prefix>
+ <chmod>0755</chmod>
+ <item>http://www.pfsense.com/packages/config/gwled/gwled.php</item>
+ </additional_files_needed>
+ <service>
+ <name>gwled</name>
+ <rcfile>gwled.sh</rcfile>
+ <executable>gwled</executable>
+ </service>
+ <fields>
+ <field>
+ <fielddescr>Enable gwled</fielddescr>
+ <fieldname>enable</fieldname>
+ <type>checkbox</type>
+ <enablefields>enable_led2,enable_led3,gw_led2,gw_led3</enablefields>
+ <description>if this is enabled, it will use LED #2 and #3 to
+ indicate network activity. Be aware, however, that this will
+ possibly consume some system resources in the process.</description>
+ </field>
+ <field>
+ <fielddescr>Enable LED #2</fielddescr>
+ <fieldname>enable_led2</fieldname>
+ <type>checkbox</type>
+ </field>
+ <field>
+ <fielddescr>Interface For LED #2</fielddescr>
+ <fieldname>gw_led2</fieldname>
+ <type>select_source</type>
+ <source><![CDATA[gwled_get_gateways()]]></source>
+ <source_name>name</source_name>
+ <source_value>value</source_value>
+ <description>Use LED #2 to indicate the status for this gateway.</description>
+ </field>
+ <field>
+ <fielddescr>Enable LED #3</fielddescr>
+ <fieldname>enable_led3</fieldname>
+ <type>checkbox</type>
+ </field>
+ <field>
+ <fielddescr>Interface For LED #3</fielddescr>
+ <fieldname>gw_led3</fieldname>
+ <type>select_source</type>
+ <source><![CDATA[gwled_get_gateways()]]></source>
+ <source_name>name</source_name>
+ <source_value>value</source_value>
+ <description>Use LED #3 to indicate the status for this gateway.</description>
+ </field>
+ </fields>
+ <custom_php_validation_command>
+ validate_form_gwled($_POST, &amp;$input_errors);
+ </custom_php_validation_command>
+ <custom_php_resync_config_command>
+ sync_package_gwled();
+ </custom_php_resync_config_command>
+</packagegui>