GitHub Access Token became invalid

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