@@ -1,8 +1,9 @@ |
||
1 | 1 | #!/usr/bin/php |
2 | 2 | <?php |
3 | 3 | |
4 | -if (PHP_SAPI != "cli") |
|
4 | +if (PHP_SAPI != "cli") { |
|
5 | 5 | exit; |
6 | +} |
|
6 | 7 | |
7 | 8 | $home = '/var/www/html/RBL'; |
8 | 9 | require_once($home.'/config.php'); |
@@ -4,8 +4,9 @@ discard block |
||
4 | 4 | $typedesc=$_POST['type']; |
5 | 5 | $type = $tables["$typedesc"]['field']; |
6 | 6 | $col = milterTable($type); |
7 | -if ( $col === FALSE ) |
|
7 | +if ( $col === FALSE ) { |
|
8 | 8 | exit ("<p>Error in you config at field <b>$type</b>.</p>"); |
9 | +} |
|
9 | 10 | ?> |
10 | 11 | <td colspan="10" style="text-align: center"> |
11 | 12 | |
@@ -14,31 +15,35 @@ discard block |
||
14 | 15 | $user = $_POST['user']; |
15 | 16 | |
16 | 17 | /* Compare old values with new ones */ |
17 | -if (isset($_POST['newvalues'])) |
|
18 | +if (isset($_POST['newvalues'])) { |
|
18 | 19 | $new = $_POST['newvalues']; |
19 | -else |
|
20 | +} else { |
|
20 | 21 | $new = array(); |
21 | -if (! empty($_POST['oldvalues'])) |
|
22 | +} |
|
23 | +if (! empty($_POST['oldvalues'])) { |
|
22 | 24 | $old = explode(',', $_POST['oldvalues']); |
23 | -else |
|
25 | +} else { |
|
24 | 26 | $old=array(); |
27 | +} |
|
25 | 28 | $values=array(); |
26 | 29 | $logs=array(); |
27 | 30 | |
28 | 31 | print '<pre>'; |
29 | 32 | /* Check need to disable all milters, removing unnecessary setting */ |
30 | -if ( in_array('DISABLE ALL', $new) ) |
|
33 | +if ( in_array('DISABLE ALL', $new) ) { |
|
31 | 34 | $new = array('DISABLE ALL'); |
35 | +} |
|
32 | 36 | |
33 | 37 | /* Compare the values determining what to do */ |
34 | 38 | if (count(array_diff(array_merge($new, $old), array_intersect($new, $old))) !== 0) { |
35 | 39 | /* New and old are different (we assume we don't have duplicate values) */ |
36 | 40 | if (! empty($new) ) { |
37 | 41 | foreach ($new as $item) { |
38 | - if ( in_array($item, $old) ) |
|
39 | - $values["$item"] = 'keep'; |
|
40 | - else |
|
41 | - $values["$item"] = 'add'; |
|
42 | + if ( in_array($item, $old) ) { |
|
43 | + $values["$item"] = 'keep'; |
|
44 | + } else { |
|
45 | + $values["$item"] = 'add'; |
|
46 | + } |
|
42 | 47 | $logs[] = "<$item>: ". $values["$item"]; |
43 | 48 | } |
44 | 49 | } |
@@ -53,22 +58,25 @@ discard block |
||
53 | 58 | } |
54 | 59 | |
55 | 60 | /* Logging */ |
56 | -if ( empty($values) ) |
|
61 | +if ( empty($values) ) { |
|
57 | 62 | print 'No values to change.'; |
58 | -else { |
|
63 | +} else { |
|
59 | 64 | $msg = sprintf('%s: Changing Milter setting on list <%s> for %s <%s>.',$user,$typedesc,$type, $_POST['object']); |
60 | 65 | syslog(LOG_INFO, $msg); |
61 | - foreach ($logs as $log) |
|
62 | - syslog(LOG_INFO, "$user: milter $log"); |
|
66 | + foreach ($logs as $log) { |
|
67 | + syslog(LOG_INFO, "$user: milter $log"); |
|
68 | + } |
|
63 | 69 | |
64 | 70 | /* Store new values */ |
65 | - if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) |
|
66 | - exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
|
71 | + if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) { |
|
72 | + exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
|
73 | + } |
|
67 | 74 | |
68 | - if (changeMilter ($mysqli,$user,$values,$col,$_POST['miltId'])) |
|
69 | - print 'OK milter setting changed.'; |
|
70 | - else |
|
71 | - print 'ERROR updating milter setting; check your syslog. No changes made.'; |
|
75 | + if (changeMilter ($mysqli,$user,$values,$col,$_POST['miltId'])) { |
|
76 | + print 'OK milter setting changed.'; |
|
77 | + } else { |
|
78 | + print 'ERROR updating milter setting; check your syslog. No changes made.'; |
|
79 | + } |
|
72 | 80 | |
73 | 81 | $mysqli->close(); |
74 | 82 | } |
@@ -1,11 +1,14 @@ |
||
1 | 1 | <?php |
2 | -if (in_array($user,array_keys(array_filter($adm)))) $extopt = '<option value="MONTH">MONTHS</option><option value="YEAR">YEARS</option>'; |
|
3 | -else $extopt = NULL; |
|
2 | +if (in_array($user,array_keys(array_filter($adm)))) { |
|
3 | + $extopt = '<option value="MONTH">MONTHS</option><option value="YEAR">YEARS</option>'; |
|
4 | +} else { |
|
5 | + $extopt = NULL; |
|
6 | +} |
|
4 | 7 | |
5 | 8 | if ( $tables["$typedesc"]['milter'] ) { |
6 | - if ( checkMilterConf($tables["$typedesc"]) ) |
|
7 | - print '<p>This is a milter table. Please, first add your item as usual. Then you will be able to customize the milter settings.</p>'; |
|
8 | - else { |
|
9 | + if ( checkMilterConf($tables["$typedesc"]) ) { |
|
10 | + print '<p>This is a milter table. Please, first add your item as usual. Then you will be able to customize the milter settings.</p>'; |
|
11 | + } else { |
|
9 | 12 | $err = "Error in config about <$typedesc>. Check at your config.php."; |
10 | 13 | syslog (LOG_EMERG, $err); |
11 | 14 | printf ('<p>%s</p>', htmlspecialchars($err) ); |
@@ -9,19 +9,26 @@ |
||
9 | 9 | <td colspan="<?php echo $cl; ?>" style="text-align: center"> |
10 | 10 | <?php |
11 | 11 | openlog($tag, LOG_PID, $fac); |
12 | -if (empty($_POST['reason'])) die ("Specify a reason, please!</td>"); |
|
13 | -if (preg_match( '/[^\x20-\x7f]/', $_POST['reason'])) |
|
12 | +if (empty($_POST['reason'])) { |
|
13 | + die ("Specify a reason, please!</td>"); |
|
14 | +} |
|
15 | +if (preg_match( '/[^\x20-\x7f]/', $_POST['reason'])) { |
|
14 | 16 | exit('ERROR: <'.htmlentities($_POST['reason'],ENT_COMPAT | ENT_HTML401, 'ISO-8859-1').'> contains NON ASCII chars.</td>'); |
17 | +} |
|
15 | 18 | $user = username(); |
16 | 19 | |
17 | -if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) |
|
20 | +if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) { |
|
18 | 21 | exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
22 | +} |
|
19 | 23 | |
20 | -if (isFull($mysqli,$typedesc,$tables)) die("ERROR in relist: ".htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.') ); |
|
21 | -if (relist ($mysqli,username(),$_POST['value'],$type,$table,$_POST['unit'],$_POST['quantity'],$_POST['reason'])) |
|
24 | +if (isFull($mysqli,$typedesc,$tables)) { |
|
25 | + die("ERROR in relist: ".htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.') ); |
|
26 | +} |
|
27 | +if (relist ($mysqli,username(),$_POST['value'],$type,$table,$_POST['unit'],$_POST['quantity'],$_POST['reason'])) { |
|
22 | 28 | print 'OK '.$_POST["type"].' <'.$_POST['value'].'> relisted for '.$_POST['quantity'].$_POST['unit']; |
23 | -else |
|
29 | +} else { |
|
24 | 30 | print 'ERROR in relist; check log'; |
31 | +} |
|
25 | 32 | $mysqli->close(); |
26 | 33 | closelog(); |
27 | 34 | print '</td>'; |
@@ -6,20 +6,27 @@ |
||
6 | 6 | $table = ($tables["$typedesc"]['milter']) ? milterTable($type) : $tables["$typedesc"]['name']; |
7 | 7 | |
8 | 8 | openlog($tag, LOG_PID, $fac); |
9 | -if (empty($_POST['reason'])) die ("<p>Please, specify a reason!</p>"); |
|
10 | -if (preg_match( '/[^\x20-\x7f]/', $_POST['reason'])) |
|
9 | +if (empty($_POST['reason'])) { |
|
10 | + die ("<p>Please, specify a reason!</p>"); |
|
11 | +} |
|
12 | +if (preg_match( '/[^\x20-\x7f]/', $_POST['reason'])) { |
|
11 | 13 | exit('<p>ERROR: <'.htmlentities($_POST['reason'],ENT_COMPAT | ENT_HTML401, 'ISO-8859-1').'> contains NON ASCII chars.</p>'); |
14 | +} |
|
12 | 15 | $user = username(); |
13 | 16 | $err = NULL; |
14 | 17 | |
15 | -if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) |
|
18 | +if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) { |
|
16 | 19 | exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
20 | +} |
|
17 | 21 | |
18 | -if (addtolist ($mysqli,$user,$_POST['value'],$tables["$typedesc"],$_POST['unit'],$_POST['quantity'],$_POST['reason'],$err)) |
|
22 | +if (addtolist ($mysqli,$user,$_POST['value'],$tables["$typedesc"],$_POST['unit'],$_POST['quantity'],$_POST['reason'],$err)) { |
|
19 | 23 | print 'OK '.$_POST["type"].' <'.$_POST['value'].'> first time listed for '.$_POST['quantity'].$_POST['unit'].'.'; |
20 | -else |
|
24 | +} else { |
|
21 | 25 | print 'List operation ERROR; check log.'; |
22 | -if (!is_null($err) ) print htmlentities(' Error: ' . $err); |
|
26 | +} |
|
27 | +if (!is_null($err) ) { |
|
28 | + print htmlentities(' Error: ' . $err); |
|
29 | +} |
|
23 | 30 | $mysqli->close(); |
24 | 31 | closelog(); |
25 | 32 | ?> |
@@ -9,12 +9,14 @@ |
||
9 | 9 | openlog($tag, LOG_PID, $fac); |
10 | 10 | $user = username(); |
11 | 11 | |
12 | -if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) |
|
12 | +if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) { |
|
13 | 13 | exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
14 | -if (remove ($mysqli,$user,$_POST['value'],$type,$table)) |
|
14 | +} |
|
15 | +if (remove ($mysqli,$user,$_POST['value'],$type,$table)) { |
|
15 | 16 | print 'OK '.$typedesc.' <'.$_POST['value'].'> permanently REMOVED!'; |
16 | -else |
|
17 | +} else { |
|
17 | 18 | print 'Delete operation ERROR on '.$typedesc.' <'.$_POST['value'].'>; check log.'; |
19 | +} |
|
18 | 20 | print '</td>'; |
19 | 21 | $mysqli->close(); |
20 | 22 | closelog(); |
@@ -1,7 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | $adm = unserialize($_POST["adm"]); |
3 | -if (in_array($_POST["user"],array_keys(array_filter($adm)))) $extopt = '<option value="MONTH">MONTHS</option><option value="YEAR">YEARS</option>'; |
|
4 | -else $extopt = NULL; |
|
3 | +if (in_array($_POST["user"],array_keys(array_filter($adm)))) { |
|
4 | + $extopt = '<option value="MONTH">MONTHS</option><option value="YEAR">YEARS</option>'; |
|
5 | +} else { |
|
6 | + $extopt = NULL; |
|
7 | +} |
|
5 | 8 | |
6 | 9 | require_once('config.php'); |
7 | 10 | $typedesc=$_POST['type']; |
@@ -11,13 +11,15 @@ |
||
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 ) |
|
14 | +if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) { |
|
15 | 15 | exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
16 | +} |
|
16 | 17 | |
17 | -if (changestatus($mysqli,username(),$_POST['value'],'0',$type,$table)) |
|
18 | +if (changestatus($mysqli,username(),$_POST['value'],'0',$type,$table)) { |
|
18 | 19 | print 'OK '.$_POST["type"].' <'.$_POST['value'].'> delisted.'; |
19 | -else |
|
20 | +} else { |
|
20 | 21 | print 'ERROR in delist <'.$_POST['value'].'>; check log'; |
22 | +} |
|
21 | 23 | print '</td>'; |
22 | 24 | $mysqli->close(); |
23 | 25 | closelog(); |
@@ -141,17 +141,19 @@ discard block |
||
141 | 141 | $thisVal = $data[1]; |
142 | 142 | unset($data[1]); |
143 | 143 | $data = array_values($data); |
144 | - if ( !in_array($thisVal,array_keys($tolist)) ) |
|
145 | - $tolist["$thisVal"] = $data; |
|
146 | - else if ($data[3]>$tolist[$thisVal][3]) |
|
147 | - $tolist["$thisVal"] = $data; |
|
148 | -} |
|
144 | + if ( !in_array($thisVal,array_keys($tolist)) ) { |
|
145 | + $tolist["$thisVal"] = $data; |
|
146 | + } else if ($data[3]>$tolist[$thisVal][3]) { |
|
147 | + $tolist["$thisVal"] = $data; |
|
148 | + } |
|
149 | + } |
|
149 | 150 | |
150 | 151 | /* Make MYSQL connection */ |
151 | 152 | |
152 | 153 | $mysqli = myConnect($host, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user); |
153 | -if ( $mysqli === FALSE ) |
|
154 | +if ( $mysqli === FALSE ) { |
|
154 | 155 | exit (254); |
156 | +} |
|
155 | 157 | |
156 | 158 | foreach ( array_keys($tolist) as $value) { |
157 | 159 | $quantity = $conf['quantity']; |
@@ -168,17 +170,18 @@ discard block |
||
168 | 170 | $recip = emailToNotify($domainNotify_file,$domain); |
169 | 171 | $subject = sprintf('%s <%s> is now blocked because exceedes limits on outgoing emails', |
170 | 172 | $tables["$typedesc"]['field'], $value); |
171 | - if (!empty($recip)) |
|
172 | - if ( sendEmailWarn($tplfile,'[email protected]',$recip, |
|
173 | + if (!empty($recip)) { |
|
174 | + if ( sendEmailWarn($tplfile,'[email protected]',$recip, |
|
173 | 175 | $subject,$value,"$quantity $unit",$reason) ) |
174 | 176 | syslog(LOG_INFO, "$user: \"$recip\" was notified about the \"$value\" abuse."); |
177 | + } |
|
178 | + } else { |
|
179 | + syslog(LOG_ERR,"$user: <$domain> contains the '@' char. Notification cannot be sent."); |
|
175 | 180 | } |
176 | - else syslog(LOG_ERR,"$user: <$domain> contains the '@' char. Notification cannot be sent."); |
|
177 | 181 | } |
178 | 182 | } |
179 | 183 | } |
180 | - } |
|
181 | - else { |
|
184 | + } else { |
|
182 | 185 | $reason .= " But it has NOT been listed because it doesn't apply to the trigger condition."; |
183 | 186 | syslog (LOG_INFO, "$user: ".$reason); |
184 | 187 | } |