@@ -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 | |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | { |
245 | 245 | try |
246 | 246 | { |
247 | - $this->getUIDatabase()->setDBConfigValue('db_remove_days',$days); |
|
247 | + $this->getUIDatabase()->setDBConfigValue('db_remove_days',$days); |
|
248 | 248 | } |
249 | 249 | catch (Exception $e) |
250 | 250 | { |
@@ -282,33 +282,33 @@ discard block |
||
282 | 282 | */ |
283 | 283 | public function snmpconfigAction() |
284 | 284 | { |
285 | - $postData=$this->getRequest()->getPost(); |
|
285 | + $postData=$this->getRequest()->getPost(); |
|
286 | 286 | |
287 | - $snmpUse = $this->checkPostVar($postData, 'useTrapAddr', '0|1'); |
|
287 | + $snmpUse = $this->checkPostVar($postData, 'useTrapAddr', '0|1'); |
|
288 | 288 | |
289 | - $snmpOID = $this->checkPostVar($postData, 'trapAddrOID', '^[\.0-9]+$'); |
|
289 | + $snmpOID = $this->checkPostVar($postData, 'trapAddrOID', '^[\.0-9]+$'); |
|
290 | 290 | |
291 | - try |
|
292 | - { |
|
293 | - $this->getUIDatabase()->setDBConfigValue('use_SnmpTrapAddess',$snmpUse); |
|
294 | - $this->getUIDatabase()->setDBConfigValue('SnmpTrapAddess_oid',$snmpOID); |
|
295 | - } |
|
296 | - catch (Exception $e) |
|
297 | - { |
|
298 | - $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
|
299 | - return; |
|
300 | - } |
|
301 | - $this->_helper->json(array('status'=>'OK')); |
|
302 | - return; |
|
291 | + try |
|
292 | + { |
|
293 | + $this->getUIDatabase()->setDBConfigValue('use_SnmpTrapAddess',$snmpUse); |
|
294 | + $this->getUIDatabase()->setDBConfigValue('SnmpTrapAddess_oid',$snmpOID); |
|
295 | + } |
|
296 | + catch (Exception $e) |
|
297 | + { |
|
298 | + $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
|
299 | + return; |
|
300 | + } |
|
301 | + $this->_helper->json(array('status'=>'OK')); |
|
302 | + return; |
|
303 | 303 | |
304 | 304 | } |
305 | 305 | |
306 | 306 | /** Save log output to db |
307 | - * destination=>log destination |
|
308 | - * file=>file name |
|
309 | - * level => int |
|
310 | - * return : status=>OK/Message error |
|
311 | - */ |
|
307 | + * destination=>log destination |
|
308 | + * file=>file name |
|
309 | + * level => int |
|
310 | + * return : status=>OK/Message error |
|
311 | + */ |
|
312 | 312 | public function logdestinationAction() |
313 | 313 | { |
314 | 314 | $postData=$this->getRequest()->getPost(); |
@@ -327,8 +327,8 @@ discard block |
||
327 | 327 | $fileHandler=@fopen($file,'w'); |
328 | 328 | if ($fileHandler == false) |
329 | 329 | { // File os note writabe / cannot create |
330 | - $this->_helper->json(array('status'=>'File not writable : '.$file)); |
|
331 | - return; |
|
330 | + $this->_helper->json(array('status'=>'File not writable : '.$file)); |
|
331 | + return; |
|
332 | 332 | } |
333 | 333 | } |
334 | 334 | else |
@@ -348,9 +348,9 @@ discard block |
||
348 | 348 | |
349 | 349 | try |
350 | 350 | { |
351 | - $this->getUIDatabase()->setDBConfigValue('log_destination',$destination); |
|
352 | - $this->getUIDatabase()->setDBConfigValue('log_file',$file); |
|
353 | - $this->getUIDatabase()->setDBConfigValue('log_level',$level); |
|
351 | + $this->getUIDatabase()->setDBConfigValue('log_destination',$destination); |
|
352 | + $this->getUIDatabase()->setDBConfigValue('log_file',$file); |
|
353 | + $this->getUIDatabase()->setDBConfigValue('log_level',$level); |
|
354 | 354 | } |
355 | 355 | catch (Exception $e) |
356 | 356 | { |
@@ -370,33 +370,33 @@ discard block |
||
370 | 370 | public function testruleAction() |
371 | 371 | { |
372 | 372 | |
373 | - $postData=$this->getRequest()->getPost(); |
|
373 | + $postData=$this->getRequest()->getPost(); |
|
374 | 374 | |
375 | - $rule = $this->checkPostVar($postData, 'rule', '.*'); |
|
375 | + $rule = $this->checkPostVar($postData, 'rule', '.*'); |
|
376 | 376 | |
377 | - $action = $this->checkPostVar($postData, 'action', 'evaluate'); |
|
377 | + $action = $this->checkPostVar($postData, 'action', 'evaluate'); |
|
378 | 378 | |
379 | - if ($action == 'evaluate') |
|
380 | - { |
|
381 | - try |
|
382 | - { |
|
383 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
384 | - $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
385 | - $trap = new Trap($icingaweb2_etc); |
|
386 | - // Cleanup spaces before eval |
|
387 | - $rule=$trap->ruleClass->eval_cleanup($rule); |
|
388 | - // Eval |
|
389 | - $item=0; |
|
390 | - $rule=$trap->ruleClass->evaluation($rule,$item); |
|
391 | - } |
|
392 | - catch (Exception $e) |
|
393 | - { |
|
394 | - $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() )); |
|
395 | - return; |
|
396 | - } |
|
397 | - $return=($rule==true)?'true':'false'; |
|
398 | - $this->_helper->json(array('status'=>'OK', 'message' => $return)); |
|
399 | - } |
|
379 | + if ($action == 'evaluate') |
|
380 | + { |
|
381 | + try |
|
382 | + { |
|
383 | + require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
384 | + $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
385 | + $trap = new Trap($icingaweb2_etc); |
|
386 | + // Cleanup spaces before eval |
|
387 | + $rule=$trap->ruleClass->eval_cleanup($rule); |
|
388 | + // Eval |
|
389 | + $item=0; |
|
390 | + $rule=$trap->ruleClass->evaluation($rule,$item); |
|
391 | + } |
|
392 | + catch (Exception $e) |
|
393 | + { |
|
394 | + $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() )); |
|
395 | + return; |
|
396 | + } |
|
397 | + $return=($rule==true)?'true':'false'; |
|
398 | + $this->_helper->json(array('status'=>'OK', 'message' => $return)); |
|
399 | + } |
|
400 | 400 | |
401 | 401 | } |
402 | 402 | |
@@ -407,35 +407,35 @@ discard block |
||
407 | 407 | */ |
408 | 408 | public function pluginAction() |
409 | 409 | { |
410 | - $postData=$this->getRequest()->getPost(); |
|
410 | + $postData=$this->getRequest()->getPost(); |
|
411 | 411 | |
412 | - $pluginName = $this->checkPostVar($postData, 'name', '.*'); |
|
412 | + $pluginName = $this->checkPostVar($postData, 'name', '.*'); |
|
413 | 413 | |
414 | - $action = $this->checkPostVar($postData, 'action', 'enable|disable'); |
|
414 | + $action = $this->checkPostVar($postData, 'action', 'enable|disable'); |
|
415 | 415 | |
416 | - try |
|
417 | - { |
|
418 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
419 | - $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
420 | - $trap = new Trap($icingaweb2_etc); |
|
421 | - // Enable plugin. |
|
422 | - $action=($action == 'enable') ? true : false; |
|
423 | - $retVal=$trap->pluginClass->enablePlugin($pluginName, $action); |
|
416 | + try |
|
417 | + { |
|
418 | + require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
419 | + $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
420 | + $trap = new Trap($icingaweb2_etc); |
|
421 | + // Enable plugin. |
|
422 | + $action=($action == 'enable') ? true : false; |
|
423 | + $retVal=$trap->pluginClass->enablePlugin($pluginName, $action); |
|
424 | 424 | |
425 | - } |
|
426 | - catch (Exception $e) |
|
427 | - { |
|
428 | - $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
429 | - return; |
|
430 | - } |
|
431 | - if ($retVal === true) |
|
432 | - { |
|
433 | - $this->_helper->json(array('status'=>'OK')); |
|
434 | - } |
|
435 | - else |
|
436 | - { |
|
437 | - $this->_helper->json(array('status'=>'Error, see logs')); |
|
438 | - } |
|
425 | + } |
|
426 | + catch (Exception $e) |
|
427 | + { |
|
428 | + $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
429 | + return; |
|
430 | + } |
|
431 | + if ($retVal === true) |
|
432 | + { |
|
433 | + $this->_helper->json(array('status'=>'OK')); |
|
434 | + } |
|
435 | + else |
|
436 | + { |
|
437 | + $this->_helper->json(array('status'=>'Error, see logs')); |
|
438 | + } |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | /** Function evaluation |
@@ -445,49 +445,49 @@ discard block |
||
445 | 445 | */ |
446 | 446 | public function functionAction() |
447 | 447 | { |
448 | - $postData=$this->getRequest()->getPost(); |
|
448 | + $postData=$this->getRequest()->getPost(); |
|
449 | 449 | |
450 | - $functionString = $this->checkPostVar($postData, 'function', '.*'); |
|
450 | + $functionString = $this->checkPostVar($postData, 'function', '.*'); |
|
451 | 451 | |
452 | - $this->checkPostVar($postData, 'action', 'evaluate'); |
|
452 | + $this->checkPostVar($postData, 'action', 'evaluate'); |
|
453 | 453 | |
454 | - // Only one action possible for now, no tests on action. |
|
455 | - try |
|
456 | - { |
|
457 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
458 | - $icingaweb2Etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
459 | - $trap = new Trap($icingaweb2Etc); |
|
460 | - // load all plugins in case tested function is not enabled. |
|
461 | - $trap->pluginClass->registerAllPlugins(false); |
|
462 | - // Clean all spaces |
|
463 | - $functionString = $trap->ruleClass->eval_cleanup($functionString); |
|
464 | - // Eval functions |
|
465 | - $result = $trap->pluginClass->evaluateFunctionString($functionString); |
|
466 | - } |
|
467 | - catch (Exception $e) |
|
468 | - { |
|
469 | - $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
470 | - return; |
|
471 | - } |
|
454 | + // Only one action possible for now, no tests on action. |
|
455 | + try |
|
456 | + { |
|
457 | + require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
458 | + $icingaweb2Etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
459 | + $trap = new Trap($icingaweb2Etc); |
|
460 | + // load all plugins in case tested function is not enabled. |
|
461 | + $trap->pluginClass->registerAllPlugins(false); |
|
462 | + // Clean all spaces |
|
463 | + $functionString = $trap->ruleClass->eval_cleanup($functionString); |
|
464 | + // Eval functions |
|
465 | + $result = $trap->pluginClass->evaluateFunctionString($functionString); |
|
466 | + } |
|
467 | + catch (Exception $e) |
|
468 | + { |
|
469 | + $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
470 | + return; |
|
471 | + } |
|
472 | 472 | |
473 | - $result = ($result === true)?'True':'False'; |
|
474 | - $this->_helper->json(array('status'=>'OK','message' => $result)); |
|
473 | + $result = ($result === true)?'True':'False'; |
|
474 | + $this->_helper->json(array('status'=>'OK','message' => $result)); |
|
475 | 475 | } |
476 | 476 | |
477 | - /************** Utilities **********************/ |
|
477 | + /************** Utilities **********************/ |
|
478 | 478 | |
479 | 479 | private function checkPostVar(array $postData,string $postVar, string $validRegexp) : string |
480 | 480 | { |
481 | - if (!isset ($postData[$postVar])) |
|
482 | - { |
|
483 | - $this->_helper->json(array('status'=>'No ' . $postVar)); |
|
484 | - return ''; |
|
485 | - } |
|
486 | - if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1) |
|
487 | - { |
|
488 | - $this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar])); |
|
489 | - return ''; |
|
490 | - } |
|
491 | - return $postData[$postVar]; |
|
481 | + if (!isset ($postData[$postVar])) |
|
482 | + { |
|
483 | + $this->_helper->json(array('status'=>'No ' . $postVar)); |
|
484 | + return ''; |
|
485 | + } |
|
486 | + if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1) |
|
487 | + { |
|
488 | + $this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar])); |
|
489 | + return ''; |
|
490 | + } |
|
491 | + return $postData[$postVar]; |
|
492 | 492 | } |
493 | 493 | } |
@@ -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->getUIDatabase()->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->getUIDatabase()->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->getUIDatabase()->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->getUIDatabase()->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->getUIDatabase()->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->getUIDatabase()->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,20 +235,20 @@ 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 | $days=intval($days); |
240 | 240 | |
241 | - $action = $this->checkPostVar($postData, 'action', 'save|execute'); |
|
241 | + $action=$this->checkPostVar($postData, 'action', 'save|execute'); |
|
242 | 242 | |
243 | 243 | if ($action == 'save') |
244 | 244 | { |
245 | 245 | try |
246 | 246 | { |
247 | - $this->getUIDatabase()->setDBConfigValue('db_remove_days',$days); |
|
247 | + $this->getUIDatabase()->setDBConfigValue('db_remove_days', $days); |
|
248 | 248 | } |
249 | 249 | catch (Exception $e) |
250 | 250 | { |
251 | - $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
|
251 | + $this->_helper->json(array('status'=>'Save error : '.$e->getMessage())); |
|
252 | 252 | return; |
253 | 253 | } |
254 | 254 | $this->_helper->json(array('status'=>'OK')); |
@@ -258,16 +258,16 @@ discard block |
||
258 | 258 | { |
259 | 259 | try |
260 | 260 | { |
261 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
261 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
262 | 262 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
263 | 263 | $debug_level=4; |
264 | - $trap = new Trap($icingaweb2_etc); |
|
265 | - $trap->setLogging($debug_level,'syslog'); |
|
264 | + $trap=new Trap($icingaweb2_etc); |
|
265 | + $trap->setLogging($debug_level, 'syslog'); |
|
266 | 266 | $trap->eraseOldTraps($days); |
267 | 267 | } |
268 | 268 | catch (Exception $e) |
269 | 269 | { |
270 | - $this->_helper->json(array('status'=>'execute error : '.$e->getMessage() )); |
|
270 | + $this->_helper->json(array('status'=>'execute error : '.$e->getMessage())); |
|
271 | 271 | return; |
272 | 272 | } |
273 | 273 | $this->_helper->json(array('status'=>'OK')); |
@@ -284,18 +284,18 @@ discard block |
||
284 | 284 | { |
285 | 285 | $postData=$this->getRequest()->getPost(); |
286 | 286 | |
287 | - $snmpUse = $this->checkPostVar($postData, 'useTrapAddr', '0|1'); |
|
287 | + $snmpUse=$this->checkPostVar($postData, 'useTrapAddr', '0|1'); |
|
288 | 288 | |
289 | - $snmpOID = $this->checkPostVar($postData, 'trapAddrOID', '^[\.0-9]+$'); |
|
289 | + $snmpOID=$this->checkPostVar($postData, 'trapAddrOID', '^[\.0-9]+$'); |
|
290 | 290 | |
291 | 291 | try |
292 | 292 | { |
293 | - $this->getUIDatabase()->setDBConfigValue('use_SnmpTrapAddess',$snmpUse); |
|
294 | - $this->getUIDatabase()->setDBConfigValue('SnmpTrapAddess_oid',$snmpOID); |
|
293 | + $this->getUIDatabase()->setDBConfigValue('use_SnmpTrapAddess', $snmpUse); |
|
294 | + $this->getUIDatabase()->setDBConfigValue('SnmpTrapAddess_oid', $snmpOID); |
|
295 | 295 | } |
296 | 296 | catch (Exception $e) |
297 | 297 | { |
298 | - $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
|
298 | + $this->_helper->json(array('status'=>'Save error : '.$e->getMessage())); |
|
299 | 299 | return; |
300 | 300 | } |
301 | 301 | $this->_helper->json(array('status'=>'OK')); |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | { |
314 | 314 | $postData=$this->getRequest()->getPost(); |
315 | 315 | |
316 | - $destination = $this->checkPostVar($postData, 'destination', '.*'); |
|
316 | + $destination=$this->checkPostVar($postData, 'destination', '.*'); |
|
317 | 317 | $logDest=$this->getModuleConfig()->getLogDestinations(); |
318 | 318 | if (!isset($logDest[$destination])) |
319 | 319 | { |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | if (isset($postData['file'])) |
325 | 325 | { |
326 | 326 | $file=$postData['file']; |
327 | - $fileHandler=@fopen($file,'w'); |
|
327 | + $fileHandler=@fopen($file, 'w'); |
|
328 | 328 | if ($fileHandler == false) |
329 | 329 | { // File os note writabe / cannot create |
330 | 330 | $this->_helper->json(array('status'=>'File not writable : '.$file)); |
@@ -344,17 +344,17 @@ discard block |
||
344 | 344 | } |
345 | 345 | } |
346 | 346 | |
347 | - $level = $this->checkPostVar($postData, 'level', '[0-9]'); |
|
347 | + $level=$this->checkPostVar($postData, 'level', '[0-9]'); |
|
348 | 348 | |
349 | 349 | try |
350 | 350 | { |
351 | - $this->getUIDatabase()->setDBConfigValue('log_destination',$destination); |
|
352 | - $this->getUIDatabase()->setDBConfigValue('log_file',$file); |
|
353 | - $this->getUIDatabase()->setDBConfigValue('log_level',$level); |
|
351 | + $this->getUIDatabase()->setDBConfigValue('log_destination', $destination); |
|
352 | + $this->getUIDatabase()->setDBConfigValue('log_file', $file); |
|
353 | + $this->getUIDatabase()->setDBConfigValue('log_level', $level); |
|
354 | 354 | } |
355 | 355 | catch (Exception $e) |
356 | 356 | { |
357 | - $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
|
357 | + $this->_helper->json(array('status'=>'Save error : '.$e->getMessage())); |
|
358 | 358 | return; |
359 | 359 | } |
360 | 360 | $this->_helper->json(array('status'=>'OK')); |
@@ -372,29 +372,29 @@ discard block |
||
372 | 372 | |
373 | 373 | $postData=$this->getRequest()->getPost(); |
374 | 374 | |
375 | - $rule = $this->checkPostVar($postData, 'rule', '.*'); |
|
375 | + $rule=$this->checkPostVar($postData, 'rule', '.*'); |
|
376 | 376 | |
377 | - $action = $this->checkPostVar($postData, 'action', 'evaluate'); |
|
377 | + $action=$this->checkPostVar($postData, 'action', 'evaluate'); |
|
378 | 378 | |
379 | 379 | if ($action == 'evaluate') |
380 | 380 | { |
381 | 381 | try |
382 | 382 | { |
383 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
383 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
384 | 384 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
385 | - $trap = new Trap($icingaweb2_etc); |
|
385 | + $trap=new Trap($icingaweb2_etc); |
|
386 | 386 | // Cleanup spaces before eval |
387 | 387 | $rule=$trap->ruleClass->eval_cleanup($rule); |
388 | 388 | // Eval |
389 | 389 | $item=0; |
390 | - $rule=$trap->ruleClass->evaluation($rule,$item); |
|
390 | + $rule=$trap->ruleClass->evaluation($rule, $item); |
|
391 | 391 | } |
392 | 392 | catch (Exception $e) |
393 | 393 | { |
394 | - $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() )); |
|
394 | + $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage())); |
|
395 | 395 | return; |
396 | 396 | } |
397 | - $return=($rule==true)?'true':'false'; |
|
397 | + $return=($rule == true) ? 'true' : 'false'; |
|
398 | 398 | $this->_helper->json(array('status'=>'OK', 'message' => $return)); |
399 | 399 | } |
400 | 400 | |
@@ -409,15 +409,15 @@ discard block |
||
409 | 409 | { |
410 | 410 | $postData=$this->getRequest()->getPost(); |
411 | 411 | |
412 | - $pluginName = $this->checkPostVar($postData, 'name', '.*'); |
|
412 | + $pluginName=$this->checkPostVar($postData, 'name', '.*'); |
|
413 | 413 | |
414 | - $action = $this->checkPostVar($postData, 'action', 'enable|disable'); |
|
414 | + $action=$this->checkPostVar($postData, 'action', 'enable|disable'); |
|
415 | 415 | |
416 | 416 | try |
417 | 417 | { |
418 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
418 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
419 | 419 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
420 | - $trap = new Trap($icingaweb2_etc); |
|
420 | + $trap=new Trap($icingaweb2_etc); |
|
421 | 421 | // Enable plugin. |
422 | 422 | $action=($action == 'enable') ? true : false; |
423 | 423 | $retVal=$trap->pluginClass->enablePlugin($pluginName, $action); |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | } |
426 | 426 | catch (Exception $e) |
427 | 427 | { |
428 | - $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
428 | + $this->_helper->json(array('status'=>'Action error : '.$e->getMessage())); |
|
429 | 429 | return; |
430 | 430 | } |
431 | 431 | if ($retVal === true) |
@@ -447,45 +447,45 @@ discard block |
||
447 | 447 | { |
448 | 448 | $postData=$this->getRequest()->getPost(); |
449 | 449 | |
450 | - $functionString = $this->checkPostVar($postData, 'function', '.*'); |
|
450 | + $functionString=$this->checkPostVar($postData, 'function', '.*'); |
|
451 | 451 | |
452 | 452 | $this->checkPostVar($postData, 'action', 'evaluate'); |
453 | 453 | |
454 | 454 | // Only one action possible for now, no tests on action. |
455 | 455 | try |
456 | 456 | { |
457 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
457 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
458 | 458 | $icingaweb2Etc=$this->Config()->get('config', 'icingaweb2_etc'); |
459 | - $trap = new Trap($icingaweb2Etc); |
|
459 | + $trap=new Trap($icingaweb2Etc); |
|
460 | 460 | // load all plugins in case tested function is not enabled. |
461 | 461 | $trap->pluginClass->registerAllPlugins(false); |
462 | 462 | // Clean all spaces |
463 | - $functionString = $trap->ruleClass->eval_cleanup($functionString); |
|
463 | + $functionString=$trap->ruleClass->eval_cleanup($functionString); |
|
464 | 464 | // Eval functions |
465 | - $result = $trap->pluginClass->evaluateFunctionString($functionString); |
|
465 | + $result=$trap->pluginClass->evaluateFunctionString($functionString); |
|
466 | 466 | } |
467 | 467 | catch (Exception $e) |
468 | 468 | { |
469 | - $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
469 | + $this->_helper->json(array('status'=>'Action error : '.$e->getMessage())); |
|
470 | 470 | return; |
471 | 471 | } |
472 | 472 | |
473 | - $result = ($result === true)?'True':'False'; |
|
474 | - $this->_helper->json(array('status'=>'OK','message' => $result)); |
|
473 | + $result=($result === true) ? 'True' : 'False'; |
|
474 | + $this->_helper->json(array('status'=>'OK', 'message' => $result)); |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | /************** Utilities **********************/ |
478 | 478 | |
479 | - private function checkPostVar(array $postData,string $postVar, string $validRegexp) : string |
|
479 | + private function checkPostVar(array $postData, string $postVar, string $validRegexp) : string |
|
480 | 480 | { |
481 | 481 | if (!isset ($postData[$postVar])) |
482 | 482 | { |
483 | - $this->_helper->json(array('status'=>'No ' . $postVar)); |
|
483 | + $this->_helper->json(array('status'=>'No '.$postVar)); |
|
484 | 484 | return ''; |
485 | 485 | } |
486 | 486 | if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1) |
487 | 487 | { |
488 | - $this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar])); |
|
488 | + $this->_helper->json(array('status'=>'Unknown '.$postVar.' value '.$postData[$postVar])); |
|
489 | 489 | return ''; |
490 | 490 | } |
491 | 491 | return $postData[$postVar]; |
@@ -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', |
@@ -245,8 +238,7 @@ discard block |
||
245 | 238 | try |
246 | 239 | { |
247 | 240 | $this->getUIDatabase()->setDBConfigValue('db_remove_days',$days); |
248 | - } |
|
249 | - catch (Exception $e) |
|
241 | + } catch (Exception $e) |
|
250 | 242 | { |
251 | 243 | $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
252 | 244 | return; |
@@ -264,8 +256,7 @@ discard block |
||
264 | 256 | $trap = new Trap($icingaweb2_etc); |
265 | 257 | $trap->setLogging($debug_level,'syslog'); |
266 | 258 | $trap->eraseOldTraps($days); |
267 | - } |
|
268 | - catch (Exception $e) |
|
259 | + } catch (Exception $e) |
|
269 | 260 | { |
270 | 261 | $this->_helper->json(array('status'=>'execute error : '.$e->getMessage() )); |
271 | 262 | return; |
@@ -292,8 +283,7 @@ discard block |
||
292 | 283 | { |
293 | 284 | $this->getUIDatabase()->setDBConfigValue('use_SnmpTrapAddess',$snmpUse); |
294 | 285 | $this->getUIDatabase()->setDBConfigValue('SnmpTrapAddess_oid',$snmpOID); |
295 | - } |
|
296 | - catch (Exception $e) |
|
286 | + } catch (Exception $e) |
|
297 | 287 | { |
298 | 288 | $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
299 | 289 | return; |
@@ -330,14 +320,12 @@ discard block |
||
330 | 320 | $this->_helper->json(array('status'=>'File not writable : '.$file)); |
331 | 321 | return; |
332 | 322 | } |
333 | - } |
|
334 | - else |
|
323 | + } else |
|
335 | 324 | { |
336 | 325 | if ($destination != 'file') |
337 | 326 | { |
338 | 327 | $file=null; |
339 | - } |
|
340 | - else |
|
328 | + } else |
|
341 | 329 | { |
342 | 330 | $this->_helper->json(array('status'=>'No file')); |
343 | 331 | return; |
@@ -351,8 +339,7 @@ discard block |
||
351 | 339 | $this->getUIDatabase()->setDBConfigValue('log_destination',$destination); |
352 | 340 | $this->getUIDatabase()->setDBConfigValue('log_file',$file); |
353 | 341 | $this->getUIDatabase()->setDBConfigValue('log_level',$level); |
354 | - } |
|
355 | - catch (Exception $e) |
|
342 | + } catch (Exception $e) |
|
356 | 343 | { |
357 | 344 | $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
358 | 345 | return; |
@@ -388,8 +375,7 @@ discard block |
||
388 | 375 | // Eval |
389 | 376 | $item=0; |
390 | 377 | $rule=$trap->ruleClass->evaluation($rule,$item); |
391 | - } |
|
392 | - catch (Exception $e) |
|
378 | + } catch (Exception $e) |
|
393 | 379 | { |
394 | 380 | $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() )); |
395 | 381 | return; |
@@ -422,8 +408,7 @@ discard block |
||
422 | 408 | $action=($action == 'enable') ? true : false; |
423 | 409 | $retVal=$trap->pluginClass->enablePlugin($pluginName, $action); |
424 | 410 | |
425 | - } |
|
426 | - catch (Exception $e) |
|
411 | + } catch (Exception $e) |
|
427 | 412 | { |
428 | 413 | $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
429 | 414 | return; |
@@ -431,8 +416,7 @@ discard block |
||
431 | 416 | if ($retVal === true) |
432 | 417 | { |
433 | 418 | $this->_helper->json(array('status'=>'OK')); |
434 | - } |
|
435 | - else |
|
419 | + } else |
|
436 | 420 | { |
437 | 421 | $this->_helper->json(array('status'=>'Error, see logs')); |
438 | 422 | } |
@@ -463,8 +447,7 @@ discard block |
||
463 | 447 | $functionString = $trap->ruleClass->eval_cleanup($functionString); |
464 | 448 | // Eval functions |
465 | 449 | $result = $trap->pluginClass->evaluateFunctionString($functionString); |
466 | - } |
|
467 | - catch (Exception $e) |
|
450 | + } catch (Exception $e) |
|
468 | 451 | { |
469 | 452 | $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
470 | 453 | return; |
@@ -17,846 +17,846 @@ discard block |
||
17 | 17 | */ |
18 | 18 | class Trap |
19 | 19 | { |
20 | - use TrapConfig; |
|
20 | + use TrapConfig; |
|
21 | 21 | |
22 | - // Configuration files and dirs |
|
23 | - /** @var string Icinga etc path */ |
|
24 | - protected $icingaweb2Etc; |
|
25 | - /** @var string $trapModuleConfig config.ini of module */ |
|
26 | - protected $trapModuleConfig; |
|
27 | - /** @var string $icingaweb2Ressources resources.ini of icingaweb2 */ |
|
28 | - protected $icingaweb2Ressources; |
|
29 | - // Options from config.ini (default values) |
|
30 | - /** @var string $snmptranslate */ |
|
31 | - protected $snmptranslate='/usr/bin/snmptranslate'; |
|
32 | - /** @var string $snmptranslate_dirs */ |
|
33 | - protected $snmptranslate_dirs='/usr/share/icingaweb2/modules/trapdirector/mibs'; |
|
34 | - /** @var string $icinga2cmd */ |
|
35 | - protected $icinga2cmd='/var/run/icinga2/cmd/icinga2.cmd'; |
|
36 | - /** @var string $dbPrefix */ |
|
37 | - protected $dbPrefix='traps_'; |
|
22 | + // Configuration files and dirs |
|
23 | + /** @var string Icinga etc path */ |
|
24 | + protected $icingaweb2Etc; |
|
25 | + /** @var string $trapModuleConfig config.ini of module */ |
|
26 | + protected $trapModuleConfig; |
|
27 | + /** @var string $icingaweb2Ressources resources.ini of icingaweb2 */ |
|
28 | + protected $icingaweb2Ressources; |
|
29 | + // Options from config.ini (default values) |
|
30 | + /** @var string $snmptranslate */ |
|
31 | + protected $snmptranslate='/usr/bin/snmptranslate'; |
|
32 | + /** @var string $snmptranslate_dirs */ |
|
33 | + protected $snmptranslate_dirs='/usr/share/icingaweb2/modules/trapdirector/mibs'; |
|
34 | + /** @var string $icinga2cmd */ |
|
35 | + protected $icinga2cmd='/var/run/icinga2/cmd/icinga2.cmd'; |
|
36 | + /** @var string $dbPrefix */ |
|
37 | + protected $dbPrefix='traps_'; |
|
38 | 38 | |
39 | - // API |
|
40 | - /** @var boolean $apiUse */ |
|
41 | - protected $apiUse=false; |
|
42 | - /** @var Icinga2API $icinga2api */ |
|
43 | - protected $icinga2api=null; |
|
44 | - /** @var string $apiHostname */ |
|
45 | - protected $apiHostname=''; |
|
46 | - /** @var integer $apiPort */ |
|
47 | - protected $apiPort=0; |
|
48 | - /** @var string $apiUsername */ |
|
49 | - protected $apiUsername=''; |
|
50 | - /** @var string $apiPassword */ |
|
51 | - protected $apiPassword=''; |
|
39 | + // API |
|
40 | + /** @var boolean $apiUse */ |
|
41 | + protected $apiUse=false; |
|
42 | + /** @var Icinga2API $icinga2api */ |
|
43 | + protected $icinga2api=null; |
|
44 | + /** @var string $apiHostname */ |
|
45 | + protected $apiHostname=''; |
|
46 | + /** @var integer $apiPort */ |
|
47 | + protected $apiPort=0; |
|
48 | + /** @var string $apiUsername */ |
|
49 | + protected $apiUsername=''; |
|
50 | + /** @var string $apiPassword */ |
|
51 | + protected $apiPassword=''; |
|
52 | 52 | |
53 | - // Logs |
|
54 | - /** @var Logging Logging class. */ |
|
55 | - public $logging; //< Logging class. |
|
56 | - /** @var bool true if log was setup in constructor */ |
|
57 | - protected $logSetup; //< bool true if log was setup in constructor |
|
53 | + // Logs |
|
54 | + /** @var Logging Logging class. */ |
|
55 | + public $logging; //< Logging class. |
|
56 | + /** @var bool true if log was setup in constructor */ |
|
57 | + protected $logSetup; //< bool true if log was setup in constructor |
|
58 | 58 | |
59 | - // Databases |
|
60 | - /** @var Database $trapsDB Database class*/ |
|
61 | - public $trapsDB = null; |
|
59 | + // Databases |
|
60 | + /** @var Database $trapsDB Database class*/ |
|
61 | + public $trapsDB = null; |
|
62 | 62 | |
63 | - // Trap received data |
|
64 | - protected $receivingHost; |
|
65 | - /** @var array Main trap data (oid, source...) */ |
|
66 | - public $trapData=array(); |
|
67 | - /** @var array $trapDataExt Additional trap data objects (oid/value).*/ |
|
68 | - public $trapDataExt=array(); |
|
69 | - /** @var int $trapId trap_id after sql insert*/ |
|
70 | - public $trapId=null; |
|
71 | - /** @var string $trapAction trap action for final write*/ |
|
72 | - public $trapAction=null; |
|
73 | - /** @var boolean $trapToDb log trap to DB */ |
|
74 | - protected $trapToDb=true; |
|
63 | + // Trap received data |
|
64 | + protected $receivingHost; |
|
65 | + /** @var array Main trap data (oid, source...) */ |
|
66 | + public $trapData=array(); |
|
67 | + /** @var array $trapDataExt Additional trap data objects (oid/value).*/ |
|
68 | + public $trapDataExt=array(); |
|
69 | + /** @var int $trapId trap_id after sql insert*/ |
|
70 | + public $trapId=null; |
|
71 | + /** @var string $trapAction trap action for final write*/ |
|
72 | + public $trapAction=null; |
|
73 | + /** @var boolean $trapToDb log trap to DB */ |
|
74 | + protected $trapToDb=true; |
|
75 | 75 | |
76 | - /** @var Mib mib class */ |
|
77 | - public $mibClass = null; |
|
76 | + /** @var Mib mib class */ |
|
77 | + public $mibClass = null; |
|
78 | 78 | |
79 | - /** @var Rule rule class */ |
|
80 | - public $ruleClass = null; |
|
79 | + /** @var Rule rule class */ |
|
80 | + public $ruleClass = null; |
|
81 | 81 | |
82 | - /** @var Plugins plugins manager **/ |
|
83 | - public $pluginClass = null; |
|
82 | + /** @var Plugins plugins manager **/ |
|
83 | + public $pluginClass = null; |
|
84 | 84 | |
85 | - /** @var TrapApi $trapApiClass */ |
|
86 | - public $trapApiClass = null; |
|
85 | + /** @var TrapApi $trapApiClass */ |
|
86 | + public $trapApiClass = null; |
|
87 | 87 | |
88 | - function __construct($etcDir='/etc/icingaweb2',$baseLogLevel=null,$baseLogMode='syslog',$baseLogFile='') |
|
89 | - { |
|
90 | - // Paths of ini files |
|
91 | - $this->icingaweb2Etc=$etcDir; |
|
92 | - $this->trapModuleConfig=$this->icingaweb2Etc."/modules/trapdirector/config.ini"; |
|
93 | - $this->icingaweb2Ressources=$this->icingaweb2Etc."/resources.ini"; |
|
88 | + function __construct($etcDir='/etc/icingaweb2',$baseLogLevel=null,$baseLogMode='syslog',$baseLogFile='') |
|
89 | + { |
|
90 | + // Paths of ini files |
|
91 | + $this->icingaweb2Etc=$etcDir; |
|
92 | + $this->trapModuleConfig=$this->icingaweb2Etc."/modules/trapdirector/config.ini"; |
|
93 | + $this->icingaweb2Ressources=$this->icingaweb2Etc."/resources.ini"; |
|
94 | 94 | |
95 | - //************* Setup logging |
|
96 | - $this->logging = new Logging(); |
|
97 | - if ($baseLogLevel != null) |
|
98 | - { |
|
99 | - $this->logging->setLogging($baseLogLevel, $baseLogMode,$baseLogFile); |
|
100 | - $this->logSetup=true; |
|
101 | - } |
|
102 | - else |
|
103 | - { |
|
104 | - $this->logSetup=false; |
|
105 | - } |
|
106 | - $this->logging->log('Loggin started', INFO); |
|
107 | - |
|
108 | - |
|
109 | - // Create distributed API object |
|
110 | - |
|
111 | - $this->trapApiClass = new TrapApi($this->logging); |
|
112 | - |
|
113 | - //*************** Get options from ini files |
|
114 | - if (! is_file($this->trapModuleConfig)) |
|
115 | - { |
|
116 | - throw new Exception("Ini file ".$this->trapModuleConfig." does not exists"); |
|
117 | - } |
|
118 | - $trapConfig=parse_ini_file($this->trapModuleConfig,true); |
|
119 | - if ($trapConfig == false) |
|
120 | - { |
|
121 | - $this->logging->log("Error reading ini file : ".$this->trapModuleConfig,ERROR,'syslog'); |
|
122 | - throw new Exception("Error reading ini file : ".$this->trapModuleConfig); |
|
123 | - } |
|
124 | - $this->getMainOptions($trapConfig); // Get main options from ini file |
|
125 | - |
|
126 | - //*************** Setup database class & get options |
|
127 | - $this->setupDatabase($trapConfig); |
|
128 | - |
|
129 | - $this->getDatabaseOptions(); // Get options in database |
|
130 | - |
|
131 | - //*************** Setup API |
|
132 | - if ($this->apiUse === true) $this->getAPI(); // Setup API |
|
133 | - |
|
134 | - //*************** Setup MIB |
|
135 | - $this->mibClass = new Mib($this->logging,$this->trapsDB,$this->snmptranslate,$this->snmptranslate_dirs); // Create Mib class |
|
136 | - |
|
137 | - //*************** Setup Rule |
|
138 | - $this->ruleClass = new Rule($this); //< Create Rule class |
|
139 | - |
|
140 | - $this->trapData=array( // TODO : put this in a reset function (DAEMON_MODE) |
|
141 | - 'source_ip' => 'unknown', |
|
142 | - 'source_port' => 'unknown', |
|
143 | - 'destination_ip' => 'unknown', |
|
144 | - 'destination_port' => 'unknown', |
|
145 | - 'trap_oid' => 'unknown' |
|
146 | - ); |
|
147 | - |
|
148 | - //*************** Setup Plugins |
|
149 | - //Create plugin class. Plugins are not loaded here, but by calling registerAllPlugins |
|
150 | - $this->pluginClass = new Plugins($this); |
|
95 | + //************* Setup logging |
|
96 | + $this->logging = new Logging(); |
|
97 | + if ($baseLogLevel != null) |
|
98 | + { |
|
99 | + $this->logging->setLogging($baseLogLevel, $baseLogMode,$baseLogFile); |
|
100 | + $this->logSetup=true; |
|
101 | + } |
|
102 | + else |
|
103 | + { |
|
104 | + $this->logSetup=false; |
|
105 | + } |
|
106 | + $this->logging->log('Loggin started', INFO); |
|
107 | + |
|
108 | + |
|
109 | + // Create distributed API object |
|
110 | + |
|
111 | + $this->trapApiClass = new TrapApi($this->logging); |
|
112 | + |
|
113 | + //*************** Get options from ini files |
|
114 | + if (! is_file($this->trapModuleConfig)) |
|
115 | + { |
|
116 | + throw new Exception("Ini file ".$this->trapModuleConfig." does not exists"); |
|
117 | + } |
|
118 | + $trapConfig=parse_ini_file($this->trapModuleConfig,true); |
|
119 | + if ($trapConfig == false) |
|
120 | + { |
|
121 | + $this->logging->log("Error reading ini file : ".$this->trapModuleConfig,ERROR,'syslog'); |
|
122 | + throw new Exception("Error reading ini file : ".$this->trapModuleConfig); |
|
123 | + } |
|
124 | + $this->getMainOptions($trapConfig); // Get main options from ini file |
|
125 | + |
|
126 | + //*************** Setup database class & get options |
|
127 | + $this->setupDatabase($trapConfig); |
|
128 | + |
|
129 | + $this->getDatabaseOptions(); // Get options in database |
|
130 | + |
|
131 | + //*************** Setup API |
|
132 | + if ($this->apiUse === true) $this->getAPI(); // Setup API |
|
133 | + |
|
134 | + //*************** Setup MIB |
|
135 | + $this->mibClass = new Mib($this->logging,$this->trapsDB,$this->snmptranslate,$this->snmptranslate_dirs); // Create Mib class |
|
136 | + |
|
137 | + //*************** Setup Rule |
|
138 | + $this->ruleClass = new Rule($this); //< Create Rule class |
|
139 | + |
|
140 | + $this->trapData=array( // TODO : put this in a reset function (DAEMON_MODE) |
|
141 | + 'source_ip' => 'unknown', |
|
142 | + 'source_port' => 'unknown', |
|
143 | + 'destination_ip' => 'unknown', |
|
144 | + 'destination_port' => 'unknown', |
|
145 | + 'trap_oid' => 'unknown' |
|
146 | + ); |
|
147 | + |
|
148 | + //*************** Setup Plugins |
|
149 | + //Create plugin class. Plugins are not loaded here, but by calling registerAllPlugins |
|
150 | + $this->pluginClass = new Plugins($this); |
|
151 | 151 | |
152 | 152 | |
153 | - } |
|
153 | + } |
|
154 | 154 | |
155 | - /** @return \Trapdirector\Logging */ |
|
156 | - public function getLogging() |
|
157 | - { |
|
158 | - return $this->logging; |
|
159 | - } |
|
155 | + /** @return \Trapdirector\Logging */ |
|
156 | + public function getLogging() |
|
157 | + { |
|
158 | + return $this->logging; |
|
159 | + } |
|
160 | 160 | |
161 | - /** @return \Trapdirector\TrapApi */ |
|
162 | - public function getTrapApi() |
|
163 | - { |
|
164 | - return $this->trapApiClass; |
|
165 | - } |
|
161 | + /** @return \Trapdirector\TrapApi */ |
|
162 | + public function getTrapApi() |
|
163 | + { |
|
164 | + return $this->trapApiClass; |
|
165 | + } |
|
166 | 166 | |
167 | - /** @return \Trapdirector\Database */ |
|
168 | - public function getTrapsDB() |
|
169 | - { |
|
170 | - return $this->trapsDB; |
|
171 | - } |
|
167 | + /** @return \Trapdirector\Database */ |
|
168 | + public function getTrapsDB() |
|
169 | + { |
|
170 | + return $this->trapsDB; |
|
171 | + } |
|
172 | 172 | |
173 | - /** OBSOLETE Send log. Throws exception on critical error |
|
174 | - * @param string $message Message to log |
|
175 | - * @param int $level 1=critical 2=warning 3=trace 4=debug |
|
176 | - * @param string $destination file/syslog/display |
|
177 | - * @return void |
|
178 | - **/ |
|
179 | - public function trapLog( $message, $level, $destination ='') // OBSOLETE |
|
180 | - { |
|
181 | - // TODO : replace ref with $this->logging->log |
|
182 | - $this->logging->log($message, $level, $destination); |
|
183 | - } |
|
173 | + /** OBSOLETE Send log. Throws exception on critical error |
|
174 | + * @param string $message Message to log |
|
175 | + * @param int $level 1=critical 2=warning 3=trace 4=debug |
|
176 | + * @param string $destination file/syslog/display |
|
177 | + * @return void |
|
178 | + **/ |
|
179 | + public function trapLog( $message, $level, $destination ='') // OBSOLETE |
|
180 | + { |
|
181 | + // TODO : replace ref with $this->logging->log |
|
182 | + $this->logging->log($message, $level, $destination); |
|
183 | + } |
|
184 | 184 | |
185 | - public function setLogging($debugLvl,$outputType,$outputOption=null) // OBSOLETE |
|
186 | - { |
|
187 | - $this->logging->setLogging($debugLvl, $outputType,$outputOption); |
|
188 | - } |
|
185 | + public function setLogging($debugLvl,$outputType,$outputOption=null) // OBSOLETE |
|
186 | + { |
|
187 | + $this->logging->setLogging($debugLvl, $outputType,$outputOption); |
|
188 | + } |
|
189 | 189 | |
190 | - /** |
|
191 | - * Returns or create new IcingaAPI object |
|
192 | - * @return \Icinga\Module\Trapdirector\Icinga2API |
|
193 | - */ |
|
194 | - protected function getAPI() |
|
195 | - { |
|
196 | - if ($this->icinga2api == null) |
|
197 | - { |
|
198 | - $this->icinga2api = new Icinga2API($this->apiHostname,$this->apiPort); |
|
199 | - } |
|
200 | - return $this->icinga2api; |
|
201 | - } |
|
190 | + /** |
|
191 | + * Returns or create new IcingaAPI object |
|
192 | + * @return \Icinga\Module\Trapdirector\Icinga2API |
|
193 | + */ |
|
194 | + protected function getAPI() |
|
195 | + { |
|
196 | + if ($this->icinga2api == null) |
|
197 | + { |
|
198 | + $this->icinga2api = new Icinga2API($this->apiHostname,$this->apiPort); |
|
199 | + } |
|
200 | + return $this->icinga2api; |
|
201 | + } |
|
202 | 202 | |
203 | 203 | |
204 | - /** |
|
205 | - * read data from stream |
|
206 | - * @param $stream string input stream, defaults to "php://stdin" |
|
207 | - * @return mixed array trap data or exception with error |
|
208 | - */ |
|
209 | - public function read_trap($stream='php://stdin') |
|
210 | - { |
|
211 | - //Read data from snmptrapd from stdin |
|
212 | - $input_stream=fopen($stream, 'r'); |
|
213 | - |
|
214 | - if ($input_stream === false) |
|
215 | - { |
|
216 | - $this->writeTrapErrorToDB("Error reading trap (code 1/Stdin)"); |
|
217 | - $this->logging->log("Error reading stdin !",ERROR,''); |
|
218 | - return null; // note : exception thrown by logging |
|
219 | - } |
|
220 | - |
|
221 | - // line 1 : host |
|
222 | - $this->receivingHost=chop(fgets($input_stream)); |
|
223 | - if ($this->receivingHost === false) |
|
224 | - { |
|
225 | - $this->writeTrapErrorToDB("Error reading trap (code 1/Line Host)"); |
|
226 | - $this->logging->log("Error reading Host !",ERROR,''); |
|
227 | - } |
|
228 | - // line 2 IP:port=>IP:port |
|
229 | - $IP=chop(fgets($input_stream)); |
|
230 | - if ($IP === false) |
|
231 | - { |
|
232 | - $this->writeTrapErrorToDB("Error reading trap (code 1/Line IP)"); |
|
233 | - $this->logging->log("Error reading IP !",ERROR,''); |
|
234 | - } |
|
235 | - $matches=array(); |
|
236 | - $ret_code=preg_match('/.DP: \[(.*)\]:(.*)->\[(.*)\]:(.*)/',$IP,$matches); |
|
237 | - if ($ret_code===0 || $ret_code===false) |
|
238 | - { |
|
239 | - $this->writeTrapErrorToDB("Error parsing trap (code 2/IP)"); |
|
240 | - $this->logging->log('Error parsing IP : '.$IP,ERROR,''); |
|
241 | - } |
|
242 | - else |
|
243 | - { |
|
244 | - $this->trapData['source_ip']=$matches[1]; |
|
245 | - $this->trapData['destination_ip']=$matches[3]; |
|
246 | - $this->trapData['source_port']=$matches[2]; |
|
247 | - $this->trapData['destination_port']=$matches[4]; |
|
248 | - } |
|
249 | - |
|
250 | - while (($vars=fgets($input_stream)) !==false) |
|
251 | - { |
|
252 | - $vars=chop($vars); |
|
253 | - $ret_code=preg_match('/^([^ ]+) (.*)$/',$vars,$matches); |
|
254 | - if ($ret_code===0 || $ret_code===false) |
|
255 | - { |
|
256 | - $this->logging->log('No match on trap data : '.$vars,WARN,''); |
|
257 | - continue; |
|
258 | - } |
|
259 | - if (($matches[1]=='.1.3.6.1.6.3.1.1.4.1.0') || ($matches[1]=='.1.3.6.1.6.3.1.1.4.1')) |
|
260 | - { |
|
261 | - $this->trapData['trap_oid']=$matches[2]; |
|
262 | - continue; |
|
263 | - } |
|
264 | - if ( $this->useSnmpTrapAddess === TRUE && preg_match('/'.$this->snmpTrapAddressOID.'/', $matches[1]) == 1) |
|
265 | - { |
|
266 | - $this->logging->log('Found relayed trap from ' . $matches[2] . ' relayed by ' .$this->trapData['source_ip'],DEBUG); |
|
267 | - if (preg_match('/^[0-9\.]+$/',$matches[2]) == 0 && preg_match('/^[0-9a-fA-F:]+$/',$matches[2]) == 0) |
|
268 | - { |
|
269 | - $this->logging->log('Value of SnmpTrapAddess ('.$this->snmpTrapAddressOID.') is not IP : ' .$matches[2],WARN,''); |
|
270 | - continue; |
|
271 | - } |
|
272 | - $this->trapData['source_ip'] = $matches[2]; |
|
273 | - continue; |
|
274 | - } |
|
275 | - $object= new stdClass; |
|
276 | - $object->oid =$matches[1]; |
|
277 | - $object->value = $matches[2]; |
|
278 | - array_push($this->trapDataExt,$object); |
|
279 | - } |
|
280 | - |
|
281 | - if ($this->trapData['trap_oid']=='unknown') |
|
282 | - { |
|
283 | - $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)",$this->trapData['source_ip']); |
|
284 | - $this->logging->log('no trap oid found',ERROR,''); |
|
285 | - } |
|
286 | - |
|
287 | - // Translate oids. |
|
288 | - |
|
289 | - $retArray=$this->translateOID($this->trapData['trap_oid']); |
|
290 | - if ($retArray != null) |
|
291 | - { |
|
292 | - $this->trapData['trap_name']=$retArray['trap_name']; |
|
293 | - $this->trapData['trap_name_mib']=$retArray['trap_name_mib']; |
|
294 | - } |
|
295 | - foreach ($this->trapDataExt as $key => $val) |
|
296 | - { |
|
297 | - $retArray=$this->translateOID($val->oid); |
|
298 | - if ($retArray != null) |
|
299 | - { |
|
300 | - $this->trapDataExt[$key]->oid_name=$retArray['trap_name']; |
|
301 | - $this->trapDataExt[$key]->oid_name_mib=$retArray['trap_name_mib']; |
|
302 | - } |
|
303 | - } |
|
304 | - |
|
305 | - |
|
306 | - $this->trapData['status']= 'waiting'; |
|
307 | - |
|
308 | - return $this->trapData; |
|
309 | - } |
|
204 | + /** |
|
205 | + * read data from stream |
|
206 | + * @param $stream string input stream, defaults to "php://stdin" |
|
207 | + * @return mixed array trap data or exception with error |
|
208 | + */ |
|
209 | + public function read_trap($stream='php://stdin') |
|
210 | + { |
|
211 | + //Read data from snmptrapd from stdin |
|
212 | + $input_stream=fopen($stream, 'r'); |
|
213 | + |
|
214 | + if ($input_stream === false) |
|
215 | + { |
|
216 | + $this->writeTrapErrorToDB("Error reading trap (code 1/Stdin)"); |
|
217 | + $this->logging->log("Error reading stdin !",ERROR,''); |
|
218 | + return null; // note : exception thrown by logging |
|
219 | + } |
|
220 | + |
|
221 | + // line 1 : host |
|
222 | + $this->receivingHost=chop(fgets($input_stream)); |
|
223 | + if ($this->receivingHost === false) |
|
224 | + { |
|
225 | + $this->writeTrapErrorToDB("Error reading trap (code 1/Line Host)"); |
|
226 | + $this->logging->log("Error reading Host !",ERROR,''); |
|
227 | + } |
|
228 | + // line 2 IP:port=>IP:port |
|
229 | + $IP=chop(fgets($input_stream)); |
|
230 | + if ($IP === false) |
|
231 | + { |
|
232 | + $this->writeTrapErrorToDB("Error reading trap (code 1/Line IP)"); |
|
233 | + $this->logging->log("Error reading IP !",ERROR,''); |
|
234 | + } |
|
235 | + $matches=array(); |
|
236 | + $ret_code=preg_match('/.DP: \[(.*)\]:(.*)->\[(.*)\]:(.*)/',$IP,$matches); |
|
237 | + if ($ret_code===0 || $ret_code===false) |
|
238 | + { |
|
239 | + $this->writeTrapErrorToDB("Error parsing trap (code 2/IP)"); |
|
240 | + $this->logging->log('Error parsing IP : '.$IP,ERROR,''); |
|
241 | + } |
|
242 | + else |
|
243 | + { |
|
244 | + $this->trapData['source_ip']=$matches[1]; |
|
245 | + $this->trapData['destination_ip']=$matches[3]; |
|
246 | + $this->trapData['source_port']=$matches[2]; |
|
247 | + $this->trapData['destination_port']=$matches[4]; |
|
248 | + } |
|
249 | + |
|
250 | + while (($vars=fgets($input_stream)) !==false) |
|
251 | + { |
|
252 | + $vars=chop($vars); |
|
253 | + $ret_code=preg_match('/^([^ ]+) (.*)$/',$vars,$matches); |
|
254 | + if ($ret_code===0 || $ret_code===false) |
|
255 | + { |
|
256 | + $this->logging->log('No match on trap data : '.$vars,WARN,''); |
|
257 | + continue; |
|
258 | + } |
|
259 | + if (($matches[1]=='.1.3.6.1.6.3.1.1.4.1.0') || ($matches[1]=='.1.3.6.1.6.3.1.1.4.1')) |
|
260 | + { |
|
261 | + $this->trapData['trap_oid']=$matches[2]; |
|
262 | + continue; |
|
263 | + } |
|
264 | + if ( $this->useSnmpTrapAddess === TRUE && preg_match('/'.$this->snmpTrapAddressOID.'/', $matches[1]) == 1) |
|
265 | + { |
|
266 | + $this->logging->log('Found relayed trap from ' . $matches[2] . ' relayed by ' .$this->trapData['source_ip'],DEBUG); |
|
267 | + if (preg_match('/^[0-9\.]+$/',$matches[2]) == 0 && preg_match('/^[0-9a-fA-F:]+$/',$matches[2]) == 0) |
|
268 | + { |
|
269 | + $this->logging->log('Value of SnmpTrapAddess ('.$this->snmpTrapAddressOID.') is not IP : ' .$matches[2],WARN,''); |
|
270 | + continue; |
|
271 | + } |
|
272 | + $this->trapData['source_ip'] = $matches[2]; |
|
273 | + continue; |
|
274 | + } |
|
275 | + $object= new stdClass; |
|
276 | + $object->oid =$matches[1]; |
|
277 | + $object->value = $matches[2]; |
|
278 | + array_push($this->trapDataExt,$object); |
|
279 | + } |
|
280 | + |
|
281 | + if ($this->trapData['trap_oid']=='unknown') |
|
282 | + { |
|
283 | + $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)",$this->trapData['source_ip']); |
|
284 | + $this->logging->log('no trap oid found',ERROR,''); |
|
285 | + } |
|
286 | + |
|
287 | + // Translate oids. |
|
288 | + |
|
289 | + $retArray=$this->translateOID($this->trapData['trap_oid']); |
|
290 | + if ($retArray != null) |
|
291 | + { |
|
292 | + $this->trapData['trap_name']=$retArray['trap_name']; |
|
293 | + $this->trapData['trap_name_mib']=$retArray['trap_name_mib']; |
|
294 | + } |
|
295 | + foreach ($this->trapDataExt as $key => $val) |
|
296 | + { |
|
297 | + $retArray=$this->translateOID($val->oid); |
|
298 | + if ($retArray != null) |
|
299 | + { |
|
300 | + $this->trapDataExt[$key]->oid_name=$retArray['trap_name']; |
|
301 | + $this->trapDataExt[$key]->oid_name_mib=$retArray['trap_name_mib']; |
|
302 | + } |
|
303 | + } |
|
304 | + |
|
305 | + |
|
306 | + $this->trapData['status']= 'waiting'; |
|
307 | + |
|
308 | + return $this->trapData; |
|
309 | + } |
|
310 | 310 | |
311 | - /** |
|
312 | - * Translate oid into array(MIB,Name) |
|
313 | - * @param $oid string oid to translate |
|
314 | - * @return mixed : null if not found or array(MIB,Name) |
|
315 | - */ |
|
316 | - public function translateOID($oid) |
|
317 | - { |
|
318 | - // try from database |
|
319 | - $db_conn=$this->trapsDB->db_connect_trap(); |
|
320 | - |
|
321 | - $sql='SELECT mib,name from '.$this->dbPrefix.'mib_cache WHERE oid=\''.$oid.'\';'; |
|
322 | - $this->logging->log('SQL query : '.$sql,DEBUG ); |
|
323 | - if (($ret_code=$db_conn->query($sql)) === false) { |
|
324 | - $this->logging->log('No result in query : ' . $sql,ERROR,''); |
|
325 | - } |
|
326 | - $name=$ret_code->fetch(); |
|
327 | - if ($name['name'] != null) |
|
328 | - { |
|
329 | - return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']); |
|
330 | - } |
|
331 | - |
|
332 | - // Also check if it is an instance of OID |
|
333 | - $oid_instance=preg_replace('/\.[0-9]+$/','',$oid); |
|
334 | - |
|
335 | - $sql='SELECT mib,name from '.$this->dbPrefix.'mib_cache WHERE oid=\''.$oid_instance.'\';'; |
|
336 | - $this->logging->log('SQL query : '.$sql,DEBUG ); |
|
337 | - if (($ret_code=$db_conn->query($sql)) === false) { |
|
338 | - $this->logging->log('No result in query : ' . $sql,ERROR,''); |
|
339 | - } |
|
340 | - $name=$ret_code->fetch(); |
|
341 | - if ($name['name'] != null) |
|
342 | - { |
|
343 | - return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']); |
|
344 | - } |
|
345 | - |
|
346 | - // Try to get oid name from snmptranslate |
|
347 | - $translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs. |
|
348 | - ' '.$oid); |
|
349 | - $matches=array(); |
|
350 | - $ret_code=preg_match('/(.*)::(.*)/',$translate,$matches); |
|
351 | - if ($ret_code===0 || $ret_code === false) { |
|
352 | - return NULL; |
|
353 | - } else { |
|
354 | - $this->logging->log('Found name with snmptrapd and not in DB for oid='.$oid,INFO); |
|
355 | - return array('trap_name_mib'=>$matches[1],'trap_name'=>$matches[2]); |
|
356 | - } |
|
357 | - } |
|
311 | + /** |
|
312 | + * Translate oid into array(MIB,Name) |
|
313 | + * @param $oid string oid to translate |
|
314 | + * @return mixed : null if not found or array(MIB,Name) |
|
315 | + */ |
|
316 | + public function translateOID($oid) |
|
317 | + { |
|
318 | + // try from database |
|
319 | + $db_conn=$this->trapsDB->db_connect_trap(); |
|
320 | + |
|
321 | + $sql='SELECT mib,name from '.$this->dbPrefix.'mib_cache WHERE oid=\''.$oid.'\';'; |
|
322 | + $this->logging->log('SQL query : '.$sql,DEBUG ); |
|
323 | + if (($ret_code=$db_conn->query($sql)) === false) { |
|
324 | + $this->logging->log('No result in query : ' . $sql,ERROR,''); |
|
325 | + } |
|
326 | + $name=$ret_code->fetch(); |
|
327 | + if ($name['name'] != null) |
|
328 | + { |
|
329 | + return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']); |
|
330 | + } |
|
331 | + |
|
332 | + // Also check if it is an instance of OID |
|
333 | + $oid_instance=preg_replace('/\.[0-9]+$/','',$oid); |
|
334 | + |
|
335 | + $sql='SELECT mib,name from '.$this->dbPrefix.'mib_cache WHERE oid=\''.$oid_instance.'\';'; |
|
336 | + $this->logging->log('SQL query : '.$sql,DEBUG ); |
|
337 | + if (($ret_code=$db_conn->query($sql)) === false) { |
|
338 | + $this->logging->log('No result in query : ' . $sql,ERROR,''); |
|
339 | + } |
|
340 | + $name=$ret_code->fetch(); |
|
341 | + if ($name['name'] != null) |
|
342 | + { |
|
343 | + return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']); |
|
344 | + } |
|
345 | + |
|
346 | + // Try to get oid name from snmptranslate |
|
347 | + $translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs. |
|
348 | + ' '.$oid); |
|
349 | + $matches=array(); |
|
350 | + $ret_code=preg_match('/(.*)::(.*)/',$translate,$matches); |
|
351 | + if ($ret_code===0 || $ret_code === false) { |
|
352 | + return NULL; |
|
353 | + } else { |
|
354 | + $this->logging->log('Found name with snmptrapd and not in DB for oid='.$oid,INFO); |
|
355 | + return array('trap_name_mib'=>$matches[1],'trap_name'=>$matches[2]); |
|
356 | + } |
|
357 | + } |
|
358 | 358 | |
359 | - /** |
|
360 | - * Erase old trap records |
|
361 | - * @param integer $days : erase traps when more than $days old |
|
362 | - * @return integer : number of lines deleted |
|
363 | - **/ |
|
364 | - public function eraseOldTraps($days=0) |
|
365 | - { |
|
366 | - if ($days==0) |
|
367 | - { |
|
368 | - if (($days=$this->getDBConfig('db_remove_days')) == null) |
|
369 | - { |
|
370 | - $this->logging->log('No days specified & no db value : no tap erase' ,WARN,''); |
|
371 | - return; |
|
372 | - } |
|
373 | - } |
|
374 | - $db_conn=$this->trapsDB->db_connect_trap(); |
|
375 | - $daysago = strtotime("-".$days." day"); |
|
376 | - $sql= 'delete from '.$this->dbPrefix.'received where date_received < \''.date("Y-m-d H:i:s",$daysago).'\';'; |
|
377 | - if ($db_conn->query($sql) === false) { |
|
378 | - $this->logging->log('Error erasing traps : '.$sql,ERROR,''); |
|
379 | - } |
|
380 | - $this->logging->log('Erased traps older than '.$days.' day(s) : '.$sql,INFO); |
|
381 | - } |
|
359 | + /** |
|
360 | + * Erase old trap records |
|
361 | + * @param integer $days : erase traps when more than $days old |
|
362 | + * @return integer : number of lines deleted |
|
363 | + **/ |
|
364 | + public function eraseOldTraps($days=0) |
|
365 | + { |
|
366 | + if ($days==0) |
|
367 | + { |
|
368 | + if (($days=$this->getDBConfig('db_remove_days')) == null) |
|
369 | + { |
|
370 | + $this->logging->log('No days specified & no db value : no tap erase' ,WARN,''); |
|
371 | + return; |
|
372 | + } |
|
373 | + } |
|
374 | + $db_conn=$this->trapsDB->db_connect_trap(); |
|
375 | + $daysago = strtotime("-".$days." day"); |
|
376 | + $sql= 'delete from '.$this->dbPrefix.'received where date_received < \''.date("Y-m-d H:i:s",$daysago).'\';'; |
|
377 | + if ($db_conn->query($sql) === false) { |
|
378 | + $this->logging->log('Error erasing traps : '.$sql,ERROR,''); |
|
379 | + } |
|
380 | + $this->logging->log('Erased traps older than '.$days.' day(s) : '.$sql,INFO); |
|
381 | + } |
|
382 | 382 | |
383 | - /** Write error to received trap database |
|
384 | - */ |
|
385 | - public function writeTrapErrorToDB($message,$sourceIP=null,$trapoid=null) |
|
386 | - { |
|
387 | - |
|
388 | - $db_conn=$this->trapsDB->db_connect_trap(); |
|
389 | - |
|
390 | - // add date time |
|
391 | - $insert_col ='date_received,status'; |
|
392 | - $insert_val = "'" . date("Y-m-d H:i:s")."','error'"; |
|
393 | - |
|
394 | - if ($sourceIP !=null) |
|
395 | - { |
|
396 | - $insert_col .=',source_ip'; |
|
397 | - $insert_val .=",'". $sourceIP ."'"; |
|
398 | - } |
|
399 | - if ($trapoid !=null) |
|
400 | - { |
|
401 | - $insert_col .=',trap_oid'; |
|
402 | - $insert_val .=",'". $trapoid ."'"; |
|
403 | - } |
|
404 | - $insert_col .=',status_detail'; |
|
405 | - $insert_val .=",'". $message ."'"; |
|
406 | - |
|
407 | - $sql= 'INSERT INTO '.$this->dbPrefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')'; |
|
408 | - |
|
409 | - switch ($this->trapsDB->trapDBType) |
|
410 | - { |
|
411 | - case 'pgsql': |
|
412 | - $sql .= ' RETURNING id;'; |
|
413 | - $this->logging->log('sql : '.$sql,INFO); |
|
414 | - if (($ret_code=$db_conn->query($sql)) === false) { |
|
415 | - $this->logging->log('Error SQL insert : '.$sql,1,''); |
|
416 | - } |
|
417 | - $this->logging->log('SQL insertion OK',INFO ); |
|
418 | - // Get last id to insert oid/values in secondary table |
|
419 | - if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) { |
|
383 | + /** Write error to received trap database |
|
384 | + */ |
|
385 | + public function writeTrapErrorToDB($message,$sourceIP=null,$trapoid=null) |
|
386 | + { |
|
387 | + |
|
388 | + $db_conn=$this->trapsDB->db_connect_trap(); |
|
389 | + |
|
390 | + // add date time |
|
391 | + $insert_col ='date_received,status'; |
|
392 | + $insert_val = "'" . date("Y-m-d H:i:s")."','error'"; |
|
393 | + |
|
394 | + if ($sourceIP !=null) |
|
395 | + { |
|
396 | + $insert_col .=',source_ip'; |
|
397 | + $insert_val .=",'". $sourceIP ."'"; |
|
398 | + } |
|
399 | + if ($trapoid !=null) |
|
400 | + { |
|
401 | + $insert_col .=',trap_oid'; |
|
402 | + $insert_val .=",'". $trapoid ."'"; |
|
403 | + } |
|
404 | + $insert_col .=',status_detail'; |
|
405 | + $insert_val .=",'". $message ."'"; |
|
406 | + |
|
407 | + $sql= 'INSERT INTO '.$this->dbPrefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')'; |
|
408 | + |
|
409 | + switch ($this->trapsDB->trapDBType) |
|
410 | + { |
|
411 | + case 'pgsql': |
|
412 | + $sql .= ' RETURNING id;'; |
|
413 | + $this->logging->log('sql : '.$sql,INFO); |
|
414 | + if (($ret_code=$db_conn->query($sql)) === false) { |
|
415 | + $this->logging->log('Error SQL insert : '.$sql,1,''); |
|
416 | + } |
|
417 | + $this->logging->log('SQL insertion OK',INFO ); |
|
418 | + // Get last id to insert oid/values in secondary table |
|
419 | + if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) { |
|
420 | 420 | |
421 | - $this->logging->log('Erreur recuperation id',1,''); |
|
422 | - } |
|
423 | - if (! isset($inserted_id_ret['id'])) { |
|
424 | - $this->logging->log('Error getting id',1,''); |
|
425 | - } |
|
426 | - $this->trapId=$inserted_id_ret['id']; |
|
427 | - break; |
|
428 | - case 'mysql': |
|
429 | - $sql .= ';'; |
|
430 | - $this->logging->log('sql : '.$sql,INFO ); |
|
431 | - if ($db_conn->query($sql) === false) { |
|
432 | - $this->logging->log('Error SQL insert : '.$sql,1,''); |
|
433 | - } |
|
434 | - $this->logging->log('SQL insertion OK',INFO ); |
|
435 | - // Get last id to insert oid/values in secondary table |
|
436 | - $sql='SELECT LAST_INSERT_ID();'; |
|
437 | - if (($ret_code=$db_conn->query($sql)) === false) { |
|
438 | - $this->logging->log('Erreur recuperation id',1,''); |
|
439 | - } |
|
421 | + $this->logging->log('Erreur recuperation id',1,''); |
|
422 | + } |
|
423 | + if (! isset($inserted_id_ret['id'])) { |
|
424 | + $this->logging->log('Error getting id',1,''); |
|
425 | + } |
|
426 | + $this->trapId=$inserted_id_ret['id']; |
|
427 | + break; |
|
428 | + case 'mysql': |
|
429 | + $sql .= ';'; |
|
430 | + $this->logging->log('sql : '.$sql,INFO ); |
|
431 | + if ($db_conn->query($sql) === false) { |
|
432 | + $this->logging->log('Error SQL insert : '.$sql,1,''); |
|
433 | + } |
|
434 | + $this->logging->log('SQL insertion OK',INFO ); |
|
435 | + // Get last id to insert oid/values in secondary table |
|
436 | + $sql='SELECT LAST_INSERT_ID();'; |
|
437 | + if (($ret_code=$db_conn->query($sql)) === false) { |
|
438 | + $this->logging->log('Erreur recuperation id',1,''); |
|
439 | + } |
|
440 | 440 | |
441 | - $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
|
442 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
443 | - $this->trapId=$inserted_id; |
|
444 | - break; |
|
445 | - default: |
|
446 | - $this->logging->log('Error SQL type unknown : '.$this->trapsDB->trapDBType,1,''); |
|
447 | - } |
|
448 | - |
|
449 | - $this->logging->log('id found: '. $this->trapId,INFO ); |
|
450 | - } |
|
441 | + $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
|
442 | + if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
443 | + $this->trapId=$inserted_id; |
|
444 | + break; |
|
445 | + default: |
|
446 | + $this->logging->log('Error SQL type unknown : '.$this->trapsDB->trapDBType,1,''); |
|
447 | + } |
|
448 | + |
|
449 | + $this->logging->log('id found: '. $this->trapId,INFO ); |
|
450 | + } |
|
451 | 451 | |
452 | - /** Write trap data to trap database |
|
453 | - */ |
|
454 | - public function writeTrapToDB() |
|
455 | - { |
|
456 | - |
|
457 | - // If action is ignore -> don't send t DB |
|
458 | - if ($this->trapToDb === false) return; |
|
459 | - |
|
460 | - |
|
461 | - $db_conn=$this->trapsDB->db_connect_trap(); |
|
462 | - |
|
463 | - $insert_col=''; |
|
464 | - $insert_val=''; |
|
465 | - // add date time |
|
466 | - $this->trapData['date_received'] = date("Y-m-d H:i:s"); |
|
467 | - |
|
468 | - $firstcol=1; |
|
469 | - foreach ($this->trapData as $col => $val) |
|
470 | - { |
|
471 | - if ($firstcol==0) |
|
472 | - { |
|
473 | - $insert_col .=','; |
|
474 | - $insert_val .=','; |
|
475 | - } |
|
476 | - $insert_col .= $col ; |
|
477 | - $insert_val .= ($val==null)? 'NULL' : $db_conn->quote($val); |
|
478 | - $firstcol=0; |
|
479 | - } |
|
480 | - |
|
481 | - $sql= 'INSERT INTO '.$this->dbPrefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')'; |
|
482 | - switch ($this->trapsDB->trapDBType) |
|
483 | - { |
|
484 | - case 'pgsql': |
|
485 | - $sql .= ' RETURNING id;'; |
|
486 | - $this->logging->log('sql : '.$sql,INFO ); |
|
487 | - if (($ret_code=$db_conn->query($sql)) === false) { |
|
488 | - $this->logging->log('Error SQL insert : '.$sql,ERROR,''); |
|
489 | - } |
|
490 | - $this->logging->log('SQL insertion OK',INFO ); |
|
491 | - // Get last id to insert oid/values in secondary table |
|
492 | - if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) { |
|
452 | + /** Write trap data to trap database |
|
453 | + */ |
|
454 | + public function writeTrapToDB() |
|
455 | + { |
|
456 | + |
|
457 | + // If action is ignore -> don't send t DB |
|
458 | + if ($this->trapToDb === false) return; |
|
459 | + |
|
460 | + |
|
461 | + $db_conn=$this->trapsDB->db_connect_trap(); |
|
462 | + |
|
463 | + $insert_col=''; |
|
464 | + $insert_val=''; |
|
465 | + // add date time |
|
466 | + $this->trapData['date_received'] = date("Y-m-d H:i:s"); |
|
467 | + |
|
468 | + $firstcol=1; |
|
469 | + foreach ($this->trapData as $col => $val) |
|
470 | + { |
|
471 | + if ($firstcol==0) |
|
472 | + { |
|
473 | + $insert_col .=','; |
|
474 | + $insert_val .=','; |
|
475 | + } |
|
476 | + $insert_col .= $col ; |
|
477 | + $insert_val .= ($val==null)? 'NULL' : $db_conn->quote($val); |
|
478 | + $firstcol=0; |
|
479 | + } |
|
480 | + |
|
481 | + $sql= 'INSERT INTO '.$this->dbPrefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')'; |
|
482 | + switch ($this->trapsDB->trapDBType) |
|
483 | + { |
|
484 | + case 'pgsql': |
|
485 | + $sql .= ' RETURNING id;'; |
|
486 | + $this->logging->log('sql : '.$sql,INFO ); |
|
487 | + if (($ret_code=$db_conn->query($sql)) === false) { |
|
488 | + $this->logging->log('Error SQL insert : '.$sql,ERROR,''); |
|
489 | + } |
|
490 | + $this->logging->log('SQL insertion OK',INFO ); |
|
491 | + // Get last id to insert oid/values in secondary table |
|
492 | + if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) { |
|
493 | 493 | |
494 | - $this->logging->log('Erreur recuperation id',ERROR,''); |
|
495 | - } |
|
496 | - if (! isset($inserted_id_ret['id'])) { |
|
497 | - $this->logging->log('Error getting id',ERROR,''); |
|
498 | - } |
|
499 | - $this->trapId=$inserted_id_ret['id']; |
|
500 | - break; |
|
501 | - case 'mysql': |
|
502 | - $sql .= ';'; |
|
503 | - $this->logging->log('sql : '.$sql,INFO ); |
|
504 | - if ($db_conn->query($sql) === false) { |
|
505 | - $this->logging->log('Error SQL insert : '.$sql,ERROR,''); |
|
506 | - } |
|
507 | - $this->logging->log('SQL insertion OK',INFO ); |
|
508 | - // Get last id to insert oid/values in secondary table |
|
509 | - $sql='SELECT LAST_INSERT_ID();'; |
|
510 | - if (($ret_code=$db_conn->query($sql)) === false) { |
|
511 | - $this->logging->log('Erreur recuperation id',ERROR,''); |
|
512 | - } |
|
494 | + $this->logging->log('Erreur recuperation id',ERROR,''); |
|
495 | + } |
|
496 | + if (! isset($inserted_id_ret['id'])) { |
|
497 | + $this->logging->log('Error getting id',ERROR,''); |
|
498 | + } |
|
499 | + $this->trapId=$inserted_id_ret['id']; |
|
500 | + break; |
|
501 | + case 'mysql': |
|
502 | + $sql .= ';'; |
|
503 | + $this->logging->log('sql : '.$sql,INFO ); |
|
504 | + if ($db_conn->query($sql) === false) { |
|
505 | + $this->logging->log('Error SQL insert : '.$sql,ERROR,''); |
|
506 | + } |
|
507 | + $this->logging->log('SQL insertion OK',INFO ); |
|
508 | + // Get last id to insert oid/values in secondary table |
|
509 | + $sql='SELECT LAST_INSERT_ID();'; |
|
510 | + if (($ret_code=$db_conn->query($sql)) === false) { |
|
511 | + $this->logging->log('Erreur recuperation id',ERROR,''); |
|
512 | + } |
|
513 | 513 | |
514 | - $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
|
515 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
516 | - $this->trapId=$inserted_id; |
|
517 | - break; |
|
518 | - default: |
|
519 | - $this->logging->log('Error SQL type unknown : '.$this->trapsDB->trapDBType,ERROR,''); |
|
520 | - } |
|
521 | - $this->logging->log('id found: '.$this->trapId,INFO ); |
|
522 | - |
|
523 | - // Fill trap extended data table |
|
524 | - foreach ($this->trapDataExt as $value) { |
|
525 | - // TODO : detect if trap value is encoded and decode it to UTF-8 for database |
|
526 | - $firstcol=1; |
|
527 | - $value->trap_id = $this->trapId; |
|
528 | - $insert_col=''; |
|
529 | - $insert_val=''; |
|
530 | - foreach ($value as $col => $val) |
|
531 | - { |
|
532 | - if ($firstcol==0) |
|
533 | - { |
|
534 | - $insert_col .=','; |
|
535 | - $insert_val .=','; |
|
536 | - } |
|
537 | - $insert_col .= $col; |
|
538 | - $insert_val .= ($val==null)? 'NULL' : $db_conn->quote($val); |
|
539 | - $firstcol=0; |
|
540 | - } |
|
514 | + $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
|
515 | + if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
516 | + $this->trapId=$inserted_id; |
|
517 | + break; |
|
518 | + default: |
|
519 | + $this->logging->log('Error SQL type unknown : '.$this->trapsDB->trapDBType,ERROR,''); |
|
520 | + } |
|
521 | + $this->logging->log('id found: '.$this->trapId,INFO ); |
|
522 | + |
|
523 | + // Fill trap extended data table |
|
524 | + foreach ($this->trapDataExt as $value) { |
|
525 | + // TODO : detect if trap value is encoded and decode it to UTF-8 for database |
|
526 | + $firstcol=1; |
|
527 | + $value->trap_id = $this->trapId; |
|
528 | + $insert_col=''; |
|
529 | + $insert_val=''; |
|
530 | + foreach ($value as $col => $val) |
|
531 | + { |
|
532 | + if ($firstcol==0) |
|
533 | + { |
|
534 | + $insert_col .=','; |
|
535 | + $insert_val .=','; |
|
536 | + } |
|
537 | + $insert_col .= $col; |
|
538 | + $insert_val .= ($val==null)? 'NULL' : $db_conn->quote($val); |
|
539 | + $firstcol=0; |
|
540 | + } |
|
541 | 541 | |
542 | - $sql= 'INSERT INTO '.$this->dbPrefix.'received_data (' . $insert_col . ') VALUES ('.$insert_val.');'; |
|
542 | + $sql= 'INSERT INTO '.$this->dbPrefix.'received_data (' . $insert_col . ') VALUES ('.$insert_val.');'; |
|
543 | 543 | |
544 | - if ($db_conn->query($sql) === false) { |
|
545 | - $this->logging->log('Erreur insertion data : ' . $sql,WARN,''); |
|
546 | - } |
|
547 | - } |
|
548 | - } |
|
544 | + if ($db_conn->query($sql) === false) { |
|
545 | + $this->logging->log('Erreur insertion data : ' . $sql,WARN,''); |
|
546 | + } |
|
547 | + } |
|
548 | + } |
|
549 | 549 | |
550 | - /** Get rules from rule database with ip and oid |
|
551 | - * @param $ip string ipv4 or ipv6 |
|
552 | - * @param $oid string oid in numeric |
|
553 | - * @return mixed|boolean : PDO object or false |
|
554 | - */ |
|
555 | - protected function getRules($ip,$oid) |
|
556 | - { |
|
557 | - $db_conn=$this->trapsDB->db_connect_trap(); |
|
558 | - // fetch rules based on IP in rule and OID |
|
559 | - $sql='SELECT * from '.$this->dbPrefix.'rules WHERE trap_oid=\''.$oid.'\' '; |
|
560 | - $this->logging->log('SQL query : '.$sql,DEBUG ); |
|
561 | - if (($ret_code=$db_conn->query($sql)) === false) { |
|
562 | - $this->logging->log('No result in query : ' . $sql,WARN,''); |
|
563 | - return false; |
|
564 | - } |
|
565 | - $rules_all=$ret_code->fetchAll(); |
|
566 | - //echo "rule all :\n";print_r($rules_all);echo "\n"; |
|
567 | - $rules_ret=array(); |
|
568 | - $rule_ret_key=0; |
|
569 | - foreach ($rules_all as $key => $rule) |
|
570 | - { |
|
571 | - if ($rule['ip4']==$ip || $rule['ip6']==$ip) |
|
572 | - { |
|
573 | - $rules_ret[$rule_ret_key]=$rules_all[$key]; |
|
574 | - //TODO : get host name by API (and check if correct in rule). |
|
575 | - $rule_ret_key++; |
|
576 | - continue; |
|
577 | - } |
|
578 | - // TODO : get hosts IP by API |
|
579 | - if (isset($rule['host_group_name']) && $rule['host_group_name']!=null) |
|
580 | - { // get ips of group members by oid |
|
581 | - $db_conn2=$this->trapsDB->db_connect_ido(); |
|
582 | - $sql="SELECT m.host_object_id, a.address as ip4, a.address6 as ip6, b.name1 as host_name |
|
550 | + /** Get rules from rule database with ip and oid |
|
551 | + * @param $ip string ipv4 or ipv6 |
|
552 | + * @param $oid string oid in numeric |
|
553 | + * @return mixed|boolean : PDO object or false |
|
554 | + */ |
|
555 | + protected function getRules($ip,$oid) |
|
556 | + { |
|
557 | + $db_conn=$this->trapsDB->db_connect_trap(); |
|
558 | + // fetch rules based on IP in rule and OID |
|
559 | + $sql='SELECT * from '.$this->dbPrefix.'rules WHERE trap_oid=\''.$oid.'\' '; |
|
560 | + $this->logging->log('SQL query : '.$sql,DEBUG ); |
|
561 | + if (($ret_code=$db_conn->query($sql)) === false) { |
|
562 | + $this->logging->log('No result in query : ' . $sql,WARN,''); |
|
563 | + return false; |
|
564 | + } |
|
565 | + $rules_all=$ret_code->fetchAll(); |
|
566 | + //echo "rule all :\n";print_r($rules_all);echo "\n"; |
|
567 | + $rules_ret=array(); |
|
568 | + $rule_ret_key=0; |
|
569 | + foreach ($rules_all as $key => $rule) |
|
570 | + { |
|
571 | + if ($rule['ip4']==$ip || $rule['ip6']==$ip) |
|
572 | + { |
|
573 | + $rules_ret[$rule_ret_key]=$rules_all[$key]; |
|
574 | + //TODO : get host name by API (and check if correct in rule). |
|
575 | + $rule_ret_key++; |
|
576 | + continue; |
|
577 | + } |
|
578 | + // TODO : get hosts IP by API |
|
579 | + if (isset($rule['host_group_name']) && $rule['host_group_name']!=null) |
|
580 | + { // get ips of group members by oid |
|
581 | + $db_conn2=$this->trapsDB->db_connect_ido(); |
|
582 | + $sql="SELECT m.host_object_id, a.address as ip4, a.address6 as ip6, b.name1 as host_name |
|
583 | 583 | FROM icinga_objects as o |
584 | 584 | LEFT JOIN icinga_hostgroups as h ON o.object_id=h.hostgroup_object_id |
585 | 585 | LEFT JOIN icinga_hostgroup_members as m ON h.hostgroup_id=m.hostgroup_id |
586 | 586 | LEFT JOIN icinga_hosts as a ON a.host_object_id = m.host_object_id |
587 | 587 | LEFT JOIN icinga_objects as b ON b.object_id = a.host_object_id |
588 | 588 | WHERE o.name1='".$rule['host_group_name']."';"; |
589 | - if (($ret_code2=$db_conn2->query($sql)) === false) { |
|
590 | - $this->logging->log('No result in query : ' . $sql,WARN,''); |
|
591 | - continue; |
|
592 | - } |
|
593 | - $grouphosts=$ret_code2->fetchAll(); |
|
594 | - //echo "rule grp :\n";print_r($grouphosts);echo "\n"; |
|
595 | - foreach ( $grouphosts as $host) |
|
596 | - { |
|
597 | - //echo $host['ip4']."\n"; |
|
598 | - if ($host['ip4']==$ip || $host['ip6']==$ip) |
|
599 | - { |
|
600 | - //echo "Rule added \n"; |
|
601 | - $rules_ret[$rule_ret_key]=$rules_all[$key]; |
|
602 | - $rules_ret[$rule_ret_key]['host_name']=$host['host_name']; |
|
603 | - $rule_ret_key++; |
|
604 | - } |
|
605 | - } |
|
606 | - } |
|
607 | - } |
|
608 | - //echo "rule rest :\n";print_r($rules_ret);echo "\n";exit(0); |
|
609 | - return $rules_ret; |
|
610 | - } |
|
589 | + if (($ret_code2=$db_conn2->query($sql)) === false) { |
|
590 | + $this->logging->log('No result in query : ' . $sql,WARN,''); |
|
591 | + continue; |
|
592 | + } |
|
593 | + $grouphosts=$ret_code2->fetchAll(); |
|
594 | + //echo "rule grp :\n";print_r($grouphosts);echo "\n"; |
|
595 | + foreach ( $grouphosts as $host) |
|
596 | + { |
|
597 | + //echo $host['ip4']."\n"; |
|
598 | + if ($host['ip4']==$ip || $host['ip6']==$ip) |
|
599 | + { |
|
600 | + //echo "Rule added \n"; |
|
601 | + $rules_ret[$rule_ret_key]=$rules_all[$key]; |
|
602 | + $rules_ret[$rule_ret_key]['host_name']=$host['host_name']; |
|
603 | + $rule_ret_key++; |
|
604 | + } |
|
605 | + } |
|
606 | + } |
|
607 | + } |
|
608 | + //echo "rule rest :\n";print_r($rules_ret);echo "\n";exit(0); |
|
609 | + return $rules_ret; |
|
610 | + } |
|
611 | 611 | |
612 | - /** Add rule match to rule |
|
613 | - * @param id int : rule id |
|
614 | - * @param set int : value to set |
|
615 | - */ |
|
616 | - protected function add_rule_match($id, $set) |
|
617 | - { |
|
618 | - $db_conn=$this->trapsDB->db_connect_trap(); |
|
619 | - $sql="UPDATE ".$this->dbPrefix."rules SET num_match = '".$set."' WHERE (id = '".$id."');"; |
|
620 | - if ($db_conn->query($sql) === false) { |
|
621 | - $this->logging->log('Error in update query : ' . $sql,WARN,''); |
|
622 | - } |
|
623 | - } |
|
612 | + /** Add rule match to rule |
|
613 | + * @param id int : rule id |
|
614 | + * @param set int : value to set |
|
615 | + */ |
|
616 | + protected function add_rule_match($id, $set) |
|
617 | + { |
|
618 | + $db_conn=$this->trapsDB->db_connect_trap(); |
|
619 | + $sql="UPDATE ".$this->dbPrefix."rules SET num_match = '".$set."' WHERE (id = '".$id."');"; |
|
620 | + if ($db_conn->query($sql) === false) { |
|
621 | + $this->logging->log('Error in update query : ' . $sql,WARN,''); |
|
622 | + } |
|
623 | + } |
|
624 | 624 | |
625 | - /** Send SERVICE_CHECK_RESULT with icinga2cmd or API |
|
626 | - * |
|
627 | - * @param string $host |
|
628 | - * @param string $service |
|
629 | - * @param integer $state numerical staus |
|
630 | - * @param string $display |
|
631 | - * @returnn bool true is service check was sent without error |
|
632 | - */ |
|
633 | - public function serviceCheckResult($host,$service,$state,$display) |
|
634 | - { |
|
635 | - if ($this->apiUse === false) |
|
636 | - { |
|
637 | - $send = '[' . date('U') .'] PROCESS_SERVICE_CHECK_RESULT;' . |
|
638 | - $host.';' .$service .';' . $state . ';'.$display; |
|
639 | - $this->logging->log( $send." : to : " .$this->icinga2cmd,INFO ); |
|
625 | + /** Send SERVICE_CHECK_RESULT with icinga2cmd or API |
|
626 | + * |
|
627 | + * @param string $host |
|
628 | + * @param string $service |
|
629 | + * @param integer $state numerical staus |
|
630 | + * @param string $display |
|
631 | + * @returnn bool true is service check was sent without error |
|
632 | + */ |
|
633 | + public function serviceCheckResult($host,$service,$state,$display) |
|
634 | + { |
|
635 | + if ($this->apiUse === false) |
|
636 | + { |
|
637 | + $send = '[' . date('U') .'] PROCESS_SERVICE_CHECK_RESULT;' . |
|
638 | + $host.';' .$service .';' . $state . ';'.$display; |
|
639 | + $this->logging->log( $send." : to : " .$this->icinga2cmd,INFO ); |
|
640 | 640 | |
641 | - // TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default.... |
|
642 | - exec('echo "'.$send.'" > ' .$this->icinga2cmd); |
|
643 | - return true; |
|
644 | - } |
|
645 | - else |
|
646 | - { |
|
647 | - // Get perfdata if found |
|
648 | - $matches=array(); |
|
649 | - if (preg_match('/(.*)\|(.*)/',$display,$matches) == 1) |
|
650 | - { |
|
651 | - $display=$matches[1]; |
|
652 | - $perfdata=$matches[2]; |
|
653 | - } |
|
654 | - else |
|
655 | - { |
|
656 | - $perfdata=''; |
|
657 | - } |
|
641 | + // TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default.... |
|
642 | + exec('echo "'.$send.'" > ' .$this->icinga2cmd); |
|
643 | + return true; |
|
644 | + } |
|
645 | + else |
|
646 | + { |
|
647 | + // Get perfdata if found |
|
648 | + $matches=array(); |
|
649 | + if (preg_match('/(.*)\|(.*)/',$display,$matches) == 1) |
|
650 | + { |
|
651 | + $display=$matches[1]; |
|
652 | + $perfdata=$matches[2]; |
|
653 | + } |
|
654 | + else |
|
655 | + { |
|
656 | + $perfdata=''; |
|
657 | + } |
|
658 | 658 | |
659 | - $api = $this->getAPI(); |
|
660 | - $api->setCredentials($this->apiUsername, $this->apiPassword); |
|
661 | - list($retcode,$retmessage)=$api->serviceCheckResult($host,$service,$state,$display,$perfdata); |
|
662 | - if ($retcode == false) |
|
663 | - { |
|
664 | - $this->logging->log( "Error sending result : " .$retmessage,WARN,''); |
|
665 | - return false; |
|
666 | - } |
|
667 | - else |
|
668 | - { |
|
669 | - $this->logging->log( "Sent result : " .$retmessage,INFO ); |
|
670 | - return true; |
|
671 | - } |
|
672 | - } |
|
673 | - } |
|
659 | + $api = $this->getAPI(); |
|
660 | + $api->setCredentials($this->apiUsername, $this->apiPassword); |
|
661 | + list($retcode,$retmessage)=$api->serviceCheckResult($host,$service,$state,$display,$perfdata); |
|
662 | + if ($retcode == false) |
|
663 | + { |
|
664 | + $this->logging->log( "Error sending result : " .$retmessage,WARN,''); |
|
665 | + return false; |
|
666 | + } |
|
667 | + else |
|
668 | + { |
|
669 | + $this->logging->log( "Sent result : " .$retmessage,INFO ); |
|
670 | + return true; |
|
671 | + } |
|
672 | + } |
|
673 | + } |
|
674 | 674 | |
675 | - public function getHostByIP($ip) |
|
676 | - { |
|
677 | - $api = $this->getAPI(); |
|
678 | - $api->setCredentials($this->apiUsername, $this->apiPassword); |
|
679 | - return $api->getHostByIP($ip); |
|
680 | - } |
|
675 | + public function getHostByIP($ip) |
|
676 | + { |
|
677 | + $api = $this->getAPI(); |
|
678 | + $api->setCredentials($this->apiUsername, $this->apiPassword); |
|
679 | + return $api->getHostByIP($ip); |
|
680 | + } |
|
681 | 681 | |
682 | - /** Resolve display. |
|
683 | - * Changes _OID(<oid>) to value if found or text "<not in trap>" |
|
684 | - * @param $display string |
|
685 | - * @return string display |
|
686 | - */ |
|
687 | - protected function applyDisplay($display) |
|
688 | - { |
|
689 | - $matches=array(); |
|
690 | - while (preg_match('/_OID\(([0-9\.\*]+)\)/',$display,$matches) == 1) |
|
691 | - { |
|
692 | - $oid=$matches[1]; |
|
693 | - $found=0; |
|
694 | - // Test and transform regexp |
|
695 | - $oidR = $this->ruleClass->regexp_eval($oid); |
|
682 | + /** Resolve display. |
|
683 | + * Changes _OID(<oid>) to value if found or text "<not in trap>" |
|
684 | + * @param $display string |
|
685 | + * @return string display |
|
686 | + */ |
|
687 | + protected function applyDisplay($display) |
|
688 | + { |
|
689 | + $matches=array(); |
|
690 | + while (preg_match('/_OID\(([0-9\.\*]+)\)/',$display,$matches) == 1) |
|
691 | + { |
|
692 | + $oid=$matches[1]; |
|
693 | + $found=0; |
|
694 | + // Test and transform regexp |
|
695 | + $oidR = $this->ruleClass->regexp_eval($oid); |
|
696 | 696 | |
697 | - foreach($this->trapDataExt as $val) |
|
698 | - { |
|
699 | - if (preg_match("/^$oidR$/",$val->oid) == 1) |
|
700 | - { |
|
701 | - $val->value=preg_replace('/"/','',$val->value); |
|
702 | - $rep=0; |
|
703 | - $display=preg_replace('/_OID\('.$oid.'\)/',$val->value,$display,-1,$rep); |
|
704 | - if ($rep==0) |
|
705 | - { |
|
706 | - $this->logging->log("Error in display",WARN,''); |
|
707 | - return $display; |
|
708 | - } |
|
709 | - $found=1; |
|
710 | - break; |
|
711 | - } |
|
712 | - } |
|
713 | - if ($found==0) |
|
714 | - { |
|
715 | - $display=preg_replace('/_OID\('.$oid.'\)/','<not in trap>',$display,-1,$rep); |
|
716 | - if ($rep==0) |
|
717 | - { |
|
718 | - $this->logging->log("Error in display",WARN,''); |
|
719 | - return $display; |
|
720 | - } |
|
721 | - } |
|
722 | - } |
|
723 | - return $display; |
|
724 | - } |
|
697 | + foreach($this->trapDataExt as $val) |
|
698 | + { |
|
699 | + if (preg_match("/^$oidR$/",$val->oid) == 1) |
|
700 | + { |
|
701 | + $val->value=preg_replace('/"/','',$val->value); |
|
702 | + $rep=0; |
|
703 | + $display=preg_replace('/_OID\('.$oid.'\)/',$val->value,$display,-1,$rep); |
|
704 | + if ($rep==0) |
|
705 | + { |
|
706 | + $this->logging->log("Error in display",WARN,''); |
|
707 | + return $display; |
|
708 | + } |
|
709 | + $found=1; |
|
710 | + break; |
|
711 | + } |
|
712 | + } |
|
713 | + if ($found==0) |
|
714 | + { |
|
715 | + $display=preg_replace('/_OID\('.$oid.'\)/','<not in trap>',$display,-1,$rep); |
|
716 | + if ($rep==0) |
|
717 | + { |
|
718 | + $this->logging->log("Error in display",WARN,''); |
|
719 | + return $display; |
|
720 | + } |
|
721 | + } |
|
722 | + } |
|
723 | + return $display; |
|
724 | + } |
|
725 | 725 | |
726 | - /** Match rules for current trap and do action |
|
727 | - */ |
|
728 | - public function applyRules() |
|
729 | - { |
|
730 | - $rules = $this->getRules($this->trapData['source_ip'],$this->trapData['trap_oid']); |
|
731 | - |
|
732 | - if ($rules===false || count($rules)==0) |
|
733 | - { |
|
734 | - $this->logging->log('No rules found for this trap',INFO ); |
|
735 | - $this->trapData['status']='unknown'; |
|
736 | - $this->trapToDb=true; |
|
737 | - return; |
|
738 | - } |
|
739 | - //print_r($rules); |
|
740 | - // Evaluate all rules in sequence |
|
741 | - $this->trapAction=null; |
|
742 | - foreach ($rules as $rule) |
|
743 | - { |
|
726 | + /** Match rules for current trap and do action |
|
727 | + */ |
|
728 | + public function applyRules() |
|
729 | + { |
|
730 | + $rules = $this->getRules($this->trapData['source_ip'],$this->trapData['trap_oid']); |
|
731 | + |
|
732 | + if ($rules===false || count($rules)==0) |
|
733 | + { |
|
734 | + $this->logging->log('No rules found for this trap',INFO ); |
|
735 | + $this->trapData['status']='unknown'; |
|
736 | + $this->trapToDb=true; |
|
737 | + return; |
|
738 | + } |
|
739 | + //print_r($rules); |
|
740 | + // Evaluate all rules in sequence |
|
741 | + $this->trapAction=null; |
|
742 | + foreach ($rules as $rule) |
|
743 | + { |
|
744 | 744 | |
745 | - $host_name=$rule['host_name']; |
|
746 | - $service_name=$rule['service_name']; |
|
745 | + $host_name=$rule['host_name']; |
|
746 | + $service_name=$rule['service_name']; |
|
747 | 747 | |
748 | - $display=$this->applyDisplay($rule['display']); |
|
749 | - $this->trapAction = ($this->trapAction==null)? '' : $this->trapAction . ', '; |
|
750 | - try |
|
751 | - { |
|
752 | - $this->logging->log('Rule to eval : '.$rule['rule'],INFO ); |
|
753 | - $evalr=$this->ruleClass->eval_rule($rule['rule'], $this->trapDataExt) ; |
|
754 | - //->eval_rule($rule['rule']); |
|
748 | + $display=$this->applyDisplay($rule['display']); |
|
749 | + $this->trapAction = ($this->trapAction==null)? '' : $this->trapAction . ', '; |
|
750 | + try |
|
751 | + { |
|
752 | + $this->logging->log('Rule to eval : '.$rule['rule'],INFO ); |
|
753 | + $evalr=$this->ruleClass->eval_rule($rule['rule'], $this->trapDataExt) ; |
|
754 | + //->eval_rule($rule['rule']); |
|
755 | 755 | |
756 | - if ($evalr == true) |
|
757 | - { |
|
758 | - //$this->logging->log('rules OOK: '.print_r($rule),INFO ); |
|
759 | - $action=$rule['action_match']; |
|
760 | - $this->logging->log('action OK : '.$action,INFO ); |
|
761 | - if ($action >= 0) |
|
762 | - { |
|
763 | - if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false) |
|
764 | - { |
|
765 | - $this->trapAction.='Error sending status : check cmd/API'; |
|
766 | - } |
|
767 | - else |
|
768 | - { |
|
769 | - $this->add_rule_match($rule['id'],$rule['num_match']+1); |
|
770 | - $this->trapAction.='Status '.$action.' to '.$host_name.'/'.$service_name; |
|
771 | - } |
|
772 | - } |
|
773 | - else |
|
774 | - { |
|
775 | - $this->add_rule_match($rule['id'],$rule['num_match']+1); |
|
776 | - } |
|
777 | - $this->trapToDb=($action==-2)?false:true; |
|
778 | - } |
|
779 | - else |
|
780 | - { |
|
781 | - //$this->logging->log('rules KOO : '.print_r($rule),INFO ); |
|
756 | + if ($evalr == true) |
|
757 | + { |
|
758 | + //$this->logging->log('rules OOK: '.print_r($rule),INFO ); |
|
759 | + $action=$rule['action_match']; |
|
760 | + $this->logging->log('action OK : '.$action,INFO ); |
|
761 | + if ($action >= 0) |
|
762 | + { |
|
763 | + if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false) |
|
764 | + { |
|
765 | + $this->trapAction.='Error sending status : check cmd/API'; |
|
766 | + } |
|
767 | + else |
|
768 | + { |
|
769 | + $this->add_rule_match($rule['id'],$rule['num_match']+1); |
|
770 | + $this->trapAction.='Status '.$action.' to '.$host_name.'/'.$service_name; |
|
771 | + } |
|
772 | + } |
|
773 | + else |
|
774 | + { |
|
775 | + $this->add_rule_match($rule['id'],$rule['num_match']+1); |
|
776 | + } |
|
777 | + $this->trapToDb=($action==-2)?false:true; |
|
778 | + } |
|
779 | + else |
|
780 | + { |
|
781 | + //$this->logging->log('rules KOO : '.print_r($rule),INFO ); |
|
782 | 782 | |
783 | - $action=$rule['action_nomatch']; |
|
784 | - $this->logging->log('action NOK : '.$action,INFO ); |
|
785 | - if ($action >= 0) |
|
786 | - { |
|
787 | - if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false) |
|
788 | - { |
|
789 | - $this->trapAction.='Error sending status : check cmd/API'; |
|
790 | - } |
|
791 | - else |
|
792 | - { |
|
793 | - $this->add_rule_match($rule['id'],$rule['num_match']+1); |
|
794 | - $this->trapAction.='Status '.$action.' to '.$host_name.'/'.$service_name; |
|
795 | - } |
|
796 | - } |
|
797 | - else |
|
798 | - { |
|
799 | - $this->add_rule_match($rule['id'],$rule['num_match']+1); |
|
800 | - } |
|
801 | - $this->trapToDb=($action==-2)?false:true; |
|
802 | - } |
|
803 | - // Put name in source_name |
|
804 | - if (!isset($this->trapData['source_name'])) |
|
805 | - { |
|
806 | - $this->trapData['source_name']=$rule['host_name']; |
|
807 | - } |
|
808 | - else |
|
809 | - { |
|
810 | - if (!preg_match('/'.$rule['host_name'].'/',$this->trapData['source_name'])) |
|
811 | - { // only add if not present |
|
812 | - $this->trapData['source_name'].=','.$rule['host_name']; |
|
813 | - } |
|
814 | - } |
|
815 | - } |
|
816 | - catch (Exception $e) |
|
817 | - { |
|
818 | - $this->logging->log('Error in rule eval : '.$e->getMessage(),WARN,''); |
|
819 | - $this->trapAction.=' ERR : '.$e->getMessage(); |
|
820 | - $this->trapData['status']='error'; |
|
821 | - } |
|
783 | + $action=$rule['action_nomatch']; |
|
784 | + $this->logging->log('action NOK : '.$action,INFO ); |
|
785 | + if ($action >= 0) |
|
786 | + { |
|
787 | + if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false) |
|
788 | + { |
|
789 | + $this->trapAction.='Error sending status : check cmd/API'; |
|
790 | + } |
|
791 | + else |
|
792 | + { |
|
793 | + $this->add_rule_match($rule['id'],$rule['num_match']+1); |
|
794 | + $this->trapAction.='Status '.$action.' to '.$host_name.'/'.$service_name; |
|
795 | + } |
|
796 | + } |
|
797 | + else |
|
798 | + { |
|
799 | + $this->add_rule_match($rule['id'],$rule['num_match']+1); |
|
800 | + } |
|
801 | + $this->trapToDb=($action==-2)?false:true; |
|
802 | + } |
|
803 | + // Put name in source_name |
|
804 | + if (!isset($this->trapData['source_name'])) |
|
805 | + { |
|
806 | + $this->trapData['source_name']=$rule['host_name']; |
|
807 | + } |
|
808 | + else |
|
809 | + { |
|
810 | + if (!preg_match('/'.$rule['host_name'].'/',$this->trapData['source_name'])) |
|
811 | + { // only add if not present |
|
812 | + $this->trapData['source_name'].=','.$rule['host_name']; |
|
813 | + } |
|
814 | + } |
|
815 | + } |
|
816 | + catch (Exception $e) |
|
817 | + { |
|
818 | + $this->logging->log('Error in rule eval : '.$e->getMessage(),WARN,''); |
|
819 | + $this->trapAction.=' ERR : '.$e->getMessage(); |
|
820 | + $this->trapData['status']='error'; |
|
821 | + } |
|
822 | 822 | |
823 | - } |
|
824 | - if ($this->trapData['status']=='error') |
|
825 | - { |
|
826 | - $this->trapToDb=true; // Always put errors in DB for the use can see |
|
827 | - } |
|
828 | - else |
|
829 | - { |
|
830 | - $this->trapData['status']='done'; |
|
831 | - } |
|
832 | - } |
|
823 | + } |
|
824 | + if ($this->trapData['status']=='error') |
|
825 | + { |
|
826 | + $this->trapToDb=true; // Always put errors in DB for the use can see |
|
827 | + } |
|
828 | + else |
|
829 | + { |
|
830 | + $this->trapData['status']='done'; |
|
831 | + } |
|
832 | + } |
|
833 | 833 | |
834 | - /** Add Time a action to rule |
|
835 | - * @param string $time : time to process to insert in SQL |
|
836 | - */ |
|
837 | - public function add_rule_final($time) |
|
838 | - { |
|
839 | - $db_conn=$this->trapsDB->db_connect_trap(); |
|
840 | - if ($this->trapAction==null) |
|
841 | - { |
|
842 | - $this->trapAction='No action'; |
|
843 | - } |
|
844 | - $sql="UPDATE ".$this->dbPrefix."received SET process_time = '".$time."' , status_detail='".$this->trapAction."' WHERE (id = '".$this->trapId."');"; |
|
845 | - if ($db_conn->query($sql) === false) { |
|
846 | - $this->logging->log('Error in update query : ' . $sql,WARN,''); |
|
847 | - } |
|
848 | - } |
|
834 | + /** Add Time a action to rule |
|
835 | + * @param string $time : time to process to insert in SQL |
|
836 | + */ |
|
837 | + public function add_rule_final($time) |
|
838 | + { |
|
839 | + $db_conn=$this->trapsDB->db_connect_trap(); |
|
840 | + if ($this->trapAction==null) |
|
841 | + { |
|
842 | + $this->trapAction='No action'; |
|
843 | + } |
|
844 | + $sql="UPDATE ".$this->dbPrefix."received SET process_time = '".$time."' , status_detail='".$this->trapAction."' WHERE (id = '".$this->trapId."');"; |
|
845 | + if ($db_conn->query($sql) === false) { |
|
846 | + $this->logging->log('Error in update query : ' . $sql,WARN,''); |
|
847 | + } |
|
848 | + } |
|
849 | 849 | |
850 | - /*********** UTILITIES *********************/ |
|
850 | + /*********** UTILITIES *********************/ |
|
851 | 851 | |
852 | - /** reset service to OK after time defined in rule |
|
853 | - * TODO logic is : get all service in error + all rules, see if getting all rules then select services is better |
|
854 | - * @return integer : not in use |
|
855 | - **/ |
|
856 | - public function reset_services() |
|
857 | - { |
|
858 | - // Get all services not in 'ok' state |
|
859 | - $sql_query="SELECT s.service_object_id, |
|
852 | + /** reset service to OK after time defined in rule |
|
853 | + * TODO logic is : get all service in error + all rules, see if getting all rules then select services is better |
|
854 | + * @return integer : not in use |
|
855 | + **/ |
|
856 | + public function reset_services() |
|
857 | + { |
|
858 | + // Get all services not in 'ok' state |
|
859 | + $sql_query="SELECT s.service_object_id, |
|
860 | 860 | UNIX_TIMESTAMP(s.last_check) AS last_check, |
861 | 861 | s.current_state as state, |
862 | 862 | v.name1 as host_name, |
@@ -864,43 +864,43 @@ discard block |
||
864 | 864 | FROM icinga_servicestatus AS s |
865 | 865 | LEFT JOIN icinga_objects as v ON s.service_object_id=v.object_id |
866 | 866 | WHERE s.current_state != 0;"; |
867 | - $db_conn=$this->trapsDB->db_connect_ido(); |
|
868 | - if (($services_db=$db_conn->query($sql_query)) === false) { // set err to 1 to throw exception. |
|
869 | - $this->logging->log('No result in query : ' . $sql_query,ERROR,''); |
|
870 | - return 0; |
|
871 | - } |
|
872 | - $services=$services_db->fetchAll(); |
|
873 | - |
|
874 | - // Get all rules |
|
875 | - $sql_query="SELECT host_name, service_name, revert_ok FROM ".$this->dbPrefix."rules where revert_ok != 0;"; |
|
876 | - $db_conn2=$this->trapsDB->db_connect_trap(); |
|
877 | - if (($rules_db=$db_conn2->query($sql_query)) === false) { |
|
878 | - $this->logging->log('No result in query : ' . $sql_query,ERROR,''); |
|
879 | - return 0; |
|
880 | - } |
|
881 | - $rules=$rules_db->fetchAll(); |
|
882 | - |
|
883 | - $now=date('U'); |
|
884 | - |
|
885 | - $numreset=0; |
|
886 | - foreach ($rules as $rule) |
|
887 | - { |
|
888 | - foreach ($services as $service) |
|
889 | - { |
|
890 | - if ($service['service_name'] == $rule['service_name'] && |
|
891 | - $service['host_name'] == $rule['host_name'] && |
|
892 | - ($service['last_check'] + $rule['revert_ok']) < $now) |
|
893 | - { |
|
894 | - $this->serviceCheckResult($service['host_name'],$service['service_name'],0,'Reset service to OK after '.$rule['revert_ok'].' seconds'); |
|
895 | - $numreset++; |
|
896 | - } |
|
897 | - } |
|
898 | - } |
|
899 | - echo "\n"; |
|
900 | - echo $numreset . " service(s) reset to OK\n"; |
|
901 | - return 0; |
|
902 | - |
|
903 | - } |
|
867 | + $db_conn=$this->trapsDB->db_connect_ido(); |
|
868 | + if (($services_db=$db_conn->query($sql_query)) === false) { // set err to 1 to throw exception. |
|
869 | + $this->logging->log('No result in query : ' . $sql_query,ERROR,''); |
|
870 | + return 0; |
|
871 | + } |
|
872 | + $services=$services_db->fetchAll(); |
|
873 | + |
|
874 | + // Get all rules |
|
875 | + $sql_query="SELECT host_name, service_name, revert_ok FROM ".$this->dbPrefix."rules where revert_ok != 0;"; |
|
876 | + $db_conn2=$this->trapsDB->db_connect_trap(); |
|
877 | + if (($rules_db=$db_conn2->query($sql_query)) === false) { |
|
878 | + $this->logging->log('No result in query : ' . $sql_query,ERROR,''); |
|
879 | + return 0; |
|
880 | + } |
|
881 | + $rules=$rules_db->fetchAll(); |
|
882 | + |
|
883 | + $now=date('U'); |
|
884 | + |
|
885 | + $numreset=0; |
|
886 | + foreach ($rules as $rule) |
|
887 | + { |
|
888 | + foreach ($services as $service) |
|
889 | + { |
|
890 | + if ($service['service_name'] == $rule['service_name'] && |
|
891 | + $service['host_name'] == $rule['host_name'] && |
|
892 | + ($service['last_check'] + $rule['revert_ok']) < $now) |
|
893 | + { |
|
894 | + $this->serviceCheckResult($service['host_name'],$service['service_name'],0,'Reset service to OK after '.$rule['revert_ok'].' seconds'); |
|
895 | + $numreset++; |
|
896 | + } |
|
897 | + } |
|
898 | + } |
|
899 | + echo "\n"; |
|
900 | + echo $numreset . " service(s) reset to OK\n"; |
|
901 | + return 0; |
|
902 | + |
|
903 | + } |
|
904 | 904 | |
905 | 905 | |
906 | 906 | } |
907 | 907 | \ No newline at end of file |
@@ -52,13 +52,13 @@ discard block |
||
52 | 52 | |
53 | 53 | // Logs |
54 | 54 | /** @var Logging Logging class. */ |
55 | - public $logging; //< Logging class. |
|
55 | + public $logging; //< Logging class. |
|
56 | 56 | /** @var bool true if log was setup in constructor */ |
57 | - protected $logSetup; //< bool true if log was setup in constructor |
|
57 | + protected $logSetup; //< bool true if log was setup in constructor |
|
58 | 58 | |
59 | 59 | // Databases |
60 | 60 | /** @var Database $trapsDB Database class*/ |
61 | - public $trapsDB = null; |
|
61 | + public $trapsDB=null; |
|
62 | 62 | |
63 | 63 | // Trap received data |
64 | 64 | protected $receivingHost; |
@@ -74,18 +74,18 @@ discard block |
||
74 | 74 | protected $trapToDb=true; |
75 | 75 | |
76 | 76 | /** @var Mib mib class */ |
77 | - public $mibClass = null; |
|
77 | + public $mibClass=null; |
|
78 | 78 | |
79 | 79 | /** @var Rule rule class */ |
80 | - public $ruleClass = null; |
|
80 | + public $ruleClass=null; |
|
81 | 81 | |
82 | 82 | /** @var Plugins plugins manager **/ |
83 | - public $pluginClass = null; |
|
83 | + public $pluginClass=null; |
|
84 | 84 | |
85 | 85 | /** @var TrapApi $trapApiClass */ |
86 | - public $trapApiClass = null; |
|
86 | + public $trapApiClass=null; |
|
87 | 87 | |
88 | - function __construct($etcDir='/etc/icingaweb2',$baseLogLevel=null,$baseLogMode='syslog',$baseLogFile='') |
|
88 | + function __construct($etcDir='/etc/icingaweb2', $baseLogLevel=null, $baseLogMode='syslog', $baseLogFile='') |
|
89 | 89 | { |
90 | 90 | // Paths of ini files |
91 | 91 | $this->icingaweb2Etc=$etcDir; |
@@ -93,10 +93,10 @@ discard block |
||
93 | 93 | $this->icingaweb2Ressources=$this->icingaweb2Etc."/resources.ini"; |
94 | 94 | |
95 | 95 | //************* Setup logging |
96 | - $this->logging = new Logging(); |
|
96 | + $this->logging=new Logging(); |
|
97 | 97 | if ($baseLogLevel != null) |
98 | 98 | { |
99 | - $this->logging->setLogging($baseLogLevel, $baseLogMode,$baseLogFile); |
|
99 | + $this->logging->setLogging($baseLogLevel, $baseLogMode, $baseLogFile); |
|
100 | 100 | $this->logSetup=true; |
101 | 101 | } |
102 | 102 | else |
@@ -108,17 +108,17 @@ discard block |
||
108 | 108 | |
109 | 109 | // Create distributed API object |
110 | 110 | |
111 | - $this->trapApiClass = new TrapApi($this->logging); |
|
111 | + $this->trapApiClass=new TrapApi($this->logging); |
|
112 | 112 | |
113 | 113 | //*************** Get options from ini files |
114 | - if (! is_file($this->trapModuleConfig)) |
|
114 | + if (!is_file($this->trapModuleConfig)) |
|
115 | 115 | { |
116 | 116 | throw new Exception("Ini file ".$this->trapModuleConfig." does not exists"); |
117 | 117 | } |
118 | - $trapConfig=parse_ini_file($this->trapModuleConfig,true); |
|
118 | + $trapConfig=parse_ini_file($this->trapModuleConfig, true); |
|
119 | 119 | if ($trapConfig == false) |
120 | 120 | { |
121 | - $this->logging->log("Error reading ini file : ".$this->trapModuleConfig,ERROR,'syslog'); |
|
121 | + $this->logging->log("Error reading ini file : ".$this->trapModuleConfig, ERROR, 'syslog'); |
|
122 | 122 | throw new Exception("Error reading ini file : ".$this->trapModuleConfig); |
123 | 123 | } |
124 | 124 | $this->getMainOptions($trapConfig); // Get main options from ini file |
@@ -132,10 +132,10 @@ discard block |
||
132 | 132 | if ($this->apiUse === true) $this->getAPI(); // Setup API |
133 | 133 | |
134 | 134 | //*************** Setup MIB |
135 | - $this->mibClass = new Mib($this->logging,$this->trapsDB,$this->snmptranslate,$this->snmptranslate_dirs); // Create Mib class |
|
135 | + $this->mibClass=new Mib($this->logging, $this->trapsDB, $this->snmptranslate, $this->snmptranslate_dirs); // Create Mib class |
|
136 | 136 | |
137 | 137 | //*************** Setup Rule |
138 | - $this->ruleClass = new Rule($this); //< Create Rule class |
|
138 | + $this->ruleClass=new Rule($this); //< Create Rule class |
|
139 | 139 | |
140 | 140 | $this->trapData=array( // TODO : put this in a reset function (DAEMON_MODE) |
141 | 141 | 'source_ip' => 'unknown', |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | |
148 | 148 | //*************** Setup Plugins |
149 | 149 | //Create plugin class. Plugins are not loaded here, but by calling registerAllPlugins |
150 | - $this->pluginClass = new Plugins($this); |
|
150 | + $this->pluginClass=new Plugins($this); |
|
151 | 151 | |
152 | 152 | |
153 | 153 | } |
@@ -176,15 +176,15 @@ discard block |
||
176 | 176 | * @param string $destination file/syslog/display |
177 | 177 | * @return void |
178 | 178 | **/ |
179 | - public function trapLog( $message, $level, $destination ='') // OBSOLETE |
|
179 | + public function trapLog($message, $level, $destination='') // OBSOLETE |
|
180 | 180 | { |
181 | 181 | // TODO : replace ref with $this->logging->log |
182 | 182 | $this->logging->log($message, $level, $destination); |
183 | 183 | } |
184 | 184 | |
185 | - public function setLogging($debugLvl,$outputType,$outputOption=null) // OBSOLETE |
|
185 | + public function setLogging($debugLvl, $outputType, $outputOption=null) // OBSOLETE |
|
186 | 186 | { |
187 | - $this->logging->setLogging($debugLvl, $outputType,$outputOption); |
|
187 | + $this->logging->setLogging($debugLvl, $outputType, $outputOption); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | { |
196 | 196 | if ($this->icinga2api == null) |
197 | 197 | { |
198 | - $this->icinga2api = new Icinga2API($this->apiHostname,$this->apiPort); |
|
198 | + $this->icinga2api=new Icinga2API($this->apiHostname, $this->apiPort); |
|
199 | 199 | } |
200 | 200 | return $this->icinga2api; |
201 | 201 | } |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | if ($input_stream === false) |
215 | 215 | { |
216 | 216 | $this->writeTrapErrorToDB("Error reading trap (code 1/Stdin)"); |
217 | - $this->logging->log("Error reading stdin !",ERROR,''); |
|
217 | + $this->logging->log("Error reading stdin !", ERROR, ''); |
|
218 | 218 | return null; // note : exception thrown by logging |
219 | 219 | } |
220 | 220 | |
@@ -223,21 +223,21 @@ discard block |
||
223 | 223 | if ($this->receivingHost === false) |
224 | 224 | { |
225 | 225 | $this->writeTrapErrorToDB("Error reading trap (code 1/Line Host)"); |
226 | - $this->logging->log("Error reading Host !",ERROR,''); |
|
226 | + $this->logging->log("Error reading Host !", ERROR, ''); |
|
227 | 227 | } |
228 | 228 | // line 2 IP:port=>IP:port |
229 | 229 | $IP=chop(fgets($input_stream)); |
230 | 230 | if ($IP === false) |
231 | 231 | { |
232 | 232 | $this->writeTrapErrorToDB("Error reading trap (code 1/Line IP)"); |
233 | - $this->logging->log("Error reading IP !",ERROR,''); |
|
233 | + $this->logging->log("Error reading IP !", ERROR, ''); |
|
234 | 234 | } |
235 | 235 | $matches=array(); |
236 | - $ret_code=preg_match('/.DP: \[(.*)\]:(.*)->\[(.*)\]:(.*)/',$IP,$matches); |
|
237 | - if ($ret_code===0 || $ret_code===false) |
|
236 | + $ret_code=preg_match('/.DP: \[(.*)\]:(.*)->\[(.*)\]:(.*)/', $IP, $matches); |
|
237 | + if ($ret_code === 0 || $ret_code === false) |
|
238 | 238 | { |
239 | 239 | $this->writeTrapErrorToDB("Error parsing trap (code 2/IP)"); |
240 | - $this->logging->log('Error parsing IP : '.$IP,ERROR,''); |
|
240 | + $this->logging->log('Error parsing IP : '.$IP, ERROR, ''); |
|
241 | 241 | } |
242 | 242 | else |
243 | 243 | { |
@@ -247,41 +247,41 @@ discard block |
||
247 | 247 | $this->trapData['destination_port']=$matches[4]; |
248 | 248 | } |
249 | 249 | |
250 | - while (($vars=fgets($input_stream)) !==false) |
|
250 | + while (($vars=fgets($input_stream)) !== false) |
|
251 | 251 | { |
252 | 252 | $vars=chop($vars); |
253 | - $ret_code=preg_match('/^([^ ]+) (.*)$/',$vars,$matches); |
|
254 | - if ($ret_code===0 || $ret_code===false) |
|
253 | + $ret_code=preg_match('/^([^ ]+) (.*)$/', $vars, $matches); |
|
254 | + if ($ret_code === 0 || $ret_code === false) |
|
255 | 255 | { |
256 | - $this->logging->log('No match on trap data : '.$vars,WARN,''); |
|
256 | + $this->logging->log('No match on trap data : '.$vars, WARN, ''); |
|
257 | 257 | continue; |
258 | 258 | } |
259 | - if (($matches[1]=='.1.3.6.1.6.3.1.1.4.1.0') || ($matches[1]=='.1.3.6.1.6.3.1.1.4.1')) |
|
259 | + if (($matches[1] == '.1.3.6.1.6.3.1.1.4.1.0') || ($matches[1] == '.1.3.6.1.6.3.1.1.4.1')) |
|
260 | 260 | { |
261 | 261 | $this->trapData['trap_oid']=$matches[2]; |
262 | 262 | continue; |
263 | 263 | } |
264 | - if ( $this->useSnmpTrapAddess === TRUE && preg_match('/'.$this->snmpTrapAddressOID.'/', $matches[1]) == 1) |
|
264 | + if ($this->useSnmpTrapAddess === TRUE && preg_match('/'.$this->snmpTrapAddressOID.'/', $matches[1]) == 1) |
|
265 | 265 | { |
266 | - $this->logging->log('Found relayed trap from ' . $matches[2] . ' relayed by ' .$this->trapData['source_ip'],DEBUG); |
|
267 | - if (preg_match('/^[0-9\.]+$/',$matches[2]) == 0 && preg_match('/^[0-9a-fA-F:]+$/',$matches[2]) == 0) |
|
266 | + $this->logging->log('Found relayed trap from '.$matches[2].' relayed by '.$this->trapData['source_ip'], DEBUG); |
|
267 | + if (preg_match('/^[0-9\.]+$/', $matches[2]) == 0 && preg_match('/^[0-9a-fA-F:]+$/', $matches[2]) == 0) |
|
268 | 268 | { |
269 | - $this->logging->log('Value of SnmpTrapAddess ('.$this->snmpTrapAddressOID.') is not IP : ' .$matches[2],WARN,''); |
|
269 | + $this->logging->log('Value of SnmpTrapAddess ('.$this->snmpTrapAddressOID.') is not IP : '.$matches[2], WARN, ''); |
|
270 | 270 | continue; |
271 | 271 | } |
272 | - $this->trapData['source_ip'] = $matches[2]; |
|
272 | + $this->trapData['source_ip']=$matches[2]; |
|
273 | 273 | continue; |
274 | 274 | } |
275 | - $object= new stdClass; |
|
276 | - $object->oid =$matches[1]; |
|
277 | - $object->value = $matches[2]; |
|
278 | - array_push($this->trapDataExt,$object); |
|
275 | + $object=new stdClass; |
|
276 | + $object->oid=$matches[1]; |
|
277 | + $object->value=$matches[2]; |
|
278 | + array_push($this->trapDataExt, $object); |
|
279 | 279 | } |
280 | 280 | |
281 | - if ($this->trapData['trap_oid']=='unknown') |
|
281 | + if ($this->trapData['trap_oid'] == 'unknown') |
|
282 | 282 | { |
283 | - $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)",$this->trapData['source_ip']); |
|
284 | - $this->logging->log('no trap oid found',ERROR,''); |
|
283 | + $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)", $this->trapData['source_ip']); |
|
284 | + $this->logging->log('no trap oid found', ERROR, ''); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | // Translate oids. |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | } |
304 | 304 | |
305 | 305 | |
306 | - $this->trapData['status']= 'waiting'; |
|
306 | + $this->trapData['status']='waiting'; |
|
307 | 307 | |
308 | 308 | return $this->trapData; |
309 | 309 | } |
@@ -319,40 +319,40 @@ discard block |
||
319 | 319 | $db_conn=$this->trapsDB->db_connect_trap(); |
320 | 320 | |
321 | 321 | $sql='SELECT mib,name from '.$this->dbPrefix.'mib_cache WHERE oid=\''.$oid.'\';'; |
322 | - $this->logging->log('SQL query : '.$sql,DEBUG ); |
|
322 | + $this->logging->log('SQL query : '.$sql, DEBUG); |
|
323 | 323 | if (($ret_code=$db_conn->query($sql)) === false) { |
324 | - $this->logging->log('No result in query : ' . $sql,ERROR,''); |
|
324 | + $this->logging->log('No result in query : '.$sql, ERROR, ''); |
|
325 | 325 | } |
326 | 326 | $name=$ret_code->fetch(); |
327 | 327 | if ($name['name'] != null) |
328 | 328 | { |
329 | - return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']); |
|
329 | + return array('trap_name_mib'=>$name['mib'], 'trap_name'=>$name['name']); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | // Also check if it is an instance of OID |
333 | - $oid_instance=preg_replace('/\.[0-9]+$/','',$oid); |
|
333 | + $oid_instance=preg_replace('/\.[0-9]+$/', '', $oid); |
|
334 | 334 | |
335 | 335 | $sql='SELECT mib,name from '.$this->dbPrefix.'mib_cache WHERE oid=\''.$oid_instance.'\';'; |
336 | - $this->logging->log('SQL query : '.$sql,DEBUG ); |
|
336 | + $this->logging->log('SQL query : '.$sql, DEBUG); |
|
337 | 337 | if (($ret_code=$db_conn->query($sql)) === false) { |
338 | - $this->logging->log('No result in query : ' . $sql,ERROR,''); |
|
338 | + $this->logging->log('No result in query : '.$sql, ERROR, ''); |
|
339 | 339 | } |
340 | 340 | $name=$ret_code->fetch(); |
341 | 341 | if ($name['name'] != null) |
342 | 342 | { |
343 | - return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']); |
|
343 | + return array('trap_name_mib'=>$name['mib'], 'trap_name'=>$name['name']); |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | // Try to get oid name from snmptranslate |
347 | - $translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs. |
|
347 | + $translate=exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs. |
|
348 | 348 | ' '.$oid); |
349 | 349 | $matches=array(); |
350 | - $ret_code=preg_match('/(.*)::(.*)/',$translate,$matches); |
|
351 | - if ($ret_code===0 || $ret_code === false) { |
|
350 | + $ret_code=preg_match('/(.*)::(.*)/', $translate, $matches); |
|
351 | + if ($ret_code === 0 || $ret_code === false) { |
|
352 | 352 | return NULL; |
353 | 353 | } else { |
354 | - $this->logging->log('Found name with snmptrapd and not in DB for oid='.$oid,INFO); |
|
355 | - return array('trap_name_mib'=>$matches[1],'trap_name'=>$matches[2]); |
|
354 | + $this->logging->log('Found name with snmptrapd and not in DB for oid='.$oid, INFO); |
|
355 | + return array('trap_name_mib'=>$matches[1], 'trap_name'=>$matches[2]); |
|
356 | 356 | } |
357 | 357 | } |
358 | 358 | |
@@ -363,90 +363,90 @@ discard block |
||
363 | 363 | **/ |
364 | 364 | public function eraseOldTraps($days=0) |
365 | 365 | { |
366 | - if ($days==0) |
|
366 | + if ($days == 0) |
|
367 | 367 | { |
368 | 368 | if (($days=$this->getDBConfig('db_remove_days')) == null) |
369 | 369 | { |
370 | - $this->logging->log('No days specified & no db value : no tap erase' ,WARN,''); |
|
370 | + $this->logging->log('No days specified & no db value : no tap erase', WARN, ''); |
|
371 | 371 | return; |
372 | 372 | } |
373 | 373 | } |
374 | 374 | $db_conn=$this->trapsDB->db_connect_trap(); |
375 | - $daysago = strtotime("-".$days." day"); |
|
376 | - $sql= 'delete from '.$this->dbPrefix.'received where date_received < \''.date("Y-m-d H:i:s",$daysago).'\';'; |
|
375 | + $daysago=strtotime("-".$days." day"); |
|
376 | + $sql='delete from '.$this->dbPrefix.'received where date_received < \''.date("Y-m-d H:i:s", $daysago).'\';'; |
|
377 | 377 | if ($db_conn->query($sql) === false) { |
378 | - $this->logging->log('Error erasing traps : '.$sql,ERROR,''); |
|
378 | + $this->logging->log('Error erasing traps : '.$sql, ERROR, ''); |
|
379 | 379 | } |
380 | - $this->logging->log('Erased traps older than '.$days.' day(s) : '.$sql,INFO); |
|
380 | + $this->logging->log('Erased traps older than '.$days.' day(s) : '.$sql, INFO); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | /** Write error to received trap database |
384 | 384 | */ |
385 | - public function writeTrapErrorToDB($message,$sourceIP=null,$trapoid=null) |
|
385 | + public function writeTrapErrorToDB($message, $sourceIP=null, $trapoid=null) |
|
386 | 386 | { |
387 | 387 | |
388 | 388 | $db_conn=$this->trapsDB->db_connect_trap(); |
389 | 389 | |
390 | 390 | // add date time |
391 | - $insert_col ='date_received,status'; |
|
392 | - $insert_val = "'" . date("Y-m-d H:i:s")."','error'"; |
|
391 | + $insert_col='date_received,status'; |
|
392 | + $insert_val="'".date("Y-m-d H:i:s")."','error'"; |
|
393 | 393 | |
394 | - if ($sourceIP !=null) |
|
394 | + if ($sourceIP != null) |
|
395 | 395 | { |
396 | - $insert_col .=',source_ip'; |
|
397 | - $insert_val .=",'". $sourceIP ."'"; |
|
396 | + $insert_col.=',source_ip'; |
|
397 | + $insert_val.=",'".$sourceIP."'"; |
|
398 | 398 | } |
399 | - if ($trapoid !=null) |
|
399 | + if ($trapoid != null) |
|
400 | 400 | { |
401 | - $insert_col .=',trap_oid'; |
|
402 | - $insert_val .=",'". $trapoid ."'"; |
|
401 | + $insert_col.=',trap_oid'; |
|
402 | + $insert_val.=",'".$trapoid."'"; |
|
403 | 403 | } |
404 | - $insert_col .=',status_detail'; |
|
405 | - $insert_val .=",'". $message ."'"; |
|
404 | + $insert_col.=',status_detail'; |
|
405 | + $insert_val.=",'".$message."'"; |
|
406 | 406 | |
407 | - $sql= 'INSERT INTO '.$this->dbPrefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')'; |
|
407 | + $sql='INSERT INTO '.$this->dbPrefix.'received ('.$insert_col.') VALUES ('.$insert_val.')'; |
|
408 | 408 | |
409 | 409 | switch ($this->trapsDB->trapDBType) |
410 | 410 | { |
411 | 411 | case 'pgsql': |
412 | - $sql .= ' RETURNING id;'; |
|
413 | - $this->logging->log('sql : '.$sql,INFO); |
|
412 | + $sql.=' RETURNING id;'; |
|
413 | + $this->logging->log('sql : '.$sql, INFO); |
|
414 | 414 | if (($ret_code=$db_conn->query($sql)) === false) { |
415 | - $this->logging->log('Error SQL insert : '.$sql,1,''); |
|
415 | + $this->logging->log('Error SQL insert : '.$sql, 1, ''); |
|
416 | 416 | } |
417 | - $this->logging->log('SQL insertion OK',INFO ); |
|
417 | + $this->logging->log('SQL insertion OK', INFO); |
|
418 | 418 | // Get last id to insert oid/values in secondary table |
419 | 419 | if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) { |
420 | 420 | |
421 | - $this->logging->log('Erreur recuperation id',1,''); |
|
421 | + $this->logging->log('Erreur recuperation id', 1, ''); |
|
422 | 422 | } |
423 | - if (! isset($inserted_id_ret['id'])) { |
|
424 | - $this->logging->log('Error getting id',1,''); |
|
423 | + if (!isset($inserted_id_ret['id'])) { |
|
424 | + $this->logging->log('Error getting id', 1, ''); |
|
425 | 425 | } |
426 | 426 | $this->trapId=$inserted_id_ret['id']; |
427 | 427 | break; |
428 | 428 | case 'mysql': |
429 | - $sql .= ';'; |
|
430 | - $this->logging->log('sql : '.$sql,INFO ); |
|
429 | + $sql.=';'; |
|
430 | + $this->logging->log('sql : '.$sql, INFO); |
|
431 | 431 | if ($db_conn->query($sql) === false) { |
432 | - $this->logging->log('Error SQL insert : '.$sql,1,''); |
|
432 | + $this->logging->log('Error SQL insert : '.$sql, 1, ''); |
|
433 | 433 | } |
434 | - $this->logging->log('SQL insertion OK',INFO ); |
|
434 | + $this->logging->log('SQL insertion OK', INFO); |
|
435 | 435 | // Get last id to insert oid/values in secondary table |
436 | 436 | $sql='SELECT LAST_INSERT_ID();'; |
437 | 437 | if (($ret_code=$db_conn->query($sql)) === false) { |
438 | - $this->logging->log('Erreur recuperation id',1,''); |
|
438 | + $this->logging->log('Erreur recuperation id', 1, ''); |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
442 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
442 | + if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
443 | 443 | $this->trapId=$inserted_id; |
444 | 444 | break; |
445 | 445 | default: |
446 | - $this->logging->log('Error SQL type unknown : '.$this->trapsDB->trapDBType,1,''); |
|
446 | + $this->logging->log('Error SQL type unknown : '.$this->trapsDB->trapDBType, 1, ''); |
|
447 | 447 | } |
448 | 448 | |
449 | - $this->logging->log('id found: '. $this->trapId,INFO ); |
|
449 | + $this->logging->log('id found: '.$this->trapId, INFO); |
|
450 | 450 | } |
451 | 451 | |
452 | 452 | /** Write trap data to trap database |
@@ -463,86 +463,86 @@ discard block |
||
463 | 463 | $insert_col=''; |
464 | 464 | $insert_val=''; |
465 | 465 | // add date time |
466 | - $this->trapData['date_received'] = date("Y-m-d H:i:s"); |
|
466 | + $this->trapData['date_received']=date("Y-m-d H:i:s"); |
|
467 | 467 | |
468 | 468 | $firstcol=1; |
469 | 469 | foreach ($this->trapData as $col => $val) |
470 | 470 | { |
471 | - if ($firstcol==0) |
|
471 | + if ($firstcol == 0) |
|
472 | 472 | { |
473 | - $insert_col .=','; |
|
474 | - $insert_val .=','; |
|
473 | + $insert_col.=','; |
|
474 | + $insert_val.=','; |
|
475 | 475 | } |
476 | - $insert_col .= $col ; |
|
477 | - $insert_val .= ($val==null)? 'NULL' : $db_conn->quote($val); |
|
476 | + $insert_col.=$col; |
|
477 | + $insert_val.=($val == null) ? 'NULL' : $db_conn->quote($val); |
|
478 | 478 | $firstcol=0; |
479 | 479 | } |
480 | 480 | |
481 | - $sql= 'INSERT INTO '.$this->dbPrefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')'; |
|
481 | + $sql='INSERT INTO '.$this->dbPrefix.'received ('.$insert_col.') VALUES ('.$insert_val.')'; |
|
482 | 482 | switch ($this->trapsDB->trapDBType) |
483 | 483 | { |
484 | 484 | case 'pgsql': |
485 | - $sql .= ' RETURNING id;'; |
|
486 | - $this->logging->log('sql : '.$sql,INFO ); |
|
485 | + $sql.=' RETURNING id;'; |
|
486 | + $this->logging->log('sql : '.$sql, INFO); |
|
487 | 487 | if (($ret_code=$db_conn->query($sql)) === false) { |
488 | - $this->logging->log('Error SQL insert : '.$sql,ERROR,''); |
|
488 | + $this->logging->log('Error SQL insert : '.$sql, ERROR, ''); |
|
489 | 489 | } |
490 | - $this->logging->log('SQL insertion OK',INFO ); |
|
490 | + $this->logging->log('SQL insertion OK', INFO); |
|
491 | 491 | // Get last id to insert oid/values in secondary table |
492 | 492 | if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) { |
493 | 493 | |
494 | - $this->logging->log('Erreur recuperation id',ERROR,''); |
|
494 | + $this->logging->log('Erreur recuperation id', ERROR, ''); |
|
495 | 495 | } |
496 | - if (! isset($inserted_id_ret['id'])) { |
|
497 | - $this->logging->log('Error getting id',ERROR,''); |
|
496 | + if (!isset($inserted_id_ret['id'])) { |
|
497 | + $this->logging->log('Error getting id', ERROR, ''); |
|
498 | 498 | } |
499 | 499 | $this->trapId=$inserted_id_ret['id']; |
500 | 500 | break; |
501 | 501 | case 'mysql': |
502 | - $sql .= ';'; |
|
503 | - $this->logging->log('sql : '.$sql,INFO ); |
|
502 | + $sql.=';'; |
|
503 | + $this->logging->log('sql : '.$sql, INFO); |
|
504 | 504 | if ($db_conn->query($sql) === false) { |
505 | - $this->logging->log('Error SQL insert : '.$sql,ERROR,''); |
|
505 | + $this->logging->log('Error SQL insert : '.$sql, ERROR, ''); |
|
506 | 506 | } |
507 | - $this->logging->log('SQL insertion OK',INFO ); |
|
507 | + $this->logging->log('SQL insertion OK', INFO); |
|
508 | 508 | // Get last id to insert oid/values in secondary table |
509 | 509 | $sql='SELECT LAST_INSERT_ID();'; |
510 | 510 | if (($ret_code=$db_conn->query($sql)) === false) { |
511 | - $this->logging->log('Erreur recuperation id',ERROR,''); |
|
511 | + $this->logging->log('Erreur recuperation id', ERROR, ''); |
|
512 | 512 | } |
513 | 513 | |
514 | 514 | $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
515 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
515 | + if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
516 | 516 | $this->trapId=$inserted_id; |
517 | 517 | break; |
518 | 518 | default: |
519 | - $this->logging->log('Error SQL type unknown : '.$this->trapsDB->trapDBType,ERROR,''); |
|
519 | + $this->logging->log('Error SQL type unknown : '.$this->trapsDB->trapDBType, ERROR, ''); |
|
520 | 520 | } |
521 | - $this->logging->log('id found: '.$this->trapId,INFO ); |
|
521 | + $this->logging->log('id found: '.$this->trapId, INFO); |
|
522 | 522 | |
523 | 523 | // Fill trap extended data table |
524 | 524 | foreach ($this->trapDataExt as $value) { |
525 | 525 | // TODO : detect if trap value is encoded and decode it to UTF-8 for database |
526 | 526 | $firstcol=1; |
527 | - $value->trap_id = $this->trapId; |
|
527 | + $value->trap_id=$this->trapId; |
|
528 | 528 | $insert_col=''; |
529 | 529 | $insert_val=''; |
530 | 530 | foreach ($value as $col => $val) |
531 | 531 | { |
532 | - if ($firstcol==0) |
|
532 | + if ($firstcol == 0) |
|
533 | 533 | { |
534 | - $insert_col .=','; |
|
535 | - $insert_val .=','; |
|
534 | + $insert_col.=','; |
|
535 | + $insert_val.=','; |
|
536 | 536 | } |
537 | - $insert_col .= $col; |
|
538 | - $insert_val .= ($val==null)? 'NULL' : $db_conn->quote($val); |
|
537 | + $insert_col.=$col; |
|
538 | + $insert_val.=($val == null) ? 'NULL' : $db_conn->quote($val); |
|
539 | 539 | $firstcol=0; |
540 | 540 | } |
541 | 541 | |
542 | - $sql= 'INSERT INTO '.$this->dbPrefix.'received_data (' . $insert_col . ') VALUES ('.$insert_val.');'; |
|
542 | + $sql='INSERT INTO '.$this->dbPrefix.'received_data ('.$insert_col.') VALUES ('.$insert_val.');'; |
|
543 | 543 | |
544 | 544 | if ($db_conn->query($sql) === false) { |
545 | - $this->logging->log('Erreur insertion data : ' . $sql,WARN,''); |
|
545 | + $this->logging->log('Erreur insertion data : '.$sql, WARN, ''); |
|
546 | 546 | } |
547 | 547 | } |
548 | 548 | } |
@@ -552,14 +552,14 @@ discard block |
||
552 | 552 | * @param $oid string oid in numeric |
553 | 553 | * @return mixed|boolean : PDO object or false |
554 | 554 | */ |
555 | - protected function getRules($ip,$oid) |
|
555 | + protected function getRules($ip, $oid) |
|
556 | 556 | { |
557 | 557 | $db_conn=$this->trapsDB->db_connect_trap(); |
558 | 558 | // fetch rules based on IP in rule and OID |
559 | 559 | $sql='SELECT * from '.$this->dbPrefix.'rules WHERE trap_oid=\''.$oid.'\' '; |
560 | - $this->logging->log('SQL query : '.$sql,DEBUG ); |
|
560 | + $this->logging->log('SQL query : '.$sql, DEBUG); |
|
561 | 561 | if (($ret_code=$db_conn->query($sql)) === false) { |
562 | - $this->logging->log('No result in query : ' . $sql,WARN,''); |
|
562 | + $this->logging->log('No result in query : '.$sql, WARN, ''); |
|
563 | 563 | return false; |
564 | 564 | } |
565 | 565 | $rules_all=$ret_code->fetchAll(); |
@@ -568,7 +568,7 @@ discard block |
||
568 | 568 | $rule_ret_key=0; |
569 | 569 | foreach ($rules_all as $key => $rule) |
570 | 570 | { |
571 | - if ($rule['ip4']==$ip || $rule['ip6']==$ip) |
|
571 | + if ($rule['ip4'] == $ip || $rule['ip6'] == $ip) |
|
572 | 572 | { |
573 | 573 | $rules_ret[$rule_ret_key]=$rules_all[$key]; |
574 | 574 | //TODO : get host name by API (and check if correct in rule). |
@@ -576,7 +576,7 @@ discard block |
||
576 | 576 | continue; |
577 | 577 | } |
578 | 578 | // TODO : get hosts IP by API |
579 | - if (isset($rule['host_group_name']) && $rule['host_group_name']!=null) |
|
579 | + if (isset($rule['host_group_name']) && $rule['host_group_name'] != null) |
|
580 | 580 | { // get ips of group members by oid |
581 | 581 | $db_conn2=$this->trapsDB->db_connect_ido(); |
582 | 582 | $sql="SELECT m.host_object_id, a.address as ip4, a.address6 as ip6, b.name1 as host_name |
@@ -587,15 +587,15 @@ discard block |
||
587 | 587 | LEFT JOIN icinga_objects as b ON b.object_id = a.host_object_id |
588 | 588 | WHERE o.name1='".$rule['host_group_name']."';"; |
589 | 589 | if (($ret_code2=$db_conn2->query($sql)) === false) { |
590 | - $this->logging->log('No result in query : ' . $sql,WARN,''); |
|
590 | + $this->logging->log('No result in query : '.$sql, WARN, ''); |
|
591 | 591 | continue; |
592 | 592 | } |
593 | 593 | $grouphosts=$ret_code2->fetchAll(); |
594 | 594 | //echo "rule grp :\n";print_r($grouphosts);echo "\n"; |
595 | - foreach ( $grouphosts as $host) |
|
595 | + foreach ($grouphosts as $host) |
|
596 | 596 | { |
597 | 597 | //echo $host['ip4']."\n"; |
598 | - if ($host['ip4']==$ip || $host['ip6']==$ip) |
|
598 | + if ($host['ip4'] == $ip || $host['ip6'] == $ip) |
|
599 | 599 | { |
600 | 600 | //echo "Rule added \n"; |
601 | 601 | $rules_ret[$rule_ret_key]=$rules_all[$key]; |
@@ -618,7 +618,7 @@ discard block |
||
618 | 618 | $db_conn=$this->trapsDB->db_connect_trap(); |
619 | 619 | $sql="UPDATE ".$this->dbPrefix."rules SET num_match = '".$set."' WHERE (id = '".$id."');"; |
620 | 620 | if ($db_conn->query($sql) === false) { |
621 | - $this->logging->log('Error in update query : ' . $sql,WARN,''); |
|
621 | + $this->logging->log('Error in update query : '.$sql, WARN, ''); |
|
622 | 622 | } |
623 | 623 | } |
624 | 624 | |
@@ -630,23 +630,23 @@ discard block |
||
630 | 630 | * @param string $display |
631 | 631 | * @returnn bool true is service check was sent without error |
632 | 632 | */ |
633 | - public function serviceCheckResult($host,$service,$state,$display) |
|
633 | + public function serviceCheckResult($host, $service, $state, $display) |
|
634 | 634 | { |
635 | 635 | if ($this->apiUse === false) |
636 | 636 | { |
637 | - $send = '[' . date('U') .'] PROCESS_SERVICE_CHECK_RESULT;' . |
|
638 | - $host.';' .$service .';' . $state . ';'.$display; |
|
639 | - $this->logging->log( $send." : to : " .$this->icinga2cmd,INFO ); |
|
637 | + $send='['.date('U').'] PROCESS_SERVICE_CHECK_RESULT;'. |
|
638 | + $host.';'.$service.';'.$state.';'.$display; |
|
639 | + $this->logging->log($send." : to : ".$this->icinga2cmd, INFO); |
|
640 | 640 | |
641 | 641 | // TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default.... |
642 | - exec('echo "'.$send.'" > ' .$this->icinga2cmd); |
|
642 | + exec('echo "'.$send.'" > '.$this->icinga2cmd); |
|
643 | 643 | return true; |
644 | 644 | } |
645 | 645 | else |
646 | 646 | { |
647 | 647 | // Get perfdata if found |
648 | 648 | $matches=array(); |
649 | - if (preg_match('/(.*)\|(.*)/',$display,$matches) == 1) |
|
649 | + if (preg_match('/(.*)\|(.*)/', $display, $matches) == 1) |
|
650 | 650 | { |
651 | 651 | $display=$matches[1]; |
652 | 652 | $perfdata=$matches[2]; |
@@ -656,17 +656,17 @@ discard block |
||
656 | 656 | $perfdata=''; |
657 | 657 | } |
658 | 658 | |
659 | - $api = $this->getAPI(); |
|
659 | + $api=$this->getAPI(); |
|
660 | 660 | $api->setCredentials($this->apiUsername, $this->apiPassword); |
661 | - list($retcode,$retmessage)=$api->serviceCheckResult($host,$service,$state,$display,$perfdata); |
|
661 | + list($retcode, $retmessage)=$api->serviceCheckResult($host, $service, $state, $display, $perfdata); |
|
662 | 662 | if ($retcode == false) |
663 | 663 | { |
664 | - $this->logging->log( "Error sending result : " .$retmessage,WARN,''); |
|
664 | + $this->logging->log("Error sending result : ".$retmessage, WARN, ''); |
|
665 | 665 | return false; |
666 | 666 | } |
667 | 667 | else |
668 | 668 | { |
669 | - $this->logging->log( "Sent result : " .$retmessage,INFO ); |
|
669 | + $this->logging->log("Sent result : ".$retmessage, INFO); |
|
670 | 670 | return true; |
671 | 671 | } |
672 | 672 | } |
@@ -674,7 +674,7 @@ discard block |
||
674 | 674 | |
675 | 675 | public function getHostByIP($ip) |
676 | 676 | { |
677 | - $api = $this->getAPI(); |
|
677 | + $api=$this->getAPI(); |
|
678 | 678 | $api->setCredentials($this->apiUsername, $this->apiPassword); |
679 | 679 | return $api->getHostByIP($ip); |
680 | 680 | } |
@@ -687,35 +687,35 @@ discard block |
||
687 | 687 | protected function applyDisplay($display) |
688 | 688 | { |
689 | 689 | $matches=array(); |
690 | - while (preg_match('/_OID\(([0-9\.\*]+)\)/',$display,$matches) == 1) |
|
690 | + while (preg_match('/_OID\(([0-9\.\*]+)\)/', $display, $matches) == 1) |
|
691 | 691 | { |
692 | 692 | $oid=$matches[1]; |
693 | 693 | $found=0; |
694 | 694 | // Test and transform regexp |
695 | - $oidR = $this->ruleClass->regexp_eval($oid); |
|
695 | + $oidR=$this->ruleClass->regexp_eval($oid); |
|
696 | 696 | |
697 | - foreach($this->trapDataExt as $val) |
|
697 | + foreach ($this->trapDataExt as $val) |
|
698 | 698 | { |
699 | - if (preg_match("/^$oidR$/",$val->oid) == 1) |
|
699 | + if (preg_match("/^$oidR$/", $val->oid) == 1) |
|
700 | 700 | { |
701 | - $val->value=preg_replace('/"/','',$val->value); |
|
701 | + $val->value=preg_replace('/"/', '', $val->value); |
|
702 | 702 | $rep=0; |
703 | - $display=preg_replace('/_OID\('.$oid.'\)/',$val->value,$display,-1,$rep); |
|
704 | - if ($rep==0) |
|
703 | + $display=preg_replace('/_OID\('.$oid.'\)/', $val->value, $display, -1, $rep); |
|
704 | + if ($rep == 0) |
|
705 | 705 | { |
706 | - $this->logging->log("Error in display",WARN,''); |
|
706 | + $this->logging->log("Error in display", WARN, ''); |
|
707 | 707 | return $display; |
708 | 708 | } |
709 | 709 | $found=1; |
710 | 710 | break; |
711 | 711 | } |
712 | 712 | } |
713 | - if ($found==0) |
|
713 | + if ($found == 0) |
|
714 | 714 | { |
715 | - $display=preg_replace('/_OID\('.$oid.'\)/','<not in trap>',$display,-1,$rep); |
|
716 | - if ($rep==0) |
|
715 | + $display=preg_replace('/_OID\('.$oid.'\)/', '<not in trap>', $display, -1, $rep); |
|
716 | + if ($rep == 0) |
|
717 | 717 | { |
718 | - $this->logging->log("Error in display",WARN,''); |
|
718 | + $this->logging->log("Error in display", WARN, ''); |
|
719 | 719 | return $display; |
720 | 720 | } |
721 | 721 | } |
@@ -727,11 +727,11 @@ discard block |
||
727 | 727 | */ |
728 | 728 | public function applyRules() |
729 | 729 | { |
730 | - $rules = $this->getRules($this->trapData['source_ip'],$this->trapData['trap_oid']); |
|
730 | + $rules=$this->getRules($this->trapData['source_ip'], $this->trapData['trap_oid']); |
|
731 | 731 | |
732 | - if ($rules===false || count($rules)==0) |
|
732 | + if ($rules === false || count($rules) == 0) |
|
733 | 733 | { |
734 | - $this->logging->log('No rules found for this trap',INFO ); |
|
734 | + $this->logging->log('No rules found for this trap', INFO); |
|
735 | 735 | $this->trapData['status']='unknown'; |
736 | 736 | $this->trapToDb=true; |
737 | 737 | return; |
@@ -746,59 +746,59 @@ discard block |
||
746 | 746 | $service_name=$rule['service_name']; |
747 | 747 | |
748 | 748 | $display=$this->applyDisplay($rule['display']); |
749 | - $this->trapAction = ($this->trapAction==null)? '' : $this->trapAction . ', '; |
|
749 | + $this->trapAction=($this->trapAction == null) ? '' : $this->trapAction.', '; |
|
750 | 750 | try |
751 | 751 | { |
752 | - $this->logging->log('Rule to eval : '.$rule['rule'],INFO ); |
|
753 | - $evalr=$this->ruleClass->eval_rule($rule['rule'], $this->trapDataExt) ; |
|
752 | + $this->logging->log('Rule to eval : '.$rule['rule'], INFO); |
|
753 | + $evalr=$this->ruleClass->eval_rule($rule['rule'], $this->trapDataExt); |
|
754 | 754 | //->eval_rule($rule['rule']); |
755 | 755 | |
756 | 756 | if ($evalr == true) |
757 | 757 | { |
758 | 758 | //$this->logging->log('rules OOK: '.print_r($rule),INFO ); |
759 | 759 | $action=$rule['action_match']; |
760 | - $this->logging->log('action OK : '.$action,INFO ); |
|
760 | + $this->logging->log('action OK : '.$action, INFO); |
|
761 | 761 | if ($action >= 0) |
762 | 762 | { |
763 | - if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false) |
|
763 | + if ($this->serviceCheckResult($host_name, $service_name, $action, $display) == false) |
|
764 | 764 | { |
765 | 765 | $this->trapAction.='Error sending status : check cmd/API'; |
766 | 766 | } |
767 | 767 | else |
768 | 768 | { |
769 | - $this->add_rule_match($rule['id'],$rule['num_match']+1); |
|
769 | + $this->add_rule_match($rule['id'], $rule['num_match'] + 1); |
|
770 | 770 | $this->trapAction.='Status '.$action.' to '.$host_name.'/'.$service_name; |
771 | 771 | } |
772 | 772 | } |
773 | 773 | else |
774 | 774 | { |
775 | - $this->add_rule_match($rule['id'],$rule['num_match']+1); |
|
775 | + $this->add_rule_match($rule['id'], $rule['num_match'] + 1); |
|
776 | 776 | } |
777 | - $this->trapToDb=($action==-2)?false:true; |
|
777 | + $this->trapToDb=($action == -2) ?false:true; |
|
778 | 778 | } |
779 | 779 | else |
780 | 780 | { |
781 | 781 | //$this->logging->log('rules KOO : '.print_r($rule),INFO ); |
782 | 782 | |
783 | 783 | $action=$rule['action_nomatch']; |
784 | - $this->logging->log('action NOK : '.$action,INFO ); |
|
784 | + $this->logging->log('action NOK : '.$action, INFO); |
|
785 | 785 | if ($action >= 0) |
786 | 786 | { |
787 | - if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false) |
|
787 | + if ($this->serviceCheckResult($host_name, $service_name, $action, $display) == false) |
|
788 | 788 | { |
789 | 789 | $this->trapAction.='Error sending status : check cmd/API'; |
790 | 790 | } |
791 | 791 | else |
792 | 792 | { |
793 | - $this->add_rule_match($rule['id'],$rule['num_match']+1); |
|
793 | + $this->add_rule_match($rule['id'], $rule['num_match'] + 1); |
|
794 | 794 | $this->trapAction.='Status '.$action.' to '.$host_name.'/'.$service_name; |
795 | 795 | } |
796 | 796 | } |
797 | 797 | else |
798 | 798 | { |
799 | - $this->add_rule_match($rule['id'],$rule['num_match']+1); |
|
799 | + $this->add_rule_match($rule['id'], $rule['num_match'] + 1); |
|
800 | 800 | } |
801 | - $this->trapToDb=($action==-2)?false:true; |
|
801 | + $this->trapToDb=($action == -2) ?false:true; |
|
802 | 802 | } |
803 | 803 | // Put name in source_name |
804 | 804 | if (!isset($this->trapData['source_name'])) |
@@ -807,7 +807,7 @@ discard block |
||
807 | 807 | } |
808 | 808 | else |
809 | 809 | { |
810 | - if (!preg_match('/'.$rule['host_name'].'/',$this->trapData['source_name'])) |
|
810 | + if (!preg_match('/'.$rule['host_name'].'/', $this->trapData['source_name'])) |
|
811 | 811 | { // only add if not present |
812 | 812 | $this->trapData['source_name'].=','.$rule['host_name']; |
813 | 813 | } |
@@ -815,13 +815,13 @@ discard block |
||
815 | 815 | } |
816 | 816 | catch (Exception $e) |
817 | 817 | { |
818 | - $this->logging->log('Error in rule eval : '.$e->getMessage(),WARN,''); |
|
818 | + $this->logging->log('Error in rule eval : '.$e->getMessage(), WARN, ''); |
|
819 | 819 | $this->trapAction.=' ERR : '.$e->getMessage(); |
820 | 820 | $this->trapData['status']='error'; |
821 | 821 | } |
822 | 822 | |
823 | 823 | } |
824 | - if ($this->trapData['status']=='error') |
|
824 | + if ($this->trapData['status'] == 'error') |
|
825 | 825 | { |
826 | 826 | $this->trapToDb=true; // Always put errors in DB for the use can see |
827 | 827 | } |
@@ -837,13 +837,13 @@ discard block |
||
837 | 837 | public function add_rule_final($time) |
838 | 838 | { |
839 | 839 | $db_conn=$this->trapsDB->db_connect_trap(); |
840 | - if ($this->trapAction==null) |
|
840 | + if ($this->trapAction == null) |
|
841 | 841 | { |
842 | 842 | $this->trapAction='No action'; |
843 | 843 | } |
844 | 844 | $sql="UPDATE ".$this->dbPrefix."received SET process_time = '".$time."' , status_detail='".$this->trapAction."' WHERE (id = '".$this->trapId."');"; |
845 | 845 | if ($db_conn->query($sql) === false) { |
846 | - $this->logging->log('Error in update query : ' . $sql,WARN,''); |
|
846 | + $this->logging->log('Error in update query : '.$sql, WARN, ''); |
|
847 | 847 | } |
848 | 848 | } |
849 | 849 | |
@@ -866,7 +866,7 @@ discard block |
||
866 | 866 | WHERE s.current_state != 0;"; |
867 | 867 | $db_conn=$this->trapsDB->db_connect_ido(); |
868 | 868 | if (($services_db=$db_conn->query($sql_query)) === false) { // set err to 1 to throw exception. |
869 | - $this->logging->log('No result in query : ' . $sql_query,ERROR,''); |
|
869 | + $this->logging->log('No result in query : '.$sql_query, ERROR, ''); |
|
870 | 870 | return 0; |
871 | 871 | } |
872 | 872 | $services=$services_db->fetchAll(); |
@@ -875,7 +875,7 @@ discard block |
||
875 | 875 | $sql_query="SELECT host_name, service_name, revert_ok FROM ".$this->dbPrefix."rules where revert_ok != 0;"; |
876 | 876 | $db_conn2=$this->trapsDB->db_connect_trap(); |
877 | 877 | if (($rules_db=$db_conn2->query($sql_query)) === false) { |
878 | - $this->logging->log('No result in query : ' . $sql_query,ERROR,''); |
|
878 | + $this->logging->log('No result in query : '.$sql_query, ERROR, ''); |
|
879 | 879 | return 0; |
880 | 880 | } |
881 | 881 | $rules=$rules_db->fetchAll(); |
@@ -891,13 +891,13 @@ discard block |
||
891 | 891 | $service['host_name'] == $rule['host_name'] && |
892 | 892 | ($service['last_check'] + $rule['revert_ok']) < $now) |
893 | 893 | { |
894 | - $this->serviceCheckResult($service['host_name'],$service['service_name'],0,'Reset service to OK after '.$rule['revert_ok'].' seconds'); |
|
894 | + $this->serviceCheckResult($service['host_name'], $service['service_name'], 0, 'Reset service to OK after '.$rule['revert_ok'].' seconds'); |
|
895 | 895 | $numreset++; |
896 | 896 | } |
897 | 897 | } |
898 | 898 | } |
899 | 899 | echo "\n"; |
900 | - echo $numreset . " service(s) reset to OK\n"; |
|
900 | + echo $numreset." service(s) reset to OK\n"; |
|
901 | 901 | return 0; |
902 | 902 | |
903 | 903 | } |
@@ -98,8 +98,7 @@ discard block |
||
98 | 98 | { |
99 | 99 | $this->logging->setLogging($baseLogLevel, $baseLogMode,$baseLogFile); |
100 | 100 | $this->logSetup=true; |
101 | - } |
|
102 | - else |
|
101 | + } else |
|
103 | 102 | { |
104 | 103 | $this->logSetup=false; |
105 | 104 | } |
@@ -129,7 +128,10 @@ discard block |
||
129 | 128 | $this->getDatabaseOptions(); // Get options in database |
130 | 129 | |
131 | 130 | //*************** Setup API |
132 | - if ($this->apiUse === true) $this->getAPI(); // Setup API |
|
131 | + if ($this->apiUse === true) { |
|
132 | + $this->getAPI(); |
|
133 | + } |
|
134 | + // Setup API |
|
133 | 135 | |
134 | 136 | //*************** Setup MIB |
135 | 137 | $this->mibClass = new Mib($this->logging,$this->trapsDB,$this->snmptranslate,$this->snmptranslate_dirs); // Create Mib class |
@@ -238,8 +240,7 @@ discard block |
||
238 | 240 | { |
239 | 241 | $this->writeTrapErrorToDB("Error parsing trap (code 2/IP)"); |
240 | 242 | $this->logging->log('Error parsing IP : '.$IP,ERROR,''); |
241 | - } |
|
242 | - else |
|
243 | + } else |
|
243 | 244 | { |
244 | 245 | $this->trapData['source_ip']=$matches[1]; |
245 | 246 | $this->trapData['destination_ip']=$matches[3]; |
@@ -439,7 +440,9 @@ discard block |
||
439 | 440 | } |
440 | 441 | |
441 | 442 | $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
442 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
443 | + if ($inserted_id==false) { |
|
444 | + throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
445 | + } |
|
443 | 446 | $this->trapId=$inserted_id; |
444 | 447 | break; |
445 | 448 | default: |
@@ -455,7 +458,9 @@ discard block |
||
455 | 458 | { |
456 | 459 | |
457 | 460 | // If action is ignore -> don't send t DB |
458 | - if ($this->trapToDb === false) return; |
|
461 | + if ($this->trapToDb === false) { |
|
462 | + return; |
|
463 | + } |
|
459 | 464 | |
460 | 465 | |
461 | 466 | $db_conn=$this->trapsDB->db_connect_trap(); |
@@ -512,7 +517,9 @@ discard block |
||
512 | 517 | } |
513 | 518 | |
514 | 519 | $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
515 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
520 | + if ($inserted_id==false) { |
|
521 | + throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
522 | + } |
|
516 | 523 | $this->trapId=$inserted_id; |
517 | 524 | break; |
518 | 525 | default: |
@@ -641,8 +648,7 @@ discard block |
||
641 | 648 | // TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default.... |
642 | 649 | exec('echo "'.$send.'" > ' .$this->icinga2cmd); |
643 | 650 | return true; |
644 | - } |
|
645 | - else |
|
651 | + } else |
|
646 | 652 | { |
647 | 653 | // Get perfdata if found |
648 | 654 | $matches=array(); |
@@ -650,8 +656,7 @@ discard block |
||
650 | 656 | { |
651 | 657 | $display=$matches[1]; |
652 | 658 | $perfdata=$matches[2]; |
653 | - } |
|
654 | - else |
|
659 | + } else |
|
655 | 660 | { |
656 | 661 | $perfdata=''; |
657 | 662 | } |
@@ -663,8 +668,7 @@ discard block |
||
663 | 668 | { |
664 | 669 | $this->logging->log( "Error sending result : " .$retmessage,WARN,''); |
665 | 670 | return false; |
666 | - } |
|
667 | - else |
|
671 | + } else |
|
668 | 672 | { |
669 | 673 | $this->logging->log( "Sent result : " .$retmessage,INFO ); |
670 | 674 | return true; |
@@ -763,20 +767,17 @@ discard block |
||
763 | 767 | if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false) |
764 | 768 | { |
765 | 769 | $this->trapAction.='Error sending status : check cmd/API'; |
766 | - } |
|
767 | - else |
|
770 | + } else |
|
768 | 771 | { |
769 | 772 | $this->add_rule_match($rule['id'],$rule['num_match']+1); |
770 | 773 | $this->trapAction.='Status '.$action.' to '.$host_name.'/'.$service_name; |
771 | 774 | } |
772 | - } |
|
773 | - else |
|
775 | + } else |
|
774 | 776 | { |
775 | 777 | $this->add_rule_match($rule['id'],$rule['num_match']+1); |
776 | 778 | } |
777 | 779 | $this->trapToDb=($action==-2)?false:true; |
778 | - } |
|
779 | - else |
|
780 | + } else |
|
780 | 781 | { |
781 | 782 | //$this->logging->log('rules KOO : '.print_r($rule),INFO ); |
782 | 783 | |
@@ -787,14 +788,12 @@ discard block |
||
787 | 788 | if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false) |
788 | 789 | { |
789 | 790 | $this->trapAction.='Error sending status : check cmd/API'; |
790 | - } |
|
791 | - else |
|
791 | + } else |
|
792 | 792 | { |
793 | 793 | $this->add_rule_match($rule['id'],$rule['num_match']+1); |
794 | 794 | $this->trapAction.='Status '.$action.' to '.$host_name.'/'.$service_name; |
795 | 795 | } |
796 | - } |
|
797 | - else |
|
796 | + } else |
|
798 | 797 | { |
799 | 798 | $this->add_rule_match($rule['id'],$rule['num_match']+1); |
800 | 799 | } |
@@ -804,16 +803,14 @@ discard block |
||
804 | 803 | if (!isset($this->trapData['source_name'])) |
805 | 804 | { |
806 | 805 | $this->trapData['source_name']=$rule['host_name']; |
807 | - } |
|
808 | - else |
|
806 | + } else |
|
809 | 807 | { |
810 | 808 | if (!preg_match('/'.$rule['host_name'].'/',$this->trapData['source_name'])) |
811 | 809 | { // only add if not present |
812 | 810 | $this->trapData['source_name'].=','.$rule['host_name']; |
813 | 811 | } |
814 | 812 | } |
815 | - } |
|
816 | - catch (Exception $e) |
|
813 | + } catch (Exception $e) |
|
817 | 814 | { |
818 | 815 | $this->logging->log('Error in rule eval : '.$e->getMessage(),WARN,''); |
819 | 816 | $this->trapAction.=' ERR : '.$e->getMessage(); |
@@ -824,8 +821,7 @@ discard block |
||
824 | 821 | if ($this->trapData['status']=='error') |
825 | 822 | { |
826 | 823 | $this->trapToDb=true; // Always put errors in DB for the use can see |
827 | - } |
|
828 | - else |
|
824 | + } else |
|
829 | 825 | { |
830 | 826 | $this->trapData['status']='done'; |
831 | 827 | } |
@@ -15,197 +15,197 @@ |
||
15 | 15 | trait TrapConfig |
16 | 16 | { |
17 | 17 | |
18 | - /** @return \Trapdirector\Logging */ |
|
19 | - abstract public function getLogging(); |
|
20 | - /** @return \Trapdirector\TrapApi */ |
|
21 | - abstract public function getTrapApi(); |
|
18 | + /** @return \Trapdirector\Logging */ |
|
19 | + abstract public function getLogging(); |
|
20 | + /** @return \Trapdirector\TrapApi */ |
|
21 | + abstract public function getTrapApi(); |
|
22 | 22 | |
23 | - // TODO : Get default values from TrapModuleConfig |
|
24 | - /** @var bool Use SnmpTrapAddess as source adress */ |
|
25 | - public $useSnmpTrapAddess=TRUE; |
|
26 | - /** @var string Special OID to get IP source address of trap emitter */ |
|
27 | - public $snmpTrapAddressOID='.1.3.6.1.6.3.18.1.3'; |
|
23 | + // TODO : Get default values from TrapModuleConfig |
|
24 | + /** @var bool Use SnmpTrapAddess as source adress */ |
|
25 | + public $useSnmpTrapAddess=TRUE; |
|
26 | + /** @var string Special OID to get IP source address of trap emitter */ |
|
27 | + public $snmpTrapAddressOID='.1.3.6.1.6.3.18.1.3'; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Get option from array of ini file, send message if empty |
|
31 | - * @param string $option_array Array of ini file |
|
32 | - * @param string $option_category category in ini file |
|
33 | - * @param string $option_name name of option in category |
|
34 | - * @param mixed $option_var variable to fill if found, left untouched if not found |
|
35 | - * @param integer $log_level default 2 (warning) |
|
36 | - * @param string $message warning message if not found |
|
37 | - * @return boolean true if found, or false |
|
38 | - */ |
|
39 | - protected function getOptionIfSet($option_array,$option_category,$option_name, &$option_var, $log_level = WARN, $message = null) |
|
40 | - { |
|
41 | - if (!isset($option_array[$option_category][$option_name])) |
|
42 | - { |
|
43 | - if ($message === null) |
|
44 | - { |
|
45 | - $message='No ' . $option_name . ' in config file: '. $this->trapModuleConfig; |
|
46 | - } |
|
47 | - $this->getLogging()->log($message,$log_level); |
|
48 | - return false; |
|
49 | - } |
|
50 | - else |
|
51 | - { |
|
52 | - $option_var=$option_array[$option_category][$option_name]; |
|
53 | - return true; |
|
54 | - } |
|
55 | - } |
|
29 | + /** |
|
30 | + * Get option from array of ini file, send message if empty |
|
31 | + * @param string $option_array Array of ini file |
|
32 | + * @param string $option_category category in ini file |
|
33 | + * @param string $option_name name of option in category |
|
34 | + * @param mixed $option_var variable to fill if found, left untouched if not found |
|
35 | + * @param integer $log_level default 2 (warning) |
|
36 | + * @param string $message warning message if not found |
|
37 | + * @return boolean true if found, or false |
|
38 | + */ |
|
39 | + protected function getOptionIfSet($option_array,$option_category,$option_name, &$option_var, $log_level = WARN, $message = null) |
|
40 | + { |
|
41 | + if (!isset($option_array[$option_category][$option_name])) |
|
42 | + { |
|
43 | + if ($message === null) |
|
44 | + { |
|
45 | + $message='No ' . $option_name . ' in config file: '. $this->trapModuleConfig; |
|
46 | + } |
|
47 | + $this->getLogging()->log($message,$log_level); |
|
48 | + return false; |
|
49 | + } |
|
50 | + else |
|
51 | + { |
|
52 | + $option_var=$option_array[$option_category][$option_name]; |
|
53 | + return true; |
|
54 | + } |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Get options in database |
|
59 | - */ |
|
60 | - protected function getDatabaseOptions() |
|
61 | - { |
|
62 | - // Database options |
|
63 | - if ($this->logSetup === false) // Only if logging was no setup in constructor |
|
64 | - { |
|
65 | - $this->getDBConfigIfSet('log_level',$this->getLogging()->debugLevel); |
|
66 | - $this->getDBConfigIfSet('log_destination',$this->getLogging()->outputMode); |
|
67 | - $this->getDBConfigIfSet('log_file',$this->getLogging()->outputFile); |
|
68 | - } |
|
69 | - |
|
70 | - $tmpVal = -1; // Get boolean coded in database as 1/0 |
|
71 | - $this->getDBConfigIfSet('use_SnmpTrapAddess', $tmpVal); |
|
72 | - if ($tmpVal != -1) $this->useSnmpTrapAddess = ($tmpVal == 1) ? TRUE : FALSE; |
|
73 | - |
|
74 | - $this->getDBConfigIfSet('SnmpTrapAddess_oid', $this->snmpTrapAddressOID); // Get oid then replace '.' with '\.' to use in regexp whrn reading traps |
|
75 | - $this->snmpTrapAddressOID = preg_replace('/\./', '\\.', $this->snmpTrapAddressOID); |
|
76 | - } |
|
77 | - |
|
78 | - /** Set $variable to value if $element found in database config table |
|
79 | - * @param string $element |
|
80 | - * @param string $variable |
|
81 | - */ |
|
82 | - protected function getDBConfigIfSet($element,&$variable) |
|
83 | - { |
|
84 | - $value=$this->getDBConfig($element); |
|
85 | - if ($value != null) $variable=$value; |
|
86 | - } |
|
57 | + /** |
|
58 | + * Get options in database |
|
59 | + */ |
|
60 | + protected function getDatabaseOptions() |
|
61 | + { |
|
62 | + // Database options |
|
63 | + if ($this->logSetup === false) // Only if logging was no setup in constructor |
|
64 | + { |
|
65 | + $this->getDBConfigIfSet('log_level',$this->getLogging()->debugLevel); |
|
66 | + $this->getDBConfigIfSet('log_destination',$this->getLogging()->outputMode); |
|
67 | + $this->getDBConfigIfSet('log_file',$this->getLogging()->outputFile); |
|
68 | + } |
|
69 | + |
|
70 | + $tmpVal = -1; // Get boolean coded in database as 1/0 |
|
71 | + $this->getDBConfigIfSet('use_SnmpTrapAddess', $tmpVal); |
|
72 | + if ($tmpVal != -1) $this->useSnmpTrapAddess = ($tmpVal == 1) ? TRUE : FALSE; |
|
73 | + |
|
74 | + $this->getDBConfigIfSet('SnmpTrapAddess_oid', $this->snmpTrapAddressOID); // Get oid then replace '.' with '\.' to use in regexp whrn reading traps |
|
75 | + $this->snmpTrapAddressOID = preg_replace('/\./', '\\.', $this->snmpTrapAddressOID); |
|
76 | + } |
|
77 | + |
|
78 | + /** Set $variable to value if $element found in database config table |
|
79 | + * @param string $element |
|
80 | + * @param string $variable |
|
81 | + */ |
|
82 | + protected function getDBConfigIfSet($element,&$variable) |
|
83 | + { |
|
84 | + $value=$this->getDBConfig($element); |
|
85 | + if ($value != null) $variable=$value; |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * Get data from db_config |
|
90 | - * @param $element string name of param |
|
91 | - * @return mixed : value (or null) |
|
92 | - */ |
|
93 | - protected function getDBConfig($element) // TODO : put this in DB class |
|
94 | - { |
|
95 | - $db_conn=$this->trapsDB->db_connect_trap(); |
|
96 | - $sql='SELECT value from '.$this->dbPrefix.'db_config WHERE ( name=\''.$element.'\' )'; |
|
97 | - if (($ret_code=$db_conn->query($sql)) === false) { |
|
98 | - $this->logging->log('No result in query : ' . $sql,WARN,''); |
|
99 | - return null; |
|
100 | - } |
|
101 | - $value=$ret_code->fetch(); |
|
102 | - if ($value != null && isset($value['value'])) |
|
103 | - { |
|
104 | - return $value['value']; |
|
105 | - } |
|
106 | - return null; |
|
107 | - } |
|
88 | + /** |
|
89 | + * Get data from db_config |
|
90 | + * @param $element string name of param |
|
91 | + * @return mixed : value (or null) |
|
92 | + */ |
|
93 | + protected function getDBConfig($element) // TODO : put this in DB class |
|
94 | + { |
|
95 | + $db_conn=$this->trapsDB->db_connect_trap(); |
|
96 | + $sql='SELECT value from '.$this->dbPrefix.'db_config WHERE ( name=\''.$element.'\' )'; |
|
97 | + if (($ret_code=$db_conn->query($sql)) === false) { |
|
98 | + $this->logging->log('No result in query : ' . $sql,WARN,''); |
|
99 | + return null; |
|
100 | + } |
|
101 | + $value=$ret_code->fetch(); |
|
102 | + if ($value != null && isset($value['value'])) |
|
103 | + { |
|
104 | + return $value['value']; |
|
105 | + } |
|
106 | + return null; |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Get options from ini file |
|
111 | - * @param array $trap_config : ini file array |
|
112 | - */ |
|
113 | - protected function getMainOptions($trapConfig) |
|
114 | - { |
|
115 | - |
|
116 | - $nodeStatus=''; |
|
117 | - $this->getOptionIfSet($trapConfig,'config','node', $nodeStatus); |
|
118 | - if ($this->getTrapApi()->setStatus($nodeStatus) === FALSE) |
|
119 | - { |
|
120 | - $this->getLogging()->log('Unknown node status '.$nodeStatus.' : setting to MASTER',WARN); |
|
121 | - $this->getTrapApi()->setStatusMaster(); |
|
122 | - } |
|
123 | - else |
|
124 | - { |
|
125 | - if ($this->getTrapApi()->getStatus() != TrapApi::MASTER) |
|
126 | - { |
|
127 | - // Get options to connect to API |
|
128 | - $IP = $port = $user = $pass = null; |
|
129 | - $this->getOptionIfSet($trapConfig,'config','masterIP', $IP, ERROR); |
|
130 | - $this->getOptionIfSet($trapConfig,'config','masterPort', $port, ERROR); |
|
131 | - $this->getOptionIfSet($trapConfig,'config','masterUser', $user, ERROR); |
|
132 | - $this->getOptionIfSet($trapConfig,'config','masterPass', $pass, ERROR); |
|
133 | - $this->getTrapApi()->setParams($IP, $port, $user, $pass); |
|
134 | - return; |
|
135 | - } |
|
136 | - } |
|
137 | - |
|
138 | - // Snmptranslate binary path |
|
139 | - $this->getOptionIfSet($trapConfig,'config','snmptranslate', $this->snmptranslate); |
|
140 | - |
|
141 | - // mibs path |
|
142 | - $this->getOptionIfSet($trapConfig,'config','snmptranslate_dirs', $this->snmptranslate_dirs); |
|
143 | - |
|
144 | - // icinga2cmd path |
|
145 | - $this->getOptionIfSet($trapConfig,'config','icingacmd', $this->icinga2cmd); |
|
146 | - |
|
147 | - // table prefix |
|
148 | - $this->getOptionIfSet($trapConfig,'config','database_prefix', $this->dbPrefix); |
|
149 | - |
|
150 | - // API options |
|
151 | - if ($this->getOptionIfSet($trapConfig,'config','icingaAPI_host', $this->apiHostname)) |
|
152 | - { |
|
153 | - $this->apiUse=true; |
|
154 | - // Get API options or throw exception as not configured correctly |
|
155 | - $this->getOptionIfSet($trapConfig,'config','icingaAPI_port', $this->apiPort,ERROR); |
|
156 | - $this->getOptionIfSet($trapConfig,'config','icingaAPI_user', $this->apiUsername,ERROR); |
|
157 | - $this->getOptionIfSet($trapConfig,'config','icingaAPI_password', $this->apiPassword,ERROR); |
|
158 | - } |
|
159 | - } |
|
109 | + /** |
|
110 | + * Get options from ini file |
|
111 | + * @param array $trap_config : ini file array |
|
112 | + */ |
|
113 | + protected function getMainOptions($trapConfig) |
|
114 | + { |
|
115 | + |
|
116 | + $nodeStatus=''; |
|
117 | + $this->getOptionIfSet($trapConfig,'config','node', $nodeStatus); |
|
118 | + if ($this->getTrapApi()->setStatus($nodeStatus) === FALSE) |
|
119 | + { |
|
120 | + $this->getLogging()->log('Unknown node status '.$nodeStatus.' : setting to MASTER',WARN); |
|
121 | + $this->getTrapApi()->setStatusMaster(); |
|
122 | + } |
|
123 | + else |
|
124 | + { |
|
125 | + if ($this->getTrapApi()->getStatus() != TrapApi::MASTER) |
|
126 | + { |
|
127 | + // Get options to connect to API |
|
128 | + $IP = $port = $user = $pass = null; |
|
129 | + $this->getOptionIfSet($trapConfig,'config','masterIP', $IP, ERROR); |
|
130 | + $this->getOptionIfSet($trapConfig,'config','masterPort', $port, ERROR); |
|
131 | + $this->getOptionIfSet($trapConfig,'config','masterUser', $user, ERROR); |
|
132 | + $this->getOptionIfSet($trapConfig,'config','masterPass', $pass, ERROR); |
|
133 | + $this->getTrapApi()->setParams($IP, $port, $user, $pass); |
|
134 | + return; |
|
135 | + } |
|
136 | + } |
|
137 | + |
|
138 | + // Snmptranslate binary path |
|
139 | + $this->getOptionIfSet($trapConfig,'config','snmptranslate', $this->snmptranslate); |
|
140 | + |
|
141 | + // mibs path |
|
142 | + $this->getOptionIfSet($trapConfig,'config','snmptranslate_dirs', $this->snmptranslate_dirs); |
|
143 | + |
|
144 | + // icinga2cmd path |
|
145 | + $this->getOptionIfSet($trapConfig,'config','icingacmd', $this->icinga2cmd); |
|
146 | + |
|
147 | + // table prefix |
|
148 | + $this->getOptionIfSet($trapConfig,'config','database_prefix', $this->dbPrefix); |
|
149 | + |
|
150 | + // API options |
|
151 | + if ($this->getOptionIfSet($trapConfig,'config','icingaAPI_host', $this->apiHostname)) |
|
152 | + { |
|
153 | + $this->apiUse=true; |
|
154 | + // Get API options or throw exception as not configured correctly |
|
155 | + $this->getOptionIfSet($trapConfig,'config','icingaAPI_port', $this->apiPort,ERROR); |
|
156 | + $this->getOptionIfSet($trapConfig,'config','icingaAPI_user', $this->apiUsername,ERROR); |
|
157 | + $this->getOptionIfSet($trapConfig,'config','icingaAPI_password', $this->apiPassword,ERROR); |
|
158 | + } |
|
159 | + } |
|
160 | 160 | |
161 | - /** |
|
162 | - * Create and setup database class for trap & ido (if no api) db |
|
163 | - * @param array $trap_config : ini file array |
|
164 | - */ |
|
165 | - protected function setupDatabase($trapConfig) |
|
166 | - { |
|
167 | - // Trap database |
|
168 | - if (!array_key_exists('database',$trapConfig['config'])) |
|
169 | - { |
|
170 | - $this->logging->log("No database in config file: ".$this->trapModuleConfig,ERROR,''); |
|
171 | - return; |
|
172 | - } |
|
173 | - $dbTrapName=$trapConfig['config']['database']; |
|
174 | - $this->logging->log("Found database in config file: ".$dbTrapName,INFO ); |
|
175 | - |
|
176 | - if ( ($dbConfig=parse_ini_file($this->icingaweb2Ressources,true)) === false) |
|
177 | - { |
|
178 | - $this->logging->log("Error reading ini file : ".$this->icingaweb2Ressources,ERROR,''); |
|
179 | - return; |
|
180 | - } |
|
181 | - if (!array_key_exists($dbTrapName,$dbConfig)) |
|
182 | - { |
|
183 | - $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2Ressources,ERROR,''); |
|
184 | - return; |
|
185 | - } |
|
186 | - |
|
187 | - $this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName],$this->dbPrefix); |
|
188 | - |
|
189 | - $this->logging->log("API Use : ".print_r($this->apiUse,true),DEBUG ); |
|
190 | - |
|
191 | - //TODO enable this again when API queries are all done : |
|
192 | - //if ($this->apiUse === true) return; // In case of API use, no IDO is necessary |
|
193 | - |
|
194 | - // IDO Database |
|
195 | - if (!array_key_exists('IDOdatabase',$trapConfig['config'])) |
|
196 | - { |
|
197 | - $this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig,ERROR,''); |
|
198 | - } |
|
199 | - $dbIdoName=$trapConfig['config']['IDOdatabase']; |
|
200 | - |
|
201 | - $this->logging->log("Found IDO database in config file: ".$dbIdoName,INFO ); |
|
202 | - if (!array_key_exists($dbIdoName,$dbConfig)) |
|
203 | - { |
|
204 | - $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources,ERROR,''); |
|
205 | - return; |
|
206 | - } |
|
207 | - |
|
208 | - $this->trapsDB->setupIDO($dbConfig[$dbIdoName]); |
|
209 | - } |
|
161 | + /** |
|
162 | + * Create and setup database class for trap & ido (if no api) db |
|
163 | + * @param array $trap_config : ini file array |
|
164 | + */ |
|
165 | + protected function setupDatabase($trapConfig) |
|
166 | + { |
|
167 | + // Trap database |
|
168 | + if (!array_key_exists('database',$trapConfig['config'])) |
|
169 | + { |
|
170 | + $this->logging->log("No database in config file: ".$this->trapModuleConfig,ERROR,''); |
|
171 | + return; |
|
172 | + } |
|
173 | + $dbTrapName=$trapConfig['config']['database']; |
|
174 | + $this->logging->log("Found database in config file: ".$dbTrapName,INFO ); |
|
175 | + |
|
176 | + if ( ($dbConfig=parse_ini_file($this->icingaweb2Ressources,true)) === false) |
|
177 | + { |
|
178 | + $this->logging->log("Error reading ini file : ".$this->icingaweb2Ressources,ERROR,''); |
|
179 | + return; |
|
180 | + } |
|
181 | + if (!array_key_exists($dbTrapName,$dbConfig)) |
|
182 | + { |
|
183 | + $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2Ressources,ERROR,''); |
|
184 | + return; |
|
185 | + } |
|
186 | + |
|
187 | + $this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName],$this->dbPrefix); |
|
188 | + |
|
189 | + $this->logging->log("API Use : ".print_r($this->apiUse,true),DEBUG ); |
|
190 | + |
|
191 | + //TODO enable this again when API queries are all done : |
|
192 | + //if ($this->apiUse === true) return; // In case of API use, no IDO is necessary |
|
193 | + |
|
194 | + // IDO Database |
|
195 | + if (!array_key_exists('IDOdatabase',$trapConfig['config'])) |
|
196 | + { |
|
197 | + $this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig,ERROR,''); |
|
198 | + } |
|
199 | + $dbIdoName=$trapConfig['config']['IDOdatabase']; |
|
200 | + |
|
201 | + $this->logging->log("Found IDO database in config file: ".$dbIdoName,INFO ); |
|
202 | + if (!array_key_exists($dbIdoName,$dbConfig)) |
|
203 | + { |
|
204 | + $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources,ERROR,''); |
|
205 | + return; |
|
206 | + } |
|
207 | + |
|
208 | + $this->trapsDB->setupIDO($dbConfig[$dbIdoName]); |
|
209 | + } |
|
210 | 210 | |
211 | 211 | } |
212 | 212 | \ No newline at end of file |
@@ -36,15 +36,15 @@ discard block |
||
36 | 36 | * @param string $message warning message if not found |
37 | 37 | * @return boolean true if found, or false |
38 | 38 | */ |
39 | - protected function getOptionIfSet($option_array,$option_category,$option_name, &$option_var, $log_level = WARN, $message = null) |
|
39 | + protected function getOptionIfSet($option_array, $option_category, $option_name, &$option_var, $log_level=WARN, $message=null) |
|
40 | 40 | { |
41 | 41 | if (!isset($option_array[$option_category][$option_name])) |
42 | 42 | { |
43 | 43 | if ($message === null) |
44 | 44 | { |
45 | - $message='No ' . $option_name . ' in config file: '. $this->trapModuleConfig; |
|
45 | + $message='No '.$option_name.' in config file: '.$this->trapModuleConfig; |
|
46 | 46 | } |
47 | - $this->getLogging()->log($message,$log_level); |
|
47 | + $this->getLogging()->log($message, $log_level); |
|
48 | 48 | return false; |
49 | 49 | } |
50 | 50 | else |
@@ -62,24 +62,24 @@ discard block |
||
62 | 62 | // Database options |
63 | 63 | if ($this->logSetup === false) // Only if logging was no setup in constructor |
64 | 64 | { |
65 | - $this->getDBConfigIfSet('log_level',$this->getLogging()->debugLevel); |
|
66 | - $this->getDBConfigIfSet('log_destination',$this->getLogging()->outputMode); |
|
67 | - $this->getDBConfigIfSet('log_file',$this->getLogging()->outputFile); |
|
65 | + $this->getDBConfigIfSet('log_level', $this->getLogging()->debugLevel); |
|
66 | + $this->getDBConfigIfSet('log_destination', $this->getLogging()->outputMode); |
|
67 | + $this->getDBConfigIfSet('log_file', $this->getLogging()->outputFile); |
|
68 | 68 | } |
69 | 69 | |
70 | - $tmpVal = -1; // Get boolean coded in database as 1/0 |
|
70 | + $tmpVal=-1; // Get boolean coded in database as 1/0 |
|
71 | 71 | $this->getDBConfigIfSet('use_SnmpTrapAddess', $tmpVal); |
72 | - if ($tmpVal != -1) $this->useSnmpTrapAddess = ($tmpVal == 1) ? TRUE : FALSE; |
|
72 | + if ($tmpVal != -1) $this->useSnmpTrapAddess=($tmpVal == 1) ? TRUE : FALSE; |
|
73 | 73 | |
74 | 74 | $this->getDBConfigIfSet('SnmpTrapAddess_oid', $this->snmpTrapAddressOID); // Get oid then replace '.' with '\.' to use in regexp whrn reading traps |
75 | - $this->snmpTrapAddressOID = preg_replace('/\./', '\\.', $this->snmpTrapAddressOID); |
|
75 | + $this->snmpTrapAddressOID=preg_replace('/\./', '\\.', $this->snmpTrapAddressOID); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** Set $variable to value if $element found in database config table |
79 | 79 | * @param string $element |
80 | 80 | * @param string $variable |
81 | 81 | */ |
82 | - protected function getDBConfigIfSet($element,&$variable) |
|
82 | + protected function getDBConfigIfSet($element, &$variable) |
|
83 | 83 | { |
84 | 84 | $value=$this->getDBConfig($element); |
85 | 85 | if ($value != null) $variable=$value; |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | $db_conn=$this->trapsDB->db_connect_trap(); |
96 | 96 | $sql='SELECT value from '.$this->dbPrefix.'db_config WHERE ( name=\''.$element.'\' )'; |
97 | 97 | if (($ret_code=$db_conn->query($sql)) === false) { |
98 | - $this->logging->log('No result in query : ' . $sql,WARN,''); |
|
98 | + $this->logging->log('No result in query : '.$sql, WARN, ''); |
|
99 | 99 | return null; |
100 | 100 | } |
101 | 101 | $value=$ret_code->fetch(); |
@@ -114,10 +114,10 @@ discard block |
||
114 | 114 | { |
115 | 115 | |
116 | 116 | $nodeStatus=''; |
117 | - $this->getOptionIfSet($trapConfig,'config','node', $nodeStatus); |
|
117 | + $this->getOptionIfSet($trapConfig, 'config', 'node', $nodeStatus); |
|
118 | 118 | if ($this->getTrapApi()->setStatus($nodeStatus) === FALSE) |
119 | 119 | { |
120 | - $this->getLogging()->log('Unknown node status '.$nodeStatus.' : setting to MASTER',WARN); |
|
120 | + $this->getLogging()->log('Unknown node status '.$nodeStatus.' : setting to MASTER', WARN); |
|
121 | 121 | $this->getTrapApi()->setStatusMaster(); |
122 | 122 | } |
123 | 123 | else |
@@ -125,36 +125,36 @@ discard block |
||
125 | 125 | if ($this->getTrapApi()->getStatus() != TrapApi::MASTER) |
126 | 126 | { |
127 | 127 | // Get options to connect to API |
128 | - $IP = $port = $user = $pass = null; |
|
129 | - $this->getOptionIfSet($trapConfig,'config','masterIP', $IP, ERROR); |
|
130 | - $this->getOptionIfSet($trapConfig,'config','masterPort', $port, ERROR); |
|
131 | - $this->getOptionIfSet($trapConfig,'config','masterUser', $user, ERROR); |
|
132 | - $this->getOptionIfSet($trapConfig,'config','masterPass', $pass, ERROR); |
|
128 | + $IP=$port=$user=$pass=null; |
|
129 | + $this->getOptionIfSet($trapConfig, 'config', 'masterIP', $IP, ERROR); |
|
130 | + $this->getOptionIfSet($trapConfig, 'config', 'masterPort', $port, ERROR); |
|
131 | + $this->getOptionIfSet($trapConfig, 'config', 'masterUser', $user, ERROR); |
|
132 | + $this->getOptionIfSet($trapConfig, 'config', 'masterPass', $pass, ERROR); |
|
133 | 133 | $this->getTrapApi()->setParams($IP, $port, $user, $pass); |
134 | 134 | return; |
135 | 135 | } |
136 | 136 | } |
137 | 137 | |
138 | 138 | // Snmptranslate binary path |
139 | - $this->getOptionIfSet($trapConfig,'config','snmptranslate', $this->snmptranslate); |
|
139 | + $this->getOptionIfSet($trapConfig, 'config', 'snmptranslate', $this->snmptranslate); |
|
140 | 140 | |
141 | 141 | // mibs path |
142 | - $this->getOptionIfSet($trapConfig,'config','snmptranslate_dirs', $this->snmptranslate_dirs); |
|
142 | + $this->getOptionIfSet($trapConfig, 'config', 'snmptranslate_dirs', $this->snmptranslate_dirs); |
|
143 | 143 | |
144 | 144 | // icinga2cmd path |
145 | - $this->getOptionIfSet($trapConfig,'config','icingacmd', $this->icinga2cmd); |
|
145 | + $this->getOptionIfSet($trapConfig, 'config', 'icingacmd', $this->icinga2cmd); |
|
146 | 146 | |
147 | 147 | // table prefix |
148 | - $this->getOptionIfSet($trapConfig,'config','database_prefix', $this->dbPrefix); |
|
148 | + $this->getOptionIfSet($trapConfig, 'config', 'database_prefix', $this->dbPrefix); |
|
149 | 149 | |
150 | 150 | // API options |
151 | - if ($this->getOptionIfSet($trapConfig,'config','icingaAPI_host', $this->apiHostname)) |
|
151 | + if ($this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_host', $this->apiHostname)) |
|
152 | 152 | { |
153 | 153 | $this->apiUse=true; |
154 | 154 | // Get API options or throw exception as not configured correctly |
155 | - $this->getOptionIfSet($trapConfig,'config','icingaAPI_port', $this->apiPort,ERROR); |
|
156 | - $this->getOptionIfSet($trapConfig,'config','icingaAPI_user', $this->apiUsername,ERROR); |
|
157 | - $this->getOptionIfSet($trapConfig,'config','icingaAPI_password', $this->apiPassword,ERROR); |
|
155 | + $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_port', $this->apiPort, ERROR); |
|
156 | + $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_user', $this->apiUsername, ERROR); |
|
157 | + $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_password', $this->apiPassword, ERROR); |
|
158 | 158 | } |
159 | 159 | } |
160 | 160 | |
@@ -165,43 +165,43 @@ discard block |
||
165 | 165 | protected function setupDatabase($trapConfig) |
166 | 166 | { |
167 | 167 | // Trap database |
168 | - if (!array_key_exists('database',$trapConfig['config'])) |
|
168 | + if (!array_key_exists('database', $trapConfig['config'])) |
|
169 | 169 | { |
170 | - $this->logging->log("No database in config file: ".$this->trapModuleConfig,ERROR,''); |
|
170 | + $this->logging->log("No database in config file: ".$this->trapModuleConfig, ERROR, ''); |
|
171 | 171 | return; |
172 | 172 | } |
173 | 173 | $dbTrapName=$trapConfig['config']['database']; |
174 | - $this->logging->log("Found database in config file: ".$dbTrapName,INFO ); |
|
174 | + $this->logging->log("Found database in config file: ".$dbTrapName, INFO); |
|
175 | 175 | |
176 | - if ( ($dbConfig=parse_ini_file($this->icingaweb2Ressources,true)) === false) |
|
176 | + if (($dbConfig=parse_ini_file($this->icingaweb2Ressources, true)) === false) |
|
177 | 177 | { |
178 | - $this->logging->log("Error reading ini file : ".$this->icingaweb2Ressources,ERROR,''); |
|
178 | + $this->logging->log("Error reading ini file : ".$this->icingaweb2Ressources, ERROR, ''); |
|
179 | 179 | return; |
180 | 180 | } |
181 | - if (!array_key_exists($dbTrapName,$dbConfig)) |
|
181 | + if (!array_key_exists($dbTrapName, $dbConfig)) |
|
182 | 182 | { |
183 | - $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2Ressources,ERROR,''); |
|
183 | + $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2Ressources, ERROR, ''); |
|
184 | 184 | return; |
185 | 185 | } |
186 | 186 | |
187 | - $this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName],$this->dbPrefix); |
|
187 | + $this->trapsDB=new Database($this->logging, $dbConfig[$dbTrapName], $this->dbPrefix); |
|
188 | 188 | |
189 | - $this->logging->log("API Use : ".print_r($this->apiUse,true),DEBUG ); |
|
189 | + $this->logging->log("API Use : ".print_r($this->apiUse, true), DEBUG); |
|
190 | 190 | |
191 | 191 | //TODO enable this again when API queries are all done : |
192 | 192 | //if ($this->apiUse === true) return; // In case of API use, no IDO is necessary |
193 | 193 | |
194 | 194 | // IDO Database |
195 | - if (!array_key_exists('IDOdatabase',$trapConfig['config'])) |
|
195 | + if (!array_key_exists('IDOdatabase', $trapConfig['config'])) |
|
196 | 196 | { |
197 | - $this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig,ERROR,''); |
|
197 | + $this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig, ERROR, ''); |
|
198 | 198 | } |
199 | 199 | $dbIdoName=$trapConfig['config']['IDOdatabase']; |
200 | 200 | |
201 | - $this->logging->log("Found IDO database in config file: ".$dbIdoName,INFO ); |
|
202 | - if (!array_key_exists($dbIdoName,$dbConfig)) |
|
201 | + $this->logging->log("Found IDO database in config file: ".$dbIdoName, INFO); |
|
202 | + if (!array_key_exists($dbIdoName, $dbConfig)) |
|
203 | 203 | { |
204 | - $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources,ERROR,''); |
|
204 | + $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources, ERROR, ''); |
|
205 | 205 | return; |
206 | 206 | } |
207 | 207 |
@@ -46,8 +46,7 @@ discard block |
||
46 | 46 | } |
47 | 47 | $this->getLogging()->log($message,$log_level); |
48 | 48 | return false; |
49 | - } |
|
50 | - else |
|
49 | + } else |
|
51 | 50 | { |
52 | 51 | $option_var=$option_array[$option_category][$option_name]; |
53 | 52 | return true; |
@@ -60,16 +59,20 @@ discard block |
||
60 | 59 | protected function getDatabaseOptions() |
61 | 60 | { |
62 | 61 | // Database options |
63 | - if ($this->logSetup === false) // Only if logging was no setup in constructor |
|
62 | + if ($this->logSetup === false) { |
|
63 | + // Only if logging was no setup in constructor |
|
64 | 64 | { |
65 | 65 | $this->getDBConfigIfSet('log_level',$this->getLogging()->debugLevel); |
66 | + } |
|
66 | 67 | $this->getDBConfigIfSet('log_destination',$this->getLogging()->outputMode); |
67 | 68 | $this->getDBConfigIfSet('log_file',$this->getLogging()->outputFile); |
68 | 69 | } |
69 | 70 | |
70 | 71 | $tmpVal = -1; // Get boolean coded in database as 1/0 |
71 | 72 | $this->getDBConfigIfSet('use_SnmpTrapAddess', $tmpVal); |
72 | - if ($tmpVal != -1) $this->useSnmpTrapAddess = ($tmpVal == 1) ? TRUE : FALSE; |
|
73 | + if ($tmpVal != -1) { |
|
74 | + $this->useSnmpTrapAddess = ($tmpVal == 1) ? TRUE : FALSE; |
|
75 | + } |
|
73 | 76 | |
74 | 77 | $this->getDBConfigIfSet('SnmpTrapAddess_oid', $this->snmpTrapAddressOID); // Get oid then replace '.' with '\.' to use in regexp whrn reading traps |
75 | 78 | $this->snmpTrapAddressOID = preg_replace('/\./', '\\.', $this->snmpTrapAddressOID); |
@@ -82,7 +85,9 @@ discard block |
||
82 | 85 | protected function getDBConfigIfSet($element,&$variable) |
83 | 86 | { |
84 | 87 | $value=$this->getDBConfig($element); |
85 | - if ($value != null) $variable=$value; |
|
88 | + if ($value != null) { |
|
89 | + $variable=$value; |
|
90 | + } |
|
86 | 91 | } |
87 | 92 | |
88 | 93 | /** |
@@ -119,8 +124,7 @@ discard block |
||
119 | 124 | { |
120 | 125 | $this->getLogging()->log('Unknown node status '.$nodeStatus.' : setting to MASTER',WARN); |
121 | 126 | $this->getTrapApi()->setStatusMaster(); |
122 | - } |
|
123 | - else |
|
127 | + } else |
|
124 | 128 | { |
125 | 129 | if ($this->getTrapApi()->getStatus() != TrapApi::MASTER) |
126 | 130 | { |
@@ -7,137 +7,137 @@ |
||
7 | 7 | class HandlerTable extends TrapDirectorTable |
8 | 8 | { |
9 | 9 | |
10 | - protected $status_display=array( |
|
11 | - -2 =>'ignore', |
|
12 | - -1 => '-', |
|
13 | - 0 => 'OK', |
|
14 | - 1 => 'warning', |
|
15 | - 2 => 'critical', |
|
16 | - 3 => 'unknown',); |
|
10 | + protected $status_display=array( |
|
11 | + -2 =>'ignore', |
|
12 | + -1 => '-', |
|
13 | + 0 => 'OK', |
|
14 | + 1 => 'warning', |
|
15 | + 2 => 'critical', |
|
16 | + 3 => 'unknown',); |
|
17 | 17 | |
18 | - // translate |
|
19 | - protected $doTranslate=false; |
|
20 | - protected $MIB; |
|
18 | + // translate |
|
19 | + protected $doTranslate=false; |
|
20 | + protected $MIB; |
|
21 | 21 | |
22 | - // categories |
|
23 | - protected $categories = NULL; |
|
22 | + // categories |
|
23 | + protected $categories = NULL; |
|
24 | 24 | |
25 | - public function setCategoriesArray(array $categories) |
|
26 | - { |
|
27 | - $this->categories = $categories; |
|
28 | - } |
|
25 | + public function setCategoriesArray(array $categories) |
|
26 | + { |
|
27 | + $this->categories = $categories; |
|
28 | + } |
|
29 | 29 | |
30 | - public function groupingPrintData( $value) |
|
31 | - { |
|
32 | - if ($this->groupingColumn == 'rule_type') |
|
33 | - { |
|
34 | - if ($this->categories == NULL || (! isset($this->categories[$value]))) |
|
35 | - return 'Unknown category ('.$value.')'; |
|
36 | - return 'Category : '. $this->categories[$value]; |
|
37 | - } |
|
38 | - $html = "$value"; |
|
39 | - return $html; |
|
40 | - } |
|
30 | + public function groupingPrintData( $value) |
|
31 | + { |
|
32 | + if ($this->groupingColumn == 'rule_type') |
|
33 | + { |
|
34 | + if ($this->categories == NULL || (! isset($this->categories[$value]))) |
|
35 | + return 'Unknown category ('.$value.')'; |
|
36 | + return 'Category : '. $this->categories[$value]; |
|
37 | + } |
|
38 | + $html = "$value"; |
|
39 | + return $html; |
|
40 | + } |
|
41 | 41 | |
42 | - public function setMibloader($mibloader) |
|
43 | - { |
|
44 | - $this->MIB=$mibloader; |
|
45 | - $this->doTranslate=true; |
|
46 | - } |
|
42 | + public function setMibloader($mibloader) |
|
43 | + { |
|
44 | + $this->MIB=$mibloader; |
|
45 | + $this->doTranslate=true; |
|
46 | + } |
|
47 | 47 | |
48 | - public function titleOrder($name) |
|
49 | - { |
|
50 | - switch ($name) |
|
51 | - { |
|
52 | - case 'host_name' : return $this->content[$name]; break; |
|
53 | - case 'source_ip' : return 'ip4'; break; |
|
54 | - default: return $this->content[$name]; |
|
55 | - } |
|
56 | - return NULL; |
|
57 | - } |
|
48 | + public function titleOrder($name) |
|
49 | + { |
|
50 | + switch ($name) |
|
51 | + { |
|
52 | + case 'host_name' : return $this->content[$name]; break; |
|
53 | + case 'source_ip' : return 'ip4'; break; |
|
54 | + default: return $this->content[$name]; |
|
55 | + } |
|
56 | + return NULL; |
|
57 | + } |
|
58 | 58 | |
59 | - public function getCurrentURL() |
|
60 | - { |
|
61 | - return Url::fromPath($this->urlPath . '/handler'); |
|
62 | - } |
|
59 | + public function getCurrentURL() |
|
60 | + { |
|
61 | + return Url::fromPath($this->urlPath . '/handler'); |
|
62 | + } |
|
63 | 63 | |
64 | - public function renderLine($row) |
|
65 | - { |
|
66 | - $html = ''; |
|
67 | - $firstCol = true; |
|
64 | + public function renderLine($row) |
|
65 | + { |
|
66 | + $html = ''; |
|
67 | + $firstCol = true; |
|
68 | 68 | |
69 | - $titleNames = array_keys($this->titles); |
|
70 | - foreach ($titleNames as $rowkey ) |
|
71 | - { |
|
72 | - // Check missing value |
|
73 | - if (property_exists($row, $rowkey)) |
|
74 | - { |
|
75 | - switch ($rowkey) |
|
76 | - { |
|
77 | - case 'action_match': // display text levels |
|
78 | - case 'action_nomatch': |
|
79 | - $val=$this->status_display[$row->$rowkey]; |
|
80 | - break; |
|
81 | - case 'trap_oid': // try to traslate oids. |
|
69 | + $titleNames = array_keys($this->titles); |
|
70 | + foreach ($titleNames as $rowkey ) |
|
71 | + { |
|
72 | + // Check missing value |
|
73 | + if (property_exists($row, $rowkey)) |
|
74 | + { |
|
75 | + switch ($rowkey) |
|
76 | + { |
|
77 | + case 'action_match': // display text levels |
|
78 | + case 'action_nomatch': |
|
79 | + $val=$this->status_display[$row->$rowkey]; |
|
80 | + break; |
|
81 | + case 'trap_oid': // try to traslate oids. |
|
82 | 82 | |
83 | - if ($this->doTranslate === true) |
|
84 | - { |
|
85 | - $oidName = $this->MIB->translateOID($row->$rowkey); |
|
86 | - if (isset($oidName['name'])) |
|
87 | - { |
|
88 | - $val=$oidName['name']; |
|
89 | - } |
|
90 | - else |
|
91 | - { |
|
92 | - $val = $row->$rowkey; |
|
93 | - } |
|
94 | - } |
|
95 | - else |
|
96 | - { |
|
97 | - $val = $row->$rowkey; |
|
98 | - } |
|
99 | - break; |
|
100 | - case 'host_name': // switch to hostgroup if name is null |
|
101 | - if ($row->$rowkey == null) |
|
102 | - { |
|
103 | - $val = $row->host_group_name; |
|
104 | - } |
|
105 | - else |
|
106 | - { |
|
107 | - $val = $row->$rowkey; |
|
108 | - } |
|
109 | - break; |
|
110 | - default: |
|
111 | - $val = $row->$rowkey; |
|
112 | - } |
|
113 | - if ($rowkey == 'trap_oid' && $this->doTranslate===true) |
|
114 | - { |
|
83 | + if ($this->doTranslate === true) |
|
84 | + { |
|
85 | + $oidName = $this->MIB->translateOID($row->$rowkey); |
|
86 | + if (isset($oidName['name'])) |
|
87 | + { |
|
88 | + $val=$oidName['name']; |
|
89 | + } |
|
90 | + else |
|
91 | + { |
|
92 | + $val = $row->$rowkey; |
|
93 | + } |
|
94 | + } |
|
95 | + else |
|
96 | + { |
|
97 | + $val = $row->$rowkey; |
|
98 | + } |
|
99 | + break; |
|
100 | + case 'host_name': // switch to hostgroup if name is null |
|
101 | + if ($row->$rowkey == null) |
|
102 | + { |
|
103 | + $val = $row->host_group_name; |
|
104 | + } |
|
105 | + else |
|
106 | + { |
|
107 | + $val = $row->$rowkey; |
|
108 | + } |
|
109 | + break; |
|
110 | + default: |
|
111 | + $val = $row->$rowkey; |
|
112 | + } |
|
113 | + if ($rowkey == 'trap_oid' && $this->doTranslate===true) |
|
114 | + { |
|
115 | 115 | |
116 | - } |
|
117 | - } else { |
|
118 | - $val = '-'; |
|
119 | - } |
|
120 | - if ($firstCol === true) { // Put link in first column for trap detail. |
|
121 | - $html .= '<td class="traphover">' |
|
122 | - . $this->view->qlink( |
|
123 | - $this->view->escape($val), |
|
124 | - Url::fromPath( |
|
125 | - $this->urlPath . '/handler/add', |
|
126 | - array('ruleid' => $row->id) |
|
127 | - ) |
|
128 | - ); |
|
129 | - if ($row->comment != '') |
|
130 | - { |
|
131 | - $html.= '<span class="tohover">'. $row->comment .'</span></td>'; |
|
132 | - } |
|
133 | - $html.= '</td>'; |
|
134 | - } else { |
|
135 | - $html .= '<td>' . $this->view->escape($val) . '</td>'; |
|
136 | - } |
|
137 | - $firstCol=false; |
|
116 | + } |
|
117 | + } else { |
|
118 | + $val = '-'; |
|
119 | + } |
|
120 | + if ($firstCol === true) { // Put link in first column for trap detail. |
|
121 | + $html .= '<td class="traphover">' |
|
122 | + . $this->view->qlink( |
|
123 | + $this->view->escape($val), |
|
124 | + Url::fromPath( |
|
125 | + $this->urlPath . '/handler/add', |
|
126 | + array('ruleid' => $row->id) |
|
127 | + ) |
|
128 | + ); |
|
129 | + if ($row->comment != '') |
|
130 | + { |
|
131 | + $html.= '<span class="tohover">'. $row->comment .'</span></td>'; |
|
132 | + } |
|
133 | + $html.= '</td>'; |
|
134 | + } else { |
|
135 | + $html .= '<td>' . $this->view->escape($val) . '</td>'; |
|
136 | + } |
|
137 | + $firstCol=false; |
|
138 | 138 | |
139 | - } |
|
140 | - return $html; |
|
141 | - } |
|
139 | + } |
|
140 | + return $html; |
|
141 | + } |
|
142 | 142 | |
143 | 143 | } |
144 | 144 | \ No newline at end of file |
@@ -20,22 +20,22 @@ discard block |
||
20 | 20 | protected $MIB; |
21 | 21 | |
22 | 22 | // categories |
23 | - protected $categories = NULL; |
|
23 | + protected $categories=NULL; |
|
24 | 24 | |
25 | 25 | public function setCategoriesArray(array $categories) |
26 | 26 | { |
27 | - $this->categories = $categories; |
|
27 | + $this->categories=$categories; |
|
28 | 28 | } |
29 | 29 | |
30 | - public function groupingPrintData( $value) |
|
30 | + public function groupingPrintData($value) |
|
31 | 31 | { |
32 | 32 | if ($this->groupingColumn == 'rule_type') |
33 | 33 | { |
34 | - if ($this->categories == NULL || (! isset($this->categories[$value]))) |
|
34 | + if ($this->categories == NULL || (!isset($this->categories[$value]))) |
|
35 | 35 | return 'Unknown category ('.$value.')'; |
36 | - return 'Category : '. $this->categories[$value]; |
|
36 | + return 'Category : '.$this->categories[$value]; |
|
37 | 37 | } |
38 | - $html = "$value"; |
|
38 | + $html="$value"; |
|
39 | 39 | return $html; |
40 | 40 | } |
41 | 41 | |
@@ -58,16 +58,16 @@ discard block |
||
58 | 58 | |
59 | 59 | public function getCurrentURL() |
60 | 60 | { |
61 | - return Url::fromPath($this->urlPath . '/handler'); |
|
61 | + return Url::fromPath($this->urlPath.'/handler'); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | public function renderLine($row) |
65 | 65 | { |
66 | - $html = ''; |
|
67 | - $firstCol = true; |
|
66 | + $html=''; |
|
67 | + $firstCol=true; |
|
68 | 68 | |
69 | - $titleNames = array_keys($this->titles); |
|
70 | - foreach ($titleNames as $rowkey ) |
|
69 | + $titleNames=array_keys($this->titles); |
|
70 | + foreach ($titleNames as $rowkey) |
|
71 | 71 | { |
72 | 72 | // Check missing value |
73 | 73 | if (property_exists($row, $rowkey)) |
@@ -82,57 +82,57 @@ discard block |
||
82 | 82 | |
83 | 83 | if ($this->doTranslate === true) |
84 | 84 | { |
85 | - $oidName = $this->MIB->translateOID($row->$rowkey); |
|
85 | + $oidName=$this->MIB->translateOID($row->$rowkey); |
|
86 | 86 | if (isset($oidName['name'])) |
87 | 87 | { |
88 | 88 | $val=$oidName['name']; |
89 | 89 | } |
90 | 90 | else |
91 | 91 | { |
92 | - $val = $row->$rowkey; |
|
92 | + $val=$row->$rowkey; |
|
93 | 93 | } |
94 | 94 | } |
95 | 95 | else |
96 | 96 | { |
97 | - $val = $row->$rowkey; |
|
97 | + $val=$row->$rowkey; |
|
98 | 98 | } |
99 | 99 | break; |
100 | 100 | case 'host_name': // switch to hostgroup if name is null |
101 | 101 | if ($row->$rowkey == null) |
102 | 102 | { |
103 | - $val = $row->host_group_name; |
|
103 | + $val=$row->host_group_name; |
|
104 | 104 | } |
105 | 105 | else |
106 | 106 | { |
107 | - $val = $row->$rowkey; |
|
107 | + $val=$row->$rowkey; |
|
108 | 108 | } |
109 | 109 | break; |
110 | 110 | default: |
111 | - $val = $row->$rowkey; |
|
111 | + $val=$row->$rowkey; |
|
112 | 112 | } |
113 | - if ($rowkey == 'trap_oid' && $this->doTranslate===true) |
|
113 | + if ($rowkey == 'trap_oid' && $this->doTranslate === true) |
|
114 | 114 | { |
115 | 115 | |
116 | 116 | } |
117 | 117 | } else { |
118 | - $val = '-'; |
|
118 | + $val='-'; |
|
119 | 119 | } |
120 | 120 | if ($firstCol === true) { // Put link in first column for trap detail. |
121 | - $html .= '<td class="traphover">' |
|
121 | + $html.='<td class="traphover">' |
|
122 | 122 | . $this->view->qlink( |
123 | 123 | $this->view->escape($val), |
124 | 124 | Url::fromPath( |
125 | - $this->urlPath . '/handler/add', |
|
125 | + $this->urlPath.'/handler/add', |
|
126 | 126 | array('ruleid' => $row->id) |
127 | 127 | ) |
128 | 128 | ); |
129 | 129 | if ($row->comment != '') |
130 | 130 | { |
131 | - $html.= '<span class="tohover">'. $row->comment .'</span></td>'; |
|
131 | + $html.='<span class="tohover">'.$row->comment.'</span></td>'; |
|
132 | 132 | } |
133 | - $html.= '</td>'; |
|
133 | + $html.='</td>'; |
|
134 | 134 | } else { |
135 | - $html .= '<td>' . $this->view->escape($val) . '</td>'; |
|
135 | + $html.='<td>'.$this->view->escape($val).'</td>'; |
|
136 | 136 | } |
137 | 137 | $firstCol=false; |
138 | 138 |
@@ -31,8 +31,9 @@ discard block |
||
31 | 31 | { |
32 | 32 | if ($this->groupingColumn == 'rule_type') |
33 | 33 | { |
34 | - if ($this->categories == NULL || (! isset($this->categories[$value]))) |
|
35 | - return 'Unknown category ('.$value.')'; |
|
34 | + if ($this->categories == NULL || (! isset($this->categories[$value]))) { |
|
35 | + return 'Unknown category ('.$value.')'; |
|
36 | + } |
|
36 | 37 | return 'Category : '. $this->categories[$value]; |
37 | 38 | } |
38 | 39 | $html = "$value"; |
@@ -86,13 +87,11 @@ discard block |
||
86 | 87 | if (isset($oidName['name'])) |
87 | 88 | { |
88 | 89 | $val=$oidName['name']; |
89 | - } |
|
90 | - else |
|
90 | + } else |
|
91 | 91 | { |
92 | 92 | $val = $row->$rowkey; |
93 | 93 | } |
94 | - } |
|
95 | - else |
|
94 | + } else |
|
96 | 95 | { |
97 | 96 | $val = $row->$rowkey; |
98 | 97 | } |
@@ -101,8 +100,7 @@ discard block |
||
101 | 100 | if ($row->$rowkey == null) |
102 | 101 | { |
103 | 102 | $val = $row->host_group_name; |
104 | - } |
|
105 | - else |
|
103 | + } else |
|
106 | 104 | { |
107 | 105 | $val = $row->$rowkey; |
108 | 106 | } |
@@ -5,299 +5,299 @@ discard block |
||
5 | 5 | |
6 | 6 | abstract class TrapDirectorTable |
7 | 7 | { |
8 | - /** @var array $titles table titles (name, display value) */ |
|
9 | - protected $titles = null; |
|
8 | + /** @var array $titles table titles (name, display value) */ |
|
9 | + protected $titles = null; |
|
10 | 10 | |
11 | - /** @var array $content table content (name, sb column name). name index must be the same as $titles*/ |
|
12 | - protected $content = null; |
|
11 | + /** @var array $content table content (name, sb column name). name index must be the same as $titles*/ |
|
12 | + protected $content = null; |
|
13 | 13 | |
14 | - /** @var array $columnNames names of columns for filtering */ |
|
15 | - protected $columnNames = array(); |
|
14 | + /** @var array $columnNames names of columns for filtering */ |
|
15 | + protected $columnNames = array(); |
|
16 | 16 | |
17 | - /** @var mixed $dbConn connection to database */ |
|
18 | - protected $dbConn = null; |
|
17 | + /** @var mixed $dbConn connection to database */ |
|
18 | + protected $dbConn = null; |
|
19 | 19 | |
20 | - /** Current view **/ |
|
21 | - protected $view; |
|
20 | + /** Current view **/ |
|
21 | + protected $view; |
|
22 | 22 | |
23 | - protected $urlPath; |
|
23 | + protected $urlPath; |
|
24 | 24 | |
25 | - // Database stuff |
|
25 | + // Database stuff |
|
26 | 26 | /** @var array $table (db ref, name) */ |
27 | - protected $table = array(); |
|
27 | + protected $table = array(); |
|
28 | 28 | |
29 | - /** @var mixed $query Query in database; */ |
|
30 | - protected $query = null; |
|
29 | + /** @var mixed $query Query in database; */ |
|
30 | + protected $query = null; |
|
31 | 31 | |
32 | - /** @var array $order : (db column, 'ASC' | 'DESC') */ |
|
33 | - protected $order = array(); |
|
34 | - protected $orderQuery = ''; |
|
32 | + /** @var array $order : (db column, 'ASC' | 'DESC') */ |
|
33 | + protected $order = array(); |
|
34 | + protected $orderQuery = ''; |
|
35 | 35 | |
36 | - /********* Filter ********/ |
|
37 | - /** @var string $filterString : string filter for db columns */ |
|
38 | - protected $filterString = ''; |
|
36 | + /********* Filter ********/ |
|
37 | + /** @var string $filterString : string filter for db columns */ |
|
38 | + protected $filterString = ''; |
|
39 | 39 | |
40 | - /** @var array $filterColumn : columns to apply filter to */ |
|
41 | - protected $filterColumn = array(); |
|
40 | + /** @var array $filterColumn : columns to apply filter to */ |
|
41 | + protected $filterColumn = array(); |
|
42 | 42 | |
43 | - protected $filterQuery=''; |
|
43 | + protected $filterQuery=''; |
|
44 | 44 | |
45 | - /*************** Paging *************/ |
|
46 | - protected $maxPerPage = 25; |
|
45 | + /*************** Paging *************/ |
|
46 | + protected $maxPerPage = 25; |
|
47 | 47 | |
48 | - protected $currentPage = 0; |
|
48 | + protected $currentPage = 0; |
|
49 | 49 | |
50 | - /*************** Grouping ************/ |
|
51 | - protected $grouppingActive=false; |
|
50 | + /*************** Grouping ************/ |
|
51 | + protected $grouppingActive=false; |
|
52 | 52 | |
53 | - protected $groupingColumn=''; |
|
53 | + protected $groupingColumn=''; |
|
54 | 54 | |
55 | - protected $groupingVal=''; |
|
55 | + protected $groupingVal=''; |
|
56 | 56 | |
57 | - protected $groupingColSpan=1; |
|
57 | + protected $groupingColSpan=1; |
|
58 | 58 | |
59 | - function __construct(array $table,array $titles, array $columns, array $columnNames, $dbConn , $view, $urlPath) |
|
60 | - { |
|
61 | - $this->table = $table; |
|
62 | - $this->titles = $titles; |
|
63 | - $this->content = $columns; |
|
64 | - $this->columnNames = $columnNames; |
|
65 | - $this->dbConn = $dbConn; |
|
59 | + function __construct(array $table,array $titles, array $columns, array $columnNames, $dbConn , $view, $urlPath) |
|
60 | + { |
|
61 | + $this->table = $table; |
|
62 | + $this->titles = $titles; |
|
63 | + $this->content = $columns; |
|
64 | + $this->columnNames = $columnNames; |
|
65 | + $this->dbConn = $dbConn; |
|
66 | 66 | |
67 | - $this->view = $view; |
|
68 | - $this->urlPath = $urlPath; |
|
67 | + $this->view = $view; |
|
68 | + $this->urlPath = $urlPath; |
|
69 | 69 | |
70 | - return $this; |
|
71 | - } |
|
70 | + return $this; |
|
71 | + } |
|
72 | 72 | |
73 | 73 | |
74 | - /************** GET variables and URLs *************/ |
|
75 | - public function getParams(array $getVars) |
|
76 | - { |
|
77 | - $this->getFilterQuery($getVars); |
|
78 | - $this->getPagingQuery($getVars); |
|
79 | - $this->getOrderQuery($getVars); |
|
80 | - } |
|
81 | - |
|
82 | - public function getCurrentURL() |
|
83 | - { |
|
84 | - return '?'; |
|
85 | - } |
|
86 | - |
|
87 | - protected function getCurrentURLAndQS(string $caller) |
|
88 | - { |
|
89 | - $actionURL = $this->getCurrentURL() . '?' ; |
|
90 | - $QSList=array(); |
|
91 | - if ($caller != 'filter' && $this->curFilterQuery() != '') |
|
92 | - array_push($QSList , $this->curFilterQuery()); |
|
74 | + /************** GET variables and URLs *************/ |
|
75 | + public function getParams(array $getVars) |
|
76 | + { |
|
77 | + $this->getFilterQuery($getVars); |
|
78 | + $this->getPagingQuery($getVars); |
|
79 | + $this->getOrderQuery($getVars); |
|
80 | + } |
|
81 | + |
|
82 | + public function getCurrentURL() |
|
83 | + { |
|
84 | + return '?'; |
|
85 | + } |
|
86 | + |
|
87 | + protected function getCurrentURLAndQS(string $caller) |
|
88 | + { |
|
89 | + $actionURL = $this->getCurrentURL() . '?' ; |
|
90 | + $QSList=array(); |
|
91 | + if ($caller != 'filter' && $this->curFilterQuery() != '') |
|
92 | + array_push($QSList , $this->curFilterQuery()); |
|
93 | 93 | |
94 | - if ($caller != 'paging' && $caller != 'filter' && $this->curPagingQuery() != '') |
|
95 | - array_push($QSList , $this->curPagingQuery()); |
|
94 | + if ($caller != 'paging' && $caller != 'filter' && $this->curPagingQuery() != '') |
|
95 | + array_push($QSList , $this->curPagingQuery()); |
|
96 | 96 | |
97 | - if ($caller != 'order' && $this->curOrderQuery() != '') |
|
98 | - array_push($QSList , $this->curOrderQuery()); |
|
97 | + if ($caller != 'order' && $this->curOrderQuery() != '') |
|
98 | + array_push($QSList , $this->curOrderQuery()); |
|
99 | 99 | |
100 | - if (count($QSList) != 0) |
|
101 | - $actionURL .= implode('&', $QSList) . '&'; |
|
100 | + if (count($QSList) != 0) |
|
101 | + $actionURL .= implode('&', $QSList) . '&'; |
|
102 | 102 | |
103 | - return $actionURL; |
|
104 | - } |
|
105 | - |
|
106 | - /************* DB queries ******************/ |
|
107 | - /** |
|
108 | - * Get base query in $this->query |
|
109 | - * @return TrapDirectorTable |
|
110 | - */ |
|
111 | - public function getBaseQuery() |
|
112 | - { |
|
113 | - $this->query = $this->dbConn->select(); |
|
114 | - $this->query = $this->query->from( |
|
115 | - $this->table, |
|
116 | - $this->content |
|
117 | - ); |
|
103 | + return $actionURL; |
|
104 | + } |
|
105 | + |
|
106 | + /************* DB queries ******************/ |
|
107 | + /** |
|
108 | + * Get base query in $this->query |
|
109 | + * @return TrapDirectorTable |
|
110 | + */ |
|
111 | + public function getBaseQuery() |
|
112 | + { |
|
113 | + $this->query = $this->dbConn->select(); |
|
114 | + $this->query = $this->query->from( |
|
115 | + $this->table, |
|
116 | + $this->content |
|
117 | + ); |
|
118 | 118 | |
119 | - return $this; |
|
120 | - } |
|
121 | - |
|
122 | - public function fullQuery() |
|
123 | - { |
|
124 | - $this->getBaseQuery() |
|
125 | - ->applyFilter() |
|
126 | - ->applyPaging() |
|
127 | - ->applyOrder(); |
|
119 | + return $this; |
|
120 | + } |
|
121 | + |
|
122 | + public function fullQuery() |
|
123 | + { |
|
124 | + $this->getBaseQuery() |
|
125 | + ->applyFilter() |
|
126 | + ->applyPaging() |
|
127 | + ->applyOrder(); |
|
128 | 128 | |
129 | - return $this->dbConn->fetchAll($this->query); |
|
130 | - //return $this->query->fetchAll(); |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /**************** Filtering ******************/ |
|
135 | - |
|
136 | - public function applyFilter() |
|
137 | - { |
|
138 | - if ($this->filterString == '' || count($this->filterColumn) == 0) |
|
139 | - { |
|
140 | - return $this; |
|
141 | - } |
|
142 | - $filter=''; |
|
143 | - foreach ($this->filterColumn as $column) |
|
144 | - { |
|
145 | - if ($filter != "") $filter.=' OR '; |
|
146 | - //$filter .= "'" . $column . "' LIKE '%" . $this->filterString. "%'"; |
|
147 | - $filter .= $column . " LIKE '%" . $this->filterString. "%'"; |
|
148 | - } |
|
149 | - //echo $filter; |
|
129 | + return $this->dbConn->fetchAll($this->query); |
|
130 | + //return $this->query->fetchAll(); |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /**************** Filtering ******************/ |
|
135 | + |
|
136 | + public function applyFilter() |
|
137 | + { |
|
138 | + if ($this->filterString == '' || count($this->filterColumn) == 0) |
|
139 | + { |
|
140 | + return $this; |
|
141 | + } |
|
142 | + $filter=''; |
|
143 | + foreach ($this->filterColumn as $column) |
|
144 | + { |
|
145 | + if ($filter != "") $filter.=' OR '; |
|
146 | + //$filter .= "'" . $column . "' LIKE '%" . $this->filterString. "%'"; |
|
147 | + $filter .= $column . " LIKE '%" . $this->filterString. "%'"; |
|
148 | + } |
|
149 | + //echo $filter; |
|
150 | 150 | |
151 | - $this->query=$this->query->where($filter); |
|
151 | + $this->query=$this->query->where($filter); |
|
152 | 152 | |
153 | - return $this; |
|
154 | - } |
|
153 | + return $this; |
|
154 | + } |
|
155 | 155 | |
156 | - public function setFilter(string $filter, array $filterCol) |
|
157 | - { |
|
158 | - $this->filterString = $filter; |
|
159 | - $this->filterColumn = $filterCol; |
|
160 | - return $this; |
|
161 | - } |
|
156 | + public function setFilter(string $filter, array $filterCol) |
|
157 | + { |
|
158 | + $this->filterString = $filter; |
|
159 | + $this->filterColumn = $filterCol; |
|
160 | + return $this; |
|
161 | + } |
|
162 | 162 | |
163 | - public function renderFilter() |
|
164 | - { |
|
163 | + public function renderFilter() |
|
164 | + { |
|
165 | 165 | |
166 | - $html=' <form id="genfilter" name="mainFilterGen" |
|
166 | + $html=' <form id="genfilter" name="mainFilterGen" |
|
167 | 167 | enctype="application/x-www-form-urlencoded" |
168 | 168 | action="'.$this->getCurrentURLAndQS('filter').'" |
169 | 169 | method="get">'; |
170 | - $html.='<input type="text" name="f" title="Search is simple! Try to combine multiple words" |
|
170 | + $html.='<input type="text" name="f" title="Search is simple! Try to combine multiple words" |
|
171 | 171 | placeholder="Search..." value="'.$this->filterQuery.'">'; |
172 | 172 | |
173 | - $html.='</form>'; |
|
174 | - return $html; |
|
175 | - } |
|
173 | + $html.='</form>'; |
|
174 | + return $html; |
|
175 | + } |
|
176 | 176 | |
177 | - public function getFilterQuery(array $getVars) |
|
178 | - { |
|
179 | - if (isset($getVars['f'])) |
|
180 | - { |
|
181 | - $this->filterQuery = $getVars['f']; |
|
182 | - $this->setFilter(html_entity_decode($getVars['f']), $this->columnNames); |
|
183 | - } |
|
184 | - } |
|
185 | - |
|
186 | - protected function curFilterQuery() |
|
187 | - { |
|
188 | - if ($this->filterQuery == '') return ''; |
|
189 | - return 'f='.$this->filterQuery; |
|
190 | - } |
|
191 | - |
|
192 | - /***************** Ordering ********************/ |
|
193 | - |
|
194 | - public function applyOrder() |
|
195 | - { |
|
196 | - if (count($this->order) == 0) |
|
197 | - { |
|
198 | - return $this; |
|
199 | - } |
|
200 | - $orderSQL=''; |
|
201 | - foreach ($this->order as $column => $direction) |
|
202 | - { |
|
203 | - if ($orderSQL != "") $orderSQL.=','; |
|
177 | + public function getFilterQuery(array $getVars) |
|
178 | + { |
|
179 | + if (isset($getVars['f'])) |
|
180 | + { |
|
181 | + $this->filterQuery = $getVars['f']; |
|
182 | + $this->setFilter(html_entity_decode($getVars['f']), $this->columnNames); |
|
183 | + } |
|
184 | + } |
|
185 | + |
|
186 | + protected function curFilterQuery() |
|
187 | + { |
|
188 | + if ($this->filterQuery == '') return ''; |
|
189 | + return 'f='.$this->filterQuery; |
|
190 | + } |
|
191 | + |
|
192 | + /***************** Ordering ********************/ |
|
193 | + |
|
194 | + public function applyOrder() |
|
195 | + { |
|
196 | + if (count($this->order) == 0) |
|
197 | + { |
|
198 | + return $this; |
|
199 | + } |
|
200 | + $orderSQL=''; |
|
201 | + foreach ($this->order as $column => $direction) |
|
202 | + { |
|
203 | + if ($orderSQL != "") $orderSQL.=','; |
|
204 | 204 | |
205 | - $orderSQL .= $column . ' ' . $direction; |
|
206 | - } |
|
207 | - $this->query = $this->query->order($orderSQL); |
|
205 | + $orderSQL .= $column . ' ' . $direction; |
|
206 | + } |
|
207 | + $this->query = $this->query->order($orderSQL); |
|
208 | 208 | |
209 | - return $this; |
|
210 | - } |
|
211 | - |
|
212 | - public function setOrder(array $order) |
|
213 | - { |
|
214 | - $this->order = $order; |
|
215 | - return $this; |
|
216 | - } |
|
209 | + return $this; |
|
210 | + } |
|
211 | + |
|
212 | + public function setOrder(array $order) |
|
213 | + { |
|
214 | + $this->order = $order; |
|
215 | + return $this; |
|
216 | + } |
|
217 | 217 | |
218 | - public function isOrderSet() |
|
219 | - { |
|
220 | - if (count($this->order == 0)) return FALSE; |
|
221 | - return TRUE; |
|
222 | - } |
|
223 | - |
|
224 | - public function getOrderQuery(array $getVars) |
|
225 | - { |
|
226 | - if (isset($getVars['o'])) |
|
227 | - { |
|
228 | - $this->orderQuery = $getVars['o']; |
|
229 | - $match = array(); |
|
230 | - if (preg_match('/(.*)(ASC|DESC)$/', $this->orderQuery , $match)) |
|
231 | - { |
|
232 | - $orderArray=array($match[1] => $match[2]); |
|
233 | - echo "$match[1] => $match[2]"; |
|
234 | - $this->setOrder($orderArray); |
|
235 | - } |
|
236 | - } |
|
237 | - } |
|
238 | - |
|
239 | - protected function curOrderQuery() |
|
240 | - { |
|
241 | - if ($this->orderQuery == '') return ''; |
|
242 | - return 'o='.$this->orderQuery; |
|
243 | - } |
|
244 | - |
|
245 | - /***************** Paging and counting *********/ |
|
246 | - |
|
247 | - public function countQuery() |
|
248 | - { |
|
249 | - $this->query = $this->dbConn->select(); |
|
250 | - $this->query = $this->query |
|
251 | - ->from( |
|
252 | - $this->table, |
|
253 | - array('COUNT(*)') |
|
254 | - ); |
|
255 | - $this->applyFilter(); |
|
256 | - } |
|
257 | - |
|
258 | - public function count() |
|
259 | - { |
|
260 | - $this->countQuery(); |
|
261 | - return $this->dbConn->fetchOne($this->query); |
|
262 | - } |
|
263 | - |
|
264 | - public function setMaxPerPage(int $max) |
|
265 | - { |
|
266 | - $this->maxPerPage = $max; |
|
267 | - } |
|
268 | - |
|
269 | - protected function getPagingQuery(array $getVars) |
|
270 | - { |
|
271 | - if (isset($getVars['page'])) |
|
272 | - { |
|
273 | - $this->currentPage = $getVars['page']; |
|
274 | - } |
|
275 | - } |
|
218 | + public function isOrderSet() |
|
219 | + { |
|
220 | + if (count($this->order == 0)) return FALSE; |
|
221 | + return TRUE; |
|
222 | + } |
|
223 | + |
|
224 | + public function getOrderQuery(array $getVars) |
|
225 | + { |
|
226 | + if (isset($getVars['o'])) |
|
227 | + { |
|
228 | + $this->orderQuery = $getVars['o']; |
|
229 | + $match = array(); |
|
230 | + if (preg_match('/(.*)(ASC|DESC)$/', $this->orderQuery , $match)) |
|
231 | + { |
|
232 | + $orderArray=array($match[1] => $match[2]); |
|
233 | + echo "$match[1] => $match[2]"; |
|
234 | + $this->setOrder($orderArray); |
|
235 | + } |
|
236 | + } |
|
237 | + } |
|
238 | + |
|
239 | + protected function curOrderQuery() |
|
240 | + { |
|
241 | + if ($this->orderQuery == '') return ''; |
|
242 | + return 'o='.$this->orderQuery; |
|
243 | + } |
|
244 | + |
|
245 | + /***************** Paging and counting *********/ |
|
246 | + |
|
247 | + public function countQuery() |
|
248 | + { |
|
249 | + $this->query = $this->dbConn->select(); |
|
250 | + $this->query = $this->query |
|
251 | + ->from( |
|
252 | + $this->table, |
|
253 | + array('COUNT(*)') |
|
254 | + ); |
|
255 | + $this->applyFilter(); |
|
256 | + } |
|
257 | + |
|
258 | + public function count() |
|
259 | + { |
|
260 | + $this->countQuery(); |
|
261 | + return $this->dbConn->fetchOne($this->query); |
|
262 | + } |
|
263 | + |
|
264 | + public function setMaxPerPage(int $max) |
|
265 | + { |
|
266 | + $this->maxPerPage = $max; |
|
267 | + } |
|
268 | + |
|
269 | + protected function getPagingQuery(array $getVars) |
|
270 | + { |
|
271 | + if (isset($getVars['page'])) |
|
272 | + { |
|
273 | + $this->currentPage = $getVars['page']; |
|
274 | + } |
|
275 | + } |
|
276 | 276 | |
277 | - protected function curPagingQuery() |
|
278 | - { |
|
279 | - if ($this->currentPage == '') return ''; |
|
280 | - return 'page='.$this->currentPage; |
|
281 | - } |
|
282 | - |
|
283 | - public function renderPagingHeader() |
|
284 | - { |
|
285 | - $count = $this->count(); |
|
286 | - if ($count <= $this->maxPerPage ) |
|
287 | - { |
|
288 | - return 'count : ' . $this->count() . '<br>'; |
|
289 | - } |
|
277 | + protected function curPagingQuery() |
|
278 | + { |
|
279 | + if ($this->currentPage == '') return ''; |
|
280 | + return 'page='.$this->currentPage; |
|
281 | + } |
|
282 | + |
|
283 | + public function renderPagingHeader() |
|
284 | + { |
|
285 | + $count = $this->count(); |
|
286 | + if ($count <= $this->maxPerPage ) |
|
287 | + { |
|
288 | + return 'count : ' . $this->count() . '<br>'; |
|
289 | + } |
|
290 | 290 | |
291 | - if ($this->currentPage == 0) $this->currentPage = 1; |
|
291 | + if ($this->currentPage == 0) $this->currentPage = 1; |
|
292 | 292 | |
293 | - $numPages = intdiv($count , $this->maxPerPage); |
|
294 | - if ($count % $this->maxPerPage != 0 ) $numPages++; |
|
293 | + $numPages = intdiv($count , $this->maxPerPage); |
|
294 | + if ($count % $this->maxPerPage != 0 ) $numPages++; |
|
295 | 295 | |
296 | - $html = '<div class="pagination-control" role="navigation">'; |
|
297 | - $html .= '<ul class="nav tab-nav">'; |
|
298 | - if ($this->currentPage <=1) |
|
299 | - { |
|
300 | - $html .= ' |
|
296 | + $html = '<div class="pagination-control" role="navigation">'; |
|
297 | + $html .= '<ul class="nav tab-nav">'; |
|
298 | + if ($this->currentPage <=1) |
|
299 | + { |
|
300 | + $html .= ' |
|
301 | 301 | <li class="nav-item disabled" aria-hidden="true"> |
302 | 302 | <span class="previous-page"> |
303 | 303 | <span class="sr-only">Previous page</span> |
@@ -305,35 +305,35 @@ discard block |
||
305 | 305 | </span> |
306 | 306 | </li> |
307 | 307 | '; |
308 | - } |
|
309 | - else |
|
310 | - { |
|
311 | - $html .= ' |
|
308 | + } |
|
309 | + else |
|
310 | + { |
|
311 | + $html .= ' |
|
312 | 312 | <li class="nav-item"> |
313 | 313 | <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. ($this->currentPage - 1 ).'" class="previous-page" > |
314 | 314 | <i aria-hidden="true" class="icon-angle-double-left"></i> |
315 | 315 | </a> |
316 | 316 | </li> |
317 | 317 | '; |
318 | - } |
|
318 | + } |
|
319 | 319 | |
320 | - for ($i=1; $i <= $numPages ; $i++) |
|
321 | - { |
|
322 | - $active = ($this->currentPage == $i) ? 'active' : ''; |
|
323 | - $first = ($i-1)*$this->maxPerPage+1; |
|
324 | - $last = $i * $this->maxPerPage; |
|
325 | - if ($last > $count) $last = $count; |
|
326 | - $display = 'Show rows '. $first . ' to '. $last .' of '. $count; |
|
327 | - $html .= '<li class="' . $active . ' nav-item"> |
|
320 | + for ($i=1; $i <= $numPages ; $i++) |
|
321 | + { |
|
322 | + $active = ($this->currentPage == $i) ? 'active' : ''; |
|
323 | + $first = ($i-1)*$this->maxPerPage+1; |
|
324 | + $last = $i * $this->maxPerPage; |
|
325 | + if ($last > $count) $last = $count; |
|
326 | + $display = 'Show rows '. $first . ' to '. $last .' of '. $count; |
|
327 | + $html .= '<li class="' . $active . ' nav-item"> |
|
328 | 328 | <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. $i .'" title="' . $display . '" aria-label="' . $display . '"> |
329 | 329 | '.$i.' |
330 | 330 | </a> |
331 | 331 | </li>'; |
332 | - } |
|
332 | + } |
|
333 | 333 | |
334 | - if ($this->currentPage == $numPages) |
|
335 | - { |
|
336 | - $html .= ' |
|
334 | + if ($this->currentPage == $numPages) |
|
335 | + { |
|
336 | + $html .= ' |
|
337 | 337 | <li class="nav-item disabled" aria-hidden="true"> |
338 | 338 | <span class="previous-page"> |
339 | 339 | <span class="sr-only">Previous page</span> |
@@ -341,150 +341,150 @@ discard block |
||
341 | 341 | </span> |
342 | 342 | </li> |
343 | 343 | '; |
344 | - } |
|
345 | - else |
|
346 | - { |
|
347 | - $html .= ' |
|
344 | + } |
|
345 | + else |
|
346 | + { |
|
347 | + $html .= ' |
|
348 | 348 | <li class="nav-item"> |
349 | 349 | <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. ($this->currentPage + 1 ).'" class="next-page"> |
350 | 350 | <i aria-hidden="true" class="icon-angle-double-right"></i> |
351 | 351 | </a> |
352 | 352 | </li> |
353 | 353 | '; |
354 | - } |
|
354 | + } |
|
355 | 355 | |
356 | - $html .= '</ul> </div>'; |
|
356 | + $html .= '</ul> </div>'; |
|
357 | 357 | |
358 | - return $html; |
|
359 | - } |
|
360 | - |
|
361 | - public function applyPaging() |
|
362 | - { |
|
363 | - $this->query->limitPage($this->currentPage,$this->maxPerPage); |
|
364 | - return $this; |
|
365 | - } |
|
366 | - |
|
367 | - /***************** Grouping ****************/ |
|
368 | - |
|
369 | - public function setGrouping($columnDBName) |
|
370 | - { |
|
371 | - $this->groupingColumn = $columnDBName; |
|
372 | - $this->grouppingActive = TRUE; |
|
373 | - } |
|
374 | - |
|
375 | - public function initGrouping() |
|
376 | - { |
|
377 | - $this->groupingVal = ''; |
|
378 | - $this->groupingColSpan = count($this->titles); |
|
379 | - } |
|
380 | - |
|
381 | - public function groupingPrintData( $value) |
|
382 | - { |
|
383 | - $html = "$value"; |
|
384 | - return $html; |
|
385 | - } |
|
386 | - |
|
387 | - public function groupingNextLine( $values) |
|
388 | - { |
|
389 | - if ($this->grouppingActive === FALSE) return ''; |
|
358 | + return $html; |
|
359 | + } |
|
360 | + |
|
361 | + public function applyPaging() |
|
362 | + { |
|
363 | + $this->query->limitPage($this->currentPage,$this->maxPerPage); |
|
364 | + return $this; |
|
365 | + } |
|
366 | + |
|
367 | + /***************** Grouping ****************/ |
|
368 | + |
|
369 | + public function setGrouping($columnDBName) |
|
370 | + { |
|
371 | + $this->groupingColumn = $columnDBName; |
|
372 | + $this->grouppingActive = TRUE; |
|
373 | + } |
|
374 | + |
|
375 | + public function initGrouping() |
|
376 | + { |
|
377 | + $this->groupingVal = ''; |
|
378 | + $this->groupingColSpan = count($this->titles); |
|
379 | + } |
|
380 | + |
|
381 | + public function groupingPrintData( $value) |
|
382 | + { |
|
383 | + $html = "$value"; |
|
384 | + return $html; |
|
385 | + } |
|
386 | + |
|
387 | + public function groupingNextLine( $values) |
|
388 | + { |
|
389 | + if ($this->grouppingActive === FALSE) return ''; |
|
390 | 390 | |
391 | - $dbcol = $this->groupingColumn; |
|
392 | - if ($this->groupingVal == '' || $this->groupingVal != $values->$dbcol ) |
|
393 | - { |
|
394 | - $this->groupingVal = $values->$dbcol; |
|
395 | - $html = '<tr><th colspan="'. $this->groupingColSpan .'">'. $this->groupingPrintData($this->groupingVal) .'</th></tr>'; |
|
396 | - return $html; |
|
397 | - } |
|
398 | - return ''; |
|
391 | + $dbcol = $this->groupingColumn; |
|
392 | + if ($this->groupingVal == '' || $this->groupingVal != $values->$dbcol ) |
|
393 | + { |
|
394 | + $this->groupingVal = $values->$dbcol; |
|
395 | + $html = '<tr><th colspan="'. $this->groupingColSpan .'">'. $this->groupingPrintData($this->groupingVal) .'</th></tr>'; |
|
396 | + return $html; |
|
397 | + } |
|
398 | + return ''; |
|
399 | 399 | |
400 | - } |
|
401 | - |
|
402 | - /*************** Rendering *************************/ |
|
403 | - |
|
404 | - public function titleOrder($name) |
|
405 | - { |
|
406 | - return $this->content[$name]; |
|
407 | - } |
|
408 | - |
|
409 | - public function renderTitles() |
|
410 | - { |
|
411 | - $html = "<thead>\n<tr>\n"; |
|
412 | - foreach ($this->titles as $name => $values) |
|
413 | - { |
|
414 | - $titleOrder = $this->titleOrder($name); |
|
415 | - if ($titleOrder != NULL) |
|
416 | - { |
|
417 | - if (isset($this->order[$titleOrder])) |
|
418 | - { |
|
419 | - if ($this->order[$titleOrder] == 'ASC') |
|
420 | - { |
|
421 | - $titleOrder.='DESC'; |
|
422 | - } |
|
423 | - else |
|
424 | - { |
|
425 | - $titleOrder.='ASC'; |
|
426 | - } |
|
427 | - } |
|
428 | - else |
|
429 | - { |
|
430 | - $titleOrder.='ASC'; |
|
431 | - } |
|
432 | - $actionURL = $this->getCurrentURLAndQS('order').'o='.$titleOrder; |
|
433 | - $html .= '<th><a href="'.$actionURL.'">' . $values . '</a></th>'; |
|
434 | - } |
|
435 | - else |
|
436 | - { |
|
437 | - $html .= '<th>' . $values . '</th>'; |
|
438 | - } |
|
439 | - } |
|
440 | - $html .= "</tr>\n</thead>\n"; |
|
441 | - return $html; |
|
442 | - } |
|
443 | - |
|
444 | - public function renderLine( $value) |
|
445 | - { |
|
446 | - $html = ''; |
|
447 | - $titleNames = array_keys($this->titles); |
|
448 | - foreach ($titleNames as $name ) |
|
449 | - { |
|
450 | - $html .= '<td>'; |
|
451 | - $html .= $value->$name; |
|
452 | - $html .= "</td>\n"; |
|
453 | - } |
|
454 | - return $html; |
|
455 | - } |
|
456 | - |
|
457 | - public function renderTable(array $values) |
|
458 | - { |
|
459 | - $html = '<tbody id="obj_table_body">'; |
|
460 | - foreach($values as $value) |
|
461 | - { |
|
462 | - $html .= $this->groupingNextLine($value); |
|
400 | + } |
|
401 | + |
|
402 | + /*************** Rendering *************************/ |
|
403 | + |
|
404 | + public function titleOrder($name) |
|
405 | + { |
|
406 | + return $this->content[$name]; |
|
407 | + } |
|
408 | + |
|
409 | + public function renderTitles() |
|
410 | + { |
|
411 | + $html = "<thead>\n<tr>\n"; |
|
412 | + foreach ($this->titles as $name => $values) |
|
413 | + { |
|
414 | + $titleOrder = $this->titleOrder($name); |
|
415 | + if ($titleOrder != NULL) |
|
416 | + { |
|
417 | + if (isset($this->order[$titleOrder])) |
|
418 | + { |
|
419 | + if ($this->order[$titleOrder] == 'ASC') |
|
420 | + { |
|
421 | + $titleOrder.='DESC'; |
|
422 | + } |
|
423 | + else |
|
424 | + { |
|
425 | + $titleOrder.='ASC'; |
|
426 | + } |
|
427 | + } |
|
428 | + else |
|
429 | + { |
|
430 | + $titleOrder.='ASC'; |
|
431 | + } |
|
432 | + $actionURL = $this->getCurrentURLAndQS('order').'o='.$titleOrder; |
|
433 | + $html .= '<th><a href="'.$actionURL.'">' . $values . '</a></th>'; |
|
434 | + } |
|
435 | + else |
|
436 | + { |
|
437 | + $html .= '<th>' . $values . '</th>'; |
|
438 | + } |
|
439 | + } |
|
440 | + $html .= "</tr>\n</thead>\n"; |
|
441 | + return $html; |
|
442 | + } |
|
443 | + |
|
444 | + public function renderLine( $value) |
|
445 | + { |
|
446 | + $html = ''; |
|
447 | + $titleNames = array_keys($this->titles); |
|
448 | + foreach ($titleNames as $name ) |
|
449 | + { |
|
450 | + $html .= '<td>'; |
|
451 | + $html .= $value->$name; |
|
452 | + $html .= "</td>\n"; |
|
453 | + } |
|
454 | + return $html; |
|
455 | + } |
|
456 | + |
|
457 | + public function renderTable(array $values) |
|
458 | + { |
|
459 | + $html = '<tbody id="obj_table_body">'; |
|
460 | + foreach($values as $value) |
|
461 | + { |
|
462 | + $html .= $this->groupingNextLine($value); |
|
463 | 463 | |
464 | - $html .= "<tr>\n"; |
|
465 | - $html .= $this->renderLine($value); |
|
466 | - $html .= "</tr>\n"; |
|
467 | - } |
|
468 | - $html .= '</tbody>'; |
|
469 | - return $html; |
|
470 | - } |
|
471 | - |
|
472 | - public function render() |
|
473 | - { |
|
474 | - $html = ''; |
|
464 | + $html .= "<tr>\n"; |
|
465 | + $html .= $this->renderLine($value); |
|
466 | + $html .= "</tr>\n"; |
|
467 | + } |
|
468 | + $html .= '</tbody>'; |
|
469 | + return $html; |
|
470 | + } |
|
471 | + |
|
472 | + public function render() |
|
473 | + { |
|
474 | + $html = ''; |
|
475 | 475 | |
476 | 476 | |
477 | - $values = $this->fullQuery(); |
|
478 | - $this->initGrouping(); |
|
477 | + $values = $this->fullQuery(); |
|
478 | + $this->initGrouping(); |
|
479 | 479 | |
480 | - $html.="<table class='simple common-table table-row-selectable'>\n"; |
|
480 | + $html.="<table class='simple common-table table-row-selectable'>\n"; |
|
481 | 481 | |
482 | - $html .= $this->renderTitles(); |
|
483 | - $html .= $this->renderTable($values); |
|
484 | - $html .= '</table>'; |
|
482 | + $html .= $this->renderTitles(); |
|
483 | + $html .= $this->renderTable($values); |
|
484 | + $html .= '</table>'; |
|
485 | 485 | |
486 | 486 | |
487 | - return $html; |
|
488 | - } |
|
487 | + return $html; |
|
488 | + } |
|
489 | 489 | |
490 | 490 | } |
491 | 491 | \ No newline at end of file |
@@ -6,16 +6,16 @@ discard block |
||
6 | 6 | abstract class TrapDirectorTable |
7 | 7 | { |
8 | 8 | /** @var array $titles table titles (name, display value) */ |
9 | - protected $titles = null; |
|
9 | + protected $titles=null; |
|
10 | 10 | |
11 | 11 | /** @var array $content table content (name, sb column name). name index must be the same as $titles*/ |
12 | - protected $content = null; |
|
12 | + protected $content=null; |
|
13 | 13 | |
14 | 14 | /** @var array $columnNames names of columns for filtering */ |
15 | - protected $columnNames = array(); |
|
15 | + protected $columnNames=array(); |
|
16 | 16 | |
17 | 17 | /** @var mixed $dbConn connection to database */ |
18 | - protected $dbConn = null; |
|
18 | + protected $dbConn=null; |
|
19 | 19 | |
20 | 20 | /** Current view **/ |
21 | 21 | protected $view; |
@@ -24,28 +24,28 @@ discard block |
||
24 | 24 | |
25 | 25 | // Database stuff |
26 | 26 | /** @var array $table (db ref, name) */ |
27 | - protected $table = array(); |
|
27 | + protected $table=array(); |
|
28 | 28 | |
29 | 29 | /** @var mixed $query Query in database; */ |
30 | - protected $query = null; |
|
30 | + protected $query=null; |
|
31 | 31 | |
32 | 32 | /** @var array $order : (db column, 'ASC' | 'DESC') */ |
33 | - protected $order = array(); |
|
34 | - protected $orderQuery = ''; |
|
33 | + protected $order=array(); |
|
34 | + protected $orderQuery=''; |
|
35 | 35 | |
36 | 36 | /********* Filter ********/ |
37 | 37 | /** @var string $filterString : string filter for db columns */ |
38 | - protected $filterString = ''; |
|
38 | + protected $filterString=''; |
|
39 | 39 | |
40 | 40 | /** @var array $filterColumn : columns to apply filter to */ |
41 | - protected $filterColumn = array(); |
|
41 | + protected $filterColumn=array(); |
|
42 | 42 | |
43 | 43 | protected $filterQuery=''; |
44 | 44 | |
45 | 45 | /*************** Paging *************/ |
46 | - protected $maxPerPage = 25; |
|
46 | + protected $maxPerPage=25; |
|
47 | 47 | |
48 | - protected $currentPage = 0; |
|
48 | + protected $currentPage=0; |
|
49 | 49 | |
50 | 50 | /*************** Grouping ************/ |
51 | 51 | protected $grouppingActive=false; |
@@ -56,16 +56,16 @@ discard block |
||
56 | 56 | |
57 | 57 | protected $groupingColSpan=1; |
58 | 58 | |
59 | - function __construct(array $table,array $titles, array $columns, array $columnNames, $dbConn , $view, $urlPath) |
|
59 | + function __construct(array $table, array $titles, array $columns, array $columnNames, $dbConn, $view, $urlPath) |
|
60 | 60 | { |
61 | - $this->table = $table; |
|
62 | - $this->titles = $titles; |
|
63 | - $this->content = $columns; |
|
64 | - $this->columnNames = $columnNames; |
|
65 | - $this->dbConn = $dbConn; |
|
61 | + $this->table=$table; |
|
62 | + $this->titles=$titles; |
|
63 | + $this->content=$columns; |
|
64 | + $this->columnNames=$columnNames; |
|
65 | + $this->dbConn=$dbConn; |
|
66 | 66 | |
67 | - $this->view = $view; |
|
68 | - $this->urlPath = $urlPath; |
|
67 | + $this->view=$view; |
|
68 | + $this->urlPath=$urlPath; |
|
69 | 69 | |
70 | 70 | return $this; |
71 | 71 | } |
@@ -86,19 +86,19 @@ discard block |
||
86 | 86 | |
87 | 87 | protected function getCurrentURLAndQS(string $caller) |
88 | 88 | { |
89 | - $actionURL = $this->getCurrentURL() . '?' ; |
|
89 | + $actionURL=$this->getCurrentURL().'?'; |
|
90 | 90 | $QSList=array(); |
91 | 91 | if ($caller != 'filter' && $this->curFilterQuery() != '') |
92 | - array_push($QSList , $this->curFilterQuery()); |
|
92 | + array_push($QSList, $this->curFilterQuery()); |
|
93 | 93 | |
94 | 94 | if ($caller != 'paging' && $caller != 'filter' && $this->curPagingQuery() != '') |
95 | - array_push($QSList , $this->curPagingQuery()); |
|
95 | + array_push($QSList, $this->curPagingQuery()); |
|
96 | 96 | |
97 | 97 | if ($caller != 'order' && $this->curOrderQuery() != '') |
98 | - array_push($QSList , $this->curOrderQuery()); |
|
98 | + array_push($QSList, $this->curOrderQuery()); |
|
99 | 99 | |
100 | 100 | if (count($QSList) != 0) |
101 | - $actionURL .= implode('&', $QSList) . '&'; |
|
101 | + $actionURL.=implode('&', $QSList).'&'; |
|
102 | 102 | |
103 | 103 | return $actionURL; |
104 | 104 | } |
@@ -110,8 +110,8 @@ discard block |
||
110 | 110 | */ |
111 | 111 | public function getBaseQuery() |
112 | 112 | { |
113 | - $this->query = $this->dbConn->select(); |
|
114 | - $this->query = $this->query->from( |
|
113 | + $this->query=$this->dbConn->select(); |
|
114 | + $this->query=$this->query->from( |
|
115 | 115 | $this->table, |
116 | 116 | $this->content |
117 | 117 | ); |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | { |
145 | 145 | if ($filter != "") $filter.=' OR '; |
146 | 146 | //$filter .= "'" . $column . "' LIKE '%" . $this->filterString. "%'"; |
147 | - $filter .= $column . " LIKE '%" . $this->filterString. "%'"; |
|
147 | + $filter.=$column." LIKE '%".$this->filterString."%'"; |
|
148 | 148 | } |
149 | 149 | //echo $filter; |
150 | 150 | |
@@ -155,8 +155,8 @@ discard block |
||
155 | 155 | |
156 | 156 | public function setFilter(string $filter, array $filterCol) |
157 | 157 | { |
158 | - $this->filterString = $filter; |
|
159 | - $this->filterColumn = $filterCol; |
|
158 | + $this->filterString=$filter; |
|
159 | + $this->filterColumn=$filterCol; |
|
160 | 160 | return $this; |
161 | 161 | } |
162 | 162 | |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | { |
179 | 179 | if (isset($getVars['f'])) |
180 | 180 | { |
181 | - $this->filterQuery = $getVars['f']; |
|
181 | + $this->filterQuery=$getVars['f']; |
|
182 | 182 | $this->setFilter(html_entity_decode($getVars['f']), $this->columnNames); |
183 | 183 | } |
184 | 184 | } |
@@ -202,16 +202,16 @@ discard block |
||
202 | 202 | { |
203 | 203 | if ($orderSQL != "") $orderSQL.=','; |
204 | 204 | |
205 | - $orderSQL .= $column . ' ' . $direction; |
|
205 | + $orderSQL.=$column.' '.$direction; |
|
206 | 206 | } |
207 | - $this->query = $this->query->order($orderSQL); |
|
207 | + $this->query=$this->query->order($orderSQL); |
|
208 | 208 | |
209 | 209 | return $this; |
210 | 210 | } |
211 | 211 | |
212 | 212 | public function setOrder(array $order) |
213 | 213 | { |
214 | - $this->order = $order; |
|
214 | + $this->order=$order; |
|
215 | 215 | return $this; |
216 | 216 | } |
217 | 217 | |
@@ -225,9 +225,9 @@ discard block |
||
225 | 225 | { |
226 | 226 | if (isset($getVars['o'])) |
227 | 227 | { |
228 | - $this->orderQuery = $getVars['o']; |
|
229 | - $match = array(); |
|
230 | - if (preg_match('/(.*)(ASC|DESC)$/', $this->orderQuery , $match)) |
|
228 | + $this->orderQuery=$getVars['o']; |
|
229 | + $match=array(); |
|
230 | + if (preg_match('/(.*)(ASC|DESC)$/', $this->orderQuery, $match)) |
|
231 | 231 | { |
232 | 232 | $orderArray=array($match[1] => $match[2]); |
233 | 233 | echo "$match[1] => $match[2]"; |
@@ -246,8 +246,8 @@ discard block |
||
246 | 246 | |
247 | 247 | public function countQuery() |
248 | 248 | { |
249 | - $this->query = $this->dbConn->select(); |
|
250 | - $this->query = $this->query |
|
249 | + $this->query=$this->dbConn->select(); |
|
250 | + $this->query=$this->query |
|
251 | 251 | ->from( |
252 | 252 | $this->table, |
253 | 253 | array('COUNT(*)') |
@@ -263,14 +263,14 @@ discard block |
||
263 | 263 | |
264 | 264 | public function setMaxPerPage(int $max) |
265 | 265 | { |
266 | - $this->maxPerPage = $max; |
|
266 | + $this->maxPerPage=$max; |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | protected function getPagingQuery(array $getVars) |
270 | 270 | { |
271 | 271 | if (isset($getVars['page'])) |
272 | 272 | { |
273 | - $this->currentPage = $getVars['page']; |
|
273 | + $this->currentPage=$getVars['page']; |
|
274 | 274 | } |
275 | 275 | } |
276 | 276 | |
@@ -282,22 +282,22 @@ discard block |
||
282 | 282 | |
283 | 283 | public function renderPagingHeader() |
284 | 284 | { |
285 | - $count = $this->count(); |
|
286 | - if ($count <= $this->maxPerPage ) |
|
285 | + $count=$this->count(); |
|
286 | + if ($count <= $this->maxPerPage) |
|
287 | 287 | { |
288 | - return 'count : ' . $this->count() . '<br>'; |
|
288 | + return 'count : '.$this->count().'<br>'; |
|
289 | 289 | } |
290 | 290 | |
291 | - if ($this->currentPage == 0) $this->currentPage = 1; |
|
291 | + if ($this->currentPage == 0) $this->currentPage=1; |
|
292 | 292 | |
293 | - $numPages = intdiv($count , $this->maxPerPage); |
|
294 | - if ($count % $this->maxPerPage != 0 ) $numPages++; |
|
293 | + $numPages=intdiv($count, $this->maxPerPage); |
|
294 | + if ($count % $this->maxPerPage != 0) $numPages++; |
|
295 | 295 | |
296 | - $html = '<div class="pagination-control" role="navigation">'; |
|
297 | - $html .= '<ul class="nav tab-nav">'; |
|
298 | - if ($this->currentPage <=1) |
|
296 | + $html='<div class="pagination-control" role="navigation">'; |
|
297 | + $html.='<ul class="nav tab-nav">'; |
|
298 | + if ($this->currentPage <= 1) |
|
299 | 299 | { |
300 | - $html .= ' |
|
300 | + $html.=' |
|
301 | 301 | <li class="nav-item disabled" aria-hidden="true"> |
302 | 302 | <span class="previous-page"> |
303 | 303 | <span class="sr-only">Previous page</span> |
@@ -308,24 +308,24 @@ discard block |
||
308 | 308 | } |
309 | 309 | else |
310 | 310 | { |
311 | - $html .= ' |
|
311 | + $html.=' |
|
312 | 312 | <li class="nav-item"> |
313 | - <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. ($this->currentPage - 1 ).'" class="previous-page" > |
|
313 | + <a href="'. $this->getCurrentURLAndQS('paging').'&page='.($this->currentPage - 1).'" class="previous-page" > |
|
314 | 314 | <i aria-hidden="true" class="icon-angle-double-left"></i> |
315 | 315 | </a> |
316 | 316 | </li> |
317 | 317 | '; |
318 | 318 | } |
319 | 319 | |
320 | - for ($i=1; $i <= $numPages ; $i++) |
|
320 | + for ($i=1; $i <= $numPages; $i++) |
|
321 | 321 | { |
322 | - $active = ($this->currentPage == $i) ? 'active' : ''; |
|
323 | - $first = ($i-1)*$this->maxPerPage+1; |
|
324 | - $last = $i * $this->maxPerPage; |
|
325 | - if ($last > $count) $last = $count; |
|
326 | - $display = 'Show rows '. $first . ' to '. $last .' of '. $count; |
|
327 | - $html .= '<li class="' . $active . ' nav-item"> |
|
328 | - <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. $i .'" title="' . $display . '" aria-label="' . $display . '"> |
|
322 | + $active=($this->currentPage == $i) ? 'active' : ''; |
|
323 | + $first=($i - 1) * $this->maxPerPage + 1; |
|
324 | + $last=$i * $this->maxPerPage; |
|
325 | + if ($last > $count) $last=$count; |
|
326 | + $display='Show rows '.$first.' to '.$last.' of '.$count; |
|
327 | + $html.='<li class="'.$active.' nav-item"> |
|
328 | + <a href="'. $this->getCurrentURLAndQS('paging').'&page='.$i.'" title="'.$display.'" aria-label="'.$display.'"> |
|
329 | 329 | '.$i.' |
330 | 330 | </a> |
331 | 331 | </li>'; |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | |
334 | 334 | if ($this->currentPage == $numPages) |
335 | 335 | { |
336 | - $html .= ' |
|
336 | + $html.=' |
|
337 | 337 | <li class="nav-item disabled" aria-hidden="true"> |
338 | 338 | <span class="previous-page"> |
339 | 339 | <span class="sr-only">Previous page</span> |
@@ -344,23 +344,23 @@ discard block |
||
344 | 344 | } |
345 | 345 | else |
346 | 346 | { |
347 | - $html .= ' |
|
347 | + $html.=' |
|
348 | 348 | <li class="nav-item"> |
349 | - <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. ($this->currentPage + 1 ).'" class="next-page"> |
|
349 | + <a href="'. $this->getCurrentURLAndQS('paging').'&page='.($this->currentPage + 1).'" class="next-page"> |
|
350 | 350 | <i aria-hidden="true" class="icon-angle-double-right"></i> |
351 | 351 | </a> |
352 | 352 | </li> |
353 | 353 | '; |
354 | 354 | } |
355 | 355 | |
356 | - $html .= '</ul> </div>'; |
|
356 | + $html.='</ul> </div>'; |
|
357 | 357 | |
358 | 358 | return $html; |
359 | 359 | } |
360 | 360 | |
361 | 361 | public function applyPaging() |
362 | 362 | { |
363 | - $this->query->limitPage($this->currentPage,$this->maxPerPage); |
|
363 | + $this->query->limitPage($this->currentPage, $this->maxPerPage); |
|
364 | 364 | return $this; |
365 | 365 | } |
366 | 366 | |
@@ -368,31 +368,31 @@ discard block |
||
368 | 368 | |
369 | 369 | public function setGrouping($columnDBName) |
370 | 370 | { |
371 | - $this->groupingColumn = $columnDBName; |
|
372 | - $this->grouppingActive = TRUE; |
|
371 | + $this->groupingColumn=$columnDBName; |
|
372 | + $this->grouppingActive=TRUE; |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | public function initGrouping() |
376 | 376 | { |
377 | - $this->groupingVal = ''; |
|
378 | - $this->groupingColSpan = count($this->titles); |
|
377 | + $this->groupingVal=''; |
|
378 | + $this->groupingColSpan=count($this->titles); |
|
379 | 379 | } |
380 | 380 | |
381 | - public function groupingPrintData( $value) |
|
381 | + public function groupingPrintData($value) |
|
382 | 382 | { |
383 | - $html = "$value"; |
|
383 | + $html="$value"; |
|
384 | 384 | return $html; |
385 | 385 | } |
386 | 386 | |
387 | - public function groupingNextLine( $values) |
|
387 | + public function groupingNextLine($values) |
|
388 | 388 | { |
389 | 389 | if ($this->grouppingActive === FALSE) return ''; |
390 | 390 | |
391 | - $dbcol = $this->groupingColumn; |
|
392 | - if ($this->groupingVal == '' || $this->groupingVal != $values->$dbcol ) |
|
391 | + $dbcol=$this->groupingColumn; |
|
392 | + if ($this->groupingVal == '' || $this->groupingVal != $values->$dbcol) |
|
393 | 393 | { |
394 | - $this->groupingVal = $values->$dbcol; |
|
395 | - $html = '<tr><th colspan="'. $this->groupingColSpan .'">'. $this->groupingPrintData($this->groupingVal) .'</th></tr>'; |
|
394 | + $this->groupingVal=$values->$dbcol; |
|
395 | + $html='<tr><th colspan="'.$this->groupingColSpan.'">'.$this->groupingPrintData($this->groupingVal).'</th></tr>'; |
|
396 | 396 | return $html; |
397 | 397 | } |
398 | 398 | return ''; |
@@ -408,10 +408,10 @@ discard block |
||
408 | 408 | |
409 | 409 | public function renderTitles() |
410 | 410 | { |
411 | - $html = "<thead>\n<tr>\n"; |
|
411 | + $html="<thead>\n<tr>\n"; |
|
412 | 412 | foreach ($this->titles as $name => $values) |
413 | 413 | { |
414 | - $titleOrder = $this->titleOrder($name); |
|
414 | + $titleOrder=$this->titleOrder($name); |
|
415 | 415 | if ($titleOrder != NULL) |
416 | 416 | { |
417 | 417 | if (isset($this->order[$titleOrder])) |
@@ -429,59 +429,59 @@ discard block |
||
429 | 429 | { |
430 | 430 | $titleOrder.='ASC'; |
431 | 431 | } |
432 | - $actionURL = $this->getCurrentURLAndQS('order').'o='.$titleOrder; |
|
433 | - $html .= '<th><a href="'.$actionURL.'">' . $values . '</a></th>'; |
|
432 | + $actionURL=$this->getCurrentURLAndQS('order').'o='.$titleOrder; |
|
433 | + $html.='<th><a href="'.$actionURL.'">'.$values.'</a></th>'; |
|
434 | 434 | } |
435 | 435 | else |
436 | 436 | { |
437 | - $html .= '<th>' . $values . '</th>'; |
|
437 | + $html.='<th>'.$values.'</th>'; |
|
438 | 438 | } |
439 | 439 | } |
440 | - $html .= "</tr>\n</thead>\n"; |
|
440 | + $html.="</tr>\n</thead>\n"; |
|
441 | 441 | return $html; |
442 | 442 | } |
443 | 443 | |
444 | - public function renderLine( $value) |
|
444 | + public function renderLine($value) |
|
445 | 445 | { |
446 | - $html = ''; |
|
447 | - $titleNames = array_keys($this->titles); |
|
448 | - foreach ($titleNames as $name ) |
|
446 | + $html=''; |
|
447 | + $titleNames=array_keys($this->titles); |
|
448 | + foreach ($titleNames as $name) |
|
449 | 449 | { |
450 | - $html .= '<td>'; |
|
451 | - $html .= $value->$name; |
|
452 | - $html .= "</td>\n"; |
|
450 | + $html.='<td>'; |
|
451 | + $html.=$value->$name; |
|
452 | + $html.="</td>\n"; |
|
453 | 453 | } |
454 | 454 | return $html; |
455 | 455 | } |
456 | 456 | |
457 | 457 | public function renderTable(array $values) |
458 | 458 | { |
459 | - $html = '<tbody id="obj_table_body">'; |
|
460 | - foreach($values as $value) |
|
459 | + $html='<tbody id="obj_table_body">'; |
|
460 | + foreach ($values as $value) |
|
461 | 461 | { |
462 | - $html .= $this->groupingNextLine($value); |
|
462 | + $html.=$this->groupingNextLine($value); |
|
463 | 463 | |
464 | - $html .= "<tr>\n"; |
|
465 | - $html .= $this->renderLine($value); |
|
466 | - $html .= "</tr>\n"; |
|
464 | + $html.="<tr>\n"; |
|
465 | + $html.=$this->renderLine($value); |
|
466 | + $html.="</tr>\n"; |
|
467 | 467 | } |
468 | - $html .= '</tbody>'; |
|
468 | + $html.='</tbody>'; |
|
469 | 469 | return $html; |
470 | 470 | } |
471 | 471 | |
472 | 472 | public function render() |
473 | 473 | { |
474 | - $html = ''; |
|
474 | + $html=''; |
|
475 | 475 | |
476 | 476 | |
477 | - $values = $this->fullQuery(); |
|
477 | + $values=$this->fullQuery(); |
|
478 | 478 | $this->initGrouping(); |
479 | 479 | |
480 | 480 | $html.="<table class='simple common-table table-row-selectable'>\n"; |
481 | 481 | |
482 | - $html .= $this->renderTitles(); |
|
483 | - $html .= $this->renderTable($values); |
|
484 | - $html .= '</table>'; |
|
482 | + $html.=$this->renderTitles(); |
|
483 | + $html.=$this->renderTable($values); |
|
484 | + $html.='</table>'; |
|
485 | 485 | |
486 | 486 | |
487 | 487 | return $html; |
@@ -88,17 +88,21 @@ discard block |
||
88 | 88 | { |
89 | 89 | $actionURL = $this->getCurrentURL() . '?' ; |
90 | 90 | $QSList=array(); |
91 | - if ($caller != 'filter' && $this->curFilterQuery() != '') |
|
92 | - array_push($QSList , $this->curFilterQuery()); |
|
91 | + if ($caller != 'filter' && $this->curFilterQuery() != '') { |
|
92 | + array_push($QSList , $this->curFilterQuery()); |
|
93 | + } |
|
93 | 94 | |
94 | - if ($caller != 'paging' && $caller != 'filter' && $this->curPagingQuery() != '') |
|
95 | - array_push($QSList , $this->curPagingQuery()); |
|
95 | + if ($caller != 'paging' && $caller != 'filter' && $this->curPagingQuery() != '') { |
|
96 | + array_push($QSList , $this->curPagingQuery()); |
|
97 | + } |
|
96 | 98 | |
97 | - if ($caller != 'order' && $this->curOrderQuery() != '') |
|
98 | - array_push($QSList , $this->curOrderQuery()); |
|
99 | + if ($caller != 'order' && $this->curOrderQuery() != '') { |
|
100 | + array_push($QSList , $this->curOrderQuery()); |
|
101 | + } |
|
99 | 102 | |
100 | - if (count($QSList) != 0) |
|
101 | - $actionURL .= implode('&', $QSList) . '&'; |
|
103 | + if (count($QSList) != 0) { |
|
104 | + $actionURL .= implode('&', $QSList) . '&'; |
|
105 | + } |
|
102 | 106 | |
103 | 107 | return $actionURL; |
104 | 108 | } |
@@ -142,7 +146,9 @@ discard block |
||
142 | 146 | $filter=''; |
143 | 147 | foreach ($this->filterColumn as $column) |
144 | 148 | { |
145 | - if ($filter != "") $filter.=' OR '; |
|
149 | + if ($filter != "") { |
|
150 | + $filter.=' OR '; |
|
151 | + } |
|
146 | 152 | //$filter .= "'" . $column . "' LIKE '%" . $this->filterString. "%'"; |
147 | 153 | $filter .= $column . " LIKE '%" . $this->filterString. "%'"; |
148 | 154 | } |
@@ -185,7 +191,9 @@ discard block |
||
185 | 191 | |
186 | 192 | protected function curFilterQuery() |
187 | 193 | { |
188 | - if ($this->filterQuery == '') return ''; |
|
194 | + if ($this->filterQuery == '') { |
|
195 | + return ''; |
|
196 | + } |
|
189 | 197 | return 'f='.$this->filterQuery; |
190 | 198 | } |
191 | 199 | |
@@ -200,7 +208,9 @@ discard block |
||
200 | 208 | $orderSQL=''; |
201 | 209 | foreach ($this->order as $column => $direction) |
202 | 210 | { |
203 | - if ($orderSQL != "") $orderSQL.=','; |
|
211 | + if ($orderSQL != "") { |
|
212 | + $orderSQL.=','; |
|
213 | + } |
|
204 | 214 | |
205 | 215 | $orderSQL .= $column . ' ' . $direction; |
206 | 216 | } |
@@ -217,7 +227,9 @@ discard block |
||
217 | 227 | |
218 | 228 | public function isOrderSet() |
219 | 229 | { |
220 | - if (count($this->order == 0)) return FALSE; |
|
230 | + if (count($this->order == 0)) { |
|
231 | + return FALSE; |
|
232 | + } |
|
221 | 233 | return TRUE; |
222 | 234 | } |
223 | 235 | |
@@ -238,7 +250,9 @@ discard block |
||
238 | 250 | |
239 | 251 | protected function curOrderQuery() |
240 | 252 | { |
241 | - if ($this->orderQuery == '') return ''; |
|
253 | + if ($this->orderQuery == '') { |
|
254 | + return ''; |
|
255 | + } |
|
242 | 256 | return 'o='.$this->orderQuery; |
243 | 257 | } |
244 | 258 | |
@@ -276,7 +290,9 @@ discard block |
||
276 | 290 | |
277 | 291 | protected function curPagingQuery() |
278 | 292 | { |
279 | - if ($this->currentPage == '') return ''; |
|
293 | + if ($this->currentPage == '') { |
|
294 | + return ''; |
|
295 | + } |
|
280 | 296 | return 'page='.$this->currentPage; |
281 | 297 | } |
282 | 298 | |
@@ -288,10 +304,14 @@ discard block |
||
288 | 304 | return 'count : ' . $this->count() . '<br>'; |
289 | 305 | } |
290 | 306 | |
291 | - if ($this->currentPage == 0) $this->currentPage = 1; |
|
307 | + if ($this->currentPage == 0) { |
|
308 | + $this->currentPage = 1; |
|
309 | + } |
|
292 | 310 | |
293 | 311 | $numPages = intdiv($count , $this->maxPerPage); |
294 | - if ($count % $this->maxPerPage != 0 ) $numPages++; |
|
312 | + if ($count % $this->maxPerPage != 0 ) { |
|
313 | + $numPages++; |
|
314 | + } |
|
295 | 315 | |
296 | 316 | $html = '<div class="pagination-control" role="navigation">'; |
297 | 317 | $html .= '<ul class="nav tab-nav">'; |
@@ -305,8 +325,7 @@ discard block |
||
305 | 325 | </span> |
306 | 326 | </li> |
307 | 327 | '; |
308 | - } |
|
309 | - else |
|
328 | + } else |
|
310 | 329 | { |
311 | 330 | $html .= ' |
312 | 331 | <li class="nav-item"> |
@@ -322,7 +341,9 @@ discard block |
||
322 | 341 | $active = ($this->currentPage == $i) ? 'active' : ''; |
323 | 342 | $first = ($i-1)*$this->maxPerPage+1; |
324 | 343 | $last = $i * $this->maxPerPage; |
325 | - if ($last > $count) $last = $count; |
|
344 | + if ($last > $count) { |
|
345 | + $last = $count; |
|
346 | + } |
|
326 | 347 | $display = 'Show rows '. $first . ' to '. $last .' of '. $count; |
327 | 348 | $html .= '<li class="' . $active . ' nav-item"> |
328 | 349 | <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. $i .'" title="' . $display . '" aria-label="' . $display . '"> |
@@ -341,8 +362,7 @@ discard block |
||
341 | 362 | </span> |
342 | 363 | </li> |
343 | 364 | '; |
344 | - } |
|
345 | - else |
|
365 | + } else |
|
346 | 366 | { |
347 | 367 | $html .= ' |
348 | 368 | <li class="nav-item"> |
@@ -386,7 +406,9 @@ discard block |
||
386 | 406 | |
387 | 407 | public function groupingNextLine( $values) |
388 | 408 | { |
389 | - if ($this->grouppingActive === FALSE) return ''; |
|
409 | + if ($this->grouppingActive === FALSE) { |
|
410 | + return ''; |
|
411 | + } |
|
390 | 412 | |
391 | 413 | $dbcol = $this->groupingColumn; |
392 | 414 | if ($this->groupingVal == '' || $this->groupingVal != $values->$dbcol ) |
@@ -419,20 +441,17 @@ discard block |
||
419 | 441 | if ($this->order[$titleOrder] == 'ASC') |
420 | 442 | { |
421 | 443 | $titleOrder.='DESC'; |
422 | - } |
|
423 | - else |
|
444 | + } else |
|
424 | 445 | { |
425 | 446 | $titleOrder.='ASC'; |
426 | 447 | } |
427 | - } |
|
428 | - else |
|
448 | + } else |
|
429 | 449 | { |
430 | 450 | $titleOrder.='ASC'; |
431 | 451 | } |
432 | 452 | $actionURL = $this->getCurrentURLAndQS('order').'o='.$titleOrder; |
433 | 453 | $html .= '<th><a href="'.$actionURL.'">' . $values . '</a></th>'; |
434 | - } |
|
435 | - else |
|
454 | + } else |
|
436 | 455 | { |
437 | 456 | $html .= '<th>' . $values . '</th>'; |
438 | 457 | } |
@@ -4,18 +4,18 @@ discard block |
||
4 | 4 | |
5 | 5 | class TrapModuleConfig |
6 | 6 | { |
7 | - /********** Database configuration ***********************/ |
|
7 | + /********** Database configuration ***********************/ |
|
8 | 8 | // Database prefix for tables |
9 | - protected $table_prefix; //< Database prefix for tables |
|
9 | + protected $table_prefix; //< Database prefix for tables |
|
10 | 10 | protected $DBConfigDefaults=array( |
11 | 11 | 'db_remove_days' => 60, // number of days before removing traps |
12 | 12 | 'log_destination' => 'syslog', // Log destination for trap handler |
13 | 13 | 'log_file' => '/tmp/trapdirector.log', // Log file |
14 | 14 | 'log_level' => 2, // log level |
15 | 15 | 'use_SnmpTrapAddess' => 1, // use SnmpTrapAddress by default |
16 | - 'SnmpTrapAddess_oid' => '.1.3.6.1.6.3.18.1.3', // default snmpTrapAdress OID |
|
17 | - 'max_rows_in_list' => 5, // Max rows displayed in table before paging |
|
18 | - 'handler_categories' => '0:Not categorized' // handlers categories : <index>:<name>!<index>:<name> .... |
|
16 | + 'SnmpTrapAddess_oid' => '.1.3.6.1.6.3.18.1.3', // default snmpTrapAdress OID |
|
17 | + 'max_rows_in_list' => 5, // Max rows displayed in table before paging |
|
18 | + 'handler_categories' => '0:Not categorized' // handlers categories : <index>:<name>!<index>:<name> .... |
|
19 | 19 | ); |
20 | 20 | // get default values for dbconfig |
21 | 21 | public function getDBConfigDefaults() { return $this->DBConfigDefaults;} |
@@ -122,27 +122,27 @@ discard block |
||
122 | 122 | // Note : must have 'source_ip' and 'last_sent' |
123 | 123 | public function getTrapHostListDisplayColumns() |
124 | 124 | { |
125 | - return array( |
|
126 | - 'source_name' => 't.source_name', |
|
127 | - 'source_ip' => 't.source_ip', |
|
128 | - 'trap_oid' => 't.trap_oid', |
|
129 | - 'count' => 'count(*)', |
|
130 | - 'last_sent' => 'UNIX_TIMESTAMP(max(t.date_received))' |
|
131 | - ); |
|
125 | + return array( |
|
126 | + 'source_name' => 't.source_name', |
|
127 | + 'source_ip' => 't.source_ip', |
|
128 | + 'trap_oid' => 't.trap_oid', |
|
129 | + 'count' => 'count(*)', |
|
130 | + 'last_sent' => 'UNIX_TIMESTAMP(max(t.date_received))' |
|
131 | + ); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | public function getTrapHostListSearchColumns() |
135 | 135 | { |
136 | - return array(); // No search needed on this table |
|
136 | + return array(); // No search needed on this table |
|
137 | 137 | } |
138 | 138 | // Titles display in Trap List table |
139 | 139 | public function getTrapHostListTitles() |
140 | 140 | { |
141 | - return array( |
|
142 | - 'trap_oid' => 'Trap OID', |
|
143 | - 'count' => 'Number of traps received', |
|
144 | - 'last_sent' => 'Last trap received' |
|
145 | - ); |
|
141 | + return array( |
|
142 | + 'trap_oid' => 'Trap OID', |
|
143 | + 'count' => 'Number of traps received', |
|
144 | + 'last_sent' => 'Last trap received' |
|
145 | + ); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | |
@@ -157,13 +157,13 @@ discard block |
||
157 | 157 | 'source_ip' => "CASE WHEN r.ip4 IS NULL THEN r.ip6 ELSE r.ip4 END", |
158 | 158 | 'trap_oid' => 'r.trap_oid', |
159 | 159 | 'rule' => 'r.rule', |
160 | - 'comment' => 'r.comment', |
|
161 | - 'category' => 'r.rule_type', |
|
160 | + 'comment' => 'r.comment', |
|
161 | + 'category' => 'r.rule_type', |
|
162 | 162 | 'action_match' => 'r.action_match', |
163 | 163 | 'action_nomatch'=> 'r.action_nomatch', |
164 | 164 | 'service_name' => 'r.service_name', |
165 | 165 | 'num_match' => 'r.num_match', |
166 | - 'rule_type' => 'r.rule_type', |
|
166 | + 'rule_type' => 'r.rule_type', |
|
167 | 167 | 'id' => 'r.id' |
168 | 168 | ); |
169 | 169 | } |
@@ -184,17 +184,17 @@ discard block |
||
184 | 184 | } |
185 | 185 | public function getHandlerColumns() |
186 | 186 | { |
187 | - return array( |
|
188 | - 'r.host_name', 'r.host_group_name', |
|
189 | - 'r.ip4', 'r.ip6', |
|
190 | - 'r.trap_oid', |
|
191 | - 'r.rule', |
|
192 | - 'r.action_match', |
|
193 | - 'r.action_nomatch', |
|
194 | - 'r.service_name', |
|
195 | - 'r.num_match', |
|
196 | - 'r.id' |
|
197 | - ); |
|
187 | + return array( |
|
188 | + 'r.host_name', 'r.host_group_name', |
|
189 | + 'r.ip4', 'r.ip6', |
|
190 | + 'r.trap_oid', |
|
191 | + 'r.rule', |
|
192 | + 'r.action_match', |
|
193 | + 'r.action_nomatch', |
|
194 | + 'r.service_name', |
|
195 | + 'r.num_match', |
|
196 | + 'r.id' |
|
197 | + ); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | // handler update (<key> => <sql select>) |
@@ -214,9 +214,9 @@ discard block |
||
214 | 214 | 'revert_ok' => 'r.revert_ok', |
215 | 215 | 'display' => 'r.display', |
216 | 216 | 'modified' => 'UNIX_TIMESTAMP(r.modified)', |
217 | - 'modifier' => 'r.modifier', |
|
218 | - 'comment' => 'r.comment', |
|
219 | - 'category' => 'r.rule_type' |
|
217 | + 'modifier' => 'r.modifier', |
|
218 | + 'comment' => 'r.comment', |
|
219 | + 'category' => 'r.rule_type' |
|
220 | 220 | ); |
221 | 221 | } |
222 | 222 |
@@ -18,27 +18,27 @@ discard block |
||
18 | 18 | 'handler_categories' => '0:Not categorized' // handlers categories : <index>:<name>!<index>:<name> .... |
19 | 19 | ); |
20 | 20 | // get default values for dbconfig |
21 | - public function getDBConfigDefaults() { return $this->DBConfigDefaults;} |
|
21 | + public function getDBConfigDefaults() { return $this->DBConfigDefaults; } |
|
22 | 22 | /** Minimum DB version |
23 | 23 | * @return number |
24 | 24 | */ |
25 | - static public function getDbMinVersion() { return 2;} |
|
25 | + static public function getDbMinVersion() { return 2; } |
|
26 | 26 | /** Current DB version |
27 | 27 | * @return number |
28 | 28 | */ |
29 | - static public function getDbCurVersion() { return 2;} |
|
29 | + static public function getDbCurVersion() { return 2; } |
|
30 | 30 | |
31 | 31 | /************ Module configuration **********************/ |
32 | 32 | // Module base path |
33 | 33 | static public function urlPath() { return 'trapdirector'; } |
34 | - static public function getapiUserPermissions() { return array("status", "objects/query/Host", "objects/query/Service" , "actions/process-check-result"); } //< api user permissions required |
|
34 | + static public function getapiUserPermissions() { return array("status", "objects/query/Host", "objects/query/Service", "actions/process-check-result"); } //< api user permissions required |
|
35 | 35 | |
36 | 36 | |
37 | 37 | /*********** Log configuration *************************/ |
38 | 38 | protected $logLevels=array(0=>'No output', 1=>'critical', 2=>'warning', 3=>'trace', 4=>'ALL'); |
39 | - public function getlogLevels() { return $this->logLevels;} |
|
40 | - protected $logDestinations=array('syslog'=>'syslog','file'=>'file','display'=>'display'); |
|
41 | - public function getLogDestinations() { return $this->logDestinations;} |
|
39 | + public function getlogLevels() { return $this->logLevels; } |
|
40 | + protected $logDestinations=array('syslog'=>'syslog', 'file'=>'file', 'display'=>'display'); |
|
41 | + public function getLogDestinations() { return $this->logDestinations; } |
|
42 | 42 | |
43 | 43 | function __construct($prefix) |
44 | 44 | { |
@@ -49,29 +49,29 @@ discard block |
||
49 | 49 | // DB table name of trap received list : prefix 't' |
50 | 50 | public function getTrapTableName() |
51 | 51 | { |
52 | - return array('t' => $this->table_prefix . 'received'); |
|
52 | + return array('t' => $this->table_prefix.'received'); |
|
53 | 53 | } |
54 | 54 | // DB table name of trap data list : prefix 'd' |
55 | 55 | public function getTrapDataTableName() |
56 | 56 | { |
57 | - return array('d' => $this->table_prefix . 'received_data'); |
|
57 | + return array('d' => $this->table_prefix.'received_data'); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | // DB table name of rules : prefix 'r' |
61 | 61 | public function getTrapRuleName() |
62 | 62 | { |
63 | - return array('r' => $this->table_prefix . 'rules'); |
|
63 | + return array('r' => $this->table_prefix.'rules'); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | // DB table name of db config : prefix 'c' |
67 | 67 | public function getDbConfigTableName() |
68 | 68 | { |
69 | - return array('c' => $this->table_prefix . 'db_config'); |
|
69 | + return array('c' => $this->table_prefix.'db_config'); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | // Mib cache tables |
73 | - public function getMIBCacheTableName() { return $this->table_prefix . 'mib_cache'; } |
|
74 | - public function getMIBCacheTableTrapObjName() { return $this->table_prefix . 'mib_cache_trap_object'; } |
|
73 | + public function getMIBCacheTableName() { return $this->table_prefix.'mib_cache'; } |
|
74 | + public function getMIBCacheTableTrapObjName() { return $this->table_prefix.'mib_cache_trap_object'; } |
|
75 | 75 | |
76 | 76 | |
77 | 77 | /****************** Database queries *******************/ |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | public function getHandlerListDisplayColumns() |
153 | 153 | { |
154 | 154 | return array( |
155 | - 'host_name' => 'r.host_name',//'UNIX_TIMESTAMP(t.date_received)', |
|
155 | + 'host_name' => 'r.host_name', //'UNIX_TIMESTAMP(t.date_received)', |
|
156 | 156 | 'host_group_name'=> 'r.host_group_name', |
157 | 157 | 'source_ip' => "CASE WHEN r.ip4 IS NULL THEN r.ip6 ELSE r.ip4 END", |
158 | 158 | 'trap_oid' => 'r.trap_oid', |
@@ -224,32 +224,32 @@ discard block |
||
224 | 224 | public function trapDetailQuery() |
225 | 225 | { |
226 | 226 | return array( |
227 | - 'timestamp' => array('Date','UNIX_TIMESTAMP(t.date_received)'), |
|
228 | - 'source_ip' => array('Source IP','t.source_ip'), |
|
229 | - 'source_name' => array('Source name','t.source_name'), |
|
230 | - 'source_port' => array('Source port','t.source_port'), |
|
231 | - 'destination_ip' => array('Destination IP','t.destination_ip'), |
|
232 | - 'destination_port' => array('Destination port','t.destination_port'), |
|
233 | - 'trap_oid' => array('Numeric OID','t.trap_oid'), |
|
234 | - 'trap_name' => array('Trap name','t.trap_name'), |
|
235 | - 'trap_name_mib' => array('Trap MIB','t.trap_name_mib'), |
|
236 | - 'status' => array('Processing status','t.status'), |
|
237 | - 'status_detail' => array('Status details','t.status_detail'), |
|
238 | - 'process_time' => array('Trap processing time','t.process_time'), |
|
227 | + 'timestamp' => array('Date', 'UNIX_TIMESTAMP(t.date_received)'), |
|
228 | + 'source_ip' => array('Source IP', 't.source_ip'), |
|
229 | + 'source_name' => array('Source name', 't.source_name'), |
|
230 | + 'source_port' => array('Source port', 't.source_port'), |
|
231 | + 'destination_ip' => array('Destination IP', 't.destination_ip'), |
|
232 | + 'destination_port' => array('Destination port', 't.destination_port'), |
|
233 | + 'trap_oid' => array('Numeric OID', 't.trap_oid'), |
|
234 | + 'trap_name' => array('Trap name', 't.trap_name'), |
|
235 | + 'trap_name_mib' => array('Trap MIB', 't.trap_name_mib'), |
|
236 | + 'status' => array('Processing status', 't.status'), |
|
237 | + 'status_detail' => array('Status details', 't.status_detail'), |
|
238 | + 'process_time' => array('Trap processing time', 't.process_time'), |
|
239 | 239 | ); |
240 | 240 | } |
241 | 241 | // Trap detail : additional data (<key> => <title> <sql select>) |
242 | 242 | public function trapDataDetailQuery() |
243 | 243 | { |
244 | 244 | return array( |
245 | - 'oid' => array('Numeric OID','d.oid'), |
|
246 | - 'oid_name' => array('Text OID','d.oid_name'), |
|
247 | - 'oid_name_mib' => array('MIB','d.oid_name_mib'), |
|
248 | - 'value' => array('Value','d.value'), |
|
245 | + 'oid' => array('Numeric OID', 'd.oid'), |
|
246 | + 'oid_name' => array('Text OID', 'd.oid_name'), |
|
247 | + 'oid_name_mib' => array('MIB', 'd.oid_name_mib'), |
|
248 | + 'value' => array('Value', 'd.value'), |
|
249 | 249 | ); |
250 | 250 | } |
251 | 251 | // foreign key of trap data table |
252 | - public function trapDataFK() { return 'trap_id';} |
|
252 | + public function trapDataFK() { return 'trap_id'; } |
|
253 | 253 | |
254 | 254 | // Max items in a list OBSOLETE TODO : remove after all tables moved to trapdirectorTable |
255 | 255 | public function itemListDisplay() { return 25; } |
@@ -47,8 +47,8 @@ discard block |
||
47 | 47 | |
48 | 48 | |
49 | 49 | /** Get instance of TrapModuleConfig class |
50 | - * @return TrapModuleConfig |
|
51 | - */ |
|
50 | + * @return TrapModuleConfig |
|
51 | + */ |
|
52 | 52 | public function getModuleConfig() |
53 | 53 | { |
54 | 54 | if ($this->moduleConfig == Null) |
@@ -80,12 +80,12 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function getTrapHostListTable() |
82 | 82 | { |
83 | - if ($this->trapTableHostList == Null) |
|
83 | + if ($this->trapTableHostList == Null) |
|
84 | 84 | { |
85 | - $this->trapTableHostList = new TrapTableHostList(); |
|
86 | - $this->trapTableHostList->setConfig($this->getModuleConfig()); |
|
87 | - } |
|
88 | - return $this->trapTableHostList; |
|
85 | + $this->trapTableHostList = new TrapTableHostList(); |
|
86 | + $this->trapTableHostList->setConfig($this->getModuleConfig()); |
|
87 | + } |
|
88 | + return $this->trapTableHostList; |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -106,12 +106,12 @@ discard block |
||
106 | 106 | */ |
107 | 107 | public function getUIDatabase() |
108 | 108 | { |
109 | - if ($this->UIDatabase == Null) |
|
110 | - { |
|
111 | - $this->UIDatabase = new UIDatabase($this); |
|
109 | + if ($this->UIDatabase == Null) |
|
110 | + { |
|
111 | + $this->UIDatabase = new UIDatabase($this); |
|
112 | 112 | |
113 | - } |
|
114 | - return $this->UIDatabase; |
|
113 | + } |
|
114 | + return $this->UIDatabase; |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -120,34 +120,34 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public function getIdoConn() |
122 | 122 | { |
123 | - if ($this->icingaAPI === NULL) |
|
124 | - { |
|
125 | - $host = $this->Config()->get('config', 'icingaAPI_host'); |
|
126 | - $port = $this->Config()->get('config', 'icingaAPI_port'); |
|
127 | - $user = $this->Config()->get('config', 'icingaAPI_user'); |
|
128 | - $pass = $this->Config()->get('config', 'icingaAPI_password'); |
|
129 | - $this->icingaAPI = new Icinga2API($host,$port); |
|
130 | - $this->icingaAPI->setCredentials($user, $pass); |
|
131 | - list($ret,$message) = $this->icingaAPI->test(NULL); |
|
132 | - if ($ret === TRUE) |
|
133 | - { |
|
134 | - return $this->getUIDatabase(); |
|
135 | - } |
|
123 | + if ($this->icingaAPI === NULL) |
|
124 | + { |
|
125 | + $host = $this->Config()->get('config', 'icingaAPI_host'); |
|
126 | + $port = $this->Config()->get('config', 'icingaAPI_port'); |
|
127 | + $user = $this->Config()->get('config', 'icingaAPI_user'); |
|
128 | + $pass = $this->Config()->get('config', 'icingaAPI_password'); |
|
129 | + $this->icingaAPI = new Icinga2API($host,$port); |
|
130 | + $this->icingaAPI->setCredentials($user, $pass); |
|
131 | + list($ret,$message) = $this->icingaAPI->test(NULL); |
|
132 | + if ($ret === TRUE) |
|
133 | + { |
|
134 | + return $this->getUIDatabase(); |
|
135 | + } |
|
136 | 136 | |
137 | - } |
|
138 | - return $this->icingaAPI; |
|
137 | + } |
|
138 | + return $this->icingaAPI; |
|
139 | 139 | |
140 | 140 | } |
141 | 141 | |
142 | - protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null) |
|
143 | - { |
|
144 | - $limit = $this->params->get('limit', $limit); |
|
145 | - $page = $this->params->get('page', $offset); |
|
142 | + protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null) |
|
143 | + { |
|
144 | + $limit = $this->params->get('limit', $limit); |
|
145 | + $page = $this->params->get('page', $offset); |
|
146 | 146 | |
147 | - $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0); |
|
147 | + $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0); |
|
148 | 148 | |
149 | - return $paginatable; |
|
150 | - } |
|
149 | + return $paginatable; |
|
150 | + } |
|
151 | 151 | |
152 | 152 | public function displayExitError($source,$message) |
153 | 153 | { // TODO : check better ways to transmit data (with POST ?) |
@@ -156,33 +156,33 @@ discard block |
||
156 | 156 | |
157 | 157 | protected function checkReadPermission() |
158 | 158 | { |
159 | - if (! $this->Auth()->hasPermission('trapdirector/view')) { |
|
160 | - $this->displayExitError('Permissions','No permission fo view content'); |
|
161 | - } |
|
159 | + if (! $this->Auth()->hasPermission('trapdirector/view')) { |
|
160 | + $this->displayExitError('Permissions','No permission fo view content'); |
|
161 | + } |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | protected function checkConfigPermission() |
165 | 165 | { |
166 | - if (! $this->Auth()->hasPermission('trapdirector/config')) { |
|
167 | - $this->displayExitError('Permissions','No permission fo configure'); |
|
168 | - } |
|
166 | + if (! $this->Auth()->hasPermission('trapdirector/config')) { |
|
167 | + $this->displayExitError('Permissions','No permission fo configure'); |
|
168 | + } |
|
169 | 169 | } |
170 | 170 | |
171 | - /** |
|
172 | - * Check if user has write permission |
|
173 | - * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page |
|
174 | - * @return boolean : user has permission |
|
175 | - */ |
|
171 | + /** |
|
172 | + * Check if user has write permission |
|
173 | + * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page |
|
174 | + * @return boolean : user has permission |
|
175 | + */ |
|
176 | 176 | protected function checkModuleConfigPermission($check=0) |
177 | 177 | { |
178 | - if (! $this->Auth()->hasPermission('trapdirector/module_config')) { |
|
179 | - if ($check == 0) |
|
180 | - { |
|
181 | - $this->displayExitError('Permissions','No permission fo configure module'); |
|
182 | - } |
|
183 | - return false; |
|
184 | - } |
|
185 | - return true; |
|
178 | + if (! $this->Auth()->hasPermission('trapdirector/module_config')) { |
|
179 | + if ($check == 0) |
|
180 | + { |
|
181 | + $this->displayExitError('Permissions','No permission fo configure module'); |
|
182 | + } |
|
183 | + return false; |
|
184 | + } |
|
185 | + return true; |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /************************* Trap class get **********************/ |
@@ -202,18 +202,18 @@ discard block |
||
202 | 202 | /************************** MIB related **************************/ |
203 | 203 | |
204 | 204 | /** Get MIBLoader class |
205 | - * @return MIBLoader class |
|
206 | - */ |
|
205 | + * @return MIBLoader class |
|
206 | + */ |
|
207 | 207 | protected function getMIB() |
208 | 208 | { |
209 | 209 | if ($this->MIBData == null) |
210 | 210 | { |
211 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
212 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
211 | + $dbConn = $this->getUIDatabase()->getDbConn(); |
|
212 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
213 | 213 | $this->MIBData=new MIBLoader( |
214 | 214 | $this->Config()->get('config', 'snmptranslate'), |
215 | 215 | $this->Config()->get('config', 'snmptranslate_dirs'), |
216 | - $dbConn, |
|
216 | + $dbConn, |
|
217 | 217 | $this->getModuleConfig() |
218 | 218 | ); |
219 | 219 | } |
@@ -223,13 +223,13 @@ discard block |
||
223 | 223 | /************************** Database queries *******************/ |
224 | 224 | |
225 | 225 | /** Check if director is installed |
226 | - * @return bool true/false |
|
227 | - */ |
|
226 | + * @return bool true/false |
|
227 | + */ |
|
228 | 228 | protected function isDirectorInstalled() |
229 | 229 | { |
230 | - $output=array(); |
|
231 | - exec('icingacli module list',$output); |
|
232 | - foreach ($output as $line) |
|
230 | + $output=array(); |
|
231 | + exec('icingacli module list',$output); |
|
232 | + foreach ($output as $line) |
|
233 | 233 | { |
234 | 234 | if (preg_match('/^director .*enabled/',$line)) |
235 | 235 | { |
@@ -242,72 +242,72 @@ discard block |
||
242 | 242 | |
243 | 243 | /************************ UI elements **************************/ |
244 | 244 | |
245 | - /** |
|
246 | - * get max rows to display before paging. |
|
247 | - * @return number |
|
248 | - */ |
|
245 | + /** |
|
246 | + * get max rows to display before paging. |
|
247 | + * @return number |
|
248 | + */ |
|
249 | 249 | public function itemListDisplay() |
250 | 250 | { |
251 | - return $this->getUIDatabase()->getDBConfigValue('max_rows_in_list'); |
|
251 | + return $this->getUIDatabase()->getDBConfigValue('max_rows_in_list'); |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | public function setitemListDisplay(int $maxRows) |
255 | 255 | { |
256 | - return $this->getUIDatabase()->setDBConfigValue('max_rows_in_list',$maxRows); |
|
256 | + return $this->getUIDatabase()->setDBConfigValue('max_rows_in_list',$maxRows); |
|
257 | 257 | } |
258 | 258 | |
259 | - /** |
|
260 | - * get Handlers categories list (index => textvalue). |
|
261 | - * @return array |
|
262 | - */ |
|
259 | + /** |
|
260 | + * get Handlers categories list (index => textvalue). |
|
261 | + * @return array |
|
262 | + */ |
|
263 | 263 | public function getHandlersCategory() |
264 | 264 | { |
265 | - //<index>:<name>!<index>:<name> |
|
266 | - $catList = $this->getUIDatabase()->getDBConfigValue('handler_categories'); |
|
267 | - $catListArray=explode('!',$catList); |
|
268 | - $retArray=array(); |
|
269 | - foreach ($catListArray as $category) |
|
270 | - { |
|
271 | - $catArray=explode(':',$category); |
|
272 | - $retArray[$catArray[0]] = $catArray[1]; |
|
273 | - } |
|
274 | - return $retArray; |
|
265 | + //<index>:<name>!<index>:<name> |
|
266 | + $catList = $this->getUIDatabase()->getDBConfigValue('handler_categories'); |
|
267 | + $catListArray=explode('!',$catList); |
|
268 | + $retArray=array(); |
|
269 | + foreach ($catListArray as $category) |
|
270 | + { |
|
271 | + $catArray=explode(':',$category); |
|
272 | + $retArray[$catArray[0]] = $catArray[1]; |
|
273 | + } |
|
274 | + return $retArray; |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | public function setHandlerCategory(array $catArray) |
278 | 278 | { |
279 | - $catString=''; |
|
280 | - foreach ($catArray as $index => $value) |
|
281 | - { |
|
282 | - if ($catString != '' ) $catString .= '!'; |
|
283 | - $catString .= $index . ':' . $value; |
|
284 | - } |
|
285 | - $this->getUIDatabase()->setDBConfigValue('handler_categories', $catString); |
|
279 | + $catString=''; |
|
280 | + foreach ($catArray as $index => $value) |
|
281 | + { |
|
282 | + if ($catString != '' ) $catString .= '!'; |
|
283 | + $catString .= $index . ':' . $value; |
|
284 | + } |
|
285 | + $this->getUIDatabase()->setDBConfigValue('handler_categories', $catString); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | public function addHandlersCategory(string $catName) |
289 | 289 | { |
290 | - $catArray = $this->getHandlersCategory(); |
|
291 | - $i=1; |
|
292 | - while (isset($catArray[$i]) && $i < 100) $i++; |
|
293 | - if ($i == 100) throw new ProgrammingError('Category array error'); |
|
294 | - $catArray[$i] = $catName; |
|
295 | - $this->setHandlerCategory($catArray); |
|
290 | + $catArray = $this->getHandlersCategory(); |
|
291 | + $i=1; |
|
292 | + while (isset($catArray[$i]) && $i < 100) $i++; |
|
293 | + if ($i == 100) throw new ProgrammingError('Category array error'); |
|
294 | + $catArray[$i] = $catName; |
|
295 | + $this->setHandlerCategory($catArray); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | public function delHandlersCategory(int $catIndex) |
299 | 299 | { |
300 | - $catArray = $this->getHandlersCategory(); |
|
301 | - unset($catArray[$catIndex]); |
|
302 | - $this->setHandlerCategory($catArray); |
|
303 | - $this->getUIDatabase()->updateHandlersOnCategoryDelete($catIndex); |
|
300 | + $catArray = $this->getHandlersCategory(); |
|
301 | + unset($catArray[$catIndex]); |
|
302 | + $this->setHandlerCategory($catArray); |
|
303 | + $this->getUIDatabase()->updateHandlersOnCategoryDelete($catIndex); |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | public function renameHandlersCategory(int $catIndex, string $catName) |
307 | 307 | { |
308 | - $catArray = $this->getHandlersCategory(); |
|
309 | - $catArray[$catIndex] = $catName; |
|
310 | - $this->setHandlerCategory($catArray); |
|
308 | + $catArray = $this->getHandlersCategory(); |
|
309 | + $catArray[$catIndex] = $catName; |
|
310 | + $this->setHandlerCategory($catArray); |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | /** @var UIDatabase $UIDatabase */ |
43 | 43 | protected $UIDatabase; |
44 | 44 | /** @var Icinga2Api $IcingaAPI */ |
45 | - protected $icingaAPI = NULL; |
|
45 | + protected $icingaAPI=NULL; |
|
46 | 46 | |
47 | 47 | |
48 | 48 | |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | { |
59 | 59 | $this->redirectNow('trapdirector/settings?message=No database prefix'); |
60 | 60 | } |
61 | - $this->moduleConfig = new TrapModuleConfig($db_prefix); |
|
61 | + $this->moduleConfig=new TrapModuleConfig($db_prefix); |
|
62 | 62 | } |
63 | 63 | return $this->moduleConfig; |
64 | 64 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function getTrapListTable() { |
71 | 71 | if ($this->trapTableList == Null) { |
72 | - $this->trapTableList = new TrapTableList(); |
|
72 | + $this->trapTableList=new TrapTableList(); |
|
73 | 73 | $this->trapTableList->setConfig($this->getModuleConfig()); |
74 | 74 | } |
75 | 75 | return $this->trapTableList; |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | { |
83 | 83 | if ($this->trapTableHostList == Null) |
84 | 84 | { |
85 | - $this->trapTableHostList = new TrapTableHostList(); |
|
85 | + $this->trapTableHostList=new TrapTableHostList(); |
|
86 | 86 | $this->trapTableHostList->setConfig($this->getModuleConfig()); |
87 | 87 | } |
88 | 88 | return $this->trapTableHostList; |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | { |
96 | 96 | if ($this->handlerTableList == Null) |
97 | 97 | { |
98 | - $this->handlerTableList = new HandlerTableList(); |
|
98 | + $this->handlerTableList=new HandlerTableList(); |
|
99 | 99 | $this->handlerTableList->setConfig($this->getModuleConfig()); |
100 | 100 | } |
101 | 101 | return $this->handlerTableList; |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | { |
109 | 109 | if ($this->UIDatabase == Null) |
110 | 110 | { |
111 | - $this->UIDatabase = new UIDatabase($this); |
|
111 | + $this->UIDatabase=new UIDatabase($this); |
|
112 | 112 | |
113 | 113 | } |
114 | 114 | return $this->UIDatabase; |
@@ -122,13 +122,13 @@ discard block |
||
122 | 122 | { |
123 | 123 | if ($this->icingaAPI === NULL) |
124 | 124 | { |
125 | - $host = $this->Config()->get('config', 'icingaAPI_host'); |
|
126 | - $port = $this->Config()->get('config', 'icingaAPI_port'); |
|
127 | - $user = $this->Config()->get('config', 'icingaAPI_user'); |
|
128 | - $pass = $this->Config()->get('config', 'icingaAPI_password'); |
|
129 | - $this->icingaAPI = new Icinga2API($host,$port); |
|
125 | + $host=$this->Config()->get('config', 'icingaAPI_host'); |
|
126 | + $port=$this->Config()->get('config', 'icingaAPI_port'); |
|
127 | + $user=$this->Config()->get('config', 'icingaAPI_user'); |
|
128 | + $pass=$this->Config()->get('config', 'icingaAPI_password'); |
|
129 | + $this->icingaAPI=new Icinga2API($host, $port); |
|
130 | 130 | $this->icingaAPI->setCredentials($user, $pass); |
131 | - list($ret,$message) = $this->icingaAPI->test(NULL); |
|
131 | + list($ret, $message)=$this->icingaAPI->test(NULL); |
|
132 | 132 | if ($ret === TRUE) |
133 | 133 | { |
134 | 134 | return $this->getUIDatabase(); |
@@ -139,32 +139,32 @@ discard block |
||
139 | 139 | |
140 | 140 | } |
141 | 141 | |
142 | - protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null) |
|
142 | + protected function applyPaginationLimits(Paginatable $paginatable, $limit=25, $offset=null) |
|
143 | 143 | { |
144 | - $limit = $this->params->get('limit', $limit); |
|
145 | - $page = $this->params->get('page', $offset); |
|
144 | + $limit=$this->params->get('limit', $limit); |
|
145 | + $page=$this->params->get('page', $offset); |
|
146 | 146 | |
147 | 147 | $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0); |
148 | 148 | |
149 | 149 | return $paginatable; |
150 | 150 | } |
151 | 151 | |
152 | - public function displayExitError($source,$message) |
|
152 | + public function displayExitError($source, $message) |
|
153 | 153 | { // TODO : check better ways to transmit data (with POST ?) |
154 | 154 | $this->redirectNow('trapdirector/error?source='.$source.'&message='.$message); |
155 | 155 | } |
156 | 156 | |
157 | 157 | protected function checkReadPermission() |
158 | 158 | { |
159 | - if (! $this->Auth()->hasPermission('trapdirector/view')) { |
|
160 | - $this->displayExitError('Permissions','No permission fo view content'); |
|
159 | + if (!$this->Auth()->hasPermission('trapdirector/view')) { |
|
160 | + $this->displayExitError('Permissions', 'No permission fo view content'); |
|
161 | 161 | } |
162 | 162 | } |
163 | 163 | |
164 | 164 | protected function checkConfigPermission() |
165 | 165 | { |
166 | - if (! $this->Auth()->hasPermission('trapdirector/config')) { |
|
167 | - $this->displayExitError('Permissions','No permission fo configure'); |
|
166 | + if (!$this->Auth()->hasPermission('trapdirector/config')) { |
|
167 | + $this->displayExitError('Permissions', 'No permission fo configure'); |
|
168 | 168 | } |
169 | 169 | } |
170 | 170 | |
@@ -175,10 +175,10 @@ discard block |
||
175 | 175 | */ |
176 | 176 | protected function checkModuleConfigPermission($check=0) |
177 | 177 | { |
178 | - if (! $this->Auth()->hasPermission('trapdirector/module_config')) { |
|
178 | + if (!$this->Auth()->hasPermission('trapdirector/module_config')) { |
|
179 | 179 | if ($check == 0) |
180 | 180 | { |
181 | - $this->displayExitError('Permissions','No permission fo configure module'); |
|
181 | + $this->displayExitError('Permissions', 'No permission fo configure module'); |
|
182 | 182 | } |
183 | 183 | return false; |
184 | 184 | } |
@@ -190,10 +190,10 @@ discard block |
||
190 | 190 | { // TODO : try/catch here ? or within caller |
191 | 191 | if ($this->trapClass == null) |
192 | 192 | { |
193 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
193 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
194 | 194 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
195 | 195 | //$debug_level=4; |
196 | - $this->trapClass = new Trap($icingaweb2_etc); |
|
196 | + $this->trapClass=new Trap($icingaweb2_etc); |
|
197 | 197 | //$Trap->setLogging($debug_level,'syslog'); |
198 | 198 | } |
199 | 199 | return $this->trapClass; |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | { |
209 | 209 | if ($this->MIBData == null) |
210 | 210 | { |
211 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
211 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
212 | 212 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
213 | 213 | $this->MIBData=new MIBLoader( |
214 | 214 | $this->Config()->get('config', 'snmptranslate'), |
@@ -228,10 +228,10 @@ discard block |
||
228 | 228 | protected function isDirectorInstalled() |
229 | 229 | { |
230 | 230 | $output=array(); |
231 | - exec('icingacli module list',$output); |
|
231 | + exec('icingacli module list', $output); |
|
232 | 232 | foreach ($output as $line) |
233 | 233 | { |
234 | - if (preg_match('/^director .*enabled/',$line)) |
|
234 | + if (preg_match('/^director .*enabled/', $line)) |
|
235 | 235 | { |
236 | 236 | return true; |
237 | 237 | } |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | |
254 | 254 | public function setitemListDisplay(int $maxRows) |
255 | 255 | { |
256 | - return $this->getUIDatabase()->setDBConfigValue('max_rows_in_list',$maxRows); |
|
256 | + return $this->getUIDatabase()->setDBConfigValue('max_rows_in_list', $maxRows); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
@@ -263,13 +263,13 @@ discard block |
||
263 | 263 | public function getHandlersCategory() |
264 | 264 | { |
265 | 265 | //<index>:<name>!<index>:<name> |
266 | - $catList = $this->getUIDatabase()->getDBConfigValue('handler_categories'); |
|
267 | - $catListArray=explode('!',$catList); |
|
266 | + $catList=$this->getUIDatabase()->getDBConfigValue('handler_categories'); |
|
267 | + $catListArray=explode('!', $catList); |
|
268 | 268 | $retArray=array(); |
269 | 269 | foreach ($catListArray as $category) |
270 | 270 | { |
271 | - $catArray=explode(':',$category); |
|
272 | - $retArray[$catArray[0]] = $catArray[1]; |
|
271 | + $catArray=explode(':', $category); |
|
272 | + $retArray[$catArray[0]]=$catArray[1]; |
|
273 | 273 | } |
274 | 274 | return $retArray; |
275 | 275 | } |
@@ -279,25 +279,25 @@ discard block |
||
279 | 279 | $catString=''; |
280 | 280 | foreach ($catArray as $index => $value) |
281 | 281 | { |
282 | - if ($catString != '' ) $catString .= '!'; |
|
283 | - $catString .= $index . ':' . $value; |
|
282 | + if ($catString != '') $catString.='!'; |
|
283 | + $catString.=$index.':'.$value; |
|
284 | 284 | } |
285 | 285 | $this->getUIDatabase()->setDBConfigValue('handler_categories', $catString); |
286 | 286 | } |
287 | 287 | |
288 | 288 | public function addHandlersCategory(string $catName) |
289 | 289 | { |
290 | - $catArray = $this->getHandlersCategory(); |
|
290 | + $catArray=$this->getHandlersCategory(); |
|
291 | 291 | $i=1; |
292 | 292 | while (isset($catArray[$i]) && $i < 100) $i++; |
293 | 293 | if ($i == 100) throw new ProgrammingError('Category array error'); |
294 | - $catArray[$i] = $catName; |
|
294 | + $catArray[$i]=$catName; |
|
295 | 295 | $this->setHandlerCategory($catArray); |
296 | 296 | } |
297 | 297 | |
298 | 298 | public function delHandlersCategory(int $catIndex) |
299 | 299 | { |
300 | - $catArray = $this->getHandlersCategory(); |
|
300 | + $catArray=$this->getHandlersCategory(); |
|
301 | 301 | unset($catArray[$catIndex]); |
302 | 302 | $this->setHandlerCategory($catArray); |
303 | 303 | $this->getUIDatabase()->updateHandlersOnCategoryDelete($catIndex); |
@@ -305,8 +305,8 @@ discard block |
||
305 | 305 | |
306 | 306 | public function renameHandlersCategory(int $catIndex, string $catName) |
307 | 307 | { |
308 | - $catArray = $this->getHandlersCategory(); |
|
309 | - $catArray[$catIndex] = $catName; |
|
308 | + $catArray=$this->getHandlersCategory(); |
|
309 | + $catArray[$catIndex]=$catName; |
|
310 | 310 | $this->setHandlerCategory($catArray); |
311 | 311 | } |
312 | 312 |
@@ -209,7 +209,9 @@ discard block |
||
209 | 209 | if ($this->MIBData == null) |
210 | 210 | { |
211 | 211 | $dbConn = $this->getUIDatabase()->getDbConn(); |
212 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
212 | + if ($dbConn === null) { |
|
213 | + throw new \ErrorException('uncatched db error'); |
|
214 | + } |
|
213 | 215 | $this->MIBData=new MIBLoader( |
214 | 216 | $this->Config()->get('config', 'snmptranslate'), |
215 | 217 | $this->Config()->get('config', 'snmptranslate_dirs'), |
@@ -279,7 +281,9 @@ discard block |
||
279 | 281 | $catString=''; |
280 | 282 | foreach ($catArray as $index => $value) |
281 | 283 | { |
282 | - if ($catString != '' ) $catString .= '!'; |
|
284 | + if ($catString != '' ) { |
|
285 | + $catString .= '!'; |
|
286 | + } |
|
283 | 287 | $catString .= $index . ':' . $value; |
284 | 288 | } |
285 | 289 | $this->getUIDatabase()->setDBConfigValue('handler_categories', $catString); |
@@ -289,8 +293,12 @@ discard block |
||
289 | 293 | { |
290 | 294 | $catArray = $this->getHandlersCategory(); |
291 | 295 | $i=1; |
292 | - while (isset($catArray[$i]) && $i < 100) $i++; |
|
293 | - if ($i == 100) throw new ProgrammingError('Category array error'); |
|
296 | + while (isset($catArray[$i]) && $i < 100) { |
|
297 | + $i++; |
|
298 | + } |
|
299 | + if ($i == 100) { |
|
300 | + throw new ProgrammingError('Category array error'); |
|
301 | + } |
|
294 | 302 | $catArray[$i] = $catName; |
295 | 303 | $this->setHandlerCategory($catArray); |
296 | 304 | } |
@@ -20,245 +20,245 @@ |
||
20 | 20 | trait TrapDBQuery |
21 | 21 | { |
22 | 22 | |
23 | - /** @return TrapsController */ |
|
24 | - abstract protected function getTrapCtrl(); |
|
23 | + /** @return TrapsController */ |
|
24 | + abstract protected function getTrapCtrl(); |
|
25 | 25 | |
26 | - /** @return Zend_Db_Adapter_Abstract : returns DB connexion or null on error */ |
|
27 | - abstract public function getDbConn(); |
|
26 | + /** @return Zend_Db_Adapter_Abstract : returns DB connexion or null on error */ |
|
27 | + abstract public function getDbConn(); |
|
28 | 28 | |
29 | - /** Add handler rule in traps DB |
|
30 | - * @param array $params : array(<db item>=><value>) |
|
31 | - * @return int inserted id |
|
32 | - */ |
|
33 | - public function addHandlerRule($params) |
|
34 | - { |
|
35 | - // TODO Check for rule consistency |
|
29 | + /** Add handler rule in traps DB |
|
30 | + * @param array $params : array(<db item>=><value>) |
|
31 | + * @return int inserted id |
|
32 | + */ |
|
33 | + public function addHandlerRule($params) |
|
34 | + { |
|
35 | + // TODO Check for rule consistency |
|
36 | 36 | |
37 | - $dbConn = $this->getDbConn(); |
|
38 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
39 | - // Add last modified date = creation date and username |
|
40 | - $params['created'] = new Zend_Db_Expr('NOW()'); |
|
41 | - $params['modified'] = new Zend_Db_Expr('NOW()'); |
|
42 | - $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername(); |
|
37 | + $dbConn = $this->getDbConn(); |
|
38 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
39 | + // Add last modified date = creation date and username |
|
40 | + $params['created'] = new Zend_Db_Expr('NOW()'); |
|
41 | + $params['modified'] = new Zend_Db_Expr('NOW()'); |
|
42 | + $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername(); |
|
43 | 43 | |
44 | - $query=$dbConn->insert( |
|
45 | - $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
|
46 | - $params |
|
47 | - ); |
|
48 | - if($query==false) |
|
49 | - { |
|
50 | - return null; |
|
51 | - } |
|
52 | - return $dbConn->lastInsertId(); |
|
53 | - } |
|
44 | + $query=$dbConn->insert( |
|
45 | + $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
|
46 | + $params |
|
47 | + ); |
|
48 | + if($query==false) |
|
49 | + { |
|
50 | + return null; |
|
51 | + } |
|
52 | + return $dbConn->lastInsertId(); |
|
53 | + } |
|
54 | 54 | |
55 | - /** Update handler rule in traps DB |
|
56 | - * @param array $params : (<db item>=><value>) |
|
57 | - * @param integer $ruleID : rule id in db |
|
58 | - * @return array affected rows |
|
59 | - */ |
|
60 | - public function updateHandlerRule($params,$ruleID) |
|
61 | - { |
|
62 | - // TODO Check for rule consistency |
|
63 | - $dbConn = $this->getDbConn(); |
|
64 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
65 | - // Add last modified date = creation date and username |
|
66 | - $params['modified'] = new Zend_Db_Expr('NOW()'); |
|
67 | - $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername(); |
|
55 | + /** Update handler rule in traps DB |
|
56 | + * @param array $params : (<db item>=><value>) |
|
57 | + * @param integer $ruleID : rule id in db |
|
58 | + * @return array affected rows |
|
59 | + */ |
|
60 | + public function updateHandlerRule($params,$ruleID) |
|
61 | + { |
|
62 | + // TODO Check for rule consistency |
|
63 | + $dbConn = $this->getDbConn(); |
|
64 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
65 | + // Add last modified date = creation date and username |
|
66 | + $params['modified'] = new Zend_Db_Expr('NOW()'); |
|
67 | + $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername(); |
|
68 | 68 | |
69 | - $numRows=$dbConn->update( |
|
70 | - $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
|
71 | - $params, |
|
72 | - 'id='.$ruleID |
|
73 | - ); |
|
74 | - return $numRows; |
|
75 | - } |
|
69 | + $numRows=$dbConn->update( |
|
70 | + $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
|
71 | + $params, |
|
72 | + 'id='.$ruleID |
|
73 | + ); |
|
74 | + return $numRows; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * ON category removal, put back cat to 0 on handlers with this category. |
|
79 | - * @param int $catIndex |
|
80 | - * @throws \ErrorException |
|
81 | - * @return number |
|
82 | - */ |
|
83 | - public function updateHandlersOnCategoryDelete($catIndex) |
|
84 | - { |
|
85 | - // TODO Check for rule consistency |
|
86 | - $dbConn = $this->getDbConn(); |
|
87 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
77 | + /** |
|
78 | + * ON category removal, put back cat to 0 on handlers with this category. |
|
79 | + * @param int $catIndex |
|
80 | + * @throws \ErrorException |
|
81 | + * @return number |
|
82 | + */ |
|
83 | + public function updateHandlersOnCategoryDelete($catIndex) |
|
84 | + { |
|
85 | + // TODO Check for rule consistency |
|
86 | + $dbConn = $this->getDbConn(); |
|
87 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
88 | 88 | |
89 | - $numRows=$dbConn->update( |
|
90 | - $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
|
91 | - array('rule_type' => 0), |
|
92 | - 'rule_type='.$catIndex |
|
93 | - ); |
|
94 | - return $numRows; |
|
95 | - } |
|
89 | + $numRows=$dbConn->update( |
|
90 | + $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
|
91 | + array('rule_type' => 0), |
|
92 | + 'rule_type='.$catIndex |
|
93 | + ); |
|
94 | + return $numRows; |
|
95 | + } |
|
96 | 96 | |
97 | - /** Delete rule by id |
|
98 | - * @param int $ruleID rule id |
|
99 | - */ |
|
100 | - public function deleteRule($ruleID) |
|
101 | - { |
|
102 | - if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id'); } |
|
97 | + /** Delete rule by id |
|
98 | + * @param int $ruleID rule id |
|
99 | + */ |
|
100 | + public function deleteRule($ruleID) |
|
101 | + { |
|
102 | + if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id'); } |
|
103 | 103 | |
104 | - $dbConn = $this->getDbConn(); |
|
105 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
104 | + $dbConn = $this->getDbConn(); |
|
105 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
106 | 106 | |
107 | - $query=$dbConn->delete( |
|
108 | - $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
|
109 | - 'id='.$ruleID |
|
110 | - ); |
|
111 | - return $query; |
|
112 | - } |
|
107 | + $query=$dbConn->delete( |
|
108 | + $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
|
109 | + 'id='.$ruleID |
|
110 | + ); |
|
111 | + return $query; |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * Get last trap rule table modification |
|
116 | - * @throws \ErrorException |
|
117 | - * @return Zend_Db_Select |
|
118 | - */ |
|
119 | - public function lastModification() |
|
120 | - { |
|
121 | - $dbConn = $this->getDbConn(); |
|
122 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
114 | + /** |
|
115 | + * Get last trap rule table modification |
|
116 | + * @throws \ErrorException |
|
117 | + * @return Zend_Db_Select |
|
118 | + */ |
|
119 | + public function lastModification() |
|
120 | + { |
|
121 | + $dbConn = $this->getDbConn(); |
|
122 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
123 | 123 | |
124 | - $query = $dbConn->select() |
|
125 | - ->from( |
|
126 | - $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
|
127 | - array('lastModified'=>'UNIX_TIMESTAMP(MAX(modified))')); |
|
128 | - $returnRow=$dbConn->fetchRow($query); |
|
129 | - return $returnRow->lastmodified; |
|
130 | - } |
|
124 | + $query = $dbConn->select() |
|
125 | + ->from( |
|
126 | + $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
|
127 | + array('lastModified'=>'UNIX_TIMESTAMP(MAX(modified))')); |
|
128 | + $returnRow=$dbConn->fetchRow($query); |
|
129 | + return $returnRow->lastmodified; |
|
130 | + } |
|
131 | 131 | |
132 | - /** Delete trap by ip & oid |
|
133 | - * @param $ipAddr string source IP (v4 or v6) |
|
134 | - * @param $oid string oid |
|
135 | - */ |
|
136 | - public function deleteTrap($ipAddr,$oid) |
|
137 | - { |
|
132 | + /** Delete trap by ip & oid |
|
133 | + * @param $ipAddr string source IP (v4 or v6) |
|
134 | + * @param $oid string oid |
|
135 | + */ |
|
136 | + public function deleteTrap($ipAddr,$oid) |
|
137 | + { |
|
138 | 138 | |
139 | - $dbConn = $this->getDbConn(); |
|
140 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
141 | - $condition=null; |
|
142 | - if ($ipAddr != null) |
|
143 | - { |
|
144 | - $condition="source_ip='$ipAddr'"; |
|
145 | - } |
|
146 | - if ($oid != null) |
|
147 | - { |
|
148 | - $condition=($condition===null)?'':$condition.' AND '; |
|
149 | - $condition.="trap_oid='$oid'"; |
|
150 | - } |
|
151 | - if($condition === null) return null; |
|
152 | - $query=$dbConn->delete( |
|
153 | - $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(), |
|
154 | - $condition |
|
155 | - ); |
|
156 | - // TODO test ret code etc... |
|
157 | - return $query; |
|
158 | - } |
|
139 | + $dbConn = $this->getDbConn(); |
|
140 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
141 | + $condition=null; |
|
142 | + if ($ipAddr != null) |
|
143 | + { |
|
144 | + $condition="source_ip='$ipAddr'"; |
|
145 | + } |
|
146 | + if ($oid != null) |
|
147 | + { |
|
148 | + $condition=($condition===null)?'':$condition.' AND '; |
|
149 | + $condition.="trap_oid='$oid'"; |
|
150 | + } |
|
151 | + if($condition === null) return null; |
|
152 | + $query=$dbConn->delete( |
|
153 | + $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(), |
|
154 | + $condition |
|
155 | + ); |
|
156 | + // TODO test ret code etc... |
|
157 | + return $query; |
|
158 | + } |
|
159 | 159 | |
160 | 160 | |
161 | - /** count trap by ip & oid |
|
162 | - * @param $ipAddr string source IP (v4 or v6) |
|
163 | - * @param $oid string oid |
|
164 | - */ |
|
165 | - public function countTrap($ipAddr,$oid) |
|
166 | - { |
|
161 | + /** count trap by ip & oid |
|
162 | + * @param $ipAddr string source IP (v4 or v6) |
|
163 | + * @param $oid string oid |
|
164 | + */ |
|
165 | + public function countTrap($ipAddr,$oid) |
|
166 | + { |
|
167 | 167 | |
168 | - $dbConn = $this->getDbConn(); |
|
169 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
168 | + $dbConn = $this->getDbConn(); |
|
169 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
170 | 170 | |
171 | - $condition=null; |
|
172 | - if ($ipAddr != null) |
|
173 | - { |
|
174 | - $condition="source_ip='$ipAddr'"; |
|
175 | - } |
|
176 | - if ($oid != null) |
|
177 | - { |
|
178 | - $condition=($condition===null)?'':$condition.' AND '; |
|
179 | - $condition.="trap_oid='$oid'"; |
|
180 | - } |
|
181 | - if($condition === null) return 0; |
|
182 | - $query=$dbConn->select() |
|
183 | - ->from( |
|
184 | - $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(), |
|
185 | - array('num'=>'count(*)')) |
|
186 | - ->where($condition); |
|
187 | - $returnRow=$dbConn->fetchRow($query); |
|
188 | - return $returnRow->num; |
|
189 | - } |
|
171 | + $condition=null; |
|
172 | + if ($ipAddr != null) |
|
173 | + { |
|
174 | + $condition="source_ip='$ipAddr'"; |
|
175 | + } |
|
176 | + if ($oid != null) |
|
177 | + { |
|
178 | + $condition=($condition===null)?'':$condition.' AND '; |
|
179 | + $condition.="trap_oid='$oid'"; |
|
180 | + } |
|
181 | + if($condition === null) return 0; |
|
182 | + $query=$dbConn->select() |
|
183 | + ->from( |
|
184 | + $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(), |
|
185 | + array('num'=>'count(*)')) |
|
186 | + ->where($condition); |
|
187 | + $returnRow=$dbConn->fetchRow($query); |
|
188 | + return $returnRow->num; |
|
189 | + } |
|
190 | 190 | |
191 | - /** get configuration value |
|
192 | - * @param string $element : configuration name in db |
|
193 | - */ |
|
194 | - public function getDBConfigValue($element) |
|
195 | - { |
|
191 | + /** get configuration value |
|
192 | + * @param string $element : configuration name in db |
|
193 | + */ |
|
194 | + public function getDBConfigValue($element) |
|
195 | + { |
|
196 | 196 | |
197 | - $dbConn = $this->getDbConn(); |
|
198 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
197 | + $dbConn = $this->getDbConn(); |
|
198 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
199 | 199 | |
200 | - $query=$dbConn->select() |
|
201 | - ->from( |
|
202 | - $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(), |
|
203 | - array('value'=>'value')) |
|
204 | - ->where('name=?',$element); |
|
205 | - $returnRow=$dbConn->fetchRow($query); |
|
206 | - if ($returnRow==null) // value does not exists |
|
207 | - { |
|
208 | - $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults(); |
|
209 | - if ( ! isset($default[$element])) return null; // no default and not value |
|
200 | + $query=$dbConn->select() |
|
201 | + ->from( |
|
202 | + $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(), |
|
203 | + array('value'=>'value')) |
|
204 | + ->where('name=?',$element); |
|
205 | + $returnRow=$dbConn->fetchRow($query); |
|
206 | + if ($returnRow==null) // value does not exists |
|
207 | + { |
|
208 | + $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults(); |
|
209 | + if ( ! isset($default[$element])) return null; // no default and not value |
|
210 | 210 | |
211 | - $this->addDBConfigValue($element,$default[$element]); |
|
212 | - return $default[$element]; |
|
213 | - } |
|
214 | - if ($returnRow->value == null) // value id empty |
|
215 | - { |
|
216 | - $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults(); |
|
217 | - if ( ! isset($default[$element])) return null; // no default and not value |
|
218 | - $this->setDBConfigValue($element,$default[$element]); |
|
219 | - return $default[$element]; |
|
220 | - } |
|
221 | - return $returnRow->value; |
|
222 | - } |
|
211 | + $this->addDBConfigValue($element,$default[$element]); |
|
212 | + return $default[$element]; |
|
213 | + } |
|
214 | + if ($returnRow->value == null) // value id empty |
|
215 | + { |
|
216 | + $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults(); |
|
217 | + if ( ! isset($default[$element])) return null; // no default and not value |
|
218 | + $this->setDBConfigValue($element,$default[$element]); |
|
219 | + return $default[$element]; |
|
220 | + } |
|
221 | + return $returnRow->value; |
|
222 | + } |
|
223 | 223 | |
224 | - /** add configuration value |
|
225 | - * @param string $element : name of config element |
|
226 | - * @param string $value : value |
|
227 | - */ |
|
224 | + /** add configuration value |
|
225 | + * @param string $element : name of config element |
|
226 | + * @param string $value : value |
|
227 | + */ |
|
228 | 228 | |
229 | - public function addDBConfigValue($element,$value) |
|
230 | - { |
|
229 | + public function addDBConfigValue($element,$value) |
|
230 | + { |
|
231 | 231 | |
232 | - $dbConn = $this->getDbConn(); |
|
233 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
232 | + $dbConn = $this->getDbConn(); |
|
233 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
234 | 234 | |
235 | - $query=$dbConn->insert( |
|
236 | - $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(), |
|
237 | - array( |
|
238 | - 'name' => $element, |
|
239 | - 'value'=>$value |
|
240 | - ) |
|
241 | - ); |
|
242 | - return $query; |
|
243 | - } |
|
235 | + $query=$dbConn->insert( |
|
236 | + $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(), |
|
237 | + array( |
|
238 | + 'name' => $element, |
|
239 | + 'value'=>$value |
|
240 | + ) |
|
241 | + ); |
|
242 | + return $query; |
|
243 | + } |
|
244 | 244 | |
245 | - /** set configuration value |
|
246 | - * @param string $element : name of config element |
|
247 | - * @param string $value : value |
|
248 | - */ |
|
249 | - public function setDBConfigValue($element,$value) |
|
250 | - { |
|
245 | + /** set configuration value |
|
246 | + * @param string $element : name of config element |
|
247 | + * @param string $value : value |
|
248 | + */ |
|
249 | + public function setDBConfigValue($element,$value) |
|
250 | + { |
|
251 | 251 | |
252 | - $dbConn = $this->getDbConn(); |
|
253 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
252 | + $dbConn = $this->getDbConn(); |
|
253 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
254 | 254 | |
255 | - $query=$dbConn->update( |
|
256 | - $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(), |
|
257 | - array('value'=>$value), |
|
258 | - 'name=\''.$element.'\'' |
|
259 | - ); |
|
260 | - return $query; |
|
261 | - } |
|
255 | + $query=$dbConn->update( |
|
256 | + $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(), |
|
257 | + array('value'=>$value), |
|
258 | + 'name=\''.$element.'\'' |
|
259 | + ); |
|
260 | + return $query; |
|
261 | + } |
|
262 | 262 | |
263 | 263 | |
264 | 264 | } |
265 | 265 | \ No newline at end of file |
@@ -34,18 +34,18 @@ discard block |
||
34 | 34 | { |
35 | 35 | // TODO Check for rule consistency |
36 | 36 | |
37 | - $dbConn = $this->getDbConn(); |
|
37 | + $dbConn=$this->getDbConn(); |
|
38 | 38 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
39 | 39 | // Add last modified date = creation date and username |
40 | - $params['created'] = new Zend_Db_Expr('NOW()'); |
|
41 | - $params['modified'] = new Zend_Db_Expr('NOW()'); |
|
42 | - $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername(); |
|
40 | + $params['created']=new Zend_Db_Expr('NOW()'); |
|
41 | + $params['modified']=new Zend_Db_Expr('NOW()'); |
|
42 | + $params['modifier']=$this->getTrapCtrl()->Auth()->getUser()->getUsername(); |
|
43 | 43 | |
44 | 44 | $query=$dbConn->insert( |
45 | 45 | $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
46 | 46 | $params |
47 | 47 | ); |
48 | - if($query==false) |
|
48 | + if ($query == false) |
|
49 | 49 | { |
50 | 50 | return null; |
51 | 51 | } |
@@ -57,14 +57,14 @@ discard block |
||
57 | 57 | * @param integer $ruleID : rule id in db |
58 | 58 | * @return array affected rows |
59 | 59 | */ |
60 | - public function updateHandlerRule($params,$ruleID) |
|
60 | + public function updateHandlerRule($params, $ruleID) |
|
61 | 61 | { |
62 | 62 | // TODO Check for rule consistency |
63 | - $dbConn = $this->getDbConn(); |
|
63 | + $dbConn=$this->getDbConn(); |
|
64 | 64 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
65 | 65 | // Add last modified date = creation date and username |
66 | - $params['modified'] = new Zend_Db_Expr('NOW()'); |
|
67 | - $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername(); |
|
66 | + $params['modified']=new Zend_Db_Expr('NOW()'); |
|
67 | + $params['modifier']=$this->getTrapCtrl()->Auth()->getUser()->getUsername(); |
|
68 | 68 | |
69 | 69 | $numRows=$dbConn->update( |
70 | 70 | $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | public function updateHandlersOnCategoryDelete($catIndex) |
84 | 84 | { |
85 | 85 | // TODO Check for rule consistency |
86 | - $dbConn = $this->getDbConn(); |
|
86 | + $dbConn=$this->getDbConn(); |
|
87 | 87 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
88 | 88 | |
89 | 89 | $numRows=$dbConn->update( |
@@ -99,9 +99,9 @@ discard block |
||
99 | 99 | */ |
100 | 100 | public function deleteRule($ruleID) |
101 | 101 | { |
102 | - if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id'); } |
|
102 | + if (!preg_match('/^[0-9]+$/', $ruleID)) { throw new Exception('Invalid id'); } |
|
103 | 103 | |
104 | - $dbConn = $this->getDbConn(); |
|
104 | + $dbConn=$this->getDbConn(); |
|
105 | 105 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
106 | 106 | |
107 | 107 | $query=$dbConn->delete( |
@@ -118,10 +118,10 @@ discard block |
||
118 | 118 | */ |
119 | 119 | public function lastModification() |
120 | 120 | { |
121 | - $dbConn = $this->getDbConn(); |
|
121 | + $dbConn=$this->getDbConn(); |
|
122 | 122 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
123 | 123 | |
124 | - $query = $dbConn->select() |
|
124 | + $query=$dbConn->select() |
|
125 | 125 | ->from( |
126 | 126 | $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
127 | 127 | array('lastModified'=>'UNIX_TIMESTAMP(MAX(modified))')); |
@@ -133,10 +133,10 @@ discard block |
||
133 | 133 | * @param $ipAddr string source IP (v4 or v6) |
134 | 134 | * @param $oid string oid |
135 | 135 | */ |
136 | - public function deleteTrap($ipAddr,$oid) |
|
136 | + public function deleteTrap($ipAddr, $oid) |
|
137 | 137 | { |
138 | 138 | |
139 | - $dbConn = $this->getDbConn(); |
|
139 | + $dbConn=$this->getDbConn(); |
|
140 | 140 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
141 | 141 | $condition=null; |
142 | 142 | if ($ipAddr != null) |
@@ -145,10 +145,10 @@ discard block |
||
145 | 145 | } |
146 | 146 | if ($oid != null) |
147 | 147 | { |
148 | - $condition=($condition===null)?'':$condition.' AND '; |
|
148 | + $condition=($condition === null) ? '' : $condition.' AND '; |
|
149 | 149 | $condition.="trap_oid='$oid'"; |
150 | 150 | } |
151 | - if($condition === null) return null; |
|
151 | + if ($condition === null) return null; |
|
152 | 152 | $query=$dbConn->delete( |
153 | 153 | $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(), |
154 | 154 | $condition |
@@ -162,10 +162,10 @@ discard block |
||
162 | 162 | * @param $ipAddr string source IP (v4 or v6) |
163 | 163 | * @param $oid string oid |
164 | 164 | */ |
165 | - public function countTrap($ipAddr,$oid) |
|
165 | + public function countTrap($ipAddr, $oid) |
|
166 | 166 | { |
167 | 167 | |
168 | - $dbConn = $this->getDbConn(); |
|
168 | + $dbConn=$this->getDbConn(); |
|
169 | 169 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
170 | 170 | |
171 | 171 | $condition=null; |
@@ -175,10 +175,10 @@ discard block |
||
175 | 175 | } |
176 | 176 | if ($oid != null) |
177 | 177 | { |
178 | - $condition=($condition===null)?'':$condition.' AND '; |
|
178 | + $condition=($condition === null) ? '' : $condition.' AND '; |
|
179 | 179 | $condition.="trap_oid='$oid'"; |
180 | 180 | } |
181 | - if($condition === null) return 0; |
|
181 | + if ($condition === null) return 0; |
|
182 | 182 | $query=$dbConn->select() |
183 | 183 | ->from( |
184 | 184 | $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(), |
@@ -194,28 +194,28 @@ discard block |
||
194 | 194 | public function getDBConfigValue($element) |
195 | 195 | { |
196 | 196 | |
197 | - $dbConn = $this->getDbConn(); |
|
197 | + $dbConn=$this->getDbConn(); |
|
198 | 198 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
199 | 199 | |
200 | 200 | $query=$dbConn->select() |
201 | 201 | ->from( |
202 | 202 | $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(), |
203 | 203 | array('value'=>'value')) |
204 | - ->where('name=?',$element); |
|
204 | + ->where('name=?', $element); |
|
205 | 205 | $returnRow=$dbConn->fetchRow($query); |
206 | - if ($returnRow==null) // value does not exists |
|
206 | + if ($returnRow == null) // value does not exists |
|
207 | 207 | { |
208 | 208 | $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults(); |
209 | - if ( ! isset($default[$element])) return null; // no default and not value |
|
209 | + if (!isset($default[$element])) return null; // no default and not value |
|
210 | 210 | |
211 | - $this->addDBConfigValue($element,$default[$element]); |
|
211 | + $this->addDBConfigValue($element, $default[$element]); |
|
212 | 212 | return $default[$element]; |
213 | 213 | } |
214 | 214 | if ($returnRow->value == null) // value id empty |
215 | 215 | { |
216 | 216 | $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults(); |
217 | - if ( ! isset($default[$element])) return null; // no default and not value |
|
218 | - $this->setDBConfigValue($element,$default[$element]); |
|
217 | + if (!isset($default[$element])) return null; // no default and not value |
|
218 | + $this->setDBConfigValue($element, $default[$element]); |
|
219 | 219 | return $default[$element]; |
220 | 220 | } |
221 | 221 | return $returnRow->value; |
@@ -226,10 +226,10 @@ discard block |
||
226 | 226 | * @param string $value : value |
227 | 227 | */ |
228 | 228 | |
229 | - public function addDBConfigValue($element,$value) |
|
229 | + public function addDBConfigValue($element, $value) |
|
230 | 230 | { |
231 | 231 | |
232 | - $dbConn = $this->getDbConn(); |
|
232 | + $dbConn=$this->getDbConn(); |
|
233 | 233 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
234 | 234 | |
235 | 235 | $query=$dbConn->insert( |
@@ -246,10 +246,10 @@ discard block |
||
246 | 246 | * @param string $element : name of config element |
247 | 247 | * @param string $value : value |
248 | 248 | */ |
249 | - public function setDBConfigValue($element,$value) |
|
249 | + public function setDBConfigValue($element, $value) |
|
250 | 250 | { |
251 | 251 | |
252 | - $dbConn = $this->getDbConn(); |
|
252 | + $dbConn=$this->getDbConn(); |
|
253 | 253 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
254 | 254 | |
255 | 255 | $query=$dbConn->update( |
@@ -35,7 +35,9 @@ discard block |
||
35 | 35 | // TODO Check for rule consistency |
36 | 36 | |
37 | 37 | $dbConn = $this->getDbConn(); |
38 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
38 | + if ($dbConn === null) { |
|
39 | + throw new \ErrorException('uncatched db error'); |
|
40 | + } |
|
39 | 41 | // Add last modified date = creation date and username |
40 | 42 | $params['created'] = new Zend_Db_Expr('NOW()'); |
41 | 43 | $params['modified'] = new Zend_Db_Expr('NOW()'); |
@@ -61,7 +63,9 @@ discard block |
||
61 | 63 | { |
62 | 64 | // TODO Check for rule consistency |
63 | 65 | $dbConn = $this->getDbConn(); |
64 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
66 | + if ($dbConn === null) { |
|
67 | + throw new \ErrorException('uncatched db error'); |
|
68 | + } |
|
65 | 69 | // Add last modified date = creation date and username |
66 | 70 | $params['modified'] = new Zend_Db_Expr('NOW()'); |
67 | 71 | $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername(); |
@@ -84,7 +88,9 @@ discard block |
||
84 | 88 | { |
85 | 89 | // TODO Check for rule consistency |
86 | 90 | $dbConn = $this->getDbConn(); |
87 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
91 | + if ($dbConn === null) { |
|
92 | + throw new \ErrorException('uncatched db error'); |
|
93 | + } |
|
88 | 94 | |
89 | 95 | $numRows=$dbConn->update( |
90 | 96 | $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
@@ -102,7 +108,9 @@ discard block |
||
102 | 108 | if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id'); } |
103 | 109 | |
104 | 110 | $dbConn = $this->getDbConn(); |
105 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
111 | + if ($dbConn === null) { |
|
112 | + throw new \ErrorException('uncatched db error'); |
|
113 | + } |
|
106 | 114 | |
107 | 115 | $query=$dbConn->delete( |
108 | 116 | $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
@@ -119,7 +127,9 @@ discard block |
||
119 | 127 | public function lastModification() |
120 | 128 | { |
121 | 129 | $dbConn = $this->getDbConn(); |
122 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
130 | + if ($dbConn === null) { |
|
131 | + throw new \ErrorException('uncatched db error'); |
|
132 | + } |
|
123 | 133 | |
124 | 134 | $query = $dbConn->select() |
125 | 135 | ->from( |
@@ -137,7 +147,9 @@ discard block |
||
137 | 147 | { |
138 | 148 | |
139 | 149 | $dbConn = $this->getDbConn(); |
140 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
150 | + if ($dbConn === null) { |
|
151 | + throw new \ErrorException('uncatched db error'); |
|
152 | + } |
|
141 | 153 | $condition=null; |
142 | 154 | if ($ipAddr != null) |
143 | 155 | { |
@@ -148,7 +160,9 @@ discard block |
||
148 | 160 | $condition=($condition===null)?'':$condition.' AND '; |
149 | 161 | $condition.="trap_oid='$oid'"; |
150 | 162 | } |
151 | - if($condition === null) return null; |
|
163 | + if($condition === null) { |
|
164 | + return null; |
|
165 | + } |
|
152 | 166 | $query=$dbConn->delete( |
153 | 167 | $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(), |
154 | 168 | $condition |
@@ -166,7 +180,9 @@ discard block |
||
166 | 180 | { |
167 | 181 | |
168 | 182 | $dbConn = $this->getDbConn(); |
169 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
183 | + if ($dbConn === null) { |
|
184 | + throw new \ErrorException('uncatched db error'); |
|
185 | + } |
|
170 | 186 | |
171 | 187 | $condition=null; |
172 | 188 | if ($ipAddr != null) |
@@ -178,7 +194,9 @@ discard block |
||
178 | 194 | $condition=($condition===null)?'':$condition.' AND '; |
179 | 195 | $condition.="trap_oid='$oid'"; |
180 | 196 | } |
181 | - if($condition === null) return 0; |
|
197 | + if($condition === null) { |
|
198 | + return 0; |
|
199 | + } |
|
182 | 200 | $query=$dbConn->select() |
183 | 201 | ->from( |
184 | 202 | $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(), |
@@ -195,7 +213,9 @@ discard block |
||
195 | 213 | { |
196 | 214 | |
197 | 215 | $dbConn = $this->getDbConn(); |
198 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
216 | + if ($dbConn === null) { |
|
217 | + throw new \ErrorException('uncatched db error'); |
|
218 | + } |
|
199 | 219 | |
200 | 220 | $query=$dbConn->select() |
201 | 221 | ->from( |
@@ -203,18 +223,28 @@ discard block |
||
203 | 223 | array('value'=>'value')) |
204 | 224 | ->where('name=?',$element); |
205 | 225 | $returnRow=$dbConn->fetchRow($query); |
206 | - if ($returnRow==null) // value does not exists |
|
226 | + if ($returnRow==null) { |
|
227 | + // value does not exists |
|
207 | 228 | { |
208 | 229 | $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults(); |
209 | - if ( ! isset($default[$element])) return null; // no default and not value |
|
230 | + } |
|
231 | + if ( ! isset($default[$element])) { |
|
232 | + return null; |
|
233 | + } |
|
234 | + // no default and not value |
|
210 | 235 | |
211 | 236 | $this->addDBConfigValue($element,$default[$element]); |
212 | 237 | return $default[$element]; |
213 | 238 | } |
214 | - if ($returnRow->value == null) // value id empty |
|
239 | + if ($returnRow->value == null) { |
|
240 | + // value id empty |
|
215 | 241 | { |
216 | 242 | $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults(); |
217 | - if ( ! isset($default[$element])) return null; // no default and not value |
|
243 | + } |
|
244 | + if ( ! isset($default[$element])) { |
|
245 | + return null; |
|
246 | + } |
|
247 | + // no default and not value |
|
218 | 248 | $this->setDBConfigValue($element,$default[$element]); |
219 | 249 | return $default[$element]; |
220 | 250 | } |
@@ -230,7 +260,9 @@ discard block |
||
230 | 260 | { |
231 | 261 | |
232 | 262 | $dbConn = $this->getDbConn(); |
233 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
263 | + if ($dbConn === null) { |
|
264 | + throw new \ErrorException('uncatched db error'); |
|
265 | + } |
|
234 | 266 | |
235 | 267 | $query=$dbConn->insert( |
236 | 268 | $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(), |
@@ -250,7 +282,9 @@ discard block |
||
250 | 282 | { |
251 | 283 | |
252 | 284 | $dbConn = $this->getDbConn(); |
253 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
285 | + if ($dbConn === null) { |
|
286 | + throw new \ErrorException('uncatched db error'); |
|
287 | + } |
|
254 | 288 | |
255 | 289 | $query=$dbConn->update( |
256 | 290 | $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(), |
@@ -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(*)') |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | |
52 | 52 | try |
53 | 53 | { |
54 | - $this->view->currentLogDestination=$this->getUIDatabase()->getDBConfigValue('log_destination'); |
|
54 | + $this->view->currentLogDestination=$this->getUIDatabase()->getDBConfigValue('log_destination'); |
|
55 | 55 | $this->view->logDestinations=$this->getModuleConfig()->getLogDestinations(); |
56 | 56 | $this->view->currentLogFile=$this->getUIDatabase()->getDBConfigValue('log_file'); |
57 | 57 | $this->view->logLevels=$this->getModuleConfig()->getlogLevels(); |
@@ -65,23 +65,23 @@ discard block |
||
65 | 65 | /*************** SNMP configuration ****************/ |
66 | 66 | try |
67 | 67 | { |
68 | - $this->view->useSnmpTrapAddess= ( $this->getUIDatabase()->getDBConfigValue('use_SnmpTrapAddess') == 1 ) ? TRUE : FALSE; |
|
69 | - $this->view->SnmpTrapAddressOID=$this->getUIDatabase()->getDBConfigValue('SnmpTrapAddess_oid'); |
|
70 | - $this->view->SnmpTrapAddressOIDDefault = ($this->view->SnmpTrapAddressOID == $this->getModuleConfig()->getDBConfigDefaults()['SnmpTrapAddess_oid'] ) ? TRUE : FALSE; |
|
68 | + $this->view->useSnmpTrapAddess= ( $this->getUIDatabase()->getDBConfigValue('use_SnmpTrapAddess') == 1 ) ? TRUE : FALSE; |
|
69 | + $this->view->SnmpTrapAddressOID=$this->getUIDatabase()->getDBConfigValue('SnmpTrapAddess_oid'); |
|
70 | + $this->view->SnmpTrapAddressOIDDefault = ($this->view->SnmpTrapAddressOID == $this->getModuleConfig()->getDBConfigDefaults()['SnmpTrapAddess_oid'] ) ? TRUE : FALSE; |
|
71 | 71 | |
72 | 72 | } |
73 | 73 | catch (Exception $e) |
74 | 74 | { |
75 | - $this->displayExitError('status',$e->getMessage()); |
|
75 | + $this->displayExitError('status',$e->getMessage()); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | } |
79 | 79 | |
80 | 80 | /** Mib management |
81 | - * Post param : action=update_mib_db : update mib database |
|
82 | - * Post param : ation=check_update : check if mib update is finished |
|
83 | - * File post : mibfile -> save mib file |
|
84 | - */ |
|
81 | + * Post param : action=update_mib_db : update mib database |
|
82 | + * Post param : ation=check_update : check if mib update is finished |
|
83 | + * File post : mibfile -> save mib file |
|
84 | + */ |
|
85 | 85 | public function mibAction() |
86 | 86 | { |
87 | 87 | $this->prepareTabs()->activate('mib'); |
@@ -100,22 +100,22 @@ discard block |
||
100 | 100 | $return=exec('icingacli trapdirector mib update --pid /tmp/trapdirector_update.pid'); |
101 | 101 | if (preg_match('/OK/',$return)) |
102 | 102 | { |
103 | - $this->_helper->json(array('status'=>'OK')); |
|
103 | + $this->_helper->json(array('status'=>'OK')); |
|
104 | 104 | } |
105 | 105 | // Error |
106 | 106 | $this->_helper->json(array('status'=>$return)); |
107 | 107 | } |
108 | 108 | if ($action == 'check_update') |
109 | 109 | { |
110 | - $file=@fopen('/tmp/trapdirector_update.pid','r'); |
|
111 | - if ($file == false) |
|
112 | - { // process is dead |
|
113 | - $this->_helper->json(array('status'=>'tu quoque fili','err'=>'Cannot open file')); |
|
114 | - return; |
|
115 | - } |
|
116 | - $pid=fgets($file); |
|
117 | - $output=array(); |
|
118 | - $retVal=0; |
|
110 | + $file=@fopen('/tmp/trapdirector_update.pid','r'); |
|
111 | + if ($file == false) |
|
112 | + { // process is dead |
|
113 | + $this->_helper->json(array('status'=>'tu quoque fili','err'=>'Cannot open file')); |
|
114 | + return; |
|
115 | + } |
|
116 | + $pid=fgets($file); |
|
117 | + $output=array(); |
|
118 | + $retVal=0; |
|
119 | 119 | exec('ps '.$pid,$output,$retVal); |
120 | 120 | if ($retVal == 0) |
121 | 121 | { // process is alive |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | } |
124 | 124 | else |
125 | 125 | { // process is dead |
126 | - $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid)); |
|
126 | + $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid)); |
|
127 | 127 | } |
128 | 128 | } |
129 | 129 | $this->_helper->json(array('status'=>'ERR : no '.$action.' action possible' )); |
@@ -131,32 +131,32 @@ discard block |
||
131 | 131 | /** Check for mib file UPLOAD */ |
132 | 132 | if (isset($_FILES['mibfile'])) |
133 | 133 | { |
134 | - $name=filter_var($_FILES['mibfile']['name'],FILTER_SANITIZE_STRING); |
|
134 | + $name=filter_var($_FILES['mibfile']['name'],FILTER_SANITIZE_STRING); |
|
135 | 135 | $DirConf=explode(':',$this->Config()->get('config', 'snmptranslate_dirs')); |
136 | 136 | $destDir=array_shift($DirConf); |
137 | 137 | if (!is_dir($destDir)) |
138 | 138 | { |
139 | - $this->view->uploadStatus="ERROR : no $destDir directory, check module configuration"; |
|
139 | + $this->view->uploadStatus="ERROR : no $destDir directory, check module configuration"; |
|
140 | 140 | } |
141 | 141 | else |
142 | 142 | { |
143 | - if (!is_writable($destDir)) |
|
144 | - { |
|
145 | - $this->view->uploadStatus="ERROR : $destDir directory is not writable"; |
|
146 | - } |
|
147 | - else |
|
148 | - { |
|
149 | - $destination = $destDir .'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name"; |
|
150 | - $sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'],FILTER_SANITIZE_STRING); |
|
151 | - if (move_uploaded_file($sourceTmpNam,$destination)===false) |
|
152 | - { |
|
153 | - $this->view->uploadStatus="ERROR, file $destination not loaded. Check file and path name or selinux violations"; |
|
154 | - } |
|
155 | - else |
|
156 | - { |
|
157 | - $this->view->uploadStatus="File $name uploaded in $destDir"; |
|
158 | - } |
|
159 | - } |
|
143 | + if (!is_writable($destDir)) |
|
144 | + { |
|
145 | + $this->view->uploadStatus="ERROR : $destDir directory is not writable"; |
|
146 | + } |
|
147 | + else |
|
148 | + { |
|
149 | + $destination = $destDir .'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name"; |
|
150 | + $sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'],FILTER_SANITIZE_STRING); |
|
151 | + if (move_uploaded_file($sourceTmpNam,$destination)===false) |
|
152 | + { |
|
153 | + $this->view->uploadStatus="ERROR, file $destination not loaded. Check file and path name or selinux violations"; |
|
154 | + } |
|
155 | + else |
|
156 | + { |
|
157 | + $this->view->uploadStatus="File $name uploaded in $destDir"; |
|
158 | + } |
|
159 | + } |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | } |
@@ -236,63 +236,63 @@ discard block |
||
236 | 236 | /** UI options */ |
237 | 237 | public function uimgtAction() |
238 | 238 | { |
239 | - $this->prepareTabs()->activate('uimgt'); |
|
239 | + $this->prepareTabs()->activate('uimgt'); |
|
240 | 240 | |
241 | - $this->view->setError=''; |
|
242 | - $this->view->setOKMsg=''; |
|
241 | + $this->view->setError=''; |
|
242 | + $this->view->setOKMsg=''; |
|
243 | 243 | |
244 | - //max_rows=25&row_update=update |
|
245 | - if ( $this->getRequest()->getParam('max_rows',NULL) !== NULL ) |
|
246 | - { |
|
247 | - $maxRows = $this->getRequest()->getParam('max_rows'); |
|
248 | - if (!preg_match('/^[0-9]+$/', $maxRows) || $maxRows < 1) |
|
249 | - { |
|
250 | - $this->view->setError='Max rows must be a number'; |
|
251 | - } |
|
252 | - else |
|
253 | - { |
|
254 | - $this->setitemListDisplay($maxRows); |
|
255 | - $this->view->setOKMsg='Set max rows to ' . $maxRows; |
|
256 | - } |
|
257 | - } |
|
244 | + //max_rows=25&row_update=update |
|
245 | + if ( $this->getRequest()->getParam('max_rows',NULL) !== NULL ) |
|
246 | + { |
|
247 | + $maxRows = $this->getRequest()->getParam('max_rows'); |
|
248 | + if (!preg_match('/^[0-9]+$/', $maxRows) || $maxRows < 1) |
|
249 | + { |
|
250 | + $this->view->setError='Max rows must be a number'; |
|
251 | + } |
|
252 | + else |
|
253 | + { |
|
254 | + $this->setitemListDisplay($maxRows); |
|
255 | + $this->view->setOKMsg='Set max rows to ' . $maxRows; |
|
256 | + } |
|
257 | + } |
|
258 | 258 | |
259 | - if ( $this->getRequest()->getParam('add_category',NULL) !== NULL ) |
|
260 | - { |
|
261 | - $addCat = $this->getRequest()->getParam('add_category'); |
|
262 | - $this->addHandlersCategory($addCat); |
|
263 | - } |
|
259 | + if ( $this->getRequest()->getParam('add_category',NULL) !== NULL ) |
|
260 | + { |
|
261 | + $addCat = $this->getRequest()->getParam('add_category'); |
|
262 | + $this->addHandlersCategory($addCat); |
|
263 | + } |
|
264 | 264 | |
265 | - if ( $this->getRequest()->getPost('type',NULL) !== NULL ) |
|
266 | - { |
|
267 | - $type = $this->getRequest()->getPost('type',NULL); |
|
268 | - $index = $this->getRequest()->getPost('index',NULL); |
|
269 | - $newname = $this->getRequest()->getPost('newname',NULL); |
|
265 | + if ( $this->getRequest()->getPost('type',NULL) !== NULL ) |
|
266 | + { |
|
267 | + $type = $this->getRequest()->getPost('type',NULL); |
|
268 | + $index = $this->getRequest()->getPost('index',NULL); |
|
269 | + $newname = $this->getRequest()->getPost('newname',NULL); |
|
270 | 270 | |
271 | - if (!preg_match('/^[0-9]+$/', $index) || $index < 1) |
|
272 | - $this->_helper->json(array('status'=>'Bad index')); |
|
271 | + if (!preg_match('/^[0-9]+$/', $index) || $index < 1) |
|
272 | + $this->_helper->json(array('status'=>'Bad index')); |
|
273 | 273 | |
274 | - switch ($type) |
|
275 | - { |
|
276 | - case 'delete': |
|
277 | - $this->delHandlersCategory($index); |
|
278 | - $this->_helper->json(array('status'=>'OK')); |
|
279 | - return; |
|
280 | - break; |
|
281 | - case 'rename': |
|
282 | - $this->renameHandlersCategory($index, $newname); |
|
283 | - $this->_helper->json(array('status'=>'OK')); |
|
284 | - return; |
|
285 | - break; |
|
286 | - default: |
|
287 | - $this->_helper->json(array('status'=>'Unknwon command')); |
|
288 | - return; |
|
289 | - break; |
|
290 | - } |
|
291 | - } |
|
274 | + switch ($type) |
|
275 | + { |
|
276 | + case 'delete': |
|
277 | + $this->delHandlersCategory($index); |
|
278 | + $this->_helper->json(array('status'=>'OK')); |
|
279 | + return; |
|
280 | + break; |
|
281 | + case 'rename': |
|
282 | + $this->renameHandlersCategory($index, $newname); |
|
283 | + $this->_helper->json(array('status'=>'OK')); |
|
284 | + return; |
|
285 | + break; |
|
286 | + default: |
|
287 | + $this->_helper->json(array('status'=>'Unknwon command')); |
|
288 | + return; |
|
289 | + break; |
|
290 | + } |
|
291 | + } |
|
292 | 292 | |
293 | - $this->view->maxRows = $this->itemListDisplay(); |
|
293 | + $this->view->maxRows = $this->itemListDisplay(); |
|
294 | 294 | |
295 | - $this->view->categories = $this->getHandlersCategory(); |
|
295 | + $this->view->categories = $this->getHandlersCategory(); |
|
296 | 296 | |
297 | 297 | |
298 | 298 | |
@@ -341,47 +341,47 @@ discard block |
||
341 | 341 | */ |
342 | 342 | public function pluginsAction() |
343 | 343 | { |
344 | - $this->prepareTabs()->activate('plugins'); |
|
344 | + $this->prepareTabs()->activate('plugins'); |
|
345 | 345 | |
346 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
347 | - $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
348 | - $Trap = new Trap($icingaweb2_etc,4); |
|
346 | + require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
347 | + $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
348 | + $Trap = new Trap($icingaweb2_etc,4); |
|
349 | 349 | |
350 | - $this->view->pluginLoaded = htmlentities($Trap->pluginClass->registerAllPlugins(false)); |
|
350 | + $this->view->pluginLoaded = htmlentities($Trap->pluginClass->registerAllPlugins(false)); |
|
351 | 351 | |
352 | - $enabledPlugins = $Trap->pluginClass->getEnabledPlugins(); |
|
352 | + $enabledPlugins = $Trap->pluginClass->getEnabledPlugins(); |
|
353 | 353 | |
354 | - $pluginList = $Trap->pluginClass->pluginList(); |
|
354 | + $pluginList = $Trap->pluginClass->pluginList(); |
|
355 | 355 | |
356 | - // Plugin list and fill function name list |
|
357 | - $functionList=array(); |
|
358 | - $this->view->pluginArray=array(); |
|
359 | - foreach ($pluginList as $plugin) |
|
360 | - { |
|
361 | - $pluginDetails=$Trap->pluginClass->pluginDetails($plugin); |
|
362 | - $pluginDetails->enabled = (in_array($plugin, $enabledPlugins)) ? true : false; |
|
363 | - $pluginDetails->catchAllTraps = ($pluginDetails->catchAllTraps === true )? 'Yes' : 'No'; |
|
364 | - $pluginDetails->processTraps = ($pluginDetails->processTraps === true )? 'Yes' : 'No'; |
|
365 | - $pluginDetails->description = htmlentities($pluginDetails->description); |
|
366 | - $pluginDetails->description = preg_replace('/\n/','<br>',$pluginDetails->description); |
|
367 | - array_push($this->view->pluginArray, $pluginDetails); |
|
368 | - // Get functions for function details |
|
369 | - foreach ($pluginDetails->funcArray as $function) |
|
370 | - { |
|
371 | - array_push($functionList,$function); |
|
372 | - } |
|
373 | - } |
|
356 | + // Plugin list and fill function name list |
|
357 | + $functionList=array(); |
|
358 | + $this->view->pluginArray=array(); |
|
359 | + foreach ($pluginList as $plugin) |
|
360 | + { |
|
361 | + $pluginDetails=$Trap->pluginClass->pluginDetails($plugin); |
|
362 | + $pluginDetails->enabled = (in_array($plugin, $enabledPlugins)) ? true : false; |
|
363 | + $pluginDetails->catchAllTraps = ($pluginDetails->catchAllTraps === true )? 'Yes' : 'No'; |
|
364 | + $pluginDetails->processTraps = ($pluginDetails->processTraps === true )? 'Yes' : 'No'; |
|
365 | + $pluginDetails->description = htmlentities($pluginDetails->description); |
|
366 | + $pluginDetails->description = preg_replace('/\n/','<br>',$pluginDetails->description); |
|
367 | + array_push($this->view->pluginArray, $pluginDetails); |
|
368 | + // Get functions for function details |
|
369 | + foreach ($pluginDetails->funcArray as $function) |
|
370 | + { |
|
371 | + array_push($functionList,$function); |
|
372 | + } |
|
373 | + } |
|
374 | 374 | |
375 | - // Function list with details |
|
376 | - $this->view->functionList=array(); |
|
377 | - foreach ($functionList as $function) |
|
378 | - { |
|
379 | - $functionDetail = $Trap->pluginClass->getFunctionDetails($function); |
|
380 | - $functionDetail->params = htmlentities($functionDetail->params); |
|
381 | - $functionDetail->description = htmlentities($functionDetail->description); |
|
382 | - $functionDetail->description = preg_replace('/\n/','<br>',$functionDetail->description); |
|
383 | - array_push($this->view->functionList, $functionDetail); |
|
384 | - } |
|
375 | + // Function list with details |
|
376 | + $this->view->functionList=array(); |
|
377 | + foreach ($functionList as $function) |
|
378 | + { |
|
379 | + $functionDetail = $Trap->pluginClass->getFunctionDetails($function); |
|
380 | + $functionDetail->params = htmlentities($functionDetail->params); |
|
381 | + $functionDetail->description = htmlentities($functionDetail->description); |
|
382 | + $functionDetail->description = preg_replace('/\n/','<br>',$functionDetail->description); |
|
383 | + array_push($this->view->functionList, $functionDetail); |
|
384 | + } |
|
385 | 385 | |
386 | 386 | } |
387 | 387 | |
@@ -393,36 +393,36 @@ discard block |
||
393 | 393 | )->add('mib', array( |
394 | 394 | 'label' => $this->translate('MIB Management'), |
395 | 395 | 'url' => $this->getModuleConfig()->urlPath() . '/status/mib') |
396 | - )->add('uimgt', array( |
|
397 | - 'label' => $this->translate('UI Configuration'), |
|
398 | - 'url' => $this->getModuleConfig()->urlPath() . '/status/uimgt') |
|
399 | - )->add('services', array( |
|
396 | + )->add('uimgt', array( |
|
397 | + 'label' => $this->translate('UI Configuration'), |
|
398 | + 'url' => $this->getModuleConfig()->urlPath() . '/status/uimgt') |
|
399 | + )->add('services', array( |
|
400 | 400 | 'label' => $this->translate('Services management'), |
401 | 401 | 'url' => $this->getModuleConfig()->urlPath() . '/status/services') |
402 | - )->add('plugins', array( |
|
403 | - 'label' => $this->translate('Plugins management'), |
|
404 | - 'url' => $this->getModuleConfig()->urlPath() . '/status/plugins') |
|
405 | - ); |
|
402 | + )->add('plugins', array( |
|
403 | + 'label' => $this->translate('Plugins management'), |
|
404 | + 'url' => $this->getModuleConfig()->urlPath() . '/status/plugins') |
|
405 | + ); |
|
406 | 406 | } |
407 | 407 | } |
408 | 408 | |
409 | 409 | // TODO : see if useless |
410 | 410 | class UploadForm extends Form |
411 | 411 | { |
412 | - public function __construct($options = null) |
|
413 | - { |
|
414 | - parent::__construct($options); |
|
415 | - $this->addElements2(); |
|
416 | - } |
|
412 | + public function __construct($options = null) |
|
413 | + { |
|
414 | + parent::__construct($options); |
|
415 | + $this->addElements2(); |
|
416 | + } |
|
417 | 417 | |
418 | - public function addElements2() |
|
419 | - { |
|
420 | - // File Input |
|
421 | - $file = new File('mib-file'); |
|
422 | - $file->setLabel('Mib upload'); |
|
423 | - //->setAttrib('multiple', null); |
|
424 | - $this->addElement($file); |
|
418 | + public function addElements2() |
|
419 | + { |
|
420 | + // File Input |
|
421 | + $file = new File('mib-file'); |
|
422 | + $file->setLabel('Mib upload'); |
|
423 | + //->setAttrib('multiple', null); |
|
424 | + $this->addElement($file); |
|
425 | 425 | $button = new Submit("upload",array('ignore'=>false)); |
426 | 426 | $this->addElement($button);//->setIgnore(false); |
427 | - } |
|
427 | + } |
|
428 | 428 | } |
@@ -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,20 +59,20 @@ 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 | /*************** SNMP configuration ****************/ |
66 | 66 | try |
67 | 67 | { |
68 | - $this->view->useSnmpTrapAddess= ( $this->getUIDatabase()->getDBConfigValue('use_SnmpTrapAddess') == 1 ) ? TRUE : FALSE; |
|
68 | + $this->view->useSnmpTrapAddess=($this->getUIDatabase()->getDBConfigValue('use_SnmpTrapAddess') == 1) ? TRUE : FALSE; |
|
69 | 69 | $this->view->SnmpTrapAddressOID=$this->getUIDatabase()->getDBConfigValue('SnmpTrapAddess_oid'); |
70 | - $this->view->SnmpTrapAddressOIDDefault = ($this->view->SnmpTrapAddressOID == $this->getModuleConfig()->getDBConfigDefaults()['SnmpTrapAddess_oid'] ) ? TRUE : FALSE; |
|
70 | + $this->view->SnmpTrapAddressOIDDefault=($this->view->SnmpTrapAddressOID == $this->getModuleConfig()->getDBConfigDefaults()['SnmpTrapAddess_oid']) ? TRUE : FALSE; |
|
71 | 71 | |
72 | 72 | } |
73 | 73 | catch (Exception $e) |
74 | 74 | { |
75 | - $this->displayExitError('status',$e->getMessage()); |
|
75 | + $this->displayExitError('status', $e->getMessage()); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | } |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | if ($action == 'update_mib_db') |
99 | 99 | { // Do the update in background |
100 | 100 | $return=exec('icingacli trapdirector mib update --pid /tmp/trapdirector_update.pid'); |
101 | - if (preg_match('/OK/',$return)) |
|
101 | + if (preg_match('/OK/', $return)) |
|
102 | 102 | { |
103 | 103 | $this->_helper->json(array('status'=>'OK')); |
104 | 104 | } |
@@ -107,32 +107,32 @@ discard block |
||
107 | 107 | } |
108 | 108 | if ($action == 'check_update') |
109 | 109 | { |
110 | - $file=@fopen('/tmp/trapdirector_update.pid','r'); |
|
110 | + $file=@fopen('/tmp/trapdirector_update.pid', 'r'); |
|
111 | 111 | if ($file == false) |
112 | 112 | { // process is dead |
113 | - $this->_helper->json(array('status'=>'tu quoque fili','err'=>'Cannot open file')); |
|
113 | + $this->_helper->json(array('status'=>'tu quoque fili', 'err'=>'Cannot open file')); |
|
114 | 114 | return; |
115 | 115 | } |
116 | 116 | $pid=fgets($file); |
117 | 117 | $output=array(); |
118 | 118 | $retVal=0; |
119 | - exec('ps '.$pid,$output,$retVal); |
|
119 | + exec('ps '.$pid, $output, $retVal); |
|
120 | 120 | if ($retVal == 0) |
121 | 121 | { // process is alive |
122 | 122 | $this->_helper->json(array('status'=>'Alive and kicking')); |
123 | 123 | } |
124 | 124 | else |
125 | 125 | { // process is dead |
126 | - $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid)); |
|
126 | + $this->_helper->json(array('status'=>'tu quoque fili', 'err'=>'no proc'.$pid)); |
|
127 | 127 | } |
128 | 128 | } |
129 | - $this->_helper->json(array('status'=>'ERR : no '.$action.' action possible' )); |
|
129 | + $this->_helper->json(array('status'=>'ERR : no '.$action.' action possible')); |
|
130 | 130 | } |
131 | 131 | /** Check for mib file UPLOAD */ |
132 | 132 | if (isset($_FILES['mibfile'])) |
133 | 133 | { |
134 | - $name=filter_var($_FILES['mibfile']['name'],FILTER_SANITIZE_STRING); |
|
135 | - $DirConf=explode(':',$this->Config()->get('config', 'snmptranslate_dirs')); |
|
134 | + $name=filter_var($_FILES['mibfile']['name'], FILTER_SANITIZE_STRING); |
|
135 | + $DirConf=explode(':', $this->Config()->get('config', 'snmptranslate_dirs')); |
|
136 | 136 | $destDir=array_shift($DirConf); |
137 | 137 | if (!is_dir($destDir)) |
138 | 138 | { |
@@ -146,9 +146,9 @@ discard block |
||
146 | 146 | } |
147 | 147 | else |
148 | 148 | { |
149 | - $destination = $destDir .'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name"; |
|
150 | - $sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'],FILTER_SANITIZE_STRING); |
|
151 | - if (move_uploaded_file($sourceTmpNam,$destination)===false) |
|
149 | + $destination=$destDir.'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name"; |
|
150 | + $sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'], FILTER_SANITIZE_STRING); |
|
151 | + if (move_uploaded_file($sourceTmpNam, $destination) === false) |
|
152 | 152 | { |
153 | 153 | $this->view->uploadStatus="ERROR, file $destination not loaded. Check file and path name or selinux violations"; |
154 | 154 | } |
@@ -164,13 +164,13 @@ discard block |
||
164 | 164 | } |
165 | 165 | |
166 | 166 | // snmptranslate tests |
167 | - $snmptranslate = $this->Config()->get('config', 'snmptranslate'); |
|
167 | + $snmptranslate=$this->Config()->get('config', 'snmptranslate'); |
|
168 | 168 | $this->view->snmptranslate_bin=$snmptranslate; |
169 | 169 | $this->view->snmptranslate_state='warn'; |
170 | - if (is_executable ( $snmptranslate )) |
|
170 | + if (is_executable($snmptranslate)) |
|
171 | 171 | { |
172 | - $translate=exec($snmptranslate . ' 1'); |
|
173 | - if (preg_match('/iso/',$translate)) |
|
172 | + $translate=exec($snmptranslate.' 1'); |
|
173 | + if (preg_match('/iso/', $translate)) |
|
174 | 174 | { |
175 | 175 | $this->view->snmptranslate='works fine'; |
176 | 176 | $this->view->snmptranslate_state='ok'; |
@@ -188,46 +188,46 @@ discard block |
||
188 | 188 | // mib database |
189 | 189 | |
190 | 190 | $this->view->mibDbCount=$this->getMIB()->countObjects(); |
191 | - $this->view->mibDbCountTrap=$this->getMIB()->countObjects(null,21); |
|
191 | + $this->view->mibDbCountTrap=$this->getMIB()->countObjects(null, 21); |
|
192 | 192 | |
193 | 193 | // mib dirs |
194 | 194 | $DirConf=$this->Config()->get('config', 'snmptranslate_dirs'); |
195 | - $dirArray=explode(':',$DirConf); |
|
195 | + $dirArray=explode(':', $DirConf); |
|
196 | 196 | |
197 | 197 | // Get base directories from net-snmp-config |
198 | 198 | $output=$matches=array(); |
199 | 199 | $retVal=0; |
200 | - $sysDirs=exec('net-snmp-config --default-mibdirs',$output,$retVal); |
|
201 | - if ($retVal==0) |
|
200 | + $sysDirs=exec('net-snmp-config --default-mibdirs', $output, $retVal); |
|
201 | + if ($retVal == 0) |
|
202 | 202 | { |
203 | - $dirArray=array_merge($dirArray,explode(':',$sysDirs)); |
|
203 | + $dirArray=array_merge($dirArray, explode(':', $sysDirs)); |
|
204 | 204 | } |
205 | 205 | else |
206 | 206 | { |
207 | - $translateOut=exec($this->Config()->get('config', 'snmptranslate') . ' -Dinit_mib .1.3 2>&1 | grep MIBDIRS'); |
|
208 | - if (preg_match('/MIBDIRS.*\'([^\']+)\'/',$translateOut,$matches)) |
|
207 | + $translateOut=exec($this->Config()->get('config', 'snmptranslate').' -Dinit_mib .1.3 2>&1 | grep MIBDIRS'); |
|
208 | + if (preg_match('/MIBDIRS.*\'([^\']+)\'/', $translateOut, $matches)) |
|
209 | 209 | { |
210 | - $dirArray=array_merge($dirArray,explode(':',$matches[1])); |
|
210 | + $dirArray=array_merge($dirArray, explode(':', $matches[1])); |
|
211 | 211 | } |
212 | 212 | else |
213 | 213 | { |
214 | - array_push($dirArray,'Install net-snmp-config to see system directories'); |
|
214 | + array_push($dirArray, 'Install net-snmp-config to see system directories'); |
|
215 | 215 | } |
216 | 216 | } |
217 | 217 | |
218 | 218 | $this->view->dirArray=$dirArray; |
219 | 219 | |
220 | 220 | $output=null; |
221 | - foreach (explode(':',$DirConf) as $mibdir) |
|
221 | + foreach (explode(':', $DirConf) as $mibdir) |
|
222 | 222 | { |
223 | - exec('ls '.$mibdir.' | grep -v traplist.txt',$output); |
|
223 | + exec('ls '.$mibdir.' | grep -v traplist.txt', $output); |
|
224 | 224 | } |
225 | 225 | //$i=0;$listFiles='';while (isset($output[$i])) $listFiles.=$output[$i++]; |
226 | 226 | //$this->view->fileList=explode(' ',$listFiles); |
227 | 227 | $this->view->fileList=$output; |
228 | 228 | |
229 | 229 | // Zend form |
230 | - $this->view->form= new UploadForm(); |
|
230 | + $this->view->form=new UploadForm(); |
|
231 | 231 | //$this->view->form= new Form('upload-form'); |
232 | 232 | |
233 | 233 | |
@@ -242,9 +242,9 @@ discard block |
||
242 | 242 | $this->view->setOKMsg=''; |
243 | 243 | |
244 | 244 | //max_rows=25&row_update=update |
245 | - if ( $this->getRequest()->getParam('max_rows',NULL) !== NULL ) |
|
245 | + if ($this->getRequest()->getParam('max_rows', NULL) !== NULL) |
|
246 | 246 | { |
247 | - $maxRows = $this->getRequest()->getParam('max_rows'); |
|
247 | + $maxRows=$this->getRequest()->getParam('max_rows'); |
|
248 | 248 | if (!preg_match('/^[0-9]+$/', $maxRows) || $maxRows < 1) |
249 | 249 | { |
250 | 250 | $this->view->setError='Max rows must be a number'; |
@@ -252,21 +252,21 @@ discard block |
||
252 | 252 | else |
253 | 253 | { |
254 | 254 | $this->setitemListDisplay($maxRows); |
255 | - $this->view->setOKMsg='Set max rows to ' . $maxRows; |
|
255 | + $this->view->setOKMsg='Set max rows to '.$maxRows; |
|
256 | 256 | } |
257 | 257 | } |
258 | 258 | |
259 | - if ( $this->getRequest()->getParam('add_category',NULL) !== NULL ) |
|
259 | + if ($this->getRequest()->getParam('add_category', NULL) !== NULL) |
|
260 | 260 | { |
261 | - $addCat = $this->getRequest()->getParam('add_category'); |
|
261 | + $addCat=$this->getRequest()->getParam('add_category'); |
|
262 | 262 | $this->addHandlersCategory($addCat); |
263 | 263 | } |
264 | 264 | |
265 | - if ( $this->getRequest()->getPost('type',NULL) !== NULL ) |
|
265 | + if ($this->getRequest()->getPost('type', NULL) !== NULL) |
|
266 | 266 | { |
267 | - $type = $this->getRequest()->getPost('type',NULL); |
|
268 | - $index = $this->getRequest()->getPost('index',NULL); |
|
269 | - $newname = $this->getRequest()->getPost('newname',NULL); |
|
267 | + $type=$this->getRequest()->getPost('type', NULL); |
|
268 | + $index=$this->getRequest()->getPost('index', NULL); |
|
269 | + $newname=$this->getRequest()->getPost('newname', NULL); |
|
270 | 270 | |
271 | 271 | if (!preg_match('/^[0-9]+$/', $index) || $index < 1) |
272 | 272 | $this->_helper->json(array('status'=>'Bad index')); |
@@ -290,9 +290,9 @@ discard block |
||
290 | 290 | } |
291 | 291 | } |
292 | 292 | |
293 | - $this->view->maxRows = $this->itemListDisplay(); |
|
293 | + $this->view->maxRows=$this->itemListDisplay(); |
|
294 | 294 | |
295 | - $this->view->categories = $this->getHandlersCategory(); |
|
295 | + $this->view->categories=$this->getHandlersCategory(); |
|
296 | 296 | |
297 | 297 | |
298 | 298 | |
@@ -316,18 +316,18 @@ discard block |
||
316 | 316 | $this->view->templateForm_output=''; |
317 | 317 | if (isset($postData['template_name']) && isset($postData['template_revert_time'])) |
318 | 318 | { |
319 | - $template_create = 'icingacli director service create --json \'{ "check_command": "dummy", '; |
|
320 | - $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", '; |
|
321 | - $template_create .= '"object_name": "'.$postData['template_name'].'", "object_type": "template", "retry_interval": "'.$postData['template_revert_time'].'"}\''; |
|
319 | + $template_create='icingacli director service create --json \'{ "check_command": "dummy", '; |
|
320 | + $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", '; |
|
321 | + $template_create.='"object_name": "'.$postData['template_name'].'", "object_type": "template", "retry_interval": "'.$postData['template_revert_time'].'"}\''; |
|
322 | 322 | $output=array(); |
323 | 323 | $ret_code=0; |
324 | - exec($template_create,$output,$ret_code); |
|
324 | + exec($template_create, $output, $ret_code); |
|
325 | 325 | if ($ret_code != 0) |
326 | 326 | { |
327 | - $this->displayExitError("Status -> Services","Error creating template : ".$output[0].'<br>Command was : '.$template_create); |
|
327 | + $this->displayExitError("Status -> Services", "Error creating template : ".$output[0].'<br>Command was : '.$template_create); |
|
328 | 328 | } |
329 | - exec('icingacli director config deploy',$output,$ret_code); |
|
330 | - $this->view->templateForm_output='Template '.$postData['template_name']. ' created'; |
|
329 | + exec('icingacli director config deploy', $output, $ret_code); |
|
330 | + $this->view->templateForm_output='Template '.$postData['template_name'].' created'; |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | // template creation form |
@@ -343,15 +343,15 @@ discard block |
||
343 | 343 | { |
344 | 344 | $this->prepareTabs()->activate('plugins'); |
345 | 345 | |
346 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
346 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
347 | 347 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
348 | - $Trap = new Trap($icingaweb2_etc,4); |
|
348 | + $Trap=new Trap($icingaweb2_etc, 4); |
|
349 | 349 | |
350 | - $this->view->pluginLoaded = htmlentities($Trap->pluginClass->registerAllPlugins(false)); |
|
350 | + $this->view->pluginLoaded=htmlentities($Trap->pluginClass->registerAllPlugins(false)); |
|
351 | 351 | |
352 | - $enabledPlugins = $Trap->pluginClass->getEnabledPlugins(); |
|
352 | + $enabledPlugins=$Trap->pluginClass->getEnabledPlugins(); |
|
353 | 353 | |
354 | - $pluginList = $Trap->pluginClass->pluginList(); |
|
354 | + $pluginList=$Trap->pluginClass->pluginList(); |
|
355 | 355 | |
356 | 356 | // Plugin list and fill function name list |
357 | 357 | $functionList=array(); |
@@ -359,16 +359,16 @@ discard block |
||
359 | 359 | foreach ($pluginList as $plugin) |
360 | 360 | { |
361 | 361 | $pluginDetails=$Trap->pluginClass->pluginDetails($plugin); |
362 | - $pluginDetails->enabled = (in_array($plugin, $enabledPlugins)) ? true : false; |
|
363 | - $pluginDetails->catchAllTraps = ($pluginDetails->catchAllTraps === true )? 'Yes' : 'No'; |
|
364 | - $pluginDetails->processTraps = ($pluginDetails->processTraps === true )? 'Yes' : 'No'; |
|
365 | - $pluginDetails->description = htmlentities($pluginDetails->description); |
|
366 | - $pluginDetails->description = preg_replace('/\n/','<br>',$pluginDetails->description); |
|
362 | + $pluginDetails->enabled=(in_array($plugin, $enabledPlugins)) ? true : false; |
|
363 | + $pluginDetails->catchAllTraps=($pluginDetails->catchAllTraps === true) ? 'Yes' : 'No'; |
|
364 | + $pluginDetails->processTraps=($pluginDetails->processTraps === true) ? 'Yes' : 'No'; |
|
365 | + $pluginDetails->description=htmlentities($pluginDetails->description); |
|
366 | + $pluginDetails->description=preg_replace('/\n/', '<br>', $pluginDetails->description); |
|
367 | 367 | array_push($this->view->pluginArray, $pluginDetails); |
368 | 368 | // Get functions for function details |
369 | 369 | foreach ($pluginDetails->funcArray as $function) |
370 | 370 | { |
371 | - array_push($functionList,$function); |
|
371 | + array_push($functionList, $function); |
|
372 | 372 | } |
373 | 373 | } |
374 | 374 | |
@@ -376,10 +376,10 @@ discard block |
||
376 | 376 | $this->view->functionList=array(); |
377 | 377 | foreach ($functionList as $function) |
378 | 378 | { |
379 | - $functionDetail = $Trap->pluginClass->getFunctionDetails($function); |
|
380 | - $functionDetail->params = htmlentities($functionDetail->params); |
|
381 | - $functionDetail->description = htmlentities($functionDetail->description); |
|
382 | - $functionDetail->description = preg_replace('/\n/','<br>',$functionDetail->description); |
|
379 | + $functionDetail=$Trap->pluginClass->getFunctionDetails($function); |
|
380 | + $functionDetail->params=htmlentities($functionDetail->params); |
|
381 | + $functionDetail->description=htmlentities($functionDetail->description); |
|
382 | + $functionDetail->description=preg_replace('/\n/', '<br>', $functionDetail->description); |
|
383 | 383 | array_push($this->view->functionList, $functionDetail); |
384 | 384 | } |
385 | 385 | |
@@ -389,19 +389,19 @@ discard block |
||
389 | 389 | { |
390 | 390 | return $this->getTabs()->add('status', array( |
391 | 391 | 'label' => $this->translate('Status'), |
392 | - 'url' => $this->getModuleConfig()->urlPath() . '/status') |
|
392 | + 'url' => $this->getModuleConfig()->urlPath().'/status') |
|
393 | 393 | )->add('mib', array( |
394 | 394 | 'label' => $this->translate('MIB Management'), |
395 | - 'url' => $this->getModuleConfig()->urlPath() . '/status/mib') |
|
395 | + 'url' => $this->getModuleConfig()->urlPath().'/status/mib') |
|
396 | 396 | )->add('uimgt', array( |
397 | 397 | 'label' => $this->translate('UI Configuration'), |
398 | - 'url' => $this->getModuleConfig()->urlPath() . '/status/uimgt') |
|
398 | + 'url' => $this->getModuleConfig()->urlPath().'/status/uimgt') |
|
399 | 399 | )->add('services', array( |
400 | 400 | 'label' => $this->translate('Services management'), |
401 | - 'url' => $this->getModuleConfig()->urlPath() . '/status/services') |
|
401 | + 'url' => $this->getModuleConfig()->urlPath().'/status/services') |
|
402 | 402 | )->add('plugins', array( |
403 | 403 | 'label' => $this->translate('Plugins management'), |
404 | - 'url' => $this->getModuleConfig()->urlPath() . '/status/plugins') |
|
404 | + 'url' => $this->getModuleConfig()->urlPath().'/status/plugins') |
|
405 | 405 | ); |
406 | 406 | } |
407 | 407 | } |
@@ -409,7 +409,7 @@ discard block |
||
409 | 409 | // TODO : see if useless |
410 | 410 | class UploadForm extends Form |
411 | 411 | { |
412 | - public function __construct($options = null) |
|
412 | + public function __construct($options=null) |
|
413 | 413 | { |
414 | 414 | parent::__construct($options); |
415 | 415 | $this->addElements2(); |
@@ -418,11 +418,11 @@ discard block |
||
418 | 418 | public function addElements2() |
419 | 419 | { |
420 | 420 | // File Input |
421 | - $file = new File('mib-file'); |
|
421 | + $file=new File('mib-file'); |
|
422 | 422 | $file->setLabel('Mib upload'); |
423 | 423 | //->setAttrib('multiple', null); |
424 | 424 | $this->addElement($file); |
425 | - $button = new Submit("upload",array('ignore'=>false)); |
|
426 | - $this->addElement($button);//->setIgnore(false); |
|
425 | + $button=new Submit("upload", array('ignore'=>false)); |
|
426 | + $this->addElement($button); //->setIgnore(false); |
|
427 | 427 | } |
428 | 428 | } |
@@ -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->getUIDatabase()->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->getUIDatabase()->getDBConfigValue('log_file'); |
57 | 58 | $this->view->logLevels=$this->getModuleConfig()->getlogLevels(); |
58 | 59 | $this->view->currentLogLevel=$this->getUIDatabase()->getDBConfigValue('log_level'); |
59 | - } |
|
60 | - catch (Exception $e) |
|
60 | + } catch (Exception $e) |
|
61 | 61 | { |
62 | 62 | $this->displayExitError('status',$e->getMessage()); |
63 | 63 | } |
@@ -69,8 +69,7 @@ discard block |
||
69 | 69 | $this->view->SnmpTrapAddressOID=$this->getUIDatabase()->getDBConfigValue('SnmpTrapAddess_oid'); |
70 | 70 | $this->view->SnmpTrapAddressOIDDefault = ($this->view->SnmpTrapAddressOID == $this->getModuleConfig()->getDBConfigDefaults()['SnmpTrapAddess_oid'] ) ? TRUE : FALSE; |
71 | 71 | |
72 | - } |
|
73 | - catch (Exception $e) |
|
72 | + } catch (Exception $e) |
|
74 | 73 | { |
75 | 74 | $this->displayExitError('status',$e->getMessage()); |
76 | 75 | } |
@@ -120,8 +119,7 @@ discard block |
||
120 | 119 | if ($retVal == 0) |
121 | 120 | { // process is alive |
122 | 121 | $this->_helper->json(array('status'=>'Alive and kicking')); |
123 | - } |
|
124 | - else |
|
122 | + } else |
|
125 | 123 | { // process is dead |
126 | 124 | $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid)); |
127 | 125 | } |
@@ -137,22 +135,19 @@ discard block |
||
137 | 135 | if (!is_dir($destDir)) |
138 | 136 | { |
139 | 137 | $this->view->uploadStatus="ERROR : no $destDir directory, check module configuration"; |
140 | - } |
|
141 | - else |
|
138 | + } else |
|
142 | 139 | { |
143 | 140 | if (!is_writable($destDir)) |
144 | 141 | { |
145 | 142 | $this->view->uploadStatus="ERROR : $destDir directory is not writable"; |
146 | - } |
|
147 | - else |
|
143 | + } else |
|
148 | 144 | { |
149 | 145 | $destination = $destDir .'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name"; |
150 | 146 | $sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'],FILTER_SANITIZE_STRING); |
151 | 147 | if (move_uploaded_file($sourceTmpNam,$destination)===false) |
152 | 148 | { |
153 | 149 | $this->view->uploadStatus="ERROR, file $destination not loaded. Check file and path name or selinux violations"; |
154 | - } |
|
155 | - else |
|
150 | + } else |
|
156 | 151 | { |
157 | 152 | $this->view->uploadStatus="File $name uploaded in $destDir"; |
158 | 153 | } |
@@ -174,13 +169,11 @@ discard block |
||
174 | 169 | { |
175 | 170 | $this->view->snmptranslate='works fine'; |
176 | 171 | $this->view->snmptranslate_state='ok'; |
177 | - } |
|
178 | - else |
|
172 | + } else |
|
179 | 173 | { |
180 | 174 | $this->view->snmptranslate='can execute but no resolution'; |
181 | 175 | } |
182 | - } |
|
183 | - else |
|
176 | + } else |
|
184 | 177 | { |
185 | 178 | $this->view->snmptranslate='cannot execute'; |
186 | 179 | } |
@@ -201,15 +194,13 @@ discard block |
||
201 | 194 | if ($retVal==0) |
202 | 195 | { |
203 | 196 | $dirArray=array_merge($dirArray,explode(':',$sysDirs)); |
204 | - } |
|
205 | - else |
|
197 | + } else |
|
206 | 198 | { |
207 | 199 | $translateOut=exec($this->Config()->get('config', 'snmptranslate') . ' -Dinit_mib .1.3 2>&1 | grep MIBDIRS'); |
208 | 200 | if (preg_match('/MIBDIRS.*\'([^\']+)\'/',$translateOut,$matches)) |
209 | 201 | { |
210 | 202 | $dirArray=array_merge($dirArray,explode(':',$matches[1])); |
211 | - } |
|
212 | - else |
|
203 | + } else |
|
213 | 204 | { |
214 | 205 | array_push($dirArray,'Install net-snmp-config to see system directories'); |
215 | 206 | } |
@@ -248,8 +239,7 @@ discard block |
||
248 | 239 | if (!preg_match('/^[0-9]+$/', $maxRows) || $maxRows < 1) |
249 | 240 | { |
250 | 241 | $this->view->setError='Max rows must be a number'; |
251 | - } |
|
252 | - else |
|
242 | + } else |
|
253 | 243 | { |
254 | 244 | $this->setitemListDisplay($maxRows); |
255 | 245 | $this->view->setOKMsg='Set max rows to ' . $maxRows; |
@@ -268,8 +258,9 @@ discard block |
||
268 | 258 | $index = $this->getRequest()->getPost('index',NULL); |
269 | 259 | $newname = $this->getRequest()->getPost('newname',NULL); |
270 | 260 | |
271 | - if (!preg_match('/^[0-9]+$/', $index) || $index < 1) |
|
272 | - $this->_helper->json(array('status'=>'Bad index')); |
|
261 | + if (!preg_match('/^[0-9]+$/', $index) || $index < 1) { |
|
262 | + $this->_helper->json(array('status'=>'Bad index')); |
|
263 | + } |
|
273 | 264 | |
274 | 265 | switch ($type) |
275 | 266 | { |