net/ntopng: new plugin (#801)

(cherry picked from commit aaf93801a4)
(cherry picked from commit 5626cc1e8f)
This commit is contained in:
Michael 2018-09-07 14:45:49 +02:00 committed by Franco Fichtner
parent b32cb8bfb6
commit a4dbfc26b4
18 changed files with 442 additions and 0 deletions

View file

@ -56,6 +56,7 @@ net/haproxy -- Reliable, high performance TCP/HTTP load balancer
net/igmp-proxy -- IGMP-Proxy Service
net/l2tp -- L2TP server based on MPD5
net/mdns-repeater -- Proxy multicast DNS between networks
net/ntopng -- Traffic Analysis and Flow Collection
net/pppoe -- PPPoE server based on MPD5
net/pptp -- PPTP server based on MPD5
net/quagga -- End of life, superseded by FRR plugin

8
net/ntopng/Makefile Normal file
View file

@ -0,0 +1,8 @@
PLUGIN_NAME= ntopng
PLUGIN_VERSION= 0.1
PLUGIN_COMMENT= Traffic Analysis and Flow Collection
PLUGIN_DEPENDS= ntopng redis
PLUGIN_MAINTAINER= m.muenz@gmail.com
PLUGIN_DEVEL= yes
.include "../../Mk/plugins.mk"

7
net/ntopng/pkg-descr Normal file
View file

@ -0,0 +1,7 @@
ntopng is the next generation version of the original ntop,
a network traffic probe that monitors network usage. ntopng
is based on libpcap and it has been written in a portable
way in order to virtually run on every Unix platform, MacOSX
and on Windows as well.
WWW: https://www.ntop.org/products/traffic-analysis/ntop/

View file

@ -0,0 +1,55 @@
<?php
/*
Copyright (C) 2018 Michael Muenz
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 ntopng_enabled()
{
$model = new \OPNsense\Ntopng\General();
return (string)$model->enabled == '1';
}
function ntopng_services()
{
$services = array();
if (!ntopng_enabled()) {
return $services;
}
$services[] = array(
'description' => gettext('ntopng'),
'configd' => array(
'restart' => array('ntopng restart'),
'start' => array('ntopng start'),
'stop' => array('ntopng stop'),
),
'name' => 'ntopng',
'pid' => '/var/run/ntopng/ntopng.pid'
);
return $services;
}

View file

@ -0,0 +1,39 @@
<?php
/**
* Copyright (C) 2018 Michael Muenz
*
* 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\Ntopng\Api;
use OPNsense\Base\ApiMutableModelControllerBase;
class GeneralController extends ApiMutableModelControllerBase
{
static protected $internalModelClass = '\OPNsense\Ntopng\General';
static protected $internalModelName = 'general';
}

View file

@ -0,0 +1,58 @@
<?php
/**
* Copyright (C) 2018 Michael Muenz
*
* 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\Ntopng\Api;
use OPNsense\Base\ApiMutableServiceControllerBase;
use OPNsense\Core\Backend;
use OPNsense\Ntopng\General;
/**
* Class ServiceController
* @package OPNsense\Ntopng
*/
class ServiceController extends ApiMutableServiceControllerBase
{
static protected $internalServiceClass = '\OPNsense\Ntopng\General';
static protected $internalServiceTemplate = 'OPNsense/Ntopng';
static protected $internalServiceEnabled = 'enabled';
static protected $internalServiceName = 'ntopng';
/**
* check if Redis plugin is installed
* @return array
*/
public function checkredisAction()
{
$backend = new Backend();
$response = $backend->configdRun("firmware plugin redis");
return $response;
}
}

View file

@ -0,0 +1,38 @@
<?php
/*
Copyright (C) 2018 Michael Muenz
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\Ntopng;
class GeneralController extends \OPNsense\Base\IndexController
{
public function indexAction()
{
$this->view->generalForm = $this->getForm("general");
$this->view->pick('OPNsense/Ntopng/general');
}
}

View file

@ -0,0 +1,26 @@
<form>
<field>
<id>general.enabled</id>
<label>Enable ntopng</label>
<type>checkbox</type>
<help>This will activate ntopng.</help>
</field>
<field>
<id>general.interface</id>
<label>Interfaces</label>
<type>dropdown</type>
<help>Select the interface to listen to.</help>
</field>
<field>
<id>general.httpport</id>
<label>HTTP Port</label>
<type>text</type>
<help>HTTP Port this service listens on.</help>
</field>
<field>
<id>general.dnsmode</id>
<label>DNS Mode</label>
<type>dropdown</type>
<help>Sets the DNS resolution mode.</help>
</field>
</form>

View file

@ -0,0 +1,9 @@
<acl>
<page-ntopng-config>
<name>Services: ntopng</name>
<patterns>
<pattern>ui/ntopng/*</pattern>
<pattern>api/ntopng/*</pattern>
</patterns>
</page-ntopng-config>
</acl>

View file

@ -0,0 +1,35 @@
<?php
/*
Copyright (C) 2018 Michael Muenz
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\Ntopng;
use OPNsense\Base\BaseModel;
class General extends BaseModel
{
}

View file

@ -0,0 +1,28 @@
<model>
<mount>//OPNsense/ntopng/general</mount>
<description>ntopng configuration</description>
<version>0.0.1</version>
<items>
<enabled type="BooleanField">
<default>0</default>
<Required>Y</Required>
</enabled>
<interface type="InterfaceField">
<Required>N</Required>
<Multiple>N</Multiple>
</interface>
<httpport type="PortField">
<Required>Y</Required>
<default>3000</default>
</httpport>
<dnsmode type="OptionField">
<Required>N</Required>
<OptionValues>
<Option0 value="0">Decode DNS responses and resolve only local numeric IPs</Option0>
<Option1 value="1">Decode DNS responses and resolve all numeric IPs</Option1>
<Option2 value="2">Decode DNS responses and do not resolve numeric IPs</Option2>
<Option3 value="3">Do not decode DNS responses and do not resolve numeric IPs</Option3>
</OptionValues>
</dnsmode>
</items>
</model>

View file

@ -0,0 +1,5 @@
<menu>
<Services>
<Ntopng cssClass="fa fa-binoculars fa-fw" url="/ui/ntopng/general/index" />
</Services>
</menu>

View file

@ -0,0 +1,80 @@
{#
OPNsense® is Copyright © 2014 2018 by Deciso B.V.
This file is Copyright © 2018 by Michael Muenz
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.
#}
<div class="alert alert-warning" role="alert" id="missing_redis" style="display:none;min-height:65px;">
<div style="margin-top: 8px;">{{ lang._('No Redis plugin found, please install via System > Firmware > Plugins and enable the service.')}}</div>
</div>
<!-- Navigation bar -->
<ul class="nav nav-tabs" data-tabs="tabs" id="maintabs">
<li class="active"><a data-toggle="tab" href="#general">{{ lang._('General') }}</a></li>
</ul>
<div class="tab-content content-box tab-content">
<div id="general" class="tab-pane fade in active">
<div class="content-box" style="padding-bottom: 1.5em;">
{{ partial("layout_partials/base_form",['fields':generalForm,'id':'frm_general_settings'])}}
<div class="col-md-12">
<hr />
<button class="btn btn-primary" id="saveAct" type="button"><b>{{ lang._('Save') }}</b><i id="saveAct_progress"></i></button>
</div>
</div>
</div>
</div>
<script>
$( document ).ready(function() {
var data_get_map = {'frm_general_settings':"/api/ntopng/general/get"};
mapDataToFormUI(data_get_map).done(function(data){
formatTokenizersUI();
$('.selectpicker').selectpicker('refresh');
});
ajaxCall(url="/api/ntopng/service/status", sendData={}, callback=function(data,status) {
updateServiceStatusUI(data['status']);
});
// check if Redis plugin is installed
ajaxCall(url="/api/ntopng/service/checkredis", sendData={}, callback=function(data,status) {
if (data == "0") {
$('#missing_redis').show();
}
});
$("#saveAct").click(function(){
saveFormToEndpoint(url="/api/ntopng/general/set", formid='frm_general_settings',callback_ok=function(){
$("#saveAct_progress").addClass("fa fa-spinner fa-pulse");
ajaxCall(url="/api/ntopng/service/reconfigure", sendData={}, callback=function(data,status) {
$("#saveAct_progress").removeClass("fa fa-spinner fa-pulse");
});
});
});
});
</script>

View file

@ -0,0 +1,9 @@
#!/bin/sh
mkdir -p /var/run/ntopng/
chmod 755 /var/run/ntopng
chown ntopng:ntopng /var/run/ntopng
mkdir -p /var/tmp/ntopng/
chmod 755 /var/tmp/ntopng
chown ntopng:wheel /var/tmp/ntopng

View file

@ -0,0 +1,23 @@
[start]
command:/usr/local/opnsense/scripts/OPNsense/Ntopng/setup.sh;/usr/local/etc/rc.d/ntopng start
parameters:
type:script
message:starting ntopng
[stop]
command:/usr/local/etc/rc.d/ntopng stop
parameters:
type:script
message:stopping ntopng
[restart]
command:/usr/local/opnsense/scripts/OPNsense/Ntopng/setup.sh;/usr/local/etc/rc.d/ntopng restart
parameters:
type:script
message:restarting ntopng
[status]
command:sh /usr/local/etc/rc.d/ntopng status;exit 0
parameters:
type:script_output
message:ntopng status

View file

@ -0,0 +1,2 @@
ntopng:/etc/rc.conf.d/ntopng
ntopng.conf:/usr/local/etc/ntopng.conf

View file

@ -0,0 +1,7 @@
{% if helpers.exists('OPNsense.ntopng.general.enabled') and OPNsense.ntopng.general.enabled == '1' %}
ntopng_var_script="/usr/local/opnsense/scripts/OPNsense/Ntopng/setup.sh"
ntopng_enable="YES"
ntopng_flags="/usr/local/etc/ntopng.conf"
{% else %}
ntopng_enable="NO"
{% endif %}

View file

@ -0,0 +1,12 @@
{% if helpers.exists('OPNsense.ntopng.general.enabled') and OPNsense.ntopng.general.enabled == '1' %}
{% from 'OPNsense/Macros/interface.macro' import physical_interface %}
{% if helpers.exists('OPNsense.ntopng.general.interface') and OPNsense.ntopng.general.interface != '' %}
-i={{ physical_interface(OPNsense.ntopng.general.interface) }}
{% endif %}
{% if helpers.exists('OPNsense.ntopng.general.httpport') and OPNsense.ntopng.general.httpport != '' %}
-w={{ OPNsense.ntopng.general.httpport }}
{% endif %}
{% if helpers.exists('OPNsense.ntopng.general.dnsmode') and OPNsense.ntopng.general.dnsmode != '' %}
-n={{ OPNsense.ntopng.general.dnsmode }}
{% endif %}
{% endif %}