Skip to content

Commit 9f6b46b

Browse files
committed
Add OPNarplog
1 parent 5c4e3a2 commit 9f6b46b

File tree

19 files changed

+972
-0
lines changed

19 files changed

+972
-0
lines changed

net-mgmt/opnarplog/Makefile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
PLUGIN_NAME= OPNarplog
2+
PLUGIN_VERSION= 0.1
3+
PLUGIN_REVISION= 1
4+
PLUGIN_COMMENT= arpwatch alternative for OPNsense
5+
PLUGIN_MAINTAINER= github.com/mr-manuel
6+
7+
.include "../../Mk/plugins.mk"

net-mgmt/opnarplog/pkg-descr

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
OPNarplog is a versatile network monitoring tool that tracks and logs changes in ARP (Address Resolution Protocol) and NDP (Neighbor Discovery Protocol) tables, capturing key details such as IPv4 and IPv6 addresses, hostnames, MAC addresses, and interface changes. The plugin is configurable, allowing administrators to selectively enable or disable tracking for different modifications based on specific needs, whether it’s for IP address shifts, hostname updates, new MAC detections, or interface changes. This customization and comprehensive logging ensure precise, up-to-date network visibility, ideal for securing networks and managing dynamic device inventories effectively.
2+
3+
WWW: https://github.com/mr-manuel/opnsense_plugins
4+
5+
6+
Plugin Changelog
7+
================
8+
9+
0.1
10+
11+
* Initial release

net-mgmt/opnarplog/src/bin/opnarplog.py

+424
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/*
4+
* Copyright (C) 2024 github.com/mr-manuel
5+
* All rights reserved.
6+
*
7+
*/
8+
9+
function opnarplog_services()
10+
{
11+
global $config;
12+
13+
$services = array();
14+
15+
if (isset($config['OPNsense']['opnarplog']['general']['enabled']) && $config['OPNsense']['opnarplog']['general']['enabled'] == 1) {
16+
$services[] = array(
17+
'description' => gettext('OPNarplog Daemon'),
18+
'configd' => array(
19+
'restart' => array('opnarplog restart'),
20+
'start' => array('opnarplog start'),
21+
'stop' => array('opnarplog stop'),
22+
),
23+
'name' => 'opnarplog',
24+
'pidfile' => '/var/run/opnarplog.pid',
25+
);
26+
}
27+
28+
return $services;
29+
}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/sh
2+
#
3+
# $FreeBSD$
4+
#
5+
# PROVIDE: opnarplog
6+
# REQUIRE: SERVERS
7+
# KEYWORD: shutdown
8+
#
9+
10+
. /etc/rc.subr
11+
12+
name=opnarplog
13+
14+
rcvar=opnarplog_enable
15+
pidfile=/var/run/${name}.pid
16+
command=/usr/sbin/daemon
17+
command_args="-f -P ${pidfile} /usr/local/bin/python3 /usr/local/bin/opnarplog.py"
18+
19+
load_rc_config ${name}
20+
21+
: ${opnarplog_enable="NO"}
22+
23+
run_rc_command $1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/*
4+
* Copyright (C) 2024 github.com/mr-manuel
5+
* All rights reserved.
6+
*/
7+
8+
namespace OPNsense\Opnarplog\Api;
9+
10+
use OPNsense\Base\ApiMutableModelControllerBase;
11+
12+
class GeneralController extends ApiMutableModelControllerBase
13+
{
14+
protected static $internalModelClass = '\OPNsense\Opnarplog\General';
15+
protected static $internalModelName = 'general';
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* Copyright (C) 2024 github.com/mr-manuel
5+
* All rights reserved.
6+
*/
7+
8+
namespace OPNsense\Opnarplog\Api;
9+
10+
use OPNsense\Base\ApiMutableServiceControllerBase;
11+
use OPNsense\Core\Backend;
12+
use OPNsense\Opnarplog\General;
13+
14+
class ServiceController extends ApiMutableServiceControllerBase
15+
{
16+
protected static $internalServiceClass = '\OPNsense\Opnarplog\General';
17+
protected static $internalServiceTemplate = 'OPNsense/Opnarplog';
18+
protected static $internalServiceEnabled = 'enabled';
19+
protected static $internalServiceName = 'opnarplog';
20+
21+
/**
22+
* remove database folder
23+
* @return array
24+
*/
25+
public function resetdbAction()
26+
{
27+
$backend = new Backend();
28+
$response = $backend->configdRun("opnarplog resetdb");
29+
return array("response" => $response);
30+
}
31+
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/*
4+
* Copyright (C) 2024 github.com/mr-manuel
5+
* All rights reserved.
6+
*/
7+
8+
namespace OPNsense\Opnarplog;
9+
10+
class GeneralController extends \OPNsense\Base\IndexController
11+
{
12+
public function indexAction()
13+
{
14+
$this->view->generalForm = $this->getForm('general');
15+
$this->view->pick('OPNsense/Opnarplog/general');
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<form>
2+
<field>
3+
<id>general.enabled</id>
4+
<label>Enable</label>
5+
<type>checkbox</type>
6+
<help>Enable or disable OPNarplog. This will not automatically enable any mail notifications, see notes below</help>
7+
</field>
8+
<field>
9+
<id>general.protocols</id>
10+
<label>Protocols</label>
11+
<type>dropdown</type>
12+
<help>Select the protocols you want to watch</help>
13+
</field>
14+
<field>
15+
<id>general.interfaces</id>
16+
<label>Interfaces</label>
17+
<type>select_multiple</type>
18+
<help>Leave empty to track on all interfaces or add the interfaces you want to track</help>
19+
<hint>All (default)</hint>
20+
</field>
21+
<field>
22+
<id>general.suppress_mac</id>
23+
<label>Suppress MAC address</label>
24+
<type>select_multiple</type>
25+
<style>tokenize</style>
26+
<allownew>true</allownew>
27+
<help>
28+
<![CDATA[Add MAC addresses you want to exclude from the notifications in the following format: xx:xx:xx:xx:xx<br>
29+
The firewall MAC addresses are already excluded]]>
30+
</help>
31+
</field>
32+
<field>
33+
<id>general.log_new_entries</id>
34+
<label>Log new MAC/IP address entries</label>
35+
<type>checkbox</type>
36+
<help>Enable or disable the logging of new entries</help>
37+
</field>
38+
<field>
39+
<id>general.log_mac_changes</id>
40+
<label>Log MAC address changes</label>
41+
<type>checkbox</type>
42+
<help>Enable or disable the logging of MAC address changes (helps to find duplicates or spoofing)</help>
43+
</field>
44+
<field>
45+
<id>general.log_ipv4_changes</id>
46+
<label>Log IPv4 address changes</label>
47+
<type>checkbox</type>
48+
<help>Enable or disable the logging of IPv4 address changes</help>
49+
</field>
50+
<field>
51+
<id>general.log_ipv6_changes</id>
52+
<label>Log IPv6 address changes</label>
53+
<type>checkbox</type>
54+
<help>Enable or disable the logging of IPv6 address changes</help>
55+
</field>
56+
<field>
57+
<id>general.log_hostname_changes</id>
58+
<label>Log hostname changes</label>
59+
<type>checkbox</type>
60+
<help>Enable or disable the logging of hostname changes</help>
61+
</field>
62+
<field>
63+
<id>general.log_interface_changes</id>
64+
<label>Log interface changes</label>
65+
<type>checkbox</type>
66+
<help>Enable or disable the logging of interface changes</help>
67+
</field>
68+
<field>
69+
<id>general.retention_days</id>
70+
<label>Retention</label>
71+
<type>text</type>
72+
<advanced>true</advanced>
73+
<help>After how many days should an inactive MAC address be deleted from the database? After this period the device is recognized as new</help>
74+
</field>
75+
</form>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<acl>
2+
<page-opnarplog-config>
3+
<name>Services: OPNarplog</name>
4+
<patterns>
5+
<pattern>ui/opnarplog/*</pattern>
6+
<pattern>api/opnarplog/*</pattern>
7+
</patterns>
8+
</page-opnarplog-config>
9+
</acl>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
/*
4+
* Copyright (C) 2024 Deciso B.V.
5+
* Copyright (C) 2024 github.com/mr-manuel
6+
* All rights reserved.
7+
*
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions are met:
10+
*
11+
* 1. Redistributions of source code must retain the above copyright notice,
12+
* this list of conditions and the following disclaimer.
13+
*
14+
* 2. Redistributions in binary form must reproduce the above copyright
15+
* notice, this list of conditions and the following disclaimer in the
16+
* documentation and/or other materials provided with the distribution.
17+
*
18+
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20+
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21+
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22+
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
* POSSIBILITY OF SUCH DAMAGE.
28+
*/
29+
30+
namespace OPNsense\Opnarplog\FieldTypes;
31+
32+
use OPNsense\Base\FieldTypes\BaseListField;
33+
use OPNsense\Core\Config;
34+
35+
/**
36+
* Class OpnarplogDomainField
37+
* @package OPNsense\Opnarplog\FieldTypes
38+
* Created from src\opnsense\mvc\app\models\OPNsense\Unbound\FieldTypes\UnboundInterfaceField.php
39+
*/
40+
class OpnarplogInterfaceField extends BaseListField
41+
{
42+
/**
43+
* Iterate over all interfaces in the configuration and only exclude virtual interfaces.
44+
*/
45+
public function actionPostLoadingEvent()
46+
{
47+
$config = Config::getInstance()->object();
48+
49+
foreach ($config->interfaces->children() as $key => $node) {
50+
if (empty($node->virtual)) {
51+
$this->internalOptionList[str_replace(".", "_", $node->if)] = !empty($node->descr) ? (string)$node->descr : strtoupper($key);
52+
}
53+
}
54+
55+
natcasesort($this->internalOptionList);
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
/*
4+
* Copyright (C) 2024 github.com/mr-manuel
5+
* All rights reserved.
6+
*/
7+
8+
namespace OPNsense\Opnarplog;
9+
10+
use OPNsense\Base\BaseModel;
11+
12+
class General extends BaseModel
13+
{
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<model>
2+
<mount>//OPNsense/opnarplog/general</mount>
3+
<description>OPNarplog general configuration</description>
4+
<version>0.0.1</version>
5+
<items>
6+
<enabled type="BooleanField">
7+
<default>0</default>
8+
<Required>Y</Required>
9+
</enabled>
10+
<protocols type="OptionField">
11+
<Default>IPv4 and IPv6</Default>
12+
<Required>Y</Required>
13+
<OptionValues>
14+
<opt1 value="all">IPv4 and IPv6</opt1>
15+
<opt2 value="ipv4_only">IPv4 only</opt2>
16+
<opt3 value="ipv6_only">IPv6 only</opt3>
17+
</OptionValues>
18+
</protocols>
19+
<interfaces type=".\OpnarplogInterfaceField">
20+
<Required>N</Required>
21+
<Multiple>Y</Multiple>
22+
</interfaces>
23+
<suppress_mac type="CSVListField">
24+
<Required>N</Required>
25+
<Multiple>Y</Multiple>
26+
</suppress_mac>
27+
<log_new_entries type="BooleanField">
28+
<default>1</default>
29+
</log_new_entries>
30+
<log_mac_changes type="BooleanField">
31+
<default>1</default>
32+
</log_mac_changes>
33+
<log_ipv4_changes type="BooleanField">
34+
<default>0</default>
35+
</log_ipv4_changes>
36+
<log_ipv6_changes type="BooleanField">
37+
<default>0</default>
38+
</log_ipv6_changes>
39+
<log_hostname_changes type="BooleanField">
40+
<default>0</default>
41+
</log_hostname_changes>
42+
<log_interface_changes type="BooleanField">
43+
<default>0</default>
44+
</log_interface_changes>
45+
<retention_days type="IntegerField">
46+
<Default>30</Default>
47+
<Required>Y</Required>
48+
<advanced>true</advanced>
49+
<MinimumValue>1</MinimumValue>
50+
<MaximumValue>365</MaximumValue>
51+
<ValidationMessage>Retention needs to be an integer value between 1 and 365</ValidationMessage>
52+
</retention_days>
53+
</items>
54+
</model>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<menu>
2+
<Services>
3+
<OPNarplog VisibleName="OPNarplog" cssClass="fa fa-eye fa-fw">
4+
<General VisibleName="General" url="/ui/opnarplog/general/index" />
5+
<LogFile VisibleName="Log File" url="/ui/diagnostics/log/core/opnarplog" />
6+
</OPNarplog>
7+
</Services>
8+
</menu>

0 commit comments

Comments
 (0)