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

Add OPNarplog #4322

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions net-mgmt/opnarplog/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
PLUGIN_NAME= OPNarplog
PLUGIN_VERSION= 0.1
PLUGIN_REVISION= 1
PLUGIN_COMMENT= arpwatch alternative for OPNsense
PLUGIN_MAINTAINER= github.com/mr-manuel

.include "../../Mk/plugins.mk"
11 changes: 11 additions & 0 deletions net-mgmt/opnarplog/pkg-descr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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.

WWW: https://github.com/mr-manuel/opnsense_plugins


Plugin Changelog
================

0.1

* Initial release
424 changes: 424 additions & 0 deletions net-mgmt/opnarplog/src/bin/opnarplog.py

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions net-mgmt/opnarplog/src/etc/inc/plugins.inc.d/opnarplog.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/*
* Copyright (C) 2024 github.com/mr-manuel
* All rights reserved.
*
*/

function opnarplog_services()
{
global $config;

$services = array();

if (isset($config['OPNsense']['opnarplog']['general']['enabled']) && $config['OPNsense']['opnarplog']['general']['enabled'] == 1) {
$services[] = array(
'description' => gettext('OPNarplog Daemon'),
'configd' => array(
'restart' => array('opnarplog restart'),
'start' => array('opnarplog start'),
'stop' => array('opnarplog stop'),
),
'name' => 'opnarplog',
'pidfile' => '/var/run/opnarplog.pid',
);
}

return $services;
}
23 changes: 23 additions & 0 deletions net-mgmt/opnarplog/src/etc/rc.d/opnarplog
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: opnarplog
# REQUIRE: SERVERS
# KEYWORD: shutdown
#

. /etc/rc.subr

name=opnarplog

rcvar=opnarplog_enable
pidfile=/var/run/${name}.pid
command=/usr/sbin/daemon
command_args="-f -P ${pidfile} /usr/local/bin/python3 /usr/local/bin/opnarplog.py"

load_rc_config ${name}

: ${opnarplog_enable="NO"}

run_rc_command $1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* Copyright (C) 2024 github.com/mr-manuel
* All rights reserved.
*/

namespace OPNsense\Opnarplog\Api;

use OPNsense\Base\ApiMutableModelControllerBase;

class GeneralController extends ApiMutableModelControllerBase
{
protected static $internalModelClass = '\OPNsense\Opnarplog\General';
protected static $internalModelName = 'general';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* Copyright (C) 2024 github.com/mr-manuel
* All rights reserved.
*/

namespace OPNsense\Opnarplog\Api;

use OPNsense\Base\ApiMutableServiceControllerBase;
use OPNsense\Core\Backend;
use OPNsense\Opnarplog\General;

class ServiceController extends ApiMutableServiceControllerBase
{
protected static $internalServiceClass = '\OPNsense\Opnarplog\General';
protected static $internalServiceTemplate = 'OPNsense/Opnarplog';
protected static $internalServiceEnabled = 'enabled';
protected static $internalServiceName = 'opnarplog';

/**
* remove database folder
* @return array
*/
public function resetdbAction()
{
$backend = new Backend();
$response = $backend->configdRun("opnarplog resetdb");
return array("response" => $response);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/*
* Copyright (C) 2024 github.com/mr-manuel
* All rights reserved.
*/

namespace OPNsense\Opnarplog;

class GeneralController extends \OPNsense\Base\IndexController
{
public function indexAction()
{
$this->view->generalForm = $this->getForm('general');
$this->view->pick('OPNsense/Opnarplog/general');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<form>
<field>
<id>general.enabled</id>
<label>Enable</label>
<type>checkbox</type>
<help>Enable or disable OPNarplog. This will not automatically enable any mail notifications, see notes below</help>
</field>
<field>
<id>general.protocols</id>
<label>Protocols</label>
<type>dropdown</type>
<help>Select the protocols you want to watch</help>
</field>
<field>
<id>general.interfaces</id>
<label>Interfaces</label>
<type>select_multiple</type>
<help>Leave empty to track on all interfaces or add the interfaces you want to track</help>
<hint>All (default)</hint>
</field>
<field>
<id>general.suppress_mac</id>
<label>Suppress MAC address</label>
<type>select_multiple</type>
<style>tokenize</style>
<allownew>true</allownew>
<help>
<![CDATA[Add MAC addresses you want to exclude from the notifications in the following format: xx:xx:xx:xx:xx<br>
The firewall MAC addresses are already excluded]]>
</help>
</field>
<field>
<id>general.log_new_entries</id>
<label>Log new MAC/IP address entries</label>
<type>checkbox</type>
<help>Enable or disable the logging of new entries</help>
</field>
<field>
<id>general.log_mac_changes</id>
<label>Log MAC address changes</label>
<type>checkbox</type>
<help>Enable or disable the logging of MAC address changes (helps to find duplicates or spoofing)</help>
</field>
<field>
<id>general.log_ipv4_changes</id>
<label>Log IPv4 address changes</label>
<type>checkbox</type>
<help>Enable or disable the logging of IPv4 address changes</help>
</field>
<field>
<id>general.log_ipv6_changes</id>
<label>Log IPv6 address changes</label>
<type>checkbox</type>
<help>Enable or disable the logging of IPv6 address changes</help>
</field>
<field>
<id>general.log_hostname_changes</id>
<label>Log hostname changes</label>
<type>checkbox</type>
<help>Enable or disable the logging of hostname changes</help>
</field>
<field>
<id>general.log_interface_changes</id>
<label>Log interface changes</label>
<type>checkbox</type>
<help>Enable or disable the logging of interface changes</help>
</field>
<field>
<id>general.retention_days</id>
<label>Retention</label>
<type>text</type>
<advanced>true</advanced>
<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>
</field>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<acl>
<page-opnarplog-config>
<name>Services: OPNarplog</name>
<patterns>
<pattern>ui/opnarplog/*</pattern>
<pattern>api/opnarplog/*</pattern>
</patterns>
</page-opnarplog-config>
</acl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/*
* Copyright (C) 2024 Deciso B.V.
* Copyright (C) 2024 github.com/mr-manuel
* 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\Opnarplog\FieldTypes;

use OPNsense\Base\FieldTypes\BaseListField;
use OPNsense\Core\Config;

/**
* Class OpnarplogDomainField
* @package OPNsense\Opnarplog\FieldTypes
* Created from src\opnsense\mvc\app\models\OPNsense\Unbound\FieldTypes\UnboundInterfaceField.php
*/
class OpnarplogInterfaceField extends BaseListField
{
/**
* Iterate over all interfaces in the configuration and only exclude virtual interfaces.
*/
public function actionPostLoadingEvent()
{
$config = Config::getInstance()->object();

foreach ($config->interfaces->children() as $key => $node) {
if (empty($node->virtual)) {
$this->internalOptionList[str_replace(".", "_", $node->if)] = !empty($node->descr) ? (string)$node->descr : strtoupper($key);
}
}

natcasesort($this->internalOptionList);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

/*
* Copyright (C) 2024 github.com/mr-manuel
* All rights reserved.
*/

namespace OPNsense\Opnarplog;

use OPNsense\Base\BaseModel;

class General extends BaseModel
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<model>
<mount>//OPNsense/opnarplog/general</mount>
<description>OPNarplog general configuration</description>
<version>0.0.1</version>
<items>
<enabled type="BooleanField">
<default>0</default>
<Required>Y</Required>
</enabled>
<protocols type="OptionField">
<Default>IPv4 and IPv6</Default>
<Required>Y</Required>
<OptionValues>
<opt1 value="all">IPv4 and IPv6</opt1>
<opt2 value="ipv4_only">IPv4 only</opt2>
<opt3 value="ipv6_only">IPv6 only</opt3>
</OptionValues>
</protocols>
<interfaces type=".\OpnarplogInterfaceField">
<Required>N</Required>
<Multiple>Y</Multiple>
</interfaces>
<suppress_mac type="CSVListField">
<Required>N</Required>
<Multiple>Y</Multiple>
</suppress_mac>
<log_new_entries type="BooleanField">
<default>1</default>
</log_new_entries>
<log_mac_changes type="BooleanField">
<default>1</default>
</log_mac_changes>
<log_ipv4_changes type="BooleanField">
<default>0</default>
</log_ipv4_changes>
<log_ipv6_changes type="BooleanField">
<default>0</default>
</log_ipv6_changes>
<log_hostname_changes type="BooleanField">
<default>0</default>
</log_hostname_changes>
<log_interface_changes type="BooleanField">
<default>0</default>
</log_interface_changes>
<retention_days type="IntegerField">
<Default>30</Default>
<Required>Y</Required>
<advanced>true</advanced>
<MinimumValue>1</MinimumValue>
<MaximumValue>365</MaximumValue>
<ValidationMessage>Retention needs to be an integer value between 1 and 365</ValidationMessage>
</retention_days>
</items>
</model>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<menu>
<Services>
<OPNarplog VisibleName="OPNarplog" cssClass="fa fa-eye fa-fw">
<General VisibleName="General" url="/ui/opnarplog/general/index" />
<LogFile VisibleName="Log File" url="/ui/diagnostics/log/core/opnarplog" />
</OPNarplog>
</Services>
</menu>
Loading