@@ -8,10 +8,10 @@ discard block |
||
8 | 8 | |
9 | 9 | /********* Filter ********/ |
10 | 10 | /** @var string $filterString : string filter for db columns */ |
11 | - protected $filterString = ''; |
|
11 | + protected $filterString=''; |
|
12 | 12 | |
13 | 13 | /** @var array $filterColumn : columns to apply filter to */ |
14 | - protected $filterColumn = array(); |
|
14 | + protected $filterColumn=array(); |
|
15 | 15 | |
16 | 16 | protected $filterQuery=''; |
17 | 17 | |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | { |
30 | 30 | if ($filter != "") $filter.=' OR '; |
31 | 31 | //$filter .= "'" . $column . "' LIKE '%" . $this->filterString. "%'"; |
32 | - $filter .= $column . " LIKE '%" . $this->filterString. "%'"; |
|
32 | + $filter.=$column." LIKE '%".$this->filterString."%'"; |
|
33 | 33 | } |
34 | 34 | //echo $filter; |
35 | 35 | |
@@ -40,8 +40,8 @@ discard block |
||
40 | 40 | |
41 | 41 | public function setFilter(string $filter, array $filterCol) |
42 | 42 | { |
43 | - $this->filterString = $filter; |
|
44 | - $this->filterColumn = $filterCol; |
|
43 | + $this->filterString=$filter; |
|
44 | + $this->filterColumn=$filterCol; |
|
45 | 45 | return $this; |
46 | 46 | } |
47 | 47 | |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | { |
64 | 64 | if (isset($getVars['f'])) |
65 | 65 | { |
66 | - $this->filterQuery = $getVars['f']; |
|
66 | + $this->filterQuery=$getVars['f']; |
|
67 | 67 | $this->setFilter(html_entity_decode($getVars['f']), $this->columnNames); |
68 | 68 | } |
69 | 69 | } |
@@ -27,7 +27,9 @@ discard block |
||
27 | 27 | $filter=''; |
28 | 28 | foreach ($this->filterColumn as $column) |
29 | 29 | { |
30 | - if ($filter != "") $filter.=' OR '; |
|
30 | + if ($filter != "") { |
|
31 | + $filter.=' OR '; |
|
32 | + } |
|
31 | 33 | //$filter .= "'" . $column . "' LIKE '%" . $this->filterString. "%'"; |
32 | 34 | $filter .= $column . " LIKE '%" . $this->filterString. "%'"; |
33 | 35 | } |
@@ -70,7 +72,9 @@ discard block |
||
70 | 72 | |
71 | 73 | protected function curFilterQuery() |
72 | 74 | { |
73 | - if ($this->filterQuery == '') return ''; |
|
75 | + if ($this->filterQuery == '') { |
|
76 | + return ''; |
|
77 | + } |
|
74 | 78 | return 'f='.$this->filterQuery; |
75 | 79 | } |
76 | 80 |
@@ -6,75 +6,75 @@ |
||
6 | 6 | trait TrapDirectorTableFilter |
7 | 7 | { |
8 | 8 | |
9 | - /********* Filter ********/ |
|
10 | - /** @var string $filterString : string filter for db columns */ |
|
11 | - protected $filterString = ''; |
|
9 | + /********* Filter ********/ |
|
10 | + /** @var string $filterString : string filter for db columns */ |
|
11 | + protected $filterString = ''; |
|
12 | 12 | |
13 | - /** @var array $filterColumn : columns to apply filter to */ |
|
14 | - protected $filterColumn = array(); |
|
13 | + /** @var array $filterColumn : columns to apply filter to */ |
|
14 | + protected $filterColumn = array(); |
|
15 | 15 | |
16 | - protected $filterQuery=''; |
|
16 | + protected $filterQuery=''; |
|
17 | 17 | |
18 | - /**** var & func of TrapDirectorTable used ***/ |
|
19 | - protected $query; |
|
20 | - abstract protected function getCurrentURLAndQS(string $caller); |
|
18 | + /**** var & func of TrapDirectorTable used ***/ |
|
19 | + protected $query; |
|
20 | + abstract protected function getCurrentURLAndQS(string $caller); |
|
21 | 21 | |
22 | - /**************** Filtering ******************/ |
|
22 | + /**************** Filtering ******************/ |
|
23 | 23 | |
24 | - public function applyFilter() |
|
25 | - { |
|
26 | - if ($this->filterString == '' || count($this->filterColumn) == 0) |
|
27 | - { |
|
28 | - return $this; |
|
29 | - } |
|
30 | - $filter=''; |
|
31 | - foreach ($this->filterColumn as $column) |
|
32 | - { |
|
33 | - if ($filter != "") $filter.=' OR '; |
|
34 | - //$filter .= "'" . $column . "' LIKE '%" . $this->filterString. "%'"; |
|
35 | - $filter .= $column . " LIKE '%" . $this->filterString. "%'"; |
|
36 | - } |
|
37 | - //echo $filter; |
|
24 | + public function applyFilter() |
|
25 | + { |
|
26 | + if ($this->filterString == '' || count($this->filterColumn) == 0) |
|
27 | + { |
|
28 | + return $this; |
|
29 | + } |
|
30 | + $filter=''; |
|
31 | + foreach ($this->filterColumn as $column) |
|
32 | + { |
|
33 | + if ($filter != "") $filter.=' OR '; |
|
34 | + //$filter .= "'" . $column . "' LIKE '%" . $this->filterString. "%'"; |
|
35 | + $filter .= $column . " LIKE '%" . $this->filterString. "%'"; |
|
36 | + } |
|
37 | + //echo $filter; |
|
38 | 38 | |
39 | - $this->query=$this->query->where($filter); |
|
39 | + $this->query=$this->query->where($filter); |
|
40 | 40 | |
41 | - return $this; |
|
42 | - } |
|
41 | + return $this; |
|
42 | + } |
|
43 | 43 | |
44 | - public function setFilter(string $filter, array $filterCol) |
|
45 | - { |
|
46 | - $this->filterString = $filter; |
|
47 | - $this->filterColumn = $filterCol; |
|
48 | - return $this; |
|
49 | - } |
|
44 | + public function setFilter(string $filter, array $filterCol) |
|
45 | + { |
|
46 | + $this->filterString = $filter; |
|
47 | + $this->filterColumn = $filterCol; |
|
48 | + return $this; |
|
49 | + } |
|
50 | 50 | |
51 | - public function renderFilter() |
|
52 | - { |
|
51 | + public function renderFilter() |
|
52 | + { |
|
53 | 53 | |
54 | - $html=' <form id="genfilter" name="mainFilterGen" |
|
54 | + $html=' <form id="genfilter" name="mainFilterGen" |
|
55 | 55 | enctype="application/x-www-form-urlencoded" |
56 | 56 | action="'.$this->getCurrentURLAndQS('filter').'" |
57 | 57 | method="get">'; |
58 | - $html.='<input type="text" name="f" title="Search is simple! Try to combine multiple words" |
|
58 | + $html.='<input type="text" name="f" title="Search is simple! Try to combine multiple words" |
|
59 | 59 | placeholder="Search..." value="'.$this->filterQuery.'">'; |
60 | 60 | |
61 | - $html.='</form>'; |
|
62 | - return $html; |
|
63 | - } |
|
61 | + $html.='</form>'; |
|
62 | + return $html; |
|
63 | + } |
|
64 | 64 | |
65 | - public function getFilterQuery(array $getVars) |
|
66 | - { |
|
67 | - if (isset($getVars['f'])) |
|
68 | - { |
|
69 | - $this->filterQuery = $getVars['f']; |
|
70 | - $this->setFilter(html_entity_decode($getVars['f']), $this->columnNames); |
|
71 | - } |
|
72 | - } |
|
65 | + public function getFilterQuery(array $getVars) |
|
66 | + { |
|
67 | + if (isset($getVars['f'])) |
|
68 | + { |
|
69 | + $this->filterQuery = $getVars['f']; |
|
70 | + $this->setFilter(html_entity_decode($getVars['f']), $this->columnNames); |
|
71 | + } |
|
72 | + } |
|
73 | 73 | |
74 | - protected function curFilterQuery() |
|
75 | - { |
|
76 | - if ($this->filterQuery == '') return ''; |
|
77 | - return 'f='.$this->filterQuery; |
|
78 | - } |
|
74 | + protected function curFilterQuery() |
|
75 | + { |
|
76 | + if ($this->filterQuery == '') return ''; |
|
77 | + return 'f='.$this->filterQuery; |
|
78 | + } |
|
79 | 79 | |
80 | 80 | } |
81 | 81 | \ No newline at end of file |
@@ -6,195 +6,195 @@ |
||
6 | 6 | abstract class TrapDirectorTable |
7 | 7 | { |
8 | 8 | |
9 | - use TrapDirectorTableFilter; |
|
10 | - use TrapDirectorTablePaging; |
|
11 | - use TrapDirectorTableOrder; |
|
12 | - use TrapDirectorTableGrouping; |
|
9 | + use TrapDirectorTableFilter; |
|
10 | + use TrapDirectorTablePaging; |
|
11 | + use TrapDirectorTableOrder; |
|
12 | + use TrapDirectorTableGrouping; |
|
13 | 13 | |
14 | - /** @var array $titles table titles (name, display value) */ |
|
15 | - protected $titles = null; |
|
14 | + /** @var array $titles table titles (name, display value) */ |
|
15 | + protected $titles = null; |
|
16 | 16 | |
17 | - /** @var array $content table content (name, sb column name). name index must be the same as $titles*/ |
|
18 | - protected $content = null; |
|
17 | + /** @var array $content table content (name, sb column name). name index must be the same as $titles*/ |
|
18 | + protected $content = null; |
|
19 | 19 | |
20 | - /** @var array $columnNames names of columns for filtering */ |
|
21 | - protected $columnNames = array(); |
|
20 | + /** @var array $columnNames names of columns for filtering */ |
|
21 | + protected $columnNames = array(); |
|
22 | 22 | |
23 | - /** @var mixed $dbConn connection to database */ |
|
24 | - protected $dbConn = null; |
|
23 | + /** @var mixed $dbConn connection to database */ |
|
24 | + protected $dbConn = null; |
|
25 | 25 | |
26 | - /** Current view **/ |
|
27 | - protected $view; |
|
26 | + /** Current view **/ |
|
27 | + protected $view; |
|
28 | 28 | |
29 | - protected $urlPath; |
|
29 | + protected $urlPath; |
|
30 | 30 | |
31 | - // Database stuff |
|
31 | + // Database stuff |
|
32 | 32 | /** @var array $table (db ref, name) */ |
33 | - protected $table = array(); |
|
34 | - |
|
35 | - /** @var mixed $query Query in database; */ |
|
36 | - protected $query = null; |
|
37 | - |
|
38 | - function __construct(array $table,array $titles, array $columns, array $columnNames, $dbConn , $view, $urlPath) |
|
39 | - { |
|
40 | - $this->table = $table; |
|
41 | - $this->titles = $titles; |
|
42 | - $this->content = $columns; |
|
43 | - $this->columnNames = $columnNames; |
|
44 | - $this->dbConn = $dbConn; |
|
33 | + protected $table = array(); |
|
34 | + |
|
35 | + /** @var mixed $query Query in database; */ |
|
36 | + protected $query = null; |
|
37 | + |
|
38 | + function __construct(array $table,array $titles, array $columns, array $columnNames, $dbConn , $view, $urlPath) |
|
39 | + { |
|
40 | + $this->table = $table; |
|
41 | + $this->titles = $titles; |
|
42 | + $this->content = $columns; |
|
43 | + $this->columnNames = $columnNames; |
|
44 | + $this->dbConn = $dbConn; |
|
45 | 45 | |
46 | - $this->view = $view; |
|
47 | - $this->urlPath = $urlPath; |
|
46 | + $this->view = $view; |
|
47 | + $this->urlPath = $urlPath; |
|
48 | 48 | |
49 | - return $this; |
|
50 | - } |
|
49 | + return $this; |
|
50 | + } |
|
51 | 51 | |
52 | 52 | |
53 | - /************** GET variables and URLs *************/ |
|
54 | - public function getParams(array $getVars) |
|
55 | - { |
|
56 | - $this->getFilterQuery($getVars); |
|
57 | - $this->getPagingQuery($getVars); |
|
58 | - $this->getOrderQuery($getVars); |
|
59 | - } |
|
60 | - |
|
61 | - public function getCurrentURL() |
|
62 | - { |
|
63 | - return '?'; |
|
64 | - } |
|
65 | - |
|
66 | - protected function getCurrentURLAndQS(string $caller) |
|
67 | - { |
|
68 | - $actionURL = $this->getCurrentURL() . '?' ; |
|
69 | - $QSList=array(); |
|
70 | - if ($caller != 'filter' && $this->curFilterQuery() != '') |
|
71 | - array_push($QSList , $this->curFilterQuery()); |
|
53 | + /************** GET variables and URLs *************/ |
|
54 | + public function getParams(array $getVars) |
|
55 | + { |
|
56 | + $this->getFilterQuery($getVars); |
|
57 | + $this->getPagingQuery($getVars); |
|
58 | + $this->getOrderQuery($getVars); |
|
59 | + } |
|
60 | + |
|
61 | + public function getCurrentURL() |
|
62 | + { |
|
63 | + return '?'; |
|
64 | + } |
|
65 | + |
|
66 | + protected function getCurrentURLAndQS(string $caller) |
|
67 | + { |
|
68 | + $actionURL = $this->getCurrentURL() . '?' ; |
|
69 | + $QSList=array(); |
|
70 | + if ($caller != 'filter' && $this->curFilterQuery() != '') |
|
71 | + array_push($QSList , $this->curFilterQuery()); |
|
72 | 72 | |
73 | - if ($caller != 'paging' && $caller != 'filter' && $this->curPagingQuery() != '') |
|
74 | - array_push($QSList , $this->curPagingQuery()); |
|
73 | + if ($caller != 'paging' && $caller != 'filter' && $this->curPagingQuery() != '') |
|
74 | + array_push($QSList , $this->curPagingQuery()); |
|
75 | 75 | |
76 | - if ($caller != 'order' && $this->curOrderQuery() != '') |
|
77 | - array_push($QSList , $this->curOrderQuery()); |
|
76 | + if ($caller != 'order' && $this->curOrderQuery() != '') |
|
77 | + array_push($QSList , $this->curOrderQuery()); |
|
78 | 78 | |
79 | - if (count($QSList) != 0) |
|
80 | - $actionURL .= implode('&', $QSList) . '&'; |
|
79 | + if (count($QSList) != 0) |
|
80 | + $actionURL .= implode('&', $QSList) . '&'; |
|
81 | 81 | |
82 | - return $actionURL; |
|
83 | - } |
|
84 | - |
|
85 | - /************* DB queries ******************/ |
|
86 | - /** |
|
87 | - * Get base query in $this->query |
|
88 | - * @return TrapDirectorTable |
|
89 | - */ |
|
90 | - public function getBaseQuery() |
|
91 | - { |
|
92 | - $this->query = $this->dbConn->select(); |
|
93 | - $this->query = $this->query->from( |
|
94 | - $this->table, |
|
95 | - $this->content |
|
96 | - ); |
|
82 | + return $actionURL; |
|
83 | + } |
|
84 | + |
|
85 | + /************* DB queries ******************/ |
|
86 | + /** |
|
87 | + * Get base query in $this->query |
|
88 | + * @return TrapDirectorTable |
|
89 | + */ |
|
90 | + public function getBaseQuery() |
|
91 | + { |
|
92 | + $this->query = $this->dbConn->select(); |
|
93 | + $this->query = $this->query->from( |
|
94 | + $this->table, |
|
95 | + $this->content |
|
96 | + ); |
|
97 | 97 | |
98 | - return $this; |
|
99 | - } |
|
100 | - |
|
101 | - public function fullQuery() |
|
102 | - { |
|
103 | - $this->getBaseQuery() |
|
104 | - ->applyFilter() |
|
105 | - ->applyPaging() |
|
106 | - ->applyOrder(); |
|
98 | + return $this; |
|
99 | + } |
|
100 | + |
|
101 | + public function fullQuery() |
|
102 | + { |
|
103 | + $this->getBaseQuery() |
|
104 | + ->applyFilter() |
|
105 | + ->applyPaging() |
|
106 | + ->applyOrder(); |
|
107 | 107 | |
108 | - return $this->dbConn->fetchAll($this->query); |
|
109 | - //return $this->query->fetchAll(); |
|
110 | - } |
|
108 | + return $this->dbConn->fetchAll($this->query); |
|
109 | + //return $this->query->fetchAll(); |
|
110 | + } |
|
111 | 111 | |
112 | - /*************** Rendering *************************/ |
|
113 | - |
|
114 | - public function titleOrder($name) |
|
115 | - { |
|
116 | - return $this->content[$name]; |
|
117 | - } |
|
118 | - |
|
119 | - public function renderTitles() |
|
120 | - { |
|
121 | - $html = "<thead>\n<tr>\n"; |
|
122 | - foreach ($this->titles as $name => $values) |
|
123 | - { |
|
124 | - $titleOrder = $this->titleOrder($name); // TODO : put this as function of order trait |
|
125 | - if ($titleOrder != NULL) |
|
126 | - { |
|
127 | - if (isset($this->order[$titleOrder])) |
|
128 | - { |
|
129 | - if ($this->order[$titleOrder] == 'ASC') |
|
130 | - { |
|
131 | - $titleOrder.='DESC'; |
|
132 | - } |
|
133 | - else |
|
134 | - { |
|
135 | - $titleOrder.='ASC'; |
|
136 | - } |
|
137 | - } |
|
138 | - else |
|
139 | - { |
|
140 | - $titleOrder.='ASC'; |
|
141 | - } |
|
142 | - $actionURL = $this->getCurrentURLAndQS('order').'o='.$titleOrder; |
|
143 | - $html .= '<th><a href="'.$actionURL.'">' . $values . '</a></th>'; |
|
144 | - } |
|
145 | - else |
|
146 | - { |
|
147 | - $html .= '<th>' . $values . '</th>'; |
|
148 | - } |
|
149 | - } |
|
150 | - $html .= "</tr>\n</thead>\n"; |
|
151 | - return $html; |
|
152 | - } |
|
153 | - |
|
154 | - public function renderLine( $value) |
|
155 | - { |
|
156 | - $html = ''; |
|
157 | - $titleNames = array_keys($this->titles); |
|
158 | - foreach ($titleNames as $name ) |
|
159 | - { |
|
160 | - $html .= '<td>'; |
|
161 | - $html .= $value->$name; |
|
162 | - $html .= "</td>\n"; |
|
163 | - } |
|
164 | - return $html; |
|
165 | - } |
|
166 | - |
|
167 | - public function renderTable(array $values) |
|
168 | - { |
|
169 | - $html = '<tbody id="obj_table_body">'; |
|
170 | - foreach($values as $value) |
|
171 | - { |
|
172 | - $html .= $this->groupingNextLine($value); |
|
112 | + /*************** Rendering *************************/ |
|
113 | + |
|
114 | + public function titleOrder($name) |
|
115 | + { |
|
116 | + return $this->content[$name]; |
|
117 | + } |
|
118 | + |
|
119 | + public function renderTitles() |
|
120 | + { |
|
121 | + $html = "<thead>\n<tr>\n"; |
|
122 | + foreach ($this->titles as $name => $values) |
|
123 | + { |
|
124 | + $titleOrder = $this->titleOrder($name); // TODO : put this as function of order trait |
|
125 | + if ($titleOrder != NULL) |
|
126 | + { |
|
127 | + if (isset($this->order[$titleOrder])) |
|
128 | + { |
|
129 | + if ($this->order[$titleOrder] == 'ASC') |
|
130 | + { |
|
131 | + $titleOrder.='DESC'; |
|
132 | + } |
|
133 | + else |
|
134 | + { |
|
135 | + $titleOrder.='ASC'; |
|
136 | + } |
|
137 | + } |
|
138 | + else |
|
139 | + { |
|
140 | + $titleOrder.='ASC'; |
|
141 | + } |
|
142 | + $actionURL = $this->getCurrentURLAndQS('order').'o='.$titleOrder; |
|
143 | + $html .= '<th><a href="'.$actionURL.'">' . $values . '</a></th>'; |
|
144 | + } |
|
145 | + else |
|
146 | + { |
|
147 | + $html .= '<th>' . $values . '</th>'; |
|
148 | + } |
|
149 | + } |
|
150 | + $html .= "</tr>\n</thead>\n"; |
|
151 | + return $html; |
|
152 | + } |
|
153 | + |
|
154 | + public function renderLine( $value) |
|
155 | + { |
|
156 | + $html = ''; |
|
157 | + $titleNames = array_keys($this->titles); |
|
158 | + foreach ($titleNames as $name ) |
|
159 | + { |
|
160 | + $html .= '<td>'; |
|
161 | + $html .= $value->$name; |
|
162 | + $html .= "</td>\n"; |
|
163 | + } |
|
164 | + return $html; |
|
165 | + } |
|
166 | + |
|
167 | + public function renderTable(array $values) |
|
168 | + { |
|
169 | + $html = '<tbody id="obj_table_body">'; |
|
170 | + foreach($values as $value) |
|
171 | + { |
|
172 | + $html .= $this->groupingNextLine($value); |
|
173 | 173 | |
174 | - $html .= "<tr>\n"; |
|
175 | - $html .= $this->renderLine($value); |
|
176 | - $html .= "</tr>\n"; |
|
177 | - } |
|
178 | - $html .= '</tbody>'; |
|
179 | - return $html; |
|
180 | - } |
|
181 | - |
|
182 | - public function render() |
|
183 | - { |
|
184 | - $html = ''; |
|
174 | + $html .= "<tr>\n"; |
|
175 | + $html .= $this->renderLine($value); |
|
176 | + $html .= "</tr>\n"; |
|
177 | + } |
|
178 | + $html .= '</tbody>'; |
|
179 | + return $html; |
|
180 | + } |
|
181 | + |
|
182 | + public function render() |
|
183 | + { |
|
184 | + $html = ''; |
|
185 | 185 | |
186 | 186 | |
187 | - $values = $this->fullQuery(); |
|
188 | - $this->initGrouping(); |
|
187 | + $values = $this->fullQuery(); |
|
188 | + $this->initGrouping(); |
|
189 | 189 | |
190 | - $html.="<table class='simple common-table table-row-selectable'>\n"; |
|
190 | + $html.="<table class='simple common-table table-row-selectable'>\n"; |
|
191 | 191 | |
192 | - $html .= $this->renderTitles(); |
|
193 | - $html .= $this->renderTable($values); |
|
194 | - $html .= '</table>'; |
|
192 | + $html .= $this->renderTitles(); |
|
193 | + $html .= $this->renderTable($values); |
|
194 | + $html .= '</table>'; |
|
195 | 195 | |
196 | 196 | |
197 | - return $html; |
|
198 | - } |
|
197 | + return $html; |
|
198 | + } |
|
199 | 199 | |
200 | 200 | } |
201 | 201 | \ No newline at end of file |
@@ -12,16 +12,16 @@ discard block |
||
12 | 12 | use TrapDirectorTableGrouping; |
13 | 13 | |
14 | 14 | /** @var array $titles table titles (name, display value) */ |
15 | - protected $titles = null; |
|
15 | + protected $titles=null; |
|
16 | 16 | |
17 | 17 | /** @var array $content table content (name, sb column name). name index must be the same as $titles*/ |
18 | - protected $content = null; |
|
18 | + protected $content=null; |
|
19 | 19 | |
20 | 20 | /** @var array $columnNames names of columns for filtering */ |
21 | - protected $columnNames = array(); |
|
21 | + protected $columnNames=array(); |
|
22 | 22 | |
23 | 23 | /** @var mixed $dbConn connection to database */ |
24 | - protected $dbConn = null; |
|
24 | + protected $dbConn=null; |
|
25 | 25 | |
26 | 26 | /** Current view **/ |
27 | 27 | protected $view; |
@@ -30,21 +30,21 @@ discard block |
||
30 | 30 | |
31 | 31 | // Database stuff |
32 | 32 | /** @var array $table (db ref, name) */ |
33 | - protected $table = array(); |
|
33 | + protected $table=array(); |
|
34 | 34 | |
35 | 35 | /** @var mixed $query Query in database; */ |
36 | - protected $query = null; |
|
36 | + protected $query=null; |
|
37 | 37 | |
38 | - function __construct(array $table,array $titles, array $columns, array $columnNames, $dbConn , $view, $urlPath) |
|
38 | + function __construct(array $table, array $titles, array $columns, array $columnNames, $dbConn, $view, $urlPath) |
|
39 | 39 | { |
40 | - $this->table = $table; |
|
41 | - $this->titles = $titles; |
|
42 | - $this->content = $columns; |
|
43 | - $this->columnNames = $columnNames; |
|
44 | - $this->dbConn = $dbConn; |
|
40 | + $this->table=$table; |
|
41 | + $this->titles=$titles; |
|
42 | + $this->content=$columns; |
|
43 | + $this->columnNames=$columnNames; |
|
44 | + $this->dbConn=$dbConn; |
|
45 | 45 | |
46 | - $this->view = $view; |
|
47 | - $this->urlPath = $urlPath; |
|
46 | + $this->view=$view; |
|
47 | + $this->urlPath=$urlPath; |
|
48 | 48 | |
49 | 49 | return $this; |
50 | 50 | } |
@@ -65,19 +65,19 @@ discard block |
||
65 | 65 | |
66 | 66 | protected function getCurrentURLAndQS(string $caller) |
67 | 67 | { |
68 | - $actionURL = $this->getCurrentURL() . '?' ; |
|
68 | + $actionURL=$this->getCurrentURL().'?'; |
|
69 | 69 | $QSList=array(); |
70 | 70 | if ($caller != 'filter' && $this->curFilterQuery() != '') |
71 | - array_push($QSList , $this->curFilterQuery()); |
|
71 | + array_push($QSList, $this->curFilterQuery()); |
|
72 | 72 | |
73 | 73 | if ($caller != 'paging' && $caller != 'filter' && $this->curPagingQuery() != '') |
74 | - array_push($QSList , $this->curPagingQuery()); |
|
74 | + array_push($QSList, $this->curPagingQuery()); |
|
75 | 75 | |
76 | 76 | if ($caller != 'order' && $this->curOrderQuery() != '') |
77 | - array_push($QSList , $this->curOrderQuery()); |
|
77 | + array_push($QSList, $this->curOrderQuery()); |
|
78 | 78 | |
79 | 79 | if (count($QSList) != 0) |
80 | - $actionURL .= implode('&', $QSList) . '&'; |
|
80 | + $actionURL.=implode('&', $QSList).'&'; |
|
81 | 81 | |
82 | 82 | return $actionURL; |
83 | 83 | } |
@@ -89,8 +89,8 @@ discard block |
||
89 | 89 | */ |
90 | 90 | public function getBaseQuery() |
91 | 91 | { |
92 | - $this->query = $this->dbConn->select(); |
|
93 | - $this->query = $this->query->from( |
|
92 | + $this->query=$this->dbConn->select(); |
|
93 | + $this->query=$this->query->from( |
|
94 | 94 | $this->table, |
95 | 95 | $this->content |
96 | 96 | ); |
@@ -118,10 +118,10 @@ discard block |
||
118 | 118 | |
119 | 119 | public function renderTitles() |
120 | 120 | { |
121 | - $html = "<thead>\n<tr>\n"; |
|
121 | + $html="<thead>\n<tr>\n"; |
|
122 | 122 | foreach ($this->titles as $name => $values) |
123 | 123 | { |
124 | - $titleOrder = $this->titleOrder($name); // TODO : put this as function of order trait |
|
124 | + $titleOrder=$this->titleOrder($name); // TODO : put this as function of order trait |
|
125 | 125 | if ($titleOrder != NULL) |
126 | 126 | { |
127 | 127 | if (isset($this->order[$titleOrder])) |
@@ -139,59 +139,59 @@ discard block |
||
139 | 139 | { |
140 | 140 | $titleOrder.='ASC'; |
141 | 141 | } |
142 | - $actionURL = $this->getCurrentURLAndQS('order').'o='.$titleOrder; |
|
143 | - $html .= '<th><a href="'.$actionURL.'">' . $values . '</a></th>'; |
|
142 | + $actionURL=$this->getCurrentURLAndQS('order').'o='.$titleOrder; |
|
143 | + $html.='<th><a href="'.$actionURL.'">'.$values.'</a></th>'; |
|
144 | 144 | } |
145 | 145 | else |
146 | 146 | { |
147 | - $html .= '<th>' . $values . '</th>'; |
|
147 | + $html.='<th>'.$values.'</th>'; |
|
148 | 148 | } |
149 | 149 | } |
150 | - $html .= "</tr>\n</thead>\n"; |
|
150 | + $html.="</tr>\n</thead>\n"; |
|
151 | 151 | return $html; |
152 | 152 | } |
153 | 153 | |
154 | - public function renderLine( $value) |
|
154 | + public function renderLine($value) |
|
155 | 155 | { |
156 | - $html = ''; |
|
157 | - $titleNames = array_keys($this->titles); |
|
158 | - foreach ($titleNames as $name ) |
|
156 | + $html=''; |
|
157 | + $titleNames=array_keys($this->titles); |
|
158 | + foreach ($titleNames as $name) |
|
159 | 159 | { |
160 | - $html .= '<td>'; |
|
161 | - $html .= $value->$name; |
|
162 | - $html .= "</td>\n"; |
|
160 | + $html.='<td>'; |
|
161 | + $html.=$value->$name; |
|
162 | + $html.="</td>\n"; |
|
163 | 163 | } |
164 | 164 | return $html; |
165 | 165 | } |
166 | 166 | |
167 | 167 | public function renderTable(array $values) |
168 | 168 | { |
169 | - $html = '<tbody id="obj_table_body">'; |
|
170 | - foreach($values as $value) |
|
169 | + $html='<tbody id="obj_table_body">'; |
|
170 | + foreach ($values as $value) |
|
171 | 171 | { |
172 | - $html .= $this->groupingNextLine($value); |
|
172 | + $html.=$this->groupingNextLine($value); |
|
173 | 173 | |
174 | - $html .= "<tr>\n"; |
|
175 | - $html .= $this->renderLine($value); |
|
176 | - $html .= "</tr>\n"; |
|
174 | + $html.="<tr>\n"; |
|
175 | + $html.=$this->renderLine($value); |
|
176 | + $html.="</tr>\n"; |
|
177 | 177 | } |
178 | - $html .= '</tbody>'; |
|
178 | + $html.='</tbody>'; |
|
179 | 179 | return $html; |
180 | 180 | } |
181 | 181 | |
182 | 182 | public function render() |
183 | 183 | { |
184 | - $html = ''; |
|
184 | + $html=''; |
|
185 | 185 | |
186 | 186 | |
187 | - $values = $this->fullQuery(); |
|
187 | + $values=$this->fullQuery(); |
|
188 | 188 | $this->initGrouping(); |
189 | 189 | |
190 | 190 | $html.="<table class='simple common-table table-row-selectable'>\n"; |
191 | 191 | |
192 | - $html .= $this->renderTitles(); |
|
193 | - $html .= $this->renderTable($values); |
|
194 | - $html .= '</table>'; |
|
192 | + $html.=$this->renderTitles(); |
|
193 | + $html.=$this->renderTable($values); |
|
194 | + $html.='</table>'; |
|
195 | 195 | |
196 | 196 | |
197 | 197 | return $html; |
@@ -67,17 +67,21 @@ discard block |
||
67 | 67 | { |
68 | 68 | $actionURL = $this->getCurrentURL() . '?' ; |
69 | 69 | $QSList=array(); |
70 | - if ($caller != 'filter' && $this->curFilterQuery() != '') |
|
71 | - array_push($QSList , $this->curFilterQuery()); |
|
70 | + if ($caller != 'filter' && $this->curFilterQuery() != '') { |
|
71 | + array_push($QSList , $this->curFilterQuery()); |
|
72 | + } |
|
72 | 73 | |
73 | - if ($caller != 'paging' && $caller != 'filter' && $this->curPagingQuery() != '') |
|
74 | - array_push($QSList , $this->curPagingQuery()); |
|
74 | + if ($caller != 'paging' && $caller != 'filter' && $this->curPagingQuery() != '') { |
|
75 | + array_push($QSList , $this->curPagingQuery()); |
|
76 | + } |
|
75 | 77 | |
76 | - if ($caller != 'order' && $this->curOrderQuery() != '') |
|
77 | - array_push($QSList , $this->curOrderQuery()); |
|
78 | + if ($caller != 'order' && $this->curOrderQuery() != '') { |
|
79 | + array_push($QSList , $this->curOrderQuery()); |
|
80 | + } |
|
78 | 81 | |
79 | - if (count($QSList) != 0) |
|
80 | - $actionURL .= implode('&', $QSList) . '&'; |
|
82 | + if (count($QSList) != 0) { |
|
83 | + $actionURL .= implode('&', $QSList) . '&'; |
|
84 | + } |
|
81 | 85 | |
82 | 86 | return $actionURL; |
83 | 87 | } |
@@ -129,20 +133,17 @@ discard block |
||
129 | 133 | if ($this->order[$titleOrder] == 'ASC') |
130 | 134 | { |
131 | 135 | $titleOrder.='DESC'; |
132 | - } |
|
133 | - else |
|
136 | + } else |
|
134 | 137 | { |
135 | 138 | $titleOrder.='ASC'; |
136 | 139 | } |
137 | - } |
|
138 | - else |
|
140 | + } else |
|
139 | 141 | { |
140 | 142 | $titleOrder.='ASC'; |
141 | 143 | } |
142 | 144 | $actionURL = $this->getCurrentURLAndQS('order').'o='.$titleOrder; |
143 | 145 | $html .= '<th><a href="'.$actionURL.'">' . $values . '</a></th>'; |
144 | - } |
|
145 | - else |
|
146 | + } else |
|
146 | 147 | { |
147 | 148 | $html .= '<th>' . $values . '</th>'; |
148 | 149 | } |
@@ -46,7 +46,9 @@ discard block |
||
46 | 46 | |
47 | 47 | protected function curPagingQuery() |
48 | 48 | { |
49 | - if ($this->currentPage == '') return ''; |
|
49 | + if ($this->currentPage == '') { |
|
50 | + return ''; |
|
51 | + } |
|
50 | 52 | return 'page='.$this->currentPage; |
51 | 53 | } |
52 | 54 | |
@@ -58,10 +60,14 @@ discard block |
||
58 | 60 | return 'count : ' . $this->count() . '<br>'; |
59 | 61 | } |
60 | 62 | |
61 | - if ($this->currentPage == 0) $this->currentPage = 1; |
|
63 | + if ($this->currentPage == 0) { |
|
64 | + $this->currentPage = 1; |
|
65 | + } |
|
62 | 66 | |
63 | 67 | $numPages = intdiv($count , $this->maxPerPage); |
64 | - if ($count % $this->maxPerPage != 0 ) $numPages++; |
|
68 | + if ($count % $this->maxPerPage != 0 ) { |
|
69 | + $numPages++; |
|
70 | + } |
|
65 | 71 | |
66 | 72 | $html = '<div class="pagination-control" role="navigation">'; |
67 | 73 | $html .= '<ul class="nav tab-nav">'; |
@@ -75,8 +81,7 @@ discard block |
||
75 | 81 | </span> |
76 | 82 | </li> |
77 | 83 | '; |
78 | - } |
|
79 | - else |
|
84 | + } else |
|
80 | 85 | { |
81 | 86 | $html .= ' |
82 | 87 | <li class="nav-item"> |
@@ -92,7 +97,9 @@ discard block |
||
92 | 97 | $active = ($this->currentPage == $i) ? 'active' : ''; |
93 | 98 | $first = ($i-1)*$this->maxPerPage+1; |
94 | 99 | $last = $i * $this->maxPerPage; |
95 | - if ($last > $count) $last = $count; |
|
100 | + if ($last > $count) { |
|
101 | + $last = $count; |
|
102 | + } |
|
96 | 103 | $display = 'Show rows '. $first . ' to '. $last .' of '. $count; |
97 | 104 | $html .= '<li class="' . $active . ' nav-item"> |
98 | 105 | <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. $i .'" title="' . $display . '" aria-label="' . $display . '"> |
@@ -111,8 +118,7 @@ discard block |
||
111 | 118 | </span> |
112 | 119 | </li> |
113 | 120 | '; |
114 | - } |
|
115 | - else |
|
121 | + } else |
|
116 | 122 | { |
117 | 123 | $html .= ' |
118 | 124 | <li class="nav-item"> |
@@ -6,72 +6,72 @@ discard block |
||
6 | 6 | trait TrapDirectorTablePaging |
7 | 7 | { |
8 | 8 | |
9 | - /*************** Paging *************/ |
|
10 | - protected $maxPerPage = 25; |
|
9 | + /*************** Paging *************/ |
|
10 | + protected $maxPerPage = 25; |
|
11 | 11 | |
12 | - protected $currentPage = 0; |
|
12 | + protected $currentPage = 0; |
|
13 | 13 | |
14 | - /**** var & func of TrapDirectorTable used ***/ |
|
15 | - protected $query; |
|
16 | - abstract protected function getCurrentURLAndQS(string $caller); |
|
17 | - abstract public function applyFilter(); |
|
14 | + /**** var & func of TrapDirectorTable used ***/ |
|
15 | + protected $query; |
|
16 | + abstract protected function getCurrentURLAndQS(string $caller); |
|
17 | + abstract public function applyFilter(); |
|
18 | 18 | |
19 | - /***************** Paging and counting *********/ |
|
19 | + /***************** Paging and counting *********/ |
|
20 | 20 | |
21 | - public function countQuery() |
|
22 | - { |
|
23 | - $this->query = $this->dbConn->select(); |
|
24 | - $this->query = $this->query |
|
25 | - ->from( |
|
26 | - $this->table, |
|
27 | - array('COUNT(*)') |
|
28 | - ); |
|
29 | - $this->applyFilter(); |
|
30 | - } |
|
21 | + public function countQuery() |
|
22 | + { |
|
23 | + $this->query = $this->dbConn->select(); |
|
24 | + $this->query = $this->query |
|
25 | + ->from( |
|
26 | + $this->table, |
|
27 | + array('COUNT(*)') |
|
28 | + ); |
|
29 | + $this->applyFilter(); |
|
30 | + } |
|
31 | 31 | |
32 | - public function count() |
|
33 | - { |
|
34 | - $this->countQuery(); |
|
35 | - return $this->dbConn->fetchOne($this->query); |
|
36 | - } |
|
32 | + public function count() |
|
33 | + { |
|
34 | + $this->countQuery(); |
|
35 | + return $this->dbConn->fetchOne($this->query); |
|
36 | + } |
|
37 | 37 | |
38 | - public function setMaxPerPage(int $max) |
|
39 | - { |
|
40 | - $this->maxPerPage = $max; |
|
41 | - } |
|
38 | + public function setMaxPerPage(int $max) |
|
39 | + { |
|
40 | + $this->maxPerPage = $max; |
|
41 | + } |
|
42 | 42 | |
43 | - protected function getPagingQuery(array $getVars) |
|
44 | - { |
|
45 | - if (isset($getVars['page'])) |
|
46 | - { |
|
47 | - $this->currentPage = $getVars['page']; |
|
48 | - } |
|
49 | - } |
|
43 | + protected function getPagingQuery(array $getVars) |
|
44 | + { |
|
45 | + if (isset($getVars['page'])) |
|
46 | + { |
|
47 | + $this->currentPage = $getVars['page']; |
|
48 | + } |
|
49 | + } |
|
50 | 50 | |
51 | - protected function curPagingQuery() |
|
52 | - { |
|
53 | - if ($this->currentPage == '') return ''; |
|
54 | - return 'page='.$this->currentPage; |
|
55 | - } |
|
51 | + protected function curPagingQuery() |
|
52 | + { |
|
53 | + if ($this->currentPage == '') return ''; |
|
54 | + return 'page='.$this->currentPage; |
|
55 | + } |
|
56 | 56 | |
57 | - public function renderPagingHeader() |
|
58 | - { |
|
59 | - $count = $this->count(); |
|
60 | - if ($count <= $this->maxPerPage ) |
|
61 | - { |
|
62 | - return 'count : ' . $this->count() . '<br>'; |
|
63 | - } |
|
57 | + public function renderPagingHeader() |
|
58 | + { |
|
59 | + $count = $this->count(); |
|
60 | + if ($count <= $this->maxPerPage ) |
|
61 | + { |
|
62 | + return 'count : ' . $this->count() . '<br>'; |
|
63 | + } |
|
64 | 64 | |
65 | - if ($this->currentPage == 0) $this->currentPage = 1; |
|
65 | + if ($this->currentPage == 0) $this->currentPage = 1; |
|
66 | 66 | |
67 | - $numPages = intdiv($count , $this->maxPerPage); |
|
68 | - if ($count % $this->maxPerPage != 0 ) $numPages++; |
|
67 | + $numPages = intdiv($count , $this->maxPerPage); |
|
68 | + if ($count % $this->maxPerPage != 0 ) $numPages++; |
|
69 | 69 | |
70 | - $html = '<div class="pagination-control" role="navigation">'; |
|
71 | - $html .= '<ul class="nav tab-nav">'; |
|
72 | - if ($this->currentPage <=1) |
|
73 | - { |
|
74 | - $html .= ' |
|
70 | + $html = '<div class="pagination-control" role="navigation">'; |
|
71 | + $html .= '<ul class="nav tab-nav">'; |
|
72 | + if ($this->currentPage <=1) |
|
73 | + { |
|
74 | + $html .= ' |
|
75 | 75 | <li class="nav-item disabled" aria-hidden="true"> |
76 | 76 | <span class="previous-page"> |
77 | 77 | <span class="sr-only">Previous page</span> |
@@ -79,35 +79,35 @@ discard block |
||
79 | 79 | </span> |
80 | 80 | </li> |
81 | 81 | '; |
82 | - } |
|
83 | - else |
|
84 | - { |
|
85 | - $html .= ' |
|
82 | + } |
|
83 | + else |
|
84 | + { |
|
85 | + $html .= ' |
|
86 | 86 | <li class="nav-item"> |
87 | 87 | <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. ($this->currentPage - 1 ).'" class="previous-page" > |
88 | 88 | <i aria-hidden="true" class="icon-angle-double-left"></i> |
89 | 89 | </a> |
90 | 90 | </li> |
91 | 91 | '; |
92 | - } |
|
92 | + } |
|
93 | 93 | |
94 | - for ($i=1; $i <= $numPages ; $i++) |
|
95 | - { |
|
96 | - $active = ($this->currentPage == $i) ? 'active' : ''; |
|
97 | - $first = ($i-1)*$this->maxPerPage+1; |
|
98 | - $last = $i * $this->maxPerPage; |
|
99 | - if ($last > $count) $last = $count; |
|
100 | - $display = 'Show rows '. $first . ' to '. $last .' of '. $count; |
|
101 | - $html .= '<li class="' . $active . ' nav-item"> |
|
94 | + for ($i=1; $i <= $numPages ; $i++) |
|
95 | + { |
|
96 | + $active = ($this->currentPage == $i) ? 'active' : ''; |
|
97 | + $first = ($i-1)*$this->maxPerPage+1; |
|
98 | + $last = $i * $this->maxPerPage; |
|
99 | + if ($last > $count) $last = $count; |
|
100 | + $display = 'Show rows '. $first . ' to '. $last .' of '. $count; |
|
101 | + $html .= '<li class="' . $active . ' nav-item"> |
|
102 | 102 | <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. $i .'" title="' . $display . '" aria-label="' . $display . '"> |
103 | 103 | '.$i.' |
104 | 104 | </a> |
105 | 105 | </li>'; |
106 | - } |
|
106 | + } |
|
107 | 107 | |
108 | - if ($this->currentPage == $numPages) |
|
109 | - { |
|
110 | - $html .= ' |
|
108 | + if ($this->currentPage == $numPages) |
|
109 | + { |
|
110 | + $html .= ' |
|
111 | 111 | <li class="nav-item disabled" aria-hidden="true"> |
112 | 112 | <span class="previous-page"> |
113 | 113 | <span class="sr-only">Previous page</span> |
@@ -115,28 +115,28 @@ discard block |
||
115 | 115 | </span> |
116 | 116 | </li> |
117 | 117 | '; |
118 | - } |
|
119 | - else |
|
120 | - { |
|
121 | - $html .= ' |
|
118 | + } |
|
119 | + else |
|
120 | + { |
|
121 | + $html .= ' |
|
122 | 122 | <li class="nav-item"> |
123 | 123 | <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. ($this->currentPage + 1 ).'" class="next-page"> |
124 | 124 | <i aria-hidden="true" class="icon-angle-double-right"></i> |
125 | 125 | </a> |
126 | 126 | </li> |
127 | 127 | '; |
128 | - } |
|
128 | + } |
|
129 | 129 | |
130 | - $html .= '</ul> </div>'; |
|
130 | + $html .= '</ul> </div>'; |
|
131 | 131 | |
132 | - return $html; |
|
133 | - } |
|
132 | + return $html; |
|
133 | + } |
|
134 | 134 | |
135 | - public function applyPaging() |
|
136 | - { |
|
137 | - $this->query->limitPage($this->currentPage,$this->maxPerPage); |
|
138 | - return $this; |
|
139 | - } |
|
135 | + public function applyPaging() |
|
136 | + { |
|
137 | + $this->query->limitPage($this->currentPage,$this->maxPerPage); |
|
138 | + return $this; |
|
139 | + } |
|
140 | 140 | |
141 | 141 | |
142 | 142 | } |
143 | 143 | \ No newline at end of file |
@@ -7,9 +7,9 @@ discard block |
||
7 | 7 | { |
8 | 8 | |
9 | 9 | /*************** Paging *************/ |
10 | - protected $maxPerPage = 25; |
|
10 | + protected $maxPerPage=25; |
|
11 | 11 | |
12 | - protected $currentPage = 0; |
|
12 | + protected $currentPage=0; |
|
13 | 13 | |
14 | 14 | /**** var & func of TrapDirectorTable used ***/ |
15 | 15 | protected $query; |
@@ -20,8 +20,8 @@ discard block |
||
20 | 20 | |
21 | 21 | public function countQuery() |
22 | 22 | { |
23 | - $this->query = $this->dbConn->select(); |
|
24 | - $this->query = $this->query |
|
23 | + $this->query=$this->dbConn->select(); |
|
24 | + $this->query=$this->query |
|
25 | 25 | ->from( |
26 | 26 | $this->table, |
27 | 27 | array('COUNT(*)') |
@@ -37,14 +37,14 @@ discard block |
||
37 | 37 | |
38 | 38 | public function setMaxPerPage(int $max) |
39 | 39 | { |
40 | - $this->maxPerPage = $max; |
|
40 | + $this->maxPerPage=$max; |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | protected function getPagingQuery(array $getVars) |
44 | 44 | { |
45 | 45 | if (isset($getVars['page'])) |
46 | 46 | { |
47 | - $this->currentPage = $getVars['page']; |
|
47 | + $this->currentPage=$getVars['page']; |
|
48 | 48 | } |
49 | 49 | } |
50 | 50 | |
@@ -56,22 +56,22 @@ discard block |
||
56 | 56 | |
57 | 57 | public function renderPagingHeader() |
58 | 58 | { |
59 | - $count = $this->count(); |
|
60 | - if ($count <= $this->maxPerPage ) |
|
59 | + $count=$this->count(); |
|
60 | + if ($count <= $this->maxPerPage) |
|
61 | 61 | { |
62 | - return 'count : ' . $this->count() . '<br>'; |
|
62 | + return 'count : '.$this->count().'<br>'; |
|
63 | 63 | } |
64 | 64 | |
65 | - if ($this->currentPage == 0) $this->currentPage = 1; |
|
65 | + if ($this->currentPage == 0) $this->currentPage=1; |
|
66 | 66 | |
67 | - $numPages = intdiv($count , $this->maxPerPage); |
|
68 | - if ($count % $this->maxPerPage != 0 ) $numPages++; |
|
67 | + $numPages=intdiv($count, $this->maxPerPage); |
|
68 | + if ($count % $this->maxPerPage != 0) $numPages++; |
|
69 | 69 | |
70 | - $html = '<div class="pagination-control" role="navigation">'; |
|
71 | - $html .= '<ul class="nav tab-nav">'; |
|
72 | - if ($this->currentPage <=1) |
|
70 | + $html='<div class="pagination-control" role="navigation">'; |
|
71 | + $html.='<ul class="nav tab-nav">'; |
|
72 | + if ($this->currentPage <= 1) |
|
73 | 73 | { |
74 | - $html .= ' |
|
74 | + $html.=' |
|
75 | 75 | <li class="nav-item disabled" aria-hidden="true"> |
76 | 76 | <span class="previous-page"> |
77 | 77 | <span class="sr-only">Previous page</span> |
@@ -82,24 +82,24 @@ discard block |
||
82 | 82 | } |
83 | 83 | else |
84 | 84 | { |
85 | - $html .= ' |
|
85 | + $html.=' |
|
86 | 86 | <li class="nav-item"> |
87 | - <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. ($this->currentPage - 1 ).'" class="previous-page" > |
|
87 | + <a href="'. $this->getCurrentURLAndQS('paging').'&page='.($this->currentPage - 1).'" class="previous-page" > |
|
88 | 88 | <i aria-hidden="true" class="icon-angle-double-left"></i> |
89 | 89 | </a> |
90 | 90 | </li> |
91 | 91 | '; |
92 | 92 | } |
93 | 93 | |
94 | - for ($i=1; $i <= $numPages ; $i++) |
|
94 | + for ($i=1; $i <= $numPages; $i++) |
|
95 | 95 | { |
96 | - $active = ($this->currentPage == $i) ? 'active' : ''; |
|
97 | - $first = ($i-1)*$this->maxPerPage+1; |
|
98 | - $last = $i * $this->maxPerPage; |
|
99 | - if ($last > $count) $last = $count; |
|
100 | - $display = 'Show rows '. $first . ' to '. $last .' of '. $count; |
|
101 | - $html .= '<li class="' . $active . ' nav-item"> |
|
102 | - <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. $i .'" title="' . $display . '" aria-label="' . $display . '"> |
|
96 | + $active=($this->currentPage == $i) ? 'active' : ''; |
|
97 | + $first=($i - 1) * $this->maxPerPage + 1; |
|
98 | + $last=$i * $this->maxPerPage; |
|
99 | + if ($last > $count) $last=$count; |
|
100 | + $display='Show rows '.$first.' to '.$last.' of '.$count; |
|
101 | + $html.='<li class="'.$active.' nav-item"> |
|
102 | + <a href="'. $this->getCurrentURLAndQS('paging').'&page='.$i.'" title="'.$display.'" aria-label="'.$display.'"> |
|
103 | 103 | '.$i.' |
104 | 104 | </a> |
105 | 105 | </li>'; |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | |
108 | 108 | if ($this->currentPage == $numPages) |
109 | 109 | { |
110 | - $html .= ' |
|
110 | + $html.=' |
|
111 | 111 | <li class="nav-item disabled" aria-hidden="true"> |
112 | 112 | <span class="previous-page"> |
113 | 113 | <span class="sr-only">Previous page</span> |
@@ -118,23 +118,23 @@ discard block |
||
118 | 118 | } |
119 | 119 | else |
120 | 120 | { |
121 | - $html .= ' |
|
121 | + $html.=' |
|
122 | 122 | <li class="nav-item"> |
123 | - <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. ($this->currentPage + 1 ).'" class="next-page"> |
|
123 | + <a href="'. $this->getCurrentURLAndQS('paging').'&page='.($this->currentPage + 1).'" class="next-page"> |
|
124 | 124 | <i aria-hidden="true" class="icon-angle-double-right"></i> |
125 | 125 | </a> |
126 | 126 | </li> |
127 | 127 | '; |
128 | 128 | } |
129 | 129 | |
130 | - $html .= '</ul> </div>'; |
|
130 | + $html.='</ul> </div>'; |
|
131 | 131 | |
132 | 132 | return $html; |
133 | 133 | } |
134 | 134 | |
135 | 135 | public function applyPaging() |
136 | 136 | { |
137 | - $this->query->limitPage($this->currentPage,$this->maxPerPage); |
|
137 | + $this->query->limitPage($this->currentPage, $this->maxPerPage); |
|
138 | 138 | return $this; |
139 | 139 | } |
140 | 140 |
@@ -20,7 +20,9 @@ discard block |
||
20 | 20 | $orderSQL=''; |
21 | 21 | foreach ($this->order as $column => $direction) |
22 | 22 | { |
23 | - if ($orderSQL != "") $orderSQL.=','; |
|
23 | + if ($orderSQL != "") { |
|
24 | + $orderSQL.=','; |
|
25 | + } |
|
24 | 26 | |
25 | 27 | $orderSQL .= $column . ' ' . $direction; |
26 | 28 | } |
@@ -37,7 +39,9 @@ discard block |
||
37 | 39 | |
38 | 40 | public function isOrderSet() |
39 | 41 | { |
40 | - if (count($this->order) == 0) return FALSE; |
|
42 | + if (count($this->order) == 0) { |
|
43 | + return FALSE; |
|
44 | + } |
|
41 | 45 | return TRUE; |
42 | 46 | } |
43 | 47 | |
@@ -58,7 +62,9 @@ discard block |
||
58 | 62 | |
59 | 63 | protected function curOrderQuery() |
60 | 64 | { |
61 | - if ($this->orderQuery == '') return ''; |
|
65 | + if ($this->orderQuery == '') { |
|
66 | + return ''; |
|
67 | + } |
|
62 | 68 | return 'o='.$this->orderQuery; |
63 | 69 | } |
64 | 70 |
@@ -5,65 +5,65 @@ |
||
5 | 5 | |
6 | 6 | trait TrapDirectorTableOrder |
7 | 7 | { |
8 | - /** @var array $order : (db column, 'ASC' | 'DESC') */ |
|
9 | - protected $order = array(); |
|
10 | - /** @var string $orderQuery passed by GET */ |
|
11 | - protected $orderQuery = ''; |
|
8 | + /** @var array $order : (db column, 'ASC' | 'DESC') */ |
|
9 | + protected $order = array(); |
|
10 | + /** @var string $orderQuery passed by GET */ |
|
11 | + protected $orderQuery = ''; |
|
12 | 12 | |
13 | - /** used var & functions of trapDirectorTable **/ |
|
14 | - protected $query; |
|
13 | + /** used var & functions of trapDirectorTable **/ |
|
14 | + protected $query; |
|
15 | 15 | |
16 | 16 | /***************** Ordering ********************/ |
17 | 17 | |
18 | - public function applyOrder() |
|
19 | - { |
|
20 | - if (count($this->order) == 0) |
|
21 | - { |
|
22 | - return $this; |
|
23 | - } |
|
24 | - $orderSQL=''; |
|
25 | - foreach ($this->order as $column => $direction) |
|
26 | - { |
|
27 | - if ($orderSQL != "") $orderSQL.=','; |
|
18 | + public function applyOrder() |
|
19 | + { |
|
20 | + if (count($this->order) == 0) |
|
21 | + { |
|
22 | + return $this; |
|
23 | + } |
|
24 | + $orderSQL=''; |
|
25 | + foreach ($this->order as $column => $direction) |
|
26 | + { |
|
27 | + if ($orderSQL != "") $orderSQL.=','; |
|
28 | 28 | |
29 | - $orderSQL .= $column . ' ' . $direction; |
|
30 | - } |
|
31 | - $this->query = $this->query->order($orderSQL); |
|
29 | + $orderSQL .= $column . ' ' . $direction; |
|
30 | + } |
|
31 | + $this->query = $this->query->order($orderSQL); |
|
32 | 32 | |
33 | - return $this; |
|
34 | - } |
|
33 | + return $this; |
|
34 | + } |
|
35 | 35 | |
36 | - public function setOrder(array $order) |
|
37 | - { |
|
38 | - $this->order = $order; |
|
39 | - return $this; |
|
40 | - } |
|
36 | + public function setOrder(array $order) |
|
37 | + { |
|
38 | + $this->order = $order; |
|
39 | + return $this; |
|
40 | + } |
|
41 | 41 | |
42 | - public function isOrderSet() |
|
43 | - { |
|
44 | - if (count($this->order) == 0) return FALSE; |
|
45 | - return TRUE; |
|
46 | - } |
|
42 | + public function isOrderSet() |
|
43 | + { |
|
44 | + if (count($this->order) == 0) return FALSE; |
|
45 | + return TRUE; |
|
46 | + } |
|
47 | 47 | |
48 | - public function getOrderQuery(array $getVars) |
|
49 | - { |
|
50 | - if (isset($getVars['o'])) |
|
51 | - { |
|
52 | - $this->orderQuery = $getVars['o']; |
|
53 | - $match = array(); |
|
54 | - if (preg_match('/(.*)(ASC|DESC)$/', $this->orderQuery , $match)) |
|
55 | - { |
|
56 | - $orderArray=array($match[1] => $match[2]); |
|
57 | - echo "$match[1] => $match[2]"; |
|
58 | - $this->setOrder($orderArray); |
|
59 | - } |
|
60 | - } |
|
61 | - } |
|
48 | + public function getOrderQuery(array $getVars) |
|
49 | + { |
|
50 | + if (isset($getVars['o'])) |
|
51 | + { |
|
52 | + $this->orderQuery = $getVars['o']; |
|
53 | + $match = array(); |
|
54 | + if (preg_match('/(.*)(ASC|DESC)$/', $this->orderQuery , $match)) |
|
55 | + { |
|
56 | + $orderArray=array($match[1] => $match[2]); |
|
57 | + echo "$match[1] => $match[2]"; |
|
58 | + $this->setOrder($orderArray); |
|
59 | + } |
|
60 | + } |
|
61 | + } |
|
62 | 62 | |
63 | - protected function curOrderQuery() |
|
64 | - { |
|
65 | - if ($this->orderQuery == '') return ''; |
|
66 | - return 'o='.$this->orderQuery; |
|
67 | - } |
|
63 | + protected function curOrderQuery() |
|
64 | + { |
|
65 | + if ($this->orderQuery == '') return ''; |
|
66 | + return 'o='.$this->orderQuery; |
|
67 | + } |
|
68 | 68 | |
69 | 69 | } |
70 | 70 | \ No newline at end of file |
@@ -6,9 +6,9 @@ discard block |
||
6 | 6 | trait TrapDirectorTableOrder |
7 | 7 | { |
8 | 8 | /** @var array $order : (db column, 'ASC' | 'DESC') */ |
9 | - protected $order = array(); |
|
9 | + protected $order=array(); |
|
10 | 10 | /** @var string $orderQuery passed by GET */ |
11 | - protected $orderQuery = ''; |
|
11 | + protected $orderQuery=''; |
|
12 | 12 | |
13 | 13 | /** used var & functions of trapDirectorTable **/ |
14 | 14 | protected $query; |
@@ -26,16 +26,16 @@ discard block |
||
26 | 26 | { |
27 | 27 | if ($orderSQL != "") $orderSQL.=','; |
28 | 28 | |
29 | - $orderSQL .= $column . ' ' . $direction; |
|
29 | + $orderSQL.=$column.' '.$direction; |
|
30 | 30 | } |
31 | - $this->query = $this->query->order($orderSQL); |
|
31 | + $this->query=$this->query->order($orderSQL); |
|
32 | 32 | |
33 | 33 | return $this; |
34 | 34 | } |
35 | 35 | |
36 | 36 | public function setOrder(array $order) |
37 | 37 | { |
38 | - $this->order = $order; |
|
38 | + $this->order=$order; |
|
39 | 39 | return $this; |
40 | 40 | } |
41 | 41 | |
@@ -49,9 +49,9 @@ discard block |
||
49 | 49 | { |
50 | 50 | if (isset($getVars['o'])) |
51 | 51 | { |
52 | - $this->orderQuery = $getVars['o']; |
|
53 | - $match = array(); |
|
54 | - if (preg_match('/(.*)(ASC|DESC)$/', $this->orderQuery , $match)) |
|
52 | + $this->orderQuery=$getVars['o']; |
|
53 | + $match=array(); |
|
54 | + if (preg_match('/(.*)(ASC|DESC)$/', $this->orderQuery, $match)) |
|
55 | 55 | { |
56 | 56 | $orderArray=array($match[1] => $match[2]); |
57 | 57 | echo "$match[1] => $match[2]"; |
@@ -4,18 +4,18 @@ 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 |
|
17 | - 'max_rows_in_list' => 25, // Max rows displayed in table before paging |
|
18 | - 'handler_categories' => '0:Not categorized' // handlers categories : <index>:<name>!<index>:<name> .... |
|
16 | + 'SnmpTrapAddess_oid' => '.1.3.6.1.6.3.18.1.3', // default snmpTrapAdress OID |
|
17 | + 'max_rows_in_list' => 25, // Max rows displayed in table before paging |
|
18 | + 'handler_categories' => '0:Not categorized' // handlers categories : <index>:<name>!<index>:<name> .... |
|
19 | 19 | ); |
20 | 20 | // get default values for dbconfig |
21 | 21 | public function getDBConfigDefaults() { return $this->DBConfigDefaults;} |
@@ -122,27 +122,27 @@ discard block |
||
122 | 122 | // Note : must have 'source_ip' and 'last_sent' |
123 | 123 | public function getTrapHostListDisplayColumns() |
124 | 124 | { |
125 | - return array( |
|
126 | - 'source_name' => 't.source_name', |
|
127 | - 'source_ip' => 't.source_ip', |
|
128 | - 'trap_oid' => 't.trap_oid', |
|
129 | - 'count' => 'count(*)', |
|
130 | - 'last_sent' => 'UNIX_TIMESTAMP(max(t.date_received))' |
|
131 | - ); |
|
125 | + return array( |
|
126 | + 'source_name' => 't.source_name', |
|
127 | + 'source_ip' => 't.source_ip', |
|
128 | + 'trap_oid' => 't.trap_oid', |
|
129 | + 'count' => 'count(*)', |
|
130 | + 'last_sent' => 'UNIX_TIMESTAMP(max(t.date_received))' |
|
131 | + ); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | public function getTrapHostListSearchColumns() |
135 | 135 | { |
136 | - return array(); // No search needed on this table |
|
136 | + return array(); // No search needed on this table |
|
137 | 137 | } |
138 | 138 | // Titles display in Trap List table |
139 | 139 | public function getTrapHostListTitles() |
140 | 140 | { |
141 | - return array( |
|
142 | - 'trap_oid' => 'Trap OID', |
|
143 | - 'count' => 'Number of traps received', |
|
144 | - 'last_sent' => 'Last trap received' |
|
145 | - ); |
|
141 | + return array( |
|
142 | + 'trap_oid' => 'Trap OID', |
|
143 | + 'count' => 'Number of traps received', |
|
144 | + 'last_sent' => 'Last trap received' |
|
145 | + ); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | |
@@ -157,13 +157,13 @@ discard block |
||
157 | 157 | 'source_ip' => "CASE WHEN r.ip4 IS NULL THEN r.ip6 ELSE r.ip4 END", |
158 | 158 | 'trap_oid' => 'r.trap_oid', |
159 | 159 | 'rule' => 'r.rule', |
160 | - 'comment' => 'r.comment', |
|
161 | - 'category' => 'r.rule_type', |
|
160 | + 'comment' => 'r.comment', |
|
161 | + 'category' => 'r.rule_type', |
|
162 | 162 | 'action_match' => 'r.action_match', |
163 | 163 | 'action_nomatch'=> 'r.action_nomatch', |
164 | 164 | 'service_name' => 'r.service_name', |
165 | 165 | 'num_match' => 'r.num_match', |
166 | - 'rule_type' => 'r.rule_type', |
|
166 | + 'rule_type' => 'r.rule_type', |
|
167 | 167 | 'id' => 'r.id' |
168 | 168 | ); |
169 | 169 | } |
@@ -184,17 +184,17 @@ discard block |
||
184 | 184 | } |
185 | 185 | public function getHandlerColumns() |
186 | 186 | { |
187 | - return array( |
|
188 | - 'r.host_name', 'r.host_group_name', |
|
189 | - 'r.ip4', 'r.ip6', |
|
190 | - 'r.trap_oid', |
|
191 | - 'r.rule', |
|
192 | - 'r.action_match', |
|
193 | - 'r.action_nomatch', |
|
194 | - 'r.service_name', |
|
195 | - 'r.num_match', |
|
196 | - 'r.id' |
|
197 | - ); |
|
187 | + return array( |
|
188 | + 'r.host_name', 'r.host_group_name', |
|
189 | + 'r.ip4', 'r.ip6', |
|
190 | + 'r.trap_oid', |
|
191 | + 'r.rule', |
|
192 | + 'r.action_match', |
|
193 | + 'r.action_nomatch', |
|
194 | + 'r.service_name', |
|
195 | + 'r.num_match', |
|
196 | + 'r.id' |
|
197 | + ); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | // handler update (<key> => <sql select>) |
@@ -214,9 +214,9 @@ discard block |
||
214 | 214 | 'revert_ok' => 'r.revert_ok', |
215 | 215 | 'display' => 'r.display', |
216 | 216 | 'modified' => 'UNIX_TIMESTAMP(r.modified)', |
217 | - 'modifier' => 'r.modifier', |
|
218 | - 'comment' => 'r.comment', |
|
219 | - 'category' => 'r.rule_type' |
|
217 | + 'modifier' => 'r.modifier', |
|
218 | + 'comment' => 'r.comment', |
|
219 | + 'category' => 'r.rule_type' |
|
220 | 220 | ); |
221 | 221 | } |
222 | 222 |
@@ -18,27 +18,27 @@ discard block |
||
18 | 18 | 'handler_categories' => '0:Not categorized' // handlers categories : <index>:<name>!<index>:<name> .... |
19 | 19 | ); |
20 | 20 | // get default values for dbconfig |
21 | - public function getDBConfigDefaults() { return $this->DBConfigDefaults;} |
|
21 | + public function getDBConfigDefaults() { return $this->DBConfigDefaults; } |
|
22 | 22 | /** Minimum DB version |
23 | 23 | * @return number |
24 | 24 | */ |
25 | - static public function getDbMinVersion() { return 2;} |
|
25 | + static public function getDbMinVersion() { return 2; } |
|
26 | 26 | /** Current DB version |
27 | 27 | * @return number |
28 | 28 | */ |
29 | - static public function getDbCurVersion() { return 2;} |
|
29 | + static public function getDbCurVersion() { return 2; } |
|
30 | 30 | |
31 | 31 | /************ Module configuration **********************/ |
32 | 32 | // Module base path |
33 | 33 | static public function urlPath() { return 'trapdirector'; } |
34 | - static public function getapiUserPermissions() { return array("status", "objects/query/Host", "objects/query/hostgroup", "objects/query/Service" , "actions/process-check-result"); } //< api user permissions required |
|
34 | + static public function getapiUserPermissions() { return array("status", "objects/query/Host", "objects/query/hostgroup", "objects/query/Service", "actions/process-check-result"); } //< api user permissions required |
|
35 | 35 | |
36 | 36 | |
37 | 37 | /*********** Log configuration *************************/ |
38 | 38 | protected $logLevels=array(0=>'No output', 1=>'critical', 2=>'warning', 3=>'trace', 4=>'ALL'); |
39 | - public function getlogLevels() { return $this->logLevels;} |
|
40 | - protected $logDestinations=array('syslog'=>'syslog','file'=>'file','display'=>'display'); |
|
41 | - public function getLogDestinations() { return $this->logDestinations;} |
|
39 | + public function getlogLevels() { return $this->logLevels; } |
|
40 | + protected $logDestinations=array('syslog'=>'syslog', 'file'=>'file', 'display'=>'display'); |
|
41 | + public function getLogDestinations() { return $this->logDestinations; } |
|
42 | 42 | |
43 | 43 | function __construct($prefix) |
44 | 44 | { |
@@ -49,29 +49,29 @@ discard block |
||
49 | 49 | // DB table name of trap received list : prefix 't' |
50 | 50 | public function getTrapTableName() |
51 | 51 | { |
52 | - return array('t' => $this->table_prefix . 'received'); |
|
52 | + return array('t' => $this->table_prefix.'received'); |
|
53 | 53 | } |
54 | 54 | // DB table name of trap data list : prefix 'd' |
55 | 55 | public function getTrapDataTableName() |
56 | 56 | { |
57 | - return array('d' => $this->table_prefix . 'received_data'); |
|
57 | + return array('d' => $this->table_prefix.'received_data'); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | // DB table name of rules : prefix 'r' |
61 | 61 | public function getTrapRuleName() |
62 | 62 | { |
63 | - return array('r' => $this->table_prefix . 'rules'); |
|
63 | + return array('r' => $this->table_prefix.'rules'); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | // DB table name of db config : prefix 'c' |
67 | 67 | public function getDbConfigTableName() |
68 | 68 | { |
69 | - return array('c' => $this->table_prefix . 'db_config'); |
|
69 | + return array('c' => $this->table_prefix.'db_config'); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | // Mib cache tables |
73 | - public function getMIBCacheTableName() { return $this->table_prefix . 'mib_cache'; } |
|
74 | - public function getMIBCacheTableTrapObjName() { return $this->table_prefix . 'mib_cache_trap_object'; } |
|
73 | + public function getMIBCacheTableName() { return $this->table_prefix.'mib_cache'; } |
|
74 | + public function getMIBCacheTableTrapObjName() { return $this->table_prefix.'mib_cache_trap_object'; } |
|
75 | 75 | |
76 | 76 | |
77 | 77 | /****************** Database queries *******************/ |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | public function getHandlerListDisplayColumns() |
153 | 153 | { |
154 | 154 | return array( |
155 | - 'host_name' => 'r.host_name',//'UNIX_TIMESTAMP(t.date_received)', |
|
155 | + 'host_name' => 'r.host_name', //'UNIX_TIMESTAMP(t.date_received)', |
|
156 | 156 | 'host_group_name'=> 'r.host_group_name', |
157 | 157 | 'source_ip' => "CASE WHEN r.ip4 IS NULL THEN r.ip6 ELSE r.ip4 END", |
158 | 158 | 'trap_oid' => 'r.trap_oid', |
@@ -224,32 +224,32 @@ discard block |
||
224 | 224 | public function trapDetailQuery() |
225 | 225 | { |
226 | 226 | return array( |
227 | - 'timestamp' => array('Date','UNIX_TIMESTAMP(t.date_received)'), |
|
228 | - 'source_ip' => array('Source IP','t.source_ip'), |
|
229 | - 'source_name' => array('Source name','t.source_name'), |
|
230 | - 'source_port' => array('Source port','t.source_port'), |
|
231 | - 'destination_ip' => array('Destination IP','t.destination_ip'), |
|
232 | - 'destination_port' => array('Destination port','t.destination_port'), |
|
233 | - 'trap_oid' => array('Numeric OID','t.trap_oid'), |
|
234 | - 'trap_name' => array('Trap name','t.trap_name'), |
|
235 | - 'trap_name_mib' => array('Trap MIB','t.trap_name_mib'), |
|
236 | - 'status' => array('Processing status','t.status'), |
|
237 | - 'status_detail' => array('Status details','t.status_detail'), |
|
238 | - 'process_time' => array('Trap processing time','t.process_time'), |
|
227 | + 'timestamp' => array('Date', 'UNIX_TIMESTAMP(t.date_received)'), |
|
228 | + 'source_ip' => array('Source IP', 't.source_ip'), |
|
229 | + 'source_name' => array('Source name', 't.source_name'), |
|
230 | + 'source_port' => array('Source port', 't.source_port'), |
|
231 | + 'destination_ip' => array('Destination IP', 't.destination_ip'), |
|
232 | + 'destination_port' => array('Destination port', 't.destination_port'), |
|
233 | + 'trap_oid' => array('Numeric OID', 't.trap_oid'), |
|
234 | + 'trap_name' => array('Trap name', 't.trap_name'), |
|
235 | + 'trap_name_mib' => array('Trap MIB', 't.trap_name_mib'), |
|
236 | + 'status' => array('Processing status', 't.status'), |
|
237 | + 'status_detail' => array('Status details', 't.status_detail'), |
|
238 | + 'process_time' => array('Trap processing time', 't.process_time'), |
|
239 | 239 | ); |
240 | 240 | } |
241 | 241 | // Trap detail : additional data (<key> => <title> <sql select>) |
242 | 242 | public function trapDataDetailQuery() |
243 | 243 | { |
244 | 244 | return array( |
245 | - 'oid' => array('Numeric OID','d.oid'), |
|
246 | - 'oid_name' => array('Text OID','d.oid_name'), |
|
247 | - 'oid_name_mib' => array('MIB','d.oid_name_mib'), |
|
248 | - 'value' => array('Value','d.value'), |
|
245 | + 'oid' => array('Numeric OID', 'd.oid'), |
|
246 | + 'oid_name' => array('Text OID', 'd.oid_name'), |
|
247 | + 'oid_name_mib' => array('MIB', 'd.oid_name_mib'), |
|
248 | + 'value' => array('Value', 'd.value'), |
|
249 | 249 | ); |
250 | 250 | } |
251 | 251 | // foreign key of trap data table |
252 | - public function trapDataFK() { return 'trap_id';} |
|
252 | + public function trapDataFK() { return 'trap_id'; } |
|
253 | 253 | |
254 | 254 | // Max items in a list OBSOLETE TODO : remove after all tables moved to trapdirectorTable |
255 | 255 | public function itemListDisplay() { return 25; } |
@@ -7,86 +7,86 @@ |
||
7 | 7 | { |
8 | 8 | |
9 | 9 | |
10 | - /*************** Grouping ************/ |
|
10 | + /*************** Grouping ************/ |
|
11 | 11 | |
12 | - /** @var boolean $grouppingActive set to true if grouping is active by query or function call */ |
|
13 | - protected $grouppingActive=false; |
|
12 | + /** @var boolean $grouppingActive set to true if grouping is active by query or function call */ |
|
13 | + protected $grouppingActive=false; |
|
14 | 14 | |
15 | - /** @var string $groupingColumn Name of column (can be hidden) for grouping */ |
|
16 | - protected $groupingColumn=''; |
|
15 | + /** @var string $groupingColumn Name of column (can be hidden) for grouping */ |
|
16 | + protected $groupingColumn=''; |
|
17 | 17 | |
18 | - /**@var string $groupingVal Current value of grouping column in row (used while rendering) */ |
|
19 | - protected $groupingVal=''; |
|
18 | + /**@var string $groupingVal Current value of grouping column in row (used while rendering) */ |
|
19 | + protected $groupingVal=''; |
|
20 | 20 | |
21 | - /** @var integer $groupingColSpan colspan of grouping line : set to table titles in init */ |
|
22 | - protected $groupingColSpan=1; |
|
21 | + /** @var integer $groupingColSpan colspan of grouping line : set to table titles in init */ |
|
22 | + protected $groupingColSpan=1; |
|
23 | 23 | |
24 | - /***************** Grouping ****************/ |
|
24 | + /***************** Grouping ****************/ |
|
25 | 25 | |
26 | - /** |
|
27 | - * Set grouping. column must be DB name |
|
28 | - * @param string $columnDBName |
|
29 | - */ |
|
30 | - public function setGrouping(string $columnDBName) |
|
31 | - { |
|
32 | - $this->groupingColumn = $columnDBName; |
|
33 | - $this->grouppingActive = TRUE; |
|
34 | - } |
|
26 | + /** |
|
27 | + * Set grouping. column must be DB name |
|
28 | + * @param string $columnDBName |
|
29 | + */ |
|
30 | + public function setGrouping(string $columnDBName) |
|
31 | + { |
|
32 | + $this->groupingColumn = $columnDBName; |
|
33 | + $this->grouppingActive = TRUE; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Init of grouping before rendering |
|
38 | - */ |
|
39 | - public function initGrouping() |
|
40 | - { |
|
41 | - $this->groupingVal = ''; |
|
42 | - $this->groupingColSpan = count($this->titles); |
|
43 | - } |
|
36 | + /** |
|
37 | + * Init of grouping before rendering |
|
38 | + */ |
|
39 | + public function initGrouping() |
|
40 | + { |
|
41 | + $this->groupingVal = ''; |
|
42 | + $this->groupingColSpan = count($this->titles); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Function to print grouping value (for ovveride in specific tables) |
|
47 | - * @param string $value |
|
48 | - * @return string |
|
49 | - */ |
|
50 | - public function groupingPrintData( string $value ) |
|
51 | - { |
|
52 | - $html = "$value"; |
|
53 | - return $html; |
|
54 | - } |
|
45 | + /** |
|
46 | + * Function to print grouping value (for ovveride in specific tables) |
|
47 | + * @param string $value |
|
48 | + * @return string |
|
49 | + */ |
|
50 | + public function groupingPrintData( string $value ) |
|
51 | + { |
|
52 | + $html = "$value"; |
|
53 | + return $html; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * When to display new grouping line (for ovveride in specific tables) |
|
58 | - * @param string $val1 Current value in grouping |
|
59 | - * @param string $val2 Value of current line |
|
60 | - * @return boolean TRUE if a new grouping line is needed. |
|
61 | - */ |
|
62 | - public function groupingEvalNext(string $val1, string $val2) |
|
63 | - { |
|
64 | - if ($val1 != $val2) |
|
65 | - return TRUE; |
|
66 | - else |
|
67 | - return FALSE; |
|
68 | - } |
|
56 | + /** |
|
57 | + * When to display new grouping line (for ovveride in specific tables) |
|
58 | + * @param string $val1 Current value in grouping |
|
59 | + * @param string $val2 Value of current line |
|
60 | + * @return boolean TRUE if a new grouping line is needed. |
|
61 | + */ |
|
62 | + public function groupingEvalNext(string $val1, string $val2) |
|
63 | + { |
|
64 | + if ($val1 != $val2) |
|
65 | + return TRUE; |
|
66 | + else |
|
67 | + return FALSE; |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Called before each line to check if grouping line is needed. |
|
72 | - * @param mixed $values |
|
73 | - * @return string with line or empty. |
|
74 | - */ |
|
75 | - public function groupingNextLine( $values) |
|
76 | - { |
|
77 | - if ($this->grouppingActive === FALSE) return ''; |
|
70 | + /** |
|
71 | + * Called before each line to check if grouping line is needed. |
|
72 | + * @param mixed $values |
|
73 | + * @return string with line or empty. |
|
74 | + */ |
|
75 | + public function groupingNextLine( $values) |
|
76 | + { |
|
77 | + if ($this->grouppingActive === FALSE) return ''; |
|
78 | 78 | |
79 | - $dbcol = $this->groupingColumn; |
|
80 | - $dbVal = $values->$dbcol; |
|
81 | - if ( $dbVal === NULL ) $dbVal = '0'; // Set default to 0 |
|
82 | - if ($this->groupingVal == '' || $this->groupingEvalNext($this->groupingVal ,$dbVal) === TRUE ) |
|
83 | - { |
|
84 | - $this->groupingVal = $dbVal; |
|
85 | - $html = '<tr><th colspan="'. $this->groupingColSpan .'">'. $this->groupingPrintData($this->groupingVal) .'</th></tr>'; |
|
86 | - return $html; |
|
87 | - } |
|
88 | - return ''; |
|
79 | + $dbcol = $this->groupingColumn; |
|
80 | + $dbVal = $values->$dbcol; |
|
81 | + if ( $dbVal === NULL ) $dbVal = '0'; // Set default to 0 |
|
82 | + if ($this->groupingVal == '' || $this->groupingEvalNext($this->groupingVal ,$dbVal) === TRUE ) |
|
83 | + { |
|
84 | + $this->groupingVal = $dbVal; |
|
85 | + $html = '<tr><th colspan="'. $this->groupingColSpan .'">'. $this->groupingPrintData($this->groupingVal) .'</th></tr>'; |
|
86 | + return $html; |
|
87 | + } |
|
88 | + return ''; |
|
89 | 89 | |
90 | - } |
|
90 | + } |
|
91 | 91 | |
92 | 92 | } |
@@ -29,8 +29,8 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public function setGrouping(string $columnDBName) |
31 | 31 | { |
32 | - $this->groupingColumn = $columnDBName; |
|
33 | - $this->grouppingActive = TRUE; |
|
32 | + $this->groupingColumn=$columnDBName; |
|
33 | + $this->grouppingActive=TRUE; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function initGrouping() |
40 | 40 | { |
41 | - $this->groupingVal = ''; |
|
42 | - $this->groupingColSpan = count($this->titles); |
|
41 | + $this->groupingVal=''; |
|
42 | + $this->groupingColSpan=count($this->titles); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -47,9 +47,9 @@ discard block |
||
47 | 47 | * @param string $value |
48 | 48 | * @return string |
49 | 49 | */ |
50 | - public function groupingPrintData( string $value ) |
|
50 | + public function groupingPrintData(string $value) |
|
51 | 51 | { |
52 | - $html = "$value"; |
|
52 | + $html="$value"; |
|
53 | 53 | return $html; |
54 | 54 | } |
55 | 55 | |
@@ -72,17 +72,17 @@ discard block |
||
72 | 72 | * @param mixed $values |
73 | 73 | * @return string with line or empty. |
74 | 74 | */ |
75 | - public function groupingNextLine( $values) |
|
75 | + public function groupingNextLine($values) |
|
76 | 76 | { |
77 | 77 | if ($this->grouppingActive === FALSE) return ''; |
78 | 78 | |
79 | - $dbcol = $this->groupingColumn; |
|
80 | - $dbVal = $values->$dbcol; |
|
81 | - if ( $dbVal === NULL ) $dbVal = '0'; // Set default to 0 |
|
82 | - if ($this->groupingVal == '' || $this->groupingEvalNext($this->groupingVal ,$dbVal) === TRUE ) |
|
79 | + $dbcol=$this->groupingColumn; |
|
80 | + $dbVal=$values->$dbcol; |
|
81 | + if ($dbVal === NULL) $dbVal='0'; // Set default to 0 |
|
82 | + if ($this->groupingVal == '' || $this->groupingEvalNext($this->groupingVal, $dbVal) === TRUE) |
|
83 | 83 | { |
84 | - $this->groupingVal = $dbVal; |
|
85 | - $html = '<tr><th colspan="'. $this->groupingColSpan .'">'. $this->groupingPrintData($this->groupingVal) .'</th></tr>'; |
|
84 | + $this->groupingVal=$dbVal; |
|
85 | + $html='<tr><th colspan="'.$this->groupingColSpan.'">'.$this->groupingPrintData($this->groupingVal).'</th></tr>'; |
|
86 | 86 | return $html; |
87 | 87 | } |
88 | 88 | return ''; |
@@ -61,10 +61,11 @@ discard block |
||
61 | 61 | */ |
62 | 62 | public function groupingEvalNext(string $val1, string $val2) |
63 | 63 | { |
64 | - if ($val1 != $val2) |
|
65 | - return TRUE; |
|
66 | - else |
|
67 | - return FALSE; |
|
64 | + if ($val1 != $val2) { |
|
65 | + return TRUE; |
|
66 | + } else { |
|
67 | + return FALSE; |
|
68 | + } |
|
68 | 69 | } |
69 | 70 | |
70 | 71 | /** |
@@ -74,11 +75,16 @@ discard block |
||
74 | 75 | */ |
75 | 76 | public function groupingNextLine( $values) |
76 | 77 | { |
77 | - if ($this->grouppingActive === FALSE) return ''; |
|
78 | + if ($this->grouppingActive === FALSE) { |
|
79 | + return ''; |
|
80 | + } |
|
78 | 81 | |
79 | 82 | $dbcol = $this->groupingColumn; |
80 | 83 | $dbVal = $values->$dbcol; |
81 | - if ( $dbVal === NULL ) $dbVal = '0'; // Set default to 0 |
|
84 | + if ( $dbVal === NULL ) { |
|
85 | + $dbVal = '0'; |
|
86 | + } |
|
87 | + // Set default to 0 |
|
82 | 88 | if ($this->groupingVal == '' || $this->groupingEvalNext($this->groupingVal ,$dbVal) === TRUE ) |
83 | 89 | { |
84 | 90 | $this->groupingVal = $dbVal; |
@@ -80,18 +80,19 @@ discard block |
||
80 | 80 | try |
81 | 81 | { |
82 | 82 | $result=$this->request('GET', "", NULL, NULL); |
83 | - } |
|
84 | - catch (Exception $e) |
|
83 | + } catch (Exception $e) |
|
85 | 84 | { |
86 | 85 | return array(true, 'Error with API : '.$e->getMessage()); |
87 | 86 | } |
88 | 87 | //var_dump($result); |
89 | 88 | $permOk=1; |
90 | 89 | $permMissing=''; |
91 | - if ($permissions === NULL || count($permissions) == 0) // If no permission check return OK after connexion |
|
90 | + if ($permissions === NULL || count($permissions) == 0) { |
|
91 | + // If no permission check return OK after connexion |
|
92 | 92 | { |
93 | 93 | return array(false,'OK'); |
94 | 94 | } |
95 | + } |
|
95 | 96 | if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions')) |
96 | 97 | { |
97 | 98 | |
@@ -177,8 +178,7 @@ discard block |
||
177 | 178 | if (property_exists($result,'status')) |
178 | 179 | { |
179 | 180 | $message=$result->status; |
180 | - } |
|
181 | - else |
|
181 | + } else |
|
182 | 182 | { |
183 | 183 | $message="Unkown status"; |
184 | 184 | } |
@@ -189,8 +189,7 @@ discard block |
||
189 | 189 | if (isset($result->results[0])) |
190 | 190 | { |
191 | 191 | return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status); |
192 | - } |
|
193 | - else |
|
192 | + } else |
|
194 | 193 | { |
195 | 194 | return array(false,'Service not found'); |
196 | 195 | } |
@@ -211,8 +210,7 @@ discard block |
||
211 | 210 | if (property_exists($result,'status')) |
212 | 211 | { |
213 | 212 | throw new Exception('Ret code ' .$result->error.' : ' . $result->status); |
214 | - } |
|
215 | - else |
|
213 | + } else |
|
216 | 214 | { |
217 | 215 | throw new Exception('Ret code ' .$result->error.' : Unkown status'); |
218 | 216 | } |
@@ -8,347 +8,347 @@ |
||
8 | 8 | |
9 | 9 | class IcingaApiBase |
10 | 10 | { |
11 | - protected $version = 'v1'; //< icinga2 api version |
|
11 | + protected $version = 'v1'; //< icinga2 api version |
|
12 | 12 | |
13 | - protected $host; //< icinga2 host name or IP |
|
14 | - protected $port; //< icinga2 api port |
|
13 | + protected $host; //< icinga2 host name or IP |
|
14 | + protected $port; //< icinga2 api port |
|
15 | 15 | |
16 | - protected $user; //< user name |
|
17 | - protected $pass; //< user password |
|
18 | - protected $usercert; //< user key for certificate auth (NOT IMPLEMENTED) |
|
19 | - protected $authmethod='pass'; //< Authentication : 'pass' or 'cert' |
|
16 | + protected $user; //< user name |
|
17 | + protected $pass; //< user password |
|
18 | + protected $usercert; //< user key for certificate auth (NOT IMPLEMENTED) |
|
19 | + protected $authmethod='pass'; //< Authentication : 'pass' or 'cert' |
|
20 | 20 | |
21 | - protected $queryURL=array( |
|
22 | - 'host' => 'objects/hosts', |
|
23 | - 'hostgroup' => 'objects/hostgroups', |
|
24 | - 'service' => 'objects/services' |
|
25 | - ); |
|
21 | + protected $queryURL=array( |
|
22 | + 'host' => 'objects/hosts', |
|
23 | + 'hostgroup' => 'objects/hostgroups', |
|
24 | + 'service' => 'objects/services' |
|
25 | + ); |
|
26 | 26 | |
27 | - protected $curl; |
|
28 | - // http://php.net/manual/de/function.json-last-error.php#119985 |
|
29 | - protected $errorReference = [ |
|
30 | - JSON_ERROR_NONE => 'No error has occurred.', |
|
31 | - JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.', |
|
32 | - JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.', |
|
33 | - JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded.', |
|
34 | - JSON_ERROR_SYNTAX => 'Syntax error.', |
|
35 | - JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded.', |
|
36 | - JSON_ERROR_RECURSION => 'One or more recursive references in the value to be encoded.', |
|
37 | - JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded.', |
|
38 | - JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given.', |
|
39 | - ]; |
|
40 | - const JSON_UNKNOWN_ERROR = 'Unknown error.'; |
|
27 | + protected $curl; |
|
28 | + // http://php.net/manual/de/function.json-last-error.php#119985 |
|
29 | + protected $errorReference = [ |
|
30 | + JSON_ERROR_NONE => 'No error has occurred.', |
|
31 | + JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.', |
|
32 | + JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.', |
|
33 | + JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded.', |
|
34 | + JSON_ERROR_SYNTAX => 'Syntax error.', |
|
35 | + JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded.', |
|
36 | + JSON_ERROR_RECURSION => 'One or more recursive references in the value to be encoded.', |
|
37 | + JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded.', |
|
38 | + JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given.', |
|
39 | + ]; |
|
40 | + const JSON_UNKNOWN_ERROR = 'Unknown error.'; |
|
41 | 41 | |
42 | - /** |
|
43 | - * Creates Icinga2API object |
|
44 | - * |
|
45 | - * @param string $host host name or IP |
|
46 | - * @param number $port API port |
|
47 | - */ |
|
48 | - public function __construct($host, $port = 5665) |
|
49 | - { |
|
50 | - $this->host=$host; |
|
51 | - $this->port=$port; |
|
52 | - } |
|
53 | - /** |
|
54 | - * Set user & pass |
|
55 | - * @param string $user |
|
56 | - * @param string $pass |
|
57 | - */ |
|
58 | - public function setCredentials($user,$pass) |
|
59 | - { |
|
60 | - $this->user=$user; |
|
61 | - $this->pass=$pass; |
|
62 | - $this->authmethod='pass'; |
|
63 | - } |
|
42 | + /** |
|
43 | + * Creates Icinga2API object |
|
44 | + * |
|
45 | + * @param string $host host name or IP |
|
46 | + * @param number $port API port |
|
47 | + */ |
|
48 | + public function __construct($host, $port = 5665) |
|
49 | + { |
|
50 | + $this->host=$host; |
|
51 | + $this->port=$port; |
|
52 | + } |
|
53 | + /** |
|
54 | + * Set user & pass |
|
55 | + * @param string $user |
|
56 | + * @param string $pass |
|
57 | + */ |
|
58 | + public function setCredentials($user,$pass) |
|
59 | + { |
|
60 | + $this->user=$user; |
|
61 | + $this->pass=$pass; |
|
62 | + $this->authmethod='pass'; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Set user & certificate (NOT IMPLEMENTED @throws RuntimeException) |
|
67 | - * @param string $user |
|
68 | - * @param string $usercert |
|
69 | - */ |
|
70 | - public function setCredentialskey($user,$usercert) |
|
71 | - { |
|
72 | - $this->user=$user; |
|
73 | - $this->usercert=$usercert; |
|
74 | - $this->authmethod='cert'; |
|
75 | - throw new RuntimeException('Certificate auth not implemented'); |
|
76 | - } |
|
65 | + /** |
|
66 | + * Set user & certificate (NOT IMPLEMENTED @throws RuntimeException) |
|
67 | + * @param string $user |
|
68 | + * @param string $usercert |
|
69 | + */ |
|
70 | + public function setCredentialskey($user,$usercert) |
|
71 | + { |
|
72 | + $this->user=$user; |
|
73 | + $this->usercert=$usercert; |
|
74 | + $this->authmethod='cert'; |
|
75 | + throw new RuntimeException('Certificate auth not implemented'); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Test API connection |
|
80 | - * @param array $permissions : check permissions if not null or empty |
|
81 | - * @return array (bool,string) : bool = false is all OK, else true with message |
|
82 | - * */ |
|
83 | - public function test(array $permissions) |
|
84 | - { |
|
85 | - try |
|
86 | - { |
|
87 | - $result=$this->request('GET', "", NULL, NULL); |
|
88 | - } |
|
89 | - catch (Exception $e) |
|
90 | - { |
|
91 | - return array(true, 'Error with API : '.$e->getMessage()); |
|
92 | - } |
|
93 | - //var_dump($result); |
|
94 | - $permOk=1; |
|
95 | - $permMissing=''; |
|
96 | - if ($permissions === NULL || count($permissions) == 0) // If no permission check return OK after connexion |
|
97 | - { |
|
98 | - return array(false,'OK'); |
|
99 | - } |
|
100 | - if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions')) |
|
101 | - { |
|
78 | + /** |
|
79 | + * Test API connection |
|
80 | + * @param array $permissions : check permissions if not null or empty |
|
81 | + * @return array (bool,string) : bool = false is all OK, else true with message |
|
82 | + * */ |
|
83 | + public function test(array $permissions) |
|
84 | + { |
|
85 | + try |
|
86 | + { |
|
87 | + $result=$this->request('GET', "", NULL, NULL); |
|
88 | + } |
|
89 | + catch (Exception $e) |
|
90 | + { |
|
91 | + return array(true, 'Error with API : '.$e->getMessage()); |
|
92 | + } |
|
93 | + //var_dump($result); |
|
94 | + $permOk=1; |
|
95 | + $permMissing=''; |
|
96 | + if ($permissions === NULL || count($permissions) == 0) // If no permission check return OK after connexion |
|
97 | + { |
|
98 | + return array(false,'OK'); |
|
99 | + } |
|
100 | + if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions')) |
|
101 | + { |
|
102 | 102 | |
103 | - foreach ( $permissions as $mustPermission) |
|
104 | - { |
|
105 | - $curPermOK=0; |
|
106 | - foreach ( $result->results[0]->permissions as $curPermission) |
|
107 | - { |
|
108 | - $curPermission=preg_replace('/\*/','.*',$curPermission); // put * as .* to created a regexp |
|
109 | - if (preg_match('#'.$curPermission.'#',$mustPermission)) |
|
110 | - { |
|
111 | - $curPermOK=1; |
|
112 | - break; |
|
113 | - } |
|
114 | - } |
|
115 | - if ($curPermOK == 0) |
|
116 | - { |
|
117 | - $permOk=0; |
|
118 | - $permMissing=$mustPermission; |
|
119 | - break; |
|
120 | - } |
|
121 | - } |
|
122 | - if ($permOk == 0) |
|
123 | - { |
|
124 | - return array(true,'API connection OK, but missing permission : '.$permMissing); |
|
125 | - } |
|
126 | - return array(false,'API connection OK'); |
|
103 | + foreach ( $permissions as $mustPermission) |
|
104 | + { |
|
105 | + $curPermOK=0; |
|
106 | + foreach ( $result->results[0]->permissions as $curPermission) |
|
107 | + { |
|
108 | + $curPermission=preg_replace('/\*/','.*',$curPermission); // put * as .* to created a regexp |
|
109 | + if (preg_match('#'.$curPermission.'#',$mustPermission)) |
|
110 | + { |
|
111 | + $curPermOK=1; |
|
112 | + break; |
|
113 | + } |
|
114 | + } |
|
115 | + if ($curPermOK == 0) |
|
116 | + { |
|
117 | + $permOk=0; |
|
118 | + $permMissing=$mustPermission; |
|
119 | + break; |
|
120 | + } |
|
121 | + } |
|
122 | + if ($permOk == 0) |
|
123 | + { |
|
124 | + return array(true,'API connection OK, but missing permission : '.$permMissing); |
|
125 | + } |
|
126 | + return array(false,'API connection OK'); |
|
127 | 127 | |
128 | - } |
|
129 | - return array(true,'API connection OK, but cannot get permissions'); |
|
130 | - } |
|
128 | + } |
|
129 | + return array(true,'API connection OK, but cannot get permissions'); |
|
130 | + } |
|
131 | 131 | |
132 | 132 | |
133 | - protected function url($url) { |
|
134 | - return sprintf('https://%s:%d/%s/%s', $this->host, $this->port, $this->version, $url); |
|
135 | - } |
|
133 | + protected function url($url) { |
|
134 | + return sprintf('https://%s:%d/%s/%s', $this->host, $this->port, $this->version, $url); |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * Create or return curl ressource |
|
139 | - * @throws Exception |
|
140 | - * @return resource |
|
141 | - */ |
|
142 | - protected function curl() { |
|
143 | - if ($this->curl === null) { |
|
144 | - $this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port)); |
|
145 | - if ($this->curl === false) { |
|
146 | - throw new Exception('CURL INIT ERROR'); |
|
147 | - } |
|
148 | - } |
|
149 | - return $this->curl; |
|
150 | - } |
|
137 | + /** |
|
138 | + * Create or return curl ressource |
|
139 | + * @throws Exception |
|
140 | + * @return resource |
|
141 | + */ |
|
142 | + protected function curl() { |
|
143 | + if ($this->curl === null) { |
|
144 | + $this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port)); |
|
145 | + if ($this->curl === false) { |
|
146 | + throw new Exception('CURL INIT ERROR'); |
|
147 | + } |
|
148 | + } |
|
149 | + return $this->curl; |
|
150 | + } |
|
151 | 151 | |
152 | - /** |
|
153 | - * Send a passive service check |
|
154 | - * @param string $host : host name |
|
155 | - * @param string $service : service name |
|
156 | - * @param int $state : state of service |
|
157 | - * @param string $display : service passive check output |
|
158 | - * @param string $perfdata : performance data as string |
|
159 | - * @return array (status = true (oK) or false (nok), string message) |
|
160 | - */ |
|
161 | - public function serviceCheckResult($host,$service,$state,$display,$perfdata='') |
|
162 | - { |
|
163 | - //Send a POST request to the URL endpoint /v1/actions/process-check-result |
|
164 | - //actions/process-check-result?service=example.localdomain!passive-ping6 |
|
165 | - $url='actions/process-check-result'; |
|
166 | - $body=array( |
|
167 | - "filter" => 'service.name=="'.$service.'" && service.host_name=="'.$host.'"', |
|
168 | - 'type' => 'Service', |
|
169 | - "exit_status" => $state, |
|
170 | - "plugin_output" => $display, |
|
171 | - "performance_data" => $perfdata |
|
172 | - ); |
|
173 | - try |
|
174 | - { |
|
175 | - $result=$this->request('POST', $url, null, $body); |
|
176 | - } catch (Exception $e) |
|
177 | - { |
|
178 | - return array(false, $e->getMessage()); |
|
179 | - } |
|
180 | - if (property_exists($result,'error') ) |
|
181 | - { |
|
182 | - if (property_exists($result,'status')) |
|
183 | - { |
|
184 | - $message=$result->status; |
|
185 | - } |
|
186 | - else |
|
187 | - { |
|
188 | - $message="Unkown status"; |
|
189 | - } |
|
190 | - return array(false , 'Ret code ' .$result->error.' : '.$message); |
|
191 | - } |
|
192 | - if (property_exists($result, 'results')) |
|
193 | - { |
|
194 | - if (isset($result->results[0])) |
|
195 | - { |
|
196 | - return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status); |
|
197 | - } |
|
198 | - else |
|
199 | - { |
|
200 | - return array(false,'Service not found'); |
|
201 | - } |
|
152 | + /** |
|
153 | + * Send a passive service check |
|
154 | + * @param string $host : host name |
|
155 | + * @param string $service : service name |
|
156 | + * @param int $state : state of service |
|
157 | + * @param string $display : service passive check output |
|
158 | + * @param string $perfdata : performance data as string |
|
159 | + * @return array (status = true (oK) or false (nok), string message) |
|
160 | + */ |
|
161 | + public function serviceCheckResult($host,$service,$state,$display,$perfdata='') |
|
162 | + { |
|
163 | + //Send a POST request to the URL endpoint /v1/actions/process-check-result |
|
164 | + //actions/process-check-result?service=example.localdomain!passive-ping6 |
|
165 | + $url='actions/process-check-result'; |
|
166 | + $body=array( |
|
167 | + "filter" => 'service.name=="'.$service.'" && service.host_name=="'.$host.'"', |
|
168 | + 'type' => 'Service', |
|
169 | + "exit_status" => $state, |
|
170 | + "plugin_output" => $display, |
|
171 | + "performance_data" => $perfdata |
|
172 | + ); |
|
173 | + try |
|
174 | + { |
|
175 | + $result=$this->request('POST', $url, null, $body); |
|
176 | + } catch (Exception $e) |
|
177 | + { |
|
178 | + return array(false, $e->getMessage()); |
|
179 | + } |
|
180 | + if (property_exists($result,'error') ) |
|
181 | + { |
|
182 | + if (property_exists($result,'status')) |
|
183 | + { |
|
184 | + $message=$result->status; |
|
185 | + } |
|
186 | + else |
|
187 | + { |
|
188 | + $message="Unkown status"; |
|
189 | + } |
|
190 | + return array(false , 'Ret code ' .$result->error.' : '.$message); |
|
191 | + } |
|
192 | + if (property_exists($result, 'results')) |
|
193 | + { |
|
194 | + if (isset($result->results[0])) |
|
195 | + { |
|
196 | + return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status); |
|
197 | + } |
|
198 | + else |
|
199 | + { |
|
200 | + return array(false,'Service not found'); |
|
201 | + } |
|
202 | 202 | |
203 | - } |
|
204 | - return array(false,'Unkown result, open issue with this : '.print_r($result,true)); |
|
205 | - } |
|
203 | + } |
|
204 | + return array(false,'Unkown result, open issue with this : '.print_r($result,true)); |
|
205 | + } |
|
206 | 206 | |
207 | - /** |
|
208 | - * Check 'result' exists and check for errors/status |
|
209 | - * @param \stdClass $result |
|
210 | - * @throws Exception |
|
211 | - */ |
|
212 | - public function checkResultStatus(\stdClass $result) |
|
213 | - { |
|
214 | - if (property_exists($result,'error') ) |
|
215 | - { |
|
216 | - if (property_exists($result,'status')) |
|
217 | - { |
|
218 | - throw new Exception('Ret code ' .$result->error.' : ' . $result->status); |
|
219 | - } |
|
220 | - else |
|
221 | - { |
|
222 | - throw new Exception('Ret code ' .$result->error.' : Unkown status'); |
|
223 | - } |
|
224 | - } |
|
225 | - if ( ! property_exists($result, 'results')) |
|
226 | - { |
|
227 | - throw new Exception('Unkown result'); |
|
228 | - } |
|
229 | - } |
|
207 | + /** |
|
208 | + * Check 'result' exists and check for errors/status |
|
209 | + * @param \stdClass $result |
|
210 | + * @throws Exception |
|
211 | + */ |
|
212 | + public function checkResultStatus(\stdClass $result) |
|
213 | + { |
|
214 | + if (property_exists($result,'error') ) |
|
215 | + { |
|
216 | + if (property_exists($result,'status')) |
|
217 | + { |
|
218 | + throw new Exception('Ret code ' .$result->error.' : ' . $result->status); |
|
219 | + } |
|
220 | + else |
|
221 | + { |
|
222 | + throw new Exception('Ret code ' .$result->error.' : Unkown status'); |
|
223 | + } |
|
224 | + } |
|
225 | + if ( ! property_exists($result, 'results')) |
|
226 | + { |
|
227 | + throw new Exception('Unkown result'); |
|
228 | + } |
|
229 | + } |
|
230 | 230 | |
231 | - /** |
|
232 | - * Send request to API |
|
233 | - * @param string $method get/post/... |
|
234 | - * @param string $url (after /v1/ ) |
|
235 | - * @param array $headers |
|
236 | - * @param array $body |
|
237 | - * @throws Exception |
|
238 | - * @return array |
|
239 | - */ |
|
240 | - public function request($method, $url, $headers, $body) { |
|
241 | - $auth = sprintf('%s:%s', $this->user, $this->pass); |
|
242 | - $curlHeaders = array("Accept: application/json"); |
|
243 | - if ($body !== null) { |
|
244 | - $body = json_encode($body); |
|
245 | - array_push($curlHeaders, 'Content-Type: application/json'); |
|
246 | - //array_push($curlHeaders, 'X-HTTP-Method-Override: GET'); |
|
247 | - } |
|
248 | - //var_dump($body); |
|
249 | - //var_dump($this->url($url)); |
|
250 | - if ($headers !== null) { |
|
251 | - $curlFinalHeaders = array_merge($curlHeaders, $headers); |
|
252 | - } else |
|
253 | - { |
|
254 | - $curlFinalHeaders=$curlHeaders; |
|
255 | - } |
|
256 | - $curl = $this->curl(); |
|
257 | - $opts = array( |
|
258 | - CURLOPT_URL => $this->url($url), |
|
259 | - CURLOPT_HTTPHEADER => $curlFinalHeaders, |
|
260 | - CURLOPT_USERPWD => $auth, |
|
261 | - CURLOPT_CUSTOMREQUEST => strtoupper($method), |
|
262 | - CURLOPT_RETURNTRANSFER => true, |
|
263 | - CURLOPT_CONNECTTIMEOUT => 10, |
|
264 | - CURLOPT_SSL_VERIFYHOST => false, |
|
265 | - CURLOPT_SSL_VERIFYPEER => false, |
|
266 | - ); |
|
267 | - if ($body !== null) { |
|
268 | - $opts[CURLOPT_POSTFIELDS] = $body; |
|
269 | - } |
|
270 | - curl_setopt_array($curl, $opts); |
|
271 | - $res = curl_exec($curl); |
|
272 | - if ($res === false) { |
|
273 | - throw new Exception('CURL ERROR: ' . curl_error($curl)); |
|
274 | - } |
|
275 | - $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); |
|
276 | - if ($statusCode === 401) { |
|
277 | - throw new Exception('Unable to authenticate, please check your API credentials'); |
|
278 | - } |
|
279 | - return $this->fromJsonResult($res); |
|
280 | - } |
|
231 | + /** |
|
232 | + * Send request to API |
|
233 | + * @param string $method get/post/... |
|
234 | + * @param string $url (after /v1/ ) |
|
235 | + * @param array $headers |
|
236 | + * @param array $body |
|
237 | + * @throws Exception |
|
238 | + * @return array |
|
239 | + */ |
|
240 | + public function request($method, $url, $headers, $body) { |
|
241 | + $auth = sprintf('%s:%s', $this->user, $this->pass); |
|
242 | + $curlHeaders = array("Accept: application/json"); |
|
243 | + if ($body !== null) { |
|
244 | + $body = json_encode($body); |
|
245 | + array_push($curlHeaders, 'Content-Type: application/json'); |
|
246 | + //array_push($curlHeaders, 'X-HTTP-Method-Override: GET'); |
|
247 | + } |
|
248 | + //var_dump($body); |
|
249 | + //var_dump($this->url($url)); |
|
250 | + if ($headers !== null) { |
|
251 | + $curlFinalHeaders = array_merge($curlHeaders, $headers); |
|
252 | + } else |
|
253 | + { |
|
254 | + $curlFinalHeaders=$curlHeaders; |
|
255 | + } |
|
256 | + $curl = $this->curl(); |
|
257 | + $opts = array( |
|
258 | + CURLOPT_URL => $this->url($url), |
|
259 | + CURLOPT_HTTPHEADER => $curlFinalHeaders, |
|
260 | + CURLOPT_USERPWD => $auth, |
|
261 | + CURLOPT_CUSTOMREQUEST => strtoupper($method), |
|
262 | + CURLOPT_RETURNTRANSFER => true, |
|
263 | + CURLOPT_CONNECTTIMEOUT => 10, |
|
264 | + CURLOPT_SSL_VERIFYHOST => false, |
|
265 | + CURLOPT_SSL_VERIFYPEER => false, |
|
266 | + ); |
|
267 | + if ($body !== null) { |
|
268 | + $opts[CURLOPT_POSTFIELDS] = $body; |
|
269 | + } |
|
270 | + curl_setopt_array($curl, $opts); |
|
271 | + $res = curl_exec($curl); |
|
272 | + if ($res === false) { |
|
273 | + throw new Exception('CURL ERROR: ' . curl_error($curl)); |
|
274 | + } |
|
275 | + $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); |
|
276 | + if ($statusCode === 401) { |
|
277 | + throw new Exception('Unable to authenticate, please check your API credentials'); |
|
278 | + } |
|
279 | + return $this->fromJsonResult($res); |
|
280 | + } |
|
281 | 281 | |
282 | - /** |
|
283 | - * |
|
284 | - * @param string $json json encoded |
|
285 | - * @throws Exception |
|
286 | - * @return array json decoded |
|
287 | - */ |
|
288 | - protected function fromJsonResult($json) { |
|
289 | - $result = @json_decode($json); |
|
290 | - //var_dump($json); |
|
291 | - if ($result === null) { |
|
292 | - throw new Exception('Parsing JSON failed: '.$this->getLastJsonErrorMessage(json_last_error())); |
|
293 | - } |
|
294 | - return $result; |
|
295 | - } |
|
282 | + /** |
|
283 | + * |
|
284 | + * @param string $json json encoded |
|
285 | + * @throws Exception |
|
286 | + * @return array json decoded |
|
287 | + */ |
|
288 | + protected function fromJsonResult($json) { |
|
289 | + $result = @json_decode($json); |
|
290 | + //var_dump($json); |
|
291 | + if ($result === null) { |
|
292 | + throw new Exception('Parsing JSON failed: '.$this->getLastJsonErrorMessage(json_last_error())); |
|
293 | + } |
|
294 | + return $result; |
|
295 | + } |
|
296 | 296 | |
297 | - /** |
|
298 | - * Return text error no json error |
|
299 | - * @param string $errorCode |
|
300 | - * @return string |
|
301 | - */ |
|
302 | - protected function getLastJsonErrorMessage($errorCode) { |
|
303 | - if (!array_key_exists($errorCode, $this->errorReference)) { |
|
304 | - return self::JSON_UNKNOWN_ERROR; |
|
305 | - } |
|
306 | - return $this->errorReference[$errorCode]; |
|
307 | - } |
|
297 | + /** |
|
298 | + * Return text error no json error |
|
299 | + * @param string $errorCode |
|
300 | + * @return string |
|
301 | + */ |
|
302 | + protected function getLastJsonErrorMessage($errorCode) { |
|
303 | + if (!array_key_exists($errorCode, $this->errorReference)) { |
|
304 | + return self::JSON_UNKNOWN_ERROR; |
|
305 | + } |
|
306 | + return $this->errorReference[$errorCode]; |
|
307 | + } |
|
308 | 308 | |
309 | - public function standardQuery(string $urlType , string $filter, array $attributes) |
|
310 | - { |
|
311 | - /* |
|
309 | + public function standardQuery(string $urlType , string $filter, array $attributes) |
|
310 | + { |
|
311 | + /* |
|
312 | 312 | * curl -k -s -u trapdirector:trapdirector -H 'X-HTTP-Method-Override: GET' -X POST 'https://localhost:5665/v1/objects/hosts' |
313 | 313 | * -d '{"filter":"\"test_trap\" in host.groups","attrs": ["address" ,"address6"],"pretty": true}' |
314 | 314 | |
315 | 315 | {"results":[{"attrs":{"__name":"Icinga host","address":"127.0.0.1","display_name":"Icinga host","name":"Icinga host"},"joins":{},"meta":{},"name":"Icinga host","type":"Host"}]} |
316 | 316 | */ |
317 | 317 | |
318 | - if (! isset($this->queryURL[$urlType] )) |
|
319 | - { |
|
320 | - throw new Exception("Unkown object type"); |
|
321 | - } |
|
322 | - $url=$this->queryURL[$urlType]; |
|
323 | - $body=array(); |
|
324 | - if ($filter !== NULL) |
|
325 | - { |
|
326 | - $body['filter'] = $filter; |
|
327 | - } |
|
328 | - if (count($attributes) != 0) |
|
329 | - { |
|
330 | - $body['attrs'] = $attributes; |
|
331 | - } |
|
318 | + if (! isset($this->queryURL[$urlType] )) |
|
319 | + { |
|
320 | + throw new Exception("Unkown object type"); |
|
321 | + } |
|
322 | + $url=$this->queryURL[$urlType]; |
|
323 | + $body=array(); |
|
324 | + if ($filter !== NULL) |
|
325 | + { |
|
326 | + $body['filter'] = $filter; |
|
327 | + } |
|
328 | + if (count($attributes) != 0) |
|
329 | + { |
|
330 | + $body['attrs'] = $attributes; |
|
331 | + } |
|
332 | 332 | |
333 | - try |
|
334 | - { |
|
335 | - $result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body); |
|
336 | - } catch (Exception $e) |
|
337 | - { |
|
338 | - throw new Exception($e->getMessage()); |
|
339 | - } |
|
333 | + try |
|
334 | + { |
|
335 | + $result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body); |
|
336 | + } catch (Exception $e) |
|
337 | + { |
|
338 | + throw new Exception($e->getMessage()); |
|
339 | + } |
|
340 | 340 | |
341 | - $this->checkResultStatus($result); |
|
341 | + $this->checkResultStatus($result); |
|
342 | 342 | |
343 | - $numHost=0; |
|
344 | - $hostArray=array(); |
|
345 | - while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs')) |
|
346 | - { |
|
347 | - $hostArray[$numHost] = $result->results[$numHost]->attrs; |
|
348 | - $numHost++; |
|
349 | - } |
|
350 | - return $hostArray; |
|
351 | - } |
|
343 | + $numHost=0; |
|
344 | + $hostArray=array(); |
|
345 | + while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs')) |
|
346 | + { |
|
347 | + $hostArray[$numHost] = $result->results[$numHost]->attrs; |
|
348 | + $numHost++; |
|
349 | + } |
|
350 | + return $hostArray; |
|
351 | + } |
|
352 | 352 | |
353 | 353 | } |
354 | 354 |
@@ -8,15 +8,15 @@ discard block |
||
8 | 8 | |
9 | 9 | class IcingaApiBase |
10 | 10 | { |
11 | - protected $version = 'v1'; //< icinga2 api version |
|
11 | + protected $version='v1'; //< icinga2 api version |
|
12 | 12 | |
13 | - protected $host; //< icinga2 host name or IP |
|
14 | - protected $port; //< icinga2 api port |
|
13 | + protected $host; //< icinga2 host name or IP |
|
14 | + protected $port; //< icinga2 api port |
|
15 | 15 | |
16 | - protected $user; //< user name |
|
17 | - protected $pass; //< user password |
|
18 | - protected $usercert; //< user key for certificate auth (NOT IMPLEMENTED) |
|
19 | - protected $authmethod='pass'; //< Authentication : 'pass' or 'cert' |
|
16 | + protected $user; //< user name |
|
17 | + protected $pass; //< user password |
|
18 | + protected $usercert; //< user key for certificate auth (NOT IMPLEMENTED) |
|
19 | + protected $authmethod='pass'; //< Authentication : 'pass' or 'cert' |
|
20 | 20 | |
21 | 21 | protected $queryURL=array( |
22 | 22 | 'host' => 'objects/hosts', |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | |
27 | 27 | protected $curl; |
28 | 28 | // http://php.net/manual/de/function.json-last-error.php#119985 |
29 | - protected $errorReference = [ |
|
29 | + protected $errorReference=[ |
|
30 | 30 | JSON_ERROR_NONE => 'No error has occurred.', |
31 | 31 | JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.', |
32 | 32 | JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.', |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded.', |
38 | 38 | JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given.', |
39 | 39 | ]; |
40 | - const JSON_UNKNOWN_ERROR = 'Unknown error.'; |
|
40 | + const JSON_UNKNOWN_ERROR='Unknown error.'; |
|
41 | 41 | |
42 | 42 | /** |
43 | 43 | * Creates Icinga2API object |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | * @param string $host host name or IP |
46 | 46 | * @param number $port API port |
47 | 47 | */ |
48 | - public function __construct($host, $port = 5665) |
|
48 | + public function __construct($host, $port=5665) |
|
49 | 49 | { |
50 | 50 | $this->host=$host; |
51 | 51 | $this->port=$port; |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * @param string $user |
56 | 56 | * @param string $pass |
57 | 57 | */ |
58 | - public function setCredentials($user,$pass) |
|
58 | + public function setCredentials($user, $pass) |
|
59 | 59 | { |
60 | 60 | $this->user=$user; |
61 | 61 | $this->pass=$pass; |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | * @param string $user |
68 | 68 | * @param string $usercert |
69 | 69 | */ |
70 | - public function setCredentialskey($user,$usercert) |
|
70 | + public function setCredentialskey($user, $usercert) |
|
71 | 71 | { |
72 | 72 | $this->user=$user; |
73 | 73 | $this->usercert=$usercert; |
@@ -95,18 +95,18 @@ discard block |
||
95 | 95 | $permMissing=''; |
96 | 96 | if ($permissions === NULL || count($permissions) == 0) // If no permission check return OK after connexion |
97 | 97 | { |
98 | - return array(false,'OK'); |
|
98 | + return array(false, 'OK'); |
|
99 | 99 | } |
100 | 100 | if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions')) |
101 | 101 | { |
102 | 102 | |
103 | - foreach ( $permissions as $mustPermission) |
|
103 | + foreach ($permissions as $mustPermission) |
|
104 | 104 | { |
105 | 105 | $curPermOK=0; |
106 | - foreach ( $result->results[0]->permissions as $curPermission) |
|
106 | + foreach ($result->results[0]->permissions as $curPermission) |
|
107 | 107 | { |
108 | - $curPermission=preg_replace('/\*/','.*',$curPermission); // put * as .* to created a regexp |
|
109 | - if (preg_match('#'.$curPermission.'#',$mustPermission)) |
|
108 | + $curPermission=preg_replace('/\*/', '.*', $curPermission); // put * as .* to created a regexp |
|
109 | + if (preg_match('#'.$curPermission.'#', $mustPermission)) |
|
110 | 110 | { |
111 | 111 | $curPermOK=1; |
112 | 112 | break; |
@@ -121,12 +121,12 @@ discard block |
||
121 | 121 | } |
122 | 122 | if ($permOk == 0) |
123 | 123 | { |
124 | - return array(true,'API connection OK, but missing permission : '.$permMissing); |
|
124 | + return array(true, 'API connection OK, but missing permission : '.$permMissing); |
|
125 | 125 | } |
126 | - return array(false,'API connection OK'); |
|
126 | + return array(false, 'API connection OK'); |
|
127 | 127 | |
128 | 128 | } |
129 | - return array(true,'API connection OK, but cannot get permissions'); |
|
129 | + return array(true, 'API connection OK, but cannot get permissions'); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | */ |
142 | 142 | protected function curl() { |
143 | 143 | if ($this->curl === null) { |
144 | - $this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port)); |
|
144 | + $this->curl=curl_init(sprintf('https://%s:%d', $this->host, $this->port)); |
|
145 | 145 | if ($this->curl === false) { |
146 | 146 | throw new Exception('CURL INIT ERROR'); |
147 | 147 | } |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @param string $perfdata : performance data as string |
159 | 159 | * @return array (status = true (oK) or false (nok), string message) |
160 | 160 | */ |
161 | - public function serviceCheckResult($host,$service,$state,$display,$perfdata='') |
|
161 | + public function serviceCheckResult($host, $service, $state, $display, $perfdata='') |
|
162 | 162 | { |
163 | 163 | //Send a POST request to the URL endpoint /v1/actions/process-check-result |
164 | 164 | //actions/process-check-result?service=example.localdomain!passive-ping6 |
@@ -177,9 +177,9 @@ discard block |
||
177 | 177 | { |
178 | 178 | return array(false, $e->getMessage()); |
179 | 179 | } |
180 | - if (property_exists($result,'error') ) |
|
180 | + if (property_exists($result, 'error')) |
|
181 | 181 | { |
182 | - if (property_exists($result,'status')) |
|
182 | + if (property_exists($result, 'status')) |
|
183 | 183 | { |
184 | 184 | $message=$result->status; |
185 | 185 | } |
@@ -187,21 +187,21 @@ discard block |
||
187 | 187 | { |
188 | 188 | $message="Unkown status"; |
189 | 189 | } |
190 | - return array(false , 'Ret code ' .$result->error.' : '.$message); |
|
190 | + return array(false, 'Ret code '.$result->error.' : '.$message); |
|
191 | 191 | } |
192 | 192 | if (property_exists($result, 'results')) |
193 | 193 | { |
194 | 194 | if (isset($result->results[0])) |
195 | 195 | { |
196 | - return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status); |
|
196 | + return array(true, 'code '.$result->results[0]->code.' : '.$result->results[0]->status); |
|
197 | 197 | } |
198 | 198 | else |
199 | 199 | { |
200 | - return array(false,'Service not found'); |
|
200 | + return array(false, 'Service not found'); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | } |
204 | - return array(false,'Unkown result, open issue with this : '.print_r($result,true)); |
|
204 | + return array(false, 'Unkown result, open issue with this : '.print_r($result, true)); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -211,18 +211,18 @@ discard block |
||
211 | 211 | */ |
212 | 212 | public function checkResultStatus(\stdClass $result) |
213 | 213 | { |
214 | - if (property_exists($result,'error') ) |
|
214 | + if (property_exists($result, 'error')) |
|
215 | 215 | { |
216 | - if (property_exists($result,'status')) |
|
216 | + if (property_exists($result, 'status')) |
|
217 | 217 | { |
218 | - throw new Exception('Ret code ' .$result->error.' : ' . $result->status); |
|
218 | + throw new Exception('Ret code '.$result->error.' : '.$result->status); |
|
219 | 219 | } |
220 | 220 | else |
221 | 221 | { |
222 | - throw new Exception('Ret code ' .$result->error.' : Unkown status'); |
|
222 | + throw new Exception('Ret code '.$result->error.' : Unkown status'); |
|
223 | 223 | } |
224 | 224 | } |
225 | - if ( ! property_exists($result, 'results')) |
|
225 | + if (!property_exists($result, 'results')) |
|
226 | 226 | { |
227 | 227 | throw new Exception('Unkown result'); |
228 | 228 | } |
@@ -238,23 +238,23 @@ discard block |
||
238 | 238 | * @return array |
239 | 239 | */ |
240 | 240 | public function request($method, $url, $headers, $body) { |
241 | - $auth = sprintf('%s:%s', $this->user, $this->pass); |
|
242 | - $curlHeaders = array("Accept: application/json"); |
|
241 | + $auth=sprintf('%s:%s', $this->user, $this->pass); |
|
242 | + $curlHeaders=array("Accept: application/json"); |
|
243 | 243 | if ($body !== null) { |
244 | - $body = json_encode($body); |
|
244 | + $body=json_encode($body); |
|
245 | 245 | array_push($curlHeaders, 'Content-Type: application/json'); |
246 | 246 | //array_push($curlHeaders, 'X-HTTP-Method-Override: GET'); |
247 | 247 | } |
248 | 248 | //var_dump($body); |
249 | 249 | //var_dump($this->url($url)); |
250 | 250 | if ($headers !== null) { |
251 | - $curlFinalHeaders = array_merge($curlHeaders, $headers); |
|
251 | + $curlFinalHeaders=array_merge($curlHeaders, $headers); |
|
252 | 252 | } else |
253 | 253 | { |
254 | 254 | $curlFinalHeaders=$curlHeaders; |
255 | 255 | } |
256 | - $curl = $this->curl(); |
|
257 | - $opts = array( |
|
256 | + $curl=$this->curl(); |
|
257 | + $opts=array( |
|
258 | 258 | CURLOPT_URL => $this->url($url), |
259 | 259 | CURLOPT_HTTPHEADER => $curlFinalHeaders, |
260 | 260 | CURLOPT_USERPWD => $auth, |
@@ -265,14 +265,14 @@ discard block |
||
265 | 265 | CURLOPT_SSL_VERIFYPEER => false, |
266 | 266 | ); |
267 | 267 | if ($body !== null) { |
268 | - $opts[CURLOPT_POSTFIELDS] = $body; |
|
268 | + $opts[CURLOPT_POSTFIELDS]=$body; |
|
269 | 269 | } |
270 | 270 | curl_setopt_array($curl, $opts); |
271 | - $res = curl_exec($curl); |
|
271 | + $res=curl_exec($curl); |
|
272 | 272 | if ($res === false) { |
273 | - throw new Exception('CURL ERROR: ' . curl_error($curl)); |
|
273 | + throw new Exception('CURL ERROR: '.curl_error($curl)); |
|
274 | 274 | } |
275 | - $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); |
|
275 | + $statusCode=curl_getinfo($curl, CURLINFO_HTTP_CODE); |
|
276 | 276 | if ($statusCode === 401) { |
277 | 277 | throw new Exception('Unable to authenticate, please check your API credentials'); |
278 | 278 | } |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | * @return array json decoded |
287 | 287 | */ |
288 | 288 | protected function fromJsonResult($json) { |
289 | - $result = @json_decode($json); |
|
289 | + $result=@json_decode($json); |
|
290 | 290 | //var_dump($json); |
291 | 291 | if ($result === null) { |
292 | 292 | throw new Exception('Parsing JSON failed: '.$this->getLastJsonErrorMessage(json_last_error())); |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | return $this->errorReference[$errorCode]; |
307 | 307 | } |
308 | 308 | |
309 | - public function standardQuery(string $urlType , string $filter, array $attributes) |
|
309 | + public function standardQuery(string $urlType, string $filter, array $attributes) |
|
310 | 310 | { |
311 | 311 | /* |
312 | 312 | * curl -k -s -u trapdirector:trapdirector -H 'X-HTTP-Method-Override: GET' -X POST 'https://localhost:5665/v1/objects/hosts' |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | {"results":[{"attrs":{"__name":"Icinga host","address":"127.0.0.1","display_name":"Icinga host","name":"Icinga host"},"joins":{},"meta":{},"name":"Icinga host","type":"Host"}]} |
316 | 316 | */ |
317 | 317 | |
318 | - if (! isset($this->queryURL[$urlType] )) |
|
318 | + if (!isset($this->queryURL[$urlType])) |
|
319 | 319 | { |
320 | 320 | throw new Exception("Unkown object type"); |
321 | 321 | } |
@@ -323,11 +323,11 @@ discard block |
||
323 | 323 | $body=array(); |
324 | 324 | if ($filter !== NULL) |
325 | 325 | { |
326 | - $body['filter'] = $filter; |
|
326 | + $body['filter']=$filter; |
|
327 | 327 | } |
328 | 328 | if (count($attributes) != 0) |
329 | 329 | { |
330 | - $body['attrs'] = $attributes; |
|
330 | + $body['attrs']=$attributes; |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | try |
@@ -342,9 +342,9 @@ discard block |
||
342 | 342 | |
343 | 343 | $numHost=0; |
344 | 344 | $hostArray=array(); |
345 | - while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs')) |
|
345 | + while (isset($result->results[$numHost]) && property_exists($result->results[$numHost], 'attrs')) |
|
346 | 346 | { |
347 | - $hostArray[$numHost] = $result->results[$numHost]->attrs; |
|
347 | + $hostArray[$numHost]=$result->results[$numHost]->attrs; |
|
348 | 348 | $numHost++; |
349 | 349 | } |
350 | 350 | return $hostArray; |
@@ -6,8 +6,8 @@ |
||
6 | 6 | $this->providePermission('trapdirector/config', $this->translate('Allow to create and modify traps services')); |
7 | 7 | |
8 | 8 | $this->provideConfigTab('config', array( |
9 | - 'title' => 'Configuration', |
|
10 | - 'url' => 'settings' |
|
9 | + 'title' => 'Configuration', |
|
10 | + 'url' => 'settings' |
|
11 | 11 | )); |
12 | 12 | |
13 | 13 | /** |
@@ -17,22 +17,22 @@ |
||
17 | 17 | )); |
18 | 18 | **/ |
19 | 19 | |
20 | -$section = $this->menuSection(N_('Traps'),array ( |
|
20 | +$section=$this->menuSection(N_('Traps'), array( |
|
21 | 21 | 'icon' => 'filter', |
22 | 22 | 'url' => 'trapdirector' |
23 | 23 | )); |
24 | 24 | |
25 | -$section->add(N_('Status & Mibs'),array( |
|
25 | +$section->add(N_('Status & Mibs'), array( |
|
26 | 26 | 'url' => 'trapdirector/status/', |
27 | 27 | 'permission' => 'trapdirector/view' |
28 | 28 | )); |
29 | 29 | |
30 | -$section->add(N_('Received'),array( |
|
30 | +$section->add(N_('Received'), array( |
|
31 | 31 | 'url' => 'trapdirector/received/', |
32 | 32 | 'permission' => 'trapdirector/view' |
33 | 33 | )); |
34 | 34 | |
35 | -$section->add(N_('Handlers'),array( |
|
35 | +$section->add(N_('Handlers'), array( |
|
36 | 36 | 'url' => 'trapdirector/handler/', |
37 | 37 | 'permission' => 'trapdirector/config' |
38 | 38 | )); |
@@ -131,9 +131,11 @@ discard block |
||
131 | 131 | $this->icingaAPI = new Icinga2API($host,$port); |
132 | 132 | $this->icingaAPI->setCredentials($user, $pass); |
133 | 133 | list($ret,$message) = $this->icingaAPI->test($this->getModuleConfig()->getapiUserPermissions()); |
134 | - if ($ret === TRUE) // On error, switch to ido DB |
|
134 | + if ($ret === TRUE) { |
|
135 | + // On error, switch to ido DB |
|
135 | 136 | { |
136 | 137 | $this->apiMode = FALSE; |
138 | + } |
|
137 | 139 | return $this->getUIDatabase(); |
138 | 140 | } |
139 | 141 | $this->apiMode = TRUE; |
@@ -213,7 +215,9 @@ discard block |
||
213 | 215 | if ($this->MIBData == null) |
214 | 216 | { |
215 | 217 | $dbConn = $this->getUIDatabase()->getDbConn(); |
216 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
218 | + if ($dbConn === null) { |
|
219 | + throw new \ErrorException('uncatched db error'); |
|
220 | + } |
|
217 | 221 | $this->MIBData=new MIBLoader( |
218 | 222 | $this->Config()->get('config', 'snmptranslate'), |
219 | 223 | $this->Config()->get('config', 'snmptranslate_dirs'), |
@@ -283,7 +287,9 @@ discard block |
||
283 | 287 | $catString=''; |
284 | 288 | foreach ($catArray as $index => $value) |
285 | 289 | { |
286 | - if ($catString != '' ) $catString .= '!'; |
|
290 | + if ($catString != '' ) { |
|
291 | + $catString .= '!'; |
|
292 | + } |
|
287 | 293 | $catString .= $index . ':' . $value; |
288 | 294 | } |
289 | 295 | $this->getUIDatabase()->setDBConfigValue('handler_categories', $catString); |
@@ -293,8 +299,12 @@ discard block |
||
293 | 299 | { |
294 | 300 | $catArray = $this->getHandlersCategory(); |
295 | 301 | $i=1; |
296 | - while (isset($catArray[$i]) && $i < 100) $i++; |
|
297 | - if ($i == 100) throw new ProgrammingError('Category array error'); |
|
302 | + while (isset($catArray[$i]) && $i < 100) { |
|
303 | + $i++; |
|
304 | + } |
|
305 | + if ($i == 100) { |
|
306 | + throw new ProgrammingError('Category array error'); |
|
307 | + } |
|
298 | 308 | $catArray[$i] = $catName; |
299 | 309 | $this->setHandlerCategory($catArray); |
300 | 310 | } |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | |
50 | 50 | |
51 | 51 | /** Get instance of TrapModuleConfig class |
52 | - * @return TrapModuleConfig |
|
53 | - */ |
|
52 | + * @return TrapModuleConfig |
|
53 | + */ |
|
54 | 54 | public function getModuleConfig() |
55 | 55 | { |
56 | 56 | if ($this->moduleConfig == Null) |
@@ -82,12 +82,12 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function getTrapHostListTable() |
84 | 84 | { |
85 | - if ($this->trapTableHostList == Null) |
|
85 | + if ($this->trapTableHostList == Null) |
|
86 | 86 | { |
87 | - $this->trapTableHostList = new TrapTableHostList(); |
|
88 | - $this->trapTableHostList->setConfig($this->getModuleConfig()); |
|
89 | - } |
|
90 | - return $this->trapTableHostList; |
|
87 | + $this->trapTableHostList = new TrapTableHostList(); |
|
88 | + $this->trapTableHostList->setConfig($this->getModuleConfig()); |
|
89 | + } |
|
90 | + return $this->trapTableHostList; |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -108,12 +108,12 @@ discard block |
||
108 | 108 | */ |
109 | 109 | public function getUIDatabase() |
110 | 110 | { |
111 | - if ($this->UIDatabase == Null) |
|
112 | - { |
|
113 | - $this->UIDatabase = new UIDatabase($this); |
|
111 | + if ($this->UIDatabase == Null) |
|
112 | + { |
|
113 | + $this->UIDatabase = new UIDatabase($this); |
|
114 | 114 | |
115 | - } |
|
116 | - return $this->UIDatabase; |
|
115 | + } |
|
116 | + return $this->UIDatabase; |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -122,41 +122,41 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public function getIdoConn() |
124 | 124 | { |
125 | - if ($this->icingaAPI === NULL) |
|
126 | - { |
|
127 | - $host = $this->Config()->get('config', 'icingaAPI_host'); |
|
128 | - if ($host == '') |
|
129 | - { |
|
130 | - $this->apiMode = FALSE; |
|
131 | - return $this->getUIDatabase(); |
|
132 | - } |
|
133 | - $port = $this->Config()->get('config', 'icingaAPI_port'); |
|
134 | - $user = $this->Config()->get('config', 'icingaAPI_user'); |
|
135 | - $pass = $this->Config()->get('config', 'icingaAPI_password'); |
|
136 | - $this->icingaAPI = new Icinga2API($host,$port); |
|
137 | - $this->icingaAPI->setCredentials($user, $pass); |
|
138 | - list($ret,$message) = $this->icingaAPI->test($this->getModuleConfig()->getapiUserPermissions()); |
|
139 | - if ($ret === TRUE) // On error, switch to ido DB |
|
140 | - { |
|
141 | - $this->apiMode = FALSE; |
|
142 | - return $this->getUIDatabase(); |
|
143 | - } |
|
144 | - $this->apiMode = TRUE; |
|
125 | + if ($this->icingaAPI === NULL) |
|
126 | + { |
|
127 | + $host = $this->Config()->get('config', 'icingaAPI_host'); |
|
128 | + if ($host == '') |
|
129 | + { |
|
130 | + $this->apiMode = FALSE; |
|
131 | + return $this->getUIDatabase(); |
|
132 | + } |
|
133 | + $port = $this->Config()->get('config', 'icingaAPI_port'); |
|
134 | + $user = $this->Config()->get('config', 'icingaAPI_user'); |
|
135 | + $pass = $this->Config()->get('config', 'icingaAPI_password'); |
|
136 | + $this->icingaAPI = new Icinga2API($host,$port); |
|
137 | + $this->icingaAPI->setCredentials($user, $pass); |
|
138 | + list($ret,$message) = $this->icingaAPI->test($this->getModuleConfig()->getapiUserPermissions()); |
|
139 | + if ($ret === TRUE) // On error, switch to ido DB |
|
140 | + { |
|
141 | + $this->apiMode = FALSE; |
|
142 | + return $this->getUIDatabase(); |
|
143 | + } |
|
144 | + $this->apiMode = TRUE; |
|
145 | 145 | |
146 | - } |
|
147 | - return $this->icingaAPI; |
|
146 | + } |
|
147 | + return $this->icingaAPI; |
|
148 | 148 | |
149 | 149 | } |
150 | 150 | |
151 | - protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null) |
|
152 | - { |
|
153 | - $limit = $this->params->get('limit', $limit); |
|
154 | - $page = $this->params->get('page', $offset); |
|
151 | + protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null) |
|
152 | + { |
|
153 | + $limit = $this->params->get('limit', $limit); |
|
154 | + $page = $this->params->get('page', $offset); |
|
155 | 155 | |
156 | - $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0); |
|
156 | + $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0); |
|
157 | 157 | |
158 | - return $paginatable; |
|
159 | - } |
|
158 | + return $paginatable; |
|
159 | + } |
|
160 | 160 | |
161 | 161 | public function displayExitError($source,$message) |
162 | 162 | { // TODO : check better ways to transmit data (with POST ?) |
@@ -165,33 +165,33 @@ discard block |
||
165 | 165 | |
166 | 166 | protected function checkReadPermission() |
167 | 167 | { |
168 | - if (! $this->Auth()->hasPermission('trapdirector/view')) { |
|
169 | - $this->displayExitError('Permissions','No permission fo view content'); |
|
170 | - } |
|
168 | + if (! $this->Auth()->hasPermission('trapdirector/view')) { |
|
169 | + $this->displayExitError('Permissions','No permission fo view content'); |
|
170 | + } |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | protected function checkConfigPermission() |
174 | 174 | { |
175 | - if (! $this->Auth()->hasPermission('trapdirector/config')) { |
|
176 | - $this->displayExitError('Permissions','No permission fo configure'); |
|
177 | - } |
|
175 | + if (! $this->Auth()->hasPermission('trapdirector/config')) { |
|
176 | + $this->displayExitError('Permissions','No permission fo configure'); |
|
177 | + } |
|
178 | 178 | } |
179 | 179 | |
180 | - /** |
|
181 | - * Check if user has write permission |
|
182 | - * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page |
|
183 | - * @return boolean : user has permission |
|
184 | - */ |
|
180 | + /** |
|
181 | + * Check if user has write permission |
|
182 | + * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page |
|
183 | + * @return boolean : user has permission |
|
184 | + */ |
|
185 | 185 | protected function checkModuleConfigPermission($check=0) |
186 | 186 | { |
187 | - if (! $this->Auth()->hasPermission('trapdirector/module_config')) { |
|
188 | - if ($check == 0) |
|
189 | - { |
|
190 | - $this->displayExitError('Permissions','No permission fo configure module'); |
|
191 | - } |
|
192 | - return false; |
|
193 | - } |
|
194 | - return true; |
|
187 | + if (! $this->Auth()->hasPermission('trapdirector/module_config')) { |
|
188 | + if ($check == 0) |
|
189 | + { |
|
190 | + $this->displayExitError('Permissions','No permission fo configure module'); |
|
191 | + } |
|
192 | + return false; |
|
193 | + } |
|
194 | + return true; |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /************************* Trap class get **********************/ |
@@ -211,18 +211,18 @@ discard block |
||
211 | 211 | /************************** MIB related **************************/ |
212 | 212 | |
213 | 213 | /** Get MIBLoader class |
214 | - * @return MIBLoader class |
|
215 | - */ |
|
214 | + * @return MIBLoader class |
|
215 | + */ |
|
216 | 216 | protected function getMIB() |
217 | 217 | { |
218 | 218 | if ($this->MIBData == null) |
219 | 219 | { |
220 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
221 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
220 | + $dbConn = $this->getUIDatabase()->getDbConn(); |
|
221 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
222 | 222 | $this->MIBData=new MIBLoader( |
223 | 223 | $this->Config()->get('config', 'snmptranslate'), |
224 | 224 | $this->Config()->get('config', 'snmptranslate_dirs'), |
225 | - $dbConn, |
|
225 | + $dbConn, |
|
226 | 226 | $this->getModuleConfig() |
227 | 227 | ); |
228 | 228 | } |
@@ -232,13 +232,13 @@ discard block |
||
232 | 232 | /************************** Database queries *******************/ |
233 | 233 | |
234 | 234 | /** Check if director is installed |
235 | - * @return bool true/false |
|
236 | - */ |
|
235 | + * @return bool true/false |
|
236 | + */ |
|
237 | 237 | protected function isDirectorInstalled() |
238 | 238 | { |
239 | - $output=array(); |
|
240 | - exec('icingacli module list',$output); |
|
241 | - foreach ($output as $line) |
|
239 | + $output=array(); |
|
240 | + exec('icingacli module list',$output); |
|
241 | + foreach ($output as $line) |
|
242 | 242 | { |
243 | 243 | if (preg_match('/^director .*enabled/',$line)) |
244 | 244 | { |
@@ -251,72 +251,72 @@ discard block |
||
251 | 251 | |
252 | 252 | /************************ UI elements **************************/ |
253 | 253 | |
254 | - /** |
|
255 | - * get max rows to display before paging. |
|
256 | - * @return number |
|
257 | - */ |
|
254 | + /** |
|
255 | + * get max rows to display before paging. |
|
256 | + * @return number |
|
257 | + */ |
|
258 | 258 | public function itemListDisplay() |
259 | 259 | { |
260 | - return $this->getUIDatabase()->getDBConfigValue('max_rows_in_list'); |
|
260 | + return $this->getUIDatabase()->getDBConfigValue('max_rows_in_list'); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | public function setitemListDisplay(int $maxRows) |
264 | 264 | { |
265 | - return $this->getUIDatabase()->setDBConfigValue('max_rows_in_list',$maxRows); |
|
265 | + return $this->getUIDatabase()->setDBConfigValue('max_rows_in_list',$maxRows); |
|
266 | 266 | } |
267 | 267 | |
268 | - /** |
|
269 | - * get Handlers categories list (index => textvalue). |
|
270 | - * @return array |
|
271 | - */ |
|
268 | + /** |
|
269 | + * get Handlers categories list (index => textvalue). |
|
270 | + * @return array |
|
271 | + */ |
|
272 | 272 | public function getHandlersCategory() |
273 | 273 | { |
274 | - //<index>:<name>!<index>:<name> |
|
275 | - $catList = $this->getUIDatabase()->getDBConfigValue('handler_categories'); |
|
276 | - $catListArray=explode('!',$catList); |
|
277 | - $retArray=array(); |
|
278 | - foreach ($catListArray as $category) |
|
279 | - { |
|
280 | - $catArray=explode(':',$category); |
|
281 | - $retArray[$catArray[0]] = $catArray[1]; |
|
282 | - } |
|
283 | - return $retArray; |
|
274 | + //<index>:<name>!<index>:<name> |
|
275 | + $catList = $this->getUIDatabase()->getDBConfigValue('handler_categories'); |
|
276 | + $catListArray=explode('!',$catList); |
|
277 | + $retArray=array(); |
|
278 | + foreach ($catListArray as $category) |
|
279 | + { |
|
280 | + $catArray=explode(':',$category); |
|
281 | + $retArray[$catArray[0]] = $catArray[1]; |
|
282 | + } |
|
283 | + return $retArray; |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | public function setHandlerCategory(array $catArray) |
287 | 287 | { |
288 | - $catString=''; |
|
289 | - foreach ($catArray as $index => $value) |
|
290 | - { |
|
291 | - if ($catString != '' ) $catString .= '!'; |
|
292 | - $catString .= $index . ':' . $value; |
|
293 | - } |
|
294 | - $this->getUIDatabase()->setDBConfigValue('handler_categories', $catString); |
|
288 | + $catString=''; |
|
289 | + foreach ($catArray as $index => $value) |
|
290 | + { |
|
291 | + if ($catString != '' ) $catString .= '!'; |
|
292 | + $catString .= $index . ':' . $value; |
|
293 | + } |
|
294 | + $this->getUIDatabase()->setDBConfigValue('handler_categories', $catString); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | public function addHandlersCategory(string $catName) |
298 | 298 | { |
299 | - $catArray = $this->getHandlersCategory(); |
|
300 | - $i=1; |
|
301 | - while (isset($catArray[$i]) && $i < 100) $i++; |
|
302 | - if ($i == 100) throw new ProgrammingError('Category array error'); |
|
303 | - $catArray[$i] = $catName; |
|
304 | - $this->setHandlerCategory($catArray); |
|
299 | + $catArray = $this->getHandlersCategory(); |
|
300 | + $i=1; |
|
301 | + while (isset($catArray[$i]) && $i < 100) $i++; |
|
302 | + if ($i == 100) throw new ProgrammingError('Category array error'); |
|
303 | + $catArray[$i] = $catName; |
|
304 | + $this->setHandlerCategory($catArray); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | public function delHandlersCategory(int $catIndex) |
308 | 308 | { |
309 | - $catArray = $this->getHandlersCategory(); |
|
310 | - unset($catArray[$catIndex]); |
|
311 | - $this->setHandlerCategory($catArray); |
|
312 | - $this->getUIDatabase()->updateHandlersOnCategoryDelete($catIndex); |
|
309 | + $catArray = $this->getHandlersCategory(); |
|
310 | + unset($catArray[$catIndex]); |
|
311 | + $this->setHandlerCategory($catArray); |
|
312 | + $this->getUIDatabase()->updateHandlersOnCategoryDelete($catIndex); |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | public function renameHandlersCategory(int $catIndex, string $catName) |
316 | 316 | { |
317 | - $catArray = $this->getHandlersCategory(); |
|
318 | - $catArray[$catIndex] = $catName; |
|
319 | - $this->setHandlerCategory($catArray); |
|
317 | + $catArray = $this->getHandlersCategory(); |
|
318 | + $catArray[$catIndex] = $catName; |
|
319 | + $this->setHandlerCategory($catArray); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | } |
@@ -39,11 +39,11 @@ discard block |
||
39 | 39 | /** @var Trap $trapClass Trap class for bin/trap_class.php */ |
40 | 40 | protected $trapClass; |
41 | 41 | /** @var UIDatabase $UIDatabase */ |
42 | - protected $UIDatabase = NULL; |
|
42 | + protected $UIDatabase=NULL; |
|
43 | 43 | /** @var Icinga2API $IcingaAPI */ |
44 | - protected $icingaAPI = NULL; |
|
44 | + protected $icingaAPI=NULL; |
|
45 | 45 | /** @var bool $apiMode connection to icinngaDB is by api (true) od ido DB (false) */ |
46 | - protected $apiMode = FALSE; |
|
46 | + protected $apiMode=FALSE; |
|
47 | 47 | |
48 | 48 | |
49 | 49 | |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | { |
61 | 61 | $this->redirectNow('trapdirector/settings?message=No database prefix'); |
62 | 62 | } |
63 | - $this->moduleConfig = new TrapModuleConfig($db_prefix); |
|
63 | + $this->moduleConfig=new TrapModuleConfig($db_prefix); |
|
64 | 64 | } |
65 | 65 | return $this->moduleConfig; |
66 | 66 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function getTrapListTable() { |
73 | 73 | if ($this->trapTableList == Null) { |
74 | - $this->trapTableList = new TrapTableList(); |
|
74 | + $this->trapTableList=new TrapTableList(); |
|
75 | 75 | $this->trapTableList->setConfig($this->getModuleConfig()); |
76 | 76 | } |
77 | 77 | return $this->trapTableList; |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | { |
85 | 85 | if ($this->trapTableHostList == Null) |
86 | 86 | { |
87 | - $this->trapTableHostList = new TrapTableHostList(); |
|
87 | + $this->trapTableHostList=new TrapTableHostList(); |
|
88 | 88 | $this->trapTableHostList->setConfig($this->getModuleConfig()); |
89 | 89 | } |
90 | 90 | return $this->trapTableHostList; |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | { |
98 | 98 | if ($this->handlerTableList == Null) |
99 | 99 | { |
100 | - $this->handlerTableList = new HandlerTableList(); |
|
100 | + $this->handlerTableList=new HandlerTableList(); |
|
101 | 101 | $this->handlerTableList->setConfig($this->getModuleConfig()); |
102 | 102 | } |
103 | 103 | return $this->handlerTableList; |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | { |
111 | 111 | if ($this->UIDatabase == Null) |
112 | 112 | { |
113 | - $this->UIDatabase = new UIDatabase($this); |
|
113 | + $this->UIDatabase=new UIDatabase($this); |
|
114 | 114 | |
115 | 115 | } |
116 | 116 | return $this->UIDatabase; |
@@ -124,56 +124,56 @@ discard block |
||
124 | 124 | { |
125 | 125 | if ($this->icingaAPI === NULL) |
126 | 126 | { |
127 | - $host = $this->Config()->get('config', 'icingaAPI_host'); |
|
127 | + $host=$this->Config()->get('config', 'icingaAPI_host'); |
|
128 | 128 | if ($host == '') |
129 | 129 | { |
130 | - $this->apiMode = FALSE; |
|
130 | + $this->apiMode=FALSE; |
|
131 | 131 | return $this->getUIDatabase(); |
132 | 132 | } |
133 | - $port = $this->Config()->get('config', 'icingaAPI_port'); |
|
134 | - $user = $this->Config()->get('config', 'icingaAPI_user'); |
|
135 | - $pass = $this->Config()->get('config', 'icingaAPI_password'); |
|
136 | - $this->icingaAPI = new Icinga2API($host,$port); |
|
133 | + $port=$this->Config()->get('config', 'icingaAPI_port'); |
|
134 | + $user=$this->Config()->get('config', 'icingaAPI_user'); |
|
135 | + $pass=$this->Config()->get('config', 'icingaAPI_password'); |
|
136 | + $this->icingaAPI=new Icinga2API($host, $port); |
|
137 | 137 | $this->icingaAPI->setCredentials($user, $pass); |
138 | - list($ret,$message) = $this->icingaAPI->test($this->getModuleConfig()->getapiUserPermissions()); |
|
138 | + list($ret, $message)=$this->icingaAPI->test($this->getModuleConfig()->getapiUserPermissions()); |
|
139 | 139 | if ($ret === TRUE) // On error, switch to ido DB |
140 | 140 | { |
141 | - $this->apiMode = FALSE; |
|
141 | + $this->apiMode=FALSE; |
|
142 | 142 | return $this->getUIDatabase(); |
143 | 143 | } |
144 | - $this->apiMode = TRUE; |
|
144 | + $this->apiMode=TRUE; |
|
145 | 145 | |
146 | 146 | } |
147 | 147 | return $this->icingaAPI; |
148 | 148 | |
149 | 149 | } |
150 | 150 | |
151 | - protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null) |
|
151 | + protected function applyPaginationLimits(Paginatable $paginatable, $limit=25, $offset=null) |
|
152 | 152 | { |
153 | - $limit = $this->params->get('limit', $limit); |
|
154 | - $page = $this->params->get('page', $offset); |
|
153 | + $limit=$this->params->get('limit', $limit); |
|
154 | + $page=$this->params->get('page', $offset); |
|
155 | 155 | |
156 | 156 | $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0); |
157 | 157 | |
158 | 158 | return $paginatable; |
159 | 159 | } |
160 | 160 | |
161 | - public function displayExitError($source,$message) |
|
161 | + public function displayExitError($source, $message) |
|
162 | 162 | { // TODO : check better ways to transmit data (with POST ?) |
163 | 163 | $this->redirectNow('trapdirector/error?source='.$source.'&message='.$message); |
164 | 164 | } |
165 | 165 | |
166 | 166 | protected function checkReadPermission() |
167 | 167 | { |
168 | - if (! $this->Auth()->hasPermission('trapdirector/view')) { |
|
169 | - $this->displayExitError('Permissions','No permission fo view content'); |
|
168 | + if (!$this->Auth()->hasPermission('trapdirector/view')) { |
|
169 | + $this->displayExitError('Permissions', 'No permission fo view content'); |
|
170 | 170 | } |
171 | 171 | } |
172 | 172 | |
173 | 173 | protected function checkConfigPermission() |
174 | 174 | { |
175 | - if (! $this->Auth()->hasPermission('trapdirector/config')) { |
|
176 | - $this->displayExitError('Permissions','No permission fo configure'); |
|
175 | + if (!$this->Auth()->hasPermission('trapdirector/config')) { |
|
176 | + $this->displayExitError('Permissions', 'No permission fo configure'); |
|
177 | 177 | } |
178 | 178 | } |
179 | 179 | |
@@ -184,10 +184,10 @@ discard block |
||
184 | 184 | */ |
185 | 185 | protected function checkModuleConfigPermission($check=0) |
186 | 186 | { |
187 | - if (! $this->Auth()->hasPermission('trapdirector/module_config')) { |
|
187 | + if (!$this->Auth()->hasPermission('trapdirector/module_config')) { |
|
188 | 188 | if ($check == 0) |
189 | 189 | { |
190 | - $this->displayExitError('Permissions','No permission fo configure module'); |
|
190 | + $this->displayExitError('Permissions', 'No permission fo configure module'); |
|
191 | 191 | } |
192 | 192 | return false; |
193 | 193 | } |
@@ -199,10 +199,10 @@ discard block |
||
199 | 199 | { // TODO : try/catch here ? or within caller |
200 | 200 | if ($this->trapClass == null) |
201 | 201 | { |
202 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
202 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
203 | 203 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
204 | 204 | //$debug_level=4; |
205 | - $this->trapClass = new Trap($icingaweb2_etc); |
|
205 | + $this->trapClass=new Trap($icingaweb2_etc); |
|
206 | 206 | //$Trap->setLogging($debug_level,'syslog'); |
207 | 207 | } |
208 | 208 | return $this->trapClass; |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | { |
218 | 218 | if ($this->MIBData == null) |
219 | 219 | { |
220 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
220 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
221 | 221 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
222 | 222 | $this->MIBData=new MIBLoader( |
223 | 223 | $this->Config()->get('config', 'snmptranslate'), |
@@ -237,10 +237,10 @@ discard block |
||
237 | 237 | protected function isDirectorInstalled() |
238 | 238 | { |
239 | 239 | $output=array(); |
240 | - exec('icingacli module list',$output); |
|
240 | + exec('icingacli module list', $output); |
|
241 | 241 | foreach ($output as $line) |
242 | 242 | { |
243 | - if (preg_match('/^director .*enabled/',$line)) |
|
243 | + if (preg_match('/^director .*enabled/', $line)) |
|
244 | 244 | { |
245 | 245 | return true; |
246 | 246 | } |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | |
263 | 263 | public function setitemListDisplay(int $maxRows) |
264 | 264 | { |
265 | - return $this->getUIDatabase()->setDBConfigValue('max_rows_in_list',$maxRows); |
|
265 | + return $this->getUIDatabase()->setDBConfigValue('max_rows_in_list', $maxRows); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
@@ -272,13 +272,13 @@ discard block |
||
272 | 272 | public function getHandlersCategory() |
273 | 273 | { |
274 | 274 | //<index>:<name>!<index>:<name> |
275 | - $catList = $this->getUIDatabase()->getDBConfigValue('handler_categories'); |
|
276 | - $catListArray=explode('!',$catList); |
|
275 | + $catList=$this->getUIDatabase()->getDBConfigValue('handler_categories'); |
|
276 | + $catListArray=explode('!', $catList); |
|
277 | 277 | $retArray=array(); |
278 | 278 | foreach ($catListArray as $category) |
279 | 279 | { |
280 | - $catArray=explode(':',$category); |
|
281 | - $retArray[$catArray[0]] = $catArray[1]; |
|
280 | + $catArray=explode(':', $category); |
|
281 | + $retArray[$catArray[0]]=$catArray[1]; |
|
282 | 282 | } |
283 | 283 | return $retArray; |
284 | 284 | } |
@@ -288,25 +288,25 @@ discard block |
||
288 | 288 | $catString=''; |
289 | 289 | foreach ($catArray as $index => $value) |
290 | 290 | { |
291 | - if ($catString != '' ) $catString .= '!'; |
|
292 | - $catString .= $index . ':' . $value; |
|
291 | + if ($catString != '') $catString.='!'; |
|
292 | + $catString.=$index.':'.$value; |
|
293 | 293 | } |
294 | 294 | $this->getUIDatabase()->setDBConfigValue('handler_categories', $catString); |
295 | 295 | } |
296 | 296 | |
297 | 297 | public function addHandlersCategory(string $catName) |
298 | 298 | { |
299 | - $catArray = $this->getHandlersCategory(); |
|
299 | + $catArray=$this->getHandlersCategory(); |
|
300 | 300 | $i=1; |
301 | 301 | while (isset($catArray[$i]) && $i < 100) $i++; |
302 | 302 | if ($i == 100) throw new ProgrammingError('Category array error'); |
303 | - $catArray[$i] = $catName; |
|
303 | + $catArray[$i]=$catName; |
|
304 | 304 | $this->setHandlerCategory($catArray); |
305 | 305 | } |
306 | 306 | |
307 | 307 | public function delHandlersCategory(int $catIndex) |
308 | 308 | { |
309 | - $catArray = $this->getHandlersCategory(); |
|
309 | + $catArray=$this->getHandlersCategory(); |
|
310 | 310 | unset($catArray[$catIndex]); |
311 | 311 | $this->setHandlerCategory($catArray); |
312 | 312 | $this->getUIDatabase()->updateHandlersOnCategoryDelete($catIndex); |
@@ -314,8 +314,8 @@ discard block |
||
314 | 314 | |
315 | 315 | public function renameHandlersCategory(int $catIndex, string $catName) |
316 | 316 | { |
317 | - $catArray = $this->getHandlersCategory(); |
|
318 | - $catArray[$catIndex] = $catName; |
|
317 | + $catArray=$this->getHandlersCategory(); |
|
318 | + $catArray[$catIndex]=$catName; |
|
319 | 319 | $this->setHandlerCategory($catArray); |
320 | 320 | } |
321 | 321 |