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 /usr/local/pkg/miniupnpd.inc | |
parent | 32f5ff5af42027c32deab5336d6e6fc80364e766 (diff) | |
download | pfsense-422e039b33d37f6cadff5b2370ab4b036bef88f7.zip pfsense-422e039b33d37f6cadff5b2370ab4b036bef88f7.tar.gz |
MFC miniupnpd changes from Ryan Wagoner
Diffstat (limited to 'usr/local/pkg/miniupnpd.inc')
-rw-r--r-- | usr/local/pkg/miniupnpd.inc | 67 |
1 files changed, 47 insertions, 20 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 +?> |