@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | * @param \Zend_Db_Adapter_Abstract $db current database |
| 22 | 22 | * @param TrapModuleConfig $config TrapModuleConfig class instance |
| 23 | 23 | */ |
| 24 | - public function __construct($snmptranslate,$snmptranslate_dirs,$db,$config) |
|
| 24 | + public function __construct($snmptranslate, $snmptranslate_dirs, $db, $config) |
|
| 25 | 25 | { |
| 26 | 26 | $this->snmptranslate=$snmptranslate; |
| 27 | 27 | $this->snmptranslate_dirs=$snmptranslate_dirs; |
@@ -38,19 +38,19 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | public function getMIBList() |
| 40 | 40 | { |
| 41 | - $dbconn = $this->db; |
|
| 41 | + $dbconn=$this->db; |
|
| 42 | 42 | $query=$dbconn->select() |
| 43 | 43 | ->distinct() |
| 44 | 44 | ->from( |
| 45 | 45 | $this->config->getMIBCacheTableName(), |
| 46 | 46 | array('mib' => 'mib')) |
| 47 | 47 | ->where("type = '21'") |
| 48 | - ->order('mib ASC'); ; |
|
| 48 | + ->order('mib ASC'); ; |
|
| 49 | 49 | $names=$dbconn->fetchAll($query); |
| 50 | 50 | $mib=array(); |
| 51 | - foreach($names as $val) |
|
| 51 | + foreach ($names as $val) |
|
| 52 | 52 | { |
| 53 | - array_push($mib,$val->mib); |
|
| 53 | + array_push($mib, $val->mib); |
|
| 54 | 54 | } |
| 55 | 55 | return $mib; |
| 56 | 56 | |
@@ -64,12 +64,12 @@ discard block |
||
| 64 | 64 | public function getTrapList($mib) |
| 65 | 65 | { |
| 66 | 66 | $traps=array(); |
| 67 | - $dbconn = $this->db; |
|
| 67 | + $dbconn=$this->db; |
|
| 68 | 68 | $query=$dbconn->select() |
| 69 | 69 | ->from( |
| 70 | 70 | $this->config->getMIBCacheTableName(), |
| 71 | 71 | array('name' => 'name', 'oid' => 'oid', 'description' => 'description')) |
| 72 | - ->where("mib = '".$mib."' AND type='21'") ; |
|
| 72 | + ->where("mib = '".$mib."' AND type='21'"); |
|
| 73 | 73 | $names=$dbconn->fetchAll($query); |
| 74 | 74 | foreach ($names as $val) |
| 75 | 75 | { |
@@ -87,19 +87,19 @@ discard block |
||
| 87 | 87 | $objects=array(); |
| 88 | 88 | |
| 89 | 89 | // Get trap id in DB |
| 90 | - $dbconn = $this->db; |
|
| 90 | + $dbconn=$this->db; |
|
| 91 | 91 | $query=$dbconn->select() |
| 92 | 92 | ->from( |
| 93 | 93 | $this->config->getMIBCacheTableName(), |
| 94 | 94 | array('id' => 'id')) |
| 95 | - ->where("oid = '".$trap."'") ; |
|
| 95 | + ->where("oid = '".$trap."'"); |
|
| 96 | 96 | $id=$dbconn->fetchRow($query); |
| 97 | - if ( ($id == null) || ! property_exists($id,'id') ) return null; |
|
| 97 | + if (($id == null) || !property_exists($id, 'id')) return null; |
|
| 98 | 98 | |
| 99 | 99 | $query=$dbconn->select() |
| 100 | 100 | ->from( |
| 101 | 101 | array('c' => $this->config->getMIBCacheTableName()), |
| 102 | - array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum', |
|
| 102 | + array('name' => 'c.name', 'mib' => 'c.mib', 'oid' => 'c.oid', 'type_enum'=>'c.type_enum', |
|
| 103 | 103 | 'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint', |
| 104 | 104 | 'description' => 'c.description')) |
| 105 | 105 | ->join( |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | 'o.trap_id='.$id->id ) |
| 108 | 108 | ->where("o.object_id = c.id"); |
| 109 | 109 | $listObjects=$dbconn->fetchAll($query); |
| 110 | - if ( count($listObjects)==0 ) return null; |
|
| 110 | + if (count($listObjects) == 0) return null; |
|
| 111 | 111 | |
| 112 | 112 | foreach ($listObjects as $val) |
| 113 | 113 | { |
@@ -128,14 +128,14 @@ discard block |
||
| 128 | 128 | */ |
| 129 | 129 | public function translateOID($oid) |
| 130 | 130 | { |
| 131 | - if (!preg_match('/^\./',$oid)) $oid = '.' . $oid; // Add a leading '.' |
|
| 132 | - $retArray=array('oid' => $oid, 'mib' => null, 'name'=>null,'type'=>null); |
|
| 133 | - $dbconn = $this->db; |
|
| 131 | + if (!preg_match('/^\./', $oid)) $oid='.'.$oid; // Add a leading '.' |
|
| 132 | + $retArray=array('oid' => $oid, 'mib' => null, 'name'=>null, 'type'=>null); |
|
| 133 | + $dbconn=$this->db; |
|
| 134 | 134 | |
| 135 | 135 | $query=$dbconn->select() |
| 136 | 136 | ->from( |
| 137 | 137 | array('o' => $this->config->getMIBCacheTableName()), |
| 138 | - array('mib'=>'o.mib','name' => 'o.name','type'=>'o.syntax', |
|
| 138 | + array('mib'=>'o.mib', 'name' => 'o.name', 'type'=>'o.syntax', |
|
| 139 | 139 | 'type_enum'=>'o.type_enum', 'description'=>'o.description')) |
| 140 | 140 | ->where('o.oid=\''.$oid.'\''); |
| 141 | 141 | $object=$dbconn->fetchRow($query); |
@@ -151,18 +151,18 @@ discard block |
||
| 151 | 151 | |
| 152 | 152 | // Try to get oid name from snmptranslate |
| 153 | 153 | $matches=array(); |
| 154 | - $translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs. |
|
| 154 | + $translate=exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs. |
|
| 155 | 155 | ' '.$oid); |
| 156 | - $ret_code=preg_match('/(.*)::(.*)/',$translate,$matches); |
|
| 157 | - if ($ret_code===0 || $ret_code===false) { |
|
| 156 | + $ret_code=preg_match('/(.*)::(.*)/', $translate, $matches); |
|
| 157 | + if ($ret_code === 0 || $ret_code === false) { |
|
| 158 | 158 | return null; |
| 159 | 159 | } |
| 160 | 160 | $retArray['mib']=$matches[1]; |
| 161 | 161 | $retArray['name']=$matches[2]; |
| 162 | 162 | |
| 163 | - $translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.' -Td -On ' . $matches[0] . |
|
| 163 | + $translate=exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.' -Td -On '.$matches[0]. |
|
| 164 | 164 | " | grep SYNTAX | sed 's/SYNTAX[[:blank:]]*//'"); |
| 165 | - if (preg_match('/(.*)\{(.*)\}/',$translate,$matches)) |
|
| 165 | + if (preg_match('/(.*)\{(.*)\}/', $translate, $matches)) |
|
| 166 | 166 | { |
| 167 | 167 | $retArray['type']=$matches[1]; |
| 168 | 168 | $retArray['type_enum']=$matches[2]; |
@@ -197,9 +197,9 @@ discard block |
||
| 197 | 197 | * @param string $type filter by type (21=trap) |
| 198 | 198 | * @return number number of entries in db. |
| 199 | 199 | */ |
| 200 | - public function countObjects($mib=null,$type=null) |
|
| 200 | + public function countObjects($mib=null, $type=null) |
|
| 201 | 201 | { |
| 202 | - $dbconn = $this->db; |
|
| 202 | + $dbconn=$this->db; |
|
| 203 | 203 | $query=$dbconn->select() |
| 204 | 204 | ->from( |
| 205 | 205 | $this->config->getMIBCacheTableName(), |
@@ -207,11 +207,11 @@ discard block |
||
| 207 | 207 | $where=null; |
| 208 | 208 | if ($mib !== null) |
| 209 | 209 | { |
| 210 | - $where ="mib = '$mib' "; |
|
| 210 | + $where="mib = '$mib' "; |
|
| 211 | 211 | } |
| 212 | 212 | if ($type !== null) |
| 213 | 213 | { |
| 214 | - $where=($where !== null)?' AND ':''; |
|
| 214 | + $where=($where !== null) ? ' AND ' : ''; |
|
| 215 | 215 | $where.="type='$type'"; |
| 216 | 216 | } |
| 217 | 217 | if ($where !== null) |
@@ -227,10 +227,10 @@ discard block |
||
| 227 | 227 | * @param integer $id |
| 228 | 228 | * @return array trap details |
| 229 | 229 | */ |
| 230 | - public function getTrapDetails($oid=null,$id=null) |
|
| 230 | + public function getTrapDetails($oid=null, $id=null) |
|
| 231 | 231 | { |
| 232 | 232 | // Get trap id in DB |
| 233 | - if ($oid===null) |
|
| 233 | + if ($oid === null) |
|
| 234 | 234 | { |
| 235 | 235 | $where="c.id = '$id'"; |
| 236 | 236 | } |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | $query=$this->db->select() |
| 242 | 242 | ->from( |
| 243 | 243 | array('c' => $this->config->getMIBCacheTableName()), |
| 244 | - array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum', |
|
| 244 | + array('name' => 'c.name', 'mib' => 'c.mib', 'oid' => 'c.oid', 'type_enum'=>'c.type_enum', |
|
| 245 | 245 | 'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint', |
| 246 | 246 | 'description' => 'c.description')) |
| 247 | 247 | ->where($where); |
@@ -94,7 +94,9 @@ discard block |
||
| 94 | 94 | array('id' => 'id')) |
| 95 | 95 | ->where("oid = '".$trap."'") ; |
| 96 | 96 | $id=$dbconn->fetchRow($query); |
| 97 | - if ( ($id == null) || ! property_exists($id,'id') ) return null; |
|
| 97 | + if ( ($id == null) || ! property_exists($id,'id') ) { |
|
| 98 | + return null; |
|
| 99 | + } |
|
| 98 | 100 | |
| 99 | 101 | $query=$dbconn->select() |
| 100 | 102 | ->from( |
@@ -107,7 +109,9 @@ discard block |
||
| 107 | 109 | 'o.trap_id='.$id->id ) |
| 108 | 110 | ->where("o.object_id = c.id"); |
| 109 | 111 | $listObjects=$dbconn->fetchAll($query); |
| 110 | - if ( count($listObjects)==0 ) return null; |
|
| 112 | + if ( count($listObjects)==0 ) { |
|
| 113 | + return null; |
|
| 114 | + } |
|
| 111 | 115 | |
| 112 | 116 | foreach ($listObjects as $val) |
| 113 | 117 | { |
@@ -128,7 +132,10 @@ discard block |
||
| 128 | 132 | */ |
| 129 | 133 | public function translateOID($oid) |
| 130 | 134 | { |
| 131 | - if (!preg_match('/^\./',$oid)) $oid = '.' . $oid; // Add a leading '.' |
|
| 135 | + if (!preg_match('/^\./',$oid)) { |
|
| 136 | + $oid = '.' . $oid; |
|
| 137 | + } |
|
| 138 | + // Add a leading '.' |
|
| 132 | 139 | $retArray=array('oid' => $oid, 'mib' => null, 'name'=>null,'type'=>null); |
| 133 | 140 | $dbconn = $this->db; |
| 134 | 141 | |
@@ -166,8 +173,7 @@ discard block |
||
| 166 | 173 | { |
| 167 | 174 | $retArray['type']=$matches[1]; |
| 168 | 175 | $retArray['type_enum']=$matches[2]; |
| 169 | - } |
|
| 170 | - else |
|
| 176 | + } else |
|
| 171 | 177 | { |
| 172 | 178 | $retArray['type']=$translate; |
| 173 | 179 | $retArray['type_enum']=''; |
@@ -233,8 +239,7 @@ discard block |
||
| 233 | 239 | if ($oid===null) |
| 234 | 240 | { |
| 235 | 241 | $where="c.id = '$id'"; |
| 236 | - } |
|
| 237 | - else |
|
| 242 | + } else |
|
| 238 | 243 | { |
| 239 | 244 | $where="c.oid = '$oid'"; |
| 240 | 245 | } |
@@ -31,10 +31,10 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Get all mibs in db which have at least one trap |
|
| 36 | - * @return array |
|
| 37 | - */ |
|
| 34 | + /** |
|
| 35 | + * Get all mibs in db which have at least one trap |
|
| 36 | + * @return array |
|
| 37 | + */ |
|
| 38 | 38 | |
| 39 | 39 | public function getMIBList() |
| 40 | 40 | { |
@@ -58,9 +58,9 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | |
| 60 | 60 | /** Get trap list from a mib |
| 61 | - * @param $mib string mib name |
|
| 62 | - * @return array : traps |
|
| 63 | - */ |
|
| 61 | + * @param $mib string mib name |
|
| 62 | + * @return array : traps |
|
| 63 | + */ |
|
| 64 | 64 | public function getTrapList($mib) |
| 65 | 65 | { |
| 66 | 66 | $traps=array(); |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | $query=$dbconn->select() |
| 69 | 69 | ->from( |
| 70 | 70 | $this->config->getMIBCacheTableName(), |
| 71 | - array('name' => 'name', 'oid' => 'oid', 'description' => 'description')) |
|
| 71 | + array('name' => 'name', 'oid' => 'oid', 'description' => 'description')) |
|
| 72 | 72 | ->where("mib = '".$mib."' AND type='21'") ; |
| 73 | 73 | $names=$dbconn->fetchAll($query); |
| 74 | 74 | foreach ($names as $val) |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** Get objects a trap can have |
| 82 | - * @param string $trap oid of trap |
|
| 83 | - * @return array|null : null if trap not found, or array ( <oid> => name/mib/type ) |
|
| 84 | - */ |
|
| 82 | + * @param string $trap oid of trap |
|
| 83 | + * @return array|null : null if trap not found, or array ( <oid> => name/mib/type ) |
|
| 84 | + */ |
|
| 85 | 85 | public function getObjectList($trap) |
| 86 | 86 | { |
| 87 | 87 | $objects=array(); |
@@ -97,15 +97,15 @@ discard block |
||
| 97 | 97 | if ( ($id == null) || ! property_exists($id,'id') ) return null; |
| 98 | 98 | |
| 99 | 99 | $query=$dbconn->select() |
| 100 | - ->from( |
|
| 101 | - array('c' => $this->config->getMIBCacheTableName()), |
|
| 102 | - array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum', |
|
| 103 | - 'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint', |
|
| 104 | - 'description' => 'c.description')) |
|
| 105 | - ->join( |
|
| 106 | - array('o' => $this->config->getMIBCacheTableTrapObjName()), |
|
| 107 | - 'o.trap_id='.$id->id ) |
|
| 108 | - ->where("o.object_id = c.id"); |
|
| 100 | + ->from( |
|
| 101 | + array('c' => $this->config->getMIBCacheTableName()), |
|
| 102 | + array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum', |
|
| 103 | + 'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint', |
|
| 104 | + 'description' => 'c.description')) |
|
| 105 | + ->join( |
|
| 106 | + array('o' => $this->config->getMIBCacheTableTrapObjName()), |
|
| 107 | + 'o.trap_id='.$id->id ) |
|
| 108 | + ->where("o.object_id = c.id"); |
|
| 109 | 109 | $listObjects=$dbconn->fetchAll($query); |
| 110 | 110 | if ( count($listObjects)==0 ) return null; |
| 111 | 111 | |
@@ -123,12 +123,12 @@ discard block |
||
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** translate oid in MIB::Name |
| 126 | - * @param string $oid |
|
| 127 | - * @return array|null : return array with index (oid -> oid, mib -> mib name, name -> oid name, type -> oid type) |
|
| 128 | - */ |
|
| 126 | + * @param string $oid |
|
| 127 | + * @return array|null : return array with index (oid -> oid, mib -> mib name, name -> oid name, type -> oid type) |
|
| 128 | + */ |
|
| 129 | 129 | public function translateOID($oid) |
| 130 | 130 | { |
| 131 | - if (!preg_match('/^\./',$oid)) $oid = '.' . $oid; // Add a leading '.' |
|
| 131 | + if (!preg_match('/^\./',$oid)) $oid = '.' . $oid; // Add a leading '.' |
|
| 132 | 132 | $retArray=array('oid' => $oid, 'mib' => null, 'name'=>null,'type'=>null); |
| 133 | 133 | $dbconn = $this->db; |
| 134 | 134 | |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | ->from( |
| 137 | 137 | array('o' => $this->config->getMIBCacheTableName()), |
| 138 | 138 | array('mib'=>'o.mib','name' => 'o.name','type'=>'o.syntax', |
| 139 | - 'type_enum'=>'o.type_enum', 'description'=>'o.description')) |
|
| 139 | + 'type_enum'=>'o.type_enum', 'description'=>'o.description')) |
|
| 140 | 140 | ->where('o.oid=\''.$oid.'\''); |
| 141 | 141 | $object=$dbconn->fetchRow($query); |
| 142 | 142 | if ($object != null) |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | // Try to get oid name from snmptranslate |
| 153 | 153 | $matches=array(); |
| 154 | 154 | $translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs. |
| 155 | - ' '.$oid); |
|
| 155 | + ' '.$oid); |
|
| 156 | 156 | $ret_code=preg_match('/(.*)::(.*)/',$translate,$matches); |
| 157 | 157 | if ($ret_code===0 || $ret_code===false) { |
| 158 | 158 | return null; |
@@ -164,8 +164,8 @@ discard block |
||
| 164 | 164 | " | grep SYNTAX | sed 's/SYNTAX[[:blank:]]*//'"); |
| 165 | 165 | if (preg_match('/(.*)\{(.*)\}/',$translate,$matches)) |
| 166 | 166 | { |
| 167 | - $retArray['type']=$matches[1]; |
|
| 168 | - $retArray['type_enum']=$matches[2]; |
|
| 167 | + $retArray['type']=$matches[1]; |
|
| 168 | + $retArray['type_enum']=$matches[2]; |
|
| 169 | 169 | } |
| 170 | 170 | else |
| 171 | 171 | { |
@@ -229,25 +229,25 @@ discard block |
||
| 229 | 229 | */ |
| 230 | 230 | public function getTrapDetails($oid=null,$id=null) |
| 231 | 231 | { |
| 232 | - // Get trap id in DB |
|
| 233 | - if ($oid===null) |
|
| 234 | - { |
|
| 235 | - $where="c.id = '$id'"; |
|
| 236 | - } |
|
| 237 | - else |
|
| 238 | - { |
|
| 239 | - $where="c.oid = '$oid'"; |
|
| 240 | - } |
|
| 241 | - $query=$this->db->select() |
|
| 242 | - ->from( |
|
| 243 | - array('c' => $this->config->getMIBCacheTableName()), |
|
| 244 | - array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum', |
|
| 245 | - 'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint', |
|
| 246 | - 'description' => 'c.description')) |
|
| 247 | - ->where($where); |
|
| 248 | - $trap=$this->db->fetchRow($query); |
|
| 232 | + // Get trap id in DB |
|
| 233 | + if ($oid===null) |
|
| 234 | + { |
|
| 235 | + $where="c.id = '$id'"; |
|
| 236 | + } |
|
| 237 | + else |
|
| 238 | + { |
|
| 239 | + $where="c.oid = '$oid'"; |
|
| 240 | + } |
|
| 241 | + $query=$this->db->select() |
|
| 242 | + ->from( |
|
| 243 | + array('c' => $this->config->getMIBCacheTableName()), |
|
| 244 | + array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum', |
|
| 245 | + 'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint', |
|
| 246 | + 'description' => 'c.description')) |
|
| 247 | + ->where($where); |
|
| 248 | + $trap=$this->db->fetchRow($query); |
|
| 249 | 249 | |
| 250 | - return $trap; |
|
| 250 | + return $trap; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | } |
@@ -21,7 +21,9 @@ discard block |
||
| 21 | 21 | $this->prepareTabs()->activate('traps'); |
| 22 | 22 | |
| 23 | 23 | $dbConn = $this->getUIDatabase()->getDb(); |
| 24 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 24 | + if ($dbConn === null) { |
|
| 25 | + throw new \ErrorException('uncatched db error'); |
|
| 26 | + } |
|
| 25 | 27 | $this->getTrapListTable()->setConnection($dbConn); |
| 26 | 28 | |
| 27 | 29 | // Apply pagination limits |
@@ -58,7 +60,9 @@ discard block |
||
| 58 | 60 | $queryArray=$this->getModuleConfig()->trapDetailQuery(); |
| 59 | 61 | |
| 60 | 62 | $dbConn = $this->getUIDatabase()->getDbConn(); |
| 61 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 63 | + if ($dbConn === null) { |
|
| 64 | + throw new \ErrorException('uncatched db error'); |
|
| 65 | + } |
|
| 62 | 66 | |
| 63 | 67 | // URL to add a handler |
| 64 | 68 | $this->view->addHandlerUrl=Url::fromPath( |
@@ -78,9 +82,10 @@ discard block |
||
| 78 | 82 | ->from($this->moduleConfig->getTrapTableName(),$elmts) |
| 79 | 83 | ->where('id=?',$trapid); |
| 80 | 84 | $trapDetail=$dbConn->fetchRow($query); |
| 81 | - if ( $trapDetail == null) throw new Exception('No traps was found with id = '.$trapid); |
|
| 82 | - } |
|
| 83 | - catch (Exception $e) |
|
| 85 | + if ( $trapDetail == null) { |
|
| 86 | + throw new Exception('No traps was found with id = '.$trapid); |
|
| 87 | + } |
|
| 88 | + } catch (Exception $e) |
|
| 84 | 89 | { |
| 85 | 90 | $this->displayExitError('Trap detail',$e->getMessage()); |
| 86 | 91 | return; |
@@ -111,8 +116,7 @@ discard block |
||
| 111 | 116 | ->from($this->moduleConfig->getTrapDataTableName(),$data_elmts) |
| 112 | 117 | ->where('trap_id=?',$trapid); |
| 113 | 118 | $trapDetail=$dbConn->fetchAll($query); |
| 114 | - } |
|
| 115 | - catch (Exception $e) |
|
| 119 | + } catch (Exception $e) |
|
| 116 | 120 | { |
| 117 | 121 | $this->displayExitError('Trap detail',$e->getMessage()); |
| 118 | 122 | } |
@@ -120,8 +124,7 @@ discard block |
||
| 120 | 124 | if ($trapDetail == null ) |
| 121 | 125 | { |
| 122 | 126 | $this->view->data=false; |
| 123 | - } |
|
| 124 | - else |
|
| 127 | + } else |
|
| 125 | 128 | { |
| 126 | 129 | $this->view->data=true; |
| 127 | 130 | // Store result in array. |
@@ -148,7 +151,9 @@ discard block |
||
| 148 | 151 | $this->prepareTabs()->activate('hosts'); |
| 149 | 152 | |
| 150 | 153 | $dbConn = $this->getUIDatabase()->getDb(); |
| 151 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 154 | + if ($dbConn === null) { |
|
| 155 | + throw new \ErrorException('uncatched db error'); |
|
| 156 | + } |
|
| 152 | 157 | |
| 153 | 158 | $this->getTrapHostListTable()->setConnection($dbConn); |
| 154 | 159 | |
@@ -209,8 +214,7 @@ discard block |
||
| 209 | 214 | $ip=$postData['IP']; |
| 210 | 215 | $oid=$postData['OID']; |
| 211 | 216 | $action=$postData['action']; |
| 212 | - } |
|
| 213 | - else |
|
| 217 | + } else |
|
| 214 | 218 | { |
| 215 | 219 | $this->_helper->json(array('status'=>'Missing variables')); |
| 216 | 220 | return; |
@@ -40,8 +40,8 @@ discard block |
||
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | - * Trap detail page |
|
| 44 | - */ |
|
| 43 | + * Trap detail page |
|
| 44 | + */ |
|
| 45 | 45 | public function trapdetailAction() |
| 46 | 46 | { |
| 47 | 47 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | // Do DB query for trap. |
| 75 | 75 | try |
| 76 | 76 | { |
| 77 | - $query = $dbConn->select() |
|
| 77 | + $query = $dbConn->select() |
|
| 78 | 78 | ->from($this->moduleConfig->getTrapTableName(),$elmts) |
| 79 | 79 | ->where('id=?',$trapid); |
| 80 | 80 | $trapDetail=$dbConn->fetchRow($query); |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | } |
| 108 | 108 | try |
| 109 | 109 | { |
| 110 | - $query = $dbConn->select() |
|
| 110 | + $query = $dbConn->select() |
|
| 111 | 111 | ->from($this->moduleConfig->getTrapDataTableName(),$data_elmts) |
| 112 | 112 | ->where('trap_id=?',$trapid); |
| 113 | 113 | $trapDetail=$dbConn->fetchAll($query); |
@@ -144,24 +144,24 @@ discard block |
||
| 144 | 144 | */ |
| 145 | 145 | public function hostsAction() |
| 146 | 146 | { |
| 147 | - $this->checkReadPermission(); |
|
| 148 | - $this->prepareTabs()->activate('hosts'); |
|
| 147 | + $this->checkReadPermission(); |
|
| 148 | + $this->prepareTabs()->activate('hosts'); |
|
| 149 | 149 | |
| 150 | - $dbConn = $this->getUIDatabase()->getDb(); |
|
| 151 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 150 | + $dbConn = $this->getUIDatabase()->getDb(); |
|
| 151 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 152 | 152 | |
| 153 | - $this->getTrapHostListTable()->setConnection($dbConn); |
|
| 153 | + $this->getTrapHostListTable()->setConnection($dbConn); |
|
| 154 | 154 | |
| 155 | - // Apply pagination limits |
|
| 156 | - $this->view->table=$this->applyPaginationLimits($this->getTrapHostListTable(),$this->getModuleConfig()->itemListDisplay()); |
|
| 155 | + // Apply pagination limits |
|
| 156 | + $this->view->table=$this->applyPaginationLimits($this->getTrapHostListTable(),$this->getModuleConfig()->itemListDisplay()); |
|
| 157 | 157 | |
| 158 | - // Set Filter |
|
| 159 | - //$postData=$this->getRequest()->getPost(); |
|
| 160 | - $filter=array(); |
|
| 161 | - $filter['q']=$this->params->get('q');//(isset($postData['q']))?$postData['q']:''; |
|
| 162 | - $filter['done']=$this->params->get('done'); |
|
| 163 | - $this->view->filter=$filter; |
|
| 164 | - $this->view->table->updateFilter(Url::fromRequest(),$filter); |
|
| 158 | + // Set Filter |
|
| 159 | + //$postData=$this->getRequest()->getPost(); |
|
| 160 | + $filter=array(); |
|
| 161 | + $filter['q']=$this->params->get('q');//(isset($postData['q']))?$postData['q']:''; |
|
| 162 | + $filter['done']=$this->params->get('done'); |
|
| 163 | + $this->view->filter=$filter; |
|
| 164 | + $this->view->table->updateFilter(Url::fromRequest(),$filter); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | public function deleteAction() |
@@ -181,12 +181,12 @@ discard block |
||
| 181 | 181 | return $this->getTabs()->add('traps', array( |
| 182 | 182 | 'label' => $this->translate('Traps'), |
| 183 | 183 | 'url' => $this->getModuleConfig()->urlPath() . '/received') |
| 184 | - ) |
|
| 185 | - ->add('hosts', array( |
|
| 186 | - 'label' => $this->translate('Hosts'), |
|
| 187 | - 'url' => $this->getModuleConfig()->urlPath() . '/received/hosts') |
|
| 188 | - ) |
|
| 189 | - ->add('delete', array( |
|
| 184 | + ) |
|
| 185 | + ->add('hosts', array( |
|
| 186 | + 'label' => $this->translate('Hosts'), |
|
| 187 | + 'url' => $this->getModuleConfig()->urlPath() . '/received/hosts') |
|
| 188 | + ) |
|
| 189 | + ->add('delete', array( |
|
| 190 | 190 | 'label' => $this->translate('Delete'), |
| 191 | 191 | 'url' => $this->getModuleConfig()->urlPath() . '/received/delete') |
| 192 | 192 | ); |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | } |
| 223 | 223 | if ($action =="delete") |
| 224 | 224 | { |
| 225 | - $this->_helper->json(array('status'=>'OK','count'=>$this->getUIDatabase()->deleteTrap($ip,$oid))); |
|
| 225 | + $this->_helper->json(array('status'=>'OK','count'=>$this->getUIDatabase()->deleteTrap($ip,$oid))); |
|
| 226 | 226 | return; |
| 227 | 227 | } |
| 228 | 228 | $this->_helper->json(array('status'=>'unknown action')); |
@@ -20,20 +20,20 @@ discard block |
||
| 20 | 20 | $this->checkReadPermission(); |
| 21 | 21 | $this->prepareTabs()->activate('traps'); |
| 22 | 22 | |
| 23 | - $dbConn = $this->getUIDatabase()->getDb(); |
|
| 23 | + $dbConn=$this->getUIDatabase()->getDb(); |
|
| 24 | 24 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 25 | 25 | $this->getTrapListTable()->setConnection($dbConn); |
| 26 | 26 | |
| 27 | 27 | // Apply pagination limits |
| 28 | - $this->view->table=$this->applyPaginationLimits($this->getTrapListTable(),$this->getModuleConfig()->itemListDisplay()); |
|
| 28 | + $this->view->table=$this->applyPaginationLimits($this->getTrapListTable(), $this->getModuleConfig()->itemListDisplay()); |
|
| 29 | 29 | |
| 30 | 30 | // Set Filter |
| 31 | 31 | //$postData=$this->getRequest()->getPost(); |
| 32 | 32 | $filter=array(); |
| 33 | - $filter['q']=$this->params->get('q');//(isset($postData['q']))?$postData['q']:''; |
|
| 33 | + $filter['q']=$this->params->get('q'); //(isset($postData['q']))?$postData['q']:''; |
|
| 34 | 34 | $filter['done']=$this->params->get('done'); |
| 35 | 35 | $this->view->filter=$filter; |
| 36 | - $this->view->table->updateFilter(Url::fromRequest(),$filter); |
|
| 36 | + $this->view->table->updateFilter(Url::fromRequest(), $filter); |
|
| 37 | 37 | |
| 38 | 38 | //$this->view->filterEditor = $this->getTrapListTable()->getFilterEditor($this->getRequest()); |
| 39 | 39 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | $this->checkReadPermission(); |
| 49 | 49 | // set up tab |
| 50 | - $this->getTabs()->add('get',array( |
|
| 50 | + $this->getTabs()->add('get', array( |
|
| 51 | 51 | 'active' => true, |
| 52 | 52 | 'label' => $this->translate('Detailed status'), |
| 53 | 53 | 'url' => Url::fromRequest() |
@@ -57,12 +57,12 @@ discard block |
||
| 57 | 57 | $this->view->trapid=$trapid; |
| 58 | 58 | $queryArray=$this->getModuleConfig()->trapDetailQuery(); |
| 59 | 59 | |
| 60 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
| 60 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
| 61 | 61 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 62 | 62 | |
| 63 | 63 | // URL to add a handler |
| 64 | 64 | $this->view->addHandlerUrl=Url::fromPath( |
| 65 | - $this->getModuleConfig()->urlPath() . '/handler/add', |
|
| 65 | + $this->getModuleConfig()->urlPath().'/handler/add', |
|
| 66 | 66 | array('fromid' => $trapid)); |
| 67 | 67 | // *************** Get main data |
| 68 | 68 | // extract columns and titles; |
@@ -74,28 +74,28 @@ discard block |
||
| 74 | 74 | // Do DB query for trap. |
| 75 | 75 | try |
| 76 | 76 | { |
| 77 | - $query = $dbConn->select() |
|
| 78 | - ->from($this->moduleConfig->getTrapTableName(),$elmts) |
|
| 79 | - ->where('id=?',$trapid); |
|
| 77 | + $query=$dbConn->select() |
|
| 78 | + ->from($this->moduleConfig->getTrapTableName(), $elmts) |
|
| 79 | + ->where('id=?', $trapid); |
|
| 80 | 80 | $trapDetail=$dbConn->fetchRow($query); |
| 81 | - if ( $trapDetail == null) throw new Exception('No traps was found with id = '.$trapid); |
|
| 81 | + if ($trapDetail == null) throw new Exception('No traps was found with id = '.$trapid); |
|
| 82 | 82 | } |
| 83 | 83 | catch (Exception $e) |
| 84 | 84 | { |
| 85 | - $this->displayExitError('Trap detail',$e->getMessage()); |
|
| 85 | + $this->displayExitError('Trap detail', $e->getMessage()); |
|
| 86 | 86 | return; |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | // Store result in array (with Titles). |
| 90 | 90 | foreach ($queryArray as $key => $val) { |
| 91 | 91 | if ($key == 'timestamp') { |
| 92 | - $cval=strftime('%c',$trapDetail->$key); |
|
| 92 | + $cval=strftime('%c', $trapDetail->$key); |
|
| 93 | 93 | } else { |
| 94 | 94 | $cval=$trapDetail->$key; |
| 95 | 95 | } |
| 96 | - array_push($queryArray[$key],$cval); |
|
| 96 | + array_push($queryArray[$key], $cval); |
|
| 97 | 97 | } |
| 98 | - $this->view->rowset = $queryArray; |
|
| 98 | + $this->view->rowset=$queryArray; |
|
| 99 | 99 | |
| 100 | 100 | // ************** Check for additionnal data |
| 101 | 101 | |
@@ -107,17 +107,17 @@ discard block |
||
| 107 | 107 | } |
| 108 | 108 | try |
| 109 | 109 | { |
| 110 | - $query = $dbConn->select() |
|
| 111 | - ->from($this->moduleConfig->getTrapDataTableName(),$data_elmts) |
|
| 112 | - ->where('trap_id=?',$trapid); |
|
| 110 | + $query=$dbConn->select() |
|
| 111 | + ->from($this->moduleConfig->getTrapDataTableName(), $data_elmts) |
|
| 112 | + ->where('trap_id=?', $trapid); |
|
| 113 | 113 | $trapDetail=$dbConn->fetchAll($query); |
| 114 | 114 | } |
| 115 | 115 | catch (Exception $e) |
| 116 | 116 | { |
| 117 | - $this->displayExitError('Trap detail',$e->getMessage()); |
|
| 117 | + $this->displayExitError('Trap detail', $e->getMessage()); |
|
| 118 | 118 | } |
| 119 | 119 | // TODO : code this in a better & simpler way |
| 120 | - if ($trapDetail == null ) |
|
| 120 | + if ($trapDetail == null) |
|
| 121 | 121 | { |
| 122 | 122 | $this->view->data=false; |
| 123 | 123 | } |
@@ -129,9 +129,9 @@ discard block |
||
| 129 | 129 | foreach ($trapDetail as $key => $val) |
| 130 | 130 | { |
| 131 | 131 | $trapval[$key]=array(); |
| 132 | - foreach (array_keys($queryArrayData) as $vkey ) |
|
| 132 | + foreach (array_keys($queryArrayData) as $vkey) |
|
| 133 | 133 | { |
| 134 | - array_push($trapval[$key],$val->$vkey); |
|
| 134 | + array_push($trapval[$key], $val->$vkey); |
|
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | 137 | $this->view->data_val=$trapval; |
@@ -147,21 +147,21 @@ discard block |
||
| 147 | 147 | $this->checkReadPermission(); |
| 148 | 148 | $this->prepareTabs()->activate('hosts'); |
| 149 | 149 | |
| 150 | - $dbConn = $this->getUIDatabase()->getDb(); |
|
| 150 | + $dbConn=$this->getUIDatabase()->getDb(); |
|
| 151 | 151 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 152 | 152 | |
| 153 | 153 | $this->getTrapHostListTable()->setConnection($dbConn); |
| 154 | 154 | |
| 155 | 155 | // Apply pagination limits |
| 156 | - $this->view->table=$this->applyPaginationLimits($this->getTrapHostListTable(),$this->getModuleConfig()->itemListDisplay()); |
|
| 156 | + $this->view->table=$this->applyPaginationLimits($this->getTrapHostListTable(), $this->getModuleConfig()->itemListDisplay()); |
|
| 157 | 157 | |
| 158 | 158 | // Set Filter |
| 159 | 159 | //$postData=$this->getRequest()->getPost(); |
| 160 | 160 | $filter=array(); |
| 161 | - $filter['q']=$this->params->get('q');//(isset($postData['q']))?$postData['q']:''; |
|
| 161 | + $filter['q']=$this->params->get('q'); //(isset($postData['q']))?$postData['q']:''; |
|
| 162 | 162 | $filter['done']=$this->params->get('done'); |
| 163 | 163 | $this->view->filter=$filter; |
| 164 | - $this->view->table->updateFilter(Url::fromRequest(),$filter); |
|
| 164 | + $this->view->table->updateFilter(Url::fromRequest(), $filter); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | public function deleteAction() |
@@ -180,15 +180,15 @@ discard block |
||
| 180 | 180 | { |
| 181 | 181 | return $this->getTabs()->add('traps', array( |
| 182 | 182 | 'label' => $this->translate('Traps'), |
| 183 | - 'url' => $this->getModuleConfig()->urlPath() . '/received') |
|
| 183 | + 'url' => $this->getModuleConfig()->urlPath().'/received') |
|
| 184 | 184 | ) |
| 185 | 185 | ->add('hosts', array( |
| 186 | 186 | 'label' => $this->translate('Hosts'), |
| 187 | - 'url' => $this->getModuleConfig()->urlPath() . '/received/hosts') |
|
| 187 | + 'url' => $this->getModuleConfig()->urlPath().'/received/hosts') |
|
| 188 | 188 | ) |
| 189 | 189 | ->add('delete', array( |
| 190 | 190 | 'label' => $this->translate('Delete'), |
| 191 | - 'url' => $this->getModuleConfig()->urlPath() . '/received/delete') |
|
| 191 | + 'url' => $this->getModuleConfig()->urlPath().'/received/delete') |
|
| 192 | 192 | ); |
| 193 | 193 | } |
| 194 | 194 | |
@@ -215,14 +215,14 @@ discard block |
||
| 215 | 215 | $this->_helper->json(array('status'=>'Missing variables')); |
| 216 | 216 | return; |
| 217 | 217 | } |
| 218 | - if ($action =="count") |
|
| 218 | + if ($action == "count") |
|
| 219 | 219 | { |
| 220 | - $this->_helper->json(array('status'=>'OK','count'=>$this->getUIDatabase()->countTrap($ip,$oid))); |
|
| 220 | + $this->_helper->json(array('status'=>'OK', 'count'=>$this->getUIDatabase()->countTrap($ip, $oid))); |
|
| 221 | 221 | return; |
| 222 | 222 | } |
| 223 | - if ($action =="delete") |
|
| 223 | + if ($action == "delete") |
|
| 224 | 224 | { |
| 225 | - $this->_helper->json(array('status'=>'OK','count'=>$this->getUIDatabase()->deleteTrap($ip,$oid))); |
|
| 225 | + $this->_helper->json(array('status'=>'OK', 'count'=>$this->getUIDatabase()->deleteTrap($ip, $oid))); |
|
| 226 | 226 | return; |
| 227 | 227 | } |
| 228 | 228 | $this->_helper->json(array('status'=>'unknown action')); |
@@ -21,19 +21,19 @@ discard block |
||
| 21 | 21 | /************ Trapdb ***********/ |
| 22 | 22 | try |
| 23 | 23 | { |
| 24 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
| 24 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
| 25 | 25 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 26 | - $query = $dbConn->select()->from( |
|
| 26 | + $query=$dbConn->select()->from( |
|
| 27 | 27 | $this->getModuleConfig()->getTrapTableName(), |
| 28 | 28 | array('COUNT(*)') |
| 29 | 29 | ); |
| 30 | 30 | $this->view->trap_count=$dbConn->fetchOne($query); |
| 31 | - $query = $dbConn->select()->from( |
|
| 31 | + $query=$dbConn->select()->from( |
|
| 32 | 32 | $this->getModuleConfig()->getTrapDataTableName(), |
| 33 | 33 | array('COUNT(*)') |
| 34 | 34 | ); |
| 35 | 35 | $this->view->trap_object_count=$dbConn->fetchOne($query); |
| 36 | - $query = $dbConn->select()->from( |
|
| 36 | + $query=$dbConn->select()->from( |
|
| 37 | 37 | $this->getModuleConfig()->getTrapRuleName(), |
| 38 | 38 | array('COUNT(*)') |
| 39 | 39 | ); |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | } |
| 45 | 45 | catch (Exception $e) |
| 46 | 46 | { |
| 47 | - $this->displayExitError('status',$e->getMessage()); |
|
| 47 | + $this->displayExitError('status', $e->getMessage()); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | /*************** Log destination *******************/ |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | } |
| 60 | 60 | catch (Exception $e) |
| 61 | 61 | { |
| 62 | - $this->displayExitError('status',$e->getMessage()); |
|
| 62 | + $this->displayExitError('status', $e->getMessage()); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | } |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | if ($action == 'update_mib_db') |
| 86 | 86 | { // Do the update in background |
| 87 | 87 | $return=exec('icingacli trapdirector mib update --pid /tmp/trapdirector_update.pid'); |
| 88 | - if (preg_match('/OK/',$return)) |
|
| 88 | + if (preg_match('/OK/', $return)) |
|
| 89 | 89 | { |
| 90 | 90 | $this->_helper->json(array('status'=>'OK')); |
| 91 | 91 | } |
@@ -94,32 +94,32 @@ discard block |
||
| 94 | 94 | } |
| 95 | 95 | if ($action == 'check_update') |
| 96 | 96 | { |
| 97 | - $file=@fopen('/tmp/trapdirector_update.pid','r'); |
|
| 97 | + $file=@fopen('/tmp/trapdirector_update.pid', 'r'); |
|
| 98 | 98 | if ($file == false) |
| 99 | 99 | { // process is dead |
| 100 | - $this->_helper->json(array('status'=>'tu quoque fili','err'=>'Cannot open file')); |
|
| 100 | + $this->_helper->json(array('status'=>'tu quoque fili', 'err'=>'Cannot open file')); |
|
| 101 | 101 | return; |
| 102 | 102 | } |
| 103 | 103 | $pid=fgets($file); |
| 104 | 104 | $output=array(); |
| 105 | 105 | $retVal=0; |
| 106 | - exec('ps '.$pid,$output,$retVal); |
|
| 106 | + exec('ps '.$pid, $output, $retVal); |
|
| 107 | 107 | if ($retVal == 0) |
| 108 | 108 | { // process is alive |
| 109 | 109 | $this->_helper->json(array('status'=>'Alive and kicking')); |
| 110 | 110 | } |
| 111 | 111 | else |
| 112 | 112 | { // process is dead |
| 113 | - $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid)); |
|
| 113 | + $this->_helper->json(array('status'=>'tu quoque fili', 'err'=>'no proc'.$pid)); |
|
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | - $this->_helper->json(array('status'=>'ERR : no '.$action.' action possible' )); |
|
| 116 | + $this->_helper->json(array('status'=>'ERR : no '.$action.' action possible')); |
|
| 117 | 117 | } |
| 118 | 118 | /** Check for mib file UPLOAD */ |
| 119 | 119 | if (isset($_FILES['mibfile'])) |
| 120 | 120 | { |
| 121 | - $name=filter_var($_FILES['mibfile']['name'],FILTER_SANITIZE_STRING); |
|
| 122 | - $DirConf=explode(':',$this->Config()->get('config', 'snmptranslate_dirs')); |
|
| 121 | + $name=filter_var($_FILES['mibfile']['name'], FILTER_SANITIZE_STRING); |
|
| 122 | + $DirConf=explode(':', $this->Config()->get('config', 'snmptranslate_dirs')); |
|
| 123 | 123 | $destDir=array_shift($DirConf); |
| 124 | 124 | if (!is_dir($destDir)) |
| 125 | 125 | { |
@@ -133,9 +133,9 @@ discard block |
||
| 133 | 133 | } |
| 134 | 134 | else |
| 135 | 135 | { |
| 136 | - $destination = $destDir .'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name"; |
|
| 137 | - $sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'],FILTER_SANITIZE_STRING); |
|
| 138 | - if (move_uploaded_file($sourceTmpNam,$destination)===false) |
|
| 136 | + $destination=$destDir.'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name"; |
|
| 137 | + $sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'], FILTER_SANITIZE_STRING); |
|
| 138 | + if (move_uploaded_file($sourceTmpNam, $destination) === false) |
|
| 139 | 139 | { |
| 140 | 140 | $this->view->uploadStatus="ERROR, file $destination not loaded. Check file and path name or selinux violations"; |
| 141 | 141 | } |
@@ -151,13 +151,13 @@ discard block |
||
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | // snmptranslate tests |
| 154 | - $snmptranslate = $this->Config()->get('config', 'snmptranslate'); |
|
| 154 | + $snmptranslate=$this->Config()->get('config', 'snmptranslate'); |
|
| 155 | 155 | $this->view->snmptranslate_bin=$snmptranslate; |
| 156 | 156 | $this->view->snmptranslate_state='warn'; |
| 157 | - if (is_executable ( $snmptranslate )) |
|
| 157 | + if (is_executable($snmptranslate)) |
|
| 158 | 158 | { |
| 159 | - $translate=exec($snmptranslate . ' 1'); |
|
| 160 | - if (preg_match('/iso/',$translate)) |
|
| 159 | + $translate=exec($snmptranslate.' 1'); |
|
| 160 | + if (preg_match('/iso/', $translate)) |
|
| 161 | 161 | { |
| 162 | 162 | $this->view->snmptranslate='works fine'; |
| 163 | 163 | $this->view->snmptranslate_state='ok'; |
@@ -175,46 +175,46 @@ discard block |
||
| 175 | 175 | // mib database |
| 176 | 176 | |
| 177 | 177 | $this->view->mibDbCount=$this->getMIB()->countObjects(); |
| 178 | - $this->view->mibDbCountTrap=$this->getMIB()->countObjects(null,21); |
|
| 178 | + $this->view->mibDbCountTrap=$this->getMIB()->countObjects(null, 21); |
|
| 179 | 179 | |
| 180 | 180 | // mib dirs |
| 181 | 181 | $DirConf=$this->Config()->get('config', 'snmptranslate_dirs'); |
| 182 | - $dirArray=explode(':',$DirConf); |
|
| 182 | + $dirArray=explode(':', $DirConf); |
|
| 183 | 183 | |
| 184 | 184 | // Get base directories from net-snmp-config |
| 185 | 185 | $output=$matches=array(); |
| 186 | 186 | $retVal=0; |
| 187 | - $sysDirs=exec('net-snmp-config --default-mibdirs',$output,$retVal); |
|
| 188 | - if ($retVal==0) |
|
| 187 | + $sysDirs=exec('net-snmp-config --default-mibdirs', $output, $retVal); |
|
| 188 | + if ($retVal == 0) |
|
| 189 | 189 | { |
| 190 | - $dirArray=array_merge($dirArray,explode(':',$sysDirs)); |
|
| 190 | + $dirArray=array_merge($dirArray, explode(':', $sysDirs)); |
|
| 191 | 191 | } |
| 192 | 192 | else |
| 193 | 193 | { |
| 194 | - $translateOut=exec($this->Config()->get('config', 'snmptranslate') . ' -Dinit_mib .1.3 2>&1 | grep MIBDIRS'); |
|
| 195 | - if (preg_match('/MIBDIRS.*\'([^\']+)\'/',$translateOut,$matches)) |
|
| 194 | + $translateOut=exec($this->Config()->get('config', 'snmptranslate').' -Dinit_mib .1.3 2>&1 | grep MIBDIRS'); |
|
| 195 | + if (preg_match('/MIBDIRS.*\'([^\']+)\'/', $translateOut, $matches)) |
|
| 196 | 196 | { |
| 197 | - $dirArray=array_merge($dirArray,explode(':',$matches[1])); |
|
| 197 | + $dirArray=array_merge($dirArray, explode(':', $matches[1])); |
|
| 198 | 198 | } |
| 199 | 199 | else |
| 200 | 200 | { |
| 201 | - array_push($dirArray,'Install net-snmp-config to see system directories'); |
|
| 201 | + array_push($dirArray, 'Install net-snmp-config to see system directories'); |
|
| 202 | 202 | } |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | $this->view->dirArray=$dirArray; |
| 206 | 206 | |
| 207 | 207 | $output=null; |
| 208 | - foreach (explode(':',$DirConf) as $mibdir) |
|
| 208 | + foreach (explode(':', $DirConf) as $mibdir) |
|
| 209 | 209 | { |
| 210 | - exec('ls '.$mibdir.' | grep -v traplist.txt',$output); |
|
| 210 | + exec('ls '.$mibdir.' | grep -v traplist.txt', $output); |
|
| 211 | 211 | } |
| 212 | 212 | //$i=0;$listFiles='';while (isset($output[$i])) $listFiles.=$output[$i++]; |
| 213 | 213 | //$this->view->fileList=explode(' ',$listFiles); |
| 214 | 214 | $this->view->fileList=$output; |
| 215 | 215 | |
| 216 | 216 | // Zend form |
| 217 | - $this->view->form= new UploadForm(); |
|
| 217 | + $this->view->form=new UploadForm(); |
|
| 218 | 218 | //$this->view->form= new Form('upload-form'); |
| 219 | 219 | |
| 220 | 220 | |
@@ -238,18 +238,18 @@ discard block |
||
| 238 | 238 | $this->view->templateForm_output=''; |
| 239 | 239 | if (isset($postData['template_name']) && isset($postData['template_revert_time'])) |
| 240 | 240 | { |
| 241 | - $template_create = 'icingacli director service create --json \'{ "check_command": "dummy", '; |
|
| 242 | - $template_create .= '"check_interval": "' .$postData['template_revert_time']. '", "check_timeout": "20", "disabled": false, "enable_active_checks": true, "enable_event_handler": true, "enable_notifications": true, "enable_passive_checks": true, "enable_perfdata": true, "max_check_attempts": "1", '; |
|
| 243 | - $template_create .= '"object_name": "'.$postData['template_name'].'", "object_type": "template", "retry_interval": "'.$postData['template_revert_time'].'"}\''; |
|
| 241 | + $template_create='icingacli director service create --json \'{ "check_command": "dummy", '; |
|
| 242 | + $template_create.='"check_interval": "'.$postData['template_revert_time'].'", "check_timeout": "20", "disabled": false, "enable_active_checks": true, "enable_event_handler": true, "enable_notifications": true, "enable_passive_checks": true, "enable_perfdata": true, "max_check_attempts": "1", '; |
|
| 243 | + $template_create.='"object_name": "'.$postData['template_name'].'", "object_type": "template", "retry_interval": "'.$postData['template_revert_time'].'"}\''; |
|
| 244 | 244 | $output=array(); |
| 245 | 245 | $ret_code=0; |
| 246 | - exec($template_create,$output,$ret_code); |
|
| 246 | + exec($template_create, $output, $ret_code); |
|
| 247 | 247 | if ($ret_code != 0) |
| 248 | 248 | { |
| 249 | - $this->displayExitError("Status -> Services","Error creating template : ".$output[0].'<br>Command was : '.$template_create); |
|
| 249 | + $this->displayExitError("Status -> Services", "Error creating template : ".$output[0].'<br>Command was : '.$template_create); |
|
| 250 | 250 | } |
| 251 | - exec('icingacli director config deploy',$output,$ret_code); |
|
| 252 | - $this->view->templateForm_output='Template '.$postData['template_name']. ' created'; |
|
| 251 | + exec('icingacli director config deploy', $output, $ret_code); |
|
| 252 | + $this->view->templateForm_output='Template '.$postData['template_name'].' created'; |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | // template creation form |
@@ -265,15 +265,15 @@ discard block |
||
| 265 | 265 | { |
| 266 | 266 | $this->prepareTabs()->activate('plugins'); |
| 267 | 267 | |
| 268 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 268 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
| 269 | 269 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 270 | - $Trap = new Trap($icingaweb2_etc,4); |
|
| 270 | + $Trap=new Trap($icingaweb2_etc, 4); |
|
| 271 | 271 | |
| 272 | - $this->view->pluginLoaded = htmlentities($Trap->pluginClass->registerAllPlugins(false)); |
|
| 272 | + $this->view->pluginLoaded=htmlentities($Trap->pluginClass->registerAllPlugins(false)); |
|
| 273 | 273 | |
| 274 | - $enabledPlugins = $Trap->pluginClass->getEnabledPlugins(); |
|
| 274 | + $enabledPlugins=$Trap->pluginClass->getEnabledPlugins(); |
|
| 275 | 275 | |
| 276 | - $pluginList = $Trap->pluginClass->pluginList(); |
|
| 276 | + $pluginList=$Trap->pluginClass->pluginList(); |
|
| 277 | 277 | |
| 278 | 278 | // Plugin list and fill function name list |
| 279 | 279 | $functionList=array(); |
@@ -281,16 +281,16 @@ discard block |
||
| 281 | 281 | foreach ($pluginList as $plugin) |
| 282 | 282 | { |
| 283 | 283 | $pluginDetails=$Trap->pluginClass->pluginDetails($plugin); |
| 284 | - $pluginDetails->enabled = (in_array($plugin, $enabledPlugins)) ? true : false; |
|
| 285 | - $pluginDetails->catchAllTraps = ($pluginDetails->catchAllTraps === true )? 'Yes' : 'No'; |
|
| 286 | - $pluginDetails->processTraps = ($pluginDetails->processTraps === true )? 'Yes' : 'No'; |
|
| 287 | - $pluginDetails->description = htmlentities($pluginDetails->description); |
|
| 288 | - $pluginDetails->description = preg_replace('/\n/','<br>',$pluginDetails->description); |
|
| 284 | + $pluginDetails->enabled=(in_array($plugin, $enabledPlugins)) ? true : false; |
|
| 285 | + $pluginDetails->catchAllTraps=($pluginDetails->catchAllTraps === true) ? 'Yes' : 'No'; |
|
| 286 | + $pluginDetails->processTraps=($pluginDetails->processTraps === true) ? 'Yes' : 'No'; |
|
| 287 | + $pluginDetails->description=htmlentities($pluginDetails->description); |
|
| 288 | + $pluginDetails->description=preg_replace('/\n/', '<br>', $pluginDetails->description); |
|
| 289 | 289 | array_push($this->view->pluginArray, $pluginDetails); |
| 290 | 290 | // Get functions for function details |
| 291 | 291 | foreach ($pluginDetails->funcArray as $function) |
| 292 | 292 | { |
| 293 | - array_push($functionList,$function); |
|
| 293 | + array_push($functionList, $function); |
|
| 294 | 294 | } |
| 295 | 295 | } |
| 296 | 296 | |
@@ -298,10 +298,10 @@ discard block |
||
| 298 | 298 | $this->view->functionList=array(); |
| 299 | 299 | foreach ($functionList as $function) |
| 300 | 300 | { |
| 301 | - $functionDetail = $Trap->pluginClass->getFunctionDetails($function); |
|
| 302 | - $functionDetail->params = htmlentities($functionDetail->params); |
|
| 303 | - $functionDetail->description = htmlentities($functionDetail->description); |
|
| 304 | - $functionDetail->description = preg_replace('/\n/','<br>',$functionDetail->description); |
|
| 301 | + $functionDetail=$Trap->pluginClass->getFunctionDetails($function); |
|
| 302 | + $functionDetail->params=htmlentities($functionDetail->params); |
|
| 303 | + $functionDetail->description=htmlentities($functionDetail->description); |
|
| 304 | + $functionDetail->description=preg_replace('/\n/', '<br>', $functionDetail->description); |
|
| 305 | 305 | array_push($this->view->functionList, $functionDetail); |
| 306 | 306 | } |
| 307 | 307 | |
@@ -311,16 +311,16 @@ discard block |
||
| 311 | 311 | { |
| 312 | 312 | return $this->getTabs()->add('status', array( |
| 313 | 313 | 'label' => $this->translate('Status'), |
| 314 | - 'url' => $this->getModuleConfig()->urlPath() . '/status') |
|
| 314 | + 'url' => $this->getModuleConfig()->urlPath().'/status') |
|
| 315 | 315 | )->add('mib', array( |
| 316 | 316 | 'label' => $this->translate('MIB Management'), |
| 317 | - 'url' => $this->getModuleConfig()->urlPath() . '/status/mib') |
|
| 317 | + 'url' => $this->getModuleConfig()->urlPath().'/status/mib') |
|
| 318 | 318 | )->add('services', array( |
| 319 | 319 | 'label' => $this->translate('Services management'), |
| 320 | - 'url' => $this->getModuleConfig()->urlPath() . '/status/services') |
|
| 320 | + 'url' => $this->getModuleConfig()->urlPath().'/status/services') |
|
| 321 | 321 | )->add('plugins', array( |
| 322 | 322 | 'label' => $this->translate('Plugins management'), |
| 323 | - 'url' => $this->getModuleConfig()->urlPath() . '/status/plugins') |
|
| 323 | + 'url' => $this->getModuleConfig()->urlPath().'/status/plugins') |
|
| 324 | 324 | ); |
| 325 | 325 | } |
| 326 | 326 | } |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | // TODO : see if useless |
| 329 | 329 | class UploadForm extends Form |
| 330 | 330 | { |
| 331 | - public function __construct($options = null) |
|
| 331 | + public function __construct($options=null) |
|
| 332 | 332 | { |
| 333 | 333 | parent::__construct($options); |
| 334 | 334 | $this->addElements2(); |
@@ -337,11 +337,11 @@ discard block |
||
| 337 | 337 | public function addElements2() |
| 338 | 338 | { |
| 339 | 339 | // File Input |
| 340 | - $file = new File('mib-file'); |
|
| 340 | + $file=new File('mib-file'); |
|
| 341 | 341 | $file->setLabel('Mib upload'); |
| 342 | 342 | //->setAttrib('multiple', null); |
| 343 | 343 | $this->addElement($file); |
| 344 | - $button = new Submit("upload",array('ignore'=>false)); |
|
| 345 | - $this->addElement($button);//->setIgnore(false); |
|
| 344 | + $button=new Submit("upload", array('ignore'=>false)); |
|
| 345 | + $this->addElement($button); //->setIgnore(false); |
|
| 346 | 346 | } |
| 347 | 347 | } |
@@ -21,8 +21,8 @@ discard block |
||
| 21 | 21 | /************ Trapdb ***********/ |
| 22 | 22 | try |
| 23 | 23 | { |
| 24 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
| 25 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 24 | + $dbConn = $this->getUIDatabase()->getDbConn(); |
|
| 25 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 26 | 26 | $query = $dbConn->select()->from( |
| 27 | 27 | $this->getModuleConfig()->getTrapTableName(), |
| 28 | 28 | array('COUNT(*)') |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | |
| 52 | 52 | try |
| 53 | 53 | { |
| 54 | - $this->view->currentLogDestination=$this->getUIDatabase()->getDBConfigValue('log_destination'); |
|
| 54 | + $this->view->currentLogDestination=$this->getUIDatabase()->getDBConfigValue('log_destination'); |
|
| 55 | 55 | $this->view->logDestinations=$this->getModuleConfig()->getLogDestinations(); |
| 56 | 56 | $this->view->currentLogFile=$this->getUIDatabase()->getDBConfigValue('log_file'); |
| 57 | 57 | $this->view->logLevels=$this->getModuleConfig()->getlogLevels(); |
@@ -65,10 +65,10 @@ discard block |
||
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** Mib management |
| 68 | - * Post param : action=update_mib_db : update mib database |
|
| 69 | - * Post param : ation=check_update : check if mib update is finished |
|
| 70 | - * File post : mibfile -> save mib file |
|
| 71 | - */ |
|
| 68 | + * Post param : action=update_mib_db : update mib database |
|
| 69 | + * Post param : ation=check_update : check if mib update is finished |
|
| 70 | + * File post : mibfile -> save mib file |
|
| 71 | + */ |
|
| 72 | 72 | public function mibAction() |
| 73 | 73 | { |
| 74 | 74 | $this->prepareTabs()->activate('mib'); |
@@ -87,22 +87,22 @@ discard block |
||
| 87 | 87 | $return=exec('icingacli trapdirector mib update --pid /tmp/trapdirector_update.pid'); |
| 88 | 88 | if (preg_match('/OK/',$return)) |
| 89 | 89 | { |
| 90 | - $this->_helper->json(array('status'=>'OK')); |
|
| 90 | + $this->_helper->json(array('status'=>'OK')); |
|
| 91 | 91 | } |
| 92 | 92 | // Error |
| 93 | 93 | $this->_helper->json(array('status'=>$return)); |
| 94 | 94 | } |
| 95 | 95 | if ($action == 'check_update') |
| 96 | 96 | { |
| 97 | - $file=@fopen('/tmp/trapdirector_update.pid','r'); |
|
| 98 | - if ($file == false) |
|
| 99 | - { // process is dead |
|
| 100 | - $this->_helper->json(array('status'=>'tu quoque fili','err'=>'Cannot open file')); |
|
| 101 | - return; |
|
| 102 | - } |
|
| 103 | - $pid=fgets($file); |
|
| 104 | - $output=array(); |
|
| 105 | - $retVal=0; |
|
| 97 | + $file=@fopen('/tmp/trapdirector_update.pid','r'); |
|
| 98 | + if ($file == false) |
|
| 99 | + { // process is dead |
|
| 100 | + $this->_helper->json(array('status'=>'tu quoque fili','err'=>'Cannot open file')); |
|
| 101 | + return; |
|
| 102 | + } |
|
| 103 | + $pid=fgets($file); |
|
| 104 | + $output=array(); |
|
| 105 | + $retVal=0; |
|
| 106 | 106 | exec('ps '.$pid,$output,$retVal); |
| 107 | 107 | if ($retVal == 0) |
| 108 | 108 | { // process is alive |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | } |
| 111 | 111 | else |
| 112 | 112 | { // process is dead |
| 113 | - $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid)); |
|
| 113 | + $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid)); |
|
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | $this->_helper->json(array('status'=>'ERR : no '.$action.' action possible' )); |
@@ -118,32 +118,32 @@ discard block |
||
| 118 | 118 | /** Check for mib file UPLOAD */ |
| 119 | 119 | if (isset($_FILES['mibfile'])) |
| 120 | 120 | { |
| 121 | - $name=filter_var($_FILES['mibfile']['name'],FILTER_SANITIZE_STRING); |
|
| 121 | + $name=filter_var($_FILES['mibfile']['name'],FILTER_SANITIZE_STRING); |
|
| 122 | 122 | $DirConf=explode(':',$this->Config()->get('config', 'snmptranslate_dirs')); |
| 123 | 123 | $destDir=array_shift($DirConf); |
| 124 | 124 | if (!is_dir($destDir)) |
| 125 | 125 | { |
| 126 | - $this->view->uploadStatus="ERROR : no $destDir directory, check module configuration"; |
|
| 126 | + $this->view->uploadStatus="ERROR : no $destDir directory, check module configuration"; |
|
| 127 | 127 | } |
| 128 | 128 | else |
| 129 | 129 | { |
| 130 | - if (!is_writable($destDir)) |
|
| 131 | - { |
|
| 132 | - $this->view->uploadStatus="ERROR : $destDir directory is not writable"; |
|
| 133 | - } |
|
| 134 | - else |
|
| 135 | - { |
|
| 136 | - $destination = $destDir .'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name"; |
|
| 137 | - $sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'],FILTER_SANITIZE_STRING); |
|
| 138 | - if (move_uploaded_file($sourceTmpNam,$destination)===false) |
|
| 139 | - { |
|
| 140 | - $this->view->uploadStatus="ERROR, file $destination not loaded. Check file and path name or selinux violations"; |
|
| 141 | - } |
|
| 142 | - else |
|
| 143 | - { |
|
| 144 | - $this->view->uploadStatus="File $name uploaded in $destDir"; |
|
| 145 | - } |
|
| 146 | - } |
|
| 130 | + if (!is_writable($destDir)) |
|
| 131 | + { |
|
| 132 | + $this->view->uploadStatus="ERROR : $destDir directory is not writable"; |
|
| 133 | + } |
|
| 134 | + else |
|
| 135 | + { |
|
| 136 | + $destination = $destDir .'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name"; |
|
| 137 | + $sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'],FILTER_SANITIZE_STRING); |
|
| 138 | + if (move_uploaded_file($sourceTmpNam,$destination)===false) |
|
| 139 | + { |
|
| 140 | + $this->view->uploadStatus="ERROR, file $destination not loaded. Check file and path name or selinux violations"; |
|
| 141 | + } |
|
| 142 | + else |
|
| 143 | + { |
|
| 144 | + $this->view->uploadStatus="File $name uploaded in $destDir"; |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | } |
@@ -263,47 +263,47 @@ discard block |
||
| 263 | 263 | */ |
| 264 | 264 | public function pluginsAction() |
| 265 | 265 | { |
| 266 | - $this->prepareTabs()->activate('plugins'); |
|
| 266 | + $this->prepareTabs()->activate('plugins'); |
|
| 267 | 267 | |
| 268 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 269 | - $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
| 270 | - $Trap = new Trap($icingaweb2_etc,4); |
|
| 268 | + require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 269 | + $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
| 270 | + $Trap = new Trap($icingaweb2_etc,4); |
|
| 271 | 271 | |
| 272 | - $this->view->pluginLoaded = htmlentities($Trap->pluginClass->registerAllPlugins(false)); |
|
| 272 | + $this->view->pluginLoaded = htmlentities($Trap->pluginClass->registerAllPlugins(false)); |
|
| 273 | 273 | |
| 274 | - $enabledPlugins = $Trap->pluginClass->getEnabledPlugins(); |
|
| 274 | + $enabledPlugins = $Trap->pluginClass->getEnabledPlugins(); |
|
| 275 | 275 | |
| 276 | - $pluginList = $Trap->pluginClass->pluginList(); |
|
| 276 | + $pluginList = $Trap->pluginClass->pluginList(); |
|
| 277 | 277 | |
| 278 | - // Plugin list and fill function name list |
|
| 279 | - $functionList=array(); |
|
| 280 | - $this->view->pluginArray=array(); |
|
| 281 | - foreach ($pluginList as $plugin) |
|
| 282 | - { |
|
| 283 | - $pluginDetails=$Trap->pluginClass->pluginDetails($plugin); |
|
| 284 | - $pluginDetails->enabled = (in_array($plugin, $enabledPlugins)) ? true : false; |
|
| 285 | - $pluginDetails->catchAllTraps = ($pluginDetails->catchAllTraps === true )? 'Yes' : 'No'; |
|
| 286 | - $pluginDetails->processTraps = ($pluginDetails->processTraps === true )? 'Yes' : 'No'; |
|
| 287 | - $pluginDetails->description = htmlentities($pluginDetails->description); |
|
| 288 | - $pluginDetails->description = preg_replace('/\n/','<br>',$pluginDetails->description); |
|
| 289 | - array_push($this->view->pluginArray, $pluginDetails); |
|
| 290 | - // Get functions for function details |
|
| 291 | - foreach ($pluginDetails->funcArray as $function) |
|
| 292 | - { |
|
| 293 | - array_push($functionList,$function); |
|
| 294 | - } |
|
| 295 | - } |
|
| 278 | + // Plugin list and fill function name list |
|
| 279 | + $functionList=array(); |
|
| 280 | + $this->view->pluginArray=array(); |
|
| 281 | + foreach ($pluginList as $plugin) |
|
| 282 | + { |
|
| 283 | + $pluginDetails=$Trap->pluginClass->pluginDetails($plugin); |
|
| 284 | + $pluginDetails->enabled = (in_array($plugin, $enabledPlugins)) ? true : false; |
|
| 285 | + $pluginDetails->catchAllTraps = ($pluginDetails->catchAllTraps === true )? 'Yes' : 'No'; |
|
| 286 | + $pluginDetails->processTraps = ($pluginDetails->processTraps === true )? 'Yes' : 'No'; |
|
| 287 | + $pluginDetails->description = htmlentities($pluginDetails->description); |
|
| 288 | + $pluginDetails->description = preg_replace('/\n/','<br>',$pluginDetails->description); |
|
| 289 | + array_push($this->view->pluginArray, $pluginDetails); |
|
| 290 | + // Get functions for function details |
|
| 291 | + foreach ($pluginDetails->funcArray as $function) |
|
| 292 | + { |
|
| 293 | + array_push($functionList,$function); |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | 296 | |
| 297 | - // Function list with details |
|
| 298 | - $this->view->functionList=array(); |
|
| 299 | - foreach ($functionList as $function) |
|
| 300 | - { |
|
| 301 | - $functionDetail = $Trap->pluginClass->getFunctionDetails($function); |
|
| 302 | - $functionDetail->params = htmlentities($functionDetail->params); |
|
| 303 | - $functionDetail->description = htmlentities($functionDetail->description); |
|
| 304 | - $functionDetail->description = preg_replace('/\n/','<br>',$functionDetail->description); |
|
| 305 | - array_push($this->view->functionList, $functionDetail); |
|
| 306 | - } |
|
| 297 | + // Function list with details |
|
| 298 | + $this->view->functionList=array(); |
|
| 299 | + foreach ($functionList as $function) |
|
| 300 | + { |
|
| 301 | + $functionDetail = $Trap->pluginClass->getFunctionDetails($function); |
|
| 302 | + $functionDetail->params = htmlentities($functionDetail->params); |
|
| 303 | + $functionDetail->description = htmlentities($functionDetail->description); |
|
| 304 | + $functionDetail->description = preg_replace('/\n/','<br>',$functionDetail->description); |
|
| 305 | + array_push($this->view->functionList, $functionDetail); |
|
| 306 | + } |
|
| 307 | 307 | |
| 308 | 308 | } |
| 309 | 309 | |
@@ -318,30 +318,30 @@ discard block |
||
| 318 | 318 | )->add('services', array( |
| 319 | 319 | 'label' => $this->translate('Services management'), |
| 320 | 320 | 'url' => $this->getModuleConfig()->urlPath() . '/status/services') |
| 321 | - )->add('plugins', array( |
|
| 322 | - 'label' => $this->translate('Plugins management'), |
|
| 323 | - 'url' => $this->getModuleConfig()->urlPath() . '/status/plugins') |
|
| 324 | - ); |
|
| 321 | + )->add('plugins', array( |
|
| 322 | + 'label' => $this->translate('Plugins management'), |
|
| 323 | + 'url' => $this->getModuleConfig()->urlPath() . '/status/plugins') |
|
| 324 | + ); |
|
| 325 | 325 | } |
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | // TODO : see if useless |
| 329 | 329 | class UploadForm extends Form |
| 330 | 330 | { |
| 331 | - public function __construct($options = null) |
|
| 332 | - { |
|
| 333 | - parent::__construct($options); |
|
| 334 | - $this->addElements2(); |
|
| 335 | - } |
|
| 331 | + public function __construct($options = null) |
|
| 332 | + { |
|
| 333 | + parent::__construct($options); |
|
| 334 | + $this->addElements2(); |
|
| 335 | + } |
|
| 336 | 336 | |
| 337 | - public function addElements2() |
|
| 338 | - { |
|
| 339 | - // File Input |
|
| 340 | - $file = new File('mib-file'); |
|
| 341 | - $file->setLabel('Mib upload'); |
|
| 342 | - //->setAttrib('multiple', null); |
|
| 343 | - $this->addElement($file); |
|
| 337 | + public function addElements2() |
|
| 338 | + { |
|
| 339 | + // File Input |
|
| 340 | + $file = new File('mib-file'); |
|
| 341 | + $file->setLabel('Mib upload'); |
|
| 342 | + //->setAttrib('multiple', null); |
|
| 343 | + $this->addElement($file); |
|
| 344 | 344 | $button = new Submit("upload",array('ignore'=>false)); |
| 345 | 345 | $this->addElement($button);//->setIgnore(false); |
| 346 | - } |
|
| 346 | + } |
|
| 347 | 347 | } |
@@ -22,7 +22,9 @@ discard block |
||
| 22 | 22 | try |
| 23 | 23 | { |
| 24 | 24 | $dbConn = $this->getUIDatabase()->getDbConn(); |
| 25 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 25 | + if ($dbConn === null) { |
|
| 26 | + throw new \ErrorException('uncatched db error'); |
|
| 27 | + } |
|
| 26 | 28 | $query = $dbConn->select()->from( |
| 27 | 29 | $this->getModuleConfig()->getTrapTableName(), |
| 28 | 30 | array('COUNT(*)') |
@@ -41,8 +43,7 @@ discard block |
||
| 41 | 43 | |
| 42 | 44 | $this->view->trap_days_delete=$this->getUIDatabase()->getDBConfigValue('db_remove_days'); |
| 43 | 45 | |
| 44 | - } |
|
| 45 | - catch (Exception $e) |
|
| 46 | + } catch (Exception $e) |
|
| 46 | 47 | { |
| 47 | 48 | $this->displayExitError('status',$e->getMessage()); |
| 48 | 49 | } |
@@ -56,8 +57,7 @@ discard block |
||
| 56 | 57 | $this->view->currentLogFile=$this->getUIDatabase()->getDBConfigValue('log_file'); |
| 57 | 58 | $this->view->logLevels=$this->getModuleConfig()->getlogLevels(); |
| 58 | 59 | $this->view->currentLogLevel=$this->getUIDatabase()->getDBConfigValue('log_level'); |
| 59 | - } |
|
| 60 | - catch (Exception $e) |
|
| 60 | + } catch (Exception $e) |
|
| 61 | 61 | { |
| 62 | 62 | $this->displayExitError('status',$e->getMessage()); |
| 63 | 63 | } |
@@ -107,8 +107,7 @@ discard block |
||
| 107 | 107 | if ($retVal == 0) |
| 108 | 108 | { // process is alive |
| 109 | 109 | $this->_helper->json(array('status'=>'Alive and kicking')); |
| 110 | - } |
|
| 111 | - else |
|
| 110 | + } else |
|
| 112 | 111 | { // process is dead |
| 113 | 112 | $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid)); |
| 114 | 113 | } |
@@ -124,22 +123,19 @@ discard block |
||
| 124 | 123 | if (!is_dir($destDir)) |
| 125 | 124 | { |
| 126 | 125 | $this->view->uploadStatus="ERROR : no $destDir directory, check module configuration"; |
| 127 | - } |
|
| 128 | - else |
|
| 126 | + } else |
|
| 129 | 127 | { |
| 130 | 128 | if (!is_writable($destDir)) |
| 131 | 129 | { |
| 132 | 130 | $this->view->uploadStatus="ERROR : $destDir directory is not writable"; |
| 133 | - } |
|
| 134 | - else |
|
| 131 | + } else |
|
| 135 | 132 | { |
| 136 | 133 | $destination = $destDir .'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name"; |
| 137 | 134 | $sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'],FILTER_SANITIZE_STRING); |
| 138 | 135 | if (move_uploaded_file($sourceTmpNam,$destination)===false) |
| 139 | 136 | { |
| 140 | 137 | $this->view->uploadStatus="ERROR, file $destination not loaded. Check file and path name or selinux violations"; |
| 141 | - } |
|
| 142 | - else |
|
| 138 | + } else |
|
| 143 | 139 | { |
| 144 | 140 | $this->view->uploadStatus="File $name uploaded in $destDir"; |
| 145 | 141 | } |
@@ -161,13 +157,11 @@ discard block |
||
| 161 | 157 | { |
| 162 | 158 | $this->view->snmptranslate='works fine'; |
| 163 | 159 | $this->view->snmptranslate_state='ok'; |
| 164 | - } |
|
| 165 | - else |
|
| 160 | + } else |
|
| 166 | 161 | { |
| 167 | 162 | $this->view->snmptranslate='can execute but no resolution'; |
| 168 | 163 | } |
| 169 | - } |
|
| 170 | - else |
|
| 164 | + } else |
|
| 171 | 165 | { |
| 172 | 166 | $this->view->snmptranslate='cannot execute'; |
| 173 | 167 | } |
@@ -188,15 +182,13 @@ discard block |
||
| 188 | 182 | if ($retVal==0) |
| 189 | 183 | { |
| 190 | 184 | $dirArray=array_merge($dirArray,explode(':',$sysDirs)); |
| 191 | - } |
|
| 192 | - else |
|
| 185 | + } else |
|
| 193 | 186 | { |
| 194 | 187 | $translateOut=exec($this->Config()->get('config', 'snmptranslate') . ' -Dinit_mib .1.3 2>&1 | grep MIBDIRS'); |
| 195 | 188 | if (preg_match('/MIBDIRS.*\'([^\']+)\'/',$translateOut,$matches)) |
| 196 | 189 | { |
| 197 | 190 | $dirArray=array_merge($dirArray,explode(':',$matches[1])); |
| 198 | - } |
|
| 199 | - else |
|
| 191 | + } else |
|
| 200 | 192 | { |
| 201 | 193 | array_push($dirArray,'Install net-snmp-config to see system directories'); |
| 202 | 194 | } |
@@ -25,16 +25,16 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | private function get_param() |
| 27 | 27 | { |
| 28 | - $dberrorMsg=$this->params->get('dberror'); |
|
| 29 | - if ($dberrorMsg != '') |
|
| 30 | - { |
|
| 31 | - $this->view->errorDetected=$dberrorMsg; |
|
| 32 | - } |
|
| 33 | - $dberrorMsg=$this->params->get('idodberror'); |
|
| 34 | - if ($dberrorMsg != '') |
|
| 35 | - { |
|
| 36 | - $this->view->errorDetected=$dberrorMsg; |
|
| 37 | - } |
|
| 28 | + $dberrorMsg=$this->params->get('dberror'); |
|
| 29 | + if ($dberrorMsg != '') |
|
| 30 | + { |
|
| 31 | + $this->view->errorDetected=$dberrorMsg; |
|
| 32 | + } |
|
| 33 | + $dberrorMsg=$this->params->get('idodberror'); |
|
| 34 | + if ($dberrorMsg != '') |
|
| 35 | + { |
|
| 36 | + $this->view->errorDetected=$dberrorMsg; |
|
| 37 | + } |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -43,22 +43,22 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | private function check_empty_config() |
| 45 | 45 | { |
| 46 | - $this->view->configErrorDetected == NULL; // Displayed error on various conifugration errors. |
|
| 47 | - if ($this->Config()->isEmpty() == true) |
|
| 48 | - { |
|
| 49 | - $this->Config()->setSection('config'); // Set base config section. |
|
| 50 | - try |
|
| 51 | - { |
|
| 52 | - $this->Config()->saveIni(); |
|
| 53 | - $this->view->configErrorDetected='Configuration is empty : you can run install script with parameters (see Automatic installation below)'; |
|
| 54 | - //$emptyConfig=1; |
|
| 55 | - } |
|
| 56 | - catch (Exception $e) |
|
| 57 | - { |
|
| 58 | - $this->view->configErrorDetected=$e->getMessage(); |
|
| 59 | - } |
|
| 46 | + $this->view->configErrorDetected == NULL; // Displayed error on various conifugration errors. |
|
| 47 | + if ($this->Config()->isEmpty() == true) |
|
| 48 | + { |
|
| 49 | + $this->Config()->setSection('config'); // Set base config section. |
|
| 50 | + try |
|
| 51 | + { |
|
| 52 | + $this->Config()->saveIni(); |
|
| 53 | + $this->view->configErrorDetected='Configuration is empty : you can run install script with parameters (see Automatic installation below)'; |
|
| 54 | + //$emptyConfig=1; |
|
| 55 | + } |
|
| 56 | + catch (Exception $e) |
|
| 57 | + { |
|
| 58 | + $this->view->configErrorDetected=$e->getMessage(); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - } |
|
| 61 | + } |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -71,56 +71,56 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | private function check_db() |
| 73 | 73 | { |
| 74 | - $db_message=array( // index => ( message OK, message NOK, optional link if NOK ) |
|
| 75 | - 0 => array('Database configuration OK','',''), |
|
| 76 | - 1 => array('Database set in config.ini','No database in config.ini',''), |
|
| 77 | - 2 => array('Database exists in Icingaweb2 config','Database does not exist in Icingaweb2 : ', |
|
| 78 | - Url::fromPath('config/resource')), |
|
| 79 | - 3 => array('Database credentials OK','Database does not exist/invalid credentials/no schema : ', |
|
| 80 | - Url::fromPath('trapdirector/settings/createschema')), |
|
| 81 | - 4 => array('Schema is set','Schema is not set for ', |
|
| 82 | - Url::fromPath('trapdirector/settings/createschema')), |
|
| 83 | - 5 => array('Schema is up to date','Schema is outdated :', |
|
| 84 | - Url::fromPath('trapdirector/settings/updateschema')), |
|
| 85 | - ); |
|
| 74 | + $db_message=array( // index => ( message OK, message NOK, optional link if NOK ) |
|
| 75 | + 0 => array('Database configuration OK','',''), |
|
| 76 | + 1 => array('Database set in config.ini','No database in config.ini',''), |
|
| 77 | + 2 => array('Database exists in Icingaweb2 config','Database does not exist in Icingaweb2 : ', |
|
| 78 | + Url::fromPath('config/resource')), |
|
| 79 | + 3 => array('Database credentials OK','Database does not exist/invalid credentials/no schema : ', |
|
| 80 | + Url::fromPath('trapdirector/settings/createschema')), |
|
| 81 | + 4 => array('Schema is set','Schema is not set for ', |
|
| 82 | + Url::fromPath('trapdirector/settings/createschema')), |
|
| 83 | + 5 => array('Schema is up to date','Schema is outdated :', |
|
| 84 | + Url::fromPath('trapdirector/settings/updateschema')), |
|
| 85 | + ); |
|
| 86 | 86 | |
| 87 | - try { |
|
| 88 | - $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
|
| 89 | - $dberror=array(0,''); |
|
| 90 | - } catch (DBException $e) { |
|
| 91 | - $dberror = $e->getArray(); |
|
| 92 | - } |
|
| 87 | + try { |
|
| 88 | + $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
|
| 89 | + $dberror=array(0,''); |
|
| 90 | + } catch (DBException $e) { |
|
| 91 | + $dberror = $e->getArray(); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - $this->view->db_error=$dberror[0]; |
|
| 95 | - switch ($dberror[0]) |
|
| 96 | - { |
|
| 97 | - case 2: |
|
| 98 | - case 4: |
|
| 99 | - $db_message[$dberror[0]][1] .= $dberror[1]; |
|
| 100 | - break; |
|
| 101 | - case 3: |
|
| 102 | - $db_message[$dberror[0]][1] .= $dberror[1] . ', Message : ' . $dberror[2]; |
|
| 103 | - break; |
|
| 104 | - case 5: |
|
| 105 | - $db_message[$dberror[0]][1] .= ' version '. $dberror[1] . ', version needed : ' .$dberror[2]; |
|
| 106 | - break; |
|
| 107 | - case 0: |
|
| 108 | - case 1: |
|
| 109 | - break; |
|
| 110 | - default: |
|
| 111 | - new ProgrammingError('Out of bond result from database test'); |
|
| 112 | - } |
|
| 113 | - $this->view->message=$db_message; |
|
| 94 | + $this->view->db_error=$dberror[0]; |
|
| 95 | + switch ($dberror[0]) |
|
| 96 | + { |
|
| 97 | + case 2: |
|
| 98 | + case 4: |
|
| 99 | + $db_message[$dberror[0]][1] .= $dberror[1]; |
|
| 100 | + break; |
|
| 101 | + case 3: |
|
| 102 | + $db_message[$dberror[0]][1] .= $dberror[1] . ', Message : ' . $dberror[2]; |
|
| 103 | + break; |
|
| 104 | + case 5: |
|
| 105 | + $db_message[$dberror[0]][1] .= ' version '. $dberror[1] . ', version needed : ' .$dberror[2]; |
|
| 106 | + break; |
|
| 107 | + case 0: |
|
| 108 | + case 1: |
|
| 109 | + break; |
|
| 110 | + default: |
|
| 111 | + new ProgrammingError('Out of bond result from database test'); |
|
| 112 | + } |
|
| 113 | + $this->view->message=$db_message; |
|
| 114 | 114 | |
| 115 | - try { |
|
| 116 | - $this->getUIDatabase()->testGetIdoDb(); // Get DB in test mode |
|
| 117 | - $dberror=array(0,''); |
|
| 118 | - } catch (DBException $e) { |
|
| 119 | - $dberror = $e->getArray(); |
|
| 120 | - } |
|
| 115 | + try { |
|
| 116 | + $this->getUIDatabase()->testGetIdoDb(); // Get DB in test mode |
|
| 117 | + $dberror=array(0,''); |
|
| 118 | + } catch (DBException $e) { |
|
| 119 | + $dberror = $e->getArray(); |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - $this->view->ido_db_error=$dberror[0]; |
|
| 123 | - $this->view->ido_message='IDO Database : ' . $dberror[1]; |
|
| 122 | + $this->view->ido_db_error=$dberror[0]; |
|
| 123 | + $this->view->ido_message='IDO Database : ' . $dberror[1]; |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** |
@@ -130,23 +130,23 @@ discard block |
||
| 130 | 130 | */ |
| 131 | 131 | private function check_api() |
| 132 | 132 | { |
| 133 | - if ($this->Config()->get('config', 'icingaAPI_host') != '') |
|
| 134 | - { |
|
| 135 | - $apitest=new Icinga2Api($this->Config()->get('config', 'icingaAPI_host'),$this->Config()->get('config', 'icingaAPI_port')); |
|
| 136 | - $apitest->setCredentials($this->Config()->get('config', 'icingaAPI_user'), $this->Config()->get('config', 'icingaAPI_password')); |
|
| 137 | - try { |
|
| 138 | - list($this->view->apimessageError,$this->view->apimessage)=$apitest->test($this->getModuleConfig()::getapiUserPermissions()); |
|
| 139 | - //$this->view->apimessageError=false; |
|
| 140 | - } catch (RuntimeException $e) { |
|
| 141 | - $this->view->apimessage='API config : ' . $e->getMessage(); |
|
| 142 | - $this->view->apimessageError=true; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - else |
|
| 146 | - { |
|
| 147 | - $this->view->apimessage='API parameters not configured'; |
|
| 148 | - $this->view->apimessageError=true; |
|
| 149 | - } |
|
| 133 | + if ($this->Config()->get('config', 'icingaAPI_host') != '') |
|
| 134 | + { |
|
| 135 | + $apitest=new Icinga2Api($this->Config()->get('config', 'icingaAPI_host'),$this->Config()->get('config', 'icingaAPI_port')); |
|
| 136 | + $apitest->setCredentials($this->Config()->get('config', 'icingaAPI_user'), $this->Config()->get('config', 'icingaAPI_password')); |
|
| 137 | + try { |
|
| 138 | + list($this->view->apimessageError,$this->view->apimessage)=$apitest->test($this->getModuleConfig()::getapiUserPermissions()); |
|
| 139 | + //$this->view->apimessageError=false; |
|
| 140 | + } catch (RuntimeException $e) { |
|
| 141 | + $this->view->apimessage='API config : ' . $e->getMessage(); |
|
| 142 | + $this->view->apimessageError=true; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + else |
|
| 146 | + { |
|
| 147 | + $this->view->apimessage='API parameters not configured'; |
|
| 148 | + $this->view->apimessageError=true; |
|
| 149 | + } |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | /** |
@@ -157,21 +157,21 @@ discard block |
||
| 157 | 157 | */ |
| 158 | 158 | private function check_icingaweb_path() |
| 159 | 159 | { |
| 160 | - $this->view->icingaEtcWarn=0; |
|
| 161 | - $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
| 162 | - if ($icingaweb2_etc != "/etc/icingaweb2/" && $icingaweb2_etc != '') |
|
| 163 | - { |
|
| 164 | - $output=array(); |
|
| 160 | + $this->view->icingaEtcWarn=0; |
|
| 161 | + $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
| 162 | + if ($icingaweb2_etc != "/etc/icingaweb2/" && $icingaweb2_etc != '') |
|
| 163 | + { |
|
| 164 | + $output=array(); |
|
| 165 | 165 | |
| 166 | - exec('cat ' . $this->module->getBaseDir() .'/bin/trap_in.php | grep "\$icingaweb2Etc=" ',$output); |
|
| 166 | + exec('cat ' . $this->module->getBaseDir() .'/bin/trap_in.php | grep "\$icingaweb2Etc=" ',$output); |
|
| 167 | 167 | |
| 168 | 168 | |
| 169 | - if (! isset($output[0]) || ! preg_match('#"'. $icingaweb2_etc .'"#',$output[0])) |
|
| 170 | - { |
|
| 171 | - $this->view->icingaEtcWarn=1; |
|
| 172 | - $this->view->icingaweb2_etc=$icingaweb2_etc; |
|
| 173 | - } |
|
| 174 | - } |
|
| 169 | + if (! isset($output[0]) || ! preg_match('#"'. $icingaweb2_etc .'"#',$output[0])) |
|
| 170 | + { |
|
| 171 | + $this->view->icingaEtcWarn=1; |
|
| 172 | + $this->view->icingaweb2_etc=$icingaweb2_etc; |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | 176 | } |
| 177 | 177 | |
@@ -182,15 +182,15 @@ discard block |
||
| 182 | 182 | */ |
| 183 | 183 | private function get_db_list($allowed) |
| 184 | 184 | { |
| 185 | - $resources = array(); |
|
| 186 | - foreach (ResourceFactory::getResourceConfigs() as $name => $resource) |
|
| 187 | - { |
|
| 188 | - if ($resource->get('type') === 'db' && in_array($resource->get('db'), $allowed)) |
|
| 189 | - { |
|
| 190 | - $resources[$name] = $name; |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - return $resources; |
|
| 185 | + $resources = array(); |
|
| 186 | + foreach (ResourceFactory::getResourceConfigs() as $name => $resource) |
|
| 187 | + { |
|
| 188 | + if ($resource->get('type') === 'db' && in_array($resource->get('db'), $allowed)) |
|
| 189 | + { |
|
| 190 | + $resources[$name] = $name; |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + return $resources; |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | /** |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | public function indexAction() |
| 210 | 210 | { |
| 211 | 211 | |
| 212 | - // CHeck permissions : display tests in any case, but no configuration. |
|
| 212 | + // CHeck permissions : display tests in any case, but no configuration. |
|
| 213 | 213 | $this->view->configPermission=$this->checkModuleConfigPermission(1); |
| 214 | 214 | // But check read permission |
| 215 | 215 | $this->checkReadPermission(); |
@@ -217,16 +217,16 @@ discard block |
||
| 217 | 217 | $this->view->tabs = $this->Module()->getConfigTabs()->activate('config'); |
| 218 | 218 | |
| 219 | 219 | // Get message : sent on configuration problems detected by controllers |
| 220 | - $this->get_param(); |
|
| 220 | + $this->get_param(); |
|
| 221 | 221 | |
| 222 | - // Test if configuration exists, if not create for installer script |
|
| 222 | + // Test if configuration exists, if not create for installer script |
|
| 223 | 223 | $this->check_empty_config(); |
| 224 | 224 | |
| 225 | 225 | // Test Database |
| 226 | - $this->check_db(); |
|
| 226 | + $this->check_db(); |
|
| 227 | 227 | |
| 228 | 228 | //********* Test API |
| 229 | - $this->check_api(); |
|
| 229 | + $this->check_api(); |
|
| 230 | 230 | |
| 231 | 231 | //*********** Test snmptrapd alive and options |
| 232 | 232 | list ($this->view->snmptrapdError, $this->view->snmptrapdMessage) = $this->checkSnmpTrapd(); |
@@ -241,11 +241,11 @@ discard block |
||
| 241 | 241 | $this->view->traps_in_config= PHP_BINARY . ' ' . $this->Module()->getBaseDir() . '/bin/trap_in.php'; |
| 242 | 242 | |
| 243 | 243 | $this->view->installer= $this->Module()->getBaseDir() . '/bin/installer.sh ' |
| 244 | - . ' -c all ' |
|
| 245 | - . ' -d ' . $this->Module()->getBaseDir() |
|
| 246 | - . ' -p ' . PHP_BINARY |
|
| 247 | - . ' -a ' . exec('whoami') |
|
| 248 | - . ' -w ' . Icinga::app()->getConfigDir(); |
|
| 244 | + . ' -c all ' |
|
| 245 | + . ' -d ' . $this->Module()->getBaseDir() |
|
| 246 | + . ' -p ' . PHP_BINARY |
|
| 247 | + . ' -a ' . exec('whoami') |
|
| 248 | + . ' -w ' . Icinga::app()->getConfigDir(); |
|
| 249 | 249 | |
| 250 | 250 | // ******************* configuration form setup******************* |
| 251 | 251 | $this->view->form = $form = new TrapsConfigForm(); |
@@ -275,8 +275,8 @@ discard block |
||
| 275 | 275 | |
| 276 | 276 | try |
| 277 | 277 | { |
| 278 | - $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
|
| 279 | - printf('Schema already exists'); |
|
| 278 | + $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
|
| 279 | + printf('Schema already exists'); |
|
| 280 | 280 | |
| 281 | 281 | } |
| 282 | 282 | catch (DBException $e) |
@@ -287,19 +287,19 @@ discard block |
||
| 287 | 287 | // Get module database name |
| 288 | 288 | $dbName=$this->Config()->get('config', 'database'); |
| 289 | 289 | |
| 290 | - $dbResource = ResourceFactory::getResourceConfig($dbName); |
|
| 291 | - $dbType=$dbResource->get('db'); |
|
| 292 | - switch ($dbType) { |
|
| 293 | - case 'mysql': |
|
| 294 | - $dbFileExt='sql'; |
|
| 295 | - break; |
|
| 296 | - case 'pgsql': |
|
| 297 | - $dbFileExt='pgsql'; |
|
| 298 | - break; |
|
| 299 | - default: |
|
| 300 | - printf("Database configuration error : Unsuported DB"); |
|
| 301 | - return; |
|
| 302 | - } |
|
| 290 | + $dbResource = ResourceFactory::getResourceConfig($dbName); |
|
| 291 | + $dbType=$dbResource->get('db'); |
|
| 292 | + switch ($dbType) { |
|
| 293 | + case 'mysql': |
|
| 294 | + $dbFileExt='sql'; |
|
| 295 | + break; |
|
| 296 | + case 'pgsql': |
|
| 297 | + $dbFileExt='pgsql'; |
|
| 298 | + break; |
|
| 299 | + default: |
|
| 300 | + printf("Database configuration error : Unsuported DB"); |
|
| 301 | + return; |
|
| 302 | + } |
|
| 303 | 303 | |
| 304 | 304 | printf('<pre>'); |
| 305 | 305 | require_once $this->Module()->getBaseDir() .'/bin/trap_class.php'; |
@@ -323,32 +323,32 @@ discard block |
||
| 323 | 323 | public function updateschemaAction() |
| 324 | 324 | { |
| 325 | 325 | $this->checkModuleConfigPermission(); |
| 326 | - $this->getTabs()->add('get',array( |
|
| 327 | - 'active' => true, |
|
| 328 | - 'label' => $this->translate('Update Schema'), |
|
| 329 | - 'url' => Url::fromRequest() |
|
| 330 | - )); |
|
| 326 | + $this->getTabs()->add('get',array( |
|
| 327 | + 'active' => true, |
|
| 328 | + 'label' => $this->translate('Update Schema'), |
|
| 329 | + 'url' => Url::fromRequest() |
|
| 330 | + )); |
|
| 331 | 331 | // check if needed |
| 332 | 332 | $dberror=array(); |
| 333 | - try |
|
| 334 | - { |
|
| 335 | - $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
|
| 336 | - echo 'Schema already exists and is up to date<br>'; |
|
| 337 | - return; |
|
| 338 | - } |
|
| 339 | - catch (DBException $e) |
|
| 340 | - { |
|
| 341 | - $dberror=$e->getArray(); |
|
| 342 | - } |
|
| 333 | + try |
|
| 334 | + { |
|
| 335 | + $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
|
| 336 | + echo 'Schema already exists and is up to date<br>'; |
|
| 337 | + return; |
|
| 338 | + } |
|
| 339 | + catch (DBException $e) |
|
| 340 | + { |
|
| 341 | + $dberror=$e->getArray(); |
|
| 342 | + } |
|
| 343 | 343 | |
| 344 | 344 | echo 'Return to <a href="' . Url::fromPath('trapdirector/settings') .'" class="link-button icon-wrench"> settings page </a><br><br>'; |
| 345 | 345 | |
| 346 | 346 | if ($dberror[0] != 5) |
| 347 | 347 | { |
| 348 | - echo 'Database does not exists or is not setup correctly<br>'; |
|
| 349 | - return; |
|
| 348 | + echo 'Database does not exists or is not setup correctly<br>'; |
|
| 349 | + return; |
|
| 350 | 350 | } |
| 351 | - // setup |
|
| 351 | + // setup |
|
| 352 | 352 | require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
| 353 | 353 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 354 | 354 | $debug_level=4; |
@@ -361,20 +361,20 @@ discard block |
||
| 361 | 361 | $target_version=$dberror[2]; |
| 362 | 362 | |
| 363 | 363 | if ($this->params->get('msgok') == null) { |
| 364 | - // Check for messages and display if any |
|
| 365 | - echo "Upgrade databse is going to start.<br>Don't forget to backup your database before update<br>"; |
|
| 366 | - $Trap->setLogging(2,'syslog'); |
|
| 367 | - $message = $Trap->trapsDB->update_schema($updateSchema,$target_version,$prefix,true); |
|
| 368 | - if ($message != '') |
|
| 369 | - { |
|
| 370 | - echo 'Note :<br><pre>'; |
|
| 371 | - echo $message; |
|
| 372 | - echo '</pre>'; |
|
| 373 | - echo '<br>'; |
|
| 374 | - echo '<a class="link-button" style="font-size:large;font-weight:bold" href="' . Url::fromPath('trapdirector/settings/updateschema') .'?msgok=1">Click here to update</a>'; |
|
| 375 | - echo '<br>'; |
|
| 376 | - return; |
|
| 377 | - } |
|
| 364 | + // Check for messages and display if any |
|
| 365 | + echo "Upgrade databse is going to start.<br>Don't forget to backup your database before update<br>"; |
|
| 366 | + $Trap->setLogging(2,'syslog'); |
|
| 367 | + $message = $Trap->trapsDB->update_schema($updateSchema,$target_version,$prefix,true); |
|
| 368 | + if ($message != '') |
|
| 369 | + { |
|
| 370 | + echo 'Note :<br><pre>'; |
|
| 371 | + echo $message; |
|
| 372 | + echo '</pre>'; |
|
| 373 | + echo '<br>'; |
|
| 374 | + echo '<a class="link-button" style="font-size:large;font-weight:bold" href="' . Url::fromPath('trapdirector/settings/updateschema') .'?msgok=1">Click here to update</a>'; |
|
| 375 | + echo '<br>'; |
|
| 376 | + return; |
|
| 377 | + } |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | $Trap->setLogging($debug_level,'display'); |
@@ -388,28 +388,28 @@ discard block |
||
| 388 | 388 | |
| 389 | 389 | private function checkSnmpTrapd() |
| 390 | 390 | { |
| 391 | - $psOutput=array(); |
|
| 392 | - // First check is someone is listening to port 162. As not root, we can't have pid... |
|
| 393 | - exec('netstat -an |grep -E "udp.*:162"',$psOutput); |
|
| 394 | - if (count($psOutput) == 0) |
|
| 395 | - { |
|
| 396 | - return array(1,'Port UDP/162 is not open : snmptrapd must not be started'); |
|
| 397 | - } |
|
| 398 | - $psOutput=array(); |
|
| 399 | - exec('ps fax |grep snmptrapd |grep -v grep',$psOutput); |
|
| 400 | - if (count($psOutput) == 0) |
|
| 401 | - { |
|
| 402 | - return array(1,"UDP/162 : OK, but no snmptrapd process (?)"); |
|
| 403 | - } |
|
| 404 | - // Assume there is only one line... TODO : see if there is a better way to do this |
|
| 405 | - $line = preg_replace('/^.*snmptrapd /','',$psOutput[0]); |
|
| 406 | - if (!preg_match('/-n/',$line)) |
|
| 407 | - return array(1,'snmptrapd has no -n option : '.$line); |
|
| 408 | - if (!preg_match('/-O[^ ]*n/',$line)) |
|
| 409 | - return array(1,'snmptrapd has no -On option : '.$line); |
|
| 410 | - if (!preg_match('/-O[^ ]*e/',$line)) |
|
| 411 | - return array(1,'snmptrapd has no -Oe option : '.$line); |
|
| 391 | + $psOutput=array(); |
|
| 392 | + // First check is someone is listening to port 162. As not root, we can't have pid... |
|
| 393 | + exec('netstat -an |grep -E "udp.*:162"',$psOutput); |
|
| 394 | + if (count($psOutput) == 0) |
|
| 395 | + { |
|
| 396 | + return array(1,'Port UDP/162 is not open : snmptrapd must not be started'); |
|
| 397 | + } |
|
| 398 | + $psOutput=array(); |
|
| 399 | + exec('ps fax |grep snmptrapd |grep -v grep',$psOutput); |
|
| 400 | + if (count($psOutput) == 0) |
|
| 401 | + { |
|
| 402 | + return array(1,"UDP/162 : OK, but no snmptrapd process (?)"); |
|
| 403 | + } |
|
| 404 | + // Assume there is only one line... TODO : see if there is a better way to do this |
|
| 405 | + $line = preg_replace('/^.*snmptrapd /','',$psOutput[0]); |
|
| 406 | + if (!preg_match('/-n/',$line)) |
|
| 407 | + return array(1,'snmptrapd has no -n option : '.$line); |
|
| 408 | + if (!preg_match('/-O[^ ]*n/',$line)) |
|
| 409 | + return array(1,'snmptrapd has no -On option : '.$line); |
|
| 410 | + if (!preg_match('/-O[^ ]*e/',$line)) |
|
| 411 | + return array(1,'snmptrapd has no -Oe option : '.$line); |
|
| 412 | 412 | |
| 413 | - return array(0,'snmptrapd listening to UDP/162, options : '.$line); |
|
| 413 | + return array(0,'snmptrapd listening to UDP/162, options : '.$line); |
|
| 414 | 414 | } |
| 415 | 415 | } |
@@ -72,23 +72,23 @@ discard block |
||
| 72 | 72 | private function check_db() |
| 73 | 73 | { |
| 74 | 74 | $db_message=array( // index => ( message OK, message NOK, optional link if NOK ) |
| 75 | - 0 => array('Database configuration OK','',''), |
|
| 76 | - 1 => array('Database set in config.ini','No database in config.ini',''), |
|
| 77 | - 2 => array('Database exists in Icingaweb2 config','Database does not exist in Icingaweb2 : ', |
|
| 75 | + 0 => array('Database configuration OK', '', ''), |
|
| 76 | + 1 => array('Database set in config.ini', 'No database in config.ini', ''), |
|
| 77 | + 2 => array('Database exists in Icingaweb2 config', 'Database does not exist in Icingaweb2 : ', |
|
| 78 | 78 | Url::fromPath('config/resource')), |
| 79 | - 3 => array('Database credentials OK','Database does not exist/invalid credentials/no schema : ', |
|
| 79 | + 3 => array('Database credentials OK', 'Database does not exist/invalid credentials/no schema : ', |
|
| 80 | 80 | Url::fromPath('trapdirector/settings/createschema')), |
| 81 | - 4 => array('Schema is set','Schema is not set for ', |
|
| 81 | + 4 => array('Schema is set', 'Schema is not set for ', |
|
| 82 | 82 | Url::fromPath('trapdirector/settings/createschema')), |
| 83 | - 5 => array('Schema is up to date','Schema is outdated :', |
|
| 83 | + 5 => array('Schema is up to date', 'Schema is outdated :', |
|
| 84 | 84 | Url::fromPath('trapdirector/settings/updateschema')), |
| 85 | 85 | ); |
| 86 | 86 | |
| 87 | 87 | try { |
| 88 | 88 | $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
| 89 | - $dberror=array(0,''); |
|
| 89 | + $dberror=array(0, ''); |
|
| 90 | 90 | } catch (DBException $e) { |
| 91 | - $dberror = $e->getArray(); |
|
| 91 | + $dberror=$e->getArray(); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | $this->view->db_error=$dberror[0]; |
@@ -96,13 +96,13 @@ discard block |
||
| 96 | 96 | { |
| 97 | 97 | case 2: |
| 98 | 98 | case 4: |
| 99 | - $db_message[$dberror[0]][1] .= $dberror[1]; |
|
| 99 | + $db_message[$dberror[0]][1].=$dberror[1]; |
|
| 100 | 100 | break; |
| 101 | 101 | case 3: |
| 102 | - $db_message[$dberror[0]][1] .= $dberror[1] . ', Message : ' . $dberror[2]; |
|
| 102 | + $db_message[$dberror[0]][1].=$dberror[1].', Message : '.$dberror[2]; |
|
| 103 | 103 | break; |
| 104 | 104 | case 5: |
| 105 | - $db_message[$dberror[0]][1] .= ' version '. $dberror[1] . ', version needed : ' .$dberror[2]; |
|
| 105 | + $db_message[$dberror[0]][1].=' version '.$dberror[1].', version needed : '.$dberror[2]; |
|
| 106 | 106 | break; |
| 107 | 107 | case 0: |
| 108 | 108 | case 1: |
@@ -114,13 +114,13 @@ discard block |
||
| 114 | 114 | |
| 115 | 115 | try { |
| 116 | 116 | $this->getUIDatabase()->testGetIdoDb(); // Get DB in test mode |
| 117 | - $dberror=array(0,''); |
|
| 117 | + $dberror=array(0, ''); |
|
| 118 | 118 | } catch (DBException $e) { |
| 119 | - $dberror = $e->getArray(); |
|
| 119 | + $dberror=$e->getArray(); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | $this->view->ido_db_error=$dberror[0]; |
| 123 | - $this->view->ido_message='IDO Database : ' . $dberror[1]; |
|
| 123 | + $this->view->ido_message='IDO Database : '.$dberror[1]; |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** |
@@ -132,13 +132,13 @@ discard block |
||
| 132 | 132 | { |
| 133 | 133 | if ($this->Config()->get('config', 'icingaAPI_host') != '') |
| 134 | 134 | { |
| 135 | - $apitest=new Icinga2Api($this->Config()->get('config', 'icingaAPI_host'),$this->Config()->get('config', 'icingaAPI_port')); |
|
| 135 | + $apitest=new Icinga2Api($this->Config()->get('config', 'icingaAPI_host'), $this->Config()->get('config', 'icingaAPI_port')); |
|
| 136 | 136 | $apitest->setCredentials($this->Config()->get('config', 'icingaAPI_user'), $this->Config()->get('config', 'icingaAPI_password')); |
| 137 | 137 | try { |
| 138 | - list($this->view->apimessageError,$this->view->apimessage)=$apitest->test($this->getModuleConfig()::getapiUserPermissions()); |
|
| 138 | + list($this->view->apimessageError, $this->view->apimessage)=$apitest->test($this->getModuleConfig()::getapiUserPermissions()); |
|
| 139 | 139 | //$this->view->apimessageError=false; |
| 140 | 140 | } catch (RuntimeException $e) { |
| 141 | - $this->view->apimessage='API config : ' . $e->getMessage(); |
|
| 141 | + $this->view->apimessage='API config : '.$e->getMessage(); |
|
| 142 | 142 | $this->view->apimessageError=true; |
| 143 | 143 | } |
| 144 | 144 | } |
@@ -163,10 +163,10 @@ discard block |
||
| 163 | 163 | { |
| 164 | 164 | $output=array(); |
| 165 | 165 | |
| 166 | - exec('cat ' . $this->module->getBaseDir() .'/bin/trap_in.php | grep "\$icingaweb2Etc=" ',$output); |
|
| 166 | + exec('cat '.$this->module->getBaseDir().'/bin/trap_in.php | grep "\$icingaweb2Etc=" ', $output); |
|
| 167 | 167 | |
| 168 | 168 | |
| 169 | - if (! isset($output[0]) || ! preg_match('#"'. $icingaweb2_etc .'"#',$output[0])) |
|
| 169 | + if (!isset($output[0]) || !preg_match('#"'.$icingaweb2_etc.'"#', $output[0])) |
|
| 170 | 170 | { |
| 171 | 171 | $this->view->icingaEtcWarn=1; |
| 172 | 172 | $this->view->icingaweb2_etc=$icingaweb2_etc; |
@@ -182,12 +182,12 @@ discard block |
||
| 182 | 182 | */ |
| 183 | 183 | private function get_db_list($allowed) |
| 184 | 184 | { |
| 185 | - $resources = array(); |
|
| 185 | + $resources=array(); |
|
| 186 | 186 | foreach (ResourceFactory::getResourceConfigs() as $name => $resource) |
| 187 | 187 | { |
| 188 | 188 | if ($resource->get('type') === 'db' && in_array($resource->get('db'), $allowed)) |
| 189 | 189 | { |
| 190 | - $resources[$name] = $name; |
|
| 190 | + $resources[$name]=$name; |
|
| 191 | 191 | } |
| 192 | 192 | } |
| 193 | 193 | return $resources; |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | // But check read permission |
| 215 | 215 | $this->checkReadPermission(); |
| 216 | 216 | |
| 217 | - $this->view->tabs = $this->Module()->getConfigTabs()->activate('config'); |
|
| 217 | + $this->view->tabs=$this->Module()->getConfigTabs()->activate('config'); |
|
| 218 | 218 | |
| 219 | 219 | // Get message : sent on configuration problems detected by controllers |
| 220 | 220 | $this->get_param(); |
@@ -229,32 +229,32 @@ discard block |
||
| 229 | 229 | $this->check_api(); |
| 230 | 230 | |
| 231 | 231 | //*********** Test snmptrapd alive and options |
| 232 | - list ($this->view->snmptrapdError, $this->view->snmptrapdMessage) = $this->checkSnmpTrapd(); |
|
| 232 | + list ($this->view->snmptrapdError, $this->view->snmptrapdMessage)=$this->checkSnmpTrapd(); |
|
| 233 | 233 | |
| 234 | 234 | // List DB in $ressources |
| 235 | - $resources = $this->get_db_list(array('mysql', 'pgsql')); |
|
| 235 | + $resources=$this->get_db_list(array('mysql', 'pgsql')); |
|
| 236 | 236 | |
| 237 | 237 | // Check standard Icingaweb2 path |
| 238 | 238 | $this->check_icingaweb_path(); |
| 239 | 239 | |
| 240 | 240 | // Setup path for mini documentation |
| 241 | - $this->view->traps_in_config= PHP_BINARY . ' ' . $this->Module()->getBaseDir() . '/bin/trap_in.php'; |
|
| 241 | + $this->view->traps_in_config=PHP_BINARY.' '.$this->Module()->getBaseDir().'/bin/trap_in.php'; |
|
| 242 | 242 | |
| 243 | - $this->view->installer= $this->Module()->getBaseDir() . '/bin/installer.sh ' |
|
| 243 | + $this->view->installer=$this->Module()->getBaseDir().'/bin/installer.sh ' |
|
| 244 | 244 | . ' -c all ' |
| 245 | - . ' -d ' . $this->Module()->getBaseDir() |
|
| 246 | - . ' -p ' . PHP_BINARY |
|
| 247 | - . ' -a ' . exec('whoami') |
|
| 248 | - . ' -w ' . Icinga::app()->getConfigDir(); |
|
| 245 | + . ' -d '.$this->Module()->getBaseDir() |
|
| 246 | + . ' -p '.PHP_BINARY |
|
| 247 | + . ' -a '.exec('whoami') |
|
| 248 | + . ' -w '.Icinga::app()->getConfigDir(); |
|
| 249 | 249 | |
| 250 | 250 | // ******************* configuration form setup******************* |
| 251 | - $this->view->form = $form = new TrapsConfigForm(); |
|
| 251 | + $this->view->form=$form=new TrapsConfigForm(); |
|
| 252 | 252 | |
| 253 | 253 | // set default paths; |
| 254 | - $this->view->form->setPaths($this->Module()->getBaseDir(),Icinga::app()->getConfigDir()); |
|
| 254 | + $this->view->form->setPaths($this->Module()->getBaseDir(), Icinga::app()->getConfigDir()); |
|
| 255 | 255 | |
| 256 | 256 | // set default ido database |
| 257 | - $this->view->form->setDefaultIDODB($this->Config()->module('monitoring','backends')->get('icinga','resource')); |
|
| 257 | + $this->view->form->setDefaultIDODB($this->Config()->module('monitoring', 'backends')->get('icinga', 'resource')); |
|
| 258 | 258 | |
| 259 | 259 | // Make form handle request. |
| 260 | 260 | $form->setIniConfig($this->Config()) |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | public function createschemaAction() |
| 267 | 267 | { |
| 268 | 268 | $this->checkModuleConfigPermission(); |
| 269 | - $this->getTabs()->add('create_schema',array( |
|
| 269 | + $this->getTabs()->add('create_schema', array( |
|
| 270 | 270 | 'active' => true, |
| 271 | 271 | 'label' => $this->translate('Create Schema'), |
| 272 | 272 | 'url' => Url::fromRequest() |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | // Get module database name |
| 288 | 288 | $dbName=$this->Config()->get('config', 'database'); |
| 289 | 289 | |
| 290 | - $dbResource = ResourceFactory::getResourceConfig($dbName); |
|
| 290 | + $dbResource=ResourceFactory::getResourceConfig($dbName); |
|
| 291 | 291 | $dbType=$dbResource->get('db'); |
| 292 | 292 | switch ($dbType) { |
| 293 | 293 | case 'mysql': |
@@ -302,28 +302,28 @@ discard block |
||
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | printf('<pre>'); |
| 305 | - require_once $this->Module()->getBaseDir() .'/bin/trap_class.php'; |
|
| 305 | + require_once $this->Module()->getBaseDir().'/bin/trap_class.php'; |
|
| 306 | 306 | |
| 307 | 307 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 308 | 308 | $debug_level=4; |
| 309 | - $Trap = new Trap($icingaweb2_etc); |
|
| 310 | - $Trap->setLogging($debug_level,'display'); |
|
| 309 | + $Trap=new Trap($icingaweb2_etc); |
|
| 310 | + $Trap->setLogging($debug_level, 'display'); |
|
| 311 | 311 | |
| 312 | 312 | $prefix=$this->Config()->get('config', 'database_prefix'); |
| 313 | 313 | // schema file : <path>/SQL/schema_v<verion>.<dbtype> |
| 314 | - $schema=$this->Module()->getBaseDir() . |
|
| 315 | - '/SQL/schema_v'. $this->getModuleConfig()->getDbCurVersion() . '.' . $dbFileExt; |
|
| 314 | + $schema=$this->Module()->getBaseDir(). |
|
| 315 | + '/SQL/schema_v'.$this->getModuleConfig()->getDbCurVersion().'.'.$dbFileExt; |
|
| 316 | 316 | |
| 317 | - $Trap->trapsDB->create_schema($schema,$prefix); |
|
| 317 | + $Trap->trapsDB->create_schema($schema, $prefix); |
|
| 318 | 318 | echo '</pre>'; |
| 319 | 319 | } |
| 320 | - echo '<br><br>Return to <a href="' . Url::fromPath('trapdirector/settings') .'" class="link-button icon-wrench"> settings page </a>'; |
|
| 320 | + echo '<br><br>Return to <a href="'.Url::fromPath('trapdirector/settings').'" class="link-button icon-wrench"> settings page </a>'; |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | public function updateschemaAction() |
| 324 | 324 | { |
| 325 | 325 | $this->checkModuleConfigPermission(); |
| 326 | - $this->getTabs()->add('get',array( |
|
| 326 | + $this->getTabs()->add('get', array( |
|
| 327 | 327 | 'active' => true, |
| 328 | 328 | 'label' => $this->translate('Update Schema'), |
| 329 | 329 | 'url' => Url::fromRequest() |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | $dberror=$e->getArray(); |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | - echo 'Return to <a href="' . Url::fromPath('trapdirector/settings') .'" class="link-button icon-wrench"> settings page </a><br><br>'; |
|
| 344 | + echo 'Return to <a href="'.Url::fromPath('trapdirector/settings').'" class="link-button icon-wrench"> settings page </a><br><br>'; |
|
| 345 | 345 | |
| 346 | 346 | if ($dberror[0] != 5) |
| 347 | 347 | { |
@@ -349,40 +349,40 @@ discard block |
||
| 349 | 349 | return; |
| 350 | 350 | } |
| 351 | 351 | // setup |
| 352 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 352 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
| 353 | 353 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 354 | 354 | $debug_level=4; |
| 355 | - $Trap = new Trap($icingaweb2_etc); |
|
| 355 | + $Trap=new Trap($icingaweb2_etc); |
|
| 356 | 356 | |
| 357 | 357 | |
| 358 | 358 | $prefix=$this->Config()->get('config', 'database_prefix'); |
| 359 | - $updateSchema=$this->Module()->getBaseDir() . '/SQL/'; |
|
| 359 | + $updateSchema=$this->Module()->getBaseDir().'/SQL/'; |
|
| 360 | 360 | |
| 361 | 361 | $target_version=$dberror[2]; |
| 362 | 362 | |
| 363 | 363 | if ($this->params->get('msgok') == null) { |
| 364 | 364 | // Check for messages and display if any |
| 365 | 365 | echo "Upgrade databse is going to start.<br>Don't forget to backup your database before update<br>"; |
| 366 | - $Trap->setLogging(2,'syslog'); |
|
| 367 | - $message = $Trap->trapsDB->update_schema($updateSchema,$target_version,$prefix,true); |
|
| 366 | + $Trap->setLogging(2, 'syslog'); |
|
| 367 | + $message=$Trap->trapsDB->update_schema($updateSchema, $target_version, $prefix, true); |
|
| 368 | 368 | if ($message != '') |
| 369 | 369 | { |
| 370 | 370 | echo 'Note :<br><pre>'; |
| 371 | 371 | echo $message; |
| 372 | 372 | echo '</pre>'; |
| 373 | 373 | echo '<br>'; |
| 374 | - echo '<a class="link-button" style="font-size:large;font-weight:bold" href="' . Url::fromPath('trapdirector/settings/updateschema') .'?msgok=1">Click here to update</a>'; |
|
| 374 | + echo '<a class="link-button" style="font-size:large;font-weight:bold" href="'.Url::fromPath('trapdirector/settings/updateschema').'?msgok=1">Click here to update</a>'; |
|
| 375 | 375 | echo '<br>'; |
| 376 | 376 | return; |
| 377 | 377 | } |
| 378 | 378 | } |
| 379 | 379 | |
| 380 | - $Trap->setLogging($debug_level,'display'); |
|
| 380 | + $Trap->setLogging($debug_level, 'display'); |
|
| 381 | 381 | |
| 382 | - echo 'Updating schema to '. $target_version . ': <br>'; |
|
| 382 | + echo 'Updating schema to '.$target_version.': <br>'; |
|
| 383 | 383 | echo '<pre>'; |
| 384 | 384 | |
| 385 | - $Trap->trapsDB->update_schema($updateSchema,$target_version,$prefix); |
|
| 385 | + $Trap->trapsDB->update_schema($updateSchema, $target_version, $prefix); |
|
| 386 | 386 | echo '</pre>'; |
| 387 | 387 | } |
| 388 | 388 | |
@@ -390,26 +390,26 @@ discard block |
||
| 390 | 390 | { |
| 391 | 391 | $psOutput=array(); |
| 392 | 392 | // First check is someone is listening to port 162. As not root, we can't have pid... |
| 393 | - exec('netstat -an |grep -E "udp.*:162"',$psOutput); |
|
| 393 | + exec('netstat -an |grep -E "udp.*:162"', $psOutput); |
|
| 394 | 394 | if (count($psOutput) == 0) |
| 395 | 395 | { |
| 396 | - return array(1,'Port UDP/162 is not open : snmptrapd must not be started'); |
|
| 396 | + return array(1, 'Port UDP/162 is not open : snmptrapd must not be started'); |
|
| 397 | 397 | } |
| 398 | 398 | $psOutput=array(); |
| 399 | - exec('ps fax |grep snmptrapd |grep -v grep',$psOutput); |
|
| 399 | + exec('ps fax |grep snmptrapd |grep -v grep', $psOutput); |
|
| 400 | 400 | if (count($psOutput) == 0) |
| 401 | 401 | { |
| 402 | - return array(1,"UDP/162 : OK, but no snmptrapd process (?)"); |
|
| 402 | + return array(1, "UDP/162 : OK, but no snmptrapd process (?)"); |
|
| 403 | 403 | } |
| 404 | 404 | // Assume there is only one line... TODO : see if there is a better way to do this |
| 405 | - $line = preg_replace('/^.*snmptrapd /','',$psOutput[0]); |
|
| 406 | - if (!preg_match('/-n/',$line)) |
|
| 407 | - return array(1,'snmptrapd has no -n option : '.$line); |
|
| 408 | - if (!preg_match('/-O[^ ]*n/',$line)) |
|
| 409 | - return array(1,'snmptrapd has no -On option : '.$line); |
|
| 410 | - if (!preg_match('/-O[^ ]*e/',$line)) |
|
| 411 | - return array(1,'snmptrapd has no -Oe option : '.$line); |
|
| 405 | + $line=preg_replace('/^.*snmptrapd /', '', $psOutput[0]); |
|
| 406 | + if (!preg_match('/-n/', $line)) |
|
| 407 | + return array(1, 'snmptrapd has no -n option : '.$line); |
|
| 408 | + if (!preg_match('/-O[^ ]*n/', $line)) |
|
| 409 | + return array(1, 'snmptrapd has no -On option : '.$line); |
|
| 410 | + if (!preg_match('/-O[^ ]*e/', $line)) |
|
| 411 | + return array(1, 'snmptrapd has no -Oe option : '.$line); |
|
| 412 | 412 | |
| 413 | - return array(0,'snmptrapd listening to UDP/162, options : '.$line); |
|
| 413 | + return array(0, 'snmptrapd listening to UDP/162, options : '.$line); |
|
| 414 | 414 | } |
| 415 | 415 | } |
@@ -52,8 +52,7 @@ discard block |
||
| 52 | 52 | $this->Config()->saveIni(); |
| 53 | 53 | $this->view->configErrorDetected='Configuration is empty : you can run install script with parameters (see Automatic installation below)'; |
| 54 | 54 | //$emptyConfig=1; |
| 55 | - } |
|
| 56 | - catch (Exception $e) |
|
| 55 | + } catch (Exception $e) |
|
| 57 | 56 | { |
| 58 | 57 | $this->view->configErrorDetected=$e->getMessage(); |
| 59 | 58 | } |
@@ -141,8 +140,7 @@ discard block |
||
| 141 | 140 | $this->view->apimessage='API config : ' . $e->getMessage(); |
| 142 | 141 | $this->view->apimessageError=true; |
| 143 | 142 | } |
| 144 | - } |
|
| 145 | - else |
|
| 143 | + } else |
|
| 146 | 144 | { |
| 147 | 145 | $this->view->apimessage='API parameters not configured'; |
| 148 | 146 | $this->view->apimessageError=true; |
@@ -278,8 +276,7 @@ discard block |
||
| 278 | 276 | $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
| 279 | 277 | printf('Schema already exists'); |
| 280 | 278 | |
| 281 | - } |
|
| 282 | - catch (DBException $e) |
|
| 279 | + } catch (DBException $e) |
|
| 283 | 280 | { |
| 284 | 281 | |
| 285 | 282 | printf('Creating schema : <br>'); |
@@ -335,8 +332,7 @@ discard block |
||
| 335 | 332 | $this->getUIDatabase()->testGetDb(); // Get DB in test mode |
| 336 | 333 | echo 'Schema already exists and is up to date<br>'; |
| 337 | 334 | return; |
| 338 | - } |
|
| 339 | - catch (DBException $e) |
|
| 335 | + } catch (DBException $e) |
|
| 340 | 336 | { |
| 341 | 337 | $dberror=$e->getArray(); |
| 342 | 338 | } |
@@ -403,12 +399,15 @@ discard block |
||
| 403 | 399 | } |
| 404 | 400 | // Assume there is only one line... TODO : see if there is a better way to do this |
| 405 | 401 | $line = preg_replace('/^.*snmptrapd /','',$psOutput[0]); |
| 406 | - if (!preg_match('/-n/',$line)) |
|
| 407 | - return array(1,'snmptrapd has no -n option : '.$line); |
|
| 408 | - if (!preg_match('/-O[^ ]*n/',$line)) |
|
| 409 | - return array(1,'snmptrapd has no -On option : '.$line); |
|
| 410 | - if (!preg_match('/-O[^ ]*e/',$line)) |
|
| 411 | - return array(1,'snmptrapd has no -Oe option : '.$line); |
|
| 402 | + if (!preg_match('/-n/',$line)) { |
|
| 403 | + return array(1,'snmptrapd has no -n option : '.$line); |
|
| 404 | + } |
|
| 405 | + if (!preg_match('/-O[^ ]*n/',$line)) { |
|
| 406 | + return array(1,'snmptrapd has no -On option : '.$line); |
|
| 407 | + } |
|
| 408 | + if (!preg_match('/-O[^ ]*e/',$line)) { |
|
| 409 | + return array(1,'snmptrapd has no -Oe option : '.$line); |
|
| 410 | + } |
|
| 412 | 411 | |
| 413 | 412 | return array(0,'snmptrapd listening to UDP/162, options : '.$line); |
| 414 | 413 | } |
@@ -116,8 +116,7 @@ discard block |
||
| 116 | 116 | $this->trapController->redirectNow('trapdirector/settings?dberror=5'); |
| 117 | 117 | return false; |
| 118 | 118 | } |
| 119 | - } |
|
| 120 | - catch (Exception $e) |
|
| 119 | + } catch (Exception $e) |
|
| 121 | 120 | { |
| 122 | 121 | if ($test === true) |
| 123 | 122 | { |
@@ -142,8 +141,7 @@ discard block |
||
| 142 | 141 | try |
| 143 | 142 | { |
| 144 | 143 | $dbconn = IcingaDbConnection::fromResourceName($DBname); |
| 145 | - } |
|
| 146 | - catch (Exception $e) |
|
| 144 | + } catch (Exception $e) |
|
| 147 | 145 | { |
| 148 | 146 | if ($test === true) |
| 149 | 147 | { |
@@ -157,8 +155,7 @@ discard block |
||
| 157 | 155 | { |
| 158 | 156 | $dbAdapter=$dbconn->getDbAdapter(); |
| 159 | 157 | |
| 160 | - } |
|
| 161 | - catch (Exception $e) |
|
| 158 | + } catch (Exception $e) |
|
| 162 | 159 | { |
| 163 | 160 | if ($test === true) |
| 164 | 161 | { |
@@ -185,7 +182,9 @@ discard block |
||
| 185 | 182 | */ |
| 186 | 183 | public function getDb() |
| 187 | 184 | { |
| 188 | - if ( $this->trapDB != null ) return $this->trapDB; |
|
| 185 | + if ( $this->trapDB != null ) { |
|
| 186 | + return $this->trapDB; |
|
| 187 | + } |
|
| 189 | 188 | |
| 190 | 189 | |
| 191 | 190 | $dbresource=$this->trapController->Config()->get('config', 'database'); |
@@ -213,7 +212,9 @@ discard block |
||
| 213 | 212 | */ |
| 214 | 213 | public function getDbConn() |
| 215 | 214 | { |
| 216 | - if ($this->getDb() == null) return null; |
|
| 215 | + if ($this->getDb() == null) { |
|
| 216 | + return null; |
|
| 217 | + } |
|
| 217 | 218 | return $this->getDb()->getConnection(); |
| 218 | 219 | } |
| 219 | 220 | |
@@ -243,7 +244,9 @@ discard block |
||
| 243 | 244 | */ |
| 244 | 245 | public function getIdoDb() |
| 245 | 246 | { |
| 246 | - if ( $this->idoDB != null ) return $this->idoDB; |
|
| 247 | + if ( $this->idoDB != null ) { |
|
| 248 | + return $this->idoDB; |
|
| 249 | + } |
|
| 247 | 250 | // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
| 248 | 251 | $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');; |
| 249 | 252 | |
@@ -256,8 +259,7 @@ discard block |
||
| 256 | 259 | try |
| 257 | 260 | { |
| 258 | 261 | $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
| 259 | - } |
|
| 260 | - catch (Exception $e) |
|
| 262 | + } catch (Exception $e) |
|
| 261 | 263 | { |
| 262 | 264 | $this->trapController->redirectNow('trapdirector/settings?idodberror=2'); |
| 263 | 265 | return null; |
@@ -274,7 +276,9 @@ discard block |
||
| 274 | 276 | */ |
| 275 | 277 | public function getIdoDbConn() |
| 276 | 278 | { |
| 277 | - if ($this->getIdoDb() == null) return null; |
|
| 279 | + if ($this->getIdoDb() == null) { |
|
| 280 | + return null; |
|
| 281 | + } |
|
| 278 | 282 | return $this->getIdoDb()->getConnection(); |
| 279 | 283 | } |
| 280 | 284 | |
@@ -296,8 +300,7 @@ discard block |
||
| 296 | 300 | try |
| 297 | 301 | { |
| 298 | 302 | $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
| 299 | - } |
|
| 300 | - catch (Exception $e) |
|
| 303 | + } catch (Exception $e) |
|
| 301 | 304 | { |
| 302 | 305 | throw new DBException( array(2,"Database $dbresource does not exists in IcingaWeb2") ); |
| 303 | 306 | } |
@@ -311,8 +314,7 @@ discard block |
||
| 311 | 314 | { |
| 312 | 315 | throw new DBException( array(4,"$dbresource does not look like an IDO database")); |
| 313 | 316 | } |
| 314 | - } |
|
| 315 | - catch (Exception $e) |
|
| 317 | + } catch (Exception $e) |
|
| 316 | 318 | { |
| 317 | 319 | throw new DBException( array(3,"Error connecting to $dbresource : " . $e->getMessage())); |
| 318 | 320 | } |
@@ -29,10 +29,10 @@ discard block |
||
| 29 | 29 | * @param int $code |
| 30 | 30 | * @param Exception $previous |
| 31 | 31 | */ |
| 32 | - public function __construct(array $retarray, string $message = null, int $code = 0, Exception $previous = null) |
|
| 32 | + public function __construct(array $retarray, string $message=null, int $code=0, Exception $previous=null) |
|
| 33 | 33 | { |
| 34 | - parent::__construct($message,$code,$previous); |
|
| 35 | - $this->returnArray = $retarray; |
|
| 34 | + parent::__construct($message, $code, $previous); |
|
| 35 | + $this->returnArray=$retarray; |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | class UIDatabase //extends TrapDBQuery |
| 58 | 58 | { |
| 59 | - use TrapDBQuery,IdoDBQuery; |
|
| 59 | + use TrapDBQuery, IdoDBQuery; |
|
| 60 | 60 | |
| 61 | 61 | /** @var TrapsController $trapController TrapController 'parent' class */ |
| 62 | 62 | protected $trapController=null; |
@@ -94,19 +94,19 @@ discard block |
||
| 94 | 94 | * @return bool true if OK, false if version < min version |
| 95 | 95 | * @throws Exception if error and test = true |
| 96 | 96 | */ |
| 97 | - protected function testDbVersion($dbAdapter,int $min,bool $test, string $DBname) |
|
| 97 | + protected function testDbVersion($dbAdapter, int $min, bool $test, string $DBname) |
|
| 98 | 98 | { |
| 99 | 99 | try |
| 100 | 100 | { |
| 101 | - $query = $dbAdapter->select() |
|
| 102 | - ->from($this->trapController->getModuleConfig()->getDbConfigTableName(),'value') |
|
| 101 | + $query=$dbAdapter->select() |
|
| 102 | + ->from($this->trapController->getModuleConfig()->getDbConfigTableName(), 'value') |
|
| 103 | 103 | ->where('name=\'db_version\''); |
| 104 | 104 | $version=$dbAdapter->fetchRow($query); |
| 105 | - if ( ($version == null) || ! property_exists($version,'value') ) |
|
| 105 | + if (($version == null) || !property_exists($version, 'value')) |
|
| 106 | 106 | { |
| 107 | 107 | if ($test === true) |
| 108 | 108 | { |
| 109 | - $this->testResult = array(4,$DBname); |
|
| 109 | + $this->testResult=array(4, $DBname); |
|
| 110 | 110 | return false; |
| 111 | 111 | } |
| 112 | 112 | $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | { |
| 117 | 117 | if ($test === true) |
| 118 | 118 | { |
| 119 | - $this->testResult = array(5,$version->value,$min); |
|
| 119 | + $this->testResult=array(5, $version->value, $min); |
|
| 120 | 120 | return false; |
| 121 | 121 | } |
| 122 | 122 | $this->trapController->redirectNow('trapdirector/settings?dberror=5'); |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | { |
| 128 | 128 | if ($test === true) |
| 129 | 129 | { |
| 130 | - $this->testResult = array(3,$DBname,$e->getMessage()); |
|
| 130 | + $this->testResult=array(3, $DBname, $e->getMessage()); |
|
| 131 | 131 | return false; |
| 132 | 132 | } |
| 133 | 133 | $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
@@ -143,17 +143,17 @@ discard block |
||
| 143 | 143 | * @throws DBException if test = true and error |
| 144 | 144 | * @return Selectable|null : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
| 145 | 145 | */ |
| 146 | - protected function getDbByName($DBname , $test = false , $test_version = true) |
|
| 146 | + protected function getDbByName($DBname, $test=false, $test_version=true) |
|
| 147 | 147 | { |
| 148 | 148 | try |
| 149 | 149 | { |
| 150 | - $dbconn = IcingaDbConnection::fromResourceName($DBname); |
|
| 150 | + $dbconn=IcingaDbConnection::fromResourceName($DBname); |
|
| 151 | 151 | } |
| 152 | 152 | catch (Exception $e) |
| 153 | 153 | { |
| 154 | 154 | if ($test === true) |
| 155 | 155 | { |
| 156 | - throw new DBException(array(2,$DBname)); |
|
| 156 | + throw new DBException(array(2, $DBname)); |
|
| 157 | 157 | } |
| 158 | 158 | $this->trapController->redirectNow('trapdirector/settings?dberror=2'); |
| 159 | 159 | return null; |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | { |
| 169 | 169 | if ($test === true) |
| 170 | 170 | { |
| 171 | - throw new DBException(array(3,$DBname,$e->getMessage())); |
|
| 171 | + throw new DBException(array(3, $DBname, $e->getMessage())); |
|
| 172 | 172 | } |
| 173 | 173 | $this->trapController->redirectNow('trapdirector/settings?dberror=3'); |
| 174 | 174 | return null; |
@@ -191,19 +191,19 @@ discard block |
||
| 191 | 191 | */ |
| 192 | 192 | public function getDb() |
| 193 | 193 | { |
| 194 | - if ( $this->trapDB != null ) return $this->trapDB; |
|
| 194 | + if ($this->trapDB != null) return $this->trapDB; |
|
| 195 | 195 | |
| 196 | 196 | |
| 197 | 197 | $dbresource=$this->trapController->Config()->get('config', 'database'); |
| 198 | 198 | |
| 199 | - if ( ! $dbresource ) |
|
| 199 | + if (!$dbresource) |
|
| 200 | 200 | { |
| 201 | 201 | $this->trapController->redirectNow('trapdirector/settings?dberror=1'); |
| 202 | 202 | return null; |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | try { |
| 206 | - $this->trapDB = $this->getDbByName($dbresource,false,true); |
|
| 206 | + $this->trapDB=$this->getDbByName($dbresource, false, true); |
|
| 207 | 207 | } catch (DBException $e) { |
| 208 | 208 | return null; // Should not happen as test = false |
| 209 | 209 | } |
@@ -233,12 +233,12 @@ discard block |
||
| 233 | 233 | { |
| 234 | 234 | $dbresource=$this->trapController->Config()->get('config', 'database'); |
| 235 | 235 | |
| 236 | - if ( ! $dbresource ) |
|
| 236 | + if (!$dbresource) |
|
| 237 | 237 | { |
| 238 | - throw new DBException(array(1,'')); |
|
| 238 | + throw new DBException(array(1, '')); |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - $this->trapDB = $this->getDbByName($dbresource,true,true); |
|
| 241 | + $this->trapDB=$this->getDbByName($dbresource, true, true); |
|
| 242 | 242 | return; |
| 243 | 243 | } |
| 244 | 244 | |
@@ -249,11 +249,11 @@ discard block |
||
| 249 | 249 | */ |
| 250 | 250 | public function getIdoDb() |
| 251 | 251 | { |
| 252 | - if ( $this->idoDB != null ) return $this->idoDB; |
|
| 252 | + if ($this->idoDB != null) return $this->idoDB; |
|
| 253 | 253 | // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
| 254 | - $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');; |
|
| 254 | + $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase'); ; |
|
| 255 | 255 | |
| 256 | - if ( ! $dbresource ) |
|
| 256 | + if (!$dbresource) |
|
| 257 | 257 | { |
| 258 | 258 | $this->trapController->redirectNow('trapdirector/settings?idodberror=1'); |
| 259 | 259 | return null; |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | |
| 262 | 262 | try |
| 263 | 263 | { |
| 264 | - $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
| 264 | + $dbconn=IcingaDbConnection::fromResourceName($dbresource); |
|
| 265 | 265 | } |
| 266 | 266 | catch (Exception $e) |
| 267 | 267 | { |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | return null; |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - $this->idoDB = $dbconn; |
|
| 272 | + $this->idoDB=$dbconn; |
|
| 273 | 273 | return $this->idoDB; |
| 274 | 274 | } |
| 275 | 275 | |
@@ -292,35 +292,35 @@ discard block |
||
| 292 | 292 | public function testGetIdoDb() |
| 293 | 293 | { |
| 294 | 294 | // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
| 295 | - $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');; |
|
| 295 | + $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase'); ; |
|
| 296 | 296 | |
| 297 | - if ( ! $dbresource ) |
|
| 297 | + if (!$dbresource) |
|
| 298 | 298 | { |
| 299 | - throw new DBException(array(1,'No database in config.ini')); |
|
| 299 | + throw new DBException(array(1, 'No database in config.ini')); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | try |
| 303 | 303 | { |
| 304 | - $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
| 304 | + $dbconn=IcingaDbConnection::fromResourceName($dbresource); |
|
| 305 | 305 | } |
| 306 | 306 | catch (Exception $e) |
| 307 | 307 | { |
| 308 | - throw new DBException( array(2,"Database $dbresource does not exists in IcingaWeb2") ); |
|
| 308 | + throw new DBException(array(2, "Database $dbresource does not exists in IcingaWeb2")); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | try |
| 312 | 312 | { |
| 313 | - $query = $dbconn->select() |
|
| 314 | - ->from('icinga_dbversion',array('version')); |
|
| 313 | + $query=$dbconn->select() |
|
| 314 | + ->from('icinga_dbversion', array('version')); |
|
| 315 | 315 | $version=$dbconn->fetchRow($query); |
| 316 | - if ( ($version == null) || ! property_exists($version,'version') ) |
|
| 316 | + if (($version == null) || !property_exists($version, 'version')) |
|
| 317 | 317 | { |
| 318 | - throw new DBException( array(4,"$dbresource does not look like an IDO database")); |
|
| 318 | + throw new DBException(array(4, "$dbresource does not look like an IDO database")); |
|
| 319 | 319 | } |
| 320 | 320 | } |
| 321 | 321 | catch (Exception $e) |
| 322 | 322 | { |
| 323 | - throw new DBException( array(3,"Error connecting to $dbresource : " . $e->getMessage())); |
|
| 323 | + throw new DBException(array(3, "Error connecting to $dbresource : ".$e->getMessage())); |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | return; |
@@ -19,30 +19,30 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | class DBException extends Exception |
| 21 | 21 | { |
| 22 | - /** @var array $returnArray */ |
|
| 23 | - private $returnArray; |
|
| 22 | + /** @var array $returnArray */ |
|
| 23 | + private $returnArray; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Buil DBException |
|
| 27 | - * @param array $retarray |
|
| 28 | - * @param string $message |
|
| 29 | - * @param int $code |
|
| 30 | - * @param Exception $previous |
|
| 31 | - */ |
|
| 32 | - public function __construct(array $retarray, string $message = null, int $code = 0, Exception $previous = null) |
|
| 33 | - { |
|
| 34 | - parent::__construct($message,$code,$previous); |
|
| 35 | - $this->returnArray = $retarray; |
|
| 36 | - } |
|
| 25 | + /** |
|
| 26 | + * Buil DBException |
|
| 27 | + * @param array $retarray |
|
| 28 | + * @param string $message |
|
| 29 | + * @param int $code |
|
| 30 | + * @param Exception $previous |
|
| 31 | + */ |
|
| 32 | + public function __construct(array $retarray, string $message = null, int $code = 0, Exception $previous = null) |
|
| 33 | + { |
|
| 34 | + parent::__construct($message,$code,$previous); |
|
| 35 | + $this->returnArray = $retarray; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Get exception array |
|
| 40 | - * @return array |
|
| 41 | - */ |
|
| 42 | - public function getArray() |
|
| 43 | - { |
|
| 44 | - return $this->returnArray; |
|
| 45 | - } |
|
| 38 | + /** |
|
| 39 | + * Get exception array |
|
| 40 | + * @return array |
|
| 41 | + */ |
|
| 42 | + public function getArray() |
|
| 43 | + { |
|
| 44 | + return $this->returnArray; |
|
| 45 | + } |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -56,278 +56,278 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | class UIDatabase //extends TrapDBQuery |
| 58 | 58 | { |
| 59 | - use TrapDBQuery,IdoDBQuery; |
|
| 59 | + use TrapDBQuery,IdoDBQuery; |
|
| 60 | 60 | |
| 61 | - /** @var TrapsController $trapController TrapController 'parent' class */ |
|
| 62 | - protected $trapController=null; |
|
| 61 | + /** @var TrapsController $trapController TrapController 'parent' class */ |
|
| 62 | + protected $trapController=null; |
|
| 63 | 63 | |
| 64 | - /** @var Selectable $trapDB Trap Database*/ |
|
| 65 | - protected $trapDB=null; |
|
| 64 | + /** @var Selectable $trapDB Trap Database*/ |
|
| 65 | + protected $trapDB=null; |
|
| 66 | 66 | |
| 67 | - /** @var Selectable $trapDB Icinga IDO database*/ |
|
| 68 | - protected $idoDB=null; |
|
| 67 | + /** @var Selectable $trapDB Icinga IDO database*/ |
|
| 68 | + protected $idoDB=null; |
|
| 69 | 69 | |
| 70 | - /** @var array $testResult */ |
|
| 71 | - protected $testResult; |
|
| 70 | + /** @var array $testResult */ |
|
| 71 | + protected $testResult; |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * |
|
| 75 | - * @param TrapsController $trapCtrl |
|
| 76 | - */ |
|
| 77 | - function __construct(TrapsController $trapCtrl) |
|
| 78 | - { |
|
| 79 | - $this->trapController=$trapCtrl; |
|
| 80 | - } |
|
| 73 | + /** |
|
| 74 | + * |
|
| 75 | + * @param TrapsController $trapCtrl |
|
| 76 | + */ |
|
| 77 | + function __construct(TrapsController $trapCtrl) |
|
| 78 | + { |
|
| 79 | + $this->trapController=$trapCtrl; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Get TrapsController instance |
|
| 84 | - * @return TrapsController |
|
| 85 | - */ |
|
| 86 | - protected function getTrapCtrl() |
|
| 87 | - { |
|
| 88 | - return $this->trapController; |
|
| 89 | - } |
|
| 82 | + /** |
|
| 83 | + * Get TrapsController instance |
|
| 84 | + * @return TrapsController |
|
| 85 | + */ |
|
| 86 | + protected function getTrapCtrl() |
|
| 87 | + { |
|
| 88 | + return $this->trapController; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Test if database version >= min database version |
|
| 93 | - * |
|
| 94 | - * @param \Zend_Db_Adapter_Abstract $dbConn |
|
| 95 | - * @param int $min Minimum version |
|
| 96 | - * @param bool $test Test mode |
|
| 97 | - * @param string $DBname Name of DB |
|
| 98 | - * @return bool true if OK, false if version < min version |
|
| 99 | - * @throws Exception if error and test = true |
|
| 100 | - */ |
|
| 101 | - protected function testDbVersion($dbAdapter,int $min,bool $test, string $DBname) |
|
| 102 | - { |
|
| 103 | - try |
|
| 104 | - { |
|
| 105 | - $query = $dbAdapter->select() |
|
| 106 | - ->from($this->trapController->getModuleConfig()->getDbConfigTableName(),'value') |
|
| 107 | - ->where('name=\'db_version\''); |
|
| 108 | - $version=$dbAdapter->fetchRow($query); |
|
| 109 | - if ( ($version == null) || ! property_exists($version,'value') ) |
|
| 110 | - { |
|
| 111 | - if ($test === true) |
|
| 112 | - { |
|
| 113 | - $this->testResult = array(4,$DBname); |
|
| 114 | - return false; |
|
| 115 | - } |
|
| 116 | - $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
|
| 117 | - return false; |
|
| 118 | - } |
|
| 119 | - if ($version->value < $min) |
|
| 120 | - { |
|
| 121 | - if ($test === true) |
|
| 122 | - { |
|
| 123 | - $this->testResult = array(5,$version->value,$min); |
|
| 124 | - return false; |
|
| 125 | - } |
|
| 126 | - $this->trapController->redirectNow('trapdirector/settings?dberror=5'); |
|
| 127 | - return false; |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - catch (Exception $e) |
|
| 131 | - { |
|
| 132 | - if ($test === true) |
|
| 133 | - { |
|
| 134 | - $this->testResult = array(3,$DBname,$e->getMessage()); |
|
| 135 | - return false; |
|
| 136 | - } |
|
| 137 | - $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
|
| 138 | - return false; |
|
| 139 | - } |
|
| 140 | - return true; |
|
| 141 | - } |
|
| 91 | + /** |
|
| 92 | + * Test if database version >= min database version |
|
| 93 | + * |
|
| 94 | + * @param \Zend_Db_Adapter_Abstract $dbConn |
|
| 95 | + * @param int $min Minimum version |
|
| 96 | + * @param bool $test Test mode |
|
| 97 | + * @param string $DBname Name of DB |
|
| 98 | + * @return bool true if OK, false if version < min version |
|
| 99 | + * @throws Exception if error and test = true |
|
| 100 | + */ |
|
| 101 | + protected function testDbVersion($dbAdapter,int $min,bool $test, string $DBname) |
|
| 102 | + { |
|
| 103 | + try |
|
| 104 | + { |
|
| 105 | + $query = $dbAdapter->select() |
|
| 106 | + ->from($this->trapController->getModuleConfig()->getDbConfigTableName(),'value') |
|
| 107 | + ->where('name=\'db_version\''); |
|
| 108 | + $version=$dbAdapter->fetchRow($query); |
|
| 109 | + if ( ($version == null) || ! property_exists($version,'value') ) |
|
| 110 | + { |
|
| 111 | + if ($test === true) |
|
| 112 | + { |
|
| 113 | + $this->testResult = array(4,$DBname); |
|
| 114 | + return false; |
|
| 115 | + } |
|
| 116 | + $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
|
| 117 | + return false; |
|
| 118 | + } |
|
| 119 | + if ($version->value < $min) |
|
| 120 | + { |
|
| 121 | + if ($test === true) |
|
| 122 | + { |
|
| 123 | + $this->testResult = array(5,$version->value,$min); |
|
| 124 | + return false; |
|
| 125 | + } |
|
| 126 | + $this->trapController->redirectNow('trapdirector/settings?dberror=5'); |
|
| 127 | + return false; |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + catch (Exception $e) |
|
| 131 | + { |
|
| 132 | + if ($test === true) |
|
| 133 | + { |
|
| 134 | + $this->testResult = array(3,$DBname,$e->getMessage()); |
|
| 135 | + return false; |
|
| 136 | + } |
|
| 137 | + $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
|
| 138 | + return false; |
|
| 139 | + } |
|
| 140 | + return true; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - /** Get Database connexion |
|
| 144 | - * @param $DBname string DB name in resource.ini_ge |
|
| 145 | - * @param $test bool if set to true, returns error code and not database |
|
| 146 | - * @param $test_version bool if set to flase, does not test database version of trapDB |
|
| 147 | - * @throws DBException if test = true and error |
|
| 148 | - * @return Selectable|null : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
|
| 149 | - */ |
|
| 150 | - protected function getDbByName($DBname , $test = false , $test_version = true) |
|
| 151 | - { |
|
| 152 | - try |
|
| 153 | - { |
|
| 154 | - $dbconn = IcingaDbConnection::fromResourceName($DBname); |
|
| 155 | - } |
|
| 156 | - catch (Exception $e) |
|
| 157 | - { |
|
| 158 | - if ($test === true) |
|
| 159 | - { |
|
| 160 | - throw new DBException(array(2,$DBname)); |
|
| 161 | - } |
|
| 162 | - $this->trapController->redirectNow('trapdirector/settings?dberror=2'); |
|
| 163 | - return null; |
|
| 164 | - } |
|
| 143 | + /** Get Database connexion |
|
| 144 | + * @param $DBname string DB name in resource.ini_ge |
|
| 145 | + * @param $test bool if set to true, returns error code and not database |
|
| 146 | + * @param $test_version bool if set to flase, does not test database version of trapDB |
|
| 147 | + * @throws DBException if test = true and error |
|
| 148 | + * @return Selectable|null : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
|
| 149 | + */ |
|
| 150 | + protected function getDbByName($DBname , $test = false , $test_version = true) |
|
| 151 | + { |
|
| 152 | + try |
|
| 153 | + { |
|
| 154 | + $dbconn = IcingaDbConnection::fromResourceName($DBname); |
|
| 155 | + } |
|
| 156 | + catch (Exception $e) |
|
| 157 | + { |
|
| 158 | + if ($test === true) |
|
| 159 | + { |
|
| 160 | + throw new DBException(array(2,$DBname)); |
|
| 161 | + } |
|
| 162 | + $this->trapController->redirectNow('trapdirector/settings?dberror=2'); |
|
| 163 | + return null; |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - try |
|
| 167 | - { |
|
| 168 | - $dbAdapter=$dbconn->getDbAdapter(); |
|
| 166 | + try |
|
| 167 | + { |
|
| 168 | + $dbAdapter=$dbconn->getDbAdapter(); |
|
| 169 | 169 | |
| 170 | - } |
|
| 171 | - catch (Exception $e) |
|
| 172 | - { |
|
| 173 | - if ($test === true) |
|
| 174 | - { |
|
| 175 | - throw new DBException(array(3,$DBname,$e->getMessage())); |
|
| 176 | - } |
|
| 177 | - $this->trapController->redirectNow('trapdirector/settings?dberror=3'); |
|
| 178 | - return null; |
|
| 179 | - } |
|
| 170 | + } |
|
| 171 | + catch (Exception $e) |
|
| 172 | + { |
|
| 173 | + if ($test === true) |
|
| 174 | + { |
|
| 175 | + throw new DBException(array(3,$DBname,$e->getMessage())); |
|
| 176 | + } |
|
| 177 | + $this->trapController->redirectNow('trapdirector/settings?dberror=3'); |
|
| 178 | + return null; |
|
| 179 | + } |
|
| 180 | 180 | |
| 181 | - if ($test_version == true) { |
|
| 182 | - $testRet=$this->testDbVersion($dbAdapter, $this->trapController->getModuleConfig()->getDbMinVersion(), $test, $DBname); |
|
| 183 | - if ($testRet !== true) |
|
| 184 | - { |
|
| 185 | - throw new DBException($this->testResult); |
|
| 186 | - } |
|
| 187 | - } |
|
| 181 | + if ($test_version == true) { |
|
| 182 | + $testRet=$this->testDbVersion($dbAdapter, $this->trapController->getModuleConfig()->getDbMinVersion(), $test, $DBname); |
|
| 183 | + if ($testRet !== true) |
|
| 184 | + { |
|
| 185 | + throw new DBException($this->testResult); |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | - return $dbconn; |
|
| 190 | - } |
|
| 189 | + return $dbconn; |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | - /** |
|
| 193 | - * Get Trap database |
|
| 194 | - * @return Selectable|null : returns DB connexion or null on error. |
|
| 195 | - */ |
|
| 196 | - public function getDb() |
|
| 197 | - { |
|
| 198 | - if ( $this->trapDB != null ) return $this->trapDB; |
|
| 192 | + /** |
|
| 193 | + * Get Trap database |
|
| 194 | + * @return Selectable|null : returns DB connexion or null on error. |
|
| 195 | + */ |
|
| 196 | + public function getDb() |
|
| 197 | + { |
|
| 198 | + if ( $this->trapDB != null ) return $this->trapDB; |
|
| 199 | 199 | |
| 200 | 200 | |
| 201 | - $dbresource=$this->trapController->Config()->get('config', 'database'); |
|
| 201 | + $dbresource=$this->trapController->Config()->get('config', 'database'); |
|
| 202 | 202 | |
| 203 | - if ( ! $dbresource ) |
|
| 204 | - { |
|
| 205 | - $this->trapController->redirectNow('trapdirector/settings?dberror=1'); |
|
| 206 | - return null; |
|
| 207 | - } |
|
| 203 | + if ( ! $dbresource ) |
|
| 204 | + { |
|
| 205 | + $this->trapController->redirectNow('trapdirector/settings?dberror=1'); |
|
| 206 | + return null; |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - try { |
|
| 210 | - $this->trapDB = $this->getDbByName($dbresource,false,true); |
|
| 211 | - } catch (DBException $e) { |
|
| 212 | - return null; // Should not happen as test = false |
|
| 213 | - } |
|
| 209 | + try { |
|
| 210 | + $this->trapDB = $this->getDbByName($dbresource,false,true); |
|
| 211 | + } catch (DBException $e) { |
|
| 212 | + return null; // Should not happen as test = false |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - //$this->trapDB->getConnection(); |
|
| 215 | + //$this->trapDB->getConnection(); |
|
| 216 | 216 | |
| 217 | - return $this->trapDB; |
|
| 218 | - } |
|
| 217 | + return $this->trapDB; |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | - /** |
|
| 221 | - * Get Zend adapter of DB. |
|
| 222 | - * @return \Zend_Db_Adapter_Abstract|null |
|
| 223 | - */ |
|
| 224 | - public function getDbConn() |
|
| 225 | - { |
|
| 226 | - if ($this->getDb() == null) return null; |
|
| 227 | - return $this->getDb()->getConnection(); |
|
| 228 | - } |
|
| 220 | + /** |
|
| 221 | + * Get Zend adapter of DB. |
|
| 222 | + * @return \Zend_Db_Adapter_Abstract|null |
|
| 223 | + */ |
|
| 224 | + public function getDbConn() |
|
| 225 | + { |
|
| 226 | + if ($this->getDb() == null) return null; |
|
| 227 | + return $this->getDb()->getConnection(); |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | - /** |
|
| 231 | - * Test Trap database |
|
| 232 | - * @param boolean $test |
|
| 233 | - * @throws DBException on error. |
|
| 234 | - * @return \Zend_Db_Adapter_Abstract|array|null : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
|
| 235 | - */ |
|
| 236 | - public function testGetDb() |
|
| 237 | - { |
|
| 238 | - $dbresource=$this->trapController->Config()->get('config', 'database'); |
|
| 230 | + /** |
|
| 231 | + * Test Trap database |
|
| 232 | + * @param boolean $test |
|
| 233 | + * @throws DBException on error. |
|
| 234 | + * @return \Zend_Db_Adapter_Abstract|array|null : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
|
| 235 | + */ |
|
| 236 | + public function testGetDb() |
|
| 237 | + { |
|
| 238 | + $dbresource=$this->trapController->Config()->get('config', 'database'); |
|
| 239 | 239 | |
| 240 | - if ( ! $dbresource ) |
|
| 241 | - { |
|
| 242 | - throw new DBException(array(1,'')); |
|
| 243 | - } |
|
| 240 | + if ( ! $dbresource ) |
|
| 241 | + { |
|
| 242 | + throw new DBException(array(1,'')); |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - $this->trapDB = $this->getDbByName($dbresource,true,true); |
|
| 246 | - return; |
|
| 247 | - } |
|
| 245 | + $this->trapDB = $this->getDbByName($dbresource,true,true); |
|
| 246 | + return; |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | 249 | |
| 250 | - /** |
|
| 251 | - * Get IDO Database |
|
| 252 | - * @return \Zend_Db_Adapter_Abstract|NULL returns DB connexion or null on error. |
|
| 253 | - */ |
|
| 254 | - public function getIdoDb() |
|
| 255 | - { |
|
| 256 | - if ( $this->idoDB != null ) return $this->idoDB; |
|
| 257 | - // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
|
| 258 | - $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');; |
|
| 250 | + /** |
|
| 251 | + * Get IDO Database |
|
| 252 | + * @return \Zend_Db_Adapter_Abstract|NULL returns DB connexion or null on error. |
|
| 253 | + */ |
|
| 254 | + public function getIdoDb() |
|
| 255 | + { |
|
| 256 | + if ( $this->idoDB != null ) return $this->idoDB; |
|
| 257 | + // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
|
| 258 | + $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');; |
|
| 259 | 259 | |
| 260 | - if ( ! $dbresource ) |
|
| 261 | - { |
|
| 262 | - $this->trapController->redirectNow('trapdirector/settings?idodberror=1'); |
|
| 263 | - return null; |
|
| 264 | - } |
|
| 260 | + if ( ! $dbresource ) |
|
| 261 | + { |
|
| 262 | + $this->trapController->redirectNow('trapdirector/settings?idodberror=1'); |
|
| 263 | + return null; |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | - try |
|
| 267 | - { |
|
| 268 | - $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
| 269 | - } |
|
| 270 | - catch (Exception $e) |
|
| 271 | - { |
|
| 272 | - $this->trapController->redirectNow('trapdirector/settings?idodberror=2'); |
|
| 273 | - return null; |
|
| 274 | - } |
|
| 266 | + try |
|
| 267 | + { |
|
| 268 | + $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
| 269 | + } |
|
| 270 | + catch (Exception $e) |
|
| 271 | + { |
|
| 272 | + $this->trapController->redirectNow('trapdirector/settings?idodberror=2'); |
|
| 273 | + return null; |
|
| 274 | + } |
|
| 275 | 275 | |
| 276 | - $this->idoDB = $dbconn; |
|
| 277 | - return $this->idoDB; |
|
| 278 | - } |
|
| 276 | + $this->idoDB = $dbconn; |
|
| 277 | + return $this->idoDB; |
|
| 278 | + } |
|
| 279 | 279 | |
| 280 | 280 | |
| 281 | - /** |
|
| 282 | - * Get Zend adapter of DB. |
|
| 283 | - * @return \Zend_Db_Adapter_Abstract|null |
|
| 284 | - */ |
|
| 285 | - public function getIdoDbConn() |
|
| 286 | - { |
|
| 287 | - if ($this->getIdoDb() == null) return null; |
|
| 288 | - return $this->getIdoDb()->getConnection(); |
|
| 289 | - } |
|
| 281 | + /** |
|
| 282 | + * Get Zend adapter of DB. |
|
| 283 | + * @return \Zend_Db_Adapter_Abstract|null |
|
| 284 | + */ |
|
| 285 | + public function getIdoDbConn() |
|
| 286 | + { |
|
| 287 | + if ($this->getIdoDb() == null) return null; |
|
| 288 | + return $this->getIdoDb()->getConnection(); |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | - /** |
|
| 292 | - * Get IDO Database |
|
| 293 | - * @param boolean $test |
|
| 294 | - * @throws DBException on error |
|
| 295 | - */ |
|
| 296 | - public function testGetIdoDb() |
|
| 297 | - { |
|
| 298 | - // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
|
| 299 | - $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');; |
|
| 291 | + /** |
|
| 292 | + * Get IDO Database |
|
| 293 | + * @param boolean $test |
|
| 294 | + * @throws DBException on error |
|
| 295 | + */ |
|
| 296 | + public function testGetIdoDb() |
|
| 297 | + { |
|
| 298 | + // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
|
| 299 | + $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');; |
|
| 300 | 300 | |
| 301 | - if ( ! $dbresource ) |
|
| 302 | - { |
|
| 303 | - throw new DBException(array(1,'No database in config.ini')); |
|
| 304 | - } |
|
| 301 | + if ( ! $dbresource ) |
|
| 302 | + { |
|
| 303 | + throw new DBException(array(1,'No database in config.ini')); |
|
| 304 | + } |
|
| 305 | 305 | |
| 306 | - try |
|
| 307 | - { |
|
| 308 | - $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
| 309 | - } |
|
| 310 | - catch (Exception $e) |
|
| 311 | - { |
|
| 312 | - throw new DBException( array(2,"Database $dbresource does not exists in IcingaWeb2") ); |
|
| 313 | - } |
|
| 306 | + try |
|
| 307 | + { |
|
| 308 | + $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
| 309 | + } |
|
| 310 | + catch (Exception $e) |
|
| 311 | + { |
|
| 312 | + throw new DBException( array(2,"Database $dbresource does not exists in IcingaWeb2") ); |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | - try |
|
| 316 | - { |
|
| 317 | - $query = $dbconn->select() |
|
| 318 | - ->from('icinga_dbversion',array('version')); |
|
| 319 | - $version=$dbconn->fetchRow($query); |
|
| 320 | - if ( ($version == null) || ! property_exists($version,'version') ) |
|
| 321 | - { |
|
| 322 | - throw new DBException( array(4,"$dbresource does not look like an IDO database")); |
|
| 323 | - } |
|
| 324 | - } |
|
| 325 | - catch (Exception $e) |
|
| 326 | - { |
|
| 327 | - throw new DBException( array(3,"Error connecting to $dbresource : " . $e->getMessage())); |
|
| 328 | - } |
|
| 315 | + try |
|
| 316 | + { |
|
| 317 | + $query = $dbconn->select() |
|
| 318 | + ->from('icinga_dbversion',array('version')); |
|
| 319 | + $version=$dbconn->fetchRow($query); |
|
| 320 | + if ( ($version == null) || ! property_exists($version,'version') ) |
|
| 321 | + { |
|
| 322 | + throw new DBException( array(4,"$dbresource does not look like an IDO database")); |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | + catch (Exception $e) |
|
| 326 | + { |
|
| 327 | + throw new DBException( array(3,"Error connecting to $dbresource : " . $e->getMessage())); |
|
| 328 | + } |
|
| 329 | 329 | |
| 330 | - return; |
|
| 331 | - } |
|
| 330 | + return; |
|
| 331 | + } |
|
| 332 | 332 | |
| 333 | 333 | } |
| 334 | 334 | \ No newline at end of file |
@@ -12,8 +12,8 @@ discard block |
||
| 12 | 12 | { |
| 13 | 13 | |
| 14 | 14 | /** Get host list with filter (IP or name) : host=<filter> |
| 15 | - * returns in JSON : status=>OK/NOK hosts=>array of hosts |
|
| 16 | - */ |
|
| 15 | + * returns in JSON : status=>OK/NOK hosts=>array of hosts |
|
| 16 | + */ |
|
| 17 | 17 | public function gethostsAction() |
| 18 | 18 | { |
| 19 | 19 | $postData=$this->getRequest()->getPost(); |
@@ -32,8 +32,8 @@ discard block |
||
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** Get hostgroup list with filter (name) : hostgroup=<hostFilter> |
| 35 | - * returns in JSON : status=>OK/NOK hosts=>array of hosts |
|
| 36 | - */ |
|
| 35 | + * returns in JSON : status=>OK/NOK hosts=>array of hosts |
|
| 36 | + */ |
|
| 37 | 37 | public function gethostgroupsAction() |
| 38 | 38 | { |
| 39 | 39 | $postData=$this->getRequest()->getPost(); |
@@ -52,11 +52,11 @@ discard block |
||
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | /** Get service list by host name ( host=<host> ) |
| 55 | - * returns in JSON : |
|
| 56 | - * status=>OK/No services found/More than one host matches |
|
| 57 | - * services=>array of services (name) |
|
| 58 | - * hostid = host object id or -1 if not found. |
|
| 59 | - */ |
|
| 55 | + * returns in JSON : |
|
| 56 | + * status=>OK/No services found/More than one host matches |
|
| 57 | + * services=>array of services (name) |
|
| 58 | + * hostid = host object id or -1 if not found. |
|
| 59 | + */ |
|
| 60 | 60 | public function getservicesAction() |
| 61 | 61 | { |
| 62 | 62 | $postData=$this->getRequest()->getPost(); |
@@ -98,11 +98,11 @@ discard block |
||
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | /** Get service list by host group ( name=<host> ) |
| 101 | - * returns in JSON : |
|
| 102 | - * status=>OK/No services found/More than one host matches |
|
| 103 | - * services=>array of services (name) |
|
| 104 | - * groupid = group object id or -1 if not found. |
|
| 105 | - */ |
|
| 101 | + * returns in JSON : |
|
| 102 | + * status=>OK/No services found/More than one host matches |
|
| 103 | + * services=>array of services (name) |
|
| 104 | + * groupid = group object id or -1 if not found. |
|
| 105 | + */ |
|
| 106 | 106 | public function gethostgroupservicesAction() |
| 107 | 107 | { |
| 108 | 108 | $postData=$this->getRequest()->getPost(); |
@@ -132,10 +132,10 @@ discard block |
||
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | /** Get traps from mib : entry : mib=<mib> |
| 135 | - * returns in JSON : |
|
| 136 | - * status=>OK/No mib/Error getting mibs |
|
| 137 | - * traps=>array of array( oid -> name) |
|
| 138 | - */ |
|
| 135 | + * returns in JSON : |
|
| 136 | + * status=>OK/No mib/Error getting mibs |
|
| 137 | + * traps=>array of array( oid -> name) |
|
| 138 | + */ |
|
| 139 | 139 | public function gettrapsAction() |
| 140 | 140 | { |
| 141 | 141 | $postData=$this->getRequest()->getPost(); |
@@ -155,10 +155,10 @@ discard block |
||
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** Get trap objects from mib : entry : trap=<oid> |
| 158 | - * returns in JSON : |
|
| 159 | - * status=>OK/no trap/not found |
|
| 160 | - * objects=>array of array( oid -> name, oid->mib) |
|
| 161 | - */ |
|
| 158 | + * returns in JSON : |
|
| 159 | + * status=>OK/no trap/not found |
|
| 160 | + * objects=>array of array( oid -> name, oid->mib) |
|
| 161 | + */ |
|
| 162 | 162 | public function gettrapobjectsAction() |
| 163 | 163 | { |
| 164 | 164 | $postData=$this->getRequest()->getPost(); |
@@ -178,8 +178,8 @@ discard block |
||
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** Get list of all loaded mibs : entry : none |
| 181 | - * return : array of strings. |
|
| 182 | - */ |
|
| 181 | + * return : array of strings. |
|
| 182 | + */ |
|
| 183 | 183 | public function getmiblistAction() |
| 184 | 184 | { |
| 185 | 185 | try |
@@ -194,10 +194,10 @@ discard block |
||
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | /** Get MIB::Name from OID : entry : oid |
| 197 | - * status=>OK/No oid/not found |
|
| 198 | - * mib=>string |
|
| 199 | - * name=>string |
|
| 200 | - */ |
|
| 197 | + * status=>OK/No oid/not found |
|
| 198 | + * mib=>string |
|
| 199 | + * name=>string |
|
| 200 | + */ |
|
| 201 | 201 | public function translateoidAction() |
| 202 | 202 | { |
| 203 | 203 | $postData=$this->getRequest()->getPost(); |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | 'name' => $object['name'], |
| 219 | 219 | 'type' => $object['type'], |
| 220 | 220 | 'type_enum' => $object['type_enum'], |
| 221 | - 'description' => $object['description'] |
|
| 221 | + 'description' => $object['description'] |
|
| 222 | 222 | ) |
| 223 | 223 | ); |
| 224 | 224 | } |
@@ -226,10 +226,10 @@ discard block |
||
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** Save or execute database purge of <n> days |
| 229 | - * days=>int |
|
| 230 | - * action=>save/execute |
|
| 231 | - * return : status=>OK/Message error |
|
| 232 | - */ |
|
| 229 | + * days=>int |
|
| 230 | + * action=>save/execute |
|
| 231 | + * return : status=>OK/Message error |
|
| 232 | + */ |
|
| 233 | 233 | public function dbmaintenanceAction() |
| 234 | 234 | { |
| 235 | 235 | |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | { |
| 244 | 244 | try |
| 245 | 245 | { |
| 246 | - $this->getUIDatabase()->setDBConfigValue('db_remove_days',$days); |
|
| 246 | + $this->getUIDatabase()->setDBConfigValue('db_remove_days',$days); |
|
| 247 | 247 | } |
| 248 | 248 | catch (Exception $e) |
| 249 | 249 | { |
@@ -275,11 +275,11 @@ discard block |
||
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** Save log output to db |
| 278 | - * destination=>log destination |
|
| 279 | - * file=>file name |
|
| 280 | - * level => int |
|
| 281 | - * return : status=>OK/Message error |
|
| 282 | - */ |
|
| 278 | + * destination=>log destination |
|
| 279 | + * file=>file name |
|
| 280 | + * level => int |
|
| 281 | + * return : status=>OK/Message error |
|
| 282 | + */ |
|
| 283 | 283 | public function logdestinationAction() |
| 284 | 284 | { |
| 285 | 285 | $postData=$this->getRequest()->getPost(); |
@@ -298,8 +298,8 @@ discard block |
||
| 298 | 298 | $fileHandler=@fopen($file,'w'); |
| 299 | 299 | if ($fileHandler == false) |
| 300 | 300 | { // File os note writabe / cannot create |
| 301 | - $this->_helper->json(array('status'=>'File not writable : '.$file)); |
|
| 302 | - return; |
|
| 301 | + $this->_helper->json(array('status'=>'File not writable : '.$file)); |
|
| 302 | + return; |
|
| 303 | 303 | } |
| 304 | 304 | } |
| 305 | 305 | else |
@@ -319,9 +319,9 @@ discard block |
||
| 319 | 319 | |
| 320 | 320 | try |
| 321 | 321 | { |
| 322 | - $this->getUIDatabase()->setDBConfigValue('log_destination',$destination); |
|
| 323 | - $this->getUIDatabase()->setDBConfigValue('log_file',$file); |
|
| 324 | - $this->getUIDatabase()->setDBConfigValue('log_level',$level); |
|
| 322 | + $this->getUIDatabase()->setDBConfigValue('log_destination',$destination); |
|
| 323 | + $this->getUIDatabase()->setDBConfigValue('log_file',$file); |
|
| 324 | + $this->getUIDatabase()->setDBConfigValue('log_level',$level); |
|
| 325 | 325 | } |
| 326 | 326 | catch (Exception $e) |
| 327 | 327 | { |
@@ -341,33 +341,33 @@ discard block |
||
| 341 | 341 | public function testruleAction() |
| 342 | 342 | { |
| 343 | 343 | |
| 344 | - $postData=$this->getRequest()->getPost(); |
|
| 344 | + $postData=$this->getRequest()->getPost(); |
|
| 345 | 345 | |
| 346 | - $rule = $this->checkPostVar($postData, 'rule', '.*'); |
|
| 346 | + $rule = $this->checkPostVar($postData, 'rule', '.*'); |
|
| 347 | 347 | |
| 348 | - $action = $this->checkPostVar($postData, 'action', 'evaluate'); |
|
| 348 | + $action = $this->checkPostVar($postData, 'action', 'evaluate'); |
|
| 349 | 349 | |
| 350 | - if ($action == 'evaluate') |
|
| 351 | - { |
|
| 352 | - try |
|
| 353 | - { |
|
| 354 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 355 | - $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
| 356 | - $trap = new Trap($icingaweb2_etc); |
|
| 357 | - // Cleanup spaces before eval |
|
| 358 | - $rule=$trap->ruleClass->eval_cleanup($rule); |
|
| 359 | - // Eval |
|
| 360 | - $item=0; |
|
| 361 | - $rule=$trap->ruleClass->evaluation($rule,$item); |
|
| 362 | - } |
|
| 363 | - catch (Exception $e) |
|
| 364 | - { |
|
| 365 | - $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() )); |
|
| 366 | - return; |
|
| 367 | - } |
|
| 368 | - $return=($rule==true)?'true':'false'; |
|
| 369 | - $this->_helper->json(array('status'=>'OK', 'message' => $return)); |
|
| 370 | - } |
|
| 350 | + if ($action == 'evaluate') |
|
| 351 | + { |
|
| 352 | + try |
|
| 353 | + { |
|
| 354 | + require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 355 | + $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
| 356 | + $trap = new Trap($icingaweb2_etc); |
|
| 357 | + // Cleanup spaces before eval |
|
| 358 | + $rule=$trap->ruleClass->eval_cleanup($rule); |
|
| 359 | + // Eval |
|
| 360 | + $item=0; |
|
| 361 | + $rule=$trap->ruleClass->evaluation($rule,$item); |
|
| 362 | + } |
|
| 363 | + catch (Exception $e) |
|
| 364 | + { |
|
| 365 | + $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() )); |
|
| 366 | + return; |
|
| 367 | + } |
|
| 368 | + $return=($rule==true)?'true':'false'; |
|
| 369 | + $this->_helper->json(array('status'=>'OK', 'message' => $return)); |
|
| 370 | + } |
|
| 371 | 371 | |
| 372 | 372 | } |
| 373 | 373 | |
@@ -378,35 +378,35 @@ discard block |
||
| 378 | 378 | */ |
| 379 | 379 | public function pluginAction() |
| 380 | 380 | { |
| 381 | - $postData=$this->getRequest()->getPost(); |
|
| 381 | + $postData=$this->getRequest()->getPost(); |
|
| 382 | 382 | |
| 383 | - $pluginName = $this->checkPostVar($postData, 'name', '.*'); |
|
| 383 | + $pluginName = $this->checkPostVar($postData, 'name', '.*'); |
|
| 384 | 384 | |
| 385 | - $action = $this->checkPostVar($postData, 'action', 'enable|disable'); |
|
| 385 | + $action = $this->checkPostVar($postData, 'action', 'enable|disable'); |
|
| 386 | 386 | |
| 387 | - try |
|
| 388 | - { |
|
| 389 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 390 | - $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
| 391 | - $trap = new Trap($icingaweb2_etc); |
|
| 392 | - // Enable plugin. |
|
| 393 | - $action=($action == 'enable') ? true : false; |
|
| 394 | - $retVal=$trap->pluginClass->enablePlugin($pluginName, $action); |
|
| 387 | + try |
|
| 388 | + { |
|
| 389 | + require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 390 | + $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
| 391 | + $trap = new Trap($icingaweb2_etc); |
|
| 392 | + // Enable plugin. |
|
| 393 | + $action=($action == 'enable') ? true : false; |
|
| 394 | + $retVal=$trap->pluginClass->enablePlugin($pluginName, $action); |
|
| 395 | 395 | |
| 396 | - } |
|
| 397 | - catch (Exception $e) |
|
| 398 | - { |
|
| 399 | - $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
| 400 | - return; |
|
| 401 | - } |
|
| 402 | - if ($retVal === true) |
|
| 403 | - { |
|
| 404 | - $this->_helper->json(array('status'=>'OK')); |
|
| 405 | - } |
|
| 406 | - else |
|
| 407 | - { |
|
| 408 | - $this->_helper->json(array('status'=>'Error, see logs')); |
|
| 409 | - } |
|
| 396 | + } |
|
| 397 | + catch (Exception $e) |
|
| 398 | + { |
|
| 399 | + $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
| 400 | + return; |
|
| 401 | + } |
|
| 402 | + if ($retVal === true) |
|
| 403 | + { |
|
| 404 | + $this->_helper->json(array('status'=>'OK')); |
|
| 405 | + } |
|
| 406 | + else |
|
| 407 | + { |
|
| 408 | + $this->_helper->json(array('status'=>'Error, see logs')); |
|
| 409 | + } |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** Function evaluation |
@@ -416,49 +416,49 @@ discard block |
||
| 416 | 416 | */ |
| 417 | 417 | public function functionAction() |
| 418 | 418 | { |
| 419 | - $postData=$this->getRequest()->getPost(); |
|
| 419 | + $postData=$this->getRequest()->getPost(); |
|
| 420 | 420 | |
| 421 | - $functionString = $this->checkPostVar($postData, 'function', '.*'); |
|
| 421 | + $functionString = $this->checkPostVar($postData, 'function', '.*'); |
|
| 422 | 422 | |
| 423 | - $this->checkPostVar($postData, 'action', 'evaluate'); |
|
| 423 | + $this->checkPostVar($postData, 'action', 'evaluate'); |
|
| 424 | 424 | |
| 425 | - // Only one action possible for now, no tests on action. |
|
| 426 | - try |
|
| 427 | - { |
|
| 428 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 429 | - $icingaweb2Etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
| 430 | - $trap = new Trap($icingaweb2Etc); |
|
| 431 | - // load all plugins in case tested function is not enabled. |
|
| 432 | - $trap->pluginClass->registerAllPlugins(false); |
|
| 433 | - // Clean all spaces |
|
| 434 | - $functionString = $trap->ruleClass->eval_cleanup($functionString); |
|
| 435 | - // Eval functions |
|
| 436 | - $result = $trap->pluginClass->evaluateFunctionString($functionString); |
|
| 437 | - } |
|
| 438 | - catch (Exception $e) |
|
| 439 | - { |
|
| 440 | - $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
| 441 | - return; |
|
| 442 | - } |
|
| 425 | + // Only one action possible for now, no tests on action. |
|
| 426 | + try |
|
| 427 | + { |
|
| 428 | + require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 429 | + $icingaweb2Etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
| 430 | + $trap = new Trap($icingaweb2Etc); |
|
| 431 | + // load all plugins in case tested function is not enabled. |
|
| 432 | + $trap->pluginClass->registerAllPlugins(false); |
|
| 433 | + // Clean all spaces |
|
| 434 | + $functionString = $trap->ruleClass->eval_cleanup($functionString); |
|
| 435 | + // Eval functions |
|
| 436 | + $result = $trap->pluginClass->evaluateFunctionString($functionString); |
|
| 437 | + } |
|
| 438 | + catch (Exception $e) |
|
| 439 | + { |
|
| 440 | + $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
| 441 | + return; |
|
| 442 | + } |
|
| 443 | 443 | |
| 444 | - $result = ($result === true)?'True':'False'; |
|
| 445 | - $this->_helper->json(array('status'=>'OK','message' => $result)); |
|
| 444 | + $result = ($result === true)?'True':'False'; |
|
| 445 | + $this->_helper->json(array('status'=>'OK','message' => $result)); |
|
| 446 | 446 | } |
| 447 | 447 | |
| 448 | - /************** Utilities **********************/ |
|
| 448 | + /************** Utilities **********************/ |
|
| 449 | 449 | |
| 450 | 450 | private function checkPostVar(array $postData,string $postVar, string $validRegexp) : string |
| 451 | 451 | { |
| 452 | - if (!isset ($postData[$postVar])) |
|
| 453 | - { |
|
| 454 | - $this->_helper->json(array('status'=>'No ' . $postVar)); |
|
| 455 | - return ''; |
|
| 456 | - } |
|
| 457 | - if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1) |
|
| 458 | - { |
|
| 459 | - $this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar])); |
|
| 460 | - return ''; |
|
| 461 | - } |
|
| 462 | - return $postData[$postVar]; |
|
| 452 | + if (!isset ($postData[$postVar])) |
|
| 453 | + { |
|
| 454 | + $this->_helper->json(array('status'=>'No ' . $postVar)); |
|
| 455 | + return ''; |
|
| 456 | + } |
|
| 457 | + if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1) |
|
| 458 | + { |
|
| 459 | + $this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar])); |
|
| 460 | + return ''; |
|
| 461 | + } |
|
| 462 | + return $postData[$postVar]; |
|
| 463 | 463 | } |
| 464 | 464 | } |
@@ -65,8 +65,7 @@ discard block |
||
| 65 | 65 | if (isset($postData['host'])) |
| 66 | 66 | { |
| 67 | 67 | $host=$postData['host']; |
| 68 | - } |
|
| 69 | - else |
|
| 68 | + } else |
|
| 70 | 69 | { |
| 71 | 70 | $this->_helper->json(array('status'=>'No Hosts','hostid' => -1)); |
| 72 | 71 | return; |
@@ -77,8 +76,7 @@ discard block |
||
| 77 | 76 | { |
| 78 | 77 | $this->_helper->json(array('status'=>'More than one host matches','hostid' => -1)); |
| 79 | 78 | return; |
| 80 | - } |
|
| 81 | - else if (count($hostArray) == 0) |
|
| 79 | + } else if (count($hostArray) == 0) |
|
| 82 | 80 | { |
| 83 | 81 | $this->_helper->json(array('status'=>'No host matches','hostid' => -1)); |
| 84 | 82 | return; |
@@ -114,8 +112,7 @@ discard block |
||
| 114 | 112 | { |
| 115 | 113 | $this->_helper->json(array('status'=>'More than one hostgroup matches','hostid' => -1)); |
| 116 | 114 | return; |
| 117 | - } |
|
| 118 | - else if (count($hostArray) == 0) |
|
| 115 | + } else if (count($hostArray) == 0) |
|
| 119 | 116 | { |
| 120 | 117 | $this->_helper->json(array('status'=>'No hostgroup matches','hostid' => -1)); |
| 121 | 118 | return; |
@@ -146,8 +143,7 @@ discard block |
||
| 146 | 143 | { |
| 147 | 144 | $traplist=$this->getMIB()->getTrapList($mib); |
| 148 | 145 | $retTraps=array('status'=>'OK','traps' => $traplist); |
| 149 | - } |
|
| 150 | - catch (Exception $e) |
|
| 146 | + } catch (Exception $e) |
|
| 151 | 147 | { |
| 152 | 148 | $retTraps=array('status' => 'Error getting mibs'); |
| 153 | 149 | } |
@@ -169,8 +165,7 @@ discard block |
||
| 169 | 165 | { |
| 170 | 166 | $objectlist=$this->getMIB()->getObjectList($trap); |
| 171 | 167 | $retObjects=array('status'=>'OK','objects' => $objectlist); |
| 172 | - } |
|
| 173 | - catch (Exception $e) |
|
| 168 | + } catch (Exception $e) |
|
| 174 | 169 | { |
| 175 | 170 | $retObjects=array('status' => 'not found'); |
| 176 | 171 | } |
@@ -185,8 +180,7 @@ discard block |
||
| 185 | 180 | try |
| 186 | 181 | { |
| 187 | 182 | $miblist=$this->getMIB()->getMIBList(); |
| 188 | - } |
|
| 189 | - catch (Exception $e) |
|
| 183 | + } catch (Exception $e) |
|
| 190 | 184 | { |
| 191 | 185 | $miblist=array('Error getting mibs'); |
| 192 | 186 | } |
@@ -209,8 +203,7 @@ discard block |
||
| 209 | 203 | { |
| 210 | 204 | $this->_helper->json(array('status'=>'Not found')); |
| 211 | 205 | return; |
| 212 | - } |
|
| 213 | - else |
|
| 206 | + } else |
|
| 214 | 207 | { |
| 215 | 208 | $this->_helper->json( |
| 216 | 209 | array('status'=>'OK', |
@@ -244,8 +237,7 @@ discard block |
||
| 244 | 237 | try |
| 245 | 238 | { |
| 246 | 239 | $this->getUIDatabase()->setDBConfigValue('db_remove_days',$days); |
| 247 | - } |
|
| 248 | - catch (Exception $e) |
|
| 240 | + } catch (Exception $e) |
|
| 249 | 241 | { |
| 250 | 242 | $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
| 251 | 243 | return; |
@@ -263,8 +255,7 @@ discard block |
||
| 263 | 255 | $trap = new Trap($icingaweb2_etc); |
| 264 | 256 | $trap->setLogging($debug_level,'syslog'); |
| 265 | 257 | $trap->eraseOldTraps($days); |
| 266 | - } |
|
| 267 | - catch (Exception $e) |
|
| 258 | + } catch (Exception $e) |
|
| 268 | 259 | { |
| 269 | 260 | $this->_helper->json(array('status'=>'execute error : '.$e->getMessage() )); |
| 270 | 261 | return; |
@@ -301,14 +292,12 @@ discard block |
||
| 301 | 292 | $this->_helper->json(array('status'=>'File not writable : '.$file)); |
| 302 | 293 | return; |
| 303 | 294 | } |
| 304 | - } |
|
| 305 | - else |
|
| 295 | + } else |
|
| 306 | 296 | { |
| 307 | 297 | if ($destination != 'file') |
| 308 | 298 | { |
| 309 | 299 | $file=null; |
| 310 | - } |
|
| 311 | - else |
|
| 300 | + } else |
|
| 312 | 301 | { |
| 313 | 302 | $this->_helper->json(array('status'=>'No file')); |
| 314 | 303 | return; |
@@ -322,8 +311,7 @@ discard block |
||
| 322 | 311 | $this->getUIDatabase()->setDBConfigValue('log_destination',$destination); |
| 323 | 312 | $this->getUIDatabase()->setDBConfigValue('log_file',$file); |
| 324 | 313 | $this->getUIDatabase()->setDBConfigValue('log_level',$level); |
| 325 | - } |
|
| 326 | - catch (Exception $e) |
|
| 314 | + } catch (Exception $e) |
|
| 327 | 315 | { |
| 328 | 316 | $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
| 329 | 317 | return; |
@@ -359,8 +347,7 @@ discard block |
||
| 359 | 347 | // Eval |
| 360 | 348 | $item=0; |
| 361 | 349 | $rule=$trap->ruleClass->evaluation($rule,$item); |
| 362 | - } |
|
| 363 | - catch (Exception $e) |
|
| 350 | + } catch (Exception $e) |
|
| 364 | 351 | { |
| 365 | 352 | $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() )); |
| 366 | 353 | return; |
@@ -393,8 +380,7 @@ discard block |
||
| 393 | 380 | $action=($action == 'enable') ? true : false; |
| 394 | 381 | $retVal=$trap->pluginClass->enablePlugin($pluginName, $action); |
| 395 | 382 | |
| 396 | - } |
|
| 397 | - catch (Exception $e) |
|
| 383 | + } catch (Exception $e) |
|
| 398 | 384 | { |
| 399 | 385 | $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
| 400 | 386 | return; |
@@ -402,8 +388,7 @@ discard block |
||
| 402 | 388 | if ($retVal === true) |
| 403 | 389 | { |
| 404 | 390 | $this->_helper->json(array('status'=>'OK')); |
| 405 | - } |
|
| 406 | - else |
|
| 391 | + } else |
|
| 407 | 392 | { |
| 408 | 393 | $this->_helper->json(array('status'=>'Error, see logs')); |
| 409 | 394 | } |
@@ -434,8 +419,7 @@ discard block |
||
| 434 | 419 | $functionString = $trap->ruleClass->eval_cleanup($functionString); |
| 435 | 420 | // Eval functions |
| 436 | 421 | $result = $trap->pluginClass->evaluateFunctionString($functionString); |
| 437 | - } |
|
| 438 | - catch (Exception $e) |
|
| 422 | + } catch (Exception $e) |
|
| 439 | 423 | { |
| 440 | 424 | $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
| 441 | 425 | return; |
@@ -18,14 +18,14 @@ discard block |
||
| 18 | 18 | { |
| 19 | 19 | $postData=$this->getRequest()->getPost(); |
| 20 | 20 | |
| 21 | - $hostFilter = $this->checkPostVar($postData, 'hostFilter', '.*'); |
|
| 21 | + $hostFilter=$this->checkPostVar($postData, 'hostFilter', '.*'); |
|
| 22 | 22 | |
| 23 | - $retHosts=array('status'=>'OK','hosts' => array()); |
|
| 23 | + $retHosts=array('status'=>'OK', 'hosts' => array()); |
|
| 24 | 24 | |
| 25 | 25 | $hosts=$this->getUIDatabase()->getHostByIP($hostFilter); |
| 26 | 26 | foreach ($hosts as $val) |
| 27 | 27 | { |
| 28 | - array_push($retHosts['hosts'],$val->name); |
|
| 28 | + array_push($retHosts['hosts'], $val->name); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | $this->_helper->json($retHosts); |
@@ -38,14 +38,14 @@ discard block |
||
| 38 | 38 | { |
| 39 | 39 | $postData=$this->getRequest()->getPost(); |
| 40 | 40 | |
| 41 | - $hostFilter = $this->checkPostVar($postData, 'hostFilter', '.*'); |
|
| 41 | + $hostFilter=$this->checkPostVar($postData, 'hostFilter', '.*'); |
|
| 42 | 42 | |
| 43 | - $retHosts=array('status'=>'OK','hosts' => array()); |
|
| 43 | + $retHosts=array('status'=>'OK', 'hosts' => array()); |
|
| 44 | 44 | |
| 45 | 45 | $hosts=$this->getUIDatabase()->getHostGroupByName($hostFilter); |
| 46 | 46 | foreach ($hosts as $val) |
| 47 | 47 | { |
| 48 | - array_push($retHosts['hosts'],$val->name); |
|
| 48 | + array_push($retHosts['hosts'], $val->name); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | $this->_helper->json($retHosts); |
@@ -68,31 +68,31 @@ discard block |
||
| 68 | 68 | } |
| 69 | 69 | else |
| 70 | 70 | { |
| 71 | - $this->_helper->json(array('status'=>'No Hosts','hostid' => -1)); |
|
| 71 | + $this->_helper->json(array('status'=>'No Hosts', 'hostid' => -1)); |
|
| 72 | 72 | return; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | $hostArray=$this->getUIDatabase()->getHostByName($host); |
| 76 | 76 | if (count($hostArray) > 1) |
| 77 | 77 | { |
| 78 | - $this->_helper->json(array('status'=>'More than one host matches','hostid' => -1)); |
|
| 78 | + $this->_helper->json(array('status'=>'More than one host matches', 'hostid' => -1)); |
|
| 79 | 79 | return; |
| 80 | 80 | } |
| 81 | 81 | else if (count($hostArray) == 0) |
| 82 | 82 | { |
| 83 | - $this->_helper->json(array('status'=>'No host matches','hostid' => -1)); |
|
| 83 | + $this->_helper->json(array('status'=>'No host matches', 'hostid' => -1)); |
|
| 84 | 84 | return; |
| 85 | 85 | } |
| 86 | 86 | $services=$this->getUIDatabase()->getServicesByHostid($hostArray[0]->id); |
| 87 | 87 | if (count($services) < 1) |
| 88 | 88 | { |
| 89 | - $this->_helper->json(array('status'=>'No services found for host','hostid' => $hostArray[0]->id)); |
|
| 89 | + $this->_helper->json(array('status'=>'No services found for host', 'hostid' => $hostArray[0]->id)); |
|
| 90 | 90 | return; |
| 91 | 91 | } |
| 92 | - $retServices=array('status'=>'OK','services' => array(),'hostid' => $hostArray[0]->id); |
|
| 92 | + $retServices=array('status'=>'OK', 'services' => array(), 'hostid' => $hostArray[0]->id); |
|
| 93 | 93 | foreach ($services as $val) |
| 94 | 94 | { |
| 95 | - array_push($retServices['services'],array($val->id , $val->name)); |
|
| 95 | + array_push($retServices['services'], array($val->id, $val->name)); |
|
| 96 | 96 | } |
| 97 | 97 | $this->_helper->json($retServices); |
| 98 | 98 | } |
@@ -107,26 +107,26 @@ discard block |
||
| 107 | 107 | { |
| 108 | 108 | $postData=$this->getRequest()->getPost(); |
| 109 | 109 | |
| 110 | - $host = $this->checkPostVar($postData, 'host', '.+'); |
|
| 110 | + $host=$this->checkPostVar($postData, 'host', '.+'); |
|
| 111 | 111 | |
| 112 | 112 | $hostArray=$this->getUIDatabase()->getHostGroupByName($host); |
| 113 | 113 | if (count($hostArray) > 1) |
| 114 | 114 | { |
| 115 | - $this->_helper->json(array('status'=>'More than one hostgroup matches','hostid' => -1)); |
|
| 115 | + $this->_helper->json(array('status'=>'More than one hostgroup matches', 'hostid' => -1)); |
|
| 116 | 116 | return; |
| 117 | 117 | } |
| 118 | 118 | else if (count($hostArray) == 0) |
| 119 | 119 | { |
| 120 | - $this->_helper->json(array('status'=>'No hostgroup matches','hostid' => -1)); |
|
| 120 | + $this->_helper->json(array('status'=>'No hostgroup matches', 'hostid' => -1)); |
|
| 121 | 121 | return; |
| 122 | 122 | } |
| 123 | 123 | $services=$this->getUIDatabase()->getServicesByHostGroupid($hostArray[0]->id); |
| 124 | 124 | if (count($services) < 1) |
| 125 | 125 | { |
| 126 | - $this->_helper->json(array('status'=>'No services found for hostgroup','hostid' => $hostArray[0]->id)); |
|
| 126 | + $this->_helper->json(array('status'=>'No services found for hostgroup', 'hostid' => $hostArray[0]->id)); |
|
| 127 | 127 | return; |
| 128 | 128 | } |
| 129 | - $retServices=array('status'=>'OK','services' => $services,'hostid' => $hostArray[0]->id); |
|
| 129 | + $retServices=array('status'=>'OK', 'services' => $services, 'hostid' => $hostArray[0]->id); |
|
| 130 | 130 | |
| 131 | 131 | $this->_helper->json($retServices); |
| 132 | 132 | } |
@@ -140,12 +140,12 @@ discard block |
||
| 140 | 140 | { |
| 141 | 141 | $postData=$this->getRequest()->getPost(); |
| 142 | 142 | |
| 143 | - $mib = $this->checkPostVar($postData, 'mib', '.*'); |
|
| 143 | + $mib=$this->checkPostVar($postData, 'mib', '.*'); |
|
| 144 | 144 | |
| 145 | 145 | try |
| 146 | 146 | { |
| 147 | 147 | $traplist=$this->getMIB()->getTrapList($mib); |
| 148 | - $retTraps=array('status'=>'OK','traps' => $traplist); |
|
| 148 | + $retTraps=array('status'=>'OK', 'traps' => $traplist); |
|
| 149 | 149 | } |
| 150 | 150 | catch (Exception $e) |
| 151 | 151 | { |
@@ -163,12 +163,12 @@ discard block |
||
| 163 | 163 | { |
| 164 | 164 | $postData=$this->getRequest()->getPost(); |
| 165 | 165 | |
| 166 | - $trap = $this->checkPostVar($postData, 'trap', '.*'); |
|
| 166 | + $trap=$this->checkPostVar($postData, 'trap', '.*'); |
|
| 167 | 167 | |
| 168 | 168 | try |
| 169 | 169 | { |
| 170 | 170 | $objectlist=$this->getMIB()->getObjectList($trap); |
| 171 | - $retObjects=array('status'=>'OK','objects' => $objectlist); |
|
| 171 | + $retObjects=array('status'=>'OK', 'objects' => $objectlist); |
|
| 172 | 172 | } |
| 173 | 173 | catch (Exception $e) |
| 174 | 174 | { |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | { |
| 203 | 203 | $postData=$this->getRequest()->getPost(); |
| 204 | 204 | |
| 205 | - $oid = $this->checkPostVar($postData, 'oid', '.*'); |
|
| 205 | + $oid=$this->checkPostVar($postData, 'oid', '.*'); |
|
| 206 | 206 | |
| 207 | 207 | // Try to get oid name from snmptranslate |
| 208 | 208 | if (($object=$this->getMIB()->translateOID($oid)) == null) |
@@ -235,20 +235,20 @@ discard block |
||
| 235 | 235 | |
| 236 | 236 | $postData=$this->getRequest()->getPost(); |
| 237 | 237 | |
| 238 | - $days = $this->checkPostVar($postData, 'days', '^[0-9]+$'); |
|
| 238 | + $days=$this->checkPostVar($postData, 'days', '^[0-9]+$'); |
|
| 239 | 239 | $days=intval($days); |
| 240 | 240 | |
| 241 | - $action = $this->checkPostVar($postData, 'action', 'save|execute'); |
|
| 241 | + $action=$this->checkPostVar($postData, 'action', 'save|execute'); |
|
| 242 | 242 | |
| 243 | 243 | if ($action == 'save') |
| 244 | 244 | { |
| 245 | 245 | try |
| 246 | 246 | { |
| 247 | - $this->getUIDatabase()->setDBConfigValue('db_remove_days',$days); |
|
| 247 | + $this->getUIDatabase()->setDBConfigValue('db_remove_days', $days); |
|
| 248 | 248 | } |
| 249 | 249 | catch (Exception $e) |
| 250 | 250 | { |
| 251 | - $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
|
| 251 | + $this->_helper->json(array('status'=>'Save error : '.$e->getMessage())); |
|
| 252 | 252 | return; |
| 253 | 253 | } |
| 254 | 254 | $this->_helper->json(array('status'=>'OK')); |
@@ -258,16 +258,16 @@ discard block |
||
| 258 | 258 | { |
| 259 | 259 | try |
| 260 | 260 | { |
| 261 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 261 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
| 262 | 262 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 263 | 263 | $debug_level=4; |
| 264 | - $trap = new Trap($icingaweb2_etc); |
|
| 265 | - $trap->setLogging($debug_level,'syslog'); |
|
| 264 | + $trap=new Trap($icingaweb2_etc); |
|
| 265 | + $trap->setLogging($debug_level, 'syslog'); |
|
| 266 | 266 | $trap->eraseOldTraps($days); |
| 267 | 267 | } |
| 268 | 268 | catch (Exception $e) |
| 269 | 269 | { |
| 270 | - $this->_helper->json(array('status'=>'execute error : '.$e->getMessage() )); |
|
| 270 | + $this->_helper->json(array('status'=>'execute error : '.$e->getMessage())); |
|
| 271 | 271 | return; |
| 272 | 272 | } |
| 273 | 273 | $this->_helper->json(array('status'=>'OK')); |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | { |
| 286 | 286 | $postData=$this->getRequest()->getPost(); |
| 287 | 287 | |
| 288 | - $destination = $this->checkPostVar($postData, 'destination', '.*'); |
|
| 288 | + $destination=$this->checkPostVar($postData, 'destination', '.*'); |
|
| 289 | 289 | $logDest=$this->getModuleConfig()->getLogDestinations(); |
| 290 | 290 | if (!isset($logDest[$destination])) |
| 291 | 291 | { |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | if (isset($postData['file'])) |
| 297 | 297 | { |
| 298 | 298 | $file=$postData['file']; |
| 299 | - $fileHandler=@fopen($file,'w'); |
|
| 299 | + $fileHandler=@fopen($file, 'w'); |
|
| 300 | 300 | if ($fileHandler == false) |
| 301 | 301 | { // File os note writabe / cannot create |
| 302 | 302 | $this->_helper->json(array('status'=>'File not writable : '.$file)); |
@@ -316,17 +316,17 @@ discard block |
||
| 316 | 316 | } |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - $level = $this->checkPostVar($postData, 'level', '[0-9]'); |
|
| 319 | + $level=$this->checkPostVar($postData, 'level', '[0-9]'); |
|
| 320 | 320 | |
| 321 | 321 | try |
| 322 | 322 | { |
| 323 | - $this->getUIDatabase()->setDBConfigValue('log_destination',$destination); |
|
| 324 | - $this->getUIDatabase()->setDBConfigValue('log_file',$file); |
|
| 325 | - $this->getUIDatabase()->setDBConfigValue('log_level',$level); |
|
| 323 | + $this->getUIDatabase()->setDBConfigValue('log_destination', $destination); |
|
| 324 | + $this->getUIDatabase()->setDBConfigValue('log_file', $file); |
|
| 325 | + $this->getUIDatabase()->setDBConfigValue('log_level', $level); |
|
| 326 | 326 | } |
| 327 | 327 | catch (Exception $e) |
| 328 | 328 | { |
| 329 | - $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
|
| 329 | + $this->_helper->json(array('status'=>'Save error : '.$e->getMessage())); |
|
| 330 | 330 | return; |
| 331 | 331 | } |
| 332 | 332 | $this->_helper->json(array('status'=>'OK')); |
@@ -344,29 +344,29 @@ discard block |
||
| 344 | 344 | |
| 345 | 345 | $postData=$this->getRequest()->getPost(); |
| 346 | 346 | |
| 347 | - $rule = $this->checkPostVar($postData, 'rule', '.*'); |
|
| 347 | + $rule=$this->checkPostVar($postData, 'rule', '.*'); |
|
| 348 | 348 | |
| 349 | - $action = $this->checkPostVar($postData, 'action', 'evaluate'); |
|
| 349 | + $action=$this->checkPostVar($postData, 'action', 'evaluate'); |
|
| 350 | 350 | |
| 351 | 351 | if ($action == 'evaluate') |
| 352 | 352 | { |
| 353 | 353 | try |
| 354 | 354 | { |
| 355 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 355 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
| 356 | 356 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 357 | - $trap = new Trap($icingaweb2_etc); |
|
| 357 | + $trap=new Trap($icingaweb2_etc); |
|
| 358 | 358 | // Cleanup spaces before eval |
| 359 | 359 | $rule=$trap->ruleClass->eval_cleanup($rule); |
| 360 | 360 | // Eval |
| 361 | 361 | $item=0; |
| 362 | - $rule=$trap->ruleClass->evaluation($rule,$item); |
|
| 362 | + $rule=$trap->ruleClass->evaluation($rule, $item); |
|
| 363 | 363 | } |
| 364 | 364 | catch (Exception $e) |
| 365 | 365 | { |
| 366 | - $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() )); |
|
| 366 | + $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage())); |
|
| 367 | 367 | return; |
| 368 | 368 | } |
| 369 | - $return=($rule==true)?'true':'false'; |
|
| 369 | + $return=($rule == true) ? 'true' : 'false'; |
|
| 370 | 370 | $this->_helper->json(array('status'=>'OK', 'message' => $return)); |
| 371 | 371 | } |
| 372 | 372 | |
@@ -381,15 +381,15 @@ discard block |
||
| 381 | 381 | { |
| 382 | 382 | $postData=$this->getRequest()->getPost(); |
| 383 | 383 | |
| 384 | - $pluginName = $this->checkPostVar($postData, 'name', '.*'); |
|
| 384 | + $pluginName=$this->checkPostVar($postData, 'name', '.*'); |
|
| 385 | 385 | |
| 386 | - $action = $this->checkPostVar($postData, 'action', 'enable|disable'); |
|
| 386 | + $action=$this->checkPostVar($postData, 'action', 'enable|disable'); |
|
| 387 | 387 | |
| 388 | 388 | try |
| 389 | 389 | { |
| 390 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 390 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
| 391 | 391 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 392 | - $trap = new Trap($icingaweb2_etc); |
|
| 392 | + $trap=new Trap($icingaweb2_etc); |
|
| 393 | 393 | // Enable plugin. |
| 394 | 394 | $action=($action == 'enable') ? true : false; |
| 395 | 395 | $retVal=$trap->pluginClass->enablePlugin($pluginName, $action); |
@@ -397,7 +397,7 @@ discard block |
||
| 397 | 397 | } |
| 398 | 398 | catch (Exception $e) |
| 399 | 399 | { |
| 400 | - $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
| 400 | + $this->_helper->json(array('status'=>'Action error : '.$e->getMessage())); |
|
| 401 | 401 | return; |
| 402 | 402 | } |
| 403 | 403 | if ($retVal === true) |
@@ -419,45 +419,45 @@ discard block |
||
| 419 | 419 | { |
| 420 | 420 | $postData=$this->getRequest()->getPost(); |
| 421 | 421 | |
| 422 | - $functionString = $this->checkPostVar($postData, 'function', '.*'); |
|
| 422 | + $functionString=$this->checkPostVar($postData, 'function', '.*'); |
|
| 423 | 423 | |
| 424 | 424 | $this->checkPostVar($postData, 'action', 'evaluate'); |
| 425 | 425 | |
| 426 | 426 | // Only one action possible for now, no tests on action. |
| 427 | 427 | try |
| 428 | 428 | { |
| 429 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 429 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
| 430 | 430 | $icingaweb2Etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 431 | - $trap = new Trap($icingaweb2Etc); |
|
| 431 | + $trap=new Trap($icingaweb2Etc); |
|
| 432 | 432 | // load all plugins in case tested function is not enabled. |
| 433 | 433 | $trap->pluginClass->registerAllPlugins(false); |
| 434 | 434 | // Clean all spaces |
| 435 | - $functionString = $trap->ruleClass->eval_cleanup($functionString); |
|
| 435 | + $functionString=$trap->ruleClass->eval_cleanup($functionString); |
|
| 436 | 436 | // Eval functions |
| 437 | - $result = $trap->pluginClass->evaluateFunctionString($functionString); |
|
| 437 | + $result=$trap->pluginClass->evaluateFunctionString($functionString); |
|
| 438 | 438 | } |
| 439 | 439 | catch (Exception $e) |
| 440 | 440 | { |
| 441 | - $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
| 441 | + $this->_helper->json(array('status'=>'Action error : '.$e->getMessage())); |
|
| 442 | 442 | return; |
| 443 | 443 | } |
| 444 | 444 | |
| 445 | - $result = ($result === true)?'True':'False'; |
|
| 446 | - $this->_helper->json(array('status'=>'OK','message' => $result)); |
|
| 445 | + $result=($result === true) ? 'True' : 'False'; |
|
| 446 | + $this->_helper->json(array('status'=>'OK', 'message' => $result)); |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | /************** Utilities **********************/ |
| 450 | 450 | |
| 451 | - private function checkPostVar(array $postData,string $postVar, string $validRegexp) : string |
|
| 451 | + private function checkPostVar(array $postData, string $postVar, string $validRegexp) : string |
|
| 452 | 452 | { |
| 453 | 453 | if (!isset ($postData[$postVar])) |
| 454 | 454 | { |
| 455 | - $this->_helper->json(array('status'=>'No ' . $postVar)); |
|
| 455 | + $this->_helper->json(array('status'=>'No '.$postVar)); |
|
| 456 | 456 | return ''; |
| 457 | 457 | } |
| 458 | 458 | if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1) |
| 459 | 459 | { |
| 460 | - $this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar])); |
|
| 460 | + $this->_helper->json(array('status'=>'Unknown '.$postVar.' value '.$postData[$postVar])); |
|
| 461 | 461 | return ''; |
| 462 | 462 | } |
| 463 | 463 | return $postData[$postVar]; |
@@ -26,7 +26,9 @@ discard block |
||
| 26 | 26 | // TODO Check for rule consistency |
| 27 | 27 | |
| 28 | 28 | $dbConn = $this->getDbConn(); |
| 29 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 29 | + if ($dbConn === null) { |
|
| 30 | + throw new \ErrorException('uncatched db error'); |
|
| 31 | + } |
|
| 30 | 32 | // Add last modified date = creation date and username |
| 31 | 33 | $params['created'] = new Zend_Db_Expr('NOW()'); |
| 32 | 34 | $params['modified'] = new Zend_Db_Expr('NOW()'); |
@@ -52,7 +54,9 @@ discard block |
||
| 52 | 54 | { |
| 53 | 55 | // TODO Check for rule consistency |
| 54 | 56 | $dbConn = $this->getDbConn(); |
| 55 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 57 | + if ($dbConn === null) { |
|
| 58 | + throw new \ErrorException('uncatched db error'); |
|
| 59 | + } |
|
| 56 | 60 | // Add last modified date = creation date and username |
| 57 | 61 | $params['modified'] = new Zend_Db_Expr('NOW()'); |
| 58 | 62 | $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername(); |
@@ -73,7 +77,9 @@ discard block |
||
| 73 | 77 | if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id'); } |
| 74 | 78 | |
| 75 | 79 | $dbConn = $this->getDbConn(); |
| 76 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 80 | + if ($dbConn === null) { |
|
| 81 | + throw new \ErrorException('uncatched db error'); |
|
| 82 | + } |
|
| 77 | 83 | |
| 78 | 84 | $query=$dbConn->delete( |
| 79 | 85 | $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
@@ -90,7 +96,9 @@ discard block |
||
| 90 | 96 | { |
| 91 | 97 | |
| 92 | 98 | $dbConn = $this->getDbConn(); |
| 93 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 99 | + if ($dbConn === null) { |
|
| 100 | + throw new \ErrorException('uncatched db error'); |
|
| 101 | + } |
|
| 94 | 102 | $condition=null; |
| 95 | 103 | if ($ipAddr != null) |
| 96 | 104 | { |
@@ -101,7 +109,9 @@ discard block |
||
| 101 | 109 | $condition=($condition===null)?'':$condition.' AND '; |
| 102 | 110 | $condition.="trap_oid='$oid'"; |
| 103 | 111 | } |
| 104 | - if($condition === null) return null; |
|
| 112 | + if($condition === null) { |
|
| 113 | + return null; |
|
| 114 | + } |
|
| 105 | 115 | $query=$dbConn->delete( |
| 106 | 116 | $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(), |
| 107 | 117 | $condition |
@@ -119,7 +129,9 @@ discard block |
||
| 119 | 129 | { |
| 120 | 130 | |
| 121 | 131 | $dbConn = $this->getDbConn(); |
| 122 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 132 | + if ($dbConn === null) { |
|
| 133 | + throw new \ErrorException('uncatched db error'); |
|
| 134 | + } |
|
| 123 | 135 | |
| 124 | 136 | $condition=null; |
| 125 | 137 | if ($ipAddr != null) |
@@ -131,7 +143,9 @@ discard block |
||
| 131 | 143 | $condition=($condition===null)?'':$condition.' AND '; |
| 132 | 144 | $condition.="trap_oid='$oid'"; |
| 133 | 145 | } |
| 134 | - if($condition === null) return 0; |
|
| 146 | + if($condition === null) { |
|
| 147 | + return 0; |
|
| 148 | + } |
|
| 135 | 149 | $query=$dbConn->select() |
| 136 | 150 | ->from( |
| 137 | 151 | $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(), |
@@ -148,7 +162,9 @@ discard block |
||
| 148 | 162 | { |
| 149 | 163 | |
| 150 | 164 | $dbConn = $this->getDbConn(); |
| 151 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 165 | + if ($dbConn === null) { |
|
| 166 | + throw new \ErrorException('uncatched db error'); |
|
| 167 | + } |
|
| 152 | 168 | |
| 153 | 169 | $query=$dbConn->select() |
| 154 | 170 | ->from( |
@@ -156,18 +172,28 @@ discard block |
||
| 156 | 172 | array('value'=>'value')) |
| 157 | 173 | ->where('name=?',$element); |
| 158 | 174 | $returnRow=$dbConn->fetchRow($query); |
| 159 | - if ($returnRow==null) // value does not exists |
|
| 175 | + if ($returnRow==null) { |
|
| 176 | + // value does not exists |
|
| 160 | 177 | { |
| 161 | 178 | $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults(); |
| 162 | - if ( ! isset($default[$element])) return null; // no default and not value |
|
| 179 | + } |
|
| 180 | + if ( ! isset($default[$element])) { |
|
| 181 | + return null; |
|
| 182 | + } |
|
| 183 | + // no default and not value |
|
| 163 | 184 | |
| 164 | 185 | $this->addDBConfigValue($element,$default[$element]); |
| 165 | 186 | return $default[$element]; |
| 166 | 187 | } |
| 167 | - if ($returnRow->value == null) // value id empty |
|
| 188 | + if ($returnRow->value == null) { |
|
| 189 | + // value id empty |
|
| 168 | 190 | { |
| 169 | 191 | $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults(); |
| 170 | - if ( ! isset($default[$element])) return null; // no default and not value |
|
| 192 | + } |
|
| 193 | + if ( ! isset($default[$element])) { |
|
| 194 | + return null; |
|
| 195 | + } |
|
| 196 | + // no default and not value |
|
| 171 | 197 | $this->setDBConfigValue($element,$default[$element]); |
| 172 | 198 | return $default[$element]; |
| 173 | 199 | } |
@@ -183,7 +209,9 @@ discard block |
||
| 183 | 209 | { |
| 184 | 210 | |
| 185 | 211 | $dbConn = $this->getDbConn(); |
| 186 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 212 | + if ($dbConn === null) { |
|
| 213 | + throw new \ErrorException('uncatched db error'); |
|
| 214 | + } |
|
| 187 | 215 | |
| 188 | 216 | $query=$dbConn->insert( |
| 189 | 217 | $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(), |
@@ -203,7 +231,9 @@ discard block |
||
| 203 | 231 | { |
| 204 | 232 | |
| 205 | 233 | $dbConn = $this->getDbConn(); |
| 206 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 234 | + if ($dbConn === null) { |
|
| 235 | + throw new \ErrorException('uncatched db error'); |
|
| 236 | + } |
|
| 207 | 237 | |
| 208 | 238 | $query=$dbConn->update( |
| 209 | 239 | $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(), |
@@ -19,207 +19,207 @@ |
||
| 19 | 19 | trait TrapDBQuery |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** @return TrapsController */ |
|
| 23 | - abstract protected function getTrapCtrl(); |
|
| 22 | + /** @return TrapsController */ |
|
| 23 | + abstract protected function getTrapCtrl(); |
|
| 24 | 24 | |
| 25 | - /** @return Zend_Db_Adapter_Abstract : returns DB connexion or null on error */ |
|
| 26 | - abstract public function getDbConn(); |
|
| 25 | + /** @return Zend_Db_Adapter_Abstract : returns DB connexion or null on error */ |
|
| 26 | + abstract public function getDbConn(); |
|
| 27 | 27 | |
| 28 | - /** Add handler rule in traps DB |
|
| 29 | - * @param array $params : array(<db item>=><value>) |
|
| 30 | - * @return int inserted id |
|
| 31 | - */ |
|
| 32 | - public function addHandlerRule($params) |
|
| 33 | - { |
|
| 34 | - // TODO Check for rule consistency |
|
| 28 | + /** Add handler rule in traps DB |
|
| 29 | + * @param array $params : array(<db item>=><value>) |
|
| 30 | + * @return int inserted id |
|
| 31 | + */ |
|
| 32 | + public function addHandlerRule($params) |
|
| 33 | + { |
|
| 34 | + // TODO Check for rule consistency |
|
| 35 | 35 | |
| 36 | - $dbConn = $this->getDbConn(); |
|
| 37 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 38 | - // Add last modified date = creation date and username |
|
| 39 | - $params['created'] = new Zend_Db_Expr('NOW()'); |
|
| 40 | - $params['modified'] = new Zend_Db_Expr('NOW()'); |
|
| 41 | - $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername(); |
|
| 36 | + $dbConn = $this->getDbConn(); |
|
| 37 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 38 | + // Add last modified date = creation date and username |
|
| 39 | + $params['created'] = new Zend_Db_Expr('NOW()'); |
|
| 40 | + $params['modified'] = new Zend_Db_Expr('NOW()'); |
|
| 41 | + $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername(); |
|
| 42 | 42 | |
| 43 | - $query=$dbConn->insert( |
|
| 44 | - $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
|
| 45 | - $params |
|
| 46 | - ); |
|
| 47 | - if($query==false) |
|
| 48 | - { |
|
| 49 | - return null; |
|
| 50 | - } |
|
| 51 | - return $dbConn->lastInsertId(); |
|
| 52 | - } |
|
| 43 | + $query=$dbConn->insert( |
|
| 44 | + $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
|
| 45 | + $params |
|
| 46 | + ); |
|
| 47 | + if($query==false) |
|
| 48 | + { |
|
| 49 | + return null; |
|
| 50 | + } |
|
| 51 | + return $dbConn->lastInsertId(); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** Update handler rule in traps DB |
|
| 55 | - * @param array $params : (<db item>=><value>) |
|
| 56 | - * @param integer $ruleID : rule id in db |
|
| 57 | - * @return array affected rows |
|
| 58 | - */ |
|
| 59 | - public function updateHandlerRule($params,$ruleID) |
|
| 60 | - { |
|
| 61 | - // TODO Check for rule consistency |
|
| 62 | - $dbConn = $this->getDbConn(); |
|
| 63 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 64 | - // Add last modified date = creation date and username |
|
| 65 | - $params['modified'] = new Zend_Db_Expr('NOW()'); |
|
| 66 | - $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername(); |
|
| 54 | + /** Update handler rule in traps DB |
|
| 55 | + * @param array $params : (<db item>=><value>) |
|
| 56 | + * @param integer $ruleID : rule id in db |
|
| 57 | + * @return array affected rows |
|
| 58 | + */ |
|
| 59 | + public function updateHandlerRule($params,$ruleID) |
|
| 60 | + { |
|
| 61 | + // TODO Check for rule consistency |
|
| 62 | + $dbConn = $this->getDbConn(); |
|
| 63 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 64 | + // Add last modified date = creation date and username |
|
| 65 | + $params['modified'] = new Zend_Db_Expr('NOW()'); |
|
| 66 | + $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername(); |
|
| 67 | 67 | |
| 68 | - $numRows=$dbConn->update( |
|
| 69 | - $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
|
| 70 | - $params, |
|
| 71 | - 'id='.$ruleID |
|
| 72 | - ); |
|
| 73 | - return $numRows; |
|
| 74 | - } |
|
| 68 | + $numRows=$dbConn->update( |
|
| 69 | + $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
|
| 70 | + $params, |
|
| 71 | + 'id='.$ruleID |
|
| 72 | + ); |
|
| 73 | + return $numRows; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /** Delete rule by id |
|
| 77 | - * @param int $ruleID rule id |
|
| 78 | - */ |
|
| 79 | - public function deleteRule($ruleID) |
|
| 80 | - { |
|
| 81 | - if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id'); } |
|
| 76 | + /** Delete rule by id |
|
| 77 | + * @param int $ruleID rule id |
|
| 78 | + */ |
|
| 79 | + public function deleteRule($ruleID) |
|
| 80 | + { |
|
| 81 | + if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id'); } |
|
| 82 | 82 | |
| 83 | - $dbConn = $this->getDbConn(); |
|
| 84 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 83 | + $dbConn = $this->getDbConn(); |
|
| 84 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 85 | 85 | |
| 86 | - $query=$dbConn->delete( |
|
| 87 | - $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
|
| 88 | - 'id='.$ruleID |
|
| 89 | - ); |
|
| 90 | - return $query; |
|
| 91 | - } |
|
| 86 | + $query=$dbConn->delete( |
|
| 87 | + $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
|
| 88 | + 'id='.$ruleID |
|
| 89 | + ); |
|
| 90 | + return $query; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** Delete trap by ip & oid |
|
| 94 | - * @param $ipAddr string source IP (v4 or v6) |
|
| 95 | - * @param $oid string oid |
|
| 96 | - */ |
|
| 97 | - public function deleteTrap($ipAddr,$oid) |
|
| 98 | - { |
|
| 93 | + /** Delete trap by ip & oid |
|
| 94 | + * @param $ipAddr string source IP (v4 or v6) |
|
| 95 | + * @param $oid string oid |
|
| 96 | + */ |
|
| 97 | + public function deleteTrap($ipAddr,$oid) |
|
| 98 | + { |
|
| 99 | 99 | |
| 100 | - $dbConn = $this->getDbConn(); |
|
| 101 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 102 | - $condition=null; |
|
| 103 | - if ($ipAddr != null) |
|
| 104 | - { |
|
| 105 | - $condition="source_ip='$ipAddr'"; |
|
| 106 | - } |
|
| 107 | - if ($oid != null) |
|
| 108 | - { |
|
| 109 | - $condition=($condition===null)?'':$condition.' AND '; |
|
| 110 | - $condition.="trap_oid='$oid'"; |
|
| 111 | - } |
|
| 112 | - if($condition === null) return null; |
|
| 113 | - $query=$dbConn->delete( |
|
| 114 | - $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(), |
|
| 115 | - $condition |
|
| 116 | - ); |
|
| 117 | - // TODO test ret code etc... |
|
| 118 | - return $query; |
|
| 119 | - } |
|
| 100 | + $dbConn = $this->getDbConn(); |
|
| 101 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 102 | + $condition=null; |
|
| 103 | + if ($ipAddr != null) |
|
| 104 | + { |
|
| 105 | + $condition="source_ip='$ipAddr'"; |
|
| 106 | + } |
|
| 107 | + if ($oid != null) |
|
| 108 | + { |
|
| 109 | + $condition=($condition===null)?'':$condition.' AND '; |
|
| 110 | + $condition.="trap_oid='$oid'"; |
|
| 111 | + } |
|
| 112 | + if($condition === null) return null; |
|
| 113 | + $query=$dbConn->delete( |
|
| 114 | + $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(), |
|
| 115 | + $condition |
|
| 116 | + ); |
|
| 117 | + // TODO test ret code etc... |
|
| 118 | + return $query; |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | 121 | |
| 122 | - /** count trap by ip & oid |
|
| 123 | - * @param $ipAddr string source IP (v4 or v6) |
|
| 124 | - * @param $oid string oid |
|
| 125 | - */ |
|
| 126 | - public function countTrap($ipAddr,$oid) |
|
| 127 | - { |
|
| 122 | + /** count trap by ip & oid |
|
| 123 | + * @param $ipAddr string source IP (v4 or v6) |
|
| 124 | + * @param $oid string oid |
|
| 125 | + */ |
|
| 126 | + public function countTrap($ipAddr,$oid) |
|
| 127 | + { |
|
| 128 | 128 | |
| 129 | - $dbConn = $this->getDbConn(); |
|
| 130 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 129 | + $dbConn = $this->getDbConn(); |
|
| 130 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 131 | 131 | |
| 132 | - $condition=null; |
|
| 133 | - if ($ipAddr != null) |
|
| 134 | - { |
|
| 135 | - $condition="source_ip='$ipAddr'"; |
|
| 136 | - } |
|
| 137 | - if ($oid != null) |
|
| 138 | - { |
|
| 139 | - $condition=($condition===null)?'':$condition.' AND '; |
|
| 140 | - $condition.="trap_oid='$oid'"; |
|
| 141 | - } |
|
| 142 | - if($condition === null) return 0; |
|
| 143 | - $query=$dbConn->select() |
|
| 144 | - ->from( |
|
| 145 | - $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(), |
|
| 146 | - array('num'=>'count(*)')) |
|
| 147 | - ->where($condition); |
|
| 148 | - $returnRow=$dbConn->fetchRow($query); |
|
| 149 | - return $returnRow->num; |
|
| 150 | - } |
|
| 132 | + $condition=null; |
|
| 133 | + if ($ipAddr != null) |
|
| 134 | + { |
|
| 135 | + $condition="source_ip='$ipAddr'"; |
|
| 136 | + } |
|
| 137 | + if ($oid != null) |
|
| 138 | + { |
|
| 139 | + $condition=($condition===null)?'':$condition.' AND '; |
|
| 140 | + $condition.="trap_oid='$oid'"; |
|
| 141 | + } |
|
| 142 | + if($condition === null) return 0; |
|
| 143 | + $query=$dbConn->select() |
|
| 144 | + ->from( |
|
| 145 | + $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(), |
|
| 146 | + array('num'=>'count(*)')) |
|
| 147 | + ->where($condition); |
|
| 148 | + $returnRow=$dbConn->fetchRow($query); |
|
| 149 | + return $returnRow->num; |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - /** get configuration value |
|
| 153 | - * @param string $element : configuration name in db |
|
| 154 | - */ |
|
| 155 | - public function getDBConfigValue($element) |
|
| 156 | - { |
|
| 152 | + /** get configuration value |
|
| 153 | + * @param string $element : configuration name in db |
|
| 154 | + */ |
|
| 155 | + public function getDBConfigValue($element) |
|
| 156 | + { |
|
| 157 | 157 | |
| 158 | - $dbConn = $this->getDbConn(); |
|
| 159 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 158 | + $dbConn = $this->getDbConn(); |
|
| 159 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 160 | 160 | |
| 161 | - $query=$dbConn->select() |
|
| 162 | - ->from( |
|
| 163 | - $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(), |
|
| 164 | - array('value'=>'value')) |
|
| 165 | - ->where('name=?',$element); |
|
| 166 | - $returnRow=$dbConn->fetchRow($query); |
|
| 167 | - if ($returnRow==null) // value does not exists |
|
| 168 | - { |
|
| 169 | - $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults(); |
|
| 170 | - if ( ! isset($default[$element])) return null; // no default and not value |
|
| 161 | + $query=$dbConn->select() |
|
| 162 | + ->from( |
|
| 163 | + $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(), |
|
| 164 | + array('value'=>'value')) |
|
| 165 | + ->where('name=?',$element); |
|
| 166 | + $returnRow=$dbConn->fetchRow($query); |
|
| 167 | + if ($returnRow==null) // value does not exists |
|
| 168 | + { |
|
| 169 | + $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults(); |
|
| 170 | + if ( ! isset($default[$element])) return null; // no default and not value |
|
| 171 | 171 | |
| 172 | - $this->addDBConfigValue($element,$default[$element]); |
|
| 173 | - return $default[$element]; |
|
| 174 | - } |
|
| 175 | - if ($returnRow->value == null) // value id empty |
|
| 176 | - { |
|
| 177 | - $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults(); |
|
| 178 | - if ( ! isset($default[$element])) return null; // no default and not value |
|
| 179 | - $this->setDBConfigValue($element,$default[$element]); |
|
| 180 | - return $default[$element]; |
|
| 181 | - } |
|
| 182 | - return $returnRow->value; |
|
| 183 | - } |
|
| 172 | + $this->addDBConfigValue($element,$default[$element]); |
|
| 173 | + return $default[$element]; |
|
| 174 | + } |
|
| 175 | + if ($returnRow->value == null) // value id empty |
|
| 176 | + { |
|
| 177 | + $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults(); |
|
| 178 | + if ( ! isset($default[$element])) return null; // no default and not value |
|
| 179 | + $this->setDBConfigValue($element,$default[$element]); |
|
| 180 | + return $default[$element]; |
|
| 181 | + } |
|
| 182 | + return $returnRow->value; |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - /** add configuration value |
|
| 186 | - * @param string $element : name of config element |
|
| 187 | - * @param string $value : value |
|
| 188 | - */ |
|
| 185 | + /** add configuration value |
|
| 186 | + * @param string $element : name of config element |
|
| 187 | + * @param string $value : value |
|
| 188 | + */ |
|
| 189 | 189 | |
| 190 | - public function addDBConfigValue($element,$value) |
|
| 191 | - { |
|
| 190 | + public function addDBConfigValue($element,$value) |
|
| 191 | + { |
|
| 192 | 192 | |
| 193 | - $dbConn = $this->getDbConn(); |
|
| 194 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 193 | + $dbConn = $this->getDbConn(); |
|
| 194 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 195 | 195 | |
| 196 | - $query=$dbConn->insert( |
|
| 197 | - $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(), |
|
| 198 | - array( |
|
| 199 | - 'name' => $element, |
|
| 200 | - 'value'=>$value |
|
| 201 | - ) |
|
| 202 | - ); |
|
| 203 | - return $query; |
|
| 204 | - } |
|
| 196 | + $query=$dbConn->insert( |
|
| 197 | + $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(), |
|
| 198 | + array( |
|
| 199 | + 'name' => $element, |
|
| 200 | + 'value'=>$value |
|
| 201 | + ) |
|
| 202 | + ); |
|
| 203 | + return $query; |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - /** set configuration value |
|
| 207 | - * @param string $element : name of config element |
|
| 208 | - * @param string $value : value |
|
| 209 | - */ |
|
| 210 | - public function setDBConfigValue($element,$value) |
|
| 211 | - { |
|
| 206 | + /** set configuration value |
|
| 207 | + * @param string $element : name of config element |
|
| 208 | + * @param string $value : value |
|
| 209 | + */ |
|
| 210 | + public function setDBConfigValue($element,$value) |
|
| 211 | + { |
|
| 212 | 212 | |
| 213 | - $dbConn = $this->getDbConn(); |
|
| 214 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 213 | + $dbConn = $this->getDbConn(); |
|
| 214 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 215 | 215 | |
| 216 | - $query=$dbConn->update( |
|
| 217 | - $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(), |
|
| 218 | - array('value'=>$value), |
|
| 219 | - 'name=\''.$element.'\'' |
|
| 220 | - ); |
|
| 221 | - return $query; |
|
| 222 | - } |
|
| 216 | + $query=$dbConn->update( |
|
| 217 | + $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(), |
|
| 218 | + array('value'=>$value), |
|
| 219 | + 'name=\''.$element.'\'' |
|
| 220 | + ); |
|
| 221 | + return $query; |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | 224 | |
| 225 | 225 | } |
| 226 | 226 | \ No newline at end of file |
@@ -33,18 +33,18 @@ discard block |
||
| 33 | 33 | { |
| 34 | 34 | // TODO Check for rule consistency |
| 35 | 35 | |
| 36 | - $dbConn = $this->getDbConn(); |
|
| 36 | + $dbConn=$this->getDbConn(); |
|
| 37 | 37 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 38 | 38 | // Add last modified date = creation date and username |
| 39 | - $params['created'] = new Zend_Db_Expr('NOW()'); |
|
| 40 | - $params['modified'] = new Zend_Db_Expr('NOW()'); |
|
| 41 | - $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername(); |
|
| 39 | + $params['created']=new Zend_Db_Expr('NOW()'); |
|
| 40 | + $params['modified']=new Zend_Db_Expr('NOW()'); |
|
| 41 | + $params['modifier']=$this->getTrapCtrl()->Auth()->getUser()->getUsername(); |
|
| 42 | 42 | |
| 43 | 43 | $query=$dbConn->insert( |
| 44 | 44 | $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
| 45 | 45 | $params |
| 46 | 46 | ); |
| 47 | - if($query==false) |
|
| 47 | + if ($query == false) |
|
| 48 | 48 | { |
| 49 | 49 | return null; |
| 50 | 50 | } |
@@ -56,14 +56,14 @@ discard block |
||
| 56 | 56 | * @param integer $ruleID : rule id in db |
| 57 | 57 | * @return array affected rows |
| 58 | 58 | */ |
| 59 | - public function updateHandlerRule($params,$ruleID) |
|
| 59 | + public function updateHandlerRule($params, $ruleID) |
|
| 60 | 60 | { |
| 61 | 61 | // TODO Check for rule consistency |
| 62 | - $dbConn = $this->getDbConn(); |
|
| 62 | + $dbConn=$this->getDbConn(); |
|
| 63 | 63 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 64 | 64 | // Add last modified date = creation date and username |
| 65 | - $params['modified'] = new Zend_Db_Expr('NOW()'); |
|
| 66 | - $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername(); |
|
| 65 | + $params['modified']=new Zend_Db_Expr('NOW()'); |
|
| 66 | + $params['modifier']=$this->getTrapCtrl()->Auth()->getUser()->getUsername(); |
|
| 67 | 67 | |
| 68 | 68 | $numRows=$dbConn->update( |
| 69 | 69 | $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
@@ -78,9 +78,9 @@ discard block |
||
| 78 | 78 | */ |
| 79 | 79 | public function deleteRule($ruleID) |
| 80 | 80 | { |
| 81 | - if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id'); } |
|
| 81 | + if (!preg_match('/^[0-9]+$/', $ruleID)) { throw new Exception('Invalid id'); } |
|
| 82 | 82 | |
| 83 | - $dbConn = $this->getDbConn(); |
|
| 83 | + $dbConn=$this->getDbConn(); |
|
| 84 | 84 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 85 | 85 | |
| 86 | 86 | $query=$dbConn->delete( |
@@ -94,10 +94,10 @@ discard block |
||
| 94 | 94 | * @param $ipAddr string source IP (v4 or v6) |
| 95 | 95 | * @param $oid string oid |
| 96 | 96 | */ |
| 97 | - public function deleteTrap($ipAddr,$oid) |
|
| 97 | + public function deleteTrap($ipAddr, $oid) |
|
| 98 | 98 | { |
| 99 | 99 | |
| 100 | - $dbConn = $this->getDbConn(); |
|
| 100 | + $dbConn=$this->getDbConn(); |
|
| 101 | 101 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 102 | 102 | $condition=null; |
| 103 | 103 | if ($ipAddr != null) |
@@ -106,10 +106,10 @@ discard block |
||
| 106 | 106 | } |
| 107 | 107 | if ($oid != null) |
| 108 | 108 | { |
| 109 | - $condition=($condition===null)?'':$condition.' AND '; |
|
| 109 | + $condition=($condition === null) ? '' : $condition.' AND '; |
|
| 110 | 110 | $condition.="trap_oid='$oid'"; |
| 111 | 111 | } |
| 112 | - if($condition === null) return null; |
|
| 112 | + if ($condition === null) return null; |
|
| 113 | 113 | $query=$dbConn->delete( |
| 114 | 114 | $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(), |
| 115 | 115 | $condition |
@@ -123,10 +123,10 @@ discard block |
||
| 123 | 123 | * @param $ipAddr string source IP (v4 or v6) |
| 124 | 124 | * @param $oid string oid |
| 125 | 125 | */ |
| 126 | - public function countTrap($ipAddr,$oid) |
|
| 126 | + public function countTrap($ipAddr, $oid) |
|
| 127 | 127 | { |
| 128 | 128 | |
| 129 | - $dbConn = $this->getDbConn(); |
|
| 129 | + $dbConn=$this->getDbConn(); |
|
| 130 | 130 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 131 | 131 | |
| 132 | 132 | $condition=null; |
@@ -136,10 +136,10 @@ discard block |
||
| 136 | 136 | } |
| 137 | 137 | if ($oid != null) |
| 138 | 138 | { |
| 139 | - $condition=($condition===null)?'':$condition.' AND '; |
|
| 139 | + $condition=($condition === null) ? '' : $condition.' AND '; |
|
| 140 | 140 | $condition.="trap_oid='$oid'"; |
| 141 | 141 | } |
| 142 | - if($condition === null) return 0; |
|
| 142 | + if ($condition === null) return 0; |
|
| 143 | 143 | $query=$dbConn->select() |
| 144 | 144 | ->from( |
| 145 | 145 | $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(), |
@@ -155,28 +155,28 @@ discard block |
||
| 155 | 155 | public function getDBConfigValue($element) |
| 156 | 156 | { |
| 157 | 157 | |
| 158 | - $dbConn = $this->getDbConn(); |
|
| 158 | + $dbConn=$this->getDbConn(); |
|
| 159 | 159 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 160 | 160 | |
| 161 | 161 | $query=$dbConn->select() |
| 162 | 162 | ->from( |
| 163 | 163 | $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(), |
| 164 | 164 | array('value'=>'value')) |
| 165 | - ->where('name=?',$element); |
|
| 165 | + ->where('name=?', $element); |
|
| 166 | 166 | $returnRow=$dbConn->fetchRow($query); |
| 167 | - if ($returnRow==null) // value does not exists |
|
| 167 | + if ($returnRow == null) // value does not exists |
|
| 168 | 168 | { |
| 169 | 169 | $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults(); |
| 170 | - if ( ! isset($default[$element])) return null; // no default and not value |
|
| 170 | + if (!isset($default[$element])) return null; // no default and not value |
|
| 171 | 171 | |
| 172 | - $this->addDBConfigValue($element,$default[$element]); |
|
| 172 | + $this->addDBConfigValue($element, $default[$element]); |
|
| 173 | 173 | return $default[$element]; |
| 174 | 174 | } |
| 175 | 175 | if ($returnRow->value == null) // value id empty |
| 176 | 176 | { |
| 177 | 177 | $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults(); |
| 178 | - if ( ! isset($default[$element])) return null; // no default and not value |
|
| 179 | - $this->setDBConfigValue($element,$default[$element]); |
|
| 178 | + if (!isset($default[$element])) return null; // no default and not value |
|
| 179 | + $this->setDBConfigValue($element, $default[$element]); |
|
| 180 | 180 | return $default[$element]; |
| 181 | 181 | } |
| 182 | 182 | return $returnRow->value; |
@@ -187,10 +187,10 @@ discard block |
||
| 187 | 187 | * @param string $value : value |
| 188 | 188 | */ |
| 189 | 189 | |
| 190 | - public function addDBConfigValue($element,$value) |
|
| 190 | + public function addDBConfigValue($element, $value) |
|
| 191 | 191 | { |
| 192 | 192 | |
| 193 | - $dbConn = $this->getDbConn(); |
|
| 193 | + $dbConn=$this->getDbConn(); |
|
| 194 | 194 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 195 | 195 | |
| 196 | 196 | $query=$dbConn->insert( |
@@ -207,10 +207,10 @@ discard block |
||
| 207 | 207 | * @param string $element : name of config element |
| 208 | 208 | * @param string $value : value |
| 209 | 209 | */ |
| 210 | - public function setDBConfigValue($element,$value) |
|
| 210 | + public function setDBConfigValue($element, $value) |
|
| 211 | 211 | { |
| 212 | 212 | |
| 213 | - $dbConn = $this->getDbConn(); |
|
| 213 | + $dbConn=$this->getDbConn(); |
|
| 214 | 214 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 215 | 215 | |
| 216 | 216 | $query=$dbConn->update( |
@@ -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) |
@@ -76,12 +76,12 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | public function getTrapHostListTable() |
| 78 | 78 | { |
| 79 | - if ($this->trapTableHostList == Null) |
|
| 79 | + if ($this->trapTableHostList == Null) |
|
| 80 | 80 | { |
| 81 | - $this->trapTableHostList = new TrapTableHostList(); |
|
| 82 | - $this->trapTableHostList->setConfig($this->getModuleConfig()); |
|
| 83 | - } |
|
| 84 | - return $this->trapTableHostList; |
|
| 81 | + $this->trapTableHostList = new TrapTableHostList(); |
|
| 82 | + $this->trapTableHostList->setConfig($this->getModuleConfig()); |
|
| 83 | + } |
|
| 84 | + return $this->trapTableHostList; |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -102,23 +102,23 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | public function getUIDatabase() |
| 104 | 104 | { |
| 105 | - if ($this->UIDatabase == Null) |
|
| 106 | - { |
|
| 107 | - $this->UIDatabase = new UIDatabase($this); |
|
| 105 | + if ($this->UIDatabase == Null) |
|
| 106 | + { |
|
| 107 | + $this->UIDatabase = new UIDatabase($this); |
|
| 108 | 108 | |
| 109 | - } |
|
| 110 | - return $this->UIDatabase; |
|
| 109 | + } |
|
| 110 | + return $this->UIDatabase; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null) |
|
| 114 | - { |
|
| 115 | - $limit = $this->params->get('limit', $limit); |
|
| 116 | - $page = $this->params->get('page', $offset); |
|
| 113 | + protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null) |
|
| 114 | + { |
|
| 115 | + $limit = $this->params->get('limit', $limit); |
|
| 116 | + $page = $this->params->get('page', $offset); |
|
| 117 | 117 | |
| 118 | - $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0); |
|
| 118 | + $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0); |
|
| 119 | 119 | |
| 120 | - return $paginatable; |
|
| 121 | - } |
|
| 120 | + return $paginatable; |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | 123 | public function displayExitError($source,$message) |
| 124 | 124 | { // TODO : check better ways to transmit data (with POST ?) |
@@ -127,33 +127,33 @@ discard block |
||
| 127 | 127 | |
| 128 | 128 | protected function checkReadPermission() |
| 129 | 129 | { |
| 130 | - if (! $this->Auth()->hasPermission('trapdirector/view')) { |
|
| 131 | - $this->displayExitError('Permissions','No permission fo view content'); |
|
| 132 | - } |
|
| 130 | + if (! $this->Auth()->hasPermission('trapdirector/view')) { |
|
| 131 | + $this->displayExitError('Permissions','No permission fo view content'); |
|
| 132 | + } |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | protected function checkConfigPermission() |
| 136 | 136 | { |
| 137 | - if (! $this->Auth()->hasPermission('trapdirector/config')) { |
|
| 138 | - $this->displayExitError('Permissions','No permission fo configure'); |
|
| 139 | - } |
|
| 137 | + if (! $this->Auth()->hasPermission('trapdirector/config')) { |
|
| 138 | + $this->displayExitError('Permissions','No permission fo configure'); |
|
| 139 | + } |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * Check if user has write permission |
|
| 144 | - * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page |
|
| 145 | - * @return boolean : user has permission |
|
| 146 | - */ |
|
| 142 | + /** |
|
| 143 | + * Check if user has write permission |
|
| 144 | + * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page |
|
| 145 | + * @return boolean : user has permission |
|
| 146 | + */ |
|
| 147 | 147 | protected function checkModuleConfigPermission($check=0) |
| 148 | 148 | { |
| 149 | - if (! $this->Auth()->hasPermission('trapdirector/module_config')) { |
|
| 150 | - if ($check == 0) |
|
| 151 | - { |
|
| 152 | - $this->displayExitError('Permissions','No permission fo configure module'); |
|
| 153 | - } |
|
| 154 | - return false; |
|
| 155 | - } |
|
| 156 | - return true; |
|
| 149 | + if (! $this->Auth()->hasPermission('trapdirector/module_config')) { |
|
| 150 | + if ($check == 0) |
|
| 151 | + { |
|
| 152 | + $this->displayExitError('Permissions','No permission fo configure module'); |
|
| 153 | + } |
|
| 154 | + return false; |
|
| 155 | + } |
|
| 156 | + return true; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /************************* Trap class get **********************/ |
@@ -173,18 +173,18 @@ discard block |
||
| 173 | 173 | /************************** MIB related **************************/ |
| 174 | 174 | |
| 175 | 175 | /** Get MIBLoader class |
| 176 | - * @return MIBLoader class |
|
| 177 | - */ |
|
| 176 | + * @return MIBLoader class |
|
| 177 | + */ |
|
| 178 | 178 | protected function getMIB() |
| 179 | 179 | { |
| 180 | 180 | if ($this->MIBData == null) |
| 181 | 181 | { |
| 182 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
| 183 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 182 | + $dbConn = $this->getUIDatabase()->getDbConn(); |
|
| 183 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 184 | 184 | $this->MIBData=new MIBLoader( |
| 185 | 185 | $this->Config()->get('config', 'snmptranslate'), |
| 186 | 186 | $this->Config()->get('config', 'snmptranslate_dirs'), |
| 187 | - $dbConn, |
|
| 187 | + $dbConn, |
|
| 188 | 188 | $this->getModuleConfig() |
| 189 | 189 | ); |
| 190 | 190 | } |
@@ -194,13 +194,13 @@ discard block |
||
| 194 | 194 | /************************** Database queries *******************/ |
| 195 | 195 | |
| 196 | 196 | /** Check if director is installed |
| 197 | - * @return bool true/false |
|
| 198 | - */ |
|
| 197 | + * @return bool true/false |
|
| 198 | + */ |
|
| 199 | 199 | protected function isDirectorInstalled() |
| 200 | 200 | { |
| 201 | - $output=array(); |
|
| 202 | - exec('icingacli module list',$output); |
|
| 203 | - foreach ($output as $line) |
|
| 201 | + $output=array(); |
|
| 202 | + exec('icingacli module list',$output); |
|
| 203 | + foreach ($output as $line) |
|
| 204 | 204 | { |
| 205 | 205 | if (preg_match('/^director .*enabled/',$line)) |
| 206 | 206 | { |
@@ -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; |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | { |
| 79 | 79 | if ($this->trapTableHostList == Null) |
| 80 | 80 | { |
| 81 | - $this->trapTableHostList = new TrapTableHostList(); |
|
| 81 | + $this->trapTableHostList=new TrapTableHostList(); |
|
| 82 | 82 | $this->trapTableHostList->setConfig($this->getModuleConfig()); |
| 83 | 83 | } |
| 84 | 84 | return $this->trapTableHostList; |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | { |
| 92 | 92 | if ($this->handlerTableList == Null) |
| 93 | 93 | { |
| 94 | - $this->handlerTableList = new HandlerTableList(); |
|
| 94 | + $this->handlerTableList=new HandlerTableList(); |
|
| 95 | 95 | $this->handlerTableList->setConfig($this->getModuleConfig()); |
| 96 | 96 | } |
| 97 | 97 | return $this->handlerTableList; |
@@ -104,38 +104,38 @@ discard block |
||
| 104 | 104 | { |
| 105 | 105 | if ($this->UIDatabase == Null) |
| 106 | 106 | { |
| 107 | - $this->UIDatabase = new UIDatabase($this); |
|
| 107 | + $this->UIDatabase=new UIDatabase($this); |
|
| 108 | 108 | |
| 109 | 109 | } |
| 110 | 110 | return $this->UIDatabase; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null) |
|
| 113 | + protected function applyPaginationLimits(Paginatable $paginatable, $limit=25, $offset=null) |
|
| 114 | 114 | { |
| 115 | - $limit = $this->params->get('limit', $limit); |
|
| 116 | - $page = $this->params->get('page', $offset); |
|
| 115 | + $limit=$this->params->get('limit', $limit); |
|
| 116 | + $page=$this->params->get('page', $offset); |
|
| 117 | 117 | |
| 118 | 118 | $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0); |
| 119 | 119 | |
| 120 | 120 | return $paginatable; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - public function displayExitError($source,$message) |
|
| 123 | + public function displayExitError($source, $message) |
|
| 124 | 124 | { // TODO : check better ways to transmit data (with POST ?) |
| 125 | 125 | $this->redirectNow('trapdirector/error?source='.$source.'&message='.$message); |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | protected function checkReadPermission() |
| 129 | 129 | { |
| 130 | - if (! $this->Auth()->hasPermission('trapdirector/view')) { |
|
| 131 | - $this->displayExitError('Permissions','No permission fo view content'); |
|
| 130 | + if (!$this->Auth()->hasPermission('trapdirector/view')) { |
|
| 131 | + $this->displayExitError('Permissions', 'No permission fo view content'); |
|
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | protected function checkConfigPermission() |
| 136 | 136 | { |
| 137 | - if (! $this->Auth()->hasPermission('trapdirector/config')) { |
|
| 138 | - $this->displayExitError('Permissions','No permission fo configure'); |
|
| 137 | + if (!$this->Auth()->hasPermission('trapdirector/config')) { |
|
| 138 | + $this->displayExitError('Permissions', 'No permission fo configure'); |
|
| 139 | 139 | } |
| 140 | 140 | } |
| 141 | 141 | |
@@ -146,10 +146,10 @@ discard block |
||
| 146 | 146 | */ |
| 147 | 147 | protected function checkModuleConfigPermission($check=0) |
| 148 | 148 | { |
| 149 | - if (! $this->Auth()->hasPermission('trapdirector/module_config')) { |
|
| 149 | + if (!$this->Auth()->hasPermission('trapdirector/module_config')) { |
|
| 150 | 150 | if ($check == 0) |
| 151 | 151 | { |
| 152 | - $this->displayExitError('Permissions','No permission fo configure module'); |
|
| 152 | + $this->displayExitError('Permissions', 'No permission fo configure module'); |
|
| 153 | 153 | } |
| 154 | 154 | return false; |
| 155 | 155 | } |
@@ -161,10 +161,10 @@ discard block |
||
| 161 | 161 | { // TODO : try/catch here ? or within caller |
| 162 | 162 | if ($this->trapClass == null) |
| 163 | 163 | { |
| 164 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 164 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
| 165 | 165 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 166 | 166 | //$debug_level=4; |
| 167 | - $this->trapClass = new Trap($icingaweb2_etc); |
|
| 167 | + $this->trapClass=new Trap($icingaweb2_etc); |
|
| 168 | 168 | //$Trap->setLogging($debug_level,'syslog'); |
| 169 | 169 | } |
| 170 | 170 | return $this->trapClass; |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | { |
| 180 | 180 | if ($this->MIBData == null) |
| 181 | 181 | { |
| 182 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
| 182 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
| 183 | 183 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 184 | 184 | $this->MIBData=new MIBLoader( |
| 185 | 185 | $this->Config()->get('config', 'snmptranslate'), |
@@ -199,10 +199,10 @@ discard block |
||
| 199 | 199 | protected function isDirectorInstalled() |
| 200 | 200 | { |
| 201 | 201 | $output=array(); |
| 202 | - exec('icingacli module list',$output); |
|
| 202 | + exec('icingacli module list', $output); |
|
| 203 | 203 | foreach ($output as $line) |
| 204 | 204 | { |
| 205 | - if (preg_match('/^director .*enabled/',$line)) |
|
| 205 | + if (preg_match('/^director .*enabled/', $line)) |
|
| 206 | 206 | { |
| 207 | 207 | return true; |
| 208 | 208 | } |
@@ -180,7 +180,9 @@ |
||
| 180 | 180 | if ($this->MIBData == null) |
| 181 | 181 | { |
| 182 | 182 | $dbConn = $this->getUIDatabase()->getDbConn(); |
| 183 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 183 | + if ($dbConn === null) { |
|
| 184 | + throw new \ErrorException('uncatched db error'); |
|
| 185 | + } |
|
| 184 | 186 | $this->MIBData=new MIBLoader( |
| 185 | 187 | $this->Config()->get('config', 'snmptranslate'), |
| 186 | 188 | $this->Config()->get('config', 'snmptranslate_dirs'), |
@@ -23,14 +23,14 @@ discard block |
||
| 23 | 23 | public function getHostByIP($ip) |
| 24 | 24 | { |
| 25 | 25 | // 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 |
| 26 | - $dbConn = $this->getIdoDbConn(); |
|
| 26 | + $dbConn=$this->getIdoDbConn(); |
|
| 27 | 27 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 28 | 28 | |
| 29 | 29 | // TODO : check for SQL injections |
| 30 | 30 | $query=$dbConn->select() |
| 31 | 31 | ->from( |
| 32 | 32 | array('a' => 'icinga_objects'), |
| 33 | - array('name' => 'a.name1','id' => 'object_id')) |
|
| 33 | + array('name' => 'a.name1', 'id' => 'object_id')) |
|
| 34 | 34 | ->join( |
| 35 | 35 | array('b' => 'icinga_hosts'), |
| 36 | 36 | 'b.host_object_id=a.object_id', |
@@ -46,14 +46,14 @@ discard block |
||
| 46 | 46 | public function getHostByName($name) |
| 47 | 47 | { |
| 48 | 48 | // 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 |
| 49 | - $dbConn = $this->getIdoDbConn(); |
|
| 49 | + $dbConn=$this->getIdoDbConn(); |
|
| 50 | 50 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 51 | 51 | |
| 52 | 52 | // TODO : check for SQL injections |
| 53 | 53 | $query=$dbConn->select() |
| 54 | 54 | ->from( |
| 55 | 55 | array('a' => 'icinga_objects'), |
| 56 | - array('name' => 'a.name1','id' => 'object_id')) |
|
| 56 | + array('name' => 'a.name1', 'id' => 'object_id')) |
|
| 57 | 57 | ->join( |
| 58 | 58 | array('b' => 'icinga_hosts'), |
| 59 | 59 | 'b.host_object_id=a.object_id', |
@@ -69,13 +69,13 @@ discard block |
||
| 69 | 69 | public function getHostGroupByName($ip) |
| 70 | 70 | { |
| 71 | 71 | // 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 |
| 72 | - $dbConn = $this->getIdoDbConn(); |
|
| 72 | + $dbConn=$this->getIdoDbConn(); |
|
| 73 | 73 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 74 | 74 | // TODO : check for SQL injections |
| 75 | 75 | $query=$dbConn->select() |
| 76 | 76 | ->from( |
| 77 | 77 | array('a' => 'icinga_objects'), |
| 78 | - array('name' => 'a.name1','id' => 'object_id')) |
|
| 78 | + array('name' => 'a.name1', 'id' => 'object_id')) |
|
| 79 | 79 | ->join( |
| 80 | 80 | array('b' => 'icinga_hostgroups'), |
| 81 | 81 | 'b.hostgroup_object_id=a.object_id', |
@@ -91,8 +91,8 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | public function getHostInfoByID($id) |
| 93 | 93 | { |
| 94 | - if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
| 95 | - $dbConn = $this->getIdoDbConn(); |
|
| 94 | + if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); } |
|
| 95 | + $dbConn=$this->getIdoDbConn(); |
|
| 96 | 96 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 97 | 97 | $query=$dbConn->select() |
| 98 | 98 | ->from( |
@@ -113,18 +113,18 @@ discard block |
||
| 113 | 113 | */ |
| 114 | 114 | public function getHostByObjectID($id) // TODO : duplicate of getHostInfoByID above |
| 115 | 115 | { |
| 116 | - if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
| 117 | - $dbConn = $this->getIdoDbConn(); |
|
| 116 | + if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); } |
|
| 117 | + $dbConn=$this->getIdoDbConn(); |
|
| 118 | 118 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 119 | 119 | $query=$dbConn->select() |
| 120 | 120 | ->from( |
| 121 | 121 | array('a' => 'icinga_objects'), |
| 122 | - array('name' => 'a.name1','id' => 'a.object_id')) |
|
| 122 | + array('name' => 'a.name1', 'id' => 'a.object_id')) |
|
| 123 | 123 | ->join( |
| 124 | 124 | array('b' => 'icinga_hosts'), |
| 125 | 125 | 'b.host_object_id=a.object_id', |
| 126 | - array('display_name' => 'b.display_name' , 'ip' => 'b.address', 'ip6' => 'b.address6')) |
|
| 127 | - ->where('a.object_id = ?',$id); |
|
| 126 | + array('display_name' => 'b.display_name', 'ip' => 'b.address', 'ip6' => 'b.address6')) |
|
| 127 | + ->where('a.object_id = ?', $id); |
|
| 128 | 128 | return $dbConn->fetchRow($query); |
| 129 | 129 | } |
| 130 | 130 | |
@@ -136,17 +136,17 @@ discard block |
||
| 136 | 136 | public function getServicesByHostid($id) |
| 137 | 137 | { |
| 138 | 138 | // 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 |
| 139 | - if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
| 140 | - $dbConn = $this->getIdoDbConn(); |
|
| 139 | + if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); } |
|
| 140 | + $dbConn=$this->getIdoDbConn(); |
|
| 141 | 141 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 142 | 142 | $query=$dbConn->select() |
| 143 | 143 | ->from( |
| 144 | 144 | array('s' => 'icinga_services'), |
| 145 | - array('name' => 's.display_name','id' => 's.service_object_id')) |
|
| 145 | + array('name' => 's.display_name', 'id' => 's.service_object_id')) |
|
| 146 | 146 | ->join( |
| 147 | 147 | array('a' => 'icinga_objects'), |
| 148 | 148 | 's.service_object_id=a.object_id', |
| 149 | - array('is_active'=>'a.is_active','name2'=>'a.name2')) |
|
| 149 | + array('is_active'=>'a.is_active', 'name2'=>'a.name2')) |
|
| 150 | 150 | ->where('s.host_object_id='.$id.' AND a.is_active = 1'); |
| 151 | 151 | return $dbConn->fetchAll($query); |
| 152 | 152 | } |
@@ -159,8 +159,8 @@ discard block |
||
| 159 | 159 | */ |
| 160 | 160 | public function getServicesByHostGroupid($id) |
| 161 | 161 | { |
| 162 | - if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
| 163 | - $dbConn = $this->getIdoDbConn(); |
|
| 162 | + if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); } |
|
| 163 | + $dbConn=$this->getIdoDbConn(); |
|
| 164 | 164 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 165 | 165 | $query=$dbConn->select() |
| 166 | 166 | ->from( |
@@ -177,11 +177,11 @@ discard block |
||
| 177 | 177 | foreach ($hosts as $key => $host) |
| 178 | 178 | { // For each host, get all services and add in common_services if not found or add counter |
| 179 | 179 | $host_services=$this->getServicesByHostid($host->host_object_id); |
| 180 | - foreach($host_services as $service) |
|
| 180 | + foreach ($host_services as $service) |
|
| 181 | 181 | { |
| 182 | 182 | if (isset($common_services[$service->name2]['num'])) |
| 183 | 183 | { |
| 184 | - $common_services[$service->name2]['num'] +=1; |
|
| 184 | + $common_services[$service->name2]['num']+=1; |
|
| 185 | 185 | } |
| 186 | 186 | else |
| 187 | 187 | { |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | { |
| 198 | 198 | if ($common_services[$key]['num'] == $num_hosts) |
| 199 | 199 | { |
| 200 | - array_push($result,array($key,$common_services[$key]['name'])); |
|
| 200 | + array_push($result, array($key, $common_services[$key]['name'])); |
|
| 201 | 201 | } |
| 202 | 202 | } |
| 203 | 203 | |
@@ -210,9 +210,9 @@ discard block |
||
| 210 | 210 | * @param $name string service name |
| 211 | 211 | * @return array service id |
| 212 | 212 | */ |
| 213 | - public function getServiceIDByName($hostname,$name) |
|
| 213 | + public function getServiceIDByName($hostname, $name) |
|
| 214 | 214 | { |
| 215 | - $dbConn = $this->getIdoDbConn(); |
|
| 215 | + $dbConn=$this->getIdoDbConn(); |
|
| 216 | 216 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 217 | 217 | |
| 218 | 218 | if ($name == null) |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | $query=$dbConn->select() |
| 224 | 224 | ->from( |
| 225 | 225 | array('s' => 'icinga_services'), |
| 226 | - array('name' => 's.display_name','id' => 's.service_object_id')) |
|
| 226 | + array('name' => 's.display_name', 'id' => 's.service_object_id')) |
|
| 227 | 227 | ->join( |
| 228 | 228 | array('a' => 'icinga_objects'), |
| 229 | 229 | 's.service_object_id=a.object_id', |
@@ -241,14 +241,14 @@ discard block |
||
| 241 | 241 | public function getObjectNameByid($id) |
| 242 | 242 | { |
| 243 | 243 | // 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 |
| 244 | - if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
| 245 | - $dbConn = $this->getIdoDbConn(); |
|
| 244 | + if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); } |
|
| 245 | + $dbConn=$this->getIdoDbConn(); |
|
| 246 | 246 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 247 | 247 | |
| 248 | 248 | $query=$dbConn->select() |
| 249 | 249 | ->from( |
| 250 | 250 | array('a' => 'icinga_objects'), |
| 251 | - array('name1' => 'a.name1','name2' => 'a.name2')) |
|
| 251 | + array('name1' => 'a.name1', 'name2' => 'a.name2')) |
|
| 252 | 252 | ->where('a.object_id='.$id.' AND a.is_active = 1'); |
| 253 | 253 | |
| 254 | 254 | return $dbConn->fetchRow($query); |
@@ -24,7 +24,9 @@ discard block |
||
| 24 | 24 | { |
| 25 | 25 | // 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 |
| 26 | 26 | $dbConn = $this->getIdoDbConn(); |
| 27 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 27 | + if ($dbConn === null) { |
|
| 28 | + throw new \ErrorException('uncatched db error'); |
|
| 29 | + } |
|
| 28 | 30 | |
| 29 | 31 | // TODO : check for SQL injections |
| 30 | 32 | $query=$dbConn->select() |
@@ -47,7 +49,9 @@ discard block |
||
| 47 | 49 | { |
| 48 | 50 | // 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 |
| 49 | 51 | $dbConn = $this->getIdoDbConn(); |
| 50 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 52 | + if ($dbConn === null) { |
|
| 53 | + throw new \ErrorException('uncatched db error'); |
|
| 54 | + } |
|
| 51 | 55 | |
| 52 | 56 | // TODO : check for SQL injections |
| 53 | 57 | $query=$dbConn->select() |
@@ -70,7 +74,9 @@ discard block |
||
| 70 | 74 | { |
| 71 | 75 | // 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 |
| 72 | 76 | $dbConn = $this->getIdoDbConn(); |
| 73 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 77 | + if ($dbConn === null) { |
|
| 78 | + throw new \ErrorException('uncatched db error'); |
|
| 79 | + } |
|
| 74 | 80 | // TODO : check for SQL injections |
| 75 | 81 | $query=$dbConn->select() |
| 76 | 82 | ->from( |
@@ -93,7 +99,9 @@ discard block |
||
| 93 | 99 | { |
| 94 | 100 | if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
| 95 | 101 | $dbConn = $this->getIdoDbConn(); |
| 96 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 102 | + if ($dbConn === null) { |
|
| 103 | + throw new \ErrorException('uncatched db error'); |
|
| 104 | + } |
|
| 97 | 105 | $query=$dbConn->select() |
| 98 | 106 | ->from( |
| 99 | 107 | array('a' => 'icinga_objects'), |
@@ -115,7 +123,9 @@ discard block |
||
| 115 | 123 | { |
| 116 | 124 | if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
| 117 | 125 | $dbConn = $this->getIdoDbConn(); |
| 118 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 126 | + if ($dbConn === null) { |
|
| 127 | + throw new \ErrorException('uncatched db error'); |
|
| 128 | + } |
|
| 119 | 129 | $query=$dbConn->select() |
| 120 | 130 | ->from( |
| 121 | 131 | array('a' => 'icinga_objects'), |
@@ -138,7 +148,9 @@ discard block |
||
| 138 | 148 | // 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 |
| 139 | 149 | if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
| 140 | 150 | $dbConn = $this->getIdoDbConn(); |
| 141 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 151 | + if ($dbConn === null) { |
|
| 152 | + throw new \ErrorException('uncatched db error'); |
|
| 153 | + } |
|
| 142 | 154 | $query=$dbConn->select() |
| 143 | 155 | ->from( |
| 144 | 156 | array('s' => 'icinga_services'), |
@@ -161,7 +173,9 @@ discard block |
||
| 161 | 173 | { |
| 162 | 174 | if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
| 163 | 175 | $dbConn = $this->getIdoDbConn(); |
| 164 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 176 | + if ($dbConn === null) { |
|
| 177 | + throw new \ErrorException('uncatched db error'); |
|
| 178 | + } |
|
| 165 | 179 | $query=$dbConn->select() |
| 166 | 180 | ->from( |
| 167 | 181 | array('s' => 'icinga_hostgroup_members'), |
@@ -182,8 +196,7 @@ discard block |
||
| 182 | 196 | if (isset($common_services[$service->name2]['num'])) |
| 183 | 197 | { |
| 184 | 198 | $common_services[$service->name2]['num'] +=1; |
| 185 | - } |
|
| 186 | - else |
|
| 199 | + } else |
|
| 187 | 200 | { |
| 188 | 201 | $common_services[$service->name2]['num']=1; |
| 189 | 202 | $common_services[$service->name2]['name']=$service->name; |
@@ -213,7 +226,9 @@ discard block |
||
| 213 | 226 | public function getServiceIDByName($hostname,$name) |
| 214 | 227 | { |
| 215 | 228 | $dbConn = $this->getIdoDbConn(); |
| 216 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 229 | + if ($dbConn === null) { |
|
| 230 | + throw new \ErrorException('uncatched db error'); |
|
| 231 | + } |
|
| 217 | 232 | |
| 218 | 233 | if ($name == null) |
| 219 | 234 | { |
@@ -243,7 +258,9 @@ discard block |
||
| 243 | 258 | // 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 |
| 244 | 259 | if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
| 245 | 260 | $dbConn = $this->getIdoDbConn(); |
| 246 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 261 | + if ($dbConn === null) { |
|
| 262 | + throw new \ErrorException('uncatched db error'); |
|
| 263 | + } |
|
| 247 | 264 | |
| 248 | 265 | $query=$dbConn->select() |
| 249 | 266 | ->from( |
@@ -18,247 +18,247 @@ |
||
| 18 | 18 | trait IdoDBQuery |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** @return TrapsController */ |
|
| 22 | - abstract protected function getTrapCtrl(); |
|
| 21 | + /** @return TrapsController */ |
|
| 22 | + abstract protected function getTrapCtrl(); |
|
| 23 | 23 | |
| 24 | - /** @return Zend_Db_Adapter_Abstract : returns DB connexion or null on error */ |
|
| 25 | - abstract public function getIdoDbConn(); |
|
| 24 | + /** @return Zend_Db_Adapter_Abstract : returns DB connexion or null on error */ |
|
| 25 | + abstract public function getIdoDbConn(); |
|
| 26 | 26 | |
| 27 | - /** Get host(s) by IP (v4 or v6) or by name in IDO database |
|
| 28 | - * does not catch exceptions |
|
| 29 | - * @return array of objects ( name, id (object_id), display_name) |
|
| 30 | - */ |
|
| 31 | - public function getHostByIP($ip) |
|
| 32 | - { |
|
| 33 | - // 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 |
|
| 34 | - $dbConn = $this->getIdoDbConn(); |
|
| 35 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 27 | + /** Get host(s) by IP (v4 or v6) or by name in IDO database |
|
| 28 | + * does not catch exceptions |
|
| 29 | + * @return array of objects ( name, id (object_id), display_name) |
|
| 30 | + */ |
|
| 31 | + public function getHostByIP($ip) |
|
| 32 | + { |
|
| 33 | + // 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 |
|
| 34 | + $dbConn = $this->getIdoDbConn(); |
|
| 35 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 36 | 36 | |
| 37 | - // TODO : check for SQL injections |
|
| 38 | - $query=$dbConn->select() |
|
| 39 | - ->from( |
|
| 40 | - array('a' => 'icinga_objects'), |
|
| 41 | - array('name' => 'a.name1','id' => 'object_id')) |
|
| 42 | - ->join( |
|
| 43 | - array('b' => 'icinga_hosts'), |
|
| 44 | - 'b.host_object_id=a.object_id', |
|
| 45 | - array('display_name' => 'b.display_name')) |
|
| 46 | - ->where("(b.address LIKE '%".$ip."%' OR b.address6 LIKE '%".$ip."%' OR a.name1 LIKE '%".$ip."%' OR b.display_name LIKE '%".$ip."%') and a.is_active = 1"); |
|
| 47 | - return $dbConn->fetchAll($query); |
|
| 48 | - } |
|
| 37 | + // TODO : check for SQL injections |
|
| 38 | + $query=$dbConn->select() |
|
| 39 | + ->from( |
|
| 40 | + array('a' => 'icinga_objects'), |
|
| 41 | + array('name' => 'a.name1','id' => 'object_id')) |
|
| 42 | + ->join( |
|
| 43 | + array('b' => 'icinga_hosts'), |
|
| 44 | + 'b.host_object_id=a.object_id', |
|
| 45 | + array('display_name' => 'b.display_name')) |
|
| 46 | + ->where("(b.address LIKE '%".$ip."%' OR b.address6 LIKE '%".$ip."%' OR a.name1 LIKE '%".$ip."%' OR b.display_name LIKE '%".$ip."%') and a.is_active = 1"); |
|
| 47 | + return $dbConn->fetchAll($query); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** Get host(s) by name in IDO database |
|
| 51 | - * does not catch exceptions |
|
| 52 | - * @return array of objects ( name, id (object_id), display_name) |
|
| 53 | - */ |
|
| 54 | - public function getHostByName($name) |
|
| 55 | - { |
|
| 56 | - // 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 |
|
| 57 | - $dbConn = $this->getIdoDbConn(); |
|
| 58 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 50 | + /** Get host(s) by name in IDO database |
|
| 51 | + * does not catch exceptions |
|
| 52 | + * @return array of objects ( name, id (object_id), display_name) |
|
| 53 | + */ |
|
| 54 | + public function getHostByName($name) |
|
| 55 | + { |
|
| 56 | + // 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 |
|
| 57 | + $dbConn = $this->getIdoDbConn(); |
|
| 58 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 59 | 59 | |
| 60 | - // TODO : check for SQL injections |
|
| 61 | - $query=$dbConn->select() |
|
| 62 | - ->from( |
|
| 63 | - array('a' => 'icinga_objects'), |
|
| 64 | - array('name' => 'a.name1','id' => 'object_id')) |
|
| 65 | - ->join( |
|
| 66 | - array('b' => 'icinga_hosts'), |
|
| 67 | - 'b.host_object_id=a.object_id', |
|
| 68 | - array('display_name' => 'b.display_name')) |
|
| 69 | - ->where("a.name1 = '$name'"); |
|
| 70 | - return $dbConn->fetchAll($query); |
|
| 71 | - } |
|
| 60 | + // TODO : check for SQL injections |
|
| 61 | + $query=$dbConn->select() |
|
| 62 | + ->from( |
|
| 63 | + array('a' => 'icinga_objects'), |
|
| 64 | + array('name' => 'a.name1','id' => 'object_id')) |
|
| 65 | + ->join( |
|
| 66 | + array('b' => 'icinga_hosts'), |
|
| 67 | + 'b.host_object_id=a.object_id', |
|
| 68 | + array('display_name' => 'b.display_name')) |
|
| 69 | + ->where("a.name1 = '$name'"); |
|
| 70 | + return $dbConn->fetchAll($query); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** Get host groups by name in IDO database |
|
| 74 | - * does not catch exceptions |
|
| 75 | - * @return array of objects ( name, id (object_id), display_name) |
|
| 76 | - */ |
|
| 77 | - public function getHostGroupByName($ip) |
|
| 78 | - { |
|
| 79 | - // 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 |
|
| 80 | - $dbConn = $this->getIdoDbConn(); |
|
| 81 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 82 | - // TODO : check for SQL injections |
|
| 83 | - $query=$dbConn->select() |
|
| 84 | - ->from( |
|
| 85 | - array('a' => 'icinga_objects'), |
|
| 86 | - array('name' => 'a.name1','id' => 'object_id')) |
|
| 87 | - ->join( |
|
| 88 | - array('b' => 'icinga_hostgroups'), |
|
| 89 | - 'b.hostgroup_object_id=a.object_id', |
|
| 90 | - array('display_name' => 'b.alias')) |
|
| 91 | - ->where("(a.name1 LIKE '%".$ip."%' OR b.alias LIKE '%".$ip."%') and a.is_active = 1"); |
|
| 92 | - return $dbConn->fetchAll($query); |
|
| 93 | - } |
|
| 73 | + /** Get host groups by name in IDO database |
|
| 74 | + * does not catch exceptions |
|
| 75 | + * @return array of objects ( name, id (object_id), display_name) |
|
| 76 | + */ |
|
| 77 | + public function getHostGroupByName($ip) |
|
| 78 | + { |
|
| 79 | + // 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 |
|
| 80 | + $dbConn = $this->getIdoDbConn(); |
|
| 81 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 82 | + // TODO : check for SQL injections |
|
| 83 | + $query=$dbConn->select() |
|
| 84 | + ->from( |
|
| 85 | + array('a' => 'icinga_objects'), |
|
| 86 | + array('name' => 'a.name1','id' => 'object_id')) |
|
| 87 | + ->join( |
|
| 88 | + array('b' => 'icinga_hostgroups'), |
|
| 89 | + 'b.hostgroup_object_id=a.object_id', |
|
| 90 | + array('display_name' => 'b.alias')) |
|
| 91 | + ->where("(a.name1 LIKE '%".$ip."%' OR b.alias LIKE '%".$ip."%') and a.is_active = 1"); |
|
| 92 | + return $dbConn->fetchAll($query); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** Get host IP (v4 and v6) by name in IDO database |
|
| 96 | - * does not catch exceptions |
|
| 97 | - * @return array ( name, display_name, ip4, ip6) |
|
| 98 | - */ |
|
| 99 | - public function getHostInfoByID($id) |
|
| 100 | - { |
|
| 101 | - if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
| 102 | - $dbConn = $this->getIdoDbConn(); |
|
| 103 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 104 | - $query=$dbConn->select() |
|
| 105 | - ->from( |
|
| 106 | - array('a' => 'icinga_objects'), |
|
| 107 | - array('name' => 'a.name1')) |
|
| 108 | - ->join( |
|
| 109 | - array('b' => 'icinga_hosts'), |
|
| 110 | - 'b.host_object_id=a.object_id', |
|
| 111 | - array('ip4' => 'b.address', 'ip6' => 'b.address6', 'display_name' => 'b.display_name')) |
|
| 112 | - ->where("a.object_id = '".$id."'"); |
|
| 113 | - return $dbConn->fetchRow($query); |
|
| 114 | - } |
|
| 95 | + /** Get host IP (v4 and v6) by name in IDO database |
|
| 96 | + * does not catch exceptions |
|
| 97 | + * @return array ( name, display_name, ip4, ip6) |
|
| 98 | + */ |
|
| 99 | + public function getHostInfoByID($id) |
|
| 100 | + { |
|
| 101 | + if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
| 102 | + $dbConn = $this->getIdoDbConn(); |
|
| 103 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 104 | + $query=$dbConn->select() |
|
| 105 | + ->from( |
|
| 106 | + array('a' => 'icinga_objects'), |
|
| 107 | + array('name' => 'a.name1')) |
|
| 108 | + ->join( |
|
| 109 | + array('b' => 'icinga_hosts'), |
|
| 110 | + 'b.host_object_id=a.object_id', |
|
| 111 | + array('ip4' => 'b.address', 'ip6' => 'b.address6', 'display_name' => 'b.display_name')) |
|
| 112 | + ->where("a.object_id = '".$id."'"); |
|
| 113 | + return $dbConn->fetchRow($query); |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - /** Get host by objectid in IDO database |
|
| 117 | - * does not catch exceptions |
|
| 118 | - * @return array of objects ( id, name, display_name, ip, ip6, ) |
|
| 119 | - */ |
|
| 120 | - public function getHostByObjectID($id) // TODO : duplicate of getHostInfoByID above |
|
| 121 | - { |
|
| 122 | - if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
| 123 | - $dbConn = $this->getIdoDbConn(); |
|
| 124 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 125 | - $query=$dbConn->select() |
|
| 126 | - ->from( |
|
| 127 | - array('a' => 'icinga_objects'), |
|
| 128 | - array('name' => 'a.name1','id' => 'a.object_id')) |
|
| 129 | - ->join( |
|
| 130 | - array('b' => 'icinga_hosts'), |
|
| 131 | - 'b.host_object_id=a.object_id', |
|
| 132 | - array('display_name' => 'b.display_name' , 'ip' => 'b.address', 'ip6' => 'b.address6')) |
|
| 133 | - ->where('a.object_id = ?',$id); |
|
| 134 | - return $dbConn->fetchRow($query); |
|
| 135 | - } |
|
| 116 | + /** Get host by objectid in IDO database |
|
| 117 | + * does not catch exceptions |
|
| 118 | + * @return array of objects ( id, name, display_name, ip, ip6, ) |
|
| 119 | + */ |
|
| 120 | + public function getHostByObjectID($id) // TODO : duplicate of getHostInfoByID above |
|
| 121 | + { |
|
| 122 | + if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
| 123 | + $dbConn = $this->getIdoDbConn(); |
|
| 124 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 125 | + $query=$dbConn->select() |
|
| 126 | + ->from( |
|
| 127 | + array('a' => 'icinga_objects'), |
|
| 128 | + array('name' => 'a.name1','id' => 'a.object_id')) |
|
| 129 | + ->join( |
|
| 130 | + array('b' => 'icinga_hosts'), |
|
| 131 | + 'b.host_object_id=a.object_id', |
|
| 132 | + array('display_name' => 'b.display_name' , 'ip' => 'b.address', 'ip6' => 'b.address6')) |
|
| 133 | + ->where('a.object_id = ?',$id); |
|
| 134 | + return $dbConn->fetchRow($query); |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - /** Get services from object ( host_object_id) in IDO database |
|
| 138 | - * does not catch exceptions |
|
| 139 | - * @param $id int object_id |
|
| 140 | - * @return array display_name (of service), service_object_id |
|
| 141 | - */ |
|
| 142 | - public function getServicesByHostid($id) |
|
| 143 | - { |
|
| 144 | - // 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 |
|
| 145 | - if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
| 146 | - $dbConn = $this->getIdoDbConn(); |
|
| 147 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 148 | - $query=$dbConn->select() |
|
| 149 | - ->from( |
|
| 150 | - array('s' => 'icinga_services'), |
|
| 151 | - array('name' => 's.display_name','id' => 's.service_object_id')) |
|
| 152 | - ->join( |
|
| 153 | - array('a' => 'icinga_objects'), |
|
| 154 | - 's.service_object_id=a.object_id', |
|
| 155 | - array('is_active'=>'a.is_active','name2'=>'a.name2')) |
|
| 156 | - ->where('s.host_object_id='.$id.' AND a.is_active = 1'); |
|
| 157 | - return $dbConn->fetchAll($query); |
|
| 158 | - } |
|
| 137 | + /** Get services from object ( host_object_id) in IDO database |
|
| 138 | + * does not catch exceptions |
|
| 139 | + * @param $id int object_id |
|
| 140 | + * @return array display_name (of service), service_object_id |
|
| 141 | + */ |
|
| 142 | + public function getServicesByHostid($id) |
|
| 143 | + { |
|
| 144 | + // 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 |
|
| 145 | + if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
| 146 | + $dbConn = $this->getIdoDbConn(); |
|
| 147 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 148 | + $query=$dbConn->select() |
|
| 149 | + ->from( |
|
| 150 | + array('s' => 'icinga_services'), |
|
| 151 | + array('name' => 's.display_name','id' => 's.service_object_id')) |
|
| 152 | + ->join( |
|
| 153 | + array('a' => 'icinga_objects'), |
|
| 154 | + 's.service_object_id=a.object_id', |
|
| 155 | + array('is_active'=>'a.is_active','name2'=>'a.name2')) |
|
| 156 | + ->where('s.host_object_id='.$id.' AND a.is_active = 1'); |
|
| 157 | + return $dbConn->fetchAll($query); |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | - /** Get services from hostgroup object id ( hostgroup_object_id) in IDO database |
|
| 161 | - * gets all hosts in hostgroup and return common services |
|
| 162 | - * does not catch exceptions |
|
| 163 | - * @param $id int object_id |
|
| 164 | - * @return array display_name (of service), service_object_id |
|
| 165 | - */ |
|
| 166 | - public function getServicesByHostGroupid($id) |
|
| 167 | - { |
|
| 168 | - if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
| 169 | - $dbConn = $this->getIdoDbConn(); |
|
| 170 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 171 | - $query=$dbConn->select() |
|
| 172 | - ->from( |
|
| 173 | - array('s' => 'icinga_hostgroup_members'), |
|
| 174 | - array('host_object_id' => 's.host_object_id')) |
|
| 175 | - ->join( |
|
| 176 | - array('a' => 'icinga_hostgroups'), |
|
| 177 | - 's.hostgroup_id=a.hostgroup_id', |
|
| 178 | - 'hostgroup_object_id') |
|
| 179 | - ->where('a.hostgroup_object_id='.$id); |
|
| 180 | - $hosts=$dbConn->fetchAll($query); |
|
| 181 | - $common_services=array(); |
|
| 182 | - $num_hosts=count($hosts); |
|
| 183 | - foreach ($hosts as $key => $host) |
|
| 184 | - { // For each host, get all services and add in common_services if not found or add counter |
|
| 185 | - $host_services=$this->getServicesByHostid($host->host_object_id); |
|
| 186 | - foreach($host_services as $service) |
|
| 187 | - { |
|
| 188 | - if (isset($common_services[$service->name2]['num'])) |
|
| 189 | - { |
|
| 190 | - $common_services[$service->name2]['num'] +=1; |
|
| 191 | - } |
|
| 192 | - else |
|
| 193 | - { |
|
| 194 | - $common_services[$service->name2]['num']=1; |
|
| 195 | - $common_services[$service->name2]['name']=$service->name; |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - $result=array(); |
|
| 160 | + /** Get services from hostgroup object id ( hostgroup_object_id) in IDO database |
|
| 161 | + * gets all hosts in hostgroup and return common services |
|
| 162 | + * does not catch exceptions |
|
| 163 | + * @param $id int object_id |
|
| 164 | + * @return array display_name (of service), service_object_id |
|
| 165 | + */ |
|
| 166 | + public function getServicesByHostGroupid($id) |
|
| 167 | + { |
|
| 168 | + if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
| 169 | + $dbConn = $this->getIdoDbConn(); |
|
| 170 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 171 | + $query=$dbConn->select() |
|
| 172 | + ->from( |
|
| 173 | + array('s' => 'icinga_hostgroup_members'), |
|
| 174 | + array('host_object_id' => 's.host_object_id')) |
|
| 175 | + ->join( |
|
| 176 | + array('a' => 'icinga_hostgroups'), |
|
| 177 | + 's.hostgroup_id=a.hostgroup_id', |
|
| 178 | + 'hostgroup_object_id') |
|
| 179 | + ->where('a.hostgroup_object_id='.$id); |
|
| 180 | + $hosts=$dbConn->fetchAll($query); |
|
| 181 | + $common_services=array(); |
|
| 182 | + $num_hosts=count($hosts); |
|
| 183 | + foreach ($hosts as $key => $host) |
|
| 184 | + { // For each host, get all services and add in common_services if not found or add counter |
|
| 185 | + $host_services=$this->getServicesByHostid($host->host_object_id); |
|
| 186 | + foreach($host_services as $service) |
|
| 187 | + { |
|
| 188 | + if (isset($common_services[$service->name2]['num'])) |
|
| 189 | + { |
|
| 190 | + $common_services[$service->name2]['num'] +=1; |
|
| 191 | + } |
|
| 192 | + else |
|
| 193 | + { |
|
| 194 | + $common_services[$service->name2]['num']=1; |
|
| 195 | + $common_services[$service->name2]['name']=$service->name; |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + $result=array(); |
|
| 200 | 200 | |
| 201 | - //print_r($common_services); |
|
| 202 | - foreach (array_keys($common_services) as $key) |
|
| 203 | - { |
|
| 204 | - if ($common_services[$key]['num'] == $num_hosts) |
|
| 205 | - { |
|
| 206 | - array_push($result,array($key,$common_services[$key]['name'])); |
|
| 207 | - } |
|
| 208 | - } |
|
| 201 | + //print_r($common_services); |
|
| 202 | + foreach (array_keys($common_services) as $key) |
|
| 203 | + { |
|
| 204 | + if ($common_services[$key]['num'] == $num_hosts) |
|
| 205 | + { |
|
| 206 | + array_push($result,array($key,$common_services[$key]['name'])); |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - return $result; |
|
| 211 | - } |
|
| 210 | + return $result; |
|
| 211 | + } |
|
| 212 | 212 | |
| 213 | - /** Get services object id by host name / service name in IDO database |
|
| 214 | - * does not catch exceptions |
|
| 215 | - * @param $hostname string host name |
|
| 216 | - * @param $name string service name |
|
| 217 | - * @return array service id |
|
| 218 | - */ |
|
| 219 | - public function getServiceIDByName($hostname,$name) |
|
| 220 | - { |
|
| 221 | - $dbConn = $this->getIdoDbConn(); |
|
| 222 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 213 | + /** Get services object id by host name / service name in IDO database |
|
| 214 | + * does not catch exceptions |
|
| 215 | + * @param $hostname string host name |
|
| 216 | + * @param $name string service name |
|
| 217 | + * @return array service id |
|
| 218 | + */ |
|
| 219 | + public function getServiceIDByName($hostname,$name) |
|
| 220 | + { |
|
| 221 | + $dbConn = $this->getIdoDbConn(); |
|
| 222 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 223 | 223 | |
| 224 | - if ($name == null) |
|
| 225 | - { |
|
| 226 | - return array(); |
|
| 227 | - } |
|
| 224 | + if ($name == null) |
|
| 225 | + { |
|
| 226 | + return array(); |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - $query=$dbConn->select() |
|
| 230 | - ->from( |
|
| 231 | - array('s' => 'icinga_services'), |
|
| 232 | - array('name' => 's.display_name','id' => 's.service_object_id')) |
|
| 233 | - ->join( |
|
| 234 | - array('a' => 'icinga_objects'), |
|
| 235 | - 's.service_object_id=a.object_id', |
|
| 236 | - 'is_active') |
|
| 237 | - ->where('a.name2=\''.$name.'\' AND a.name1=\''.$hostname.'\' AND a.is_active = 1'); |
|
| 229 | + $query=$dbConn->select() |
|
| 230 | + ->from( |
|
| 231 | + array('s' => 'icinga_services'), |
|
| 232 | + array('name' => 's.display_name','id' => 's.service_object_id')) |
|
| 233 | + ->join( |
|
| 234 | + array('a' => 'icinga_objects'), |
|
| 235 | + 's.service_object_id=a.object_id', |
|
| 236 | + 'is_active') |
|
| 237 | + ->where('a.name2=\''.$name.'\' AND a.name1=\''.$hostname.'\' AND a.is_active = 1'); |
|
| 238 | 238 | |
| 239 | - return $dbConn->fetchAll($query); |
|
| 240 | - } |
|
| 239 | + return $dbConn->fetchAll($query); |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | - /** Get object name from object_id in IDO database |
|
| 243 | - * does not catch exceptions |
|
| 244 | - * @param int $id object_id (default to null, used first if not null) |
|
| 245 | - * @return array name1 (host) name2 (service) |
|
| 246 | - */ |
|
| 247 | - public function getObjectNameByid($id) |
|
| 248 | - { |
|
| 249 | - // 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 |
|
| 250 | - if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
| 251 | - $dbConn = $this->getIdoDbConn(); |
|
| 252 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 242 | + /** Get object name from object_id in IDO database |
|
| 243 | + * does not catch exceptions |
|
| 244 | + * @param int $id object_id (default to null, used first if not null) |
|
| 245 | + * @return array name1 (host) name2 (service) |
|
| 246 | + */ |
|
| 247 | + public function getObjectNameByid($id) |
|
| 248 | + { |
|
| 249 | + // 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 |
|
| 250 | + if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
| 251 | + $dbConn = $this->getIdoDbConn(); |
|
| 252 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 253 | 253 | |
| 254 | - $query=$dbConn->select() |
|
| 255 | - ->from( |
|
| 256 | - array('a' => 'icinga_objects'), |
|
| 257 | - array('name1' => 'a.name1','name2' => 'a.name2')) |
|
| 258 | - ->where('a.object_id='.$id.' AND a.is_active = 1'); |
|
| 254 | + $query=$dbConn->select() |
|
| 255 | + ->from( |
|
| 256 | + array('a' => 'icinga_objects'), |
|
| 257 | + array('name1' => 'a.name1','name2' => 'a.name2')) |
|
| 258 | + ->where('a.object_id='.$id.' AND a.is_active = 1'); |
|
| 259 | 259 | |
| 260 | - return $dbConn->fetchRow($query); |
|
| 261 | - } |
|
| 260 | + return $dbConn->fetchRow($query); |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | 263 | |
| 264 | 264 | } |
| 265 | 265 | \ No newline at end of file |