Commit 79edae2c authored by Franco Fichtner's avatar Franco Fichtner

universal plug and play: align with service hooks

parent d9810025
......@@ -139,12 +139,13 @@ function sync_package_miniupnpd() {
/* if miniupnpd not running start it */
if(!upnp_running()) {
upnp_notice("Starting service on interface: {$ifaces_active}");
upnp_action('start');
upnp_start();
}
/* or restart miniupnpd if settings were changed */
else {
upnp_notice("Restarting service on interface: {$ifaces_active}");
upnp_action('restart');
upnp_stop();
upnp_start();
}
}
} else {
......@@ -157,7 +158,7 @@ function sync_package_miniupnpd() {
else
upnp_notice('Stopping service: no interfaces selected');
upnp_action('stop');
upnp_stop();
@unlink($config_file);
}
}
......
<?php
/*
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>
Copyright (C) 2005-2006 Colin Smith <ethethlay@gmail.com>
Copyright (C) 2014-2016 Franco Fichtner <franco@opnsense.org>
Copyright (C) 2010 Ermal Luci
Copyright (C) 2005-2006 Colin Smith <ethethlay@gmail.com>
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>
All rights reserved.
Redistribution and use in source and binary forms, with or without
......@@ -2430,33 +2431,25 @@ function configure_cron()
killbypid('/var/run/cron.pid', 'HUP');
}
function upnp_action($action)
function upnp_start()
{
global $config;
if (file_exists('/var/etc/miniupnpd.conf')) {
@unlink('/var/run/miniupnpd.pid');
mwexec_bg('/usr/local/sbin/miniupnpd -f /var/etc/miniupnpd.conf -P /var/run/miniupnpd.pid');
}
}
switch($action) {
case "start":
if (file_exists('/var/etc/miniupnpd.conf')) {
@unlink('/var/run/miniupnpd.pid');
mwexec_bg('/usr/local/sbin/miniupnpd -f /var/etc/miniupnpd.conf -P /var/run/miniupnpd.pid');
}
break;
case "stop":
killbypid('/var/run/miniupnpd.pid');
while((int)exec("/bin/pgrep -a miniupnpd | wc -l") > 0) {
mwexec('killall miniupnpd 2>/dev/null', true);
}
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_stop()
{
killbypid('/var/run/miniupnpd.pid');
while((int)exec("/bin/pgrep -a miniupnpd | wc -l") > 0) {
mwexec('killall miniupnpd 2>/dev/null', true);
}
mwexec('/sbin/pfctl -aminiupnpd -Fr 2>&1 >/dev/null');
mwexec('/sbin/pfctl -aminiupnpd -Fn 2>&1 >/dev/null');
}
function upnp_start()
function upnp_configure()
{
global $config;
......@@ -2467,7 +2460,6 @@ function upnp_start()
}
}
function install_cron_job($command, $active=false, $minute="0", $hour="*", $monthday="*", $month="*", $weekday="*", $who="root") {
global $config;
......@@ -2644,6 +2636,11 @@ function services_get()
$pconfig = array();
$pconfig['name'] = "miniupnpd";
$pconfig['description'] = gettext("UPnP Service");
$pconfig['description'] = gettext("UPnP Service");
$pconfig['php']['restart'] = array('upnp_stop', 'upnp_start');
$pconfig['php']['start'] = array('upnp_start');
$pconfig['php']['stop'] = array('upnp_stop');
$pconfig['pidfile'] = '/var/run/miniupnpd.pid';
$services[] = $pconfig;
}
......
......@@ -341,7 +341,7 @@ if ($kern_hz == '1000') {
services_igmpproxy_configure();
/* start the upnp daemon if it is enabled */
upnp_start();
upnp_configure();
/* If powerd is enabled, lets launch it */
activate_powerd();
......
......@@ -84,10 +84,6 @@ function service_control_start($name, $extras)
}
}
return $msg;
/* XXX extra argument is extra tricky */
} elseif ($name == 'miniupnpd') {
upnp_action('start');
return $msg;
}
$service = find_service_by_name($name);
......@@ -119,12 +115,6 @@ function service_control_stop($name, $extras)
$msg = sprintf(gettext("%s has been stopped."), htmlspecialchars($name));
$filter = array();
/* XXX extra argument is extra tricky */
if ($name == 'miniupnpd') {
upnp_action('stop');
return $msg;
}
if ($name == 'openvpn') {
$filter['mode'] = $extras['vpnmode']; /* XXX I think mode is spurious */
$filter['vpnid'] = $extras['id'];
......@@ -192,7 +182,8 @@ function service_control_restart($name, $extras) {
services_igmpproxy_configure();
break;
case 'miniupnpd':
upnp_action('restart');
upnp_stop();
upnp_start();
break;
case 'ipsec':
vpn_ipsec_force_reload();
......
......@@ -33,7 +33,8 @@ require_once("interfaces.inc");
if ($_POST) {
if ($_POST['clear'] == "Clear") {
upnp_action('restart');
upnp_stop();
upnp_start();
$savemsg = gettext("Rules have been cleared and the daemon restarted");
}
}
......@@ -111,7 +112,7 @@ include("head.inc");
</div>
<form action="status_upnp.php" method="post">
<input type="submit" name="clear" id="clear" class="btn btn-primary" value="<?=gettext("Clear");?>" /> <?=gettext("all currently connected sessions");?>.
<button type="submit" name="clear" id="clear" class="btn btn-primary" value="Clear"><?=gettext("Clear");?></button> <?=gettext("all currently connected sessions");?>.
</form>
<?php endif; ?>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment