Passed
Push — master ( 4e3982...fc09e8 )
by Patrick
03:58
created
library/Trapdirector/TrapsController.php 1 patch
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -39,11 +39,11 @@  discard block
 block discarded – undo
39 39
 	/** @var Trap $trapClass Trap class for bin/trap_class.php */
40 40
 	protected $trapClass;
41 41
 	/** @var UIDatabase $UIDatabase */
42
-	protected $UIDatabase = NULL;
42
+	protected $UIDatabase=NULL;
43 43
 	/** @var Icinga2API $IcingaAPI */
44
-	protected $icingaAPI = NULL;
44
+	protected $icingaAPI=NULL;
45 45
 	/** @var bool $apiMode connection to icinngaDB is by api (true) od ido DB (false) */
46
-	protected $apiMode = FALSE;
46
+	protected $apiMode=FALSE;
47 47
 	
48 48
 	
49 49
 	
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 			{
61 61
 				$this->redirectNow('trapdirector/settings?message=No database prefix');
62 62
 			}
63
-			$this->moduleConfig = new TrapModuleConfig($db_prefix);
63
+			$this->moduleConfig=new TrapModuleConfig($db_prefix);
64 64
 		}
65 65
 		return $this->moduleConfig;
66 66
 	}
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 	 */
72 72
 	public function getTrapListTable() {
73 73
 		if ($this->trapTableList == Null) {
74
-			$this->trapTableList = new TrapTableList();
74
+			$this->trapTableList=new TrapTableList();
75 75
 			$this->trapTableList->setConfig($this->getModuleConfig());
76 76
 		}
77 77
 		return $this->trapTableList;
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 	{
85 85
 	    if ($this->trapTableHostList == Null) 
86 86
 		{
87
-	        $this->trapTableHostList = new TrapTableHostList();
87
+	        $this->trapTableHostList=new TrapTableHostList();
88 88
 	        $this->trapTableHostList->setConfig($this->getModuleConfig());
89 89
 	    }
90 90
 	    return $this->trapTableHostList;
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 	{
98 98
 		if ($this->handlerTableList == Null) 
99 99
 		{
100
-			$this->handlerTableList = new HandlerTableList();
100
+			$this->handlerTableList=new HandlerTableList();
101 101
 			$this->handlerTableList->setConfig($this->getModuleConfig());
102 102
 		}
103 103
 		return $this->handlerTableList;
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	{
111 111
 	    if ($this->UIDatabase == Null)
112 112
 	    {
113
-	        $this->UIDatabase = new UIDatabase($this);
113
+	        $this->UIDatabase=new UIDatabase($this);
114 114
 	       
115 115
 	    }
116 116
 	    return $this->UIDatabase;
@@ -124,56 +124,56 @@  discard block
 block discarded – undo
124 124
 	{
125 125
 	    if ($this->icingaAPI === NULL)
126 126
 	    {
127
-    	    $host = $this->Config()->get('config', 'icingaAPI_host');
127
+    	    $host=$this->Config()->get('config', 'icingaAPI_host');
128 128
     	    if ($host == '')
129 129
     	    {
130
-    	        $this->apiMode = FALSE;
130
+    	        $this->apiMode=FALSE;
131 131
     	        return $this->getUIDatabase();
132 132
     	    }
133
-    	    $port = $this->Config()->get('config', 'icingaAPI_port');
134
-    	    $user = $this->Config()->get('config', 'icingaAPI_user');
135
-    	    $pass = $this->Config()->get('config', 'icingaAPI_password');
136
-    	    $this->icingaAPI = new Icinga2API($host,$port);
133
+    	    $port=$this->Config()->get('config', 'icingaAPI_port');
134
+    	    $user=$this->Config()->get('config', 'icingaAPI_user');
135
+    	    $pass=$this->Config()->get('config', 'icingaAPI_password');
136
+    	    $this->icingaAPI=new Icinga2API($host, $port);
137 137
     	    $this->icingaAPI->setCredentials($user, $pass);
138
-    	    list($ret,$message) = $this->icingaAPI->test($this->getModuleConfig()->getapiUserPermissions());
138
+    	    list($ret, $message)=$this->icingaAPI->test($this->getModuleConfig()->getapiUserPermissions());
139 139
     	    if ($ret === TRUE) // On error, switch to ido DB
140 140
     	    {
141
-    	        $this->apiMode = FALSE;
141
+    	        $this->apiMode=FALSE;
142 142
     	        return $this->getUIDatabase();
143 143
     	    }
144
-    	    $this->apiMode = TRUE;
144
+    	    $this->apiMode=TRUE;
145 145
     	    
146 146
 	    }
147 147
 	    return $this->icingaAPI;
148 148
 	    
149 149
 	}
150 150
 	
151
-    protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
151
+    protected function applyPaginationLimits(Paginatable $paginatable, $limit=25, $offset=null)
152 152
     {
153
-        $limit = $this->params->get('limit', $limit);
154
-        $page = $this->params->get('page', $offset);
153
+        $limit=$this->params->get('limit', $limit);
154
+        $page=$this->params->get('page', $offset);
155 155
 
156 156
         $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
157 157
 
158 158
         return $paginatable;
159 159
     }	
160 160
 	
161
-	public function displayExitError($source,$message)
161
+	public function displayExitError($source, $message)
162 162
 	{	// TODO : check better ways to transmit data (with POST ?)
163 163
 		$this->redirectNow('trapdirector/error?source='.$source.'&message='.$message);
164 164
 	}
165 165
 	
166 166
 	protected function checkReadPermission()
167 167
 	{
168
-        if (! $this->Auth()->hasPermission('trapdirector/view')) {
169
-            $this->displayExitError('Permissions','No permission fo view content');
168
+        if (!$this->Auth()->hasPermission('trapdirector/view')) {
169
+            $this->displayExitError('Permissions', 'No permission fo view content');
170 170
         }		
171 171
 	}
172 172
 
173 173
 	protected function checkConfigPermission()
174 174
 	{
175
-        if (! $this->Auth()->hasPermission('trapdirector/config')) {
176
-            $this->displayExitError('Permissions','No permission fo configure');
175
+        if (!$this->Auth()->hasPermission('trapdirector/config')) {
176
+            $this->displayExitError('Permissions', 'No permission fo configure');
177 177
         }		
178 178
 	}
179 179
 	
@@ -184,10 +184,10 @@  discard block
 block discarded – undo
184 184
      */
185 185
 	protected function checkModuleConfigPermission($check=0)
186 186
 	{
187
-        if (! $this->Auth()->hasPermission('trapdirector/module_config')) {
187
+        if (!$this->Auth()->hasPermission('trapdirector/module_config')) {
188 188
             if ($check == 0)
189 189
             {
190
-                $this->displayExitError('Permissions','No permission fo configure module');
190
+                $this->displayExitError('Permissions', 'No permission fo configure module');
191 191
             }
192 192
             return false;
193 193
         }
@@ -199,10 +199,10 @@  discard block
 block discarded – undo
199 199
 	{ // TODO : try/catch here ? or within caller
200 200
 		if ($this->trapClass == null)
201 201
 		{
202
-			require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
202
+			require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
203 203
 			$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
204 204
 			//$debug_level=4;
205
-			$this->trapClass = new Trap($icingaweb2_etc);
205
+			$this->trapClass=new Trap($icingaweb2_etc);
206 206
 			//$Trap->setLogging($debug_level,'syslog');
207 207
 		}
208 208
 		return $this->trapClass;
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 	{
218 218
 		if ($this->MIBData == null)
219 219
 		{
220
-		    $dbConn = $this->getUIDatabase()->getDbConn();
220
+		    $dbConn=$this->getUIDatabase()->getDbConn();
221 221
 		    if ($dbConn === null) throw new \ErrorException('uncatched db error');
222 222
 			$this->MIBData=new MIBLoader(
223 223
 				$this->Config()->get('config', 'snmptranslate'),
@@ -237,10 +237,10 @@  discard block
 block discarded – undo
237 237
 	protected function isDirectorInstalled()
238 238
 	{
239 239
 	    $output=array();
240
-	    exec('icingacli module list',$output);
240
+	    exec('icingacli module list', $output);
241 241
 	    foreach ($output as $line)
242 242
 		{
243
-			if (preg_match('/^director .*enabled/',$line))
243
+			if (preg_match('/^director .*enabled/', $line))
244 244
 			{
245 245
 				return true;
246 246
 			}
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 
263 263
 	public function setitemListDisplay(int $maxRows)
264 264
 	{
265
-	    return $this->getUIDatabase()->setDBConfigValue('max_rows_in_list',$maxRows);
265
+	    return $this->getUIDatabase()->setDBConfigValue('max_rows_in_list', $maxRows);
266 266
 	}
267 267
 	
268 268
     /**
@@ -272,13 +272,13 @@  discard block
 block discarded – undo
272 272
 	public function getHandlersCategory()
273 273
 	{
274 274
 	    //<index>:<name>!<index>:<name>
275
-	    $catList = $this->getUIDatabase()->getDBConfigValue('handler_categories');
276
-	    $catListArray=explode('!',$catList);
275
+	    $catList=$this->getUIDatabase()->getDBConfigValue('handler_categories');
276
+	    $catListArray=explode('!', $catList);
277 277
 	    $retArray=array();
278 278
 	    foreach ($catListArray as $category)
279 279
 	    {
280
-	        $catArray=explode(':',$category);
281
-	        $retArray[$catArray[0]] = $catArray[1];
280
+	        $catArray=explode(':', $category);
281
+	        $retArray[$catArray[0]]=$catArray[1];
282 282
 	    }
283 283
 	    return $retArray; 
284 284
 	}
@@ -288,25 +288,25 @@  discard block
 block discarded – undo
288 288
 	    $catString='';
289 289
 	    foreach ($catArray as $index => $value)
290 290
 	    {
291
-	        if ($catString != '' ) $catString .= '!';
292
-	        $catString .= $index . ':' . $value;
291
+	        if ($catString != '') $catString.='!';
292
+	        $catString.=$index.':'.$value;
293 293
 	    }
294 294
 	    $this->getUIDatabase()->setDBConfigValue('handler_categories', $catString);
295 295
 	}
296 296
 	
297 297
 	public function addHandlersCategory(string $catName)
298 298
 	{
299
-	    $catArray = $this->getHandlersCategory();
299
+	    $catArray=$this->getHandlersCategory();
300 300
 	    $i=1;
301 301
 	    while (isset($catArray[$i]) && $i < 100) $i++;
302 302
 	    if ($i == 100) throw new ProgrammingError('Category array error');
303
-	    $catArray[$i] = $catName;
303
+	    $catArray[$i]=$catName;
304 304
 	    $this->setHandlerCategory($catArray);
305 305
 	}
306 306
 	
307 307
 	public function delHandlersCategory(int $catIndex)
308 308
 	{
309
-	    $catArray = $this->getHandlersCategory();
309
+	    $catArray=$this->getHandlersCategory();
310 310
 	    unset($catArray[$catIndex]);
311 311
 	    $this->setHandlerCategory($catArray);
312 312
 	    $this->getUIDatabase()->updateHandlersOnCategoryDelete($catIndex);
@@ -314,8 +314,8 @@  discard block
 block discarded – undo
314 314
 	
315 315
 	public function renameHandlersCategory(int $catIndex, string $catName)
316 316
 	{
317
-	    $catArray = $this->getHandlersCategory();
318
-	    $catArray[$catIndex] = $catName;
317
+	    $catArray=$this->getHandlersCategory();
318
+	    $catArray[$catIndex]=$catName;
319 319
 	    $this->setHandlerCategory($catArray);
320 320
 	}
321 321
 	
Please login to merge, or discard this patch.