@@ -11,13 +11,12 @@ discard block |
||
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(); |
@@ -41,22 +40,22 @@ discard block |
||
41 | 40 | */ |
42 | 41 | public function testruleAction() |
43 | 42 | { |
44 | - $this->checkReadPermission(); |
|
45 | - $this->getTabs()->add('get',array( |
|
46 | - 'active' => true, |
|
47 | - 'label' => $this->translate('Test Rule'), |
|
48 | - 'url' => Url::fromRequest() |
|
49 | - )); |
|
43 | + $this->checkReadPermission(); |
|
44 | + $this->getTabs()->add('get',array( |
|
45 | + 'active' => true, |
|
46 | + 'label' => $this->translate('Test Rule'), |
|
47 | + 'url' => Url::fromRequest() |
|
48 | + )); |
|
50 | 49 | |
51 | 50 | |
52 | - if ($this->params->get('rule') !== null) |
|
53 | - { |
|
54 | - $this->view->rule= $this->params->get('rule'); |
|
55 | - } |
|
56 | - else |
|
57 | - { |
|
58 | - $this->view->rule=''; |
|
59 | - } |
|
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 | + } |
|
60 | 59 | } |
61 | 60 | |
62 | 61 | /** |
@@ -64,31 +63,31 @@ discard block |
||
64 | 63 | */ |
65 | 64 | private function add_setup_vars() |
66 | 65 | { |
67 | - // variables to send to view |
|
68 | - $this->view->hostlist=array(); // host list to input datalist |
|
69 | - $this->view->hostname=''; // Host name in input text |
|
70 | - $this->view->serviceGet=false; // Set to true to get list of service if only one host set |
|
71 | - $this->view->serviceSet=null; // Select service in services select (must have serviceGet=true). |
|
72 | - $this->view->mainoid=''; // Trap OID |
|
73 | - $this->view->mib=''; // Trap mib |
|
74 | - $this->view->name=''; // Trap name |
|
75 | - $this->view->trapListForMIB=array(); // Trap list if mib exists for trap |
|
76 | - $this->view->objectList=array(); // objects sent with trap |
|
77 | - $this->view->display=''; // Initial display |
|
78 | - $this->view->rule=''; // rule display |
|
79 | - $this->view->revertOK=''; // revert OK in seconds |
|
80 | - $this->view->hostid=-1; // normally set by javascript serviceGet() |
|
81 | - $this->view->ruleid=-1; // Rule id in DB for update & delete |
|
82 | - $this->view->setToUpdate=false; // set form as update form |
|
83 | - $this->view->setRuleMatch=-1; // set action on rule match (default nothing) |
|
84 | - $this->view->setRuleNoMatch=-1; // set action on rule no match (default nothing) |
|
66 | + // variables to send to view |
|
67 | + $this->view->hostlist=array(); // host list to input datalist |
|
68 | + $this->view->hostname=''; // Host name in input text |
|
69 | + $this->view->serviceGet=false; // Set to true to get list of service if only one host set |
|
70 | + $this->view->serviceSet=null; // Select service in services select (must have serviceGet=true). |
|
71 | + $this->view->mainoid=''; // Trap OID |
|
72 | + $this->view->mib=''; // Trap mib |
|
73 | + $this->view->name=''; // Trap name |
|
74 | + $this->view->trapListForMIB=array(); // Trap list if mib exists for trap |
|
75 | + $this->view->objectList=array(); // objects sent with trap |
|
76 | + $this->view->display=''; // Initial display |
|
77 | + $this->view->rule=''; // rule display |
|
78 | + $this->view->revertOK=''; // revert OK in seconds |
|
79 | + $this->view->hostid=-1; // normally set by javascript serviceGet() |
|
80 | + $this->view->ruleid=-1; // Rule id in DB for update & delete |
|
81 | + $this->view->setToUpdate=false; // set form as update form |
|
82 | + $this->view->setRuleMatch=-1; // set action on rule match (default nothing) |
|
83 | + $this->view->setRuleNoMatch=-1; // set action on rule no match (default nothing) |
|
85 | 84 | |
86 | - $this->view->selectGroup=false; // Select by group if true |
|
87 | - $this->view->hostgroupid=-1; // host group id |
|
88 | - $this->view->serviceGroupGet=false; // Get list of service for group (set serviceSet to select one) |
|
85 | + $this->view->selectGroup=false; // Select by group if true |
|
86 | + $this->view->hostgroupid=-1; // host group id |
|
87 | + $this->view->serviceGroupGet=false; // Get list of service for group (set serviceSet to select one) |
|
89 | 88 | |
90 | - $this->view->modifier=null; |
|
91 | - $this->view->modified=null; |
|
89 | + $this->view->modifier=null; |
|
90 | + $this->view->modified=null; |
|
92 | 91 | } |
93 | 92 | |
94 | 93 | /** |
@@ -97,102 +96,102 @@ discard block |
||
97 | 96 | */ |
98 | 97 | private function add_from_existing($trapid) |
99 | 98 | { |
100 | - /********** Setup from existing trap ***************/ |
|
101 | - // Get the full trap info |
|
102 | - $trapDetail=$this->getTrapDetail($trapid); |
|
99 | + /********** Setup from existing trap ***************/ |
|
100 | + // Get the full trap info |
|
101 | + $trapDetail=$this->getTrapDetail($trapid); |
|
103 | 102 | |
104 | - $hostfilter=$trapDetail->source_ip; |
|
103 | + $hostfilter=$trapDetail->source_ip; |
|
105 | 104 | |
106 | - // Get host |
|
107 | - try |
|
108 | - { |
|
109 | - $hosts=$this->getHostByIP($hostfilter); |
|
110 | - } |
|
111 | - catch (Exception $e) |
|
112 | - { |
|
113 | - $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage()); |
|
114 | - } |
|
105 | + // Get host |
|
106 | + try |
|
107 | + { |
|
108 | + $hosts=$this->getHostByIP($hostfilter); |
|
109 | + } |
|
110 | + catch (Exception $e) |
|
111 | + { |
|
112 | + $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage()); |
|
113 | + } |
|
115 | 114 | |
116 | 115 | |
117 | - // if one unique host found -> put id text input |
|
118 | - if (count($hosts)==1) { |
|
119 | - $this->view->hostname=$hosts[0]->name; |
|
120 | - //$hostid=$hosts[0]->id; |
|
121 | - // Tell JS to get services when page is loaded |
|
122 | - $this->view->serviceGet=true; |
|
116 | + // if one unique host found -> put id text input |
|
117 | + if (count($hosts)==1) { |
|
118 | + $this->view->hostname=$hosts[0]->name; |
|
119 | + //$hostid=$hosts[0]->id; |
|
120 | + // Tell JS to get services when page is loaded |
|
121 | + $this->view->serviceGet=true; |
|
123 | 122 | |
124 | - } |
|
125 | - else |
|
126 | - { |
|
127 | - foreach($hosts as $key=>$val) |
|
128 | - { |
|
129 | - array_push($this->view->hostlist,$hosts[$key]->name); |
|
130 | - } |
|
131 | - } |
|
123 | + } |
|
124 | + else |
|
125 | + { |
|
126 | + foreach($hosts as $key=>$val) |
|
127 | + { |
|
128 | + array_push($this->view->hostlist,$hosts[$key]->name); |
|
129 | + } |
|
130 | + } |
|
132 | 131 | |
133 | - // set up trap oid and objects received by the trap |
|
132 | + // set up trap oid and objects received by the trap |
|
134 | 133 | |
135 | - $this->view->mainoid=$trapDetail->trap_oid; |
|
136 | - if ($trapDetail->trap_name_mib != null) |
|
137 | - { |
|
138 | - $this->view->mib=$trapDetail->trap_name_mib; |
|
139 | - $this->view->name=$trapDetail->trap_name; |
|
140 | - $this->view->trapListForMIB=$this->getMIB() |
|
141 | - ->getTrapList($trapDetail->trap_name_mib); |
|
142 | - } |
|
134 | + $this->view->mainoid=$trapDetail->trap_oid; |
|
135 | + if ($trapDetail->trap_name_mib != null) |
|
136 | + { |
|
137 | + $this->view->mib=$trapDetail->trap_name_mib; |
|
138 | + $this->view->name=$trapDetail->trap_name; |
|
139 | + $this->view->trapListForMIB=$this->getMIB() |
|
140 | + ->getTrapList($trapDetail->trap_name_mib); |
|
141 | + } |
|
143 | 142 | |
144 | - // Get all objects that can be in trap from MIB |
|
145 | - $allObjects=$this->getMIB()->getObjectList($trapDetail->trap_oid); |
|
146 | - // Get all objects in current Trap |
|
147 | - $currentTrapObjects=$this->getTrapobjects($trapid); |
|
148 | - $oid_index=1; |
|
149 | - foreach ($currentTrapObjects as $key => $val) |
|
150 | - { |
|
151 | - $currentObjectType='Unknown'; |
|
152 | - $currentObjectTypeEnum='Unknown'; |
|
153 | - if (isset($allObjects[$val->oid]['type'])) |
|
154 | - { |
|
155 | - $currentObjectType=$allObjects[$val->oid]['type']; |
|
156 | - $currentObjectTypeEnum=$allObjects[$val->oid]['type_enum']; |
|
157 | - } |
|
158 | - $currentObject=array( |
|
159 | - $oid_index, |
|
160 | - $val->oid, |
|
161 | - $val->oid_name_mib, |
|
162 | - $val->oid_name, |
|
163 | - $val->value, |
|
164 | - $currentObjectType, |
|
165 | - $currentObjectTypeEnum |
|
166 | - ); |
|
167 | - $oid_index++; |
|
168 | - array_push($this->view->objectList,$currentObject); |
|
169 | - // set currrent object to null in allObjects |
|
170 | - if (isset($allObjects[$val->oid])) |
|
171 | - { |
|
172 | - $allObjects[$val->oid]=null; |
|
173 | - } |
|
174 | - } |
|
175 | - if ($allObjects!=null) // in case trap doesn't have objects or is not resolved |
|
176 | - { |
|
177 | - foreach ($allObjects as $key => $val) |
|
178 | - { |
|
179 | - if ($val==null) { continue; } |
|
180 | - array_push($this->view->objectList, array( |
|
181 | - $oid_index, |
|
182 | - $key, |
|
183 | - $allObjects[$key]['mib'], |
|
184 | - $allObjects[$key]['name'], |
|
185 | - '', |
|
186 | - $allObjects[$key]['type'], |
|
187 | - $allObjects[$key]['type_enum'] |
|
188 | - )); |
|
189 | - $oid_index++; |
|
190 | - } |
|
191 | - } |
|
143 | + // Get all objects that can be in trap from MIB |
|
144 | + $allObjects=$this->getMIB()->getObjectList($trapDetail->trap_oid); |
|
145 | + // Get all objects in current Trap |
|
146 | + $currentTrapObjects=$this->getTrapobjects($trapid); |
|
147 | + $oid_index=1; |
|
148 | + foreach ($currentTrapObjects as $key => $val) |
|
149 | + { |
|
150 | + $currentObjectType='Unknown'; |
|
151 | + $currentObjectTypeEnum='Unknown'; |
|
152 | + if (isset($allObjects[$val->oid]['type'])) |
|
153 | + { |
|
154 | + $currentObjectType=$allObjects[$val->oid]['type']; |
|
155 | + $currentObjectTypeEnum=$allObjects[$val->oid]['type_enum']; |
|
156 | + } |
|
157 | + $currentObject=array( |
|
158 | + $oid_index, |
|
159 | + $val->oid, |
|
160 | + $val->oid_name_mib, |
|
161 | + $val->oid_name, |
|
162 | + $val->value, |
|
163 | + $currentObjectType, |
|
164 | + $currentObjectTypeEnum |
|
165 | + ); |
|
166 | + $oid_index++; |
|
167 | + array_push($this->view->objectList,$currentObject); |
|
168 | + // set currrent object to null in allObjects |
|
169 | + if (isset($allObjects[$val->oid])) |
|
170 | + { |
|
171 | + $allObjects[$val->oid]=null; |
|
172 | + } |
|
173 | + } |
|
174 | + if ($allObjects!=null) // in case trap doesn't have objects or is not resolved |
|
175 | + { |
|
176 | + foreach ($allObjects as $key => $val) |
|
177 | + { |
|
178 | + if ($val==null) { continue; } |
|
179 | + array_push($this->view->objectList, array( |
|
180 | + $oid_index, |
|
181 | + $key, |
|
182 | + $allObjects[$key]['mib'], |
|
183 | + $allObjects[$key]['name'], |
|
184 | + '', |
|
185 | + $allObjects[$key]['type'], |
|
186 | + $allObjects[$key]['type_enum'] |
|
187 | + )); |
|
188 | + $oid_index++; |
|
189 | + } |
|
190 | + } |
|
192 | 191 | |
193 | - // Add a simple display |
|
194 | - $this->view->display='Trap '.$trapDetail->trap_name.' received'; |
|
195 | - $this->view->create_basic_rule=true; |
|
192 | + // Add a simple display |
|
193 | + $this->view->display='Trap '.$trapDetail->trap_name.' received'; |
|
194 | + $this->view->create_basic_rule=true; |
|
196 | 195 | } |
197 | 196 | |
198 | 197 | /** |
@@ -201,29 +200,29 @@ discard block |
||
201 | 200 | */ |
202 | 201 | private function add_check_host_exists($ruleDetail) |
203 | 202 | { |
204 | - // Check if hostname still exists |
|
205 | - $host_get=$this->getHostByName($this->view->hostname); |
|
203 | + // Check if hostname still exists |
|
204 | + $host_get=$this->getHostByName($this->view->hostname); |
|
206 | 205 | |
207 | - if (count($host_get)==0) |
|
208 | - { |
|
209 | - $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore'; |
|
210 | - $this->view->serviceGet=false; |
|
211 | - } |
|
212 | - else |
|
213 | - { |
|
214 | - // Tell JS to get services when page is loaded |
|
215 | - $this->view->serviceGet=true; |
|
216 | - // get service id for form to set : |
|
217 | - $serviceID=$this->getServiceIDByName($this->view->hostname,$ruleDetail->service_name); |
|
218 | - if (count($serviceID) ==0) |
|
219 | - { |
|
220 | - $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
221 | - } |
|
222 | - else |
|
223 | - { |
|
224 | - $this->view->serviceSet=$serviceID[0]->id; |
|
225 | - } |
|
226 | - } |
|
206 | + if (count($host_get)==0) |
|
207 | + { |
|
208 | + $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore'; |
|
209 | + $this->view->serviceGet=false; |
|
210 | + } |
|
211 | + else |
|
212 | + { |
|
213 | + // Tell JS to get services when page is loaded |
|
214 | + $this->view->serviceGet=true; |
|
215 | + // get service id for form to set : |
|
216 | + $serviceID=$this->getServiceIDByName($this->view->hostname,$ruleDetail->service_name); |
|
217 | + if (count($serviceID) ==0) |
|
218 | + { |
|
219 | + $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
220 | + } |
|
221 | + else |
|
222 | + { |
|
223 | + $this->view->serviceSet=$serviceID[0]->id; |
|
224 | + } |
|
225 | + } |
|
227 | 226 | } |
228 | 227 | |
229 | 228 | /** |
@@ -232,33 +231,33 @@ discard block |
||
232 | 231 | */ |
233 | 232 | private function add_check_hostgroup_exists($ruleDetail) |
234 | 233 | { |
235 | - // Check if groupe exists |
|
236 | - $group_get=$this->getHostGroupByName($this->view->hostgroupname); |
|
237 | - if (count($group_get)==0) |
|
238 | - { |
|
239 | - $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore'; |
|
240 | - $this->view->serviceGroupGet=false; |
|
241 | - } |
|
242 | - else |
|
243 | - { |
|
244 | - $grpServices=$this->getServicesByHostGroupid($group_get[0]->id); |
|
245 | - $foundGrpService=0; |
|
246 | - foreach ($grpServices as $grpService) |
|
247 | - { |
|
248 | - if ($grpService[0] == $ruleDetail->service_name) |
|
249 | - { |
|
250 | - $foundGrpService=1; |
|
251 | - $this->view->serviceSet=$ruleDetail->service_name; |
|
252 | - } |
|
253 | - } |
|
234 | + // Check if groupe exists |
|
235 | + $group_get=$this->getHostGroupByName($this->view->hostgroupname); |
|
236 | + if (count($group_get)==0) |
|
237 | + { |
|
238 | + $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore'; |
|
239 | + $this->view->serviceGroupGet=false; |
|
240 | + } |
|
241 | + else |
|
242 | + { |
|
243 | + $grpServices=$this->getServicesByHostGroupid($group_get[0]->id); |
|
244 | + $foundGrpService=0; |
|
245 | + foreach ($grpServices as $grpService) |
|
246 | + { |
|
247 | + if ($grpService[0] == $ruleDetail->service_name) |
|
248 | + { |
|
249 | + $foundGrpService=1; |
|
250 | + $this->view->serviceSet=$ruleDetail->service_name; |
|
251 | + } |
|
252 | + } |
|
254 | 253 | |
255 | - // Tell JS to get services when page is loaded |
|
256 | - $this->view->serviceGroupGet=true; |
|
257 | - if ($foundGrpService==0) |
|
258 | - { |
|
259 | - $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
260 | - } |
|
261 | - } |
|
254 | + // Tell JS to get services when page is loaded |
|
255 | + $this->view->serviceGroupGet=true; |
|
256 | + if ($foundGrpService==0) |
|
257 | + { |
|
258 | + $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
259 | + } |
|
260 | + } |
|
262 | 261 | } |
263 | 262 | |
264 | 263 | /** |
@@ -270,52 +269,52 @@ discard block |
||
270 | 269 | */ |
271 | 270 | private function add_create_trap_object_list(&$display, &$rule) |
272 | 271 | { |
273 | - $curObjectList=array(); |
|
274 | - $index=1; |
|
275 | - // check in display & rule for : OID(<oid>) |
|
276 | - $matches=array(); |
|
277 | - while ( preg_match('/_OID\(([\.0-9\*]+)\)/',$display,$matches) || |
|
278 | - preg_match('/_OID\(([\.0-9\*]+)\)/',$rule,$matches)) |
|
279 | - { |
|
280 | - $curOid=$matches[1]; |
|
272 | + $curObjectList=array(); |
|
273 | + $index=1; |
|
274 | + // check in display & rule for : OID(<oid>) |
|
275 | + $matches=array(); |
|
276 | + while ( preg_match('/_OID\(([\.0-9\*]+)\)/',$display,$matches) || |
|
277 | + preg_match('/_OID\(([\.0-9\*]+)\)/',$rule,$matches)) |
|
278 | + { |
|
279 | + $curOid=$matches[1]; |
|
281 | 280 | |
282 | - if ( (preg_match('/\*/',$curOid) == 0 ) |
|
283 | - && ($object=$this->getMIB()->translateOID($curOid)) != null) |
|
284 | - { |
|
285 | - array_push($curObjectList, array( |
|
286 | - $index, |
|
287 | - $curOid, |
|
288 | - $object['mib'], |
|
289 | - $object['name'], |
|
290 | - '', |
|
291 | - $object['type'], |
|
292 | - $object['type_enum'] |
|
293 | - )); |
|
294 | - } |
|
295 | - else |
|
296 | - { |
|
297 | - array_push($curObjectList, array( |
|
298 | - $index, |
|
299 | - $curOid, |
|
300 | - 'not found', |
|
301 | - 'not found', |
|
302 | - '', |
|
303 | - 'not found', |
|
304 | - 'not found' |
|
305 | - )); |
|
306 | - } |
|
307 | - $curOid = preg_replace('/\*/','\*',$curOid); |
|
308 | - $display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display); |
|
309 | - $rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule); |
|
310 | - $index++; |
|
311 | - } |
|
312 | - return $curObjectList; |
|
281 | + if ( (preg_match('/\*/',$curOid) == 0 ) |
|
282 | + && ($object=$this->getMIB()->translateOID($curOid)) != null) |
|
283 | + { |
|
284 | + array_push($curObjectList, array( |
|
285 | + $index, |
|
286 | + $curOid, |
|
287 | + $object['mib'], |
|
288 | + $object['name'], |
|
289 | + '', |
|
290 | + $object['type'], |
|
291 | + $object['type_enum'] |
|
292 | + )); |
|
293 | + } |
|
294 | + else |
|
295 | + { |
|
296 | + array_push($curObjectList, array( |
|
297 | + $index, |
|
298 | + $curOid, |
|
299 | + 'not found', |
|
300 | + 'not found', |
|
301 | + '', |
|
302 | + 'not found', |
|
303 | + 'not found' |
|
304 | + )); |
|
305 | + } |
|
306 | + $curOid = preg_replace('/\*/','\*',$curOid); |
|
307 | + $display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display); |
|
308 | + $rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule); |
|
309 | + $index++; |
|
310 | + } |
|
311 | + return $curObjectList; |
|
313 | 312 | } |
314 | 313 | |
315 | 314 | /** Add a handler |
316 | - * Get params fromid : setup from existing trap (id of trap table) |
|
317 | - * Get param ruleid : edit from existing handler (id of rule table) |
|
318 | - */ |
|
315 | + * Get params fromid : setup from existing trap (id of trap table) |
|
316 | + * Get param ruleid : edit from existing handler (id of rule table) |
|
317 | + */ |
|
319 | 318 | public function addAction() |
320 | 319 | { |
321 | 320 | $this->checkConfigPermission(); |
@@ -334,8 +333,8 @@ discard block |
||
334 | 333 | //$this->view->trapvalues=false; // Set to true to display 'value' colum in objects |
335 | 334 | |
336 | 335 | if (($trapid = $this->params->get('fromid')) !== null) { |
337 | - /********** Setup from existing trap ***************/ |
|
338 | - $this->add_from_existing($trapid); |
|
336 | + /********** Setup from existing trap ***************/ |
|
337 | + $this->add_from_existing($trapid); |
|
339 | 338 | return; |
340 | 339 | } |
341 | 340 | |
@@ -360,14 +359,14 @@ discard block |
||
360 | 359 | $this->view->warning_message=''; |
361 | 360 | if ($this->view->hostname != null) |
362 | 361 | { |
363 | - $this->view->selectGroup=false; |
|
364 | - // Check if hostname still exists |
|
365 | - $this->add_check_host_exists($ruleDetail); |
|
362 | + $this->view->selectGroup=false; |
|
363 | + // Check if hostname still exists |
|
364 | + $this->add_check_host_exists($ruleDetail); |
|
366 | 365 | } |
367 | 366 | else |
368 | 367 | { |
369 | - $this->view->selectGroup=true; |
|
370 | - $this->add_check_hostgroup_exists($ruleDetail); // Check if groupe exists |
|
368 | + $this->view->selectGroup=true; |
|
369 | + $this->add_check_hostgroup_exists($ruleDetail); // Check if groupe exists |
|
371 | 370 | } |
372 | 371 | |
373 | 372 | $this->view->mainoid=$ruleDetail->trap_oid; |
@@ -395,9 +394,9 @@ discard block |
||
395 | 394 | } |
396 | 395 | |
397 | 396 | /** Validate form and output message to user |
398 | - * @param in postdata |
|
399 | - * @return string status : OK / <Message> |
|
400 | - **/ |
|
397 | + * @param in postdata |
|
398 | + * @return string status : OK / <Message> |
|
399 | + **/ |
|
401 | 400 | protected function handlerformAction() |
402 | 401 | { |
403 | 402 | $postData=$this->getRequest()->getPost(); |
@@ -438,7 +437,7 @@ discard block |
||
438 | 437 | //$this->Module()-> |
439 | 438 | $this->_helper->json(array( |
440 | 439 | 'status'=>'OK', |
441 | - 'redirect'=>'trapdirector/handler' |
|
440 | + 'redirect'=>'trapdirector/handler' |
|
442 | 441 | |
443 | 442 | )); |
444 | 443 | } |
@@ -522,9 +521,9 @@ discard block |
||
522 | 521 | } |
523 | 522 | |
524 | 523 | /** Get trap detail by trapid. |
525 | - * @param integer $trapid : id of trap in received table |
|
526 | - * @return array (objects) |
|
527 | - */ |
|
524 | + * @param integer $trapid : id of trap in received table |
|
525 | + * @return array (objects) |
|
526 | + */ |
|
528 | 527 | protected function getTrapDetail($trapid) |
529 | 528 | { |
530 | 529 | if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id'); } |
@@ -540,14 +539,14 @@ discard block |
||
540 | 539 | } |
541 | 540 | try |
542 | 541 | { |
543 | - $query = $dbConn->select() |
|
542 | + $query = $dbConn->select() |
|
544 | 543 | ->from($this->getModuleConfig()->getTrapTableName(),$elmts) |
545 | 544 | ->where('id=?',$trapid); |
546 | 545 | $trapDetail=$dbConn->fetchRow($query); |
547 | 546 | if ( $trapDetail == null ) |
548 | 547 | { |
549 | - $trapDetail = 'NULL'; |
|
550 | - throw new Exception('No traps was found with id = '.$trapid); |
|
548 | + $trapDetail = 'NULL'; |
|
549 | + throw new Exception('No traps was found with id = '.$trapid); |
|
551 | 550 | } |
552 | 551 | } |
553 | 552 | catch (Exception $e) |
@@ -561,9 +560,9 @@ discard block |
||
561 | 560 | } |
562 | 561 | |
563 | 562 | /** Get trap objects |
564 | - * @param integer $trapid : trap id |
|
565 | - * @return array : full column in db of trap id |
|
566 | - */ |
|
563 | + * @param integer $trapid : trap id |
|
564 | + * @return array : full column in db of trap id |
|
565 | + */ |
|
567 | 566 | protected function getTrapobjects($trapid) |
568 | 567 | { |
569 | 568 | if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id'); } |
@@ -579,7 +578,7 @@ discard block |
||
579 | 578 | } |
580 | 579 | try |
581 | 580 | { |
582 | - $query = $dbConn->select() |
|
581 | + $query = $dbConn->select() |
|
583 | 582 | ->from($this->moduleConfig->getTrapDataTableName(),$data_elmts) |
584 | 583 | ->where('trap_id=?',$trapid); |
585 | 584 | $trapDetail=$dbConn->fetchAll($query); |
@@ -595,10 +594,10 @@ discard block |
||
595 | 594 | } |
596 | 595 | |
597 | 596 | /** Get rule detail by ruleid. |
598 | - * @param integer $ruleid int id of rule in rule table |
|
599 | - * @return object : column objects in db |
|
600 | - * |
|
601 | - */ |
|
597 | + * @param integer $ruleid int id of rule in rule table |
|
598 | + * @return object : column objects in db |
|
599 | + * |
|
600 | + */ |
|
602 | 601 | protected function getRuleDetail($ruleid) |
603 | 602 | { |
604 | 603 | if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id'); } |
@@ -609,7 +608,7 @@ discard block |
||
609 | 608 | // *************** Get main data |
610 | 609 | try |
611 | 610 | { |
612 | - $query = $dbConn->select() |
|
611 | + $query = $dbConn->select() |
|
613 | 612 | ->from($this->getModuleConfig()->getTrapRuleName(),$queryArray) |
614 | 613 | ->where('id=?',$ruleid); |
615 | 614 | $ruleDetail=$dbConn->fetchRow($query); |
@@ -626,7 +625,7 @@ discard block |
||
626 | 625 | } |
627 | 626 | |
628 | 627 | /** Setup tabs for rules |
629 | - */ |
|
628 | + */ |
|
630 | 629 | protected function prepareTabs() |
631 | 630 | { |
632 | 631 | return $this->getTabs()->add('status', array( |
@@ -23,16 +23,16 @@ discard block |
||
23 | 23 | $this->checkReadPermission(); |
24 | 24 | $this->prepareTabs()->activate('status'); |
25 | 25 | |
26 | - $dbConn = $this->getUIDatabase()->getDb(); |
|
26 | + $dbConn=$this->getUIDatabase()->getDb(); |
|
27 | 27 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
28 | 28 | |
29 | 29 | $this->getHandlerListTable()->setConnection($dbConn); |
30 | 30 | $this->getHandlerListTable()->setMibloader($this->getMIB()); |
31 | 31 | // Apply pagination limits |
32 | - $this->view->table=$this->applyPaginationLimits($this->getHandlerListTable(),$this->getModuleConfig()->itemListDisplay()); |
|
32 | + $this->view->table=$this->applyPaginationLimits($this->getHandlerListTable(), $this->getModuleConfig()->itemListDisplay()); |
|
33 | 33 | |
34 | 34 | // Set Filter |
35 | - $this->view->filterEditor = $this->getHandlerListTable()->getFilterEditor($this->getRequest()); |
|
35 | + $this->view->filterEditor=$this->getHandlerListTable()->getFilterEditor($this->getRequest()); |
|
36 | 36 | |
37 | 37 | //$this->displayExitError('Handler/indexAction','Not implemented'); |
38 | 38 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | public function testruleAction() |
43 | 43 | { |
44 | 44 | $this->checkReadPermission(); |
45 | - $this->getTabs()->add('get',array( |
|
45 | + $this->getTabs()->add('get', array( |
|
46 | 46 | 'active' => true, |
47 | 47 | 'label' => $this->translate('Test Rule'), |
48 | 48 | 'url' => Url::fromRequest() |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | |
52 | 52 | if ($this->params->get('rule') !== null) |
53 | 53 | { |
54 | - $this->view->rule= $this->params->get('rule'); |
|
54 | + $this->view->rule=$this->params->get('rule'); |
|
55 | 55 | } |
56 | 56 | else |
57 | 57 | { |
@@ -110,12 +110,12 @@ discard block |
||
110 | 110 | } |
111 | 111 | catch (Exception $e) |
112 | 112 | { |
113 | - $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage()); |
|
113 | + $this->displayExitError('Add handler : get host by IP/Name ', $e->getMessage()); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | |
117 | 117 | // if one unique host found -> put id text input |
118 | - if (count($hosts)==1) { |
|
118 | + if (count($hosts) == 1) { |
|
119 | 119 | $this->view->hostname=$hosts[0]->name; |
120 | 120 | //$hostid=$hosts[0]->id; |
121 | 121 | // Tell JS to get services when page is loaded |
@@ -124,9 +124,9 @@ discard block |
||
124 | 124 | } |
125 | 125 | else |
126 | 126 | { |
127 | - foreach($hosts as $key=>$val) |
|
127 | + foreach ($hosts as $key=>$val) |
|
128 | 128 | { |
129 | - array_push($this->view->hostlist,$hosts[$key]->name); |
|
129 | + array_push($this->view->hostlist, $hosts[$key]->name); |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
@@ -165,18 +165,18 @@ discard block |
||
165 | 165 | $currentObjectTypeEnum |
166 | 166 | ); |
167 | 167 | $oid_index++; |
168 | - array_push($this->view->objectList,$currentObject); |
|
168 | + array_push($this->view->objectList, $currentObject); |
|
169 | 169 | // set currrent object to null in allObjects |
170 | 170 | if (isset($allObjects[$val->oid])) |
171 | 171 | { |
172 | 172 | $allObjects[$val->oid]=null; |
173 | 173 | } |
174 | 174 | } |
175 | - if ($allObjects!=null) // in case trap doesn't have objects or is not resolved |
|
175 | + if ($allObjects != null) // in case trap doesn't have objects or is not resolved |
|
176 | 176 | { |
177 | 177 | foreach ($allObjects as $key => $val) |
178 | 178 | { |
179 | - if ($val==null) { continue; } |
|
179 | + if ($val == null) { continue; } |
|
180 | 180 | array_push($this->view->objectList, array( |
181 | 181 | $oid_index, |
182 | 182 | $key, |
@@ -204,9 +204,9 @@ discard block |
||
204 | 204 | // Check if hostname still exists |
205 | 205 | $host_get=$this->getHostByName($this->view->hostname); |
206 | 206 | |
207 | - if (count($host_get)==0) |
|
207 | + if (count($host_get) == 0) |
|
208 | 208 | { |
209 | - $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore'; |
|
209 | + $this->view->warning_message='Host '.$this->view->hostname.' doesn\'t exists anymore'; |
|
210 | 210 | $this->view->serviceGet=false; |
211 | 211 | } |
212 | 212 | else |
@@ -214,10 +214,10 @@ discard block |
||
214 | 214 | // Tell JS to get services when page is loaded |
215 | 215 | $this->view->serviceGet=true; |
216 | 216 | // get service id for form to set : |
217 | - $serviceID=$this->getServiceIDByName($this->view->hostname,$ruleDetail->service_name); |
|
218 | - if (count($serviceID) ==0) |
|
217 | + $serviceID=$this->getServiceIDByName($this->view->hostname, $ruleDetail->service_name); |
|
218 | + if (count($serviceID) == 0) |
|
219 | 219 | { |
220 | - $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
220 | + $this->view->warning_message=' Service '.$ruleDetail->service_name.' doesn\'t exists anymore'; |
|
221 | 221 | } |
222 | 222 | else |
223 | 223 | { |
@@ -234,9 +234,9 @@ discard block |
||
234 | 234 | { |
235 | 235 | // Check if groupe exists |
236 | 236 | $group_get=$this->getHostGroupByName($this->view->hostgroupname); |
237 | - if (count($group_get)==0) |
|
237 | + if (count($group_get) == 0) |
|
238 | 238 | { |
239 | - $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore'; |
|
239 | + $this->view->warning_message='HostGroup '.$this->view->hostgroupname.' doesn\'t exists anymore'; |
|
240 | 240 | $this->view->serviceGroupGet=false; |
241 | 241 | } |
242 | 242 | else |
@@ -254,9 +254,9 @@ discard block |
||
254 | 254 | |
255 | 255 | // Tell JS to get services when page is loaded |
256 | 256 | $this->view->serviceGroupGet=true; |
257 | - if ($foundGrpService==0) |
|
257 | + if ($foundGrpService == 0) |
|
258 | 258 | { |
259 | - $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
259 | + $this->view->warning_message.=' Service '.$ruleDetail->service_name.' doesn\'t exists anymore'; |
|
260 | 260 | } |
261 | 261 | } |
262 | 262 | } |
@@ -274,12 +274,12 @@ discard block |
||
274 | 274 | $index=1; |
275 | 275 | // check in display & rule for : OID(<oid>) |
276 | 276 | $matches=array(); |
277 | - while ( preg_match('/_OID\(([\.0-9\*]+)\)/',$display,$matches) || |
|
278 | - preg_match('/_OID\(([\.0-9\*]+)\)/',$rule,$matches)) |
|
277 | + while (preg_match('/_OID\(([\.0-9\*]+)\)/', $display, $matches) || |
|
278 | + preg_match('/_OID\(([\.0-9\*]+)\)/', $rule, $matches)) |
|
279 | 279 | { |
280 | 280 | $curOid=$matches[1]; |
281 | 281 | |
282 | - if ( (preg_match('/\*/',$curOid) == 0 ) |
|
282 | + if ((preg_match('/\*/', $curOid) == 0) |
|
283 | 283 | && ($object=$this->getMIB()->translateOID($curOid)) != null) |
284 | 284 | { |
285 | 285 | array_push($curObjectList, array( |
@@ -304,9 +304,9 @@ discard block |
||
304 | 304 | 'not found' |
305 | 305 | )); |
306 | 306 | } |
307 | - $curOid = preg_replace('/\*/','\*',$curOid); |
|
308 | - $display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display); |
|
309 | - $rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule); |
|
307 | + $curOid=preg_replace('/\*/', '\*', $curOid); |
|
308 | + $display=preg_replace('/_OID\('.$curOid.'\)/', '\$'.$index.'\$', $display); |
|
309 | + $rule=preg_replace('/_OID\('.$curOid.'\)/', '\$'.$index.'\$', $rule); |
|
310 | 310 | $index++; |
311 | 311 | } |
312 | 312 | return $curObjectList; |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | { |
321 | 321 | $this->checkConfigPermission(); |
322 | 322 | // set up tab |
323 | - $this->getTabs()->add('get',array( |
|
323 | + $this->getTabs()->add('get', array( |
|
324 | 324 | 'active' => true, |
325 | 325 | 'label' => $this->translate('Add handler'), |
326 | 326 | 'url' => Url::fromRequest() |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | |
334 | 334 | //$this->view->trapvalues=false; // Set to true to display 'value' colum in objects |
335 | 335 | |
336 | - if (($trapid = $this->params->get('fromid')) !== null) { |
|
336 | + if (($trapid=$this->params->get('fromid')) !== null) { |
|
337 | 337 | /********** Setup from existing trap ***************/ |
338 | 338 | $this->add_from_existing($trapid); |
339 | 339 | return; |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | $this->view->setRuleMatch=$ruleDetail->action_match; |
354 | 354 | $this->view->setRuleNoMatch=$ruleDetail->action_nomatch; |
355 | 355 | $this->view->hostgroupname=$ruleDetail->host_group_name; |
356 | - $this->view->modified=gmdate("Y-m-d\TH:i:s\Z",$ruleDetail->modified); |
|
356 | + $this->view->modified=gmdate("Y-m-d\TH:i:s\Z", $ruleDetail->modified); |
|
357 | 357 | $this->view->modifier=$ruleDetail->modifier; |
358 | 358 | |
359 | 359 | // Warning message if host/service don't exists anymore |
@@ -405,26 +405,26 @@ discard block |
||
405 | 405 | |
406 | 406 | $params=array( |
407 | 407 | // id (also db) => array('post' => post id, 'val' => default val, 'db' => send to table) |
408 | - 'hostgroup' => array('post' => 'hostgroup','db'=>false), |
|
409 | - 'db_rule' => array('post' => 'db_rule','db'=>false), |
|
410 | - 'hostid' => array('post' => 'hostid','db'=>false), |
|
411 | - 'host_name' => array('post' => 'hostname','val' => null,'db'=>true), |
|
412 | - 'host_group_name'=> array('post' => null,'val' => null,'db'=>true), |
|
413 | - 'serviceid' => array('post' => 'serviceid','db'=>false), |
|
414 | - 'service_name' => array('post' => 'serviceName','db'=>true), |
|
415 | - 'trap_oid' => array('post' => 'oid','db'=>true), |
|
416 | - 'revert_ok' => array('post' => 'revertOK','val' => 0,'db'=>true), |
|
417 | - 'display' => array('post' => 'display','val' => '','db'=>true), |
|
418 | - 'rule' => array('post' => 'rule','val' => '','db'=>true), |
|
419 | - 'action_match' => array('post' => 'ruleMatch','val' => -1,'db'=>true), |
|
420 | - 'action_nomatch'=> array('post' => 'ruleNoMatch','val' => -1,'db'=>true), |
|
421 | - 'ip4' => array('post' => null,'val' => null,'db'=>true), |
|
422 | - 'ip6' => array('post' => null,'val' => null,'db'=>true), |
|
423 | - 'action_form' => array('post' => 'action_form','db'=>false) |
|
408 | + 'hostgroup' => array('post' => 'hostgroup', 'db'=>false), |
|
409 | + 'db_rule' => array('post' => 'db_rule', 'db'=>false), |
|
410 | + 'hostid' => array('post' => 'hostid', 'db'=>false), |
|
411 | + 'host_name' => array('post' => 'hostname', 'val' => null, 'db'=>true), |
|
412 | + 'host_group_name'=> array('post' => null, 'val' => null, 'db'=>true), |
|
413 | + 'serviceid' => array('post' => 'serviceid', 'db'=>false), |
|
414 | + 'service_name' => array('post' => 'serviceName', 'db'=>true), |
|
415 | + 'trap_oid' => array('post' => 'oid', 'db'=>true), |
|
416 | + 'revert_ok' => array('post' => 'revertOK', 'val' => 0, 'db'=>true), |
|
417 | + 'display' => array('post' => 'display', 'val' => '', 'db'=>true), |
|
418 | + 'rule' => array('post' => 'rule', 'val' => '', 'db'=>true), |
|
419 | + 'action_match' => array('post' => 'ruleMatch', 'val' => -1, 'db'=>true), |
|
420 | + 'action_nomatch'=> array('post' => 'ruleNoMatch', 'val' => -1, 'db'=>true), |
|
421 | + 'ip4' => array('post' => null, 'val' => null, 'db'=>true), |
|
422 | + 'ip6' => array('post' => null, 'val' => null, 'db'=>true), |
|
423 | + 'action_form' => array('post' => 'action_form', 'db'=>false) |
|
424 | 424 | ); |
425 | 425 | |
426 | 426 | if (isset($postData[$params['action_form']['post']]) |
427 | - && $postData[$params['action_form']['post']] == 'delete' ) |
|
427 | + && $postData[$params['action_form']['post']] == 'delete') |
|
428 | 428 | { |
429 | 429 | try |
430 | 430 | { |
@@ -444,16 +444,16 @@ discard block |
||
444 | 444 | } |
445 | 445 | foreach (array_keys($params) as $key) |
446 | 446 | { |
447 | - if ($params[$key]['post']==null) continue; // data not sent in post vars |
|
448 | - if (! isset($postData[$params[$key]['post']])) |
|
447 | + if ($params[$key]['post'] == null) continue; // data not sent in post vars |
|
448 | + if (!isset($postData[$params[$key]['post']])) |
|
449 | 449 | { |
450 | 450 | // should not happen as the js checks data |
451 | - $this->_helper->json(array('status'=>'No ' . $key)); |
|
451 | + $this->_helper->json(array('status'=>'No '.$key)); |
|
452 | 452 | } |
453 | 453 | else |
454 | 454 | { |
455 | 455 | $data=$postData[$params[$key]['post']]; |
456 | - if ($data!=null && $data !="") |
|
456 | + if ($data != null && $data != "") |
|
457 | 457 | { |
458 | 458 | $params[$key]['val']=$postData[$params[$key]['post']]; |
459 | 459 | } |
@@ -462,8 +462,8 @@ discard block |
||
462 | 462 | |
463 | 463 | try |
464 | 464 | { |
465 | - $isHostGroup=($params['hostgroup']['val'] == 1)?true:false; |
|
466 | - if (! $isHostGroup ) |
|
465 | + $isHostGroup=($params['hostgroup']['val'] == 1) ?true:false; |
|
466 | + if (!$isHostGroup) |
|
467 | 467 | { // checks if selection by host |
468 | 468 | $hostAddr=$this->getHostInfoByID($params['hostid']['val']); |
469 | 469 | $params['ip4']['val']=$hostAddr->ip4; |
@@ -490,25 +490,25 @@ discard block |
||
490 | 490 | return; |
491 | 491 | } |
492 | 492 | // Put param in correct column (group_name) |
493 | - $params['host_group_name']['val'] = $params['host_name']['val']; |
|
493 | + $params['host_group_name']['val']=$params['host_name']['val']; |
|
494 | 494 | $params['host_name']['val']=null; |
495 | 495 | } |
496 | 496 | $dbparams=array(); |
497 | 497 | foreach ($params as $key=>$val) |
498 | 498 | { |
499 | - if ($val['db']==true ) |
|
499 | + if ($val['db'] == true) |
|
500 | 500 | { |
501 | - $dbparams[$key] = $val['val']; |
|
501 | + $dbparams[$key]=$val['val']; |
|
502 | 502 | } |
503 | 503 | } |
504 | 504 | // echo '<br>'; print_r($dbparams);echo '<br>'; |
505 | - if ($params['db_rule']['val'] == -1 ) |
|
505 | + if ($params['db_rule']['val'] == -1) |
|
506 | 506 | { |
507 | 507 | $ruleID=$this->addHandlerRule($dbparams); |
508 | 508 | } |
509 | 509 | else |
510 | 510 | { |
511 | - $this->updateHandlerRule($dbparams,$params['db_rule']['val']); |
|
511 | + $this->updateHandlerRule($dbparams, $params['db_rule']['val']); |
|
512 | 512 | $ruleID=$params['db_rule']['val']; |
513 | 513 | } |
514 | 514 | } |
@@ -527,10 +527,10 @@ discard block |
||
527 | 527 | */ |
528 | 528 | protected function getTrapDetail($trapid) |
529 | 529 | { |
530 | - if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id'); } |
|
530 | + if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); } |
|
531 | 531 | $queryArray=$this->getModuleConfig()->trapDetailQuery(); |
532 | 532 | |
533 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
533 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
534 | 534 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
535 | 535 | // *************** Get main data |
536 | 536 | // extract columns and titles; |
@@ -540,19 +540,19 @@ discard block |
||
540 | 540 | } |
541 | 541 | try |
542 | 542 | { |
543 | - $query = $dbConn->select() |
|
544 | - ->from($this->getModuleConfig()->getTrapTableName(),$elmts) |
|
545 | - ->where('id=?',$trapid); |
|
543 | + $query=$dbConn->select() |
|
544 | + ->from($this->getModuleConfig()->getTrapTableName(), $elmts) |
|
545 | + ->where('id=?', $trapid); |
|
546 | 546 | $trapDetail=$dbConn->fetchRow($query); |
547 | - if ( $trapDetail == null ) |
|
547 | + if ($trapDetail == null) |
|
548 | 548 | { |
549 | - $trapDetail = 'NULL'; |
|
549 | + $trapDetail='NULL'; |
|
550 | 550 | throw new Exception('No traps was found with id = '.$trapid); |
551 | 551 | } |
552 | 552 | } |
553 | 553 | catch (Exception $e) |
554 | 554 | { |
555 | - $this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage()); |
|
555 | + $this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail, true), $e->getMessage()); |
|
556 | 556 | return; |
557 | 557 | } |
558 | 558 | |
@@ -566,10 +566,10 @@ discard block |
||
566 | 566 | */ |
567 | 567 | protected function getTrapobjects($trapid) |
568 | 568 | { |
569 | - if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id'); } |
|
569 | + if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); } |
|
570 | 570 | $queryArrayData=$this->getModuleConfig()->trapDataDetailQuery(); |
571 | 571 | |
572 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
572 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
573 | 573 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
574 | 574 | // *************** Get object data |
575 | 575 | // extract columns and titles; |
@@ -579,15 +579,15 @@ discard block |
||
579 | 579 | } |
580 | 580 | try |
581 | 581 | { |
582 | - $query = $dbConn->select() |
|
583 | - ->from($this->moduleConfig->getTrapDataTableName(),$data_elmts) |
|
584 | - ->where('trap_id=?',$trapid); |
|
582 | + $query=$dbConn->select() |
|
583 | + ->from($this->moduleConfig->getTrapDataTableName(), $data_elmts) |
|
584 | + ->where('trap_id=?', $trapid); |
|
585 | 585 | $trapDetail=$dbConn->fetchAll($query); |
586 | 586 | // if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid); |
587 | 587 | } |
588 | 588 | catch (Exception $e) |
589 | 589 | { |
590 | - $this->displayExitError('Add handler : get trap data detail : ',$e->getMessage()); |
|
590 | + $this->displayExitError('Add handler : get trap data detail : ', $e->getMessage()); |
|
591 | 591 | return array(); |
592 | 592 | } |
593 | 593 | |
@@ -601,24 +601,24 @@ discard block |
||
601 | 601 | */ |
602 | 602 | protected function getRuleDetail($ruleid) |
603 | 603 | { |
604 | - if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id'); } |
|
604 | + if (!preg_match('/^[0-9]+$/', $ruleid)) { throw new Exception('Invalid id'); } |
|
605 | 605 | $queryArray=$this->getModuleConfig()->ruleDetailQuery(); |
606 | 606 | |
607 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
607 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
608 | 608 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
609 | 609 | // *************** Get main data |
610 | 610 | try |
611 | 611 | { |
612 | - $query = $dbConn->select() |
|
613 | - ->from($this->getModuleConfig()->getTrapRuleName(),$queryArray) |
|
614 | - ->where('id=?',$ruleid); |
|
612 | + $query=$dbConn->select() |
|
613 | + ->from($this->getModuleConfig()->getTrapRuleName(), $queryArray) |
|
614 | + ->where('id=?', $ruleid); |
|
615 | 615 | $ruleDetail=$dbConn->fetchRow($query); |
616 | - if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid); |
|
616 | + if ($ruleDetail == null) throw new Exception('No rule was found with id = '.$ruleid); |
|
617 | 617 | } |
618 | 618 | catch (Exception $e) |
619 | 619 | { |
620 | - $this->displayExitError('Update handler : get rule detail',$e->getMessage()); |
|
621 | - throw new Exception('Error : ',$e->getMessage()); |
|
620 | + $this->displayExitError('Update handler : get rule detail', $e->getMessage()); |
|
621 | + throw new Exception('Error : ', $e->getMessage()); |
|
622 | 622 | } |
623 | 623 | |
624 | 624 | return $ruleDetail; |
@@ -631,7 +631,7 @@ discard block |
||
631 | 631 | { |
632 | 632 | return $this->getTabs()->add('status', array( |
633 | 633 | 'label' => $this->translate('Traps'), |
634 | - 'url' => $this->getModuleConfig()->urlPath() . '/handler') |
|
634 | + 'url' => $this->getModuleConfig()->urlPath().'/handler') |
|
635 | 635 | ); |
636 | 636 | } |
637 | 637 |
@@ -24,7 +24,9 @@ discard block |
||
24 | 24 | $this->prepareTabs()->activate('status'); |
25 | 25 | |
26 | 26 | $dbConn = $this->getUIDatabase()->getDb(); |
27 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
27 | + if ($dbConn === null) { |
|
28 | + throw new \ErrorException('uncatched db error'); |
|
29 | + } |
|
28 | 30 | |
29 | 31 | $this->getHandlerListTable()->setConnection($dbConn); |
30 | 32 | $this->getHandlerListTable()->setMibloader($this->getMIB()); |
@@ -52,8 +54,7 @@ discard block |
||
52 | 54 | if ($this->params->get('rule') !== null) |
53 | 55 | { |
54 | 56 | $this->view->rule= $this->params->get('rule'); |
55 | - } |
|
56 | - else |
|
57 | + } else |
|
57 | 58 | { |
58 | 59 | $this->view->rule=''; |
59 | 60 | } |
@@ -107,8 +108,7 @@ discard block |
||
107 | 108 | try |
108 | 109 | { |
109 | 110 | $hosts=$this->getHostByIP($hostfilter); |
110 | - } |
|
111 | - catch (Exception $e) |
|
111 | + } catch (Exception $e) |
|
112 | 112 | { |
113 | 113 | $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage()); |
114 | 114 | } |
@@ -121,8 +121,7 @@ discard block |
||
121 | 121 | // Tell JS to get services when page is loaded |
122 | 122 | $this->view->serviceGet=true; |
123 | 123 | |
124 | - } |
|
125 | - else |
|
124 | + } else |
|
126 | 125 | { |
127 | 126 | foreach($hosts as $key=>$val) |
128 | 127 | { |
@@ -172,11 +171,14 @@ discard block |
||
172 | 171 | $allObjects[$val->oid]=null; |
173 | 172 | } |
174 | 173 | } |
175 | - if ($allObjects!=null) // in case trap doesn't have objects or is not resolved |
|
174 | + if ($allObjects!=null) { |
|
175 | + // in case trap doesn't have objects or is not resolved |
|
176 | 176 | { |
177 | 177 | foreach ($allObjects as $key => $val) |
178 | 178 | { |
179 | - if ($val==null) { continue; } |
|
179 | + if ($val==null) { continue; |
|
180 | + } |
|
181 | + } |
|
180 | 182 | array_push($this->view->objectList, array( |
181 | 183 | $oid_index, |
182 | 184 | $key, |
@@ -208,8 +210,7 @@ discard block |
||
208 | 210 | { |
209 | 211 | $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore'; |
210 | 212 | $this->view->serviceGet=false; |
211 | - } |
|
212 | - else |
|
213 | + } else |
|
213 | 214 | { |
214 | 215 | // Tell JS to get services when page is loaded |
215 | 216 | $this->view->serviceGet=true; |
@@ -218,8 +219,7 @@ discard block |
||
218 | 219 | if (count($serviceID) ==0) |
219 | 220 | { |
220 | 221 | $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
221 | - } |
|
222 | - else |
|
222 | + } else |
|
223 | 223 | { |
224 | 224 | $this->view->serviceSet=$serviceID[0]->id; |
225 | 225 | } |
@@ -238,8 +238,7 @@ discard block |
||
238 | 238 | { |
239 | 239 | $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore'; |
240 | 240 | $this->view->serviceGroupGet=false; |
241 | - } |
|
242 | - else |
|
241 | + } else |
|
243 | 242 | { |
244 | 243 | $grpServices=$this->getServicesByHostGroupid($group_get[0]->id); |
245 | 244 | $foundGrpService=0; |
@@ -291,8 +290,7 @@ discard block |
||
291 | 290 | $object['type'], |
292 | 291 | $object['type_enum'] |
293 | 292 | )); |
294 | - } |
|
295 | - else |
|
293 | + } else |
|
296 | 294 | { |
297 | 295 | array_push($curObjectList, array( |
298 | 296 | $index, |
@@ -363,8 +361,7 @@ discard block |
||
363 | 361 | $this->view->selectGroup=false; |
364 | 362 | // Check if hostname still exists |
365 | 363 | $this->add_check_host_exists($ruleDetail); |
366 | - } |
|
367 | - else |
|
364 | + } else |
|
368 | 365 | { |
369 | 366 | $this->view->selectGroup=true; |
370 | 367 | $this->add_check_hostgroup_exists($ruleDetail); // Check if groupe exists |
@@ -372,9 +369,11 @@ discard block |
||
372 | 369 | |
373 | 370 | $this->view->mainoid=$ruleDetail->trap_oid; |
374 | 371 | $oidName=$this->getMIB()->translateOID($ruleDetail->trap_oid); |
375 | - if ($oidName != null) // oid is found in mibs |
|
372 | + if ($oidName != null) { |
|
373 | + // oid is found in mibs |
|
376 | 374 | { |
377 | - $this->view->mib=$oidName['mib']; |
|
375 | + $this->view->mib=$oidName['mib']; |
|
376 | + } |
|
378 | 377 | $this->view->name=$oidName['name']; |
379 | 378 | $this->view->trapListForMIB=$this->getMIB() |
380 | 379 | ->getTrapList($oidName['mib']); |
@@ -429,8 +428,7 @@ discard block |
||
429 | 428 | try |
430 | 429 | { |
431 | 430 | $this->deleteRule($postData[$params['db_rule']['post']]); |
432 | - } |
|
433 | - catch (Exception $e) |
|
431 | + } catch (Exception $e) |
|
434 | 432 | { |
435 | 433 | $this->_helper->json(array('status'=>$e->getMessage())); |
436 | 434 | return; |
@@ -444,13 +442,15 @@ discard block |
||
444 | 442 | } |
445 | 443 | foreach (array_keys($params) as $key) |
446 | 444 | { |
447 | - if ($params[$key]['post']==null) continue; // data not sent in post vars |
|
445 | + if ($params[$key]['post']==null) { |
|
446 | + continue; |
|
447 | + } |
|
448 | + // data not sent in post vars |
|
448 | 449 | if (! isset($postData[$params[$key]['post']])) |
449 | 450 | { |
450 | 451 | // should not happen as the js checks data |
451 | 452 | $this->_helper->json(array('status'=>'No ' . $key)); |
452 | - } |
|
453 | - else |
|
453 | + } else |
|
454 | 454 | { |
455 | 455 | $data=$postData[$params[$key]['post']]; |
456 | 456 | if ($data!=null && $data !="") |
@@ -480,8 +480,7 @@ discard block |
||
480 | 480 | $this->_helper->json(array('status'=>"Invalid service id : Please re enter service")); |
481 | 481 | return; |
482 | 482 | } |
483 | - } |
|
484 | - else |
|
483 | + } else |
|
485 | 484 | { |
486 | 485 | $object=$this->getObjectNameByid($params['hostid']['val']); |
487 | 486 | if ($params['host_name']['val'] != $object->name1) |
@@ -505,14 +504,12 @@ discard block |
||
505 | 504 | if ($params['db_rule']['val'] == -1 ) |
506 | 505 | { |
507 | 506 | $ruleID=$this->addHandlerRule($dbparams); |
508 | - } |
|
509 | - else |
|
507 | + } else |
|
510 | 508 | { |
511 | 509 | $this->updateHandlerRule($dbparams,$params['db_rule']['val']); |
512 | 510 | $ruleID=$params['db_rule']['val']; |
513 | 511 | } |
514 | - } |
|
515 | - catch (Exception $e) |
|
512 | + } catch (Exception $e) |
|
516 | 513 | { |
517 | 514 | $this->_helper->json(array('status'=>$e->getMessage())); |
518 | 515 | return; |
@@ -531,7 +528,9 @@ discard block |
||
531 | 528 | $queryArray=$this->getModuleConfig()->trapDetailQuery(); |
532 | 529 | |
533 | 530 | $dbConn = $this->getUIDatabase()->getDbConn(); |
534 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
531 | + if ($dbConn === null) { |
|
532 | + throw new \ErrorException('uncatched db error'); |
|
533 | + } |
|
535 | 534 | // *************** Get main data |
536 | 535 | // extract columns and titles; |
537 | 536 | $elmts=NULL; |
@@ -549,8 +548,7 @@ discard block |
||
549 | 548 | $trapDetail = 'NULL'; |
550 | 549 | throw new Exception('No traps was found with id = '.$trapid); |
551 | 550 | } |
552 | - } |
|
553 | - catch (Exception $e) |
|
551 | + } catch (Exception $e) |
|
554 | 552 | { |
555 | 553 | $this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage()); |
556 | 554 | return; |
@@ -570,7 +568,9 @@ discard block |
||
570 | 568 | $queryArrayData=$this->getModuleConfig()->trapDataDetailQuery(); |
571 | 569 | |
572 | 570 | $dbConn = $this->getUIDatabase()->getDbConn(); |
573 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
571 | + if ($dbConn === null) { |
|
572 | + throw new \ErrorException('uncatched db error'); |
|
573 | + } |
|
574 | 574 | // *************** Get object data |
575 | 575 | // extract columns and titles; |
576 | 576 | $data_elmts=NULL; |
@@ -584,8 +584,7 @@ discard block |
||
584 | 584 | ->where('trap_id=?',$trapid); |
585 | 585 | $trapDetail=$dbConn->fetchAll($query); |
586 | 586 | // if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid); |
587 | - } |
|
588 | - catch (Exception $e) |
|
587 | + } catch (Exception $e) |
|
589 | 588 | { |
590 | 589 | $this->displayExitError('Add handler : get trap data detail : ',$e->getMessage()); |
591 | 590 | return array(); |
@@ -605,7 +604,9 @@ discard block |
||
605 | 604 | $queryArray=$this->getModuleConfig()->ruleDetailQuery(); |
606 | 605 | |
607 | 606 | $dbConn = $this->getUIDatabase()->getDbConn(); |
608 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
607 | + if ($dbConn === null) { |
|
608 | + throw new \ErrorException('uncatched db error'); |
|
609 | + } |
|
609 | 610 | // *************** Get main data |
610 | 611 | try |
611 | 612 | { |
@@ -613,9 +614,10 @@ discard block |
||
613 | 614 | ->from($this->getModuleConfig()->getTrapRuleName(),$queryArray) |
614 | 615 | ->where('id=?',$ruleid); |
615 | 616 | $ruleDetail=$dbConn->fetchRow($query); |
616 | - if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid); |
|
617 | - } |
|
618 | - catch (Exception $e) |
|
617 | + if ( $ruleDetail == null ) { |
|
618 | + throw new Exception('No rule was found with id = '.$ruleid); |
|
619 | + } |
|
620 | + } catch (Exception $e) |
|
619 | 621 | { |
620 | 622 | $this->displayExitError('Update handler : get rule detail',$e->getMessage()); |
621 | 623 | throw new Exception('Error : ',$e->getMessage()); |
@@ -19,30 +19,30 @@ discard block |
||
19 | 19 | */ |
20 | 20 | class DBException extends Exception |
21 | 21 | { |
22 | - /** @var array $returnArray */ |
|
23 | - private $returnArray; |
|
22 | + /** @var array $returnArray */ |
|
23 | + private $returnArray; |
|
24 | 24 | |
25 | - /** |
|
26 | - * Buil DBException |
|
27 | - * @param array $retarray |
|
28 | - * @param string $message |
|
29 | - * @param int $code |
|
30 | - * @param Exception $previous |
|
31 | - */ |
|
32 | - public function __construct(array $retarray, string $message = null, int $code = 0, Exception $previous = null) |
|
33 | - { |
|
34 | - parent::__construct($message,$code,$previous); |
|
35 | - $this->returnArray = $retarray; |
|
36 | - } |
|
25 | + /** |
|
26 | + * Buil DBException |
|
27 | + * @param array $retarray |
|
28 | + * @param string $message |
|
29 | + * @param int $code |
|
30 | + * @param Exception $previous |
|
31 | + */ |
|
32 | + public function __construct(array $retarray, string $message = null, int $code = 0, Exception $previous = null) |
|
33 | + { |
|
34 | + parent::__construct($message,$code,$previous); |
|
35 | + $this->returnArray = $retarray; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Get exception array |
|
40 | - * @return array |
|
41 | - */ |
|
42 | - public function getArray() |
|
43 | - { |
|
44 | - return $this->returnArray; |
|
45 | - } |
|
38 | + /** |
|
39 | + * Get exception array |
|
40 | + * @return array |
|
41 | + */ |
|
42 | + public function getArray() |
|
43 | + { |
|
44 | + return $this->returnArray; |
|
45 | + } |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -57,267 +57,267 @@ discard block |
||
57 | 57 | class UIDatabase |
58 | 58 | { |
59 | 59 | |
60 | - /** @var TrapsController $trapController TrapController 'parent' class */ |
|
61 | - protected $trapController=null; |
|
60 | + /** @var TrapsController $trapController TrapController 'parent' class */ |
|
61 | + protected $trapController=null; |
|
62 | 62 | |
63 | - /** @var Selectable $trapDB Trap Database*/ |
|
64 | - protected $trapDB=null; |
|
63 | + /** @var Selectable $trapDB Trap Database*/ |
|
64 | + protected $trapDB=null; |
|
65 | 65 | |
66 | - /** @var Selectable $trapDB Icinga IDO database*/ |
|
67 | - protected $idoDB=null; |
|
66 | + /** @var Selectable $trapDB Icinga IDO database*/ |
|
67 | + protected $idoDB=null; |
|
68 | 68 | |
69 | - /** @var array $testResult */ |
|
70 | - protected $testResult; |
|
69 | + /** @var array $testResult */ |
|
70 | + protected $testResult; |
|
71 | 71 | |
72 | - /** |
|
73 | - * |
|
74 | - * @param TrapsController $trapCtrl |
|
75 | - */ |
|
76 | - function __construct(TrapsController $trapCtrl) |
|
77 | - { |
|
78 | - $this->trapController=$trapCtrl; |
|
79 | - } |
|
72 | + /** |
|
73 | + * |
|
74 | + * @param TrapsController $trapCtrl |
|
75 | + */ |
|
76 | + function __construct(TrapsController $trapCtrl) |
|
77 | + { |
|
78 | + $this->trapController=$trapCtrl; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * Test if database version >= min database version |
|
83 | - * |
|
84 | - * @param \Zend_Db_Adapter_Abstract $dbConn |
|
85 | - * @param int $min Minimum version |
|
86 | - * @param bool $test Test mode |
|
87 | - * @param string $DBname Name of DB |
|
88 | - * @return bool true if OK, false if version < min version |
|
89 | - * @throws Exception if error and test = true |
|
90 | - */ |
|
91 | - protected function testDbVersion($dbAdapter,int $min,bool $test, string $DBname) |
|
92 | - { |
|
93 | - try |
|
94 | - { |
|
95 | - $query = $dbAdapter->select() |
|
96 | - ->from($this->trapController->getModuleConfig()->getDbConfigTableName(),'value') |
|
97 | - ->where('name=\'db_version\''); |
|
98 | - $version=$dbAdapter->fetchRow($query); |
|
99 | - if ( ($version == null) || ! property_exists($version,'value') ) |
|
100 | - { |
|
101 | - if ($test === true) |
|
102 | - { |
|
103 | - $this->testResult = array(4,$DBname); |
|
104 | - return false; |
|
105 | - } |
|
106 | - $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
|
107 | - return false; |
|
108 | - } |
|
109 | - if ($version->value < $min) |
|
110 | - { |
|
111 | - if ($test === true) |
|
112 | - { |
|
113 | - $this->testResult = array(5,$version->value,$min); |
|
114 | - return false; |
|
115 | - } |
|
116 | - $this->trapController->redirectNow('trapdirector/settings?dberror=5'); |
|
117 | - return false; |
|
118 | - } |
|
119 | - } |
|
120 | - catch (Exception $e) |
|
121 | - { |
|
122 | - if ($test === true) |
|
123 | - { |
|
124 | - $this->testResult = array(3,$DBname,$e->getMessage()); |
|
125 | - return false; |
|
126 | - } |
|
127 | - $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
|
128 | - return false; |
|
129 | - } |
|
130 | - return true; |
|
131 | - } |
|
81 | + /** |
|
82 | + * Test if database version >= min database version |
|
83 | + * |
|
84 | + * @param \Zend_Db_Adapter_Abstract $dbConn |
|
85 | + * @param int $min Minimum version |
|
86 | + * @param bool $test Test mode |
|
87 | + * @param string $DBname Name of DB |
|
88 | + * @return bool true if OK, false if version < min version |
|
89 | + * @throws Exception if error and test = true |
|
90 | + */ |
|
91 | + protected function testDbVersion($dbAdapter,int $min,bool $test, string $DBname) |
|
92 | + { |
|
93 | + try |
|
94 | + { |
|
95 | + $query = $dbAdapter->select() |
|
96 | + ->from($this->trapController->getModuleConfig()->getDbConfigTableName(),'value') |
|
97 | + ->where('name=\'db_version\''); |
|
98 | + $version=$dbAdapter->fetchRow($query); |
|
99 | + if ( ($version == null) || ! property_exists($version,'value') ) |
|
100 | + { |
|
101 | + if ($test === true) |
|
102 | + { |
|
103 | + $this->testResult = array(4,$DBname); |
|
104 | + return false; |
|
105 | + } |
|
106 | + $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
|
107 | + return false; |
|
108 | + } |
|
109 | + if ($version->value < $min) |
|
110 | + { |
|
111 | + if ($test === true) |
|
112 | + { |
|
113 | + $this->testResult = array(5,$version->value,$min); |
|
114 | + return false; |
|
115 | + } |
|
116 | + $this->trapController->redirectNow('trapdirector/settings?dberror=5'); |
|
117 | + return false; |
|
118 | + } |
|
119 | + } |
|
120 | + catch (Exception $e) |
|
121 | + { |
|
122 | + if ($test === true) |
|
123 | + { |
|
124 | + $this->testResult = array(3,$DBname,$e->getMessage()); |
|
125 | + return false; |
|
126 | + } |
|
127 | + $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
|
128 | + return false; |
|
129 | + } |
|
130 | + return true; |
|
131 | + } |
|
132 | 132 | |
133 | - /** Get Database connexion |
|
134 | - * @param $DBname string DB name in resource.ini_ge |
|
135 | - * @param $test bool if set to true, returns error code and not database |
|
136 | - * @param $test_version bool if set to flase, does not test database version of trapDB |
|
137 | - * @throws DBException if test = true and error |
|
138 | - * @return Selectable|null : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
|
139 | - */ |
|
140 | - protected function getDbByName($DBname , $test = false , $test_version = true) |
|
141 | - { |
|
142 | - try |
|
143 | - { |
|
144 | - $dbconn = IcingaDbConnection::fromResourceName($DBname); |
|
145 | - } |
|
146 | - catch (Exception $e) |
|
147 | - { |
|
148 | - if ($test === true) |
|
149 | - { |
|
150 | - throw new DBException(array(2,$DBname)); |
|
151 | - } |
|
152 | - $this->trapController->redirectNow('trapdirector/settings?dberror=2'); |
|
153 | - return null; |
|
154 | - } |
|
133 | + /** Get Database connexion |
|
134 | + * @param $DBname string DB name in resource.ini_ge |
|
135 | + * @param $test bool if set to true, returns error code and not database |
|
136 | + * @param $test_version bool if set to flase, does not test database version of trapDB |
|
137 | + * @throws DBException if test = true and error |
|
138 | + * @return Selectable|null : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
|
139 | + */ |
|
140 | + protected function getDbByName($DBname , $test = false , $test_version = true) |
|
141 | + { |
|
142 | + try |
|
143 | + { |
|
144 | + $dbconn = IcingaDbConnection::fromResourceName($DBname); |
|
145 | + } |
|
146 | + catch (Exception $e) |
|
147 | + { |
|
148 | + if ($test === true) |
|
149 | + { |
|
150 | + throw new DBException(array(2,$DBname)); |
|
151 | + } |
|
152 | + $this->trapController->redirectNow('trapdirector/settings?dberror=2'); |
|
153 | + return null; |
|
154 | + } |
|
155 | 155 | |
156 | - try |
|
157 | - { |
|
158 | - $dbAdapter=$dbconn->getDbAdapter(); |
|
156 | + try |
|
157 | + { |
|
158 | + $dbAdapter=$dbconn->getDbAdapter(); |
|
159 | 159 | |
160 | - } |
|
161 | - catch (Exception $e) |
|
162 | - { |
|
163 | - if ($test === true) |
|
164 | - { |
|
165 | - throw new DBException(array(3,$DBname,$e->getMessage())); |
|
166 | - } |
|
167 | - $this->trapController->redirectNow('trapdirector/settings?dberror=3'); |
|
168 | - return null; |
|
169 | - } |
|
160 | + } |
|
161 | + catch (Exception $e) |
|
162 | + { |
|
163 | + if ($test === true) |
|
164 | + { |
|
165 | + throw new DBException(array(3,$DBname,$e->getMessage())); |
|
166 | + } |
|
167 | + $this->trapController->redirectNow('trapdirector/settings?dberror=3'); |
|
168 | + return null; |
|
169 | + } |
|
170 | 170 | |
171 | - if ($test_version == true) { |
|
172 | - $testRet=$this->testDbVersion($dbAdapter, $this->trapController->getModuleConfig()->getDbMinVersion(), $test, $DBname); |
|
173 | - if ($testRet !== true) |
|
174 | - { |
|
175 | - throw new DBException($this->testResult); |
|
176 | - } |
|
177 | - } |
|
171 | + if ($test_version == true) { |
|
172 | + $testRet=$this->testDbVersion($dbAdapter, $this->trapController->getModuleConfig()->getDbMinVersion(), $test, $DBname); |
|
173 | + if ($testRet !== true) |
|
174 | + { |
|
175 | + throw new DBException($this->testResult); |
|
176 | + } |
|
177 | + } |
|
178 | 178 | |
179 | - return $dbconn; |
|
180 | - } |
|
179 | + return $dbconn; |
|
180 | + } |
|
181 | 181 | |
182 | - /** |
|
183 | - * Get Trap database |
|
184 | - * @return Selectable|null : returns DB connexion or null on error. |
|
185 | - */ |
|
186 | - public function getDb() |
|
187 | - { |
|
188 | - if ( $this->trapDB != null ) return $this->trapDB; |
|
182 | + /** |
|
183 | + * Get Trap database |
|
184 | + * @return Selectable|null : returns DB connexion or null on error. |
|
185 | + */ |
|
186 | + public function getDb() |
|
187 | + { |
|
188 | + if ( $this->trapDB != null ) return $this->trapDB; |
|
189 | 189 | |
190 | 190 | |
191 | - $dbresource=$this->trapController->Config()->get('config', 'database'); |
|
191 | + $dbresource=$this->trapController->Config()->get('config', 'database'); |
|
192 | 192 | |
193 | - if ( ! $dbresource ) |
|
194 | - { |
|
195 | - $this->trapController->redirectNow('trapdirector/settings?dberror=1'); |
|
196 | - return null; |
|
197 | - } |
|
193 | + if ( ! $dbresource ) |
|
194 | + { |
|
195 | + $this->trapController->redirectNow('trapdirector/settings?dberror=1'); |
|
196 | + return null; |
|
197 | + } |
|
198 | 198 | |
199 | - try { |
|
200 | - $this->trapDB = $this->getDbByName($dbresource,false,true); |
|
201 | - } catch (DBException $e) { |
|
202 | - return null; // Should not happen as test = false |
|
203 | - } |
|
199 | + try { |
|
200 | + $this->trapDB = $this->getDbByName($dbresource,false,true); |
|
201 | + } catch (DBException $e) { |
|
202 | + return null; // Should not happen as test = false |
|
203 | + } |
|
204 | 204 | |
205 | - //$this->trapDB->getConnection(); |
|
205 | + //$this->trapDB->getConnection(); |
|
206 | 206 | |
207 | - return $this->trapDB; |
|
208 | - } |
|
207 | + return $this->trapDB; |
|
208 | + } |
|
209 | 209 | |
210 | - /** |
|
211 | - * Get Zend adapter of DB. |
|
212 | - * @return \Zend_Db_Adapter_Abstract|null |
|
213 | - */ |
|
214 | - public function getDbConn() |
|
215 | - { |
|
216 | - if ($this->getDb() == null) return null; |
|
217 | - return $this->getDb()->getConnection(); |
|
218 | - } |
|
210 | + /** |
|
211 | + * Get Zend adapter of DB. |
|
212 | + * @return \Zend_Db_Adapter_Abstract|null |
|
213 | + */ |
|
214 | + public function getDbConn() |
|
215 | + { |
|
216 | + if ($this->getDb() == null) return null; |
|
217 | + return $this->getDb()->getConnection(); |
|
218 | + } |
|
219 | 219 | |
220 | - /** |
|
221 | - * Test Trap database |
|
222 | - * @param boolean $test |
|
223 | - * @throws DBException on error. |
|
224 | - * @return \Zend_Db_Adapter_Abstract|array|null : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
|
225 | - */ |
|
226 | - public function testGetDb() |
|
227 | - { |
|
228 | - $dbresource=$this->trapController->Config()->get('config', 'database'); |
|
220 | + /** |
|
221 | + * Test Trap database |
|
222 | + * @param boolean $test |
|
223 | + * @throws DBException on error. |
|
224 | + * @return \Zend_Db_Adapter_Abstract|array|null : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
|
225 | + */ |
|
226 | + public function testGetDb() |
|
227 | + { |
|
228 | + $dbresource=$this->trapController->Config()->get('config', 'database'); |
|
229 | 229 | |
230 | - if ( ! $dbresource ) |
|
231 | - { |
|
232 | - throw new DBException(array(1,'')); |
|
233 | - } |
|
230 | + if ( ! $dbresource ) |
|
231 | + { |
|
232 | + throw new DBException(array(1,'')); |
|
233 | + } |
|
234 | 234 | |
235 | - $this->trapDB = $this->getDbByName($dbresource,true,true); |
|
236 | - return; |
|
237 | - } |
|
235 | + $this->trapDB = $this->getDbByName($dbresource,true,true); |
|
236 | + return; |
|
237 | + } |
|
238 | 238 | |
239 | 239 | |
240 | - /** |
|
241 | - * Get IDO Database |
|
242 | - * @return \Zend_Db_Adapter_Abstract|NULL returns DB connexion or null on error. |
|
243 | - */ |
|
244 | - public function getIdoDb() |
|
245 | - { |
|
246 | - if ( $this->idoDB != null ) return $this->idoDB; |
|
247 | - // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
|
248 | - $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');; |
|
240 | + /** |
|
241 | + * Get IDO Database |
|
242 | + * @return \Zend_Db_Adapter_Abstract|NULL returns DB connexion or null on error. |
|
243 | + */ |
|
244 | + public function getIdoDb() |
|
245 | + { |
|
246 | + if ( $this->idoDB != null ) return $this->idoDB; |
|
247 | + // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
|
248 | + $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');; |
|
249 | 249 | |
250 | - if ( ! $dbresource ) |
|
251 | - { |
|
252 | - $this->trapController->redirectNow('trapdirector/settings?idodberror=1'); |
|
253 | - return null; |
|
254 | - } |
|
250 | + if ( ! $dbresource ) |
|
251 | + { |
|
252 | + $this->trapController->redirectNow('trapdirector/settings?idodberror=1'); |
|
253 | + return null; |
|
254 | + } |
|
255 | 255 | |
256 | - try |
|
257 | - { |
|
258 | - $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
259 | - } |
|
260 | - catch (Exception $e) |
|
261 | - { |
|
262 | - $this->trapController->redirectNow('trapdirector/settings?idodberror=2'); |
|
263 | - return null; |
|
264 | - } |
|
256 | + try |
|
257 | + { |
|
258 | + $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
259 | + } |
|
260 | + catch (Exception $e) |
|
261 | + { |
|
262 | + $this->trapController->redirectNow('trapdirector/settings?idodberror=2'); |
|
263 | + return null; |
|
264 | + } |
|
265 | 265 | |
266 | - $this->idoDB = $dbconn; |
|
267 | - return $this->idoDB; |
|
268 | - } |
|
266 | + $this->idoDB = $dbconn; |
|
267 | + return $this->idoDB; |
|
268 | + } |
|
269 | 269 | |
270 | 270 | |
271 | - /** |
|
272 | - * Get Zend adapter of DB. |
|
273 | - * @return \Zend_Db_Adapter_Abstract|null |
|
274 | - */ |
|
275 | - public function getIdoDbConn() |
|
276 | - { |
|
277 | - if ($this->getIdoDb() == null) return null; |
|
278 | - return $this->getIdoDb()->getConnection(); |
|
279 | - } |
|
271 | + /** |
|
272 | + * Get Zend adapter of DB. |
|
273 | + * @return \Zend_Db_Adapter_Abstract|null |
|
274 | + */ |
|
275 | + public function getIdoDbConn() |
|
276 | + { |
|
277 | + if ($this->getIdoDb() == null) return null; |
|
278 | + return $this->getIdoDb()->getConnection(); |
|
279 | + } |
|
280 | 280 | |
281 | - /** |
|
282 | - * Get IDO Database |
|
283 | - * @param boolean $test |
|
284 | - * @throws DBException on error |
|
285 | - */ |
|
286 | - public function testGetIdoDb() |
|
287 | - { |
|
288 | - // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
|
289 | - $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');; |
|
281 | + /** |
|
282 | + * Get IDO Database |
|
283 | + * @param boolean $test |
|
284 | + * @throws DBException on error |
|
285 | + */ |
|
286 | + public function testGetIdoDb() |
|
287 | + { |
|
288 | + // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
|
289 | + $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');; |
|
290 | 290 | |
291 | - if ( ! $dbresource ) |
|
292 | - { |
|
293 | - throw new DBException(array(1,'No database in config.ini')); |
|
294 | - } |
|
291 | + if ( ! $dbresource ) |
|
292 | + { |
|
293 | + throw new DBException(array(1,'No database in config.ini')); |
|
294 | + } |
|
295 | 295 | |
296 | - try |
|
297 | - { |
|
298 | - $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
299 | - } |
|
300 | - catch (Exception $e) |
|
301 | - { |
|
302 | - throw new DBException( array(2,"Database $dbresource does not exists in IcingaWeb2") ); |
|
303 | - } |
|
296 | + try |
|
297 | + { |
|
298 | + $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
299 | + } |
|
300 | + catch (Exception $e) |
|
301 | + { |
|
302 | + throw new DBException( array(2,"Database $dbresource does not exists in IcingaWeb2") ); |
|
303 | + } |
|
304 | 304 | |
305 | - try |
|
306 | - { |
|
307 | - $query = $dbconn->select() |
|
308 | - ->from('icinga_dbversion',array('version')); |
|
309 | - $version=$dbconn->fetchRow($query); |
|
310 | - if ( ($version == null) || ! property_exists($version,'version') ) |
|
311 | - { |
|
312 | - throw new DBException( array(4,"$dbresource does not look like an IDO database")); |
|
313 | - } |
|
314 | - } |
|
315 | - catch (Exception $e) |
|
316 | - { |
|
317 | - throw new DBException( array(3,"Error connecting to $dbresource : " . $e->getMessage())); |
|
318 | - } |
|
305 | + try |
|
306 | + { |
|
307 | + $query = $dbconn->select() |
|
308 | + ->from('icinga_dbversion',array('version')); |
|
309 | + $version=$dbconn->fetchRow($query); |
|
310 | + if ( ($version == null) || ! property_exists($version,'version') ) |
|
311 | + { |
|
312 | + throw new DBException( array(4,"$dbresource does not look like an IDO database")); |
|
313 | + } |
|
314 | + } |
|
315 | + catch (Exception $e) |
|
316 | + { |
|
317 | + throw new DBException( array(3,"Error connecting to $dbresource : " . $e->getMessage())); |
|
318 | + } |
|
319 | 319 | |
320 | - return; |
|
321 | - } |
|
320 | + return; |
|
321 | + } |
|
322 | 322 | |
323 | 323 | } |
324 | 324 | \ No newline at end of file |
@@ -29,10 +29,10 @@ discard block |
||
29 | 29 | * @param int $code |
30 | 30 | * @param Exception $previous |
31 | 31 | */ |
32 | - public function __construct(array $retarray, string $message = null, int $code = 0, Exception $previous = null) |
|
32 | + public function __construct(array $retarray, string $message=null, int $code=0, Exception $previous=null) |
|
33 | 33 | { |
34 | - parent::__construct($message,$code,$previous); |
|
35 | - $this->returnArray = $retarray; |
|
34 | + parent::__construct($message, $code, $previous); |
|
35 | + $this->returnArray=$retarray; |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
@@ -88,19 +88,19 @@ discard block |
||
88 | 88 | * @return bool true if OK, false if version < min version |
89 | 89 | * @throws Exception if error and test = true |
90 | 90 | */ |
91 | - protected function testDbVersion($dbAdapter,int $min,bool $test, string $DBname) |
|
91 | + protected function testDbVersion($dbAdapter, int $min, bool $test, string $DBname) |
|
92 | 92 | { |
93 | 93 | try |
94 | 94 | { |
95 | - $query = $dbAdapter->select() |
|
96 | - ->from($this->trapController->getModuleConfig()->getDbConfigTableName(),'value') |
|
95 | + $query=$dbAdapter->select() |
|
96 | + ->from($this->trapController->getModuleConfig()->getDbConfigTableName(), 'value') |
|
97 | 97 | ->where('name=\'db_version\''); |
98 | 98 | $version=$dbAdapter->fetchRow($query); |
99 | - if ( ($version == null) || ! property_exists($version,'value') ) |
|
99 | + if (($version == null) || !property_exists($version, 'value')) |
|
100 | 100 | { |
101 | 101 | if ($test === true) |
102 | 102 | { |
103 | - $this->testResult = array(4,$DBname); |
|
103 | + $this->testResult=array(4, $DBname); |
|
104 | 104 | return false; |
105 | 105 | } |
106 | 106 | $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | { |
111 | 111 | if ($test === true) |
112 | 112 | { |
113 | - $this->testResult = array(5,$version->value,$min); |
|
113 | + $this->testResult=array(5, $version->value, $min); |
|
114 | 114 | return false; |
115 | 115 | } |
116 | 116 | $this->trapController->redirectNow('trapdirector/settings?dberror=5'); |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | { |
122 | 122 | if ($test === true) |
123 | 123 | { |
124 | - $this->testResult = array(3,$DBname,$e->getMessage()); |
|
124 | + $this->testResult=array(3, $DBname, $e->getMessage()); |
|
125 | 125 | return false; |
126 | 126 | } |
127 | 127 | $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
@@ -137,17 +137,17 @@ discard block |
||
137 | 137 | * @throws DBException if test = true and error |
138 | 138 | * @return Selectable|null : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
139 | 139 | */ |
140 | - protected function getDbByName($DBname , $test = false , $test_version = true) |
|
140 | + protected function getDbByName($DBname, $test=false, $test_version=true) |
|
141 | 141 | { |
142 | 142 | try |
143 | 143 | { |
144 | - $dbconn = IcingaDbConnection::fromResourceName($DBname); |
|
144 | + $dbconn=IcingaDbConnection::fromResourceName($DBname); |
|
145 | 145 | } |
146 | 146 | catch (Exception $e) |
147 | 147 | { |
148 | 148 | if ($test === true) |
149 | 149 | { |
150 | - throw new DBException(array(2,$DBname)); |
|
150 | + throw new DBException(array(2, $DBname)); |
|
151 | 151 | } |
152 | 152 | $this->trapController->redirectNow('trapdirector/settings?dberror=2'); |
153 | 153 | return null; |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | { |
163 | 163 | if ($test === true) |
164 | 164 | { |
165 | - throw new DBException(array(3,$DBname,$e->getMessage())); |
|
165 | + throw new DBException(array(3, $DBname, $e->getMessage())); |
|
166 | 166 | } |
167 | 167 | $this->trapController->redirectNow('trapdirector/settings?dberror=3'); |
168 | 168 | return null; |
@@ -185,19 +185,19 @@ discard block |
||
185 | 185 | */ |
186 | 186 | public function getDb() |
187 | 187 | { |
188 | - if ( $this->trapDB != null ) return $this->trapDB; |
|
188 | + if ($this->trapDB != null) return $this->trapDB; |
|
189 | 189 | |
190 | 190 | |
191 | 191 | $dbresource=$this->trapController->Config()->get('config', 'database'); |
192 | 192 | |
193 | - if ( ! $dbresource ) |
|
193 | + if (!$dbresource) |
|
194 | 194 | { |
195 | 195 | $this->trapController->redirectNow('trapdirector/settings?dberror=1'); |
196 | 196 | return null; |
197 | 197 | } |
198 | 198 | |
199 | 199 | try { |
200 | - $this->trapDB = $this->getDbByName($dbresource,false,true); |
|
200 | + $this->trapDB=$this->getDbByName($dbresource, false, true); |
|
201 | 201 | } catch (DBException $e) { |
202 | 202 | return null; // Should not happen as test = false |
203 | 203 | } |
@@ -227,12 +227,12 @@ discard block |
||
227 | 227 | { |
228 | 228 | $dbresource=$this->trapController->Config()->get('config', 'database'); |
229 | 229 | |
230 | - if ( ! $dbresource ) |
|
230 | + if (!$dbresource) |
|
231 | 231 | { |
232 | - throw new DBException(array(1,'')); |
|
232 | + throw new DBException(array(1, '')); |
|
233 | 233 | } |
234 | 234 | |
235 | - $this->trapDB = $this->getDbByName($dbresource,true,true); |
|
235 | + $this->trapDB=$this->getDbByName($dbresource, true, true); |
|
236 | 236 | return; |
237 | 237 | } |
238 | 238 | |
@@ -243,11 +243,11 @@ discard block |
||
243 | 243 | */ |
244 | 244 | public function getIdoDb() |
245 | 245 | { |
246 | - if ( $this->idoDB != null ) return $this->idoDB; |
|
246 | + if ($this->idoDB != null) return $this->idoDB; |
|
247 | 247 | // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
248 | - $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');; |
|
248 | + $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase'); ; |
|
249 | 249 | |
250 | - if ( ! $dbresource ) |
|
250 | + if (!$dbresource) |
|
251 | 251 | { |
252 | 252 | $this->trapController->redirectNow('trapdirector/settings?idodberror=1'); |
253 | 253 | return null; |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | |
256 | 256 | try |
257 | 257 | { |
258 | - $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
258 | + $dbconn=IcingaDbConnection::fromResourceName($dbresource); |
|
259 | 259 | } |
260 | 260 | catch (Exception $e) |
261 | 261 | { |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | return null; |
264 | 264 | } |
265 | 265 | |
266 | - $this->idoDB = $dbconn; |
|
266 | + $this->idoDB=$dbconn; |
|
267 | 267 | return $this->idoDB; |
268 | 268 | } |
269 | 269 | |
@@ -286,35 +286,35 @@ discard block |
||
286 | 286 | public function testGetIdoDb() |
287 | 287 | { |
288 | 288 | // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
289 | - $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');; |
|
289 | + $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase'); ; |
|
290 | 290 | |
291 | - if ( ! $dbresource ) |
|
291 | + if (!$dbresource) |
|
292 | 292 | { |
293 | - throw new DBException(array(1,'No database in config.ini')); |
|
293 | + throw new DBException(array(1, 'No database in config.ini')); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | try |
297 | 297 | { |
298 | - $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
298 | + $dbconn=IcingaDbConnection::fromResourceName($dbresource); |
|
299 | 299 | } |
300 | 300 | catch (Exception $e) |
301 | 301 | { |
302 | - throw new DBException( array(2,"Database $dbresource does not exists in IcingaWeb2") ); |
|
302 | + throw new DBException(array(2, "Database $dbresource does not exists in IcingaWeb2")); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | try |
306 | 306 | { |
307 | - $query = $dbconn->select() |
|
308 | - ->from('icinga_dbversion',array('version')); |
|
307 | + $query=$dbconn->select() |
|
308 | + ->from('icinga_dbversion', array('version')); |
|
309 | 309 | $version=$dbconn->fetchRow($query); |
310 | - if ( ($version == null) || ! property_exists($version,'version') ) |
|
310 | + if (($version == null) || !property_exists($version, 'version')) |
|
311 | 311 | { |
312 | - throw new DBException( array(4,"$dbresource does not look like an IDO database")); |
|
312 | + throw new DBException(array(4, "$dbresource does not look like an IDO database")); |
|
313 | 313 | } |
314 | 314 | } |
315 | 315 | catch (Exception $e) |
316 | 316 | { |
317 | - throw new DBException( array(3,"Error connecting to $dbresource : " . $e->getMessage())); |
|
317 | + throw new DBException(array(3, "Error connecting to $dbresource : ".$e->getMessage())); |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | return; |
@@ -116,8 +116,7 @@ discard block |
||
116 | 116 | $this->trapController->redirectNow('trapdirector/settings?dberror=5'); |
117 | 117 | return false; |
118 | 118 | } |
119 | - } |
|
120 | - catch (Exception $e) |
|
119 | + } catch (Exception $e) |
|
121 | 120 | { |
122 | 121 | if ($test === true) |
123 | 122 | { |
@@ -142,8 +141,7 @@ discard block |
||
142 | 141 | try |
143 | 142 | { |
144 | 143 | $dbconn = IcingaDbConnection::fromResourceName($DBname); |
145 | - } |
|
146 | - catch (Exception $e) |
|
144 | + } catch (Exception $e) |
|
147 | 145 | { |
148 | 146 | if ($test === true) |
149 | 147 | { |
@@ -157,8 +155,7 @@ discard block |
||
157 | 155 | { |
158 | 156 | $dbAdapter=$dbconn->getDbAdapter(); |
159 | 157 | |
160 | - } |
|
161 | - catch (Exception $e) |
|
158 | + } catch (Exception $e) |
|
162 | 159 | { |
163 | 160 | if ($test === true) |
164 | 161 | { |
@@ -185,7 +182,9 @@ discard block |
||
185 | 182 | */ |
186 | 183 | public function getDb() |
187 | 184 | { |
188 | - if ( $this->trapDB != null ) return $this->trapDB; |
|
185 | + if ( $this->trapDB != null ) { |
|
186 | + return $this->trapDB; |
|
187 | + } |
|
189 | 188 | |
190 | 189 | |
191 | 190 | $dbresource=$this->trapController->Config()->get('config', 'database'); |
@@ -213,7 +212,9 @@ discard block |
||
213 | 212 | */ |
214 | 213 | public function getDbConn() |
215 | 214 | { |
216 | - if ($this->getDb() == null) return null; |
|
215 | + if ($this->getDb() == null) { |
|
216 | + return null; |
|
217 | + } |
|
217 | 218 | return $this->getDb()->getConnection(); |
218 | 219 | } |
219 | 220 | |
@@ -243,7 +244,9 @@ discard block |
||
243 | 244 | */ |
244 | 245 | public function getIdoDb() |
245 | 246 | { |
246 | - if ( $this->idoDB != null ) return $this->idoDB; |
|
247 | + if ( $this->idoDB != null ) { |
|
248 | + return $this->idoDB; |
|
249 | + } |
|
247 | 250 | // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
248 | 251 | $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');; |
249 | 252 | |
@@ -256,8 +259,7 @@ discard block |
||
256 | 259 | try |
257 | 260 | { |
258 | 261 | $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
259 | - } |
|
260 | - catch (Exception $e) |
|
262 | + } catch (Exception $e) |
|
261 | 263 | { |
262 | 264 | $this->trapController->redirectNow('trapdirector/settings?idodberror=2'); |
263 | 265 | return null; |
@@ -274,7 +276,9 @@ discard block |
||
274 | 276 | */ |
275 | 277 | public function getIdoDbConn() |
276 | 278 | { |
277 | - if ($this->getIdoDb() == null) return null; |
|
279 | + if ($this->getIdoDb() == null) { |
|
280 | + return null; |
|
281 | + } |
|
278 | 282 | return $this->getIdoDb()->getConnection(); |
279 | 283 | } |
280 | 284 | |
@@ -296,8 +300,7 @@ discard block |
||
296 | 300 | try |
297 | 301 | { |
298 | 302 | $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
299 | - } |
|
300 | - catch (Exception $e) |
|
303 | + } catch (Exception $e) |
|
301 | 304 | { |
302 | 305 | throw new DBException( array(2,"Database $dbresource does not exists in IcingaWeb2") ); |
303 | 306 | } |
@@ -311,8 +314,7 @@ discard block |
||
311 | 314 | { |
312 | 315 | throw new DBException( array(4,"$dbresource does not look like an IDO database")); |
313 | 316 | } |
314 | - } |
|
315 | - catch (Exception $e) |
|
317 | + } catch (Exception $e) |
|
316 | 318 | { |
317 | 319 | throw new DBException( array(3,"Error connecting to $dbresource : " . $e->getMessage())); |
318 | 320 | } |