/** * monitor this entry by creating a monitor entry object and * committing it to the database * * @param string type should be src or dst depending * on which side of the connection is to be * monitored. * @throws Exception * @return integer 0 on success */ public function monitor($type) { if ($type == "src") { $addr = $this->srcaddr; $port = $this->sport; } else { $addr = $this->dstaddr; $port = $this->dport; } try { $monitor_ent = new portMonitorEntry($this->db); $monitor_ent->srcaddr = $addr; $monitor_ent->sport = $port; $monitor_ent->proto = $this->proto; $monitor_ent->commit(); } catch (Exception $e) { throw $e; } return 0; }
/** * applyDeviceTemplate * * @param args array containing parameters * device_id id of device to apply template to * template_id id of template to apply * @throws none * @return array containing result and possible error messages */ public function ajax_applyDevicetemplate($args) { $result = 'success'; $error = ''; $data = array(); try { if (!array_key_exists('device_id', $args)) { $result = 'failure'; $error = 'No device id supplied'; } else { if (!array_key_exists('template_id', $args)) { $result = 'failure'; $error = 'No template id supplied'; } else { $tpl = $this->getDeviceTemplate($args['template_id']); if (!is_null($tpl)) { // apply $tpl->params to device id // convert params from json data to php data $params = json_decode($tpl->params, true); $dev = $this->getDevice($args['device_id']); foreach ($params as $p) { if ($p['type'] == 'ICMP') { require_once 'pingEntry.php'; $ent = new pingEntry(); $ent->db($this->db); $ent->device = $dev; $ent->commit(); } else { if ($p['type'] == 'Port') { require_once 'portMonitorEntry.php'; $ent = new portMonitorEntry($this->db); $ent->device_id = $args['device_id']; $ent->sport = $p['port']; $ent->proto = 'tcp'; $ent->commit(); } else { if ($p['type'] == 'SSL Certificate') { require_once 'certificateMonitorEntry.php'; $ent = new certificateMonitorEntry($this->db); $ent->device_id = $args['device_id']; $ent->url = 'https://' . $dev->name . '/'; $ent->commit(); } else { if ($p['type'] == 'Shell Script') { require_once 'shellMonitorEntry.php'; $ent = new shellMonitorEntry($this->db); $ent->device_id = $args['device_id']; $ent->script = $p['script']; $ent->params = ''; $ent->commit(); } else { if ($p['type'] == 'URL') { require_once 'urlMonitorEntry.php'; $ent = new urlMonitorEntry($this->db); $ent->device_id = $args['device_id']; $ent->url = $p['url']; $ent->expect_http_status = $p['code']; $ent->expect_http_content = $p['content']; $ent->request_mathod = $p['method']; $ent->http_post_vars = $p['post_vars']; $ent->commit(); } } } } } } } else { $result = 'failure'; $error = 'Template id ' . $args['template_id'] . ' does not exist'; } } } } catch (Exception $e) { return array('result' => 'failure', 'error' => $e->getMessage()); } return array('result' => $result, 'error' => $error, 'data' => $data); }