From 4deab50ab286daac0c563ca0ccfe0220c9b95364 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Tue, 3 Jan 2017 23:10:18 +0100 Subject: [PATCH] net/igmpproxy: export from core --- net/igmpproxy/Makefile | 8 + .../src/etc/inc/plugins.inc.d/igmpproxy.inc | 121 ++++++++ .../app/models/OPNsense/IGMPProxy/ACL/ACL.xml | 14 + .../models/OPNsense/IGMPProxy/Menu/Menu.xml | 7 + net/igmpproxy/src/www/services_igmpproxy.php | 149 ++++++++++ .../src/www/services_igmpproxy_edit.php | 281 ++++++++++++++++++ 6 files changed, 580 insertions(+) create mode 100644 net/igmpproxy/Makefile create mode 100644 net/igmpproxy/src/etc/inc/plugins.inc.d/igmpproxy.inc create mode 100644 net/igmpproxy/src/opnsense/mvc/app/models/OPNsense/IGMPProxy/ACL/ACL.xml create mode 100644 net/igmpproxy/src/opnsense/mvc/app/models/OPNsense/IGMPProxy/Menu/Menu.xml create mode 100644 net/igmpproxy/src/www/services_igmpproxy.php create mode 100644 net/igmpproxy/src/www/services_igmpproxy_edit.php diff --git a/net/igmpproxy/Makefile b/net/igmpproxy/Makefile new file mode 100644 index 000000000..fef19a7f2 --- /dev/null +++ b/net/igmpproxy/Makefile @@ -0,0 +1,8 @@ +PLUGIN_NAME= igmpproxy +PLUGIN_VERSION= 0.1 +PLUGIN_PRIVATE= yes +PLUGIN_DEPENDS= igmpproxy +PLUGIN_COMMENT= IGMP-Proxy Service +PLUGIN_MAINTAINER= franco@opnsense.org + +.include "../../Mk/plugins.mk" diff --git a/net/igmpproxy/src/etc/inc/plugins.inc.d/igmpproxy.inc b/net/igmpproxy/src/etc/inc/plugins.inc.d/igmpproxy.inc new file mode 100644 index 000000000..4ae52c5eb --- /dev/null +++ b/net/igmpproxy/src/etc/inc/plugins.inc.d/igmpproxy.inc @@ -0,0 +1,121 @@ + + Copyright (C) 2010 Ermal Luci + Copyright (C) 2005-2006 Colin Smith + Copyright (C) 2003-2004 Manuel Kasper + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ + +function igmpproxy_enabled() +{ + global $config; + + return isset($config['igmpproxy']['igmpentry']); +} + +function igmpproxy_services() +{ + $services = array(); + + if (!igmpproxy_enabled()) { + return $services; + } + + $pconfig = array(); + $pconfig['name'] = 'igmpproxy'; + $pconfig['description'] = gettext('IGMP Proxy'); + $pconfig['php']['restart'] = array('igmpproxy_configure_do'); + $pconfig['php']['start'] = array('igmpproxy_configure_do'); + $services[] = $pconfig; + + return $services; +} + +function igmpproxy_configure() +{ + return array( + 'bootup' => array('igmpproxy_configure_do'), + 'interface' => array('igmpproxy_configure_do'), + ); +} + +function igmpproxy_configure_do($verbose = false) +{ + global $config; + + killbyname('igmpproxy'); + + if (!igmpproxy_enabled()) { + return; + } + + if ($verbose) { + echo 'Starting IGMP Proxy...'; + flush(); + } + + $iflist = get_configured_interface_list(); + + $igmpconf = << "") { + $item = explode(" ", $igmpcf['address']); + foreach($item as $iww) { + $igmpconf .= "altnet {$iww}\n"; + } + } + $igmpconf .= "\n"; + } + foreach ($iflist as $ifn) { + $realif = get_real_interface($ifn); + $igmpconf .= "phyint {$realif} disabled\n"; + } + $igmpconf .= "\n"; + + file_put_contents('/usr/local/etc/igmpproxy.conf', $igmpconf); + mwexec('/usr/local/etc/rc.d/igmpproxy onestart'); + + if ($verbose) { + print "done.\n"; + } +} diff --git a/net/igmpproxy/src/opnsense/mvc/app/models/OPNsense/IGMPProxy/ACL/ACL.xml b/net/igmpproxy/src/opnsense/mvc/app/models/OPNsense/IGMPProxy/ACL/ACL.xml new file mode 100644 index 000000000..5abf99b26 --- /dev/null +++ b/net/igmpproxy/src/opnsense/mvc/app/models/OPNsense/IGMPProxy/ACL/ACL.xml @@ -0,0 +1,14 @@ + + + Services: IGMP Proxy + + services_igmpproxy.php* + + + + Services: IGMP Proxy: Edit + + services_igmpproxy_edit.php* + + + diff --git a/net/igmpproxy/src/opnsense/mvc/app/models/OPNsense/IGMPProxy/Menu/Menu.xml b/net/igmpproxy/src/opnsense/mvc/app/models/OPNsense/IGMPProxy/Menu/Menu.xml new file mode 100644 index 000000000..03dde8678 --- /dev/null +++ b/net/igmpproxy/src/opnsense/mvc/app/models/OPNsense/IGMPProxy/Menu/Menu.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/net/igmpproxy/src/www/services_igmpproxy.php b/net/igmpproxy/src/www/services_igmpproxy.php new file mode 100644 index 000000000..7c0361aed --- /dev/null +++ b/net/igmpproxy/src/www/services_igmpproxy.php @@ -0,0 +1,149 @@ +. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ + +require_once("guiconfig.inc"); +require_once("interfaces.inc"); +require_once("services.inc"); +require_once('plugins.inc.d/igmpproxy.inc'); + +$a_igmpproxy = array(); +if (isset($config['igmpproxy']['igmpentry'])) { + $a_igmpproxy = &$config['igmpproxy']['igmpentry']; +} + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + if (isset($_POST['act']) && $_POST['act'] == "del") { + if (isset($_POST['id']) && !empty($a_igmpproxy[$_POST['id']])){ + unset($a_igmpproxy[$_POST['id']]); + write_config(); + igmpproxy_configure_do(); + } + header(url_safe('Location: /services_igmpproxy.php')); + exit; + } +} + +$service_hook = 'igmpproxy'; + +include("head.inc"); + +legacy_html_escape_form_data($a_igmpproxy); + +$main_buttons = array( + array('label' => gettext('Add a new IGMP entry'), 'href' => 'services_igmpproxy_edit.php'), +); + +?> + + + +
+
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + " class="btn btn-default btn-xs"> + +
+ +
+
+
+
+
+
+
+
+ diff --git a/net/igmpproxy/src/www/services_igmpproxy_edit.php b/net/igmpproxy/src/www/services_igmpproxy_edit.php new file mode 100644 index 000000000..c1d4970cf --- /dev/null +++ b/net/igmpproxy/src/www/services_igmpproxy_edit.php @@ -0,0 +1,281 @@ +. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ + +require_once("guiconfig.inc"); +require_once("services.inc"); +require_once('plugins.inc.d/igmpproxy.inc'); + +if (!isset($config['igmpproxy']['igmpentry'])) { + $config['igmpproxy']['igmpentry'] = array(); +} +$a_igmpproxy = &$config['igmpproxy']['igmpentry']; + +if ($_SERVER['REQUEST_METHOD'] === 'GET') { + if (isset($_GET['id']) && !empty($a_igmpproxy[$_GET['id']])) { + $id = $_GET['id']; + } + $pconfig = array(); + foreach (array('ifname', 'threshold', 'type', 'address', 'descr') as $fieldname) { + if (isset($id) && isset($a_igmpproxy[$id][$fieldname])) { + $pconfig[$fieldname] = $a_igmpproxy[$id][$fieldname]; + } else { + $pconfig[$fieldname] = null; + } + } + $pconfig['networks_network'] = array(); + $pconfig['networks_mask'] = array(); + foreach (explode(" ", $pconfig['address']) as $entry) { + $parts = explode('/', $entry); + $pconfig['networks_network'][] = $parts[0]; + $pconfig['networks_mask'][] = $parts[1]; + } +} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { + if (isset($_POST['id']) && !empty($a_igmpproxy[$_POST['id']])) { + $id = $_POST['id']; + } + $pconfig = $_POST; + $input_errors = array(); + $pconfig['address'] = ""; + foreach ($pconfig['networks_network'] as $idx => $value) { + if (!empty($value) && !empty($pconfig['networks_mask'][$idx])) { + $pconfig['address'] .= " " . $value . "/" . $pconfig['networks_mask'][$idx]; + } + } + $pconfig['address'] = trim($pconfig['address']); + if ($pconfig['type'] == "upstream") { + foreach ($a_igmpproxy as $pid => $proxyentry) { + if (isset($id) && $id == $pid) { + continue; + } + if ($proxyentry['type'] == "upstream" && $proxyentry['ifname'] != $pconfig['interface']) { + $input_errors[] = gettext("Only one 'upstream' interface can be configured."); + } + } + } + if (count($input_errors) == 0) { + $igmpentry = array(); + $igmpentry['ifname'] = $pconfig['ifname']; + $igmpentry['threshold'] = $pconfig['threshold']; + $igmpentry['type'] = $pconfig['type']; + $igmpentry['address'] = $pconfig['address']; + $igmpentry['descr'] = $pconfig['descr']; + + if (isset($id)) { + $a_igmpproxy[$id] = $igmpentry; + } else { + $a_igmpproxy[] = $igmpentry; + } + + write_config(); + igmpproxy_configure_do(); + header(url_safe('Location: /services_igmpproxy.php')); + exit; + } +} + +legacy_html_escape_form_data($pconfig); +include("head.inc"); +?> + + + + + +
+
+
+ 0) print_input_errors($input_errors); ?> +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+ + +
+ + +
+ + +
+ + + + + + + + + + $network):?> + + + + + + + + + + + + +
+
+
+ + + +
+
+
+
+ " /> + " /> + + + +
+
+
+
+
+
+
+
+