Passed
Pull Request — master (#78)
by
unknown
04:15
created
application/clicommands/TrapsCommand.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -30,16 +30,16 @@  discard block
 block discarded – undo
30 30
 	public function rotateAction()
31 31
 	{
32 32
 		$module=Icinga::app()->getModuleManager()->getModule($this->getModuleName());
33
-		require_once($module->getBaseDir() .'/bin/trap_class.php');
33
+		require_once($module->getBaseDir().'/bin/trap_class.php');
34 34
 		$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
35 35
 		$debug_level=2;
36
-		$trap = new Trap($icingaweb2_etc);
37
-		$trap->setLogging($debug_level,'display');
36
+		$trap=new Trap($icingaweb2_etc);
37
+		$trap->setLogging($debug_level, 'display');
38 38
 		try
39 39
 		{
40
-			$days = $this->params->get('days', '<default>');
40
+			$days=$this->params->get('days', '<default>');
41 41
 			echo $this->screen->colorize("Deleting traps older than $days days\n", 'lightblue');
42
-			if ($days=='<default>')
42
+			if ($days == '<default>')
43 43
 			{
44 44
 				$trap->eraseOldTraps();
45 45
 			}
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 		}
52 52
 		catch (Exception $e)
53 53
 		{
54
-			echo 'Error in updating : ' . $e->getMessage();
54
+			echo 'Error in updating : '.$e->getMessage();
55 55
 		}	   
56 56
 	}  	
57 57
 	
@@ -66,18 +66,18 @@  discard block
 block discarded – undo
66 66
 	public function resetOKAction()
67 67
 	{
68 68
 		$module=Icinga::app()->getModuleManager()->getModule($this->getModuleName());
69
-		require_once($module->getBaseDir() .'/bin/trap_class.php');
69
+		require_once($module->getBaseDir().'/bin/trap_class.php');
70 70
 		$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
71 71
 		$debug_level=2;
72
-		$trap = new Trap($icingaweb2_etc);
73
-		$trap->setLogging($debug_level,'display');
72
+		$trap=new Trap($icingaweb2_etc);
73
+		$trap->setLogging($debug_level, 'display');
74 74
 		try 
75 75
 		{
76 76
 			$trap->reset_services();
77 77
 		} 
78 78
 		catch (Exception $e) 
79 79
 		{
80
-			echo 'ERROR : '. $e->getMessage();
80
+			echo 'ERROR : '.$e->getMessage();
81 81
 		}
82 82
 	} 	
83 83
 	
Please login to merge, or discard this patch.
application/forms/TrapsConfigForm.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 		$this->setName('form_config_traps');
19 19
 		$this->setSubmitLabel($this->translate('Save Changes'));
20 20
 	}
21
-	public function setPaths($module_base_path,$icinga_base_path)
21
+	public function setPaths($module_base_path, $icinga_base_path)
22 22
 	{
23 23
 		$this->module_base_path=$module_base_path;
24 24
 		$this->icinga_base_path=$icinga_base_path;
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
         );
83 83
 		$retval=0;
84 84
 		$output=array();
85
-		$snmptranslate=exec('which snmptranslate',$output,$retval);
85
+		$snmptranslate=exec('which snmptranslate', $output, $retval);
86 86
 		if ($retval != 0) 
87 87
 		{
88 88
 			$snmptranslate='/usr/bin/snmptranslate';
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
     }	
173 173
 
174 174
     
175
-    public function render(Zend_View_Interface $view = NULL)
175
+    public function render(Zend_View_Interface $view=NULL)
176 176
     {
177 177
         
178 178
 
Please login to merge, or discard this patch.
application/controllers/ErrorController.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
 	
13 13
 	public function indexAction()
14 14
 	{	  
15
-		$this->getTabs()->add('get',array(
15
+		$this->getTabs()->add('get', array(
16 16
 			'active'	=> true,
17 17
 			'label'		=> $this->translate('Error'),
18 18
 			'url'		=> Url::fromRequest()
Please login to merge, or discard this patch.
tests/db_test.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -3,16 +3,16 @@  discard block
 block discarded – undo
3 3
 
4 4
 require_once 'bin/trap_class.php';
5 5
 
6
-$options = getopt("c:v:d:b:a:");
6
+$options=getopt("c:v:d:b:a:");
7 7
 
8
-$icingaweb2Etc=(array_key_exists('d',$options))?$options['d']:"/etc/icingaweb2";
8
+$icingaweb2Etc=(array_key_exists('d', $options)) ? $options['d'] : "/etc/icingaweb2";
9 9
 
10
-$debugLevel=4;// 0=No output 1=critical 2=warning 3=trace 4=ALL
10
+$debugLevel=4; // 0=No output 1=critical 2=warning 3=trace 4=ALL
11 11
 
12
-$trap = new trap($icingaweb2Etc,$debugLevel,'display');
13
-$trap->setLogging($debugLevel,'display');
12
+$trap=new trap($icingaweb2Etc, $debugLevel, 'display');
13
+$trap->setLogging($debugLevel, 'display');
14 14
 
15
-if (!array_key_exists('v',$options) || !array_key_exists('c',$options) || !array_key_exists('b',$options)|| !array_key_exists('a',$options))
15
+if (!array_key_exists('v', $options) || !array_key_exists('c', $options) || !array_key_exists('b', $options) || !array_key_exists('a', $options))
16 16
 {
17 17
     printf("Need version -v, path -a, database -b (mysql,pgsql) command -c (create/update)\n");
18 18
     exit(1);
@@ -20,22 +20,22 @@  discard block
 block discarded – undo
20 20
 $command=$options['c'];
21 21
 $path=$options['a'];
22 22
 try {
23
-    switch($command)
23
+    switch ($command)
24 24
     {
25 25
         case 'create':
26
-            $schema=($options['b']=='mysql')?'schema_v'.$options['v'].'.sql':'schema_v'.$options['v'].'.pgsql';
26
+            $schema=($options['b'] == 'mysql') ? 'schema_v'.$options['v'].'.sql' : 'schema_v'.$options['v'].'.pgsql';
27 27
             $schema=$path.'/SQL/'.$schema;
28 28
             $trap->trapsDB->create_schema($schema, 'traps_');
29 29
             break;
30 30
         case 'update':
31
-            $message=$trap->trapsDB->update_schema($path."/SQL/",$options['v'], 'traps_',true);
32
-            printf("Update message : %s\n",$message);
31
+            $message=$trap->trapsDB->update_schema($path."/SQL/", $options['v'], 'traps_', true);
32
+            printf("Update message : %s\n", $message);
33 33
             if ($message == 'ERROR')
34 34
             {
35 35
                 exit(1);
36 36
             }
37 37
             printf("Messages DONE, updating : \n");
38
-            $message=$trap->trapsDB->update_schema($path."/SQL/",$options['v'], 'traps_');
38
+            $message=$trap->trapsDB->update_schema($path."/SQL/", $options['v'], 'traps_');
39 39
             if ($message == 'ERROR')
40 40
             {
41 41
                 exit(1);
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
             exit(1);
47 47
     }
48 48
 } catch (Exception $e) {
49
-    printf("Caught Exception %s\n",$e->getMessage());
49
+    printf("Caught Exception %s\n", $e->getMessage());
50 50
     exit (1);
51 51
 }
52 52
 
Please login to merge, or discard this patch.
library/Trapdirector/Tables/HandlerTableList.php 1 patch
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -32,8 +32,8 @@  discard block
 block discarded – undo
32 32
 	// Filters 
33 33
 	
34 34
     protected $filter;
35
-    protected $enforcedFilters = array();
36
-    protected $searchColumns = array();
35
+    protected $enforcedFilters=array();
36
+    protected $searchColumns=array();
37 37
 	
38 38
 	protected function getTitles() {
39 39
 		return $this->moduleConfig->getHandlerListTitles();
@@ -53,34 +53,34 @@  discard block
 block discarded – undo
53 53
 	public function render()
54 54
 	{
55 55
 		$data=$this->getTable();
56
-		$view = $this->getView();
57
-		$this->columnCount = count($this->getTitles());
56
+		$view=$this->getView();
57
+		$this->columnCount=count($this->getTitles());
58 58
 		$this->lastDay=null;
59 59
 		// Table start
60
-		$htm  = '<table class="simple common-table table-row-selectable">';
60
+		$htm='<table class="simple common-table table-row-selectable">';
61 61
 		
62 62
 		// Titles
63
-		$htm .= "<thead>\n  <tr>\n";
64
-		$titles = $this->getTitles();
63
+		$htm.="<thead>\n  <tr>\n";
64
+		$titles=$this->getTitles();
65 65
 		foreach ($titles as $title) 
66 66
 		{
67
-			$htm .= '    <th>' . $view->escape($view->translate($title)) . "</th>\n";
67
+			$htm.='    <th>'.$view->escape($view->translate($title))."</th>\n";
68 68
 		}
69
-		$htm .= "  </tr>\n</thead>\n";
69
+		$htm.="  </tr>\n</thead>\n";
70 70
 		
71 71
 		// Rows
72
-		$htm .= "<tbody>\n";
72
+		$htm.="<tbody>\n";
73 73
 		
74 74
 		foreach ($data as $row) 
75 75
 		{
76
-			$firstCol = true;
76
+			$firstCol=true;
77 77
 			// Put date header
78 78
 			//$htm .= $this->renderDayIfNew($row->timestamp);
79 79
 			
80 80
 			
81 81
 			// Render row
82
-			$htm .= '<tr '.' >';
83
-			foreach ( $titles as $rowkey => $title) 
82
+			$htm.='<tr '.' >';
83
+			foreach ($titles as $rowkey => $title) 
84 84
 			{
85 85
 				// Check missing value
86 86
 				if (property_exists($row, $rowkey)) 
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 						break;
94 94
 						case 'trap_oid': // try to traslate oids.
95 95
 						
96
-							if ($this->doTranslate===true)
96
+							if ($this->doTranslate === true)
97 97
 							{
98 98
 								$oidName=$this->MIB->translateOID($row->$rowkey);
99 99
 								if (isset($oidName['name']))
@@ -102,52 +102,52 @@  discard block
 block discarded – undo
102 102
 								}
103 103
 								else
104 104
 								{
105
-									$val = $row->$rowkey;
105
+									$val=$row->$rowkey;
106 106
 								}								
107 107
 							}
108 108
 							else
109 109
 							{
110
-								$val = $row->$rowkey;
110
+								$val=$row->$rowkey;
111 111
 							}
112 112
 						break;
113 113
 						case 'host_name': // switch to hostgroup if name is null
114 114
 							if ($row->$rowkey == null)
115 115
 							{
116
-								$val = $row->host_group_name;
116
+								$val=$row->host_group_name;
117 117
 							}
118 118
 							else
119 119
 							{
120
-								$val = $row->$rowkey;
120
+								$val=$row->$rowkey;
121 121
 							}
122 122
 						break;
123 123
 						default:
124
-							$val = $row->$rowkey;
124
+							$val=$row->$rowkey;
125 125
 					}
126
-					if ($rowkey == 'trap_oid' && $this->doTranslate===true)
126
+					if ($rowkey == 'trap_oid' && $this->doTranslate === true)
127 127
 					{					
128 128
 							
129 129
 					}
130 130
 				} else {
131
-					$val = '-';
131
+					$val='-';
132 132
 				}
133 133
 				if ($firstCol === true) { // Put link in first column for trap detail.
134
-					$htm .= '<td>' 
134
+					$htm.='<td>' 
135 135
 							. $view->qlink(
136 136
 									$view->escape($val),  
137 137
 									Url::fromPath(
138
-										$this->moduleConfig->urlPath() . '/handler/add', 
138
+										$this->moduleConfig->urlPath().'/handler/add', 
139 139
 										array('ruleid' => $row->id)
140 140
 									)
141 141
 							)
142 142
 							. '</td>';
143 143
 				} else {
144
-					$htm .= '<td>' . $view->escape($val) . '</td>';
144
+					$htm.='<td>'.$view->escape($val).'</td>';
145 145
 				}
146 146
 				$firstCol=false;
147 147
 			}
148
-			$htm .= "<tr>\n";
148
+			$htm.="<tr>\n";
149 149
 		}
150
-		$htm .= "</tbody></table>\n";
150
+		$htm.="</tbody></table>\n";
151 151
 		//$htm .= "Filter : " . $this->filter."<br>\n";
152 152
 		return $htm;
153 153
 
@@ -156,13 +156,13 @@  discard block
 block discarded – undo
156 156
     public function count()
157 157
     {
158 158
         //$db = $this->connection()->getConnection();
159
-        $query = clone($this->getBaseQuery());
159
+        $query=clone($this->getBaseQuery());
160 160
         $query->reset('order')->columns(array('COUNT(*)'));
161 161
         $this->applyFiltersToQuery($query);
162 162
 
163 163
 		$db=$this->db();
164 164
 		
165
-		$query = $db->select()->from(
165
+		$query=$db->select()->from(
166 166
             $this->moduleConfig->getTrapRuleName(),
167 167
             array('COUNT(*)')
168 168
         );
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 	
173 173
     public function getPaginator()
174 174
     {
175
-        $paginator = new Paginator();
175
+        $paginator=new Paginator();
176 176
         $paginator->setQuery($this);
177 177
 
178 178
         return $paginator;
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 	{
185 185
 		$db=$this->db();
186 186
 		
187
-		$query = $this->getBaseQuery();
187
+		$query=$this->getBaseQuery();
188 188
 		
189 189
        if ($this->hasLimit() || $this->hasOffset()) {
190 190
             $query->limit($this->getLimit(), $this->getOffset());
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
     {
198 198
 		$db=$this->db();
199 199
 		
200
-		$query = $db->select()->from(
200
+		$query=$db->select()->from(
201 201
             $this->moduleConfig->getTrapRuleName(),
202 202
             $this->moduleConfig->getHandlerListDisplayColumns()
203 203
         )->order('host_name DESC,trap_oid DESC');
@@ -219,20 +219,20 @@  discard block
 block discarded – undo
219 219
 
220 220
     public function setFilter($filter)
221 221
     {
222
-        $this->filter = $filter;
222
+        $this->filter=$filter;
223 223
         return $this;
224 224
     }
225 225
 	
226 226
 	public function getFilterEditor(Request $request)
227 227
     {
228
-        $filterEditor = Widget::create('filterEditor')
228
+        $filterEditor=Widget::create('filterEditor')
229 229
             ->setColumns(array_keys($this->getColumns()))
230 230
             ->setSearchColumns(array_keys($this->getSearchColumns()))
231 231
             ->preserveParams('limit', 'sort', 'dir', 'view', 'backend')
232 232
             ->ignoreParams('page')
233 233
             ->handleRequest($request);
234 234
 
235
-        $filter = $filterEditor->getFilter();
235
+        $filter=$filterEditor->getFilter();
236 236
         $this->setFilter($filter);
237 237
 
238 238
         return $filterEditor;
Please login to merge, or discard this patch.
library/Trapdirector/TrapsProcess/Logging.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -4,17 +4,17 @@  discard block
 block discarded – undo
4 4
 
5 5
 use Exception;
6 6
 
7
-define("ERROR", 1);define("WARN", 2);define("INFO", 3);define("DEBUG", 4);
7
+define("ERROR", 1); define("WARN", 2); define("INFO", 3); define("DEBUG", 4);
8 8
 
9 9
 class Logging
10 10
 {
11 11
 
12 12
     //**** Options from config database
13 13
     // Default values
14
-    public $debugLevel=2;  // 0=No output 1=critical 2=warning 3=trace 4=ALL
14
+    public $debugLevel=2; // 0=No output 1=critical 2=warning 3=trace 4=ALL
15 15
     public $outputMode='syslog'; // alert type : file, syslog, display
16 16
     public $outputFile="/tmp/trapdebug.txt";
17
-    protected $logLevels=array("","Error","Warning","Info","Debug");
17
+    protected $logLevels=array("", "Error", "Warning", "Info", "Debug");
18 18
     protected $outputList=array('file', 'syslog', 'display');
19 19
     
20 20
     /** Send log. Throws exception on critical error
@@ -24,29 +24,29 @@  discard block
 block discarded – undo
24 24
      *	@return void
25 25
      *  @throws Exception
26 26
      **/
27
-    public function log( $message, $level, $destination ='')
27
+    public function log($message, $level, $destination='')
28 28
     {
29 29
         if ($this->debugLevel >= $level)
30 30
         {
31
-            $date = '['.  date("Y/m/d H:i:s") . '] '; // no date in syslog as already there
32
-            $message = '[TrapDirector] ['.$this->logLevels[$level].']: ' .$message . "\n";
31
+            $date='['.date("Y/m/d H:i:s").'] '; // no date in syslog as already there
32
+            $message='[TrapDirector] ['.$this->logLevels[$level].']: '.$message."\n";
33 33
             
34
-            $output = ( $destination != '' ) ? $destination : $this->outputMode;
34
+            $output=($destination != '') ? $destination : $this->outputMode;
35 35
             switch ($output)
36 36
             {
37 37
                 case 'file':
38
-                    file_put_contents ($this->outputFile, $date.$message , FILE_APPEND);
38
+                    file_put_contents($this->outputFile, $date.$message, FILE_APPEND);
39 39
                     break;
40 40
                 case 'syslog':
41
-                    switch($level)
41
+                    switch ($level)
42 42
                     {
43
-                        case 1 : $prio = LOG_ERR;break;
44
-                        case 2 : $prio = LOG_WARNING;break;
45
-                        case 3 : $prio = LOG_INFO;break;
46
-                        case 4 : $prio = LOG_INFO;break; // LOG_DEBUG isn't always displayed in syslog
47
-                        default: $prio = LOG_ERR;
43
+                        case 1 : $prio=LOG_ERR; break;
44
+                        case 2 : $prio=LOG_WARNING; break;
45
+                        case 3 : $prio=LOG_INFO; break;
46
+                        case 4 : $prio=LOG_INFO; break; // LOG_DEBUG isn't always displayed in syslog
47
+                        default: $prio=LOG_ERR;
48 48
                     }
49
-                    syslog($prio,$message);
49
+                    syslog($prio, $message);
50 50
                     break;
51 51
                 case 'display':
52 52
                     echo $date.$message;
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
     }
63 63
     
64 64
         
65
-    public function setLogging($debugLvl,$outputType,$outputFile=null)
65
+    public function setLogging($debugLvl, $outputType, $outputFile=null)
66 66
     {
67 67
         $this->setLevel($debugLvl);
68 68
         switch ($outputType)
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
      */
99 99
     public function setDestination($destination)
100 100
     {
101
-        if (!is_string($destination) || ! in_array($destination, $this->outputList))
101
+        if (!is_string($destination) || !in_array($destination, $this->outputList))
102 102
         {
103 103
             throw new Exception('Invalid log destination');
104 104
         }
Please login to merge, or discard this patch.
library/Trapdirector/TrapsProcess/Database.php 1 patch
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -34,16 +34,16 @@  discard block
 block discarded – undo
34 34
      * @param Logging $logClass : where to log
35 35
      * @param array $dbParam : array of named params  type,host,dbname,username,[port],[password]
36 36
      */
37
-    function __construct($logClass,$dbParam,$dbPrefix)
37
+    function __construct($logClass, $dbParam, $dbPrefix)
38 38
     {
39 39
         $this->logging=$logClass;
40 40
         $this->dbPrefix=$dbPrefix;
41 41
         
42 42
         $this->trapDSN=$this->setupDSN($dbParam);
43
-        $this->trapUsername = $dbParam['username'];
44
-        $this->trapPass = (array_key_exists('password', $dbParam)) ? $dbParam['password']:'';
43
+        $this->trapUsername=$dbParam['username'];
44
+        $this->trapPass=(array_key_exists('password', $dbParam)) ? $dbParam['password'] : '';
45 45
         $this->trapDBType=$dbParam['db'];
46
-        $this->logging->log('DSN : '.$this->trapDSN. ';user '.$this->trapUsername.' / prefix : '. $this->dbPrefix,INFO);
46
+        $this->logging->log('DSN : '.$this->trapDSN.';user '.$this->trapUsername.' / prefix : '.$this->dbPrefix, INFO);
47 47
         $this->db_connect_trap();
48 48
         
49 49
     }
@@ -55,9 +55,9 @@  discard block
 block discarded – undo
55 55
     public function setupIDO($dbParam)
56 56
     {
57 57
         $this->idoDSN=$this->setupDSN($dbParam);
58
-        $this->idoUsername = $dbParam['username'];
59
-        $this->idoPass = (array_key_exists('password', $dbParam)) ? $dbParam['password']:'';
60
-        $this->logging->log('DSN : '.$this->idoDSN. ';user '.$this->idoUsername,INFO);
58
+        $this->idoUsername=$dbParam['username'];
59
+        $this->idoPass=(array_key_exists('password', $dbParam)) ? $dbParam['password'] : '';
60
+        $this->logging->log('DSN : '.$this->idoDSN.';user '.$this->idoUsername, INFO);
61 61
         $this->idoDBType=$dbParam['db'];
62 62
         $this->db_connect_ido();
63 63
     }
@@ -75,13 +75,13 @@  discard block
 block discarded – undo
75 75
                 return $this->idoDB;
76 76
             } catch (Exception $e) {
77 77
                 // select 1 failed, try to reconnect.
78
-                $this->logging->log('Database IDO connection lost, reconnecting',WARN);
78
+                $this->logging->log('Database IDO connection lost, reconnecting', WARN);
79 79
             }
80 80
         }
81 81
         try {
82
-            $this->idoDB = new PDO($this->idoDSN,$this->idoUsername,$this->idoPass);
82
+            $this->idoDB=new PDO($this->idoDSN, $this->idoUsername, $this->idoPass);
83 83
         } catch (PDOException $e) {
84
-            $this->logging->log('Connection failed to IDO : ' . $e->getMessage(),ERROR,'');
84
+            $this->logging->log('Connection failed to IDO : '.$e->getMessage(), ERROR, '');
85 85
         }
86 86
         return $this->idoDB;
87 87
     }
@@ -99,13 +99,13 @@  discard block
 block discarded – undo
99 99
                 return $this->trapDB;
100 100
             } catch (Exception $e) {
101 101
                 // select 1 failed, try to reconnect.
102
-                $this->logging->log('Database connection lost, reconnecting',WARN);
102
+                $this->logging->log('Database connection lost, reconnecting', WARN);
103 103
             }           
104 104
         }       
105 105
         try {
106
-            $this->trapDB = new PDO($this->trapDSN,$this->trapUsername,$this->trapPass);
106
+            $this->trapDB=new PDO($this->trapDSN, $this->trapUsername, $this->trapPass);
107 107
         } catch (PDOException $e) {
108
-            $this->logging->log('Connection failed : ' . $e->getMessage(),ERROR,'');
108
+            $this->logging->log('Connection failed : '.$e->getMessage(), ERROR, '');
109 109
         }
110 110
         return $this->trapDB;
111 111
     }
@@ -117,21 +117,21 @@  discard block
 block discarded – undo
117 117
      */
118 118
     protected function setupDSN($configElmt)  
119 119
     {
120
-        if (!array_key_exists('db',$configElmt) ||
121
-            !array_key_exists('host',$configElmt) ||
122
-            !array_key_exists('dbname',$configElmt) ||
123
-            !array_key_exists('username',$configElmt))
120
+        if (!array_key_exists('db', $configElmt) ||
121
+            !array_key_exists('host', $configElmt) ||
122
+            !array_key_exists('dbname', $configElmt) ||
123
+            !array_key_exists('username', $configElmt))
124 124
         {
125
-            $this->logging->log('Missing DB params',ERROR);
125
+            $this->logging->log('Missing DB params', ERROR);
126 126
             return ''; 
127 127
         }
128 128
         
129 129
         //	$dsn = 'mysql:dbname=traps;host=127.0.0.1';
130
-        $dsn= $configElmt['db'].':dbname='.$configElmt['dbname'].';host='.$configElmt['host'];
130
+        $dsn=$configElmt['db'].':dbname='.$configElmt['dbname'].';host='.$configElmt['host'];
131 131
         
132 132
         if (array_key_exists('port', $configElmt))
133 133
         {
134
-            $dsn .= ';port='.$configElmt['port'];
134
+            $dsn.=';port='.$configElmt['port'];
135 135
         }
136 136
         return $dsn;
137 137
     }
@@ -141,12 +141,12 @@  discard block
 block discarded – undo
141 141
      * @param string $element
142 142
      * @return boolean true on success, else false (error logged)
143 143
      */
144
-    public function setDBConfig($name,$element)
144
+    public function setDBConfig($name, $element)
145 145
     {
146 146
         $db_conn=$this->db_connect_trap();
147 147
         $sql='SELECT id from '.$this->dbPrefix.'db_config WHERE ( name=\''.$name.'\' )';
148 148
         if (($ret_code=$db_conn->query($sql)) === false) {
149
-            $this->logging->log('Error setting config element : ' . $sql,WARN,'');           
149
+            $this->logging->log('Error setting config element : '.$sql, WARN, '');           
150 150
             return false;
151 151
         }
152 152
         $value=$ret_code->fetch();
@@ -159,10 +159,10 @@  discard block
 block discarded – undo
159 159
             $sql='INSERT INTO '.$this->dbPrefix.'db_config (name,value) VALUES (\''.$name.'\' , \''.$element.'\' )';
160 160
         }
161 161
         if (($ret_code=$db_conn->query($sql)) === false) {
162
-            $this->logging->log('Error setting config element : ' . $sql,WARN,'');
162
+            $this->logging->log('Error setting config element : '.$sql, WARN, '');
163 163
             return false;
164 164
         }
165
-        $this->logging->log('Setting config '.$name.' = '.$element.' in database',INFO);
165
+        $this->logging->log('Setting config '.$name.' = '.$element.' in database', INFO);
166 166
         return true;
167 167
     }
168 168
 
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
         $db_conn=$this->db_connect_trap();
177 177
         $sql='SELECT value from '.$this->dbPrefix.'db_config WHERE ( name=\''.$element.'\' )';
178 178
         if (($ret_code=$db_conn->query($sql)) === false) {
179
-            $this->logging->log('No result in query : ' . $sql,WARN,'');
179
+            $this->logging->log('No result in query : '.$sql, WARN, '');
180 180
             return null;
181 181
         }
182 182
         $value=$ret_code->fetch();
@@ -194,14 +194,14 @@  discard block
 block discarded – undo
194 194
      *	@param $schema_file	string File to read schema from
195 195
      *	@param $table_prefix string to replace #PREFIX# in schema file by this
196 196
      */
197
-    public function create_schema($schema_file,$table_prefix)
197
+    public function create_schema($schema_file, $table_prefix)
198 198
     {
199 199
         //Read data from snmptrapd from stdin
200 200
         $input_stream=fopen($schema_file, 'r');
201 201
         
202
-        if ($input_stream=== false)
202
+        if ($input_stream === false)
203 203
         {
204
-            $this->logging->log("Error reading schema !",ERROR,'');
204
+            $this->logging->log("Error reading schema !", ERROR, '');
205 205
             return;
206 206
         }
207 207
         $newline='';
@@ -211,15 +211,15 @@  discard block
 block discarded – undo
211 211
         
212 212
         while (($line=fgets($input_stream)) !== false)
213 213
         {
214
-            $newline.=chop(preg_replace('/#PREFIX#/',$table_prefix,$line));
214
+            $newline.=chop(preg_replace('/#PREFIX#/', $table_prefix, $line));
215 215
             if (preg_match('/; *$/', $newline))
216 216
             {
217
-                $sql= $newline;
217
+                $sql=$newline;
218 218
                 if ($db_conn->query($sql) === false) {
219
-                    $this->logging->log('Error create schema : '.$sql,ERROR,'');
219
+                    $this->logging->log('Error create schema : '.$sql, ERROR, '');
220 220
                     return;
221 221
                 }
222
-                if (preg_match('/^ *CREATE TABLE ([^ ]+)/',$newline,$cur_table_array))
222
+                if (preg_match('/^ *CREATE TABLE ([^ ]+)/', $newline, $cur_table_array))
223 223
                 {
224 224
                     $cur_table='table '.$cur_table_array[1];
225 225
                 }
@@ -227,20 +227,20 @@  discard block
 block discarded – undo
227 227
                 {
228 228
                     $cur_table='secret SQL stuff :-)';
229 229
                 }
230
-                $this->logging->log('Creating : ' . $cur_table,INFO );
230
+                $this->logging->log('Creating : '.$cur_table, INFO);
231 231
                 $newline='';
232 232
             }
233 233
         }
234 234
         
235
-        $sql= $newline;
236
-        if ($sql != '' )
235
+        $sql=$newline;
236
+        if ($sql != '')
237 237
         {
238 238
             if ($db_conn->query($sql) === false) {
239
-                $this->logging->log('Error create schema : '.$sql,ERROR,'');
239
+                $this->logging->log('Error create schema : '.$sql, ERROR, '');
240 240
                 return;
241 241
             }
242 242
         }
243
-        $this->logging->log('Schema created',INFO);
243
+        $this->logging->log('Schema created', INFO);
244 244
     }
245 245
     
246 246
     /**
@@ -251,14 +251,14 @@  discard block
 block discarded – undo
251 251
      *     @param bool $getmsg : only get messages from version upgrades
252 252
      *     @return string : if $getmsg=true, return messages or 'ERROR' on error.
253 253
      */
254
-    public function update_schema($prefix,$target_version,$table_prefix,$getmsg=false)
254
+    public function update_schema($prefix, $target_version, $table_prefix, $getmsg=false)
255 255
     {
256 256
         // Get current db number
257 257
         $db_conn=$this->db_connect_trap();
258 258
         $sql='SELECT value from '.$this->dbPrefix.'db_config WHERE name=\'db_version\' ';
259
-        $this->logging->log('SQL query : '.$sql,DEBUG );
259
+        $this->logging->log('SQL query : '.$sql, DEBUG);
260 260
         if (($ret_code=$db_conn->query($sql)) === false) {
261
-            $this->logging->log('Cannot get db version. Query : ' . $sql,2,'');
261
+            $this->logging->log('Cannot get db version. Query : '.$sql, 2, '');
262 262
             return 'ERROR';
263 263
         }
264 264
         $version=$ret_code->fetchAll();
@@ -266,11 +266,11 @@  discard block
 block discarded – undo
266 266
         
267 267
         if ($this->trapDBType == 'pgsql')
268 268
         {
269
-            $prefix .= 'update_pgsql/schema_';
269
+            $prefix.='update_pgsql/schema_';
270 270
         }
271 271
         else
272 272
         {
273
-            $prefix .= 'update_sql/schema_';
273
+            $prefix.='update_sql/schema_';
274 274
         }
275 275
         //echo "version all :\n";print_r($version);echo " \n $cur_ver \n";
276 276
         if ($getmsg === true)
@@ -294,17 +294,17 @@  discard block
 block discarded – undo
294 294
      *     @param string $table_prefix   to replace #PREFIX# in schema file by this
295 295
      *     @return bool : true on error
296 296
      */
297
-    public function update_schema_do($prefix,$cur_version,$target_version,$table_prefix)
297
+    public function update_schema_do($prefix, $cur_version, $target_version, $table_prefix)
298 298
     {
299
-        while($cur_version<$target_version)
299
+        while ($cur_version < $target_version)
300 300
         { // TODO : execute pre & post scripts
301 301
             $cur_version++;
302
-            $this->logging->log('Updating to version : ' .$cur_version ,INFO );
303
-            $updateFile=$prefix.'v'.($cur_version-1).'_v'.$cur_version.'.sql';
302
+            $this->logging->log('Updating to version : '.$cur_version, INFO);
303
+            $updateFile=$prefix.'v'.($cur_version - 1).'_v'.$cur_version.'.sql';
304 304
             $input_stream=fopen($updateFile, 'r');
305
-            if ($input_stream=== false)
305
+            if ($input_stream === false)
306 306
             {
307
-                $this->logging->log("Error reading update file ". $updateFile,ERROR);
307
+                $this->logging->log("Error reading update file ".$updateFile, ERROR);
308 308
                 return true;
309 309
             }
310 310
             $newline='';
@@ -313,25 +313,25 @@  discard block
 block discarded – undo
313 313
             while (($line=fgets($input_stream)) !== false)
314 314
             {
315 315
                 if (preg_match('/^#/', $line)) continue; // ignore comment lines
316
-                $newline.=chop(preg_replace('/#PREFIX#/',$table_prefix,$line));
316
+                $newline.=chop(preg_replace('/#PREFIX#/', $table_prefix, $line));
317 317
                 if (preg_match('/; *$/', $newline))
318 318
                 {
319 319
                     $sql_req=$db_conn->prepare($newline);
320 320
                     if ($sql_req->execute() === false) {
321
-                        $this->logging->log('Error create schema : '.$newline,ERROR);
321
+                        $this->logging->log('Error create schema : '.$newline, ERROR);
322 322
                         return true;
323 323
                     }
324 324
                     $cur_table_array=array();
325
-                    if (preg_match('/^ *([^ ]+) TABLE ([^ ]+)/',$newline,$cur_table_array))
325
+                    if (preg_match('/^ *([^ ]+) TABLE ([^ ]+)/', $newline, $cur_table_array))
326 326
                     {
327
-                        $cur_table=$cur_table_array[1] . ' SQL table '.$cur_table_array[2];
327
+                        $cur_table=$cur_table_array[1].' SQL table '.$cur_table_array[2];
328 328
                     }
329 329
                     else
330 330
                     {
331 331
                         $cur_table='secret SQL stuff :-)';
332 332
                         //$cur_table=$newline;
333 333
                     }
334
-                    $this->logging->log('Doing : ' . $cur_table,INFO );
334
+                    $this->logging->log('Doing : '.$cur_table, INFO);
335 335
                     
336 336
                     $newline='';
337 337
                 }
@@ -339,13 +339,13 @@  discard block
 block discarded – undo
339 339
             fclose($input_stream);
340 340
             
341 341
             $sql='UPDATE '.$this->dbPrefix.'db_config SET value='.$cur_version.' WHERE ( name=\'db_version\' )';
342
-            $this->logging->log('SQL query : '.$sql,DEBUG );
342
+            $this->logging->log('SQL query : '.$sql, DEBUG);
343 343
             if ($db_conn->query($sql) === false) {
344
-                $this->logging->log('Cannot update db version. Query : ' . $sql,WARN);
344
+                $this->logging->log('Cannot update db version. Query : '.$sql, WARN);
345 345
                 return true;
346 346
             }
347 347
             
348
-            $this->logging->log('Schema updated to version : '.$cur_version ,INFO);
348
+            $this->logging->log('Schema updated to version : '.$cur_version, INFO);
349 349
         }
350 350
         return false;
351 351
     }
@@ -357,33 +357,33 @@  discard block
 block discarded – undo
357 357
      *     @param int $target_version  target db version number
358 358
      *     @return string : return messages or 'ERROR'.
359 359
      */
360
-    private function update_schema_message($prefix,$cur_version,$target_version)
360
+    private function update_schema_message($prefix, $cur_version, $target_version)
361 361
     {
362 362
  
363 363
         $message='';
364
-        $this->logging->log('getting message for upgrade',DEBUG );
365
-        while($cur_version<$target_version)
364
+        $this->logging->log('getting message for upgrade', DEBUG);
365
+        while ($cur_version < $target_version)
366 366
         {
367 367
             $cur_version++;
368
-            $updateFile=$prefix.'v'.($cur_version-1).'_v'.$cur_version.'.sql';
368
+            $updateFile=$prefix.'v'.($cur_version - 1).'_v'.$cur_version.'.sql';
369 369
             $input_stream=fopen($updateFile, 'r');
370
-            if ($input_stream=== false)
370
+            if ($input_stream === false)
371 371
             {
372
-                $this->logging->log("Error reading update file ". $updateFile,2,'');
372
+                $this->logging->log("Error reading update file ".$updateFile, 2, '');
373 373
                 return 'ERROR';
374 374
             }
375 375
             do 
376 376
             { 
377 377
                 $line=fgets($input_stream); 
378 378
             }
379
-            while ($line !== false && !preg_match('/#MESSAGE/',$line));
379
+            while ($line !== false && !preg_match('/#MESSAGE/', $line));
380 380
             fclose($input_stream);
381 381
             if ($line === false)
382 382
             {
383
-                $this->logging->log("No message in file ". $updateFile,2,'');
383
+                $this->logging->log("No message in file ".$updateFile, 2, '');
384 384
                 return '';
385 385
             }
386
-            $message .= ($cur_version-1) . '->' . $cur_version. ' : ' . preg_replace('/#MESSAGE : /','',$line)."\n";
386
+            $message.=($cur_version - 1).'->'.$cur_version.' : '.preg_replace('/#MESSAGE : /', '', $line)."\n";
387 387
         }
388 388
         return $message;
389 389
     }
Please login to merge, or discard this patch.
library/Trapdirector/TrapsProcess/Plugins.php 1 patch
Spacing   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
      * $pluginsList[plugin name]['target']  : bool true if plugin can be trap processing target
25 25
      * $pluginsList[plugin name]['enabled'] : bool true if plugin is in enabled list 
26 26
      **/
27
-    protected $pluginsList = array();
27
+    protected $pluginsList=array();
28 28
 
29 29
     /** Array of functions names
30 30
      * @var array $functionList 
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
      * @param string $plugin_dir optional plugin directory
52 52
      * @throws \Exception
53 53
      */
54
-    function __construct(Trap $trapClass,string $pluginDir='')
54
+    function __construct(Trap $trapClass, string $pluginDir='')
55 55
     {
56 56
         if ($pluginDir == '')
57 57
         {
@@ -88,42 +88,42 @@  discard block
 block discarded – undo
88 88
      */
89 89
     private function loadEnabledPlugins()
90 90
     {
91
-        $PluginList = $this->trapClass->trapsDB->getDBConfig('enabled_plugins');
91
+        $PluginList=$this->trapClass->trapsDB->getDBConfig('enabled_plugins');
92 92
                
93 93
         if ($PluginList === null || $PluginList == '')
94 94
         {
95
-            $this->logClass->log('No enabled plugins',DEBUG);
95
+            $this->logClass->log('No enabled plugins', DEBUG);
96 96
             return;
97 97
         }
98 98
         else
99 99
         {   // Saved config : <plugin name>;<Catch all OID ? 1|0>;<Trap target ? 1|0>;<func 1 name>|<func 2 name>... ,<plugin2 name>....
100
-            $this->logClass->log('Enabled plugins = '.$PluginList,DEBUG);
100
+            $this->logClass->log('Enabled plugins = '.$PluginList, DEBUG);
101 101
             
102
-            $pluginArray = explode(',', $PluginList);
102
+            $pluginArray=explode(',', $PluginList);
103 103
             foreach ($pluginArray as $pluginElmt)
104 104
             {
105
-                $pluginElmt = explode(';',$pluginElmt);
105
+                $pluginElmt=explode(';', $pluginElmt);
106 106
                 if ($pluginElmt === false || count($pluginElmt) != 4)
107 107
                 {
108
-                    throw new \Exception('Invalid plugin configuration : '. $PluginList );
108
+                    throw new \Exception('Invalid plugin configuration : '.$PluginList);
109 109
                 }
110 110
                 $pluginName=$pluginElmt[0];
111 111
                 
112
-                $pluginListElmt = array();
113
-                $pluginListElmt['object'] = null; // class not loaded
114
-                $pluginListElmt['allOID'] = ($pluginElmt[1]=='1') ? true : false;
115
-                $pluginListElmt['target'] = ($pluginElmt[2]=='1') ? true : false;
116
-                $pluginListElmt['enabled'] = true;
112
+                $pluginListElmt=array();
113
+                $pluginListElmt['object']=null; // class not loaded
114
+                $pluginListElmt['allOID']=($pluginElmt[1] == '1') ? true : false;
115
+                $pluginListElmt['target']=($pluginElmt[2] == '1') ? true : false;
116
+                $pluginListElmt['enabled']=true;
117 117
                 
118
-                $this->pluginsList[$pluginName] = $pluginListElmt;
118
+                $this->pluginsList[$pluginName]=$pluginListElmt;
119 119
                 
120 120
                 // deal with plugin functions
121
-                $pluginFunctions = explode('|',$pluginElmt[3]);
121
+                $pluginFunctions=explode('|', $pluginElmt[3]);
122 122
                 if ($pluginFunctions !== false)
123 123
                 {
124 124
                     foreach ($pluginFunctions as $function)
125 125
                     {
126
-                        $this->functionList[$function] = array(
126
+                        $this->functionList[$function]=array(
127 127
                             'plugin'    =>   $pluginName,
128 128
                             'function'  =>  null
129 129
                         );
@@ -155,16 +155,16 @@  discard block
 block discarded – undo
155 155
                 {
156 156
                     continue;
157 157
                 }
158
-                $functionString .= ($functionString == '') ? '' : '|'; // add separator if not empty
159
-                $functionString .= $fName;
158
+                $functionString.=($functionString == '') ? '' : '|'; // add separator if not empty
159
+                $functionString.=$fName;
160 160
             }
161
-            $saveString .= ($saveString == '')?'':',' ;
161
+            $saveString.=($saveString == '') ? '' : ',';
162 162
             
163
-            $allOID = ($value['allOID'] === true) ? 1 : 0;
164
-            $target = ($value['target'] === true) ? 1 : 0;
165
-            $saveString .= $name . ';' . $allOID . ';' . $target . ';' . $functionString ;
163
+            $allOID=($value['allOID'] === true) ? 1 : 0;
164
+            $target=($value['target'] === true) ? 1 : 0;
165
+            $saveString.=$name.';'.$allOID.';'.$target.';'.$functionString;
166 166
         }
167
-        $this->logClass->log('Saving : ' . $saveString,DEBUG);
167
+        $this->logClass->log('Saving : '.$saveString, DEBUG);
168 168
         return $this->trapClass->trapsDB->setDBConfig('enabled_plugins', $saveString);
169 169
     }
170 170
     
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
         {
179 179
             if ($value['enabled'] == true)
180 180
             {
181
-                array_push($retArray,$name);
181
+                array_push($retArray, $name);
182 182
             }
183 183
         }
184 184
         return $retArray;
@@ -190,29 +190,29 @@  discard block
 block discarded – undo
190 190
      * @param bool $enabled true to enable, false to disable
191 191
      * @return bool true if OK, or false (error logged)
192 192
      */
193
-    public function enablePlugin(string $pluginName,bool $enabled)
193
+    public function enablePlugin(string $pluginName, bool $enabled)
194 194
     {
195 195
         if ($enabled === false)
196 196
         {
197 197
             // If plugin is defined set to disable
198
-            if ( isset($this->pluginsList[$pluginName]))
198
+            if (isset($this->pluginsList[$pluginName]))
199 199
             {
200
-                $this->pluginsList[$pluginName]['enabled'] = false;
200
+                $this->pluginsList[$pluginName]['enabled']=false;
201 201
             }            
202 202
             return $this->saveEnabledPlugins();
203 203
         }
204 204
         // Check if plugin is loaded / exists
205
-        if ( ! isset($this->pluginsList[$pluginName]) || 
205
+        if (!isset($this->pluginsList[$pluginName]) || 
206 206
                 $this->pluginsList[$pluginName]['object'] === null)
207 207
         {
208 208
             try {
209 209
                 $this->registerPlugin($pluginName);
210 210
             } catch (Exception $e) {
211
-                $this->logClass->log('Cannot enable plugin : ' . $e->getMessage(),WARN);
211
+                $this->logClass->log('Cannot enable plugin : '.$e->getMessage(), WARN);
212 212
                 return false;
213 213
             }
214 214
         }
215
-        $this->pluginsList[$pluginName]['enabled'] = true;
215
+        $this->pluginsList[$pluginName]['enabled']=true;
216 216
         // save in DB and return 
217 217
         return $this->saveEnabledPlugins();
218 218
     }
@@ -233,12 +233,12 @@  discard block
 block discarded – undo
233 233
      */
234 234
     public function registerPlugin(string $pluginName)
235 235
     {
236
-        if ( ! isset($this->pluginsList[$pluginName]) ) // Plugin isn't enable, create entry
236
+        if (!isset($this->pluginsList[$pluginName])) // Plugin isn't enable, create entry
237 237
         {
238
-            $pluginListElmt = array();
239
-            $pluginListElmt['object'] = null; // class not loaded
240
-            $pluginListElmt['enabled'] = false;
241
-            $this->pluginsList[$pluginName] = $pluginListElmt;
238
+            $pluginListElmt=array();
239
+            $pluginListElmt['object']=null; // class not loaded
240
+            $pluginListElmt['enabled']=false;
241
+            $this->pluginsList[$pluginName]=$pluginListElmt;
242 242
         }
243 243
         
244 244
         if ($this->pluginsList[$pluginName]['object'] !== null)
@@ -247,13 +247,13 @@  discard block
 block discarded – undo
247 247
         }
248 248
         try {
249 249
             // Include plugin file
250
-            include_once($this->pluginDir.'/' . $pluginName . '.php');
250
+            include_once($this->pluginDir.'/'.$pluginName.'.php');
251 251
             
252 252
             // Create full class name with namespace
253
-            $pluginClassName = __NAMESPACE__ . '\\Plugins\\' . $pluginName;
253
+            $pluginClassName=__NAMESPACE__.'\\Plugins\\'.$pluginName;
254 254
             
255 255
             // Create class
256
-            $newClass = new $pluginClassName();
256
+            $newClass=new $pluginClassName();
257 257
             
258 258
             // Set logging
259 259
             $newClass->setLoggingClass($this->logClass);
@@ -276,33 +276,33 @@  discard block
 block discarded – undo
276 276
             {
277 277
                 if (isset($this->functionList[$fname]))
278 278
                 {
279
-                    if ($this->functionList[$fname]['plugin'] != $pluginName )
279
+                    if ($this->functionList[$fname]['plugin'] != $pluginName)
280 280
                     {
281
-                        throw new Exception('Duplicate function name '.$fname . ' in ' 
282
-                            . $pluginName . ' and ' . $this->functionList[$fname]['plugin']);
281
+                        throw new Exception('Duplicate function name '.$fname.' in ' 
282
+                            . $pluginName.' and '.$this->functionList[$fname]['plugin']);
283 283
                     }
284 284
                     
285 285
                 }
286 286
                 else
287 287
                 {
288 288
                     $this->functionList[$fname]=array();
289
-                    $this->functionList[$fname]['plugin'] = $pluginName;
289
+                    $this->functionList[$fname]['plugin']=$pluginName;
290 290
                 }
291 291
                 $this->functionList[$fname]['function']=$function['function'];
292 292
             }
293
-            $this->logClass->log('Registered plugin '.$pluginName,DEBUG);
293
+            $this->logClass->log('Registered plugin '.$pluginName, DEBUG);
294 294
             
295 295
         } catch (Exception $e) {
296 296
             unset($this->pluginsList[$pluginName]);
297
-            $errorMessage = "Error registering plugin $pluginName : ".$e->getMessage();
298
-            $this->logClass->log($errorMessage,WARN);
297
+            $errorMessage="Error registering plugin $pluginName : ".$e->getMessage();
298
+            $this->logClass->log($errorMessage, WARN);
299 299
             // Disable the plugin
300 300
             $this->enablePlugin($pluginName, false);
301 301
             throw new \Exception($errorMessage);
302 302
         } catch (Throwable $t) {
303 303
             unset($this->pluginsList[$pluginName]);
304
-            $errorMessage = $t->getMessage() . ' in file ' . $t->getFile() . ' line ' . $t->getLine();
305
-            $this->logClass->log($errorMessage,WARN);
304
+            $errorMessage=$t->getMessage().' in file '.$t->getFile().' line '.$t->getLine();
305
+            $this->logClass->log($errorMessage, WARN);
306 306
             // Disable the plugin
307 307
             $this->enablePlugin($pluginName, false);
308 308
             throw new \Exception($errorMessage);
@@ -323,24 +323,24 @@  discard block
 block discarded – undo
323 323
             try {
324 324
                 $this->registerPlugin($pluginName);
325 325
             } catch (Exception $e) {
326
-                $retDisplay .= $e->getMessage() . ' / ';
326
+                $retDisplay.=$e->getMessage().' / ';
327 327
             }
328 328
         }
329 329
         if ($checkEnabled === false) // Load all php files in plugin dir
330 330
         {
331 331
             foreach (glob($this->pluginDir."/*.php") as $filename)
332 332
             {             
333
-                $pluginName=basename($filename,'.php');
334
-                if (!preg_match('/^[a-zA-Z0-9]+$/',$pluginName))
333
+                $pluginName=basename($filename, '.php');
334
+                if (!preg_match('/^[a-zA-Z0-9]+$/', $pluginName))
335 335
                 {
336 336
                     $this->logClass->log("Invalid plugin name : ".$pluginName, WARN);
337
-                    $retDisplay .= "Invalid plugin name : ".$pluginName . " / ";
337
+                    $retDisplay.="Invalid plugin name : ".$pluginName." / ";
338 338
                     break;
339 339
                 }
340 340
                 try { // Already registerd plugin will simply return false
341 341
                     $this->registerPlugin($pluginName);               
342 342
                 } catch (Exception $e) {
343
-                    $retDisplay .= $e->getMessage() . ' / ';
343
+                    $retDisplay.=$e->getMessage().' / ';
344 344
                 }
345 345
             }
346 346
         }
@@ -380,17 +380,17 @@  discard block
 block discarded – undo
380 380
         {
381 381
             $this->registerPlugin($name); // can throw exception handled by caller
382 382
         }
383
-        $retObj = new stdClass();
384
-        $retObj->name           = $name;
385
-        $retObj->catchAllTraps  = $this->pluginsList[$name]['allOID'];
386
-        $retObj->processTraps   = $this->pluginsList[$name]['target'];
387
-        $retObj->description    = $this->pluginsList[$name]['object']->description;
383
+        $retObj=new stdClass();
384
+        $retObj->name=$name;
385
+        $retObj->catchAllTraps=$this->pluginsList[$name]['allOID'];
386
+        $retObj->processTraps=$this->pluginsList[$name]['target'];
387
+        $retObj->description=$this->pluginsList[$name]['object']->description;
388 388
         $functions=array();
389 389
         foreach ($this->functionList as $fName => $func)
390 390
         {
391 391
             if ($func['plugin'] == $name)
392 392
             {
393
-                array_push($functions,$fName);
393
+                array_push($functions, $fName);
394 394
             }
395 395
         }
396 396
         $retObj->funcArray=$functions;
@@ -403,13 +403,13 @@  discard block
 block discarded – undo
403 403
      * @param string $pluginName
404 404
      * @return boolean returns plugin object of false;
405 405
      */
406
-    public function getFunction($funcName,&$pluginName)
406
+    public function getFunction($funcName, &$pluginName)
407 407
     {
408
-        if (! isset($this->functionList[$funcName]) )
408
+        if (!isset($this->functionList[$funcName]))
409 409
         {
410 410
             return false;
411 411
         }
412
-        $pluginName = $this->functionList[$funcName]['plugin'];
412
+        $pluginName=$this->functionList[$funcName]['plugin'];
413 413
         return true;
414 414
     }
415 415
     
@@ -421,21 +421,21 @@  discard block
 block discarded – undo
421 421
      */
422 422
     public function getFunctionDetails($funcName)
423 423
     {
424
-        if (! isset($this->functionList[$funcName]) )
424
+        if (!isset($this->functionList[$funcName]))
425 425
         {
426 426
             return false;
427 427
         }
428
-        $pluginName = $this->functionList[$funcName]['plugin']; // plugin name
429
-        $plugin = $this->pluginsList[$pluginName]['object']; // plugin object
428
+        $pluginName=$this->functionList[$funcName]['plugin']; // plugin name
429
+        $plugin=$this->pluginsList[$pluginName]['object']; // plugin object
430 430
         if ($plugin === null)
431 431
         {
432 432
             $this->registerPlugin($pluginName); // can throw exception handled by caller
433 433
         }
434
-        $retObj = new stdClass();
435
-        $retObj->name           = $funcName;
436
-        $retObj->plugin         = $pluginName;
437
-        $retObj->params         = $plugin->functions[$funcName]['params'];
438
-        $retObj->description    = $plugin->functions[$funcName]['description'];
434
+        $retObj=new stdClass();
435
+        $retObj->name=$funcName;
436
+        $retObj->plugin=$pluginName;
437
+        $retObj->params=$plugin->functions[$funcName]['params'];
438
+        $retObj->description=$plugin->functions[$funcName]['description'];
439 439
         return $retObj;
440 440
     }
441 441
     
@@ -446,23 +446,23 @@  discard block
 block discarded – undo
446 446
      * @throws Exception
447 447
      * @return bool
448 448
      */
449
-    public function getFunctionEval(string $funcName,$params) : bool
449
+    public function getFunctionEval(string $funcName, $params) : bool
450 450
     {
451
-        if (! isset($this->functionList[$funcName]) )
451
+        if (!isset($this->functionList[$funcName]))
452 452
         {
453
-            throw new Exception($funcName . ' not found.');
453
+            throw new Exception($funcName.' not found.');
454 454
         }
455
-        $pluginName = $this->functionList[$funcName]['plugin']; // plugin name
456
-        $plugin = $this->pluginsList[$pluginName]['object']; // plugin object
455
+        $pluginName=$this->functionList[$funcName]['plugin']; // plugin name
456
+        $plugin=$this->pluginsList[$pluginName]['object']; // plugin object
457 457
 
458 458
         if ($plugin === null)
459 459
         {
460 460
             $this->registerPlugin($pluginName); // can throw exception handled by caller
461
-            $plugin = $this->pluginsList[$pluginName]['object'];
461
+            $plugin=$this->pluginsList[$pluginName]['object'];
462 462
         }
463 463
         
464
-        $propertyName = $this->functionList[$funcName]['function'];
465
-        $this->logClass->log('Using property '. $propertyName . ' of class : '.$pluginName,DEBUG);
464
+        $propertyName=$this->functionList[$funcName]['function'];
465
+        $this->logClass->log('Using property '.$propertyName.' of class : '.$pluginName, DEBUG);
466 466
         
467 467
         return $plugin->{$propertyName}($params);        
468 468
     }
@@ -475,17 +475,17 @@  discard block
 block discarded – undo
475 475
         //$this->logClass->log('eval cleanup : '.$functionString,DEBUG);
476 476
         
477 477
         // Match function call
478
-        $num=preg_match('/^__([a-zA-Z0-9]+)\((.+)\)$/', $functionString , $matches);
479
-        if ($num !=1)
478
+        $num=preg_match('/^__([a-zA-Z0-9]+)\((.+)\)$/', $functionString, $matches);
479
+        if ($num != 1)
480 480
         {
481
-            throw new \ErrorException('Function syntax error : ' . $functionString );
481
+            throw new \ErrorException('Function syntax error : '.$functionString);
482 482
         }
483
-        $this->logClass->log('Got function : '. $matches[1] . ', params : '.$matches[2],DEBUG);
483
+        $this->logClass->log('Got function : '.$matches[1].', params : '.$matches[2], DEBUG);
484 484
         $funcName=$matches[1];
485 485
         
486 486
         // Get parameters comma separated
487
-        $funcParams=str_getcsv($matches[2],',','"',"\\");
488
-        $this->logClass->log('Function params : ' . print_r($funcParams,true),DEBUG);
487
+        $funcParams=str_getcsv($matches[2], ',', '"', "\\");
488
+        $this->logClass->log('Function params : '.print_r($funcParams, true), DEBUG);
489 489
         
490 490
         // return evaluation
491 491
         return $this->getFunctionEval($funcName, $funcParams);        
@@ -520,7 +520,7 @@  discard block
 block discarded – undo
520 520
      */
521 521
     public function setLoggingClass($loggingClass)
522 522
     {
523
-        $this->loggingClass = $loggingClass;
523
+        $this->loggingClass=$loggingClass;
524 524
     }
525 525
     
526 526
     /**
@@ -528,8 +528,8 @@  discard block
 block discarded – undo
528 528
      * @param string $message
529 529
      * @param int $level DEBUG/INFO/WARN/CRIT
530 530
      */
531
-    public function log($message,$level)
531
+    public function log($message, $level)
532 532
     {
533
-        $this->loggingClass->log('[ '.get_class($this).'] '. $message, $level);
533
+        $this->loggingClass->log('[ '.get_class($this).'] '.$message, $level);
534 534
     }
535 535
 }
536 536
\ No newline at end of file
Please login to merge, or discard this patch.
library/Trapdirector/Plugins/NetworkRule.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
      */
59 59
     function __construct()
60 60
     {
61
-        $this->name=basename(__FILE__,'.php');
61
+        $this->name=basename(__FILE__, '.php');
62 62
         return $this;
63 63
     }
64 64
     
@@ -72,49 +72,49 @@  discard block
 block discarded – undo
72 72
     public function isInNetwork(array $params) : bool
73 73
     {
74 74
         // Check param numbers and thrown exception if not correct.
75
-        if (count($params)!=3)
75
+        if (count($params) != 3)
76 76
         {
77
-            throw new Exception('Invalid number of parameters : ' . count($params));
77
+            throw new Exception('Invalid number of parameters : '.count($params));
78 78
         }
79 79
         
80
-        $ip = $params[0];
81
-        $net = $params[1];
82
-        $masq = $params[2];
80
+        $ip=$params[0];
81
+        $net=$params[1];
82
+        $masq=$params[2];
83 83
         
84 84
         
85
-        $this->log('#'. $ip . '# / #' . $net . '# / #' . $masq,DEBUG);
85
+        $this->log('#'.$ip.'# / #'.$net.'# / #'.$masq, DEBUG);
86 86
         
87
-        $ip2 = ip2long($ip);
88
-        $net2 = ip2long($net);
87
+        $ip2=ip2long($ip);
88
+        $net2=ip2long($net);
89 89
         
90
-        if ($ip2 === false )
90
+        if ($ip2 === false)
91 91
         {
92
-            $this->log('Invalid IP : #' . $ip.'#',WARN);
92
+            $this->log('Invalid IP : #'.$ip.'#', WARN);
93 93
             throw new Exception('Invalid IP');
94 94
         }
95 95
         if ($net2 === false)
96 96
         {
97
-            $this->log('Invalid network',WARN);
97
+            $this->log('Invalid network', WARN);
98 98
             throw new Exception('Invalid net');
99 99
         }
100
-        if ($masq<1 || $masq > 32)
100
+        if ($masq < 1 || $masq > 32)
101 101
         {
102
-            $this->log('Invalid masq',WARN);
102
+            $this->log('Invalid masq', WARN);
103 103
             throw new Exception('Invalid net masq');
104 104
         }
105 105
         // $range is in IP/CIDR format eg 127.0.0.1/24
106 106
 
107
-        $masq = pow( 2, ( 32 - $masq ) ) - 1;
108
-        $masq = ~ $masq;
109
-        return ( ( $ip2 & $masq ) == ( $net2 & $masq ) );
107
+        $masq=pow(2, (32 - $masq)) - 1;
108
+        $masq=~ $masq;
109
+        return (($ip2 & $masq) == ($net2 & $masq));
110 110
         
111 111
     }
112 112
     
113 113
     public function testParam(array $param)
114 114
     {
115
-        if (count($param)!=1)
115
+        if (count($param) != 1)
116 116
         {
117
-            throw new Exception('Invalid number of parameters : ' . count($param));
117
+            throw new Exception('Invalid number of parameters : '.count($param));
118 118
         }
119 119
         if ($param[0] == 'true') return true;
120 120
         return false;
Please login to merge, or discard this patch.