@@ -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->getUIDatabase()->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->getUIDatabase()->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->getUIDatabase()->getHostByName($this->view->hostname); |
|
| 203 | + // Check if hostname still exists |
|
| 204 | + $host_get=$this->getUIDatabase()->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->getUIDatabase()->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->getUIDatabase()->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->getUIDatabase()->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->getUIDatabase()->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->getUIDatabase()->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->getUIDatabase()->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(); |
@@ -428,7 +427,7 @@ discard block |
||
| 428 | 427 | { |
| 429 | 428 | try |
| 430 | 429 | { |
| 431 | - $this->getUIDatabase()->deleteRule($postData[$params['db_rule']['post']]); |
|
| 430 | + $this->getUIDatabase()->deleteRule($postData[$params['db_rule']['post']]); |
|
| 432 | 431 | } |
| 433 | 432 | catch (Exception $e) |
| 434 | 433 | { |
@@ -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 | } |
@@ -465,7 +464,7 @@ discard block |
||
| 465 | 464 | $isHostGroup=($params['hostgroup']['val'] == 1)?true:false; |
| 466 | 465 | if (! $isHostGroup ) |
| 467 | 466 | { // checks if selection by host |
| 468 | - $hostAddr=$this->getUIDatabase()->getHostInfoByID($params['hostid']['val']); |
|
| 467 | + $hostAddr=$this->getUIDatabase()->getHostInfoByID($params['hostid']['val']); |
|
| 469 | 468 | $params['ip4']['val']=$hostAddr->ip4; |
| 470 | 469 | $params['ip6']['val']=$hostAddr->ip6; |
| 471 | 470 | $checkHostName=$hostAddr->name; |
@@ -476,8 +475,8 @@ discard block |
||
| 476 | 475 | } |
| 477 | 476 | if (!is_numeric($params['serviceid']['val'])) |
| 478 | 477 | { |
| 479 | - $this->_helper->json(array('status'=>"Invalid service id ". $params['serviceid']['val'])); |
|
| 480 | - return; |
|
| 478 | + $this->_helper->json(array('status'=>"Invalid service id ". $params['serviceid']['val'])); |
|
| 479 | + return; |
|
| 481 | 480 | } |
| 482 | 481 | $serviceName=$this->getUIDatabase()->getObjectNameByid($params['serviceid']['val']); |
| 483 | 482 | if ($params['service_name']['val'] != $serviceName->name2) |
@@ -488,7 +487,7 @@ discard block |
||
| 488 | 487 | } |
| 489 | 488 | else |
| 490 | 489 | { |
| 491 | - $object=$this->getUIDatabase()->getObjectNameByid($params['hostid']['val']); |
|
| 490 | + $object=$this->getUIDatabase()->getObjectNameByid($params['hostid']['val']); |
|
| 492 | 491 | if ($params['host_name']['val'] != $object->name1) |
| 493 | 492 | { |
| 494 | 493 | $this->_helper->json(array('status'=>"Invalid object group id : Please re enter service")); |
@@ -509,11 +508,11 @@ discard block |
||
| 509 | 508 | // echo '<br>'; print_r($dbparams);echo '<br>'; |
| 510 | 509 | if ($params['db_rule']['val'] == -1 ) |
| 511 | 510 | { |
| 512 | - $ruleID=$this->getUIDatabase()->addHandlerRule($dbparams); |
|
| 511 | + $ruleID=$this->getUIDatabase()->addHandlerRule($dbparams); |
|
| 513 | 512 | } |
| 514 | 513 | else |
| 515 | 514 | { |
| 516 | - $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']); |
|
| 515 | + $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']); |
|
| 517 | 516 | $ruleID=$params['db_rule']['val']; |
| 518 | 517 | } |
| 519 | 518 | } |
@@ -527,9 +526,9 @@ discard block |
||
| 527 | 526 | } |
| 528 | 527 | |
| 529 | 528 | /** Get trap detail by trapid. |
| 530 | - * @param integer $trapid : id of trap in received table |
|
| 531 | - * @return array (objects) |
|
| 532 | - */ |
|
| 529 | + * @param integer $trapid : id of trap in received table |
|
| 530 | + * @return array (objects) |
|
| 531 | + */ |
|
| 533 | 532 | protected function getTrapDetail($trapid) |
| 534 | 533 | { |
| 535 | 534 | if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id'); } |
@@ -545,14 +544,14 @@ discard block |
||
| 545 | 544 | } |
| 546 | 545 | try |
| 547 | 546 | { |
| 548 | - $query = $dbConn->select() |
|
| 547 | + $query = $dbConn->select() |
|
| 549 | 548 | ->from($this->getModuleConfig()->getTrapTableName(),$elmts) |
| 550 | 549 | ->where('id=?',$trapid); |
| 551 | 550 | $trapDetail=$dbConn->fetchRow($query); |
| 552 | 551 | if ( $trapDetail == null ) |
| 553 | 552 | { |
| 554 | - $trapDetail = 'NULL'; |
|
| 555 | - throw new Exception('No traps was found with id = '.$trapid); |
|
| 553 | + $trapDetail = 'NULL'; |
|
| 554 | + throw new Exception('No traps was found with id = '.$trapid); |
|
| 556 | 555 | } |
| 557 | 556 | } |
| 558 | 557 | catch (Exception $e) |
@@ -566,9 +565,9 @@ discard block |
||
| 566 | 565 | } |
| 567 | 566 | |
| 568 | 567 | /** Get trap objects |
| 569 | - * @param integer $trapid : trap id |
|
| 570 | - * @return array : full column in db of trap id |
|
| 571 | - */ |
|
| 568 | + * @param integer $trapid : trap id |
|
| 569 | + * @return array : full column in db of trap id |
|
| 570 | + */ |
|
| 572 | 571 | protected function getTrapobjects($trapid) |
| 573 | 572 | { |
| 574 | 573 | if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id'); } |
@@ -584,7 +583,7 @@ discard block |
||
| 584 | 583 | } |
| 585 | 584 | try |
| 586 | 585 | { |
| 587 | - $query = $dbConn->select() |
|
| 586 | + $query = $dbConn->select() |
|
| 588 | 587 | ->from($this->moduleConfig->getTrapDataTableName(),$data_elmts) |
| 589 | 588 | ->where('trap_id=?',$trapid); |
| 590 | 589 | $trapDetail=$dbConn->fetchAll($query); |
@@ -600,10 +599,10 @@ discard block |
||
| 600 | 599 | } |
| 601 | 600 | |
| 602 | 601 | /** Get rule detail by ruleid. |
| 603 | - * @param integer $ruleid int id of rule in rule table |
|
| 604 | - * @return object|array : column objects in db |
|
| 605 | - * |
|
| 606 | - */ |
|
| 602 | + * @param integer $ruleid int id of rule in rule table |
|
| 603 | + * @return object|array : column objects in db |
|
| 604 | + * |
|
| 605 | + */ |
|
| 607 | 606 | protected function getRuleDetail($ruleid) |
| 608 | 607 | { |
| 609 | 608 | if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id'); } |
@@ -614,7 +613,7 @@ discard block |
||
| 614 | 613 | // *************** Get main data |
| 615 | 614 | try |
| 616 | 615 | { |
| 617 | - $query = $dbConn->select() |
|
| 616 | + $query = $dbConn->select() |
|
| 618 | 617 | ->from($this->getModuleConfig()->getTrapRuleName(),$queryArray) |
| 619 | 618 | ->where('id=?',$ruleid); |
| 620 | 619 | $ruleDetail=$dbConn->fetchRow($query); |
@@ -631,7 +630,7 @@ discard block |
||
| 631 | 630 | } |
| 632 | 631 | |
| 633 | 632 | /** Setup tabs for rules |
| 634 | - */ |
|
| 633 | + */ |
|
| 635 | 634 | protected function prepareTabs() |
| 636 | 635 | { |
| 637 | 636 | return $this->getTabs()->add('status', array( |
@@ -20,7 +20,7 @@ |
||
| 20 | 20 | $inputStream=fopen('php://stdin', 'r'); |
| 21 | 21 | if ($inputStream === false) |
| 22 | 22 | { |
| 23 | - exit(1); |
|
| 23 | + exit(1); |
|
| 24 | 24 | } |
| 25 | 25 | $rule=chop(fgets($inputStream)); |
| 26 | 26 | } else |
@@ -8,363 +8,363 @@ |
||
| 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 | - } |
|
| 78 | - catch (Exception $e) |
|
| 79 | - { |
|
| 80 | - return array(true, 'Error with API : '.$e->getMessage()); |
|
| 81 | - } |
|
| 82 | - //var_dump($result); |
|
| 83 | - $permOk=1; |
|
| 84 | - $permMissing=''; |
|
| 85 | - if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions')) |
|
| 86 | - { |
|
| 72 | + public function test(array $permissions) |
|
| 73 | + { |
|
| 74 | + try |
|
| 75 | + { |
|
| 76 | + $result=$this->request('GET', "", NULL, NULL); |
|
| 77 | + } |
|
| 78 | + catch (Exception $e) |
|
| 79 | + { |
|
| 80 | + return array(true, 'Error with API : '.$e->getMessage()); |
|
| 81 | + } |
|
| 82 | + //var_dump($result); |
|
| 83 | + $permOk=1; |
|
| 84 | + $permMissing=''; |
|
| 85 | + if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions')) |
|
| 86 | + { |
|
| 87 | 87 | |
| 88 | - foreach ( $permissions as $mustPermission) |
|
| 89 | - { |
|
| 90 | - $curPermOK=0; |
|
| 91 | - foreach ( $result->results[0]->permissions as $curPermission) |
|
| 92 | - { |
|
| 93 | - $curPermission=preg_replace('/\*/','.*',$curPermission); // put * as .* to created a regexp |
|
| 94 | - if (preg_match('#'.$curPermission.'#',$mustPermission)) |
|
| 95 | - { |
|
| 96 | - $curPermOK=1; |
|
| 97 | - break; |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - if ($curPermOK == 0) |
|
| 101 | - { |
|
| 102 | - $permOk=0; |
|
| 103 | - $permMissing=$mustPermission; |
|
| 104 | - break; |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - if ($permOk == 0) |
|
| 108 | - { |
|
| 109 | - return array(true,'API connection OK, but missing permission : '.$permMissing); |
|
| 110 | - } |
|
| 111 | - return array(false,'API connection OK'); |
|
| 88 | + foreach ( $permissions as $mustPermission) |
|
| 89 | + { |
|
| 90 | + $curPermOK=0; |
|
| 91 | + foreach ( $result->results[0]->permissions as $curPermission) |
|
| 92 | + { |
|
| 93 | + $curPermission=preg_replace('/\*/','.*',$curPermission); // put * as .* to created a regexp |
|
| 94 | + if (preg_match('#'.$curPermission.'#',$mustPermission)) |
|
| 95 | + { |
|
| 96 | + $curPermOK=1; |
|
| 97 | + break; |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + if ($curPermOK == 0) |
|
| 101 | + { |
|
| 102 | + $permOk=0; |
|
| 103 | + $permMissing=$mustPermission; |
|
| 104 | + break; |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + if ($permOk == 0) |
|
| 108 | + { |
|
| 109 | + return array(true,'API connection OK, but missing permission : '.$permMissing); |
|
| 110 | + } |
|
| 111 | + return array(false,'API connection OK'); |
|
| 112 | 112 | |
| 113 | - } |
|
| 114 | - return array(true,'API connection OK, but cannot get permissions'); |
|
| 115 | - } |
|
| 113 | + } |
|
| 114 | + return array(true,'API connection OK, but cannot get permissions'); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | 117 | |
| 118 | - protected function url($url) { |
|
| 119 | - return sprintf('https://%s:%d/%s/%s', $this->host, $this->port, $this->version, $url); |
|
| 120 | - } |
|
| 118 | + protected function url($url) { |
|
| 119 | + return sprintf('https://%s:%d/%s/%s', $this->host, $this->port, $this->version, $url); |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * Create or return curl ressource |
|
| 124 | - * @throws Exception |
|
| 125 | - * @return resource |
|
| 126 | - */ |
|
| 127 | - protected function curl() { |
|
| 128 | - if ($this->curl === null) { |
|
| 129 | - $this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port)); |
|
| 130 | - if ($this->curl === false) { |
|
| 131 | - throw new Exception('CURL INIT ERROR'); |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - return $this->curl; |
|
| 135 | - } |
|
| 122 | + /** |
|
| 123 | + * Create or return curl ressource |
|
| 124 | + * @throws Exception |
|
| 125 | + * @return resource |
|
| 126 | + */ |
|
| 127 | + protected function curl() { |
|
| 128 | + if ($this->curl === null) { |
|
| 129 | + $this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port)); |
|
| 130 | + if ($this->curl === false) { |
|
| 131 | + throw new Exception('CURL INIT ERROR'); |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + return $this->curl; |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - /** |
|
| 138 | - * Send a passive service check |
|
| 139 | - * @param string $host : host name |
|
| 140 | - * @param string $service : service name |
|
| 141 | - * @param int $state : state of service |
|
| 142 | - * @param string $display : service passive check output |
|
| 143 | - * @param string $perfdata : performance data as string |
|
| 144 | - * @return array (status = true (oK) or false (nok), string message) |
|
| 145 | - */ |
|
| 146 | - public function serviceCheckResult($host,$service,$state,$display,$perfdata='') |
|
| 147 | - { |
|
| 148 | - //Send a POST request to the URL endpoint /v1/actions/process-check-result |
|
| 149 | - //actions/process-check-result?service=example.localdomain!passive-ping6 |
|
| 150 | - $url='actions/process-check-result'; |
|
| 151 | - $body=array( |
|
| 152 | - "filter" => 'service.name=="'.$service.'" && service.host_name=="'.$host.'"', |
|
| 153 | - 'type' => 'Service', |
|
| 154 | - "exit_status" => $state, |
|
| 155 | - "plugin_output" => $display, |
|
| 156 | - "performance_data" => $perfdata |
|
| 157 | - ); |
|
| 158 | - try |
|
| 159 | - { |
|
| 160 | - $result=$this->request('POST', $url, null, $body); |
|
| 161 | - } catch (Exception $e) |
|
| 162 | - { |
|
| 163 | - return array(false, $e->getMessage()); |
|
| 164 | - } |
|
| 165 | - if (property_exists($result,'error') ) |
|
| 166 | - { |
|
| 167 | - if (property_exists($result,'status')) |
|
| 168 | - { |
|
| 169 | - $message=$result->status; |
|
| 170 | - } |
|
| 171 | - else |
|
| 172 | - { |
|
| 173 | - $message="Unkown status"; |
|
| 174 | - } |
|
| 175 | - return array(false , 'Ret code ' .$result->error.' : '.$message); |
|
| 176 | - } |
|
| 177 | - if (property_exists($result, 'results')) |
|
| 178 | - { |
|
| 179 | - if (isset($result->results[0])) |
|
| 180 | - { |
|
| 181 | - return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status); |
|
| 182 | - } |
|
| 183 | - else |
|
| 184 | - { |
|
| 185 | - return array(false,'Service not found'); |
|
| 186 | - } |
|
| 137 | + /** |
|
| 138 | + * Send a passive service check |
|
| 139 | + * @param string $host : host name |
|
| 140 | + * @param string $service : service name |
|
| 141 | + * @param int $state : state of service |
|
| 142 | + * @param string $display : service passive check output |
|
| 143 | + * @param string $perfdata : performance data as string |
|
| 144 | + * @return array (status = true (oK) or false (nok), string message) |
|
| 145 | + */ |
|
| 146 | + public function serviceCheckResult($host,$service,$state,$display,$perfdata='') |
|
| 147 | + { |
|
| 148 | + //Send a POST request to the URL endpoint /v1/actions/process-check-result |
|
| 149 | + //actions/process-check-result?service=example.localdomain!passive-ping6 |
|
| 150 | + $url='actions/process-check-result'; |
|
| 151 | + $body=array( |
|
| 152 | + "filter" => 'service.name=="'.$service.'" && service.host_name=="'.$host.'"', |
|
| 153 | + 'type' => 'Service', |
|
| 154 | + "exit_status" => $state, |
|
| 155 | + "plugin_output" => $display, |
|
| 156 | + "performance_data" => $perfdata |
|
| 157 | + ); |
|
| 158 | + try |
|
| 159 | + { |
|
| 160 | + $result=$this->request('POST', $url, null, $body); |
|
| 161 | + } catch (Exception $e) |
|
| 162 | + { |
|
| 163 | + return array(false, $e->getMessage()); |
|
| 164 | + } |
|
| 165 | + if (property_exists($result,'error') ) |
|
| 166 | + { |
|
| 167 | + if (property_exists($result,'status')) |
|
| 168 | + { |
|
| 169 | + $message=$result->status; |
|
| 170 | + } |
|
| 171 | + else |
|
| 172 | + { |
|
| 173 | + $message="Unkown status"; |
|
| 174 | + } |
|
| 175 | + return array(false , 'Ret code ' .$result->error.' : '.$message); |
|
| 176 | + } |
|
| 177 | + if (property_exists($result, 'results')) |
|
| 178 | + { |
|
| 179 | + if (isset($result->results[0])) |
|
| 180 | + { |
|
| 181 | + return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status); |
|
| 182 | + } |
|
| 183 | + else |
|
| 184 | + { |
|
| 185 | + return array(false,'Service not found'); |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - } |
|
| 189 | - return array(false,'Unkown result, open issue with this : '.print_r($result,true)); |
|
| 190 | - } |
|
| 188 | + } |
|
| 189 | + return array(false,'Unkown result, open issue with this : '.print_r($result,true)); |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | - /** |
|
| 193 | - * return array of host by IP (4 or 6) |
|
| 194 | - * @param string $ip |
|
| 195 | - * @throws Exception |
|
| 196 | - * @return array objects : array('__name','name','display_name') |
|
| 197 | - */ |
|
| 198 | - public function getHostByIP($ip) |
|
| 199 | - { |
|
| 200 | - /* |
|
| 192 | + /** |
|
| 193 | + * return array of host by IP (4 or 6) |
|
| 194 | + * @param string $ip |
|
| 195 | + * @throws Exception |
|
| 196 | + * @return array objects : array('__name','name','display_name') |
|
| 197 | + */ |
|
| 198 | + public function getHostByIP($ip) |
|
| 199 | + { |
|
| 200 | + /* |
|
| 201 | 201 | * curl -k -s -u trapdirector:trapdirector -H 'X-HTTP-Method-Override: GET' -X POST 'https://localhost:5665/v1/objects/hosts' |
| 202 | 202 | * -d '{"filter":"host.group==\"test_trap\"","attrs": ["address" ,"address6"]}' |
| 203 | 203 | |
| 204 | 204 | {"results":[{"attrs":{"__name":"Icinga host","address":"127.0.0.1","display_name":"Icinga host","name":"Icinga host"},"joins":{},"meta":{},"name":"Icinga host","type":"Host"}]} |
| 205 | 205 | */ |
| 206 | 206 | |
| 207 | - $url='objects/hosts'; |
|
| 208 | - $body=array( |
|
| 209 | - "filter" => 'host.address=="'.$ip.'" || host.address6=="'.$ip.'"', |
|
| 210 | - "attrs" => array('__name','name','display_name') |
|
| 211 | - ); |
|
| 212 | - try |
|
| 213 | - { |
|
| 214 | - $result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body); |
|
| 215 | - } catch (Exception $e) |
|
| 216 | - { |
|
| 217 | - throw new Exception($e->getMessage()); |
|
| 218 | - } |
|
| 207 | + $url='objects/hosts'; |
|
| 208 | + $body=array( |
|
| 209 | + "filter" => 'host.address=="'.$ip.'" || host.address6=="'.$ip.'"', |
|
| 210 | + "attrs" => array('__name','name','display_name') |
|
| 211 | + ); |
|
| 212 | + try |
|
| 213 | + { |
|
| 214 | + $result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body); |
|
| 215 | + } catch (Exception $e) |
|
| 216 | + { |
|
| 217 | + throw new Exception($e->getMessage()); |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | - if (property_exists($result,'error') ) |
|
| 221 | - { |
|
| 222 | - if (property_exists($result,'status')) |
|
| 223 | - { |
|
| 224 | - throw new Exception('Ret code ' .$result->error.' : ' . $result->status); |
|
| 225 | - } |
|
| 226 | - else |
|
| 227 | - { |
|
| 228 | - throw new Exception('Ret code ' .$result->error.' : Unkown status'); |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - if (property_exists($result, 'results')) |
|
| 232 | - { |
|
| 233 | - $numHost=0; |
|
| 234 | - $hostArray=array(); |
|
| 235 | - while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs')) |
|
| 236 | - { |
|
| 237 | - $hostArray[$numHost] = $result->results[$numHost]->attrs; |
|
| 238 | - $numHost++; |
|
| 239 | - } |
|
| 240 | - return $hostArray; |
|
| 241 | - } |
|
| 242 | - throw new Exception('Unkown result'); |
|
| 243 | - } |
|
| 220 | + if (property_exists($result,'error') ) |
|
| 221 | + { |
|
| 222 | + if (property_exists($result,'status')) |
|
| 223 | + { |
|
| 224 | + throw new Exception('Ret code ' .$result->error.' : ' . $result->status); |
|
| 225 | + } |
|
| 226 | + else |
|
| 227 | + { |
|
| 228 | + throw new Exception('Ret code ' .$result->error.' : Unkown status'); |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + if (property_exists($result, 'results')) |
|
| 232 | + { |
|
| 233 | + $numHost=0; |
|
| 234 | + $hostArray=array(); |
|
| 235 | + while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs')) |
|
| 236 | + { |
|
| 237 | + $hostArray[$numHost] = $result->results[$numHost]->attrs; |
|
| 238 | + $numHost++; |
|
| 239 | + } |
|
| 240 | + return $hostArray; |
|
| 241 | + } |
|
| 242 | + throw new Exception('Unkown result'); |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - /** |
|
| 246 | - * Get all host and IP from hostgroup |
|
| 247 | - * @param string $hostGroup |
|
| 248 | - * @throws Exception |
|
| 249 | - * @return array : attributes : address, address6, name |
|
| 250 | - */ |
|
| 251 | - public function getHostsIPByHostGroup($hostGroup) |
|
| 252 | - { |
|
| 253 | - $url='objects/hosts'; |
|
| 254 | - $body=array( |
|
| 255 | - "filter" => '\"'.$hostGroup.'\" in host.groups', |
|
| 256 | - "attrs" => array('address','address','name') |
|
| 257 | - ); |
|
| 258 | - try |
|
| 259 | - { |
|
| 260 | - $result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body); |
|
| 261 | - } catch (Exception $e) |
|
| 262 | - { |
|
| 263 | - throw new Exception($e->getMessage()); |
|
| 264 | - } |
|
| 245 | + /** |
|
| 246 | + * Get all host and IP from hostgroup |
|
| 247 | + * @param string $hostGroup |
|
| 248 | + * @throws Exception |
|
| 249 | + * @return array : attributes : address, address6, name |
|
| 250 | + */ |
|
| 251 | + public function getHostsIPByHostGroup($hostGroup) |
|
| 252 | + { |
|
| 253 | + $url='objects/hosts'; |
|
| 254 | + $body=array( |
|
| 255 | + "filter" => '\"'.$hostGroup.'\" in host.groups', |
|
| 256 | + "attrs" => array('address','address','name') |
|
| 257 | + ); |
|
| 258 | + try |
|
| 259 | + { |
|
| 260 | + $result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body); |
|
| 261 | + } catch (Exception $e) |
|
| 262 | + { |
|
| 263 | + throw new Exception($e->getMessage()); |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | - if (property_exists($result,'error') ) |
|
| 267 | - { |
|
| 268 | - if (property_exists($result,'status')) |
|
| 269 | - { |
|
| 270 | - throw new Exception('Ret code ' .$result->error.' : ' . $result->status); |
|
| 271 | - } |
|
| 272 | - else |
|
| 273 | - { |
|
| 274 | - throw new Exception('Ret code ' .$result->error.' : Unkown status'); |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - if (property_exists($result, 'results')) |
|
| 278 | - { |
|
| 279 | - $numHost=0; |
|
| 280 | - $hostArray=array(); |
|
| 281 | - while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs')) |
|
| 282 | - { |
|
| 283 | - $hostArray[$numHost] = $result->results[$numHost]->attrs; |
|
| 284 | - $hostArray[$numHost]->name = $result->results[$numHost]->name; |
|
| 285 | - $numHost++; |
|
| 286 | - } |
|
| 287 | - return $hostArray; |
|
| 288 | - } |
|
| 289 | - throw new Exception('Unkown result'); |
|
| 290 | - } |
|
| 266 | + if (property_exists($result,'error') ) |
|
| 267 | + { |
|
| 268 | + if (property_exists($result,'status')) |
|
| 269 | + { |
|
| 270 | + throw new Exception('Ret code ' .$result->error.' : ' . $result->status); |
|
| 271 | + } |
|
| 272 | + else |
|
| 273 | + { |
|
| 274 | + throw new Exception('Ret code ' .$result->error.' : Unkown status'); |
|
| 275 | + } |
|
| 276 | + } |
|
| 277 | + if (property_exists($result, 'results')) |
|
| 278 | + { |
|
| 279 | + $numHost=0; |
|
| 280 | + $hostArray=array(); |
|
| 281 | + while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs')) |
|
| 282 | + { |
|
| 283 | + $hostArray[$numHost] = $result->results[$numHost]->attrs; |
|
| 284 | + $hostArray[$numHost]->name = $result->results[$numHost]->name; |
|
| 285 | + $numHost++; |
|
| 286 | + } |
|
| 287 | + return $hostArray; |
|
| 288 | + } |
|
| 289 | + throw new Exception('Unkown result'); |
|
| 290 | + } |
|
| 291 | 291 | |
| 292 | - /** |
|
| 293 | - * Send request to API |
|
| 294 | - * @param string $method get/post/... |
|
| 295 | - * @param string $url (after /v1/ ) |
|
| 296 | - * @param array $headers |
|
| 297 | - * @param array $body |
|
| 298 | - * @throws Exception |
|
| 299 | - * @return array |
|
| 300 | - */ |
|
| 301 | - public function request($method, $url, $headers, $body) { |
|
| 302 | - $auth = sprintf('%s:%s', $this->user, $this->pass); |
|
| 303 | - $curlHeaders = array("Accept: application/json"); |
|
| 304 | - if ($body !== null) { |
|
| 305 | - $body = json_encode($body); |
|
| 306 | - array_push($curlHeaders, 'Content-Type: application/json'); |
|
| 307 | - //array_push($curlHeaders, 'X-HTTP-Method-Override: GET'); |
|
| 308 | - } |
|
| 309 | - //var_dump($body); |
|
| 310 | - //var_dump($this->url($url)); |
|
| 311 | - if ($headers !== null) { |
|
| 312 | - $curlFinalHeaders = array_merge($curlHeaders, $headers); |
|
| 313 | - } else |
|
| 314 | - { |
|
| 315 | - $curlFinalHeaders=$curlHeaders; |
|
| 316 | - } |
|
| 317 | - $curl = $this->curl(); |
|
| 318 | - $opts = array( |
|
| 319 | - CURLOPT_URL => $this->url($url), |
|
| 320 | - CURLOPT_HTTPHEADER => $curlFinalHeaders, |
|
| 321 | - CURLOPT_USERPWD => $auth, |
|
| 322 | - CURLOPT_CUSTOMREQUEST => strtoupper($method), |
|
| 323 | - CURLOPT_RETURNTRANSFER => true, |
|
| 324 | - CURLOPT_CONNECTTIMEOUT => 10, |
|
| 325 | - CURLOPT_SSL_VERIFYHOST => false, |
|
| 326 | - CURLOPT_SSL_VERIFYPEER => false, |
|
| 327 | - ); |
|
| 328 | - if ($body !== null) { |
|
| 329 | - $opts[CURLOPT_POSTFIELDS] = $body; |
|
| 330 | - } |
|
| 331 | - curl_setopt_array($curl, $opts); |
|
| 332 | - $res = curl_exec($curl); |
|
| 333 | - if ($res === false) { |
|
| 334 | - throw new Exception('CURL ERROR: ' . curl_error($curl)); |
|
| 335 | - } |
|
| 336 | - $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); |
|
| 337 | - if ($statusCode === 401) { |
|
| 338 | - throw new Exception('Unable to authenticate, please check your API credentials'); |
|
| 339 | - } |
|
| 340 | - return $this->fromJsonResult($res); |
|
| 341 | - } |
|
| 292 | + /** |
|
| 293 | + * Send request to API |
|
| 294 | + * @param string $method get/post/... |
|
| 295 | + * @param string $url (after /v1/ ) |
|
| 296 | + * @param array $headers |
|
| 297 | + * @param array $body |
|
| 298 | + * @throws Exception |
|
| 299 | + * @return array |
|
| 300 | + */ |
|
| 301 | + public function request($method, $url, $headers, $body) { |
|
| 302 | + $auth = sprintf('%s:%s', $this->user, $this->pass); |
|
| 303 | + $curlHeaders = array("Accept: application/json"); |
|
| 304 | + if ($body !== null) { |
|
| 305 | + $body = json_encode($body); |
|
| 306 | + array_push($curlHeaders, 'Content-Type: application/json'); |
|
| 307 | + //array_push($curlHeaders, 'X-HTTP-Method-Override: GET'); |
|
| 308 | + } |
|
| 309 | + //var_dump($body); |
|
| 310 | + //var_dump($this->url($url)); |
|
| 311 | + if ($headers !== null) { |
|
| 312 | + $curlFinalHeaders = array_merge($curlHeaders, $headers); |
|
| 313 | + } else |
|
| 314 | + { |
|
| 315 | + $curlFinalHeaders=$curlHeaders; |
|
| 316 | + } |
|
| 317 | + $curl = $this->curl(); |
|
| 318 | + $opts = array( |
|
| 319 | + CURLOPT_URL => $this->url($url), |
|
| 320 | + CURLOPT_HTTPHEADER => $curlFinalHeaders, |
|
| 321 | + CURLOPT_USERPWD => $auth, |
|
| 322 | + CURLOPT_CUSTOMREQUEST => strtoupper($method), |
|
| 323 | + CURLOPT_RETURNTRANSFER => true, |
|
| 324 | + CURLOPT_CONNECTTIMEOUT => 10, |
|
| 325 | + CURLOPT_SSL_VERIFYHOST => false, |
|
| 326 | + CURLOPT_SSL_VERIFYPEER => false, |
|
| 327 | + ); |
|
| 328 | + if ($body !== null) { |
|
| 329 | + $opts[CURLOPT_POSTFIELDS] = $body; |
|
| 330 | + } |
|
| 331 | + curl_setopt_array($curl, $opts); |
|
| 332 | + $res = curl_exec($curl); |
|
| 333 | + if ($res === false) { |
|
| 334 | + throw new Exception('CURL ERROR: ' . curl_error($curl)); |
|
| 335 | + } |
|
| 336 | + $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); |
|
| 337 | + if ($statusCode === 401) { |
|
| 338 | + throw new Exception('Unable to authenticate, please check your API credentials'); |
|
| 339 | + } |
|
| 340 | + return $this->fromJsonResult($res); |
|
| 341 | + } |
|
| 342 | 342 | |
| 343 | - /** |
|
| 344 | - * |
|
| 345 | - * @param string $json json encoded |
|
| 346 | - * @throws Exception |
|
| 347 | - * @return array json decoded |
|
| 348 | - */ |
|
| 349 | - protected function fromJsonResult($json) { |
|
| 350 | - $result = @json_decode($json); |
|
| 351 | - //var_dump($json); |
|
| 352 | - if ($result === null) { |
|
| 353 | - throw new Exception('Parsing JSON failed: '.$this->getLastJsonErrorMessage(json_last_error())); |
|
| 354 | - } |
|
| 355 | - return $result; |
|
| 356 | - } |
|
| 343 | + /** |
|
| 344 | + * |
|
| 345 | + * @param string $json json encoded |
|
| 346 | + * @throws Exception |
|
| 347 | + * @return array json decoded |
|
| 348 | + */ |
|
| 349 | + protected function fromJsonResult($json) { |
|
| 350 | + $result = @json_decode($json); |
|
| 351 | + //var_dump($json); |
|
| 352 | + if ($result === null) { |
|
| 353 | + throw new Exception('Parsing JSON failed: '.$this->getLastJsonErrorMessage(json_last_error())); |
|
| 354 | + } |
|
| 355 | + return $result; |
|
| 356 | + } |
|
| 357 | 357 | |
| 358 | - /** |
|
| 359 | - * Return text error no json error |
|
| 360 | - * @param string $errorCode |
|
| 361 | - * @return string |
|
| 362 | - */ |
|
| 363 | - protected function getLastJsonErrorMessage($errorCode) { |
|
| 364 | - if (!array_key_exists($errorCode, $this->errorReference)) { |
|
| 365 | - return self::JSON_UNKNOWN_ERROR; |
|
| 366 | - } |
|
| 367 | - return $this->errorReference[$errorCode]; |
|
| 368 | - } |
|
| 358 | + /** |
|
| 359 | + * Return text error no json error |
|
| 360 | + * @param string $errorCode |
|
| 361 | + * @return string |
|
| 362 | + */ |
|
| 363 | + protected function getLastJsonErrorMessage($errorCode) { |
|
| 364 | + if (!array_key_exists($errorCode, $this->errorReference)) { |
|
| 365 | + return self::JSON_UNKNOWN_ERROR; |
|
| 366 | + } |
|
| 367 | + return $this->errorReference[$errorCode]; |
|
| 368 | + } |
|
| 369 | 369 | } |
| 370 | 370 | |
@@ -31,10 +31,10 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Get all mibs in db which have at least one trap |
|
| 36 | - * @return array |
|
| 37 | - */ |
|
| 34 | + /** |
|
| 35 | + * Get all mibs in db which have at least one trap |
|
| 36 | + * @return array |
|
| 37 | + */ |
|
| 38 | 38 | |
| 39 | 39 | public function getMIBList() |
| 40 | 40 | { |
@@ -58,9 +58,9 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | |
| 60 | 60 | /** Get trap list from a mib |
| 61 | - * @param $mib string mib name |
|
| 62 | - * @return array : traps |
|
| 63 | - */ |
|
| 61 | + * @param $mib string mib name |
|
| 62 | + * @return array : traps |
|
| 63 | + */ |
|
| 64 | 64 | public function getTrapList($mib) |
| 65 | 65 | { |
| 66 | 66 | $traps=array(); |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | $query=$dbconn->select() |
| 69 | 69 | ->from( |
| 70 | 70 | $this->config->getMIBCacheTableName(), |
| 71 | - array('name' => 'name', 'oid' => 'oid', 'description' => 'description')) |
|
| 71 | + array('name' => 'name', 'oid' => 'oid', 'description' => 'description')) |
|
| 72 | 72 | ->where("mib = '".$mib."' AND type='21'") ; |
| 73 | 73 | $names=$dbconn->fetchAll($query); |
| 74 | 74 | foreach ($names as $val) |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** Get objects a trap can have |
| 82 | - * @param string $trap oid of trap |
|
| 83 | - * @return array|null : null if trap not found, or array ( <oid> => name/mib/type ) |
|
| 84 | - */ |
|
| 82 | + * @param string $trap oid of trap |
|
| 83 | + * @return array|null : null if trap not found, or array ( <oid> => name/mib/type ) |
|
| 84 | + */ |
|
| 85 | 85 | public function getObjectList($trap) |
| 86 | 86 | { |
| 87 | 87 | $objects=array(); |
@@ -97,15 +97,15 @@ discard block |
||
| 97 | 97 | if ( ($id == null) || ! property_exists($id,'id') ) return null; |
| 98 | 98 | |
| 99 | 99 | $query=$dbconn->select() |
| 100 | - ->from( |
|
| 101 | - array('c' => $this->config->getMIBCacheTableName()), |
|
| 102 | - array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum', |
|
| 103 | - 'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint', |
|
| 104 | - 'description' => 'c.description')) |
|
| 105 | - ->join( |
|
| 106 | - array('o' => $this->config->getMIBCacheTableTrapObjName()), |
|
| 107 | - 'o.trap_id='.$id->id ) |
|
| 108 | - ->where("o.object_id = c.id"); |
|
| 100 | + ->from( |
|
| 101 | + array('c' => $this->config->getMIBCacheTableName()), |
|
| 102 | + array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum', |
|
| 103 | + 'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint', |
|
| 104 | + 'description' => 'c.description')) |
|
| 105 | + ->join( |
|
| 106 | + array('o' => $this->config->getMIBCacheTableTrapObjName()), |
|
| 107 | + 'o.trap_id='.$id->id ) |
|
| 108 | + ->where("o.object_id = c.id"); |
|
| 109 | 109 | $listObjects=$dbconn->fetchAll($query); |
| 110 | 110 | if ( count($listObjects)==0 ) return null; |
| 111 | 111 | |
@@ -123,12 +123,12 @@ discard block |
||
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** translate oid in MIB::Name |
| 126 | - * @param string $oid |
|
| 127 | - * @return array|null : return array with index (oid -> oid, mib -> mib name, name -> oid name, type -> oid type) |
|
| 128 | - */ |
|
| 126 | + * @param string $oid |
|
| 127 | + * @return array|null : return array with index (oid -> oid, mib -> mib name, name -> oid name, type -> oid type) |
|
| 128 | + */ |
|
| 129 | 129 | public function translateOID($oid) |
| 130 | 130 | { |
| 131 | - if (!preg_match('/^\./',$oid)) $oid = '.' . $oid; // Add a leading '.' |
|
| 131 | + if (!preg_match('/^\./',$oid)) $oid = '.' . $oid; // Add a leading '.' |
|
| 132 | 132 | $retArray=array('oid' => $oid, 'mib' => null, 'name'=>null,'type'=>null); |
| 133 | 133 | $dbconn = $this->db; |
| 134 | 134 | |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | ->from( |
| 137 | 137 | array('o' => $this->config->getMIBCacheTableName()), |
| 138 | 138 | array('mib'=>'o.mib','name' => 'o.name','type'=>'o.syntax', |
| 139 | - 'type_enum'=>'o.type_enum', 'description'=>'o.description')) |
|
| 139 | + 'type_enum'=>'o.type_enum', 'description'=>'o.description')) |
|
| 140 | 140 | ->where('o.oid=\''.$oid.'\''); |
| 141 | 141 | $object=$dbconn->fetchRow($query); |
| 142 | 142 | if ($object != null) |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | // Try to get oid name from snmptranslate |
| 153 | 153 | $matches=array(); |
| 154 | 154 | $translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs. |
| 155 | - ' '.$oid); |
|
| 155 | + ' '.$oid); |
|
| 156 | 156 | $ret_code=preg_match('/(.*)::(.*)/',$translate,$matches); |
| 157 | 157 | if ($ret_code===0 || $ret_code===false) { |
| 158 | 158 | return null; |
@@ -164,8 +164,8 @@ discard block |
||
| 164 | 164 | " | grep SYNTAX | sed 's/SYNTAX[[:blank:]]*//'"); |
| 165 | 165 | if (preg_match('/(.*)\{(.*)\}/',$translate,$matches)) |
| 166 | 166 | { |
| 167 | - $retArray['type']=$matches[1]; |
|
| 168 | - $retArray['type_enum']=$matches[2]; |
|
| 167 | + $retArray['type']=$matches[1]; |
|
| 168 | + $retArray['type_enum']=$matches[2]; |
|
| 169 | 169 | } |
| 170 | 170 | else |
| 171 | 171 | { |
@@ -229,25 +229,25 @@ discard block |
||
| 229 | 229 | */ |
| 230 | 230 | public function getTrapDetails($oid=null,$id=null) |
| 231 | 231 | { |
| 232 | - // Get trap id in DB |
|
| 233 | - if ($oid===null) |
|
| 234 | - { |
|
| 235 | - $where="c.id = '$id'"; |
|
| 236 | - } |
|
| 237 | - else |
|
| 238 | - { |
|
| 239 | - $where="c.oid = '$oid'"; |
|
| 240 | - } |
|
| 241 | - $query=$this->db->select() |
|
| 242 | - ->from( |
|
| 243 | - array('c' => $this->config->getMIBCacheTableName()), |
|
| 244 | - array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum', |
|
| 245 | - 'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint', |
|
| 246 | - 'description' => 'c.description')) |
|
| 247 | - ->where($where); |
|
| 248 | - $trap=$this->db->fetchRow($query); |
|
| 232 | + // Get trap id in DB |
|
| 233 | + if ($oid===null) |
|
| 234 | + { |
|
| 235 | + $where="c.id = '$id'"; |
|
| 236 | + } |
|
| 237 | + else |
|
| 238 | + { |
|
| 239 | + $where="c.oid = '$oid'"; |
|
| 240 | + } |
|
| 241 | + $query=$this->db->select() |
|
| 242 | + ->from( |
|
| 243 | + array('c' => $this->config->getMIBCacheTableName()), |
|
| 244 | + array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum', |
|
| 245 | + 'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint', |
|
| 246 | + 'description' => 'c.description')) |
|
| 247 | + ->where($where); |
|
| 248 | + $trap=$this->db->fetchRow($query); |
|
| 249 | 249 | |
| 250 | - return $trap; |
|
| 250 | + return $trap; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | } |
@@ -4,183 +4,183 @@ |
||
| 4 | 4 | |
| 5 | 5 | trait MibDatabase |
| 6 | 6 | { |
| 7 | - /** @var array $oidDesc MUST be overide by calling class */ |
|
| 8 | - protected $oidDesc; |
|
| 7 | + /** @var array $oidDesc MUST be overide by calling class */ |
|
| 8 | + protected $oidDesc; |
|
| 9 | 9 | |
| 10 | - /** @var array $dbOidIndex MUST be overide by calling class */ |
|
| 11 | - protected $dbOidIndex; |
|
| 10 | + /** @var array $dbOidIndex MUST be overide by calling class */ |
|
| 11 | + protected $dbOidIndex; |
|
| 12 | 12 | |
| 13 | - /** @return \Trapdirector\Logging */ |
|
| 14 | - abstract public function getLogging(); |
|
| 13 | + /** @return \Trapdirector\Logging */ |
|
| 14 | + abstract public function getLogging(); |
|
| 15 | 15 | |
| 16 | - /** @return \Trapdirector\Database */ |
|
| 17 | - abstract public function getTrapsDB(); |
|
| 16 | + /** @return \Trapdirector\Database */ |
|
| 17 | + abstract public function getTrapsDB(); |
|
| 18 | 18 | |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Update or add an OID to database uses $this->dbOidIndex for mem cache |
|
| 22 | - * and $this->oidDesc doe data |
|
| 23 | - * @return number : 0=unchanged, 1 = changed, 2=created |
|
| 24 | - */ |
|
| 25 | - public function update_oid() |
|
| 26 | - { |
|
| 27 | - $db_conn=$this->getTrapsDB()->db_connect_trap(); |
|
| 28 | - // Quote description. |
|
| 29 | - $this->oidDesc['description']=$db_conn->quote($this->oidDesc['description']); |
|
| 20 | + /** |
|
| 21 | + * Update or add an OID to database uses $this->dbOidIndex for mem cache |
|
| 22 | + * and $this->oidDesc doe data |
|
| 23 | + * @return number : 0=unchanged, 1 = changed, 2=created |
|
| 24 | + */ |
|
| 25 | + public function update_oid() |
|
| 26 | + { |
|
| 27 | + $db_conn=$this->getTrapsDB()->db_connect_trap(); |
|
| 28 | + // Quote description. |
|
| 29 | + $this->oidDesc['description']=$db_conn->quote($this->oidDesc['description']); |
|
| 30 | 30 | |
| 31 | - if (isset($this->dbOidIndex[$this->oidDesc['oid']])) |
|
| 32 | - { // oid exists in db, so update |
|
| 33 | - return $this->update_oid_update(); |
|
| 34 | - } |
|
| 35 | - // create new OID. |
|
| 36 | - return $this->update_oid_create(); |
|
| 31 | + if (isset($this->dbOidIndex[$this->oidDesc['oid']])) |
|
| 32 | + { // oid exists in db, so update |
|
| 33 | + return $this->update_oid_update(); |
|
| 34 | + } |
|
| 35 | + // create new OID. |
|
| 36 | + return $this->update_oid_create(); |
|
| 37 | 37 | |
| 38 | - } |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Update object in DB with object in dbOidIndex if name/mib/type has changed. |
|
| 42 | - * @return number : 0=unchanged, 1 = changed, 2=created |
|
| 43 | - */ |
|
| 44 | - private function update_oid_update() |
|
| 45 | - { |
|
| 40 | + /** |
|
| 41 | + * Update object in DB with object in dbOidIndex if name/mib/type has changed. |
|
| 42 | + * @return number : 0=unchanged, 1 = changed, 2=created |
|
| 43 | + */ |
|
| 44 | + private function update_oid_update() |
|
| 45 | + { |
|
| 46 | 46 | |
| 47 | - $db_conn=$this->getTrapsDB()->db_connect_trap(); |
|
| 47 | + $db_conn=$this->getTrapsDB()->db_connect_trap(); |
|
| 48 | 48 | |
| 49 | - if ($this->dbOidIndex[$this->oidDesc['oid']]['key'] == -1) |
|
| 50 | - { // newly created. |
|
| 51 | - return 0; |
|
| 52 | - } |
|
| 53 | - $oidIndex=$this->dbOidIndex[$this->oidDesc['oid']]['key']; // Get index in dbOidAll |
|
| 54 | - $dbOid=$this->dbOidAll[$oidIndex]; // Get array of element |
|
| 55 | - if ( $this->oidDesc['name'] != $dbOid['name'] || |
|
| 56 | - $this->oidDesc['mib'] != $dbOid['mib'] || |
|
| 57 | - $this->oidDesc['type'] !=$dbOid['type'] |
|
| 58 | - ) |
|
| 59 | - { // Do update |
|
| 60 | - $sql='UPDATE '.$this->getTrapsDB()->dbPrefix.'mib_cache SET '. |
|
| 61 | - 'name = :name , type = :type , mib = :mib , textual_convention = :tc , display_hint = :display_hint'. |
|
| 62 | - ', syntax = :syntax, type_enum = :type_enum, description = :description '. |
|
| 63 | - ' WHERE id= :id'; |
|
| 64 | - $sqlQuery=$db_conn->prepare($sql); |
|
| 49 | + if ($this->dbOidIndex[$this->oidDesc['oid']]['key'] == -1) |
|
| 50 | + { // newly created. |
|
| 51 | + return 0; |
|
| 52 | + } |
|
| 53 | + $oidIndex=$this->dbOidIndex[$this->oidDesc['oid']]['key']; // Get index in dbOidAll |
|
| 54 | + $dbOid=$this->dbOidAll[$oidIndex]; // Get array of element |
|
| 55 | + if ( $this->oidDesc['name'] != $dbOid['name'] || |
|
| 56 | + $this->oidDesc['mib'] != $dbOid['mib'] || |
|
| 57 | + $this->oidDesc['type'] !=$dbOid['type'] |
|
| 58 | + ) |
|
| 59 | + { // Do update |
|
| 60 | + $sql='UPDATE '.$this->getTrapsDB()->dbPrefix.'mib_cache SET '. |
|
| 61 | + 'name = :name , type = :type , mib = :mib , textual_convention = :tc , display_hint = :display_hint'. |
|
| 62 | + ', syntax = :syntax, type_enum = :type_enum, description = :description '. |
|
| 63 | + ' WHERE id= :id'; |
|
| 64 | + $sqlQuery=$db_conn->prepare($sql); |
|
| 65 | 65 | |
| 66 | - $sqlParam=array( |
|
| 67 | - ':name' => $this->oidDesc['name'], |
|
| 68 | - ':type' => $this->oidDesc['type'], |
|
| 69 | - ':mib' => $this->oidDesc['mib'], |
|
| 70 | - ':tc' => $this->oidDesc['textconv']??'null', |
|
| 71 | - ':display_hint' => $this->oidDesc['dispHint']??'null' , |
|
| 72 | - ':syntax' => $this->oidDesc['syntax']==null??'null', |
|
| 73 | - ':type_enum' => $this->oidDesc['type_enum']??'null', |
|
| 74 | - ':description' => $this->oidDesc['description']??'null', |
|
| 75 | - ':id' => $this->dbOidAll[$this->dbOidIndex[$this->oidDesc['oid']]['id']] |
|
| 76 | - ); |
|
| 66 | + $sqlParam=array( |
|
| 67 | + ':name' => $this->oidDesc['name'], |
|
| 68 | + ':type' => $this->oidDesc['type'], |
|
| 69 | + ':mib' => $this->oidDesc['mib'], |
|
| 70 | + ':tc' => $this->oidDesc['textconv']??'null', |
|
| 71 | + ':display_hint' => $this->oidDesc['dispHint']??'null' , |
|
| 72 | + ':syntax' => $this->oidDesc['syntax']==null??'null', |
|
| 73 | + ':type_enum' => $this->oidDesc['type_enum']??'null', |
|
| 74 | + ':description' => $this->oidDesc['description']??'null', |
|
| 75 | + ':id' => $this->dbOidAll[$this->dbOidIndex[$this->oidDesc['oid']]['id']] |
|
| 76 | + ); |
|
| 77 | 77 | |
| 78 | - if ($sqlQuery->execute($sqlParam) === false) { |
|
| 79 | - $this->getLogging()->log('Error in query : ' . $sql,ERROR,''); |
|
| 80 | - } |
|
| 81 | - $this->getLogging()->log('Trap updated : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG ); |
|
| 82 | - return 1; |
|
| 83 | - } |
|
| 84 | - else |
|
| 85 | - { |
|
| 86 | - $this->getLogging()->log('Trap unchanged : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG ); |
|
| 87 | - return 0; |
|
| 88 | - } |
|
| 89 | - } |
|
| 78 | + if ($sqlQuery->execute($sqlParam) === false) { |
|
| 79 | + $this->getLogging()->log('Error in query : ' . $sql,ERROR,''); |
|
| 80 | + } |
|
| 81 | + $this->getLogging()->log('Trap updated : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG ); |
|
| 82 | + return 1; |
|
| 83 | + } |
|
| 84 | + else |
|
| 85 | + { |
|
| 86 | + $this->getLogging()->log('Trap unchanged : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG ); |
|
| 87 | + return 0; |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Create object in DB with object in dbOidIndex |
|
| 93 | - * @return number : 0=unchanged, 1 = changed, 2=created |
|
| 94 | - */ |
|
| 95 | - private function update_oid_create() |
|
| 96 | - { |
|
| 97 | - // Insert data |
|
| 91 | + /** |
|
| 92 | + * Create object in DB with object in dbOidIndex |
|
| 93 | + * @return number : 0=unchanged, 1 = changed, 2=created |
|
| 94 | + */ |
|
| 95 | + private function update_oid_create() |
|
| 96 | + { |
|
| 97 | + // Insert data |
|
| 98 | 98 | |
| 99 | - $db_conn=$this->getTrapsDB()->db_connect_trap(); |
|
| 100 | - $sql='INSERT INTO '.$this->getTrapsDB()->dbPrefix.'mib_cache '. |
|
| 101 | - '(oid, name, type , mib, textual_convention, display_hint '. |
|
| 102 | - ', syntax, type_enum , description ) ' . |
|
| 103 | - 'values (:oid, :name , :type ,:mib ,:tc , :display_hint'. |
|
| 104 | - ', :syntax, :type_enum, :description )'; |
|
| 99 | + $db_conn=$this->getTrapsDB()->db_connect_trap(); |
|
| 100 | + $sql='INSERT INTO '.$this->getTrapsDB()->dbPrefix.'mib_cache '. |
|
| 101 | + '(oid, name, type , mib, textual_convention, display_hint '. |
|
| 102 | + ', syntax, type_enum , description ) ' . |
|
| 103 | + 'values (:oid, :name , :type ,:mib ,:tc , :display_hint'. |
|
| 104 | + ', :syntax, :type_enum, :description )'; |
|
| 105 | 105 | |
| 106 | - if ($this->getTrapsDB()->trapDBType == 'pgsql') $sql .= 'RETURNING id'; |
|
| 106 | + if ($this->getTrapsDB()->trapDBType == 'pgsql') $sql .= 'RETURNING id'; |
|
| 107 | 107 | |
| 108 | - $sqlQuery=$db_conn->prepare($sql); |
|
| 108 | + $sqlQuery=$db_conn->prepare($sql); |
|
| 109 | 109 | |
| 110 | - $sqlParam=array( |
|
| 111 | - ':oid' => $this->oidDesc['oid'], |
|
| 112 | - ':name' => $this->oidDesc['name'], |
|
| 113 | - ':type' => $this->oidDesc['type'], |
|
| 114 | - ':mib' => $this->oidDesc['mib'], |
|
| 115 | - ':tc' => $this->oidDesc['textconv']??'null', |
|
| 116 | - ':display_hint' => $this->oidDesc['dispHint']??'null', |
|
| 117 | - ':syntax' => $this->oidDesc['syntax']??'null', |
|
| 118 | - ':type_enum' => $this->oidDesc['type_enum']??'null', |
|
| 119 | - ':description' => $this->oidDesc['description']??'null' |
|
| 120 | - ); |
|
| 110 | + $sqlParam=array( |
|
| 111 | + ':oid' => $this->oidDesc['oid'], |
|
| 112 | + ':name' => $this->oidDesc['name'], |
|
| 113 | + ':type' => $this->oidDesc['type'], |
|
| 114 | + ':mib' => $this->oidDesc['mib'], |
|
| 115 | + ':tc' => $this->oidDesc['textconv']??'null', |
|
| 116 | + ':display_hint' => $this->oidDesc['dispHint']??'null', |
|
| 117 | + ':syntax' => $this->oidDesc['syntax']??'null', |
|
| 118 | + ':type_enum' => $this->oidDesc['type_enum']??'null', |
|
| 119 | + ':description' => $this->oidDesc['description']??'null' |
|
| 120 | + ); |
|
| 121 | 121 | |
| 122 | - if ($sqlQuery->execute($sqlParam) === false) { |
|
| 123 | - $this->getLogging()->log('Error in query : ' . $sql,1,''); |
|
| 124 | - } |
|
| 122 | + if ($sqlQuery->execute($sqlParam) === false) { |
|
| 123 | + $this->getLogging()->log('Error in query : ' . $sql,1,''); |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - switch ($this->getTrapsDB()->trapDBType) |
|
| 127 | - { |
|
| 128 | - case 'pgsql': |
|
| 129 | - // Get last id to insert oid/values in secondary table |
|
| 130 | - if (($inserted_id_ret=$sqlQuery->fetch(PDO::FETCH_ASSOC)) === false) { |
|
| 131 | - $this->getLogging()->log('Error getting id - pgsql - ',1,''); |
|
| 132 | - } |
|
| 133 | - if (! isset($inserted_id_ret['id'])) { |
|
| 134 | - $this->getLogging()->log('Error getting id - pgsql - empty.',ERROR); |
|
| 135 | - return 0; |
|
| 136 | - } |
|
| 137 | - $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id_ret['id']; |
|
| 138 | - break; |
|
| 139 | - case 'mysql': |
|
| 140 | - // Get last id to insert oid/values in secondary table |
|
| 141 | - $sql='SELECT LAST_INSERT_ID();'; |
|
| 142 | - if (($ret_code=$db_conn->query($sql)) === false) { |
|
| 143 | - $this->getLogging()->log('Erreur getting id - mysql - ',ERROR); |
|
| 144 | - return 0; |
|
| 145 | - } |
|
| 126 | + switch ($this->getTrapsDB()->trapDBType) |
|
| 127 | + { |
|
| 128 | + case 'pgsql': |
|
| 129 | + // Get last id to insert oid/values in secondary table |
|
| 130 | + if (($inserted_id_ret=$sqlQuery->fetch(PDO::FETCH_ASSOC)) === false) { |
|
| 131 | + $this->getLogging()->log('Error getting id - pgsql - ',1,''); |
|
| 132 | + } |
|
| 133 | + if (! isset($inserted_id_ret['id'])) { |
|
| 134 | + $this->getLogging()->log('Error getting id - pgsql - empty.',ERROR); |
|
| 135 | + return 0; |
|
| 136 | + } |
|
| 137 | + $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id_ret['id']; |
|
| 138 | + break; |
|
| 139 | + case 'mysql': |
|
| 140 | + // Get last id to insert oid/values in secondary table |
|
| 141 | + $sql='SELECT LAST_INSERT_ID();'; |
|
| 142 | + if (($ret_code=$db_conn->query($sql)) === false) { |
|
| 143 | + $this->getLogging()->log('Erreur getting id - mysql - ',ERROR); |
|
| 144 | + return 0; |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
|
| 148 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 149 | - $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id; |
|
| 150 | - break; |
|
| 151 | - default: |
|
| 152 | - $this->getLogging()->log('Error SQL type Unknown : '.$this->getTrapsDB()->trapDBType,ERROR); |
|
| 153 | - return 0; |
|
| 154 | - } |
|
| 147 | + $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
|
| 148 | + if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 149 | + $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id; |
|
| 150 | + break; |
|
| 151 | + default: |
|
| 152 | + $this->getLogging()->log('Error SQL type Unknown : '.$this->getTrapsDB()->trapDBType,ERROR); |
|
| 153 | + return 0; |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - // Set as newly created. |
|
| 157 | - $this->dbOidIndex[$this->oidDesc['oid']]['key']=-1; |
|
| 158 | - return 2; |
|
| 159 | - } |
|
| 156 | + // Set as newly created. |
|
| 157 | + $this->dbOidIndex[$this->oidDesc['oid']]['key']=-1; |
|
| 158 | + return 2; |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - /** |
|
| 162 | - * get all objects for a trap. |
|
| 163 | - * @param integer $trapId |
|
| 164 | - * @return array : array of cached objects |
|
| 165 | - */ |
|
| 166 | - private function cache_db_objects($trapId) |
|
| 167 | - { |
|
| 168 | - $dbObjects=array(); // cache of objects for trap in db |
|
| 169 | - $db_conn=$this->getTrapsDB()->db_connect_trap(); |
|
| 170 | - // Get all objects |
|
| 171 | - $sql='SELECT * FROM '.$this->getTrapsDB()->dbPrefix.'mib_cache_trap_object where trap_id='.$trapId.';'; |
|
| 172 | - $this->getLogging()->log('SQL query get all traps: '.$sql,DEBUG ); |
|
| 173 | - if (($ret_code=$db_conn->query($sql)) === false) { |
|
| 174 | - $this->getLogging()->log('No result in query : ' . $sql,1,''); |
|
| 175 | - } |
|
| 176 | - $dbObjectsRaw=$ret_code->fetchAll(); |
|
| 161 | + /** |
|
| 162 | + * get all objects for a trap. |
|
| 163 | + * @param integer $trapId |
|
| 164 | + * @return array : array of cached objects |
|
| 165 | + */ |
|
| 166 | + private function cache_db_objects($trapId) |
|
| 167 | + { |
|
| 168 | + $dbObjects=array(); // cache of objects for trap in db |
|
| 169 | + $db_conn=$this->getTrapsDB()->db_connect_trap(); |
|
| 170 | + // Get all objects |
|
| 171 | + $sql='SELECT * FROM '.$this->getTrapsDB()->dbPrefix.'mib_cache_trap_object where trap_id='.$trapId.';'; |
|
| 172 | + $this->getLogging()->log('SQL query get all traps: '.$sql,DEBUG ); |
|
| 173 | + if (($ret_code=$db_conn->query($sql)) === false) { |
|
| 174 | + $this->getLogging()->log('No result in query : ' . $sql,1,''); |
|
| 175 | + } |
|
| 176 | + $dbObjectsRaw=$ret_code->fetchAll(); |
|
| 177 | 177 | |
| 178 | - foreach ($dbObjectsRaw as $val) |
|
| 179 | - { |
|
| 180 | - $dbObjects[$val['object_id']]=1; |
|
| 181 | - } |
|
| 182 | - return $dbObjects; |
|
| 183 | - } |
|
| 178 | + foreach ($dbObjectsRaw as $val) |
|
| 179 | + { |
|
| 180 | + $dbObjects[$val['object_id']]=1; |
|
| 181 | + } |
|
| 182 | + return $dbObjects; |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | 185 | |
| 186 | 186 | } |
| 187 | 187 | \ No newline at end of file |
@@ -17,519 +17,519 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class Plugins |
| 19 | 19 | { |
| 20 | - /** Array of plugin objects. Keys ar plugin name |
|
| 21 | - * @var PluginTemplate[] $pluginsList Plugins array with name as index |
|
| 22 | - * $pluginsList[plugin name]['object'] : plugin object (NULL of not loaded) |
|
| 23 | - * $pluginsList[plugin name]['allOID'] : bool true if plugin catches all oid |
|
| 24 | - * $pluginsList[plugin name]['target'] : bool true if plugin can be trap processing target |
|
| 25 | - * $pluginsList[plugin name]['enabled'] : bool true if plugin is in enabled list |
|
| 26 | - **/ |
|
| 27 | - protected $pluginsList = array(); |
|
| 20 | + /** Array of plugin objects. Keys ar plugin name |
|
| 21 | + * @var PluginTemplate[] $pluginsList Plugins array with name as index |
|
| 22 | + * $pluginsList[plugin name]['object'] : plugin object (NULL of not loaded) |
|
| 23 | + * $pluginsList[plugin name]['allOID'] : bool true if plugin catches all oid |
|
| 24 | + * $pluginsList[plugin name]['target'] : bool true if plugin can be trap processing target |
|
| 25 | + * $pluginsList[plugin name]['enabled'] : bool true if plugin is in enabled list |
|
| 26 | + **/ |
|
| 27 | + protected $pluginsList = array(); |
|
| 28 | 28 | |
| 29 | - /** Array of functions names |
|
| 30 | - * @var array $functionList |
|
| 31 | - * $functionList[name]['plugin'] : Plugin name |
|
| 32 | - * $functionList[name]['function'] : Plugin function to call (null if plugin not loaded) |
|
| 33 | - */ |
|
| 34 | - protected $functionList=array(); |
|
| 29 | + /** Array of functions names |
|
| 30 | + * @var array $functionList |
|
| 31 | + * $functionList[name]['plugin'] : Plugin name |
|
| 32 | + * $functionList[name]['function'] : Plugin function to call (null if plugin not loaded) |
|
| 33 | + */ |
|
| 34 | + protected $functionList=array(); |
|
| 35 | 35 | |
| 36 | - /** @var string[] $enabledPlugins list of enabled plugins */ |
|
| 37 | - //public $enabledPlugins = array(); |
|
| 36 | + /** @var string[] $enabledPlugins list of enabled plugins */ |
|
| 37 | + //public $enabledPlugins = array(); |
|
| 38 | 38 | |
| 39 | 39 | |
| 40 | - /** @var Logging $logClass */ |
|
| 41 | - protected $logClass; |
|
| 40 | + /** @var Logging $logClass */ |
|
| 41 | + protected $logClass; |
|
| 42 | 42 | |
| 43 | - /** @var Trap $trapClass */ |
|
| 44 | - protected $trapClass; |
|
| 43 | + /** @var Trap $trapClass */ |
|
| 44 | + protected $trapClass; |
|
| 45 | 45 | |
| 46 | - /** @var string $pluginDir */ |
|
| 47 | - protected $pluginDir; |
|
| 46 | + /** @var string $pluginDir */ |
|
| 47 | + protected $pluginDir; |
|
| 48 | 48 | |
| 49 | - /** Setup class |
|
| 50 | - * @param Trap $logClass the top trap class |
|
| 51 | - * @param string $plugin_dir optional plugin directory |
|
| 52 | - * @throws \Exception |
|
| 53 | - */ |
|
| 54 | - function __construct(Trap $trapClass,string $pluginDir='') |
|
| 55 | - { |
|
| 56 | - if ($pluginDir == '') |
|
| 57 | - { |
|
| 58 | - $this->pluginDir=dirname(__DIR__).'/Plugins'; |
|
| 59 | - } |
|
| 60 | - else |
|
| 61 | - { |
|
| 62 | - $this->pluginDir=$pluginDir; |
|
| 63 | - } |
|
| 64 | - // Set and check Logging class |
|
| 65 | - $this->trapClass=$trapClass; |
|
| 66 | - if ($this->trapClass === null) |
|
| 67 | - { |
|
| 68 | - throw new Exception('Log class not loaded into trap class'); |
|
| 69 | - } |
|
| 70 | - $this->logClass=$trapClass->logging; |
|
| 71 | - if ($this->logClass === null) |
|
| 72 | - { |
|
| 73 | - throw new Exception('Log class not loaded into trap class'); |
|
| 74 | - } |
|
| 75 | - // check DB class and get plugins list. |
|
| 76 | - if ($this->trapClass->trapsDB === null) |
|
| 77 | - { |
|
| 78 | - throw new Exception('Database class not loaded into trap class'); |
|
| 79 | - } |
|
| 80 | - $this->loadEnabledPlugins(); |
|
| 81 | - } |
|
| 49 | + /** Setup class |
|
| 50 | + * @param Trap $logClass the top trap class |
|
| 51 | + * @param string $plugin_dir optional plugin directory |
|
| 52 | + * @throws \Exception |
|
| 53 | + */ |
|
| 54 | + function __construct(Trap $trapClass,string $pluginDir='') |
|
| 55 | + { |
|
| 56 | + if ($pluginDir == '') |
|
| 57 | + { |
|
| 58 | + $this->pluginDir=dirname(__DIR__).'/Plugins'; |
|
| 59 | + } |
|
| 60 | + else |
|
| 61 | + { |
|
| 62 | + $this->pluginDir=$pluginDir; |
|
| 63 | + } |
|
| 64 | + // Set and check Logging class |
|
| 65 | + $this->trapClass=$trapClass; |
|
| 66 | + if ($this->trapClass === null) |
|
| 67 | + { |
|
| 68 | + throw new Exception('Log class not loaded into trap class'); |
|
| 69 | + } |
|
| 70 | + $this->logClass=$trapClass->logging; |
|
| 71 | + if ($this->logClass === null) |
|
| 72 | + { |
|
| 73 | + throw new Exception('Log class not loaded into trap class'); |
|
| 74 | + } |
|
| 75 | + // check DB class and get plugins list. |
|
| 76 | + if ($this->trapClass->trapsDB === null) |
|
| 77 | + { |
|
| 78 | + throw new Exception('Database class not loaded into trap class'); |
|
| 79 | + } |
|
| 80 | + $this->loadEnabledPlugins(); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Load enabled plugins from database config table. |
|
| 86 | - * Fills enabledPlugins and functionList properties |
|
| 87 | - * @throws \Exception |
|
| 88 | - */ |
|
| 89 | - private function loadEnabledPlugins() |
|
| 90 | - { |
|
| 91 | - $PluginList = $this->trapClass->trapsDB->getDBConfig('enabled_plugins'); |
|
| 84 | + /** |
|
| 85 | + * Load enabled plugins from database config table. |
|
| 86 | + * Fills enabledPlugins and functionList properties |
|
| 87 | + * @throws \Exception |
|
| 88 | + */ |
|
| 89 | + private function loadEnabledPlugins() |
|
| 90 | + { |
|
| 91 | + $PluginList = $this->trapClass->trapsDB->getDBConfig('enabled_plugins'); |
|
| 92 | 92 | |
| 93 | - if ($PluginList === null || $PluginList == '') |
|
| 94 | - { |
|
| 95 | - $this->logClass->log('No enabled plugins',DEBUG); |
|
| 96 | - return; |
|
| 97 | - } |
|
| 98 | - else |
|
| 99 | - { // Saved config : <plugin name>;<Catch all OID ? 1|0>;<Trap target ? 1|0>;<func 1 name>|<func 2 name>... ,<plugin2 name>.... |
|
| 100 | - $this->logClass->log('Enabled plugins = '.$PluginList,DEBUG); |
|
| 93 | + if ($PluginList === null || $PluginList == '') |
|
| 94 | + { |
|
| 95 | + $this->logClass->log('No enabled plugins',DEBUG); |
|
| 96 | + return; |
|
| 97 | + } |
|
| 98 | + else |
|
| 99 | + { // Saved config : <plugin name>;<Catch all OID ? 1|0>;<Trap target ? 1|0>;<func 1 name>|<func 2 name>... ,<plugin2 name>.... |
|
| 100 | + $this->logClass->log('Enabled plugins = '.$PluginList,DEBUG); |
|
| 101 | 101 | |
| 102 | - $pluginArray = explode(',', $PluginList); |
|
| 103 | - foreach ($pluginArray as $pluginElmt) |
|
| 104 | - { |
|
| 105 | - $pluginElmt = explode(';',$pluginElmt); |
|
| 106 | - if ($pluginElmt === false || count($pluginElmt) != 4) |
|
| 107 | - { |
|
| 108 | - throw new \Exception('Invalid plugin configuration : '. $PluginList ); |
|
| 109 | - } |
|
| 110 | - $pluginName=$pluginElmt[0]; |
|
| 102 | + $pluginArray = explode(',', $PluginList); |
|
| 103 | + foreach ($pluginArray as $pluginElmt) |
|
| 104 | + { |
|
| 105 | + $pluginElmt = explode(';',$pluginElmt); |
|
| 106 | + if ($pluginElmt === false || count($pluginElmt) != 4) |
|
| 107 | + { |
|
| 108 | + throw new \Exception('Invalid plugin configuration : '. $PluginList ); |
|
| 109 | + } |
|
| 110 | + $pluginName=$pluginElmt[0]; |
|
| 111 | 111 | |
| 112 | - $pluginListElmt = array(); |
|
| 113 | - $pluginListElmt['object'] = null; // class not loaded |
|
| 114 | - $pluginListElmt['allOID'] = ($pluginElmt[1]=='1') ? true : false; |
|
| 115 | - $pluginListElmt['target'] = ($pluginElmt[2]=='1') ? true : false; |
|
| 116 | - $pluginListElmt['enabled'] = true; |
|
| 112 | + $pluginListElmt = array(); |
|
| 113 | + $pluginListElmt['object'] = null; // class not loaded |
|
| 114 | + $pluginListElmt['allOID'] = ($pluginElmt[1]=='1') ? true : false; |
|
| 115 | + $pluginListElmt['target'] = ($pluginElmt[2]=='1') ? true : false; |
|
| 116 | + $pluginListElmt['enabled'] = true; |
|
| 117 | 117 | |
| 118 | - $this->pluginsList[$pluginName] = $pluginListElmt; |
|
| 118 | + $this->pluginsList[$pluginName] = $pluginListElmt; |
|
| 119 | 119 | |
| 120 | - // deal with plugin functions |
|
| 121 | - $pluginFunctions = explode('|',$pluginElmt[3]); |
|
| 122 | - if ($pluginFunctions !== false) |
|
| 123 | - { |
|
| 124 | - foreach ($pluginFunctions as $function) |
|
| 125 | - { |
|
| 126 | - $this->functionList[$function] = array( |
|
| 127 | - 'plugin' => $pluginName, |
|
| 128 | - 'function' => null |
|
| 129 | - ); |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - } |
|
| 120 | + // deal with plugin functions |
|
| 121 | + $pluginFunctions = explode('|',$pluginElmt[3]); |
|
| 122 | + if ($pluginFunctions !== false) |
|
| 123 | + { |
|
| 124 | + foreach ($pluginFunctions as $function) |
|
| 125 | + { |
|
| 126 | + $this->functionList[$function] = array( |
|
| 127 | + 'plugin' => $pluginName, |
|
| 128 | + 'function' => null |
|
| 129 | + ); |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | - } |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - } |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | - /** |
|
| 139 | - * Save enabled plugin array in DB config |
|
| 140 | - * @return bool true if OK, or false (error logged by DB Class) |
|
| 141 | - */ |
|
| 142 | - private function saveEnabledPlugins() |
|
| 143 | - { |
|
| 144 | - $saveString=''; |
|
| 145 | - foreach ($this->pluginsList as $name => $value) |
|
| 146 | - { |
|
| 147 | - if ($value['enabled'] == false) |
|
| 148 | - { |
|
| 149 | - continue; |
|
| 150 | - } |
|
| 151 | - $functionString=''; |
|
| 152 | - foreach ($this->functionList as $fName => $fvalue) |
|
| 153 | - { |
|
| 154 | - if ($fvalue['plugin'] != $name) |
|
| 155 | - { |
|
| 156 | - continue; |
|
| 157 | - } |
|
| 158 | - $functionString .= ($functionString == '') ? '' : '|'; // add separator if not empty |
|
| 159 | - $functionString .= $fName; |
|
| 160 | - } |
|
| 161 | - $saveString .= ($saveString == '')?'':',' ; |
|
| 138 | + /** |
|
| 139 | + * Save enabled plugin array in DB config |
|
| 140 | + * @return bool true if OK, or false (error logged by DB Class) |
|
| 141 | + */ |
|
| 142 | + private function saveEnabledPlugins() |
|
| 143 | + { |
|
| 144 | + $saveString=''; |
|
| 145 | + foreach ($this->pluginsList as $name => $value) |
|
| 146 | + { |
|
| 147 | + if ($value['enabled'] == false) |
|
| 148 | + { |
|
| 149 | + continue; |
|
| 150 | + } |
|
| 151 | + $functionString=''; |
|
| 152 | + foreach ($this->functionList as $fName => $fvalue) |
|
| 153 | + { |
|
| 154 | + if ($fvalue['plugin'] != $name) |
|
| 155 | + { |
|
| 156 | + continue; |
|
| 157 | + } |
|
| 158 | + $functionString .= ($functionString == '') ? '' : '|'; // add separator if not empty |
|
| 159 | + $functionString .= $fName; |
|
| 160 | + } |
|
| 161 | + $saveString .= ($saveString == '')?'':',' ; |
|
| 162 | 162 | |
| 163 | - $allOID = ($value['allOID'] === true) ? 1 : 0; |
|
| 164 | - $target = ($value['target'] === true) ? 1 : 0; |
|
| 165 | - $saveString .= $name . ';' . $allOID . ';' . $target . ';' . $functionString ; |
|
| 166 | - } |
|
| 167 | - $this->logClass->log('Saving : ' . $saveString,DEBUG); |
|
| 168 | - return $this->trapClass->trapsDB->setDBConfig('enabled_plugins', $saveString); |
|
| 169 | - } |
|
| 163 | + $allOID = ($value['allOID'] === true) ? 1 : 0; |
|
| 164 | + $target = ($value['target'] === true) ? 1 : 0; |
|
| 165 | + $saveString .= $name . ';' . $allOID . ';' . $target . ';' . $functionString ; |
|
| 166 | + } |
|
| 167 | + $this->logClass->log('Saving : ' . $saveString,DEBUG); |
|
| 168 | + return $this->trapClass->trapsDB->setDBConfig('enabled_plugins', $saveString); |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - /** Get enabled plugin list by name |
|
| 172 | - * @return array |
|
| 173 | - */ |
|
| 174 | - public function getEnabledPlugins() : array |
|
| 175 | - { |
|
| 176 | - $retArray=array(); |
|
| 177 | - foreach ($this->pluginsList as $name => $value) |
|
| 178 | - { |
|
| 179 | - if ($value['enabled'] == true) |
|
| 180 | - { |
|
| 181 | - array_push($retArray,$name); |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - return $retArray; |
|
| 185 | - } |
|
| 171 | + /** Get enabled plugin list by name |
|
| 172 | + * @return array |
|
| 173 | + */ |
|
| 174 | + public function getEnabledPlugins() : array |
|
| 175 | + { |
|
| 176 | + $retArray=array(); |
|
| 177 | + foreach ($this->pluginsList as $name => $value) |
|
| 178 | + { |
|
| 179 | + if ($value['enabled'] == true) |
|
| 180 | + { |
|
| 181 | + array_push($retArray,$name); |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + return $retArray; |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - /** Enable plugin (enabling an enabled plugin is OK, same for disabled). |
|
| 188 | - * and save in DB config |
|
| 189 | - * @param string $pluginName |
|
| 190 | - * @param bool $enabled true to enable, false to disable |
|
| 191 | - * @return bool true if OK, or false (error logged) |
|
| 192 | - */ |
|
| 193 | - public function enablePlugin(string $pluginName,bool $enabled) |
|
| 194 | - { |
|
| 195 | - if ($enabled === false) |
|
| 196 | - { |
|
| 197 | - // If plugin is defined set to disable |
|
| 198 | - if ( isset($this->pluginsList[$pluginName])) |
|
| 199 | - { |
|
| 200 | - $this->pluginsList[$pluginName]['enabled'] = false; |
|
| 201 | - } |
|
| 202 | - return $this->saveEnabledPlugins(); |
|
| 203 | - } |
|
| 204 | - // Check if plugin is loaded / exists |
|
| 205 | - if ( ! isset($this->pluginsList[$pluginName]) || |
|
| 206 | - $this->pluginsList[$pluginName]['object'] === null) |
|
| 207 | - { |
|
| 208 | - try { |
|
| 209 | - $this->registerPlugin($pluginName); |
|
| 210 | - } catch (Exception $e) { |
|
| 211 | - $this->logClass->log('Cannot enable plugin : ' . $e->getMessage(),WARN); |
|
| 212 | - return false; |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - $this->pluginsList[$pluginName]['enabled'] = true; |
|
| 216 | - // save in DB and return |
|
| 217 | - return $this->saveEnabledPlugins(); |
|
| 218 | - } |
|
| 187 | + /** Enable plugin (enabling an enabled plugin is OK, same for disabled). |
|
| 188 | + * and save in DB config |
|
| 189 | + * @param string $pluginName |
|
| 190 | + * @param bool $enabled true to enable, false to disable |
|
| 191 | + * @return bool true if OK, or false (error logged) |
|
| 192 | + */ |
|
| 193 | + public function enablePlugin(string $pluginName,bool $enabled) |
|
| 194 | + { |
|
| 195 | + if ($enabled === false) |
|
| 196 | + { |
|
| 197 | + // If plugin is defined set to disable |
|
| 198 | + if ( isset($this->pluginsList[$pluginName])) |
|
| 199 | + { |
|
| 200 | + $this->pluginsList[$pluginName]['enabled'] = false; |
|
| 201 | + } |
|
| 202 | + return $this->saveEnabledPlugins(); |
|
| 203 | + } |
|
| 204 | + // Check if plugin is loaded / exists |
|
| 205 | + if ( ! isset($this->pluginsList[$pluginName]) || |
|
| 206 | + $this->pluginsList[$pluginName]['object'] === null) |
|
| 207 | + { |
|
| 208 | + try { |
|
| 209 | + $this->registerPlugin($pluginName); |
|
| 210 | + } catch (Exception $e) { |
|
| 211 | + $this->logClass->log('Cannot enable plugin : ' . $e->getMessage(),WARN); |
|
| 212 | + return false; |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + $this->pluginsList[$pluginName]['enabled'] = true; |
|
| 216 | + // save in DB and return |
|
| 217 | + return $this->saveEnabledPlugins(); |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | - /** |
|
| 221 | - * Destroy plugin objects and reload them with new enabled list. |
|
| 222 | - * TODO : Code this function (ref DAEMON_MODE) |
|
| 223 | - */ |
|
| 224 | - public function reloadAllPlugins() |
|
| 225 | - { |
|
| 226 | - return; |
|
| 227 | - } |
|
| 220 | + /** |
|
| 221 | + * Destroy plugin objects and reload them with new enabled list. |
|
| 222 | + * TODO : Code this function (ref DAEMON_MODE) |
|
| 223 | + */ |
|
| 224 | + public function reloadAllPlugins() |
|
| 225 | + { |
|
| 226 | + return; |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - /** Load plugin by name. Create entry if not in $pluginsList |
|
| 230 | - * @param string $pluginName Plugin name to load |
|
| 231 | - * @return bool true if created, false if already loaded |
|
| 232 | - * @throws Exception on error loading plugin |
|
| 233 | - */ |
|
| 234 | - public function registerPlugin(string $pluginName) |
|
| 235 | - { |
|
| 236 | - if ( ! isset($this->pluginsList[$pluginName]) ) // Plugin isn't enable, create entry |
|
| 237 | - { |
|
| 238 | - $pluginListElmt = array(); |
|
| 239 | - $pluginListElmt['object'] = null; // class not loaded |
|
| 240 | - $pluginListElmt['enabled'] = false; |
|
| 241 | - $this->pluginsList[$pluginName] = $pluginListElmt; |
|
| 242 | - } |
|
| 229 | + /** Load plugin by name. Create entry if not in $pluginsList |
|
| 230 | + * @param string $pluginName Plugin name to load |
|
| 231 | + * @return bool true if created, false if already loaded |
|
| 232 | + * @throws Exception on error loading plugin |
|
| 233 | + */ |
|
| 234 | + public function registerPlugin(string $pluginName) |
|
| 235 | + { |
|
| 236 | + if ( ! isset($this->pluginsList[$pluginName]) ) // Plugin isn't enable, create entry |
|
| 237 | + { |
|
| 238 | + $pluginListElmt = array(); |
|
| 239 | + $pluginListElmt['object'] = null; // class not loaded |
|
| 240 | + $pluginListElmt['enabled'] = false; |
|
| 241 | + $this->pluginsList[$pluginName] = $pluginListElmt; |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - if ($this->pluginsList[$pluginName]['object'] !== null) |
|
| 245 | - { |
|
| 246 | - return false; |
|
| 247 | - } |
|
| 248 | - try { |
|
| 249 | - // Include plugin file |
|
| 250 | - include_once($this->pluginDir.'/' . $pluginName . '.php'); |
|
| 244 | + if ($this->pluginsList[$pluginName]['object'] !== null) |
|
| 245 | + { |
|
| 246 | + return false; |
|
| 247 | + } |
|
| 248 | + try { |
|
| 249 | + // Include plugin file |
|
| 250 | + include_once($this->pluginDir.'/' . $pluginName . '.php'); |
|
| 251 | 251 | |
| 252 | - // Create full class name with namespace |
|
| 253 | - $pluginClassName = __NAMESPACE__ . '\\Plugins\\' . $pluginName; |
|
| 252 | + // Create full class name with namespace |
|
| 253 | + $pluginClassName = __NAMESPACE__ . '\\Plugins\\' . $pluginName; |
|
| 254 | 254 | |
| 255 | - // Create class |
|
| 256 | - $newClass = new $pluginClassName(); |
|
| 255 | + // Create class |
|
| 256 | + $newClass = new $pluginClassName(); |
|
| 257 | 257 | |
| 258 | - // Set logging |
|
| 259 | - $newClass->setLoggingClass($this->logClass); |
|
| 258 | + // Set logging |
|
| 259 | + $newClass->setLoggingClass($this->logClass); |
|
| 260 | 260 | |
| 261 | - // Add in plugin array |
|
| 262 | - $this->pluginsList[$pluginName]['object']=$newClass; |
|
| 263 | - $this->pluginsList[$pluginName]['allOID']=$newClass->catchAllTraps; |
|
| 264 | - $this->pluginsList[$pluginName]['target']=$newClass->processTraps; |
|
| 261 | + // Add in plugin array |
|
| 262 | + $this->pluginsList[$pluginName]['object']=$newClass; |
|
| 263 | + $this->pluginsList[$pluginName]['allOID']=$newClass->catchAllTraps; |
|
| 264 | + $this->pluginsList[$pluginName]['target']=$newClass->processTraps; |
|
| 265 | 265 | |
| 266 | - // Delete old functions |
|
| 267 | - foreach ($this->functionList as $fname => $fvalue) |
|
| 268 | - { |
|
| 269 | - if ($fvalue['plugin'] == $pluginName) |
|
| 270 | - { |
|
| 271 | - unset($this->functionList[$fname]); |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - // Add functions |
|
| 275 | - foreach ($newClass->functions as $fname => $function) |
|
| 276 | - { |
|
| 277 | - if (isset($this->functionList[$fname])) |
|
| 278 | - { |
|
| 279 | - if ($this->functionList[$fname]['plugin'] != $pluginName ) |
|
| 280 | - { |
|
| 281 | - throw new Exception('Duplicate function name '.$fname . ' in ' |
|
| 282 | - . $pluginName . ' and ' . $this->functionList[$fname]['plugin']); |
|
| 283 | - } |
|
| 266 | + // Delete old functions |
|
| 267 | + foreach ($this->functionList as $fname => $fvalue) |
|
| 268 | + { |
|
| 269 | + if ($fvalue['plugin'] == $pluginName) |
|
| 270 | + { |
|
| 271 | + unset($this->functionList[$fname]); |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + // Add functions |
|
| 275 | + foreach ($newClass->functions as $fname => $function) |
|
| 276 | + { |
|
| 277 | + if (isset($this->functionList[$fname])) |
|
| 278 | + { |
|
| 279 | + if ($this->functionList[$fname]['plugin'] != $pluginName ) |
|
| 280 | + { |
|
| 281 | + throw new Exception('Duplicate function name '.$fname . ' in ' |
|
| 282 | + . $pluginName . ' and ' . $this->functionList[$fname]['plugin']); |
|
| 283 | + } |
|
| 284 | 284 | |
| 285 | - } |
|
| 286 | - else |
|
| 287 | - { |
|
| 288 | - $this->functionList[$fname]=array(); |
|
| 289 | - $this->functionList[$fname]['plugin'] = $pluginName; |
|
| 290 | - } |
|
| 291 | - $this->functionList[$fname]['function']=$function['function']; |
|
| 292 | - } |
|
| 293 | - $this->logClass->log('Registered plugin '.$pluginName,DEBUG); |
|
| 285 | + } |
|
| 286 | + else |
|
| 287 | + { |
|
| 288 | + $this->functionList[$fname]=array(); |
|
| 289 | + $this->functionList[$fname]['plugin'] = $pluginName; |
|
| 290 | + } |
|
| 291 | + $this->functionList[$fname]['function']=$function['function']; |
|
| 292 | + } |
|
| 293 | + $this->logClass->log('Registered plugin '.$pluginName,DEBUG); |
|
| 294 | 294 | |
| 295 | - } catch (Exception $e) { |
|
| 296 | - unset($this->pluginsList[$pluginName]); |
|
| 297 | - $errorMessage = "Error registering plugin $pluginName : ".$e->getMessage(); |
|
| 298 | - $this->logClass->log($errorMessage,WARN); |
|
| 299 | - // Disable the plugin |
|
| 300 | - $this->enablePlugin($pluginName, false); |
|
| 301 | - throw new \Exception($errorMessage); |
|
| 302 | - } catch (Throwable $t) { |
|
| 303 | - unset($this->pluginsList[$pluginName]); |
|
| 304 | - $errorMessage = $t->getMessage() . ' in file ' . $t->getFile() . ' line ' . $t->getLine(); |
|
| 305 | - $this->logClass->log($errorMessage,WARN); |
|
| 306 | - // Disable the plugin |
|
| 307 | - $this->enablePlugin($pluginName, false); |
|
| 308 | - throw new \Exception($errorMessage); |
|
| 309 | - } |
|
| 310 | - return true; |
|
| 311 | - } |
|
| 295 | + } catch (Exception $e) { |
|
| 296 | + unset($this->pluginsList[$pluginName]); |
|
| 297 | + $errorMessage = "Error registering plugin $pluginName : ".$e->getMessage(); |
|
| 298 | + $this->logClass->log($errorMessage,WARN); |
|
| 299 | + // Disable the plugin |
|
| 300 | + $this->enablePlugin($pluginName, false); |
|
| 301 | + throw new \Exception($errorMessage); |
|
| 302 | + } catch (Throwable $t) { |
|
| 303 | + unset($this->pluginsList[$pluginName]); |
|
| 304 | + $errorMessage = $t->getMessage() . ' in file ' . $t->getFile() . ' line ' . $t->getLine(); |
|
| 305 | + $this->logClass->log($errorMessage,WARN); |
|
| 306 | + // Disable the plugin |
|
| 307 | + $this->enablePlugin($pluginName, false); |
|
| 308 | + throw new \Exception($errorMessage); |
|
| 309 | + } |
|
| 310 | + return true; |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | - /** Registers all plugins (check=false) or only those with name present in array (check=true) |
|
| 314 | - * @param bool $checkEnabled Check if plugin is enabled before loading it |
|
| 315 | - * @return string Errors encountered while registering plugins |
|
| 316 | - */ |
|
| 317 | - public function registerAllPlugins(bool $checkEnabled=true) |
|
| 318 | - { |
|
| 319 | - $retDisplay=''; |
|
| 320 | - // First load enabled plugins |
|
| 321 | - foreach (array_keys($this->pluginsList) as $pluginName) |
|
| 322 | - { |
|
| 323 | - try { |
|
| 324 | - $this->registerPlugin($pluginName); |
|
| 325 | - } catch (Exception $e) { |
|
| 326 | - $retDisplay .= $e->getMessage() . ' / '; |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - if ($checkEnabled === false) // Load all php files in plugin dir |
|
| 330 | - { |
|
| 331 | - foreach (glob($this->pluginDir."/*.php") as $filename) |
|
| 332 | - { |
|
| 333 | - $pluginName=basename($filename,'.php'); |
|
| 334 | - if (!preg_match('/^[a-zA-Z0-9]+$/',$pluginName)) |
|
| 335 | - { |
|
| 336 | - $this->logClass->log("Invalid plugin name : ".$pluginName, WARN); |
|
| 337 | - $retDisplay .= "Invalid plugin name : ".$pluginName . " / "; |
|
| 338 | - break; |
|
| 339 | - } |
|
| 340 | - try { // Already registerd plugin will simply return false |
|
| 341 | - $this->registerPlugin($pluginName); |
|
| 342 | - } catch (Exception $e) { |
|
| 343 | - $retDisplay .= $e->getMessage() . ' / '; |
|
| 344 | - } |
|
| 345 | - } |
|
| 346 | - } |
|
| 313 | + /** Registers all plugins (check=false) or only those with name present in array (check=true) |
|
| 314 | + * @param bool $checkEnabled Check if plugin is enabled before loading it |
|
| 315 | + * @return string Errors encountered while registering plugins |
|
| 316 | + */ |
|
| 317 | + public function registerAllPlugins(bool $checkEnabled=true) |
|
| 318 | + { |
|
| 319 | + $retDisplay=''; |
|
| 320 | + // First load enabled plugins |
|
| 321 | + foreach (array_keys($this->pluginsList) as $pluginName) |
|
| 322 | + { |
|
| 323 | + try { |
|
| 324 | + $this->registerPlugin($pluginName); |
|
| 325 | + } catch (Exception $e) { |
|
| 326 | + $retDisplay .= $e->getMessage() . ' / '; |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + if ($checkEnabled === false) // Load all php files in plugin dir |
|
| 330 | + { |
|
| 331 | + foreach (glob($this->pluginDir."/*.php") as $filename) |
|
| 332 | + { |
|
| 333 | + $pluginName=basename($filename,'.php'); |
|
| 334 | + if (!preg_match('/^[a-zA-Z0-9]+$/',$pluginName)) |
|
| 335 | + { |
|
| 336 | + $this->logClass->log("Invalid plugin name : ".$pluginName, WARN); |
|
| 337 | + $retDisplay .= "Invalid plugin name : ".$pluginName . " / "; |
|
| 338 | + break; |
|
| 339 | + } |
|
| 340 | + try { // Already registerd plugin will simply return false |
|
| 341 | + $this->registerPlugin($pluginName); |
|
| 342 | + } catch (Exception $e) { |
|
| 343 | + $retDisplay .= $e->getMessage() . ' / '; |
|
| 344 | + } |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | 347 | |
| 348 | - if ($retDisplay == '') |
|
| 349 | - { |
|
| 350 | - return 'All plugins loaded OK'; |
|
| 351 | - } |
|
| 352 | - else |
|
| 353 | - { |
|
| 354 | - return $retDisplay; |
|
| 355 | - } |
|
| 356 | - } |
|
| 348 | + if ($retDisplay == '') |
|
| 349 | + { |
|
| 350 | + return 'All plugins loaded OK'; |
|
| 351 | + } |
|
| 352 | + else |
|
| 353 | + { |
|
| 354 | + return $retDisplay; |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | 357 | |
| 358 | - /** |
|
| 359 | - * Returns array of name of loaded plugins |
|
| 360 | - * @return array |
|
| 361 | - */ |
|
| 362 | - public function pluginList() : array |
|
| 363 | - { |
|
| 364 | - return array_keys($this->pluginsList); |
|
| 365 | - } |
|
| 358 | + /** |
|
| 359 | + * Returns array of name of loaded plugins |
|
| 360 | + * @return array |
|
| 361 | + */ |
|
| 362 | + public function pluginList() : array |
|
| 363 | + { |
|
| 364 | + return array_keys($this->pluginsList); |
|
| 365 | + } |
|
| 366 | 366 | |
| 367 | - /** |
|
| 368 | - * Get plugin details |
|
| 369 | - * @param string $name name of plugins |
|
| 370 | - * @return boolean|stdClass result as stdClass or false if plugin not found. |
|
| 371 | - * @throws \Exception if registering is not possible |
|
| 372 | - */ |
|
| 373 | - public function pluginDetails(string $name) |
|
| 374 | - { |
|
| 375 | - if (!array_key_exists($name, $this->pluginsList)) |
|
| 376 | - { |
|
| 377 | - return false; |
|
| 378 | - } |
|
| 379 | - if ($this->pluginsList[$name]['object'] === null) |
|
| 380 | - { |
|
| 381 | - $this->registerPlugin($name); // can throw exception handled by caller |
|
| 382 | - } |
|
| 383 | - $retObj = new stdClass(); |
|
| 384 | - $retObj->name = $name; |
|
| 385 | - $retObj->catchAllTraps = $this->pluginsList[$name]['allOID']; |
|
| 386 | - $retObj->processTraps = $this->pluginsList[$name]['target']; |
|
| 387 | - $retObj->description = $this->pluginsList[$name]['object']->description; |
|
| 388 | - $functions=array(); |
|
| 389 | - foreach ($this->functionList as $fName => $func) |
|
| 390 | - { |
|
| 391 | - if ($func['plugin'] == $name) |
|
| 392 | - { |
|
| 393 | - array_push($functions,$fName); |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - $retObj->funcArray=$functions; |
|
| 397 | - return $retObj; |
|
| 398 | - } |
|
| 367 | + /** |
|
| 368 | + * Get plugin details |
|
| 369 | + * @param string $name name of plugins |
|
| 370 | + * @return boolean|stdClass result as stdClass or false if plugin not found. |
|
| 371 | + * @throws \Exception if registering is not possible |
|
| 372 | + */ |
|
| 373 | + public function pluginDetails(string $name) |
|
| 374 | + { |
|
| 375 | + if (!array_key_exists($name, $this->pluginsList)) |
|
| 376 | + { |
|
| 377 | + return false; |
|
| 378 | + } |
|
| 379 | + if ($this->pluginsList[$name]['object'] === null) |
|
| 380 | + { |
|
| 381 | + $this->registerPlugin($name); // can throw exception handled by caller |
|
| 382 | + } |
|
| 383 | + $retObj = new stdClass(); |
|
| 384 | + $retObj->name = $name; |
|
| 385 | + $retObj->catchAllTraps = $this->pluginsList[$name]['allOID']; |
|
| 386 | + $retObj->processTraps = $this->pluginsList[$name]['target']; |
|
| 387 | + $retObj->description = $this->pluginsList[$name]['object']->description; |
|
| 388 | + $functions=array(); |
|
| 389 | + foreach ($this->functionList as $fName => $func) |
|
| 390 | + { |
|
| 391 | + if ($func['plugin'] == $name) |
|
| 392 | + { |
|
| 393 | + array_push($functions,$fName); |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + $retObj->funcArray=$functions; |
|
| 397 | + return $retObj; |
|
| 398 | + } |
|
| 399 | 399 | |
| 400 | - /** |
|
| 401 | - * Get plugin name from function name |
|
| 402 | - * @param string $funcName |
|
| 403 | - * @param string $pluginName |
|
| 404 | - * @return boolean returns plugin object of false; |
|
| 405 | - */ |
|
| 406 | - public function getFunction($funcName,&$pluginName) |
|
| 407 | - { |
|
| 408 | - if (! isset($this->functionList[$funcName]) ) |
|
| 409 | - { |
|
| 410 | - return false; |
|
| 411 | - } |
|
| 412 | - $pluginName = $this->functionList[$funcName]['plugin']; |
|
| 413 | - return true; |
|
| 414 | - } |
|
| 400 | + /** |
|
| 401 | + * Get plugin name from function name |
|
| 402 | + * @param string $funcName |
|
| 403 | + * @param string $pluginName |
|
| 404 | + * @return boolean returns plugin object of false; |
|
| 405 | + */ |
|
| 406 | + public function getFunction($funcName,&$pluginName) |
|
| 407 | + { |
|
| 408 | + if (! isset($this->functionList[$funcName]) ) |
|
| 409 | + { |
|
| 410 | + return false; |
|
| 411 | + } |
|
| 412 | + $pluginName = $this->functionList[$funcName]['plugin']; |
|
| 413 | + return true; |
|
| 414 | + } |
|
| 415 | 415 | |
| 416 | - /** |
|
| 417 | - * Get functions params and description |
|
| 418 | - * @param string $funcName |
|
| 419 | - * @return boolean|stdClass false if not found or object (name,params,description) |
|
| 420 | - * @throws \Exception if registering is not possible |
|
| 421 | - */ |
|
| 422 | - public function getFunctionDetails($funcName) |
|
| 423 | - { |
|
| 424 | - if (! isset($this->functionList[$funcName]) ) |
|
| 425 | - { |
|
| 426 | - return false; |
|
| 427 | - } |
|
| 428 | - $pluginName = $this->functionList[$funcName]['plugin']; // plugin name |
|
| 429 | - $plugin = $this->pluginsList[$pluginName]['object']; // plugin object |
|
| 430 | - if ($plugin === null) |
|
| 431 | - { |
|
| 432 | - $this->registerPlugin($pluginName); // can throw exception handled by caller |
|
| 433 | - } |
|
| 434 | - $retObj = new stdClass(); |
|
| 435 | - $retObj->name = $funcName; |
|
| 436 | - $retObj->plugin = $pluginName; |
|
| 437 | - $retObj->params = $plugin->functions[$funcName]['params']; |
|
| 438 | - $retObj->description = $plugin->functions[$funcName]['description']; |
|
| 439 | - return $retObj; |
|
| 440 | - } |
|
| 416 | + /** |
|
| 417 | + * Get functions params and description |
|
| 418 | + * @param string $funcName |
|
| 419 | + * @return boolean|stdClass false if not found or object (name,params,description) |
|
| 420 | + * @throws \Exception if registering is not possible |
|
| 421 | + */ |
|
| 422 | + public function getFunctionDetails($funcName) |
|
| 423 | + { |
|
| 424 | + if (! isset($this->functionList[$funcName]) ) |
|
| 425 | + { |
|
| 426 | + return false; |
|
| 427 | + } |
|
| 428 | + $pluginName = $this->functionList[$funcName]['plugin']; // plugin name |
|
| 429 | + $plugin = $this->pluginsList[$pluginName]['object']; // plugin object |
|
| 430 | + if ($plugin === null) |
|
| 431 | + { |
|
| 432 | + $this->registerPlugin($pluginName); // can throw exception handled by caller |
|
| 433 | + } |
|
| 434 | + $retObj = new stdClass(); |
|
| 435 | + $retObj->name = $funcName; |
|
| 436 | + $retObj->plugin = $pluginName; |
|
| 437 | + $retObj->params = $plugin->functions[$funcName]['params']; |
|
| 438 | + $retObj->description = $plugin->functions[$funcName]['description']; |
|
| 439 | + return $retObj; |
|
| 440 | + } |
|
| 441 | 441 | |
| 442 | - /** |
|
| 443 | - * Evaluate function with parameters |
|
| 444 | - * @param string $funcName |
|
| 445 | - * @param mixed $params |
|
| 446 | - * @throws Exception |
|
| 447 | - * @return bool |
|
| 448 | - */ |
|
| 449 | - public function getFunctionEval(string $funcName,$params) : bool |
|
| 450 | - { |
|
| 451 | - if (! isset($this->functionList[$funcName]) ) |
|
| 452 | - { |
|
| 453 | - throw new Exception($funcName . ' not found.'); |
|
| 454 | - } |
|
| 455 | - $pluginName = $this->functionList[$funcName]['plugin']; // plugin name |
|
| 456 | - $plugin = $this->pluginsList[$pluginName]['object']; // plugin object |
|
| 442 | + /** |
|
| 443 | + * Evaluate function with parameters |
|
| 444 | + * @param string $funcName |
|
| 445 | + * @param mixed $params |
|
| 446 | + * @throws Exception |
|
| 447 | + * @return bool |
|
| 448 | + */ |
|
| 449 | + public function getFunctionEval(string $funcName,$params) : bool |
|
| 450 | + { |
|
| 451 | + if (! isset($this->functionList[$funcName]) ) |
|
| 452 | + { |
|
| 453 | + throw new Exception($funcName . ' not found.'); |
|
| 454 | + } |
|
| 455 | + $pluginName = $this->functionList[$funcName]['plugin']; // plugin name |
|
| 456 | + $plugin = $this->pluginsList[$pluginName]['object']; // plugin object |
|
| 457 | 457 | |
| 458 | - if ($plugin === null) |
|
| 459 | - { |
|
| 460 | - $this->registerPlugin($pluginName); // can throw exception handled by caller |
|
| 461 | - $plugin = $this->pluginsList[$pluginName]['object']; |
|
| 462 | - } |
|
| 458 | + if ($plugin === null) |
|
| 459 | + { |
|
| 460 | + $this->registerPlugin($pluginName); // can throw exception handled by caller |
|
| 461 | + $plugin = $this->pluginsList[$pluginName]['object']; |
|
| 462 | + } |
|
| 463 | 463 | |
| 464 | - $propertyName = $this->functionList[$funcName]['function']; |
|
| 465 | - $this->logClass->log('Using property '. $propertyName . ' of class : '.$pluginName,DEBUG); |
|
| 464 | + $propertyName = $this->functionList[$funcName]['function']; |
|
| 465 | + $this->logClass->log('Using property '. $propertyName . ' of class : '.$pluginName,DEBUG); |
|
| 466 | 466 | |
| 467 | - return $plugin->{$propertyName}($params); |
|
| 468 | - } |
|
| 467 | + return $plugin->{$propertyName}($params); |
|
| 468 | + } |
|
| 469 | 469 | |
| 470 | - public function evaluateFunctionString(string $functionString) : bool |
|
| 471 | - { |
|
| 472 | - $matches=array(); |
|
| 473 | - // Cleanup spaces |
|
| 474 | - //$functionString = $this->trapClass->ruleClass->eval_cleanup($functionString); |
|
| 475 | - //$this->logClass->log('eval cleanup : '.$functionString,DEBUG); |
|
| 470 | + public function evaluateFunctionString(string $functionString) : bool |
|
| 471 | + { |
|
| 472 | + $matches=array(); |
|
| 473 | + // Cleanup spaces |
|
| 474 | + //$functionString = $this->trapClass->ruleClass->eval_cleanup($functionString); |
|
| 475 | + //$this->logClass->log('eval cleanup : '.$functionString,DEBUG); |
|
| 476 | 476 | |
| 477 | - // Match function call |
|
| 478 | - $num=preg_match('/^__([a-zA-Z0-9]+)\((.+)\)$/', $functionString , $matches); |
|
| 479 | - if ($num !=1) |
|
| 480 | - { |
|
| 481 | - throw new \ErrorException('Function syntax error : ' . $functionString ); |
|
| 482 | - } |
|
| 483 | - $this->logClass->log('Got function : '. $matches[1] . ', params : '.$matches[2],DEBUG); |
|
| 484 | - $funcName=$matches[1]; |
|
| 477 | + // Match function call |
|
| 478 | + $num=preg_match('/^__([a-zA-Z0-9]+)\((.+)\)$/', $functionString , $matches); |
|
| 479 | + if ($num !=1) |
|
| 480 | + { |
|
| 481 | + throw new \ErrorException('Function syntax error : ' . $functionString ); |
|
| 482 | + } |
|
| 483 | + $this->logClass->log('Got function : '. $matches[1] . ', params : '.$matches[2],DEBUG); |
|
| 484 | + $funcName=$matches[1]; |
|
| 485 | 485 | |
| 486 | - // Get parameters comma separated |
|
| 487 | - $funcParams=str_getcsv($matches[2],',','"',"\\"); |
|
| 488 | - $this->logClass->log('Function params : ' . print_r($funcParams,true),DEBUG); |
|
| 486 | + // Get parameters comma separated |
|
| 487 | + $funcParams=str_getcsv($matches[2],',','"',"\\"); |
|
| 488 | + $this->logClass->log('Function params : ' . print_r($funcParams,true),DEBUG); |
|
| 489 | 489 | |
| 490 | - // return evaluation |
|
| 491 | - return $this->getFunctionEval($funcName, $funcParams); |
|
| 490 | + // return evaluation |
|
| 491 | + return $this->getFunctionEval($funcName, $funcParams); |
|
| 492 | 492 | |
| 493 | - } |
|
| 493 | + } |
|
| 494 | 494 | |
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | abstract class PluginTemplate |
| 498 | 498 | { |
| 499 | 499 | |
| 500 | - /** @var Logging $loggingClass */ |
|
| 501 | - private $loggingClass; |
|
| 500 | + /** @var Logging $loggingClass */ |
|
| 501 | + private $loggingClass; |
|
| 502 | 502 | |
| 503 | - /** @var string $name Name of plugin */ |
|
| 504 | - public $name; |
|
| 503 | + /** @var string $name Name of plugin */ |
|
| 504 | + public $name; |
|
| 505 | 505 | |
| 506 | - /** @var string $description Description of plugin */ |
|
| 507 | - public $description='Default plugin description'; |
|
| 506 | + /** @var string $description Description of plugin */ |
|
| 507 | + public $description='Default plugin description'; |
|
| 508 | 508 | |
| 509 | - /** @var array $functions Functions of this plugin for rule eval*/ |
|
| 510 | - public $functions=array(); |
|
| 509 | + /** @var array $functions Functions of this plugin for rule eval*/ |
|
| 510 | + public $functions=array(); |
|
| 511 | 511 | |
| 512 | - /** @var boolean $catchAllTraps Set to true if all traps will be sent to the plugin */ |
|
| 513 | - public $catchAllTraps=false; |
|
| 512 | + /** @var boolean $catchAllTraps Set to true if all traps will be sent to the plugin */ |
|
| 513 | + public $catchAllTraps=false; |
|
| 514 | 514 | |
| 515 | - /** @var boolean $processTraps Set to true if plugins can handle traps */ |
|
| 516 | - public $processTraps=false; |
|
| 515 | + /** @var boolean $processTraps Set to true if plugins can handle traps */ |
|
| 516 | + public $processTraps=false; |
|
| 517 | 517 | |
| 518 | - /** |
|
| 519 | - * @param \Trapdirector\Logging $loggingClass |
|
| 520 | - */ |
|
| 521 | - public function setLoggingClass($loggingClass) |
|
| 522 | - { |
|
| 523 | - $this->loggingClass = $loggingClass; |
|
| 524 | - } |
|
| 518 | + /** |
|
| 519 | + * @param \Trapdirector\Logging $loggingClass |
|
| 520 | + */ |
|
| 521 | + public function setLoggingClass($loggingClass) |
|
| 522 | + { |
|
| 523 | + $this->loggingClass = $loggingClass; |
|
| 524 | + } |
|
| 525 | 525 | |
| 526 | - /** |
|
| 527 | - * |
|
| 528 | - * @param string $message |
|
| 529 | - * @param int $level DEBUG/INFO/WARN/CRIT |
|
| 530 | - */ |
|
| 531 | - public function log($message,$level) |
|
| 532 | - { |
|
| 533 | - $this->loggingClass->log('[ '.get_class($this).'] '. $message, $level); |
|
| 534 | - } |
|
| 526 | + /** |
|
| 527 | + * |
|
| 528 | + * @param string $message |
|
| 529 | + * @param int $level DEBUG/INFO/WARN/CRIT |
|
| 530 | + */ |
|
| 531 | + public function log($message,$level) |
|
| 532 | + { |
|
| 533 | + $this->loggingClass->log('[ '.get_class($this).'] '. $message, $level); |
|
| 534 | + } |
|
| 535 | 535 | } |
| 536 | 536 | \ No newline at end of file |