Passed
Push — master ( f94f6f...4a1327 )
by Patrick
03:06
created
library/Trapdirector/TrapsProcess/Rule.php 1 patch
Spacing   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -27,30 +27,30 @@  discard block
 block discarded – undo
27 27
  * Get full number 
28 28
  * @return array<number,string>
29 29
  */
30
-    private function get_number($rule,&$item)
30
+    private function get_number($rule, &$item)
31 31
     {
32
-        $item2=$item+1;
32
+        $item2=$item + 1;
33 33
         while (
34
-            ($item2!=strlen($rule)) 
35
-            && (preg_match('/[\-0-9\.]/',$rule[$item2]))) 
34
+            ($item2 != strlen($rule)) 
35
+            && (preg_match('/[\-0-9\.]/', $rule[$item2]))) 
36 36
         { 
37
-            $item2++ ;
37
+            $item2++;
38 38
         }
39
-        $val=substr($rule,$item,$item2-$item);
39
+        $val=substr($rule, $item, $item2 - $item);
40 40
         $item=$item2;
41 41
         //echo "number ".$val."\n";
42 42
         
43
-        return array(0,$val);
43
+        return array(0, $val);
44 44
     }
45 45
 
46
-    private function get_string($rule,&$item)
46
+    private function get_string($rule, &$item)
47 47
     {
48 48
         $item++;
49
-        $item2=$this->eval_getNext($rule,$item,'"');
50
-        $val=substr($rule,$item,$item2-$item-1);
49
+        $item2=$this->eval_getNext($rule, $item, '"');
50
+        $val=substr($rule, $item, $item2 - $item - 1);
51 51
         $item=$item2;
52 52
         //echo "string : ".$val."\n";
53
-        return array(1,$val);
53
+        return array(1, $val);
54 54
         
55 55
     }
56 56
     
@@ -62,20 +62,20 @@  discard block
 block discarded – undo
62 62
      * @throws Exception
63 63
      * @return string : everything inside parenthesis
64 64
      */
65
-    private function parse_parenthesis(string $rule,int &$item) : string
65
+    private function parse_parenthesis(string $rule, int &$item) : string
66 66
     {
67 67
         $item++;
68 68
         $start=$item;
69 69
         $parenthesis_count=0;
70 70
         while (($item < strlen($rule)) // Not end of string AND
71
-            && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded ()
71
+            && (($rule[$item] != ')') || $parenthesis_count > 0)) // Closing ')' or embeded ()
72 72
         {
73
-            if ($rule[$item] == '"' )
73
+            if ($rule[$item] == '"')
74 74
             { // pass through string
75 75
                 $item++;
76
-                $item=$this->eval_getNext($rule,$item,'"');
76
+                $item=$this->eval_getNext($rule, $item, '"');
77 77
             }
78
-            else{
78
+            else {
79 79
                 if ($rule[$item] == '(')
80 80
                 {
81 81
                     $parenthesis_count++;
@@ -88,8 +88,8 @@  discard block
 block discarded – undo
88 88
             }
89 89
         }
90 90
         
91
-        if ($item==strlen($rule)) {throw new Exception("no closing () in ".$rule ." at " .$item);}
92
-        $val=substr($rule,$start,$item-$start);
91
+        if ($item == strlen($rule)) {throw new Exception("no closing () in ".$rule." at ".$item); }
92
+        $val=substr($rule, $start, $item - $start);
93 93
         $item++;
94 94
         return $val;
95 95
     }
@@ -101,45 +101,45 @@  discard block
 block discarded – undo
101 101
      * @param int $item
102 102
      * @return array
103 103
      */
104
-    private function get_group(string $rule,int &$item) : array
104
+    private function get_group(string $rule, int &$item) : array
105 105
     {
106 106
         // gets eveything inside parenthesis
107 107
         $val=$this->parse_parenthesis($rule, $item);
108 108
         // Returns boolean with evaluation of all inside parenthesis
109 109
         $start=0;
110
-        return array(2,$this->evaluation($val,$start));
110
+        return array(2, $this->evaluation($val, $start));
111 111
     }
112 112
 
113
-    private function get_function(string $rule,int &$item) : array
113
+    private function get_function(string $rule, int &$item) : array
114 114
     {
115 115
         // function is : __function(param1,param2...)
116 116
         $start=$item; 
117
-        while (($item < strlen($rule)) && ($rule[$item] != '(' )) // Not end of string AND not opening '('
117
+        while (($item < strlen($rule)) && ($rule[$item] != '(')) // Not end of string AND not opening '('
118 118
         {
119 119
             $item++;
120 120
         }        
121
-        if ($item==strlen($rule)) {throw new Exception("no opening () for function in ".$rule ." at " .$item);}
121
+        if ($item == strlen($rule)) {throw new Exception("no opening () for function in ".$rule." at ".$item); }
122 122
         
123 123
         // get parameters between parenthesis
124 124
         
125 125
         $this->parse_parenthesis($rule, $item);
126 126
         
127
-        $val=substr($rule,$start,$item-$start);
127
+        $val=substr($rule, $start, $item - $start);
128 128
         
129
-        $this->logging->log('got function ' . $val,DEBUG);
129
+        $this->logging->log('got function '.$val, DEBUG);
130 130
         
131
-        return array(2,$this->trapClass->pluginClass->evaluateFunctionString($val));
131
+        return array(2, $this->trapClass->pluginClass->evaluateFunctionString($val));
132 132
         
133 133
     }
134 134
     
135
-    protected function eval_getElement($rule,&$item)
135
+    protected function eval_getElement($rule, &$item)
136 136
     {
137 137
         if ($item >= strlen($rule))
138 138
         {
139
-            throw new Exception("Early end of string ".$rule ." at " .$item );
139
+            throw new Exception("Early end of string ".$rule." at ".$item);
140 140
         }
141
-        while ($rule[$item]==' ') $item++;
142
-        if (preg_match('/[\-0-9\.]/',$rule[$item]))
141
+        while ($rule[$item] == ' ') $item++;
142
+        if (preg_match('/[\-0-9\.]/', $rule[$item]))
143 143
         { // number
144 144
             return $this->get_number($rule, $item);
145 145
         }
@@ -156,54 +156,54 @@  discard block
 block discarded – undo
156 156
         { // function
157 157
             return $this->get_function($rule, $item);
158 158
         }
159
-        throw new Exception("number/string not found in ".$rule ." at " .$item . ' : ' .$rule[$item]);
159
+        throw new Exception("number/string not found in ".$rule." at ".$item.' : '.$rule[$item]);
160 160
         
161 161
     }
162 162
     
163
-    protected function eval_getNext($rule,$item,$tok)
163
+    protected function eval_getNext($rule, $item, $tok)
164 164
     {
165 165
         while (
166
-            ($rule[$item] != $tok ) 
166
+            ($rule[$item] != $tok) 
167 167
             && ($item < strlen($rule))) 
168 168
         { 
169 169
             $item++;
170 170
         }
171
-        if ($item==strlen($rule)) {
172
-            throw new Exception("closing '".$tok."' not found in ".$rule ." at " .$item);
171
+        if ($item == strlen($rule)) {
172
+            throw new Exception("closing '".$tok."' not found in ".$rule." at ".$item);
173 173
         }
174
-        return $item+1;
174
+        return $item + 1;
175 175
     }
176 176
     
177
-    protected function eval_getOper($rule,&$item)
177
+    protected function eval_getOper($rule, &$item)
178 178
     {
179
-        while ($rule[$item]==' ') $item++;
179
+        while ($rule[$item] == ' ') $item++;
180 180
         switch ($rule[$item])
181 181
         {
182 182
             case '<':
183
-                if ($rule[$item+1]=='=') { $item+=2; return array(0,"<=");}
184
-                $item++; return array(0,"<");
183
+                if ($rule[$item + 1] == '=') { $item+=2; return array(0, "<="); }
184
+                $item++; return array(0, "<");
185 185
             case '>':
186
-                if ($rule[$item+1]=='=') { $item+=2; return array(0,">=");}
187
-                $item++; return array(0,">");
186
+                if ($rule[$item + 1] == '=') { $item+=2; return array(0, ">="); }
187
+                $item++; return array(0, ">");
188 188
             case '=':
189
-                $item++; return array(0,"=");
189
+                $item++; return array(0, "=");
190 190
             case '!':
191
-                if ($rule[$item+1]=='=') { $item+=2; return array(0,"!=");}
192
-                throw new Exception("Erreur in expr - incorrect operator '!'  found in ".$rule ." at " .$item);
191
+                if ($rule[$item + 1] == '=') { $item+=2; return array(0, "!="); }
192
+                throw new Exception("Erreur in expr - incorrect operator '!'  found in ".$rule." at ".$item);
193 193
             case '~':
194
-                $item++; return array(0,"~");
194
+                $item++; return array(0, "~");
195 195
             case '|':
196
-                $item++; return array(1,"|");
196
+                $item++; return array(1, "|");
197 197
             case '&':
198
-                $item++; return array(1,"&");
198
+                $item++; return array(1, "&");
199 199
             default	:
200
-                throw new Exception("Erreur in expr - operator not found in ".$rule ." at " .$item);
200
+                throw new Exception("Erreur in expr - operator not found in ".$rule." at ".$item);
201 201
         }
202 202
     }
203 203
     
204
-    private function check_negate_first($rule,&$item)
204
+    private function check_negate_first($rule, &$item)
205 205
     {
206
-        if ( $rule[$item] == '!') // If '!' found, negate next expression.
206
+        if ($rule[$item] == '!') // If '!' found, negate next expression.
207 207
         {
208 208
             $item++;
209 209
             return true;
@@ -214,21 +214,21 @@  discard block
 block discarded – undo
214 214
         }
215 215
     }
216 216
 
217
-    private function do_compare($val1,$val2,$comp,$negate)
217
+    private function do_compare($val1, $val2, $comp, $negate)
218 218
     {
219
-        switch ($comp){
220
-            case '<':	$retVal= ($val1 < $val2); break;
221
-            case '<=':	$retVal= ($val1 <= $val2); break;
222
-            case '>':	$retVal= ($val1 > $val2); break;
223
-            case '>=':	$retVal= ($val1 >= $val2); break;
224
-            case '=':	$retVal= ($val1 == $val2); break;
225
-            case '!=':	$retVal= ($val1 != $val2); break;
226
-            case '~':	$retVal= (preg_match('/'.preg_replace('/"/','',$val2).'/',$val1)); break;
227
-            case '|':	$retVal= ($val1 || $val2); break;
228
-            case '&':	$retVal= ($val1 && $val2); break;
219
+        switch ($comp) {
220
+            case '<':	$retVal=($val1 < $val2); break;
221
+            case '<=':	$retVal=($val1 <= $val2); break;
222
+            case '>':	$retVal=($val1 > $val2); break;
223
+            case '>=':	$retVal=($val1 >= $val2); break;
224
+            case '=':	$retVal=($val1 == $val2); break;
225
+            case '!=':	$retVal=($val1 != $val2); break;
226
+            case '~':	$retVal=(preg_match('/'.preg_replace('/"/', '', $val2).'/', $val1)); break;
227
+            case '|':	$retVal=($val1 || $val2); break;
228
+            case '&':	$retVal=($val1 && $val2); break;
229 229
             default:  throw new Exception("Error in expression - unknown comp : ".$comp);
230 230
         }
231
-        if ($negate === true) $retVal = ! $retVal; // Inverse result if negate before expression
231
+        if ($negate === true) $retVal=!$retVal; // Inverse result if negate before expression
232 232
         
233 233
         return $retVal;
234 234
     }
@@ -241,56 +241,56 @@  discard block
 block discarded – undo
241 241
      *   comparison int vs strings will return null (error)
242 242
      *	return : bool or null on error
243 243
      */
244
-    public function evaluation($rule,&$item)
244
+    public function evaluation($rule, &$item)
245 245
     {
246 246
         //echo "Evaluation of ".substr($rule,$item)."\n";
247 247
         $negate=$this->check_negate_first($rule, $item);
248 248
         // First element : number, string or ()
249
-        list($type1,$val1) = $this->eval_getElement($rule,$item);
249
+        list($type1, $val1)=$this->eval_getElement($rule, $item);
250 250
         //echo "Elmt1: ".$val1."/".$type1." : ".substr($rule,$item)."\n";
251 251
         
252
-        if ($item==strlen($rule)) // If only element, return value, but only boolean
252
+        if ($item == strlen($rule)) // If only element, return value, but only boolean
253 253
         {
254 254
             if ($type1 != 2) throw new Exception("Cannot use num/string as boolean : ".$rule);
255
-            if ($negate === true) $val1= ! $val1;
255
+            if ($negate === true) $val1=!$val1;
256 256
             return $val1;
257 257
         }
258 258
         
259 259
         // Second element : operator
260
-        list($typec,$comp) = $this->eval_getOper($rule,$item);
260
+        list($typec, $comp)=$this->eval_getOper($rule, $item);
261 261
         //echo "Comp : ".$comp." : ".substr($rule,$item)."\n";
262 262
         
263 263
         // Third element : number, string or ()
264
-        if ( $rule[$item] == '!') // starts with a ! so evaluate whats next
264
+        if ($rule[$item] == '!') // starts with a ! so evaluate whats next
265 265
         {
266 266
             $item++;
267 267
             if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule);
268
-            $val2= ! $this->evaluation($rule,$item);
268
+            $val2=!$this->evaluation($rule, $item);
269 269
             $type2=2; // result is a boolean
270 270
         }
271 271
         else
272 272
         {
273
-            list($type2,$val2) = $this->eval_getElement($rule,$item);
273
+            list($type2, $val2)=$this->eval_getElement($rule, $item);
274 274
         }
275 275
         //echo "Elmt2: ".$val2."/".$type2." : ".substr($rule,$item)."\n";
276 276
         
277
-        if ($type1!=$type2)  // cannot compare different types
277
+        if ($type1 != $type2)  // cannot compare different types
278 278
         {
279 279
             throw new Exception("Cannot compare string & number : ".$rule);
280 280
         }
281
-        if ($typec==1 && $type1 !=2) // cannot use & or | with string/number
281
+        if ($typec == 1 && $type1 != 2) // cannot use & or | with string/number
282 282
         {
283 283
             throw new Exception("Cannot use boolean operators with string & number : ".$rule);
284 284
         }
285 285
         
286
-        $retVal = $this->do_compare($val1, $val2, $comp, $negate);
286
+        $retVal=$this->do_compare($val1, $val2, $comp, $negate);
287 287
         
288
-        if ($item==strlen($rule)) return $retVal; // End of string : return evaluation
288
+        if ($item == strlen($rule)) return $retVal; // End of string : return evaluation
289 289
         // check for logical operator :
290 290
         switch ($rule[$item])
291 291
         {
292
-            case '|':	$item++; return ($retVal || $this->evaluation($rule,$item) );
293
-            case '&':	$item++; return ($retVal && $this->evaluation($rule,$item) );
292
+            case '|':	$item++; return ($retVal || $this->evaluation($rule, $item));
293
+            case '&':	$item++; return ($retVal && $this->evaluation($rule, $item));
294 294
             
295 295
             default:  throw new Exception("Erreur in expr - garbadge at end of expression : ".$rule[$item]);
296 296
         }
@@ -303,17 +303,17 @@  discard block
 block discarded – undo
303 303
         $rule2='';
304 304
         while ($item < strlen($rule))
305 305
         {
306
-            if ($rule[$item]==' ') { $item++; continue; }
307
-            if ($rule[$item]=='"')
306
+            if ($rule[$item] == ' ') { $item++; continue; }
307
+            if ($rule[$item] == '"')
308 308
             {
309 309
                 $rule2.=$rule[$item];
310 310
                 $item++;
311
-                while (($item < strlen($rule)) && ($rule[$item]!='"') )
311
+                while (($item < strlen($rule)) && ($rule[$item] != '"'))
312 312
                 {
313 313
                     $rule2.=$rule[$item];
314 314
                     $item++;
315 315
                 }
316
-                if ($item == strlen ($rule)) throw new Exception("closing '\"' not found in ".$rule ." at " .$item);
316
+                if ($item == strlen($rule)) throw new Exception("closing '\"' not found in ".$rule." at ".$item);
317 317
                 $rule2.=$rule[$item];
318 318
                 $item++;
319 319
                 continue;
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
         // replace * with \* in oid for preg_replace
343 343
         $oid=preg_replace('/\*/', '\*', $oid);
344 344
         
345
-        $this->logging->log('Regexp eval : '.$oid.' / '.$oidR,DEBUG );
345
+        $this->logging->log('Regexp eval : '.$oid.' / '.$oidR, DEBUG);
346 346
         
347 347
         return $oidR;
348 348
     }
@@ -353,50 +353,50 @@  discard block
 block discarded – undo
353 353
      *  @param array $oidList : OIDs values to sustitute.
354 354
      *	@return bool : true : rule match, false : rule don't match , throw exception on error.
355 355
      */   
356
-    public function eval_rule($rule,$oidList)
356
+    public function eval_rule($rule, $oidList)
357 357
     {
358
-        if ($rule==null || $rule == '') // Empty rule is always true
358
+        if ($rule == null || $rule == '') // Empty rule is always true
359 359
         {
360 360
             return true;
361 361
         }
362 362
         $matches=array();
363
-        while (preg_match('/_OID\(([0-9\.\*]+)\)/',$rule,$matches) == 1)
363
+        while (preg_match('/_OID\(([0-9\.\*]+)\)/', $rule, $matches) == 1)
364 364
         {
365 365
             $oid=$matches[1];
366 366
             $found=0;
367 367
             // Test and transform regexp
368
-            $oidR = $this->regexp_eval($oid);
368
+            $oidR=$this->regexp_eval($oid);
369 369
             
370
-            foreach($oidList as $val)
370
+            foreach ($oidList as $val)
371 371
             {
372
-                if (preg_match("/^$oidR$/",$val->oid) == 1)
372
+                if (preg_match("/^$oidR$/", $val->oid) == 1)
373 373
                 {
374
-                    if (!preg_match('/^-?[0-9]*\.?[0-9]+$/',$val->value))
374
+                    if (!preg_match('/^-?[0-9]*\.?[0-9]+$/', $val->value))
375 375
                     { // If not a number, change " to ' and put " around it
376
-                        $val->value=preg_replace('/"/',"'",$val->value);
376
+                        $val->value=preg_replace('/"/', "'", $val->value);
377 377
                         $val->value='"'.$val->value.'"';
378 378
                     }
379 379
                     $rep=0;
380
-                    $rule=preg_replace('/_OID\('.$oid.'\)/',$val->value,$rule,-1,$rep);
381
-                    if ($rep==0)
380
+                    $rule=preg_replace('/_OID\('.$oid.'\)/', $val->value, $rule, -1, $rep);
381
+                    if ($rep == 0)
382 382
                     {
383
-                        $this->logging->log("Error in rule_eval",WARN,'');
383
+                        $this->logging->log("Error in rule_eval", WARN, '');
384 384
                         return false;
385 385
                     }
386 386
                     $found=1;
387 387
                     break;
388 388
                 }
389 389
             }
390
-            if ($found==0)
390
+            if ($found == 0)
391 391
             {	// OID not found : throw error
392 392
                 throw new Exception('OID '.$oid.' not found in trap');
393 393
             }
394 394
         }
395 395
         $item=0;
396 396
         $rule=$this->eval_cleanup($rule);
397
-        $this->logging->log('Rule after clenup: '.$rule,INFO );
397
+        $this->logging->log('Rule after clenup: '.$rule, INFO);
398 398
         
399
-        return  $this->evaluation($rule,$item);
399
+        return  $this->evaluation($rule, $item);
400 400
     }
401 401
     
402 402
 }
403 403
\ No newline at end of file
Please login to merge, or discard this patch.
library/Trapdirector/TrapsProcess/Trap.php 1 patch
Spacing   +199 added lines, -199 removed lines patch added patch discarded remove patch
@@ -49,13 +49,13 @@  discard block
 block discarded – undo
49 49
     
50 50
     // Logs
51 51
     /** @var Logging Logging class. */
52
-    public $logging;    //< Logging class.
52
+    public $logging; //< Logging class.
53 53
     /** @var bool true if log was setup in constructor */
54
-    protected $logSetup;   //< bool true if log was setup in constructor
54
+    protected $logSetup; //< bool true if log was setup in constructor
55 55
     
56 56
     // Databases
57 57
     /** @var Database $trapsDB  Database class*/
58
-    public $trapsDB = null;
58
+    public $trapsDB=null;
59 59
     
60 60
     // Trap received data
61 61
     protected $receivingHost;
@@ -71,15 +71,15 @@  discard block
 block discarded – undo
71 71
     protected $trapToDb=true;
72 72
     
73 73
     /** @var Mib mib class */
74
-    public $mibClass = null;
74
+    public $mibClass=null;
75 75
     
76 76
     /** @var Rule rule class */
77
-    public $ruleClass = null;
77
+    public $ruleClass=null;
78 78
     
79 79
     /** @var Plugins plugins manager **/
80
-    public $pluginClass = null;
80
+    public $pluginClass=null;
81 81
     
82
-    function __construct($etcDir='/etc/icingaweb2',$baseLogLevel=null,$baseLogMode='syslog',$baseLogFile='')
82
+    function __construct($etcDir='/etc/icingaweb2', $baseLogLevel=null, $baseLogMode='syslog', $baseLogFile='')
83 83
     {
84 84
         // Paths of ini files
85 85
         $this->icingaweb2Etc=$etcDir;
@@ -87,10 +87,10 @@  discard block
 block discarded – undo
87 87
         $this->icingaweb2Ressources=$this->icingaweb2Etc."/resources.ini";
88 88
         
89 89
         //************* Setup logging
90
-        $this->logging = new Logging();
90
+        $this->logging=new Logging();
91 91
         if ($baseLogLevel != null)
92 92
         {
93
-            $this->logging->setLogging($baseLogLevel, $baseLogMode,$baseLogFile);
93
+            $this->logging->setLogging($baseLogLevel, $baseLogMode, $baseLogFile);
94 94
             $this->logSetup=true;
95 95
         }
96 96
         else
@@ -100,14 +100,14 @@  discard block
 block discarded – undo
100 100
         $this->logging->log('Loggin started', INFO);
101 101
         
102 102
         //*************** Get options from ini files
103
-        if (! is_file($this->trapModuleConfig))
103
+        if (!is_file($this->trapModuleConfig))
104 104
         {
105 105
             throw new Exception("Ini file ".$this->trapModuleConfig." does not exists");
106 106
         }
107
-        $trapConfig=parse_ini_file($this->trapModuleConfig,true);
107
+        $trapConfig=parse_ini_file($this->trapModuleConfig, true);
108 108
         if ($trapConfig == false)
109 109
         {
110
-            $this->logging->log("Error reading ini file : ".$this->trapModuleConfig,ERROR,'syslog');
110
+            $this->logging->log("Error reading ini file : ".$this->trapModuleConfig, ERROR, 'syslog');
111 111
             throw new Exception("Error reading ini file : ".$this->trapModuleConfig);
112 112
         }
113 113
         $this->getMainOptions($trapConfig); // Get main options from ini file
@@ -121,10 +121,10 @@  discard block
 block discarded – undo
121 121
         if ($this->apiUse === true) $this->getAPI(); // Setup API
122 122
         
123 123
         //*************** Setup MIB
124
-        $this->mibClass = new Mib($this->logging,$this->trapsDB,$this->snmptranslate,$this->snmptranslate_dirs); // Create Mib class
124
+        $this->mibClass=new Mib($this->logging, $this->trapsDB, $this->snmptranslate, $this->snmptranslate_dirs); // Create Mib class
125 125
         
126 126
         //*************** Setup Rule
127
-        $this->ruleClass = new Rule($this); //< Create Rule class
127
+        $this->ruleClass=new Rule($this); //< Create Rule class
128 128
         
129 129
         $this->trapData=array(  // TODO : put this in a reset function (DAEMON_MODE)
130 130
             'source_ip'	=> 'unknown',
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
         
137 137
         //*************** Setup Plugins
138 138
         //Create plugin class. Plugins are not loaded here, but by calling registerAllPlugins
139
-        $this->pluginClass = new Plugins($this);
139
+        $this->pluginClass=new Plugins($this);
140 140
             
141 141
             
142 142
     }
@@ -151,15 +151,15 @@  discard block
 block discarded – undo
151 151
      * @param string $message warning message if not found
152 152
      * @return boolean true if found, or false
153 153
      */
154
-    protected function getOptionIfSet($option_array,$option_category,$option_name, &$option_var, $log_level = 2, $message = null)
154
+    protected function getOptionIfSet($option_array, $option_category, $option_name, &$option_var, $log_level=2, $message=null)
155 155
     {
156 156
         if (!isset($option_array[$option_category][$option_name]))
157 157
         {
158 158
             if ($message === null)
159 159
             {
160
-                $message='No ' . $option_name . ' in config file: '. $this->trapModuleConfig;
160
+                $message='No '.$option_name.' in config file: '.$this->trapModuleConfig;
161 161
             }
162
-            $this->logging->log($message,$log_level);
162
+            $this->logging->log($message, $log_level);
163 163
             return false;
164 164
         }
165 165
         else
@@ -177,24 +177,24 @@  discard block
 block discarded – undo
177 177
     {
178 178
         
179 179
         // Snmptranslate binary path
180
-        $this->getOptionIfSet($trapConfig,'config','snmptranslate', $this->snmptranslate);
180
+        $this->getOptionIfSet($trapConfig, 'config', 'snmptranslate', $this->snmptranslate);
181 181
         
182 182
         // mibs path
183
-        $this->getOptionIfSet($trapConfig,'config','snmptranslate_dirs', $this->snmptranslate_dirs);
183
+        $this->getOptionIfSet($trapConfig, 'config', 'snmptranslate_dirs', $this->snmptranslate_dirs);
184 184
         
185 185
         // icinga2cmd path
186
-        $this->getOptionIfSet($trapConfig,'config','icingacmd', $this->icinga2cmd);
186
+        $this->getOptionIfSet($trapConfig, 'config', 'icingacmd', $this->icinga2cmd);
187 187
         
188 188
         // table prefix
189
-        $this->getOptionIfSet($trapConfig,'config','database_prefix', $this->dbPrefix);
189
+        $this->getOptionIfSet($trapConfig, 'config', 'database_prefix', $this->dbPrefix);
190 190
         
191 191
         // API options
192
-        if ($this->getOptionIfSet($trapConfig,'config','icingaAPI_host', $this->apiHostname))
192
+        if ($this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_host', $this->apiHostname))
193 193
         {
194 194
             $this->apiUse=true;
195
-            $this->getOptionIfSet($trapConfig,'config','icingaAPI_port', $this->apiPort);
196
-            $this->getOptionIfSet($trapConfig,'config','icingaAPI_user', $this->apiUsername);
197
-            $this->getOptionIfSet($trapConfig,'config','icingaAPI_password', $this->apiPassword);
195
+            $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_port', $this->apiPort);
196
+            $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_user', $this->apiUsername);
197
+            $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_password', $this->apiPassword);
198 198
         }
199 199
     }
200 200
     
@@ -205,40 +205,40 @@  discard block
 block discarded – undo
205 205
     protected function setupDatabase($trapConfig)
206 206
     {
207 207
         // Trap database
208
-        if (!array_key_exists('database',$trapConfig['config']))
208
+        if (!array_key_exists('database', $trapConfig['config']))
209 209
         {
210
-            $this->logging->log("No database in config file: ".$this->trapModuleConfig,ERROR,'');
210
+            $this->logging->log("No database in config file: ".$this->trapModuleConfig, ERROR, '');
211 211
             return;
212 212
         }
213 213
         $dbTrapName=$trapConfig['config']['database'];
214
-        $this->logging->log("Found database in config file: ".$dbTrapName,INFO );
214
+        $this->logging->log("Found database in config file: ".$dbTrapName, INFO);
215 215
         
216
-        if ( ($dbConfig=parse_ini_file($this->icingaweb2Ressources,true)) === false)
216
+        if (($dbConfig=parse_ini_file($this->icingaweb2Ressources, true)) === false)
217 217
         {
218
-            $this->logging->log("Error reading ini file : ".$this->icingaweb2Ressources,ERROR,'');
218
+            $this->logging->log("Error reading ini file : ".$this->icingaweb2Ressources, ERROR, '');
219 219
             return;
220 220
         }
221
-        if (!array_key_exists($dbTrapName,$dbConfig))
221
+        if (!array_key_exists($dbTrapName, $dbConfig))
222 222
         {
223
-            $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2Ressources,ERROR,'');
223
+            $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2Ressources, ERROR, '');
224 224
             return;
225 225
         }
226 226
         
227
-        $this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName],$this->dbPrefix);
227
+        $this->trapsDB=new Database($this->logging, $dbConfig[$dbTrapName], $this->dbPrefix);
228 228
         
229 229
         if ($this->apiUse === true) return; // In case of API use, no IDO is necessary
230 230
         
231 231
         // IDO Database
232
-        if (!array_key_exists('IDOdatabase',$trapConfig['config']))
232
+        if (!array_key_exists('IDOdatabase', $trapConfig['config']))
233 233
         {
234
-            $this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig,ERROR,'');
234
+            $this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig, ERROR, '');
235 235
         }
236 236
         $dbIdoName=$trapConfig['config']['IDOdatabase'];
237 237
         
238
-        $this->logging->log("Found IDO database in config file: ".$dbIdoName,INFO );
239
-        if (!array_key_exists($dbIdoName,$dbConfig))
238
+        $this->logging->log("Found IDO database in config file: ".$dbIdoName, INFO);
239
+        if (!array_key_exists($dbIdoName, $dbConfig))
240 240
         {
241
-            $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources,ERROR,'');
241
+            $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources, ERROR, '');
242 242
             return;
243 243
         }
244 244
         
@@ -253,9 +253,9 @@  discard block
 block discarded – undo
253 253
         // Database options
254 254
         if ($this->logSetup === false) // Only if logging was no setup in constructor
255 255
         {
256
-            $this->getDBConfigIfSet('log_level',$this->logging->debugLevel);
257
-            $this->getDBConfigIfSet('log_destination',$this->logging->outputMode);
258
-            $this->getDBConfigIfSet('log_file',$this->logging->outputFile);
256
+            $this->getDBConfigIfSet('log_level', $this->logging->debugLevel);
257
+            $this->getDBConfigIfSet('log_destination', $this->logging->outputMode);
258
+            $this->getDBConfigIfSet('log_file', $this->logging->outputFile);
259 259
         }
260 260
     }
261 261
     
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
      * @param string $element
264 264
      * @param string $variable
265 265
      */
266
-    protected function getDBConfigIfSet($element,&$variable)
266
+    protected function getDBConfigIfSet($element, &$variable)
267 267
     {
268 268
         $value=$this->getDBConfig($element);
269 269
         if ($value != null) $variable=$value;
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
         $db_conn=$this->trapsDB->db_connect_trap();
280 280
         $sql='SELECT value from '.$this->dbPrefix.'db_config WHERE ( name=\''.$element.'\' )';
281 281
         if (($ret_code=$db_conn->query($sql)) === false) {
282
-            $this->logging->log('No result in query : ' . $sql,WARN,'');
282
+            $this->logging->log('No result in query : '.$sql, WARN, '');
283 283
             return null;
284 284
         }
285 285
         $value=$ret_code->fetch();
@@ -296,15 +296,15 @@  discard block
 block discarded – undo
296 296
      *	@param  string $destination file/syslog/display
297 297
      *	@return void
298 298
      **/
299
-    public function trapLog( $message, $level, $destination ='') // OBSOLETE
299
+    public function trapLog($message, $level, $destination='') // OBSOLETE
300 300
     {
301 301
         // TODO : replace ref with $this->logging->log
302 302
         $this->logging->log($message, $level, $destination);
303 303
     }
304 304
     
305
-    public function setLogging($debugLvl,$outputType,$outputOption=null)  // OBSOLETE
305
+    public function setLogging($debugLvl, $outputType, $outputOption=null)  // OBSOLETE
306 306
     {
307
-        $this->logging->setLogging($debugLvl, $outputType,$outputOption);
307
+        $this->logging->setLogging($debugLvl, $outputType, $outputOption);
308 308
     }
309 309
     
310 310
     /**
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
     {
316 316
         if ($this->icinga2api == null)
317 317
         {
318
-            $this->icinga2api = new Icinga2API($this->apiHostname,$this->apiPort);
318
+            $this->icinga2api=new Icinga2API($this->apiHostname, $this->apiPort);
319 319
         }
320 320
         return $this->icinga2api;
321 321
     }
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
         if ($input_stream === false)
335 335
         {
336 336
             $this->writeTrapErrorToDB("Error reading trap (code 1/Stdin)");
337
-            $this->logging->log("Error reading stdin !",ERROR,'');
337
+            $this->logging->log("Error reading stdin !", ERROR, '');
338 338
             return null; // note : exception thrown by logging
339 339
         }
340 340
         
@@ -343,21 +343,21 @@  discard block
 block discarded – undo
343 343
         if ($this->receivingHost === false)
344 344
         {
345 345
             $this->writeTrapErrorToDB("Error reading trap (code 1/Line Host)");
346
-            $this->logging->log("Error reading Host !",ERROR,'');
346
+            $this->logging->log("Error reading Host !", ERROR, '');
347 347
         }
348 348
         // line 2 IP:port=>IP:port
349 349
         $IP=chop(fgets($input_stream));
350 350
         if ($IP === false)
351 351
         {
352 352
             $this->writeTrapErrorToDB("Error reading trap (code 1/Line IP)");
353
-            $this->logging->log("Error reading IP !",ERROR,'');
353
+            $this->logging->log("Error reading IP !", ERROR, '');
354 354
         }
355 355
         $matches=array();
356
-        $ret_code=preg_match('/.DP: \[(.*)\]:(.*)->\[(.*)\]:(.*)/',$IP,$matches);
357
-        if ($ret_code===0 || $ret_code===false)
356
+        $ret_code=preg_match('/.DP: \[(.*)\]:(.*)->\[(.*)\]:(.*)/', $IP, $matches);
357
+        if ($ret_code === 0 || $ret_code === false)
358 358
         {
359 359
             $this->writeTrapErrorToDB("Error parsing trap (code 2/IP)");
360
-            $this->logging->log('Error parsing IP : '.$IP,ERROR,'');
360
+            $this->logging->log('Error parsing IP : '.$IP, ERROR, '');
361 361
         }
362 362
         else
363 363
         {
@@ -367,34 +367,34 @@  discard block
 block discarded – undo
367 367
             $this->trapData['destination_port']=$matches[4];
368 368
         }
369 369
         
370
-        while (($vars=fgets($input_stream)) !==false)
370
+        while (($vars=fgets($input_stream)) !== false)
371 371
         {
372 372
             $vars=chop($vars);
373
-            $ret_code=preg_match('/^([^ ]+) (.*)$/',$vars,$matches);
374
-            if ($ret_code===0 || $ret_code===false)
373
+            $ret_code=preg_match('/^([^ ]+) (.*)$/', $vars, $matches);
374
+            if ($ret_code === 0 || $ret_code === false)
375 375
             {
376
-                $this->logging->log('No match on trap data : '.$vars,WARN,'');
376
+                $this->logging->log('No match on trap data : '.$vars, WARN, '');
377 377
             }
378 378
             else
379 379
             {
380
-                if (($matches[1]=='.1.3.6.1.6.3.1.1.4.1.0') || ($matches[1]=='.1.3.6.1.6.3.1.1.4.1'))
380
+                if (($matches[1] == '.1.3.6.1.6.3.1.1.4.1.0') || ($matches[1] == '.1.3.6.1.6.3.1.1.4.1'))
381 381
                 {
382 382
                     $this->trapData['trap_oid']=$matches[2];
383 383
                 }
384 384
                 else
385 385
                 {
386
-                    $object= new stdClass;
387
-                    $object->oid =$matches[1];
388
-                    $object->value = $matches[2];
389
-                    array_push($this->trapDataExt,$object);
386
+                    $object=new stdClass;
387
+                    $object->oid=$matches[1];
388
+                    $object->value=$matches[2];
389
+                    array_push($this->trapDataExt, $object);
390 390
                 }
391 391
             }
392 392
         }
393 393
         
394
-        if ($this->trapData['trap_oid']=='unknown')
394
+        if ($this->trapData['trap_oid'] == 'unknown')
395 395
         {
396
-            $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)",$this->trapData['source_ip']);
397
-            $this->logging->log('no trap oid found',ERROR,'');
396
+            $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)", $this->trapData['source_ip']);
397
+            $this->logging->log('no trap oid found', ERROR, '');
398 398
         }
399 399
         
400 400
         // Translate oids.
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
         }
417 417
         
418 418
         
419
-        $this->trapData['status']= 'waiting';
419
+        $this->trapData['status']='waiting';
420 420
         
421 421
         return $this->trapData;
422 422
     }
@@ -432,40 +432,40 @@  discard block
 block discarded – undo
432 432
         $db_conn=$this->trapsDB->db_connect_trap();
433 433
         
434 434
         $sql='SELECT mib,name from '.$this->dbPrefix.'mib_cache WHERE oid=\''.$oid.'\';';
435
-        $this->logging->log('SQL query : '.$sql,DEBUG );
435
+        $this->logging->log('SQL query : '.$sql, DEBUG);
436 436
         if (($ret_code=$db_conn->query($sql)) === false) {
437
-            $this->logging->log('No result in query : ' . $sql,ERROR,'');
437
+            $this->logging->log('No result in query : '.$sql, ERROR, '');
438 438
         }
439 439
         $name=$ret_code->fetch();
440 440
         if ($name['name'] != null)
441 441
         {
442
-            return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']);
442
+            return array('trap_name_mib'=>$name['mib'], 'trap_name'=>$name['name']);
443 443
         }
444 444
         
445 445
         // Also check if it is an instance of OID
446
-        $oid_instance=preg_replace('/\.[0-9]+$/','',$oid);
446
+        $oid_instance=preg_replace('/\.[0-9]+$/', '', $oid);
447 447
         
448 448
         $sql='SELECT mib,name from '.$this->dbPrefix.'mib_cache WHERE oid=\''.$oid_instance.'\';';
449
-        $this->logging->log('SQL query : '.$sql,DEBUG );
449
+        $this->logging->log('SQL query : '.$sql, DEBUG);
450 450
         if (($ret_code=$db_conn->query($sql)) === false) {
451
-            $this->logging->log('No result in query : ' . $sql,ERROR,'');
451
+            $this->logging->log('No result in query : '.$sql, ERROR, '');
452 452
         }
453 453
         $name=$ret_code->fetch();
454 454
         if ($name['name'] != null)
455 455
         {
456
-            return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']);
456
+            return array('trap_name_mib'=>$name['mib'], 'trap_name'=>$name['name']);
457 457
         }
458 458
         
459 459
         // Try to get oid name from snmptranslate
460
-        $translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
460
+        $translate=exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.
461 461
             ' '.$oid);
462 462
         $matches=array();
463
-        $ret_code=preg_match('/(.*)::(.*)/',$translate,$matches);
464
-        if ($ret_code===0 || $ret_code === false) {
463
+        $ret_code=preg_match('/(.*)::(.*)/', $translate, $matches);
464
+        if ($ret_code === 0 || $ret_code === false) {
465 465
             return NULL;
466 466
         } else {
467
-            $this->logging->log('Found name with snmptrapd and not in DB for oid='.$oid,INFO);
468
-            return array('trap_name_mib'=>$matches[1],'trap_name'=>$matches[2]);
467
+            $this->logging->log('Found name with snmptrapd and not in DB for oid='.$oid, INFO);
468
+            return array('trap_name_mib'=>$matches[1], 'trap_name'=>$matches[2]);
469 469
         }
470 470
     }
471 471
     
@@ -476,90 +476,90 @@  discard block
 block discarded – undo
476 476
      **/
477 477
     public function eraseOldTraps($days=0)
478 478
     {
479
-        if ($days==0)
479
+        if ($days == 0)
480 480
         {
481 481
             if (($days=$this->getDBConfig('db_remove_days')) == null)
482 482
             {
483
-                $this->logging->log('No days specified & no db value : no tap erase' ,WARN,'');
483
+                $this->logging->log('No days specified & no db value : no tap erase', WARN, '');
484 484
                 return;
485 485
             }
486 486
         }
487 487
         $db_conn=$this->trapsDB->db_connect_trap();
488
-        $daysago = strtotime("-".$days." day");
489
-        $sql= 'delete from '.$this->dbPrefix.'received where date_received < \''.date("Y-m-d H:i:s",$daysago).'\';';
488
+        $daysago=strtotime("-".$days." day");
489
+        $sql='delete from '.$this->dbPrefix.'received where date_received < \''.date("Y-m-d H:i:s", $daysago).'\';';
490 490
         if ($db_conn->query($sql) === false) {
491
-            $this->logging->log('Error erasing traps : '.$sql,ERROR,'');
491
+            $this->logging->log('Error erasing traps : '.$sql, ERROR, '');
492 492
         }
493
-        $this->logging->log('Erased traps older than '.$days.' day(s) : '.$sql,INFO);
493
+        $this->logging->log('Erased traps older than '.$days.' day(s) : '.$sql, INFO);
494 494
     }
495 495
     
496 496
     /** Write error to received trap database
497 497
      */
498
-    public function writeTrapErrorToDB($message,$sourceIP=null,$trapoid=null)
498
+    public function writeTrapErrorToDB($message, $sourceIP=null, $trapoid=null)
499 499
     {
500 500
         
501 501
         $db_conn=$this->trapsDB->db_connect_trap();
502 502
         
503 503
         // add date time
504
-        $insert_col ='date_received,status';
505
-        $insert_val = "'" . date("Y-m-d H:i:s")."','error'";
504
+        $insert_col='date_received,status';
505
+        $insert_val="'".date("Y-m-d H:i:s")."','error'";
506 506
         
507
-        if ($sourceIP !=null)
507
+        if ($sourceIP != null)
508 508
         {
509
-            $insert_col .=',source_ip';
510
-            $insert_val .=",'". $sourceIP ."'";
509
+            $insert_col.=',source_ip';
510
+            $insert_val.=",'".$sourceIP."'";
511 511
         }
512
-        if ($trapoid !=null)
512
+        if ($trapoid != null)
513 513
         {
514
-            $insert_col .=',trap_oid';
515
-            $insert_val .=",'". $trapoid ."'";
514
+            $insert_col.=',trap_oid';
515
+            $insert_val.=",'".$trapoid."'";
516 516
         }
517
-        $insert_col .=',status_detail';
518
-        $insert_val .=",'". $message ."'";
517
+        $insert_col.=',status_detail';
518
+        $insert_val.=",'".$message."'";
519 519
         
520
-        $sql= 'INSERT INTO '.$this->dbPrefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')';
520
+        $sql='INSERT INTO '.$this->dbPrefix.'received ('.$insert_col.') VALUES ('.$insert_val.')';
521 521
         
522 522
         switch ($this->trapsDB->trapDBType)
523 523
         {
524 524
             case 'pgsql':
525
-                $sql .= ' RETURNING id;';
526
-                $this->logging->log('sql : '.$sql,INFO);
525
+                $sql.=' RETURNING id;';
526
+                $this->logging->log('sql : '.$sql, INFO);
527 527
                 if (($ret_code=$db_conn->query($sql)) === false) {
528
-                    $this->logging->log('Error SQL insert : '.$sql,1,'');
528
+                    $this->logging->log('Error SQL insert : '.$sql, 1, '');
529 529
                 }
530
-                $this->logging->log('SQL insertion OK',INFO );
530
+                $this->logging->log('SQL insertion OK', INFO);
531 531
                 // Get last id to insert oid/values in secondary table
532 532
                 if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) {
533 533
                     
534
-                    $this->logging->log('Erreur recuperation id',1,'');
534
+                    $this->logging->log('Erreur recuperation id', 1, '');
535 535
                 }
536
-                if (! isset($inserted_id_ret['id'])) {
537
-                    $this->logging->log('Error getting id',1,'');
536
+                if (!isset($inserted_id_ret['id'])) {
537
+                    $this->logging->log('Error getting id', 1, '');
538 538
                 }
539 539
                 $this->trapId=$inserted_id_ret['id'];
540 540
                 break;
541 541
             case 'mysql':
542
-                $sql .= ';';
543
-                $this->logging->log('sql : '.$sql,INFO );
542
+                $sql.=';';
543
+                $this->logging->log('sql : '.$sql, INFO);
544 544
                 if ($db_conn->query($sql) === false) {
545
-                    $this->logging->log('Error SQL insert : '.$sql,1,'');
545
+                    $this->logging->log('Error SQL insert : '.$sql, 1, '');
546 546
                 }
547
-                $this->logging->log('SQL insertion OK',INFO );
547
+                $this->logging->log('SQL insertion OK', INFO);
548 548
                 // Get last id to insert oid/values in secondary table
549 549
                 $sql='SELECT LAST_INSERT_ID();';
550 550
                 if (($ret_code=$db_conn->query($sql)) === false) {
551
-                    $this->logging->log('Erreur recuperation id',1,'');
551
+                    $this->logging->log('Erreur recuperation id', 1, '');
552 552
                 }
553 553
                 
554 554
                 $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
555
-                if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
555
+                if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
556 556
                 $this->trapId=$inserted_id;
557 557
                 break;
558 558
             default:
559
-                $this->logging->log('Error SQL type unknown  : '.$this->trapsDB->trapDBType,1,'');
559
+                $this->logging->log('Error SQL type unknown  : '.$this->trapsDB->trapDBType, 1, '');
560 560
         }
561 561
         
562
-        $this->logging->log('id found: '. $this->trapId,INFO );
562
+        $this->logging->log('id found: '.$this->trapId, INFO);
563 563
     }
564 564
     
565 565
     /** Write trap data to trap database
@@ -576,86 +576,86 @@  discard block
 block discarded – undo
576 576
         $insert_col='';
577 577
         $insert_val='';
578 578
         // add date time
579
-        $this->trapData['date_received'] = date("Y-m-d H:i:s");
579
+        $this->trapData['date_received']=date("Y-m-d H:i:s");
580 580
         
581 581
         $firstcol=1;
582 582
         foreach ($this->trapData as $col => $val)
583 583
         {
584
-            if ($firstcol==0)
584
+            if ($firstcol == 0)
585 585
             {
586
-                $insert_col .=',';
587
-                $insert_val .=',';
586
+                $insert_col.=',';
587
+                $insert_val.=',';
588 588
             }
589
-            $insert_col .= $col ;
590
-            $insert_val .= ($val==null)? 'NULL' : $db_conn->quote($val);
589
+            $insert_col.=$col;
590
+            $insert_val.=($val == null) ? 'NULL' : $db_conn->quote($val);
591 591
             $firstcol=0;
592 592
         }
593 593
         
594
-        $sql= 'INSERT INTO '.$this->dbPrefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')';
594
+        $sql='INSERT INTO '.$this->dbPrefix.'received ('.$insert_col.') VALUES ('.$insert_val.')';
595 595
         switch ($this->trapsDB->trapDBType)
596 596
         {
597 597
             case 'pgsql':
598
-                $sql .= ' RETURNING id;';
599
-                $this->logging->log('sql : '.$sql,INFO );
598
+                $sql.=' RETURNING id;';
599
+                $this->logging->log('sql : '.$sql, INFO);
600 600
                 if (($ret_code=$db_conn->query($sql)) === false) {
601
-                    $this->logging->log('Error SQL insert : '.$sql,ERROR,'');
601
+                    $this->logging->log('Error SQL insert : '.$sql, ERROR, '');
602 602
                 }
603
-                $this->logging->log('SQL insertion OK',INFO );
603
+                $this->logging->log('SQL insertion OK', INFO);
604 604
                 // Get last id to insert oid/values in secondary table
605 605
                 if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) {
606 606
                     
607
-                    $this->logging->log('Erreur recuperation id',ERROR,'');
607
+                    $this->logging->log('Erreur recuperation id', ERROR, '');
608 608
                 }
609
-                if (! isset($inserted_id_ret['id'])) {
610
-                    $this->logging->log('Error getting id',ERROR,'');
609
+                if (!isset($inserted_id_ret['id'])) {
610
+                    $this->logging->log('Error getting id', ERROR, '');
611 611
                 }
612 612
                 $this->trapId=$inserted_id_ret['id'];
613 613
                 break;
614 614
             case 'mysql':
615
-                $sql .= ';';
616
-                $this->logging->log('sql : '.$sql,INFO );
615
+                $sql.=';';
616
+                $this->logging->log('sql : '.$sql, INFO);
617 617
                 if ($db_conn->query($sql) === false) {
618
-                    $this->logging->log('Error SQL insert : '.$sql,ERROR,'');
618
+                    $this->logging->log('Error SQL insert : '.$sql, ERROR, '');
619 619
                 }
620
-                $this->logging->log('SQL insertion OK',INFO );
620
+                $this->logging->log('SQL insertion OK', INFO);
621 621
                 // Get last id to insert oid/values in secondary table
622 622
                 $sql='SELECT LAST_INSERT_ID();';
623 623
                 if (($ret_code=$db_conn->query($sql)) === false) {
624
-                    $this->logging->log('Erreur recuperation id',ERROR,'');
624
+                    $this->logging->log('Erreur recuperation id', ERROR, '');
625 625
                 }
626 626
                 
627 627
                 $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
628
-                if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
628
+                if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
629 629
                 $this->trapId=$inserted_id;
630 630
                 break;
631 631
             default:
632
-                $this->logging->log('Error SQL type unknown : '.$this->trapsDB->trapDBType,ERROR,'');
632
+                $this->logging->log('Error SQL type unknown : '.$this->trapsDB->trapDBType, ERROR, '');
633 633
         }
634
-        $this->logging->log('id found: '.$this->trapId,INFO );
634
+        $this->logging->log('id found: '.$this->trapId, INFO);
635 635
         
636 636
         // Fill trap extended data table
637 637
         foreach ($this->trapDataExt as $value) {
638 638
             // TODO : detect if trap value is encoded and decode it to UTF-8 for database
639 639
             $firstcol=1;
640
-            $value->trap_id = $this->trapId;
640
+            $value->trap_id=$this->trapId;
641 641
             $insert_col='';
642 642
             $insert_val='';
643 643
             foreach ($value as $col => $val)
644 644
             {
645
-                if ($firstcol==0)
645
+                if ($firstcol == 0)
646 646
                 {
647
-                    $insert_col .=',';
648
-                    $insert_val .=',';
647
+                    $insert_col.=',';
648
+                    $insert_val.=',';
649 649
                 }
650
-                $insert_col .= $col;
651
-                $insert_val .= ($val==null)? 'NULL' : $db_conn->quote($val);
650
+                $insert_col.=$col;
651
+                $insert_val.=($val == null) ? 'NULL' : $db_conn->quote($val);
652 652
                 $firstcol=0;
653 653
             }
654 654
             
655
-            $sql= 'INSERT INTO '.$this->dbPrefix.'received_data (' . $insert_col . ') VALUES ('.$insert_val.');';
655
+            $sql='INSERT INTO '.$this->dbPrefix.'received_data ('.$insert_col.') VALUES ('.$insert_val.');';
656 656
             
657 657
             if ($db_conn->query($sql) === false) {
658
-                $this->logging->log('Erreur insertion data : ' . $sql,WARN,'');
658
+                $this->logging->log('Erreur insertion data : '.$sql, WARN, '');
659 659
             }
660 660
         }
661 661
     }
@@ -665,14 +665,14 @@  discard block
 block discarded – undo
665 665
      *	@param $oid string oid in numeric
666 666
      *	@return mixed|boolean : PDO object or false
667 667
      */
668
-    protected function getRules($ip,$oid)
668
+    protected function getRules($ip, $oid)
669 669
     {
670 670
         $db_conn=$this->trapsDB->db_connect_trap();
671 671
         // fetch rules based on IP in rule and OID
672 672
         $sql='SELECT * from '.$this->dbPrefix.'rules WHERE trap_oid=\''.$oid.'\' ';
673
-        $this->logging->log('SQL query : '.$sql,DEBUG );
673
+        $this->logging->log('SQL query : '.$sql, DEBUG);
674 674
         if (($ret_code=$db_conn->query($sql)) === false) {
675
-            $this->logging->log('No result in query : ' . $sql,WARN,'');
675
+            $this->logging->log('No result in query : '.$sql, WARN, '');
676 676
             return false;
677 677
         }
678 678
         $rules_all=$ret_code->fetchAll();
@@ -681,7 +681,7 @@  discard block
 block discarded – undo
681 681
         $rule_ret_key=0;
682 682
         foreach ($rules_all as $key => $rule)
683 683
         {
684
-            if ($rule['ip4']==$ip || $rule['ip6']==$ip)
684
+            if ($rule['ip4'] == $ip || $rule['ip6'] == $ip)
685 685
             {
686 686
                 $rules_ret[$rule_ret_key]=$rules_all[$key];
687 687
                 //TODO : get host name by API (and check if correct in rule).
@@ -689,7 +689,7 @@  discard block
 block discarded – undo
689 689
                 continue;
690 690
             }
691 691
             // TODO : get hosts IP by API
692
-            if (isset($rule['host_group_name']) && $rule['host_group_name']!=null)
692
+            if (isset($rule['host_group_name']) && $rule['host_group_name'] != null)
693 693
             { // get ips of group members by oid
694 694
                 $db_conn2=$this->trapsDB->db_connect_ido();
695 695
                 $sql="SELECT m.host_object_id, a.address as ip4, a.address6 as ip6, b.name1 as host_name
@@ -700,15 +700,15 @@  discard block
 block discarded – undo
700 700
 						LEFT JOIN icinga_objects as b ON b.object_id = a.host_object_id
701 701
 						WHERE o.name1='".$rule['host_group_name']."';";
702 702
                 if (($ret_code2=$db_conn2->query($sql)) === false) {
703
-                    $this->logging->log('No result in query : ' . $sql,WARN,'');
703
+                    $this->logging->log('No result in query : '.$sql, WARN, '');
704 704
                     continue;
705 705
                 }
706 706
                 $grouphosts=$ret_code2->fetchAll();
707 707
                 //echo "rule grp :\n";print_r($grouphosts);echo "\n";
708
-                foreach ( $grouphosts as $host)
708
+                foreach ($grouphosts as $host)
709 709
                 {
710 710
                     //echo $host['ip4']."\n";
711
-                    if ($host['ip4']==$ip || $host['ip6']==$ip)
711
+                    if ($host['ip4'] == $ip || $host['ip6'] == $ip)
712 712
                     {
713 713
                         //echo "Rule added \n";
714 714
                         $rules_ret[$rule_ret_key]=$rules_all[$key];
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
         $db_conn=$this->trapsDB->db_connect_trap();
732 732
         $sql="UPDATE ".$this->dbPrefix."rules SET num_match = '".$set."' WHERE (id = '".$id."');";
733 733
         if ($db_conn->query($sql) === false) {
734
-            $this->logging->log('Error in update query : ' . $sql,WARN,'');
734
+            $this->logging->log('Error in update query : '.$sql, WARN, '');
735 735
         }
736 736
     }
737 737
     
@@ -743,23 +743,23 @@  discard block
 block discarded – undo
743 743
      * @param string $display
744 744
      * @returnn bool true is service check was sent without error
745 745
      */
746
-    public function serviceCheckResult($host,$service,$state,$display)
746
+    public function serviceCheckResult($host, $service, $state, $display)
747 747
     {
748 748
         if ($this->apiUse === false)
749 749
         {
750
-            $send = '[' . date('U') .'] PROCESS_SERVICE_CHECK_RESULT;' .
751
-                $host.';' .$service .';' . $state . ';'.$display;
752
-                $this->logging->log( $send." : to : " .$this->icinga2cmd,INFO );
750
+            $send='['.date('U').'] PROCESS_SERVICE_CHECK_RESULT;'.
751
+                $host.';'.$service.';'.$state.';'.$display;
752
+                $this->logging->log($send." : to : ".$this->icinga2cmd, INFO);
753 753
                 
754 754
                 // TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default....
755
-                exec('echo "'.$send.'" > ' .$this->icinga2cmd);
755
+                exec('echo "'.$send.'" > '.$this->icinga2cmd);
756 756
                 return true;
757 757
         }
758 758
         else
759 759
         {
760 760
             // Get perfdata if found
761 761
             $matches=array();
762
-            if (preg_match('/(.*)\|(.*)/',$display,$matches) == 1)
762
+            if (preg_match('/(.*)\|(.*)/', $display, $matches) == 1)
763 763
             {
764 764
                 $display=$matches[1];
765 765
                 $perfdata=$matches[2];
@@ -769,17 +769,17 @@  discard block
 block discarded – undo
769 769
                 $perfdata='';
770 770
             }
771 771
             
772
-            $api = $this->getAPI();
772
+            $api=$this->getAPI();
773 773
             $api->setCredentials($this->apiUsername, $this->apiPassword);
774
-            list($retcode,$retmessage)=$api->serviceCheckResult($host,$service,$state,$display,$perfdata);
774
+            list($retcode, $retmessage)=$api->serviceCheckResult($host, $service, $state, $display, $perfdata);
775 775
             if ($retcode == false)
776 776
             {
777
-                $this->logging->log( "Error sending result : " .$retmessage,WARN,'');
777
+                $this->logging->log("Error sending result : ".$retmessage, WARN, '');
778 778
                 return false;
779 779
             }
780 780
             else
781 781
             {
782
-                $this->logging->log( "Sent result : " .$retmessage,INFO );
782
+                $this->logging->log("Sent result : ".$retmessage, INFO);
783 783
                 return true;
784 784
             }
785 785
         }
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
     
788 788
     public function getHostByIP($ip)
789 789
     {
790
-        $api = $this->getAPI();
790
+        $api=$this->getAPI();
791 791
         $api->setCredentials($this->apiUsername, $this->apiPassword);
792 792
         return $api->getHostByIP($ip);
793 793
     }
@@ -800,35 +800,35 @@  discard block
 block discarded – undo
800 800
     protected function applyDisplay($display)
801 801
     {
802 802
         $matches=array();
803
-        while (preg_match('/_OID\(([0-9\.\*]+)\)/',$display,$matches) == 1)
803
+        while (preg_match('/_OID\(([0-9\.\*]+)\)/', $display, $matches) == 1)
804 804
         {
805 805
             $oid=$matches[1];
806 806
             $found=0;
807 807
             // Test and transform regexp
808
-            $oidR = $this->ruleClass->regexp_eval($oid);
808
+            $oidR=$this->ruleClass->regexp_eval($oid);
809 809
             
810
-            foreach($this->trapDataExt as $val)
810
+            foreach ($this->trapDataExt as $val)
811 811
             {
812
-                if (preg_match("/^$oidR$/",$val->oid) == 1)
812
+                if (preg_match("/^$oidR$/", $val->oid) == 1)
813 813
                 {
814
-                    $val->value=preg_replace('/"/','',$val->value);
814
+                    $val->value=preg_replace('/"/', '', $val->value);
815 815
                     $rep=0;
816
-                    $display=preg_replace('/_OID\('.$oid.'\)/',$val->value,$display,-1,$rep);
817
-                    if ($rep==0)
816
+                    $display=preg_replace('/_OID\('.$oid.'\)/', $val->value, $display, -1, $rep);
817
+                    if ($rep == 0)
818 818
                     {
819
-                        $this->logging->log("Error in display",WARN,'');
819
+                        $this->logging->log("Error in display", WARN, '');
820 820
                         return $display;
821 821
                     }
822 822
                     $found=1;
823 823
                     break;
824 824
                 }
825 825
             }
826
-            if ($found==0)
826
+            if ($found == 0)
827 827
             {
828
-                $display=preg_replace('/_OID\('.$oid.'\)/','<not in trap>',$display,-1,$rep);
829
-                if ($rep==0)
828
+                $display=preg_replace('/_OID\('.$oid.'\)/', '<not in trap>', $display, -1, $rep);
829
+                if ($rep == 0)
830 830
                 {
831
-                    $this->logging->log("Error in display",WARN,'');
831
+                    $this->logging->log("Error in display", WARN, '');
832 832
                     return $display;
833 833
                 }
834 834
             }
@@ -840,11 +840,11 @@  discard block
 block discarded – undo
840 840
      */
841 841
     public function applyRules()
842 842
     {
843
-        $rules = $this->getRules($this->trapData['source_ip'],$this->trapData['trap_oid']);
843
+        $rules=$this->getRules($this->trapData['source_ip'], $this->trapData['trap_oid']);
844 844
         
845
-        if ($rules===false || count($rules)==0)
845
+        if ($rules === false || count($rules) == 0)
846 846
         {
847
-            $this->logging->log('No rules found for this trap',INFO );
847
+            $this->logging->log('No rules found for this trap', INFO);
848 848
             $this->trapData['status']='unknown';
849 849
             $this->trapToDb=true;
850 850
             return;
@@ -859,59 +859,59 @@  discard block
 block discarded – undo
859 859
             $service_name=$rule['service_name'];
860 860
             
861 861
             $display=$this->applyDisplay($rule['display']);
862
-            $this->trapAction = ($this->trapAction==null)? '' : $this->trapAction . ', ';
862
+            $this->trapAction=($this->trapAction == null) ? '' : $this->trapAction.', ';
863 863
             try
864 864
             {
865
-                $this->logging->log('Rule to eval : '.$rule['rule'],INFO );
866
-                $evalr=$this->ruleClass->eval_rule($rule['rule'], $this->trapDataExt) ;
865
+                $this->logging->log('Rule to eval : '.$rule['rule'], INFO);
866
+                $evalr=$this->ruleClass->eval_rule($rule['rule'], $this->trapDataExt);
867 867
                 //->eval_rule($rule['rule']);
868 868
                 
869 869
                 if ($evalr == true)
870 870
                 {
871 871
                     //$this->logging->log('rules OOK: '.print_r($rule),INFO );
872 872
                     $action=$rule['action_match'];
873
-                    $this->logging->log('action OK : '.$action,INFO );
873
+                    $this->logging->log('action OK : '.$action, INFO);
874 874
                     if ($action >= 0)
875 875
                     {
876
-                        if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false)
876
+                        if ($this->serviceCheckResult($host_name, $service_name, $action, $display) == false)
877 877
                         {
878 878
                             $this->trapAction.='Error sending status : check cmd/API';
879 879
                         }
880 880
                         else
881 881
                         {
882
-                            $this->add_rule_match($rule['id'],$rule['num_match']+1);
882
+                            $this->add_rule_match($rule['id'], $rule['num_match'] + 1);
883 883
                             $this->trapAction.='Status '.$action.' to '.$host_name.'/'.$service_name;
884 884
                         }
885 885
                     }
886 886
                     else
887 887
                     {
888
-                        $this->add_rule_match($rule['id'],$rule['num_match']+1);
888
+                        $this->add_rule_match($rule['id'], $rule['num_match'] + 1);
889 889
                     }
890
-                    $this->trapToDb=($action==-2)?false:true;
890
+                    $this->trapToDb=($action == -2) ?false:true;
891 891
                 }
892 892
                 else
893 893
                 {
894 894
                     //$this->logging->log('rules KOO : '.print_r($rule),INFO );
895 895
                     
896 896
                     $action=$rule['action_nomatch'];
897
-                    $this->logging->log('action NOK : '.$action,INFO );
897
+                    $this->logging->log('action NOK : '.$action, INFO);
898 898
                     if ($action >= 0)
899 899
                     {
900
-                        if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false)
900
+                        if ($this->serviceCheckResult($host_name, $service_name, $action, $display) == false)
901 901
                         {
902 902
                             $this->trapAction.='Error sending status : check cmd/API';
903 903
                         }
904 904
                         else
905 905
                         {
906
-                            $this->add_rule_match($rule['id'],$rule['num_match']+1);
906
+                            $this->add_rule_match($rule['id'], $rule['num_match'] + 1);
907 907
                             $this->trapAction.='Status '.$action.' to '.$host_name.'/'.$service_name;
908 908
                         }
909 909
                     }
910 910
                     else
911 911
                     {
912
-                        $this->add_rule_match($rule['id'],$rule['num_match']+1);
912
+                        $this->add_rule_match($rule['id'], $rule['num_match'] + 1);
913 913
                     }
914
-                    $this->trapToDb=($action==-2)?false:true;
914
+                    $this->trapToDb=($action == -2) ?false:true;
915 915
                 }
916 916
                 // Put name in source_name
917 917
                 if (!isset($this->trapData['source_name']))
@@ -920,7 +920,7 @@  discard block
 block discarded – undo
920 920
                 }
921 921
                 else
922 922
                 {
923
-                    if (!preg_match('/'.$rule['host_name'].'/',$this->trapData['source_name']))
923
+                    if (!preg_match('/'.$rule['host_name'].'/', $this->trapData['source_name']))
924 924
                     { // only add if not present
925 925
                         $this->trapData['source_name'].=','.$rule['host_name'];
926 926
                     }
@@ -928,13 +928,13 @@  discard block
 block discarded – undo
928 928
             }
929 929
             catch (Exception $e)
930 930
             {
931
-                $this->logging->log('Error in rule eval : '.$e->getMessage(),WARN,'');
931
+                $this->logging->log('Error in rule eval : '.$e->getMessage(), WARN, '');
932 932
                 $this->trapAction.=' ERR : '.$e->getMessage();
933 933
                 $this->trapData['status']='error';
934 934
             }
935 935
             
936 936
         }
937
-        if ($this->trapData['status']=='error')
937
+        if ($this->trapData['status'] == 'error')
938 938
         {
939 939
             $this->trapToDb=true; // Always put errors in DB for the use can see
940 940
         }
@@ -950,13 +950,13 @@  discard block
 block discarded – undo
950 950
     public function add_rule_final($time)
951 951
     {
952 952
         $db_conn=$this->trapsDB->db_connect_trap();
953
-        if ($this->trapAction==null)
953
+        if ($this->trapAction == null)
954 954
         {
955 955
             $this->trapAction='No action';
956 956
         }
957 957
         $sql="UPDATE ".$this->dbPrefix."received SET process_time = '".$time."' , status_detail='".$this->trapAction."'  WHERE (id = '".$this->trapId."');";
958 958
         if ($db_conn->query($sql) === false) {
959
-            $this->logging->log('Error in update query : ' . $sql,WARN,'');
959
+            $this->logging->log('Error in update query : '.$sql, WARN, '');
960 960
         }
961 961
     }
962 962
     
@@ -979,7 +979,7 @@  discard block
 block discarded – undo
979 979
     WHERE s.current_state != 0;";
980 980
         $db_conn=$this->trapsDB->db_connect_ido();
981 981
         if (($services_db=$db_conn->query($sql_query)) === false) { // set err to 1 to throw exception.
982
-            $this->logging->log('No result in query : ' . $sql_query,ERROR,'');
982
+            $this->logging->log('No result in query : '.$sql_query, ERROR, '');
983 983
             return 0;
984 984
         }
985 985
         $services=$services_db->fetchAll();
@@ -988,7 +988,7 @@  discard block
 block discarded – undo
988 988
         $sql_query="SELECT host_name, service_name, revert_ok FROM ".$this->dbPrefix."rules where revert_ok != 0;";
989 989
         $db_conn2=$this->trapsDB->db_connect_trap();
990 990
         if (($rules_db=$db_conn2->query($sql_query)) === false) {
991
-            $this->logging->log('No result in query : ' . $sql_query,ERROR,'');
991
+            $this->logging->log('No result in query : '.$sql_query, ERROR, '');
992 992
             return 0;
993 993
         }
994 994
         $rules=$rules_db->fetchAll();
@@ -1004,13 +1004,13 @@  discard block
 block discarded – undo
1004 1004
                     $service['host_name'] == $rule['host_name'] &&
1005 1005
                     ($service['last_check'] + $rule['revert_ok']) < $now)
1006 1006
                 {
1007
-                    $this->serviceCheckResult($service['host_name'],$service['service_name'],0,'Reset service to OK after '.$rule['revert_ok'].' seconds');
1007
+                    $this->serviceCheckResult($service['host_name'], $service['service_name'], 0, 'Reset service to OK after '.$rule['revert_ok'].' seconds');
1008 1008
                     $numreset++;
1009 1009
                 }
1010 1010
             }
1011 1011
         }
1012 1012
         echo "\n";
1013
-        echo $numreset . " service(s) reset to OK\n";
1013
+        echo $numreset." service(s) reset to OK\n";
1014 1014
         return 0;
1015 1015
         
1016 1016
     }
Please login to merge, or discard this patch.
library/Trapdirector/TrapsController.php 1 patch
Spacing   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -22,14 +22,14 @@  discard block
 block discarded – undo
22 22
 
23 23
 class TrapsController extends Controller
24 24
 {
25
-	protected $moduleConfig;  	//< TrapModuleConfig instance
26
-	protected $trapTableList; 	//< TrapTableList (by date)
27
-	protected $trapTableHostList; 	//< TrapTableList (by hosts)
28
-	protected $handlerTableList; 	//< HandlerTableList instance
29
-	protected $trapDB;			//< Trap database
30
-	protected $icingaDB;		//< Icinga IDO database;
31
-	protected $MIBData; 		//< MIBLoader class
32
-	protected $trapClass;		//< Trap class for bin/trap_class.php
25
+	protected $moduleConfig; //< TrapModuleConfig instance
26
+	protected $trapTableList; //< TrapTableList (by date)
27
+	protected $trapTableHostList; //< TrapTableList (by hosts)
28
+	protected $handlerTableList; //< HandlerTableList instance
29
+	protected $trapDB; //< Trap database
30
+	protected $icingaDB; //< Icinga IDO database;
31
+	protected $MIBData; //< MIBLoader class
32
+	protected $trapClass; //< Trap class for bin/trap_class.php
33 33
 		
34 34
 	/** Get instance of TrapModuleConfig class
35 35
 	*	@return TrapModuleConfig
@@ -43,14 +43,14 @@  discard block
 block discarded – undo
43 43
 			{
44 44
 				$this->redirectNow('trapdirector/settings?message=No database prefix');
45 45
 			}
46
-			$this->moduleConfig = new TrapModuleConfig($db_prefix);
46
+			$this->moduleConfig=new TrapModuleConfig($db_prefix);
47 47
 		}
48 48
 		return $this->moduleConfig;
49 49
 	}
50 50
 	
51 51
 	public function getTrapListTable() {
52 52
 		if ($this->trapTableList == Null) {
53
-			$this->trapTableList = new TrapTableList();
53
+			$this->trapTableList=new TrapTableList();
54 54
 			$this->trapTableList->setConfig($this->getModuleConfig());
55 55
 		}
56 56
 		return $this->trapTableList;
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	{
61 61
 	    if ($this->trapTableHostList == Null) 
62 62
 		{
63
-	        $this->trapTableHostList = new TrapTableHostList();
63
+	        $this->trapTableHostList=new TrapTableHostList();
64 64
 	        $this->trapTableHostList->setConfig($this->getModuleConfig());
65 65
 	    }
66 66
 	    return $this->trapTableHostList;
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 	{
71 71
 		if ($this->handlerTableList == Null) 
72 72
 		{
73
-			$this->handlerTableList = new HandlerTableList();
73
+			$this->handlerTableList=new HandlerTableList();
74 74
 			$this->handlerTableList->setConfig($this->getModuleConfig());
75 75
 		}
76 76
 		return $this->handlerTableList;
@@ -82,15 +82,15 @@  discard block
 block discarded – undo
82 82
 	*	@param $test_version bool if set to flase, does not test database version of trapDB
83 83
 	*	@return array<integer,mixed>|mixed : if test=false, returns DB connexion, else array(error_num,message) or null on error.
84 84
 	*/
85
-	public function getDbByName($DBname,$test=false,$test_version=true)
85
+	public function getDbByName($DBname, $test=false, $test_version=true)
86 86
 	{
87 87
 		try 
88 88
 		{
89
-			$dbconn = IcingaDbConnection::fromResourceName($DBname);
89
+			$dbconn=IcingaDbConnection::fromResourceName($DBname);
90 90
 		} 
91 91
 		catch (Exception $e)
92 92
 		{
93
-			if ($test) return array(2,$DBname);
93
+			if ($test) return array(2, $DBname);
94 94
 			$this->redirectNow('trapdirector/settings?dberror=2');
95 95
 			return null;
96 96
 		}
@@ -101,37 +101,37 @@  discard block
 block discarded – undo
101 101
 			}
102 102
 			catch (Exception $e) 
103 103
 			{
104
-				if ($test) return array(3,$DBname,$e->getMessage());
104
+				if ($test) return array(3, $DBname, $e->getMessage());
105 105
 				$this->redirectNow('trapdirector/settings?dberror=3');
106 106
 				return null;
107 107
 			}
108 108
 			try
109 109
 			{
110
-				$query = $db->select()
111
-					->from($this->getModuleConfig()->getDbConfigTableName(),'value')
110
+				$query=$db->select()
111
+					->from($this->getModuleConfig()->getDbConfigTableName(), 'value')
112 112
 					->where('name=\'db_version\'');
113 113
 				$version=$db->fetchRow($query);
114
-				if ( ($version == null) || ! property_exists($version,'value') )
114
+				if (($version == null) || !property_exists($version, 'value'))
115 115
 				{
116
-					if ($test) return array(4,$DBname);
116
+					if ($test) return array(4, $DBname);
117 117
 					$this->redirectNow('trapdirector/settings?dberror=4');
118 118
 					return null;
119 119
 				}
120 120
 				if ($version->value < $this->getModuleConfig()->getDbMinVersion()) 
121 121
 				{
122
-					if ($test) return array(5,$version->value,$this->getModuleConfig()->getDbMinVersion());
122
+					if ($test) return array(5, $version->value, $this->getModuleConfig()->getDbMinVersion());
123 123
 					$this->redirectNow('trapdirector/settings?dberror=5');
124 124
 					return null;
125 125
 				}
126 126
 			}
127 127
 			catch (Exception $e) 
128 128
 			{
129
-				if ($test) return array(3,$DBname,$e->getMessage());
129
+				if ($test) return array(3, $DBname, $e->getMessage());
130 130
 				$this->redirectNow('trapdirector/settings?dberror=4');
131 131
 				return null;
132 132
 			}
133 133
 		}
134
-		if ($test) return array(0,'');
134
+		if ($test) return array(0, '');
135 135
 		return $dbconn;
136 136
 	}
137 137
 
@@ -142,17 +142,17 @@  discard block
 block discarded – undo
142 142
 	 */
143 143
 	public function getDb($test=false)
144 144
 	{
145
-		if ($this->trapDB != null && $test = false) return $this->trapDB;
145
+		if ($this->trapDB != null && $test=false) return $this->trapDB;
146 146
 		
147 147
 		$dbresource=$this->Config()->get('config', 'database');
148 148
 		
149
-		if ( ! $dbresource )
149
+		if (!$dbresource)
150 150
 		{	
151
-			if ($test) return array(1,'');
151
+			if ($test) return array(1, '');
152 152
 			$this->redirectNow('trapdirector/settings?dberror=1');
153 153
 			return null;
154 154
 		}
155
-		$retDB=$this->getDbByName($dbresource,$test,true);
155
+		$retDB=$this->getDbByName($dbresource, $test, true);
156 156
 		if ($test === true) return $retDB;
157 157
 		$this->trapDB=$retDB;
158 158
 		return $this->trapDB;
@@ -160,78 +160,78 @@  discard block
 block discarded – undo
160 160
 	
161 161
 	public function getIdoDb($test=false)
162 162
 	{
163
-		if ($this->icingaDB != null && $test = false) return $this->icingaDB;
163
+		if ($this->icingaDB != null && $test=false) return $this->icingaDB;
164 164
 		// TODO : get ido database directly from icingaweb2 config -> (or not if using only API)
165
-		$dbresource=$this->Config()->get('config', 'IDOdatabase');;
165
+		$dbresource=$this->Config()->get('config', 'IDOdatabase'); ;
166 166
 
167
-		if ( ! $dbresource )
167
+		if (!$dbresource)
168 168
 		{
169
-		    if ($test) return array(1,'No database in config.ini');
169
+		    if ($test) return array(1, 'No database in config.ini');
170 170
 		    $this->redirectNow('trapdirector/settings?idodberror=1');
171 171
 		    return null;
172 172
 		}
173 173
 		
174 174
 		try
175 175
 		{
176
-		    $dbconn = IcingaDbConnection::fromResourceName($dbresource);
176
+		    $dbconn=IcingaDbConnection::fromResourceName($dbresource);
177 177
 		}
178 178
 		catch (Exception $e)
179 179
 		{
180
-		    if ($test) return array(2,"Database $dbresource does not exists in IcingaWeb2");
180
+		    if ($test) return array(2, "Database $dbresource does not exists in IcingaWeb2");
181 181
 		    $this->redirectNow('trapdirector/settings?idodberror=2');
182 182
 		    return null;
183 183
 		}
184 184
 		
185 185
 		if ($test == false) 
186 186
 		{ 
187
-			$this->icingaDB = $dbconn; 
187
+			$this->icingaDB=$dbconn; 
188 188
 			return $this->icingaDB;
189 189
 		}
190 190
 		
191 191
 		try
192 192
 		{
193
-		    $query = $dbconn->select()
194
-		    ->from('icinga_dbversion',array('version'));
193
+		    $query=$dbconn->select()
194
+		    ->from('icinga_dbversion', array('version'));
195 195
 		    $version=$dbconn->fetchRow($query);
196
-		    if ( ($version == null) || ! property_exists($version,'version') )
196
+		    if (($version == null) || !property_exists($version, 'version'))
197 197
 		    {
198
-		        return array(4,"$dbresource does not look like an IDO database");
198
+		        return array(4, "$dbresource does not look like an IDO database");
199 199
 		    }
200 200
 		}
201 201
 		catch (Exception $e)
202 202
 		{
203
-			return array(3,"Error connecting to $dbresource : " . $e->getMessage());
203
+			return array(3, "Error connecting to $dbresource : ".$e->getMessage());
204 204
 		}
205 205
 		
206
-		return array(0,'');
206
+		return array(0, '');
207 207
 	}
208 208
 	
209
-    protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
209
+    protected function applyPaginationLimits(Paginatable $paginatable, $limit=25, $offset=null)
210 210
     {
211
-        $limit = $this->params->get('limit', $limit);
212
-        $page = $this->params->get('page', $offset);
211
+        $limit=$this->params->get('limit', $limit);
212
+        $page=$this->params->get('page', $offset);
213 213
 
214 214
         $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
215 215
 
216 216
         return $paginatable;
217 217
     }	
218 218
 	
219
-	public function displayExitError($source,$message)
219
+	public function displayExitError($source, $message)
220 220
 	{	// TODO : check better ways to transmit data (with POST ?)
221 221
 		$this->redirectNow('trapdirector/error?source='.$source.'&message='.$message);
222 222
 	}
223 223
 	
224 224
 	protected function checkReadPermission()
225 225
 	{
226
-        if (! $this->Auth()->hasPermission('trapdirector/view')) {
227
-            $this->displayExitError('Permissions','No permission fo view content');
226
+        if (!$this->Auth()->hasPermission('trapdirector/view')) {
227
+            $this->displayExitError('Permissions', 'No permission fo view content');
228 228
         }		
229 229
 	}
230 230
 
231 231
 	protected function checkConfigPermission()
232 232
 	{
233
-        if (! $this->Auth()->hasPermission('trapdirector/config')) {
234
-            $this->displayExitError('Permissions','No permission fo configure');
233
+        if (!$this->Auth()->hasPermission('trapdirector/config')) {
234
+            $this->displayExitError('Permissions', 'No permission fo configure');
235 235
         }		
236 236
 	}
237 237
 	
@@ -242,10 +242,10 @@  discard block
 block discarded – undo
242 242
      */
243 243
 	protected function checkModuleConfigPermission($check=0)
244 244
 	{
245
-        if (! $this->Auth()->hasPermission('trapdirector/module_config')) {
245
+        if (!$this->Auth()->hasPermission('trapdirector/module_config')) {
246 246
             if ($check == 0)
247 247
             {
248
-                $this->displayExitError('Permissions','No permission fo configure module');
248
+                $this->displayExitError('Permissions', 'No permission fo configure module');
249 249
             }
250 250
             return false;
251 251
         }
@@ -257,10 +257,10 @@  discard block
 block discarded – undo
257 257
 	{ // TODO : try/catch here ? or within caller
258 258
 		if ($this->trapClass == null)
259 259
 		{
260
-			require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
260
+			require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
261 261
 			$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
262 262
 			//$debug_level=4;
263
-			$this->trapClass = new Trap($icingaweb2_etc);
263
+			$this->trapClass=new Trap($icingaweb2_etc);
264 264
 			//$Trap->setLogging($debug_level,'syslog');
265 265
 		}
266 266
 		return $this->trapClass;
@@ -294,12 +294,12 @@  discard block
 block discarded – undo
294 294
 	protected function getHostByIP($ip) 
295 295
 	{
296 296
 		// select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
297
-		$db = $this->getIdoDb()->getConnection();
297
+		$db=$this->getIdoDb()->getConnection();
298 298
 		// TODO : check for SQL injections
299 299
 		$query=$db->select()
300 300
 				->from(
301 301
 					array('a' => 'icinga_objects'),
302
-					array('name' => 'a.name1','id' => 'object_id'))
302
+					array('name' => 'a.name1', 'id' => 'object_id'))
303 303
 				->join(
304 304
 					array('b' => 'icinga_hosts'),
305 305
 					'b.host_object_id=a.object_id',
@@ -315,12 +315,12 @@  discard block
 block discarded – undo
315 315
 	protected function getHostByName($name) 
316 316
 	{
317 317
 		// select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
318
-		$db = $this->getIdoDb()->getConnection();
318
+		$db=$this->getIdoDb()->getConnection();
319 319
 		// TODO : check for SQL injections
320 320
 		$query=$db->select()
321 321
 				->from(
322 322
 					array('a' => 'icinga_objects'),
323
-					array('name' => 'a.name1','id' => 'object_id'))
323
+					array('name' => 'a.name1', 'id' => 'object_id'))
324 324
 				->join(
325 325
 					array('b' => 'icinga_hosts'),
326 326
 					'b.host_object_id=a.object_id',
@@ -336,12 +336,12 @@  discard block
 block discarded – undo
336 336
 	protected function getHostGroupByName($ip) 
337 337
 	{
338 338
 		// select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
339
-		$db = $this->getIdoDb()->getConnection();
339
+		$db=$this->getIdoDb()->getConnection();
340 340
 		// TODO : check for SQL injections
341 341
 		$query=$db->select()
342 342
 				->from(
343 343
 					array('a' => 'icinga_objects'),
344
-					array('name' => 'a.name1','id' => 'object_id'))
344
+					array('name' => 'a.name1', 'id' => 'object_id'))
345 345
 				->join(
346 346
 					array('b' => 'icinga_hostgroups'),
347 347
 					'b.hostgroup_object_id=a.object_id',
@@ -357,8 +357,8 @@  discard block
 block discarded – undo
357 357
 	*/
358 358
 	protected function getHostInfoByID($id) 
359 359
 	{
360
-		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
361
-		$db = $this->getIdoDb()->getConnection();
360
+		if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
361
+		$db=$this->getIdoDb()->getConnection();
362 362
 		$query=$db->select()
363 363
 				->from(
364 364
 					array('a' => 'icinga_objects'),
@@ -378,17 +378,17 @@  discard block
 block discarded – undo
378 378
 	*/
379 379
 	protected function getHostByObjectID($id) // TODO : duplicate of getHostInfoByID above
380 380
 	{
381
-		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
382
-		$db = $this->getIdoDb()->getConnection();
381
+		if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
382
+		$db=$this->getIdoDb()->getConnection();
383 383
 		$query=$db->select()
384 384
 				->from(
385 385
 					array('a' => 'icinga_objects'),
386
-					array('name' => 'a.name1','id' => 'a.object_id'))
386
+					array('name' => 'a.name1', 'id' => 'a.object_id'))
387 387
 				->join(
388 388
 					array('b' => 'icinga_hosts'),
389 389
 					'b.host_object_id=a.object_id',
390
-					array('display_name' => 'b.display_name' , 'ip' => 'b.address', 'ip6' => 'b.address6'))
391
-				->where('a.object_id = ?',$id);
390
+					array('display_name' => 'b.display_name', 'ip' => 'b.address', 'ip6' => 'b.address6'))
391
+				->where('a.object_id = ?', $id);
392 392
 		return $db->fetchRow($query);
393 393
 	}	
394 394
 	
@@ -400,16 +400,16 @@  discard block
 block discarded – undo
400 400
 	protected function getServicesByHostid($id) 
401 401
 	{
402 402
 		// select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
403
-		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
404
-		$db = $this->getIdoDb()->getConnection();
403
+		if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
404
+		$db=$this->getIdoDb()->getConnection();
405 405
 		$query=$db->select()
406 406
 				->from(
407 407
 					array('s' => 'icinga_services'),
408
-					array('name' => 's.display_name','id' => 's.service_object_id'))
408
+					array('name' => 's.display_name', 'id' => 's.service_object_id'))
409 409
 				->join(
410 410
 					array('a' => 'icinga_objects'),
411 411
 					's.service_object_id=a.object_id',
412
-					array('is_active'=>'a.is_active','name2'=>'a.name2'))
412
+					array('is_active'=>'a.is_active', 'name2'=>'a.name2'))
413 413
 				->where('s.host_object_id='.$id.' AND a.is_active = 1');
414 414
 		return $db->fetchAll($query);
415 415
 	}	
@@ -422,8 +422,8 @@  discard block
 block discarded – undo
422 422
 	*/
423 423
 	protected function getServicesByHostGroupid($id) 
424 424
 	{		
425
-		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
426
-		$db = $this->getIdoDb()->getConnection();
425
+		if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
426
+		$db=$this->getIdoDb()->getConnection();
427 427
 		$query=$db->select()
428 428
 				->from(
429 429
 					array('s' => 'icinga_hostgroup_members'),
@@ -439,11 +439,11 @@  discard block
 block discarded – undo
439 439
 		foreach ($hosts as $key => $host)
440 440
 		{ // For each host, get all services and add in common_services if not found or add counter
441 441
 			$host_services=$this->getServicesByHostid($host->host_object_id);
442
-			foreach($host_services as $service)
442
+			foreach ($host_services as $service)
443 443
 			{
444 444
 				if (isset($common_services[$service->name2]['num']))
445 445
 				{
446
-					$common_services[$service->name2]['num'] +=1;
446
+					$common_services[$service->name2]['num']+=1;
447 447
 				}
448 448
 				else
449 449
 				{
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
 		{
460 460
 		    if ($common_services[$key]['num'] == $num_hosts)
461 461
 			{
462
-				array_push($result,array($key,$common_services[$key]['name']));
462
+				array_push($result, array($key, $common_services[$key]['name']));
463 463
 			}
464 464
 		}
465 465
 		
@@ -472,9 +472,9 @@  discard block
 block discarded – undo
472 472
 	*	@param $name string service name
473 473
 	*	@return array  service id
474 474
 	*/
475
-	protected function getServiceIDByName($hostname,$name) 
475
+	protected function getServiceIDByName($hostname, $name) 
476 476
 	{
477
-		$db = $this->getIdoDb()->getConnection();
477
+		$db=$this->getIdoDb()->getConnection();
478 478
 		if ($name == null)
479 479
 		{
480 480
 			return array();
@@ -483,7 +483,7 @@  discard block
 block discarded – undo
483 483
 		$query=$db->select()
484 484
 				->from(
485 485
 					array('s' => 'icinga_services'),
486
-					array('name' => 's.display_name','id' => 's.service_object_id'))
486
+					array('name' => 's.display_name', 'id' => 's.service_object_id'))
487 487
 				->join(
488 488
 					array('a' => 'icinga_objects'),
489 489
 					's.service_object_id=a.object_id',
@@ -501,12 +501,12 @@  discard block
 block discarded – undo
501 501
 	protected function getObjectNameByid($id) 
502 502
 	{
503 503
 		// select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
504
-		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
505
-		$db = $this->getIdoDb()->getConnection();
504
+		if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
505
+		$db=$this->getIdoDb()->getConnection();
506 506
 		$query=$db->select()
507 507
 				->from(
508 508
 					array('a' => 'icinga_objects'),
509
-					array('name1' => 'a.name1','name2' => 'a.name2'))
509
+					array('name1' => 'a.name1', 'name2' => 'a.name2'))
510 510
 				->where('a.object_id='.$id.' AND a.is_active = 1');
511 511
 
512 512
 		return $db->fetchRow($query);
@@ -519,17 +519,17 @@  discard block
 block discarded – undo
519 519
 	protected function addHandlerRule($params)
520 520
 	{
521 521
 		// TODO Check for rule consistency
522
-		$db = $this->getDb()->getConnection();
522
+		$db=$this->getDb()->getConnection();
523 523
 		// Add last modified date = creation date and username
524
-		$params['created'] = new Zend_Db_Expr('NOW()');
525
-		$params['modified'] = new 	Zend_Db_Expr('NOW()');
526
-		$params['modifier'] = $this->Auth()->getUser()->getUsername();
524
+		$params['created']=new Zend_Db_Expr('NOW()');
525
+		$params['modified']=new 	Zend_Db_Expr('NOW()');
526
+		$params['modifier']=$this->Auth()->getUser()->getUsername();
527 527
 		
528 528
 		$query=$db->insert(
529 529
 			$this->getModuleConfig()->getTrapRuleName(),
530 530
 			$params
531 531
 		);
532
-		if($query==false)
532
+		if ($query == false)
533 533
 		{
534 534
 		  return null;
535 535
 		}
@@ -541,13 +541,13 @@  discard block
 block discarded – undo
541 541
 	*   @param integer $ruleID : rule id in db
542 542
 	*	@return array affected rows
543 543
 	*/
544
-	protected function updateHandlerRule($params,$ruleID)
544
+	protected function updateHandlerRule($params, $ruleID)
545 545
 	{
546 546
 		// TODO Check for rule consistency
547
-		$db = $this->getDb()->getConnection();
547
+		$db=$this->getDb()->getConnection();
548 548
 		// Add last modified date = creation date and username
549
-		$params['modified'] = new 	Zend_Db_Expr('NOW()');
550
-		$params['modifier'] = $this->Auth()->getUser()->getUsername();
549
+		$params['modified']=new 	Zend_Db_Expr('NOW()');
550
+		$params['modifier']=$this->Auth()->getUser()->getUsername();
551 551
 		
552 552
 		$numRows=$db->update(
553 553
 			$this->getModuleConfig()->getTrapRuleName(),
@@ -562,8 +562,8 @@  discard block
 block discarded – undo
562 562
 	*/
563 563
 	protected function deleteRule($ruleID)
564 564
 	{
565
-		if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id');  }
566
-		$db = $this->getDb()->getConnection();
565
+		if (!preg_match('/^[0-9]+$/', $ruleID)) { throw new Exception('Invalid id'); }
566
+		$db=$this->getDb()->getConnection();
567 567
 		
568 568
 		$query=$db->delete(
569 569
 			$this->getModuleConfig()->getTrapRuleName(),
@@ -576,10 +576,10 @@  discard block
 block discarded – undo
576 576
 	*	@param $ip string source IP (v4 or v6)
577 577
 	*	@param $oid string oid
578 578
 	*/
579
-	protected function deleteTrap($ip,$oid)
579
+	protected function deleteTrap($ip, $oid)
580 580
 	{
581 581
 		
582
-		$db = $this->getDb()->getConnection();
582
+		$db=$this->getDb()->getConnection();
583 583
 		$condition=null;
584 584
 		if ($ip != null)
585 585
 		{
@@ -587,10 +587,10 @@  discard block
 block discarded – undo
587 587
 		}
588 588
 		if ($oid != null)
589 589
 		{
590
-			$condition=($condition===null)?'':$condition.' AND ';
590
+			$condition=($condition === null) ? '' : $condition.' AND ';
591 591
 			$condition.="trap_oid='$oid'";
592 592
 		}
593
-		if($condition === null) return null;
593
+		if ($condition === null) return null;
594 594
 		$query=$db->delete(
595 595
 			$this->getModuleConfig()->getTrapTableName(),
596 596
 			$condition
@@ -604,10 +604,10 @@  discard block
 block discarded – undo
604 604
 	*	@param $ip string source IP (v4 or v6)
605 605
 	*	@param $oid string oid
606 606
 	*/
607
-	protected function countTrap($ip,$oid)
607
+	protected function countTrap($ip, $oid)
608 608
 	{
609 609
 		
610
-		$db = $this->getDb()->getConnection();
610
+		$db=$this->getDb()->getConnection();
611 611
 		$condition=null;
612 612
 		if ($ip != null)
613 613
 		{
@@ -615,10 +615,10 @@  discard block
 block discarded – undo
615 615
 		}
616 616
 		if ($oid != null)
617 617
 		{
618
-			$condition=($condition===null)?'':$condition.' AND ';
618
+			$condition=($condition === null) ? '' : $condition.' AND ';
619 619
 			$condition.="trap_oid='$oid'";
620 620
 		}
621
-		if($condition === null) return 0;
621
+		if ($condition === null) return 0;
622 622
 		$query=$db->select()
623 623
 			->from(
624 624
 				$this->getModuleConfig()->getTrapTableName(),
@@ -634,27 +634,27 @@  discard block
 block discarded – undo
634 634
 	protected function getDBConfigValue($element)
635 635
 	{
636 636
 	
637
-		$db = $this->getDb()->getConnection();
637
+		$db=$this->getDb()->getConnection();
638 638
 		
639 639
 		$query=$db->select()
640 640
 			->from(
641 641
 				$this->getModuleConfig()->getDbConfigTableName(),
642 642
 				array('value'=>'value'))
643
-			->where('name=?',$element);
643
+			->where('name=?', $element);
644 644
 		$return_row=$db->fetchRow($query);
645
-		if ($return_row==null)  // value does not exists
645
+		if ($return_row == null)  // value does not exists
646 646
 		{
647 647
 			$default=$this->getModuleConfig()->getDBConfigDefaults();
648
-			if ( ! isset($default[$element])) return null; // no default and not value
648
+			if (!isset($default[$element])) return null; // no default and not value
649 649
 			
650
-			$this->addDBConfigValue($element,$default[$element]);
650
+			$this->addDBConfigValue($element, $default[$element]);
651 651
 			return $default[$element];
652 652
 		}
653 653
 		if ($return_row->value == null) // value id empty
654 654
 		{
655 655
 			$default=$this->getModuleConfig()->getDBConfigDefaults();
656
-			if ( ! isset($default[$element])) return null; // no default and not value
657
-			$this->setDBConfigValue($element,$default[$element]);
656
+			if (!isset($default[$element])) return null; // no default and not value
657
+			$this->setDBConfigValue($element, $default[$element]);
658 658
 			return $default[$element];			
659 659
 		}
660 660
 		return $return_row->value;		
@@ -665,10 +665,10 @@  discard block
 block discarded – undo
665 665
 	*   @param string $value : value
666 666
 	*/
667 667
 		
668
-	protected function addDBConfigValue($element,$value)
668
+	protected function addDBConfigValue($element, $value)
669 669
 	{
670 670
 	
671
-		$db = $this->getDb()->getConnection();
671
+		$db=$this->getDb()->getConnection();
672 672
 		
673 673
 		$query=$db->insert(
674 674
 				$this->getModuleConfig()->getDbConfigTableName(),
@@ -684,10 +684,10 @@  discard block
 block discarded – undo
684 684
 	*	@param string $element : name of config element
685 685
 	*   @param string $value : value
686 686
 	*/
687
-	protected function setDBConfigValue($element,$value)
687
+	protected function setDBConfigValue($element, $value)
688 688
 	{
689 689
 	
690
-		$db = $this->getDb()->getConnection();
690
+		$db=$this->getDb()->getConnection();
691 691
 		$query=$db->update(
692 692
 				$this->getModuleConfig()->getDbConfigTableName(),
693 693
 				array('value'=>$value),
@@ -702,10 +702,10 @@  discard block
 block discarded – undo
702 702
 	protected function isDirectorInstalled()
703 703
 	{
704 704
 	    $output=array();
705
-	    exec('icingacli module list',$output);
705
+	    exec('icingacli module list', $output);
706 706
 	    foreach ($output as $line)
707 707
 		{
708
-			if (preg_match('/^director .*enabled/',$line))
708
+			if (preg_match('/^director .*enabled/', $line))
709 709
 			{
710 710
 				return true;
711 711
 			}
Please login to merge, or discard this patch.
application/controllers/HelperController.php 1 patch
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -18,14 +18,14 @@  discard block
 block discarded – undo
18 18
 	{
19 19
 		$postData=$this->getRequest()->getPost();
20 20
 		
21
-		$hostFilter = $this->checkPostVar($postData, 'hostFilter', '.*');
21
+		$hostFilter=$this->checkPostVar($postData, 'hostFilter', '.*');
22 22
 		
23
-		$retHosts=array('status'=>'OK','hosts' => array());
23
+		$retHosts=array('status'=>'OK', 'hosts' => array());
24 24
 
25 25
 		$hosts=$this->getHostByIP($hostFilter);
26 26
 		foreach ($hosts as $val)
27 27
 		{
28
-			array_push($retHosts['hosts'],$val->name);
28
+			array_push($retHosts['hosts'], $val->name);
29 29
 		}
30 30
 		
31 31
 		$this->_helper->json($retHosts);
@@ -38,14 +38,14 @@  discard block
 block discarded – undo
38 38
 	{
39 39
 		$postData=$this->getRequest()->getPost();
40 40
 		
41
-		$hostFilter = $this->checkPostVar($postData, 'hostFilter', '.*');
41
+		$hostFilter=$this->checkPostVar($postData, 'hostFilter', '.*');
42 42
 		
43
-		$retHosts=array('status'=>'OK','hosts' => array());
43
+		$retHosts=array('status'=>'OK', 'hosts' => array());
44 44
 
45 45
 		$hosts=$this->getHostGroupByName($hostFilter);
46 46
 		foreach ($hosts as $val)
47 47
 		{
48
-			array_push($retHosts['hosts'],$val->name);
48
+			array_push($retHosts['hosts'], $val->name);
49 49
 		}
50 50
 		
51 51
 		$this->_helper->json($retHosts);
@@ -68,31 +68,31 @@  discard block
 block discarded – undo
68 68
 		}
69 69
 		else
70 70
 		{
71
-			$this->_helper->json(array('status'=>'No Hosts','hostid' => -1));
71
+			$this->_helper->json(array('status'=>'No Hosts', 'hostid' => -1));
72 72
 			return;
73 73
 		}
74 74
 		
75 75
 		$hostArray=$this->getHostByName($host);
76 76
 		if (count($hostArray) > 1)
77 77
 		{	
78
-			$this->_helper->json(array('status'=>'More than one host matches','hostid' => -1));
78
+			$this->_helper->json(array('status'=>'More than one host matches', 'hostid' => -1));
79 79
 			return;
80 80
 		}
81 81
 		else if (count($hostArray) == 0)
82 82
 		{
83
-			$this->_helper->json(array('status'=>'No host matches','hostid' => -1));
83
+			$this->_helper->json(array('status'=>'No host matches', 'hostid' => -1));
84 84
 			return;
85 85
 		}
86 86
 		$services=$this->getServicesByHostid($hostArray[0]->id);
87 87
 		if (count($services) < 1)
88 88
 		{
89
-			$this->_helper->json(array('status'=>'No services found for host','hostid' => $hostArray[0]->id));
89
+			$this->_helper->json(array('status'=>'No services found for host', 'hostid' => $hostArray[0]->id));
90 90
 			return;
91 91
 		}
92
-		$retServices=array('status'=>'OK','services' => array(),'hostid' => $hostArray[0]->id);
92
+		$retServices=array('status'=>'OK', 'services' => array(), 'hostid' => $hostArray[0]->id);
93 93
 		foreach ($services as $val)
94 94
 		{
95
-			array_push($retServices['services'],array($val->id , $val->name));
95
+			array_push($retServices['services'], array($val->id, $val->name));
96 96
 		}
97 97
 		$this->_helper->json($retServices);
98 98
 	}
@@ -107,26 +107,26 @@  discard block
 block discarded – undo
107 107
 	{
108 108
 		$postData=$this->getRequest()->getPost();
109 109
 		
110
-		$host = $this->checkPostVar($postData, 'host', '.+');
110
+		$host=$this->checkPostVar($postData, 'host', '.+');
111 111
 		
112 112
 		$hostArray=$this->getHostGroupByName($host);
113 113
 		if (count($hostArray) > 1)
114 114
 		{	
115
-			$this->_helper->json(array('status'=>'More than one hostgroup matches','hostid' => -1));
115
+			$this->_helper->json(array('status'=>'More than one hostgroup matches', 'hostid' => -1));
116 116
 			return;
117 117
 		}
118 118
 		else if (count($hostArray) == 0)
119 119
 		{
120
-			$this->_helper->json(array('status'=>'No hostgroup matches','hostid' => -1));
120
+			$this->_helper->json(array('status'=>'No hostgroup matches', 'hostid' => -1));
121 121
 			return;
122 122
 		}
123 123
 		$services=$this->getServicesByHostGroupid($hostArray[0]->id);
124 124
 		if (count($services) < 1)
125 125
 		{
126
-			$this->_helper->json(array('status'=>'No services found for hostgroup','hostid' => $hostArray[0]->id));
126
+			$this->_helper->json(array('status'=>'No services found for hostgroup', 'hostid' => $hostArray[0]->id));
127 127
 			return;
128 128
 		}
129
-		$retServices=array('status'=>'OK','services' => $services,'hostid' => $hostArray[0]->id);
129
+		$retServices=array('status'=>'OK', 'services' => $services, 'hostid' => $hostArray[0]->id);
130 130
 		
131 131
 		$this->_helper->json($retServices);
132 132
 	}
@@ -140,12 +140,12 @@  discard block
 block discarded – undo
140 140
 	{
141 141
 		$postData=$this->getRequest()->getPost();
142 142
 		
143
-		$mib = $this->checkPostVar($postData, 'mib', '.*');
143
+		$mib=$this->checkPostVar($postData, 'mib', '.*');
144 144
 
145 145
 		try
146 146
 		{
147 147
 			$traplist=$this->getMIB()->getTrapList($mib);
148
-			$retTraps=array('status'=>'OK','traps' => $traplist);
148
+			$retTraps=array('status'=>'OK', 'traps' => $traplist);
149 149
 		} 
150 150
 		catch (Exception $e) 
151 151
 		{ 
@@ -163,12 +163,12 @@  discard block
 block discarded – undo
163 163
 	{
164 164
 		$postData=$this->getRequest()->getPost();
165 165
 		
166
-		$trap = $this->checkPostVar($postData, 'trap', '.*');
166
+		$trap=$this->checkPostVar($postData, 'trap', '.*');
167 167
 		
168 168
 		try
169 169
 		{
170 170
 			$objectlist=$this->getMIB()->getObjectList($trap);
171
-			$retObjects=array('status'=>'OK','objects' => $objectlist);
171
+			$retObjects=array('status'=>'OK', 'objects' => $objectlist);
172 172
 		} 
173 173
 		catch (Exception $e) 
174 174
 		{ 
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 	{
203 203
 		$postData=$this->getRequest()->getPost();
204 204
 		
205
-		$oid = $this->checkPostVar($postData, 'oid', '.*');
205
+		$oid=$this->checkPostVar($postData, 'oid', '.*');
206 206
 		
207 207
 		// Try to get oid name from snmptranslate
208 208
 		if (($object=$this->getMIB()->translateOID($oid)) == null)
@@ -235,19 +235,19 @@  discard block
 block discarded – undo
235 235
 		
236 236
 		$postData=$this->getRequest()->getPost();
237 237
 		
238
-		$days = $this->checkPostVar($postData, 'days', '^[0-9]+$');
238
+		$days=$this->checkPostVar($postData, 'days', '^[0-9]+$');
239 239
 
240
-		$action = $this->checkPostVar($postData, 'action', 'save|execute');
240
+		$action=$this->checkPostVar($postData, 'action', 'save|execute');
241 241
 		
242 242
 		if ($action == 'save')
243 243
 		{
244 244
 			try
245 245
 			{
246
-				$this->setDBConfigValue('db_remove_days',$days);
246
+				$this->setDBConfigValue('db_remove_days', $days);
247 247
 			}
248 248
 			catch (Exception $e)
249 249
 			{
250
-				$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
250
+				$this->_helper->json(array('status'=>'Save error : '.$e->getMessage()));
251 251
 				return;
252 252
 			}
253 253
 			$this->_helper->json(array('status'=>'OK'));
@@ -257,16 +257,16 @@  discard block
 block discarded – undo
257 257
 		{
258 258
 			try
259 259
 			{
260
-				require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
260
+				require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
261 261
 				$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
262 262
 				$debug_level=4;
263
-				$trap = new Trap($icingaweb2_etc);
264
-				$trap->setLogging($debug_level,'syslog');
263
+				$trap=new Trap($icingaweb2_etc);
264
+				$trap->setLogging($debug_level, 'syslog');
265 265
 				$trap->eraseOldTraps($days);
266 266
 			}
267 267
 			catch (Exception $e)
268 268
 			{
269
-				$this->_helper->json(array('status'=>'execute error : '.$e->getMessage() ));
269
+				$this->_helper->json(array('status'=>'execute error : '.$e->getMessage()));
270 270
 				return;
271 271
 			}			
272 272
 			$this->_helper->json(array('status'=>'OK'));
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 	{
285 285
 		$postData=$this->getRequest()->getPost();
286 286
 		
287
-		$destination = $this->checkPostVar($postData, 'destination', '.*');
287
+		$destination=$this->checkPostVar($postData, 'destination', '.*');
288 288
 		$logDest=$this->getModuleConfig()->getLogDestinations();
289 289
 		if (!isset($logDest[$destination]))
290 290
 		{
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
 		if (isset($postData['file']))
296 296
 		{ 
297 297
 			$file=$postData['file'];
298
-			$fileHandler=@fopen($file,'w');
298
+			$fileHandler=@fopen($file, 'w');
299 299
 			if ($fileHandler == false)
300 300
 			{   // File os note writabe / cannot create
301 301
 			    $this->_helper->json(array('status'=>'File not writable :  '.$file));
@@ -315,17 +315,17 @@  discard block
 block discarded – undo
315 315
 			}
316 316
 		}
317 317
 
318
-		$level = $this->checkPostVar($postData, 'level', '[0-9]');
318
+		$level=$this->checkPostVar($postData, 'level', '[0-9]');
319 319
 				
320 320
 		try
321 321
 		{
322
-			$this->setDBConfigValue('log_destination',$destination);
323
-			$this->setDBConfigValue('log_file',$file);
324
-			$this->setDBConfigValue('log_level',$level);
322
+			$this->setDBConfigValue('log_destination', $destination);
323
+			$this->setDBConfigValue('log_file', $file);
324
+			$this->setDBConfigValue('log_level', $level);
325 325
 		}
326 326
 		catch (Exception $e)
327 327
 		{
328
-			$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
328
+			$this->_helper->json(array('status'=>'Save error : '.$e->getMessage()));
329 329
 			return;
330 330
 		}
331 331
 		$this->_helper->json(array('status'=>'OK'));
@@ -343,29 +343,29 @@  discard block
 block discarded – undo
343 343
 	    
344 344
 	    $postData=$this->getRequest()->getPost();
345 345
 	   
346
-	    $rule = $this->checkPostVar($postData, 'rule', '.*');
346
+	    $rule=$this->checkPostVar($postData, 'rule', '.*');
347 347
 
348
-	    $action = $this->checkPostVar($postData, 'action', 'evaluate');
348
+	    $action=$this->checkPostVar($postData, 'action', 'evaluate');
349 349
 
350 350
 	    if ($action == 'evaluate')
351 351
 	    {
352 352
 	        try
353 353
 	        {
354
-	            require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
354
+	            require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
355 355
 	            $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
356
-	            $trap = new Trap($icingaweb2_etc);
356
+	            $trap=new Trap($icingaweb2_etc);
357 357
 	            // Cleanup spaces before eval
358 358
 	            $rule=$trap->ruleClass->eval_cleanup($rule);
359 359
 	            // Eval
360 360
 	            $item=0;
361
-	            $rule=$trap->ruleClass->evaluation($rule,$item);
361
+	            $rule=$trap->ruleClass->evaluation($rule, $item);
362 362
 	        }
363 363
 	        catch (Exception $e)
364 364
 	        {
365
-	            $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() ));
365
+	            $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage()));
366 366
 	            return;
367 367
 	        }
368
-	        $return=($rule==true)?'true':'false';
368
+	        $return=($rule == true) ? 'true' : 'false';
369 369
 	        $this->_helper->json(array('status'=>'OK', 'message' => $return));
370 370
 	    }
371 371
 	    
@@ -380,15 +380,15 @@  discard block
 block discarded – undo
380 380
 	{
381 381
 	    $postData=$this->getRequest()->getPost();
382 382
 	    
383
-	    $pluginName = $this->checkPostVar($postData, 'name', '.*');
383
+	    $pluginName=$this->checkPostVar($postData, 'name', '.*');
384 384
 	    
385
-	    $action = $this->checkPostVar($postData, 'action', 'enable|disable');
385
+	    $action=$this->checkPostVar($postData, 'action', 'enable|disable');
386 386
 	    
387 387
         try
388 388
         {
389
-            require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
389
+            require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
390 390
             $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
391
-            $trap = new Trap($icingaweb2_etc);
391
+            $trap=new Trap($icingaweb2_etc);
392 392
             // Enable plugin.
393 393
             $action=($action == 'enable') ? true : false;
394 394
             $retVal=$trap->pluginClass->enablePlugin($pluginName, $action);
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
         }
397 397
         catch (Exception $e)
398 398
         {
399
-            $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() ));
399
+            $this->_helper->json(array('status'=>'Action error : '.$e->getMessage()));
400 400
             return;
401 401
         }
402 402
         if ($retVal === true)
@@ -418,45 +418,45 @@  discard block
 block discarded – undo
418 418
 	{
419 419
 	    $postData=$this->getRequest()->getPost();
420 420
 	    
421
-	    $functionString = $this->checkPostVar($postData, 'function', '.*');
421
+	    $functionString=$this->checkPostVar($postData, 'function', '.*');
422 422
 	    
423 423
 	    $this->checkPostVar($postData, 'action', 'evaluate');
424 424
 	    
425 425
 	    // Only one action possible for now, no tests on action.
426 426
 	    try
427 427
 	    {
428
-	        require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
428
+	        require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
429 429
 	        $icingaweb2Etc=$this->Config()->get('config', 'icingaweb2_etc');
430
-	        $trap = new Trap($icingaweb2Etc);
430
+	        $trap=new Trap($icingaweb2Etc);
431 431
 	        // load all plugins in case tested function is not enabled.
432 432
 	        $trap->pluginClass->registerAllPlugins(false);
433 433
 	        // Clean all spaces
434
-	        $functionString = $trap->ruleClass->eval_cleanup($functionString);
434
+	        $functionString=$trap->ruleClass->eval_cleanup($functionString);
435 435
 	        // Eval functions
436
-	        $result = $trap->pluginClass->evaluateFunctionString($functionString);	        
436
+	        $result=$trap->pluginClass->evaluateFunctionString($functionString);	        
437 437
 	    }
438 438
 	    catch (Exception $e)
439 439
 	    {
440
-	        $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() ));
440
+	        $this->_helper->json(array('status'=>'Action error : '.$e->getMessage()));
441 441
 	        return;
442 442
 	    }
443 443
 	    
444
-        $result = ($result === true)?'True':'False';
445
-        $this->_helper->json(array('status'=>'OK','message' => $result));
444
+        $result=($result === true) ? 'True' : 'False';
445
+        $this->_helper->json(array('status'=>'OK', 'message' => $result));
446 446
 	}
447 447
 
448 448
     /**************   Utilities **********************/
449 449
 
450
-	private function checkPostVar(array $postData,string $postVar, string $validRegexp) : string
450
+	private function checkPostVar(array $postData, string $postVar, string $validRegexp) : string
451 451
 	{
452 452
 	    if (!isset ($postData[$postVar]))
453 453
 	    {
454
-	        $this->_helper->json(array('status'=>'No ' . $postVar));
454
+	        $this->_helper->json(array('status'=>'No '.$postVar));
455 455
 	        return '';
456 456
 	    }
457 457
 	    if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1)
458 458
 	    {
459
-	        $this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar]));
459
+	        $this->_helper->json(array('status'=>'Unknown '.$postVar.' value '.$postData[$postVar]));
460 460
 	        return '';
461 461
 	    }
462 462
 	    return $postData[$postVar];
Please login to merge, or discard this patch.
application/controllers/HandlerController.php 1 patch
Spacing   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -23,14 +23,14 @@  discard block
 block discarded – undo
23 23
 		$this->checkReadPermission();
24 24
 		$this->prepareTabs()->activate('status');
25 25
 
26
-		$db = $this->getDb();
26
+		$db=$this->getDb();
27 27
 		$this->getHandlerListTable()->setConnection($db);
28 28
 		$this->getHandlerListTable()->setMibloader($this->getMIB());
29 29
 		// Apply pagination limits 
30
-		$this->view->table=$this->applyPaginationLimits($this->getHandlerListTable(),$this->getModuleConfig()->itemListDisplay());		
30
+		$this->view->table=$this->applyPaginationLimits($this->getHandlerListTable(), $this->getModuleConfig()->itemListDisplay());		
31 31
 		
32 32
 		// Set Filter
33
-		$this->view->filterEditor = $this->getHandlerListTable()->getFilterEditor($this->getRequest());		
33
+		$this->view->filterEditor=$this->getHandlerListTable()->getFilterEditor($this->getRequest());		
34 34
 	
35 35
 		//$this->displayExitError('Handler/indexAction','Not implemented');
36 36
 	}
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	public function testruleAction()
41 41
 	{
42 42
 	    $this->checkReadPermission();
43
-	    $this->getTabs()->add('get',array(
43
+	    $this->getTabs()->add('get', array(
44 44
 	        'active'	=> true,
45 45
 	        'label'		=> $this->translate('Test Rule'),
46 46
 	        'url'		=> Url::fromRequest()
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 
51 51
 	    if ($this->params->get('rule') !== null) 
52 52
 	    {
53
-	        $this->view->rule= $this->params->get('rule');
53
+	        $this->view->rule=$this->params->get('rule');
54 54
 	    }
55 55
 	    else
56 56
 	    {
@@ -109,12 +109,12 @@  discard block
 block discarded – undo
109 109
 	    }
110 110
 	    catch (Exception $e)
111 111
 	    {
112
-	        $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage());
112
+	        $this->displayExitError('Add handler : get host by IP/Name ', $e->getMessage());
113 113
 	    }
114 114
 	    
115 115
 	    
116 116
 	    // if one unique host found -> put id text input
117
-	    if (count($hosts)==1) {
117
+	    if (count($hosts) == 1) {
118 118
 	        $this->view->hostname=$hosts[0]->name;
119 119
 	        //$hostid=$hosts[0]->id;
120 120
 	        // Tell JS to get services when page is loaded
@@ -123,9 +123,9 @@  discard block
 block discarded – undo
123 123
 	    }
124 124
 	    else
125 125
 	    {
126
-	        foreach($hosts as $key=>$val)
126
+	        foreach ($hosts as $key=>$val)
127 127
 	        {
128
-	            array_push($this->view->hostlist,$hosts[$key]->name);
128
+	            array_push($this->view->hostlist, $hosts[$key]->name);
129 129
 	        }
130 130
 	    }
131 131
 	    
@@ -164,18 +164,18 @@  discard block
 block discarded – undo
164 164
 	            $currentObjectTypeEnum
165 165
 	        );
166 166
 	        $oid_index++;
167
-	        array_push($this->view->objectList,$currentObject);
167
+	        array_push($this->view->objectList, $currentObject);
168 168
 	        // set currrent object to null in allObjects
169 169
 	        if (isset($allObjects[$val->oid]))
170 170
 	        {
171 171
 	            $allObjects[$val->oid]=null;
172 172
 	        }
173 173
 	    }
174
-	    if ($allObjects!=null) // in case trap doesn't have objects or is not resolved
174
+	    if ($allObjects != null) // in case trap doesn't have objects or is not resolved
175 175
 	    {
176 176
 	        foreach ($allObjects as $key => $val)
177 177
 	        {
178
-	            if ($val==null) { continue; }
178
+	            if ($val == null) { continue; }
179 179
 	            array_push($this->view->objectList, array(
180 180
 	                $oid_index,
181 181
 	                $key,
@@ -203,9 +203,9 @@  discard block
 block discarded – undo
203 203
 	    // Check if hostname still exists
204 204
 	    $host_get=$this->getHostByName($this->view->hostname);
205 205
 	    
206
-	    if (count($host_get)==0)
206
+	    if (count($host_get) == 0)
207 207
 	    {
208
-	        $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
208
+	        $this->view->warning_message='Host '.$this->view->hostname.' doesn\'t exists anymore';
209 209
 	        $this->view->serviceGet=false;
210 210
 	    }
211 211
 	    else
@@ -213,10 +213,10 @@  discard block
 block discarded – undo
213 213
 	        // Tell JS to get services when page is loaded
214 214
 	        $this->view->serviceGet=true;
215 215
 	        // get service id for form to set :
216
-	        $serviceID=$this->getServiceIDByName($this->view->hostname,$ruleDetail->service_name);
217
-	        if (count($serviceID) ==0)
216
+	        $serviceID=$this->getServiceIDByName($this->view->hostname, $ruleDetail->service_name);
217
+	        if (count($serviceID) == 0)
218 218
 	        {
219
-	            $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
219
+	            $this->view->warning_message=' Service '.$ruleDetail->service_name.' doesn\'t exists anymore';
220 220
 	        }
221 221
 	        else
222 222
 	        {
@@ -233,9 +233,9 @@  discard block
 block discarded – undo
233 233
 	{
234 234
 	    // Check if groupe exists
235 235
 	    $group_get=$this->getHostGroupByName($this->view->hostgroupname);
236
-	    if (count($group_get)==0)
236
+	    if (count($group_get) == 0)
237 237
 	    {
238
-	        $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
238
+	        $this->view->warning_message='HostGroup '.$this->view->hostgroupname.' doesn\'t exists anymore';
239 239
 	        $this->view->serviceGroupGet=false;
240 240
 	    }
241 241
 	    else
@@ -253,9 +253,9 @@  discard block
 block discarded – undo
253 253
 	        
254 254
 	        // Tell JS to get services when page is loaded
255 255
 	        $this->view->serviceGroupGet=true;
256
-	        if ($foundGrpService==0)
256
+	        if ($foundGrpService == 0)
257 257
 	        {
258
-	            $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
258
+	            $this->view->warning_message.=' Service '.$ruleDetail->service_name.' doesn\'t exists anymore';
259 259
 	        }
260 260
 	    }
261 261
 	}
@@ -273,12 +273,12 @@  discard block
 block discarded – undo
273 273
 	    $index=1;
274 274
 	    // check in display & rule for : OID(<oid>)
275 275
 	    $matches=array();
276
-	    while ( preg_match('/_OID\(([\.0-9\*]+)\)/',$display,$matches) ||
277
-	        preg_match('/_OID\(([\.0-9\*]+)\)/',$rule,$matches))
276
+	    while (preg_match('/_OID\(([\.0-9\*]+)\)/', $display, $matches) ||
277
+	        preg_match('/_OID\(([\.0-9\*]+)\)/', $rule, $matches))
278 278
 	    {
279 279
 	        $curOid=$matches[1];
280 280
 	        
281
-	        if ( (preg_match('/\*/',$curOid) == 0 ) 
281
+	        if ((preg_match('/\*/', $curOid) == 0) 
282 282
 	            && ($object=$this->getMIB()->translateOID($curOid)) != null)
283 283
 	        {
284 284
 	            array_push($curObjectList, array(
@@ -303,9 +303,9 @@  discard block
 block discarded – undo
303 303
 	                'not found'
304 304
 	            ));
305 305
 	        }
306
-	        $curOid = preg_replace('/\*/','\*',$curOid);
307
-	        $display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display);
308
-	        $rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule);
306
+	        $curOid=preg_replace('/\*/', '\*', $curOid);
307
+	        $display=preg_replace('/_OID\('.$curOid.'\)/', '\$'.$index.'\$', $display);
308
+	        $rule=preg_replace('/_OID\('.$curOid.'\)/', '\$'.$index.'\$', $rule);
309 309
 	        $index++;
310 310
 	    }
311 311
 	    return $curObjectList;
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
 	{
320 320
 		$this->checkConfigPermission();
321 321
 		// set up tab
322
-		$this->getTabs()->add('get',array(
322
+		$this->getTabs()->add('get', array(
323 323
 			'active'	=> true,
324 324
 			'label'		=> $this->translate('Add handler'),
325 325
 			'url'		=> Url::fromRequest()
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 		
333 333
 		//$this->view->trapvalues=false; // Set to true to display 'value' colum in objects
334 334
 		
335
-		if (($trapid = $this->params->get('fromid')) !== null) {
335
+		if (($trapid=$this->params->get('fromid')) !== null) {
336 336
 		    /********** Setup from existing trap ***************/
337 337
             $this->add_from_existing($trapid);
338 338
 			return;
@@ -352,7 +352,7 @@  discard block
 block discarded – undo
352 352
 			$this->view->setRuleMatch=$ruleDetail->action_match;
353 353
 			$this->view->setRuleNoMatch=$ruleDetail->action_nomatch;
354 354
 			$this->view->hostgroupname=$ruleDetail->host_group_name;
355
-			$this->view->modified=gmdate("Y-m-d\TH:i:s\Z",$ruleDetail->modified);
355
+			$this->view->modified=gmdate("Y-m-d\TH:i:s\Z", $ruleDetail->modified);
356 356
 			$this->view->modifier=$ruleDetail->modifier;
357 357
 			
358 358
 			// Warning message if host/service don't exists anymore
@@ -404,26 +404,26 @@  discard block
 block discarded – undo
404 404
 	
405 405
 		$params=array(
406 406
 			// id (also db) => 	array('post' => post id, 'val' => default val, 'db' => send to table)
407
-			'hostgroup'		=>	array('post' => 'hostgroup','db'=>false),
408
-			'db_rule'		=>	array('post' => 'db_rule','db'=>false),
409
-			'hostid'		=>	array('post' => 'hostid','db'=>false),
410
-			'host_name'		=>	array('post' => 'hostname','val' => null,'db'=>true),
411
-			'host_group_name'=>	array('post' => null,'val' => null,'db'=>true),
412
-			'serviceid'		=>	array('post' => 'serviceid','db'=>false),
413
-			'service_name'	=>	array('post' => 'serviceName','db'=>true),
414
-			'trap_oid'		=>	array('post' => 'oid','db'=>true),
415
-			'revert_ok'		=>	array('post' => 'revertOK','val' => 0,'db'=>true),
416
-			'display'		=>	array('post' => 'display','val' => '','db'=>true),
417
-			'rule'			=>	array('post' => 'rule','val' => '','db'=>true),			
418
-			'action_match'	=>	array('post' => 'ruleMatch','val' => -1,'db'=>true),
419
-			'action_nomatch'=>	array('post' => 'ruleNoMatch','val' => -1,'db'=>true),					
420
-			'ip4'			=>	array('post' => null,'val' => null,'db'=>true),
421
-			'ip6'			=>	array('post' => null,'val' => null,'db'=>true),
422
-			'action_form'	=>	array('post' => 'action_form','db'=>false)
407
+			'hostgroup'		=>	array('post' => 'hostgroup', 'db'=>false),
408
+			'db_rule'		=>	array('post' => 'db_rule', 'db'=>false),
409
+			'hostid'		=>	array('post' => 'hostid', 'db'=>false),
410
+			'host_name'		=>	array('post' => 'hostname', 'val' => null, 'db'=>true),
411
+			'host_group_name'=>	array('post' => null, 'val' => null, 'db'=>true),
412
+			'serviceid'		=>	array('post' => 'serviceid', 'db'=>false),
413
+			'service_name'	=>	array('post' => 'serviceName', 'db'=>true),
414
+			'trap_oid'		=>	array('post' => 'oid', 'db'=>true),
415
+			'revert_ok'		=>	array('post' => 'revertOK', 'val' => 0, 'db'=>true),
416
+			'display'		=>	array('post' => 'display', 'val' => '', 'db'=>true),
417
+			'rule'			=>	array('post' => 'rule', 'val' => '', 'db'=>true),			
418
+			'action_match'	=>	array('post' => 'ruleMatch', 'val' => -1, 'db'=>true),
419
+			'action_nomatch'=>	array('post' => 'ruleNoMatch', 'val' => -1, 'db'=>true),					
420
+			'ip4'			=>	array('post' => null, 'val' => null, 'db'=>true),
421
+			'ip6'			=>	array('post' => null, 'val' => null, 'db'=>true),
422
+			'action_form'	=>	array('post' => 'action_form', 'db'=>false)
423 423
 		);
424 424
 		
425 425
 		if (isset($postData[$params['action_form']['post']]) 
426
-			&& $postData[$params['action_form']['post']] == 'delete' )
426
+			&& $postData[$params['action_form']['post']] == 'delete')
427 427
 		{
428 428
 			try
429 429
 			{
@@ -443,16 +443,16 @@  discard block
 block discarded – undo
443 443
 		}		
444 444
 		foreach (array_keys($params) as $key)
445 445
 		{
446
-			if ($params[$key]['post']==null) continue; // data not sent in post vars
447
-			if (! isset($postData[$params[$key]['post']]))
446
+			if ($params[$key]['post'] == null) continue; // data not sent in post vars
447
+			if (!isset($postData[$params[$key]['post']]))
448 448
 			{
449 449
 				// should not happen as the js checks data
450
-				$this->_helper->json(array('status'=>'No ' . $key));
450
+				$this->_helper->json(array('status'=>'No '.$key));
451 451
 			}
452 452
 			else
453 453
 			{
454 454
 				$data=$postData[$params[$key]['post']];
455
-				if ($data!=null && $data !="")
455
+				if ($data != null && $data != "")
456 456
 				{
457 457
 					$params[$key]['val']=$postData[$params[$key]['post']];
458 458
 				}
@@ -461,8 +461,8 @@  discard block
 block discarded – undo
461 461
 
462 462
 		try 
463 463
 		{
464
-			$isHostGroup=($params['hostgroup']['val'] == 1)?true:false;
465
-			if (! $isHostGroup ) 
464
+			$isHostGroup=($params['hostgroup']['val'] == 1) ?true:false;
465
+			if (!$isHostGroup) 
466 466
 			{  // checks if selection by host 
467 467
 				$hostAddr=$this->getHostInfoByID($params['hostid']['val']);
468 468
 				$params['ip4']['val']=$hostAddr->ip4;
@@ -489,25 +489,25 @@  discard block
 block discarded – undo
489 489
 					return;					
490 490
 				}
491 491
 				// Put param in correct column (group_name)
492
-				$params['host_group_name']['val'] = $params['host_name']['val'];
492
+				$params['host_group_name']['val']=$params['host_name']['val'];
493 493
 				$params['host_name']['val']=null;
494 494
 			}
495 495
 			$dbparams=array();
496 496
 			foreach ($params as $key=>$val)
497 497
 			{
498
-				if ($val['db']==true )
498
+				if ($val['db'] == true)
499 499
 				{
500
-					$dbparams[$key] = $val['val'];
500
+					$dbparams[$key]=$val['val'];
501 501
 				}
502 502
 			}
503 503
 			// echo '<br>';	print_r($dbparams);echo '<br>';
504
-			if ($params['db_rule']['val'] == -1 ) 
504
+			if ($params['db_rule']['val'] == -1) 
505 505
 			{
506 506
 				$ruleID=$this->addHandlerRule($dbparams);
507 507
 			}
508 508
 			else
509 509
 			{
510
-				$this->updateHandlerRule($dbparams,$params['db_rule']['val']);
510
+				$this->updateHandlerRule($dbparams, $params['db_rule']['val']);
511 511
 				$ruleID=$params['db_rule']['val'];
512 512
 			}
513 513
 		}
@@ -526,10 +526,10 @@  discard block
 block discarded – undo
526 526
 	*/
527 527
 	protected function getTrapDetail($trapid) 
528 528
 	{
529
-		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
529
+		if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); }
530 530
 		$queryArray=$this->getModuleConfig()->trapDetailQuery();
531 531
 		
532
-		$db = $this->getDb()->getConnection();
532
+		$db=$this->getDb()->getConnection();
533 533
 		// ***************  Get main data
534 534
 		// extract columns and titles;
535 535
 		$elmts=NULL;
@@ -538,19 +538,19 @@  discard block
 block discarded – undo
538 538
 		}
539 539
 		try
540 540
 		{		
541
-			$query = $db->select()
542
-				->from($this->getModuleConfig()->getTrapTableName(),$elmts)
543
-				->where('id=?',$trapid);
541
+			$query=$db->select()
542
+				->from($this->getModuleConfig()->getTrapTableName(), $elmts)
543
+				->where('id=?', $trapid);
544 544
 			$trapDetail=$db->fetchRow($query);
545
-			if ( $trapDetail == null ) 
545
+			if ($trapDetail == null) 
546 546
 			{
547
-			    $trapDetail = 'NULL';
547
+			    $trapDetail='NULL';
548 548
 			    throw new Exception('No traps was found with id = '.$trapid);
549 549
 			}
550 550
 		}
551 551
 		catch (Exception $e)
552 552
 		{
553
-			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage());
553
+			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail, true), $e->getMessage());
554 554
 			return;
555 555
 		}
556 556
 
@@ -564,10 +564,10 @@  discard block
 block discarded – undo
564 564
 	*/
565 565
 	protected function getTrapobjects($trapid)
566 566
 	{	
567
-		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
567
+		if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); }
568 568
 		$queryArrayData=$this->getModuleConfig()->trapDataDetailQuery();
569 569
 		
570
-		$db = $this->getDb()->getConnection();
570
+		$db=$this->getDb()->getConnection();
571 571
 		// ***************  Get object data
572 572
 		// extract columns and titles;
573 573
 		$data_elmts=NULL;
@@ -576,15 +576,15 @@  discard block
 block discarded – undo
576 576
 		}
577 577
 		try
578 578
 		{		
579
-			$query = $db->select()
580
-				->from($this->moduleConfig->getTrapDataTableName(),$data_elmts)
581
-				->where('trap_id=?',$trapid);
579
+			$query=$db->select()
580
+				->from($this->moduleConfig->getTrapDataTableName(), $data_elmts)
581
+				->where('trap_id=?', $trapid);
582 582
 			$trapDetail=$db->fetchAll($query);
583 583
 			// if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid);
584 584
 		}
585 585
 		catch (Exception $e)
586 586
 		{
587
-			$this->displayExitError('Add handler : get trap data detail : ',$e->getMessage());
587
+			$this->displayExitError('Add handler : get trap data detail : ', $e->getMessage());
588 588
 			return array();
589 589
 		}
590 590
 
@@ -597,22 +597,22 @@  discard block
 block discarded – undo
597 597
 	*/
598 598
 	protected function getRuleDetail($ruleid) 
599 599
 	{
600
-		if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id');  }
600
+		if (!preg_match('/^[0-9]+$/', $ruleid)) { throw new Exception('Invalid id'); }
601 601
 		$queryArray=$this->getModuleConfig()->ruleDetailQuery();
602 602
 		
603
-		$db = $this->getDb()->getConnection();
603
+		$db=$this->getDb()->getConnection();
604 604
 		// ***************  Get main data
605 605
 		try
606 606
 		{		
607
-			$query = $db->select()
608
-				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
609
-				->where('id=?',$ruleid);
607
+			$query=$db->select()
608
+				->from($this->getModuleConfig()->getTrapRuleName(), $queryArray)
609
+				->where('id=?', $ruleid);
610 610
 			$ruleDetail=$db->fetchRow($query);
611
-			if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid);
611
+			if ($ruleDetail == null) throw new Exception('No rule was found with id = '.$ruleid);
612 612
 		}
613 613
 		catch (Exception $e)
614 614
 		{
615
-			$this->displayExitError('Update handler : get rule detail',$e->getMessage());
615
+			$this->displayExitError('Update handler : get rule detail', $e->getMessage());
616 616
 			return array();
617 617
 		}
618 618
 
@@ -626,7 +626,7 @@  discard block
 block discarded – undo
626 626
 	{
627 627
 		return $this->getTabs()->add('status', array(
628 628
 			'label' => $this->translate('Traps'),
629
-			'url'   => $this->getModuleConfig()->urlPath() . '/handler')
629
+			'url'   => $this->getModuleConfig()->urlPath().'/handler')
630 630
 		);
631 631
 	} 
632 632
 	
Please login to merge, or discard this patch.