Skip to content

Commit

Permalink
add MDNS Repeater (#241)
Browse files Browse the repository at this point in the history
* add MDNS Repeater
* cleanup: remove cdata block
* Update comment
* rename template and use join
* use the package name also in the config
* remove extended description
* update targets, makefile
  • Loading branch information
fabianfrz authored Sep 2, 2017
1 parent adfbd2a commit 275803f
Show file tree
Hide file tree
Showing 15 changed files with 415 additions and 0 deletions.
8 changes: 8 additions & 0 deletions net/mdns-repeater/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
PLUGIN_NAME= mdns-repeater
PLUGIN_VERSION= 1.0
PLUGIN_COMMENT= Proxy multicast DNS between networks
PLUGIN_MAINTAINER= franz.fabian.94@gmail.com
PLUGIN_DEPENDS= mdns-repeater
PLUGIN_DEVEL= yes

.include "../../Mk/plugins.mk"
Empty file added net/mdns-repeater/pkg-descr
Empty file.
68 changes: 68 additions & 0 deletions net/mdns-repeater/src/etc/inc/plugins.inc.d/mdnsrepeater.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?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()
{
$mdns_repeater = new \OPNsense\MDNSRepeater\MDNSRepeater();
{
if ((string)$mdns_repeater->enabled == '1') {
return true;
}

return false;
}

function mdnsrepeater_firewall($fw)
{
if (!mdnsrepeater_enabled()) {
return;
}
}

function mdnsrepeater_services()
{
$services = array();

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

$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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?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.
*/

namespace OPNsense\MDNSRepeater\Api;

use \OPNsense\Base\ApiControllerBase;
use \OPNsense\Core\Backend;
use \OPNsense\MDNSRepeater\MDNSRepeater;

class ServiceController extends ApiControllerBase
{
public function statusAction()
{
$backend = new Backend();
$result = array('result' => 'failed');
$mdlMDNSRepeater = new MDNSRepeater();
$result['result'] = $backend->configdRun('mdnsrepeater status');
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");
$mdlMDNSRepeater = new MDNSRepeater();
$result['result'] = $backend->configdRun('mdnsrepeater stop');
return $result;
}

public function restartAction()
{
$this->stopAction();
return $this->startAction();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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.
*
*/

namespace OPNsense\MDNSRepeater\Api;

use \OPNsense\Base\ApiMutableModelControllerBase;

class SettingsController extends ApiMutableModelControllerBase
{
static protected $internalModelClass = '\OPNsense\MDNSRepeater\MDNSRepeater';
static protected $internalModelName = 'mdnsrepeater';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?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.
*
*/

namespace OPNsense\MDNSRepeater;

/**
* Class IndexController
* @package OPNsense\MDNSRepeater
*/
class IndexController extends \OPNsense\Base\IndexController
{
/**
* MDNS Repeater index page
* @throws \Exception
*/
public function indexAction()
{
$this->view->title = gettext('MDNS Repeater');
$this->view->general = $this->getForm("general");
$this->view->pick('OPNsense/MDNSRepeater/index');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<form>
<field>
<id>mdnsrepeater.enabled</id>
<label>enabled</label>
<type>checkbox</type>
<help>Enable the repeater.</help>
</field>
<field>
<id>mdnsrepeater.interfaces</id>
<label>Listen Interfaces</label>
<type>select_multiple</type>
<multiple>Y</multiple>
</field>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<acl>
<page-services-mdnsrepeater>
<name>Services: MDNS Repeatery</name>
<patterns>
<pattern>ui/mdnsrepeater/*</pattern>
<pattern>api/mdnsrepeater/*</pattern>
</patterns>
</page-services-mdnsrepeater>
</acl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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.
*
*/

namespace OPNsense\MDNSRepeater;

use OPNsense\Base\BaseModel;

class MDNSRepeater extends BaseModel
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<model>
<mount>//OPNsense/MDNSRepeater</mount>
<version>1.0.0</version>
<description>mdns-repeater settings</description>
<items>
<enabled type="BooleanField">
<default>0</default>
<Required>Y</Required>
</enabled>
<interfaces type="InterfaceField">
<Required>Y</Required>
<multiple>Y</multiple>
</interfaces>
</items>
</model>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<menu>
<Services>
<MDNSRepeater VisibleName="MDNS Repeater" cssClass="fa fa-bolt fa-fw" url="/ui/mdnsrepeater/"/>
</Services>
</menu>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{#

Copyright © 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 PROVIDEDAS ISAND 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.

#}

<script type="text/javascript">

$( document ).ready(function() {
var data_get_map = {'general': '/api/mdnsrepeater/settings/get'};
mapDataToFormUI(data_get_map).done(function(data){
formatTokenizersUI();
$('.selectpicker').selectpicker('refresh');
});
ajaxCall(url="/api/mdnsrepeater/service/status", sendData={}, callback=function(data,status) {
updateServiceStatusUI(data['status']);
});

// link save button to API set action
$("#saveAct").click(function(){
saveFormToEndpoint(url="/api/mdnsrepeater/settings/set", formid='general',callback_ok=function(){
ajaxCall(url="/api/mdnsrepeater/service/restart", sendData={}, callback=function(data,status) {
ajaxCall(url="/api/mdnsrepeater/service/status", sendData={}, callback=function(data,status) {
updateServiceStatusUI(data['status']);
});
});
});
});
});

</script>

<div class="content-box" style="padding-bottom: 1.5em;">
{{ partial("layout_partials/base_form",['fields': general,'id':'general'])}}
<hr />
<div class="col-md-12">
<button class="btn btn-primary" id="saveAct" type="button"><b>{{ lang._('Save') }}</b></button>
</div>
</div>
Loading

0 comments on commit 275803f

Please sign in to comment.