@@ -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 | } |