Passed
Push — master ( 4e3982...fc09e8 )
by Patrick
03:58
created
library/Trapdirector/TrapsController.php 1 patch
Indentation   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
 	
50 50
 	
51 51
 	/** Get instance of TrapModuleConfig class
52
-	*	@return TrapModuleConfig
53
-	*/
52
+	 *	@return TrapModuleConfig
53
+	 */
54 54
 	public function getModuleConfig() 
55 55
 	{
56 56
 		if ($this->moduleConfig == Null) 
@@ -82,12 +82,12 @@  discard block
 block discarded – undo
82 82
 	 */
83 83
 	public function getTrapHostListTable()
84 84
 	{
85
-	    if ($this->trapTableHostList == Null) 
85
+		if ($this->trapTableHostList == Null) 
86 86
 		{
87
-	        $this->trapTableHostList = new TrapTableHostList();
88
-	        $this->trapTableHostList->setConfig($this->getModuleConfig());
89
-	    }
90
-	    return $this->trapTableHostList;
87
+			$this->trapTableHostList = new TrapTableHostList();
88
+			$this->trapTableHostList->setConfig($this->getModuleConfig());
89
+		}
90
+		return $this->trapTableHostList;
91 91
 	}
92 92
 	
93 93
 	/**
@@ -108,12 +108,12 @@  discard block
 block discarded – undo
108 108
 	 */
109 109
 	public function getUIDatabase()
110 110
 	{
111
-	    if ($this->UIDatabase == Null)
112
-	    {
113
-	        $this->UIDatabase = new UIDatabase($this);
111
+		if ($this->UIDatabase == Null)
112
+		{
113
+			$this->UIDatabase = new UIDatabase($this);
114 114
 	       
115
-	    }
116
-	    return $this->UIDatabase;
115
+		}
116
+		return $this->UIDatabase;
117 117
 	}
118 118
 
119 119
 	/**
@@ -122,41 +122,41 @@  discard block
 block discarded – undo
122 122
 	 */
123 123
 	public function getIdoConn()
124 124
 	{
125
-	    if ($this->icingaAPI === NULL)
126
-	    {
127
-    	    $host = $this->Config()->get('config', 'icingaAPI_host');
128
-    	    if ($host == '')
129
-    	    {
130
-    	        $this->apiMode = FALSE;
131
-    	        return $this->getUIDatabase();
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);
137
-    	    $this->icingaAPI->setCredentials($user, $pass);
138
-    	    list($ret,$message) = $this->icingaAPI->test($this->getModuleConfig()->getapiUserPermissions());
139
-    	    if ($ret === TRUE) // On error, switch to ido DB
140
-    	    {
141
-    	        $this->apiMode = FALSE;
142
-    	        return $this->getUIDatabase();
143
-    	    }
144
-    	    $this->apiMode = TRUE;
125
+		if ($this->icingaAPI === NULL)
126
+		{
127
+			$host = $this->Config()->get('config', 'icingaAPI_host');
128
+			if ($host == '')
129
+			{
130
+				$this->apiMode = FALSE;
131
+				return $this->getUIDatabase();
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);
137
+			$this->icingaAPI->setCredentials($user, $pass);
138
+			list($ret,$message) = $this->icingaAPI->test($this->getModuleConfig()->getapiUserPermissions());
139
+			if ($ret === TRUE) // On error, switch to ido DB
140
+			{
141
+				$this->apiMode = FALSE;
142
+				return $this->getUIDatabase();
143
+			}
144
+			$this->apiMode = TRUE;
145 145
     	    
146
-	    }
147
-	    return $this->icingaAPI;
146
+		}
147
+		return $this->icingaAPI;
148 148
 	    
149 149
 	}
150 150
 	
151
-    protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
152
-    {
153
-        $limit = $this->params->get('limit', $limit);
154
-        $page = $this->params->get('page', $offset);
151
+	protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
152
+	{
153
+		$limit = $this->params->get('limit', $limit);
154
+		$page = $this->params->get('page', $offset);
155 155
 
156
-        $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
156
+		$paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
157 157
 
158
-        return $paginatable;
159
-    }	
158
+		return $paginatable;
159
+	}	
160 160
 	
161 161
 	public function displayExitError($source,$message)
162 162
 	{	// TODO : check better ways to transmit data (with POST ?)
@@ -165,33 +165,33 @@  discard block
 block discarded – undo
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');
170
-        }		
168
+		if (! $this->Auth()->hasPermission('trapdirector/view')) {
169
+			$this->displayExitError('Permissions','No permission fo view content');
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');
177
-        }		
175
+		if (! $this->Auth()->hasPermission('trapdirector/config')) {
176
+			$this->displayExitError('Permissions','No permission fo configure');
177
+		}		
178 178
 	}
179 179
 	
180
-    /**
181
-     * Check if user has write permission
182
-     * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page
183
-     * @return boolean : user has permission
184
-     */
180
+	/**
181
+	 * Check if user has write permission
182
+	 * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page
183
+	 * @return boolean : user has permission
184
+	 */
185 185
 	protected function checkModuleConfigPermission($check=0)
186 186
 	{
187
-        if (! $this->Auth()->hasPermission('trapdirector/module_config')) {
188
-            if ($check == 0)
189
-            {
190
-                $this->displayExitError('Permissions','No permission fo configure module');
191
-            }
192
-            return false;
193
-        }
194
-        return true;
187
+		if (! $this->Auth()->hasPermission('trapdirector/module_config')) {
188
+			if ($check == 0)
189
+			{
190
+				$this->displayExitError('Permissions','No permission fo configure module');
191
+			}
192
+			return false;
193
+		}
194
+		return true;
195 195
 	}
196 196
 
197 197
 	/*************************  Trap class get **********************/
@@ -211,18 +211,18 @@  discard block
 block discarded – undo
211 211
 	/************************** MIB related **************************/
212 212
 	
213 213
 	/** Get MIBLoader class
214
-	*	@return MIBLoader class
215
-	*/
214
+	 *	@return MIBLoader class
215
+	 */
216 216
 	protected function getMIB()
217 217
 	{
218 218
 		if ($this->MIBData == null)
219 219
 		{
220
-		    $dbConn = $this->getUIDatabase()->getDbConn();
221
-		    if ($dbConn === null) throw new \ErrorException('uncatched db error');
220
+			$dbConn = $this->getUIDatabase()->getDbConn();
221
+			if ($dbConn === null) throw new \ErrorException('uncatched db error');
222 222
 			$this->MIBData=new MIBLoader(
223 223
 				$this->Config()->get('config', 'snmptranslate'),
224 224
 				$this->Config()->get('config', 'snmptranslate_dirs'),
225
-			    $dbConn,
225
+				$dbConn,
226 226
 				$this->getModuleConfig()
227 227
 			);
228 228
 		}
@@ -232,13 +232,13 @@  discard block
 block discarded – undo
232 232
 	/**************************  Database queries *******************/		
233 233
 	
234 234
 	/** Check if director is installed
235
-	*	@return bool true/false
236
-	*/
235
+	 *	@return bool true/false
236
+	 */
237 237
 	protected function isDirectorInstalled()
238 238
 	{
239
-	    $output=array();
240
-	    exec('icingacli module list',$output);
241
-	    foreach ($output as $line)
239
+		$output=array();
240
+		exec('icingacli module list',$output);
241
+		foreach ($output as $line)
242 242
 		{
243 243
 			if (preg_match('/^director .*enabled/',$line))
244 244
 			{
@@ -251,72 +251,72 @@  discard block
 block discarded – undo
251 251
 
252 252
 	/************************ UI elements **************************/
253 253
 	
254
-    /**
255
-     * get max rows to display before paging.
256
-     * @return number
257
-     */
254
+	/**
255
+	 * get max rows to display before paging.
256
+	 * @return number
257
+	 */
258 258
 	public function itemListDisplay()
259 259
 	{
260
-	    return $this->getUIDatabase()->getDBConfigValue('max_rows_in_list');
260
+		return $this->getUIDatabase()->getDBConfigValue('max_rows_in_list');
261 261
 	}
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
-    /**
269
-     * get Handlers categories list (index => textvalue).
270
-     * @return array
271
-     */	
268
+	/**
269
+	 * get Handlers categories list (index => textvalue).
270
+	 * @return array
271
+	 */	
272 272
 	public function getHandlersCategory()
273 273
 	{
274
-	    //<index>:<name>!<index>:<name>
275
-	    $catList = $this->getUIDatabase()->getDBConfigValue('handler_categories');
276
-	    $catListArray=explode('!',$catList);
277
-	    $retArray=array();
278
-	    foreach ($catListArray as $category)
279
-	    {
280
-	        $catArray=explode(':',$category);
281
-	        $retArray[$catArray[0]] = $catArray[1];
282
-	    }
283
-	    return $retArray; 
274
+		//<index>:<name>!<index>:<name>
275
+		$catList = $this->getUIDatabase()->getDBConfigValue('handler_categories');
276
+		$catListArray=explode('!',$catList);
277
+		$retArray=array();
278
+		foreach ($catListArray as $category)
279
+		{
280
+			$catArray=explode(':',$category);
281
+			$retArray[$catArray[0]] = $catArray[1];
282
+		}
283
+		return $retArray; 
284 284
 	}
285 285
 
286 286
 	public function setHandlerCategory(array $catArray)
287 287
 	{
288
-	    $catString='';
289
-	    foreach ($catArray as $index => $value)
290
-	    {
291
-	        if ($catString != '' ) $catString .= '!';
292
-	        $catString .= $index . ':' . $value;
293
-	    }
294
-	    $this->getUIDatabase()->setDBConfigValue('handler_categories', $catString);
288
+		$catString='';
289
+		foreach ($catArray as $index => $value)
290
+		{
291
+			if ($catString != '' ) $catString .= '!';
292
+			$catString .= $index . ':' . $value;
293
+		}
294
+		$this->getUIDatabase()->setDBConfigValue('handler_categories', $catString);
295 295
 	}
296 296
 	
297 297
 	public function addHandlersCategory(string $catName)
298 298
 	{
299
-	    $catArray = $this->getHandlersCategory();
300
-	    $i=1;
301
-	    while (isset($catArray[$i]) && $i < 100) $i++;
302
-	    if ($i == 100) throw new ProgrammingError('Category array error');
303
-	    $catArray[$i] = $catName;
304
-	    $this->setHandlerCategory($catArray);
299
+		$catArray = $this->getHandlersCategory();
300
+		$i=1;
301
+		while (isset($catArray[$i]) && $i < 100) $i++;
302
+		if ($i == 100) throw new ProgrammingError('Category array error');
303
+		$catArray[$i] = $catName;
304
+		$this->setHandlerCategory($catArray);
305 305
 	}
306 306
 	
307 307
 	public function delHandlersCategory(int $catIndex)
308 308
 	{
309
-	    $catArray = $this->getHandlersCategory();
310
-	    unset($catArray[$catIndex]);
311
-	    $this->setHandlerCategory($catArray);
312
-	    $this->getUIDatabase()->updateHandlersOnCategoryDelete($catIndex);
309
+		$catArray = $this->getHandlersCategory();
310
+		unset($catArray[$catIndex]);
311
+		$this->setHandlerCategory($catArray);
312
+		$this->getUIDatabase()->updateHandlersOnCategoryDelete($catIndex);
313 313
 	}
314 314
 	
315 315
 	public function renameHandlersCategory(int $catIndex, string $catName)
316 316
 	{
317
-	    $catArray = $this->getHandlersCategory();
318
-	    $catArray[$catIndex] = $catName;
319
-	    $this->setHandlerCategory($catArray);
317
+		$catArray = $this->getHandlersCategory();
318
+		$catArray[$catIndex] = $catName;
319
+		$this->setHandlerCategory($catArray);
320 320
 	}
321 321
 	
322 322
 }
Please login to merge, or discard this patch.