summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--etc/inc/services.inc35
-rw-r--r--usr/local/pkg/miniupnpd.inc51
-rw-r--r--usr/local/pkg/miniupnpd.xml6
-rwxr-xr-xusr/local/www/status_services.php10
-rw-r--r--usr/local/www/status_upnp.php2
5 files changed, 40 insertions, 64 deletions
diff --git a/etc/inc/services.inc b/etc/inc/services.inc
index 0ddeb50..5b2158f 100644
--- a/etc/inc/services.inc
+++ b/etc/inc/services.inc
@@ -1272,11 +1272,38 @@ function configure_cron() {
conf_mount_ro();
}
+function upnp_action ($action) {
+ switch($action) {
+ case "start":
+ if(file_exists('/var/etc/miniupnpd.conf'))
+ mwexec_bg('/usr/local/sbin/miniupnpd -f /var/etc/miniupnpd.conf');
+ break;
+ case "stop":
+ while((int)exec("pgrep miniupnpd | wc -l") > 0)
+ mwexec('killall miniupnpd 2>/dev/null');
+ mwexec('/sbin/pfctl -aminiupnpd -Fr 2>&1 >/dev/null');
+ mwexec('/sbin/pfctl -aminiupnpd -Fn 2>&1 >/dev/null');
+ break;
+ case "restart":
+ upnp_action('stop');
+ upnp_action('start');
+ break;
+ }
+}
+
function upnp_start() {
- global $config;
- if($config['installedpackages']['miniupnpd']['config'][0]["enable"]) {
- mwexec_bg("/usr/local/sbin/miniupnpd -f /var/etc/miniupnpd.conf");
+ global $config, $g;
+ if($config['installedpackages']['miniupnpd']['config'][0]['enable']) {
+ if($g['booting']) {
+ echo "Starting UPnP service... ";
+ include('/usr/local/pkg/miniupnpd.inc');
+ sync_package_miniupnpd();
+ echo "done.\n";
+ }
+ else {
+ upnp_action('start');
+ }
}
}
-?> \ No newline at end of file
+?>
diff --git a/usr/local/pkg/miniupnpd.inc b/usr/local/pkg/miniupnpd.inc
index f4aa98c..5e1a204 100644
--- a/usr/local/pkg/miniupnpd.inc
+++ b/usr/local/pkg/miniupnpd.inc
@@ -9,22 +9,6 @@
function upnp_notice ($msg) { syslog(LOG_NOTICE, "miniupnpd: {$msg}"); return; }
function upnp_warn ($msg) { syslog(LOG_WARNING, "miniupnpd: {$msg}"); return; }
- function upnp_action ($action) {
- switch($action) {
- case "start":
- mwexec("killall miniupnpd 2>/dev/null");
- upnp_start();
- break;
- case "stop":
- mwexec("killall miniupnpd");
- break;
- case "restart":
- mwexec("killall miniupnpd");
- upnp_start();
- break;
- }
- }
-
function upnp_running () {
if((int)exec("pgrep miniupnpd | wc -l") > 0)
return true;
@@ -39,10 +23,10 @@
}
function upnp_write_config($conf_file, $conf_text) {
- $conf_file = "/var/etc/miniupnpd.conf";
$conf = fopen($conf_file, "w");
if(!$conf) {
upnp_warn("Could not open {$conf_file} for writing.");
+ echo "Could not open {$conf_file} for writing.";
exit;
}
fwrite($conf, $conf_text);
@@ -155,8 +139,6 @@
/* since config is written before this file invoked we don't need to read post data */
if(upnp_config('enable') && upnp_config('iface_array'))
$iface_array = explode(',',upnp_config('iface_array'));
- else
- upnp_action("stop");
if($iface_array) {
foreach($iface_array as $iface) {
@@ -234,28 +216,8 @@
if(upnp_config('permdefault'))
$configtext .= "deny 0-65535 0.0.0.0/0 0-65535\n";
- /* generate rc file start and stop */
- $stop = <<<EOD
-if [ `pgrep miniupnpd | wc -l` != 0 ]; then
- /usr/bin/killall miniupnpd
- while [ `pgrep miniupnpd | wc -l` != 0 ]; do
- sleep 1
- done
- fi
- # Clear existing rules and rdr entries
- if [ `pfctl -aminiupnpd -sr | wc -l` != 0 ]; then
- /sbin/pfctl -aminiupnpd -Fr 2>&1 >/dev/null
- fi
- if [ `pfctl -aminiupnpd -sn | wc -l` != 0 ]; then
- /sbin/pfctl -aminiupnpd -Fn 2>&1 >/dev/null
- fi
-EOD;
- $start = $stop."\n\t/usr/local/sbin/miniupnpd -f ".UPNP_CONFIG;
-
/* write out the configuration */
- conf_mount_rw();
upnp_write_config(UPNP_CONFIG,$configtext);
- conf_mount_ro();
/* if miniupnpd not running start it */
if(!upnp_running()) {
@@ -274,18 +236,15 @@ EOD;
/* no parameters user does not want miniupnpd running */
/* lets stop the service and remove the rc file */
- if(file_exists(UPNP_RCFILE)) {
+ if(file_exists(UPNP_CONFIG)) {
if(!upnp_config('enable'))
upnp_notice('Stopping service: miniupnpd disabled');
else
- upnp_notice('Stopping service: no interfaces selected');
-
- upnp_action('stop');
+ upnp_notice('Stopping service: no interfaces selected');
- conf_mount_rw();
- unlink(UPNP_RCFILE);
+ upnp_notice('Stopping service: miniupnpd disabled');
+ upnp_action('stop');
unlink(UPNP_CONFIG);
- conf_mount_ro();
}
}
diff --git a/usr/local/pkg/miniupnpd.xml b/usr/local/pkg/miniupnpd.xml
index bac2337..dc3b057 100644
--- a/usr/local/pkg/miniupnpd.xml
+++ b/usr/local/pkg/miniupnpd.xml
@@ -123,10 +123,4 @@
<custom_php_resync_config_command>
sync_package_miniupnpd();
</custom_php_resync_config_command>
- <custom_php_install_command>
- sync_package_miniupnpd();
- </custom_php_install_command>
- <custom_php_deinstall_command>
- exec("rm -f /usr/local/etc/rc.d/miniupnpd*");
- </custom_php_deinstall_command>
</packagegui>
diff --git a/usr/local/www/status_services.php b/usr/local/www/status_services.php
index 42c0da1..f603507 100755
--- a/usr/local/www/status_services.php
+++ b/usr/local/www/status_services.php
@@ -54,8 +54,7 @@ if($_GET['mode'] == "restartservice" and $_GET['service']) {
services_dhcpd_configure();
break;
case 'miniupnpd':
- if(file_exists('/usr/local/etc/rc.d/miniupnpd.sh'))
- mwexec('/usr/local/etc/rc.d/miniupnpd.sh restart');
+ upnp_action('restart');
break;
case 'racoon':
exec("killall -9 racoon");
@@ -95,8 +94,7 @@ if($_GET['mode'] == "startservice" and $_GET['service']) {
services_dhcpd_configure();
break;
case 'miniupnpd':
- if(file_exists('/usr/local/etc/rc.d/miniupnpd.sh'))
- mwexec('/usr/local/etc/rc.d/miniupnpd.sh start');
+ upnp_action('start');
break;
case 'racoon':
exec("killall -9 racoon");
@@ -140,9 +138,7 @@ if($_GET['mode'] == "stopservice" && $_GET['service']) {
killbypid("{$g['varrun_path']}/dnsmasq.pid");
break;
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');
+ upnp_action('stop');
break;
case 'ntpd':
killbyname("ntpd");
diff --git a/usr/local/www/status_upnp.php b/usr/local/www/status_upnp.php
index f13c6d8..cea49a8 100644
--- a/usr/local/www/status_upnp.php
+++ b/usr/local/www/status_upnp.php
@@ -33,7 +33,7 @@ require("guiconfig.inc");
if ($_POST) {
if ($_POST['clear'] == "Clear") {
- mwexec("/bin/sh /usr/local/etc/rc.d/miniupnpd.sh restart");
+ upnp_action('restart');
$savemsg = "Rules have been cleared and the daemon restarted";
}
}
OpenPOWER on IntegriCloud