diff --git a/net-mgmt/net-snmp/Makefile b/net-mgmt/net-snmp/Makefile new file mode 100644 index 000000000..7ff3a6ced --- /dev/null +++ b/net-mgmt/net-snmp/Makefile @@ -0,0 +1,7 @@ +PLUGIN_NAME= net-snmp +PLUGIN_VERSION= 0.1 +PLUGIN_COMMENT= Net-SNMP is a daemon for the SNMP protocol +PLUGIN_DEPENDS= net-snmp +PLUGIN_MAINTAINER= m.muenz@gmail.com +PLUGIN_DEVEL= yes +.include "../../Mk/plugins.mk" diff --git a/net-mgmt/net-snmp/pkg-descr b/net-mgmt/net-snmp/pkg-descr new file mode 100644 index 000000000..d5a05c057 --- /dev/null +++ b/net-mgmt/net-snmp/pkg-descr @@ -0,0 +1,8 @@ +Simple Network Management Protocol (SNMP) is a widely used +protocol for monitoring the health and welfare of network +equipment (eg. routers), computer equipment and even devices +like UPSs. +Net-SNMP is a suite of applications used to implement +SNMP v1, SNMP v2c and SNMP v3 using both IPv4 and IPv6. + +WWW: http://www.net-snmp.org \ No newline at end of file diff --git a/net-mgmt/net-snmp/src/etc/inc/plugins.inc.d/netsnmp.inc b/net-mgmt/net-snmp/src/etc/inc/plugins.inc.d/netsnmp.inc new file mode 100644 index 000000000..edb3d3f32 --- /dev/null +++ b/net-mgmt/net-snmp/src/etc/inc/plugins.inc.d/netsnmp.inc @@ -0,0 +1,55 @@ +enabled == '1'; +} + +function netsnmp_services() +{ + $services = array(); + + if (!netsnmp_enabled()) { + return $services; + } + + $services[] = array( + 'description' => gettext('Net-SNMP Daemon'), + 'configd' => array( + 'restart' => array('netsnmp restart'), + 'start' => array('netsnmp start'), + 'stop' => array('netsnmp stop'), + ), + 'name' => 'snmpd', + 'pidfile' => '/var/run/net_snmpd.pid' + ); + + return $services; +} diff --git a/net-mgmt/net-snmp/src/opnsense/mvc/app/controllers/OPNsense/Netsnmp/Api/GeneralController.php b/net-mgmt/net-snmp/src/opnsense/mvc/app/controllers/OPNsense/Netsnmp/Api/GeneralController.php new file mode 100644 index 000000000..a6e53f851 --- /dev/null +++ b/net-mgmt/net-snmp/src/opnsense/mvc/app/controllers/OPNsense/Netsnmp/Api/GeneralController.php @@ -0,0 +1,39 @@ +searchBase('users.user', array("enabled", "username", "password", "enckey")); + } + public function getUserAction($uuid = null) + { + $this->sessionClose(); + return $this->getBase('user', 'users.user', $uuid); + } + public function addUserAction() + { + return $this->addBase('user', 'users.user'); + } + public function delUserAction($uuid) + { + return $this->delBase('users.user', $uuid); + } + public function setUserAction($uuid) + { + return $this->setBase('user', 'users.user', $uuid); + } + public function toggleUserAction($uuid) + { + return $this->toggleBase('users.user', $uuid); + } +} diff --git a/net-mgmt/net-snmp/src/opnsense/mvc/app/controllers/OPNsense/Netsnmp/GeneralController.php b/net-mgmt/net-snmp/src/opnsense/mvc/app/controllers/OPNsense/Netsnmp/GeneralController.php new file mode 100644 index 000000000..508d49c9e --- /dev/null +++ b/net-mgmt/net-snmp/src/opnsense/mvc/app/controllers/OPNsense/Netsnmp/GeneralController.php @@ -0,0 +1,39 @@ +view->generalForm = $this->getForm("general"); + $this->view->formDialogEditNetsnmpUser = $this->getForm("dialogEditNetsnmpUser"); + $this->view->pick('OPNsense/Netsnmp/general'); + } +} diff --git a/net-mgmt/net-snmp/src/opnsense/mvc/app/controllers/OPNsense/Netsnmp/forms/dialogEditNetsnmpUser.xml b/net-mgmt/net-snmp/src/opnsense/mvc/app/controllers/OPNsense/Netsnmp/forms/dialogEditNetsnmpUser.xml new file mode 100644 index 000000000..afa4c3c25 --- /dev/null +++ b/net-mgmt/net-snmp/src/opnsense/mvc/app/controllers/OPNsense/Netsnmp/forms/dialogEditNetsnmpUser.xml @@ -0,0 +1,26 @@ +
+ + user.enabled + + checkbox + This will enable or disable the user account. + + + user.username + + text + Set the unique username for the user. + + + user.password + + text + Set the password for the user. Minimum is 8 characters. + + + user.enckey + + text + Set the encryption key to secure the connection between client and this host. Minimum is 8 characters. + +
diff --git a/net-mgmt/net-snmp/src/opnsense/mvc/app/controllers/OPNsense/Netsnmp/forms/general.xml b/net-mgmt/net-snmp/src/opnsense/mvc/app/controllers/OPNsense/Netsnmp/forms/general.xml new file mode 100644 index 000000000..fa72b365b --- /dev/null +++ b/net-mgmt/net-snmp/src/opnsense/mvc/app/controllers/OPNsense/Netsnmp/forms/general.xml @@ -0,0 +1,26 @@ +
+ + general.enabled + + checkbox + This will activate the snmpd service. + + + general.community + + text + Set the community string to use. + + + general.syslocation + + text + Set location where this unit is. + + + general.syscontact + + text + Set the contact address to use. + +
diff --git a/net-mgmt/net-snmp/src/opnsense/mvc/app/models/OPNsense/Netsnmp/ACL/ACL.xml b/net-mgmt/net-snmp/src/opnsense/mvc/app/models/OPNsense/Netsnmp/ACL/ACL.xml new file mode 100644 index 000000000..ec423b8f3 --- /dev/null +++ b/net-mgmt/net-snmp/src/opnsense/mvc/app/models/OPNsense/Netsnmp/ACL/ACL.xml @@ -0,0 +1,9 @@ + + + Services: Net-SNMP + + ui/netsnmp/* + api/netsnmp/* + + + diff --git a/net-mgmt/net-snmp/src/opnsense/mvc/app/models/OPNsense/Netsnmp/General.php b/net-mgmt/net-snmp/src/opnsense/mvc/app/models/OPNsense/Netsnmp/General.php new file mode 100644 index 000000000..9710927fc --- /dev/null +++ b/net-mgmt/net-snmp/src/opnsense/mvc/app/models/OPNsense/Netsnmp/General.php @@ -0,0 +1,35 @@ + + //OPNsense/netsnmp/general + Netsnmp configuration + 1.0.0 + + + 0 + Y + + + + N + + + + N + + + + N + + + diff --git a/net-mgmt/net-snmp/src/opnsense/mvc/app/models/OPNsense/Netsnmp/Menu/Menu.xml b/net-mgmt/net-snmp/src/opnsense/mvc/app/models/OPNsense/Netsnmp/Menu/Menu.xml new file mode 100644 index 000000000..970af18ed --- /dev/null +++ b/net-mgmt/net-snmp/src/opnsense/mvc/app/models/OPNsense/Netsnmp/Menu/Menu.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/net-mgmt/net-snmp/src/opnsense/mvc/app/models/OPNsense/Netsnmp/User.php b/net-mgmt/net-snmp/src/opnsense/mvc/app/models/OPNsense/Netsnmp/User.php new file mode 100644 index 000000000..f034df95b --- /dev/null +++ b/net-mgmt/net-snmp/src/opnsense/mvc/app/models/OPNsense/Netsnmp/User.php @@ -0,0 +1,31 @@ + + //OPNsense/netsnmp/user + Netsnmp user configuration + 1.0.0 + + + + + 1 + Y + + + + Y + /^([0-9a-zA-Z._\-]){1,64}$/u + Should be a string between 1 and 64 characters. Allowed characters are 0-9a-zA-Z._- + + + + Y + /^([0-9a-zA-Z._\-\!\$\%\/\(\)\+\#\=]){8,64}$/u + Should be a string between 8 and 64 characters. Allowed characters are 0-9a-zA-Z._-!$%/()+#= + + + + Y + /^([0-9a-zA-Z._\-\!\$\%\/\(\)\+\#\=]){8,64}$/u + Should be a string between 8 and 64 characters. Allowed characters are 0-9a-zA-Z._-!$%/()+#= + + + + + diff --git a/net-mgmt/net-snmp/src/opnsense/mvc/app/views/OPNsense/Netsnmp/general.volt b/net-mgmt/net-snmp/src/opnsense/mvc/app/views/OPNsense/Netsnmp/general.volt new file mode 100644 index 000000000..517364928 --- /dev/null +++ b/net-mgmt/net-snmp/src/opnsense/mvc/app/views/OPNsense/Netsnmp/general.volt @@ -0,0 +1,126 @@ +{# + +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. + +#} + + + + +
+
+
+ {{ partial("layout_partials/base_form",['fields':generalForm,'id':'frm_general_settings'])}} +
+
+ +
+
+
+
+ + + + + + + + + + + + + + + + + + + +
{{ lang._('Enabled') }}{{ lang._('Username') }}{{ lang._('Password') }}{{ lang._('Encryption Key') }}{{ lang._('ID') }}{{ lang._('Commands') }}
+ +
+
+
+ +

+
+
+
+ +{{ partial("layout_partials/base_dialog",['fields':formDialogEditNetsnmpUser,'id':'dialogEditNetsnmpUser','label':lang._('Edit User')])}} + + diff --git a/net-mgmt/net-snmp/src/opnsense/scripts/OPNsense/Netsnmp/setup.sh b/net-mgmt/net-snmp/src/opnsense/scripts/OPNsense/Netsnmp/setup.sh new file mode 100644 index 000000000..3f497afaf --- /dev/null +++ b/net-mgmt/net-snmp/src/opnsense/scripts/OPNsense/Netsnmp/setup.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +mkdir -p /var/net-snmp +chown -R root:wheel /var/net-snmp +chmod 755 /var/net-snmp + +mkdir -p /var/net-snmp/mib_indexes +chown -R root:wheel /var/mib_indexes +chmod 700 /var/net-snmp/mib_indexes diff --git a/net-mgmt/net-snmp/src/opnsense/service/conf/actions.d/actions_netsnmp.conf b/net-mgmt/net-snmp/src/opnsense/service/conf/actions.d/actions_netsnmp.conf new file mode 100644 index 000000000..708c7b5c9 --- /dev/null +++ b/net-mgmt/net-snmp/src/opnsense/service/conf/actions.d/actions_netsnmp.conf @@ -0,0 +1,24 @@ +[start] +command:/usr/local/opnsense/scripts/OPNsense/Netsnmp/setup.sh;/usr/local/etc/rc.d/snmpd start +parameters: +type:script +message:starting Net-SNMP + +[stop] +command:/usr/local/etc/rc.d/snmpd stop; exit 0 +parameters: +type:script +message:stopping Net-SNMP + +[restart] +command:/usr/local/opnsense/scripts/OPNsense/Netsnmp/setup.sh;/usr/local/etc/rc.d/snmpd restart +parameters: +type:script +message:restarting Net-SNMP + +[status] +command:/usr/local/etc/rc.d/snmpd status;exit 0 +parameters: +type:script_output +message:request Net-SNMP status + diff --git a/net-mgmt/net-snmp/src/opnsense/service/templates/OPNsense/Netsnmp/+TARGETS b/net-mgmt/net-snmp/src/opnsense/service/templates/OPNsense/Netsnmp/+TARGETS new file mode 100644 index 000000000..dd42c3b77 --- /dev/null +++ b/net-mgmt/net-snmp/src/opnsense/service/templates/OPNsense/Netsnmp/+TARGETS @@ -0,0 +1,3 @@ +snmpd:/etc/rc.conf.d/snmpd +snmpd_usercredentials.conf:/var/net-snmp/snmpd.conf +snmpd.conf:/usr/local/share/snmp/snmpd.conf \ No newline at end of file diff --git a/net-mgmt/net-snmp/src/opnsense/service/templates/OPNsense/Netsnmp/snmpd b/net-mgmt/net-snmp/src/opnsense/service/templates/OPNsense/Netsnmp/snmpd new file mode 100644 index 000000000..74a0cfcb3 --- /dev/null +++ b/net-mgmt/net-snmp/src/opnsense/service/templates/OPNsense/Netsnmp/snmpd @@ -0,0 +1,6 @@ +{% if helpers.exists('OPNsense.netsnmp.general.enabled') and OPNsense.netsnmp.general.enabled == '1' %} +snmpd_var_script="/usr/local/opnsense/scripts/OPNsense/Netsnmp/setup.sh" +snmpd_enable="YES" +{% else %} +snmpd_enable="NO" +{% endif %} diff --git a/net-mgmt/net-snmp/src/opnsense/service/templates/OPNsense/Netsnmp/snmpd.conf b/net-mgmt/net-snmp/src/opnsense/service/templates/OPNsense/Netsnmp/snmpd.conf new file mode 100644 index 000000000..d9b18e14d --- /dev/null +++ b/net-mgmt/net-snmp/src/opnsense/service/templates/OPNsense/Netsnmp/snmpd.conf @@ -0,0 +1,28 @@ +{% if helpers.exists('OPNsense.netsnmp.general.enabled') and OPNsense.netsnmp.general.enabled == '1' %} + +{% from 'OPNsense/Macros/interface.macro' import physical_interface %} + +agentAddress udp:161,udp6:[::1]:161 + +{% if helpers.exists('OPNsense.netsnmp.general.community') and OPNsense.netsnmp.general.community != '' %} +rocommunity {{ OPNsense.netsnmp.general.community }} +{% endif %} + +{% if helpers.exists('OPNsense.netsnmp.user.users.user') %} +{% for user_list in helpers.toList('OPNsense.netsnmp.user.users.user') %} +{% if user_list.enabled == '1' %} +rouser {{ user_list.username }} +{% endif %} +{% endfor %} +{% endif %} + +{% if helpers.exists('OPNsense.netsnmp.general.syslocation') and OPNsense.netsnmp.general.syslocation != '' %} +sysLocation {{ OPNsense.netsnmp.general.syslocation }} +{% endif %} + +{% if helpers.exists('OPNsense.netsnmp.general.syscontact') and OPNsense.netsnmp.general.syscontact != '' %} +sysContact {{ OPNsense.netsnmp.general.syscontact }} +{% endif %} + + +{% endif %} diff --git a/net-mgmt/net-snmp/src/opnsense/service/templates/OPNsense/Netsnmp/snmpd_usercredentials.conf b/net-mgmt/net-snmp/src/opnsense/service/templates/OPNsense/Netsnmp/snmpd_usercredentials.conf new file mode 100644 index 000000000..5296fc450 --- /dev/null +++ b/net-mgmt/net-snmp/src/opnsense/service/templates/OPNsense/Netsnmp/snmpd_usercredentials.conf @@ -0,0 +1,11 @@ +{% if helpers.exists('OPNsense.netsnmp.general.enabled') and OPNsense.netsnmp.general.enabled == '1' %} + +{% if helpers.exists('OPNsense.netsnmp.user.users.user') %} +{% for user_list in helpers.toList('OPNsense.netsnmp.user.users.user') %} +{% if user_list.enabled == '1' %} +createUser {{ user_list.username }} SHA "{{ user_list.password }}" AES {{ user_list.enckey}} +{% endif %} +{% endfor %} +{% endif %} + +{% endif %} \ No newline at end of file