Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/mdns-repeater: Modernize plugin code; Add blocklist support (contributed by Kodehyrden) #4375

Merged
merged 7 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions net/mdns-repeater/Makefile
Original file line number Diff line number Diff line change
@@ -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= [email protected]
PLUGIN_DEPENDS= mdns-repeater
Expand Down
5 changes: 5 additions & 0 deletions net/mdns-repeater/pkg-descr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
102 changes: 52 additions & 50 deletions net/mdns-repeater/src/etc/inc/plugins.inc.d/mdnsrepeater.inc
Original file line number Diff line number Diff line change
@@ -1,63 +1,65 @@
<?php

/*
Copyright (C) 2017 Fabian Franz
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_enabled()
{
$model = new \OPNsense\MDNSRepeater\MDNSRepeater();
return (string)$model->enabled == '1';
}
* 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_firewall($fw)
function mdnsrepeater_services()
{
if (!mdnsrepeater_enabled()) {
return;
global $config;

$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',
];
}

return $services;
}

function mdnsrepeater_services()
function mdnsrepeater_xmlrpc_sync()
{
$services = array();
$result = [];

// don't load the service if it is not enabled
// maybe there are no settings yet
if (!mdnsrepeater_enabled()) {
return $services;
}

$services[] = array(
$result[] = [
'description' => gettext('mDNS Repeater'),
'configd' => array(
'restart' => array('mdnsrepeater restart'),
'start' => array('mdnsrepeater start'),
'stop' => array('mdnsrepeater stop'),
),
'name' => 'mdns-repeater',
);
'section' => 'OPNsense.MDNSRepeater',
'id' => 'mdns-repeater',
'services' => ['mdns-repeater'],
];

return $services;
return $result;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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';
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
<form>
<field>
<id>mdnsrepeater.enabled</id>
<label>Enable</label>
<type>checkbox</type>
<help>Enable the repeater.</help>
</field>
<field>
<id>mdnsrepeater.enablecarp</id>
<label>Enable CARP Failover</label>
<type>checkbox</type>
<help>This will activate the repeater service only on the master device.</help>
</field>
<field>
<id>mdnsrepeater.interfaces</id>
<label>Listen Interfaces</label>
<type>select_multiple</type>
<help>At least 2 interfaces must be selected. The maximum number of supported interfaces by the daemon is 5.</help>
</field>
<field>
<type>header</type>
<label>General Settings</label>
</field>
<field>
<id>mdnsrepeater.enabled</id>
<label>Enable</label>
<type>checkbox</type>
<help>Enable the repeater.</help>
</field>
<field>
<id>mdnsrepeater.enablecarp</id>
<label>Enable CARP Failover</label>
<type>checkbox</type>
<help>This will activate the repeater service only on the master device.</help>
</field>
<field>
<id>mdnsrepeater.interfaces</id>
<label>Listen Interfaces</label>
<type>select_multiple</type>
<help>At least 2 interfaces must be selected. The maximum number of supported interfaces by the daemon is 5.</help>
</field>
<field>
<id>mdnsrepeater.blocklist</id>
<label>Blocklist</label>
<type>select_multiple</type>
<style>tokenize</style>
<allownew>true</allownew>
<help>Enter up to 16 client IPv4 addresses including subnet or networks to be exluded.</help>
</field>
</form>
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
<model>
<mount>//OPNsense/MDNSRepeater</mount>
<version>1.0.1</version>
<description>mdns-repeater settings</description>
<items>
<enabled type="BooleanField">
<Default>0</Default>
<Required>Y</Required>
</enabled>
<enablecarp type="BooleanField">
<Default>0</Default>
<Required>Y</Required>
</enablecarp>
<interfaces type="InterfaceField">
<Default>lan</Default>
<Required>Y</Required>
<Multiple>Y</Multiple>
</interfaces>
</items>
<mount>//OPNsense/MDNSRepeater</mount>
<version>1.0.1</version>
<description>mdns-repeater settings</description>
<items>
<enabled type="BooleanField">
<Default>0</Default>
<Required>Y</Required>
</enabled>
<enablecarp type="BooleanField">
<Default>0</Default>
<Required>Y</Required>
</enablecarp>
<interfaces type="InterfaceField">
<Default>lan</Default>
<Required>Y</Required>
<Multiple>Y</Multiple>
</interfaces>
<blocklist type="NetworkField">
<NetMaskRequired>Y</NetMaskRequired>
<AddressFamily>ipv4</AddressFamily>
<FieldSeparator>,</FieldSeparator>
<WildcardEnabled>N</WildcardEnabled>
<AsList>Y</AsList>
<ValidationMessage>Only valid IPv4 networks or individual addresses including subnet are allowed.</ValidationMessage>
</blocklist>
</items>
</model>
Loading