@@ -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(); |
@@ -234,6 +234,9 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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); |
@@ -3,22 +3,27 @@ discard block |
||
3 | 3 | ini_set('error_log', 'syslog'); |
4 | 4 | |
5 | 5 | function username() { |
6 | - if (isset ($_SERVER['REMOTE_USER'])) $user = $_SERVER['REMOTE_USER']; |
|
7 | - else if (isset ($_SERVER['USER'])) $user = $_SERVER['USER']; |
|
8 | - else $user='unknown'; |
|
6 | + if (isset ($_SERVER['REMOTE_USER'])) { |
|
7 | + $user = $_SERVER['REMOTE_USER']; |
|
8 | + } else if (isset ($_SERVER['USER'])) { |
|
9 | + $user = $_SERVER['USER']; |
|
10 | + } else { |
|
11 | + $user='unknown'; |
|
12 | + } |
|
9 | 13 | return $user; |
10 | 14 | } |
11 | 15 | |
12 | 16 | function checkSSL() { |
13 | - if ( empty( $_SERVER['HTTPS'] ) ) |
|
14 | - printf ('<div id="content">Ehi sysadmin! Your site is not secure. Please enable SSL on your server and configure a redirect, such as' . |
|
17 | + if ( empty( $_SERVER['HTTPS'] ) ) { |
|
18 | + printf ('<div id="content">Ehi sysadmin! Your site is not secure. Please enable SSL on your server and configure a redirect, such as' . |
|
15 | 19 | '<pre>' . |
16 | 20 | htmlspecialchars('<VirtualHost *:80>' . "\n" . |
17 | 21 | ' ServerName %s' . "\n" . |
18 | 22 | ' Redirect permanent / https://%s/' . "\n" . |
19 | 23 | '</VirtualHost>') . |
20 | 24 | '</pre></div>', gethostname(), gethostname()); |
21 | -} |
|
25 | + } |
|
26 | + } |
|
22 | 27 | |
23 | 28 | function myConnect($host, $user, $pass, $db, $port, $tablelist, $typedesc, $loguser) { |
24 | 29 | $db = ( $tablelist["$typedesc"]['milter'] ) ? $tablelist["$typedesc"]['name'] : $db; |
@@ -99,8 +104,9 @@ discard block |
||
99 | 104 | if ($myconn->query($query) === TRUE) { |
100 | 105 | syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit."); |
101 | 106 | $result=TRUE; |
107 | + } else { |
|
108 | + syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
|
102 | 109 | } |
103 | - else syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
|
104 | 110 | return $result; |
105 | 111 | } |
106 | 112 | |
@@ -110,8 +116,7 @@ discard block |
||
110 | 116 | if ( $exptime ) { /* Entry already listed */ |
111 | 117 | $nlist = '`nlist`'; |
112 | 118 | $exptime = sprintf('\'%s\'', $exptime); /* Eh MySQL... an hour lost to notice this */ |
113 | - } |
|
114 | - else { |
|
119 | + } else { |
|
115 | 120 | $exptime = 'CURRENT_TIMESTAMP'; |
116 | 121 | $nlist = '`nlist` + 1'; |
117 | 122 | } |
@@ -149,8 +154,9 @@ discard block |
||
149 | 154 | if ($myconn->query($query) === TRUE) { |
150 | 155 | syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit from $exptime."); |
151 | 156 | $result=TRUE; |
157 | + } else { |
|
158 | + syslog (LOG_ERR, "$user: Error: ". $myconn->error); |
|
152 | 159 | } |
153 | - else syslog (LOG_ERR, "$user: Error: ". $myconn->error); |
|
154 | 160 | return $result; |
155 | 161 | } |
156 | 162 | |
@@ -173,9 +179,11 @@ discard block |
||
173 | 179 | } |
174 | 180 | |
175 | 181 | |
176 | - if ($return=$myconn->query($query) === TRUE) |
|
177 | - syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>."); |
|
178 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
182 | + if ($return=$myconn->query($query) === TRUE) { |
|
183 | + syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>."); |
|
184 | + } else { |
|
185 | + syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
186 | + } |
|
179 | 187 | |
180 | 188 | return $return; |
181 | 189 | } |
@@ -197,8 +205,9 @@ discard block |
||
197 | 205 | |
198 | 206 | if ($return=$myconn->query($query) === TRUE) { |
199 | 207 | syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>"); |
208 | + } else { |
|
209 | + syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
200 | 210 | } |
201 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
202 | 211 | return $return; |
203 | 212 | } |
204 | 213 | |
@@ -222,14 +231,16 @@ discard block |
||
222 | 231 | $j++; |
223 | 232 | |
224 | 233 | } while ($myconn->next_result()); |
225 | - } |
|
226 | - else { |
|
234 | + } else { |
|
227 | 235 | syslog(LOG_ERR, "Expire job - Error: ". $myconn->error); |
228 | 236 | $return = FALSE; |
229 | 237 | } |
230 | 238 | } |
231 | - if ( !($return) ) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); |
|
232 | - else syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.'); |
|
239 | + if ( !($return) ) { |
|
240 | + syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); |
|
241 | + } else { |
|
242 | + syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.'); |
|
243 | + } |
|
233 | 244 | return $return; |
234 | 245 | } |
235 | 246 | |
@@ -238,8 +249,11 @@ discard block |
||
238 | 249 | |
239 | 250 | $exp=new DateTime($row['exp']); |
240 | 251 | $now=new DateTime('NOW'); |
241 | - if (($exp > $now) and ($row['active'])) return true; |
|
242 | - else return false; |
|
252 | + if (($exp > $now) and ($row['active'])) { |
|
253 | + return true; |
|
254 | + } else { |
|
255 | + return false; |
|
256 | + } |
|
243 | 257 | |
244 | 258 | } |
245 | 259 | |
@@ -259,10 +273,11 @@ discard block |
||
259 | 273 | END; |
260 | 274 | $activeMilts = explode(',',$value); |
261 | 275 | foreach ( $milts as $milter ) { |
262 | - if ( in_array($milter, $activeMilts) ) |
|
263 | - $selected= 'selected'; |
|
264 | - else |
|
265 | - $selected= NULL; |
|
276 | + if ( in_array($milter, $activeMilts) ) { |
|
277 | + $selected= 'selected'; |
|
278 | + } else { |
|
279 | + $selected= NULL; |
|
280 | + } |
|
266 | 281 | $button .= sprintf('<option value="%s" %s>%s</option>', $milter, $selected, $milter); |
267 | 282 | } |
268 | 283 | $button .= '</select></div><input class="button" name="Change" type="submit" value="Change" /></form>'; |
@@ -279,9 +294,12 @@ discard block |
||
279 | 294 | $whynot=NULL; |
280 | 295 | switch ($what) { |
281 | 296 | case 'Ok': |
282 | - if ($lock) return NULL; |
|
283 | - if (in_array($user,array_keys($adm))) |
|
284 | - if ( consistentListing($myconn,$alltables,$typedesc,$value,$whynot) ) return require('relistButton.php'); |
|
297 | + if ($lock) { |
|
298 | + return NULL; |
|
299 | + } |
|
300 | + if (in_array($user,array_keys($adm))) { |
|
301 | + if ( consistentListing($myconn,$alltables,$typedesc,$value,$whynot) ) return require('relistButton.php'); |
|
302 | + } |
|
285 | 303 | return htmlspecialchars($whynot); |
286 | 304 | case 'Listed': |
287 | 305 | case 'WhiteListed': |
@@ -293,7 +311,9 @@ discard block |
||
293 | 311 | function consistentListing($myconn,$alltables,$typed,$value,&$warn) { |
294 | 312 | /* Check if there are no pending mislisting */ |
295 | 313 | $warn = NULL; |
296 | - if (! isset($alltables["$typed"]['depend']) ) return TRUE; |
|
314 | + if (! isset($alltables["$typed"]['depend']) ) { |
|
315 | + return TRUE; |
|
316 | + } |
|
297 | 317 | foreach ($alltables["$typed"]['depend'] as $listdep) { |
298 | 318 | if ($alltables["$typed"]['field'] != $alltables["$listdep"]['field'] ) { |
299 | 319 | $warn = "Config ERROR: <$typed> and <$listdep> are of different types! I can't check consistency!"; |
@@ -324,10 +344,10 @@ discard block |
||
324 | 344 | |
325 | 345 | if ( $tablelist['milter'] ) { |
326 | 346 | $table = milterTable($type); |
327 | - if ($value == 'ALL') |
|
328 | - $query = sprintf('SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id) GROUP by idmilt', |
|
347 | + if ($value == 'ALL') { |
|
348 | + $query = sprintf('SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id) GROUP by idmilt', |
|
329 | 349 | $table,$table); |
330 | - else { |
|
350 | + } else { |
|
331 | 351 | switch ($type) { |
332 | 352 | case 'network': |
333 | 353 | list($sub['net'],$sub['mask'])=explode('/',$value); |
@@ -352,12 +372,11 @@ discard block |
||
352 | 372 | return FALSE; |
353 | 373 | } |
354 | 374 | } |
355 | - } |
|
356 | - |
|
357 | - else { |
|
375 | + } else { |
|
358 | 376 | $table = $tablelist['name']; |
359 | - if ($value == 'ALL') $query = 'select * from '.$table; |
|
360 | - else { |
|
377 | + if ($value == 'ALL') { |
|
378 | + $query = 'select * from '.$table; |
|
379 | + } else { |
|
361 | 380 | switch ($type) { |
362 | 381 | case 'ip': |
363 | 382 | $query= "select * from $table where $type = INET_ATON('$value')"; |
@@ -379,8 +398,9 @@ discard block |
||
379 | 398 | } |
380 | 399 | |
381 | 400 | $result = $myconn->query($query); |
382 | - if($result === false) |
|
383 | - syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error); |
|
401 | + if($result === false) { |
|
402 | + syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error); |
|
403 | + } |
|
384 | 404 | return $result; |
385 | 405 | } |
386 | 406 | |
@@ -397,12 +417,14 @@ discard block |
||
397 | 417 | |
398 | 418 | function isFull($myconn,$typedesc,$alltables) { |
399 | 419 | if (isset($alltables["$typedesc"]['limit'])) { |
400 | - if ( $alltables["$typedesc"]['milter'] ) |
|
401 | - $tab = 'net'; |
|
402 | - else |
|
403 | - $tab = $alltables["$typedesc"]['name']; |
|
404 | - if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) |
|
405 | - return TRUE; |
|
420 | + if ( $alltables["$typedesc"]['milter'] ) { |
|
421 | + $tab = 'net'; |
|
422 | + } else { |
|
423 | + $tab = $alltables["$typedesc"]['name']; |
|
424 | + } |
|
425 | + if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) { |
|
426 | + return TRUE; |
|
427 | + } |
|
406 | 428 | } |
407 | 429 | return FALSE; |
408 | 430 | } |
@@ -415,14 +437,17 @@ discard block |
||
415 | 437 | $tabhtm = <<<END |
416 | 438 | <table><thead><tr><th>$type</th><th title="The date this object has been listed for the first time">DateAdd</th><th>DateMod</th><th>Exp</th><th>Status</th><th title="Number of times this object has been listed">#List</th> |
417 | 439 | END; |
418 | - if ( $tables["$typedesc"]['milter'] ) |
|
419 | - $tabhtm .= '<th title="Milter active for this object">Milters</th>'; |
|
440 | + if ( $tables["$typedesc"]['milter'] ) { |
|
441 | + $tabhtm .= '<th title="Milter active for this object">Milters</th>'; |
|
442 | + } |
|
420 | 443 | $tabhtm .= '<th>Authored by</th><th width="250">Reason</th><th>Action</th></tr></thead><tfoot><tr></tr></tfoot><tbody>'."\n"; |
421 | 444 | |
422 | - if ($type == 'domain') |
|
423 | - $value = nsdom($value); |
|
424 | - if (is_null($value)) |
|
425 | - return FALSE; |
|
445 | + if ($type == 'domain') { |
|
446 | + $value = nsdom($value); |
|
447 | + } |
|
448 | + if (is_null($value)) { |
|
449 | + return FALSE; |
|
450 | + } |
|
426 | 451 | |
427 | 452 | $result = searchentry ($myconn,$value,$tables["$typedesc"]); |
428 | 453 | if ($result) { |
@@ -430,18 +455,23 @@ discard block |
||
430 | 455 | |
431 | 456 | /* Check for limit in number of listed items */ |
432 | 457 | $full = isFull($myconn,$typedesc,$tables); |
433 | - if ($full) print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>'; |
|
458 | + if ($full) { |
|
459 | + print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>'; |
|
460 | + } |
|
434 | 461 | |
435 | 462 | if ($result->num_rows) { |
436 | 463 | print $tabhtm; |
437 | 464 | $i=0; |
438 | 465 | while ($riga = $result->fetch_array(MYSQLI_ASSOC)) { |
439 | 466 | if (isListed($riga)) { |
440 | - if ($tables["$typedesc"]['bl']) $listed='Listed'; |
|
441 | - else $listed='WhiteListed'; |
|
442 | - } |
|
443 | - else |
|
444 | - $listed='Ok'; |
|
467 | + if ($tables["$typedesc"]['bl']) { |
|
468 | + $listed='Listed'; |
|
469 | + } else { |
|
470 | + $listed='WhiteListed'; |
|
471 | + } |
|
472 | + } else { |
|
473 | + $listed='Ok'; |
|
474 | + } |
|
445 | 475 | |
446 | 476 | switch ($type) { |
447 | 477 | case 'ip': |
@@ -454,27 +484,30 @@ discard block |
||
454 | 484 | $element = $riga["$type"]; |
455 | 485 | } |
456 | 486 | |
457 | - if ( $tables["$typedesc"]['milter'] AND checkMilterConf($tables["$typedesc"]) ) |
|
458 | - 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", |
|
487 | + if ( $tables["$typedesc"]['milter'] AND checkMilterConf($tables["$typedesc"]) ) { |
|
488 | + 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", |
|
459 | 489 | $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)); |
460 | - else |
|
461 | - 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", |
|
490 | + } else { |
|
491 | + 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", |
|
462 | 492 | $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)); |
493 | + } |
|
463 | 494 | $i++; |
464 | 495 | } |
465 | 496 | print '</tbody></table>'; |
466 | - } |
|
467 | - else { |
|
497 | + } else { |
|
468 | 498 | print "<pre>$type <$value> is not listed!\n</pre>"; |
469 | - if ( in_array($user,array_keys($adm)) AND ($value != 'ALL') ) |
|
470 | - if ( (!$full) AND (consistentListing($myconn,$tables,$typedesc,$value,$whynot)) ) require_once('listForm.php'); |
|
471 | - else print '<p>'.htmlspecialchars($whynot).'</p>'; |
|
499 | + if ( in_array($user,array_keys($adm)) AND ($value != 'ALL') ) { |
|
500 | + if ( (!$full) AND (consistentListing($myconn,$tables,$typedesc,$value,$whynot)) ) require_once('listForm.php'); |
|
501 | + } else { |
|
502 | + print '<p>'.htmlspecialchars($whynot).'</p>'; |
|
503 | + } |
|
472 | 504 | |
473 | 505 | } |
474 | 506 | $result->free(); |
507 | + } else { |
|
508 | + print '<pre>Query error or something wrong in DB schema'."\n</pre>"; |
|
509 | + } |
|
475 | 510 | } |
476 | - else print '<pre>Query error or something wrong in DB schema'."\n</pre>"; |
|
477 | -} |
|
478 | 511 | |
479 | 512 | |
480 | 513 | |
@@ -517,24 +550,32 @@ discard block |
||
517 | 550 | $old_mailfrom = ini_get("sendmail_from"); |
518 | 551 | ini_set("sendmail_from", $from); |
519 | 552 | $params = sprintf("-oi -f %s", '<>'); |
520 | - if (!(mail($to,$sbj, $body,$headers,$params))) $flag=FALSE; |
|
521 | - else $flag=TRUE; |
|
522 | - if (isset($old_mailfrom)) |
|
523 | - ini_set("sendmail_from", $old_mailfrom); |
|
524 | - } |
|
525 | - else { |
|
526 | - if (!(mail($to,$sbj, $body,$headers))) $flag=FALSE; |
|
527 | - else $flag=TRUE; |
|
553 | + if (!(mail($to,$sbj, $body,$headers,$params))) { |
|
554 | + $flag=FALSE; |
|
555 | + } else { |
|
556 | + $flag=TRUE; |
|
557 | + } |
|
558 | + if (isset($old_mailfrom)) { |
|
559 | + ini_set("sendmail_from", $old_mailfrom); |
|
560 | + } |
|
561 | + } else { |
|
562 | + if (!(mail($to,$sbj, $body,$headers))) { |
|
563 | + $flag=FALSE; |
|
564 | + } else { |
|
565 | + $flag=TRUE; |
|
566 | + } |
|
528 | 567 | } |
529 | 568 | return $flag; |
530 | 569 | } |
531 | 570 | |
532 | 571 | function emailToNotify($notify_file,$dom) { |
533 | 572 | $ini_array = parse_ini_file($notify_file); |
534 | - if (in_array($dom,array_keys($ini_array))) |
|
535 | - return $ini_array["$dom"]; |
|
536 | - else return FALSE; |
|
537 | -} |
|
573 | + if (in_array($dom,array_keys($ini_array))) { |
|
574 | + return $ini_array["$dom"]; |
|
575 | + } else { |
|
576 | + return FALSE; |
|
577 | + } |
|
578 | + } |
|
538 | 579 | |
539 | 580 | |
540 | 581 | function searchAndList ($myconn,$loguser,$tables,$typedesc,$value,$unit,&$quantity,&$reason) { |
@@ -582,8 +623,7 @@ discard block |
||
582 | 623 | $reason); |
583 | 624 | $quantity = 1; |
584 | 625 | $unit = 'DAY'; |
585 | - } |
|
586 | - else { |
|
626 | + } else { |
|
587 | 627 | /* Entry delisted */ |
588 | 628 | $quantity *= $thisentry['nlist']; |
589 | 629 | $expdate = 0; /* This forces expiration from CURRENT_TIMESTAMP */ |
@@ -614,9 +654,10 @@ discard block |
||
614 | 654 | $net = new \dautkom\ipv4\IPv4(); |
615 | 655 | $range = $net->address($addressA)->mask($maskA)->getRange(); |
616 | 656 | $ips = ipRange($range); |
617 | - foreach ( $ips as $ip ) |
|
618 | - if ( $net->address($addressB)->mask($maskB)->has($ip) ) |
|
657 | + foreach ( $ips as $ip ) { |
|
658 | + if ( $net->address($addressB)->mask($maskB)->has($ip) ) |
|
619 | 659 | return TRUE; |
660 | + } |
|
620 | 661 | return FALSE; |
621 | 662 | } |
622 | 663 | |
@@ -693,8 +734,9 @@ discard block |
||
693 | 734 | return FALSE; |
694 | 735 | } |
695 | 736 | if ($result->num_rows) { |
696 | - while ($milt = $result->fetch_array(MYSQLI_ASSOC)) |
|
697 | - $milters[] = $milt['name']; |
|
737 | + while ($milt = $result->fetch_array(MYSQLI_ASSOC)) { |
|
738 | + $milters[] = $milt['name']; |
|
739 | + } |
|
698 | 740 | } |
699 | 741 | $result->free(); |
700 | 742 | return $milters; |
@@ -720,12 +762,14 @@ discard block |
||
720 | 762 | $query[] = "DELETE FROM `milt` WHERE (`id` = '$miltID' AND `name` = '$value')"; |
721 | 763 | } |
722 | 764 | } |
723 | - if ( count($query) ) /* This "if" is redundant, because if I call this I already checked there is a change */ |
|
765 | + if ( count($query) ) { |
|
766 | + /* This "if" is redundant, because if I call this I already checked there is a change */ |
|
724 | 767 | /* I update datemod because the user couldn't change */ |
725 | 768 | $query[] = sprintf('UPDATE `%s` SET |
726 | 769 | `user`=\'%s\', |
727 | 770 | `datemod`= CURRENT_TIMESTAMP |
728 | 771 | WHERE `idmilt`=%d', $table, $loguser, $miltID); |
772 | + } |
|
729 | 773 | |
730 | 774 | |
731 | 775 | /* Start a safe transaction: it commits only if all queries happen */ |
@@ -739,19 +783,20 @@ discard block |
||
739 | 783 | } |
740 | 784 | } |
741 | 785 | if ( $ok ) { |
742 | - if ( $myconn->commit() ) |
|
743 | - syslog(LOG_INFO, "$loguser: Milter setting changed successfully."); |
|
744 | - else { |
|
786 | + if ( $myconn->commit() ) { |
|
787 | + syslog(LOG_INFO, "$loguser: Milter setting changed successfully."); |
|
788 | + } else { |
|
745 | 789 | syslog(LOG_ERR, "$loguser: Milter setting NOT changed for an unpredictable COMMIT error."); |
746 | - if ( $myconn->rollback() ) |
|
747 | - syslog(LOG_INFO, "$loguser: rollback succeeded."); |
|
748 | - else |
|
749 | - syslog(LOG_ERR, "$loguser: rollback failed. Your db could be compromized. Check it!"); |
|
790 | + if ( $myconn->rollback() ) { |
|
791 | + syslog(LOG_INFO, "$loguser: rollback succeeded."); |
|
792 | + } else { |
|
793 | + syslog(LOG_ERR, "$loguser: rollback failed. Your db could be compromized. Check it!"); |
|
794 | + } |
|
750 | 795 | $ok = FALSE; |
751 | 796 | } |
797 | + } else { |
|
798 | + syslog(LOG_ERR, "$loguser: Error: Milter setting NOT changed. See at above errors."); |
|
752 | 799 | } |
753 | - else |
|
754 | - syslog(LOG_ERR, "$loguser: Error: Milter setting NOT changed. See at above errors."); |
|
755 | 800 | return $ok; |
756 | 801 | |
757 | 802 | } |
@@ -780,20 +825,24 @@ discard block |
||
780 | 825 | function nsdom($dom) { |
781 | 826 | /* Return the first upper domain (or domain itself) with NS record */ |
782 | 827 | /* checkdnsrr doesn't work with alias... use dns_get_record */ |
783 | - if (dns_get_record ( $dom , DNS_NS )) |
|
784 | - return rtrim($dom, '.'); |
|
785 | - if (dns_get_record ( $dom , DNS_A )) |
|
786 | - return nsdom( ltrim(strstr($dom, '.'), '.') ); |
|
828 | + if (dns_get_record ( $dom , DNS_NS )) { |
|
829 | + return rtrim($dom, '.'); |
|
830 | + } |
|
831 | + if (dns_get_record ( $dom , DNS_A )) { |
|
832 | + return nsdom( ltrim(strstr($dom, '.'), '.') ); |
|
833 | + } |
|
787 | 834 | return NULL; |
788 | 835 | } |
789 | 836 | |
790 | 837 | function isValid($dom) { |
791 | 838 | /* Return TRUE id domain has NS or A record */ |
792 | 839 | if (preg_match('/^(?!:\/\/)([a-zA-Z0-9-]+\.){0,5}[a-zA-Z0-9-][a-zA-Z0-9-]+\.[a-zA-Z]{2,64}?\.{0,1}$/i',$dom) === 1) { |
793 | - if (checkdnsrr ( $dom , 'NS' )) |
|
794 | - return TRUE; |
|
795 | - if (checkdnsrr ( $dom , 'A' )) |
|
796 | - return TRUE; |
|
840 | + if (checkdnsrr ( $dom , 'NS' )) { |
|
841 | + return TRUE; |
|
842 | + } |
|
843 | + if (checkdnsrr ( $dom , 'A' )) { |
|
844 | + return TRUE; |
|
845 | + } |
|
797 | 846 | } |
798 | 847 | return FALSE; |
799 | 848 | } |