diff options
Diffstat (limited to 'packages/miniupnpd/miniupnpd.inc')
-rw-r--r-- | packages/miniupnpd/miniupnpd.inc | 112 |
1 files changed, 67 insertions, 45 deletions
diff --git a/packages/miniupnpd/miniupnpd.inc b/packages/miniupnpd/miniupnpd.inc index d536253c..fb81fdbc 100644 --- a/packages/miniupnpd/miniupnpd.inc +++ b/packages/miniupnpd/miniupnpd.inc @@ -1,69 +1,91 @@ <?php require_once("config.inc"); require_once("functions.inc"); + + function upnp_notice ($msg) { syslog(LOG_NOTICE, "miniupnpd: $msg"); return; } + function upnp_warn ($msg) { syslog(LOG_WARNING, "miniupnpd: $msg"); return; } + /* Miniupnp */ function sync_package_miniupnpd() { global $config; global $input_errors; - conf_mount_rw(); - config_lock(); - $miniupnpd_config =&$_POST; - $if_final = ""; - $ifaces_final = ""; - $first = 0; + $ifaces_final = ""; $wanif = get_real_wan_interface(); - if($_POST['overridewanip']) - $overridewanip = $_POST['overridewanip']; - else if($config['installedpackages']['miniupnpd']['config'][0]['overridewanip']) - $overridewanip = $config['installedpackages']['miniupnpd']['config'][0]['overridewanip']; + upnp_notice("Syncing package"); - if($_POST['interface_array']) - $interface_array = $_POST['interface_array']; - else if(is_array($config['installedpackages']['miniupnpd']['config'][0]['interface_array'])) - $interface_array = $config['installedpackages']['miniupnpd']['config'][0]['interface_array']; + conf_mount_rw(); + config_lock(); - if($interface_array) { - foreach($interface_array as $iface) { + /* since config is written before this file invoked we don't need to read post data */ + if($config['installedpackages']['miniupnpd']['config'][0]['overridewanip']) + $overridewanip = $config['installedpackages']['miniupnpd']['config'][0]['overridewanip']; + if($config['installedpackages']['miniupnpd']['config'][0]['iface_array']) + $iface_array = explode(",",$config['installedpackages']['miniupnpd']['config'][0]['iface_array']); + + if($iface_array) { + foreach($iface_array as $iface) { $if = convert_friendly_interface_to_real_interface_name($iface); - if($if) { + /* above function returns iface if fail */ + if($if!=$iface) { $addr = find_interface_ip($if); - $ifaces_final .= " -i {$wanif} -a {$addr}"; - $first = 1; + /* non enbaled interfaces are displayed in list on miniupnpd settings page */ + /* check that the interface has an ip address before adding paramters */ + if($addr) { + upnp_notice("Active on {$iface} interface"); + $ifaces_final .= " -i {$wanif} -a {$addr}"; + } else { + upnp_warn("Interface {$iface} has no ip address"); + } } else { - log_error("Could not resolve real interface {$iface}"); + upnp_warn("Could not resolve real interface {$iface}"); } } - $start = "# Clear existing rules and rdr entries \n"; - $start .= "/sbin/pfctl -aminiupnpd -Fr 2>&1 >/dev/null\n"; - $start .= "/sbin/pfctl -aminiupnpd -Fn 2>&1 >/dev/null\n"; - $start .= "/usr/bin/killall miniupnpd\n"; - $start .= "while [ `ps -A | grep /usr/local/sbin/miniupnpd | grep -v grep | wc -l` != 0 ]; do sleep 1; done\n"; - $start .= "/usr/local/sbin/miniupnpd -p 2869{$ifaces_final}"; - /* override wan ip address, common for carp, etc */ - if($overridewanip) - $start .= " -o {$overridewanip}"; + if($ifaces_final) { + /* valid paramters lets create rc file and start miniupnpd */ + + $start = "/usr/bin/killall miniupnpd\n"; + $start .= "# Clear existing rules and rdr entries \n"; + $start .= "/sbin/pfctl -aminiupnpd -Fr 2>&1 >/dev/null\n"; + $start .= "/sbin/pfctl -aminiupnpd -Fn 2>&1 >/dev/null\n"; + $start .= "while [ `pgrep miniupnpd | wc -l` != 0 ]; do sleep 1; done\n"; + $start .= "/usr/local/sbin/miniupnpd -p 2869{$ifaces_final}"; + + /* override wan ip address, common for carp, etc */ + if($overridewanip) + $start .= " -o {$overridewanip}"; + + $stop = "/usr/bin/killall miniupnpd \n"; + $stop .= "# Clear existing rules and rdr entries \n"; + $stop .= "/sbin/pfctl -aminiupnpd -Fr 2>&1 >/dev/null\n"; + $stop .= "/sbin/pfctl -aminiupnpd -Fn 2>&1 >/dev/null"; + write_rcfile(array( + "file" => "miniupnpd.sh", + "start" => $start, + "stop" => $stop + ) + ); - $stop .= "/usr/bin/killall miniupnpd \n"; - $stop .= "# Clear existing rules and rdr entries \n"; - $stop .= "/sbin/pfctl -aminiupnpd -Fr 2>&1 >/dev/null\n"; - $stop .= "/sbin/pfctl -aminiupnpd -Fn 2>&1 >/dev/null\n"; - write_rcfile(array( - "file" => "miniupnpd.sh", - "start" => $start, - "stop" => $stop - ) - ); + /* 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"); + } + } } - /* if not ONE instance running lets start */ - /* or if $_POST data as user is changing settings */ - if((int)exec("ps -A | grep /usr/local/sbin/miniupnpd | grep -v grep | wc -l") != 1 || $_POST['interface_array']) { - start_service("miniupnpd"); - } + if(!$iface_array || !$ifaces_final) { + /* 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*"); + } config_unlock(); conf_mount_ro(); } -?>
\ No newline at end of file +?> |