Пример #1
0
 /**
  * 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;
 }
Пример #2
0
 /**
  * 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);
 }
Пример #3
0
 /**
  * toggle job by uuid (enable/disable)
  * @param $uuid item unique id
  * @return array status
  */
 public function toggleJobAction($uuid)
 {
     $result = array("result" => "failed");
     if ($this->request->isPost()) {
         $mdlCron = new Cron();
         if ($uuid != null) {
             $node = $mdlCron->getNodeByReference('jobs.job.' . $uuid);
             if ($node != null) {
                 if ($node->enabled->__toString() == "1") {
                     $result['result'] = "Disabled";
                     $node->enabled = "0";
                 } else {
                     $result['result'] = "Enabled";
                     $node->enabled = "1";
                 }
                 // if item has toggled, serialize to config and save
                 $mdlCron->serializeToConfig();
                 Config::getInstance()->save();
             }
         }
     }
     return $result;
 }