@@ -7,103 +7,103 @@ |
||
| 7 | 7 | class HandlerTable extends TrapDirectorTable |
| 8 | 8 | { |
| 9 | 9 | |
| 10 | - protected $status_display=array( |
|
| 11 | - -2 =>'ignore', |
|
| 12 | - -1 => '-', |
|
| 13 | - 0 => 'OK', |
|
| 14 | - 1 => 'warning', |
|
| 15 | - 2 => 'critical', |
|
| 16 | - 3 => 'unknown',); |
|
| 10 | + protected $status_display=array( |
|
| 11 | + -2 =>'ignore', |
|
| 12 | + -1 => '-', |
|
| 13 | + 0 => 'OK', |
|
| 14 | + 1 => 'warning', |
|
| 15 | + 2 => 'critical', |
|
| 16 | + 3 => 'unknown',); |
|
| 17 | 17 | |
| 18 | - // translate |
|
| 19 | - protected $doTranslate=false; |
|
| 20 | - protected $MIB; |
|
| 18 | + // translate |
|
| 19 | + protected $doTranslate=false; |
|
| 20 | + protected $MIB; |
|
| 21 | 21 | |
| 22 | - public function setMibloader($mibloader) |
|
| 23 | - { |
|
| 24 | - $this->MIB=$mibloader; |
|
| 25 | - $this->doTranslate=true; |
|
| 26 | - } |
|
| 22 | + public function setMibloader($mibloader) |
|
| 23 | + { |
|
| 24 | + $this->MIB=$mibloader; |
|
| 25 | + $this->doTranslate=true; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | 28 | |
| 29 | - public function getCurrentURL() |
|
| 30 | - { |
|
| 31 | - return Url::fromPath($this->urlPath . '/handler'); |
|
| 32 | - } |
|
| 29 | + public function getCurrentURL() |
|
| 30 | + { |
|
| 31 | + return Url::fromPath($this->urlPath . '/handler'); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - public function renderLine($row) |
|
| 35 | - { |
|
| 36 | - $html = ''; |
|
| 37 | - $firstCol = true; |
|
| 34 | + public function renderLine($row) |
|
| 35 | + { |
|
| 36 | + $html = ''; |
|
| 37 | + $firstCol = true; |
|
| 38 | 38 | |
| 39 | - $titleNames = array_keys($this->titles); |
|
| 40 | - foreach ($titleNames as $rowkey ) |
|
| 41 | - { |
|
| 42 | - // Check missing value |
|
| 43 | - if (property_exists($row, $rowkey)) |
|
| 44 | - { |
|
| 45 | - switch ($rowkey) |
|
| 46 | - { |
|
| 47 | - case 'action_match': // display text levels |
|
| 48 | - case 'action_nomatch': |
|
| 49 | - $val=$this->status_display[$row->$rowkey]; |
|
| 50 | - break; |
|
| 51 | - case 'trap_oid': // try to traslate oids. |
|
| 39 | + $titleNames = array_keys($this->titles); |
|
| 40 | + foreach ($titleNames as $rowkey ) |
|
| 41 | + { |
|
| 42 | + // Check missing value |
|
| 43 | + if (property_exists($row, $rowkey)) |
|
| 44 | + { |
|
| 45 | + switch ($rowkey) |
|
| 46 | + { |
|
| 47 | + case 'action_match': // display text levels |
|
| 48 | + case 'action_nomatch': |
|
| 49 | + $val=$this->status_display[$row->$rowkey]; |
|
| 50 | + break; |
|
| 51 | + case 'trap_oid': // try to traslate oids. |
|
| 52 | 52 | |
| 53 | - if ($this->doTranslate === true) |
|
| 54 | - { |
|
| 55 | - $oidName = $this->MIB->translateOID($row->$rowkey); |
|
| 56 | - if (isset($oidName['name'])) |
|
| 57 | - { |
|
| 58 | - $val=$oidName['name']; |
|
| 59 | - } |
|
| 60 | - else |
|
| 61 | - { |
|
| 62 | - $val = $row->$rowkey; |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - else |
|
| 66 | - { |
|
| 67 | - $val = $row->$rowkey; |
|
| 68 | - } |
|
| 69 | - break; |
|
| 70 | - case 'host_name': // switch to hostgroup if name is null |
|
| 71 | - if ($row->$rowkey == null) |
|
| 72 | - { |
|
| 73 | - $val = $row->host_group_name; |
|
| 74 | - } |
|
| 75 | - else |
|
| 76 | - { |
|
| 77 | - $val = $row->$rowkey; |
|
| 78 | - } |
|
| 79 | - break; |
|
| 80 | - default: |
|
| 81 | - $val = $row->$rowkey; |
|
| 82 | - } |
|
| 83 | - if ($rowkey == 'trap_oid' && $this->doTranslate===true) |
|
| 84 | - { |
|
| 53 | + if ($this->doTranslate === true) |
|
| 54 | + { |
|
| 55 | + $oidName = $this->MIB->translateOID($row->$rowkey); |
|
| 56 | + if (isset($oidName['name'])) |
|
| 57 | + { |
|
| 58 | + $val=$oidName['name']; |
|
| 59 | + } |
|
| 60 | + else |
|
| 61 | + { |
|
| 62 | + $val = $row->$rowkey; |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + else |
|
| 66 | + { |
|
| 67 | + $val = $row->$rowkey; |
|
| 68 | + } |
|
| 69 | + break; |
|
| 70 | + case 'host_name': // switch to hostgroup if name is null |
|
| 71 | + if ($row->$rowkey == null) |
|
| 72 | + { |
|
| 73 | + $val = $row->host_group_name; |
|
| 74 | + } |
|
| 75 | + else |
|
| 76 | + { |
|
| 77 | + $val = $row->$rowkey; |
|
| 78 | + } |
|
| 79 | + break; |
|
| 80 | + default: |
|
| 81 | + $val = $row->$rowkey; |
|
| 82 | + } |
|
| 83 | + if ($rowkey == 'trap_oid' && $this->doTranslate===true) |
|
| 84 | + { |
|
| 85 | 85 | |
| 86 | - } |
|
| 87 | - } else { |
|
| 88 | - $val = '-'; |
|
| 89 | - } |
|
| 90 | - if ($firstCol === true) { // Put link in first column for trap detail. |
|
| 91 | - $html .= '<td>' |
|
| 92 | - . $this->view->qlink( |
|
| 93 | - $this->view->escape($val), |
|
| 94 | - Url::fromPath( |
|
| 95 | - $this->urlPath . '/handler/add', |
|
| 96 | - array('ruleid' => $row->id) |
|
| 97 | - ) |
|
| 98 | - ) |
|
| 99 | - . '</td>'; |
|
| 100 | - } else { |
|
| 101 | - $html .= '<td>' . $this->view->escape($val) . '</td>'; |
|
| 102 | - } |
|
| 103 | - $firstCol=false; |
|
| 86 | + } |
|
| 87 | + } else { |
|
| 88 | + $val = '-'; |
|
| 89 | + } |
|
| 90 | + if ($firstCol === true) { // Put link in first column for trap detail. |
|
| 91 | + $html .= '<td>' |
|
| 92 | + . $this->view->qlink( |
|
| 93 | + $this->view->escape($val), |
|
| 94 | + Url::fromPath( |
|
| 95 | + $this->urlPath . '/handler/add', |
|
| 96 | + array('ruleid' => $row->id) |
|
| 97 | + ) |
|
| 98 | + ) |
|
| 99 | + . '</td>'; |
|
| 100 | + } else { |
|
| 101 | + $html .= '<td>' . $this->view->escape($val) . '</td>'; |
|
| 102 | + } |
|
| 103 | + $firstCol=false; |
|
| 104 | 104 | |
| 105 | - } |
|
| 106 | - return $html; |
|
| 107 | - } |
|
| 105 | + } |
|
| 106 | + return $html; |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | 109 | } |
| 110 | 110 | \ No newline at end of file |
@@ -18,9 +18,9 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | // Filters |
| 20 | 20 | |
| 21 | - protected $filter; |
|
| 22 | - protected $enforcedFilters = array(); |
|
| 23 | - protected $searchColumns = array(); |
|
| 21 | + protected $filter; |
|
| 22 | + protected $enforcedFilters = array(); |
|
| 23 | + protected $searchColumns = array(); |
|
| 24 | 24 | |
| 25 | 25 | protected function getTitles() { |
| 26 | 26 | // TODO : check moduleconfig is set |
@@ -28,10 +28,10 @@ discard block |
||
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | // ****************** Render table in html |
| 31 | - public function __toString() |
|
| 32 | - { |
|
| 33 | - return $this->render(); |
|
| 34 | - } |
|
| 31 | + public function __toString() |
|
| 32 | + { |
|
| 33 | + return $this->render(); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | 36 | public function render() |
| 37 | 37 | { |
@@ -95,26 +95,26 @@ discard block |
||
| 95 | 95 | |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - public function count() |
|
| 99 | - { |
|
| 100 | - $db=$this->db(); |
|
| 98 | + public function count() |
|
| 99 | + { |
|
| 100 | + $db=$this->db(); |
|
| 101 | 101 | |
| 102 | 102 | $query = $db->select()->from( |
| 103 | - $this->moduleConfig->getTrapTableName(), |
|
| 104 | - array('COUNT(*)') |
|
| 105 | - ); |
|
| 103 | + $this->moduleConfig->getTrapTableName(), |
|
| 104 | + array('COUNT(*)') |
|
| 105 | + ); |
|
| 106 | 106 | $this->applyFiltersToQuery($query); |
| 107 | 107 | |
| 108 | - return $db->fetchOne($query); |
|
| 109 | - } |
|
| 108 | + return $db->fetchOne($query); |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - public function getPaginator() |
|
| 112 | - { |
|
| 113 | - $paginator = new Paginator(); |
|
| 114 | - $paginator->setQuery($this); |
|
| 111 | + public function getPaginator() |
|
| 112 | + { |
|
| 113 | + $paginator = new Paginator(); |
|
| 114 | + $paginator->setQuery($this); |
|
| 115 | 115 | |
| 116 | - return $paginator; |
|
| 117 | - } |
|
| 116 | + return $paginator; |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | 119 | // ****************** DB connection and query |
| 120 | 120 | |
@@ -124,24 +124,24 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | $query = $this->getBaseQuery(); |
| 126 | 126 | $this->applyFiltersToQuery($query); |
| 127 | - if ($this->hasLimit() || $this->hasOffset()) { |
|
| 128 | - $query->limit($this->getLimit(), $this->getOffset()); |
|
| 129 | - } |
|
| 127 | + if ($this->hasLimit() || $this->hasOffset()) { |
|
| 128 | + $query->limit($this->getLimit(), $this->getOffset()); |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | 131 | return $db->fetchAll($query); |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - public function getBaseQuery() |
|
| 135 | - { |
|
| 134 | + public function getBaseQuery() |
|
| 135 | + { |
|
| 136 | 136 | $db=$this->db(); |
| 137 | 137 | |
| 138 | 138 | $query = $db->select()->from( |
| 139 | - $this->moduleConfig->getTrapTableName(), |
|
| 140 | - $this->moduleConfig->getTrapListDisplayColumns() |
|
| 141 | - )->order('timestamp DESC'); |
|
| 139 | + $this->moduleConfig->getTrapTableName(), |
|
| 140 | + $this->moduleConfig->getTrapListDisplayColumns() |
|
| 141 | + )->order('timestamp DESC'); |
|
| 142 | 142 | |
| 143 | - return $query; |
|
| 144 | - } |
|
| 143 | + return $query; |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | 146 | // ****************** Filters |
| 147 | 147 | |
@@ -171,39 +171,39 @@ discard block |
||
| 171 | 171 | $this->filter_done=(isset($filter['done']))?$this->filter_done=$filter['done']:0; |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - protected function getSearchColumns() |
|
| 175 | - { |
|
| 176 | - return $this->getColumns(); |
|
| 177 | - } |
|
| 174 | + protected function getSearchColumns() |
|
| 175 | + { |
|
| 176 | + return $this->getColumns(); |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | 179 | public function getColumns() |
| 180 | 180 | { |
| 181 | 181 | return $this->moduleConfig->getTrapListDisplayColumns(); |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - public function setFilter($filter) |
|
| 185 | - { |
|
| 186 | - $this->filter = $filter; |
|
| 187 | - return $this; |
|
| 188 | - } |
|
| 184 | + public function setFilter($filter) |
|
| 185 | + { |
|
| 186 | + $this->filter = $filter; |
|
| 187 | + return $this; |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | 190 | public function getFilterEditor(Request $request) |
| 191 | - { |
|
| 192 | - $filterEditor = Widget::create('filterEditor') |
|
| 193 | - ->setColumns(array_keys($this->getColumns())) |
|
| 194 | - ->setSearchColumns(array_keys($this->getSearchColumns())) |
|
| 195 | - ->preserveParams('limit', 'sort', 'dir', 'view', 'backend') |
|
| 196 | - ->ignoreParams('page') |
|
| 197 | - ->handleRequest($request); |
|
| 191 | + { |
|
| 192 | + $filterEditor = Widget::create('filterEditor') |
|
| 193 | + ->setColumns(array_keys($this->getColumns())) |
|
| 194 | + ->setSearchColumns(array_keys($this->getSearchColumns())) |
|
| 195 | + ->preserveParams('limit', 'sort', 'dir', 'view', 'backend') |
|
| 196 | + ->ignoreParams('page') |
|
| 197 | + ->handleRequest($request); |
|
| 198 | 198 | |
| 199 | - $filter = $filterEditor->getFilter(); |
|
| 200 | - $this->setFilter($filter); |
|
| 199 | + $filter = $filterEditor->getFilter(); |
|
| 200 | + $this->setFilter($filter); |
|
| 201 | 201 | |
| 202 | - return $filterEditor; |
|
| 203 | - } |
|
| 202 | + return $filterEditor; |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | - protected function applyFiltersToQuery($query) |
|
| 206 | - { |
|
| 205 | + protected function applyFiltersToQuery($query) |
|
| 206 | + { |
|
| 207 | 207 | |
| 208 | 208 | $sql=''; |
| 209 | 209 | if ($this->filter_query != '') |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | $sql.="(status != 'done')"; |
| 225 | 225 | } |
| 226 | 226 | if ($sql != '') $query->where($sql); |
| 227 | - return $query; |
|
| 228 | - } |
|
| 227 | + return $query; |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | 230 | } |
| 231 | 231 | \ No newline at end of file |
@@ -9,275 +9,275 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | abstract class TrapDirectorTable |
| 11 | 11 | { |
| 12 | - /** @var array $titles table titles (name, display value) */ |
|
| 13 | - protected $titles = null; |
|
| 12 | + /** @var array $titles table titles (name, display value) */ |
|
| 13 | + protected $titles = null; |
|
| 14 | 14 | |
| 15 | - /** @var array $content table content (name, sb column name). name index must be the same as $titles*/ |
|
| 16 | - protected $content = null; |
|
| 15 | + /** @var array $content table content (name, sb column name). name index must be the same as $titles*/ |
|
| 16 | + protected $content = null; |
|
| 17 | 17 | |
| 18 | - /** @var array $columnNames names of columns for filtering */ |
|
| 19 | - protected $columnNames = array(); |
|
| 18 | + /** @var array $columnNames names of columns for filtering */ |
|
| 19 | + protected $columnNames = array(); |
|
| 20 | 20 | |
| 21 | - /** @var Selectable $dbConn connection to database */ |
|
| 22 | - protected $dbConn = null; |
|
| 21 | + /** @var Selectable $dbConn connection to database */ |
|
| 22 | + protected $dbConn = null; |
|
| 23 | 23 | |
| 24 | - /** Current view **/ |
|
| 25 | - protected $view; |
|
| 24 | + /** Current view **/ |
|
| 25 | + protected $view; |
|
| 26 | 26 | |
| 27 | - protected $urlPath; |
|
| 27 | + protected $urlPath; |
|
| 28 | 28 | |
| 29 | - // Database stuff |
|
| 29 | + // Database stuff |
|
| 30 | 30 | /** @var array $table (db ref, name) */ |
| 31 | - protected $table = array(); |
|
| 31 | + protected $table = array(); |
|
| 32 | 32 | |
| 33 | - /** @var Queryable $query Query in database; */ |
|
| 34 | - protected $query = null; |
|
| 33 | + /** @var Queryable $query Query in database; */ |
|
| 34 | + protected $query = null; |
|
| 35 | 35 | |
| 36 | - /** @var array $order : (db column, 'ASC' | 'DESC') */ |
|
| 37 | - protected $order = array(); |
|
| 38 | - protected $orderQuery = ''; |
|
| 36 | + /** @var array $order : (db column, 'ASC' | 'DESC') */ |
|
| 37 | + protected $order = array(); |
|
| 38 | + protected $orderQuery = ''; |
|
| 39 | 39 | |
| 40 | - /********* Filter ********/ |
|
| 41 | - /** @var string $filterString : string filter for db columns */ |
|
| 42 | - protected $filterString = ''; |
|
| 40 | + /********* Filter ********/ |
|
| 41 | + /** @var string $filterString : string filter for db columns */ |
|
| 42 | + protected $filterString = ''; |
|
| 43 | 43 | |
| 44 | - /** @var array $filterColumn : columns to apply filter to */ |
|
| 45 | - protected $filterColumn = array(); |
|
| 44 | + /** @var array $filterColumn : columns to apply filter to */ |
|
| 45 | + protected $filterColumn = array(); |
|
| 46 | 46 | |
| 47 | - protected $filterQuery=''; |
|
| 47 | + protected $filterQuery=''; |
|
| 48 | 48 | |
| 49 | - /*************** Paging *************/ |
|
| 50 | - protected $maxPerPage = 25; |
|
| 49 | + /*************** Paging *************/ |
|
| 50 | + protected $maxPerPage = 25; |
|
| 51 | 51 | |
| 52 | - protected $currentPage = 0; |
|
| 52 | + protected $currentPage = 0; |
|
| 53 | 53 | |
| 54 | - function __construct(array $table,array $titles, array $columns, array $columnNames, $dbConn , $view, $urlPath) |
|
| 55 | - { |
|
| 56 | - $this->table = $table; |
|
| 57 | - $this->titles = $titles; |
|
| 58 | - $this->content = $columns; |
|
| 59 | - $this->columnNames = $columnNames; |
|
| 60 | - $this->dbConn = $dbConn; |
|
| 54 | + function __construct(array $table,array $titles, array $columns, array $columnNames, $dbConn , $view, $urlPath) |
|
| 55 | + { |
|
| 56 | + $this->table = $table; |
|
| 57 | + $this->titles = $titles; |
|
| 58 | + $this->content = $columns; |
|
| 59 | + $this->columnNames = $columnNames; |
|
| 60 | + $this->dbConn = $dbConn; |
|
| 61 | 61 | |
| 62 | - $this->view = $view; |
|
| 63 | - $this->urlPath = $urlPath; |
|
| 62 | + $this->view = $view; |
|
| 63 | + $this->urlPath = $urlPath; |
|
| 64 | 64 | |
| 65 | - return $this; |
|
| 66 | - } |
|
| 65 | + return $this; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | 68 | |
| 69 | - /************** GET variables and URLs *************/ |
|
| 70 | - public function getParams(array $getVars) |
|
| 71 | - { |
|
| 72 | - $this->getFilterQuery($getVars); |
|
| 73 | - $this->getPagingQuery($getVars); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - public function getCurrentURL() |
|
| 77 | - { |
|
| 78 | - return '?'; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - protected function getCurrentURLAndQS(string $caller) |
|
| 82 | - { |
|
| 83 | - $actionURL = $this->getCurrentURL() . '?' ; |
|
| 84 | - $QSList=array(); |
|
| 85 | - if ($caller != 'filter' && $this->curFilterQuery() != '') |
|
| 86 | - array_push($QSList , $this->curFilterQuery()); |
|
| 69 | + /************** GET variables and URLs *************/ |
|
| 70 | + public function getParams(array $getVars) |
|
| 71 | + { |
|
| 72 | + $this->getFilterQuery($getVars); |
|
| 73 | + $this->getPagingQuery($getVars); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + public function getCurrentURL() |
|
| 77 | + { |
|
| 78 | + return '?'; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + protected function getCurrentURLAndQS(string $caller) |
|
| 82 | + { |
|
| 83 | + $actionURL = $this->getCurrentURL() . '?' ; |
|
| 84 | + $QSList=array(); |
|
| 85 | + if ($caller != 'filter' && $this->curFilterQuery() != '') |
|
| 86 | + array_push($QSList , $this->curFilterQuery()); |
|
| 87 | 87 | |
| 88 | - if ($caller != 'paging' && $caller != 'filter' && $this->curPagingQuery() != '') |
|
| 89 | - array_push($QSList , $this->curPagingQuery()); |
|
| 88 | + if ($caller != 'paging' && $caller != 'filter' && $this->curPagingQuery() != '') |
|
| 89 | + array_push($QSList , $this->curPagingQuery()); |
|
| 90 | 90 | |
| 91 | - if ($caller != 'order' && $this->curOrderQuery() != '') |
|
| 92 | - array_push($QSList , $this->curOrderQuery()); |
|
| 91 | + if ($caller != 'order' && $this->curOrderQuery() != '') |
|
| 92 | + array_push($QSList , $this->curOrderQuery()); |
|
| 93 | 93 | |
| 94 | - if (count($QSList) != 0) |
|
| 95 | - $actionURL .= implode('&', $QSList); |
|
| 94 | + if (count($QSList) != 0) |
|
| 95 | + $actionURL .= implode('&', $QSList); |
|
| 96 | 96 | |
| 97 | - return $actionURL; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /************* DB queries ******************/ |
|
| 101 | - /** |
|
| 102 | - * Get base query in $this->query |
|
| 103 | - * @return TrapDirectorTable |
|
| 104 | - */ |
|
| 105 | - public function getBaseQuery() |
|
| 106 | - { |
|
| 107 | - $this->query = $this->dbConn->select(); |
|
| 108 | - $this->query = $this->query->from( |
|
| 109 | - $this->table, |
|
| 110 | - $this->content |
|
| 111 | - ); |
|
| 97 | + return $actionURL; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /************* DB queries ******************/ |
|
| 101 | + /** |
|
| 102 | + * Get base query in $this->query |
|
| 103 | + * @return TrapDirectorTable |
|
| 104 | + */ |
|
| 105 | + public function getBaseQuery() |
|
| 106 | + { |
|
| 107 | + $this->query = $this->dbConn->select(); |
|
| 108 | + $this->query = $this->query->from( |
|
| 109 | + $this->table, |
|
| 110 | + $this->content |
|
| 111 | + ); |
|
| 112 | 112 | |
| 113 | - return $this; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - public function fullQuery() |
|
| 117 | - { |
|
| 118 | - $this->getBaseQuery() |
|
| 119 | - ->applyFilter() |
|
| 120 | - ->applyPaging() |
|
| 121 | - ->applyOrder(); |
|
| 113 | + return $this; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + public function fullQuery() |
|
| 117 | + { |
|
| 118 | + $this->getBaseQuery() |
|
| 119 | + ->applyFilter() |
|
| 120 | + ->applyPaging() |
|
| 121 | + ->applyOrder(); |
|
| 122 | 122 | |
| 123 | - return $this->dbConn->fetchAll($this->query); |
|
| 124 | - //return $this->query->fetchAll(); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - /**************** Filtering ******************/ |
|
| 129 | - public function applyFilter() |
|
| 130 | - { |
|
| 131 | - if ($this->filterString == '' || count($this->filterColumn) == 0) |
|
| 132 | - { |
|
| 133 | - return $this; |
|
| 134 | - } |
|
| 135 | - $filter=''; |
|
| 136 | - foreach ($this->filterColumn as $column) |
|
| 137 | - { |
|
| 138 | - if ($filter != "") $filter.=' OR '; |
|
| 139 | - //$filter .= "'" . $column . "' LIKE '%" . $this->filterString. "%'"; |
|
| 140 | - $filter .= $column . " LIKE '%" . $this->filterString. "%'"; |
|
| 141 | - } |
|
| 142 | - //echo $filter; |
|
| 123 | + return $this->dbConn->fetchAll($this->query); |
|
| 124 | + //return $this->query->fetchAll(); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + /**************** Filtering ******************/ |
|
| 129 | + public function applyFilter() |
|
| 130 | + { |
|
| 131 | + if ($this->filterString == '' || count($this->filterColumn) == 0) |
|
| 132 | + { |
|
| 133 | + return $this; |
|
| 134 | + } |
|
| 135 | + $filter=''; |
|
| 136 | + foreach ($this->filterColumn as $column) |
|
| 137 | + { |
|
| 138 | + if ($filter != "") $filter.=' OR '; |
|
| 139 | + //$filter .= "'" . $column . "' LIKE '%" . $this->filterString. "%'"; |
|
| 140 | + $filter .= $column . " LIKE '%" . $this->filterString. "%'"; |
|
| 141 | + } |
|
| 142 | + //echo $filter; |
|
| 143 | 143 | |
| 144 | - $this->query=$this->query->where($filter); |
|
| 144 | + $this->query=$this->query->where($filter); |
|
| 145 | 145 | |
| 146 | - return $this; |
|
| 147 | - } |
|
| 146 | + return $this; |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - public function setFilter(string $filter, array $filterCol) |
|
| 150 | - { |
|
| 151 | - $this->filterString = $filter; |
|
| 152 | - $this->filterColumn = $filterCol; |
|
| 153 | - return $this; |
|
| 154 | - } |
|
| 149 | + public function setFilter(string $filter, array $filterCol) |
|
| 150 | + { |
|
| 151 | + $this->filterString = $filter; |
|
| 152 | + $this->filterColumn = $filterCol; |
|
| 153 | + return $this; |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | 156 | |
| 157 | - public function renderFilter() |
|
| 158 | - { |
|
| 157 | + public function renderFilter() |
|
| 158 | + { |
|
| 159 | 159 | |
| 160 | - $html=' <form id="genfilter" name="mainFilterGen" |
|
| 160 | + $html=' <form id="genfilter" name="mainFilterGen" |
|
| 161 | 161 | enctype="application/x-www-form-urlencoded" |
| 162 | 162 | action="'.$this->getCurrentURLAndQS('filter').'" |
| 163 | 163 | method="get">'; |
| 164 | - $html.='<input type="text" name="f" title="Search is simple! Try to combine multiple words" |
|
| 164 | + $html.='<input type="text" name="f" title="Search is simple! Try to combine multiple words" |
|
| 165 | 165 | placeholder="Search..." value="'.$this->filterQuery.'">'; |
| 166 | 166 | |
| 167 | - $html.='</form>'; |
|
| 168 | - return $html; |
|
| 169 | - } |
|
| 167 | + $html.='</form>'; |
|
| 168 | + return $html; |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - public function getFilterQuery(array $getVars) |
|
| 172 | - { |
|
| 173 | - if (isset($getVars['f'])) |
|
| 174 | - { |
|
| 175 | - $this->filterQuery = $getVars['f']; |
|
| 176 | - $this->setFilter(html_entity_decode($getVars['f']), $this->columnNames); |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - protected function curFilterQuery() |
|
| 181 | - { |
|
| 182 | - if ($this->filterQuery == '') return ''; |
|
| 183 | - return 'f='.$this->filterQuery; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /***************** Ordering ********************/ |
|
| 187 | - public function applyOrder() |
|
| 188 | - { |
|
| 189 | - if (count($this->order) == 0) |
|
| 190 | - { |
|
| 191 | - return $this; |
|
| 192 | - } |
|
| 193 | - $orderSQL=''; |
|
| 194 | - foreach ($this->order as $column => $direction) |
|
| 195 | - { |
|
| 196 | - if ($orderSQL != "") $orderSQL.=','; |
|
| 171 | + public function getFilterQuery(array $getVars) |
|
| 172 | + { |
|
| 173 | + if (isset($getVars['f'])) |
|
| 174 | + { |
|
| 175 | + $this->filterQuery = $getVars['f']; |
|
| 176 | + $this->setFilter(html_entity_decode($getVars['f']), $this->columnNames); |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + protected function curFilterQuery() |
|
| 181 | + { |
|
| 182 | + if ($this->filterQuery == '') return ''; |
|
| 183 | + return 'f='.$this->filterQuery; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /***************** Ordering ********************/ |
|
| 187 | + public function applyOrder() |
|
| 188 | + { |
|
| 189 | + if (count($this->order) == 0) |
|
| 190 | + { |
|
| 191 | + return $this; |
|
| 192 | + } |
|
| 193 | + $orderSQL=''; |
|
| 194 | + foreach ($this->order as $column => $direction) |
|
| 195 | + { |
|
| 196 | + if ($orderSQL != "") $orderSQL.=','; |
|
| 197 | 197 | |
| 198 | - $orderSQL .= $column . ' ' . $direction; |
|
| 199 | - } |
|
| 200 | - $this->query = $this->query->order($orderSQL); |
|
| 198 | + $orderSQL .= $column . ' ' . $direction; |
|
| 199 | + } |
|
| 200 | + $this->query = $this->query->order($orderSQL); |
|
| 201 | 201 | |
| 202 | - return $this; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - public function setOrder(array $order) |
|
| 206 | - { |
|
| 207 | - $this->order = $order; |
|
| 208 | - return $this; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - public function getOrderQuery(array $getVars) |
|
| 212 | - { |
|
| 213 | - if (isset($getVars['o'])) |
|
| 214 | - { |
|
| 215 | - $this->orderQuery = $getVars['o']; |
|
| 216 | - // TODO |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - protected function curOrderQuery() |
|
| 221 | - { |
|
| 222 | - if ($this->orderQuery == '') return ''; |
|
| 223 | - return 'o='.$this->orderQuery; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /***************** Paging and counting *********/ |
|
| 227 | - public function countQuery() |
|
| 228 | - { |
|
| 229 | - $this->query = $this->dbConn->select(); |
|
| 230 | - $this->query = $this->query |
|
| 231 | - ->from( |
|
| 232 | - $this->table, |
|
| 233 | - array('COUNT(*)') |
|
| 234 | - ); |
|
| 235 | - $this->applyFilter(); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - public function count() |
|
| 239 | - { |
|
| 240 | - $this->countQuery(); |
|
| 241 | - return $this->dbConn->fetchOne($this->query); |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - public function setMaxPerPage(int $max) |
|
| 245 | - { |
|
| 246 | - $this->maxPerPage = $max; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - protected function getPagingQuery(array $getVars) |
|
| 250 | - { |
|
| 251 | - if (isset($getVars['page'])) |
|
| 252 | - { |
|
| 253 | - $this->currentPage = $getVars['page']; |
|
| 254 | - } |
|
| 255 | - } |
|
| 202 | + return $this; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + public function setOrder(array $order) |
|
| 206 | + { |
|
| 207 | + $this->order = $order; |
|
| 208 | + return $this; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + public function getOrderQuery(array $getVars) |
|
| 212 | + { |
|
| 213 | + if (isset($getVars['o'])) |
|
| 214 | + { |
|
| 215 | + $this->orderQuery = $getVars['o']; |
|
| 216 | + // TODO |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + protected function curOrderQuery() |
|
| 221 | + { |
|
| 222 | + if ($this->orderQuery == '') return ''; |
|
| 223 | + return 'o='.$this->orderQuery; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /***************** Paging and counting *********/ |
|
| 227 | + public function countQuery() |
|
| 228 | + { |
|
| 229 | + $this->query = $this->dbConn->select(); |
|
| 230 | + $this->query = $this->query |
|
| 231 | + ->from( |
|
| 232 | + $this->table, |
|
| 233 | + array('COUNT(*)') |
|
| 234 | + ); |
|
| 235 | + $this->applyFilter(); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + public function count() |
|
| 239 | + { |
|
| 240 | + $this->countQuery(); |
|
| 241 | + return $this->dbConn->fetchOne($this->query); |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + public function setMaxPerPage(int $max) |
|
| 245 | + { |
|
| 246 | + $this->maxPerPage = $max; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + protected function getPagingQuery(array $getVars) |
|
| 250 | + { |
|
| 251 | + if (isset($getVars['page'])) |
|
| 252 | + { |
|
| 253 | + $this->currentPage = $getVars['page']; |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | 256 | |
| 257 | - protected function curPagingQuery() |
|
| 258 | - { |
|
| 259 | - if ($this->currentPage == '') return ''; |
|
| 260 | - return 'page='.$this->currentPage; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - public function renderPagingHeader() |
|
| 264 | - { |
|
| 265 | - $count = $this->count(); |
|
| 266 | - if ($count <= $this->maxPerPage ) |
|
| 267 | - { |
|
| 268 | - return 'count : ' . $this->count() . '<br>'; |
|
| 269 | - } |
|
| 257 | + protected function curPagingQuery() |
|
| 258 | + { |
|
| 259 | + if ($this->currentPage == '') return ''; |
|
| 260 | + return 'page='.$this->currentPage; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + public function renderPagingHeader() |
|
| 264 | + { |
|
| 265 | + $count = $this->count(); |
|
| 266 | + if ($count <= $this->maxPerPage ) |
|
| 267 | + { |
|
| 268 | + return 'count : ' . $this->count() . '<br>'; |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - if ($this->currentPage == 0) $this->currentPage = 1; |
|
| 271 | + if ($this->currentPage == 0) $this->currentPage = 1; |
|
| 272 | 272 | |
| 273 | - $numPages = intdiv($count , $this->maxPerPage); |
|
| 274 | - if ($count % $this->maxPerPage != 0 ) $numPages++; |
|
| 273 | + $numPages = intdiv($count , $this->maxPerPage); |
|
| 274 | + if ($count % $this->maxPerPage != 0 ) $numPages++; |
|
| 275 | 275 | |
| 276 | - $html = '<div class="pagination-control" role="navigation">'; |
|
| 277 | - $html .= '<ul class="nav tab-nav">'; |
|
| 278 | - if ($this->currentPage <=1) |
|
| 279 | - { |
|
| 280 | - $html .= ' |
|
| 276 | + $html = '<div class="pagination-control" role="navigation">'; |
|
| 277 | + $html .= '<ul class="nav tab-nav">'; |
|
| 278 | + if ($this->currentPage <=1) |
|
| 279 | + { |
|
| 280 | + $html .= ' |
|
| 281 | 281 | <li class="nav-item disabled" aria-hidden="true"> |
| 282 | 282 | <span class="previous-page"> |
| 283 | 283 | <span class="sr-only">Previous page</span> |
@@ -285,35 +285,35 @@ discard block |
||
| 285 | 285 | </span> |
| 286 | 286 | </li> |
| 287 | 287 | '; |
| 288 | - } |
|
| 289 | - else |
|
| 290 | - { |
|
| 291 | - $html .= ' |
|
| 288 | + } |
|
| 289 | + else |
|
| 290 | + { |
|
| 291 | + $html .= ' |
|
| 292 | 292 | <li class="nav-item"> |
| 293 | 293 | <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. ($this->currentPage - 1 ).'" class="previous-page" > |
| 294 | 294 | <i aria-hidden="true" class="icon-angle-double-left"></i> |
| 295 | 295 | </a> |
| 296 | 296 | </li> |
| 297 | 297 | '; |
| 298 | - } |
|
| 298 | + } |
|
| 299 | 299 | |
| 300 | - for ($i=1; $i <= $numPages ; $i++) |
|
| 301 | - { |
|
| 302 | - $active = ($this->currentPage == $i) ? 'active' : ''; |
|
| 303 | - $first = ($i-1)*$this->maxPerPage+1; |
|
| 304 | - $last = $i * $this->maxPerPage; |
|
| 305 | - if ($last > $count) $last = $count; |
|
| 306 | - $display = 'Show rows '. $first . ' to '. $last .' of '. $count; |
|
| 307 | - $html .= '<li class="' . $active . ' nav-item"> |
|
| 300 | + for ($i=1; $i <= $numPages ; $i++) |
|
| 301 | + { |
|
| 302 | + $active = ($this->currentPage == $i) ? 'active' : ''; |
|
| 303 | + $first = ($i-1)*$this->maxPerPage+1; |
|
| 304 | + $last = $i * $this->maxPerPage; |
|
| 305 | + if ($last > $count) $last = $count; |
|
| 306 | + $display = 'Show rows '. $first . ' to '. $last .' of '. $count; |
|
| 307 | + $html .= '<li class="' . $active . ' nav-item"> |
|
| 308 | 308 | <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. $i .'" title="' . $display . '" aria-label="' . $display . '"> |
| 309 | 309 | '.$i.' |
| 310 | 310 | </a> |
| 311 | 311 | </li>'; |
| 312 | - } |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - if ($this->currentPage == $numPages) |
|
| 315 | - { |
|
| 316 | - $html .= ' |
|
| 314 | + if ($this->currentPage == $numPages) |
|
| 315 | + { |
|
| 316 | + $html .= ' |
|
| 317 | 317 | <li class="nav-item disabled" aria-hidden="true"> |
| 318 | 318 | <span class="previous-page"> |
| 319 | 319 | <span class="sr-only">Previous page</span> |
@@ -321,21 +321,21 @@ discard block |
||
| 321 | 321 | </span> |
| 322 | 322 | </li> |
| 323 | 323 | '; |
| 324 | - } |
|
| 325 | - else |
|
| 326 | - { |
|
| 327 | - $html .= ' |
|
| 324 | + } |
|
| 325 | + else |
|
| 326 | + { |
|
| 327 | + $html .= ' |
|
| 328 | 328 | <li class="nav-item"> |
| 329 | 329 | <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. ($this->currentPage + 1 ).'" class="next-page"> |
| 330 | 330 | <i aria-hidden="true" class="icon-angle-double-right"></i> |
| 331 | 331 | </a> |
| 332 | 332 | </li> |
| 333 | 333 | '; |
| 334 | - } |
|
| 334 | + } |
|
| 335 | 335 | |
| 336 | - $html .= '</ul> </div>'; |
|
| 336 | + $html .= '</ul> </div>'; |
|
| 337 | 337 | |
| 338 | - $htmlOLD = ' |
|
| 338 | + $htmlOLD = ' |
|
| 339 | 339 | <ul class="nav tab-nav"> |
| 340 | 340 | |
| 341 | 341 | <li class="active nav-item"> |
@@ -355,68 +355,68 @@ discard block |
||
| 355 | 355 | </li> |
| 356 | 356 | </ul> |
| 357 | 357 | '; |
| 358 | - return $html; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - public function applyPaging() |
|
| 362 | - { |
|
| 363 | - $this->query->limitPage($this->currentPage,$this->maxPerPage); |
|
| 364 | - return $this; |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - /*************** Rendering *************************/ |
|
| 368 | - public function renderTitles() |
|
| 369 | - { |
|
| 370 | - $html = "<thead>\n<tr>\n"; |
|
| 371 | - foreach ($this->titles as $values) |
|
| 372 | - { |
|
| 373 | - $html .= '<th>' . $values . '</th>'; |
|
| 374 | - } |
|
| 375 | - $html .= "</tr>\n</thead>\n"; |
|
| 376 | - return $html; |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - public function renderLine( $value) |
|
| 380 | - { |
|
| 381 | - $html = ''; |
|
| 382 | - $titleNames = array_keys($this->titles); |
|
| 383 | - foreach ($titleNames as $name ) |
|
| 384 | - { |
|
| 385 | - $html .= '<td>'; |
|
| 386 | - $html .= $value->$name; |
|
| 387 | - $html .= "</td>\n"; |
|
| 388 | - } |
|
| 389 | - return $html; |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - public function renderTable(array $values) |
|
| 393 | - { |
|
| 394 | - $html = '<tbody id="obj_table_body">'; |
|
| 395 | - foreach($values as $value) |
|
| 396 | - { |
|
| 397 | - $html .= "<tr>\n"; |
|
| 398 | - $html .= $this->renderLine($value); |
|
| 399 | - $html .= "</tr>\n"; |
|
| 400 | - } |
|
| 401 | - $html .= '</tbody>'; |
|
| 402 | - return $html; |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - public function render() |
|
| 406 | - { |
|
| 407 | - $html = ''; |
|
| 358 | + return $html; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + public function applyPaging() |
|
| 362 | + { |
|
| 363 | + $this->query->limitPage($this->currentPage,$this->maxPerPage); |
|
| 364 | + return $this; |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + /*************** Rendering *************************/ |
|
| 368 | + public function renderTitles() |
|
| 369 | + { |
|
| 370 | + $html = "<thead>\n<tr>\n"; |
|
| 371 | + foreach ($this->titles as $values) |
|
| 372 | + { |
|
| 373 | + $html .= '<th>' . $values . '</th>'; |
|
| 374 | + } |
|
| 375 | + $html .= "</tr>\n</thead>\n"; |
|
| 376 | + return $html; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + public function renderLine( $value) |
|
| 380 | + { |
|
| 381 | + $html = ''; |
|
| 382 | + $titleNames = array_keys($this->titles); |
|
| 383 | + foreach ($titleNames as $name ) |
|
| 384 | + { |
|
| 385 | + $html .= '<td>'; |
|
| 386 | + $html .= $value->$name; |
|
| 387 | + $html .= "</td>\n"; |
|
| 388 | + } |
|
| 389 | + return $html; |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + public function renderTable(array $values) |
|
| 393 | + { |
|
| 394 | + $html = '<tbody id="obj_table_body">'; |
|
| 395 | + foreach($values as $value) |
|
| 396 | + { |
|
| 397 | + $html .= "<tr>\n"; |
|
| 398 | + $html .= $this->renderLine($value); |
|
| 399 | + $html .= "</tr>\n"; |
|
| 400 | + } |
|
| 401 | + $html .= '</tbody>'; |
|
| 402 | + return $html; |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + public function render() |
|
| 406 | + { |
|
| 407 | + $html = ''; |
|
| 408 | 408 | |
| 409 | 409 | |
| 410 | - $values = $this->fullQuery(); |
|
| 410 | + $values = $this->fullQuery(); |
|
| 411 | 411 | |
| 412 | - $html.="<table class='simple common-table table-row-selectable'>\n"; |
|
| 412 | + $html.="<table class='simple common-table table-row-selectable'>\n"; |
|
| 413 | 413 | |
| 414 | - $html .= $this->renderTitles(); |
|
| 415 | - $html .= $this->renderTable($values); |
|
| 416 | - $html .= '</table>'; |
|
| 414 | + $html .= $this->renderTitles(); |
|
| 415 | + $html .= $this->renderTable($values); |
|
| 416 | + $html .= '</table>'; |
|
| 417 | 417 | |
| 418 | 418 | |
| 419 | - return $html; |
|
| 420 | - } |
|
| 419 | + return $html; |
|
| 420 | + } |
|
| 421 | 421 | |
| 422 | 422 | } |
| 423 | 423 | \ No newline at end of file |
@@ -4,16 +4,16 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | class TrapModuleConfig |
| 6 | 6 | { |
| 7 | - /********** Database configuration ***********************/ |
|
| 7 | + /********** Database configuration ***********************/ |
|
| 8 | 8 | // Database prefix for tables |
| 9 | - protected $table_prefix; //< Database prefix for tables |
|
| 9 | + protected $table_prefix; //< Database prefix for tables |
|
| 10 | 10 | protected $DBConfigDefaults=array( |
| 11 | 11 | 'db_remove_days' => 60, // number of days before removing traps |
| 12 | 12 | 'log_destination' => 'syslog', // Log destination for trap handler |
| 13 | 13 | 'log_file' => '/tmp/trapdirector.log', // Log file |
| 14 | 14 | 'log_level' => 2, // log level |
| 15 | 15 | 'use_SnmpTrapAddess' => 1, // use SnmpTrapAddress by default |
| 16 | - 'SnmpTrapAddess_oid' => '.1.3.6.1.6.3.18.1.3', // default snmpTrapAdress OID |
|
| 16 | + 'SnmpTrapAddess_oid' => '.1.3.6.1.6.3.18.1.3', // default snmpTrapAdress OID |
|
| 17 | 17 | ); |
| 18 | 18 | // get default values for dbconfig |
| 19 | 19 | public function getDBConfigDefaults() { return $this->DBConfigDefaults;} |
@@ -120,27 +120,27 @@ discard block |
||
| 120 | 120 | // Note : must have 'source_ip' and 'last_sent' |
| 121 | 121 | public function getTrapHostListDisplayColumns() |
| 122 | 122 | { |
| 123 | - return array( |
|
| 124 | - 'source_name' => 't.source_name', |
|
| 125 | - 'source_ip' => 't.source_ip', |
|
| 126 | - 'trap_oid' => 't.trap_oid', |
|
| 127 | - 'count' => 'count(*)', |
|
| 128 | - 'last_sent' => 'UNIX_TIMESTAMP(max(t.date_received))' |
|
| 129 | - ); |
|
| 123 | + return array( |
|
| 124 | + 'source_name' => 't.source_name', |
|
| 125 | + 'source_ip' => 't.source_ip', |
|
| 126 | + 'trap_oid' => 't.trap_oid', |
|
| 127 | + 'count' => 'count(*)', |
|
| 128 | + 'last_sent' => 'UNIX_TIMESTAMP(max(t.date_received))' |
|
| 129 | + ); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | public function getTrapHostListSearchColumns() |
| 133 | 133 | { |
| 134 | - return array(); // No search needed on this table |
|
| 134 | + return array(); // No search needed on this table |
|
| 135 | 135 | } |
| 136 | 136 | // Titles display in Trap List table |
| 137 | 137 | public function getTrapHostListTitles() |
| 138 | 138 | { |
| 139 | - return array( |
|
| 140 | - 'trap_oid' => 'Trap OID', |
|
| 141 | - 'count' => 'Number of traps received', |
|
| 142 | - 'last_sent' => 'Last trap received' |
|
| 143 | - ); |
|
| 139 | + return array( |
|
| 140 | + 'trap_oid' => 'Trap OID', |
|
| 141 | + 'count' => 'Number of traps received', |
|
| 142 | + 'last_sent' => 'Last trap received' |
|
| 143 | + ); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | |
@@ -179,17 +179,17 @@ discard block |
||
| 179 | 179 | } |
| 180 | 180 | public function getHandlerColumns() |
| 181 | 181 | { |
| 182 | - return array( |
|
| 183 | - 'r.host_name', 'r.host_group_name', |
|
| 184 | - 'r.ip4', 'r.ip6', |
|
| 185 | - 'r.trap_oid', |
|
| 186 | - 'r.rule', |
|
| 187 | - 'r.action_match', |
|
| 188 | - 'r.action_nomatch', |
|
| 189 | - 'r.service_name', |
|
| 190 | - 'r.num_match', |
|
| 191 | - 'r.id' |
|
| 192 | - ); |
|
| 182 | + return array( |
|
| 183 | + 'r.host_name', 'r.host_group_name', |
|
| 184 | + 'r.ip4', 'r.ip6', |
|
| 185 | + 'r.trap_oid', |
|
| 186 | + 'r.rule', |
|
| 187 | + 'r.action_match', |
|
| 188 | + 'r.action_nomatch', |
|
| 189 | + 'r.service_name', |
|
| 190 | + 'r.num_match', |
|
| 191 | + 'r.id' |
|
| 192 | + ); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | // handler update (<key> => <sql select>) |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | 'revert_ok' => 'r.revert_ok', |
| 210 | 210 | 'display' => 'r.display', |
| 211 | 211 | 'modified' => 'UNIX_TIMESTAMP(r.modified)', |
| 212 | - 'modifier' => 'r.modifier' |
|
| 212 | + 'modifier' => 'r.modifier' |
|
| 213 | 213 | ); |
| 214 | 214 | } |
| 215 | 215 | |
@@ -12,13 +12,12 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | //use Icinga\Web\Form as Form; |
| 14 | 14 | /** Rules management |
| 15 | - |
|
| 16 | -*/ |
|
| 15 | + */ |
|
| 17 | 16 | class HandlerController extends TrapsController |
| 18 | 17 | { |
| 19 | 18 | |
| 20 | 19 | /** index : list existing rules |
| 21 | - */ |
|
| 20 | + */ |
|
| 22 | 21 | public function indexAction() |
| 23 | 22 | { |
| 24 | 23 | $this->checkReadPermission(); |
@@ -28,13 +27,13 @@ discard block |
||
| 28 | 27 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 29 | 28 | |
| 30 | 29 | $this->view->handlerTable = new HandlerTable( |
| 31 | - $this->moduleConfig->getTrapRuleName(), |
|
| 32 | - $this->moduleConfig->getHandlerListTitles(), |
|
| 33 | - $this->moduleConfig->getHandlerListDisplayColumns(), |
|
| 34 | - $this->moduleConfig->getHandlerColumns(), |
|
| 35 | - $dbConn->getConnection(), |
|
| 36 | - $this->view, |
|
| 37 | - $this->moduleConfig->urlPath()); |
|
| 30 | + $this->moduleConfig->getTrapRuleName(), |
|
| 31 | + $this->moduleConfig->getHandlerListTitles(), |
|
| 32 | + $this->moduleConfig->getHandlerListDisplayColumns(), |
|
| 33 | + $this->moduleConfig->getHandlerColumns(), |
|
| 34 | + $dbConn->getConnection(), |
|
| 35 | + $this->view, |
|
| 36 | + $this->moduleConfig->urlPath()); |
|
| 38 | 37 | |
| 39 | 38 | $getVars = $this->getRequest()->getParams(); |
| 40 | 39 | $this->view->handlerTable->getParams($getVars); |
@@ -60,22 +59,22 @@ discard block |
||
| 60 | 59 | */ |
| 61 | 60 | public function testruleAction() |
| 62 | 61 | { |
| 63 | - $this->checkReadPermission(); |
|
| 64 | - $this->getTabs()->add('get',array( |
|
| 65 | - 'active' => true, |
|
| 66 | - 'label' => $this->translate('Test Rule'), |
|
| 67 | - 'url' => Url::fromRequest() |
|
| 68 | - )); |
|
| 62 | + $this->checkReadPermission(); |
|
| 63 | + $this->getTabs()->add('get',array( |
|
| 64 | + 'active' => true, |
|
| 65 | + 'label' => $this->translate('Test Rule'), |
|
| 66 | + 'url' => Url::fromRequest() |
|
| 67 | + )); |
|
| 69 | 68 | |
| 70 | 69 | |
| 71 | - if ($this->params->get('rule') !== null) |
|
| 72 | - { |
|
| 73 | - $this->view->rule= $this->params->get('rule'); |
|
| 74 | - } |
|
| 75 | - else |
|
| 76 | - { |
|
| 77 | - $this->view->rule=''; |
|
| 78 | - } |
|
| 70 | + if ($this->params->get('rule') !== null) |
|
| 71 | + { |
|
| 72 | + $this->view->rule= $this->params->get('rule'); |
|
| 73 | + } |
|
| 74 | + else |
|
| 75 | + { |
|
| 76 | + $this->view->rule=''; |
|
| 77 | + } |
|
| 79 | 78 | } |
| 80 | 79 | |
| 81 | 80 | /** |
@@ -83,31 +82,31 @@ discard block |
||
| 83 | 82 | */ |
| 84 | 83 | private function add_setup_vars() |
| 85 | 84 | { |
| 86 | - // variables to send to view |
|
| 87 | - $this->view->hostlist=array(); // host list to input datalist |
|
| 88 | - $this->view->hostname=''; // Host name in input text |
|
| 89 | - $this->view->serviceGet=false; // Set to true to get list of service if only one host set |
|
| 90 | - $this->view->serviceSet=null; // Select service in services select (must have serviceGet=true). |
|
| 91 | - $this->view->mainoid=''; // Trap OID |
|
| 92 | - $this->view->mib=''; // Trap mib |
|
| 93 | - $this->view->name=''; // Trap name |
|
| 94 | - $this->view->trapListForMIB=array(); // Trap list if mib exists for trap |
|
| 95 | - $this->view->objectList=array(); // objects sent with trap |
|
| 96 | - $this->view->display=''; // Initial display |
|
| 97 | - $this->view->rule=''; // rule display |
|
| 98 | - $this->view->revertOK=''; // revert OK in seconds |
|
| 99 | - $this->view->hostid=-1; // normally set by javascript serviceGet() |
|
| 100 | - $this->view->ruleid=-1; // Rule id in DB for update & delete |
|
| 101 | - $this->view->setToUpdate=false; // set form as update form |
|
| 102 | - $this->view->setRuleMatch=-1; // set action on rule match (default nothing) |
|
| 103 | - $this->view->setRuleNoMatch=-1; // set action on rule no match (default nothing) |
|
| 85 | + // variables to send to view |
|
| 86 | + $this->view->hostlist=array(); // host list to input datalist |
|
| 87 | + $this->view->hostname=''; // Host name in input text |
|
| 88 | + $this->view->serviceGet=false; // Set to true to get list of service if only one host set |
|
| 89 | + $this->view->serviceSet=null; // Select service in services select (must have serviceGet=true). |
|
| 90 | + $this->view->mainoid=''; // Trap OID |
|
| 91 | + $this->view->mib=''; // Trap mib |
|
| 92 | + $this->view->name=''; // Trap name |
|
| 93 | + $this->view->trapListForMIB=array(); // Trap list if mib exists for trap |
|
| 94 | + $this->view->objectList=array(); // objects sent with trap |
|
| 95 | + $this->view->display=''; // Initial display |
|
| 96 | + $this->view->rule=''; // rule display |
|
| 97 | + $this->view->revertOK=''; // revert OK in seconds |
|
| 98 | + $this->view->hostid=-1; // normally set by javascript serviceGet() |
|
| 99 | + $this->view->ruleid=-1; // Rule id in DB for update & delete |
|
| 100 | + $this->view->setToUpdate=false; // set form as update form |
|
| 101 | + $this->view->setRuleMatch=-1; // set action on rule match (default nothing) |
|
| 102 | + $this->view->setRuleNoMatch=-1; // set action on rule no match (default nothing) |
|
| 104 | 103 | |
| 105 | - $this->view->selectGroup=false; // Select by group if true |
|
| 106 | - $this->view->hostgroupid=-1; // host group id |
|
| 107 | - $this->view->serviceGroupGet=false; // Get list of service for group (set serviceSet to select one) |
|
| 104 | + $this->view->selectGroup=false; // Select by group if true |
|
| 105 | + $this->view->hostgroupid=-1; // host group id |
|
| 106 | + $this->view->serviceGroupGet=false; // Get list of service for group (set serviceSet to select one) |
|
| 108 | 107 | |
| 109 | - $this->view->modifier=null; |
|
| 110 | - $this->view->modified=null; |
|
| 108 | + $this->view->modifier=null; |
|
| 109 | + $this->view->modified=null; |
|
| 111 | 110 | } |
| 112 | 111 | |
| 113 | 112 | /** |
@@ -116,102 +115,102 @@ discard block |
||
| 116 | 115 | */ |
| 117 | 116 | private function add_from_existing($trapid) |
| 118 | 117 | { |
| 119 | - /********** Setup from existing trap ***************/ |
|
| 120 | - // Get the full trap info |
|
| 121 | - $trapDetail=$this->getTrapDetail($trapid); |
|
| 118 | + /********** Setup from existing trap ***************/ |
|
| 119 | + // Get the full trap info |
|
| 120 | + $trapDetail=$this->getTrapDetail($trapid); |
|
| 122 | 121 | |
| 123 | - $hostfilter=$trapDetail->source_ip; |
|
| 122 | + $hostfilter=$trapDetail->source_ip; |
|
| 124 | 123 | |
| 125 | - // Get host |
|
| 126 | - try |
|
| 127 | - { |
|
| 128 | - $hosts=$this->getUIDatabase()->getHostByIP($hostfilter); |
|
| 129 | - } |
|
| 130 | - catch (Exception $e) |
|
| 131 | - { |
|
| 132 | - $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage()); |
|
| 133 | - } |
|
| 124 | + // Get host |
|
| 125 | + try |
|
| 126 | + { |
|
| 127 | + $hosts=$this->getUIDatabase()->getHostByIP($hostfilter); |
|
| 128 | + } |
|
| 129 | + catch (Exception $e) |
|
| 130 | + { |
|
| 131 | + $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage()); |
|
| 132 | + } |
|
| 134 | 133 | |
| 135 | 134 | |
| 136 | - // if one unique host found -> put id text input |
|
| 137 | - if (count($hosts)==1) { |
|
| 138 | - $this->view->hostname=$hosts[0]->name; |
|
| 139 | - //$hostid=$hosts[0]->id; |
|
| 140 | - // Tell JS to get services when page is loaded |
|
| 141 | - $this->view->serviceGet=true; |
|
| 135 | + // if one unique host found -> put id text input |
|
| 136 | + if (count($hosts)==1) { |
|
| 137 | + $this->view->hostname=$hosts[0]->name; |
|
| 138 | + //$hostid=$hosts[0]->id; |
|
| 139 | + // Tell JS to get services when page is loaded |
|
| 140 | + $this->view->serviceGet=true; |
|
| 142 | 141 | |
| 143 | - } |
|
| 144 | - else |
|
| 145 | - { |
|
| 146 | - foreach($hosts as $key=>$val) |
|
| 147 | - { |
|
| 148 | - array_push($this->view->hostlist,$hosts[$key]->name); |
|
| 149 | - } |
|
| 150 | - } |
|
| 142 | + } |
|
| 143 | + else |
|
| 144 | + { |
|
| 145 | + foreach($hosts as $key=>$val) |
|
| 146 | + { |
|
| 147 | + array_push($this->view->hostlist,$hosts[$key]->name); |
|
| 148 | + } |
|
| 149 | + } |
|
| 151 | 150 | |
| 152 | - // set up trap oid and objects received by the trap |
|
| 151 | + // set up trap oid and objects received by the trap |
|
| 153 | 152 | |
| 154 | - $this->view->mainoid=$trapDetail->trap_oid; |
|
| 155 | - if ($trapDetail->trap_name_mib != null) |
|
| 156 | - { |
|
| 157 | - $this->view->mib=$trapDetail->trap_name_mib; |
|
| 158 | - $this->view->name=$trapDetail->trap_name; |
|
| 159 | - $this->view->trapListForMIB=$this->getMIB() |
|
| 160 | - ->getTrapList($trapDetail->trap_name_mib); |
|
| 161 | - } |
|
| 153 | + $this->view->mainoid=$trapDetail->trap_oid; |
|
| 154 | + if ($trapDetail->trap_name_mib != null) |
|
| 155 | + { |
|
| 156 | + $this->view->mib=$trapDetail->trap_name_mib; |
|
| 157 | + $this->view->name=$trapDetail->trap_name; |
|
| 158 | + $this->view->trapListForMIB=$this->getMIB() |
|
| 159 | + ->getTrapList($trapDetail->trap_name_mib); |
|
| 160 | + } |
|
| 162 | 161 | |
| 163 | - // Get all objects that can be in trap from MIB |
|
| 164 | - $allObjects=$this->getMIB()->getObjectList($trapDetail->trap_oid); |
|
| 165 | - // Get all objects in current Trap |
|
| 166 | - $currentTrapObjects=$this->getTrapobjects($trapid); |
|
| 167 | - $oid_index=1; |
|
| 168 | - foreach ($currentTrapObjects as $key => $val) |
|
| 169 | - { |
|
| 170 | - $currentObjectType='Unknown'; |
|
| 171 | - $currentObjectTypeEnum='Unknown'; |
|
| 172 | - if (isset($allObjects[$val->oid]['type'])) |
|
| 173 | - { |
|
| 174 | - $currentObjectType=$allObjects[$val->oid]['type']; |
|
| 175 | - $currentObjectTypeEnum=$allObjects[$val->oid]['type_enum']; |
|
| 176 | - } |
|
| 177 | - $currentObject=array( |
|
| 178 | - $oid_index, |
|
| 179 | - $val->oid, |
|
| 180 | - $val->oid_name_mib, |
|
| 181 | - $val->oid_name, |
|
| 182 | - $val->value, |
|
| 183 | - $currentObjectType, |
|
| 184 | - $currentObjectTypeEnum |
|
| 185 | - ); |
|
| 186 | - $oid_index++; |
|
| 187 | - array_push($this->view->objectList,$currentObject); |
|
| 188 | - // set currrent object to null in allObjects |
|
| 189 | - if (isset($allObjects[$val->oid])) |
|
| 190 | - { |
|
| 191 | - $allObjects[$val->oid]=null; |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - if ($allObjects!=null) // in case trap doesn't have objects or is not resolved |
|
| 195 | - { |
|
| 196 | - foreach ($allObjects as $key => $val) |
|
| 197 | - { |
|
| 198 | - if ($val==null) { continue; } |
|
| 199 | - array_push($this->view->objectList, array( |
|
| 200 | - $oid_index, |
|
| 201 | - $key, |
|
| 202 | - $allObjects[$key]['mib'], |
|
| 203 | - $allObjects[$key]['name'], |
|
| 204 | - '', |
|
| 205 | - $allObjects[$key]['type'], |
|
| 206 | - $allObjects[$key]['type_enum'] |
|
| 207 | - )); |
|
| 208 | - $oid_index++; |
|
| 209 | - } |
|
| 210 | - } |
|
| 162 | + // Get all objects that can be in trap from MIB |
|
| 163 | + $allObjects=$this->getMIB()->getObjectList($trapDetail->trap_oid); |
|
| 164 | + // Get all objects in current Trap |
|
| 165 | + $currentTrapObjects=$this->getTrapobjects($trapid); |
|
| 166 | + $oid_index=1; |
|
| 167 | + foreach ($currentTrapObjects as $key => $val) |
|
| 168 | + { |
|
| 169 | + $currentObjectType='Unknown'; |
|
| 170 | + $currentObjectTypeEnum='Unknown'; |
|
| 171 | + if (isset($allObjects[$val->oid]['type'])) |
|
| 172 | + { |
|
| 173 | + $currentObjectType=$allObjects[$val->oid]['type']; |
|
| 174 | + $currentObjectTypeEnum=$allObjects[$val->oid]['type_enum']; |
|
| 175 | + } |
|
| 176 | + $currentObject=array( |
|
| 177 | + $oid_index, |
|
| 178 | + $val->oid, |
|
| 179 | + $val->oid_name_mib, |
|
| 180 | + $val->oid_name, |
|
| 181 | + $val->value, |
|
| 182 | + $currentObjectType, |
|
| 183 | + $currentObjectTypeEnum |
|
| 184 | + ); |
|
| 185 | + $oid_index++; |
|
| 186 | + array_push($this->view->objectList,$currentObject); |
|
| 187 | + // set currrent object to null in allObjects |
|
| 188 | + if (isset($allObjects[$val->oid])) |
|
| 189 | + { |
|
| 190 | + $allObjects[$val->oid]=null; |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + if ($allObjects!=null) // in case trap doesn't have objects or is not resolved |
|
| 194 | + { |
|
| 195 | + foreach ($allObjects as $key => $val) |
|
| 196 | + { |
|
| 197 | + if ($val==null) { continue; } |
|
| 198 | + array_push($this->view->objectList, array( |
|
| 199 | + $oid_index, |
|
| 200 | + $key, |
|
| 201 | + $allObjects[$key]['mib'], |
|
| 202 | + $allObjects[$key]['name'], |
|
| 203 | + '', |
|
| 204 | + $allObjects[$key]['type'], |
|
| 205 | + $allObjects[$key]['type_enum'] |
|
| 206 | + )); |
|
| 207 | + $oid_index++; |
|
| 208 | + } |
|
| 209 | + } |
|
| 211 | 210 | |
| 212 | - // Add a simple display |
|
| 213 | - $this->view->display='Trap '.$trapDetail->trap_name.' received'; |
|
| 214 | - $this->view->create_basic_rule=true; |
|
| 211 | + // Add a simple display |
|
| 212 | + $this->view->display='Trap '.$trapDetail->trap_name.' received'; |
|
| 213 | + $this->view->create_basic_rule=true; |
|
| 215 | 214 | } |
| 216 | 215 | |
| 217 | 216 | /** |
@@ -220,29 +219,29 @@ discard block |
||
| 220 | 219 | */ |
| 221 | 220 | private function add_check_host_exists($ruleDetail) |
| 222 | 221 | { |
| 223 | - // Check if hostname still exists |
|
| 224 | - $host_get=$this->getUIDatabase()->getHostByName($this->view->hostname); |
|
| 222 | + // Check if hostname still exists |
|
| 223 | + $host_get=$this->getUIDatabase()->getHostByName($this->view->hostname); |
|
| 225 | 224 | |
| 226 | - if (count($host_get)==0) |
|
| 227 | - { |
|
| 228 | - $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore'; |
|
| 229 | - $this->view->serviceGet=false; |
|
| 230 | - } |
|
| 231 | - else |
|
| 232 | - { |
|
| 233 | - // Tell JS to get services when page is loaded |
|
| 234 | - $this->view->serviceGet=true; |
|
| 235 | - // get service id for form to set : |
|
| 236 | - $serviceID=$this->getUIDatabase()->getServiceIDByName($this->view->hostname,$ruleDetail->service_name); |
|
| 237 | - if (count($serviceID) ==0) |
|
| 238 | - { |
|
| 239 | - $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
| 240 | - } |
|
| 241 | - else |
|
| 242 | - { |
|
| 243 | - $this->view->serviceSet=$serviceID[0]->id; |
|
| 244 | - } |
|
| 245 | - } |
|
| 225 | + if (count($host_get)==0) |
|
| 226 | + { |
|
| 227 | + $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore'; |
|
| 228 | + $this->view->serviceGet=false; |
|
| 229 | + } |
|
| 230 | + else |
|
| 231 | + { |
|
| 232 | + // Tell JS to get services when page is loaded |
|
| 233 | + $this->view->serviceGet=true; |
|
| 234 | + // get service id for form to set : |
|
| 235 | + $serviceID=$this->getUIDatabase()->getServiceIDByName($this->view->hostname,$ruleDetail->service_name); |
|
| 236 | + if (count($serviceID) ==0) |
|
| 237 | + { |
|
| 238 | + $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
| 239 | + } |
|
| 240 | + else |
|
| 241 | + { |
|
| 242 | + $this->view->serviceSet=$serviceID[0]->id; |
|
| 243 | + } |
|
| 244 | + } |
|
| 246 | 245 | } |
| 247 | 246 | |
| 248 | 247 | /** |
@@ -251,33 +250,33 @@ discard block |
||
| 251 | 250 | */ |
| 252 | 251 | private function add_check_hostgroup_exists($ruleDetail) |
| 253 | 252 | { |
| 254 | - // Check if groupe exists |
|
| 255 | - $group_get=$this->getUIDatabase()->getHostGroupByName($this->view->hostgroupname); |
|
| 256 | - if (count($group_get)==0) |
|
| 257 | - { |
|
| 258 | - $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore'; |
|
| 259 | - $this->view->serviceGroupGet=false; |
|
| 260 | - } |
|
| 261 | - else |
|
| 262 | - { |
|
| 263 | - $grpServices=$this->getUIDatabase()->getServicesByHostGroupid($group_get[0]->id); |
|
| 264 | - $foundGrpService=0; |
|
| 265 | - foreach ($grpServices as $grpService) |
|
| 266 | - { |
|
| 267 | - if ($grpService[0] == $ruleDetail->service_name) |
|
| 268 | - { |
|
| 269 | - $foundGrpService=1; |
|
| 270 | - $this->view->serviceSet=$ruleDetail->service_name; |
|
| 271 | - } |
|
| 272 | - } |
|
| 253 | + // Check if groupe exists |
|
| 254 | + $group_get=$this->getUIDatabase()->getHostGroupByName($this->view->hostgroupname); |
|
| 255 | + if (count($group_get)==0) |
|
| 256 | + { |
|
| 257 | + $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore'; |
|
| 258 | + $this->view->serviceGroupGet=false; |
|
| 259 | + } |
|
| 260 | + else |
|
| 261 | + { |
|
| 262 | + $grpServices=$this->getUIDatabase()->getServicesByHostGroupid($group_get[0]->id); |
|
| 263 | + $foundGrpService=0; |
|
| 264 | + foreach ($grpServices as $grpService) |
|
| 265 | + { |
|
| 266 | + if ($grpService[0] == $ruleDetail->service_name) |
|
| 267 | + { |
|
| 268 | + $foundGrpService=1; |
|
| 269 | + $this->view->serviceSet=$ruleDetail->service_name; |
|
| 270 | + } |
|
| 271 | + } |
|
| 273 | 272 | |
| 274 | - // Tell JS to get services when page is loaded |
|
| 275 | - $this->view->serviceGroupGet=true; |
|
| 276 | - if ($foundGrpService==0) |
|
| 277 | - { |
|
| 278 | - $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
| 279 | - } |
|
| 280 | - } |
|
| 273 | + // Tell JS to get services when page is loaded |
|
| 274 | + $this->view->serviceGroupGet=true; |
|
| 275 | + if ($foundGrpService==0) |
|
| 276 | + { |
|
| 277 | + $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
| 278 | + } |
|
| 279 | + } |
|
| 281 | 280 | } |
| 282 | 281 | |
| 283 | 282 | /** |
@@ -289,52 +288,52 @@ discard block |
||
| 289 | 288 | */ |
| 290 | 289 | private function add_create_trap_object_list(&$display, &$rule) |
| 291 | 290 | { |
| 292 | - $curObjectList=array(); |
|
| 293 | - $index=1; |
|
| 294 | - // check in display & rule for : OID(<oid>) |
|
| 295 | - $matches=array(); |
|
| 296 | - while ( preg_match('/_OID\(([\.0-9\*]+)\)/',$display,$matches) || |
|
| 297 | - preg_match('/_OID\(([\.0-9\*]+)\)/',$rule,$matches)) |
|
| 298 | - { |
|
| 299 | - $curOid=$matches[1]; |
|
| 291 | + $curObjectList=array(); |
|
| 292 | + $index=1; |
|
| 293 | + // check in display & rule for : OID(<oid>) |
|
| 294 | + $matches=array(); |
|
| 295 | + while ( preg_match('/_OID\(([\.0-9\*]+)\)/',$display,$matches) || |
|
| 296 | + preg_match('/_OID\(([\.0-9\*]+)\)/',$rule,$matches)) |
|
| 297 | + { |
|
| 298 | + $curOid=$matches[1]; |
|
| 300 | 299 | |
| 301 | - if ( (preg_match('/\*/',$curOid) == 0 ) |
|
| 302 | - && ($object=$this->getMIB()->translateOID($curOid)) != null) |
|
| 303 | - { |
|
| 304 | - array_push($curObjectList, array( |
|
| 305 | - $index, |
|
| 306 | - $curOid, |
|
| 307 | - $object['mib'], |
|
| 308 | - $object['name'], |
|
| 309 | - '', |
|
| 310 | - $object['type'], |
|
| 311 | - $object['type_enum'] |
|
| 312 | - )); |
|
| 313 | - } |
|
| 314 | - else |
|
| 315 | - { |
|
| 316 | - array_push($curObjectList, array( |
|
| 317 | - $index, |
|
| 318 | - $curOid, |
|
| 319 | - 'not found', |
|
| 320 | - 'not found', |
|
| 321 | - '', |
|
| 322 | - 'not found', |
|
| 323 | - 'not found' |
|
| 324 | - )); |
|
| 325 | - } |
|
| 326 | - $curOid = preg_replace('/\*/','\*',$curOid); |
|
| 327 | - $display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display); |
|
| 328 | - $rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule); |
|
| 329 | - $index++; |
|
| 330 | - } |
|
| 331 | - return $curObjectList; |
|
| 300 | + if ( (preg_match('/\*/',$curOid) == 0 ) |
|
| 301 | + && ($object=$this->getMIB()->translateOID($curOid)) != null) |
|
| 302 | + { |
|
| 303 | + array_push($curObjectList, array( |
|
| 304 | + $index, |
|
| 305 | + $curOid, |
|
| 306 | + $object['mib'], |
|
| 307 | + $object['name'], |
|
| 308 | + '', |
|
| 309 | + $object['type'], |
|
| 310 | + $object['type_enum'] |
|
| 311 | + )); |
|
| 312 | + } |
|
| 313 | + else |
|
| 314 | + { |
|
| 315 | + array_push($curObjectList, array( |
|
| 316 | + $index, |
|
| 317 | + $curOid, |
|
| 318 | + 'not found', |
|
| 319 | + 'not found', |
|
| 320 | + '', |
|
| 321 | + 'not found', |
|
| 322 | + 'not found' |
|
| 323 | + )); |
|
| 324 | + } |
|
| 325 | + $curOid = preg_replace('/\*/','\*',$curOid); |
|
| 326 | + $display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display); |
|
| 327 | + $rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule); |
|
| 328 | + $index++; |
|
| 329 | + } |
|
| 330 | + return $curObjectList; |
|
| 332 | 331 | } |
| 333 | 332 | |
| 334 | 333 | /** Add a handler |
| 335 | - * Get params fromid : setup from existing trap (id of trap table) |
|
| 336 | - * Get param ruleid : edit from existing handler (id of rule table) |
|
| 337 | - */ |
|
| 334 | + * Get params fromid : setup from existing trap (id of trap table) |
|
| 335 | + * Get param ruleid : edit from existing handler (id of rule table) |
|
| 336 | + */ |
|
| 338 | 337 | public function addAction() |
| 339 | 338 | { |
| 340 | 339 | $this->checkConfigPermission(); |
@@ -354,8 +353,8 @@ discard block |
||
| 354 | 353 | //$this->view->trapvalues=false; // Set to true to display 'value' colum in objects |
| 355 | 354 | |
| 356 | 355 | if (($trapid = $this->params->get('fromid')) !== null) { |
| 357 | - /********** Setup from existing trap ***************/ |
|
| 358 | - $this->add_from_existing($trapid); |
|
| 356 | + /********** Setup from existing trap ***************/ |
|
| 357 | + $this->add_from_existing($trapid); |
|
| 359 | 358 | return; |
| 360 | 359 | } |
| 361 | 360 | |
@@ -380,14 +379,14 @@ discard block |
||
| 380 | 379 | $this->view->warning_message=''; |
| 381 | 380 | if ($this->view->hostname != null) |
| 382 | 381 | { |
| 383 | - $this->view->selectGroup=false; |
|
| 384 | - // Check if hostname still exists |
|
| 385 | - $this->add_check_host_exists($ruleDetail); |
|
| 382 | + $this->view->selectGroup=false; |
|
| 383 | + // Check if hostname still exists |
|
| 384 | + $this->add_check_host_exists($ruleDetail); |
|
| 386 | 385 | } |
| 387 | 386 | else |
| 388 | 387 | { |
| 389 | - $this->view->selectGroup=true; |
|
| 390 | - $this->add_check_hostgroup_exists($ruleDetail); // Check if groupe exists |
|
| 388 | + $this->view->selectGroup=true; |
|
| 389 | + $this->add_check_hostgroup_exists($ruleDetail); // Check if groupe exists |
|
| 391 | 390 | } |
| 392 | 391 | |
| 393 | 392 | $this->view->mainoid=$ruleDetail->trap_oid; |
@@ -415,9 +414,9 @@ discard block |
||
| 415 | 414 | } |
| 416 | 415 | |
| 417 | 416 | /** Validate form and output message to user |
| 418 | - * @param in postdata |
|
| 419 | - * @return string status : OK / <Message> |
|
| 420 | - **/ |
|
| 417 | + * @param in postdata |
|
| 418 | + * @return string status : OK / <Message> |
|
| 419 | + **/ |
|
| 421 | 420 | protected function handlerformAction() |
| 422 | 421 | { |
| 423 | 422 | $postData=$this->getRequest()->getPost(); |
@@ -440,7 +439,7 @@ discard block |
||
| 440 | 439 | 'action_nomatch'=> array('post' => 'ruleNoMatch', 'val' => -1, 'db'=>true), |
| 441 | 440 | 'ip4' => array('post' => null, 'val' => null, 'db'=>true), |
| 442 | 441 | 'ip6' => array('post' => null, 'val' => null, 'db'=>true), |
| 443 | - 'action_form' => array('post' => 'action_form', 'val' => null, 'db'=>false) |
|
| 442 | + 'action_form' => array('post' => 'action_form', 'val' => null, 'db'=>false) |
|
| 444 | 443 | ); |
| 445 | 444 | |
| 446 | 445 | if (isset($postData[$params['action_form']['post']]) |
@@ -448,7 +447,7 @@ discard block |
||
| 448 | 447 | { |
| 449 | 448 | try |
| 450 | 449 | { |
| 451 | - $this->getUIDatabase()->deleteRule($postData[$params['db_rule']['post']]); |
|
| 450 | + $this->getUIDatabase()->deleteRule($postData[$params['db_rule']['post']]); |
|
| 452 | 451 | } |
| 453 | 452 | catch (Exception $e) |
| 454 | 453 | { |
@@ -458,7 +457,7 @@ discard block |
||
| 458 | 457 | //$this->Module()-> |
| 459 | 458 | $this->_helper->json(array( |
| 460 | 459 | 'status'=>'OK', |
| 461 | - 'redirect'=>'trapdirector/handler' |
|
| 460 | + 'redirect'=>'trapdirector/handler' |
|
| 462 | 461 | |
| 463 | 462 | )); |
| 464 | 463 | } |
@@ -485,7 +484,7 @@ discard block |
||
| 485 | 484 | $isHostGroup=($params['hostgroup']['val'] == 1)?true:false; |
| 486 | 485 | if (! $isHostGroup ) |
| 487 | 486 | { // checks if selection by host |
| 488 | - $hostAddr=$this->getUIDatabase()->getHostInfoByID($params['hostid']['val']); |
|
| 487 | + $hostAddr=$this->getUIDatabase()->getHostInfoByID($params['hostid']['val']); |
|
| 489 | 488 | $params['ip4']['val']=$hostAddr->ip4; |
| 490 | 489 | $params['ip6']['val']=$hostAddr->ip6; |
| 491 | 490 | $checkHostName=$hostAddr->name; |
@@ -496,8 +495,8 @@ discard block |
||
| 496 | 495 | } |
| 497 | 496 | if (!is_numeric($params['serviceid']['val'])) |
| 498 | 497 | { |
| 499 | - $this->_helper->json(array('status'=>"Invalid service id ". $params['serviceid']['val'])); |
|
| 500 | - return; |
|
| 498 | + $this->_helper->json(array('status'=>"Invalid service id ". $params['serviceid']['val'])); |
|
| 499 | + return; |
|
| 501 | 500 | } |
| 502 | 501 | $serviceName=$this->getUIDatabase()->getObjectNameByid($params['serviceid']['val']); |
| 503 | 502 | if ($params['service_name']['val'] != $serviceName->name2) |
@@ -508,7 +507,7 @@ discard block |
||
| 508 | 507 | } |
| 509 | 508 | else |
| 510 | 509 | { |
| 511 | - $object=$this->getUIDatabase()->getObjectNameByid($params['hostid']['val']); |
|
| 510 | + $object=$this->getUIDatabase()->getObjectNameByid($params['hostid']['val']); |
|
| 512 | 511 | if ($params['host_name']['val'] != $object->name1) |
| 513 | 512 | { |
| 514 | 513 | $this->_helper->json(array('status'=>"Invalid object group id : Please re enter service")); |
@@ -530,11 +529,11 @@ discard block |
||
| 530 | 529 | |
| 531 | 530 | if ($params['db_rule']['val'] == -1 || $params['action_form']['val'] == 'clone') |
| 532 | 531 | { // If no rule number or action is clone, add the handler |
| 533 | - $ruleID=$this->getUIDatabase()->addHandlerRule($dbparams); |
|
| 532 | + $ruleID=$this->getUIDatabase()->addHandlerRule($dbparams); |
|
| 534 | 533 | } |
| 535 | 534 | else |
| 536 | 535 | { |
| 537 | - $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']); |
|
| 536 | + $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']); |
|
| 538 | 537 | $ruleID=$params['db_rule']['val']; |
| 539 | 538 | } |
| 540 | 539 | } |
@@ -548,9 +547,9 @@ discard block |
||
| 548 | 547 | } |
| 549 | 548 | |
| 550 | 549 | /** Get trap detail by trapid. |
| 551 | - * @param integer $trapid : id of trap in received table |
|
| 552 | - * @return array (objects) |
|
| 553 | - */ |
|
| 550 | + * @param integer $trapid : id of trap in received table |
|
| 551 | + * @return array (objects) |
|
| 552 | + */ |
|
| 554 | 553 | protected function getTrapDetail($trapid) |
| 555 | 554 | { |
| 556 | 555 | if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id'); } |
@@ -566,14 +565,14 @@ discard block |
||
| 566 | 565 | } |
| 567 | 566 | try |
| 568 | 567 | { |
| 569 | - $query = $dbConn->select() |
|
| 568 | + $query = $dbConn->select() |
|
| 570 | 569 | ->from($this->getModuleConfig()->getTrapTableName(),$elmts) |
| 571 | 570 | ->where('id=?',$trapid); |
| 572 | 571 | $trapDetail=$dbConn->fetchRow($query); |
| 573 | 572 | if ( $trapDetail == null ) |
| 574 | 573 | { |
| 575 | - $trapDetail = 'NULL'; |
|
| 576 | - throw new Exception('No traps was found with id = '.$trapid); |
|
| 574 | + $trapDetail = 'NULL'; |
|
| 575 | + throw new Exception('No traps was found with id = '.$trapid); |
|
| 577 | 576 | } |
| 578 | 577 | } |
| 579 | 578 | catch (Exception $e) |
@@ -587,9 +586,9 @@ discard block |
||
| 587 | 586 | } |
| 588 | 587 | |
| 589 | 588 | /** Get trap objects |
| 590 | - * @param integer $trapid : trap id |
|
| 591 | - * @return array : full column in db of trap id |
|
| 592 | - */ |
|
| 589 | + * @param integer $trapid : trap id |
|
| 590 | + * @return array : full column in db of trap id |
|
| 591 | + */ |
|
| 593 | 592 | protected function getTrapobjects($trapid) |
| 594 | 593 | { |
| 595 | 594 | if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id'); } |
@@ -605,7 +604,7 @@ discard block |
||
| 605 | 604 | } |
| 606 | 605 | try |
| 607 | 606 | { |
| 608 | - $query = $dbConn->select() |
|
| 607 | + $query = $dbConn->select() |
|
| 609 | 608 | ->from($this->moduleConfig->getTrapDataTableName(),$data_elmts) |
| 610 | 609 | ->where('trap_id=?',$trapid); |
| 611 | 610 | $trapDetail=$dbConn->fetchAll($query); |
@@ -621,10 +620,10 @@ discard block |
||
| 621 | 620 | } |
| 622 | 621 | |
| 623 | 622 | /** Get rule detail by ruleid. |
| 624 | - * @param integer $ruleid int id of rule in rule table |
|
| 625 | - * @return object|array : column objects in db |
|
| 626 | - * |
|
| 627 | - */ |
|
| 623 | + * @param integer $ruleid int id of rule in rule table |
|
| 624 | + * @return object|array : column objects in db |
|
| 625 | + * |
|
| 626 | + */ |
|
| 628 | 627 | protected function getRuleDetail($ruleid) |
| 629 | 628 | { |
| 630 | 629 | if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id'); } |
@@ -635,7 +634,7 @@ discard block |
||
| 635 | 634 | // *************** Get main data |
| 636 | 635 | try |
| 637 | 636 | { |
| 638 | - $query = $dbConn->select() |
|
| 637 | + $query = $dbConn->select() |
|
| 639 | 638 | ->from($this->getModuleConfig()->getTrapRuleName(),$queryArray) |
| 640 | 639 | ->where('id=?',$ruleid); |
| 641 | 640 | $ruleDetail=$dbConn->fetchRow($query); |
@@ -652,7 +651,7 @@ discard block |
||
| 652 | 651 | } |
| 653 | 652 | |
| 654 | 653 | /** Setup tabs for rules |
| 655 | - */ |
|
| 654 | + */ |
|
| 656 | 655 | protected function prepareTabs() |
| 657 | 656 | { |
| 658 | 657 | return $this->getTabs()->add('status', array( |