diff --git a/net/mdns-repeater/Makefile b/net/mdns-repeater/Makefile index 8fc5683f4..35f45dfb8 100644 --- a/net/mdns-repeater/Makefile +++ b/net/mdns-repeater/Makefile @@ -1,6 +1,5 @@ PLUGIN_NAME= mdns-repeater -PLUGIN_VERSION= 1.1 -PLUGIN_REVISION= 1 +PLUGIN_VERSION= 1.2 PLUGIN_COMMENT= Proxy multicast DNS between networks PLUGIN_MAINTAINER= franz.fabian.94@gmail.com PLUGIN_DEPENDS= mdns-repeater diff --git a/net/mdns-repeater/pkg-descr b/net/mdns-repeater/pkg-descr index a5ed7facd..c67d64e00 100644 --- a/net/mdns-repeater/pkg-descr +++ b/net/mdns-repeater/pkg-descr @@ -7,6 +7,11 @@ It can be used to bridge zeroconf devices to work properly across the two subnet Plugin Changelog ================ +1.2 + +* modernize plugin code +* blocklist support (contributed by Kodehyrden) + 1.1 * CARP support (contributed by Markus Reiter) diff --git a/net/mdns-repeater/src/etc/inc/plugins.inc.d/mdnsrepeater.inc b/net/mdns-repeater/src/etc/inc/plugins.inc.d/mdnsrepeater.inc index 6990e232f..9d51f61d9 100644 --- a/net/mdns-repeater/src/etc/inc/plugins.inc.d/mdnsrepeater.inc +++ b/net/mdns-repeater/src/etc/inc/plugins.inc.d/mdnsrepeater.inc @@ -1,63 +1,65 @@ enabled == '1'; -} - -function mdnsrepeater_firewall($fw) -{ - if (!mdnsrepeater_enabled()) { - return; - } -} + * Copyright (c) 2017 Fabian Franz + * Copyright (c) 2024 Cedrik Pischem + * 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 mdnsrepeater_services() { - $services = array(); + global $config; - // don't load the service if it is not enabled - // maybe there are no settings yet - if (!mdnsrepeater_enabled()) { - return $services; + $services = []; + + if (isset($config['OPNsense']['MDNSRepeater']['enabled']) && + $config['OPNsense']['MDNSRepeater']['enabled'] == '1') { + $services[] = [ + 'description' => gettext('mDNS Repeater'), + 'configd' => [ + 'start' => ['mdnsrepeater start'], + 'restart' => ['mdnsrepeater restart'], + 'stop' => ['mdnsrepeater stop'], + ], + 'name' => 'mdns-repeater', + 'pidfile' => '/var/run/mdns-repeater.pid', + ]; } - $services[] = array( - 'description' => gettext('mDNS Repeater'), - 'configd' => array( - 'restart' => array('mdnsrepeater restart'), - 'start' => array('mdnsrepeater start'), - 'stop' => array('mdnsrepeater stop'), - ), - 'name' => 'mdns-repeater', - ); - return $services; } + +function mdnsrepeater_xmlrpc_sync() +{ + $result = []; + + $result[] = [ + 'description' => gettext('mDNS Repeater'), + 'section' => 'OPNsense.MDNSRepeater', + 'id' => 'mdns-repeater', + 'services' => ['mdns-repeater'], + ]; + + return $result; +} diff --git a/net/mdns-repeater/src/opnsense/mvc/app/controllers/OPNsense/MDNSRepeater/Api/ServiceController.php b/net/mdns-repeater/src/opnsense/mvc/app/controllers/OPNsense/MDNSRepeater/Api/ServiceController.php index 1d5637292..f109dd8a3 100644 --- a/net/mdns-repeater/src/opnsense/mvc/app/controllers/OPNsense/MDNSRepeater/Api/ServiceController.php +++ b/net/mdns-repeater/src/opnsense/mvc/app/controllers/OPNsense/MDNSRepeater/Api/ServiceController.php @@ -2,6 +2,7 @@ /** * Copyright (C) 2017 Fabian Franz + * Copyright (C) 2024 Cedrik Pischem * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -28,52 +29,12 @@ namespace OPNsense\MDNSRepeater\Api; -use OPNsense\Base\ApiControllerBase; -use OPNsense\Core\Backend; -use OPNsense\MDNSRepeater\MDNSRepeater; +use OPNsense\Base\ApiMutableServiceControllerBase; -class ServiceController extends ApiControllerBase +class ServiceController extends ApiMutableServiceControllerBase { - public function statusAction() - { - $backend = new Backend(); - $result = array('result' => 'failed'); - $res = $backend->configdRun('mdnsrepeater status'); - if (stripos($res, 'is running')) { - $result['result'] = 'running'; - } elseif (stripos($res, 'not running')) { - $general = new MDNSRepeater(); - if ((string)$general->enabled == '1') { - $result['result'] = 'stopped'; - } else { - $result['result'] = 'disabled'; - } - } else { - $result['message'] = $res; - } - return $result; - } - - public function startAction() - { - $backend = new Backend(); - $result = array('result' => 'failed'); - $backend->configdRun('template reload OPNsense/MDNSRepeater'); - $result['result'] = $backend->configdRun('mdnsrepeater start'); - return $result; - } - - public function stopAction() - { - $backend = new Backend(); - $result = array("result" => "failed"); - $result['result'] = $backend->configdRun('mdnsrepeater stop'); - return $result; - } - - public function restartAction() - { - $this->stopAction(); - return $this->startAction(); - } + protected static $internalServiceClass = '\OPNsense\MDNSRepeater\MDNSRepeater'; + protected static $internalServiceTemplate = 'OPNsense/MDNSRepeater'; + protected static $internalServiceEnabled = 'enabled'; + protected static $internalServiceName = 'mdnsrepeater'; } diff --git a/net/mdns-repeater/src/opnsense/mvc/app/controllers/OPNsense/MDNSRepeater/forms/general.xml b/net/mdns-repeater/src/opnsense/mvc/app/controllers/OPNsense/MDNSRepeater/forms/general.xml index 7a565757f..4f6ba145b 100644 --- a/net/mdns-repeater/src/opnsense/mvc/app/controllers/OPNsense/MDNSRepeater/forms/general.xml +++ b/net/mdns-repeater/src/opnsense/mvc/app/controllers/OPNsense/MDNSRepeater/forms/general.xml @@ -1,20 +1,32 @@
diff --git a/net/mdns-repeater/src/opnsense/mvc/app/models/OPNsense/MDNSRepeater/MDNSRepeater.xml b/net/mdns-repeater/src/opnsense/mvc/app/models/OPNsense/MDNSRepeater/MDNSRepeater.xml index 85015e3d6..e5e868d55 100644 --- a/net/mdns-repeater/src/opnsense/mvc/app/models/OPNsense/MDNSRepeater/MDNSRepeater.xml +++ b/net/mdns-repeater/src/opnsense/mvc/app/models/OPNsense/MDNSRepeater/MDNSRepeater.xml @@ -1,20 +1,28 @@