@@ -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,56 +71,56 @@ discard block |
||
71 | 71 | */ |
72 | 72 | private function check_db() |
73 | 73 | { |
74 | - $db_message=array( // index => ( message OK, message NOK, optional link if NOK ) |
|
75 | - 0 => array('Database configuration OK','',''), |
|
76 | - 1 => array('Database set in config.ini','No database in config.ini',''), |
|
77 | - 2 => array('Database exists in Icingaweb2 config','Database does not exist in Icingaweb2 : ', |
|
78 | - Url::fromPath('config/resource')), |
|
79 | - 3 => array('Database credentials OK','Database does not exist/invalid credentials/no schema : ', |
|
80 | - Url::fromPath('trapdirector/settings/createschema')), |
|
81 | - 4 => array('Schema is set','Schema is not set for ', |
|
82 | - Url::fromPath('trapdirector/settings/createschema')), |
|
83 | - 5 => array('Schema is up to date','Schema is outdated :', |
|
84 | - Url::fromPath('trapdirector/settings/updateschema')), |
|
85 | - ); |
|
74 | + $db_message=array( // index => ( message OK, message NOK, optional link if NOK ) |
|
75 | + 0 => array('Database configuration OK','',''), |
|
76 | + 1 => array('Database set in config.ini','No database in config.ini',''), |
|
77 | + 2 => array('Database exists in Icingaweb2 config','Database does not exist in Icingaweb2 : ', |
|
78 | + Url::fromPath('config/resource')), |
|
79 | + 3 => array('Database credentials OK','Database does not exist/invalid credentials/no schema : ', |
|
80 | + Url::fromPath('trapdirector/settings/createschema')), |
|
81 | + 4 => array('Schema is set','Schema is not set for ', |
|
82 | + Url::fromPath('trapdirector/settings/createschema')), |
|
83 | + 5 => array('Schema is up to date','Schema is outdated :', |
|
84 | + Url::fromPath('trapdirector/settings/updateschema')), |
|
85 | + ); |
|
86 | 86 | |
87 | - try { |
|
88 | - $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
|
89 | - $dberror=array(0,''); |
|
90 | - } catch (DBException $e) { |
|
91 | - $dberror = $e->getArray(); |
|
92 | - } |
|
87 | + try { |
|
88 | + $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
|
89 | + $dberror=array(0,''); |
|
90 | + } catch (DBException $e) { |
|
91 | + $dberror = $e->getArray(); |
|
92 | + } |
|
93 | 93 | |
94 | - $this->view->db_error=$dberror[0]; |
|
95 | - switch ($dberror[0]) |
|
96 | - { |
|
97 | - case 2: |
|
98 | - case 4: |
|
99 | - $db_message[$dberror[0]][1] .= $dberror[1]; |
|
100 | - break; |
|
101 | - case 3: |
|
102 | - $db_message[$dberror[0]][1] .= $dberror[1] . ', Message : ' . $dberror[2]; |
|
103 | - break; |
|
104 | - case 5: |
|
105 | - $db_message[$dberror[0]][1] .= ' version '. $dberror[1] . ', version needed : ' .$dberror[2]; |
|
106 | - break; |
|
107 | - case 0: |
|
108 | - case 1: |
|
109 | - break; |
|
110 | - default: |
|
111 | - new ProgrammingError('Out of bond result from database test'); |
|
112 | - } |
|
113 | - $this->view->message=$db_message; |
|
94 | + $this->view->db_error=$dberror[0]; |
|
95 | + switch ($dberror[0]) |
|
96 | + { |
|
97 | + case 2: |
|
98 | + case 4: |
|
99 | + $db_message[$dberror[0]][1] .= $dberror[1]; |
|
100 | + break; |
|
101 | + case 3: |
|
102 | + $db_message[$dberror[0]][1] .= $dberror[1] . ', Message : ' . $dberror[2]; |
|
103 | + break; |
|
104 | + case 5: |
|
105 | + $db_message[$dberror[0]][1] .= ' version '. $dberror[1] . ', version needed : ' .$dberror[2]; |
|
106 | + break; |
|
107 | + case 0: |
|
108 | + case 1: |
|
109 | + break; |
|
110 | + default: |
|
111 | + new ProgrammingError('Out of bond result from database test'); |
|
112 | + } |
|
113 | + $this->view->message=$db_message; |
|
114 | 114 | |
115 | - try { |
|
116 | - $this->getUIDatabase()->testGetIdoDb(); // Get DB in test mode |
|
117 | - $dberror=array(0,''); |
|
118 | - } catch (DBException $e) { |
|
119 | - $dberror = $e->getArray(); |
|
120 | - } |
|
115 | + try { |
|
116 | + $this->getUIDatabase()->testGetIdoDb(); // Get DB in test mode |
|
117 | + $dberror=array(0,''); |
|
118 | + } catch (DBException $e) { |
|
119 | + $dberror = $e->getArray(); |
|
120 | + } |
|
121 | 121 | |
122 | - $this->view->ido_db_error=$dberror[0]; |
|
123 | - $this->view->ido_message='IDO Database : ' . $dberror[1]; |
|
122 | + $this->view->ido_db_error=$dberror[0]; |
|
123 | + $this->view->ido_message='IDO Database : ' . $dberror[1]; |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -130,23 +130,23 @@ discard block |
||
130 | 130 | */ |
131 | 131 | private function check_api() |
132 | 132 | { |
133 | - if ($this->Config()->get('config', 'icingaAPI_host') != '') |
|
134 | - { |
|
135 | - $apitest=new Icinga2Api($this->Config()->get('config', 'icingaAPI_host'),$this->Config()->get('config', 'icingaAPI_port')); |
|
136 | - $apitest->setCredentials($this->Config()->get('config', 'icingaAPI_user'), $this->Config()->get('config', 'icingaAPI_password')); |
|
137 | - try { |
|
138 | - list($this->view->apimessageError,$this->view->apimessage)=$apitest->test($this->getModuleConfig()::getapiUserPermissions()); |
|
139 | - //$this->view->apimessageError=false; |
|
140 | - } catch (RuntimeException $e) { |
|
141 | - $this->view->apimessage='API config : ' . $e->getMessage(); |
|
142 | - $this->view->apimessageError=true; |
|
143 | - } |
|
144 | - } |
|
145 | - else |
|
146 | - { |
|
147 | - $this->view->apimessage='API parameters not configured'; |
|
148 | - $this->view->apimessageError=true; |
|
149 | - } |
|
133 | + if ($this->Config()->get('config', 'icingaAPI_host') != '') |
|
134 | + { |
|
135 | + $apitest=new Icinga2Api($this->Config()->get('config', 'icingaAPI_host'),$this->Config()->get('config', 'icingaAPI_port')); |
|
136 | + $apitest->setCredentials($this->Config()->get('config', 'icingaAPI_user'), $this->Config()->get('config', 'icingaAPI_password')); |
|
137 | + try { |
|
138 | + list($this->view->apimessageError,$this->view->apimessage)=$apitest->test($this->getModuleConfig()::getapiUserPermissions()); |
|
139 | + //$this->view->apimessageError=false; |
|
140 | + } catch (RuntimeException $e) { |
|
141 | + $this->view->apimessage='API config : ' . $e->getMessage(); |
|
142 | + $this->view->apimessageError=true; |
|
143 | + } |
|
144 | + } |
|
145 | + else |
|
146 | + { |
|
147 | + $this->view->apimessage='API parameters not configured'; |
|
148 | + $this->view->apimessageError=true; |
|
149 | + } |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | /** |
@@ -157,21 +157,21 @@ discard block |
||
157 | 157 | */ |
158 | 158 | private function check_icingaweb_path() |
159 | 159 | { |
160 | - $this->view->icingaEtcWarn=0; |
|
161 | - $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
162 | - if ($icingaweb2_etc != "/etc/icingaweb2/" && $icingaweb2_etc != '') |
|
163 | - { |
|
164 | - $output=array(); |
|
160 | + $this->view->icingaEtcWarn=0; |
|
161 | + $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
162 | + if ($icingaweb2_etc != "/etc/icingaweb2/" && $icingaweb2_etc != '') |
|
163 | + { |
|
164 | + $output=array(); |
|
165 | 165 | |
166 | - exec('cat ' . $this->module->getBaseDir() .'/bin/trap_in.php | grep "\$icingaweb2Etc=" ',$output); |
|
166 | + exec('cat ' . $this->module->getBaseDir() .'/bin/trap_in.php | grep "\$icingaweb2Etc=" ',$output); |
|
167 | 167 | |
168 | 168 | |
169 | - if (! isset($output[0]) || ! preg_match('#"'. $icingaweb2_etc .'"#',$output[0])) |
|
170 | - { |
|
171 | - $this->view->icingaEtcWarn=1; |
|
172 | - $this->view->icingaweb2_etc=$icingaweb2_etc; |
|
173 | - } |
|
174 | - } |
|
169 | + if (! isset($output[0]) || ! preg_match('#"'. $icingaweb2_etc .'"#',$output[0])) |
|
170 | + { |
|
171 | + $this->view->icingaEtcWarn=1; |
|
172 | + $this->view->icingaweb2_etc=$icingaweb2_etc; |
|
173 | + } |
|
174 | + } |
|
175 | 175 | |
176 | 176 | } |
177 | 177 | |
@@ -182,15 +182,15 @@ discard block |
||
182 | 182 | */ |
183 | 183 | private function get_db_list($allowed) |
184 | 184 | { |
185 | - $resources = array(); |
|
186 | - foreach (ResourceFactory::getResourceConfigs() as $name => $resource) |
|
187 | - { |
|
188 | - if ($resource->get('type') === 'db' && in_array($resource->get('db'), $allowed)) |
|
189 | - { |
|
190 | - $resources[$name] = $name; |
|
191 | - } |
|
192 | - } |
|
193 | - return $resources; |
|
185 | + $resources = array(); |
|
186 | + foreach (ResourceFactory::getResourceConfigs() as $name => $resource) |
|
187 | + { |
|
188 | + if ($resource->get('type') === 'db' && in_array($resource->get('db'), $allowed)) |
|
189 | + { |
|
190 | + $resources[$name] = $name; |
|
191 | + } |
|
192 | + } |
|
193 | + return $resources; |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
@@ -199,23 +199,23 @@ discard block |
||
199 | 199 | */ |
200 | 200 | private function get_php_binary() |
201 | 201 | { |
202 | - $phpBinary= array( PHP_BINARY, PHP_BINDIR . "/php", '/usr/bin/php'); |
|
202 | + $phpBinary= array( PHP_BINARY, PHP_BINDIR . "/php", '/usr/bin/php'); |
|
203 | 203 | |
204 | - foreach ($phpBinary as $phpBin ) |
|
205 | - { |
|
206 | - $output=array(); |
|
207 | - $retCode=255; |
|
208 | - $input="154865134987aaaa"; |
|
209 | - exec("$phpBin -r \"echo '$input';\"",$output,$retCode); |
|
204 | + foreach ($phpBinary as $phpBin ) |
|
205 | + { |
|
206 | + $output=array(); |
|
207 | + $retCode=255; |
|
208 | + $input="154865134987aaaa"; |
|
209 | + exec("$phpBin -r \"echo '$input';\"",$output,$retCode); |
|
210 | 210 | |
211 | - if (! isset($output[0])) $output[0]="NO OUT"; |
|
211 | + if (! isset($output[0])) $output[0]="NO OUT"; |
|
212 | 212 | |
213 | - if ($retCode == 0 && preg_match("/$input/",$output[0]) == 1) |
|
214 | - { |
|
215 | - return $phpBin; |
|
216 | - } |
|
217 | - } |
|
218 | - return NULL; |
|
213 | + if ($retCode == 0 && preg_match("/$input/",$output[0]) == 1) |
|
214 | + { |
|
215 | + return $phpBin; |
|
216 | + } |
|
217 | + } |
|
218 | + return NULL; |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | public function indexAction() |
235 | 235 | { |
236 | 236 | |
237 | - // CHeck permissions : display tests in any case, but no configuration. |
|
237 | + // CHeck permissions : display tests in any case, but no configuration. |
|
238 | 238 | $this->view->configPermission=$this->checkModuleConfigPermission(1); |
239 | 239 | // But check read permission |
240 | 240 | $this->checkReadPermission(); |
@@ -242,16 +242,16 @@ discard block |
||
242 | 242 | $this->view->tabs = $this->Module()->getConfigTabs()->activate('config'); |
243 | 243 | |
244 | 244 | // Get message : sent on configuration problems detected by controllers |
245 | - $this->get_param(); |
|
245 | + $this->get_param(); |
|
246 | 246 | |
247 | - // Test if configuration exists, if not create for installer script |
|
247 | + // Test if configuration exists, if not create for installer script |
|
248 | 248 | $this->check_empty_config(); |
249 | 249 | |
250 | 250 | // Test Database |
251 | - $this->check_db(); |
|
251 | + $this->check_db(); |
|
252 | 252 | |
253 | 253 | //********* Test API |
254 | - $this->check_api(); |
|
254 | + $this->check_api(); |
|
255 | 255 | |
256 | 256 | //*********** Test snmptrapd alive and options |
257 | 257 | list ($this->view->snmptrapdError, $this->view->snmptrapdMessage) = $this->checkSnmpTrapd(); |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | $phpBinary = $this->get_php_binary(); |
266 | 266 | if ($phpBinary == null) |
267 | 267 | { |
268 | - $phpBinary = ' PHP BINARY NOT FOUND '; |
|
268 | + $phpBinary = ' PHP BINARY NOT FOUND '; |
|
269 | 269 | |
270 | 270 | } |
271 | 271 | |
@@ -273,11 +273,11 @@ discard block |
||
273 | 273 | $this->view->traps_in_config= $phpBinary . ' ' . $this->Module()->getBaseDir() . '/bin/trap_in.php'; |
274 | 274 | |
275 | 275 | $this->view->installer= $this->Module()->getBaseDir() . '/bin/installer.sh ' |
276 | - . ' -c all ' |
|
277 | - . ' -d ' . $this->Module()->getBaseDir() |
|
278 | - . ' -p ' . $phpBinary |
|
279 | - . ' -a ' . exec('whoami') |
|
280 | - . ' -w ' . Icinga::app()->getConfigDir(); |
|
276 | + . ' -c all ' |
|
277 | + . ' -d ' . $this->Module()->getBaseDir() |
|
278 | + . ' -p ' . $phpBinary |
|
279 | + . ' -a ' . exec('whoami') |
|
280 | + . ' -w ' . Icinga::app()->getConfigDir(); |
|
281 | 281 | |
282 | 282 | // ******************* configuration form setup******************* |
283 | 283 | $this->view->form = $form = new TrapsConfigForm(); |
@@ -307,8 +307,8 @@ discard block |
||
307 | 307 | |
308 | 308 | try |
309 | 309 | { |
310 | - $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
|
311 | - printf('Schema already exists'); |
|
310 | + $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
|
311 | + printf('Schema already exists'); |
|
312 | 312 | |
313 | 313 | } |
314 | 314 | catch (DBException $e) |
@@ -319,19 +319,19 @@ discard block |
||
319 | 319 | // Get module database name |
320 | 320 | $dbName=$this->Config()->get('config', 'database'); |
321 | 321 | |
322 | - $dbResource = ResourceFactory::getResourceConfig($dbName); |
|
323 | - $dbType=$dbResource->get('db'); |
|
324 | - switch ($dbType) { |
|
325 | - case 'mysql': |
|
326 | - $dbFileExt='sql'; |
|
327 | - break; |
|
328 | - case 'pgsql': |
|
329 | - $dbFileExt='pgsql'; |
|
330 | - break; |
|
331 | - default: |
|
332 | - printf("Database configuration error : Unsuported DB"); |
|
333 | - return; |
|
334 | - } |
|
322 | + $dbResource = ResourceFactory::getResourceConfig($dbName); |
|
323 | + $dbType=$dbResource->get('db'); |
|
324 | + switch ($dbType) { |
|
325 | + case 'mysql': |
|
326 | + $dbFileExt='sql'; |
|
327 | + break; |
|
328 | + case 'pgsql': |
|
329 | + $dbFileExt='pgsql'; |
|
330 | + break; |
|
331 | + default: |
|
332 | + printf("Database configuration error : Unsuported DB"); |
|
333 | + return; |
|
334 | + } |
|
335 | 335 | |
336 | 336 | printf('<pre>'); |
337 | 337 | require_once $this->Module()->getBaseDir() .'/bin/trap_class.php'; |
@@ -355,32 +355,32 @@ discard block |
||
355 | 355 | public function updateschemaAction() |
356 | 356 | { |
357 | 357 | $this->checkModuleConfigPermission(); |
358 | - $this->getTabs()->add('get',array( |
|
359 | - 'active' => true, |
|
360 | - 'label' => $this->translate('Update Schema'), |
|
361 | - 'url' => Url::fromRequest() |
|
362 | - )); |
|
358 | + $this->getTabs()->add('get',array( |
|
359 | + 'active' => true, |
|
360 | + 'label' => $this->translate('Update Schema'), |
|
361 | + 'url' => Url::fromRequest() |
|
362 | + )); |
|
363 | 363 | // check if needed |
364 | 364 | $dberror=array(); |
365 | - try |
|
366 | - { |
|
367 | - $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
|
368 | - echo 'Schema already exists and is up to date<br>'; |
|
369 | - return; |
|
370 | - } |
|
371 | - catch (DBException $e) |
|
372 | - { |
|
373 | - $dberror=$e->getArray(); |
|
374 | - } |
|
365 | + try |
|
366 | + { |
|
367 | + $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
|
368 | + echo 'Schema already exists and is up to date<br>'; |
|
369 | + return; |
|
370 | + } |
|
371 | + catch (DBException $e) |
|
372 | + { |
|
373 | + $dberror=$e->getArray(); |
|
374 | + } |
|
375 | 375 | |
376 | 376 | echo 'Return to <a href="' . Url::fromPath('trapdirector/settings') .'" class="link-button icon-wrench"> settings page </a><br><br>'; |
377 | 377 | |
378 | 378 | if ($dberror[0] != 5) |
379 | 379 | { |
380 | - echo 'Database does not exists or is not setup correctly<br>'; |
|
381 | - return; |
|
380 | + echo 'Database does not exists or is not setup correctly<br>'; |
|
381 | + return; |
|
382 | 382 | } |
383 | - // setup |
|
383 | + // setup |
|
384 | 384 | require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
385 | 385 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
386 | 386 | $debug_level=4; |
@@ -393,20 +393,20 @@ discard block |
||
393 | 393 | $target_version=$dberror[2]; |
394 | 394 | |
395 | 395 | if ($this->params->get('msgok') == null) { |
396 | - // Check for messages and display if any |
|
397 | - echo "Upgrade databse is going to start.<br>Don't forget to backup your database before update<br>"; |
|
398 | - $Trap->setLogging(2,'syslog'); |
|
399 | - $message = $Trap->trapsDB->update_schema($updateSchema,$target_version,$prefix,true); |
|
400 | - if ($message != '') |
|
401 | - { |
|
402 | - echo 'Note :<br><pre>'; |
|
403 | - echo $message; |
|
404 | - echo '</pre>'; |
|
405 | - echo '<br>'; |
|
406 | - 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>'; |
|
407 | - echo '<br>'; |
|
408 | - return; |
|
409 | - } |
|
396 | + // Check for messages and display if any |
|
397 | + echo "Upgrade databse is going to start.<br>Don't forget to backup your database before update<br>"; |
|
398 | + $Trap->setLogging(2,'syslog'); |
|
399 | + $message = $Trap->trapsDB->update_schema($updateSchema,$target_version,$prefix,true); |
|
400 | + if ($message != '') |
|
401 | + { |
|
402 | + echo 'Note :<br><pre>'; |
|
403 | + echo $message; |
|
404 | + echo '</pre>'; |
|
405 | + echo '<br>'; |
|
406 | + 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>'; |
|
407 | + echo '<br>'; |
|
408 | + return; |
|
409 | + } |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | $Trap->setLogging($debug_level,'display'); |
@@ -420,50 +420,50 @@ discard block |
||
420 | 420 | |
421 | 421 | private function checkSnmpTrapd() |
422 | 422 | { |
423 | - $psOutput=array(); |
|
424 | - // First check is someone is listening to port 162. As not root, we can't have pid... |
|
425 | - $sspath = exec('which ss 2>/dev/null'); |
|
426 | - if(empty($sspath)) |
|
427 | - { |
|
428 | - // RHEL based systems |
|
429 | - $sspath = '/usr/sbin/ss'; |
|
430 | - } |
|
431 | - if(!is_executable("$sspath")) |
|
432 | - { |
|
433 | - return array(1,"Can not execute $sspath"); |
|
434 | - } |
|
435 | - exec("$sspath -lun | grep ':162 '",$psOutput); |
|
436 | - if (count($psOutput) == 0) |
|
437 | - { |
|
438 | - return array(1,'Port UDP/162 is not open : is snmptrapd running?'); |
|
439 | - } |
|
440 | - $psOutput=array(); |
|
441 | - $selinux_state = ''; |
|
442 | - if(is_executable('/usr/sbin/getenforce')) |
|
443 | - { |
|
444 | - $selinux_state = exec('/usr/sbin/getenforce 2>/dev/null'); |
|
445 | - } |
|
446 | - if($selinux_state !== 'Enforcing') |
|
447 | - { |
|
448 | - exec('ps --no-headers -o command -C snmptrapd',$psOutput); |
|
449 | - if (count($psOutput) == 0) |
|
450 | - { |
|
451 | - return array(1,"UDP/162 : OK, but no snmptrapd process (?)"); |
|
452 | - } |
|
453 | - // Assume there is only one line... TODO : see if there is a better way to do this |
|
454 | - $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); |
|
423 | + $psOutput=array(); |
|
424 | + // First check is someone is listening to port 162. As not root, we can't have pid... |
|
425 | + $sspath = exec('which ss 2>/dev/null'); |
|
426 | + if(empty($sspath)) |
|
427 | + { |
|
428 | + // RHEL based systems |
|
429 | + $sspath = '/usr/sbin/ss'; |
|
430 | + } |
|
431 | + if(!is_executable("$sspath")) |
|
432 | + { |
|
433 | + return array(1,"Can not execute $sspath"); |
|
434 | + } |
|
435 | + exec("$sspath -lun | grep ':162 '",$psOutput); |
|
436 | + if (count($psOutput) == 0) |
|
437 | + { |
|
438 | + return array(1,'Port UDP/162 is not open : is snmptrapd running?'); |
|
439 | + } |
|
440 | + $psOutput=array(); |
|
441 | + $selinux_state = ''; |
|
442 | + if(is_executable('/usr/sbin/getenforce')) |
|
443 | + { |
|
444 | + $selinux_state = exec('/usr/sbin/getenforce 2>/dev/null'); |
|
445 | + } |
|
446 | + if($selinux_state !== 'Enforcing') |
|
447 | + { |
|
448 | + exec('ps --no-headers -o command -C snmptrapd',$psOutput); |
|
449 | + if (count($psOutput) == 0) |
|
450 | + { |
|
451 | + return array(1,"UDP/162 : OK, but no snmptrapd process (?)"); |
|
452 | + } |
|
453 | + // Assume there is only one line... TODO : see if there is a better way to do this |
|
454 | + $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); |
|
461 | 461 | |
462 | - return array(0,'snmptrapd listening to UDP/162, options : '.$line); |
|
463 | - } |
|
464 | - else |
|
465 | - { |
|
466 | - return array(0,'A daemon (hidden by SELinux) is listening on UDP/162'); |
|
467 | - } |
|
462 | + return array(0,'snmptrapd listening to UDP/162, options : '.$line); |
|
463 | + } |
|
464 | + else |
|
465 | + { |
|
466 | + return array(0,'A daemon (hidden by SELinux) is listening on UDP/162'); |
|
467 | + } |
|
468 | 468 | } |
469 | 469 | } |
@@ -72,23 +72,23 @@ discard block |
||
72 | 72 | private function check_db() |
73 | 73 | { |
74 | 74 | $db_message=array( // index => ( message OK, message NOK, optional link if NOK ) |
75 | - 0 => array('Database configuration OK','',''), |
|
76 | - 1 => array('Database set in config.ini','No database in config.ini',''), |
|
77 | - 2 => array('Database exists in Icingaweb2 config','Database does not exist in Icingaweb2 : ', |
|
75 | + 0 => array('Database configuration OK', '', ''), |
|
76 | + 1 => array('Database set in config.ini', 'No database in config.ini', ''), |
|
77 | + 2 => array('Database exists in Icingaweb2 config', 'Database does not exist in Icingaweb2 : ', |
|
78 | 78 | Url::fromPath('config/resource')), |
79 | - 3 => array('Database credentials OK','Database does not exist/invalid credentials/no schema : ', |
|
79 | + 3 => array('Database credentials OK', 'Database does not exist/invalid credentials/no schema : ', |
|
80 | 80 | Url::fromPath('trapdirector/settings/createschema')), |
81 | - 4 => array('Schema is set','Schema is not set for ', |
|
81 | + 4 => array('Schema is set', 'Schema is not set for ', |
|
82 | 82 | Url::fromPath('trapdirector/settings/createschema')), |
83 | - 5 => array('Schema is up to date','Schema is outdated :', |
|
83 | + 5 => array('Schema is up to date', 'Schema is outdated :', |
|
84 | 84 | Url::fromPath('trapdirector/settings/updateschema')), |
85 | 85 | ); |
86 | 86 | |
87 | 87 | try { |
88 | 88 | $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
89 | - $dberror=array(0,''); |
|
89 | + $dberror=array(0, ''); |
|
90 | 90 | } catch (DBException $e) { |
91 | - $dberror = $e->getArray(); |
|
91 | + $dberror=$e->getArray(); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | $this->view->db_error=$dberror[0]; |
@@ -96,13 +96,13 @@ discard block |
||
96 | 96 | { |
97 | 97 | case 2: |
98 | 98 | case 4: |
99 | - $db_message[$dberror[0]][1] .= $dberror[1]; |
|
99 | + $db_message[$dberror[0]][1].=$dberror[1]; |
|
100 | 100 | break; |
101 | 101 | case 3: |
102 | - $db_message[$dberror[0]][1] .= $dberror[1] . ', Message : ' . $dberror[2]; |
|
102 | + $db_message[$dberror[0]][1].=$dberror[1].', Message : '.$dberror[2]; |
|
103 | 103 | break; |
104 | 104 | case 5: |
105 | - $db_message[$dberror[0]][1] .= ' version '. $dberror[1] . ', version needed : ' .$dberror[2]; |
|
105 | + $db_message[$dberror[0]][1].=' version '.$dberror[1].', version needed : '.$dberror[2]; |
|
106 | 106 | break; |
107 | 107 | case 0: |
108 | 108 | case 1: |
@@ -114,13 +114,13 @@ discard block |
||
114 | 114 | |
115 | 115 | try { |
116 | 116 | $this->getUIDatabase()->testGetIdoDb(); // Get DB in test mode |
117 | - $dberror=array(0,''); |
|
117 | + $dberror=array(0, ''); |
|
118 | 118 | } catch (DBException $e) { |
119 | - $dberror = $e->getArray(); |
|
119 | + $dberror=$e->getArray(); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | $this->view->ido_db_error=$dberror[0]; |
123 | - $this->view->ido_message='IDO Database : ' . $dberror[1]; |
|
123 | + $this->view->ido_message='IDO Database : '.$dberror[1]; |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -132,13 +132,13 @@ discard block |
||
132 | 132 | { |
133 | 133 | if ($this->Config()->get('config', 'icingaAPI_host') != '') |
134 | 134 | { |
135 | - $apitest=new Icinga2Api($this->Config()->get('config', 'icingaAPI_host'),$this->Config()->get('config', 'icingaAPI_port')); |
|
135 | + $apitest=new Icinga2Api($this->Config()->get('config', 'icingaAPI_host'), $this->Config()->get('config', 'icingaAPI_port')); |
|
136 | 136 | $apitest->setCredentials($this->Config()->get('config', 'icingaAPI_user'), $this->Config()->get('config', 'icingaAPI_password')); |
137 | 137 | try { |
138 | - list($this->view->apimessageError,$this->view->apimessage)=$apitest->test($this->getModuleConfig()::getapiUserPermissions()); |
|
138 | + list($this->view->apimessageError, $this->view->apimessage)=$apitest->test($this->getModuleConfig()::getapiUserPermissions()); |
|
139 | 139 | //$this->view->apimessageError=false; |
140 | 140 | } catch (RuntimeException $e) { |
141 | - $this->view->apimessage='API config : ' . $e->getMessage(); |
|
141 | + $this->view->apimessage='API config : '.$e->getMessage(); |
|
142 | 142 | $this->view->apimessageError=true; |
143 | 143 | } |
144 | 144 | } |
@@ -163,10 +163,10 @@ discard block |
||
163 | 163 | { |
164 | 164 | $output=array(); |
165 | 165 | |
166 | - exec('cat ' . $this->module->getBaseDir() .'/bin/trap_in.php | grep "\$icingaweb2Etc=" ',$output); |
|
166 | + exec('cat '.$this->module->getBaseDir().'/bin/trap_in.php | grep "\$icingaweb2Etc=" ', $output); |
|
167 | 167 | |
168 | 168 | |
169 | - if (! isset($output[0]) || ! preg_match('#"'. $icingaweb2_etc .'"#',$output[0])) |
|
169 | + if (!isset($output[0]) || !preg_match('#"'.$icingaweb2_etc.'"#', $output[0])) |
|
170 | 170 | { |
171 | 171 | $this->view->icingaEtcWarn=1; |
172 | 172 | $this->view->icingaweb2_etc=$icingaweb2_etc; |
@@ -182,12 +182,12 @@ discard block |
||
182 | 182 | */ |
183 | 183 | private function get_db_list($allowed) |
184 | 184 | { |
185 | - $resources = array(); |
|
185 | + $resources=array(); |
|
186 | 186 | foreach (ResourceFactory::getResourceConfigs() as $name => $resource) |
187 | 187 | { |
188 | 188 | if ($resource->get('type') === 'db' && in_array($resource->get('db'), $allowed)) |
189 | 189 | { |
190 | - $resources[$name] = $name; |
|
190 | + $resources[$name]=$name; |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | return $resources; |
@@ -199,18 +199,18 @@ discard block |
||
199 | 199 | */ |
200 | 200 | private function get_php_binary() |
201 | 201 | { |
202 | - $phpBinary= array( PHP_BINARY, PHP_BINDIR . "/php", '/usr/bin/php'); |
|
202 | + $phpBinary=array(PHP_BINARY, PHP_BINDIR."/php", '/usr/bin/php'); |
|
203 | 203 | |
204 | - foreach ($phpBinary as $phpBin ) |
|
204 | + foreach ($phpBinary as $phpBin) |
|
205 | 205 | { |
206 | 206 | $output=array(); |
207 | 207 | $retCode=255; |
208 | 208 | $input="154865134987aaaa"; |
209 | - exec("$phpBin -r \"echo '$input';\"",$output,$retCode); |
|
209 | + exec("$phpBin -r \"echo '$input';\"", $output, $retCode); |
|
210 | 210 | |
211 | - if (! isset($output[0])) $output[0]="NO OUT"; |
|
211 | + if (!isset($output[0])) $output[0]="NO OUT"; |
|
212 | 212 | |
213 | - if ($retCode == 0 && preg_match("/$input/",$output[0]) == 1) |
|
213 | + if ($retCode == 0 && preg_match("/$input/", $output[0]) == 1) |
|
214 | 214 | { |
215 | 215 | return $phpBin; |
216 | 216 | } |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | // But check read permission |
240 | 240 | $this->checkReadPermission(); |
241 | 241 | |
242 | - $this->view->tabs = $this->Module()->getConfigTabs()->activate('config'); |
|
242 | + $this->view->tabs=$this->Module()->getConfigTabs()->activate('config'); |
|
243 | 243 | |
244 | 244 | // Get message : sent on configuration problems detected by controllers |
245 | 245 | $this->get_param(); |
@@ -254,39 +254,39 @@ discard block |
||
254 | 254 | $this->check_api(); |
255 | 255 | |
256 | 256 | //*********** Test snmptrapd alive and options |
257 | - list ($this->view->snmptrapdError, $this->view->snmptrapdMessage) = $this->checkSnmpTrapd(); |
|
257 | + list ($this->view->snmptrapdError, $this->view->snmptrapdMessage)=$this->checkSnmpTrapd(); |
|
258 | 258 | |
259 | 259 | // List DB in $ressources |
260 | - $resources = $this->get_db_list(array('mysql', 'pgsql')); |
|
260 | + $resources=$this->get_db_list(array('mysql', 'pgsql')); |
|
261 | 261 | |
262 | 262 | // Check standard Icingaweb2 path |
263 | 263 | $this->check_icingaweb_path(); |
264 | 264 | |
265 | - $phpBinary = $this->get_php_binary(); |
|
265 | + $phpBinary=$this->get_php_binary(); |
|
266 | 266 | if ($phpBinary == null) |
267 | 267 | { |
268 | - $phpBinary = ' PHP BINARY NOT FOUND '; |
|
268 | + $phpBinary=' PHP BINARY NOT FOUND '; |
|
269 | 269 | |
270 | 270 | } |
271 | 271 | |
272 | 272 | // Setup path for mini documentation |
273 | - $this->view->traps_in_config= $phpBinary . ' ' . $this->Module()->getBaseDir() . '/bin/trap_in.php'; |
|
273 | + $this->view->traps_in_config=$phpBinary.' '.$this->Module()->getBaseDir().'/bin/trap_in.php'; |
|
274 | 274 | |
275 | - $this->view->installer= $this->Module()->getBaseDir() . '/bin/installer.sh ' |
|
275 | + $this->view->installer=$this->Module()->getBaseDir().'/bin/installer.sh ' |
|
276 | 276 | . ' -c all ' |
277 | - . ' -d ' . $this->Module()->getBaseDir() |
|
278 | - . ' -p ' . $phpBinary |
|
279 | - . ' -a ' . exec('whoami') |
|
280 | - . ' -w ' . Icinga::app()->getConfigDir(); |
|
277 | + . ' -d '.$this->Module()->getBaseDir() |
|
278 | + . ' -p '.$phpBinary |
|
279 | + . ' -a '.exec('whoami') |
|
280 | + . ' -w '.Icinga::app()->getConfigDir(); |
|
281 | 281 | |
282 | 282 | // ******************* configuration form setup******************* |
283 | - $this->view->form = $form = new TrapsConfigForm(); |
|
283 | + $this->view->form=$form=new TrapsConfigForm(); |
|
284 | 284 | |
285 | 285 | // set default paths; |
286 | - $this->view->form->setPaths($this->Module()->getBaseDir(),Icinga::app()->getConfigDir()); |
|
286 | + $this->view->form->setPaths($this->Module()->getBaseDir(), Icinga::app()->getConfigDir()); |
|
287 | 287 | |
288 | 288 | // set default ido database |
289 | - $this->view->form->setDefaultIDODB($this->Config()->module('monitoring','backends')->get('icinga','resource')); |
|
289 | + $this->view->form->setDefaultIDODB($this->Config()->module('monitoring', 'backends')->get('icinga', 'resource')); |
|
290 | 290 | |
291 | 291 | // Make form handle request. |
292 | 292 | $form->setIniConfig($this->Config()) |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | public function createschemaAction() |
299 | 299 | { |
300 | 300 | $this->checkModuleConfigPermission(); |
301 | - $this->getTabs()->add('create_schema',array( |
|
301 | + $this->getTabs()->add('create_schema', array( |
|
302 | 302 | 'active' => true, |
303 | 303 | 'label' => $this->translate('Create Schema'), |
304 | 304 | 'url' => Url::fromRequest() |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | // Get module database name |
320 | 320 | $dbName=$this->Config()->get('config', 'database'); |
321 | 321 | |
322 | - $dbResource = ResourceFactory::getResourceConfig($dbName); |
|
322 | + $dbResource=ResourceFactory::getResourceConfig($dbName); |
|
323 | 323 | $dbType=$dbResource->get('db'); |
324 | 324 | switch ($dbType) { |
325 | 325 | case 'mysql': |
@@ -334,28 +334,28 @@ discard block |
||
334 | 334 | } |
335 | 335 | |
336 | 336 | printf('<pre>'); |
337 | - require_once $this->Module()->getBaseDir() .'/bin/trap_class.php'; |
|
337 | + require_once $this->Module()->getBaseDir().'/bin/trap_class.php'; |
|
338 | 338 | |
339 | 339 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
340 | 340 | $debug_level=4; |
341 | - $Trap = new Trap($icingaweb2_etc); |
|
342 | - $Trap->setLogging($debug_level,'display'); |
|
341 | + $Trap=new Trap($icingaweb2_etc); |
|
342 | + $Trap->setLogging($debug_level, 'display'); |
|
343 | 343 | |
344 | 344 | $prefix=$this->Config()->get('config', 'database_prefix'); |
345 | 345 | // schema file : <path>/SQL/schema_v<verion>.<dbtype> |
346 | - $schema=$this->Module()->getBaseDir() . |
|
347 | - '/SQL/schema_v'. $this->getModuleConfig()->getDbCurVersion() . '.' . $dbFileExt; |
|
346 | + $schema=$this->Module()->getBaseDir(). |
|
347 | + '/SQL/schema_v'.$this->getModuleConfig()->getDbCurVersion().'.'.$dbFileExt; |
|
348 | 348 | |
349 | - $Trap->trapsDB->create_schema($schema,$prefix); |
|
349 | + $Trap->trapsDB->create_schema($schema, $prefix); |
|
350 | 350 | echo '</pre>'; |
351 | 351 | } |
352 | - echo '<br><br>Return to <a href="' . Url::fromPath('trapdirector/settings') .'" class="link-button icon-wrench"> settings page </a>'; |
|
352 | + echo '<br><br>Return to <a href="'.Url::fromPath('trapdirector/settings').'" class="link-button icon-wrench"> settings page </a>'; |
|
353 | 353 | } |
354 | 354 | |
355 | 355 | public function updateschemaAction() |
356 | 356 | { |
357 | 357 | $this->checkModuleConfigPermission(); |
358 | - $this->getTabs()->add('get',array( |
|
358 | + $this->getTabs()->add('get', array( |
|
359 | 359 | 'active' => true, |
360 | 360 | 'label' => $this->translate('Update Schema'), |
361 | 361 | 'url' => Url::fromRequest() |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | $dberror=$e->getArray(); |
374 | 374 | } |
375 | 375 | |
376 | - echo 'Return to <a href="' . Url::fromPath('trapdirector/settings') .'" class="link-button icon-wrench"> settings page </a><br><br>'; |
|
376 | + echo 'Return to <a href="'.Url::fromPath('trapdirector/settings').'" class="link-button icon-wrench"> settings page </a><br><br>'; |
|
377 | 377 | |
378 | 378 | if ($dberror[0] != 5) |
379 | 379 | { |
@@ -381,40 +381,40 @@ discard block |
||
381 | 381 | return; |
382 | 382 | } |
383 | 383 | // setup |
384 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
384 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
385 | 385 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
386 | 386 | $debug_level=4; |
387 | - $Trap = new Trap($icingaweb2_etc); |
|
387 | + $Trap=new Trap($icingaweb2_etc); |
|
388 | 388 | |
389 | 389 | |
390 | 390 | $prefix=$this->Config()->get('config', 'database_prefix'); |
391 | - $updateSchema=$this->Module()->getBaseDir() . '/SQL/'; |
|
391 | + $updateSchema=$this->Module()->getBaseDir().'/SQL/'; |
|
392 | 392 | |
393 | 393 | $target_version=$dberror[2]; |
394 | 394 | |
395 | 395 | if ($this->params->get('msgok') == null) { |
396 | 396 | // Check for messages and display if any |
397 | 397 | echo "Upgrade databse is going to start.<br>Don't forget to backup your database before update<br>"; |
398 | - $Trap->setLogging(2,'syslog'); |
|
399 | - $message = $Trap->trapsDB->update_schema($updateSchema,$target_version,$prefix,true); |
|
398 | + $Trap->setLogging(2, 'syslog'); |
|
399 | + $message=$Trap->trapsDB->update_schema($updateSchema, $target_version, $prefix, true); |
|
400 | 400 | if ($message != '') |
401 | 401 | { |
402 | 402 | echo 'Note :<br><pre>'; |
403 | 403 | echo $message; |
404 | 404 | echo '</pre>'; |
405 | 405 | echo '<br>'; |
406 | - 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>'; |
|
406 | + 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>'; |
|
407 | 407 | echo '<br>'; |
408 | 408 | return; |
409 | 409 | } |
410 | 410 | } |
411 | 411 | |
412 | - $Trap->setLogging($debug_level,'display'); |
|
412 | + $Trap->setLogging($debug_level, 'display'); |
|
413 | 413 | |
414 | - echo 'Updating schema to '. $target_version . ': <br>'; |
|
414 | + echo 'Updating schema to '.$target_version.': <br>'; |
|
415 | 415 | echo '<pre>'; |
416 | 416 | |
417 | - $Trap->trapsDB->update_schema($updateSchema,$target_version,$prefix); |
|
417 | + $Trap->trapsDB->update_schema($updateSchema, $target_version, $prefix); |
|
418 | 418 | echo '</pre>'; |
419 | 419 | } |
420 | 420 | |
@@ -422,48 +422,48 @@ discard block |
||
422 | 422 | { |
423 | 423 | $psOutput=array(); |
424 | 424 | // First check is someone is listening to port 162. As not root, we can't have pid... |
425 | - $sspath = exec('which ss 2>/dev/null'); |
|
426 | - if(empty($sspath)) |
|
425 | + $sspath=exec('which ss 2>/dev/null'); |
|
426 | + if (empty($sspath)) |
|
427 | 427 | { |
428 | 428 | // RHEL based systems |
429 | - $sspath = '/usr/sbin/ss'; |
|
429 | + $sspath='/usr/sbin/ss'; |
|
430 | 430 | } |
431 | - if(!is_executable("$sspath")) |
|
431 | + if (!is_executable("$sspath")) |
|
432 | 432 | { |
433 | - return array(1,"Can not execute $sspath"); |
|
433 | + return array(1, "Can not execute $sspath"); |
|
434 | 434 | } |
435 | - exec("$sspath -lun | grep ':162 '",$psOutput); |
|
435 | + exec("$sspath -lun | grep ':162 '", $psOutput); |
|
436 | 436 | if (count($psOutput) == 0) |
437 | 437 | { |
438 | - return array(1,'Port UDP/162 is not open : is snmptrapd running?'); |
|
438 | + return array(1, 'Port UDP/162 is not open : is snmptrapd running?'); |
|
439 | 439 | } |
440 | 440 | $psOutput=array(); |
441 | - $selinux_state = ''; |
|
442 | - if(is_executable('/usr/sbin/getenforce')) |
|
441 | + $selinux_state=''; |
|
442 | + if (is_executable('/usr/sbin/getenforce')) |
|
443 | 443 | { |
444 | - $selinux_state = exec('/usr/sbin/getenforce 2>/dev/null'); |
|
444 | + $selinux_state=exec('/usr/sbin/getenforce 2>/dev/null'); |
|
445 | 445 | } |
446 | - if($selinux_state !== 'Enforcing') |
|
446 | + if ($selinux_state !== 'Enforcing') |
|
447 | 447 | { |
448 | - exec('ps --no-headers -o command -C snmptrapd',$psOutput); |
|
448 | + exec('ps --no-headers -o command -C snmptrapd', $psOutput); |
|
449 | 449 | if (count($psOutput) == 0) |
450 | 450 | { |
451 | - return array(1,"UDP/162 : OK, but no snmptrapd process (?)"); |
|
451 | + return array(1, "UDP/162 : OK, but no snmptrapd process (?)"); |
|
452 | 452 | } |
453 | 453 | // Assume there is only one line... TODO : see if there is a better way to do this |
454 | - $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); |
|
454 | + $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); |
|
461 | 461 | |
462 | - return array(0,'snmptrapd listening to UDP/162, options : '.$line); |
|
462 | + return array(0, 'snmptrapd listening to UDP/162, options : '.$line); |
|
463 | 463 | } |
464 | 464 | else |
465 | 465 | { |
466 | - return array(0,'A daemon (hidden by SELinux) is listening on UDP/162'); |
|
466 | + return array(0, 'A daemon (hidden by SELinux) is listening on UDP/162'); |
|
467 | 467 | } |
468 | 468 | } |
469 | 469 | } |