OPNsense Plugin: os-rmm-agent mit WebGUI-Settings, rc.d Service, configd-Integration, Build-Script
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace OPNsense\RMMAgent\Api;
|
||||
|
||||
use OPNsense\Base\ApiMutableServiceControllerBase;
|
||||
|
||||
class ServiceController extends ApiMutableServiceControllerBase
|
||||
{
|
||||
protected static $internalServiceClass = '\OPNsense\RMMAgent\RMMAgent';
|
||||
protected static $internalServiceTemplate = 'OPNsense/RMMAgent/config.yaml';
|
||||
protected static $internalServiceEnabled = 'general.Enabled';
|
||||
protected static $internalServiceName = 'rmmagent';
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace OPNsense\RMMAgent\Api;
|
||||
|
||||
use OPNsense\Base\ApiMutableModelControllerBase;
|
||||
|
||||
class SettingsController extends ApiMutableModelControllerBase
|
||||
{
|
||||
protected static $internalModelName = 'rmmagent';
|
||||
protected static $internalModelClass = 'OPNsense\RMMAgent\RMMAgent';
|
||||
|
||||
public function getAction()
|
||||
{
|
||||
return $this->getBase('general', 'general');
|
||||
}
|
||||
|
||||
public function setAction()
|
||||
{
|
||||
return $this->setBase('general', 'general');
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace OPNsense\RMMAgent;
|
||||
|
||||
use OPNsense\Base\IndexController;
|
||||
|
||||
class GeneralController extends IndexController
|
||||
{
|
||||
public function indexAction()
|
||||
{
|
||||
$this->view->generalForm = $this->getForm('general');
|
||||
$this->view->pick('OPNsense/RMMAgent/general');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<form>
|
||||
<field>
|
||||
<id>rmmagent.general.Enabled</id>
|
||||
<label>Aktiviert</label>
|
||||
<type>checkbox</type>
|
||||
<help>RMM Agent Dienst aktivieren/deaktivieren</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>rmmagent.general.BackendUrl</id>
|
||||
<label>Backend URL</label>
|
||||
<type>text</type>
|
||||
<help>URL des RMM Backends (z.B. https://192.168.85.13:8443)</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>rmmagent.general.ApiKey</id>
|
||||
<label>API Key</label>
|
||||
<type>password</type>
|
||||
<help>API-Schluessel fuer die Authentifizierung am Backend</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>rmmagent.general.AgentName</id>
|
||||
<label>Agent Name</label>
|
||||
<type>text</type>
|
||||
<help>Optionaler Name (Standard: Hostname der Firewall)</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>rmmagent.general.Interval</id>
|
||||
<label>Heartbeat Intervall (Sek.)</label>
|
||||
<type>text</type>
|
||||
<help>Intervall fuer Heartbeat/Datensammlung in Sekunden (Standard: 60)</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>rmmagent.general.Insecure</id>
|
||||
<label>Self-Signed Zertifikate</label>
|
||||
<type>checkbox</type>
|
||||
<help>TLS-Zertifikats-Pruefung deaktivieren (fuer self-signed Backend-Zertifikate)</help>
|
||||
</field>
|
||||
</form>
|
||||
@@ -0,0 +1,6 @@
|
||||
<menu>
|
||||
<Services>
|
||||
<RMMAgent VisibleName="RMM Agent" cssClass="fa fa-shield" url="/ui/rmmagent/general" order="99">
|
||||
</RMMAgent>
|
||||
</Services>
|
||||
</menu>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace OPNsense\RMMAgent;
|
||||
|
||||
use OPNsense\Base\BaseModel;
|
||||
|
||||
class RMMAgent extends BaseModel
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<model>
|
||||
<mount>//OPNsense/rmmagent</mount>
|
||||
<version>1.0.0</version>
|
||||
<description>RMM Agent Settings</description>
|
||||
<items>
|
||||
<general>
|
||||
<Enabled type="BooleanField">
|
||||
<Default>0</Default>
|
||||
<Required>Y</Required>
|
||||
</Enabled>
|
||||
<BackendUrl type="TextField">
|
||||
<Required>Y</Required>
|
||||
<Mask>/^https?:\/\/.+/</Mask>
|
||||
<ValidationMessage>Gueltige URL erforderlich (https://host:port)</ValidationMessage>
|
||||
</BackendUrl>
|
||||
<ApiKey type="TextField">
|
||||
<Required>Y</Required>
|
||||
<Mask>/^.{8,}$/</Mask>
|
||||
<ValidationMessage>API-Key muss mindestens 8 Zeichen lang sein</ValidationMessage>
|
||||
</ApiKey>
|
||||
<AgentName type="TextField">
|
||||
<Required>N</Required>
|
||||
<ValidationMessage>Optionaler Agent-Name</ValidationMessage>
|
||||
</AgentName>
|
||||
<Interval type="IntegerField">
|
||||
<Default>60</Default>
|
||||
<MinimumValue>10</MinimumValue>
|
||||
<MaximumValue>3600</MaximumValue>
|
||||
<ValidationMessage>Intervall zwischen 10 und 3600 Sekunden</ValidationMessage>
|
||||
</Interval>
|
||||
<Insecure type="BooleanField">
|
||||
<Default>1</Default>
|
||||
<Required>Y</Required>
|
||||
</Insecure>
|
||||
</general>
|
||||
</items>
|
||||
</model>
|
||||
@@ -0,0 +1,51 @@
|
||||
{#
|
||||
# Copyright (c) 2026 cynfo.com
|
||||
# RMM Agent Settings Page
|
||||
#}
|
||||
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
var data_get_map = {'frm_GeneralSettings': '/api/rmmagent/settings/get'};
|
||||
mapDataToFormUI(data_get_map).done(function () {
|
||||
formatTokenizersUI();
|
||||
$('.selectpicker').selectpicker('refresh');
|
||||
updateServiceControlUI('rmmagent');
|
||||
});
|
||||
|
||||
$('#saveAct').unbind('click').click(function () {
|
||||
saveFormToEndpoint('/api/rmmagent/settings/set', 'frm_GeneralSettings', function () {
|
||||
$('#saveAct_progress').addClass('fa fa-spinner fa-pulse');
|
||||
ajaxCall('/api/rmmagent/service/reconfigure', {}, function (data, status) {
|
||||
updateServiceControlUI('rmmagent');
|
||||
$('#saveAct_progress').removeClass('fa fa-spinner fa-pulse');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="content-box" style="padding: 10px;">
|
||||
<div class="content-box-header">
|
||||
<h3>{{ lang._('RMM Agent Einstellungen') }}</h3>
|
||||
</div>
|
||||
<div class="content-box-main">
|
||||
<div class="table-responsive">
|
||||
{{ partial("layout_partials/base_form", ['fields': generalForm, 'id': 'frm_GeneralSettings']) }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<hr/>
|
||||
<button class="btn btn-primary" id="saveAct" type="button">
|
||||
<b>{{ lang._('Speichern') }}</b> <i id="saveAct_progress"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="content-box" style="padding: 10px; margin-top: 20px;">
|
||||
<div class="content-box-header">
|
||||
<h3>{{ lang._('Dienst-Status') }}</h3>
|
||||
</div>
|
||||
<div class="content-box-main">
|
||||
{{ partial("layout_partials/service_control", ['serviceName': 'rmmagent']) }}
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,31 @@
|
||||
#!/usr/local/bin/php
|
||||
<?php
|
||||
|
||||
require_once('config.inc');
|
||||
require_once('util.inc');
|
||||
|
||||
use OPNsense\RMMAgent\RMMAgent;
|
||||
|
||||
$mdl = new RMMAgent();
|
||||
|
||||
$backendUrl = (string)$mdl->general->BackendUrl;
|
||||
$apiKey = (string)$mdl->general->ApiKey;
|
||||
$interval = (string)$mdl->general->Interval;
|
||||
$agentName = (string)$mdl->general->AgentName;
|
||||
$insecure = (string)$mdl->general->Insecure;
|
||||
|
||||
if (empty($interval)) {
|
||||
$interval = "60";
|
||||
}
|
||||
|
||||
echo "# RMM Agent Configuration — auto-generated\n";
|
||||
echo "# Do not edit — changes via OPNsense WebGUI\n\n";
|
||||
echo "backend_url: \"{$backendUrl}\"\n";
|
||||
echo "api_key: \"{$apiKey}\"\n";
|
||||
echo "interval_seconds: {$interval}\n";
|
||||
|
||||
if (!empty($agentName)) {
|
||||
echo "agent_name: \"{$agentName}\"\n";
|
||||
}
|
||||
|
||||
// insecure is handled via command-line flag, not config
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
# RMM Agent — generate config and manage service
|
||||
|
||||
CONFIGDIR="/usr/local/rmm"
|
||||
CONFIGFILE="${CONFIGDIR}/config.yaml"
|
||||
# Generate config from model
|
||||
mkdir -p "${CONFIGDIR}"
|
||||
/usr/local/bin/php /usr/local/opnsense/scripts/OPNsense/RMMAgent/generate_config.php > "${CONFIGFILE}"
|
||||
|
||||
# Check if enabled
|
||||
ENABLED=$(/usr/local/sbin/pluginctl -g OPNsense.rmmagent.general.Enabled 2>/dev/null)
|
||||
|
||||
# Check insecure flag
|
||||
INSECURE=$(/usr/local/sbin/pluginctl -g OPNsense.rmmagent.general.Insecure 2>/dev/null)
|
||||
if [ "${INSECURE}" = "1" ]; then
|
||||
/usr/sbin/sysrc rmm_agent_insecure="YES" > /dev/null 2>&1
|
||||
else
|
||||
/usr/sbin/sysrc rmm_agent_insecure="NO" > /dev/null 2>&1
|
||||
fi
|
||||
|
||||
if [ "${ENABLED}" = "1" ]; then
|
||||
/usr/sbin/sysrc rmm_agent_enable="YES" > /dev/null 2>&1
|
||||
/usr/local/etc/rc.d/rmm_agent restart
|
||||
echo "RMM Agent started"
|
||||
else
|
||||
/usr/local/etc/rc.d/rmm_agent stop 2>/dev/null
|
||||
/usr/sbin/sysrc rmm_agent_enable="NO" > /dev/null 2>&1
|
||||
echo "RMM Agent stopped"
|
||||
fi
|
||||
@@ -0,0 +1,29 @@
|
||||
[start]
|
||||
command:/usr/local/etc/rc.d/rmm_agent start
|
||||
parameters:
|
||||
type:script
|
||||
message:Starting RMM Agent
|
||||
|
||||
[stop]
|
||||
command:/usr/local/etc/rc.d/rmm_agent stop
|
||||
parameters:
|
||||
type:script
|
||||
message:Stopping RMM Agent
|
||||
|
||||
[restart]
|
||||
command:/usr/local/etc/rc.d/rmm_agent restart
|
||||
parameters:
|
||||
type:script
|
||||
message:Restarting RMM Agent
|
||||
|
||||
[status]
|
||||
command:/usr/local/etc/rc.d/rmm_agent status; exit 0
|
||||
parameters:
|
||||
type:script_output
|
||||
message:Request RMM Agent status
|
||||
|
||||
[reconfigure]
|
||||
command:/usr/local/opnsense/scripts/rmmagent/setup.sh
|
||||
parameters:
|
||||
type:script
|
||||
message:Reconfiguring RMM Agent
|
||||
Reference in New Issue
Block a user