@@ -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; |
@@ -64,8 +64,7 @@ discard block |
||
| 64 | 64 | if ($pid == 1) |
| 65 | 65 | { |
| 66 | 66 | $trap->setLogging($logLevel,'display'); |
| 67 | - } |
|
| 68 | - else |
|
| 67 | + } else |
|
| 69 | 68 | { // use default display TODO : if default is 'display' son process will be killed at first output.... |
| 70 | 69 | if ($pid != 0) |
| 71 | 70 | { |
@@ -74,8 +73,7 @@ discard block |
||
| 74 | 73 | fclose($file); |
| 75 | 74 | echo "OK : process $pid in bckground"; |
| 76 | 75 | return 0; |
| 77 | - } |
|
| 78 | - else |
|
| 76 | + } else |
|
| 79 | 77 | { // son process : close all file descriptors and go to a new session |
| 80 | 78 | fclose($file); |
| 81 | 79 | // $sid = posix_setsid(); |
@@ -85,8 +83,7 @@ discard block |
||
| 85 | 83 | try |
| 86 | 84 | { |
| 87 | 85 | $trap->mibClass->update_mib_database(false,$forceCheck); |
| 88 | - } |
|
| 89 | - catch (Exception $e) |
|
| 86 | + } catch (Exception $e) |
|
| 90 | 87 | { |
| 91 | 88 | $trap->trapLog('Error in updating : ' . $e->getMessage(),2); |
| 92 | 89 | } |
@@ -103,8 +100,7 @@ discard block |
||
| 103 | 100 | $trap->mibClass->update_mib_database(true,$forceCheck); |
| 104 | 101 | echo "Done\n"; |
| 105 | 102 | |
| 106 | - } |
|
| 107 | - catch (Exception $e) |
|
| 103 | + } catch (Exception $e) |
|
| 108 | 104 | { |
| 109 | 105 | echo 'Error in updating : ' . $e->getMessage(); |
| 110 | 106 | } |
@@ -147,8 +143,7 @@ discard block |
||
| 147 | 143 | $Config->getMIBCacheTableName(), |
| 148 | 144 | 'id>0'); |
| 149 | 145 | echo 'Deleted '. $query . " traps and objects\n"; |
| 150 | - } |
|
| 151 | - catch (Exception $e) |
|
| 146 | + } catch (Exception $e) |
|
| 152 | 147 | { |
| 153 | 148 | echo 'Error in DB : ' . $e->getMessage(); |
| 154 | 149 | } |
@@ -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 | } |