@@ -40,8 +40,7 @@ |
||
| 40 | 40 | $query = $dataBase->select()->from($Config->getTrapRuleName(),array('COUNT(*)')); |
| 41 | 41 | printf("Number of rules : %s\n", $dataBase->fetchOne($query) ); |
| 42 | 42 | |
| 43 | - } |
|
| 44 | - catch (Exception $e) |
|
| 43 | + } catch (Exception $e) |
|
| 45 | 44 | { |
| 46 | 45 | printf('Error in DB : %s\n', $e->getMessage()); |
| 47 | 46 | } |
@@ -42,14 +42,12 @@ discard block |
||
| 42 | 42 | if ($days=='<default>') |
| 43 | 43 | { |
| 44 | 44 | $trap->eraseOldTraps(); |
| 45 | - } |
|
| 46 | - else |
|
| 45 | + } else |
|
| 47 | 46 | { |
| 48 | 47 | $trap->eraseOldTraps($days); |
| 49 | 48 | } |
| 50 | 49 | |
| 51 | - } |
|
| 52 | - catch (Exception $e) |
|
| 50 | + } catch (Exception $e) |
|
| 53 | 51 | { |
| 54 | 52 | echo 'Error in updating : ' . $e->getMessage(); |
| 55 | 53 | } |
@@ -74,8 +72,7 @@ discard block |
||
| 74 | 72 | try |
| 75 | 73 | { |
| 76 | 74 | $trap->reset_services(); |
| 77 | - } |
|
| 78 | - catch (Exception $e) |
|
| 75 | + } catch (Exception $e) |
|
| 79 | 76 | { |
| 80 | 77 | echo 'ERROR : '. $e->getMessage(); |
| 81 | 78 | } |
@@ -256,7 +256,9 @@ discard block |
||
| 256 | 256 | $first=1; |
| 257 | 257 | foreach($this->moduleConfig->getTrapListSearchColumns() as $column) |
| 258 | 258 | { |
| 259 | - if ($first==0) $sql.=' OR '; |
|
| 259 | + if ($first==0) { |
|
| 260 | + $sql.=' OR '; |
|
| 261 | + } |
|
| 260 | 262 | $first=0; |
| 261 | 263 | $sql.=" ".$column." LIKE '%".$this->filter_query."%' "; |
| 262 | 264 | } |
@@ -264,10 +266,14 @@ discard block |
||
| 264 | 266 | } |
| 265 | 267 | if ($this->filter_done == 1) |
| 266 | 268 | { |
| 267 | - if ($sql != '') $sql.=' AND '; |
|
| 269 | + if ($sql != '') { |
|
| 270 | + $sql.=' AND '; |
|
| 271 | + } |
|
| 268 | 272 | $sql.="(status != 'done')"; |
| 269 | 273 | } |
| 270 | - if ($sql != '') $query->where($sql); |
|
| 274 | + if ($sql != '') { |
|
| 275 | + $query->where($sql); |
|
| 276 | + } |
|
| 271 | 277 | return $query; |
| 272 | 278 | } |
| 273 | 279 | |
@@ -99,13 +99,11 @@ discard block |
||
| 99 | 99 | if (isset($oidName['name'])) |
| 100 | 100 | { |
| 101 | 101 | $val=$oidName['name']; |
| 102 | - } |
|
| 103 | - else |
|
| 102 | + } else |
|
| 104 | 103 | { |
| 105 | 104 | $val = $row->$rowkey; |
| 106 | 105 | } |
| 107 | - } |
|
| 108 | - else |
|
| 106 | + } else |
|
| 109 | 107 | { |
| 110 | 108 | $val = $row->$rowkey; |
| 111 | 109 | } |
@@ -114,8 +112,7 @@ discard block |
||
| 114 | 112 | if ($row->$rowkey == null) |
| 115 | 113 | { |
| 116 | 114 | $val = $row->host_group_name; |
| 117 | - } |
|
| 118 | - else |
|
| 115 | + } else |
|
| 119 | 116 | { |
| 120 | 117 | $val = $row->$rowkey; |
| 121 | 118 | } |
@@ -214,7 +214,9 @@ discard block |
||
| 214 | 214 | $first=1; |
| 215 | 215 | foreach($this->moduleConfig->getTrapListSearchColumns() as $column) |
| 216 | 216 | { |
| 217 | - if ($first==0) $sql.=' OR '; |
|
| 217 | + if ($first==0) { |
|
| 218 | + $sql.=' OR '; |
|
| 219 | + } |
|
| 218 | 220 | $first=0; |
| 219 | 221 | $sql.=" CAST(".$column." AS char(100)) LIKE '%".$this->filter_query."%' "; |
| 220 | 222 | } |
@@ -222,10 +224,14 @@ discard block |
||
| 222 | 224 | } |
| 223 | 225 | if ($this->filter_done == 1) |
| 224 | 226 | { |
| 225 | - if ($sql != '') $sql.=' AND '; |
|
| 227 | + if ($sql != '') { |
|
| 228 | + $sql.=' AND '; |
|
| 229 | + } |
|
| 226 | 230 | $sql.="(status != 'done')"; |
| 227 | 231 | } |
| 228 | - if ($sql != '') $query->where($sql); |
|
| 232 | + if ($sql != '') { |
|
| 233 | + $query->where($sql); |
|
| 234 | + } |
|
| 229 | 235 | return $query; |
| 230 | 236 | } |
| 231 | 237 | |
@@ -68,7 +68,9 @@ |
||
| 68 | 68 | switch ($outputType) |
| 69 | 69 | { |
| 70 | 70 | case 'file': |
| 71 | - if ($outputFile == null) throw new Exception("File logging without file !"); |
|
| 71 | + if ($outputFile == null) { |
|
| 72 | + throw new Exception("File logging without file !"); |
|
| 73 | + } |
|
| 72 | 74 | $this->setFile($outputFile); |
| 73 | 75 | $this->setDestination('file'); |
| 74 | 76 | break; |
@@ -74,8 +74,7 @@ discard block |
||
| 74 | 74 | try |
| 75 | 75 | { |
| 76 | 76 | $result=$this->request('GET', "", NULL, NULL); |
| 77 | - } |
|
| 78 | - catch (Exception $e) |
|
| 77 | + } catch (Exception $e) |
|
| 79 | 78 | { |
| 80 | 79 | return array(true, 'Error with API : '.$e->getMessage()); |
| 81 | 80 | } |
@@ -165,8 +164,7 @@ discard block |
||
| 165 | 164 | if (property_exists($result,'status')) |
| 166 | 165 | { |
| 167 | 166 | $message=$result->status; |
| 168 | - } |
|
| 169 | - else |
|
| 167 | + } else |
|
| 170 | 168 | { |
| 171 | 169 | $message="Unkown status"; |
| 172 | 170 | } |
@@ -177,8 +175,7 @@ discard block |
||
| 177 | 175 | if (isset($result->results[0])) |
| 178 | 176 | { |
| 179 | 177 | return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status); |
| 180 | - } |
|
| 181 | - else |
|
| 178 | + } else |
|
| 182 | 179 | { |
| 183 | 180 | return array(false,'Service not found'); |
| 184 | 181 | } |
@@ -220,8 +217,7 @@ discard block |
||
| 220 | 217 | if (property_exists($result,'status')) |
| 221 | 218 | { |
| 222 | 219 | throw new Exception('Ret code ' .$result->error.' : ' . $result->status); |
| 223 | - } |
|
| 224 | - else |
|
| 220 | + } else |
|
| 225 | 221 | { |
| 226 | 222 | throw new Exception('Ret code ' .$result->error.' : Unkown status'); |
| 227 | 223 | } |
@@ -266,8 +262,7 @@ discard block |
||
| 266 | 262 | if (property_exists($result,'status')) |
| 267 | 263 | { |
| 268 | 264 | throw new Exception('Ret code ' .$result->error.' : ' . $result->status); |
| 269 | - } |
|
| 270 | - else |
|
| 265 | + } else |
|
| 271 | 266 | { |
| 272 | 267 | throw new Exception('Ret code ' .$result->error.' : Unkown status'); |
| 273 | 268 | } |
@@ -56,8 +56,7 @@ discard block |
||
| 56 | 56 | if ($pluginDir == '') |
| 57 | 57 | { |
| 58 | 58 | $this->pluginDir=dirname(__DIR__).'/Plugins'; |
| 59 | - } |
|
| 60 | - else |
|
| 59 | + } else |
|
| 61 | 60 | { |
| 62 | 61 | $this->pluginDir=$pluginDir; |
| 63 | 62 | } |
@@ -94,8 +93,7 @@ discard block |
||
| 94 | 93 | { |
| 95 | 94 | $this->logClass->log('No enabled plugins',DEBUG); |
| 96 | 95 | return; |
| 97 | - } |
|
| 98 | - else |
|
| 96 | + } else |
|
| 99 | 97 | { // Saved config : <plugin name>;<Catch all OID ? 1|0>;<Trap target ? 1|0>;<func 1 name>|<func 2 name>... ,<plugin2 name>.... |
| 100 | 98 | $this->logClass->log('Enabled plugins = '.$PluginList,DEBUG); |
| 101 | 99 | |
@@ -233,9 +231,11 @@ discard block |
||
| 233 | 231 | */ |
| 234 | 232 | public function registerPlugin(string $pluginName) |
| 235 | 233 | { |
| 236 | - if ( ! isset($this->pluginsList[$pluginName]) ) // Plugin isn't enable, create entry |
|
| 234 | + if ( ! isset($this->pluginsList[$pluginName]) ) { |
|
| 235 | + // Plugin isn't enable, create entry |
|
| 237 | 236 | { |
| 238 | 237 | $pluginListElmt = array(); |
| 238 | + } |
|
| 239 | 239 | $pluginListElmt['object'] = null; // class not loaded |
| 240 | 240 | $pluginListElmt['enabled'] = false; |
| 241 | 241 | $this->pluginsList[$pluginName] = $pluginListElmt; |
@@ -282,8 +282,7 @@ discard block |
||
| 282 | 282 | . $pluginName . ' and ' . $this->functionList[$fname]['plugin']); |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | - } |
|
| 286 | - else |
|
| 285 | + } else |
|
| 287 | 286 | { |
| 288 | 287 | $this->functionList[$fname]=array(); |
| 289 | 288 | $this->functionList[$fname]['plugin'] = $pluginName; |
@@ -326,11 +325,13 @@ discard block |
||
| 326 | 325 | $retDisplay .= $e->getMessage() . ' / '; |
| 327 | 326 | } |
| 328 | 327 | } |
| 329 | - if ($checkEnabled === false) // Load all php files in plugin dir |
|
| 328 | + if ($checkEnabled === false) { |
|
| 329 | + // Load all php files in plugin dir |
|
| 330 | 330 | { |
| 331 | 331 | foreach (glob($this->pluginDir."/*.php") as $filename) |
| 332 | 332 | { |
| 333 | 333 | $pluginName=basename($filename,'.php'); |
| 334 | + } |
|
| 334 | 335 | if (!preg_match('/^[a-zA-Z0-9]+$/',$pluginName)) |
| 335 | 336 | { |
| 336 | 337 | $this->logClass->log("Invalid plugin name : ".$pluginName, WARN); |
@@ -348,8 +349,7 @@ discard block |
||
| 348 | 349 | if ($retDisplay == '') |
| 349 | 350 | { |
| 350 | 351 | return 'All plugins loaded OK'; |
| 351 | - } |
|
| 352 | - else |
|
| 352 | + } else |
|
| 353 | 353 | { |
| 354 | 354 | return $retDisplay; |
| 355 | 355 | } |
@@ -153,8 +153,7 @@ discard block |
||
| 153 | 153 | if ($value != null && isset($value['id'])) |
| 154 | 154 | { // Entry exists -> update |
| 155 | 155 | $sql='UPDATE '.$this->dbPrefix.'db_config SET value = \''.$element.'\' WHERE (id = '.$value['id'].')'; |
| 156 | - } |
|
| 157 | - else |
|
| 156 | + } else |
|
| 158 | 157 | { // Entry does no exists -> create |
| 159 | 158 | $sql='INSERT INTO '.$this->dbPrefix.'db_config (name,value) VALUES (\''.$name.'\' , \''.$element.'\' )'; |
| 160 | 159 | } |
@@ -222,8 +221,7 @@ discard block |
||
| 222 | 221 | if (preg_match('/^ *CREATE TABLE ([^ ]+)/',$newline,$cur_table_array)) |
| 223 | 222 | { |
| 224 | 223 | $cur_table='table '.$cur_table_array[1]; |
| 225 | - } |
|
| 226 | - else |
|
| 224 | + } else |
|
| 227 | 225 | { |
| 228 | 226 | $cur_table='secret SQL stuff :-)'; |
| 229 | 227 | } |
@@ -267,8 +265,7 @@ discard block |
||
| 267 | 265 | if ($this->trapDBType == 'pgsql') |
| 268 | 266 | { |
| 269 | 267 | $prefix .= 'update_pgsql/schema_'; |
| 270 | - } |
|
| 271 | - else |
|
| 268 | + } else |
|
| 272 | 269 | { |
| 273 | 270 | $prefix .= 'update_sql/schema_'; |
| 274 | 271 | } |
@@ -312,7 +309,10 @@ discard block |
||
| 312 | 309 | $db_conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| 313 | 310 | while (($line=fgets($input_stream)) !== false) |
| 314 | 311 | { |
| 315 | - if (preg_match('/^#/', $line)) continue; // ignore comment lines |
|
| 312 | + if (preg_match('/^#/', $line)) { |
|
| 313 | + continue; |
|
| 314 | + } |
|
| 315 | + // ignore comment lines |
|
| 316 | 316 | $newline.=chop(preg_replace('/#PREFIX#/',$table_prefix,$line)); |
| 317 | 317 | if (preg_match('/; *$/', $newline)) |
| 318 | 318 | { |
@@ -325,8 +325,7 @@ discard block |
||
| 325 | 325 | if (preg_match('/^ *([^ ]+) TABLE ([^ ]+)/',$newline,$cur_table_array)) |
| 326 | 326 | { |
| 327 | 327 | $cur_table=$cur_table_array[1] . ' SQL table '.$cur_table_array[2]; |
| 328 | - } |
|
| 329 | - else |
|
| 328 | + } else |
|
| 330 | 329 | { |
| 331 | 330 | $cur_table='secret SQL stuff :-)'; |
| 332 | 331 | //$cur_table=$newline; |