Fix: SettingsController in install.sh aktualisiert (rmmagent[general] Parsing)
This commit is contained in:
@@ -273,9 +273,9 @@ class SettingsController extends ApiControllerBase
|
||||
public function getAction()
|
||||
{
|
||||
$mdl = new RMMAgent();
|
||||
$result = array('general' => array());
|
||||
$result = array('rmmagent' => array('general' => array()));
|
||||
foreach ($mdl->general->iterateItems() as $key => $node) {
|
||||
$result['general'][$key] = (string)$node;
|
||||
$result['rmmagent']['general'][$key] = (string)$node;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
@@ -285,20 +285,45 @@ class SettingsController extends ApiControllerBase
|
||||
$result = array('result' => 'failed');
|
||||
if ($this->request->isPost()) {
|
||||
$mdl = new RMMAgent();
|
||||
$post = $this->request->getPost('general');
|
||||
if (!empty($post)) {
|
||||
foreach ($post as $key => $value) {
|
||||
$node = $mdl->general->$key;
|
||||
if ($node !== null) {
|
||||
$node->setValue($value);
|
||||
$post = null;
|
||||
|
||||
// OPNsense sends data as rmmagent[general][KEY]
|
||||
$rmmagent = $this->request->getPost('rmmagent');
|
||||
if (!empty($rmmagent) && isset($rmmagent['general'])) {
|
||||
$post = $rmmagent['general'];
|
||||
}
|
||||
|
||||
// Fallback: JSON body
|
||||
if (empty($post)) {
|
||||
$rawBody = $this->request->getRawBody();
|
||||
if (!empty($rawBody)) {
|
||||
$jsonData = json_decode($rawBody, true);
|
||||
if (isset($jsonData['rmmagent']['general'])) {
|
||||
$post = $jsonData['rmmagent']['general'];
|
||||
} elseif (isset($jsonData['general'])) {
|
||||
$post = $jsonData['general'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($post)) {
|
||||
foreach ($post as $key => $value) {
|
||||
try {
|
||||
$node = $mdl->general->$key;
|
||||
if ($node !== null) {
|
||||
$node->setValue($value);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// skip
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$valMsgs = $mdl->performValidation();
|
||||
if ($valMsgs->count() > 0) {
|
||||
$result['validations'] = array();
|
||||
foreach ($valMsgs as $msg) {
|
||||
$result['validations']['general.' . $msg->getField()] = $msg->getMessage();
|
||||
$result['validations']['rmmagent.general.' . $msg->getField()] = $msg->getMessage();
|
||||
}
|
||||
} else {
|
||||
$mdl->serializeToConfig();
|
||||
@@ -575,6 +600,31 @@ function rmmagent_services()
|
||||
}
|
||||
INCEOF
|
||||
|
||||
# Initialen config.xml Eintrag erstellen (falls noch nicht vorhanden)
|
||||
echo " Initialen config.xml Eintrag pruefen..."
|
||||
cat > /tmp/rmm_init_config.php << 'INITEOF'
|
||||
<?php
|
||||
require_once("/usr/local/etc/inc/config.inc");
|
||||
$config = OPNsense\Core\Config::getInstance();
|
||||
$xml = $config->object();
|
||||
if (!isset($xml->OPNsense->rmmagent)) {
|
||||
$rmm = $xml->OPNsense->addChild('rmmagent');
|
||||
$gen = $rmm->addChild('general');
|
||||
$gen->addChild('Enabled', '0');
|
||||
$gen->addChild('BackendUrl', '');
|
||||
$gen->addChild('ApiKey', '');
|
||||
$gen->addChild('AgentName', '');
|
||||
$gen->addChild('Interval', '60');
|
||||
$gen->addChild('Insecure', '1');
|
||||
$config->save();
|
||||
echo " Initialer rmmagent Eintrag in config.xml erstellt\n";
|
||||
} else {
|
||||
echo " rmmagent Eintrag bereits vorhanden\n";
|
||||
}
|
||||
INITEOF
|
||||
php /tmp/rmm_init_config.php
|
||||
rm -f /tmp/rmm_init_config.php
|
||||
|
||||
# Cache loeschen und configd neustarten
|
||||
rm -f /var/lib/php/cache/_usr_local_opnsense_mvc_app_views_opnsense_rmmagent_*.php
|
||||
service configd restart
|
||||
|
||||
+30
-13
@@ -1,7 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace OPNsense\RMMAgent\Api;
|
||||
|
||||
use OPNsense\Base\ApiControllerBase;
|
||||
use OPNsense\RMMAgent\RMMAgent;
|
||||
use OPNsense\Core\Config;
|
||||
@@ -11,28 +9,48 @@ class SettingsController extends ApiControllerBase
|
||||
public function getAction()
|
||||
{
|
||||
$mdl = new RMMAgent();
|
||||
$result = array('general' => array());
|
||||
|
||||
$result = array('rmmagent' => array('general' => array()));
|
||||
foreach ($mdl->general->iterateItems() as $key => $node) {
|
||||
$result['general'][$key] = (string)$node;
|
||||
$result['rmmagent']['general'][$key] = (string)$node;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function setAction()
|
||||
{
|
||||
$result = array('result' => 'failed');
|
||||
|
||||
if ($this->request->isPost()) {
|
||||
$mdl = new RMMAgent();
|
||||
$post = null;
|
||||
|
||||
// OPNsense sends data as rmmagent[general][KEY]
|
||||
$rmmagent = $this->request->getPost('rmmagent');
|
||||
if (!empty($rmmagent) && isset($rmmagent['general'])) {
|
||||
$post = $rmmagent['general'];
|
||||
}
|
||||
|
||||
// Fallback: JSON body
|
||||
if (empty($post)) {
|
||||
$rawBody = $this->request->getRawBody();
|
||||
if (!empty($rawBody)) {
|
||||
$jsonData = json_decode($rawBody, true);
|
||||
if (isset($jsonData['rmmagent']['general'])) {
|
||||
$post = $jsonData['rmmagent']['general'];
|
||||
} elseif (isset($jsonData['general'])) {
|
||||
$post = $jsonData['general'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$post = $this->request->getPost('general');
|
||||
if (!empty($post)) {
|
||||
foreach ($post as $key => $value) {
|
||||
$node = $mdl->general->$key;
|
||||
if ($node !== null) {
|
||||
$node->setValue($value);
|
||||
try {
|
||||
$node = $mdl->general->$key;
|
||||
if ($node !== null) {
|
||||
$node->setValue($value);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// skip
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,7 +59,7 @@ class SettingsController extends ApiControllerBase
|
||||
if ($valMsgs->count() > 0) {
|
||||
$result['validations'] = array();
|
||||
foreach ($valMsgs as $msg) {
|
||||
$result['validations']['general.' . $msg->getField()] = $msg->getMessage();
|
||||
$result['validations']['rmmagent.general.' . $msg->getField()] = $msg->getMessage();
|
||||
}
|
||||
} else {
|
||||
$mdl->serializeToConfig();
|
||||
@@ -49,7 +67,6 @@ class SettingsController extends ApiControllerBase
|
||||
$result['result'] = 'saved';
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user