@@ -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,31 +422,31 @@ 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 = '/usr/sbin/ss'; |
|
| 426 | - if(!is_executable("$sspath")) |
|
| 425 | + $sspath='/usr/sbin/ss'; |
|
| 426 | + if (!is_executable("$sspath")) |
|
| 427 | 427 | { |
| 428 | - return array(1,"Can not execute $sspath"); |
|
| 428 | + return array(1, "Can not execute $sspath"); |
|
| 429 | 429 | } |
| 430 | - exec("$sspath -lun | grep ':162 '",$psOutput); |
|
| 430 | + exec("$sspath -lun | grep ':162 '", $psOutput); |
|
| 431 | 431 | if (count($psOutput) == 0) |
| 432 | 432 | { |
| 433 | - return array(1,'Port UDP/162 is not open : is snmptrapd running?'); |
|
| 433 | + return array(1, 'Port UDP/162 is not open : is snmptrapd running?'); |
|
| 434 | 434 | } |
| 435 | 435 | $psOutput=array(); |
| 436 | - exec('ps --no-headers -o command -C snmptrapd',$psOutput); |
|
| 436 | + exec('ps --no-headers -o command -C snmptrapd', $psOutput); |
|
| 437 | 437 | if (count($psOutput) == 0) |
| 438 | 438 | { |
| 439 | - return array(1,"UDP/162 : OK, but no snmptrapd process (?)"); |
|
| 439 | + return array(1, "UDP/162 : OK, but no snmptrapd process (?)"); |
|
| 440 | 440 | } |
| 441 | 441 | // Assume there is only one line... TODO : see if there is a better way to do this |
| 442 | - $line = preg_replace('/^.*snmptrapd /','',$psOutput[0]); |
|
| 443 | - if (!preg_match('/-n/',$line)) |
|
| 444 | - return array(1,'snmptrapd has no -n option : '.$line); |
|
| 445 | - if (!preg_match('/-O[^ ]*n/',$line)) |
|
| 446 | - return array(1,'snmptrapd has no -On option : '.$line); |
|
| 447 | - if (!preg_match('/-O[^ ]*e/',$line)) |
|
| 448 | - return array(1,'snmptrapd has no -Oe option : '.$line); |
|
| 442 | + $line=preg_replace('/^.*snmptrapd /', '', $psOutput[0]); |
|
| 443 | + if (!preg_match('/-n/', $line)) |
|
| 444 | + return array(1, 'snmptrapd has no -n option : '.$line); |
|
| 445 | + if (!preg_match('/-O[^ ]*n/', $line)) |
|
| 446 | + return array(1, 'snmptrapd has no -On option : '.$line); |
|
| 447 | + if (!preg_match('/-O[^ ]*e/', $line)) |
|
| 448 | + return array(1, 'snmptrapd has no -Oe option : '.$line); |
|
| 449 | 449 | |
| 450 | - return array(0,'snmptrapd listening to UDP/162, options : '.$line); |
|
| 450 | + return array(0, 'snmptrapd listening to UDP/162, options : '.$line); |
|
| 451 | 451 | } |
| 452 | 452 | } |