diff --git a/security/clamav/src/opnsense/mvc/app/controllers/OPNsense/ClamAV/Api/GeneralController.php b/security/clamav/src/opnsense/mvc/app/controllers/OPNsense/ClamAV/Api/GeneralController.php index 704c29577..a732d11ba 100644 --- a/security/clamav/src/opnsense/mvc/app/controllers/OPNsense/ClamAV/Api/GeneralController.php +++ b/security/clamav/src/opnsense/mvc/app/controllers/OPNsense/ClamAV/Api/GeneralController.php @@ -31,47 +31,10 @@ namespace OPNsense\ClamAV\Api; -use \OPNsense\Base\ApiControllerBase; -use \OPNsense\ClamAV\General; -use \OPNsense\Core\Config; +use \OPNsense\Base\ApiMutableModelControllerBase; -class GeneralController extends ApiControllerBase +class GeneralController extends ApiMutableModelControllerBase { - public function getAction() - { - // define list of configurable settings - $result = array(); - if ($this->request->isGet()) { - $mdlGeneral = new General(); - $result['general'] = $mdlGeneral->getNodes(); - } - return $result; - } - - public function setAction() - { - $result = array("result"=>"failed"); - if ($this->request->isPost()) { - // load model and update with provided data - $mdlGeneral = new General(); - $mdlGeneral->setNodes($this->request->getPost("general")); - - // perform validation - $valMsgs = $mdlGeneral->performValidation(); - foreach ($valMsgs as $field => $msg) { - if (!array_key_exists("validations", $result)) { - $result["validations"] = array(); - } - $result["validations"]["general.".$msg->getField()] = $msg->getMessage(); - } - - // serialize model to config and save - if ($valMsgs->count() == 0) { - $mdlGeneral->serializeToConfig(); - Config::getInstance()->save(); - $result["result"] = "saved"; - } - } - return $result; - } + static protected $internalModelName = 'general'; + static protected $internalModelClass = '\OPNsense\ClamAV\General'; } diff --git a/www/c-icap/src/opnsense/mvc/app/controllers/OPNsense/CICAP/Api/AntivirusController.php b/www/c-icap/src/opnsense/mvc/app/controllers/OPNsense/CICAP/Api/AntivirusController.php index b4018a4a7..b8f5831f1 100644 --- a/www/c-icap/src/opnsense/mvc/app/controllers/OPNsense/CICAP/Api/AntivirusController.php +++ b/www/c-icap/src/opnsense/mvc/app/controllers/OPNsense/CICAP/Api/AntivirusController.php @@ -31,47 +31,10 @@ namespace OPNsense\CICAP\Api; -use \OPNsense\Base\ApiControllerBase; -use \OPNsense\CICAP\Antivirus; -use \OPNsense\Core\Config; +use \OPNsense\Base\ApiMutableModelControllerBase; -class AntivirusController extends ApiControllerBase +class AntivirusController extends ApiMutableModelControllerBase { - public function getAction() - { - // define list of configurable settings - $result = array(); - if ($this->request->isGet()) { - $mdlAntivirus = new Antivirus(); - $result['antivirus'] = $mdlAntivirus->getNodes(); - } - return $result; - } - - public function setAction() - { - $result = array("result"=>"failed"); - if ($this->request->isPost()) { - // load model and update with provided data - $mdlAntivirus = new Antivirus(); - $mdlAntivirus->setNodes($this->request->getPost("antivirus")); - - // perform validation - $valMsgs = $mdlAntivirus->performValidation(); - foreach ($valMsgs as $field => $msg) { - if (!array_key_exists("validations", $result)) { - $result["validations"] = array(); - } - $result["validations"]["antivirus.".$msg->getField()] = $msg->getMessage(); - } - - // serialize model to config and save - if ($valMsgs->count() == 0) { - $mdlAntivirus->serializeToConfig(); - Config::getInstance()->save(); - $result["result"] = "saved"; - } - } - return $result; - } + static protected $internalModelName = 'antivirus'; + static protected $internalModelClass = '\OPNsense\CICAP\Antivirus'; } diff --git a/www/c-icap/src/opnsense/mvc/app/controllers/OPNsense/CICAP/Api/GeneralController.php b/www/c-icap/src/opnsense/mvc/app/controllers/OPNsense/CICAP/Api/GeneralController.php index f66807e73..9685d4cc4 100644 --- a/www/c-icap/src/opnsense/mvc/app/controllers/OPNsense/CICAP/Api/GeneralController.php +++ b/www/c-icap/src/opnsense/mvc/app/controllers/OPNsense/CICAP/Api/GeneralController.php @@ -31,47 +31,10 @@ namespace OPNsense\CICAP\Api; -use \OPNsense\Base\ApiControllerBase; -use \OPNsense\CICAP\General; -use \OPNsense\Core\Config; +use \OPNsense\Base\ApiMutableModelControllerBase; -class GeneralController extends ApiControllerBase +class GeneralController extends ApiMutableModelControllerBase { - public function getAction() - { - // define list of configurable settings - $result = array(); - if ($this->request->isGet()) { - $mdlGeneral = new General(); - $result['general'] = $mdlGeneral->getNodes(); - } - return $result; - } - - public function setAction() - { - $result = array("result"=>"failed"); - if ($this->request->isPost()) { - // load model and update with provided data - $mdlGeneral = new General(); - $mdlGeneral->setNodes($this->request->getPost("general")); - - // perform validation - $valMsgs = $mdlGeneral->performValidation(); - foreach ($valMsgs as $field => $msg) { - if (!array_key_exists("validations", $result)) { - $result["validations"] = array(); - } - $result["validations"]["general.".$msg->getField()] = $msg->getMessage(); - } - - // serialize model to config and save - if ($valMsgs->count() == 0) { - $mdlGeneral->serializeToConfig(); - Config::getInstance()->save(); - $result["result"] = "saved"; - } - } - return $result; - } + static protected $internalModelName = 'general'; + static protected $internalModelClass = '\OPNsense\CICAP\General'; }