@@ -7,396 +7,396 @@ |
||
| 7 | 7 | class Rule |
| 8 | 8 | { |
| 9 | 9 | |
| 10 | - /** @var Logging $logging logging class*/ |
|
| 11 | - protected $logging; |
|
| 10 | + /** @var Logging $logging logging class*/ |
|
| 11 | + protected $logging; |
|
| 12 | 12 | |
| 13 | - /** @var Trap $trapClass */ |
|
| 14 | - protected $trapClass; |
|
| 13 | + /** @var Trap $trapClass */ |
|
| 14 | + protected $trapClass; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Setup Rule Class |
|
| 18 | - * @param Trap $trapClass : To get logging class & plugin class |
|
| 19 | - */ |
|
| 20 | - function __construct($trapClass) |
|
| 21 | - { |
|
| 22 | - $this->trapClass=$trapClass; |
|
| 23 | - $this->logging=$trapClass->logging; |
|
| 24 | - } |
|
| 16 | + /** |
|
| 17 | + * Setup Rule Class |
|
| 18 | + * @param Trap $trapClass : To get logging class & plugin class |
|
| 19 | + */ |
|
| 20 | + function __construct($trapClass) |
|
| 21 | + { |
|
| 22 | + $this->trapClass=$trapClass; |
|
| 23 | + $this->logging=$trapClass->logging; |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | 27 | * Get full number |
| 28 | 28 | * @return array<number,string> |
| 29 | 29 | */ |
| 30 | - private function get_number($rule,&$item) |
|
| 31 | - { |
|
| 32 | - $item2=$item+1; |
|
| 33 | - while ( |
|
| 34 | - ($item2!=strlen($rule)) |
|
| 35 | - && (preg_match('/[\-0-9\.]/',$rule[$item2]))) |
|
| 36 | - { |
|
| 37 | - $item2++ ; |
|
| 38 | - } |
|
| 39 | - $val=substr($rule,$item,$item2-$item); |
|
| 40 | - $item=$item2; |
|
| 41 | - //echo "number ".$val."\n"; |
|
| 30 | + private function get_number($rule,&$item) |
|
| 31 | + { |
|
| 32 | + $item2=$item+1; |
|
| 33 | + while ( |
|
| 34 | + ($item2!=strlen($rule)) |
|
| 35 | + && (preg_match('/[\-0-9\.]/',$rule[$item2]))) |
|
| 36 | + { |
|
| 37 | + $item2++ ; |
|
| 38 | + } |
|
| 39 | + $val=substr($rule,$item,$item2-$item); |
|
| 40 | + $item=$item2; |
|
| 41 | + //echo "number ".$val."\n"; |
|
| 42 | 42 | |
| 43 | - return array(0,$val); |
|
| 44 | - } |
|
| 43 | + return array(0,$val); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - private function get_string($rule,&$item) |
|
| 47 | - { |
|
| 48 | - $item++; |
|
| 49 | - $item2=$this->eval_getNext($rule,$item,'"'); |
|
| 50 | - $val=substr($rule,$item,$item2-$item-1); |
|
| 51 | - $item=$item2; |
|
| 52 | - //echo "string : ".$val."\n"; |
|
| 53 | - return array(1,$val); |
|
| 46 | + private function get_string($rule,&$item) |
|
| 47 | + { |
|
| 48 | + $item++; |
|
| 49 | + $item2=$this->eval_getNext($rule,$item,'"'); |
|
| 50 | + $val=substr($rule,$item,$item2-$item-1); |
|
| 51 | + $item=$item2; |
|
| 52 | + //echo "string : ".$val."\n"; |
|
| 53 | + return array(1,$val); |
|
| 54 | 54 | |
| 55 | - } |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Parse elements inside () : jumps over "" and count parenthesis. |
|
| 59 | - * Ex : ( "test" != ")test" & (1==2) ) will return "test" != ")test" & (1==2) |
|
| 60 | - * @param string $rule : the current rule |
|
| 61 | - * @param int $item : actual position in rule |
|
| 62 | - * @throws Exception |
|
| 63 | - * @return string : everything inside parenthesis |
|
| 64 | - */ |
|
| 65 | - private function parse_parenthesis(string $rule,int &$item) : string |
|
| 66 | - { |
|
| 67 | - $item++; |
|
| 68 | - $start=$item; |
|
| 69 | - $parenthesis_count=0; |
|
| 70 | - while (($item < strlen($rule)) // Not end of string AND |
|
| 71 | - && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded () |
|
| 72 | - { |
|
| 73 | - if ($rule[$item] == '"' ) |
|
| 74 | - { // pass through string |
|
| 75 | - $item++; |
|
| 76 | - $item=$this->eval_getNext($rule,$item,'"'); |
|
| 77 | - } |
|
| 78 | - else{ |
|
| 79 | - if ($rule[$item] == '(') |
|
| 80 | - { |
|
| 81 | - $parenthesis_count++; |
|
| 82 | - } |
|
| 83 | - if ($rule[$item] == ')') |
|
| 84 | - { |
|
| 85 | - $parenthesis_count--; |
|
| 86 | - } |
|
| 87 | - $item++; |
|
| 88 | - } |
|
| 89 | - } |
|
| 57 | + /** |
|
| 58 | + * Parse elements inside () : jumps over "" and count parenthesis. |
|
| 59 | + * Ex : ( "test" != ")test" & (1==2) ) will return "test" != ")test" & (1==2) |
|
| 60 | + * @param string $rule : the current rule |
|
| 61 | + * @param int $item : actual position in rule |
|
| 62 | + * @throws Exception |
|
| 63 | + * @return string : everything inside parenthesis |
|
| 64 | + */ |
|
| 65 | + private function parse_parenthesis(string $rule,int &$item) : string |
|
| 66 | + { |
|
| 67 | + $item++; |
|
| 68 | + $start=$item; |
|
| 69 | + $parenthesis_count=0; |
|
| 70 | + while (($item < strlen($rule)) // Not end of string AND |
|
| 71 | + && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded () |
|
| 72 | + { |
|
| 73 | + if ($rule[$item] == '"' ) |
|
| 74 | + { // pass through string |
|
| 75 | + $item++; |
|
| 76 | + $item=$this->eval_getNext($rule,$item,'"'); |
|
| 77 | + } |
|
| 78 | + else{ |
|
| 79 | + if ($rule[$item] == '(') |
|
| 80 | + { |
|
| 81 | + $parenthesis_count++; |
|
| 82 | + } |
|
| 83 | + if ($rule[$item] == ')') |
|
| 84 | + { |
|
| 85 | + $parenthesis_count--; |
|
| 86 | + } |
|
| 87 | + $item++; |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - if ($item==strlen($rule)) {throw new Exception("no closing () in ".$rule ." at " .$item);} |
|
| 92 | - $val=substr($rule,$start,$item-$start); |
|
| 93 | - $item++; |
|
| 94 | - return $val; |
|
| 95 | - } |
|
| 91 | + if ($item==strlen($rule)) {throw new Exception("no closing () in ".$rule ." at " .$item);} |
|
| 92 | + $val=substr($rule,$start,$item-$start); |
|
| 93 | + $item++; |
|
| 94 | + return $val; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Get and eval a grouped condition - ex : (1==1) |
|
| 100 | - * @param string $rule |
|
| 101 | - * @param int $item |
|
| 102 | - * @return array |
|
| 103 | - */ |
|
| 104 | - private function get_group(string $rule,int &$item) : array |
|
| 105 | - { |
|
| 106 | - // gets eveything inside parenthesis |
|
| 107 | - $val=$this->parse_parenthesis($rule, $item); |
|
| 108 | - // Returns boolean with evaluation of all inside parenthesis |
|
| 109 | - $start=0; |
|
| 110 | - return array(2,$this->evaluation($val,$start)); |
|
| 111 | - } |
|
| 98 | + /** |
|
| 99 | + * Get and eval a grouped condition - ex : (1==1) |
|
| 100 | + * @param string $rule |
|
| 101 | + * @param int $item |
|
| 102 | + * @return array |
|
| 103 | + */ |
|
| 104 | + private function get_group(string $rule,int &$item) : array |
|
| 105 | + { |
|
| 106 | + // gets eveything inside parenthesis |
|
| 107 | + $val=$this->parse_parenthesis($rule, $item); |
|
| 108 | + // Returns boolean with evaluation of all inside parenthesis |
|
| 109 | + $start=0; |
|
| 110 | + return array(2,$this->evaluation($val,$start)); |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - private function get_function(string $rule,int &$item) : array |
|
| 114 | - { |
|
| 115 | - // function is : __function(param1,param2...) |
|
| 116 | - $start=$item; |
|
| 117 | - while (($item < strlen($rule)) && ($rule[$item] != '(' )) // Not end of string AND not opening '(' |
|
| 118 | - { |
|
| 119 | - $item++; |
|
| 120 | - } |
|
| 121 | - if ($item==strlen($rule)) {throw new Exception("no opening () for function in ".$rule ." at " .$item);} |
|
| 113 | + private function get_function(string $rule,int &$item) : array |
|
| 114 | + { |
|
| 115 | + // function is : __function(param1,param2...) |
|
| 116 | + $start=$item; |
|
| 117 | + while (($item < strlen($rule)) && ($rule[$item] != '(' )) // Not end of string AND not opening '(' |
|
| 118 | + { |
|
| 119 | + $item++; |
|
| 120 | + } |
|
| 121 | + if ($item==strlen($rule)) {throw new Exception("no opening () for function in ".$rule ." at " .$item);} |
|
| 122 | 122 | |
| 123 | - // get parameters between parenthesis |
|
| 123 | + // get parameters between parenthesis |
|
| 124 | 124 | |
| 125 | - $this->parse_parenthesis($rule, $item); |
|
| 125 | + $this->parse_parenthesis($rule, $item); |
|
| 126 | 126 | |
| 127 | - $val=substr($rule,$start,$item-$start); |
|
| 127 | + $val=substr($rule,$start,$item-$start); |
|
| 128 | 128 | |
| 129 | - $this->logging->log('got function ' . $val,DEBUG); |
|
| 129 | + $this->logging->log('got function ' . $val,DEBUG); |
|
| 130 | 130 | |
| 131 | - return array(2,$this->trapClass->pluginClass->evaluateFunctionString($val)); |
|
| 131 | + return array(2,$this->trapClass->pluginClass->evaluateFunctionString($val)); |
|
| 132 | 132 | |
| 133 | - } |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - protected function eval_getElement($rule,&$item) |
|
| 136 | - { |
|
| 137 | - if ($item >= strlen($rule)) |
|
| 138 | - { |
|
| 139 | - throw new Exception("Early end of string ".$rule ." at " .$item ); |
|
| 140 | - } |
|
| 141 | - while ($rule[$item]==' ') $item++; |
|
| 142 | - if (preg_match('/[\-0-9\.]/',$rule[$item])) |
|
| 143 | - { // number |
|
| 144 | - return $this->get_number($rule, $item); |
|
| 145 | - } |
|
| 146 | - if ($rule[$item] == '"') |
|
| 147 | - { // string |
|
| 148 | - return $this->get_string($rule, $item); |
|
| 149 | - } |
|
| 135 | + protected function eval_getElement($rule,&$item) |
|
| 136 | + { |
|
| 137 | + if ($item >= strlen($rule)) |
|
| 138 | + { |
|
| 139 | + throw new Exception("Early end of string ".$rule ." at " .$item ); |
|
| 140 | + } |
|
| 141 | + while ($rule[$item]==' ') $item++; |
|
| 142 | + if (preg_match('/[\-0-9\.]/',$rule[$item])) |
|
| 143 | + { // number |
|
| 144 | + return $this->get_number($rule, $item); |
|
| 145 | + } |
|
| 146 | + if ($rule[$item] == '"') |
|
| 147 | + { // string |
|
| 148 | + return $this->get_string($rule, $item); |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - if ($rule[$item] == '(') |
|
| 152 | - { // grouping |
|
| 153 | - return $this->get_group($rule, $item); |
|
| 154 | - } |
|
| 155 | - if ($rule[$item] == '_') |
|
| 156 | - { // function |
|
| 157 | - return $this->get_function($rule, $item); |
|
| 158 | - } |
|
| 159 | - throw new Exception("number/string not found in ".$rule ." at " .$item . ' : ' .$rule[$item]); |
|
| 151 | + if ($rule[$item] == '(') |
|
| 152 | + { // grouping |
|
| 153 | + return $this->get_group($rule, $item); |
|
| 154 | + } |
|
| 155 | + if ($rule[$item] == '_') |
|
| 156 | + { // function |
|
| 157 | + return $this->get_function($rule, $item); |
|
| 158 | + } |
|
| 159 | + throw new Exception("number/string not found in ".$rule ." at " .$item . ' : ' .$rule[$item]); |
|
| 160 | 160 | |
| 161 | - } |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | - protected function eval_getNext($rule,$item,$tok) |
|
| 164 | - { |
|
| 165 | - while ( |
|
| 166 | - ($rule[$item] != $tok ) |
|
| 167 | - && ($item < strlen($rule))) |
|
| 168 | - { |
|
| 169 | - $item++; |
|
| 170 | - } |
|
| 171 | - if ($item==strlen($rule)) { |
|
| 172 | - throw new Exception("closing '".$tok."' not found in ".$rule ." at " .$item); |
|
| 173 | - } |
|
| 174 | - return $item+1; |
|
| 175 | - } |
|
| 163 | + protected function eval_getNext($rule,$item,$tok) |
|
| 164 | + { |
|
| 165 | + while ( |
|
| 166 | + ($rule[$item] != $tok ) |
|
| 167 | + && ($item < strlen($rule))) |
|
| 168 | + { |
|
| 169 | + $item++; |
|
| 170 | + } |
|
| 171 | + if ($item==strlen($rule)) { |
|
| 172 | + throw new Exception("closing '".$tok."' not found in ".$rule ." at " .$item); |
|
| 173 | + } |
|
| 174 | + return $item+1; |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - protected function eval_getOper($rule,&$item) |
|
| 178 | - { |
|
| 179 | - while ($rule[$item]==' ') $item++; |
|
| 180 | - switch ($rule[$item]) |
|
| 181 | - { |
|
| 182 | - case '<': |
|
| 183 | - if ($rule[$item+1]=='=') { $item+=2; return array(0,"<=");} |
|
| 184 | - $item++; return array(0,"<"); |
|
| 185 | - case '>': |
|
| 186 | - if ($rule[$item+1]=='=') { $item+=2; return array(0,">=");} |
|
| 187 | - $item++; return array(0,">"); |
|
| 188 | - case '=': |
|
| 189 | - $item++; return array(0,"="); |
|
| 190 | - case '!': |
|
| 191 | - if ($rule[$item+1]=='=') { $item+=2; return array(0,"!=");} |
|
| 192 | - throw new Exception("Erreur in expr - incorrect operator '!' found in ".$rule ." at " .$item); |
|
| 193 | - case '~': |
|
| 194 | - $item++; return array(0,"~"); |
|
| 195 | - case '|': |
|
| 196 | - $item++; return array(1,"|"); |
|
| 197 | - case '&': |
|
| 198 | - $item++; return array(1,"&"); |
|
| 199 | - default : |
|
| 200 | - throw new Exception("Erreur in expr - operator not found in ".$rule ." at " .$item); |
|
| 201 | - } |
|
| 202 | - } |
|
| 177 | + protected function eval_getOper($rule,&$item) |
|
| 178 | + { |
|
| 179 | + while ($rule[$item]==' ') $item++; |
|
| 180 | + switch ($rule[$item]) |
|
| 181 | + { |
|
| 182 | + case '<': |
|
| 183 | + if ($rule[$item+1]=='=') { $item+=2; return array(0,"<=");} |
|
| 184 | + $item++; return array(0,"<"); |
|
| 185 | + case '>': |
|
| 186 | + if ($rule[$item+1]=='=') { $item+=2; return array(0,">=");} |
|
| 187 | + $item++; return array(0,">"); |
|
| 188 | + case '=': |
|
| 189 | + $item++; return array(0,"="); |
|
| 190 | + case '!': |
|
| 191 | + if ($rule[$item+1]=='=') { $item+=2; return array(0,"!=");} |
|
| 192 | + throw new Exception("Erreur in expr - incorrect operator '!' found in ".$rule ." at " .$item); |
|
| 193 | + case '~': |
|
| 194 | + $item++; return array(0,"~"); |
|
| 195 | + case '|': |
|
| 196 | + $item++; return array(1,"|"); |
|
| 197 | + case '&': |
|
| 198 | + $item++; return array(1,"&"); |
|
| 199 | + default : |
|
| 200 | + throw new Exception("Erreur in expr - operator not found in ".$rule ." at " .$item); |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - private function check_negate_first($rule,&$item) |
|
| 205 | - { |
|
| 206 | - if ( $rule[$item] == '!') // If '!' found, negate next expression. |
|
| 207 | - { |
|
| 208 | - $item++; |
|
| 209 | - return true; |
|
| 210 | - } |
|
| 211 | - else |
|
| 212 | - { |
|
| 213 | - return false; |
|
| 214 | - } |
|
| 215 | - } |
|
| 204 | + private function check_negate_first($rule,&$item) |
|
| 205 | + { |
|
| 206 | + if ( $rule[$item] == '!') // If '!' found, negate next expression. |
|
| 207 | + { |
|
| 208 | + $item++; |
|
| 209 | + return true; |
|
| 210 | + } |
|
| 211 | + else |
|
| 212 | + { |
|
| 213 | + return false; |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | 216 | |
| 217 | - private function do_compare($val1,$val2,$comp,$negate) |
|
| 218 | - { |
|
| 219 | - switch ($comp){ |
|
| 220 | - case '<': $retVal= ($val1 < $val2); break; |
|
| 221 | - case '<=': $retVal= ($val1 <= $val2); break; |
|
| 222 | - case '>': $retVal= ($val1 > $val2); break; |
|
| 223 | - case '>=': $retVal= ($val1 >= $val2); break; |
|
| 224 | - case '=': $retVal= ($val1 == $val2); break; |
|
| 225 | - case '!=': $retVal= ($val1 != $val2); break; |
|
| 226 | - case '~': $retVal= (preg_match('/'.preg_replace('/"/','',$val2).'/',$val1)); break; |
|
| 227 | - case '|': $retVal= ($val1 || $val2); break; |
|
| 228 | - case '&': $retVal= ($val1 && $val2); break; |
|
| 229 | - default: throw new Exception("Error in expression - unknown comp : ".$comp); |
|
| 230 | - } |
|
| 231 | - if ($negate === true) $retVal = ! $retVal; // Inverse result if negate before expression |
|
| 217 | + private function do_compare($val1,$val2,$comp,$negate) |
|
| 218 | + { |
|
| 219 | + switch ($comp){ |
|
| 220 | + case '<': $retVal= ($val1 < $val2); break; |
|
| 221 | + case '<=': $retVal= ($val1 <= $val2); break; |
|
| 222 | + case '>': $retVal= ($val1 > $val2); break; |
|
| 223 | + case '>=': $retVal= ($val1 >= $val2); break; |
|
| 224 | + case '=': $retVal= ($val1 == $val2); break; |
|
| 225 | + case '!=': $retVal= ($val1 != $val2); break; |
|
| 226 | + case '~': $retVal= (preg_match('/'.preg_replace('/"/','',$val2).'/',$val1)); break; |
|
| 227 | + case '|': $retVal= ($val1 || $val2); break; |
|
| 228 | + case '&': $retVal= ($val1 && $val2); break; |
|
| 229 | + default: throw new Exception("Error in expression - unknown comp : ".$comp); |
|
| 230 | + } |
|
| 231 | + if ($negate === true) $retVal = ! $retVal; // Inverse result if negate before expression |
|
| 232 | 232 | |
| 233 | - return $retVal; |
|
| 234 | - } |
|
| 233 | + return $retVal; |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | - /** Evaluation : makes token and evaluate. |
|
| 237 | - * Public function for expressions testing |
|
| 238 | - * accepts : < > = <= >= != (typec = 0) |
|
| 239 | - * operators : & | (typec=1) |
|
| 240 | - * with : integers/float (type 0) or strings "" (type 1) or results (type 2) |
|
| 241 | - * comparison int vs strings will return null (error) |
|
| 242 | - * return : bool or null on error |
|
| 243 | - */ |
|
| 244 | - public function evaluation($rule,&$item) |
|
| 245 | - { |
|
| 246 | - //echo "Evaluation of ".substr($rule,$item)."\n"; |
|
| 247 | - $negate=$this->check_negate_first($rule, $item); |
|
| 248 | - // First element : number, string or () |
|
| 249 | - list($type1,$val1) = $this->eval_getElement($rule,$item); |
|
| 250 | - //echo "Elmt1: ".$val1."/".$type1." : ".substr($rule,$item)."\n"; |
|
| 236 | + /** Evaluation : makes token and evaluate. |
|
| 237 | + * Public function for expressions testing |
|
| 238 | + * accepts : < > = <= >= != (typec = 0) |
|
| 239 | + * operators : & | (typec=1) |
|
| 240 | + * with : integers/float (type 0) or strings "" (type 1) or results (type 2) |
|
| 241 | + * comparison int vs strings will return null (error) |
|
| 242 | + * return : bool or null on error |
|
| 243 | + */ |
|
| 244 | + public function evaluation($rule,&$item) |
|
| 245 | + { |
|
| 246 | + //echo "Evaluation of ".substr($rule,$item)."\n"; |
|
| 247 | + $negate=$this->check_negate_first($rule, $item); |
|
| 248 | + // First element : number, string or () |
|
| 249 | + list($type1,$val1) = $this->eval_getElement($rule,$item); |
|
| 250 | + //echo "Elmt1: ".$val1."/".$type1." : ".substr($rule,$item)."\n"; |
|
| 251 | 251 | |
| 252 | - if ($item==strlen($rule)) // If only element, return value, but only boolean |
|
| 253 | - { |
|
| 254 | - if ($type1 != 2) throw new Exception("Cannot use num/string as boolean : ".$rule); |
|
| 255 | - if ($negate === true) $val1= ! $val1; |
|
| 256 | - return $val1; |
|
| 257 | - } |
|
| 252 | + if ($item==strlen($rule)) // If only element, return value, but only boolean |
|
| 253 | + { |
|
| 254 | + if ($type1 != 2) throw new Exception("Cannot use num/string as boolean : ".$rule); |
|
| 255 | + if ($negate === true) $val1= ! $val1; |
|
| 256 | + return $val1; |
|
| 257 | + } |
|
| 258 | 258 | |
| 259 | - // Second element : operator |
|
| 260 | - list($typec,$comp) = $this->eval_getOper($rule,$item); |
|
| 261 | - //echo "Comp : ".$comp." : ".substr($rule,$item)."\n"; |
|
| 259 | + // Second element : operator |
|
| 260 | + list($typec,$comp) = $this->eval_getOper($rule,$item); |
|
| 261 | + //echo "Comp : ".$comp." : ".substr($rule,$item)."\n"; |
|
| 262 | 262 | |
| 263 | - // Third element : number, string or () |
|
| 264 | - if ( $rule[$item] == '!') // starts with a ! so evaluate whats next |
|
| 265 | - { |
|
| 266 | - $item++; |
|
| 267 | - if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule); |
|
| 268 | - $val2= ! $this->evaluation($rule,$item); |
|
| 269 | - $type2=2; // result is a boolean |
|
| 270 | - } |
|
| 271 | - else |
|
| 272 | - { |
|
| 273 | - list($type2,$val2) = $this->eval_getElement($rule,$item); |
|
| 274 | - } |
|
| 275 | - //echo "Elmt2: ".$val2."/".$type2." : ".substr($rule,$item)."\n"; |
|
| 263 | + // Third element : number, string or () |
|
| 264 | + if ( $rule[$item] == '!') // starts with a ! so evaluate whats next |
|
| 265 | + { |
|
| 266 | + $item++; |
|
| 267 | + if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule); |
|
| 268 | + $val2= ! $this->evaluation($rule,$item); |
|
| 269 | + $type2=2; // result is a boolean |
|
| 270 | + } |
|
| 271 | + else |
|
| 272 | + { |
|
| 273 | + list($type2,$val2) = $this->eval_getElement($rule,$item); |
|
| 274 | + } |
|
| 275 | + //echo "Elmt2: ".$val2."/".$type2." : ".substr($rule,$item)."\n"; |
|
| 276 | 276 | |
| 277 | - if ($type1!=$type2) // cannot compare different types |
|
| 278 | - { |
|
| 279 | - throw new Exception("Cannot compare string & number : ".$rule); |
|
| 280 | - } |
|
| 281 | - if ($typec==1 && $type1 !=2) // cannot use & or | with string/number |
|
| 282 | - { |
|
| 283 | - throw new Exception("Cannot use boolean operators with string & number : ".$rule); |
|
| 284 | - } |
|
| 277 | + if ($type1!=$type2) // cannot compare different types |
|
| 278 | + { |
|
| 279 | + throw new Exception("Cannot compare string & number : ".$rule); |
|
| 280 | + } |
|
| 281 | + if ($typec==1 && $type1 !=2) // cannot use & or | with string/number |
|
| 282 | + { |
|
| 283 | + throw new Exception("Cannot use boolean operators with string & number : ".$rule); |
|
| 284 | + } |
|
| 285 | 285 | |
| 286 | - $retVal = $this->do_compare($val1, $val2, $comp, $negate); |
|
| 286 | + $retVal = $this->do_compare($val1, $val2, $comp, $negate); |
|
| 287 | 287 | |
| 288 | - if ($item==strlen($rule)) return $retVal; // End of string : return evaluation |
|
| 289 | - // check for logical operator : |
|
| 290 | - switch ($rule[$item]) |
|
| 291 | - { |
|
| 292 | - case '|': $item++; return ($retVal || $this->evaluation($rule,$item) ); |
|
| 293 | - case '&': $item++; return ($retVal && $this->evaluation($rule,$item) ); |
|
| 288 | + if ($item==strlen($rule)) return $retVal; // End of string : return evaluation |
|
| 289 | + // check for logical operator : |
|
| 290 | + switch ($rule[$item]) |
|
| 291 | + { |
|
| 292 | + case '|': $item++; return ($retVal || $this->evaluation($rule,$item) ); |
|
| 293 | + case '&': $item++; return ($retVal && $this->evaluation($rule,$item) ); |
|
| 294 | 294 | |
| 295 | - default: throw new Exception("Erreur in expr - garbadge at end of expression : ".$rule[$item]); |
|
| 296 | - } |
|
| 297 | - } |
|
| 295 | + default: throw new Exception("Erreur in expr - garbadge at end of expression : ".$rule[$item]); |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - // Remove all whitespaces (when not quoted) |
|
| 300 | - public function eval_cleanup($rule) |
|
| 301 | - { |
|
| 302 | - $item=0; |
|
| 303 | - $rule2=''; |
|
| 304 | - while ($item < strlen($rule)) |
|
| 305 | - { |
|
| 306 | - if ($rule[$item]==' ') { $item++; continue; } |
|
| 307 | - if ($rule[$item]=='"') |
|
| 308 | - { |
|
| 309 | - $rule2.=$rule[$item]; |
|
| 310 | - $item++; |
|
| 311 | - while (($item < strlen($rule)) && ($rule[$item]!='"') ) |
|
| 312 | - { |
|
| 313 | - $rule2.=$rule[$item]; |
|
| 314 | - $item++; |
|
| 315 | - } |
|
| 316 | - if ($item == strlen ($rule)) throw new Exception("closing '\"' not found in ".$rule ." at " .$item); |
|
| 317 | - $rule2.=$rule[$item]; |
|
| 318 | - $item++; |
|
| 319 | - continue; |
|
| 320 | - } |
|
| 299 | + // Remove all whitespaces (when not quoted) |
|
| 300 | + public function eval_cleanup($rule) |
|
| 301 | + { |
|
| 302 | + $item=0; |
|
| 303 | + $rule2=''; |
|
| 304 | + while ($item < strlen($rule)) |
|
| 305 | + { |
|
| 306 | + if ($rule[$item]==' ') { $item++; continue; } |
|
| 307 | + if ($rule[$item]=='"') |
|
| 308 | + { |
|
| 309 | + $rule2.=$rule[$item]; |
|
| 310 | + $item++; |
|
| 311 | + while (($item < strlen($rule)) && ($rule[$item]!='"') ) |
|
| 312 | + { |
|
| 313 | + $rule2.=$rule[$item]; |
|
| 314 | + $item++; |
|
| 315 | + } |
|
| 316 | + if ($item == strlen ($rule)) throw new Exception("closing '\"' not found in ".$rule ." at " .$item); |
|
| 317 | + $rule2.=$rule[$item]; |
|
| 318 | + $item++; |
|
| 319 | + continue; |
|
| 320 | + } |
|
| 321 | 321 | |
| 322 | - $rule2.=$rule[$item]; |
|
| 323 | - $item++; |
|
| 324 | - } |
|
| 322 | + $rule2.=$rule[$item]; |
|
| 323 | + $item++; |
|
| 324 | + } |
|
| 325 | 325 | |
| 326 | - return $rule2; |
|
| 327 | - } |
|
| 326 | + return $rule2; |
|
| 327 | + } |
|
| 328 | 328 | |
| 329 | 329 | |
| 330 | - /** |
|
| 331 | - * Get '*' or '**' and transform in [0-9]+ or .* in return string |
|
| 332 | - * @param string $oid OID in normal or regexp format. '*' will be escaped ('\*') |
|
| 333 | - * @return string correct regexp format |
|
| 334 | - */ |
|
| 335 | - public function regexp_eval(string &$oid) |
|
| 336 | - { |
|
| 337 | - // ** replaced by .* |
|
| 338 | - $oidR=preg_replace('/\*\*/', '.*', $oid); |
|
| 339 | - // * replaced by [0-9]+ |
|
| 340 | - $oidR=preg_replace('/\*/', '[0-9]+', $oidR); |
|
| 330 | + /** |
|
| 331 | + * Get '*' or '**' and transform in [0-9]+ or .* in return string |
|
| 332 | + * @param string $oid OID in normal or regexp format. '*' will be escaped ('\*') |
|
| 333 | + * @return string correct regexp format |
|
| 334 | + */ |
|
| 335 | + public function regexp_eval(string &$oid) |
|
| 336 | + { |
|
| 337 | + // ** replaced by .* |
|
| 338 | + $oidR=preg_replace('/\*\*/', '.*', $oid); |
|
| 339 | + // * replaced by [0-9]+ |
|
| 340 | + $oidR=preg_replace('/\*/', '[0-9]+', $oidR); |
|
| 341 | 341 | |
| 342 | - // replace * with \* in oid for preg_replace |
|
| 343 | - $oid=preg_replace('/\*/', '\*', $oid); |
|
| 342 | + // replace * with \* in oid for preg_replace |
|
| 343 | + $oid=preg_replace('/\*/', '\*', $oid); |
|
| 344 | 344 | |
| 345 | - $this->logging->log('Regexp eval : '.$oid.' / '.$oidR,DEBUG ); |
|
| 345 | + $this->logging->log('Regexp eval : '.$oid.' / '.$oidR,DEBUG ); |
|
| 346 | 346 | |
| 347 | - return $oidR; |
|
| 348 | - } |
|
| 347 | + return $oidR; |
|
| 348 | + } |
|
| 349 | 349 | |
| 350 | 350 | |
| 351 | - /** Evaluation rule (uses eval_* functions recursively) |
|
| 352 | - * @param string $rule : rule ( _OID(.1.3.6.1.4.1.8072.2.3.2.1)=_OID(.1.3.6.1.2.1.1.3.0) ) |
|
| 353 | - * @param array $oidList : OIDs values to sustitute. |
|
| 354 | - * @return bool : true : rule match, false : rule don't match , throw exception on error. |
|
| 355 | - */ |
|
| 356 | - public function eval_rule($rule,$oidList) |
|
| 357 | - { |
|
| 358 | - if ($rule==null || $rule == '') // Empty rule is always true |
|
| 359 | - { |
|
| 360 | - return true; |
|
| 361 | - } |
|
| 362 | - $matches=array(); |
|
| 363 | - while (preg_match('/_OID\(([0-9\.\*]+)\)/',$rule,$matches) == 1) |
|
| 364 | - { |
|
| 365 | - $oid=$matches[1]; |
|
| 366 | - $found=0; |
|
| 367 | - // Test and transform regexp |
|
| 368 | - $oidR = $this->regexp_eval($oid); |
|
| 351 | + /** Evaluation rule (uses eval_* functions recursively) |
|
| 352 | + * @param string $rule : rule ( _OID(.1.3.6.1.4.1.8072.2.3.2.1)=_OID(.1.3.6.1.2.1.1.3.0) ) |
|
| 353 | + * @param array $oidList : OIDs values to sustitute. |
|
| 354 | + * @return bool : true : rule match, false : rule don't match , throw exception on error. |
|
| 355 | + */ |
|
| 356 | + public function eval_rule($rule,$oidList) |
|
| 357 | + { |
|
| 358 | + if ($rule==null || $rule == '') // Empty rule is always true |
|
| 359 | + { |
|
| 360 | + return true; |
|
| 361 | + } |
|
| 362 | + $matches=array(); |
|
| 363 | + while (preg_match('/_OID\(([0-9\.\*]+)\)/',$rule,$matches) == 1) |
|
| 364 | + { |
|
| 365 | + $oid=$matches[1]; |
|
| 366 | + $found=0; |
|
| 367 | + // Test and transform regexp |
|
| 368 | + $oidR = $this->regexp_eval($oid); |
|
| 369 | 369 | |
| 370 | - foreach($oidList as $val) |
|
| 371 | - { |
|
| 372 | - if (preg_match("/^$oidR$/",$val->oid) == 1) |
|
| 373 | - { |
|
| 374 | - if (!preg_match('/^-?[0-9]*\.?[0-9]+$/',$val->value)) |
|
| 375 | - { // If not a number, change " to ' and put " around it |
|
| 376 | - $val->value=preg_replace('/"/',"'",$val->value); |
|
| 377 | - $val->value='"'.$val->value.'"'; |
|
| 378 | - } |
|
| 379 | - $rep=0; |
|
| 380 | - $rule=preg_replace('/_OID\('.$oid.'\)/',$val->value,$rule,-1,$rep); |
|
| 381 | - if ($rep==0) |
|
| 382 | - { |
|
| 383 | - $this->logging->log("Error in rule_eval",WARN,''); |
|
| 384 | - return false; |
|
| 385 | - } |
|
| 386 | - $found=1; |
|
| 387 | - break; |
|
| 388 | - } |
|
| 389 | - } |
|
| 390 | - if ($found==0) |
|
| 391 | - { // OID not found : throw error |
|
| 392 | - throw new Exception('OID '.$oid.' not found in trap'); |
|
| 393 | - } |
|
| 394 | - } |
|
| 395 | - $item=0; |
|
| 396 | - $rule=$this->eval_cleanup($rule); |
|
| 397 | - $this->logging->log('Rule after clenup: '.$rule,INFO ); |
|
| 370 | + foreach($oidList as $val) |
|
| 371 | + { |
|
| 372 | + if (preg_match("/^$oidR$/",$val->oid) == 1) |
|
| 373 | + { |
|
| 374 | + if (!preg_match('/^-?[0-9]*\.?[0-9]+$/',$val->value)) |
|
| 375 | + { // If not a number, change " to ' and put " around it |
|
| 376 | + $val->value=preg_replace('/"/',"'",$val->value); |
|
| 377 | + $val->value='"'.$val->value.'"'; |
|
| 378 | + } |
|
| 379 | + $rep=0; |
|
| 380 | + $rule=preg_replace('/_OID\('.$oid.'\)/',$val->value,$rule,-1,$rep); |
|
| 381 | + if ($rep==0) |
|
| 382 | + { |
|
| 383 | + $this->logging->log("Error in rule_eval",WARN,''); |
|
| 384 | + return false; |
|
| 385 | + } |
|
| 386 | + $found=1; |
|
| 387 | + break; |
|
| 388 | + } |
|
| 389 | + } |
|
| 390 | + if ($found==0) |
|
| 391 | + { // OID not found : throw error |
|
| 392 | + throw new Exception('OID '.$oid.' not found in trap'); |
|
| 393 | + } |
|
| 394 | + } |
|
| 395 | + $item=0; |
|
| 396 | + $rule=$this->eval_cleanup($rule); |
|
| 397 | + $this->logging->log('Rule after clenup: '.$rule,INFO ); |
|
| 398 | 398 | |
| 399 | - return $this->evaluation($rule,$item); |
|
| 400 | - } |
|
| 399 | + return $this->evaluation($rule,$item); |
|
| 400 | + } |
|
| 401 | 401 | |
| 402 | 402 | } |
| 403 | 403 | \ No newline at end of file |
@@ -27,30 +27,30 @@ discard block |
||
| 27 | 27 | * Get full number |
| 28 | 28 | * @return array<number,string> |
| 29 | 29 | */ |
| 30 | - private function get_number($rule,&$item) |
|
| 30 | + private function get_number($rule, &$item) |
|
| 31 | 31 | { |
| 32 | - $item2=$item+1; |
|
| 32 | + $item2=$item + 1; |
|
| 33 | 33 | while ( |
| 34 | - ($item2!=strlen($rule)) |
|
| 35 | - && (preg_match('/[\-0-9\.]/',$rule[$item2]))) |
|
| 34 | + ($item2 != strlen($rule)) |
|
| 35 | + && (preg_match('/[\-0-9\.]/', $rule[$item2]))) |
|
| 36 | 36 | { |
| 37 | - $item2++ ; |
|
| 37 | + $item2++; |
|
| 38 | 38 | } |
| 39 | - $val=substr($rule,$item,$item2-$item); |
|
| 39 | + $val=substr($rule, $item, $item2 - $item); |
|
| 40 | 40 | $item=$item2; |
| 41 | 41 | //echo "number ".$val."\n"; |
| 42 | 42 | |
| 43 | - return array(0,$val); |
|
| 43 | + return array(0, $val); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - private function get_string($rule,&$item) |
|
| 46 | + private function get_string($rule, &$item) |
|
| 47 | 47 | { |
| 48 | 48 | $item++; |
| 49 | - $item2=$this->eval_getNext($rule,$item,'"'); |
|
| 50 | - $val=substr($rule,$item,$item2-$item-1); |
|
| 49 | + $item2=$this->eval_getNext($rule, $item, '"'); |
|
| 50 | + $val=substr($rule, $item, $item2 - $item - 1); |
|
| 51 | 51 | $item=$item2; |
| 52 | 52 | //echo "string : ".$val."\n"; |
| 53 | - return array(1,$val); |
|
| 53 | + return array(1, $val); |
|
| 54 | 54 | |
| 55 | 55 | } |
| 56 | 56 | |
@@ -62,20 +62,20 @@ discard block |
||
| 62 | 62 | * @throws Exception |
| 63 | 63 | * @return string : everything inside parenthesis |
| 64 | 64 | */ |
| 65 | - private function parse_parenthesis(string $rule,int &$item) : string |
|
| 65 | + private function parse_parenthesis(string $rule, int &$item) : string |
|
| 66 | 66 | { |
| 67 | 67 | $item++; |
| 68 | 68 | $start=$item; |
| 69 | 69 | $parenthesis_count=0; |
| 70 | 70 | while (($item < strlen($rule)) // Not end of string AND |
| 71 | - && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded () |
|
| 71 | + && (($rule[$item] != ')') || $parenthesis_count > 0)) // Closing ')' or embeded () |
|
| 72 | 72 | { |
| 73 | - if ($rule[$item] == '"' ) |
|
| 73 | + if ($rule[$item] == '"') |
|
| 74 | 74 | { // pass through string |
| 75 | 75 | $item++; |
| 76 | - $item=$this->eval_getNext($rule,$item,'"'); |
|
| 76 | + $item=$this->eval_getNext($rule, $item, '"'); |
|
| 77 | 77 | } |
| 78 | - else{ |
|
| 78 | + else { |
|
| 79 | 79 | if ($rule[$item] == '(') |
| 80 | 80 | { |
| 81 | 81 | $parenthesis_count++; |
@@ -88,8 +88,8 @@ discard block |
||
| 88 | 88 | } |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - if ($item==strlen($rule)) {throw new Exception("no closing () in ".$rule ." at " .$item);} |
|
| 92 | - $val=substr($rule,$start,$item-$start); |
|
| 91 | + if ($item == strlen($rule)) {throw new Exception("no closing () in ".$rule." at ".$item); } |
|
| 92 | + $val=substr($rule, $start, $item - $start); |
|
| 93 | 93 | $item++; |
| 94 | 94 | return $val; |
| 95 | 95 | } |
@@ -101,45 +101,45 @@ discard block |
||
| 101 | 101 | * @param int $item |
| 102 | 102 | * @return array |
| 103 | 103 | */ |
| 104 | - private function get_group(string $rule,int &$item) : array |
|
| 104 | + private function get_group(string $rule, int &$item) : array |
|
| 105 | 105 | { |
| 106 | 106 | // gets eveything inside parenthesis |
| 107 | 107 | $val=$this->parse_parenthesis($rule, $item); |
| 108 | 108 | // Returns boolean with evaluation of all inside parenthesis |
| 109 | 109 | $start=0; |
| 110 | - return array(2,$this->evaluation($val,$start)); |
|
| 110 | + return array(2, $this->evaluation($val, $start)); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - private function get_function(string $rule,int &$item) : array |
|
| 113 | + private function get_function(string $rule, int &$item) : array |
|
| 114 | 114 | { |
| 115 | 115 | // function is : __function(param1,param2...) |
| 116 | 116 | $start=$item; |
| 117 | - while (($item < strlen($rule)) && ($rule[$item] != '(' )) // Not end of string AND not opening '(' |
|
| 117 | + while (($item < strlen($rule)) && ($rule[$item] != '(')) // Not end of string AND not opening '(' |
|
| 118 | 118 | { |
| 119 | 119 | $item++; |
| 120 | 120 | } |
| 121 | - if ($item==strlen($rule)) {throw new Exception("no opening () for function in ".$rule ." at " .$item);} |
|
| 121 | + if ($item == strlen($rule)) {throw new Exception("no opening () for function in ".$rule." at ".$item); } |
|
| 122 | 122 | |
| 123 | 123 | // get parameters between parenthesis |
| 124 | 124 | |
| 125 | 125 | $this->parse_parenthesis($rule, $item); |
| 126 | 126 | |
| 127 | - $val=substr($rule,$start,$item-$start); |
|
| 127 | + $val=substr($rule, $start, $item - $start); |
|
| 128 | 128 | |
| 129 | - $this->logging->log('got function ' . $val,DEBUG); |
|
| 129 | + $this->logging->log('got function '.$val, DEBUG); |
|
| 130 | 130 | |
| 131 | - return array(2,$this->trapClass->pluginClass->evaluateFunctionString($val)); |
|
| 131 | + return array(2, $this->trapClass->pluginClass->evaluateFunctionString($val)); |
|
| 132 | 132 | |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - protected function eval_getElement($rule,&$item) |
|
| 135 | + protected function eval_getElement($rule, &$item) |
|
| 136 | 136 | { |
| 137 | 137 | if ($item >= strlen($rule)) |
| 138 | 138 | { |
| 139 | - throw new Exception("Early end of string ".$rule ." at " .$item ); |
|
| 139 | + throw new Exception("Early end of string ".$rule." at ".$item); |
|
| 140 | 140 | } |
| 141 | - while ($rule[$item]==' ') $item++; |
|
| 142 | - if (preg_match('/[\-0-9\.]/',$rule[$item])) |
|
| 141 | + while ($rule[$item] == ' ') $item++; |
|
| 142 | + if (preg_match('/[\-0-9\.]/', $rule[$item])) |
|
| 143 | 143 | { // number |
| 144 | 144 | return $this->get_number($rule, $item); |
| 145 | 145 | } |
@@ -156,54 +156,54 @@ discard block |
||
| 156 | 156 | { // function |
| 157 | 157 | return $this->get_function($rule, $item); |
| 158 | 158 | } |
| 159 | - throw new Exception("number/string not found in ".$rule ." at " .$item . ' : ' .$rule[$item]); |
|
| 159 | + throw new Exception("number/string not found in ".$rule." at ".$item.' : '.$rule[$item]); |
|
| 160 | 160 | |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - protected function eval_getNext($rule,$item,$tok) |
|
| 163 | + protected function eval_getNext($rule, $item, $tok) |
|
| 164 | 164 | { |
| 165 | 165 | while ( |
| 166 | - ($rule[$item] != $tok ) |
|
| 166 | + ($rule[$item] != $tok) |
|
| 167 | 167 | && ($item < strlen($rule))) |
| 168 | 168 | { |
| 169 | 169 | $item++; |
| 170 | 170 | } |
| 171 | - if ($item==strlen($rule)) { |
|
| 172 | - throw new Exception("closing '".$tok."' not found in ".$rule ." at " .$item); |
|
| 171 | + if ($item == strlen($rule)) { |
|
| 172 | + throw new Exception("closing '".$tok."' not found in ".$rule." at ".$item); |
|
| 173 | 173 | } |
| 174 | - return $item+1; |
|
| 174 | + return $item + 1; |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - protected function eval_getOper($rule,&$item) |
|
| 177 | + protected function eval_getOper($rule, &$item) |
|
| 178 | 178 | { |
| 179 | - while ($rule[$item]==' ') $item++; |
|
| 179 | + while ($rule[$item] == ' ') $item++; |
|
| 180 | 180 | switch ($rule[$item]) |
| 181 | 181 | { |
| 182 | 182 | case '<': |
| 183 | - if ($rule[$item+1]=='=') { $item+=2; return array(0,"<=");} |
|
| 184 | - $item++; return array(0,"<"); |
|
| 183 | + if ($rule[$item + 1] == '=') { $item+=2; return array(0, "<="); } |
|
| 184 | + $item++; return array(0, "<"); |
|
| 185 | 185 | case '>': |
| 186 | - if ($rule[$item+1]=='=') { $item+=2; return array(0,">=");} |
|
| 187 | - $item++; return array(0,">"); |
|
| 186 | + if ($rule[$item + 1] == '=') { $item+=2; return array(0, ">="); } |
|
| 187 | + $item++; return array(0, ">"); |
|
| 188 | 188 | case '=': |
| 189 | - $item++; return array(0,"="); |
|
| 189 | + $item++; return array(0, "="); |
|
| 190 | 190 | case '!': |
| 191 | - if ($rule[$item+1]=='=') { $item+=2; return array(0,"!=");} |
|
| 192 | - throw new Exception("Erreur in expr - incorrect operator '!' found in ".$rule ." at " .$item); |
|
| 191 | + if ($rule[$item + 1] == '=') { $item+=2; return array(0, "!="); } |
|
| 192 | + throw new Exception("Erreur in expr - incorrect operator '!' found in ".$rule." at ".$item); |
|
| 193 | 193 | case '~': |
| 194 | - $item++; return array(0,"~"); |
|
| 194 | + $item++; return array(0, "~"); |
|
| 195 | 195 | case '|': |
| 196 | - $item++; return array(1,"|"); |
|
| 196 | + $item++; return array(1, "|"); |
|
| 197 | 197 | case '&': |
| 198 | - $item++; return array(1,"&"); |
|
| 198 | + $item++; return array(1, "&"); |
|
| 199 | 199 | default : |
| 200 | - throw new Exception("Erreur in expr - operator not found in ".$rule ." at " .$item); |
|
| 200 | + throw new Exception("Erreur in expr - operator not found in ".$rule." at ".$item); |
|
| 201 | 201 | } |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - private function check_negate_first($rule,&$item) |
|
| 204 | + private function check_negate_first($rule, &$item) |
|
| 205 | 205 | { |
| 206 | - if ( $rule[$item] == '!') // If '!' found, negate next expression. |
|
| 206 | + if ($rule[$item] == '!') // If '!' found, negate next expression. |
|
| 207 | 207 | { |
| 208 | 208 | $item++; |
| 209 | 209 | return true; |
@@ -214,21 +214,21 @@ discard block |
||
| 214 | 214 | } |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - private function do_compare($val1,$val2,$comp,$negate) |
|
| 217 | + private function do_compare($val1, $val2, $comp, $negate) |
|
| 218 | 218 | { |
| 219 | - switch ($comp){ |
|
| 220 | - case '<': $retVal= ($val1 < $val2); break; |
|
| 221 | - case '<=': $retVal= ($val1 <= $val2); break; |
|
| 222 | - case '>': $retVal= ($val1 > $val2); break; |
|
| 223 | - case '>=': $retVal= ($val1 >= $val2); break; |
|
| 224 | - case '=': $retVal= ($val1 == $val2); break; |
|
| 225 | - case '!=': $retVal= ($val1 != $val2); break; |
|
| 226 | - case '~': $retVal= (preg_match('/'.preg_replace('/"/','',$val2).'/',$val1)); break; |
|
| 227 | - case '|': $retVal= ($val1 || $val2); break; |
|
| 228 | - case '&': $retVal= ($val1 && $val2); break; |
|
| 219 | + switch ($comp) { |
|
| 220 | + case '<': $retVal=($val1 < $val2); break; |
|
| 221 | + case '<=': $retVal=($val1 <= $val2); break; |
|
| 222 | + case '>': $retVal=($val1 > $val2); break; |
|
| 223 | + case '>=': $retVal=($val1 >= $val2); break; |
|
| 224 | + case '=': $retVal=($val1 == $val2); break; |
|
| 225 | + case '!=': $retVal=($val1 != $val2); break; |
|
| 226 | + case '~': $retVal=(preg_match('/'.preg_replace('/"/', '', $val2).'/', $val1)); break; |
|
| 227 | + case '|': $retVal=($val1 || $val2); break; |
|
| 228 | + case '&': $retVal=($val1 && $val2); break; |
|
| 229 | 229 | default: throw new Exception("Error in expression - unknown comp : ".$comp); |
| 230 | 230 | } |
| 231 | - if ($negate === true) $retVal = ! $retVal; // Inverse result if negate before expression |
|
| 231 | + if ($negate === true) $retVal=!$retVal; // Inverse result if negate before expression |
|
| 232 | 232 | |
| 233 | 233 | return $retVal; |
| 234 | 234 | } |
@@ -241,56 +241,56 @@ discard block |
||
| 241 | 241 | * comparison int vs strings will return null (error) |
| 242 | 242 | * return : bool or null on error |
| 243 | 243 | */ |
| 244 | - public function evaluation($rule,&$item) |
|
| 244 | + public function evaluation($rule, &$item) |
|
| 245 | 245 | { |
| 246 | 246 | //echo "Evaluation of ".substr($rule,$item)."\n"; |
| 247 | 247 | $negate=$this->check_negate_first($rule, $item); |
| 248 | 248 | // First element : number, string or () |
| 249 | - list($type1,$val1) = $this->eval_getElement($rule,$item); |
|
| 249 | + list($type1, $val1)=$this->eval_getElement($rule, $item); |
|
| 250 | 250 | //echo "Elmt1: ".$val1."/".$type1." : ".substr($rule,$item)."\n"; |
| 251 | 251 | |
| 252 | - if ($item==strlen($rule)) // If only element, return value, but only boolean |
|
| 252 | + if ($item == strlen($rule)) // If only element, return value, but only boolean |
|
| 253 | 253 | { |
| 254 | 254 | if ($type1 != 2) throw new Exception("Cannot use num/string as boolean : ".$rule); |
| 255 | - if ($negate === true) $val1= ! $val1; |
|
| 255 | + if ($negate === true) $val1=!$val1; |
|
| 256 | 256 | return $val1; |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | // Second element : operator |
| 260 | - list($typec,$comp) = $this->eval_getOper($rule,$item); |
|
| 260 | + list($typec, $comp)=$this->eval_getOper($rule, $item); |
|
| 261 | 261 | //echo "Comp : ".$comp." : ".substr($rule,$item)."\n"; |
| 262 | 262 | |
| 263 | 263 | // Third element : number, string or () |
| 264 | - if ( $rule[$item] == '!') // starts with a ! so evaluate whats next |
|
| 264 | + if ($rule[$item] == '!') // starts with a ! so evaluate whats next |
|
| 265 | 265 | { |
| 266 | 266 | $item++; |
| 267 | 267 | if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule); |
| 268 | - $val2= ! $this->evaluation($rule,$item); |
|
| 268 | + $val2=!$this->evaluation($rule, $item); |
|
| 269 | 269 | $type2=2; // result is a boolean |
| 270 | 270 | } |
| 271 | 271 | else |
| 272 | 272 | { |
| 273 | - list($type2,$val2) = $this->eval_getElement($rule,$item); |
|
| 273 | + list($type2, $val2)=$this->eval_getElement($rule, $item); |
|
| 274 | 274 | } |
| 275 | 275 | //echo "Elmt2: ".$val2."/".$type2." : ".substr($rule,$item)."\n"; |
| 276 | 276 | |
| 277 | - if ($type1!=$type2) // cannot compare different types |
|
| 277 | + if ($type1 != $type2) // cannot compare different types |
|
| 278 | 278 | { |
| 279 | 279 | throw new Exception("Cannot compare string & number : ".$rule); |
| 280 | 280 | } |
| 281 | - if ($typec==1 && $type1 !=2) // cannot use & or | with string/number |
|
| 281 | + if ($typec == 1 && $type1 != 2) // cannot use & or | with string/number |
|
| 282 | 282 | { |
| 283 | 283 | throw new Exception("Cannot use boolean operators with string & number : ".$rule); |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | - $retVal = $this->do_compare($val1, $val2, $comp, $negate); |
|
| 286 | + $retVal=$this->do_compare($val1, $val2, $comp, $negate); |
|
| 287 | 287 | |
| 288 | - if ($item==strlen($rule)) return $retVal; // End of string : return evaluation |
|
| 288 | + if ($item == strlen($rule)) return $retVal; // End of string : return evaluation |
|
| 289 | 289 | // check for logical operator : |
| 290 | 290 | switch ($rule[$item]) |
| 291 | 291 | { |
| 292 | - case '|': $item++; return ($retVal || $this->evaluation($rule,$item) ); |
|
| 293 | - case '&': $item++; return ($retVal && $this->evaluation($rule,$item) ); |
|
| 292 | + case '|': $item++; return ($retVal || $this->evaluation($rule, $item)); |
|
| 293 | + case '&': $item++; return ($retVal && $this->evaluation($rule, $item)); |
|
| 294 | 294 | |
| 295 | 295 | default: throw new Exception("Erreur in expr - garbadge at end of expression : ".$rule[$item]); |
| 296 | 296 | } |
@@ -303,17 +303,17 @@ discard block |
||
| 303 | 303 | $rule2=''; |
| 304 | 304 | while ($item < strlen($rule)) |
| 305 | 305 | { |
| 306 | - if ($rule[$item]==' ') { $item++; continue; } |
|
| 307 | - if ($rule[$item]=='"') |
|
| 306 | + if ($rule[$item] == ' ') { $item++; continue; } |
|
| 307 | + if ($rule[$item] == '"') |
|
| 308 | 308 | { |
| 309 | 309 | $rule2.=$rule[$item]; |
| 310 | 310 | $item++; |
| 311 | - while (($item < strlen($rule)) && ($rule[$item]!='"') ) |
|
| 311 | + while (($item < strlen($rule)) && ($rule[$item] != '"')) |
|
| 312 | 312 | { |
| 313 | 313 | $rule2.=$rule[$item]; |
| 314 | 314 | $item++; |
| 315 | 315 | } |
| 316 | - if ($item == strlen ($rule)) throw new Exception("closing '\"' not found in ".$rule ." at " .$item); |
|
| 316 | + if ($item == strlen($rule)) throw new Exception("closing '\"' not found in ".$rule." at ".$item); |
|
| 317 | 317 | $rule2.=$rule[$item]; |
| 318 | 318 | $item++; |
| 319 | 319 | continue; |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | // replace * with \* in oid for preg_replace |
| 343 | 343 | $oid=preg_replace('/\*/', '\*', $oid); |
| 344 | 344 | |
| 345 | - $this->logging->log('Regexp eval : '.$oid.' / '.$oidR,DEBUG ); |
|
| 345 | + $this->logging->log('Regexp eval : '.$oid.' / '.$oidR, DEBUG); |
|
| 346 | 346 | |
| 347 | 347 | return $oidR; |
| 348 | 348 | } |
@@ -353,50 +353,50 @@ discard block |
||
| 353 | 353 | * @param array $oidList : OIDs values to sustitute. |
| 354 | 354 | * @return bool : true : rule match, false : rule don't match , throw exception on error. |
| 355 | 355 | */ |
| 356 | - public function eval_rule($rule,$oidList) |
|
| 356 | + public function eval_rule($rule, $oidList) |
|
| 357 | 357 | { |
| 358 | - if ($rule==null || $rule == '') // Empty rule is always true |
|
| 358 | + if ($rule == null || $rule == '') // Empty rule is always true |
|
| 359 | 359 | { |
| 360 | 360 | return true; |
| 361 | 361 | } |
| 362 | 362 | $matches=array(); |
| 363 | - while (preg_match('/_OID\(([0-9\.\*]+)\)/',$rule,$matches) == 1) |
|
| 363 | + while (preg_match('/_OID\(([0-9\.\*]+)\)/', $rule, $matches) == 1) |
|
| 364 | 364 | { |
| 365 | 365 | $oid=$matches[1]; |
| 366 | 366 | $found=0; |
| 367 | 367 | // Test and transform regexp |
| 368 | - $oidR = $this->regexp_eval($oid); |
|
| 368 | + $oidR=$this->regexp_eval($oid); |
|
| 369 | 369 | |
| 370 | - foreach($oidList as $val) |
|
| 370 | + foreach ($oidList as $val) |
|
| 371 | 371 | { |
| 372 | - if (preg_match("/^$oidR$/",$val->oid) == 1) |
|
| 372 | + if (preg_match("/^$oidR$/", $val->oid) == 1) |
|
| 373 | 373 | { |
| 374 | - if (!preg_match('/^-?[0-9]*\.?[0-9]+$/',$val->value)) |
|
| 374 | + if (!preg_match('/^-?[0-9]*\.?[0-9]+$/', $val->value)) |
|
| 375 | 375 | { // If not a number, change " to ' and put " around it |
| 376 | - $val->value=preg_replace('/"/',"'",$val->value); |
|
| 376 | + $val->value=preg_replace('/"/', "'", $val->value); |
|
| 377 | 377 | $val->value='"'.$val->value.'"'; |
| 378 | 378 | } |
| 379 | 379 | $rep=0; |
| 380 | - $rule=preg_replace('/_OID\('.$oid.'\)/',$val->value,$rule,-1,$rep); |
|
| 381 | - if ($rep==0) |
|
| 380 | + $rule=preg_replace('/_OID\('.$oid.'\)/', $val->value, $rule, -1, $rep); |
|
| 381 | + if ($rep == 0) |
|
| 382 | 382 | { |
| 383 | - $this->logging->log("Error in rule_eval",WARN,''); |
|
| 383 | + $this->logging->log("Error in rule_eval", WARN, ''); |
|
| 384 | 384 | return false; |
| 385 | 385 | } |
| 386 | 386 | $found=1; |
| 387 | 387 | break; |
| 388 | 388 | } |
| 389 | 389 | } |
| 390 | - if ($found==0) |
|
| 390 | + if ($found == 0) |
|
| 391 | 391 | { // OID not found : throw error |
| 392 | 392 | throw new Exception('OID '.$oid.' not found in trap'); |
| 393 | 393 | } |
| 394 | 394 | } |
| 395 | 395 | $item=0; |
| 396 | 396 | $rule=$this->eval_cleanup($rule); |
| 397 | - $this->logging->log('Rule after clenup: '.$rule,INFO ); |
|
| 397 | + $this->logging->log('Rule after clenup: '.$rule, INFO); |
|
| 398 | 398 | |
| 399 | - return $this->evaluation($rule,$item); |
|
| 399 | + return $this->evaluation($rule, $item); |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | } |
| 403 | 403 | \ No newline at end of file |
@@ -68,14 +68,15 @@ discard block |
||
| 68 | 68 | $start=$item; |
| 69 | 69 | $parenthesis_count=0; |
| 70 | 70 | while (($item < strlen($rule)) // Not end of string AND |
| 71 | - && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded () |
|
| 71 | + && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) { |
|
| 72 | + // Closing ')' or embeded () |
|
| 72 | 73 | { |
| 73 | 74 | if ($rule[$item] == '"' ) |
| 74 | 75 | { // pass through string |
| 75 | 76 | $item++; |
| 77 | + } |
|
| 76 | 78 | $item=$this->eval_getNext($rule,$item,'"'); |
| 77 | - } |
|
| 78 | - else{ |
|
| 79 | + } else{ |
|
| 79 | 80 | if ($rule[$item] == '(') |
| 80 | 81 | { |
| 81 | 82 | $parenthesis_count++; |
@@ -114,9 +115,11 @@ discard block |
||
| 114 | 115 | { |
| 115 | 116 | // function is : __function(param1,param2...) |
| 116 | 117 | $start=$item; |
| 117 | - while (($item < strlen($rule)) && ($rule[$item] != '(' )) // Not end of string AND not opening '(' |
|
| 118 | + while (($item < strlen($rule)) && ($rule[$item] != '(' )) { |
|
| 119 | + // Not end of string AND not opening '(' |
|
| 118 | 120 | { |
| 119 | 121 | $item++; |
| 122 | + } |
|
| 120 | 123 | } |
| 121 | 124 | if ($item==strlen($rule)) {throw new Exception("no opening () for function in ".$rule ." at " .$item);} |
| 122 | 125 | |
@@ -138,7 +141,9 @@ discard block |
||
| 138 | 141 | { |
| 139 | 142 | throw new Exception("Early end of string ".$rule ." at " .$item ); |
| 140 | 143 | } |
| 141 | - while ($rule[$item]==' ') $item++; |
|
| 144 | + while ($rule[$item]==' ') { |
|
| 145 | + $item++; |
|
| 146 | + } |
|
| 142 | 147 | if (preg_match('/[\-0-9\.]/',$rule[$item])) |
| 143 | 148 | { // number |
| 144 | 149 | return $this->get_number($rule, $item); |
@@ -176,7 +181,9 @@ discard block |
||
| 176 | 181 | |
| 177 | 182 | protected function eval_getOper($rule,&$item) |
| 178 | 183 | { |
| 179 | - while ($rule[$item]==' ') $item++; |
|
| 184 | + while ($rule[$item]==' ') { |
|
| 185 | + $item++; |
|
| 186 | + } |
|
| 180 | 187 | switch ($rule[$item]) |
| 181 | 188 | { |
| 182 | 189 | case '<': |
@@ -203,12 +210,13 @@ discard block |
||
| 203 | 210 | |
| 204 | 211 | private function check_negate_first($rule,&$item) |
| 205 | 212 | { |
| 206 | - if ( $rule[$item] == '!') // If '!' found, negate next expression. |
|
| 213 | + if ( $rule[$item] == '!') { |
|
| 214 | + // If '!' found, negate next expression. |
|
| 207 | 215 | { |
| 208 | 216 | $item++; |
| 209 | - return true; |
|
| 210 | 217 | } |
| 211 | - else |
|
| 218 | + return true; |
|
| 219 | + } else |
|
| 212 | 220 | { |
| 213 | 221 | return false; |
| 214 | 222 | } |
@@ -228,7 +236,10 @@ discard block |
||
| 228 | 236 | case '&': $retVal= ($val1 && $val2); break; |
| 229 | 237 | default: throw new Exception("Error in expression - unknown comp : ".$comp); |
| 230 | 238 | } |
| 231 | - if ($negate === true) $retVal = ! $retVal; // Inverse result if negate before expression |
|
| 239 | + if ($negate === true) { |
|
| 240 | + $retVal = ! $retVal; |
|
| 241 | + } |
|
| 242 | + // Inverse result if negate before expression |
|
| 232 | 243 | |
| 233 | 244 | return $retVal; |
| 234 | 245 | } |
@@ -249,10 +260,14 @@ discard block |
||
| 249 | 260 | list($type1,$val1) = $this->eval_getElement($rule,$item); |
| 250 | 261 | //echo "Elmt1: ".$val1."/".$type1." : ".substr($rule,$item)."\n"; |
| 251 | 262 | |
| 252 | - if ($item==strlen($rule)) // If only element, return value, but only boolean |
|
| 263 | + if ($item==strlen($rule)) { |
|
| 264 | + // If only element, return value, but only boolean |
|
| 253 | 265 | { |
| 254 | 266 | if ($type1 != 2) throw new Exception("Cannot use num/string as boolean : ".$rule); |
| 255 | - if ($negate === true) $val1= ! $val1; |
|
| 267 | + } |
|
| 268 | + if ($negate === true) { |
|
| 269 | + $val1= ! $val1; |
|
| 270 | + } |
|
| 256 | 271 | return $val1; |
| 257 | 272 | } |
| 258 | 273 | |
@@ -261,31 +276,41 @@ discard block |
||
| 261 | 276 | //echo "Comp : ".$comp." : ".substr($rule,$item)."\n"; |
| 262 | 277 | |
| 263 | 278 | // Third element : number, string or () |
| 264 | - if ( $rule[$item] == '!') // starts with a ! so evaluate whats next |
|
| 279 | + if ( $rule[$item] == '!') { |
|
| 280 | + // starts with a ! so evaluate whats next |
|
| 265 | 281 | { |
| 266 | 282 | $item++; |
| 267 | - if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule); |
|
| 283 | + } |
|
| 284 | + if ($typec != 1) { |
|
| 285 | + throw new Exception("Mixing boolean and comparison : ".$rule); |
|
| 286 | + } |
|
| 268 | 287 | $val2= ! $this->evaluation($rule,$item); |
| 269 | 288 | $type2=2; // result is a boolean |
| 270 | - } |
|
| 271 | - else |
|
| 289 | + } else |
|
| 272 | 290 | { |
| 273 | 291 | list($type2,$val2) = $this->eval_getElement($rule,$item); |
| 274 | 292 | } |
| 275 | 293 | //echo "Elmt2: ".$val2."/".$type2." : ".substr($rule,$item)."\n"; |
| 276 | 294 | |
| 277 | - if ($type1!=$type2) // cannot compare different types |
|
| 295 | + if ($type1!=$type2) { |
|
| 296 | + // cannot compare different types |
|
| 278 | 297 | { |
| 279 | 298 | throw new Exception("Cannot compare string & number : ".$rule); |
| 280 | 299 | } |
| 281 | - if ($typec==1 && $type1 !=2) // cannot use & or | with string/number |
|
| 300 | + } |
|
| 301 | + if ($typec==1 && $type1 !=2) { |
|
| 302 | + // cannot use & or | with string/number |
|
| 282 | 303 | { |
| 283 | 304 | throw new Exception("Cannot use boolean operators with string & number : ".$rule); |
| 284 | 305 | } |
| 306 | + } |
|
| 285 | 307 | |
| 286 | 308 | $retVal = $this->do_compare($val1, $val2, $comp, $negate); |
| 287 | 309 | |
| 288 | - if ($item==strlen($rule)) return $retVal; // End of string : return evaluation |
|
| 310 | + if ($item==strlen($rule)) { |
|
| 311 | + return $retVal; |
|
| 312 | + } |
|
| 313 | + // End of string : return evaluation |
|
| 289 | 314 | // check for logical operator : |
| 290 | 315 | switch ($rule[$item]) |
| 291 | 316 | { |
@@ -313,7 +338,9 @@ discard block |
||
| 313 | 338 | $rule2.=$rule[$item]; |
| 314 | 339 | $item++; |
| 315 | 340 | } |
| 316 | - if ($item == strlen ($rule)) throw new Exception("closing '\"' not found in ".$rule ." at " .$item); |
|
| 341 | + if ($item == strlen ($rule)) { |
|
| 342 | + throw new Exception("closing '\"' not found in ".$rule ." at " .$item); |
|
| 343 | + } |
|
| 317 | 344 | $rule2.=$rule[$item]; |
| 318 | 345 | $item++; |
| 319 | 346 | continue; |
@@ -355,10 +382,12 @@ discard block |
||
| 355 | 382 | */ |
| 356 | 383 | public function eval_rule($rule,$oidList) |
| 357 | 384 | { |
| 358 | - if ($rule==null || $rule == '') // Empty rule is always true |
|
| 385 | + if ($rule==null || $rule == '') { |
|
| 386 | + // Empty rule is always true |
|
| 359 | 387 | { |
| 360 | 388 | return true; |
| 361 | 389 | } |
| 390 | + } |
|
| 362 | 391 | $matches=array(); |
| 363 | 392 | while (preg_match('/_OID\(([0-9\.\*]+)\)/',$rule,$matches) == 1) |
| 364 | 393 | { |
@@ -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 int $trap oid of trap |
|
| 83 | - * @return array|null : null if trap not found, or array ( <oid> => name/mib/type ) |
|
| 84 | - */ |
|
| 82 | + * @param int $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,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 | } |
@@ -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,19 +235,19 @@ 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 | |
| 240 | - $action = $this->checkPostVar($postData, 'action', 'save|execute'); |
|
| 240 | + $action=$this->checkPostVar($postData, 'action', 'save|execute'); |
|
| 241 | 241 | |
| 242 | 242 | if ($action == 'save') |
| 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 | { |
| 250 | - $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
|
| 250 | + $this->_helper->json(array('status'=>'Save error : '.$e->getMessage())); |
|
| 251 | 251 | return; |
| 252 | 252 | } |
| 253 | 253 | $this->_helper->json(array('status'=>'OK')); |
@@ -257,16 +257,16 @@ discard block |
||
| 257 | 257 | { |
| 258 | 258 | try |
| 259 | 259 | { |
| 260 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 260 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
| 261 | 261 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 262 | 262 | $debug_level=4; |
| 263 | - $trap = new Trap($icingaweb2_etc); |
|
| 264 | - $trap->setLogging($debug_level,'syslog'); |
|
| 263 | + $trap=new Trap($icingaweb2_etc); |
|
| 264 | + $trap->setLogging($debug_level, 'syslog'); |
|
| 265 | 265 | $trap->eraseOldTraps($days); |
| 266 | 266 | } |
| 267 | 267 | catch (Exception $e) |
| 268 | 268 | { |
| 269 | - $this->_helper->json(array('status'=>'execute error : '.$e->getMessage() )); |
|
| 269 | + $this->_helper->json(array('status'=>'execute error : '.$e->getMessage())); |
|
| 270 | 270 | return; |
| 271 | 271 | } |
| 272 | 272 | $this->_helper->json(array('status'=>'OK')); |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | { |
| 285 | 285 | $postData=$this->getRequest()->getPost(); |
| 286 | 286 | |
| 287 | - $destination = $this->checkPostVar($postData, 'destination', '.*'); |
|
| 287 | + $destination=$this->checkPostVar($postData, 'destination', '.*'); |
|
| 288 | 288 | $logDest=$this->getModuleConfig()->getLogDestinations(); |
| 289 | 289 | if (!isset($logDest[$destination])) |
| 290 | 290 | { |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | if (isset($postData['file'])) |
| 296 | 296 | { |
| 297 | 297 | $file=$postData['file']; |
| 298 | - $fileHandler=@fopen($file,'w'); |
|
| 298 | + $fileHandler=@fopen($file, 'w'); |
|
| 299 | 299 | if ($fileHandler == false) |
| 300 | 300 | { // File os note writabe / cannot create |
| 301 | 301 | $this->_helper->json(array('status'=>'File not writable : '.$file)); |
@@ -315,17 +315,17 @@ discard block |
||
| 315 | 315 | } |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | - $level = $this->checkPostVar($postData, 'level', '[0-9]'); |
|
| 318 | + $level=$this->checkPostVar($postData, 'level', '[0-9]'); |
|
| 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 | { |
| 328 | - $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
|
| 328 | + $this->_helper->json(array('status'=>'Save error : '.$e->getMessage())); |
|
| 329 | 329 | return; |
| 330 | 330 | } |
| 331 | 331 | $this->_helper->json(array('status'=>'OK')); |
@@ -343,29 +343,29 @@ discard block |
||
| 343 | 343 | |
| 344 | 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 | 350 | if ($action == 'evaluate') |
| 351 | 351 | { |
| 352 | 352 | try |
| 353 | 353 | { |
| 354 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 354 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
| 355 | 355 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 356 | - $trap = new Trap($icingaweb2_etc); |
|
| 356 | + $trap=new Trap($icingaweb2_etc); |
|
| 357 | 357 | // Cleanup spaces before eval |
| 358 | 358 | $rule=$trap->ruleClass->eval_cleanup($rule); |
| 359 | 359 | // Eval |
| 360 | 360 | $item=0; |
| 361 | - $rule=$trap->ruleClass->evaluation($rule,$item); |
|
| 361 | + $rule=$trap->ruleClass->evaluation($rule, $item); |
|
| 362 | 362 | } |
| 363 | 363 | catch (Exception $e) |
| 364 | 364 | { |
| 365 | - $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() )); |
|
| 365 | + $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage())); |
|
| 366 | 366 | return; |
| 367 | 367 | } |
| 368 | - $return=($rule==true)?'true':'false'; |
|
| 368 | + $return=($rule == true) ? 'true' : 'false'; |
|
| 369 | 369 | $this->_helper->json(array('status'=>'OK', 'message' => $return)); |
| 370 | 370 | } |
| 371 | 371 | |
@@ -380,15 +380,15 @@ discard block |
||
| 380 | 380 | { |
| 381 | 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 | 387 | try |
| 388 | 388 | { |
| 389 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 389 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
| 390 | 390 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 391 | - $trap = new Trap($icingaweb2_etc); |
|
| 391 | + $trap=new Trap($icingaweb2_etc); |
|
| 392 | 392 | // Enable plugin. |
| 393 | 393 | $action=($action == 'enable') ? true : false; |
| 394 | 394 | $retVal=$trap->pluginClass->enablePlugin($pluginName, $action); |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | } |
| 397 | 397 | catch (Exception $e) |
| 398 | 398 | { |
| 399 | - $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
| 399 | + $this->_helper->json(array('status'=>'Action error : '.$e->getMessage())); |
|
| 400 | 400 | return; |
| 401 | 401 | } |
| 402 | 402 | if ($retVal === true) |
@@ -418,45 +418,45 @@ discard block |
||
| 418 | 418 | { |
| 419 | 419 | $postData=$this->getRequest()->getPost(); |
| 420 | 420 | |
| 421 | - $functionString = $this->checkPostVar($postData, 'function', '.*'); |
|
| 421 | + $functionString=$this->checkPostVar($postData, 'function', '.*'); |
|
| 422 | 422 | |
| 423 | 423 | $this->checkPostVar($postData, 'action', 'evaluate'); |
| 424 | 424 | |
| 425 | 425 | // Only one action possible for now, no tests on action. |
| 426 | 426 | try |
| 427 | 427 | { |
| 428 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 428 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
| 429 | 429 | $icingaweb2Etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 430 | - $trap = new Trap($icingaweb2Etc); |
|
| 430 | + $trap=new Trap($icingaweb2Etc); |
|
| 431 | 431 | // load all plugins in case tested function is not enabled. |
| 432 | 432 | $trap->pluginClass->registerAllPlugins(false); |
| 433 | 433 | // Clean all spaces |
| 434 | - $functionString = $trap->ruleClass->eval_cleanup($functionString); |
|
| 434 | + $functionString=$trap->ruleClass->eval_cleanup($functionString); |
|
| 435 | 435 | // Eval functions |
| 436 | - $result = $trap->pluginClass->evaluateFunctionString($functionString); |
|
| 436 | + $result=$trap->pluginClass->evaluateFunctionString($functionString); |
|
| 437 | 437 | } |
| 438 | 438 | catch (Exception $e) |
| 439 | 439 | { |
| 440 | - $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
| 440 | + $this->_helper->json(array('status'=>'Action error : '.$e->getMessage())); |
|
| 441 | 441 | return; |
| 442 | 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 | 448 | /************** Utilities **********************/ |
| 449 | 449 | |
| 450 | - private function checkPostVar(array $postData,string $postVar, string $validRegexp) : string |
|
| 450 | + private function checkPostVar(array $postData, string $postVar, string $validRegexp) : string |
|
| 451 | 451 | { |
| 452 | 452 | if (!isset ($postData[$postVar])) |
| 453 | 453 | { |
| 454 | - $this->_helper->json(array('status'=>'No ' . $postVar)); |
|
| 454 | + $this->_helper->json(array('status'=>'No '.$postVar)); |
|
| 455 | 455 | return ''; |
| 456 | 456 | } |
| 457 | 457 | if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1) |
| 458 | 458 | { |
| 459 | - $this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar])); |
|
| 459 | + $this->_helper->json(array('status'=>'Unknown '.$postVar.' value '.$postData[$postVar])); |
|
| 460 | 460 | return ''; |
| 461 | 461 | } |
| 462 | 462 | 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'), |