Passed
Push — master ( 225d38...efec06 )
by Patrick
01:58
created
application/controllers/SettingsController.php 1 patch
Spacing   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -72,15 +72,15 @@  discard block
 block discarded – undo
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
       
@@ -91,13 +91,13 @@  discard block
 block discarded – undo
91 91
       {
92 92
           case 2:
93 93
           case 4:
94
-              $db_message[$dberror[0]][1] .= $dberror[1];
94
+              $db_message[$dberror[0]][1].=$dberror[1];
95 95
               break;
96 96
           case 3:
97
-              $db_message[$dberror[0]][1] .= $dberror[1] . ', Message : ' . $dberror[2];
97
+              $db_message[$dberror[0]][1].=$dberror[1].', Message : '.$dberror[2];
98 98
               break;
99 99
           case 5:
100
-              $db_message[$dberror[0]][1] .= ' version '. $dberror[1] . ', version needed : ' .$dberror[2];
100
+              $db_message[$dberror[0]][1].=' version '.$dberror[1].', version needed : '.$dberror[2];
101 101
               break;
102 102
           case 0:
103 103
           case 1:
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
       
110 110
       $dberror=$this->getIdoDb(true); // Get IDO DB in test mode
111 111
       $this->view->ido_db_error=$dberror[0];
112
-      $this->view->ido_message='IDO Database : ' . $dberror[1];
112
+      $this->view->ido_message='IDO Database : '.$dberror[1];
113 113
   }
114 114
   
115 115
   /**
@@ -121,13 +121,13 @@  discard block
 block discarded – undo
121 121
   {
122 122
       if ($this->Config()->get('config', 'icingaAPI_host') != '')
123 123
       {
124
-          $apitest=new Icinga2Api($this->Config()->get('config', 'icingaAPI_host'),$this->Config()->get('config', 'icingaAPI_port'));
124
+          $apitest=new Icinga2Api($this->Config()->get('config', 'icingaAPI_host'), $this->Config()->get('config', 'icingaAPI_port'));
125 125
           $apitest->setCredentials($this->Config()->get('config', 'icingaAPI_user'), $this->Config()->get('config', 'icingaAPI_password'));
126 126
           try {
127
-              list($this->view->apimessageError,$this->view->apimessage)=$apitest->test($this->getModuleConfig()::getapiUserPermissions());
127
+              list($this->view->apimessageError, $this->view->apimessage)=$apitest->test($this->getModuleConfig()::getapiUserPermissions());
128 128
               //$this->view->apimessageError=false;
129 129
           } catch (RuntimeException $e) {
130
-              $this->view->apimessage='API config : ' . $e->getMessage();
130
+              $this->view->apimessage='API config : '.$e->getMessage();
131 131
               $this->view->apimessageError=true;
132 132
           }
133 133
       }
@@ -152,10 +152,10 @@  discard block
 block discarded – undo
152 152
       {
153 153
           $output=array();
154 154
           
155
-          exec('cat ' . $this->module->getBaseDir() .'/bin/trap_in.php | grep "\$icingaweb2Etc=" ',$output);
155
+          exec('cat '.$this->module->getBaseDir().'/bin/trap_in.php | grep "\$icingaweb2Etc=" ', $output);
156 156
           
157 157
           
158
-          if (! isset($output[0]) || ! preg_match('#"'. $icingaweb2_etc .'"#',$output[0]))
158
+          if (!isset($output[0]) || !preg_match('#"'.$icingaweb2_etc.'"#', $output[0]))
159 159
           {
160 160
               $this->view->icingaEtcWarn=1;
161 161
               $this->view->icingaweb2_etc=$icingaweb2_etc;
@@ -171,12 +171,12 @@  discard block
 block discarded – undo
171 171
    */
172 172
   private function get_db_list($allowed)
173 173
   {
174
-      $resources = array();
174
+      $resources=array();
175 175
       foreach (ResourceFactory::getResourceConfigs() as $name => $resource) 
176 176
       {
177 177
           if ($resource->get('type') === 'db' && in_array($resource->get('db'), $allowed)) 
178 178
           {
179
-              $resources[$name] = $name;
179
+              $resources[$name]=$name;
180 180
           }
181 181
       }
182 182
       return $resources;
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 	// But check read permission
204 204
 	$this->checkReadPermission();
205 205
 	
206
-	$this->view->tabs = $this->Module()->getConfigTabs()->activate('config');
206
+	$this->view->tabs=$this->Module()->getConfigTabs()->activate('config');
207 207
 	
208 208
 	// Get message : sent on configuration problems detected by controllers
209 209
     $this->get_param();
@@ -218,32 +218,32 @@  discard block
 block discarded – undo
218 218
     $this->check_api();
219 219
 	
220 220
 	//*********** Test snmptrapd alive and options
221
-	list ($this->view->snmptrapdError, $this->view->snmptrapdMessage) = $this->checkSnmpTrapd();
221
+	list ($this->view->snmptrapdError, $this->view->snmptrapdMessage)=$this->checkSnmpTrapd();
222 222
 
223 223
 	// List DB in $ressources
224
-	$resources = $this->get_db_list(array('mysql', 'pgsql')); 
224
+	$resources=$this->get_db_list(array('mysql', 'pgsql')); 
225 225
 
226 226
 	// Check standard Icingaweb2 path
227 227
 	$this->check_icingaweb_path();
228 228
 	
229 229
 	// Setup path for mini documentation
230
-	$this->view->traps_in_config= PHP_BINARY . ' ' . $this->Module()->getBaseDir() . '/bin/trap_in.php';
230
+	$this->view->traps_in_config=PHP_BINARY.' '.$this->Module()->getBaseDir().'/bin/trap_in.php';
231 231
 	
232
-	$this->view->installer= $this->Module()->getBaseDir() . '/bin/installer.sh '
232
+	$this->view->installer=$this->Module()->getBaseDir().'/bin/installer.sh '
233 233
 	    . ' -c all ' 
234
-	    . ' -d ' . $this->Module()->getBaseDir()
235
-	    . ' -p ' . PHP_BINARY
236
-	    . ' -a ' . exec('whoami')
237
-	    . ' -w ' . Icinga::app()->getConfigDir();
234
+	    . ' -d '.$this->Module()->getBaseDir()
235
+	    . ' -p '.PHP_BINARY
236
+	    . ' -a '.exec('whoami')
237
+	    . ' -w '.Icinga::app()->getConfigDir();
238 238
 	        
239 239
 	// ******************* configuration form setup*******************
240
-	$this->view->form = $form = new TrapsConfigForm();
240
+	$this->view->form=$form=new TrapsConfigForm();
241 241
 	
242 242
 	// set default paths;
243
-	$this->view->form->setPaths($this->Module()->getBaseDir(),Icinga::app()->getConfigDir());
243
+	$this->view->form->setPaths($this->Module()->getBaseDir(), Icinga::app()->getConfigDir());
244 244
 	
245 245
 	// set default ido database
246
-	$this->view->form->setDefaultIDODB($this->Config()->module('monitoring','backends')->get('icinga','resource'));
246
+	$this->view->form->setDefaultIDODB($this->Config()->module('monitoring', 'backends')->get('icinga', 'resource'));
247 247
 	
248 248
 	// Make form handle request.
249 249
 	$form->setIniConfig($this->Config())
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
   public function createschemaAction()
256 256
   {
257 257
 	$this->checkModuleConfigPermission();
258
-	$this->getTabs()->add('create_schema',array(
258
+	$this->getTabs()->add('create_schema', array(
259 259
 		'active'	=> true,
260 260
 		'label'		=> $this->translate('Create Schema'),
261 261
 		'url'		=> Url::fromRequest()
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 		$dbName=$this->Config()->get('config', 'database');
277 277
 
278 278
 		try {
279
-		  $dbResource = ResourceFactory::getResourceConfig($dbName);
279
+		  $dbResource=ResourceFactory::getResourceConfig($dbName);
280 280
 		  $dbType=$dbResource->get('db');
281 281
 		  switch ($dbType) {
282 282
 		      case 'mysql':
@@ -288,34 +288,34 @@  discard block
 block discarded – undo
288 288
 		      default:
289 289
 		          throw new ConfigurationError('Unsuported database : '.$dbType);
290 290
 		  }
291
-		} catch (ConfigurationError $e )
291
+		} catch (ConfigurationError $e)
292 292
 		{
293
-		    printf("Database configuration error : %s",$e->getMessage());
293
+		    printf("Database configuration error : %s", $e->getMessage());
294 294
 		    return;
295 295
 		}
296 296
 		printf('<pre>');
297
-		require_once $this->Module()->getBaseDir() .'/bin/trap_class.php';
297
+		require_once $this->Module()->getBaseDir().'/bin/trap_class.php';
298 298
 		
299 299
 		$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
300 300
 		$debug_level=4;
301
-		$Trap = new Trap($icingaweb2_etc);
302
-		$Trap->setLogging($debug_level,'display');
301
+		$Trap=new Trap($icingaweb2_etc);
302
+		$Trap->setLogging($debug_level, 'display');
303 303
 		
304 304
 		$prefix=$this->Config()->get('config', 'database_prefix');
305 305
 		// schema file : <path>/SQL/schema_v<verion>.<dbtype>
306
-		$schema=$this->Module()->getBaseDir() . 
307
-		'/SQL/schema_v'. $this->getModuleConfig()->getDbCurVersion() . '.' . $dbFileExt;
306
+		$schema=$this->Module()->getBaseDir(). 
307
+		'/SQL/schema_v'.$this->getModuleConfig()->getDbCurVersion().'.'.$dbFileExt;
308 308
 		
309
-		$Trap->trapsDB->create_schema($schema,$prefix);
309
+		$Trap->trapsDB->create_schema($schema, $prefix);
310 310
 		echo '</pre>';
311 311
 	}
312
-	echo '<br><br>Return to <a href="' . Url::fromPath('trapdirector/settings') .'" class="link-button icon-wrench"> settings page </a>';
312
+	echo '<br><br>Return to <a href="'.Url::fromPath('trapdirector/settings').'" class="link-button icon-wrench"> settings page </a>';
313 313
   }
314 314
 
315 315
   public function updateschemaAction()
316 316
   {
317 317
 	  $this->checkModuleConfigPermission();
318
-    	$this->getTabs()->add('get',array(
318
+    	$this->getTabs()->add('get', array(
319 319
     		'active'	=> true,
320 320
     		'label'		=> $this->translate('Update Schema'),
321 321
     		'url'		=> Url::fromRequest()
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
 	  
325 325
 	  $dberror=$this->getDb(true); // Get DB in test mode
326 326
 	  
327
-	  echo 'Return to <a href="' . Url::fromPath('trapdirector/settings') .'" class="link-button icon-wrench"> settings page </a><br><br>';
327
+	  echo 'Return to <a href="'.Url::fromPath('trapdirector/settings').'" class="link-button icon-wrench"> settings page </a><br><br>';
328 328
 	  
329 329
 	  if ($dberror[0] == 0)
330 330
 	  {
@@ -337,40 +337,40 @@  discard block
 block discarded – undo
337 337
 	      return;
338 338
 	  }
339 339
       // setup
340
-	  require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
340
+	  require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
341 341
 	  $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
342 342
 	  $debug_level=4;
343
-	  $Trap = new Trap($icingaweb2_etc);
343
+	  $Trap=new Trap($icingaweb2_etc);
344 344
 	  
345 345
 	  
346 346
 	  $prefix=$this->Config()->get('config', 'database_prefix');
347
-	  $updateSchema=$this->Module()->getBaseDir() . '/SQL/';
347
+	  $updateSchema=$this->Module()->getBaseDir().'/SQL/';
348 348
 	  
349 349
 	  $target_version=$dberror[2];
350 350
 	  
351 351
 	  if ($this->params->get('msgok') == null) {
352 352
 	      // Check for messages and display if any
353 353
               echo "Upgrade databse is going to start.<br>Don't forget to backup your database before update<br>";
354
-	      $Trap->setLogging(2,'syslog');
355
-	      $message = $Trap->trapsDB->update_schema($updateSchema,$target_version,$prefix,true);
354
+	      $Trap->setLogging(2, 'syslog');
355
+	      $message=$Trap->trapsDB->update_schema($updateSchema, $target_version, $prefix, true);
356 356
 	      if ($message != '')
357 357
 	      {
358 358
 	          echo 'Note :<br><pre>';
359 359
 	          echo $message;
360 360
 	          echo '</pre>';
361 361
 	          echo '<br>';
362
-	          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>';
362
+	          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>';
363 363
 	          echo '<br>';
364 364
 	          return;
365 365
 	      }
366 366
 	  }
367 367
 	  
368
-	  $Trap->setLogging($debug_level,'display');
368
+	  $Trap->setLogging($debug_level, 'display');
369 369
 	  
370
-	  echo 'Updating schema to '. $target_version . ': <br>';
370
+	  echo 'Updating schema to '.$target_version.': <br>';
371 371
 	  echo '<pre>';
372 372
 	  	  
373
-	  $Trap->trapsDB->update_schema($updateSchema,$target_version,$prefix);
373
+	  $Trap->trapsDB->update_schema($updateSchema, $target_version, $prefix);
374 374
 	  echo '</pre>';
375 375
   }  
376 376
 
@@ -378,26 +378,26 @@  discard block
 block discarded – undo
378 378
   {
379 379
       $psOutput=array();
380 380
       // First check is someone is listening to port 162. As not root, we can't have pid... 
381
-      exec('netstat -an |grep -E "udp.*:162"',$psOutput);
381
+      exec('netstat -an |grep -E "udp.*:162"', $psOutput);
382 382
       if (count($psOutput) == 0)
383 383
       {
384
-          return array(1,'Port UDP/162 is not open : snmptrapd must not be started');
384
+          return array(1, 'Port UDP/162 is not open : snmptrapd must not be started');
385 385
       }
386 386
       $psOutput=array();
387
-      exec('ps fax |grep snmptrapd |grep -v grep',$psOutput);
387
+      exec('ps fax |grep snmptrapd |grep -v grep', $psOutput);
388 388
       if (count($psOutput) == 0)
389 389
       {
390
-          return array(1,"UDP/162 : OK, but no snmptrapd process (?)");
390
+          return array(1, "UDP/162 : OK, but no snmptrapd process (?)");
391 391
       }
392 392
       // Assume there is only one line... TODO : see if there is a better way to do this
393
-      $line = preg_replace('/^.*snmptrapd /','',$psOutput[0]);
394
-      if (!preg_match('/-n/',$line))
395
-          return array(1,'snmptrapd has no -n option : '.$line);
396
-      if (!preg_match('/-O[^ ]*n/',$line))
397
-          return array(1,'snmptrapd has no -On option : '.$line);
398
-      if (!preg_match('/-O[^ ]*e/',$line))
399
-          return array(1,'snmptrapd has no -Oe option : '.$line);
393
+      $line=preg_replace('/^.*snmptrapd /', '', $psOutput[0]);
394
+      if (!preg_match('/-n/', $line))
395
+          return array(1, 'snmptrapd has no -n option : '.$line);
396
+      if (!preg_match('/-O[^ ]*n/', $line))
397
+          return array(1, 'snmptrapd has no -On option : '.$line);
398
+      if (!preg_match('/-O[^ ]*e/', $line))
399
+          return array(1, 'snmptrapd has no -Oe option : '.$line);
400 400
       
401
-      return array(0,'snmptrapd listening to UDP/162, options : '.$line);
401
+      return array(0, 'snmptrapd listening to UDP/162, options : '.$line);
402 402
   }
403 403
 }
Please login to merge, or discard this patch.