@@ -10,21 +10,25 @@ discard block |
||
10 | 10 | if ( preg_match_all('/^Received:\sfrom(?:.|\r\n\s)*?[\[\(]\s*(?P<ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})[\]\)](?:.|\r\n\s)+\s+by(?:\s|\r\n\s+)(?P<host>\S+).*(?:\s|\r\n\s\s)+.*;\s+(?P<date>.*)/m',$header,$received) ) { |
11 | 11 | for ($i = count($received[0])-1;$i>=0;$i--) { |
12 | 12 | # print "Examine ".$received[0][$i]."\n"; |
13 | - if ( preg_match($msa,$received['host'][$i]) ) |
|
14 | - $dateR = $received['date'][$i]; |
|
13 | + if ( preg_match($msa,$received['host'][$i]) ) { |
|
14 | + $dateR = $received['date'][$i]; |
|
15 | + } |
|
15 | 16 | foreach ($mxserver as $mx) { |
16 | - if (!$ip) |
|
17 | - if ($mx == $received['host'][$i]) { |
|
17 | + if (!$ip) { |
|
18 | + if ($mx == $received['host'][$i]) { |
|
18 | 19 | $host = $received['host'][$i]; |
20 | + } |
|
19 | 21 | $ip = $received['ip'][$i]; |
20 | 22 | } |
21 | 23 | } |
22 | 24 | } |
23 | 25 | } |
24 | - if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$dateC) != 1) |
|
25 | - $dateC['date'] = 'Not found'; |
|
26 | - if ( preg_match ('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/',$header,$mid) != 1) |
|
27 | - $mid['mid'] = NULL; |
|
26 | + if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$dateC) != 1) { |
|
27 | + $dateC['date'] = 'Not found'; |
|
28 | + } |
|
29 | + if ( preg_match ('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/',$header,$mid) != 1) { |
|
30 | + $mid['mid'] = NULL; |
|
31 | + } |
|
28 | 32 | return array($ip,$host,$dateR,$dateC['date'],$mid['mid']); |
29 | 33 | } |
30 | 34 | |
@@ -40,7 +44,9 @@ discard block |
||
40 | 44 | |
41 | 45 | function summaryBadReport ($uidvet) { |
42 | 46 | $nuid = $uidvet['count']; |
43 | - if ( empty($uidvet) ) return NULL; |
|
47 | + if ( empty($uidvet) ) { |
|
48 | + return NULL; |
|
49 | + } |
|
44 | 50 | $return = '<hr><h3>Statistics by UID</h3><table><tr><th>UID</th><th>Learned times</th></tr>'."\n"; |
45 | 51 | |
46 | 52 | /* Remove count index */ |
@@ -75,8 +81,12 @@ discard block |
||
75 | 81 | foreach ($colarr as $col => $arr) { |
76 | 82 | foreach ($arr as $k => $v) { |
77 | 83 | $k = substr($k,1); |
78 | - if (!isset($ret[$k])) $ret[$k] = $array[$k]; |
|
79 | - if (isset ($array[$k][$col])) $ret[$k][$col] = $array[$k][$col]; |
|
84 | + if (!isset($ret[$k])) { |
|
85 | + $ret[$k] = $array[$k]; |
|
86 | + } |
|
87 | + if (isset ($array[$k][$col])) { |
|
88 | + $ret[$k][$col] = $array[$k][$col]; |
|
89 | + } |
|
80 | 90 | } |
81 | 91 | } |
82 | 92 | return $ret; |
@@ -87,13 +97,17 @@ discard block |
||
87 | 97 | function summaryReportAndList ($cf,$myconn,$tables,$category,$ipvet) { |
88 | 98 | $nips = $ipvet['count']; |
89 | 99 | |
90 | - if ( empty($ipvet) ) return NULL; |
|
100 | + if ( empty($ipvet) ) { |
|
101 | + return NULL; |
|
102 | + } |
|
91 | 103 | $return = '<h3>Statistics by IP</h3><table><tr><th>IP</th><th>Learned by</th><th>Learned times</th><th title="This field doesn\'t say if this ip is currently listed, but it says if this IP has listed now!">Listed Now</th></tr>'."\n"; |
92 | 104 | |
93 | 105 | $ips = array_keys($ipvet['ip']); |
94 | 106 | |
95 | 107 | foreach ( $ips as $ip ) { |
96 | - if ( $ip == 'count' ) continue; |
|
108 | + if ( $ip == 'count' ) { |
|
109 | + continue; |
|
110 | + } |
|
97 | 111 | $nlearn = $ipvet['ip']["$ip"]['count']; |
98 | 112 | unset($ipvet['ip']["$ip"]['count']); |
99 | 113 | $quantity = $cf['quantity']["$category"]; /* In searchAndList this value is passed by reference and modified */ |
@@ -102,10 +116,12 @@ discard block |
||
102 | 116 | if ( ($nlearn >= $cf['thresholdip']["$category"])&&($nuid >= $cf['thresholduid']["$category"]) ) { |
103 | 117 | $reason = "The IP <$ip> has been listed because was marked $nlearn times as $category by $nuid different accounts during last ".$cf['oldestday'].' days.'; |
104 | 118 | $listed = searchAndList ($myconn,$cf['user'],$tables,$cf['list']["$category"],$ip,$cf['unit']["$category"],$quantity,$reason); |
119 | + } else { |
|
120 | + $listed = FALSE; |
|
105 | 121 | } |
106 | - else $listed = FALSE; |
|
122 | + } else { |
|
123 | + $listed = FALSE; |
|
107 | 124 | } |
108 | - else $listed = FALSE; |
|
109 | 125 | $nowlist = array( TRUE => array( |
110 | 126 | 'style' => 'id=\'ipfound\'', |
111 | 127 | 'name' => 'YES', |
@@ -123,7 +139,9 @@ discard block |
||
123 | 139 | $return .='<tr><td rowspan="'.$nuid.'">'.$ip.'</td>'; |
124 | 140 | $return .= sprintf ('<td>%s</td><td rowspan="'.$nuid.'">%u</td><td rowspan="'.$nuid.'" '.$nowlist["$listed"]['style'].'>%s</td></tr>',$ipvet['ip']["$ip"][0],$nlearn,$nowlist["$listed"]['name']); |
125 | 141 | $rowuid=NULL; |
126 | - for ($j=1;$j<$nuid;$j++) $rowuid .= '<tr><td>%s</td></tr>'; |
|
142 | + for ($j=1;$j<$nuid;$j++) { |
|
143 | + $rowuid .= '<tr><td>%s</td></tr>'; |
|
144 | + } |
|
127 | 145 | array_shift($ipvet['ip']["$ip"]); |
128 | 146 | $return .= vsprintf ($rowuid,$ipvet['ip']["$ip"]); |
129 | 147 | |
@@ -136,14 +154,18 @@ discard block |
||
136 | 154 | $return .= '<h3>Statistics by UID</h3><table><tr><th>UID</th><th>IP learned</th><th>Learned times</th></tr>'."\n"; |
137 | 155 | $uids = array_keys($ipvet['uid']); |
138 | 156 | foreach ( $uids as $uid ) { |
139 | - if ( $uid == 'count' ) continue; |
|
157 | + if ( $uid == 'count' ) { |
|
158 | + continue; |
|
159 | + } |
|
140 | 160 | $nlearn = $ipvet['uid']["$uid"]['count']; |
141 | 161 | unset ( $ipvet['uid']["$uid"]['count'] ); |
142 | 162 | $nip = count($ipvet['uid']["$uid"]); |
143 | 163 | $return .='<tr><td rowspan="'.$nip.'">'.$uid.'</td>'; |
144 | 164 | $return .= sprintf ('<td>%s</td><td rowspan="'.$nip.'">%u</td></tr>',$ipvet['uid']["$uid"][0],$nlearn); |
145 | 165 | $rowuid=NULL; |
146 | - for ($j=1;$j<$nip;$j++) $rowuid .= '<tr><td>%s</td></tr>'; |
|
166 | + for ($j=1;$j<$nip;$j++) { |
|
167 | + $rowuid .= '<tr><td>%s</td></tr>'; |
|
168 | + } |
|
147 | 169 | array_shift($ipvet['uid']["$uid"]); |
148 | 170 | $return .= vsprintf ($rowuid,$ipvet['uid']["$uid"]); |
149 | 171 | |
@@ -192,14 +214,14 @@ discard block |
||
192 | 214 | { |
193 | 215 | // More than one field attribute returned by search |
194 | 216 | // You must redefine the search |
195 | - if ( count($result->getFieldNames()) > 1 ) return FALSE; |
|
196 | - } |
|
197 | - else if ($result instanceof Splunk_ResultsMessage) |
|
217 | + if ( count($result->getFieldNames()) > 1 ) { |
|
218 | + return FALSE; |
|
219 | + } |
|
220 | + } else if ($result instanceof Splunk_ResultsMessage) |
|
198 | 221 | { |
199 | 222 | // I don't want messages in my search |
200 | 223 | return FALSE; |
201 | - } |
|
202 | - else if (is_array($result)) |
|
224 | + } else if (is_array($result)) |
|
203 | 225 | { |
204 | 226 | // Process a row |
205 | 227 | foreach ($result as $key => $valueOrValues) |
@@ -207,15 +229,13 @@ discard block |
||
207 | 229 | if (is_array($valueOrValues)) |
208 | 230 | { |
209 | 231 | return FALSE; |
210 | - } |
|
211 | - else |
|
232 | + } else |
|
212 | 233 | { |
213 | 234 | return $valueOrValues; |
214 | 235 | #print " {$key} => {$value}\r\n"; |
215 | 236 | } |
216 | 237 | } |
217 | - } |
|
218 | - else |
|
238 | + } else |
|
219 | 239 | { |
220 | 240 | #print "Unknow result type"; |
221 | 241 | return FALSE; |
@@ -229,7 +249,9 @@ discard block |
||
229 | 249 | $fileb= dirname(__FILE__) . '/' . $cf['badreportFile']["$type"]; |
230 | 250 | $m_mail = imap_open('{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}'.$cf['folder']["$type"], $cf['account'],$cf['authpassword'], OP_READONLY) |
231 | 251 | or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); |
232 | - if ( !$m_mail ) exit(254); |
|
252 | + if ( !$m_mail ) { |
|
253 | + exit(254); |
|
254 | + } |
|
233 | 255 | |
234 | 256 | |
235 | 257 | syslog (LOG_INFO,$cf['user'].': Successfully connected to <'.$cf['mailhost'].">; Reading $type messages of last ".$cf['oldestday'].' days...'); |
@@ -242,20 +264,28 @@ discard block |
||
242 | 264 | // Order results starting from newest message |
243 | 265 | if ( empty($m_search) ) { |
244 | 266 | syslog (LOG_INFO,$cf['user'].": No mail found in $type folder. No reports written for $type."); |
245 | - if ( $ierr = imap_errors() ) |
|
246 | - foreach ( $ierr as $thiserr ) |
|
267 | + if ( $ierr = imap_errors() ) { |
|
268 | + foreach ( $ierr as $thiserr ) |
|
247 | 269 | syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); |
248 | - if ( $ierr = imap_alerts() ) |
|
249 | - foreach ( $ierr as $thiserr ) |
|
270 | + } |
|
271 | + if ( $ierr = imap_alerts() ) { |
|
272 | + foreach ( $ierr as $thiserr ) |
|
250 | 273 | syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); |
274 | + } |
|
251 | 275 | imap_close( $m_mail ); |
252 | - if ( file_exists( $file ) ) unlink ($file); |
|
253 | - if ( file_exists( $fileb ) ) unlink ($fileb); |
|
276 | + if ( file_exists( $file ) ) { |
|
277 | + unlink ($file); |
|
278 | + } |
|
279 | + if ( file_exists( $fileb ) ) { |
|
280 | + unlink ($fileb); |
|
281 | + } |
|
254 | 282 | return FALSE; |
255 | 283 | } |
256 | 284 | $nmes = count ($m_search); |
257 | 285 | syslog (LOG_INFO,$cf['user'].": Found $nmes mail in $type folder."); |
258 | - if ($nmes>0) rsort($m_search); |
|
286 | + if ($nmes>0) { |
|
287 | + rsort($m_search); |
|
288 | + } |
|
259 | 289 | |
260 | 290 | // Create report file |
261 | 291 | |
@@ -264,7 +294,9 @@ discard block |
||
264 | 294 | $lastup = "Last Update: " . date ("d F Y H:i", time()); |
265 | 295 | fwrite( $fp, file_get_contents(dirname(__FILE__) . '/' . $cf['reportTemplateHeader']) ); |
266 | 296 | fwrite( $fp,"<h1> Report of IP sending $type</h1><h5>$lastup</h5><h2>Detailed Report</h2>" ); |
267 | - if ($cf['onlyReport']) fwrite( $fp,'<p>None of the below IP has been listed because listing is not active in configuration.</p>'); |
|
297 | + if ($cf['onlyReport']) { |
|
298 | + fwrite( $fp,'<p>None of the below IP has been listed because listing is not active in configuration.</p>'); |
|
299 | + } |
|
268 | 300 | fwrite( $fp,'<table><tr><th title="taken from Received header" nowrap>Date of Learn</th><th title="taken from Date header" nowrap>Date of Write</th><th nowrap>UID</th><th nowrap>IP</th><th title="How many times this uid learns">#UID</th><th title="Number of times this learned IP appears in different mails">#IP</th><th nowrap>Received by</th><th>Message-Id</th></tr>' ); |
269 | 301 | fwrite( $fpb,file_get_contents(dirname(__FILE__) . '/' . $cf['reportTemplateHeader']) ); |
270 | 302 | fwrite( $fpb,"<h1> Report of bad reported $type mails</h1><h5>$lastup</h5><h2>Detailed Report</h2>" ); |
@@ -310,10 +342,11 @@ discard block |
||
310 | 342 | |
311 | 343 | if (in_array($uid,array_keys($ipuid['uid']))) { |
312 | 344 | $ipuid['uid']["$uid"]['count']++; //number of learn by this uid |
313 | - if (!in_array($ip,$ipuid['uid']["$uid"])) |
|
314 | - $ipuid['uid']["$uid"][]=$ip; //ips learned by this uid |
|
315 | - } |
|
316 | - else { |
|
345 | + if (!in_array($ip,$ipuid['uid']["$uid"])) { |
|
346 | + $ipuid['uid']["$uid"][]=$ip; |
|
347 | + } |
|
348 | + //ips learned by this uid |
|
349 | + } else { |
|
317 | 350 | $ipuid['uid']["$uid"]['count'] = 1; |
318 | 351 | $ipuid['uid']["$uid"][]=$ip; |
319 | 352 | $ipuid['uid']['count']++; //number of unique uids |
@@ -321,10 +354,11 @@ discard block |
||
321 | 354 | |
322 | 355 | if (in_array($ip,array_keys($ipuid['ip']))) { |
323 | 356 | $ipuid['ip']["$ip"]['count']++; //number of time this ip appears in different messages |
324 | - if (!in_array($uid,$ipuid['ip']["$ip"])) |
|
325 | - $ipuid['ip']["$ip"][]=$uid; //uids that learned this ip |
|
326 | - } |
|
327 | - else { |
|
357 | + if (!in_array($uid,$ipuid['ip']["$ip"])) { |
|
358 | + $ipuid['ip']["$ip"][]=$uid; |
|
359 | + } |
|
360 | + //uids that learned this ip |
|
361 | + } else { |
|
328 | 362 | $ipuid['ip']["$ip"]['count'] = 1; |
329 | 363 | $ipuid['ip']["$ip"][]=$uid; |
330 | 364 | $ipuid['ip']['count']++; //number of unique ips |
@@ -332,21 +366,30 @@ discard block |
||
332 | 366 | |
333 | 367 | /* Update HTML report */ |
334 | 368 | fwrite($fp,updateReport ( $ip,$uid,$ipuid['ip']["$ip"]['count'],$ipuid['uid']["$uid"]['count'],$host,$dateClient,$mid,$dateReceived) ); |
335 | - } |
|
336 | - else { /* Bad learn */ |
|
369 | + } else { /* Bad learn */ |
|
337 | 370 | |
338 | - if (in_array($uid,array_keys($uidbad['uid']))) |
|
339 | - $uidbad['uid']["$uid"]['count']++; //number of bad learn by this uid |
|
371 | + if (in_array($uid,array_keys($uidbad['uid']))) { |
|
372 | + $uidbad['uid']["$uid"]['count']++; |
|
373 | + } |
|
374 | + //number of bad learn by this uid |
|
340 | 375 | else { |
341 | 376 | $uidbad['uid']["$uid"]['count'] = 1; |
342 | 377 | $uidbad['uid']["$uid"][]=$uid; |
343 | 378 | $uidbad['count']++; //numeber of unique bad uids |
344 | 379 | } |
345 | 380 | /* The reason of bad report */ |
346 | - if ($host === FALSE) $reason = 'This mail was not received by recognized MX host'; |
|
347 | - if ($dateReceived === FALSE) $reason = 'This mail was not submitted to recognized MSA for learn'; |
|
348 | - if ($uid=='unknown') $reason = 'The uid of this mail was not found in splunk log'; |
|
349 | - if (!isset($reason)) $reason = '?'; |
|
381 | + if ($host === FALSE) { |
|
382 | + $reason = 'This mail was not received by recognized MX host'; |
|
383 | + } |
|
384 | + if ($dateReceived === FALSE) { |
|
385 | + $reason = 'This mail was not submitted to recognized MSA for learn'; |
|
386 | + } |
|
387 | + if ($uid=='unknown') { |
|
388 | + $reason = 'The uid of this mail was not found in splunk log'; |
|
389 | + } |
|
390 | + if (!isset($reason)) { |
|
391 | + $reason = '?'; |
|
392 | + } |
|
350 | 393 | |
351 | 394 | fwrite( $fpb,updatebadReport ( $uid,$dateClient,$mid,$dateReceived,$reason ) ); |
352 | 395 | } |
@@ -364,9 +407,9 @@ discard block |
||
364 | 407 | fwrite($fp, '<hr><h2>Summary Report</h2><h5>Listing policy: ip must be learned at least '.$cf['thresholdip']["$type"].' times from at least '.$cf['thresholduid']["$type"].' different valid uids.</h5>' ); |
365 | 408 | |
366 | 409 | /* Make MYSQL connection */ |
367 | - if ( $cf['onlyReport'] ) |
|
368 | - $mysqli = NULL; |
|
369 | - else { |
|
410 | + if ( $cf['onlyReport'] ) { |
|
411 | + $mysqli = NULL; |
|
412 | + } else { |
|
370 | 413 | $mysqli = new mysqli($myconnArray['dbhost'], $myconnArray['userdb'], $myconnArray['pwd'], $myconnArray['db'], $myconnArray['dbport']); |
371 | 414 | if ($mysqli->connect_error) { |
372 | 415 | syslog (LOG_EMERG, $cf['user'].': Connect Error (' . $mysqli->connect_errno . ') ' |
@@ -378,8 +421,9 @@ discard block |
||
378 | 421 | /***********************/ |
379 | 422 | |
380 | 423 | fwrite($fp, summaryReportAndList ($cf,$mysqli,$tables,$type,$ipuid) ); |
381 | - if ( !$cf['onlyReport'] ) |
|
382 | - $mysqli->close(); |
|
424 | + if ( !$cf['onlyReport'] ) { |
|
425 | + $mysqli->close(); |
|
426 | + } |
|
383 | 427 | fwrite($fp,file_get_contents(dirname(__FILE__) . '/' . $cf['reportTemplateFooter'])); |
384 | 428 | fclose($fp); |
385 | 429 | |
@@ -389,12 +433,14 @@ discard block |
||
389 | 433 | fclose($fpb); |
390 | 434 | syslog (LOG_INFO,$cf['user'].': Report files written. Listing job for '.$type.' terminated.'); |
391 | 435 | |
392 | - if ( $ierr = imap_errors() ) |
|
393 | - foreach ( $ierr as $thiserr ) |
|
436 | + if ( $ierr = imap_errors() ) { |
|
437 | + foreach ( $ierr as $thiserr ) |
|
394 | 438 | syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); |
395 | - if ( $ierr = imap_alerts() ) |
|
396 | - foreach ( $ierr as $thiserr ) |
|
439 | + } |
|
440 | + if ( $ierr = imap_alerts() ) { |
|
441 | + foreach ( $ierr as $thiserr ) |
|
397 | 442 | syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); |
443 | + } |
|
398 | 444 | imap_close($m_mail); |
399 | 445 | } |
400 | 446 | ?> |
@@ -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>'; |
@@ -5,32 +5,39 @@ discard block |
||
5 | 5 | $net = new \dautkom\ipv4\IPv4(); |
6 | 6 | |
7 | 7 | $_ = $_POST['genere']; |
8 | -if ( ($tables["$_"]['field']=='email') AND ($_POST['Value']!='ALL') ) |
|
8 | +if ( ($tables["$_"]['field']=='email') AND ($_POST['Value']!='ALL') ) { |
|
9 | 9 | if (!(filter_var($_POST['Value'], FILTER_VALIDATE_EMAIL))) |
10 | 10 | exit ('<pre><'.$_POST['Value'].'> is NOT a valid email address.</pre>'); |
11 | +} |
|
11 | 12 | |
12 | -if ( ($tables["$_"]['field']=='domain') AND ($_POST['Value']!='ALL') ) |
|
13 | +if ( ($tables["$_"]['field']=='domain') AND ($_POST['Value']!='ALL') ) { |
|
13 | 14 | if (!(filter_var(gethostbyname($_POST['Value']), FILTER_VALIDATE_IP))) |
14 | 15 | exit ('<pre><'.$_POST['Value'].'> is NOT a valid domain.</pre>'); |
16 | +} |
|
15 | 17 | |
16 | -if ( ($tables["$_"]['field']=='ip') AND ($_POST['Value']!='ALL') ) |
|
18 | +if ( ($tables["$_"]['field']=='ip') AND ($_POST['Value']!='ALL') ) { |
|
17 | 19 | if (!(filter_var($_POST['Value'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4))) |
18 | 20 | exit ('<pre><'.$_POST['Value'].'> is NOT a valid IP address.</pre>'); |
21 | +} |
|
19 | 22 | |
20 | 23 | if ( ($tables["$_"]['field']=='network') AND ($_POST['Value']!='ALL') ) { |
21 | 24 | $value = explode('/',$_POST['Value']); |
22 | - if (count($value) != 2) |
|
23 | - exit ('<pre><'.$_POST['Value'].'> is NOT a valid Network/Netmask pair.</pre>'); |
|
24 | - if (!$net->address($value[0])->mask($value[1])->isValid(1)) |
|
25 | - exit ('<pre><'.$_POST['Value'].'> is NOT a valid Network/Netmask.</pre>'); |
|
25 | + if (count($value) != 2) { |
|
26 | + exit ('<pre><'.$_POST['Value'].'> is NOT a valid Network/Netmask pair.</pre>'); |
|
27 | + } |
|
28 | + if (!$net->address($value[0])->mask($value[1])->isValid(1)) { |
|
29 | + exit ('<pre><'.$_POST['Value'].'> is NOT a valid Network/Netmask.</pre>'); |
|
30 | + } |
|
26 | 31 | $_POST['Value'] = $value[0].'/'.$net->mask($value[1])->convertTo('dec'); |
27 | 32 | } |
28 | 33 | |
29 | 34 | if ( ($tables["$_"]['field']=='username') AND ($_POST['Value']!='ALL') ) { |
30 | - if ( preg_match( '/[^\x20-\x7f]/', $_POST['Value']) ) |
|
31 | - exit('<pre><'.$_POST['Value'].'> contains NON ASCII chars.</pre>'); |
|
32 | - if ( preg_match( '/[$~=#*+%,{}()\/\\<>;:\"`\[\]&?\s]/', $_POST['Value']) ) |
|
33 | - exit('<pre><'.$_POST['Value'].'> contains invalid ASCII chars.</pre>'); |
|
35 | + if ( preg_match( '/[^\x20-\x7f]/', $_POST['Value']) ) { |
|
36 | + exit('<pre><'.$_POST['Value'].'> contains NON ASCII chars.</pre>'); |
|
37 | + } |
|
38 | + if ( preg_match( '/[$~=#*+%,{}()\/\\<>;:\"`\[\]&?\s]/', $_POST['Value']) ) { |
|
39 | + exit('<pre><'.$_POST['Value'].'> contains invalid ASCII chars.</pre>'); |
|
40 | + } |
|
34 | 41 | switch ( $_POST['Value'] ) { |
35 | 42 | case 'anonymous': |
36 | 43 | case 'anybody': |
@@ -41,18 +48,23 @@ discard block |
||
41 | 48 | } |
42 | 49 | |
43 | 50 | if (empty($_GET)) { |
44 | - if ($tables["$_"]['milter']) print "<p><i>$_</i> is a miltermap of ".$tables["$_"]['field'].'.</p>'; |
|
45 | - else { |
|
46 | - if ($tables["$_"]['bl']) print "<p><i>$_</i> is a blocklist of ".$tables["$_"]['field'].'.</p>'; |
|
47 | - else print "<p><i>$_</i> is a whitelist of ".$tables["$_"]['field'].'.</p>'; |
|
51 | + if ($tables["$_"]['milter']) { |
|
52 | + print "<p><i>$_</i> is a miltermap of ".$tables["$_"]['field'].'.</p>'; |
|
53 | + } else { |
|
54 | + if ($tables["$_"]['bl']) { |
|
55 | + print "<p><i>$_</i> is a blocklist of ".$tables["$_"]['field'].'.</p>'; |
|
56 | + } else { |
|
57 | + print "<p><i>$_</i> is a whitelist of ".$tables["$_"]['field'].'.</p>'; |
|
58 | + } |
|
48 | 59 | } |
49 | 60 | } |
50 | 61 | |
51 | 62 | openlog($tag, LOG_PID, $fac); |
52 | 63 | $user = username(); |
53 | 64 | |
54 | -if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $_, $user)) === FALSE ) |
|
65 | +if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $_, $user)) === FALSE ) { |
|
55 | 66 | exit ('Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
67 | +} |
|
56 | 68 | |
57 | 69 | rlookup($mysqli,username(),$admins,$_POST['Value'],$_POST['genere'],$tables); |
58 | 70 | $mysqli->close(); |
@@ -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 | ?> |
@@ -3,9 +3,13 @@ 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 | |
@@ -89,8 +93,9 @@ discard block |
||
89 | 93 | if ($myconn->query($query) === TRUE) { |
90 | 94 | syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit."); |
91 | 95 | $result=TRUE; |
96 | + } else { |
|
97 | + syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
|
92 | 98 | } |
93 | - else syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
|
94 | 99 | return $result; |
95 | 100 | } |
96 | 101 | |
@@ -131,8 +136,9 @@ discard block |
||
131 | 136 | if ($myconn->query($query) === TRUE) { |
132 | 137 | syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit."); |
133 | 138 | $result=TRUE; |
139 | + } else { |
|
140 | + syslog (LOG_ERR, "$user: Error: ". $myconn->error); |
|
134 | 141 | } |
135 | - else syslog (LOG_ERR, "$user: Error: ". $myconn->error); |
|
136 | 142 | return $result; |
137 | 143 | } |
138 | 144 | |
@@ -155,9 +161,11 @@ discard block |
||
155 | 161 | } |
156 | 162 | |
157 | 163 | |
158 | - if ($return=$myconn->query($query) === TRUE) |
|
159 | - syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>."); |
|
160 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
164 | + if ($return=$myconn->query($query) === TRUE) { |
|
165 | + syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>."); |
|
166 | + } else { |
|
167 | + syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
168 | + } |
|
161 | 169 | |
162 | 170 | return $return; |
163 | 171 | } |
@@ -179,8 +187,9 @@ discard block |
||
179 | 187 | |
180 | 188 | if ($return=$myconn->query($query) === TRUE) { |
181 | 189 | syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>"); |
190 | + } else { |
|
191 | + syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
182 | 192 | } |
183 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
184 | 193 | return $return; |
185 | 194 | } |
186 | 195 | |
@@ -204,14 +213,16 @@ discard block |
||
204 | 213 | $j++; |
205 | 214 | |
206 | 215 | } while ($myconn->next_result()); |
207 | - } |
|
208 | - else { |
|
216 | + } else { |
|
209 | 217 | syslog(LOG_ERR, "Expire job - Error: ". $myconn->error); |
210 | 218 | $return = FALSE; |
211 | 219 | } |
212 | 220 | } |
213 | - if ( !($return) ) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); |
|
214 | - else syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.'); |
|
221 | + if ( !($return) ) { |
|
222 | + syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); |
|
223 | + } else { |
|
224 | + syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.'); |
|
225 | + } |
|
215 | 226 | return $return; |
216 | 227 | } |
217 | 228 | |
@@ -220,8 +231,11 @@ discard block |
||
220 | 231 | |
221 | 232 | $exp=new DateTime($row['exp']); |
222 | 233 | $now=new DateTime('NOW'); |
223 | - if (($exp > $now) and ($row['active'])) return true; |
|
224 | - else return false; |
|
234 | + if (($exp > $now) and ($row['active'])) { |
|
235 | + return true; |
|
236 | + } else { |
|
237 | + return false; |
|
238 | + } |
|
225 | 239 | |
226 | 240 | } |
227 | 241 | |
@@ -241,10 +255,11 @@ discard block |
||
241 | 255 | END; |
242 | 256 | $activeMilts = explode(',',$value); |
243 | 257 | foreach ( $milts as $milter ) { |
244 | - if ( in_array($milter, $activeMilts) ) |
|
245 | - $selected= 'selected'; |
|
246 | - else |
|
247 | - $selected= NULL; |
|
258 | + if ( in_array($milter, $activeMilts) ) { |
|
259 | + $selected= 'selected'; |
|
260 | + } else { |
|
261 | + $selected= NULL; |
|
262 | + } |
|
248 | 263 | $button .= sprintf('<option value="%s" %s>%s</option>', $milter, $selected, $milter); |
249 | 264 | } |
250 | 265 | $button .= '</select></div><input class="button" name="Change" type="submit" value="Change" /></form>'; |
@@ -261,9 +276,12 @@ discard block |
||
261 | 276 | $whynot=NULL; |
262 | 277 | switch ($what) { |
263 | 278 | case 'Ok': |
264 | - if ($lock) return NULL; |
|
265 | - if (in_array($user,array_keys($adm))) |
|
266 | - if ( consistentListing($myconn,$alltables,$typedesc,$value,$whynot) ) return require('relistButton.php'); |
|
279 | + if ($lock) { |
|
280 | + return NULL; |
|
281 | + } |
|
282 | + if (in_array($user,array_keys($adm))) { |
|
283 | + if ( consistentListing($myconn,$alltables,$typedesc,$value,$whynot) ) return require('relistButton.php'); |
|
284 | + } |
|
267 | 285 | return htmlspecialchars($whynot); |
268 | 286 | case 'Listed': |
269 | 287 | case 'WhiteListed': |
@@ -275,7 +293,9 @@ discard block |
||
275 | 293 | function consistentListing($myconn,$alltables,$typed,$value,&$warn) { |
276 | 294 | /* Check if there are no pending mislisting */ |
277 | 295 | $warn = NULL; |
278 | - if (! isset($alltables["$typed"]['depend']) ) return TRUE; |
|
296 | + if (! isset($alltables["$typed"]['depend']) ) { |
|
297 | + return TRUE; |
|
298 | + } |
|
279 | 299 | foreach ($alltables["$typed"]['depend'] as $listdep) { |
280 | 300 | if ($alltables["$typed"]['field'] != $alltables["$listdep"]['field'] ) { |
281 | 301 | $warn = "Config ERROR: <$typed> and <$listdep> are of different types! I can't check consistency!"; |
@@ -306,10 +326,10 @@ discard block |
||
306 | 326 | |
307 | 327 | if ( $tablelist['milter'] ) { |
308 | 328 | $table = milterTable($type); |
309 | - if ($value == 'ALL') |
|
310 | - $query = sprintf('SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id) GROUP by idmilt', |
|
329 | + if ($value == 'ALL') { |
|
330 | + $query = sprintf('SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id) GROUP by idmilt', |
|
311 | 331 | $table,$table); |
312 | - else { |
|
332 | + } else { |
|
313 | 333 | switch ($type) { |
314 | 334 | case 'network': |
315 | 335 | list($sub['net'],$sub['mask'])=explode('/',$value); |
@@ -334,12 +354,11 @@ discard block |
||
334 | 354 | return FALSE; |
335 | 355 | } |
336 | 356 | } |
337 | - } |
|
338 | - |
|
339 | - else { |
|
357 | + } else { |
|
340 | 358 | $table = $tablelist['name']; |
341 | - if ($value == 'ALL') $query = 'select * from '.$table; |
|
342 | - else { |
|
359 | + if ($value == 'ALL') { |
|
360 | + $query = 'select * from '.$table; |
|
361 | + } else { |
|
343 | 362 | switch ($type) { |
344 | 363 | case 'ip': |
345 | 364 | $query= "select * from $table where $type = INET_ATON('$value')"; |
@@ -361,8 +380,9 @@ discard block |
||
361 | 380 | } |
362 | 381 | |
363 | 382 | $result = $myconn->query($query); |
364 | - if($result === false) |
|
365 | - syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error); |
|
383 | + if($result === false) { |
|
384 | + syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error); |
|
385 | + } |
|
366 | 386 | return $result; |
367 | 387 | } |
368 | 388 | |
@@ -379,12 +399,14 @@ discard block |
||
379 | 399 | |
380 | 400 | function isFull($myconn,$typedesc,$alltables) { |
381 | 401 | if (isset($alltables["$typedesc"]['limit'])) { |
382 | - if ( $alltables["$typedesc"]['milter'] ) |
|
383 | - $tab = 'net'; |
|
384 | - else |
|
385 | - $tab = $alltables["$typedesc"]['name']; |
|
386 | - if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) |
|
387 | - return TRUE; |
|
402 | + if ( $alltables["$typedesc"]['milter'] ) { |
|
403 | + $tab = 'net'; |
|
404 | + } else { |
|
405 | + $tab = $alltables["$typedesc"]['name']; |
|
406 | + } |
|
407 | + if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) { |
|
408 | + return TRUE; |
|
409 | + } |
|
388 | 410 | } |
389 | 411 | return FALSE; |
390 | 412 | } |
@@ -397,8 +419,9 @@ discard block |
||
397 | 419 | $tabhtm = <<<END |
398 | 420 | <table><thead><tr><th>$type</th><th title="The date this object has been listed for the first time">DateAdd</th><th>DateMod</th><th>Exp</th><th>Status</th><th title="Number of times this object has been listed">#List</th> |
399 | 421 | END; |
400 | - if ( $tables["$typedesc"]['milter'] ) |
|
401 | - $tabhtm .= '<th title="Milter active for this object">Milters</th>'; |
|
422 | + if ( $tables["$typedesc"]['milter'] ) { |
|
423 | + $tabhtm .= '<th title="Milter active for this object">Milters</th>'; |
|
424 | + } |
|
402 | 425 | $tabhtm .= '<th>Authored by</th><th width="250">Reason</th><th>Action</th></tr></thead><tfoot><tr></tr></tfoot><tbody>'."\n"; |
403 | 426 | |
404 | 427 | $result = searchentry ($myconn,$value,$tables["$typedesc"]); |
@@ -407,18 +430,23 @@ discard block |
||
407 | 430 | |
408 | 431 | /* Check for limit in number of listed items */ |
409 | 432 | $full = isFull($myconn,$typedesc,$tables); |
410 | - if ($full) print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>'; |
|
433 | + if ($full) { |
|
434 | + print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>'; |
|
435 | + } |
|
411 | 436 | |
412 | 437 | if ($result->num_rows) { |
413 | 438 | print $tabhtm; |
414 | 439 | $i=0; |
415 | 440 | while ($riga = $result->fetch_array(MYSQLI_ASSOC)) { |
416 | 441 | if (isListed($riga)) { |
417 | - if ($tables["$typedesc"]['bl']) $listed='Listed'; |
|
418 | - else $listed='WhiteListed'; |
|
419 | - } |
|
420 | - else |
|
421 | - $listed='Ok'; |
|
442 | + if ($tables["$typedesc"]['bl']) { |
|
443 | + $listed='Listed'; |
|
444 | + } else { |
|
445 | + $listed='WhiteListed'; |
|
446 | + } |
|
447 | + } else { |
|
448 | + $listed='Ok'; |
|
449 | + } |
|
422 | 450 | |
423 | 451 | switch ($type) { |
424 | 452 | case 'ip': |
@@ -431,27 +459,30 @@ discard block |
||
431 | 459 | $element = $riga["$type"]; |
432 | 460 | } |
433 | 461 | |
434 | - if ( $tables["$typedesc"]['milter'] AND checkMilterConf($tables["$typedesc"]) ) |
|
435 | - printf ("<tr id=id$i><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td nowrap id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td>%s</td></tr>\n", |
|
462 | + if ( $tables["$typedesc"]['milter'] AND checkMilterConf($tables["$typedesc"]) ) { |
|
463 | + printf ("<tr id=id$i><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td nowrap id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td>%s</td></tr>\n", |
|
436 | 464 | $element, $riga['date'], $riga['datemod'], $riga['exp'], $riga['active'], $riga['nlist'], askMilter($myconn,$i,$element,$typedesc,$riga['idmilt'],$riga['miltnames'],$user,$adm), $riga['user'],htmlspecialchars($riga['reason']),ask($myconn,$i,$listed,$tables,$typedesc,$element,$full,$user,$adm)); |
437 | - else |
|
438 | - printf ("<tr id=id$i><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td>%s</td></tr>\n", |
|
465 | + } else { |
|
466 | + printf ("<tr id=id$i><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td>%s</td></tr>\n", |
|
439 | 467 | $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)); |
468 | + } |
|
440 | 469 | $i++; |
441 | 470 | } |
442 | 471 | print '</tbody></table>'; |
443 | - } |
|
444 | - else { |
|
472 | + } else { |
|
445 | 473 | print "<pre>$type <$value> is not listed!\n</pre>"; |
446 | - if ( in_array($user,array_keys($adm)) AND ($value != 'ALL') ) |
|
447 | - if ( (!$full) AND (consistentListing($myconn,$tables,$typedesc,$value,$whynot)) ) require_once('listForm.php'); |
|
448 | - else print '<p>'.htmlspecialchars($whynot).'</p>'; |
|
474 | + if ( in_array($user,array_keys($adm)) AND ($value != 'ALL') ) { |
|
475 | + if ( (!$full) AND (consistentListing($myconn,$tables,$typedesc,$value,$whynot)) ) require_once('listForm.php'); |
|
476 | + } else { |
|
477 | + print '<p>'.htmlspecialchars($whynot).'</p>'; |
|
478 | + } |
|
449 | 479 | |
450 | 480 | } |
451 | 481 | $result->free(); |
482 | + } else { |
|
483 | + print '<pre>Query error or something wrong in DB schema'."\n</pre>"; |
|
484 | + } |
|
452 | 485 | } |
453 | - else print '<pre>Query error or something wrong in DB schema'."\n</pre>"; |
|
454 | -} |
|
455 | 486 | |
456 | 487 | |
457 | 488 | |
@@ -494,24 +525,32 @@ discard block |
||
494 | 525 | $old_mailfrom = ini_get("sendmail_from"); |
495 | 526 | ini_set("sendmail_from", $from); |
496 | 527 | $params = sprintf("-oi -f %s", '<>'); |
497 | - if (!(mail($to,$sbj, $body,$headers,$params))) $flag=FALSE; |
|
498 | - else $flag=TRUE; |
|
499 | - if (isset($old_mailfrom)) |
|
500 | - ini_set("sendmail_from", $old_mailfrom); |
|
501 | - } |
|
502 | - else { |
|
503 | - if (!(mail($to,$sbj, $body,$headers))) $flag=FALSE; |
|
504 | - else $flag=TRUE; |
|
528 | + if (!(mail($to,$sbj, $body,$headers,$params))) { |
|
529 | + $flag=FALSE; |
|
530 | + } else { |
|
531 | + $flag=TRUE; |
|
532 | + } |
|
533 | + if (isset($old_mailfrom)) { |
|
534 | + ini_set("sendmail_from", $old_mailfrom); |
|
535 | + } |
|
536 | + } else { |
|
537 | + if (!(mail($to,$sbj, $body,$headers))) { |
|
538 | + $flag=FALSE; |
|
539 | + } else { |
|
540 | + $flag=TRUE; |
|
541 | + } |
|
505 | 542 | } |
506 | 543 | return $flag; |
507 | 544 | } |
508 | 545 | |
509 | 546 | function emailToNotify($notify_file,$dom) { |
510 | 547 | $ini_array = parse_ini_file($notify_file); |
511 | - if (in_array($dom,array_keys($ini_array))) |
|
512 | - return $ini_array["$dom"]; |
|
513 | - else return FALSE; |
|
514 | -} |
|
548 | + if (in_array($dom,array_keys($ini_array))) { |
|
549 | + return $ini_array["$dom"]; |
|
550 | + } else { |
|
551 | + return FALSE; |
|
552 | + } |
|
553 | + } |
|
515 | 554 | |
516 | 555 | |
517 | 556 | function searchAndList ($myconn,$loguser,$tables,$typedesc,$value,$unit,&$quantity,$reason) { |
@@ -588,9 +627,10 @@ discard block |
||
588 | 627 | $net = new \dautkom\ipv4\IPv4(); |
589 | 628 | $range = $net->address($addressA)->mask($maskA)->getRange(); |
590 | 629 | $ips = ipRange($range); |
591 | - foreach ( $ips as $ip ) |
|
592 | - if ( $net->address($addressB)->mask($maskB)->has($ip) ) |
|
630 | + foreach ( $ips as $ip ) { |
|
631 | + if ( $net->address($addressB)->mask($maskB)->has($ip) ) |
|
593 | 632 | return TRUE; |
633 | + } |
|
594 | 634 | return FALSE; |
595 | 635 | } |
596 | 636 | |
@@ -667,8 +707,9 @@ discard block |
||
667 | 707 | return FALSE; |
668 | 708 | } |
669 | 709 | if ($result->num_rows) { |
670 | - while ($milt = $result->fetch_array(MYSQLI_ASSOC)) |
|
671 | - $milters[] = $milt['name']; |
|
710 | + while ($milt = $result->fetch_array(MYSQLI_ASSOC)) { |
|
711 | + $milters[] = $milt['name']; |
|
712 | + } |
|
672 | 713 | } |
673 | 714 | $result->free(); |
674 | 715 | return $milters; |
@@ -694,12 +735,14 @@ discard block |
||
694 | 735 | $query[] = "DELETE FROM `milt` WHERE (`id` = '$miltID' AND `name` = '$value')"; |
695 | 736 | } |
696 | 737 | } |
697 | - if ( count($query) ) /* This "if" is redundant, because if I call this I already checked there is a change */ |
|
738 | + if ( count($query) ) { |
|
739 | + /* This "if" is redundant, because if I call this I already checked there is a change */ |
|
698 | 740 | /* I update datemod because the user couldn't change */ |
699 | 741 | $query[] = sprintf('UPDATE `%s` SET |
700 | 742 | `user`=\'%s\', |
701 | 743 | `datemod`= CURRENT_TIMESTAMP |
702 | 744 | WHERE `idmilt`=%d', $table, $loguser, $miltID); |
745 | + } |
|
703 | 746 | |
704 | 747 | |
705 | 748 | /* Start a safe transaction: it commits only if all queries happen */ |
@@ -713,19 +756,20 @@ discard block |
||
713 | 756 | } |
714 | 757 | } |
715 | 758 | if ( $ok ) { |
716 | - if ( $myconn->commit() ) |
|
717 | - syslog(LOG_INFO, "$loguser: Milter setting changed successfully."); |
|
718 | - else { |
|
759 | + if ( $myconn->commit() ) { |
|
760 | + syslog(LOG_INFO, "$loguser: Milter setting changed successfully."); |
|
761 | + } else { |
|
719 | 762 | syslog(LOG_ERR, "$loguser: Milter setting NOT changed for an unpredictable COMMIT error."); |
720 | - if ( $myconn->rollback() ) |
|
721 | - syslog(LOG_INFO, "$loguser: rollback succeeded."); |
|
722 | - else |
|
723 | - syslog(LOG_ERR, "$loguser: rollback failed. Your db could be compromized. Check it!"); |
|
763 | + if ( $myconn->rollback() ) { |
|
764 | + syslog(LOG_INFO, "$loguser: rollback succeeded."); |
|
765 | + } else { |
|
766 | + syslog(LOG_ERR, "$loguser: rollback failed. Your db could be compromized. Check it!"); |
|
767 | + } |
|
724 | 768 | $ok = FALSE; |
725 | 769 | } |
770 | + } else { |
|
771 | + syslog(LOG_ERR, "$loguser: Error: Milter setting NOT changed. See at above errors."); |
|
726 | 772 | } |
727 | - else |
|
728 | - syslog(LOG_ERR, "$loguser: Error: Milter setting NOT changed. See at above errors."); |
|
729 | 773 | return $ok; |
730 | 774 | |
731 | 775 | } |
@@ -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']; |