Passed
Push — master ( 42d7f2...df2595 )
by Patrick
02:12
created
library/Trapdirector/Tables/TrapTableHostList.php 1 patch
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -22,8 +22,8 @@  discard block
 block discarded – undo
22 22
 	// Filters 
23 23
 	
24 24
     protected $filter;
25
-    protected $enforcedFilters = array();
26
-    protected $searchColumns = array();
25
+    protected $enforcedFilters=array();
26
+    protected $searchColumns=array();
27 27
 	
28 28
 	protected function getTitles() {
29 29
 		// TODO : check moduleconfig is set
@@ -33,9 +33,9 @@  discard block
 block discarded – undo
33 33
 	// ******************  Render table in html 
34 34
 	
35 35
 	// Host grouping
36
-	protected function renderHostIfNew($IP,$hostname)
36
+	protected function renderHostIfNew($IP, $hostname)
37 37
 	{
38
-	    $view = $this->getView();
38
+	    $view=$this->getView();
39 39
 	    
40 40
 	    if ($this->lastHost === $IP) {
41 41
 	        return;
@@ -43,31 +43,31 @@  discard block
 block discarded – undo
43 43
 	    
44 44
 	    if ($this->lastHost === null) 
45 45
 	    {
46
-	        $htm = "<thead>\n  <tr>\n";
46
+	        $htm="<thead>\n  <tr>\n";
47 47
 	    } else {
48
-	        $htm = "</tbody>\n<thead>\n  <tr>\n";
48
+	        $htm="</tbody>\n<thead>\n  <tr>\n";
49 49
 	    }
50 50
 	    
51 51
 	    if ($this->columnCount === null) 
52 52
 	    {
53
-	        $this->columnCount = count($this->getTitles());
53
+	        $this->columnCount=count($this->getTitles());
54 54
 	    }
55 55
 	    
56
-	    $htm .= '<th colspan="' . $this->columnCount . '">' . $view->escape($IP);
56
+	    $htm.='<th colspan="'.$this->columnCount.'">'.$view->escape($IP);
57 57
 	    if ($hostname != null)
58 58
 	    {
59
-	        $htm .= ' ('.$hostname.')';
59
+	        $htm.=' ('.$hostname.')';
60 60
 	    }
61
-	    $htm .= '</th>' . "\n";
61
+	    $htm.='</th>'."\n";
62 62
 	    if ($this->lastHost === null) {
63
-	        $htm .= "  </tr>\n";
63
+	        $htm.="  </tr>\n";
64 64
 	    } else {
65
-	        $htm .= "  </tr>\n</thead>\n";
65
+	        $htm.="  </tr>\n</thead>\n";
66 66
 	    }
67 67
 	    
68
-	    $this->lastHost = $IP;
68
+	    $this->lastHost=$IP;
69 69
 	    
70
-	    return $htm . "<tbody>\n";
70
+	    return $htm."<tbody>\n";
71 71
 	}		
72 72
 	
73 73
     public function __toString()
@@ -78,62 +78,62 @@  discard block
 block discarded – undo
78 78
 	public function render()
79 79
 	{
80 80
 		$data=$this->getTable();
81
-		$view = $this->getView();
82
-		$this->columnCount = count($this->getTitles());
81
+		$view=$this->getView();
82
+		$this->columnCount=count($this->getTitles());
83 83
 		$this->lastHost=null;
84 84
 		// Table start
85
-		$htm  = '<table class="simple common-table table-row-selectable">';
85
+		$htm='<table class="simple common-table table-row-selectable">';
86 86
 		
87 87
 		// Titles
88
-		$htm .= "<thead>\n  <tr>\n";
89
-		$titles = $this->getTitles();
88
+		$htm.="<thead>\n  <tr>\n";
89
+		$titles=$this->getTitles();
90 90
 		foreach ($titles as $title) 
91 91
 		{
92
-			$htm .= '    <th>' . $view->escape($view->translate($title)) . "</th>\n";
92
+			$htm.='    <th>'.$view->escape($view->translate($title))."</th>\n";
93 93
 		}
94
-		$htm .= "  </tr>\n</thead>\n";
94
+		$htm.="  </tr>\n</thead>\n";
95 95
 		
96 96
 		// Rows
97
-		$htm .= "<tbody>\n";
97
+		$htm.="<tbody>\n";
98 98
 		
99 99
 		foreach ($data as $row) 
100 100
 		{
101 101
 
102
-			$firstCol = true;
102
+			$firstCol=true;
103 103
 			// Put host header
104
-			$source_name=(property_exists($row,'source_name'))?$row->source_name:null;
105
-			$htm .= $this->renderHostIfNew($row->source_ip,$source_name);
104
+			$source_name=(property_exists($row, 'source_name')) ? $row->source_name : null;
105
+			$htm.=$this->renderHostIfNew($row->source_ip, $source_name);
106 106
 			
107 107
 			
108 108
 			// Render row
109
-			$htm .= '<tr '.' >';
110
-			foreach ( $titles as $rowkey => $title) 
109
+			$htm.='<tr '.' >';
110
+			foreach ($titles as $rowkey => $title) 
111 111
 			{
112 112
 				// Check missing value
113 113
 				if (property_exists($row, $rowkey)) 
114 114
 				{
115
-					$val = ($rowkey=='last_sent') ?  strftime('%c',$row->$rowkey) : $row->$rowkey;
115
+					$val=($rowkey == 'last_sent') ?  strftime('%c', $row->$rowkey) : $row->$rowkey;
116 116
 				} else {
117
-					$val = '-';
117
+					$val='-';
118 118
 				}
119 119
 				if ($firstCol === true) { // Put link in first column for trap detail.
120
-					$htm .= '<td>' 
120
+					$htm.='<td>' 
121 121
 							. $view->qlink(
122 122
 									$view->escape($val),  
123 123
 									Url::fromPath(
124
-										$this->moduleConfig->urlPath() . '/received', 
124
+										$this->moduleConfig->urlPath().'/received', 
125 125
 										array('q' => $row->trap_oid)
126 126
 									)
127 127
 							)
128 128
 							. '</td>';
129 129
 				} else {
130
-					$htm .= '<td>' . $view->escape($val) . '</td>';
130
+					$htm.='<td>'.$view->escape($val).'</td>';
131 131
 				}
132 132
 				$firstCol=false;
133 133
 			}
134
-			$htm .= "<tr>\n";
134
+			$htm.="<tr>\n";
135 135
 		}
136
-		$htm .= "</tbody></table>\n";
136
+		$htm.="</tbody></table>\n";
137 137
 		//$htm .= "Filter : " . $this->filter."<br>\n";
138 138
 		return $htm;
139 139
 
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
     {  
144 144
         $db=$this->db();
145 145
 		
146
-		$query = $this->getBaseQuery();
146
+		$query=$this->getBaseQuery();
147 147
 		$this->applyFiltersToQuery($query);
148 148
 		$values=$db->fetchAll($query);
149 149
 		
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	
155 155
     public function getPaginator()
156 156
     {
157
-        $paginator = new Paginator();
157
+        $paginator=new Paginator();
158 158
         $paginator->setQuery($this);
159 159
 
160 160
         return $paginator;
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 	{
167 167
 		$db=$this->db();
168 168
 		
169
-		$query = $this->getBaseQuery();
169
+		$query=$this->getBaseQuery();
170 170
 		$this->applyFiltersToQuery($query);
171 171
        if ($this->hasLimit() || $this->hasOffset()) {
172 172
             $query->limit($this->getLimit(), $this->getOffset());
@@ -178,10 +178,10 @@  discard block
 block discarded – undo
178 178
     public function getBaseQuery()
179 179
     {
180 180
 		$db=$this->db();
181
-		$query = $db->select()->from(
181
+		$query=$db->select()->from(
182 182
             $this->moduleConfig->getTrapTableName(),
183 183
 		    $this->moduleConfig->getTrapHostListDisplayColumns()
184
-		    )->group(array('t.source_ip','t.source_name','t.trap_oid'))
184
+		    )->group(array('t.source_ip', 't.source_name', 't.trap_oid'))
185 185
 		    ->order('t.source_ip');
186 186
 
187 187
         return $query;
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 	protected $filter_Handler;
193 193
 	protected $filter_query='';
194 194
 	protected $filter_done='';
195
-	protected $filter_query_list=array('q','done');
195
+	protected $filter_query_list=array('q', 'done');
196 196
 	public function renderFilterHTML()
197 197
 	{
198 198
 		$htm=' <form id="filter" name="mainFilter" 
@@ -202,17 +202,17 @@  discard block
 block discarded – undo
202 202
 		$htm.='<input type="text" name="q" title="Search is simple! Try to combine multiple words" 
203 203
 		placeholder="Search..." class="search" value="'.$this->filter_query.'">';
204 204
 		$htm.='<input type="checkbox" id="checkbox_done" name="done" value="1" class="autosubmit" ';
205
-		if	($this->filter_done == 1) { $htm.=' checked ';}
205
+		if ($this->filter_done == 1) { $htm.=' checked '; }
206 206
 		$htm.='> <label for="checkbox_done">Hide processed traps</label>';
207 207
 		$htm.='</form>';
208 208
 		return $htm;
209 209
 	}
210 210
 	
211
-	public function updateFilter($handler,$filter)
211
+	public function updateFilter($handler, $filter)
212 212
 	{
213 213
 		$this->filter_Handler=$handler->remove($this->filter_query_list)->__toString();
214
-		$this->filter_query=(isset($filter['q']))?$this->filter_query=$filter['q']:'';
215
-		$this->filter_done=(isset($filter['done']))?$this->filter_done=$filter['done']:0;
214
+		$this->filter_query=(isset($filter['q'])) ? $this->filter_query=$filter['q'] : '';
215
+		$this->filter_done=(isset($filter['done'])) ? $this->filter_done=$filter['done'] : 0;
216 216
 	}
217 217
 	
218 218
     protected function getSearchColumns()
@@ -227,20 +227,20 @@  discard block
 block discarded – undo
227 227
 
228 228
     public function setFilter($filter)
229 229
     {
230
-        $this->filter = $filter;
230
+        $this->filter=$filter;
231 231
         return $this;
232 232
     }
233 233
 	
234 234
 	public function getFilterEditor(Request $request)
235 235
     {
236
-        $filterEditor = Widget::create('filterEditor')
236
+        $filterEditor=Widget::create('filterEditor')
237 237
             ->setColumns(array_keys($this->getColumns()))
238 238
             ->setSearchColumns(array_keys($this->getSearchColumns()))
239 239
             ->preserveParams('limit', 'sort', 'dir', 'view', 'backend')
240 240
             ->ignoreParams('page')
241 241
             ->handleRequest($request);
242 242
 
243
-        $filter = $filterEditor->getFilter();
243
+        $filter=$filterEditor->getFilter();
244 244
         $this->setFilter($filter);
245 245
 
246 246
         return $filterEditor;
@@ -254,9 +254,9 @@  discard block
 block discarded – undo
254 254
 		{
255 255
 			$sql.='(';
256 256
 			$first=1;
257
-			foreach($this->moduleConfig->getTrapListSearchColumns() as $column)
257
+			foreach ($this->moduleConfig->getTrapListSearchColumns() as $column)
258 258
 			{
259
-				if ($first==0) $sql.=' OR ';
259
+				if ($first == 0) $sql.=' OR ';
260 260
 				$first=0;
261 261
 				$sql.=" ".$column." LIKE  '%".$this->filter_query."%' ";
262 262
 			}
Please login to merge, or discard this patch.
library/Trapdirector/TrapsController.php 2 patches
Indentation   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -32,8 +32,8 @@  discard block
 block discarded – undo
32 32
 	protected $trapClass;		//< Trap class for bin/trap_class.php
33 33
 		
34 34
 	/** Get instance of TrapModuleConfig class
35
-	*	@return TrapModuleConfig
36
-	*/
35
+	 *	@return TrapModuleConfig
36
+	 */
37 37
 	public function getModuleConfig() 
38 38
 	{
39 39
 		if ($this->moduleConfig == Null) 
@@ -58,12 +58,12 @@  discard block
 block discarded – undo
58 58
 	
59 59
 	public function getTrapHostListTable()
60 60
 	{
61
-	    if ($this->trapTableHostList == Null) 
61
+		if ($this->trapTableHostList == Null) 
62 62
 		{
63
-	        $this->trapTableHostList = new TrapTableHostList();
64
-	        $this->trapTableHostList->setConfig($this->getModuleConfig());
65
-	    }
66
-	    return $this->trapTableHostList;
63
+			$this->trapTableHostList = new TrapTableHostList();
64
+			$this->trapTableHostList->setConfig($this->getModuleConfig());
65
+		}
66
+		return $this->trapTableHostList;
67 67
 	}
68 68
 	
69 69
 	public function getHandlerListTable() 
@@ -77,11 +77,11 @@  discard block
 block discarded – undo
77 77
 	}	
78 78
 	
79 79
 	/**	Get Database connexion
80
-	*	@param $DBname string DB name in resource.ini_ge
81
-	*	@param $test bool if set to true, returns error code and not database
82
-	*	@param $test_version bool if set to flase, does not test database version of trapDB
83
-	*	@return array<integer,mixed>|mixed : if test=false, returns DB connexion, else array(error_num,message) or null on error.
84
-	*/
80
+	 *	@param $DBname string DB name in resource.ini_ge
81
+	 *	@param $test bool if set to true, returns error code and not database
82
+	 *	@param $test_version bool if set to flase, does not test database version of trapDB
83
+	 *	@return array<integer,mixed>|mixed : if test=false, returns DB connexion, else array(error_num,message) or null on error.
84
+	 */
85 85
 	public function getDbByName($DBname,$test=false,$test_version=true)
86 86
 	{
87 87
 		try 
@@ -161,20 +161,20 @@  discard block
 block discarded – undo
161 161
 
162 162
 		if ( ! $dbresource )
163 163
 		{
164
-		    if ($test) return array(1,'No database in config.ini');
165
-		    $this->redirectNow('trapdirector/settings?idodberror=1');
166
-		    return null;
164
+			if ($test) return array(1,'No database in config.ini');
165
+			$this->redirectNow('trapdirector/settings?idodberror=1');
166
+			return null;
167 167
 		}
168 168
 		
169 169
 		try
170 170
 		{
171
-		    $dbconn = IcingaDbConnection::fromResourceName($dbresource);
171
+			$dbconn = IcingaDbConnection::fromResourceName($dbresource);
172 172
 		}
173 173
 		catch (Exception $e)
174 174
 		{
175
-		    if ($test) return array(2,"Database $dbresource does not exists in IcingaWeb2");
176
-		    $this->redirectNow('trapdirector/settings?idodberror=2');
177
-		    return null;
175
+			if ($test) return array(2,"Database $dbresource does not exists in IcingaWeb2");
176
+			$this->redirectNow('trapdirector/settings?idodberror=2');
177
+			return null;
178 178
 		}
179 179
 		
180 180
 		if ($test == false) 
@@ -185,13 +185,13 @@  discard block
 block discarded – undo
185 185
 		
186 186
 		try
187 187
 		{
188
-		    $query = $dbconn->select()
189
-		    ->from('icinga_dbversion',array('version'));
190
-		    $version=$dbconn->fetchRow($query);
191
-		    if ( ($version == null) || ! property_exists($version,'version') )
192
-		    {
193
-		        return array(4,"$dbresource does not look like an IDO database");
194
-		    }
188
+			$query = $dbconn->select()
189
+			->from('icinga_dbversion',array('version'));
190
+			$version=$dbconn->fetchRow($query);
191
+			if ( ($version == null) || ! property_exists($version,'version') )
192
+			{
193
+				return array(4,"$dbresource does not look like an IDO database");
194
+			}
195 195
 		}
196 196
 		catch (Exception $e)
197 197
 		{
@@ -201,15 +201,15 @@  discard block
 block discarded – undo
201 201
 		return array(0,'');
202 202
 	}
203 203
 	
204
-    protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
205
-    {
206
-        $limit = $this->params->get('limit', $limit);
207
-        $page = $this->params->get('page', $offset);
204
+	protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
205
+	{
206
+		$limit = $this->params->get('limit', $limit);
207
+		$page = $this->params->get('page', $offset);
208 208
 
209
-        $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
209
+		$paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
210 210
 
211
-        return $paginatable;
212
-    }	
211
+		return $paginatable;
212
+	}	
213 213
 	
214 214
 	public function displayExitError($source,$message)
215 215
 	{	// TODO : check better ways to transmit data (with POST ?)
@@ -218,33 +218,33 @@  discard block
 block discarded – undo
218 218
 	
219 219
 	protected function checkReadPermission()
220 220
 	{
221
-        if (! $this->Auth()->hasPermission('trapdirector/view')) {
222
-            $this->displayExitError('Permissions','No permission fo view content');
223
-        }		
221
+		if (! $this->Auth()->hasPermission('trapdirector/view')) {
222
+			$this->displayExitError('Permissions','No permission fo view content');
223
+		}		
224 224
 	}
225 225
 
226 226
 	protected function checkConfigPermission()
227 227
 	{
228
-        if (! $this->Auth()->hasPermission('trapdirector/config')) {
229
-            $this->displayExitError('Permissions','No permission fo configure');
230
-        }		
228
+		if (! $this->Auth()->hasPermission('trapdirector/config')) {
229
+			$this->displayExitError('Permissions','No permission fo configure');
230
+		}		
231 231
 	}
232 232
 	
233
-    /**
234
-     * Check if user has write permission
235
-     * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page
236
-     * @return boolean : user has permission
237
-     */
233
+	/**
234
+	 * Check if user has write permission
235
+	 * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page
236
+	 * @return boolean : user has permission
237
+	 */
238 238
 	protected function checkModuleConfigPermission($check=0)
239 239
 	{
240
-        if (! $this->Auth()->hasPermission('trapdirector/module_config')) {
241
-            if ($check == 0)
242
-            {
243
-                $this->displayExitError('Permissions','No permission fo configure module');
244
-            }
245
-            return false;
246
-        }
247
-        return true;
240
+		if (! $this->Auth()->hasPermission('trapdirector/module_config')) {
241
+			if ($check == 0)
242
+			{
243
+				$this->displayExitError('Permissions','No permission fo configure module');
244
+			}
245
+			return false;
246
+		}
247
+		return true;
248 248
 	}
249 249
 
250 250
 	/*************************  Trap class get **********************/
@@ -264,8 +264,8 @@  discard block
 block discarded – undo
264 264
 	/************************** MIB related **************************/
265 265
 	
266 266
 	/** Get MIBLoader class
267
-	*	@return MIBLoader class
268
-	*/
267
+	 *	@return MIBLoader class
268
+	 */
269 269
 	protected function getMIB()
270 270
 	{
271 271
 		if ($this->MIBData == null)
@@ -283,9 +283,9 @@  discard block
 block discarded – undo
283 283
 	/**************************  Database queries *******************/
284 284
 	
285 285
 	/** Get host(s) by IP (v4 or v6) or by name in IDO database
286
-	*	does not catch exceptions
287
-	*	@return array of objects ( name, id (object_id), display_name)
288
-	*/
286
+	 *	does not catch exceptions
287
+	 *	@return array of objects ( name, id (object_id), display_name)
288
+	 */
289 289
 	protected function getHostByIP($ip) 
290 290
 	{
291 291
 		// select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
@@ -304,9 +304,9 @@  discard block
 block discarded – undo
304 304
 	}
305 305
 
306 306
 	/** Get host(s) by name in IDO database
307
-	*	does not catch exceptions
308
-	*	@return array of objects ( name, id (object_id), display_name)
309
-	*/
307
+	 *	does not catch exceptions
308
+	 *	@return array of objects ( name, id (object_id), display_name)
309
+	 */
310 310
 	protected function getHostByName($name) 
311 311
 	{
312 312
 		// select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
@@ -325,9 +325,9 @@  discard block
 block discarded – undo
325 325
 	}	
326 326
 	
327 327
 	/** Get host groups by  name in IDO database
328
-	*	does not catch exceptions
329
-	*	@return array of objects ( name, id (object_id), display_name)
330
-	*/
328
+	 *	does not catch exceptions
329
+	 *	@return array of objects ( name, id (object_id), display_name)
330
+	 */
331 331
 	protected function getHostGroupByName($ip) 
332 332
 	{
333 333
 		// select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
@@ -347,9 +347,9 @@  discard block
 block discarded – undo
347 347
 
348 348
 	
349 349
 	/** Get host IP (v4 and v6) by name in IDO database
350
-	*	does not catch exceptions
351
-	*	@return array ( name, display_name, ip4, ip6)
352
-	*/
350
+	 *	does not catch exceptions
351
+	 *	@return array ( name, display_name, ip4, ip6)
352
+	 */
353 353
 	protected function getHostInfoByID($id) 
354 354
 	{
355 355
 		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
@@ -368,9 +368,9 @@  discard block
 block discarded – undo
368 368
 
369 369
 	
370 370
 	/** Get host by objectid  in IDO database
371
-	*	does not catch exceptions
372
-	*	@return array of objects ( id, name, display_name, ip, ip6,  )
373
-	*/
371
+	 *	does not catch exceptions
372
+	 *	@return array of objects ( id, name, display_name, ip, ip6,  )
373
+	 */
374 374
 	protected function getHostByObjectID($id) // TODO : duplicate of getHostInfoByID above
375 375
 	{
376 376
 		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
@@ -388,10 +388,10 @@  discard block
 block discarded – undo
388 388
 	}	
389 389
 	
390 390
 	/** Get services from object ( host_object_id) in IDO database
391
-	*	does not catch exceptions
392
-	*	@param $id	int object_id
393
-	*	@return array display_name (of service), service_object_id
394
-	*/
391
+	 *	does not catch exceptions
392
+	 *	@param $id	int object_id
393
+	 *	@return array display_name (of service), service_object_id
394
+	 */
395 395
 	protected function getServicesByHostid($id) 
396 396
 	{
397 397
 		// select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
@@ -411,11 +411,11 @@  discard block
 block discarded – undo
411 411
 	}	
412 412
 	
413 413
 	/** Get services from hostgroup object id ( hostgroup_object_id) in IDO database
414
-	* 	gets all hosts in hostgroup and return common services
415
-	*	does not catch exceptions
416
-	*	@param $id	int object_id
417
-	*	@return array display_name (of service), service_object_id
418
-	*/
414
+	 * 	gets all hosts in hostgroup and return common services
415
+	 *	does not catch exceptions
416
+	 *	@param $id	int object_id
417
+	 *	@return array display_name (of service), service_object_id
418
+	 */
419 419
 	protected function getServicesByHostGroupid($id) 
420 420
 	{		
421 421
 		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
 		//print_r($common_services);
455 455
 		foreach (array_keys($common_services) as $key)
456 456
 		{
457
-		    if ($common_services[$key]['num'] == $num_hosts)
457
+			if ($common_services[$key]['num'] == $num_hosts)
458 458
 			{
459 459
 				array_push($result,array($key,$common_services[$key]['name']));
460 460
 			}
@@ -464,11 +464,11 @@  discard block
 block discarded – undo
464 464
 	}	
465 465
 
466 466
 	/** Get services object id by host name / service name in IDO database
467
-	*	does not catch exceptions
468
-	*	@param $hostname string host name
469
-	*	@param $name string service name
470
-	*	@return array  service id
471
-	*/
467
+	 *	does not catch exceptions
468
+	 *	@param $hostname string host name
469
+	 *	@param $name string service name
470
+	 *	@return array  service id
471
+	 */
472 472
 	protected function getServiceIDByName($hostname,$name) 
473 473
 	{
474 474
 		$db = $this->getIdoDb()->getConnection();
@@ -491,10 +491,10 @@  discard block
 block discarded – undo
491 491
 	}
492 492
 	
493 493
 	/** Get object name from object_id  in IDO database
494
-	*	does not catch exceptions
495
-	*	@param int $id object_id (default to null, used first if not null)
496
-	*	@return array name1 (host) name2 (service)
497
-	*/
494
+	 *	does not catch exceptions
495
+	 *	@param int $id object_id (default to null, used first if not null)
496
+	 *	@return array name1 (host) name2 (service)
497
+	 */
498 498
 	protected function getObjectNameByid($id) 
499 499
 	{
500 500
 		// select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
@@ -510,9 +510,9 @@  discard block
 block discarded – undo
510 510
 	}		
511 511
 
512 512
 	/** Add handler rule in traps DB
513
-	*	@param array(<db item>=><value>)
514
-	*	@return int inserted id
515
-	*/
513
+	 *	@param array(<db item>=><value>)
514
+	 *	@return int inserted id
515
+	 */
516 516
 	protected function addHandlerRule($params)
517 517
 	{
518 518
 		// TODO Check for rule consistency
@@ -534,9 +534,9 @@  discard block
 block discarded – undo
534 534
 	}	
535 535
 
536 536
 	/** Update handler rule in traps DB
537
-	*	@param array(<db item>=><value>)
538
-	*	@return array affected rows
539
-	*/
537
+	 *	@param array(<db item>=><value>)
538
+	 *	@return array affected rows
539
+	 */
540 540
 	protected function updateHandlerRule($params,$ruleID)
541 541
 	{
542 542
 		// TODO Check for rule consistency
@@ -554,8 +554,8 @@  discard block
 block discarded – undo
554 554
 	}	
555 555
 	
556 556
 	/** Delete rule by id
557
-	*	@param int $ruleID rule id
558
-	*/
557
+	 *	@param int $ruleID rule id
558
+	 */
559 559
 	protected function deleteRule($ruleID)
560 560
 	{
561 561
 		if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id');  }
@@ -569,9 +569,9 @@  discard block
 block discarded – undo
569 569
 	}
570 570
 
571 571
 	/** Delete trap by ip & oid
572
-	*	@param $ip string source IP (v4 or v6)
573
-	*	@param $oid string oid
574
-	*/
572
+	 *	@param $ip string source IP (v4 or v6)
573
+	 *	@param $oid string oid
574
+	 */
575 575
 	protected function deleteTrap($ip,$oid)
576 576
 	{
577 577
 		
@@ -597,9 +597,9 @@  discard block
 block discarded – undo
597 597
    
598 598
 
599 599
 	/** count trap by ip & oid
600
-	*	@param $ip string source IP (v4 or v6)
601
-	*	@param $oid string oid
602
-	*/
600
+	 *	@param $ip string source IP (v4 or v6)
601
+	 *	@param $oid string oid
602
+	 */
603 603
 	protected function countTrap($ip,$oid)
604 604
 	{
605 605
 		
@@ -625,8 +625,8 @@  discard block
 block discarded – undo
625 625
 	}		
626 626
 	
627 627
 	/** get configuration value
628
-	*	@param configuration name in db
629
-	*/
628
+	 *	@param configuration name in db
629
+	 */
630 630
 	protected function getDBConfigValue($element)
631 631
 	{
632 632
 	
@@ -657,8 +657,8 @@  discard block
 block discarded – undo
657 657
 	}
658 658
 
659 659
 	/** add configuration value
660
-	*	@param name value
661
-	*/
660
+	 *	@param name value
661
+	 */
662 662
 	protected function addDBConfigValue($element,$value)
663 663
 	{
664 664
 	
@@ -675,8 +675,8 @@  discard block
 block discarded – undo
675 675
 	}
676 676
 
677 677
 	/** set configuration value
678
-	*	@param name value
679
-	*/
678
+	 *	@param name value
679
+	 */
680 680
 	protected function setDBConfigValue($element,$value)
681 681
 	{
682 682
 	
@@ -690,13 +690,13 @@  discard block
 block discarded – undo
690 690
 	}
691 691
 	
692 692
 	/** Check if director is installed
693
-	*	@return bool true/false
694
-	*/
693
+	 *	@return bool true/false
694
+	 */
695 695
 	protected function isDirectorInstalled()
696 696
 	{
697
-	    $output=array();
698
-	    exec('icingacli module list',$output);
699
-	    foreach ($output as $line)
697
+		$output=array();
698
+		exec('icingacli module list',$output);
699
+		foreach ($output as $line)
700 700
 		{
701 701
 			if (preg_match('/^director .*enabled/',$line))
702 702
 			{
Please login to merge, or discard this patch.
Spacing   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -22,14 +22,14 @@  discard block
 block discarded – undo
22 22
 
23 23
 class TrapsController extends Controller
24 24
 {
25
-	protected $moduleConfig;  	//< TrapModuleConfig instance
26
-	protected $trapTableList; 	//< TrapTableList (by date)
27
-	protected $trapTableHostList; 	//< TrapTableList (by hosts)
28
-	protected $handlerTableList; 	//< HandlerTableList instance
29
-	protected $trapDB;			//< Trap database
30
-	protected $icingaDB;		//< Icinga IDO database;
31
-	protected $MIBData; 		//< MIBLoader class
32
-	protected $trapClass;		//< Trap class for bin/trap_class.php
25
+	protected $moduleConfig; //< TrapModuleConfig instance
26
+	protected $trapTableList; //< TrapTableList (by date)
27
+	protected $trapTableHostList; //< TrapTableList (by hosts)
28
+	protected $handlerTableList; //< HandlerTableList instance
29
+	protected $trapDB; //< Trap database
30
+	protected $icingaDB; //< Icinga IDO database;
31
+	protected $MIBData; //< MIBLoader class
32
+	protected $trapClass; //< Trap class for bin/trap_class.php
33 33
 		
34 34
 	/** Get instance of TrapModuleConfig class
35 35
 	*	@return TrapModuleConfig
@@ -43,14 +43,14 @@  discard block
 block discarded – undo
43 43
 			{
44 44
 				$this->redirectNow('trapdirector/settings?message=No database prefix');
45 45
 			}
46
-			$this->moduleConfig = new TrapModuleConfig($db_prefix);
46
+			$this->moduleConfig=new TrapModuleConfig($db_prefix);
47 47
 		}
48 48
 		return $this->moduleConfig;
49 49
 	}
50 50
 	
51 51
 	public function getTrapListTable() {
52 52
 		if ($this->trapTableList == Null) {
53
-			$this->trapTableList = new TrapTableList();
53
+			$this->trapTableList=new TrapTableList();
54 54
 			$this->trapTableList->setConfig($this->getModuleConfig());
55 55
 		}
56 56
 		return $this->trapTableList;
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	{
61 61
 	    if ($this->trapTableHostList == Null) 
62 62
 		{
63
-	        $this->trapTableHostList = new TrapTableHostList();
63
+	        $this->trapTableHostList=new TrapTableHostList();
64 64
 	        $this->trapTableHostList->setConfig($this->getModuleConfig());
65 65
 	    }
66 66
 	    return $this->trapTableHostList;
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 	{
71 71
 		if ($this->handlerTableList == Null) 
72 72
 		{
73
-			$this->handlerTableList = new HandlerTableList();
73
+			$this->handlerTableList=new HandlerTableList();
74 74
 			$this->handlerTableList->setConfig($this->getModuleConfig());
75 75
 		}
76 76
 		return $this->handlerTableList;
@@ -82,15 +82,15 @@  discard block
 block discarded – undo
82 82
 	*	@param $test_version bool if set to flase, does not test database version of trapDB
83 83
 	*	@return array<integer,mixed>|mixed : if test=false, returns DB connexion, else array(error_num,message) or null on error.
84 84
 	*/
85
-	public function getDbByName($DBname,$test=false,$test_version=true)
85
+	public function getDbByName($DBname, $test=false, $test_version=true)
86 86
 	{
87 87
 		try 
88 88
 		{
89
-			$dbconn = IcingaDbConnection::fromResourceName($DBname);
89
+			$dbconn=IcingaDbConnection::fromResourceName($DBname);
90 90
 		} 
91 91
 		catch (Exception $e)
92 92
 		{
93
-			if ($test) return array(2,$DBname);
93
+			if ($test) return array(2, $DBname);
94 94
 			$this->redirectNow('trapdirector/settings?dberror=2');
95 95
 			return null;
96 96
 		}
@@ -101,53 +101,53 @@  discard block
 block discarded – undo
101 101
 			}
102 102
 			catch (Exception $e) 
103 103
 			{
104
-				if ($test) return array(3,$DBname,$e->getMessage());
104
+				if ($test) return array(3, $DBname, $e->getMessage());
105 105
 				$this->redirectNow('trapdirector/settings?dberror=3');
106 106
 				return null;
107 107
 			}
108 108
 			try
109 109
 			{
110
-				$query = $db->select()
111
-					->from($this->getModuleConfig()->getDbConfigTableName(),'value')
110
+				$query=$db->select()
111
+					->from($this->getModuleConfig()->getDbConfigTableName(), 'value')
112 112
 					->where('name=\'db_version\'');
113 113
 				$version=$db->fetchRow($query);
114
-				if ( ($version == null) || ! property_exists($version,'value') )
114
+				if (($version == null) || !property_exists($version, 'value'))
115 115
 				{
116
-					if ($test) return array(4,$DBname);
116
+					if ($test) return array(4, $DBname);
117 117
 					$this->redirectNow('trapdirector/settings?dberror=4');
118 118
 					return null;
119 119
 				}
120 120
 				if ($version->value < $this->getModuleConfig()->getDbMinVersion()) 
121 121
 				{
122
-					if ($test) return array(5,$version->value,$this->getModuleConfig()->getDbMinVersion());
122
+					if ($test) return array(5, $version->value, $this->getModuleConfig()->getDbMinVersion());
123 123
 					$this->redirectNow('trapdirector/settings?dberror=5');
124 124
 					return null;
125 125
 				}
126 126
 			}
127 127
 			catch (Exception $e) 
128 128
 			{
129
-				if ($test) return array(3,$DBname,$e->getMessage());
129
+				if ($test) return array(3, $DBname, $e->getMessage());
130 130
 				$this->redirectNow('trapdirector/settings?dberror=4');
131 131
 				return null;
132 132
 			}
133 133
 		}
134
-		if ($test) return array(0,'');
134
+		if ($test) return array(0, '');
135 135
 		return $dbconn;
136 136
 	}
137 137
 
138 138
 	public function getDb($test=false)
139 139
 	{
140
-		if ($this->trapDB != null && $test = false) return $this->trapDB;
140
+		if ($this->trapDB != null && $test=false) return $this->trapDB;
141 141
 		
142 142
 		$dbresource=$this->Config()->get('config', 'database');
143 143
 		
144
-		if ( ! $dbresource )
144
+		if (!$dbresource)
145 145
 		{	
146
-			if ($test) return array(1,'');
146
+			if ($test) return array(1, '');
147 147
 			$this->redirectNow('trapdirector/settings?dberror=1');
148 148
 			return null;
149 149
 		}
150
-		$retDB=$this->getDbByName($dbresource,$test,true);
150
+		$retDB=$this->getDbByName($dbresource, $test, true);
151 151
 		if ($test == true) return $retDB;
152 152
 		$this->trapDB=$retDB;
153 153
 		return $this->trapDB;
@@ -155,78 +155,78 @@  discard block
 block discarded – undo
155 155
 	
156 156
 	public function getIdoDb($test=false)
157 157
 	{
158
-		if ($this->icingaDB != null && $test = false) return $this->icingaDB;
158
+		if ($this->icingaDB != null && $test=false) return $this->icingaDB;
159 159
 		// TODO : get ido database directly from icingaweb2 config -> (or not if using only API)
160
-		$dbresource=$this->Config()->get('config', 'IDOdatabase');;
160
+		$dbresource=$this->Config()->get('config', 'IDOdatabase'); ;
161 161
 
162
-		if ( ! $dbresource )
162
+		if (!$dbresource)
163 163
 		{
164
-		    if ($test) return array(1,'No database in config.ini');
164
+		    if ($test) return array(1, 'No database in config.ini');
165 165
 		    $this->redirectNow('trapdirector/settings?idodberror=1');
166 166
 		    return null;
167 167
 		}
168 168
 		
169 169
 		try
170 170
 		{
171
-		    $dbconn = IcingaDbConnection::fromResourceName($dbresource);
171
+		    $dbconn=IcingaDbConnection::fromResourceName($dbresource);
172 172
 		}
173 173
 		catch (Exception $e)
174 174
 		{
175
-		    if ($test) return array(2,"Database $dbresource does not exists in IcingaWeb2");
175
+		    if ($test) return array(2, "Database $dbresource does not exists in IcingaWeb2");
176 176
 		    $this->redirectNow('trapdirector/settings?idodberror=2');
177 177
 		    return null;
178 178
 		}
179 179
 		
180 180
 		if ($test == false) 
181 181
 		{ 
182
-			$this->icingaDB = $dbconn; 
182
+			$this->icingaDB=$dbconn; 
183 183
 			return $this->icingaDB;
184 184
 		}
185 185
 		
186 186
 		try
187 187
 		{
188
-		    $query = $dbconn->select()
189
-		    ->from('icinga_dbversion',array('version'));
188
+		    $query=$dbconn->select()
189
+		    ->from('icinga_dbversion', array('version'));
190 190
 		    $version=$dbconn->fetchRow($query);
191
-		    if ( ($version == null) || ! property_exists($version,'version') )
191
+		    if (($version == null) || !property_exists($version, 'version'))
192 192
 		    {
193
-		        return array(4,"$dbresource does not look like an IDO database");
193
+		        return array(4, "$dbresource does not look like an IDO database");
194 194
 		    }
195 195
 		}
196 196
 		catch (Exception $e)
197 197
 		{
198
-			return array(3,"Error connecting to $dbresource : " . $e->getMessage());
198
+			return array(3, "Error connecting to $dbresource : ".$e->getMessage());
199 199
 		}
200 200
 		
201
-		return array(0,'');
201
+		return array(0, '');
202 202
 	}
203 203
 	
204
-    protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
204
+    protected function applyPaginationLimits(Paginatable $paginatable, $limit=25, $offset=null)
205 205
     {
206
-        $limit = $this->params->get('limit', $limit);
207
-        $page = $this->params->get('page', $offset);
206
+        $limit=$this->params->get('limit', $limit);
207
+        $page=$this->params->get('page', $offset);
208 208
 
209 209
         $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
210 210
 
211 211
         return $paginatable;
212 212
     }	
213 213
 	
214
-	public function displayExitError($source,$message)
214
+	public function displayExitError($source, $message)
215 215
 	{	// TODO : check better ways to transmit data (with POST ?)
216 216
 		$this->redirectNow('trapdirector/error?source='.$source.'&message='.$message);
217 217
 	}
218 218
 	
219 219
 	protected function checkReadPermission()
220 220
 	{
221
-        if (! $this->Auth()->hasPermission('trapdirector/view')) {
222
-            $this->displayExitError('Permissions','No permission fo view content');
221
+        if (!$this->Auth()->hasPermission('trapdirector/view')) {
222
+            $this->displayExitError('Permissions', 'No permission fo view content');
223 223
         }		
224 224
 	}
225 225
 
226 226
 	protected function checkConfigPermission()
227 227
 	{
228
-        if (! $this->Auth()->hasPermission('trapdirector/config')) {
229
-            $this->displayExitError('Permissions','No permission fo configure');
228
+        if (!$this->Auth()->hasPermission('trapdirector/config')) {
229
+            $this->displayExitError('Permissions', 'No permission fo configure');
230 230
         }		
231 231
 	}
232 232
 	
@@ -237,10 +237,10 @@  discard block
 block discarded – undo
237 237
      */
238 238
 	protected function checkModuleConfigPermission($check=0)
239 239
 	{
240
-        if (! $this->Auth()->hasPermission('trapdirector/module_config')) {
240
+        if (!$this->Auth()->hasPermission('trapdirector/module_config')) {
241 241
             if ($check == 0)
242 242
             {
243
-                $this->displayExitError('Permissions','No permission fo configure module');
243
+                $this->displayExitError('Permissions', 'No permission fo configure module');
244 244
             }
245 245
             return false;
246 246
         }
@@ -252,10 +252,10 @@  discard block
 block discarded – undo
252 252
 	{ // TODO : try/catch here ? or within caller
253 253
 		if ($this->trapClass == null)
254 254
 		{
255
-			require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
255
+			require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
256 256
 			$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
257 257
 			//$debug_level=4;
258
-			$this->trapClass = new Trap($icingaweb2_etc);
258
+			$this->trapClass=new Trap($icingaweb2_etc);
259 259
 			//$Trap->setLogging($debug_level,'syslog');
260 260
 		}
261 261
 		return $this->trapClass;
@@ -289,12 +289,12 @@  discard block
 block discarded – undo
289 289
 	protected function getHostByIP($ip) 
290 290
 	{
291 291
 		// select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
292
-		$db = $this->getIdoDb()->getConnection();
292
+		$db=$this->getIdoDb()->getConnection();
293 293
 		// TODO : check for SQL injections
294 294
 		$query=$db->select()
295 295
 				->from(
296 296
 					array('a' => 'icinga_objects'),
297
-					array('name' => 'a.name1','id' => 'object_id'))
297
+					array('name' => 'a.name1', 'id' => 'object_id'))
298 298
 				->join(
299 299
 					array('b' => 'icinga_hosts'),
300 300
 					'b.host_object_id=a.object_id',
@@ -310,12 +310,12 @@  discard block
 block discarded – undo
310 310
 	protected function getHostByName($name) 
311 311
 	{
312 312
 		// select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
313
-		$db = $this->getIdoDb()->getConnection();
313
+		$db=$this->getIdoDb()->getConnection();
314 314
 		// TODO : check for SQL injections
315 315
 		$query=$db->select()
316 316
 				->from(
317 317
 					array('a' => 'icinga_objects'),
318
-					array('name' => 'a.name1','id' => 'object_id'))
318
+					array('name' => 'a.name1', 'id' => 'object_id'))
319 319
 				->join(
320 320
 					array('b' => 'icinga_hosts'),
321 321
 					'b.host_object_id=a.object_id',
@@ -331,12 +331,12 @@  discard block
 block discarded – undo
331 331
 	protected function getHostGroupByName($ip) 
332 332
 	{
333 333
 		// select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
334
-		$db = $this->getIdoDb()->getConnection();
334
+		$db=$this->getIdoDb()->getConnection();
335 335
 		// TODO : check for SQL injections
336 336
 		$query=$db->select()
337 337
 				->from(
338 338
 					array('a' => 'icinga_objects'),
339
-					array('name' => 'a.name1','id' => 'object_id'))
339
+					array('name' => 'a.name1', 'id' => 'object_id'))
340 340
 				->join(
341 341
 					array('b' => 'icinga_hostgroups'),
342 342
 					'b.hostgroup_object_id=a.object_id',
@@ -352,8 +352,8 @@  discard block
 block discarded – undo
352 352
 	*/
353 353
 	protected function getHostInfoByID($id) 
354 354
 	{
355
-		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
356
-		$db = $this->getIdoDb()->getConnection();
355
+		if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
356
+		$db=$this->getIdoDb()->getConnection();
357 357
 		$query=$db->select()
358 358
 				->from(
359 359
 					array('a' => 'icinga_objects'),
@@ -373,17 +373,17 @@  discard block
 block discarded – undo
373 373
 	*/
374 374
 	protected function getHostByObjectID($id) // TODO : duplicate of getHostInfoByID above
375 375
 	{
376
-		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
377
-		$db = $this->getIdoDb()->getConnection();
376
+		if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
377
+		$db=$this->getIdoDb()->getConnection();
378 378
 		$query=$db->select()
379 379
 				->from(
380 380
 					array('a' => 'icinga_objects'),
381
-					array('name' => 'a.name1','id' => 'a.object_id'))
381
+					array('name' => 'a.name1', 'id' => 'a.object_id'))
382 382
 				->join(
383 383
 					array('b' => 'icinga_hosts'),
384 384
 					'b.host_object_id=a.object_id',
385
-					array('display_name' => 'b.display_name' , 'ip' => 'b.address', 'ip6' => 'b.address6'))
386
-				->where('a.object_id = ?',$id);
385
+					array('display_name' => 'b.display_name', 'ip' => 'b.address', 'ip6' => 'b.address6'))
386
+				->where('a.object_id = ?', $id);
387 387
 		return $db->fetchRow($query);
388 388
 	}	
389 389
 	
@@ -395,16 +395,16 @@  discard block
 block discarded – undo
395 395
 	protected function getServicesByHostid($id) 
396 396
 	{
397 397
 		// select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
398
-		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
399
-		$db = $this->getIdoDb()->getConnection();
398
+		if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
399
+		$db=$this->getIdoDb()->getConnection();
400 400
 		$query=$db->select()
401 401
 				->from(
402 402
 					array('s' => 'icinga_services'),
403
-					array('name' => 's.display_name','id' => 's.service_object_id'))
403
+					array('name' => 's.display_name', 'id' => 's.service_object_id'))
404 404
 				->join(
405 405
 					array('a' => 'icinga_objects'),
406 406
 					's.service_object_id=a.object_id',
407
-					array('is_active'=>'a.is_active','name2'=>'a.name2'))
407
+					array('is_active'=>'a.is_active', 'name2'=>'a.name2'))
408 408
 				->where('s.host_object_id='.$id.' AND a.is_active = 1');
409 409
 
410 410
 		return $db->fetchAll($query);
@@ -418,8 +418,8 @@  discard block
 block discarded – undo
418 418
 	*/
419 419
 	protected function getServicesByHostGroupid($id) 
420 420
 	{		
421
-		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
422
-		$db = $this->getIdoDb()->getConnection();
421
+		if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
422
+		$db=$this->getIdoDb()->getConnection();
423 423
 		$query=$db->select()
424 424
 				->from(
425 425
 					array('s' => 'icinga_hostgroup_members'),
@@ -436,11 +436,11 @@  discard block
 block discarded – undo
436 436
 		foreach ($hosts as $key => $host)
437 437
 		{ // For each host, get all services and add in common_services if not found or add counter
438 438
 			$host_services=$this->getServicesByHostid($host->host_object_id);
439
-			foreach($host_services as $service)
439
+			foreach ($host_services as $service)
440 440
 			{
441 441
 				if (isset($common_services[$service->name2]['num']))
442 442
 				{
443
-					$common_services[$service->name2]['num'] +=1;
443
+					$common_services[$service->name2]['num']+=1;
444 444
 				}
445 445
 				else
446 446
 				{
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
 		{
457 457
 		    if ($common_services[$key]['num'] == $num_hosts)
458 458
 			{
459
-				array_push($result,array($key,$common_services[$key]['name']));
459
+				array_push($result, array($key, $common_services[$key]['name']));
460 460
 			}
461 461
 		}
462 462
 		
@@ -469,9 +469,9 @@  discard block
 block discarded – undo
469 469
 	*	@param $name string service name
470 470
 	*	@return array  service id
471 471
 	*/
472
-	protected function getServiceIDByName($hostname,$name) 
472
+	protected function getServiceIDByName($hostname, $name) 
473 473
 	{
474
-		$db = $this->getIdoDb()->getConnection();
474
+		$db=$this->getIdoDb()->getConnection();
475 475
 		if ($name == null)
476 476
 		{
477 477
 			return array();
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
 		$query=$db->select()
481 481
 				->from(
482 482
 					array('s' => 'icinga_services'),
483
-					array('name' => 's.display_name','id' => 's.service_object_id'))
483
+					array('name' => 's.display_name', 'id' => 's.service_object_id'))
484 484
 				->join(
485 485
 					array('a' => 'icinga_objects'),
486 486
 					's.service_object_id=a.object_id',
@@ -498,12 +498,12 @@  discard block
 block discarded – undo
498 498
 	protected function getObjectNameByid($id) 
499 499
 	{
500 500
 		// select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
501
-		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
502
-		$db = $this->getIdoDb()->getConnection();
501
+		if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
502
+		$db=$this->getIdoDb()->getConnection();
503 503
 		$query=$db->select()
504 504
 				->from(
505 505
 					array('a' => 'icinga_objects'),
506
-					array('name1' => 'a.name1','name2' => 'a.name2'))
506
+					array('name1' => 'a.name1', 'name2' => 'a.name2'))
507 507
 				->where('a.object_id='.$id.' AND a.is_active = 1');
508 508
 
509 509
 		return $db->fetchRow($query);
@@ -516,17 +516,17 @@  discard block
 block discarded – undo
516 516
 	protected function addHandlerRule($params)
517 517
 	{
518 518
 		// TODO Check for rule consistency
519
-		$db = $this->getDb()->getConnection();
519
+		$db=$this->getDb()->getConnection();
520 520
 		// Add last modified date = creation date and username
521
-		$params['created'] = new Zend_Db_Expr('NOW()');
522
-		$params['modified'] = new 	Zend_Db_Expr('NOW()');
523
-		$params['modifier'] = $this->Auth()->getUser()->getUsername();
521
+		$params['created']=new Zend_Db_Expr('NOW()');
522
+		$params['modified']=new 	Zend_Db_Expr('NOW()');
523
+		$params['modifier']=$this->Auth()->getUser()->getUsername();
524 524
 		
525 525
 		$query=$db->insert(
526 526
 			$this->getModuleConfig()->getTrapRuleName(),
527 527
 			$params
528 528
 		);
529
-		if($query==false)
529
+		if ($query == false)
530 530
 		{
531 531
 		  return null;
532 532
 		}
@@ -537,13 +537,13 @@  discard block
 block discarded – undo
537 537
 	*	@param array(<db item>=><value>)
538 538
 	*	@return array affected rows
539 539
 	*/
540
-	protected function updateHandlerRule($params,$ruleID)
540
+	protected function updateHandlerRule($params, $ruleID)
541 541
 	{
542 542
 		// TODO Check for rule consistency
543
-		$db = $this->getDb()->getConnection();
543
+		$db=$this->getDb()->getConnection();
544 544
 		// Add last modified date = creation date and username
545
-		$params['modified'] = new 	Zend_Db_Expr('NOW()');
546
-		$params['modifier'] = $this->Auth()->getUser()->getUsername();
545
+		$params['modified']=new 	Zend_Db_Expr('NOW()');
546
+		$params['modifier']=$this->Auth()->getUser()->getUsername();
547 547
 		
548 548
 		$numRows=$db->update(
549 549
 			$this->getModuleConfig()->getTrapRuleName(),
@@ -558,8 +558,8 @@  discard block
 block discarded – undo
558 558
 	*/
559 559
 	protected function deleteRule($ruleID)
560 560
 	{
561
-		if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id');  }
562
-		$db = $this->getDb()->getConnection();
561
+		if (!preg_match('/^[0-9]+$/', $ruleID)) { throw new Exception('Invalid id'); }
562
+		$db=$this->getDb()->getConnection();
563 563
 		
564 564
 		$query=$db->delete(
565 565
 			$this->getModuleConfig()->getTrapRuleName(),
@@ -572,10 +572,10 @@  discard block
 block discarded – undo
572 572
 	*	@param $ip string source IP (v4 or v6)
573 573
 	*	@param $oid string oid
574 574
 	*/
575
-	protected function deleteTrap($ip,$oid)
575
+	protected function deleteTrap($ip, $oid)
576 576
 	{
577 577
 		
578
-		$db = $this->getDb()->getConnection();
578
+		$db=$this->getDb()->getConnection();
579 579
 		$condition=null;
580 580
 		if ($ip != null)
581 581
 		{
@@ -583,10 +583,10 @@  discard block
 block discarded – undo
583 583
 		}
584 584
 		if ($oid != null)
585 585
 		{
586
-			$condition=($condition===null)?'':$condition.' AND ';
586
+			$condition=($condition === null) ? '' : $condition.' AND ';
587 587
 			$condition.="trap_oid='$oid'";
588 588
 		}
589
-		if($condition === null) return null;
589
+		if ($condition === null) return null;
590 590
 		$query=$db->delete(
591 591
 			$this->getModuleConfig()->getTrapTableName(),
592 592
 			$condition
@@ -600,10 +600,10 @@  discard block
 block discarded – undo
600 600
 	*	@param $ip string source IP (v4 or v6)
601 601
 	*	@param $oid string oid
602 602
 	*/
603
-	protected function countTrap($ip,$oid)
603
+	protected function countTrap($ip, $oid)
604 604
 	{
605 605
 		
606
-		$db = $this->getDb()->getConnection();
606
+		$db=$this->getDb()->getConnection();
607 607
 		$condition=null;
608 608
 		if ($ip != null)
609 609
 		{
@@ -611,10 +611,10 @@  discard block
 block discarded – undo
611 611
 		}
612 612
 		if ($oid != null)
613 613
 		{
614
-			$condition=($condition==null)?'':$condition.' AND ';
614
+			$condition=($condition == null) ? '' : $condition.' AND ';
615 615
 			$condition.="trap_oid='$oid'";
616 616
 		}
617
-		if($condition ==null) return 0;
617
+		if ($condition == null) return 0;
618 618
 		$query=$db->select()
619 619
 			->from(
620 620
 				$this->getModuleConfig()->getTrapTableName(),
@@ -630,27 +630,27 @@  discard block
 block discarded – undo
630 630
 	protected function getDBConfigValue($element)
631 631
 	{
632 632
 	
633
-		$db = $this->getDb()->getConnection();
633
+		$db=$this->getDb()->getConnection();
634 634
 		
635 635
 		$query=$db->select()
636 636
 			->from(
637 637
 				$this->getModuleConfig()->getDbConfigTableName(),
638 638
 				array('value'=>'value'))
639
-			->where('name=?',$element);
639
+			->where('name=?', $element);
640 640
 		$return_row=$db->fetchRow($query);
641
-		if ($return_row==null)  // value does not exists
641
+		if ($return_row == null)  // value does not exists
642 642
 		{
643 643
 			$default=$this->getModuleConfig()->getDBConfigDefaults();
644
-			if ( ! isset($default[$element])) return null; // no default and not value
644
+			if (!isset($default[$element])) return null; // no default and not value
645 645
 			
646
-			$this->addDBConfigValue($element,$default[$element]);
646
+			$this->addDBConfigValue($element, $default[$element]);
647 647
 			return $default[$element];
648 648
 		}
649 649
 		if ($return_row->value == null) // value id empty
650 650
 		{
651 651
 			$default=$this->getModuleConfig()->getDBConfigDefaults();
652
-			if ( ! isset($default[$element])) return null; // no default and not value
653
-			$this->setDBConfigValue($element,$default[$element]);
652
+			if (!isset($default[$element])) return null; // no default and not value
653
+			$this->setDBConfigValue($element, $default[$element]);
654 654
 			return $default[$element];			
655 655
 		}
656 656
 		return $return_row->value;		
@@ -659,10 +659,10 @@  discard block
 block discarded – undo
659 659
 	/** add configuration value
660 660
 	*	@param name value
661 661
 	*/
662
-	protected function addDBConfigValue($element,$value)
662
+	protected function addDBConfigValue($element, $value)
663 663
 	{
664 664
 	
665
-		$db = $this->getDb()->getConnection();
665
+		$db=$this->getDb()->getConnection();
666 666
 		
667 667
 		$query=$db->insert(
668 668
 				$this->getModuleConfig()->getDbConfigTableName(),
@@ -677,10 +677,10 @@  discard block
 block discarded – undo
677 677
 	/** set configuration value
678 678
 	*	@param name value
679 679
 	*/
680
-	protected function setDBConfigValue($element,$value)
680
+	protected function setDBConfigValue($element, $value)
681 681
 	{
682 682
 	
683
-		$db = $this->getDb()->getConnection();
683
+		$db=$this->getDb()->getConnection();
684 684
 		$query=$db->update(
685 685
 				$this->getModuleConfig()->getDbConfigTableName(),
686 686
 				array('value'=>$value),
@@ -695,10 +695,10 @@  discard block
 block discarded – undo
695 695
 	protected function isDirectorInstalled()
696 696
 	{
697 697
 	    $output=array();
698
-	    exec('icingacli module list',$output);
698
+	    exec('icingacli module list', $output);
699 699
 	    foreach ($output as $line)
700 700
 		{
701
-			if (preg_match('/^director .*enabled/',$line))
701
+			if (preg_match('/^director .*enabled/', $line))
702 702
 			{
703 703
 				return true;
704 704
 			}
Please login to merge, or discard this patch.
library/Trapdirector/Config/MIBLoader.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -54,9 +54,9 @@  discard block
 block discarded – undo
54 54
 	
55 55
 	
56 56
 	/** Get trap list from a mib 
57
-	*	@param $mib string mib name
58
-	*	@return array(traps)
59
-	*/
57
+	 *	@param $mib string mib name
58
+	 *	@return array(traps)
59
+	 */
60 60
 	public function getTrapList($mib)
61 61
 	{
62 62
 		$traps=array();
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 		$query=$dbconn->select()
65 65
 				->from(
66 66
 					$this->config->getMIBCacheTableName(),
67
-				    array('name' => 'name', 'oid' => 'oid', 'description' => 'description'))
67
+					array('name' => 'name', 'oid' => 'oid', 'description' => 'description'))
68 68
 				->where("mib = '".$mib."' AND type='21'") ;
69 69
 		$names=$dbconn->fetchAll($query);
70 70
 		foreach ($names as $val)
@@ -75,9 +75,9 @@  discard block
 block discarded – undo
75 75
 	}
76 76
 	
77 77
 	/** Get objects a trap can have
78
-	*	@param int oid of trap
79
-	*	@return : null if trap not found, or array ( <oid> => name/mib/type )
80
-	*/
78
+	 *	@param int oid of trap
79
+	 *	@return : null if trap not found, or array ( <oid> => name/mib/type )
80
+	 */
81 81
 	public function getObjectList($trap)
82 82
 	{
83 83
 		$objects=array();
@@ -93,15 +93,15 @@  discard block
 block discarded – undo
93 93
 		if ( ($id == null) || ! property_exists($id,'id') ) return null;
94 94
 		
95 95
 		$query=$dbconn->select()
96
-		        ->from(
97
-		            array('c' => $this->config->getMIBCacheTableName()),
98
-		            array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum',
99
-		                'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint',
100
-		                'description' => 'c.description'))
101
-		        ->join(
102
-		            array('o' => $this->config->getMIBCacheTableTrapObjName()),
103
-		            'o.trap_id='.$id->id )
104
-		        ->where("o.object_id = c.id");
96
+				->from(
97
+					array('c' => $this->config->getMIBCacheTableName()),
98
+					array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum',
99
+						'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint',
100
+						'description' => 'c.description'))
101
+				->join(
102
+					array('o' => $this->config->getMIBCacheTableTrapObjName()),
103
+					'o.trap_id='.$id->id )
104
+				->where("o.object_id = c.id");
105 105
 		$listObjects=$dbconn->fetchAll($query);
106 106
 		if ( count($listObjects)==0 ) return null;
107 107
 		
@@ -119,12 +119,12 @@  discard block
 block discarded – undo
119 119
 	}
120 120
 
121 121
 	/** translate oid in MIB::Name 
122
-	*	@param string oid
123
-	*	@return array|null :  return array with index (oid -> oid, mib -> mib name, name -> oid name, type -> oid type)
124
-	*/
122
+	 *	@param string oid
123
+	 *	@return array|null :  return array with index (oid -> oid, mib -> mib name, name -> oid name, type -> oid type)
124
+	 */
125 125
 	public function translateOID($oid)
126 126
 	{
127
-	    if (!preg_match('/^\./',$oid)) $oid = '.' . $oid; // Add a leading '.'
127
+		if (!preg_match('/^\./',$oid)) $oid = '.' . $oid; // Add a leading '.'
128 128
 		$retArray=array('oid' => $oid, 'mib' => null, 'name'=>null,'type'=>null);
129 129
 		$dbconn = $this->db->getConnection();
130 130
 
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 				->from(
133 133
 					array('o' => $this->config->getMIBCacheTableName()),
134 134
 					array('mib'=>'o.mib','name' => 'o.name','type'=>'o.syntax',
135
-					    'type_enum'=>'o.type_enum', 'description'=>'o.description'))
135
+						'type_enum'=>'o.type_enum', 'description'=>'o.description'))
136 136
 				->where('o.oid=\''.$oid.'\'');
137 137
 		$object=$dbconn->fetchRow($query);
138 138
 		if ($object != null) 
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 		// Try to get oid name from snmptranslate
149 149
 		$matches=array();
150 150
 		$translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
151
-		    ' '.$oid);
151
+			' '.$oid);
152 152
 		$ret_code=preg_match('/(.*)::(.*)/',$translate,$matches);
153 153
 		if ($ret_code==0 || $ret_code==FALSE) {
154 154
 			return null;
@@ -160,8 +160,8 @@  discard block
 block discarded – undo
160 160
 			" | grep SYNTAX | sed 's/SYNTAX[[:blank:]]*//'");
161 161
 		if (preg_match('/(.*)\{(.*)\}/',$translate,$matches))
162 162
 		{
163
-		    $retArray['type']=$matches[1];
164
-		    $retArray['type_enum']=$matches[2];
163
+			$retArray['type']=$matches[1];
164
+			$retArray['type_enum']=$matches[2];
165 165
 		}
166 166
 		else
167 167
 		{
@@ -225,25 +225,25 @@  discard block
 block discarded – undo
225 225
 	 */
226 226
 	public function getTrapDetails($oid=null,$id=null)
227 227
 	{	    
228
-	    // Get trap id in DB
229
-	    if ($oid==null)
230
-	    {
231
-	        $where="c.id = '$id'";
232
-	    }
233
-	    else
234
-	    {
235
-	        $where="c.oid = '$oid'";
236
-	    }
237
-	    $query=$this->db->getConnection()->select()
238
-           ->from(
239
-            array('c' => $this->config->getMIBCacheTableName()),
240
-            array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum',
241
-                'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint',
242
-                'description' => 'c.description'))
243
-            ->where($where);
244
-        $trap=$this->db->getConnection()->fetchRow($query);
228
+		// Get trap id in DB
229
+		if ($oid==null)
230
+		{
231
+			$where="c.id = '$id'";
232
+		}
233
+		else
234
+		{
235
+			$where="c.oid = '$oid'";
236
+		}
237
+		$query=$this->db->getConnection()->select()
238
+		   ->from(
239
+			array('c' => $this->config->getMIBCacheTableName()),
240
+			array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum',
241
+				'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint',
242
+				'description' => 'c.description'))
243
+			->where($where);
244
+		$trap=$this->db->getConnection()->fetchRow($query);
245 245
         
246
-        return $trap;
246
+		return $trap;
247 247
 	}
248 248
 	
249 249
 }
Please login to merge, or discard this patch.
application/controllers/HandlerController.php 3 patches
Indentation   +88 added lines, -89 removed lines patch added patch discarded remove patch
@@ -11,13 +11,12 @@  discard block
 block discarded – undo
11 11
 
12 12
 //use Icinga\Web\Form as Form;
13 13
 /** Rules management
14
-
15
-*/
14
+ */
16 15
 class HandlerController extends TrapsController
17 16
 {
18 17
 
19 18
 	/** index : list existing rules 
20
-	*/
19
+	 */
21 20
 	public function indexAction()
22 21
 	{	
23 22
 		$this->checkReadPermission();
@@ -39,29 +38,29 @@  discard block
 block discarded – undo
39 38
 	 */
40 39
 	public function testruleAction()
41 40
 	{
42
-	    $this->checkReadPermission();
43
-	    $this->getTabs()->add('get',array(
44
-	        'active'	=> true,
45
-	        'label'		=> $this->translate('Test Rule'),
46
-	        'url'		=> Url::fromRequest()
47
-	    ));
41
+		$this->checkReadPermission();
42
+		$this->getTabs()->add('get',array(
43
+			'active'	=> true,
44
+			'label'		=> $this->translate('Test Rule'),
45
+			'url'		=> Url::fromRequest()
46
+		));
48 47
 	    
49
-	    //$db = $this->getDb();
48
+		//$db = $this->getDb();
50 49
 
51
-	    if ($this->params->get('rule') !== null) 
52
-	    {
53
-	        $this->view->rule= $this->params->get('rule');
54
-	    }
55
-	    else
56
-	    {
57
-	        $this->view->rule='';
58
-	    }
50
+		if ($this->params->get('rule') !== null) 
51
+		{
52
+			$this->view->rule= $this->params->get('rule');
53
+		}
54
+		else
55
+		{
56
+			$this->view->rule='';
57
+		}
59 58
 	}
60 59
 	
61 60
 	/** Add a handler  
62
-	*	Get params fromid : setup from existing trap (id of trap table)
63
-	*	Get param ruleid : edit from existing handler (id of rule table)
64
-	*/
61
+	 *	Get params fromid : setup from existing trap (id of trap table)
62
+	 *	Get param ruleid : edit from existing handler (id of rule table)
63
+	 */
65 64
 	public function addAction()
66 65
 	{
67 66
 		$this->checkConfigPermission();
@@ -162,7 +161,7 @@  discard block
 block discarded – undo
162 161
 					$currentObjectTypeEnum=$allObjects[$val->oid]['type_enum'];
163 162
 				}
164 163
 				$currentObject=array(
165
-				    $oid_index,
164
+					$oid_index,
166 165
 					$val->oid,
167 166
 					$val->oid_name_mib,
168 167
 					$val->oid_name,
@@ -184,7 +183,7 @@  discard block
 block discarded – undo
184 183
 				{
185 184
 					if ($val==null) { continue; }
186 185
 					array_push($this->view->objectList, array(
187
-					    $oid_index,
186
+						$oid_index,
188 187
 						$key,
189 188
 						$allObjects[$key]['mib'],
190 189
 						$allObjects[$key]['name'],
@@ -223,61 +222,61 @@  discard block
 block discarded – undo
223 222
 			$this->view->warning_message='';
224 223
 			if ($this->view->hostname != null)
225 224
 			{
226
-			    $this->view->selectGroup=false;
227
-			    // Check if hostname still exists
228
-			    $host_get=$this->getHostByName($this->view->hostname);
225
+				$this->view->selectGroup=false;
226
+				// Check if hostname still exists
227
+				$host_get=$this->getHostByName($this->view->hostname);
229 228
 			    
230
-			    if (count($host_get)==0)
231
-			    {
232
-			        $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
233
-			        $this->view->serviceGet=false;
234
-			    }
235
-			    else
236
-			    {
237
-    				// Tell JS to get services when page is loaded
238
-    				$this->view->serviceGet=true;
239
-    				// get service id for form to set :			
240
-    				$serviceID=$this->getServiceIDByName($this->view->hostname,$ruleDetail->service_name);
241
-    				if (count($serviceID) ==0)
242
-    				{
243
-    				    $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
244
-    				} 
245
-    				else
246
-    				{
247
-    				    $this->view->serviceSet=$serviceID[0]->id;
248
-    				}
249
-			    }
229
+				if (count($host_get)==0)
230
+				{
231
+					$this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
232
+					$this->view->serviceGet=false;
233
+				}
234
+				else
235
+				{
236
+					// Tell JS to get services when page is loaded
237
+					$this->view->serviceGet=true;
238
+					// get service id for form to set :			
239
+					$serviceID=$this->getServiceIDByName($this->view->hostname,$ruleDetail->service_name);
240
+					if (count($serviceID) ==0)
241
+					{
242
+						$this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
243
+					} 
244
+					else
245
+					{
246
+						$this->view->serviceSet=$serviceID[0]->id;
247
+					}
248
+				}
250 249
 			}
251 250
 			else
252 251
 			{
253
-			    $this->view->selectGroup=true;
254
-			    // Check if groupe exists
255
-			    $group_get=$this->getHostGroupByName($this->view->hostgroupname);
256
-			    if (count($group_get)==0)
257
-			    {
258
-			        $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
259
-			        $this->view->serviceGroupGet=false;
260
-			    }
261
-			    else
262
-			    {
263
-			        $grpServices=$this->getServicesByHostGroupid($group_get[0]->id);
264
-			        $foundGrpService=0;
265
-			        foreach ($grpServices as $grpService)
266
-			        {
267
-			            if ($grpService[0] == $ruleDetail->service_name)
268
-			            {
269
-			                $foundGrpService=1;
270
-			                $this->view->serviceSet=$ruleDetail->service_name;
271
-			            }
272
-			        }
252
+				$this->view->selectGroup=true;
253
+				// Check if groupe exists
254
+				$group_get=$this->getHostGroupByName($this->view->hostgroupname);
255
+				if (count($group_get)==0)
256
+				{
257
+					$this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
258
+					$this->view->serviceGroupGet=false;
259
+				}
260
+				else
261
+				{
262
+					$grpServices=$this->getServicesByHostGroupid($group_get[0]->id);
263
+					$foundGrpService=0;
264
+					foreach ($grpServices as $grpService)
265
+					{
266
+						if ($grpService[0] == $ruleDetail->service_name)
267
+						{
268
+							$foundGrpService=1;
269
+							$this->view->serviceSet=$ruleDetail->service_name;
270
+						}
271
+					}
273 272
 			        
274
-			        // Tell JS to get services when page is loaded
275
-			        $this->view->serviceGroupGet=true;
276
-			        if ($foundGrpService==0)
277
-			        {
278
-			            $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
279
-			        }
280
-			    }				
273
+					// Tell JS to get services when page is loaded
274
+					$this->view->serviceGroupGet=true;
275
+					if ($foundGrpService==0)
276
+					{
277
+						$this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
278
+					}
279
+				}				
281 280
 			}
282 281
 			$this->view->mainoid=$ruleDetail->trap_oid;
283 282
 			$oidName=$this->getMIB()->translateOID($ruleDetail->trap_oid);
@@ -302,7 +301,7 @@  discard block
 block discarded – undo
302 301
 				if (($object=$this->getMIB()->translateOID($curOid)) != null)
303 302
 				{
304 303
 					array_push($curObjectList, array(
305
-					    $index,
304
+						$index,
306 305
 						$curOid,
307 306
 						$object['mib'],
308 307
 						$object['name'],
@@ -314,7 +313,7 @@  discard block
 block discarded – undo
314 313
 				else
315 314
 				{
316 315
 					array_push($curObjectList, array(
317
-					    $index,
316
+						$index,
318 317
 						$curOid,
319 318
 						'not found',
320 319
 						'not found',
@@ -335,9 +334,9 @@  discard block
 block discarded – undo
335 334
 	}
336 335
 	
337 336
 	/** Validate form and output message to user  
338
-	*	@param in postdata 
339
-	* 	@return string status : OK / <Message>
340
-	**/
337
+	 *	@param in postdata 
338
+	 * 	@return string status : OK / <Message>
339
+	 **/
341 340
 	protected function handlerformAction()
342 341
 	{
343 342
 		$postData=$this->getRequest()->getPost();
@@ -378,7 +377,7 @@  discard block
 block discarded – undo
378 377
 			//$this->Module()->
379 378
 			$this->_helper->json(array(
380 379
 				'status'=>'OK',
381
-			    'redirect'=>'trapdirector/handler'
380
+				'redirect'=>'trapdirector/handler'
382 381
 			      
383 382
 			));
384 383
 		}		
@@ -462,9 +461,9 @@  discard block
 block discarded – undo
462 461
 	}
463 462
 
464 463
 	/** Get trap detail by trapid. 
465
-	*	@param integer $trapid : id of trap in received table
466
-	*	@return array (objects)
467
-	*/
464
+	 *	@param integer $trapid : id of trap in received table
465
+	 *	@return array (objects)
466
+	 */
468 467
 	protected function getTrapDetail($trapid) 
469 468
 	{
470 469
 		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
@@ -496,9 +495,9 @@  discard block
 block discarded – undo
496 495
 	}
497 496
 
498 497
 	/** Get trap objects
499
-	*	@param integer $trapid : trap id
500
-	* 	@return array : full column in db of trap id
501
-	*/
498
+	 *	@param integer $trapid : trap id
499
+	 * 	@return array : full column in db of trap id
500
+	 */
502 501
 	protected function getTrapobjects($trapid)
503 502
 	{	
504 503
 		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
@@ -529,9 +528,9 @@  discard block
 block discarded – undo
529 528
 	}
530 529
 
531 530
 	/** Get rule detail by ruleid.
532
-	*	@param integer $ruleid int id of rule in rule table
533
-	*	@return array : column objects in db
534
-	*/
531
+	 *	@param integer $ruleid int id of rule in rule table
532
+	 *	@return array : column objects in db
533
+	 */
535 534
 	protected function getRuleDetail($ruleid) 
536 535
 	{
537 536
 		if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id');  }
@@ -558,7 +557,7 @@  discard block
 block discarded – undo
558 557
 	}
559 558
 
560 559
 	/** Setup tabs for rules 
561
-	*/
560
+	 */
562 561
 	protected function prepareTabs()
563 562
 	{
564 563
 		return $this->getTabs()->add('status', array(
Please login to merge, or discard this patch.
Spacing   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -23,14 +23,14 @@  discard block
 block discarded – undo
23 23
 		$this->checkReadPermission();
24 24
 		$this->prepareTabs()->activate('status');
25 25
 
26
-		$db = $this->getDb();
26
+		$db=$this->getDb();
27 27
 		$this->getHandlerListTable()->setConnection($db);
28 28
 		$this->getHandlerListTable()->setMibloader($this->getMIB());
29 29
 		// Apply pagination limits 
30
-		$this->view->table=$this->applyPaginationLimits($this->getHandlerListTable(),$this->getModuleConfig()->itemListDisplay());		
30
+		$this->view->table=$this->applyPaginationLimits($this->getHandlerListTable(), $this->getModuleConfig()->itemListDisplay());		
31 31
 		
32 32
 		// Set Filter
33
-		$this->view->filterEditor = $this->getHandlerListTable()->getFilterEditor($this->getRequest());		
33
+		$this->view->filterEditor=$this->getHandlerListTable()->getFilterEditor($this->getRequest());		
34 34
 	
35 35
 		//$this->displayExitError('Handler/indexAction','Not implemented');
36 36
 	}
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	public function testruleAction()
41 41
 	{
42 42
 	    $this->checkReadPermission();
43
-	    $this->getTabs()->add('get',array(
43
+	    $this->getTabs()->add('get', array(
44 44
 	        'active'	=> true,
45 45
 	        'label'		=> $this->translate('Test Rule'),
46 46
 	        'url'		=> Url::fromRequest()
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 
51 51
 	    if ($this->params->get('rule') !== null) 
52 52
 	    {
53
-	        $this->view->rule= $this->params->get('rule');
53
+	        $this->view->rule=$this->params->get('rule');
54 54
 	    }
55 55
 	    else
56 56
 	    {
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	{
67 67
 		$this->checkConfigPermission();
68 68
 		// set up tab
69
-		$this->getTabs()->add('get',array(
69
+		$this->getTabs()->add('get', array(
70 70
 			'active'	=> true,
71 71
 			'label'		=> $this->translate('Add handler'),
72 72
 			'url'		=> Url::fromRequest()
@@ -116,12 +116,12 @@  discard block
 block discarded – undo
116 116
 			}
117 117
 			catch (Exception $e)
118 118
 			{
119
-				$this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage());
119
+				$this->displayExitError('Add handler : get host by IP/Name ', $e->getMessage());
120 120
 			}
121 121
 			
122 122
 			
123 123
 			// if one unique host found -> put id text input
124
-			if (count($hosts)==1) {
124
+			if (count($hosts) == 1) {
125 125
 				$this->view->hostname=$hosts[0]->name;
126 126
 				//$hostid=$hosts[0]->id;
127 127
 				// Tell JS to get services when page is loaded
@@ -130,9 +130,9 @@  discard block
 block discarded – undo
130 130
 			}
131 131
 			else
132 132
 			{
133
-				foreach($hosts as $key=>$val)
133
+				foreach ($hosts as $key=>$val)
134 134
 				{
135
-					array_push($this->view->hostlist,$hosts[$key]->name);
135
+					array_push($this->view->hostlist, $hosts[$key]->name);
136 136
 				}
137 137
 			}
138 138
 			
@@ -171,18 +171,18 @@  discard block
 block discarded – undo
171 171
 					$currentObjectTypeEnum
172 172
 				);
173 173
 				$oid_index++;
174
-				array_push($this->view->objectList,$currentObject);
174
+				array_push($this->view->objectList, $currentObject);
175 175
 				// set currrent object to null in allObjects
176 176
 				if (isset($allObjects[$val->oid]))
177 177
 				{
178 178
 					$allObjects[$val->oid]=null;
179 179
 				}
180 180
 			}
181
-			if ($allObjects!=null) // in case trap doesn't have objects or is not resolved
181
+			if ($allObjects != null) // in case trap doesn't have objects or is not resolved
182 182
 			{
183 183
 				foreach ($allObjects as $key => $val)
184 184
 				{
185
-					if ($val==null) { continue; }
185
+					if ($val == null) { continue; }
186 186
 					array_push($this->view->objectList, array(
187 187
 					    $oid_index,
188 188
 						$key,
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 			$this->view->setRuleMatch=$ruleDetail->action_match;
217 217
 			$this->view->setRuleNoMatch=$ruleDetail->action_nomatch;
218 218
 			$this->view->hostgroupname=$ruleDetail->host_group_name;
219
-			$this->view->modified=gmdate("Y-m-d\TH:i:s\Z",$ruleDetail->modified);
219
+			$this->view->modified=gmdate("Y-m-d\TH:i:s\Z", $ruleDetail->modified);
220 220
 			$this->view->modifier=$ruleDetail->modifier;
221 221
 			
222 222
 			// Warning message if host/service don't exists anymore
@@ -227,9 +227,9 @@  discard block
 block discarded – undo
227 227
 			    // Check if hostname still exists
228 228
 			    $host_get=$this->getHostByName($this->view->hostname);
229 229
 			    
230
-			    if (count($host_get)==0)
230
+			    if (count($host_get) == 0)
231 231
 			    {
232
-			        $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
232
+			        $this->view->warning_message='Host '.$this->view->hostname.' doesn\'t exists anymore';
233 233
 			        $this->view->serviceGet=false;
234 234
 			    }
235 235
 			    else
@@ -237,10 +237,10 @@  discard block
 block discarded – undo
237 237
     				// Tell JS to get services when page is loaded
238 238
     				$this->view->serviceGet=true;
239 239
     				// get service id for form to set :			
240
-    				$serviceID=$this->getServiceIDByName($this->view->hostname,$ruleDetail->service_name);
241
-    				if (count($serviceID) ==0)
240
+    				$serviceID=$this->getServiceIDByName($this->view->hostname, $ruleDetail->service_name);
241
+    				if (count($serviceID) == 0)
242 242
     				{
243
-    				    $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
243
+    				    $this->view->warning_message=' Service '.$ruleDetail->service_name.' doesn\'t exists anymore';
244 244
     				} 
245 245
     				else
246 246
     				{
@@ -253,9 +253,9 @@  discard block
 block discarded – undo
253 253
 			    $this->view->selectGroup=true;
254 254
 			    // Check if groupe exists
255 255
 			    $group_get=$this->getHostGroupByName($this->view->hostgroupname);
256
-			    if (count($group_get)==0)
256
+			    if (count($group_get) == 0)
257 257
 			    {
258
-			        $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
258
+			        $this->view->warning_message='HostGroup '.$this->view->hostgroupname.' doesn\'t exists anymore';
259 259
 			        $this->view->serviceGroupGet=false;
260 260
 			    }
261 261
 			    else
@@ -273,9 +273,9 @@  discard block
 block discarded – undo
273 273
 			        
274 274
 			        // Tell JS to get services when page is loaded
275 275
 			        $this->view->serviceGroupGet=true;
276
-			        if ($foundGrpService==0)
276
+			        if ($foundGrpService == 0)
277 277
 			        {
278
-			            $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
278
+			            $this->view->warning_message.=' Service '.$ruleDetail->service_name.' doesn\'t exists anymore';
279 279
 			        }
280 280
 			    }				
281 281
 			}
@@ -295,8 +295,8 @@  discard block
 block discarded – undo
295 295
 			$index=1; 
296 296
 			// check in display & rule for : OID(<oid>)
297 297
 			$matches=array();
298
-			while ( preg_match('/_OID\(([\.0-9]+)\)/',$display,$matches) ||
299
-					preg_match('/_OID\(([\.0-9]+)\)/',$rule,$matches))
298
+			while (preg_match('/_OID\(([\.0-9]+)\)/', $display, $matches) ||
299
+					preg_match('/_OID\(([\.0-9]+)\)/', $rule, $matches))
300 300
 			{
301 301
 				$curOid=$matches[1];
302 302
 				if (($object=$this->getMIB()->translateOID($curOid)) != null)
@@ -322,8 +322,8 @@  discard block
 block discarded – undo
322 322
 						'not found'
323 323
 					));
324 324
 				}
325
-				$display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display);
326
-				$rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule);
325
+				$display=preg_replace('/_OID\('.$curOid.'\)/', '\$'.$index.'\$', $display);
326
+				$rule=preg_replace('/_OID\('.$curOid.'\)/', '\$'.$index.'\$', $rule);
327 327
 				$index++;
328 328
 			}
329 329
 			// set display
@@ -345,26 +345,26 @@  discard block
 block discarded – undo
345 345
 	
346 346
 		$params=array(
347 347
 			// id (also db) => 	array('post' => post id, 'val' => default val, 'db' => send to table)
348
-			'hostgroup'		=>	array('post' => 'hostgroup','db'=>false),
349
-			'db_rule'		=>	array('post' => 'db_rule','db'=>false),
350
-			'hostid'		=>	array('post' => 'hostid','db'=>false),
351
-			'host_name'		=>	array('post' => 'hostname','val' => null,'db'=>true),
352
-			'host_group_name'=>	array('post' => null,'val' => null,'db'=>true),
353
-			'serviceid'		=>	array('post' => 'serviceid','db'=>false),
354
-			'service_name'	=>	array('post' => 'serviceName','db'=>true),
355
-			'trap_oid'		=>	array('post' => 'oid','db'=>true),
356
-			'revert_ok'		=>	array('post' => 'revertOK','val' => 0,'db'=>true),
357
-			'display'		=>	array('post' => 'display','val' => '','db'=>true),
358
-			'rule'			=>	array('post' => 'rule','val' => '','db'=>true),			
359
-			'action_match'	=>	array('post' => 'ruleMatch','val' => -1,'db'=>true),
360
-			'action_nomatch'=>	array('post' => 'ruleNoMatch','val' => -1,'db'=>true),					
361
-			'ip4'			=>	array('post' => null,'val' => null,'db'=>true),
362
-			'ip6'			=>	array('post' => null,'val' => null,'db'=>true),
363
-			'action_form'	=>	array('post' => 'action_form','db'=>false)
348
+			'hostgroup'		=>	array('post' => 'hostgroup', 'db'=>false),
349
+			'db_rule'		=>	array('post' => 'db_rule', 'db'=>false),
350
+			'hostid'		=>	array('post' => 'hostid', 'db'=>false),
351
+			'host_name'		=>	array('post' => 'hostname', 'val' => null, 'db'=>true),
352
+			'host_group_name'=>	array('post' => null, 'val' => null, 'db'=>true),
353
+			'serviceid'		=>	array('post' => 'serviceid', 'db'=>false),
354
+			'service_name'	=>	array('post' => 'serviceName', 'db'=>true),
355
+			'trap_oid'		=>	array('post' => 'oid', 'db'=>true),
356
+			'revert_ok'		=>	array('post' => 'revertOK', 'val' => 0, 'db'=>true),
357
+			'display'		=>	array('post' => 'display', 'val' => '', 'db'=>true),
358
+			'rule'			=>	array('post' => 'rule', 'val' => '', 'db'=>true),			
359
+			'action_match'	=>	array('post' => 'ruleMatch', 'val' => -1, 'db'=>true),
360
+			'action_nomatch'=>	array('post' => 'ruleNoMatch', 'val' => -1, 'db'=>true),					
361
+			'ip4'			=>	array('post' => null, 'val' => null, 'db'=>true),
362
+			'ip6'			=>	array('post' => null, 'val' => null, 'db'=>true),
363
+			'action_form'	=>	array('post' => 'action_form', 'db'=>false)
364 364
 		);
365 365
 		
366 366
 		if (isset($postData[$params['action_form']['post']]) 
367
-			&& $postData[$params['action_form']['post']] == 'delete' )
367
+			&& $postData[$params['action_form']['post']] == 'delete')
368 368
 		{
369 369
 			try
370 370
 			{
@@ -384,16 +384,16 @@  discard block
 block discarded – undo
384 384
 		}		
385 385
 		foreach (array_keys($params) as $key)
386 386
 		{
387
-			if ($params[$key]['post']==null) continue; // data not sent in post vars
388
-			if (! isset($postData[$params[$key]['post']]))
387
+			if ($params[$key]['post'] == null) continue; // data not sent in post vars
388
+			if (!isset($postData[$params[$key]['post']]))
389 389
 			{
390 390
 				// should not happen as the js checks data
391
-				$this->_helper->json(array('status'=>'No ' . $key));
391
+				$this->_helper->json(array('status'=>'No '.$key));
392 392
 			}
393 393
 			else
394 394
 			{
395 395
 				$data=$postData[$params[$key]['post']];
396
-				if ($data!=null && $data !="")
396
+				if ($data != null && $data != "")
397 397
 				{
398 398
 					$params[$key]['val']=$postData[$params[$key]['post']];
399 399
 				}
@@ -402,8 +402,8 @@  discard block
 block discarded – undo
402 402
 
403 403
 		try 
404 404
 		{
405
-			$isHostGroup=($params['hostgroup']['val'] == 1)?true:false;
406
-			if (! $isHostGroup ) 
405
+			$isHostGroup=($params['hostgroup']['val'] == 1) ?true:false;
406
+			if (!$isHostGroup) 
407 407
 			{  // checks if selection by host 
408 408
 				$hostAddr=$this->getHostInfoByID($params['hostid']['val']);
409 409
 				$params['ip4']['val']=$hostAddr->ip4;
@@ -430,25 +430,25 @@  discard block
 block discarded – undo
430 430
 					return;					
431 431
 				}
432 432
 				// Put param in correct column (group_name)
433
-				$params['host_group_name']['val'] = $params['host_name']['val'];
433
+				$params['host_group_name']['val']=$params['host_name']['val'];
434 434
 				$params['host_name']['val']=null;
435 435
 			}
436 436
 			$dbparams=array();
437 437
 			foreach ($params as $key=>$val)
438 438
 			{
439
-				if ($val['db']==true )
439
+				if ($val['db'] == true)
440 440
 				{
441
-					$dbparams[$key] = $val['val'];
441
+					$dbparams[$key]=$val['val'];
442 442
 				}
443 443
 			}
444 444
 			// echo '<br>';	print_r($dbparams);echo '<br>';
445
-			if ($params['db_rule']['val'] == -1 ) 
445
+			if ($params['db_rule']['val'] == -1) 
446 446
 			{
447 447
 				$ruleID=$this->addHandlerRule($dbparams);
448 448
 			}
449 449
 			else
450 450
 			{
451
-				$this->updateHandlerRule($dbparams,$params['db_rule']['val']);
451
+				$this->updateHandlerRule($dbparams, $params['db_rule']['val']);
452 452
 				$ruleID=$params['db_rule']['val'];
453 453
 			}
454 454
 		}
@@ -467,10 +467,10 @@  discard block
 block discarded – undo
467 467
 	*/
468 468
 	protected function getTrapDetail($trapid) 
469 469
 	{
470
-		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
470
+		if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); }
471 471
 		$queryArray=$this->getModuleConfig()->trapDetailQuery();
472 472
 		
473
-		$db = $this->getDb()->getConnection();
473
+		$db=$this->getDb()->getConnection();
474 474
 		// ***************  Get main data
475 475
 		// extract columns and titles;
476 476
 		$elmts=NULL;
@@ -479,15 +479,15 @@  discard block
 block discarded – undo
479 479
 		}
480 480
 		try
481 481
 		{		
482
-			$query = $db->select()
483
-				->from($this->getModuleConfig()->getTrapTableName(),$elmts)
484
-				->where('id=?',$trapid);
482
+			$query=$db->select()
483
+				->from($this->getModuleConfig()->getTrapTableName(), $elmts)
484
+				->where('id=?', $trapid);
485 485
 			$trapDetail=$db->fetchRow($query);
486
-			if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid);
486
+			if ($trapDetail == null) throw new Exception('No traps was found with id = '.$trapid);
487 487
 		}
488 488
 		catch (Exception $e)
489 489
 		{
490
-			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage());
490
+			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail, true), $e->getMessage());
491 491
 			return;
492 492
 		}
493 493
 
@@ -501,10 +501,10 @@  discard block
 block discarded – undo
501 501
 	*/
502 502
 	protected function getTrapobjects($trapid)
503 503
 	{	
504
-		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
504
+		if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); }
505 505
 		$queryArrayData=$this->getModuleConfig()->trapDataDetailQuery();
506 506
 		
507
-		$db = $this->getDb()->getConnection();
507
+		$db=$this->getDb()->getConnection();
508 508
 		// ***************  Get object data
509 509
 		// extract columns and titles;
510 510
 		$data_elmts=NULL;
@@ -513,15 +513,15 @@  discard block
 block discarded – undo
513 513
 		}
514 514
 		try
515 515
 		{		
516
-			$query = $db->select()
517
-				->from($this->moduleConfig->getTrapDataTableName(),$data_elmts)
518
-				->where('trap_id=?',$trapid);
516
+			$query=$db->select()
517
+				->from($this->moduleConfig->getTrapDataTableName(), $data_elmts)
518
+				->where('trap_id=?', $trapid);
519 519
 			$trapDetail=$db->fetchAll($query);
520 520
 			// if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid);
521 521
 		}
522 522
 		catch (Exception $e)
523 523
 		{
524
-			$this->displayExitError('Add handler : get trap data detail : ',$e->getMessage());
524
+			$this->displayExitError('Add handler : get trap data detail : ', $e->getMessage());
525 525
 			return array();
526 526
 		}
527 527
 
@@ -534,22 +534,22 @@  discard block
 block discarded – undo
534 534
 	*/
535 535
 	protected function getRuleDetail($ruleid) 
536 536
 	{
537
-		if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id');  }
537
+		if (!preg_match('/^[0-9]+$/', $ruleid)) { throw new Exception('Invalid id'); }
538 538
 		$queryArray=$this->getModuleConfig()->ruleDetailQuery();
539 539
 		
540
-		$db = $this->getDb()->getConnection();
540
+		$db=$this->getDb()->getConnection();
541 541
 		// ***************  Get main data
542 542
 		try
543 543
 		{		
544
-			$query = $db->select()
545
-				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
546
-				->where('id=?',$ruleid);
544
+			$query=$db->select()
545
+				->from($this->getModuleConfig()->getTrapRuleName(), $queryArray)
546
+				->where('id=?', $ruleid);
547 547
 			$ruleDetail=$db->fetchRow($query);
548
-			if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid);
548
+			if ($ruleDetail == null) throw new Exception('No rule was found with id = '.$ruleid);
549 549
 		}
550 550
 		catch (Exception $e)
551 551
 		{
552
-			$this->displayExitError('Update handler : get rule detail',$e->getMessage());
552
+			$this->displayExitError('Update handler : get rule detail', $e->getMessage());
553 553
 			return array();
554 554
 		}
555 555
 
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
 	{
564 564
 		return $this->getTabs()->add('status', array(
565 565
 			'label' => $this->translate('Traps'),
566
-			'url'   => $this->getModuleConfig()->urlPath() . '/handler')
566
+			'url'   => $this->getModuleConfig()->urlPath().'/handler')
567 567
 		);
568 568
 	} 
569 569
 	
Please login to merge, or discard this patch.
Braces   +35 added lines, -39 removed lines patch added patch discarded remove patch
@@ -51,8 +51,7 @@  discard block
 block discarded – undo
51 51
 	    if ($this->params->get('rule') !== null) 
52 52
 	    {
53 53
 	        $this->view->rule= $this->params->get('rule');
54
-	    }
55
-	    else
54
+	    } else
56 55
 	    {
57 56
 	        $this->view->rule='';
58 57
 	    }
@@ -113,8 +112,7 @@  discard block
 block discarded – undo
113 112
 			try
114 113
 			{
115 114
 				$hosts=$this->getHostByIP($hostfilter);
116
-			}
117
-			catch (Exception $e)
115
+			} catch (Exception $e)
118 116
 			{
119 117
 				$this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage());
120 118
 			}
@@ -127,8 +125,7 @@  discard block
 block discarded – undo
127 125
 				// Tell JS to get services when page is loaded
128 126
 				$this->view->serviceGet=true;
129 127
 				
130
-			}
131
-			else
128
+			} else
132 129
 			{
133 130
 				foreach($hosts as $key=>$val)
134 131
 				{
@@ -178,11 +175,14 @@  discard block
 block discarded – undo
178 175
 					$allObjects[$val->oid]=null;
179 176
 				}
180 177
 			}
181
-			if ($allObjects!=null) // in case trap doesn't have objects or is not resolved
178
+			if ($allObjects!=null) {
179
+				// in case trap doesn't have objects or is not resolved
182 180
 			{
183 181
 				foreach ($allObjects as $key => $val)
184 182
 				{
185
-					if ($val==null) { continue; }
183
+					if ($val==null) { continue;
184
+			}
185
+			}
186 186
 					array_push($this->view->objectList, array(
187 187
 					    $oid_index,
188 188
 						$key,
@@ -231,8 +231,7 @@  discard block
 block discarded – undo
231 231
 			    {
232 232
 			        $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
233 233
 			        $this->view->serviceGet=false;
234
-			    }
235
-			    else
234
+			    } else
236 235
 			    {
237 236
     				// Tell JS to get services when page is loaded
238 237
     				$this->view->serviceGet=true;
@@ -241,14 +240,12 @@  discard block
 block discarded – undo
241 240
     				if (count($serviceID) ==0)
242 241
     				{
243 242
     				    $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
244
-    				} 
245
-    				else
243
+    				} else
246 244
     				{
247 245
     				    $this->view->serviceSet=$serviceID[0]->id;
248 246
     				}
249 247
 			    }
250
-			}
251
-			else
248
+			} else
252 249
 			{
253 250
 			    $this->view->selectGroup=true;
254 251
 			    // Check if groupe exists
@@ -257,8 +254,7 @@  discard block
 block discarded – undo
257 254
 			    {
258 255
 			        $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
259 256
 			        $this->view->serviceGroupGet=false;
260
-			    }
261
-			    else
257
+			    } else
262 258
 			    {
263 259
 			        $grpServices=$this->getServicesByHostGroupid($group_get[0]->id);
264 260
 			        $foundGrpService=0;
@@ -281,9 +277,11 @@  discard block
 block discarded – undo
281 277
 			}
282 278
 			$this->view->mainoid=$ruleDetail->trap_oid;
283 279
 			$oidName=$this->getMIB()->translateOID($ruleDetail->trap_oid);
284
-			if ($oidName != null)  // oid is found in mibs
280
+			if ($oidName != null) {
281
+				// oid is found in mibs
285 282
 			{
286
-				$this->view->mib=$oidName['mib']; 
283
+				$this->view->mib=$oidName['mib'];
284
+			}
287 285
 				$this->view->name=$oidName['name'];
288 286
 				$this->view->trapListForMIB=$this->getMIB()
289 287
 					->getTrapList($oidName['mib']);				
@@ -310,8 +308,7 @@  discard block
 block discarded – undo
310 308
 						$object['type'],
311 309
 						$object['type_enum']
312 310
 					));
313
-				}
314
-				else
311
+				} else
315 312
 				{
316 313
 					array_push($curObjectList, array(
317 314
 					    $index,
@@ -369,8 +366,7 @@  discard block
 block discarded – undo
369 366
 			try
370 367
 			{
371 368
 				$this->deleteRule($postData[$params['db_rule']['post']]);
372
-			}
373
-			catch (Exception $e)
369
+			} catch (Exception $e)
374 370
 			{
375 371
 				$this->_helper->json(array('status'=>$e->getMessage()));
376 372
 				return;
@@ -384,13 +380,15 @@  discard block
 block discarded – undo
384 380
 		}		
385 381
 		foreach (array_keys($params) as $key)
386 382
 		{
387
-			if ($params[$key]['post']==null) continue; // data not sent in post vars
383
+			if ($params[$key]['post']==null) {
384
+				continue;
385
+			}
386
+			// data not sent in post vars
388 387
 			if (! isset($postData[$params[$key]['post']]))
389 388
 			{
390 389
 				// should not happen as the js checks data
391 390
 				$this->_helper->json(array('status'=>'No ' . $key));
392
-			}
393
-			else
391
+			} else
394 392
 			{
395 393
 				$data=$postData[$params[$key]['post']];
396 394
 				if ($data!=null && $data !="")
@@ -420,8 +418,7 @@  discard block
 block discarded – undo
420 418
 					$this->_helper->json(array('status'=>"Invalid service id : Please re enter service"));
421 419
 					return;
422 420
 				}
423
-			}
424
-			else
421
+			} else
425 422
 			{
426 423
 				$object=$this->getObjectNameByid($params['hostid']['val']);
427 424
 				if ($params['host_name']['val'] != $object->name1)
@@ -445,14 +442,12 @@  discard block
 block discarded – undo
445 442
 			if ($params['db_rule']['val'] == -1 ) 
446 443
 			{
447 444
 				$ruleID=$this->addHandlerRule($dbparams);
448
-			}
449
-			else
445
+			} else
450 446
 			{
451 447
 				$this->updateHandlerRule($dbparams,$params['db_rule']['val']);
452 448
 				$ruleID=$params['db_rule']['val'];
453 449
 			}
454
-		}
455
-		catch (Exception $e)
450
+		} catch (Exception $e)
456 451
 		{
457 452
 			$this->_helper->json(array('status'=>$e->getMessage()));
458 453
 			return;
@@ -483,9 +478,10 @@  discard block
 block discarded – undo
483 478
 				->from($this->getModuleConfig()->getTrapTableName(),$elmts)
484 479
 				->where('id=?',$trapid);
485 480
 			$trapDetail=$db->fetchRow($query);
486
-			if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid);
487
-		}
488
-		catch (Exception $e)
481
+			if ( $trapDetail == null ) {
482
+				throw new Exception('No traps was found with id = '.$trapid);
483
+			}
484
+		} catch (Exception $e)
489 485
 		{
490 486
 			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage());
491 487
 			return;
@@ -518,8 +514,7 @@  discard block
 block discarded – undo
518 514
 				->where('trap_id=?',$trapid);
519 515
 			$trapDetail=$db->fetchAll($query);
520 516
 			// if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid);
521
-		}
522
-		catch (Exception $e)
517
+		} catch (Exception $e)
523 518
 		{
524 519
 			$this->displayExitError('Add handler : get trap data detail : ',$e->getMessage());
525 520
 			return array();
@@ -545,9 +540,10 @@  discard block
 block discarded – undo
545 540
 				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
546 541
 				->where('id=?',$ruleid);
547 542
 			$ruleDetail=$db->fetchRow($query);
548
-			if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid);
549
-		}
550
-		catch (Exception $e)
543
+			if ( $ruleDetail == null ) {
544
+				throw new Exception('No rule was found with id = '.$ruleid);
545
+			}
546
+		} catch (Exception $e)
551 547
 		{
552 548
 			$this->displayExitError('Update handler : get rule detail',$e->getMessage());
553 549
 			return array();
Please login to merge, or discard this patch.
application/controllers/HelperController.php 3 patches
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -12,8 +12,8 @@  discard block
 block discarded – undo
12 12
 {
13 13
 	
14 14
 	/** Get host list with filter (IP or name) : host=<filter>
15
-	*	returns in JSON : status=>OK/NOK  hosts=>array of hosts
16
-	*/
15
+	 *	returns in JSON : status=>OK/NOK  hosts=>array of hosts
16
+	 */
17 17
 	public function gethostsAction()
18 18
 	{
19 19
 		$postData=$this->getRequest()->getPost();
@@ -40,8 +40,8 @@  discard block
 block discarded – undo
40 40
 
41 41
 	
42 42
 	/** Get hostgroup list with filter (name) : hostgroup=<hostFilter>
43
-	*	returns in JSON : status=>OK/NOK  hosts=>array of hosts
44
-	*/
43
+	 *	returns in JSON : status=>OK/NOK  hosts=>array of hosts
44
+	 */
45 45
 	public function gethostgroupsAction()
46 46
 	{
47 47
 		$postData=$this->getRequest()->getPost();
@@ -68,11 +68,11 @@  discard block
 block discarded – undo
68 68
 
69 69
 	
70 70
 	/** Get service list by host name ( host=<host> )
71
-	*	returns in JSON : 
72
-	*		status=>OK/No services found/More than one host matches
73
-	*		services=>array of services (name)
74
-	*		hostid = host object id or -1 if not found.
75
-	*/
71
+	 *	returns in JSON : 
72
+	 *		status=>OK/No services found/More than one host matches
73
+	 *		services=>array of services (name)
74
+	 *		hostid = host object id or -1 if not found.
75
+	 */
76 76
 	public function getservicesAction()
77 77
 	{
78 78
 		$postData=$this->getRequest()->getPost();
@@ -112,11 +112,11 @@  discard block
 block discarded – undo
112 112
 	}
113 113
 	
114 114
 	/** Get service list by host group ( name=<host> )
115
-	*	returns in JSON : 
116
-	*		status=>OK/No services found/More than one host matches
117
-	*		services=>array of services (name)
118
-	*		groupid = group object id or -1 if not found.
119
-	*/
115
+	 *	returns in JSON : 
116
+	 *		status=>OK/No services found/More than one host matches
117
+	 *		services=>array of services (name)
118
+	 *		groupid = group object id or -1 if not found.
119
+	 */
120 120
 	public function gethostgroupservicesAction()
121 121
 	{
122 122
 		$postData=$this->getRequest()->getPost();
@@ -153,10 +153,10 @@  discard block
 block discarded – undo
153 153
 	}
154 154
 
155 155
 	/** Get traps from mib  : entry : mib=<mib>
156
-	*	returns in JSON : 
157
-	*		status=>OK/No mib/Error getting mibs
158
-	*		traps=>array of array( oid -> name)
159
-	*/
156
+	 *	returns in JSON : 
157
+	 *		status=>OK/No mib/Error getting mibs
158
+	 *		traps=>array of array( oid -> name)
159
+	 */
160 160
 	public function gettrapsAction()
161 161
 	{
162 162
 		$postData=$this->getRequest()->getPost();
@@ -182,10 +182,10 @@  discard block
 block discarded – undo
182 182
 	}	
183 183
 
184 184
 	/** Get trap objects from mib  : entry : trap=<oid>
185
-	*	returns in JSON : 
186
-	*		status=>OK/no trap/not found
187
-	*		objects=>array of array( oid -> name, oid->mib)
188
-	*/
185
+	 *	returns in JSON : 
186
+	 *		status=>OK/no trap/not found
187
+	 *		objects=>array of array( oid -> name, oid->mib)
188
+	 */
189 189
 	public function gettrapobjectsAction()
190 190
 	{
191 191
 		$postData=$this->getRequest()->getPost();
@@ -211,8 +211,8 @@  discard block
 block discarded – undo
211 211
 	}	
212 212
 	
213 213
 	/** Get list of all loaded mibs : entry : none
214
-	*	return : array of strings.
215
-	*/
214
+	 *	return : array of strings.
215
+	 */
216 216
 	public function getmiblistAction()
217 217
 	{
218 218
 		try
@@ -227,10 +227,10 @@  discard block
 block discarded – undo
227 227
 	}
228 228
 	
229 229
 	/** Get MIB::Name from OID : entry : oid
230
-	*		status=>OK/No oid/not found
231
-	*		mib=>string
232
-	*		name=>string
233
-	*/	
230
+	 *		status=>OK/No oid/not found
231
+	 *		mib=>string
232
+	 *		name=>string
233
+	 */	
234 234
 	public function translateoidAction()
235 235
 	{
236 236
 		$postData=$this->getRequest()->getPost();
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 					'name' => $object['name'],
259 259
 					'type' => $object['type'],
260 260
 					'type_enum' => $object['type_enum'],
261
-				    'description' => $object['description']
261
+					'description' => $object['description']
262 262
 				)
263 263
 			);
264 264
 		}
@@ -267,10 +267,10 @@  discard block
 block discarded – undo
267 267
 
268 268
 	
269 269
 	/** Save or execute database purge of <n> days
270
-	*	days=>int 
271
-	*	action=>save/execute
272
-	*	return : status=>OK/Message error
273
-	*/
270
+	 *	days=>int 
271
+	 *	action=>save/execute
272
+	 *	return : status=>OK/Message error
273
+	 */
274 274
 	public function dbmaintenanceAction()
275 275
 	{
276 276
 		
@@ -339,11 +339,11 @@  discard block
 block discarded – undo
339 339
 	}	
340 340
 
341 341
 	/** Save log output to db
342
-	*	destination=>log destination 
343
-	*	file=>file name
344
-	*	level => int 
345
-	*	return : status=>OK/Message error
346
-	*/
342
+	 *	destination=>log destination 
343
+	 *	file=>file name
344
+	 *	level => int 
345
+	 *	return : status=>OK/Message error
346
+	 */
347 347
 	public function logdestinationAction()
348 348
 	{
349 349
 		$postData=$this->getRequest()->getPost();
@@ -367,8 +367,8 @@  discard block
 block discarded – undo
367 367
 			$fileHandler=@fopen($file,'w');
368 368
 			if ($fileHandler == false)
369 369
 			{   // File os note writabe / cannot create
370
-			    $this->_helper->json(array('status'=>'File not writable :  '.$file));
371
-			    return;
370
+				$this->_helper->json(array('status'=>'File not writable :  '.$file));
371
+				return;
372 372
 			}
373 373
 		}
374 374
 		else
@@ -418,50 +418,50 @@  discard block
 block discarded – undo
418 418
 	public function testruleAction()
419 419
 	{
420 420
 	    
421
-	    $postData=$this->getRequest()->getPost();
422
-	    if (isset($postData['rule']))
423
-	    {
424
-	        $rule=$postData['rule'];
425
-	    }
426
-	    else
427
-	    {
428
-	        $this->_helper->json(array('status'=>'No Rule'));
429
-	    }
430
-	    if (isset($postData['action']))
431
-	    {
432
-	        $action=$postData['action'];
433
-	        if ($action != 'evaluate')
434
-	        {
435
-	            $this->_helper->json(array('status'=>'unknown action '.$action));
436
-	            return;
437
-	        }
438
-	    }
439
-	    else
440
-	    {
441
-	        $this->_helper->json(array('status'=>'No action'));
442
-	        return;
443
-	    }
444
-	    if ($action == 'evaluate')
445
-	    {
446
-	        try
447
-	        {
448
-	            require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
449
-	            $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
450
-	            $Trap = new Trap($icingaweb2_etc);
451
-	            // Cleanup spaces before eval
452
-	            $rule=$Trap->eval_cleanup($rule);
453
-	            // Eval
454
-	            $item=0;
455
-	            $rule=$Trap->evaluation($rule,$item);
456
-	        }
457
-	        catch (Exception $e)
458
-	        {
459
-	            $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() ));
460
-	            return;
461
-	        }
462
-	        $return=($rule==true)?'true':'false';
463
-	        $this->_helper->json(array('status'=>'OK', 'message' => $return));
464
-	    }
421
+		$postData=$this->getRequest()->getPost();
422
+		if (isset($postData['rule']))
423
+		{
424
+			$rule=$postData['rule'];
425
+		}
426
+		else
427
+		{
428
+			$this->_helper->json(array('status'=>'No Rule'));
429
+		}
430
+		if (isset($postData['action']))
431
+		{
432
+			$action=$postData['action'];
433
+			if ($action != 'evaluate')
434
+			{
435
+				$this->_helper->json(array('status'=>'unknown action '.$action));
436
+				return;
437
+			}
438
+		}
439
+		else
440
+		{
441
+			$this->_helper->json(array('status'=>'No action'));
442
+			return;
443
+		}
444
+		if ($action == 'evaluate')
445
+		{
446
+			try
447
+			{
448
+				require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
449
+				$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
450
+				$Trap = new Trap($icingaweb2_etc);
451
+				// Cleanup spaces before eval
452
+				$rule=$Trap->eval_cleanup($rule);
453
+				// Eval
454
+				$item=0;
455
+				$rule=$Trap->evaluation($rule,$item);
456
+			}
457
+			catch (Exception $e)
458
+			{
459
+				$this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() ));
460
+				return;
461
+			}
462
+			$return=($rule==true)?'true':'false';
463
+			$this->_helper->json(array('status'=>'OK', 'message' => $return));
464
+		}
465 465
 	    
466 466
 	}	
467 467
 	
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -27,12 +27,12 @@  discard block
 block discarded – undo
27 27
 			return;
28 28
 		}
29 29
 
30
-		$retHosts=array('status'=>'OK','hosts' => array());
30
+		$retHosts=array('status'=>'OK', 'hosts' => array());
31 31
 
32 32
 		$hosts=$this->getHostByIP($hostFilter);
33 33
 		foreach ($hosts as $val)
34 34
 		{
35
-			array_push($retHosts['hosts'],$val->name);
35
+			array_push($retHosts['hosts'], $val->name);
36 36
 		}
37 37
 		
38 38
 		$this->_helper->json($retHosts);
@@ -55,12 +55,12 @@  discard block
 block discarded – undo
55 55
 			return;
56 56
 		}
57 57
 
58
-		$retHosts=array('status'=>'OK','hosts' => array());
58
+		$retHosts=array('status'=>'OK', 'hosts' => array());
59 59
 
60 60
 		$hosts=$this->getHostGroupByName($hostFilter);
61 61
 		foreach ($hosts as $val)
62 62
 		{
63
-			array_push($retHosts['hosts'],$val->name);
63
+			array_push($retHosts['hosts'], $val->name);
64 64
 		}
65 65
 		
66 66
 		$this->_helper->json($retHosts);
@@ -82,31 +82,31 @@  discard block
 block discarded – undo
82 82
 		}
83 83
 		else
84 84
 		{
85
-			$this->_helper->json(array('status'=>'No Hosts','hostid' => -1));
85
+			$this->_helper->json(array('status'=>'No Hosts', 'hostid' => -1));
86 86
 			return;
87 87
 		}
88 88
 		
89 89
 		$hostArray=$this->getHostByName($host);
90 90
 		if (count($hostArray) > 1)
91 91
 		{	
92
-			$this->_helper->json(array('status'=>'More than one host matches','hostid' => -1));
92
+			$this->_helper->json(array('status'=>'More than one host matches', 'hostid' => -1));
93 93
 			return;
94 94
 		}
95 95
 		else if (count($hostArray) == 0)
96 96
 		{
97
-			$this->_helper->json(array('status'=>'No host matches','hostid' => -1));
97
+			$this->_helper->json(array('status'=>'No host matches', 'hostid' => -1));
98 98
 			return;
99 99
 		}
100 100
 		$services=$this->getServicesByHostid($hostArray[0]->id);
101 101
 		if (count($services) < 1)
102 102
 		{
103
-			$this->_helper->json(array('status'=>'No services found for host','hostid' => $hostArray[0]->id));
103
+			$this->_helper->json(array('status'=>'No services found for host', 'hostid' => $hostArray[0]->id));
104 104
 			return;
105 105
 		}
106
-		$retServices=array('status'=>'OK','services' => array(),'hostid' => $hostArray[0]->id);
106
+		$retServices=array('status'=>'OK', 'services' => array(), 'hostid' => $hostArray[0]->id);
107 107
 		foreach ($services as $val)
108 108
 		{
109
-			array_push($retServices['services'],array($val->id , $val->name));
109
+			array_push($retServices['services'], array($val->id, $val->name));
110 110
 		}
111 111
 		$this->_helper->json($retServices);
112 112
 	}
@@ -126,28 +126,28 @@  discard block
 block discarded – undo
126 126
 		}
127 127
 		else
128 128
 		{
129
-			$this->_helper->json(array('status'=>'No Hosts','hostid' => -1));
129
+			$this->_helper->json(array('status'=>'No Hosts', 'hostid' => -1));
130 130
 			return;
131 131
 		}
132 132
 		
133 133
 		$hostArray=$this->getHostGroupByName($host);
134 134
 		if (count($hostArray) > 1)
135 135
 		{	
136
-			$this->_helper->json(array('status'=>'More than one hostgroup matches','hostid' => -1));
136
+			$this->_helper->json(array('status'=>'More than one hostgroup matches', 'hostid' => -1));
137 137
 			return;
138 138
 		}
139 139
 		else if (count($hostArray) == 0)
140 140
 		{
141
-			$this->_helper->json(array('status'=>'No hostgroup matches','hostid' => -1));
141
+			$this->_helper->json(array('status'=>'No hostgroup matches', 'hostid' => -1));
142 142
 			return;
143 143
 		}
144 144
 		$services=$this->getServicesByHostGroupid($hostArray[0]->id);
145 145
 		if (count($services) < 1)
146 146
 		{
147
-			$this->_helper->json(array('status'=>'No services found for hostgroup','hostid' => $hostArray[0]->id));
147
+			$this->_helper->json(array('status'=>'No services found for hostgroup', 'hostid' => $hostArray[0]->id));
148 148
 			return;
149 149
 		}
150
-		$retServices=array('status'=>'OK','services' => $services,'hostid' => $hostArray[0]->id);
150
+		$retServices=array('status'=>'OK', 'services' => $services, 'hostid' => $hostArray[0]->id);
151 151
 		
152 152
 		$this->_helper->json($retServices);
153 153
 	}
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 		try
173 173
 		{
174 174
 			$traplist=$this->getMIB()->getTrapList($mib);
175
-			$retTraps=array('status'=>'OK','traps' => $traplist);
175
+			$retTraps=array('status'=>'OK', 'traps' => $traplist);
176 176
 		} 
177 177
 		catch (Exception $e) 
178 178
 		{ 
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 		try
202 202
 		{
203 203
 			$objectlist=$this->getMIB()->getObjectList($trap);
204
-			$retObjects=array('status'=>'OK','objects' => $objectlist);
204
+			$retObjects=array('status'=>'OK', 'objects' => $objectlist);
205 205
 		} 
206 206
 		catch (Exception $e) 
207 207
 		{ 
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 		if (isset($postData['days']))
279 279
 		{
280 280
 			$days=$postData['days'];
281
-			if (!preg_match('/^[0-9]+$/',$days))
281
+			if (!preg_match('/^[0-9]+$/', $days))
282 282
 			{
283 283
 				$this->_helper->json(array('status'=>'invalid days : '.$days));
284 284
 				return;
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 		if (isset($postData['action']))
293 293
 		{
294 294
 			$action=$postData['action'];
295
-			if ($action != 'save' && $action !='execute')
295
+			if ($action != 'save' && $action != 'execute')
296 296
 			{
297 297
 				$this->_helper->json(array('status'=>'unknown action '.$action));
298 298
 				return;
@@ -307,11 +307,11 @@  discard block
 block discarded – undo
307 307
 		{
308 308
 			try
309 309
 			{
310
-				$this->setDBConfigValue('db_remove_days',$days);
310
+				$this->setDBConfigValue('db_remove_days', $days);
311 311
 			}
312 312
 			catch (Exception $e)
313 313
 			{
314
-				$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
314
+				$this->_helper->json(array('status'=>'Save error : '.$e->getMessage()));
315 315
 				return;
316 316
 			}
317 317
 			$this->_helper->json(array('status'=>'OK'));
@@ -321,16 +321,16 @@  discard block
 block discarded – undo
321 321
 		{
322 322
 			try
323 323
 			{
324
-				require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
324
+				require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
325 325
 				$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
326 326
 				$debug_level=4;
327
-				$Trap = new Trap($icingaweb2_etc);
328
-				$Trap->setLogging($debug_level,'syslog');
327
+				$Trap=new Trap($icingaweb2_etc);
328
+				$Trap->setLogging($debug_level, 'syslog');
329 329
 				$Trap->eraseOldTraps($days);
330 330
 			}
331 331
 			catch (Exception $e)
332 332
 			{
333
-				$this->_helper->json(array('status'=>'execute error : '.$e->getMessage() ));
333
+				$this->_helper->json(array('status'=>'execute error : '.$e->getMessage()));
334 334
 				return;
335 335
 			}			
336 336
 			$this->_helper->json(array('status'=>'OK'));
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
 		if (isset($postData['file']))
365 365
 		{ 
366 366
 			$file=$postData['file'];
367
-			$fileHandler=@fopen($file,'w');
367
+			$fileHandler=@fopen($file, 'w');
368 368
 			if ($fileHandler == false)
369 369
 			{   // File os note writabe / cannot create
370 370
 			    $this->_helper->json(array('status'=>'File not writable :  '.$file));
@@ -396,13 +396,13 @@  discard block
 block discarded – undo
396 396
 		
397 397
 		try
398 398
 		{
399
-			$this->setDBConfigValue('log_destination',$destination);
400
-			$this->setDBConfigValue('log_file',$file);
401
-			$this->setDBConfigValue('log_level',$level);
399
+			$this->setDBConfigValue('log_destination', $destination);
400
+			$this->setDBConfigValue('log_file', $file);
401
+			$this->setDBConfigValue('log_level', $level);
402 402
 		}
403 403
 		catch (Exception $e)
404 404
 		{
405
-			$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
405
+			$this->_helper->json(array('status'=>'Save error : '.$e->getMessage()));
406 406
 			return;
407 407
 		}
408 408
 		$this->_helper->json(array('status'=>'OK'));
@@ -445,21 +445,21 @@  discard block
 block discarded – undo
445 445
 	    {
446 446
 	        try
447 447
 	        {
448
-	            require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
448
+	            require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
449 449
 	            $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
450
-	            $Trap = new Trap($icingaweb2_etc);
450
+	            $Trap=new Trap($icingaweb2_etc);
451 451
 	            // Cleanup spaces before eval
452 452
 	            $rule=$Trap->eval_cleanup($rule);
453 453
 	            // Eval
454 454
 	            $item=0;
455
-	            $rule=$Trap->evaluation($rule,$item);
455
+	            $rule=$Trap->evaluation($rule, $item);
456 456
 	        }
457 457
 	        catch (Exception $e)
458 458
 	        {
459
-	            $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() ));
459
+	            $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage()));
460 460
 	            return;
461 461
 	        }
462
-	        $return=($rule==true)?'true':'false';
462
+	        $return=($rule == true) ? 'true' : 'false';
463 463
 	        $this->_helper->json(array('status'=>'OK', 'message' => $return));
464 464
 	    }
465 465
 	    
Please login to merge, or discard this patch.
Braces   +25 added lines, -50 removed lines patch added patch discarded remove patch
@@ -20,8 +20,7 @@  discard block
 block discarded – undo
20 20
 		if (isset($postData['hostFilter']))
21 21
 		{
22 22
 			$hostFilter=$postData['hostFilter'];
23
-		}
24
-		else
23
+		} else
25 24
 		{
26 25
 			$this->_helper->json(array('status'=>'KO'));
27 26
 			return;
@@ -48,8 +47,7 @@  discard block
 block discarded – undo
48 47
 		if (isset($postData['hostFilter']))
49 48
 		{
50 49
 			$hostFilter=$postData['hostFilter'];
51
-		}
52
-		else
50
+		} else
53 51
 		{
54 52
 			$this->_helper->json(array('status'=>'Error : no filter'));
55 53
 			return;
@@ -79,8 +77,7 @@  discard block
 block discarded – undo
79 77
 		if (isset($postData['host']))
80 78
 		{
81 79
 			$host=$postData['host'];
82
-		}
83
-		else
80
+		} else
84 81
 		{
85 82
 			$this->_helper->json(array('status'=>'No Hosts','hostid' => -1));
86 83
 			return;
@@ -91,8 +88,7 @@  discard block
 block discarded – undo
91 88
 		{	
92 89
 			$this->_helper->json(array('status'=>'More than one host matches','hostid' => -1));
93 90
 			return;
94
-		}
95
-		else if (count($hostArray) == 0)
91
+		} else if (count($hostArray) == 0)
96 92
 		{
97 93
 			$this->_helper->json(array('status'=>'No host matches','hostid' => -1));
98 94
 			return;
@@ -123,8 +119,7 @@  discard block
 block discarded – undo
123 119
 		if (isset($postData['host']))
124 120
 		{
125 121
 			$host=$postData['host'];
126
-		}
127
-		else
122
+		} else
128 123
 		{
129 124
 			$this->_helper->json(array('status'=>'No Hosts','hostid' => -1));
130 125
 			return;
@@ -135,8 +130,7 @@  discard block
 block discarded – undo
135 130
 		{	
136 131
 			$this->_helper->json(array('status'=>'More than one hostgroup matches','hostid' => -1));
137 132
 			return;
138
-		}
139
-		else if (count($hostArray) == 0)
133
+		} else if (count($hostArray) == 0)
140 134
 		{
141 135
 			$this->_helper->json(array('status'=>'No hostgroup matches','hostid' => -1));
142 136
 			return;
@@ -163,8 +157,7 @@  discard block
 block discarded – undo
163 157
 		if (isset($postData['mib']))
164 158
 		{
165 159
 			$mib=$postData['mib'];
166
-		}
167
-		else
160
+		} else
168 161
 		{
169 162
 			$this->_helper->json(array('status'=>'No mib'));
170 163
 			return;
@@ -173,8 +166,7 @@  discard block
 block discarded – undo
173 166
 		{
174 167
 			$traplist=$this->getMIB()->getTrapList($mib);
175 168
 			$retTraps=array('status'=>'OK','traps' => $traplist);
176
-		} 
177
-		catch (Exception $e) 
169
+		} catch (Exception $e) 
178 170
 		{ 
179 171
 			$retTraps=array('status' => 'Error getting mibs');
180 172
 		}
@@ -192,8 +184,7 @@  discard block
 block discarded – undo
192 184
 		if (isset($postData['trap']))
193 185
 		{
194 186
 			$trap=$postData['trap'];
195
-		}
196
-		else
187
+		} else
197 188
 		{
198 189
 			$this->_helper->json(array('status'=>'No trap'));
199 190
 			return;
@@ -202,8 +193,7 @@  discard block
 block discarded – undo
202 193
 		{
203 194
 			$objectlist=$this->getMIB()->getObjectList($trap);
204 195
 			$retObjects=array('status'=>'OK','objects' => $objectlist);
205
-		} 
206
-		catch (Exception $e) 
196
+		} catch (Exception $e) 
207 197
 		{ 
208 198
 			$retObjects=array('status' => 'not found');
209 199
 		}
@@ -218,8 +208,7 @@  discard block
 block discarded – undo
218 208
 		try
219 209
 		{
220 210
 			$miblist=$this->getMIB()->getMIBList();
221
-		} 
222
-		catch (Exception $e) 
211
+		} catch (Exception $e) 
223 212
 		{ 
224 213
 			$miblist=array('Error getting mibs');
225 214
 		}
@@ -237,8 +226,7 @@  discard block
 block discarded – undo
237 226
 		if (isset($postData['oid']))
238 227
 		{
239 228
 			$oid=$postData['oid'];
240
-		}
241
-		else
229
+		} else
242 230
 		{
243 231
 			$this->_helper->json(array('status'=>'No oid'));
244 232
 			return;
@@ -249,8 +237,7 @@  discard block
 block discarded – undo
249 237
 		{
250 238
 			$this->_helper->json(array('status'=>'Not found'));
251 239
 			return;
252
-		}
253
-		else
240
+		} else
254 241
 		{
255 242
 			$this->_helper->json(
256 243
 				array('status'=>'OK',
@@ -283,8 +270,7 @@  discard block
 block discarded – undo
283 270
 				$this->_helper->json(array('status'=>'invalid days : '.$days));
284 271
 				return;
285 272
 			}
286
-		}
287
-		else
273
+		} else
288 274
 		{
289 275
 			$this->_helper->json(array('status'=>'No days'));
290 276
 			return;
@@ -297,8 +283,7 @@  discard block
 block discarded – undo
297 283
 				$this->_helper->json(array('status'=>'unknown action '.$action));
298 284
 				return;
299 285
 			}
300
-		}
301
-		else
286
+		} else
302 287
 		{
303 288
 			$this->_helper->json(array('status'=>'No action'));
304 289
 			return;
@@ -308,8 +293,7 @@  discard block
 block discarded – undo
308 293
 			try
309 294
 			{
310 295
 				$this->setDBConfigValue('db_remove_days',$days);
311
-			}
312
-			catch (Exception $e)
296
+			} catch (Exception $e)
313 297
 			{
314 298
 				$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
315 299
 				return;
@@ -327,8 +311,7 @@  discard block
 block discarded – undo
327 311
 				$Trap = new Trap($icingaweb2_etc);
328 312
 				$Trap->setLogging($debug_level,'syslog');
329 313
 				$Trap->eraseOldTraps($days);
330
-			}
331
-			catch (Exception $e)
314
+			} catch (Exception $e)
332 315
 			{
333 316
 				$this->_helper->json(array('status'=>'execute error : '.$e->getMessage() ));
334 317
 				return;
@@ -356,8 +339,7 @@  discard block
 block discarded – undo
356 339
 				$this->_helper->json(array('status'=>'invalid destination : '.$destination));
357 340
 				return;
358 341
 			}
359
-		}
360
-		else
342
+		} else
361 343
 		{
362 344
 			$this->_helper->json(array('status'=>'No destination'));
363 345
 		}
@@ -370,14 +352,12 @@  discard block
 block discarded – undo
370 352
 			    $this->_helper->json(array('status'=>'File not writable :  '.$file));
371 353
 			    return;
372 354
 			}
373
-		}
374
-		else
355
+		} else
375 356
 		{
376 357
 			if ($destination != 'file')
377 358
 			{
378 359
 				$file=null;
379
-			}
380
-			else
360
+			} else
381 361
 			{
382 362
 				$this->_helper->json(array('status'=>'No file'));
383 363
 				return;
@@ -387,8 +367,7 @@  discard block
 block discarded – undo
387 367
 		if (isset($postData['level']))
388 368
 		{ 
389 369
 			$level=$postData['level'];
390
-		}
391
-		else
370
+		} else
392 371
 		{
393 372
 			$this->_helper->json(array('status'=>'No level'));
394 373
 			return;
@@ -399,8 +378,7 @@  discard block
 block discarded – undo
399 378
 			$this->setDBConfigValue('log_destination',$destination);
400 379
 			$this->setDBConfigValue('log_file',$file);
401 380
 			$this->setDBConfigValue('log_level',$level);
402
-		}
403
-		catch (Exception $e)
381
+		} catch (Exception $e)
404 382
 		{
405 383
 			$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
406 384
 			return;
@@ -422,8 +400,7 @@  discard block
 block discarded – undo
422 400
 	    if (isset($postData['rule']))
423 401
 	    {
424 402
 	        $rule=$postData['rule'];
425
-	    }
426
-	    else
403
+	    } else
427 404
 	    {
428 405
 	        $this->_helper->json(array('status'=>'No Rule'));
429 406
 	    }
@@ -435,8 +412,7 @@  discard block
 block discarded – undo
435 412
 	            $this->_helper->json(array('status'=>'unknown action '.$action));
436 413
 	            return;
437 414
 	        }
438
-	    }
439
-	    else
415
+	    } else
440 416
 	    {
441 417
 	        $this->_helper->json(array('status'=>'No action'));
442 418
 	        return;
@@ -453,8 +429,7 @@  discard block
 block discarded – undo
453 429
 	            // Eval
454 430
 	            $item=0;
455 431
 	            $rule=$Trap->evaluation($rule,$item);
456
-	        }
457
-	        catch (Exception $e)
432
+	        } catch (Exception $e)
458 433
 	        {
459 434
 	            $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() ));
460 435
 	            return;
Please login to merge, or discard this patch.
application/controllers/StatusController.php 3 patches
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -65,10 +65,10 @@  discard block
 block discarded – undo
65 65
 	} 
66 66
   
67 67
 	/** Mib management
68
-	*	Post param : action=update_mib_db : update mib database
69
-	*	Post param : ation=check_update : check if mib update is finished
70
-	*	File post : mibfile -> save mib file
71
-	*/
68
+	 *	Post param : action=update_mib_db : update mib database
69
+	 *	Post param : ation=check_update : check if mib update is finished
70
+	 *	File post : mibfile -> save mib file
71
+	 */
72 72
 	public function mibAction()
73 73
 	{
74 74
 		$this->prepareTabs()->activate('mib');
@@ -87,22 +87,22 @@  discard block
 block discarded – undo
87 87
 					$return=exec('icingacli trapdirector mib update --pid /tmp/trapdirector_update.pid');
88 88
 					if (preg_match('/OK/',$return))
89 89
 					{
90
-					    $this->_helper->json(array('status'=>'OK'));
90
+						$this->_helper->json(array('status'=>'OK'));
91 91
 					}
92 92
 					// Error
93 93
 					$this->_helper->json(array('status'=>$return));
94 94
 				}
95 95
 				if ($action == 'check_update')
96 96
 				{
97
-				    $file=@fopen('/tmp/trapdirector_update.pid','r');
98
-				    if ($file == false)
99
-				    {   // process is dead
100
-				        $this->_helper->json(array('status'=>'tu quoque fili','err'=>'Cannot open file'));
101
-				        return;
102
-				    }
103
-				    $pid=fgets($file);
104
-				    $output=array();
105
-				    $retVal=0;
97
+					$file=@fopen('/tmp/trapdirector_update.pid','r');
98
+					if ($file == false)
99
+					{   // process is dead
100
+						$this->_helper->json(array('status'=>'tu quoque fili','err'=>'Cannot open file'));
101
+						return;
102
+					}
103
+					$pid=fgets($file);
104
+					$output=array();
105
+					$retVal=0;
106 106
 					exec('ps '.$pid,$output,$retVal);
107 107
 					if ($retVal == 0)
108 108
 					{ // process is alive
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 					}
111 111
 					else
112 112
 					{ // process is dead
113
-					    $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid));
113
+						$this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid));
114 114
 					}
115 115
 				}
116 116
 				$this->_helper->json(array('status'=>'ERR : no '.$action.' action possible' ));
@@ -259,20 +259,20 @@  discard block
 block discarded – undo
259 259
 // TODO : see if useless 
260 260
 class UploadForm extends Form
261 261
 { 
262
-    public function __construct($options = null) 
263
-    {
264
-        parent::__construct($options);
265
-        $this->addElements2();
266
-    }
262
+	public function __construct($options = null) 
263
+	{
264
+		parent::__construct($options);
265
+		$this->addElements2();
266
+	}
267 267
 
268
-    public function addElements2()
269
-    {
270
-        // File Input
271
-        $file = new File('mib-file');
272
-        $file->setLabel('Mib upload');
273
-             //->setAttrib('multiple', null);
274
-        $this->addElement($file);
268
+	public function addElements2()
269
+	{
270
+		// File Input
271
+		$file = new File('mib-file');
272
+		$file->setLabel('Mib upload');
273
+			 //->setAttrib('multiple', null);
274
+		$this->addElement($file);
275 275
 		$button = new Submit("upload",array('ignore'=>false));
276 276
 		$this->addElement($button);//->setIgnore(false);
277
-    }
277
+	}
278 278
 }
Please login to merge, or discard this patch.
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -22,18 +22,18 @@  discard block
 block discarded – undo
22 22
 		/************  Trapdb ***********/
23 23
 		try
24 24
 		{
25
-			$db = $this->getDb()->getConnection();
26
-			$query = $db->select()->from(
25
+			$db=$this->getDb()->getConnection();
26
+			$query=$db->select()->from(
27 27
 				$this->getModuleConfig()->getTrapTableName(),
28 28
 				array('COUNT(*)')
29 29
 			);			
30 30
 			$this->view->trap_count=$db->fetchOne($query);
31
-			$query = $db->select()->from(
31
+			$query=$db->select()->from(
32 32
 				$this->getModuleConfig()->getTrapDataTableName(),
33 33
 				array('COUNT(*)')
34 34
 			);			
35 35
 			$this->view->trap_object_count=$db->fetchOne($query);
36
-			$query = $db->select()->from(
36
+			$query=$db->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,7 +59,7 @@  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
 	} 
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 				if ($action == 'update_mib_db')
86 86
 				{ // Do the update in background
87 87
 					$return=exec('icingacli trapdirector mib update --pid /tmp/trapdirector_update.pid');
88
-					if (preg_match('/OK/',$return))
88
+					if (preg_match('/OK/', $return))
89 89
 					{
90 90
 					    $this->_helper->json(array('status'=>'OK'));
91 91
 					}
@@ -94,34 +94,34 @@  discard block
 block discarded – undo
94 94
 				}
95 95
 				if ($action == 'check_update')
96 96
 				{
97
-				    $file=@fopen('/tmp/trapdirector_update.pid','r');
97
+				    $file=@fopen('/tmp/trapdirector_update.pid', 'r');
98 98
 				    if ($file == false)
99 99
 				    {   // process is dead
100
-				        $this->_helper->json(array('status'=>'tu quoque fili','err'=>'Cannot open file'));
100
+				        $this->_helper->json(array('status'=>'tu quoque fili', 'err'=>'Cannot open file'));
101 101
 				        return;
102 102
 				    }
103 103
 				    $pid=fgets($file);
104 104
 				    $output=array();
105 105
 				    $retVal=0;
106
-					exec('ps '.$pid,$output,$retVal);
106
+					exec('ps '.$pid, $output, $retVal);
107 107
 					if ($retVal == 0)
108 108
 					{ // process is alive
109 109
 						$this->_helper->json(array('status'=>'Alive and kicking'));
110 110
 					}
111 111
 					else
112 112
 					{ // process is dead
113
-					    $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid));
113
+					    $this->_helper->json(array('status'=>'tu quoque fili', 'err'=>'no proc'.$pid));
114 114
 					}
115 115
 				}
116
-				$this->_helper->json(array('status'=>'ERR : no '.$action.' action possible' ));
116
+				$this->_helper->json(array('status'=>'ERR : no '.$action.' action possible'));
117 117
 			}
118 118
 			/** Check for mib file UPLOAD */
119 119
 			if (isset($_FILES['mibfile']))
120 120
 			{
121 121
 				$name=$_FILES['mibfile']['name'];
122
-				$DirConf=explode(':',$this->Config()->get('config', 'snmptranslate_dirs'));
123
-				$destination = array_shift($DirConf) .'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name";
124
-				if (move_uploaded_file($_FILES['mibfile']['tmp_name'],$destination)===false)
122
+				$DirConf=explode(':', $this->Config()->get('config', 'snmptranslate_dirs'));
123
+				$destination=array_shift($DirConf).'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name";
124
+				if (move_uploaded_file($_FILES['mibfile']['tmp_name'], $destination) === false)
125 125
 				{
126 126
 					$this->view->uploadStatus='ERROR, file not loaded. Check mibs directory permission';
127 127
 				}
@@ -134,13 +134,13 @@  discard block
 block discarded – undo
134 134
 		}
135 135
 		
136 136
 		// snmptranslate tests
137
-		$snmptranslate = $this->Config()->get('config', 'snmptranslate');
137
+		$snmptranslate=$this->Config()->get('config', 'snmptranslate');
138 138
 		$this->view->snmptranslate_bin=$snmptranslate;
139 139
 		$this->view->snmptranslate_state='warn';
140
-		if (is_executable ( $snmptranslate ))
140
+		if (is_executable($snmptranslate))
141 141
 		{
142
-			$translate=exec($snmptranslate . ' 1');
143
-			if (preg_match('/iso/',$translate))
142
+			$translate=exec($snmptranslate.' 1');
143
+			if (preg_match('/iso/', $translate))
144 144
 			{
145 145
 				$this->view->snmptranslate='works fine';
146 146
 				$this->view->snmptranslate_state='ok';
@@ -158,46 +158,46 @@  discard block
 block discarded – undo
158 158
 		// mib database
159 159
 		
160 160
 		$this->view->mibDbCount=$this->getMIB()->countObjects();
161
-		$this->view->mibDbCountTrap=$this->getMIB()->countObjects(null,21);
161
+		$this->view->mibDbCountTrap=$this->getMIB()->countObjects(null, 21);
162 162
 		
163 163
 		// mib dirs
164 164
 		$DirConf=$this->Config()->get('config', 'snmptranslate_dirs');
165
-		$dirArray=explode(':',$DirConf);
165
+		$dirArray=explode(':', $DirConf);
166 166
 
167 167
 		// Get base directories from net-snmp-config
168 168
 		$output=$matches=array();
169 169
 		$retVal=0;
170
-		$sysDirs=exec('net-snmp-config --default-mibdirs',$output,$retVal);
171
-		if ($retVal==0)
170
+		$sysDirs=exec('net-snmp-config --default-mibdirs', $output, $retVal);
171
+		if ($retVal == 0)
172 172
 		{
173
-			$dirArray=array_merge($dirArray,explode(':',$sysDirs));
173
+			$dirArray=array_merge($dirArray, explode(':', $sysDirs));
174 174
 		}
175 175
 		else
176 176
 		{
177
-			$translateOut=exec($this->Config()->get('config', 'snmptranslate') . ' -Dinit_mib .1.3 2>&1 | grep MIBDIRS');
178
-			if (preg_match('/MIBDIRS.*\'([^\']+)\'/',$translateOut,$matches))
177
+			$translateOut=exec($this->Config()->get('config', 'snmptranslate').' -Dinit_mib .1.3 2>&1 | grep MIBDIRS');
178
+			if (preg_match('/MIBDIRS.*\'([^\']+)\'/', $translateOut, $matches))
179 179
 			{
180
-				$dirArray=array_merge($dirArray,explode(':',$matches[1]));
180
+				$dirArray=array_merge($dirArray, explode(':', $matches[1]));
181 181
 			}
182 182
 			else
183 183
 			{
184
-				array_push($dirArray,'Install net-snmp-config to see system directories');
184
+				array_push($dirArray, 'Install net-snmp-config to see system directories');
185 185
 			}
186 186
 		}
187 187
 		
188 188
 		$this->view->dirArray=$dirArray;
189 189
 		
190 190
 		$output=null;
191
-		foreach (explode(':',$DirConf) as $mibdir)
191
+		foreach (explode(':', $DirConf) as $mibdir)
192 192
 		{
193
-			exec('ls '.$mibdir.' | grep -v traplist.txt',$output);
193
+			exec('ls '.$mibdir.' | grep -v traplist.txt', $output);
194 194
 		}
195 195
 		//$i=0;$listFiles='';while (isset($output[$i])) $listFiles.=$output[$i++];
196 196
 		//$this->view->fileList=explode(' ',$listFiles);
197 197
 		$this->view->fileList=$output;
198 198
 		
199 199
 		// Zend form 
200
-		$this->view->form= new UploadForm();
200
+		$this->view->form=new UploadForm();
201 201
 		//$this->view->form= new Form('upload-form');
202 202
 		
203 203
 		
@@ -221,18 +221,18 @@  discard block
 block discarded – undo
221 221
 		$this->view->templateForm_output='';
222 222
 		if (isset($postData['template_name']) && isset($postData['template_revert_time']))
223 223
 		{
224
-			$template_create = 'icingacli director service create --json \'{ "check_command": "dummy", ';
225
-			$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", ';
226
-			$template_create .= '"object_name": "'.$postData['template_name'].'", "object_type": "template", "retry_interval": "'.$postData['template_revert_time'].'"}\'';
224
+			$template_create='icingacli director service create --json \'{ "check_command": "dummy", ';
225
+			$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", ';
226
+			$template_create.='"object_name": "'.$postData['template_name'].'", "object_type": "template", "retry_interval": "'.$postData['template_revert_time'].'"}\'';
227 227
 			$output=array();
228 228
 			$ret_code=0;
229
-			exec($template_create,$output,$ret_code);
229
+			exec($template_create, $output, $ret_code);
230 230
 			if ($ret_code != 0)
231 231
 			{
232
-				$this->displayExitError("Status -> Services","Error creating template : ".$output[0].'<br>Command was : '.$template_create);
232
+				$this->displayExitError("Status -> Services", "Error creating template : ".$output[0].'<br>Command was : '.$template_create);
233 233
 			}
234
-			exec('icingacli director config deploy',$output,$ret_code);
235
-			$this->view->templateForm_output='Template '.$postData['template_name']. ' created';
234
+			exec('icingacli director config deploy', $output, $ret_code);
235
+			$this->view->templateForm_output='Template '.$postData['template_name'].' created';
236 236
 		}
237 237
 		
238 238
 		// template creation form
@@ -245,13 +245,13 @@  discard block
 block discarded – undo
245 245
 	{
246 246
 		return $this->getTabs()->add('status', array(
247 247
 			'label' => $this->translate('Status'),
248
-			'url'   => $this->getModuleConfig()->urlPath() . '/status')
248
+			'url'   => $this->getModuleConfig()->urlPath().'/status')
249 249
 		)->add('mib', array(
250 250
 			'label' => $this->translate('MIB Management'),
251
-			'url'   => $this->getModuleConfig()->urlPath() . '/status/mib')
251
+			'url'   => $this->getModuleConfig()->urlPath().'/status/mib')
252 252
 		)->add('services', array(
253 253
 			'label' => $this->translate('Services management'),
254
-			'url'   => $this->getModuleConfig()->urlPath() . '/status/services')
254
+			'url'   => $this->getModuleConfig()->urlPath().'/status/services')
255 255
 		);
256 256
 	} 
257 257
 }
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 // TODO : see if useless 
260 260
 class UploadForm extends Form
261 261
 { 
262
-    public function __construct($options = null) 
262
+    public function __construct($options=null) 
263 263
     {
264 264
         parent::__construct($options);
265 265
         $this->addElements2();
@@ -268,11 +268,11 @@  discard block
 block discarded – undo
268 268
     public function addElements2()
269 269
     {
270 270
         // File Input
271
-        $file = new File('mib-file');
271
+        $file=new File('mib-file');
272 272
         $file->setLabel('Mib upload');
273 273
              //->setAttrib('multiple', null);
274 274
         $this->addElement($file);
275
-		$button = new Submit("upload",array('ignore'=>false));
276
-		$this->addElement($button);//->setIgnore(false);
275
+		$button=new Submit("upload", array('ignore'=>false));
276
+		$this->addElement($button); //->setIgnore(false);
277 277
     }
278 278
 }
Please login to merge, or discard this patch.
Braces   +8 added lines, -16 removed lines patch added patch discarded remove patch
@@ -41,8 +41,7 @@  discard block
 block discarded – undo
41 41
  			
42 42
 			$this->view->trap_days_delete=$this->getDBConfigValue('db_remove_days');
43 43
 			
44
-		}
45
-		catch (Exception $e)
44
+		} catch (Exception $e)
46 45
 		{
47 46
 			$this->displayExitError('status',$e->getMessage());
48 47
 		}
@@ -56,8 +55,7 @@  discard block
 block discarded – undo
56 55
 			$this->view->currentLogFile=$this->getDBConfigValue('log_file');
57 56
 			$this->view->logLevels=$this->getModuleConfig()->getlogLevels();
58 57
 			$this->view->currentLogLevel=$this->getDBConfigValue('log_level');
59
-		}
60
-		catch (Exception $e)
58
+		} catch (Exception $e)
61 59
 		{
62 60
 			$this->displayExitError('status',$e->getMessage());
63 61
 		}		
@@ -107,8 +105,7 @@  discard block
 block discarded – undo
107 105
 					if ($retVal == 0)
108 106
 					{ // process is alive
109 107
 						$this->_helper->json(array('status'=>'Alive and kicking'));
110
-					}
111
-					else
108
+					} else
112 109
 					{ // process is dead
113 110
 					    $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid));
114 111
 					}
@@ -124,8 +121,7 @@  discard block
 block discarded – undo
124 121
 				if (move_uploaded_file($_FILES['mibfile']['tmp_name'],$destination)===false)
125 122
 				{
126 123
 					$this->view->uploadStatus='ERROR, file not loaded. Check mibs directory permission';
127
-				}
128
-				else
124
+				} else
129 125
 				{
130 126
 					$this->view->uploadStatus="File $name uploaded";
131 127
 				}
@@ -144,13 +140,11 @@  discard block
 block discarded – undo
144 140
 			{
145 141
 				$this->view->snmptranslate='works fine';
146 142
 				$this->view->snmptranslate_state='ok';
147
-			}
148
-			else
143
+			} else
149 144
 			{
150 145
 				$this->view->snmptranslate='can execute but no resolution';
151 146
 			}
152
-		}
153
-		else
147
+		} else
154 148
 		{
155 149
 			$this->view->snmptranslate='cannot execute';
156 150
 		}
@@ -171,15 +165,13 @@  discard block
 block discarded – undo
171 165
 		if ($retVal==0)
172 166
 		{
173 167
 			$dirArray=array_merge($dirArray,explode(':',$sysDirs));
174
-		}
175
-		else
168
+		} else
176 169
 		{
177 170
 			$translateOut=exec($this->Config()->get('config', 'snmptranslate') . ' -Dinit_mib .1.3 2>&1 | grep MIBDIRS');
178 171
 			if (preg_match('/MIBDIRS.*\'([^\']+)\'/',$translateOut,$matches))
179 172
 			{
180 173
 				$dirArray=array_merge($dirArray,explode(':',$matches[1]));
181
-			}
182
-			else
174
+			} else
183 175
 			{
184 176
 				array_push($dirArray,'Install net-snmp-config to see system directories');
185 177
 			}
Please login to merge, or discard this patch.
application/controllers/SettingsController.php 2 patches
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -22,37 +22,37 @@  discard block
 block discarded – undo
22 22
   public function indexAction()
23 23
   {
24 24
       
25
-    // CHeck permissions : display tests in any case, but no configuration.
25
+	// CHeck permissions : display tests in any case, but no configuration.
26 26
 	$this->view->configPermission=$this->checkModuleConfigPermission(1);
27 27
 	// But check read permission
28 28
 	$this->checkReadPermission();
29 29
 	// Get message : sent on configuration problems detected by controllers
30 30
 	$dberrorMsg=$this->params->get('dberror');
31 31
 	if ($dberrorMsg != '')
32
-	    $this->view->errorDetected=$dberrorMsg;
33
-    $dberrorMsg=$this->params->get('idodberror');
34
-    if ($dberrorMsg != '')
35
-        $this->view->errorDetected=$dberrorMsg;
32
+		$this->view->errorDetected=$dberrorMsg;
33
+	$dberrorMsg=$this->params->get('idodberror');
34
+	if ($dberrorMsg != '')
35
+		$this->view->errorDetected=$dberrorMsg;
36 36
     
37
-    $this->view->configErrorDetected == NULL; // Displayed error on various conifugration errors.
37
+	$this->view->configErrorDetected == NULL; // Displayed error on various conifugration errors.
38 38
     
39
-    // Test if configuration exists, if not create for installer script
39
+	// Test if configuration exists, if not create for installer script
40 40
 	//$emptyConfig=0;
41
-    if ($this->Config()->isEmpty() == true)
42
-    {
43
-        $this->Config()->setSection('config'); // Set base config section.
44
-        try 
45
-        { 
46
-            $this->Config()->saveIni();
47
-            $this->view->configErrorDetected='Configuration is empty : you can run install script with parameters (see Automatic installation below)';
41
+	if ($this->Config()->isEmpty() == true)
42
+	{
43
+		$this->Config()->setSection('config'); // Set base config section.
44
+		try 
45
+		{ 
46
+			$this->Config()->saveIni();
47
+			$this->view->configErrorDetected='Configuration is empty : you can run install script with parameters (see Automatic installation below)';
48 48
 			//$emptyConfig=1;
49
-        }
50
-        catch (Exception $e)
51
-        {
52
-            $this->view->configErrorDetected=$e->getMessage();
53
-        }
49
+		}
50
+		catch (Exception $e)
51
+		{
52
+			$this->view->configErrorDetected=$e->getMessage();
53
+		}
54 54
         
55
-    }
55
+	}
56 56
 	// Test Database
57 57
 	$db_message=array( // index => ( message OK, message NOK, optional link if NOK ) 
58 58
 		0	=>	array('Database configuration OK','',''),
@@ -97,20 +97,20 @@  discard block
 block discarded – undo
97 97
 	//********* Test API
98 98
 	if ($this->Config()->get('config', 'icingaAPI_host') != '')
99 99
 	{
100
-	    $apitest=new Icinga2Api($this->Config()->get('config', 'icingaAPI_host'),$this->Config()->get('config', 'icingaAPI_port'));
101
-    	$apitest->setCredentials($this->Config()->get('config', 'icingaAPI_user'), $this->Config()->get('config', 'icingaAPI_password'));
102
-    	try {
103
-    	    list($this->view->apimessageError,$this->view->apimessage)=$apitest->test($this->getModuleConfig()::getapiUserPermissions());
104
-    	    //$this->view->apimessageError=false;
105
-    	} catch (RuntimeException $e) {
106
-    	    $this->view->apimessage='API config : ' . $e->getMessage();
107
-    	    $this->view->apimessageError=true;
108
-    	} 
100
+		$apitest=new Icinga2Api($this->Config()->get('config', 'icingaAPI_host'),$this->Config()->get('config', 'icingaAPI_port'));
101
+		$apitest->setCredentials($this->Config()->get('config', 'icingaAPI_user'), $this->Config()->get('config', 'icingaAPI_password'));
102
+		try {
103
+			list($this->view->apimessageError,$this->view->apimessage)=$apitest->test($this->getModuleConfig()::getapiUserPermissions());
104
+			//$this->view->apimessageError=false;
105
+		} catch (RuntimeException $e) {
106
+			$this->view->apimessage='API config : ' . $e->getMessage();
107
+			$this->view->apimessageError=true;
108
+		} 
109 109
 	}
110 110
 	else
111 111
 	{
112
-	    $this->view->apimessage='API parameters not configured';
113
-	    $this->view->apimessageError=true;
112
+		$this->view->apimessage='API parameters not configured';
113
+		$this->view->apimessageError=true;
114 114
 	}
115 115
 	
116 116
 	//*********** Test snmptrapd alive and options
@@ -125,33 +125,33 @@  discard block
 block discarded – undo
125 125
 		}
126 126
 	}
127 127
 
128
-    $this->view->tabs = $this->Module()->getConfigTabs()->activate('config');
128
+	$this->view->tabs = $this->Module()->getConfigTabs()->activate('config');
129 129
 
130 130
 	// Check standard Icingaweb2 path
131 131
 	$this->view->icingaEtcWarn=0;
132 132
 	$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
133 133
 	if ($icingaweb2_etc != "/etc/icingaweb2/" && $icingaweb2_etc != '')
134 134
 	{
135
-	    $output=array();
135
+		$output=array();
136 136
 	    
137
-	    exec('cat ' . $this->module->getBaseDir() .'/bin/trap_in.php | grep "\$icingaweb2_etc=" ',$output);
137
+		exec('cat ' . $this->module->getBaseDir() .'/bin/trap_in.php | grep "\$icingaweb2_etc=" ',$output);
138 138
 	    
139
-	    if (! preg_match('#"'. $icingaweb2_etc .'"#',$output[0]))
140
-	    {
141
-    	    $this->view->icingaEtcWarn=1;
142
-	        $this->view->icingaweb2_etc=$icingaweb2_etc;
143
-	    }
139
+		if (! preg_match('#"'. $icingaweb2_etc .'"#',$output[0]))
140
+		{
141
+			$this->view->icingaEtcWarn=1;
142
+			$this->view->icingaweb2_etc=$icingaweb2_etc;
143
+		}
144 144
 	}
145 145
 
146 146
 	// Setup path for mini documentation
147 147
 	$this->view->traps_in_config= PHP_BINARY . ' ' . $this->Module()->getBaseDir() . '/bin/trap_in.php';
148 148
 	
149 149
 	$this->view->installer= $this->Module()->getBaseDir() . '/bin/installer.sh '
150
-	    . ' -c all ' 
151
-	    . ' -d ' . $this->Module()->getBaseDir()
152
-	    . ' -p ' . PHP_BINARY
153
-	    . ' -a ' . exec('whoami')
154
-	    . ' -w ' . Icinga::app()->getConfigDir();
150
+		. ' -c all ' 
151
+		. ' -d ' . $this->Module()->getBaseDir()
152
+		. ' -p ' . PHP_BINARY
153
+		. ' -a ' . exec('whoami')
154
+		. ' -w ' . Icinga::app()->getConfigDir();
155 155
 	        
156 156
 	// ******************* configuration form setup*******************
157 157
 	$this->view->form = $form = new TrapsConfigForm();
@@ -196,19 +196,19 @@  discard block
 block discarded – undo
196 196
 		  $dbResource = ResourceFactory::getResourceConfig($dbName);
197 197
 		  $dbType=$dbResource->get('db');
198 198
 		  switch ($dbType) {
199
-		      case 'mysql':
200
-		          $dbFileExt='sql';
201
-		          break;
202
-		      case 'pgsql':
203
-		          $dbFileExt='pgsql';
204
-		          break;
205
-		      default:
206
-		          throw new ConfigurationError('Unsuported database : '.$dbType);
199
+			  case 'mysql':
200
+				  $dbFileExt='sql';
201
+				  break;
202
+			  case 'pgsql':
203
+				  $dbFileExt='pgsql';
204
+				  break;
205
+			  default:
206
+				  throw new ConfigurationError('Unsuported database : '.$dbType);
207 207
 		  }
208 208
 		} catch (ConfigurationError $e )
209 209
 		{
210
-		    printf("Database configuration error : %s",$e->getMessage());
211
-		    return;
210
+			printf("Database configuration error : %s",$e->getMessage());
211
+			return;
212 212
 		}
213 213
 		printf('<pre>');
214 214
 		require_once $this->Module()->getBaseDir() .'/bin/trap_class.php';
@@ -232,11 +232,11 @@  discard block
 block discarded – undo
232 232
   public function updateschemaAction()
233 233
   {
234 234
 	  $this->checkModuleConfigPermission();
235
-    	$this->getTabs()->add('get',array(
236
-    		'active'	=> true,
237
-    		'label'		=> $this->translate('Update Schema'),
238
-    		'url'		=> Url::fromRequest()
239
-    	));
235
+		$this->getTabs()->add('get',array(
236
+			'active'	=> true,
237
+			'label'		=> $this->translate('Update Schema'),
238
+			'url'		=> Url::fromRequest()
239
+		));
240 240
 	  // check if needed
241 241
 	  
242 242
 	  $dberror=$this->getDb(true); // Get DB in test mode
@@ -245,15 +245,15 @@  discard block
 block discarded – undo
245 245
 	  
246 246
 	  if ($dberror[0] == 0)
247 247
 	  {
248
-	      echo 'Schema already exists and is up to date<br>';
249
-	      return;
248
+		  echo 'Schema already exists and is up to date<br>';
249
+		  return;
250 250
 	  }
251 251
 	  if ($dberror[0] != 5)
252 252
 	  {
253
-	      echo 'Database does not exists or is not setup correctly<br>';
254
-	      return;
253
+		  echo 'Database does not exists or is not setup correctly<br>';
254
+		  return;
255 255
 	  }
256
-      // setup
256
+	  // setup
257 257
 	  require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
258 258
 	  $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
259 259
 	  $debug_level=4;
@@ -266,20 +266,20 @@  discard block
 block discarded – undo
266 266
 	  $target_version=$dberror[2];
267 267
 	  
268 268
 	  if ($this->params->get('msgok') == null) {
269
-	      // Check for messages and display if any
270
-              echo "Upgrade databse is going to start.<br>Don't forget to backup your database before update<br>";
271
-	      $Trap->setLogging(2,'syslog');
272
-	      $message = $Trap->update_schema($updateSchema,$target_version,$prefix,true);
273
-	      if ($message != '')
274
-	      {
275
-	          echo 'Note :<br><pre>';
276
-	          echo $message;
277
-	          echo '</pre>';
278
-	          echo '<br>';
279
-	          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>';
280
-	          echo '<br>';
281
-	          return;
282
-	      }
269
+		  // Check for messages and display if any
270
+			  echo "Upgrade databse is going to start.<br>Don't forget to backup your database before update<br>";
271
+		  $Trap->setLogging(2,'syslog');
272
+		  $message = $Trap->update_schema($updateSchema,$target_version,$prefix,true);
273
+		  if ($message != '')
274
+		  {
275
+			  echo 'Note :<br><pre>';
276
+			  echo $message;
277
+			  echo '</pre>';
278
+			  echo '<br>';
279
+			  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>';
280
+			  echo '<br>';
281
+			  return;
282
+		  }
283 283
 	  }
284 284
 	  
285 285
 	  $Trap->setLogging($debug_level,'display');
@@ -293,28 +293,28 @@  discard block
 block discarded – undo
293 293
 
294 294
   private function checkSnmpTrapd()
295 295
   {
296
-      $psOutput=array();
297
-      // First check is someone is listening to port 162. As not root, we can't have pid... 
298
-      exec('netstat -an |grep -E "udp.*:162"',$psOutput);
299
-      if (count($psOutput) == 0)
300
-      {
301
-          return array(1,'Port UDP/162 is not open : snmptrapd must not be started');
302
-      }
303
-      $psOutput=array();
304
-      exec('ps fax |grep snmptrapd |grep -v grep',$psOutput);
305
-      if (count($psOutput) == 0)
306
-      {
307
-          return array(1,"UDP/162 : OK, but no snmptrapd process (?)");
308
-      }
309
-      // Assume there is only one line... TODO : see if there is a better way to do this
310
-      $line = preg_replace('/^.*snmptrapd /','',$psOutput[0]);
311
-      if (!preg_match('/-n/',$line))
312
-          return array(1,'snmptrapd has no -n option : '.$line);
313
-      if (!preg_match('/-O[^ ]*n/',$line))
314
-          return array(1,'snmptrapd has no -On option : '.$line);
315
-      if (!preg_match('/-O[^ ]*e/',$line))
316
-          return array(1,'snmptrapd has no -Oe option : '.$line);
296
+	  $psOutput=array();
297
+	  // First check is someone is listening to port 162. As not root, we can't have pid... 
298
+	  exec('netstat -an |grep -E "udp.*:162"',$psOutput);
299
+	  if (count($psOutput) == 0)
300
+	  {
301
+		  return array(1,'Port UDP/162 is not open : snmptrapd must not be started');
302
+	  }
303
+	  $psOutput=array();
304
+	  exec('ps fax |grep snmptrapd |grep -v grep',$psOutput);
305
+	  if (count($psOutput) == 0)
306
+	  {
307
+		  return array(1,"UDP/162 : OK, but no snmptrapd process (?)");
308
+	  }
309
+	  // Assume there is only one line... TODO : see if there is a better way to do this
310
+	  $line = preg_replace('/^.*snmptrapd /','',$psOutput[0]);
311
+	  if (!preg_match('/-n/',$line))
312
+		  return array(1,'snmptrapd has no -n option : '.$line);
313
+	  if (!preg_match('/-O[^ ]*n/',$line))
314
+		  return array(1,'snmptrapd has no -On option : '.$line);
315
+	  if (!preg_match('/-O[^ ]*e/',$line))
316
+		  return array(1,'snmptrapd has no -Oe option : '.$line);
317 317
       
318
-      return array(0,'snmptrapd listening to UDP/162, options : '.$line);
318
+	  return array(0,'snmptrapd listening to UDP/162, options : '.$line);
319 319
   }
320 320
 }
Please login to merge, or discard this patch.
Braces   +18 added lines, -16 removed lines patch added patch discarded remove patch
@@ -28,11 +28,13 @@  discard block
 block discarded – undo
28 28
 	$this->checkReadPermission();
29 29
 	// Get message : sent on configuration problems detected by controllers
30 30
 	$dberrorMsg=$this->params->get('dberror');
31
-	if ($dberrorMsg != '')
32
-	    $this->view->errorDetected=$dberrorMsg;
31
+	if ($dberrorMsg != '') {
32
+		    $this->view->errorDetected=$dberrorMsg;
33
+	}
33 34
     $dberrorMsg=$this->params->get('idodberror');
34
-    if ($dberrorMsg != '')
35
-        $this->view->errorDetected=$dberrorMsg;
35
+    if ($dberrorMsg != '') {
36
+            $this->view->errorDetected=$dberrorMsg;
37
+    }
36 38
     
37 39
     $this->view->configErrorDetected == NULL; // Displayed error on various conifugration errors.
38 40
     
@@ -46,8 +48,7 @@  discard block
 block discarded – undo
46 48
             $this->Config()->saveIni();
47 49
             $this->view->configErrorDetected='Configuration is empty : you can run install script with parameters (see Automatic installation below)';
48 50
 			//$emptyConfig=1;
49
-        }
50
-        catch (Exception $e)
51
+        } catch (Exception $e)
51 52
         {
52 53
             $this->view->configErrorDetected=$e->getMessage();
53 54
         }
@@ -106,8 +107,7 @@  discard block
 block discarded – undo
106 107
     	    $this->view->apimessage='API config : ' . $e->getMessage();
107 108
     	    $this->view->apimessageError=true;
108 109
     	} 
109
-	}
110
-	else
110
+	} else
111 111
 	{
112 112
 	    $this->view->apimessage='API parameters not configured';
113 113
 	    $this->view->apimessageError=true;
@@ -184,8 +184,7 @@  discard block
 block discarded – undo
184 184
 	if ($dberror[0] == 0)
185 185
 	{
186 186
 		printf('Schema already exists');
187
-	}
188
-	else
187
+	} else
189 188
 	{
190 189
 		printf('Creating schema : <br>');
191 190
 
@@ -308,12 +307,15 @@  discard block
 block discarded – undo
308 307
       }
309 308
       // Assume there is only one line... TODO : see if there is a better way to do this
310 309
       $line = preg_replace('/^.*snmptrapd /','',$psOutput[0]);
311
-      if (!preg_match('/-n/',$line))
312
-          return array(1,'snmptrapd has no -n option : '.$line);
313
-      if (!preg_match('/-O[^ ]*n/',$line))
314
-          return array(1,'snmptrapd has no -On option : '.$line);
315
-      if (!preg_match('/-O[^ ]*e/',$line))
316
-          return array(1,'snmptrapd has no -Oe option : '.$line);
310
+      if (!preg_match('/-n/',$line)) {
311
+                return array(1,'snmptrapd has no -n option : '.$line);
312
+      }
313
+      if (!preg_match('/-O[^ ]*n/',$line)) {
314
+                return array(1,'snmptrapd has no -On option : '.$line);
315
+      }
316
+      if (!preg_match('/-O[^ ]*e/',$line)) {
317
+                return array(1,'snmptrapd has no -Oe option : '.$line);
318
+      }
317 319
       
318 320
       return array(0,'snmptrapd listening to UDP/162, options : '.$line);
319 321
   }
Please login to merge, or discard this patch.