Passed
Push — master ( b8f383...dcdb45 )
by Patrick
02:09
created
library/Trapdirector/Tables/HandlerTableList.php 3 patches
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -31,9 +31,9 @@  discard block
 block discarded – undo
31 31
 	
32 32
 	// Filters 
33 33
 	
34
-    protected $filter;
35
-    protected $enforcedFilters = array();
36
-    protected $searchColumns = array();
34
+	protected $filter;
35
+	protected $enforcedFilters = array();
36
+	protected $searchColumns = array();
37 37
 	
38 38
 	protected function getTitles() {
39 39
 		return $this->moduleConfig->getHandlerListTitles();
@@ -45,10 +45,10 @@  discard block
 block discarded – undo
45 45
 		$this->doTranslate=true;
46 46
 	}
47 47
 	// ******************  Render table in html  
48
-    public function __toString()
49
-    {
50
-        return $this->render();
51
-    }
48
+	public function __toString()
49
+	{
50
+		return $this->render();
51
+	}
52 52
 	
53 53
 	public function render()
54 54
 	{
@@ -153,30 +153,30 @@  discard block
 block discarded – undo
153 153
 
154 154
 	}
155 155
 
156
-    public function count()
157
-    {
158
-        $db = $this->connection()->getConnection();
159
-        $query = clone($this->getBaseQuery());
160
-        $query->reset('order')->columns(array('COUNT(*)'));
161
-        $this->applyFiltersToQuery($query);
156
+	public function count()
157
+	{
158
+		$db = $this->connection()->getConnection();
159
+		$query = clone($this->getBaseQuery());
160
+		$query->reset('order')->columns(array('COUNT(*)'));
161
+		$this->applyFiltersToQuery($query);
162 162
 
163 163
 		$db=$this->db();
164 164
 		
165 165
 		$query = $db->select()->from(
166
-            $this->moduleConfig->getTrapRuleName(),
167
-            array('COUNT(*)')
168
-        );
166
+			$this->moduleConfig->getTrapRuleName(),
167
+			array('COUNT(*)')
168
+		);
169 169
 		
170
-        return $db->fetchOne($query);
171
-    }
170
+		return $db->fetchOne($query);
171
+	}
172 172
 	
173
-    public function getPaginator()
174
-    {
175
-        $paginator = new Paginator();
176
-        $paginator->setQuery($this);
173
+	public function getPaginator()
174
+	{
175
+		$paginator = new Paginator();
176
+		$paginator->setQuery($this);
177 177
 
178
-        return $paginator;
179
-    }
178
+		return $paginator;
179
+	}
180 180
 	
181 181
 	// ****************** DB connection and query
182 182
 	
@@ -186,63 +186,63 @@  discard block
 block discarded – undo
186 186
 		
187 187
 		$query = $this->getBaseQuery();
188 188
 		
189
-       if ($this->hasLimit() || $this->hasOffset()) {
190
-            $query->limit($this->getLimit(), $this->getOffset());
191
-        }		
189
+	   if ($this->hasLimit() || $this->hasOffset()) {
190
+			$query->limit($this->getLimit(), $this->getOffset());
191
+		}		
192 192
 		
193 193
 		return $db->fetchAll($query);
194 194
 	}
195 195
 	 
196
-    public function getBaseQuery()
197
-    {
196
+	public function getBaseQuery()
197
+	{
198 198
 		$db=$this->db();
199 199
 		
200 200
 		$query = $db->select()->from(
201
-            $this->moduleConfig->getTrapRuleName(),
202
-            $this->moduleConfig->getHandlerListDisplayColumns()
203
-        )->order('host_name DESC,trap_oid DESC');
201
+			$this->moduleConfig->getTrapRuleName(),
202
+			$this->moduleConfig->getHandlerListDisplayColumns()
203
+		)->order('host_name DESC,trap_oid DESC');
204 204
 
205
-        return $query;
206
-    }	 
205
+		return $query;
206
+	}	 
207 207
 	
208 208
 	// ****************** Filters
209 209
 
210
-    protected function getSearchColumns()
211
-    {
212
-        return $this->getColumns();
213
-    }
210
+	protected function getSearchColumns()
211
+	{
212
+		return $this->getColumns();
213
+	}
214 214
 	
215 215
 	public function getColumns()
216 216
 	{
217 217
 		return $this->moduleConfig->getHandlerListDisplayColumns();
218 218
 	}
219 219
 
220
-    public function setFilter($filter)
221
-    {
222
-        $this->filter = $filter;
223
-        return $this;
224
-    }
220
+	public function setFilter($filter)
221
+	{
222
+		$this->filter = $filter;
223
+		return $this;
224
+	}
225 225
 	
226 226
 	public function getFilterEditor(Request $request)
227
-    {
228
-        $filterEditor = Widget::create('filterEditor')
229
-            ->setColumns(array_keys($this->getColumns()))
230
-            ->setSearchColumns(array_keys($this->getSearchColumns()))
231
-            ->preserveParams('limit', 'sort', 'dir', 'view', 'backend')
232
-            ->ignoreParams('page')
233
-            ->handleRequest($request);
227
+	{
228
+		$filterEditor = Widget::create('filterEditor')
229
+			->setColumns(array_keys($this->getColumns()))
230
+			->setSearchColumns(array_keys($this->getSearchColumns()))
231
+			->preserveParams('limit', 'sort', 'dir', 'view', 'backend')
232
+			->ignoreParams('page')
233
+			->handleRequest($request);
234 234
 
235
-        $filter = $filterEditor->getFilter();
236
-        $this->setFilter($filter);
235
+		$filter = $filterEditor->getFilter();
236
+		$this->setFilter($filter);
237 237
 
238
-        return $filterEditor;
239
-    }
238
+		return $filterEditor;
239
+	}
240 240
 	
241
-    protected function applyFiltersToQuery($query)
242
-    {
241
+	protected function applyFiltersToQuery($query)
242
+	{
243 243
 		// TODO : implement
244 244
 		
245
-        /*$filter = null;
245
+		/*$filter = null;
246 246
         $enforced = $this->enforcedFilters;
247 247
         if ($this->filter && ! $this->filter->isEmpty()) {
248 248
             $filter = $this->filter;
@@ -257,8 +257,8 @@  discard block
 block discarded – undo
257 257
         }
258 258
 		*/
259 259
 		
260
-        return $query;
261
-    }	
260
+		return $query;
261
+	}	
262 262
 
263 263
 }
264 264
 
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -32,8 +32,8 @@  discard block
 block discarded – undo
32 32
 	// Filters 
33 33
 	
34 34
     protected $filter;
35
-    protected $enforcedFilters = array();
36
-    protected $searchColumns = array();
35
+    protected $enforcedFilters=array();
36
+    protected $searchColumns=array();
37 37
 	
38 38
 	protected function getTitles() {
39 39
 		return $this->moduleConfig->getHandlerListTitles();
@@ -53,34 +53,34 @@  discard block
 block discarded – undo
53 53
 	public function render()
54 54
 	{
55 55
 		$data=$this->getTable();
56
-		$view = $this->getView();
57
-		$this->columnCount = count($this->getTitles());
56
+		$view=$this->getView();
57
+		$this->columnCount=count($this->getTitles());
58 58
 		$this->lastDay=null;
59 59
 		// Table start
60
-		$htm  = '<table class="simple common-table table-row-selectable">';
60
+		$htm='<table class="simple common-table table-row-selectable">';
61 61
 		
62 62
 		// Titles
63
-		$htm .= "<thead>\n  <tr>\n";
64
-		$titles = $this->getTitles();
63
+		$htm.="<thead>\n  <tr>\n";
64
+		$titles=$this->getTitles();
65 65
 		foreach ($titles as $title) 
66 66
 		{
67
-			$htm .= '    <th>' . $view->escape($view->translate($title)) . "</th>\n";
67
+			$htm.='    <th>'.$view->escape($view->translate($title))."</th>\n";
68 68
 		}
69
-		$htm .= "  </tr>\n</thead>\n";
69
+		$htm.="  </tr>\n</thead>\n";
70 70
 		
71 71
 		// Rows
72
-		$htm .= "<tbody>\n";
72
+		$htm.="<tbody>\n";
73 73
 		
74 74
 		foreach ($data as $row) 
75 75
 		{
76
-			$firstCol = true;
76
+			$firstCol=true;
77 77
 			// Put date header
78 78
 			//$htm .= $this->renderDayIfNew($row->timestamp);
79 79
 			
80 80
 			
81 81
 			// Render row
82
-			$htm .= '<tr '.' >';
83
-			foreach ( $titles as $rowkey => $title) 
82
+			$htm.='<tr '.' >';
83
+			foreach ($titles as $rowkey => $title) 
84 84
 			{
85 85
 				// Check missing value
86 86
 				if (property_exists($row, $rowkey)) 
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 						break;
94 94
 						case 'trap_oid': // try to traslate oids.
95 95
 						
96
-							if ($this->doTranslate==true)
96
+							if ($this->doTranslate == true)
97 97
 							{
98 98
 								$oidName=$this->MIB->translateOID($row->$rowkey);
99 99
 								if (isset($oidName['name']))
@@ -102,52 +102,52 @@  discard block
 block discarded – undo
102 102
 								}
103 103
 								else
104 104
 								{
105
-									$val = $row->$rowkey;
105
+									$val=$row->$rowkey;
106 106
 								}								
107 107
 							}
108 108
 							else
109 109
 							{
110
-								$val = $row->$rowkey;
110
+								$val=$row->$rowkey;
111 111
 							}
112 112
 						break;
113 113
 						case 'host_name': // switch to hostgroup if name is null
114 114
 							if ($row->$rowkey == null)
115 115
 							{
116
-								$val = $row->host_group_name;
116
+								$val=$row->host_group_name;
117 117
 							}
118 118
 							else
119 119
 							{
120
-								$val = $row->$rowkey;
120
+								$val=$row->$rowkey;
121 121
 							}
122 122
 						break;
123 123
 						default:
124
-							$val = $row->$rowkey;
124
+							$val=$row->$rowkey;
125 125
 					}
126
-					if ($rowkey == 'trap_oid' && $this->doTranslate==true)
126
+					if ($rowkey == 'trap_oid' && $this->doTranslate == true)
127 127
 					{					
128 128
 							
129 129
 					}
130 130
 				} else {
131
-					$val = '-';
131
+					$val='-';
132 132
 				}
133 133
 				if ($firstCol == true) { // Put link in first column for trap detail.
134
-					$htm .= '<td>' 
134
+					$htm.='<td>' 
135 135
 							. $view->qlink(
136 136
 									$view->escape($val),  
137 137
 									Url::fromPath(
138
-										$this->moduleConfig->urlPath() . '/handler/add', 
138
+										$this->moduleConfig->urlPath().'/handler/add', 
139 139
 										array('ruleid' => $row->id)
140 140
 									)
141 141
 							)
142 142
 							. '</td>';
143 143
 				} else {
144
-					$htm .= '<td>' . $view->escape($val) . '</td>';
144
+					$htm.='<td>'.$view->escape($val).'</td>';
145 145
 				}
146 146
 				$firstCol=false;
147 147
 			}
148
-			$htm .= "<tr>\n";
148
+			$htm.="<tr>\n";
149 149
 		}
150
-		$htm .= "</tbody></table>\n";
150
+		$htm.="</tbody></table>\n";
151 151
 		//$htm .= "Filter : " . $this->filter."<br>\n";
152 152
 		return $htm;
153 153
 
@@ -155,14 +155,14 @@  discard block
 block discarded – undo
155 155
 
156 156
     public function count()
157 157
     {
158
-        $db = $this->connection()->getConnection();
159
-        $query = clone($this->getBaseQuery());
158
+        $db=$this->connection()->getConnection();
159
+        $query=clone($this->getBaseQuery());
160 160
         $query->reset('order')->columns(array('COUNT(*)'));
161 161
         $this->applyFiltersToQuery($query);
162 162
 
163 163
 		$db=$this->db();
164 164
 		
165
-		$query = $db->select()->from(
165
+		$query=$db->select()->from(
166 166
             $this->moduleConfig->getTrapRuleName(),
167 167
             array('COUNT(*)')
168 168
         );
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 	
173 173
     public function getPaginator()
174 174
     {
175
-        $paginator = new Paginator();
175
+        $paginator=new Paginator();
176 176
         $paginator->setQuery($this);
177 177
 
178 178
         return $paginator;
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 	{
185 185
 		$db=$this->db();
186 186
 		
187
-		$query = $this->getBaseQuery();
187
+		$query=$this->getBaseQuery();
188 188
 		
189 189
        if ($this->hasLimit() || $this->hasOffset()) {
190 190
             $query->limit($this->getLimit(), $this->getOffset());
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
     {
198 198
 		$db=$this->db();
199 199
 		
200
-		$query = $db->select()->from(
200
+		$query=$db->select()->from(
201 201
             $this->moduleConfig->getTrapRuleName(),
202 202
             $this->moduleConfig->getHandlerListDisplayColumns()
203 203
         )->order('host_name DESC,trap_oid DESC');
@@ -219,20 +219,20 @@  discard block
 block discarded – undo
219 219
 
220 220
     public function setFilter($filter)
221 221
     {
222
-        $this->filter = $filter;
222
+        $this->filter=$filter;
223 223
         return $this;
224 224
     }
225 225
 	
226 226
 	public function getFilterEditor(Request $request)
227 227
     {
228
-        $filterEditor = Widget::create('filterEditor')
228
+        $filterEditor=Widget::create('filterEditor')
229 229
             ->setColumns(array_keys($this->getColumns()))
230 230
             ->setSearchColumns(array_keys($this->getSearchColumns()))
231 231
             ->preserveParams('limit', 'sort', 'dir', 'view', 'backend')
232 232
             ->ignoreParams('page')
233 233
             ->handleRequest($request);
234 234
 
235
-        $filter = $filterEditor->getFilter();
235
+        $filter=$filterEditor->getFilter();
236 236
         $this->setFilter($filter);
237 237
 
238 238
         return $filterEditor;
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -99,13 +99,11 @@  discard block
 block discarded – undo
99 99
 								if (isset($oidName['name']))
100 100
 								{
101 101
 									$val=$oidName['name'];
102
-								}
103
-								else
102
+								} else
104 103
 								{
105 104
 									$val = $row->$rowkey;
106 105
 								}								
107
-							}
108
-							else
106
+							} else
109 107
 							{
110 108
 								$val = $row->$rowkey;
111 109
 							}
@@ -114,8 +112,7 @@  discard block
 block discarded – undo
114 112
 							if ($row->$rowkey == null)
115 113
 							{
116 114
 								$val = $row->host_group_name;
117
-							}
118
-							else
115
+							} else
119 116
 							{
120 117
 								$val = $row->$rowkey;
121 118
 							}
Please login to merge, or discard this patch.
library/Trapdirector/Tables/TrapTableList.php 3 patches
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -20,9 +20,9 @@  discard block
 block discarded – undo
20 20
 	
21 21
 	// Filters 
22 22
 	
23
-    protected $filter;
24
-    protected $enforcedFilters = array();
25
-    protected $searchColumns = array();
23
+	protected $filter;
24
+	protected $enforcedFilters = array();
25
+	protected $searchColumns = array();
26 26
 	
27 27
 	protected function getTitles() {
28 28
 		// TODO : check moduleconfig is set
@@ -30,10 +30,10 @@  discard block
 block discarded – undo
30 30
 	}
31 31
 		
32 32
 	// ******************  Render table in html  
33
-    public function __toString()
34
-    {
35
-        return $this->render();
36
-    }
33
+	public function __toString()
34
+	{
35
+		return $this->render();
36
+	}
37 37
 	
38 38
 	public function render()
39 39
 	{
@@ -97,26 +97,26 @@  discard block
 block discarded – undo
97 97
 
98 98
 	}
99 99
 
100
-    public function count()
101
-    {
102
-        $db=$this->db();
100
+	public function count()
101
+	{
102
+		$db=$this->db();
103 103
 		
104 104
 		$query = $db->select()->from(
105
-            $this->moduleConfig->getTrapTableName(),
106
-            array('COUNT(*)')
107
-        );
105
+			$this->moduleConfig->getTrapTableName(),
106
+			array('COUNT(*)')
107
+		);
108 108
 		$this->applyFiltersToQuery($query);
109 109
 		
110
-        return $db->fetchOne($query);
111
-    }
110
+		return $db->fetchOne($query);
111
+	}
112 112
 	
113
-    public function getPaginator()
114
-    {
115
-        $paginator = new Paginator();
116
-        $paginator->setQuery($this);
113
+	public function getPaginator()
114
+	{
115
+		$paginator = new Paginator();
116
+		$paginator->setQuery($this);
117 117
 
118
-        return $paginator;
119
-    }
118
+		return $paginator;
119
+	}
120 120
 	
121 121
 	// ****************** DB connection and query
122 122
 	
@@ -126,24 +126,24 @@  discard block
 block discarded – undo
126 126
 		
127 127
 		$query = $this->getBaseQuery();
128 128
 		$this->applyFiltersToQuery($query);
129
-       if ($this->hasLimit() || $this->hasOffset()) {
130
-            $query->limit($this->getLimit(), $this->getOffset());
131
-        }		
129
+	   if ($this->hasLimit() || $this->hasOffset()) {
130
+			$query->limit($this->getLimit(), $this->getOffset());
131
+		}		
132 132
 		
133 133
 		return $db->fetchAll($query);
134 134
 	}
135 135
 	 
136
-    public function getBaseQuery()
137
-    {
136
+	public function getBaseQuery()
137
+	{
138 138
 		$db=$this->db();
139 139
 		
140 140
 		$query = $db->select()->from(
141
-            $this->moduleConfig->getTrapTableName(),
142
-            $this->moduleConfig->getTrapListDisplayColumns()
143
-        )->order('timestamp DESC');
141
+			$this->moduleConfig->getTrapTableName(),
142
+			$this->moduleConfig->getTrapListDisplayColumns()
143
+		)->order('timestamp DESC');
144 144
 
145
-        return $query;
146
-    }	 
145
+		return $query;
146
+	}	 
147 147
 	
148 148
 	// ****************** Filters
149 149
 
@@ -173,39 +173,39 @@  discard block
 block discarded – undo
173 173
 		$this->filter_done=(isset($filter['done']))?$this->filter_done=$filter['done']:0;
174 174
 	}
175 175
 	
176
-    protected function getSearchColumns()
177
-    {
178
-        return $this->getColumns();
179
-    }
176
+	protected function getSearchColumns()
177
+	{
178
+		return $this->getColumns();
179
+	}
180 180
 	
181 181
 	public function getColumns()
182 182
 	{
183 183
 		return $this->moduleConfig->getTrapListDisplayColumns();
184 184
 	}
185 185
 
186
-    public function setFilter($filter)
187
-    {
188
-        $this->filter = $filter;
189
-        return $this;
190
-    }
186
+	public function setFilter($filter)
187
+	{
188
+		$this->filter = $filter;
189
+		return $this;
190
+	}
191 191
 	
192 192
 	public function getFilterEditor(Request $request)
193
-    {
194
-        $filterEditor = Widget::create('filterEditor')
195
-            ->setColumns(array_keys($this->getColumns()))
196
-            ->setSearchColumns(array_keys($this->getSearchColumns()))
197
-            ->preserveParams('limit', 'sort', 'dir', 'view', 'backend')
198
-            ->ignoreParams('page')
199
-            ->handleRequest($request);
200
-
201
-        $filter = $filterEditor->getFilter();
202
-        $this->setFilter($filter);
203
-
204
-        return $filterEditor;
205
-    }
193
+	{
194
+		$filterEditor = Widget::create('filterEditor')
195
+			->setColumns(array_keys($this->getColumns()))
196
+			->setSearchColumns(array_keys($this->getSearchColumns()))
197
+			->preserveParams('limit', 'sort', 'dir', 'view', 'backend')
198
+			->ignoreParams('page')
199
+			->handleRequest($request);
200
+
201
+		$filter = $filterEditor->getFilter();
202
+		$this->setFilter($filter);
203
+
204
+		return $filterEditor;
205
+	}
206 206
 	
207
-    protected function applyFiltersToQuery($query)
208
-    {
207
+	protected function applyFiltersToQuery($query)
208
+	{
209 209
 		
210 210
 		$sql='';
211 211
 		if ($this->filter_query != '')
@@ -226,8 +226,8 @@  discard block
 block discarded – undo
226 226
 			$sql.="(status != 'done')";
227 227
 		}
228 228
 		if ($sql != '') $query->where($sql);		
229
-        return $query;
230
-    }	
229
+		return $query;
230
+	}	
231 231
 
232 232
 }
233 233
 
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
21 21
 	// Filters 
22 22
 	
23 23
     protected $filter;
24
-    protected $enforcedFilters = array();
25
-    protected $searchColumns = array();
24
+    protected $enforcedFilters=array();
25
+    protected $searchColumns=array();
26 26
 	
27 27
 	protected function getTitles() {
28 28
 		// TODO : check moduleconfig is set
@@ -38,60 +38,60 @@  discard block
 block discarded – undo
38 38
 	public function render()
39 39
 	{
40 40
 		$data=$this->getTable();
41
-		$view = $this->getView();
42
-		$this->columnCount = count($this->getTitles());
41
+		$view=$this->getView();
42
+		$this->columnCount=count($this->getTitles());
43 43
 		$this->lastDay=null;
44 44
 		// Table start
45
-		$htm  = '<table class="simple common-table table-row-selectable">';
45
+		$htm='<table class="simple common-table table-row-selectable">';
46 46
 		
47 47
 		// Titles
48
-		$htm .= "<thead>\n  <tr>\n";
49
-		$titles = $this->getTitles();
48
+		$htm.="<thead>\n  <tr>\n";
49
+		$titles=$this->getTitles();
50 50
 		foreach ($titles as $title) 
51 51
 		{
52
-			$htm .= '    <th>' . $view->escape($view->translate($title)) . "</th>\n";
52
+			$htm.='    <th>'.$view->escape($view->translate($title))."</th>\n";
53 53
 		}
54
-		$htm .= "  </tr>\n</thead>\n";
54
+		$htm.="  </tr>\n</thead>\n";
55 55
 		
56 56
 		// Rows
57
-		$htm .= "<tbody>\n";
57
+		$htm.="<tbody>\n";
58 58
 		
59 59
 		foreach ($data as $row) 
60 60
 		{
61
-			$firstCol = true;
61
+			$firstCol=true;
62 62
 			// Put date header
63
-			$htm .= $this->renderDayIfNew($row->timestamp);
63
+			$htm.=$this->renderDayIfNew($row->timestamp);
64 64
 			
65 65
 			
66 66
 			// Render row
67
-			$htm .= '<tr '.' >';
68
-			foreach ( $titles as $rowkey => $title) 
67
+			$htm.='<tr '.' >';
68
+			foreach ($titles as $rowkey => $title) 
69 69
 			{
70 70
 				// Check missing value
71 71
 				if (property_exists($row, $rowkey)) 
72 72
 				{
73
-					$val = ($rowkey=='timestamp') ?  strftime('%T',$row->$rowkey) : $row->$rowkey;
73
+					$val=($rowkey == 'timestamp') ?  strftime('%T', $row->$rowkey) : $row->$rowkey;
74 74
 				} else {
75
-					$val = '-';
75
+					$val='-';
76 76
 				}
77 77
 				if ($firstCol == true) { // Put link in first column for trap detail.
78
-					$htm .= '<td>' 
78
+					$htm.='<td>' 
79 79
 							. $view->qlink(
80 80
 									$view->escape($val),  
81 81
 									Url::fromPath(
82
-										$this->moduleConfig->urlPath() . '/received/trapdetail', 
82
+										$this->moduleConfig->urlPath().'/received/trapdetail', 
83 83
 										array('id' => $row->id)
84 84
 									)
85 85
 							)
86 86
 							. '</td>';
87 87
 				} else {
88
-					$htm .= '<td>' . $view->escape($val) . '</td>';
88
+					$htm.='<td>'.$view->escape($val).'</td>';
89 89
 				}
90 90
 				$firstCol=false;
91 91
 			}
92
-			$htm .= "<tr>\n";
92
+			$htm.="<tr>\n";
93 93
 		}
94
-		$htm .= "</tbody></table>\n";
94
+		$htm.="</tbody></table>\n";
95 95
 		//$htm .= "Filter : " . $this->filter."<br>\n";
96 96
 		return $htm;
97 97
 
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
     {
102 102
         $db=$this->db();
103 103
 		
104
-		$query = $db->select()->from(
104
+		$query=$db->select()->from(
105 105
             $this->moduleConfig->getTrapTableName(),
106 106
             array('COUNT(*)')
107 107
         );
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 	
113 113
     public function getPaginator()
114 114
     {
115
-        $paginator = new Paginator();
115
+        $paginator=new Paginator();
116 116
         $paginator->setQuery($this);
117 117
 
118 118
         return $paginator;
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 	{
125 125
 		$db=$this->db();
126 126
 		
127
-		$query = $this->getBaseQuery();
127
+		$query=$this->getBaseQuery();
128 128
 		$this->applyFiltersToQuery($query);
129 129
        if ($this->hasLimit() || $this->hasOffset()) {
130 130
             $query->limit($this->getLimit(), $this->getOffset());
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
     {
138 138
 		$db=$this->db();
139 139
 		
140
-		$query = $db->select()->from(
140
+		$query=$db->select()->from(
141 141
             $this->moduleConfig->getTrapTableName(),
142 142
             $this->moduleConfig->getTrapListDisplayColumns()
143 143
         )->order('timestamp DESC');
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 	protected $filter_Handler;
151 151
 	protected $filter_query='';
152 152
 	protected $filter_done='';
153
-	protected $filter_query_list=array('q','done');
153
+	protected $filter_query_list=array('q', 'done');
154 154
 	public function renderFilterHTML()
155 155
 	{
156 156
 		$htm=' <form id="filter" name="mainFilter" 
@@ -160,17 +160,17 @@  discard block
 block discarded – undo
160 160
 		$htm.='<input type="text" name="q" title="Search is simple! Try to combine multiple words" 
161 161
 		placeholder="Search..." class="search" value="'.$this->filter_query.'">';
162 162
 		$htm.='<input type="checkbox" id="checkbox_done" name="done" value="1" class="autosubmit" ';
163
-		if	($this->filter_done == 1) { $htm.=' checked ';}
163
+		if ($this->filter_done == 1) { $htm.=' checked '; }
164 164
 		$htm.='> <label for="checkbox_done">Hide processed traps</label>';
165 165
 		$htm.='</form>';
166 166
 		return $htm;
167 167
 	}
168 168
 	
169
-	public function updateFilter($handler,$filter)
169
+	public function updateFilter($handler, $filter)
170 170
 	{
171 171
 		$this->filter_Handler=$handler->remove($this->filter_query_list)->__toString();
172
-		$this->filter_query=(isset($filter['q']))?$this->filter_query=$filter['q']:'';
173
-		$this->filter_done=(isset($filter['done']))?$this->filter_done=$filter['done']:0;
172
+		$this->filter_query=(isset($filter['q'])) ? $this->filter_query=$filter['q'] : '';
173
+		$this->filter_done=(isset($filter['done'])) ? $this->filter_done=$filter['done'] : 0;
174 174
 	}
175 175
 	
176 176
     protected function getSearchColumns()
@@ -185,20 +185,20 @@  discard block
 block discarded – undo
185 185
 
186 186
     public function setFilter($filter)
187 187
     {
188
-        $this->filter = $filter;
188
+        $this->filter=$filter;
189 189
         return $this;
190 190
     }
191 191
 	
192 192
 	public function getFilterEditor(Request $request)
193 193
     {
194
-        $filterEditor = Widget::create('filterEditor')
194
+        $filterEditor=Widget::create('filterEditor')
195 195
             ->setColumns(array_keys($this->getColumns()))
196 196
             ->setSearchColumns(array_keys($this->getSearchColumns()))
197 197
             ->preserveParams('limit', 'sort', 'dir', 'view', 'backend')
198 198
             ->ignoreParams('page')
199 199
             ->handleRequest($request);
200 200
 
201
-        $filter = $filterEditor->getFilter();
201
+        $filter=$filterEditor->getFilter();
202 202
         $this->setFilter($filter);
203 203
 
204 204
         return $filterEditor;
@@ -212,9 +212,9 @@  discard block
 block discarded – undo
212 212
 		{
213 213
 			$sql.='(';
214 214
 			$first=1;
215
-			foreach($this->moduleConfig->getTrapListSearchColumns() as $column)
215
+			foreach ($this->moduleConfig->getTrapListSearchColumns() as $column)
216 216
 			{
217
-				if ($first==0) $sql.=' OR ';
217
+				if ($first == 0) $sql.=' OR ';
218 218
 				$first=0;
219 219
 				$sql.=" CAST(".$column." AS  char(100))  LIKE  '%".$this->filter_query."%' ";
220 220
 			}
Please login to merge, or discard this patch.
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -214,7 +214,9 @@  discard block
 block discarded – undo
214 214
 			$first=1;
215 215
 			foreach($this->moduleConfig->getTrapListSearchColumns() as $column)
216 216
 			{
217
-				if ($first==0) $sql.=' OR ';
217
+				if ($first==0) {
218
+					$sql.=' OR ';
219
+				}
218 220
 				$first=0;
219 221
 				$sql.=" CAST(".$column." AS  char(100))  LIKE  '%".$this->filter_query."%' ";
220 222
 			}
@@ -222,10 +224,14 @@  discard block
 block discarded – undo
222 224
 		}
223 225
 		if ($this->filter_done == 1)
224 226
 		{
225
-			if ($sql != '') $sql.=' AND ';
227
+			if ($sql != '') {
228
+				$sql.=' AND ';
229
+			}
226 230
 			$sql.="(status != 'done')";
227 231
 		}
228
-		if ($sql != '') $query->where($sql);		
232
+		if ($sql != '') {
233
+			$query->where($sql);
234
+		}
229 235
         return $query;
230 236
     }	
231 237
 
Please login to merge, or discard this patch.
library/Trapdirector/Icinga2Api.php 3 patches
Indentation   +329 added lines, -329 removed lines patch added patch discarded remove patch
@@ -8,360 +8,360 @@
 block discarded – undo
8 8
 
9 9
 class Icinga2API 
10 10
 {
11
-    protected $version = 'v1';      //< icinga2 api version
11
+	protected $version = 'v1';      //< icinga2 api version
12 12
     
13
-    protected $host;                //< icinga2 host name or IP
14
-    protected $port;                //< icinga2 api port
13
+	protected $host;                //< icinga2 host name or IP
14
+	protected $port;                //< icinga2 api port
15 15
     
16
-    protected $user;                //< user name
17
-    protected $pass;                //< user password
18
-    protected $usercert;            //< user key for certificate auth (NOT IMPLEMENTED)
19
-    protected $authmethod='pass';   //< Authentication : 'pass' or 'cert'
16
+	protected $user;                //< user name
17
+	protected $pass;                //< user password
18
+	protected $usercert;            //< user key for certificate auth (NOT IMPLEMENTED)
19
+	protected $authmethod='pass';   //< Authentication : 'pass' or 'cert'
20 20
 
21
-    protected $curl;
22
-    // http://php.net/manual/de/function.json-last-error.php#119985
23
-    protected $errorReference = [
24
-        JSON_ERROR_NONE => 'No error has occurred.',
25
-        JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.',
26
-        JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.',
27
-        JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded.',
28
-        JSON_ERROR_SYNTAX => 'Syntax error.',
29
-        JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded.',
30
-        JSON_ERROR_RECURSION => 'One or more recursive references in the value to be encoded.',
31
-        JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded.',
32
-        JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given.',
33
-    ];
34
-    const JSON_UNKNOWN_ERROR = 'Unknown error.';
21
+	protected $curl;
22
+	// http://php.net/manual/de/function.json-last-error.php#119985
23
+	protected $errorReference = [
24
+		JSON_ERROR_NONE => 'No error has occurred.',
25
+		JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.',
26
+		JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.',
27
+		JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded.',
28
+		JSON_ERROR_SYNTAX => 'Syntax error.',
29
+		JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded.',
30
+		JSON_ERROR_RECURSION => 'One or more recursive references in the value to be encoded.',
31
+		JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded.',
32
+		JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given.',
33
+	];
34
+	const JSON_UNKNOWN_ERROR = 'Unknown error.';
35 35
     
36
-    /**
37
-     * Creates Icinga2API object
38
-     * 
39
-     * @param string $host host name or IP
40
-     * @param number $port API port
41
-     */
42
-    public function __construct($host, $port = 5665)
43
-    {
44
-        $this->host=$host;
45
-        $this->port=$port;
46
-    }
47
-    /**
48
-     * Set user & pass
49
-     * @param string $user
50
-     * @param string $pass
51
-     */
52
-    public function setCredentials($user,$pass)
53
-    {
54
-        $this->user=$user;
55
-        $this->pass=$pass;
56
-        $this->authmethod='pass';
57
-    }
36
+	/**
37
+	 * Creates Icinga2API object
38
+	 * 
39
+	 * @param string $host host name or IP
40
+	 * @param number $port API port
41
+	 */
42
+	public function __construct($host, $port = 5665)
43
+	{
44
+		$this->host=$host;
45
+		$this->port=$port;
46
+	}
47
+	/**
48
+	 * Set user & pass
49
+	 * @param string $user
50
+	 * @param string $pass
51
+	 */
52
+	public function setCredentials($user,$pass)
53
+	{
54
+		$this->user=$user;
55
+		$this->pass=$pass;
56
+		$this->authmethod='pass';
57
+	}
58 58
     
59
-    /**
60
-     * Set user & certificate (NOT IMPLEMENTED @throws RuntimeException)
61
-     * @param string $user
62
-     * @param string $usercert
63
-     */
64
-    public function setCredentialskey($user,$usercert)
65
-    {
66
-        $this->user=$user;
67
-        $this->usercert=$usercert;
68
-        $this->authmethod='cert';
69
-        throw new RuntimeException('Certificate auth not implemented');
70
-    }
59
+	/**
60
+	 * Set user & certificate (NOT IMPLEMENTED @throws RuntimeException)
61
+	 * @param string $user
62
+	 * @param string $usercert
63
+	 */
64
+	public function setCredentialskey($user,$usercert)
65
+	{
66
+		$this->user=$user;
67
+		$this->usercert=$usercert;
68
+		$this->authmethod='cert';
69
+		throw new RuntimeException('Certificate auth not implemented');
70
+	}
71 71
 
72
-    public function test(array $permissions)
73
-    {
74
-       try
75
-        {
76
-            $result=$this->request('GET', "", NULL, NULL);
77
-        } catch (Exception $e)
78
-        {
79
-            return array(true, 'Error with API : '.$e->getMessage());
80
-        }
81
-        //var_dump($result);
82
-        $permOk=1;
83
-        $permMissing='';
84
-        if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions'))
85
-        {
72
+	public function test(array $permissions)
73
+	{
74
+	   try
75
+		{
76
+			$result=$this->request('GET', "", NULL, NULL);
77
+		} catch (Exception $e)
78
+		{
79
+			return array(true, 'Error with API : '.$e->getMessage());
80
+		}
81
+		//var_dump($result);
82
+		$permOk=1;
83
+		$permMissing='';
84
+		if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions'))
85
+		{
86 86
             
87
-            foreach ( $permissions as $mustPermission)
88
-            {
89
-                $curPermOK=0;
90
-                foreach ( $result->results[0]->permissions as $curPermission)
91
-                {
92
-                    $curPermission=preg_replace('/\*/','.*',$curPermission); // put * as .* to created a regexp
93
-                    if (preg_match('#'.$curPermission.'#',$mustPermission))
94
-                    {
95
-                        $curPermOK=1;
96
-                        break;
97
-                    }
98
-                }
99
-                if ($curPermOK == 0)
100
-                {
101
-                    $permOk=0;
102
-                    $permMissing=$mustPermission;
103
-                    break;
104
-                }
105
-            }
106
-            if ($permOk == 0)
107
-            {
108
-                return array(true,'API connection OK, but missing permission : '.$permMissing);
109
-            }
110
-            return array(false,'API connection OK');
87
+			foreach ( $permissions as $mustPermission)
88
+			{
89
+				$curPermOK=0;
90
+				foreach ( $result->results[0]->permissions as $curPermission)
91
+				{
92
+					$curPermission=preg_replace('/\*/','.*',$curPermission); // put * as .* to created a regexp
93
+					if (preg_match('#'.$curPermission.'#',$mustPermission))
94
+					{
95
+						$curPermOK=1;
96
+						break;
97
+					}
98
+				}
99
+				if ($curPermOK == 0)
100
+				{
101
+					$permOk=0;
102
+					$permMissing=$mustPermission;
103
+					break;
104
+				}
105
+			}
106
+			if ($permOk == 0)
107
+			{
108
+				return array(true,'API connection OK, but missing permission : '.$permMissing);
109
+			}
110
+			return array(false,'API connection OK');
111 111
             
112
-        }
113
-        return array(true,'API connection OK, but cannot get permissions');
114
-    }
112
+		}
113
+		return array(true,'API connection OK, but cannot get permissions');
114
+	}
115 115
     
116 116
     
117
-    protected function url($url) {
118
-        return sprintf('https://%s:%d/%s/%s', $this->host, $this->port, $this->version, $url);
119
-    }
117
+	protected function url($url) {
118
+		return sprintf('https://%s:%d/%s/%s', $this->host, $this->port, $this->version, $url);
119
+	}
120 120
     
121
-    /**
122
-     * Create or return curl ressource
123
-     * @throws Exception
124
-     * @return resource
125
-     */
126
-    protected function curl() {
127
-        if ($this->curl === null) {
128
-            $this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port));
129
-            if (!$this->curl) {
130
-                throw new Exception('CURL INIT ERROR: ' . curl_error($this->curl));
131
-            }
132
-        }
133
-        return $this->curl;
134
-    }
121
+	/**
122
+	 * Create or return curl ressource
123
+	 * @throws Exception
124
+	 * @return resource
125
+	 */
126
+	protected function curl() {
127
+		if ($this->curl === null) {
128
+			$this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port));
129
+			if (!$this->curl) {
130
+				throw new Exception('CURL INIT ERROR: ' . curl_error($this->curl));
131
+			}
132
+		}
133
+		return $this->curl;
134
+	}
135 135
 
136
-    /**
137
-     * Send a passive service check
138
-     * @param string $host : host name 
139
-     * @param string $service : service name
140
-     * @param int $state : state of service
141
-     * @param string $display : service passive check output
142
-     * @return array (status = true (oK) or false (nok), string message)
143
-     */
144
-    public function serviceCheckResult($host,$service,$state,$display)
145
-    {
146
-        //Send a POST request to the URL endpoint /v1/actions/process-check-result
147
-        //actions/process-check-result?service=example.localdomain!passive-ping6
148
-        $url='actions/process-check-result';
149
-        $body=array(
150
-            "filter"        => 'service.name=="'.$service.'" && service.host_name=="'.$host.'"',
151
-            'type'          => 'Service',
152
-            "exit_status"   => $state,
153
-            "plugin_output" => $display
154
-        );
155
-        try 
156
-        {
157
-            $result=$this->request('POST', $url, null, $body);
158
-        } catch (Exception $e) 
159
-        {
160
-            return array(false, $e->getMessage());
161
-        }
162
-        if (property_exists($result,'error') )
163
-        {
164
-            if (property_exists($result,'status'))
165
-            {
166
-                $message=$result->status;
167
-            }
168
-            else 
169
-            {
170
-                $message="Unkown status";
171
-            }
172
-            return array(false , 'Ret code ' .$result->error.' : '.$message);
173
-        }
174
-        if (property_exists($result, 'results'))
175
-        {
176
-            if (isset($result->results[0]))
177
-            {
178
-                return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status);
179
-            }
180
-            else
181
-            {
182
-                return array(false,'Service not found');
183
-            }
136
+	/**
137
+	 * Send a passive service check
138
+	 * @param string $host : host name 
139
+	 * @param string $service : service name
140
+	 * @param int $state : state of service
141
+	 * @param string $display : service passive check output
142
+	 * @return array (status = true (oK) or false (nok), string message)
143
+	 */
144
+	public function serviceCheckResult($host,$service,$state,$display)
145
+	{
146
+		//Send a POST request to the URL endpoint /v1/actions/process-check-result
147
+		//actions/process-check-result?service=example.localdomain!passive-ping6
148
+		$url='actions/process-check-result';
149
+		$body=array(
150
+			"filter"        => 'service.name=="'.$service.'" && service.host_name=="'.$host.'"',
151
+			'type'          => 'Service',
152
+			"exit_status"   => $state,
153
+			"plugin_output" => $display
154
+		);
155
+		try 
156
+		{
157
+			$result=$this->request('POST', $url, null, $body);
158
+		} catch (Exception $e) 
159
+		{
160
+			return array(false, $e->getMessage());
161
+		}
162
+		if (property_exists($result,'error') )
163
+		{
164
+			if (property_exists($result,'status'))
165
+			{
166
+				$message=$result->status;
167
+			}
168
+			else 
169
+			{
170
+				$message="Unkown status";
171
+			}
172
+			return array(false , 'Ret code ' .$result->error.' : '.$message);
173
+		}
174
+		if (property_exists($result, 'results'))
175
+		{
176
+			if (isset($result->results[0]))
177
+			{
178
+				return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status);
179
+			}
180
+			else
181
+			{
182
+				return array(false,'Service not found');
183
+			}
184 184
             
185
-        }
186
-        return array(false,'Unkown result, open issue with this : '.print_r($result,true));
187
-    }
185
+		}
186
+		return array(false,'Unkown result, open issue with this : '.print_r($result,true));
187
+	}
188 188
  
189
-    /**
190
-     * return array of host by IP (4 or 6)
191
-     * @param string $ip
192
-     * @throws Exception
193
-     * @return array objects : array('__name','name','display_name')
194
-     */
195
-    public function getHostByIP($ip) 
196
-    {
197
-        /*
189
+	/**
190
+	 * return array of host by IP (4 or 6)
191
+	 * @param string $ip
192
+	 * @throws Exception
193
+	 * @return array objects : array('__name','name','display_name')
194
+	 */
195
+	public function getHostByIP($ip) 
196
+	{
197
+		/*
198 198
          *  curl -k -s -u  trapdirector:trapdirector -H 'X-HTTP-Method-Override: GET' -X POST 'https://localhost:5665/v1/objects/hosts' 
199 199
          *  -d '{"filter":"host.group==\"test_trap\"","attrs": ["address" ,"address6"]}'
200 200
             
201 201
             {"results":[{"attrs":{"__name":"Icinga host","address":"127.0.0.1","display_name":"Icinga host","name":"Icinga host"},"joins":{},"meta":{},"name":"Icinga host","type":"Host"}]}
202 202
          */
203 203
         
204
-        $url='objects/hosts';
205
-        $body=array(
206
-            "filter"        => 'host.address=="'.$ip.'" || host.address6=="'.$ip.'"',
207
-            "attrs"         => array('__name','name','display_name')
208
-        );
209
-        try
210
-        {
211
-            $result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body);
212
-        } catch (Exception $e)
213
-        {
214
-            throw new Exception($e->getMessage());
215
-        }
204
+		$url='objects/hosts';
205
+		$body=array(
206
+			"filter"        => 'host.address=="'.$ip.'" || host.address6=="'.$ip.'"',
207
+			"attrs"         => array('__name','name','display_name')
208
+		);
209
+		try
210
+		{
211
+			$result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body);
212
+		} catch (Exception $e)
213
+		{
214
+			throw new Exception($e->getMessage());
215
+		}
216 216
         
217
-        if (property_exists($result,'error') )
218
-        {
219
-            if (property_exists($result,'status'))
220
-            {
221
-                throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
222
-            }
223
-            else
224
-            {
225
-                throw new Exception('Ret code ' .$result->error.' : Unkown status');
226
-            }
227
-        }
228
-        if (property_exists($result, 'results'))
229
-        {
230
-            $numHost=0;
231
-            $hostArray=array();
232
-            while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
233
-            {
234
-                $hostArray[$numHost] = $result->results[$numHost]->attrs;
235
-                $numHost++;
236
-            }
237
-            return $hostArray;            
238
-        }
239
-        throw new Exception('Unkown result');
240
-    }
217
+		if (property_exists($result,'error') )
218
+		{
219
+			if (property_exists($result,'status'))
220
+			{
221
+				throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
222
+			}
223
+			else
224
+			{
225
+				throw new Exception('Ret code ' .$result->error.' : Unkown status');
226
+			}
227
+		}
228
+		if (property_exists($result, 'results'))
229
+		{
230
+			$numHost=0;
231
+			$hostArray=array();
232
+			while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
233
+			{
234
+				$hostArray[$numHost] = $result->results[$numHost]->attrs;
235
+				$numHost++;
236
+			}
237
+			return $hostArray;            
238
+		}
239
+		throw new Exception('Unkown result');
240
+	}
241 241
 
242
-    /**
243
-     * Get all host and IP from hostgroup
244
-     * @param string $hostGroup
245
-     * @throws Exception
246
-     * @return array : attributes : address, address6, name
247
-     */
248
-    public function getHostsIPByHostGroup($hostGroup)
249
-    {        
250
-        $url='objects/hosts';
251
-        $body=array(
252
-            "filter"        => '\"'.$hostGroup.'\" in host.groups',
253
-            "attrs"         => array('address','address','name')
254
-        );
255
-        try
256
-        {
257
-            $result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body);
258
-        } catch (Exception $e)
259
-        {
260
-            throw new Exception($e->getMessage());
261
-        }
242
+	/**
243
+	 * Get all host and IP from hostgroup
244
+	 * @param string $hostGroup
245
+	 * @throws Exception
246
+	 * @return array : attributes : address, address6, name
247
+	 */
248
+	public function getHostsIPByHostGroup($hostGroup)
249
+	{        
250
+		$url='objects/hosts';
251
+		$body=array(
252
+			"filter"        => '\"'.$hostGroup.'\" in host.groups',
253
+			"attrs"         => array('address','address','name')
254
+		);
255
+		try
256
+		{
257
+			$result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body);
258
+		} catch (Exception $e)
259
+		{
260
+			throw new Exception($e->getMessage());
261
+		}
262 262
         
263
-        if (property_exists($result,'error') )
264
-        {
265
-            if (property_exists($result,'status'))
266
-            {
267
-                throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
268
-            }
269
-            else
270
-            {
271
-                throw new Exception('Ret code ' .$result->error.' : Unkown status');
272
-            }
273
-        }
274
-        if (property_exists($result, 'results'))
275
-        {
276
-            $numHost=0;
277
-            $hostArray=array();
278
-            while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
279
-            {
280
-                $hostArray[$numHost] = $result->results[$numHost]->attrs;
281
-                $hostArray[$numHost]->name = $result->results[$numHost]->name;
282
-                $numHost++;
283
-            }
284
-            return $hostArray;
285
-        }
286
-        throw new Exception('Unkown result');
287
-    }
263
+		if (property_exists($result,'error') )
264
+		{
265
+			if (property_exists($result,'status'))
266
+			{
267
+				throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
268
+			}
269
+			else
270
+			{
271
+				throw new Exception('Ret code ' .$result->error.' : Unkown status');
272
+			}
273
+		}
274
+		if (property_exists($result, 'results'))
275
+		{
276
+			$numHost=0;
277
+			$hostArray=array();
278
+			while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
279
+			{
280
+				$hostArray[$numHost] = $result->results[$numHost]->attrs;
281
+				$hostArray[$numHost]->name = $result->results[$numHost]->name;
282
+				$numHost++;
283
+			}
284
+			return $hostArray;
285
+		}
286
+		throw new Exception('Unkown result');
287
+	}
288 288
     
289
-    /**
290
-     * Send request to API
291
-     * @param string $method get/post/...
292
-     * @param string $url (after /v1/ )
293
-     * @param array $headers
294
-     * @param array $body 
295
-     * @throws Exception
296
-     * @return array
297
-     */
298
-    public function request($method, $url, $headers, $body) {
299
-        $auth = sprintf('%s:%s', $this->user, $this->pass);
300
-        $curlHeaders = array("Accept: application/json");
301
-        if ($body !== null) {
302
-            $body = json_encode($body);
303
-            array_push($curlHeaders, 'Content-Type: application/json');
304
-            //array_push($curlHeaders, 'X-HTTP-Method-Override: GET');
305
-        }
306
-        //var_dump($body);
307
-        //var_dump($this->url($url));
308
-        if ($headers !== null) {
309
-            $curlFinalHeaders = array_merge($curlHeaders, $headers);
310
-        } else 
311
-        {
312
-            $curlFinalHeaders=$curlHeaders;
313
-        }
314
-        $curl = $this->curl();
315
-        $opts = array(
316
-            CURLOPT_URL		=> $this->url($url),
317
-            CURLOPT_HTTPHEADER 	=> $curlFinalHeaders,
318
-            CURLOPT_USERPWD		=> $auth,
319
-            CURLOPT_CUSTOMREQUEST	=> strtoupper($method),
320
-            CURLOPT_RETURNTRANSFER 	=> true,
321
-            CURLOPT_CONNECTTIMEOUT 	=> 10,
322
-            CURLOPT_SSL_VERIFYHOST 	=> false,
323
-            CURLOPT_SSL_VERIFYPEER 	=> false,
324
-        );
325
-        if ($body !== null) {
326
-            $opts[CURLOPT_POSTFIELDS] = $body;
327
-        }
328
-        curl_setopt_array($curl, $opts);
329
-        $res = curl_exec($curl);
330
-        if ($res === false) {
331
-            throw new Exception('CURL ERROR: ' . curl_error($curl));
332
-        }
333
-        $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
334
-        if ($statusCode === 401) {
335
-            throw new Exception('Unable to authenticate, please check your API credentials');
336
-        }
337
-        return $this->fromJsonResult($res);
338
-    }
289
+	/**
290
+	 * Send request to API
291
+	 * @param string $method get/post/...
292
+	 * @param string $url (after /v1/ )
293
+	 * @param array $headers
294
+	 * @param array $body 
295
+	 * @throws Exception
296
+	 * @return array
297
+	 */
298
+	public function request($method, $url, $headers, $body) {
299
+		$auth = sprintf('%s:%s', $this->user, $this->pass);
300
+		$curlHeaders = array("Accept: application/json");
301
+		if ($body !== null) {
302
+			$body = json_encode($body);
303
+			array_push($curlHeaders, 'Content-Type: application/json');
304
+			//array_push($curlHeaders, 'X-HTTP-Method-Override: GET');
305
+		}
306
+		//var_dump($body);
307
+		//var_dump($this->url($url));
308
+		if ($headers !== null) {
309
+			$curlFinalHeaders = array_merge($curlHeaders, $headers);
310
+		} else 
311
+		{
312
+			$curlFinalHeaders=$curlHeaders;
313
+		}
314
+		$curl = $this->curl();
315
+		$opts = array(
316
+			CURLOPT_URL		=> $this->url($url),
317
+			CURLOPT_HTTPHEADER 	=> $curlFinalHeaders,
318
+			CURLOPT_USERPWD		=> $auth,
319
+			CURLOPT_CUSTOMREQUEST	=> strtoupper($method),
320
+			CURLOPT_RETURNTRANSFER 	=> true,
321
+			CURLOPT_CONNECTTIMEOUT 	=> 10,
322
+			CURLOPT_SSL_VERIFYHOST 	=> false,
323
+			CURLOPT_SSL_VERIFYPEER 	=> false,
324
+		);
325
+		if ($body !== null) {
326
+			$opts[CURLOPT_POSTFIELDS] = $body;
327
+		}
328
+		curl_setopt_array($curl, $opts);
329
+		$res = curl_exec($curl);
330
+		if ($res === false) {
331
+			throw new Exception('CURL ERROR: ' . curl_error($curl));
332
+		}
333
+		$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
334
+		if ($statusCode === 401) {
335
+			throw new Exception('Unable to authenticate, please check your API credentials');
336
+		}
337
+		return $this->fromJsonResult($res);
338
+	}
339 339
     
340
-    /**
341
-     * 
342
-     * @param string $json json encoded 
343
-     * @throws Exception
344
-     * @return array json decoded
345
-     */
346
-    protected function fromJsonResult($json) {
347
-        $result = @json_decode($json);
348
-        //var_dump($json);
349
-        if ($result === null) {
350
-            throw new Exception('Parsing JSON failed: '.$this->getLastJsonErrorMessage(json_last_error()));
351
-        }
352
-        return $result;
353
-    }
340
+	/**
341
+	 * 
342
+	 * @param string $json json encoded 
343
+	 * @throws Exception
344
+	 * @return array json decoded
345
+	 */
346
+	protected function fromJsonResult($json) {
347
+		$result = @json_decode($json);
348
+		//var_dump($json);
349
+		if ($result === null) {
350
+			throw new Exception('Parsing JSON failed: '.$this->getLastJsonErrorMessage(json_last_error()));
351
+		}
352
+		return $result;
353
+	}
354 354
     
355
-    /**
356
-     * Return text error no json error
357
-     * @param string $errorCode
358
-     * @return string
359
-     */
360
-    protected function getLastJsonErrorMessage($errorCode) {
361
-        if (!array_key_exists($errorCode, $this->errorReference)) {
362
-            return self::JSON_UNKNOWN_ERROR;
363
-        }
364
-        return $this->errorReference[$errorCode];
365
-    }
355
+	/**
356
+	 * Return text error no json error
357
+	 * @param string $errorCode
358
+	 * @return string
359
+	 */
360
+	protected function getLastJsonErrorMessage($errorCode) {
361
+		if (!array_key_exists($errorCode, $this->errorReference)) {
362
+			return self::JSON_UNKNOWN_ERROR;
363
+		}
364
+		return $this->errorReference[$errorCode];
365
+	}
366 366
 }
367 367
 
Please login to merge, or discard this patch.
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -8,19 +8,19 @@  discard block
 block discarded – undo
8 8
 
9 9
 class Icinga2API 
10 10
 {
11
-    protected $version = 'v1';      //< icinga2 api version
11
+    protected $version='v1'; //< icinga2 api version
12 12
     
13
-    protected $host;                //< icinga2 host name or IP
14
-    protected $port;                //< icinga2 api port
13
+    protected $host; //< icinga2 host name or IP
14
+    protected $port; //< icinga2 api port
15 15
     
16
-    protected $user;                //< user name
17
-    protected $pass;                //< user password
18
-    protected $usercert;            //< user key for certificate auth (NOT IMPLEMENTED)
19
-    protected $authmethod='pass';   //< Authentication : 'pass' or 'cert'
16
+    protected $user; //< user name
17
+    protected $pass; //< user password
18
+    protected $usercert; //< user key for certificate auth (NOT IMPLEMENTED)
19
+    protected $authmethod='pass'; //< Authentication : 'pass' or 'cert'
20 20
 
21 21
     protected $curl;
22 22
     // http://php.net/manual/de/function.json-last-error.php#119985
23
-    protected $errorReference = [
23
+    protected $errorReference=[
24 24
         JSON_ERROR_NONE => 'No error has occurred.',
25 25
         JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.',
26 26
         JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.',
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
         JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded.',
32 32
         JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given.',
33 33
     ];
34
-    const JSON_UNKNOWN_ERROR = 'Unknown error.';
34
+    const JSON_UNKNOWN_ERROR='Unknown error.';
35 35
     
36 36
     /**
37 37
      * Creates Icinga2API object
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
      * @param string $host host name or IP
40 40
      * @param number $port API port
41 41
      */
42
-    public function __construct($host, $port = 5665)
42
+    public function __construct($host, $port=5665)
43 43
     {
44 44
         $this->host=$host;
45 45
         $this->port=$port;
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
      * @param string $user
50 50
      * @param string $pass
51 51
      */
52
-    public function setCredentials($user,$pass)
52
+    public function setCredentials($user, $pass)
53 53
     {
54 54
         $this->user=$user;
55 55
         $this->pass=$pass;
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
      * @param string $user
62 62
      * @param string $usercert
63 63
      */
64
-    public function setCredentialskey($user,$usercert)
64
+    public function setCredentialskey($user, $usercert)
65 65
     {
66 66
         $this->user=$user;
67 67
         $this->usercert=$usercert;
@@ -84,13 +84,13 @@  discard block
 block discarded – undo
84 84
         if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions'))
85 85
         {
86 86
             
87
-            foreach ( $permissions as $mustPermission)
87
+            foreach ($permissions as $mustPermission)
88 88
             {
89 89
                 $curPermOK=0;
90
-                foreach ( $result->results[0]->permissions as $curPermission)
90
+                foreach ($result->results[0]->permissions as $curPermission)
91 91
                 {
92
-                    $curPermission=preg_replace('/\*/','.*',$curPermission); // put * as .* to created a regexp
93
-                    if (preg_match('#'.$curPermission.'#',$mustPermission))
92
+                    $curPermission=preg_replace('/\*/', '.*', $curPermission); // put * as .* to created a regexp
93
+                    if (preg_match('#'.$curPermission.'#', $mustPermission))
94 94
                     {
95 95
                         $curPermOK=1;
96 96
                         break;
@@ -105,12 +105,12 @@  discard block
 block discarded – undo
105 105
             }
106 106
             if ($permOk == 0)
107 107
             {
108
-                return array(true,'API connection OK, but missing permission : '.$permMissing);
108
+                return array(true, 'API connection OK, but missing permission : '.$permMissing);
109 109
             }
110
-            return array(false,'API connection OK');
110
+            return array(false, 'API connection OK');
111 111
             
112 112
         }
113
-        return array(true,'API connection OK, but cannot get permissions');
113
+        return array(true, 'API connection OK, but cannot get permissions');
114 114
     }
115 115
     
116 116
     
@@ -125,9 +125,9 @@  discard block
 block discarded – undo
125 125
      */
126 126
     protected function curl() {
127 127
         if ($this->curl === null) {
128
-            $this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port));
128
+            $this->curl=curl_init(sprintf('https://%s:%d', $this->host, $this->port));
129 129
             if (!$this->curl) {
130
-                throw new Exception('CURL INIT ERROR: ' . curl_error($this->curl));
130
+                throw new Exception('CURL INIT ERROR: '.curl_error($this->curl));
131 131
             }
132 132
         }
133 133
         return $this->curl;
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      * @param string $display : service passive check output
142 142
      * @return array (status = true (oK) or false (nok), string message)
143 143
      */
144
-    public function serviceCheckResult($host,$service,$state,$display)
144
+    public function serviceCheckResult($host, $service, $state, $display)
145 145
     {
146 146
         //Send a POST request to the URL endpoint /v1/actions/process-check-result
147 147
         //actions/process-check-result?service=example.localdomain!passive-ping6
@@ -159,9 +159,9 @@  discard block
 block discarded – undo
159 159
         {
160 160
             return array(false, $e->getMessage());
161 161
         }
162
-        if (property_exists($result,'error') )
162
+        if (property_exists($result, 'error'))
163 163
         {
164
-            if (property_exists($result,'status'))
164
+            if (property_exists($result, 'status'))
165 165
             {
166 166
                 $message=$result->status;
167 167
             }
@@ -169,21 +169,21 @@  discard block
 block discarded – undo
169 169
             {
170 170
                 $message="Unkown status";
171 171
             }
172
-            return array(false , 'Ret code ' .$result->error.' : '.$message);
172
+            return array(false, 'Ret code '.$result->error.' : '.$message);
173 173
         }
174 174
         if (property_exists($result, 'results'))
175 175
         {
176 176
             if (isset($result->results[0]))
177 177
             {
178
-                return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status);
178
+                return array(true, 'code '.$result->results[0]->code.' : '.$result->results[0]->status);
179 179
             }
180 180
             else
181 181
             {
182
-                return array(false,'Service not found');
182
+                return array(false, 'Service not found');
183 183
             }
184 184
             
185 185
         }
186
-        return array(false,'Unkown result, open issue with this : '.print_r($result,true));
186
+        return array(false, 'Unkown result, open issue with this : '.print_r($result, true));
187 187
     }
188 188
  
189 189
     /**
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
         $url='objects/hosts';
205 205
         $body=array(
206 206
             "filter"        => 'host.address=="'.$ip.'" || host.address6=="'.$ip.'"',
207
-            "attrs"         => array('__name','name','display_name')
207
+            "attrs"         => array('__name', 'name', 'display_name')
208 208
         );
209 209
         try
210 210
         {
@@ -214,24 +214,24 @@  discard block
 block discarded – undo
214 214
             throw new Exception($e->getMessage());
215 215
         }
216 216
         
217
-        if (property_exists($result,'error') )
217
+        if (property_exists($result, 'error'))
218 218
         {
219
-            if (property_exists($result,'status'))
219
+            if (property_exists($result, 'status'))
220 220
             {
221
-                throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
221
+                throw new Exception('Ret code '.$result->error.' : '.$result->status);
222 222
             }
223 223
             else
224 224
             {
225
-                throw new Exception('Ret code ' .$result->error.' : Unkown status');
225
+                throw new Exception('Ret code '.$result->error.' : Unkown status');
226 226
             }
227 227
         }
228 228
         if (property_exists($result, 'results'))
229 229
         {
230 230
             $numHost=0;
231 231
             $hostArray=array();
232
-            while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
232
+            while (isset($result->results[$numHost]) && property_exists($result->results[$numHost], 'attrs'))
233 233
             {
234
-                $hostArray[$numHost] = $result->results[$numHost]->attrs;
234
+                $hostArray[$numHost]=$result->results[$numHost]->attrs;
235 235
                 $numHost++;
236 236
             }
237 237
             return $hostArray;            
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
         $url='objects/hosts';
251 251
         $body=array(
252 252
             "filter"        => '\"'.$hostGroup.'\" in host.groups',
253
-            "attrs"         => array('address','address','name')
253
+            "attrs"         => array('address', 'address', 'name')
254 254
         );
255 255
         try
256 256
         {
@@ -260,25 +260,25 @@  discard block
 block discarded – undo
260 260
             throw new Exception($e->getMessage());
261 261
         }
262 262
         
263
-        if (property_exists($result,'error') )
263
+        if (property_exists($result, 'error'))
264 264
         {
265
-            if (property_exists($result,'status'))
265
+            if (property_exists($result, 'status'))
266 266
             {
267
-                throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
267
+                throw new Exception('Ret code '.$result->error.' : '.$result->status);
268 268
             }
269 269
             else
270 270
             {
271
-                throw new Exception('Ret code ' .$result->error.' : Unkown status');
271
+                throw new Exception('Ret code '.$result->error.' : Unkown status');
272 272
             }
273 273
         }
274 274
         if (property_exists($result, 'results'))
275 275
         {
276 276
             $numHost=0;
277 277
             $hostArray=array();
278
-            while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
278
+            while (isset($result->results[$numHost]) && property_exists($result->results[$numHost], 'attrs'))
279 279
             {
280
-                $hostArray[$numHost] = $result->results[$numHost]->attrs;
281
-                $hostArray[$numHost]->name = $result->results[$numHost]->name;
280
+                $hostArray[$numHost]=$result->results[$numHost]->attrs;
281
+                $hostArray[$numHost]->name=$result->results[$numHost]->name;
282 282
                 $numHost++;
283 283
             }
284 284
             return $hostArray;
@@ -296,23 +296,23 @@  discard block
 block discarded – undo
296 296
      * @return array
297 297
      */
298 298
     public function request($method, $url, $headers, $body) {
299
-        $auth = sprintf('%s:%s', $this->user, $this->pass);
300
-        $curlHeaders = array("Accept: application/json");
299
+        $auth=sprintf('%s:%s', $this->user, $this->pass);
300
+        $curlHeaders=array("Accept: application/json");
301 301
         if ($body !== null) {
302
-            $body = json_encode($body);
302
+            $body=json_encode($body);
303 303
             array_push($curlHeaders, 'Content-Type: application/json');
304 304
             //array_push($curlHeaders, 'X-HTTP-Method-Override: GET');
305 305
         }
306 306
         //var_dump($body);
307 307
         //var_dump($this->url($url));
308 308
         if ($headers !== null) {
309
-            $curlFinalHeaders = array_merge($curlHeaders, $headers);
309
+            $curlFinalHeaders=array_merge($curlHeaders, $headers);
310 310
         } else 
311 311
         {
312 312
             $curlFinalHeaders=$curlHeaders;
313 313
         }
314
-        $curl = $this->curl();
315
-        $opts = array(
314
+        $curl=$this->curl();
315
+        $opts=array(
316 316
             CURLOPT_URL		=> $this->url($url),
317 317
             CURLOPT_HTTPHEADER 	=> $curlFinalHeaders,
318 318
             CURLOPT_USERPWD		=> $auth,
@@ -323,14 +323,14 @@  discard block
 block discarded – undo
323 323
             CURLOPT_SSL_VERIFYPEER 	=> false,
324 324
         );
325 325
         if ($body !== null) {
326
-            $opts[CURLOPT_POSTFIELDS] = $body;
326
+            $opts[CURLOPT_POSTFIELDS]=$body;
327 327
         }
328 328
         curl_setopt_array($curl, $opts);
329
-        $res = curl_exec($curl);
329
+        $res=curl_exec($curl);
330 330
         if ($res === false) {
331
-            throw new Exception('CURL ERROR: ' . curl_error($curl));
331
+            throw new Exception('CURL ERROR: '.curl_error($curl));
332 332
         }
333
-        $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
333
+        $statusCode=curl_getinfo($curl, CURLINFO_HTTP_CODE);
334 334
         if ($statusCode === 401) {
335 335
             throw new Exception('Unable to authenticate, please check your API credentials');
336 336
         }
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
      * @return array json decoded
345 345
      */
346 346
     protected function fromJsonResult($json) {
347
-        $result = @json_decode($json);
347
+        $result=@json_decode($json);
348 348
         //var_dump($json);
349 349
         if ($result === null) {
350 350
             throw new Exception('Parsing JSON failed: '.$this->getLastJsonErrorMessage(json_last_error()));
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -164,8 +164,7 @@  discard block
 block discarded – undo
164 164
             if (property_exists($result,'status'))
165 165
             {
166 166
                 $message=$result->status;
167
-            }
168
-            else 
167
+            } else 
169 168
             {
170 169
                 $message="Unkown status";
171 170
             }
@@ -176,8 +175,7 @@  discard block
 block discarded – undo
176 175
             if (isset($result->results[0]))
177 176
             {
178 177
                 return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status);
179
-            }
180
-            else
178
+            } else
181 179
             {
182 180
                 return array(false,'Service not found');
183 181
             }
@@ -219,8 +217,7 @@  discard block
 block discarded – undo
219 217
             if (property_exists($result,'status'))
220 218
             {
221 219
                 throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
222
-            }
223
-            else
220
+            } else
224 221
             {
225 222
                 throw new Exception('Ret code ' .$result->error.' : Unkown status');
226 223
             }
@@ -265,8 +262,7 @@  discard block
 block discarded – undo
265 262
             if (property_exists($result,'status'))
266 263
             {
267 264
                 throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
268
-            }
269
-            else
265
+            } else
270 266
             {
271 267
                 throw new Exception('Ret code ' .$result->error.' : Unkown status');
272 268
             }
Please login to merge, or discard this patch.
library/Trapdirector/Config/TrapModuleConfig.php 2 patches
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -4,9 +4,9 @@  discard block
 block discarded – undo
4 4
 
5 5
 class TrapModuleConfig
6 6
 {
7
-    /********** Database configuration ***********************/
7
+	/********** Database configuration ***********************/
8 8
 	// Database prefix for tables 
9
-    protected $table_prefix; //< Database prefix for tables 	
9
+	protected $table_prefix; //< Database prefix for tables 	
10 10
 	protected $DBConfigDefaults=array(
11 11
 		'db_remove_days' => 60, // number of days before removing traps
12 12
 		'log_destination' => 'syslog', // Log destination for trap handler
@@ -113,27 +113,27 @@  discard block
 block discarded – undo
113 113
 	// Note : must have 'source_ip' and 'last_sent'
114 114
 	public function getTrapHostListDisplayColumns()
115 115
 	{
116
-	    return array(
117
-	        'source_name'  =>  't.source_name',
118
-	        'source_ip'    =>  't.source_ip',
119
-	        'trap_oid'     =>  't.trap_oid',
120
-	        'count'        =>  'count(*)',
121
-	        'last_sent'    =>  'UNIX_TIMESTAMP(max(t.date_received))'
122
-	    );
116
+		return array(
117
+			'source_name'  =>  't.source_name',
118
+			'source_ip'    =>  't.source_ip',
119
+			'trap_oid'     =>  't.trap_oid',
120
+			'count'        =>  'count(*)',
121
+			'last_sent'    =>  'UNIX_TIMESTAMP(max(t.date_received))'
122
+		);
123 123
 	}
124 124
 
125 125
 	public function getTrapHostListSearchColumns()
126 126
 	{
127
-	    return array(); // No search needed on this table
127
+		return array(); // No search needed on this table
128 128
 	}
129 129
 	// Titles display in Trap List table
130 130
 	public function getTrapHostListTitles()
131 131
 	{
132
-	    return array(
133
-	        'trap_oid'		=> 'Trap OID',
134
-	        'count'		    => 'Number of traps received',
135
-	        'last_sent'     => 'Last trap received'
136
-	    );
132
+		return array(
133
+			'trap_oid'		=> 'Trap OID',
134
+			'count'		    => 'Number of traps received',
135
+			'last_sent'     => 'Last trap received'
136
+		);
137 137
 	}
138 138
 	
139 139
 	
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 			'revert_ok'		=> 'r.revert_ok',
189 189
 			'display'		=> 'r.display',
190 190
 			'modified'		=> 'UNIX_TIMESTAMP(r.modified)',
191
-            'modifier'		=> 'r.modifier'
191
+			'modifier'		=> 'r.modifier'
192 192
 		);
193 193
 	}	
194 194
 		
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -14,22 +14,22 @@  discard block
 block discarded – undo
14 14
 		'log_level' => 2, // log level
15 15
 	);
16 16
 	// get default values for dbconfig
17
-	public function getDBConfigDefaults() { return $this->DBConfigDefaults;}
17
+	public function getDBConfigDefaults() { return $this->DBConfigDefaults; }
18 18
 	// Minimum DB version
19
-	static public function getDbMinVersion() { return 2;}	
19
+	static public function getDbMinVersion() { return 2; }	
20 20
 	// Current DB version
21
-	static public function getDbCurVersion() { return 2;}
21
+	static public function getDbCurVersion() { return 2; }
22 22
 
23 23
 	/************ Module configuration **********************/
24 24
 	// Module base path
25 25
 	static public function urlPath() { return 'trapdirector'; }
26
-	static public function getapiUserPermissions() { return array("status", "objects/query/Host", "objects/query/Service" , "actions/process-check-result"); } //< api user permissions required
26
+	static public function getapiUserPermissions() { return array("status", "objects/query/Host", "objects/query/Service", "actions/process-check-result"); } //< api user permissions required
27 27
 	
28 28
 	/*********** Log configuration *************************/
29 29
 	protected $logLevels=array(0=>'No output', 1=>'critical', 2=>'warning', 3=>'trace', 4=>'ALL');
30
-	public function getlogLevels() { return $this->logLevels;}
31
-	protected $logDestinations=array('syslog'=>'syslog','file'=>'file','display'=>'display');
32
-	public function getLogDestinations() { return $this->logDestinations;}
30
+	public function getlogLevels() { return $this->logLevels; }
31
+	protected $logDestinations=array('syslog'=>'syslog', 'file'=>'file', 'display'=>'display');
32
+	public function getLogDestinations() { return $this->logDestinations; }
33 33
 	
34 34
 	function __construct($prefix)
35 35
 	{
@@ -40,29 +40,29 @@  discard block
 block discarded – undo
40 40
 	// DB table name of trap received list : prefix 't'
41 41
 	public function getTrapTableName() 
42 42
 	{ 
43
-		return array('t' => $this->table_prefix . 'received'); 
43
+		return array('t' => $this->table_prefix.'received'); 
44 44
 	}
45 45
 	// DB table name of trap data  list : prefix 'd'
46 46
 	public function getTrapDataTableName() 
47 47
 	{ 
48
-		return array('d' => $this->table_prefix . 'received_data'); 
48
+		return array('d' => $this->table_prefix.'received_data'); 
49 49
 	}	
50 50
 
51 51
 	// DB table name of rules : prefix 'r'
52 52
 	public function getTrapRuleName() 
53 53
 	{ 
54
-		return array('r' => $this->table_prefix . 'rules'); 
54
+		return array('r' => $this->table_prefix.'rules'); 
55 55
 	}		
56 56
 	
57 57
 	// DB table name of db config : prefix 'c'
58 58
 	public function getDbConfigTableName() 
59 59
 	{ 
60
-		return array('c' => $this->table_prefix . 'db_config');
60
+		return array('c' => $this->table_prefix.'db_config');
61 61
 	}
62 62
 	
63 63
 	// Mib cache tables
64
-	public function getMIBCacheTableName() { return $this->table_prefix . 'mib_cache'; }
65
-	public function getMIBCacheTableTrapObjName() { return $this->table_prefix . 'mib_cache_trap_object'; }
64
+	public function getMIBCacheTableName() { return $this->table_prefix.'mib_cache'; }
65
+	public function getMIBCacheTableTrapObjName() { return $this->table_prefix.'mib_cache_trap_object'; }
66 66
 	
67 67
 	
68 68
 	/****************** Database queries *******************/
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 	public function getHandlerListDisplayColumns()
144 144
 	{
145 145
 		return array(
146
-			'host_name'		=> 'r.host_name',//'UNIX_TIMESTAMP(t.date_received)',
146
+			'host_name'		=> 'r.host_name', //'UNIX_TIMESTAMP(t.date_received)',
147 147
 			'host_group_name'=> 'r.host_group_name',
148 148
 			'source_ip'		=> "CASE WHEN r.ip4 IS NULL THEN r.ip6 ELSE r.ip4 END",
149 149
 			'trap_oid'		=> 'r.trap_oid',
@@ -196,32 +196,32 @@  discard block
 block discarded – undo
196 196
 	public function trapDetailQuery()
197 197
 	{
198 198
 		return array(
199
-			'timestamp'			=> array('Date','UNIX_TIMESTAMP(t.date_received)'),
200
-			'source_ip'			=> array('Source IP','t.source_ip'),
201
-			'source_name'		=> array('Source name','t.source_name'),
202
-			'source_port'		=> array('Source port','t.source_port'),
203
-			'destination_ip'	=> array('Destination IP','t.destination_ip'),
204
-			'destination_port'	=> array('Destination port','t.destination_port'),			
205
-			'trap_oid'			=> array('Numeric OID','t.trap_oid'),
206
-			'trap_name'			=> array('Trap name','t.trap_name'),
207
-			'trap_name_mib'		=> array('Trap MIB','t.trap_name_mib'),
208
-			'status'			=> array('Processing status','t.status'),
209
-			'status_detail'		=> array('Status details','t.status_detail'),
210
-			'process_time'		=> array('Trap processing time','t.process_time'),			
199
+			'timestamp'			=> array('Date', 'UNIX_TIMESTAMP(t.date_received)'),
200
+			'source_ip'			=> array('Source IP', 't.source_ip'),
201
+			'source_name'		=> array('Source name', 't.source_name'),
202
+			'source_port'		=> array('Source port', 't.source_port'),
203
+			'destination_ip'	=> array('Destination IP', 't.destination_ip'),
204
+			'destination_port'	=> array('Destination port', 't.destination_port'),			
205
+			'trap_oid'			=> array('Numeric OID', 't.trap_oid'),
206
+			'trap_name'			=> array('Trap name', 't.trap_name'),
207
+			'trap_name_mib'		=> array('Trap MIB', 't.trap_name_mib'),
208
+			'status'			=> array('Processing status', 't.status'),
209
+			'status_detail'		=> array('Status details', 't.status_detail'),
210
+			'process_time'		=> array('Trap processing time', 't.process_time'),			
211 211
 		);
212 212
 	}
213 213
 	// Trap detail : additional data (<key> => <title> <sql select>)
214 214
 	public function trapDataDetailQuery()
215 215
 	{
216 216
 		return array(
217
-			'oid'				=> array('Numeric OID','d.oid'),
218
-			'oid_name'			=> array('Text OID','d.oid_name'),
219
-			'oid_name_mib'		=> array('MIB','d.oid_name_mib'),
220
-			'value'				=> array('Value','d.value'),
217
+			'oid'				=> array('Numeric OID', 'd.oid'),
218
+			'oid_name'			=> array('Text OID', 'd.oid_name'),
219
+			'oid_name_mib'		=> array('MIB', 'd.oid_name_mib'),
220
+			'value'				=> array('Value', 'd.value'),
221 221
 		);
222 222
 	}
223 223
 	// foreign key of trap data table
224
-	public function trapDataFK() { return 'trap_id';}
224
+	public function trapDataFK() { return 'trap_id'; }
225 225
 	
226 226
 	// Max items in a list
227 227
 	public function itemListDisplay() { return 25; }
Please login to merge, or discard this patch.
tests/expr_test.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -3,18 +3,18 @@  discard block
 block discarded – undo
3 3
 
4 4
 require_once 'bin/trap_class.php';
5 5
 
6
-$options = getopt("r:d:");
6
+$options=getopt("r:d:");
7 7
 
8
-$icingaweb2Etc=(array_key_exists('d',$options))?$options['d']:"/etc/icingaweb2";
8
+$icingaweb2Etc=(array_key_exists('d', $options)) ? $options['d'] : "/etc/icingaweb2";
9 9
 
10
-$debugLevel=4;// 0=No output 1=critical 2=warning 3=trace 4=ALL
10
+$debugLevel=4; // 0=No output 1=critical 2=warning 3=trace 4=ALL
11 11
 
12
-$trap = new trap($icingaweb2Etc);
13
-$trap->setLogging($debugLevel,'display');
12
+$trap=new trap($icingaweb2Etc);
13
+$trap->setLogging($debugLevel, 'display');
14 14
 
15
-$input=array_key_exists('r',$options);
15
+$input=array_key_exists('r', $options);
16 16
 
17
-if (! $input) {
17
+if (!$input) {
18 18
   $inputStream=fopen('php://stdin', 'r');
19 19
   $rule=chop(fgets($inputStream));
20 20
 } else
@@ -25,11 +25,11 @@  discard block
 block discarded – undo
25 25
   $rule=$trap->eval_cleanup($rule);
26 26
   //echo 'After cleanup : #'.$rule."#\n";
27 27
   $item=0;
28
-  $val = $trap->evaluation($rule,$item);
29
-  if ($val==true) { printf( "true"); } else { printf( "false");}
28
+  $val=$trap->evaluation($rule, $item);
29
+  if ($val == true) { printf("true"); } else { printf("false"); }
30 30
   printf("\n");
31 31
 }
32
-catch (Exception $e) { printf("%s\n",$e->getMessage()); exit(1);}
32
+catch (Exception $e) { printf("%s\n", $e->getMessage()); exit(1); }
33 33
 
34 34
 exit(0);
35 35
 ?>
Please login to merge, or discard this patch.
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -17,8 +17,9 @@  discard block
 block discarded – undo
17 17
 if (! $input) {
18 18
   $inputStream=fopen('php://stdin', 'r');
19 19
   $rule=chop(fgets($inputStream));
20
-} else
20
+} else {
21 21
   $rule=$options['r'];
22
+}
22 23
 
23 24
 try
24 25
 {
@@ -28,8 +29,7 @@  discard block
 block discarded – undo
28 29
   $val = $trap->evaluation($rule,$item);
29 30
   if ($val==true) { printf( "true"); } else { printf( "false");}
30 31
   printf("\n");
31
-}
32
-catch (Exception $e) { printf("%s\n",$e->getMessage()); exit(1);}
32
+} catch (Exception $e) { printf("%s\n",$e->getMessage()); exit(1);}
33 33
 
34 34
 exit(0);
35 35
 ?>
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.
bin/trap_in.php 3 patches
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -30,15 +30,13 @@
 block discarded – undo
30 30
 
31 31
 	$Trap->add_rule_final(microtime(true) - $time1);
32 32
 	
33
-}
34
-catch (Exception $e) 
33
+} catch (Exception $e) 
35 34
 {
36 35
     if ($Trap == null)
37 36
     {  // Exception in trap creation : log in display & syslog
38 37
         $logging = new Logging();
39 38
         $logging->log("Caught exception creating Trap class",2);
40
-    }
41
-    else
39
+    } else
42 40
     {
43 41
 	   $Trap->trapLog("Exception : ". $e->getMessage(),2,0);
44 42
     }
Please login to merge, or discard this patch.
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -15,13 +15,13 @@  discard block
 block discarded – undo
15 15
 
16 16
 try
17 17
 {
18
-    $Trap = new Trap($icingaweb2_etc);
19
-    //$Trap = new Trap($icingaweb2_etc,4,'display'); // For debug
20
-    //$Trap = new Trap($icingaweb2_etc,4,'syslog'); // For debug
21
-    //$Trap->setLogging(4,'syslog'); 
18
+	$Trap = new Trap($icingaweb2_etc);
19
+	//$Trap = new Trap($icingaweb2_etc,4,'display'); // For debug
20
+	//$Trap = new Trap($icingaweb2_etc,4,'syslog'); // For debug
21
+	//$Trap->setLogging(4,'syslog'); 
22 22
     
23
-    // TODO : tranfer this to reset_trap cli command
24
-    $Trap->eraseOldTraps();
23
+	// TODO : tranfer this to reset_trap cli command
24
+	$Trap->eraseOldTraps();
25 25
 
26 26
 	$Trap->read_trap('php://stdin');
27 27
 
@@ -34,15 +34,15 @@  discard block
 block discarded – undo
34 34
 }
35 35
 catch (Exception $e) 
36 36
 {
37
-    if ($Trap == null)
38
-    {  // Exception in trap creation : log in display & syslog
39
-        $logging = new Logging();
40
-        $logging->log("Caught exception creating Trap class",2);
41
-    }
42
-    else
43
-    {
37
+	if ($Trap == null)
38
+	{  // Exception in trap creation : log in display & syslog
39
+		$logging = new Logging();
40
+		$logging->log("Caught exception creating Trap class",2);
41
+	}
42
+	else
43
+	{
44 44
 	   $Trap->trapLog("Exception : ". $e->getMessage(),2,0);
45
-    }
45
+	}
46 46
 }
47 47
 
48 48
 //end
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 use Trapdirector\Logging;
4 4
 
5 5
 // start
6
-$time1 = microtime(true);
6
+$time1=microtime(true);
7 7
 
8 8
 require_once ('trap_class.php');
9 9
 
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 
16 16
 try
17 17
 {
18
-    $Trap = new Trap($icingaweb2_etc);
18
+    $Trap=new Trap($icingaweb2_etc);
19 19
     //$Trap = new Trap($icingaweb2_etc,4,'display'); // For debug
20 20
     //$Trap = new Trap($icingaweb2_etc,4,'syslog'); // For debug
21 21
     //$Trap->setLogging(4,'syslog'); 
@@ -36,12 +36,12 @@  discard block
 block discarded – undo
36 36
 {
37 37
     if ($Trap == null)
38 38
     {  // Exception in trap creation : log in display & syslog
39
-        $logging = new Logging();
40
-        $logging->log("Caught exception creating Trap class",2);
39
+        $logging=new Logging();
40
+        $logging->log("Caught exception creating Trap class", 2);
41 41
     }
42 42
     else
43 43
     {
44
-	   $Trap->trapLog("Exception : ". $e->getMessage(),2,0);
44
+	   $Trap->trapLog("Exception : ".$e->getMessage(), 2, 0);
45 45
     }
46 46
 }
47 47
 
Please login to merge, or discard this patch.