/** * reconfigure IDS */ public function reconfigureAction() { $status = "failed"; if ($this->request->isPost()) { // close session for long running action $this->sessionClose(); $mdlIDS = new IDS(); $runStatus = $this->statusAction(); // we should always have a cron item configured for IDS, let's create one upon first reconfigure. if ((string) $mdlIDS->general->UpdateCron == "") { $mdlCron = new Cron(); // update cron relation (if this doesn't break consistency) $mdlIDS->general->UpdateCron = $mdlCron->newDailyJob("IDS", "ids update", "ids rule updates", "0"); if ($mdlCron->performValidation()->count() == 0) { $mdlCron->serializeToConfig(); // save data to config, do not validate because the current in memory model doesn't know about the // cron item just created. $mdlIDS->serializeToConfig($validateFullModel = false, $disable_validation = true); Config::getInstance()->save(); } } if ($runStatus['status'] == "running" && (string) $mdlIDS->general->enabled == 0) { $this->stopAction(); } $backend = new Backend(); $bckresult = trim($backend->configdRun("template reload OPNsense.IDS")); if ($bckresult == "OK") { if ((string) $mdlIDS->general->enabled == 1) { $bckresult = trim($backend->configdRun("ids install rules")); if ($bckresult == "OK") { if ($runStatus['status'] == 'running') { $status = $this->restartAction()['response']; } else { $status = $this->startAction()['response']; } } else { $status = "error installing ids rules (" . $bckresult . ")"; } } else { $status = "OK"; } } else { $status = "error generating ids template (" . $bckresult . ")"; } } return array("status" => $status); }
/** * add new job and set with attributes from post * @return array */ public function addJobAction() { $result = array("result" => "failed"); if ($this->request->isPost() && $this->request->hasPost("job")) { $result = array("result" => "failed", "validations" => array()); $mdlCron = new Cron(); $node = $mdlCron->jobs->job->Add(); $node->setNodes($this->request->getPost("job")); $node->origin = "cron"; // set origin to this component - cron are manually created rules. $valMsgs = $mdlCron->performValidation(); foreach ($valMsgs as $field => $msg) { $fieldnm = str_replace($node->__reference, "job", $msg->getField()); $result["validations"][$fieldnm] = $msg->getMessage(); } if (count($result['validations']) == 0) { // save config if validated correctly $mdlCron->serializeToConfig(); Config::getInstance()->save(); $result = array("result" => "saved"); } return $result; } return $result; }
/** * create new cron item for remote acl or return already available one * @return array status action */ public function fetchRBCronAction() { $result = array("result" => "failed"); if ($this->request->isPost()) { $mdlProxy = new Proxy(); if ((string) $mdlProxy->forward->acl->remoteACLs->UpdateCron == "") { $mdlCron = new Cron(); // update cron relation (if this doesn't break consistency) $uuid = $mdlCron->newDailyJob("Proxy", "proxy fetchacls", "fetch proxy acls", "1"); $mdlProxy->forward->acl->remoteACLs->UpdateCron = $uuid; if ($mdlCron->performValidation()->count() == 0) { $mdlCron->serializeToConfig(); // save data to config, do not validate because the current in memory model doesn't know about the // cron item just created. $mdlProxy->serializeToConfig($validateFullModel = false, $disable_validation = true); Config::getInstance()->save(); $result['result'] = "new"; $result['uuid'] = $uuid; } else { $result['result'] = "unable to add cron"; } } else { $result['result'] = "existing"; $result['uuid'] = (string) $mdlProxy->forward->acl->remoteACLs->UpdateCron; } } return $result; }
/** * add new job and set with attributes from post * @return array */ public function addJobAction() { $result = array("result" => "failed"); if ($this->request->isPost() && $this->request->hasPost("job")) { $result = array("result" => "failed", "validations" => array()); $mdlCron = new Cron(); $node = $mdlCron->jobs->job->Add(); $node->setNodes($this->request->getPost("job")); $node->origin = "cron"; // set origin to this component - cron are manually created rules. $valMsgs = $mdlCron->performValidation(); foreach ($valMsgs as $field => $msg) { $fieldnm = str_replace($node->__reference, "job", $msg->getField()); if ($fieldnm != $msg->getField()) { // only collect validation errors for the item we're currently editing. $result["validations"][$fieldnm] = $msg->getMessage(); } } if (count($result['validations']) == 0) { // we've already performed a validation, prevent issues from other items in the model reflecting back to us. $mdlCron->serializeToConfig($disable_validation = true); // save config if validated correctly Config::getInstance()->save(); $result = array("result" => "saved"); } return $result; } return $result; }