Passed
Push — master ( 0a83f6...9e9438 )
by Patrick
01:49
created
library/Trapdirector/Tables/TrapDirectorTableGrouping.php 3 patches
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -7,86 +7,86 @@
 block discarded – undo
7 7
 {
8 8
     
9 9
   
10
-    /*************** Grouping ************/
10
+	/*************** Grouping ************/
11 11
     
12
-    /** @var boolean $grouppingActive set to true if grouping is active by query or function call */
13
-    protected $grouppingActive=false;
12
+	/** @var boolean $grouppingActive set to true if grouping is active by query or function call */
13
+	protected $grouppingActive=false;
14 14
     
15
-    /** @var string $groupingColumn Name of column (can be hidden) for grouping */
16
-    protected $groupingColumn='';
15
+	/** @var string $groupingColumn Name of column (can be hidden) for grouping */
16
+	protected $groupingColumn='';
17 17
     
18
-    /**@var string $groupingVal Current value of grouping column in row (used while rendering) */
19
-    protected $groupingVal='';
18
+	/**@var string $groupingVal Current value of grouping column in row (used while rendering) */
19
+	protected $groupingVal='';
20 20
     
21
-    /** @var integer $groupingColSpan colspan of grouping line : set to table titles in init */
22
-    protected $groupingColSpan=1;
21
+	/** @var integer $groupingColSpan colspan of grouping line : set to table titles in init */
22
+	protected $groupingColSpan=1;
23 23
       
24
-    /*****************  Grouping ****************/
24
+	/*****************  Grouping ****************/
25 25
     
26
-    /**
27
-     * Set grouping. column must be DB name
28
-     * @param string $columnDBName
29
-     */
30
-    public function setGrouping(string $columnDBName)
31
-    {
32
-        $this->groupingColumn = $columnDBName;
33
-        $this->grouppingActive = TRUE;
34
-    }
26
+	/**
27
+	 * Set grouping. column must be DB name
28
+	 * @param string $columnDBName
29
+	 */
30
+	public function setGrouping(string $columnDBName)
31
+	{
32
+		$this->groupingColumn = $columnDBName;
33
+		$this->grouppingActive = TRUE;
34
+	}
35 35
     
36
-    /**
37
-     * Init of grouping before rendering
38
-     */
39
-    public function initGrouping()
40
-    {
41
-        $this->groupingVal = '';
42
-        $this->groupingColSpan = count($this->titles);
43
-    }
36
+	/**
37
+	 * Init of grouping before rendering
38
+	 */
39
+	public function initGrouping()
40
+	{
41
+		$this->groupingVal = '';
42
+		$this->groupingColSpan = count($this->titles);
43
+	}
44 44
     
45
-    /**
46
-     * Function to print grouping value (for ovveride in specific tables)
47
-     * @param string $value
48
-     * @return string
49
-     */
50
-    public function groupingPrintData( string $value )
51
-    {
52
-        $html = "$value";
53
-        return $html;
54
-    }
45
+	/**
46
+	 * Function to print grouping value (for ovveride in specific tables)
47
+	 * @param string $value
48
+	 * @return string
49
+	 */
50
+	public function groupingPrintData( string $value )
51
+	{
52
+		$html = "$value";
53
+		return $html;
54
+	}
55 55
     
56
-    /**
57
-     * When to display new grouping line  (for ovveride in specific tables)
58
-     * @param string $val1 Current value in grouping
59
-     * @param string $val2 Value of current line
60
-     * @return boolean TRUE if a new grouping line is needed.
61
-     */
62
-    public function groupingEvalNext(string $val1, string $val2)
63
-    {
64
-        if ($val1 != $val2)
65
-            return TRUE;
66
-        else
67
-            return FALSE;
68
-    }
56
+	/**
57
+	 * When to display new grouping line  (for ovveride in specific tables)
58
+	 * @param string $val1 Current value in grouping
59
+	 * @param string $val2 Value of current line
60
+	 * @return boolean TRUE if a new grouping line is needed.
61
+	 */
62
+	public function groupingEvalNext(string $val1, string $val2)
63
+	{
64
+		if ($val1 != $val2)
65
+			return TRUE;
66
+		else
67
+			return FALSE;
68
+	}
69 69
     
70
-    /**
71
-     * Called before each line to check if grouping line is needed.
72
-     * @param mixed $values
73
-     * @return string with line or empty.
74
-     */
75
-    public function groupingNextLine( $values)
76
-    {
77
-        if ($this->grouppingActive === FALSE) return '';
70
+	/**
71
+	 * Called before each line to check if grouping line is needed.
72
+	 * @param mixed $values
73
+	 * @return string with line or empty.
74
+	 */
75
+	public function groupingNextLine( $values)
76
+	{
77
+		if ($this->grouppingActive === FALSE) return '';
78 78
 
79
-        $dbcol = $this->groupingColumn;
80
-        $dbVal = $values->$dbcol;
81
-        if ( $dbVal === NULL ) $dbVal = '0'; // Set default to 0
82
-        if ($this->groupingVal == '' || $this->groupingEvalNext($this->groupingVal ,$dbVal) === TRUE )
83
-        {
84
-            $this->groupingVal = $dbVal;
85
-            $html = '<tr><th colspan="'. $this->groupingColSpan .'">'. $this->groupingPrintData($this->groupingVal) .'</th></tr>';
86
-            return $html;
87
-        }
88
-        return '';
79
+		$dbcol = $this->groupingColumn;
80
+		$dbVal = $values->$dbcol;
81
+		if ( $dbVal === NULL ) $dbVal = '0'; // Set default to 0
82
+		if ($this->groupingVal == '' || $this->groupingEvalNext($this->groupingVal ,$dbVal) === TRUE )
83
+		{
84
+			$this->groupingVal = $dbVal;
85
+			$html = '<tr><th colspan="'. $this->groupingColSpan .'">'. $this->groupingPrintData($this->groupingVal) .'</th></tr>';
86
+			return $html;
87
+		}
88
+		return '';
89 89
 
90
-    }
90
+	}
91 91
  
92 92
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
29 29
      */
30 30
     public function setGrouping(string $columnDBName)
31 31
     {
32
-        $this->groupingColumn = $columnDBName;
33
-        $this->grouppingActive = TRUE;
32
+        $this->groupingColumn=$columnDBName;
33
+        $this->grouppingActive=TRUE;
34 34
     }
35 35
     
36 36
     /**
@@ -38,8 +38,8 @@  discard block
 block discarded – undo
38 38
      */
39 39
     public function initGrouping()
40 40
     {
41
-        $this->groupingVal = '';
42
-        $this->groupingColSpan = count($this->titles);
41
+        $this->groupingVal='';
42
+        $this->groupingColSpan=count($this->titles);
43 43
     }
44 44
     
45 45
     /**
@@ -47,9 +47,9 @@  discard block
 block discarded – undo
47 47
      * @param string $value
48 48
      * @return string
49 49
      */
50
-    public function groupingPrintData( string $value )
50
+    public function groupingPrintData(string $value)
51 51
     {
52
-        $html = "$value";
52
+        $html="$value";
53 53
         return $html;
54 54
     }
55 55
     
@@ -72,17 +72,17 @@  discard block
 block discarded – undo
72 72
      * @param mixed $values
73 73
      * @return string with line or empty.
74 74
      */
75
-    public function groupingNextLine( $values)
75
+    public function groupingNextLine($values)
76 76
     {
77 77
         if ($this->grouppingActive === FALSE) return '';
78 78
 
79
-        $dbcol = $this->groupingColumn;
80
-        $dbVal = $values->$dbcol;
81
-        if ( $dbVal === NULL ) $dbVal = '0'; // Set default to 0
82
-        if ($this->groupingVal == '' || $this->groupingEvalNext($this->groupingVal ,$dbVal) === TRUE )
79
+        $dbcol=$this->groupingColumn;
80
+        $dbVal=$values->$dbcol;
81
+        if ($dbVal === NULL) $dbVal='0'; // Set default to 0
82
+        if ($this->groupingVal == '' || $this->groupingEvalNext($this->groupingVal, $dbVal) === TRUE)
83 83
         {
84
-            $this->groupingVal = $dbVal;
85
-            $html = '<tr><th colspan="'. $this->groupingColSpan .'">'. $this->groupingPrintData($this->groupingVal) .'</th></tr>';
84
+            $this->groupingVal=$dbVal;
85
+            $html='<tr><th colspan="'.$this->groupingColSpan.'">'.$this->groupingPrintData($this->groupingVal).'</th></tr>';
86 86
             return $html;
87 87
         }
88 88
         return '';
Please login to merge, or discard this patch.
Braces   +12 added lines, -6 removed lines patch added patch discarded remove patch
@@ -61,10 +61,11 @@  discard block
 block discarded – undo
61 61
      */
62 62
     public function groupingEvalNext(string $val1, string $val2)
63 63
     {
64
-        if ($val1 != $val2)
65
-            return TRUE;
66
-        else
67
-            return FALSE;
64
+        if ($val1 != $val2) {
65
+                    return TRUE;
66
+        } else {
67
+                    return FALSE;
68
+        }
68 69
     }
69 70
     
70 71
     /**
@@ -74,11 +75,16 @@  discard block
 block discarded – undo
74 75
      */
75 76
     public function groupingNextLine( $values)
76 77
     {
77
-        if ($this->grouppingActive === FALSE) return '';
78
+        if ($this->grouppingActive === FALSE) {
79
+        	return '';
80
+        }
78 81
 
79 82
         $dbcol = $this->groupingColumn;
80 83
         $dbVal = $values->$dbcol;
81
-        if ( $dbVal === NULL ) $dbVal = '0'; // Set default to 0
84
+        if ( $dbVal === NULL ) {
85
+        	$dbVal = '0';
86
+        }
87
+        // Set default to 0
82 88
         if ($this->groupingVal == '' || $this->groupingEvalNext($this->groupingVal ,$dbVal) === TRUE )
83 89
         {
84 90
             $this->groupingVal = $dbVal;
Please login to merge, or discard this patch.
application/controllers/StatusController.php 3 patches
Braces   +19 added lines, -29 removed lines patch added patch discarded remove patch
@@ -22,7 +22,9 @@  discard block
 block discarded – undo
22 22
 		try
23 23
 		{
24 24
 		    $dbConn = $this->getUIDatabase()->getDbConn();
25
-		    if ($dbConn === null) throw new \ErrorException('uncatched db error');
25
+		    if ($dbConn === null) {
26
+		    	throw new \ErrorException('uncatched db error');
27
+		    }
26 28
 			$query = $dbConn->select()->from(
27 29
 				$this->getModuleConfig()->getTrapTableName(),
28 30
 				array('COUNT(*)')
@@ -41,8 +43,7 @@  discard block
 block discarded – undo
41 43
  			
42 44
 			$this->view->trap_days_delete=$this->getUIDatabase()->getDBConfigValue('db_remove_days');
43 45
 			
44
-		}
45
-		catch (Exception $e)
46
+		} catch (Exception $e)
46 47
 		{
47 48
 			$this->displayExitError('status',$e->getMessage());
48 49
 		}
@@ -56,8 +57,7 @@  discard block
 block discarded – undo
56 57
 			$this->view->currentLogFile=$this->getUIDatabase()->getDBConfigValue('log_file');
57 58
 			$this->view->logLevels=$this->getModuleConfig()->getlogLevels();
58 59
 			$this->view->currentLogLevel=$this->getUIDatabase()->getDBConfigValue('log_level');
59
-		}
60
-		catch (Exception $e)
60
+		} catch (Exception $e)
61 61
 		{
62 62
 			$this->displayExitError('status',$e->getMessage());
63 63
 		}
@@ -69,8 +69,7 @@  discard block
 block discarded – undo
69 69
 		    $this->view->SnmpTrapAddressOID=$this->getUIDatabase()->getDBConfigValue('SnmpTrapAddess_oid');
70 70
 		    $this->view->SnmpTrapAddressOIDDefault = ($this->view->SnmpTrapAddressOID == $this->getModuleConfig()->getDBConfigDefaults()['SnmpTrapAddess_oid'] ) ? TRUE : FALSE;
71 71
 		    
72
-		}
73
-		catch (Exception $e)
72
+		} catch (Exception $e)
74 73
 		{
75 74
 		    $this->displayExitError('status',$e->getMessage());
76 75
 		}		
@@ -120,8 +119,7 @@  discard block
 block discarded – undo
120 119
 					if ($retVal == 0)
121 120
 					{ // process is alive
122 121
 						$this->_helper->json(array('status'=>'Alive and kicking'));
123
-					}
124
-					else
122
+					} else
125 123
 					{ // process is dead
126 124
 					    $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid));
127 125
 					}
@@ -137,22 +135,19 @@  discard block
 block discarded – undo
137 135
 				if (!is_dir($destDir))
138 136
 				{
139 137
 				    $this->view->uploadStatus="ERROR : no $destDir directory, check module configuration";
140
-				}
141
-				else
138
+				} else
142 139
 				{
143 140
 				    if (!is_writable($destDir))
144 141
 				    {
145 142
 				        $this->view->uploadStatus="ERROR : $destDir directory is not writable";
146
-				    }
147
-				    else
143
+				    } else
148 144
 				    {
149 145
 				        $destination = $destDir .'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name";
150 146
 				        $sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'],FILTER_SANITIZE_STRING);
151 147
 				        if (move_uploaded_file($sourceTmpNam,$destination)===false)
152 148
     				    {
153 149
     				        $this->view->uploadStatus="ERROR, file $destination not loaded. Check file and path name or selinux violations";
154
-    				    }
155
-    				    else
150
+    				    } else
156 151
     				    {
157 152
     				        $this->view->uploadStatus="File $name uploaded in $destDir";
158 153
     				    }
@@ -177,18 +172,15 @@  discard block
 block discarded – undo
177 172
 			    {		    
178 173
     				$this->view->snmptranslate='works fine';
179 174
     				$this->view->snmptranslate_state='ok';
180
-			    }
181
-			    else
175
+			    } else
182 176
 			    {
183 177
 			        $this->view->snmptranslate='works fine but missing basic MIBs';
184 178
 			    }
185
-			}
186
-			else
179
+			} else
187 180
 			{
188 181
 				$this->view->snmptranslate='Can execute but no OID to name resolution';
189 182
 			}
190
-		}
191
-		else
183
+		} else
192 184
 		{
193 185
 			$this->view->snmptranslate='Cannot execute';
194 186
 		}
@@ -209,15 +201,13 @@  discard block
 block discarded – undo
209 201
 		if ($retVal==0)
210 202
 		{
211 203
 			$dirArray=array_merge($dirArray,explode(':',$sysDirs));
212
-		}
213
-		else
204
+		} else
214 205
 		{
215 206
 			$translateOut=exec($this->Config()->get('config', 'snmptranslate') . ' -Dinit_mib .1.3 2>&1 | grep MIBDIRS');
216 207
 			if (preg_match('/MIBDIRS.*\'([^\']+)\'/',$translateOut,$matches))
217 208
 			{
218 209
 				$dirArray=array_merge($dirArray,explode(':',$matches[1]));
219
-			}
220
-			else
210
+			} else
221 211
 			{
222 212
 				array_push($dirArray,'Install net-snmp-config to see system directories');
223 213
 			}
@@ -256,8 +246,7 @@  discard block
 block discarded – undo
256 246
 	        if (!preg_match('/^[0-9]+$/', $maxRows) || $maxRows < 1)
257 247
 	        {
258 248
 	            $this->view->setError='Max rows must be a number';
259
-	        }
260
-	        else
249
+	        } else
261 250
 	        {
262 251
 	            $this->setitemListDisplay($maxRows);
263 252
 	            $this->view->setOKMsg='Set max rows to ' . $maxRows;
@@ -276,8 +265,9 @@  discard block
 block discarded – undo
276 265
 	        $index = $this->getRequest()->getPost('index',NULL);
277 266
 	        $newname = $this->getRequest()->getPost('newname',NULL);
278 267
 
279
-	        if (!preg_match('/^[0-9]+$/', $index) || $index < 1)
280
-	            $this->_helper->json(array('status'=>'Bad index'));
268
+	        if (!preg_match('/^[0-9]+$/', $index) || $index < 1) {
269
+	        	            $this->_helper->json(array('status'=>'Bad index'));
270
+	        }
281 271
 	        
282 272
 	        switch ($type)
283 273
 	        {
Please login to merge, or discard this patch.
Indentation   +187 added lines, -187 removed lines patch added patch discarded remove patch
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
21 21
 		/************  Trapdb ***********/
22 22
 		try
23 23
 		{
24
-		    $dbConn = $this->getUIDatabase()->getDbConn();
25
-		    if ($dbConn === null) throw new \ErrorException('uncatched db error');
24
+			$dbConn = $this->getUIDatabase()->getDbConn();
25
+			if ($dbConn === null) throw new \ErrorException('uncatched db error');
26 26
 			$query = $dbConn->select()->from(
27 27
 				$this->getModuleConfig()->getTrapTableName(),
28 28
 				array('COUNT(*)')
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 		
52 52
 		try
53 53
 		{		
54
-		    $this->view->currentLogDestination=$this->getUIDatabase()->getDBConfigValue('log_destination');
54
+			$this->view->currentLogDestination=$this->getUIDatabase()->getDBConfigValue('log_destination');
55 55
 			$this->view->logDestinations=$this->getModuleConfig()->getLogDestinations();
56 56
 			$this->view->currentLogFile=$this->getUIDatabase()->getDBConfigValue('log_file');
57 57
 			$this->view->logLevels=$this->getModuleConfig()->getlogLevels();
@@ -65,23 +65,23 @@  discard block
 block discarded – undo
65 65
 		/*************** SNMP configuration ****************/
66 66
 		try
67 67
 		{
68
-		    $this->view->useSnmpTrapAddess= ( $this->getUIDatabase()->getDBConfigValue('use_SnmpTrapAddess') == 1 ) ? TRUE : FALSE;
69
-		    $this->view->SnmpTrapAddressOID=$this->getUIDatabase()->getDBConfigValue('SnmpTrapAddess_oid');
70
-		    $this->view->SnmpTrapAddressOIDDefault = ($this->view->SnmpTrapAddressOID == $this->getModuleConfig()->getDBConfigDefaults()['SnmpTrapAddess_oid'] ) ? TRUE : FALSE;
68
+			$this->view->useSnmpTrapAddess= ( $this->getUIDatabase()->getDBConfigValue('use_SnmpTrapAddess') == 1 ) ? TRUE : FALSE;
69
+			$this->view->SnmpTrapAddressOID=$this->getUIDatabase()->getDBConfigValue('SnmpTrapAddess_oid');
70
+			$this->view->SnmpTrapAddressOIDDefault = ($this->view->SnmpTrapAddressOID == $this->getModuleConfig()->getDBConfigDefaults()['SnmpTrapAddess_oid'] ) ? TRUE : FALSE;
71 71
 		    
72 72
 		}
73 73
 		catch (Exception $e)
74 74
 		{
75
-		    $this->displayExitError('status',$e->getMessage());
75
+			$this->displayExitError('status',$e->getMessage());
76 76
 		}		
77 77
 		
78 78
 	} 
79 79
   
80 80
 	/** Mib management
81
-	*	Post param : action=update_mib_db : update mib database
82
-	*	Post param : ation=check_update : check if mib update is finished
83
-	*	File post : mibfile -> save mib file
84
-	*/
81
+	 *	Post param : action=update_mib_db : update mib database
82
+	 *	Post param : ation=check_update : check if mib update is finished
83
+	 *	File post : mibfile -> save mib file
84
+	 */
85 85
 	public function mibAction()
86 86
 	{
87 87
 		$this->prepareTabs()->activate('mib');
@@ -100,22 +100,22 @@  discard block
 block discarded – undo
100 100
 					$return=exec('icingacli trapdirector mib update --pid /tmp/trapdirector_update.pid');
101 101
 					if (preg_match('/OK/',$return))
102 102
 					{
103
-					    $this->_helper->json(array('status'=>'OK'));
103
+						$this->_helper->json(array('status'=>'OK'));
104 104
 					}
105 105
 					// Error
106 106
 					$this->_helper->json(array('status'=>$return));
107 107
 				}
108 108
 				if ($action == 'check_update')
109 109
 				{
110
-				    $file=@fopen('/tmp/trapdirector_update.pid','r');
111
-				    if ($file == false)
112
-				    {   // process is dead
113
-				        $this->_helper->json(array('status'=>'tu quoque fili','err'=>'Cannot open file'));
114
-				        return;
115
-				    }
116
-				    $pid=fgets($file);
117
-				    $output=array();
118
-				    $retVal=0;
110
+					$file=@fopen('/tmp/trapdirector_update.pid','r');
111
+					if ($file == false)
112
+					{   // process is dead
113
+						$this->_helper->json(array('status'=>'tu quoque fili','err'=>'Cannot open file'));
114
+						return;
115
+					}
116
+					$pid=fgets($file);
117
+					$output=array();
118
+					$retVal=0;
119 119
 					exec('ps '.$pid,$output,$retVal);
120 120
 					if ($retVal == 0)
121 121
 					{ // process is alive
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 					}
124 124
 					else
125 125
 					{ // process is dead
126
-					    $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid));
126
+						$this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid));
127 127
 					}
128 128
 				}
129 129
 				$this->_helper->json(array('status'=>'ERR : no '.$action.' action possible' ));
@@ -131,32 +131,32 @@  discard block
 block discarded – undo
131 131
 			/** Check for mib file UPLOAD */
132 132
 			if (isset($_FILES['mibfile']))
133 133
 			{
134
-			    $name=filter_var($_FILES['mibfile']['name'],FILTER_SANITIZE_STRING);
134
+				$name=filter_var($_FILES['mibfile']['name'],FILTER_SANITIZE_STRING);
135 135
 				$DirConf=explode(':',$this->Config()->get('config', 'snmptranslate_dirs'));
136 136
 				$destDir=array_shift($DirConf);
137 137
 				if (!is_dir($destDir))
138 138
 				{
139
-				    $this->view->uploadStatus="ERROR : no $destDir directory, check module configuration";
139
+					$this->view->uploadStatus="ERROR : no $destDir directory, check module configuration";
140 140
 				}
141 141
 				else
142 142
 				{
143
-				    if (!is_writable($destDir))
144
-				    {
145
-				        $this->view->uploadStatus="ERROR : $destDir directory is not writable";
146
-				    }
147
-				    else
148
-				    {
149
-				        $destination = $destDir .'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name";
150
-				        $sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'],FILTER_SANITIZE_STRING);
151
-				        if (move_uploaded_file($sourceTmpNam,$destination)===false)
152
-    				    {
153
-    				        $this->view->uploadStatus="ERROR, file $destination not loaded. Check file and path name or selinux violations";
154
-    				    }
155
-    				    else
156
-    				    {
157
-    				        $this->view->uploadStatus="File $name uploaded in $destDir";
158
-    				    }
159
-				    }
143
+					if (!is_writable($destDir))
144
+					{
145
+						$this->view->uploadStatus="ERROR : $destDir directory is not writable";
146
+					}
147
+					else
148
+					{
149
+						$destination = $destDir .'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name";
150
+						$sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'],FILTER_SANITIZE_STRING);
151
+						if (move_uploaded_file($sourceTmpNam,$destination)===false)
152
+						{
153
+							$this->view->uploadStatus="ERROR, file $destination not loaded. Check file and path name or selinux violations";
154
+						}
155
+						else
156
+						{
157
+							$this->view->uploadStatus="File $name uploaded in $destDir";
158
+						}
159
+					}
160 160
 				}
161 161
 
162 162
 			}
@@ -172,16 +172,16 @@  discard block
 block discarded – undo
172 172
 			$translate=exec($snmptranslate . ' 1');
173 173
 			if (preg_match('/iso/',$translate))
174 174
 			{
175
-			    $translate=exec($snmptranslate . ' 1.3.6.1.4');
176
-			    if (preg_match('/private/',$translate))
177
-			    {		    
178
-    				$this->view->snmptranslate='works fine';
179
-    				$this->view->snmptranslate_state='ok';
180
-			    }
181
-			    else
182
-			    {
183
-			        $this->view->snmptranslate='works fine but missing basic MIBs';
184
-			    }
175
+				$translate=exec($snmptranslate . ' 1.3.6.1.4');
176
+				if (preg_match('/private/',$translate))
177
+				{		    
178
+					$this->view->snmptranslate='works fine';
179
+					$this->view->snmptranslate_state='ok';
180
+				}
181
+				else
182
+				{
183
+					$this->view->snmptranslate='works fine but missing basic MIBs';
184
+				}
185 185
 			}
186 186
 			else
187 187
 			{
@@ -244,63 +244,63 @@  discard block
 block discarded – undo
244 244
 	/** UI options */
245 245
 	public function uimgtAction()
246 246
 	{
247
-	    $this->prepareTabs()->activate('uimgt');
247
+		$this->prepareTabs()->activate('uimgt');
248 248
 	    
249
-	    $this->view->setError='';
250
-	    $this->view->setOKMsg='';
249
+		$this->view->setError='';
250
+		$this->view->setOKMsg='';
251 251
 	    
252
-	    //max_rows=25&row_update=update
253
-	    if ( $this->getRequest()->getParam('max_rows',NULL) !== NULL )
254
-	    {
255
-	        $maxRows = $this->getRequest()->getParam('max_rows');
256
-	        if (!preg_match('/^[0-9]+$/', $maxRows) || $maxRows < 1)
257
-	        {
258
-	            $this->view->setError='Max rows must be a number';
259
-	        }
260
-	        else
261
-	        {
262
-	            $this->setitemListDisplay($maxRows);
263
-	            $this->view->setOKMsg='Set max rows to ' . $maxRows;
264
-	        }
265
-	    }
252
+		//max_rows=25&row_update=update
253
+		if ( $this->getRequest()->getParam('max_rows',NULL) !== NULL )
254
+		{
255
+			$maxRows = $this->getRequest()->getParam('max_rows');
256
+			if (!preg_match('/^[0-9]+$/', $maxRows) || $maxRows < 1)
257
+			{
258
+				$this->view->setError='Max rows must be a number';
259
+			}
260
+			else
261
+			{
262
+				$this->setitemListDisplay($maxRows);
263
+				$this->view->setOKMsg='Set max rows to ' . $maxRows;
264
+			}
265
+		}
266 266
 	    
267
-	    if ( $this->getRequest()->getParam('add_category',NULL) !== NULL )
268
-	    {
269
-	        $addCat = $this->getRequest()->getParam('add_category');
270
-            $this->addHandlersCategory($addCat);
271
-	    }
267
+		if ( $this->getRequest()->getParam('add_category',NULL) !== NULL )
268
+		{
269
+			$addCat = $this->getRequest()->getParam('add_category');
270
+			$this->addHandlersCategory($addCat);
271
+		}
272 272
 	    
273
-	    if ( $this->getRequest()->getPost('type',NULL) !== NULL )
274
-	    {
275
-	        $type = $this->getRequest()->getPost('type',NULL);
276
-	        $index = $this->getRequest()->getPost('index',NULL);
277
-	        $newname = $this->getRequest()->getPost('newname',NULL);
273
+		if ( $this->getRequest()->getPost('type',NULL) !== NULL )
274
+		{
275
+			$type = $this->getRequest()->getPost('type',NULL);
276
+			$index = $this->getRequest()->getPost('index',NULL);
277
+			$newname = $this->getRequest()->getPost('newname',NULL);
278 278
 
279
-	        if (!preg_match('/^[0-9]+$/', $index) || $index < 1)
280
-	            $this->_helper->json(array('status'=>'Bad index'));
279
+			if (!preg_match('/^[0-9]+$/', $index) || $index < 1)
280
+				$this->_helper->json(array('status'=>'Bad index'));
281 281
 	        
282
-	        switch ($type)
283
-	        {
284
-	            case 'delete':
285
-	                $this->delHandlersCategory($index);
286
-	                $this->_helper->json(array('status'=>'OK'));
287
-	                return;
288
-	                break;
289
-	            case 'rename':
290
-	                $this->renameHandlersCategory($index, $newname);
291
-	                $this->_helper->json(array('status'=>'OK'));
292
-	                return;
293
-	                break;
294
-	            default:
295
-	                $this->_helper->json(array('status'=>'Unknwon command'));
296
-	                return;
297
-	                break;
298
-	        }
299
-	    }
282
+			switch ($type)
283
+			{
284
+				case 'delete':
285
+					$this->delHandlersCategory($index);
286
+					$this->_helper->json(array('status'=>'OK'));
287
+					return;
288
+					break;
289
+				case 'rename':
290
+					$this->renameHandlersCategory($index, $newname);
291
+					$this->_helper->json(array('status'=>'OK'));
292
+					return;
293
+					break;
294
+				default:
295
+					$this->_helper->json(array('status'=>'Unknwon command'));
296
+					return;
297
+					break;
298
+			}
299
+		}
300 300
 	    
301
-	    $this->view->maxRows = $this->itemListDisplay();
301
+		$this->view->maxRows = $this->itemListDisplay();
302 302
 	    
303
-	    $this->view->categories = $this->getHandlersCategory();
303
+		$this->view->categories = $this->getHandlersCategory();
304 304
 	    
305 305
 	    
306 306
 	    
@@ -349,47 +349,47 @@  discard block
 block discarded – undo
349 349
 	 */
350 350
 	public function pluginsAction()
351 351
 	{
352
-	    $this->prepareTabs()->activate('plugins');
352
+		$this->prepareTabs()->activate('plugins');
353 353
 	    
354
-	    require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
355
-	    $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
356
-	    $Trap = new Trap($icingaweb2_etc,4);
354
+		require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
355
+		$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
356
+		$Trap = new Trap($icingaweb2_etc,4);
357 357
 	    
358
-	    $this->view->pluginLoaded = htmlentities($Trap->pluginClass->registerAllPlugins(false));
358
+		$this->view->pluginLoaded = htmlentities($Trap->pluginClass->registerAllPlugins(false));
359 359
 	    
360
-	    $enabledPlugins = $Trap->pluginClass->getEnabledPlugins();
360
+		$enabledPlugins = $Trap->pluginClass->getEnabledPlugins();
361 361
 
362
-	    $pluginList = $Trap->pluginClass->pluginList();
362
+		$pluginList = $Trap->pluginClass->pluginList();
363 363
 	    
364
-	    // Plugin list and fill function name list
365
-	    $functionList=array();
366
-	    $this->view->pluginArray=array();
367
-	    foreach ($pluginList as $plugin)
368
-	    {
369
-	        $pluginDetails=$Trap->pluginClass->pluginDetails($plugin);
370
-	        $pluginDetails->enabled =  (in_array($plugin, $enabledPlugins)) ? true : false;
371
-	        $pluginDetails->catchAllTraps = ($pluginDetails->catchAllTraps === true )? 'Yes' : 'No';
372
-	        $pluginDetails->processTraps = ($pluginDetails->processTraps === true )? 'Yes' : 'No';
373
-	        $pluginDetails->description = htmlentities($pluginDetails->description);
374
-	        $pluginDetails->description = preg_replace('/\n/','<br>',$pluginDetails->description);
375
-	        array_push($this->view->pluginArray, $pluginDetails);
376
-	        // Get functions for function details
377
-	        foreach ($pluginDetails->funcArray as $function)
378
-	        {
379
-	            array_push($functionList,$function);
380
-	        }
381
-	    }
364
+		// Plugin list and fill function name list
365
+		$functionList=array();
366
+		$this->view->pluginArray=array();
367
+		foreach ($pluginList as $plugin)
368
+		{
369
+			$pluginDetails=$Trap->pluginClass->pluginDetails($plugin);
370
+			$pluginDetails->enabled =  (in_array($plugin, $enabledPlugins)) ? true : false;
371
+			$pluginDetails->catchAllTraps = ($pluginDetails->catchAllTraps === true )? 'Yes' : 'No';
372
+			$pluginDetails->processTraps = ($pluginDetails->processTraps === true )? 'Yes' : 'No';
373
+			$pluginDetails->description = htmlentities($pluginDetails->description);
374
+			$pluginDetails->description = preg_replace('/\n/','<br>',$pluginDetails->description);
375
+			array_push($this->view->pluginArray, $pluginDetails);
376
+			// Get functions for function details
377
+			foreach ($pluginDetails->funcArray as $function)
378
+			{
379
+				array_push($functionList,$function);
380
+			}
381
+		}
382 382
 	    
383
-	    // Function list with details
384
-	    $this->view->functionList=array();
385
-	    foreach ($functionList as $function)
386
-	    {
387
-	        $functionDetail = $Trap->pluginClass->getFunctionDetails($function);
388
-	        $functionDetail->params = htmlentities($functionDetail->params);
389
-	        $functionDetail->description = htmlentities($functionDetail->description);
390
-	        $functionDetail->description = preg_replace('/\n/','<br>',$functionDetail->description);
391
-	        array_push($this->view->functionList, $functionDetail);
392
-	    }
383
+		// Function list with details
384
+		$this->view->functionList=array();
385
+		foreach ($functionList as $function)
386
+		{
387
+			$functionDetail = $Trap->pluginClass->getFunctionDetails($function);
388
+			$functionDetail->params = htmlentities($functionDetail->params);
389
+			$functionDetail->description = htmlentities($functionDetail->description);
390
+			$functionDetail->description = preg_replace('/\n/','<br>',$functionDetail->description);
391
+			array_push($this->view->functionList, $functionDetail);
392
+		}
393 393
 
394 394
 	}
395 395
 
@@ -398,47 +398,47 @@  discard block
 block discarded – undo
398 398
 	 */
399 399
 	public function debugAction()
400 400
 	{
401
-	    $this->view->answer='No answer';
402
-	    $this->view->input1 = '';
401
+		$this->view->answer='No answer';
402
+		$this->view->input1 = '';
403 403
 	    
404
-	    $postData=$this->getRequest()->getPost();
405
-	    if (isset($postData['input1']))
406
-	    {
407
-	        $input1 = $postData['input1'];
408
-	        $input2 = $postData['input2'];
409
-	        $input3 = $postData['input3'];
410
-	        $this->view->input1 = $input1;
411
-	        //$this->view->answer=$input1 . '/' . $input2  . '/' . $input3;
412
-	        try {
413
-	            $this->view->answer = 'Answer : ';
414
-	            $API = $this->getIdoConn();
415
-	            $DB = $this->getUIDatabase();
404
+		$postData=$this->getRequest()->getPost();
405
+		if (isset($postData['input1']))
406
+		{
407
+			$input1 = $postData['input1'];
408
+			$input2 = $postData['input2'];
409
+			$input3 = $postData['input3'];
410
+			$this->view->input1 = $input1;
411
+			//$this->view->answer=$input1 . '/' . $input2  . '/' . $input3;
412
+			try {
413
+				$this->view->answer = 'Answer : ';
414
+				$API = $this->getIdoConn();
415
+				$DB = $this->getUIDatabase();
416 416
 
417
-	            //$hosts = $DB->getServicesByHostGroupid($input1);
418
-	            //$this->view->answer .= 'services : '.print_r($hosts,true);
417
+				//$hosts = $DB->getServicesByHostGroupid($input1);
418
+				//$this->view->answer .= 'services : '.print_r($hosts,true);
419 419
 	            
420
-	            $hosts = $API->getServicesByHostGroupid($input1);
421
-	            $this->view->answer .= 'services : '.print_r($hosts,true);
420
+				$hosts = $API->getServicesByHostGroupid($input1);
421
+				$this->view->answer .= 'services : '.print_r($hosts,true);
422 422
 	            
423 423
 
424 424
 	            
425
-	            return;
426
-	            $hosts = $API->getHostByIP($input1);
427
-	            $this->view->answer .= 'Host : '. print_r($hosts,true);
428
-	            $hosts = $API->getHostGroupByName($input1);
429
-	            $this->view->answer .= 'Group : '.print_r($hosts,true);
430
-	            $hosts = $API->getServicesByHostid($input1);
431
-	            $this->view->answer .= 'service : '.print_r($hosts,true);
425
+				return;
426
+				$hosts = $API->getHostByIP($input1);
427
+				$this->view->answer .= 'Host : '. print_r($hosts,true);
428
+				$hosts = $API->getHostGroupByName($input1);
429
+				$this->view->answer .= 'Group : '.print_r($hosts,true);
430
+				$hosts = $API->getServicesByHostid($input1);
431
+				$this->view->answer .= 'service : '.print_r($hosts,true);
432 432
 	            
433
-	            /* $hosts = $API->getHostsIPByHostGroup($input1);
433
+				/* $hosts = $API->getHostsIPByHostGroup($input1);
434 434
 	            $this->view->answer .= "\n Hostgrp : " . print_r($hosts,true); */
435 435
 	            
436
-	        } catch (Exception $e)
437
-	        {
438
-	            $this->view->answer = "Exception : " . print_r($e);
439
-	        }
436
+			} catch (Exception $e)
437
+			{
438
+				$this->view->answer = "Exception : " . print_r($e);
439
+			}
440 440
 	        
441
-	    }
441
+		}
442 442
 	    
443 443
 	}
444 444
 	
@@ -450,36 +450,36 @@  discard block
 block discarded – undo
450 450
 		)->add('mib', array(
451 451
 			'label' => $this->translate('MIB Management'),
452 452
 			'url'   => $this->getModuleConfig()->urlPath() . '/status/mib')
453
-	    )->add('uimgt', array(
454
-	        'label' => $this->translate('UI Configuration'),
455
-	        'url'   => $this->getModuleConfig()->urlPath() . '/status/uimgt')
456
-        )->add('services', array(
453
+		)->add('uimgt', array(
454
+			'label' => $this->translate('UI Configuration'),
455
+			'url'   => $this->getModuleConfig()->urlPath() . '/status/uimgt')
456
+		)->add('services', array(
457 457
 			'label' => $this->translate('Services management'),
458 458
 			'url'   => $this->getModuleConfig()->urlPath() . '/status/services')
459
-	    )->add('plugins', array(
460
-	        'label' => $this->translate('Plugins management'),
461
-	        'url'   => $this->getModuleConfig()->urlPath() . '/status/plugins')
462
-	    );
459
+		)->add('plugins', array(
460
+			'label' => $this->translate('Plugins management'),
461
+			'url'   => $this->getModuleConfig()->urlPath() . '/status/plugins')
462
+		);
463 463
 	} 
464 464
 }
465 465
 
466 466
 // TODO : see if useless 
467 467
 class UploadForm extends Form
468 468
 { 
469
-    public function __construct($options = null) 
470
-    {
471
-        parent::__construct($options);
472
-        $this->addElements2();
473
-    }
469
+	public function __construct($options = null) 
470
+	{
471
+		parent::__construct($options);
472
+		$this->addElements2();
473
+	}
474 474
 
475
-    public function addElements2()
476
-    {
477
-        // File Input
478
-        $file = new File('mib-file');
479
-        $file->setLabel('Mib upload');
480
-             //->setAttrib('multiple', null);
481
-        $this->addElement($file);
475
+	public function addElements2()
476
+	{
477
+		// File Input
478
+		$file = new File('mib-file');
479
+		$file->setLabel('Mib upload');
480
+			 //->setAttrib('multiple', null);
481
+		$this->addElement($file);
482 482
 		$button = new Submit("upload",array('ignore'=>false));
483 483
 		$this->addElement($button);//->setIgnore(false);
484
-    }
484
+	}
485 485
 }
Please login to merge, or discard this patch.
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -21,19 +21,19 @@  discard block
 block discarded – undo
21 21
 		/************  Trapdb ***********/
22 22
 		try
23 23
 		{
24
-		    $dbConn = $this->getUIDatabase()->getDbConn();
24
+		    $dbConn=$this->getUIDatabase()->getDbConn();
25 25
 		    if ($dbConn === null) throw new \ErrorException('uncatched db error');
26
-			$query = $dbConn->select()->from(
26
+			$query=$dbConn->select()->from(
27 27
 				$this->getModuleConfig()->getTrapTableName(),
28 28
 				array('COUNT(*)')
29 29
 			);			
30 30
 			$this->view->trap_count=$dbConn->fetchOne($query);
31
-			$query = $dbConn->select()->from(
31
+			$query=$dbConn->select()->from(
32 32
 				$this->getModuleConfig()->getTrapDataTableName(),
33 33
 				array('COUNT(*)')
34 34
 			);			
35 35
 			$this->view->trap_object_count=$dbConn->fetchOne($query);
36
-			$query = $dbConn->select()->from(
36
+			$query=$dbConn->select()->from(
37 37
 				$this->getModuleConfig()->getTrapRuleName(),
38 38
 				array('COUNT(*)')
39 39
 			);			
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 		}
45 45
 		catch (Exception $e)
46 46
 		{
47
-			$this->displayExitError('status',$e->getMessage());
47
+			$this->displayExitError('status', $e->getMessage());
48 48
 		}
49 49
 		
50 50
 		/*************** Log destination *******************/
@@ -59,20 +59,20 @@  discard block
 block discarded – undo
59 59
 		}
60 60
 		catch (Exception $e)
61 61
 		{
62
-			$this->displayExitError('status',$e->getMessage());
62
+			$this->displayExitError('status', $e->getMessage());
63 63
 		}
64 64
 		
65 65
 		/*************** SNMP configuration ****************/
66 66
 		try
67 67
 		{
68
-		    $this->view->useSnmpTrapAddess= ( $this->getUIDatabase()->getDBConfigValue('use_SnmpTrapAddess') == 1 ) ? TRUE : FALSE;
68
+		    $this->view->useSnmpTrapAddess=($this->getUIDatabase()->getDBConfigValue('use_SnmpTrapAddess') == 1) ? TRUE : FALSE;
69 69
 		    $this->view->SnmpTrapAddressOID=$this->getUIDatabase()->getDBConfigValue('SnmpTrapAddess_oid');
70
-		    $this->view->SnmpTrapAddressOIDDefault = ($this->view->SnmpTrapAddressOID == $this->getModuleConfig()->getDBConfigDefaults()['SnmpTrapAddess_oid'] ) ? TRUE : FALSE;
70
+		    $this->view->SnmpTrapAddressOIDDefault=($this->view->SnmpTrapAddressOID == $this->getModuleConfig()->getDBConfigDefaults()['SnmpTrapAddess_oid']) ? TRUE : FALSE;
71 71
 		    
72 72
 		}
73 73
 		catch (Exception $e)
74 74
 		{
75
-		    $this->displayExitError('status',$e->getMessage());
75
+		    $this->displayExitError('status', $e->getMessage());
76 76
 		}		
77 77
 		
78 78
 	} 
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 				if ($action == 'update_mib_db')
99 99
 				{ // Do the update in background
100 100
 					$return=exec('icingacli trapdirector mib update --pid /tmp/trapdirector_update.pid');
101
-					if (preg_match('/OK/',$return))
101
+					if (preg_match('/OK/', $return))
102 102
 					{
103 103
 					    $this->_helper->json(array('status'=>'OK'));
104 104
 					}
@@ -107,32 +107,32 @@  discard block
 block discarded – undo
107 107
 				}
108 108
 				if ($action == 'check_update')
109 109
 				{
110
-				    $file=@fopen('/tmp/trapdirector_update.pid','r');
110
+				    $file=@fopen('/tmp/trapdirector_update.pid', 'r');
111 111
 				    if ($file == false)
112 112
 				    {   // process is dead
113
-				        $this->_helper->json(array('status'=>'tu quoque fili','err'=>'Cannot open file'));
113
+				        $this->_helper->json(array('status'=>'tu quoque fili', 'err'=>'Cannot open file'));
114 114
 				        return;
115 115
 				    }
116 116
 				    $pid=fgets($file);
117 117
 				    $output=array();
118 118
 				    $retVal=0;
119
-					exec('ps '.$pid,$output,$retVal);
119
+					exec('ps '.$pid, $output, $retVal);
120 120
 					if ($retVal == 0)
121 121
 					{ // process is alive
122 122
 						$this->_helper->json(array('status'=>'Alive and kicking'));
123 123
 					}
124 124
 					else
125 125
 					{ // process is dead
126
-					    $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid));
126
+					    $this->_helper->json(array('status'=>'tu quoque fili', 'err'=>'no proc'.$pid));
127 127
 					}
128 128
 				}
129
-				$this->_helper->json(array('status'=>'ERR : no '.$action.' action possible' ));
129
+				$this->_helper->json(array('status'=>'ERR : no '.$action.' action possible'));
130 130
 			}
131 131
 			/** Check for mib file UPLOAD */
132 132
 			if (isset($_FILES['mibfile']))
133 133
 			{
134
-			    $name=filter_var($_FILES['mibfile']['name'],FILTER_SANITIZE_STRING);
135
-				$DirConf=explode(':',$this->Config()->get('config', 'snmptranslate_dirs'));
134
+			    $name=filter_var($_FILES['mibfile']['name'], FILTER_SANITIZE_STRING);
135
+				$DirConf=explode(':', $this->Config()->get('config', 'snmptranslate_dirs'));
136 136
 				$destDir=array_shift($DirConf);
137 137
 				if (!is_dir($destDir))
138 138
 				{
@@ -146,9 +146,9 @@  discard block
 block discarded – undo
146 146
 				    }
147 147
 				    else
148 148
 				    {
149
-				        $destination = $destDir .'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name";
150
-				        $sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'],FILTER_SANITIZE_STRING);
151
-				        if (move_uploaded_file($sourceTmpNam,$destination)===false)
149
+				        $destination=$destDir.'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name";
150
+				        $sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'], FILTER_SANITIZE_STRING);
151
+				        if (move_uploaded_file($sourceTmpNam, $destination) === false)
152 152
     				    {
153 153
     				        $this->view->uploadStatus="ERROR, file $destination not loaded. Check file and path name or selinux violations";
154 154
     				    }
@@ -164,16 +164,16 @@  discard block
 block discarded – undo
164 164
 		}
165 165
 		
166 166
 		// snmptranslate tests
167
-		$snmptranslate = $this->Config()->get('config', 'snmptranslate');
167
+		$snmptranslate=$this->Config()->get('config', 'snmptranslate');
168 168
 		$this->view->snmptranslate_bin=$snmptranslate;
169 169
 		$this->view->snmptranslate_state='warn';
170
-		if (is_executable ( $snmptranslate ))
170
+		if (is_executable($snmptranslate))
171 171
 		{
172
-			$translate=exec($snmptranslate . ' 1');
173
-			if (preg_match('/iso/',$translate))
172
+			$translate=exec($snmptranslate.' 1');
173
+			if (preg_match('/iso/', $translate))
174 174
 			{
175
-			    $translate=exec($snmptranslate . ' 1.3.6.1.4');
176
-			    if (preg_match('/private/',$translate))
175
+			    $translate=exec($snmptranslate.' 1.3.6.1.4');
176
+			    if (preg_match('/private/', $translate))
177 177
 			    {		    
178 178
     				$this->view->snmptranslate='works fine';
179 179
     				$this->view->snmptranslate_state='ok';
@@ -196,46 +196,46 @@  discard block
 block discarded – undo
196 196
 		// mib database
197 197
 		
198 198
 		$this->view->mibDbCount=$this->getMIB()->countObjects();
199
-		$this->view->mibDbCountTrap=$this->getMIB()->countObjects(null,21);
199
+		$this->view->mibDbCountTrap=$this->getMIB()->countObjects(null, 21);
200 200
 		
201 201
 		// mib dirs
202 202
 		$DirConf=$this->Config()->get('config', 'snmptranslate_dirs');
203
-		$dirArray=explode(':',$DirConf);
203
+		$dirArray=explode(':', $DirConf);
204 204
 
205 205
 		// Get base directories from net-snmp-config
206 206
 		$output=$matches=array();
207 207
 		$retVal=0;
208
-		$sysDirs=exec('net-snmp-config --default-mibdirs',$output,$retVal);
209
-		if ($retVal==0)
208
+		$sysDirs=exec('net-snmp-config --default-mibdirs', $output, $retVal);
209
+		if ($retVal == 0)
210 210
 		{
211
-			$dirArray=array_merge($dirArray,explode(':',$sysDirs));
211
+			$dirArray=array_merge($dirArray, explode(':', $sysDirs));
212 212
 		}
213 213
 		else
214 214
 		{
215
-			$translateOut=exec($this->Config()->get('config', 'snmptranslate') . ' -Dinit_mib .1.3 2>&1 | grep MIBDIRS');
216
-			if (preg_match('/MIBDIRS.*\'([^\']+)\'/',$translateOut,$matches))
215
+			$translateOut=exec($this->Config()->get('config', 'snmptranslate').' -Dinit_mib .1.3 2>&1 | grep MIBDIRS');
216
+			if (preg_match('/MIBDIRS.*\'([^\']+)\'/', $translateOut, $matches))
217 217
 			{
218
-				$dirArray=array_merge($dirArray,explode(':',$matches[1]));
218
+				$dirArray=array_merge($dirArray, explode(':', $matches[1]));
219 219
 			}
220 220
 			else
221 221
 			{
222
-				array_push($dirArray,'Install net-snmp-config to see system directories');
222
+				array_push($dirArray, 'Install net-snmp-config to see system directories');
223 223
 			}
224 224
 		}
225 225
 		
226 226
 		$this->view->dirArray=$dirArray;
227 227
 		
228 228
 		$output=null;
229
-		foreach (explode(':',$DirConf) as $mibdir)
229
+		foreach (explode(':', $DirConf) as $mibdir)
230 230
 		{
231
-			exec('ls '.$mibdir.' | grep -v traplist.txt',$output);
231
+			exec('ls '.$mibdir.' | grep -v traplist.txt', $output);
232 232
 		}
233 233
 		//$i=0;$listFiles='';while (isset($output[$i])) $listFiles.=$output[$i++];
234 234
 		//$this->view->fileList=explode(' ',$listFiles);
235 235
 		$this->view->fileList=$output;
236 236
 		
237 237
 		// Zend form 
238
-		$this->view->form= new UploadForm();
238
+		$this->view->form=new UploadForm();
239 239
 		//$this->view->form= new Form('upload-form');
240 240
 		
241 241
 		
@@ -250,9 +250,9 @@  discard block
 block discarded – undo
250 250
 	    $this->view->setOKMsg='';
251 251
 	    
252 252
 	    //max_rows=25&row_update=update
253
-	    if ( $this->getRequest()->getParam('max_rows',NULL) !== NULL )
253
+	    if ($this->getRequest()->getParam('max_rows', NULL) !== NULL)
254 254
 	    {
255
-	        $maxRows = $this->getRequest()->getParam('max_rows');
255
+	        $maxRows=$this->getRequest()->getParam('max_rows');
256 256
 	        if (!preg_match('/^[0-9]+$/', $maxRows) || $maxRows < 1)
257 257
 	        {
258 258
 	            $this->view->setError='Max rows must be a number';
@@ -260,21 +260,21 @@  discard block
 block discarded – undo
260 260
 	        else
261 261
 	        {
262 262
 	            $this->setitemListDisplay($maxRows);
263
-	            $this->view->setOKMsg='Set max rows to ' . $maxRows;
263
+	            $this->view->setOKMsg='Set max rows to '.$maxRows;
264 264
 	        }
265 265
 	    }
266 266
 	    
267
-	    if ( $this->getRequest()->getParam('add_category',NULL) !== NULL )
267
+	    if ($this->getRequest()->getParam('add_category', NULL) !== NULL)
268 268
 	    {
269
-	        $addCat = $this->getRequest()->getParam('add_category');
269
+	        $addCat=$this->getRequest()->getParam('add_category');
270 270
             $this->addHandlersCategory($addCat);
271 271
 	    }
272 272
 	    
273
-	    if ( $this->getRequest()->getPost('type',NULL) !== NULL )
273
+	    if ($this->getRequest()->getPost('type', NULL) !== NULL)
274 274
 	    {
275
-	        $type = $this->getRequest()->getPost('type',NULL);
276
-	        $index = $this->getRequest()->getPost('index',NULL);
277
-	        $newname = $this->getRequest()->getPost('newname',NULL);
275
+	        $type=$this->getRequest()->getPost('type', NULL);
276
+	        $index=$this->getRequest()->getPost('index', NULL);
277
+	        $newname=$this->getRequest()->getPost('newname', NULL);
278 278
 
279 279
 	        if (!preg_match('/^[0-9]+$/', $index) || $index < 1)
280 280
 	            $this->_helper->json(array('status'=>'Bad index'));
@@ -298,9 +298,9 @@  discard block
 block discarded – undo
298 298
 	        }
299 299
 	    }
300 300
 	    
301
-	    $this->view->maxRows = $this->itemListDisplay();
301
+	    $this->view->maxRows=$this->itemListDisplay();
302 302
 	    
303
-	    $this->view->categories = $this->getHandlersCategory();
303
+	    $this->view->categories=$this->getHandlersCategory();
304 304
 	    
305 305
 	    
306 306
 	    
@@ -324,18 +324,18 @@  discard block
 block discarded – undo
324 324
 		$this->view->templateForm_output='';
325 325
 		if (isset($postData['template_name']) && isset($postData['template_revert_time']))
326 326
 		{
327
-			$template_create = 'icingacli director service create --json \'{ "check_command": "dummy", ';
328
-			$template_create .= '"check_interval": "' .$postData['template_revert_time']. '", "check_timeout": "20", "disabled": false, "enable_active_checks": true, "enable_event_handler": true, "enable_notifications": true, "enable_passive_checks": true, "enable_perfdata": true, "max_check_attempts": "1", ';
329
-			$template_create .= '"object_name": "'.$postData['template_name'].'", "object_type": "template", "retry_interval": "'.$postData['template_revert_time'].'"}\'';
327
+			$template_create='icingacli director service create --json \'{ "check_command": "dummy", ';
328
+			$template_create.='"check_interval": "'.$postData['template_revert_time'].'", "check_timeout": "20", "disabled": false, "enable_active_checks": true, "enable_event_handler": true, "enable_notifications": true, "enable_passive_checks": true, "enable_perfdata": true, "max_check_attempts": "1", ';
329
+			$template_create.='"object_name": "'.$postData['template_name'].'", "object_type": "template", "retry_interval": "'.$postData['template_revert_time'].'"}\'';
330 330
 			$output=array();
331 331
 			$ret_code=0;
332
-			exec($template_create,$output,$ret_code);
332
+			exec($template_create, $output, $ret_code);
333 333
 			if ($ret_code != 0)
334 334
 			{
335
-				$this->displayExitError("Status -> Services","Error creating template : ".$output[0].'<br>Command was : '.$template_create);
335
+				$this->displayExitError("Status -> Services", "Error creating template : ".$output[0].'<br>Command was : '.$template_create);
336 336
 			}
337
-			exec('icingacli director config deploy',$output,$ret_code);
338
-			$this->view->templateForm_output='Template '.$postData['template_name']. ' created';
337
+			exec('icingacli director config deploy', $output, $ret_code);
338
+			$this->view->templateForm_output='Template '.$postData['template_name'].' created';
339 339
 		}
340 340
 		
341 341
 		// template creation form
@@ -351,15 +351,15 @@  discard block
 block discarded – undo
351 351
 	{
352 352
 	    $this->prepareTabs()->activate('plugins');
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,4);
356
+	    $Trap=new Trap($icingaweb2_etc, 4);
357 357
 	    
358
-	    $this->view->pluginLoaded = htmlentities($Trap->pluginClass->registerAllPlugins(false));
358
+	    $this->view->pluginLoaded=htmlentities($Trap->pluginClass->registerAllPlugins(false));
359 359
 	    
360
-	    $enabledPlugins = $Trap->pluginClass->getEnabledPlugins();
360
+	    $enabledPlugins=$Trap->pluginClass->getEnabledPlugins();
361 361
 
362
-	    $pluginList = $Trap->pluginClass->pluginList();
362
+	    $pluginList=$Trap->pluginClass->pluginList();
363 363
 	    
364 364
 	    // Plugin list and fill function name list
365 365
 	    $functionList=array();
@@ -367,16 +367,16 @@  discard block
 block discarded – undo
367 367
 	    foreach ($pluginList as $plugin)
368 368
 	    {
369 369
 	        $pluginDetails=$Trap->pluginClass->pluginDetails($plugin);
370
-	        $pluginDetails->enabled =  (in_array($plugin, $enabledPlugins)) ? true : false;
371
-	        $pluginDetails->catchAllTraps = ($pluginDetails->catchAllTraps === true )? 'Yes' : 'No';
372
-	        $pluginDetails->processTraps = ($pluginDetails->processTraps === true )? 'Yes' : 'No';
373
-	        $pluginDetails->description = htmlentities($pluginDetails->description);
374
-	        $pluginDetails->description = preg_replace('/\n/','<br>',$pluginDetails->description);
370
+	        $pluginDetails->enabled=(in_array($plugin, $enabledPlugins)) ? true : false;
371
+	        $pluginDetails->catchAllTraps=($pluginDetails->catchAllTraps === true) ? 'Yes' : 'No';
372
+	        $pluginDetails->processTraps=($pluginDetails->processTraps === true) ? 'Yes' : 'No';
373
+	        $pluginDetails->description=htmlentities($pluginDetails->description);
374
+	        $pluginDetails->description=preg_replace('/\n/', '<br>', $pluginDetails->description);
375 375
 	        array_push($this->view->pluginArray, $pluginDetails);
376 376
 	        // Get functions for function details
377 377
 	        foreach ($pluginDetails->funcArray as $function)
378 378
 	        {
379
-	            array_push($functionList,$function);
379
+	            array_push($functionList, $function);
380 380
 	        }
381 381
 	    }
382 382
 	    
@@ -384,10 +384,10 @@  discard block
 block discarded – undo
384 384
 	    $this->view->functionList=array();
385 385
 	    foreach ($functionList as $function)
386 386
 	    {
387
-	        $functionDetail = $Trap->pluginClass->getFunctionDetails($function);
388
-	        $functionDetail->params = htmlentities($functionDetail->params);
389
-	        $functionDetail->description = htmlentities($functionDetail->description);
390
-	        $functionDetail->description = preg_replace('/\n/','<br>',$functionDetail->description);
387
+	        $functionDetail=$Trap->pluginClass->getFunctionDetails($function);
388
+	        $functionDetail->params=htmlentities($functionDetail->params);
389
+	        $functionDetail->description=htmlentities($functionDetail->description);
390
+	        $functionDetail->description=preg_replace('/\n/', '<br>', $functionDetail->description);
391 391
 	        array_push($this->view->functionList, $functionDetail);
392 392
 	    }
393 393
 
@@ -399,43 +399,43 @@  discard block
 block discarded – undo
399 399
 	public function debugAction()
400 400
 	{
401 401
 	    $this->view->answer='No answer';
402
-	    $this->view->input1 = '';
402
+	    $this->view->input1='';
403 403
 	    
404 404
 	    $postData=$this->getRequest()->getPost();
405 405
 	    if (isset($postData['input1']))
406 406
 	    {
407
-	        $input1 = $postData['input1'];
408
-	        $input2 = $postData['input2'];
409
-	        $input3 = $postData['input3'];
410
-	        $this->view->input1 = $input1;
407
+	        $input1=$postData['input1'];
408
+	        $input2=$postData['input2'];
409
+	        $input3=$postData['input3'];
410
+	        $this->view->input1=$input1;
411 411
 	        //$this->view->answer=$input1 . '/' . $input2  . '/' . $input3;
412 412
 	        try {
413
-	            $this->view->answer = 'Answer : ';
414
-	            $API = $this->getIdoConn();
415
-	            $DB = $this->getUIDatabase();
413
+	            $this->view->answer='Answer : ';
414
+	            $API=$this->getIdoConn();
415
+	            $DB=$this->getUIDatabase();
416 416
 
417 417
 	            //$hosts = $DB->getServicesByHostGroupid($input1);
418 418
 	            //$this->view->answer .= 'services : '.print_r($hosts,true);
419 419
 	            
420
-	            $hosts = $API->getServicesByHostGroupid($input1);
421
-	            $this->view->answer .= 'services : '.print_r($hosts,true);
420
+	            $hosts=$API->getServicesByHostGroupid($input1);
421
+	            $this->view->answer.='services : '.print_r($hosts, true);
422 422
 	            
423 423
 
424 424
 	            
425 425
 	            return;
426
-	            $hosts = $API->getHostByIP($input1);
427
-	            $this->view->answer .= 'Host : '. print_r($hosts,true);
428
-	            $hosts = $API->getHostGroupByName($input1);
429
-	            $this->view->answer .= 'Group : '.print_r($hosts,true);
430
-	            $hosts = $API->getServicesByHostid($input1);
431
-	            $this->view->answer .= 'service : '.print_r($hosts,true);
426
+	            $hosts=$API->getHostByIP($input1);
427
+	            $this->view->answer.='Host : '.print_r($hosts, true);
428
+	            $hosts=$API->getHostGroupByName($input1);
429
+	            $this->view->answer.='Group : '.print_r($hosts, true);
430
+	            $hosts=$API->getServicesByHostid($input1);
431
+	            $this->view->answer.='service : '.print_r($hosts, true);
432 432
 	            
433 433
 	            /* $hosts = $API->getHostsIPByHostGroup($input1);
434 434
 	            $this->view->answer .= "\n Hostgrp : " . print_r($hosts,true); */
435 435
 	            
436 436
 	        } catch (Exception $e)
437 437
 	        {
438
-	            $this->view->answer = "Exception : " . print_r($e);
438
+	            $this->view->answer="Exception : ".print_r($e);
439 439
 	        }
440 440
 	        
441 441
 	    }
@@ -446,19 +446,19 @@  discard block
 block discarded – undo
446 446
 	{
447 447
 		return $this->getTabs()->add('status', array(
448 448
 			'label' => $this->translate('Status'),
449
-			'url'   => $this->getModuleConfig()->urlPath() . '/status')
449
+			'url'   => $this->getModuleConfig()->urlPath().'/status')
450 450
 		)->add('mib', array(
451 451
 			'label' => $this->translate('MIB Management'),
452
-			'url'   => $this->getModuleConfig()->urlPath() . '/status/mib')
452
+			'url'   => $this->getModuleConfig()->urlPath().'/status/mib')
453 453
 	    )->add('uimgt', array(
454 454
 	        'label' => $this->translate('UI Configuration'),
455
-	        'url'   => $this->getModuleConfig()->urlPath() . '/status/uimgt')
455
+	        'url'   => $this->getModuleConfig()->urlPath().'/status/uimgt')
456 456
         )->add('services', array(
457 457
 			'label' => $this->translate('Services management'),
458
-			'url'   => $this->getModuleConfig()->urlPath() . '/status/services')
458
+			'url'   => $this->getModuleConfig()->urlPath().'/status/services')
459 459
 	    )->add('plugins', array(
460 460
 	        'label' => $this->translate('Plugins management'),
461
-	        'url'   => $this->getModuleConfig()->urlPath() . '/status/plugins')
461
+	        'url'   => $this->getModuleConfig()->urlPath().'/status/plugins')
462 462
 	    );
463 463
 	} 
464 464
 }
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
 // TODO : see if useless 
467 467
 class UploadForm extends Form
468 468
 { 
469
-    public function __construct($options = null) 
469
+    public function __construct($options=null) 
470 470
     {
471 471
         parent::__construct($options);
472 472
         $this->addElements2();
@@ -475,11 +475,11 @@  discard block
 block discarded – undo
475 475
     public function addElements2()
476 476
     {
477 477
         // File Input
478
-        $file = new File('mib-file');
478
+        $file=new File('mib-file');
479 479
         $file->setLabel('Mib upload');
480 480
              //->setAttrib('multiple', null);
481 481
         $this->addElement($file);
482
-		$button = new Submit("upload",array('ignore'=>false));
483
-		$this->addElement($button);//->setIgnore(false);
482
+		$button=new Submit("upload", array('ignore'=>false));
483
+		$this->addElement($button); //->setIgnore(false);
484 484
     }
485 485
 }
Please login to merge, or discard this patch.
library/Trapdirector/Icinga2Api.php 3 patches
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -10,151 +10,151 @@
 block discarded – undo
10 10
 class Icinga2API extends IcingaApiBase
11 11
 {
12 12
     
13
-    /**
14
-     * Creates Icinga2API object
15
-     * 
16
-     * @param string $host host name or IP
17
-     * @param number $port API port
18
-     */
19
-    public function __construct($host, $port = 5665)
20
-    {
21
-        parent::__construct($host,$port);
22
-    }
23
-    /**
13
+	/**
14
+	 * Creates Icinga2API object
15
+	 * 
16
+	 * @param string $host host name or IP
17
+	 * @param number $port API port
18
+	 */
19
+	public function __construct($host, $port = 5665)
20
+	{
21
+		parent::__construct($host,$port);
22
+	}
23
+	/**
24 24
 
25 25
 /************ Host query ************/  
26 26
   
27
-    /**
28
-     * return array of host by IP (4 or 6) or name
29
-     * @param string $ip
30
-     * @throws Exception
31
-     * @return array objects : array('__name','name','display_name')
32
-     */
33
-    public function getHostByIP(string $ip) 
34
-    {
35
-        return $this->standardQuery(
36
-            'host', 
37
-            'match("*' . $ip . '*",host.address) || match("*' . $ip . '*",host.address6) || match("*' . $ip . '*",host.name) || match("*' . $ip . '*",host.display_name)',
38
-            array('__name','name','display_name')
39
-        );
40
-    }
27
+	/**
28
+	 * return array of host by IP (4 or 6) or name
29
+	 * @param string $ip
30
+	 * @throws Exception
31
+	 * @return array objects : array('__name','name','display_name')
32
+	 */
33
+	public function getHostByIP(string $ip) 
34
+	{
35
+		return $this->standardQuery(
36
+			'host', 
37
+			'match("*' . $ip . '*",host.address) || match("*' . $ip . '*",host.address6) || match("*' . $ip . '*",host.name) || match("*' . $ip . '*",host.display_name)',
38
+			array('__name','name','display_name')
39
+		);
40
+	}
41 41
 
42 42
     
43
-    /**
44
-     * Get host(s) by name in API
45
-     * @param string $name
46
-     * @return array|NULL[] : see getHostByIP
47
-     */
48
-    public function getHostByName(string $name)
49
-    {
50
-        return $this->getHostByIP($name);
51
-    }
43
+	/**
44
+	 * Get host(s) by name in API
45
+	 * @param string $name
46
+	 * @return array|NULL[] : see getHostByIP
47
+	 */
48
+	public function getHostByName(string $name)
49
+	{
50
+		return $this->getHostByIP($name);
51
+	}
52 52
  
53
-    /**
54
-     * Get all host and IP from hostgroup
55
-     * @param string $hostGroup
56
-     * @throws Exception
57
-     * @return array : attributes : address, address6, name
58
-     */
59
-    public function getHostsIPByHostGroup($hostGroup)
60
-    {        
61
-        return $this->standardQuery(
62
-            'host', 
63
-            '"' . $hostGroup . '" in host.groups',
64
-            array('address','address6','name')
53
+	/**
54
+	 * Get all host and IP from hostgroup
55
+	 * @param string $hostGroup
56
+	 * @throws Exception
57
+	 * @return array : attributes : address, address6, name
58
+	 */
59
+	public function getHostsIPByHostGroup($hostGroup)
60
+	{        
61
+		return $this->standardQuery(
62
+			'host', 
63
+			'"' . $hostGroup . '" in host.groups',
64
+			array('address','address6','name')
65 65
                 
66
-        );
67
-    }
66
+		);
67
+	}
68 68
     
69
-    /**
70
-     * Get all host and IP from hostgroup
71
-     * @param string $hostGroup
72
-     * @throws Exception
73
-     * @return array : attributes : address, address6, name
74
-     */
75
-    public function getHostGroupByName($name)
76
-    {
77
-        return $this->standardQuery(
78
-            'hostgroup',
79
-            'match("*' . $name . '*",hostgroup.name)',
80
-            array('name','display_name')
69
+	/**
70
+	 * Get all host and IP from hostgroup
71
+	 * @param string $hostGroup
72
+	 * @throws Exception
73
+	 * @return array : attributes : address, address6, name
74
+	 */
75
+	public function getHostGroupByName($name)
76
+	{
77
+		return $this->standardQuery(
78
+			'hostgroup',
79
+			'match("*' . $name . '*",hostgroup.name)',
80
+			array('name','display_name')
81 81
             
82
-            );
83
-    }
82
+			);
83
+	}
84 84
 
85
-    /** Get services from host in API
86
-     *	
87
-     *  @throws Exception
88
-     *	@param $id string host name
89
-     *	@return array display_name (of service), service_object_id
90
-     */
91
-    public function getServicesByHostid(string $id, bool $active = TRUE, bool $passive_svc = TRUE)
92
-    {
93
-        $filter = 'match("' . $id . '!*", service.__name)';
94
-        if ($active === TRUE)
95
-        {
96
-            $filter .= ' && service.active==true';
97
-        }
98
-        if ($passive_svc === TRUE)
99
-        {
100
-            $filter .= ' && service.enable_passive_checks==true';
101
-        }
102
-        return $this->standardQuery(
103
-            'service',
104
-            $filter,
105
-            array('__name','name','display_name','active')
106
-            );
85
+	/** Get services from host in API
86
+	 *	
87
+	 *  @throws Exception
88
+	 *	@param $id string host name
89
+	 *	@return array display_name (of service), service_object_id
90
+	 */
91
+	public function getServicesByHostid(string $id, bool $active = TRUE, bool $passive_svc = TRUE)
92
+	{
93
+		$filter = 'match("' . $id . '!*", service.__name)';
94
+		if ($active === TRUE)
95
+		{
96
+			$filter .= ' && service.active==true';
97
+		}
98
+		if ($passive_svc === TRUE)
99
+		{
100
+			$filter .= ' && service.enable_passive_checks==true';
101
+		}
102
+		return $this->standardQuery(
103
+			'service',
104
+			$filter,
105
+			array('__name','name','display_name','active')
106
+			);
107 107
         
108
-    }
108
+	}
109 109
 
110
-    /**
111
-     * return array of host by IP (4 or 6) or name
112
-     * @param string $group Host group name
113
-     * @throws Exception
114
-     * @return array objects : array('name','display_name')
115
-     */
116
-    public function getHostsByGroup(string $group)
117
-    {
118
-         return $this->standardQuery(
119
-            'host',
120
-            '"' . $group . '" in host.groups',
121
-            array('name','display_name')
122
-            );
123
-    }
110
+	/**
111
+	 * return array of host by IP (4 or 6) or name
112
+	 * @param string $group Host group name
113
+	 * @throws Exception
114
+	 * @return array objects : array('name','display_name')
115
+	 */
116
+	public function getHostsByGroup(string $group)
117
+	{
118
+		 return $this->standardQuery(
119
+			'host',
120
+			'"' . $group . '" in host.groups',
121
+			array('name','display_name')
122
+			);
123
+	}
124 124
     
125
-    public function getServicesByHostGroupid(string $group)
126
-    {
127
-        $hostList = $this->getHostsByGroup($group);
128
-        //return $hostList;
129
-        $hostNum = count($hostList);
130
-        $serviceList=array();
131
-        foreach ($hostList as $curHost)
132
-        {
133
-            $services = $this->getServicesByHostid($curHost->name);
134
-            foreach ($services as $service)
135
-            {
136
-                //return $service;
137
-                if (! isset($serviceList[$service->name]))
138
-                {
139
-                    $serviceList[$service->name]=
140
-                        array('num'=> 1 ,'display_name' => $service->display_name);
141
-                }
142
-                else
143
-                {
144
-                    $serviceList[$service->name]['num']++;
145
-                }
146
-            }
147
-        }
148
-        $commonServices=array();
149
-        foreach ($serviceList as $serviceName => $values)
150
-        {
151
-            if ($values['num'] >= $hostNum)
152
-            {
153
-                $commonServices[$serviceName] = $values['display_name'];
154
-            }
155
-        }
156
-        return $commonServices;
157
-    }
125
+	public function getServicesByHostGroupid(string $group)
126
+	{
127
+		$hostList = $this->getHostsByGroup($group);
128
+		//return $hostList;
129
+		$hostNum = count($hostList);
130
+		$serviceList=array();
131
+		foreach ($hostList as $curHost)
132
+		{
133
+			$services = $this->getServicesByHostid($curHost->name);
134
+			foreach ($services as $service)
135
+			{
136
+				//return $service;
137
+				if (! isset($serviceList[$service->name]))
138
+				{
139
+					$serviceList[$service->name]=
140
+						array('num'=> 1 ,'display_name' => $service->display_name);
141
+				}
142
+				else
143
+				{
144
+					$serviceList[$service->name]['num']++;
145
+				}
146
+			}
147
+		}
148
+		$commonServices=array();
149
+		foreach ($serviceList as $serviceName => $values)
150
+		{
151
+			if ($values['num'] >= $hostNum)
152
+			{
153
+				$commonServices[$serviceName] = $values['display_name'];
154
+			}
155
+		}
156
+		return $commonServices;
157
+	}
158 158
     
159 159
 }
160 160
 
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -16,9 +16,9 @@  discard block
 block discarded – undo
16 16
      * @param string $host host name or IP
17 17
      * @param number $port API port
18 18
      */
19
-    public function __construct($host, $port = 5665)
19
+    public function __construct($host, $port=5665)
20 20
     {
21
-        parent::__construct($host,$port);
21
+        parent::__construct($host, $port);
22 22
     }
23 23
     /**
24 24
 
@@ -34,8 +34,8 @@  discard block
 block discarded – undo
34 34
     {
35 35
         return $this->standardQuery(
36 36
             'host', 
37
-            'match("*' . $ip . '*",host.address) || match("*' . $ip . '*",host.address6) || match("*' . $ip . '*",host.name) || match("*' . $ip . '*",host.display_name)',
38
-            array('__name','name','display_name')
37
+            'match("*'.$ip.'*",host.address) || match("*'.$ip.'*",host.address6) || match("*'.$ip.'*",host.name) || match("*'.$ip.'*",host.display_name)',
38
+            array('__name', 'name', 'display_name')
39 39
         );
40 40
     }
41 41
 
@@ -60,8 +60,8 @@  discard block
 block discarded – undo
60 60
     {        
61 61
         return $this->standardQuery(
62 62
             'host', 
63
-            '"' . $hostGroup . '" in host.groups',
64
-            array('address','address6','name')
63
+            '"'.$hostGroup.'" in host.groups',
64
+            array('address', 'address6', 'name')
65 65
                 
66 66
         );
67 67
     }
@@ -76,8 +76,8 @@  discard block
 block discarded – undo
76 76
     {
77 77
         return $this->standardQuery(
78 78
             'hostgroup',
79
-            'match("*' . $name . '*",hostgroup.name)',
80
-            array('name','display_name')
79
+            'match("*'.$name.'*",hostgroup.name)',
80
+            array('name', 'display_name')
81 81
             
82 82
             );
83 83
     }
@@ -88,21 +88,21 @@  discard block
 block discarded – undo
88 88
      *	@param $id string host name
89 89
      *	@return array display_name (of service), service_object_id
90 90
      */
91
-    public function getServicesByHostid(string $id, bool $active = TRUE, bool $passive_svc = TRUE)
91
+    public function getServicesByHostid(string $id, bool $active=TRUE, bool $passive_svc=TRUE)
92 92
     {
93
-        $filter = 'match("' . $id . '!*", service.__name)';
93
+        $filter='match("'.$id.'!*", service.__name)';
94 94
         if ($active === TRUE)
95 95
         {
96
-            $filter .= ' && service.active==true';
96
+            $filter.=' && service.active==true';
97 97
         }
98 98
         if ($passive_svc === TRUE)
99 99
         {
100
-            $filter .= ' && service.enable_passive_checks==true';
100
+            $filter.=' && service.enable_passive_checks==true';
101 101
         }
102 102
         return $this->standardQuery(
103 103
             'service',
104 104
             $filter,
105
-            array('__name','name','display_name','active')
105
+            array('__name', 'name', 'display_name', 'active')
106 106
             );
107 107
         
108 108
     }
@@ -117,27 +117,27 @@  discard block
 block discarded – undo
117 117
     {
118 118
          return $this->standardQuery(
119 119
             'host',
120
-            '"' . $group . '" in host.groups',
121
-            array('name','display_name')
120
+            '"'.$group.'" in host.groups',
121
+            array('name', 'display_name')
122 122
             );
123 123
     }
124 124
     
125 125
     public function getServicesByHostGroupid(string $group)
126 126
     {
127
-        $hostList = $this->getHostsByGroup($group);
127
+        $hostList=$this->getHostsByGroup($group);
128 128
         //return $hostList;
129
-        $hostNum = count($hostList);
129
+        $hostNum=count($hostList);
130 130
         $serviceList=array();
131 131
         foreach ($hostList as $curHost)
132 132
         {
133
-            $services = $this->getServicesByHostid($curHost->name);
133
+            $services=$this->getServicesByHostid($curHost->name);
134 134
             foreach ($services as $service)
135 135
             {
136 136
                 //return $service;
137
-                if (! isset($serviceList[$service->name]))
137
+                if (!isset($serviceList[$service->name]))
138 138
                 {
139 139
                     $serviceList[$service->name]=
140
-                        array('num'=> 1 ,'display_name' => $service->display_name);
140
+                        array('num'=> 1, 'display_name' => $service->display_name);
141 141
                 }
142 142
                 else
143 143
                 {
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
         {
151 151
             if ($values['num'] >= $hostNum)
152 152
             {
153
-                $commonServices[$serviceName] = $values['display_name'];
153
+                $commonServices[$serviceName]=$values['display_name'];
154 154
             }
155 155
         }
156 156
         return $commonServices;
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -138,8 +138,7 @@
 block discarded – undo
138 138
                 {
139 139
                     $serviceList[$service->name]=
140 140
                         array('num'=> 1 ,'display_name' => $service->display_name);
141
-                }
142
-                else
141
+                } else
143 142
                 {
144 143
                     $serviceList[$service->name]['num']++;
145 144
                 }
Please login to merge, or discard this patch.
library/Trapdirector/IcingaApi/IcingaApiBase.php 3 patches
Indentation   +308 added lines, -308 removed lines patch added patch discarded remove patch
@@ -8,342 +8,342 @@
 block discarded – undo
8 8
 
9 9
 class IcingaApiBase
10 10
 {
11
-    protected $version = 'v1';      //< icinga2 api version
11
+	protected $version = 'v1';      //< icinga2 api version
12 12
     
13
-    protected $host;                //< icinga2 host name or IP
14
-    protected $port;                //< icinga2 api port
13
+	protected $host;                //< icinga2 host name or IP
14
+	protected $port;                //< icinga2 api port
15 15
     
16
-    protected $user;                //< user name
17
-    protected $pass;                //< user password
18
-    protected $usercert;            //< user key for certificate auth (NOT IMPLEMENTED)
19
-    protected $authmethod='pass';   //< Authentication : 'pass' or 'cert'
16
+	protected $user;                //< user name
17
+	protected $pass;                //< user password
18
+	protected $usercert;            //< user key for certificate auth (NOT IMPLEMENTED)
19
+	protected $authmethod='pass';   //< Authentication : 'pass' or 'cert'
20 20
 
21
-    protected $queryURL=array(
22
-        'host'  => 'objects/hosts',
23
-        'hostgroup' => 'objects/hostgroups',
24
-        'service' => 'objects/services'
25
-    );
21
+	protected $queryURL=array(
22
+		'host'  => 'objects/hosts',
23
+		'hostgroup' => 'objects/hostgroups',
24
+		'service' => 'objects/services'
25
+	);
26 26
     
27
-    protected $curl;
28
-    // http://php.net/manual/de/function.json-last-error.php#119985
29
-    protected $errorReference = [
30
-        JSON_ERROR_NONE => 'No error has occurred.',
31
-        JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.',
32
-        JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.',
33
-        JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded.',
34
-        JSON_ERROR_SYNTAX => 'Syntax error.',
35
-        JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded.',
36
-        JSON_ERROR_RECURSION => 'One or more recursive references in the value to be encoded.',
37
-        JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded.',
38
-        JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given.',
39
-    ];
40
-    const JSON_UNKNOWN_ERROR = 'Unknown error.';
27
+	protected $curl;
28
+	// http://php.net/manual/de/function.json-last-error.php#119985
29
+	protected $errorReference = [
30
+		JSON_ERROR_NONE => 'No error has occurred.',
31
+		JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.',
32
+		JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.',
33
+		JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded.',
34
+		JSON_ERROR_SYNTAX => 'Syntax error.',
35
+		JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded.',
36
+		JSON_ERROR_RECURSION => 'One or more recursive references in the value to be encoded.',
37
+		JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded.',
38
+		JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given.',
39
+	];
40
+	const JSON_UNKNOWN_ERROR = 'Unknown error.';
41 41
     
42
-    /**
43
-     * Creates Icinga2API object
44
-     * 
45
-     * @param string $host host name or IP
46
-     * @param number $port API port
47
-     */
48
-    public function __construct($host, $port = 5665)
49
-    {
50
-        $this->host=$host;
51
-        $this->port=$port;
52
-    }
53
-    /**
54
-     * Set user & pass
55
-     * @param string $user
56
-     * @param string $pass
57
-     */
58
-    public function setCredentials($user,$pass)
59
-    {
60
-        $this->user=$user;
61
-        $this->pass=$pass;
62
-        $this->authmethod='pass';
63
-    }
42
+	/**
43
+	 * Creates Icinga2API object
44
+	 * 
45
+	 * @param string $host host name or IP
46
+	 * @param number $port API port
47
+	 */
48
+	public function __construct($host, $port = 5665)
49
+	{
50
+		$this->host=$host;
51
+		$this->port=$port;
52
+	}
53
+	/**
54
+	 * Set user & pass
55
+	 * @param string $user
56
+	 * @param string $pass
57
+	 */
58
+	public function setCredentials($user,$pass)
59
+	{
60
+		$this->user=$user;
61
+		$this->pass=$pass;
62
+		$this->authmethod='pass';
63
+	}
64 64
     
65
-    /**
66
-     * Set user & certificate (NOT IMPLEMENTED @throws RuntimeException)
67
-     * @param string $user
68
-     * @param string $usercert
69
-     */
70
-    public function setCredentialskey($user,$usercert)
71
-    {
72
-        $this->user=$user;
73
-        $this->usercert=$usercert;
74
-        $this->authmethod='cert';
75
-        throw new RuntimeException('Certificate auth not implemented');
76
-    }
65
+	/**
66
+	 * Set user & certificate (NOT IMPLEMENTED @throws RuntimeException)
67
+	 * @param string $user
68
+	 * @param string $usercert
69
+	 */
70
+	public function setCredentialskey($user,$usercert)
71
+	{
72
+		$this->user=$user;
73
+		$this->usercert=$usercert;
74
+		$this->authmethod='cert';
75
+		throw new RuntimeException('Certificate auth not implemented');
76
+	}
77 77
 
78
-    public function test(array $permissions)
79
-    {
80
-       try
81
-        {
82
-            $result=$this->request('GET', "", NULL, NULL);
83
-        } 
84
-        catch (Exception $e)
85
-        {
86
-            return array(true, 'Error with API : '.$e->getMessage());
87
-        }
88
-        //var_dump($result);
89
-        $permOk=1;
90
-        $permMissing='';
91
-        if ($permissions === NULL || count($permissions) == 0) // If no permission check return OK after connexion
92
-        {
93
-            return array(false,'OK');
94
-        }
95
-        if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions'))
96
-        {
78
+	public function test(array $permissions)
79
+	{
80
+	   try
81
+		{
82
+			$result=$this->request('GET', "", NULL, NULL);
83
+		} 
84
+		catch (Exception $e)
85
+		{
86
+			return array(true, 'Error with API : '.$e->getMessage());
87
+		}
88
+		//var_dump($result);
89
+		$permOk=1;
90
+		$permMissing='';
91
+		if ($permissions === NULL || count($permissions) == 0) // If no permission check return OK after connexion
92
+		{
93
+			return array(false,'OK');
94
+		}
95
+		if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions'))
96
+		{
97 97
             
98
-            foreach ( $permissions as $mustPermission)
99
-            {
100
-                $curPermOK=0;
101
-                foreach ( $result->results[0]->permissions as $curPermission)
102
-                {
103
-                    $curPermission=preg_replace('/\*/','.*',$curPermission); // put * as .* to created a regexp
104
-                    if (preg_match('#'.$curPermission.'#',$mustPermission))
105
-                    {
106
-                        $curPermOK=1;
107
-                        break;
108
-                    }
109
-                }
110
-                if ($curPermOK == 0)
111
-                {
112
-                    $permOk=0;
113
-                    $permMissing=$mustPermission;
114
-                    break;
115
-                }
116
-            }
117
-            if ($permOk == 0)
118
-            {
119
-                return array(true,'API connection OK, but missing permission : '.$permMissing);
120
-            }
121
-            return array(false,'API connection OK');
98
+			foreach ( $permissions as $mustPermission)
99
+			{
100
+				$curPermOK=0;
101
+				foreach ( $result->results[0]->permissions as $curPermission)
102
+				{
103
+					$curPermission=preg_replace('/\*/','.*',$curPermission); // put * as .* to created a regexp
104
+					if (preg_match('#'.$curPermission.'#',$mustPermission))
105
+					{
106
+						$curPermOK=1;
107
+						break;
108
+					}
109
+				}
110
+				if ($curPermOK == 0)
111
+				{
112
+					$permOk=0;
113
+					$permMissing=$mustPermission;
114
+					break;
115
+				}
116
+			}
117
+			if ($permOk == 0)
118
+			{
119
+				return array(true,'API connection OK, but missing permission : '.$permMissing);
120
+			}
121
+			return array(false,'API connection OK');
122 122
             
123
-        }
124
-        return array(true,'API connection OK, but cannot get permissions');
125
-    }
123
+		}
124
+		return array(true,'API connection OK, but cannot get permissions');
125
+	}
126 126
     
127 127
     
128
-    protected function url($url) {
129
-        return sprintf('https://%s:%d/%s/%s', $this->host, $this->port, $this->version, $url);
130
-    }
128
+	protected function url($url) {
129
+		return sprintf('https://%s:%d/%s/%s', $this->host, $this->port, $this->version, $url);
130
+	}
131 131
     
132
-    /**
133
-     * Create or return curl ressource
134
-     * @throws Exception
135
-     * @return resource
136
-     */
137
-    protected function curl() {
138
-        if ($this->curl === null) {
139
-            $this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port));
140
-            if ($this->curl === false) {
141
-                throw new Exception('CURL INIT ERROR');
142
-            }
143
-        }
144
-        return $this->curl;
145
-    }
132
+	/**
133
+	 * Create or return curl ressource
134
+	 * @throws Exception
135
+	 * @return resource
136
+	 */
137
+	protected function curl() {
138
+		if ($this->curl === null) {
139
+			$this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port));
140
+			if ($this->curl === false) {
141
+				throw new Exception('CURL INIT ERROR');
142
+			}
143
+		}
144
+		return $this->curl;
145
+	}
146 146
 
147
-    /**
148
-     * Send a passive service check
149
-     * @param string $host : host name 
150
-     * @param string $service : service name
151
-     * @param int $state : state of service
152
-     * @param string $display : service passive check output
153
-     * @param string $perfdata : performance data as string
154
-     * @return array (status = true (oK) or false (nok), string message)
155
-     */
156
-    public function serviceCheckResult($host,$service,$state,$display,$perfdata='')
157
-    {
158
-        //Send a POST request to the URL endpoint /v1/actions/process-check-result
159
-        //actions/process-check-result?service=example.localdomain!passive-ping6
160
-        $url='actions/process-check-result';
161
-        $body=array(
162
-            "filter"        => 'service.name=="'.$service.'" && service.host_name=="'.$host.'"',
163
-            'type'          => 'Service',
164
-            "exit_status"   => $state,
165
-            "plugin_output" => $display,
166
-            "performance_data" => $perfdata
167
-        );
168
-        try 
169
-        {
170
-            $result=$this->request('POST', $url, null, $body);
171
-        } catch (Exception $e) 
172
-        {
173
-            return array(false, $e->getMessage());
174
-        }
175
-        if (property_exists($result,'error') )
176
-        {
177
-            if (property_exists($result,'status'))
178
-            {
179
-                $message=$result->status;
180
-            }
181
-            else 
182
-            {
183
-                $message="Unkown status";
184
-            }
185
-            return array(false , 'Ret code ' .$result->error.' : '.$message);
186
-        }
187
-        if (property_exists($result, 'results'))
188
-        {
189
-            if (isset($result->results[0]))
190
-            {
191
-                return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status);
192
-            }
193
-            else
194
-            {
195
-                return array(false,'Service not found');
196
-            }
147
+	/**
148
+	 * Send a passive service check
149
+	 * @param string $host : host name 
150
+	 * @param string $service : service name
151
+	 * @param int $state : state of service
152
+	 * @param string $display : service passive check output
153
+	 * @param string $perfdata : performance data as string
154
+	 * @return array (status = true (oK) or false (nok), string message)
155
+	 */
156
+	public function serviceCheckResult($host,$service,$state,$display,$perfdata='')
157
+	{
158
+		//Send a POST request to the URL endpoint /v1/actions/process-check-result
159
+		//actions/process-check-result?service=example.localdomain!passive-ping6
160
+		$url='actions/process-check-result';
161
+		$body=array(
162
+			"filter"        => 'service.name=="'.$service.'" && service.host_name=="'.$host.'"',
163
+			'type'          => 'Service',
164
+			"exit_status"   => $state,
165
+			"plugin_output" => $display,
166
+			"performance_data" => $perfdata
167
+		);
168
+		try 
169
+		{
170
+			$result=$this->request('POST', $url, null, $body);
171
+		} catch (Exception $e) 
172
+		{
173
+			return array(false, $e->getMessage());
174
+		}
175
+		if (property_exists($result,'error') )
176
+		{
177
+			if (property_exists($result,'status'))
178
+			{
179
+				$message=$result->status;
180
+			}
181
+			else 
182
+			{
183
+				$message="Unkown status";
184
+			}
185
+			return array(false , 'Ret code ' .$result->error.' : '.$message);
186
+		}
187
+		if (property_exists($result, 'results'))
188
+		{
189
+			if (isset($result->results[0]))
190
+			{
191
+				return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status);
192
+			}
193
+			else
194
+			{
195
+				return array(false,'Service not found');
196
+			}
197 197
             
198
-        }
199
-        return array(false,'Unkown result, open issue with this : '.print_r($result,true));
200
-    }
198
+		}
199
+		return array(false,'Unkown result, open issue with this : '.print_r($result,true));
200
+	}
201 201
   
202
-    /**
203
-     * Check 'result' exists and check for errors/status
204
-     * @param \stdClass $result
205
-     * @throws Exception 
206
-     */
207
-    public function checkResultStatus(\stdClass $result) 
208
-    {
209
-        if (property_exists($result,'error') )
210
-        {
211
-            if (property_exists($result,'status'))
212
-            {
213
-                throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
214
-            }
215
-            else
216
-            {
217
-                throw new Exception('Ret code ' .$result->error.' : Unkown status');
218
-            }
219
-        }
220
-        if ( ! property_exists($result, 'results'))
221
-        {
222
-            throw new Exception('Unkown result');
223
-        }
224
-    }
202
+	/**
203
+	 * Check 'result' exists and check for errors/status
204
+	 * @param \stdClass $result
205
+	 * @throws Exception 
206
+	 */
207
+	public function checkResultStatus(\stdClass $result) 
208
+	{
209
+		if (property_exists($result,'error') )
210
+		{
211
+			if (property_exists($result,'status'))
212
+			{
213
+				throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
214
+			}
215
+			else
216
+			{
217
+				throw new Exception('Ret code ' .$result->error.' : Unkown status');
218
+			}
219
+		}
220
+		if ( ! property_exists($result, 'results'))
221
+		{
222
+			throw new Exception('Unkown result');
223
+		}
224
+	}
225 225
     
226
-    /**
227
-     * Send request to API
228
-     * @param string $method get/post/...
229
-     * @param string $url (after /v1/ )
230
-     * @param array $headers
231
-     * @param array $body 
232
-     * @throws Exception
233
-     * @return array
234
-     */
235
-    public function request($method, $url, $headers, $body) {
236
-        $auth = sprintf('%s:%s', $this->user, $this->pass);
237
-        $curlHeaders = array("Accept: application/json");
238
-        if ($body !== null) {
239
-            $body = json_encode($body);
240
-            array_push($curlHeaders, 'Content-Type: application/json');
241
-            //array_push($curlHeaders, 'X-HTTP-Method-Override: GET');
242
-        }
243
-        //var_dump($body);
244
-        //var_dump($this->url($url));
245
-        if ($headers !== null) {
246
-            $curlFinalHeaders = array_merge($curlHeaders, $headers);
247
-        } else 
248
-        {
249
-            $curlFinalHeaders=$curlHeaders;
250
-        }
251
-        $curl = $this->curl();
252
-        $opts = array(
253
-            CURLOPT_URL		=> $this->url($url),
254
-            CURLOPT_HTTPHEADER 	=> $curlFinalHeaders,
255
-            CURLOPT_USERPWD		=> $auth,
256
-            CURLOPT_CUSTOMREQUEST	=> strtoupper($method),
257
-            CURLOPT_RETURNTRANSFER 	=> true,
258
-            CURLOPT_CONNECTTIMEOUT 	=> 10,
259
-            CURLOPT_SSL_VERIFYHOST 	=> false,
260
-            CURLOPT_SSL_VERIFYPEER 	=> false,
261
-        );
262
-        if ($body !== null) {
263
-            $opts[CURLOPT_POSTFIELDS] = $body;
264
-        }
265
-        curl_setopt_array($curl, $opts);
266
-        $res = curl_exec($curl);
267
-        if ($res === false) {
268
-            throw new Exception('CURL ERROR: ' . curl_error($curl));
269
-        }
270
-        $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
271
-        if ($statusCode === 401) {
272
-            throw new Exception('Unable to authenticate, please check your API credentials');
273
-        }
274
-        return $this->fromJsonResult($res);
275
-    }
226
+	/**
227
+	 * Send request to API
228
+	 * @param string $method get/post/...
229
+	 * @param string $url (after /v1/ )
230
+	 * @param array $headers
231
+	 * @param array $body 
232
+	 * @throws Exception
233
+	 * @return array
234
+	 */
235
+	public function request($method, $url, $headers, $body) {
236
+		$auth = sprintf('%s:%s', $this->user, $this->pass);
237
+		$curlHeaders = array("Accept: application/json");
238
+		if ($body !== null) {
239
+			$body = json_encode($body);
240
+			array_push($curlHeaders, 'Content-Type: application/json');
241
+			//array_push($curlHeaders, 'X-HTTP-Method-Override: GET');
242
+		}
243
+		//var_dump($body);
244
+		//var_dump($this->url($url));
245
+		if ($headers !== null) {
246
+			$curlFinalHeaders = array_merge($curlHeaders, $headers);
247
+		} else 
248
+		{
249
+			$curlFinalHeaders=$curlHeaders;
250
+		}
251
+		$curl = $this->curl();
252
+		$opts = array(
253
+			CURLOPT_URL		=> $this->url($url),
254
+			CURLOPT_HTTPHEADER 	=> $curlFinalHeaders,
255
+			CURLOPT_USERPWD		=> $auth,
256
+			CURLOPT_CUSTOMREQUEST	=> strtoupper($method),
257
+			CURLOPT_RETURNTRANSFER 	=> true,
258
+			CURLOPT_CONNECTTIMEOUT 	=> 10,
259
+			CURLOPT_SSL_VERIFYHOST 	=> false,
260
+			CURLOPT_SSL_VERIFYPEER 	=> false,
261
+		);
262
+		if ($body !== null) {
263
+			$opts[CURLOPT_POSTFIELDS] = $body;
264
+		}
265
+		curl_setopt_array($curl, $opts);
266
+		$res = curl_exec($curl);
267
+		if ($res === false) {
268
+			throw new Exception('CURL ERROR: ' . curl_error($curl));
269
+		}
270
+		$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
271
+		if ($statusCode === 401) {
272
+			throw new Exception('Unable to authenticate, please check your API credentials');
273
+		}
274
+		return $this->fromJsonResult($res);
275
+	}
276 276
     
277
-    /**
278
-     * 
279
-     * @param string $json json encoded 
280
-     * @throws Exception
281
-     * @return array json decoded
282
-     */
283
-    protected function fromJsonResult($json) {
284
-        $result = @json_decode($json);
285
-        //var_dump($json);
286
-        if ($result === null) {
287
-            throw new Exception('Parsing JSON failed: '.$this->getLastJsonErrorMessage(json_last_error()));
288
-        }
289
-        return $result;
290
-    }
277
+	/**
278
+	 * 
279
+	 * @param string $json json encoded 
280
+	 * @throws Exception
281
+	 * @return array json decoded
282
+	 */
283
+	protected function fromJsonResult($json) {
284
+		$result = @json_decode($json);
285
+		//var_dump($json);
286
+		if ($result === null) {
287
+			throw new Exception('Parsing JSON failed: '.$this->getLastJsonErrorMessage(json_last_error()));
288
+		}
289
+		return $result;
290
+	}
291 291
     
292
-    /**
293
-     * Return text error no json error
294
-     * @param string $errorCode
295
-     * @return string
296
-     */
297
-    protected function getLastJsonErrorMessage($errorCode) {
298
-        if (!array_key_exists($errorCode, $this->errorReference)) {
299
-            return self::JSON_UNKNOWN_ERROR;
300
-        }
301
-        return $this->errorReference[$errorCode];
302
-    }
292
+	/**
293
+	 * Return text error no json error
294
+	 * @param string $errorCode
295
+	 * @return string
296
+	 */
297
+	protected function getLastJsonErrorMessage($errorCode) {
298
+		if (!array_key_exists($errorCode, $this->errorReference)) {
299
+			return self::JSON_UNKNOWN_ERROR;
300
+		}
301
+		return $this->errorReference[$errorCode];
302
+	}
303 303
 
304
-    public function standardQuery(string $urlType , string $filter, array $attributes)
305
-    {
306
-        /*
304
+	public function standardQuery(string $urlType , string $filter, array $attributes)
305
+	{
306
+		/*
307 307
          *  curl -k -s -u  trapdirector:trapdirector -H 'X-HTTP-Method-Override: GET' -X POST 'https://localhost:5665/v1/objects/hosts'
308 308
          *  -d '{"filter":"host.group==\"test_trap\"","attrs": ["address" ,"address6"]}'
309 309
          
310 310
          {"results":[{"attrs":{"__name":"Icinga host","address":"127.0.0.1","display_name":"Icinga host","name":"Icinga host"},"joins":{},"meta":{},"name":"Icinga host","type":"Host"}]}
311 311
          */
312 312
         
313
-        if (! isset($this->queryURL[$urlType] ))
314
-        {
315
-            throw new Exception("Unkown object type");
316
-        }
317
-        $url=$this->queryURL[$urlType];
318
-        $body=array();
319
-        if ($filter !== NULL)
320
-        {
321
-            $body['filter'] = $filter;
322
-        }
323
-        if (count($attributes) != 0)
324
-        {
325
-            $body['attrs'] = $attributes;
326
-        }
313
+		if (! isset($this->queryURL[$urlType] ))
314
+		{
315
+			throw new Exception("Unkown object type");
316
+		}
317
+		$url=$this->queryURL[$urlType];
318
+		$body=array();
319
+		if ($filter !== NULL)
320
+		{
321
+			$body['filter'] = $filter;
322
+		}
323
+		if (count($attributes) != 0)
324
+		{
325
+			$body['attrs'] = $attributes;
326
+		}
327 327
 
328
-        try
329
-        {
330
-            $result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body);
331
-        } catch (Exception $e)
332
-        {
333
-            throw new Exception($e->getMessage());
334
-        }
328
+		try
329
+		{
330
+			$result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body);
331
+		} catch (Exception $e)
332
+		{
333
+			throw new Exception($e->getMessage());
334
+		}
335 335
         
336
-        $this->checkResultStatus($result);
336
+		$this->checkResultStatus($result);
337 337
         
338
-        $numHost=0;
339
-        $hostArray=array();
340
-        while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
341
-        {
342
-            $hostArray[$numHost] = $result->results[$numHost]->attrs;
343
-            $numHost++;
344
-        }
345
-        return $hostArray;
346
-    }
338
+		$numHost=0;
339
+		$hostArray=array();
340
+		while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
341
+		{
342
+			$hostArray[$numHost] = $result->results[$numHost]->attrs;
343
+			$numHost++;
344
+		}
345
+		return $hostArray;
346
+	}
347 347
     
348 348
 }
349 349
 
Please login to merge, or discard this patch.
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -8,15 +8,15 @@  discard block
 block discarded – undo
8 8
 
9 9
 class IcingaApiBase
10 10
 {
11
-    protected $version = 'v1';      //< icinga2 api version
11
+    protected $version='v1'; //< icinga2 api version
12 12
     
13
-    protected $host;                //< icinga2 host name or IP
14
-    protected $port;                //< icinga2 api port
13
+    protected $host; //< icinga2 host name or IP
14
+    protected $port; //< icinga2 api port
15 15
     
16
-    protected $user;                //< user name
17
-    protected $pass;                //< user password
18
-    protected $usercert;            //< user key for certificate auth (NOT IMPLEMENTED)
19
-    protected $authmethod='pass';   //< Authentication : 'pass' or 'cert'
16
+    protected $user; //< user name
17
+    protected $pass; //< user password
18
+    protected $usercert; //< user key for certificate auth (NOT IMPLEMENTED)
19
+    protected $authmethod='pass'; //< Authentication : 'pass' or 'cert'
20 20
 
21 21
     protected $queryURL=array(
22 22
         'host'  => 'objects/hosts',
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
     
27 27
     protected $curl;
28 28
     // http://php.net/manual/de/function.json-last-error.php#119985
29
-    protected $errorReference = [
29
+    protected $errorReference=[
30 30
         JSON_ERROR_NONE => 'No error has occurred.',
31 31
         JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.',
32 32
         JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.',
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
         JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded.',
38 38
         JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given.',
39 39
     ];
40
-    const JSON_UNKNOWN_ERROR = 'Unknown error.';
40
+    const JSON_UNKNOWN_ERROR='Unknown error.';
41 41
     
42 42
     /**
43 43
      * Creates Icinga2API object
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
      * @param string $host host name or IP
46 46
      * @param number $port API port
47 47
      */
48
-    public function __construct($host, $port = 5665)
48
+    public function __construct($host, $port=5665)
49 49
     {
50 50
         $this->host=$host;
51 51
         $this->port=$port;
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
      * @param string $user
56 56
      * @param string $pass
57 57
      */
58
-    public function setCredentials($user,$pass)
58
+    public function setCredentials($user, $pass)
59 59
     {
60 60
         $this->user=$user;
61 61
         $this->pass=$pass;
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
      * @param string $user
68 68
      * @param string $usercert
69 69
      */
70
-    public function setCredentialskey($user,$usercert)
70
+    public function setCredentialskey($user, $usercert)
71 71
     {
72 72
         $this->user=$user;
73 73
         $this->usercert=$usercert;
@@ -90,18 +90,18 @@  discard block
 block discarded – undo
90 90
         $permMissing='';
91 91
         if ($permissions === NULL || count($permissions) == 0) // If no permission check return OK after connexion
92 92
         {
93
-            return array(false,'OK');
93
+            return array(false, 'OK');
94 94
         }
95 95
         if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions'))
96 96
         {
97 97
             
98
-            foreach ( $permissions as $mustPermission)
98
+            foreach ($permissions as $mustPermission)
99 99
             {
100 100
                 $curPermOK=0;
101
-                foreach ( $result->results[0]->permissions as $curPermission)
101
+                foreach ($result->results[0]->permissions as $curPermission)
102 102
                 {
103
-                    $curPermission=preg_replace('/\*/','.*',$curPermission); // put * as .* to created a regexp
104
-                    if (preg_match('#'.$curPermission.'#',$mustPermission))
103
+                    $curPermission=preg_replace('/\*/', '.*', $curPermission); // put * as .* to created a regexp
104
+                    if (preg_match('#'.$curPermission.'#', $mustPermission))
105 105
                     {
106 106
                         $curPermOK=1;
107 107
                         break;
@@ -116,12 +116,12 @@  discard block
 block discarded – undo
116 116
             }
117 117
             if ($permOk == 0)
118 118
             {
119
-                return array(true,'API connection OK, but missing permission : '.$permMissing);
119
+                return array(true, 'API connection OK, but missing permission : '.$permMissing);
120 120
             }
121
-            return array(false,'API connection OK');
121
+            return array(false, 'API connection OK');
122 122
             
123 123
         }
124
-        return array(true,'API connection OK, but cannot get permissions');
124
+        return array(true, 'API connection OK, but cannot get permissions');
125 125
     }
126 126
     
127 127
     
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
      */
137 137
     protected function curl() {
138 138
         if ($this->curl === null) {
139
-            $this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port));
139
+            $this->curl=curl_init(sprintf('https://%s:%d', $this->host, $this->port));
140 140
             if ($this->curl === false) {
141 141
                 throw new Exception('CURL INIT ERROR');
142 142
             }
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
      * @param string $perfdata : performance data as string
154 154
      * @return array (status = true (oK) or false (nok), string message)
155 155
      */
156
-    public function serviceCheckResult($host,$service,$state,$display,$perfdata='')
156
+    public function serviceCheckResult($host, $service, $state, $display, $perfdata='')
157 157
     {
158 158
         //Send a POST request to the URL endpoint /v1/actions/process-check-result
159 159
         //actions/process-check-result?service=example.localdomain!passive-ping6
@@ -172,9 +172,9 @@  discard block
 block discarded – undo
172 172
         {
173 173
             return array(false, $e->getMessage());
174 174
         }
175
-        if (property_exists($result,'error') )
175
+        if (property_exists($result, 'error'))
176 176
         {
177
-            if (property_exists($result,'status'))
177
+            if (property_exists($result, 'status'))
178 178
             {
179 179
                 $message=$result->status;
180 180
             }
@@ -182,21 +182,21 @@  discard block
 block discarded – undo
182 182
             {
183 183
                 $message="Unkown status";
184 184
             }
185
-            return array(false , 'Ret code ' .$result->error.' : '.$message);
185
+            return array(false, 'Ret code '.$result->error.' : '.$message);
186 186
         }
187 187
         if (property_exists($result, 'results'))
188 188
         {
189 189
             if (isset($result->results[0]))
190 190
             {
191
-                return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status);
191
+                return array(true, 'code '.$result->results[0]->code.' : '.$result->results[0]->status);
192 192
             }
193 193
             else
194 194
             {
195
-                return array(false,'Service not found');
195
+                return array(false, 'Service not found');
196 196
             }
197 197
             
198 198
         }
199
-        return array(false,'Unkown result, open issue with this : '.print_r($result,true));
199
+        return array(false, 'Unkown result, open issue with this : '.print_r($result, true));
200 200
     }
201 201
   
202 202
     /**
@@ -206,18 +206,18 @@  discard block
 block discarded – undo
206 206
      */
207 207
     public function checkResultStatus(\stdClass $result) 
208 208
     {
209
-        if (property_exists($result,'error') )
209
+        if (property_exists($result, 'error'))
210 210
         {
211
-            if (property_exists($result,'status'))
211
+            if (property_exists($result, 'status'))
212 212
             {
213
-                throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
213
+                throw new Exception('Ret code '.$result->error.' : '.$result->status);
214 214
             }
215 215
             else
216 216
             {
217
-                throw new Exception('Ret code ' .$result->error.' : Unkown status');
217
+                throw new Exception('Ret code '.$result->error.' : Unkown status');
218 218
             }
219 219
         }
220
-        if ( ! property_exists($result, 'results'))
220
+        if (!property_exists($result, 'results'))
221 221
         {
222 222
             throw new Exception('Unkown result');
223 223
         }
@@ -233,23 +233,23 @@  discard block
 block discarded – undo
233 233
      * @return array
234 234
      */
235 235
     public function request($method, $url, $headers, $body) {
236
-        $auth = sprintf('%s:%s', $this->user, $this->pass);
237
-        $curlHeaders = array("Accept: application/json");
236
+        $auth=sprintf('%s:%s', $this->user, $this->pass);
237
+        $curlHeaders=array("Accept: application/json");
238 238
         if ($body !== null) {
239
-            $body = json_encode($body);
239
+            $body=json_encode($body);
240 240
             array_push($curlHeaders, 'Content-Type: application/json');
241 241
             //array_push($curlHeaders, 'X-HTTP-Method-Override: GET');
242 242
         }
243 243
         //var_dump($body);
244 244
         //var_dump($this->url($url));
245 245
         if ($headers !== null) {
246
-            $curlFinalHeaders = array_merge($curlHeaders, $headers);
246
+            $curlFinalHeaders=array_merge($curlHeaders, $headers);
247 247
         } else 
248 248
         {
249 249
             $curlFinalHeaders=$curlHeaders;
250 250
         }
251
-        $curl = $this->curl();
252
-        $opts = array(
251
+        $curl=$this->curl();
252
+        $opts=array(
253 253
             CURLOPT_URL		=> $this->url($url),
254 254
             CURLOPT_HTTPHEADER 	=> $curlFinalHeaders,
255 255
             CURLOPT_USERPWD		=> $auth,
@@ -260,14 +260,14 @@  discard block
 block discarded – undo
260 260
             CURLOPT_SSL_VERIFYPEER 	=> false,
261 261
         );
262 262
         if ($body !== null) {
263
-            $opts[CURLOPT_POSTFIELDS] = $body;
263
+            $opts[CURLOPT_POSTFIELDS]=$body;
264 264
         }
265 265
         curl_setopt_array($curl, $opts);
266
-        $res = curl_exec($curl);
266
+        $res=curl_exec($curl);
267 267
         if ($res === false) {
268
-            throw new Exception('CURL ERROR: ' . curl_error($curl));
268
+            throw new Exception('CURL ERROR: '.curl_error($curl));
269 269
         }
270
-        $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
270
+        $statusCode=curl_getinfo($curl, CURLINFO_HTTP_CODE);
271 271
         if ($statusCode === 401) {
272 272
             throw new Exception('Unable to authenticate, please check your API credentials');
273 273
         }
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
      * @return array json decoded
282 282
      */
283 283
     protected function fromJsonResult($json) {
284
-        $result = @json_decode($json);
284
+        $result=@json_decode($json);
285 285
         //var_dump($json);
286 286
         if ($result === null) {
287 287
             throw new Exception('Parsing JSON failed: '.$this->getLastJsonErrorMessage(json_last_error()));
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
         return $this->errorReference[$errorCode];
302 302
     }
303 303
 
304
-    public function standardQuery(string $urlType , string $filter, array $attributes)
304
+    public function standardQuery(string $urlType, string $filter, array $attributes)
305 305
     {
306 306
         /*
307 307
          *  curl -k -s -u  trapdirector:trapdirector -H 'X-HTTP-Method-Override: GET' -X POST 'https://localhost:5665/v1/objects/hosts'
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
          {"results":[{"attrs":{"__name":"Icinga host","address":"127.0.0.1","display_name":"Icinga host","name":"Icinga host"},"joins":{},"meta":{},"name":"Icinga host","type":"Host"}]}
311 311
          */
312 312
         
313
-        if (! isset($this->queryURL[$urlType] ))
313
+        if (!isset($this->queryURL[$urlType]))
314 314
         {
315 315
             throw new Exception("Unkown object type");
316 316
         }
@@ -318,11 +318,11 @@  discard block
 block discarded – undo
318 318
         $body=array();
319 319
         if ($filter !== NULL)
320 320
         {
321
-            $body['filter'] = $filter;
321
+            $body['filter']=$filter;
322 322
         }
323 323
         if (count($attributes) != 0)
324 324
         {
325
-            $body['attrs'] = $attributes;
325
+            $body['attrs']=$attributes;
326 326
         }
327 327
 
328 328
         try
@@ -337,9 +337,9 @@  discard block
 block discarded – undo
337 337
         
338 338
         $numHost=0;
339 339
         $hostArray=array();
340
-        while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
340
+        while (isset($result->results[$numHost]) && property_exists($result->results[$numHost], 'attrs'))
341 341
         {
342
-            $hostArray[$numHost] = $result->results[$numHost]->attrs;
342
+            $hostArray[$numHost]=$result->results[$numHost]->attrs;
343 343
             $numHost++;
344 344
         }
345 345
         return $hostArray;
Please login to merge, or discard this patch.
Braces   +7 added lines, -9 removed lines patch added patch discarded remove patch
@@ -80,18 +80,19 @@  discard block
 block discarded – undo
80 80
        try
81 81
         {
82 82
             $result=$this->request('GET', "", NULL, NULL);
83
-        } 
84
-        catch (Exception $e)
83
+        } catch (Exception $e)
85 84
         {
86 85
             return array(true, 'Error with API : '.$e->getMessage());
87 86
         }
88 87
         //var_dump($result);
89 88
         $permOk=1;
90 89
         $permMissing='';
91
-        if ($permissions === NULL || count($permissions) == 0) // If no permission check return OK after connexion
90
+        if ($permissions === NULL || count($permissions) == 0) {
91
+        	// If no permission check return OK after connexion
92 92
         {
93 93
             return array(false,'OK');
94 94
         }
95
+        }
95 96
         if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions'))
96 97
         {
97 98
             
@@ -177,8 +178,7 @@  discard block
 block discarded – undo
177 178
             if (property_exists($result,'status'))
178 179
             {
179 180
                 $message=$result->status;
180
-            }
181
-            else 
181
+            } else 
182 182
             {
183 183
                 $message="Unkown status";
184 184
             }
@@ -189,8 +189,7 @@  discard block
 block discarded – undo
189 189
             if (isset($result->results[0]))
190 190
             {
191 191
                 return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status);
192
-            }
193
-            else
192
+            } else
194 193
             {
195 194
                 return array(false,'Service not found');
196 195
             }
@@ -211,8 +210,7 @@  discard block
 block discarded – undo
211 210
             if (property_exists($result,'status'))
212 211
             {
213 212
                 throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
214
-            }
215
-            else
213
+            } else
216 214
             {
217 215
                 throw new Exception('Ret code ' .$result->error.' : Unkown status');
218 216
             }
Please login to merge, or discard this patch.
configuration.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -6,8 +6,8 @@
 block discarded – undo
6 6
 $this->providePermission('trapdirector/config', $this->translate('Allow to create and modify traps services'));
7 7
 
8 8
 $this->provideConfigTab('config', array(
9
-    'title' => 'Configuration',
10
-    'url'   => 'settings'
9
+	'title' => 'Configuration',
10
+	'url'   => 'settings'
11 11
 ));
12 12
 
13 13
 /**
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -17,22 +17,22 @@
 block discarded – undo
17 17
 ));
18 18
 **/
19 19
 
20
-$section = $this->menuSection(N_('Traps'),array (
20
+$section=$this->menuSection(N_('Traps'), array(
21 21
 	'icon'	=> 'filter',
22 22
 	'url'	=> 'trapdirector'
23 23
 ));
24 24
 
25
-$section->add(N_('Status & Mibs'),array(
25
+$section->add(N_('Status & Mibs'), array(
26 26
 	'url'			=> 'trapdirector/status/',
27 27
 	'permission' 	=> 'trapdirector/view'
28 28
 ));
29 29
 
30
-$section->add(N_('Received'),array(
30
+$section->add(N_('Received'), array(
31 31
 	'url'			=> 'trapdirector/received/',
32 32
 	'permission' 	=> 'trapdirector/view'
33 33
 ));
34 34
 
35
-$section->add(N_('Handlers'),array(
35
+$section->add(N_('Handlers'), array(
36 36
 	'url'			=> 'trapdirector/handler/',
37 37
 	'permission' 	=> 'trapdirector/config'
38 38
 ));
Please login to merge, or discard this patch.