aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--packages/miniupnpd/miniupnpd.inc112
-rw-r--r--packages/miniupnpd/miniupnpd.xml9
-rw-r--r--packages/miniupnpd/status_upnp.php10
3 files changed, 73 insertions, 58 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
+?>
diff --git a/packages/miniupnpd/miniupnpd.xml b/packages/miniupnpd/miniupnpd.xml
index 2f310d62..5f46ad64 100644
--- a/packages/miniupnpd/miniupnpd.xml
+++ b/packages/miniupnpd/miniupnpd.xml
@@ -46,7 +46,7 @@
<fields>
<field>
<fielddescr>Interface (generally LAN)</fielddescr>
- <fieldname>interface_array</fieldname>
+ <fieldname>iface_array</fieldname>
<value>lan</value>
<multiple>true</multiple>
<size>3</size>
@@ -57,16 +57,13 @@
<fieldname>overridewanip</fieldname>
<type>input</type>
</field>
- </fields>
+ </fields>
<custom_php_resync_config_command>
- sync_package_miniupnpd();
+ sync_package_miniupnpd();
</custom_php_resync_config_command>
<custom_php_install_command>
sync_package_miniupnpd();
</custom_php_install_command>
- <custom_add_php_command>
- sync_package_miniupnpd();
- </custom_add_php_command>
<custom_php_deinstall_command>
exec("rm -f /usr/local/etc/rc.d/miniupnpd*");
</custom_php_deinstall_command>
diff --git a/packages/miniupnpd/status_upnp.php b/packages/miniupnpd/status_upnp.php
index 23bcc8ea..d1928ee0 100644
--- a/packages/miniupnpd/status_upnp.php
+++ b/packages/miniupnpd/status_upnp.php
@@ -32,16 +32,12 @@
require("guiconfig.inc");
/* Defaults to this page but if no settings are present, redirect to setup page */
-if(!is_array($config['installedpackages']['miniupnpd']['config'][0]['interface_array']))
- Header("Location: /pkg_edit.php?xml=miniupnpd.xml&amp;id=0");
+if(!$config['installedpackages']['miniupnpd']['config'][0]['iface_array'])
+ Header("Location: /pkg_edit.php?xml=miniupnpd.xml&id=0");
if ($_POST) {
if ($_POST['clear'] == "Clear") {
- // stop
- mwexec("/bin/sh /usr/local/etc/rc.d/miniupnpd.sh stop");
- usleep(300);
- // start
- mwexec("/bin/sh /usr/local/etc/rc.d/miniupnpd.sh start");
+ mwexec("/bin/sh /usr/local/etc/rc.d/miniupnpd.sh restart");
$savemsg = "Rules have been cleared and the daemon restarted";
}
}