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 ( c97009...4d35db )
by Marco
02:11
created
function.php 2 patches
Indentation   +149 added lines, -149 removed lines patch added patch discarded remove patch
@@ -4,18 +4,18 @@  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
 
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
-        if ($mysqli->connect_error) {
17
-           	syslog (LOG_EMERG, $loguser.': Connect Error to DB <'.$db.'> (' . $mysqli->connect_errno . ') '
18
-                    		. $mysqli->connect_error);
16
+		if ($mysqli->connect_error) {
17
+		   	syslog (LOG_EMERG, $loguser.': Connect Error to DB <'.$db.'> (' . $mysqli->connect_errno . ') '
18
+							. $mysqli->connect_error);
19 19
 		return FALSE;
20 20
 	}
21 21
 	syslog(LOG_INFO, $loguser.': Successfully MySQL connected at DB <'.$db.'> to ' . $mysqli->host_info) ;
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 			}
57 57
 		}
58 58
 		list($sub['net'],$sub['mask'])=explode('/',$value);
59
-                $query= sprintf("INSERT INTO `$table` (
59
+				$query= sprintf("INSERT INTO `$table` (
60 60
                         `$type` ,
61 61
 			`netmask`,
62 62
                         `date` ,
@@ -69,10 +69,10 @@  discard block
 block discarded – undo
69 69
                         INET_ATON( '%s' ) , INET_ATON( '%s' ) ,
70 70
                         CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s'
71 71
                 )" ,$sub['net'],$sub['mask'],$expUnit,$expQ,$user,$myreason);
72
-                break;
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` ,
@@ -87,8 +87,8 @@  discard block
 block discarded – undo
87 87
 	}
88 88
 
89 89
 	if ($myconn->query($query) === TRUE) {
90
-	    syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit.");
91
-	    $result=TRUE;
90
+		syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit.");
91
+		$result=TRUE;
92 92
 	}
93 93
 	else syslog(LOG_ERR, "$user: Error: ".$myconn->error);
94 94
 	return $result;
@@ -98,9 +98,9 @@  discard block
 block discarded – undo
98 98
 
99 99
 	$result=FALSE;
100 100
 
101
-        switch ($type) {
101
+		switch ($type) {
102 102
 	  case 'ip':
103
-                $query= sprintf("UPDATE `$table` SET
103
+				$query= sprintf("UPDATE `$table` SET
104 104
 			`active` = '1',
105 105
 			`user` = '%s',
106 106
 			`exp` = TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP),
@@ -108,9 +108,9 @@  discard block
 block discarded – undo
108 108
 			`reason` = '%s'
109 109
 			WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user,$expUnit,$expQ,$myreason,$value);
110 110
 		break;
111
-          case 'network':
111
+		  case 'network':
112 112
 		list($sub['net'],$sub['mask'])=explode('/',$value);
113
-                $query= sprintf("UPDATE `$table` SET
113
+				$query= sprintf("UPDATE `$table` SET
114 114
                         `active` = '1',
115 115
                         `user` = '%s',
116 116
                         `exp` = TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP),
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
                         WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1" ,$user,$expUnit,$expQ,$myreason,$sub['net'],$sub['mask']);
120 120
 		break;
121 121
 	  default:
122
-                $query= sprintf("UPDATE `$table` SET
122
+				$query= sprintf("UPDATE `$table` SET
123 123
                         `active` = '1',
124 124
                         `user` = '%s',
125 125
                         `exp` = TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP),
@@ -128,18 +128,18 @@  discard block
 block discarded – undo
128 128
 			WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user,$expUnit,$expQ,$myreason,$value);
129 129
 	}
130 130
 
131
-        if ($myconn->query($query) === TRUE) {
132
-            syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit.");
131
+		if ($myconn->query($query) === TRUE) {
132
+			syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit.");
133 133
 		$result=TRUE;
134
-        }
135
-        else syslog (LOG_ERR, "$user: Error: ". $myconn->error);
134
+		}
135
+		else syslog (LOG_ERR, "$user: Error: ". $myconn->error);
136 136
 	return $result;
137 137
 }
138 138
 
139 139
 function remove ($myconn,$user,$value,$type,$table) {
140 140
 
141
-        switch ($type) {
142
-          case 'ip':
141
+		switch ($type) {
142
+		  case 'ip':
143 143
 		$query = sprintf("DELETE FROM `$table` WHERE
144 144
                         `$table`.`$type` = INET_ATON('%s') LIMIT 1", $value);
145 145
 		break;
@@ -155,18 +155,18 @@  discard block
 block discarded – undo
155 155
 	}
156 156
 
157 157
 
158
-        if ($return=$myconn->query($query) === TRUE) 
159
-            syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>.");
160
-        else syslog(LOG_ERR, "$user: Error: ". $myconn->error);
158
+		if ($return=$myconn->query($query) === TRUE) 
159
+			syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>.");
160
+		else syslog(LOG_ERR, "$user: Error: ". $myconn->error);
161 161
 
162
-        return $return;
162
+		return $return;
163 163
 }
164 164
 
165 165
 
166 166
 function changestatus ($myconn,$user,$value,$status,$type,$table) {
167 167
 
168 168
 	switch ($type) {
169
-          case 'ip':
169
+		  case 'ip':
170 170
 		$query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user, $value);
171 171
 		break;
172 172
 	  case 'network':
@@ -177,16 +177,16 @@  discard block
 block discarded – undo
177 177
 		$query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user, $value);
178 178
 	}
179 179
 
180
-        if ($return=$myconn->query($query) === TRUE) {
181
-            syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>");
182
-        }
183
-        else syslog(LOG_ERR, "$user: Error: ". $myconn->error);
180
+		if ($return=$myconn->query($query) === TRUE) {
181
+			syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>");
182
+		}
183
+		else syslog(LOG_ERR, "$user: Error: ". $myconn->error);
184 184
 	return $return;	
185 185
 }
186 186
 
187 187
 
188 188
 function expire ($myconn,$user,$tables,$expireTime) {
189
-        $return=TRUE;
189
+		$return=TRUE;
190 190
 	$log=array();
191 191
 	$desc = array_keys($tables);
192 192
 	foreach ($desc as $tdesc) { 
@@ -196,11 +196,11 @@  discard block
 block discarded – undo
196 196
 		/* END OF QUERY */
197 197
 		$log[0] = 'expired for';
198 198
 		$log[1] = 'disabled for';
199
-        	if ($myconn->multi_query($query)) {
199
+			if ($myconn->multi_query($query)) {
200 200
 			$j = 0;
201 201
 			do {
202
-		    		$numdel = $myconn->affected_rows;
203
-	            		syslog(LOG_INFO, "Expire job - <$user> Permanently DELETED $numdel records ".$log[$j]." $expireTime YEARS from <".$tables["$tdesc"]['name'].'>.');
202
+					$numdel = $myconn->affected_rows;
203
+						syslog(LOG_INFO, "Expire job - <$user> Permanently DELETED $numdel records ".$log[$j]." $expireTime YEARS from <".$tables["$tdesc"]['name'].'>.');
204 204
 				$j++;
205 205
 
206 206
 			} while ($myconn->next_result());
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
 	}
213 213
 	if ( !($return) ) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated');
214 214
 	else  syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.');
215
-        return $return;
215
+		return $return;
216 216
 }
217 217
 
218 218
 
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 		if ( $entry->num_rows ) {
286 286
 			if ( $entry->num_rows == 1 ) {
287 287
 				$riga = $entry->fetch_array(MYSQLI_ASSOC);
288
-                        	if (isListed($riga)) {
288
+							if (isListed($riga)) {
289 289
 					$warn = "<$value> is already present in <$listdep> list!";
290 290
 					$entry->free();
291 291
 					return FALSE;
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
 function searchentry ($myconn,$value,$tablelist) {
303 303
 /* Make a MYSQL query and return result */
304 304
 
305
-        $type = $tablelist['field'];
305
+		$type = $tablelist['field'];
306 306
 	
307 307
 	if ( $tablelist['milter'] ) {
308 308
 		$table = milterTable($type);
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
 				case 'ip':
327 327
 					$query = sprintf('SELECT * FROM (
328 328
 							SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id)' .
329
-                                                		'WHERE `ip` =  INET_ATON(\'%s\')
329
+														'WHERE `ip` =  INET_ATON(\'%s\')
330 330
 							 ) AS val WHERE val.ip IS NOT null', $table, $table, $value);
331 331
 					break;
332 332
 				default:
@@ -337,33 +337,33 @@  discard block
 block discarded – undo
337 337
 	}
338 338
 
339 339
 	else {
340
-	        $table = $tablelist['name'];
341
-	        if ($value == 'ALL') $query = 'select * from '.$table;
342
-	        else {
343
-	                switch ($type) {
344
-	                  case 'ip':
345
-	                        $query= "select * from $table where $type =  INET_ATON('$value')";
346
-	                        break;
347
-	                  case 'network':
348
-	                        list($sub['net'],$sub['mask'])=explode('/',$value);
349
-	                        $query= sprintf('select * from `%s`
340
+			$table = $tablelist['name'];
341
+			if ($value == 'ALL') $query = 'select * from '.$table;
342
+			else {
343
+					switch ($type) {
344
+					  case 'ip':
345
+							$query= "select * from $table where $type =  INET_ATON('$value')";
346
+							break;
347
+					  case 'network':
348
+							list($sub['net'],$sub['mask'])=explode('/',$value);
349
+							$query= sprintf('select * from `%s`
350 350
 						WHERE (
351 351
 							inet_aton(\'%s\') >= network AND
352 352
 							( inet_aton(\'%s\') | ( inet_aton(\'%s\') ^ (power(2,32)-1) ) )
353 353
 								<= network | ( netmask ^ (power(2,32)-1) )
354 354
 						)', $table, $sub['net'], $sub['net'], $sub['mask']);
355 355
 ;
356
-	                        break;
357
-	                  default:
358
-	                        $query= "select * from $table where $type = '$value'";
359
-	                }
360
-	        }
356
+							break;
357
+					  default:
358
+							$query= "select * from $table where $type = '$value'";
359
+					}
360
+			}
361 361
 	}
362 362
 
363 363
 	$result = $myconn->query($query);
364 364
 	if($result === false)
365 365
 		syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error);
366
-        return $result;
366
+		return $result;
367 367
 }
368 368
 
369 369
 function countListed ($myconn,$table) {
@@ -378,14 +378,14 @@  discard block
 block discarded – undo
378 378
 
379 379
 
380 380
 function isFull($myconn,$typedesc,$alltables) {
381
-        if (isset($alltables["$typedesc"]['limit'])) {
381
+		if (isset($alltables["$typedesc"]['limit'])) {
382 382
 		if ( $alltables["$typedesc"]['milter'] )
383 383
 			$tab = 'net';
384 384
 		else
385 385
 			$tab = $alltables["$typedesc"]['name'];
386
-                if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) 
387
-                        return TRUE;
388
-        }
386
+				if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) 
387
+						return TRUE;
388
+		}
389 389
 	return FALSE;
390 390
 }
391 391
 
@@ -405,14 +405,14 @@  discard block
 block discarded – undo
405 405
 	if ($result) {
406 406
 		printf("<pre>Your request for $type &lt;$value&gt; returned %d items.\n</pre>", $result->num_rows);
407 407
 
408
-        /* Check for limit in number of listed items */
408
+		/* Check for limit in number of listed items */
409 409
 	$full = isFull($myconn,$typedesc,$tables);
410 410
 	if ($full) print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>';
411 411
 
412 412
 		if ($result->num_rows) {
413 413
 			print $tabhtm;
414 414
 			$i=0;
415
-        		while ($riga = $result->fetch_array(MYSQLI_ASSOC)) {
415
+				while ($riga = $result->fetch_array(MYSQLI_ASSOC)) {
416 416
 				if (isListed($riga)) {
417 417
 					if ($tables["$typedesc"]['bl']) $listed='Listed';
418 418
 					else $listed='WhiteListed';
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
 					 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",
439 439
 					$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));
440 440
 				$i++;
441
-        		}
441
+				}
442 442
 			print '</tbody></table>';
443 443
 		}
444 444
 		else {
@@ -458,15 +458,15 @@  discard block
 block discarded – undo
458 458
         
459 459
 function sendEmailWarn($tplf,$from,$to,$sbj,$emailListed,$intervalToExpire,$detail) {
460 460
 	$now = time();
461
-        setlocale (LC_TIME, 'it_IT');
462
-        $date = date("r",$now);
461
+		setlocale (LC_TIME, 'it_IT');
462
+		$date = date("r",$now);
463 463
 	$messageID = md5(uniqid($now,1)) . '@' . $_SERVER["HOSTNAME"];
464 464
 	$mua = 'PHP/' . phpversion();
465 465
 
466 466
 	/* Parsing headers */
467 467
 	if (!file_exists($tplf['header'])) {
468
-    		syslog(LOG_ERR, 'Sending email... template file <'.$tplf['header'].'> not found!');
469
-    		exit;
468
+			syslog(LOG_ERR, 'Sending email... template file <'.$tplf['header'].'> not found!');
469
+			exit;
470 470
 	}
471 471
 
472 472
 	$head_tmpl = file_get_contents($tplf['header']);
@@ -475,35 +475,35 @@  discard block
 block discarded – undo
475 475
 	$headers = str_replace($arr_tpl_vars, $arr_tpl_data, $head_tmpl);
476 476
 	$headers = preg_replace( '/\r|\n/', "\r\n", $headers );
477 477
 
478
-        /* Parsing body */
478
+		/* Parsing body */
479 479
 
480
-        if (!file_exists($tplf['body'])) {
481
-                syslog(LOG_ERR, 'Sending email... template file <'.$tplf['body'].'> not found!');
482
-                exit;
483
-        }
480
+		if (!file_exists($tplf['body'])) {
481
+				syslog(LOG_ERR, 'Sending email... template file <'.$tplf['body'].'> not found!');
482
+				exit;
483
+		}
484 484
 
485
-        $body_tmpl = file_get_contents($tplf['body']);
486
-        $arr_tpl_vars = array('{emailListed}','{expInterval}','{reason}');
487
-        $arr_tpl_data = array($emailListed,$intervalToExpire,$detail);
488
-        $body = str_replace($arr_tpl_vars, $arr_tpl_data, $body_tmpl);
489
-        $body = preg_replace( "/\r|\n/", "\r\n", $body );
485
+		$body_tmpl = file_get_contents($tplf['body']);
486
+		$arr_tpl_vars = array('{emailListed}','{expInterval}','{reason}');
487
+		$arr_tpl_data = array($emailListed,$intervalToExpire,$detail);
488
+		$body = str_replace($arr_tpl_vars, $arr_tpl_data, $body_tmpl);
489
+		$body = preg_replace( "/\r|\n/", "\r\n", $body );
490 490
 	$body = wordwrap ( $body, 75 , "\r\n" );	
491 491
 
492 492
 	/* Send the mail! */
493
-        if ( strlen(ini_get("safe_mode"))< 1) {
494
-                $old_mailfrom = ini_get("sendmail_from");
495
-                ini_set("sendmail_from", $from);
496
-                $params = sprintf("-oi -f %s", '<>');
497
-                if (!(mail($to,$sbj, $body,$headers,$params))) $flag=FALSE;
498
-                else $flag=TRUE;
499
-                if (isset($old_mailfrom))
500
-                        ini_set("sendmail_from", $old_mailfrom);
501
-        }
502
-        else {
503
-                if (!(mail($to,$sbj, $body,$headers))) $flag=FALSE;
504
-                else $flag=TRUE;
505
-        }
506
-        return $flag;
493
+		if ( strlen(ini_get("safe_mode"))< 1) {
494
+				$old_mailfrom = ini_get("sendmail_from");
495
+				ini_set("sendmail_from", $from);
496
+				$params = sprintf("-oi -f %s", '<>');
497
+				if (!(mail($to,$sbj, $body,$headers,$params))) $flag=FALSE;
498
+				else $flag=TRUE;
499
+				if (isset($old_mailfrom))
500
+						ini_set("sendmail_from", $old_mailfrom);
501
+		}
502
+		else {
503
+				if (!(mail($to,$sbj, $body,$headers))) $flag=FALSE;
504
+				else $flag=TRUE;
505
+		}
506
+		return $flag;
507 507
 }
508 508
 
509 509
 function emailToNotify($notify_file,$dom) {
@@ -517,59 +517,59 @@  discard block
 block discarded – undo
517 517
 function searchAndList ($myconn,$loguser,$tables,$typedesc,$value,$unit,&$quantity,$reason) {
518 518
 
519 519
 /* Search and list value */
520
-        $type = $tables["$typedesc"]['field'];
521
-        $table = $tables["$typedesc"]['name'];
522
-        $result = searchentry ($myconn,$value,$tables["$typedesc"]);
523
-
524
-        /* Manage abnormal conditions */
525
-        /* Value already present in db more than once. This is absurd. Panic! */
526
-        if ($result->num_rows > 1) {
527
-                syslog(LOG_EMERG,"$loguser: PANIC! Select for $type '$value' returned ". $result->num_rows ." items instead of one. Abnormal. Contact a sysadmin or a developer.");
528
-                $result->free();
529
-                return FALSE;
530
-        }
520
+		$type = $tables["$typedesc"]['field'];
521
+		$table = $tables["$typedesc"]['name'];
522
+		$result = searchentry ($myconn,$value,$tables["$typedesc"]);
523
+
524
+		/* Manage abnormal conditions */
525
+		/* Value already present in db more than once. This is absurd. Panic! */
526
+		if ($result->num_rows > 1) {
527
+				syslog(LOG_EMERG,"$loguser: PANIC! Select for $type '$value' returned ". $result->num_rows ." items instead of one. Abnormal. Contact a sysadmin or a developer.");
528
+				$result->free();
529
+				return FALSE;
530
+		}
531 531
 
532
-        /* Value already present in db or not present: to list anyway */
533
-        if ($result->num_rows >= 0) {
534
-                /* First, check for limit in number of listed items */
535
-                if (isFull($myconn,$typedesc,$tables)) {
536
-                        syslog(LOG_EMERG,"$loguser: $typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items. Abnormal exit.');
537
-                        $result->free();
538
-                        return FALSE;
539
-                }
540
-                /* Second, check if the (re)list would be consistent now */
541
-                if (! consistentListing($myconn,$tables,$typedesc,$value,$whynot) ) {
542
-                        syslog(LOG_ERR, $loguser.': '.$whynot);
543
-                        $result->free();
544
-                        return FALSE;
545
-                }
546
-        }
547
-        /* End of abnormal conditions */
532
+		/* Value already present in db or not present: to list anyway */
533
+		if ($result->num_rows >= 0) {
534
+				/* First, check for limit in number of listed items */
535
+				if (isFull($myconn,$typedesc,$tables)) {
536
+						syslog(LOG_EMERG,"$loguser: $typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items. Abnormal exit.');
537
+						$result->free();
538
+						return FALSE;
539
+				}
540
+				/* Second, check if the (re)list would be consistent now */
541
+				if (! consistentListing($myconn,$tables,$typedesc,$value,$whynot) ) {
542
+						syslog(LOG_ERR, $loguser.': '.$whynot);
543
+						$result->free();
544
+						return FALSE;
545
+				}
546
+		}
547
+		/* End of abnormal conditions */
548 548
 
549 549
 
550
-        /* Finally, here I can list the value! */
550
+		/* Finally, here I can list the value! */
551 551
 	$thisentry = $result->fetch_array(MYSQLI_ASSOC);
552
-        switch ($result->num_rows) {
553
-                /* Relist value if already present */
554
-                case 1:
555
-                        /* Entry already listed */
556
-                        if ( isListed($thisentry) ) {
557
-                                syslog(LOG_INFO, $loguser.': '.$value.' already listed. Nothing to do.');
558
-                                $result->free();
559
-                                return FALSE;
560
-                        }
561
-
562
-                        /* Entry delisted */
563
-                        $result->free();
552
+		switch ($result->num_rows) {
553
+				/* Relist value if already present */
554
+				case 1:
555
+						/* Entry already listed */
556
+						if ( isListed($thisentry) ) {
557
+								syslog(LOG_INFO, $loguser.': '.$value.' already listed. Nothing to do.');
558
+								$result->free();
559
+								return FALSE;
560
+						}
561
+
562
+						/* Entry delisted */
563
+						$result->free();
564 564
 			$quantity *= $thisentry['nlist'];
565
-                        return relist ($myconn,$loguser,$value,$type,$table,$unit,$quantity,$reason);
565
+						return relist ($myconn,$loguser,$value,$type,$table,$unit,$quantity,$reason);
566 566
 
567 567
 
568
-                /* First time list value */
569
-                case 0:
570
-                        $result->free();
571
-                        return addtolist ($myconn,$loguser,$value,$tables["$typedesc"],$unit,$quantity,$reason,$_);
572
-        }
568
+				/* First time list value */
569
+				case 0:
570
+						$result->free();
571
+						return addtolist ($myconn,$loguser,$value,$tables["$typedesc"],$unit,$quantity,$reason,$_);
572
+		}
573 573
 }
574 574
 
575 575
 
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
 		return FALSE;
603 603
 	}
604 604
 	$result = searchentry ($myconn,'ALL',$tabletype);
605
-        if ($result->num_rows) {
605
+		if ($result->num_rows) {
606 606
 		while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
607 607
 			$thisNet = long2ip($row['network']).'/'.long2ip($row['netmask']);
608 608
 			if ( isIn($thisNet, $net) ) {
@@ -622,7 +622,7 @@  discard block
 block discarded – undo
622 622
 /* For miltermap */
623 623
 function checkMilterConf($table) {
624 624
 	if (isset($table['milter'])) {
625
-        	if ($table['milter'] ===  TRUE) {
625
+			if ($table['milter'] ===  TRUE) {
626 626
 			switch ( $table['field'] ) {
627 627
 				case 'network':
628 628
 				case 'ip':
@@ -645,15 +645,15 @@  discard block
 block discarded – undo
645 645
 
646 646
 function milterTable($t) {
647 647
 	/* Return the milter object table for type t  or FALSE on error */
648
-        switch ($t) {
649
-                case 'network':
650
-                        return 'net';
651
-                case 'ip':
652
-                        return 'ips';
653
-                default:
648
+		switch ($t) {
649
+				case 'network':
650
+						return 'net';
651
+				case 'ip':
652
+						return 'ips';
653
+				default:
654 654
 			syslog(LOG_EMERG, "ALERT: type <$t> not allowed in configuration. ");
655
-                        return FALSE;
656
-        }
655
+						return FALSE;
656
+		}
657 657
 }
658 658
 
659 659
 
@@ -661,9 +661,9 @@  discard block
 block discarded – undo
661 661
 	$milters=array();
662 662
 	$query = 'SELECT `name` FROM `config`';
663 663
 
664
-        $result = $myconn->query($query);
665
-        if($result === false) {
666
-                syslog(LOG_EMERG, "$loguser: ALERT: Query <$query> failed: ".$myconn->error);
664
+		$result = $myconn->query($query);
665
+		if($result === false) {
666
+				syslog(LOG_EMERG, "$loguser: ALERT: Query <$query> failed: ".$myconn->error);
667 667
 		return FALSE;
668 668
 	}
669 669
 	if ($result->num_rows) {
Please login to merge, or discard this patch.
Spacing   +149 added lines, -149 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,60 +83,60 @@  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) {
97
+function relist($myconn, $user, $value, $type, $table, $expUnit, $expQ, $myreason) {
98 98
 
99
-	$result=FALSE;
99
+	$result = FALSE;
100 100
 
101 101
         switch ($type) {
102 102
 	  case 'ip':
103
-                $query= sprintf("UPDATE `$table` SET
103
+                $query = sprintf("UPDATE `$table` SET
104 104
 			`active` = '1',
105 105
 			`user` = '%s',
106 106
 			`exp` = TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP),
107 107
 			`nlist` = `nlist` + 1,
108 108
 			`reason` = '%s'
109
-			WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user,$expUnit,$expQ,$myreason,$value);
109
+			WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1", $user, $expUnit, $expQ, $myreason, $value);
110 110
 		break;
111 111
           case 'network':
112
-		list($sub['net'],$sub['mask'])=explode('/',$value);
113
-                $query= sprintf("UPDATE `$table` SET
112
+		list($sub['net'], $sub['mask']) = explode('/', $value);
113
+                $query = sprintf("UPDATE `$table` SET
114 114
                         `active` = '1',
115 115
                         `user` = '%s',
116 116
                         `exp` = TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP),
117 117
                         `nlist` = `nlist` + 1,
118 118
                         `reason` = '%s'
119
-                        WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1" ,$user,$expUnit,$expQ,$myreason,$sub['net'],$sub['mask']);
119
+                        WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1", $user, $expUnit, $expQ, $myreason, $sub['net'], $sub['mask']);
120 120
 		break;
121 121
 	  default:
122
-                $query= sprintf("UPDATE `$table` SET
122
+                $query = sprintf("UPDATE `$table` SET
123 123
                         `active` = '1',
124 124
                         `user` = '%s',
125 125
                         `exp` = TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP),
126 126
                         `nlist` = `nlist` + 1,
127 127
                         `reason` = '%s'
128
-			WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user,$expUnit,$expQ,$myreason,$value);
128
+			WHERE `$table`.`$type` = '%s' LIMIT 1", $user, $expUnit, $expQ, $myreason, $value);
129 129
 	}
130 130
 
131 131
         if ($myconn->query($query) === TRUE) {
132 132
             syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit.");
133
-		$result=TRUE;
133
+		$result = TRUE;
134 134
         }
135
-        else syslog (LOG_ERR, "$user: Error: ". $myconn->error);
135
+        else syslog(LOG_ERR, "$user: Error: ".$myconn->error);
136 136
 	return $result;
137 137
 }
138 138
 
139
-function remove ($myconn,$user,$value,$type,$table) {
139
+function remove($myconn, $user, $value, $type, $table) {
140 140
 
141 141
         switch ($type) {
142 142
           case 'ip':
@@ -144,10 +144,10 @@  discard block
 block discarded – undo
144 144
                         `$table`.`$type` = INET_ATON('%s') LIMIT 1", $value);
145 145
 		break;
146 146
 	  case 'network':
147
-		list($sub['net'],$sub['mask'])=explode('/',$value);
147
+		list($sub['net'], $sub['mask']) = explode('/', $value);
148 148
 		$query = sprintf("DELETE FROM `$table` WHERE
149 149
 			`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s') LIMIT 1",
150
-			$sub['net'],$sub['mask']);
150
+			$sub['net'], $sub['mask']);
151 151
 		break;
152 152
 	  default:
153 153
 		$query = sprintf("DELETE FROM `$table` WHERE
@@ -155,39 +155,39 @@  discard block
 block discarded – undo
155 155
 	}
156 156
 
157 157
 
158
-        if ($return=$myconn->query($query) === TRUE) 
158
+        if ($return = $myconn->query($query) === TRUE) 
159 159
             syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>.");
160
-        else syslog(LOG_ERR, "$user: Error: ". $myconn->error);
160
+        else syslog(LOG_ERR, "$user: Error: ".$myconn->error);
161 161
 
162 162
         return $return;
163 163
 }
164 164
 
165 165
 
166
-function changestatus ($myconn,$user,$value,$status,$type,$table) {
166
+function changestatus($myconn, $user, $value, $status, $type, $table) {
167 167
 
168 168
 	switch ($type) {
169 169
           case 'ip':
170
-		$query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user, $value);
170
+		$query = sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1", $user, $value);
171 171
 		break;
172 172
 	  case 'network':
173
-		list($sub['net'],$sub['mask'])=explode('/',$value);
174
-		$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']);
173
+		list($sub['net'], $sub['mask']) = explode('/', $value);
174
+		$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']);
175 175
 		break;
176 176
 	  default:
177
-		$query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user, $value);
177
+		$query = sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = '%s' LIMIT 1", $user, $value);
178 178
 	}
179 179
 
180
-        if ($return=$myconn->query($query) === TRUE) {
180
+        if ($return = $myconn->query($query) === TRUE) {
181 181
             syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>");
182 182
         }
183
-        else syslog(LOG_ERR, "$user: Error: ". $myconn->error);
183
+        else syslog(LOG_ERR, "$user: Error: ".$myconn->error);
184 184
 	return $return;	
185 185
 }
186 186
 
187 187
 
188
-function expire ($myconn,$user,$tables,$expireTime) {
189
-        $return=TRUE;
190
-	$log=array();
188
+function expire($myconn, $user, $tables, $expireTime) {
189
+        $return = TRUE;
190
+	$log = array();
191 191
 	$desc = array_keys($tables);
192 192
 	foreach ($desc as $tdesc) { 
193 193
 		/* QUERY */
@@ -206,11 +206,11 @@  discard block
 block discarded – undo
206 206
 			} while ($myconn->next_result());
207 207
 		}
208 208
 		else {
209
-			syslog(LOG_ERR, "Expire job - Error: ". $myconn->error);
209
+			syslog(LOG_ERR, "Expire job - Error: ".$myconn->error);
210 210
 			$return = FALSE;
211 211
 		}
212 212
 	}
213
-	if ( !($return) ) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated');
213
+	if (!($return)) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated');
214 214
 	else  syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.');
215 215
         return $return;
216 216
 }
@@ -218,18 +218,18 @@  discard block
 block discarded – undo
218 218
 
219 219
 function isListed($row) {
220 220
 
221
-	$exp=new DateTime($row['exp']);
222
-	$now=new DateTime('NOW');
223
-	if (($exp > $now) and ($row['active'])) return true;
221
+	$exp = new DateTime($row['exp']);
222
+	$now = new DateTime('NOW');
223
+	if (($exp>$now) and ($row['active'])) return true;
224 224
 	else return false;
225 225
 
226 226
 }
227 227
 
228 228
 
229
-function askMilter($myconn,$id,$obj,$typedesc,$miltId,$value,$user,$adm)  {
230
-	$milts = readMiltName($myconn,$user);
229
+function askMilter($myconn, $id, $obj, $typedesc, $miltId, $value, $user, $adm) {
230
+	$milts = readMiltName($myconn, $user);
231 231
 	$size = count($milts);
232
-	if (in_array($user,array_keys($adm))) {
232
+	if (in_array($user, array_keys($adm))) {
233 233
 		$button = <<<END
234 234
 		<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;" />
235 235
 		<input name="object" type="hidden" value="$obj" /><input name="oldvalues" type="hidden" value="$value" />
@@ -239,12 +239,12 @@  discard block
 block discarded – undo
239 239
 		<div class="noscroll">
240 240
 		<select class="input_text" name="newvalues[]" multiple size="$size">
241 241
 END;
242
-		$activeMilts = explode(',',$value);
243
-		foreach ( $milts as $milter ) {
244
-			if ( in_array($milter, $activeMilts) )
245
-				$selected= 'selected';
242
+		$activeMilts = explode(',', $value);
243
+		foreach ($milts as $milter) {
244
+			if (in_array($milter, $activeMilts))
245
+				$selected = 'selected';
246 246
 			else
247
-				$selected= NULL;
247
+				$selected = NULL;
248 248
 			$button .= sprintf('<option value="%s" %s>%s</option>', $milter, $selected, $milter);
249 249
 		}	
250 250
 		$button .= '</select></div><input class="button" name="Change" type="submit" value="Change" /></form>';
@@ -256,14 +256,14 @@  discard block
 block discarded – undo
256 256
 }
257 257
 
258 258
 
259
-function ask($myconn,$id,$what,$alltables,$typedesc,$value,$lock,$user,$adm) {
259
+function ask($myconn, $id, $what, $alltables, $typedesc, $value, $lock, $user, $adm) {
260 260
 
261
-	$whynot=NULL;
261
+	$whynot = NULL;
262 262
 	switch ($what) {
263 263
 		case 'Ok':
264 264
 			if ($lock) return NULL;
265
-			if (in_array($user,array_keys($adm)))
266
-				if ( consistentListing($myconn,$alltables,$typedesc,$value,$whynot) ) return require('relistButton.php');
265
+			if (in_array($user, array_keys($adm)))
266
+				if (consistentListing($myconn, $alltables, $typedesc, $value, $whynot)) return require('relistButton.php');
267 267
 			return htmlspecialchars($whynot);
268 268
 		case 'Listed':
269 269
 		case 'WhiteListed':
@@ -272,18 +272,18 @@  discard block
 block discarded – undo
272 272
 }
273 273
 
274 274
 
275
-function consistentListing($myconn,$alltables,$typed,$value,&$warn) {
275
+function consistentListing($myconn, $alltables, $typed, $value, &$warn) {
276 276
 /* Check if there are no pending mislisting */
277 277
 	$warn = NULL;
278
-	if (! isset($alltables["$typed"]['depend']) ) return TRUE;
278
+	if (!isset($alltables["$typed"]['depend'])) return TRUE;
279 279
 	foreach ($alltables["$typed"]['depend'] as $listdep) {
280
-		if ($alltables["$typed"]['field'] != $alltables["$listdep"]['field'] ) {
280
+		if ($alltables["$typed"]['field'] != $alltables["$listdep"]['field']) {
281 281
 			$warn = "Config ERROR: <$typed> and <$listdep> are of different types! I can't check consistency!";
282 282
 			return FALSE;
283 283
 		}
284
-		$entry = searchentry($myconn,$value,$alltables["$listdep"]);
285
-		if ( $entry->num_rows ) {
286
-			if ( $entry->num_rows == 1 ) {
284
+		$entry = searchentry($myconn, $value, $alltables["$listdep"]);
285
+		if ($entry->num_rows) {
286
+			if ($entry->num_rows == 1) {
287 287
 				$riga = $entry->fetch_array(MYSQLI_ASSOC);
288 288
                         	if (isListed($riga)) {
289 289
 					$warn = "<$value> is already present in <$listdep> list!";
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
 					return FALSE;
292 292
 				}
293 293
 			}
294
-			if ( $entry->num_rows > 1 ) {$warn = "<$value> seems to be present more than once in <$listdep>. Contact a sysadmin NOW!";}
294
+			if ($entry->num_rows>1) {$warn = "<$value> seems to be present more than once in <$listdep>. Contact a sysadmin NOW!"; }
295 295
 		}
296 296
 		$entry->free();
297 297
 	}
@@ -299,20 +299,20 @@  discard block
 block discarded – undo
299 299
 	return TRUE;
300 300
 }
301 301
 
302
-function searchentry ($myconn,$value,$tablelist) {
302
+function searchentry($myconn, $value, $tablelist) {
303 303
 /* Make a MYSQL query and return result */
304 304
 
305 305
         $type = $tablelist['field'];
306 306
 	
307
-	if ( $tablelist['milter'] ) {
307
+	if ($tablelist['milter']) {
308 308
 		$table = milterTable($type);
309 309
 		if ($value == 'ALL')
310 310
 			$query = sprintf('SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id) GROUP by idmilt',
311
-				$table,$table);
311
+				$table, $table);
312 312
 		else {
313 313
 			switch ($type) {
314 314
 				case 'network':
315
-					list($sub['net'],$sub['mask'])=explode('/',$value);
315
+					list($sub['net'], $sub['mask']) = explode('/', $value);
316 316
 					$query = sprintf('SELECT * FROM (
317 317
 							SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id)
318 318
 				 				WHERE (
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 							 ) AS val WHERE val.ip IS NOT null', $table, $table, $value);
331 331
 					break;
332 332
 				default:
333
-					syslog(LOG_EMERG, 'ALERT: The type <'.$type.'> is not allowed for milter lists.' );
333
+					syslog(LOG_EMERG, 'ALERT: The type <'.$type.'> is not allowed for milter lists.');
334 334
 					return FALSE;
335 335
 			}
336 336
 		}
@@ -342,11 +342,11 @@  discard block
 block discarded – undo
342 342
 	        else {
343 343
 	                switch ($type) {
344 344
 	                  case 'ip':
345
-	                        $query= "select * from $table where $type =  INET_ATON('$value')";
345
+	                        $query = "select * from $table where $type =  INET_ATON('$value')";
346 346
 	                        break;
347 347
 	                  case 'network':
348
-	                        list($sub['net'],$sub['mask'])=explode('/',$value);
349
-	                        $query= sprintf('select * from `%s`
348
+	                        list($sub['net'], $sub['mask']) = explode('/', $value);
349
+	                        $query = sprintf('select * from `%s`
350 350
 						WHERE (
351 351
 							inet_aton(\'%s\') >= network AND
352 352
 							( inet_aton(\'%s\') | ( inet_aton(\'%s\') ^ (power(2,32)-1) ) )
@@ -355,18 +355,18 @@  discard block
 block discarded – undo
355 355
 ;
356 356
 	                        break;
357 357
 	                  default:
358
-	                        $query= "select * from $table where $type = '$value'";
358
+	                        $query = "select * from $table where $type = '$value'";
359 359
 	                }
360 360
 	        }
361 361
 	}
362 362
 
363 363
 	$result = $myconn->query($query);
364
-	if($result === false)
364
+	if ($result === false)
365 365
 		syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error);
366 366
         return $result;
367 367
 }
368 368
 
369
-function countListed ($myconn,$table) {
369
+function countListed($myconn, $table) {
370 370
 /* Return number of current listed items into a rbl table */
371 371
 	$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";
372 372
 	$row = $myconn->query($query);
@@ -377,48 +377,48 @@  discard block
 block discarded – undo
377 377
 }
378 378
 
379 379
 
380
-function isFull($myconn,$typedesc,$alltables) {
380
+function isFull($myconn, $typedesc, $alltables) {
381 381
         if (isset($alltables["$typedesc"]['limit'])) {
382
-		if ( $alltables["$typedesc"]['milter'] )
382
+		if ($alltables["$typedesc"]['milter'])
383 383
 			$tab = 'net';
384 384
 		else
385 385
 			$tab = $alltables["$typedesc"]['name'];
386
-                if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) 
386
+                if (countListed($myconn, $tab)>=$alltables["$typedesc"]['limit']) 
387 387
                         return TRUE;
388 388
         }
389 389
 	return FALSE;
390 390
 }
391 391
 
392
-function rlookup ($myconn,$user,$adm,$value,$typedesc,$tables) {
392
+function rlookup($myconn, $user, $adm, $value, $typedesc, $tables) {
393 393
 
394 394
 	$type = $tables["$typedesc"]['field'];
395
-	$whynot=NULL;
395
+	$whynot = NULL;
396 396
 
397 397
 	$tabhtm = <<<END
398 398
 	<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>
399 399
 END;
400
-	if ( $tables["$typedesc"]['milter'] )
400
+	if ($tables["$typedesc"]['milter'])
401 401
 		$tabhtm .= '<th title="Milter active for this object">Milters</th>';
402 402
 	$tabhtm .= '<th>Authored by</th><th width="250">Reason</th><th>Action</th></tr></thead><tfoot><tr></tr></tfoot><tbody>'."\n";
403 403
 
404
-	$result = searchentry ($myconn,$value,$tables["$typedesc"]);
404
+	$result = searchentry($myconn, $value, $tables["$typedesc"]);
405 405
 	if ($result) {
406 406
 		printf("<pre>Your request for $type &lt;$value&gt; returned %d items.\n</pre>", $result->num_rows);
407 407
 
408 408
         /* Check for limit in number of listed items */
409
-	$full = isFull($myconn,$typedesc,$tables);
409
+	$full = isFull($myconn, $typedesc, $tables);
410 410
 	if ($full) print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>';
411 411
 
412 412
 		if ($result->num_rows) {
413 413
 			print $tabhtm;
414
-			$i=0;
414
+			$i = 0;
415 415
         		while ($riga = $result->fetch_array(MYSQLI_ASSOC)) {
416 416
 				if (isListed($riga)) {
417
-					if ($tables["$typedesc"]['bl']) $listed='Listed';
418
-					else $listed='WhiteListed';
417
+					if ($tables["$typedesc"]['bl']) $listed = 'Listed';
418
+					else $listed = 'WhiteListed';
419 419
 				}	
420 420
 				else
421
-					$listed='Ok';
421
+					$listed = 'Ok';
422 422
 
423 423
 				switch ($type) {
424 424
 				  case 'ip':
@@ -431,20 +431,20 @@  discard block
 block discarded – undo
431 431
 					$element = $riga["$type"];
432 432
 				}
433 433
 
434
-				if ( $tables["$typedesc"]['milter'] AND checkMilterConf($tables["$typedesc"]) )
435
-					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",
436
-					$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));
434
+				if ($tables["$typedesc"]['milter'] AND checkMilterConf($tables["$typedesc"]))
435
+					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",
436
+					$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));
437 437
 				else
438
-					 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",
439
-					$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));
438
+					 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",
439
+					$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));
440 440
 				$i++;
441 441
         		}
442 442
 			print '</tbody></table>';
443 443
 		}
444 444
 		else {
445 445
 			print "<pre>$type &lt;$value&gt; is not listed!\n</pre>";
446
-			if ( in_array($user,array_keys($adm)) AND ($value != 'ALL') )
447
-				if ( (!$full) AND (consistentListing($myconn,$tables,$typedesc,$value,$whynot)) ) require_once('listForm.php');
446
+			if (in_array($user, array_keys($adm)) AND ($value != 'ALL'))
447
+				if ((!$full) AND (consistentListing($myconn, $tables, $typedesc, $value, $whynot))) require_once('listForm.php');
448 448
 									else print '<p>'.htmlspecialchars($whynot).'</p>';
449 449
 				
450 450
 		}
@@ -456,12 +456,12 @@  discard block
 block discarded – undo
456 456
 
457 457
 
458 458
         
459
-function sendEmailWarn($tplf,$from,$to,$sbj,$emailListed,$intervalToExpire,$detail) {
459
+function sendEmailWarn($tplf, $from, $to, $sbj, $emailListed, $intervalToExpire, $detail) {
460 460
 	$now = time();
461
-        setlocale (LC_TIME, 'it_IT');
462
-        $date = date("r",$now);
463
-	$messageID = md5(uniqid($now,1)) . '@' . $_SERVER["HOSTNAME"];
464
-	$mua = 'PHP/' . phpversion();
461
+        setlocale(LC_TIME, 'it_IT');
462
+        $date = date("r", $now);
463
+	$messageID = md5(uniqid($now, 1)).'@'.$_SERVER["HOSTNAME"];
464
+	$mua = 'PHP/'.phpversion();
465 465
 
466 466
 	/* Parsing headers */
467 467
 	if (!file_exists($tplf['header'])) {
@@ -470,10 +470,10 @@  discard block
 block discarded – undo
470 470
 	}
471 471
 
472 472
 	$head_tmpl = file_get_contents($tplf['header']);
473
-	$arr_tpl_vars = array('{from}','{to}','{date}','{messageID}','{mua}');
474
-	$arr_tpl_data = array($from,$to,$date,$messageID,$mua);
473
+	$arr_tpl_vars = array('{from}', '{to}', '{date}', '{messageID}', '{mua}');
474
+	$arr_tpl_data = array($from, $to, $date, $messageID, $mua);
475 475
 	$headers = str_replace($arr_tpl_vars, $arr_tpl_data, $head_tmpl);
476
-	$headers = preg_replace( '/\r|\n/', "\r\n", $headers );
476
+	$headers = preg_replace('/\r|\n/', "\r\n", $headers);
477 477
 
478 478
         /* Parsing body */
479 479
 
@@ -483,62 +483,62 @@  discard block
 block discarded – undo
483 483
         }
484 484
 
485 485
         $body_tmpl = file_get_contents($tplf['body']);
486
-        $arr_tpl_vars = array('{emailListed}','{expInterval}','{reason}');
487
-        $arr_tpl_data = array($emailListed,$intervalToExpire,$detail);
486
+        $arr_tpl_vars = array('{emailListed}', '{expInterval}', '{reason}');
487
+        $arr_tpl_data = array($emailListed, $intervalToExpire, $detail);
488 488
         $body = str_replace($arr_tpl_vars, $arr_tpl_data, $body_tmpl);
489
-        $body = preg_replace( "/\r|\n/", "\r\n", $body );
490
-	$body = wordwrap ( $body, 75 , "\r\n" );	
489
+        $body = preg_replace("/\r|\n/", "\r\n", $body);
490
+	$body = wordwrap($body, 75, "\r\n");	
491 491
 
492 492
 	/* Send the mail! */
493
-        if ( strlen(ini_get("safe_mode"))< 1) {
493
+        if (strlen(ini_get("safe_mode"))<1) {
494 494
                 $old_mailfrom = ini_get("sendmail_from");
495 495
                 ini_set("sendmail_from", $from);
496 496
                 $params = sprintf("-oi -f %s", '<>');
497
-                if (!(mail($to,$sbj, $body,$headers,$params))) $flag=FALSE;
498
-                else $flag=TRUE;
497
+                if (!(mail($to, $sbj, $body, $headers, $params))) $flag = FALSE;
498
+                else $flag = TRUE;
499 499
                 if (isset($old_mailfrom))
500 500
                         ini_set("sendmail_from", $old_mailfrom);
501 501
         }
502 502
         else {
503
-                if (!(mail($to,$sbj, $body,$headers))) $flag=FALSE;
504
-                else $flag=TRUE;
503
+                if (!(mail($to, $sbj, $body, $headers))) $flag = FALSE;
504
+                else $flag = TRUE;
505 505
         }
506 506
         return $flag;
507 507
 }
508 508
 
509
-function emailToNotify($notify_file,$dom) {
509
+function emailToNotify($notify_file, $dom) {
510 510
 	$ini_array = parse_ini_file($notify_file);
511
-	if (in_array($dom,array_keys($ini_array)))
511
+	if (in_array($dom, array_keys($ini_array)))
512 512
 		return $ini_array["$dom"];
513 513
 	else return FALSE;
514 514
 }
515 515
 
516 516
 
517
-function searchAndList ($myconn,$loguser,$tables,$typedesc,$value,$unit,&$quantity,$reason) {
517
+function searchAndList($myconn, $loguser, $tables, $typedesc, $value, $unit, &$quantity, $reason) {
518 518
 
519 519
 /* Search and list value */
520 520
         $type = $tables["$typedesc"]['field'];
521 521
         $table = $tables["$typedesc"]['name'];
522
-        $result = searchentry ($myconn,$value,$tables["$typedesc"]);
522
+        $result = searchentry($myconn, $value, $tables["$typedesc"]);
523 523
 
524 524
         /* Manage abnormal conditions */
525 525
         /* Value already present in db more than once. This is absurd. Panic! */
526
-        if ($result->num_rows > 1) {
527
-                syslog(LOG_EMERG,"$loguser: PANIC! Select for $type '$value' returned ". $result->num_rows ." items instead of one. Abnormal. Contact a sysadmin or a developer.");
526
+        if ($result->num_rows>1) {
527
+                syslog(LOG_EMERG, "$loguser: PANIC! Select for $type '$value' returned ".$result->num_rows." items instead of one. Abnormal. Contact a sysadmin or a developer.");
528 528
                 $result->free();
529 529
                 return FALSE;
530 530
         }
531 531
 
532 532
         /* Value already present in db or not present: to list anyway */
533
-        if ($result->num_rows >= 0) {
533
+        if ($result->num_rows>=0) {
534 534
                 /* First, check for limit in number of listed items */
535
-                if (isFull($myconn,$typedesc,$tables)) {
536
-                        syslog(LOG_EMERG,"$loguser: $typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items. Abnormal exit.');
535
+                if (isFull($myconn, $typedesc, $tables)) {
536
+                        syslog(LOG_EMERG, "$loguser: $typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items. Abnormal exit.');
537 537
                         $result->free();
538 538
                         return FALSE;
539 539
                 }
540 540
                 /* Second, check if the (re)list would be consistent now */
541
-                if (! consistentListing($myconn,$tables,$typedesc,$value,$whynot) ) {
541
+                if (!consistentListing($myconn, $tables, $typedesc, $value, $whynot)) {
542 542
                         syslog(LOG_ERR, $loguser.': '.$whynot);
543 543
                         $result->free();
544 544
                         return FALSE;
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
                 /* Relist value if already present */
554 554
                 case 1:
555 555
                         /* Entry already listed */
556
-                        if ( isListed($thisentry) ) {
556
+                        if (isListed($thisentry)) {
557 557
                                 syslog(LOG_INFO, $loguser.': '.$value.' already listed. Nothing to do.');
558 558
                                 $result->free();
559 559
                                 return FALSE;
@@ -562,34 +562,34 @@  discard block
 block discarded – undo
562 562
                         /* Entry delisted */
563 563
                         $result->free();
564 564
 			$quantity *= $thisentry['nlist'];
565
-                        return relist ($myconn,$loguser,$value,$type,$table,$unit,$quantity,$reason);
565
+                        return relist($myconn, $loguser, $value, $type, $table, $unit, $quantity, $reason);
566 566
 
567 567
 
568 568
                 /* First time list value */
569 569
                 case 0:
570 570
                         $result->free();
571
-                        return addtolist ($myconn,$loguser,$value,$tables["$typedesc"],$unit,$quantity,$reason,$_);
571
+                        return addtolist($myconn, $loguser, $value, $tables["$typedesc"], $unit, $quantity, $reason, $_);
572 572
         }
573 573
 }
574 574
 
575 575
 
576 576
 /*************** Functions to check if two net overlap each other ********************/
577 577
 
578
-function ipRange ($range) {
578
+function ipRange($range) {
579 579
 /* List IP in range */
580
-	return array_map('long2ip', range( ip2long($range[0]), ip2long($range[1]) ) );
580
+	return array_map('long2ip', range(ip2long($range[0]), ip2long($range[1])));
581 581
 }
582 582
 
583 583
 function isIn($netA, $netB) {
584 584
 /* TRUE if an IP of $netA is contained in netB */
585
-	list($addressA,$maskA) = explode('/', $netA);
586
-	list($addressB,$maskB) = explode('/', $netB);
585
+	list($addressA, $maskA) = explode('/', $netA);
586
+	list($addressB, $maskB) = explode('/', $netB);
587 587
 	require_once 'vendor/autoload.php';
588 588
 	$net = new \dautkom\ipv4\IPv4();
589 589
 	$range = $net->address($addressA)->mask($maskA)->getRange();
590 590
 	$ips = ipRange($range);
591
-	foreach ( $ips as $ip )
592
-		if ( $net->address($addressB)->mask($maskB)->has($ip) )
591
+	foreach ($ips as $ip)
592
+		if ($net->address($addressB)->mask($maskB)->has($ip))
593 593
 			return TRUE;
594 594
 	return FALSE;
595 595
 }
@@ -601,11 +601,11 @@  discard block
 block discarded – undo
601 601
 		syslog(LOG_ERR, $loguser.': '.$tabletype['name'].' is not a network list.');
602 602
 		return FALSE;
603 603
 	}
604
-	$result = searchentry ($myconn,'ALL',$tabletype);
604
+	$result = searchentry($myconn, 'ALL', $tabletype);
605 605
         if ($result->num_rows) {
606 606
 		while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
607 607
 			$thisNet = long2ip($row['network']).'/'.long2ip($row['netmask']);
608
-			if ( isIn($thisNet, $net) ) {
608
+			if (isIn($thisNet, $net)) {
609 609
 				$result->free();
610 610
 				syslog(LOG_INFO, "$loguser: the net <$net> overlaps the existing network <$thisNet>.");
611 611
 				return TRUE;
@@ -622,8 +622,8 @@  discard block
 block discarded – undo
622 622
 /* For miltermap */
623 623
 function checkMilterConf($table) {
624 624
 	if (isset($table['milter'])) {
625
-        	if ($table['milter'] ===  TRUE) {
626
-			switch ( $table['field'] ) {
625
+        	if ($table['milter'] === TRUE) {
626
+			switch ($table['field']) {
627 627
 				case 'network':
628 628
 				case 'ip':
629 629
 					return TRUE;
@@ -657,12 +657,12 @@  discard block
 block discarded – undo
657 657
 }
658 658
 
659 659
 
660
-function readMiltName($myconn,$loguser) {
661
-	$milters=array();
660
+function readMiltName($myconn, $loguser) {
661
+	$milters = array();
662 662
 	$query = 'SELECT `name` FROM `config`';
663 663
 
664 664
         $result = $myconn->query($query);
665
-        if($result === false) {
665
+        if ($result === false) {
666 666
                 syslog(LOG_EMERG, "$loguser: ALERT: Query <$query> failed: ".$myconn->error);
667 667
 		return FALSE;
668 668
 	}
@@ -674,27 +674,27 @@  discard block
 block discarded – undo
674 674
 	return $milters;
675 675
 }
676 676
 
677
-function changeMilter ($myconn,$loguser,$miltVal,$table,$miltID) {
677
+function changeMilter($myconn, $loguser, $miltVal, $table, $miltID) {
678 678
 	$query = array();
679
-	foreach ( $miltVal as $value => $action ) {
680
-		switch ( $action ) {
679
+	foreach ($miltVal as $value => $action) {
680
+		switch ($action) {
681 681
 			case 'keep':
682 682
 				break;
683 683
 			case 'add':
684
-				$query[] = sprintf( "INSERT INTO `milt` (
684
+				$query[] = sprintf("INSERT INTO `milt` (
685 685
                 		        	`id` ,
686 686
                         			`name` 
687 687
                 			)
688 688
                 			VALUES (
689 689
                         			%d ,
690 690
 						'%s'
691
-					)",$miltID,$value);
691
+					)",$miltID, $value);
692 692
 				break;
693 693
 			case 'del':
694 694
 				$query[] = "DELETE FROM  `milt` WHERE (`id` = '$miltID' AND `name` = '$value')";
695 695
 		}
696 696
 	}
697
-	if ( count($query) ) /* This "if" is redundant, because if I call this I already checked there is a change */
697
+	if (count($query)) /* This "if" is redundant, because if I call this I already checked there is a change */
698 698
 		/* I update datemod because the user couldn't change */
699 699
 		$query[] = sprintf('UPDATE `%s` SET
700 700
 						`user`=\'%s\',
@@ -706,18 +706,18 @@  discard block
 block discarded – undo
706 706
 	$myconn->autocommit(FALSE);
707 707
 	$myconn->begin_transaction(MYSQLI_TRANS_START_READ_ONLY);
708 708
 	$ok = TRUE;
709
-	foreach ( $query as $q ) {
709
+	foreach ($query as $q) {
710 710
 		if ($myconn->query($q) !== TRUE) {
711 711
 			$ok = FALSE;
712 712
 			syslog(LOG_ERR, "$loguser: Error: ".$myconn->error);
713 713
 		}
714 714
 	}
715
-	if ( $ok ) {
716
-		if ( $myconn->commit() )
715
+	if ($ok) {
716
+		if ($myconn->commit())
717 717
 			syslog(LOG_INFO, "$loguser: Milter setting changed successfully.");
718 718
 		else {
719 719
 			syslog(LOG_ERR, "$loguser: Milter setting NOT changed for an unpredictable COMMIT error.");
720
-			if ( $myconn->rollback() )
720
+			if ($myconn->rollback())
721 721
 				syslog(LOG_INFO, "$loguser: rollback succeeded.");
722 722
 			else
723 723
 				syslog(LOG_ERR, "$loguser: rollback failed. Your db could be compromized. Check it!");
Please login to merge, or discard this patch.