mirror of
https://github.com/netbirdio/plugins.git
synced 2026-05-22 18:44:07 -07:00
Merge pull request #2423 from jan-win1993/puppet-agent-ver02
Puppet Agent plugin version 0.2
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
-26
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-51
@@ -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';
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -58,5 +56,11 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
</div>
|
||||
|
||||
<div class="col-md-12">
|
||||
<button class="btn btn-primary" id="saveAct" type="button"><b>{{ lang._('Save') }}</b></button>
|
||||
<button class="btn btn-primary" id="saveAct"
|
||||
data-endpoint='/api/puppetagent/service/reconfigure'
|
||||
data-label="{{ lang._('Save') }}"
|
||||
data-service-widget="puppetagent"
|
||||
data-error-title="{{ lang._('Error reconfiguring puppetagent') }}"
|
||||
type="button"
|
||||
></button>
|
||||
</div>
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user