From 55cffd5bafe4433a6f992b793b13025dafe5a038 Mon Sep 17 00:00:00 2001 From: Martin Wasley Date: Wed, 15 Apr 2020 13:26:11 +0100 Subject: [PATCH] net/udpbroadcastrelay plugin - Initial commit (#1677) --- net/udpbroadcastrelay/Makefile | 8 + net/udpbroadcastrelay/pkg-descr | 29 ++ .../inc/plugins.inc.d/udpbroadcastrelay.inc | 83 ++++ .../src/etc/rc.d/os-udpbroadcastrelay | 170 +++++++++ .../Api/ServiceController.php | 174 +++++++++ .../Api/SettingsController.php | 353 ++++++++++++++++++ .../UDPBroadcastRelay/IndexController.php | 47 +++ .../UDPBroadcastRelay/forms/dialogEdit.xml | 52 +++ .../OPNsense/UDPBroadcastRelay/ACL/ACL.xml | 9 + .../OPNsense/UDPBroadcastRelay/Menu/Menu.xml | 5 + .../UDPBroadcastRelay/UDPBroadcastRelay.php | 39 ++ .../UDPBroadcastRelay/UDPBroadcastRelay.xml | 60 +++ .../OPNsense/UDPBroadcastRelay/index.volt | 118 ++++++ .../actions.d/actions_udpbroadcastrelay.conf | 29 ++ .../OPNsense/UDPBroadcastRelay/+TARGETS | 1 + .../OPNsense/UDPBroadcastRelay/rc.conf.d | 37 ++ 16 files changed, 1214 insertions(+) create mode 100644 net/udpbroadcastrelay/Makefile create mode 100644 net/udpbroadcastrelay/pkg-descr create mode 100644 net/udpbroadcastrelay/src/etc/inc/plugins.inc.d/udpbroadcastrelay.inc create mode 100644 net/udpbroadcastrelay/src/etc/rc.d/os-udpbroadcastrelay create mode 100644 net/udpbroadcastrelay/src/opnsense/mvc/app/controllers/OPNsense/UDPBroadcastRelay/Api/ServiceController.php create mode 100644 net/udpbroadcastrelay/src/opnsense/mvc/app/controllers/OPNsense/UDPBroadcastRelay/Api/SettingsController.php create mode 100644 net/udpbroadcastrelay/src/opnsense/mvc/app/controllers/OPNsense/UDPBroadcastRelay/IndexController.php create mode 100644 net/udpbroadcastrelay/src/opnsense/mvc/app/controllers/OPNsense/UDPBroadcastRelay/forms/dialogEdit.xml create mode 100644 net/udpbroadcastrelay/src/opnsense/mvc/app/models/OPNsense/UDPBroadcastRelay/ACL/ACL.xml create mode 100644 net/udpbroadcastrelay/src/opnsense/mvc/app/models/OPNsense/UDPBroadcastRelay/Menu/Menu.xml create mode 100644 net/udpbroadcastrelay/src/opnsense/mvc/app/models/OPNsense/UDPBroadcastRelay/UDPBroadcastRelay.php create mode 100644 net/udpbroadcastrelay/src/opnsense/mvc/app/models/OPNsense/UDPBroadcastRelay/UDPBroadcastRelay.xml create mode 100644 net/udpbroadcastrelay/src/opnsense/mvc/app/views/OPNsense/UDPBroadcastRelay/index.volt create mode 100644 net/udpbroadcastrelay/src/opnsense/service/conf/actions.d/actions_udpbroadcastrelay.conf create mode 100644 net/udpbroadcastrelay/src/opnsense/service/templates/OPNsense/UDPBroadcastRelay/+TARGETS create mode 100644 net/udpbroadcastrelay/src/opnsense/service/templates/OPNsense/UDPBroadcastRelay/rc.conf.d diff --git a/net/udpbroadcastrelay/Makefile b/net/udpbroadcastrelay/Makefile new file mode 100644 index 000000000..22783a489 --- /dev/null +++ b/net/udpbroadcastrelay/Makefile @@ -0,0 +1,8 @@ +PLUGIN_NAME= os-udpbroadcastrelay +PLUGIN_VERSION= 0.7 +PLUGIN_DEVEL= YES +PLUGIN_COMMENT= Control ubpbroadcastrelay processes +PLUGIN_DEPENDS= udpbroadcastrelay +PLUGIN_MAINTAINER= mjwasley@gmail.com + +.include "../../Mk/plugins.mk" diff --git a/net/udpbroadcastrelay/pkg-descr b/net/udpbroadcastrelay/pkg-descr new file mode 100644 index 000000000..1a1c37af0 --- /dev/null +++ b/net/udpbroadcastrelay/pkg-descr @@ -0,0 +1,29 @@ +udbproadcastrelay is a UDP multicast relayer. Its intended use is to +rebroadbcast udp packets on a specific port across interfaces, be those +interfaces physical or VLAN. + +It is used where devices such as Sonos or Sky are spread accross +different subnets and are not able to detect the servers or devices. + +Examples of different devices and the ports are as follows: + +Syncthing discovery +udp_vars="--id 1 --port 21027 --dev igb1 --dev igb2" + +mDNS / Broadcast DNS (Chromecast Discovery + Bonjour + More) +udp_vars="--id 1 --port 5353 --dev eth0 --dev eth1 --multicast 224.0.0.251 -s 1.1.1.1" + +(Chromecast requires broadcasts to originate from an address on its subnet) use +the rebroadbcast address option. + +SSDP (Sonos Roku Discovery + More) +udp_vars="--id 1 --port 1900 --dev eth0 --dev eth1 --multicast 239.255.255.250" + +Lifx Bulb Discovery +udp_vars=" --id 1 --port 56700 --dev eth0 --dev eth1" + +Broadlink IR Emitter Discovery +udp_vars=" --id 1 --port 80 --dev eth0 --dev eth1" + +Warcraft 3 Server Discovery +udp_vars=" --id 1 --port 6112 --dev eth0 --dev eth1" diff --git a/net/udpbroadcastrelay/src/etc/inc/plugins.inc.d/udpbroadcastrelay.inc b/net/udpbroadcastrelay/src/etc/inc/plugins.inc.d/udpbroadcastrelay.inc new file mode 100644 index 000000000..1a3b3aa82 --- /dev/null +++ b/net/udpbroadcastrelay/src/etc/inc/plugins.inc.d/udpbroadcastrelay.inc @@ -0,0 +1,83 @@ +udpbroadcastrelay->iterateItems() as $server) { + if ($server->enabled == '1') { + return true; + } + } + + return false; +} + +function udpbroadcastrelay_firewall($fw) +{ + if (!udpbroadcastrelay_enabled()) { + return; + } +} + +function udpbroadcastrelay_services() +{ + $services = array(); + + if (!udpbroadcastrelay_enabled()) { + return $services; + } + + $model = new \OPNsense\UDPBroadcastRelay\UDPBroadcastRelay(); + + foreach ($model->udpbroadcastrelay->iterateItems() as $server) { + + if ($server->enabled == '0'){ + continue; + } + + $services[] = array( + + 'description' => $server->description, + 'id' => $server->InstanceID, + 'pidfile' => "/var/run/udpbroadcastrelay_{$server->InstanceID}.pid", + 'configd' => array( + 'restart' => array('udpbroadcastrelay restart '.$server->InstanceID), + 'start' => array('udpbroadcastrelay start '.$server->InstanceID), + 'stop' => array('udpbroadcastrelay stop '.$server->InstanceID), + + ), + + 'name' => 'udpbroadcastrelay', + ); + + } + + return $services; +} diff --git a/net/udpbroadcastrelay/src/etc/rc.d/os-udpbroadcastrelay b/net/udpbroadcastrelay/src/etc/rc.d/os-udpbroadcastrelay new file mode 100644 index 000000000..d076d6901 --- /dev/null +++ b/net/udpbroadcastrelay/src/etc/rc.d/os-udpbroadcastrelay @@ -0,0 +1,170 @@ +#!/bin/sh +# +# $FreeBSD$ +# + +# PROVIDE: osudpbroadcastrelay +# KEYWORD: shutdown + +. /etc/rc.subr + +name="osudpbroadcastrelay" +rcvar="osudpbroadcastrelay_enable" +command="/usr/local/sbin/udpbroadcastrelay" +extra_commands="reload" +reload_cmd="udpbroadcastrelay_reload" + + +load_rc_config $name + +if [ -n "$2" ]; then + eval osudpbroadcastrelay_flags=\$osudpbroadcastrelay_${2} + pidfile="/var/run/udpbroadcastrelay_$2.pid" +fi + + +udpbroadcastrelay_start () { + udpbroadcastrelay_status + if [ $? -eq 0 ]; then # already running + return 0 + fi + run_rc_command "start" + if [ $? -eq 0 ]; then + cmd_string=`basename ${procname:-${command}}` + cmd="ps ax -o pid= -o command= | grep $cmd_string | grep -e "$osudpbroadcastrelay_flags" | grep -v grep | awk '{ print $1 }" + ps_pid=$cmd + if [ -z "$ps_pid" ]; then + err 1 "Cannot get pid for $cmd_string $osudpbroadcastrelay_flags" + fi + return $? + fi + return 1 +} + +udpbroadcastrelay_stop () { + udpbroadcastrelay_status + if [ $? -eq 1 ]; then # already stopped + return 0 + fi + run_rc_command "stop" + if [ $? -ne 0 ]; then + err 1 "Cannot stop udpbroadcastrelay with pid from $pidfile" + fi + rm -f $pidfile + return $? +} + +udpbroadcastrelay_restart () { + udpbroadcastrelay_stop + if [ $? -ne 0 ]; then + return $? + fi + udpbroadcastrelay_start + return $? +} + +udpbroadcastrelay_status () { + if [ -z "$pidfile" ]; then + err 1 "Instance name unknown" + fi + run_rc_command "status" + return $? +} + +udpbroadcastrelay_reload () { + osudpbroadcastrelay_flags="" + pidfile="" + # get running instances + ps ax -o pid= -o command= | grep "udpbroadcastrelay" | grep -v grep | while read line; do + # get instance name + instance=`echo $line | awk '{printf "%s", $4 }' | sed 's/\./_/g'` + # get instance flags + instance_flags="${line#*udpbroadcastrelay}" + # check if it should run + echo + eval osudpbroadcastrelay_flags=\$osudpbroadcastrelay_${instance} + + if [ -n "$osudpbroadcastrelay_flags" -a "$osudpbroadcastrelay_flags" = "$instance_flags" ]; then + echo "running instance $instance match config" + continue + fi + echo "running instance $instance not configured" + osudpbroadcastrelay_flags=$instance_flags + pidfile="/var/run/udpbroadcastrelay_$instance.pid" + udpbroadcastrelay_stop + done + # start configured instances + + if [ -n "$osudpbroadcastrelay_instances" ]; then + + for i in $osudpbroadcastrelay_instances; do + eval osudpbroadcastrelay_flags=\$osudpbroadcastrelay_${i} + pidfile="/var/run/udpbroadcastrelay_$i.pid" + run_rc_command "start" + done + fi + return 0 +} + +case $1 in + start) + if [ -z "$osudpbroadcastrelay_flags=\$osudpbroadcastrelay_${i}" -o -z "$pidfile" ]; then + if [ -n "$osudpbroadcastrelay_instances" ]; then + for i in $osudpbroadcastrelay_instances; do + eval osudpbroadcastrelay_flags=\$osudpbroadcastrelay_${i} + pidfile="/var/run/udpbroadcastrelay_$i.pid" + udpbroadcastrelay_start + done + fi + else + udpbroadcastrelay_start + fi + exit $? + ;; + stop) + if [ -z "$osudpbroadcastrelay_flags" -o -z "$pidfile" ]; then + if [ -n "$osudpbroadcastrelay_instances" ]; then + for i in $osudpbroadcastrelay_instances; do + eval osudpbroadcastrelay_flags=\$osudpbroadcastrelay_${i} + pidfile="/var/run/udpbroadcastrelay_$i.pid" + udpbroadcastrelay_stop + done + fi + else + udpbroadcastrelay_stop + fi + exit $? + ;; + restart) + if [ -z "$osudpbroadcastrelay_flags" -o -z "$pidfile" ]; then + if [ -n "$osudpbroadcastrelay_instances" ]; then + for i in $osudpbroadcastrelay_instances; do + eval osudpbroadcastrelay_flags=\$osudpbroadcastrelay_${i} + pidfile="/var/run/udpbroadcastrelay_$i.pid" + udpbroadcastrelay_restart + done + fi + else + udpbroadcastrelay_restart + fi + exit $? + ;; + status) + if [ -z "$osudpbroadcastrelay_flags" -a -z "$pidfile" ]; then + if [ -n "$osudpbroadcastrelay_instances" ]; then + for i in $osudpbroadcastrelay_instances; do + eval osudpbroadcastrelay_flags=\$osudpbroadcastrelay_${i} + pidfile="/var/run/udpbroadcastrelay_$i.pid" + udpbroadcastrelay_status + done + fi + else + udpbroadcastrelay_status + fi + exit $? + ;; + reload) + udpbroadcastrelay_reload; + exit $? + ;; +esac diff --git a/net/udpbroadcastrelay/src/opnsense/mvc/app/controllers/OPNsense/UDPBroadcastRelay/Api/ServiceController.php b/net/udpbroadcastrelay/src/opnsense/mvc/app/controllers/OPNsense/UDPBroadcastRelay/Api/ServiceController.php new file mode 100644 index 000000000..d14f101f4 --- /dev/null +++ b/net/udpbroadcastrelay/src/opnsense/mvc/app/controllers/OPNsense/UDPBroadcastRelay/Api/ServiceController.php @@ -0,0 +1,174 @@ + "failed", "function" => "status"); + if ($this->request->isPost()) { + $this->sessionClose(); + } + if ($uuid != null) { + $mdlUDPBroadcastRelay = new UDPBroadcastRelay(); + $node = $mdlUDPBroadcastRelay->getNodeByReference('udpbroadcastrelay.' . $uuid); + if ($node != null) { + $result['result'] = $this->callBackend('status', $node); + } + } + return $result; + } + + /** + * start a udpbroadcastrelay process + * @param $uuid item unique id + * @return array + */ + public function startAction($uuid) + { + $result = array("result" => "failed", "function" => "start"); + if ($this->request->isPost()) { + $this->sessionClose(); + } + if ($uuid != null) { + $mdlUDPBroadcastRelay = new UDPBroadcastRelay(); + $node = $mdlUDPBroadcastRelay->getNodeByReference('udpbroadcastrelay.' . $uuid); + if ($node != null) { + $result['result'] = $this->callBackend('start', $node); + } + } + return $result; + } + + /** + * stop a udpbroadcastrelay process + * @param $uuid item unique id + * @return array + */ + public function stopAction($uuid) + { + $result = array("result" => "failed", "function" => "stop"); + if ($this->request->isPost()) { + $this->sessionClose(); + } + if ($uuid != null) { + $mdlUDPBroadcastRelay = new UDPBroadcastRelay(); + $node = $mdlUDPBroadcastRelay->getNodeByReference('udpbroadcastrelay.' . $uuid); + if ($node != null) { + $result['result'] = $this->callBackend('stop', $node); + } + } + return $result; + } + + /** + * restart a udpbroadcastrelay process + * @param $uuid item unique id + * @return array + */ + public function restartAction($uuid) + { + if ($this->request->isPost()) { + $this->sessionClose(); + } + if ($uuid != null) { + $mdlUDPBroadcastRelay = new UDPBroadcastRelay(); + $node = $mdlUDPBroadcastRelay->getNodeByReference('udpbroadcastrelay.' . $uuid); + if ($node != null) { + $result['result'] = $this->callBackend('restart', $node); + } + } + return $result; + } + + /** + * recreate configuration file from template + * @return array + */ + public function configAction() + { + $result = array("result" => "failed", "function" => "config"); + if ($this->request->isPost()) { + $this->sessionClose(); + } + $result['result'] = $this->callBackend('template'); + return $result; + } + + /** + * reload configuration + * @return array + */ + public function reloadAction() + { + if ($this->request->isPost()) { + $this->sessionClose(); + } + $result = $this->configAction(); + if ($result['result'] == 'OK') { + $result['function'] = "reload"; + $result['result'] = $this->callBackend('reload'); + } + return $result; + } + + /** + * call backend + * @param action, node + * @return string + */ + protected function callBackend($action, &$node = null) + { + $backend = new Backend(); + if ($node != null) { + $instance = preg_replace("/\./", "_", $node->InstanceID->__toString()); + return trim($backend->configdpRun('udpbroadcastrelay', array($action, $instance))); + } + if ($action == 'template') { + return trim($backend->configdRun('template reload OPNsense/UDPBroadcastRelay')); + } + if ($action == 'reload') { + return trim($backend->configdRun('udpbroadcastrelay reload')); + + } + return "Wrong action defined"; + } +} diff --git a/net/udpbroadcastrelay/src/opnsense/mvc/app/controllers/OPNsense/UDPBroadcastRelay/Api/SettingsController.php b/net/udpbroadcastrelay/src/opnsense/mvc/app/controllers/OPNsense/UDPBroadcastRelay/Api/SettingsController.php new file mode 100644 index 000000000..8f08921d3 --- /dev/null +++ b/net/udpbroadcastrelay/src/opnsense/mvc/app/controllers/OPNsense/UDPBroadcastRelay/Api/SettingsController.php @@ -0,0 +1,353 @@ +getNodeByReference('udpbroadcastrelay.' . $uuid); + if ($node != null) { + // return node + return array("udpbroadcastrelay" => $node->getNodes()); + } + } else { + // generate new node, but don't save to disc + $node = $mdlUDPBroadcastRelay->udpbroadcastrelay->Add(); + return array("udpbroadcastrelay" => $node->getNodes()); + } + return array(); + } + + /** + * update udpbroadcastrelay with given properties + * @param $uuid item unique id + * @return array + */ + public function setRelayAction($uuid) + { + $result = array("result" => "failed"); + if ($this->request->isPost() && $this->request->hasPost("udpbroadcastrelay")) { + $mdlUDPBroadcastRelay = new UDPBroadcastRelay(); + // keep a list to detect duplicates later + $CurrentProxies = $mdlUDPBroadcastRelay->getNodes(); + if ($uuid != null) { + $node = $mdlUDPBroadcastRelay->getNodeByReference('udpbroadcastrelay.' . $uuid); + if ($node != null) { + $Enabled = $node->enabled->__toString(); + $result = array("result" => "failed", "validations" => array()); + $relayInfo = $this->request->getPost("udpbroadcastrelay"); + + $node->setNodes($relayInfo); + $valMsgs = $mdlUDPBroadcastRelay->performValidation(); + foreach ($valMsgs as $field => $msg) { + $fieldnm = str_replace($node->__reference, "udpbroadcastrelay", $msg->getField()); + $result["validations"][$fieldnm] = $msg->getMessage(); + } + + if (count($result['validations']) == 0) { + // check for duplicates + + foreach ($CurrentProxies['udpbroadcastrelay'] as $CurrentUUID => &$CurrentRelay) { + if ( + $node->InstanceID->__toString() == $CurrentRelay['InstanceID'] && + $node->listenport->__toString() == $CurrentRelay['listenport'] && + $uuid != $CurrentUUID + ) { + return array( + "result" => "failed", + "validations" => array( + "udpbroadcastrelay.InstanceID" => "Instance ID already in use.", + "udpbroadcastrelay.listenport" => "Listen port already in use." + ) + ); + } + if ( + $node->listenport->__toString() == $CurrentRelay['listenport'] && + $uuid != $CurrentUUID + ) { + return array( + "result" => "failed", + "validations" => array( + "udpbroadcastrelay.listenport" => "Listen Port already in use." + ) + ); + } + if ( + $node->InstanceID->__toString() == $CurrentRelay['InstanceID'] && + $uuid != $CurrentUUID + ) { + return array( + "result" => "failed", + "validations" => array( + "udpbroadcastrelay.InstanceID" => "Instance ID already In use." + ) + ); + } + $result = count(explode(',',$node->interfaces)); + if ( + $result < 2 && + $uuid != $CurrentUUID + ) { + return array( + "result" => "failed", + "validations" => array( + "udpbroadcastrelay.interfaces" => "At least two interfaces must be selected." + ) + ); + } + } + + // save config if validated correctly + $mdlUDPBroadcastRelay->serializeToConfig(); + Config::getInstance()->save(); + // reload config + $svcUDPBroadcastRelay = new ServiceController(); + $result = $svcUDPBroadcastRelay->reloadAction(); + } + } + } + } + return $result; + } + + /** + * add new udpbroadcastrelay and set with attributes from post + * @return array + */ + public function addRelayAction() + { + $result = array("result" => "failed"); + if ($this->request->isPost() && $this->request->hasPost("udpbroadcastrelay")) { + $result = array("result" => "failed", "validations" => array()); + $mdlUDPBroadcastRelay = new UDPBroadcastRelay(); + // keep a list to detect duplicates later + $CurrentProxies = $mdlUDPBroadcastRelay->getNodes(); + $node = $mdlUDPBroadcastRelay->udpbroadcastrelay->Add(); + $node->setNodes($this->request->getPost("udpbroadcastrelay")); + + $valMsgs = $mdlUDPBroadcastRelay->performValidation(); + + foreach ($valMsgs as $field => $msg) { + $fieldnm = str_replace($node->__reference, "udpbroadcastrelay", $msg->getField()); + $result["validations"][$fieldnm] = $msg->getMessage(); + } + + if (count($result['validations']) == 0) { + foreach ($CurrentProxies['udpbroadcastrelay'] as &$CurrentRelay) { + if ( + $node->InstanceID->__toString() == $CurrentRelay['InstanceID'] && + $node->listenport->__toString() == $CurrentRelay['listenport'] + ) { + return array( + "result" => "failed", + "validations" => array( + "udpbroadcastrelay.InstanceID" => "Instance ID already in use.", + "udpbroadcastrelay.listenport" => "Listen port already in use." + ) + ); + } + if ( + $node->listenport->__toString() == $CurrentRelay['listenport'] + ) { + return array( + "result" => "failed", + "validations" => array( + "udpbroadcastrelay.listenport" => "Listen Port already in use." + ) + ); + } + if ( + $node->InstanceID->__toString() == $CurrentRelay['InstanceID'] + ) { + return array( + "result" => "failed", + "validations" => array( + "udpbroadcastrelay.InstanceID" => "Instance ID already In use." + ) + ); + } + + $result = count(explode(',',$node->interfaces)); + if ( + $result < 2 + ) { + return array( + "result" => "failed", + "validations" => array( + "udpbroadcastrelay.interfaces" => "At least two interfaces must be selected." + ) + ); + } + } + + // save config if validated correctly + $mdlUDPBroadcastRelay->serializeToConfig(); + Config::getInstance()->save(); + // reload config + $svcUDPBroadcastRelay = new ServiceController(); + $result = $svcUDPBroadcastRelay->reloadAction(); + } + } + return $result; + } + + /** + * delete udpbroadcastrelay by uuid + * @param $uuid item unique id + * @return array status + */ + public function delRelayAction($uuid) + { + + $result = array("result" => "failed"); + if ($this->request->isPost()) { + $mdlUDPBroadcastRelay = new UDPBroadcastRelay(); + if ($uuid != null) { + $node = $mdlUDPBroadcastRelay->getNodeByReference('udpbroadcastrelay.' . $uuid); + if ($node != null) { + if ($mdlUDPBroadcastRelay->udpbroadcastrelay->del($uuid) == true) { + // if item is removed, serialize to config and save + $mdlUDPBroadcastRelay->serializeToConfig(); + Config::getInstance()->save(); + // reload config + $svcUDPBroadcastRelay = new ServiceController(); + $result = $svcUDPBroadcastRelay->reloadAction(); + } + } else { + $result['result'] = 'not found'; + } + } + } + return $result; + } + + /** + * toggle udpbroadcastrelay by uuid (enable/disable) + * @param $uuid item unique id + * @return array status + */ + public function toggleRelayAction($uuid) + { + + $result = array("result" => "failed"); + if ($this->request->isPost()) { + $mdlUDPBroadcastRelay = new UDPBroadcastRelay(); + if ($uuid != null) { + $node = $mdlUDPBroadcastRelay->getNodeByReference('udpbroadcastrelay.' . $uuid); + if ($node != null) { + if ($node->enabled->__toString() == "1") { + $node->enabled = "0"; + } else { + $node->enabled = "1"; + } + // if item has toggled, serialize to config and save + $mdlUDPBroadcastRelay->serializeToConfig(); + Config::getInstance()->save(); + // reload config + $svcUDPBroadcastRelay = new ServiceController(); + $result = $svcUDPBroadcastRelay->reloadAction(); + } + } + } + return $result; + } + + /** + * + * search udpbroadcastrelay + * @return array + */ + public function searchRelayAction() + { + $this->sessionClose(); + $fields = array( + "enabled", + "interfaces", + "multicastaddress", + "sourceaddress", + "listenport", + "InstanceID", + "RevertTTL", + "description" + ); + $mdlUDPBroadcastRelay = new UDPBroadcastRelay(); + + $grid = new UIModelGrid($mdlUDPBroadcastRelay->udpbroadcastrelay); + $response = $grid->fetchBindRequest( + $this->request, + $fields, + "InstanceID" + ); + $svcUDPBroadcastRelay = new ServiceController(); + foreach ($response['rows'] as &$row) { + $result = $svcUDPBroadcastRelay->statusAction($row['uuid']); + if ($result['result'] == 'OK') { + $row['status'] = 0; + continue; + } + $node = $mdlUDPBroadcastRelay->getNodeByReference('udpbroadcastrelay.' . $row['uuid']); + if ($node != null) { + if ($node->enabled->__toString() == "1") { + $row['status'] = 2; + } else { + $row['status'] = 5; + } + } + } + + return $response; + } +} diff --git a/net/udpbroadcastrelay/src/opnsense/mvc/app/controllers/OPNsense/UDPBroadcastRelay/IndexController.php b/net/udpbroadcastrelay/src/opnsense/mvc/app/controllers/OPNsense/UDPBroadcastRelay/IndexController.php new file mode 100644 index 000000000..6301a81bc --- /dev/null +++ b/net/udpbroadcastrelay/src/opnsense/mvc/app/controllers/OPNsense/UDPBroadcastRelay/IndexController.php @@ -0,0 +1,47 @@ +view->formDialogEdit = $this->getForm("dialogEdit"); + $this->view->pick('OPNsense/UDPBroadcastRelay/index'); + } +} diff --git a/net/udpbroadcastrelay/src/opnsense/mvc/app/controllers/OPNsense/UDPBroadcastRelay/forms/dialogEdit.xml b/net/udpbroadcastrelay/src/opnsense/mvc/app/controllers/OPNsense/UDPBroadcastRelay/forms/dialogEdit.xml new file mode 100644 index 000000000..f39ae5111 --- /dev/null +++ b/net/udpbroadcastrelay/src/opnsense/mvc/app/controllers/OPNsense/UDPBroadcastRelay/forms/dialogEdit.xml @@ -0,0 +1,52 @@ +
+ + udpbroadcastrelay.enabled + + checkbox + + + + udpbroadcastrelay.listenport + + text + + + + udpbroadcastrelay.interfaces + + select_multiple + At least two interfaces must be selected. + + + udpbroadcastrelay.multicastaddress + + select_multiple + true + + + + + udpbroadcastrelay.sourceaddress + + text + + + + udpbroadcastrelay.InstanceID + + text + + + + udpbroadcastrelay.RevertTTL + + checkbox + + + + udpbroadcastrelay.description + + text + + +
diff --git a/net/udpbroadcastrelay/src/opnsense/mvc/app/models/OPNsense/UDPBroadcastRelay/ACL/ACL.xml b/net/udpbroadcastrelay/src/opnsense/mvc/app/models/OPNsense/UDPBroadcastRelay/ACL/ACL.xml new file mode 100644 index 000000000..051ea7fe9 --- /dev/null +++ b/net/udpbroadcastrelay/src/opnsense/mvc/app/models/OPNsense/UDPBroadcastRelay/ACL/ACL.xml @@ -0,0 +1,9 @@ + + + Services: UDP Broadcast Relay + + ui/udpbroadcastrelay/* + api/udpbroadcastrelay/* + + + diff --git a/net/udpbroadcastrelay/src/opnsense/mvc/app/models/OPNsense/UDPBroadcastRelay/Menu/Menu.xml b/net/udpbroadcastrelay/src/opnsense/mvc/app/models/OPNsense/UDPBroadcastRelay/Menu/Menu.xml new file mode 100644 index 000000000..1ae475838 --- /dev/null +++ b/net/udpbroadcastrelay/src/opnsense/mvc/app/models/OPNsense/UDPBroadcastRelay/Menu/Menu.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/net/udpbroadcastrelay/src/opnsense/mvc/app/models/OPNsense/UDPBroadcastRelay/UDPBroadcastRelay.php b/net/udpbroadcastrelay/src/opnsense/mvc/app/models/OPNsense/UDPBroadcastRelay/UDPBroadcastRelay.php new file mode 100644 index 000000000..b9b7640fc --- /dev/null +++ b/net/udpbroadcastrelay/src/opnsense/mvc/app/models/OPNsense/UDPBroadcastRelay/UDPBroadcastRelay.php @@ -0,0 +1,39 @@ + + //OPNsense/udpbroadcastrelays + 1.0.0 + UDP Broadcast Relay settings + + + + 1 + Y + + + lan + Y + Y + + + N + + Y + /^([\/0-9.,])*/u + Broadcast address must be a valid IPv4 address + + + N + + /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-4]|2[0-5][0-9]|[01]?[0-9][0-9]?)$/ + Source address must be a valid IPv4 address + + + + Y + 1 + 65535 + Listen port needs to be an integer value between 1 and 65535 + + + N + + /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-4]|2[0-5][0-9]|[01]?[0-9][0-9]?)$/ + Source address must be a valid IPv4 address + + + 0 + Y + 1 + 63 + InstanceID needs to be an integer value between 1 and 63 + + + 0 + Y + + + N + /^([\t\n\v\f\r 0-9a-zA-Z.,_\x{00A0}-\x{FFFF}]){1,255}$/u + Enter a description. + + + + diff --git a/net/udpbroadcastrelay/src/opnsense/mvc/app/views/OPNsense/UDPBroadcastRelay/index.volt b/net/udpbroadcastrelay/src/opnsense/mvc/app/views/OPNsense/UDPBroadcastRelay/index.volt new file mode 100644 index 000000000..1904a3145 --- /dev/null +++ b/net/udpbroadcastrelay/src/opnsense/mvc/app/views/OPNsense/UDPBroadcastRelay/index.volt @@ -0,0 +1,118 @@ +{# + +OPNsense® is Copyright © 2014 – 2017 by Deciso B.V. +Copyright (C) 2020 Martin Wasley + +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. + +#} + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
{{ lang._('Enabled') }}{{ lang._('Interfaces') }}{{ lang._('Multicast Addresses') }}{{ lang._('Source Address') }}{{ lang._('Listen Port') }}{{ lang._('ID') }}{{ lang._('Description') }}{{ lang._('ID') }}{{ lang._('Use ID as TTL') }}{{ lang._('Commands') }}
+ + +
+
+
+ +{# include dialog #} +{{ partial("layout_partials/base_dialog",['fields':formDialogEdit,'id':'DialogEdit','label':lang._('Edit Relay')])}} diff --git a/net/udpbroadcastrelay/src/opnsense/service/conf/actions.d/actions_udpbroadcastrelay.conf b/net/udpbroadcastrelay/src/opnsense/service/conf/actions.d/actions_udpbroadcastrelay.conf new file mode 100644 index 000000000..0ec66ac4a --- /dev/null +++ b/net/udpbroadcastrelay/src/opnsense/service/conf/actions.d/actions_udpbroadcastrelay.conf @@ -0,0 +1,29 @@ +[start] +command:/usr/local/etc/rc.d/os-udpbroadcastrelay start +parameters:%s +type:script +message:starting udpbroadcastrelay instance + +[stop] +command:/usr/local/etc/rc.d/os-udpbroadcastrelay stop +parameters:%s +type:script +message:stopping udpbroadcastrelay instance + +[status] +command:/usr/local/etc/rc.d/os-udpbroadcastrelay status +parameters:%s +type:script +message:get udpbroadcastrelay instance status + +[restart] +command:/usr/local/etc/rc.d/os-udpbroadcastrelay restart +parameters:%s +type:script +message:restarting udpbroadcastrelay instance + +[reload] +command:/usr/local/etc/rc.d/os-udpbroadcastrelay reload +parameters:%s +type:script +message:reload udpbroadcastrelay diff --git a/net/udpbroadcastrelay/src/opnsense/service/templates/OPNsense/UDPBroadcastRelay/+TARGETS b/net/udpbroadcastrelay/src/opnsense/service/templates/OPNsense/UDPBroadcastRelay/+TARGETS new file mode 100644 index 000000000..9377f1753 --- /dev/null +++ b/net/udpbroadcastrelay/src/opnsense/service/templates/OPNsense/UDPBroadcastRelay/+TARGETS @@ -0,0 +1 @@ +rc.conf.d:/etc/rc.conf.d/osudpbroadcastrelay diff --git a/net/udpbroadcastrelay/src/opnsense/service/templates/OPNsense/UDPBroadcastRelay/rc.conf.d b/net/udpbroadcastrelay/src/opnsense/service/templates/OPNsense/UDPBroadcastRelay/rc.conf.d new file mode 100644 index 000000000..918016c81 --- /dev/null +++ b/net/udpbroadcastrelay/src/opnsense/service/templates/OPNsense/UDPBroadcastRelay/rc.conf.d @@ -0,0 +1,37 @@ +{% if helpers.exists('OPNsense.udpbroadcastrelays.udpbroadcastrelay') %} +{% from 'OPNsense/Macros/interface.macro' import physical_interface %} +osudpbroadcastrelay_enable="YES" +{% set Instances=[] %} +{% for osudpbroadcastrelay in helpers.toList('OPNsense.udpbroadcastrelays.udpbroadcastrelay') %} +{% if osudpbroadcastrelay.enabled|default('0') == '1' %} +{% set Parameters=[] %} +{% if osudpbroadcastrelay.InstanceID %} +{% do Parameters.append("--id " ~ osudpbroadcastrelay.InstanceID) %} +{% endif %} +{% set osifnames = osudpbroadcastrelay.interfaces.split(',') %} +{% set interface_list=[] %} +{% for i in osifnames %} +{% do interface_list.append(physical_interface(i)) %} +{% do Parameters.append("--dev " ~ physical_interface(i)) %} +{% endfor %} +{% do Parameters.append("--port " ~ osudpbroadcastrelay.listenport) %} +{% if osudpbroadcastrelay.multicastaddress %} +{% set osmcastaddresses = osudpbroadcastrelay.multicastaddress.split(',') %} +{% for mcastaddress in osmcastaddresses %} +{% do Parameters.append("--multicast " ~ mcastaddress) %} +{% endfor %} +{% endif %} +{% if osudpbroadcastrelay.sourceaddress %} +{% do Parameters.append("-s " ~ osudpbroadcastrelay.sourceaddress) %} +{% endif %} +{% if osudpbroadcastrelay.RevertTTL|default('0') == '1' %} +{% do Parameters.append("-t ") %} +{% endif %} +{% do Parameters.append("-f") %} +{% set Instance=osudpbroadcastrelay.InstanceID %} +osudpbroadcastrelay_{{Instance}}="{% for Parameter in Parameters %} {{Parameter}}{% endfor %}" +{% do Instances.append(Instance) %} +{% endif %} +{% endfor %} +osudpbroadcastrelay_instances="{% for Instance in Instances %} {{Instance}}{% endfor %}" +{% endif %}