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 ( 7c40ab...39df4e )
by Marco
02:30
created
contrib/splunk/webhook/readPost.php 2 patches
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -26,17 +26,17 @@  discard block
 block discarded – undo
26 26
 
27 27
  /* Conf */
28 28
 if (!isset($_GET['conf'])) {
29
-        syslog(LOG_ALERT,
30
-        sprintf('%s: you must insert the config file name as a GET parameter, such as %s?conf=listEmail.conf',
31
-                $user, $_SERVER['SCRIPT_NAME']) );
32
-        exit(254);
29
+		syslog(LOG_ALERT,
30
+		sprintf('%s: you must insert the config file name as a GET parameter, such as %s?conf=listEmail.conf',
31
+				$user, $_SERVER['SCRIPT_NAME']) );
32
+		exit(254);
33 33
 }
34 34
 $fileconf = $_GET['conf'];
35 35
 if ( !file_exists(dirname(__FILE__) . '/../' . $fileconf) ) {
36
-        syslog(LOG_ALERT,
37
-        sprintf('%s: the configuration file <%s> doesn\'t exist.',
38
-                $user, $fileconf ));
39
-        exit(254);
36
+		syslog(LOG_ALERT,
37
+		sprintf('%s: the configuration file <%s> doesn\'t exist.',
38
+				$user, $fileconf ));
39
+		exit(254);
40 40
 }
41 41
 
42 42
 closelog();
@@ -64,8 +64,8 @@  discard block
 block discarded – undo
64 64
 
65 65
 /* check you select a blocklist */
66 66
 if ( !$tables["$typedesc"]['bl'] ) {
67
-        syslog(LOG_EMERG,"$user: <$typedesc> is not a blocklist. Are you stupid? Do you want to whitelist a spammer? I refuse to continue.");
68
-        exit (254);
67
+		syslog(LOG_EMERG,"$user: <$typedesc> is not a blocklist. Are you stupid? Do you want to whitelist a spammer? I refuse to continue.");
68
+		exit (254);
69 69
 }
70 70
 
71 71
 
@@ -95,15 +95,15 @@  discard block
 block discarded – undo
95 95
 if (preg_match_all('/^https?\:\/\/(?<splunkhost>[\w\.\-]+)\:8000\/app\/(?<splunkapp>[\w\.\-]+)\/\@go\?sid=(?<job>[\w\.\-\d]+)$/',
96 96
 	$webhook['results_link'], $out, PREG_PATTERN_ORDER) === FALSE) {
97 97
 	syslog(LOG_ALERT,
98
-        	sprintf('%s: unexpected error: can\'t parse the results link returned by webhook (<%s>).',
98
+			sprintf('%s: unexpected error: can\'t parse the results link returned by webhook (<%s>).',
99 99
 		$user, $webhook['results_link']) );
100 100
 	return 255;
101 101
 }
102 102
 
103 103
 if ( $webhook['app'] != $out['splunkapp'][0] ) {
104 104
 	syslog(LOG_ALERT,
105
-        	sprintf('%s: unexpected error: the APP returned by webhook (<%s>) doesn\'t match the app (<%s>) in result link.',
106
-                $user, $webhook['app'], $out['splunkapp'][0] ) );
105
+			sprintf('%s: unexpected error: the APP returned by webhook (<%s>) doesn\'t match the app (<%s>) in result link.',
106
+				$user, $webhook['app'], $out['splunkapp'][0] ) );
107 107
 	return 255;
108 108
 }
109 109
 
@@ -137,14 +137,14 @@  discard block
 block discarded – undo
137 137
 
138 138
 $nr = count ($results);
139 139
 for ($i=1; $i<$nr; $i++) {	/* We skip first header line (i=0) */
140
-        $data = str_getcsv($results[$i], ',');
141
-        $thisVal = $data[1];
142
-        unset($data[1]);
143
-        $data = array_values($data);
144
-        if ( !in_array($thisVal,array_keys($tolist))  )
145
-	        $tolist["$thisVal"] = $data;
146
-        else if ($data[3]>$tolist[$thisVal][3])
147
-	        $tolist["$thisVal"] = $data;
140
+		$data = str_getcsv($results[$i], ',');
141
+		$thisVal = $data[1];
142
+		unset($data[1]);
143
+		$data = array_values($data);
144
+		if ( !in_array($thisVal,array_keys($tolist))  )
145
+			$tolist["$thisVal"] = $data;
146
+		else if ($data[3]>$tolist[$thisVal][3])
147
+			$tolist["$thisVal"] = $data;
148 148
 }
149 149
 
150 150
 /* Make MYSQL connection */
@@ -154,34 +154,34 @@  discard block
 block discarded – undo
154 154
 	exit (254);
155 155
 
156 156
 foreach ( array_keys($tolist) as $value) {
157
-        $quantity = $conf['quantity'];
158
-        $reason = 'On ['.$tolist["$value"][0]."] <$value> sent ".$tolist["$value"][1].' messages to '.$tolist["$value"][2].' recipients.';
159
-        if ( $tolist["$value"][3] >= $threshold ) {
160
-                if ( searchAndList ($mysqli,$user,$tables,$typedesc,$value,$unit,$quantity,$reason) ) {
161
-                        syslog (LOG_INFO, "$user: ".'Listing reason: '.$reason);
162
-                        /* Send a email to domain admin if you list an email */
163
-                        if ( ( $tables["$typedesc"]['field'] == 'email' ) OR ( $tables["$typedesc"]['field'] == 'username' ) ) {
164
-                                /* Sometime uid are in the form of <user>@<domain> ... */
165
-                                if ( strpos($value, '@') !== FALSE ) {
166
-                                        $domain = substr(strrchr($value, '@'), 1);
167
-                                        if ( strpos($domain, '@') === FALSE ) {
168
-                                                $recip = emailToNotify($domainNotify_file,$domain);
169
-                                                $subject = sprintf('%s <%s> is now blocked because exceedes limits on outgoing emails',
170
-                                                                $tables["$typedesc"]['field'], $value);
171
-                                                if (!empty($recip))
172
-                                                        if ( sendEmailWarn($tplfile,'[email protected]',$recip,
173
-                                                                $subject,$value,"$quantity $unit",$reason) )
174
-                                                                syslog(LOG_INFO, "$user: \"$recip\" was notified about the \"$value\" abuse.");
175
-                                        }
176
-                                        else syslog(LOG_ERR,"$user: <$domain> contains the '@' char. Notification cannot be sent.");
177
-                                }
178
-                        }
179
-                }
180
-        }
181
-        else {
182
-                $reason .= " But it has NOT been listed because it doesn't apply to the trigger condition.";
183
-                syslog (LOG_INFO, "$user: ".$reason);
184
-        }
157
+		$quantity = $conf['quantity'];
158
+		$reason = 'On ['.$tolist["$value"][0]."] <$value> sent ".$tolist["$value"][1].' messages to '.$tolist["$value"][2].' recipients.';
159
+		if ( $tolist["$value"][3] >= $threshold ) {
160
+				if ( searchAndList ($mysqli,$user,$tables,$typedesc,$value,$unit,$quantity,$reason) ) {
161
+						syslog (LOG_INFO, "$user: ".'Listing reason: '.$reason);
162
+						/* Send a email to domain admin if you list an email */
163
+						if ( ( $tables["$typedesc"]['field'] == 'email' ) OR ( $tables["$typedesc"]['field'] == 'username' ) ) {
164
+								/* Sometime uid are in the form of <user>@<domain> ... */
165
+								if ( strpos($value, '@') !== FALSE ) {
166
+										$domain = substr(strrchr($value, '@'), 1);
167
+										if ( strpos($domain, '@') === FALSE ) {
168
+												$recip = emailToNotify($domainNotify_file,$domain);
169
+												$subject = sprintf('%s <%s> is now blocked because exceedes limits on outgoing emails',
170
+																$tables["$typedesc"]['field'], $value);
171
+												if (!empty($recip))
172
+														if ( sendEmailWarn($tplfile,'[email protected]',$recip,
173
+																$subject,$value,"$quantity $unit",$reason) )
174
+																syslog(LOG_INFO, "$user: \"$recip\" was notified about the \"$value\" abuse.");
175
+										}
176
+										else syslog(LOG_ERR,"$user: <$domain> contains the '@' char. Notification cannot be sent.");
177
+								}
178
+						}
179
+				}
180
+		}
181
+		else {
182
+				$reason .= " But it has NOT been listed because it doesn't apply to the trigger condition.";
183
+				syslog (LOG_INFO, "$user: ".$reason);
184
+		}
185 185
 }
186 186
 
187 187
 /* Close connection */
Please login to merge, or discard this patch.
Braces   +14 added lines, -11 removed lines patch added patch discarded remove patch
@@ -141,17 +141,19 @@  discard block
 block discarded – undo
141 141
         $thisVal = $data[1];
142 142
         unset($data[1]);
143 143
         $data = array_values($data);
144
-        if ( !in_array($thisVal,array_keys($tolist))  )
145
-	        $tolist["$thisVal"] = $data;
146
-        else if ($data[3]>$tolist[$thisVal][3])
147
-	        $tolist["$thisVal"] = $data;
148
-}
144
+        if ( !in_array($thisVal,array_keys($tolist))  ) {
145
+        	        $tolist["$thisVal"] = $data;
146
+        } else if ($data[3]>$tolist[$thisVal][3]) {
147
+        	        $tolist["$thisVal"] = $data;
148
+        }
149
+        }
149 150
 
150 151
 /* Make MYSQL connection */
151 152
 
152 153
 $mysqli = myConnect($host, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user);
153
-if ( $mysqli === FALSE )
154
+if ( $mysqli === FALSE ) {
154 155
 	exit (254);
156
+}
155 157
 
156 158
 foreach ( array_keys($tolist) as $value) {
157 159
         $quantity = $conf['quantity'];
@@ -168,17 +170,18 @@  discard block
 block discarded – undo
168 170
                                                 $recip = emailToNotify($domainNotify_file,$domain);
169 171
                                                 $subject = sprintf('%s <%s> is now blocked because exceedes limits on outgoing emails',
170 172
                                                                 $tables["$typedesc"]['field'], $value);
171
-                                                if (!empty($recip))
172
-                                                        if ( sendEmailWarn($tplfile,'[email protected]',$recip,
173
+                                                if (!empty($recip)) {
174
+                                                                                                        if ( sendEmailWarn($tplfile,'[email protected]',$recip,
173 175
                                                                 $subject,$value,"$quantity $unit",$reason) )
174 176
                                                                 syslog(LOG_INFO, "$user: \"$recip\" was notified about the \"$value\" abuse.");
177
+                                                }
178
+                                        } else {
179
+                                        	syslog(LOG_ERR,"$user: <$domain> contains the '@' char. Notification cannot be sent.");
175 180
                                         }
176
-                                        else syslog(LOG_ERR,"$user: <$domain> contains the '@' char. Notification cannot be sent.");
177 181
                                 }
178 182
                         }
179 183
                 }
180
-        }
181
-        else {
184
+        } else {
182 185
                 $reason .= " But it has NOT been listed because it doesn't apply to the trigger condition.";
183 186
                 syslog (LOG_INFO, "$user: ".$reason);
184 187
         }
Please login to merge, or discard this patch.
index.php 1 patch
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -14,12 +14,14 @@
 block discarded – undo
14 14
 require_once('function.php');
15 15
 
16 16
 checkSSL();
17
-if ( $require_auth )
17
+if ( $require_auth ) {
18 18
 	if ( username() == 'unknown' ) exit ("<p>You MUST configure your server to use authentication.</p>");
19
+}
19 20
 
20 21
 
21
-if ( $imapListActive )
22
+if ( $imapListActive ) {
22 23
 	print ' <p style="text-align: right"><a href="/spamreport" target="_new">SPAM Learn Observer</a></p>';
24
+}
23 25
 
24 26
 print <<<END
25 27
 <form name="check" action="result.php" onSubmit="xmlhttpPost('result.php', 'check', 'Risultato', '<img src=\'/include/pleasewait.gif\'>'); return false;" enctype="text/plain" method="post" target="_self">
Please login to merge, or discard this patch.
function.php 2 patches
Indentation   +158 added lines, -158 removed lines patch added patch discarded remove patch
@@ -4,8 +4,8 @@  discard block
 block discarded – undo
4 4
 
5 5
 function username() {
6 6
 	if (isset ($_SERVER['REMOTE_USER'])) $user = $_SERVER['REMOTE_USER'];
7
-        	else if (isset ($_SERVER['USER'])) $user = $_SERVER['USER'];
8
-                	else $user='unknown';
7
+			else if (isset ($_SERVER['USER'])) $user = $_SERVER['USER'];
8
+					else $user='unknown';
9 9
 	return $user;
10 10
 }
11 11
 
@@ -21,11 +21,11 @@  discard block
 block discarded – undo
21 21
 }
22 22
 
23 23
 function myConnect($host, $user, $pass, $db, $port, $tablelist, $typedesc, $loguser) {
24
-        $db = ( $tablelist["$typedesc"]['milter'] ) ? $tablelist["$typedesc"]['name'] : $db;
24
+		$db = ( $tablelist["$typedesc"]['milter'] ) ? $tablelist["$typedesc"]['name'] : $db;
25 25
 	$mysqli = new mysqli($host, $user, $pass, $db, $port);
26
-        if ($mysqli->connect_error) {
27
-           	syslog (LOG_EMERG, $loguser.': Connect Error to DB <'.$db.'> (' . $mysqli->connect_errno . ') '
28
-                    		. $mysqli->connect_error);
26
+		if ($mysqli->connect_error) {
27
+		   	syslog (LOG_EMERG, $loguser.': Connect Error to DB <'.$db.'> (' . $mysqli->connect_errno . ') '
28
+							. $mysqli->connect_error);
29 29
 		return FALSE;
30 30
 	}
31 31
 	syslog(LOG_INFO, $loguser.': Successfully MySQL connected at DB <'.$db.'> to ' . $mysqli->host_info) ;
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 			}
67 67
 		}
68 68
 		list($sub['net'],$sub['mask'])=explode('/',$value);
69
-                $query= sprintf("INSERT INTO `$table` (
69
+				$query= sprintf("INSERT INTO `$table` (
70 70
                         `$type` ,
71 71
 			`netmask`,
72 72
                         `date` ,
@@ -79,10 +79,10 @@  discard block
 block discarded – undo
79 79
                         INET_ATON( '%s' ) , INET_ATON( '%s' ) ,
80 80
                         CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s'
81 81
                 )" ,$sub['net'],$sub['mask'],$expUnit,$expQ,$user,$myreason);
82
-                break;
82
+				break;
83 83
 
84 84
 	  default:
85
-                $query= sprintf("INSERT INTO `$table` (
85
+				$query= sprintf("INSERT INTO `$table` (
86 86
                         `$type` ,
87 87
                         `date` ,
88 88
                         `exp` ,
@@ -97,8 +97,8 @@  discard block
 block discarded – undo
97 97
 	}
98 98
 
99 99
 	if ($myconn->query($query) === TRUE) {
100
-	    syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit.");
101
-	    $result=TRUE;
100
+		syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit.");
101
+		$result=TRUE;
102 102
 	}
103 103
 	else syslog(LOG_ERR, "$user: Error: ".$myconn->error);
104 104
 	return $result;
@@ -116,9 +116,9 @@  discard block
 block discarded – undo
116 116
 		$nlist = '`nlist` + 1';
117 117
 	}
118 118
 
119
-        switch ($type) {
119
+		switch ($type) {
120 120
 	  case 'ip':
121
-                $query= sprintf("UPDATE `$table` SET
121
+				$query= sprintf("UPDATE `$table` SET
122 122
 			`active` = '1',
123 123
 			`user` = '%s',
124 124
 			`exp` = TIMESTAMPADD(%s,%d,%s),
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
 			`reason` = '%s'
127 127
 			WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user,$expUnit,$expQ,$exptime,$nlist,$myreason,$value);
128 128
 		break;
129
-          case 'network':
129
+		  case 'network':
130 130
 		list($sub['net'],$sub['mask'])=explode('/',$value);
131
-                $query= sprintf("UPDATE `$table` SET
131
+				$query= sprintf("UPDATE `$table` SET
132 132
                         `active` = '1',
133 133
                         `user` = '%s',
134 134
                         `exp` = TIMESTAMPADD(%s,%d,%s),
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
                         WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1" ,$user,$expUnit,$expQ,$exptime,$nlist,$myreason,$sub['net'],$sub['mask']);
138 138
 		break;
139 139
 	  default:
140
-                $query= sprintf("UPDATE `$table` SET
140
+				$query= sprintf("UPDATE `$table` SET
141 141
                         `active` = '1',
142 142
                         `user` = '%s',
143 143
                         `exp` = TIMESTAMPADD(%s,%d,%s),
@@ -146,18 +146,18 @@  discard block
 block discarded – undo
146 146
 			WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user,$expUnit,$expQ,$exptime,$nlist,$myreason,$value);
147 147
 	}
148 148
 
149
-        if ($myconn->query($query) === TRUE) {
150
-            syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit from $exptime.");
149
+		if ($myconn->query($query) === TRUE) {
150
+			syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit from $exptime.");
151 151
 		$result=TRUE;
152
-        }
153
-        else syslog (LOG_ERR, "$user: Error: ". $myconn->error);
152
+		}
153
+		else syslog (LOG_ERR, "$user: Error: ". $myconn->error);
154 154
 	return $result;
155 155
 }
156 156
 
157 157
 function remove ($myconn,$user,$value,$type,$table) {
158 158
 
159
-        switch ($type) {
160
-          case 'ip':
159
+		switch ($type) {
160
+		  case 'ip':
161 161
 		$query = sprintf("DELETE FROM `$table` WHERE
162 162
                         `$table`.`$type` = INET_ATON('%s') LIMIT 1", $value);
163 163
 		break;
@@ -173,18 +173,18 @@  discard block
 block discarded – undo
173 173
 	}
174 174
 
175 175
 
176
-        if ($return=$myconn->query($query) === TRUE) 
177
-            syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>.");
178
-        else syslog(LOG_ERR, "$user: Error: ". $myconn->error);
176
+		if ($return=$myconn->query($query) === TRUE) 
177
+			syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>.");
178
+		else syslog(LOG_ERR, "$user: Error: ". $myconn->error);
179 179
 
180
-        return $return;
180
+		return $return;
181 181
 }
182 182
 
183 183
 
184 184
 function changestatus ($myconn,$user,$value,$status,$type,$table) {
185 185
 
186 186
 	switch ($type) {
187
-          case 'ip':
187
+		  case 'ip':
188 188
 		$query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user, $value);
189 189
 		break;
190 190
 	  case 'network':
@@ -195,16 +195,16 @@  discard block
 block discarded – undo
195 195
 		$query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user, $value);
196 196
 	}
197 197
 
198
-        if ($return=$myconn->query($query) === TRUE) {
199
-            syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>");
200
-        }
201
-        else syslog(LOG_ERR, "$user: Error: ". $myconn->error);
198
+		if ($return=$myconn->query($query) === TRUE) {
199
+			syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>");
200
+		}
201
+		else syslog(LOG_ERR, "$user: Error: ". $myconn->error);
202 202
 	return $return;	
203 203
 }
204 204
 
205 205
 
206 206
 function expire ($myconn,$user,$tables,$expireTime) {
207
-        $return=TRUE;
207
+		$return=TRUE;
208 208
 	$log=array();
209 209
 	$desc = array_keys($tables);
210 210
 	foreach ($desc as $tdesc) { 
@@ -214,11 +214,11 @@  discard block
 block discarded – undo
214 214
 		/* END OF QUERY */
215 215
 		$log[0] = 'expired for';
216 216
 		$log[1] = 'disabled for';
217
-        	if ($myconn->multi_query($query)) {
217
+			if ($myconn->multi_query($query)) {
218 218
 			$j = 0;
219 219
 			do {
220
-		    		$numdel = $myconn->affected_rows;
221
-	            		syslog(LOG_INFO, "Expire job - <$user> Permanently DELETED $numdel records ".$log[$j]." $expireTime YEARS from <".$tables["$tdesc"]['name'].'>.');
220
+					$numdel = $myconn->affected_rows;
221
+						syslog(LOG_INFO, "Expire job - <$user> Permanently DELETED $numdel records ".$log[$j]." $expireTime YEARS from <".$tables["$tdesc"]['name'].'>.');
222 222
 				$j++;
223 223
 
224 224
 			} while ($myconn->next_result());
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 	}
231 231
 	if ( !($return) ) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated');
232 232
 	else  syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.');
233
-        return $return;
233
+		return $return;
234 234
 }
235 235
 
236 236
 
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
 		if ( $entry->num_rows ) {
304 304
 			if ( $entry->num_rows == 1 ) {
305 305
 				$riga = $entry->fetch_array(MYSQLI_ASSOC);
306
-                        	if (isListed($riga)) {
306
+							if (isListed($riga)) {
307 307
 					$warn = "<$value> is already present in <$listdep> list!";
308 308
 					$entry->free();
309 309
 					return FALSE;
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 function searchentry ($myconn,$value,$tablelist) {
321 321
 /* Make a MYSQL query and return result */
322 322
 
323
-        $type = $tablelist['field'];
323
+		$type = $tablelist['field'];
324 324
 	
325 325
 	if ( $tablelist['milter'] ) {
326 326
 		$table = milterTable($type);
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 				case 'ip':
345 345
 					$query = sprintf('SELECT * FROM (
346 346
 							SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id)' .
347
-                                                		'WHERE `ip` =  INET_ATON(\'%s\')
347
+														'WHERE `ip` =  INET_ATON(\'%s\')
348 348
 							 ) AS val WHERE val.ip IS NOT null', $table, $table, $value);
349 349
 					break;
350 350
 				default:
@@ -355,33 +355,33 @@  discard block
 block discarded – undo
355 355
 	}
356 356
 
357 357
 	else {
358
-	        $table = $tablelist['name'];
359
-	        if ($value == 'ALL') $query = 'select * from '.$table;
360
-	        else {
361
-	                switch ($type) {
362
-	                  case 'ip':
363
-	                        $query= "select * from $table where $type =  INET_ATON('$value')";
364
-	                        break;
365
-	                  case 'network':
366
-	                        list($sub['net'],$sub['mask'])=explode('/',$value);
367
-	                        $query= sprintf('select * from `%s`
358
+			$table = $tablelist['name'];
359
+			if ($value == 'ALL') $query = 'select * from '.$table;
360
+			else {
361
+					switch ($type) {
362
+					  case 'ip':
363
+							$query= "select * from $table where $type =  INET_ATON('$value')";
364
+							break;
365
+					  case 'network':
366
+							list($sub['net'],$sub['mask'])=explode('/',$value);
367
+							$query= sprintf('select * from `%s`
368 368
 						WHERE (
369 369
 							inet_aton(\'%s\') >= network AND
370 370
 							( inet_aton(\'%s\') | ( inet_aton(\'%s\') ^ (power(2,32)-1) ) )
371 371
 								<= network | ( netmask ^ (power(2,32)-1) )
372 372
 						)', $table, $sub['net'], $sub['net'], $sub['mask']);
373 373
 ;
374
-	                        break;
375
-	                  default:
376
-	                        $query= "select * from $table where $type = '$value'";
377
-	                }
378
-	        }
374
+							break;
375
+					  default:
376
+							$query= "select * from $table where $type = '$value'";
377
+					}
378
+			}
379 379
 	}
380 380
 
381 381
 	$result = $myconn->query($query);
382 382
 	if($result === false)
383 383
 		syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error);
384
-        return $result;
384
+		return $result;
385 385
 }
386 386
 
387 387
 function countListed ($myconn,$table) {
@@ -396,14 +396,14 @@  discard block
 block discarded – undo
396 396
 
397 397
 
398 398
 function isFull($myconn,$typedesc,$alltables) {
399
-        if (isset($alltables["$typedesc"]['limit'])) {
399
+		if (isset($alltables["$typedesc"]['limit'])) {
400 400
 		if ( $alltables["$typedesc"]['milter'] )
401 401
 			$tab = 'net';
402 402
 		else
403 403
 			$tab = $alltables["$typedesc"]['name'];
404
-                if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) 
405
-                        return TRUE;
406
-        }
404
+				if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) 
405
+						return TRUE;
406
+		}
407 407
 	return FALSE;
408 408
 }
409 409
 
@@ -423,14 +423,14 @@  discard block
 block discarded – undo
423 423
 	if ($result) {
424 424
 		printf("<pre>Your request for $type &lt;$value&gt; returned %d items.\n</pre>", $result->num_rows);
425 425
 
426
-        /* Check for limit in number of listed items */
426
+		/* Check for limit in number of listed items */
427 427
 	$full = isFull($myconn,$typedesc,$tables);
428 428
 	if ($full) print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>';
429 429
 
430 430
 		if ($result->num_rows) {
431 431
 			print $tabhtm;
432 432
 			$i=0;
433
-        		while ($riga = $result->fetch_array(MYSQLI_ASSOC)) {
433
+				while ($riga = $result->fetch_array(MYSQLI_ASSOC)) {
434 434
 				if (isListed($riga)) {
435 435
 					if ($tables["$typedesc"]['bl']) $listed='Listed';
436 436
 					else $listed='WhiteListed';
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
 					 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",
457 457
 					$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));
458 458
 				$i++;
459
-        		}
459
+				}
460 460
 			print '</tbody></table>';
461 461
 		}
462 462
 		else {
@@ -476,15 +476,15 @@  discard block
 block discarded – undo
476 476
         
477 477
 function sendEmailWarn($tplf,$from,$to,$sbj,$emailListed,$intervalToExpire,$detail) {
478 478
 	$now = time();
479
-        setlocale (LC_TIME, 'it_IT');
480
-        $date = date("r",$now);
479
+		setlocale (LC_TIME, 'it_IT');
480
+		$date = date("r",$now);
481 481
 	$messageID = md5(uniqid($now,1)) . '@' . gethostname();
482 482
 	$mua = 'PHP/' . phpversion();
483 483
 
484 484
 	/* Parsing headers */
485 485
 	if (!file_exists($tplf['header'])) {
486
-    		syslog(LOG_ERR, 'Sending email... template file <'.$tplf['header'].'> not found!');
487
-    		exit;
486
+			syslog(LOG_ERR, 'Sending email... template file <'.$tplf['header'].'> not found!');
487
+			exit;
488 488
 	}
489 489
 
490 490
 	$head_tmpl = file_get_contents($tplf['header']);
@@ -493,35 +493,35 @@  discard block
 block discarded – undo
493 493
 	$headers = str_replace($arr_tpl_vars, $arr_tpl_data, $head_tmpl);
494 494
 	$headers = preg_replace( '/\r|\n/', "\r\n", $headers );
495 495
 
496
-        /* Parsing body */
496
+		/* Parsing body */
497 497
 
498
-        if (!file_exists($tplf['body'])) {
499
-                syslog(LOG_ERR, 'Sending email... template file <'.$tplf['body'].'> not found!');
500
-                exit;
501
-        }
498
+		if (!file_exists($tplf['body'])) {
499
+				syslog(LOG_ERR, 'Sending email... template file <'.$tplf['body'].'> not found!');
500
+				exit;
501
+		}
502 502
 
503
-        $body_tmpl = file_get_contents($tplf['body']);
504
-        $arr_tpl_vars = array('{emailListed}','{expInterval}','{reason}');
505
-        $arr_tpl_data = array($emailListed,$intervalToExpire,$detail);
506
-        $body = str_replace($arr_tpl_vars, $arr_tpl_data, $body_tmpl);
507
-        $body = preg_replace( "/\r|\n/", "\r\n", $body );
503
+		$body_tmpl = file_get_contents($tplf['body']);
504
+		$arr_tpl_vars = array('{emailListed}','{expInterval}','{reason}');
505
+		$arr_tpl_data = array($emailListed,$intervalToExpire,$detail);
506
+		$body = str_replace($arr_tpl_vars, $arr_tpl_data, $body_tmpl);
507
+		$body = preg_replace( "/\r|\n/", "\r\n", $body );
508 508
 	$body = wordwrap ( $body, 75 , "\r\n" );	
509 509
 
510 510
 	/* Send the mail! */
511
-        if ( strlen(ini_get("safe_mode"))< 1) {
512
-                $old_mailfrom = ini_get("sendmail_from");
513
-                ini_set("sendmail_from", $from);
514
-                $params = sprintf("-oi -f %s", '<>');
515
-                if (!(mail($to,$sbj, $body,$headers,$params))) $flag=FALSE;
516
-                else $flag=TRUE;
517
-                if (isset($old_mailfrom))
518
-                        ini_set("sendmail_from", $old_mailfrom);
519
-        }
520
-        else {
521
-                if (!(mail($to,$sbj, $body,$headers))) $flag=FALSE;
522
-                else $flag=TRUE;
523
-        }
524
-        return $flag;
511
+		if ( strlen(ini_get("safe_mode"))< 1) {
512
+				$old_mailfrom = ini_get("sendmail_from");
513
+				ini_set("sendmail_from", $from);
514
+				$params = sprintf("-oi -f %s", '<>');
515
+				if (!(mail($to,$sbj, $body,$headers,$params))) $flag=FALSE;
516
+				else $flag=TRUE;
517
+				if (isset($old_mailfrom))
518
+						ini_set("sendmail_from", $old_mailfrom);
519
+		}
520
+		else {
521
+				if (!(mail($to,$sbj, $body,$headers))) $flag=FALSE;
522
+				else $flag=TRUE;
523
+		}
524
+		return $flag;
525 525
 }
526 526
 
527 527
 function emailToNotify($notify_file,$dom) {
@@ -535,62 +535,62 @@  discard block
 block discarded – undo
535 535
 function searchAndList ($myconn,$loguser,$tables,$typedesc,$value,$unit,&$quantity,&$reason) {
536 536
 
537 537
 /* Search and list value */
538
-        $type = $tables["$typedesc"]['field'];
539
-        $table = $tables["$typedesc"]['name'];
540
-        $result = searchentry ($myconn,$value,$tables["$typedesc"]);
541
-
542
-        /* Manage abnormal conditions */
543
-        /* Value already present in db more than once. This is absurd. Panic! */
544
-        if ($result->num_rows > 1) {
545
-                syslog(LOG_EMERG,"$loguser: PANIC! Select for $type '$value' returned ". $result->num_rows ." items instead of one. Abnormal. Contact a sysadmin or a developer.");
546
-                $result->free();
547
-                return FALSE;
548
-        }
538
+		$type = $tables["$typedesc"]['field'];
539
+		$table = $tables["$typedesc"]['name'];
540
+		$result = searchentry ($myconn,$value,$tables["$typedesc"]);
541
+
542
+		/* Manage abnormal conditions */
543
+		/* Value already present in db more than once. This is absurd. Panic! */
544
+		if ($result->num_rows > 1) {
545
+				syslog(LOG_EMERG,"$loguser: PANIC! Select for $type '$value' returned ". $result->num_rows ." items instead of one. Abnormal. Contact a sysadmin or a developer.");
546
+				$result->free();
547
+				return FALSE;
548
+		}
549 549
 
550
-        /* Value already present in db or not present: to list anyway */
551
-        if ($result->num_rows >= 0) {
552
-                /* First, check for limit in number of listed items */
553
-                if (isFull($myconn,$typedesc,$tables)) {
554
-                        syslog(LOG_EMERG,"$loguser: $typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items. Abnormal exit.');
555
-                        $result->free();
556
-                        return FALSE;
557
-                }
558
-                /* Second, check if the (re)list would be consistent now */
559
-                if (! consistentListing($myconn,$tables,$typedesc,$value,$whynot) ) {
560
-                        syslog(LOG_ERR, $loguser.': '.$whynot);
561
-                        $result->free();
562
-                        return FALSE;
563
-                }
564
-        }
565
-        /* End of abnormal conditions */
550
+		/* Value already present in db or not present: to list anyway */
551
+		if ($result->num_rows >= 0) {
552
+				/* First, check for limit in number of listed items */
553
+				if (isFull($myconn,$typedesc,$tables)) {
554
+						syslog(LOG_EMERG,"$loguser: $typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items. Abnormal exit.');
555
+						$result->free();
556
+						return FALSE;
557
+				}
558
+				/* Second, check if the (re)list would be consistent now */
559
+				if (! consistentListing($myconn,$tables,$typedesc,$value,$whynot) ) {
560
+						syslog(LOG_ERR, $loguser.': '.$whynot);
561
+						$result->free();
562
+						return FALSE;
563
+				}
564
+		}
565
+		/* End of abnormal conditions */
566 566
 
567 567
 
568
-        /* Finally, here I can list the value! */
568
+		/* Finally, here I can list the value! */
569 569
 	$thisentry = $result->fetch_array(MYSQLI_ASSOC);
570
-        switch ($result->num_rows) {
571
-                /* Relist value if already present */
572
-                case 1:
573
-                        if ( isListed($thisentry) ) {
570
+		switch ($result->num_rows) {
571
+				/* Relist value if already present */
572
+				case 1:
573
+						if ( isListed($thisentry) ) {
574 574
 				/* Entry already listed */
575 575
 				$expdate = $thisentry['exp'];
576 576
 				$reason = sprintf('%s. Already listed. Adding 1 DAY to previous expire date.',
577 577
 					 $reason);
578 578
 				$quantity = 1;
579 579
 				$unit = 'DAY';
580
-                        }
580
+						}
581 581
 			else {
582
-                        	/* Entry delisted */
582
+							/* Entry delisted */
583 583
 				$quantity *= $thisentry['nlist'];
584 584
 				$expdate = 0; /* This forces expiration from CURRENT_TIMESTAMP */
585 585
 			}
586 586
 			$result->free();
587
-                        return relist ($myconn,$loguser,$value,$type,$table,$unit,$quantity,$reason, $expdate);
587
+						return relist ($myconn,$loguser,$value,$type,$table,$unit,$quantity,$reason, $expdate);
588 588
 
589
-                /* First time list value */
590
-                case 0:
591
-                        $result->free();
592
-                        return addtolist ($myconn,$loguser,$value,$tables["$typedesc"],$unit,$quantity,$reason,$_);
593
-        }
589
+				/* First time list value */
590
+				case 0:
591
+						$result->free();
592
+						return addtolist ($myconn,$loguser,$value,$tables["$typedesc"],$unit,$quantity,$reason,$_);
593
+		}
594 594
 }
595 595
 
596 596
 
@@ -623,7 +623,7 @@  discard block
 block discarded – undo
623 623
 		return FALSE;
624 624
 	}
625 625
 	$result = searchentry ($myconn,'ALL',$tabletype);
626
-        if ($result->num_rows) {
626
+		if ($result->num_rows) {
627 627
 		while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
628 628
 			$thisNet = long2ip($row['network']).'/'.long2ip($row['netmask']);
629 629
 			if ( isIn($thisNet, $net) ) {
@@ -643,7 +643,7 @@  discard block
 block discarded – undo
643 643
 /* For miltermap */
644 644
 function checkMilterConf($table) {
645 645
 	if (isset($table['milter'])) {
646
-        	if ($table['milter'] ===  TRUE) {
646
+			if ($table['milter'] ===  TRUE) {
647 647
 			switch ( $table['field'] ) {
648 648
 				case 'network':
649 649
 				case 'ip':
@@ -666,15 +666,15 @@  discard block
 block discarded – undo
666 666
 
667 667
 function milterTable($t) {
668 668
 	/* Return the milter object table for type t  or FALSE on error */
669
-        switch ($t) {
670
-                case 'network':
671
-                        return 'net';
672
-                case 'ip':
673
-                        return 'ips';
674
-                default:
669
+		switch ($t) {
670
+				case 'network':
671
+						return 'net';
672
+				case 'ip':
673
+						return 'ips';
674
+				default:
675 675
 			syslog(LOG_EMERG, "ALERT: type <$t> not allowed in configuration. ");
676
-                        return FALSE;
677
-        }
676
+						return FALSE;
677
+		}
678 678
 }
679 679
 
680 680
 
@@ -682,9 +682,9 @@  discard block
 block discarded – undo
682 682
 	$milters=array();
683 683
 	$query = 'SELECT `name` FROM `config`';
684 684
 
685
-        $result = $myconn->query($query);
686
-        if($result === false) {
687
-                syslog(LOG_EMERG, "$loguser: ALERT: Query <$query> failed: ".$myconn->error);
685
+		$result = $myconn->query($query);
686
+		if($result === false) {
687
+				syslog(LOG_EMERG, "$loguser: ALERT: Query <$query> failed: ".$myconn->error);
688 688
 		return FALSE;
689 689
 	}
690 690
 	if ($result->num_rows) {
@@ -754,21 +754,21 @@  discard block
 block discarded – undo
754 754
 
755 755
 function curl_get($url, array $get = NULL, array $options = array(), $loguser)
756 756
 {
757
-    $defaults = array(
758
-        CURLOPT_URL => $url. (strpos($url, '?') === FALSE ? '?' : ''). http_build_query($get),
759
-        CURLOPT_HEADER => 0,
760
-        CURLOPT_RETURNTRANSFER => TRUE,
761
-        CURLOPT_TIMEOUT => 4
762
-    );
763
-
764
-    $ch = curl_init();
765
-    curl_setopt_array($ch, ($options + $defaults));
766
-    if( ! $result = curl_exec($ch))
767
-    {
768
-        syslog(LOG_ERR, sprintf('%s: CURL Error: <%s>', $loguser, curl_error($ch)));
769
-    }
770
-    curl_close($ch);
771
-    return $result;
757
+	$defaults = array(
758
+		CURLOPT_URL => $url. (strpos($url, '?') === FALSE ? '?' : ''). http_build_query($get),
759
+		CURLOPT_HEADER => 0,
760
+		CURLOPT_RETURNTRANSFER => TRUE,
761
+		CURLOPT_TIMEOUT => 4
762
+	);
763
+
764
+	$ch = curl_init();
765
+	curl_setopt_array($ch, ($options + $defaults));
766
+	if( ! $result = curl_exec($ch))
767
+	{
768
+		syslog(LOG_ERR, sprintf('%s: CURL Error: <%s>', $loguser, curl_error($ch)));
769
+	}
770
+	curl_close($ch);
771
+	return $result;
772 772
 }
773 773
 
774 774
 /*
Please login to merge, or discard this patch.
Braces   +134 added lines, -91 removed lines patch added patch discarded remove patch
@@ -3,22 +3,27 @@  discard block
 block discarded – undo
3 3
 ini_set('error_log', 'syslog');
4 4
 
5 5
 function username() {
6
-	if (isset ($_SERVER['REMOTE_USER'])) $user = $_SERVER['REMOTE_USER'];
7
-        	else if (isset ($_SERVER['USER'])) $user = $_SERVER['USER'];
8
-                	else $user='unknown';
6
+	if (isset ($_SERVER['REMOTE_USER'])) {
7
+		$user = $_SERVER['REMOTE_USER'];
8
+	} else if (isset ($_SERVER['USER'])) {
9
+        		$user = $_SERVER['USER'];
10
+        	} else {
11
+                		$user='unknown';
12
+                	}
9 13
 	return $user;
10 14
 }
11 15
 
12 16
 function checkSSL() {
13
-	if ( empty( $_SERVER['HTTPS'] ) )
14
-		printf ('<div id="content">Ehi sysadmin! Your site is not secure. Please enable SSL on your server and configure a redirect, such as' .
17
+	if ( empty( $_SERVER['HTTPS'] ) ) {
18
+			printf ('<div id="content">Ehi sysadmin! Your site is not secure. Please enable SSL on your server and configure a redirect, such as' .
15 19
 			'<pre>' .
16 20
 			htmlspecialchars('<VirtualHost *:80>' . "\n" .
17 21
 			'  ServerName %s' . "\n" .
18 22
 			'  Redirect permanent / https://%s/' . "\n" .
19 23
 			'</VirtualHost>') .
20 24
 			'</pre></div>', gethostname(), gethostname());
21
-}
25
+	}
26
+	}
22 27
 
23 28
 function myConnect($host, $user, $pass, $db, $port, $tablelist, $typedesc, $loguser) {
24 29
         $db = ( $tablelist["$typedesc"]['milter'] ) ? $tablelist["$typedesc"]['name'] : $db;
@@ -99,8 +104,9 @@  discard block
 block discarded – undo
99 104
 	if ($myconn->query($query) === TRUE) {
100 105
 	    syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit.");
101 106
 	    $result=TRUE;
107
+	} else {
108
+		syslog(LOG_ERR, "$user: Error: ".$myconn->error);
102 109
 	}
103
-	else syslog(LOG_ERR, "$user: Error: ".$myconn->error);
104 110
 	return $result;
105 111
 }
106 112
 
@@ -110,8 +116,7 @@  discard block
 block discarded – undo
110 116
 	if ( $exptime ) { /* Entry already listed */
111 117
 		$nlist = '`nlist`';
112 118
 		$exptime = sprintf('\'%s\'', $exptime);  /* Eh MySQL... an hour lost to notice this */
113
-	}
114
-	else {
119
+	} else {
115 120
 		$exptime = 'CURRENT_TIMESTAMP';
116 121
 		$nlist = '`nlist` + 1';
117 122
 	}
@@ -149,8 +154,9 @@  discard block
 block discarded – undo
149 154
         if ($myconn->query($query) === TRUE) {
150 155
             syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit from $exptime.");
151 156
 		$result=TRUE;
157
+        } else {
158
+        	syslog (LOG_ERR, "$user: Error: ". $myconn->error);
152 159
         }
153
-        else syslog (LOG_ERR, "$user: Error: ". $myconn->error);
154 160
 	return $result;
155 161
 }
156 162
 
@@ -173,9 +179,11 @@  discard block
 block discarded – undo
173 179
 	}
174 180
 
175 181
 
176
-        if ($return=$myconn->query($query) === TRUE) 
177
-            syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>.");
178
-        else syslog(LOG_ERR, "$user: Error: ". $myconn->error);
182
+        if ($return=$myconn->query($query) === TRUE) {
183
+                    syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>.");
184
+        } else {
185
+        	syslog(LOG_ERR, "$user: Error: ". $myconn->error);
186
+        }
179 187
 
180 188
         return $return;
181 189
 }
@@ -197,8 +205,9 @@  discard block
 block discarded – undo
197 205
 
198 206
         if ($return=$myconn->query($query) === TRUE) {
199 207
             syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>");
208
+        } else {
209
+        	syslog(LOG_ERR, "$user: Error: ". $myconn->error);
200 210
         }
201
-        else syslog(LOG_ERR, "$user: Error: ". $myconn->error);
202 211
 	return $return;	
203 212
 }
204 213
 
@@ -222,14 +231,16 @@  discard block
 block discarded – undo
222 231
 				$j++;
223 232
 
224 233
 			} while ($myconn->next_result());
225
-		}
226
-		else {
234
+		} else {
227 235
 			syslog(LOG_ERR, "Expire job - Error: ". $myconn->error);
228 236
 			$return = FALSE;
229 237
 		}
230 238
 	}
231
-	if ( !($return) ) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated');
232
-	else  syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.');
239
+	if ( !($return) ) {
240
+		syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated');
241
+	} else {
242
+		syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.');
243
+	}
233 244
         return $return;
234 245
 }
235 246
 
@@ -238,8 +249,11 @@  discard block
 block discarded – undo
238 249
 
239 250
 	$exp=new DateTime($row['exp']);
240 251
 	$now=new DateTime('NOW');
241
-	if (($exp > $now) and ($row['active'])) return true;
242
-	else return false;
252
+	if (($exp > $now) and ($row['active'])) {
253
+		return true;
254
+	} else {
255
+		return false;
256
+	}
243 257
 
244 258
 }
245 259
 
@@ -259,10 +273,11 @@  discard block
 block discarded – undo
259 273
 END;
260 274
 		$activeMilts = explode(',',$value);
261 275
 		foreach ( $milts as $milter ) {
262
-			if ( in_array($milter, $activeMilts) )
263
-				$selected= 'selected';
264
-			else
265
-				$selected= NULL;
276
+			if ( in_array($milter, $activeMilts) ) {
277
+							$selected= 'selected';
278
+			} else {
279
+							$selected= NULL;
280
+			}
266 281
 			$button .= sprintf('<option value="%s" %s>%s</option>', $milter, $selected, $milter);
267 282
 		}	
268 283
 		$button .= '</select></div><input class="button" name="Change" type="submit" value="Change" /></form>';
@@ -279,9 +294,12 @@  discard block
 block discarded – undo
279 294
 	$whynot=NULL;
280 295
 	switch ($what) {
281 296
 		case 'Ok':
282
-			if ($lock) return NULL;
283
-			if (in_array($user,array_keys($adm)))
284
-				if ( consistentListing($myconn,$alltables,$typedesc,$value,$whynot) ) return require('relistButton.php');
297
+			if ($lock) {
298
+				return NULL;
299
+			}
300
+			if (in_array($user,array_keys($adm))) {
301
+							if ( consistentListing($myconn,$alltables,$typedesc,$value,$whynot) ) return require('relistButton.php');
302
+			}
285 303
 			return htmlspecialchars($whynot);
286 304
 		case 'Listed':
287 305
 		case 'WhiteListed':
@@ -293,7 +311,9 @@  discard block
 block discarded – undo
293 311
 function consistentListing($myconn,$alltables,$typed,$value,&$warn) {
294 312
 /* Check if there are no pending mislisting */
295 313
 	$warn = NULL;
296
-	if (! isset($alltables["$typed"]['depend']) ) return TRUE;
314
+	if (! isset($alltables["$typed"]['depend']) ) {
315
+		return TRUE;
316
+	}
297 317
 	foreach ($alltables["$typed"]['depend'] as $listdep) {
298 318
 		if ($alltables["$typed"]['field'] != $alltables["$listdep"]['field'] ) {
299 319
 			$warn = "Config ERROR: <$typed> and <$listdep> are of different types! I can't check consistency!";
@@ -324,10 +344,10 @@  discard block
 block discarded – undo
324 344
 	
325 345
 	if ( $tablelist['milter'] ) {
326 346
 		$table = milterTable($type);
327
-		if ($value == 'ALL')
328
-			$query = sprintf('SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id) GROUP by idmilt',
347
+		if ($value == 'ALL') {
348
+					$query = sprintf('SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id) GROUP by idmilt',
329 349
 				$table,$table);
330
-		else {
350
+		} else {
331 351
 			switch ($type) {
332 352
 				case 'network':
333 353
 					list($sub['net'],$sub['mask'])=explode('/',$value);
@@ -352,12 +372,11 @@  discard block
 block discarded – undo
352 372
 					return FALSE;
353 373
 			}
354 374
 		}
355
-	}
356
-
357
-	else {
375
+	} else {
358 376
 	        $table = $tablelist['name'];
359
-	        if ($value == 'ALL') $query = 'select * from '.$table;
360
-	        else {
377
+	        if ($value == 'ALL') {
378
+	        	$query = 'select * from '.$table;
379
+	        } else {
361 380
 	                switch ($type) {
362 381
 	                  case 'ip':
363 382
 	                        $query= "select * from $table where $type =  INET_ATON('$value')";
@@ -379,8 +398,9 @@  discard block
 block discarded – undo
379 398
 	}
380 399
 
381 400
 	$result = $myconn->query($query);
382
-	if($result === false)
383
-		syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error);
401
+	if($result === false) {
402
+			syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error);
403
+	}
384 404
         return $result;
385 405
 }
386 406
 
@@ -397,12 +417,14 @@  discard block
 block discarded – undo
397 417
 
398 418
 function isFull($myconn,$typedesc,$alltables) {
399 419
         if (isset($alltables["$typedesc"]['limit'])) {
400
-		if ( $alltables["$typedesc"]['milter'] )
401
-			$tab = 'net';
402
-		else
403
-			$tab = $alltables["$typedesc"]['name'];
404
-                if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) 
405
-                        return TRUE;
420
+		if ( $alltables["$typedesc"]['milter'] ) {
421
+					$tab = 'net';
422
+		} else {
423
+					$tab = $alltables["$typedesc"]['name'];
424
+		}
425
+                if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) {
426
+                                        return TRUE;
427
+                }
406 428
         }
407 429
 	return FALSE;
408 430
 }
@@ -415,8 +437,9 @@  discard block
 block discarded – undo
415 437
 	$tabhtm = <<<END
416 438
 	<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>
417 439
 END;
418
-	if ( $tables["$typedesc"]['milter'] )
419
-		$tabhtm .= '<th title="Milter active for this object">Milters</th>';
440
+	if ( $tables["$typedesc"]['milter'] ) {
441
+			$tabhtm .= '<th title="Milter active for this object">Milters</th>';
442
+	}
420 443
 	$tabhtm .= '<th>Authored by</th><th width="250">Reason</th><th>Action</th></tr></thead><tfoot><tr></tr></tfoot><tbody>'."\n";
421 444
 
422 445
 	$result = searchentry ($myconn,$value,$tables["$typedesc"]);
@@ -425,18 +448,23 @@  discard block
 block discarded – undo
425 448
 
426 449
         /* Check for limit in number of listed items */
427 450
 	$full = isFull($myconn,$typedesc,$tables);
428
-	if ($full) print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>';
451
+	if ($full) {
452
+		print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>';
453
+	}
429 454
 
430 455
 		if ($result->num_rows) {
431 456
 			print $tabhtm;
432 457
 			$i=0;
433 458
         		while ($riga = $result->fetch_array(MYSQLI_ASSOC)) {
434 459
 				if (isListed($riga)) {
435
-					if ($tables["$typedesc"]['bl']) $listed='Listed';
436
-					else $listed='WhiteListed';
437
-				}	
438
-				else
439
-					$listed='Ok';
460
+					if ($tables["$typedesc"]['bl']) {
461
+						$listed='Listed';
462
+					} else {
463
+						$listed='WhiteListed';
464
+					}
465
+				} else {
466
+									$listed='Ok';
467
+				}
440 468
 
441 469
 				switch ($type) {
442 470
 				  case 'ip':
@@ -449,27 +477,30 @@  discard block
 block discarded – undo
449 477
 					$element = $riga["$type"];
450 478
 				}
451 479
 
452
-				if ( $tables["$typedesc"]['milter'] AND checkMilterConf($tables["$typedesc"]) )
453
-					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",
480
+				if ( $tables["$typedesc"]['milter'] AND checkMilterConf($tables["$typedesc"]) ) {
481
+									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",
454 482
 					$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));
455
-				else
456
-					 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",
483
+				} else {
484
+									 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",
457 485
 					$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));
486
+				}
458 487
 				$i++;
459 488
         		}
460 489
 			print '</tbody></table>';
461
-		}
462
-		else {
490
+		} else {
463 491
 			print "<pre>$type &lt;$value&gt; is not listed!\n</pre>";
464
-			if ( in_array($user,array_keys($adm)) AND ($value != 'ALL') )
465
-				if ( (!$full) AND (consistentListing($myconn,$tables,$typedesc,$value,$whynot)) ) require_once('listForm.php');
466
-									else print '<p>'.htmlspecialchars($whynot).'</p>';
492
+			if ( in_array($user,array_keys($adm)) AND ($value != 'ALL') ) {
493
+							if ( (!$full) AND (consistentListing($myconn,$tables,$typedesc,$value,$whynot)) ) require_once('listForm.php');
494
+			} else {
495
+										print '<p>'.htmlspecialchars($whynot).'</p>';
496
+									}
467 497
 				
468 498
 		}
469 499
 		$result->free();
500
+	} else {
501
+		print '<pre>Query error or something wrong in DB schema'."\n</pre>";
502
+	}
470 503
 	}
471
-	else print '<pre>Query error or something wrong in DB schema'."\n</pre>";
472
-}
473 504
 
474 505
 
475 506
 
@@ -512,24 +543,32 @@  discard block
 block discarded – undo
512 543
                 $old_mailfrom = ini_get("sendmail_from");
513 544
                 ini_set("sendmail_from", $from);
514 545
                 $params = sprintf("-oi -f %s", '<>');
515
-                if (!(mail($to,$sbj, $body,$headers,$params))) $flag=FALSE;
516
-                else $flag=TRUE;
517
-                if (isset($old_mailfrom))
518
-                        ini_set("sendmail_from", $old_mailfrom);
519
-        }
520
-        else {
521
-                if (!(mail($to,$sbj, $body,$headers))) $flag=FALSE;
522
-                else $flag=TRUE;
546
+                if (!(mail($to,$sbj, $body,$headers,$params))) {
547
+                	$flag=FALSE;
548
+                } else {
549
+                	$flag=TRUE;
550
+                }
551
+                if (isset($old_mailfrom)) {
552
+                                        ini_set("sendmail_from", $old_mailfrom);
553
+                }
554
+        } else {
555
+                if (!(mail($to,$sbj, $body,$headers))) {
556
+                	$flag=FALSE;
557
+                } else {
558
+                	$flag=TRUE;
559
+                }
523 560
         }
524 561
         return $flag;
525 562
 }
526 563
 
527 564
 function emailToNotify($notify_file,$dom) {
528 565
 	$ini_array = parse_ini_file($notify_file);
529
-	if (in_array($dom,array_keys($ini_array)))
530
-		return $ini_array["$dom"];
531
-	else return FALSE;
532
-}
566
+	if (in_array($dom,array_keys($ini_array))) {
567
+			return $ini_array["$dom"];
568
+	} else {
569
+		return FALSE;
570
+	}
571
+	}
533 572
 
534 573
 
535 574
 function searchAndList ($myconn,$loguser,$tables,$typedesc,$value,$unit,&$quantity,&$reason) {
@@ -577,8 +616,7 @@  discard block
 block discarded – undo
577 616
 					 $reason);
578 617
 				$quantity = 1;
579 618
 				$unit = 'DAY';
580
-                        }
581
-			else {
619
+                        } else {
582 620
                         	/* Entry delisted */
583 621
 				$quantity *= $thisentry['nlist'];
584 622
 				$expdate = 0; /* This forces expiration from CURRENT_TIMESTAMP */
@@ -609,9 +647,10 @@  discard block
 block discarded – undo
609 647
 	$net = new \dautkom\ipv4\IPv4();
610 648
 	$range = $net->address($addressA)->mask($maskA)->getRange();
611 649
 	$ips = ipRange($range);
612
-	foreach ( $ips as $ip )
613
-		if ( $net->address($addressB)->mask($maskB)->has($ip) )
650
+	foreach ( $ips as $ip ) {
651
+			if ( $net->address($addressB)->mask($maskB)->has($ip) )
614 652
 			return TRUE;
653
+	}
615 654
 	return FALSE;
616 655
 }
617 656
 
@@ -688,8 +727,9 @@  discard block
 block discarded – undo
688 727
 		return FALSE;
689 728
 	}
690 729
 	if ($result->num_rows) {
691
-		while ($milt = $result->fetch_array(MYSQLI_ASSOC))
692
-			$milters[] = $milt['name'];
730
+		while ($milt = $result->fetch_array(MYSQLI_ASSOC)) {
731
+					$milters[] = $milt['name'];
732
+		}
693 733
 	}
694 734
 	$result->free();
695 735
 	return $milters;
@@ -715,12 +755,14 @@  discard block
 block discarded – undo
715 755
 				$query[] = "DELETE FROM  `milt` WHERE (`id` = '$miltID' AND `name` = '$value')";
716 756
 		}
717 757
 	}
718
-	if ( count($query) ) /* This "if" is redundant, because if I call this I already checked there is a change */
758
+	if ( count($query) ) {
759
+		/* This "if" is redundant, because if I call this I already checked there is a change */
719 760
 		/* I update datemod because the user couldn't change */
720 761
 		$query[] = sprintf('UPDATE `%s` SET
721 762
 						`user`=\'%s\',
722 763
 						`datemod`= CURRENT_TIMESTAMP
723 764
 					 WHERE `idmilt`=%d', $table, $loguser, $miltID);
765
+	}
724 766
 
725 767
 
726 768
 	/* Start a safe transaction: it commits only if all queries happen */
@@ -734,19 +776,20 @@  discard block
 block discarded – undo
734 776
 		}
735 777
 	}
736 778
 	if ( $ok ) {
737
-		if ( $myconn->commit() )
738
-			syslog(LOG_INFO, "$loguser: Milter setting changed successfully.");
739
-		else {
779
+		if ( $myconn->commit() ) {
780
+					syslog(LOG_INFO, "$loguser: Milter setting changed successfully.");
781
+		} else {
740 782
 			syslog(LOG_ERR, "$loguser: Milter setting NOT changed for an unpredictable COMMIT error.");
741
-			if ( $myconn->rollback() )
742
-				syslog(LOG_INFO, "$loguser: rollback succeeded.");
743
-			else
744
-				syslog(LOG_ERR, "$loguser: rollback failed. Your db could be compromized. Check it!");
783
+			if ( $myconn->rollback() ) {
784
+							syslog(LOG_INFO, "$loguser: rollback succeeded.");
785
+			} else {
786
+							syslog(LOG_ERR, "$loguser: rollback failed. Your db could be compromized. Check it!");
787
+			}
745 788
 			$ok = FALSE;
746 789
 		}
790
+	} else {
791
+			syslog(LOG_ERR, "$loguser: Error: Milter setting NOT changed. See at above errors.");
747 792
 	}
748
-	else
749
-		syslog(LOG_ERR, "$loguser: Error: Milter setting NOT changed. See at above errors.");
750 793
 	return $ok;
751 794
 		
752 795
 }
Please login to merge, or discard this patch.