diff options
author | Scott Ullrich <sullrich@pfsense.org> | 2006-12-26 23:00:52 +0000 |
---|---|---|
committer | Scott Ullrich <sullrich@pfsense.org> | 2006-12-26 23:00:52 +0000 |
commit | 422e039b33d37f6cadff5b2370ab4b036bef88f7 (patch) | |
tree | 2ef374095c5e211c918fcadf2978b98e909674ce | |
parent | 32f5ff5af42027c32deab5336d6e6fc80364e766 (diff) | |
download | pfsense-422e039b33d37f6cadff5b2370ab4b036bef88f7.zip pfsense-422e039b33d37f6cadff5b2370ab4b036bef88f7.tar.gz |
MFC miniupnpd changes from Ryan Wagoner
-rw-r--r-- | usr/local/pkg/miniupnpd.inc | 67 | ||||
-rw-r--r-- | usr/local/pkg/miniupnpd.xml | 20 | ||||
-rwxr-xr-x | usr/local/www/fbegin.inc | 2 | ||||
-rwxr-xr-x | usr/local/www/status_services.php | 35 | ||||
-rw-r--r-- | usr/local/www/status_upnp.php | 9 |
5 files changed, 92 insertions, 41 deletions
diff --git a/usr/local/pkg/miniupnpd.inc b/usr/local/pkg/miniupnpd.inc index dd1ed10..2126127 100644 --- a/usr/local/pkg/miniupnpd.inc +++ b/usr/local/pkg/miniupnpd.inc @@ -2,10 +2,17 @@ require_once("config.inc"); require_once("functions.inc"); - /* Miniupnp */ + /* MiniUPnPd */ - function upnp_notice ($msg) { syslog(LOG_NOTICE, "miniupnpd: $msg"); return; } - function upnp_warn ($msg) { syslog(LOG_WARNING, "miniupnpd: $msg"); return; } + define('UPNP_RCFILE', '/usr/local/etc/rc.d/miniupnpd.sh'); + + function upnp_notice ($msg) { syslog(LOG_NOTICE, "miniupnpd: {$msg}"); return; } + function upnp_warn ($msg) { syslog(LOG_WARNING, "miniupnpd: {$msg}"); return; } + + function upnp_action ($action) { + if (file_exists(UPNP_RCFILE)) + mwexec(UPNP_RCFILE.' '.$action); + } function upnp_config ($name) { global $config; @@ -27,6 +34,8 @@ function before_form_miniupnpd($pkg) { global $config; + config_lock(); + /* if shaper connection speed defined hide fields */ if($config['ezshaper']['step2']['download'] && $config['ezshaper']['step2']['upload']) { $i=0; @@ -36,6 +45,8 @@ $i++; } } + + config_unlock(); } function validate_form_miniupnpd($post, $input_errors) { @@ -59,13 +70,10 @@ $ifaces_final = ""; $wanif = get_real_wan_interface(); - upnp_notice("Syncing package"); - - conf_mount_rw(); config_lock(); /* since config is written before this file invoked we don't need to read post data */ - if(upnp_config("iface_array")) + if(upnp_config("enable") && upnp_config("iface_array")) $iface_array = explode(",",upnp_config("iface_array")); if($iface_array) { @@ -77,13 +85,16 @@ /* non enabled interfaces are displayed in list on miniupnpd settings page */ /* check that the interface has an ip address before adding parameters */ if($addr) { - upnp_notice("Active on {$iface} interface"); $ifaces_final .= " -a {$addr}"; + if(!$ifaces_active) + $ifaces_active = $iface; + else + $ifaces_active .= ", {$iface}"; } else { - upnp_warn("Interface {$iface} has no ip address"); + upnp_warn("Interface {$iface} has no ip address, ignoring"); } } else { - upnp_warn("Could not resolve real interface {$iface}"); + upnp_warn("Could not resolve real interface for {$iface}"); } } @@ -137,6 +148,8 @@ EOD; if($sysuptime) $start .= " -U"; + conf_mount_rw(); + write_rcfile(array( "file" => "miniupnpd.sh", "start" => $start, @@ -144,11 +157,17 @@ EOD; ) ); - /* if not ONE instance running lets start */ - /* or if $_POST data as user is changing settings */ - if((int)exec("pgrep miniupnpd | wc -l") != 1 || $_POST['iface_array']) { - upnp_notice("Starting service"); - start_service("miniupnpd"); + conf_mount_ro(); + + /* if miniupnpd not running start it */ + if((int)exec("pgrep miniupnpd | wc -l") != 1) { + upnp_notice("Starting service on interface: {$ifaces_active}"); + upnp_action("start"); + } + /* or restart miniupnpd if settings were changed */ + elseif($_POST['iface_array']) { + upnp_notice("Restarting service on interface: {$ifaces_active}"); + upnp_action("restart"); } } } @@ -157,12 +176,20 @@ EOD; /* no parameters user does not want miniupnpd running */ /* lets stop the service and remove the rc file */ - stop_service("miniupnpd"); - upnp_warn("No interfaces stopping service"); - exec("rm -f /usr/local/etc/rc.d/miniupnpd*"); + if(file_exists(UPNP_RCFILE)) { + if(!upnp_config("enable")) + upnp_notice("Stopping service, miniupnpd disabled"); + else + upnp_notice("Stopping service, no interfaces selected"); + + upnp_action("stop"); + + conf_mount_rw(); + unlink(UPNP_RCFILE); + conf_mount_ro(); + } } config_unlock(); - conf_mount_ro(); } -?>
\ No newline at end of file +?> diff --git a/usr/local/pkg/miniupnpd.xml b/usr/local/pkg/miniupnpd.xml index d1515e8..bc1affc 100644 --- a/usr/local/pkg/miniupnpd.xml +++ b/usr/local/pkg/miniupnpd.xml @@ -1,13 +1,13 @@ <?xml version="1.0" encoding="utf-8" ?> <packagegui> - <title>Services: Miniupnpd</title> + <title>Services: MiniUPnPd</title> <name>miniupnpd</name> - <version>20061129</version> + <version>20061214</version> <savetext>Change</savetext> <include_file>/usr/local/pkg/miniupnpd.inc</include_file> <aftersaveredirect>status_upnp.php</aftersaveredirect> <menu> - <name>Miniupnpd</name> + <name>MiniUPnPd</name> <tooltiptext>Set miniupnpd settings such as interfaces to listen on.</tooltiptext> <section>Services</section> <url>/status_upnp.php</url> @@ -34,23 +34,29 @@ </service> <tabs> <tab> - <text>UPNP Status</text> + <text>UPnP Status</text> <url>status_upnp.php</url> </tab> <tab> - <text>miniupnpd Settings</text> + <text>MiniUPnPd Settings</text> <url>/pkg_edit.php?xml=miniupnpd.xml&id=0</url> <active/> </tab> </tabs> <fields> <field> - <fielddescr>Interface (generally LAN)</fielddescr> + <fielddescr>Enable MiniUPnPd</fielddescr> + <fieldname>enable</fieldname> + <type>checkbox</type> + </field> + <field> + <fielddescr>Interfaces (generally LAN)</fielddescr> <fieldname>iface_array</fieldname> <value>lan</value> <multiple>true</multiple> <size>3</size> <type>interfaces_selection</type> + <description>You can use the CTRL or COMMAND key to select multiple interfaces.</description> </field> <field> <fielddescr>Maximum Download Speed (Kbits/second)</fielddescr> @@ -93,4 +99,4 @@ <custom_php_deinstall_command> exec("rm -f /usr/local/etc/rc.d/miniupnpd*"); </custom_php_deinstall_command> -</packagegui>
\ No newline at end of file +</packagegui> diff --git a/usr/local/www/fbegin.inc b/usr/local/www/fbegin.inc index 0837b33..aa7365c 100755 --- a/usr/local/www/fbegin.inc +++ b/usr/local/www/fbegin.inc @@ -154,7 +154,7 @@ require_once("notices.inc"); <li><a href="/load_balancer_pool.php" class="navlnk">Load Balancer</a></li> <li><a href="/pkg_edit.php?xml=olsrd.xml&id=0" class="navlnk">OLSR</a></li> <li><a href="/services_snmp.php" class="navlnk">SNMP</a></li> - <li><a href="/status_upnp.php" class="navlnk">Miniupnpd</a></li> + <li><a href="/status_upnp.php" class="navlnk">MiniUPnPd</a></li> <li><a href="/services_wol.php" class="navlnk">Wake on LAN</a></li> <?php echo return_ext_menu("Services"); ?> </ul> diff --git a/usr/local/www/status_services.php b/usr/local/www/status_services.php index 4001d5a..26c38eb 100755 --- a/usr/local/www/status_services.php +++ b/usr/local/www/status_services.php @@ -46,48 +46,59 @@ if($_GET['mode'] == "restartservice" and $_GET['service']) { switch($_GET['service']) { case 'bsnmpd': services_snmpd_configure(); - sleep(5); break; case 'dnsmasq': services_dnsmasq_configure(); - sleep(5); break; case 'dhcpd': services_dhcpd_configure(); - sleep(5); + break; + case 'miniupnpd': + if(file_exists('/usr/local/etc/rc.d/miniupnpd.sh')) + mwexec('/usr/local/etc/rc.d/miniupnpd.sh restart'); break; default: restart_service($_GET['service']); - sleep(5); break; } $savemsg = "{$_GET['service']} has been restarted."; + sleep(5); } if($_GET['mode'] == "startservice" and $_GET['service']) { switch($_GET['service']) { case 'bsnmpd': services_snmpd_configure(); - sleep(5); break; case 'dnsmasq': services_dnsmasq_configure(); - sleep(5); break; case 'dhcpd': services_dhcpd_configure(); - sleep(5); + break; + case 'miniupnpd': + if(file_exists('/usr/local/etc/rc.d/miniupnpd.sh')) + mwexec('/usr/local/etc/rc.d/miniupnpd.sh start'); break; default: start_service($_GET['service']); - sleep(5); break; } $savemsg = "{$_GET['service']} has been started."; + sleep(5); } if($_GET['mode'] == "stopservice" and $_GET['service']) { + switch($_GET['service']) { + case 'miniupnpd': + /* can't just killbyname since we need to clear pf rules */ + if(file_exists('/usr/local/etc/rc.d/miniupnpd.sh')) + mwexec('/usr/local/etc/rc.d/miniupnpd.sh stop'); + break; + default: stop_service($_GET['service']); + break; + } $savemsg = "{$_GET['service']} has been stopped."; sleep(5); } @@ -189,6 +200,13 @@ if(isset($config['proxyarp']['proxyarpnet'])) { unset($pconfig); } +if($config['installedpackages']['miniupnpd']['config'][0]['enable']) { + $pconfig['name'] = "miniupnpd"; + $pconfig['description'] = gettext("MiniUPnPd Service"); + $services[] = $pconfig; + unset($pconfig); +} + if($services) { foreach($services as $service) { if(!$service['name']) continue; @@ -233,4 +251,3 @@ if($services) { <?php include("fend.inc"); ?> </body> </html> - diff --git a/usr/local/www/status_upnp.php b/usr/local/www/status_upnp.php index d1928ee..87e2294 100644 --- a/usr/local/www/status_upnp.php +++ b/usr/local/www/status_upnp.php @@ -32,7 +32,8 @@ require("guiconfig.inc"); /* Defaults to this page but if no settings are present, redirect to setup page */ -if(!$config['installedpackages']['miniupnpd']['config'][0]['iface_array']) +if(!$config['installedpackages']['miniupnpd']['config'][0]['iface_array'] || + !$config['installedpackages']['miniupnpd']['config'][0]['enable']) Header("Location: /pkg_edit.php?xml=miniupnpd.xml&id=0"); if ($_POST) { @@ -65,8 +66,8 @@ include("head.inc"); <table width="100%" border="0" cellpadding="0" cellspacing="0"> <?php $tab_array = array(); - $tab_array[] = array(gettext("UPNP Status "), true, "/status_upnp.php"); - $tab_array[] = array(gettext("miniupnpd Settings "), false, "/pkg_edit.php?xml=miniupnpd.xml&id=0"); + $tab_array[] = array(gettext("UPnP Status "), true, "/status_upnp.php"); + $tab_array[] = array(gettext("MiniUPnPd Settings "), false, "/pkg_edit.php?xml=miniupnpd.xml&id=0"); display_top_tabs($tab_array); ?> </table> @@ -88,7 +89,7 @@ include("head.inc"); <td width="60%" class="listhdr"><?=gettext("Description")?></td> </tr> <?php $i = 0; foreach ($rdr_entries as $rdr_entry) { - if (preg_match("/rdr on (.*) inet proto (.*) from any to any port = (.*) label \"(.*)\" -> (.*) port (.*)/", $rdr_entry, $matches)) + if (preg_match("/on (.*) inet proto (.*) from any to any port = (.*) label \"(.*)\" -> (.*) port (.*)/", $rdr_entry, $matches)) $rdr_proto = $matches[2]; $rdr_port = $matches[3]; $rdr_ip = $matches[5]; |