Passed
Push — master ( 8ef52a...4d2ca2 )
by Patrick
02:00
created
library/Trapdirector/TrapsController.php 1 patch
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	/** @var UIDatabase $UIDatabase */
42 42
 	protected $UIDatabase;
43 43
 	/** @var Icinga2API $IcingaAPI */
44
-	protected $icingaAPI = NULL;
44
+	protected $icingaAPI=NULL;
45 45
 	
46 46
 	
47 47
 	
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 			{
58 58
 				$this->redirectNow('trapdirector/settings?message=No database prefix');
59 59
 			}
60
-			$this->moduleConfig = new TrapModuleConfig($db_prefix);
60
+			$this->moduleConfig=new TrapModuleConfig($db_prefix);
61 61
 		}
62 62
 		return $this->moduleConfig;
63 63
 	}
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 	 */
69 69
 	public function getTrapListTable() {
70 70
 		if ($this->trapTableList == Null) {
71
-			$this->trapTableList = new TrapTableList();
71
+			$this->trapTableList=new TrapTableList();
72 72
 			$this->trapTableList->setConfig($this->getModuleConfig());
73 73
 		}
74 74
 		return $this->trapTableList;
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 	{
82 82
 	    if ($this->trapTableHostList == Null) 
83 83
 		{
84
-	        $this->trapTableHostList = new TrapTableHostList();
84
+	        $this->trapTableHostList=new TrapTableHostList();
85 85
 	        $this->trapTableHostList->setConfig($this->getModuleConfig());
86 86
 	    }
87 87
 	    return $this->trapTableHostList;
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 	{
95 95
 		if ($this->handlerTableList == Null) 
96 96
 		{
97
-			$this->handlerTableList = new HandlerTableList();
97
+			$this->handlerTableList=new HandlerTableList();
98 98
 			$this->handlerTableList->setConfig($this->getModuleConfig());
99 99
 		}
100 100
 		return $this->handlerTableList;
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 	{
108 108
 	    if ($this->UIDatabase == Null)
109 109
 	    {
110
-	        $this->UIDatabase = new UIDatabase($this);
110
+	        $this->UIDatabase=new UIDatabase($this);
111 111
 	       
112 112
 	    }
113 113
 	    return $this->UIDatabase;
@@ -121,13 +121,13 @@  discard block
 block discarded – undo
121 121
 	{
122 122
 	    if ($this->icingaAPI === NULL)
123 123
 	    {
124
-    	    $host = $this->Config()->get('config', 'icingaAPI_host');
125
-    	    $port = $this->Config()->get('config', 'icingaAPI_port');
126
-    	    $user = $this->Config()->get('config', 'icingaAPI_user');
127
-    	    $pass = $this->Config()->get('config', 'icingaAPI_password');
128
-    	    $this->icingaAPI = new Icinga2API($host,$port);
124
+    	    $host=$this->Config()->get('config', 'icingaAPI_host');
125
+    	    $port=$this->Config()->get('config', 'icingaAPI_port');
126
+    	    $user=$this->Config()->get('config', 'icingaAPI_user');
127
+    	    $pass=$this->Config()->get('config', 'icingaAPI_password');
128
+    	    $this->icingaAPI=new Icinga2API($host, $port);
129 129
     	    $this->icingaAPI->setCredentials($user, $pass);
130
-    	    list($ret,$message) = $this->icingaAPI->test(array());
130
+    	    list($ret, $message)=$this->icingaAPI->test(array());
131 131
     	    if ($ret === TRUE)
132 132
     	    {
133 133
     	        return $this->getUIDatabase();
@@ -138,32 +138,32 @@  discard block
 block discarded – undo
138 138
 	    
139 139
 	}
140 140
 	
141
-    protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
141
+    protected function applyPaginationLimits(Paginatable $paginatable, $limit=25, $offset=null)
142 142
     {
143
-        $limit = $this->params->get('limit', $limit);
144
-        $page = $this->params->get('page', $offset);
143
+        $limit=$this->params->get('limit', $limit);
144
+        $page=$this->params->get('page', $offset);
145 145
 
146 146
         $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
147 147
 
148 148
         return $paginatable;
149 149
     }	
150 150
 	
151
-	public function displayExitError($source,$message)
151
+	public function displayExitError($source, $message)
152 152
 	{	// TODO : check better ways to transmit data (with POST ?)
153 153
 		$this->redirectNow('trapdirector/error?source='.$source.'&message='.$message);
154 154
 	}
155 155
 	
156 156
 	protected function checkReadPermission()
157 157
 	{
158
-        if (! $this->Auth()->hasPermission('trapdirector/view')) {
159
-            $this->displayExitError('Permissions','No permission fo view content');
158
+        if (!$this->Auth()->hasPermission('trapdirector/view')) {
159
+            $this->displayExitError('Permissions', 'No permission fo view content');
160 160
         }		
161 161
 	}
162 162
 
163 163
 	protected function checkConfigPermission()
164 164
 	{
165
-        if (! $this->Auth()->hasPermission('trapdirector/config')) {
166
-            $this->displayExitError('Permissions','No permission fo configure');
165
+        if (!$this->Auth()->hasPermission('trapdirector/config')) {
166
+            $this->displayExitError('Permissions', 'No permission fo configure');
167 167
         }		
168 168
 	}
169 169
 	
@@ -174,10 +174,10 @@  discard block
 block discarded – undo
174 174
      */
175 175
 	protected function checkModuleConfigPermission($check=0)
176 176
 	{
177
-        if (! $this->Auth()->hasPermission('trapdirector/module_config')) {
177
+        if (!$this->Auth()->hasPermission('trapdirector/module_config')) {
178 178
             if ($check == 0)
179 179
             {
180
-                $this->displayExitError('Permissions','No permission fo configure module');
180
+                $this->displayExitError('Permissions', 'No permission fo configure module');
181 181
             }
182 182
             return false;
183 183
         }
@@ -189,10 +189,10 @@  discard block
 block discarded – undo
189 189
 	{ // TODO : try/catch here ? or within caller
190 190
 		if ($this->trapClass == null)
191 191
 		{
192
-			require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
192
+			require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
193 193
 			$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
194 194
 			//$debug_level=4;
195
-			$this->trapClass = new Trap($icingaweb2_etc);
195
+			$this->trapClass=new Trap($icingaweb2_etc);
196 196
 			//$Trap->setLogging($debug_level,'syslog');
197 197
 		}
198 198
 		return $this->trapClass;
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 	{
208 208
 		if ($this->MIBData == null)
209 209
 		{
210
-		    $dbConn = $this->getUIDatabase()->getDbConn();
210
+		    $dbConn=$this->getUIDatabase()->getDbConn();
211 211
 		    if ($dbConn === null) throw new \ErrorException('uncatched db error');
212 212
 			$this->MIBData=new MIBLoader(
213 213
 				$this->Config()->get('config', 'snmptranslate'),
@@ -227,10 +227,10 @@  discard block
 block discarded – undo
227 227
 	protected function isDirectorInstalled()
228 228
 	{
229 229
 	    $output=array();
230
-	    exec('icingacli module list',$output);
230
+	    exec('icingacli module list', $output);
231 231
 	    foreach ($output as $line)
232 232
 		{
233
-			if (preg_match('/^director .*enabled/',$line))
233
+			if (preg_match('/^director .*enabled/', $line))
234 234
 			{
235 235
 				return true;
236 236
 			}
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 
253 253
 	public function setitemListDisplay(int $maxRows)
254 254
 	{
255
-	    return $this->getUIDatabase()->setDBConfigValue('max_rows_in_list',$maxRows);
255
+	    return $this->getUIDatabase()->setDBConfigValue('max_rows_in_list', $maxRows);
256 256
 	}
257 257
 	
258 258
     /**
@@ -262,13 +262,13 @@  discard block
 block discarded – undo
262 262
 	public function getHandlersCategory()
263 263
 	{
264 264
 	    //<index>:<name>!<index>:<name>
265
-	    $catList = $this->getUIDatabase()->getDBConfigValue('handler_categories');
266
-	    $catListArray=explode('!',$catList);
265
+	    $catList=$this->getUIDatabase()->getDBConfigValue('handler_categories');
266
+	    $catListArray=explode('!', $catList);
267 267
 	    $retArray=array();
268 268
 	    foreach ($catListArray as $category)
269 269
 	    {
270
-	        $catArray=explode(':',$category);
271
-	        $retArray[$catArray[0]] = $catArray[1];
270
+	        $catArray=explode(':', $category);
271
+	        $retArray[$catArray[0]]=$catArray[1];
272 272
 	    }
273 273
 	    return $retArray; 
274 274
 	}
@@ -278,25 +278,25 @@  discard block
 block discarded – undo
278 278
 	    $catString='';
279 279
 	    foreach ($catArray as $index => $value)
280 280
 	    {
281
-	        if ($catString != '' ) $catString .= '!';
282
-	        $catString .= $index . ':' . $value;
281
+	        if ($catString != '') $catString.='!';
282
+	        $catString.=$index.':'.$value;
283 283
 	    }
284 284
 	    $this->getUIDatabase()->setDBConfigValue('handler_categories', $catString);
285 285
 	}
286 286
 	
287 287
 	public function addHandlersCategory(string $catName)
288 288
 	{
289
-	    $catArray = $this->getHandlersCategory();
289
+	    $catArray=$this->getHandlersCategory();
290 290
 	    $i=1;
291 291
 	    while (isset($catArray[$i]) && $i < 100) $i++;
292 292
 	    if ($i == 100) throw new ProgrammingError('Category array error');
293
-	    $catArray[$i] = $catName;
293
+	    $catArray[$i]=$catName;
294 294
 	    $this->setHandlerCategory($catArray);
295 295
 	}
296 296
 	
297 297
 	public function delHandlersCategory(int $catIndex)
298 298
 	{
299
-	    $catArray = $this->getHandlersCategory();
299
+	    $catArray=$this->getHandlersCategory();
300 300
 	    unset($catArray[$catIndex]);
301 301
 	    $this->setHandlerCategory($catArray);
302 302
 	    $this->getUIDatabase()->updateHandlersOnCategoryDelete($catIndex);
@@ -304,8 +304,8 @@  discard block
 block discarded – undo
304 304
 	
305 305
 	public function renameHandlersCategory(int $catIndex, string $catName)
306 306
 	{
307
-	    $catArray = $this->getHandlersCategory();
308
-	    $catArray[$catIndex] = $catName;
307
+	    $catArray=$this->getHandlersCategory();
308
+	    $catArray[$catIndex]=$catName;
309 309
 	    $this->setHandlerCategory($catArray);
310 310
 	}
311 311
 	
Please login to merge, or discard this patch.
library/Trapdirector/Config/TrapModuleConfig.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -18,27 +18,27 @@  discard block
 block discarded – undo
18 18
 	    'handler_categories' => '0:Not categorized' // handlers categories : <index>:<name>!<index>:<name> ....
19 19
 	);
20 20
 	// get default values for dbconfig
21
-	public function getDBConfigDefaults() { return $this->DBConfigDefaults;}
21
+	public function getDBConfigDefaults() { return $this->DBConfigDefaults; }
22 22
 	/** Minimum DB version
23 23
 	 * @return number
24 24
 	 */
25
-	static public function getDbMinVersion() { return 2;}	
25
+	static public function getDbMinVersion() { return 2; }	
26 26
 	/** Current DB version
27 27
 	 * @return number
28 28
 	 */
29
-	static public function getDbCurVersion() { return 2;}
29
+	static public function getDbCurVersion() { return 2; }
30 30
 
31 31
 	/************ Module configuration **********************/
32 32
 	// Module base path
33 33
 	static public function urlPath() { return 'trapdirector'; }
34
-	static public function getapiUserPermissions() { return array("status", "objects/query/Host", "objects/query/hostgroup", "objects/query/Service" , "actions/process-check-result"); } //< api user permissions required
34
+	static public function getapiUserPermissions() { return array("status", "objects/query/Host", "objects/query/hostgroup", "objects/query/Service", "actions/process-check-result"); } //< api user permissions required
35 35
 	
36 36
 	
37 37
 	/*********** Log configuration *************************/
38 38
 	protected $logLevels=array(0=>'No output', 1=>'critical', 2=>'warning', 3=>'trace', 4=>'ALL');
39
-	public function getlogLevels() { return $this->logLevels;}
40
-	protected $logDestinations=array('syslog'=>'syslog','file'=>'file','display'=>'display');
41
-	public function getLogDestinations() { return $this->logDestinations;}
39
+	public function getlogLevels() { return $this->logLevels; }
40
+	protected $logDestinations=array('syslog'=>'syslog', 'file'=>'file', 'display'=>'display');
41
+	public function getLogDestinations() { return $this->logDestinations; }
42 42
 	
43 43
 	function __construct($prefix)
44 44
 	{
@@ -49,29 +49,29 @@  discard block
 block discarded – undo
49 49
 	// DB table name of trap received list : prefix 't'
50 50
 	public function getTrapTableName() 
51 51
 	{ 
52
-		return array('t' => $this->table_prefix . 'received'); 
52
+		return array('t' => $this->table_prefix.'received'); 
53 53
 	}
54 54
 	// DB table name of trap data  list : prefix 'd'
55 55
 	public function getTrapDataTableName() 
56 56
 	{ 
57
-		return array('d' => $this->table_prefix . 'received_data'); 
57
+		return array('d' => $this->table_prefix.'received_data'); 
58 58
 	}	
59 59
 
60 60
 	// DB table name of rules : prefix 'r'
61 61
 	public function getTrapRuleName() 
62 62
 	{ 
63
-		return array('r' => $this->table_prefix . 'rules'); 
63
+		return array('r' => $this->table_prefix.'rules'); 
64 64
 	}		
65 65
 	
66 66
 	// DB table name of db config : prefix 'c'
67 67
 	public function getDbConfigTableName() 
68 68
 	{ 
69
-		return array('c' => $this->table_prefix . 'db_config');
69
+		return array('c' => $this->table_prefix.'db_config');
70 70
 	}
71 71
 	
72 72
 	// Mib cache tables
73
-	public function getMIBCacheTableName() { return $this->table_prefix . 'mib_cache'; }
74
-	public function getMIBCacheTableTrapObjName() { return $this->table_prefix . 'mib_cache_trap_object'; }
73
+	public function getMIBCacheTableName() { return $this->table_prefix.'mib_cache'; }
74
+	public function getMIBCacheTableTrapObjName() { return $this->table_prefix.'mib_cache_trap_object'; }
75 75
 	
76 76
 	
77 77
 	/****************** Database queries *******************/
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 	public function getHandlerListDisplayColumns()
153 153
 	{
154 154
 		return array(
155
-			'host_name'		=> 'r.host_name',//'UNIX_TIMESTAMP(t.date_received)',
155
+			'host_name'		=> 'r.host_name', //'UNIX_TIMESTAMP(t.date_received)',
156 156
 			'host_group_name'=> 'r.host_group_name',
157 157
 			'source_ip'		=> "CASE WHEN r.ip4 IS NULL THEN r.ip6 ELSE r.ip4 END",
158 158
 			'trap_oid'		=> 'r.trap_oid',
@@ -224,32 +224,32 @@  discard block
 block discarded – undo
224 224
 	public function trapDetailQuery()
225 225
 	{
226 226
 		return array(
227
-			'timestamp'			=> array('Date','UNIX_TIMESTAMP(t.date_received)'),
228
-			'source_ip'			=> array('Source IP','t.source_ip'),
229
-			'source_name'		=> array('Source name','t.source_name'),
230
-			'source_port'		=> array('Source port','t.source_port'),
231
-			'destination_ip'	=> array('Destination IP','t.destination_ip'),
232
-			'destination_port'	=> array('Destination port','t.destination_port'),			
233
-			'trap_oid'			=> array('Numeric OID','t.trap_oid'),
234
-			'trap_name'			=> array('Trap name','t.trap_name'),
235
-			'trap_name_mib'		=> array('Trap MIB','t.trap_name_mib'),
236
-			'status'			=> array('Processing status','t.status'),
237
-			'status_detail'		=> array('Status details','t.status_detail'),
238
-			'process_time'		=> array('Trap processing time','t.process_time'),			
227
+			'timestamp'			=> array('Date', 'UNIX_TIMESTAMP(t.date_received)'),
228
+			'source_ip'			=> array('Source IP', 't.source_ip'),
229
+			'source_name'		=> array('Source name', 't.source_name'),
230
+			'source_port'		=> array('Source port', 't.source_port'),
231
+			'destination_ip'	=> array('Destination IP', 't.destination_ip'),
232
+			'destination_port'	=> array('Destination port', 't.destination_port'),			
233
+			'trap_oid'			=> array('Numeric OID', 't.trap_oid'),
234
+			'trap_name'			=> array('Trap name', 't.trap_name'),
235
+			'trap_name_mib'		=> array('Trap MIB', 't.trap_name_mib'),
236
+			'status'			=> array('Processing status', 't.status'),
237
+			'status_detail'		=> array('Status details', 't.status_detail'),
238
+			'process_time'		=> array('Trap processing time', 't.process_time'),			
239 239
 		);
240 240
 	}
241 241
 	// Trap detail : additional data (<key> => <title> <sql select>)
242 242
 	public function trapDataDetailQuery()
243 243
 	{
244 244
 		return array(
245
-			'oid'				=> array('Numeric OID','d.oid'),
246
-			'oid_name'			=> array('Text OID','d.oid_name'),
247
-			'oid_name_mib'		=> array('MIB','d.oid_name_mib'),
248
-			'value'				=> array('Value','d.value'),
245
+			'oid'				=> array('Numeric OID', 'd.oid'),
246
+			'oid_name'			=> array('Text OID', 'd.oid_name'),
247
+			'oid_name_mib'		=> array('MIB', 'd.oid_name_mib'),
248
+			'value'				=> array('Value', 'd.value'),
249 249
 		);
250 250
 	}
251 251
 	// foreign key of trap data table
252
-	public function trapDataFK() { return 'trap_id';}
252
+	public function trapDataFK() { return 'trap_id'; }
253 253
 	
254 254
 	// Max items in a list OBSOLETE TODO : remove after all tables moved to trapdirectorTable
255 255
 	public function itemListDisplay() { return 25; }
Please login to merge, or discard this patch.
library/Trapdirector/Icinga2Api.php 1 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.
library/Trapdirector/IcingaApi/IcingaApiBase.php 1 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.
configuration.php 1 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.
application/controllers/StatusController.php 1 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.
application/controllers/SettingsController.php 1 patch
Spacing   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -72,23 +72,23 @@  discard block
 block discarded – undo
72 72
   private function check_db()
73 73
   {
74 74
       $db_message=array( // index => ( message OK, message NOK, optional link if NOK )
75
-          0	=>	array('Database configuration OK','',''),
76
-          1	=>	array('Database set in config.ini','No database in config.ini',''),
77
-          2	=>	array('Database exists in Icingaweb2 config','Database does not exist in Icingaweb2 : ',
75
+          0	=>	array('Database configuration OK', '', ''),
76
+          1	=>	array('Database set in config.ini', 'No database in config.ini', ''),
77
+          2	=>	array('Database exists in Icingaweb2 config', 'Database does not exist in Icingaweb2 : ',
78 78
               Url::fromPath('config/resource')),
79
-          3	=>	array('Database credentials OK','Database does not exist/invalid credentials/no schema : ',
79
+          3	=>	array('Database credentials OK', 'Database does not exist/invalid credentials/no schema : ',
80 80
               Url::fromPath('trapdirector/settings/createschema')),
81
-          4	=>	array('Schema is set','Schema is not set for ',
81
+          4	=>	array('Schema is set', 'Schema is not set for ',
82 82
               Url::fromPath('trapdirector/settings/createschema')),
83
-          5	=>	array('Schema is up to date','Schema is outdated :',
83
+          5	=>	array('Schema is up to date', 'Schema is outdated :',
84 84
               Url::fromPath('trapdirector/settings/updateschema')),
85 85
       );
86 86
       
87 87
       try {
88 88
           $this->getUIDatabase()->testGetDb(); // Get DB in test mode
89
-          $dberror=array(0,'');
89
+          $dberror=array(0, '');
90 90
       } catch (DBException $e) {
91
-          $dberror = $e->getArray();
91
+          $dberror=$e->getArray();
92 92
       }
93 93
       
94 94
       $this->view->db_error=$dberror[0];
@@ -96,13 +96,13 @@  discard block
 block discarded – undo
96 96
       {
97 97
           case 2:
98 98
           case 4:
99
-              $db_message[$dberror[0]][1] .= $dberror[1];
99
+              $db_message[$dberror[0]][1].=$dberror[1];
100 100
               break;
101 101
           case 3:
102
-              $db_message[$dberror[0]][1] .= $dberror[1] . ', Message : ' . $dberror[2];
102
+              $db_message[$dberror[0]][1].=$dberror[1].', Message : '.$dberror[2];
103 103
               break;
104 104
           case 5:
105
-              $db_message[$dberror[0]][1] .= ' version '. $dberror[1] . ', version needed : ' .$dberror[2];
105
+              $db_message[$dberror[0]][1].=' version '.$dberror[1].', version needed : '.$dberror[2];
106 106
               break;
107 107
           case 0:
108 108
           case 1:
@@ -114,13 +114,13 @@  discard block
 block discarded – undo
114 114
       
115 115
       try {
116 116
           $this->getUIDatabase()->testGetIdoDb(); // Get DB in test mode
117
-          $dberror=array(0,'');
117
+          $dberror=array(0, '');
118 118
       } catch (DBException $e) {
119
-          $dberror = $e->getArray();
119
+          $dberror=$e->getArray();
120 120
       }
121 121
       
122 122
       $this->view->ido_db_error=$dberror[0];
123
-      $this->view->ido_message='IDO Database : ' . $dberror[1];
123
+      $this->view->ido_message='IDO Database : '.$dberror[1];
124 124
   }
125 125
   
126 126
   /**
@@ -132,13 +132,13 @@  discard block
 block discarded – undo
132 132
   {
133 133
       if ($this->Config()->get('config', 'icingaAPI_host') != '')
134 134
       {
135
-          $apitest=new Icinga2API($this->Config()->get('config', 'icingaAPI_host'),$this->Config()->get('config', 'icingaAPI_port'));
135
+          $apitest=new Icinga2API($this->Config()->get('config', 'icingaAPI_host'), $this->Config()->get('config', 'icingaAPI_port'));
136 136
           $apitest->setCredentials($this->Config()->get('config', 'icingaAPI_user'), $this->Config()->get('config', 'icingaAPI_password'));
137 137
           try {
138
-              list($this->view->apimessageError,$this->view->apimessage)=$apitest->test($this->getModuleConfig()::getapiUserPermissions());
138
+              list($this->view->apimessageError, $this->view->apimessage)=$apitest->test($this->getModuleConfig()::getapiUserPermissions());
139 139
               //$this->view->apimessageError=false;
140 140
           } catch (RuntimeException $e) {
141
-              $this->view->apimessage='API config : ' . $e->getMessage();
141
+              $this->view->apimessage='API config : '.$e->getMessage();
142 142
               $this->view->apimessageError=true;
143 143
           }
144 144
       }
@@ -163,10 +163,10 @@  discard block
 block discarded – undo
163 163
       {
164 164
           $output=array();
165 165
           
166
-          exec('cat ' . $this->module->getBaseDir() .'/bin/trap_in.php | grep "\$icingaweb2Etc=" ',$output);
166
+          exec('cat '.$this->module->getBaseDir().'/bin/trap_in.php | grep "\$icingaweb2Etc=" ', $output);
167 167
           
168 168
           
169
-          if (! isset($output[0]) || ! preg_match('#"'. $icingaweb2_etc .'"#',$output[0]))
169
+          if (!isset($output[0]) || !preg_match('#"'.$icingaweb2_etc.'"#', $output[0]))
170 170
           {
171 171
               $this->view->icingaEtcWarn=1;
172 172
               $this->view->icingaweb2_etc=$icingaweb2_etc;
@@ -182,12 +182,12 @@  discard block
 block discarded – undo
182 182
    */
183 183
   private function get_db_list($allowed)
184 184
   {
185
-      $resources = array();
185
+      $resources=array();
186 186
       foreach (ResourceFactory::getResourceConfigs() as $name => $resource) 
187 187
       {
188 188
           if ($resource->get('type') === 'db' && in_array($resource->get('db'), $allowed)) 
189 189
           {
190
-              $resources[$name] = $name;
190
+              $resources[$name]=$name;
191 191
           }
192 192
       }
193 193
       return $resources;
@@ -199,18 +199,18 @@  discard block
 block discarded – undo
199 199
    */
200 200
   private function get_php_binary()
201 201
   {
202
-      $phpBinary= array( PHP_BINARY, PHP_BINDIR . "/php", '/usr/bin/php');
202
+      $phpBinary=array(PHP_BINARY, PHP_BINDIR."/php", '/usr/bin/php');
203 203
 
204
-      foreach ($phpBinary as $phpBin )
204
+      foreach ($phpBinary as $phpBin)
205 205
       {
206 206
           $output=array();
207 207
           $retCode=255;
208 208
           $input="154865134987aaaa";
209
-          exec("$phpBin -r \"echo '$input';\"",$output,$retCode);
209
+          exec("$phpBin -r \"echo '$input';\"", $output, $retCode);
210 210
           
211
-          if (! isset($output[0])) $output[0]="NO OUT";
211
+          if (!isset($output[0])) $output[0]="NO OUT";
212 212
           
213
-          if ($retCode == 0 && preg_match("/$input/",$output[0]) == 1)
213
+          if ($retCode == 0 && preg_match("/$input/", $output[0]) == 1)
214 214
           {
215 215
               return $phpBin;
216 216
           }          
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 	// But check read permission
240 240
 	$this->checkReadPermission();
241 241
 	
242
-	$this->view->tabs = $this->Module()->getConfigTabs()->activate('config');	
242
+	$this->view->tabs=$this->Module()->getConfigTabs()->activate('config');	
243 243
 	
244 244
 	// Get message : sent on configuration problems detected by controllers
245 245
     $this->get_param();
@@ -254,39 +254,39 @@  discard block
 block discarded – undo
254 254
     $this->check_api();
255 255
 	
256 256
 	//*********** Test snmptrapd alive and options
257
-	list ($this->view->snmptrapdError, $this->view->snmptrapdMessage) = $this->checkSnmpTrapd();
257
+	list ($this->view->snmptrapdError, $this->view->snmptrapdMessage)=$this->checkSnmpTrapd();
258 258
 
259 259
 	// List DB in $ressources
260
-	$resources = $this->get_db_list(array('mysql', 'pgsql')); 
260
+	$resources=$this->get_db_list(array('mysql', 'pgsql')); 
261 261
 
262 262
 	// Check standard Icingaweb2 path
263 263
 	$this->check_icingaweb_path();
264 264
 
265
-	$phpBinary = $this->get_php_binary();
265
+	$phpBinary=$this->get_php_binary();
266 266
 	if ($phpBinary === null)
267 267
 	{
268
-	    $phpBinary = ' PHP BINARY NOT FOUND ';
268
+	    $phpBinary=' PHP BINARY NOT FOUND ';
269 269
 	    
270 270
 	}
271 271
 	
272 272
 	// Setup path for mini documentation
273
-	$this->view->traps_in_config= $phpBinary . ' ' . $this->Module()->getBaseDir() . '/bin/trap_in.php';
273
+	$this->view->traps_in_config=$phpBinary.' '.$this->Module()->getBaseDir().'/bin/trap_in.php';
274 274
 	
275
-	$this->view->installer= $this->Module()->getBaseDir() . '/bin/installer.sh '
275
+	$this->view->installer=$this->Module()->getBaseDir().'/bin/installer.sh '
276 276
 	    . ' -c all ' 
277
-	    . ' -d ' . $this->Module()->getBaseDir()
278
-	    . ' -p ' . $phpBinary
279
-	    . ' -a ' . exec('whoami')
280
-	    . ' -w ' . Icinga::app()->getConfigDir();
277
+	    . ' -d '.$this->Module()->getBaseDir()
278
+	    . ' -p '.$phpBinary
279
+	    . ' -a '.exec('whoami')
280
+	    . ' -w '.Icinga::app()->getConfigDir();
281 281
 	        
282 282
 	// ******************* configuration form setup*******************
283
-	$this->view->form = $form = new TrapsConfigForm();
283
+	$this->view->form=$form=new TrapsConfigForm();
284 284
 	
285 285
 	// set default paths;
286
-	$this->view->form->setPaths($this->Module()->getBaseDir(),Icinga::app()->getConfigDir());
286
+	$this->view->form->setPaths($this->Module()->getBaseDir(), Icinga::app()->getConfigDir());
287 287
 	
288 288
 	// set default ido database
289
-	$this->view->form->setDefaultIDODB($this->Config()->module('monitoring','backends')->get('icinga','resource'));
289
+	$this->view->form->setDefaultIDODB($this->Config()->module('monitoring', 'backends')->get('icinga', 'resource'));
290 290
 	
291 291
 	// Make form handle request.
292 292
 	$form->setIniConfig($this->Config())
@@ -315,18 +315,18 @@  discard block
 block discarded – undo
315 315
       $this->view->configPermission=$this->checkModuleConfigPermission();
316 316
       
317 317
       // Setup tabs
318
-      $this->view->tabs = $this->Module()->getConfigTabs()->activate('satellite');	
318
+      $this->view->tabs=$this->Module()->getConfigTabs()->activate('satellite');	
319 319
       
320
-      $this->view->masterHASet = FALSE;
320
+      $this->view->masterHASet=FALSE;
321 321
       
322
-      $this->view->masterHAConf = array ('name' => 'masterHA1', 'icingaweb2 user'=>'User1');
322
+      $this->view->masterHAConf=array('name' => 'masterHA1', 'icingaweb2 user'=>'User1');
323 323
   }
324 324
   
325 325
   
326 326
   public function createschemaAction()
327 327
   {
328 328
 	$this->checkModuleConfigPermission();
329
-	$this->getTabs()->add('create_schema',array(
329
+	$this->getTabs()->add('create_schema', array(
330 330
 		'active'	=> true,
331 331
 		'label'		=> $this->translate('Create Schema'),
332 332
 		'url'		=> Url::fromRequest()
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
 		// Get module database name
348 348
 		$dbName=$this->Config()->get('config', 'database');
349 349
 
350
-        $dbResource = ResourceFactory::getResourceConfig($dbName);
350
+        $dbResource=ResourceFactory::getResourceConfig($dbName);
351 351
         $dbType=$dbResource->get('db');
352 352
         switch ($dbType) {
353 353
           case 'mysql':
@@ -362,28 +362,28 @@  discard block
 block discarded – undo
362 362
         } 
363 363
 
364 364
 		printf('<pre>');
365
-		require_once $this->Module()->getBaseDir() .'/bin/trap_class.php';
365
+		require_once $this->Module()->getBaseDir().'/bin/trap_class.php';
366 366
 		
367 367
 		$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
368 368
 		$debug_level=4;
369
-		$Trap = new Trap($icingaweb2_etc);
370
-		$Trap->setLogging($debug_level,'display');
369
+		$Trap=new Trap($icingaweb2_etc);
370
+		$Trap->setLogging($debug_level, 'display');
371 371
 		
372 372
 		$prefix=$this->Config()->get('config', 'database_prefix');
373 373
 		// schema file : <path>/SQL/schema_v<verion>.<dbtype>
374
-		$schema=$this->Module()->getBaseDir() . 
375
-		'/SQL/schema_v'. $this->getModuleConfig()->getDbCurVersion() . '.' . $dbFileExt;
374
+		$schema=$this->Module()->getBaseDir(). 
375
+		'/SQL/schema_v'.$this->getModuleConfig()->getDbCurVersion().'.'.$dbFileExt;
376 376
 		
377
-		$Trap->trapsDB->create_schema($schema,$prefix);
377
+		$Trap->trapsDB->create_schema($schema, $prefix);
378 378
 		echo '</pre>';
379 379
 	}
380
-	echo '<br><br>Return to <a href="' . Url::fromPath('trapdirector/settings') .'" class="link-button icon-wrench"> settings page </a>';
380
+	echo '<br><br>Return to <a href="'.Url::fromPath('trapdirector/settings').'" class="link-button icon-wrench"> settings page </a>';
381 381
   }
382 382
 
383 383
   public function updateschemaAction()
384 384
   {
385 385
 	  $this->checkModuleConfigPermission();
386
-      $this->getTabs()->add('get',array(
386
+      $this->getTabs()->add('get', array(
387 387
     		'active'	=> true,
388 388
     		'label'		=> $this->translate('Update Schema'),
389 389
     		'url'		=> Url::fromRequest()
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
           $dberror=$e->getArray(); 
402 402
       }
403 403
 	  
404
-	  echo 'Return to <a href="' . Url::fromPath('trapdirector/settings') .'" class="link-button icon-wrench"> settings page </a><br><br>';
404
+	  echo 'Return to <a href="'.Url::fromPath('trapdirector/settings').'" class="link-button icon-wrench"> settings page </a><br><br>';
405 405
 	  
406 406
 	  if ($dberror[0] != 5)
407 407
 	  {
@@ -409,40 +409,40 @@  discard block
 block discarded – undo
409 409
 	      return;
410 410
 	  }
411 411
       // setup
412
-	  require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
412
+	  require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
413 413
 	  $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
414 414
 	  $debug_level=4;
415
-	  $Trap = new Trap($icingaweb2_etc);
415
+	  $Trap=new Trap($icingaweb2_etc);
416 416
 	  
417 417
 	  
418 418
 	  $prefix=$this->Config()->get('config', 'database_prefix');
419
-	  $updateSchema=$this->Module()->getBaseDir() . '/SQL/';
419
+	  $updateSchema=$this->Module()->getBaseDir().'/SQL/';
420 420
 	  
421 421
 	  $target_version=$dberror[2];
422 422
 	  
423 423
 	  if ($this->params->get('msgok') == null) {
424 424
 	      // Check for messages and display if any
425 425
               echo "Upgrade databse is going to start.<br>Don't forget to backup your database before update<br>";
426
-	      $Trap->setLogging(2,'syslog');
427
-	      $message = $Trap->trapsDB->update_schema($updateSchema,$target_version,$prefix,true);
426
+	      $Trap->setLogging(2, 'syslog');
427
+	      $message=$Trap->trapsDB->update_schema($updateSchema, $target_version, $prefix, true);
428 428
 	      if ($message != '')
429 429
 	      {
430 430
 	          echo 'Note :<br><pre>';
431 431
 	          echo $message;
432 432
 	          echo '</pre>';
433 433
 	          echo '<br>';
434
-	          echo '<a  class="link-button" style="font-size:large;font-weight:bold" href="' . Url::fromPath('trapdirector/settings/updateschema') .'?msgok=1">Click here to update</a>';
434
+	          echo '<a  class="link-button" style="font-size:large;font-weight:bold" href="'.Url::fromPath('trapdirector/settings/updateschema').'?msgok=1">Click here to update</a>';
435 435
 	          echo '<br>';
436 436
 	          return;
437 437
 	      }
438 438
 	  }
439 439
 	  
440
-	  $Trap->setLogging($debug_level,'display');
440
+	  $Trap->setLogging($debug_level, 'display');
441 441
 	  
442
-	  echo 'Updating schema to '. $target_version . ': <br>';
442
+	  echo 'Updating schema to '.$target_version.': <br>';
443 443
 	  echo '<pre>';
444 444
 	  	  
445
-	  $Trap->trapsDB->update_schema($updateSchema,$target_version,$prefix);
445
+	  $Trap->trapsDB->update_schema($updateSchema, $target_version, $prefix);
446 446
 	  echo '</pre>';
447 447
   }  
448 448
 
@@ -451,48 +451,48 @@  discard block
 block discarded – undo
451 451
   {
452 452
       $psOutput=array();
453 453
       // First check is someone is listening to port 162. As not root, we can't have pid... 
454
-      $sspath = exec('which ss 2>/dev/null');
455
-      if(empty($sspath))
454
+      $sspath=exec('which ss 2>/dev/null');
455
+      if (empty($sspath))
456 456
       {
457 457
           // RHEL based systems
458
-          $sspath = '/usr/sbin/ss';
458
+          $sspath='/usr/sbin/ss';
459 459
       }
460
-      if(!is_executable("$sspath"))
460
+      if (!is_executable("$sspath"))
461 461
       {
462
-          return array(1,"Can not execute $sspath");
462
+          return array(1, "Can not execute $sspath");
463 463
       }
464
-      exec("$sspath -lun | grep ':162 '",$psOutput);
464
+      exec("$sspath -lun | grep ':162 '", $psOutput);
465 465
       if (count($psOutput) == 0)
466 466
       {
467
-          return array(1,'Port UDP/162 is not open : is snmptrapd running?');
467
+          return array(1, 'Port UDP/162 is not open : is snmptrapd running?');
468 468
       }
469 469
       $psOutput=array();
470
-      $selinux_state = '';
471
-      if(is_executable('/usr/sbin/getenforce'))
470
+      $selinux_state='';
471
+      if (is_executable('/usr/sbin/getenforce'))
472 472
       {
473
-          $selinux_state = exec('/usr/sbin/getenforce 2>/dev/null');
473
+          $selinux_state=exec('/usr/sbin/getenforce 2>/dev/null');
474 474
       }
475
-      if($selinux_state !== 'Enforcing')
475
+      if ($selinux_state !== 'Enforcing')
476 476
       {
477
-          exec('ps --no-headers -o command -C snmptrapd',$psOutput);
477
+          exec('ps --no-headers -o command -C snmptrapd', $psOutput);
478 478
           if (count($psOutput) == 0)
479 479
           {
480
-              return array(1,"UDP/162 : OK, but no snmptrapd process (?)");
480
+              return array(1, "UDP/162 : OK, but no snmptrapd process (?)");
481 481
           }
482 482
           // Assume there is only one line... TODO : see if there is a better way to do this
483
-          $line = preg_replace('/^.*snmptrapd /','',$psOutput[0]);
484
-          if (!preg_match('/-n/',$line))
485
-              return array(1,'snmptrapd has no -n option : '.$line);
486
-          if (!preg_match('/-O[^ ]*n/',$line))
487
-              return array(1,'snmptrapd has no -On option : '.$line);
488
-          if (!preg_match('/-O[^ ]*e/',$line))
489
-              return array(1,'snmptrapd has no -Oe option : '.$line);
483
+          $line=preg_replace('/^.*snmptrapd /', '', $psOutput[0]);
484
+          if (!preg_match('/-n/', $line))
485
+              return array(1, 'snmptrapd has no -n option : '.$line);
486
+          if (!preg_match('/-O[^ ]*n/', $line))
487
+              return array(1, 'snmptrapd has no -On option : '.$line);
488
+          if (!preg_match('/-O[^ ]*e/', $line))
489
+              return array(1, 'snmptrapd has no -Oe option : '.$line);
490 490
 
491
-          return array(0,'snmptrapd listening to UDP/162, options : '.$line);
491
+          return array(0, 'snmptrapd listening to UDP/162, options : '.$line);
492 492
       }
493 493
       else
494 494
       {
495
-          return array(0,'A daemon (hidden by SELinux) is listening on UDP/162');
495
+          return array(0, 'A daemon (hidden by SELinux) is listening on UDP/162');
496 496
       }
497 497
   }
498 498
 }
Please login to merge, or discard this patch.