/** * 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); }
/** * update IDS settings * @return array status */ public function setAction() { $result = array("result" => "failed"); if ($this->request->isPost()) { // load model and update with provided data $mdlIDS = new IDS(); $mdlIDS->setNodes($this->request->getPost("ids")); // perform validation $valMsgs = $mdlIDS->performValidation(); foreach ($valMsgs as $field => $msg) { if (!array_key_exists("validations", $result)) { $result["validations"] = array(); } $result["validations"]["ids." . $msg->getField()] = $msg->getMessage(); } // serialize model to config and save if ($valMsgs->count() == 0) { $mdlIDS->serializeToConfig(); Config::getInstance()->save(); $result["result"] = "saved"; } } return $result; }