@@ -64,8 +64,7 @@ discard block |
||
64 | 64 | if ($pid == 1) |
65 | 65 | { |
66 | 66 | $trap->setLogging($logLevel,'display'); |
67 | - } |
|
68 | - else |
|
67 | + } else |
|
69 | 68 | { // use default display TODO : if default is 'display' son process will be killed at first output.... |
70 | 69 | if ($pid != 0) |
71 | 70 | { |
@@ -74,8 +73,7 @@ discard block |
||
74 | 73 | fclose($file); |
75 | 74 | echo "OK : process $pid in bckground"; |
76 | 75 | return 0; |
77 | - } |
|
78 | - else |
|
76 | + } else |
|
79 | 77 | { // son process : close all file descriptors and go to a new session |
80 | 78 | fclose($file); |
81 | 79 | // $sid = posix_setsid(); |
@@ -85,8 +83,7 @@ discard block |
||
85 | 83 | try |
86 | 84 | { |
87 | 85 | $trap->mibClass->update_mib_database(false,$forceCheck); |
88 | - } |
|
89 | - catch (Exception $e) |
|
86 | + } catch (Exception $e) |
|
90 | 87 | { |
91 | 88 | $trap->logging->log('Error in updating : ' . $e->getMessage(),2); |
92 | 89 | } |
@@ -103,8 +100,7 @@ discard block |
||
103 | 100 | $trap->mibClass->update_mib_database(true,$forceCheck); |
104 | 101 | echo "Done\n"; |
105 | 102 | |
106 | - } |
|
107 | - catch (Exception $e) |
|
103 | + } catch (Exception $e) |
|
108 | 104 | { |
109 | 105 | echo 'Error in updating : ' . $e->getMessage(); |
110 | 106 | } |
@@ -147,8 +143,7 @@ discard block |
||
147 | 143 | $Config->getMIBCacheTableName(), |
148 | 144 | 'id>0'); |
149 | 145 | echo 'Deleted '. $query . " traps and objects\n"; |
150 | - } |
|
151 | - catch (Exception $e) |
|
146 | + } catch (Exception $e) |
|
152 | 147 | { |
153 | 148 | echo 'Error in DB : ' . $e->getMessage(); |
154 | 149 | } |
@@ -22,77 +22,77 @@ discard block |
||
22 | 22 | class MibCommand extends Command |
23 | 23 | { |
24 | 24 | /** |
25 | - * Update mib database |
|
26 | - * |
|
27 | - * USAGE |
|
28 | - * |
|
29 | - * icingli trapdirector mib update |
|
30 | - * |
|
31 | - * OPTIONS |
|
32 | - * |
|
33 | - * --pid <file> : run in background with pid in <file> |
|
34 | - * |
|
35 | - * --verb : Set output log to verbose |
|
36 | - * |
|
37 | - * --force-check : force check of all traps & objects for change. (NOT IMPLEMENTED) |
|
38 | - */ |
|
25 | + * Update mib database |
|
26 | + * |
|
27 | + * USAGE |
|
28 | + * |
|
29 | + * icingli trapdirector mib update |
|
30 | + * |
|
31 | + * OPTIONS |
|
32 | + * |
|
33 | + * --pid <file> : run in background with pid in <file> |
|
34 | + * |
|
35 | + * --verb : Set output log to verbose |
|
36 | + * |
|
37 | + * --force-check : force check of all traps & objects for change. (NOT IMPLEMENTED) |
|
38 | + */ |
|
39 | 39 | public function updateAction() |
40 | 40 | { |
41 | - $background = $this->params->get('pid', null); |
|
42 | - $logLevel= $this->params->has('verb') ? 4 : 2; |
|
43 | - if ($this->params->has('force-check')) { echo "Not implemented"; return;} |
|
44 | - $forceCheck=$this->params->has('force-check')?True:False; |
|
45 | - $pid=1; |
|
46 | - if ($background != null) |
|
47 | - { |
|
48 | - $file=@fopen($background,'w'); |
|
49 | - if ($file == false) |
|
50 | - { |
|
51 | - echo 'Error : cannot open pid file '.$background; |
|
52 | - return 1; |
|
53 | - } |
|
54 | - $pid = pcntl_fork(); |
|
55 | - if ($pid == -1) { |
|
56 | - echo 'Error : Cannot fork process'; |
|
57 | - return 1; |
|
58 | - } |
|
59 | - } |
|
60 | - $module=Icinga::app()->getModuleManager()->getModule($this->getModuleName()); |
|
41 | + $background = $this->params->get('pid', null); |
|
42 | + $logLevel= $this->params->has('verb') ? 4 : 2; |
|
43 | + if ($this->params->has('force-check')) { echo "Not implemented"; return;} |
|
44 | + $forceCheck=$this->params->has('force-check')?True:False; |
|
45 | + $pid=1; |
|
46 | + if ($background != null) |
|
47 | + { |
|
48 | + $file=@fopen($background,'w'); |
|
49 | + if ($file == false) |
|
50 | + { |
|
51 | + echo 'Error : cannot open pid file '.$background; |
|
52 | + return 1; |
|
53 | + } |
|
54 | + $pid = pcntl_fork(); |
|
55 | + if ($pid == -1) { |
|
56 | + echo 'Error : Cannot fork process'; |
|
57 | + return 1; |
|
58 | + } |
|
59 | + } |
|
60 | + $module=Icinga::app()->getModuleManager()->getModule($this->getModuleName()); |
|
61 | 61 | require_once($module->getBaseDir() .'/bin/trap_class.php'); |
62 | 62 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
63 | 63 | $trap = new Trap($icingaweb2_etc); |
64 | 64 | if ($pid == 1) |
65 | 65 | { |
66 | - $trap->setLogging($logLevel,'display'); |
|
66 | + $trap->setLogging($logLevel,'display'); |
|
67 | 67 | } |
68 | 68 | else |
69 | 69 | { // use default display TODO : if default is 'display' son process will be killed at first output.... |
70 | - if ($pid != 0) |
|
71 | - { |
|
72 | - // father process |
|
73 | - fwrite($file,$pid); |
|
74 | - fclose($file); |
|
75 | - echo "OK : process $pid in bckground"; |
|
76 | - return 0; |
|
77 | - } |
|
78 | - else |
|
79 | - { // son process : close all file descriptors and go to a new session |
|
80 | - fclose($file); |
|
70 | + if ($pid != 0) |
|
71 | + { |
|
72 | + // father process |
|
73 | + fwrite($file,$pid); |
|
74 | + fclose($file); |
|
75 | + echo "OK : process $pid in bckground"; |
|
76 | + return 0; |
|
77 | + } |
|
78 | + else |
|
79 | + { // son process : close all file descriptors and go to a new session |
|
80 | + fclose($file); |
|
81 | 81 | // $sid = posix_setsid(); |
82 | - fclose(STDIN); |
|
83 | - fclose(STDOUT); |
|
84 | - fclose(STDERR); |
|
85 | - try |
|
86 | - { |
|
87 | - $trap->mibClass->update_mib_database(false,$forceCheck); |
|
88 | - } |
|
89 | - catch (Exception $e) |
|
90 | - { |
|
91 | - $trap->logging->log('Error in updating : ' . $e->getMessage(),2); |
|
92 | - } |
|
93 | - unlink($background); |
|
94 | - return 0; |
|
95 | - } |
|
82 | + fclose(STDIN); |
|
83 | + fclose(STDOUT); |
|
84 | + fclose(STDERR); |
|
85 | + try |
|
86 | + { |
|
87 | + $trap->mibClass->update_mib_database(false,$forceCheck); |
|
88 | + } |
|
89 | + catch (Exception $e) |
|
90 | + { |
|
91 | + $trap->logging->log('Error in updating : ' . $e->getMessage(),2); |
|
92 | + } |
|
93 | + unlink($background); |
|
94 | + return 0; |
|
95 | + } |
|
96 | 96 | |
97 | 97 | } |
98 | 98 | |
@@ -110,28 +110,28 @@ discard block |
||
110 | 110 | } |
111 | 111 | if ($pid != 1) |
112 | 112 | { |
113 | - unlink($background); |
|
113 | + unlink($background); |
|
114 | 114 | } |
115 | 115 | } |
116 | 116 | /** |
117 | - * purge all mib database NOT IMPLEMENTED |
|
118 | - * |
|
119 | - * USAGE |
|
120 | - * |
|
121 | - * icingli trapdirector mib purge --confirm |
|
122 | - * |
|
123 | - * OPTIONS |
|
124 | - * |
|
125 | - * --confirm : needed to execute purge |
|
126 | - */ |
|
117 | + * purge all mib database NOT IMPLEMENTED |
|
118 | + * |
|
119 | + * USAGE |
|
120 | + * |
|
121 | + * icingli trapdirector mib purge --confirm |
|
122 | + * |
|
123 | + * OPTIONS |
|
124 | + * |
|
125 | + * --confirm : needed to execute purge |
|
126 | + */ |
|
127 | 127 | public function purgeAction() |
128 | 128 | { |
129 | 129 | $db_prefix=$this->Config()->get('config', 'database_prefix'); |
130 | 130 | |
131 | 131 | if (!$this->params->has('confirm')) |
132 | 132 | { |
133 | - echo "This needs confirmation with '--confirm'\n"; |
|
134 | - return; |
|
133 | + echo "This needs confirmation with '--confirm'\n"; |
|
134 | + return; |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | $Config = new TrapModuleConfig($db_prefix); |
@@ -145,9 +145,9 @@ discard block |
||
145 | 145 | $db = IcingaDbConnection::fromResourceName($dbresource)->getDbAdapter(); |
146 | 146 | |
147 | 147 | $query = $db->delete( |
148 | - $Config->getMIBCacheTableName(), |
|
149 | - 'id>0'); |
|
150 | - echo 'Deleted '. $query . " traps and objects\n"; |
|
148 | + $Config->getMIBCacheTableName(), |
|
149 | + 'id>0'); |
|
150 | + echo 'Deleted '. $query . " traps and objects\n"; |
|
151 | 151 | } |
152 | 152 | catch (Exception $e) |
153 | 153 | { |
@@ -38,39 +38,39 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function updateAction() |
40 | 40 | { |
41 | - $background = $this->params->get('pid', null); |
|
42 | - $logLevel= $this->params->has('verb') ? 4 : 2; |
|
43 | - if ($this->params->has('force-check')) { echo "Not implemented"; return;} |
|
44 | - $forceCheck=$this->params->has('force-check')?True:False; |
|
41 | + $background=$this->params->get('pid', null); |
|
42 | + $logLevel=$this->params->has('verb') ? 4 : 2; |
|
43 | + if ($this->params->has('force-check')) { echo "Not implemented"; return; } |
|
44 | + $forceCheck=$this->params->has('force-check') ?True:False; |
|
45 | 45 | $pid=1; |
46 | 46 | if ($background != null) |
47 | 47 | { |
48 | - $file=@fopen($background,'w'); |
|
48 | + $file=@fopen($background, 'w'); |
|
49 | 49 | if ($file == false) |
50 | 50 | { |
51 | 51 | echo 'Error : cannot open pid file '.$background; |
52 | 52 | return 1; |
53 | 53 | } |
54 | - $pid = pcntl_fork(); |
|
54 | + $pid=pcntl_fork(); |
|
55 | 55 | if ($pid == -1) { |
56 | 56 | echo 'Error : Cannot fork process'; |
57 | 57 | return 1; |
58 | 58 | } |
59 | 59 | } |
60 | 60 | $module=Icinga::app()->getModuleManager()->getModule($this->getModuleName()); |
61 | - require_once($module->getBaseDir() .'/bin/trap_class.php'); |
|
61 | + require_once($module->getBaseDir().'/bin/trap_class.php'); |
|
62 | 62 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
63 | - $trap = new Trap($icingaweb2_etc); |
|
63 | + $trap=new Trap($icingaweb2_etc); |
|
64 | 64 | if ($pid == 1) |
65 | 65 | { |
66 | - $trap->setLogging($logLevel,'display'); |
|
66 | + $trap->setLogging($logLevel, 'display'); |
|
67 | 67 | } |
68 | 68 | else |
69 | 69 | { // use default display TODO : if default is 'display' son process will be killed at first output.... |
70 | 70 | if ($pid != 0) |
71 | 71 | { |
72 | 72 | // father process |
73 | - fwrite($file,$pid); |
|
73 | + fwrite($file, $pid); |
|
74 | 74 | fclose($file); |
75 | 75 | echo "OK : process $pid in bckground"; |
76 | 76 | return 0; |
@@ -84,11 +84,11 @@ discard block |
||
84 | 84 | fclose(STDERR); |
85 | 85 | try |
86 | 86 | { |
87 | - $trap->mibClass->update_mib_database(false,$forceCheck); |
|
87 | + $trap->mibClass->update_mib_database(false, $forceCheck); |
|
88 | 88 | } |
89 | 89 | catch (Exception $e) |
90 | 90 | { |
91 | - $trap->logging->log('Error in updating : ' . $e->getMessage(),2); |
|
91 | + $trap->logging->log('Error in updating : '.$e->getMessage(), 2); |
|
92 | 92 | } |
93 | 93 | unlink($background); |
94 | 94 | return 0; |
@@ -100,13 +100,13 @@ discard block |
||
100 | 100 | { |
101 | 101 | echo "Update main mib database : \n"; |
102 | 102 | echo "# (trap found) C (trap already processed) . (every 2 seconds) : \n"; |
103 | - $trap->mibClass->update_mib_database(true,$forceCheck); |
|
103 | + $trap->mibClass->update_mib_database(true, $forceCheck); |
|
104 | 104 | echo "Done\n"; |
105 | 105 | |
106 | 106 | } |
107 | 107 | catch (Exception $e) |
108 | 108 | { |
109 | - echo 'Error in updating : ' . $e->getMessage(); |
|
109 | + echo 'Error in updating : '.$e->getMessage(); |
|
110 | 110 | } |
111 | 111 | if ($pid != 1) |
112 | 112 | { |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | return; |
135 | 135 | } |
136 | 136 | |
137 | - $Config = new TrapModuleConfig($db_prefix); |
|
137 | + $Config=new TrapModuleConfig($db_prefix); |
|
138 | 138 | |
139 | 139 | try |
140 | 140 | { |
@@ -142,16 +142,16 @@ discard block |
||
142 | 142 | $dbresource=$this->Config()->get('config', 'database'); |
143 | 143 | echo "DB name : $dbresource\n"; |
144 | 144 | // $db = IcingaDbConnection::fromResourceName($dbresource)->getConnection(); |
145 | - $db = IcingaDbConnection::fromResourceName($dbresource)->getDbAdapter(); |
|
145 | + $db=IcingaDbConnection::fromResourceName($dbresource)->getDbAdapter(); |
|
146 | 146 | |
147 | - $query = $db->delete( |
|
147 | + $query=$db->delete( |
|
148 | 148 | $Config->getMIBCacheTableName(), |
149 | 149 | 'id>0'); |
150 | - echo 'Deleted '. $query . " traps and objects\n"; |
|
150 | + echo 'Deleted '.$query." traps and objects\n"; |
|
151 | 151 | } |
152 | 152 | catch (Exception $e) |
153 | 153 | { |
154 | - echo 'Error in DB : ' . $e->getMessage(); |
|
154 | + echo 'Error in DB : '.$e->getMessage(); |
|
155 | 155 | } |
156 | 156 | } |
157 | 157 |
@@ -52,8 +52,7 @@ discard block |
||
52 | 52 | $this->Config()->saveIni(); |
53 | 53 | $this->view->configErrorDetected='Configuration is empty : you can run install script with parameters (see Automatic installation below)'; |
54 | 54 | //$emptyConfig=1; |
55 | - } |
|
56 | - catch (Exception $e) |
|
55 | + } catch (Exception $e) |
|
57 | 56 | { |
58 | 57 | $this->view->configErrorDetected=$e->getMessage(); |
59 | 58 | } |
@@ -141,8 +140,7 @@ discard block |
||
141 | 140 | $this->view->apimessage='API config : ' . $e->getMessage(); |
142 | 141 | $this->view->apimessageError=true; |
143 | 142 | } |
144 | - } |
|
145 | - else |
|
143 | + } else |
|
146 | 144 | { |
147 | 145 | $this->view->apimessage='API parameters not configured'; |
148 | 146 | $this->view->apimessageError=true; |
@@ -208,7 +206,9 @@ discard block |
||
208 | 206 | $input="154865134987aaaa"; |
209 | 207 | exec("$phpBin -r \"echo '$input';\"",$output,$retCode); |
210 | 208 | |
211 | - if (! isset($output[0])) $output[0]="NO OUT"; |
|
209 | + if (! isset($output[0])) { |
|
210 | + $output[0]="NO OUT"; |
|
211 | + } |
|
212 | 212 | |
213 | 213 | if ($retCode == 0 && preg_match("/$input/",$output[0]) == 1) |
214 | 214 | { |
@@ -310,8 +310,7 @@ discard block |
||
310 | 310 | $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
311 | 311 | printf('Schema already exists'); |
312 | 312 | |
313 | - } |
|
314 | - catch (DBException $e) |
|
313 | + } catch (DBException $e) |
|
315 | 314 | { |
316 | 315 | |
317 | 316 | printf('Creating schema : <br>'); |
@@ -367,8 +366,7 @@ discard block |
||
367 | 366 | $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
368 | 367 | echo 'Schema already exists and is up to date<br>'; |
369 | 368 | return; |
370 | - } |
|
371 | - catch (DBException $e) |
|
369 | + } catch (DBException $e) |
|
372 | 370 | { |
373 | 371 | $dberror=$e->getArray(); |
374 | 372 | } |
@@ -452,16 +450,18 @@ discard block |
||
452 | 450 | } |
453 | 451 | // Assume there is only one line... TODO : see if there is a better way to do this |
454 | 452 | $line = preg_replace('/^.*snmptrapd /','',$psOutput[0]); |
455 | - if (!preg_match('/-n/',$line)) |
|
456 | - return array(1,'snmptrapd has no -n option : '.$line); |
|
457 | - if (!preg_match('/-O[^ ]*n/',$line)) |
|
458 | - return array(1,'snmptrapd has no -On option : '.$line); |
|
459 | - if (!preg_match('/-O[^ ]*e/',$line)) |
|
460 | - return array(1,'snmptrapd has no -Oe option : '.$line); |
|
453 | + if (!preg_match('/-n/',$line)) { |
|
454 | + return array(1,'snmptrapd has no -n option : '.$line); |
|
455 | + } |
|
456 | + if (!preg_match('/-O[^ ]*n/',$line)) { |
|
457 | + return array(1,'snmptrapd has no -On option : '.$line); |
|
458 | + } |
|
459 | + if (!preg_match('/-O[^ ]*e/',$line)) { |
|
460 | + return array(1,'snmptrapd has no -Oe option : '.$line); |
|
461 | + } |
|
461 | 462 | |
462 | 463 | return array(0,'snmptrapd listening to UDP/162, options : '.$line); |
463 | - } |
|
464 | - else |
|
464 | + } else |
|
465 | 465 | { |
466 | 466 | return array(0,'A daemon (hidden by SELinux) is listening on UDP/162'); |
467 | 467 | } |
@@ -25,16 +25,16 @@ discard block |
||
25 | 25 | */ |
26 | 26 | private function get_param() |
27 | 27 | { |
28 | - $dberrorMsg=$this->params->get('dberror'); |
|
29 | - if ($dberrorMsg != '') |
|
30 | - { |
|
31 | - $this->view->errorDetected=$dberrorMsg; |
|
32 | - } |
|
33 | - $dberrorMsg=$this->params->get('idodberror'); |
|
34 | - if ($dberrorMsg != '') |
|
35 | - { |
|
36 | - $this->view->errorDetected=$dberrorMsg; |
|
37 | - } |
|
28 | + $dberrorMsg=$this->params->get('dberror'); |
|
29 | + if ($dberrorMsg != '') |
|
30 | + { |
|
31 | + $this->view->errorDetected=$dberrorMsg; |
|
32 | + } |
|
33 | + $dberrorMsg=$this->params->get('idodberror'); |
|
34 | + if ($dberrorMsg != '') |
|
35 | + { |
|
36 | + $this->view->errorDetected=$dberrorMsg; |
|
37 | + } |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -43,22 +43,22 @@ discard block |
||
43 | 43 | */ |
44 | 44 | private function check_empty_config() |
45 | 45 | { |
46 | - $this->view->configErrorDetected == NULL; // Displayed error on various conifugration errors. |
|
47 | - if ($this->Config()->isEmpty() == true) |
|
48 | - { |
|
49 | - $this->Config()->setSection('config'); // Set base config section. |
|
50 | - try |
|
51 | - { |
|
52 | - $this->Config()->saveIni(); |
|
53 | - $this->view->configErrorDetected='Configuration is empty : you can run install script with parameters (see Automatic installation below)'; |
|
54 | - //$emptyConfig=1; |
|
55 | - } |
|
56 | - catch (Exception $e) |
|
57 | - { |
|
58 | - $this->view->configErrorDetected=$e->getMessage(); |
|
59 | - } |
|
46 | + $this->view->configErrorDetected == NULL; // Displayed error on various conifugration errors. |
|
47 | + if ($this->Config()->isEmpty() == true) |
|
48 | + { |
|
49 | + $this->Config()->setSection('config'); // Set base config section. |
|
50 | + try |
|
51 | + { |
|
52 | + $this->Config()->saveIni(); |
|
53 | + $this->view->configErrorDetected='Configuration is empty : you can run install script with parameters (see Automatic installation below)'; |
|
54 | + //$emptyConfig=1; |
|
55 | + } |
|
56 | + catch (Exception $e) |
|
57 | + { |
|
58 | + $this->view->configErrorDetected=$e->getMessage(); |
|
59 | + } |
|
60 | 60 | |
61 | - } |
|
61 | + } |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -71,57 +71,57 @@ discard block |
||
71 | 71 | */ |
72 | 72 | private function check_db() |
73 | 73 | { |
74 | - $db_message=array( // index => ( message OK, message NOK, optional link if NOK ) |
|
75 | - 0 => array('Database configuration OK','',''), |
|
76 | - 1 => array('Database set in config.ini','No database in config.ini',''), |
|
77 | - 2 => array('Database exists in Icingaweb2 config','Database does not exist in Icingaweb2 : ', |
|
78 | - Url::fromPath('config/resource')), |
|
79 | - 3 => array('Database credentials OK','Database does not exist/invalid credentials/no schema : ', |
|
80 | - Url::fromPath('trapdirector/settings/createschema')), |
|
81 | - 4 => array('Schema is set','Schema is not set for ', |
|
82 | - Url::fromPath('trapdirector/settings/createschema')), |
|
83 | - 5 => array('Schema is up to date','Schema is outdated :', |
|
84 | - Url::fromPath('trapdirector/settings/updateschema')), |
|
85 | - ); |
|
74 | + $db_message=array( // index => ( message OK, message NOK, optional link if NOK ) |
|
75 | + 0 => array('Database configuration OK','',''), |
|
76 | + 1 => array('Database set in config.ini','No database in config.ini',''), |
|
77 | + 2 => array('Database exists in Icingaweb2 config','Database does not exist in Icingaweb2 : ', |
|
78 | + Url::fromPath('config/resource')), |
|
79 | + 3 => array('Database credentials OK','Database does not exist/invalid credentials/no schema : ', |
|
80 | + Url::fromPath('trapdirector/settings/createschema')), |
|
81 | + 4 => array('Schema is set','Schema is not set for ', |
|
82 | + Url::fromPath('trapdirector/settings/createschema')), |
|
83 | + 5 => array('Schema is up to date','Schema is outdated :', |
|
84 | + Url::fromPath('trapdirector/settings/updateschema')), |
|
85 | + ); |
|
86 | 86 | |
87 | - try { |
|
88 | - $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
|
89 | - $dberror=array(0,''); |
|
90 | - } catch (DBException $e) { |
|
91 | - $dberror = $e->getArray(); |
|
92 | - } |
|
87 | + try { |
|
88 | + $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
|
89 | + $dberror=array(0,''); |
|
90 | + } catch (DBException $e) { |
|
91 | + $dberror = $e->getArray(); |
|
92 | + } |
|
93 | 93 | |
94 | - $this->view->db_error=$dberror[0]; |
|
95 | - switch ($dberror[0]) |
|
96 | - { |
|
97 | - case 2: |
|
98 | - case 4: |
|
99 | - $db_message[$dberror[0]][1] .= $dberror[1]; |
|
100 | - break; |
|
101 | - case 3: |
|
102 | - $db_message[$dberror[0]][1] .= $dberror[1] . ', Message : ' . $dberror[2]; |
|
103 | - break; |
|
104 | - case 5: |
|
105 | - $db_message[$dberror[0]][1] .= ' version '. $dberror[1] . ', version needed : ' .$dberror[2]; |
|
106 | - break; |
|
107 | - case 0: |
|
108 | - case 1: |
|
109 | - break; |
|
110 | - default: |
|
111 | - new ProgrammingError('Out of bond result from database test'); |
|
112 | - } |
|
113 | - $this->view->message=$db_message; |
|
94 | + $this->view->db_error=$dberror[0]; |
|
95 | + switch ($dberror[0]) |
|
96 | + { |
|
97 | + case 2: |
|
98 | + case 4: |
|
99 | + $db_message[$dberror[0]][1] .= $dberror[1]; |
|
100 | + break; |
|
101 | + case 3: |
|
102 | + $db_message[$dberror[0]][1] .= $dberror[1] . ', Message : ' . $dberror[2]; |
|
103 | + break; |
|
104 | + case 5: |
|
105 | + $db_message[$dberror[0]][1] .= ' version '. $dberror[1] . ', version needed : ' .$dberror[2]; |
|
106 | + break; |
|
107 | + case 0: |
|
108 | + case 1: |
|
109 | + break; |
|
110 | + default: |
|
111 | + new ProgrammingError('Out of bond result from database test'); |
|
112 | + } |
|
113 | + $this->view->message=$db_message; |
|
114 | 114 | |
115 | - try { |
|
116 | - $this->getUIDatabase()->testGetIdoDb(); // Get DB in test mode |
|
117 | - $dberror=array(0,''); |
|
118 | - } catch (DBException $e) { |
|
119 | - $dberror = $e->getArray(); |
|
120 | - } |
|
115 | + try { |
|
116 | + $this->getUIDatabase()->testGetIdoDb(); // Get DB in test mode |
|
117 | + $dberror=array(0,''); |
|
118 | + } catch (DBException $e) { |
|
119 | + $dberror = $e->getArray(); |
|
120 | + } |
|
121 | 121 | |
122 | - $this->view->ido_db_error=$dberror[0]; |
|
123 | - $this->view->ido_message='IDO Database : ' . $dberror[1]; |
|
124 | - $this->view->ido_message .='<br />=> Default to API use. Make sure it is configured and check is returning OK!'; |
|
122 | + $this->view->ido_db_error=$dberror[0]; |
|
123 | + $this->view->ido_message='IDO Database : ' . $dberror[1]; |
|
124 | + $this->view->ido_message .='<br />=> Default to API use. Make sure it is configured and check is returning OK!'; |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -131,23 +131,23 @@ discard block |
||
131 | 131 | */ |
132 | 132 | private function check_api() |
133 | 133 | { |
134 | - if ($this->Config()->get('config', 'icingaAPI_host') != '') |
|
135 | - { |
|
136 | - $apitest=new Icinga2API($this->Config()->get('config', 'icingaAPI_host'),$this->Config()->get('config', 'icingaAPI_port')); |
|
137 | - $apitest->setCredentials($this->Config()->get('config', 'icingaAPI_user'), $this->Config()->get('config', 'icingaAPI_password')); |
|
138 | - try { |
|
139 | - list($this->view->apimessageError,$this->view->apimessage)=$apitest->test($this->getModuleConfig()::getapiUserPermissions()); |
|
140 | - //$this->view->apimessageError=false; |
|
141 | - } catch (RuntimeException $e) { |
|
142 | - $this->view->apimessage='API config : ' . $e->getMessage(); |
|
143 | - $this->view->apimessageError=true; |
|
144 | - } |
|
145 | - } |
|
146 | - else |
|
147 | - { |
|
148 | - $this->view->apimessage='API parameters not configured'; |
|
149 | - $this->view->apimessageError=true; |
|
150 | - } |
|
134 | + if ($this->Config()->get('config', 'icingaAPI_host') != '') |
|
135 | + { |
|
136 | + $apitest=new Icinga2API($this->Config()->get('config', 'icingaAPI_host'),$this->Config()->get('config', 'icingaAPI_port')); |
|
137 | + $apitest->setCredentials($this->Config()->get('config', 'icingaAPI_user'), $this->Config()->get('config', 'icingaAPI_password')); |
|
138 | + try { |
|
139 | + list($this->view->apimessageError,$this->view->apimessage)=$apitest->test($this->getModuleConfig()::getapiUserPermissions()); |
|
140 | + //$this->view->apimessageError=false; |
|
141 | + } catch (RuntimeException $e) { |
|
142 | + $this->view->apimessage='API config : ' . $e->getMessage(); |
|
143 | + $this->view->apimessageError=true; |
|
144 | + } |
|
145 | + } |
|
146 | + else |
|
147 | + { |
|
148 | + $this->view->apimessage='API parameters not configured'; |
|
149 | + $this->view->apimessageError=true; |
|
150 | + } |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -158,21 +158,21 @@ discard block |
||
158 | 158 | */ |
159 | 159 | private function check_icingaweb_path() |
160 | 160 | { |
161 | - $this->view->icingaEtcWarn=0; |
|
162 | - $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
163 | - if ($icingaweb2_etc != "/etc/icingaweb2/" && $icingaweb2_etc != '') |
|
164 | - { |
|
165 | - $output=array(); |
|
161 | + $this->view->icingaEtcWarn=0; |
|
162 | + $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
163 | + if ($icingaweb2_etc != "/etc/icingaweb2/" && $icingaweb2_etc != '') |
|
164 | + { |
|
165 | + $output=array(); |
|
166 | 166 | |
167 | - exec('cat ' . $this->module->getBaseDir() .'/bin/trap_in.php | grep "\$icingaweb2Etc=" ',$output); |
|
167 | + exec('cat ' . $this->module->getBaseDir() .'/bin/trap_in.php | grep "\$icingaweb2Etc=" ',$output); |
|
168 | 168 | |
169 | 169 | |
170 | - if (! isset($output[0]) || ! preg_match('#"'. $icingaweb2_etc .'"#',$output[0])) |
|
171 | - { |
|
172 | - $this->view->icingaEtcWarn=1; |
|
173 | - $this->view->icingaweb2_etc=$icingaweb2_etc; |
|
174 | - } |
|
175 | - } |
|
170 | + if (! isset($output[0]) || ! preg_match('#"'. $icingaweb2_etc .'"#',$output[0])) |
|
171 | + { |
|
172 | + $this->view->icingaEtcWarn=1; |
|
173 | + $this->view->icingaweb2_etc=$icingaweb2_etc; |
|
174 | + } |
|
175 | + } |
|
176 | 176 | |
177 | 177 | } |
178 | 178 | |
@@ -183,15 +183,15 @@ discard block |
||
183 | 183 | */ |
184 | 184 | private function get_db_list($allowed) |
185 | 185 | { |
186 | - $resources = array(); |
|
187 | - foreach (ResourceFactory::getResourceConfigs() as $name => $resource) |
|
188 | - { |
|
189 | - if ($resource->get('type') === 'db' && in_array($resource->get('db'), $allowed)) |
|
190 | - { |
|
191 | - $resources[$name] = $name; |
|
192 | - } |
|
193 | - } |
|
194 | - return $resources; |
|
186 | + $resources = array(); |
|
187 | + foreach (ResourceFactory::getResourceConfigs() as $name => $resource) |
|
188 | + { |
|
189 | + if ($resource->get('type') === 'db' && in_array($resource->get('db'), $allowed)) |
|
190 | + { |
|
191 | + $resources[$name] = $name; |
|
192 | + } |
|
193 | + } |
|
194 | + return $resources; |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
@@ -200,23 +200,23 @@ discard block |
||
200 | 200 | */ |
201 | 201 | private function get_php_binary() |
202 | 202 | { |
203 | - $phpBinary= array( PHP_BINARY, PHP_BINDIR . "/php", '/usr/bin/php'); |
|
203 | + $phpBinary= array( PHP_BINARY, PHP_BINDIR . "/php", '/usr/bin/php'); |
|
204 | 204 | |
205 | - foreach ($phpBinary as $phpBin ) |
|
206 | - { |
|
207 | - $output=array(); |
|
208 | - $retCode=255; |
|
209 | - $input="154865134987aaaa"; |
|
210 | - exec("$phpBin -r \"echo '$input';\"",$output,$retCode); |
|
205 | + foreach ($phpBinary as $phpBin ) |
|
206 | + { |
|
207 | + $output=array(); |
|
208 | + $retCode=255; |
|
209 | + $input="154865134987aaaa"; |
|
210 | + exec("$phpBin -r \"echo '$input';\"",$output,$retCode); |
|
211 | 211 | |
212 | - if (! isset($output[0])) $output[0]="NO OUT"; |
|
212 | + if (! isset($output[0])) $output[0]="NO OUT"; |
|
213 | 213 | |
214 | - if ($retCode == 0 && preg_match("/$input/",$output[0]) == 1) |
|
215 | - { |
|
216 | - return $phpBin; |
|
217 | - } |
|
218 | - } |
|
219 | - return NULL; |
|
214 | + if ($retCode == 0 && preg_match("/$input/",$output[0]) == 1) |
|
215 | + { |
|
216 | + return $phpBin; |
|
217 | + } |
|
218 | + } |
|
219 | + return NULL; |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | public function indexAction() |
236 | 236 | { |
237 | 237 | |
238 | - // CHeck permissions : display tests in any case, but no configuration. |
|
238 | + // CHeck permissions : display tests in any case, but no configuration. |
|
239 | 239 | $this->view->configPermission=$this->checkModuleConfigPermission(1); |
240 | 240 | // But check read permission |
241 | 241 | $this->checkReadPermission(); |
@@ -243,16 +243,16 @@ discard block |
||
243 | 243 | $this->view->tabs = $this->Module()->getConfigTabs()->activate('config'); |
244 | 244 | |
245 | 245 | // Get message : sent on configuration problems detected by controllers |
246 | - $this->get_param(); |
|
246 | + $this->get_param(); |
|
247 | 247 | |
248 | - // Test if configuration exists, if not create for installer script |
|
248 | + // Test if configuration exists, if not create for installer script |
|
249 | 249 | $this->check_empty_config(); |
250 | 250 | |
251 | 251 | // Test Database |
252 | - $this->check_db(); |
|
252 | + $this->check_db(); |
|
253 | 253 | |
254 | 254 | // Test API |
255 | - $this->check_api(); |
|
255 | + $this->check_api(); |
|
256 | 256 | |
257 | 257 | //Test snmptrapd alive and options |
258 | 258 | list ($this->view->snmptrapdError, $this->view->snmptrapdMessage) = $this->checkSnmpTrapd(); |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | $phpBinary = $this->get_php_binary(); |
267 | 267 | if ($phpBinary === null) |
268 | 268 | { |
269 | - $phpBinary = ' PHP BINARY NOT FOUND '; |
|
269 | + $phpBinary = ' PHP BINARY NOT FOUND '; |
|
270 | 270 | |
271 | 271 | } |
272 | 272 | |
@@ -274,11 +274,11 @@ discard block |
||
274 | 274 | $this->view->traps_in_config= $phpBinary . ' ' . $this->Module()->getBaseDir() . '/bin/trap_in.php'; |
275 | 275 | |
276 | 276 | $this->view->installer= $this->Module()->getBaseDir() . '/bin/installer.sh ' |
277 | - . ' -c all ' |
|
278 | - . ' -d ' . $this->Module()->getBaseDir() |
|
279 | - . ' -p ' . $phpBinary |
|
280 | - . ' -a ' . exec('whoami') |
|
281 | - . ' -w ' . Icinga::app()->getConfigDir(); |
|
277 | + . ' -c all ' |
|
278 | + . ' -d ' . $this->Module()->getBaseDir() |
|
279 | + . ' -p ' . $phpBinary |
|
280 | + . ' -a ' . exec('whoami') |
|
281 | + . ' -w ' . Icinga::app()->getConfigDir(); |
|
282 | 282 | |
283 | 283 | // ******************* configuration form setup******************* |
284 | 284 | $this->view->form = $form = new TrapsConfigForm(); |
@@ -312,15 +312,15 @@ discard block |
||
312 | 312 | public function satelliteAction() |
313 | 313 | { |
314 | 314 | |
315 | - // CHeck permissions |
|
316 | - $this->view->configPermission=$this->checkModuleConfigPermission(); |
|
315 | + // CHeck permissions |
|
316 | + $this->view->configPermission=$this->checkModuleConfigPermission(); |
|
317 | 317 | |
318 | - // Setup tabs |
|
319 | - $this->view->tabs = $this->Module()->getConfigTabs()->activate('satellite'); |
|
318 | + // Setup tabs |
|
319 | + $this->view->tabs = $this->Module()->getConfigTabs()->activate('satellite'); |
|
320 | 320 | |
321 | - $this->view->masterHASet = FALSE; |
|
321 | + $this->view->masterHASet = FALSE; |
|
322 | 322 | |
323 | - $this->view->masterHAConf = array ('name' => 'masterHA1', 'icingaweb2 user'=>'User1'); |
|
323 | + $this->view->masterHAConf = array ('name' => 'masterHA1', 'icingaweb2 user'=>'User1'); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | |
@@ -336,8 +336,8 @@ discard block |
||
336 | 336 | |
337 | 337 | try |
338 | 338 | { |
339 | - $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
|
340 | - printf('Schema already exists'); |
|
339 | + $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
|
340 | + printf('Schema already exists'); |
|
341 | 341 | |
342 | 342 | } |
343 | 343 | catch (DBException $e) |
@@ -348,19 +348,19 @@ discard block |
||
348 | 348 | // Get module database name |
349 | 349 | $dbName=$this->Config()->get('config', 'database'); |
350 | 350 | |
351 | - $dbResource = ResourceFactory::getResourceConfig($dbName); |
|
352 | - $dbType=$dbResource->get('db'); |
|
353 | - switch ($dbType) { |
|
354 | - case 'mysql': |
|
355 | - $dbFileExt='sql'; |
|
356 | - break; |
|
357 | - case 'pgsql': |
|
358 | - $dbFileExt='pgsql'; |
|
359 | - break; |
|
360 | - default: |
|
361 | - printf("Database configuration error : Unsuported DB"); |
|
362 | - return; |
|
363 | - } |
|
351 | + $dbResource = ResourceFactory::getResourceConfig($dbName); |
|
352 | + $dbType=$dbResource->get('db'); |
|
353 | + switch ($dbType) { |
|
354 | + case 'mysql': |
|
355 | + $dbFileExt='sql'; |
|
356 | + break; |
|
357 | + case 'pgsql': |
|
358 | + $dbFileExt='pgsql'; |
|
359 | + break; |
|
360 | + default: |
|
361 | + printf("Database configuration error : Unsuported DB"); |
|
362 | + return; |
|
363 | + } |
|
364 | 364 | |
365 | 365 | printf('<pre>'); |
366 | 366 | require_once $this->Module()->getBaseDir() .'/bin/trap_class.php'; |
@@ -384,32 +384,32 @@ discard block |
||
384 | 384 | public function updateschemaAction() |
385 | 385 | { |
386 | 386 | $this->checkModuleConfigPermission(); |
387 | - $this->getTabs()->add('get',array( |
|
388 | - 'active' => true, |
|
389 | - 'label' => $this->translate('Update Schema'), |
|
390 | - 'url' => Url::fromRequest() |
|
391 | - )); |
|
387 | + $this->getTabs()->add('get',array( |
|
388 | + 'active' => true, |
|
389 | + 'label' => $this->translate('Update Schema'), |
|
390 | + 'url' => Url::fromRequest() |
|
391 | + )); |
|
392 | 392 | // check if needed |
393 | 393 | $dberror=array(); |
394 | - try |
|
395 | - { |
|
396 | - $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
|
397 | - echo 'Schema already exists and is up to date<br>'; |
|
398 | - return; |
|
399 | - } |
|
400 | - catch (DBException $e) |
|
401 | - { |
|
402 | - $dberror=$e->getArray(); |
|
403 | - } |
|
394 | + try |
|
395 | + { |
|
396 | + $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
|
397 | + echo 'Schema already exists and is up to date<br>'; |
|
398 | + return; |
|
399 | + } |
|
400 | + catch (DBException $e) |
|
401 | + { |
|
402 | + $dberror=$e->getArray(); |
|
403 | + } |
|
404 | 404 | |
405 | 405 | echo 'Return to <a href="' . Url::fromPath('trapdirector/settings') .'" class="link-button icon-wrench"> settings page </a><br><br>'; |
406 | 406 | |
407 | 407 | if ($dberror[0] != 5) |
408 | 408 | { |
409 | - echo 'Database does not exists or is not setup correctly<br>'; |
|
410 | - return; |
|
409 | + echo 'Database does not exists or is not setup correctly<br>'; |
|
410 | + return; |
|
411 | 411 | } |
412 | - // setup |
|
412 | + // setup |
|
413 | 413 | require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
414 | 414 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
415 | 415 | $debug_level=4; |
@@ -422,20 +422,20 @@ discard block |
||
422 | 422 | $target_version=$dberror[2]; |
423 | 423 | |
424 | 424 | if ($this->params->get('msgok') == null) { |
425 | - // Check for messages and display if any |
|
426 | - echo "Upgrade databse is going to start.<br>Don't forget to backup your database before update<br>"; |
|
427 | - $Trap->setLogging(2,'syslog'); |
|
428 | - $message = $Trap->trapsDB->update_schema($updateSchema,$target_version,$prefix,true); |
|
429 | - if ($message != '') |
|
430 | - { |
|
431 | - echo 'Note :<br><pre>'; |
|
432 | - echo $message; |
|
433 | - echo '</pre>'; |
|
434 | - echo '<br>'; |
|
435 | - echo '<a class="link-button" style="font-size:large;font-weight:bold" href="' . Url::fromPath('trapdirector/settings/updateschema') .'?msgok=1">Click here to update</a>'; |
|
436 | - echo '<br>'; |
|
437 | - return; |
|
438 | - } |
|
425 | + // Check for messages and display if any |
|
426 | + echo "Upgrade databse is going to start.<br>Don't forget to backup your database before update<br>"; |
|
427 | + $Trap->setLogging(2,'syslog'); |
|
428 | + $message = $Trap->trapsDB->update_schema($updateSchema,$target_version,$prefix,true); |
|
429 | + if ($message != '') |
|
430 | + { |
|
431 | + echo 'Note :<br><pre>'; |
|
432 | + echo $message; |
|
433 | + echo '</pre>'; |
|
434 | + echo '<br>'; |
|
435 | + echo '<a class="link-button" style="font-size:large;font-weight:bold" href="' . Url::fromPath('trapdirector/settings/updateschema') .'?msgok=1">Click here to update</a>'; |
|
436 | + echo '<br>'; |
|
437 | + return; |
|
438 | + } |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | $Trap->setLogging($debug_level,'display'); |
@@ -450,52 +450,52 @@ discard block |
||
450 | 450 | |
451 | 451 | private function checkSnmpTrapd() |
452 | 452 | { |
453 | - $psOutput=array(); |
|
454 | - // First check is someone is listening to port 162. As not root, we can't have pid... |
|
455 | - $sspath = exec('which ss 2>/dev/null'); |
|
456 | - if(empty($sspath)) |
|
457 | - { |
|
458 | - // RHEL based systems |
|
459 | - $sspath = '/usr/sbin/ss'; |
|
460 | - } |
|
461 | - if(!is_executable("$sspath")) |
|
462 | - { |
|
463 | - return array(1,"Can not execute $sspath"); |
|
464 | - } |
|
465 | - exec("$sspath -lun | grep ':162 '",$psOutput); |
|
466 | - if (count($psOutput) == 0) |
|
467 | - { |
|
468 | - $extra = ""; |
|
469 | - if (is_file("/.dockerenv")){ $extra = '<br />=> ignore if Trapdirector is running in a different Docker container'; } |
|
470 | - return array(1,'Port UDP/162 is not open : is snmptrapd running?'. $extra); |
|
471 | - } |
|
472 | - $psOutput=array(); |
|
473 | - $selinux_state = ''; |
|
474 | - if(is_executable('/usr/sbin/getenforce')) |
|
475 | - { |
|
476 | - $selinux_state = exec('/usr/sbin/getenforce 2>/dev/null'); |
|
477 | - } |
|
478 | - if($selinux_state !== 'Enforcing') |
|
479 | - { |
|
480 | - exec('ps --no-headers -o command -C snmptrapd',$psOutput); |
|
481 | - if (count($psOutput) == 0) |
|
482 | - { |
|
483 | - return array(1,"UDP/162 : OK, but no snmptrapd process (?)"); |
|
484 | - } |
|
485 | - // Assume there is only one line... TODO : see if there is a better way to do this |
|
486 | - $line = preg_replace('/^.*snmptrapd /','',$psOutput[0]); |
|
487 | - if (!preg_match('/-n/',$line)) |
|
488 | - return array(1,'snmptrapd has no -n option : '.$line); |
|
489 | - if (!preg_match('/-O[^ ]*n/',$line)) |
|
490 | - return array(1,'snmptrapd has no -On option : '.$line); |
|
491 | - if (!preg_match('/-O[^ ]*e/',$line)) |
|
492 | - return array(1,'snmptrapd has no -Oe option : '.$line); |
|
453 | + $psOutput=array(); |
|
454 | + // First check is someone is listening to port 162. As not root, we can't have pid... |
|
455 | + $sspath = exec('which ss 2>/dev/null'); |
|
456 | + if(empty($sspath)) |
|
457 | + { |
|
458 | + // RHEL based systems |
|
459 | + $sspath = '/usr/sbin/ss'; |
|
460 | + } |
|
461 | + if(!is_executable("$sspath")) |
|
462 | + { |
|
463 | + return array(1,"Can not execute $sspath"); |
|
464 | + } |
|
465 | + exec("$sspath -lun | grep ':162 '",$psOutput); |
|
466 | + if (count($psOutput) == 0) |
|
467 | + { |
|
468 | + $extra = ""; |
|
469 | + if (is_file("/.dockerenv")){ $extra = '<br />=> ignore if Trapdirector is running in a different Docker container'; } |
|
470 | + return array(1,'Port UDP/162 is not open : is snmptrapd running?'. $extra); |
|
471 | + } |
|
472 | + $psOutput=array(); |
|
473 | + $selinux_state = ''; |
|
474 | + if(is_executable('/usr/sbin/getenforce')) |
|
475 | + { |
|
476 | + $selinux_state = exec('/usr/sbin/getenforce 2>/dev/null'); |
|
477 | + } |
|
478 | + if($selinux_state !== 'Enforcing') |
|
479 | + { |
|
480 | + exec('ps --no-headers -o command -C snmptrapd',$psOutput); |
|
481 | + if (count($psOutput) == 0) |
|
482 | + { |
|
483 | + return array(1,"UDP/162 : OK, but no snmptrapd process (?)"); |
|
484 | + } |
|
485 | + // Assume there is only one line... TODO : see if there is a better way to do this |
|
486 | + $line = preg_replace('/^.*snmptrapd /','',$psOutput[0]); |
|
487 | + if (!preg_match('/-n/',$line)) |
|
488 | + return array(1,'snmptrapd has no -n option : '.$line); |
|
489 | + if (!preg_match('/-O[^ ]*n/',$line)) |
|
490 | + return array(1,'snmptrapd has no -On option : '.$line); |
|
491 | + if (!preg_match('/-O[^ ]*e/',$line)) |
|
492 | + return array(1,'snmptrapd has no -Oe option : '.$line); |
|
493 | 493 | |
494 | - return array(0,'snmptrapd listening to UDP/162, options : '.$line); |
|
495 | - } |
|
496 | - else |
|
497 | - { |
|
498 | - return array(0,'A daemon (hidden by SELinux) is listening on UDP/162'); |
|
499 | - } |
|
494 | + return array(0,'snmptrapd listening to UDP/162, options : '.$line); |
|
495 | + } |
|
496 | + else |
|
497 | + { |
|
498 | + return array(0,'A daemon (hidden by SELinux) is listening on UDP/162'); |
|
499 | + } |
|
500 | 500 | } |
501 | 501 | } |
@@ -72,23 +72,23 @@ discard block |
||
72 | 72 | private function check_db() |
73 | 73 | { |
74 | 74 | $db_message=array( // index => ( message OK, message NOK, optional link if NOK ) |
75 | - 0 => array('Database configuration OK','',''), |
|
76 | - 1 => array('Database set in config.ini','No database in config.ini',''), |
|
77 | - 2 => array('Database exists in Icingaweb2 config','Database does not exist in Icingaweb2 : ', |
|
75 | + 0 => array('Database configuration OK', '', ''), |
|
76 | + 1 => array('Database set in config.ini', 'No database in config.ini', ''), |
|
77 | + 2 => array('Database exists in Icingaweb2 config', 'Database does not exist in Icingaweb2 : ', |
|
78 | 78 | Url::fromPath('config/resource')), |
79 | - 3 => array('Database credentials OK','Database does not exist/invalid credentials/no schema : ', |
|
79 | + 3 => array('Database credentials OK', 'Database does not exist/invalid credentials/no schema : ', |
|
80 | 80 | Url::fromPath('trapdirector/settings/createschema')), |
81 | - 4 => array('Schema is set','Schema is not set for ', |
|
81 | + 4 => array('Schema is set', 'Schema is not set for ', |
|
82 | 82 | Url::fromPath('trapdirector/settings/createschema')), |
83 | - 5 => array('Schema is up to date','Schema is outdated :', |
|
83 | + 5 => array('Schema is up to date', 'Schema is outdated :', |
|
84 | 84 | Url::fromPath('trapdirector/settings/updateschema')), |
85 | 85 | ); |
86 | 86 | |
87 | 87 | try { |
88 | 88 | $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
89 | - $dberror=array(0,''); |
|
89 | + $dberror=array(0, ''); |
|
90 | 90 | } catch (DBException $e) { |
91 | - $dberror = $e->getArray(); |
|
91 | + $dberror=$e->getArray(); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | $this->view->db_error=$dberror[0]; |
@@ -96,13 +96,13 @@ discard block |
||
96 | 96 | { |
97 | 97 | case 2: |
98 | 98 | case 4: |
99 | - $db_message[$dberror[0]][1] .= $dberror[1]; |
|
99 | + $db_message[$dberror[0]][1].=$dberror[1]; |
|
100 | 100 | break; |
101 | 101 | case 3: |
102 | - $db_message[$dberror[0]][1] .= $dberror[1] . ', Message : ' . $dberror[2]; |
|
102 | + $db_message[$dberror[0]][1].=$dberror[1].', Message : '.$dberror[2]; |
|
103 | 103 | break; |
104 | 104 | case 5: |
105 | - $db_message[$dberror[0]][1] .= ' version '. $dberror[1] . ', version needed : ' .$dberror[2]; |
|
105 | + $db_message[$dberror[0]][1].=' version '.$dberror[1].', version needed : '.$dberror[2]; |
|
106 | 106 | break; |
107 | 107 | case 0: |
108 | 108 | case 1: |
@@ -114,14 +114,14 @@ discard block |
||
114 | 114 | |
115 | 115 | try { |
116 | 116 | $this->getUIDatabase()->testGetIdoDb(); // Get DB in test mode |
117 | - $dberror=array(0,''); |
|
117 | + $dberror=array(0, ''); |
|
118 | 118 | } catch (DBException $e) { |
119 | - $dberror = $e->getArray(); |
|
119 | + $dberror=$e->getArray(); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | $this->view->ido_db_error=$dberror[0]; |
123 | - $this->view->ido_message='IDO Database : ' . $dberror[1]; |
|
124 | - $this->view->ido_message .='<br />=> Default to API use. Make sure it is configured and check is returning OK!'; |
|
123 | + $this->view->ido_message='IDO Database : '.$dberror[1]; |
|
124 | + $this->view->ido_message.='<br />=> Default to API use. Make sure it is configured and check is returning OK!'; |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -133,13 +133,13 @@ discard block |
||
133 | 133 | { |
134 | 134 | if ($this->Config()->get('config', 'icingaAPI_host') != '') |
135 | 135 | { |
136 | - $apitest=new Icinga2API($this->Config()->get('config', 'icingaAPI_host'),$this->Config()->get('config', 'icingaAPI_port')); |
|
136 | + $apitest=new Icinga2API($this->Config()->get('config', 'icingaAPI_host'), $this->Config()->get('config', 'icingaAPI_port')); |
|
137 | 137 | $apitest->setCredentials($this->Config()->get('config', 'icingaAPI_user'), $this->Config()->get('config', 'icingaAPI_password')); |
138 | 138 | try { |
139 | - list($this->view->apimessageError,$this->view->apimessage)=$apitest->test($this->getModuleConfig()::getapiUserPermissions()); |
|
139 | + list($this->view->apimessageError, $this->view->apimessage)=$apitest->test($this->getModuleConfig()::getapiUserPermissions()); |
|
140 | 140 | //$this->view->apimessageError=false; |
141 | 141 | } catch (RuntimeException $e) { |
142 | - $this->view->apimessage='API config : ' . $e->getMessage(); |
|
142 | + $this->view->apimessage='API config : '.$e->getMessage(); |
|
143 | 143 | $this->view->apimessageError=true; |
144 | 144 | } |
145 | 145 | } |
@@ -164,10 +164,10 @@ discard block |
||
164 | 164 | { |
165 | 165 | $output=array(); |
166 | 166 | |
167 | - exec('cat ' . $this->module->getBaseDir() .'/bin/trap_in.php | grep "\$icingaweb2Etc=" ',$output); |
|
167 | + exec('cat '.$this->module->getBaseDir().'/bin/trap_in.php | grep "\$icingaweb2Etc=" ', $output); |
|
168 | 168 | |
169 | 169 | |
170 | - if (! isset($output[0]) || ! preg_match('#"'. $icingaweb2_etc .'"#',$output[0])) |
|
170 | + if (!isset($output[0]) || !preg_match('#"'.$icingaweb2_etc.'"#', $output[0])) |
|
171 | 171 | { |
172 | 172 | $this->view->icingaEtcWarn=1; |
173 | 173 | $this->view->icingaweb2_etc=$icingaweb2_etc; |
@@ -183,12 +183,12 @@ discard block |
||
183 | 183 | */ |
184 | 184 | private function get_db_list($allowed) |
185 | 185 | { |
186 | - $resources = array(); |
|
186 | + $resources=array(); |
|
187 | 187 | foreach (ResourceFactory::getResourceConfigs() as $name => $resource) |
188 | 188 | { |
189 | 189 | if ($resource->get('type') === 'db' && in_array($resource->get('db'), $allowed)) |
190 | 190 | { |
191 | - $resources[$name] = $name; |
|
191 | + $resources[$name]=$name; |
|
192 | 192 | } |
193 | 193 | } |
194 | 194 | return $resources; |
@@ -200,18 +200,18 @@ discard block |
||
200 | 200 | */ |
201 | 201 | private function get_php_binary() |
202 | 202 | { |
203 | - $phpBinary= array( PHP_BINARY, PHP_BINDIR . "/php", '/usr/bin/php'); |
|
203 | + $phpBinary=array(PHP_BINARY, PHP_BINDIR."/php", '/usr/bin/php'); |
|
204 | 204 | |
205 | - foreach ($phpBinary as $phpBin ) |
|
205 | + foreach ($phpBinary as $phpBin) |
|
206 | 206 | { |
207 | 207 | $output=array(); |
208 | 208 | $retCode=255; |
209 | 209 | $input="154865134987aaaa"; |
210 | - exec("$phpBin -r \"echo '$input';\"",$output,$retCode); |
|
210 | + exec("$phpBin -r \"echo '$input';\"", $output, $retCode); |
|
211 | 211 | |
212 | - if (! isset($output[0])) $output[0]="NO OUT"; |
|
212 | + if (!isset($output[0])) $output[0]="NO OUT"; |
|
213 | 213 | |
214 | - if ($retCode == 0 && preg_match("/$input/",$output[0]) == 1) |
|
214 | + if ($retCode == 0 && preg_match("/$input/", $output[0]) == 1) |
|
215 | 215 | { |
216 | 216 | return $phpBin; |
217 | 217 | } |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | // But check read permission |
241 | 241 | $this->checkReadPermission(); |
242 | 242 | |
243 | - $this->view->tabs = $this->Module()->getConfigTabs()->activate('config'); |
|
243 | + $this->view->tabs=$this->Module()->getConfigTabs()->activate('config'); |
|
244 | 244 | |
245 | 245 | // Get message : sent on configuration problems detected by controllers |
246 | 246 | $this->get_param(); |
@@ -255,39 +255,39 @@ discard block |
||
255 | 255 | $this->check_api(); |
256 | 256 | |
257 | 257 | //Test snmptrapd alive and options |
258 | - list ($this->view->snmptrapdError, $this->view->snmptrapdMessage) = $this->checkSnmpTrapd(); |
|
258 | + list ($this->view->snmptrapdError, $this->view->snmptrapdMessage)=$this->checkSnmpTrapd(); |
|
259 | 259 | |
260 | 260 | // List DB in $ressources |
261 | - $resources = $this->get_db_list(array('mysql', 'pgsql')); |
|
261 | + $resources=$this->get_db_list(array('mysql', 'pgsql')); |
|
262 | 262 | |
263 | 263 | // Check standard Icingaweb2 path |
264 | 264 | $this->check_icingaweb_path(); |
265 | 265 | |
266 | - $phpBinary = $this->get_php_binary(); |
|
266 | + $phpBinary=$this->get_php_binary(); |
|
267 | 267 | if ($phpBinary === null) |
268 | 268 | { |
269 | - $phpBinary = ' PHP BINARY NOT FOUND '; |
|
269 | + $phpBinary=' PHP BINARY NOT FOUND '; |
|
270 | 270 | |
271 | 271 | } |
272 | 272 | |
273 | 273 | // Setup path for mini documentation |
274 | - $this->view->traps_in_config= $phpBinary . ' ' . $this->Module()->getBaseDir() . '/bin/trap_in.php'; |
|
274 | + $this->view->traps_in_config=$phpBinary.' '.$this->Module()->getBaseDir().'/bin/trap_in.php'; |
|
275 | 275 | |
276 | - $this->view->installer= $this->Module()->getBaseDir() . '/bin/installer.sh ' |
|
276 | + $this->view->installer=$this->Module()->getBaseDir().'/bin/installer.sh ' |
|
277 | 277 | . ' -c all ' |
278 | - . ' -d ' . $this->Module()->getBaseDir() |
|
279 | - . ' -p ' . $phpBinary |
|
280 | - . ' -a ' . exec('whoami') |
|
281 | - . ' -w ' . Icinga::app()->getConfigDir(); |
|
278 | + . ' -d '.$this->Module()->getBaseDir() |
|
279 | + . ' -p '.$phpBinary |
|
280 | + . ' -a '.exec('whoami') |
|
281 | + . ' -w '.Icinga::app()->getConfigDir(); |
|
282 | 282 | |
283 | 283 | // ******************* configuration form setup******************* |
284 | - $this->view->form = $form = new TrapsConfigForm(); |
|
284 | + $this->view->form=$form=new TrapsConfigForm(); |
|
285 | 285 | |
286 | 286 | // set default paths; |
287 | - $this->view->form->setPaths($this->Module()->getBaseDir(),Icinga::app()->getConfigDir()); |
|
287 | + $this->view->form->setPaths($this->Module()->getBaseDir(), Icinga::app()->getConfigDir()); |
|
288 | 288 | |
289 | 289 | // set default ido database |
290 | - $this->view->form->setDefaultIDODB($this->Config()->module('monitoring','backends')->get('icinga','resource')); |
|
290 | + $this->view->form->setDefaultIDODB($this->Config()->module('monitoring', 'backends')->get('icinga', 'resource')); |
|
291 | 291 | |
292 | 292 | // Make form handle request. |
293 | 293 | $form->setIniConfig($this->Config()) |
@@ -316,18 +316,18 @@ discard block |
||
316 | 316 | $this->view->configPermission=$this->checkModuleConfigPermission(); |
317 | 317 | |
318 | 318 | // Setup tabs |
319 | - $this->view->tabs = $this->Module()->getConfigTabs()->activate('satellite'); |
|
319 | + $this->view->tabs=$this->Module()->getConfigTabs()->activate('satellite'); |
|
320 | 320 | |
321 | - $this->view->masterHASet = FALSE; |
|
321 | + $this->view->masterHASet=FALSE; |
|
322 | 322 | |
323 | - $this->view->masterHAConf = array ('name' => 'masterHA1', 'icingaweb2 user'=>'User1'); |
|
323 | + $this->view->masterHAConf=array('name' => 'masterHA1', 'icingaweb2 user'=>'User1'); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | |
327 | 327 | public function createschemaAction() |
328 | 328 | { |
329 | 329 | $this->checkModuleConfigPermission(); |
330 | - $this->getTabs()->add('create_schema',array( |
|
330 | + $this->getTabs()->add('create_schema', array( |
|
331 | 331 | 'active' => true, |
332 | 332 | 'label' => $this->translate('Create Schema'), |
333 | 333 | 'url' => Url::fromRequest() |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | // Get module database name |
349 | 349 | $dbName=$this->Config()->get('config', 'database'); |
350 | 350 | |
351 | - $dbResource = ResourceFactory::getResourceConfig($dbName); |
|
351 | + $dbResource=ResourceFactory::getResourceConfig($dbName); |
|
352 | 352 | $dbType=$dbResource->get('db'); |
353 | 353 | switch ($dbType) { |
354 | 354 | case 'mysql': |
@@ -363,28 +363,28 @@ discard block |
||
363 | 363 | } |
364 | 364 | |
365 | 365 | printf('<pre>'); |
366 | - require_once $this->Module()->getBaseDir() .'/bin/trap_class.php'; |
|
366 | + require_once $this->Module()->getBaseDir().'/bin/trap_class.php'; |
|
367 | 367 | |
368 | 368 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
369 | 369 | $debug_level=4; |
370 | - $Trap = new Trap($icingaweb2_etc); |
|
371 | - $Trap->setLogging($debug_level,'display'); |
|
370 | + $Trap=new Trap($icingaweb2_etc); |
|
371 | + $Trap->setLogging($debug_level, 'display'); |
|
372 | 372 | |
373 | 373 | $prefix=$this->Config()->get('config', 'database_prefix'); |
374 | 374 | // schema file : <path>/SQL/schema_v<verion>.<dbtype> |
375 | - $schema=$this->Module()->getBaseDir() . |
|
376 | - '/SQL/schema_v'. $this->getModuleConfig()->getDbCurVersion() . '.' . $dbFileExt; |
|
375 | + $schema=$this->Module()->getBaseDir(). |
|
376 | + '/SQL/schema_v'.$this->getModuleConfig()->getDbCurVersion().'.'.$dbFileExt; |
|
377 | 377 | |
378 | - $Trap->trapsDB->create_schema($schema,$prefix); |
|
378 | + $Trap->trapsDB->create_schema($schema, $prefix); |
|
379 | 379 | echo '</pre>'; |
380 | 380 | } |
381 | - echo '<br><br>Return to <a href="' . Url::fromPath('trapdirector/settings') .'" class="link-button icon-wrench"> settings page </a>'; |
|
381 | + echo '<br><br>Return to <a href="'.Url::fromPath('trapdirector/settings').'" class="link-button icon-wrench"> settings page </a>'; |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | public function updateschemaAction() |
385 | 385 | { |
386 | 386 | $this->checkModuleConfigPermission(); |
387 | - $this->getTabs()->add('get',array( |
|
387 | + $this->getTabs()->add('get', array( |
|
388 | 388 | 'active' => true, |
389 | 389 | 'label' => $this->translate('Update Schema'), |
390 | 390 | 'url' => Url::fromRequest() |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | $dberror=$e->getArray(); |
403 | 403 | } |
404 | 404 | |
405 | - echo 'Return to <a href="' . Url::fromPath('trapdirector/settings') .'" class="link-button icon-wrench"> settings page </a><br><br>'; |
|
405 | + echo 'Return to <a href="'.Url::fromPath('trapdirector/settings').'" class="link-button icon-wrench"> settings page </a><br><br>'; |
|
406 | 406 | |
407 | 407 | if ($dberror[0] != 5) |
408 | 408 | { |
@@ -410,40 +410,40 @@ discard block |
||
410 | 410 | return; |
411 | 411 | } |
412 | 412 | // setup |
413 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
413 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
414 | 414 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
415 | 415 | $debug_level=4; |
416 | - $Trap = new Trap($icingaweb2_etc); |
|
416 | + $Trap=new Trap($icingaweb2_etc); |
|
417 | 417 | |
418 | 418 | |
419 | 419 | $prefix=$this->Config()->get('config', 'database_prefix'); |
420 | - $updateSchema=$this->Module()->getBaseDir() . '/SQL/'; |
|
420 | + $updateSchema=$this->Module()->getBaseDir().'/SQL/'; |
|
421 | 421 | |
422 | 422 | $target_version=$dberror[2]; |
423 | 423 | |
424 | 424 | if ($this->params->get('msgok') == null) { |
425 | 425 | // Check for messages and display if any |
426 | 426 | echo "Upgrade databse is going to start.<br>Don't forget to backup your database before update<br>"; |
427 | - $Trap->setLogging(2,'syslog'); |
|
428 | - $message = $Trap->trapsDB->update_schema($updateSchema,$target_version,$prefix,true); |
|
427 | + $Trap->setLogging(2, 'syslog'); |
|
428 | + $message=$Trap->trapsDB->update_schema($updateSchema, $target_version, $prefix, true); |
|
429 | 429 | if ($message != '') |
430 | 430 | { |
431 | 431 | echo 'Note :<br><pre>'; |
432 | 432 | echo $message; |
433 | 433 | echo '</pre>'; |
434 | 434 | echo '<br>'; |
435 | - echo '<a class="link-button" style="font-size:large;font-weight:bold" href="' . Url::fromPath('trapdirector/settings/updateschema') .'?msgok=1">Click here to update</a>'; |
|
435 | + echo '<a class="link-button" style="font-size:large;font-weight:bold" href="'.Url::fromPath('trapdirector/settings/updateschema').'?msgok=1">Click here to update</a>'; |
|
436 | 436 | echo '<br>'; |
437 | 437 | return; |
438 | 438 | } |
439 | 439 | } |
440 | 440 | |
441 | - $Trap->setLogging($debug_level,'display'); |
|
441 | + $Trap->setLogging($debug_level, 'display'); |
|
442 | 442 | |
443 | - echo 'Updating schema to '. $target_version . ': <br>'; |
|
443 | + echo 'Updating schema to '.$target_version.': <br>'; |
|
444 | 444 | echo '<pre>'; |
445 | 445 | |
446 | - $Trap->trapsDB->update_schema($updateSchema,$target_version,$prefix); |
|
446 | + $Trap->trapsDB->update_schema($updateSchema, $target_version, $prefix); |
|
447 | 447 | echo '</pre>'; |
448 | 448 | } |
449 | 449 | |
@@ -452,50 +452,50 @@ discard block |
||
452 | 452 | { |
453 | 453 | $psOutput=array(); |
454 | 454 | // First check is someone is listening to port 162. As not root, we can't have pid... |
455 | - $sspath = exec('which ss 2>/dev/null'); |
|
456 | - if(empty($sspath)) |
|
455 | + $sspath=exec('which ss 2>/dev/null'); |
|
456 | + if (empty($sspath)) |
|
457 | 457 | { |
458 | 458 | // RHEL based systems |
459 | - $sspath = '/usr/sbin/ss'; |
|
459 | + $sspath='/usr/sbin/ss'; |
|
460 | 460 | } |
461 | - if(!is_executable("$sspath")) |
|
461 | + if (!is_executable("$sspath")) |
|
462 | 462 | { |
463 | - return array(1,"Can not execute $sspath"); |
|
463 | + return array(1, "Can not execute $sspath"); |
|
464 | 464 | } |
465 | - exec("$sspath -lun | grep ':162 '",$psOutput); |
|
465 | + exec("$sspath -lun | grep ':162 '", $psOutput); |
|
466 | 466 | if (count($psOutput) == 0) |
467 | 467 | { |
468 | - $extra = ""; |
|
469 | - if (is_file("/.dockerenv")){ $extra = '<br />=> ignore if Trapdirector is running in a different Docker container'; } |
|
470 | - return array(1,'Port UDP/162 is not open : is snmptrapd running?'. $extra); |
|
468 | + $extra=""; |
|
469 | + if (is_file("/.dockerenv")) { $extra='<br />=> ignore if Trapdirector is running in a different Docker container'; } |
|
470 | + return array(1, 'Port UDP/162 is not open : is snmptrapd running?'.$extra); |
|
471 | 471 | } |
472 | 472 | $psOutput=array(); |
473 | - $selinux_state = ''; |
|
474 | - if(is_executable('/usr/sbin/getenforce')) |
|
473 | + $selinux_state=''; |
|
474 | + if (is_executable('/usr/sbin/getenforce')) |
|
475 | 475 | { |
476 | - $selinux_state = exec('/usr/sbin/getenforce 2>/dev/null'); |
|
476 | + $selinux_state=exec('/usr/sbin/getenforce 2>/dev/null'); |
|
477 | 477 | } |
478 | - if($selinux_state !== 'Enforcing') |
|
478 | + if ($selinux_state !== 'Enforcing') |
|
479 | 479 | { |
480 | - exec('ps --no-headers -o command -C snmptrapd',$psOutput); |
|
480 | + exec('ps --no-headers -o command -C snmptrapd', $psOutput); |
|
481 | 481 | if (count($psOutput) == 0) |
482 | 482 | { |
483 | - return array(1,"UDP/162 : OK, but no snmptrapd process (?)"); |
|
483 | + return array(1, "UDP/162 : OK, but no snmptrapd process (?)"); |
|
484 | 484 | } |
485 | 485 | // Assume there is only one line... TODO : see if there is a better way to do this |
486 | - $line = preg_replace('/^.*snmptrapd /','',$psOutput[0]); |
|
487 | - if (!preg_match('/-n/',$line)) |
|
488 | - return array(1,'snmptrapd has no -n option : '.$line); |
|
489 | - if (!preg_match('/-O[^ ]*n/',$line)) |
|
490 | - return array(1,'snmptrapd has no -On option : '.$line); |
|
491 | - if (!preg_match('/-O[^ ]*e/',$line)) |
|
492 | - return array(1,'snmptrapd has no -Oe option : '.$line); |
|
486 | + $line=preg_replace('/^.*snmptrapd /', '', $psOutput[0]); |
|
487 | + if (!preg_match('/-n/', $line)) |
|
488 | + return array(1, 'snmptrapd has no -n option : '.$line); |
|
489 | + if (!preg_match('/-O[^ ]*n/', $line)) |
|
490 | + return array(1, 'snmptrapd has no -On option : '.$line); |
|
491 | + if (!preg_match('/-O[^ ]*e/', $line)) |
|
492 | + return array(1, 'snmptrapd has no -Oe option : '.$line); |
|
493 | 493 | |
494 | - return array(0,'snmptrapd listening to UDP/162, options : '.$line); |
|
494 | + return array(0, 'snmptrapd listening to UDP/162, options : '.$line); |
|
495 | 495 | } |
496 | 496 | else |
497 | 497 | { |
498 | - return array(0,'A daemon (hidden by SELinux) is listening on UDP/162'); |
|
498 | + return array(0, 'A daemon (hidden by SELinux) is listening on UDP/162'); |
|
499 | 499 | } |
500 | 500 | } |
501 | 501 | } |
@@ -11,28 +11,28 @@ discard block |
||
11 | 11 | class ApiController extends TrapsController |
12 | 12 | { |
13 | 13 | |
14 | - private $json_options=JSON_PRETTY_PRINT; |
|
14 | + private $json_options=JSON_PRETTY_PRINT; |
|
15 | 15 | |
16 | - protected function send_json($object) |
|
17 | - { |
|
18 | - if (isset($object['Error'])) |
|
19 | - { |
|
20 | - $this->send_json_error($object); |
|
21 | - return; |
|
22 | - } |
|
23 | - $this->_helper->layout()->disableLayout(); |
|
24 | - $this->getResponse()->setHeader('Content-Type', 'application/json', true); |
|
25 | - $this->getResponse()->sendHeaders(); |
|
26 | - echo json_encode($object, $this->json_options) . "\n"; |
|
27 | - } |
|
16 | + protected function send_json($object) |
|
17 | + { |
|
18 | + if (isset($object['Error'])) |
|
19 | + { |
|
20 | + $this->send_json_error($object); |
|
21 | + return; |
|
22 | + } |
|
23 | + $this->_helper->layout()->disableLayout(); |
|
24 | + $this->getResponse()->setHeader('Content-Type', 'application/json', true); |
|
25 | + $this->getResponse()->sendHeaders(); |
|
26 | + echo json_encode($object, $this->json_options) . "\n"; |
|
27 | + } |
|
28 | 28 | |
29 | - protected function send_json_error($object) |
|
30 | - { |
|
31 | - $this->_helper->layout()->disableLayout(); |
|
32 | - $this->getResponse()->setHeader('Content-Type', 'application/json', true); |
|
33 | - $this->getResponse()->sendHeaders(); |
|
34 | - echo json_encode($object, $this->json_options) . "\n"; |
|
35 | - } |
|
29 | + protected function send_json_error($object) |
|
30 | + { |
|
31 | + $this->_helper->layout()->disableLayout(); |
|
32 | + $this->getResponse()->setHeader('Content-Type', 'application/json', true); |
|
33 | + $this->getResponse()->sendHeaders(); |
|
34 | + echo json_encode($object, $this->json_options) . "\n"; |
|
35 | + } |
|
36 | 36 | |
37 | 37 | public function indexAction() |
38 | 38 | { |
@@ -47,18 +47,18 @@ discard block |
||
47 | 47 | |
48 | 48 | public function dboptionActions() |
49 | 49 | { |
50 | - $this->checkReadPermission(); |
|
51 | - $apiObj= new RestAPI($this); |
|
50 | + $this->checkReadPermission(); |
|
51 | + $apiObj= new RestAPI($this); |
|
52 | 52 | |
53 | - $params = $this->getRequest()->getParams(); |
|
54 | - if (isset($params['name'])) |
|
55 | - { |
|
53 | + $params = $this->getRequest()->getParams(); |
|
54 | + if (isset($params['name'])) |
|
55 | + { |
|
56 | 56 | |
57 | - } |
|
58 | - else |
|
59 | - { |
|
57 | + } |
|
58 | + else |
|
59 | + { |
|
60 | 60 | |
61 | - } |
|
61 | + } |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | } |
65 | 65 | \ No newline at end of file |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | $this->_helper->layout()->disableLayout(); |
24 | 24 | $this->getResponse()->setHeader('Content-Type', 'application/json', true); |
25 | 25 | $this->getResponse()->sendHeaders(); |
26 | - echo json_encode($object, $this->json_options) . "\n"; |
|
26 | + echo json_encode($object, $this->json_options)."\n"; |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | protected function send_json_error($object) |
@@ -31,15 +31,15 @@ discard block |
||
31 | 31 | $this->_helper->layout()->disableLayout(); |
32 | 32 | $this->getResponse()->setHeader('Content-Type', 'application/json', true); |
33 | 33 | $this->getResponse()->sendHeaders(); |
34 | - echo json_encode($object, $this->json_options) . "\n"; |
|
34 | + echo json_encode($object, $this->json_options)."\n"; |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | public function indexAction() |
38 | 38 | { |
39 | 39 | $this->checkReadPermission(); |
40 | - $apiObj= new RestAPI($this); |
|
40 | + $apiObj=new RestAPI($this); |
|
41 | 41 | |
42 | - $modif = $apiObj->last_modified(); |
|
42 | + $modif=$apiObj->last_modified(); |
|
43 | 43 | $this->send_json($modif); |
44 | 44 | //print_r($modif); |
45 | 45 | return; |
@@ -48,9 +48,9 @@ discard block |
||
48 | 48 | public function dboptionActions() |
49 | 49 | { |
50 | 50 | $this->checkReadPermission(); |
51 | - $apiObj= new RestAPI($this); |
|
51 | + $apiObj=new RestAPI($this); |
|
52 | 52 | |
53 | - $params = $this->getRequest()->getParams(); |
|
53 | + $params=$this->getRequest()->getParams(); |
|
54 | 54 | if (isset($params['name'])) |
55 | 55 | { |
56 | 56 |
@@ -54,8 +54,7 @@ |
||
54 | 54 | if (isset($params['name'])) |
55 | 55 | { |
56 | 56 | |
57 | - } |
|
58 | - else |
|
57 | + } else |
|
59 | 58 | { |
60 | 59 | |
61 | 60 | } |
@@ -17,93 +17,93 @@ |
||
17 | 17 | class TrapApi |
18 | 18 | { |
19 | 19 | |
20 | - // Constants |
|
21 | - public const MASTER=1; |
|
22 | - public const MASTERHA=2; |
|
23 | - public const SAT=3; |
|
24 | - public $stateArray = array('MASTER' => TrapApi::MASTER, 'MASTERHA' => TrapApi::MASTERHA , 'SAT' => TrapApi::SAT ); |
|
20 | + // Constants |
|
21 | + public const MASTER=1; |
|
22 | + public const MASTERHA=2; |
|
23 | + public const SAT=3; |
|
24 | + public $stateArray = array('MASTER' => TrapApi::MASTER, 'MASTERHA' => TrapApi::MASTERHA , 'SAT' => TrapApi::SAT ); |
|
25 | 25 | |
26 | - /** @var integer $whoami current server : MASTER MASTERHA or SAT */ |
|
27 | - public $whoami = TrapApi::MASTER; |
|
28 | - /** @var string $masterIP ip of master if MASTERHA or SAT */ |
|
29 | - public $masterIP=''; |
|
30 | - /** @var integer $masterPort port of master if MASTERHA or SAT */ |
|
31 | - public $masterPort=443; |
|
32 | - /** @var string $masterUser user to log in API */ |
|
33 | - public $masterUser=''; |
|
34 | - /** @var string $masterPass password */ |
|
35 | - public $masterPass=''; |
|
26 | + /** @var integer $whoami current server : MASTER MASTERHA or SAT */ |
|
27 | + public $whoami = TrapApi::MASTER; |
|
28 | + /** @var string $masterIP ip of master if MASTERHA or SAT */ |
|
29 | + public $masterIP=''; |
|
30 | + /** @var integer $masterPort port of master if MASTERHA or SAT */ |
|
31 | + public $masterPort=443; |
|
32 | + /** @var string $masterUser user to log in API */ |
|
33 | + public $masterUser=''; |
|
34 | + /** @var string $masterPass password */ |
|
35 | + public $masterPass=''; |
|
36 | 36 | |
37 | - /** @var Logging $logging logging class */ |
|
38 | - protected $logging; |
|
37 | + /** @var Logging $logging logging class */ |
|
38 | + protected $logging; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Create TrapApi class |
|
42 | - * @param Logging $logClass |
|
43 | - */ |
|
44 | - function __construct($logClass) |
|
45 | - { |
|
46 | - $this->logging=$logClass; |
|
47 | - } |
|
40 | + /** |
|
41 | + * Create TrapApi class |
|
42 | + * @param Logging $logClass |
|
43 | + */ |
|
44 | + function __construct($logClass) |
|
45 | + { |
|
46 | + $this->logging=$logClass; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Return true if ode is master. |
|
51 | - * @return boolean |
|
52 | - */ |
|
53 | - public function isMaster() |
|
54 | - { |
|
55 | - return ($this->whoami == MASTER); |
|
56 | - } |
|
49 | + /** |
|
50 | + * Return true if ode is master. |
|
51 | + * @return boolean |
|
52 | + */ |
|
53 | + public function isMaster() |
|
54 | + { |
|
55 | + return ($this->whoami == MASTER); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * return status of node |
|
60 | - * @return number |
|
61 | - */ |
|
62 | - public function getStatus() |
|
63 | - { |
|
64 | - return $this->whoami; |
|
65 | - } |
|
58 | + /** |
|
59 | + * return status of node |
|
60 | + * @return number |
|
61 | + */ |
|
62 | + public function getStatus() |
|
63 | + { |
|
64 | + return $this->whoami; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * Set status os node to $status |
|
69 | - * @param string $status |
|
70 | - * @return boolean : true if $status is correct, or false. |
|
71 | - */ |
|
72 | - public function setStatus(string $status) |
|
73 | - { |
|
74 | - if (! isset($this->stateArray[$status])) |
|
75 | - { |
|
76 | - return FALSE; |
|
77 | - } |
|
67 | + /** |
|
68 | + * Set status os node to $status |
|
69 | + * @param string $status |
|
70 | + * @return boolean : true if $status is correct, or false. |
|
71 | + */ |
|
72 | + public function setStatus(string $status) |
|
73 | + { |
|
74 | + if (! isset($this->stateArray[$status])) |
|
75 | + { |
|
76 | + return FALSE; |
|
77 | + } |
|
78 | 78 | |
79 | - $this->logging->log('Setting status to : ' . $status, INFO); |
|
79 | + $this->logging->log('Setting status to : ' . $status, INFO); |
|
80 | 80 | |
81 | - $this->whoami = $this->stateArray[$status]; |
|
81 | + $this->whoami = $this->stateArray[$status]; |
|
82 | 82 | |
83 | - return TRUE; |
|
84 | - } |
|
83 | + return TRUE; |
|
84 | + } |
|
85 | 85 | |
86 | - public function setStatusMaster() |
|
87 | - { |
|
88 | - $this->whoami = TrapApi::MASTER; |
|
89 | - } |
|
86 | + public function setStatusMaster() |
|
87 | + { |
|
88 | + $this->whoami = TrapApi::MASTER; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * Set params for API connection |
|
93 | - * @param string $IP |
|
94 | - * @param int $port |
|
95 | - * @param string $user |
|
96 | - * @param string $pass |
|
97 | - * @return boolean true if params are OK |
|
98 | - */ |
|
99 | - public function setParams(string $IP, int $port, string $user, string $pass) |
|
100 | - { |
|
101 | - $this->masterIP = $IP; |
|
102 | - $this->masterPort = $port; |
|
103 | - $this->masterUser = $user; |
|
104 | - $this->masterPass = $pass; |
|
91 | + /** |
|
92 | + * Set params for API connection |
|
93 | + * @param string $IP |
|
94 | + * @param int $port |
|
95 | + * @param string $user |
|
96 | + * @param string $pass |
|
97 | + * @return boolean true if params are OK |
|
98 | + */ |
|
99 | + public function setParams(string $IP, int $port, string $user, string $pass) |
|
100 | + { |
|
101 | + $this->masterIP = $IP; |
|
102 | + $this->masterPort = $port; |
|
103 | + $this->masterUser = $user; |
|
104 | + $this->masterPass = $pass; |
|
105 | 105 | |
106 | - return true; |
|
107 | - } |
|
106 | + return true; |
|
107 | + } |
|
108 | 108 | |
109 | 109 | } |
110 | 110 | \ No newline at end of file |
@@ -21,10 +21,10 @@ discard block |
||
21 | 21 | public const MASTER=1; |
22 | 22 | public const MASTERHA=2; |
23 | 23 | public const SAT=3; |
24 | - public $stateArray = array('MASTER' => TrapApi::MASTER, 'MASTERHA' => TrapApi::MASTERHA , 'SAT' => TrapApi::SAT ); |
|
24 | + public $stateArray=array('MASTER' => TrapApi::MASTER, 'MASTERHA' => TrapApi::MASTERHA, 'SAT' => TrapApi::SAT); |
|
25 | 25 | |
26 | 26 | /** @var integer $whoami current server : MASTER MASTERHA or SAT */ |
27 | - public $whoami = TrapApi::MASTER; |
|
27 | + public $whoami=TrapApi::MASTER; |
|
28 | 28 | /** @var string $masterIP ip of master if MASTERHA or SAT */ |
29 | 29 | public $masterIP=''; |
30 | 30 | /** @var integer $masterPort port of master if MASTERHA or SAT */ |
@@ -71,21 +71,21 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function setStatus(string $status) |
73 | 73 | { |
74 | - if (! isset($this->stateArray[$status])) |
|
74 | + if (!isset($this->stateArray[$status])) |
|
75 | 75 | { |
76 | 76 | return FALSE; |
77 | 77 | } |
78 | 78 | |
79 | - $this->logging->log('Setting status to : ' . $status, INFO); |
|
79 | + $this->logging->log('Setting status to : '.$status, INFO); |
|
80 | 80 | |
81 | - $this->whoami = $this->stateArray[$status]; |
|
81 | + $this->whoami=$this->stateArray[$status]; |
|
82 | 82 | |
83 | 83 | return TRUE; |
84 | 84 | } |
85 | 85 | |
86 | 86 | public function setStatusMaster() |
87 | 87 | { |
88 | - $this->whoami = TrapApi::MASTER; |
|
88 | + $this->whoami=TrapApi::MASTER; |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -98,10 +98,10 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function setParams(string $IP, int $port, string $user, string $pass) |
100 | 100 | { |
101 | - $this->masterIP = $IP; |
|
102 | - $this->masterPort = $port; |
|
103 | - $this->masterUser = $user; |
|
104 | - $this->masterPass = $pass; |
|
101 | + $this->masterIP=$IP; |
|
102 | + $this->masterPort=$port; |
|
103 | + $this->masterUser=$user; |
|
104 | + $this->masterPass=$pass; |
|
105 | 105 | |
106 | 106 | return true; |
107 | 107 | } |
@@ -14,43 +14,43 @@ |
||
14 | 14 | |
15 | 15 | class RestAPI |
16 | 16 | { |
17 | - public $version=1; |
|
17 | + public $version=1; |
|
18 | 18 | |
19 | - /** |
|
20 | - * @var TrapsController $trapController |
|
21 | - */ |
|
22 | - protected $trapController=null; |
|
19 | + /** |
|
20 | + * @var TrapsController $trapController |
|
21 | + */ |
|
22 | + protected $trapController=null; |
|
23 | 23 | |
24 | - public function __construct(TrapsController $trapCtrl) |
|
25 | - { |
|
26 | - $this->trapController=$trapCtrl; |
|
27 | - } |
|
24 | + public function __construct(TrapsController $trapCtrl) |
|
25 | + { |
|
26 | + $this->trapController=$trapCtrl; |
|
27 | + } |
|
28 | 28 | |
29 | - public function sendJson($object) |
|
30 | - { |
|
31 | - $this->trapController->getResponse()->setHeader('Content-Type', 'application/json', true); |
|
32 | - $this->trapController->getResponse()->sendHeaders(); |
|
33 | - $this->trapController->helper_ret(json_encode($object, JSON_PRETTY_PRINT)); |
|
34 | - //$this->trapController->_helper->json($object); |
|
35 | - //echo json_encode($object, JSON_PRETTY_PRINT) . "\n"; |
|
36 | - } |
|
29 | + public function sendJson($object) |
|
30 | + { |
|
31 | + $this->trapController->getResponse()->setHeader('Content-Type', 'application/json', true); |
|
32 | + $this->trapController->getResponse()->sendHeaders(); |
|
33 | + $this->trapController->helper_ret(json_encode($object, JSON_PRETTY_PRINT)); |
|
34 | + //$this->trapController->_helper->json($object); |
|
35 | + //echo json_encode($object, JSON_PRETTY_PRINT) . "\n"; |
|
36 | + } |
|
37 | 37 | |
38 | - protected function sendJsonError(string $error, int $retCode = 200) |
|
39 | - { |
|
40 | - //TODO |
|
41 | - $this->sendJson('{"Error":"'.$error.'"}'); |
|
42 | - } |
|
38 | + protected function sendJsonError(string $error, int $retCode = 200) |
|
39 | + { |
|
40 | + //TODO |
|
41 | + $this->sendJson('{"Error":"'.$error.'"}'); |
|
42 | + } |
|
43 | 43 | |
44 | - public function last_modified() |
|
45 | - { |
|
46 | - try |
|
47 | - { |
|
48 | - $query = $this->trapController->getUIDatabase()->lastModification(); |
|
49 | - return array('lastModified' => $query); |
|
50 | - } |
|
51 | - catch (\ErrorException $e) |
|
52 | - { |
|
53 | - return array('Error' => $e->getMessage()); |
|
54 | - } |
|
55 | - } |
|
44 | + public function last_modified() |
|
45 | + { |
|
46 | + try |
|
47 | + { |
|
48 | + $query = $this->trapController->getUIDatabase()->lastModification(); |
|
49 | + return array('lastModified' => $query); |
|
50 | + } |
|
51 | + catch (\ErrorException $e) |
|
52 | + { |
|
53 | + return array('Error' => $e->getMessage()); |
|
54 | + } |
|
55 | + } |
|
56 | 56 | } |
57 | 57 | \ No newline at end of file |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | //echo json_encode($object, JSON_PRETTY_PRINT) . "\n"; |
36 | 36 | } |
37 | 37 | |
38 | - protected function sendJsonError(string $error, int $retCode = 200) |
|
38 | + protected function sendJsonError(string $error, int $retCode=200) |
|
39 | 39 | { |
40 | 40 | //TODO |
41 | 41 | $this->sendJson('{"Error":"'.$error.'"}'); |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | { |
46 | 46 | try |
47 | 47 | { |
48 | - $query = $this->trapController->getUIDatabase()->lastModification(); |
|
48 | + $query=$this->trapController->getUIDatabase()->lastModification(); |
|
49 | 49 | return array('lastModified' => $query); |
50 | 50 | } |
51 | 51 | catch (\ErrorException $e) |
@@ -47,8 +47,7 @@ |
||
47 | 47 | { |
48 | 48 | $query = $this->trapController->getUIDatabase()->lastModification(); |
49 | 49 | return array('lastModified' => $query); |
50 | - } |
|
51 | - catch (\ErrorException $e) |
|
50 | + } catch (\ErrorException $e) |
|
52 | 51 | { |
53 | 52 | return array('Error' => $e->getMessage()); |
54 | 53 | } |
@@ -212,7 +212,9 @@ discard block |
||
212 | 212 | $first=1; |
213 | 213 | foreach($this->moduleConfig->getTrapListSearchColumns() as $column) |
214 | 214 | { |
215 | - if ($first==0) $sql.=' OR '; |
|
215 | + if ($first==0) { |
|
216 | + $sql.=' OR '; |
|
217 | + } |
|
216 | 218 | $first=0; |
217 | 219 | $sql.=" CAST(".$column." AS char(100)) LIKE '%".$this->filter_query."%' "; |
218 | 220 | } |
@@ -220,10 +222,14 @@ discard block |
||
220 | 222 | } |
221 | 223 | if ($this->filter_done == 1) |
222 | 224 | { |
223 | - if ($sql != '') $sql.=' AND '; |
|
225 | + if ($sql != '') { |
|
226 | + $sql.=' AND '; |
|
227 | + } |
|
224 | 228 | $sql.="(status != 'done')"; |
225 | 229 | } |
226 | - if ($sql != '') $query->where($sql); |
|
230 | + if ($sql != '') { |
|
231 | + $query->where($sql); |
|
232 | + } |
|
227 | 233 | return $query; |
228 | 234 | } |
229 | 235 |
@@ -19,9 +19,9 @@ discard block |
||
19 | 19 | |
20 | 20 | // Filters |
21 | 21 | |
22 | - protected $filter; |
|
23 | - protected $enforcedFilters = array(); |
|
24 | - protected $searchColumns = array(); |
|
22 | + protected $filter; |
|
23 | + protected $enforcedFilters = array(); |
|
24 | + protected $searchColumns = array(); |
|
25 | 25 | |
26 | 26 | protected function getTitles() { |
27 | 27 | // TODO : check moduleconfig is set |
@@ -29,10 +29,10 @@ discard block |
||
29 | 29 | } |
30 | 30 | |
31 | 31 | // ****************** Render table in html |
32 | - public function __toString() |
|
33 | - { |
|
34 | - return $this->render(); |
|
35 | - } |
|
32 | + public function __toString() |
|
33 | + { |
|
34 | + return $this->render(); |
|
35 | + } |
|
36 | 36 | |
37 | 37 | public function render() |
38 | 38 | { |
@@ -96,26 +96,26 @@ discard block |
||
96 | 96 | |
97 | 97 | } |
98 | 98 | |
99 | - public function count() |
|
100 | - { |
|
101 | - $db=$this->db(); |
|
99 | + public function count() |
|
100 | + { |
|
101 | + $db=$this->db(); |
|
102 | 102 | |
103 | 103 | $query = $db->select()->from( |
104 | - $this->moduleConfig->getTrapTableName(), |
|
105 | - array('COUNT(*)') |
|
106 | - ); |
|
104 | + $this->moduleConfig->getTrapTableName(), |
|
105 | + array('COUNT(*)') |
|
106 | + ); |
|
107 | 107 | $this->applyFiltersToQuery($query); |
108 | 108 | |
109 | - return $db->fetchOne($query); |
|
110 | - } |
|
109 | + return $db->fetchOne($query); |
|
110 | + } |
|
111 | 111 | |
112 | - public function getPaginator() |
|
113 | - { |
|
114 | - $paginator = new Paginator(); |
|
115 | - $paginator->setQuery($this); |
|
112 | + public function getPaginator() |
|
113 | + { |
|
114 | + $paginator = new Paginator(); |
|
115 | + $paginator->setQuery($this); |
|
116 | 116 | |
117 | - return $paginator; |
|
118 | - } |
|
117 | + return $paginator; |
|
118 | + } |
|
119 | 119 | |
120 | 120 | // ****************** DB connection and query |
121 | 121 | |
@@ -125,24 +125,24 @@ discard block |
||
125 | 125 | |
126 | 126 | $query = $this->getBaseQuery(); |
127 | 127 | $this->applyFiltersToQuery($query); |
128 | - if ($this->hasLimit() || $this->hasOffset()) { |
|
129 | - $query->limit($this->getLimit(), $this->getOffset()); |
|
130 | - } |
|
128 | + if ($this->hasLimit() || $this->hasOffset()) { |
|
129 | + $query->limit($this->getLimit(), $this->getOffset()); |
|
130 | + } |
|
131 | 131 | |
132 | 132 | return $db->fetchAll($query); |
133 | 133 | } |
134 | 134 | |
135 | - public function getBaseQuery() |
|
136 | - { |
|
135 | + public function getBaseQuery() |
|
136 | + { |
|
137 | 137 | $db=$this->db(); |
138 | 138 | |
139 | 139 | $query = $db->select()->from( |
140 | - $this->moduleConfig->getTrapTableName(), |
|
141 | - $this->moduleConfig->getTrapListDisplayColumns() |
|
142 | - )->order('timestamp DESC'); |
|
140 | + $this->moduleConfig->getTrapTableName(), |
|
141 | + $this->moduleConfig->getTrapListDisplayColumns() |
|
142 | + )->order('timestamp DESC'); |
|
143 | 143 | |
144 | - return $query; |
|
145 | - } |
|
144 | + return $query; |
|
145 | + } |
|
146 | 146 | |
147 | 147 | // ****************** Filters |
148 | 148 | |
@@ -172,39 +172,39 @@ discard block |
||
172 | 172 | $this->filter_done=(isset($filter['done']))?$this->filter_done=$filter['done']:0; |
173 | 173 | } |
174 | 174 | |
175 | - protected function getSearchColumns() |
|
176 | - { |
|
177 | - return $this->getColumns(); |
|
178 | - } |
|
175 | + protected function getSearchColumns() |
|
176 | + { |
|
177 | + return $this->getColumns(); |
|
178 | + } |
|
179 | 179 | |
180 | 180 | public function getColumns() |
181 | 181 | { |
182 | 182 | return $this->moduleConfig->getTrapListDisplayColumns(); |
183 | 183 | } |
184 | 184 | |
185 | - public function setFilter($filter) |
|
186 | - { |
|
187 | - $this->filter = $filter; |
|
188 | - return $this; |
|
189 | - } |
|
185 | + public function setFilter($filter) |
|
186 | + { |
|
187 | + $this->filter = $filter; |
|
188 | + return $this; |
|
189 | + } |
|
190 | 190 | |
191 | 191 | public function getFilterEditor(Request $request) |
192 | - { |
|
193 | - $filterEditor = Widget::create('filterEditor') |
|
194 | - ->setColumns(array_keys($this->getColumns())) |
|
195 | - ->setSearchColumns(array_keys($this->getSearchColumns())) |
|
196 | - ->preserveParams('limit', 'sort', 'dir', 'view', 'backend') |
|
197 | - ->ignoreParams('page') |
|
198 | - ->handleRequest($request); |
|
192 | + { |
|
193 | + $filterEditor = Widget::create('filterEditor') |
|
194 | + ->setColumns(array_keys($this->getColumns())) |
|
195 | + ->setSearchColumns(array_keys($this->getSearchColumns())) |
|
196 | + ->preserveParams('limit', 'sort', 'dir', 'view', 'backend') |
|
197 | + ->ignoreParams('page') |
|
198 | + ->handleRequest($request); |
|
199 | 199 | |
200 | - $filter = $filterEditor->getFilter(); |
|
201 | - $this->setFilter($filter); |
|
200 | + $filter = $filterEditor->getFilter(); |
|
201 | + $this->setFilter($filter); |
|
202 | 202 | |
203 | - return $filterEditor; |
|
204 | - } |
|
203 | + return $filterEditor; |
|
204 | + } |
|
205 | 205 | |
206 | - protected function applyFiltersToQuery($query) |
|
207 | - { |
|
206 | + protected function applyFiltersToQuery($query) |
|
207 | + { |
|
208 | 208 | |
209 | 209 | $sql=''; |
210 | 210 | if ($this->filter_query != '') |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | $sql.="(status != 'done')"; |
226 | 226 | } |
227 | 227 | if ($sql != '') $query->where($sql); |
228 | - return $query; |
|
229 | - } |
|
228 | + return $query; |
|
229 | + } |
|
230 | 230 | |
231 | 231 | } |
@@ -20,8 +20,8 @@ discard block |
||
20 | 20 | // Filters |
21 | 21 | |
22 | 22 | protected $filter; |
23 | - protected $enforcedFilters = array(); |
|
24 | - protected $searchColumns = array(); |
|
23 | + protected $enforcedFilters=array(); |
|
24 | + protected $searchColumns=array(); |
|
25 | 25 | |
26 | 26 | protected function getTitles() { |
27 | 27 | // TODO : check moduleconfig is set |
@@ -37,60 +37,60 @@ discard block |
||
37 | 37 | public function render() |
38 | 38 | { |
39 | 39 | $data=$this->getTable(); |
40 | - $view = $this->getView(); |
|
41 | - $this->columnCount = count($this->getTitles()); |
|
40 | + $view=$this->getView(); |
|
41 | + $this->columnCount=count($this->getTitles()); |
|
42 | 42 | $this->lastDay=null; |
43 | 43 | // Table start |
44 | - $htm = '<table class="simple common-table table-row-selectable">'; |
|
44 | + $htm='<table class="simple common-table table-row-selectable">'; |
|
45 | 45 | |
46 | 46 | // Titles |
47 | - $htm .= "<thead>\n <tr>\n"; |
|
48 | - $titles = $this->getTitles(); |
|
47 | + $htm.="<thead>\n <tr>\n"; |
|
48 | + $titles=$this->getTitles(); |
|
49 | 49 | foreach ($titles as $title) |
50 | 50 | { |
51 | - $htm .= ' <th>' . $view->escape($view->translate($title)) . "</th>\n"; |
|
51 | + $htm.=' <th>'.$view->escape($view->translate($title))."</th>\n"; |
|
52 | 52 | } |
53 | - $htm .= " </tr>\n</thead>\n"; |
|
53 | + $htm.=" </tr>\n</thead>\n"; |
|
54 | 54 | |
55 | 55 | // Rows |
56 | - $htm .= "<tbody>\n"; |
|
56 | + $htm.="<tbody>\n"; |
|
57 | 57 | |
58 | 58 | foreach ($data as $row) |
59 | 59 | { |
60 | - $firstCol = true; |
|
60 | + $firstCol=true; |
|
61 | 61 | // Put date header |
62 | - $htm .= $this->renderDayIfNew($row->timestamp); |
|
62 | + $htm.=$this->renderDayIfNew($row->timestamp); |
|
63 | 63 | |
64 | 64 | |
65 | 65 | // Render row |
66 | - $htm .= '<tr>'; |
|
67 | - foreach ( $titles as $rowkey => $title) |
|
66 | + $htm.='<tr>'; |
|
67 | + foreach ($titles as $rowkey => $title) |
|
68 | 68 | { |
69 | 69 | // Check missing value |
70 | 70 | if (property_exists($row, $rowkey)) |
71 | 71 | { |
72 | - $val = ($rowkey=='timestamp') ? DateFormatter::formatTime($row->$rowkey) : $row->$rowkey; |
|
72 | + $val=($rowkey == 'timestamp') ? DateFormatter::formatTime($row->$rowkey) : $row->$rowkey; |
|
73 | 73 | } else { |
74 | - $val = '-'; |
|
74 | + $val='-'; |
|
75 | 75 | } |
76 | 76 | if ($firstCol == true) { // Put link in first column for trap detail. |
77 | - $htm .= '<td>' |
|
77 | + $htm.='<td>' |
|
78 | 78 | . $view->qlink( |
79 | 79 | $view->escape($val), |
80 | 80 | Url::fromPath( |
81 | - $this->moduleConfig->urlPath() . '/received/trapdetail', |
|
81 | + $this->moduleConfig->urlPath().'/received/trapdetail', |
|
82 | 82 | array('id' => $row->id) |
83 | 83 | ) |
84 | 84 | ) |
85 | 85 | . '</td>'; |
86 | 86 | } else { |
87 | - $htm .= '<td>' . $view->escape($val) . '</td>'; |
|
87 | + $htm.='<td>'.$view->escape($val).'</td>'; |
|
88 | 88 | } |
89 | 89 | $firstCol=false; |
90 | 90 | } |
91 | - $htm .= "<tr>\n"; |
|
91 | + $htm.="<tr>\n"; |
|
92 | 92 | } |
93 | - $htm .= "</tbody></table>\n"; |
|
93 | + $htm.="</tbody></table>\n"; |
|
94 | 94 | //$htm .= "Filter : " . $this->filter."<br>\n"; |
95 | 95 | return $htm; |
96 | 96 | |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | { |
101 | 101 | $db=$this->db(); |
102 | 102 | |
103 | - $query = $db->select()->from( |
|
103 | + $query=$db->select()->from( |
|
104 | 104 | $this->moduleConfig->getTrapTableName(), |
105 | 105 | array('COUNT(*)') |
106 | 106 | ); |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | |
112 | 112 | public function getPaginator() |
113 | 113 | { |
114 | - $paginator = new Paginator(); |
|
114 | + $paginator=new Paginator(); |
|
115 | 115 | $paginator->setQuery($this); |
116 | 116 | |
117 | 117 | return $paginator; |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | { |
124 | 124 | $db=$this->db(); |
125 | 125 | |
126 | - $query = $this->getBaseQuery(); |
|
126 | + $query=$this->getBaseQuery(); |
|
127 | 127 | $this->applyFiltersToQuery($query); |
128 | 128 | if ($this->hasLimit() || $this->hasOffset()) { |
129 | 129 | $query->limit($this->getLimit(), $this->getOffset()); |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | { |
137 | 137 | $db=$this->db(); |
138 | 138 | |
139 | - $query = $db->select()->from( |
|
139 | + $query=$db->select()->from( |
|
140 | 140 | $this->moduleConfig->getTrapTableName(), |
141 | 141 | $this->moduleConfig->getTrapListDisplayColumns() |
142 | 142 | )->order('timestamp DESC'); |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | protected $filter_Handler; |
150 | 150 | protected $filter_query=''; |
151 | 151 | protected $filter_done=''; |
152 | - protected $filter_query_list=array('q','done'); |
|
152 | + protected $filter_query_list=array('q', 'done'); |
|
153 | 153 | public function renderFilterHTML() |
154 | 154 | { |
155 | 155 | $htm=' <form id="filter" name="mainFilter" |
@@ -159,17 +159,17 @@ discard block |
||
159 | 159 | $htm.='<input type="text" name="q" title="Search is simple! Try to combine multiple words" |
160 | 160 | placeholder="Search..." class="search" value="'.$this->filter_query.'">'; |
161 | 161 | $htm.='<input type="checkbox" id="checkbox_done" name="done" value="1" class="autosubmit" '; |
162 | - if ($this->filter_done == 1) { $htm.=' checked ';} |
|
162 | + if ($this->filter_done == 1) { $htm.=' checked '; } |
|
163 | 163 | $htm.='> <label for="checkbox_done">Hide processed traps</label>'; |
164 | 164 | $htm.='</form>'; |
165 | 165 | return $htm; |
166 | 166 | } |
167 | 167 | |
168 | - public function updateFilter($handler,$filter) |
|
168 | + public function updateFilter($handler, $filter) |
|
169 | 169 | { |
170 | 170 | $this->filter_Handler=$handler->remove($this->filter_query_list)->__toString(); |
171 | - $this->filter_query=(isset($filter['q']))?$this->filter_query=$filter['q']:''; |
|
172 | - $this->filter_done=(isset($filter['done']))?$this->filter_done=$filter['done']:0; |
|
171 | + $this->filter_query=(isset($filter['q'])) ? $this->filter_query=$filter['q'] : ''; |
|
172 | + $this->filter_done=(isset($filter['done'])) ? $this->filter_done=$filter['done'] : 0; |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | protected function getSearchColumns() |
@@ -184,20 +184,20 @@ discard block |
||
184 | 184 | |
185 | 185 | public function setFilter($filter) |
186 | 186 | { |
187 | - $this->filter = $filter; |
|
187 | + $this->filter=$filter; |
|
188 | 188 | return $this; |
189 | 189 | } |
190 | 190 | |
191 | 191 | public function getFilterEditor(Request $request) |
192 | 192 | { |
193 | - $filterEditor = Widget::create('filterEditor') |
|
193 | + $filterEditor=Widget::create('filterEditor') |
|
194 | 194 | ->setColumns(array_keys($this->getColumns())) |
195 | 195 | ->setSearchColumns(array_keys($this->getSearchColumns())) |
196 | 196 | ->preserveParams('limit', 'sort', 'dir', 'view', 'backend') |
197 | 197 | ->ignoreParams('page') |
198 | 198 | ->handleRequest($request); |
199 | 199 | |
200 | - $filter = $filterEditor->getFilter(); |
|
200 | + $filter=$filterEditor->getFilter(); |
|
201 | 201 | $this->setFilter($filter); |
202 | 202 | |
203 | 203 | return $filterEditor; |
@@ -211,9 +211,9 @@ discard block |
||
211 | 211 | { |
212 | 212 | $sql.='('; |
213 | 213 | $first=1; |
214 | - foreach($this->moduleConfig->getTrapListSearchColumns() as $column) |
|
214 | + foreach ($this->moduleConfig->getTrapListSearchColumns() as $column) |
|
215 | 215 | { |
216 | - if ($first==0) $sql.=' OR '; |
|
216 | + if ($first == 0) $sql.=' OR '; |
|
217 | 217 | $first=0; |
218 | 218 | $sql.=" CAST(".$column." AS char(100)) LIKE '%".$this->filter_query."%' "; |
219 | 219 | } |
@@ -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 | } |
@@ -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( string $value) |
|
30 | + public function groupingPrintData(string $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 |
@@ -7,136 +7,136 @@ |
||
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( string $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( string $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 | - } |
|
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 | + } |
|
57 | 57 | |
58 | - public function getCurrentURL() |
|
59 | - { |
|
60 | - return Url::fromPath($this->urlPath . '/handler'); |
|
61 | - } |
|
58 | + public function getCurrentURL() |
|
59 | + { |
|
60 | + return Url::fromPath($this->urlPath . '/handler'); |
|
61 | + } |
|
62 | 62 | |
63 | - public function renderLine($row) |
|
64 | - { |
|
65 | - $html = ''; |
|
66 | - $firstCol = true; |
|
63 | + public function renderLine($row) |
|
64 | + { |
|
65 | + $html = ''; |
|
66 | + $firstCol = true; |
|
67 | 67 | |
68 | - $titleNames = array_keys($this->titles); |
|
69 | - foreach ($titleNames as $rowkey ) |
|
70 | - { |
|
71 | - // Check missing value |
|
72 | - if (property_exists($row, $rowkey)) |
|
73 | - { |
|
74 | - switch ($rowkey) |
|
75 | - { |
|
76 | - case 'action_match': // display text levels |
|
77 | - case 'action_nomatch': |
|
78 | - $val=$this->status_display[$row->$rowkey]; |
|
79 | - break; |
|
80 | - case 'trap_oid': // try to traslate oids. |
|
68 | + $titleNames = array_keys($this->titles); |
|
69 | + foreach ($titleNames as $rowkey ) |
|
70 | + { |
|
71 | + // Check missing value |
|
72 | + if (property_exists($row, $rowkey)) |
|
73 | + { |
|
74 | + switch ($rowkey) |
|
75 | + { |
|
76 | + case 'action_match': // display text levels |
|
77 | + case 'action_nomatch': |
|
78 | + $val=$this->status_display[$row->$rowkey]; |
|
79 | + break; |
|
80 | + case 'trap_oid': // try to traslate oids. |
|
81 | 81 | |
82 | - if ($this->doTranslate === true) |
|
83 | - { |
|
84 | - $oidName = $this->MIB->translateOID($row->$rowkey); |
|
85 | - if (isset($oidName['name'])) |
|
86 | - { |
|
87 | - $val=$oidName['name']; |
|
88 | - } |
|
89 | - else |
|
90 | - { |
|
91 | - $val = $row->$rowkey; |
|
92 | - } |
|
93 | - } |
|
94 | - else |
|
95 | - { |
|
96 | - $val = $row->$rowkey; |
|
97 | - } |
|
98 | - break; |
|
99 | - case 'host_name': // switch to hostgroup if name is null |
|
100 | - if ($row->$rowkey == null) |
|
101 | - { |
|
102 | - $val = $row->host_group_name; |
|
103 | - } |
|
104 | - else |
|
105 | - { |
|
106 | - $val = $row->$rowkey; |
|
107 | - } |
|
108 | - break; |
|
109 | - default: |
|
110 | - $val = $row->$rowkey; |
|
111 | - } |
|
112 | - if ($rowkey == 'trap_oid' && $this->doTranslate===true) |
|
113 | - { |
|
82 | + if ($this->doTranslate === true) |
|
83 | + { |
|
84 | + $oidName = $this->MIB->translateOID($row->$rowkey); |
|
85 | + if (isset($oidName['name'])) |
|
86 | + { |
|
87 | + $val=$oidName['name']; |
|
88 | + } |
|
89 | + else |
|
90 | + { |
|
91 | + $val = $row->$rowkey; |
|
92 | + } |
|
93 | + } |
|
94 | + else |
|
95 | + { |
|
96 | + $val = $row->$rowkey; |
|
97 | + } |
|
98 | + break; |
|
99 | + case 'host_name': // switch to hostgroup if name is null |
|
100 | + if ($row->$rowkey == null) |
|
101 | + { |
|
102 | + $val = $row->host_group_name; |
|
103 | + } |
|
104 | + else |
|
105 | + { |
|
106 | + $val = $row->$rowkey; |
|
107 | + } |
|
108 | + break; |
|
109 | + default: |
|
110 | + $val = $row->$rowkey; |
|
111 | + } |
|
112 | + if ($rowkey == 'trap_oid' && $this->doTranslate===true) |
|
113 | + { |
|
114 | 114 | |
115 | - } |
|
116 | - } else { |
|
117 | - $val = '-'; |
|
118 | - } |
|
119 | - if ($firstCol === true) { // Put link in first column for trap detail. |
|
120 | - $html .= '<td class="traphover">' |
|
121 | - . $this->view->qlink( |
|
122 | - $this->view->escape($val), |
|
123 | - Url::fromPath( |
|
124 | - $this->urlPath . '/handler/add', |
|
125 | - array('ruleid' => $row->id) |
|
126 | - ) |
|
127 | - ); |
|
128 | - if ($row->comment != '') |
|
129 | - { |
|
130 | - $html.= '<span class="tohover">'. $row->comment .'</span></td>'; |
|
131 | - } |
|
132 | - $html.= '</td>'; |
|
133 | - } else { |
|
134 | - $html .= '<td>' . $this->view->escape($val) . '</td>'; |
|
135 | - } |
|
136 | - $firstCol=false; |
|
115 | + } |
|
116 | + } else { |
|
117 | + $val = '-'; |
|
118 | + } |
|
119 | + if ($firstCol === true) { // Put link in first column for trap detail. |
|
120 | + $html .= '<td class="traphover">' |
|
121 | + . $this->view->qlink( |
|
122 | + $this->view->escape($val), |
|
123 | + Url::fromPath( |
|
124 | + $this->urlPath . '/handler/add', |
|
125 | + array('ruleid' => $row->id) |
|
126 | + ) |
|
127 | + ); |
|
128 | + if ($row->comment != '') |
|
129 | + { |
|
130 | + $html.= '<span class="tohover">'. $row->comment .'</span></td>'; |
|
131 | + } |
|
132 | + $html.= '</td>'; |
|
133 | + } else { |
|
134 | + $html .= '<td>' . $this->view->escape($val) . '</td>'; |
|
135 | + } |
|
136 | + $firstCol=false; |
|
137 | 137 | |
138 | - } |
|
139 | - return $html; |
|
140 | - } |
|
138 | + } |
|
139 | + return $html; |
|
140 | + } |
|
141 | 141 | |
142 | 142 | } |
143 | 143 | \ No newline at end of file |
@@ -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(), |
@@ -8,10 +8,10 @@ discard block |
||
8 | 8 | |
9 | 9 | /********* Filter ********/ |
10 | 10 | /** @var string $filterString : string filter for db columns */ |
11 | - protected $filterString = ''; |
|
11 | + protected $filterString=''; |
|
12 | 12 | |
13 | 13 | /** @var array $filterColumn : columns to apply filter to */ |
14 | - protected $filterColumn = array(); |
|
14 | + protected $filterColumn=array(); |
|
15 | 15 | |
16 | 16 | protected $filterQuery=''; |
17 | 17 | |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | { |
30 | 30 | if ($filter != "") $filter.=' OR '; |
31 | 31 | //$filter .= "'" . $column . "' LIKE '%" . $this->filterString. "%'"; |
32 | - $filter .= $column . " LIKE '%" . $this->filterString. "%'"; |
|
32 | + $filter.=$column." LIKE '%".$this->filterString."%'"; |
|
33 | 33 | } |
34 | 34 | //echo $filter; |
35 | 35 | |
@@ -40,8 +40,8 @@ discard block |
||
40 | 40 | |
41 | 41 | public function setFilter(string $filter, array $filterCol) |
42 | 42 | { |
43 | - $this->filterString = $filter; |
|
44 | - $this->filterColumn = $filterCol; |
|
43 | + $this->filterString=$filter; |
|
44 | + $this->filterColumn=$filterCol; |
|
45 | 45 | return $this; |
46 | 46 | } |
47 | 47 | |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | { |
64 | 64 | if (isset($getVars['f'])) |
65 | 65 | { |
66 | - $this->filterQuery = $getVars['f']; |
|
66 | + $this->filterQuery=$getVars['f']; |
|
67 | 67 | $this->setFilter(html_entity_decode($getVars['f']), $this->columnNames); |
68 | 68 | } |
69 | 69 | } |
@@ -27,7 +27,9 @@ discard block |
||
27 | 27 | $filter=''; |
28 | 28 | foreach ($this->filterColumn as $column) |
29 | 29 | { |
30 | - if ($filter != "") $filter.=' OR '; |
|
30 | + if ($filter != "") { |
|
31 | + $filter.=' OR '; |
|
32 | + } |
|
31 | 33 | //$filter .= "'" . $column . "' LIKE '%" . $this->filterString. "%'"; |
32 | 34 | $filter .= $column . " LIKE '%" . $this->filterString. "%'"; |
33 | 35 | } |
@@ -70,7 +72,9 @@ discard block |
||
70 | 72 | |
71 | 73 | protected function curFilterQuery() |
72 | 74 | { |
73 | - if ($this->filterQuery == '') return ''; |
|
75 | + if ($this->filterQuery == '') { |
|
76 | + return ''; |
|
77 | + } |
|
74 | 78 | return 'f='.$this->filterQuery; |
75 | 79 | } |
76 | 80 |
@@ -6,75 +6,75 @@ |
||
6 | 6 | trait TrapDirectorTableFilter |
7 | 7 | { |
8 | 8 | |
9 | - /********* Filter ********/ |
|
10 | - /** @var string $filterString : string filter for db columns */ |
|
11 | - protected $filterString = ''; |
|
9 | + /********* Filter ********/ |
|
10 | + /** @var string $filterString : string filter for db columns */ |
|
11 | + protected $filterString = ''; |
|
12 | 12 | |
13 | - /** @var array $filterColumn : columns to apply filter to */ |
|
14 | - protected $filterColumn = array(); |
|
13 | + /** @var array $filterColumn : columns to apply filter to */ |
|
14 | + protected $filterColumn = array(); |
|
15 | 15 | |
16 | - protected $filterQuery=''; |
|
16 | + protected $filterQuery=''; |
|
17 | 17 | |
18 | - /**** var & func of TrapDirectorTable used ***/ |
|
19 | - protected $query; |
|
20 | - abstract protected function getCurrentURLAndQS(string $caller); |
|
18 | + /**** var & func of TrapDirectorTable used ***/ |
|
19 | + protected $query; |
|
20 | + abstract protected function getCurrentURLAndQS(string $caller); |
|
21 | 21 | |
22 | - /**************** Filtering ******************/ |
|
22 | + /**************** Filtering ******************/ |
|
23 | 23 | |
24 | - public function applyFilter() |
|
25 | - { |
|
26 | - if ($this->filterString == '' || count($this->filterColumn) == 0) |
|
27 | - { |
|
28 | - return $this; |
|
29 | - } |
|
30 | - $filter=''; |
|
31 | - foreach ($this->filterColumn as $column) |
|
32 | - { |
|
33 | - if ($filter != "") $filter.=' OR '; |
|
34 | - //$filter .= "'" . $column . "' LIKE '%" . $this->filterString. "%'"; |
|
35 | - $filter .= $column . " LIKE '%" . $this->filterString. "%'"; |
|
36 | - } |
|
37 | - //echo $filter; |
|
24 | + public function applyFilter() |
|
25 | + { |
|
26 | + if ($this->filterString == '' || count($this->filterColumn) == 0) |
|
27 | + { |
|
28 | + return $this; |
|
29 | + } |
|
30 | + $filter=''; |
|
31 | + foreach ($this->filterColumn as $column) |
|
32 | + { |
|
33 | + if ($filter != "") $filter.=' OR '; |
|
34 | + //$filter .= "'" . $column . "' LIKE '%" . $this->filterString. "%'"; |
|
35 | + $filter .= $column . " LIKE '%" . $this->filterString. "%'"; |
|
36 | + } |
|
37 | + //echo $filter; |
|
38 | 38 | |
39 | - $this->query=$this->query->where($filter); |
|
39 | + $this->query=$this->query->where($filter); |
|
40 | 40 | |
41 | - return $this; |
|
42 | - } |
|
41 | + return $this; |
|
42 | + } |
|
43 | 43 | |
44 | - public function setFilter(string $filter, array $filterCol) |
|
45 | - { |
|
46 | - $this->filterString = $filter; |
|
47 | - $this->filterColumn = $filterCol; |
|
48 | - return $this; |
|
49 | - } |
|
44 | + public function setFilter(string $filter, array $filterCol) |
|
45 | + { |
|
46 | + $this->filterString = $filter; |
|
47 | + $this->filterColumn = $filterCol; |
|
48 | + return $this; |
|
49 | + } |
|
50 | 50 | |
51 | - public function renderFilter() |
|
52 | - { |
|
51 | + public function renderFilter() |
|
52 | + { |
|
53 | 53 | |
54 | - $html=' <form id="genfilter" name="mainFilterGen" |
|
54 | + $html=' <form id="genfilter" name="mainFilterGen" |
|
55 | 55 | enctype="application/x-www-form-urlencoded" |
56 | 56 | action="'.$this->getCurrentURLAndQS('filter').'" |
57 | 57 | method="get">'; |
58 | - $html.='<input type="text" name="f" title="Search is simple! Try to combine multiple words" |
|
58 | + $html.='<input type="text" name="f" title="Search is simple! Try to combine multiple words" |
|
59 | 59 | placeholder="Search..." value="'.$this->filterQuery.'">'; |
60 | 60 | |
61 | - $html.='</form>'; |
|
62 | - return $html; |
|
63 | - } |
|
61 | + $html.='</form>'; |
|
62 | + return $html; |
|
63 | + } |
|
64 | 64 | |
65 | - public function getFilterQuery(array $getVars) |
|
66 | - { |
|
67 | - if (isset($getVars['f'])) |
|
68 | - { |
|
69 | - $this->filterQuery = $getVars['f']; |
|
70 | - $this->setFilter(html_entity_decode($getVars['f']), $this->columnNames); |
|
71 | - } |
|
72 | - } |
|
65 | + public function getFilterQuery(array $getVars) |
|
66 | + { |
|
67 | + if (isset($getVars['f'])) |
|
68 | + { |
|
69 | + $this->filterQuery = $getVars['f']; |
|
70 | + $this->setFilter(html_entity_decode($getVars['f']), $this->columnNames); |
|
71 | + } |
|
72 | + } |
|
73 | 73 | |
74 | - protected function curFilterQuery() |
|
75 | - { |
|
76 | - if ($this->filterQuery == '') return ''; |
|
77 | - return 'f='.$this->filterQuery; |
|
78 | - } |
|
74 | + protected function curFilterQuery() |
|
75 | + { |
|
76 | + if ($this->filterQuery == '') return ''; |
|
77 | + return 'f='.$this->filterQuery; |
|
78 | + } |
|
79 | 79 | |
80 | 80 | } |
81 | 81 | \ No newline at end of file |