@@ -21,104 +21,104 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class NetworkRule extends PluginTemplate |
| 23 | 23 | { |
| 24 | - /** @var string $description Description of plugin */ |
|
| 25 | - public $description='Network functions to use into rules |
|
| 24 | + /** @var string $description Description of plugin */ |
|
| 25 | + public $description='Network functions to use into rules |
|
| 26 | 26 | test test test'; |
| 27 | 27 | |
| 28 | - /** @var array[] $functions Functions of this plugin for rule eval. |
|
| 29 | - * If no functions are declared, set to empty array |
|
| 30 | - * $functions[<name>]['function'] : Name of the function to be called in this class |
|
| 31 | - * $functions[<name>]['params'] : Description of input parameters of function. |
|
| 32 | - * $functions[<name>]['description'] : Description. Can be multiline. |
|
| 33 | - */ |
|
| 34 | - public $functions=array( |
|
| 35 | - 'inNetwork' => array( // The name of the function in rules |
|
| 36 | - 'function' => 'isInNetwork', // Name of the function |
|
| 37 | - 'params' => '<IP to test>,<Network IP>,<Network mask (CIDR)>', // parameters description |
|
| 38 | - 'description' => 'Test if IP is in network, ex : __inNetwork(192.168.123.5,192.168.123.0,24) returns true |
|
| 28 | + /** @var array[] $functions Functions of this plugin for rule eval. |
|
| 29 | + * If no functions are declared, set to empty array |
|
| 30 | + * $functions[<name>]['function'] : Name of the function to be called in this class |
|
| 31 | + * $functions[<name>]['params'] : Description of input parameters of function. |
|
| 32 | + * $functions[<name>]['description'] : Description. Can be multiline. |
|
| 33 | + */ |
|
| 34 | + public $functions=array( |
|
| 35 | + 'inNetwork' => array( // The name of the function in rules |
|
| 36 | + 'function' => 'isInNetwork', // Name of the function |
|
| 37 | + 'params' => '<IP to test>,<Network IP>,<Network mask (CIDR)>', // parameters description |
|
| 38 | + 'description' => 'Test if IP is in network, ex : __inNetwork(192.168.123.5,192.168.123.0,24) returns true |
|
| 39 | 39 | Does not work with IPV6' // Description (can be multiline). |
| 40 | - ), |
|
| 41 | - 'test' => array( // The name of the function in rules |
|
| 42 | - 'function' => 'testParam', // Name of the function |
|
| 43 | - 'params' => '<boolean to return as string>', // parameters description |
|
| 44 | - 'description' => 'Returns value passed as argument' // Description (can be multiline). |
|
| 45 | - ) |
|
| 46 | - ); |
|
| 40 | + ), |
|
| 41 | + 'test' => array( // The name of the function in rules |
|
| 42 | + 'function' => 'testParam', // Name of the function |
|
| 43 | + 'params' => '<boolean to return as string>', // parameters description |
|
| 44 | + 'description' => 'Returns value passed as argument' // Description (can be multiline). |
|
| 45 | + ) |
|
| 46 | + ); |
|
| 47 | 47 | |
| 48 | - /** @var boolean $catchAllTraps Set to true if all traps will be sent to the plugin NOT IMPLEMENTED */ |
|
| 49 | - public $catchAllTraps=false; |
|
| 48 | + /** @var boolean $catchAllTraps Set to true if all traps will be sent to the plugin NOT IMPLEMENTED */ |
|
| 49 | + public $catchAllTraps=false; |
|
| 50 | 50 | |
| 51 | - /** @var boolean $processTraps Set to true if plugins can handle traps NOT IMPLEMENTED */ |
|
| 52 | - public $processTraps=false; |
|
| 51 | + /** @var boolean $processTraps Set to true if plugins can handle traps NOT IMPLEMENTED */ |
|
| 52 | + public $processTraps=false; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Constructor. Can throw exceptions on error, but no logging at this point. |
|
| 56 | - * @throws \Exception |
|
| 57 | - * @return \Trapdirector\Plugins\NetworkRule |
|
| 58 | - */ |
|
| 59 | - function __construct() |
|
| 60 | - { |
|
| 61 | - $this->name=basename(__FILE__,'.php'); |
|
| 62 | - return $this; |
|
| 63 | - } |
|
| 54 | + /** |
|
| 55 | + * Constructor. Can throw exceptions on error, but no logging at this point. |
|
| 56 | + * @throws \Exception |
|
| 57 | + * @return \Trapdirector\Plugins\NetworkRule |
|
| 58 | + */ |
|
| 59 | + function __construct() |
|
| 60 | + { |
|
| 61 | + $this->name=basename(__FILE__,'.php'); |
|
| 62 | + return $this; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Function called by trapdirector if found in rules |
|
| 67 | - * Parameters check has to be done in function. |
|
| 68 | - * @param array $params Function parameters |
|
| 69 | - * @throws Exception |
|
| 70 | - * @return bool Evaluation |
|
| 71 | - */ |
|
| 72 | - public function isInNetwork(array $params) : bool |
|
| 73 | - { |
|
| 74 | - // Check param numbers and thrown exception if not correct. |
|
| 75 | - if (count($params)!=3) |
|
| 76 | - { |
|
| 77 | - throw new Exception('Invalid number of parameters : ' . count($params)); |
|
| 78 | - } |
|
| 65 | + /** |
|
| 66 | + * Function called by trapdirector if found in rules |
|
| 67 | + * Parameters check has to be done in function. |
|
| 68 | + * @param array $params Function parameters |
|
| 69 | + * @throws Exception |
|
| 70 | + * @return bool Evaluation |
|
| 71 | + */ |
|
| 72 | + public function isInNetwork(array $params) : bool |
|
| 73 | + { |
|
| 74 | + // Check param numbers and thrown exception if not correct. |
|
| 75 | + if (count($params)!=3) |
|
| 76 | + { |
|
| 77 | + throw new Exception('Invalid number of parameters : ' . count($params)); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - $ip = $params[0]; |
|
| 81 | - $net = $params[1]; |
|
| 82 | - $masq = $params[2]; |
|
| 80 | + $ip = $params[0]; |
|
| 81 | + $net = $params[1]; |
|
| 82 | + $masq = $params[2]; |
|
| 83 | 83 | |
| 84 | 84 | |
| 85 | - $this->log('#'. $ip . '# / #' . $net . '# / #' . $masq,DEBUG); |
|
| 85 | + $this->log('#'. $ip . '# / #' . $net . '# / #' . $masq,DEBUG); |
|
| 86 | 86 | |
| 87 | - $ip2 = ip2long($ip); |
|
| 88 | - $net2 = ip2long($net); |
|
| 87 | + $ip2 = ip2long($ip); |
|
| 88 | + $net2 = ip2long($net); |
|
| 89 | 89 | |
| 90 | - if ($ip2 === false ) |
|
| 91 | - { |
|
| 92 | - $this->log('Invalid IP : #' . $ip.'#',WARN); |
|
| 93 | - throw new Exception('Invalid IP'); |
|
| 94 | - } |
|
| 95 | - if ($net2 === false) |
|
| 96 | - { |
|
| 97 | - $this->log('Invalid network',WARN); |
|
| 98 | - throw new Exception('Invalid net'); |
|
| 99 | - } |
|
| 100 | - if ($masq<1 || $masq > 32) |
|
| 101 | - { |
|
| 102 | - $this->log('Invalid masq',WARN); |
|
| 103 | - throw new Exception('Invalid net masq'); |
|
| 104 | - } |
|
| 105 | - // $range is in IP/CIDR format eg 127.0.0.1/24 |
|
| 90 | + if ($ip2 === false ) |
|
| 91 | + { |
|
| 92 | + $this->log('Invalid IP : #' . $ip.'#',WARN); |
|
| 93 | + throw new Exception('Invalid IP'); |
|
| 94 | + } |
|
| 95 | + if ($net2 === false) |
|
| 96 | + { |
|
| 97 | + $this->log('Invalid network',WARN); |
|
| 98 | + throw new Exception('Invalid net'); |
|
| 99 | + } |
|
| 100 | + if ($masq<1 || $masq > 32) |
|
| 101 | + { |
|
| 102 | + $this->log('Invalid masq',WARN); |
|
| 103 | + throw new Exception('Invalid net masq'); |
|
| 104 | + } |
|
| 105 | + // $range is in IP/CIDR format eg 127.0.0.1/24 |
|
| 106 | 106 | |
| 107 | - $masq = pow( 2, ( 32 - $masq ) ) - 1; |
|
| 108 | - $masq = ~ $masq; |
|
| 109 | - return ( ( $ip2 & $masq ) == ( $net2 & $masq ) ); |
|
| 107 | + $masq = pow( 2, ( 32 - $masq ) ) - 1; |
|
| 108 | + $masq = ~ $masq; |
|
| 109 | + return ( ( $ip2 & $masq ) == ( $net2 & $masq ) ); |
|
| 110 | 110 | |
| 111 | - } |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - public function testParam(array $param) |
|
| 114 | - { |
|
| 115 | - if (count($param)!=1) |
|
| 116 | - { |
|
| 117 | - throw new Exception('Invalid number of parameters : ' . count($param)); |
|
| 118 | - } |
|
| 119 | - if ($param[0] == 'true') return true; |
|
| 120 | - return false; |
|
| 121 | - } |
|
| 113 | + public function testParam(array $param) |
|
| 114 | + { |
|
| 115 | + if (count($param)!=1) |
|
| 116 | + { |
|
| 117 | + throw new Exception('Invalid number of parameters : ' . count($param)); |
|
| 118 | + } |
|
| 119 | + if ($param[0] == 'true') return true; |
|
| 120 | + return false; |
|
| 121 | + } |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | |
@@ -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; } |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | |
| 44 | 44 | |
| 45 | 45 | /** Get instance of TrapModuleConfig class |
| 46 | - * @return TrapModuleConfig |
|
| 47 | - */ |
|
| 46 | + * @return TrapModuleConfig |
|
| 47 | + */ |
|
| 48 | 48 | public function getModuleConfig() |
| 49 | 49 | { |
| 50 | 50 | if ($this->moduleConfig == Null) |
@@ -73,12 +73,12 @@ discard block |
||
| 73 | 73 | |
| 74 | 74 | public function getTrapHostListTable() |
| 75 | 75 | { |
| 76 | - if ($this->trapTableHostList == Null) |
|
| 76 | + if ($this->trapTableHostList == Null) |
|
| 77 | 77 | { |
| 78 | - $this->trapTableHostList = new TrapTableHostList(); |
|
| 79 | - $this->trapTableHostList->setConfig($this->getModuleConfig()); |
|
| 80 | - } |
|
| 81 | - return $this->trapTableHostList; |
|
| 78 | + $this->trapTableHostList = new TrapTableHostList(); |
|
| 79 | + $this->trapTableHostList->setConfig($this->getModuleConfig()); |
|
| 80 | + } |
|
| 81 | + return $this->trapTableHostList; |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | public function getHandlerListTable() |
@@ -92,11 +92,11 @@ discard block |
||
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** Get Database connexion |
| 95 | - * @param $DBname string DB name in resource.ini_ge |
|
| 96 | - * @param $test bool if set to true, returns error code and not database |
|
| 97 | - * @param $test_version bool if set to flase, does not test database version of trapDB |
|
| 98 | - * @return array<integer,mixed>|mixed : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
|
| 99 | - */ |
|
| 95 | + * @param $DBname string DB name in resource.ini_ge |
|
| 96 | + * @param $test bool if set to true, returns error code and not database |
|
| 97 | + * @param $test_version bool if set to flase, does not test database version of trapDB |
|
| 98 | + * @return array<integer,mixed>|mixed : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
|
| 99 | + */ |
|
| 100 | 100 | public function getDbByName($DBname,$test=false,$test_version=true) |
| 101 | 101 | { |
| 102 | 102 | try |
@@ -181,20 +181,20 @@ discard block |
||
| 181 | 181 | |
| 182 | 182 | if ( ! $dbresource ) |
| 183 | 183 | { |
| 184 | - if ($test) return array(1,'No database in config.ini'); |
|
| 185 | - $this->redirectNow('trapdirector/settings?idodberror=1'); |
|
| 186 | - return null; |
|
| 184 | + if ($test) return array(1,'No database in config.ini'); |
|
| 185 | + $this->redirectNow('trapdirector/settings?idodberror=1'); |
|
| 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"); |
|
| 196 | - $this->redirectNow('trapdirector/settings?idodberror=2'); |
|
| 197 | - return null; |
|
| 195 | + if ($test) return array(2,"Database $dbresource does not exists in IcingaWeb2"); |
|
| 196 | + $this->redirectNow('trapdirector/settings?idodberror=2'); |
|
| 197 | + return null; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | if ($test == false) |
@@ -205,13 +205,13 @@ discard block |
||
| 205 | 205 | |
| 206 | 206 | try |
| 207 | 207 | { |
| 208 | - $query = $dbconn->select() |
|
| 209 | - ->from('icinga_dbversion',array('version')); |
|
| 210 | - $version=$dbconn->fetchRow($query); |
|
| 211 | - if ( ($version == null) || ! property_exists($version,'version') ) |
|
| 212 | - { |
|
| 213 | - return array(4,"$dbresource does not look like an IDO database"); |
|
| 214 | - } |
|
| 208 | + $query = $dbconn->select() |
|
| 209 | + ->from('icinga_dbversion',array('version')); |
|
| 210 | + $version=$dbconn->fetchRow($query); |
|
| 211 | + if ( ($version == null) || ! property_exists($version,'version') ) |
|
| 212 | + { |
|
| 213 | + return array(4,"$dbresource does not look like an IDO database"); |
|
| 214 | + } |
|
| 215 | 215 | } |
| 216 | 216 | catch (Exception $e) |
| 217 | 217 | { |
@@ -221,15 +221,15 @@ discard block |
||
| 221 | 221 | return array(0,''); |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null) |
|
| 225 | - { |
|
| 226 | - $limit = $this->params->get('limit', $limit); |
|
| 227 | - $page = $this->params->get('page', $offset); |
|
| 224 | + protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null) |
|
| 225 | + { |
|
| 226 | + $limit = $this->params->get('limit', $limit); |
|
| 227 | + $page = $this->params->get('page', $offset); |
|
| 228 | 228 | |
| 229 | - $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0); |
|
| 229 | + $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0); |
|
| 230 | 230 | |
| 231 | - return $paginatable; |
|
| 232 | - } |
|
| 231 | + return $paginatable; |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | 234 | public function displayExitError($source,$message) |
| 235 | 235 | { // TODO : check better ways to transmit data (with POST ?) |
@@ -238,33 +238,33 @@ discard block |
||
| 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'); |
|
| 243 | - } |
|
| 241 | + if (! $this->Auth()->hasPermission('trapdirector/view')) { |
|
| 242 | + $this->displayExitError('Permissions','No permission fo view content'); |
|
| 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'); |
|
| 250 | - } |
|
| 248 | + if (! $this->Auth()->hasPermission('trapdirector/config')) { |
|
| 249 | + $this->displayExitError('Permissions','No permission fo configure'); |
|
| 250 | + } |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | - /** |
|
| 254 | - * Check if user has write permission |
|
| 255 | - * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page |
|
| 256 | - * @return boolean : user has permission |
|
| 257 | - */ |
|
| 253 | + /** |
|
| 254 | + * Check if user has write permission |
|
| 255 | + * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page |
|
| 256 | + * @return boolean : user has permission |
|
| 257 | + */ |
|
| 258 | 258 | protected function checkModuleConfigPermission($check=0) |
| 259 | 259 | { |
| 260 | - if (! $this->Auth()->hasPermission('trapdirector/module_config')) { |
|
| 261 | - if ($check == 0) |
|
| 262 | - { |
|
| 263 | - $this->displayExitError('Permissions','No permission fo configure module'); |
|
| 264 | - } |
|
| 265 | - return false; |
|
| 266 | - } |
|
| 267 | - return true; |
|
| 260 | + if (! $this->Auth()->hasPermission('trapdirector/module_config')) { |
|
| 261 | + if ($check == 0) |
|
| 262 | + { |
|
| 263 | + $this->displayExitError('Permissions','No permission fo configure module'); |
|
| 264 | + } |
|
| 265 | + return false; |
|
| 266 | + } |
|
| 267 | + return true; |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | /************************* Trap class get **********************/ |
@@ -284,8 +284,8 @@ discard block |
||
| 284 | 284 | /************************** MIB related **************************/ |
| 285 | 285 | |
| 286 | 286 | /** Get MIBLoader class |
| 287 | - * @return MIBLoader class |
|
| 288 | - */ |
|
| 287 | + * @return MIBLoader class |
|
| 288 | + */ |
|
| 289 | 289 | protected function getMIB() |
| 290 | 290 | { |
| 291 | 291 | if ($this->MIBData == null) |
@@ -303,9 +303,9 @@ discard block |
||
| 303 | 303 | /************************** Database queries *******************/ |
| 304 | 304 | |
| 305 | 305 | /** Get host(s) by IP (v4 or v6) or by name in IDO database |
| 306 | - * does not catch exceptions |
|
| 307 | - * @return array of objects ( name, id (object_id), display_name) |
|
| 308 | - */ |
|
| 306 | + * does not catch exceptions |
|
| 307 | + * @return array of objects ( name, id (object_id), display_name) |
|
| 308 | + */ |
|
| 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 |
@@ -324,9 +324,9 @@ discard block |
||
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | /** Get host(s) by name in IDO database |
| 327 | - * does not catch exceptions |
|
| 328 | - * @return array of objects ( name, id (object_id), display_name) |
|
| 329 | - */ |
|
| 327 | + * does not catch exceptions |
|
| 328 | + * @return array of objects ( name, id (object_id), display_name) |
|
| 329 | + */ |
|
| 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 |
@@ -345,9 +345,9 @@ discard block |
||
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | /** Get host groups by name in IDO database |
| 348 | - * does not catch exceptions |
|
| 349 | - * @return array of objects ( name, id (object_id), display_name) |
|
| 350 | - */ |
|
| 348 | + * does not catch exceptions |
|
| 349 | + * @return array of objects ( name, id (object_id), display_name) |
|
| 350 | + */ |
|
| 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 |
@@ -367,9 +367,9 @@ discard block |
||
| 367 | 367 | |
| 368 | 368 | |
| 369 | 369 | /** Get host IP (v4 and v6) by name in IDO database |
| 370 | - * does not catch exceptions |
|
| 371 | - * @return array ( name, display_name, ip4, ip6) |
|
| 372 | - */ |
|
| 370 | + * does not catch exceptions |
|
| 371 | + * @return array ( name, display_name, ip4, ip6) |
|
| 372 | + */ |
|
| 373 | 373 | protected function getHostInfoByID($id) |
| 374 | 374 | { |
| 375 | 375 | if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
@@ -388,9 +388,9 @@ discard block |
||
| 388 | 388 | |
| 389 | 389 | |
| 390 | 390 | /** Get host by objectid in IDO database |
| 391 | - * does not catch exceptions |
|
| 392 | - * @return array of objects ( id, name, display_name, ip, ip6, ) |
|
| 393 | - */ |
|
| 391 | + * does not catch exceptions |
|
| 392 | + * @return array of objects ( id, name, display_name, ip, ip6, ) |
|
| 393 | + */ |
|
| 394 | 394 | protected function getHostByObjectID($id) // TODO : duplicate of getHostInfoByID above |
| 395 | 395 | { |
| 396 | 396 | if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
@@ -408,10 +408,10 @@ discard block |
||
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | /** Get services from object ( host_object_id) in IDO database |
| 411 | - * does not catch exceptions |
|
| 412 | - * @param $id int object_id |
|
| 413 | - * @return array display_name (of service), service_object_id |
|
| 414 | - */ |
|
| 411 | + * does not catch exceptions |
|
| 412 | + * @param $id int object_id |
|
| 413 | + * @return array display_name (of service), service_object_id |
|
| 414 | + */ |
|
| 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 |
@@ -430,11 +430,11 @@ discard block |
||
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | /** Get services from hostgroup object id ( hostgroup_object_id) in IDO database |
| 433 | - * gets all hosts in hostgroup and return common services |
|
| 434 | - * does not catch exceptions |
|
| 435 | - * @param $id int object_id |
|
| 436 | - * @return array display_name (of service), service_object_id |
|
| 437 | - */ |
|
| 433 | + * gets all hosts in hostgroup and return common services |
|
| 434 | + * does not catch exceptions |
|
| 435 | + * @param $id int object_id |
|
| 436 | + * @return array display_name (of service), service_object_id |
|
| 437 | + */ |
|
| 438 | 438 | protected function getServicesByHostGroupid($id) |
| 439 | 439 | { |
| 440 | 440 | if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
@@ -472,7 +472,7 @@ discard block |
||
| 472 | 472 | //print_r($common_services); |
| 473 | 473 | foreach (array_keys($common_services) as $key) |
| 474 | 474 | { |
| 475 | - if ($common_services[$key]['num'] == $num_hosts) |
|
| 475 | + if ($common_services[$key]['num'] == $num_hosts) |
|
| 476 | 476 | { |
| 477 | 477 | array_push($result,array($key,$common_services[$key]['name'])); |
| 478 | 478 | } |
@@ -482,11 +482,11 @@ discard block |
||
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | /** Get services object id by host name / service name in IDO database |
| 485 | - * does not catch exceptions |
|
| 486 | - * @param $hostname string host name |
|
| 487 | - * @param $name string service name |
|
| 488 | - * @return array service id |
|
| 489 | - */ |
|
| 485 | + * does not catch exceptions |
|
| 486 | + * @param $hostname string host name |
|
| 487 | + * @param $name string service name |
|
| 488 | + * @return array service id |
|
| 489 | + */ |
|
| 490 | 490 | protected function getServiceIDByName($hostname,$name) |
| 491 | 491 | { |
| 492 | 492 | $db = $this->getIdoDb()->getConnection(); |
@@ -509,10 +509,10 @@ discard block |
||
| 509 | 509 | } |
| 510 | 510 | |
| 511 | 511 | /** Get object name from object_id in IDO database |
| 512 | - * does not catch exceptions |
|
| 513 | - * @param int $id object_id (default to null, used first if not null) |
|
| 514 | - * @return array name1 (host) name2 (service) |
|
| 515 | - */ |
|
| 512 | + * does not catch exceptions |
|
| 513 | + * @param int $id object_id (default to null, used first if not null) |
|
| 514 | + * @return array name1 (host) name2 (service) |
|
| 515 | + */ |
|
| 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 |
@@ -528,9 +528,9 @@ discard block |
||
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | /** Add handler rule in traps DB |
| 531 | - * @param array $params : array(<db item>=><value>) |
|
| 532 | - * @return int inserted id |
|
| 533 | - */ |
|
| 531 | + * @param array $params : array(<db item>=><value>) |
|
| 532 | + * @return int inserted id |
|
| 533 | + */ |
|
| 534 | 534 | protected function addHandlerRule($params) |
| 535 | 535 | { |
| 536 | 536 | // TODO Check for rule consistency |
@@ -552,10 +552,10 @@ discard block |
||
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | /** Update handler rule in traps DB |
| 555 | - * @param array $params : (<db item>=><value>) |
|
| 556 | - * @param integer $ruleID : rule id in db |
|
| 557 | - * @return array affected rows |
|
| 558 | - */ |
|
| 555 | + * @param array $params : (<db item>=><value>) |
|
| 556 | + * @param integer $ruleID : rule id in db |
|
| 557 | + * @return array affected rows |
|
| 558 | + */ |
|
| 559 | 559 | protected function updateHandlerRule($params,$ruleID) |
| 560 | 560 | { |
| 561 | 561 | // TODO Check for rule consistency |
@@ -573,8 +573,8 @@ discard block |
||
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | /** Delete rule by id |
| 576 | - * @param int $ruleID rule id |
|
| 577 | - */ |
|
| 576 | + * @param int $ruleID rule id |
|
| 577 | + */ |
|
| 578 | 578 | protected function deleteRule($ruleID) |
| 579 | 579 | { |
| 580 | 580 | if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id'); } |
@@ -588,9 +588,9 @@ discard block |
||
| 588 | 588 | } |
| 589 | 589 | |
| 590 | 590 | /** Delete trap by ip & oid |
| 591 | - * @param $ip string source IP (v4 or v6) |
|
| 592 | - * @param $oid string oid |
|
| 593 | - */ |
|
| 591 | + * @param $ip string source IP (v4 or v6) |
|
| 592 | + * @param $oid string oid |
|
| 593 | + */ |
|
| 594 | 594 | protected function deleteTrap($ip,$oid) |
| 595 | 595 | { |
| 596 | 596 | |
@@ -616,9 +616,9 @@ discard block |
||
| 616 | 616 | |
| 617 | 617 | |
| 618 | 618 | /** count trap by ip & oid |
| 619 | - * @param $ip string source IP (v4 or v6) |
|
| 620 | - * @param $oid string oid |
|
| 621 | - */ |
|
| 619 | + * @param $ip string source IP (v4 or v6) |
|
| 620 | + * @param $oid string oid |
|
| 621 | + */ |
|
| 622 | 622 | protected function countTrap($ip,$oid) |
| 623 | 623 | { |
| 624 | 624 | |
@@ -644,8 +644,8 @@ discard block |
||
| 644 | 644 | } |
| 645 | 645 | |
| 646 | 646 | /** get configuration value |
| 647 | - * @param string $element : configuration name in db |
|
| 648 | - */ |
|
| 647 | + * @param string $element : configuration name in db |
|
| 648 | + */ |
|
| 649 | 649 | protected function getDBConfigValue($element) |
| 650 | 650 | { |
| 651 | 651 | |
@@ -676,9 +676,9 @@ discard block |
||
| 676 | 676 | } |
| 677 | 677 | |
| 678 | 678 | /** add configuration value |
| 679 | - * @param string $element : name of config element |
|
| 680 | - * @param string $value : value |
|
| 681 | - */ |
|
| 679 | + * @param string $element : name of config element |
|
| 680 | + * @param string $value : value |
|
| 681 | + */ |
|
| 682 | 682 | |
| 683 | 683 | protected function addDBConfigValue($element,$value) |
| 684 | 684 | { |
@@ -696,9 +696,9 @@ discard block |
||
| 696 | 696 | } |
| 697 | 697 | |
| 698 | 698 | /** set configuration value |
| 699 | - * @param string $element : name of config element |
|
| 700 | - * @param string $value : value |
|
| 701 | - */ |
|
| 699 | + * @param string $element : name of config element |
|
| 700 | + * @param string $value : value |
|
| 701 | + */ |
|
| 702 | 702 | protected function setDBConfigValue($element,$value) |
| 703 | 703 | { |
| 704 | 704 | |
@@ -712,13 +712,13 @@ discard block |
||
| 712 | 712 | } |
| 713 | 713 | |
| 714 | 714 | /** Check if director is installed |
| 715 | - * @return bool true/false |
|
| 716 | - */ |
|
| 715 | + * @return bool true/false |
|
| 716 | + */ |
|
| 717 | 717 | protected function isDirectorInstalled() |
| 718 | 718 | { |
| 719 | - $output=array(); |
|
| 720 | - exec('icingacli module list',$output); |
|
| 721 | - foreach ($output as $line) |
|
| 719 | + $output=array(); |
|
| 720 | + exec('icingacli module list',$output); |
|
| 721 | + foreach ($output as $line) |
|
| 722 | 722 | { |
| 723 | 723 | if (preg_match('/^director .*enabled/',$line)) |
| 724 | 724 | { |
@@ -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 | } |
@@ -15,180 +15,180 @@ |
||
| 15 | 15 | class UIDatabase |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** @var TrapsController $trapController TrapController 'parent' class */ |
|
| 19 | - private $trapController; |
|
| 18 | + /** @var TrapsController $trapController TrapController 'parent' class */ |
|
| 19 | + private $trapController; |
|
| 20 | 20 | |
| 21 | - /** @var Zend_Db_Adapter_Abstract $trapDB Trap Database*/ |
|
| 22 | - private $trapDB; |
|
| 21 | + /** @var Zend_Db_Adapter_Abstract $trapDB Trap Database*/ |
|
| 22 | + private $trapDB; |
|
| 23 | 23 | |
| 24 | - /** @var Zend_Db_Adapter_Abstract $trapDB Icinga IDO database*/ |
|
| 25 | - private $idoDB; |
|
| 24 | + /** @var Zend_Db_Adapter_Abstract $trapDB Icinga IDO database*/ |
|
| 25 | + private $idoDB; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * |
|
| 29 | - * @param TrapsController $trapCtrl |
|
| 30 | - */ |
|
| 31 | - function __construct(TrapsController $trapCtrl) |
|
| 32 | - { |
|
| 33 | - $this->trapController=$trapCtrl; |
|
| 34 | - } |
|
| 27 | + /** |
|
| 28 | + * |
|
| 29 | + * @param TrapsController $trapCtrl |
|
| 30 | + */ |
|
| 31 | + function __construct(TrapsController $trapCtrl) |
|
| 32 | + { |
|
| 33 | + $this->trapController=$trapCtrl; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Test if database version >= min database version |
|
| 38 | - * |
|
| 39 | - * @param \Zend_Db_Adapter_Abstract $dbConn |
|
| 40 | - * @param int $min Minimum version |
|
| 41 | - * @param bool $test Test mode |
|
| 42 | - * @param string $DBname Name of DB |
|
| 43 | - * @return NULL|array |
|
| 44 | - */ |
|
| 45 | - protected function testDbVersion($dbAdapter,int $min,bool $test, string $DBname) |
|
| 46 | - { |
|
| 47 | - try |
|
| 48 | - { |
|
| 49 | - $query = $dbAdapter->select() |
|
| 50 | - ->from($this->trapController->getModuleConfig()->getDbConfigTableName(),'value') |
|
| 51 | - ->where('name=\'db_version\''); |
|
| 52 | - $version=$dbAdapter->fetchRow($query); |
|
| 53 | - if ( ($version == null) || ! property_exists($version,'value') ) |
|
| 54 | - { |
|
| 55 | - if ($test) return array(4,$DBname); |
|
| 56 | - $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
|
| 57 | - return null; |
|
| 58 | - } |
|
| 59 | - if ($version->value < $min) |
|
| 60 | - { |
|
| 61 | - if ($test) return array(5,$version->value,$min); |
|
| 62 | - $this->trapController->redirectNow('trapdirector/settings?dberror=5'); |
|
| 63 | - return null; |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - catch (Exception $e) |
|
| 67 | - { |
|
| 68 | - if ($test) return array(3,$DBname,$e->getMessage()); |
|
| 69 | - $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
|
| 70 | - } |
|
| 71 | - return null; |
|
| 72 | - } |
|
| 36 | + /** |
|
| 37 | + * Test if database version >= min database version |
|
| 38 | + * |
|
| 39 | + * @param \Zend_Db_Adapter_Abstract $dbConn |
|
| 40 | + * @param int $min Minimum version |
|
| 41 | + * @param bool $test Test mode |
|
| 42 | + * @param string $DBname Name of DB |
|
| 43 | + * @return NULL|array |
|
| 44 | + */ |
|
| 45 | + protected function testDbVersion($dbAdapter,int $min,bool $test, string $DBname) |
|
| 46 | + { |
|
| 47 | + try |
|
| 48 | + { |
|
| 49 | + $query = $dbAdapter->select() |
|
| 50 | + ->from($this->trapController->getModuleConfig()->getDbConfigTableName(),'value') |
|
| 51 | + ->where('name=\'db_version\''); |
|
| 52 | + $version=$dbAdapter->fetchRow($query); |
|
| 53 | + if ( ($version == null) || ! property_exists($version,'value') ) |
|
| 54 | + { |
|
| 55 | + if ($test) return array(4,$DBname); |
|
| 56 | + $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
|
| 57 | + return null; |
|
| 58 | + } |
|
| 59 | + if ($version->value < $min) |
|
| 60 | + { |
|
| 61 | + if ($test) return array(5,$version->value,$min); |
|
| 62 | + $this->trapController->redirectNow('trapdirector/settings?dberror=5'); |
|
| 63 | + return null; |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + catch (Exception $e) |
|
| 67 | + { |
|
| 68 | + if ($test) return array(3,$DBname,$e->getMessage()); |
|
| 69 | + $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
|
| 70 | + } |
|
| 71 | + return null; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** Get Database connexion |
|
| 75 | - * @param $DBname string DB name in resource.ini_ge |
|
| 76 | - * @param $test bool if set to true, returns error code and not database |
|
| 77 | - * @param $test_version bool if set to flase, does not test database version of trapDB |
|
| 78 | - * @return Zend_Db_Adapter_Abstract|array|null : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
|
| 79 | - */ |
|
| 80 | - protected function getDbByName($DBname,$test=false,$test_version=true) |
|
| 81 | - { |
|
| 82 | - try |
|
| 83 | - { |
|
| 84 | - $dbconn = IcingaDbConnection::fromResourceName($DBname); |
|
| 85 | - } |
|
| 86 | - catch (Exception $e) |
|
| 87 | - { |
|
| 88 | - if ($test) return array(2,$DBname); |
|
| 89 | - $this->trapController->redirectNow('trapdirector/settings?dberror=2'); |
|
| 90 | - return null; |
|
| 91 | - } |
|
| 74 | + /** Get Database connexion |
|
| 75 | + * @param $DBname string DB name in resource.ini_ge |
|
| 76 | + * @param $test bool if set to true, returns error code and not database |
|
| 77 | + * @param $test_version bool if set to flase, does not test database version of trapDB |
|
| 78 | + * @return Zend_Db_Adapter_Abstract|array|null : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
|
| 79 | + */ |
|
| 80 | + protected function getDbByName($DBname,$test=false,$test_version=true) |
|
| 81 | + { |
|
| 82 | + try |
|
| 83 | + { |
|
| 84 | + $dbconn = IcingaDbConnection::fromResourceName($DBname); |
|
| 85 | + } |
|
| 86 | + catch (Exception $e) |
|
| 87 | + { |
|
| 88 | + if ($test) return array(2,$DBname); |
|
| 89 | + $this->trapController->redirectNow('trapdirector/settings?dberror=2'); |
|
| 90 | + return null; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - try |
|
| 94 | - { |
|
| 95 | - $dbAdapter=$dbconn->getDbAdapter(); |
|
| 93 | + try |
|
| 94 | + { |
|
| 95 | + $dbAdapter=$dbconn->getDbAdapter(); |
|
| 96 | 96 | |
| 97 | - } |
|
| 98 | - catch (Exception $e) |
|
| 99 | - { |
|
| 100 | - if ($test) return array(3,$DBname,$e->getMessage()); |
|
| 101 | - $this->trapController->redirectNow('trapdirector/settings?dberror=3'); |
|
| 102 | - return null; |
|
| 103 | - } |
|
| 97 | + } |
|
| 98 | + catch (Exception $e) |
|
| 99 | + { |
|
| 100 | + if ($test) return array(3,$DBname,$e->getMessage()); |
|
| 101 | + $this->trapController->redirectNow('trapdirector/settings?dberror=3'); |
|
| 102 | + return null; |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - if ($test_version == true) { |
|
| 106 | - $testRet=$this->testDbVersion($dbAdapter, $this->trapController->getModuleConfig()->getDbMinVersion(), $test, $DBname); |
|
| 107 | - if ($testRet != null) |
|
| 108 | - { |
|
| 109 | - return $testRet; |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - if ($test) return array(0,''); |
|
| 113 | - return $dbAdapter; |
|
| 114 | - } |
|
| 105 | + if ($test_version == true) { |
|
| 106 | + $testRet=$this->testDbVersion($dbAdapter, $this->trapController->getModuleConfig()->getDbMinVersion(), $test, $DBname); |
|
| 107 | + if ($testRet != null) |
|
| 108 | + { |
|
| 109 | + return $testRet; |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + if ($test) return array(0,''); |
|
| 113 | + return $dbAdapter; |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - /** |
|
| 117 | - * Get Trap database |
|
| 118 | - * @param boolean $test |
|
| 119 | - * @return Zend_Db_Adapter_Abstract|array|null : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
|
| 120 | - */ |
|
| 121 | - public function getDb($test=false) |
|
| 122 | - { |
|
| 123 | - if ($this->trapDB != null && $test = false) return $this->trapDB; |
|
| 116 | + /** |
|
| 117 | + * Get Trap database |
|
| 118 | + * @param boolean $test |
|
| 119 | + * @return Zend_Db_Adapter_Abstract|array|null : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
|
| 120 | + */ |
|
| 121 | + public function getDb($test=false) |
|
| 122 | + { |
|
| 123 | + if ($this->trapDB != null && $test = false) return $this->trapDB; |
|
| 124 | 124 | |
| 125 | - $dbresource=$this->trapController->Config()->get('config', 'database'); |
|
| 125 | + $dbresource=$this->trapController->Config()->get('config', 'database'); |
|
| 126 | 126 | |
| 127 | - if ( ! $dbresource ) |
|
| 128 | - { |
|
| 129 | - if ($test) return array(1,''); |
|
| 130 | - $this->redirectNow('trapdirector/settings?dberror=1'); |
|
| 131 | - return null; |
|
| 132 | - } |
|
| 133 | - $retDB=$this->getDbByName($dbresource,$test,true); |
|
| 127 | + if ( ! $dbresource ) |
|
| 128 | + { |
|
| 129 | + if ($test) return array(1,''); |
|
| 130 | + $this->redirectNow('trapdirector/settings?dberror=1'); |
|
| 131 | + return null; |
|
| 132 | + } |
|
| 133 | + $retDB=$this->getDbByName($dbresource,$test,true); |
|
| 134 | 134 | |
| 135 | - if ($test === true) return $retDB; |
|
| 135 | + if ($test === true) return $retDB; |
|
| 136 | 136 | |
| 137 | - $this->trapDB=$retDB; |
|
| 138 | - return $this->trapDB; |
|
| 139 | - } |
|
| 137 | + $this->trapDB=$retDB; |
|
| 138 | + return $this->trapDB; |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - /** |
|
| 142 | - * Get IDO Database |
|
| 143 | - * @param boolean $test |
|
| 144 | - * @return Zend_Db_Adapter_Abstract|array]|NULL if test=false, returns DB connexion, else array(error_num,message) or null on error. |
|
| 145 | - */ |
|
| 146 | - public function getIdoDb($test=false) |
|
| 147 | - { |
|
| 148 | - if ($this->idoDB != null && $test = false) return $this->idoDB; |
|
| 149 | - // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
|
| 150 | - $dbresource=$this->Config()->get('config', 'IDOdatabase');; |
|
| 141 | + /** |
|
| 142 | + * Get IDO Database |
|
| 143 | + * @param boolean $test |
|
| 144 | + * @return Zend_Db_Adapter_Abstract|array]|NULL if test=false, returns DB connexion, else array(error_num,message) or null on error. |
|
| 145 | + */ |
|
| 146 | + public function getIdoDb($test=false) |
|
| 147 | + { |
|
| 148 | + if ($this->idoDB != null && $test = false) return $this->idoDB; |
|
| 149 | + // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
|
| 150 | + $dbresource=$this->Config()->get('config', 'IDOdatabase');; |
|
| 151 | 151 | |
| 152 | - if ( ! $dbresource ) |
|
| 153 | - { |
|
| 154 | - if ($test) return array(1,'No database in config.ini'); |
|
| 155 | - $this->redirectNow('trapdirector/settings?idodberror=1'); |
|
| 156 | - return null; |
|
| 157 | - } |
|
| 152 | + if ( ! $dbresource ) |
|
| 153 | + { |
|
| 154 | + if ($test) return array(1,'No database in config.ini'); |
|
| 155 | + $this->redirectNow('trapdirector/settings?idodberror=1'); |
|
| 156 | + return null; |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - try |
|
| 160 | - { |
|
| 161 | - $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
| 162 | - } |
|
| 163 | - catch (Exception $e) |
|
| 164 | - { |
|
| 165 | - if ($test) return array(2,"Database $dbresource does not exists in IcingaWeb2"); |
|
| 166 | - $this->redirectNow('trapdirector/settings?idodberror=2'); |
|
| 167 | - return null; |
|
| 168 | - } |
|
| 159 | + try |
|
| 160 | + { |
|
| 161 | + $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
| 162 | + } |
|
| 163 | + catch (Exception $e) |
|
| 164 | + { |
|
| 165 | + if ($test) return array(2,"Database $dbresource does not exists in IcingaWeb2"); |
|
| 166 | + $this->redirectNow('trapdirector/settings?idodberror=2'); |
|
| 167 | + return null; |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - if ($test == false) |
|
| 171 | - { |
|
| 172 | - $this->idoDB = $dbconn->getDbAdapter(); |
|
| 173 | - return $this->idoDB; |
|
| 174 | - } |
|
| 170 | + if ($test == false) |
|
| 171 | + { |
|
| 172 | + $this->idoDB = $dbconn->getDbAdapter(); |
|
| 173 | + return $this->idoDB; |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | - try |
|
| 177 | - { |
|
| 178 | - $query = $dbconn->select() |
|
| 179 | - ->from('icinga_dbversion',array('version')); |
|
| 180 | - $version=$dbconn->fetchRow($query); |
|
| 181 | - if ( ($version == null) || ! property_exists($version,'version') ) |
|
| 182 | - { |
|
| 183 | - return array(4,"$dbresource does not look like an IDO database"); |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - catch (Exception $e) |
|
| 187 | - { |
|
| 188 | - return array(3,"Error connecting to $dbresource : " . $e->getMessage()); |
|
| 189 | - } |
|
| 176 | + try |
|
| 177 | + { |
|
| 178 | + $query = $dbconn->select() |
|
| 179 | + ->from('icinga_dbversion',array('version')); |
|
| 180 | + $version=$dbconn->fetchRow($query); |
|
| 181 | + if ( ($version == null) || ! property_exists($version,'version') ) |
|
| 182 | + { |
|
| 183 | + return array(4,"$dbresource does not look like an IDO database"); |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + catch (Exception $e) |
|
| 187 | + { |
|
| 188 | + return array(3,"Error connecting to $dbresource : " . $e->getMessage()); |
|
| 189 | + } |
|
| 190 | 190 | |
| 191 | - return array(0,''); |
|
| 192 | - } |
|
| 191 | + return array(0,''); |
|
| 192 | + } |
|
| 193 | 193 | |
| 194 | 194 | } |
| 195 | 195 | \ No newline at end of file |
@@ -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 |
@@ -52,20 +52,25 @@ discard block |
||
| 52 | 52 | $version=$dbAdapter->fetchRow($query); |
| 53 | 53 | if ( ($version == null) || ! property_exists($version,'value') ) |
| 54 | 54 | { |
| 55 | - if ($test) return array(4,$DBname); |
|
| 55 | + if ($test) { |
|
| 56 | + return array(4,$DBname); |
|
| 57 | + } |
|
| 56 | 58 | $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
| 57 | 59 | return null; |
| 58 | 60 | } |
| 59 | 61 | if ($version->value < $min) |
| 60 | 62 | { |
| 61 | - if ($test) return array(5,$version->value,$min); |
|
| 63 | + if ($test) { |
|
| 64 | + return array(5,$version->value,$min); |
|
| 65 | + } |
|
| 62 | 66 | $this->trapController->redirectNow('trapdirector/settings?dberror=5'); |
| 63 | 67 | return null; |
| 64 | 68 | } |
| 65 | - } |
|
| 66 | - catch (Exception $e) |
|
| 69 | + } catch (Exception $e) |
|
| 67 | 70 | { |
| 68 | - if ($test) return array(3,$DBname,$e->getMessage()); |
|
| 71 | + if ($test) { |
|
| 72 | + return array(3,$DBname,$e->getMessage()); |
|
| 73 | + } |
|
| 69 | 74 | $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
| 70 | 75 | } |
| 71 | 76 | return null; |
@@ -82,10 +87,11 @@ discard block |
||
| 82 | 87 | try |
| 83 | 88 | { |
| 84 | 89 | $dbconn = IcingaDbConnection::fromResourceName($DBname); |
| 85 | - } |
|
| 86 | - catch (Exception $e) |
|
| 90 | + } catch (Exception $e) |
|
| 87 | 91 | { |
| 88 | - if ($test) return array(2,$DBname); |
|
| 92 | + if ($test) { |
|
| 93 | + return array(2,$DBname); |
|
| 94 | + } |
|
| 89 | 95 | $this->trapController->redirectNow('trapdirector/settings?dberror=2'); |
| 90 | 96 | return null; |
| 91 | 97 | } |
@@ -94,10 +100,11 @@ discard block |
||
| 94 | 100 | { |
| 95 | 101 | $dbAdapter=$dbconn->getDbAdapter(); |
| 96 | 102 | |
| 97 | - } |
|
| 98 | - catch (Exception $e) |
|
| 103 | + } catch (Exception $e) |
|
| 99 | 104 | { |
| 100 | - if ($test) return array(3,$DBname,$e->getMessage()); |
|
| 105 | + if ($test) { |
|
| 106 | + return array(3,$DBname,$e->getMessage()); |
|
| 107 | + } |
|
| 101 | 108 | $this->trapController->redirectNow('trapdirector/settings?dberror=3'); |
| 102 | 109 | return null; |
| 103 | 110 | } |
@@ -109,7 +116,9 @@ discard block |
||
| 109 | 116 | return $testRet; |
| 110 | 117 | } |
| 111 | 118 | } |
| 112 | - if ($test) return array(0,''); |
|
| 119 | + if ($test) { |
|
| 120 | + return array(0,''); |
|
| 121 | + } |
|
| 113 | 122 | return $dbAdapter; |
| 114 | 123 | } |
| 115 | 124 | |
@@ -120,19 +129,25 @@ discard block |
||
| 120 | 129 | */ |
| 121 | 130 | public function getDb($test=false) |
| 122 | 131 | { |
| 123 | - if ($this->trapDB != null && $test = false) return $this->trapDB; |
|
| 132 | + if ($this->trapDB != null && $test = false) { |
|
| 133 | + return $this->trapDB; |
|
| 134 | + } |
|
| 124 | 135 | |
| 125 | 136 | $dbresource=$this->trapController->Config()->get('config', 'database'); |
| 126 | 137 | |
| 127 | 138 | if ( ! $dbresource ) |
| 128 | 139 | { |
| 129 | - if ($test) return array(1,''); |
|
| 140 | + if ($test) { |
|
| 141 | + return array(1,''); |
|
| 142 | + } |
|
| 130 | 143 | $this->redirectNow('trapdirector/settings?dberror=1'); |
| 131 | 144 | return null; |
| 132 | 145 | } |
| 133 | 146 | $retDB=$this->getDbByName($dbresource,$test,true); |
| 134 | 147 | |
| 135 | - if ($test === true) return $retDB; |
|
| 148 | + if ($test === true) { |
|
| 149 | + return $retDB; |
|
| 150 | + } |
|
| 136 | 151 | |
| 137 | 152 | $this->trapDB=$retDB; |
| 138 | 153 | return $this->trapDB; |
@@ -145,13 +160,17 @@ discard block |
||
| 145 | 160 | */ |
| 146 | 161 | public function getIdoDb($test=false) |
| 147 | 162 | { |
| 148 | - if ($this->idoDB != null && $test = false) return $this->idoDB; |
|
| 163 | + if ($this->idoDB != null && $test = false) { |
|
| 164 | + return $this->idoDB; |
|
| 165 | + } |
|
| 149 | 166 | // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
| 150 | 167 | $dbresource=$this->Config()->get('config', 'IDOdatabase');; |
| 151 | 168 | |
| 152 | 169 | if ( ! $dbresource ) |
| 153 | 170 | { |
| 154 | - if ($test) return array(1,'No database in config.ini'); |
|
| 171 | + if ($test) { |
|
| 172 | + return array(1,'No database in config.ini'); |
|
| 173 | + } |
|
| 155 | 174 | $this->redirectNow('trapdirector/settings?idodberror=1'); |
| 156 | 175 | return null; |
| 157 | 176 | } |
@@ -159,10 +178,11 @@ discard block |
||
| 159 | 178 | try |
| 160 | 179 | { |
| 161 | 180 | $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
| 162 | - } |
|
| 163 | - catch (Exception $e) |
|
| 181 | + } catch (Exception $e) |
|
| 164 | 182 | { |
| 165 | - if ($test) return array(2,"Database $dbresource does not exists in IcingaWeb2"); |
|
| 183 | + if ($test) { |
|
| 184 | + return array(2,"Database $dbresource does not exists in IcingaWeb2"); |
|
| 185 | + } |
|
| 166 | 186 | $this->redirectNow('trapdirector/settings?idodberror=2'); |
| 167 | 187 | return null; |
| 168 | 188 | } |
@@ -182,8 +202,7 @@ discard block |
||
| 182 | 202 | { |
| 183 | 203 | return array(4,"$dbresource does not look like an IDO database"); |
| 184 | 204 | } |
| 185 | - } |
|
| 186 | - catch (Exception $e) |
|
| 205 | + } catch (Exception $e) |
|
| 187 | 206 | { |
| 188 | 207 | return array(3,"Error connecting to $dbresource : " . $e->getMessage()); |
| 189 | 208 | } |