@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | require_once('config.php'); |
3 | 3 | require_once('function.php'); |
4 | -$typedesc=$_POST['type']; |
|
4 | +$typedesc = $_POST['type']; |
|
5 | 5 | $type = $tables["$typedesc"]['field']; |
6 | 6 | $table = ($tables["$typedesc"]['milter']) ? milterTable($type) : $tables["$typedesc"]['name']; |
7 | 7 | $cl = ($tables["$typedesc"]['milter']) ? 10 : 9; |
@@ -11,10 +11,10 @@ discard block |
||
11 | 11 | openlog($tag, LOG_PID, $fac); |
12 | 12 | $user = username(); |
13 | 13 | |
14 | -if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) |
|
15 | - exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
|
14 | +if (($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE) |
|
15 | + exit ($user.': Connect Error ('.$mysqli->connect_errno.') '.$mysqli->connect_error); |
|
16 | 16 | |
17 | -if (changestatus($mysqli,username(),$_POST['value'],'0',$type,$table)) |
|
17 | +if (changestatus($mysqli, username(), $_POST['value'], '0', $type, $table)) |
|
18 | 18 | print 'OK '.$_POST["type"].' <'.$_POST['value'].'> delisted.'; |
19 | 19 | else |
20 | 20 | print 'ERROR in delist <'.$_POST['value'].'>; check log'; |
@@ -16,11 +16,11 @@ discard block |
||
16 | 16 | |
17 | 17 | /************** Conf *******************/ |
18 | 18 | $base = '/var/www/html/RBL'; |
19 | -require_once($base . '/config.php'); |
|
19 | +require_once($base.'/config.php'); |
|
20 | 20 | |
21 | 21 | /* Syslog basic */ |
22 | -$tag .= 'SplunkLister'; |
|
23 | -$user = 'Splunk'; |
|
22 | +$tag .= 'SplunkLister'; |
|
23 | +$user = 'Splunk'; |
|
24 | 24 | |
25 | 25 | openlog($tag, LOG_PID, $fac); |
26 | 26 | |
@@ -28,43 +28,43 @@ discard block |
||
28 | 28 | if (!isset($_GET['conf'])) { |
29 | 29 | syslog(LOG_ALERT, |
30 | 30 | sprintf('%s: you must insert the config file name as a GET parameter, such as %s?conf=listEmail.conf', |
31 | - $user, $_SERVER['SCRIPT_NAME']) ); |
|
31 | + $user, $_SERVER['SCRIPT_NAME'])); |
|
32 | 32 | exit(254); |
33 | 33 | } |
34 | 34 | $fileconf = $_GET['conf']; |
35 | -if ( !file_exists(dirname(__FILE__) . '/../' . $fileconf) ) { |
|
35 | +if (!file_exists(dirname(__FILE__).'/../'.$fileconf)) { |
|
36 | 36 | syslog(LOG_ALERT, |
37 | 37 | sprintf('%s: the configuration file <%s> doesn\'t exist.', |
38 | - $user, $fileconf )); |
|
38 | + $user, $fileconf)); |
|
39 | 39 | exit(254); |
40 | 40 | } |
41 | 41 | |
42 | 42 | closelog(); |
43 | -$conf = parse_ini_file( dirname(__FILE__) . '/../' . $fileconf ); |
|
43 | +$conf = parse_ini_file(dirname(__FILE__).'/../'.$fileconf); |
|
44 | 44 | |
45 | 45 | /* Splunk inherited parameters */ |
46 | -$threshold = $conf['threshold']; /* Threshold value on trigger condition; the same which engage the alert */ |
|
46 | +$threshold = $conf['threshold']; /* Threshold value on trigger condition; the same which engage the alert */ |
|
47 | 47 | |
48 | 48 | /* Blacklist name */ |
49 | 49 | $typedesc = $conf['typedesc']; |
50 | 50 | |
51 | 51 | /* How long to list's parameters */ |
52 | -$unit = $conf['unit']; /* MySQL language ;) */ |
|
52 | +$unit = $conf['unit']; /* MySQL language ;) */ |
|
53 | 53 | |
54 | 54 | /* Syslog extended info */ |
55 | -$tag .= $conf['tag']; |
|
55 | +$tag .= $conf['tag']; |
|
56 | 56 | |
57 | 57 | /* Splunk password of alert owner*/ |
58 | 58 | $splpwd = $conf['splunkpassword']; |
59 | 59 | /************** End of conf *************************/ |
60 | 60 | |
61 | 61 | openlog($tag, LOG_PID, $fac); |
62 | -require_once($base . '/function.php'); |
|
62 | +require_once($base.'/function.php'); |
|
63 | 63 | |
64 | 64 | |
65 | 65 | /* check you select a blocklist */ |
66 | -if ( !$tables["$typedesc"]['bl'] ) { |
|
67 | - syslog(LOG_EMERG,"$user: <$typedesc> is not a blocklist. Are you stupid? Do you want to whitelist a spammer? I refuse to continue."); |
|
66 | +if (!$tables["$typedesc"]['bl']) { |
|
67 | + syslog(LOG_EMERG, "$user: <$typedesc> is not a blocklist. Are you stupid? Do you want to whitelist a spammer? I refuse to continue."); |
|
68 | 68 | exit (254); |
69 | 69 | } |
70 | 70 | |
@@ -96,14 +96,14 @@ discard block |
||
96 | 96 | $webhook['results_link'], $out, PREG_PATTERN_ORDER) === FALSE) { |
97 | 97 | syslog(LOG_ALERT, |
98 | 98 | sprintf('%s: unexpected error: can\'t parse the results link returned by webhook (<%s>).', |
99 | - $user, $webhook['results_link']) ); |
|
99 | + $user, $webhook['results_link'])); |
|
100 | 100 | return 255; |
101 | 101 | } |
102 | 102 | |
103 | -if ( $webhook['app'] != $out['splunkapp'][0] ) { |
|
103 | +if ($webhook['app'] != $out['splunkapp'][0]) { |
|
104 | 104 | syslog(LOG_ALERT, |
105 | 105 | sprintf('%s: unexpected error: the APP returned by webhook (<%s>) doesn\'t match the app (<%s>) in result link.', |
106 | - $user, $webhook['app'], $out['splunkapp'][0] ) ); |
|
106 | + $user, $webhook['app'], $out['splunkapp'][0])); |
|
107 | 107 | return 255; |
108 | 108 | } |
109 | 109 | |
@@ -135,13 +135,13 @@ discard block |
||
135 | 135 | |
136 | 136 | $tolist = array(); |
137 | 137 | |
138 | -$nr = count ($results); |
|
139 | -for ($i=1; $i<$nr; $i++) { /* We skip first header line (i=0) */ |
|
138 | +$nr = count($results); |
|
139 | +for ($i = 1; $i<$nr; $i++) { /* We skip first header line (i=0) */ |
|
140 | 140 | $data = str_getcsv($results[$i], ','); |
141 | 141 | $thisVal = $data[1]; |
142 | 142 | unset($data[1]); |
143 | 143 | $data = array_values($data); |
144 | - if ( !in_array($thisVal,array_keys($tolist)) ) |
|
144 | + if (!in_array($thisVal, array_keys($tolist))) |
|
145 | 145 | $tolist["$thisVal"] = $data; |
146 | 146 | else if ($data[3]>$tolist[$thisVal][3]) |
147 | 147 | $tolist["$thisVal"] = $data; |
@@ -150,42 +150,42 @@ discard block |
||
150 | 150 | /* Make MYSQL connection */ |
151 | 151 | |
152 | 152 | $mysqli = myConnect($host, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user); |
153 | -if ( $mysqli === FALSE ) |
|
153 | +if ($mysqli === FALSE) |
|
154 | 154 | exit (254); |
155 | 155 | |
156 | -foreach ( array_keys($tolist) as $value) { |
|
156 | +foreach (array_keys($tolist) as $value) { |
|
157 | 157 | $quantity = $conf['quantity']; |
158 | 158 | $reason = 'On ['.$tolist["$value"][0]."] <$value> sent ".$tolist["$value"][1].' messages to '.$tolist["$value"][2].' recipients.'; |
159 | - if ( $tolist["$value"][3] >= $threshold ) { |
|
160 | - if ( searchAndList ($mysqli,$user,$tables,$typedesc,$value,$unit,$quantity,$reason) ) { |
|
161 | - syslog (LOG_INFO, "$user: ".'Listing reason: '.$reason); |
|
159 | + if ($tolist["$value"][3]>=$threshold) { |
|
160 | + if (searchAndList($mysqli, $user, $tables, $typedesc, $value, $unit, $quantity, $reason)) { |
|
161 | + syslog(LOG_INFO, "$user: ".'Listing reason: '.$reason); |
|
162 | 162 | /* Send a email to domain admin if you list an email */ |
163 | - if ( ( $tables["$typedesc"]['field'] == 'email' ) OR ( $tables["$typedesc"]['field'] == 'username' ) ) { |
|
163 | + if (($tables["$typedesc"]['field'] == 'email') OR ($tables["$typedesc"]['field'] == 'username')) { |
|
164 | 164 | /* Sometime uid are in the form of <user>@<domain> ... */ |
165 | - if ( strpos($value, '@') !== FALSE ) { |
|
165 | + if (strpos($value, '@') !== FALSE) { |
|
166 | 166 | $domain = substr(strrchr($value, '@'), 1); |
167 | - if ( strpos($domain, '@') === FALSE ) { |
|
168 | - $recip = emailToNotify($domainNotify_file,$domain); |
|
167 | + if (strpos($domain, '@') === FALSE) { |
|
168 | + $recip = emailToNotify($domainNotify_file, $domain); |
|
169 | 169 | $subject = sprintf('%s <%s> is now blocked because exceedes limits on outgoing emails', |
170 | 170 | $tables["$typedesc"]['field'], $value); |
171 | 171 | if (!empty($recip)) |
172 | - if ( sendEmailWarn($tplfile,'[email protected]',$recip, |
|
173 | - $subject,$value,"$quantity $unit",$reason) ) |
|
172 | + if (sendEmailWarn($tplfile, '[email protected]', $recip, |
|
173 | + $subject, $value, "$quantity $unit", $reason)) |
|
174 | 174 | syslog(LOG_INFO, "$user: \"$recip\" was notified about the \"$value\" abuse."); |
175 | 175 | } |
176 | - else syslog(LOG_ERR,"$user: <$domain> contains the '@' char. Notification cannot be sent."); |
|
176 | + else syslog(LOG_ERR, "$user: <$domain> contains the '@' char. Notification cannot be sent."); |
|
177 | 177 | } |
178 | 178 | } |
179 | 179 | } |
180 | 180 | } |
181 | 181 | else { |
182 | 182 | $reason .= " But it has NOT been listed because it doesn't apply to the trigger condition."; |
183 | - syslog (LOG_INFO, "$user: ".$reason); |
|
183 | + syslog(LOG_INFO, "$user: ".$reason); |
|
184 | 184 | } |
185 | 185 | } |
186 | 186 | |
187 | 187 | /* Close connection */ |
188 | -syslog (LOG_INFO, "$user: ".'Successfully end of session.'); |
|
188 | +syslog(LOG_INFO, "$user: ".'Successfully end of session.'); |
|
189 | 189 | $mysqli->close(); |
190 | 190 | closelog(); |
191 | 191 |
@@ -14,11 +14,11 @@ discard block |
||
14 | 14 | require_once('function.php'); |
15 | 15 | |
16 | 16 | checkSSL(); |
17 | -if ( $require_auth ) |
|
18 | - if ( username() == 'unknown' ) exit ("<p>You MUST configure your server to use authentication.</p>"); |
|
17 | +if ($require_auth) |
|
18 | + if (username() == 'unknown') exit ("<p>You MUST configure your server to use authentication.</p>"); |
|
19 | 19 | |
20 | 20 | |
21 | -if ( $imapListActive ) |
|
21 | +if ($imapListActive) |
|
22 | 22 | print ' <p style="text-align: right"><a href="/spamreport" target="_new">SPAM Learn Observer</a></p>'; |
23 | 23 | |
24 | 24 | print <<<END |
@@ -27,10 +27,10 @@ discard block |
||
27 | 27 | END; |
28 | 28 | |
29 | 29 | |
30 | -$option=NULL; |
|
30 | +$option = NULL; |
|
31 | 31 | $desc = array_keys($tables); |
32 | 32 | foreach ($desc as $description) { |
33 | - $disabled = $tables["$description"]['active']==TRUE ? '' : ' disabled'; |
|
33 | + $disabled = $tables["$description"]['active'] == TRUE ? '' : ' disabled'; |
|
34 | 34 | $option .= '<option value="'.$description."\"$disabled>$description</option>"; |
35 | 35 | } |
36 | 36 |
@@ -5,46 +5,46 @@ discard block |
||
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 | function checkSSL() { |
13 | - if ( empty( $_SERVER['HTTPS'] ) ) |
|
14 | - printf ('<div id="content">Ehi sysadmin! Your site is not secure. Please enable SSL on your server and configure a redirect, such as' . |
|
15 | - '<pre>' . |
|
16 | - htmlspecialchars('<VirtualHost *:80>' . "\n" . |
|
17 | - ' ServerName %s' . "\n" . |
|
18 | - ' Redirect permanent / https://%s/' . "\n" . |
|
19 | - '</VirtualHost>') . |
|
13 | + if (empty($_SERVER['HTTPS'])) |
|
14 | + printf('<div id="content">Ehi sysadmin! Your site is not secure. Please enable SSL on your server and configure a redirect, such as'. |
|
15 | + '<pre>'. |
|
16 | + htmlspecialchars('<VirtualHost *:80>'."\n". |
|
17 | + ' ServerName %s'."\n". |
|
18 | + ' Redirect permanent / https://%s/'."\n". |
|
19 | + '</VirtualHost>'). |
|
20 | 20 | '</pre></div>', gethostname(), gethostname()); |
21 | 21 | } |
22 | 22 | |
23 | 23 | function myConnect($host, $user, $pass, $db, $port, $tablelist, $typedesc, $loguser) { |
24 | - $db = ( $tablelist["$typedesc"]['milter'] ) ? $tablelist["$typedesc"]['name'] : $db; |
|
24 | + $db = ($tablelist["$typedesc"]['milter']) ? $tablelist["$typedesc"]['name'] : $db; |
|
25 | 25 | $mysqli = new mysqli($host, $user, $pass, $db, $port); |
26 | 26 | if ($mysqli->connect_error) { |
27 | - syslog (LOG_EMERG, $loguser.': Connect Error to DB <'.$db.'> (' . $mysqli->connect_errno . ') ' |
|
27 | + syslog(LOG_EMERG, $loguser.': Connect Error to DB <'.$db.'> ('.$mysqli->connect_errno.') ' |
|
28 | 28 | . $mysqli->connect_error); |
29 | 29 | return FALSE; |
30 | 30 | } |
31 | - syslog(LOG_INFO, $loguser.': Successfully MySQL connected at DB <'.$db.'> to ' . $mysqli->host_info) ; |
|
31 | + syslog(LOG_INFO, $loguser.': Successfully MySQL connected at DB <'.$db.'> to '.$mysqli->host_info); |
|
32 | 32 | return $mysqli; |
33 | 33 | } |
34 | 34 | |
35 | -function addtolist ($myconn,$user,$value,$tabledesc,$expUnit,$expQ,$myreason,&$err) { |
|
35 | +function addtolist($myconn, $user, $value, $tabledesc, $expUnit, $expQ, $myreason, &$err) { |
|
36 | 36 | // See MySQL manual for $expQ and $expUnit at |
37 | 37 | // https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_timestampadd |
38 | 38 | |
39 | - $result=FALSE; |
|
40 | - $sub=array(); |
|
39 | + $result = FALSE; |
|
40 | + $sub = array(); |
|
41 | 41 | $type = $tabledesc['field']; |
42 | 42 | $milt = $tabledesc['milter']; |
43 | 43 | $table = ($milt) ? milterTable($type) : $tabledesc['name']; |
44 | 44 | |
45 | 45 | switch ($type) { |
46 | 46 | case 'ip': |
47 | - $query= sprintf("INSERT INTO `$table` ( |
|
47 | + $query = sprintf("INSERT INTO `$table` ( |
|
48 | 48 | `$type` , |
49 | 49 | `date` , |
50 | 50 | `exp` , |
@@ -55,18 +55,18 @@ discard block |
||
55 | 55 | VALUES ( |
56 | 56 | INET_ATON( '%s' ) , |
57 | 57 | CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s' |
58 | - )" ,$value,$expUnit,$expQ,$user,$myreason); |
|
58 | + )", $value, $expUnit, $expQ, $user, $myreason); |
|
59 | 59 | break; |
60 | 60 | |
61 | 61 | case 'network': |
62 | 62 | if (!$milt) { |
63 | - if ( netOverlap($myconn, $tabledesc, $value, $overlappedNet, $user) ) { |
|
63 | + if (netOverlap($myconn, $tabledesc, $value, $overlappedNet, $user)) { |
|
64 | 64 | $err = "<$value> overlaps the existing network <$overlappedNet>"; |
65 | 65 | return FALSE; |
66 | 66 | } |
67 | 67 | } |
68 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
69 | - $query= sprintf("INSERT INTO `$table` ( |
|
68 | + list($sub['net'], $sub['mask']) = explode('/', $value); |
|
69 | + $query = sprintf("INSERT INTO `$table` ( |
|
70 | 70 | `$type` , |
71 | 71 | `netmask`, |
72 | 72 | `date` , |
@@ -78,11 +78,11 @@ discard block |
||
78 | 78 | VALUES ( |
79 | 79 | INET_ATON( '%s' ) , INET_ATON( '%s' ) , |
80 | 80 | CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s' |
81 | - )" ,$sub['net'],$sub['mask'],$expUnit,$expQ,$user,$myreason); |
|
81 | + )", $sub['net'], $sub['mask'], $expUnit, $expQ, $user, $myreason); |
|
82 | 82 | break; |
83 | 83 | |
84 | 84 | default: |
85 | - $query= sprintf("INSERT INTO `$table` ( |
|
85 | + $query = sprintf("INSERT INTO `$table` ( |
|
86 | 86 | `$type` , |
87 | 87 | `date` , |
88 | 88 | `exp` , |
@@ -93,23 +93,23 @@ discard block |
||
93 | 93 | VALUES ( |
94 | 94 | '%s' , |
95 | 95 | CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s' |
96 | - )" ,$value,$expUnit,$expQ,$user,$myreason); |
|
96 | + )", $value, $expUnit, $expQ, $user, $myreason); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | if ($myconn->query($query) === TRUE) { |
100 | 100 | syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit."); |
101 | - $result=TRUE; |
|
101 | + $result = TRUE; |
|
102 | 102 | } |
103 | 103 | else syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
104 | 104 | return $result; |
105 | 105 | } |
106 | 106 | |
107 | -function relist ($myconn,$user,$value,$type,$table,$expUnit,$expQ,$myreason, $exptime = 0) { |
|
107 | +function relist($myconn, $user, $value, $type, $table, $expUnit, $expQ, $myreason, $exptime = 0) { |
|
108 | 108 | |
109 | - $result=FALSE; |
|
110 | - if ( $exptime ) { /* Entry already listed */ |
|
109 | + $result = FALSE; |
|
110 | + if ($exptime) { /* Entry already listed */ |
|
111 | 111 | $nlist = '`nlist`'; |
112 | - $exptime = sprintf('\'%s\'', $exptime); /* Eh MySQL... an hour lost to notice this */ |
|
112 | + $exptime = sprintf('\'%s\'', $exptime); /* Eh MySQL... an hour lost to notice this */ |
|
113 | 113 | } |
114 | 114 | else { |
115 | 115 | $exptime = 'CURRENT_TIMESTAMP'; |
@@ -118,43 +118,43 @@ discard block |
||
118 | 118 | |
119 | 119 | switch ($type) { |
120 | 120 | case 'ip': |
121 | - $query= sprintf("UPDATE `$table` SET |
|
121 | + $query = sprintf("UPDATE `$table` SET |
|
122 | 122 | `active` = '1', |
123 | 123 | `user` = '%s', |
124 | 124 | `exp` = TIMESTAMPADD(%s,%d,%s), |
125 | 125 | `nlist` = %s, |
126 | 126 | `reason` = '%s' |
127 | - WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user,$expUnit,$expQ,$exptime,$nlist,$myreason,$value); |
|
127 | + WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1", $user, $expUnit, $expQ, $exptime, $nlist, $myreason, $value); |
|
128 | 128 | break; |
129 | 129 | case 'network': |
130 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
131 | - $query= sprintf("UPDATE `$table` SET |
|
130 | + list($sub['net'], $sub['mask']) = explode('/', $value); |
|
131 | + $query = sprintf("UPDATE `$table` SET |
|
132 | 132 | `active` = '1', |
133 | 133 | `user` = '%s', |
134 | 134 | `exp` = TIMESTAMPADD(%s,%d,%s), |
135 | 135 | `nlist` = %s, |
136 | 136 | `reason` = '%s' |
137 | - WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1" ,$user,$expUnit,$expQ,$exptime,$nlist,$myreason,$sub['net'],$sub['mask']); |
|
137 | + WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1", $user, $expUnit, $expQ, $exptime, $nlist, $myreason, $sub['net'], $sub['mask']); |
|
138 | 138 | break; |
139 | 139 | default: |
140 | - $query= sprintf("UPDATE `$table` SET |
|
140 | + $query = sprintf("UPDATE `$table` SET |
|
141 | 141 | `active` = '1', |
142 | 142 | `user` = '%s', |
143 | 143 | `exp` = TIMESTAMPADD(%s,%d,%s), |
144 | 144 | `nlist` = %s, |
145 | 145 | `reason` = '%s' |
146 | - WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user,$expUnit,$expQ,$exptime,$nlist,$myreason,$value); |
|
146 | + WHERE `$table`.`$type` = '%s' LIMIT 1", $user, $expUnit, $expQ, $exptime, $nlist, $myreason, $value); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | if ($myconn->query($query) === TRUE) { |
150 | 150 | syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit from $exptime."); |
151 | - $result=TRUE; |
|
151 | + $result = TRUE; |
|
152 | 152 | } |
153 | - else syslog (LOG_ERR, "$user: Error: ". $myconn->error); |
|
153 | + else syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
|
154 | 154 | return $result; |
155 | 155 | } |
156 | 156 | |
157 | -function remove ($myconn,$user,$value,$type,$table) { |
|
157 | +function remove($myconn, $user, $value, $type, $table) { |
|
158 | 158 | |
159 | 159 | switch ($type) { |
160 | 160 | case 'ip': |
@@ -162,10 +162,10 @@ discard block |
||
162 | 162 | `$table`.`$type` = INET_ATON('%s') LIMIT 1", $value); |
163 | 163 | break; |
164 | 164 | case 'network': |
165 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
165 | + list($sub['net'], $sub['mask']) = explode('/', $value); |
|
166 | 166 | $query = sprintf("DELETE FROM `$table` WHERE |
167 | 167 | `$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s') LIMIT 1", |
168 | - $sub['net'],$sub['mask']); |
|
168 | + $sub['net'], $sub['mask']); |
|
169 | 169 | break; |
170 | 170 | default: |
171 | 171 | $query = sprintf("DELETE FROM `$table` WHERE |
@@ -173,39 +173,39 @@ discard block |
||
173 | 173 | } |
174 | 174 | |
175 | 175 | |
176 | - if ($return=$myconn->query($query) === TRUE) |
|
176 | + if ($return = $myconn->query($query) === TRUE) |
|
177 | 177 | syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>."); |
178 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
178 | + else syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
|
179 | 179 | |
180 | 180 | return $return; |
181 | 181 | } |
182 | 182 | |
183 | 183 | |
184 | -function changestatus ($myconn,$user,$value,$status,$type,$table) { |
|
184 | +function changestatus($myconn, $user, $value, $status, $type, $table) { |
|
185 | 185 | |
186 | 186 | switch ($type) { |
187 | 187 | case 'ip': |
188 | - $query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user, $value); |
|
188 | + $query = sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1", $user, $value); |
|
189 | 189 | break; |
190 | 190 | case 'network': |
191 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
192 | - $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']); |
|
191 | + list($sub['net'], $sub['mask']) = explode('/', $value); |
|
192 | + $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']); |
|
193 | 193 | break; |
194 | 194 | default: |
195 | - $query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user, $value); |
|
195 | + $query = sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = '%s' LIMIT 1", $user, $value); |
|
196 | 196 | } |
197 | 197 | |
198 | - if ($return=$myconn->query($query) === TRUE) { |
|
198 | + if ($return = $myconn->query($query) === TRUE) { |
|
199 | 199 | syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>"); |
200 | 200 | } |
201 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
201 | + else syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
|
202 | 202 | return $return; |
203 | 203 | } |
204 | 204 | |
205 | 205 | |
206 | -function expire ($myconn,$user,$tables,$expireTime) { |
|
207 | - $return=TRUE; |
|
208 | - $log=array(); |
|
206 | +function expire($myconn, $user, $tables, $expireTime) { |
|
207 | + $return = TRUE; |
|
208 | + $log = array(); |
|
209 | 209 | $desc = array_keys($tables); |
210 | 210 | foreach ($desc as $tdesc) { |
211 | 211 | /* QUERY */ |
@@ -224,11 +224,11 @@ discard block |
||
224 | 224 | } while ($myconn->next_result()); |
225 | 225 | } |
226 | 226 | else { |
227 | - syslog(LOG_ERR, "Expire job - Error: ". $myconn->error); |
|
227 | + syslog(LOG_ERR, "Expire job - Error: ".$myconn->error); |
|
228 | 228 | $return = FALSE; |
229 | 229 | } |
230 | 230 | } |
231 | - if ( !($return) ) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); |
|
231 | + if (!($return)) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); |
|
232 | 232 | else syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.'); |
233 | 233 | return $return; |
234 | 234 | } |
@@ -236,18 +236,18 @@ discard block |
||
236 | 236 | |
237 | 237 | function isListed($row) { |
238 | 238 | |
239 | - $exp=new DateTime($row['exp']); |
|
240 | - $now=new DateTime('NOW'); |
|
241 | - if (($exp > $now) and ($row['active'])) return true; |
|
239 | + $exp = new DateTime($row['exp']); |
|
240 | + $now = new DateTime('NOW'); |
|
241 | + if (($exp>$now) and ($row['active'])) return true; |
|
242 | 242 | else return false; |
243 | 243 | |
244 | 244 | } |
245 | 245 | |
246 | 246 | |
247 | -function askMilter($myconn,$id,$obj,$typedesc,$miltId,$value,$user,$adm) { |
|
248 | - $milts = readMiltName($myconn,$user); |
|
247 | +function askMilter($myconn, $id, $obj, $typedesc, $miltId, $value, $user, $adm) { |
|
248 | + $milts = readMiltName($myconn, $user); |
|
249 | 249 | $size = count($milts); |
250 | - if (in_array($user,array_keys($adm))) { |
|
250 | + if (in_array($user, array_keys($adm))) { |
|
251 | 251 | $button = <<<END |
252 | 252 | <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;" /> |
253 | 253 | <input name="object" type="hidden" value="$obj" /><input name="oldvalues" type="hidden" value="$value" /> |
@@ -257,12 +257,12 @@ discard block |
||
257 | 257 | <div class="noscroll"> |
258 | 258 | <select class="input_text" name="newvalues[]" multiple size="$size"> |
259 | 259 | END; |
260 | - $activeMilts = explode(',',$value); |
|
261 | - foreach ( $milts as $milter ) { |
|
262 | - if ( in_array($milter, $activeMilts) ) |
|
263 | - $selected= 'selected'; |
|
260 | + $activeMilts = explode(',', $value); |
|
261 | + foreach ($milts as $milter) { |
|
262 | + if (in_array($milter, $activeMilts)) |
|
263 | + $selected = 'selected'; |
|
264 | 264 | else |
265 | - $selected= NULL; |
|
265 | + $selected = NULL; |
|
266 | 266 | $button .= sprintf('<option value="%s" %s>%s</option>', $milter, $selected, $milter); |
267 | 267 | } |
268 | 268 | $button .= '</select></div><input class="button" name="Change" type="submit" value="Change" /></form>'; |
@@ -274,14 +274,14 @@ discard block |
||
274 | 274 | } |
275 | 275 | |
276 | 276 | |
277 | -function ask($myconn,$id,$what,$alltables,$typedesc,$value,$lock,$user,$adm) { |
|
277 | +function ask($myconn, $id, $what, $alltables, $typedesc, $value, $lock, $user, $adm) { |
|
278 | 278 | |
279 | - $whynot=NULL; |
|
279 | + $whynot = NULL; |
|
280 | 280 | switch ($what) { |
281 | 281 | case 'Ok': |
282 | 282 | if ($lock) return NULL; |
283 | - if (in_array($user,array_keys($adm))) |
|
284 | - if ( consistentListing($myconn,$alltables,$typedesc,$value,$whynot) ) return require('relistButton.php'); |
|
283 | + if (in_array($user, array_keys($adm))) |
|
284 | + if (consistentListing($myconn, $alltables, $typedesc, $value, $whynot)) return require('relistButton.php'); |
|
285 | 285 | return htmlspecialchars($whynot); |
286 | 286 | case 'Listed': |
287 | 287 | case 'WhiteListed': |
@@ -290,18 +290,18 @@ discard block |
||
290 | 290 | } |
291 | 291 | |
292 | 292 | |
293 | -function consistentListing($myconn,$alltables,$typed,$value,&$warn) { |
|
293 | +function consistentListing($myconn, $alltables, $typed, $value, &$warn) { |
|
294 | 294 | /* Check if there are no pending mislisting */ |
295 | 295 | $warn = NULL; |
296 | - if (! isset($alltables["$typed"]['depend']) ) return TRUE; |
|
296 | + if (!isset($alltables["$typed"]['depend'])) return TRUE; |
|
297 | 297 | foreach ($alltables["$typed"]['depend'] as $listdep) { |
298 | - if ($alltables["$typed"]['field'] != $alltables["$listdep"]['field'] ) { |
|
298 | + if ($alltables["$typed"]['field'] != $alltables["$listdep"]['field']) { |
|
299 | 299 | $warn = "Config ERROR: <$typed> and <$listdep> are of different types! I can't check consistency!"; |
300 | 300 | return FALSE; |
301 | 301 | } |
302 | - $entry = searchentry($myconn,$value,$alltables["$listdep"]); |
|
303 | - if ( $entry->num_rows ) { |
|
304 | - if ( $entry->num_rows == 1 ) { |
|
302 | + $entry = searchentry($myconn, $value, $alltables["$listdep"]); |
|
303 | + if ($entry->num_rows) { |
|
304 | + if ($entry->num_rows == 1) { |
|
305 | 305 | $riga = $entry->fetch_array(MYSQLI_ASSOC); |
306 | 306 | if (isListed($riga)) { |
307 | 307 | $warn = "<$value> is already present in <$listdep> list!"; |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | return FALSE; |
310 | 310 | } |
311 | 311 | } |
312 | - if ( $entry->num_rows > 1 ) {$warn = "<$value> seems to be present more than once in <$listdep>. Contact a sysadmin NOW!";} |
|
312 | + if ($entry->num_rows>1) {$warn = "<$value> seems to be present more than once in <$listdep>. Contact a sysadmin NOW!"; } |
|
313 | 313 | } |
314 | 314 | $entry->free(); |
315 | 315 | } |
@@ -317,20 +317,20 @@ discard block |
||
317 | 317 | return TRUE; |
318 | 318 | } |
319 | 319 | |
320 | -function searchentry ($myconn,$value,$tablelist) { |
|
320 | +function searchentry($myconn, $value, $tablelist) { |
|
321 | 321 | /* Make a MYSQL query and return result */ |
322 | 322 | |
323 | 323 | $type = $tablelist['field']; |
324 | 324 | |
325 | - if ( $tablelist['milter'] ) { |
|
325 | + if ($tablelist['milter']) { |
|
326 | 326 | $table = milterTable($type); |
327 | 327 | if ($value == 'ALL') |
328 | 328 | $query = sprintf('SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id) GROUP by idmilt', |
329 | - $table,$table); |
|
329 | + $table, $table); |
|
330 | 330 | else { |
331 | 331 | switch ($type) { |
332 | 332 | case 'network': |
333 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
333 | + list($sub['net'], $sub['mask']) = explode('/', $value); |
|
334 | 334 | $query = sprintf('SELECT * FROM ( |
335 | 335 | SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id) |
336 | 336 | WHERE ( |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | ) AS val WHERE val.ip IS NOT null', $table, $table, $value); |
349 | 349 | break; |
350 | 350 | default: |
351 | - syslog(LOG_EMERG, 'ALERT: The type <'.$type.'> is not allowed for milter lists.' ); |
|
351 | + syslog(LOG_EMERG, 'ALERT: The type <'.$type.'> is not allowed for milter lists.'); |
|
352 | 352 | return FALSE; |
353 | 353 | } |
354 | 354 | } |
@@ -360,11 +360,11 @@ discard block |
||
360 | 360 | else { |
361 | 361 | switch ($type) { |
362 | 362 | case 'ip': |
363 | - $query= "select * from $table where $type = INET_ATON('$value')"; |
|
363 | + $query = "select * from $table where $type = INET_ATON('$value')"; |
|
364 | 364 | break; |
365 | 365 | case 'network': |
366 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
367 | - $query= sprintf('select * from `%s` |
|
366 | + list($sub['net'], $sub['mask']) = explode('/', $value); |
|
367 | + $query = sprintf('select * from `%s` |
|
368 | 368 | WHERE ( |
369 | 369 | inet_aton(\'%s\') >= network AND |
370 | 370 | ( inet_aton(\'%s\') | ( inet_aton(\'%s\') ^ (power(2,32)-1) ) ) |
@@ -373,18 +373,18 @@ discard block |
||
373 | 373 | ; |
374 | 374 | break; |
375 | 375 | default: |
376 | - $query= "select * from $table where $type = '$value'"; |
|
376 | + $query = "select * from $table where $type = '$value'"; |
|
377 | 377 | } |
378 | 378 | } |
379 | 379 | } |
380 | 380 | |
381 | 381 | $result = $myconn->query($query); |
382 | - if($result === false) |
|
382 | + if ($result === false) |
|
383 | 383 | syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error); |
384 | 384 | return $result; |
385 | 385 | } |
386 | 386 | |
387 | -function countListed ($myconn,$table) { |
|
387 | +function countListed($myconn, $table) { |
|
388 | 388 | /* Return number of current listed items into a rbl table */ |
389 | 389 | $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"; |
390 | 390 | $row = $myconn->query($query); |
@@ -395,48 +395,48 @@ discard block |
||
395 | 395 | } |
396 | 396 | |
397 | 397 | |
398 | -function isFull($myconn,$typedesc,$alltables) { |
|
398 | +function isFull($myconn, $typedesc, $alltables) { |
|
399 | 399 | if (isset($alltables["$typedesc"]['limit'])) { |
400 | - if ( $alltables["$typedesc"]['milter'] ) |
|
400 | + if ($alltables["$typedesc"]['milter']) |
|
401 | 401 | $tab = 'net'; |
402 | 402 | else |
403 | 403 | $tab = $alltables["$typedesc"]['name']; |
404 | - if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) |
|
404 | + if (countListed($myconn, $tab)>=$alltables["$typedesc"]['limit']) |
|
405 | 405 | return TRUE; |
406 | 406 | } |
407 | 407 | return FALSE; |
408 | 408 | } |
409 | 409 | |
410 | -function rlookup ($myconn,$user,$adm,$value,$typedesc,$tables) { |
|
410 | +function rlookup($myconn, $user, $adm, $value, $typedesc, $tables) { |
|
411 | 411 | |
412 | 412 | $type = $tables["$typedesc"]['field']; |
413 | - $whynot=NULL; |
|
413 | + $whynot = NULL; |
|
414 | 414 | |
415 | 415 | $tabhtm = <<<END |
416 | 416 | <table><thead><tr><th>$type</th><th title="The date this object has been listed for the first time">DateAdd</th><th>DateMod</th><th>Exp</th><th>Status</th><th title="Number of times this object has been listed">#List</th> |
417 | 417 | END; |
418 | - if ( $tables["$typedesc"]['milter'] ) |
|
418 | + if ($tables["$typedesc"]['milter']) |
|
419 | 419 | $tabhtm .= '<th title="Milter active for this object">Milters</th>'; |
420 | 420 | $tabhtm .= '<th>Authored by</th><th width="250">Reason</th><th>Action</th></tr></thead><tfoot><tr></tr></tfoot><tbody>'."\n"; |
421 | 421 | |
422 | - $result = searchentry ($myconn,$value,$tables["$typedesc"]); |
|
422 | + $result = searchentry($myconn, $value, $tables["$typedesc"]); |
|
423 | 423 | if ($result) { |
424 | 424 | printf("<pre>Your request for $type <$value> returned %d items.\n</pre>", $result->num_rows); |
425 | 425 | |
426 | 426 | /* Check for limit in number of listed items */ |
427 | - $full = isFull($myconn,$typedesc,$tables); |
|
427 | + $full = isFull($myconn, $typedesc, $tables); |
|
428 | 428 | if ($full) print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>'; |
429 | 429 | |
430 | 430 | if ($result->num_rows) { |
431 | 431 | print $tabhtm; |
432 | - $i=0; |
|
432 | + $i = 0; |
|
433 | 433 | while ($riga = $result->fetch_array(MYSQLI_ASSOC)) { |
434 | 434 | if (isListed($riga)) { |
435 | - if ($tables["$typedesc"]['bl']) $listed='Listed'; |
|
436 | - else $listed='WhiteListed'; |
|
435 | + if ($tables["$typedesc"]['bl']) $listed = 'Listed'; |
|
436 | + else $listed = 'WhiteListed'; |
|
437 | 437 | } |
438 | 438 | else |
439 | - $listed='Ok'; |
|
439 | + $listed = 'Ok'; |
|
440 | 440 | |
441 | 441 | switch ($type) { |
442 | 442 | case 'ip': |
@@ -449,20 +449,20 @@ discard block |
||
449 | 449 | $element = $riga["$type"]; |
450 | 450 | } |
451 | 451 | |
452 | - if ( $tables["$typedesc"]['milter'] AND checkMilterConf($tables["$typedesc"]) ) |
|
453 | - printf ("<tr id=id$i><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td nowrap id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td>%s</td></tr>\n", |
|
454 | - $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)); |
|
452 | + if ($tables["$typedesc"]['milter'] AND checkMilterConf($tables["$typedesc"])) |
|
453 | + printf("<tr id=id$i><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td nowrap id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td>%s</td></tr>\n", |
|
454 | + $element, $riga['date'], $riga['datemod'], $riga['exp'], $riga['active'], $riga['nlist'], askMilter($myconn, $i, $element, $typedesc, $riga['idmilt'], $riga['miltnames'], $user, $adm), $riga['user'], htmlspecialchars($riga['reason']), ask($myconn, $i, $listed, $tables, $typedesc, $element, $full, $user, $adm)); |
|
455 | 455 | else |
456 | - printf ("<tr id=id$i><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td>%s</td></tr>\n", |
|
457 | - $element, $riga['date'], $riga['datemod'], $riga['exp'], $riga['active'], $riga['nlist'], $riga['user'],htmlspecialchars($riga['reason']),ask($myconn,$i,$listed,$tables,$typedesc,$element,$full,$user,$adm)); |
|
456 | + printf("<tr id=id$i><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td>%s</td></tr>\n", |
|
457 | + $element, $riga['date'], $riga['datemod'], $riga['exp'], $riga['active'], $riga['nlist'], $riga['user'], htmlspecialchars($riga['reason']), ask($myconn, $i, $listed, $tables, $typedesc, $element, $full, $user, $adm)); |
|
458 | 458 | $i++; |
459 | 459 | } |
460 | 460 | print '</tbody></table>'; |
461 | 461 | } |
462 | 462 | else { |
463 | 463 | print "<pre>$type <$value> is not listed!\n</pre>"; |
464 | - if ( in_array($user,array_keys($adm)) AND ($value != 'ALL') ) |
|
465 | - if ( (!$full) AND (consistentListing($myconn,$tables,$typedesc,$value,$whynot)) ) require_once('listForm.php'); |
|
464 | + if (in_array($user, array_keys($adm)) AND ($value != 'ALL')) |
|
465 | + if ((!$full) AND (consistentListing($myconn, $tables, $typedesc, $value, $whynot))) require_once('listForm.php'); |
|
466 | 466 | else print '<p>'.htmlspecialchars($whynot).'</p>'; |
467 | 467 | |
468 | 468 | } |
@@ -474,12 +474,12 @@ discard block |
||
474 | 474 | |
475 | 475 | |
476 | 476 | |
477 | -function sendEmailWarn($tplf,$from,$to,$sbj,$emailListed,$intervalToExpire,$detail) { |
|
477 | +function sendEmailWarn($tplf, $from, $to, $sbj, $emailListed, $intervalToExpire, $detail) { |
|
478 | 478 | $now = time(); |
479 | - setlocale (LC_TIME, 'it_IT'); |
|
480 | - $date = date("r",$now); |
|
481 | - $messageID = md5(uniqid($now,1)) . '@' . gethostname(); |
|
482 | - $mua = 'PHP/' . phpversion(); |
|
479 | + setlocale(LC_TIME, 'it_IT'); |
|
480 | + $date = date("r", $now); |
|
481 | + $messageID = md5(uniqid($now, 1)).'@'.gethostname(); |
|
482 | + $mua = 'PHP/'.phpversion(); |
|
483 | 483 | |
484 | 484 | /* Parsing headers */ |
485 | 485 | if (!file_exists($tplf['header'])) { |
@@ -488,10 +488,10 @@ discard block |
||
488 | 488 | } |
489 | 489 | |
490 | 490 | $head_tmpl = file_get_contents($tplf['header']); |
491 | - $arr_tpl_vars = array('{from}','{to}','{date}','{messageID}','{mua}'); |
|
492 | - $arr_tpl_data = array($from,$to,$date,$messageID,$mua); |
|
491 | + $arr_tpl_vars = array('{from}', '{to}', '{date}', '{messageID}', '{mua}'); |
|
492 | + $arr_tpl_data = array($from, $to, $date, $messageID, $mua); |
|
493 | 493 | $headers = str_replace($arr_tpl_vars, $arr_tpl_data, $head_tmpl); |
494 | - $headers = preg_replace( '/\r|\n/', "\r\n", $headers ); |
|
494 | + $headers = preg_replace('/\r|\n/', "\r\n", $headers); |
|
495 | 495 | |
496 | 496 | /* Parsing body */ |
497 | 497 | |
@@ -501,62 +501,62 @@ discard block |
||
501 | 501 | } |
502 | 502 | |
503 | 503 | $body_tmpl = file_get_contents($tplf['body']); |
504 | - $arr_tpl_vars = array('{emailListed}','{expInterval}','{reason}'); |
|
505 | - $arr_tpl_data = array($emailListed,$intervalToExpire,$detail); |
|
504 | + $arr_tpl_vars = array('{emailListed}', '{expInterval}', '{reason}'); |
|
505 | + $arr_tpl_data = array($emailListed, $intervalToExpire, $detail); |
|
506 | 506 | $body = str_replace($arr_tpl_vars, $arr_tpl_data, $body_tmpl); |
507 | - $body = preg_replace( "/\r|\n/", "\r\n", $body ); |
|
508 | - $body = wordwrap ( $body, 75 , "\r\n" ); |
|
507 | + $body = preg_replace("/\r|\n/", "\r\n", $body); |
|
508 | + $body = wordwrap($body, 75, "\r\n"); |
|
509 | 509 | |
510 | 510 | /* Send the mail! */ |
511 | - if ( strlen(ini_get("safe_mode"))< 1) { |
|
511 | + if (strlen(ini_get("safe_mode"))<1) { |
|
512 | 512 | $old_mailfrom = ini_get("sendmail_from"); |
513 | 513 | ini_set("sendmail_from", $from); |
514 | 514 | $params = sprintf("-oi -f %s", '<>'); |
515 | - if (!(mail($to,$sbj, $body,$headers,$params))) $flag=FALSE; |
|
516 | - else $flag=TRUE; |
|
515 | + if (!(mail($to, $sbj, $body, $headers, $params))) $flag = FALSE; |
|
516 | + else $flag = TRUE; |
|
517 | 517 | if (isset($old_mailfrom)) |
518 | 518 | ini_set("sendmail_from", $old_mailfrom); |
519 | 519 | } |
520 | 520 | else { |
521 | - if (!(mail($to,$sbj, $body,$headers))) $flag=FALSE; |
|
522 | - else $flag=TRUE; |
|
521 | + if (!(mail($to, $sbj, $body, $headers))) $flag = FALSE; |
|
522 | + else $flag = TRUE; |
|
523 | 523 | } |
524 | 524 | return $flag; |
525 | 525 | } |
526 | 526 | |
527 | -function emailToNotify($notify_file,$dom) { |
|
527 | +function emailToNotify($notify_file, $dom) { |
|
528 | 528 | $ini_array = parse_ini_file($notify_file); |
529 | - if (in_array($dom,array_keys($ini_array))) |
|
529 | + if (in_array($dom, array_keys($ini_array))) |
|
530 | 530 | return $ini_array["$dom"]; |
531 | 531 | else return FALSE; |
532 | 532 | } |
533 | 533 | |
534 | 534 | |
535 | -function searchAndList ($myconn,$loguser,$tables,$typedesc,$value,$unit,&$quantity,&$reason) { |
|
535 | +function searchAndList($myconn, $loguser, $tables, $typedesc, $value, $unit, &$quantity, &$reason) { |
|
536 | 536 | |
537 | 537 | /* Search and list value */ |
538 | 538 | $type = $tables["$typedesc"]['field']; |
539 | 539 | $table = $tables["$typedesc"]['name']; |
540 | - $result = searchentry ($myconn,$value,$tables["$typedesc"]); |
|
540 | + $result = searchentry($myconn, $value, $tables["$typedesc"]); |
|
541 | 541 | |
542 | 542 | /* Manage abnormal conditions */ |
543 | 543 | /* Value already present in db more than once. This is absurd. Panic! */ |
544 | - if ($result->num_rows > 1) { |
|
545 | - syslog(LOG_EMERG,"$loguser: PANIC! Select for $type '$value' returned ". $result->num_rows ." items instead of one. Abnormal. Contact a sysadmin or a developer."); |
|
544 | + if ($result->num_rows>1) { |
|
545 | + syslog(LOG_EMERG, "$loguser: PANIC! Select for $type '$value' returned ".$result->num_rows." items instead of one. Abnormal. Contact a sysadmin or a developer."); |
|
546 | 546 | $result->free(); |
547 | 547 | return FALSE; |
548 | 548 | } |
549 | 549 | |
550 | 550 | /* Value already present in db or not present: to list anyway */ |
551 | - if ($result->num_rows >= 0) { |
|
551 | + if ($result->num_rows>=0) { |
|
552 | 552 | /* First, check for limit in number of listed items */ |
553 | - if (isFull($myconn,$typedesc,$tables)) { |
|
554 | - syslog(LOG_EMERG,"$loguser: $typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items. Abnormal exit.'); |
|
553 | + if (isFull($myconn, $typedesc, $tables)) { |
|
554 | + syslog(LOG_EMERG, "$loguser: $typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items. Abnormal exit.'); |
|
555 | 555 | $result->free(); |
556 | 556 | return FALSE; |
557 | 557 | } |
558 | 558 | /* Second, check if the (re)list would be consistent now */ |
559 | - if (! consistentListing($myconn,$tables,$typedesc,$value,$whynot) ) { |
|
559 | + if (!consistentListing($myconn, $tables, $typedesc, $value, $whynot)) { |
|
560 | 560 | syslog(LOG_ERR, $loguser.': '.$whynot); |
561 | 561 | $result->free(); |
562 | 562 | return FALSE; |
@@ -570,7 +570,7 @@ discard block |
||
570 | 570 | switch ($result->num_rows) { |
571 | 571 | /* Relist value if already present */ |
572 | 572 | case 1: |
573 | - if ( isListed($thisentry) ) { |
|
573 | + if (isListed($thisentry)) { |
|
574 | 574 | /* Entry already listed */ |
575 | 575 | $expdate = $thisentry['exp']; |
576 | 576 | $reason = sprintf('%s. Already listed. Adding 1 DAY to previous expire date.', |
@@ -584,33 +584,33 @@ discard block |
||
584 | 584 | $expdate = 0; /* This forces expiration from CURRENT_TIMESTAMP */ |
585 | 585 | } |
586 | 586 | $result->free(); |
587 | - return relist ($myconn,$loguser,$value,$type,$table,$unit,$quantity,$reason, $expdate); |
|
587 | + return relist($myconn, $loguser, $value, $type, $table, $unit, $quantity, $reason, $expdate); |
|
588 | 588 | |
589 | 589 | /* First time list value */ |
590 | 590 | case 0: |
591 | 591 | $result->free(); |
592 | - return addtolist ($myconn,$loguser,$value,$tables["$typedesc"],$unit,$quantity,$reason,$_); |
|
592 | + return addtolist($myconn, $loguser, $value, $tables["$typedesc"], $unit, $quantity, $reason, $_); |
|
593 | 593 | } |
594 | 594 | } |
595 | 595 | |
596 | 596 | |
597 | 597 | /*************** Functions to check if two net overlap each other ********************/ |
598 | 598 | |
599 | -function ipRange ($range) { |
|
599 | +function ipRange($range) { |
|
600 | 600 | /* List IP in range */ |
601 | - return array_map('long2ip', range( ip2long($range[0]), ip2long($range[1]) ) ); |
|
601 | + return array_map('long2ip', range(ip2long($range[0]), ip2long($range[1]))); |
|
602 | 602 | } |
603 | 603 | |
604 | 604 | function isIn($netA, $netB) { |
605 | 605 | /* TRUE if an IP of $netA is contained in netB */ |
606 | - list($addressA,$maskA) = explode('/', $netA); |
|
607 | - list($addressB,$maskB) = explode('/', $netB); |
|
606 | + list($addressA, $maskA) = explode('/', $netA); |
|
607 | + list($addressB, $maskB) = explode('/', $netB); |
|
608 | 608 | require_once 'vendor/autoload.php'; |
609 | 609 | $net = new \dautkom\ipv4\IPv4(); |
610 | 610 | $range = $net->address($addressA)->mask($maskA)->getRange(); |
611 | 611 | $ips = ipRange($range); |
612 | - foreach ( $ips as $ip ) |
|
613 | - if ( $net->address($addressB)->mask($maskB)->has($ip) ) |
|
612 | + foreach ($ips as $ip) |
|
613 | + if ($net->address($addressB)->mask($maskB)->has($ip)) |
|
614 | 614 | return TRUE; |
615 | 615 | return FALSE; |
616 | 616 | } |
@@ -622,11 +622,11 @@ discard block |
||
622 | 622 | syslog(LOG_ERR, $loguser.': '.$tabletype['name'].' is not a network list.'); |
623 | 623 | return FALSE; |
624 | 624 | } |
625 | - $result = searchentry ($myconn,'ALL',$tabletype); |
|
625 | + $result = searchentry($myconn, 'ALL', $tabletype); |
|
626 | 626 | if ($result->num_rows) { |
627 | 627 | while ($row = $result->fetch_array(MYSQLI_ASSOC)) { |
628 | 628 | $thisNet = long2ip($row['network']).'/'.long2ip($row['netmask']); |
629 | - if ( isIn($thisNet, $net) ) { |
|
629 | + if (isIn($thisNet, $net)) { |
|
630 | 630 | $result->free(); |
631 | 631 | syslog(LOG_INFO, "$loguser: the net <$net> overlaps the existing network <$thisNet>."); |
632 | 632 | return TRUE; |
@@ -643,8 +643,8 @@ discard block |
||
643 | 643 | /* For miltermap */ |
644 | 644 | function checkMilterConf($table) { |
645 | 645 | if (isset($table['milter'])) { |
646 | - if ($table['milter'] === TRUE) { |
|
647 | - switch ( $table['field'] ) { |
|
646 | + if ($table['milter'] === TRUE) { |
|
647 | + switch ($table['field']) { |
|
648 | 648 | case 'network': |
649 | 649 | case 'ip': |
650 | 650 | return TRUE; |
@@ -678,12 +678,12 @@ discard block |
||
678 | 678 | } |
679 | 679 | |
680 | 680 | |
681 | -function readMiltName($myconn,$loguser) { |
|
682 | - $milters=array(); |
|
681 | +function readMiltName($myconn, $loguser) { |
|
682 | + $milters = array(); |
|
683 | 683 | $query = 'SELECT `name` FROM `config`'; |
684 | 684 | |
685 | 685 | $result = $myconn->query($query); |
686 | - if($result === false) { |
|
686 | + if ($result === false) { |
|
687 | 687 | syslog(LOG_EMERG, "$loguser: ALERT: Query <$query> failed: ".$myconn->error); |
688 | 688 | return FALSE; |
689 | 689 | } |
@@ -695,27 +695,27 @@ discard block |
||
695 | 695 | return $milters; |
696 | 696 | } |
697 | 697 | |
698 | -function changeMilter ($myconn,$loguser,$miltVal,$table,$miltID) { |
|
698 | +function changeMilter($myconn, $loguser, $miltVal, $table, $miltID) { |
|
699 | 699 | $query = array(); |
700 | - foreach ( $miltVal as $value => $action ) { |
|
701 | - switch ( $action ) { |
|
700 | + foreach ($miltVal as $value => $action) { |
|
701 | + switch ($action) { |
|
702 | 702 | case 'keep': |
703 | 703 | break; |
704 | 704 | case 'add': |
705 | - $query[] = sprintf( "INSERT INTO `milt` ( |
|
705 | + $query[] = sprintf("INSERT INTO `milt` ( |
|
706 | 706 | `id` , |
707 | 707 | `name` |
708 | 708 | ) |
709 | 709 | VALUES ( |
710 | 710 | %d , |
711 | 711 | '%s' |
712 | - )",$miltID,$value); |
|
712 | + )",$miltID, $value); |
|
713 | 713 | break; |
714 | 714 | case 'del': |
715 | 715 | $query[] = "DELETE FROM `milt` WHERE (`id` = '$miltID' AND `name` = '$value')"; |
716 | 716 | } |
717 | 717 | } |
718 | - if ( count($query) ) /* This "if" is redundant, because if I call this I already checked there is a change */ |
|
718 | + if (count($query)) /* This "if" is redundant, because if I call this I already checked there is a change */ |
|
719 | 719 | /* I update datemod because the user couldn't change */ |
720 | 720 | $query[] = sprintf('UPDATE `%s` SET |
721 | 721 | `user`=\'%s\', |
@@ -727,18 +727,18 @@ discard block |
||
727 | 727 | $myconn->autocommit(FALSE); |
728 | 728 | $myconn->begin_transaction(MYSQLI_TRANS_START_READ_ONLY); |
729 | 729 | $ok = TRUE; |
730 | - foreach ( $query as $q ) { |
|
730 | + foreach ($query as $q) { |
|
731 | 731 | if ($myconn->query($q) !== TRUE) { |
732 | 732 | $ok = FALSE; |
733 | 733 | syslog(LOG_ERR, "$loguser: Error: ".$myconn->error); |
734 | 734 | } |
735 | 735 | } |
736 | - if ( $ok ) { |
|
737 | - if ( $myconn->commit() ) |
|
736 | + if ($ok) { |
|
737 | + if ($myconn->commit()) |
|
738 | 738 | syslog(LOG_INFO, "$loguser: Milter setting changed successfully."); |
739 | 739 | else { |
740 | 740 | syslog(LOG_ERR, "$loguser: Milter setting NOT changed for an unpredictable COMMIT error."); |
741 | - if ( $myconn->rollback() ) |
|
741 | + if ($myconn->rollback()) |
|
742 | 742 | syslog(LOG_INFO, "$loguser: rollback succeeded."); |
743 | 743 | else |
744 | 744 | syslog(LOG_ERR, "$loguser: rollback failed. Your db could be compromized. Check it!"); |
@@ -755,15 +755,15 @@ discard block |
||
755 | 755 | function curl_get($url, array $get = NULL, array $options = array(), $loguser) |
756 | 756 | { |
757 | 757 | $defaults = array( |
758 | - CURLOPT_URL => $url. (strpos($url, '?') === FALSE ? '?' : ''). http_build_query($get), |
|
758 | + CURLOPT_URL => $url.(strpos($url, '?') === FALSE ? '?' : '').http_build_query($get), |
|
759 | 759 | CURLOPT_HEADER => 0, |
760 | 760 | CURLOPT_RETURNTRANSFER => TRUE, |
761 | 761 | CURLOPT_TIMEOUT => 4 |
762 | 762 | ); |
763 | 763 | |
764 | 764 | $ch = curl_init(); |
765 | - curl_setopt_array($ch, ($options + $defaults)); |
|
766 | - if( ! $result = curl_exec($ch)) |
|
765 | + curl_setopt_array($ch, ($options+$defaults)); |
|
766 | + if (!$result = curl_exec($ch)) |
|
767 | 767 | { |
768 | 768 | syslog(LOG_ERR, sprintf('%s: CURL Error: <%s>', $loguser, curl_error($ch))); |
769 | 769 | } |