@@ -14,26 +14,26 @@ discard block |
||
| 14 | 14 | 'log_level' => 2, // log level |
| 15 | 15 | ); |
| 16 | 16 | // get default values for dbconfig |
| 17 | - public function getDBConfigDefaults() { return $this->DBConfigDefaults;} |
|
| 17 | + public function getDBConfigDefaults() { return $this->DBConfigDefaults; } |
|
| 18 | 18 | /** Minimum DB version |
| 19 | 19 | * @return number |
| 20 | 20 | */ |
| 21 | - static public function getDbMinVersion() { return 2;} |
|
| 21 | + static public function getDbMinVersion() { return 2; } |
|
| 22 | 22 | /** Current DB version |
| 23 | 23 | * @return number |
| 24 | 24 | */ |
| 25 | - static public function getDbCurVersion() { return 2;} |
|
| 25 | + static public function getDbCurVersion() { return 2; } |
|
| 26 | 26 | |
| 27 | 27 | /************ Module configuration **********************/ |
| 28 | 28 | // Module base path |
| 29 | 29 | static public function urlPath() { return 'trapdirector'; } |
| 30 | - static public function getapiUserPermissions() { return array("status", "objects/query/Host", "objects/query/Service" , "actions/process-check-result"); } //< api user permissions required |
|
| 30 | + static public function getapiUserPermissions() { return array("status", "objects/query/Host", "objects/query/Service", "actions/process-check-result"); } //< api user permissions required |
|
| 31 | 31 | |
| 32 | 32 | /*********** Log configuration *************************/ |
| 33 | 33 | protected $logLevels=array(0=>'No output', 1=>'critical', 2=>'warning', 3=>'trace', 4=>'ALL'); |
| 34 | - public function getlogLevels() { return $this->logLevels;} |
|
| 35 | - protected $logDestinations=array('syslog'=>'syslog','file'=>'file','display'=>'display'); |
|
| 36 | - public function getLogDestinations() { return $this->logDestinations;} |
|
| 34 | + public function getlogLevels() { return $this->logLevels; } |
|
| 35 | + protected $logDestinations=array('syslog'=>'syslog', 'file'=>'file', 'display'=>'display'); |
|
| 36 | + public function getLogDestinations() { return $this->logDestinations; } |
|
| 37 | 37 | |
| 38 | 38 | function __construct($prefix) |
| 39 | 39 | { |
@@ -44,29 +44,29 @@ discard block |
||
| 44 | 44 | // DB table name of trap received list : prefix 't' |
| 45 | 45 | public function getTrapTableName() |
| 46 | 46 | { |
| 47 | - return array('t' => $this->table_prefix . 'received'); |
|
| 47 | + return array('t' => $this->table_prefix.'received'); |
|
| 48 | 48 | } |
| 49 | 49 | // DB table name of trap data list : prefix 'd' |
| 50 | 50 | public function getTrapDataTableName() |
| 51 | 51 | { |
| 52 | - return array('d' => $this->table_prefix . 'received_data'); |
|
| 52 | + return array('d' => $this->table_prefix.'received_data'); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | // DB table name of rules : prefix 'r' |
| 56 | 56 | public function getTrapRuleName() |
| 57 | 57 | { |
| 58 | - return array('r' => $this->table_prefix . 'rules'); |
|
| 58 | + return array('r' => $this->table_prefix.'rules'); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | // DB table name of db config : prefix 'c' |
| 62 | 62 | public function getDbConfigTableName() |
| 63 | 63 | { |
| 64 | - return array('c' => $this->table_prefix . 'db_config'); |
|
| 64 | + return array('c' => $this->table_prefix.'db_config'); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | // Mib cache tables |
| 68 | - public function getMIBCacheTableName() { return $this->table_prefix . 'mib_cache'; } |
|
| 69 | - public function getMIBCacheTableTrapObjName() { return $this->table_prefix . 'mib_cache_trap_object'; } |
|
| 68 | + public function getMIBCacheTableName() { return $this->table_prefix.'mib_cache'; } |
|
| 69 | + public function getMIBCacheTableTrapObjName() { return $this->table_prefix.'mib_cache_trap_object'; } |
|
| 70 | 70 | |
| 71 | 71 | |
| 72 | 72 | /****************** Database queries *******************/ |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | public function getHandlerListDisplayColumns() |
| 148 | 148 | { |
| 149 | 149 | return array( |
| 150 | - 'host_name' => 'r.host_name',//'UNIX_TIMESTAMP(t.date_received)', |
|
| 150 | + 'host_name' => 'r.host_name', //'UNIX_TIMESTAMP(t.date_received)', |
|
| 151 | 151 | 'host_group_name'=> 'r.host_group_name', |
| 152 | 152 | 'source_ip' => "CASE WHEN r.ip4 IS NULL THEN r.ip6 ELSE r.ip4 END", |
| 153 | 153 | 'trap_oid' => 'r.trap_oid', |
@@ -200,32 +200,32 @@ discard block |
||
| 200 | 200 | public function trapDetailQuery() |
| 201 | 201 | { |
| 202 | 202 | return array( |
| 203 | - 'timestamp' => array('Date','UNIX_TIMESTAMP(t.date_received)'), |
|
| 204 | - 'source_ip' => array('Source IP','t.source_ip'), |
|
| 205 | - 'source_name' => array('Source name','t.source_name'), |
|
| 206 | - 'source_port' => array('Source port','t.source_port'), |
|
| 207 | - 'destination_ip' => array('Destination IP','t.destination_ip'), |
|
| 208 | - 'destination_port' => array('Destination port','t.destination_port'), |
|
| 209 | - 'trap_oid' => array('Numeric OID','t.trap_oid'), |
|
| 210 | - 'trap_name' => array('Trap name','t.trap_name'), |
|
| 211 | - 'trap_name_mib' => array('Trap MIB','t.trap_name_mib'), |
|
| 212 | - 'status' => array('Processing status','t.status'), |
|
| 213 | - 'status_detail' => array('Status details','t.status_detail'), |
|
| 214 | - 'process_time' => array('Trap processing time','t.process_time'), |
|
| 203 | + 'timestamp' => array('Date', 'UNIX_TIMESTAMP(t.date_received)'), |
|
| 204 | + 'source_ip' => array('Source IP', 't.source_ip'), |
|
| 205 | + 'source_name' => array('Source name', 't.source_name'), |
|
| 206 | + 'source_port' => array('Source port', 't.source_port'), |
|
| 207 | + 'destination_ip' => array('Destination IP', 't.destination_ip'), |
|
| 208 | + 'destination_port' => array('Destination port', 't.destination_port'), |
|
| 209 | + 'trap_oid' => array('Numeric OID', 't.trap_oid'), |
|
| 210 | + 'trap_name' => array('Trap name', 't.trap_name'), |
|
| 211 | + 'trap_name_mib' => array('Trap MIB', 't.trap_name_mib'), |
|
| 212 | + 'status' => array('Processing status', 't.status'), |
|
| 213 | + 'status_detail' => array('Status details', 't.status_detail'), |
|
| 214 | + 'process_time' => array('Trap processing time', 't.process_time'), |
|
| 215 | 215 | ); |
| 216 | 216 | } |
| 217 | 217 | // Trap detail : additional data (<key> => <title> <sql select>) |
| 218 | 218 | public function trapDataDetailQuery() |
| 219 | 219 | { |
| 220 | 220 | return array( |
| 221 | - 'oid' => array('Numeric OID','d.oid'), |
|
| 222 | - 'oid_name' => array('Text OID','d.oid_name'), |
|
| 223 | - 'oid_name_mib' => array('MIB','d.oid_name_mib'), |
|
| 224 | - 'value' => array('Value','d.value'), |
|
| 221 | + 'oid' => array('Numeric OID', 'd.oid'), |
|
| 222 | + 'oid_name' => array('Text OID', 'd.oid_name'), |
|
| 223 | + 'oid_name_mib' => array('MIB', 'd.oid_name_mib'), |
|
| 224 | + 'value' => array('Value', 'd.value'), |
|
| 225 | 225 | ); |
| 226 | 226 | } |
| 227 | 227 | // foreign key of trap data table |
| 228 | - public function trapDataFK() { return 'trap_id';} |
|
| 228 | + public function trapDataFK() { return 'trap_id'; } |
|
| 229 | 229 | |
| 230 | 230 | // Max items in a list |
| 231 | 231 | public function itemListDisplay() { return 25; } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | { |
| 55 | 55 | $this->redirectNow('trapdirector/settings?message=No database prefix'); |
| 56 | 56 | } |
| 57 | - $this->moduleConfig = new TrapModuleConfig($db_prefix); |
|
| 57 | + $this->moduleConfig=new TrapModuleConfig($db_prefix); |
|
| 58 | 58 | } |
| 59 | 59 | return $this->moduleConfig; |
| 60 | 60 | } |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | */ |
| 66 | 66 | public function getTrapListTable() { |
| 67 | 67 | if ($this->trapTableList == Null) { |
| 68 | - $this->trapTableList = new TrapTableList(); |
|
| 68 | + $this->trapTableList=new TrapTableList(); |
|
| 69 | 69 | $this->trapTableList->setConfig($this->getModuleConfig()); |
| 70 | 70 | } |
| 71 | 71 | return $this->trapTableList; |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | { |
| 76 | 76 | if ($this->trapTableHostList == Null) |
| 77 | 77 | { |
| 78 | - $this->trapTableHostList = new TrapTableHostList(); |
|
| 78 | + $this->trapTableHostList=new TrapTableHostList(); |
|
| 79 | 79 | $this->trapTableHostList->setConfig($this->getModuleConfig()); |
| 80 | 80 | } |
| 81 | 81 | return $this->trapTableHostList; |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | { |
| 86 | 86 | if ($this->handlerTableList == Null) |
| 87 | 87 | { |
| 88 | - $this->handlerTableList = new HandlerTableList(); |
|
| 88 | + $this->handlerTableList=new HandlerTableList(); |
|
| 89 | 89 | $this->handlerTableList->setConfig($this->getModuleConfig()); |
| 90 | 90 | } |
| 91 | 91 | return $this->handlerTableList; |
@@ -97,15 +97,15 @@ discard block |
||
| 97 | 97 | * @param $test_version bool if set to flase, does not test database version of trapDB |
| 98 | 98 | * @return array<integer,mixed>|mixed : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
| 99 | 99 | */ |
| 100 | - public function getDbByName($DBname,$test=false,$test_version=true) |
|
| 100 | + public function getDbByName($DBname, $test=false, $test_version=true) |
|
| 101 | 101 | { |
| 102 | 102 | try |
| 103 | 103 | { |
| 104 | - $dbconn = IcingaDbConnection::fromResourceName($DBname); |
|
| 104 | + $dbconn=IcingaDbConnection::fromResourceName($DBname); |
|
| 105 | 105 | } |
| 106 | 106 | catch (Exception $e) |
| 107 | 107 | { |
| 108 | - if ($test) return array(2,$DBname); |
|
| 108 | + if ($test) return array(2, $DBname); |
|
| 109 | 109 | $this->redirectNow('trapdirector/settings?dberror=2'); |
| 110 | 110 | return null; |
| 111 | 111 | } |
@@ -116,37 +116,37 @@ discard block |
||
| 116 | 116 | } |
| 117 | 117 | catch (Exception $e) |
| 118 | 118 | { |
| 119 | - if ($test) return array(3,$DBname,$e->getMessage()); |
|
| 119 | + if ($test) return array(3, $DBname, $e->getMessage()); |
|
| 120 | 120 | $this->redirectNow('trapdirector/settings?dberror=3'); |
| 121 | 121 | return null; |
| 122 | 122 | } |
| 123 | 123 | try |
| 124 | 124 | { |
| 125 | - $query = $db->select() |
|
| 126 | - ->from($this->getModuleConfig()->getDbConfigTableName(),'value') |
|
| 125 | + $query=$db->select() |
|
| 126 | + ->from($this->getModuleConfig()->getDbConfigTableName(), 'value') |
|
| 127 | 127 | ->where('name=\'db_version\''); |
| 128 | 128 | $version=$db->fetchRow($query); |
| 129 | - if ( ($version == null) || ! property_exists($version,'value') ) |
|
| 129 | + if (($version == null) || !property_exists($version, 'value')) |
|
| 130 | 130 | { |
| 131 | - if ($test) return array(4,$DBname); |
|
| 131 | + if ($test) return array(4, $DBname); |
|
| 132 | 132 | $this->redirectNow('trapdirector/settings?dberror=4'); |
| 133 | 133 | return null; |
| 134 | 134 | } |
| 135 | 135 | if ($version->value < $this->getModuleConfig()->getDbMinVersion()) |
| 136 | 136 | { |
| 137 | - if ($test) return array(5,$version->value,$this->getModuleConfig()->getDbMinVersion()); |
|
| 137 | + if ($test) return array(5, $version->value, $this->getModuleConfig()->getDbMinVersion()); |
|
| 138 | 138 | $this->redirectNow('trapdirector/settings?dberror=5'); |
| 139 | 139 | return null; |
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | 142 | catch (Exception $e) |
| 143 | 143 | { |
| 144 | - if ($test) return array(3,$DBname,$e->getMessage()); |
|
| 144 | + if ($test) return array(3, $DBname, $e->getMessage()); |
|
| 145 | 145 | $this->redirectNow('trapdirector/settings?dberror=4'); |
| 146 | 146 | return null; |
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | - if ($test) return array(0,''); |
|
| 149 | + if ($test) return array(0, ''); |
|
| 150 | 150 | return $dbconn; |
| 151 | 151 | } |
| 152 | 152 | |
@@ -157,17 +157,17 @@ discard block |
||
| 157 | 157 | */ |
| 158 | 158 | public function getDb($test=false) |
| 159 | 159 | { |
| 160 | - if ($this->trapDB != null && $test = false) return $this->trapDB; |
|
| 160 | + if ($this->trapDB != null && $test=false) return $this->trapDB; |
|
| 161 | 161 | |
| 162 | 162 | $dbresource=$this->Config()->get('config', 'database'); |
| 163 | 163 | |
| 164 | - if ( ! $dbresource ) |
|
| 164 | + if (!$dbresource) |
|
| 165 | 165 | { |
| 166 | - if ($test) return array(1,''); |
|
| 166 | + if ($test) return array(1, ''); |
|
| 167 | 167 | $this->redirectNow('trapdirector/settings?dberror=1'); |
| 168 | 168 | return null; |
| 169 | 169 | } |
| 170 | - $retDB=$this->getDbByName($dbresource,$test,true); |
|
| 170 | + $retDB=$this->getDbByName($dbresource, $test, true); |
|
| 171 | 171 | if ($test === true) return $retDB; |
| 172 | 172 | $this->trapDB=$retDB; |
| 173 | 173 | return $this->trapDB; |
@@ -175,78 +175,78 @@ discard block |
||
| 175 | 175 | |
| 176 | 176 | public function getIdoDb($test=false) |
| 177 | 177 | { |
| 178 | - if ($this->icingaDB != null && $test = false) return $this->icingaDB; |
|
| 178 | + if ($this->icingaDB != null && $test=false) return $this->icingaDB; |
|
| 179 | 179 | // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
| 180 | - $dbresource=$this->Config()->get('config', 'IDOdatabase');; |
|
| 180 | + $dbresource=$this->Config()->get('config', 'IDOdatabase'); ; |
|
| 181 | 181 | |
| 182 | - if ( ! $dbresource ) |
|
| 182 | + if (!$dbresource) |
|
| 183 | 183 | { |
| 184 | - if ($test) return array(1,'No database in config.ini'); |
|
| 184 | + if ($test) return array(1, 'No database in config.ini'); |
|
| 185 | 185 | $this->redirectNow('trapdirector/settings?idodberror=1'); |
| 186 | 186 | return null; |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | try |
| 190 | 190 | { |
| 191 | - $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
| 191 | + $dbconn=IcingaDbConnection::fromResourceName($dbresource); |
|
| 192 | 192 | } |
| 193 | 193 | catch (Exception $e) |
| 194 | 194 | { |
| 195 | - if ($test) return array(2,"Database $dbresource does not exists in IcingaWeb2"); |
|
| 195 | + if ($test) return array(2, "Database $dbresource does not exists in IcingaWeb2"); |
|
| 196 | 196 | $this->redirectNow('trapdirector/settings?idodberror=2'); |
| 197 | 197 | return null; |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | if ($test == false) |
| 201 | 201 | { |
| 202 | - $this->icingaDB = $dbconn; |
|
| 202 | + $this->icingaDB=$dbconn; |
|
| 203 | 203 | return $this->icingaDB; |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | try |
| 207 | 207 | { |
| 208 | - $query = $dbconn->select() |
|
| 209 | - ->from('icinga_dbversion',array('version')); |
|
| 208 | + $query=$dbconn->select() |
|
| 209 | + ->from('icinga_dbversion', array('version')); |
|
| 210 | 210 | $version=$dbconn->fetchRow($query); |
| 211 | - if ( ($version == null) || ! property_exists($version,'version') ) |
|
| 211 | + if (($version == null) || !property_exists($version, 'version')) |
|
| 212 | 212 | { |
| 213 | - return array(4,"$dbresource does not look like an IDO database"); |
|
| 213 | + return array(4, "$dbresource does not look like an IDO database"); |
|
| 214 | 214 | } |
| 215 | 215 | } |
| 216 | 216 | catch (Exception $e) |
| 217 | 217 | { |
| 218 | - return array(3,"Error connecting to $dbresource : " . $e->getMessage()); |
|
| 218 | + return array(3, "Error connecting to $dbresource : ".$e->getMessage()); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - return array(0,''); |
|
| 221 | + return array(0, ''); |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null) |
|
| 224 | + protected function applyPaginationLimits(Paginatable $paginatable, $limit=25, $offset=null) |
|
| 225 | 225 | { |
| 226 | - $limit = $this->params->get('limit', $limit); |
|
| 227 | - $page = $this->params->get('page', $offset); |
|
| 226 | + $limit=$this->params->get('limit', $limit); |
|
| 227 | + $page=$this->params->get('page', $offset); |
|
| 228 | 228 | |
| 229 | 229 | $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0); |
| 230 | 230 | |
| 231 | 231 | return $paginatable; |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | - public function displayExitError($source,$message) |
|
| 234 | + public function displayExitError($source, $message) |
|
| 235 | 235 | { // TODO : check better ways to transmit data (with POST ?) |
| 236 | 236 | $this->redirectNow('trapdirector/error?source='.$source.'&message='.$message); |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | protected function checkReadPermission() |
| 240 | 240 | { |
| 241 | - if (! $this->Auth()->hasPermission('trapdirector/view')) { |
|
| 242 | - $this->displayExitError('Permissions','No permission fo view content'); |
|
| 241 | + if (!$this->Auth()->hasPermission('trapdirector/view')) { |
|
| 242 | + $this->displayExitError('Permissions', 'No permission fo view content'); |
|
| 243 | 243 | } |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | protected function checkConfigPermission() |
| 247 | 247 | { |
| 248 | - if (! $this->Auth()->hasPermission('trapdirector/config')) { |
|
| 249 | - $this->displayExitError('Permissions','No permission fo configure'); |
|
| 248 | + if (!$this->Auth()->hasPermission('trapdirector/config')) { |
|
| 249 | + $this->displayExitError('Permissions', 'No permission fo configure'); |
|
| 250 | 250 | } |
| 251 | 251 | } |
| 252 | 252 | |
@@ -257,10 +257,10 @@ discard block |
||
| 257 | 257 | */ |
| 258 | 258 | protected function checkModuleConfigPermission($check=0) |
| 259 | 259 | { |
| 260 | - if (! $this->Auth()->hasPermission('trapdirector/module_config')) { |
|
| 260 | + if (!$this->Auth()->hasPermission('trapdirector/module_config')) { |
|
| 261 | 261 | if ($check == 0) |
| 262 | 262 | { |
| 263 | - $this->displayExitError('Permissions','No permission fo configure module'); |
|
| 263 | + $this->displayExitError('Permissions', 'No permission fo configure module'); |
|
| 264 | 264 | } |
| 265 | 265 | return false; |
| 266 | 266 | } |
@@ -272,10 +272,10 @@ discard block |
||
| 272 | 272 | { // TODO : try/catch here ? or within caller |
| 273 | 273 | if ($this->trapClass == null) |
| 274 | 274 | { |
| 275 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 275 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
| 276 | 276 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 277 | 277 | //$debug_level=4; |
| 278 | - $this->trapClass = new Trap($icingaweb2_etc); |
|
| 278 | + $this->trapClass=new Trap($icingaweb2_etc); |
|
| 279 | 279 | //$Trap->setLogging($debug_level,'syslog'); |
| 280 | 280 | } |
| 281 | 281 | return $this->trapClass; |
@@ -309,12 +309,12 @@ discard block |
||
| 309 | 309 | protected function getHostByIP($ip) |
| 310 | 310 | { |
| 311 | 311 | // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
| 312 | - $db = $this->getIdoDb()->getConnection(); |
|
| 312 | + $db=$this->getIdoDb()->getConnection(); |
|
| 313 | 313 | // TODO : check for SQL injections |
| 314 | 314 | $query=$db->select() |
| 315 | 315 | ->from( |
| 316 | 316 | array('a' => 'icinga_objects'), |
| 317 | - array('name' => 'a.name1','id' => 'object_id')) |
|
| 317 | + array('name' => 'a.name1', 'id' => 'object_id')) |
|
| 318 | 318 | ->join( |
| 319 | 319 | array('b' => 'icinga_hosts'), |
| 320 | 320 | 'b.host_object_id=a.object_id', |
@@ -330,12 +330,12 @@ discard block |
||
| 330 | 330 | protected function getHostByName($name) |
| 331 | 331 | { |
| 332 | 332 | // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
| 333 | - $db = $this->getIdoDb()->getConnection(); |
|
| 333 | + $db=$this->getIdoDb()->getConnection(); |
|
| 334 | 334 | // TODO : check for SQL injections |
| 335 | 335 | $query=$db->select() |
| 336 | 336 | ->from( |
| 337 | 337 | array('a' => 'icinga_objects'), |
| 338 | - array('name' => 'a.name1','id' => 'object_id')) |
|
| 338 | + array('name' => 'a.name1', 'id' => 'object_id')) |
|
| 339 | 339 | ->join( |
| 340 | 340 | array('b' => 'icinga_hosts'), |
| 341 | 341 | 'b.host_object_id=a.object_id', |
@@ -351,12 +351,12 @@ discard block |
||
| 351 | 351 | protected function getHostGroupByName($ip) |
| 352 | 352 | { |
| 353 | 353 | // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
| 354 | - $db = $this->getIdoDb()->getConnection(); |
|
| 354 | + $db=$this->getIdoDb()->getConnection(); |
|
| 355 | 355 | // TODO : check for SQL injections |
| 356 | 356 | $query=$db->select() |
| 357 | 357 | ->from( |
| 358 | 358 | array('a' => 'icinga_objects'), |
| 359 | - array('name' => 'a.name1','id' => 'object_id')) |
|
| 359 | + array('name' => 'a.name1', 'id' => 'object_id')) |
|
| 360 | 360 | ->join( |
| 361 | 361 | array('b' => 'icinga_hostgroups'), |
| 362 | 362 | 'b.hostgroup_object_id=a.object_id', |
@@ -372,8 +372,8 @@ discard block |
||
| 372 | 372 | */ |
| 373 | 373 | protected function getHostInfoByID($id) |
| 374 | 374 | { |
| 375 | - if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
| 376 | - $db = $this->getIdoDb()->getConnection(); |
|
| 375 | + if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); } |
|
| 376 | + $db=$this->getIdoDb()->getConnection(); |
|
| 377 | 377 | $query=$db->select() |
| 378 | 378 | ->from( |
| 379 | 379 | array('a' => 'icinga_objects'), |
@@ -393,17 +393,17 @@ discard block |
||
| 393 | 393 | */ |
| 394 | 394 | protected function getHostByObjectID($id) // TODO : duplicate of getHostInfoByID above |
| 395 | 395 | { |
| 396 | - if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
| 397 | - $db = $this->getIdoDb()->getConnection(); |
|
| 396 | + if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); } |
|
| 397 | + $db=$this->getIdoDb()->getConnection(); |
|
| 398 | 398 | $query=$db->select() |
| 399 | 399 | ->from( |
| 400 | 400 | array('a' => 'icinga_objects'), |
| 401 | - array('name' => 'a.name1','id' => 'a.object_id')) |
|
| 401 | + array('name' => 'a.name1', 'id' => 'a.object_id')) |
|
| 402 | 402 | ->join( |
| 403 | 403 | array('b' => 'icinga_hosts'), |
| 404 | 404 | 'b.host_object_id=a.object_id', |
| 405 | - array('display_name' => 'b.display_name' , 'ip' => 'b.address', 'ip6' => 'b.address6')) |
|
| 406 | - ->where('a.object_id = ?',$id); |
|
| 405 | + array('display_name' => 'b.display_name', 'ip' => 'b.address', 'ip6' => 'b.address6')) |
|
| 406 | + ->where('a.object_id = ?', $id); |
|
| 407 | 407 | return $db->fetchRow($query); |
| 408 | 408 | } |
| 409 | 409 | |
@@ -415,16 +415,16 @@ discard block |
||
| 415 | 415 | protected function getServicesByHostid($id) |
| 416 | 416 | { |
| 417 | 417 | // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
| 418 | - if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
| 419 | - $db = $this->getIdoDb()->getConnection(); |
|
| 418 | + if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); } |
|
| 419 | + $db=$this->getIdoDb()->getConnection(); |
|
| 420 | 420 | $query=$db->select() |
| 421 | 421 | ->from( |
| 422 | 422 | array('s' => 'icinga_services'), |
| 423 | - array('name' => 's.display_name','id' => 's.service_object_id')) |
|
| 423 | + array('name' => 's.display_name', 'id' => 's.service_object_id')) |
|
| 424 | 424 | ->join( |
| 425 | 425 | array('a' => 'icinga_objects'), |
| 426 | 426 | 's.service_object_id=a.object_id', |
| 427 | - array('is_active'=>'a.is_active','name2'=>'a.name2')) |
|
| 427 | + array('is_active'=>'a.is_active', 'name2'=>'a.name2')) |
|
| 428 | 428 | ->where('s.host_object_id='.$id.' AND a.is_active = 1'); |
| 429 | 429 | return $db->fetchAll($query); |
| 430 | 430 | } |
@@ -437,8 +437,8 @@ discard block |
||
| 437 | 437 | */ |
| 438 | 438 | protected function getServicesByHostGroupid($id) |
| 439 | 439 | { |
| 440 | - if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
| 441 | - $db = $this->getIdoDb()->getConnection(); |
|
| 440 | + if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); } |
|
| 441 | + $db=$this->getIdoDb()->getConnection(); |
|
| 442 | 442 | $query=$db->select() |
| 443 | 443 | ->from( |
| 444 | 444 | array('s' => 'icinga_hostgroup_members'), |
@@ -454,11 +454,11 @@ discard block |
||
| 454 | 454 | foreach ($hosts as $key => $host) |
| 455 | 455 | { // For each host, get all services and add in common_services if not found or add counter |
| 456 | 456 | $host_services=$this->getServicesByHostid($host->host_object_id); |
| 457 | - foreach($host_services as $service) |
|
| 457 | + foreach ($host_services as $service) |
|
| 458 | 458 | { |
| 459 | 459 | if (isset($common_services[$service->name2]['num'])) |
| 460 | 460 | { |
| 461 | - $common_services[$service->name2]['num'] +=1; |
|
| 461 | + $common_services[$service->name2]['num']+=1; |
|
| 462 | 462 | } |
| 463 | 463 | else |
| 464 | 464 | { |
@@ -474,7 +474,7 @@ discard block |
||
| 474 | 474 | { |
| 475 | 475 | if ($common_services[$key]['num'] == $num_hosts) |
| 476 | 476 | { |
| 477 | - array_push($result,array($key,$common_services[$key]['name'])); |
|
| 477 | + array_push($result, array($key, $common_services[$key]['name'])); |
|
| 478 | 478 | } |
| 479 | 479 | } |
| 480 | 480 | |
@@ -487,9 +487,9 @@ discard block |
||
| 487 | 487 | * @param $name string service name |
| 488 | 488 | * @return array service id |
| 489 | 489 | */ |
| 490 | - protected function getServiceIDByName($hostname,$name) |
|
| 490 | + protected function getServiceIDByName($hostname, $name) |
|
| 491 | 491 | { |
| 492 | - $db = $this->getIdoDb()->getConnection(); |
|
| 492 | + $db=$this->getIdoDb()->getConnection(); |
|
| 493 | 493 | if ($name == null) |
| 494 | 494 | { |
| 495 | 495 | return array(); |
@@ -498,7 +498,7 @@ discard block |
||
| 498 | 498 | $query=$db->select() |
| 499 | 499 | ->from( |
| 500 | 500 | array('s' => 'icinga_services'), |
| 501 | - array('name' => 's.display_name','id' => 's.service_object_id')) |
|
| 501 | + array('name' => 's.display_name', 'id' => 's.service_object_id')) |
|
| 502 | 502 | ->join( |
| 503 | 503 | array('a' => 'icinga_objects'), |
| 504 | 504 | 's.service_object_id=a.object_id', |
@@ -516,12 +516,12 @@ discard block |
||
| 516 | 516 | protected function getObjectNameByid($id) |
| 517 | 517 | { |
| 518 | 518 | // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
| 519 | - if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
| 520 | - $db = $this->getIdoDb()->getConnection(); |
|
| 519 | + if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); } |
|
| 520 | + $db=$this->getIdoDb()->getConnection(); |
|
| 521 | 521 | $query=$db->select() |
| 522 | 522 | ->from( |
| 523 | 523 | array('a' => 'icinga_objects'), |
| 524 | - array('name1' => 'a.name1','name2' => 'a.name2')) |
|
| 524 | + array('name1' => 'a.name1', 'name2' => 'a.name2')) |
|
| 525 | 525 | ->where('a.object_id='.$id.' AND a.is_active = 1'); |
| 526 | 526 | |
| 527 | 527 | return $db->fetchRow($query); |
@@ -534,17 +534,17 @@ discard block |
||
| 534 | 534 | protected function addHandlerRule($params) |
| 535 | 535 | { |
| 536 | 536 | // TODO Check for rule consistency |
| 537 | - $db = $this->getDb()->getConnection(); |
|
| 537 | + $db=$this->getDb()->getConnection(); |
|
| 538 | 538 | // Add last modified date = creation date and username |
| 539 | - $params['created'] = new Zend_Db_Expr('NOW()'); |
|
| 540 | - $params['modified'] = new Zend_Db_Expr('NOW()'); |
|
| 541 | - $params['modifier'] = $this->Auth()->getUser()->getUsername(); |
|
| 539 | + $params['created']=new Zend_Db_Expr('NOW()'); |
|
| 540 | + $params['modified']=new Zend_Db_Expr('NOW()'); |
|
| 541 | + $params['modifier']=$this->Auth()->getUser()->getUsername(); |
|
| 542 | 542 | |
| 543 | 543 | $query=$db->insert( |
| 544 | 544 | $this->getModuleConfig()->getTrapRuleName(), |
| 545 | 545 | $params |
| 546 | 546 | ); |
| 547 | - if($query==false) |
|
| 547 | + if ($query == false) |
|
| 548 | 548 | { |
| 549 | 549 | return null; |
| 550 | 550 | } |
@@ -556,13 +556,13 @@ discard block |
||
| 556 | 556 | * @param integer $ruleID : rule id in db |
| 557 | 557 | * @return array affected rows |
| 558 | 558 | */ |
| 559 | - protected function updateHandlerRule($params,$ruleID) |
|
| 559 | + protected function updateHandlerRule($params, $ruleID) |
|
| 560 | 560 | { |
| 561 | 561 | // TODO Check for rule consistency |
| 562 | - $db = $this->getDb()->getConnection(); |
|
| 562 | + $db=$this->getDb()->getConnection(); |
|
| 563 | 563 | // Add last modified date = creation date and username |
| 564 | - $params['modified'] = new Zend_Db_Expr('NOW()'); |
|
| 565 | - $params['modifier'] = $this->Auth()->getUser()->getUsername(); |
|
| 564 | + $params['modified']=new Zend_Db_Expr('NOW()'); |
|
| 565 | + $params['modifier']=$this->Auth()->getUser()->getUsername(); |
|
| 566 | 566 | |
| 567 | 567 | $numRows=$db->update( |
| 568 | 568 | $this->getModuleConfig()->getTrapRuleName(), |
@@ -577,8 +577,8 @@ discard block |
||
| 577 | 577 | */ |
| 578 | 578 | protected function deleteRule($ruleID) |
| 579 | 579 | { |
| 580 | - if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id'); } |
|
| 581 | - $db = $this->getDb()->getConnection(); |
|
| 580 | + if (!preg_match('/^[0-9]+$/', $ruleID)) { throw new Exception('Invalid id'); } |
|
| 581 | + $db=$this->getDb()->getConnection(); |
|
| 582 | 582 | |
| 583 | 583 | $query=$db->delete( |
| 584 | 584 | $this->getModuleConfig()->getTrapRuleName(), |
@@ -591,10 +591,10 @@ discard block |
||
| 591 | 591 | * @param $ip string source IP (v4 or v6) |
| 592 | 592 | * @param $oid string oid |
| 593 | 593 | */ |
| 594 | - protected function deleteTrap($ip,$oid) |
|
| 594 | + protected function deleteTrap($ip, $oid) |
|
| 595 | 595 | { |
| 596 | 596 | |
| 597 | - $db = $this->getDb()->getConnection(); |
|
| 597 | + $db=$this->getDb()->getConnection(); |
|
| 598 | 598 | $condition=null; |
| 599 | 599 | if ($ip != null) |
| 600 | 600 | { |
@@ -602,10 +602,10 @@ discard block |
||
| 602 | 602 | } |
| 603 | 603 | if ($oid != null) |
| 604 | 604 | { |
| 605 | - $condition=($condition===null)?'':$condition.' AND '; |
|
| 605 | + $condition=($condition === null) ? '' : $condition.' AND '; |
|
| 606 | 606 | $condition.="trap_oid='$oid'"; |
| 607 | 607 | } |
| 608 | - if($condition === null) return null; |
|
| 608 | + if ($condition === null) return null; |
|
| 609 | 609 | $query=$db->delete( |
| 610 | 610 | $this->getModuleConfig()->getTrapTableName(), |
| 611 | 611 | $condition |
@@ -619,10 +619,10 @@ discard block |
||
| 619 | 619 | * @param $ip string source IP (v4 or v6) |
| 620 | 620 | * @param $oid string oid |
| 621 | 621 | */ |
| 622 | - protected function countTrap($ip,$oid) |
|
| 622 | + protected function countTrap($ip, $oid) |
|
| 623 | 623 | { |
| 624 | 624 | |
| 625 | - $db = $this->getDb()->getConnection(); |
|
| 625 | + $db=$this->getDb()->getConnection(); |
|
| 626 | 626 | $condition=null; |
| 627 | 627 | if ($ip != null) |
| 628 | 628 | { |
@@ -630,10 +630,10 @@ discard block |
||
| 630 | 630 | } |
| 631 | 631 | if ($oid != null) |
| 632 | 632 | { |
| 633 | - $condition=($condition===null)?'':$condition.' AND '; |
|
| 633 | + $condition=($condition === null) ? '' : $condition.' AND '; |
|
| 634 | 634 | $condition.="trap_oid='$oid'"; |
| 635 | 635 | } |
| 636 | - if($condition === null) return 0; |
|
| 636 | + if ($condition === null) return 0; |
|
| 637 | 637 | $query=$db->select() |
| 638 | 638 | ->from( |
| 639 | 639 | $this->getModuleConfig()->getTrapTableName(), |
@@ -649,27 +649,27 @@ discard block |
||
| 649 | 649 | protected function getDBConfigValue($element) |
| 650 | 650 | { |
| 651 | 651 | |
| 652 | - $db = $this->getDb()->getConnection(); |
|
| 652 | + $db=$this->getDb()->getConnection(); |
|
| 653 | 653 | |
| 654 | 654 | $query=$db->select() |
| 655 | 655 | ->from( |
| 656 | 656 | $this->getModuleConfig()->getDbConfigTableName(), |
| 657 | 657 | array('value'=>'value')) |
| 658 | - ->where('name=?',$element); |
|
| 658 | + ->where('name=?', $element); |
|
| 659 | 659 | $return_row=$db->fetchRow($query); |
| 660 | - if ($return_row==null) // value does not exists |
|
| 660 | + if ($return_row == null) // value does not exists |
|
| 661 | 661 | { |
| 662 | 662 | $default=$this->getModuleConfig()->getDBConfigDefaults(); |
| 663 | - if ( ! isset($default[$element])) return null; // no default and not value |
|
| 663 | + if (!isset($default[$element])) return null; // no default and not value |
|
| 664 | 664 | |
| 665 | - $this->addDBConfigValue($element,$default[$element]); |
|
| 665 | + $this->addDBConfigValue($element, $default[$element]); |
|
| 666 | 666 | return $default[$element]; |
| 667 | 667 | } |
| 668 | 668 | if ($return_row->value == null) // value id empty |
| 669 | 669 | { |
| 670 | 670 | $default=$this->getModuleConfig()->getDBConfigDefaults(); |
| 671 | - if ( ! isset($default[$element])) return null; // no default and not value |
|
| 672 | - $this->setDBConfigValue($element,$default[$element]); |
|
| 671 | + if (!isset($default[$element])) return null; // no default and not value |
|
| 672 | + $this->setDBConfigValue($element, $default[$element]); |
|
| 673 | 673 | return $default[$element]; |
| 674 | 674 | } |
| 675 | 675 | return $return_row->value; |
@@ -680,10 +680,10 @@ discard block |
||
| 680 | 680 | * @param string $value : value |
| 681 | 681 | */ |
| 682 | 682 | |
| 683 | - protected function addDBConfigValue($element,$value) |
|
| 683 | + protected function addDBConfigValue($element, $value) |
|
| 684 | 684 | { |
| 685 | 685 | |
| 686 | - $db = $this->getDb()->getConnection(); |
|
| 686 | + $db=$this->getDb()->getConnection(); |
|
| 687 | 687 | |
| 688 | 688 | $query=$db->insert( |
| 689 | 689 | $this->getModuleConfig()->getDbConfigTableName(), |
@@ -699,10 +699,10 @@ discard block |
||
| 699 | 699 | * @param string $element : name of config element |
| 700 | 700 | * @param string $value : value |
| 701 | 701 | */ |
| 702 | - protected function setDBConfigValue($element,$value) |
|
| 702 | + protected function setDBConfigValue($element, $value) |
|
| 703 | 703 | { |
| 704 | 704 | |
| 705 | - $db = $this->getDb()->getConnection(); |
|
| 705 | + $db=$this->getDb()->getConnection(); |
|
| 706 | 706 | $query=$db->update( |
| 707 | 707 | $this->getModuleConfig()->getDbConfigTableName(), |
| 708 | 708 | array('value'=>$value), |
@@ -717,10 +717,10 @@ discard block |
||
| 717 | 717 | protected function isDirectorInstalled() |
| 718 | 718 | { |
| 719 | 719 | $output=array(); |
| 720 | - exec('icingacli module list',$output); |
|
| 720 | + exec('icingacli module list', $output); |
|
| 721 | 721 | foreach ($output as $line) |
| 722 | 722 | { |
| 723 | - if (preg_match('/^director .*enabled/',$line)) |
|
| 723 | + if (preg_match('/^director .*enabled/', $line)) |
|
| 724 | 724 | { |
| 725 | 725 | return true; |
| 726 | 726 | } |
@@ -42,30 +42,30 @@ discard block |
||
| 42 | 42 | * @param string $DBname Name of DB |
| 43 | 43 | * @return NULL|array |
| 44 | 44 | */ |
| 45 | - protected function testDbVersion($dbAdapter,int $min,bool $test, string $DBname) |
|
| 45 | + protected function testDbVersion($dbAdapter, int $min, bool $test, string $DBname) |
|
| 46 | 46 | { |
| 47 | 47 | try |
| 48 | 48 | { |
| 49 | - $query = $dbAdapter->select() |
|
| 50 | - ->from($this->trapController->getModuleConfig()->getDbConfigTableName(),'value') |
|
| 49 | + $query=$dbAdapter->select() |
|
| 50 | + ->from($this->trapController->getModuleConfig()->getDbConfigTableName(), 'value') |
|
| 51 | 51 | ->where('name=\'db_version\''); |
| 52 | 52 | $version=$dbAdapter->fetchRow($query); |
| 53 | - if ( ($version == null) || ! property_exists($version,'value') ) |
|
| 53 | + if (($version == null) || !property_exists($version, 'value')) |
|
| 54 | 54 | { |
| 55 | - if ($test) return array(4,$DBname); |
|
| 55 | + if ($test) return array(4, $DBname); |
|
| 56 | 56 | $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
| 57 | 57 | return null; |
| 58 | 58 | } |
| 59 | 59 | if ($version->value < $min) |
| 60 | 60 | { |
| 61 | - if ($test) return array(5,$version->value,$min); |
|
| 61 | + if ($test) return array(5, $version->value, $min); |
|
| 62 | 62 | $this->trapController->redirectNow('trapdirector/settings?dberror=5'); |
| 63 | 63 | return null; |
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | catch (Exception $e) |
| 67 | 67 | { |
| 68 | - if ($test) return array(3,$DBname,$e->getMessage()); |
|
| 68 | + if ($test) return array(3, $DBname, $e->getMessage()); |
|
| 69 | 69 | $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
| 70 | 70 | } |
| 71 | 71 | return null; |
@@ -77,15 +77,15 @@ discard block |
||
| 77 | 77 | * @param $test_version bool if set to flase, does not test database version of trapDB |
| 78 | 78 | * @return Zend_Db_Adapter_Abstract|array|null : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
| 79 | 79 | */ |
| 80 | - protected function getDbByName($DBname,$test=false,$test_version=true) |
|
| 80 | + protected function getDbByName($DBname, $test=false, $test_version=true) |
|
| 81 | 81 | { |
| 82 | 82 | try |
| 83 | 83 | { |
| 84 | - $dbconn = IcingaDbConnection::fromResourceName($DBname); |
|
| 84 | + $dbconn=IcingaDbConnection::fromResourceName($DBname); |
|
| 85 | 85 | } |
| 86 | 86 | catch (Exception $e) |
| 87 | 87 | { |
| 88 | - if ($test) return array(2,$DBname); |
|
| 88 | + if ($test) return array(2, $DBname); |
|
| 89 | 89 | $this->trapController->redirectNow('trapdirector/settings?dberror=2'); |
| 90 | 90 | return null; |
| 91 | 91 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | } |
| 98 | 98 | catch (Exception $e) |
| 99 | 99 | { |
| 100 | - if ($test) return array(3,$DBname,$e->getMessage()); |
|
| 100 | + if ($test) return array(3, $DBname, $e->getMessage()); |
|
| 101 | 101 | $this->trapController->redirectNow('trapdirector/settings?dberror=3'); |
| 102 | 102 | return null; |
| 103 | 103 | } |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | return $testRet; |
| 110 | 110 | } |
| 111 | 111 | } |
| 112 | - if ($test) return array(0,''); |
|
| 112 | + if ($test) return array(0, ''); |
|
| 113 | 113 | return $dbAdapter; |
| 114 | 114 | } |
| 115 | 115 | |
@@ -120,17 +120,17 @@ discard block |
||
| 120 | 120 | */ |
| 121 | 121 | public function getDb($test=false) |
| 122 | 122 | { |
| 123 | - if ($this->trapDB != null && $test = false) return $this->trapDB; |
|
| 123 | + if ($this->trapDB != null && $test=false) return $this->trapDB; |
|
| 124 | 124 | |
| 125 | 125 | $dbresource=$this->trapController->Config()->get('config', 'database'); |
| 126 | 126 | |
| 127 | - if ( ! $dbresource ) |
|
| 127 | + if (!$dbresource) |
|
| 128 | 128 | { |
| 129 | - if ($test) return array(1,''); |
|
| 129 | + if ($test) return array(1, ''); |
|
| 130 | 130 | $this->redirectNow('trapdirector/settings?dberror=1'); |
| 131 | 131 | return null; |
| 132 | 132 | } |
| 133 | - $retDB=$this->getDbByName($dbresource,$test,true); |
|
| 133 | + $retDB=$this->getDbByName($dbresource, $test, true); |
|
| 134 | 134 | |
| 135 | 135 | if ($test === true) return $retDB; |
| 136 | 136 | |
@@ -145,50 +145,50 @@ discard block |
||
| 145 | 145 | */ |
| 146 | 146 | public function getIdoDb($test=false) |
| 147 | 147 | { |
| 148 | - if ($this->idoDB != null && $test = false) return $this->idoDB; |
|
| 148 | + if ($this->idoDB != null && $test=false) return $this->idoDB; |
|
| 149 | 149 | // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
| 150 | - $dbresource=$this->Config()->get('config', 'IDOdatabase');; |
|
| 150 | + $dbresource=$this->Config()->get('config', 'IDOdatabase'); ; |
|
| 151 | 151 | |
| 152 | - if ( ! $dbresource ) |
|
| 152 | + if (!$dbresource) |
|
| 153 | 153 | { |
| 154 | - if ($test) return array(1,'No database in config.ini'); |
|
| 154 | + if ($test) return array(1, 'No database in config.ini'); |
|
| 155 | 155 | $this->redirectNow('trapdirector/settings?idodberror=1'); |
| 156 | 156 | return null; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | try |
| 160 | 160 | { |
| 161 | - $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
| 161 | + $dbconn=IcingaDbConnection::fromResourceName($dbresource); |
|
| 162 | 162 | } |
| 163 | 163 | catch (Exception $e) |
| 164 | 164 | { |
| 165 | - if ($test) return array(2,"Database $dbresource does not exists in IcingaWeb2"); |
|
| 165 | + if ($test) return array(2, "Database $dbresource does not exists in IcingaWeb2"); |
|
| 166 | 166 | $this->redirectNow('trapdirector/settings?idodberror=2'); |
| 167 | 167 | return null; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | if ($test == false) |
| 171 | 171 | { |
| 172 | - $this->idoDB = $dbconn->getDbAdapter(); |
|
| 172 | + $this->idoDB=$dbconn->getDbAdapter(); |
|
| 173 | 173 | return $this->idoDB; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | try |
| 177 | 177 | { |
| 178 | - $query = $dbconn->select() |
|
| 179 | - ->from('icinga_dbversion',array('version')); |
|
| 178 | + $query=$dbconn->select() |
|
| 179 | + ->from('icinga_dbversion', array('version')); |
|
| 180 | 180 | $version=$dbconn->fetchRow($query); |
| 181 | - if ( ($version == null) || ! property_exists($version,'version') ) |
|
| 181 | + if (($version == null) || !property_exists($version, 'version')) |
|
| 182 | 182 | { |
| 183 | - return array(4,"$dbresource does not look like an IDO database"); |
|
| 183 | + return array(4, "$dbresource does not look like an IDO database"); |
|
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | 186 | catch (Exception $e) |
| 187 | 187 | { |
| 188 | - return array(3,"Error connecting to $dbresource : " . $e->getMessage()); |
|
| 188 | + return array(3, "Error connecting to $dbresource : ".$e->getMessage()); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - return array(0,''); |
|
| 191 | + return array(0, ''); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | } |
| 195 | 195 | \ No newline at end of file |