@@ -65,8 +65,7 @@ discard block |
||
65 | 65 | if (isset($postData['host'])) |
66 | 66 | { |
67 | 67 | $host=$postData['host']; |
68 | - } |
|
69 | - else |
|
68 | + } else |
|
70 | 69 | { |
71 | 70 | $this->_helper->json(array('status'=>'No Hosts','hostid' => -1)); |
72 | 71 | return; |
@@ -77,8 +76,7 @@ discard block |
||
77 | 76 | { |
78 | 77 | $this->_helper->json(array('status'=>'More than one host matches','hostid' => -1)); |
79 | 78 | return; |
80 | - } |
|
81 | - else if (count($hostArray) == 0) |
|
79 | + } else if (count($hostArray) == 0) |
|
82 | 80 | { |
83 | 81 | $this->_helper->json(array('status'=>'No host matches','hostid' => -1)); |
84 | 82 | return; |
@@ -114,8 +112,7 @@ discard block |
||
114 | 112 | { |
115 | 113 | $this->_helper->json(array('status'=>'More than one hostgroup matches','hostid' => -1)); |
116 | 114 | return; |
117 | - } |
|
118 | - else if (count($hostArray) == 0) |
|
115 | + } else if (count($hostArray) == 0) |
|
119 | 116 | { |
120 | 117 | $this->_helper->json(array('status'=>'No hostgroup matches','hostid' => -1)); |
121 | 118 | return; |
@@ -146,8 +143,7 @@ discard block |
||
146 | 143 | { |
147 | 144 | $traplist=$this->getMIB()->getTrapList($mib); |
148 | 145 | $retTraps=array('status'=>'OK','traps' => $traplist); |
149 | - } |
|
150 | - catch (Exception $e) |
|
146 | + } catch (Exception $e) |
|
151 | 147 | { |
152 | 148 | $retTraps=array('status' => 'Error getting mibs'); |
153 | 149 | } |
@@ -169,8 +165,7 @@ discard block |
||
169 | 165 | { |
170 | 166 | $objectlist=$this->getMIB()->getObjectList($trap); |
171 | 167 | $retObjects=array('status'=>'OK','objects' => $objectlist); |
172 | - } |
|
173 | - catch (Exception $e) |
|
168 | + } catch (Exception $e) |
|
174 | 169 | { |
175 | 170 | $retObjects=array('status' => 'not found'); |
176 | 171 | } |
@@ -185,8 +180,7 @@ discard block |
||
185 | 180 | try |
186 | 181 | { |
187 | 182 | $miblist=$this->getMIB()->getMIBList(); |
188 | - } |
|
189 | - catch (Exception $e) |
|
183 | + } catch (Exception $e) |
|
190 | 184 | { |
191 | 185 | $miblist=array('Error getting mibs'); |
192 | 186 | } |
@@ -209,8 +203,7 @@ discard block |
||
209 | 203 | { |
210 | 204 | $this->_helper->json(array('status'=>'Not found')); |
211 | 205 | return; |
212 | - } |
|
213 | - else |
|
206 | + } else |
|
214 | 207 | { |
215 | 208 | $this->_helper->json( |
216 | 209 | array('status'=>'OK', |
@@ -244,8 +237,7 @@ discard block |
||
244 | 237 | try |
245 | 238 | { |
246 | 239 | $this->setDBConfigValue('db_remove_days',$days); |
247 | - } |
|
248 | - catch (Exception $e) |
|
240 | + } catch (Exception $e) |
|
249 | 241 | { |
250 | 242 | $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
251 | 243 | return; |
@@ -263,8 +255,7 @@ discard block |
||
263 | 255 | $trap = new Trap($icingaweb2_etc); |
264 | 256 | $trap->setLogging($debug_level,'syslog'); |
265 | 257 | $trap->eraseOldTraps($days); |
266 | - } |
|
267 | - catch (Exception $e) |
|
258 | + } catch (Exception $e) |
|
268 | 259 | { |
269 | 260 | $this->_helper->json(array('status'=>'execute error : '.$e->getMessage() )); |
270 | 261 | return; |
@@ -301,14 +292,12 @@ discard block |
||
301 | 292 | $this->_helper->json(array('status'=>'File not writable : '.$file)); |
302 | 293 | return; |
303 | 294 | } |
304 | - } |
|
305 | - else |
|
295 | + } else |
|
306 | 296 | { |
307 | 297 | if ($destination != 'file') |
308 | 298 | { |
309 | 299 | $file=null; |
310 | - } |
|
311 | - else |
|
300 | + } else |
|
312 | 301 | { |
313 | 302 | $this->_helper->json(array('status'=>'No file')); |
314 | 303 | return; |
@@ -322,8 +311,7 @@ discard block |
||
322 | 311 | $this->setDBConfigValue('log_destination',$destination); |
323 | 312 | $this->setDBConfigValue('log_file',$file); |
324 | 313 | $this->setDBConfigValue('log_level',$level); |
325 | - } |
|
326 | - catch (Exception $e) |
|
314 | + } catch (Exception $e) |
|
327 | 315 | { |
328 | 316 | $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
329 | 317 | return; |
@@ -359,8 +347,7 @@ discard block |
||
359 | 347 | // Eval |
360 | 348 | $item=0; |
361 | 349 | $rule=$trap->ruleClass->evaluation($rule,$item); |
362 | - } |
|
363 | - catch (Exception $e) |
|
350 | + } catch (Exception $e) |
|
364 | 351 | { |
365 | 352 | $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() )); |
366 | 353 | return; |
@@ -393,8 +380,7 @@ discard block |
||
393 | 380 | $action=($action == 'enable') ? true : false; |
394 | 381 | $retVal=$trap->pluginClass->enablePlugin($pluginName, $action); |
395 | 382 | |
396 | - } |
|
397 | - catch (Exception $e) |
|
383 | + } catch (Exception $e) |
|
398 | 384 | { |
399 | 385 | $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
400 | 386 | return; |
@@ -402,8 +388,7 @@ discard block |
||
402 | 388 | if ($retVal === true) |
403 | 389 | { |
404 | 390 | $this->_helper->json(array('status'=>'OK')); |
405 | - } |
|
406 | - else |
|
391 | + } else |
|
407 | 392 | { |
408 | 393 | $this->_helper->json(array('status'=>'Error, see logs')); |
409 | 394 | } |
@@ -434,8 +419,7 @@ discard block |
||
434 | 419 | $functionString = $trap->ruleClass->eval_cleanup($functionString); |
435 | 420 | // Eval functions |
436 | 421 | $result = $trap->pluginClass->evaluateFunctionString($functionString); |
437 | - } |
|
438 | - catch (Exception $e) |
|
422 | + } catch (Exception $e) |
|
439 | 423 | { |
440 | 424 | $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
441 | 425 | return; |
@@ -12,8 +12,8 @@ discard block |
||
12 | 12 | { |
13 | 13 | |
14 | 14 | /** Get host list with filter (IP or name) : host=<filter> |
15 | - * returns in JSON : status=>OK/NOK hosts=>array of hosts |
|
16 | - */ |
|
15 | + * returns in JSON : status=>OK/NOK hosts=>array of hosts |
|
16 | + */ |
|
17 | 17 | public function gethostsAction() |
18 | 18 | { |
19 | 19 | $postData=$this->getRequest()->getPost(); |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | } |
33 | 33 | |
34 | 34 | /** Get hostgroup list with filter (name) : hostgroup=<hostFilter> |
35 | - * returns in JSON : status=>OK/NOK hosts=>array of hosts |
|
36 | - */ |
|
35 | + * returns in JSON : status=>OK/NOK hosts=>array of hosts |
|
36 | + */ |
|
37 | 37 | public function gethostgroupsAction() |
38 | 38 | { |
39 | 39 | $postData=$this->getRequest()->getPost(); |
@@ -52,11 +52,11 @@ discard block |
||
52 | 52 | } |
53 | 53 | |
54 | 54 | /** Get service list by host name ( host=<host> ) |
55 | - * returns in JSON : |
|
56 | - * status=>OK/No services found/More than one host matches |
|
57 | - * services=>array of services (name) |
|
58 | - * hostid = host object id or -1 if not found. |
|
59 | - */ |
|
55 | + * returns in JSON : |
|
56 | + * status=>OK/No services found/More than one host matches |
|
57 | + * services=>array of services (name) |
|
58 | + * hostid = host object id or -1 if not found. |
|
59 | + */ |
|
60 | 60 | public function getservicesAction() |
61 | 61 | { |
62 | 62 | $postData=$this->getRequest()->getPost(); |
@@ -98,11 +98,11 @@ discard block |
||
98 | 98 | } |
99 | 99 | |
100 | 100 | /** Get service list by host group ( name=<host> ) |
101 | - * returns in JSON : |
|
102 | - * status=>OK/No services found/More than one host matches |
|
103 | - * services=>array of services (name) |
|
104 | - * groupid = group object id or -1 if not found. |
|
105 | - */ |
|
101 | + * returns in JSON : |
|
102 | + * status=>OK/No services found/More than one host matches |
|
103 | + * services=>array of services (name) |
|
104 | + * groupid = group object id or -1 if not found. |
|
105 | + */ |
|
106 | 106 | public function gethostgroupservicesAction() |
107 | 107 | { |
108 | 108 | $postData=$this->getRequest()->getPost(); |
@@ -132,10 +132,10 @@ discard block |
||
132 | 132 | } |
133 | 133 | |
134 | 134 | /** Get traps from mib : entry : mib=<mib> |
135 | - * returns in JSON : |
|
136 | - * status=>OK/No mib/Error getting mibs |
|
137 | - * traps=>array of array( oid -> name) |
|
138 | - */ |
|
135 | + * returns in JSON : |
|
136 | + * status=>OK/No mib/Error getting mibs |
|
137 | + * traps=>array of array( oid -> name) |
|
138 | + */ |
|
139 | 139 | public function gettrapsAction() |
140 | 140 | { |
141 | 141 | $postData=$this->getRequest()->getPost(); |
@@ -155,10 +155,10 @@ discard block |
||
155 | 155 | } |
156 | 156 | |
157 | 157 | /** Get trap objects from mib : entry : trap=<oid> |
158 | - * returns in JSON : |
|
159 | - * status=>OK/no trap/not found |
|
160 | - * objects=>array of array( oid -> name, oid->mib) |
|
161 | - */ |
|
158 | + * returns in JSON : |
|
159 | + * status=>OK/no trap/not found |
|
160 | + * objects=>array of array( oid -> name, oid->mib) |
|
161 | + */ |
|
162 | 162 | public function gettrapobjectsAction() |
163 | 163 | { |
164 | 164 | $postData=$this->getRequest()->getPost(); |
@@ -178,8 +178,8 @@ discard block |
||
178 | 178 | } |
179 | 179 | |
180 | 180 | /** Get list of all loaded mibs : entry : none |
181 | - * return : array of strings. |
|
182 | - */ |
|
181 | + * return : array of strings. |
|
182 | + */ |
|
183 | 183 | public function getmiblistAction() |
184 | 184 | { |
185 | 185 | try |
@@ -194,10 +194,10 @@ discard block |
||
194 | 194 | } |
195 | 195 | |
196 | 196 | /** Get MIB::Name from OID : entry : oid |
197 | - * status=>OK/No oid/not found |
|
198 | - * mib=>string |
|
199 | - * name=>string |
|
200 | - */ |
|
197 | + * status=>OK/No oid/not found |
|
198 | + * mib=>string |
|
199 | + * name=>string |
|
200 | + */ |
|
201 | 201 | public function translateoidAction() |
202 | 202 | { |
203 | 203 | $postData=$this->getRequest()->getPost(); |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | 'name' => $object['name'], |
219 | 219 | 'type' => $object['type'], |
220 | 220 | 'type_enum' => $object['type_enum'], |
221 | - 'description' => $object['description'] |
|
221 | + 'description' => $object['description'] |
|
222 | 222 | ) |
223 | 223 | ); |
224 | 224 | } |
@@ -226,10 +226,10 @@ discard block |
||
226 | 226 | } |
227 | 227 | |
228 | 228 | /** Save or execute database purge of <n> days |
229 | - * days=>int |
|
230 | - * action=>save/execute |
|
231 | - * return : status=>OK/Message error |
|
232 | - */ |
|
229 | + * days=>int |
|
230 | + * action=>save/execute |
|
231 | + * return : status=>OK/Message error |
|
232 | + */ |
|
233 | 233 | public function dbmaintenanceAction() |
234 | 234 | { |
235 | 235 | |
@@ -275,11 +275,11 @@ discard block |
||
275 | 275 | } |
276 | 276 | |
277 | 277 | /** Save log output to db |
278 | - * destination=>log destination |
|
279 | - * file=>file name |
|
280 | - * level => int |
|
281 | - * return : status=>OK/Message error |
|
282 | - */ |
|
278 | + * destination=>log destination |
|
279 | + * file=>file name |
|
280 | + * level => int |
|
281 | + * return : status=>OK/Message error |
|
282 | + */ |
|
283 | 283 | public function logdestinationAction() |
284 | 284 | { |
285 | 285 | $postData=$this->getRequest()->getPost(); |
@@ -298,8 +298,8 @@ discard block |
||
298 | 298 | $fileHandler=@fopen($file,'w'); |
299 | 299 | if ($fileHandler == false) |
300 | 300 | { // File os note writabe / cannot create |
301 | - $this->_helper->json(array('status'=>'File not writable : '.$file)); |
|
302 | - return; |
|
301 | + $this->_helper->json(array('status'=>'File not writable : '.$file)); |
|
302 | + return; |
|
303 | 303 | } |
304 | 304 | } |
305 | 305 | else |
@@ -341,33 +341,33 @@ discard block |
||
341 | 341 | public function testruleAction() |
342 | 342 | { |
343 | 343 | |
344 | - $postData=$this->getRequest()->getPost(); |
|
344 | + $postData=$this->getRequest()->getPost(); |
|
345 | 345 | |
346 | - $rule = $this->checkPostVar($postData, 'rule', '.*'); |
|
346 | + $rule = $this->checkPostVar($postData, 'rule', '.*'); |
|
347 | 347 | |
348 | - $action = $this->checkPostVar($postData, 'action', 'evaluate'); |
|
348 | + $action = $this->checkPostVar($postData, 'action', 'evaluate'); |
|
349 | 349 | |
350 | - if ($action == 'evaluate') |
|
351 | - { |
|
352 | - try |
|
353 | - { |
|
354 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
355 | - $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
356 | - $trap = new Trap($icingaweb2_etc); |
|
357 | - // Cleanup spaces before eval |
|
358 | - $rule=$trap->ruleClass->eval_cleanup($rule); |
|
359 | - // Eval |
|
360 | - $item=0; |
|
361 | - $rule=$trap->ruleClass->evaluation($rule,$item); |
|
362 | - } |
|
363 | - catch (Exception $e) |
|
364 | - { |
|
365 | - $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() )); |
|
366 | - return; |
|
367 | - } |
|
368 | - $return=($rule==true)?'true':'false'; |
|
369 | - $this->_helper->json(array('status'=>'OK', 'message' => $return)); |
|
370 | - } |
|
350 | + if ($action == 'evaluate') |
|
351 | + { |
|
352 | + try |
|
353 | + { |
|
354 | + require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
355 | + $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
356 | + $trap = new Trap($icingaweb2_etc); |
|
357 | + // Cleanup spaces before eval |
|
358 | + $rule=$trap->ruleClass->eval_cleanup($rule); |
|
359 | + // Eval |
|
360 | + $item=0; |
|
361 | + $rule=$trap->ruleClass->evaluation($rule,$item); |
|
362 | + } |
|
363 | + catch (Exception $e) |
|
364 | + { |
|
365 | + $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() )); |
|
366 | + return; |
|
367 | + } |
|
368 | + $return=($rule==true)?'true':'false'; |
|
369 | + $this->_helper->json(array('status'=>'OK', 'message' => $return)); |
|
370 | + } |
|
371 | 371 | |
372 | 372 | } |
373 | 373 | |
@@ -378,35 +378,35 @@ discard block |
||
378 | 378 | */ |
379 | 379 | public function pluginAction() |
380 | 380 | { |
381 | - $postData=$this->getRequest()->getPost(); |
|
381 | + $postData=$this->getRequest()->getPost(); |
|
382 | 382 | |
383 | - $pluginName = $this->checkPostVar($postData, 'name', '.*'); |
|
383 | + $pluginName = $this->checkPostVar($postData, 'name', '.*'); |
|
384 | 384 | |
385 | - $action = $this->checkPostVar($postData, 'action', 'enable|disable'); |
|
385 | + $action = $this->checkPostVar($postData, 'action', 'enable|disable'); |
|
386 | 386 | |
387 | - try |
|
388 | - { |
|
389 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
390 | - $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
391 | - $trap = new Trap($icingaweb2_etc); |
|
392 | - // Enable plugin. |
|
393 | - $action=($action == 'enable') ? true : false; |
|
394 | - $retVal=$trap->pluginClass->enablePlugin($pluginName, $action); |
|
387 | + try |
|
388 | + { |
|
389 | + require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
390 | + $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
391 | + $trap = new Trap($icingaweb2_etc); |
|
392 | + // Enable plugin. |
|
393 | + $action=($action == 'enable') ? true : false; |
|
394 | + $retVal=$trap->pluginClass->enablePlugin($pluginName, $action); |
|
395 | 395 | |
396 | - } |
|
397 | - catch (Exception $e) |
|
398 | - { |
|
399 | - $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
400 | - return; |
|
401 | - } |
|
402 | - if ($retVal === true) |
|
403 | - { |
|
404 | - $this->_helper->json(array('status'=>'OK')); |
|
405 | - } |
|
406 | - else |
|
407 | - { |
|
408 | - $this->_helper->json(array('status'=>'Error, see logs')); |
|
409 | - } |
|
396 | + } |
|
397 | + catch (Exception $e) |
|
398 | + { |
|
399 | + $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
400 | + return; |
|
401 | + } |
|
402 | + if ($retVal === true) |
|
403 | + { |
|
404 | + $this->_helper->json(array('status'=>'OK')); |
|
405 | + } |
|
406 | + else |
|
407 | + { |
|
408 | + $this->_helper->json(array('status'=>'Error, see logs')); |
|
409 | + } |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | /** Function evaluation |
@@ -416,49 +416,49 @@ discard block |
||
416 | 416 | */ |
417 | 417 | public function functionAction() |
418 | 418 | { |
419 | - $postData=$this->getRequest()->getPost(); |
|
419 | + $postData=$this->getRequest()->getPost(); |
|
420 | 420 | |
421 | - $functionString = $this->checkPostVar($postData, 'function', '.*'); |
|
421 | + $functionString = $this->checkPostVar($postData, 'function', '.*'); |
|
422 | 422 | |
423 | - $this->checkPostVar($postData, 'action', 'evaluate'); |
|
423 | + $this->checkPostVar($postData, 'action', 'evaluate'); |
|
424 | 424 | |
425 | - // Only one action possible for now, no tests on action. |
|
426 | - try |
|
427 | - { |
|
428 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
429 | - $icingaweb2Etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
430 | - $trap = new Trap($icingaweb2Etc); |
|
431 | - // load all plugins in case tested function is not enabled. |
|
432 | - $trap->pluginClass->registerAllPlugins(false); |
|
433 | - // Clean all spaces |
|
434 | - $functionString = $trap->ruleClass->eval_cleanup($functionString); |
|
435 | - // Eval functions |
|
436 | - $result = $trap->pluginClass->evaluateFunctionString($functionString); |
|
437 | - } |
|
438 | - catch (Exception $e) |
|
439 | - { |
|
440 | - $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
441 | - return; |
|
442 | - } |
|
425 | + // Only one action possible for now, no tests on action. |
|
426 | + try |
|
427 | + { |
|
428 | + require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
429 | + $icingaweb2Etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
430 | + $trap = new Trap($icingaweb2Etc); |
|
431 | + // load all plugins in case tested function is not enabled. |
|
432 | + $trap->pluginClass->registerAllPlugins(false); |
|
433 | + // Clean all spaces |
|
434 | + $functionString = $trap->ruleClass->eval_cleanup($functionString); |
|
435 | + // Eval functions |
|
436 | + $result = $trap->pluginClass->evaluateFunctionString($functionString); |
|
437 | + } |
|
438 | + catch (Exception $e) |
|
439 | + { |
|
440 | + $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
441 | + return; |
|
442 | + } |
|
443 | 443 | |
444 | - $result = ($result === true)?'True':'False'; |
|
445 | - $this->_helper->json(array('status'=>'OK','message' => $result)); |
|
444 | + $result = ($result === true)?'True':'False'; |
|
445 | + $this->_helper->json(array('status'=>'OK','message' => $result)); |
|
446 | 446 | } |
447 | 447 | |
448 | - /************** Utilities **********************/ |
|
448 | + /************** Utilities **********************/ |
|
449 | 449 | |
450 | 450 | private function checkPostVar(array $postData,string $postVar, string $validRegexp) : string |
451 | 451 | { |
452 | - if (!isset ($postData[$postVar])) |
|
453 | - { |
|
454 | - $this->_helper->json(array('status'=>'No ' . $postVar)); |
|
455 | - return ''; |
|
456 | - } |
|
457 | - if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1) |
|
458 | - { |
|
459 | - $this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar])); |
|
460 | - return ''; |
|
461 | - } |
|
462 | - return $postData[$postVar]; |
|
452 | + if (!isset ($postData[$postVar])) |
|
453 | + { |
|
454 | + $this->_helper->json(array('status'=>'No ' . $postVar)); |
|
455 | + return ''; |
|
456 | + } |
|
457 | + if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1) |
|
458 | + { |
|
459 | + $this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar])); |
|
460 | + return ''; |
|
461 | + } |
|
462 | + return $postData[$postVar]; |
|
463 | 463 | } |
464 | 464 | } |
@@ -18,14 +18,14 @@ discard block |
||
18 | 18 | { |
19 | 19 | $postData=$this->getRequest()->getPost(); |
20 | 20 | |
21 | - $hostFilter = $this->checkPostVar($postData, 'hostFilter', '.*'); |
|
21 | + $hostFilter=$this->checkPostVar($postData, 'hostFilter', '.*'); |
|
22 | 22 | |
23 | - $retHosts=array('status'=>'OK','hosts' => array()); |
|
23 | + $retHosts=array('status'=>'OK', 'hosts' => array()); |
|
24 | 24 | |
25 | 25 | $hosts=$this->getHostByIP($hostFilter); |
26 | 26 | foreach ($hosts as $val) |
27 | 27 | { |
28 | - array_push($retHosts['hosts'],$val->name); |
|
28 | + array_push($retHosts['hosts'], $val->name); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | $this->_helper->json($retHosts); |
@@ -38,14 +38,14 @@ discard block |
||
38 | 38 | { |
39 | 39 | $postData=$this->getRequest()->getPost(); |
40 | 40 | |
41 | - $hostFilter = $this->checkPostVar($postData, 'hostFilter', '.*'); |
|
41 | + $hostFilter=$this->checkPostVar($postData, 'hostFilter', '.*'); |
|
42 | 42 | |
43 | - $retHosts=array('status'=>'OK','hosts' => array()); |
|
43 | + $retHosts=array('status'=>'OK', 'hosts' => array()); |
|
44 | 44 | |
45 | 45 | $hosts=$this->getHostGroupByName($hostFilter); |
46 | 46 | foreach ($hosts as $val) |
47 | 47 | { |
48 | - array_push($retHosts['hosts'],$val->name); |
|
48 | + array_push($retHosts['hosts'], $val->name); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | $this->_helper->json($retHosts); |
@@ -68,31 +68,31 @@ discard block |
||
68 | 68 | } |
69 | 69 | else |
70 | 70 | { |
71 | - $this->_helper->json(array('status'=>'No Hosts','hostid' => -1)); |
|
71 | + $this->_helper->json(array('status'=>'No Hosts', 'hostid' => -1)); |
|
72 | 72 | return; |
73 | 73 | } |
74 | 74 | |
75 | 75 | $hostArray=$this->getHostByName($host); |
76 | 76 | if (count($hostArray) > 1) |
77 | 77 | { |
78 | - $this->_helper->json(array('status'=>'More than one host matches','hostid' => -1)); |
|
78 | + $this->_helper->json(array('status'=>'More than one host matches', 'hostid' => -1)); |
|
79 | 79 | return; |
80 | 80 | } |
81 | 81 | else if (count($hostArray) == 0) |
82 | 82 | { |
83 | - $this->_helper->json(array('status'=>'No host matches','hostid' => -1)); |
|
83 | + $this->_helper->json(array('status'=>'No host matches', 'hostid' => -1)); |
|
84 | 84 | return; |
85 | 85 | } |
86 | 86 | $services=$this->getServicesByHostid($hostArray[0]->id); |
87 | 87 | if (count($services) < 1) |
88 | 88 | { |
89 | - $this->_helper->json(array('status'=>'No services found for host','hostid' => $hostArray[0]->id)); |
|
89 | + $this->_helper->json(array('status'=>'No services found for host', 'hostid' => $hostArray[0]->id)); |
|
90 | 90 | return; |
91 | 91 | } |
92 | - $retServices=array('status'=>'OK','services' => array(),'hostid' => $hostArray[0]->id); |
|
92 | + $retServices=array('status'=>'OK', 'services' => array(), 'hostid' => $hostArray[0]->id); |
|
93 | 93 | foreach ($services as $val) |
94 | 94 | { |
95 | - array_push($retServices['services'],array($val->id , $val->name)); |
|
95 | + array_push($retServices['services'], array($val->id, $val->name)); |
|
96 | 96 | } |
97 | 97 | $this->_helper->json($retServices); |
98 | 98 | } |
@@ -107,26 +107,26 @@ discard block |
||
107 | 107 | { |
108 | 108 | $postData=$this->getRequest()->getPost(); |
109 | 109 | |
110 | - $host = $this->checkPostVar($postData, 'host', '.+'); |
|
110 | + $host=$this->checkPostVar($postData, 'host', '.+'); |
|
111 | 111 | |
112 | 112 | $hostArray=$this->getHostGroupByName($host); |
113 | 113 | if (count($hostArray) > 1) |
114 | 114 | { |
115 | - $this->_helper->json(array('status'=>'More than one hostgroup matches','hostid' => -1)); |
|
115 | + $this->_helper->json(array('status'=>'More than one hostgroup matches', 'hostid' => -1)); |
|
116 | 116 | return; |
117 | 117 | } |
118 | 118 | else if (count($hostArray) == 0) |
119 | 119 | { |
120 | - $this->_helper->json(array('status'=>'No hostgroup matches','hostid' => -1)); |
|
120 | + $this->_helper->json(array('status'=>'No hostgroup matches', 'hostid' => -1)); |
|
121 | 121 | return; |
122 | 122 | } |
123 | 123 | $services=$this->getServicesByHostGroupid($hostArray[0]->id); |
124 | 124 | if (count($services) < 1) |
125 | 125 | { |
126 | - $this->_helper->json(array('status'=>'No services found for hostgroup','hostid' => $hostArray[0]->id)); |
|
126 | + $this->_helper->json(array('status'=>'No services found for hostgroup', 'hostid' => $hostArray[0]->id)); |
|
127 | 127 | return; |
128 | 128 | } |
129 | - $retServices=array('status'=>'OK','services' => $services,'hostid' => $hostArray[0]->id); |
|
129 | + $retServices=array('status'=>'OK', 'services' => $services, 'hostid' => $hostArray[0]->id); |
|
130 | 130 | |
131 | 131 | $this->_helper->json($retServices); |
132 | 132 | } |
@@ -140,12 +140,12 @@ discard block |
||
140 | 140 | { |
141 | 141 | $postData=$this->getRequest()->getPost(); |
142 | 142 | |
143 | - $mib = $this->checkPostVar($postData, 'mib', '.*'); |
|
143 | + $mib=$this->checkPostVar($postData, 'mib', '.*'); |
|
144 | 144 | |
145 | 145 | try |
146 | 146 | { |
147 | 147 | $traplist=$this->getMIB()->getTrapList($mib); |
148 | - $retTraps=array('status'=>'OK','traps' => $traplist); |
|
148 | + $retTraps=array('status'=>'OK', 'traps' => $traplist); |
|
149 | 149 | } |
150 | 150 | catch (Exception $e) |
151 | 151 | { |
@@ -163,12 +163,12 @@ discard block |
||
163 | 163 | { |
164 | 164 | $postData=$this->getRequest()->getPost(); |
165 | 165 | |
166 | - $trap = $this->checkPostVar($postData, 'trap', '.*'); |
|
166 | + $trap=$this->checkPostVar($postData, 'trap', '.*'); |
|
167 | 167 | |
168 | 168 | try |
169 | 169 | { |
170 | 170 | $objectlist=$this->getMIB()->getObjectList($trap); |
171 | - $retObjects=array('status'=>'OK','objects' => $objectlist); |
|
171 | + $retObjects=array('status'=>'OK', 'objects' => $objectlist); |
|
172 | 172 | } |
173 | 173 | catch (Exception $e) |
174 | 174 | { |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | { |
203 | 203 | $postData=$this->getRequest()->getPost(); |
204 | 204 | |
205 | - $oid = $this->checkPostVar($postData, 'oid', '.*'); |
|
205 | + $oid=$this->checkPostVar($postData, 'oid', '.*'); |
|
206 | 206 | |
207 | 207 | // Try to get oid name from snmptranslate |
208 | 208 | if (($object=$this->getMIB()->translateOID($oid)) == null) |
@@ -235,19 +235,19 @@ discard block |
||
235 | 235 | |
236 | 236 | $postData=$this->getRequest()->getPost(); |
237 | 237 | |
238 | - $days = $this->checkPostVar($postData, 'days', '^[0-9]+$'); |
|
238 | + $days=$this->checkPostVar($postData, 'days', '^[0-9]+$'); |
|
239 | 239 | |
240 | - $action = $this->checkPostVar($postData, 'action', 'save|execute'); |
|
240 | + $action=$this->checkPostVar($postData, 'action', 'save|execute'); |
|
241 | 241 | |
242 | 242 | if ($action == 'save') |
243 | 243 | { |
244 | 244 | try |
245 | 245 | { |
246 | - $this->setDBConfigValue('db_remove_days',$days); |
|
246 | + $this->setDBConfigValue('db_remove_days', $days); |
|
247 | 247 | } |
248 | 248 | catch (Exception $e) |
249 | 249 | { |
250 | - $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
|
250 | + $this->_helper->json(array('status'=>'Save error : '.$e->getMessage())); |
|
251 | 251 | return; |
252 | 252 | } |
253 | 253 | $this->_helper->json(array('status'=>'OK')); |
@@ -257,16 +257,16 @@ discard block |
||
257 | 257 | { |
258 | 258 | try |
259 | 259 | { |
260 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
260 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
261 | 261 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
262 | 262 | $debug_level=4; |
263 | - $trap = new Trap($icingaweb2_etc); |
|
264 | - $trap->setLogging($debug_level,'syslog'); |
|
263 | + $trap=new Trap($icingaweb2_etc); |
|
264 | + $trap->setLogging($debug_level, 'syslog'); |
|
265 | 265 | $trap->eraseOldTraps($days); |
266 | 266 | } |
267 | 267 | catch (Exception $e) |
268 | 268 | { |
269 | - $this->_helper->json(array('status'=>'execute error : '.$e->getMessage() )); |
|
269 | + $this->_helper->json(array('status'=>'execute error : '.$e->getMessage())); |
|
270 | 270 | return; |
271 | 271 | } |
272 | 272 | $this->_helper->json(array('status'=>'OK')); |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | { |
285 | 285 | $postData=$this->getRequest()->getPost(); |
286 | 286 | |
287 | - $destination = $this->checkPostVar($postData, 'destination', '.*'); |
|
287 | + $destination=$this->checkPostVar($postData, 'destination', '.*'); |
|
288 | 288 | $logDest=$this->getModuleConfig()->getLogDestinations(); |
289 | 289 | if (!isset($logDest[$destination])) |
290 | 290 | { |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | if (isset($postData['file'])) |
296 | 296 | { |
297 | 297 | $file=$postData['file']; |
298 | - $fileHandler=@fopen($file,'w'); |
|
298 | + $fileHandler=@fopen($file, 'w'); |
|
299 | 299 | if ($fileHandler == false) |
300 | 300 | { // File os note writabe / cannot create |
301 | 301 | $this->_helper->json(array('status'=>'File not writable : '.$file)); |
@@ -315,17 +315,17 @@ discard block |
||
315 | 315 | } |
316 | 316 | } |
317 | 317 | |
318 | - $level = $this->checkPostVar($postData, 'level', '[0-9]'); |
|
318 | + $level=$this->checkPostVar($postData, 'level', '[0-9]'); |
|
319 | 319 | |
320 | 320 | try |
321 | 321 | { |
322 | - $this->setDBConfigValue('log_destination',$destination); |
|
323 | - $this->setDBConfigValue('log_file',$file); |
|
324 | - $this->setDBConfigValue('log_level',$level); |
|
322 | + $this->setDBConfigValue('log_destination', $destination); |
|
323 | + $this->setDBConfigValue('log_file', $file); |
|
324 | + $this->setDBConfigValue('log_level', $level); |
|
325 | 325 | } |
326 | 326 | catch (Exception $e) |
327 | 327 | { |
328 | - $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
|
328 | + $this->_helper->json(array('status'=>'Save error : '.$e->getMessage())); |
|
329 | 329 | return; |
330 | 330 | } |
331 | 331 | $this->_helper->json(array('status'=>'OK')); |
@@ -343,29 +343,29 @@ discard block |
||
343 | 343 | |
344 | 344 | $postData=$this->getRequest()->getPost(); |
345 | 345 | |
346 | - $rule = $this->checkPostVar($postData, 'rule', '.*'); |
|
346 | + $rule=$this->checkPostVar($postData, 'rule', '.*'); |
|
347 | 347 | |
348 | - $action = $this->checkPostVar($postData, 'action', 'evaluate'); |
|
348 | + $action=$this->checkPostVar($postData, 'action', 'evaluate'); |
|
349 | 349 | |
350 | 350 | if ($action == 'evaluate') |
351 | 351 | { |
352 | 352 | try |
353 | 353 | { |
354 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
354 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
355 | 355 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
356 | - $trap = new Trap($icingaweb2_etc); |
|
356 | + $trap=new Trap($icingaweb2_etc); |
|
357 | 357 | // Cleanup spaces before eval |
358 | 358 | $rule=$trap->ruleClass->eval_cleanup($rule); |
359 | 359 | // Eval |
360 | 360 | $item=0; |
361 | - $rule=$trap->ruleClass->evaluation($rule,$item); |
|
361 | + $rule=$trap->ruleClass->evaluation($rule, $item); |
|
362 | 362 | } |
363 | 363 | catch (Exception $e) |
364 | 364 | { |
365 | - $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() )); |
|
365 | + $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage())); |
|
366 | 366 | return; |
367 | 367 | } |
368 | - $return=($rule==true)?'true':'false'; |
|
368 | + $return=($rule == true) ? 'true' : 'false'; |
|
369 | 369 | $this->_helper->json(array('status'=>'OK', 'message' => $return)); |
370 | 370 | } |
371 | 371 | |
@@ -380,15 +380,15 @@ discard block |
||
380 | 380 | { |
381 | 381 | $postData=$this->getRequest()->getPost(); |
382 | 382 | |
383 | - $pluginName = $this->checkPostVar($postData, 'name', '.*'); |
|
383 | + $pluginName=$this->checkPostVar($postData, 'name', '.*'); |
|
384 | 384 | |
385 | - $action = $this->checkPostVar($postData, 'action', 'enable|disable'); |
|
385 | + $action=$this->checkPostVar($postData, 'action', 'enable|disable'); |
|
386 | 386 | |
387 | 387 | try |
388 | 388 | { |
389 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
389 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
390 | 390 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
391 | - $trap = new Trap($icingaweb2_etc); |
|
391 | + $trap=new Trap($icingaweb2_etc); |
|
392 | 392 | // Enable plugin. |
393 | 393 | $action=($action == 'enable') ? true : false; |
394 | 394 | $retVal=$trap->pluginClass->enablePlugin($pluginName, $action); |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | } |
397 | 397 | catch (Exception $e) |
398 | 398 | { |
399 | - $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
399 | + $this->_helper->json(array('status'=>'Action error : '.$e->getMessage())); |
|
400 | 400 | return; |
401 | 401 | } |
402 | 402 | if ($retVal === true) |
@@ -418,45 +418,45 @@ discard block |
||
418 | 418 | { |
419 | 419 | $postData=$this->getRequest()->getPost(); |
420 | 420 | |
421 | - $functionString = $this->checkPostVar($postData, 'function', '.*'); |
|
421 | + $functionString=$this->checkPostVar($postData, 'function', '.*'); |
|
422 | 422 | |
423 | 423 | $this->checkPostVar($postData, 'action', 'evaluate'); |
424 | 424 | |
425 | 425 | // Only one action possible for now, no tests on action. |
426 | 426 | try |
427 | 427 | { |
428 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
428 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
429 | 429 | $icingaweb2Etc=$this->Config()->get('config', 'icingaweb2_etc'); |
430 | - $trap = new Trap($icingaweb2Etc); |
|
430 | + $trap=new Trap($icingaweb2Etc); |
|
431 | 431 | // load all plugins in case tested function is not enabled. |
432 | 432 | $trap->pluginClass->registerAllPlugins(false); |
433 | 433 | // Clean all spaces |
434 | - $functionString = $trap->ruleClass->eval_cleanup($functionString); |
|
434 | + $functionString=$trap->ruleClass->eval_cleanup($functionString); |
|
435 | 435 | // Eval functions |
436 | - $result = $trap->pluginClass->evaluateFunctionString($functionString); |
|
436 | + $result=$trap->pluginClass->evaluateFunctionString($functionString); |
|
437 | 437 | } |
438 | 438 | catch (Exception $e) |
439 | 439 | { |
440 | - $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
440 | + $this->_helper->json(array('status'=>'Action error : '.$e->getMessage())); |
|
441 | 441 | return; |
442 | 442 | } |
443 | 443 | |
444 | - $result = ($result === true)?'True':'False'; |
|
445 | - $this->_helper->json(array('status'=>'OK','message' => $result)); |
|
444 | + $result=($result === true) ? 'True' : 'False'; |
|
445 | + $this->_helper->json(array('status'=>'OK', 'message' => $result)); |
|
446 | 446 | } |
447 | 447 | |
448 | 448 | /************** Utilities **********************/ |
449 | 449 | |
450 | - private function checkPostVar(array $postData,string $postVar, string $validRegexp) : string |
|
450 | + private function checkPostVar(array $postData, string $postVar, string $validRegexp) : string |
|
451 | 451 | { |
452 | 452 | if (!isset ($postData[$postVar])) |
453 | 453 | { |
454 | - $this->_helper->json(array('status'=>'No ' . $postVar)); |
|
454 | + $this->_helper->json(array('status'=>'No '.$postVar)); |
|
455 | 455 | return ''; |
456 | 456 | } |
457 | 457 | if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1) |
458 | 458 | { |
459 | - $this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar])); |
|
459 | + $this->_helper->json(array('status'=>'Unknown '.$postVar.' value '.$postData[$postVar])); |
|
460 | 460 | return ''; |
461 | 461 | } |
462 | 462 | return $postData[$postVar]; |
@@ -21,104 +21,104 @@ |
||
21 | 21 | */ |
22 | 22 | class NetworkRule extends PluginTemplate |
23 | 23 | { |
24 | - /** @var string $description Description of plugin */ |
|
25 | - public $description='Network functions to use into rules |
|
24 | + /** @var string $description Description of plugin */ |
|
25 | + public $description='Network functions to use into rules |
|
26 | 26 | test test test'; |
27 | 27 | |
28 | - /** @var array[] $functions Functions of this plugin for rule eval. |
|
29 | - * If no functions are declared, set to empty array |
|
30 | - * $functions[<name>]['function'] : Name of the function to be called in this class |
|
31 | - * $functions[<name>]['params'] : Description of input parameters of function. |
|
32 | - * $functions[<name>]['description'] : Description. Can be multiline. |
|
33 | - */ |
|
34 | - public $functions=array( |
|
35 | - 'inNetwork' => array( // The name of the function in rules |
|
36 | - 'function' => 'isInNetwork', // Name of the function |
|
37 | - 'params' => '<IP to test>,<Network IP>,<Network mask (CIDR)>', // parameters description |
|
38 | - 'description' => 'Test if IP is in network, ex : __inNetwork(192.168.123.5,192.168.123.0,24) returns true |
|
28 | + /** @var array[] $functions Functions of this plugin for rule eval. |
|
29 | + * If no functions are declared, set to empty array |
|
30 | + * $functions[<name>]['function'] : Name of the function to be called in this class |
|
31 | + * $functions[<name>]['params'] : Description of input parameters of function. |
|
32 | + * $functions[<name>]['description'] : Description. Can be multiline. |
|
33 | + */ |
|
34 | + public $functions=array( |
|
35 | + 'inNetwork' => array( // The name of the function in rules |
|
36 | + 'function' => 'isInNetwork', // Name of the function |
|
37 | + 'params' => '<IP to test>,<Network IP>,<Network mask (CIDR)>', // parameters description |
|
38 | + 'description' => 'Test if IP is in network, ex : __inNetwork(192.168.123.5,192.168.123.0,24) returns true |
|
39 | 39 | Does not work with IPV6' // Description (can be multiline). |
40 | - ), |
|
41 | - 'test' => array( // The name of the function in rules |
|
42 | - 'function' => 'testParam', // Name of the function |
|
43 | - 'params' => '<boolean to return as string>', // parameters description |
|
44 | - 'description' => 'Returns value passed as argument' // Description (can be multiline). |
|
45 | - ) |
|
46 | - ); |
|
40 | + ), |
|
41 | + 'test' => array( // The name of the function in rules |
|
42 | + 'function' => 'testParam', // Name of the function |
|
43 | + 'params' => '<boolean to return as string>', // parameters description |
|
44 | + 'description' => 'Returns value passed as argument' // Description (can be multiline). |
|
45 | + ) |
|
46 | + ); |
|
47 | 47 | |
48 | - /** @var boolean $catchAllTraps Set to true if all traps will be sent to the plugin NOT IMPLEMENTED */ |
|
49 | - public $catchAllTraps=false; |
|
48 | + /** @var boolean $catchAllTraps Set to true if all traps will be sent to the plugin NOT IMPLEMENTED */ |
|
49 | + public $catchAllTraps=false; |
|
50 | 50 | |
51 | - /** @var boolean $processTraps Set to true if plugins can handle traps NOT IMPLEMENTED */ |
|
52 | - public $processTraps=false; |
|
51 | + /** @var boolean $processTraps Set to true if plugins can handle traps NOT IMPLEMENTED */ |
|
52 | + public $processTraps=false; |
|
53 | 53 | |
54 | - /** |
|
55 | - * Constructor. Can throw exceptions on error, but no logging at this point. |
|
56 | - * @throws \Exception |
|
57 | - * @return \Trapdirector\Plugins\NetworkRule |
|
58 | - */ |
|
59 | - function __construct() |
|
60 | - { |
|
61 | - $this->name=basename(__FILE__,'.php'); |
|
62 | - return $this; |
|
63 | - } |
|
54 | + /** |
|
55 | + * Constructor. Can throw exceptions on error, but no logging at this point. |
|
56 | + * @throws \Exception |
|
57 | + * @return \Trapdirector\Plugins\NetworkRule |
|
58 | + */ |
|
59 | + function __construct() |
|
60 | + { |
|
61 | + $this->name=basename(__FILE__,'.php'); |
|
62 | + return $this; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Function called by trapdirector if found in rules |
|
67 | - * Parameters check has to be done in function. |
|
68 | - * @param array $params Function parameters |
|
69 | - * @throws Exception |
|
70 | - * @return bool Evaluation |
|
71 | - */ |
|
72 | - public function isInNetwork(array $params) : bool |
|
73 | - { |
|
74 | - // Check param numbers and thrown exception if not correct. |
|
75 | - if (count($params)!=3) |
|
76 | - { |
|
77 | - throw new Exception('Invalid number of parameters : ' . count($params)); |
|
78 | - } |
|
65 | + /** |
|
66 | + * Function called by trapdirector if found in rules |
|
67 | + * Parameters check has to be done in function. |
|
68 | + * @param array $params Function parameters |
|
69 | + * @throws Exception |
|
70 | + * @return bool Evaluation |
|
71 | + */ |
|
72 | + public function isInNetwork(array $params) : bool |
|
73 | + { |
|
74 | + // Check param numbers and thrown exception if not correct. |
|
75 | + if (count($params)!=3) |
|
76 | + { |
|
77 | + throw new Exception('Invalid number of parameters : ' . count($params)); |
|
78 | + } |
|
79 | 79 | |
80 | - $ip = $params[0]; |
|
81 | - $net = $params[1]; |
|
82 | - $masq = $params[2]; |
|
80 | + $ip = $params[0]; |
|
81 | + $net = $params[1]; |
|
82 | + $masq = $params[2]; |
|
83 | 83 | |
84 | 84 | |
85 | - $this->log('#'. $ip . '# / #' . $net . '# / #' . $masq,DEBUG); |
|
85 | + $this->log('#'. $ip . '# / #' . $net . '# / #' . $masq,DEBUG); |
|
86 | 86 | |
87 | - $ip2 = ip2long($ip); |
|
88 | - $net2 = ip2long($net); |
|
87 | + $ip2 = ip2long($ip); |
|
88 | + $net2 = ip2long($net); |
|
89 | 89 | |
90 | - if ($ip2 === false ) |
|
91 | - { |
|
92 | - $this->log('Invalid IP : #' . $ip.'#',WARN); |
|
93 | - throw new Exception('Invalid IP'); |
|
94 | - } |
|
95 | - if ($net2 === false) |
|
96 | - { |
|
97 | - $this->log('Invalid network',WARN); |
|
98 | - throw new Exception('Invalid net'); |
|
99 | - } |
|
100 | - if ($masq<1 || $masq > 32) |
|
101 | - { |
|
102 | - $this->log('Invalid masq',WARN); |
|
103 | - throw new Exception('Invalid net masq'); |
|
104 | - } |
|
105 | - // $range is in IP/CIDR format eg 127.0.0.1/24 |
|
90 | + if ($ip2 === false ) |
|
91 | + { |
|
92 | + $this->log('Invalid IP : #' . $ip.'#',WARN); |
|
93 | + throw new Exception('Invalid IP'); |
|
94 | + } |
|
95 | + if ($net2 === false) |
|
96 | + { |
|
97 | + $this->log('Invalid network',WARN); |
|
98 | + throw new Exception('Invalid net'); |
|
99 | + } |
|
100 | + if ($masq<1 || $masq > 32) |
|
101 | + { |
|
102 | + $this->log('Invalid masq',WARN); |
|
103 | + throw new Exception('Invalid net masq'); |
|
104 | + } |
|
105 | + // $range is in IP/CIDR format eg 127.0.0.1/24 |
|
106 | 106 | |
107 | - $masq = pow( 2, ( 32 - $masq ) ) - 1; |
|
108 | - $masq = ~ $masq; |
|
109 | - return ( ( $ip2 & $masq ) == ( $net2 & $masq ) ); |
|
107 | + $masq = pow( 2, ( 32 - $masq ) ) - 1; |
|
108 | + $masq = ~ $masq; |
|
109 | + return ( ( $ip2 & $masq ) == ( $net2 & $masq ) ); |
|
110 | 110 | |
111 | - } |
|
111 | + } |
|
112 | 112 | |
113 | - public function testParam(array $param) |
|
114 | - { |
|
115 | - if (count($param)!=1) |
|
116 | - { |
|
117 | - throw new Exception('Invalid number of parameters : ' . count($param)); |
|
118 | - } |
|
119 | - if ($param[0] == 'true') return true; |
|
120 | - return false; |
|
121 | - } |
|
113 | + public function testParam(array $param) |
|
114 | + { |
|
115 | + if (count($param)!=1) |
|
116 | + { |
|
117 | + throw new Exception('Invalid number of parameters : ' . count($param)); |
|
118 | + } |
|
119 | + if ($param[0] == 'true') return true; |
|
120 | + return false; |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | |
124 | 124 |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | */ |
59 | 59 | function __construct() |
60 | 60 | { |
61 | - $this->name=basename(__FILE__,'.php'); |
|
61 | + $this->name=basename(__FILE__, '.php'); |
|
62 | 62 | return $this; |
63 | 63 | } |
64 | 64 | |
@@ -72,49 +72,49 @@ discard block |
||
72 | 72 | public function isInNetwork(array $params) : bool |
73 | 73 | { |
74 | 74 | // Check param numbers and thrown exception if not correct. |
75 | - if (count($params)!=3) |
|
75 | + if (count($params) != 3) |
|
76 | 76 | { |
77 | - throw new Exception('Invalid number of parameters : ' . count($params)); |
|
77 | + throw new Exception('Invalid number of parameters : '.count($params)); |
|
78 | 78 | } |
79 | 79 | |
80 | - $ip = $params[0]; |
|
81 | - $net = $params[1]; |
|
82 | - $masq = $params[2]; |
|
80 | + $ip=$params[0]; |
|
81 | + $net=$params[1]; |
|
82 | + $masq=$params[2]; |
|
83 | 83 | |
84 | 84 | |
85 | - $this->log('#'. $ip . '# / #' . $net . '# / #' . $masq,DEBUG); |
|
85 | + $this->log('#'.$ip.'# / #'.$net.'# / #'.$masq, DEBUG); |
|
86 | 86 | |
87 | - $ip2 = ip2long($ip); |
|
88 | - $net2 = ip2long($net); |
|
87 | + $ip2=ip2long($ip); |
|
88 | + $net2=ip2long($net); |
|
89 | 89 | |
90 | - if ($ip2 === false ) |
|
90 | + if ($ip2 === false) |
|
91 | 91 | { |
92 | - $this->log('Invalid IP : #' . $ip.'#',WARN); |
|
92 | + $this->log('Invalid IP : #'.$ip.'#', WARN); |
|
93 | 93 | throw new Exception('Invalid IP'); |
94 | 94 | } |
95 | 95 | if ($net2 === false) |
96 | 96 | { |
97 | - $this->log('Invalid network',WARN); |
|
97 | + $this->log('Invalid network', WARN); |
|
98 | 98 | throw new Exception('Invalid net'); |
99 | 99 | } |
100 | - if ($masq<1 || $masq > 32) |
|
100 | + if ($masq < 1 || $masq > 32) |
|
101 | 101 | { |
102 | - $this->log('Invalid masq',WARN); |
|
102 | + $this->log('Invalid masq', WARN); |
|
103 | 103 | throw new Exception('Invalid net masq'); |
104 | 104 | } |
105 | 105 | // $range is in IP/CIDR format eg 127.0.0.1/24 |
106 | 106 | |
107 | - $masq = pow( 2, ( 32 - $masq ) ) - 1; |
|
108 | - $masq = ~ $masq; |
|
109 | - return ( ( $ip2 & $masq ) == ( $net2 & $masq ) ); |
|
107 | + $masq=pow(2, (32 - $masq)) - 1; |
|
108 | + $masq=~ $masq; |
|
109 | + return (($ip2 & $masq) == ($net2 & $masq)); |
|
110 | 110 | |
111 | 111 | } |
112 | 112 | |
113 | 113 | public function testParam(array $param) |
114 | 114 | { |
115 | - if (count($param)!=1) |
|
115 | + if (count($param) != 1) |
|
116 | 116 | { |
117 | - throw new Exception('Invalid number of parameters : ' . count($param)); |
|
117 | + throw new Exception('Invalid number of parameters : '.count($param)); |
|
118 | 118 | } |
119 | 119 | if ($param[0] == 'true') return true; |
120 | 120 | return false; |
@@ -116,7 +116,9 @@ |
||
116 | 116 | { |
117 | 117 | throw new Exception('Invalid number of parameters : ' . count($param)); |
118 | 118 | } |
119 | - if ($param[0] == 'true') return true; |
|
119 | + if ($param[0] == 'true') { |
|
120 | + return true; |
|
121 | + } |
|
120 | 122 | return false; |
121 | 123 | } |
122 | 124 | } |
@@ -7,396 +7,396 @@ |
||
7 | 7 | class Rule |
8 | 8 | { |
9 | 9 | |
10 | - /** @var Logging $logging logging class*/ |
|
11 | - protected $logging; |
|
10 | + /** @var Logging $logging logging class*/ |
|
11 | + protected $logging; |
|
12 | 12 | |
13 | - /** @var Trap $trapClass */ |
|
14 | - protected $trapClass; |
|
13 | + /** @var Trap $trapClass */ |
|
14 | + protected $trapClass; |
|
15 | 15 | |
16 | - /** |
|
17 | - * Setup Rule Class |
|
18 | - * @param Trap $trapClass : To get logging class & plugin class |
|
19 | - */ |
|
20 | - function __construct($trapClass) |
|
21 | - { |
|
22 | - $this->trapClass=$trapClass; |
|
23 | - $this->logging=$trapClass->logging; |
|
24 | - } |
|
16 | + /** |
|
17 | + * Setup Rule Class |
|
18 | + * @param Trap $trapClass : To get logging class & plugin class |
|
19 | + */ |
|
20 | + function __construct($trapClass) |
|
21 | + { |
|
22 | + $this->trapClass=$trapClass; |
|
23 | + $this->logging=$trapClass->logging; |
|
24 | + } |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Get full number |
28 | 28 | * @return array<number,string> |
29 | 29 | */ |
30 | - private function get_number($rule,&$item) |
|
31 | - { |
|
32 | - $item2=$item+1; |
|
33 | - while ( |
|
34 | - ($item2!=strlen($rule)) |
|
35 | - && (preg_match('/[\-0-9\.]/',$rule[$item2]))) |
|
36 | - { |
|
37 | - $item2++ ; |
|
38 | - } |
|
39 | - $val=substr($rule,$item,$item2-$item); |
|
40 | - $item=$item2; |
|
41 | - //echo "number ".$val."\n"; |
|
30 | + private function get_number($rule,&$item) |
|
31 | + { |
|
32 | + $item2=$item+1; |
|
33 | + while ( |
|
34 | + ($item2!=strlen($rule)) |
|
35 | + && (preg_match('/[\-0-9\.]/',$rule[$item2]))) |
|
36 | + { |
|
37 | + $item2++ ; |
|
38 | + } |
|
39 | + $val=substr($rule,$item,$item2-$item); |
|
40 | + $item=$item2; |
|
41 | + //echo "number ".$val."\n"; |
|
42 | 42 | |
43 | - return array(0,$val); |
|
44 | - } |
|
43 | + return array(0,$val); |
|
44 | + } |
|
45 | 45 | |
46 | - private function get_string($rule,&$item) |
|
47 | - { |
|
48 | - $item++; |
|
49 | - $item2=$this->eval_getNext($rule,$item,'"'); |
|
50 | - $val=substr($rule,$item,$item2-$item-1); |
|
51 | - $item=$item2; |
|
52 | - //echo "string : ".$val."\n"; |
|
53 | - return array(1,$val); |
|
46 | + private function get_string($rule,&$item) |
|
47 | + { |
|
48 | + $item++; |
|
49 | + $item2=$this->eval_getNext($rule,$item,'"'); |
|
50 | + $val=substr($rule,$item,$item2-$item-1); |
|
51 | + $item=$item2; |
|
52 | + //echo "string : ".$val."\n"; |
|
53 | + return array(1,$val); |
|
54 | 54 | |
55 | - } |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Parse elements inside () : jumps over "" and count parenthesis. |
|
59 | - * Ex : ( "test" != ")test" & (1==2) ) will return "test" != ")test" & (1==2) |
|
60 | - * @param string $rule : the current rule |
|
61 | - * @param int $item : actual position in rule |
|
62 | - * @throws Exception |
|
63 | - * @return string : everything inside parenthesis |
|
64 | - */ |
|
65 | - private function parse_parenthesis(string $rule,int &$item) : string |
|
66 | - { |
|
67 | - $item++; |
|
68 | - $start=$item; |
|
69 | - $parenthesis_count=0; |
|
70 | - while (($item < strlen($rule)) // Not end of string AND |
|
71 | - && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded () |
|
72 | - { |
|
73 | - if ($rule[$item] == '"' ) |
|
74 | - { // pass through string |
|
75 | - $item++; |
|
76 | - $item=$this->eval_getNext($rule,$item,'"'); |
|
77 | - } |
|
78 | - else{ |
|
79 | - if ($rule[$item] == '(') |
|
80 | - { |
|
81 | - $parenthesis_count++; |
|
82 | - } |
|
83 | - if ($rule[$item] == ')') |
|
84 | - { |
|
85 | - $parenthesis_count--; |
|
86 | - } |
|
87 | - $item++; |
|
88 | - } |
|
89 | - } |
|
57 | + /** |
|
58 | + * Parse elements inside () : jumps over "" and count parenthesis. |
|
59 | + * Ex : ( "test" != ")test" & (1==2) ) will return "test" != ")test" & (1==2) |
|
60 | + * @param string $rule : the current rule |
|
61 | + * @param int $item : actual position in rule |
|
62 | + * @throws Exception |
|
63 | + * @return string : everything inside parenthesis |
|
64 | + */ |
|
65 | + private function parse_parenthesis(string $rule,int &$item) : string |
|
66 | + { |
|
67 | + $item++; |
|
68 | + $start=$item; |
|
69 | + $parenthesis_count=0; |
|
70 | + while (($item < strlen($rule)) // Not end of string AND |
|
71 | + && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded () |
|
72 | + { |
|
73 | + if ($rule[$item] == '"' ) |
|
74 | + { // pass through string |
|
75 | + $item++; |
|
76 | + $item=$this->eval_getNext($rule,$item,'"'); |
|
77 | + } |
|
78 | + else{ |
|
79 | + if ($rule[$item] == '(') |
|
80 | + { |
|
81 | + $parenthesis_count++; |
|
82 | + } |
|
83 | + if ($rule[$item] == ')') |
|
84 | + { |
|
85 | + $parenthesis_count--; |
|
86 | + } |
|
87 | + $item++; |
|
88 | + } |
|
89 | + } |
|
90 | 90 | |
91 | - if ($item==strlen($rule)) {throw new Exception("no closing () in ".$rule ." at " .$item);} |
|
92 | - $val=substr($rule,$start,$item-$start); |
|
93 | - $item++; |
|
94 | - return $val; |
|
95 | - } |
|
91 | + if ($item==strlen($rule)) {throw new Exception("no closing () in ".$rule ." at " .$item);} |
|
92 | + $val=substr($rule,$start,$item-$start); |
|
93 | + $item++; |
|
94 | + return $val; |
|
95 | + } |
|
96 | 96 | |
97 | 97 | |
98 | - /** |
|
99 | - * Get and eval a grouped condition - ex : (1==1) |
|
100 | - * @param string $rule |
|
101 | - * @param int $item |
|
102 | - * @return array |
|
103 | - */ |
|
104 | - private function get_group(string $rule,int &$item) : array |
|
105 | - { |
|
106 | - // gets eveything inside parenthesis |
|
107 | - $val=$this->parse_parenthesis($rule, $item); |
|
108 | - // Returns boolean with evaluation of all inside parenthesis |
|
109 | - $start=0; |
|
110 | - return array(2,$this->evaluation($val,$start)); |
|
111 | - } |
|
98 | + /** |
|
99 | + * Get and eval a grouped condition - ex : (1==1) |
|
100 | + * @param string $rule |
|
101 | + * @param int $item |
|
102 | + * @return array |
|
103 | + */ |
|
104 | + private function get_group(string $rule,int &$item) : array |
|
105 | + { |
|
106 | + // gets eveything inside parenthesis |
|
107 | + $val=$this->parse_parenthesis($rule, $item); |
|
108 | + // Returns boolean with evaluation of all inside parenthesis |
|
109 | + $start=0; |
|
110 | + return array(2,$this->evaluation($val,$start)); |
|
111 | + } |
|
112 | 112 | |
113 | - private function get_function(string $rule,int &$item) : array |
|
114 | - { |
|
115 | - // function is : __function(param1,param2...) |
|
116 | - $start=$item; |
|
117 | - while (($item < strlen($rule)) && ($rule[$item] != '(' )) // Not end of string AND not opening '(' |
|
118 | - { |
|
119 | - $item++; |
|
120 | - } |
|
121 | - if ($item==strlen($rule)) {throw new Exception("no opening () for function in ".$rule ." at " .$item);} |
|
113 | + private function get_function(string $rule,int &$item) : array |
|
114 | + { |
|
115 | + // function is : __function(param1,param2...) |
|
116 | + $start=$item; |
|
117 | + while (($item < strlen($rule)) && ($rule[$item] != '(' )) // Not end of string AND not opening '(' |
|
118 | + { |
|
119 | + $item++; |
|
120 | + } |
|
121 | + if ($item==strlen($rule)) {throw new Exception("no opening () for function in ".$rule ." at " .$item);} |
|
122 | 122 | |
123 | - // get parameters between parenthesis |
|
123 | + // get parameters between parenthesis |
|
124 | 124 | |
125 | - $this->parse_parenthesis($rule, $item); |
|
125 | + $this->parse_parenthesis($rule, $item); |
|
126 | 126 | |
127 | - $val=substr($rule,$start,$item-$start); |
|
127 | + $val=substr($rule,$start,$item-$start); |
|
128 | 128 | |
129 | - $this->logging->log('got function ' . $val,DEBUG); |
|
129 | + $this->logging->log('got function ' . $val,DEBUG); |
|
130 | 130 | |
131 | - return array(2,$this->trapClass->pluginClass->evaluateFunctionString($val)); |
|
131 | + return array(2,$this->trapClass->pluginClass->evaluateFunctionString($val)); |
|
132 | 132 | |
133 | - } |
|
133 | + } |
|
134 | 134 | |
135 | - protected function eval_getElement($rule,&$item) |
|
136 | - { |
|
137 | - if ($item >= strlen($rule)) |
|
138 | - { |
|
139 | - throw new Exception("Early end of string ".$rule ." at " .$item ); |
|
140 | - } |
|
141 | - while ($rule[$item]==' ') $item++; |
|
142 | - if (preg_match('/[\-0-9\.]/',$rule[$item])) |
|
143 | - { // number |
|
144 | - return $this->get_number($rule, $item); |
|
145 | - } |
|
146 | - if ($rule[$item] == '"') |
|
147 | - { // string |
|
148 | - return $this->get_string($rule, $item); |
|
149 | - } |
|
135 | + protected function eval_getElement($rule,&$item) |
|
136 | + { |
|
137 | + if ($item >= strlen($rule)) |
|
138 | + { |
|
139 | + throw new Exception("Early end of string ".$rule ." at " .$item ); |
|
140 | + } |
|
141 | + while ($rule[$item]==' ') $item++; |
|
142 | + if (preg_match('/[\-0-9\.]/',$rule[$item])) |
|
143 | + { // number |
|
144 | + return $this->get_number($rule, $item); |
|
145 | + } |
|
146 | + if ($rule[$item] == '"') |
|
147 | + { // string |
|
148 | + return $this->get_string($rule, $item); |
|
149 | + } |
|
150 | 150 | |
151 | - if ($rule[$item] == '(') |
|
152 | - { // grouping |
|
153 | - return $this->get_group($rule, $item); |
|
154 | - } |
|
155 | - if ($rule[$item] == '_') |
|
156 | - { // function |
|
157 | - return $this->get_function($rule, $item); |
|
158 | - } |
|
159 | - throw new Exception("number/string not found in ".$rule ." at " .$item . ' : ' .$rule[$item]); |
|
151 | + if ($rule[$item] == '(') |
|
152 | + { // grouping |
|
153 | + return $this->get_group($rule, $item); |
|
154 | + } |
|
155 | + if ($rule[$item] == '_') |
|
156 | + { // function |
|
157 | + return $this->get_function($rule, $item); |
|
158 | + } |
|
159 | + throw new Exception("number/string not found in ".$rule ." at " .$item . ' : ' .$rule[$item]); |
|
160 | 160 | |
161 | - } |
|
161 | + } |
|
162 | 162 | |
163 | - protected function eval_getNext($rule,$item,$tok) |
|
164 | - { |
|
165 | - while ( |
|
166 | - ($rule[$item] != $tok ) |
|
167 | - && ($item < strlen($rule))) |
|
168 | - { |
|
169 | - $item++; |
|
170 | - } |
|
171 | - if ($item==strlen($rule)) { |
|
172 | - throw new Exception("closing '".$tok."' not found in ".$rule ." at " .$item); |
|
173 | - } |
|
174 | - return $item+1; |
|
175 | - } |
|
163 | + protected function eval_getNext($rule,$item,$tok) |
|
164 | + { |
|
165 | + while ( |
|
166 | + ($rule[$item] != $tok ) |
|
167 | + && ($item < strlen($rule))) |
|
168 | + { |
|
169 | + $item++; |
|
170 | + } |
|
171 | + if ($item==strlen($rule)) { |
|
172 | + throw new Exception("closing '".$tok."' not found in ".$rule ." at " .$item); |
|
173 | + } |
|
174 | + return $item+1; |
|
175 | + } |
|
176 | 176 | |
177 | - protected function eval_getOper($rule,&$item) |
|
178 | - { |
|
179 | - while ($rule[$item]==' ') $item++; |
|
180 | - switch ($rule[$item]) |
|
181 | - { |
|
182 | - case '<': |
|
183 | - if ($rule[$item+1]=='=') { $item+=2; return array(0,"<=");} |
|
184 | - $item++; return array(0,"<"); |
|
185 | - case '>': |
|
186 | - if ($rule[$item+1]=='=') { $item+=2; return array(0,">=");} |
|
187 | - $item++; return array(0,">"); |
|
188 | - case '=': |
|
189 | - $item++; return array(0,"="); |
|
190 | - case '!': |
|
191 | - if ($rule[$item+1]=='=') { $item+=2; return array(0,"!=");} |
|
192 | - throw new Exception("Erreur in expr - incorrect operator '!' found in ".$rule ." at " .$item); |
|
193 | - case '~': |
|
194 | - $item++; return array(0,"~"); |
|
195 | - case '|': |
|
196 | - $item++; return array(1,"|"); |
|
197 | - case '&': |
|
198 | - $item++; return array(1,"&"); |
|
199 | - default : |
|
200 | - throw new Exception("Erreur in expr - operator not found in ".$rule ." at " .$item); |
|
201 | - } |
|
202 | - } |
|
177 | + protected function eval_getOper($rule,&$item) |
|
178 | + { |
|
179 | + while ($rule[$item]==' ') $item++; |
|
180 | + switch ($rule[$item]) |
|
181 | + { |
|
182 | + case '<': |
|
183 | + if ($rule[$item+1]=='=') { $item+=2; return array(0,"<=");} |
|
184 | + $item++; return array(0,"<"); |
|
185 | + case '>': |
|
186 | + if ($rule[$item+1]=='=') { $item+=2; return array(0,">=");} |
|
187 | + $item++; return array(0,">"); |
|
188 | + case '=': |
|
189 | + $item++; return array(0,"="); |
|
190 | + case '!': |
|
191 | + if ($rule[$item+1]=='=') { $item+=2; return array(0,"!=");} |
|
192 | + throw new Exception("Erreur in expr - incorrect operator '!' found in ".$rule ." at " .$item); |
|
193 | + case '~': |
|
194 | + $item++; return array(0,"~"); |
|
195 | + case '|': |
|
196 | + $item++; return array(1,"|"); |
|
197 | + case '&': |
|
198 | + $item++; return array(1,"&"); |
|
199 | + default : |
|
200 | + throw new Exception("Erreur in expr - operator not found in ".$rule ." at " .$item); |
|
201 | + } |
|
202 | + } |
|
203 | 203 | |
204 | - private function check_negate_first($rule,&$item) |
|
205 | - { |
|
206 | - if ( $rule[$item] == '!') // If '!' found, negate next expression. |
|
207 | - { |
|
208 | - $item++; |
|
209 | - return true; |
|
210 | - } |
|
211 | - else |
|
212 | - { |
|
213 | - return false; |
|
214 | - } |
|
215 | - } |
|
204 | + private function check_negate_first($rule,&$item) |
|
205 | + { |
|
206 | + if ( $rule[$item] == '!') // If '!' found, negate next expression. |
|
207 | + { |
|
208 | + $item++; |
|
209 | + return true; |
|
210 | + } |
|
211 | + else |
|
212 | + { |
|
213 | + return false; |
|
214 | + } |
|
215 | + } |
|
216 | 216 | |
217 | - private function do_compare($val1,$val2,$comp,$negate) |
|
218 | - { |
|
219 | - switch ($comp){ |
|
220 | - case '<': $retVal= ($val1 < $val2); break; |
|
221 | - case '<=': $retVal= ($val1 <= $val2); break; |
|
222 | - case '>': $retVal= ($val1 > $val2); break; |
|
223 | - case '>=': $retVal= ($val1 >= $val2); break; |
|
224 | - case '=': $retVal= ($val1 == $val2); break; |
|
225 | - case '!=': $retVal= ($val1 != $val2); break; |
|
226 | - case '~': $retVal= (preg_match('/'.preg_replace('/"/','',$val2).'/',$val1)); break; |
|
227 | - case '|': $retVal= ($val1 || $val2); break; |
|
228 | - case '&': $retVal= ($val1 && $val2); break; |
|
229 | - default: throw new Exception("Error in expression - unknown comp : ".$comp); |
|
230 | - } |
|
231 | - if ($negate === true) $retVal = ! $retVal; // Inverse result if negate before expression |
|
217 | + private function do_compare($val1,$val2,$comp,$negate) |
|
218 | + { |
|
219 | + switch ($comp){ |
|
220 | + case '<': $retVal= ($val1 < $val2); break; |
|
221 | + case '<=': $retVal= ($val1 <= $val2); break; |
|
222 | + case '>': $retVal= ($val1 > $val2); break; |
|
223 | + case '>=': $retVal= ($val1 >= $val2); break; |
|
224 | + case '=': $retVal= ($val1 == $val2); break; |
|
225 | + case '!=': $retVal= ($val1 != $val2); break; |
|
226 | + case '~': $retVal= (preg_match('/'.preg_replace('/"/','',$val2).'/',$val1)); break; |
|
227 | + case '|': $retVal= ($val1 || $val2); break; |
|
228 | + case '&': $retVal= ($val1 && $val2); break; |
|
229 | + default: throw new Exception("Error in expression - unknown comp : ".$comp); |
|
230 | + } |
|
231 | + if ($negate === true) $retVal = ! $retVal; // Inverse result if negate before expression |
|
232 | 232 | |
233 | - return $retVal; |
|
234 | - } |
|
233 | + return $retVal; |
|
234 | + } |
|
235 | 235 | |
236 | - /** Evaluation : makes token and evaluate. |
|
237 | - * Public function for expressions testing |
|
238 | - * accepts : < > = <= >= != (typec = 0) |
|
239 | - * operators : & | (typec=1) |
|
240 | - * with : integers/float (type 0) or strings "" (type 1) or results (type 2) |
|
241 | - * comparison int vs strings will return null (error) |
|
242 | - * return : bool or null on error |
|
243 | - */ |
|
244 | - public function evaluation($rule,&$item) |
|
245 | - { |
|
246 | - //echo "Evaluation of ".substr($rule,$item)."\n"; |
|
247 | - $negate=$this->check_negate_first($rule, $item); |
|
248 | - // First element : number, string or () |
|
249 | - list($type1,$val1) = $this->eval_getElement($rule,$item); |
|
250 | - //echo "Elmt1: ".$val1."/".$type1." : ".substr($rule,$item)."\n"; |
|
236 | + /** Evaluation : makes token and evaluate. |
|
237 | + * Public function for expressions testing |
|
238 | + * accepts : < > = <= >= != (typec = 0) |
|
239 | + * operators : & | (typec=1) |
|
240 | + * with : integers/float (type 0) or strings "" (type 1) or results (type 2) |
|
241 | + * comparison int vs strings will return null (error) |
|
242 | + * return : bool or null on error |
|
243 | + */ |
|
244 | + public function evaluation($rule,&$item) |
|
245 | + { |
|
246 | + //echo "Evaluation of ".substr($rule,$item)."\n"; |
|
247 | + $negate=$this->check_negate_first($rule, $item); |
|
248 | + // First element : number, string or () |
|
249 | + list($type1,$val1) = $this->eval_getElement($rule,$item); |
|
250 | + //echo "Elmt1: ".$val1."/".$type1." : ".substr($rule,$item)."\n"; |
|
251 | 251 | |
252 | - if ($item==strlen($rule)) // If only element, return value, but only boolean |
|
253 | - { |
|
254 | - if ($type1 != 2) throw new Exception("Cannot use num/string as boolean : ".$rule); |
|
255 | - if ($negate === true) $val1= ! $val1; |
|
256 | - return $val1; |
|
257 | - } |
|
252 | + if ($item==strlen($rule)) // If only element, return value, but only boolean |
|
253 | + { |
|
254 | + if ($type1 != 2) throw new Exception("Cannot use num/string as boolean : ".$rule); |
|
255 | + if ($negate === true) $val1= ! $val1; |
|
256 | + return $val1; |
|
257 | + } |
|
258 | 258 | |
259 | - // Second element : operator |
|
260 | - list($typec,$comp) = $this->eval_getOper($rule,$item); |
|
261 | - //echo "Comp : ".$comp." : ".substr($rule,$item)."\n"; |
|
259 | + // Second element : operator |
|
260 | + list($typec,$comp) = $this->eval_getOper($rule,$item); |
|
261 | + //echo "Comp : ".$comp." : ".substr($rule,$item)."\n"; |
|
262 | 262 | |
263 | - // Third element : number, string or () |
|
264 | - if ( $rule[$item] == '!') // starts with a ! so evaluate whats next |
|
265 | - { |
|
266 | - $item++; |
|
267 | - if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule); |
|
268 | - $val2= ! $this->evaluation($rule,$item); |
|
269 | - $type2=2; // result is a boolean |
|
270 | - } |
|
271 | - else |
|
272 | - { |
|
273 | - list($type2,$val2) = $this->eval_getElement($rule,$item); |
|
274 | - } |
|
275 | - //echo "Elmt2: ".$val2."/".$type2." : ".substr($rule,$item)."\n"; |
|
263 | + // Third element : number, string or () |
|
264 | + if ( $rule[$item] == '!') // starts with a ! so evaluate whats next |
|
265 | + { |
|
266 | + $item++; |
|
267 | + if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule); |
|
268 | + $val2= ! $this->evaluation($rule,$item); |
|
269 | + $type2=2; // result is a boolean |
|
270 | + } |
|
271 | + else |
|
272 | + { |
|
273 | + list($type2,$val2) = $this->eval_getElement($rule,$item); |
|
274 | + } |
|
275 | + //echo "Elmt2: ".$val2."/".$type2." : ".substr($rule,$item)."\n"; |
|
276 | 276 | |
277 | - if ($type1!=$type2) // cannot compare different types |
|
278 | - { |
|
279 | - throw new Exception("Cannot compare string & number : ".$rule); |
|
280 | - } |
|
281 | - if ($typec==1 && $type1 !=2) // cannot use & or | with string/number |
|
282 | - { |
|
283 | - throw new Exception("Cannot use boolean operators with string & number : ".$rule); |
|
284 | - } |
|
277 | + if ($type1!=$type2) // cannot compare different types |
|
278 | + { |
|
279 | + throw new Exception("Cannot compare string & number : ".$rule); |
|
280 | + } |
|
281 | + if ($typec==1 && $type1 !=2) // cannot use & or | with string/number |
|
282 | + { |
|
283 | + throw new Exception("Cannot use boolean operators with string & number : ".$rule); |
|
284 | + } |
|
285 | 285 | |
286 | - $retVal = $this->do_compare($val1, $val2, $comp, $negate); |
|
286 | + $retVal = $this->do_compare($val1, $val2, $comp, $negate); |
|
287 | 287 | |
288 | - if ($item==strlen($rule)) return $retVal; // End of string : return evaluation |
|
289 | - // check for logical operator : |
|
290 | - switch ($rule[$item]) |
|
291 | - { |
|
292 | - case '|': $item++; return ($retVal || $this->evaluation($rule,$item) ); |
|
293 | - case '&': $item++; return ($retVal && $this->evaluation($rule,$item) ); |
|
288 | + if ($item==strlen($rule)) return $retVal; // End of string : return evaluation |
|
289 | + // check for logical operator : |
|
290 | + switch ($rule[$item]) |
|
291 | + { |
|
292 | + case '|': $item++; return ($retVal || $this->evaluation($rule,$item) ); |
|
293 | + case '&': $item++; return ($retVal && $this->evaluation($rule,$item) ); |
|
294 | 294 | |
295 | - default: throw new Exception("Erreur in expr - garbadge at end of expression : ".$rule[$item]); |
|
296 | - } |
|
297 | - } |
|
295 | + default: throw new Exception("Erreur in expr - garbadge at end of expression : ".$rule[$item]); |
|
296 | + } |
|
297 | + } |
|
298 | 298 | |
299 | - // Remove all whitespaces (when not quoted) |
|
300 | - public function eval_cleanup($rule) |
|
301 | - { |
|
302 | - $item=0; |
|
303 | - $rule2=''; |
|
304 | - while ($item < strlen($rule)) |
|
305 | - { |
|
306 | - if ($rule[$item]==' ') { $item++; continue; } |
|
307 | - if ($rule[$item]=='"') |
|
308 | - { |
|
309 | - $rule2.=$rule[$item]; |
|
310 | - $item++; |
|
311 | - while (($item < strlen($rule)) && ($rule[$item]!='"') ) |
|
312 | - { |
|
313 | - $rule2.=$rule[$item]; |
|
314 | - $item++; |
|
315 | - } |
|
316 | - if ($item == strlen ($rule)) throw new Exception("closing '\"' not found in ".$rule ." at " .$item); |
|
317 | - $rule2.=$rule[$item]; |
|
318 | - $item++; |
|
319 | - continue; |
|
320 | - } |
|
299 | + // Remove all whitespaces (when not quoted) |
|
300 | + public function eval_cleanup($rule) |
|
301 | + { |
|
302 | + $item=0; |
|
303 | + $rule2=''; |
|
304 | + while ($item < strlen($rule)) |
|
305 | + { |
|
306 | + if ($rule[$item]==' ') { $item++; continue; } |
|
307 | + if ($rule[$item]=='"') |
|
308 | + { |
|
309 | + $rule2.=$rule[$item]; |
|
310 | + $item++; |
|
311 | + while (($item < strlen($rule)) && ($rule[$item]!='"') ) |
|
312 | + { |
|
313 | + $rule2.=$rule[$item]; |
|
314 | + $item++; |
|
315 | + } |
|
316 | + if ($item == strlen ($rule)) throw new Exception("closing '\"' not found in ".$rule ." at " .$item); |
|
317 | + $rule2.=$rule[$item]; |
|
318 | + $item++; |
|
319 | + continue; |
|
320 | + } |
|
321 | 321 | |
322 | - $rule2.=$rule[$item]; |
|
323 | - $item++; |
|
324 | - } |
|
322 | + $rule2.=$rule[$item]; |
|
323 | + $item++; |
|
324 | + } |
|
325 | 325 | |
326 | - return $rule2; |
|
327 | - } |
|
326 | + return $rule2; |
|
327 | + } |
|
328 | 328 | |
329 | 329 | |
330 | - /** |
|
331 | - * Get '*' or '**' and transform in [0-9]+ or .* in return string |
|
332 | - * @param string $oid OID in normal or regexp format. '*' will be escaped ('\*') |
|
333 | - * @return string correct regexp format |
|
334 | - */ |
|
335 | - public function regexp_eval(string &$oid) |
|
336 | - { |
|
337 | - // ** replaced by .* |
|
338 | - $oidR=preg_replace('/\*\*/', '.*', $oid); |
|
339 | - // * replaced by [0-9]+ |
|
340 | - $oidR=preg_replace('/\*/', '[0-9]+', $oidR); |
|
330 | + /** |
|
331 | + * Get '*' or '**' and transform in [0-9]+ or .* in return string |
|
332 | + * @param string $oid OID in normal or regexp format. '*' will be escaped ('\*') |
|
333 | + * @return string correct regexp format |
|
334 | + */ |
|
335 | + public function regexp_eval(string &$oid) |
|
336 | + { |
|
337 | + // ** replaced by .* |
|
338 | + $oidR=preg_replace('/\*\*/', '.*', $oid); |
|
339 | + // * replaced by [0-9]+ |
|
340 | + $oidR=preg_replace('/\*/', '[0-9]+', $oidR); |
|
341 | 341 | |
342 | - // replace * with \* in oid for preg_replace |
|
343 | - $oid=preg_replace('/\*/', '\*', $oid); |
|
342 | + // replace * with \* in oid for preg_replace |
|
343 | + $oid=preg_replace('/\*/', '\*', $oid); |
|
344 | 344 | |
345 | - $this->logging->log('Regexp eval : '.$oid.' / '.$oidR,DEBUG ); |
|
345 | + $this->logging->log('Regexp eval : '.$oid.' / '.$oidR,DEBUG ); |
|
346 | 346 | |
347 | - return $oidR; |
|
348 | - } |
|
347 | + return $oidR; |
|
348 | + } |
|
349 | 349 | |
350 | 350 | |
351 | - /** Evaluation rule (uses eval_* functions recursively) |
|
352 | - * @param string $rule : rule ( _OID(.1.3.6.1.4.1.8072.2.3.2.1)=_OID(.1.3.6.1.2.1.1.3.0) ) |
|
353 | - * @param array $oidList : OIDs values to sustitute. |
|
354 | - * @return bool : true : rule match, false : rule don't match , throw exception on error. |
|
355 | - */ |
|
356 | - public function eval_rule($rule,$oidList) |
|
357 | - { |
|
358 | - if ($rule==null || $rule == '') // Empty rule is always true |
|
359 | - { |
|
360 | - return true; |
|
361 | - } |
|
362 | - $matches=array(); |
|
363 | - while (preg_match('/_OID\(([0-9\.\*]+)\)/',$rule,$matches) == 1) |
|
364 | - { |
|
365 | - $oid=$matches[1]; |
|
366 | - $found=0; |
|
367 | - // Test and transform regexp |
|
368 | - $oidR = $this->regexp_eval($oid); |
|
351 | + /** Evaluation rule (uses eval_* functions recursively) |
|
352 | + * @param string $rule : rule ( _OID(.1.3.6.1.4.1.8072.2.3.2.1)=_OID(.1.3.6.1.2.1.1.3.0) ) |
|
353 | + * @param array $oidList : OIDs values to sustitute. |
|
354 | + * @return bool : true : rule match, false : rule don't match , throw exception on error. |
|
355 | + */ |
|
356 | + public function eval_rule($rule,$oidList) |
|
357 | + { |
|
358 | + if ($rule==null || $rule == '') // Empty rule is always true |
|
359 | + { |
|
360 | + return true; |
|
361 | + } |
|
362 | + $matches=array(); |
|
363 | + while (preg_match('/_OID\(([0-9\.\*]+)\)/',$rule,$matches) == 1) |
|
364 | + { |
|
365 | + $oid=$matches[1]; |
|
366 | + $found=0; |
|
367 | + // Test and transform regexp |
|
368 | + $oidR = $this->regexp_eval($oid); |
|
369 | 369 | |
370 | - foreach($oidList as $val) |
|
371 | - { |
|
372 | - if (preg_match("/^$oidR$/",$val->oid) == 1) |
|
373 | - { |
|
374 | - if (!preg_match('/^-?[0-9]*\.?[0-9]+$/',$val->value)) |
|
375 | - { // If not a number, change " to ' and put " around it |
|
376 | - $val->value=preg_replace('/"/',"'",$val->value); |
|
377 | - $val->value='"'.$val->value.'"'; |
|
378 | - } |
|
379 | - $rep=0; |
|
380 | - $rule=preg_replace('/_OID\('.$oid.'\)/',$val->value,$rule,-1,$rep); |
|
381 | - if ($rep==0) |
|
382 | - { |
|
383 | - $this->logging->log("Error in rule_eval",WARN,''); |
|
384 | - return false; |
|
385 | - } |
|
386 | - $found=1; |
|
387 | - break; |
|
388 | - } |
|
389 | - } |
|
390 | - if ($found==0) |
|
391 | - { // OID not found : throw error |
|
392 | - throw new Exception('OID '.$oid.' not found in trap'); |
|
393 | - } |
|
394 | - } |
|
395 | - $item=0; |
|
396 | - $rule=$this->eval_cleanup($rule); |
|
397 | - $this->logging->log('Rule after clenup: '.$rule,INFO ); |
|
370 | + foreach($oidList as $val) |
|
371 | + { |
|
372 | + if (preg_match("/^$oidR$/",$val->oid) == 1) |
|
373 | + { |
|
374 | + if (!preg_match('/^-?[0-9]*\.?[0-9]+$/',$val->value)) |
|
375 | + { // If not a number, change " to ' and put " around it |
|
376 | + $val->value=preg_replace('/"/',"'",$val->value); |
|
377 | + $val->value='"'.$val->value.'"'; |
|
378 | + } |
|
379 | + $rep=0; |
|
380 | + $rule=preg_replace('/_OID\('.$oid.'\)/',$val->value,$rule,-1,$rep); |
|
381 | + if ($rep==0) |
|
382 | + { |
|
383 | + $this->logging->log("Error in rule_eval",WARN,''); |
|
384 | + return false; |
|
385 | + } |
|
386 | + $found=1; |
|
387 | + break; |
|
388 | + } |
|
389 | + } |
|
390 | + if ($found==0) |
|
391 | + { // OID not found : throw error |
|
392 | + throw new Exception('OID '.$oid.' not found in trap'); |
|
393 | + } |
|
394 | + } |
|
395 | + $item=0; |
|
396 | + $rule=$this->eval_cleanup($rule); |
|
397 | + $this->logging->log('Rule after clenup: '.$rule,INFO ); |
|
398 | 398 | |
399 | - return $this->evaluation($rule,$item); |
|
400 | - } |
|
399 | + return $this->evaluation($rule,$item); |
|
400 | + } |
|
401 | 401 | |
402 | 402 | } |
403 | 403 | \ No newline at end of file |
@@ -27,30 +27,30 @@ discard block |
||
27 | 27 | * Get full number |
28 | 28 | * @return array<number,string> |
29 | 29 | */ |
30 | - private function get_number($rule,&$item) |
|
30 | + private function get_number($rule, &$item) |
|
31 | 31 | { |
32 | - $item2=$item+1; |
|
32 | + $item2=$item + 1; |
|
33 | 33 | while ( |
34 | - ($item2!=strlen($rule)) |
|
35 | - && (preg_match('/[\-0-9\.]/',$rule[$item2]))) |
|
34 | + ($item2 != strlen($rule)) |
|
35 | + && (preg_match('/[\-0-9\.]/', $rule[$item2]))) |
|
36 | 36 | { |
37 | - $item2++ ; |
|
37 | + $item2++; |
|
38 | 38 | } |
39 | - $val=substr($rule,$item,$item2-$item); |
|
39 | + $val=substr($rule, $item, $item2 - $item); |
|
40 | 40 | $item=$item2; |
41 | 41 | //echo "number ".$val."\n"; |
42 | 42 | |
43 | - return array(0,$val); |
|
43 | + return array(0, $val); |
|
44 | 44 | } |
45 | 45 | |
46 | - private function get_string($rule,&$item) |
|
46 | + private function get_string($rule, &$item) |
|
47 | 47 | { |
48 | 48 | $item++; |
49 | - $item2=$this->eval_getNext($rule,$item,'"'); |
|
50 | - $val=substr($rule,$item,$item2-$item-1); |
|
49 | + $item2=$this->eval_getNext($rule, $item, '"'); |
|
50 | + $val=substr($rule, $item, $item2 - $item - 1); |
|
51 | 51 | $item=$item2; |
52 | 52 | //echo "string : ".$val."\n"; |
53 | - return array(1,$val); |
|
53 | + return array(1, $val); |
|
54 | 54 | |
55 | 55 | } |
56 | 56 | |
@@ -62,20 +62,20 @@ discard block |
||
62 | 62 | * @throws Exception |
63 | 63 | * @return string : everything inside parenthesis |
64 | 64 | */ |
65 | - private function parse_parenthesis(string $rule,int &$item) : string |
|
65 | + private function parse_parenthesis(string $rule, int &$item) : string |
|
66 | 66 | { |
67 | 67 | $item++; |
68 | 68 | $start=$item; |
69 | 69 | $parenthesis_count=0; |
70 | 70 | while (($item < strlen($rule)) // Not end of string AND |
71 | - && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded () |
|
71 | + && (($rule[$item] != ')') || $parenthesis_count > 0)) // Closing ')' or embeded () |
|
72 | 72 | { |
73 | - if ($rule[$item] == '"' ) |
|
73 | + if ($rule[$item] == '"') |
|
74 | 74 | { // pass through string |
75 | 75 | $item++; |
76 | - $item=$this->eval_getNext($rule,$item,'"'); |
|
76 | + $item=$this->eval_getNext($rule, $item, '"'); |
|
77 | 77 | } |
78 | - else{ |
|
78 | + else { |
|
79 | 79 | if ($rule[$item] == '(') |
80 | 80 | { |
81 | 81 | $parenthesis_count++; |
@@ -88,8 +88,8 @@ discard block |
||
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
91 | - if ($item==strlen($rule)) {throw new Exception("no closing () in ".$rule ." at " .$item);} |
|
92 | - $val=substr($rule,$start,$item-$start); |
|
91 | + if ($item == strlen($rule)) {throw new Exception("no closing () in ".$rule." at ".$item); } |
|
92 | + $val=substr($rule, $start, $item - $start); |
|
93 | 93 | $item++; |
94 | 94 | return $val; |
95 | 95 | } |
@@ -101,45 +101,45 @@ discard block |
||
101 | 101 | * @param int $item |
102 | 102 | * @return array |
103 | 103 | */ |
104 | - private function get_group(string $rule,int &$item) : array |
|
104 | + private function get_group(string $rule, int &$item) : array |
|
105 | 105 | { |
106 | 106 | // gets eveything inside parenthesis |
107 | 107 | $val=$this->parse_parenthesis($rule, $item); |
108 | 108 | // Returns boolean with evaluation of all inside parenthesis |
109 | 109 | $start=0; |
110 | - return array(2,$this->evaluation($val,$start)); |
|
110 | + return array(2, $this->evaluation($val, $start)); |
|
111 | 111 | } |
112 | 112 | |
113 | - private function get_function(string $rule,int &$item) : array |
|
113 | + private function get_function(string $rule, int &$item) : array |
|
114 | 114 | { |
115 | 115 | // function is : __function(param1,param2...) |
116 | 116 | $start=$item; |
117 | - while (($item < strlen($rule)) && ($rule[$item] != '(' )) // Not end of string AND not opening '(' |
|
117 | + while (($item < strlen($rule)) && ($rule[$item] != '(')) // Not end of string AND not opening '(' |
|
118 | 118 | { |
119 | 119 | $item++; |
120 | 120 | } |
121 | - if ($item==strlen($rule)) {throw new Exception("no opening () for function in ".$rule ." at " .$item);} |
|
121 | + if ($item == strlen($rule)) {throw new Exception("no opening () for function in ".$rule." at ".$item); } |
|
122 | 122 | |
123 | 123 | // get parameters between parenthesis |
124 | 124 | |
125 | 125 | $this->parse_parenthesis($rule, $item); |
126 | 126 | |
127 | - $val=substr($rule,$start,$item-$start); |
|
127 | + $val=substr($rule, $start, $item - $start); |
|
128 | 128 | |
129 | - $this->logging->log('got function ' . $val,DEBUG); |
|
129 | + $this->logging->log('got function '.$val, DEBUG); |
|
130 | 130 | |
131 | - return array(2,$this->trapClass->pluginClass->evaluateFunctionString($val)); |
|
131 | + return array(2, $this->trapClass->pluginClass->evaluateFunctionString($val)); |
|
132 | 132 | |
133 | 133 | } |
134 | 134 | |
135 | - protected function eval_getElement($rule,&$item) |
|
135 | + protected function eval_getElement($rule, &$item) |
|
136 | 136 | { |
137 | 137 | if ($item >= strlen($rule)) |
138 | 138 | { |
139 | - throw new Exception("Early end of string ".$rule ." at " .$item ); |
|
139 | + throw new Exception("Early end of string ".$rule." at ".$item); |
|
140 | 140 | } |
141 | - while ($rule[$item]==' ') $item++; |
|
142 | - if (preg_match('/[\-0-9\.]/',$rule[$item])) |
|
141 | + while ($rule[$item] == ' ') $item++; |
|
142 | + if (preg_match('/[\-0-9\.]/', $rule[$item])) |
|
143 | 143 | { // number |
144 | 144 | return $this->get_number($rule, $item); |
145 | 145 | } |
@@ -156,54 +156,54 @@ discard block |
||
156 | 156 | { // function |
157 | 157 | return $this->get_function($rule, $item); |
158 | 158 | } |
159 | - throw new Exception("number/string not found in ".$rule ." at " .$item . ' : ' .$rule[$item]); |
|
159 | + throw new Exception("number/string not found in ".$rule." at ".$item.' : '.$rule[$item]); |
|
160 | 160 | |
161 | 161 | } |
162 | 162 | |
163 | - protected function eval_getNext($rule,$item,$tok) |
|
163 | + protected function eval_getNext($rule, $item, $tok) |
|
164 | 164 | { |
165 | 165 | while ( |
166 | - ($rule[$item] != $tok ) |
|
166 | + ($rule[$item] != $tok) |
|
167 | 167 | && ($item < strlen($rule))) |
168 | 168 | { |
169 | 169 | $item++; |
170 | 170 | } |
171 | - if ($item==strlen($rule)) { |
|
172 | - throw new Exception("closing '".$tok."' not found in ".$rule ." at " .$item); |
|
171 | + if ($item == strlen($rule)) { |
|
172 | + throw new Exception("closing '".$tok."' not found in ".$rule." at ".$item); |
|
173 | 173 | } |
174 | - return $item+1; |
|
174 | + return $item + 1; |
|
175 | 175 | } |
176 | 176 | |
177 | - protected function eval_getOper($rule,&$item) |
|
177 | + protected function eval_getOper($rule, &$item) |
|
178 | 178 | { |
179 | - while ($rule[$item]==' ') $item++; |
|
179 | + while ($rule[$item] == ' ') $item++; |
|
180 | 180 | switch ($rule[$item]) |
181 | 181 | { |
182 | 182 | case '<': |
183 | - if ($rule[$item+1]=='=') { $item+=2; return array(0,"<=");} |
|
184 | - $item++; return array(0,"<"); |
|
183 | + if ($rule[$item + 1] == '=') { $item+=2; return array(0, "<="); } |
|
184 | + $item++; return array(0, "<"); |
|
185 | 185 | case '>': |
186 | - if ($rule[$item+1]=='=') { $item+=2; return array(0,">=");} |
|
187 | - $item++; return array(0,">"); |
|
186 | + if ($rule[$item + 1] == '=') { $item+=2; return array(0, ">="); } |
|
187 | + $item++; return array(0, ">"); |
|
188 | 188 | case '=': |
189 | - $item++; return array(0,"="); |
|
189 | + $item++; return array(0, "="); |
|
190 | 190 | case '!': |
191 | - if ($rule[$item+1]=='=') { $item+=2; return array(0,"!=");} |
|
192 | - throw new Exception("Erreur in expr - incorrect operator '!' found in ".$rule ." at " .$item); |
|
191 | + if ($rule[$item + 1] == '=') { $item+=2; return array(0, "!="); } |
|
192 | + throw new Exception("Erreur in expr - incorrect operator '!' found in ".$rule." at ".$item); |
|
193 | 193 | case '~': |
194 | - $item++; return array(0,"~"); |
|
194 | + $item++; return array(0, "~"); |
|
195 | 195 | case '|': |
196 | - $item++; return array(1,"|"); |
|
196 | + $item++; return array(1, "|"); |
|
197 | 197 | case '&': |
198 | - $item++; return array(1,"&"); |
|
198 | + $item++; return array(1, "&"); |
|
199 | 199 | default : |
200 | - throw new Exception("Erreur in expr - operator not found in ".$rule ." at " .$item); |
|
200 | + throw new Exception("Erreur in expr - operator not found in ".$rule." at ".$item); |
|
201 | 201 | } |
202 | 202 | } |
203 | 203 | |
204 | - private function check_negate_first($rule,&$item) |
|
204 | + private function check_negate_first($rule, &$item) |
|
205 | 205 | { |
206 | - if ( $rule[$item] == '!') // If '!' found, negate next expression. |
|
206 | + if ($rule[$item] == '!') // If '!' found, negate next expression. |
|
207 | 207 | { |
208 | 208 | $item++; |
209 | 209 | return true; |
@@ -214,21 +214,21 @@ discard block |
||
214 | 214 | } |
215 | 215 | } |
216 | 216 | |
217 | - private function do_compare($val1,$val2,$comp,$negate) |
|
217 | + private function do_compare($val1, $val2, $comp, $negate) |
|
218 | 218 | { |
219 | - switch ($comp){ |
|
220 | - case '<': $retVal= ($val1 < $val2); break; |
|
221 | - case '<=': $retVal= ($val1 <= $val2); break; |
|
222 | - case '>': $retVal= ($val1 > $val2); break; |
|
223 | - case '>=': $retVal= ($val1 >= $val2); break; |
|
224 | - case '=': $retVal= ($val1 == $val2); break; |
|
225 | - case '!=': $retVal= ($val1 != $val2); break; |
|
226 | - case '~': $retVal= (preg_match('/'.preg_replace('/"/','',$val2).'/',$val1)); break; |
|
227 | - case '|': $retVal= ($val1 || $val2); break; |
|
228 | - case '&': $retVal= ($val1 && $val2); break; |
|
219 | + switch ($comp) { |
|
220 | + case '<': $retVal=($val1 < $val2); break; |
|
221 | + case '<=': $retVal=($val1 <= $val2); break; |
|
222 | + case '>': $retVal=($val1 > $val2); break; |
|
223 | + case '>=': $retVal=($val1 >= $val2); break; |
|
224 | + case '=': $retVal=($val1 == $val2); break; |
|
225 | + case '!=': $retVal=($val1 != $val2); break; |
|
226 | + case '~': $retVal=(preg_match('/'.preg_replace('/"/', '', $val2).'/', $val1)); break; |
|
227 | + case '|': $retVal=($val1 || $val2); break; |
|
228 | + case '&': $retVal=($val1 && $val2); break; |
|
229 | 229 | default: throw new Exception("Error in expression - unknown comp : ".$comp); |
230 | 230 | } |
231 | - if ($negate === true) $retVal = ! $retVal; // Inverse result if negate before expression |
|
231 | + if ($negate === true) $retVal=!$retVal; // Inverse result if negate before expression |
|
232 | 232 | |
233 | 233 | return $retVal; |
234 | 234 | } |
@@ -241,56 +241,56 @@ discard block |
||
241 | 241 | * comparison int vs strings will return null (error) |
242 | 242 | * return : bool or null on error |
243 | 243 | */ |
244 | - public function evaluation($rule,&$item) |
|
244 | + public function evaluation($rule, &$item) |
|
245 | 245 | { |
246 | 246 | //echo "Evaluation of ".substr($rule,$item)."\n"; |
247 | 247 | $negate=$this->check_negate_first($rule, $item); |
248 | 248 | // First element : number, string or () |
249 | - list($type1,$val1) = $this->eval_getElement($rule,$item); |
|
249 | + list($type1, $val1)=$this->eval_getElement($rule, $item); |
|
250 | 250 | //echo "Elmt1: ".$val1."/".$type1." : ".substr($rule,$item)."\n"; |
251 | 251 | |
252 | - if ($item==strlen($rule)) // If only element, return value, but only boolean |
|
252 | + if ($item == strlen($rule)) // If only element, return value, but only boolean |
|
253 | 253 | { |
254 | 254 | if ($type1 != 2) throw new Exception("Cannot use num/string as boolean : ".$rule); |
255 | - if ($negate === true) $val1= ! $val1; |
|
255 | + if ($negate === true) $val1=!$val1; |
|
256 | 256 | return $val1; |
257 | 257 | } |
258 | 258 | |
259 | 259 | // Second element : operator |
260 | - list($typec,$comp) = $this->eval_getOper($rule,$item); |
|
260 | + list($typec, $comp)=$this->eval_getOper($rule, $item); |
|
261 | 261 | //echo "Comp : ".$comp." : ".substr($rule,$item)."\n"; |
262 | 262 | |
263 | 263 | // Third element : number, string or () |
264 | - if ( $rule[$item] == '!') // starts with a ! so evaluate whats next |
|
264 | + if ($rule[$item] == '!') // starts with a ! so evaluate whats next |
|
265 | 265 | { |
266 | 266 | $item++; |
267 | 267 | if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule); |
268 | - $val2= ! $this->evaluation($rule,$item); |
|
268 | + $val2=!$this->evaluation($rule, $item); |
|
269 | 269 | $type2=2; // result is a boolean |
270 | 270 | } |
271 | 271 | else |
272 | 272 | { |
273 | - list($type2,$val2) = $this->eval_getElement($rule,$item); |
|
273 | + list($type2, $val2)=$this->eval_getElement($rule, $item); |
|
274 | 274 | } |
275 | 275 | //echo "Elmt2: ".$val2."/".$type2." : ".substr($rule,$item)."\n"; |
276 | 276 | |
277 | - if ($type1!=$type2) // cannot compare different types |
|
277 | + if ($type1 != $type2) // cannot compare different types |
|
278 | 278 | { |
279 | 279 | throw new Exception("Cannot compare string & number : ".$rule); |
280 | 280 | } |
281 | - if ($typec==1 && $type1 !=2) // cannot use & or | with string/number |
|
281 | + if ($typec == 1 && $type1 != 2) // cannot use & or | with string/number |
|
282 | 282 | { |
283 | 283 | throw new Exception("Cannot use boolean operators with string & number : ".$rule); |
284 | 284 | } |
285 | 285 | |
286 | - $retVal = $this->do_compare($val1, $val2, $comp, $negate); |
|
286 | + $retVal=$this->do_compare($val1, $val2, $comp, $negate); |
|
287 | 287 | |
288 | - if ($item==strlen($rule)) return $retVal; // End of string : return evaluation |
|
288 | + if ($item == strlen($rule)) return $retVal; // End of string : return evaluation |
|
289 | 289 | // check for logical operator : |
290 | 290 | switch ($rule[$item]) |
291 | 291 | { |
292 | - case '|': $item++; return ($retVal || $this->evaluation($rule,$item) ); |
|
293 | - case '&': $item++; return ($retVal && $this->evaluation($rule,$item) ); |
|
292 | + case '|': $item++; return ($retVal || $this->evaluation($rule, $item)); |
|
293 | + case '&': $item++; return ($retVal && $this->evaluation($rule, $item)); |
|
294 | 294 | |
295 | 295 | default: throw new Exception("Erreur in expr - garbadge at end of expression : ".$rule[$item]); |
296 | 296 | } |
@@ -303,17 +303,17 @@ discard block |
||
303 | 303 | $rule2=''; |
304 | 304 | while ($item < strlen($rule)) |
305 | 305 | { |
306 | - if ($rule[$item]==' ') { $item++; continue; } |
|
307 | - if ($rule[$item]=='"') |
|
306 | + if ($rule[$item] == ' ') { $item++; continue; } |
|
307 | + if ($rule[$item] == '"') |
|
308 | 308 | { |
309 | 309 | $rule2.=$rule[$item]; |
310 | 310 | $item++; |
311 | - while (($item < strlen($rule)) && ($rule[$item]!='"') ) |
|
311 | + while (($item < strlen($rule)) && ($rule[$item] != '"')) |
|
312 | 312 | { |
313 | 313 | $rule2.=$rule[$item]; |
314 | 314 | $item++; |
315 | 315 | } |
316 | - if ($item == strlen ($rule)) throw new Exception("closing '\"' not found in ".$rule ." at " .$item); |
|
316 | + if ($item == strlen($rule)) throw new Exception("closing '\"' not found in ".$rule." at ".$item); |
|
317 | 317 | $rule2.=$rule[$item]; |
318 | 318 | $item++; |
319 | 319 | continue; |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | // replace * with \* in oid for preg_replace |
343 | 343 | $oid=preg_replace('/\*/', '\*', $oid); |
344 | 344 | |
345 | - $this->logging->log('Regexp eval : '.$oid.' / '.$oidR,DEBUG ); |
|
345 | + $this->logging->log('Regexp eval : '.$oid.' / '.$oidR, DEBUG); |
|
346 | 346 | |
347 | 347 | return $oidR; |
348 | 348 | } |
@@ -353,50 +353,50 @@ discard block |
||
353 | 353 | * @param array $oidList : OIDs values to sustitute. |
354 | 354 | * @return bool : true : rule match, false : rule don't match , throw exception on error. |
355 | 355 | */ |
356 | - public function eval_rule($rule,$oidList) |
|
356 | + public function eval_rule($rule, $oidList) |
|
357 | 357 | { |
358 | - if ($rule==null || $rule == '') // Empty rule is always true |
|
358 | + if ($rule == null || $rule == '') // Empty rule is always true |
|
359 | 359 | { |
360 | 360 | return true; |
361 | 361 | } |
362 | 362 | $matches=array(); |
363 | - while (preg_match('/_OID\(([0-9\.\*]+)\)/',$rule,$matches) == 1) |
|
363 | + while (preg_match('/_OID\(([0-9\.\*]+)\)/', $rule, $matches) == 1) |
|
364 | 364 | { |
365 | 365 | $oid=$matches[1]; |
366 | 366 | $found=0; |
367 | 367 | // Test and transform regexp |
368 | - $oidR = $this->regexp_eval($oid); |
|
368 | + $oidR=$this->regexp_eval($oid); |
|
369 | 369 | |
370 | - foreach($oidList as $val) |
|
370 | + foreach ($oidList as $val) |
|
371 | 371 | { |
372 | - if (preg_match("/^$oidR$/",$val->oid) == 1) |
|
372 | + if (preg_match("/^$oidR$/", $val->oid) == 1) |
|
373 | 373 | { |
374 | - if (!preg_match('/^-?[0-9]*\.?[0-9]+$/',$val->value)) |
|
374 | + if (!preg_match('/^-?[0-9]*\.?[0-9]+$/', $val->value)) |
|
375 | 375 | { // If not a number, change " to ' and put " around it |
376 | - $val->value=preg_replace('/"/',"'",$val->value); |
|
376 | + $val->value=preg_replace('/"/', "'", $val->value); |
|
377 | 377 | $val->value='"'.$val->value.'"'; |
378 | 378 | } |
379 | 379 | $rep=0; |
380 | - $rule=preg_replace('/_OID\('.$oid.'\)/',$val->value,$rule,-1,$rep); |
|
381 | - if ($rep==0) |
|
380 | + $rule=preg_replace('/_OID\('.$oid.'\)/', $val->value, $rule, -1, $rep); |
|
381 | + if ($rep == 0) |
|
382 | 382 | { |
383 | - $this->logging->log("Error in rule_eval",WARN,''); |
|
383 | + $this->logging->log("Error in rule_eval", WARN, ''); |
|
384 | 384 | return false; |
385 | 385 | } |
386 | 386 | $found=1; |
387 | 387 | break; |
388 | 388 | } |
389 | 389 | } |
390 | - if ($found==0) |
|
390 | + if ($found == 0) |
|
391 | 391 | { // OID not found : throw error |
392 | 392 | throw new Exception('OID '.$oid.' not found in trap'); |
393 | 393 | } |
394 | 394 | } |
395 | 395 | $item=0; |
396 | 396 | $rule=$this->eval_cleanup($rule); |
397 | - $this->logging->log('Rule after clenup: '.$rule,INFO ); |
|
397 | + $this->logging->log('Rule after clenup: '.$rule, INFO); |
|
398 | 398 | |
399 | - return $this->evaluation($rule,$item); |
|
399 | + return $this->evaluation($rule, $item); |
|
400 | 400 | } |
401 | 401 | |
402 | 402 | } |
403 | 403 | \ No newline at end of file |
@@ -68,14 +68,15 @@ discard block |
||
68 | 68 | $start=$item; |
69 | 69 | $parenthesis_count=0; |
70 | 70 | while (($item < strlen($rule)) // Not end of string AND |
71 | - && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded () |
|
71 | + && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) { |
|
72 | + // Closing ')' or embeded () |
|
72 | 73 | { |
73 | 74 | if ($rule[$item] == '"' ) |
74 | 75 | { // pass through string |
75 | 76 | $item++; |
77 | + } |
|
76 | 78 | $item=$this->eval_getNext($rule,$item,'"'); |
77 | - } |
|
78 | - else{ |
|
79 | + } else{ |
|
79 | 80 | if ($rule[$item] == '(') |
80 | 81 | { |
81 | 82 | $parenthesis_count++; |
@@ -114,9 +115,11 @@ discard block |
||
114 | 115 | { |
115 | 116 | // function is : __function(param1,param2...) |
116 | 117 | $start=$item; |
117 | - while (($item < strlen($rule)) && ($rule[$item] != '(' )) // Not end of string AND not opening '(' |
|
118 | + while (($item < strlen($rule)) && ($rule[$item] != '(' )) { |
|
119 | + // Not end of string AND not opening '(' |
|
118 | 120 | { |
119 | 121 | $item++; |
122 | + } |
|
120 | 123 | } |
121 | 124 | if ($item==strlen($rule)) {throw new Exception("no opening () for function in ".$rule ." at " .$item);} |
122 | 125 | |
@@ -138,7 +141,9 @@ discard block |
||
138 | 141 | { |
139 | 142 | throw new Exception("Early end of string ".$rule ." at " .$item ); |
140 | 143 | } |
141 | - while ($rule[$item]==' ') $item++; |
|
144 | + while ($rule[$item]==' ') { |
|
145 | + $item++; |
|
146 | + } |
|
142 | 147 | if (preg_match('/[\-0-9\.]/',$rule[$item])) |
143 | 148 | { // number |
144 | 149 | return $this->get_number($rule, $item); |
@@ -176,7 +181,9 @@ discard block |
||
176 | 181 | |
177 | 182 | protected function eval_getOper($rule,&$item) |
178 | 183 | { |
179 | - while ($rule[$item]==' ') $item++; |
|
184 | + while ($rule[$item]==' ') { |
|
185 | + $item++; |
|
186 | + } |
|
180 | 187 | switch ($rule[$item]) |
181 | 188 | { |
182 | 189 | case '<': |
@@ -203,12 +210,13 @@ discard block |
||
203 | 210 | |
204 | 211 | private function check_negate_first($rule,&$item) |
205 | 212 | { |
206 | - if ( $rule[$item] == '!') // If '!' found, negate next expression. |
|
213 | + if ( $rule[$item] == '!') { |
|
214 | + // If '!' found, negate next expression. |
|
207 | 215 | { |
208 | 216 | $item++; |
209 | - return true; |
|
210 | 217 | } |
211 | - else |
|
218 | + return true; |
|
219 | + } else |
|
212 | 220 | { |
213 | 221 | return false; |
214 | 222 | } |
@@ -228,7 +236,10 @@ discard block |
||
228 | 236 | case '&': $retVal= ($val1 && $val2); break; |
229 | 237 | default: throw new Exception("Error in expression - unknown comp : ".$comp); |
230 | 238 | } |
231 | - if ($negate === true) $retVal = ! $retVal; // Inverse result if negate before expression |
|
239 | + if ($negate === true) { |
|
240 | + $retVal = ! $retVal; |
|
241 | + } |
|
242 | + // Inverse result if negate before expression |
|
232 | 243 | |
233 | 244 | return $retVal; |
234 | 245 | } |
@@ -249,10 +260,14 @@ discard block |
||
249 | 260 | list($type1,$val1) = $this->eval_getElement($rule,$item); |
250 | 261 | //echo "Elmt1: ".$val1."/".$type1." : ".substr($rule,$item)."\n"; |
251 | 262 | |
252 | - if ($item==strlen($rule)) // If only element, return value, but only boolean |
|
263 | + if ($item==strlen($rule)) { |
|
264 | + // If only element, return value, but only boolean |
|
253 | 265 | { |
254 | 266 | if ($type1 != 2) throw new Exception("Cannot use num/string as boolean : ".$rule); |
255 | - if ($negate === true) $val1= ! $val1; |
|
267 | + } |
|
268 | + if ($negate === true) { |
|
269 | + $val1= ! $val1; |
|
270 | + } |
|
256 | 271 | return $val1; |
257 | 272 | } |
258 | 273 | |
@@ -261,31 +276,41 @@ discard block |
||
261 | 276 | //echo "Comp : ".$comp." : ".substr($rule,$item)."\n"; |
262 | 277 | |
263 | 278 | // Third element : number, string or () |
264 | - if ( $rule[$item] == '!') // starts with a ! so evaluate whats next |
|
279 | + if ( $rule[$item] == '!') { |
|
280 | + // starts with a ! so evaluate whats next |
|
265 | 281 | { |
266 | 282 | $item++; |
267 | - if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule); |
|
283 | + } |
|
284 | + if ($typec != 1) { |
|
285 | + throw new Exception("Mixing boolean and comparison : ".$rule); |
|
286 | + } |
|
268 | 287 | $val2= ! $this->evaluation($rule,$item); |
269 | 288 | $type2=2; // result is a boolean |
270 | - } |
|
271 | - else |
|
289 | + } else |
|
272 | 290 | { |
273 | 291 | list($type2,$val2) = $this->eval_getElement($rule,$item); |
274 | 292 | } |
275 | 293 | //echo "Elmt2: ".$val2."/".$type2." : ".substr($rule,$item)."\n"; |
276 | 294 | |
277 | - if ($type1!=$type2) // cannot compare different types |
|
295 | + if ($type1!=$type2) { |
|
296 | + // cannot compare different types |
|
278 | 297 | { |
279 | 298 | throw new Exception("Cannot compare string & number : ".$rule); |
280 | 299 | } |
281 | - if ($typec==1 && $type1 !=2) // cannot use & or | with string/number |
|
300 | + } |
|
301 | + if ($typec==1 && $type1 !=2) { |
|
302 | + // cannot use & or | with string/number |
|
282 | 303 | { |
283 | 304 | throw new Exception("Cannot use boolean operators with string & number : ".$rule); |
284 | 305 | } |
306 | + } |
|
285 | 307 | |
286 | 308 | $retVal = $this->do_compare($val1, $val2, $comp, $negate); |
287 | 309 | |
288 | - if ($item==strlen($rule)) return $retVal; // End of string : return evaluation |
|
310 | + if ($item==strlen($rule)) { |
|
311 | + return $retVal; |
|
312 | + } |
|
313 | + // End of string : return evaluation |
|
289 | 314 | // check for logical operator : |
290 | 315 | switch ($rule[$item]) |
291 | 316 | { |
@@ -313,7 +338,9 @@ discard block |
||
313 | 338 | $rule2.=$rule[$item]; |
314 | 339 | $item++; |
315 | 340 | } |
316 | - if ($item == strlen ($rule)) throw new Exception("closing '\"' not found in ".$rule ." at " .$item); |
|
341 | + if ($item == strlen ($rule)) { |
|
342 | + throw new Exception("closing '\"' not found in ".$rule ." at " .$item); |
|
343 | + } |
|
317 | 344 | $rule2.=$rule[$item]; |
318 | 345 | $item++; |
319 | 346 | continue; |
@@ -355,10 +382,12 @@ discard block |
||
355 | 382 | */ |
356 | 383 | public function eval_rule($rule,$oidList) |
357 | 384 | { |
358 | - if ($rule==null || $rule == '') // Empty rule is always true |
|
385 | + if ($rule==null || $rule == '') { |
|
386 | + // Empty rule is always true |
|
359 | 387 | { |
360 | 388 | return true; |
361 | 389 | } |
390 | + } |
|
362 | 391 | $matches=array(); |
363 | 392 | while (preg_match('/_OID\(([0-9\.\*]+)\)/',$rule,$matches) == 1) |
364 | 393 | { |
@@ -44,8 +44,8 @@ discard block |
||
44 | 44 | |
45 | 45 | |
46 | 46 | /** Get instance of TrapModuleConfig class |
47 | - * @return TrapModuleConfig |
|
48 | - */ |
|
47 | + * @return TrapModuleConfig |
|
48 | + */ |
|
49 | 49 | public function getModuleConfig() |
50 | 50 | { |
51 | 51 | if ($this->moduleConfig == Null) |
@@ -77,12 +77,12 @@ discard block |
||
77 | 77 | */ |
78 | 78 | public function getTrapHostListTable() |
79 | 79 | { |
80 | - if ($this->trapTableHostList == Null) |
|
80 | + if ($this->trapTableHostList == Null) |
|
81 | 81 | { |
82 | - $this->trapTableHostList = new TrapTableHostList(); |
|
83 | - $this->trapTableHostList->setConfig($this->getModuleConfig()); |
|
84 | - } |
|
85 | - return $this->trapTableHostList; |
|
82 | + $this->trapTableHostList = new TrapTableHostList(); |
|
83 | + $this->trapTableHostList->setConfig($this->getModuleConfig()); |
|
84 | + } |
|
85 | + return $this->trapTableHostList; |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -103,23 +103,23 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function getUIDatabase() |
105 | 105 | { |
106 | - if ($this->UIDatabase == Null) |
|
107 | - { |
|
108 | - $this->UIDatabase = new UIDatabase($this); |
|
106 | + if ($this->UIDatabase == Null) |
|
107 | + { |
|
108 | + $this->UIDatabase = new UIDatabase($this); |
|
109 | 109 | |
110 | - } |
|
111 | - return $this->UIDatabase; |
|
110 | + } |
|
111 | + return $this->UIDatabase; |
|
112 | 112 | } |
113 | 113 | |
114 | - protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null) |
|
115 | - { |
|
116 | - $limit = $this->params->get('limit', $limit); |
|
117 | - $page = $this->params->get('page', $offset); |
|
114 | + protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null) |
|
115 | + { |
|
116 | + $limit = $this->params->get('limit', $limit); |
|
117 | + $page = $this->params->get('page', $offset); |
|
118 | 118 | |
119 | - $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0); |
|
119 | + $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0); |
|
120 | 120 | |
121 | - return $paginatable; |
|
122 | - } |
|
121 | + return $paginatable; |
|
122 | + } |
|
123 | 123 | |
124 | 124 | public function displayExitError($source,$message) |
125 | 125 | { // TODO : check better ways to transmit data (with POST ?) |
@@ -128,33 +128,33 @@ discard block |
||
128 | 128 | |
129 | 129 | protected function checkReadPermission() |
130 | 130 | { |
131 | - if (! $this->Auth()->hasPermission('trapdirector/view')) { |
|
132 | - $this->displayExitError('Permissions','No permission fo view content'); |
|
133 | - } |
|
131 | + if (! $this->Auth()->hasPermission('trapdirector/view')) { |
|
132 | + $this->displayExitError('Permissions','No permission fo view content'); |
|
133 | + } |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | protected function checkConfigPermission() |
137 | 137 | { |
138 | - if (! $this->Auth()->hasPermission('trapdirector/config')) { |
|
139 | - $this->displayExitError('Permissions','No permission fo configure'); |
|
140 | - } |
|
138 | + if (! $this->Auth()->hasPermission('trapdirector/config')) { |
|
139 | + $this->displayExitError('Permissions','No permission fo configure'); |
|
140 | + } |
|
141 | 141 | } |
142 | 142 | |
143 | - /** |
|
144 | - * Check if user has write permission |
|
145 | - * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page |
|
146 | - * @return boolean : user has permission |
|
147 | - */ |
|
143 | + /** |
|
144 | + * Check if user has write permission |
|
145 | + * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page |
|
146 | + * @return boolean : user has permission |
|
147 | + */ |
|
148 | 148 | protected function checkModuleConfigPermission($check=0) |
149 | 149 | { |
150 | - if (! $this->Auth()->hasPermission('trapdirector/module_config')) { |
|
151 | - if ($check == 0) |
|
152 | - { |
|
153 | - $this->displayExitError('Permissions','No permission fo configure module'); |
|
154 | - } |
|
155 | - return false; |
|
156 | - } |
|
157 | - return true; |
|
150 | + if (! $this->Auth()->hasPermission('trapdirector/module_config')) { |
|
151 | + if ($check == 0) |
|
152 | + { |
|
153 | + $this->displayExitError('Permissions','No permission fo configure module'); |
|
154 | + } |
|
155 | + return false; |
|
156 | + } |
|
157 | + return true; |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | /************************* Trap class get **********************/ |
@@ -174,18 +174,18 @@ discard block |
||
174 | 174 | /************************** MIB related **************************/ |
175 | 175 | |
176 | 176 | /** Get MIBLoader class |
177 | - * @return MIBLoader class |
|
178 | - */ |
|
177 | + * @return MIBLoader class |
|
178 | + */ |
|
179 | 179 | protected function getMIB() |
180 | 180 | { |
181 | 181 | if ($this->MIBData == null) |
182 | 182 | { |
183 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
184 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
183 | + $dbConn = $this->getUIDatabase()->getDbConn(); |
|
184 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
185 | 185 | $this->MIBData=new MIBLoader( |
186 | 186 | $this->Config()->get('config', 'snmptranslate'), |
187 | 187 | $this->Config()->get('config', 'snmptranslate_dirs'), |
188 | - $dbConn, |
|
188 | + $dbConn, |
|
189 | 189 | $this->getModuleConfig() |
190 | 190 | ); |
191 | 191 | } |
@@ -195,14 +195,14 @@ discard block |
||
195 | 195 | /************************** Database queries *******************/ |
196 | 196 | |
197 | 197 | /** Get host(s) by IP (v4 or v6) or by name in IDO database |
198 | - * does not catch exceptions |
|
199 | - * @return array of objects ( name, id (object_id), display_name) |
|
200 | - */ |
|
198 | + * does not catch exceptions |
|
199 | + * @return array of objects ( name, id (object_id), display_name) |
|
200 | + */ |
|
201 | 201 | protected function getHostByIP($ip) |
202 | 202 | { |
203 | 203 | // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
204 | - $dbConn = $this->getUIDatabase()->getIdoDbConn(); |
|
205 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
204 | + $dbConn = $this->getUIDatabase()->getIdoDbConn(); |
|
205 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
206 | 206 | |
207 | 207 | // TODO : check for SQL injections |
208 | 208 | $query=$dbConn->select() |
@@ -218,16 +218,16 @@ discard block |
||
218 | 218 | } |
219 | 219 | |
220 | 220 | /** Get host(s) by name in IDO database |
221 | - * does not catch exceptions |
|
222 | - * @return array of objects ( name, id (object_id), display_name) |
|
223 | - */ |
|
221 | + * does not catch exceptions |
|
222 | + * @return array of objects ( name, id (object_id), display_name) |
|
223 | + */ |
|
224 | 224 | protected function getHostByName($name) |
225 | 225 | { |
226 | 226 | // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
227 | - $dbConn = $this->getUIDatabase()->getIdoDbConn(); |
|
228 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
227 | + $dbConn = $this->getUIDatabase()->getIdoDbConn(); |
|
228 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
229 | 229 | |
230 | - // TODO : check for SQL injections |
|
230 | + // TODO : check for SQL injections |
|
231 | 231 | $query=$dbConn->select() |
232 | 232 | ->from( |
233 | 233 | array('a' => 'icinga_objects'), |
@@ -241,14 +241,14 @@ discard block |
||
241 | 241 | } |
242 | 242 | |
243 | 243 | /** Get host groups by name in IDO database |
244 | - * does not catch exceptions |
|
245 | - * @return array of objects ( name, id (object_id), display_name) |
|
246 | - */ |
|
244 | + * does not catch exceptions |
|
245 | + * @return array of objects ( name, id (object_id), display_name) |
|
246 | + */ |
|
247 | 247 | protected function getHostGroupByName($ip) |
248 | 248 | { |
249 | 249 | // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
250 | - $dbConn = $this->getUIDatabase()->getIdoDbConn(); |
|
251 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
250 | + $dbConn = $this->getUIDatabase()->getIdoDbConn(); |
|
251 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
252 | 252 | // TODO : check for SQL injections |
253 | 253 | $query=$dbConn->select() |
254 | 254 | ->from( |
@@ -264,9 +264,9 @@ discard block |
||
264 | 264 | |
265 | 265 | |
266 | 266 | /** Get host IP (v4 and v6) by name in IDO database |
267 | - * does not catch exceptions |
|
268 | - * @return array ( name, display_name, ip4, ip6) |
|
269 | - */ |
|
267 | + * does not catch exceptions |
|
268 | + * @return array ( name, display_name, ip4, ip6) |
|
269 | + */ |
|
270 | 270 | protected function getHostInfoByID($id) |
271 | 271 | { |
272 | 272 | if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
@@ -286,9 +286,9 @@ discard block |
||
286 | 286 | |
287 | 287 | |
288 | 288 | /** Get host by objectid in IDO database |
289 | - * does not catch exceptions |
|
290 | - * @return array of objects ( id, name, display_name, ip, ip6, ) |
|
291 | - */ |
|
289 | + * does not catch exceptions |
|
290 | + * @return array of objects ( id, name, display_name, ip, ip6, ) |
|
291 | + */ |
|
292 | 292 | protected function getHostByObjectID($id) // TODO : duplicate of getHostInfoByID above |
293 | 293 | { |
294 | 294 | if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
@@ -307,10 +307,10 @@ discard block |
||
307 | 307 | } |
308 | 308 | |
309 | 309 | /** Get services from object ( host_object_id) in IDO database |
310 | - * does not catch exceptions |
|
311 | - * @param $id int object_id |
|
312 | - * @return array display_name (of service), service_object_id |
|
313 | - */ |
|
310 | + * does not catch exceptions |
|
311 | + * @param $id int object_id |
|
312 | + * @return array display_name (of service), service_object_id |
|
313 | + */ |
|
314 | 314 | protected function getServicesByHostid($id) |
315 | 315 | { |
316 | 316 | // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
@@ -330,11 +330,11 @@ discard block |
||
330 | 330 | } |
331 | 331 | |
332 | 332 | /** Get services from hostgroup object id ( hostgroup_object_id) in IDO database |
333 | - * gets all hosts in hostgroup and return common services |
|
334 | - * does not catch exceptions |
|
335 | - * @param $id int object_id |
|
336 | - * @return array display_name (of service), service_object_id |
|
337 | - */ |
|
333 | + * gets all hosts in hostgroup and return common services |
|
334 | + * does not catch exceptions |
|
335 | + * @param $id int object_id |
|
336 | + * @return array display_name (of service), service_object_id |
|
337 | + */ |
|
338 | 338 | protected function getServicesByHostGroupid($id) |
339 | 339 | { |
340 | 340 | if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | //print_r($common_services); |
374 | 374 | foreach (array_keys($common_services) as $key) |
375 | 375 | { |
376 | - if ($common_services[$key]['num'] == $num_hosts) |
|
376 | + if ($common_services[$key]['num'] == $num_hosts) |
|
377 | 377 | { |
378 | 378 | array_push($result,array($key,$common_services[$key]['name'])); |
379 | 379 | } |
@@ -383,15 +383,15 @@ discard block |
||
383 | 383 | } |
384 | 384 | |
385 | 385 | /** Get services object id by host name / service name in IDO database |
386 | - * does not catch exceptions |
|
387 | - * @param $hostname string host name |
|
388 | - * @param $name string service name |
|
389 | - * @return array service id |
|
390 | - */ |
|
386 | + * does not catch exceptions |
|
387 | + * @param $hostname string host name |
|
388 | + * @param $name string service name |
|
389 | + * @return array service id |
|
390 | + */ |
|
391 | 391 | protected function getServiceIDByName($hostname,$name) |
392 | 392 | { |
393 | - $dbConn = $this->getUIDatabase()->getIdoDbConn(); |
|
394 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
393 | + $dbConn = $this->getUIDatabase()->getIdoDbConn(); |
|
394 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
395 | 395 | |
396 | 396 | if ($name == null) |
397 | 397 | { |
@@ -412,10 +412,10 @@ discard block |
||
412 | 412 | } |
413 | 413 | |
414 | 414 | /** Get object name from object_id in IDO database |
415 | - * does not catch exceptions |
|
416 | - * @param int $id object_id (default to null, used first if not null) |
|
417 | - * @return array name1 (host) name2 (service) |
|
418 | - */ |
|
415 | + * does not catch exceptions |
|
416 | + * @param int $id object_id (default to null, used first if not null) |
|
417 | + * @return array name1 (host) name2 (service) |
|
418 | + */ |
|
419 | 419 | protected function getObjectNameByid($id) |
420 | 420 | { |
421 | 421 | // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
@@ -433,14 +433,14 @@ discard block |
||
433 | 433 | } |
434 | 434 | |
435 | 435 | /** Add handler rule in traps DB |
436 | - * @param array $params : array(<db item>=><value>) |
|
437 | - * @return int inserted id |
|
438 | - */ |
|
436 | + * @param array $params : array(<db item>=><value>) |
|
437 | + * @return int inserted id |
|
438 | + */ |
|
439 | 439 | protected function addHandlerRule($params) |
440 | 440 | { |
441 | 441 | // TODO Check for rule consistency |
442 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
443 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
442 | + $dbConn = $this->getUIDatabase()->getDbConn(); |
|
443 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
444 | 444 | // Add last modified date = creation date and username |
445 | 445 | $params['created'] = new Zend_Db_Expr('NOW()'); |
446 | 446 | $params['modified'] = new Zend_Db_Expr('NOW()'); |
@@ -458,15 +458,15 @@ discard block |
||
458 | 458 | } |
459 | 459 | |
460 | 460 | /** Update handler rule in traps DB |
461 | - * @param array $params : (<db item>=><value>) |
|
462 | - * @param integer $ruleID : rule id in db |
|
463 | - * @return array affected rows |
|
464 | - */ |
|
461 | + * @param array $params : (<db item>=><value>) |
|
462 | + * @param integer $ruleID : rule id in db |
|
463 | + * @return array affected rows |
|
464 | + */ |
|
465 | 465 | protected function updateHandlerRule($params,$ruleID) |
466 | 466 | { |
467 | 467 | // TODO Check for rule consistency |
468 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
469 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
468 | + $dbConn = $this->getUIDatabase()->getDbConn(); |
|
469 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
470 | 470 | // Add last modified date = creation date and username |
471 | 471 | $params['modified'] = new Zend_Db_Expr('NOW()'); |
472 | 472 | $params['modifier'] = $this->Auth()->getUser()->getUsername(); |
@@ -480,8 +480,8 @@ discard block |
||
480 | 480 | } |
481 | 481 | |
482 | 482 | /** Delete rule by id |
483 | - * @param int $ruleID rule id |
|
484 | - */ |
|
483 | + * @param int $ruleID rule id |
|
484 | + */ |
|
485 | 485 | protected function deleteRule($ruleID) |
486 | 486 | { |
487 | 487 | if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id'); } |
@@ -497,14 +497,14 @@ discard block |
||
497 | 497 | } |
498 | 498 | |
499 | 499 | /** Delete trap by ip & oid |
500 | - * @param $ip string source IP (v4 or v6) |
|
501 | - * @param $oid string oid |
|
502 | - */ |
|
500 | + * @param $ip string source IP (v4 or v6) |
|
501 | + * @param $oid string oid |
|
502 | + */ |
|
503 | 503 | protected function deleteTrap($ip,$oid) |
504 | 504 | { |
505 | 505 | |
506 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
507 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
506 | + $dbConn = $this->getUIDatabase()->getDbConn(); |
|
507 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
508 | 508 | $condition=null; |
509 | 509 | if ($ip != null) |
510 | 510 | { |
@@ -526,14 +526,14 @@ discard block |
||
526 | 526 | |
527 | 527 | |
528 | 528 | /** count trap by ip & oid |
529 | - * @param $ip string source IP (v4 or v6) |
|
530 | - * @param $oid string oid |
|
531 | - */ |
|
529 | + * @param $ip string source IP (v4 or v6) |
|
530 | + * @param $oid string oid |
|
531 | + */ |
|
532 | 532 | protected function countTrap($ip,$oid) |
533 | 533 | { |
534 | 534 | |
535 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
536 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
535 | + $dbConn = $this->getUIDatabase()->getDbConn(); |
|
536 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
537 | 537 | |
538 | 538 | $condition=null; |
539 | 539 | if ($ip != null) |
@@ -556,15 +556,15 @@ discard block |
||
556 | 556 | } |
557 | 557 | |
558 | 558 | /** get configuration value |
559 | - * @param string $element : configuration name in db |
|
560 | - */ |
|
559 | + * @param string $element : configuration name in db |
|
560 | + */ |
|
561 | 561 | protected function getDBConfigValue($element) |
562 | 562 | { |
563 | 563 | |
564 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
565 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
564 | + $dbConn = $this->getUIDatabase()->getDbConn(); |
|
565 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
566 | 566 | |
567 | - $query=$dbConn->select() |
|
567 | + $query=$dbConn->select() |
|
568 | 568 | ->from( |
569 | 569 | $this->getModuleConfig()->getDbConfigTableName(), |
570 | 570 | array('value'=>'value')) |
@@ -589,17 +589,17 @@ discard block |
||
589 | 589 | } |
590 | 590 | |
591 | 591 | /** add configuration value |
592 | - * @param string $element : name of config element |
|
593 | - * @param string $value : value |
|
594 | - */ |
|
592 | + * @param string $element : name of config element |
|
593 | + * @param string $value : value |
|
594 | + */ |
|
595 | 595 | |
596 | 596 | protected function addDBConfigValue($element,$value) |
597 | 597 | { |
598 | 598 | |
599 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
600 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
599 | + $dbConn = $this->getUIDatabase()->getDbConn(); |
|
600 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
601 | 601 | |
602 | - $query=$dbConn->insert( |
|
602 | + $query=$dbConn->insert( |
|
603 | 603 | $this->getModuleConfig()->getDbConfigTableName(), |
604 | 604 | array( |
605 | 605 | 'name' => $element, |
@@ -610,16 +610,16 @@ discard block |
||
610 | 610 | } |
611 | 611 | |
612 | 612 | /** set configuration value |
613 | - * @param string $element : name of config element |
|
614 | - * @param string $value : value |
|
615 | - */ |
|
613 | + * @param string $element : name of config element |
|
614 | + * @param string $value : value |
|
615 | + */ |
|
616 | 616 | protected function setDBConfigValue($element,$value) |
617 | 617 | { |
618 | 618 | |
619 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
620 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
619 | + $dbConn = $this->getUIDatabase()->getDbConn(); |
|
620 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
621 | 621 | |
622 | - $query=$dbConn->update( |
|
622 | + $query=$dbConn->update( |
|
623 | 623 | $this->getModuleConfig()->getDbConfigTableName(), |
624 | 624 | array('value'=>$value), |
625 | 625 | 'name=\''.$element.'\'' |
@@ -628,13 +628,13 @@ discard block |
||
628 | 628 | } |
629 | 629 | |
630 | 630 | /** Check if director is installed |
631 | - * @return bool true/false |
|
632 | - */ |
|
631 | + * @return bool true/false |
|
632 | + */ |
|
633 | 633 | protected function isDirectorInstalled() |
634 | 634 | { |
635 | - $output=array(); |
|
636 | - exec('icingacli module list',$output); |
|
637 | - foreach ($output as $line) |
|
635 | + $output=array(); |
|
636 | + exec('icingacli module list',$output); |
|
637 | + foreach ($output as $line) |
|
638 | 638 | { |
639 | 639 | if (preg_match('/^director .*enabled/',$line)) |
640 | 640 | { |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | { |
56 | 56 | $this->redirectNow('trapdirector/settings?message=No database prefix'); |
57 | 57 | } |
58 | - $this->moduleConfig = new TrapModuleConfig($db_prefix); |
|
58 | + $this->moduleConfig=new TrapModuleConfig($db_prefix); |
|
59 | 59 | } |
60 | 60 | return $this->moduleConfig; |
61 | 61 | } |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function getTrapListTable() { |
68 | 68 | if ($this->trapTableList == Null) { |
69 | - $this->trapTableList = new TrapTableList(); |
|
69 | + $this->trapTableList=new TrapTableList(); |
|
70 | 70 | $this->trapTableList->setConfig($this->getModuleConfig()); |
71 | 71 | } |
72 | 72 | return $this->trapTableList; |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | { |
80 | 80 | if ($this->trapTableHostList == Null) |
81 | 81 | { |
82 | - $this->trapTableHostList = new TrapTableHostList(); |
|
82 | + $this->trapTableHostList=new TrapTableHostList(); |
|
83 | 83 | $this->trapTableHostList->setConfig($this->getModuleConfig()); |
84 | 84 | } |
85 | 85 | return $this->trapTableHostList; |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | { |
93 | 93 | if ($this->handlerTableList == Null) |
94 | 94 | { |
95 | - $this->handlerTableList = new HandlerTableList(); |
|
95 | + $this->handlerTableList=new HandlerTableList(); |
|
96 | 96 | $this->handlerTableList->setConfig($this->getModuleConfig()); |
97 | 97 | } |
98 | 98 | return $this->handlerTableList; |
@@ -105,38 +105,38 @@ discard block |
||
105 | 105 | { |
106 | 106 | if ($this->UIDatabase == Null) |
107 | 107 | { |
108 | - $this->UIDatabase = new UIDatabase($this); |
|
108 | + $this->UIDatabase=new UIDatabase($this); |
|
109 | 109 | |
110 | 110 | } |
111 | 111 | return $this->UIDatabase; |
112 | 112 | } |
113 | 113 | |
114 | - protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null) |
|
114 | + protected function applyPaginationLimits(Paginatable $paginatable, $limit=25, $offset=null) |
|
115 | 115 | { |
116 | - $limit = $this->params->get('limit', $limit); |
|
117 | - $page = $this->params->get('page', $offset); |
|
116 | + $limit=$this->params->get('limit', $limit); |
|
117 | + $page=$this->params->get('page', $offset); |
|
118 | 118 | |
119 | 119 | $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0); |
120 | 120 | |
121 | 121 | return $paginatable; |
122 | 122 | } |
123 | 123 | |
124 | - public function displayExitError($source,$message) |
|
124 | + public function displayExitError($source, $message) |
|
125 | 125 | { // TODO : check better ways to transmit data (with POST ?) |
126 | 126 | $this->redirectNow('trapdirector/error?source='.$source.'&message='.$message); |
127 | 127 | } |
128 | 128 | |
129 | 129 | protected function checkReadPermission() |
130 | 130 | { |
131 | - if (! $this->Auth()->hasPermission('trapdirector/view')) { |
|
132 | - $this->displayExitError('Permissions','No permission fo view content'); |
|
131 | + if (!$this->Auth()->hasPermission('trapdirector/view')) { |
|
132 | + $this->displayExitError('Permissions', 'No permission fo view content'); |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | |
136 | 136 | protected function checkConfigPermission() |
137 | 137 | { |
138 | - if (! $this->Auth()->hasPermission('trapdirector/config')) { |
|
139 | - $this->displayExitError('Permissions','No permission fo configure'); |
|
138 | + if (!$this->Auth()->hasPermission('trapdirector/config')) { |
|
139 | + $this->displayExitError('Permissions', 'No permission fo configure'); |
|
140 | 140 | } |
141 | 141 | } |
142 | 142 | |
@@ -147,10 +147,10 @@ discard block |
||
147 | 147 | */ |
148 | 148 | protected function checkModuleConfigPermission($check=0) |
149 | 149 | { |
150 | - if (! $this->Auth()->hasPermission('trapdirector/module_config')) { |
|
150 | + if (!$this->Auth()->hasPermission('trapdirector/module_config')) { |
|
151 | 151 | if ($check == 0) |
152 | 152 | { |
153 | - $this->displayExitError('Permissions','No permission fo configure module'); |
|
153 | + $this->displayExitError('Permissions', 'No permission fo configure module'); |
|
154 | 154 | } |
155 | 155 | return false; |
156 | 156 | } |
@@ -162,10 +162,10 @@ discard block |
||
162 | 162 | { // TODO : try/catch here ? or within caller |
163 | 163 | if ($this->trapClass == null) |
164 | 164 | { |
165 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
165 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
166 | 166 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
167 | 167 | //$debug_level=4; |
168 | - $this->trapClass = new Trap($icingaweb2_etc); |
|
168 | + $this->trapClass=new Trap($icingaweb2_etc); |
|
169 | 169 | //$Trap->setLogging($debug_level,'syslog'); |
170 | 170 | } |
171 | 171 | return $this->trapClass; |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | { |
181 | 181 | if ($this->MIBData == null) |
182 | 182 | { |
183 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
183 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
184 | 184 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
185 | 185 | $this->MIBData=new MIBLoader( |
186 | 186 | $this->Config()->get('config', 'snmptranslate'), |
@@ -201,14 +201,14 @@ discard block |
||
201 | 201 | protected function getHostByIP($ip) |
202 | 202 | { |
203 | 203 | // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
204 | - $dbConn = $this->getUIDatabase()->getIdoDbConn(); |
|
204 | + $dbConn=$this->getUIDatabase()->getIdoDbConn(); |
|
205 | 205 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
206 | 206 | |
207 | 207 | // TODO : check for SQL injections |
208 | 208 | $query=$dbConn->select() |
209 | 209 | ->from( |
210 | 210 | array('a' => 'icinga_objects'), |
211 | - array('name' => 'a.name1','id' => 'object_id')) |
|
211 | + array('name' => 'a.name1', 'id' => 'object_id')) |
|
212 | 212 | ->join( |
213 | 213 | array('b' => 'icinga_hosts'), |
214 | 214 | 'b.host_object_id=a.object_id', |
@@ -224,14 +224,14 @@ discard block |
||
224 | 224 | protected function getHostByName($name) |
225 | 225 | { |
226 | 226 | // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
227 | - $dbConn = $this->getUIDatabase()->getIdoDbConn(); |
|
227 | + $dbConn=$this->getUIDatabase()->getIdoDbConn(); |
|
228 | 228 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
229 | 229 | |
230 | 230 | // TODO : check for SQL injections |
231 | 231 | $query=$dbConn->select() |
232 | 232 | ->from( |
233 | 233 | array('a' => 'icinga_objects'), |
234 | - array('name' => 'a.name1','id' => 'object_id')) |
|
234 | + array('name' => 'a.name1', 'id' => 'object_id')) |
|
235 | 235 | ->join( |
236 | 236 | array('b' => 'icinga_hosts'), |
237 | 237 | 'b.host_object_id=a.object_id', |
@@ -247,13 +247,13 @@ discard block |
||
247 | 247 | protected function getHostGroupByName($ip) |
248 | 248 | { |
249 | 249 | // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
250 | - $dbConn = $this->getUIDatabase()->getIdoDbConn(); |
|
250 | + $dbConn=$this->getUIDatabase()->getIdoDbConn(); |
|
251 | 251 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
252 | 252 | // TODO : check for SQL injections |
253 | 253 | $query=$dbConn->select() |
254 | 254 | ->from( |
255 | 255 | array('a' => 'icinga_objects'), |
256 | - array('name' => 'a.name1','id' => 'object_id')) |
|
256 | + array('name' => 'a.name1', 'id' => 'object_id')) |
|
257 | 257 | ->join( |
258 | 258 | array('b' => 'icinga_hostgroups'), |
259 | 259 | 'b.hostgroup_object_id=a.object_id', |
@@ -269,8 +269,8 @@ discard block |
||
269 | 269 | */ |
270 | 270 | protected function getHostInfoByID($id) |
271 | 271 | { |
272 | - if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
273 | - $dbConn = $this->getUIDatabase()->getIdoDbConn(); |
|
272 | + if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); } |
|
273 | + $dbConn=$this->getUIDatabase()->getIdoDbConn(); |
|
274 | 274 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
275 | 275 | $query=$dbConn->select() |
276 | 276 | ->from( |
@@ -291,18 +291,18 @@ discard block |
||
291 | 291 | */ |
292 | 292 | protected function getHostByObjectID($id) // TODO : duplicate of getHostInfoByID above |
293 | 293 | { |
294 | - if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
295 | - $dbConn = $this->getUIDatabase()->getIdoDbConn(); |
|
294 | + if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); } |
|
295 | + $dbConn=$this->getUIDatabase()->getIdoDbConn(); |
|
296 | 296 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
297 | 297 | $query=$dbConn->select() |
298 | 298 | ->from( |
299 | 299 | array('a' => 'icinga_objects'), |
300 | - array('name' => 'a.name1','id' => 'a.object_id')) |
|
300 | + array('name' => 'a.name1', 'id' => 'a.object_id')) |
|
301 | 301 | ->join( |
302 | 302 | array('b' => 'icinga_hosts'), |
303 | 303 | 'b.host_object_id=a.object_id', |
304 | - array('display_name' => 'b.display_name' , 'ip' => 'b.address', 'ip6' => 'b.address6')) |
|
305 | - ->where('a.object_id = ?',$id); |
|
304 | + array('display_name' => 'b.display_name', 'ip' => 'b.address', 'ip6' => 'b.address6')) |
|
305 | + ->where('a.object_id = ?', $id); |
|
306 | 306 | return $dbConn->fetchRow($query); |
307 | 307 | } |
308 | 308 | |
@@ -314,17 +314,17 @@ discard block |
||
314 | 314 | protected function getServicesByHostid($id) |
315 | 315 | { |
316 | 316 | // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
317 | - if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
318 | - $dbConn = $this->getUIDatabase()->getIdoDbConn(); |
|
317 | + if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); } |
|
318 | + $dbConn=$this->getUIDatabase()->getIdoDbConn(); |
|
319 | 319 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
320 | 320 | $query=$dbConn->select() |
321 | 321 | ->from( |
322 | 322 | array('s' => 'icinga_services'), |
323 | - array('name' => 's.display_name','id' => 's.service_object_id')) |
|
323 | + array('name' => 's.display_name', 'id' => 's.service_object_id')) |
|
324 | 324 | ->join( |
325 | 325 | array('a' => 'icinga_objects'), |
326 | 326 | 's.service_object_id=a.object_id', |
327 | - array('is_active'=>'a.is_active','name2'=>'a.name2')) |
|
327 | + array('is_active'=>'a.is_active', 'name2'=>'a.name2')) |
|
328 | 328 | ->where('s.host_object_id='.$id.' AND a.is_active = 1'); |
329 | 329 | return $dbConn->fetchAll($query); |
330 | 330 | } |
@@ -337,8 +337,8 @@ discard block |
||
337 | 337 | */ |
338 | 338 | protected function getServicesByHostGroupid($id) |
339 | 339 | { |
340 | - if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
341 | - $dbConn = $this->getUIDatabase()->getIdoDbConn(); |
|
340 | + if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); } |
|
341 | + $dbConn=$this->getUIDatabase()->getIdoDbConn(); |
|
342 | 342 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
343 | 343 | $query=$dbConn->select() |
344 | 344 | ->from( |
@@ -355,11 +355,11 @@ discard block |
||
355 | 355 | foreach ($hosts as $key => $host) |
356 | 356 | { // For each host, get all services and add in common_services if not found or add counter |
357 | 357 | $host_services=$this->getServicesByHostid($host->host_object_id); |
358 | - foreach($host_services as $service) |
|
358 | + foreach ($host_services as $service) |
|
359 | 359 | { |
360 | 360 | if (isset($common_services[$service->name2]['num'])) |
361 | 361 | { |
362 | - $common_services[$service->name2]['num'] +=1; |
|
362 | + $common_services[$service->name2]['num']+=1; |
|
363 | 363 | } |
364 | 364 | else |
365 | 365 | { |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | { |
376 | 376 | if ($common_services[$key]['num'] == $num_hosts) |
377 | 377 | { |
378 | - array_push($result,array($key,$common_services[$key]['name'])); |
|
378 | + array_push($result, array($key, $common_services[$key]['name'])); |
|
379 | 379 | } |
380 | 380 | } |
381 | 381 | |
@@ -388,9 +388,9 @@ discard block |
||
388 | 388 | * @param $name string service name |
389 | 389 | * @return array service id |
390 | 390 | */ |
391 | - protected function getServiceIDByName($hostname,$name) |
|
391 | + protected function getServiceIDByName($hostname, $name) |
|
392 | 392 | { |
393 | - $dbConn = $this->getUIDatabase()->getIdoDbConn(); |
|
393 | + $dbConn=$this->getUIDatabase()->getIdoDbConn(); |
|
394 | 394 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
395 | 395 | |
396 | 396 | if ($name == null) |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | $query=$dbConn->select() |
402 | 402 | ->from( |
403 | 403 | array('s' => 'icinga_services'), |
404 | - array('name' => 's.display_name','id' => 's.service_object_id')) |
|
404 | + array('name' => 's.display_name', 'id' => 's.service_object_id')) |
|
405 | 405 | ->join( |
406 | 406 | array('a' => 'icinga_objects'), |
407 | 407 | 's.service_object_id=a.object_id', |
@@ -419,14 +419,14 @@ discard block |
||
419 | 419 | protected function getObjectNameByid($id) |
420 | 420 | { |
421 | 421 | // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
422 | - if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
423 | - $dbConn = $this->getUIDatabase()->getIdoDbConn(); |
|
422 | + if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); } |
|
423 | + $dbConn=$this->getUIDatabase()->getIdoDbConn(); |
|
424 | 424 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
425 | 425 | |
426 | 426 | $query=$dbConn->select() |
427 | 427 | ->from( |
428 | 428 | array('a' => 'icinga_objects'), |
429 | - array('name1' => 'a.name1','name2' => 'a.name2')) |
|
429 | + array('name1' => 'a.name1', 'name2' => 'a.name2')) |
|
430 | 430 | ->where('a.object_id='.$id.' AND a.is_active = 1'); |
431 | 431 | |
432 | 432 | return $dbConn->fetchRow($query); |
@@ -439,18 +439,18 @@ discard block |
||
439 | 439 | protected function addHandlerRule($params) |
440 | 440 | { |
441 | 441 | // TODO Check for rule consistency |
442 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
442 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
443 | 443 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
444 | 444 | // Add last modified date = creation date and username |
445 | - $params['created'] = new Zend_Db_Expr('NOW()'); |
|
446 | - $params['modified'] = new Zend_Db_Expr('NOW()'); |
|
447 | - $params['modifier'] = $this->Auth()->getUser()->getUsername(); |
|
445 | + $params['created']=new Zend_Db_Expr('NOW()'); |
|
446 | + $params['modified']=new Zend_Db_Expr('NOW()'); |
|
447 | + $params['modifier']=$this->Auth()->getUser()->getUsername(); |
|
448 | 448 | |
449 | 449 | $query=$dbConn->insert( |
450 | 450 | $this->getModuleConfig()->getTrapRuleName(), |
451 | 451 | $params |
452 | 452 | ); |
453 | - if($query==false) |
|
453 | + if ($query == false) |
|
454 | 454 | { |
455 | 455 | return null; |
456 | 456 | } |
@@ -462,14 +462,14 @@ discard block |
||
462 | 462 | * @param integer $ruleID : rule id in db |
463 | 463 | * @return array affected rows |
464 | 464 | */ |
465 | - protected function updateHandlerRule($params,$ruleID) |
|
465 | + protected function updateHandlerRule($params, $ruleID) |
|
466 | 466 | { |
467 | 467 | // TODO Check for rule consistency |
468 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
468 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
469 | 469 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
470 | 470 | // Add last modified date = creation date and username |
471 | - $params['modified'] = new Zend_Db_Expr('NOW()'); |
|
472 | - $params['modifier'] = $this->Auth()->getUser()->getUsername(); |
|
471 | + $params['modified']=new Zend_Db_Expr('NOW()'); |
|
472 | + $params['modifier']=$this->Auth()->getUser()->getUsername(); |
|
473 | 473 | |
474 | 474 | $numRows=$dbConn->update( |
475 | 475 | $this->getModuleConfig()->getTrapRuleName(), |
@@ -484,9 +484,9 @@ discard block |
||
484 | 484 | */ |
485 | 485 | protected function deleteRule($ruleID) |
486 | 486 | { |
487 | - if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id'); } |
|
487 | + if (!preg_match('/^[0-9]+$/', $ruleID)) { throw new Exception('Invalid id'); } |
|
488 | 488 | |
489 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
489 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
490 | 490 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
491 | 491 | |
492 | 492 | $query=$dbConn->delete( |
@@ -500,10 +500,10 @@ discard block |
||
500 | 500 | * @param $ip string source IP (v4 or v6) |
501 | 501 | * @param $oid string oid |
502 | 502 | */ |
503 | - protected function deleteTrap($ip,$oid) |
|
503 | + protected function deleteTrap($ip, $oid) |
|
504 | 504 | { |
505 | 505 | |
506 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
506 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
507 | 507 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
508 | 508 | $condition=null; |
509 | 509 | if ($ip != null) |
@@ -512,10 +512,10 @@ discard block |
||
512 | 512 | } |
513 | 513 | if ($oid != null) |
514 | 514 | { |
515 | - $condition=($condition===null)?'':$condition.' AND '; |
|
515 | + $condition=($condition === null) ? '' : $condition.' AND '; |
|
516 | 516 | $condition.="trap_oid='$oid'"; |
517 | 517 | } |
518 | - if($condition === null) return null; |
|
518 | + if ($condition === null) return null; |
|
519 | 519 | $query=$dbConn->delete( |
520 | 520 | $this->getModuleConfig()->getTrapTableName(), |
521 | 521 | $condition |
@@ -529,10 +529,10 @@ discard block |
||
529 | 529 | * @param $ip string source IP (v4 or v6) |
530 | 530 | * @param $oid string oid |
531 | 531 | */ |
532 | - protected function countTrap($ip,$oid) |
|
532 | + protected function countTrap($ip, $oid) |
|
533 | 533 | { |
534 | 534 | |
535 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
535 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
536 | 536 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
537 | 537 | |
538 | 538 | $condition=null; |
@@ -542,10 +542,10 @@ discard block |
||
542 | 542 | } |
543 | 543 | if ($oid != null) |
544 | 544 | { |
545 | - $condition=($condition===null)?'':$condition.' AND '; |
|
545 | + $condition=($condition === null) ? '' : $condition.' AND '; |
|
546 | 546 | $condition.="trap_oid='$oid'"; |
547 | 547 | } |
548 | - if($condition === null) return 0; |
|
548 | + if ($condition === null) return 0; |
|
549 | 549 | $query=$dbConn->select() |
550 | 550 | ->from( |
551 | 551 | $this->getModuleConfig()->getTrapTableName(), |
@@ -561,28 +561,28 @@ discard block |
||
561 | 561 | protected function getDBConfigValue($element) |
562 | 562 | { |
563 | 563 | |
564 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
564 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
565 | 565 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
566 | 566 | |
567 | 567 | $query=$dbConn->select() |
568 | 568 | ->from( |
569 | 569 | $this->getModuleConfig()->getDbConfigTableName(), |
570 | 570 | array('value'=>'value')) |
571 | - ->where('name=?',$element); |
|
571 | + ->where('name=?', $element); |
|
572 | 572 | $return_row=$dbConn->fetchRow($query); |
573 | - if ($return_row==null) // value does not exists |
|
573 | + if ($return_row == null) // value does not exists |
|
574 | 574 | { |
575 | 575 | $default=$this->getModuleConfig()->getDBConfigDefaults(); |
576 | - if ( ! isset($default[$element])) return null; // no default and not value |
|
576 | + if (!isset($default[$element])) return null; // no default and not value |
|
577 | 577 | |
578 | - $this->addDBConfigValue($element,$default[$element]); |
|
578 | + $this->addDBConfigValue($element, $default[$element]); |
|
579 | 579 | return $default[$element]; |
580 | 580 | } |
581 | 581 | if ($return_row->value == null) // value id empty |
582 | 582 | { |
583 | 583 | $default=$this->getModuleConfig()->getDBConfigDefaults(); |
584 | - if ( ! isset($default[$element])) return null; // no default and not value |
|
585 | - $this->setDBConfigValue($element,$default[$element]); |
|
584 | + if (!isset($default[$element])) return null; // no default and not value |
|
585 | + $this->setDBConfigValue($element, $default[$element]); |
|
586 | 586 | return $default[$element]; |
587 | 587 | } |
588 | 588 | return $return_row->value; |
@@ -593,10 +593,10 @@ discard block |
||
593 | 593 | * @param string $value : value |
594 | 594 | */ |
595 | 595 | |
596 | - protected function addDBConfigValue($element,$value) |
|
596 | + protected function addDBConfigValue($element, $value) |
|
597 | 597 | { |
598 | 598 | |
599 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
599 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
600 | 600 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
601 | 601 | |
602 | 602 | $query=$dbConn->insert( |
@@ -613,10 +613,10 @@ discard block |
||
613 | 613 | * @param string $element : name of config element |
614 | 614 | * @param string $value : value |
615 | 615 | */ |
616 | - protected function setDBConfigValue($element,$value) |
|
616 | + protected function setDBConfigValue($element, $value) |
|
617 | 617 | { |
618 | 618 | |
619 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
619 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
620 | 620 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
621 | 621 | |
622 | 622 | $query=$dbConn->update( |
@@ -633,10 +633,10 @@ discard block |
||
633 | 633 | protected function isDirectorInstalled() |
634 | 634 | { |
635 | 635 | $output=array(); |
636 | - exec('icingacli module list',$output); |
|
636 | + exec('icingacli module list', $output); |
|
637 | 637 | foreach ($output as $line) |
638 | 638 | { |
639 | - if (preg_match('/^director .*enabled/',$line)) |
|
639 | + if (preg_match('/^director .*enabled/', $line)) |
|
640 | 640 | { |
641 | 641 | return true; |
642 | 642 | } |
@@ -181,7 +181,9 @@ discard block |
||
181 | 181 | if ($this->MIBData == null) |
182 | 182 | { |
183 | 183 | $dbConn = $this->getUIDatabase()->getDbConn(); |
184 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
184 | + if ($dbConn === null) { |
|
185 | + throw new \ErrorException('uncatched db error'); |
|
186 | + } |
|
185 | 187 | $this->MIBData=new MIBLoader( |
186 | 188 | $this->Config()->get('config', 'snmptranslate'), |
187 | 189 | $this->Config()->get('config', 'snmptranslate_dirs'), |
@@ -202,7 +204,9 @@ discard block |
||
202 | 204 | { |
203 | 205 | // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
204 | 206 | $dbConn = $this->getUIDatabase()->getIdoDbConn(); |
205 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
207 | + if ($dbConn === null) { |
|
208 | + throw new \ErrorException('uncatched db error'); |
|
209 | + } |
|
206 | 210 | |
207 | 211 | // TODO : check for SQL injections |
208 | 212 | $query=$dbConn->select() |
@@ -225,7 +229,9 @@ discard block |
||
225 | 229 | { |
226 | 230 | // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
227 | 231 | $dbConn = $this->getUIDatabase()->getIdoDbConn(); |
228 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
232 | + if ($dbConn === null) { |
|
233 | + throw new \ErrorException('uncatched db error'); |
|
234 | + } |
|
229 | 235 | |
230 | 236 | // TODO : check for SQL injections |
231 | 237 | $query=$dbConn->select() |
@@ -248,7 +254,9 @@ discard block |
||
248 | 254 | { |
249 | 255 | // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
250 | 256 | $dbConn = $this->getUIDatabase()->getIdoDbConn(); |
251 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
257 | + if ($dbConn === null) { |
|
258 | + throw new \ErrorException('uncatched db error'); |
|
259 | + } |
|
252 | 260 | // TODO : check for SQL injections |
253 | 261 | $query=$dbConn->select() |
254 | 262 | ->from( |
@@ -271,7 +279,9 @@ discard block |
||
271 | 279 | { |
272 | 280 | if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
273 | 281 | $dbConn = $this->getUIDatabase()->getIdoDbConn(); |
274 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
282 | + if ($dbConn === null) { |
|
283 | + throw new \ErrorException('uncatched db error'); |
|
284 | + } |
|
275 | 285 | $query=$dbConn->select() |
276 | 286 | ->from( |
277 | 287 | array('a' => 'icinga_objects'), |
@@ -293,7 +303,9 @@ discard block |
||
293 | 303 | { |
294 | 304 | if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
295 | 305 | $dbConn = $this->getUIDatabase()->getIdoDbConn(); |
296 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
306 | + if ($dbConn === null) { |
|
307 | + throw new \ErrorException('uncatched db error'); |
|
308 | + } |
|
297 | 309 | $query=$dbConn->select() |
298 | 310 | ->from( |
299 | 311 | array('a' => 'icinga_objects'), |
@@ -316,7 +328,9 @@ discard block |
||
316 | 328 | // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
317 | 329 | if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
318 | 330 | $dbConn = $this->getUIDatabase()->getIdoDbConn(); |
319 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
331 | + if ($dbConn === null) { |
|
332 | + throw new \ErrorException('uncatched db error'); |
|
333 | + } |
|
320 | 334 | $query=$dbConn->select() |
321 | 335 | ->from( |
322 | 336 | array('s' => 'icinga_services'), |
@@ -339,7 +353,9 @@ discard block |
||
339 | 353 | { |
340 | 354 | if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
341 | 355 | $dbConn = $this->getUIDatabase()->getIdoDbConn(); |
342 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
356 | + if ($dbConn === null) { |
|
357 | + throw new \ErrorException('uncatched db error'); |
|
358 | + } |
|
343 | 359 | $query=$dbConn->select() |
344 | 360 | ->from( |
345 | 361 | array('s' => 'icinga_hostgroup_members'), |
@@ -360,8 +376,7 @@ discard block |
||
360 | 376 | if (isset($common_services[$service->name2]['num'])) |
361 | 377 | { |
362 | 378 | $common_services[$service->name2]['num'] +=1; |
363 | - } |
|
364 | - else |
|
379 | + } else |
|
365 | 380 | { |
366 | 381 | $common_services[$service->name2]['num']=1; |
367 | 382 | $common_services[$service->name2]['name']=$service->name; |
@@ -391,7 +406,9 @@ discard block |
||
391 | 406 | protected function getServiceIDByName($hostname,$name) |
392 | 407 | { |
393 | 408 | $dbConn = $this->getUIDatabase()->getIdoDbConn(); |
394 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
409 | + if ($dbConn === null) { |
|
410 | + throw new \ErrorException('uncatched db error'); |
|
411 | + } |
|
395 | 412 | |
396 | 413 | if ($name == null) |
397 | 414 | { |
@@ -421,7 +438,9 @@ discard block |
||
421 | 438 | // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
422 | 439 | if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
423 | 440 | $dbConn = $this->getUIDatabase()->getIdoDbConn(); |
424 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
441 | + if ($dbConn === null) { |
|
442 | + throw new \ErrorException('uncatched db error'); |
|
443 | + } |
|
425 | 444 | |
426 | 445 | $query=$dbConn->select() |
427 | 446 | ->from( |
@@ -440,7 +459,9 @@ discard block |
||
440 | 459 | { |
441 | 460 | // TODO Check for rule consistency |
442 | 461 | $dbConn = $this->getUIDatabase()->getDbConn(); |
443 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
462 | + if ($dbConn === null) { |
|
463 | + throw new \ErrorException('uncatched db error'); |
|
464 | + } |
|
444 | 465 | // Add last modified date = creation date and username |
445 | 466 | $params['created'] = new Zend_Db_Expr('NOW()'); |
446 | 467 | $params['modified'] = new Zend_Db_Expr('NOW()'); |
@@ -466,7 +487,9 @@ discard block |
||
466 | 487 | { |
467 | 488 | // TODO Check for rule consistency |
468 | 489 | $dbConn = $this->getUIDatabase()->getDbConn(); |
469 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
490 | + if ($dbConn === null) { |
|
491 | + throw new \ErrorException('uncatched db error'); |
|
492 | + } |
|
470 | 493 | // Add last modified date = creation date and username |
471 | 494 | $params['modified'] = new Zend_Db_Expr('NOW()'); |
472 | 495 | $params['modifier'] = $this->Auth()->getUser()->getUsername(); |
@@ -487,7 +510,9 @@ discard block |
||
487 | 510 | if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id'); } |
488 | 511 | |
489 | 512 | $dbConn = $this->getUIDatabase()->getDbConn(); |
490 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
513 | + if ($dbConn === null) { |
|
514 | + throw new \ErrorException('uncatched db error'); |
|
515 | + } |
|
491 | 516 | |
492 | 517 | $query=$dbConn->delete( |
493 | 518 | $this->getModuleConfig()->getTrapRuleName(), |
@@ -504,7 +529,9 @@ discard block |
||
504 | 529 | { |
505 | 530 | |
506 | 531 | $dbConn = $this->getUIDatabase()->getDbConn(); |
507 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
532 | + if ($dbConn === null) { |
|
533 | + throw new \ErrorException('uncatched db error'); |
|
534 | + } |
|
508 | 535 | $condition=null; |
509 | 536 | if ($ip != null) |
510 | 537 | { |
@@ -515,7 +542,9 @@ discard block |
||
515 | 542 | $condition=($condition===null)?'':$condition.' AND '; |
516 | 543 | $condition.="trap_oid='$oid'"; |
517 | 544 | } |
518 | - if($condition === null) return null; |
|
545 | + if($condition === null) { |
|
546 | + return null; |
|
547 | + } |
|
519 | 548 | $query=$dbConn->delete( |
520 | 549 | $this->getModuleConfig()->getTrapTableName(), |
521 | 550 | $condition |
@@ -533,7 +562,9 @@ discard block |
||
533 | 562 | { |
534 | 563 | |
535 | 564 | $dbConn = $this->getUIDatabase()->getDbConn(); |
536 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
565 | + if ($dbConn === null) { |
|
566 | + throw new \ErrorException('uncatched db error'); |
|
567 | + } |
|
537 | 568 | |
538 | 569 | $condition=null; |
539 | 570 | if ($ip != null) |
@@ -545,7 +576,9 @@ discard block |
||
545 | 576 | $condition=($condition===null)?'':$condition.' AND '; |
546 | 577 | $condition.="trap_oid='$oid'"; |
547 | 578 | } |
548 | - if($condition === null) return 0; |
|
579 | + if($condition === null) { |
|
580 | + return 0; |
|
581 | + } |
|
549 | 582 | $query=$dbConn->select() |
550 | 583 | ->from( |
551 | 584 | $this->getModuleConfig()->getTrapTableName(), |
@@ -562,7 +595,9 @@ discard block |
||
562 | 595 | { |
563 | 596 | |
564 | 597 | $dbConn = $this->getUIDatabase()->getDbConn(); |
565 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
598 | + if ($dbConn === null) { |
|
599 | + throw new \ErrorException('uncatched db error'); |
|
600 | + } |
|
566 | 601 | |
567 | 602 | $query=$dbConn->select() |
568 | 603 | ->from( |
@@ -570,18 +605,28 @@ discard block |
||
570 | 605 | array('value'=>'value')) |
571 | 606 | ->where('name=?',$element); |
572 | 607 | $return_row=$dbConn->fetchRow($query); |
573 | - if ($return_row==null) // value does not exists |
|
608 | + if ($return_row==null) { |
|
609 | + // value does not exists |
|
574 | 610 | { |
575 | 611 | $default=$this->getModuleConfig()->getDBConfigDefaults(); |
576 | - if ( ! isset($default[$element])) return null; // no default and not value |
|
612 | + } |
|
613 | + if ( ! isset($default[$element])) { |
|
614 | + return null; |
|
615 | + } |
|
616 | + // no default and not value |
|
577 | 617 | |
578 | 618 | $this->addDBConfigValue($element,$default[$element]); |
579 | 619 | return $default[$element]; |
580 | 620 | } |
581 | - if ($return_row->value == null) // value id empty |
|
621 | + if ($return_row->value == null) { |
|
622 | + // value id empty |
|
582 | 623 | { |
583 | 624 | $default=$this->getModuleConfig()->getDBConfigDefaults(); |
584 | - if ( ! isset($default[$element])) return null; // no default and not value |
|
625 | + } |
|
626 | + if ( ! isset($default[$element])) { |
|
627 | + return null; |
|
628 | + } |
|
629 | + // no default and not value |
|
585 | 630 | $this->setDBConfigValue($element,$default[$element]); |
586 | 631 | return $default[$element]; |
587 | 632 | } |
@@ -597,7 +642,9 @@ discard block |
||
597 | 642 | { |
598 | 643 | |
599 | 644 | $dbConn = $this->getUIDatabase()->getDbConn(); |
600 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
645 | + if ($dbConn === null) { |
|
646 | + throw new \ErrorException('uncatched db error'); |
|
647 | + } |
|
601 | 648 | |
602 | 649 | $query=$dbConn->insert( |
603 | 650 | $this->getModuleConfig()->getDbConfigTableName(), |
@@ -617,7 +664,9 @@ discard block |
||
617 | 664 | { |
618 | 665 | |
619 | 666 | $dbConn = $this->getUIDatabase()->getDbConn(); |
620 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
667 | + if ($dbConn === null) { |
|
668 | + throw new \ErrorException('uncatched db error'); |
|
669 | + } |
|
621 | 670 | |
622 | 671 | $query=$dbConn->update( |
623 | 672 | $this->getModuleConfig()->getDbConfigTableName(), |
@@ -31,10 +31,10 @@ discard block |
||
31 | 31 | |
32 | 32 | } |
33 | 33 | |
34 | - /** |
|
35 | - * Get all mibs in db which have at least one trap |
|
36 | - * @return array |
|
37 | - */ |
|
34 | + /** |
|
35 | + * Get all mibs in db which have at least one trap |
|
36 | + * @return array |
|
37 | + */ |
|
38 | 38 | |
39 | 39 | public function getMIBList() |
40 | 40 | { |
@@ -58,9 +58,9 @@ discard block |
||
58 | 58 | |
59 | 59 | |
60 | 60 | /** Get trap list from a mib |
61 | - * @param $mib string mib name |
|
62 | - * @return array : traps |
|
63 | - */ |
|
61 | + * @param $mib string mib name |
|
62 | + * @return array : traps |
|
63 | + */ |
|
64 | 64 | public function getTrapList($mib) |
65 | 65 | { |
66 | 66 | $traps=array(); |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | $query=$dbconn->select() |
69 | 69 | ->from( |
70 | 70 | $this->config->getMIBCacheTableName(), |
71 | - array('name' => 'name', 'oid' => 'oid', 'description' => 'description')) |
|
71 | + array('name' => 'name', 'oid' => 'oid', 'description' => 'description')) |
|
72 | 72 | ->where("mib = '".$mib."' AND type='21'") ; |
73 | 73 | $names=$dbconn->fetchAll($query); |
74 | 74 | foreach ($names as $val) |
@@ -79,9 +79,9 @@ discard block |
||
79 | 79 | } |
80 | 80 | |
81 | 81 | /** Get objects a trap can have |
82 | - * @param int $trap oid of trap |
|
83 | - * @return array|null : null if trap not found, or array ( <oid> => name/mib/type ) |
|
84 | - */ |
|
82 | + * @param int $trap oid of trap |
|
83 | + * @return array|null : null if trap not found, or array ( <oid> => name/mib/type ) |
|
84 | + */ |
|
85 | 85 | public function getObjectList($trap) |
86 | 86 | { |
87 | 87 | $objects=array(); |
@@ -97,15 +97,15 @@ discard block |
||
97 | 97 | if ( ($id == null) || ! property_exists($id,'id') ) return null; |
98 | 98 | |
99 | 99 | $query=$dbconn->select() |
100 | - ->from( |
|
101 | - array('c' => $this->config->getMIBCacheTableName()), |
|
102 | - array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum', |
|
103 | - 'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint', |
|
104 | - 'description' => 'c.description')) |
|
105 | - ->join( |
|
106 | - array('o' => $this->config->getMIBCacheTableTrapObjName()), |
|
107 | - 'o.trap_id='.$id->id ) |
|
108 | - ->where("o.object_id = c.id"); |
|
100 | + ->from( |
|
101 | + array('c' => $this->config->getMIBCacheTableName()), |
|
102 | + array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum', |
|
103 | + 'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint', |
|
104 | + 'description' => 'c.description')) |
|
105 | + ->join( |
|
106 | + array('o' => $this->config->getMIBCacheTableTrapObjName()), |
|
107 | + 'o.trap_id='.$id->id ) |
|
108 | + ->where("o.object_id = c.id"); |
|
109 | 109 | $listObjects=$dbconn->fetchAll($query); |
110 | 110 | if ( count($listObjects)==0 ) return null; |
111 | 111 | |
@@ -123,12 +123,12 @@ discard block |
||
123 | 123 | } |
124 | 124 | |
125 | 125 | /** translate oid in MIB::Name |
126 | - * @param string $oid |
|
127 | - * @return array|null : return array with index (oid -> oid, mib -> mib name, name -> oid name, type -> oid type) |
|
128 | - */ |
|
126 | + * @param string $oid |
|
127 | + * @return array|null : return array with index (oid -> oid, mib -> mib name, name -> oid name, type -> oid type) |
|
128 | + */ |
|
129 | 129 | public function translateOID($oid) |
130 | 130 | { |
131 | - if (!preg_match('/^\./',$oid)) $oid = '.' . $oid; // Add a leading '.' |
|
131 | + if (!preg_match('/^\./',$oid)) $oid = '.' . $oid; // Add a leading '.' |
|
132 | 132 | $retArray=array('oid' => $oid, 'mib' => null, 'name'=>null,'type'=>null); |
133 | 133 | $dbconn = $this->db; |
134 | 134 | |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | ->from( |
137 | 137 | array('o' => $this->config->getMIBCacheTableName()), |
138 | 138 | array('mib'=>'o.mib','name' => 'o.name','type'=>'o.syntax', |
139 | - 'type_enum'=>'o.type_enum', 'description'=>'o.description')) |
|
139 | + 'type_enum'=>'o.type_enum', 'description'=>'o.description')) |
|
140 | 140 | ->where('o.oid=\''.$oid.'\''); |
141 | 141 | $object=$dbconn->fetchRow($query); |
142 | 142 | if ($object != null) |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | // Try to get oid name from snmptranslate |
153 | 153 | $matches=array(); |
154 | 154 | $translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs. |
155 | - ' '.$oid); |
|
155 | + ' '.$oid); |
|
156 | 156 | $ret_code=preg_match('/(.*)::(.*)/',$translate,$matches); |
157 | 157 | if ($ret_code===0 || $ret_code===false) { |
158 | 158 | return null; |
@@ -164,8 +164,8 @@ discard block |
||
164 | 164 | " | grep SYNTAX | sed 's/SYNTAX[[:blank:]]*//'"); |
165 | 165 | if (preg_match('/(.*)\{(.*)\}/',$translate,$matches)) |
166 | 166 | { |
167 | - $retArray['type']=$matches[1]; |
|
168 | - $retArray['type_enum']=$matches[2]; |
|
167 | + $retArray['type']=$matches[1]; |
|
168 | + $retArray['type_enum']=$matches[2]; |
|
169 | 169 | } |
170 | 170 | else |
171 | 171 | { |
@@ -229,25 +229,25 @@ discard block |
||
229 | 229 | */ |
230 | 230 | public function getTrapDetails($oid=null,$id=null) |
231 | 231 | { |
232 | - // Get trap id in DB |
|
233 | - if ($oid===null) |
|
234 | - { |
|
235 | - $where="c.id = '$id'"; |
|
236 | - } |
|
237 | - else |
|
238 | - { |
|
239 | - $where="c.oid = '$oid'"; |
|
240 | - } |
|
241 | - $query=$this->db->select() |
|
242 | - ->from( |
|
243 | - array('c' => $this->config->getMIBCacheTableName()), |
|
244 | - array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum', |
|
245 | - 'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint', |
|
246 | - 'description' => 'c.description')) |
|
247 | - ->where($where); |
|
248 | - $trap=$this->db->fetchRow($query); |
|
232 | + // Get trap id in DB |
|
233 | + if ($oid===null) |
|
234 | + { |
|
235 | + $where="c.id = '$id'"; |
|
236 | + } |
|
237 | + else |
|
238 | + { |
|
239 | + $where="c.oid = '$oid'"; |
|
240 | + } |
|
241 | + $query=$this->db->select() |
|
242 | + ->from( |
|
243 | + array('c' => $this->config->getMIBCacheTableName()), |
|
244 | + array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum', |
|
245 | + 'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint', |
|
246 | + 'description' => 'c.description')) |
|
247 | + ->where($where); |
|
248 | + $trap=$this->db->fetchRow($query); |
|
249 | 249 | |
250 | - return $trap; |
|
250 | + return $trap; |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * @param \Zend_Db_Adapter_Abstract $db current database |
22 | 22 | * @param TrapModuleConfig $config TrapModuleConfig class instance |
23 | 23 | */ |
24 | - public function __construct($snmptranslate,$snmptranslate_dirs,$db,$config) |
|
24 | + public function __construct($snmptranslate, $snmptranslate_dirs, $db, $config) |
|
25 | 25 | { |
26 | 26 | $this->snmptranslate=$snmptranslate; |
27 | 27 | $this->snmptranslate_dirs=$snmptranslate_dirs; |
@@ -38,19 +38,19 @@ discard block |
||
38 | 38 | |
39 | 39 | public function getMIBList() |
40 | 40 | { |
41 | - $dbconn = $this->db; |
|
41 | + $dbconn=$this->db; |
|
42 | 42 | $query=$dbconn->select() |
43 | 43 | ->distinct() |
44 | 44 | ->from( |
45 | 45 | $this->config->getMIBCacheTableName(), |
46 | 46 | array('mib' => 'mib')) |
47 | 47 | ->where("type = '21'") |
48 | - ->order('mib ASC'); ; |
|
48 | + ->order('mib ASC'); ; |
|
49 | 49 | $names=$dbconn->fetchAll($query); |
50 | 50 | $mib=array(); |
51 | - foreach($names as $val) |
|
51 | + foreach ($names as $val) |
|
52 | 52 | { |
53 | - array_push($mib,$val->mib); |
|
53 | + array_push($mib, $val->mib); |
|
54 | 54 | } |
55 | 55 | return $mib; |
56 | 56 | |
@@ -64,12 +64,12 @@ discard block |
||
64 | 64 | public function getTrapList($mib) |
65 | 65 | { |
66 | 66 | $traps=array(); |
67 | - $dbconn = $this->db; |
|
67 | + $dbconn=$this->db; |
|
68 | 68 | $query=$dbconn->select() |
69 | 69 | ->from( |
70 | 70 | $this->config->getMIBCacheTableName(), |
71 | 71 | array('name' => 'name', 'oid' => 'oid', 'description' => 'description')) |
72 | - ->where("mib = '".$mib."' AND type='21'") ; |
|
72 | + ->where("mib = '".$mib."' AND type='21'"); |
|
73 | 73 | $names=$dbconn->fetchAll($query); |
74 | 74 | foreach ($names as $val) |
75 | 75 | { |
@@ -87,19 +87,19 @@ discard block |
||
87 | 87 | $objects=array(); |
88 | 88 | |
89 | 89 | // Get trap id in DB |
90 | - $dbconn = $this->db; |
|
90 | + $dbconn=$this->db; |
|
91 | 91 | $query=$dbconn->select() |
92 | 92 | ->from( |
93 | 93 | $this->config->getMIBCacheTableName(), |
94 | 94 | array('id' => 'id')) |
95 | - ->where("oid = '".$trap."'") ; |
|
95 | + ->where("oid = '".$trap."'"); |
|
96 | 96 | $id=$dbconn->fetchRow($query); |
97 | - if ( ($id == null) || ! property_exists($id,'id') ) return null; |
|
97 | + if (($id == null) || !property_exists($id, 'id')) return null; |
|
98 | 98 | |
99 | 99 | $query=$dbconn->select() |
100 | 100 | ->from( |
101 | 101 | array('c' => $this->config->getMIBCacheTableName()), |
102 | - array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum', |
|
102 | + array('name' => 'c.name', 'mib' => 'c.mib', 'oid' => 'c.oid', 'type_enum'=>'c.type_enum', |
|
103 | 103 | 'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint', |
104 | 104 | 'description' => 'c.description')) |
105 | 105 | ->join( |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | 'o.trap_id='.$id->id ) |
108 | 108 | ->where("o.object_id = c.id"); |
109 | 109 | $listObjects=$dbconn->fetchAll($query); |
110 | - if ( count($listObjects)==0 ) return null; |
|
110 | + if (count($listObjects) == 0) return null; |
|
111 | 111 | |
112 | 112 | foreach ($listObjects as $val) |
113 | 113 | { |
@@ -128,14 +128,14 @@ discard block |
||
128 | 128 | */ |
129 | 129 | public function translateOID($oid) |
130 | 130 | { |
131 | - if (!preg_match('/^\./',$oid)) $oid = '.' . $oid; // Add a leading '.' |
|
132 | - $retArray=array('oid' => $oid, 'mib' => null, 'name'=>null,'type'=>null); |
|
133 | - $dbconn = $this->db; |
|
131 | + if (!preg_match('/^\./', $oid)) $oid='.'.$oid; // Add a leading '.' |
|
132 | + $retArray=array('oid' => $oid, 'mib' => null, 'name'=>null, 'type'=>null); |
|
133 | + $dbconn=$this->db; |
|
134 | 134 | |
135 | 135 | $query=$dbconn->select() |
136 | 136 | ->from( |
137 | 137 | array('o' => $this->config->getMIBCacheTableName()), |
138 | - array('mib'=>'o.mib','name' => 'o.name','type'=>'o.syntax', |
|
138 | + array('mib'=>'o.mib', 'name' => 'o.name', 'type'=>'o.syntax', |
|
139 | 139 | 'type_enum'=>'o.type_enum', 'description'=>'o.description')) |
140 | 140 | ->where('o.oid=\''.$oid.'\''); |
141 | 141 | $object=$dbconn->fetchRow($query); |
@@ -151,18 +151,18 @@ discard block |
||
151 | 151 | |
152 | 152 | // Try to get oid name from snmptranslate |
153 | 153 | $matches=array(); |
154 | - $translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs. |
|
154 | + $translate=exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs. |
|
155 | 155 | ' '.$oid); |
156 | - $ret_code=preg_match('/(.*)::(.*)/',$translate,$matches); |
|
157 | - if ($ret_code===0 || $ret_code===false) { |
|
156 | + $ret_code=preg_match('/(.*)::(.*)/', $translate, $matches); |
|
157 | + if ($ret_code === 0 || $ret_code === false) { |
|
158 | 158 | return null; |
159 | 159 | } |
160 | 160 | $retArray['mib']=$matches[1]; |
161 | 161 | $retArray['name']=$matches[2]; |
162 | 162 | |
163 | - $translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.' -Td -On ' . $matches[0] . |
|
163 | + $translate=exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.' -Td -On '.$matches[0]. |
|
164 | 164 | " | grep SYNTAX | sed 's/SYNTAX[[:blank:]]*//'"); |
165 | - if (preg_match('/(.*)\{(.*)\}/',$translate,$matches)) |
|
165 | + if (preg_match('/(.*)\{(.*)\}/', $translate, $matches)) |
|
166 | 166 | { |
167 | 167 | $retArray['type']=$matches[1]; |
168 | 168 | $retArray['type_enum']=$matches[2]; |
@@ -197,9 +197,9 @@ discard block |
||
197 | 197 | * @param string $type filter by type (21=trap) |
198 | 198 | * @return number number of entries in db. |
199 | 199 | */ |
200 | - public function countObjects($mib=null,$type=null) |
|
200 | + public function countObjects($mib=null, $type=null) |
|
201 | 201 | { |
202 | - $dbconn = $this->db; |
|
202 | + $dbconn=$this->db; |
|
203 | 203 | $query=$dbconn->select() |
204 | 204 | ->from( |
205 | 205 | $this->config->getMIBCacheTableName(), |
@@ -207,11 +207,11 @@ discard block |
||
207 | 207 | $where=null; |
208 | 208 | if ($mib !== null) |
209 | 209 | { |
210 | - $where ="mib = '$mib' "; |
|
210 | + $where="mib = '$mib' "; |
|
211 | 211 | } |
212 | 212 | if ($type !== null) |
213 | 213 | { |
214 | - $where=($where !== null)?' AND ':''; |
|
214 | + $where=($where !== null) ? ' AND ' : ''; |
|
215 | 215 | $where.="type='$type'"; |
216 | 216 | } |
217 | 217 | if ($where !== null) |
@@ -227,10 +227,10 @@ discard block |
||
227 | 227 | * @param integer $id |
228 | 228 | * @return array trap details |
229 | 229 | */ |
230 | - public function getTrapDetails($oid=null,$id=null) |
|
230 | + public function getTrapDetails($oid=null, $id=null) |
|
231 | 231 | { |
232 | 232 | // Get trap id in DB |
233 | - if ($oid===null) |
|
233 | + if ($oid === null) |
|
234 | 234 | { |
235 | 235 | $where="c.id = '$id'"; |
236 | 236 | } |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | $query=$this->db->select() |
242 | 242 | ->from( |
243 | 243 | array('c' => $this->config->getMIBCacheTableName()), |
244 | - array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum', |
|
244 | + array('name' => 'c.name', 'mib' => 'c.mib', 'oid' => 'c.oid', 'type_enum'=>'c.type_enum', |
|
245 | 245 | 'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint', |
246 | 246 | 'description' => 'c.description')) |
247 | 247 | ->where($where); |
@@ -94,7 +94,9 @@ discard block |
||
94 | 94 | array('id' => 'id')) |
95 | 95 | ->where("oid = '".$trap."'") ; |
96 | 96 | $id=$dbconn->fetchRow($query); |
97 | - if ( ($id == null) || ! property_exists($id,'id') ) return null; |
|
97 | + if ( ($id == null) || ! property_exists($id,'id') ) { |
|
98 | + return null; |
|
99 | + } |
|
98 | 100 | |
99 | 101 | $query=$dbconn->select() |
100 | 102 | ->from( |
@@ -107,7 +109,9 @@ discard block |
||
107 | 109 | 'o.trap_id='.$id->id ) |
108 | 110 | ->where("o.object_id = c.id"); |
109 | 111 | $listObjects=$dbconn->fetchAll($query); |
110 | - if ( count($listObjects)==0 ) return null; |
|
112 | + if ( count($listObjects)==0 ) { |
|
113 | + return null; |
|
114 | + } |
|
111 | 115 | |
112 | 116 | foreach ($listObjects as $val) |
113 | 117 | { |
@@ -128,7 +132,10 @@ discard block |
||
128 | 132 | */ |
129 | 133 | public function translateOID($oid) |
130 | 134 | { |
131 | - if (!preg_match('/^\./',$oid)) $oid = '.' . $oid; // Add a leading '.' |
|
135 | + if (!preg_match('/^\./',$oid)) { |
|
136 | + $oid = '.' . $oid; |
|
137 | + } |
|
138 | + // Add a leading '.' |
|
132 | 139 | $retArray=array('oid' => $oid, 'mib' => null, 'name'=>null,'type'=>null); |
133 | 140 | $dbconn = $this->db; |
134 | 141 | |
@@ -166,8 +173,7 @@ discard block |
||
166 | 173 | { |
167 | 174 | $retArray['type']=$matches[1]; |
168 | 175 | $retArray['type_enum']=$matches[2]; |
169 | - } |
|
170 | - else |
|
176 | + } else |
|
171 | 177 | { |
172 | 178 | $retArray['type']=$translate; |
173 | 179 | $retArray['type_enum']=''; |
@@ -233,8 +239,7 @@ discard block |
||
233 | 239 | if ($oid===null) |
234 | 240 | { |
235 | 241 | $where="c.id = '$id'"; |
236 | - } |
|
237 | - else |
|
242 | + } else |
|
238 | 243 | { |
239 | 244 | $where="c.oid = '$oid'"; |
240 | 245 | } |
@@ -40,8 +40,8 @@ discard block |
||
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
43 | - * Trap detail page |
|
44 | - */ |
|
43 | + * Trap detail page |
|
44 | + */ |
|
45 | 45 | public function trapdetailAction() |
46 | 46 | { |
47 | 47 | |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | // Do DB query for trap. |
75 | 75 | try |
76 | 76 | { |
77 | - $query = $dbConn->select() |
|
77 | + $query = $dbConn->select() |
|
78 | 78 | ->from($this->moduleConfig->getTrapTableName(),$elmts) |
79 | 79 | ->where('id=?',$trapid); |
80 | 80 | $trapDetail=$dbConn->fetchRow($query); |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | } |
108 | 108 | try |
109 | 109 | { |
110 | - $query = $dbConn->select() |
|
110 | + $query = $dbConn->select() |
|
111 | 111 | ->from($this->moduleConfig->getTrapDataTableName(),$data_elmts) |
112 | 112 | ->where('trap_id=?',$trapid); |
113 | 113 | $trapDetail=$dbConn->fetchAll($query); |
@@ -144,24 +144,24 @@ discard block |
||
144 | 144 | */ |
145 | 145 | public function hostsAction() |
146 | 146 | { |
147 | - $this->checkReadPermission(); |
|
148 | - $this->prepareTabs()->activate('hosts'); |
|
147 | + $this->checkReadPermission(); |
|
148 | + $this->prepareTabs()->activate('hosts'); |
|
149 | 149 | |
150 | - $dbConn = $this->getUIDatabase()->getDb(); |
|
151 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
150 | + $dbConn = $this->getUIDatabase()->getDb(); |
|
151 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
152 | 152 | |
153 | - $this->getTrapHostListTable()->setConnection($dbConn); |
|
153 | + $this->getTrapHostListTable()->setConnection($dbConn); |
|
154 | 154 | |
155 | - // Apply pagination limits |
|
156 | - $this->view->table=$this->applyPaginationLimits($this->getTrapHostListTable(),$this->getModuleConfig()->itemListDisplay()); |
|
155 | + // Apply pagination limits |
|
156 | + $this->view->table=$this->applyPaginationLimits($this->getTrapHostListTable(),$this->getModuleConfig()->itemListDisplay()); |
|
157 | 157 | |
158 | - // Set Filter |
|
159 | - //$postData=$this->getRequest()->getPost(); |
|
160 | - $filter=array(); |
|
161 | - $filter['q']=$this->params->get('q');//(isset($postData['q']))?$postData['q']:''; |
|
162 | - $filter['done']=$this->params->get('done'); |
|
163 | - $this->view->filter=$filter; |
|
164 | - $this->view->table->updateFilter(Url::fromRequest(),$filter); |
|
158 | + // Set Filter |
|
159 | + //$postData=$this->getRequest()->getPost(); |
|
160 | + $filter=array(); |
|
161 | + $filter['q']=$this->params->get('q');//(isset($postData['q']))?$postData['q']:''; |
|
162 | + $filter['done']=$this->params->get('done'); |
|
163 | + $this->view->filter=$filter; |
|
164 | + $this->view->table->updateFilter(Url::fromRequest(),$filter); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | public function deleteAction() |
@@ -181,12 +181,12 @@ discard block |
||
181 | 181 | return $this->getTabs()->add('traps', array( |
182 | 182 | 'label' => $this->translate('Traps'), |
183 | 183 | 'url' => $this->getModuleConfig()->urlPath() . '/received') |
184 | - ) |
|
185 | - ->add('hosts', array( |
|
186 | - 'label' => $this->translate('Hosts'), |
|
187 | - 'url' => $this->getModuleConfig()->urlPath() . '/received/hosts') |
|
188 | - ) |
|
189 | - ->add('delete', array( |
|
184 | + ) |
|
185 | + ->add('hosts', array( |
|
186 | + 'label' => $this->translate('Hosts'), |
|
187 | + 'url' => $this->getModuleConfig()->urlPath() . '/received/hosts') |
|
188 | + ) |
|
189 | + ->add('delete', array( |
|
190 | 190 | 'label' => $this->translate('Delete'), |
191 | 191 | 'url' => $this->getModuleConfig()->urlPath() . '/received/delete') |
192 | 192 | ); |
@@ -20,20 +20,20 @@ discard block |
||
20 | 20 | $this->checkReadPermission(); |
21 | 21 | $this->prepareTabs()->activate('traps'); |
22 | 22 | |
23 | - $dbConn = $this->getUIDatabase()->getDb(); |
|
23 | + $dbConn=$this->getUIDatabase()->getDb(); |
|
24 | 24 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
25 | 25 | $this->getTrapListTable()->setConnection($dbConn); |
26 | 26 | |
27 | 27 | // Apply pagination limits |
28 | - $this->view->table=$this->applyPaginationLimits($this->getTrapListTable(),$this->getModuleConfig()->itemListDisplay()); |
|
28 | + $this->view->table=$this->applyPaginationLimits($this->getTrapListTable(), $this->getModuleConfig()->itemListDisplay()); |
|
29 | 29 | |
30 | 30 | // Set Filter |
31 | 31 | //$postData=$this->getRequest()->getPost(); |
32 | 32 | $filter=array(); |
33 | - $filter['q']=$this->params->get('q');//(isset($postData['q']))?$postData['q']:''; |
|
33 | + $filter['q']=$this->params->get('q'); //(isset($postData['q']))?$postData['q']:''; |
|
34 | 34 | $filter['done']=$this->params->get('done'); |
35 | 35 | $this->view->filter=$filter; |
36 | - $this->view->table->updateFilter(Url::fromRequest(),$filter); |
|
36 | + $this->view->table->updateFilter(Url::fromRequest(), $filter); |
|
37 | 37 | |
38 | 38 | //$this->view->filterEditor = $this->getTrapListTable()->getFilterEditor($this->getRequest()); |
39 | 39 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | |
48 | 48 | $this->checkReadPermission(); |
49 | 49 | // set up tab |
50 | - $this->getTabs()->add('get',array( |
|
50 | + $this->getTabs()->add('get', array( |
|
51 | 51 | 'active' => true, |
52 | 52 | 'label' => $this->translate('Detailed status'), |
53 | 53 | 'url' => Url::fromRequest() |
@@ -57,12 +57,12 @@ discard block |
||
57 | 57 | $this->view->trapid=$trapid; |
58 | 58 | $queryArray=$this->getModuleConfig()->trapDetailQuery(); |
59 | 59 | |
60 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
60 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
61 | 61 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
62 | 62 | |
63 | 63 | // URL to add a handler |
64 | 64 | $this->view->addHandlerUrl=Url::fromPath( |
65 | - $this->getModuleConfig()->urlPath() . '/handler/add', |
|
65 | + $this->getModuleConfig()->urlPath().'/handler/add', |
|
66 | 66 | array('fromid' => $trapid)); |
67 | 67 | // *************** Get main data |
68 | 68 | // extract columns and titles; |
@@ -74,28 +74,28 @@ discard block |
||
74 | 74 | // Do DB query for trap. |
75 | 75 | try |
76 | 76 | { |
77 | - $query = $dbConn->select() |
|
78 | - ->from($this->moduleConfig->getTrapTableName(),$elmts) |
|
79 | - ->where('id=?',$trapid); |
|
77 | + $query=$dbConn->select() |
|
78 | + ->from($this->moduleConfig->getTrapTableName(), $elmts) |
|
79 | + ->where('id=?', $trapid); |
|
80 | 80 | $trapDetail=$dbConn->fetchRow($query); |
81 | - if ( $trapDetail == null) throw new Exception('No traps was found with id = '.$trapid); |
|
81 | + if ($trapDetail == null) throw new Exception('No traps was found with id = '.$trapid); |
|
82 | 82 | } |
83 | 83 | catch (Exception $e) |
84 | 84 | { |
85 | - $this->displayExitError('Trap detail',$e->getMessage()); |
|
85 | + $this->displayExitError('Trap detail', $e->getMessage()); |
|
86 | 86 | return; |
87 | 87 | } |
88 | 88 | |
89 | 89 | // Store result in array (with Titles). |
90 | 90 | foreach ($queryArray as $key => $val) { |
91 | 91 | if ($key == 'timestamp') { |
92 | - $cval=strftime('%c',$trapDetail->$key); |
|
92 | + $cval=strftime('%c', $trapDetail->$key); |
|
93 | 93 | } else { |
94 | 94 | $cval=$trapDetail->$key; |
95 | 95 | } |
96 | - array_push($queryArray[$key],$cval); |
|
96 | + array_push($queryArray[$key], $cval); |
|
97 | 97 | } |
98 | - $this->view->rowset = $queryArray; |
|
98 | + $this->view->rowset=$queryArray; |
|
99 | 99 | |
100 | 100 | // ************** Check for additionnal data |
101 | 101 | |
@@ -107,17 +107,17 @@ discard block |
||
107 | 107 | } |
108 | 108 | try |
109 | 109 | { |
110 | - $query = $dbConn->select() |
|
111 | - ->from($this->moduleConfig->getTrapDataTableName(),$data_elmts) |
|
112 | - ->where('trap_id=?',$trapid); |
|
110 | + $query=$dbConn->select() |
|
111 | + ->from($this->moduleConfig->getTrapDataTableName(), $data_elmts) |
|
112 | + ->where('trap_id=?', $trapid); |
|
113 | 113 | $trapDetail=$dbConn->fetchAll($query); |
114 | 114 | } |
115 | 115 | catch (Exception $e) |
116 | 116 | { |
117 | - $this->displayExitError('Trap detail',$e->getMessage()); |
|
117 | + $this->displayExitError('Trap detail', $e->getMessage()); |
|
118 | 118 | } |
119 | 119 | // TODO : code this in a better & simpler way |
120 | - if ($trapDetail == null ) |
|
120 | + if ($trapDetail == null) |
|
121 | 121 | { |
122 | 122 | $this->view->data=false; |
123 | 123 | } |
@@ -129,9 +129,9 @@ discard block |
||
129 | 129 | foreach ($trapDetail as $key => $val) |
130 | 130 | { |
131 | 131 | $trapval[$key]=array(); |
132 | - foreach (array_keys($queryArrayData) as $vkey ) |
|
132 | + foreach (array_keys($queryArrayData) as $vkey) |
|
133 | 133 | { |
134 | - array_push($trapval[$key],$val->$vkey); |
|
134 | + array_push($trapval[$key], $val->$vkey); |
|
135 | 135 | } |
136 | 136 | } |
137 | 137 | $this->view->data_val=$trapval; |
@@ -147,21 +147,21 @@ discard block |
||
147 | 147 | $this->checkReadPermission(); |
148 | 148 | $this->prepareTabs()->activate('hosts'); |
149 | 149 | |
150 | - $dbConn = $this->getUIDatabase()->getDb(); |
|
150 | + $dbConn=$this->getUIDatabase()->getDb(); |
|
151 | 151 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
152 | 152 | |
153 | 153 | $this->getTrapHostListTable()->setConnection($dbConn); |
154 | 154 | |
155 | 155 | // Apply pagination limits |
156 | - $this->view->table=$this->applyPaginationLimits($this->getTrapHostListTable(),$this->getModuleConfig()->itemListDisplay()); |
|
156 | + $this->view->table=$this->applyPaginationLimits($this->getTrapHostListTable(), $this->getModuleConfig()->itemListDisplay()); |
|
157 | 157 | |
158 | 158 | // Set Filter |
159 | 159 | //$postData=$this->getRequest()->getPost(); |
160 | 160 | $filter=array(); |
161 | - $filter['q']=$this->params->get('q');//(isset($postData['q']))?$postData['q']:''; |
|
161 | + $filter['q']=$this->params->get('q'); //(isset($postData['q']))?$postData['q']:''; |
|
162 | 162 | $filter['done']=$this->params->get('done'); |
163 | 163 | $this->view->filter=$filter; |
164 | - $this->view->table->updateFilter(Url::fromRequest(),$filter); |
|
164 | + $this->view->table->updateFilter(Url::fromRequest(), $filter); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | public function deleteAction() |
@@ -180,15 +180,15 @@ discard block |
||
180 | 180 | { |
181 | 181 | return $this->getTabs()->add('traps', array( |
182 | 182 | 'label' => $this->translate('Traps'), |
183 | - 'url' => $this->getModuleConfig()->urlPath() . '/received') |
|
183 | + 'url' => $this->getModuleConfig()->urlPath().'/received') |
|
184 | 184 | ) |
185 | 185 | ->add('hosts', array( |
186 | 186 | 'label' => $this->translate('Hosts'), |
187 | - 'url' => $this->getModuleConfig()->urlPath() . '/received/hosts') |
|
187 | + 'url' => $this->getModuleConfig()->urlPath().'/received/hosts') |
|
188 | 188 | ) |
189 | 189 | ->add('delete', array( |
190 | 190 | 'label' => $this->translate('Delete'), |
191 | - 'url' => $this->getModuleConfig()->urlPath() . '/received/delete') |
|
191 | + 'url' => $this->getModuleConfig()->urlPath().'/received/delete') |
|
192 | 192 | ); |
193 | 193 | } |
194 | 194 | |
@@ -215,14 +215,14 @@ discard block |
||
215 | 215 | $this->_helper->json(array('status'=>'Missing variables')); |
216 | 216 | return; |
217 | 217 | } |
218 | - if ($action =="count") |
|
218 | + if ($action == "count") |
|
219 | 219 | { |
220 | - $this->_helper->json(array('status'=>'OK','count'=>$this->countTrap($ip,$oid))); |
|
220 | + $this->_helper->json(array('status'=>'OK', 'count'=>$this->countTrap($ip, $oid))); |
|
221 | 221 | return; |
222 | 222 | } |
223 | - if ($action =="delete") |
|
223 | + if ($action == "delete") |
|
224 | 224 | { |
225 | - $this->_helper->json(array('status'=>'OK','count'=>$this->deleteTrap($ip,$oid))); |
|
225 | + $this->_helper->json(array('status'=>'OK', 'count'=>$this->deleteTrap($ip, $oid))); |
|
226 | 226 | return; |
227 | 227 | } |
228 | 228 | $this->_helper->json(array('status'=>'unknown action')); |
@@ -21,7 +21,9 @@ discard block |
||
21 | 21 | $this->prepareTabs()->activate('traps'); |
22 | 22 | |
23 | 23 | $dbConn = $this->getUIDatabase()->getDb(); |
24 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
24 | + if ($dbConn === null) { |
|
25 | + throw new \ErrorException('uncatched db error'); |
|
26 | + } |
|
25 | 27 | $this->getTrapListTable()->setConnection($dbConn); |
26 | 28 | |
27 | 29 | // Apply pagination limits |
@@ -58,7 +60,9 @@ discard block |
||
58 | 60 | $queryArray=$this->getModuleConfig()->trapDetailQuery(); |
59 | 61 | |
60 | 62 | $dbConn = $this->getUIDatabase()->getDbConn(); |
61 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
63 | + if ($dbConn === null) { |
|
64 | + throw new \ErrorException('uncatched db error'); |
|
65 | + } |
|
62 | 66 | |
63 | 67 | // URL to add a handler |
64 | 68 | $this->view->addHandlerUrl=Url::fromPath( |
@@ -78,9 +82,10 @@ discard block |
||
78 | 82 | ->from($this->moduleConfig->getTrapTableName(),$elmts) |
79 | 83 | ->where('id=?',$trapid); |
80 | 84 | $trapDetail=$dbConn->fetchRow($query); |
81 | - if ( $trapDetail == null) throw new Exception('No traps was found with id = '.$trapid); |
|
82 | - } |
|
83 | - catch (Exception $e) |
|
85 | + if ( $trapDetail == null) { |
|
86 | + throw new Exception('No traps was found with id = '.$trapid); |
|
87 | + } |
|
88 | + } catch (Exception $e) |
|
84 | 89 | { |
85 | 90 | $this->displayExitError('Trap detail',$e->getMessage()); |
86 | 91 | return; |
@@ -111,8 +116,7 @@ discard block |
||
111 | 116 | ->from($this->moduleConfig->getTrapDataTableName(),$data_elmts) |
112 | 117 | ->where('trap_id=?',$trapid); |
113 | 118 | $trapDetail=$dbConn->fetchAll($query); |
114 | - } |
|
115 | - catch (Exception $e) |
|
119 | + } catch (Exception $e) |
|
116 | 120 | { |
117 | 121 | $this->displayExitError('Trap detail',$e->getMessage()); |
118 | 122 | } |
@@ -120,8 +124,7 @@ discard block |
||
120 | 124 | if ($trapDetail == null ) |
121 | 125 | { |
122 | 126 | $this->view->data=false; |
123 | - } |
|
124 | - else |
|
127 | + } else |
|
125 | 128 | { |
126 | 129 | $this->view->data=true; |
127 | 130 | // Store result in array. |
@@ -148,7 +151,9 @@ discard block |
||
148 | 151 | $this->prepareTabs()->activate('hosts'); |
149 | 152 | |
150 | 153 | $dbConn = $this->getUIDatabase()->getDb(); |
151 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
154 | + if ($dbConn === null) { |
|
155 | + throw new \ErrorException('uncatched db error'); |
|
156 | + } |
|
152 | 157 | |
153 | 158 | $this->getTrapHostListTable()->setConnection($dbConn); |
154 | 159 | |
@@ -209,8 +214,7 @@ discard block |
||
209 | 214 | $ip=$postData['IP']; |
210 | 215 | $oid=$postData['OID']; |
211 | 216 | $action=$postData['action']; |
212 | - } |
|
213 | - else |
|
217 | + } else |
|
214 | 218 | { |
215 | 219 | $this->_helper->json(array('status'=>'Missing variables')); |
216 | 220 | return; |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | /************ Trapdb ***********/ |
22 | 22 | try |
23 | 23 | { |
24 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
25 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
24 | + $dbConn = $this->getUIDatabase()->getDbConn(); |
|
25 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
26 | 26 | $query = $dbConn->select()->from( |
27 | 27 | $this->getModuleConfig()->getTrapTableName(), |
28 | 28 | array('COUNT(*)') |
@@ -65,10 +65,10 @@ discard block |
||
65 | 65 | } |
66 | 66 | |
67 | 67 | /** Mib management |
68 | - * Post param : action=update_mib_db : update mib database |
|
69 | - * Post param : ation=check_update : check if mib update is finished |
|
70 | - * File post : mibfile -> save mib file |
|
71 | - */ |
|
68 | + * Post param : action=update_mib_db : update mib database |
|
69 | + * Post param : ation=check_update : check if mib update is finished |
|
70 | + * File post : mibfile -> save mib file |
|
71 | + */ |
|
72 | 72 | public function mibAction() |
73 | 73 | { |
74 | 74 | $this->prepareTabs()->activate('mib'); |
@@ -87,22 +87,22 @@ discard block |
||
87 | 87 | $return=exec('icingacli trapdirector mib update --pid /tmp/trapdirector_update.pid'); |
88 | 88 | if (preg_match('/OK/',$return)) |
89 | 89 | { |
90 | - $this->_helper->json(array('status'=>'OK')); |
|
90 | + $this->_helper->json(array('status'=>'OK')); |
|
91 | 91 | } |
92 | 92 | // Error |
93 | 93 | $this->_helper->json(array('status'=>$return)); |
94 | 94 | } |
95 | 95 | if ($action == 'check_update') |
96 | 96 | { |
97 | - $file=@fopen('/tmp/trapdirector_update.pid','r'); |
|
98 | - if ($file == false) |
|
99 | - { // process is dead |
|
100 | - $this->_helper->json(array('status'=>'tu quoque fili','err'=>'Cannot open file')); |
|
101 | - return; |
|
102 | - } |
|
103 | - $pid=fgets($file); |
|
104 | - $output=array(); |
|
105 | - $retVal=0; |
|
97 | + $file=@fopen('/tmp/trapdirector_update.pid','r'); |
|
98 | + if ($file == false) |
|
99 | + { // process is dead |
|
100 | + $this->_helper->json(array('status'=>'tu quoque fili','err'=>'Cannot open file')); |
|
101 | + return; |
|
102 | + } |
|
103 | + $pid=fgets($file); |
|
104 | + $output=array(); |
|
105 | + $retVal=0; |
|
106 | 106 | exec('ps '.$pid,$output,$retVal); |
107 | 107 | if ($retVal == 0) |
108 | 108 | { // process is alive |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | } |
111 | 111 | else |
112 | 112 | { // process is dead |
113 | - $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid)); |
|
113 | + $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid)); |
|
114 | 114 | } |
115 | 115 | } |
116 | 116 | $this->_helper->json(array('status'=>'ERR : no '.$action.' action possible' )); |
@@ -118,32 +118,32 @@ discard block |
||
118 | 118 | /** Check for mib file UPLOAD */ |
119 | 119 | if (isset($_FILES['mibfile'])) |
120 | 120 | { |
121 | - $name=filter_var($_FILES['mibfile']['name'],FILTER_SANITIZE_STRING); |
|
121 | + $name=filter_var($_FILES['mibfile']['name'],FILTER_SANITIZE_STRING); |
|
122 | 122 | $DirConf=explode(':',$this->Config()->get('config', 'snmptranslate_dirs')); |
123 | 123 | $destDir=array_shift($DirConf); |
124 | 124 | if (!is_dir($destDir)) |
125 | 125 | { |
126 | - $this->view->uploadStatus="ERROR : no $destDir directory, check module configuration"; |
|
126 | + $this->view->uploadStatus="ERROR : no $destDir directory, check module configuration"; |
|
127 | 127 | } |
128 | 128 | else |
129 | 129 | { |
130 | - if (!is_writable($destDir)) |
|
131 | - { |
|
132 | - $this->view->uploadStatus="ERROR : $destDir directory is not writable"; |
|
133 | - } |
|
134 | - else |
|
135 | - { |
|
136 | - $destination = $destDir .'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name"; |
|
137 | - $sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'],FILTER_SANITIZE_STRING); |
|
138 | - if (move_uploaded_file($sourceTmpNam,$destination)===false) |
|
139 | - { |
|
140 | - $this->view->uploadStatus="ERROR, file $destination not loaded. Check file and path name or selinux violations"; |
|
141 | - } |
|
142 | - else |
|
143 | - { |
|
144 | - $this->view->uploadStatus="File $name uploaded in $destDir"; |
|
145 | - } |
|
146 | - } |
|
130 | + if (!is_writable($destDir)) |
|
131 | + { |
|
132 | + $this->view->uploadStatus="ERROR : $destDir directory is not writable"; |
|
133 | + } |
|
134 | + else |
|
135 | + { |
|
136 | + $destination = $destDir .'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name"; |
|
137 | + $sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'],FILTER_SANITIZE_STRING); |
|
138 | + if (move_uploaded_file($sourceTmpNam,$destination)===false) |
|
139 | + { |
|
140 | + $this->view->uploadStatus="ERROR, file $destination not loaded. Check file and path name or selinux violations"; |
|
141 | + } |
|
142 | + else |
|
143 | + { |
|
144 | + $this->view->uploadStatus="File $name uploaded in $destDir"; |
|
145 | + } |
|
146 | + } |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | } |
@@ -263,47 +263,47 @@ discard block |
||
263 | 263 | */ |
264 | 264 | public function pluginsAction() |
265 | 265 | { |
266 | - $this->prepareTabs()->activate('plugins'); |
|
266 | + $this->prepareTabs()->activate('plugins'); |
|
267 | 267 | |
268 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
269 | - $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
270 | - $Trap = new Trap($icingaweb2_etc,4); |
|
268 | + require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
269 | + $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
270 | + $Trap = new Trap($icingaweb2_etc,4); |
|
271 | 271 | |
272 | - $this->view->pluginLoaded = htmlentities($Trap->pluginClass->registerAllPlugins(false)); |
|
272 | + $this->view->pluginLoaded = htmlentities($Trap->pluginClass->registerAllPlugins(false)); |
|
273 | 273 | |
274 | - $enabledPlugins = $Trap->pluginClass->getEnabledPlugins(); |
|
274 | + $enabledPlugins = $Trap->pluginClass->getEnabledPlugins(); |
|
275 | 275 | |
276 | - $pluginList = $Trap->pluginClass->pluginList(); |
|
276 | + $pluginList = $Trap->pluginClass->pluginList(); |
|
277 | 277 | |
278 | - // Plugin list and fill function name list |
|
279 | - $functionList=array(); |
|
280 | - $this->view->pluginArray=array(); |
|
281 | - foreach ($pluginList as $plugin) |
|
282 | - { |
|
283 | - $pluginDetails=$Trap->pluginClass->pluginDetails($plugin); |
|
284 | - $pluginDetails->enabled = (in_array($plugin, $enabledPlugins)) ? true : false; |
|
285 | - $pluginDetails->catchAllTraps = ($pluginDetails->catchAllTraps === true )? 'Yes' : 'No'; |
|
286 | - $pluginDetails->processTraps = ($pluginDetails->processTraps === true )? 'Yes' : 'No'; |
|
287 | - $pluginDetails->description = htmlentities($pluginDetails->description); |
|
288 | - $pluginDetails->description = preg_replace('/\n/','<br>',$pluginDetails->description); |
|
289 | - array_push($this->view->pluginArray, $pluginDetails); |
|
290 | - // Get functions for function details |
|
291 | - foreach ($pluginDetails->funcArray as $function) |
|
292 | - { |
|
293 | - array_push($functionList,$function); |
|
294 | - } |
|
295 | - } |
|
278 | + // Plugin list and fill function name list |
|
279 | + $functionList=array(); |
|
280 | + $this->view->pluginArray=array(); |
|
281 | + foreach ($pluginList as $plugin) |
|
282 | + { |
|
283 | + $pluginDetails=$Trap->pluginClass->pluginDetails($plugin); |
|
284 | + $pluginDetails->enabled = (in_array($plugin, $enabledPlugins)) ? true : false; |
|
285 | + $pluginDetails->catchAllTraps = ($pluginDetails->catchAllTraps === true )? 'Yes' : 'No'; |
|
286 | + $pluginDetails->processTraps = ($pluginDetails->processTraps === true )? 'Yes' : 'No'; |
|
287 | + $pluginDetails->description = htmlentities($pluginDetails->description); |
|
288 | + $pluginDetails->description = preg_replace('/\n/','<br>',$pluginDetails->description); |
|
289 | + array_push($this->view->pluginArray, $pluginDetails); |
|
290 | + // Get functions for function details |
|
291 | + foreach ($pluginDetails->funcArray as $function) |
|
292 | + { |
|
293 | + array_push($functionList,$function); |
|
294 | + } |
|
295 | + } |
|
296 | 296 | |
297 | - // Function list with details |
|
298 | - $this->view->functionList=array(); |
|
299 | - foreach ($functionList as $function) |
|
300 | - { |
|
301 | - $functionDetail = $Trap->pluginClass->getFunctionDetails($function); |
|
302 | - $functionDetail->params = htmlentities($functionDetail->params); |
|
303 | - $functionDetail->description = htmlentities($functionDetail->description); |
|
304 | - $functionDetail->description = preg_replace('/\n/','<br>',$functionDetail->description); |
|
305 | - array_push($this->view->functionList, $functionDetail); |
|
306 | - } |
|
297 | + // Function list with details |
|
298 | + $this->view->functionList=array(); |
|
299 | + foreach ($functionList as $function) |
|
300 | + { |
|
301 | + $functionDetail = $Trap->pluginClass->getFunctionDetails($function); |
|
302 | + $functionDetail->params = htmlentities($functionDetail->params); |
|
303 | + $functionDetail->description = htmlentities($functionDetail->description); |
|
304 | + $functionDetail->description = preg_replace('/\n/','<br>',$functionDetail->description); |
|
305 | + array_push($this->view->functionList, $functionDetail); |
|
306 | + } |
|
307 | 307 | |
308 | 308 | } |
309 | 309 | |
@@ -318,30 +318,30 @@ discard block |
||
318 | 318 | )->add('services', array( |
319 | 319 | 'label' => $this->translate('Services management'), |
320 | 320 | 'url' => $this->getModuleConfig()->urlPath() . '/status/services') |
321 | - )->add('plugins', array( |
|
322 | - 'label' => $this->translate('Plugins management'), |
|
323 | - 'url' => $this->getModuleConfig()->urlPath() . '/status/plugins') |
|
324 | - ); |
|
321 | + )->add('plugins', array( |
|
322 | + 'label' => $this->translate('Plugins management'), |
|
323 | + 'url' => $this->getModuleConfig()->urlPath() . '/status/plugins') |
|
324 | + ); |
|
325 | 325 | } |
326 | 326 | } |
327 | 327 | |
328 | 328 | // TODO : see if useless |
329 | 329 | class UploadForm extends Form |
330 | 330 | { |
331 | - public function __construct($options = null) |
|
332 | - { |
|
333 | - parent::__construct($options); |
|
334 | - $this->addElements2(); |
|
335 | - } |
|
331 | + public function __construct($options = null) |
|
332 | + { |
|
333 | + parent::__construct($options); |
|
334 | + $this->addElements2(); |
|
335 | + } |
|
336 | 336 | |
337 | - public function addElements2() |
|
338 | - { |
|
339 | - // File Input |
|
340 | - $file = new File('mib-file'); |
|
341 | - $file->setLabel('Mib upload'); |
|
342 | - //->setAttrib('multiple', null); |
|
343 | - $this->addElement($file); |
|
337 | + public function addElements2() |
|
338 | + { |
|
339 | + // File Input |
|
340 | + $file = new File('mib-file'); |
|
341 | + $file->setLabel('Mib upload'); |
|
342 | + //->setAttrib('multiple', null); |
|
343 | + $this->addElement($file); |
|
344 | 344 | $button = new Submit("upload",array('ignore'=>false)); |
345 | 345 | $this->addElement($button);//->setIgnore(false); |
346 | - } |
|
346 | + } |
|
347 | 347 | } |
@@ -21,19 +21,19 @@ discard block |
||
21 | 21 | /************ Trapdb ***********/ |
22 | 22 | try |
23 | 23 | { |
24 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
24 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
25 | 25 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
26 | - $query = $dbConn->select()->from( |
|
26 | + $query=$dbConn->select()->from( |
|
27 | 27 | $this->getModuleConfig()->getTrapTableName(), |
28 | 28 | array('COUNT(*)') |
29 | 29 | ); |
30 | 30 | $this->view->trap_count=$dbConn->fetchOne($query); |
31 | - $query = $dbConn->select()->from( |
|
31 | + $query=$dbConn->select()->from( |
|
32 | 32 | $this->getModuleConfig()->getTrapDataTableName(), |
33 | 33 | array('COUNT(*)') |
34 | 34 | ); |
35 | 35 | $this->view->trap_object_count=$dbConn->fetchOne($query); |
36 | - $query = $dbConn->select()->from( |
|
36 | + $query=$dbConn->select()->from( |
|
37 | 37 | $this->getModuleConfig()->getTrapRuleName(), |
38 | 38 | array('COUNT(*)') |
39 | 39 | ); |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | } |
45 | 45 | catch (Exception $e) |
46 | 46 | { |
47 | - $this->displayExitError('status',$e->getMessage()); |
|
47 | + $this->displayExitError('status', $e->getMessage()); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /*************** Log destination *******************/ |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | } |
60 | 60 | catch (Exception $e) |
61 | 61 | { |
62 | - $this->displayExitError('status',$e->getMessage()); |
|
62 | + $this->displayExitError('status', $e->getMessage()); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | if ($action == 'update_mib_db') |
86 | 86 | { // Do the update in background |
87 | 87 | $return=exec('icingacli trapdirector mib update --pid /tmp/trapdirector_update.pid'); |
88 | - if (preg_match('/OK/',$return)) |
|
88 | + if (preg_match('/OK/', $return)) |
|
89 | 89 | { |
90 | 90 | $this->_helper->json(array('status'=>'OK')); |
91 | 91 | } |
@@ -94,32 +94,32 @@ discard block |
||
94 | 94 | } |
95 | 95 | if ($action == 'check_update') |
96 | 96 | { |
97 | - $file=@fopen('/tmp/trapdirector_update.pid','r'); |
|
97 | + $file=@fopen('/tmp/trapdirector_update.pid', 'r'); |
|
98 | 98 | if ($file == false) |
99 | 99 | { // process is dead |
100 | - $this->_helper->json(array('status'=>'tu quoque fili','err'=>'Cannot open file')); |
|
100 | + $this->_helper->json(array('status'=>'tu quoque fili', 'err'=>'Cannot open file')); |
|
101 | 101 | return; |
102 | 102 | } |
103 | 103 | $pid=fgets($file); |
104 | 104 | $output=array(); |
105 | 105 | $retVal=0; |
106 | - exec('ps '.$pid,$output,$retVal); |
|
106 | + exec('ps '.$pid, $output, $retVal); |
|
107 | 107 | if ($retVal == 0) |
108 | 108 | { // process is alive |
109 | 109 | $this->_helper->json(array('status'=>'Alive and kicking')); |
110 | 110 | } |
111 | 111 | else |
112 | 112 | { // process is dead |
113 | - $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid)); |
|
113 | + $this->_helper->json(array('status'=>'tu quoque fili', 'err'=>'no proc'.$pid)); |
|
114 | 114 | } |
115 | 115 | } |
116 | - $this->_helper->json(array('status'=>'ERR : no '.$action.' action possible' )); |
|
116 | + $this->_helper->json(array('status'=>'ERR : no '.$action.' action possible')); |
|
117 | 117 | } |
118 | 118 | /** Check for mib file UPLOAD */ |
119 | 119 | if (isset($_FILES['mibfile'])) |
120 | 120 | { |
121 | - $name=filter_var($_FILES['mibfile']['name'],FILTER_SANITIZE_STRING); |
|
122 | - $DirConf=explode(':',$this->Config()->get('config', 'snmptranslate_dirs')); |
|
121 | + $name=filter_var($_FILES['mibfile']['name'], FILTER_SANITIZE_STRING); |
|
122 | + $DirConf=explode(':', $this->Config()->get('config', 'snmptranslate_dirs')); |
|
123 | 123 | $destDir=array_shift($DirConf); |
124 | 124 | if (!is_dir($destDir)) |
125 | 125 | { |
@@ -133,9 +133,9 @@ discard block |
||
133 | 133 | } |
134 | 134 | else |
135 | 135 | { |
136 | - $destination = $destDir .'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name"; |
|
137 | - $sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'],FILTER_SANITIZE_STRING); |
|
138 | - if (move_uploaded_file($sourceTmpNam,$destination)===false) |
|
136 | + $destination=$destDir.'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name"; |
|
137 | + $sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'], FILTER_SANITIZE_STRING); |
|
138 | + if (move_uploaded_file($sourceTmpNam, $destination) === false) |
|
139 | 139 | { |
140 | 140 | $this->view->uploadStatus="ERROR, file $destination not loaded. Check file and path name or selinux violations"; |
141 | 141 | } |
@@ -151,13 +151,13 @@ discard block |
||
151 | 151 | } |
152 | 152 | |
153 | 153 | // snmptranslate tests |
154 | - $snmptranslate = $this->Config()->get('config', 'snmptranslate'); |
|
154 | + $snmptranslate=$this->Config()->get('config', 'snmptranslate'); |
|
155 | 155 | $this->view->snmptranslate_bin=$snmptranslate; |
156 | 156 | $this->view->snmptranslate_state='warn'; |
157 | - if (is_executable ( $snmptranslate )) |
|
157 | + if (is_executable($snmptranslate)) |
|
158 | 158 | { |
159 | - $translate=exec($snmptranslate . ' 1'); |
|
160 | - if (preg_match('/iso/',$translate)) |
|
159 | + $translate=exec($snmptranslate.' 1'); |
|
160 | + if (preg_match('/iso/', $translate)) |
|
161 | 161 | { |
162 | 162 | $this->view->snmptranslate='works fine'; |
163 | 163 | $this->view->snmptranslate_state='ok'; |
@@ -175,46 +175,46 @@ discard block |
||
175 | 175 | // mib database |
176 | 176 | |
177 | 177 | $this->view->mibDbCount=$this->getMIB()->countObjects(); |
178 | - $this->view->mibDbCountTrap=$this->getMIB()->countObjects(null,21); |
|
178 | + $this->view->mibDbCountTrap=$this->getMIB()->countObjects(null, 21); |
|
179 | 179 | |
180 | 180 | // mib dirs |
181 | 181 | $DirConf=$this->Config()->get('config', 'snmptranslate_dirs'); |
182 | - $dirArray=explode(':',$DirConf); |
|
182 | + $dirArray=explode(':', $DirConf); |
|
183 | 183 | |
184 | 184 | // Get base directories from net-snmp-config |
185 | 185 | $output=$matches=array(); |
186 | 186 | $retVal=0; |
187 | - $sysDirs=exec('net-snmp-config --default-mibdirs',$output,$retVal); |
|
188 | - if ($retVal==0) |
|
187 | + $sysDirs=exec('net-snmp-config --default-mibdirs', $output, $retVal); |
|
188 | + if ($retVal == 0) |
|
189 | 189 | { |
190 | - $dirArray=array_merge($dirArray,explode(':',$sysDirs)); |
|
190 | + $dirArray=array_merge($dirArray, explode(':', $sysDirs)); |
|
191 | 191 | } |
192 | 192 | else |
193 | 193 | { |
194 | - $translateOut=exec($this->Config()->get('config', 'snmptranslate') . ' -Dinit_mib .1.3 2>&1 | grep MIBDIRS'); |
|
195 | - if (preg_match('/MIBDIRS.*\'([^\']+)\'/',$translateOut,$matches)) |
|
194 | + $translateOut=exec($this->Config()->get('config', 'snmptranslate').' -Dinit_mib .1.3 2>&1 | grep MIBDIRS'); |
|
195 | + if (preg_match('/MIBDIRS.*\'([^\']+)\'/', $translateOut, $matches)) |
|
196 | 196 | { |
197 | - $dirArray=array_merge($dirArray,explode(':',$matches[1])); |
|
197 | + $dirArray=array_merge($dirArray, explode(':', $matches[1])); |
|
198 | 198 | } |
199 | 199 | else |
200 | 200 | { |
201 | - array_push($dirArray,'Install net-snmp-config to see system directories'); |
|
201 | + array_push($dirArray, 'Install net-snmp-config to see system directories'); |
|
202 | 202 | } |
203 | 203 | } |
204 | 204 | |
205 | 205 | $this->view->dirArray=$dirArray; |
206 | 206 | |
207 | 207 | $output=null; |
208 | - foreach (explode(':',$DirConf) as $mibdir) |
|
208 | + foreach (explode(':', $DirConf) as $mibdir) |
|
209 | 209 | { |
210 | - exec('ls '.$mibdir.' | grep -v traplist.txt',$output); |
|
210 | + exec('ls '.$mibdir.' | grep -v traplist.txt', $output); |
|
211 | 211 | } |
212 | 212 | //$i=0;$listFiles='';while (isset($output[$i])) $listFiles.=$output[$i++]; |
213 | 213 | //$this->view->fileList=explode(' ',$listFiles); |
214 | 214 | $this->view->fileList=$output; |
215 | 215 | |
216 | 216 | // Zend form |
217 | - $this->view->form= new UploadForm(); |
|
217 | + $this->view->form=new UploadForm(); |
|
218 | 218 | //$this->view->form= new Form('upload-form'); |
219 | 219 | |
220 | 220 | |
@@ -238,18 +238,18 @@ discard block |
||
238 | 238 | $this->view->templateForm_output=''; |
239 | 239 | if (isset($postData['template_name']) && isset($postData['template_revert_time'])) |
240 | 240 | { |
241 | - $template_create = 'icingacli director service create --json \'{ "check_command": "dummy", '; |
|
242 | - $template_create .= '"check_interval": "' .$postData['template_revert_time']. '", "check_timeout": "20", "disabled": false, "enable_active_checks": true, "enable_event_handler": true, "enable_notifications": true, "enable_passive_checks": true, "enable_perfdata": true, "max_check_attempts": "1", '; |
|
243 | - $template_create .= '"object_name": "'.$postData['template_name'].'", "object_type": "template", "retry_interval": "'.$postData['template_revert_time'].'"}\''; |
|
241 | + $template_create='icingacli director service create --json \'{ "check_command": "dummy", '; |
|
242 | + $template_create.='"check_interval": "'.$postData['template_revert_time'].'", "check_timeout": "20", "disabled": false, "enable_active_checks": true, "enable_event_handler": true, "enable_notifications": true, "enable_passive_checks": true, "enable_perfdata": true, "max_check_attempts": "1", '; |
|
243 | + $template_create.='"object_name": "'.$postData['template_name'].'", "object_type": "template", "retry_interval": "'.$postData['template_revert_time'].'"}\''; |
|
244 | 244 | $output=array(); |
245 | 245 | $ret_code=0; |
246 | - exec($template_create,$output,$ret_code); |
|
246 | + exec($template_create, $output, $ret_code); |
|
247 | 247 | if ($ret_code != 0) |
248 | 248 | { |
249 | - $this->displayExitError("Status -> Services","Error creating template : ".$output[0].'<br>Command was : '.$template_create); |
|
249 | + $this->displayExitError("Status -> Services", "Error creating template : ".$output[0].'<br>Command was : '.$template_create); |
|
250 | 250 | } |
251 | - exec('icingacli director config deploy',$output,$ret_code); |
|
252 | - $this->view->templateForm_output='Template '.$postData['template_name']. ' created'; |
|
251 | + exec('icingacli director config deploy', $output, $ret_code); |
|
252 | + $this->view->templateForm_output='Template '.$postData['template_name'].' created'; |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | // template creation form |
@@ -265,15 +265,15 @@ discard block |
||
265 | 265 | { |
266 | 266 | $this->prepareTabs()->activate('plugins'); |
267 | 267 | |
268 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
268 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
269 | 269 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
270 | - $Trap = new Trap($icingaweb2_etc,4); |
|
270 | + $Trap=new Trap($icingaweb2_etc, 4); |
|
271 | 271 | |
272 | - $this->view->pluginLoaded = htmlentities($Trap->pluginClass->registerAllPlugins(false)); |
|
272 | + $this->view->pluginLoaded=htmlentities($Trap->pluginClass->registerAllPlugins(false)); |
|
273 | 273 | |
274 | - $enabledPlugins = $Trap->pluginClass->getEnabledPlugins(); |
|
274 | + $enabledPlugins=$Trap->pluginClass->getEnabledPlugins(); |
|
275 | 275 | |
276 | - $pluginList = $Trap->pluginClass->pluginList(); |
|
276 | + $pluginList=$Trap->pluginClass->pluginList(); |
|
277 | 277 | |
278 | 278 | // Plugin list and fill function name list |
279 | 279 | $functionList=array(); |
@@ -281,16 +281,16 @@ discard block |
||
281 | 281 | foreach ($pluginList as $plugin) |
282 | 282 | { |
283 | 283 | $pluginDetails=$Trap->pluginClass->pluginDetails($plugin); |
284 | - $pluginDetails->enabled = (in_array($plugin, $enabledPlugins)) ? true : false; |
|
285 | - $pluginDetails->catchAllTraps = ($pluginDetails->catchAllTraps === true )? 'Yes' : 'No'; |
|
286 | - $pluginDetails->processTraps = ($pluginDetails->processTraps === true )? 'Yes' : 'No'; |
|
287 | - $pluginDetails->description = htmlentities($pluginDetails->description); |
|
288 | - $pluginDetails->description = preg_replace('/\n/','<br>',$pluginDetails->description); |
|
284 | + $pluginDetails->enabled=(in_array($plugin, $enabledPlugins)) ? true : false; |
|
285 | + $pluginDetails->catchAllTraps=($pluginDetails->catchAllTraps === true) ? 'Yes' : 'No'; |
|
286 | + $pluginDetails->processTraps=($pluginDetails->processTraps === true) ? 'Yes' : 'No'; |
|
287 | + $pluginDetails->description=htmlentities($pluginDetails->description); |
|
288 | + $pluginDetails->description=preg_replace('/\n/', '<br>', $pluginDetails->description); |
|
289 | 289 | array_push($this->view->pluginArray, $pluginDetails); |
290 | 290 | // Get functions for function details |
291 | 291 | foreach ($pluginDetails->funcArray as $function) |
292 | 292 | { |
293 | - array_push($functionList,$function); |
|
293 | + array_push($functionList, $function); |
|
294 | 294 | } |
295 | 295 | } |
296 | 296 | |
@@ -298,10 +298,10 @@ discard block |
||
298 | 298 | $this->view->functionList=array(); |
299 | 299 | foreach ($functionList as $function) |
300 | 300 | { |
301 | - $functionDetail = $Trap->pluginClass->getFunctionDetails($function); |
|
302 | - $functionDetail->params = htmlentities($functionDetail->params); |
|
303 | - $functionDetail->description = htmlentities($functionDetail->description); |
|
304 | - $functionDetail->description = preg_replace('/\n/','<br>',$functionDetail->description); |
|
301 | + $functionDetail=$Trap->pluginClass->getFunctionDetails($function); |
|
302 | + $functionDetail->params=htmlentities($functionDetail->params); |
|
303 | + $functionDetail->description=htmlentities($functionDetail->description); |
|
304 | + $functionDetail->description=preg_replace('/\n/', '<br>', $functionDetail->description); |
|
305 | 305 | array_push($this->view->functionList, $functionDetail); |
306 | 306 | } |
307 | 307 | |
@@ -311,16 +311,16 @@ discard block |
||
311 | 311 | { |
312 | 312 | return $this->getTabs()->add('status', array( |
313 | 313 | 'label' => $this->translate('Status'), |
314 | - 'url' => $this->getModuleConfig()->urlPath() . '/status') |
|
314 | + 'url' => $this->getModuleConfig()->urlPath().'/status') |
|
315 | 315 | )->add('mib', array( |
316 | 316 | 'label' => $this->translate('MIB Management'), |
317 | - 'url' => $this->getModuleConfig()->urlPath() . '/status/mib') |
|
317 | + 'url' => $this->getModuleConfig()->urlPath().'/status/mib') |
|
318 | 318 | )->add('services', array( |
319 | 319 | 'label' => $this->translate('Services management'), |
320 | - 'url' => $this->getModuleConfig()->urlPath() . '/status/services') |
|
320 | + 'url' => $this->getModuleConfig()->urlPath().'/status/services') |
|
321 | 321 | )->add('plugins', array( |
322 | 322 | 'label' => $this->translate('Plugins management'), |
323 | - 'url' => $this->getModuleConfig()->urlPath() . '/status/plugins') |
|
323 | + 'url' => $this->getModuleConfig()->urlPath().'/status/plugins') |
|
324 | 324 | ); |
325 | 325 | } |
326 | 326 | } |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | // TODO : see if useless |
329 | 329 | class UploadForm extends Form |
330 | 330 | { |
331 | - public function __construct($options = null) |
|
331 | + public function __construct($options=null) |
|
332 | 332 | { |
333 | 333 | parent::__construct($options); |
334 | 334 | $this->addElements2(); |
@@ -337,11 +337,11 @@ discard block |
||
337 | 337 | public function addElements2() |
338 | 338 | { |
339 | 339 | // File Input |
340 | - $file = new File('mib-file'); |
|
340 | + $file=new File('mib-file'); |
|
341 | 341 | $file->setLabel('Mib upload'); |
342 | 342 | //->setAttrib('multiple', null); |
343 | 343 | $this->addElement($file); |
344 | - $button = new Submit("upload",array('ignore'=>false)); |
|
345 | - $this->addElement($button);//->setIgnore(false); |
|
344 | + $button=new Submit("upload", array('ignore'=>false)); |
|
345 | + $this->addElement($button); //->setIgnore(false); |
|
346 | 346 | } |
347 | 347 | } |
@@ -22,7 +22,9 @@ discard block |
||
22 | 22 | try |
23 | 23 | { |
24 | 24 | $dbConn = $this->getUIDatabase()->getDbConn(); |
25 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
25 | + if ($dbConn === null) { |
|
26 | + throw new \ErrorException('uncatched db error'); |
|
27 | + } |
|
26 | 28 | $query = $dbConn->select()->from( |
27 | 29 | $this->getModuleConfig()->getTrapTableName(), |
28 | 30 | array('COUNT(*)') |
@@ -41,8 +43,7 @@ discard block |
||
41 | 43 | |
42 | 44 | $this->view->trap_days_delete=$this->getDBConfigValue('db_remove_days'); |
43 | 45 | |
44 | - } |
|
45 | - catch (Exception $e) |
|
46 | + } catch (Exception $e) |
|
46 | 47 | { |
47 | 48 | $this->displayExitError('status',$e->getMessage()); |
48 | 49 | } |
@@ -56,8 +57,7 @@ discard block |
||
56 | 57 | $this->view->currentLogFile=$this->getDBConfigValue('log_file'); |
57 | 58 | $this->view->logLevels=$this->getModuleConfig()->getlogLevels(); |
58 | 59 | $this->view->currentLogLevel=$this->getDBConfigValue('log_level'); |
59 | - } |
|
60 | - catch (Exception $e) |
|
60 | + } catch (Exception $e) |
|
61 | 61 | { |
62 | 62 | $this->displayExitError('status',$e->getMessage()); |
63 | 63 | } |
@@ -107,8 +107,7 @@ discard block |
||
107 | 107 | if ($retVal == 0) |
108 | 108 | { // process is alive |
109 | 109 | $this->_helper->json(array('status'=>'Alive and kicking')); |
110 | - } |
|
111 | - else |
|
110 | + } else |
|
112 | 111 | { // process is dead |
113 | 112 | $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid)); |
114 | 113 | } |
@@ -124,22 +123,19 @@ discard block |
||
124 | 123 | if (!is_dir($destDir)) |
125 | 124 | { |
126 | 125 | $this->view->uploadStatus="ERROR : no $destDir directory, check module configuration"; |
127 | - } |
|
128 | - else |
|
126 | + } else |
|
129 | 127 | { |
130 | 128 | if (!is_writable($destDir)) |
131 | 129 | { |
132 | 130 | $this->view->uploadStatus="ERROR : $destDir directory is not writable"; |
133 | - } |
|
134 | - else |
|
131 | + } else |
|
135 | 132 | { |
136 | 133 | $destination = $destDir .'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name"; |
137 | 134 | $sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'],FILTER_SANITIZE_STRING); |
138 | 135 | if (move_uploaded_file($sourceTmpNam,$destination)===false) |
139 | 136 | { |
140 | 137 | $this->view->uploadStatus="ERROR, file $destination not loaded. Check file and path name or selinux violations"; |
141 | - } |
|
142 | - else |
|
138 | + } else |
|
143 | 139 | { |
144 | 140 | $this->view->uploadStatus="File $name uploaded in $destDir"; |
145 | 141 | } |
@@ -161,13 +157,11 @@ discard block |
||
161 | 157 | { |
162 | 158 | $this->view->snmptranslate='works fine'; |
163 | 159 | $this->view->snmptranslate_state='ok'; |
164 | - } |
|
165 | - else |
|
160 | + } else |
|
166 | 161 | { |
167 | 162 | $this->view->snmptranslate='can execute but no resolution'; |
168 | 163 | } |
169 | - } |
|
170 | - else |
|
164 | + } else |
|
171 | 165 | { |
172 | 166 | $this->view->snmptranslate='cannot execute'; |
173 | 167 | } |
@@ -188,15 +182,13 @@ discard block |
||
188 | 182 | if ($retVal==0) |
189 | 183 | { |
190 | 184 | $dirArray=array_merge($dirArray,explode(':',$sysDirs)); |
191 | - } |
|
192 | - else |
|
185 | + } else |
|
193 | 186 | { |
194 | 187 | $translateOut=exec($this->Config()->get('config', 'snmptranslate') . ' -Dinit_mib .1.3 2>&1 | grep MIBDIRS'); |
195 | 188 | if (preg_match('/MIBDIRS.*\'([^\']+)\'/',$translateOut,$matches)) |
196 | 189 | { |
197 | 190 | $dirArray=array_merge($dirArray,explode(':',$matches[1])); |
198 | - } |
|
199 | - else |
|
191 | + } else |
|
200 | 192 | { |
201 | 193 | array_push($dirArray,'Install net-snmp-config to see system directories'); |
202 | 194 | } |
@@ -25,16 +25,16 @@ discard block |
||
25 | 25 | */ |
26 | 26 | private function get_param() |
27 | 27 | { |
28 | - $dberrorMsg=$this->params->get('dberror'); |
|
29 | - if ($dberrorMsg != '') |
|
30 | - { |
|
31 | - $this->view->errorDetected=$dberrorMsg; |
|
32 | - } |
|
33 | - $dberrorMsg=$this->params->get('idodberror'); |
|
34 | - if ($dberrorMsg != '') |
|
35 | - { |
|
36 | - $this->view->errorDetected=$dberrorMsg; |
|
37 | - } |
|
28 | + $dberrorMsg=$this->params->get('dberror'); |
|
29 | + if ($dberrorMsg != '') |
|
30 | + { |
|
31 | + $this->view->errorDetected=$dberrorMsg; |
|
32 | + } |
|
33 | + $dberrorMsg=$this->params->get('idodberror'); |
|
34 | + if ($dberrorMsg != '') |
|
35 | + { |
|
36 | + $this->view->errorDetected=$dberrorMsg; |
|
37 | + } |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -43,22 +43,22 @@ discard block |
||
43 | 43 | */ |
44 | 44 | private function check_empty_config() |
45 | 45 | { |
46 | - $this->view->configErrorDetected == NULL; // Displayed error on various conifugration errors. |
|
47 | - if ($this->Config()->isEmpty() == true) |
|
48 | - { |
|
49 | - $this->Config()->setSection('config'); // Set base config section. |
|
50 | - try |
|
51 | - { |
|
52 | - $this->Config()->saveIni(); |
|
53 | - $this->view->configErrorDetected='Configuration is empty : you can run install script with parameters (see Automatic installation below)'; |
|
54 | - //$emptyConfig=1; |
|
55 | - } |
|
56 | - catch (Exception $e) |
|
57 | - { |
|
58 | - $this->view->configErrorDetected=$e->getMessage(); |
|
59 | - } |
|
46 | + $this->view->configErrorDetected == NULL; // Displayed error on various conifugration errors. |
|
47 | + if ($this->Config()->isEmpty() == true) |
|
48 | + { |
|
49 | + $this->Config()->setSection('config'); // Set base config section. |
|
50 | + try |
|
51 | + { |
|
52 | + $this->Config()->saveIni(); |
|
53 | + $this->view->configErrorDetected='Configuration is empty : you can run install script with parameters (see Automatic installation below)'; |
|
54 | + //$emptyConfig=1; |
|
55 | + } |
|
56 | + catch (Exception $e) |
|
57 | + { |
|
58 | + $this->view->configErrorDetected=$e->getMessage(); |
|
59 | + } |
|
60 | 60 | |
61 | - } |
|
61 | + } |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -71,56 +71,56 @@ discard block |
||
71 | 71 | */ |
72 | 72 | private function check_db() |
73 | 73 | { |
74 | - $db_message=array( // index => ( message OK, message NOK, optional link if NOK ) |
|
75 | - 0 => array('Database configuration OK','',''), |
|
76 | - 1 => array('Database set in config.ini','No database in config.ini',''), |
|
77 | - 2 => array('Database exists in Icingaweb2 config','Database does not exist in Icingaweb2 : ', |
|
78 | - Url::fromPath('config/resource')), |
|
79 | - 3 => array('Database credentials OK','Database does not exist/invalid credentials/no schema : ', |
|
80 | - Url::fromPath('trapdirector/settings/createschema')), |
|
81 | - 4 => array('Schema is set','Schema is not set for ', |
|
82 | - Url::fromPath('trapdirector/settings/createschema')), |
|
83 | - 5 => array('Schema is up to date','Schema is outdated :', |
|
84 | - Url::fromPath('trapdirector/settings/updateschema')), |
|
85 | - ); |
|
74 | + $db_message=array( // index => ( message OK, message NOK, optional link if NOK ) |
|
75 | + 0 => array('Database configuration OK','',''), |
|
76 | + 1 => array('Database set in config.ini','No database in config.ini',''), |
|
77 | + 2 => array('Database exists in Icingaweb2 config','Database does not exist in Icingaweb2 : ', |
|
78 | + Url::fromPath('config/resource')), |
|
79 | + 3 => array('Database credentials OK','Database does not exist/invalid credentials/no schema : ', |
|
80 | + Url::fromPath('trapdirector/settings/createschema')), |
|
81 | + 4 => array('Schema is set','Schema is not set for ', |
|
82 | + Url::fromPath('trapdirector/settings/createschema')), |
|
83 | + 5 => array('Schema is up to date','Schema is outdated :', |
|
84 | + Url::fromPath('trapdirector/settings/updateschema')), |
|
85 | + ); |
|
86 | 86 | |
87 | - try { |
|
88 | - $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
|
89 | - $dberror=array(0,''); |
|
90 | - } catch (DBException $e) { |
|
91 | - $dberror = $e->getArray(); |
|
92 | - } |
|
87 | + try { |
|
88 | + $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
|
89 | + $dberror=array(0,''); |
|
90 | + } catch (DBException $e) { |
|
91 | + $dberror = $e->getArray(); |
|
92 | + } |
|
93 | 93 | |
94 | - $this->view->db_error=$dberror[0]; |
|
95 | - switch ($dberror[0]) |
|
96 | - { |
|
97 | - case 2: |
|
98 | - case 4: |
|
99 | - $db_message[$dberror[0]][1] .= $dberror[1]; |
|
100 | - break; |
|
101 | - case 3: |
|
102 | - $db_message[$dberror[0]][1] .= $dberror[1] . ', Message : ' . $dberror[2]; |
|
103 | - break; |
|
104 | - case 5: |
|
105 | - $db_message[$dberror[0]][1] .= ' version '. $dberror[1] . ', version needed : ' .$dberror[2]; |
|
106 | - break; |
|
107 | - case 0: |
|
108 | - case 1: |
|
109 | - break; |
|
110 | - default: |
|
111 | - new ProgrammingError('Out of bond result from database test'); |
|
112 | - } |
|
113 | - $this->view->message=$db_message; |
|
94 | + $this->view->db_error=$dberror[0]; |
|
95 | + switch ($dberror[0]) |
|
96 | + { |
|
97 | + case 2: |
|
98 | + case 4: |
|
99 | + $db_message[$dberror[0]][1] .= $dberror[1]; |
|
100 | + break; |
|
101 | + case 3: |
|
102 | + $db_message[$dberror[0]][1] .= $dberror[1] . ', Message : ' . $dberror[2]; |
|
103 | + break; |
|
104 | + case 5: |
|
105 | + $db_message[$dberror[0]][1] .= ' version '. $dberror[1] . ', version needed : ' .$dberror[2]; |
|
106 | + break; |
|
107 | + case 0: |
|
108 | + case 1: |
|
109 | + break; |
|
110 | + default: |
|
111 | + new ProgrammingError('Out of bond result from database test'); |
|
112 | + } |
|
113 | + $this->view->message=$db_message; |
|
114 | 114 | |
115 | - try { |
|
116 | - $this->getUIDatabase()->testGetIdoDb(); // Get DB in test mode |
|
117 | - $dberror=array(0,''); |
|
118 | - } catch (DBException $e) { |
|
119 | - $dberror = $e->getArray(); |
|
120 | - } |
|
115 | + try { |
|
116 | + $this->getUIDatabase()->testGetIdoDb(); // Get DB in test mode |
|
117 | + $dberror=array(0,''); |
|
118 | + } catch (DBException $e) { |
|
119 | + $dberror = $e->getArray(); |
|
120 | + } |
|
121 | 121 | |
122 | - $this->view->ido_db_error=$dberror[0]; |
|
123 | - $this->view->ido_message='IDO Database : ' . $dberror[1]; |
|
122 | + $this->view->ido_db_error=$dberror[0]; |
|
123 | + $this->view->ido_message='IDO Database : ' . $dberror[1]; |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -130,23 +130,23 @@ discard block |
||
130 | 130 | */ |
131 | 131 | private function check_api() |
132 | 132 | { |
133 | - if ($this->Config()->get('config', 'icingaAPI_host') != '') |
|
134 | - { |
|
135 | - $apitest=new Icinga2Api($this->Config()->get('config', 'icingaAPI_host'),$this->Config()->get('config', 'icingaAPI_port')); |
|
136 | - $apitest->setCredentials($this->Config()->get('config', 'icingaAPI_user'), $this->Config()->get('config', 'icingaAPI_password')); |
|
137 | - try { |
|
138 | - list($this->view->apimessageError,$this->view->apimessage)=$apitest->test($this->getModuleConfig()::getapiUserPermissions()); |
|
139 | - //$this->view->apimessageError=false; |
|
140 | - } catch (RuntimeException $e) { |
|
141 | - $this->view->apimessage='API config : ' . $e->getMessage(); |
|
142 | - $this->view->apimessageError=true; |
|
143 | - } |
|
144 | - } |
|
145 | - else |
|
146 | - { |
|
147 | - $this->view->apimessage='API parameters not configured'; |
|
148 | - $this->view->apimessageError=true; |
|
149 | - } |
|
133 | + if ($this->Config()->get('config', 'icingaAPI_host') != '') |
|
134 | + { |
|
135 | + $apitest=new Icinga2Api($this->Config()->get('config', 'icingaAPI_host'),$this->Config()->get('config', 'icingaAPI_port')); |
|
136 | + $apitest->setCredentials($this->Config()->get('config', 'icingaAPI_user'), $this->Config()->get('config', 'icingaAPI_password')); |
|
137 | + try { |
|
138 | + list($this->view->apimessageError,$this->view->apimessage)=$apitest->test($this->getModuleConfig()::getapiUserPermissions()); |
|
139 | + //$this->view->apimessageError=false; |
|
140 | + } catch (RuntimeException $e) { |
|
141 | + $this->view->apimessage='API config : ' . $e->getMessage(); |
|
142 | + $this->view->apimessageError=true; |
|
143 | + } |
|
144 | + } |
|
145 | + else |
|
146 | + { |
|
147 | + $this->view->apimessage='API parameters not configured'; |
|
148 | + $this->view->apimessageError=true; |
|
149 | + } |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | /** |
@@ -157,21 +157,21 @@ discard block |
||
157 | 157 | */ |
158 | 158 | private function check_icingaweb_path() |
159 | 159 | { |
160 | - $this->view->icingaEtcWarn=0; |
|
161 | - $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
162 | - if ($icingaweb2_etc != "/etc/icingaweb2/" && $icingaweb2_etc != '') |
|
163 | - { |
|
164 | - $output=array(); |
|
160 | + $this->view->icingaEtcWarn=0; |
|
161 | + $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
162 | + if ($icingaweb2_etc != "/etc/icingaweb2/" && $icingaweb2_etc != '') |
|
163 | + { |
|
164 | + $output=array(); |
|
165 | 165 | |
166 | - exec('cat ' . $this->module->getBaseDir() .'/bin/trap_in.php | grep "\$icingaweb2Etc=" ',$output); |
|
166 | + exec('cat ' . $this->module->getBaseDir() .'/bin/trap_in.php | grep "\$icingaweb2Etc=" ',$output); |
|
167 | 167 | |
168 | 168 | |
169 | - if (! isset($output[0]) || ! preg_match('#"'. $icingaweb2_etc .'"#',$output[0])) |
|
170 | - { |
|
171 | - $this->view->icingaEtcWarn=1; |
|
172 | - $this->view->icingaweb2_etc=$icingaweb2_etc; |
|
173 | - } |
|
174 | - } |
|
169 | + if (! isset($output[0]) || ! preg_match('#"'. $icingaweb2_etc .'"#',$output[0])) |
|
170 | + { |
|
171 | + $this->view->icingaEtcWarn=1; |
|
172 | + $this->view->icingaweb2_etc=$icingaweb2_etc; |
|
173 | + } |
|
174 | + } |
|
175 | 175 | |
176 | 176 | } |
177 | 177 | |
@@ -182,15 +182,15 @@ discard block |
||
182 | 182 | */ |
183 | 183 | private function get_db_list($allowed) |
184 | 184 | { |
185 | - $resources = array(); |
|
186 | - foreach (ResourceFactory::getResourceConfigs() as $name => $resource) |
|
187 | - { |
|
188 | - if ($resource->get('type') === 'db' && in_array($resource->get('db'), $allowed)) |
|
189 | - { |
|
190 | - $resources[$name] = $name; |
|
191 | - } |
|
192 | - } |
|
193 | - return $resources; |
|
185 | + $resources = array(); |
|
186 | + foreach (ResourceFactory::getResourceConfigs() as $name => $resource) |
|
187 | + { |
|
188 | + if ($resource->get('type') === 'db' && in_array($resource->get('db'), $allowed)) |
|
189 | + { |
|
190 | + $resources[$name] = $name; |
|
191 | + } |
|
192 | + } |
|
193 | + return $resources; |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | public function indexAction() |
210 | 210 | { |
211 | 211 | |
212 | - // CHeck permissions : display tests in any case, but no configuration. |
|
212 | + // CHeck permissions : display tests in any case, but no configuration. |
|
213 | 213 | $this->view->configPermission=$this->checkModuleConfigPermission(1); |
214 | 214 | // But check read permission |
215 | 215 | $this->checkReadPermission(); |
@@ -217,16 +217,16 @@ discard block |
||
217 | 217 | $this->view->tabs = $this->Module()->getConfigTabs()->activate('config'); |
218 | 218 | |
219 | 219 | // Get message : sent on configuration problems detected by controllers |
220 | - $this->get_param(); |
|
220 | + $this->get_param(); |
|
221 | 221 | |
222 | - // Test if configuration exists, if not create for installer script |
|
222 | + // Test if configuration exists, if not create for installer script |
|
223 | 223 | $this->check_empty_config(); |
224 | 224 | |
225 | 225 | // Test Database |
226 | - $this->check_db(); |
|
226 | + $this->check_db(); |
|
227 | 227 | |
228 | 228 | //********* Test API |
229 | - $this->check_api(); |
|
229 | + $this->check_api(); |
|
230 | 230 | |
231 | 231 | //*********** Test snmptrapd alive and options |
232 | 232 | list ($this->view->snmptrapdError, $this->view->snmptrapdMessage) = $this->checkSnmpTrapd(); |
@@ -241,11 +241,11 @@ discard block |
||
241 | 241 | $this->view->traps_in_config= PHP_BINARY . ' ' . $this->Module()->getBaseDir() . '/bin/trap_in.php'; |
242 | 242 | |
243 | 243 | $this->view->installer= $this->Module()->getBaseDir() . '/bin/installer.sh ' |
244 | - . ' -c all ' |
|
245 | - . ' -d ' . $this->Module()->getBaseDir() |
|
246 | - . ' -p ' . PHP_BINARY |
|
247 | - . ' -a ' . exec('whoami') |
|
248 | - . ' -w ' . Icinga::app()->getConfigDir(); |
|
244 | + . ' -c all ' |
|
245 | + . ' -d ' . $this->Module()->getBaseDir() |
|
246 | + . ' -p ' . PHP_BINARY |
|
247 | + . ' -a ' . exec('whoami') |
|
248 | + . ' -w ' . Icinga::app()->getConfigDir(); |
|
249 | 249 | |
250 | 250 | // ******************* configuration form setup******************* |
251 | 251 | $this->view->form = $form = new TrapsConfigForm(); |
@@ -275,8 +275,8 @@ discard block |
||
275 | 275 | |
276 | 276 | try |
277 | 277 | { |
278 | - $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
|
279 | - printf('Schema already exists'); |
|
278 | + $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
|
279 | + printf('Schema already exists'); |
|
280 | 280 | |
281 | 281 | } |
282 | 282 | catch (DBException $e) |
@@ -287,19 +287,19 @@ discard block |
||
287 | 287 | // Get module database name |
288 | 288 | $dbName=$this->Config()->get('config', 'database'); |
289 | 289 | |
290 | - $dbResource = ResourceFactory::getResourceConfig($dbName); |
|
291 | - $dbType=$dbResource->get('db'); |
|
292 | - switch ($dbType) { |
|
293 | - case 'mysql': |
|
294 | - $dbFileExt='sql'; |
|
295 | - break; |
|
296 | - case 'pgsql': |
|
297 | - $dbFileExt='pgsql'; |
|
298 | - break; |
|
299 | - default: |
|
300 | - printf("Database configuration error : Unsuported DB"); |
|
301 | - return; |
|
302 | - } |
|
290 | + $dbResource = ResourceFactory::getResourceConfig($dbName); |
|
291 | + $dbType=$dbResource->get('db'); |
|
292 | + switch ($dbType) { |
|
293 | + case 'mysql': |
|
294 | + $dbFileExt='sql'; |
|
295 | + break; |
|
296 | + case 'pgsql': |
|
297 | + $dbFileExt='pgsql'; |
|
298 | + break; |
|
299 | + default: |
|
300 | + printf("Database configuration error : Unsuported DB"); |
|
301 | + return; |
|
302 | + } |
|
303 | 303 | |
304 | 304 | printf('<pre>'); |
305 | 305 | require_once $this->Module()->getBaseDir() .'/bin/trap_class.php'; |
@@ -323,32 +323,32 @@ discard block |
||
323 | 323 | public function updateschemaAction() |
324 | 324 | { |
325 | 325 | $this->checkModuleConfigPermission(); |
326 | - $this->getTabs()->add('get',array( |
|
327 | - 'active' => true, |
|
328 | - 'label' => $this->translate('Update Schema'), |
|
329 | - 'url' => Url::fromRequest() |
|
330 | - )); |
|
326 | + $this->getTabs()->add('get',array( |
|
327 | + 'active' => true, |
|
328 | + 'label' => $this->translate('Update Schema'), |
|
329 | + 'url' => Url::fromRequest() |
|
330 | + )); |
|
331 | 331 | // check if needed |
332 | 332 | $dberror=array(); |
333 | - try |
|
334 | - { |
|
335 | - $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
|
336 | - echo 'Schema already exists and is up to date<br>'; |
|
337 | - return; |
|
338 | - } |
|
339 | - catch (DBException $e) |
|
340 | - { |
|
341 | - $dberror=$e->getArray(); |
|
342 | - } |
|
333 | + try |
|
334 | + { |
|
335 | + $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
|
336 | + echo 'Schema already exists and is up to date<br>'; |
|
337 | + return; |
|
338 | + } |
|
339 | + catch (DBException $e) |
|
340 | + { |
|
341 | + $dberror=$e->getArray(); |
|
342 | + } |
|
343 | 343 | |
344 | 344 | echo 'Return to <a href="' . Url::fromPath('trapdirector/settings') .'" class="link-button icon-wrench"> settings page </a><br><br>'; |
345 | 345 | |
346 | 346 | if ($dberror[0] != 5) |
347 | 347 | { |
348 | - echo 'Database does not exists or is not setup correctly<br>'; |
|
349 | - return; |
|
348 | + echo 'Database does not exists or is not setup correctly<br>'; |
|
349 | + return; |
|
350 | 350 | } |
351 | - // setup |
|
351 | + // setup |
|
352 | 352 | require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
353 | 353 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
354 | 354 | $debug_level=4; |
@@ -361,20 +361,20 @@ discard block |
||
361 | 361 | $target_version=$dberror[2]; |
362 | 362 | |
363 | 363 | if ($this->params->get('msgok') == null) { |
364 | - // Check for messages and display if any |
|
365 | - echo "Upgrade databse is going to start.<br>Don't forget to backup your database before update<br>"; |
|
366 | - $Trap->setLogging(2,'syslog'); |
|
367 | - $message = $Trap->trapsDB->update_schema($updateSchema,$target_version,$prefix,true); |
|
368 | - if ($message != '') |
|
369 | - { |
|
370 | - echo 'Note :<br><pre>'; |
|
371 | - echo $message; |
|
372 | - echo '</pre>'; |
|
373 | - echo '<br>'; |
|
374 | - echo '<a class="link-button" style="font-size:large;font-weight:bold" href="' . Url::fromPath('trapdirector/settings/updateschema') .'?msgok=1">Click here to update</a>'; |
|
375 | - echo '<br>'; |
|
376 | - return; |
|
377 | - } |
|
364 | + // Check for messages and display if any |
|
365 | + echo "Upgrade databse is going to start.<br>Don't forget to backup your database before update<br>"; |
|
366 | + $Trap->setLogging(2,'syslog'); |
|
367 | + $message = $Trap->trapsDB->update_schema($updateSchema,$target_version,$prefix,true); |
|
368 | + if ($message != '') |
|
369 | + { |
|
370 | + echo 'Note :<br><pre>'; |
|
371 | + echo $message; |
|
372 | + echo '</pre>'; |
|
373 | + echo '<br>'; |
|
374 | + echo '<a class="link-button" style="font-size:large;font-weight:bold" href="' . Url::fromPath('trapdirector/settings/updateschema') .'?msgok=1">Click here to update</a>'; |
|
375 | + echo '<br>'; |
|
376 | + return; |
|
377 | + } |
|
378 | 378 | } |
379 | 379 | |
380 | 380 | $Trap->setLogging($debug_level,'display'); |
@@ -388,28 +388,28 @@ discard block |
||
388 | 388 | |
389 | 389 | private function checkSnmpTrapd() |
390 | 390 | { |
391 | - $psOutput=array(); |
|
392 | - // First check is someone is listening to port 162. As not root, we can't have pid... |
|
393 | - exec('netstat -an |grep -E "udp.*:162"',$psOutput); |
|
394 | - if (count($psOutput) == 0) |
|
395 | - { |
|
396 | - return array(1,'Port UDP/162 is not open : snmptrapd must not be started'); |
|
397 | - } |
|
398 | - $psOutput=array(); |
|
399 | - exec('ps fax |grep snmptrapd |grep -v grep',$psOutput); |
|
400 | - if (count($psOutput) == 0) |
|
401 | - { |
|
402 | - return array(1,"UDP/162 : OK, but no snmptrapd process (?)"); |
|
403 | - } |
|
404 | - // Assume there is only one line... TODO : see if there is a better way to do this |
|
405 | - $line = preg_replace('/^.*snmptrapd /','',$psOutput[0]); |
|
406 | - if (!preg_match('/-n/',$line)) |
|
407 | - return array(1,'snmptrapd has no -n option : '.$line); |
|
408 | - if (!preg_match('/-O[^ ]*n/',$line)) |
|
409 | - return array(1,'snmptrapd has no -On option : '.$line); |
|
410 | - if (!preg_match('/-O[^ ]*e/',$line)) |
|
411 | - return array(1,'snmptrapd has no -Oe option : '.$line); |
|
391 | + $psOutput=array(); |
|
392 | + // First check is someone is listening to port 162. As not root, we can't have pid... |
|
393 | + exec('netstat -an |grep -E "udp.*:162"',$psOutput); |
|
394 | + if (count($psOutput) == 0) |
|
395 | + { |
|
396 | + return array(1,'Port UDP/162 is not open : snmptrapd must not be started'); |
|
397 | + } |
|
398 | + $psOutput=array(); |
|
399 | + exec('ps fax |grep snmptrapd |grep -v grep',$psOutput); |
|
400 | + if (count($psOutput) == 0) |
|
401 | + { |
|
402 | + return array(1,"UDP/162 : OK, but no snmptrapd process (?)"); |
|
403 | + } |
|
404 | + // Assume there is only one line... TODO : see if there is a better way to do this |
|
405 | + $line = preg_replace('/^.*snmptrapd /','',$psOutput[0]); |
|
406 | + if (!preg_match('/-n/',$line)) |
|
407 | + return array(1,'snmptrapd has no -n option : '.$line); |
|
408 | + if (!preg_match('/-O[^ ]*n/',$line)) |
|
409 | + return array(1,'snmptrapd has no -On option : '.$line); |
|
410 | + if (!preg_match('/-O[^ ]*e/',$line)) |
|
411 | + return array(1,'snmptrapd has no -Oe option : '.$line); |
|
412 | 412 | |
413 | - return array(0,'snmptrapd listening to UDP/162, options : '.$line); |
|
413 | + return array(0,'snmptrapd listening to UDP/162, options : '.$line); |
|
414 | 414 | } |
415 | 415 | } |
@@ -72,23 +72,23 @@ discard block |
||
72 | 72 | private function check_db() |
73 | 73 | { |
74 | 74 | $db_message=array( // index => ( message OK, message NOK, optional link if NOK ) |
75 | - 0 => array('Database configuration OK','',''), |
|
76 | - 1 => array('Database set in config.ini','No database in config.ini',''), |
|
77 | - 2 => array('Database exists in Icingaweb2 config','Database does not exist in Icingaweb2 : ', |
|
75 | + 0 => array('Database configuration OK', '', ''), |
|
76 | + 1 => array('Database set in config.ini', 'No database in config.ini', ''), |
|
77 | + 2 => array('Database exists in Icingaweb2 config', 'Database does not exist in Icingaweb2 : ', |
|
78 | 78 | Url::fromPath('config/resource')), |
79 | - 3 => array('Database credentials OK','Database does not exist/invalid credentials/no schema : ', |
|
79 | + 3 => array('Database credentials OK', 'Database does not exist/invalid credentials/no schema : ', |
|
80 | 80 | Url::fromPath('trapdirector/settings/createschema')), |
81 | - 4 => array('Schema is set','Schema is not set for ', |
|
81 | + 4 => array('Schema is set', 'Schema is not set for ', |
|
82 | 82 | Url::fromPath('trapdirector/settings/createschema')), |
83 | - 5 => array('Schema is up to date','Schema is outdated :', |
|
83 | + 5 => array('Schema is up to date', 'Schema is outdated :', |
|
84 | 84 | Url::fromPath('trapdirector/settings/updateschema')), |
85 | 85 | ); |
86 | 86 | |
87 | 87 | try { |
88 | 88 | $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
89 | - $dberror=array(0,''); |
|
89 | + $dberror=array(0, ''); |
|
90 | 90 | } catch (DBException $e) { |
91 | - $dberror = $e->getArray(); |
|
91 | + $dberror=$e->getArray(); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | $this->view->db_error=$dberror[0]; |
@@ -96,13 +96,13 @@ discard block |
||
96 | 96 | { |
97 | 97 | case 2: |
98 | 98 | case 4: |
99 | - $db_message[$dberror[0]][1] .= $dberror[1]; |
|
99 | + $db_message[$dberror[0]][1].=$dberror[1]; |
|
100 | 100 | break; |
101 | 101 | case 3: |
102 | - $db_message[$dberror[0]][1] .= $dberror[1] . ', Message : ' . $dberror[2]; |
|
102 | + $db_message[$dberror[0]][1].=$dberror[1].', Message : '.$dberror[2]; |
|
103 | 103 | break; |
104 | 104 | case 5: |
105 | - $db_message[$dberror[0]][1] .= ' version '. $dberror[1] . ', version needed : ' .$dberror[2]; |
|
105 | + $db_message[$dberror[0]][1].=' version '.$dberror[1].', version needed : '.$dberror[2]; |
|
106 | 106 | break; |
107 | 107 | case 0: |
108 | 108 | case 1: |
@@ -114,13 +114,13 @@ discard block |
||
114 | 114 | |
115 | 115 | try { |
116 | 116 | $this->getUIDatabase()->testGetIdoDb(); // Get DB in test mode |
117 | - $dberror=array(0,''); |
|
117 | + $dberror=array(0, ''); |
|
118 | 118 | } catch (DBException $e) { |
119 | - $dberror = $e->getArray(); |
|
119 | + $dberror=$e->getArray(); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | $this->view->ido_db_error=$dberror[0]; |
123 | - $this->view->ido_message='IDO Database : ' . $dberror[1]; |
|
123 | + $this->view->ido_message='IDO Database : '.$dberror[1]; |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -132,13 +132,13 @@ discard block |
||
132 | 132 | { |
133 | 133 | if ($this->Config()->get('config', 'icingaAPI_host') != '') |
134 | 134 | { |
135 | - $apitest=new Icinga2Api($this->Config()->get('config', 'icingaAPI_host'),$this->Config()->get('config', 'icingaAPI_port')); |
|
135 | + $apitest=new Icinga2Api($this->Config()->get('config', 'icingaAPI_host'), $this->Config()->get('config', 'icingaAPI_port')); |
|
136 | 136 | $apitest->setCredentials($this->Config()->get('config', 'icingaAPI_user'), $this->Config()->get('config', 'icingaAPI_password')); |
137 | 137 | try { |
138 | - list($this->view->apimessageError,$this->view->apimessage)=$apitest->test($this->getModuleConfig()::getapiUserPermissions()); |
|
138 | + list($this->view->apimessageError, $this->view->apimessage)=$apitest->test($this->getModuleConfig()::getapiUserPermissions()); |
|
139 | 139 | //$this->view->apimessageError=false; |
140 | 140 | } catch (RuntimeException $e) { |
141 | - $this->view->apimessage='API config : ' . $e->getMessage(); |
|
141 | + $this->view->apimessage='API config : '.$e->getMessage(); |
|
142 | 142 | $this->view->apimessageError=true; |
143 | 143 | } |
144 | 144 | } |
@@ -163,10 +163,10 @@ discard block |
||
163 | 163 | { |
164 | 164 | $output=array(); |
165 | 165 | |
166 | - exec('cat ' . $this->module->getBaseDir() .'/bin/trap_in.php | grep "\$icingaweb2Etc=" ',$output); |
|
166 | + exec('cat '.$this->module->getBaseDir().'/bin/trap_in.php | grep "\$icingaweb2Etc=" ', $output); |
|
167 | 167 | |
168 | 168 | |
169 | - if (! isset($output[0]) || ! preg_match('#"'. $icingaweb2_etc .'"#',$output[0])) |
|
169 | + if (!isset($output[0]) || !preg_match('#"'.$icingaweb2_etc.'"#', $output[0])) |
|
170 | 170 | { |
171 | 171 | $this->view->icingaEtcWarn=1; |
172 | 172 | $this->view->icingaweb2_etc=$icingaweb2_etc; |
@@ -182,12 +182,12 @@ discard block |
||
182 | 182 | */ |
183 | 183 | private function get_db_list($allowed) |
184 | 184 | { |
185 | - $resources = array(); |
|
185 | + $resources=array(); |
|
186 | 186 | foreach (ResourceFactory::getResourceConfigs() as $name => $resource) |
187 | 187 | { |
188 | 188 | if ($resource->get('type') === 'db' && in_array($resource->get('db'), $allowed)) |
189 | 189 | { |
190 | - $resources[$name] = $name; |
|
190 | + $resources[$name]=$name; |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | return $resources; |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | // But check read permission |
215 | 215 | $this->checkReadPermission(); |
216 | 216 | |
217 | - $this->view->tabs = $this->Module()->getConfigTabs()->activate('config'); |
|
217 | + $this->view->tabs=$this->Module()->getConfigTabs()->activate('config'); |
|
218 | 218 | |
219 | 219 | // Get message : sent on configuration problems detected by controllers |
220 | 220 | $this->get_param(); |
@@ -229,32 +229,32 @@ discard block |
||
229 | 229 | $this->check_api(); |
230 | 230 | |
231 | 231 | //*********** Test snmptrapd alive and options |
232 | - list ($this->view->snmptrapdError, $this->view->snmptrapdMessage) = $this->checkSnmpTrapd(); |
|
232 | + list ($this->view->snmptrapdError, $this->view->snmptrapdMessage)=$this->checkSnmpTrapd(); |
|
233 | 233 | |
234 | 234 | // List DB in $ressources |
235 | - $resources = $this->get_db_list(array('mysql', 'pgsql')); |
|
235 | + $resources=$this->get_db_list(array('mysql', 'pgsql')); |
|
236 | 236 | |
237 | 237 | // Check standard Icingaweb2 path |
238 | 238 | $this->check_icingaweb_path(); |
239 | 239 | |
240 | 240 | // Setup path for mini documentation |
241 | - $this->view->traps_in_config= PHP_BINARY . ' ' . $this->Module()->getBaseDir() . '/bin/trap_in.php'; |
|
241 | + $this->view->traps_in_config=PHP_BINARY.' '.$this->Module()->getBaseDir().'/bin/trap_in.php'; |
|
242 | 242 | |
243 | - $this->view->installer= $this->Module()->getBaseDir() . '/bin/installer.sh ' |
|
243 | + $this->view->installer=$this->Module()->getBaseDir().'/bin/installer.sh ' |
|
244 | 244 | . ' -c all ' |
245 | - . ' -d ' . $this->Module()->getBaseDir() |
|
246 | - . ' -p ' . PHP_BINARY |
|
247 | - . ' -a ' . exec('whoami') |
|
248 | - . ' -w ' . Icinga::app()->getConfigDir(); |
|
245 | + . ' -d '.$this->Module()->getBaseDir() |
|
246 | + . ' -p '.PHP_BINARY |
|
247 | + . ' -a '.exec('whoami') |
|
248 | + . ' -w '.Icinga::app()->getConfigDir(); |
|
249 | 249 | |
250 | 250 | // ******************* configuration form setup******************* |
251 | - $this->view->form = $form = new TrapsConfigForm(); |
|
251 | + $this->view->form=$form=new TrapsConfigForm(); |
|
252 | 252 | |
253 | 253 | // set default paths; |
254 | - $this->view->form->setPaths($this->Module()->getBaseDir(),Icinga::app()->getConfigDir()); |
|
254 | + $this->view->form->setPaths($this->Module()->getBaseDir(), Icinga::app()->getConfigDir()); |
|
255 | 255 | |
256 | 256 | // set default ido database |
257 | - $this->view->form->setDefaultIDODB($this->Config()->module('monitoring','backends')->get('icinga','resource')); |
|
257 | + $this->view->form->setDefaultIDODB($this->Config()->module('monitoring', 'backends')->get('icinga', 'resource')); |
|
258 | 258 | |
259 | 259 | // Make form handle request. |
260 | 260 | $form->setIniConfig($this->Config()) |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | public function createschemaAction() |
267 | 267 | { |
268 | 268 | $this->checkModuleConfigPermission(); |
269 | - $this->getTabs()->add('create_schema',array( |
|
269 | + $this->getTabs()->add('create_schema', array( |
|
270 | 270 | 'active' => true, |
271 | 271 | 'label' => $this->translate('Create Schema'), |
272 | 272 | 'url' => Url::fromRequest() |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | // Get module database name |
288 | 288 | $dbName=$this->Config()->get('config', 'database'); |
289 | 289 | |
290 | - $dbResource = ResourceFactory::getResourceConfig($dbName); |
|
290 | + $dbResource=ResourceFactory::getResourceConfig($dbName); |
|
291 | 291 | $dbType=$dbResource->get('db'); |
292 | 292 | switch ($dbType) { |
293 | 293 | case 'mysql': |
@@ -302,28 +302,28 @@ discard block |
||
302 | 302 | } |
303 | 303 | |
304 | 304 | printf('<pre>'); |
305 | - require_once $this->Module()->getBaseDir() .'/bin/trap_class.php'; |
|
305 | + require_once $this->Module()->getBaseDir().'/bin/trap_class.php'; |
|
306 | 306 | |
307 | 307 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
308 | 308 | $debug_level=4; |
309 | - $Trap = new Trap($icingaweb2_etc); |
|
310 | - $Trap->setLogging($debug_level,'display'); |
|
309 | + $Trap=new Trap($icingaweb2_etc); |
|
310 | + $Trap->setLogging($debug_level, 'display'); |
|
311 | 311 | |
312 | 312 | $prefix=$this->Config()->get('config', 'database_prefix'); |
313 | 313 | // schema file : <path>/SQL/schema_v<verion>.<dbtype> |
314 | - $schema=$this->Module()->getBaseDir() . |
|
315 | - '/SQL/schema_v'. $this->getModuleConfig()->getDbCurVersion() . '.' . $dbFileExt; |
|
314 | + $schema=$this->Module()->getBaseDir(). |
|
315 | + '/SQL/schema_v'.$this->getModuleConfig()->getDbCurVersion().'.'.$dbFileExt; |
|
316 | 316 | |
317 | - $Trap->trapsDB->create_schema($schema,$prefix); |
|
317 | + $Trap->trapsDB->create_schema($schema, $prefix); |
|
318 | 318 | echo '</pre>'; |
319 | 319 | } |
320 | - echo '<br><br>Return to <a href="' . Url::fromPath('trapdirector/settings') .'" class="link-button icon-wrench"> settings page </a>'; |
|
320 | + echo '<br><br>Return to <a href="'.Url::fromPath('trapdirector/settings').'" class="link-button icon-wrench"> settings page </a>'; |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | public function updateschemaAction() |
324 | 324 | { |
325 | 325 | $this->checkModuleConfigPermission(); |
326 | - $this->getTabs()->add('get',array( |
|
326 | + $this->getTabs()->add('get', array( |
|
327 | 327 | 'active' => true, |
328 | 328 | 'label' => $this->translate('Update Schema'), |
329 | 329 | 'url' => Url::fromRequest() |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | $dberror=$e->getArray(); |
342 | 342 | } |
343 | 343 | |
344 | - echo 'Return to <a href="' . Url::fromPath('trapdirector/settings') .'" class="link-button icon-wrench"> settings page </a><br><br>'; |
|
344 | + echo 'Return to <a href="'.Url::fromPath('trapdirector/settings').'" class="link-button icon-wrench"> settings page </a><br><br>'; |
|
345 | 345 | |
346 | 346 | if ($dberror[0] != 5) |
347 | 347 | { |
@@ -349,40 +349,40 @@ discard block |
||
349 | 349 | return; |
350 | 350 | } |
351 | 351 | // setup |
352 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
352 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
353 | 353 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
354 | 354 | $debug_level=4; |
355 | - $Trap = new Trap($icingaweb2_etc); |
|
355 | + $Trap=new Trap($icingaweb2_etc); |
|
356 | 356 | |
357 | 357 | |
358 | 358 | $prefix=$this->Config()->get('config', 'database_prefix'); |
359 | - $updateSchema=$this->Module()->getBaseDir() . '/SQL/'; |
|
359 | + $updateSchema=$this->Module()->getBaseDir().'/SQL/'; |
|
360 | 360 | |
361 | 361 | $target_version=$dberror[2]; |
362 | 362 | |
363 | 363 | if ($this->params->get('msgok') == null) { |
364 | 364 | // Check for messages and display if any |
365 | 365 | echo "Upgrade databse is going to start.<br>Don't forget to backup your database before update<br>"; |
366 | - $Trap->setLogging(2,'syslog'); |
|
367 | - $message = $Trap->trapsDB->update_schema($updateSchema,$target_version,$prefix,true); |
|
366 | + $Trap->setLogging(2, 'syslog'); |
|
367 | + $message=$Trap->trapsDB->update_schema($updateSchema, $target_version, $prefix, true); |
|
368 | 368 | if ($message != '') |
369 | 369 | { |
370 | 370 | echo 'Note :<br><pre>'; |
371 | 371 | echo $message; |
372 | 372 | echo '</pre>'; |
373 | 373 | echo '<br>'; |
374 | - echo '<a class="link-button" style="font-size:large;font-weight:bold" href="' . Url::fromPath('trapdirector/settings/updateschema') .'?msgok=1">Click here to update</a>'; |
|
374 | + echo '<a class="link-button" style="font-size:large;font-weight:bold" href="'.Url::fromPath('trapdirector/settings/updateschema').'?msgok=1">Click here to update</a>'; |
|
375 | 375 | echo '<br>'; |
376 | 376 | return; |
377 | 377 | } |
378 | 378 | } |
379 | 379 | |
380 | - $Trap->setLogging($debug_level,'display'); |
|
380 | + $Trap->setLogging($debug_level, 'display'); |
|
381 | 381 | |
382 | - echo 'Updating schema to '. $target_version . ': <br>'; |
|
382 | + echo 'Updating schema to '.$target_version.': <br>'; |
|
383 | 383 | echo '<pre>'; |
384 | 384 | |
385 | - $Trap->trapsDB->update_schema($updateSchema,$target_version,$prefix); |
|
385 | + $Trap->trapsDB->update_schema($updateSchema, $target_version, $prefix); |
|
386 | 386 | echo '</pre>'; |
387 | 387 | } |
388 | 388 | |
@@ -390,26 +390,26 @@ discard block |
||
390 | 390 | { |
391 | 391 | $psOutput=array(); |
392 | 392 | // First check is someone is listening to port 162. As not root, we can't have pid... |
393 | - exec('netstat -an |grep -E "udp.*:162"',$psOutput); |
|
393 | + exec('netstat -an |grep -E "udp.*:162"', $psOutput); |
|
394 | 394 | if (count($psOutput) == 0) |
395 | 395 | { |
396 | - return array(1,'Port UDP/162 is not open : snmptrapd must not be started'); |
|
396 | + return array(1, 'Port UDP/162 is not open : snmptrapd must not be started'); |
|
397 | 397 | } |
398 | 398 | $psOutput=array(); |
399 | - exec('ps fax |grep snmptrapd |grep -v grep',$psOutput); |
|
399 | + exec('ps fax |grep snmptrapd |grep -v grep', $psOutput); |
|
400 | 400 | if (count($psOutput) == 0) |
401 | 401 | { |
402 | - return array(1,"UDP/162 : OK, but no snmptrapd process (?)"); |
|
402 | + return array(1, "UDP/162 : OK, but no snmptrapd process (?)"); |
|
403 | 403 | } |
404 | 404 | // Assume there is only one line... TODO : see if there is a better way to do this |
405 | - $line = preg_replace('/^.*snmptrapd /','',$psOutput[0]); |
|
406 | - if (!preg_match('/-n/',$line)) |
|
407 | - return array(1,'snmptrapd has no -n option : '.$line); |
|
408 | - if (!preg_match('/-O[^ ]*n/',$line)) |
|
409 | - return array(1,'snmptrapd has no -On option : '.$line); |
|
410 | - if (!preg_match('/-O[^ ]*e/',$line)) |
|
411 | - return array(1,'snmptrapd has no -Oe option : '.$line); |
|
405 | + $line=preg_replace('/^.*snmptrapd /', '', $psOutput[0]); |
|
406 | + if (!preg_match('/-n/', $line)) |
|
407 | + return array(1, 'snmptrapd has no -n option : '.$line); |
|
408 | + if (!preg_match('/-O[^ ]*n/', $line)) |
|
409 | + return array(1, 'snmptrapd has no -On option : '.$line); |
|
410 | + if (!preg_match('/-O[^ ]*e/', $line)) |
|
411 | + return array(1, 'snmptrapd has no -Oe option : '.$line); |
|
412 | 412 | |
413 | - return array(0,'snmptrapd listening to UDP/162, options : '.$line); |
|
413 | + return array(0, 'snmptrapd listening to UDP/162, options : '.$line); |
|
414 | 414 | } |
415 | 415 | } |
@@ -52,8 +52,7 @@ discard block |
||
52 | 52 | $this->Config()->saveIni(); |
53 | 53 | $this->view->configErrorDetected='Configuration is empty : you can run install script with parameters (see Automatic installation below)'; |
54 | 54 | //$emptyConfig=1; |
55 | - } |
|
56 | - catch (Exception $e) |
|
55 | + } catch (Exception $e) |
|
57 | 56 | { |
58 | 57 | $this->view->configErrorDetected=$e->getMessage(); |
59 | 58 | } |
@@ -141,8 +140,7 @@ discard block |
||
141 | 140 | $this->view->apimessage='API config : ' . $e->getMessage(); |
142 | 141 | $this->view->apimessageError=true; |
143 | 142 | } |
144 | - } |
|
145 | - else |
|
143 | + } else |
|
146 | 144 | { |
147 | 145 | $this->view->apimessage='API parameters not configured'; |
148 | 146 | $this->view->apimessageError=true; |
@@ -278,8 +276,7 @@ discard block |
||
278 | 276 | $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
279 | 277 | printf('Schema already exists'); |
280 | 278 | |
281 | - } |
|
282 | - catch (DBException $e) |
|
279 | + } catch (DBException $e) |
|
283 | 280 | { |
284 | 281 | |
285 | 282 | printf('Creating schema : <br>'); |
@@ -335,8 +332,7 @@ discard block |
||
335 | 332 | $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
336 | 333 | echo 'Schema already exists and is up to date<br>'; |
337 | 334 | return; |
338 | - } |
|
339 | - catch (DBException $e) |
|
335 | + } catch (DBException $e) |
|
340 | 336 | { |
341 | 337 | $dberror=$e->getArray(); |
342 | 338 | } |
@@ -403,12 +399,15 @@ discard block |
||
403 | 399 | } |
404 | 400 | // Assume there is only one line... TODO : see if there is a better way to do this |
405 | 401 | $line = preg_replace('/^.*snmptrapd /','',$psOutput[0]); |
406 | - if (!preg_match('/-n/',$line)) |
|
407 | - return array(1,'snmptrapd has no -n option : '.$line); |
|
408 | - if (!preg_match('/-O[^ ]*n/',$line)) |
|
409 | - return array(1,'snmptrapd has no -On option : '.$line); |
|
410 | - if (!preg_match('/-O[^ ]*e/',$line)) |
|
411 | - return array(1,'snmptrapd has no -Oe option : '.$line); |
|
402 | + if (!preg_match('/-n/',$line)) { |
|
403 | + return array(1,'snmptrapd has no -n option : '.$line); |
|
404 | + } |
|
405 | + if (!preg_match('/-O[^ ]*n/',$line)) { |
|
406 | + return array(1,'snmptrapd has no -On option : '.$line); |
|
407 | + } |
|
408 | + if (!preg_match('/-O[^ ]*e/',$line)) { |
|
409 | + return array(1,'snmptrapd has no -Oe option : '.$line); |
|
410 | + } |
|
412 | 411 | |
413 | 412 | return array(0,'snmptrapd listening to UDP/162, options : '.$line); |
414 | 413 | } |
@@ -11,13 +11,12 @@ discard block |
||
11 | 11 | |
12 | 12 | //use Icinga\Web\Form as Form; |
13 | 13 | /** Rules management |
14 | - |
|
15 | -*/ |
|
14 | + */ |
|
16 | 15 | class HandlerController extends TrapsController |
17 | 16 | { |
18 | 17 | |
19 | 18 | /** index : list existing rules |
20 | - */ |
|
19 | + */ |
|
21 | 20 | public function indexAction() |
22 | 21 | { |
23 | 22 | $this->checkReadPermission(); |
@@ -41,22 +40,22 @@ discard block |
||
41 | 40 | */ |
42 | 41 | public function testruleAction() |
43 | 42 | { |
44 | - $this->checkReadPermission(); |
|
45 | - $this->getTabs()->add('get',array( |
|
46 | - 'active' => true, |
|
47 | - 'label' => $this->translate('Test Rule'), |
|
48 | - 'url' => Url::fromRequest() |
|
49 | - )); |
|
43 | + $this->checkReadPermission(); |
|
44 | + $this->getTabs()->add('get',array( |
|
45 | + 'active' => true, |
|
46 | + 'label' => $this->translate('Test Rule'), |
|
47 | + 'url' => Url::fromRequest() |
|
48 | + )); |
|
50 | 49 | |
51 | 50 | |
52 | - if ($this->params->get('rule') !== null) |
|
53 | - { |
|
54 | - $this->view->rule= $this->params->get('rule'); |
|
55 | - } |
|
56 | - else |
|
57 | - { |
|
58 | - $this->view->rule=''; |
|
59 | - } |
|
51 | + if ($this->params->get('rule') !== null) |
|
52 | + { |
|
53 | + $this->view->rule= $this->params->get('rule'); |
|
54 | + } |
|
55 | + else |
|
56 | + { |
|
57 | + $this->view->rule=''; |
|
58 | + } |
|
60 | 59 | } |
61 | 60 | |
62 | 61 | /** |
@@ -64,31 +63,31 @@ discard block |
||
64 | 63 | */ |
65 | 64 | private function add_setup_vars() |
66 | 65 | { |
67 | - // variables to send to view |
|
68 | - $this->view->hostlist=array(); // host list to input datalist |
|
69 | - $this->view->hostname=''; // Host name in input text |
|
70 | - $this->view->serviceGet=false; // Set to true to get list of service if only one host set |
|
71 | - $this->view->serviceSet=null; // Select service in services select (must have serviceGet=true). |
|
72 | - $this->view->mainoid=''; // Trap OID |
|
73 | - $this->view->mib=''; // Trap mib |
|
74 | - $this->view->name=''; // Trap name |
|
75 | - $this->view->trapListForMIB=array(); // Trap list if mib exists for trap |
|
76 | - $this->view->objectList=array(); // objects sent with trap |
|
77 | - $this->view->display=''; // Initial display |
|
78 | - $this->view->rule=''; // rule display |
|
79 | - $this->view->revertOK=''; // revert OK in seconds |
|
80 | - $this->view->hostid=-1; // normally set by javascript serviceGet() |
|
81 | - $this->view->ruleid=-1; // Rule id in DB for update & delete |
|
82 | - $this->view->setToUpdate=false; // set form as update form |
|
83 | - $this->view->setRuleMatch=-1; // set action on rule match (default nothing) |
|
84 | - $this->view->setRuleNoMatch=-1; // set action on rule no match (default nothing) |
|
66 | + // variables to send to view |
|
67 | + $this->view->hostlist=array(); // host list to input datalist |
|
68 | + $this->view->hostname=''; // Host name in input text |
|
69 | + $this->view->serviceGet=false; // Set to true to get list of service if only one host set |
|
70 | + $this->view->serviceSet=null; // Select service in services select (must have serviceGet=true). |
|
71 | + $this->view->mainoid=''; // Trap OID |
|
72 | + $this->view->mib=''; // Trap mib |
|
73 | + $this->view->name=''; // Trap name |
|
74 | + $this->view->trapListForMIB=array(); // Trap list if mib exists for trap |
|
75 | + $this->view->objectList=array(); // objects sent with trap |
|
76 | + $this->view->display=''; // Initial display |
|
77 | + $this->view->rule=''; // rule display |
|
78 | + $this->view->revertOK=''; // revert OK in seconds |
|
79 | + $this->view->hostid=-1; // normally set by javascript serviceGet() |
|
80 | + $this->view->ruleid=-1; // Rule id in DB for update & delete |
|
81 | + $this->view->setToUpdate=false; // set form as update form |
|
82 | + $this->view->setRuleMatch=-1; // set action on rule match (default nothing) |
|
83 | + $this->view->setRuleNoMatch=-1; // set action on rule no match (default nothing) |
|
85 | 84 | |
86 | - $this->view->selectGroup=false; // Select by group if true |
|
87 | - $this->view->hostgroupid=-1; // host group id |
|
88 | - $this->view->serviceGroupGet=false; // Get list of service for group (set serviceSet to select one) |
|
85 | + $this->view->selectGroup=false; // Select by group if true |
|
86 | + $this->view->hostgroupid=-1; // host group id |
|
87 | + $this->view->serviceGroupGet=false; // Get list of service for group (set serviceSet to select one) |
|
89 | 88 | |
90 | - $this->view->modifier=null; |
|
91 | - $this->view->modified=null; |
|
89 | + $this->view->modifier=null; |
|
90 | + $this->view->modified=null; |
|
92 | 91 | } |
93 | 92 | |
94 | 93 | /** |
@@ -97,102 +96,102 @@ discard block |
||
97 | 96 | */ |
98 | 97 | private function add_from_existing($trapid) |
99 | 98 | { |
100 | - /********** Setup from existing trap ***************/ |
|
101 | - // Get the full trap info |
|
102 | - $trapDetail=$this->getTrapDetail($trapid); |
|
99 | + /********** Setup from existing trap ***************/ |
|
100 | + // Get the full trap info |
|
101 | + $trapDetail=$this->getTrapDetail($trapid); |
|
103 | 102 | |
104 | - $hostfilter=$trapDetail->source_ip; |
|
103 | + $hostfilter=$trapDetail->source_ip; |
|
105 | 104 | |
106 | - // Get host |
|
107 | - try |
|
108 | - { |
|
109 | - $hosts=$this->getHostByIP($hostfilter); |
|
110 | - } |
|
111 | - catch (Exception $e) |
|
112 | - { |
|
113 | - $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage()); |
|
114 | - } |
|
105 | + // Get host |
|
106 | + try |
|
107 | + { |
|
108 | + $hosts=$this->getHostByIP($hostfilter); |
|
109 | + } |
|
110 | + catch (Exception $e) |
|
111 | + { |
|
112 | + $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage()); |
|
113 | + } |
|
115 | 114 | |
116 | 115 | |
117 | - // if one unique host found -> put id text input |
|
118 | - if (count($hosts)==1) { |
|
119 | - $this->view->hostname=$hosts[0]->name; |
|
120 | - //$hostid=$hosts[0]->id; |
|
121 | - // Tell JS to get services when page is loaded |
|
122 | - $this->view->serviceGet=true; |
|
116 | + // if one unique host found -> put id text input |
|
117 | + if (count($hosts)==1) { |
|
118 | + $this->view->hostname=$hosts[0]->name; |
|
119 | + //$hostid=$hosts[0]->id; |
|
120 | + // Tell JS to get services when page is loaded |
|
121 | + $this->view->serviceGet=true; |
|
123 | 122 | |
124 | - } |
|
125 | - else |
|
126 | - { |
|
127 | - foreach($hosts as $key=>$val) |
|
128 | - { |
|
129 | - array_push($this->view->hostlist,$hosts[$key]->name); |
|
130 | - } |
|
131 | - } |
|
123 | + } |
|
124 | + else |
|
125 | + { |
|
126 | + foreach($hosts as $key=>$val) |
|
127 | + { |
|
128 | + array_push($this->view->hostlist,$hosts[$key]->name); |
|
129 | + } |
|
130 | + } |
|
132 | 131 | |
133 | - // set up trap oid and objects received by the trap |
|
132 | + // set up trap oid and objects received by the trap |
|
134 | 133 | |
135 | - $this->view->mainoid=$trapDetail->trap_oid; |
|
136 | - if ($trapDetail->trap_name_mib != null) |
|
137 | - { |
|
138 | - $this->view->mib=$trapDetail->trap_name_mib; |
|
139 | - $this->view->name=$trapDetail->trap_name; |
|
140 | - $this->view->trapListForMIB=$this->getMIB() |
|
141 | - ->getTrapList($trapDetail->trap_name_mib); |
|
142 | - } |
|
134 | + $this->view->mainoid=$trapDetail->trap_oid; |
|
135 | + if ($trapDetail->trap_name_mib != null) |
|
136 | + { |
|
137 | + $this->view->mib=$trapDetail->trap_name_mib; |
|
138 | + $this->view->name=$trapDetail->trap_name; |
|
139 | + $this->view->trapListForMIB=$this->getMIB() |
|
140 | + ->getTrapList($trapDetail->trap_name_mib); |
|
141 | + } |
|
143 | 142 | |
144 | - // Get all objects that can be in trap from MIB |
|
145 | - $allObjects=$this->getMIB()->getObjectList($trapDetail->trap_oid); |
|
146 | - // Get all objects in current Trap |
|
147 | - $currentTrapObjects=$this->getTrapobjects($trapid); |
|
148 | - $oid_index=1; |
|
149 | - foreach ($currentTrapObjects as $key => $val) |
|
150 | - { |
|
151 | - $currentObjectType='Unknown'; |
|
152 | - $currentObjectTypeEnum='Unknown'; |
|
153 | - if (isset($allObjects[$val->oid]['type'])) |
|
154 | - { |
|
155 | - $currentObjectType=$allObjects[$val->oid]['type']; |
|
156 | - $currentObjectTypeEnum=$allObjects[$val->oid]['type_enum']; |
|
157 | - } |
|
158 | - $currentObject=array( |
|
159 | - $oid_index, |
|
160 | - $val->oid, |
|
161 | - $val->oid_name_mib, |
|
162 | - $val->oid_name, |
|
163 | - $val->value, |
|
164 | - $currentObjectType, |
|
165 | - $currentObjectTypeEnum |
|
166 | - ); |
|
167 | - $oid_index++; |
|
168 | - array_push($this->view->objectList,$currentObject); |
|
169 | - // set currrent object to null in allObjects |
|
170 | - if (isset($allObjects[$val->oid])) |
|
171 | - { |
|
172 | - $allObjects[$val->oid]=null; |
|
173 | - } |
|
174 | - } |
|
175 | - if ($allObjects!=null) // in case trap doesn't have objects or is not resolved |
|
176 | - { |
|
177 | - foreach ($allObjects as $key => $val) |
|
178 | - { |
|
179 | - if ($val==null) { continue; } |
|
180 | - array_push($this->view->objectList, array( |
|
181 | - $oid_index, |
|
182 | - $key, |
|
183 | - $allObjects[$key]['mib'], |
|
184 | - $allObjects[$key]['name'], |
|
185 | - '', |
|
186 | - $allObjects[$key]['type'], |
|
187 | - $allObjects[$key]['type_enum'] |
|
188 | - )); |
|
189 | - $oid_index++; |
|
190 | - } |
|
191 | - } |
|
143 | + // Get all objects that can be in trap from MIB |
|
144 | + $allObjects=$this->getMIB()->getObjectList($trapDetail->trap_oid); |
|
145 | + // Get all objects in current Trap |
|
146 | + $currentTrapObjects=$this->getTrapobjects($trapid); |
|
147 | + $oid_index=1; |
|
148 | + foreach ($currentTrapObjects as $key => $val) |
|
149 | + { |
|
150 | + $currentObjectType='Unknown'; |
|
151 | + $currentObjectTypeEnum='Unknown'; |
|
152 | + if (isset($allObjects[$val->oid]['type'])) |
|
153 | + { |
|
154 | + $currentObjectType=$allObjects[$val->oid]['type']; |
|
155 | + $currentObjectTypeEnum=$allObjects[$val->oid]['type_enum']; |
|
156 | + } |
|
157 | + $currentObject=array( |
|
158 | + $oid_index, |
|
159 | + $val->oid, |
|
160 | + $val->oid_name_mib, |
|
161 | + $val->oid_name, |
|
162 | + $val->value, |
|
163 | + $currentObjectType, |
|
164 | + $currentObjectTypeEnum |
|
165 | + ); |
|
166 | + $oid_index++; |
|
167 | + array_push($this->view->objectList,$currentObject); |
|
168 | + // set currrent object to null in allObjects |
|
169 | + if (isset($allObjects[$val->oid])) |
|
170 | + { |
|
171 | + $allObjects[$val->oid]=null; |
|
172 | + } |
|
173 | + } |
|
174 | + if ($allObjects!=null) // in case trap doesn't have objects or is not resolved |
|
175 | + { |
|
176 | + foreach ($allObjects as $key => $val) |
|
177 | + { |
|
178 | + if ($val==null) { continue; } |
|
179 | + array_push($this->view->objectList, array( |
|
180 | + $oid_index, |
|
181 | + $key, |
|
182 | + $allObjects[$key]['mib'], |
|
183 | + $allObjects[$key]['name'], |
|
184 | + '', |
|
185 | + $allObjects[$key]['type'], |
|
186 | + $allObjects[$key]['type_enum'] |
|
187 | + )); |
|
188 | + $oid_index++; |
|
189 | + } |
|
190 | + } |
|
192 | 191 | |
193 | - // Add a simple display |
|
194 | - $this->view->display='Trap '.$trapDetail->trap_name.' received'; |
|
195 | - $this->view->create_basic_rule=true; |
|
192 | + // Add a simple display |
|
193 | + $this->view->display='Trap '.$trapDetail->trap_name.' received'; |
|
194 | + $this->view->create_basic_rule=true; |
|
196 | 195 | } |
197 | 196 | |
198 | 197 | /** |
@@ -201,29 +200,29 @@ discard block |
||
201 | 200 | */ |
202 | 201 | private function add_check_host_exists($ruleDetail) |
203 | 202 | { |
204 | - // Check if hostname still exists |
|
205 | - $host_get=$this->getHostByName($this->view->hostname); |
|
203 | + // Check if hostname still exists |
|
204 | + $host_get=$this->getHostByName($this->view->hostname); |
|
206 | 205 | |
207 | - if (count($host_get)==0) |
|
208 | - { |
|
209 | - $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore'; |
|
210 | - $this->view->serviceGet=false; |
|
211 | - } |
|
212 | - else |
|
213 | - { |
|
214 | - // Tell JS to get services when page is loaded |
|
215 | - $this->view->serviceGet=true; |
|
216 | - // get service id for form to set : |
|
217 | - $serviceID=$this->getServiceIDByName($this->view->hostname,$ruleDetail->service_name); |
|
218 | - if (count($serviceID) ==0) |
|
219 | - { |
|
220 | - $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
221 | - } |
|
222 | - else |
|
223 | - { |
|
224 | - $this->view->serviceSet=$serviceID[0]->id; |
|
225 | - } |
|
226 | - } |
|
206 | + if (count($host_get)==0) |
|
207 | + { |
|
208 | + $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore'; |
|
209 | + $this->view->serviceGet=false; |
|
210 | + } |
|
211 | + else |
|
212 | + { |
|
213 | + // Tell JS to get services when page is loaded |
|
214 | + $this->view->serviceGet=true; |
|
215 | + // get service id for form to set : |
|
216 | + $serviceID=$this->getServiceIDByName($this->view->hostname,$ruleDetail->service_name); |
|
217 | + if (count($serviceID) ==0) |
|
218 | + { |
|
219 | + $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
220 | + } |
|
221 | + else |
|
222 | + { |
|
223 | + $this->view->serviceSet=$serviceID[0]->id; |
|
224 | + } |
|
225 | + } |
|
227 | 226 | } |
228 | 227 | |
229 | 228 | /** |
@@ -232,33 +231,33 @@ discard block |
||
232 | 231 | */ |
233 | 232 | private function add_check_hostgroup_exists($ruleDetail) |
234 | 233 | { |
235 | - // Check if groupe exists |
|
236 | - $group_get=$this->getHostGroupByName($this->view->hostgroupname); |
|
237 | - if (count($group_get)==0) |
|
238 | - { |
|
239 | - $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore'; |
|
240 | - $this->view->serviceGroupGet=false; |
|
241 | - } |
|
242 | - else |
|
243 | - { |
|
244 | - $grpServices=$this->getServicesByHostGroupid($group_get[0]->id); |
|
245 | - $foundGrpService=0; |
|
246 | - foreach ($grpServices as $grpService) |
|
247 | - { |
|
248 | - if ($grpService[0] == $ruleDetail->service_name) |
|
249 | - { |
|
250 | - $foundGrpService=1; |
|
251 | - $this->view->serviceSet=$ruleDetail->service_name; |
|
252 | - } |
|
253 | - } |
|
234 | + // Check if groupe exists |
|
235 | + $group_get=$this->getHostGroupByName($this->view->hostgroupname); |
|
236 | + if (count($group_get)==0) |
|
237 | + { |
|
238 | + $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore'; |
|
239 | + $this->view->serviceGroupGet=false; |
|
240 | + } |
|
241 | + else |
|
242 | + { |
|
243 | + $grpServices=$this->getServicesByHostGroupid($group_get[0]->id); |
|
244 | + $foundGrpService=0; |
|
245 | + foreach ($grpServices as $grpService) |
|
246 | + { |
|
247 | + if ($grpService[0] == $ruleDetail->service_name) |
|
248 | + { |
|
249 | + $foundGrpService=1; |
|
250 | + $this->view->serviceSet=$ruleDetail->service_name; |
|
251 | + } |
|
252 | + } |
|
254 | 253 | |
255 | - // Tell JS to get services when page is loaded |
|
256 | - $this->view->serviceGroupGet=true; |
|
257 | - if ($foundGrpService==0) |
|
258 | - { |
|
259 | - $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
260 | - } |
|
261 | - } |
|
254 | + // Tell JS to get services when page is loaded |
|
255 | + $this->view->serviceGroupGet=true; |
|
256 | + if ($foundGrpService==0) |
|
257 | + { |
|
258 | + $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
259 | + } |
|
260 | + } |
|
262 | 261 | } |
263 | 262 | |
264 | 263 | /** |
@@ -270,52 +269,52 @@ discard block |
||
270 | 269 | */ |
271 | 270 | private function add_create_trap_object_list(&$display, &$rule) |
272 | 271 | { |
273 | - $curObjectList=array(); |
|
274 | - $index=1; |
|
275 | - // check in display & rule for : OID(<oid>) |
|
276 | - $matches=array(); |
|
277 | - while ( preg_match('/_OID\(([\.0-9\*]+)\)/',$display,$matches) || |
|
278 | - preg_match('/_OID\(([\.0-9\*]+)\)/',$rule,$matches)) |
|
279 | - { |
|
280 | - $curOid=$matches[1]; |
|
272 | + $curObjectList=array(); |
|
273 | + $index=1; |
|
274 | + // check in display & rule for : OID(<oid>) |
|
275 | + $matches=array(); |
|
276 | + while ( preg_match('/_OID\(([\.0-9\*]+)\)/',$display,$matches) || |
|
277 | + preg_match('/_OID\(([\.0-9\*]+)\)/',$rule,$matches)) |
|
278 | + { |
|
279 | + $curOid=$matches[1]; |
|
281 | 280 | |
282 | - if ( (preg_match('/\*/',$curOid) == 0 ) |
|
283 | - && ($object=$this->getMIB()->translateOID($curOid)) != null) |
|
284 | - { |
|
285 | - array_push($curObjectList, array( |
|
286 | - $index, |
|
287 | - $curOid, |
|
288 | - $object['mib'], |
|
289 | - $object['name'], |
|
290 | - '', |
|
291 | - $object['type'], |
|
292 | - $object['type_enum'] |
|
293 | - )); |
|
294 | - } |
|
295 | - else |
|
296 | - { |
|
297 | - array_push($curObjectList, array( |
|
298 | - $index, |
|
299 | - $curOid, |
|
300 | - 'not found', |
|
301 | - 'not found', |
|
302 | - '', |
|
303 | - 'not found', |
|
304 | - 'not found' |
|
305 | - )); |
|
306 | - } |
|
307 | - $curOid = preg_replace('/\*/','\*',$curOid); |
|
308 | - $display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display); |
|
309 | - $rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule); |
|
310 | - $index++; |
|
311 | - } |
|
312 | - return $curObjectList; |
|
281 | + if ( (preg_match('/\*/',$curOid) == 0 ) |
|
282 | + && ($object=$this->getMIB()->translateOID($curOid)) != null) |
|
283 | + { |
|
284 | + array_push($curObjectList, array( |
|
285 | + $index, |
|
286 | + $curOid, |
|
287 | + $object['mib'], |
|
288 | + $object['name'], |
|
289 | + '', |
|
290 | + $object['type'], |
|
291 | + $object['type_enum'] |
|
292 | + )); |
|
293 | + } |
|
294 | + else |
|
295 | + { |
|
296 | + array_push($curObjectList, array( |
|
297 | + $index, |
|
298 | + $curOid, |
|
299 | + 'not found', |
|
300 | + 'not found', |
|
301 | + '', |
|
302 | + 'not found', |
|
303 | + 'not found' |
|
304 | + )); |
|
305 | + } |
|
306 | + $curOid = preg_replace('/\*/','\*',$curOid); |
|
307 | + $display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display); |
|
308 | + $rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule); |
|
309 | + $index++; |
|
310 | + } |
|
311 | + return $curObjectList; |
|
313 | 312 | } |
314 | 313 | |
315 | 314 | /** Add a handler |
316 | - * Get params fromid : setup from existing trap (id of trap table) |
|
317 | - * Get param ruleid : edit from existing handler (id of rule table) |
|
318 | - */ |
|
315 | + * Get params fromid : setup from existing trap (id of trap table) |
|
316 | + * Get param ruleid : edit from existing handler (id of rule table) |
|
317 | + */ |
|
319 | 318 | public function addAction() |
320 | 319 | { |
321 | 320 | $this->checkConfigPermission(); |
@@ -334,8 +333,8 @@ discard block |
||
334 | 333 | //$this->view->trapvalues=false; // Set to true to display 'value' colum in objects |
335 | 334 | |
336 | 335 | if (($trapid = $this->params->get('fromid')) !== null) { |
337 | - /********** Setup from existing trap ***************/ |
|
338 | - $this->add_from_existing($trapid); |
|
336 | + /********** Setup from existing trap ***************/ |
|
337 | + $this->add_from_existing($trapid); |
|
339 | 338 | return; |
340 | 339 | } |
341 | 340 | |
@@ -360,14 +359,14 @@ discard block |
||
360 | 359 | $this->view->warning_message=''; |
361 | 360 | if ($this->view->hostname != null) |
362 | 361 | { |
363 | - $this->view->selectGroup=false; |
|
364 | - // Check if hostname still exists |
|
365 | - $this->add_check_host_exists($ruleDetail); |
|
362 | + $this->view->selectGroup=false; |
|
363 | + // Check if hostname still exists |
|
364 | + $this->add_check_host_exists($ruleDetail); |
|
366 | 365 | } |
367 | 366 | else |
368 | 367 | { |
369 | - $this->view->selectGroup=true; |
|
370 | - $this->add_check_hostgroup_exists($ruleDetail); // Check if groupe exists |
|
368 | + $this->view->selectGroup=true; |
|
369 | + $this->add_check_hostgroup_exists($ruleDetail); // Check if groupe exists |
|
371 | 370 | } |
372 | 371 | |
373 | 372 | $this->view->mainoid=$ruleDetail->trap_oid; |
@@ -395,9 +394,9 @@ discard block |
||
395 | 394 | } |
396 | 395 | |
397 | 396 | /** Validate form and output message to user |
398 | - * @param in postdata |
|
399 | - * @return string status : OK / <Message> |
|
400 | - **/ |
|
397 | + * @param in postdata |
|
398 | + * @return string status : OK / <Message> |
|
399 | + **/ |
|
401 | 400 | protected function handlerformAction() |
402 | 401 | { |
403 | 402 | $postData=$this->getRequest()->getPost(); |
@@ -438,7 +437,7 @@ discard block |
||
438 | 437 | //$this->Module()-> |
439 | 438 | $this->_helper->json(array( |
440 | 439 | 'status'=>'OK', |
441 | - 'redirect'=>'trapdirector/handler' |
|
440 | + 'redirect'=>'trapdirector/handler' |
|
442 | 441 | |
443 | 442 | )); |
444 | 443 | } |
@@ -522,9 +521,9 @@ discard block |
||
522 | 521 | } |
523 | 522 | |
524 | 523 | /** Get trap detail by trapid. |
525 | - * @param integer $trapid : id of trap in received table |
|
526 | - * @return array (objects) |
|
527 | - */ |
|
524 | + * @param integer $trapid : id of trap in received table |
|
525 | + * @return array (objects) |
|
526 | + */ |
|
528 | 527 | protected function getTrapDetail($trapid) |
529 | 528 | { |
530 | 529 | if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id'); } |
@@ -540,14 +539,14 @@ discard block |
||
540 | 539 | } |
541 | 540 | try |
542 | 541 | { |
543 | - $query = $dbConn->select() |
|
542 | + $query = $dbConn->select() |
|
544 | 543 | ->from($this->getModuleConfig()->getTrapTableName(),$elmts) |
545 | 544 | ->where('id=?',$trapid); |
546 | 545 | $trapDetail=$dbConn->fetchRow($query); |
547 | 546 | if ( $trapDetail == null ) |
548 | 547 | { |
549 | - $trapDetail = 'NULL'; |
|
550 | - throw new Exception('No traps was found with id = '.$trapid); |
|
548 | + $trapDetail = 'NULL'; |
|
549 | + throw new Exception('No traps was found with id = '.$trapid); |
|
551 | 550 | } |
552 | 551 | } |
553 | 552 | catch (Exception $e) |
@@ -561,9 +560,9 @@ discard block |
||
561 | 560 | } |
562 | 561 | |
563 | 562 | /** Get trap objects |
564 | - * @param integer $trapid : trap id |
|
565 | - * @return array : full column in db of trap id |
|
566 | - */ |
|
563 | + * @param integer $trapid : trap id |
|
564 | + * @return array : full column in db of trap id |
|
565 | + */ |
|
567 | 566 | protected function getTrapobjects($trapid) |
568 | 567 | { |
569 | 568 | if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id'); } |
@@ -579,7 +578,7 @@ discard block |
||
579 | 578 | } |
580 | 579 | try |
581 | 580 | { |
582 | - $query = $dbConn->select() |
|
581 | + $query = $dbConn->select() |
|
583 | 582 | ->from($this->moduleConfig->getTrapDataTableName(),$data_elmts) |
584 | 583 | ->where('trap_id=?',$trapid); |
585 | 584 | $trapDetail=$dbConn->fetchAll($query); |
@@ -595,10 +594,10 @@ discard block |
||
595 | 594 | } |
596 | 595 | |
597 | 596 | /** Get rule detail by ruleid. |
598 | - * @param integer $ruleid int id of rule in rule table |
|
599 | - * @return object : column objects in db |
|
600 | - * |
|
601 | - */ |
|
597 | + * @param integer $ruleid int id of rule in rule table |
|
598 | + * @return object : column objects in db |
|
599 | + * |
|
600 | + */ |
|
602 | 601 | protected function getRuleDetail($ruleid) |
603 | 602 | { |
604 | 603 | if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id'); } |
@@ -609,7 +608,7 @@ discard block |
||
609 | 608 | // *************** Get main data |
610 | 609 | try |
611 | 610 | { |
612 | - $query = $dbConn->select() |
|
611 | + $query = $dbConn->select() |
|
613 | 612 | ->from($this->getModuleConfig()->getTrapRuleName(),$queryArray) |
614 | 613 | ->where('id=?',$ruleid); |
615 | 614 | $ruleDetail=$dbConn->fetchRow($query); |
@@ -626,7 +625,7 @@ discard block |
||
626 | 625 | } |
627 | 626 | |
628 | 627 | /** Setup tabs for rules |
629 | - */ |
|
628 | + */ |
|
630 | 629 | protected function prepareTabs() |
631 | 630 | { |
632 | 631 | return $this->getTabs()->add('status', array( |
@@ -23,16 +23,16 @@ discard block |
||
23 | 23 | $this->checkReadPermission(); |
24 | 24 | $this->prepareTabs()->activate('status'); |
25 | 25 | |
26 | - $dbConn = $this->getUIDatabase()->getDb(); |
|
26 | + $dbConn=$this->getUIDatabase()->getDb(); |
|
27 | 27 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
28 | 28 | |
29 | 29 | $this->getHandlerListTable()->setConnection($dbConn); |
30 | 30 | $this->getHandlerListTable()->setMibloader($this->getMIB()); |
31 | 31 | // Apply pagination limits |
32 | - $this->view->table=$this->applyPaginationLimits($this->getHandlerListTable(),$this->getModuleConfig()->itemListDisplay()); |
|
32 | + $this->view->table=$this->applyPaginationLimits($this->getHandlerListTable(), $this->getModuleConfig()->itemListDisplay()); |
|
33 | 33 | |
34 | 34 | // Set Filter |
35 | - $this->view->filterEditor = $this->getHandlerListTable()->getFilterEditor($this->getRequest()); |
|
35 | + $this->view->filterEditor=$this->getHandlerListTable()->getFilterEditor($this->getRequest()); |
|
36 | 36 | |
37 | 37 | //$this->displayExitError('Handler/indexAction','Not implemented'); |
38 | 38 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | public function testruleAction() |
43 | 43 | { |
44 | 44 | $this->checkReadPermission(); |
45 | - $this->getTabs()->add('get',array( |
|
45 | + $this->getTabs()->add('get', array( |
|
46 | 46 | 'active' => true, |
47 | 47 | 'label' => $this->translate('Test Rule'), |
48 | 48 | 'url' => Url::fromRequest() |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | |
52 | 52 | if ($this->params->get('rule') !== null) |
53 | 53 | { |
54 | - $this->view->rule= $this->params->get('rule'); |
|
54 | + $this->view->rule=$this->params->get('rule'); |
|
55 | 55 | } |
56 | 56 | else |
57 | 57 | { |
@@ -110,12 +110,12 @@ discard block |
||
110 | 110 | } |
111 | 111 | catch (Exception $e) |
112 | 112 | { |
113 | - $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage()); |
|
113 | + $this->displayExitError('Add handler : get host by IP/Name ', $e->getMessage()); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | |
117 | 117 | // if one unique host found -> put id text input |
118 | - if (count($hosts)==1) { |
|
118 | + if (count($hosts) == 1) { |
|
119 | 119 | $this->view->hostname=$hosts[0]->name; |
120 | 120 | //$hostid=$hosts[0]->id; |
121 | 121 | // Tell JS to get services when page is loaded |
@@ -124,9 +124,9 @@ discard block |
||
124 | 124 | } |
125 | 125 | else |
126 | 126 | { |
127 | - foreach($hosts as $key=>$val) |
|
127 | + foreach ($hosts as $key=>$val) |
|
128 | 128 | { |
129 | - array_push($this->view->hostlist,$hosts[$key]->name); |
|
129 | + array_push($this->view->hostlist, $hosts[$key]->name); |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
@@ -165,18 +165,18 @@ discard block |
||
165 | 165 | $currentObjectTypeEnum |
166 | 166 | ); |
167 | 167 | $oid_index++; |
168 | - array_push($this->view->objectList,$currentObject); |
|
168 | + array_push($this->view->objectList, $currentObject); |
|
169 | 169 | // set currrent object to null in allObjects |
170 | 170 | if (isset($allObjects[$val->oid])) |
171 | 171 | { |
172 | 172 | $allObjects[$val->oid]=null; |
173 | 173 | } |
174 | 174 | } |
175 | - if ($allObjects!=null) // in case trap doesn't have objects or is not resolved |
|
175 | + if ($allObjects != null) // in case trap doesn't have objects or is not resolved |
|
176 | 176 | { |
177 | 177 | foreach ($allObjects as $key => $val) |
178 | 178 | { |
179 | - if ($val==null) { continue; } |
|
179 | + if ($val == null) { continue; } |
|
180 | 180 | array_push($this->view->objectList, array( |
181 | 181 | $oid_index, |
182 | 182 | $key, |
@@ -204,9 +204,9 @@ discard block |
||
204 | 204 | // Check if hostname still exists |
205 | 205 | $host_get=$this->getHostByName($this->view->hostname); |
206 | 206 | |
207 | - if (count($host_get)==0) |
|
207 | + if (count($host_get) == 0) |
|
208 | 208 | { |
209 | - $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore'; |
|
209 | + $this->view->warning_message='Host '.$this->view->hostname.' doesn\'t exists anymore'; |
|
210 | 210 | $this->view->serviceGet=false; |
211 | 211 | } |
212 | 212 | else |
@@ -214,10 +214,10 @@ discard block |
||
214 | 214 | // Tell JS to get services when page is loaded |
215 | 215 | $this->view->serviceGet=true; |
216 | 216 | // get service id for form to set : |
217 | - $serviceID=$this->getServiceIDByName($this->view->hostname,$ruleDetail->service_name); |
|
218 | - if (count($serviceID) ==0) |
|
217 | + $serviceID=$this->getServiceIDByName($this->view->hostname, $ruleDetail->service_name); |
|
218 | + if (count($serviceID) == 0) |
|
219 | 219 | { |
220 | - $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
220 | + $this->view->warning_message=' Service '.$ruleDetail->service_name.' doesn\'t exists anymore'; |
|
221 | 221 | } |
222 | 222 | else |
223 | 223 | { |
@@ -234,9 +234,9 @@ discard block |
||
234 | 234 | { |
235 | 235 | // Check if groupe exists |
236 | 236 | $group_get=$this->getHostGroupByName($this->view->hostgroupname); |
237 | - if (count($group_get)==0) |
|
237 | + if (count($group_get) == 0) |
|
238 | 238 | { |
239 | - $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore'; |
|
239 | + $this->view->warning_message='HostGroup '.$this->view->hostgroupname.' doesn\'t exists anymore'; |
|
240 | 240 | $this->view->serviceGroupGet=false; |
241 | 241 | } |
242 | 242 | else |
@@ -254,9 +254,9 @@ discard block |
||
254 | 254 | |
255 | 255 | // Tell JS to get services when page is loaded |
256 | 256 | $this->view->serviceGroupGet=true; |
257 | - if ($foundGrpService==0) |
|
257 | + if ($foundGrpService == 0) |
|
258 | 258 | { |
259 | - $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
259 | + $this->view->warning_message.=' Service '.$ruleDetail->service_name.' doesn\'t exists anymore'; |
|
260 | 260 | } |
261 | 261 | } |
262 | 262 | } |
@@ -274,12 +274,12 @@ discard block |
||
274 | 274 | $index=1; |
275 | 275 | // check in display & rule for : OID(<oid>) |
276 | 276 | $matches=array(); |
277 | - while ( preg_match('/_OID\(([\.0-9\*]+)\)/',$display,$matches) || |
|
278 | - preg_match('/_OID\(([\.0-9\*]+)\)/',$rule,$matches)) |
|
277 | + while (preg_match('/_OID\(([\.0-9\*]+)\)/', $display, $matches) || |
|
278 | + preg_match('/_OID\(([\.0-9\*]+)\)/', $rule, $matches)) |
|
279 | 279 | { |
280 | 280 | $curOid=$matches[1]; |
281 | 281 | |
282 | - if ( (preg_match('/\*/',$curOid) == 0 ) |
|
282 | + if ((preg_match('/\*/', $curOid) == 0) |
|
283 | 283 | && ($object=$this->getMIB()->translateOID($curOid)) != null) |
284 | 284 | { |
285 | 285 | array_push($curObjectList, array( |
@@ -304,9 +304,9 @@ discard block |
||
304 | 304 | 'not found' |
305 | 305 | )); |
306 | 306 | } |
307 | - $curOid = preg_replace('/\*/','\*',$curOid); |
|
308 | - $display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display); |
|
309 | - $rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule); |
|
307 | + $curOid=preg_replace('/\*/', '\*', $curOid); |
|
308 | + $display=preg_replace('/_OID\('.$curOid.'\)/', '\$'.$index.'\$', $display); |
|
309 | + $rule=preg_replace('/_OID\('.$curOid.'\)/', '\$'.$index.'\$', $rule); |
|
310 | 310 | $index++; |
311 | 311 | } |
312 | 312 | return $curObjectList; |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | { |
321 | 321 | $this->checkConfigPermission(); |
322 | 322 | // set up tab |
323 | - $this->getTabs()->add('get',array( |
|
323 | + $this->getTabs()->add('get', array( |
|
324 | 324 | 'active' => true, |
325 | 325 | 'label' => $this->translate('Add handler'), |
326 | 326 | 'url' => Url::fromRequest() |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | |
334 | 334 | //$this->view->trapvalues=false; // Set to true to display 'value' colum in objects |
335 | 335 | |
336 | - if (($trapid = $this->params->get('fromid')) !== null) { |
|
336 | + if (($trapid=$this->params->get('fromid')) !== null) { |
|
337 | 337 | /********** Setup from existing trap ***************/ |
338 | 338 | $this->add_from_existing($trapid); |
339 | 339 | return; |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | $this->view->setRuleMatch=$ruleDetail->action_match; |
354 | 354 | $this->view->setRuleNoMatch=$ruleDetail->action_nomatch; |
355 | 355 | $this->view->hostgroupname=$ruleDetail->host_group_name; |
356 | - $this->view->modified=gmdate("Y-m-d\TH:i:s\Z",$ruleDetail->modified); |
|
356 | + $this->view->modified=gmdate("Y-m-d\TH:i:s\Z", $ruleDetail->modified); |
|
357 | 357 | $this->view->modifier=$ruleDetail->modifier; |
358 | 358 | |
359 | 359 | // Warning message if host/service don't exists anymore |
@@ -405,26 +405,26 @@ discard block |
||
405 | 405 | |
406 | 406 | $params=array( |
407 | 407 | // id (also db) => array('post' => post id, 'val' => default val, 'db' => send to table) |
408 | - 'hostgroup' => array('post' => 'hostgroup','db'=>false), |
|
409 | - 'db_rule' => array('post' => 'db_rule','db'=>false), |
|
410 | - 'hostid' => array('post' => 'hostid','db'=>false), |
|
411 | - 'host_name' => array('post' => 'hostname','val' => null,'db'=>true), |
|
412 | - 'host_group_name'=> array('post' => null,'val' => null,'db'=>true), |
|
413 | - 'serviceid' => array('post' => 'serviceid','db'=>false), |
|
414 | - 'service_name' => array('post' => 'serviceName','db'=>true), |
|
415 | - 'trap_oid' => array('post' => 'oid','db'=>true), |
|
416 | - 'revert_ok' => array('post' => 'revertOK','val' => 0,'db'=>true), |
|
417 | - 'display' => array('post' => 'display','val' => '','db'=>true), |
|
418 | - 'rule' => array('post' => 'rule','val' => '','db'=>true), |
|
419 | - 'action_match' => array('post' => 'ruleMatch','val' => -1,'db'=>true), |
|
420 | - 'action_nomatch'=> array('post' => 'ruleNoMatch','val' => -1,'db'=>true), |
|
421 | - 'ip4' => array('post' => null,'val' => null,'db'=>true), |
|
422 | - 'ip6' => array('post' => null,'val' => null,'db'=>true), |
|
423 | - 'action_form' => array('post' => 'action_form','db'=>false) |
|
408 | + 'hostgroup' => array('post' => 'hostgroup', 'db'=>false), |
|
409 | + 'db_rule' => array('post' => 'db_rule', 'db'=>false), |
|
410 | + 'hostid' => array('post' => 'hostid', 'db'=>false), |
|
411 | + 'host_name' => array('post' => 'hostname', 'val' => null, 'db'=>true), |
|
412 | + 'host_group_name'=> array('post' => null, 'val' => null, 'db'=>true), |
|
413 | + 'serviceid' => array('post' => 'serviceid', 'db'=>false), |
|
414 | + 'service_name' => array('post' => 'serviceName', 'db'=>true), |
|
415 | + 'trap_oid' => array('post' => 'oid', 'db'=>true), |
|
416 | + 'revert_ok' => array('post' => 'revertOK', 'val' => 0, 'db'=>true), |
|
417 | + 'display' => array('post' => 'display', 'val' => '', 'db'=>true), |
|
418 | + 'rule' => array('post' => 'rule', 'val' => '', 'db'=>true), |
|
419 | + 'action_match' => array('post' => 'ruleMatch', 'val' => -1, 'db'=>true), |
|
420 | + 'action_nomatch'=> array('post' => 'ruleNoMatch', 'val' => -1, 'db'=>true), |
|
421 | + 'ip4' => array('post' => null, 'val' => null, 'db'=>true), |
|
422 | + 'ip6' => array('post' => null, 'val' => null, 'db'=>true), |
|
423 | + 'action_form' => array('post' => 'action_form', 'db'=>false) |
|
424 | 424 | ); |
425 | 425 | |
426 | 426 | if (isset($postData[$params['action_form']['post']]) |
427 | - && $postData[$params['action_form']['post']] == 'delete' ) |
|
427 | + && $postData[$params['action_form']['post']] == 'delete') |
|
428 | 428 | { |
429 | 429 | try |
430 | 430 | { |
@@ -444,16 +444,16 @@ discard block |
||
444 | 444 | } |
445 | 445 | foreach (array_keys($params) as $key) |
446 | 446 | { |
447 | - if ($params[$key]['post']==null) continue; // data not sent in post vars |
|
448 | - if (! isset($postData[$params[$key]['post']])) |
|
447 | + if ($params[$key]['post'] == null) continue; // data not sent in post vars |
|
448 | + if (!isset($postData[$params[$key]['post']])) |
|
449 | 449 | { |
450 | 450 | // should not happen as the js checks data |
451 | - $this->_helper->json(array('status'=>'No ' . $key)); |
|
451 | + $this->_helper->json(array('status'=>'No '.$key)); |
|
452 | 452 | } |
453 | 453 | else |
454 | 454 | { |
455 | 455 | $data=$postData[$params[$key]['post']]; |
456 | - if ($data!=null && $data !="") |
|
456 | + if ($data != null && $data != "") |
|
457 | 457 | { |
458 | 458 | $params[$key]['val']=$postData[$params[$key]['post']]; |
459 | 459 | } |
@@ -462,8 +462,8 @@ discard block |
||
462 | 462 | |
463 | 463 | try |
464 | 464 | { |
465 | - $isHostGroup=($params['hostgroup']['val'] == 1)?true:false; |
|
466 | - if (! $isHostGroup ) |
|
465 | + $isHostGroup=($params['hostgroup']['val'] == 1) ?true:false; |
|
466 | + if (!$isHostGroup) |
|
467 | 467 | { // checks if selection by host |
468 | 468 | $hostAddr=$this->getHostInfoByID($params['hostid']['val']); |
469 | 469 | $params['ip4']['val']=$hostAddr->ip4; |
@@ -490,25 +490,25 @@ discard block |
||
490 | 490 | return; |
491 | 491 | } |
492 | 492 | // Put param in correct column (group_name) |
493 | - $params['host_group_name']['val'] = $params['host_name']['val']; |
|
493 | + $params['host_group_name']['val']=$params['host_name']['val']; |
|
494 | 494 | $params['host_name']['val']=null; |
495 | 495 | } |
496 | 496 | $dbparams=array(); |
497 | 497 | foreach ($params as $key=>$val) |
498 | 498 | { |
499 | - if ($val['db']==true ) |
|
499 | + if ($val['db'] == true) |
|
500 | 500 | { |
501 | - $dbparams[$key] = $val['val']; |
|
501 | + $dbparams[$key]=$val['val']; |
|
502 | 502 | } |
503 | 503 | } |
504 | 504 | // echo '<br>'; print_r($dbparams);echo '<br>'; |
505 | - if ($params['db_rule']['val'] == -1 ) |
|
505 | + if ($params['db_rule']['val'] == -1) |
|
506 | 506 | { |
507 | 507 | $ruleID=$this->addHandlerRule($dbparams); |
508 | 508 | } |
509 | 509 | else |
510 | 510 | { |
511 | - $this->updateHandlerRule($dbparams,$params['db_rule']['val']); |
|
511 | + $this->updateHandlerRule($dbparams, $params['db_rule']['val']); |
|
512 | 512 | $ruleID=$params['db_rule']['val']; |
513 | 513 | } |
514 | 514 | } |
@@ -527,10 +527,10 @@ discard block |
||
527 | 527 | */ |
528 | 528 | protected function getTrapDetail($trapid) |
529 | 529 | { |
530 | - if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id'); } |
|
530 | + if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); } |
|
531 | 531 | $queryArray=$this->getModuleConfig()->trapDetailQuery(); |
532 | 532 | |
533 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
533 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
534 | 534 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
535 | 535 | // *************** Get main data |
536 | 536 | // extract columns and titles; |
@@ -540,19 +540,19 @@ discard block |
||
540 | 540 | } |
541 | 541 | try |
542 | 542 | { |
543 | - $query = $dbConn->select() |
|
544 | - ->from($this->getModuleConfig()->getTrapTableName(),$elmts) |
|
545 | - ->where('id=?',$trapid); |
|
543 | + $query=$dbConn->select() |
|
544 | + ->from($this->getModuleConfig()->getTrapTableName(), $elmts) |
|
545 | + ->where('id=?', $trapid); |
|
546 | 546 | $trapDetail=$dbConn->fetchRow($query); |
547 | - if ( $trapDetail == null ) |
|
547 | + if ($trapDetail == null) |
|
548 | 548 | { |
549 | - $trapDetail = 'NULL'; |
|
549 | + $trapDetail='NULL'; |
|
550 | 550 | throw new Exception('No traps was found with id = '.$trapid); |
551 | 551 | } |
552 | 552 | } |
553 | 553 | catch (Exception $e) |
554 | 554 | { |
555 | - $this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage()); |
|
555 | + $this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail, true), $e->getMessage()); |
|
556 | 556 | return; |
557 | 557 | } |
558 | 558 | |
@@ -566,10 +566,10 @@ discard block |
||
566 | 566 | */ |
567 | 567 | protected function getTrapobjects($trapid) |
568 | 568 | { |
569 | - if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id'); } |
|
569 | + if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); } |
|
570 | 570 | $queryArrayData=$this->getModuleConfig()->trapDataDetailQuery(); |
571 | 571 | |
572 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
572 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
573 | 573 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
574 | 574 | // *************** Get object data |
575 | 575 | // extract columns and titles; |
@@ -579,15 +579,15 @@ discard block |
||
579 | 579 | } |
580 | 580 | try |
581 | 581 | { |
582 | - $query = $dbConn->select() |
|
583 | - ->from($this->moduleConfig->getTrapDataTableName(),$data_elmts) |
|
584 | - ->where('trap_id=?',$trapid); |
|
582 | + $query=$dbConn->select() |
|
583 | + ->from($this->moduleConfig->getTrapDataTableName(), $data_elmts) |
|
584 | + ->where('trap_id=?', $trapid); |
|
585 | 585 | $trapDetail=$dbConn->fetchAll($query); |
586 | 586 | // if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid); |
587 | 587 | } |
588 | 588 | catch (Exception $e) |
589 | 589 | { |
590 | - $this->displayExitError('Add handler : get trap data detail : ',$e->getMessage()); |
|
590 | + $this->displayExitError('Add handler : get trap data detail : ', $e->getMessage()); |
|
591 | 591 | return array(); |
592 | 592 | } |
593 | 593 | |
@@ -601,24 +601,24 @@ discard block |
||
601 | 601 | */ |
602 | 602 | protected function getRuleDetail($ruleid) |
603 | 603 | { |
604 | - if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id'); } |
|
604 | + if (!preg_match('/^[0-9]+$/', $ruleid)) { throw new Exception('Invalid id'); } |
|
605 | 605 | $queryArray=$this->getModuleConfig()->ruleDetailQuery(); |
606 | 606 | |
607 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
607 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
608 | 608 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
609 | 609 | // *************** Get main data |
610 | 610 | try |
611 | 611 | { |
612 | - $query = $dbConn->select() |
|
613 | - ->from($this->getModuleConfig()->getTrapRuleName(),$queryArray) |
|
614 | - ->where('id=?',$ruleid); |
|
612 | + $query=$dbConn->select() |
|
613 | + ->from($this->getModuleConfig()->getTrapRuleName(), $queryArray) |
|
614 | + ->where('id=?', $ruleid); |
|
615 | 615 | $ruleDetail=$dbConn->fetchRow($query); |
616 | - if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid); |
|
616 | + if ($ruleDetail == null) throw new Exception('No rule was found with id = '.$ruleid); |
|
617 | 617 | } |
618 | 618 | catch (Exception $e) |
619 | 619 | { |
620 | - $this->displayExitError('Update handler : get rule detail',$e->getMessage()); |
|
621 | - throw new Exception('Error : ',$e->getMessage()); |
|
620 | + $this->displayExitError('Update handler : get rule detail', $e->getMessage()); |
|
621 | + throw new Exception('Error : ', $e->getMessage()); |
|
622 | 622 | } |
623 | 623 | |
624 | 624 | return $ruleDetail; |
@@ -631,7 +631,7 @@ discard block |
||
631 | 631 | { |
632 | 632 | return $this->getTabs()->add('status', array( |
633 | 633 | 'label' => $this->translate('Traps'), |
634 | - 'url' => $this->getModuleConfig()->urlPath() . '/handler') |
|
634 | + 'url' => $this->getModuleConfig()->urlPath().'/handler') |
|
635 | 635 | ); |
636 | 636 | } |
637 | 637 |
@@ -24,7 +24,9 @@ discard block |
||
24 | 24 | $this->prepareTabs()->activate('status'); |
25 | 25 | |
26 | 26 | $dbConn = $this->getUIDatabase()->getDb(); |
27 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
27 | + if ($dbConn === null) { |
|
28 | + throw new \ErrorException('uncatched db error'); |
|
29 | + } |
|
28 | 30 | |
29 | 31 | $this->getHandlerListTable()->setConnection($dbConn); |
30 | 32 | $this->getHandlerListTable()->setMibloader($this->getMIB()); |
@@ -52,8 +54,7 @@ discard block |
||
52 | 54 | if ($this->params->get('rule') !== null) |
53 | 55 | { |
54 | 56 | $this->view->rule= $this->params->get('rule'); |
55 | - } |
|
56 | - else |
|
57 | + } else |
|
57 | 58 | { |
58 | 59 | $this->view->rule=''; |
59 | 60 | } |
@@ -107,8 +108,7 @@ discard block |
||
107 | 108 | try |
108 | 109 | { |
109 | 110 | $hosts=$this->getHostByIP($hostfilter); |
110 | - } |
|
111 | - catch (Exception $e) |
|
111 | + } catch (Exception $e) |
|
112 | 112 | { |
113 | 113 | $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage()); |
114 | 114 | } |
@@ -121,8 +121,7 @@ discard block |
||
121 | 121 | // Tell JS to get services when page is loaded |
122 | 122 | $this->view->serviceGet=true; |
123 | 123 | |
124 | - } |
|
125 | - else |
|
124 | + } else |
|
126 | 125 | { |
127 | 126 | foreach($hosts as $key=>$val) |
128 | 127 | { |
@@ -172,11 +171,14 @@ discard block |
||
172 | 171 | $allObjects[$val->oid]=null; |
173 | 172 | } |
174 | 173 | } |
175 | - if ($allObjects!=null) // in case trap doesn't have objects or is not resolved |
|
174 | + if ($allObjects!=null) { |
|
175 | + // in case trap doesn't have objects or is not resolved |
|
176 | 176 | { |
177 | 177 | foreach ($allObjects as $key => $val) |
178 | 178 | { |
179 | - if ($val==null) { continue; } |
|
179 | + if ($val==null) { continue; |
|
180 | + } |
|
181 | + } |
|
180 | 182 | array_push($this->view->objectList, array( |
181 | 183 | $oid_index, |
182 | 184 | $key, |
@@ -208,8 +210,7 @@ discard block |
||
208 | 210 | { |
209 | 211 | $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore'; |
210 | 212 | $this->view->serviceGet=false; |
211 | - } |
|
212 | - else |
|
213 | + } else |
|
213 | 214 | { |
214 | 215 | // Tell JS to get services when page is loaded |
215 | 216 | $this->view->serviceGet=true; |
@@ -218,8 +219,7 @@ discard block |
||
218 | 219 | if (count($serviceID) ==0) |
219 | 220 | { |
220 | 221 | $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
221 | - } |
|
222 | - else |
|
222 | + } else |
|
223 | 223 | { |
224 | 224 | $this->view->serviceSet=$serviceID[0]->id; |
225 | 225 | } |
@@ -238,8 +238,7 @@ discard block |
||
238 | 238 | { |
239 | 239 | $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore'; |
240 | 240 | $this->view->serviceGroupGet=false; |
241 | - } |
|
242 | - else |
|
241 | + } else |
|
243 | 242 | { |
244 | 243 | $grpServices=$this->getServicesByHostGroupid($group_get[0]->id); |
245 | 244 | $foundGrpService=0; |
@@ -291,8 +290,7 @@ discard block |
||
291 | 290 | $object['type'], |
292 | 291 | $object['type_enum'] |
293 | 292 | )); |
294 | - } |
|
295 | - else |
|
293 | + } else |
|
296 | 294 | { |
297 | 295 | array_push($curObjectList, array( |
298 | 296 | $index, |
@@ -363,8 +361,7 @@ discard block |
||
363 | 361 | $this->view->selectGroup=false; |
364 | 362 | // Check if hostname still exists |
365 | 363 | $this->add_check_host_exists($ruleDetail); |
366 | - } |
|
367 | - else |
|
364 | + } else |
|
368 | 365 | { |
369 | 366 | $this->view->selectGroup=true; |
370 | 367 | $this->add_check_hostgroup_exists($ruleDetail); // Check if groupe exists |
@@ -372,9 +369,11 @@ discard block |
||
372 | 369 | |
373 | 370 | $this->view->mainoid=$ruleDetail->trap_oid; |
374 | 371 | $oidName=$this->getMIB()->translateOID($ruleDetail->trap_oid); |
375 | - if ($oidName != null) // oid is found in mibs |
|
372 | + if ($oidName != null) { |
|
373 | + // oid is found in mibs |
|
376 | 374 | { |
377 | - $this->view->mib=$oidName['mib']; |
|
375 | + $this->view->mib=$oidName['mib']; |
|
376 | + } |
|
378 | 377 | $this->view->name=$oidName['name']; |
379 | 378 | $this->view->trapListForMIB=$this->getMIB() |
380 | 379 | ->getTrapList($oidName['mib']); |
@@ -429,8 +428,7 @@ discard block |
||
429 | 428 | try |
430 | 429 | { |
431 | 430 | $this->deleteRule($postData[$params['db_rule']['post']]); |
432 | - } |
|
433 | - catch (Exception $e) |
|
431 | + } catch (Exception $e) |
|
434 | 432 | { |
435 | 433 | $this->_helper->json(array('status'=>$e->getMessage())); |
436 | 434 | return; |
@@ -444,13 +442,15 @@ discard block |
||
444 | 442 | } |
445 | 443 | foreach (array_keys($params) as $key) |
446 | 444 | { |
447 | - if ($params[$key]['post']==null) continue; // data not sent in post vars |
|
445 | + if ($params[$key]['post']==null) { |
|
446 | + continue; |
|
447 | + } |
|
448 | + // data not sent in post vars |
|
448 | 449 | if (! isset($postData[$params[$key]['post']])) |
449 | 450 | { |
450 | 451 | // should not happen as the js checks data |
451 | 452 | $this->_helper->json(array('status'=>'No ' . $key)); |
452 | - } |
|
453 | - else |
|
453 | + } else |
|
454 | 454 | { |
455 | 455 | $data=$postData[$params[$key]['post']]; |
456 | 456 | if ($data!=null && $data !="") |
@@ -480,8 +480,7 @@ discard block |
||
480 | 480 | $this->_helper->json(array('status'=>"Invalid service id : Please re enter service")); |
481 | 481 | return; |
482 | 482 | } |
483 | - } |
|
484 | - else |
|
483 | + } else |
|
485 | 484 | { |
486 | 485 | $object=$this->getObjectNameByid($params['hostid']['val']); |
487 | 486 | if ($params['host_name']['val'] != $object->name1) |
@@ -505,14 +504,12 @@ discard block |
||
505 | 504 | if ($params['db_rule']['val'] == -1 ) |
506 | 505 | { |
507 | 506 | $ruleID=$this->addHandlerRule($dbparams); |
508 | - } |
|
509 | - else |
|
507 | + } else |
|
510 | 508 | { |
511 | 509 | $this->updateHandlerRule($dbparams,$params['db_rule']['val']); |
512 | 510 | $ruleID=$params['db_rule']['val']; |
513 | 511 | } |
514 | - } |
|
515 | - catch (Exception $e) |
|
512 | + } catch (Exception $e) |
|
516 | 513 | { |
517 | 514 | $this->_helper->json(array('status'=>$e->getMessage())); |
518 | 515 | return; |
@@ -531,7 +528,9 @@ discard block |
||
531 | 528 | $queryArray=$this->getModuleConfig()->trapDetailQuery(); |
532 | 529 | |
533 | 530 | $dbConn = $this->getUIDatabase()->getDbConn(); |
534 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
531 | + if ($dbConn === null) { |
|
532 | + throw new \ErrorException('uncatched db error'); |
|
533 | + } |
|
535 | 534 | // *************** Get main data |
536 | 535 | // extract columns and titles; |
537 | 536 | $elmts=NULL; |
@@ -549,8 +548,7 @@ discard block |
||
549 | 548 | $trapDetail = 'NULL'; |
550 | 549 | throw new Exception('No traps was found with id = '.$trapid); |
551 | 550 | } |
552 | - } |
|
553 | - catch (Exception $e) |
|
551 | + } catch (Exception $e) |
|
554 | 552 | { |
555 | 553 | $this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage()); |
556 | 554 | return; |
@@ -570,7 +568,9 @@ discard block |
||
570 | 568 | $queryArrayData=$this->getModuleConfig()->trapDataDetailQuery(); |
571 | 569 | |
572 | 570 | $dbConn = $this->getUIDatabase()->getDbConn(); |
573 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
571 | + if ($dbConn === null) { |
|
572 | + throw new \ErrorException('uncatched db error'); |
|
573 | + } |
|
574 | 574 | // *************** Get object data |
575 | 575 | // extract columns and titles; |
576 | 576 | $data_elmts=NULL; |
@@ -584,8 +584,7 @@ discard block |
||
584 | 584 | ->where('trap_id=?',$trapid); |
585 | 585 | $trapDetail=$dbConn->fetchAll($query); |
586 | 586 | // if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid); |
587 | - } |
|
588 | - catch (Exception $e) |
|
587 | + } catch (Exception $e) |
|
589 | 588 | { |
590 | 589 | $this->displayExitError('Add handler : get trap data detail : ',$e->getMessage()); |
591 | 590 | return array(); |
@@ -605,7 +604,9 @@ discard block |
||
605 | 604 | $queryArray=$this->getModuleConfig()->ruleDetailQuery(); |
606 | 605 | |
607 | 606 | $dbConn = $this->getUIDatabase()->getDbConn(); |
608 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
607 | + if ($dbConn === null) { |
|
608 | + throw new \ErrorException('uncatched db error'); |
|
609 | + } |
|
609 | 610 | // *************** Get main data |
610 | 611 | try |
611 | 612 | { |
@@ -613,9 +614,10 @@ discard block |
||
613 | 614 | ->from($this->getModuleConfig()->getTrapRuleName(),$queryArray) |
614 | 615 | ->where('id=?',$ruleid); |
615 | 616 | $ruleDetail=$dbConn->fetchRow($query); |
616 | - if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid); |
|
617 | - } |
|
618 | - catch (Exception $e) |
|
617 | + if ( $ruleDetail == null ) { |
|
618 | + throw new Exception('No rule was found with id = '.$ruleid); |
|
619 | + } |
|
620 | + } catch (Exception $e) |
|
619 | 621 | { |
620 | 622 | $this->displayExitError('Update handler : get rule detail',$e->getMessage()); |
621 | 623 | throw new Exception('Error : ',$e->getMessage()); |