GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 4d35db...7c40ab )
by Marco
03:05
created
contrib/splunk/webhook/readPost.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -15,11 +15,11 @@  discard block
 block discarded – undo
15 15
 
16 16
 
17 17
 /************** Conf *******************/
18
-require_once(dirname(__FILE__)  . '/../config.php');
18
+require_once(dirname(__FILE__).'/../config.php');
19 19
 
20 20
  /* Syslog basic */
21
-$tag            .= 'SplunkLister';
22
-$user		 = 'Splunk';
21
+$tag .= 'SplunkLister';
22
+$user = 'Splunk';
23 23
 
24 24
 openlog($tag, LOG_PID, $fac);
25 25
 
@@ -27,31 +27,31 @@  discard block
 block discarded – undo
27 27
 if (!isset($_GET['conf'])) {
28 28
         syslog(LOG_ALERT,
29 29
         sprintf('%s: you must insert the config file name as a GET parameter, such as %s?conf=listEmail.conf',
30
-                $user, $_SERVER['SCRIPT_NAME']) );
30
+                $user, $_SERVER['SCRIPT_NAME']));
31 31
         exit(254);
32 32
 }
33 33
 $fileconf = $_GET['conf'];
34
-if ( !file_exists(dirname(__FILE__) . '/../' . $fileconf) ) {
34
+if (!file_exists(dirname(__FILE__).'/../'.$fileconf)) {
35 35
         syslog(LOG_ALERT,
36 36
         sprintf('%s: the configuration file <%s> doesn\'t exist.',
37
-                $user, $fileconf ));
37
+                $user, $fileconf));
38 38
         exit(254);
39 39
 }
40 40
 
41 41
 closelog();
42
-$conf = parse_ini_file( dirname(__FILE__) . '/../' . $fileconf );
42
+$conf = parse_ini_file(dirname(__FILE__).'/../'.$fileconf);
43 43
 
44 44
  /* Splunk inherited parameters */
45
-$threshold = $conf['threshold'];         /* Threshold value on trigger condition; the same which engage the alert */
45
+$threshold = $conf['threshold']; /* Threshold value on trigger condition; the same which engage the alert */
46 46
 
47 47
  /* Blacklist name */
48 48
 $typedesc  = $conf['typedesc'];
49 49
 
50 50
  /* How long to list's parameters */
51
-$unit = $conf['unit'];          /* MySQL language ;) */
51
+$unit = $conf['unit']; /* MySQL language ;) */
52 52
 
53 53
  /* Syslog extended info */
54
-$tag            .= $conf['tag'];
54
+$tag .= $conf['tag'];
55 55
 
56 56
  /* Splunk password of alert owner*/
57 57
 $splpwd = $conf['splunkpassword'];
@@ -62,8 +62,8 @@  discard block
 block discarded – undo
62 62
 
63 63
 
64 64
 /* check you select a blocklist */
65
-if ( !$tables["$typedesc"]['bl'] ) {
66
-        syslog(LOG_EMERG,"$user: <$typedesc> is not a blocklist. Are you stupid? Do you want to whitelist a spammer? I refuse to continue.");
65
+if (!$tables["$typedesc"]['bl']) {
66
+        syslog(LOG_EMERG, "$user: <$typedesc> is not a blocklist. Are you stupid? Do you want to whitelist a spammer? I refuse to continue.");
67 67
         exit (254);
68 68
 }
69 69
 
@@ -99,14 +99,14 @@  discard block
 block discarded – undo
99 99
 	$webhook['results_link'], $out, PREG_PATTERN_ORDER) === FALSE) {
100 100
 	syslog(LOG_ALERT,
101 101
         	sprintf('%s: unexpected error: can\'t parse the results link returned by webhook (<%s>).',
102
-		$user, $webhook['results_link']) );
102
+		$user, $webhook['results_link']));
103 103
 	return 255;
104 104
 }
105 105
 
106
-if ( $webhook['app'] != $out['splunkapp'][0] ) {
106
+if ($webhook['app'] != $out['splunkapp'][0]) {
107 107
 	syslog(LOG_ALERT,
108 108
         	sprintf('%s: unexpected error: the APP returned by webhook (<%s>) doesn\'t match the app (<%s>) in result link.',
109
-                $user, $webhook['app'], $out['splunkapp'][0] ) );
109
+                $user, $webhook['app'], $out['splunkapp'][0]));
110 110
 	return 255;
111 111
 }
112 112
 
@@ -138,13 +138,13 @@  discard block
 block discarded – undo
138 138
 
139 139
 $tolist = array();
140 140
 
141
-$nr = count ($results);
142
-for ($i=1; $i<$nr; $i++) {	/* We skip first header line (i=0) */
141
+$nr = count($results);
142
+for ($i = 1; $i<$nr; $i++) {	/* We skip first header line (i=0) */
143 143
         $data = str_getcsv($results[$i], ',');
144 144
         $thisVal = $data[1];
145 145
         unset($data[1]);
146 146
         $data = array_values($data);
147
-        if ( !in_array($thisVal,array_keys($tolist))  )
147
+        if (!in_array($thisVal, array_keys($tolist)))
148 148
 	        $tolist["$thisVal"] = $data;
149 149
         else if ($data[3]>$tolist[$thisVal][3])
150 150
 	        $tolist["$thisVal"] = $data;
@@ -154,47 +154,47 @@  discard block
 block discarded – undo
154 154
 
155 155
 $mysqli = new mysqli($dbhost, $userdb, $pwd, $db, $dbport);
156 156
 if ($mysqli->connect_error) {
157
-        syslog (LOG_EMERG, $user.': Connect Error (' . $mysqli->connect_errno . ') '
157
+        syslog(LOG_EMERG, $user.': Connect Error ('.$mysqli->connect_errno.') '
158 158
         . $mysqli->connect_error);
159 159
         exit (254);
160 160
 
161 161
 }
162 162
 
163
-syslog(LOG_INFO, $user.': Successfully mysql connected to ' . $mysqli->host_info) ;
163
+syslog(LOG_INFO, $user.': Successfully mysql connected to '.$mysqli->host_info);
164 164
 
165
-foreach ( array_keys($tolist) as $value) {
165
+foreach (array_keys($tolist) as $value) {
166 166
         $quantity = $conf['quantity'];
167 167
         $reason = 'On ['.$tolist["$value"][0]."] <$value> sent ".$tolist["$value"][1].' messages to '.$tolist["$value"][2].' recipients.';
168
-        if ( $tolist["$value"][3] >= $threshold ) {
169
-                if ( searchAndList ($mysqli,$user,$tables,$typedesc,$value,$unit,$quantity,$reason) ) {
170
-                        syslog (LOG_INFO, "$user: ".'Listing reason: '.$reason);
168
+        if ($tolist["$value"][3]>=$threshold) {
169
+                if (searchAndList($mysqli, $user, $tables, $typedesc, $value, $unit, $quantity, $reason)) {
170
+                        syslog(LOG_INFO, "$user: ".'Listing reason: '.$reason);
171 171
                         /* Send a email to domain admin if you list an email */
172
-                        if ( ( $tables["$typedesc"]['field'] == 'email' ) OR ( $tables["$typedesc"]['field'] == 'username' ) ) {
172
+                        if (($tables["$typedesc"]['field'] == 'email') OR ($tables["$typedesc"]['field'] == 'username')) {
173 173
                                 /* Sometime uid are in the form of <user>@<domain> ... */
174
-                                if ( strpos($value, '@') !== FALSE ) {
174
+                                if (strpos($value, '@') !== FALSE) {
175 175
                                         $domain = substr(strrchr($value, '@'), 1);
176
-                                        if ( strpos($domain, '@') === FALSE ) {
177
-                                                $recip = emailToNotify($domainNotify_file,$domain);
176
+                                        if (strpos($domain, '@') === FALSE) {
177
+                                                $recip = emailToNotify($domainNotify_file, $domain);
178 178
                                                 $subject = sprintf('%s <%s> is now blocked because exceedes limits on outgoing emails',
179 179
                                                                 $tables["$typedesc"]['field'], $value);
180 180
                                                 if (!empty($recip))
181
-                                                        if ( sendEmailWarn($tplfile,'[email protected]',$recip,
182
-                                                                $subject,$value,"$quantity $unit",$reason) )
181
+                                                        if (sendEmailWarn($tplfile, '[email protected]', $recip,
182
+                                                                $subject, $value, "$quantity $unit", $reason))
183 183
                                                                 syslog(LOG_INFO, "$user: \"$recip\" was notified about the \"$value\" abuse.");
184 184
                                         }
185
-                                        else syslog(LOG_ERR,"$user: <$domain> contains the '@' char. Notification cannot be sent.");
185
+                                        else syslog(LOG_ERR, "$user: <$domain> contains the '@' char. Notification cannot be sent.");
186 186
                                 }
187 187
                         }
188 188
                 }
189 189
         }
190 190
         else {
191 191
                 $reason .= " But it has NOT been listed because it doesn't apply to the trigger condition.";
192
-                syslog (LOG_INFO, "$user: ".$reason);
192
+                syslog(LOG_INFO, "$user: ".$reason);
193 193
         }
194 194
 }
195 195
 
196 196
 /* Close connection */
197
-syslog (LOG_INFO, "$user: ".'Successfully end of session.');
197
+syslog(LOG_INFO, "$user: ".'Successfully end of session.');
198 198
 $mysqli->close();
199 199
 closelog();
200 200
 
Please login to merge, or discard this patch.
function.php 1 patch
Spacing   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -5,36 +5,36 @@  discard block
 block discarded – undo
5 5
 function username() {
6 6
 	if (isset ($_SERVER['REMOTE_USER'])) $user = $_SERVER['REMOTE_USER'];
7 7
         	else if (isset ($_SERVER['USER'])) $user = $_SERVER['USER'];
8
-                	else $user='unknown';
8
+                	else $user = 'unknown';
9 9
 	return $user;
10 10
 }
11 11
 
12 12
 
13 13
 function myConnect($host, $user, $pass, $db, $port, $tablelist, $typedesc, $loguser) {
14
-        $db = ( $tablelist["$typedesc"]['milter'] ) ? $tablelist["$typedesc"]['name'] : $db;
14
+        $db = ($tablelist["$typedesc"]['milter']) ? $tablelist["$typedesc"]['name'] : $db;
15 15
 	$mysqli = new mysqli($host, $user, $pass, $db, $port);
16 16
         if ($mysqli->connect_error) {
17
-           	syslog (LOG_EMERG, $loguser.': Connect Error to DB <'.$db.'> (' . $mysqli->connect_errno . ') '
17
+           	syslog(LOG_EMERG, $loguser.': Connect Error to DB <'.$db.'> ('.$mysqli->connect_errno.') '
18 18
                     		. $mysqli->connect_error);
19 19
 		return FALSE;
20 20
 	}
21
-	syslog(LOG_INFO, $loguser.': Successfully MySQL connected at DB <'.$db.'> to ' . $mysqli->host_info) ;
21
+	syslog(LOG_INFO, $loguser.': Successfully MySQL connected at DB <'.$db.'> to '.$mysqli->host_info);
22 22
 	return $mysqli;
23 23
 }
24 24
 
25
-function addtolist ($myconn,$user,$value,$tabledesc,$expUnit,$expQ,$myreason,&$err) {
25
+function addtolist($myconn, $user, $value, $tabledesc, $expUnit, $expQ, $myreason, &$err) {
26 26
 // See MySQL manual for $expQ and $expUnit at
27 27
 // https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_timestampadd
28 28
 
29
-	$result=FALSE;
30
-	$sub=array();
29
+	$result = FALSE;
30
+	$sub = array();
31 31
 	$type = $tabledesc['field'];
32 32
 	$milt = $tabledesc['milter'];
33 33
 	$table = ($milt) ? milterTable($type) : $tabledesc['name'];
34 34
 
35 35
 	switch ($type) {
36 36
 	  case 'ip':
37
-		$query= sprintf("INSERT INTO `$table` (
37
+		$query = sprintf("INSERT INTO `$table` (
38 38
 			`$type` ,
39 39
 			`date` ,
40 40
 			`exp` ,
@@ -45,18 +45,18 @@  discard block
 block discarded – undo
45 45
 		VALUES (
46 46
 			INET_ATON( '%s' ) ,
47 47
 			CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s'
48
-		)" ,$value,$expUnit,$expQ,$user,$myreason);
48
+		)", $value, $expUnit, $expQ, $user, $myreason);
49 49
 		break;
50 50
 
51 51
 	  case 'network':
52 52
 		if (!$milt) {
53
-			if ( netOverlap($myconn, $tabledesc, $value, $overlappedNet, $user) ) {
53
+			if (netOverlap($myconn, $tabledesc, $value, $overlappedNet, $user)) {
54 54
 				$err = "<$value> overlaps the existing network <$overlappedNet>";
55 55
 				return FALSE;
56 56
 			}
57 57
 		}
58
-		list($sub['net'],$sub['mask'])=explode('/',$value);
59
-                $query= sprintf("INSERT INTO `$table` (
58
+		list($sub['net'], $sub['mask']) = explode('/', $value);
59
+                $query = sprintf("INSERT INTO `$table` (
60 60
                         `$type` ,
61 61
 			`netmask`,
62 62
                         `date` ,
@@ -68,11 +68,11 @@  discard block
 block discarded – undo
68 68
                 VALUES (
69 69
                         INET_ATON( '%s' ) , INET_ATON( '%s' ) ,
70 70
                         CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s'
71
-                )" ,$sub['net'],$sub['mask'],$expUnit,$expQ,$user,$myreason);
71
+                )", $sub['net'], $sub['mask'], $expUnit, $expQ, $user, $myreason);
72 72
                 break;
73 73
 
74 74
 	  default:
75
-                $query= sprintf("INSERT INTO `$table` (
75
+                $query = sprintf("INSERT INTO `$table` (
76 76
                         `$type` ,
77 77
                         `date` ,
78 78
                         `exp` ,
@@ -83,23 +83,23 @@  discard block
 block discarded – undo
83 83
                 VALUES (
84 84
                         '%s' ,
85 85
                         CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s'
86
-                )" ,$value,$expUnit,$expQ,$user,$myreason);
86
+                )", $value, $expUnit, $expQ, $user, $myreason);
87 87
 	}
88 88
 
89 89
 	if ($myconn->query($query) === TRUE) {
90 90
 	    syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit.");
91
-	    $result=TRUE;
91
+	    $result = TRUE;
92 92
 	}
93 93
 	else syslog(LOG_ERR, "$user: Error: ".$myconn->error);
94 94
 	return $result;
95 95
 }
96 96
 
97
-function relist ($myconn,$user,$value,$type,$table,$expUnit,$expQ,$myreason, $exptime = 0) {
97
+function relist($myconn, $user, $value, $type, $table, $expUnit, $expQ, $myreason, $exptime = 0) {
98 98
 
99
-	$result=FALSE;
100
-	if ( $exptime ) { /* Entry already listed */
99
+	$result = FALSE;
100
+	if ($exptime) { /* Entry already listed */
101 101
 		$nlist = '`nlist`';
102
-		$exptime = sprintf('\'%s\'', $exptime);  /* Eh MySQL... an hour lost to notice this */
102
+		$exptime = sprintf('\'%s\'', $exptime); /* Eh MySQL... an hour lost to notice this */
103 103
 	}
104 104
 	else {
105 105
 		$exptime = 'CURRENT_TIMESTAMP';
@@ -108,43 +108,43 @@  discard block
 block discarded – undo
108 108
 
109 109
         switch ($type) {
110 110
 	  case 'ip':
111
-                $query= sprintf("UPDATE `$table` SET
111
+                $query = sprintf("UPDATE `$table` SET
112 112
 			`active` = '1',
113 113
 			`user` = '%s',
114 114
 			`exp` = TIMESTAMPADD(%s,%d,%s),
115 115
 			`nlist` = %s,
116 116
 			`reason` = '%s'
117
-			WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user,$expUnit,$expQ,$exptime,$nlist,$myreason,$value);
117
+			WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1", $user, $expUnit, $expQ, $exptime, $nlist, $myreason, $value);
118 118
 		break;
119 119
           case 'network':
120
-		list($sub['net'],$sub['mask'])=explode('/',$value);
121
-                $query= sprintf("UPDATE `$table` SET
120
+		list($sub['net'], $sub['mask']) = explode('/', $value);
121
+                $query = sprintf("UPDATE `$table` SET
122 122
                         `active` = '1',
123 123
                         `user` = '%s',
124 124
                         `exp` = TIMESTAMPADD(%s,%d,%s),
125 125
                         `nlist` = %s,
126 126
                         `reason` = '%s'
127
-                        WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1" ,$user,$expUnit,$expQ,$exptime,$nlist,$myreason,$sub['net'],$sub['mask']);
127
+                        WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1", $user, $expUnit, $expQ, $exptime, $nlist, $myreason, $sub['net'], $sub['mask']);
128 128
 		break;
129 129
 	  default:
130
-                $query= sprintf("UPDATE `$table` SET
130
+                $query = sprintf("UPDATE `$table` SET
131 131
                         `active` = '1',
132 132
                         `user` = '%s',
133 133
                         `exp` = TIMESTAMPADD(%s,%d,%s),
134 134
                         `nlist` = %s,
135 135
                         `reason` = '%s'
136
-			WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user,$expUnit,$expQ,$exptime,$nlist,$myreason,$value);
136
+			WHERE `$table`.`$type` = '%s' LIMIT 1", $user, $expUnit, $expQ, $exptime, $nlist, $myreason, $value);
137 137
 	}
138 138
 
139 139
         if ($myconn->query($query) === TRUE) {
140 140
             syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit from $exptime.");
141
-		$result=TRUE;
141
+		$result = TRUE;
142 142
         }
143
-        else syslog (LOG_ERR, "$user: Error: ". $myconn->error);
143
+        else syslog(LOG_ERR, "$user: Error: ".$myconn->error);
144 144
 	return $result;
145 145
 }
146 146
 
147
-function remove ($myconn,$user,$value,$type,$table) {
147
+function remove($myconn, $user, $value, $type, $table) {
148 148
 
149 149
         switch ($type) {
150 150
           case 'ip':
@@ -152,10 +152,10 @@  discard block
 block discarded – undo
152 152
                         `$table`.`$type` = INET_ATON('%s') LIMIT 1", $value);
153 153
 		break;
154 154
 	  case 'network':
155
-		list($sub['net'],$sub['mask'])=explode('/',$value);
155
+		list($sub['net'], $sub['mask']) = explode('/', $value);
156 156
 		$query = sprintf("DELETE FROM `$table` WHERE
157 157
 			`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s') LIMIT 1",
158
-			$sub['net'],$sub['mask']);
158
+			$sub['net'], $sub['mask']);
159 159
 		break;
160 160
 	  default:
161 161
 		$query = sprintf("DELETE FROM `$table` WHERE
@@ -163,39 +163,39 @@  discard block
 block discarded – undo
163 163
 	}
164 164
 
165 165
 
166
-        if ($return=$myconn->query($query) === TRUE) 
166
+        if ($return = $myconn->query($query) === TRUE) 
167 167
             syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>.");
168
-        else syslog(LOG_ERR, "$user: Error: ". $myconn->error);
168
+        else syslog(LOG_ERR, "$user: Error: ".$myconn->error);
169 169
 
170 170
         return $return;
171 171
 }
172 172
 
173 173
 
174
-function changestatus ($myconn,$user,$value,$status,$type,$table) {
174
+function changestatus($myconn, $user, $value, $status, $type, $table) {
175 175
 
176 176
 	switch ($type) {
177 177
           case 'ip':
178
-		$query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user, $value);
178
+		$query = sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1", $user, $value);
179 179
 		break;
180 180
 	  case 'network':
181
-		list($sub['net'],$sub['mask'])=explode('/',$value);
182
-		$query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1" ,$user, $sub['net'],$sub['mask']);
181
+		list($sub['net'], $sub['mask']) = explode('/', $value);
182
+		$query = sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1", $user, $sub['net'], $sub['mask']);
183 183
 		break;
184 184
 	  default:
185
-		$query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user, $value);
185
+		$query = sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = '%s' LIMIT 1", $user, $value);
186 186
 	}
187 187
 
188
-        if ($return=$myconn->query($query) === TRUE) {
188
+        if ($return = $myconn->query($query) === TRUE) {
189 189
             syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>");
190 190
         }
191
-        else syslog(LOG_ERR, "$user: Error: ". $myconn->error);
191
+        else syslog(LOG_ERR, "$user: Error: ".$myconn->error);
192 192
 	return $return;	
193 193
 }
194 194
 
195 195
 
196
-function expire ($myconn,$user,$tables,$expireTime) {
197
-        $return=TRUE;
198
-	$log=array();
196
+function expire($myconn, $user, $tables, $expireTime) {
197
+        $return = TRUE;
198
+	$log = array();
199 199
 	$desc = array_keys($tables);
200 200
 	foreach ($desc as $tdesc) { 
201 201
 		/* QUERY */
@@ -214,11 +214,11 @@  discard block
 block discarded – undo
214 214
 			} while ($myconn->next_result());
215 215
 		}
216 216
 		else {
217
-			syslog(LOG_ERR, "Expire job - Error: ". $myconn->error);
217
+			syslog(LOG_ERR, "Expire job - Error: ".$myconn->error);
218 218
 			$return = FALSE;
219 219
 		}
220 220
 	}
221
-	if ( !($return) ) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated');
221
+	if (!($return)) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated');
222 222
 	else  syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.');
223 223
         return $return;
224 224
 }
@@ -226,18 +226,18 @@  discard block
 block discarded – undo
226 226
 
227 227
 function isListed($row) {
228 228
 
229
-	$exp=new DateTime($row['exp']);
230
-	$now=new DateTime('NOW');
231
-	if (($exp > $now) and ($row['active'])) return true;
229
+	$exp = new DateTime($row['exp']);
230
+	$now = new DateTime('NOW');
231
+	if (($exp>$now) and ($row['active'])) return true;
232 232
 	else return false;
233 233
 
234 234
 }
235 235
 
236 236
 
237
-function askMilter($myconn,$id,$obj,$typedesc,$miltId,$value,$user,$adm)  {
238
-	$milts = readMiltName($myconn,$user);
237
+function askMilter($myconn, $id, $obj, $typedesc, $miltId, $value, $user, $adm) {
238
+	$milts = readMiltName($myconn, $user);
239 239
 	$size = count($milts);
240
-	if (in_array($user,array_keys($adm))) {
240
+	if (in_array($user, array_keys($adm))) {
241 241
 		$button = <<<END
242 242
 		<form style="margin:0; display:inline;" name="Milter$id" enctype="text/plain" method="post" target="_self" action="changeMilter.php" onSubmit="xmlhttpPost('changeMilter.php', 'Milter$id', 'id$id', '<img src=\'/include/pleasewait.gif\'>'); return false;" />
243 243
 		<input name="object" type="hidden" value="$obj" /><input name="oldvalues" type="hidden" value="$value" />
@@ -247,12 +247,12 @@  discard block
 block discarded – undo
247 247
 		<div class="noscroll">
248 248
 		<select class="input_text" name="newvalues[]" multiple size="$size">
249 249
 END;
250
-		$activeMilts = explode(',',$value);
251
-		foreach ( $milts as $milter ) {
252
-			if ( in_array($milter, $activeMilts) )
253
-				$selected= 'selected';
250
+		$activeMilts = explode(',', $value);
251
+		foreach ($milts as $milter) {
252
+			if (in_array($milter, $activeMilts))
253
+				$selected = 'selected';
254 254
 			else
255
-				$selected= NULL;
255
+				$selected = NULL;
256 256
 			$button .= sprintf('<option value="%s" %s>%s</option>', $milter, $selected, $milter);
257 257
 		}	
258 258
 		$button .= '</select></div><input class="button" name="Change" type="submit" value="Change" /></form>';
@@ -264,14 +264,14 @@  discard block
 block discarded – undo
264 264
 }
265 265
 
266 266
 
267
-function ask($myconn,$id,$what,$alltables,$typedesc,$value,$lock,$user,$adm) {
267
+function ask($myconn, $id, $what, $alltables, $typedesc, $value, $lock, $user, $adm) {
268 268
 
269
-	$whynot=NULL;
269
+	$whynot = NULL;
270 270
 	switch ($what) {
271 271
 		case 'Ok':
272 272
 			if ($lock) return NULL;
273
-			if (in_array($user,array_keys($adm)))
274
-				if ( consistentListing($myconn,$alltables,$typedesc,$value,$whynot) ) return require('relistButton.php');
273
+			if (in_array($user, array_keys($adm)))
274
+				if (consistentListing($myconn, $alltables, $typedesc, $value, $whynot)) return require('relistButton.php');
275 275
 			return htmlspecialchars($whynot);
276 276
 		case 'Listed':
277 277
 		case 'WhiteListed':
@@ -280,18 +280,18 @@  discard block
 block discarded – undo
280 280
 }
281 281
 
282 282
 
283
-function consistentListing($myconn,$alltables,$typed,$value,&$warn) {
283
+function consistentListing($myconn, $alltables, $typed, $value, &$warn) {
284 284
 /* Check if there are no pending mislisting */
285 285
 	$warn = NULL;
286
-	if (! isset($alltables["$typed"]['depend']) ) return TRUE;
286
+	if (!isset($alltables["$typed"]['depend'])) return TRUE;
287 287
 	foreach ($alltables["$typed"]['depend'] as $listdep) {
288
-		if ($alltables["$typed"]['field'] != $alltables["$listdep"]['field'] ) {
288
+		if ($alltables["$typed"]['field'] != $alltables["$listdep"]['field']) {
289 289
 			$warn = "Config ERROR: <$typed> and <$listdep> are of different types! I can't check consistency!";
290 290
 			return FALSE;
291 291
 		}
292
-		$entry = searchentry($myconn,$value,$alltables["$listdep"]);
293
-		if ( $entry->num_rows ) {
294
-			if ( $entry->num_rows == 1 ) {
292
+		$entry = searchentry($myconn, $value, $alltables["$listdep"]);
293
+		if ($entry->num_rows) {
294
+			if ($entry->num_rows == 1) {
295 295
 				$riga = $entry->fetch_array(MYSQLI_ASSOC);
296 296
                         	if (isListed($riga)) {
297 297
 					$warn = "<$value> is already present in <$listdep> list!";
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 					return FALSE;
300 300
 				}
301 301
 			}
302
-			if ( $entry->num_rows > 1 ) {$warn = "<$value> seems to be present more than once in <$listdep>. Contact a sysadmin NOW!";}
302
+			if ($entry->num_rows>1) {$warn = "<$value> seems to be present more than once in <$listdep>. Contact a sysadmin NOW!"; }
303 303
 		}
304 304
 		$entry->free();
305 305
 	}
@@ -307,20 +307,20 @@  discard block
 block discarded – undo
307 307
 	return TRUE;
308 308
 }
309 309
 
310
-function searchentry ($myconn,$value,$tablelist) {
310
+function searchentry($myconn, $value, $tablelist) {
311 311
 /* Make a MYSQL query and return result */
312 312
 
313 313
         $type = $tablelist['field'];
314 314
 	
315
-	if ( $tablelist['milter'] ) {
315
+	if ($tablelist['milter']) {
316 316
 		$table = milterTable($type);
317 317
 		if ($value == 'ALL')
318 318
 			$query = sprintf('SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id) GROUP by idmilt',
319
-				$table,$table);
319
+				$table, $table);
320 320
 		else {
321 321
 			switch ($type) {
322 322
 				case 'network':
323
-					list($sub['net'],$sub['mask'])=explode('/',$value);
323
+					list($sub['net'], $sub['mask']) = explode('/', $value);
324 324
 					$query = sprintf('SELECT * FROM (
325 325
 							SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id)
326 326
 				 				WHERE (
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
 							 ) AS val WHERE val.ip IS NOT null', $table, $table, $value);
339 339
 					break;
340 340
 				default:
341
-					syslog(LOG_EMERG, 'ALERT: The type <'.$type.'> is not allowed for milter lists.' );
341
+					syslog(LOG_EMERG, 'ALERT: The type <'.$type.'> is not allowed for milter lists.');
342 342
 					return FALSE;
343 343
 			}
344 344
 		}
@@ -350,11 +350,11 @@  discard block
 block discarded – undo
350 350
 	        else {
351 351
 	                switch ($type) {
352 352
 	                  case 'ip':
353
-	                        $query= "select * from $table where $type =  INET_ATON('$value')";
353
+	                        $query = "select * from $table where $type =  INET_ATON('$value')";
354 354
 	                        break;
355 355
 	                  case 'network':
356
-	                        list($sub['net'],$sub['mask'])=explode('/',$value);
357
-	                        $query= sprintf('select * from `%s`
356
+	                        list($sub['net'], $sub['mask']) = explode('/', $value);
357
+	                        $query = sprintf('select * from `%s`
358 358
 						WHERE (
359 359
 							inet_aton(\'%s\') >= network AND
360 360
 							( inet_aton(\'%s\') | ( inet_aton(\'%s\') ^ (power(2,32)-1) ) )
@@ -363,18 +363,18 @@  discard block
 block discarded – undo
363 363
 ;
364 364
 	                        break;
365 365
 	                  default:
366
-	                        $query= "select * from $table where $type = '$value'";
366
+	                        $query = "select * from $table where $type = '$value'";
367 367
 	                }
368 368
 	        }
369 369
 	}
370 370
 
371 371
 	$result = $myconn->query($query);
372
-	if($result === false)
372
+	if ($result === false)
373 373
 		syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error);
374 374
         return $result;
375 375
 }
376 376
 
377
-function countListed ($myconn,$table) {
377
+function countListed($myconn, $table) {
378 378
 /* Return number of current listed items into a rbl table */
379 379
 	$query = "SELECT COUNT(*) as `count` FROM `$table` WHERE (`active`=1 AND TIMESTAMPDIFF(MICROSECOND,NOW(),`exp`)>0) GROUP BY `active` ORDER BY `count` DESC LIMIT 1";
380 380
 	$row = $myconn->query($query);
@@ -385,48 +385,48 @@  discard block
 block discarded – undo
385 385
 }
386 386
 
387 387
 
388
-function isFull($myconn,$typedesc,$alltables) {
388
+function isFull($myconn, $typedesc, $alltables) {
389 389
         if (isset($alltables["$typedesc"]['limit'])) {
390
-		if ( $alltables["$typedesc"]['milter'] )
390
+		if ($alltables["$typedesc"]['milter'])
391 391
 			$tab = 'net';
392 392
 		else
393 393
 			$tab = $alltables["$typedesc"]['name'];
394
-                if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) 
394
+                if (countListed($myconn, $tab)>=$alltables["$typedesc"]['limit']) 
395 395
                         return TRUE;
396 396
         }
397 397
 	return FALSE;
398 398
 }
399 399
 
400
-function rlookup ($myconn,$user,$adm,$value,$typedesc,$tables) {
400
+function rlookup($myconn, $user, $adm, $value, $typedesc, $tables) {
401 401
 
402 402
 	$type = $tables["$typedesc"]['field'];
403
-	$whynot=NULL;
403
+	$whynot = NULL;
404 404
 
405 405
 	$tabhtm = <<<END
406 406
 	<table><thead><tr><th>$type</th><th title="The date this object has been listed for the first time">DateAdd</th><th>DateMod</th><th>Exp</th><th>Status</th><th title="Number of times this object has been listed">#List</th>
407 407
 END;
408
-	if ( $tables["$typedesc"]['milter'] )
408
+	if ($tables["$typedesc"]['milter'])
409 409
 		$tabhtm .= '<th title="Milter active for this object">Milters</th>';
410 410
 	$tabhtm .= '<th>Authored by</th><th width="250">Reason</th><th>Action</th></tr></thead><tfoot><tr></tr></tfoot><tbody>'."\n";
411 411
 
412
-	$result = searchentry ($myconn,$value,$tables["$typedesc"]);
412
+	$result = searchentry($myconn, $value, $tables["$typedesc"]);
413 413
 	if ($result) {
414 414
 		printf("<pre>Your request for $type &lt;$value&gt; returned %d items.\n</pre>", $result->num_rows);
415 415
 
416 416
         /* Check for limit in number of listed items */
417
-	$full = isFull($myconn,$typedesc,$tables);
417
+	$full = isFull($myconn, $typedesc, $tables);
418 418
 	if ($full) print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>';
419 419
 
420 420
 		if ($result->num_rows) {
421 421
 			print $tabhtm;
422
-			$i=0;
422
+			$i = 0;
423 423
         		while ($riga = $result->fetch_array(MYSQLI_ASSOC)) {
424 424
 				if (isListed($riga)) {
425
-					if ($tables["$typedesc"]['bl']) $listed='Listed';
426
-					else $listed='WhiteListed';
425
+					if ($tables["$typedesc"]['bl']) $listed = 'Listed';
426
+					else $listed = 'WhiteListed';
427 427
 				}	
428 428
 				else
429
-					$listed='Ok';
429
+					$listed = 'Ok';
430 430
 
431 431
 				switch ($type) {
432 432
 				  case 'ip':
@@ -439,20 +439,20 @@  discard block
 block discarded – undo
439 439
 					$element = $riga["$type"];
440 440
 				}
441 441
 
442
-				if ( $tables["$typedesc"]['milter'] AND checkMilterConf($tables["$typedesc"]) )
443
-					printf ("<tr id=id$i><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td nowrap id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td>%s</td></tr>\n",
444
-					$element, $riga['date'], $riga['datemod'], $riga['exp'], $riga['active'], $riga['nlist'], askMilter($myconn,$i,$element,$typedesc,$riga['idmilt'],$riga['miltnames'],$user,$adm), $riga['user'],htmlspecialchars($riga['reason']),ask($myconn,$i,$listed,$tables,$typedesc,$element,$full,$user,$adm));
442
+				if ($tables["$typedesc"]['milter'] AND checkMilterConf($tables["$typedesc"]))
443
+					printf("<tr id=id$i><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td nowrap id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td>%s</td></tr>\n",
444
+					$element, $riga['date'], $riga['datemod'], $riga['exp'], $riga['active'], $riga['nlist'], askMilter($myconn, $i, $element, $typedesc, $riga['idmilt'], $riga['miltnames'], $user, $adm), $riga['user'], htmlspecialchars($riga['reason']), ask($myconn, $i, $listed, $tables, $typedesc, $element, $full, $user, $adm));
445 445
 				else
446
-					 printf ("<tr id=id$i><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td>%s</td></tr>\n",
447
-					$element, $riga['date'], $riga['datemod'], $riga['exp'], $riga['active'], $riga['nlist'], $riga['user'],htmlspecialchars($riga['reason']),ask($myconn,$i,$listed,$tables,$typedesc,$element,$full,$user,$adm));
446
+					 printf("<tr id=id$i><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td>%s</td></tr>\n",
447
+					$element, $riga['date'], $riga['datemod'], $riga['exp'], $riga['active'], $riga['nlist'], $riga['user'], htmlspecialchars($riga['reason']), ask($myconn, $i, $listed, $tables, $typedesc, $element, $full, $user, $adm));
448 448
 				$i++;
449 449
         		}
450 450
 			print '</tbody></table>';
451 451
 		}
452 452
 		else {
453 453
 			print "<pre>$type &lt;$value&gt; is not listed!\n</pre>";
454
-			if ( in_array($user,array_keys($adm)) AND ($value != 'ALL') )
455
-				if ( (!$full) AND (consistentListing($myconn,$tables,$typedesc,$value,$whynot)) ) require_once('listForm.php');
454
+			if (in_array($user, array_keys($adm)) AND ($value != 'ALL'))
455
+				if ((!$full) AND (consistentListing($myconn, $tables, $typedesc, $value, $whynot))) require_once('listForm.php');
456 456
 									else print '<p>'.htmlspecialchars($whynot).'</p>';
457 457
 				
458 458
 		}
@@ -464,12 +464,12 @@  discard block
 block discarded – undo
464 464
 
465 465
 
466 466
         
467
-function sendEmailWarn($tplf,$from,$to,$sbj,$emailListed,$intervalToExpire,$detail) {
467
+function sendEmailWarn($tplf, $from, $to, $sbj, $emailListed, $intervalToExpire, $detail) {
468 468
 	$now = time();
469
-        setlocale (LC_TIME, 'it_IT');
470
-        $date = date("r",$now);
471
-	$messageID = md5(uniqid($now,1)) . '@' . gethostname();
472
-	$mua = 'PHP/' . phpversion();
469
+        setlocale(LC_TIME, 'it_IT');
470
+        $date = date("r", $now);
471
+	$messageID = md5(uniqid($now, 1)).'@'.gethostname();
472
+	$mua = 'PHP/'.phpversion();
473 473
 
474 474
 	/* Parsing headers */
475 475
 	if (!file_exists($tplf['header'])) {
@@ -478,10 +478,10 @@  discard block
 block discarded – undo
478 478
 	}
479 479
 
480 480
 	$head_tmpl = file_get_contents($tplf['header']);
481
-	$arr_tpl_vars = array('{from}','{to}','{date}','{messageID}','{mua}');
482
-	$arr_tpl_data = array($from,$to,$date,$messageID,$mua);
481
+	$arr_tpl_vars = array('{from}', '{to}', '{date}', '{messageID}', '{mua}');
482
+	$arr_tpl_data = array($from, $to, $date, $messageID, $mua);
483 483
 	$headers = str_replace($arr_tpl_vars, $arr_tpl_data, $head_tmpl);
484
-	$headers = preg_replace( '/\r|\n/', "\r\n", $headers );
484
+	$headers = preg_replace('/\r|\n/', "\r\n", $headers);
485 485
 
486 486
         /* Parsing body */
487 487
 
@@ -491,62 +491,62 @@  discard block
 block discarded – undo
491 491
         }
492 492
 
493 493
         $body_tmpl = file_get_contents($tplf['body']);
494
-        $arr_tpl_vars = array('{emailListed}','{expInterval}','{reason}');
495
-        $arr_tpl_data = array($emailListed,$intervalToExpire,$detail);
494
+        $arr_tpl_vars = array('{emailListed}', '{expInterval}', '{reason}');
495
+        $arr_tpl_data = array($emailListed, $intervalToExpire, $detail);
496 496
         $body = str_replace($arr_tpl_vars, $arr_tpl_data, $body_tmpl);
497
-        $body = preg_replace( "/\r|\n/", "\r\n", $body );
498
-	$body = wordwrap ( $body, 75 , "\r\n" );	
497
+        $body = preg_replace("/\r|\n/", "\r\n", $body);
498
+	$body = wordwrap($body, 75, "\r\n");	
499 499
 
500 500
 	/* Send the mail! */
501
-        if ( strlen(ini_get("safe_mode"))< 1) {
501
+        if (strlen(ini_get("safe_mode"))<1) {
502 502
                 $old_mailfrom = ini_get("sendmail_from");
503 503
                 ini_set("sendmail_from", $from);
504 504
                 $params = sprintf("-oi -f %s", '<>');
505
-                if (!(mail($to,$sbj, $body,$headers,$params))) $flag=FALSE;
506
-                else $flag=TRUE;
505
+                if (!(mail($to, $sbj, $body, $headers, $params))) $flag = FALSE;
506
+                else $flag = TRUE;
507 507
                 if (isset($old_mailfrom))
508 508
                         ini_set("sendmail_from", $old_mailfrom);
509 509
         }
510 510
         else {
511
-                if (!(mail($to,$sbj, $body,$headers))) $flag=FALSE;
512
-                else $flag=TRUE;
511
+                if (!(mail($to, $sbj, $body, $headers))) $flag = FALSE;
512
+                else $flag = TRUE;
513 513
         }
514 514
         return $flag;
515 515
 }
516 516
 
517
-function emailToNotify($notify_file,$dom) {
517
+function emailToNotify($notify_file, $dom) {
518 518
 	$ini_array = parse_ini_file($notify_file);
519
-	if (in_array($dom,array_keys($ini_array)))
519
+	if (in_array($dom, array_keys($ini_array)))
520 520
 		return $ini_array["$dom"];
521 521
 	else return FALSE;
522 522
 }
523 523
 
524 524
 
525
-function searchAndList ($myconn,$loguser,$tables,$typedesc,$value,$unit,&$quantity,&$reason) {
525
+function searchAndList($myconn, $loguser, $tables, $typedesc, $value, $unit, &$quantity, &$reason) {
526 526
 
527 527
 /* Search and list value */
528 528
         $type = $tables["$typedesc"]['field'];
529 529
         $table = $tables["$typedesc"]['name'];
530
-        $result = searchentry ($myconn,$value,$tables["$typedesc"]);
530
+        $result = searchentry($myconn, $value, $tables["$typedesc"]);
531 531
 
532 532
         /* Manage abnormal conditions */
533 533
         /* Value already present in db more than once. This is absurd. Panic! */
534
-        if ($result->num_rows > 1) {
535
-                syslog(LOG_EMERG,"$loguser: PANIC! Select for $type '$value' returned ". $result->num_rows ." items instead of one. Abnormal. Contact a sysadmin or a developer.");
534
+        if ($result->num_rows>1) {
535
+                syslog(LOG_EMERG, "$loguser: PANIC! Select for $type '$value' returned ".$result->num_rows." items instead of one. Abnormal. Contact a sysadmin or a developer.");
536 536
                 $result->free();
537 537
                 return FALSE;
538 538
         }
539 539
 
540 540
         /* Value already present in db or not present: to list anyway */
541
-        if ($result->num_rows >= 0) {
541
+        if ($result->num_rows>=0) {
542 542
                 /* First, check for limit in number of listed items */
543
-                if (isFull($myconn,$typedesc,$tables)) {
544
-                        syslog(LOG_EMERG,"$loguser: $typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items. Abnormal exit.');
543
+                if (isFull($myconn, $typedesc, $tables)) {
544
+                        syslog(LOG_EMERG, "$loguser: $typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items. Abnormal exit.');
545 545
                         $result->free();
546 546
                         return FALSE;
547 547
                 }
548 548
                 /* Second, check if the (re)list would be consistent now */
549
-                if (! consistentListing($myconn,$tables,$typedesc,$value,$whynot) ) {
549
+                if (!consistentListing($myconn, $tables, $typedesc, $value, $whynot)) {
550 550
                         syslog(LOG_ERR, $loguser.': '.$whynot);
551 551
                         $result->free();
552 552
                         return FALSE;
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
         switch ($result->num_rows) {
561 561
                 /* Relist value if already present */
562 562
                 case 1:
563
-                        if ( isListed($thisentry) ) {
563
+                        if (isListed($thisentry)) {
564 564
 				/* Entry already listed */
565 565
 				$expdate = $thisentry['exp'];
566 566
 				$reason = sprintf('%s. Already listed. Adding 1 DAY to previous expire date.',
@@ -574,33 +574,33 @@  discard block
 block discarded – undo
574 574
 				$expdate = 0; /* This forces expiration from CURRENT_TIMESTAMP */
575 575
 			}
576 576
 			$result->free();
577
-                        return relist ($myconn,$loguser,$value,$type,$table,$unit,$quantity,$reason, $expdate);
577
+                        return relist($myconn, $loguser, $value, $type, $table, $unit, $quantity, $reason, $expdate);
578 578
 
579 579
                 /* First time list value */
580 580
                 case 0:
581 581
                         $result->free();
582
-                        return addtolist ($myconn,$loguser,$value,$tables["$typedesc"],$unit,$quantity,$reason,$_);
582
+                        return addtolist($myconn, $loguser, $value, $tables["$typedesc"], $unit, $quantity, $reason, $_);
583 583
         }
584 584
 }
585 585
 
586 586
 
587 587
 /*************** Functions to check if two net overlap each other ********************/
588 588
 
589
-function ipRange ($range) {
589
+function ipRange($range) {
590 590
 /* List IP in range */
591
-	return array_map('long2ip', range( ip2long($range[0]), ip2long($range[1]) ) );
591
+	return array_map('long2ip', range(ip2long($range[0]), ip2long($range[1])));
592 592
 }
593 593
 
594 594
 function isIn($netA, $netB) {
595 595
 /* TRUE if an IP of $netA is contained in netB */
596
-	list($addressA,$maskA) = explode('/', $netA);
597
-	list($addressB,$maskB) = explode('/', $netB);
596
+	list($addressA, $maskA) = explode('/', $netA);
597
+	list($addressB, $maskB) = explode('/', $netB);
598 598
 	require_once 'vendor/autoload.php';
599 599
 	$net = new \dautkom\ipv4\IPv4();
600 600
 	$range = $net->address($addressA)->mask($maskA)->getRange();
601 601
 	$ips = ipRange($range);
602
-	foreach ( $ips as $ip )
603
-		if ( $net->address($addressB)->mask($maskB)->has($ip) )
602
+	foreach ($ips as $ip)
603
+		if ($net->address($addressB)->mask($maskB)->has($ip))
604 604
 			return TRUE;
605 605
 	return FALSE;
606 606
 }
@@ -612,11 +612,11 @@  discard block
 block discarded – undo
612 612
 		syslog(LOG_ERR, $loguser.': '.$tabletype['name'].' is not a network list.');
613 613
 		return FALSE;
614 614
 	}
615
-	$result = searchentry ($myconn,'ALL',$tabletype);
615
+	$result = searchentry($myconn, 'ALL', $tabletype);
616 616
         if ($result->num_rows) {
617 617
 		while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
618 618
 			$thisNet = long2ip($row['network']).'/'.long2ip($row['netmask']);
619
-			if ( isIn($thisNet, $net) ) {
619
+			if (isIn($thisNet, $net)) {
620 620
 				$result->free();
621 621
 				syslog(LOG_INFO, "$loguser: the net <$net> overlaps the existing network <$thisNet>.");
622 622
 				return TRUE;
@@ -633,8 +633,8 @@  discard block
 block discarded – undo
633 633
 /* For miltermap */
634 634
 function checkMilterConf($table) {
635 635
 	if (isset($table['milter'])) {
636
-        	if ($table['milter'] ===  TRUE) {
637
-			switch ( $table['field'] ) {
636
+        	if ($table['milter'] === TRUE) {
637
+			switch ($table['field']) {
638 638
 				case 'network':
639 639
 				case 'ip':
640 640
 					return TRUE;
@@ -668,12 +668,12 @@  discard block
 block discarded – undo
668 668
 }
669 669
 
670 670
 
671
-function readMiltName($myconn,$loguser) {
672
-	$milters=array();
671
+function readMiltName($myconn, $loguser) {
672
+	$milters = array();
673 673
 	$query = 'SELECT `name` FROM `config`';
674 674
 
675 675
         $result = $myconn->query($query);
676
-        if($result === false) {
676
+        if ($result === false) {
677 677
                 syslog(LOG_EMERG, "$loguser: ALERT: Query <$query> failed: ".$myconn->error);
678 678
 		return FALSE;
679 679
 	}
@@ -685,27 +685,27 @@  discard block
 block discarded – undo
685 685
 	return $milters;
686 686
 }
687 687
 
688
-function changeMilter ($myconn,$loguser,$miltVal,$table,$miltID) {
688
+function changeMilter($myconn, $loguser, $miltVal, $table, $miltID) {
689 689
 	$query = array();
690
-	foreach ( $miltVal as $value => $action ) {
691
-		switch ( $action ) {
690
+	foreach ($miltVal as $value => $action) {
691
+		switch ($action) {
692 692
 			case 'keep':
693 693
 				break;
694 694
 			case 'add':
695
-				$query[] = sprintf( "INSERT INTO `milt` (
695
+				$query[] = sprintf("INSERT INTO `milt` (
696 696
                 		        	`id` ,
697 697
                         			`name` 
698 698
                 			)
699 699
                 			VALUES (
700 700
                         			%d ,
701 701
 						'%s'
702
-					)",$miltID,$value);
702
+					)",$miltID, $value);
703 703
 				break;
704 704
 			case 'del':
705 705
 				$query[] = "DELETE FROM  `milt` WHERE (`id` = '$miltID' AND `name` = '$value')";
706 706
 		}
707 707
 	}
708
-	if ( count($query) ) /* This "if" is redundant, because if I call this I already checked there is a change */
708
+	if (count($query)) /* This "if" is redundant, because if I call this I already checked there is a change */
709 709
 		/* I update datemod because the user couldn't change */
710 710
 		$query[] = sprintf('UPDATE `%s` SET
711 711
 						`user`=\'%s\',
@@ -717,18 +717,18 @@  discard block
 block discarded – undo
717 717
 	$myconn->autocommit(FALSE);
718 718
 	$myconn->begin_transaction(MYSQLI_TRANS_START_READ_ONLY);
719 719
 	$ok = TRUE;
720
-	foreach ( $query as $q ) {
720
+	foreach ($query as $q) {
721 721
 		if ($myconn->query($q) !== TRUE) {
722 722
 			$ok = FALSE;
723 723
 			syslog(LOG_ERR, "$loguser: Error: ".$myconn->error);
724 724
 		}
725 725
 	}
726
-	if ( $ok ) {
727
-		if ( $myconn->commit() )
726
+	if ($ok) {
727
+		if ($myconn->commit())
728 728
 			syslog(LOG_INFO, "$loguser: Milter setting changed successfully.");
729 729
 		else {
730 730
 			syslog(LOG_ERR, "$loguser: Milter setting NOT changed for an unpredictable COMMIT error.");
731
-			if ( $myconn->rollback() )
731
+			if ($myconn->rollback())
732 732
 				syslog(LOG_INFO, "$loguser: rollback succeeded.");
733 733
 			else
734 734
 				syslog(LOG_ERR, "$loguser: rollback failed. Your db could be compromized. Check it!");
@@ -745,15 +745,15 @@  discard block
 block discarded – undo
745 745
 function curl_get($url, array $get = NULL, array $options = array(), $loguser)
746 746
 {
747 747
     $defaults = array(
748
-        CURLOPT_URL => $url. (strpos($url, '?') === FALSE ? '?' : ''). http_build_query($get),
748
+        CURLOPT_URL => $url.(strpos($url, '?') === FALSE ? '?' : '').http_build_query($get),
749 749
         CURLOPT_HEADER => 0,
750 750
         CURLOPT_RETURNTRANSFER => TRUE,
751 751
         CURLOPT_TIMEOUT => 4
752 752
     );
753 753
 
754 754
     $ch = curl_init();
755
-    curl_setopt_array($ch, ($options + $defaults));
756
-    if( ! $result = curl_exec($ch))
755
+    curl_setopt_array($ch, ($options+$defaults));
756
+    if (!$result = curl_exec($ch))
757 757
     {
758 758
         syslog(LOG_ERR, sprintf('%s: CURL Error: <%s>', $loguser, curl_error($ch)));
759 759
     }
Please login to merge, or discard this patch.