| @@ -22,7 +22,9 @@ discard block | ||
| 22 | 22 | try | 
| 23 | 23 |  		{ | 
| 24 | 24 | $dbConn = $this->getUIDatabase()->getDbConn(); | 
| 25 | -		    if ($dbConn === null) throw new \ErrorException('uncatched db error'); | |
| 25 | +		    if ($dbConn === null) { | |
| 26 | +		    	throw new \ErrorException('uncatched db error'); | |
| 27 | + } | |
| 26 | 28 | $query = $dbConn->select()->from( | 
| 27 | 29 | $this->getModuleConfig()->getTrapTableName(), | 
| 28 | 30 |  				array('COUNT(*)') | 
| @@ -41,8 +43,7 @@ discard block | ||
| 41 | 43 | |
| 42 | 44 |  			$this->view->trap_days_delete=$this->getUIDatabase()->getDBConfigValue('db_remove_days'); | 
| 43 | 45 | |
| 44 | - } | |
| 45 | - catch (Exception $e) | |
| 46 | + } catch (Exception $e) | |
| 46 | 47 |  		{ | 
| 47 | 48 |  			$this->displayExitError('status',$e->getMessage()); | 
| 48 | 49 | } | 
| @@ -56,8 +57,7 @@ discard block | ||
| 56 | 57 |  			$this->view->currentLogFile=$this->getUIDatabase()->getDBConfigValue('log_file'); | 
| 57 | 58 | $this->view->logLevels=$this->getModuleConfig()->getlogLevels(); | 
| 58 | 59 |  			$this->view->currentLogLevel=$this->getUIDatabase()->getDBConfigValue('log_level'); | 
| 59 | - } | |
| 60 | - catch (Exception $e) | |
| 60 | + } catch (Exception $e) | |
| 61 | 61 |  		{ | 
| 62 | 62 |  			$this->displayExitError('status',$e->getMessage()); | 
| 63 | 63 | } | 
| @@ -69,8 +69,7 @@ discard block | ||
| 69 | 69 |  		    $this->view->SnmpTrapAddressOID=$this->getUIDatabase()->getDBConfigValue('SnmpTrapAddess_oid'); | 
| 70 | 70 | $this->view->SnmpTrapAddressOIDDefault = ($this->view->SnmpTrapAddressOID == $this->getModuleConfig()->getDBConfigDefaults()['SnmpTrapAddess_oid'] ) ? TRUE : FALSE; | 
| 71 | 71 | |
| 72 | - } | |
| 73 | - catch (Exception $e) | |
| 72 | + } catch (Exception $e) | |
| 74 | 73 |  		{ | 
| 75 | 74 |  		    $this->displayExitError('status',$e->getMessage()); | 
| 76 | 75 | } | 
| @@ -120,8 +119,7 @@ discard block | ||
| 120 | 119 | if ($retVal == 0) | 
| 121 | 120 |  					{ // process is alive | 
| 122 | 121 |  						$this->_helper->json(array('status'=>'Alive and kicking')); | 
| 123 | - } | |
| 124 | - else | |
| 122 | + } else | |
| 125 | 123 |  					{ // process is dead | 
| 126 | 124 |  					    $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid)); | 
| 127 | 125 | } | 
| @@ -137,22 +135,19 @@ discard block | ||
| 137 | 135 | if (!is_dir($destDir)) | 
| 138 | 136 |  				{ | 
| 139 | 137 | $this->view->uploadStatus="ERROR : no $destDir directory, check module configuration"; | 
| 140 | - } | |
| 141 | - else | |
| 138 | + } else | |
| 142 | 139 |  				{ | 
| 143 | 140 | if (!is_writable($destDir)) | 
| 144 | 141 |  				    { | 
| 145 | 142 | $this->view->uploadStatus="ERROR : $destDir directory is not writable"; | 
| 146 | - } | |
| 147 | - else | |
| 143 | + } else | |
| 148 | 144 |  				    { | 
| 149 | 145 | $destination = $destDir .'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name"; | 
| 150 | 146 | $sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'],FILTER_SANITIZE_STRING); | 
| 151 | 147 | if (move_uploaded_file($sourceTmpNam,$destination)===false) | 
| 152 | 148 |      				    { | 
| 153 | 149 | $this->view->uploadStatus="ERROR, file $destination not loaded. Check file and path name or selinux violations"; | 
| 154 | - } | |
| 155 | - else | |
| 150 | + } else | |
| 156 | 151 |      				    { | 
| 157 | 152 | $this->view->uploadStatus="File $name uploaded in $destDir"; | 
| 158 | 153 | } | 
| @@ -174,13 +169,11 @@ discard block | ||
| 174 | 169 |  			{ | 
| 175 | 170 | $this->view->snmptranslate='works fine'; | 
| 176 | 171 | $this->view->snmptranslate_state='ok'; | 
| 177 | - } | |
| 178 | - else | |
| 172 | + } else | |
| 179 | 173 |  			{ | 
| 180 | 174 | $this->view->snmptranslate='can execute but no resolution'; | 
| 181 | 175 | } | 
| 182 | - } | |
| 183 | - else | |
| 176 | + } else | |
| 184 | 177 |  		{ | 
| 185 | 178 | $this->view->snmptranslate='cannot execute'; | 
| 186 | 179 | } | 
| @@ -201,15 +194,13 @@ discard block | ||
| 201 | 194 | if ($retVal==0) | 
| 202 | 195 |  		{ | 
| 203 | 196 |  			$dirArray=array_merge($dirArray,explode(':',$sysDirs)); | 
| 204 | - } | |
| 205 | - else | |
| 197 | + } else | |
| 206 | 198 |  		{ | 
| 207 | 199 |  			$translateOut=exec($this->Config()->get('config', 'snmptranslate') . ' -Dinit_mib .1.3 2>&1 | grep MIBDIRS'); | 
| 208 | 200 |  			if (preg_match('/MIBDIRS.*\'([^\']+)\'/',$translateOut,$matches)) | 
| 209 | 201 |  			{ | 
| 210 | 202 |  				$dirArray=array_merge($dirArray,explode(':',$matches[1])); | 
| 211 | - } | |
| 212 | - else | |
| 203 | + } else | |
| 213 | 204 |  			{ | 
| 214 | 205 | array_push($dirArray,'Install net-snmp-config to see system directories'); | 
| 215 | 206 | } | 
| @@ -65,8 +65,7 @@ discard block | ||
| 65 | 65 | if (isset($postData['host'])) | 
| 66 | 66 |  		{ | 
| 67 | 67 | $host=$postData['host']; | 
| 68 | - } | |
| 69 | - else | |
| 68 | + } else | |
| 70 | 69 |  		{ | 
| 71 | 70 |  			$this->_helper->json(array('status'=>'No Hosts','hostid' => -1)); | 
| 72 | 71 | return; | 
| @@ -77,8 +76,7 @@ discard block | ||
| 77 | 76 |  		{	 | 
| 78 | 77 |  			$this->_helper->json(array('status'=>'More than one host matches','hostid' => -1)); | 
| 79 | 78 | return; | 
| 80 | - } | |
| 81 | - else if (count($hostArray) == 0) | |
| 79 | + } else if (count($hostArray) == 0) | |
| 82 | 80 |  		{ | 
| 83 | 81 |  			$this->_helper->json(array('status'=>'No host matches','hostid' => -1)); | 
| 84 | 82 | return; | 
| @@ -114,8 +112,7 @@ discard block | ||
| 114 | 112 |  		{	 | 
| 115 | 113 |  			$this->_helper->json(array('status'=>'More than one hostgroup matches','hostid' => -1)); | 
| 116 | 114 | return; | 
| 117 | - } | |
| 118 | - else if (count($hostArray) == 0) | |
| 115 | + } else if (count($hostArray) == 0) | |
| 119 | 116 |  		{ | 
| 120 | 117 |  			$this->_helper->json(array('status'=>'No hostgroup matches','hostid' => -1)); | 
| 121 | 118 | return; | 
| @@ -146,8 +143,7 @@ discard block | ||
| 146 | 143 |  		{ | 
| 147 | 144 | $traplist=$this->getMIB()->getTrapList($mib); | 
| 148 | 145 |  			$retTraps=array('status'=>'OK','traps' => $traplist); | 
| 149 | - } | |
| 150 | - catch (Exception $e) | |
| 146 | + } catch (Exception $e) | |
| 151 | 147 |  		{  | 
| 152 | 148 |  			$retTraps=array('status' => 'Error getting mibs'); | 
| 153 | 149 | } | 
| @@ -169,8 +165,7 @@ discard block | ||
| 169 | 165 |  		{ | 
| 170 | 166 | $objectlist=$this->getMIB()->getObjectList($trap); | 
| 171 | 167 |  			$retObjects=array('status'=>'OK','objects' => $objectlist); | 
| 172 | - } | |
| 173 | - catch (Exception $e) | |
| 168 | + } catch (Exception $e) | |
| 174 | 169 |  		{  | 
| 175 | 170 |  			$retObjects=array('status' => 'not found'); | 
| 176 | 171 | } | 
| @@ -185,8 +180,7 @@ discard block | ||
| 185 | 180 | try | 
| 186 | 181 |  		{ | 
| 187 | 182 | $miblist=$this->getMIB()->getMIBList(); | 
| 188 | - } | |
| 189 | - catch (Exception $e) | |
| 183 | + } catch (Exception $e) | |
| 190 | 184 |  		{  | 
| 191 | 185 |  			$miblist=array('Error getting mibs'); | 
| 192 | 186 | } | 
| @@ -209,8 +203,7 @@ discard block | ||
| 209 | 203 |  		{ | 
| 210 | 204 |  			$this->_helper->json(array('status'=>'Not found')); | 
| 211 | 205 | return; | 
| 212 | - } | |
| 213 | - else | |
| 206 | + } else | |
| 214 | 207 |  		{ | 
| 215 | 208 | $this->_helper->json( | 
| 216 | 209 |  				array('status'=>'OK', | 
| @@ -245,8 +238,7 @@ discard block | ||
| 245 | 238 | try | 
| 246 | 239 |  			{ | 
| 247 | 240 |  			    $this->getUIDatabase()->setDBConfigValue('db_remove_days',$days); | 
| 248 | - } | |
| 249 | - catch (Exception $e) | |
| 241 | + } catch (Exception $e) | |
| 250 | 242 |  			{ | 
| 251 | 243 |  				$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); | 
| 252 | 244 | return; | 
| @@ -264,8 +256,7 @@ discard block | ||
| 264 | 256 | $trap = new Trap($icingaweb2_etc); | 
| 265 | 257 | $trap->setLogging($debug_level,'syslog'); | 
| 266 | 258 | $trap->eraseOldTraps($days); | 
| 267 | - } | |
| 268 | - catch (Exception $e) | |
| 259 | + } catch (Exception $e) | |
| 269 | 260 |  			{ | 
| 270 | 261 |  				$this->_helper->json(array('status'=>'execute error : '.$e->getMessage() )); | 
| 271 | 262 | return; | 
| @@ -292,8 +283,7 @@ discard block | ||
| 292 | 283 |  	    { | 
| 293 | 284 |  	        $this->getUIDatabase()->setDBConfigValue('use_SnmpTrapAddess',$snmpUse); | 
| 294 | 285 |  	        $this->getUIDatabase()->setDBConfigValue('SnmpTrapAddess_oid',$snmpOID); | 
| 295 | - } | |
| 296 | - catch (Exception $e) | |
| 286 | + } catch (Exception $e) | |
| 297 | 287 |  	    { | 
| 298 | 288 |  	        $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); | 
| 299 | 289 | return; | 
| @@ -330,14 +320,12 @@ discard block | ||
| 330 | 320 |  			    $this->_helper->json(array('status'=>'File not writable :  '.$file)); | 
| 331 | 321 | return; | 
| 332 | 322 | } | 
| 333 | - } | |
| 334 | - else | |
| 323 | + } else | |
| 335 | 324 |  		{ | 
| 336 | 325 | if ($destination != 'file') | 
| 337 | 326 |  			{ | 
| 338 | 327 | $file=null; | 
| 339 | - } | |
| 340 | - else | |
| 328 | + } else | |
| 341 | 329 |  			{ | 
| 342 | 330 |  				$this->_helper->json(array('status'=>'No file')); | 
| 343 | 331 | return; | 
| @@ -351,8 +339,7 @@ discard block | ||
| 351 | 339 |  		    $this->getUIDatabase()->setDBConfigValue('log_destination',$destination); | 
| 352 | 340 |  		    $this->getUIDatabase()->setDBConfigValue('log_file',$file); | 
| 353 | 341 |  		    $this->getUIDatabase()->setDBConfigValue('log_level',$level); | 
| 354 | - } | |
| 355 | - catch (Exception $e) | |
| 342 | + } catch (Exception $e) | |
| 356 | 343 |  		{ | 
| 357 | 344 |  			$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); | 
| 358 | 345 | return; | 
| @@ -388,8 +375,7 @@ discard block | ||
| 388 | 375 | // Eval | 
| 389 | 376 | $item=0; | 
| 390 | 377 | $rule=$trap->ruleClass->evaluation($rule,$item); | 
| 391 | - } | |
| 392 | - catch (Exception $e) | |
| 378 | + } catch (Exception $e) | |
| 393 | 379 |  	        { | 
| 394 | 380 |  	            $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() )); | 
| 395 | 381 | return; | 
| @@ -422,8 +408,7 @@ discard block | ||
| 422 | 408 | $action=($action == 'enable') ? true : false; | 
| 423 | 409 | $retVal=$trap->pluginClass->enablePlugin($pluginName, $action); | 
| 424 | 410 | |
| 425 | - } | |
| 426 | - catch (Exception $e) | |
| 411 | + } catch (Exception $e) | |
| 427 | 412 |          { | 
| 428 | 413 |              $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); | 
| 429 | 414 | return; | 
| @@ -431,8 +416,7 @@ discard block | ||
| 431 | 416 | if ($retVal === true) | 
| 432 | 417 |          { | 
| 433 | 418 |              $this->_helper->json(array('status'=>'OK')); | 
| 434 | - } | |
| 435 | - else | |
| 419 | + } else | |
| 436 | 420 |          { | 
| 437 | 421 |              $this->_helper->json(array('status'=>'Error, see logs')); | 
| 438 | 422 | } | 
| @@ -463,8 +447,7 @@ discard block | ||
| 463 | 447 | $functionString = $trap->ruleClass->eval_cleanup($functionString); | 
| 464 | 448 | // Eval functions | 
| 465 | 449 | $result = $trap->pluginClass->evaluateFunctionString($functionString); | 
| 466 | - } | |
| 467 | - catch (Exception $e) | |
| 450 | + } catch (Exception $e) | |
| 468 | 451 |  	    { | 
| 469 | 452 |  	        $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); | 
| 470 | 453 | return; |