Passed
Push — master ( df2595...b8f383 )
by Patrick
01:54
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_class.php 3 patches
Indentation   +597 added lines, -597 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	
61 61
 	function __construct($etc_dir='/etc/icingaweb2',$baseLogLevel=null,$baseLogMode='syslog',$baseLogFile='')
62 62
 	{
63
-	    // Paths of ini files
63
+		// Paths of ini files
64 64
 		$this->icingaweb2_etc=$etc_dir;
65 65
 		$this->trap_module_config=$this->icingaweb2_etc."/modules/trapdirector/config.ini";		
66 66
 		$this->icingaweb2_ressources=$this->icingaweb2_etc."/resources.ini";
@@ -69,18 +69,18 @@  discard block
 block discarded – undo
69 69
 		$this->logging = new Logging();
70 70
 		if ($baseLogLevel != null)
71 71
 		{
72
-		    $this->logging->setLogging($baseLogLevel, $baseLogMode,$baseLogFile);
73
-		    $this->logSetup=true;
72
+			$this->logging->setLogging($baseLogLevel, $baseLogMode,$baseLogFile);
73
+			$this->logSetup=true;
74 74
 		}
75 75
 		else 
76
-		    $this->logSetup=false;
76
+			$this->logSetup=false;
77 77
 		$this->logging->log('Loggin started', INFO);
78 78
 
79 79
 		// Get options from ini files
80 80
 		$trapConfig=parse_ini_file($this->trap_module_config,true);
81 81
 		if ($trapConfig == false)
82 82
 		{
83
-		    $this->logging->log("Error reading ini file : ".$this->trap_module_config,ERROR,'syslog');
83
+			$this->logging->log("Error reading ini file : ".$this->trap_module_config,ERROR,'syslog');
84 84
 		}
85 85
 		$this->getMainOptions($trapConfig); // Get main options from ini file
86 86
 		$this->setupDatabase($trapConfig); // Setup database class
@@ -110,27 +110,27 @@  discard block
 block discarded – undo
110 110
 	 */
111 111
 	protected function getOptionIfSet($option_array,$option_category,$option_name, &$option_var, $log_level = 2, $message = null)
112 112
 	{
113
-	    if (!isset($option_array[$option_category][$option_name]))
114
-	    {
115
-	        if ($message === null)
116
-	        {
117
-	            $message='No ' . $option_name . ' in config file: '. $this->trap_module_config;
118
-	        }
119
-	        $this->logging->log($message,$log_level,'syslog');
120
-	        return false;
121
-	    }
122
-	    else
123
-	    {
124
-	        $option_var=$option_array[$option_category][$option_name];
125
-	        return true;
126
-	    }
113
+		if (!isset($option_array[$option_category][$option_name]))
114
+		{
115
+			if ($message === null)
116
+			{
117
+				$message='No ' . $option_name . ' in config file: '. $this->trap_module_config;
118
+			}
119
+			$this->logging->log($message,$log_level,'syslog');
120
+			return false;
121
+		}
122
+		else
123
+		{
124
+			$option_var=$option_array[$option_category][$option_name];
125
+			return true;
126
+		}
127 127
 	}
128 128
 	
129 129
 	/** 
130 130
 	 * Get options from ini file and database
131 131
 	 * Setup the database class with options.
132 132
 	 * @param array : ini file array
133
-	*/
133
+	 */
134 134
 	protected function getMainOptions($trap_config)
135 135
 	{
136 136
 		$trap_config=parse_ini_file($this->trap_module_config,true);
@@ -153,55 +153,55 @@  discard block
 block discarded – undo
153 153
 		// API options
154 154
 		if ($this->getOptionIfSet($trap_config,'config','icingaAPI_host', $this->api_hostname))
155 155
 		{
156
-		    $this->api_use=true;
157
-		    $this->getOptionIfSet($trap_config,'config','icingaAPI_port', $this->api_port);
158
-		    $this->getOptionIfSet($trap_config,'config','icingaAPI_user', $this->api_username);
159
-		    $this->getOptionIfSet($trap_config,'config','icingaAPI_password', $this->api_password);
156
+			$this->api_use=true;
157
+			$this->getOptionIfSet($trap_config,'config','icingaAPI_port', $this->api_port);
158
+			$this->getOptionIfSet($trap_config,'config','icingaAPI_user', $this->api_username);
159
+			$this->getOptionIfSet($trap_config,'config','icingaAPI_password', $this->api_password);
160 160
 		}
161 161
 	}
162 162
 	
163 163
 	
164 164
 	protected function setupDatabase($trapConfig)
165 165
 	{
166
-	    // Trap database
167
-	    if (!array_key_exists('database',$trapConfig['config']))
168
-        {
169
-            $this->logging->log("No database in config file: ".$this->trap_module_config,ERROR,'');
170
-            return;
171
-        }
172
-        $dbTrapName=$trapConfig['config']['database'];
173
-        $this->logging->log("Found database in config file: ".$dbTrapName,INFO );
166
+		// Trap database
167
+		if (!array_key_exists('database',$trapConfig['config']))
168
+		{
169
+			$this->logging->log("No database in config file: ".$this->trap_module_config,ERROR,'');
170
+			return;
171
+		}
172
+		$dbTrapName=$trapConfig['config']['database'];
173
+		$this->logging->log("Found database in config file: ".$dbTrapName,INFO );
174 174
 	    
175 175
 	   if ( ($dbConfig=parse_ini_file($this->icingaweb2_ressources,true)) === false)
176
-	    {
177
-	        $this->logging->log("Error reading ini file : ".$this->icingaweb2_ressources,ERROR,'');
178
-	        return;
179
-	    }
180
-	    if (!array_key_exists($dbTrapName,$dbConfig))
181
-	    {
182
-	        $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2_ressources,ERROR,'');
183
-	        return;
184
-	    }
176
+		{
177
+			$this->logging->log("Error reading ini file : ".$this->icingaweb2_ressources,ERROR,'');
178
+			return;
179
+		}
180
+		if (!array_key_exists($dbTrapName,$dbConfig))
181
+		{
182
+			$this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2_ressources,ERROR,'');
183
+			return;
184
+		}
185 185
 	    
186
-        $this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName]);
186
+		$this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName]);
187 187
 	    
188
-	    if ($this->api_use === true) return; // In case of API use, no IDO is necessary
188
+		if ($this->api_use === true) return; // In case of API use, no IDO is necessary
189 189
         
190
-	    // IDO Database
191
-	    if (!array_key_exists('IDOdatabase',$trapConfig['config']))
192
-	    {
193
-	        $this->logging->log("No IDOdatabase in config file: ".$this->trap_module_config,ERROR,'');
194
-	    }
195
-	    $dbIdoName=$trapConfig['config']['IDOdatabase'];		
190
+		// IDO Database
191
+		if (!array_key_exists('IDOdatabase',$trapConfig['config']))
192
+		{
193
+			$this->logging->log("No IDOdatabase in config file: ".$this->trap_module_config,ERROR,'');
194
+		}
195
+		$dbIdoName=$trapConfig['config']['IDOdatabase'];		
196 196
 
197
-	    $this->logging->log("Found IDO database in config file: ".$dbIdoName,INFO );
198
-        if (!array_key_exists($dbIdoName,$dbConfig))
199
-	    {
200
-	        $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2_ressources,ERROR,'');
201
-	        return;
202
-	    }
197
+		$this->logging->log("Found IDO database in config file: ".$dbIdoName,INFO );
198
+		if (!array_key_exists($dbIdoName,$dbConfig))
199
+		{
200
+			$this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2_ressources,ERROR,'');
201
+			return;
202
+		}
203 203
 	    
204
-	    $this->trapsDB->setupIDO($dbConfig[$dbIdoName]);
204
+		$this->trapsDB->setupIDO($dbConfig[$dbIdoName]);
205 205
 	}
206 206
 	
207 207
 	/**
@@ -212,9 +212,9 @@  discard block
 block discarded – undo
212 212
 		// Database options
213 213
 		if ($this->logSetup == false) // Only if logging was no setup in constructor
214 214
 		{
215
-    		$this->getDBConfigIfSet('log_level',$this->logging->debugLevel);
216
-    		$this->getDBConfigIfSet('log_destination',$this->logging->outputMode);
217
-    		$this->getDBConfigIfSet('log_file',$this->logging->outputFile);
215
+			$this->getDBConfigIfSet('log_level',$this->logging->debugLevel);
216
+			$this->getDBConfigIfSet('log_destination',$this->logging->outputMode);
217
+			$this->getDBConfigIfSet('log_file',$this->logging->outputFile);
218 218
 		}
219 219
 	}
220 220
 
@@ -225,10 +225,10 @@  discard block
 block discarded – undo
225 225
 	}
226 226
 	
227 227
 	/** 
228
-	*   Get data from db_config
229
-	*	@param $element string name of param
230
-	*	@return mixed : value (or null)
231
-	*/	
228
+	 *   Get data from db_config
229
+	 *	@param $element string name of param
230
+	 *	@return mixed : value (or null)
231
+	 */	
232 232
 	protected function getDBConfig($element)
233 233
 	{
234 234
 		$db_conn=$this->trapsDB->db_connect_trap();
@@ -246,15 +246,15 @@  discard block
 block discarded – undo
246 246
 	}
247 247
 	
248 248
 	/** OBSOLETE Send log. Throws exception on critical error
249
-	*	@param	string $message Message to log
250
-	*	@param	int $level 1=critical 2=warning 3=trace 4=debug
251
-	*	@param  string $destination file/syslog/display
252
-	*	@return void
253
-	**/	
249
+	 *	@param	string $message Message to log
250
+	 *	@param	int $level 1=critical 2=warning 3=trace 4=debug
251
+	 *	@param  string $destination file/syslog/display
252
+	 *	@return void
253
+	 **/	
254 254
 	public function trapLog( $message, $level, $destination ='') // OBSOLETE
255 255
 	{	
256 256
 		// TODO : replace ref with $this->logging->log 
257
-	    $this->logging->log($message, $level, $destination);
257
+		$this->logging->log($message, $level, $destination);
258 258
 	}
259 259
 	
260 260
 	public function setLogging($debugLvl,$outputType,$outputOption=null)  // OBSOLETE
@@ -264,19 +264,19 @@  discard block
 block discarded – undo
264 264
 	
265 265
 	protected function getAPI()
266 266
 	{
267
-	    if ($this->icinga2api == null)
268
-	    {
269
-	        $this->icinga2api = new Icinga2API($this->api_hostname,$this->api_port);
270
-	    }
271
-	    return $this->icinga2api;
267
+		if ($this->icinga2api == null)
268
+		{
269
+			$this->icinga2api = new Icinga2API($this->api_hostname,$this->api_port);
270
+		}
271
+		return $this->icinga2api;
272 272
 	}
273 273
 	
274 274
 	
275 275
 	/** 
276 276
 	 * read data from stream
277
-	*	@param $stream string input stream, defaults to "php://stdin"
278
-	*	@return mixed array trap data or exception with error
279
-	*/
277
+	 *	@param $stream string input stream, defaults to "php://stdin"
278
+	 *	@return mixed array trap data or exception with error
279
+	 */
280 280
 	public function read_trap($stream='php://stdin')
281 281
 	{
282 282
 		//Read data from snmptrapd from stdin
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 
285 285
 		if ($input_stream === false)
286 286
 		{
287
-		    $this->writeTrapErrorToDB("Error reading trap (code 1/Stdin)");
287
+			$this->writeTrapErrorToDB("Error reading trap (code 1/Stdin)");
288 288
 			$this->logging->log("Error reading stdin !",ERROR,'');
289 289
 			return null; // note : exception thrown by logging
290 290
 		}
@@ -293,21 +293,21 @@  discard block
 block discarded – undo
293 293
 		$this->receivingHost=chop(fgets($input_stream));
294 294
 		if ($this->receivingHost === false)
295 295
 		{
296
-		    $this->writeTrapErrorToDB("Error reading trap (code 1/Line Host)");
296
+			$this->writeTrapErrorToDB("Error reading trap (code 1/Line Host)");
297 297
 			$this->logging->log("Error reading Host !",ERROR,''); 
298 298
 		}
299 299
 		// line 2 IP:port=>IP:port
300 300
 		$IP=chop(fgets($input_stream));
301 301
 		if ($IP === false)
302 302
 		{
303
-		    $this->writeTrapErrorToDB("Error reading trap (code 1/Line IP)");
303
+			$this->writeTrapErrorToDB("Error reading trap (code 1/Line IP)");
304 304
 			$this->logging->log("Error reading IP !",ERROR,''); 
305 305
 		}
306 306
 		$matches=array();
307 307
 		$ret_code=preg_match('/.DP: \[(.*)\]:(.*)->\[(.*)\]:(.*)/',$IP,$matches);
308 308
 		if ($ret_code===0 || $ret_code===false) 
309 309
 		{
310
-		    $this->writeTrapErrorToDB("Error parsing trap (code 2/IP)");
310
+			$this->writeTrapErrorToDB("Error parsing trap (code 2/IP)");
311 311
 			$this->logging->log('Error parsing IP : '.$IP,ERROR,'');
312 312
 		} 
313 313
 		else 
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
 			}
329 329
 			else 
330 330
 			{
331
-			    if (($matches[1]=='.1.3.6.1.6.3.1.1.4.1.0') || ($matches[1]=='.1.3.6.1.6.3.1.1.4.1'))
331
+				if (($matches[1]=='.1.3.6.1.6.3.1.1.4.1.0') || ($matches[1]=='.1.3.6.1.6.3.1.1.4.1'))
332 332
 				{
333 333
 					$this->trap_data['trap_oid']=$matches[2];				
334 334
 				}
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 
345 345
 		if ($this->trap_data['trap_oid']=='unknown') 
346 346
 		{
347
-		    $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)",$this->trap_data['source_ip']);
347
+			$this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)",$this->trap_data['source_ip']);
348 348
 			$this->logging->log('no trap oid found',ERROR,'');
349 349
 		} 
350 350
 
@@ -374,9 +374,9 @@  discard block
 block discarded – undo
374 374
 
375 375
 	/** 
376 376
 	 * Translate oid into array(MIB,Name)
377
-	* @param $oid string oid to translate
378
-	* @return mixed : null if not found or array(MIB,Name)
379
-	*/
377
+	 * @param $oid string oid to translate
378
+	 * @return mixed : null if not found or array(MIB,Name)
379
+	 */
380 380
 	public function translateOID($oid)
381 381
 	{
382 382
 		// try from database
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
 		
410 410
 		// Try to get oid name from snmptranslate
411 411
 		$translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
412
-		    ' '.$oid);
412
+			' '.$oid);
413 413
 		$matches=array();
414 414
 		$ret_code=preg_match('/(.*)::(.*)/',$translate,$matches);
415 415
 		if ($ret_code===0 || $ret_code === false) {
@@ -422,9 +422,9 @@  discard block
 block discarded – undo
422 422
 	
423 423
 	/** 
424 424
 	 * Erase old trap records 
425
-	*	@param integer $days : erase traps when more than $days old
426
-	*	@return integer : number of lines deleted
427
-	**/
425
+	 *	@param integer $days : erase traps when more than $days old
426
+	 *	@return integer : number of lines deleted
427
+	 **/
428 428
 	public function eraseOldTraps($days=0)
429 429
 	{
430 430
 		if ($days==0)
@@ -449,72 +449,72 @@  discard block
 block discarded – undo
449 449
 	public function writeTrapErrorToDB($message,$sourceIP=null,$trapoid=null)
450 450
 	{
451 451
 	    
452
-	    $db_conn=$this->trapsDB->db_connect_trap();
452
+		$db_conn=$this->trapsDB->db_connect_trap();
453 453
 	    
454
-	    // add date time
455
-	    $insert_col ='date_received,status';
456
-	    $insert_val = "'" . date("Y-m-d H:i:s")."','error'";
454
+		// add date time
455
+		$insert_col ='date_received,status';
456
+		$insert_val = "'" . date("Y-m-d H:i:s")."','error'";
457 457
         
458
-	    if ($sourceIP !=null)
459
-	    {
460
-	        $insert_col .=',source_ip';
461
-	        $insert_val .=",'". $sourceIP ."'";
462
-	    }
463
-	    if ($trapoid !=null)
464
-	    {
465
-	        $insert_col .=',trap_oid';
466
-	        $insert_val .=",'". $trapoid ."'";
467
-	    }
468
-	    $insert_col .=',status_detail';
469
-	    $insert_val .=",'". $message ."'";
458
+		if ($sourceIP !=null)
459
+		{
460
+			$insert_col .=',source_ip';
461
+			$insert_val .=",'". $sourceIP ."'";
462
+		}
463
+		if ($trapoid !=null)
464
+		{
465
+			$insert_col .=',trap_oid';
466
+			$insert_val .=",'". $trapoid ."'";
467
+		}
468
+		$insert_col .=',status_detail';
469
+		$insert_val .=",'". $message ."'";
470 470
 	    
471
-	    $sql= 'INSERT INTO '.$this->db_prefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')';
471
+		$sql= 'INSERT INTO '.$this->db_prefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')';
472 472
 	    
473
-	    switch ($this->trapsDB->trapDBType)
474
-	    {
475
-	        case 'pgsql':
476
-	            $sql .= ' RETURNING id;';
477
-	            $this->logging->log('sql : '.$sql,INFO);
478
-	            if (($ret_code=$db_conn->query($sql)) === false) {
479
-	                $this->logging->log('Error SQL insert : '.$sql,1,'');
480
-	            }
481
-	            $this->logging->log('SQL insertion OK',INFO );
482
-	            // Get last id to insert oid/values in secondary table
483
-	            if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) {
473
+		switch ($this->trapsDB->trapDBType)
474
+		{
475
+			case 'pgsql':
476
+				$sql .= ' RETURNING id;';
477
+				$this->logging->log('sql : '.$sql,INFO);
478
+				if (($ret_code=$db_conn->query($sql)) === false) {
479
+					$this->logging->log('Error SQL insert : '.$sql,1,'');
480
+				}
481
+				$this->logging->log('SQL insertion OK',INFO );
482
+				// Get last id to insert oid/values in secondary table
483
+				if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) {
484 484
 	                
485
-	                $this->logging->log('Erreur recuperation id',1,'');
486
-	            }
487
-	            if (! isset($inserted_id_ret['id'])) {
488
-	                $this->logging->log('Error getting id',1,'');
489
-	            }
490
-	            $this->trap_id=$inserted_id_ret['id'];
491
-	            break;
492
-	        case 'mysql':
493
-	            $sql .= ';';
494
-	            $this->logging->log('sql : '.$sql,INFO );
495
-	            if ($db_conn->query($sql) === false) {
496
-	                $this->logging->log('Error SQL insert : '.$sql,1,'');
497
-	            }
498
-	            $this->logging->log('SQL insertion OK',INFO );
499
-	            // Get last id to insert oid/values in secondary table
500
-	            $sql='SELECT LAST_INSERT_ID();';
501
-	            if (($ret_code=$db_conn->query($sql)) === false) {
502
-	                $this->logging->log('Erreur recuperation id',1,'');
503
-	            }
485
+					$this->logging->log('Erreur recuperation id',1,'');
486
+				}
487
+				if (! isset($inserted_id_ret['id'])) {
488
+					$this->logging->log('Error getting id',1,'');
489
+				}
490
+				$this->trap_id=$inserted_id_ret['id'];
491
+				break;
492
+			case 'mysql':
493
+				$sql .= ';';
494
+				$this->logging->log('sql : '.$sql,INFO );
495
+				if ($db_conn->query($sql) === false) {
496
+					$this->logging->log('Error SQL insert : '.$sql,1,'');
497
+				}
498
+				$this->logging->log('SQL insertion OK',INFO );
499
+				// Get last id to insert oid/values in secondary table
500
+				$sql='SELECT LAST_INSERT_ID();';
501
+				if (($ret_code=$db_conn->query($sql)) === false) {
502
+					$this->logging->log('Erreur recuperation id',1,'');
503
+				}
504 504
 	            
505
-	            $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
506
-	            if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
507
-	            $this->trap_id=$inserted_id;
508
-	            break;
509
-	        default:
510
-	            $this->logging->log('Error SQL type unknown  : '.$this->trapsDB->trapDBType,1,'');
511
-	    }
505
+				$inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
506
+				if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
507
+				$this->trap_id=$inserted_id;
508
+				break;
509
+			default:
510
+				$this->logging->log('Error SQL type unknown  : '.$this->trapsDB->trapDBType,1,'');
511
+		}
512 512
 	    
513
-	    $this->logging->log('id found: '. $this->trap_id,INFO );    
513
+		$this->logging->log('id found: '. $this->trap_id,INFO );    
514 514
 	}
515 515
 	
516 516
 	/** Write trap data to trap database
517
-	*/
517
+	 */
518 518
 	public function writeTrapToDB()
519 519
 	{
520 520
 		
@@ -612,10 +612,10 @@  discard block
 block discarded – undo
612 612
 	}
613 613
 
614 614
 	/** Get rules from rule database with ip and oid
615
-	*	@param $ip string ipv4 or ipv6
616
-	*	@param $oid string oid in numeric
617
-	*	@return mixed : PDO object or false
618
-	*/	
615
+	 *	@param $ip string ipv4 or ipv6
616
+	 *	@param $oid string oid in numeric
617
+	 *	@return mixed : PDO object or false
618
+	 */	
619 619
 	protected function getRules($ip,$oid)
620 620
 	{
621 621
 		$db_conn=$this->trapsDB->db_connect_trap();
@@ -674,9 +674,9 @@  discard block
 block discarded – undo
674 674
 	}
675 675
 
676 676
 	/** Add rule match to rule
677
-	*	@param id int : rule id
678
-	*   @param set int : value to set
679
-	*/
677
+	 *	@param id int : rule id
678
+	 *   @param set int : value to set
679
+	 */
680 680
 	protected function add_rule_match($id, $set)
681 681
 	{
682 682
 		$db_conn=$this->trapsDB->db_connect_trap();
@@ -693,53 +693,53 @@  discard block
 block discarded – undo
693 693
 	 * @param integer $state numerical staus 
694 694
 	 * @param string $display
695 695
 	 * @returnn bool true is service check was sent without error
696
-	*/
696
+	 */
697 697
 	public function serviceCheckResult($host,$service,$state,$display)
698 698
 	{
699
-	    if ($this->api_use === false)
700
-	    {
701
-    		$send = '[' . date('U') .'] PROCESS_SERVICE_CHECK_RESULT;' .
702
-    			$host.';' .$service .';' . $state . ';'.$display;
703
-    		$this->logging->log( $send." : to : " .$this->icinga2cmd,INFO );
699
+		if ($this->api_use === false)
700
+		{
701
+			$send = '[' . date('U') .'] PROCESS_SERVICE_CHECK_RESULT;' .
702
+				$host.';' .$service .';' . $state . ';'.$display;
703
+			$this->logging->log( $send." : to : " .$this->icinga2cmd,INFO );
704 704
     		
705
-    		// TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default....
706
-    		exec('echo "'.$send.'" > ' .$this->icinga2cmd);
707
-    		return true;
708
-	    }
709
-	    else
710
-	    {
711
-	        $api = $this->getAPI();
712
-	        $api->setCredentials($this->api_username, $this->api_password);
713
-	        list($retcode,$retmessage)=$api->serviceCheckResult($host,$service,$state,$display);
714
-	        if ($retcode == false)
715
-	        {
716
-	            $this->logging->log( "Error sending result : " .$retmessage,WARN,'');
717
-	            return false;
718
-	        }
719
-	        else 
720
-	        {
721
-	            $this->logging->log( "Sent result : " .$retmessage,INFO );
722
-	            return true;
723
-	        }
724
-	    }
705
+			// TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default....
706
+			exec('echo "'.$send.'" > ' .$this->icinga2cmd);
707
+			return true;
708
+		}
709
+		else
710
+		{
711
+			$api = $this->getAPI();
712
+			$api->setCredentials($this->api_username, $this->api_password);
713
+			list($retcode,$retmessage)=$api->serviceCheckResult($host,$service,$state,$display);
714
+			if ($retcode == false)
715
+			{
716
+				$this->logging->log( "Error sending result : " .$retmessage,WARN,'');
717
+				return false;
718
+			}
719
+			else 
720
+			{
721
+				$this->logging->log( "Sent result : " .$retmessage,INFO );
722
+				return true;
723
+			}
724
+		}
725 725
 	}
726 726
 	
727 727
 	public function getHostByIP($ip)
728 728
 	{
729
-	    $api = $this->getAPI();
730
-	    $api->setCredentials($this->api_username, $this->api_password);
731
-	    return $api->getHostByIP($ip);
729
+		$api = $this->getAPI();
730
+		$api->setCredentials($this->api_username, $this->api_password);
731
+		return $api->getHostByIP($ip);
732 732
 	}
733 733
 	
734 734
 	/** Resolve display. 
735
-	*	Changes OID(<oid>) to value if found or text "<not in trap>"
736
-	*	@param $display string
737
-	*	@return string display
738
-	*/
735
+	 *	Changes OID(<oid>) to value if found or text "<not in trap>"
736
+	 *	@param $display string
737
+	 *	@return string display
738
+	 */
739 739
 	protected function applyDisplay($display)
740 740
 	{
741
-	    $matches=array();
742
-	    while (preg_match('/_OID\(([0-9\.]+)\)/',$display,$matches) == 1)
741
+		$matches=array();
742
+		while (preg_match('/_OID\(([0-9\.]+)\)/',$display,$matches) == 1)
743 743
 		{
744 744
 			$oid=$matches[1];
745 745
 			$found=0;
@@ -799,11 +799,11 @@  discard block
 block discarded – undo
799 799
 		
800 800
 		if ($rule[$item] == '(')
801 801
 		{ // grouping
802
-		    $item++;
802
+			$item++;
803 803
 			$start=$item;
804 804
 			$parenthesis_count=0; 
805 805
 			while (($item < strlen($rule)) // Not end of string AND
806
-			      && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded ()
806
+				  && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded ()
807 807
 			{ 
808 808
 				if ($rule[$item] == '"' )
809 809
 				{ // pass through string
@@ -811,14 +811,14 @@  discard block
 block discarded – undo
811 811
 					$item=$this->eval_getNext($rule,$item,'"');
812 812
 				} 
813 813
 				else{
814
-				    if ($rule[$item] == '(')
815
-				    {
816
-				        $parenthesis_count++;
817
-				    }
818
-				    if ($rule[$item] == ')')
819
-				    {
820
-				        $parenthesis_count--;
821
-				    }
814
+					if ($rule[$item] == '(')
815
+					{
816
+						$parenthesis_count++;
817
+					}
818
+					if ($rule[$item] == ')')
819
+					{
820
+						$parenthesis_count--;
821
+					}
822 822
 					$item++;
823 823
 				}
824 824
 			}
@@ -870,24 +870,24 @@  discard block
 block discarded – undo
870 870
 	}
871 871
 	
872 872
 	/** Evaluation : makes token and evaluate. 
873
-	*	Public function for expressions testing
874
-	*	accepts : < > = <= >= !=  (typec = 0)
875
-	*	operators : & | (typec=1)
876
-	*	with : integers/float  (type 0) or strings "" (type 1) or results (type 2)
877
-	*   comparison int vs strings will return null (error)
878
-	*	return : bool or null on error
879
-	*/
873
+	 *	Public function for expressions testing
874
+	 *	accepts : < > = <= >= !=  (typec = 0)
875
+	 *	operators : & | (typec=1)
876
+	 *	with : integers/float  (type 0) or strings "" (type 1) or results (type 2)
877
+	 *   comparison int vs strings will return null (error)
878
+	 *	return : bool or null on error
879
+	 */
880 880
 	public function evaluation($rule,&$item)
881 881
 	{
882
-	    //echo "Evaluation of ".substr($rule,$item)."\n";
882
+		//echo "Evaluation of ".substr($rule,$item)."\n";
883 883
 		if ( $rule[$item] == '!') // If '!' found, negate next expression.
884 884
 		{
885
-		    $negate=true;
886
-		    $item++;
885
+			$negate=true;
886
+			$item++;
887 887
 		}
888 888
 		else
889 889
 		{
890
-		    $negate=false;
890
+			$negate=false;
891 891
 		}
892 892
 		// First element : number, string or ()
893 893
 		list($type1,$val1) = $this->eval_getElement($rule,$item);
@@ -907,24 +907,24 @@  discard block
 block discarded – undo
907 907
 		// Third element : number, string or ()
908 908
 		if ( $rule[$item] == '!') // starts with a ! so evaluate whats next
909 909
 		{
910
-		    $item++;
911
-		    if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule);
912
-		    $val2= ! $this->evaluation($rule,$item);
913
-		    $type2=2; // result is a boolean 
910
+			$item++;
911
+			if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule);
912
+			$val2= ! $this->evaluation($rule,$item);
913
+			$type2=2; // result is a boolean 
914 914
 		}
915 915
 		else 
916 916
 		{
917
-		    list($type2,$val2) = $this->eval_getElement($rule,$item);
917
+			list($type2,$val2) = $this->eval_getElement($rule,$item);
918 918
 		}
919 919
 		//echo "Elmt2: ".$val2."/".$type2." : ".substr($rule,$item)."\n";
920 920
 		
921 921
 		if ($type1!=$type2)  // cannot compare different types
922 922
 		{ 
923
-		    throw new Exception("Cannot compare string & number : ".$rule);
923
+			throw new Exception("Cannot compare string & number : ".$rule);
924 924
 		}
925 925
 		if ($typec==1 && $type1 !=2) // cannot use & or | with string/number
926 926
 		{
927
-		    throw new Exception("Cannot use boolean operators with string & number : ".$rule);
927
+			throw new Exception("Cannot use boolean operators with string & number : ".$rule);
928 928
 		}
929 929
 		
930 930
 		switch ($comp){
@@ -982,9 +982,9 @@  discard block
 block discarded – undo
982 982
 	}		
983 983
 	
984 984
 	/** Evaluation rule (uses eval_* functions recursively)
985
-	*	@param $rule string rule ( _OID(.1.3.6.1.4.1.8072.2.3.2.1)=_OID(.1.3.6.1.2.1.1.3.0) )
986
-	*	@return bool : true : rule match, false : rule don't match , throw exception on error.
987
-	*/
985
+	 *	@param $rule string rule ( _OID(.1.3.6.1.4.1.8072.2.3.2.1)=_OID(.1.3.6.1.2.1.1.3.0) )
986
+	 *	@return bool : true : rule match, false : rule don't match , throw exception on error.
987
+	 */
988 988
 	
989 989
 	protected function eval_rule($rule)
990 990
 	{
@@ -1029,7 +1029,7 @@  discard block
 block discarded – undo
1029 1029
 			}
1030 1030
 			if ($found==0)
1031 1031
 			{	// OID not found : throw error
1032
-			    throw new Exception('OID '.$oid.' not found in trap');
1032
+				throw new Exception('OID '.$oid.' not found in trap');
1033 1033
 			}
1034 1034
 		}
1035 1035
 		$item=0;
@@ -1040,7 +1040,7 @@  discard block
 block discarded – undo
1040 1040
 	}
1041 1041
 	
1042 1042
 	/** Match rules for current trap and do action
1043
-	*/
1043
+	 */
1044 1044
 	public function applyRules()
1045 1045
 	{
1046 1046
 		$rules = $this->getRules($this->trap_data['source_ip'],$this->trap_data['trap_oid']);
@@ -1077,12 +1077,12 @@  discard block
 block discarded – undo
1077 1077
 					{
1078 1078
 						if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false)
1079 1079
 						{
1080
-						    $this->trap_action.='Error sending status : check cmd/API';
1080
+							$this->trap_action.='Error sending status : check cmd/API';
1081 1081
 						}
1082 1082
 						else
1083 1083
 						{
1084
-						    $this->add_rule_match($rule['id'],$rule['num_match']+1);
1085
-						    $this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
1084
+							$this->add_rule_match($rule['id'],$rule['num_match']+1);
1085
+							$this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
1086 1086
 						}
1087 1087
 					}
1088 1088
 					else
@@ -1099,15 +1099,15 @@  discard block
 block discarded – undo
1099 1099
 					$this->logging->log('action NOK : '.$action,INFO );
1100 1100
 					if ($action >= 0)
1101 1101
 					{
1102
-					    if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false)
1103
-					    {
1104
-					        $this->trap_action.='Error sending status : check cmd/API';
1105
-					    }
1106
-					    else
1107
-					    {
1108
-    						$this->add_rule_match($rule['id'],$rule['num_match']+1);
1109
-    						$this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
1110
-					    }
1102
+						if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false)
1103
+						{
1104
+							$this->trap_action.='Error sending status : check cmd/API';
1105
+						}
1106
+						else
1107
+						{
1108
+							$this->add_rule_match($rule['id'],$rule['num_match']+1);
1109
+							$this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
1110
+						}
1111 1111
 					}
1112 1112
 					else
1113 1113
 					{
@@ -1130,9 +1130,9 @@  discard block
 block discarded – undo
1130 1130
 			}
1131 1131
 			catch (Exception $e) 
1132 1132
 			{ 
1133
-			    $this->logging->log('Error in rule eval : '.$e->getMessage(),WARN,'');
1134
-			    $this->trap_action.=' ERR : '.$e->getMessage();
1135
-			    $this->trap_data['status']='error';
1133
+				$this->logging->log('Error in rule eval : '.$e->getMessage(),WARN,'');
1134
+				$this->trap_action.=' ERR : '.$e->getMessage();
1135
+				$this->trap_data['status']='error';
1136 1136
 			}
1137 1137
 			
1138 1138
 		}
@@ -1147,8 +1147,8 @@  discard block
 block discarded – undo
1147 1147
 	}
1148 1148
 
1149 1149
 	/** Add Time a action to rule
1150
-	*	@param string $time : time to process to insert in SQL
1151
-	*/
1150
+	 *	@param string $time : time to process to insert in SQL
1151
+	 */
1152 1152
 	public function add_rule_final($time)
1153 1153
 	{
1154 1154
 		$db_conn=$this->trapsDB->db_connect_trap();
@@ -1165,9 +1165,9 @@  discard block
 block discarded – undo
1165 1165
 	/*********** UTILITIES *********************/
1166 1166
 	
1167 1167
 	/** Create database schema 
1168
-	*	@param $schema_file	string File to read schema from
1169
-	*	@param $table_prefix string to replace #PREFIX# in schema file by this
1170
-	*/
1168
+	 *	@param $schema_file	string File to read schema from
1169
+	 *	@param $table_prefix string to replace #PREFIX# in schema file by this
1170
+	 */
1171 1171
 	public function create_schema($schema_file,$table_prefix)
1172 1172
 	{
1173 1173
 		//Read data from snmptrapd from stdin
@@ -1187,30 +1187,30 @@  discard block
 block discarded – undo
1187 1187
 		{
1188 1188
 			$newline.=chop(preg_replace('/#PREFIX#/',$table_prefix,$line));
1189 1189
 			if (preg_match('/; *$/', $newline)) 
1190
-            {
1191
-                $sql= $newline;
1192
-                if ($db_conn->query($sql) === false) {
1193
-                    $this->logging->log('Error create schema : '.$sql,ERROR,'');
1194
-                }
1195
-                if (preg_match('/^ *CREATE TABLE ([^ ]+)/',$newline,$cur_table_array))
1196
-                {
1197
-                    $cur_table='table '.$cur_table_array[1];
1198
-                }
1199
-                else
1200
-                {
1201
-                    $cur_table='secret SQL stuff :-)';
1202
-                }
1203
-                $this->logging->log('Creating : ' . $cur_table,INFO );
1204
-                $newline='';
1205
-            }
1190
+			{
1191
+				$sql= $newline;
1192
+				if ($db_conn->query($sql) === false) {
1193
+					$this->logging->log('Error create schema : '.$sql,ERROR,'');
1194
+				}
1195
+				if (preg_match('/^ *CREATE TABLE ([^ ]+)/',$newline,$cur_table_array))
1196
+				{
1197
+					$cur_table='table '.$cur_table_array[1];
1198
+				}
1199
+				else
1200
+				{
1201
+					$cur_table='secret SQL stuff :-)';
1202
+				}
1203
+				$this->logging->log('Creating : ' . $cur_table,INFO );
1204
+				$newline='';
1205
+			}
1206 1206
 		}
1207 1207
 		
1208 1208
 		$sql= $newline;
1209 1209
 		if ($sql != '')
1210 1210
 		{
1211
-    		if ($db_conn->query($sql) === false) {
1212
-    			$this->logging->log('Error create schema : '.$sql,ERROR,'');
1213
-    		}
1211
+			if ($db_conn->query($sql) === false) {
1212
+				$this->logging->log('Error create schema : '.$sql,ERROR,'');
1213
+			}
1214 1214
 		}
1215 1215
 		$this->logging->log('Schema created',INFO);		
1216 1216
 	}
@@ -1225,113 +1225,113 @@  discard block
 block discarded – undo
1225 1225
 	 */
1226 1226
 	public function update_schema($prefix,$target_version,$table_prefix,$getmsg=false)
1227 1227
 	{
1228
-	    // Get current db number
1229
-	    $db_conn=$this->trapsDB->db_connect_trap();
1230
-	    $sql='SELECT id,value from '.$this->db_prefix.'db_config WHERE name=\'db_version\' ';
1231
-	    $this->logging->log('SQL query : '.$sql,DEBUG );
1232
-	    if (($ret_code=$db_conn->query($sql)) === false) {
1233
-	        $this->logging->log('Cannot get db version. Query : ' . $sql,2,'');
1234
-	        return;
1235
-	    }
1236
-	    $version=$ret_code->fetchAll();
1237
-	    $cur_version=$version[0]['value'];
1238
-	    $db_version_id=$version[0]['id'];
1228
+		// Get current db number
1229
+		$db_conn=$this->trapsDB->db_connect_trap();
1230
+		$sql='SELECT id,value from '.$this->db_prefix.'db_config WHERE name=\'db_version\' ';
1231
+		$this->logging->log('SQL query : '.$sql,DEBUG );
1232
+		if (($ret_code=$db_conn->query($sql)) === false) {
1233
+			$this->logging->log('Cannot get db version. Query : ' . $sql,2,'');
1234
+			return;
1235
+		}
1236
+		$version=$ret_code->fetchAll();
1237
+		$cur_version=$version[0]['value'];
1238
+		$db_version_id=$version[0]['id'];
1239 1239
 	    
1240
-	    if ($this->trapsDB->trapDBType == 'pgsql')
1241
-	    {
1242
-	        $prefix .= 'update_pgsql/schema_';
1243
-	    }
1244
-	    else
1245
-	    {
1246
-	        $prefix .= 'update_sql/schema_';
1247
-	    }
1248
-	    //echo "version all :\n";print_r($version);echo " \n $cur_ver \n";
1249
-	    if ($getmsg === true)
1250
-	    {
1251
-	        $message='';
1252
-	        $this->logging->log('getting message for upgrade',DEBUG );
1253
-	        while($cur_version<$target_version)
1254
-	        {
1255
-	            $cur_version++;
1256
-	            $updateFile=$prefix.'v'.($cur_version-1).'_v'.$cur_version.'.sql';
1257
-	            $input_stream=fopen($updateFile, 'r');
1258
-	            if ($input_stream=== false)
1259
-	            {
1260
-	                $this->logging->log("Error reading update file ". $updateFile,2,'');
1261
-	                return;
1262
-	            }
1263
-	            do { $line=fgets($input_stream); }
1264
-	            while ($line !== false && !preg_match('/#MESSAGE/',$line));
1265
-	            if ($line === false)
1266
-	            {
1267
-	                $this->logging->log("No message in file ". $updateFile,2,'');
1268
-	                return;
1269
-	            }
1270
-	            $message .= ($cur_version-1) . '->' . $cur_version. ' : ' . preg_replace('/#MESSAGE : /','',$line)."\n";
1271
-	        }
1272
-	        return $message;
1273
-	    }
1274
-	    while($cur_version<$target_version)
1275
-	    { // tODO : execute pre & post scripts
1276
-	       $cur_version++;
1277
-	       $this->logging->log('Updating to version : ' .$cur_version ,INFO );
1278
-	       $updateFile=$prefix.'v'.($cur_version-1).'_v'.$cur_version.'.sql';
1279
-	       $input_stream=fopen($updateFile, 'r');
1280
-	       if ($input_stream=== false)
1281
-	       {
1282
-	           $this->logging->log("Error reading update file ". $updateFile,2,'');
1283
-	           return;
1284
-	       }
1285
-	       $newline='';
1286
-	       $db_conn=$this->trapsDB->db_connect_trap();
1287
-	       $db_conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
1288
-	       while (($line=fgets($input_stream)) !== false)
1289
-	       {
1290
-	           if (preg_match('/^#/', $line)) continue; // ignore comment lines
1291
-	           $newline.=chop(preg_replace('/#PREFIX#/',$table_prefix,$line));
1292
-	           if (preg_match('/; *$/', $newline))
1293
-	           {
1294
-	               $sql_req=$db_conn->prepare($newline);
1295
-	               if ($sql_req->execute() === false) {
1296
-	                   $this->logging->log('Error create schema : '.$newline,1,'');
1297
-	               }
1298
-	               $cur_table_array=array();
1299
-	               if (preg_match('/^ *([^ ]+) TABLE ([^ ]+)/',$newline,$cur_table_array))
1300
-	               {
1301
-	                   $cur_table=$cur_table_array[1] . ' SQL table '.$cur_table_array[2];
1302
-	               }
1303
-	               else
1304
-	               {
1305
-	                   $cur_table='secret SQL stuff :-)';
1306
-	                   //$cur_table=$newline;
1307
-	               }
1308
-	               $this->logging->log('Doing : ' . $cur_table,INFO );
1240
+		if ($this->trapsDB->trapDBType == 'pgsql')
1241
+		{
1242
+			$prefix .= 'update_pgsql/schema_';
1243
+		}
1244
+		else
1245
+		{
1246
+			$prefix .= 'update_sql/schema_';
1247
+		}
1248
+		//echo "version all :\n";print_r($version);echo " \n $cur_ver \n";
1249
+		if ($getmsg === true)
1250
+		{
1251
+			$message='';
1252
+			$this->logging->log('getting message for upgrade',DEBUG );
1253
+			while($cur_version<$target_version)
1254
+			{
1255
+				$cur_version++;
1256
+				$updateFile=$prefix.'v'.($cur_version-1).'_v'.$cur_version.'.sql';
1257
+				$input_stream=fopen($updateFile, 'r');
1258
+				if ($input_stream=== false)
1259
+				{
1260
+					$this->logging->log("Error reading update file ". $updateFile,2,'');
1261
+					return;
1262
+				}
1263
+				do { $line=fgets($input_stream); }
1264
+				while ($line !== false && !preg_match('/#MESSAGE/',$line));
1265
+				if ($line === false)
1266
+				{
1267
+					$this->logging->log("No message in file ". $updateFile,2,'');
1268
+					return;
1269
+				}
1270
+				$message .= ($cur_version-1) . '->' . $cur_version. ' : ' . preg_replace('/#MESSAGE : /','',$line)."\n";
1271
+			}
1272
+			return $message;
1273
+		}
1274
+		while($cur_version<$target_version)
1275
+		{ // tODO : execute pre & post scripts
1276
+		   $cur_version++;
1277
+		   $this->logging->log('Updating to version : ' .$cur_version ,INFO );
1278
+		   $updateFile=$prefix.'v'.($cur_version-1).'_v'.$cur_version.'.sql';
1279
+		   $input_stream=fopen($updateFile, 'r');
1280
+		   if ($input_stream=== false)
1281
+		   {
1282
+			   $this->logging->log("Error reading update file ". $updateFile,2,'');
1283
+			   return;
1284
+		   }
1285
+		   $newline='';
1286
+		   $db_conn=$this->trapsDB->db_connect_trap();
1287
+		   $db_conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
1288
+		   while (($line=fgets($input_stream)) !== false)
1289
+		   {
1290
+			   if (preg_match('/^#/', $line)) continue; // ignore comment lines
1291
+			   $newline.=chop(preg_replace('/#PREFIX#/',$table_prefix,$line));
1292
+			   if (preg_match('/; *$/', $newline))
1293
+			   {
1294
+				   $sql_req=$db_conn->prepare($newline);
1295
+				   if ($sql_req->execute() === false) {
1296
+					   $this->logging->log('Error create schema : '.$newline,1,'');
1297
+				   }
1298
+				   $cur_table_array=array();
1299
+				   if (preg_match('/^ *([^ ]+) TABLE ([^ ]+)/',$newline,$cur_table_array))
1300
+				   {
1301
+					   $cur_table=$cur_table_array[1] . ' SQL table '.$cur_table_array[2];
1302
+				   }
1303
+				   else
1304
+				   {
1305
+					   $cur_table='secret SQL stuff :-)';
1306
+					   //$cur_table=$newline;
1307
+				   }
1308
+				   $this->logging->log('Doing : ' . $cur_table,INFO );
1309 1309
 	               
1310
-	               $newline='';
1311
-	           }
1312
-	       }
1313
-	       fclose($input_stream);
1310
+				   $newline='';
1311
+			   }
1312
+		   }
1313
+		   fclose($input_stream);
1314 1314
 	       
1315
-	       //$sql= $newline;
1316
-	       //if ($db_conn->query($sql) === false) {
1317
-	       //    $this->logging->log('Error updating schema : '.$sql,1,'');
1318
-	       //}
1315
+		   //$sql= $newline;
1316
+		   //if ($db_conn->query($sql) === false) {
1317
+		   //    $this->logging->log('Error updating schema : '.$sql,1,'');
1318
+		   //}
1319 1319
 	       
1320
-	       $sql='UPDATE '.$this->db_prefix.'db_config SET value='.$cur_version.' WHERE ( id = '.$db_version_id.' )';
1321
-	       $this->logging->log('SQL query : '.$sql,DEBUG );
1322
-	       if ($db_conn->query($sql) === false) {
1323
-	           $this->logging->log('Cannot update db version. Query : ' . $sql,2);
1324
-	           return;
1325
-	       }
1320
+		   $sql='UPDATE '.$this->db_prefix.'db_config SET value='.$cur_version.' WHERE ( id = '.$db_version_id.' )';
1321
+		   $this->logging->log('SQL query : '.$sql,DEBUG );
1322
+		   if ($db_conn->query($sql) === false) {
1323
+			   $this->logging->log('Cannot update db version. Query : ' . $sql,2);
1324
+			   return;
1325
+		   }
1326 1326
 	       
1327
-	       $this->logging->log('Schema updated to version : '.$cur_version ,INFO);
1328
-	    }
1327
+		   $this->logging->log('Schema updated to version : '.$cur_version ,INFO);
1328
+		}
1329 1329
 	}
1330 1330
 	
1331 1331
 	/** reset service to OK after time defined in rule
1332
-	*	TODO logic is : get all service in error + all rules, see if getting all rules then select services is better 
1333
-	*	@return : like a plugin : status code (0->3) <message> | <perfdata>
1334
-	**/
1332
+	 *	TODO logic is : get all service in error + all rules, see if getting all rules then select services is better 
1333
+	 *	@return : like a plugin : status code (0->3) <message> | <perfdata>
1334
+	 **/
1335 1335
 	public function reset_services()
1336 1336
 	{
1337 1337
 		// Get all services not in 'ok' state
@@ -1401,105 +1401,105 @@  discard block
 block discarded – undo
1401 1401
 		$description=$db_conn->quote($description);
1402 1402
 		if (isset($this->dbOidIndex[$oid]))
1403 1403
 		{
1404
-		    if ($this->dbOidIndex[$oid]['key'] == -1)
1405
-		    { // newly created.
1406
-		        return 0;
1407
-		    }
1404
+			if ($this->dbOidIndex[$oid]['key'] == -1)
1405
+			{ // newly created.
1406
+				return 0;
1407
+			}
1408 1408
 			if ( $name != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['name'] ||
1409
-			    $mib != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['mib'] ||
1410
-			    $type != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['type'] //||
1411
-			    //$textConv != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['textual_convention'] //||
1412
-			    //$dispHint != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['display_hint'] ||
1413
-			    //$syntax != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['syntax'] ||
1414
-			    //$type_enum != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['type_enum'] ||
1415
-			    //$description != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['description']
1416
-			    )
1409
+				$mib != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['mib'] ||
1410
+				$type != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['type'] //||
1411
+				//$textConv != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['textual_convention'] //||
1412
+				//$dispHint != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['display_hint'] ||
1413
+				//$syntax != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['syntax'] ||
1414
+				//$type_enum != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['type_enum'] ||
1415
+				//$description != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['description']
1416
+				)
1417 1417
 			{ // Do update
1418
-			    $sql='UPDATE '.$this->db_prefix.'mib_cache SET '.
1419
- 			    'name = :name , type = :type , mib = :mib , textual_convention = :tc , display_hint = :display_hint'. 
1420
- 			    ', syntax = :syntax, type_enum = :type_enum, description = :description '.
1421
- 			    ' WHERE id= :id';
1422
-			    $sqlQuery=$db_conn->prepare($sql);
1418
+				$sql='UPDATE '.$this->db_prefix.'mib_cache SET '.
1419
+ 				'name = :name , type = :type , mib = :mib , textual_convention = :tc , display_hint = :display_hint'. 
1420
+ 				', syntax = :syntax, type_enum = :type_enum, description = :description '.
1421
+ 				' WHERE id= :id';
1422
+				$sqlQuery=$db_conn->prepare($sql);
1423 1423
 			    
1424
-			    $sqlParam=array(
1425
-			        ':name' => $name,
1426
-			        ':type' => $type, 
1427
-			        ':mib' => $mib, 
1428
-			        ':tc' =>  ($textConv==null)?'null':$textConv , 
1429
-			        ':display_hint' => ($dispHint==null)?'null':$dispHint ,
1430
-			        ':syntax' => ($syntax==null)?'null':$syntax,
1431
-			        ':type_enum' => ($type_enum==null)?'null':$type_enum, 
1432
-			        ':description' => ($description==null)?'null':$description,
1433
-			        ':id' => $this->dbOidAll[$this->dbOidIndex[$oid]['id']]
1434
-			    );
1424
+				$sqlParam=array(
1425
+					':name' => $name,
1426
+					':type' => $type, 
1427
+					':mib' => $mib, 
1428
+					':tc' =>  ($textConv==null)?'null':$textConv , 
1429
+					':display_hint' => ($dispHint==null)?'null':$dispHint ,
1430
+					':syntax' => ($syntax==null)?'null':$syntax,
1431
+					':type_enum' => ($type_enum==null)?'null':$type_enum, 
1432
+					':description' => ($description==null)?'null':$description,
1433
+					':id' => $this->dbOidAll[$this->dbOidIndex[$oid]['id']]
1434
+				);
1435 1435
 			    
1436
-			    if ($sqlQuery->execute($sqlParam) === false) {
1437
-			        $this->logging->log('Error in query : ' . $sql,ERROR,'');
1438
-			    }
1439
-			    $this->logging->log('Trap updated : '.$name . ' / OID : '.$oid,DEBUG );
1436
+				if ($sqlQuery->execute($sqlParam) === false) {
1437
+					$this->logging->log('Error in query : ' . $sql,ERROR,'');
1438
+				}
1439
+				$this->logging->log('Trap updated : '.$name . ' / OID : '.$oid,DEBUG );
1440 1440
 				return 1;
1441 1441
 			}
1442 1442
 			else
1443 1443
 			{
1444
-			    $this->logging->log('Trap unchanged : '.$name . ' / OID : '.$oid,DEBUG );
1445
-			    return 0;
1444
+				$this->logging->log('Trap unchanged : '.$name . ' / OID : '.$oid,DEBUG );
1445
+				return 0;
1446 1446
 			}
1447 1447
 		}
1448
-        // create new OID.
1448
+		// create new OID.
1449 1449
 			
1450 1450
 		// Insert data
1451 1451
 
1452 1452
 		$sql='INSERT INTO '.$this->db_prefix.'mib_cache '.
1453
-		      '(oid, name, type , mib, textual_convention, display_hint '.
1454
-              ', syntax, type_enum , description ) ' . 
1455
-              'values (:oid, :name , :type ,:mib ,:tc , :display_hint'.
1456
-              ', :syntax, :type_enum, :description )';
1453
+			  '(oid, name, type , mib, textual_convention, display_hint '.
1454
+			  ', syntax, type_enum , description ) ' . 
1455
+			  'values (:oid, :name , :type ,:mib ,:tc , :display_hint'.
1456
+			  ', :syntax, :type_enum, :description )';
1457 1457
         
1458 1458
 		if ($this->trapsDB->trapDBType == 'pgsql') $sql .= 'RETURNING id';
1459 1459
 		
1460 1460
 		$sqlQuery=$db_conn->prepare($sql);
1461 1461
 		
1462 1462
 		$sqlParam=array(
1463
-		    ':oid' => $oid,
1464
-		    ':name' => $name,
1465
-		    ':type' => $type,
1466
-		    ':mib' => $mib,
1467
-		    ':tc' =>  ($textConv==null)?'null':$textConv ,
1468
-		    ':display_hint' => ($dispHint==null)?'null':$dispHint ,
1469
-		    ':syntax' => ($syntax==null)?'null':$syntax,
1470
-		    ':type_enum' => ($type_enum==null)?'null':$type_enum,
1471
-		    ':description' => ($description==null)?'null':$description
1463
+			':oid' => $oid,
1464
+			':name' => $name,
1465
+			':type' => $type,
1466
+			':mib' => $mib,
1467
+			':tc' =>  ($textConv==null)?'null':$textConv ,
1468
+			':display_hint' => ($dispHint==null)?'null':$dispHint ,
1469
+			':syntax' => ($syntax==null)?'null':$syntax,
1470
+			':type_enum' => ($type_enum==null)?'null':$type_enum,
1471
+			':description' => ($description==null)?'null':$description
1472 1472
 		);
1473 1473
 		
1474 1474
 		if ($sqlQuery->execute($sqlParam) === false) {
1475
-		    $this->logging->log('Error in query : ' . $sql,1,'');
1475
+			$this->logging->log('Error in query : ' . $sql,1,'');
1476 1476
 		}
1477 1477
 		
1478 1478
 		switch ($this->trapsDB->trapDBType)
1479 1479
 		{
1480
-		    case 'pgsql':
1481
-		        // Get last id to insert oid/values in secondary table
1482
-		        if (($inserted_id_ret=$sqlQuery->fetch(PDO::FETCH_ASSOC)) === false) {		            
1483
-		            $this->logging->log('Error getting id - pgsql - ',1,'');
1484
-		        }
1485
-		        if (! isset($inserted_id_ret['id'])) {
1486
-		            $this->logging->log('Error getting id - pgsql - empty.',1,'');
1487
-		        }
1488
-		        $this->dbOidIndex[$oid]['id']=$inserted_id_ret['id'];
1489
-		        break;
1490
-		    case 'mysql':
1491
-		        // Get last id to insert oid/values in secondary table
1492
-		        $sql='SELECT LAST_INSERT_ID();';
1493
-		        if (($ret_code=$db_conn->query($sql)) === false) {
1494
-		            $this->logging->log('Erreur getting id - mysql - ',1,'');
1495
-		        }
1480
+			case 'pgsql':
1481
+				// Get last id to insert oid/values in secondary table
1482
+				if (($inserted_id_ret=$sqlQuery->fetch(PDO::FETCH_ASSOC)) === false) {		            
1483
+					$this->logging->log('Error getting id - pgsql - ',1,'');
1484
+				}
1485
+				if (! isset($inserted_id_ret['id'])) {
1486
+					$this->logging->log('Error getting id - pgsql - empty.',1,'');
1487
+				}
1488
+				$this->dbOidIndex[$oid]['id']=$inserted_id_ret['id'];
1489
+				break;
1490
+			case 'mysql':
1491
+				// Get last id to insert oid/values in secondary table
1492
+				$sql='SELECT LAST_INSERT_ID();';
1493
+				if (($ret_code=$db_conn->query($sql)) === false) {
1494
+					$this->logging->log('Erreur getting id - mysql - ',1,'');
1495
+				}
1496 1496
 		        
1497
-		        $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
1498
-		        if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
1499
-		        $this->dbOidIndex[$oid]['id']=$inserted_id;
1500
-		        break;
1501
-		    default:
1502
-		        $this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType,1,'');
1497
+				$inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
1498
+				if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
1499
+				$this->dbOidIndex[$oid]['id']=$inserted_id;
1500
+				break;
1501
+			default:
1502
+				$this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType,1,'');
1503 1503
 		}
1504 1504
 
1505 1505
 		// Set as newly created.
@@ -1507,148 +1507,148 @@  discard block
 block discarded – undo
1507 1507
 		return 2;
1508 1508
 	}
1509 1509
 
1510
-    /**
1511
-     * create or update (with check_existing = true) objects of trap
1512
-     * @param string $trapOID : trap oid
1513
-     * @param string $trapmib : mib of trap
1514
-     * @param array $objects : array of objects name (without MIB)
1515
-     * @param bool $check_existing : check instead of create
1516
-     */
1510
+	/**
1511
+	 * create or update (with check_existing = true) objects of trap
1512
+	 * @param string $trapOID : trap oid
1513
+	 * @param string $trapmib : mib of trap
1514
+	 * @param array $objects : array of objects name (without MIB)
1515
+	 * @param bool $check_existing : check instead of create
1516
+	 */
1517 1517
 	public function trap_objects($trapOID,$trapmib,$objects,$check_existing)
1518 1518
 	{
1519
-	    $dbObjects=null; // cache of objects for trap in db
1520
-	    $db_conn=$this->trapsDB->db_connect_trap();
1519
+		$dbObjects=null; // cache of objects for trap in db
1520
+		$db_conn=$this->trapsDB->db_connect_trap();
1521 1521
 	    
1522
-	    // Get id of trapmib.
1522
+		// Get id of trapmib.
1523 1523
 
1524
-	    $trapId = $this->dbOidIndex[$trapOID]['id'];
1525
-	    if ($check_existing === true)
1526
-	    {
1527
-	        // Get all objects
1528
-	        $sql='SELECT * FROM '.$this->db_prefix.'mib_cache_trap_object where trap_id='.$trapId.';';
1529
-	        $this->logging->log('SQL query get all traps: '.$sql,DEBUG );
1530
-	        if (($ret_code=$db_conn->query($sql)) === false) {
1531
-	            $this->logging->log('No result in query : ' . $sql,1,'');
1532
-	        }
1533
-	        $dbObjectsRaw=$ret_code->fetchAll();
1524
+		$trapId = $this->dbOidIndex[$trapOID]['id'];
1525
+		if ($check_existing === true)
1526
+		{
1527
+			// Get all objects
1528
+			$sql='SELECT * FROM '.$this->db_prefix.'mib_cache_trap_object where trap_id='.$trapId.';';
1529
+			$this->logging->log('SQL query get all traps: '.$sql,DEBUG );
1530
+			if (($ret_code=$db_conn->query($sql)) === false) {
1531
+				$this->logging->log('No result in query : ' . $sql,1,'');
1532
+			}
1533
+			$dbObjectsRaw=$ret_code->fetchAll();
1534 1534
 	        
1535
-	        foreach ($dbObjectsRaw as $val)
1536
-	        {
1537
-	            $dbObjects[$val['object_id']]=1;
1538
-	        }
1539
-	    }
1540
-	    foreach ($objects as $object)
1541
-	    {
1542
-	        $match=$snmptrans=array();
1543
-	        $retVal=0;
1544
-	        $objOid=$objTc=$objDispHint=$objSyntax=$objDesc=$objEnum=NULL;
1545
-	        $tmpdesc='';$indesc=false;
1535
+			foreach ($dbObjectsRaw as $val)
1536
+			{
1537
+				$dbObjects[$val['object_id']]=1;
1538
+			}
1539
+		}
1540
+		foreach ($objects as $object)
1541
+		{
1542
+			$match=$snmptrans=array();
1543
+			$retVal=0;
1544
+			$objOid=$objTc=$objDispHint=$objSyntax=$objDesc=$objEnum=NULL;
1545
+			$tmpdesc='';$indesc=false;
1546 1546
 	        
1547
-	        $objMib=$trapmib;
1548
-	        exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
1549
-	            ' -On -Td '.$objMib.'::'.$object . ' 2>/dev/null',$snmptrans,$retVal);
1550
-	        if ($retVal!=0)
1551
-	        {
1552
-	            // Maybe not trap mib, search with IR
1553
-	            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
1554
-	                ' -IR '.$object . ' 2>/dev/null',$snmptrans,$retVal);
1555
-	            if ($retVal != 0 || !preg_match('/(.*)::(.*)/',$snmptrans[0],$match))
1556
-	            { // Not found -> continue with warning
1557
-	               $this->logging->log('Error finding trap object : '.$trapmib.'::'.$object,2,'');
1558
-	               continue;
1559
-	            }
1560
-	            $objMib=$match[1];
1547
+			$objMib=$trapmib;
1548
+			exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
1549
+				' -On -Td '.$objMib.'::'.$object . ' 2>/dev/null',$snmptrans,$retVal);
1550
+			if ($retVal!=0)
1551
+			{
1552
+				// Maybe not trap mib, search with IR
1553
+				exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
1554
+					' -IR '.$object . ' 2>/dev/null',$snmptrans,$retVal);
1555
+				if ($retVal != 0 || !preg_match('/(.*)::(.*)/',$snmptrans[0],$match))
1556
+				{ // Not found -> continue with warning
1557
+				   $this->logging->log('Error finding trap object : '.$trapmib.'::'.$object,2,'');
1558
+				   continue;
1559
+				}
1560
+				$objMib=$match[1];
1561 1561
 	            
1562
-	            // Do the snmptranslate again.
1563
-	            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
1564
-	                ' -On -Td '.$objMib.'::'.$object,$snmptrans,$retVal);
1565
-	            if ($retVal!=0) {
1566
-	                $this->logging->log('Error finding trap object : '.$objMib.'::'.$object,2,'');
1567
-	            }
1562
+				// Do the snmptranslate again.
1563
+				exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
1564
+					' -On -Td '.$objMib.'::'.$object,$snmptrans,$retVal);
1565
+				if ($retVal!=0) {
1566
+					$this->logging->log('Error finding trap object : '.$objMib.'::'.$object,2,'');
1567
+				}
1568 1568
 	            
1569
-	        }
1570
-	        foreach ($snmptrans as $line)
1571
-	        {
1572
-	            if ($indesc===true)
1573
-	            {
1574
-	                $line=preg_replace('/[\t ]+/',' ',$line);
1575
-	                if (preg_match('/(.*)"$/', $line,$match))
1576
-	                {
1577
-	                    $objDesc = $tmpdesc . $match[1];
1578
-	                    $indesc=false;
1579
-	                }
1580
-	                $tmpdesc.=$line;
1581
-	                continue;
1582
-	            }
1583
-	            if (preg_match('/^\.[0-9\.]+$/', $line))
1584
-	            {
1585
-	                $objOid=$line;
1586
-	                continue;
1587
-	            }
1588
-	            if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/',$line,$match))
1589
-	            {
1590
-	                $objSyntax=$match[1];
1591
-                    $objEnum=$match[2];
1592
-	                continue;
1593
-	            }
1594
-	            if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/',$line,$match))
1595
-	            {
1596
-	                $objSyntax=$match[1];
1597
-	                continue;
1598
-	            }
1599
-	            if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/',$line,$match))
1600
-	            {
1601
-	                $objDispHint=$match[1];
1602
-	                continue;
1603
-	            }
1604
-	            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/',$line,$match))
1605
-	            {
1606
-	                $objDesc=$match[1];
1607
-	                continue;
1608
-	            }
1609
-	            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$line,$match))
1610
-	            {
1611
-	                $tmpdesc=$match[1];
1612
-	                $indesc=true;
1613
-	                continue;
1614
-	            }
1615
-	            if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/',$line,$match))
1616
-	            {
1617
-	                $objTc=$match[1];
1618
-	                continue;
1619
-	            }
1620
-	        }
1621
-	        $this->logging->log("Adding trap $object : $objOid / $objSyntax / $objEnum / $objDispHint / $objTc",DEBUG );
1622
-	        //echo "$object : $objOid / $objSyntax / $objEnum / $objDispHint / $objTc / $objDesc\n";
1623
-	        // Update 
1624
-	        $this->update_oid($objOid, $objMib, $object, '3', $objTc, $objDispHint, $objSyntax, $objEnum,$objDesc);
1569
+			}
1570
+			foreach ($snmptrans as $line)
1571
+			{
1572
+				if ($indesc===true)
1573
+				{
1574
+					$line=preg_replace('/[\t ]+/',' ',$line);
1575
+					if (preg_match('/(.*)"$/', $line,$match))
1576
+					{
1577
+						$objDesc = $tmpdesc . $match[1];
1578
+						$indesc=false;
1579
+					}
1580
+					$tmpdesc.=$line;
1581
+					continue;
1582
+				}
1583
+				if (preg_match('/^\.[0-9\.]+$/', $line))
1584
+				{
1585
+					$objOid=$line;
1586
+					continue;
1587
+				}
1588
+				if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/',$line,$match))
1589
+				{
1590
+					$objSyntax=$match[1];
1591
+					$objEnum=$match[2];
1592
+					continue;
1593
+				}
1594
+				if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/',$line,$match))
1595
+				{
1596
+					$objSyntax=$match[1];
1597
+					continue;
1598
+				}
1599
+				if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/',$line,$match))
1600
+				{
1601
+					$objDispHint=$match[1];
1602
+					continue;
1603
+				}
1604
+				if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/',$line,$match))
1605
+				{
1606
+					$objDesc=$match[1];
1607
+					continue;
1608
+				}
1609
+				if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$line,$match))
1610
+				{
1611
+					$tmpdesc=$match[1];
1612
+					$indesc=true;
1613
+					continue;
1614
+				}
1615
+				if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/',$line,$match))
1616
+				{
1617
+					$objTc=$match[1];
1618
+					continue;
1619
+				}
1620
+			}
1621
+			$this->logging->log("Adding trap $object : $objOid / $objSyntax / $objEnum / $objDispHint / $objTc",DEBUG );
1622
+			//echo "$object : $objOid / $objSyntax / $objEnum / $objDispHint / $objTc / $objDesc\n";
1623
+			// Update 
1624
+			$this->update_oid($objOid, $objMib, $object, '3', $objTc, $objDispHint, $objSyntax, $objEnum,$objDesc);
1625 1625
             
1626
-	        if (isset($dbObjects[$this->dbOidIndex[$objOid]['id']]))
1627
-	        {   // if link exists, continue
1628
-	            $dbObjects[$this->dbOidIndex[$objOid]['id']]=2;
1629
-	            continue;
1630
-	        }
1631
-	        if ($check_existing === true) 
1632
-	        {
1633
-	            // TODO : check link trap - objects exists, mark them.
1634
-	        }
1635
-	        // Associate in object table
1636
-	        $sql='INSERT INTO '.$this->db_prefix.'mib_cache_trap_object (trap_id,object_id) '.
1637
-	   	        'values (:trap_id, :object_id)';	        
1638
-	        $sqlQuery=$db_conn->prepare($sql);	        
1639
-	        $sqlParam=array(
1640
-	            ':trap_id' => $trapId,
1641
-	            ':object_id' => $this->dbOidIndex[$objOid]['id'],
1642
-	        );
1626
+			if (isset($dbObjects[$this->dbOidIndex[$objOid]['id']]))
1627
+			{   // if link exists, continue
1628
+				$dbObjects[$this->dbOidIndex[$objOid]['id']]=2;
1629
+				continue;
1630
+			}
1631
+			if ($check_existing === true) 
1632
+			{
1633
+				// TODO : check link trap - objects exists, mark them.
1634
+			}
1635
+			// Associate in object table
1636
+			$sql='INSERT INTO '.$this->db_prefix.'mib_cache_trap_object (trap_id,object_id) '.
1637
+	   			'values (:trap_id, :object_id)';	        
1638
+			$sqlQuery=$db_conn->prepare($sql);	        
1639
+			$sqlParam=array(
1640
+				':trap_id' => $trapId,
1641
+				':object_id' => $this->dbOidIndex[$objOid]['id'],
1642
+			);
1643 1643
 	        
1644
-	        if ($sqlQuery->execute($sqlParam) === false) {
1645
-	            $this->logging->log('Error adding trap object : ' . $sql . ' / ' . $trapId . '/'. $this->dbOidIndex[$objOid]['id'] ,1,'');
1646
-	        }
1647
-	    }
1648
-	    if ($check_existing === true)
1649
-	    {
1650
-	        // TODO : remove link trap - objects that wasn't marked.
1651
-	    }
1644
+			if ($sqlQuery->execute($sqlParam) === false) {
1645
+				$this->logging->log('Error adding trap object : ' . $sql . ' / ' . $trapId . '/'. $this->dbOidIndex[$objOid]['id'] ,1,'');
1646
+			}
1647
+		}
1648
+		if ($check_existing === true)
1649
+		{
1650
+			// TODO : remove link trap - objects that wasn't marked.
1651
+		}
1652 1652
 	    
1653 1653
 	}
1654 1654
 	
@@ -1658,7 +1658,7 @@  discard block
 block discarded – undo
1658 1658
 	 * @param boolean $check_change : Force check of trap params & objects
1659 1659
 	 * @param boolean $onlyTraps : only cache traps and objects (true) or all (false)
1660 1660
 	 * @param string $startOID : only cache under startOID (NOT IMPLEMENTED)
1661
-	*/	
1661
+	 */	
1662 1662
 	public function update_mib_database($display_progress=false,$check_change=false,$onlyTraps=true,$startOID='.1')
1663 1663
 	{
1664 1664
 		// Timing 
@@ -1710,7 +1710,7 @@  discard block
 block discarded – undo
1710 1710
 		
1711 1711
 		for ($curElement=0;$curElement < $numElements;$curElement++)
1712 1712
 		{
1713
-		    $time_1= microtime(true);
1713
+			$time_1= microtime(true);
1714 1714
 			if ((microtime(true)-$timeFiveSec) > 2 && $display_progress)
1715 1715
 			{ // echo a . every 2 sec
1716 1716
 				echo '.';
@@ -1728,8 +1728,8 @@  discard block
 block discarded – undo
1728 1728
 			// Get oid or pass if not found
1729 1729
 			if (!preg_match('/^\.[0-9\.]+$/',$this->objectsAll[$curElement]))
1730 1730
 			{
1731
-			    $time_parse1 += microtime(true) - $time_1;
1732
-			    $time_parse1N ++;
1731
+				$time_parse1 += microtime(true) - $time_1;
1732
+				$time_parse1N ++;
1733 1733
 				continue;
1734 1734
 			}
1735 1735
 			$oid=$this->objectsAll[$curElement];
@@ -1740,7 +1740,7 @@  discard block
 block discarded – undo
1740 1740
 			if (!preg_match('/ +([^\(]+)\(.+\) type=([0-9]+)( tc=([0-9]+))?( hint=(.+))?/',
1741 1741
 						$this->objectsAll[$curElement],$match))
1742 1742
 			{
1743
-			    $time_check1 += microtime(true) - $time_1;
1743
+				$time_check1 += microtime(true) - $time_1;
1744 1744
 				$time_check1N++;
1745 1745
 				continue;
1746 1746
 			}
@@ -1753,8 +1753,8 @@  discard block
 block discarded – undo
1753 1753
 				// Check if next is suboid -> in that case is cannot be a trap
1754 1754
 				if (preg_match("/^$oid/",$this->objectsAll[$curElement+1]))
1755 1755
 				{
1756
-				    $time_check2 += microtime(true) - $time_1;
1757
-				    $time_check2N++;
1756
+					$time_check2 += microtime(true) - $time_1;
1757
+					$time_check2N++;
1758 1758
 					continue;
1759 1759
 				}		
1760 1760
 				unset($snmptrans);
@@ -1762,8 +1762,8 @@  discard block
 block discarded – undo
1762 1762
 					' -Td '.$oid . ' | grep OBJECTS ',$snmptrans,$retVal);
1763 1763
 				if ($retVal!=0)
1764 1764
 				{
1765
-				    $time_check2 += microtime(true) - $time_1;
1766
-				    $time_check2N++;
1765
+					$time_check2 += microtime(true) - $time_1;
1766
+					$time_check2N++;
1767 1767
 					continue;
1768 1768
 				}
1769 1769
 				//echo "\n v1 trap found : $oid \n";
@@ -1772,7 +1772,7 @@  discard block
 block discarded – undo
1772 1772
 			}
1773 1773
 			if ($onlyTraps===true && $type!=21) // if only traps and not a trap, continue
1774 1774
 			{
1775
-			    $time_check3 += microtime(true) - $time_1;
1775
+				$time_check3 += microtime(true) - $time_1;
1776 1776
 				$time_check3N++;
1777 1777
 				continue;
1778 1778
 			}
@@ -1793,7 +1793,7 @@  discard block
 block discarded – undo
1793 1793
 			
1794 1794
 			if (!preg_match('/^(.*)::/',$snmptrans[0],$match))
1795 1795
 			{
1796
-			    $this->logging->log('Error getting mib from trap '.$oid.' : ' . $snmptrans[0],1,'');
1796
+				$this->logging->log('Error getting mib from trap '.$oid.' : ' . $snmptrans[0],1,'');
1797 1797
 			}
1798 1798
 			$trapMib=$match[1];
1799 1799
 			
@@ -1801,17 +1801,17 @@  discard block
 block discarded – undo
1801 1801
 			while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++;
1802 1802
 			if (isset($snmptrans[$numLine]))
1803 1803
 			{
1804
-			    $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]);
1804
+				$snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]);
1805 1805
 
1806
-			    while (isset($snmptrans[$numLine]) && !preg_match('/"/',$snmptrans[$numLine]))
1807
-			    {
1808
-			        $trapDesc.=preg_replace('/[\t ]+/',' ',$snmptrans[$numLine]);
1809
-			        $numLine++;
1810
-			    }
1811
-			    if (isset($snmptrans[$numLine])) {
1812
-			        $trapDesc.=preg_replace('/".*/','',$snmptrans[$numLine]);
1813
-			        $trapDesc=preg_replace('/[\t ]+/',' ',$trapDesc);
1814
-			    }
1806
+				while (isset($snmptrans[$numLine]) && !preg_match('/"/',$snmptrans[$numLine]))
1807
+				{
1808
+					$trapDesc.=preg_replace('/[\t ]+/',' ',$snmptrans[$numLine]);
1809
+					$numLine++;
1810
+				}
1811
+				if (isset($snmptrans[$numLine])) {
1812
+					$trapDesc.=preg_replace('/".*/','',$snmptrans[$numLine]);
1813
+					$trapDesc=preg_replace('/[\t ]+/',' ',$trapDesc);
1814
+				}
1815 1815
 
1816 1816
 			}
1817 1817
 			$update=$this->update_oid($oid,$trapMib,$name,$type,NULL,NULL,NULL,NULL,$trapDesc);
@@ -1819,23 +1819,23 @@  discard block
 block discarded – undo
1819 1819
 			
1820 1820
 			if (($update==0) && ($check_change===false))
1821 1821
 			{ // Trapd didn't change & force check disabled
1822
-			    $time_objects += microtime(true) - $time_1;
1823
-			    if ($display_progress) echo "C";
1824
-			    continue;
1822
+				$time_objects += microtime(true) - $time_1;
1823
+				if ($display_progress) echo "C";
1824
+				continue;
1825 1825
 			}
1826 1826
 			
1827 1827
 			$synt=null;
1828 1828
 			foreach ($snmptrans as $line)
1829 1829
 			{	
1830
-    			if (preg_match('/OBJECTS.*\{([^\}]+)\}/',$line,$match))
1831
-    				{
1832
-    					$synt=$match[1];
1833
-    				}
1830
+				if (preg_match('/OBJECTS.*\{([^\}]+)\}/',$line,$match))
1831
+					{
1832
+						$synt=$match[1];
1833
+					}
1834 1834
 			}
1835 1835
 			if ($synt == null) 
1836 1836
 			{
1837 1837
 				//echo "No objects for $trapOID\n";
1838
-			    $time_objects += microtime(true) - $time_1;
1838
+				$time_objects += microtime(true) - $time_1;
1839 1839
 				continue;
1840 1840
 			}
1841 1841
 			//echo "$synt \n";
@@ -1854,18 +1854,18 @@  discard block
 block discarded – undo
1854 1854
 		
1855 1855
 		if ($display_progress)
1856 1856
 		{
1857
-    		echo "\nNumber of processed traps : $time_num_traps \n";
1858
-    		echo "\nParsing : " . number_format($time_parse1+$time_check1,1) ." sec / " . ($time_parse1N+ $time_check1N)  . " occurences\n";
1859
-    		echo "Detecting traps : " . number_format($time_check2+$time_check3,1) . " sec / " . ($time_check2N+$time_check3N) ." occurences\n";
1860
-    		echo "Trap processing ($time_updateN): ".number_format($time_update,1)." sec , ";
1861
-    		echo "Objects processing ($time_objectsN) : ".number_format($time_objects,1)." sec \n";
1857
+			echo "\nNumber of processed traps : $time_num_traps \n";
1858
+			echo "\nParsing : " . number_format($time_parse1+$time_check1,1) ." sec / " . ($time_parse1N+ $time_check1N)  . " occurences\n";
1859
+			echo "Detecting traps : " . number_format($time_check2+$time_check3,1) . " sec / " . ($time_check2N+$time_check3N) ." occurences\n";
1860
+			echo "Trap processing ($time_updateN): ".number_format($time_update,1)." sec , ";
1861
+			echo "Objects processing ($time_objectsN) : ".number_format($time_objects,1)." sec \n";
1862 1862
 		}
1863 1863
 		
1864 1864
 		// Timing ends
1865 1865
 		$timeTaken=microtime(true) - $timeTaken;
1866 1866
 		if ($display_progress)
1867 1867
 		{
1868
-		    echo "Global time : ".round($timeTaken)." seconds\n";
1868
+			echo "Global time : ".round($timeTaken)." seconds\n";
1869 1869
 		}
1870 1870
 		
1871 1871
 	}
Please login to merge, or discard this patch.
Spacing   +417 added lines, -417 removed lines patch added patch discarded remove patch
@@ -32,8 +32,8 @@  discard block
 block discarded – undo
32 32
 	protected $api_password='';
33 33
 
34 34
 	// Logs 
35
-	protected $logging;    //< Logging class.
36
-	protected $logSetup;   //< bool true if log was setup in constructor
35
+	protected $logging; //< Logging class.
36
+	protected $logSetup; //< bool true if log was setup in constructor
37 37
 	
38 38
 	//protected $debug_file="php://stdout";	
39 39
 	// Databases
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 	private $objectsAll; //< output lines of snmptranslate list
59 59
 	private $trapObjectsIndex; //< array of traps objects (as OID)
60 60
 	
61
-	function __construct($etc_dir='/etc/icingaweb2',$baseLogLevel=null,$baseLogMode='syslog',$baseLogFile='')
61
+	function __construct($etc_dir='/etc/icingaweb2', $baseLogLevel=null, $baseLogMode='syslog', $baseLogFile='')
62 62
 	{
63 63
 	    // Paths of ini files
64 64
 		$this->icingaweb2_etc=$etc_dir;
@@ -66,10 +66,10 @@  discard block
 block discarded – undo
66 66
 		$this->icingaweb2_ressources=$this->icingaweb2_etc."/resources.ini";
67 67
 
68 68
 		// Setup logging
69
-		$this->logging = new Logging();
69
+		$this->logging=new Logging();
70 70
 		if ($baseLogLevel != null)
71 71
 		{
72
-		    $this->logging->setLogging($baseLogLevel, $baseLogMode,$baseLogFile);
72
+		    $this->logging->setLogging($baseLogLevel, $baseLogMode, $baseLogFile);
73 73
 		    $this->logSetup=true;
74 74
 		}
75 75
 		else 
@@ -77,10 +77,10 @@  discard block
 block discarded – undo
77 77
 		$this->logging->log('Loggin started', INFO);
78 78
 
79 79
 		// Get options from ini files
80
-		$trapConfig=parse_ini_file($this->trap_module_config,true);
80
+		$trapConfig=parse_ini_file($this->trap_module_config, true);
81 81
 		if ($trapConfig == false)
82 82
 		{
83
-		    $this->logging->log("Error reading ini file : ".$this->trap_module_config,ERROR,'syslog');
83
+		    $this->logging->log("Error reading ini file : ".$this->trap_module_config, ERROR, 'syslog');
84 84
 		}
85 85
 		$this->getMainOptions($trapConfig); // Get main options from ini file
86 86
 		$this->setupDatabase($trapConfig); // Setup database class
@@ -108,15 +108,15 @@  discard block
 block discarded – undo
108 108
 	 * @param string $message warning message if not found
109 109
 	 * @return boolean true if found, or false
110 110
 	 */
111
-	protected function getOptionIfSet($option_array,$option_category,$option_name, &$option_var, $log_level = 2, $message = null)
111
+	protected function getOptionIfSet($option_array, $option_category, $option_name, &$option_var, $log_level=2, $message=null)
112 112
 	{
113 113
 	    if (!isset($option_array[$option_category][$option_name]))
114 114
 	    {
115 115
 	        if ($message === null)
116 116
 	        {
117
-	            $message='No ' . $option_name . ' in config file: '. $this->trap_module_config;
117
+	            $message='No '.$option_name.' in config file: '.$this->trap_module_config;
118 118
 	        }
119
-	        $this->logging->log($message,$log_level,'syslog');
119
+	        $this->logging->log($message, $log_level, 'syslog');
120 120
 	        return false;
121 121
 	    }
122 122
 	    else
@@ -133,30 +133,30 @@  discard block
 block discarded – undo
133 133
 	*/
134 134
 	protected function getMainOptions($trap_config)
135 135
 	{
136
-		$trap_config=parse_ini_file($this->trap_module_config,true);
136
+		$trap_config=parse_ini_file($this->trap_module_config, true);
137 137
 		if ($trap_config == false) 
138 138
 		{
139
-			$this->logging->log("Error reading ini file : ".$this->trap_module_config,ERROR,'syslog'); 
139
+			$this->logging->log("Error reading ini file : ".$this->trap_module_config, ERROR, 'syslog'); 
140 140
 		}
141 141
 		// Snmptranslate binary path
142
-		$this->getOptionIfSet($trap_config,'config','snmptranslate', $this->snmptranslate);
142
+		$this->getOptionIfSet($trap_config, 'config', 'snmptranslate', $this->snmptranslate);
143 143
 
144 144
 		// mibs path
145
-		$this->getOptionIfSet($trap_config,'config','snmptranslate_dirs', $this->snmptranslate_dirs);
145
+		$this->getOptionIfSet($trap_config, 'config', 'snmptranslate_dirs', $this->snmptranslate_dirs);
146 146
 
147 147
 		// icinga2cmd path
148
-		$this->getOptionIfSet($trap_config,'config','icingacmd', $this->icinga2cmd);
148
+		$this->getOptionIfSet($trap_config, 'config', 'icingacmd', $this->icinga2cmd);
149 149
 		
150 150
 		// table prefix
151
-		$this->getOptionIfSet($trap_config,'config','database_prefix', $this->db_prefix);
151
+		$this->getOptionIfSet($trap_config, 'config', 'database_prefix', $this->db_prefix);
152 152
 
153 153
 		// API options
154
-		if ($this->getOptionIfSet($trap_config,'config','icingaAPI_host', $this->api_hostname))
154
+		if ($this->getOptionIfSet($trap_config, 'config', 'icingaAPI_host', $this->api_hostname))
155 155
 		{
156 156
 		    $this->api_use=true;
157
-		    $this->getOptionIfSet($trap_config,'config','icingaAPI_port', $this->api_port);
158
-		    $this->getOptionIfSet($trap_config,'config','icingaAPI_user', $this->api_username);
159
-		    $this->getOptionIfSet($trap_config,'config','icingaAPI_password', $this->api_password);
157
+		    $this->getOptionIfSet($trap_config, 'config', 'icingaAPI_port', $this->api_port);
158
+		    $this->getOptionIfSet($trap_config, 'config', 'icingaAPI_user', $this->api_username);
159
+		    $this->getOptionIfSet($trap_config, 'config', 'icingaAPI_password', $this->api_password);
160 160
 		}
161 161
 	}
162 162
 	
@@ -164,40 +164,40 @@  discard block
 block discarded – undo
164 164
 	protected function setupDatabase($trapConfig)
165 165
 	{
166 166
 	    // Trap database
167
-	    if (!array_key_exists('database',$trapConfig['config']))
167
+	    if (!array_key_exists('database', $trapConfig['config']))
168 168
         {
169
-            $this->logging->log("No database in config file: ".$this->trap_module_config,ERROR,'');
169
+            $this->logging->log("No database in config file: ".$this->trap_module_config, ERROR, '');
170 170
             return;
171 171
         }
172 172
         $dbTrapName=$trapConfig['config']['database'];
173
-        $this->logging->log("Found database in config file: ".$dbTrapName,INFO );
173
+        $this->logging->log("Found database in config file: ".$dbTrapName, INFO);
174 174
 	    
175
-	   if ( ($dbConfig=parse_ini_file($this->icingaweb2_ressources,true)) === false)
175
+	   if (($dbConfig=parse_ini_file($this->icingaweb2_ressources, true)) === false)
176 176
 	    {
177
-	        $this->logging->log("Error reading ini file : ".$this->icingaweb2_ressources,ERROR,'');
177
+	        $this->logging->log("Error reading ini file : ".$this->icingaweb2_ressources, ERROR, '');
178 178
 	        return;
179 179
 	    }
180
-	    if (!array_key_exists($dbTrapName,$dbConfig))
180
+	    if (!array_key_exists($dbTrapName, $dbConfig))
181 181
 	    {
182
-	        $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2_ressources,ERROR,'');
182
+	        $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2_ressources, ERROR, '');
183 183
 	        return;
184 184
 	    }
185 185
 	    
186
-        $this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName]);
186
+        $this->trapsDB=new Database($this->logging, $dbConfig[$dbTrapName]);
187 187
 	    
188 188
 	    if ($this->api_use === true) return; // In case of API use, no IDO is necessary
189 189
         
190 190
 	    // IDO Database
191
-	    if (!array_key_exists('IDOdatabase',$trapConfig['config']))
191
+	    if (!array_key_exists('IDOdatabase', $trapConfig['config']))
192 192
 	    {
193
-	        $this->logging->log("No IDOdatabase in config file: ".$this->trap_module_config,ERROR,'');
193
+	        $this->logging->log("No IDOdatabase in config file: ".$this->trap_module_config, ERROR, '');
194 194
 	    }
195 195
 	    $dbIdoName=$trapConfig['config']['IDOdatabase'];		
196 196
 
197
-	    $this->logging->log("Found IDO database in config file: ".$dbIdoName,INFO );
198
-        if (!array_key_exists($dbIdoName,$dbConfig))
197
+	    $this->logging->log("Found IDO database in config file: ".$dbIdoName, INFO);
198
+        if (!array_key_exists($dbIdoName, $dbConfig))
199 199
 	    {
200
-	        $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2_ressources,ERROR,'');
200
+	        $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2_ressources, ERROR, '');
201 201
 	        return;
202 202
 	    }
203 203
 	    
@@ -212,13 +212,13 @@  discard block
 block discarded – undo
212 212
 		// Database options
213 213
 		if ($this->logSetup == false) // Only if logging was no setup in constructor
214 214
 		{
215
-    		$this->getDBConfigIfSet('log_level',$this->logging->debugLevel);
216
-    		$this->getDBConfigIfSet('log_destination',$this->logging->outputMode);
217
-    		$this->getDBConfigIfSet('log_file',$this->logging->outputFile);
215
+    		$this->getDBConfigIfSet('log_level', $this->logging->debugLevel);
216
+    		$this->getDBConfigIfSet('log_destination', $this->logging->outputMode);
217
+    		$this->getDBConfigIfSet('log_file', $this->logging->outputFile);
218 218
 		}
219 219
 	}
220 220
 
221
-	protected function getDBConfigIfSet($element,&$variable)
221
+	protected function getDBConfigIfSet($element, &$variable)
222 222
 	{
223 223
 		$value=$this->getDBConfig($element);
224 224
 		if ($value != 'null') $variable=$value;
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 		$db_conn=$this->trapsDB->db_connect_trap();
235 235
 		$sql='SELECT value from '.$this->db_prefix.'db_config WHERE ( name=\''.$element.'\' )';
236 236
 		if (($ret_code=$db_conn->query($sql)) === false) {
237
-			$this->logging->log('No result in query : ' . $sql,WARN,'');
237
+			$this->logging->log('No result in query : '.$sql, WARN, '');
238 238
 			return null;
239 239
 		}
240 240
 		$value=$ret_code->fetch();
@@ -251,22 +251,22 @@  discard block
 block discarded – undo
251 251
 	*	@param  string $destination file/syslog/display
252 252
 	*	@return void
253 253
 	**/	
254
-	public function trapLog( $message, $level, $destination ='') // OBSOLETE
254
+	public function trapLog($message, $level, $destination='') // OBSOLETE
255 255
 	{	
256 256
 		// TODO : replace ref with $this->logging->log 
257 257
 	    $this->logging->log($message, $level, $destination);
258 258
 	}
259 259
 	
260
-	public function setLogging($debugLvl,$outputType,$outputOption=null)  // OBSOLETE
260
+	public function setLogging($debugLvl, $outputType, $outputOption=null)  // OBSOLETE
261 261
 	{
262
-		$this->logging->setLogging($debugLvl, $outputType,$outputOption);
262
+		$this->logging->setLogging($debugLvl, $outputType, $outputOption);
263 263
 	}
264 264
 	
265 265
 	protected function getAPI()
266 266
 	{
267 267
 	    if ($this->icinga2api == null)
268 268
 	    {
269
-	        $this->icinga2api = new Icinga2API($this->api_hostname,$this->api_port);
269
+	        $this->icinga2api=new Icinga2API($this->api_hostname, $this->api_port);
270 270
 	    }
271 271
 	    return $this->icinga2api;
272 272
 	}
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 		if ($input_stream === false)
286 286
 		{
287 287
 		    $this->writeTrapErrorToDB("Error reading trap (code 1/Stdin)");
288
-			$this->logging->log("Error reading stdin !",ERROR,'');
288
+			$this->logging->log("Error reading stdin !", ERROR, '');
289 289
 			return null; // note : exception thrown by logging
290 290
 		}
291 291
 
@@ -294,21 +294,21 @@  discard block
 block discarded – undo
294 294
 		if ($this->receivingHost === false)
295 295
 		{
296 296
 		    $this->writeTrapErrorToDB("Error reading trap (code 1/Line Host)");
297
-			$this->logging->log("Error reading Host !",ERROR,''); 
297
+			$this->logging->log("Error reading Host !", ERROR, ''); 
298 298
 		}
299 299
 		// line 2 IP:port=>IP:port
300 300
 		$IP=chop(fgets($input_stream));
301 301
 		if ($IP === false)
302 302
 		{
303 303
 		    $this->writeTrapErrorToDB("Error reading trap (code 1/Line IP)");
304
-			$this->logging->log("Error reading IP !",ERROR,''); 
304
+			$this->logging->log("Error reading IP !", ERROR, ''); 
305 305
 		}
306 306
 		$matches=array();
307
-		$ret_code=preg_match('/.DP: \[(.*)\]:(.*)->\[(.*)\]:(.*)/',$IP,$matches);
308
-		if ($ret_code===0 || $ret_code===false) 
307
+		$ret_code=preg_match('/.DP: \[(.*)\]:(.*)->\[(.*)\]:(.*)/', $IP, $matches);
308
+		if ($ret_code === 0 || $ret_code === false) 
309 309
 		{
310 310
 		    $this->writeTrapErrorToDB("Error parsing trap (code 2/IP)");
311
-			$this->logging->log('Error parsing IP : '.$IP,ERROR,'');
311
+			$this->logging->log('Error parsing IP : '.$IP, ERROR, '');
312 312
 		} 
313 313
 		else 
314 314
 		{		
@@ -318,34 +318,34 @@  discard block
 block discarded – undo
318 318
 			$this->trap_data['destination_port']=$matches[4];
319 319
 		}
320 320
 
321
-		while (($vars=fgets($input_stream)) !==false)
321
+		while (($vars=fgets($input_stream)) !== false)
322 322
 		{
323 323
 			$vars=chop($vars);
324
-			$ret_code=preg_match('/^([^ ]+) (.*)$/',$vars,$matches);
325
-			if ($ret_code===0 || $ret_code===false) 
324
+			$ret_code=preg_match('/^([^ ]+) (.*)$/', $vars, $matches);
325
+			if ($ret_code === 0 || $ret_code === false) 
326 326
 			{
327
-				$this->logging->log('No match on trap data : '.$vars,WARN,'');
327
+				$this->logging->log('No match on trap data : '.$vars, WARN, '');
328 328
 			}
329 329
 			else 
330 330
 			{
331
-			    if (($matches[1]=='.1.3.6.1.6.3.1.1.4.1.0') || ($matches[1]=='.1.3.6.1.6.3.1.1.4.1'))
331
+			    if (($matches[1] == '.1.3.6.1.6.3.1.1.4.1.0') || ($matches[1] == '.1.3.6.1.6.3.1.1.4.1'))
332 332
 				{
333 333
 					$this->trap_data['trap_oid']=$matches[2];				
334 334
 				}
335 335
 				else
336 336
 				{
337
-					$object= new stdClass;
338
-					$object->oid =$matches[1];
339
-					$object->value = $matches[2];
340
-					array_push($this->trap_data_ext,$object);
337
+					$object=new stdClass;
338
+					$object->oid=$matches[1];
339
+					$object->value=$matches[2];
340
+					array_push($this->trap_data_ext, $object);
341 341
 				}
342 342
 			}
343 343
 		}
344 344
 
345
-		if ($this->trap_data['trap_oid']=='unknown') 
345
+		if ($this->trap_data['trap_oid'] == 'unknown') 
346 346
 		{
347
-		    $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)",$this->trap_data['source_ip']);
348
-			$this->logging->log('no trap oid found',ERROR,'');
347
+		    $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)", $this->trap_data['source_ip']);
348
+			$this->logging->log('no trap oid found', ERROR, '');
349 349
 		} 
350 350
 
351 351
 		// Translate oids.
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
 		}
368 368
 		
369 369
 
370
-		$this->trap_data['status']= 'waiting';
370
+		$this->trap_data['status']='waiting';
371 371
 		
372 372
 		return $this->trap_data;
373 373
 	}
@@ -383,40 +383,40 @@  discard block
 block discarded – undo
383 383
 		$db_conn=$this->trapsDB->db_connect_trap();
384 384
 		
385 385
 		$sql='SELECT mib,name from '.$this->db_prefix.'mib_cache WHERE oid=\''.$oid.'\';';
386
-		$this->logging->log('SQL query : '.$sql,DEBUG );
386
+		$this->logging->log('SQL query : '.$sql, DEBUG);
387 387
 		if (($ret_code=$db_conn->query($sql)) === false) {
388
-			$this->logging->log('No result in query : ' . $sql,ERROR,'');
388
+			$this->logging->log('No result in query : '.$sql, ERROR, '');
389 389
 		}
390 390
 		$name=$ret_code->fetch();
391 391
 		if ($name['name'] != null)
392 392
 		{
393
-			return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']);
393
+			return array('trap_name_mib'=>$name['mib'], 'trap_name'=>$name['name']);
394 394
 		}
395 395
 		
396 396
 		// Also check if it is an instance of OID
397
-		$oid_instance=preg_replace('/\.[0-9]+$/','',$oid);
397
+		$oid_instance=preg_replace('/\.[0-9]+$/', '', $oid);
398 398
 		
399 399
 		$sql='SELECT mib,name from '.$this->db_prefix.'mib_cache WHERE oid=\''.$oid_instance.'\';';
400
-		$this->logging->log('SQL query : '.$sql,DEBUG );
400
+		$this->logging->log('SQL query : '.$sql, DEBUG);
401 401
 		if (($ret_code=$db_conn->query($sql)) === false) {
402
-			$this->logging->log('No result in query : ' . $sql,ERROR,'');
402
+			$this->logging->log('No result in query : '.$sql, ERROR, '');
403 403
 		}
404 404
 		$name=$ret_code->fetch();
405 405
 		if ($name['name'] != null)
406 406
 		{
407
-			return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']);
407
+			return array('trap_name_mib'=>$name['mib'], 'trap_name'=>$name['name']);
408 408
 		}
409 409
 		
410 410
 		// Try to get oid name from snmptranslate
411
-		$translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
411
+		$translate=exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.
412 412
 		    ' '.$oid);
413 413
 		$matches=array();
414
-		$ret_code=preg_match('/(.*)::(.*)/',$translate,$matches);
415
-		if ($ret_code===0 || $ret_code === false) {
414
+		$ret_code=preg_match('/(.*)::(.*)/', $translate, $matches);
415
+		if ($ret_code === 0 || $ret_code === false) {
416 416
 			return NULL;
417 417
 		} else {
418
-			$this->logging->log('Found name with snmptrapd and not in DB for oid='.$oid,INFO);
419
-			return array('trap_name_mib'=>$matches[1],'trap_name'=>$matches[2]);
418
+			$this->logging->log('Found name with snmptrapd and not in DB for oid='.$oid, INFO);
419
+			return array('trap_name_mib'=>$matches[1], 'trap_name'=>$matches[2]);
420 420
 		}	
421 421
 	}
422 422
 	
@@ -427,90 +427,90 @@  discard block
 block discarded – undo
427 427
 	**/
428 428
 	public function eraseOldTraps($days=0)
429 429
 	{
430
-		if ($days==0)
430
+		if ($days == 0)
431 431
 		{
432 432
 			if (($days=$this->getDBConfig('db_remove_days')) == null)
433 433
 			{
434
-				$this->logging->log('No days specified & no db value : no tap erase' ,WARN,'');
434
+				$this->logging->log('No days specified & no db value : no tap erase', WARN, '');
435 435
 				return;
436 436
 			}
437 437
 		}
438 438
 		$db_conn=$this->trapsDB->db_connect_trap();
439
-		$daysago = strtotime("-".$days." day");
440
-		$sql= 'delete from '.$this->db_prefix.'received where date_received < \''.date("Y-m-d H:i:s",$daysago).'\';';
439
+		$daysago=strtotime("-".$days." day");
440
+		$sql='delete from '.$this->db_prefix.'received where date_received < \''.date("Y-m-d H:i:s", $daysago).'\';';
441 441
 		if ($db_conn->query($sql) === false) {
442
-			$this->logging->log('Error erasing traps : '.$sql,ERROR,'');
442
+			$this->logging->log('Error erasing traps : '.$sql, ERROR, '');
443 443
 		}
444
-		$this->logging->log('Erased traps older than '.$days.' day(s) : '.$sql,INFO);
444
+		$this->logging->log('Erased traps older than '.$days.' day(s) : '.$sql, INFO);
445 445
 	}
446 446
 
447 447
 	/** Write error to received trap database
448 448
 	 */
449
-	public function writeTrapErrorToDB($message,$sourceIP=null,$trapoid=null)
449
+	public function writeTrapErrorToDB($message, $sourceIP=null, $trapoid=null)
450 450
 	{
451 451
 	    
452 452
 	    $db_conn=$this->trapsDB->db_connect_trap();
453 453
 	    
454 454
 	    // add date time
455
-	    $insert_col ='date_received,status';
456
-	    $insert_val = "'" . date("Y-m-d H:i:s")."','error'";
455
+	    $insert_col='date_received,status';
456
+	    $insert_val="'".date("Y-m-d H:i:s")."','error'";
457 457
         
458
-	    if ($sourceIP !=null)
458
+	    if ($sourceIP != null)
459 459
 	    {
460
-	        $insert_col .=',source_ip';
461
-	        $insert_val .=",'". $sourceIP ."'";
460
+	        $insert_col.=',source_ip';
461
+	        $insert_val.=",'".$sourceIP."'";
462 462
 	    }
463
-	    if ($trapoid !=null)
463
+	    if ($trapoid != null)
464 464
 	    {
465
-	        $insert_col .=',trap_oid';
466
-	        $insert_val .=",'". $trapoid ."'";
465
+	        $insert_col.=',trap_oid';
466
+	        $insert_val.=",'".$trapoid."'";
467 467
 	    }
468
-	    $insert_col .=',status_detail';
469
-	    $insert_val .=",'". $message ."'";
468
+	    $insert_col.=',status_detail';
469
+	    $insert_val.=",'".$message."'";
470 470
 	    
471
-	    $sql= 'INSERT INTO '.$this->db_prefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')';
471
+	    $sql='INSERT INTO '.$this->db_prefix.'received ('.$insert_col.') VALUES ('.$insert_val.')';
472 472
 	    
473 473
 	    switch ($this->trapsDB->trapDBType)
474 474
 	    {
475 475
 	        case 'pgsql':
476
-	            $sql .= ' RETURNING id;';
477
-	            $this->logging->log('sql : '.$sql,INFO);
476
+	            $sql.=' RETURNING id;';
477
+	            $this->logging->log('sql : '.$sql, INFO);
478 478
 	            if (($ret_code=$db_conn->query($sql)) === false) {
479
-	                $this->logging->log('Error SQL insert : '.$sql,1,'');
479
+	                $this->logging->log('Error SQL insert : '.$sql, 1, '');
480 480
 	            }
481
-	            $this->logging->log('SQL insertion OK',INFO );
481
+	            $this->logging->log('SQL insertion OK', INFO);
482 482
 	            // Get last id to insert oid/values in secondary table
483 483
 	            if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) {
484 484
 	                
485
-	                $this->logging->log('Erreur recuperation id',1,'');
485
+	                $this->logging->log('Erreur recuperation id', 1, '');
486 486
 	            }
487
-	            if (! isset($inserted_id_ret['id'])) {
488
-	                $this->logging->log('Error getting id',1,'');
487
+	            if (!isset($inserted_id_ret['id'])) {
488
+	                $this->logging->log('Error getting id', 1, '');
489 489
 	            }
490 490
 	            $this->trap_id=$inserted_id_ret['id'];
491 491
 	            break;
492 492
 	        case 'mysql':
493
-	            $sql .= ';';
494
-	            $this->logging->log('sql : '.$sql,INFO );
493
+	            $sql.=';';
494
+	            $this->logging->log('sql : '.$sql, INFO);
495 495
 	            if ($db_conn->query($sql) === false) {
496
-	                $this->logging->log('Error SQL insert : '.$sql,1,'');
496
+	                $this->logging->log('Error SQL insert : '.$sql, 1, '');
497 497
 	            }
498
-	            $this->logging->log('SQL insertion OK',INFO );
498
+	            $this->logging->log('SQL insertion OK', INFO);
499 499
 	            // Get last id to insert oid/values in secondary table
500 500
 	            $sql='SELECT LAST_INSERT_ID();';
501 501
 	            if (($ret_code=$db_conn->query($sql)) === false) {
502
-	                $this->logging->log('Erreur recuperation id',1,'');
502
+	                $this->logging->log('Erreur recuperation id', 1, '');
503 503
 	            }
504 504
 	            
505 505
 	            $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
506
-	            if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
506
+	            if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
507 507
 	            $this->trap_id=$inserted_id;
508 508
 	            break;
509 509
 	        default:
510
-	            $this->logging->log('Error SQL type unknown  : '.$this->trapsDB->trapDBType,1,'');
510
+	            $this->logging->log('Error SQL type unknown  : '.$this->trapsDB->trapDBType, 1, '');
511 511
 	    }
512 512
 	    
513
-	    $this->logging->log('id found: '. $this->trap_id,INFO );    
513
+	    $this->logging->log('id found: '.$this->trap_id, INFO);    
514 514
 	}
515 515
 	
516 516
 	/** Write trap data to trap database
@@ -527,86 +527,86 @@  discard block
 block discarded – undo
527 527
 		$insert_col='';
528 528
 		$insert_val='';
529 529
 		// add date time
530
-		$this->trap_data['date_received'] = date("Y-m-d H:i:s");
530
+		$this->trap_data['date_received']=date("Y-m-d H:i:s");
531 531
 
532 532
 		$firstcol=1;
533 533
 		foreach ($this->trap_data as $col => $val)
534 534
 		{
535
-			if ($firstcol==0) 
535
+			if ($firstcol == 0) 
536 536
 			{
537
-				$insert_col .=',';
538
-				$insert_val .=',';
537
+				$insert_col.=',';
538
+				$insert_val.=',';
539 539
 			}
540
-			$insert_col .= $col ;
541
-			$insert_val .= ($val==null)? 'NULL' : $db_conn->quote($val);
540
+			$insert_col.=$col;
541
+			$insert_val.=($val == null) ? 'NULL' : $db_conn->quote($val);
542 542
 			$firstcol=0;
543 543
 		}
544 544
 		
545
-		$sql= 'INSERT INTO '.$this->db_prefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')';
545
+		$sql='INSERT INTO '.$this->db_prefix.'received ('.$insert_col.') VALUES ('.$insert_val.')';
546 546
 		switch ($this->trapsDB->trapDBType)
547 547
 		{
548 548
 			case 'pgsql': 
549
-				$sql .= ' RETURNING id;';
550
-				$this->logging->log('sql : '.$sql,INFO );
549
+				$sql.=' RETURNING id;';
550
+				$this->logging->log('sql : '.$sql, INFO);
551 551
 				if (($ret_code=$db_conn->query($sql)) === false) {
552
-					$this->logging->log('Error SQL insert : '.$sql,ERROR,'');
552
+					$this->logging->log('Error SQL insert : '.$sql, ERROR, '');
553 553
 				}
554
-				$this->logging->log('SQL insertion OK',INFO );
554
+				$this->logging->log('SQL insertion OK', INFO);
555 555
 				// Get last id to insert oid/values in secondary table
556 556
 				if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) {
557 557
 														   
558
-					$this->logging->log('Erreur recuperation id',ERROR,'');
558
+					$this->logging->log('Erreur recuperation id', ERROR, '');
559 559
 				}
560
-				if (! isset($inserted_id_ret['id'])) {
561
-					$this->logging->log('Error getting id',ERROR,'');
560
+				if (!isset($inserted_id_ret['id'])) {
561
+					$this->logging->log('Error getting id', ERROR, '');
562 562
 				}
563 563
 				$this->trap_id=$inserted_id_ret['id'];
564 564
 			break;
565 565
 			case 'mysql': 
566
-				$sql .= ';';
567
-				$this->logging->log('sql : '.$sql,INFO );
566
+				$sql.=';';
567
+				$this->logging->log('sql : '.$sql, INFO);
568 568
 				if ($db_conn->query($sql) === false) {
569
-					$this->logging->log('Error SQL insert : '.$sql,ERROR,'');
569
+					$this->logging->log('Error SQL insert : '.$sql, ERROR, '');
570 570
 				}
571
-				$this->logging->log('SQL insertion OK',INFO );
571
+				$this->logging->log('SQL insertion OK', INFO);
572 572
 				// Get last id to insert oid/values in secondary table
573 573
 				$sql='SELECT LAST_INSERT_ID();';
574 574
 				if (($ret_code=$db_conn->query($sql)) === false) {
575
-					$this->logging->log('Erreur recuperation id',ERROR,'');
575
+					$this->logging->log('Erreur recuperation id', ERROR, '');
576 576
 				}
577 577
 
578 578
 				$inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
579
-				if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
579
+				if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
580 580
 				$this->trap_id=$inserted_id;
581 581
 			break;
582 582
 			default: 
583
-				$this->logging->log('Error SQL type unknown : '.$this->trapsDB->trapDBType,ERROR,'');
583
+				$this->logging->log('Error SQL type unknown : '.$this->trapsDB->trapDBType, ERROR, '');
584 584
 		}
585
-		$this->logging->log('id found: '.$this->trap_id,INFO );
585
+		$this->logging->log('id found: '.$this->trap_id, INFO);
586 586
 		
587 587
 		// Fill trap extended data table
588 588
 		foreach ($this->trap_data_ext as $value) {			
589 589
 			// TODO : detect if trap value is encoded and decode it to UTF-8 for database
590 590
 			$firstcol=1;
591
-			$value->trap_id = $this->trap_id;
591
+			$value->trap_id=$this->trap_id;
592 592
 			$insert_col='';
593 593
 			$insert_val='';
594 594
 			foreach ($value as $col => $val)
595 595
 			{
596
-				if ($firstcol==0) 
596
+				if ($firstcol == 0) 
597 597
 				{
598
-					$insert_col .=',';
599
-					$insert_val .=',';
598
+					$insert_col.=',';
599
+					$insert_val.=',';
600 600
 				}
601
-				$insert_col .= $col;
602
-				$insert_val .= ($val==null)? 'NULL' : $db_conn->quote($val);
601
+				$insert_col.=$col;
602
+				$insert_val.=($val == null) ? 'NULL' : $db_conn->quote($val);
603 603
 				$firstcol=0;
604 604
 			}
605 605
 
606
-			$sql= 'INSERT INTO '.$this->db_prefix.'received_data (' . $insert_col . ') VALUES ('.$insert_val.');';			
606
+			$sql='INSERT INTO '.$this->db_prefix.'received_data ('.$insert_col.') VALUES ('.$insert_val.');';			
607 607
 
608 608
 			if (($ret_code=$db_conn->query($sql)) === false) {
609
-				$this->logging->log('Erreur insertion data : ' . $sql,WARN,'');
609
+				$this->logging->log('Erreur insertion data : '.$sql, WARN, '');
610 610
 			}	
611 611
 		}	
612 612
 	}
@@ -616,14 +616,14 @@  discard block
 block discarded – undo
616 616
 	*	@param $oid string oid in numeric
617 617
 	*	@return mixed : PDO object or false
618 618
 	*/	
619
-	protected function getRules($ip,$oid)
619
+	protected function getRules($ip, $oid)
620 620
 	{
621 621
 		$db_conn=$this->trapsDB->db_connect_trap();
622 622
 		// fetch rules based on IP in rule and OID
623 623
 		$sql='SELECT * from '.$this->db_prefix.'rules WHERE trap_oid=\''.$oid.'\' ';
624
-		$this->logging->log('SQL query : '.$sql,DEBUG );
624
+		$this->logging->log('SQL query : '.$sql, DEBUG);
625 625
 		if (($ret_code=$db_conn->query($sql)) === false) {
626
-			$this->logging->log('No result in query : ' . $sql,WARN,'');
626
+			$this->logging->log('No result in query : '.$sql, WARN, '');
627 627
 			return false;
628 628
 		}
629 629
 		$rules_all=$ret_code->fetchAll();
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
 		$rule_ret_key=0;
633 633
 		foreach ($rules_all as $key => $rule)
634 634
 		{
635
-			if ($rule['ip4']==$ip || $rule['ip6']==$ip)
635
+			if ($rule['ip4'] == $ip || $rule['ip6'] == $ip)
636 636
 			{
637 637
 				$rules_ret[$rule_ret_key]=$rules_all[$key];
638 638
 				//TODO : get host name by API (and check if correct in rule).
@@ -640,7 +640,7 @@  discard block
 block discarded – undo
640 640
 				continue;
641 641
 			}
642 642
 			// TODO : get hosts IP by API
643
-			if (isset($rule['host_group_name']) && $rule['host_group_name']!=null)
643
+			if (isset($rule['host_group_name']) && $rule['host_group_name'] != null)
644 644
 			{ // get ips of group members by oid
645 645
 				$db_conn2=$this->trapsDB->db_connect_ido();
646 646
 				$sql="SELECT m.host_object_id, a.address as ip4, a.address6 as ip6, b.name1 as host_name
@@ -651,15 +651,15 @@  discard block
 block discarded – undo
651 651
 						LEFT JOIN icinga_objects as b ON b.object_id = a.host_object_id
652 652
 						WHERE o.name1='".$rule['host_group_name']."';";
653 653
 				if (($ret_code2=$db_conn2->query($sql)) === false) {
654
-					$this->logging->log('No result in query : ' . $sql,WARN,'');
654
+					$this->logging->log('No result in query : '.$sql, WARN, '');
655 655
 					continue;
656 656
 				}
657 657
 				$grouphosts=$ret_code2->fetchAll();
658 658
 				//echo "rule grp :\n";print_r($grouphosts);echo "\n";
659
-				foreach ( $grouphosts as $host)
659
+				foreach ($grouphosts as $host)
660 660
 				{
661 661
 					//echo $host['ip4']."\n";
662
-					if ($host['ip4']==$ip || $host['ip6']==$ip)
662
+					if ($host['ip4'] == $ip || $host['ip6'] == $ip)
663 663
 					{
664 664
 						//echo "Rule added \n";
665 665
 						$rules_ret[$rule_ret_key]=$rules_all[$key];
@@ -682,7 +682,7 @@  discard block
 block discarded – undo
682 682
 		$db_conn=$this->trapsDB->db_connect_trap();
683 683
 		$sql="UPDATE ".$this->db_prefix."rules SET num_match = '".$set."' WHERE (id = '".$id."');";
684 684
 		if ($db_conn->query($sql) === false) {
685
-			$this->logging->log('Error in update query : ' . $sql,WARN,'');
685
+			$this->logging->log('Error in update query : '.$sql, WARN, '');
686 686
 		}
687 687
 	}
688 688
 	
@@ -694,31 +694,31 @@  discard block
 block discarded – undo
694 694
 	 * @param string $display
695 695
 	 * @returnn bool true is service check was sent without error
696 696
 	*/
697
-	public function serviceCheckResult($host,$service,$state,$display)
697
+	public function serviceCheckResult($host, $service, $state, $display)
698 698
 	{
699 699
 	    if ($this->api_use === false)
700 700
 	    {
701
-    		$send = '[' . date('U') .'] PROCESS_SERVICE_CHECK_RESULT;' .
702
-    			$host.';' .$service .';' . $state . ';'.$display;
703
-    		$this->logging->log( $send." : to : " .$this->icinga2cmd,INFO );
701
+    		$send='['.date('U').'] PROCESS_SERVICE_CHECK_RESULT;'.
702
+    			$host.';'.$service.';'.$state.';'.$display;
703
+    		$this->logging->log($send." : to : ".$this->icinga2cmd, INFO);
704 704
     		
705 705
     		// TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default....
706
-    		exec('echo "'.$send.'" > ' .$this->icinga2cmd);
706
+    		exec('echo "'.$send.'" > '.$this->icinga2cmd);
707 707
     		return true;
708 708
 	    }
709 709
 	    else
710 710
 	    {
711
-	        $api = $this->getAPI();
711
+	        $api=$this->getAPI();
712 712
 	        $api->setCredentials($this->api_username, $this->api_password);
713
-	        list($retcode,$retmessage)=$api->serviceCheckResult($host,$service,$state,$display);
713
+	        list($retcode, $retmessage)=$api->serviceCheckResult($host, $service, $state, $display);
714 714
 	        if ($retcode == false)
715 715
 	        {
716
-	            $this->logging->log( "Error sending result : " .$retmessage,WARN,'');
716
+	            $this->logging->log("Error sending result : ".$retmessage, WARN, '');
717 717
 	            return false;
718 718
 	        }
719 719
 	        else 
720 720
 	        {
721
-	            $this->logging->log( "Sent result : " .$retmessage,INFO );
721
+	            $this->logging->log("Sent result : ".$retmessage, INFO);
722 722
 	            return true;
723 723
 	        }
724 724
 	    }
@@ -726,7 +726,7 @@  discard block
 block discarded – undo
726 726
 	
727 727
 	public function getHostByIP($ip)
728 728
 	{
729
-	    $api = $this->getAPI();
729
+	    $api=$this->getAPI();
730 730
 	    $api->setCredentials($this->api_username, $this->api_password);
731 731
 	    return $api->getHostByIP($ip);
732 732
 	}
@@ -739,32 +739,32 @@  discard block
 block discarded – undo
739 739
 	protected function applyDisplay($display)
740 740
 	{
741 741
 	    $matches=array();
742
-	    while (preg_match('/_OID\(([0-9\.]+)\)/',$display,$matches) == 1)
742
+	    while (preg_match('/_OID\(([0-9\.]+)\)/', $display, $matches) == 1)
743 743
 		{
744 744
 			$oid=$matches[1];
745 745
 			$found=0;
746
-			foreach($this->trap_data_ext as $val)
746
+			foreach ($this->trap_data_ext as $val)
747 747
 			{
748 748
 				if ($oid == $val->oid)
749 749
 				{
750
-					$val->value=preg_replace('/"/','',$val->value);
750
+					$val->value=preg_replace('/"/', '', $val->value);
751 751
 					$rep=0;
752
-					$display=preg_replace('/_OID\('.$oid.'\)/',$val->value,$display,-1,$rep);
753
-					if ($rep==0)
752
+					$display=preg_replace('/_OID\('.$oid.'\)/', $val->value, $display, -1, $rep);
753
+					if ($rep == 0)
754 754
 					{
755
-						$this->logging->log("Error in display",WARN,'');
755
+						$this->logging->log("Error in display", WARN, '');
756 756
 						return $display;
757 757
 					}
758 758
 					$found=1;
759 759
 					break;
760 760
 				}
761 761
 			}
762
-			if ($found==0)
762
+			if ($found == 0)
763 763
 			{
764
-				$display=preg_replace('/_OID\('.$oid.'\)/','<not in trap>',$display,-1,$rep);
765
-				if ($rep==0)
764
+				$display=preg_replace('/_OID\('.$oid.'\)/', '<not in trap>', $display, -1, $rep);
765
+				if ($rep == 0)
766 766
 				{
767
-					$this->logging->log("Error in display",WARN,'');
767
+					$this->logging->log("Error in display", WARN, '');
768 768
 					return $display;
769 769
 				}				
770 770
 			}
@@ -774,27 +774,27 @@  discard block
 block discarded – undo
774 774
 
775 775
 	
776 776
 	/***************** Eval & tokenizer functions ****************/
777
-	protected function eval_getElement($rule,&$item)
777
+	protected function eval_getElement($rule, &$item)
778 778
 	{
779
-		while ($rule[$item]==' ') $item++;
780
-		if (preg_match('/[0-9\.]/',$rule[$item]))
779
+		while ($rule[$item] == ' ') $item++;
780
+		if (preg_match('/[0-9\.]/', $rule[$item]))
781 781
 		{ // number
782 782
 	
783
-			$item2=$item+1; 
784
-			while (($item2!=strlen($rule)) && (preg_match('/[0-9\.]/',$rule[$item2]))) { $item2++ ;}
785
-			$val=substr($rule,$item,$item2-$item);
783
+			$item2=$item + 1; 
784
+			while (($item2 != strlen($rule)) && (preg_match('/[0-9\.]/', $rule[$item2]))) { $item2++; }
785
+			$val=substr($rule, $item, $item2 - $item);
786 786
 			$item=$item2;
787 787
 			//echo "number ".$val."\n";
788
-			return array(0,$val);
788
+			return array(0, $val);
789 789
 		}
790 790
 		if ($rule[$item] == '"')
791 791
 		{ // string
792 792
 			$item++;
793
-			$item2=$this->eval_getNext($rule,$item,'"');
794
-			$val=substr($rule,$item,$item2-$item-1);
793
+			$item2=$this->eval_getNext($rule, $item, '"');
794
+			$val=substr($rule, $item, $item2 - $item - 1);
795 795
 			$item=$item2;
796 796
 			//echo "string : ".$val."\n";
797
-			return array(1,$val);
797
+			return array(1, $val);
798 798
 		}
799 799
 		
800 800
 		if ($rule[$item] == '(')
@@ -803,14 +803,14 @@  discard block
 block discarded – undo
803 803
 			$start=$item;
804 804
 			$parenthesis_count=0; 
805 805
 			while (($item < strlen($rule)) // Not end of string AND
806
-			      && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded ()
806
+			      && (($rule[$item] != ')') || $parenthesis_count > 0)) // Closing ')' or embeded ()
807 807
 			{ 
808
-				if ($rule[$item] == '"' )
808
+				if ($rule[$item] == '"')
809 809
 				{ // pass through string
810 810
 					$item++;
811
-					$item=$this->eval_getNext($rule,$item,'"');
811
+					$item=$this->eval_getNext($rule, $item, '"');
812 812
 				} 
813
-				else{
813
+				else {
814 814
 				    if ($rule[$item] == '(')
815 815
 				    {
816 816
 				        $parenthesis_count++;
@@ -823,49 +823,49 @@  discard block
 block discarded – undo
823 823
 				}
824 824
 			}
825 825
 			
826
-			if ($item==strlen($rule)) {throw new Exception("no closing () in ".$rule ." at " .$item);}
827
-			$val=substr($rule,$start,$item-$start);
826
+			if ($item == strlen($rule)) {throw new Exception("no closing () in ".$rule." at ".$item); }
827
+			$val=substr($rule, $start, $item - $start);
828 828
 			$item++;
829 829
 			$start=0;
830 830
 			//echo "group : ".$val."\n";
831 831
 			// returns evaluation of group as type 2 (boolean)
832
-			return array(2,$this->evaluation($val,$start));		
832
+			return array(2, $this->evaluation($val, $start));		
833 833
 		}
834
-		throw new Exception("number/string not found in ".$rule ." at " .$item . ' : ' .$rule[$item]);
834
+		throw new Exception("number/string not found in ".$rule." at ".$item.' : '.$rule[$item]);
835 835
 		
836 836
 	}
837 837
 	
838
-	protected function eval_getNext($rule,$item,$tok)
838
+	protected function eval_getNext($rule, $item, $tok)
839 839
 	{
840
-		while (($rule[$item] != $tok ) && ($item < strlen($rule))) { $item++;}
841
-		if ($item==strlen($rule)) throw new Exception("closing '".$tok."' not found in ".$rule ." at " .$item);
842
-		return $item+1;
840
+		while (($rule[$item] != $tok) && ($item < strlen($rule))) { $item++; }
841
+		if ($item == strlen($rule)) throw new Exception("closing '".$tok."' not found in ".$rule." at ".$item);
842
+		return $item + 1;
843 843
 	}
844 844
 	
845
-	protected function eval_getOper($rule,&$item)
845
+	protected function eval_getOper($rule, &$item)
846 846
 	{
847
-		while ($rule[$item]==' ') $item++;
847
+		while ($rule[$item] == ' ') $item++;
848 848
 		switch ($rule[$item])
849 849
 		{
850 850
 			case '<':
851
-				if ($rule[$item+1]=='=') { $item+=2; return array(0,"<=");}
852
-				$item++; return array(0,"<");
851
+				if ($rule[$item + 1] == '=') { $item+=2; return array(0, "<="); }
852
+				$item++; return array(0, "<");
853 853
 			case '>':
854
-				if ($rule[$item+1]=='=') { $item+=2; return array(0,">=");}
855
-				$item++; return array(0,">");
854
+				if ($rule[$item + 1] == '=') { $item+=2; return array(0, ">="); }
855
+				$item++; return array(0, ">");
856 856
 			case '=':
857
-				$item++; return array(0,"=");	
857
+				$item++; return array(0, "=");	
858 858
 			case '!':
859
-				if ($rule[$item+1]=='=') { $item+=2; return array(0,"!=");}
860
-				throw new Exception("Erreur in expr - incorrect operator '!'  found in ".$rule ." at " .$item);
859
+				if ($rule[$item + 1] == '=') { $item+=2; return array(0, "!="); }
860
+				throw new Exception("Erreur in expr - incorrect operator '!'  found in ".$rule." at ".$item);
861 861
 			case '~':
862
-				$item++; return array(0,"~");	
862
+				$item++; return array(0, "~");	
863 863
 			case '|':
864
-				$item++; return array(1,"|");	
864
+				$item++; return array(1, "|");	
865 865
 			case '&':
866
-				$item++; return array(1,"&");
866
+				$item++; return array(1, "&");
867 867
 			default	:
868
-				throw new Exception("Erreur in expr - operator not found in ".$rule ." at " .$item);
868
+				throw new Exception("Erreur in expr - operator not found in ".$rule." at ".$item);
869 869
 		}
870 870
 	}
871 871
 	
@@ -877,10 +877,10 @@  discard block
 block discarded – undo
877 877
 	*   comparison int vs strings will return null (error)
878 878
 	*	return : bool or null on error
879 879
 	*/
880
-	public function evaluation($rule,&$item)
880
+	public function evaluation($rule, &$item)
881 881
 	{
882 882
 	    //echo "Evaluation of ".substr($rule,$item)."\n";
883
-		if ( $rule[$item] == '!') // If '!' found, negate next expression.
883
+		if ($rule[$item] == '!') // If '!' found, negate next expression.
884 884
 		{
885 885
 		    $negate=true;
886 886
 		    $item++;
@@ -890,63 +890,63 @@  discard block
 block discarded – undo
890 890
 		    $negate=false;
891 891
 		}
892 892
 		// First element : number, string or ()
893
-		list($type1,$val1) = $this->eval_getElement($rule,$item);
893
+		list($type1, $val1)=$this->eval_getElement($rule, $item);
894 894
 		//echo "Elmt1: ".$val1."/".$type1." : ".substr($rule,$item)."\n";
895 895
 		
896
-		if ($item==strlen($rule)) // If only element, return value, but only boolean
896
+		if ($item == strlen($rule)) // If only element, return value, but only boolean
897 897
 		{
898 898
 		  if ($type1 != 2) throw new Exception("Cannot use num/string as boolean : ".$rule);
899
-		  if ($negate === true) $val1= ! $val1;
899
+		  if ($negate === true) $val1=!$val1;
900 900
 		  return $val1;
901 901
 		}  
902 902
 		
903 903
 		// Second element : operator
904
-		list($typec,$comp) = $this->eval_getOper($rule,$item);
904
+		list($typec, $comp)=$this->eval_getOper($rule, $item);
905 905
 		//echo "Comp : ".$comp." : ".substr($rule,$item)."\n";
906 906
         
907 907
 		// Third element : number, string or ()
908
-		if ( $rule[$item] == '!') // starts with a ! so evaluate whats next
908
+		if ($rule[$item] == '!') // starts with a ! so evaluate whats next
909 909
 		{
910 910
 		    $item++;
911 911
 		    if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule);
912
-		    $val2= ! $this->evaluation($rule,$item);
912
+		    $val2=!$this->evaluation($rule, $item);
913 913
 		    $type2=2; // result is a boolean 
914 914
 		}
915 915
 		else 
916 916
 		{
917
-		    list($type2,$val2) = $this->eval_getElement($rule,$item);
917
+		    list($type2, $val2)=$this->eval_getElement($rule, $item);
918 918
 		}
919 919
 		//echo "Elmt2: ".$val2."/".$type2." : ".substr($rule,$item)."\n";
920 920
 		
921
-		if ($type1!=$type2)  // cannot compare different types
921
+		if ($type1 != $type2)  // cannot compare different types
922 922
 		{ 
923 923
 		    throw new Exception("Cannot compare string & number : ".$rule);
924 924
 		}
925
-		if ($typec==1 && $type1 !=2) // cannot use & or | with string/number
925
+		if ($typec == 1 && $type1 != 2) // cannot use & or | with string/number
926 926
 		{
927 927
 		    throw new Exception("Cannot use boolean operators with string & number : ".$rule);
928 928
 		}
929 929
 		
930
-		switch ($comp){
931
-			case '<':	$retVal= ($val1 < $val2); break;
932
-			case '<=':	$retVal= ($val1 <= $val2); break;
933
-			case '>':	$retVal= ($val1 > $val2); break;
934
-			case '>=':	$retVal= ($val1 >= $val2); break;
935
-			case '=':	$retVal= ($val1 == $val2); break;
936
-			case '!=':	$retVal= ($val1 != $val2); break;
937
-			case '~':	$retVal= (preg_match('/'.preg_replace('/"/','',$val2).'/',$val1)); break;
938
-			case '|':	$retVal= ($val1 || $val2); break;
939
-			case '&':	$retVal= ($val1 && $val2); break;
930
+		switch ($comp) {
931
+			case '<':	$retVal=($val1 < $val2); break;
932
+			case '<=':	$retVal=($val1 <= $val2); break;
933
+			case '>':	$retVal=($val1 > $val2); break;
934
+			case '>=':	$retVal=($val1 >= $val2); break;
935
+			case '=':	$retVal=($val1 == $val2); break;
936
+			case '!=':	$retVal=($val1 != $val2); break;
937
+			case '~':	$retVal=(preg_match('/'.preg_replace('/"/', '', $val2).'/', $val1)); break;
938
+			case '|':	$retVal=($val1 || $val2); break;
939
+			case '&':	$retVal=($val1 && $val2); break;
940 940
 			default:  throw new Exception("Error in expression - unknown comp : ".$comp);
941 941
 		}
942
-		if ($negate === true) $retVal = ! $retVal; // Inverse result if negate before expression
942
+		if ($negate === true) $retVal=!$retVal; // Inverse result if negate before expression
943 943
 		
944
-		if ($item==strlen($rule)) return $retVal; // End of string : return evaluation
944
+		if ($item == strlen($rule)) return $retVal; // End of string : return evaluation
945 945
 		// check for logical operator :
946 946
 		switch ($rule[$item])
947 947
 		{
948
-			case '|':	$item++; return ($retVal || $this->evaluation($rule,$item) );
949
-			case '&':	$item++; return ($retVal && $this->evaluation($rule,$item) );
948
+			case '|':	$item++; return ($retVal || $this->evaluation($rule, $item));
949
+			case '&':	$item++; return ($retVal && $this->evaluation($rule, $item));
950 950
 			
951 951
 			default:  throw new Exception("Erreur in expr - garbadge at end of expression : ".$rule[$item]);
952 952
 		}
@@ -958,17 +958,17 @@  discard block
 block discarded – undo
958 958
 		$rule2='';
959 959
 		while ($item < strlen($rule))
960 960
 		{
961
-			if ($rule[$item]==' ') { $item++; continue; }
962
-			if ($rule[$item]=='"')
961
+			if ($rule[$item] == ' ') { $item++; continue; }
962
+			if ($rule[$item] == '"')
963 963
 			{
964 964
 				$rule2.=$rule[$item];
965 965
 				$item++;
966
-				while (($rule[$item]!='"') && ($item < strlen($rule)))
966
+				while (($rule[$item] != '"') && ($item < strlen($rule)))
967 967
 				{
968 968
 					$rule2.=$rule[$item];
969 969
 					$item++;
970 970
 				}
971
-				if ($item == strlen ($rule)) throw new Exception("closing '\"' not found in ".$rule ." at " .$item);
971
+				if ($item == strlen($rule)) throw new Exception("closing '\"' not found in ".$rule." at ".$item);
972 972
 				$rule2.=$rule[$item];
973 973
 				$item++;
974 974
 				continue;
@@ -988,12 +988,12 @@  discard block
 block discarded – undo
988 988
 	
989 989
 	protected function eval_rule($rule)
990 990
 	{
991
-		if ($rule==null || $rule == '') // Empty rule is always true
991
+		if ($rule == null || $rule == '') // Empty rule is always true
992 992
 		{
993 993
 			return true;
994 994
 		}
995 995
 		$matches=array();
996
-		while (preg_match('/_OID\(([0-9\.\*]+)\)/',$rule,$matches) == 1)
996
+		while (preg_match('/_OID\(([0-9\.\*]+)\)/', $rule, $matches) == 1)
997 997
 		{
998 998
 			$oid=$matches[1];
999 999
 			$found=0;
@@ -1005,49 +1005,49 @@  discard block
 block discarded – undo
1005 1005
 			// replace * with \* in oid for preg_replace
1006 1006
 			$oid=preg_replace('/\*/', '\*', $oid);
1007 1007
 			
1008
-			$this->logging->log('OID in rule : '.$oid.' / '.$oidR,DEBUG );
1008
+			$this->logging->log('OID in rule : '.$oid.' / '.$oidR, DEBUG);
1009 1009
 			
1010
-			foreach($this->trap_data_ext as $val)
1010
+			foreach ($this->trap_data_ext as $val)
1011 1011
 			{
1012
-				if (preg_match("/^$oidR$/",$val->oid) == 1)
1012
+				if (preg_match("/^$oidR$/", $val->oid) == 1)
1013 1013
 				{
1014
-					if (!preg_match('/^[0-9]*\.?[0-9]+$/',$val->value))
1014
+					if (!preg_match('/^[0-9]*\.?[0-9]+$/', $val->value))
1015 1015
 					{ // If not a number, change " to ' and put " around it
1016
-						$val->value=preg_replace('/"/',"'",$val->value);
1016
+						$val->value=preg_replace('/"/', "'", $val->value);
1017 1017
 						$val->value='"'.$val->value.'"';
1018 1018
 					}
1019 1019
 					$rep=0;
1020
-					$rule=preg_replace('/_OID\('.$oid.'\)/',$val->value,$rule,-1,$rep);
1021
-					if ($rep==0)
1020
+					$rule=preg_replace('/_OID\('.$oid.'\)/', $val->value, $rule, -1, $rep);
1021
+					if ($rep == 0)
1022 1022
 					{
1023
-						$this->logging->log("Error in rule_eval",WARN,'');
1023
+						$this->logging->log("Error in rule_eval", WARN, '');
1024 1024
 						return false;
1025 1025
 					}
1026 1026
 					$found=1;
1027 1027
 					break;
1028 1028
 				}
1029 1029
 			}
1030
-			if ($found==0)
1030
+			if ($found == 0)
1031 1031
 			{	// OID not found : throw error
1032 1032
 			    throw new Exception('OID '.$oid.' not found in trap');
1033 1033
 			}
1034 1034
 		}
1035 1035
 		$item=0;
1036 1036
 		$rule=$this->eval_cleanup($rule);
1037
-		$this->logging->log('Rule after clenup: '.$rule,INFO );
1037
+		$this->logging->log('Rule after clenup: '.$rule, INFO);
1038 1038
 		
1039
-		return  $this->evaluation($rule,$item);
1039
+		return  $this->evaluation($rule, $item);
1040 1040
 	}
1041 1041
 	
1042 1042
 	/** Match rules for current trap and do action
1043 1043
 	*/
1044 1044
 	public function applyRules()
1045 1045
 	{
1046
-		$rules = $this->getRules($this->trap_data['source_ip'],$this->trap_data['trap_oid']);
1046
+		$rules=$this->getRules($this->trap_data['source_ip'], $this->trap_data['trap_oid']);
1047 1047
 		
1048
-		if ($rules===false || count($rules)==0)
1048
+		if ($rules === false || count($rules) == 0)
1049 1049
 		{
1050
-			$this->logging->log('No rules found for this trap',INFO );
1050
+			$this->logging->log('No rules found for this trap', INFO);
1051 1051
 			$this->trap_data['status']='unknown';
1052 1052
 			$this->trap_to_db=true;
1053 1053
 			return;
@@ -1062,58 +1062,58 @@  discard block
 block discarded – undo
1062 1062
 			$service_name=$rule['service_name'];
1063 1063
 			
1064 1064
 			$display=$this->applyDisplay($rule['display']);
1065
-			$this->trap_action = ($this->trap_action==null)? '' : $this->trap_action . ', ';
1065
+			$this->trap_action=($this->trap_action == null) ? '' : $this->trap_action.', ';
1066 1066
 			try
1067 1067
 			{
1068
-				$this->logging->log('Rule to eval : '.$rule['rule'],INFO );
1068
+				$this->logging->log('Rule to eval : '.$rule['rule'], INFO);
1069 1069
 				$evalr=$this->eval_rule($rule['rule']);
1070 1070
 				
1071 1071
 				if ($evalr == true)
1072 1072
 				{
1073 1073
 					//$this->logging->log('rules OOK: '.print_r($rule),INFO );
1074 1074
 					$action=$rule['action_match'];
1075
-					$this->logging->log('action OK : '.$action,INFO );
1075
+					$this->logging->log('action OK : '.$action, INFO);
1076 1076
 					if ($action >= 0)
1077 1077
 					{
1078
-						if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false)
1078
+						if ($this->serviceCheckResult($host_name, $service_name, $action, $display) == false)
1079 1079
 						{
1080 1080
 						    $this->trap_action.='Error sending status : check cmd/API';
1081 1081
 						}
1082 1082
 						else
1083 1083
 						{
1084
-						    $this->add_rule_match($rule['id'],$rule['num_match']+1);
1084
+						    $this->add_rule_match($rule['id'], $rule['num_match'] + 1);
1085 1085
 						    $this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
1086 1086
 						}
1087 1087
 					}
1088 1088
 					else
1089 1089
 					{
1090
-						$this->add_rule_match($rule['id'],$rule['num_match']+1);
1090
+						$this->add_rule_match($rule['id'], $rule['num_match'] + 1);
1091 1091
 					}
1092
-					$this->trap_to_db=($action==-2)?false:true;
1092
+					$this->trap_to_db=($action == -2) ?false:true;
1093 1093
 				}
1094 1094
 				else
1095 1095
 				{
1096 1096
 					//$this->logging->log('rules KOO : '.print_r($rule),INFO );
1097 1097
 					
1098 1098
 					$action=$rule['action_nomatch'];
1099
-					$this->logging->log('action NOK : '.$action,INFO );
1099
+					$this->logging->log('action NOK : '.$action, INFO);
1100 1100
 					if ($action >= 0)
1101 1101
 					{
1102
-					    if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false)
1102
+					    if ($this->serviceCheckResult($host_name, $service_name, $action, $display) == false)
1103 1103
 					    {
1104 1104
 					        $this->trap_action.='Error sending status : check cmd/API';
1105 1105
 					    }
1106 1106
 					    else
1107 1107
 					    {
1108
-    						$this->add_rule_match($rule['id'],$rule['num_match']+1);
1108
+    						$this->add_rule_match($rule['id'], $rule['num_match'] + 1);
1109 1109
     						$this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
1110 1110
 					    }
1111 1111
 					}
1112 1112
 					else
1113 1113
 					{
1114
-						$this->add_rule_match($rule['id'],$rule['num_match']+1);
1114
+						$this->add_rule_match($rule['id'], $rule['num_match'] + 1);
1115 1115
 					}
1116
-					$this->trap_to_db=($action==-2)?false:true;					
1116
+					$this->trap_to_db=($action == -2) ?false:true;					
1117 1117
 				}
1118 1118
 				// Put name in source_name
1119 1119
 				if (!isset($this->trap_data['source_name']))
@@ -1122,7 +1122,7 @@  discard block
 block discarded – undo
1122 1122
 				}
1123 1123
 				else
1124 1124
 				{
1125
-					if (!preg_match('/'.$rule['host_name'].'/',$this->trap_data['source_name']))
1125
+					if (!preg_match('/'.$rule['host_name'].'/', $this->trap_data['source_name']))
1126 1126
 					{ // only add if not present
1127 1127
 						$this->trap_data['source_name'].=','.$rule['host_name'];
1128 1128
 					}
@@ -1130,13 +1130,13 @@  discard block
 block discarded – undo
1130 1130
 			}
1131 1131
 			catch (Exception $e) 
1132 1132
 			{ 
1133
-			    $this->logging->log('Error in rule eval : '.$e->getMessage(),WARN,'');
1133
+			    $this->logging->log('Error in rule eval : '.$e->getMessage(), WARN, '');
1134 1134
 			    $this->trap_action.=' ERR : '.$e->getMessage();
1135 1135
 			    $this->trap_data['status']='error';
1136 1136
 			}
1137 1137
 			
1138 1138
 		}
1139
-		if ($this->trap_data['status']=='error')
1139
+		if ($this->trap_data['status'] == 'error')
1140 1140
 		{
1141 1141
 		  $this->trap_to_db=true; // Always put errors in DB for the use can see
1142 1142
 		}
@@ -1152,13 +1152,13 @@  discard block
 block discarded – undo
1152 1152
 	public function add_rule_final($time)
1153 1153
 	{
1154 1154
 		$db_conn=$this->trapsDB->db_connect_trap();
1155
-		if ($this->trap_action==null) 
1155
+		if ($this->trap_action == null) 
1156 1156
 		{
1157 1157
 			$this->trap_action='No action';
1158 1158
 		}
1159 1159
 		$sql="UPDATE ".$this->db_prefix."received SET process_time = '".$time."' , status_detail='".$this->trap_action."'  WHERE (id = '".$this->trap_id."');";
1160 1160
 		if ($db_conn->query($sql) === false) {
1161
-			$this->logging->log('Error in update query : ' . $sql,WARN,'');
1161
+			$this->logging->log('Error in update query : '.$sql, WARN, '');
1162 1162
 		}
1163 1163
 	}
1164 1164
 	
@@ -1168,14 +1168,14 @@  discard block
 block discarded – undo
1168 1168
 	*	@param $schema_file	string File to read schema from
1169 1169
 	*	@param $table_prefix string to replace #PREFIX# in schema file by this
1170 1170
 	*/
1171
-	public function create_schema($schema_file,$table_prefix)
1171
+	public function create_schema($schema_file, $table_prefix)
1172 1172
 	{
1173 1173
 		//Read data from snmptrapd from stdin
1174 1174
 		$input_stream=fopen($schema_file, 'r');
1175 1175
 
1176
-		if ($input_stream=== false)
1176
+		if ($input_stream === false)
1177 1177
 		{
1178
-			$this->logging->log("Error reading schema !",ERROR,''); 
1178
+			$this->logging->log("Error reading schema !", ERROR, ''); 
1179 1179
 			return;
1180 1180
 		}
1181 1181
 		$newline='';
@@ -1185,14 +1185,14 @@  discard block
 block discarded – undo
1185 1185
 		
1186 1186
 		while (($line=fgets($input_stream)) !== false)
1187 1187
 		{
1188
-			$newline.=chop(preg_replace('/#PREFIX#/',$table_prefix,$line));
1188
+			$newline.=chop(preg_replace('/#PREFIX#/', $table_prefix, $line));
1189 1189
 			if (preg_match('/; *$/', $newline)) 
1190 1190
             {
1191
-                $sql= $newline;
1191
+                $sql=$newline;
1192 1192
                 if ($db_conn->query($sql) === false) {
1193
-                    $this->logging->log('Error create schema : '.$sql,ERROR,'');
1193
+                    $this->logging->log('Error create schema : '.$sql, ERROR, '');
1194 1194
                 }
1195
-                if (preg_match('/^ *CREATE TABLE ([^ ]+)/',$newline,$cur_table_array))
1195
+                if (preg_match('/^ *CREATE TABLE ([^ ]+)/', $newline, $cur_table_array))
1196 1196
                 {
1197 1197
                     $cur_table='table '.$cur_table_array[1];
1198 1198
                 }
@@ -1200,19 +1200,19 @@  discard block
 block discarded – undo
1200 1200
                 {
1201 1201
                     $cur_table='secret SQL stuff :-)';
1202 1202
                 }
1203
-                $this->logging->log('Creating : ' . $cur_table,INFO );
1203
+                $this->logging->log('Creating : '.$cur_table, INFO);
1204 1204
                 $newline='';
1205 1205
             }
1206 1206
 		}
1207 1207
 		
1208
-		$sql= $newline;
1208
+		$sql=$newline;
1209 1209
 		if ($sql != '')
1210 1210
 		{
1211 1211
     		if ($db_conn->query($sql) === false) {
1212
-    			$this->logging->log('Error create schema : '.$sql,ERROR,'');
1212
+    			$this->logging->log('Error create schema : '.$sql, ERROR, '');
1213 1213
     		}
1214 1214
 		}
1215
-		$this->logging->log('Schema created',INFO);		
1215
+		$this->logging->log('Schema created', INFO);		
1216 1216
 	}
1217 1217
 
1218 1218
 	/** 
@@ -1223,14 +1223,14 @@  discard block
 block discarded – undo
1223 1223
 	 *     @param bool $getmsg : only get messages from version upgrades
1224 1224
 	 *     @return string : if $getmsg=true, return messages.
1225 1225
 	 */
1226
-	public function update_schema($prefix,$target_version,$table_prefix,$getmsg=false)
1226
+	public function update_schema($prefix, $target_version, $table_prefix, $getmsg=false)
1227 1227
 	{
1228 1228
 	    // Get current db number
1229 1229
 	    $db_conn=$this->trapsDB->db_connect_trap();
1230 1230
 	    $sql='SELECT id,value from '.$this->db_prefix.'db_config WHERE name=\'db_version\' ';
1231
-	    $this->logging->log('SQL query : '.$sql,DEBUG );
1231
+	    $this->logging->log('SQL query : '.$sql, DEBUG);
1232 1232
 	    if (($ret_code=$db_conn->query($sql)) === false) {
1233
-	        $this->logging->log('Cannot get db version. Query : ' . $sql,2,'');
1233
+	        $this->logging->log('Cannot get db version. Query : '.$sql, 2, '');
1234 1234
 	        return;
1235 1235
 	    }
1236 1236
 	    $version=$ret_code->fetchAll();
@@ -1239,47 +1239,47 @@  discard block
 block discarded – undo
1239 1239
 	    
1240 1240
 	    if ($this->trapsDB->trapDBType == 'pgsql')
1241 1241
 	    {
1242
-	        $prefix .= 'update_pgsql/schema_';
1242
+	        $prefix.='update_pgsql/schema_';
1243 1243
 	    }
1244 1244
 	    else
1245 1245
 	    {
1246
-	        $prefix .= 'update_sql/schema_';
1246
+	        $prefix.='update_sql/schema_';
1247 1247
 	    }
1248 1248
 	    //echo "version all :\n";print_r($version);echo " \n $cur_ver \n";
1249 1249
 	    if ($getmsg === true)
1250 1250
 	    {
1251 1251
 	        $message='';
1252
-	        $this->logging->log('getting message for upgrade',DEBUG );
1253
-	        while($cur_version<$target_version)
1252
+	        $this->logging->log('getting message for upgrade', DEBUG);
1253
+	        while ($cur_version < $target_version)
1254 1254
 	        {
1255 1255
 	            $cur_version++;
1256
-	            $updateFile=$prefix.'v'.($cur_version-1).'_v'.$cur_version.'.sql';
1256
+	            $updateFile=$prefix.'v'.($cur_version - 1).'_v'.$cur_version.'.sql';
1257 1257
 	            $input_stream=fopen($updateFile, 'r');
1258
-	            if ($input_stream=== false)
1258
+	            if ($input_stream === false)
1259 1259
 	            {
1260
-	                $this->logging->log("Error reading update file ". $updateFile,2,'');
1260
+	                $this->logging->log("Error reading update file ".$updateFile, 2, '');
1261 1261
 	                return;
1262 1262
 	            }
1263 1263
 	            do { $line=fgets($input_stream); }
1264
-	            while ($line !== false && !preg_match('/#MESSAGE/',$line));
1264
+	            while ($line !== false && !preg_match('/#MESSAGE/', $line));
1265 1265
 	            if ($line === false)
1266 1266
 	            {
1267
-	                $this->logging->log("No message in file ". $updateFile,2,'');
1267
+	                $this->logging->log("No message in file ".$updateFile, 2, '');
1268 1268
 	                return;
1269 1269
 	            }
1270
-	            $message .= ($cur_version-1) . '->' . $cur_version. ' : ' . preg_replace('/#MESSAGE : /','',$line)."\n";
1270
+	            $message.=($cur_version - 1).'->'.$cur_version.' : '.preg_replace('/#MESSAGE : /', '', $line)."\n";
1271 1271
 	        }
1272 1272
 	        return $message;
1273 1273
 	    }
1274
-	    while($cur_version<$target_version)
1274
+	    while ($cur_version < $target_version)
1275 1275
 	    { // tODO : execute pre & post scripts
1276 1276
 	       $cur_version++;
1277
-	       $this->logging->log('Updating to version : ' .$cur_version ,INFO );
1278
-	       $updateFile=$prefix.'v'.($cur_version-1).'_v'.$cur_version.'.sql';
1277
+	       $this->logging->log('Updating to version : '.$cur_version, INFO);
1278
+	       $updateFile=$prefix.'v'.($cur_version - 1).'_v'.$cur_version.'.sql';
1279 1279
 	       $input_stream=fopen($updateFile, 'r');
1280
-	       if ($input_stream=== false)
1280
+	       if ($input_stream === false)
1281 1281
 	       {
1282
-	           $this->logging->log("Error reading update file ". $updateFile,2,'');
1282
+	           $this->logging->log("Error reading update file ".$updateFile, 2, '');
1283 1283
 	           return;
1284 1284
 	       }
1285 1285
 	       $newline='';
@@ -1288,24 +1288,24 @@  discard block
 block discarded – undo
1288 1288
 	       while (($line=fgets($input_stream)) !== false)
1289 1289
 	       {
1290 1290
 	           if (preg_match('/^#/', $line)) continue; // ignore comment lines
1291
-	           $newline.=chop(preg_replace('/#PREFIX#/',$table_prefix,$line));
1291
+	           $newline.=chop(preg_replace('/#PREFIX#/', $table_prefix, $line));
1292 1292
 	           if (preg_match('/; *$/', $newline))
1293 1293
 	           {
1294 1294
 	               $sql_req=$db_conn->prepare($newline);
1295 1295
 	               if ($sql_req->execute() === false) {
1296
-	                   $this->logging->log('Error create schema : '.$newline,1,'');
1296
+	                   $this->logging->log('Error create schema : '.$newline, 1, '');
1297 1297
 	               }
1298 1298
 	               $cur_table_array=array();
1299
-	               if (preg_match('/^ *([^ ]+) TABLE ([^ ]+)/',$newline,$cur_table_array))
1299
+	               if (preg_match('/^ *([^ ]+) TABLE ([^ ]+)/', $newline, $cur_table_array))
1300 1300
 	               {
1301
-	                   $cur_table=$cur_table_array[1] . ' SQL table '.$cur_table_array[2];
1301
+	                   $cur_table=$cur_table_array[1].' SQL table '.$cur_table_array[2];
1302 1302
 	               }
1303 1303
 	               else
1304 1304
 	               {
1305 1305
 	                   $cur_table='secret SQL stuff :-)';
1306 1306
 	                   //$cur_table=$newline;
1307 1307
 	               }
1308
-	               $this->logging->log('Doing : ' . $cur_table,INFO );
1308
+	               $this->logging->log('Doing : '.$cur_table, INFO);
1309 1309
 	               
1310 1310
 	               $newline='';
1311 1311
 	           }
@@ -1318,13 +1318,13 @@  discard block
 block discarded – undo
1318 1318
 	       //}
1319 1319
 	       
1320 1320
 	       $sql='UPDATE '.$this->db_prefix.'db_config SET value='.$cur_version.' WHERE ( id = '.$db_version_id.' )';
1321
-	       $this->logging->log('SQL query : '.$sql,DEBUG );
1321
+	       $this->logging->log('SQL query : '.$sql, DEBUG);
1322 1322
 	       if ($db_conn->query($sql) === false) {
1323
-	           $this->logging->log('Cannot update db version. Query : ' . $sql,2);
1323
+	           $this->logging->log('Cannot update db version. Query : '.$sql, 2);
1324 1324
 	           return;
1325 1325
 	       }
1326 1326
 	       
1327
-	       $this->logging->log('Schema updated to version : '.$cur_version ,INFO);
1327
+	       $this->logging->log('Schema updated to version : '.$cur_version, INFO);
1328 1328
 	    }
1329 1329
 	}
1330 1330
 	
@@ -1345,7 +1345,7 @@  discard block
 block discarded – undo
1345 1345
     WHERE s.current_state != 0;";
1346 1346
 		$db_conn=$this->trapsDB->db_connect_ido();
1347 1347
 		if (($services_db=$db_conn->query($sql_query)) === false) { // set err to 1 to throw exception.
1348
-			$this->logging->log('No result in query : ' . $sql_query,ERROR,'');
1348
+			$this->logging->log('No result in query : '.$sql_query, ERROR, '');
1349 1349
 		}
1350 1350
 		$services=$services_db->fetchAll();
1351 1351
 		
@@ -1353,7 +1353,7 @@  discard block
 block discarded – undo
1353 1353
 		$sql_query="SELECT host_name, service_name, revert_ok FROM ".$this->db_prefix."rules where revert_ok != 0;";
1354 1354
 		$db_conn2=$this->trapsDB->db_connect_trap();
1355 1355
 		if (($rules_db=$db_conn2->query($sql_query)) === false) {
1356
-			$this->logging->log('No result in query : ' . $sql_query,ERROR,''); 
1356
+			$this->logging->log('No result in query : '.$sql_query, ERROR, ''); 
1357 1357
 		}
1358 1358
 		$rules=$rules_db->fetchAll();
1359 1359
 		
@@ -1368,13 +1368,13 @@  discard block
 block discarded – undo
1368 1368
 					$service['host_name'] == $rule['host_name'] &&
1369 1369
 					($service['last_check'] + $rule['revert_ok']) < $now)
1370 1370
 				{
1371
-					$this->serviceCheckResult($service['host_name'],$service['service_name'],0,'Reset service to OK after '.$rule['revert_ok'].' seconds');
1371
+					$this->serviceCheckResult($service['host_name'], $service['service_name'], 0, 'Reset service to OK after '.$rule['revert_ok'].' seconds');
1372 1372
 					$numreset++;
1373 1373
 				}
1374 1374
 			}
1375 1375
 		}
1376 1376
 		echo "\n";
1377
-		echo $numreset . " service(s) reset to OK\n";
1377
+		echo $numreset." service(s) reset to OK\n";
1378 1378
 		return 0;
1379 1379
 		
1380 1380
 	}
@@ -1395,7 +1395,7 @@  discard block
 block discarded – undo
1395 1395
 	 * @param string $description
1396 1396
 	 * @return number : 0=unchanged, 1 = changed, 2=created
1397 1397
 	 */
1398
-	public function update_oid($oid,$mib,$name,$type,$textConv,$dispHint,$syntax,$type_enum,$description=NULL)
1398
+	public function update_oid($oid, $mib, $name, $type, $textConv, $dispHint, $syntax, $type_enum, $description=NULL)
1399 1399
 	{
1400 1400
 		$db_conn=$this->trapsDB->db_connect_trap();
1401 1401
 		$description=$db_conn->quote($description);
@@ -1405,7 +1405,7 @@  discard block
 block discarded – undo
1405 1405
 		    { // newly created.
1406 1406
 		        return 0;
1407 1407
 		    }
1408
-			if ( $name != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['name'] ||
1408
+			if ($name != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['name'] ||
1409 1409
 			    $mib != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['mib'] ||
1410 1410
 			    $type != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['type'] //||
1411 1411
 			    //$textConv != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['textual_convention'] //||
@@ -1425,23 +1425,23 @@  discard block
 block discarded – undo
1425 1425
 			        ':name' => $name,
1426 1426
 			        ':type' => $type, 
1427 1427
 			        ':mib' => $mib, 
1428
-			        ':tc' =>  ($textConv==null)?'null':$textConv , 
1429
-			        ':display_hint' => ($dispHint==null)?'null':$dispHint ,
1430
-			        ':syntax' => ($syntax==null)?'null':$syntax,
1431
-			        ':type_enum' => ($type_enum==null)?'null':$type_enum, 
1432
-			        ':description' => ($description==null)?'null':$description,
1428
+			        ':tc' =>  ($textConv == null) ? 'null' : $textConv, 
1429
+			        ':display_hint' => ($dispHint == null) ? 'null' : $dispHint,
1430
+			        ':syntax' => ($syntax == null) ? 'null' : $syntax,
1431
+			        ':type_enum' => ($type_enum == null) ? 'null' : $type_enum, 
1432
+			        ':description' => ($description == null) ? 'null' : $description,
1433 1433
 			        ':id' => $this->dbOidAll[$this->dbOidIndex[$oid]['id']]
1434 1434
 			    );
1435 1435
 			    
1436 1436
 			    if ($sqlQuery->execute($sqlParam) === false) {
1437
-			        $this->logging->log('Error in query : ' . $sql,ERROR,'');
1437
+			        $this->logging->log('Error in query : '.$sql, ERROR, '');
1438 1438
 			    }
1439
-			    $this->logging->log('Trap updated : '.$name . ' / OID : '.$oid,DEBUG );
1439
+			    $this->logging->log('Trap updated : '.$name.' / OID : '.$oid, DEBUG);
1440 1440
 				return 1;
1441 1441
 			}
1442 1442
 			else
1443 1443
 			{
1444
-			    $this->logging->log('Trap unchanged : '.$name . ' / OID : '.$oid,DEBUG );
1444
+			    $this->logging->log('Trap unchanged : '.$name.' / OID : '.$oid, DEBUG);
1445 1445
 			    return 0;
1446 1446
 			}
1447 1447
 		}
@@ -1451,11 +1451,11 @@  discard block
 block discarded – undo
1451 1451
 
1452 1452
 		$sql='INSERT INTO '.$this->db_prefix.'mib_cache '.
1453 1453
 		      '(oid, name, type , mib, textual_convention, display_hint '.
1454
-              ', syntax, type_enum , description ) ' . 
1454
+              ', syntax, type_enum , description ) '. 
1455 1455
               'values (:oid, :name , :type ,:mib ,:tc , :display_hint'.
1456 1456
               ', :syntax, :type_enum, :description )';
1457 1457
         
1458
-		if ($this->trapsDB->trapDBType == 'pgsql') $sql .= 'RETURNING id';
1458
+		if ($this->trapsDB->trapDBType == 'pgsql') $sql.='RETURNING id';
1459 1459
 		
1460 1460
 		$sqlQuery=$db_conn->prepare($sql);
1461 1461
 		
@@ -1464,15 +1464,15 @@  discard block
 block discarded – undo
1464 1464
 		    ':name' => $name,
1465 1465
 		    ':type' => $type,
1466 1466
 		    ':mib' => $mib,
1467
-		    ':tc' =>  ($textConv==null)?'null':$textConv ,
1468
-		    ':display_hint' => ($dispHint==null)?'null':$dispHint ,
1469
-		    ':syntax' => ($syntax==null)?'null':$syntax,
1470
-		    ':type_enum' => ($type_enum==null)?'null':$type_enum,
1471
-		    ':description' => ($description==null)?'null':$description
1467
+		    ':tc' =>  ($textConv == null) ? 'null' : $textConv,
1468
+		    ':display_hint' => ($dispHint == null) ? 'null' : $dispHint,
1469
+		    ':syntax' => ($syntax == null) ? 'null' : $syntax,
1470
+		    ':type_enum' => ($type_enum == null) ? 'null' : $type_enum,
1471
+		    ':description' => ($description == null) ? 'null' : $description
1472 1472
 		);
1473 1473
 		
1474 1474
 		if ($sqlQuery->execute($sqlParam) === false) {
1475
-		    $this->logging->log('Error in query : ' . $sql,1,'');
1475
+		    $this->logging->log('Error in query : '.$sql, 1, '');
1476 1476
 		}
1477 1477
 		
1478 1478
 		switch ($this->trapsDB->trapDBType)
@@ -1480,10 +1480,10 @@  discard block
 block discarded – undo
1480 1480
 		    case 'pgsql':
1481 1481
 		        // Get last id to insert oid/values in secondary table
1482 1482
 		        if (($inserted_id_ret=$sqlQuery->fetch(PDO::FETCH_ASSOC)) === false) {		            
1483
-		            $this->logging->log('Error getting id - pgsql - ',1,'');
1483
+		            $this->logging->log('Error getting id - pgsql - ', 1, '');
1484 1484
 		        }
1485
-		        if (! isset($inserted_id_ret['id'])) {
1486
-		            $this->logging->log('Error getting id - pgsql - empty.',1,'');
1485
+		        if (!isset($inserted_id_ret['id'])) {
1486
+		            $this->logging->log('Error getting id - pgsql - empty.', 1, '');
1487 1487
 		        }
1488 1488
 		        $this->dbOidIndex[$oid]['id']=$inserted_id_ret['id'];
1489 1489
 		        break;
@@ -1491,15 +1491,15 @@  discard block
 block discarded – undo
1491 1491
 		        // Get last id to insert oid/values in secondary table
1492 1492
 		        $sql='SELECT LAST_INSERT_ID();';
1493 1493
 		        if (($ret_code=$db_conn->query($sql)) === false) {
1494
-		            $this->logging->log('Erreur getting id - mysql - ',1,'');
1494
+		            $this->logging->log('Erreur getting id - mysql - ', 1, '');
1495 1495
 		        }
1496 1496
 		        
1497 1497
 		        $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
1498
-		        if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
1498
+		        if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
1499 1499
 		        $this->dbOidIndex[$oid]['id']=$inserted_id;
1500 1500
 		        break;
1501 1501
 		    default:
1502
-		        $this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType,1,'');
1502
+		        $this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType, 1, '');
1503 1503
 		}
1504 1504
 
1505 1505
 		// Set as newly created.
@@ -1514,21 +1514,21 @@  discard block
 block discarded – undo
1514 1514
      * @param array $objects : array of objects name (without MIB)
1515 1515
      * @param bool $check_existing : check instead of create
1516 1516
      */
1517
-	public function trap_objects($trapOID,$trapmib,$objects,$check_existing)
1517
+	public function trap_objects($trapOID, $trapmib, $objects, $check_existing)
1518 1518
 	{
1519 1519
 	    $dbObjects=null; // cache of objects for trap in db
1520 1520
 	    $db_conn=$this->trapsDB->db_connect_trap();
1521 1521
 	    
1522 1522
 	    // Get id of trapmib.
1523 1523
 
1524
-	    $trapId = $this->dbOidIndex[$trapOID]['id'];
1524
+	    $trapId=$this->dbOidIndex[$trapOID]['id'];
1525 1525
 	    if ($check_existing === true)
1526 1526
 	    {
1527 1527
 	        // Get all objects
1528 1528
 	        $sql='SELECT * FROM '.$this->db_prefix.'mib_cache_trap_object where trap_id='.$trapId.';';
1529
-	        $this->logging->log('SQL query get all traps: '.$sql,DEBUG );
1529
+	        $this->logging->log('SQL query get all traps: '.$sql, DEBUG);
1530 1530
 	        if (($ret_code=$db_conn->query($sql)) === false) {
1531
-	            $this->logging->log('No result in query : ' . $sql,1,'');
1531
+	            $this->logging->log('No result in query : '.$sql, 1, '');
1532 1532
 	        }
1533 1533
 	        $dbObjectsRaw=$ret_code->fetchAll();
1534 1534
 	        
@@ -1542,39 +1542,39 @@  discard block
 block discarded – undo
1542 1542
 	        $match=$snmptrans=array();
1543 1543
 	        $retVal=0;
1544 1544
 	        $objOid=$objTc=$objDispHint=$objSyntax=$objDesc=$objEnum=NULL;
1545
-	        $tmpdesc='';$indesc=false;
1545
+	        $tmpdesc=''; $indesc=false;
1546 1546
 	        
1547 1547
 	        $objMib=$trapmib;
1548
-	        exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
1549
-	            ' -On -Td '.$objMib.'::'.$object . ' 2>/dev/null',$snmptrans,$retVal);
1550
-	        if ($retVal!=0)
1548
+	        exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.
1549
+	            ' -On -Td '.$objMib.'::'.$object.' 2>/dev/null', $snmptrans, $retVal);
1550
+	        if ($retVal != 0)
1551 1551
 	        {
1552 1552
 	            // Maybe not trap mib, search with IR
1553
-	            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
1554
-	                ' -IR '.$object . ' 2>/dev/null',$snmptrans,$retVal);
1555
-	            if ($retVal != 0 || !preg_match('/(.*)::(.*)/',$snmptrans[0],$match))
1553
+	            exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.
1554
+	                ' -IR '.$object.' 2>/dev/null', $snmptrans, $retVal);
1555
+	            if ($retVal != 0 || !preg_match('/(.*)::(.*)/', $snmptrans[0], $match))
1556 1556
 	            { // Not found -> continue with warning
1557
-	               $this->logging->log('Error finding trap object : '.$trapmib.'::'.$object,2,'');
1557
+	               $this->logging->log('Error finding trap object : '.$trapmib.'::'.$object, 2, '');
1558 1558
 	               continue;
1559 1559
 	            }
1560 1560
 	            $objMib=$match[1];
1561 1561
 	            
1562 1562
 	            // Do the snmptranslate again.
1563
-	            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
1564
-	                ' -On -Td '.$objMib.'::'.$object,$snmptrans,$retVal);
1565
-	            if ($retVal!=0) {
1566
-	                $this->logging->log('Error finding trap object : '.$objMib.'::'.$object,2,'');
1563
+	            exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.
1564
+	                ' -On -Td '.$objMib.'::'.$object, $snmptrans, $retVal);
1565
+	            if ($retVal != 0) {
1566
+	                $this->logging->log('Error finding trap object : '.$objMib.'::'.$object, 2, '');
1567 1567
 	            }
1568 1568
 	            
1569 1569
 	        }
1570 1570
 	        foreach ($snmptrans as $line)
1571 1571
 	        {
1572
-	            if ($indesc===true)
1572
+	            if ($indesc === true)
1573 1573
 	            {
1574
-	                $line=preg_replace('/[\t ]+/',' ',$line);
1575
-	                if (preg_match('/(.*)"$/', $line,$match))
1574
+	                $line=preg_replace('/[\t ]+/', ' ', $line);
1575
+	                if (preg_match('/(.*)"$/', $line, $match))
1576 1576
 	                {
1577
-	                    $objDesc = $tmpdesc . $match[1];
1577
+	                    $objDesc=$tmpdesc.$match[1];
1578 1578
 	                    $indesc=false;
1579 1579
 	                }
1580 1580
 	                $tmpdesc.=$line;
@@ -1585,43 +1585,43 @@  discard block
 block discarded – undo
1585 1585
 	                $objOid=$line;
1586 1586
 	                continue;
1587 1587
 	            }
1588
-	            if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/',$line,$match))
1588
+	            if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/', $line, $match))
1589 1589
 	            {
1590 1590
 	                $objSyntax=$match[1];
1591 1591
                     $objEnum=$match[2];
1592 1592
 	                continue;
1593 1593
 	            }
1594
-	            if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/',$line,$match))
1594
+	            if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/', $line, $match))
1595 1595
 	            {
1596 1596
 	                $objSyntax=$match[1];
1597 1597
 	                continue;
1598 1598
 	            }
1599
-	            if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/',$line,$match))
1599
+	            if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/', $line, $match))
1600 1600
 	            {
1601 1601
 	                $objDispHint=$match[1];
1602 1602
 	                continue;
1603 1603
 	            }
1604
-	            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/',$line,$match))
1604
+	            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/', $line, $match))
1605 1605
 	            {
1606 1606
 	                $objDesc=$match[1];
1607 1607
 	                continue;
1608 1608
 	            }
1609
-	            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$line,$match))
1609
+	            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/', $line, $match))
1610 1610
 	            {
1611 1611
 	                $tmpdesc=$match[1];
1612 1612
 	                $indesc=true;
1613 1613
 	                continue;
1614 1614
 	            }
1615
-	            if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/',$line,$match))
1615
+	            if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/', $line, $match))
1616 1616
 	            {
1617 1617
 	                $objTc=$match[1];
1618 1618
 	                continue;
1619 1619
 	            }
1620 1620
 	        }
1621
-	        $this->logging->log("Adding trap $object : $objOid / $objSyntax / $objEnum / $objDispHint / $objTc",DEBUG );
1621
+	        $this->logging->log("Adding trap $object : $objOid / $objSyntax / $objEnum / $objDispHint / $objTc", DEBUG);
1622 1622
 	        //echo "$object : $objOid / $objSyntax / $objEnum / $objDispHint / $objTc / $objDesc\n";
1623 1623
 	        // Update 
1624
-	        $this->update_oid($objOid, $objMib, $object, '3', $objTc, $objDispHint, $objSyntax, $objEnum,$objDesc);
1624
+	        $this->update_oid($objOid, $objMib, $object, '3', $objTc, $objDispHint, $objSyntax, $objEnum, $objDesc);
1625 1625
             
1626 1626
 	        if (isset($dbObjects[$this->dbOidIndex[$objOid]['id']]))
1627 1627
 	        {   // if link exists, continue
@@ -1642,7 +1642,7 @@  discard block
 block discarded – undo
1642 1642
 	        );
1643 1643
 	        
1644 1644
 	        if ($sqlQuery->execute($sqlParam) === false) {
1645
-	            $this->logging->log('Error adding trap object : ' . $sql . ' / ' . $trapId . '/'. $this->dbOidIndex[$objOid]['id'] ,1,'');
1645
+	            $this->logging->log('Error adding trap object : '.$sql.' / '.$trapId.'/'.$this->dbOidIndex[$objOid]['id'], 1, '');
1646 1646
 	        }
1647 1647
 	    }
1648 1648
 	    if ($check_existing === true)
@@ -1659,19 +1659,19 @@  discard block
 block discarded – undo
1659 1659
 	 * @param boolean $onlyTraps : only cache traps and objects (true) or all (false)
1660 1660
 	 * @param string $startOID : only cache under startOID (NOT IMPLEMENTED)
1661 1661
 	*/	
1662
-	public function update_mib_database($display_progress=false,$check_change=false,$onlyTraps=true,$startOID='.1')
1662
+	public function update_mib_database($display_progress=false, $check_change=false, $onlyTraps=true, $startOID='.1')
1663 1663
 	{
1664 1664
 		// Timing 
1665
-		$timeTaken = microtime(true);
1665
+		$timeTaken=microtime(true);
1666 1666
 		$retVal=0;
1667 1667
 		// Get all mib objects from all mibs
1668
-		$snmpCommand=$this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.' -On -Tto 2>/dev/null';
1669
-		$this->logging->log('Getting all traps : '.$snmpCommand,DEBUG );
1668
+		$snmpCommand=$this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.' -On -Tto 2>/dev/null';
1669
+		$this->logging->log('Getting all traps : '.$snmpCommand, DEBUG);
1670 1670
 		unset($this->objectsAll);
1671
-		exec($snmpCommand,$this->objectsAll,$retVal);		
1672
-		if ($retVal!=0)
1671
+		exec($snmpCommand, $this->objectsAll, $retVal);		
1672
+		if ($retVal != 0)
1673 1673
 		{
1674
-			$this->logging->log('error executing snmptranslate',ERROR,'');
1674
+			$this->logging->log('error executing snmptranslate', ERROR, '');
1675 1675
 		}
1676 1676
 		
1677 1677
 		// Get all mibs from databse to have a memory index
@@ -1679,14 +1679,14 @@  discard block
 block discarded – undo
1679 1679
 		$db_conn=$this->trapsDB->db_connect_trap();
1680 1680
 		
1681 1681
 		$sql='SELECT * from '.$this->db_prefix.'mib_cache;';
1682
-		$this->logging->log('SQL query : '.$sql,DEBUG );
1682
+		$this->logging->log('SQL query : '.$sql, DEBUG);
1683 1683
 		if (($ret_code=$db_conn->query($sql)) === false) {
1684
-			$this->logging->log('No result in query : ' . $sql,ERROR,'');
1684
+			$this->logging->log('No result in query : '.$sql, ERROR, '');
1685 1685
 		}
1686 1686
 		$this->dbOidAll=$ret_code->fetchAll();
1687 1687
 		$this->dbOidIndex=array();
1688 1688
 		// Create the index for db;
1689
-		foreach($this->dbOidAll as $key=>$val)
1689
+		foreach ($this->dbOidAll as $key=>$val)
1690 1690
 		{
1691 1691
 			$this->dbOidIndex[$val['oid']]['key']=$key;
1692 1692
 			$this->dbOidIndex[$val['oid']]['id']=$val['id'];
@@ -1694,11 +1694,11 @@  discard block
 block discarded – undo
1694 1694
 		
1695 1695
 		// Count elements to show progress
1696 1696
 		$numElements=count($this->objectsAll);
1697
-		$this->logging->log('Total snmp objects returned by snmptranslate : '.$numElements,INFO );
1697
+		$this->logging->log('Total snmp objects returned by snmptranslate : '.$numElements, INFO);
1698 1698
 		
1699
-		$step=$basestep=$numElements/10; // output display of % done
1699
+		$step=$basestep=$numElements / 10; // output display of % done
1700 1700
 		$num_step=0;
1701
-		$timeFiveSec = microtime(true); // Used for display a '.' every <n> seconds
1701
+		$timeFiveSec=microtime(true); // Used for display a '.' every <n> seconds
1702 1702
 		
1703 1703
 		// Create index for trap objects
1704 1704
 		$this->trapObjectsIndex=array();
@@ -1708,28 +1708,28 @@  discard block
 block discarded – undo
1708 1708
 		$time_parse1N=$time_check1N=$time_check2N=$time_check3N=$time_updateN=$time_objectsN=0;
1709 1709
 		$time_num_traps=0;
1710 1710
 		
1711
-		for ($curElement=0;$curElement < $numElements;$curElement++)
1711
+		for ($curElement=0; $curElement < $numElements; $curElement++)
1712 1712
 		{
1713
-		    $time_1= microtime(true);
1714
-			if ((microtime(true)-$timeFiveSec) > 2 && $display_progress)
1713
+		    $time_1=microtime(true);
1714
+			if ((microtime(true) - $timeFiveSec) > 2 && $display_progress)
1715 1715
 			{ // echo a . every 2 sec
1716 1716
 				echo '.';
1717
-				$timeFiveSec = microtime(true);
1717
+				$timeFiveSec=microtime(true);
1718 1718
 			}
1719
-			if ($curElement>$step) 
1719
+			if ($curElement > $step) 
1720 1720
 			{ // display progress
1721 1721
 				$num_step++;
1722 1722
 				$step+=$basestep;
1723 1723
 				if ($display_progress)
1724 1724
 				{				
1725
-					echo "\n" . ($num_step*10). '% : ';
1725
+					echo "\n".($num_step * 10).'% : ';
1726 1726
 				}
1727 1727
 			}
1728 1728
 			// Get oid or pass if not found
1729
-			if (!preg_match('/^\.[0-9\.]+$/',$this->objectsAll[$curElement]))
1729
+			if (!preg_match('/^\.[0-9\.]+$/', $this->objectsAll[$curElement]))
1730 1730
 			{
1731
-			    $time_parse1 += microtime(true) - $time_1;
1732
-			    $time_parse1N ++;
1731
+			    $time_parse1+=microtime(true) - $time_1;
1732
+			    $time_parse1N++;
1733 1733
 				continue;
1734 1734
 			}
1735 1735
 			$oid=$this->objectsAll[$curElement];
@@ -1738,9 +1738,9 @@  discard block
 block discarded – undo
1738 1738
 			$curElement++;
1739 1739
 			$match=$snmptrans=array();
1740 1740
 			if (!preg_match('/ +([^\(]+)\(.+\) type=([0-9]+)( tc=([0-9]+))?( hint=(.+))?/',
1741
-						$this->objectsAll[$curElement],$match))
1741
+						$this->objectsAll[$curElement], $match))
1742 1742
 			{
1743
-			    $time_check1 += microtime(true) - $time_1;
1743
+			    $time_check1+=microtime(true) - $time_1;
1744 1744
 				$time_check1N++;
1745 1745
 				continue;
1746 1746
 			}
@@ -1748,21 +1748,21 @@  discard block
 block discarded – undo
1748 1748
 			$name=$match[1]; // Name 
1749 1749
 			$type=$match[2]; // type (21=trap, 0: may be trap, else : not trap
1750 1750
 			
1751
-			if ($type==0) // object type=0 : check if v1 trap
1751
+			if ($type == 0) // object type=0 : check if v1 trap
1752 1752
 			{
1753 1753
 				// Check if next is suboid -> in that case is cannot be a trap
1754
-				if (preg_match("/^$oid/",$this->objectsAll[$curElement+1]))
1754
+				if (preg_match("/^$oid/", $this->objectsAll[$curElement + 1]))
1755 1755
 				{
1756
-				    $time_check2 += microtime(true) - $time_1;
1756
+				    $time_check2+=microtime(true) - $time_1;
1757 1757
 				    $time_check2N++;
1758 1758
 					continue;
1759 1759
 				}		
1760 1760
 				unset($snmptrans);
1761
-				exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
1762
-					' -Td '.$oid . ' | grep OBJECTS ',$snmptrans,$retVal);
1763
-				if ($retVal!=0)
1761
+				exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.
1762
+					' -Td '.$oid.' | grep OBJECTS ', $snmptrans, $retVal);
1763
+				if ($retVal != 0)
1764 1764
 				{
1765
-				    $time_check2 += microtime(true) - $time_1;
1765
+				    $time_check2+=microtime(true) - $time_1;
1766 1766
 				    $time_check2N++;
1767 1767
 					continue;
1768 1768
 				}
@@ -1770,56 +1770,56 @@  discard block
 block discarded – undo
1770 1770
 				// Force as trap.
1771 1771
 				$type=21;
1772 1772
 			}
1773
-			if ($onlyTraps===true && $type!=21) // if only traps and not a trap, continue
1773
+			if ($onlyTraps === true && $type != 21) // if only traps and not a trap, continue
1774 1774
 			{
1775
-			    $time_check3 += microtime(true) - $time_1;
1775
+			    $time_check3+=microtime(true) - $time_1;
1776 1776
 				$time_check3N++;
1777 1777
 				continue;
1778 1778
 			}
1779 1779
 			
1780 1780
 			$time_num_traps++;
1781 1781
 			
1782
-			$this->logging->log('Found trap : '.$match[1] . ' / OID : '.$oid,INFO );
1782
+			$this->logging->log('Found trap : '.$match[1].' / OID : '.$oid, INFO);
1783 1783
 			if ($display_progress) echo '#'; // echo a # when trap found
1784 1784
 				
1785 1785
 			// get trap objects & source MIB
1786 1786
 			unset($snmptrans);
1787
-			exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
1788
-					' -Td '.$oid,$snmptrans,$retVal);
1789
-			if ($retVal!=0)
1787
+			exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.
1788
+					' -Td '.$oid, $snmptrans, $retVal);
1789
+			if ($retVal != 0)
1790 1790
 			{
1791
-				$this->logging->log('error executing snmptranslate',ERROR,'');
1791
+				$this->logging->log('error executing snmptranslate', ERROR, '');
1792 1792
 			}
1793 1793
 			
1794
-			if (!preg_match('/^(.*)::/',$snmptrans[0],$match))
1794
+			if (!preg_match('/^(.*)::/', $snmptrans[0], $match))
1795 1795
 			{
1796
-			    $this->logging->log('Error getting mib from trap '.$oid.' : ' . $snmptrans[0],1,'');
1796
+			    $this->logging->log('Error getting mib from trap '.$oid.' : '.$snmptrans[0], 1, '');
1797 1797
 			}
1798 1798
 			$trapMib=$match[1];
1799 1799
 			
1800
-			$numLine=1;$trapDesc='';
1801
-			while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++;
1800
+			$numLine=1; $trapDesc='';
1801
+			while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/', $snmptrans[$numLine], $match)) $numLine++;
1802 1802
 			if (isset($snmptrans[$numLine]))
1803 1803
 			{
1804
-			    $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]);
1804
+			    $snmptrans[$numLine]=preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/', '', $snmptrans[$numLine]);
1805 1805
 
1806
-			    while (isset($snmptrans[$numLine]) && !preg_match('/"/',$snmptrans[$numLine]))
1806
+			    while (isset($snmptrans[$numLine]) && !preg_match('/"/', $snmptrans[$numLine]))
1807 1807
 			    {
1808
-			        $trapDesc.=preg_replace('/[\t ]+/',' ',$snmptrans[$numLine]);
1808
+			        $trapDesc.=preg_replace('/[\t ]+/', ' ', $snmptrans[$numLine]);
1809 1809
 			        $numLine++;
1810 1810
 			    }
1811 1811
 			    if (isset($snmptrans[$numLine])) {
1812
-			        $trapDesc.=preg_replace('/".*/','',$snmptrans[$numLine]);
1813
-			        $trapDesc=preg_replace('/[\t ]+/',' ',$trapDesc);
1812
+			        $trapDesc.=preg_replace('/".*/', '', $snmptrans[$numLine]);
1813
+			        $trapDesc=preg_replace('/[\t ]+/', ' ', $trapDesc);
1814 1814
 			    }
1815 1815
 
1816 1816
 			}
1817
-			$update=$this->update_oid($oid,$trapMib,$name,$type,NULL,NULL,NULL,NULL,$trapDesc);
1818
-			$time_update += microtime(true) - $time_1; $time_1= microtime(true);
1817
+			$update=$this->update_oid($oid, $trapMib, $name, $type, NULL, NULL, NULL, NULL, $trapDesc);
1818
+			$time_update+=microtime(true) - $time_1; $time_1=microtime(true);
1819 1819
 			
1820
-			if (($update==0) && ($check_change===false))
1820
+			if (($update == 0) && ($check_change === false))
1821 1821
 			{ // Trapd didn't change & force check disabled
1822
-			    $time_objects += microtime(true) - $time_1;
1822
+			    $time_objects+=microtime(true) - $time_1;
1823 1823
 			    if ($display_progress) echo "C";
1824 1824
 			    continue;
1825 1825
 			}
@@ -1827,7 +1827,7 @@  discard block
 block discarded – undo
1827 1827
 			$synt=null;
1828 1828
 			foreach ($snmptrans as $line)
1829 1829
 			{	
1830
-    			if (preg_match('/OBJECTS.*\{([^\}]+)\}/',$line,$match))
1830
+    			if (preg_match('/OBJECTS.*\{([^\}]+)\}/', $line, $match))
1831 1831
     				{
1832 1832
     					$synt=$match[1];
1833 1833
     				}
@@ -1835,30 +1835,30 @@  discard block
 block discarded – undo
1835 1835
 			if ($synt == null) 
1836 1836
 			{
1837 1837
 				//echo "No objects for $trapOID\n";
1838
-			    $time_objects += microtime(true) - $time_1;
1838
+			    $time_objects+=microtime(true) - $time_1;
1839 1839
 				continue;
1840 1840
 			}
1841 1841
 			//echo "$synt \n";
1842 1842
 			$trapObjects=array();
1843
-			while (preg_match('/ *([^ ,]+) *,* */',$synt,$match))
1843
+			while (preg_match('/ *([^ ,]+) *,* */', $synt, $match))
1844 1844
 			{
1845
-				array_push($trapObjects,$match[1]);
1846
-				$synt=preg_replace('/'.$match[0].'/','',$synt);
1845
+				array_push($trapObjects, $match[1]);
1846
+				$synt=preg_replace('/'.$match[0].'/', '', $synt);
1847 1847
 			}
1848 1848
 			
1849 1849
 			$this->trap_objects($oid, $trapMib, $trapObjects, false);
1850 1850
 			
1851
-			$time_objects += microtime(true) - $time_1;
1851
+			$time_objects+=microtime(true) - $time_1;
1852 1852
 			$time_objectsN++;
1853 1853
 		}
1854 1854
 		
1855 1855
 		if ($display_progress)
1856 1856
 		{
1857 1857
     		echo "\nNumber of processed traps : $time_num_traps \n";
1858
-    		echo "\nParsing : " . number_format($time_parse1+$time_check1,1) ." sec / " . ($time_parse1N+ $time_check1N)  . " occurences\n";
1859
-    		echo "Detecting traps : " . number_format($time_check2+$time_check3,1) . " sec / " . ($time_check2N+$time_check3N) ." occurences\n";
1860
-    		echo "Trap processing ($time_updateN): ".number_format($time_update,1)." sec , ";
1861
-    		echo "Objects processing ($time_objectsN) : ".number_format($time_objects,1)." sec \n";
1858
+    		echo "\nParsing : ".number_format($time_parse1 + $time_check1, 1)." sec / ".($time_parse1N + $time_check1N)." occurences\n";
1859
+    		echo "Detecting traps : ".number_format($time_check2 + $time_check3, 1)." sec / ".($time_check2N + $time_check3N)." occurences\n";
1860
+    		echo "Trap processing ($time_updateN): ".number_format($time_update, 1)." sec , ";
1861
+    		echo "Objects processing ($time_objectsN) : ".number_format($time_objects, 1)." sec \n";
1862 1862
 		}
1863 1863
 		
1864 1864
 		// Timing ends
Please login to merge, or discard this patch.
Braces   +119 added lines, -74 removed lines patch added patch discarded remove patch
@@ -71,9 +71,9 @@  discard block
 block discarded – undo
71 71
 		{
72 72
 		    $this->logging->setLogging($baseLogLevel, $baseLogMode,$baseLogFile);
73 73
 		    $this->logSetup=true;
74
+		} else {
75
+				    $this->logSetup=false;
74 76
 		}
75
-		else 
76
-		    $this->logSetup=false;
77 77
 		$this->logging->log('Loggin started', INFO);
78 78
 
79 79
 		// Get options from ini files
@@ -86,7 +86,10 @@  discard block
 block discarded – undo
86 86
 		$this->setupDatabase($trapConfig); // Setup database class
87 87
 		
88 88
 		$this->getDatabaseOptions(); // Get options in database
89
-		if ($this->api_use === true) $this->getAPI(); // Setup API
89
+		if ($this->api_use === true) {
90
+			$this->getAPI();
91
+		}
92
+		// Setup API
90 93
 		
91 94
 		$this->trap_data=array(
92 95
 			'source_ip'	=> 'unknown',
@@ -118,8 +121,7 @@  discard block
 block discarded – undo
118 121
 	        }
119 122
 	        $this->logging->log($message,$log_level,'syslog');
120 123
 	        return false;
121
-	    }
122
-	    else
124
+	    } else
123 125
 	    {
124 126
 	        $option_var=$option_array[$option_category][$option_name];
125 127
 	        return true;
@@ -185,7 +187,10 @@  discard block
 block discarded – undo
185 187
 	    
186 188
         $this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName]);
187 189
 	    
188
-	    if ($this->api_use === true) return; // In case of API use, no IDO is necessary
190
+	    if ($this->api_use === true) {
191
+	    	return;
192
+	    }
193
+	    // In case of API use, no IDO is necessary
189 194
         
190 195
 	    // IDO Database
191 196
 	    if (!array_key_exists('IDOdatabase',$trapConfig['config']))
@@ -210,9 +215,11 @@  discard block
 block discarded – undo
210 215
 	protected function getDatabaseOptions()
211 216
 	{
212 217
 		// Database options
213
-		if ($this->logSetup == false) // Only if logging was no setup in constructor
218
+		if ($this->logSetup == false) {
219
+			// Only if logging was no setup in constructor
214 220
 		{
215 221
     		$this->getDBConfigIfSet('log_level',$this->logging->debugLevel);
222
+		}
216 223
     		$this->getDBConfigIfSet('log_destination',$this->logging->outputMode);
217 224
     		$this->getDBConfigIfSet('log_file',$this->logging->outputFile);
218 225
 		}
@@ -221,7 +228,9 @@  discard block
 block discarded – undo
221 228
 	protected function getDBConfigIfSet($element,&$variable)
222 229
 	{
223 230
 		$value=$this->getDBConfig($element);
224
-		if ($value != 'null') $variable=$value;
231
+		if ($value != 'null') {
232
+			$variable=$value;
233
+		}
225 234
 	}
226 235
 	
227 236
 	/** 
@@ -309,8 +318,7 @@  discard block
 block discarded – undo
309 318
 		{
310 319
 		    $this->writeTrapErrorToDB("Error parsing trap (code 2/IP)");
311 320
 			$this->logging->log('Error parsing IP : '.$IP,ERROR,'');
312
-		} 
313
-		else 
321
+		} else 
314 322
 		{		
315 323
 			$this->trap_data['source_ip']=$matches[1];
316 324
 			$this->trap_data['destination_ip']=$matches[3];
@@ -325,14 +333,12 @@  discard block
 block discarded – undo
325 333
 			if ($ret_code===0 || $ret_code===false) 
326 334
 			{
327 335
 				$this->logging->log('No match on trap data : '.$vars,WARN,'');
328
-			}
329
-			else 
336
+			} else 
330 337
 			{
331 338
 			    if (($matches[1]=='.1.3.6.1.6.3.1.1.4.1.0') || ($matches[1]=='.1.3.6.1.6.3.1.1.4.1'))
332 339
 				{
333 340
 					$this->trap_data['trap_oid']=$matches[2];				
334
-				}
335
-				else
341
+				} else
336 342
 				{
337 343
 					$object= new stdClass;
338 344
 					$object->oid =$matches[1];
@@ -503,7 +509,9 @@  discard block
 block discarded – undo
503 509
 	            }
504 510
 	            
505 511
 	            $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
506
-	            if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
512
+	            if ($inserted_id==false) {
513
+	            	throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
514
+	            }
507 515
 	            $this->trap_id=$inserted_id;
508 516
 	            break;
509 517
 	        default:
@@ -519,7 +527,9 @@  discard block
 block discarded – undo
519 527
 	{
520 528
 		
521 529
 		// If action is ignore -> don't send t DB
522
-		if ($this->trap_to_db === false) return;
530
+		if ($this->trap_to_db === false) {
531
+			return;
532
+		}
523 533
 		
524 534
 		
525 535
 		$db_conn=$this->trapsDB->db_connect_trap();
@@ -576,7 +586,9 @@  discard block
 block discarded – undo
576 586
 				}
577 587
 
578 588
 				$inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
579
-				if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
589
+				if ($inserted_id==false) {
590
+					throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
591
+				}
580 592
 				$this->trap_id=$inserted_id;
581 593
 			break;
582 594
 			default: 
@@ -705,8 +717,7 @@  discard block
 block discarded – undo
705 717
     		// TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default....
706 718
     		exec('echo "'.$send.'" > ' .$this->icinga2cmd);
707 719
     		return true;
708
-	    }
709
-	    else
720
+	    } else
710 721
 	    {
711 722
 	        $api = $this->getAPI();
712 723
 	        $api->setCredentials($this->api_username, $this->api_password);
@@ -715,8 +726,7 @@  discard block
 block discarded – undo
715 726
 	        {
716 727
 	            $this->logging->log( "Error sending result : " .$retmessage,WARN,'');
717 728
 	            return false;
718
-	        }
719
-	        else 
729
+	        } else 
720 730
 	        {
721 731
 	            $this->logging->log( "Sent result : " .$retmessage,INFO );
722 732
 	            return true;
@@ -776,7 +786,9 @@  discard block
 block discarded – undo
776 786
 	/***************** Eval & tokenizer functions ****************/
777 787
 	protected function eval_getElement($rule,&$item)
778 788
 	{
779
-		while ($rule[$item]==' ') $item++;
789
+		while ($rule[$item]==' ') {
790
+			$item++;
791
+		}
780 792
 		if (preg_match('/[0-9\.]/',$rule[$item]))
781 793
 		{ // number
782 794
 	
@@ -803,14 +815,15 @@  discard block
 block discarded – undo
803 815
 			$start=$item;
804 816
 			$parenthesis_count=0; 
805 817
 			while (($item < strlen($rule)) // Not end of string AND
806
-			      && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded ()
818
+			      && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) {
819
+				// Closing ')' or embeded ()
807 820
 			{ 
808 821
 				if ($rule[$item] == '"' )
809 822
 				{ // pass through string
810 823
 					$item++;
824
+			}
811 825
 					$item=$this->eval_getNext($rule,$item,'"');
812
-				} 
813
-				else{
826
+				} else{
814 827
 				    if ($rule[$item] == '(')
815 828
 				    {
816 829
 				        $parenthesis_count++;
@@ -838,13 +851,17 @@  discard block
 block discarded – undo
838 851
 	protected function eval_getNext($rule,$item,$tok)
839 852
 	{
840 853
 		while (($rule[$item] != $tok ) && ($item < strlen($rule))) { $item++;}
841
-		if ($item==strlen($rule)) throw new Exception("closing '".$tok."' not found in ".$rule ." at " .$item);
854
+		if ($item==strlen($rule)) {
855
+			throw new Exception("closing '".$tok."' not found in ".$rule ." at " .$item);
856
+		}
842 857
 		return $item+1;
843 858
 	}
844 859
 	
845 860
 	protected function eval_getOper($rule,&$item)
846 861
 	{
847
-		while ($rule[$item]==' ') $item++;
862
+		while ($rule[$item]==' ') {
863
+			$item++;
864
+		}
848 865
 		switch ($rule[$item])
849 866
 		{
850 867
 			case '<':
@@ -880,12 +897,13 @@  discard block
 block discarded – undo
880 897
 	public function evaluation($rule,&$item)
881 898
 	{
882 899
 	    //echo "Evaluation of ".substr($rule,$item)."\n";
883
-		if ( $rule[$item] == '!') // If '!' found, negate next expression.
900
+		if ( $rule[$item] == '!') {
901
+			// If '!' found, negate next expression.
884 902
 		{
885 903
 		    $negate=true;
886
-		    $item++;
887 904
 		}
888
-		else
905
+		    $item++;
906
+		} else
889 907
 		{
890 908
 		    $negate=false;
891 909
 		}
@@ -893,10 +911,14 @@  discard block
 block discarded – undo
893 911
 		list($type1,$val1) = $this->eval_getElement($rule,$item);
894 912
 		//echo "Elmt1: ".$val1."/".$type1." : ".substr($rule,$item)."\n";
895 913
 		
896
-		if ($item==strlen($rule)) // If only element, return value, but only boolean
914
+		if ($item==strlen($rule)) {
915
+			// If only element, return value, but only boolean
897 916
 		{
898 917
 		  if ($type1 != 2) throw new Exception("Cannot use num/string as boolean : ".$rule);
899
-		  if ($negate === true) $val1= ! $val1;
918
+		}
919
+		  if ($negate === true) {
920
+		  	$val1= ! $val1;
921
+		  }
900 922
 		  return $val1;
901 923
 		}  
902 924
 		
@@ -905,27 +927,34 @@  discard block
 block discarded – undo
905 927
 		//echo "Comp : ".$comp." : ".substr($rule,$item)."\n";
906 928
         
907 929
 		// Third element : number, string or ()
908
-		if ( $rule[$item] == '!') // starts with a ! so evaluate whats next
930
+		if ( $rule[$item] == '!') {
931
+			// starts with a ! so evaluate whats next
909 932
 		{
910 933
 		    $item++;
911
-		    if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule);
934
+		}
935
+		    if ($typec != 1) {
936
+		    	throw new Exception("Mixing boolean and comparison : ".$rule);
937
+		    }
912 938
 		    $val2= ! $this->evaluation($rule,$item);
913 939
 		    $type2=2; // result is a boolean 
914
-		}
915
-		else 
940
+		} else 
916 941
 		{
917 942
 		    list($type2,$val2) = $this->eval_getElement($rule,$item);
918 943
 		}
919 944
 		//echo "Elmt2: ".$val2."/".$type2." : ".substr($rule,$item)."\n";
920 945
 		
921
-		if ($type1!=$type2)  // cannot compare different types
946
+		if ($type1!=$type2) {
947
+			// cannot compare different types
922 948
 		{ 
923 949
 		    throw new Exception("Cannot compare string & number : ".$rule);
924 950
 		}
925
-		if ($typec==1 && $type1 !=2) // cannot use & or | with string/number
951
+		}
952
+		if ($typec==1 && $type1 !=2) {
953
+			// cannot use & or | with string/number
926 954
 		{
927 955
 		    throw new Exception("Cannot use boolean operators with string & number : ".$rule);
928 956
 		}
957
+		}
929 958
 		
930 959
 		switch ($comp){
931 960
 			case '<':	$retVal= ($val1 < $val2); break;
@@ -939,9 +968,15 @@  discard block
 block discarded – undo
939 968
 			case '&':	$retVal= ($val1 && $val2); break;
940 969
 			default:  throw new Exception("Error in expression - unknown comp : ".$comp);
941 970
 		}
942
-		if ($negate === true) $retVal = ! $retVal; // Inverse result if negate before expression
971
+		if ($negate === true) {
972
+			$retVal = ! $retVal;
973
+		}
974
+		// Inverse result if negate before expression
943 975
 		
944
-		if ($item==strlen($rule)) return $retVal; // End of string : return evaluation
976
+		if ($item==strlen($rule)) {
977
+			return $retVal;
978
+		}
979
+		// End of string : return evaluation
945 980
 		// check for logical operator :
946 981
 		switch ($rule[$item])
947 982
 		{
@@ -968,7 +1003,9 @@  discard block
 block discarded – undo
968 1003
 					$rule2.=$rule[$item];
969 1004
 					$item++;
970 1005
 				}
971
-				if ($item == strlen ($rule)) throw new Exception("closing '\"' not found in ".$rule ." at " .$item);
1006
+				if ($item == strlen ($rule)) {
1007
+					throw new Exception("closing '\"' not found in ".$rule ." at " .$item);
1008
+				}
972 1009
 				$rule2.=$rule[$item];
973 1010
 				$item++;
974 1011
 				continue;
@@ -988,10 +1025,12 @@  discard block
 block discarded – undo
988 1025
 	
989 1026
 	protected function eval_rule($rule)
990 1027
 	{
991
-		if ($rule==null || $rule == '') // Empty rule is always true
1028
+		if ($rule==null || $rule == '') {
1029
+			// Empty rule is always true
992 1030
 		{
993 1031
 			return true;
994 1032
 		}
1033
+		}
995 1034
 		$matches=array();
996 1035
 		while (preg_match('/_OID\(([0-9\.\*]+)\)/',$rule,$matches) == 1)
997 1036
 		{
@@ -1078,20 +1117,17 @@  discard block
 block discarded – undo
1078 1117
 						if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false)
1079 1118
 						{
1080 1119
 						    $this->trap_action.='Error sending status : check cmd/API';
1081
-						}
1082
-						else
1120
+						} else
1083 1121
 						{
1084 1122
 						    $this->add_rule_match($rule['id'],$rule['num_match']+1);
1085 1123
 						    $this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
1086 1124
 						}
1087
-					}
1088
-					else
1125
+					} else
1089 1126
 					{
1090 1127
 						$this->add_rule_match($rule['id'],$rule['num_match']+1);
1091 1128
 					}
1092 1129
 					$this->trap_to_db=($action==-2)?false:true;
1093
-				}
1094
-				else
1130
+				} else
1095 1131
 				{
1096 1132
 					//$this->logging->log('rules KOO : '.print_r($rule),INFO );
1097 1133
 					
@@ -1102,14 +1138,12 @@  discard block
 block discarded – undo
1102 1138
 					    if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false)
1103 1139
 					    {
1104 1140
 					        $this->trap_action.='Error sending status : check cmd/API';
1105
-					    }
1106
-					    else
1141
+					    } else
1107 1142
 					    {
1108 1143
     						$this->add_rule_match($rule['id'],$rule['num_match']+1);
1109 1144
     						$this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
1110 1145
 					    }
1111
-					}
1112
-					else
1146
+					} else
1113 1147
 					{
1114 1148
 						$this->add_rule_match($rule['id'],$rule['num_match']+1);
1115 1149
 					}
@@ -1119,16 +1153,14 @@  discard block
 block discarded – undo
1119 1153
 				if (!isset($this->trap_data['source_name']))
1120 1154
 				{
1121 1155
 					$this->trap_data['source_name']=$rule['host_name'];
1122
-				}
1123
-				else
1156
+				} else
1124 1157
 				{
1125 1158
 					if (!preg_match('/'.$rule['host_name'].'/',$this->trap_data['source_name']))
1126 1159
 					{ // only add if not present
1127 1160
 						$this->trap_data['source_name'].=','.$rule['host_name'];
1128 1161
 					}
1129 1162
 				}
1130
-			}
1131
-			catch (Exception $e) 
1163
+			} catch (Exception $e) 
1132 1164
 			{ 
1133 1165
 			    $this->logging->log('Error in rule eval : '.$e->getMessage(),WARN,'');
1134 1166
 			    $this->trap_action.=' ERR : '.$e->getMessage();
@@ -1139,8 +1171,7 @@  discard block
 block discarded – undo
1139 1171
 		if ($this->trap_data['status']=='error')
1140 1172
 		{
1141 1173
 		  $this->trap_to_db=true; // Always put errors in DB for the use can see
1142
-		}
1143
-		else
1174
+		} else
1144 1175
 		{
1145 1176
 		  $this->trap_data['status']='done';
1146 1177
 		}
@@ -1195,8 +1226,7 @@  discard block
 block discarded – undo
1195 1226
                 if (preg_match('/^ *CREATE TABLE ([^ ]+)/',$newline,$cur_table_array))
1196 1227
                 {
1197 1228
                     $cur_table='table '.$cur_table_array[1];
1198
-                }
1199
-                else
1229
+                } else
1200 1230
                 {
1201 1231
                     $cur_table='secret SQL stuff :-)';
1202 1232
                 }
@@ -1240,8 +1270,7 @@  discard block
 block discarded – undo
1240 1270
 	    if ($this->trapsDB->trapDBType == 'pgsql')
1241 1271
 	    {
1242 1272
 	        $prefix .= 'update_pgsql/schema_';
1243
-	    }
1244
-	    else
1273
+	    } else
1245 1274
 	    {
1246 1275
 	        $prefix .= 'update_sql/schema_';
1247 1276
 	    }
@@ -1287,7 +1316,10 @@  discard block
 block discarded – undo
1287 1316
 	       $db_conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
1288 1317
 	       while (($line=fgets($input_stream)) !== false)
1289 1318
 	       {
1290
-	           if (preg_match('/^#/', $line)) continue; // ignore comment lines
1319
+	           if (preg_match('/^#/', $line)) {
1320
+	           	continue;
1321
+	           }
1322
+	           // ignore comment lines
1291 1323
 	           $newline.=chop(preg_replace('/#PREFIX#/',$table_prefix,$line));
1292 1324
 	           if (preg_match('/; *$/', $newline))
1293 1325
 	           {
@@ -1299,8 +1331,7 @@  discard block
 block discarded – undo
1299 1331
 	               if (preg_match('/^ *([^ ]+) TABLE ([^ ]+)/',$newline,$cur_table_array))
1300 1332
 	               {
1301 1333
 	                   $cur_table=$cur_table_array[1] . ' SQL table '.$cur_table_array[2];
1302
-	               }
1303
-	               else
1334
+	               } else
1304 1335
 	               {
1305 1336
 	                   $cur_table='secret SQL stuff :-)';
1306 1337
 	                   //$cur_table=$newline;
@@ -1438,8 +1469,7 @@  discard block
 block discarded – undo
1438 1469
 			    }
1439 1470
 			    $this->logging->log('Trap updated : '.$name . ' / OID : '.$oid,DEBUG );
1440 1471
 				return 1;
1441
-			}
1442
-			else
1472
+			} else
1443 1473
 			{
1444 1474
 			    $this->logging->log('Trap unchanged : '.$name . ' / OID : '.$oid,DEBUG );
1445 1475
 			    return 0;
@@ -1455,7 +1485,9 @@  discard block
 block discarded – undo
1455 1485
               'values (:oid, :name , :type ,:mib ,:tc , :display_hint'.
1456 1486
               ', :syntax, :type_enum, :description )';
1457 1487
         
1458
-		if ($this->trapsDB->trapDBType == 'pgsql') $sql .= 'RETURNING id';
1488
+		if ($this->trapsDB->trapDBType == 'pgsql') {
1489
+			$sql .= 'RETURNING id';
1490
+		}
1459 1491
 		
1460 1492
 		$sqlQuery=$db_conn->prepare($sql);
1461 1493
 		
@@ -1495,7 +1527,9 @@  discard block
 block discarded – undo
1495 1527
 		        }
1496 1528
 		        
1497 1529
 		        $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
1498
-		        if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
1530
+		        if ($inserted_id==false) {
1531
+		        	throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
1532
+		        }
1499 1533
 		        $this->dbOidIndex[$oid]['id']=$inserted_id;
1500 1534
 		        break;
1501 1535
 		    default:
@@ -1748,12 +1782,14 @@  discard block
 block discarded – undo
1748 1782
 			$name=$match[1]; // Name 
1749 1783
 			$type=$match[2]; // type (21=trap, 0: may be trap, else : not trap
1750 1784
 			
1751
-			if ($type==0) // object type=0 : check if v1 trap
1785
+			if ($type==0) {
1786
+				// object type=0 : check if v1 trap
1752 1787
 			{
1753 1788
 				// Check if next is suboid -> in that case is cannot be a trap
1754 1789
 				if (preg_match("/^$oid/",$this->objectsAll[$curElement+1]))
1755 1790
 				{
1756 1791
 				    $time_check2 += microtime(true) - $time_1;
1792
+			}
1757 1793
 				    $time_check2N++;
1758 1794
 					continue;
1759 1795
 				}		
@@ -1770,9 +1806,11 @@  discard block
 block discarded – undo
1770 1806
 				// Force as trap.
1771 1807
 				$type=21;
1772 1808
 			}
1773
-			if ($onlyTraps===true && $type!=21) // if only traps and not a trap, continue
1809
+			if ($onlyTraps===true && $type!=21) {
1810
+				// if only traps and not a trap, continue
1774 1811
 			{
1775 1812
 			    $time_check3 += microtime(true) - $time_1;
1813
+			}
1776 1814
 				$time_check3N++;
1777 1815
 				continue;
1778 1816
 			}
@@ -1780,7 +1818,10 @@  discard block
 block discarded – undo
1780 1818
 			$time_num_traps++;
1781 1819
 			
1782 1820
 			$this->logging->log('Found trap : '.$match[1] . ' / OID : '.$oid,INFO );
1783
-			if ($display_progress) echo '#'; // echo a # when trap found
1821
+			if ($display_progress) {
1822
+				echo '#';
1823
+			}
1824
+			// echo a # when trap found
1784 1825
 				
1785 1826
 			// get trap objects & source MIB
1786 1827
 			unset($snmptrans);
@@ -1798,7 +1839,9 @@  discard block
 block discarded – undo
1798 1839
 			$trapMib=$match[1];
1799 1840
 			
1800 1841
 			$numLine=1;$trapDesc='';
1801
-			while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++;
1842
+			while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) {
1843
+				$numLine++;
1844
+			}
1802 1845
 			if (isset($snmptrans[$numLine]))
1803 1846
 			{
1804 1847
 			    $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]);
@@ -1820,7 +1863,9 @@  discard block
 block discarded – undo
1820 1863
 			if (($update==0) && ($check_change===false))
1821 1864
 			{ // Trapd didn't change & force check disabled
1822 1865
 			    $time_objects += microtime(true) - $time_1;
1823
-			    if ($display_progress) echo "C";
1866
+			    if ($display_progress) {
1867
+			    	echo "C";
1868
+			    }
1824 1869
 			    continue;
1825 1870
 			}
1826 1871
 			
Please login to merge, or discard this patch.