diff --git a/sysutils/puppet-agent/Makefile b/sysutils/puppet-agent/Makefile index af7209fe7..60340eb67 100644 --- a/sysutils/puppet-agent/Makefile +++ b/sysutils/puppet-agent/Makefile @@ -1,8 +1,8 @@ PLUGIN_NAME= puppet-agent -PLUGIN_VERSION= 0.1 +PLUGIN_VERSION= 0.2 PLUGIN_DEVEL= yes PLUGIN_COMMENT= Manage Puppet Agent -PLUGIN_DEPENDS= puppet7 +PLUGIN_DEPENDS= puppet7 py-opn-cli PLUGIN_MAINTAINER= jan.wink93@gmail.com .include "../../Mk/plugins.mk" diff --git a/sysutils/puppet-agent/src/etc/inc/plugins.inc.d/puppetagent.inc b/sysutils/puppet-agent/src/etc/inc/plugins.inc.d/puppetagent.inc index c5dd7cc63..60274cabc 100644 --- a/sysutils/puppet-agent/src/etc/inc/plugins.inc.d/puppetagent.inc +++ b/sysutils/puppet-agent/src/etc/inc/plugins.inc.d/puppetagent.inc @@ -30,8 +30,7 @@ function puppetagent_enabled() { global $config; - return isset($config['OPNsense']['puppetagent']['general']['Enabled']) && - $config['OPNsense']['puppetagent']['general']['Enabled'] == 1; + return !empty($config['OPNsense']['puppetagent']['general']['Enabled']); } /** diff --git a/sysutils/puppet-agent/src/opnsense/mvc/app/controllers/OPNsense/PuppetAgent/Api/ServiceController.php b/sysutils/puppet-agent/src/opnsense/mvc/app/controllers/OPNsense/PuppetAgent/Api/ServiceController.php index 14af09d7e..a2bdd0452 100644 --- a/sysutils/puppet-agent/src/opnsense/mvc/app/controllers/OPNsense/PuppetAgent/Api/ServiceController.php +++ b/sysutils/puppet-agent/src/opnsense/mvc/app/controllers/OPNsense/PuppetAgent/Api/ServiceController.php @@ -45,30 +45,4 @@ class ServiceController extends ApiMutableServiceControllerBase protected static $internalServiceTemplate = 'OPNsense/PuppetAgent'; protected static $internalServiceEnabled = 'general.Enabled'; protected static $internalServiceName = 'puppetagent'; - - public function reconfigureAction() - { - if ($this->request->isPost()) { - // close session for long running action - $this->sessionClose(); - - $backend = new Backend(); - // generate template - $backend->configdRun('template reload OPNsense/PuppetAgent'); - - $mdlPuppetAgent = new PuppetAgent(); - - // (res)start daemon - if ($mdlPuppetAgent->general->Enabled->__toString() == 1) { - $this->startAction(); - } - // stop Puppet Agent when disabled - else { - $this->stopAction(); - } - return array("status" => "ok"); - } else { - return array("status" => "failed"); - } - } } diff --git a/sysutils/puppet-agent/src/opnsense/mvc/app/controllers/OPNsense/PuppetAgent/Api/SettingsController.php b/sysutils/puppet-agent/src/opnsense/mvc/app/controllers/OPNsense/PuppetAgent/Api/SettingsController.php index fcd5e8861..025525aaa 100644 --- a/sysutils/puppet-agent/src/opnsense/mvc/app/controllers/OPNsense/PuppetAgent/Api/SettingsController.php +++ b/sysutils/puppet-agent/src/opnsense/mvc/app/controllers/OPNsense/PuppetAgent/Api/SettingsController.php @@ -31,7 +31,7 @@ namespace OPNsense\PuppetAgent\Api; -use OPNsense\Base\ApiControllerBase; +use OPNsense\Base\ApiMutableModelControllerBase; use OPNsense\PuppetAgent\PuppetAgent; use OPNsense\Core\Config; @@ -39,55 +39,8 @@ use OPNsense\Core\Config; * Class SettingsController Handles settings related API actions for the PuppetAgent module * @package OPNsense\PuppetAgent */ -class SettingsController extends ApiControllerBase +class SettingsController extends ApiMutableModelControllerBase { - /** - * retrieve PuppetAgent general settings - * @return array general settings - * @throws \OPNsense\Base\ModelException - * @throws \ReflectionException - */ - public function getAction() - { - // define list of configurable settings - $result = array(); - if ($this->request->isGet()) { - $mdlPuppetAgent = new PuppetAgent(); - $result['puppetagent'] = $mdlPuppetAgent->getNodes(); - } - return $result; - } - - /** - * update PupppetAgent settings - * @return array status - * @throws \OPNsense\Base\ModelException - * @throws \ReflectionException - */ - public function setAction() - { - $result = array("result" => "failed"); - if ($this->request->isPost()) { - // load model and update with provided data - $mdlPuppetAgent = new PuppetAgent(); - $mdlPuppetAgent->setNodes($this->request->getPost("puppetagent")); - - // perform validation - $valMsgs = $mdlPuppetAgent->performValidation(); - foreach ($valMsgs as $field => $msg) { - if (!array_key_exists("validations", $result)) { - $result["validations"] = array(); - } - $result["validations"]["puppetagent." . $msg->getField()] = $msg->getMessage(); - } - - // serialize model to config and save - if ($valMsgs->count() == 0) { - $mdlPuppetAgent->serializeToConfig(); - Config::getInstance()->save(); - $result["result"] = "saved"; - } - } - return $result; - } + protected static $internalModelName = 'puppetagent'; + protected static $internalModelClass = 'OPNsense\PuppetAgent\PuppetAgent'; } diff --git a/sysutils/puppet-agent/src/opnsense/mvc/app/views/OPNsense/PuppetAgent/index.volt b/sysutils/puppet-agent/src/opnsense/mvc/app/views/OPNsense/PuppetAgent/index.volt index 289cf4e88..10b93ddf7 100644 --- a/sysutils/puppet-agent/src/opnsense/mvc/app/views/OPNsense/PuppetAgent/index.volt +++ b/sysutils/puppet-agent/src/opnsense/mvc/app/views/OPNsense/PuppetAgent/index.volt @@ -33,19 +33,17 @@ POSSIBILITY OF SUCH DAMAGE. mapDataToFormUI(data_get_map).done(function(data){ // place actions to run after load, for example update form styles. }); - - updateServiceControlUI('puppetagent'); - // link save button to API set action - $("#saveAct").click(function(){ - saveFormToEndpoint(url="/api/puppetagent/settings/set",formid='frm_GeneralSettings',callback_ok=function(){ - // action to run after successful save, for example reconfigure service. - ajaxCall(url="/api/puppetagent/service/reconfigure", sendData={},callback=function(data,status) { - // action to run after reload - updateServiceControlUI('puppetagent'); + $("#saveAct").SimpleActionButton({ + onPreAction: function() { + const dfObj = new $.Deferred(); + saveFormToEndpoint(url="/api/puppetagent/settings/set",formid='frm_GeneralSettings', function() { + dfObj.resolve(); }); - }); + return dfObj; + } }); + updateServiceControlUI('puppetagent'); }); @@ -58,5 +56,11 @@ POSSIBILITY OF SUCH DAMAGE.
- +
diff --git a/sysutils/puppet-agent/src/opnsense/service/conf/actions.d/actions_puppetagent.conf b/sysutils/puppet-agent/src/opnsense/service/conf/actions.d/actions_puppetagent.conf index 808144953..f31c2bbda 100644 --- a/sysutils/puppet-agent/src/opnsense/service/conf/actions.d/actions_puppetagent.conf +++ b/sysutils/puppet-agent/src/opnsense/service/conf/actions.d/actions_puppetagent.conf @@ -5,7 +5,7 @@ type:script message:starting puppet agent [stop] -command:/usr/local/etc/rc.d/puppet onestop +command:/usr/local/etc/rc.d/puppet stop parameters: type:script message:stop puppet agent