@@ -26,8 +26,9 @@ |
||
| 26 | 26 | $user = username(); |
| 27 | 27 | $isAdmin = in_array($user,array_keys($admins)); |
| 28 | 28 | $canChange = ($isAdmin) ? '' : 'readonly'; |
| 29 | -if ( $require_auth ) |
|
| 29 | +if ( $require_auth ) { |
|
| 30 | 30 | if ( $user == 'unknown' ) exit ("<p>You MUST configure your server to use authentication.</p>"); |
| 31 | +} |
|
| 31 | 32 | |
| 32 | 33 | |
| 33 | 34 | print <<<END |
@@ -14,11 +14,12 @@ |
||
| 14 | 14 | $folders=imapFolder($conf['imap'], $_POST['username']); |
| 15 | 15 | if (is_array($folders)) { |
| 16 | 16 | print '<option value="" selected disabled>Choose a folder</option>'; |
| 17 | - foreach ( $folders as $folder ) |
|
| 18 | - printf('<option value="%s">%s</option>', |
|
| 17 | + foreach ( $folders as $folder ) { |
|
| 18 | + printf('<option value="%s">%s</option>', |
|
| 19 | 19 | $folder, |
| 20 | 20 | htmlspecialchars(mb_convert_encoding($folder, "UTF-8", "UTF7-IMAP"))); |
| 21 | -} |
|
| 21 | + } |
|
| 22 | + } |
|
| 22 | 23 | closelog(); |
| 23 | 24 | ?> |
| 24 | 25 | </select> |
@@ -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 (!(isValid($_POST['Value']))) |
| 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(); |
@@ -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,14 +97,18 @@ discard block |
||
| 87 | 97 | function summaryReportAndList ($cf,$myconn,$tables,$category,$vet,$key) { |
| 88 | 98 | $nk = $vet['count']; |
| 89 | 99 | |
| 90 | - if ( empty($vet) ) return NULL; |
|
| 100 | + if ( empty($vet) ) { |
|
| 101 | + return NULL; |
|
| 102 | + } |
|
| 91 | 103 | |
| 92 | 104 | $return = sprintf('<h3>Statistics by %s</h3><table><tr><th>%s</th><th>Learned by</th><th>Learned times</th><th title="This field doesn\'t say if this %s is currently listed, but it says if this %s has listed now!">Listed Now</th></tr>'."\n", strtoupper($key),strtoupper($key),$key,$key); |
| 93 | 105 | |
| 94 | 106 | $values = array_keys($vet["$key"]); |
| 95 | 107 | |
| 96 | 108 | foreach ( $values as $value ) { |
| 97 | - if ( $value == 'count' ) continue; |
|
| 109 | + if ( $value == 'count' ) { |
|
| 110 | + continue; |
|
| 111 | + } |
|
| 98 | 112 | $nlearn = $vet["$key"]["$value"]['count']; |
| 99 | 113 | unset($vet["$key"]["$value"]['count']); |
| 100 | 114 | $quantity = $cf["listing$key"]['quantity']["$category"]; /* In searchAndList this value is |
@@ -106,10 +120,12 @@ discard block |
||
| 106 | 120 | 'The %s <%s> has been listed because was marked %u times as %s by %u different accounts during last %u days.', |
| 107 | 121 | strtoupper($key),$value,$nlearn,$category,$nuid,$cf['imap']['oldestday']); |
| 108 | 122 | $listed = searchAndList ($myconn,$cf['syslog']['user'],$tables,$cf["listing$key"]['list']["$category"],$value,$cf["listing$key"]['unit']["$category"],$quantity,$reason); |
| 123 | + } else { |
|
| 124 | + $listed = FALSE; |
|
| 109 | 125 | } |
| 110 | - else $listed = FALSE; |
|
| 126 | + } else { |
|
| 127 | + $listed = FALSE; |
|
| 111 | 128 | } |
| 112 | - else $listed = FALSE; |
|
| 113 | 129 | $nowlist = array( TRUE => array( |
| 114 | 130 | 'style' => 'id=\'ipfound\'', |
| 115 | 131 | 'name' => 'YES', |
@@ -127,7 +143,9 @@ discard block |
||
| 127 | 143 | $return .='<tr><td rowspan="'.$nuid.'">'.$value.'</td>'; |
| 128 | 144 | $return .= sprintf ('<td>%s</td><td rowspan="'.$nuid.'">%u</td><td rowspan="'.$nuid.'" '.$nowlist["$listed"]['style'].'>%s</td></tr>',$vet["$key"]["$value"][0],$nlearn,$nowlist["$listed"]['name']); |
| 129 | 145 | $rowuid=NULL; |
| 130 | - for ($j=1;$j<$nuid;$j++) $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 146 | + for ($j=1;$j<$nuid;$j++) { |
|
| 147 | + $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 148 | + } |
|
| 131 | 149 | array_shift($vet["$key"]["$value"]); |
| 132 | 150 | $return .= vsprintf ($rowuid,$vet["$key"]["$value"]); |
| 133 | 151 | |
@@ -140,14 +158,18 @@ discard block |
||
| 140 | 158 | $return .= sprintf('<h3>Statistics by UID</h3><table><tr><th>UID</th><th>%s learned</th><th>Learned times</th></tr>'."\n",$key); |
| 141 | 159 | $uids = array_keys($vet['uid']); |
| 142 | 160 | foreach ( $uids as $uid ) { |
| 143 | - if ( $uid == 'count' ) continue; |
|
| 161 | + if ( $uid == 'count' ) { |
|
| 162 | + continue; |
|
| 163 | + } |
|
| 144 | 164 | $nlearn = $vet['uid']["$uid"]['count']; |
| 145 | 165 | unset ( $vet['uid']["$uid"]['count'] ); |
| 146 | 166 | $nip = count($vet['uid']["$uid"]); |
| 147 | 167 | $return .='<tr><td rowspan="'.$nip.'">'.$uid.'</td>'; |
| 148 | 168 | $return .= sprintf ('<td>%s</td><td rowspan="'.$nip.'">%u</td></tr>',$vet['uid']["$uid"][0],$nlearn); |
| 149 | 169 | $rowuid=NULL; |
| 150 | - for ($j=1;$j<$nip;$j++) $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 170 | + for ($j=1;$j<$nip;$j++) { |
|
| 171 | + $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 172 | + } |
|
| 151 | 173 | array_shift($vet['uid']["$uid"]); |
| 152 | 174 | $return .= vsprintf ($rowuid,$vet['uid']["$uid"]); |
| 153 | 175 | |
@@ -197,14 +219,14 @@ discard block |
||
| 197 | 219 | { |
| 198 | 220 | // More than one field attribute returned by search |
| 199 | 221 | // You must redefine the search |
| 200 | - if ( count($result->getFieldNames()) > 1 ) return FALSE; |
|
| 201 | - } |
|
| 202 | - else if ($result instanceof Splunk_ResultsMessage) |
|
| 222 | + if ( count($result->getFieldNames()) > 1 ) { |
|
| 223 | + return FALSE; |
|
| 224 | + } |
|
| 225 | + } else if ($result instanceof Splunk_ResultsMessage) |
|
| 203 | 226 | { |
| 204 | 227 | // I don't want messages in my search |
| 205 | 228 | return FALSE; |
| 206 | - } |
|
| 207 | - else if (is_array($result)) |
|
| 229 | + } else if (is_array($result)) |
|
| 208 | 230 | { |
| 209 | 231 | // Process a row |
| 210 | 232 | foreach ($result as $key => $valueOrValues) |
@@ -212,15 +234,13 @@ discard block |
||
| 212 | 234 | if (is_array($valueOrValues)) |
| 213 | 235 | { |
| 214 | 236 | return FALSE; |
| 215 | - } |
|
| 216 | - else |
|
| 237 | + } else |
|
| 217 | 238 | { |
| 218 | 239 | return $valueOrValues; |
| 219 | 240 | #print " {$key} => {$value}\r\n"; |
| 220 | 241 | } |
| 221 | 242 | } |
| 222 | - } |
|
| 223 | - else |
|
| 243 | + } else |
|
| 224 | 244 | { |
| 225 | 245 | #print "Unknow result type"; |
| 226 | 246 | return FALSE; |
@@ -240,11 +260,9 @@ discard block |
||
| 240 | 260 | if(isset($part->parts)) { |
| 241 | 261 | if($part->type == 2) { |
| 242 | 262 | $flattenedParts = flattenParts($part->parts, $flattenedParts, $prefix.$index.'.', 0, false); |
| 243 | - } |
|
| 244 | - elseif($fullPrefix) { |
|
| 263 | + } elseif($fullPrefix) { |
|
| 245 | 264 | $flattenedParts = flattenParts($part->parts, $flattenedParts, $prefix.$index.'.'); |
| 246 | - } |
|
| 247 | - else { |
|
| 265 | + } else { |
|
| 248 | 266 | $flattenedParts = flattenParts($part->parts, $flattenedParts, $prefix); |
| 249 | 267 | } |
| 250 | 268 | unset($flattenedParts[$prefix.$index]->parts); |
@@ -281,8 +299,9 @@ discard block |
||
| 281 | 299 | if ( ($num_found !== FALSE) && ($num_found>0) ) { |
| 282 | 300 | foreach ($out[0] as $url) { |
| 283 | 301 | $dom=nsdom(parse_url($url, PHP_URL_HOST)); |
| 284 | - if (!( empty($dom) || in_array($dom,$exclude) )) |
|
| 285 | - $ret[] = $dom; |
|
| 302 | + if (!( empty($dom) || in_array($dom,$exclude) )) { |
|
| 303 | + $ret[] = $dom; |
|
| 304 | + } |
|
| 286 | 305 | } |
| 287 | 306 | } |
| 288 | 307 | return array_values(array_unique($ret)); |
@@ -320,12 +339,13 @@ discard block |
||
| 320 | 339 | } |
| 321 | 340 | |
| 322 | 341 | } |
| 342 | + } else { |
|
| 343 | + $message = getPart($connection, $messageNumber, 1, $structure->encoding); |
|
| 323 | 344 | } |
| 324 | - else |
|
| 325 | - $message = getPart($connection, $messageNumber, 1, $structure->encoding); |
|
| 326 | 345 | |
| 327 | - if ( !empty($message) ) |
|
| 328 | - return getDomains($message, $exclusionList); |
|
| 346 | + if ( !empty($message) ) { |
|
| 347 | + return getDomains($message, $exclusionList); |
|
| 348 | + } |
|
| 329 | 349 | return array(); |
| 330 | 350 | } |
| 331 | 351 | |
@@ -360,7 +380,9 @@ discard block |
||
| 360 | 380 | $fileb= dirname(__FILE__) . '/' . $cf['report']['badreportFile']["$type"]; |
| 361 | 381 | $m_mail = imap_open('{'.$cf['imap']['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['imap']['authuser'].'}'.$cf['imap']['folder']["$type"], $cf['imap']['account'],$cf['imap']['authpassword'], OP_READONLY) |
| 362 | 382 | or syslog (LOG_EMERG, $cf['syslog']['user'].': Error in IMAP connection to <'.$cf['imap']['mailhost'].'>: ' . imap_last_error()); |
| 363 | - if ( !$m_mail ) exit(254); |
|
| 383 | + if ( !$m_mail ) { |
|
| 384 | + exit(254); |
|
| 385 | + } |
|
| 364 | 386 | |
| 365 | 387 | |
| 366 | 388 | syslog (LOG_INFO,$cf['syslog']['user'].': Successfully connected to <'.$cf['imap']['mailhost'].">; Reading $type messages of last ".$cf['imap']['oldestday'].' days...'); |
@@ -372,21 +394,31 @@ discard block |
||
| 372 | 394 | // Order results starting from newest message |
| 373 | 395 | if ( empty($m_search) ) { |
| 374 | 396 | syslog (LOG_INFO,$cf['syslog']['user'].": No mail found in $type folder. No reports written for $type."); |
| 375 | - if ( $ierr = imap_errors() ) |
|
| 376 | - foreach ( $ierr as $thiserr ) |
|
| 397 | + if ( $ierr = imap_errors() ) { |
|
| 398 | + foreach ( $ierr as $thiserr ) |
|
| 377 | 399 | syslog (LOG_ERR, $cf['syslog']['user'].": IMAP Error: $thiserr"); |
| 378 | - if ( $ierr = imap_alerts() ) |
|
| 379 | - foreach ( $ierr as $thiserr ) |
|
| 400 | + } |
|
| 401 | + if ( $ierr = imap_alerts() ) { |
|
| 402 | + foreach ( $ierr as $thiserr ) |
|
| 380 | 403 | syslog (LOG_ALERT, $cf['syslog']['user'].": IMAP Alert: $thiserr"); |
| 404 | + } |
|
| 381 | 405 | imap_close( $m_mail ); |
| 382 | - if ( file_exists( $file ) ) unlink ($file); |
|
| 383 | - if ( file_exists( $filed ) ) unlink ($filed); |
|
| 384 | - if ( file_exists( $fileb ) ) unlink ($fileb); |
|
| 406 | + if ( file_exists( $file ) ) { |
|
| 407 | + unlink ($file); |
|
| 408 | + } |
|
| 409 | + if ( file_exists( $filed ) ) { |
|
| 410 | + unlink ($filed); |
|
| 411 | + } |
|
| 412 | + if ( file_exists( $fileb ) ) { |
|
| 413 | + unlink ($fileb); |
|
| 414 | + } |
|
| 385 | 415 | return FALSE; |
| 386 | 416 | } |
| 387 | 417 | $nmes = count ($m_search); |
| 388 | 418 | syslog (LOG_INFO,$cf['syslog']['user'].": Found $nmes mail in $type folder."); |
| 389 | - if ($nmes>0) rsort($m_search); |
|
| 419 | + if ($nmes>0) { |
|
| 420 | + rsort($m_search); |
|
| 421 | + } |
|
| 390 | 422 | |
| 391 | 423 | // Create report file |
| 392 | 424 | |
@@ -450,10 +482,11 @@ discard block |
||
| 450 | 482 | |
| 451 | 483 | if (in_array($uid,array_keys($ipuid['uid']))) { |
| 452 | 484 | $ipuid['uid']["$uid"]['count']++; //number of learn by this uid |
| 453 | - if (!in_array($ip,$ipuid['uid']["$uid"])) |
|
| 454 | - $ipuid['uid']["$uid"][]=$ip; //ips learned by this uid |
|
| 455 | - } |
|
| 456 | - else { |
|
| 485 | + if (!in_array($ip,$ipuid['uid']["$uid"])) { |
|
| 486 | + $ipuid['uid']["$uid"][]=$ip; |
|
| 487 | + } |
|
| 488 | + //ips learned by this uid |
|
| 489 | + } else { |
|
| 457 | 490 | $ipuid['uid']["$uid"]['count'] = 1; |
| 458 | 491 | $ipuid['uid']["$uid"][]=$ip; |
| 459 | 492 | $ipuid['uid']['count']++; //number of unique uids |
@@ -461,10 +494,11 @@ discard block |
||
| 461 | 494 | |
| 462 | 495 | if (in_array($ip,array_keys($ipuid['ip']))) { |
| 463 | 496 | $ipuid['ip']["$ip"]['count']++; //number of time this ip appears in different messages |
| 464 | - if (!in_array($uid,$ipuid['ip']["$ip"])) |
|
| 465 | - $ipuid['ip']["$ip"][]=$uid; //uids that learned this ip |
|
| 466 | - } |
|
| 467 | - else { |
|
| 497 | + if (!in_array($uid,$ipuid['ip']["$ip"])) { |
|
| 498 | + $ipuid['ip']["$ip"][]=$uid; |
|
| 499 | + } |
|
| 500 | + //uids that learned this ip |
|
| 501 | + } else { |
|
| 468 | 502 | $ipuid['ip']["$ip"]['count'] = 1; |
| 469 | 503 | $ipuid['ip']["$ip"][]=$uid; |
| 470 | 504 | $ipuid['ip']['count']++; //number of unique ips |
@@ -474,10 +508,11 @@ discard block |
||
| 474 | 508 | $domuid['count']++; |
| 475 | 509 | if (in_array($uid,array_keys($domuid['uid']))) { |
| 476 | 510 | $domuid['uid']["$uid"]['count']++; //number of learn by this uid |
| 477 | - if (!in_array($dom,$domuid['uid']["$uid"])) |
|
| 478 | - $domuid['uid']["$uid"][]=$dom; //domains learned by this uid |
|
| 479 | - } |
|
| 480 | - else { |
|
| 511 | + if (!in_array($dom,$domuid['uid']["$uid"])) { |
|
| 512 | + $domuid['uid']["$uid"][]=$dom; |
|
| 513 | + } |
|
| 514 | + //domains learned by this uid |
|
| 515 | + } else { |
|
| 481 | 516 | $domuid['uid']["$uid"]['count'] = 1; |
| 482 | 517 | $domuid['uid']["$uid"][]=$dom; |
| 483 | 518 | $domuid['uid']['count']++; //number of unique uids |
@@ -485,10 +520,11 @@ discard block |
||
| 485 | 520 | |
| 486 | 521 | if (in_array($dom,array_keys($domuid['dom']))) { |
| 487 | 522 | $domuid['dom']["$dom"]['count']++; //number of learn with this domain |
| 488 | - if (!in_array($uid,$domuid['dom']["$dom"])) |
|
| 489 | - $domuid['dom']["$dom"][]=$uid; //uids that learned this domain |
|
| 490 | - } |
|
| 491 | - else { |
|
| 523 | + if (!in_array($uid,$domuid['dom']["$dom"])) { |
|
| 524 | + $domuid['dom']["$dom"][]=$uid; |
|
| 525 | + } |
|
| 526 | + //uids that learned this domain |
|
| 527 | + } else { |
|
| 492 | 528 | $domuid['dom']["$dom"]['count'] = 1; |
| 493 | 529 | $domuid['dom']["$dom"][]=$uid; |
| 494 | 530 | $domuid['dom']['count']++; //number of unique domains |
@@ -505,21 +541,30 @@ discard block |
||
| 505 | 541 | |
| 506 | 542 | /* Update HTML report */ |
| 507 | 543 | fwrite($fp,updateReport ( $ip,$uid,$ipuid['ip']["$ip"]['count'],$ipuid['uid']["$uid"]['count'],$host,$dateClient,$mid,$dateReceived) ); |
| 508 | - } |
|
| 509 | - else { /* Bad learn */ |
|
| 544 | + } else { /* Bad learn */ |
|
| 510 | 545 | |
| 511 | - if (in_array($uid,array_keys($uidbad['uid']))) |
|
| 512 | - $uidbad['uid']["$uid"]['count']++; //number of bad learn by this uid |
|
| 546 | + if (in_array($uid,array_keys($uidbad['uid']))) { |
|
| 547 | + $uidbad['uid']["$uid"]['count']++; |
|
| 548 | + } |
|
| 549 | + //number of bad learn by this uid |
|
| 513 | 550 | else { |
| 514 | 551 | $uidbad['uid']["$uid"]['count'] = 1; |
| 515 | 552 | $uidbad['uid']["$uid"][]=$uid; |
| 516 | 553 | $uidbad['count']++; //numeber of unique bad uids |
| 517 | 554 | } |
| 518 | 555 | /* The reason of bad report */ |
| 519 | - if ($host === FALSE) $reason = 'This mail was not received by recognized MX host'; |
|
| 520 | - if ($dateReceived === FALSE) $reason = 'This mail was not submitted to recognized MSA for learn'; |
|
| 521 | - if ($uid=='unknown') $reason = 'The uid of this mail was not found in splunk log'; |
|
| 522 | - if (!isset($reason)) $reason = '?'; |
|
| 556 | + if ($host === FALSE) { |
|
| 557 | + $reason = 'This mail was not received by recognized MX host'; |
|
| 558 | + } |
|
| 559 | + if ($dateReceived === FALSE) { |
|
| 560 | + $reason = 'This mail was not submitted to recognized MSA for learn'; |
|
| 561 | + } |
|
| 562 | + if ($uid=='unknown') { |
|
| 563 | + $reason = 'The uid of this mail was not found in splunk log'; |
|
| 564 | + } |
|
| 565 | + if (!isset($reason)) { |
|
| 566 | + $reason = '?'; |
|
| 567 | + } |
|
| 523 | 568 | |
| 524 | 569 | fwrite( $fpb,updatebadReport ( $uid,$dateClient,$mid,$dateReceived,$reason ) ); |
| 525 | 570 | } |
@@ -541,9 +586,9 @@ discard block |
||
| 541 | 586 | fwrite($fpd, '<hr><h2>Summary Report</h2><h5>Listing policy: domains must be learned at least '.$cf['listingdom']['threshold']["$type"].' times from at least '.$cf['listingdom']['thresholduid']["$type"].' different valid uids.</h5>' ); |
| 542 | 587 | |
| 543 | 588 | /* Make MYSQL connection */ |
| 544 | - if ( $cf['listingip']['onlyReport']["$type"] && $cf['listingdom']['onlyReport']["$type"] ) |
|
| 545 | - $mysqli = NULL; |
|
| 546 | - else { |
|
| 589 | + if ( $cf['listingip']['onlyReport']["$type"] && $cf['listingdom']['onlyReport']["$type"] ) { |
|
| 590 | + $mysqli = NULL; |
|
| 591 | + } else { |
|
| 547 | 592 | $mysqli = new mysqli($myconnArray['dbhost'], $myconnArray['userdb'], $myconnArray['pwd'], $myconnArray['db'], $myconnArray['dbport']); |
| 548 | 593 | if ($mysqli->connect_error) { |
| 549 | 594 | syslog (LOG_EMERG, $cf['syslog']['user'].': Connect Error (' . $mysqli->connect_errno . ') ' |
@@ -562,8 +607,9 @@ discard block |
||
| 562 | 607 | fwrite($fpd,file_get_contents(dirname(__FILE__) . '/' . $cf['report']['reportTemplateFooter'])); |
| 563 | 608 | fclose($fpd); |
| 564 | 609 | |
| 565 | - if ( !($cf['listingip']['onlyReport']["$type"] && $cf['listingdom']['onlyReport']["$type"]) ) |
|
| 566 | - $mysqli->close(); |
|
| 610 | + if ( !($cf['listingip']['onlyReport']["$type"] && $cf['listingdom']['onlyReport']["$type"]) ) { |
|
| 611 | + $mysqli->close(); |
|
| 612 | + } |
|
| 567 | 613 | |
| 568 | 614 | fwrite($fpb, '</table>'); |
| 569 | 615 | fwrite( $fpb,summaryBadReport( $uidbad ) ); |
@@ -571,12 +617,14 @@ discard block |
||
| 571 | 617 | fclose($fpb); |
| 572 | 618 | syslog (LOG_INFO,$cf['syslog']['user'].': Report files written. Listing job for '.$type.' terminated.'); |
| 573 | 619 | |
| 574 | - if ( $ierr = imap_errors() ) |
|
| 575 | - foreach ( $ierr as $thiserr ) |
|
| 620 | + if ( $ierr = imap_errors() ) { |
|
| 621 | + foreach ( $ierr as $thiserr ) |
|
| 576 | 622 | syslog (LOG_ERR, $cf['syslog']['user'].": IMAP Error: $thiserr"); |
| 577 | - if ( $ierr = imap_alerts() ) |
|
| 578 | - foreach ( $ierr as $thiserr ) |
|
| 623 | + } |
|
| 624 | + if ( $ierr = imap_alerts() ) { |
|
| 625 | + foreach ( $ierr as $thiserr ) |
|
| 579 | 626 | syslog (LOG_ALERT, $cf['syslog']['user'].": IMAP Alert: $thiserr"); |
| 627 | + } |
|
| 580 | 628 | imap_close($m_mail); |
| 581 | 629 | } |
| 582 | 630 | ?> |
@@ -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 lowercase 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 strtolower(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 strtolower(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 | } |
@@ -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($dbhost, $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 | } |
@@ -5,18 +5,21 @@ discard block |
||
| 5 | 5 | $open='{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}'; |
| 6 | 6 | $m_mail = imap_open($open, $username, $cf['authpassword'], OP_READONLY) |
| 7 | 7 | or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); |
| 8 | - if ( !$m_mail ) exit(254); |
|
| 8 | + if ( !$m_mail ) { |
|
| 9 | + exit(254); |
|
| 10 | + } |
|
| 9 | 11 | |
| 10 | 12 | |
| 11 | 13 | syslog (LOG_INFO,$cf['user'].': Successfully connected to <'.$cf['mailhost'].'>; Listing folders of account <'.$username.'>...'); |
| 12 | 14 | //get all folder |
| 13 | 15 | $list = imap_list($m_mail, $open, "*"); |
| 14 | 16 | imap_close($m_mail); |
| 15 | - if (is_array($list)) |
|
| 16 | - foreach ($list as $mbox) |
|
| 17 | + if (is_array($list)) { |
|
| 18 | + foreach ($list as $mbox) |
|
| 17 | 19 | $return[] = explode($open,$mbox,2)[1]; |
| 18 | - else |
|
| 19 | - syslog (LOG_INFO,$cf['user'] . ': imap_list failed: ' . imap_last_error() ); |
|
| 20 | + } else { |
|
| 21 | + syslog (LOG_INFO,$cf['user'] . ': imap_list failed: ' . imap_last_error() ); |
|
| 22 | + } |
|
| 20 | 23 | return $return; |
| 21 | 24 | } |
| 22 | 25 | |
@@ -24,7 +27,9 @@ discard block |
||
| 24 | 27 | $head=array(); |
| 25 | 28 | $m_mail = imap_open('{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}'.$folder, $username,$cf['authpassword'], OP_READONLY) |
| 26 | 29 | or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); |
| 27 | - if ( !$m_mail ) exit(254); |
|
| 30 | + if ( !$m_mail ) { |
|
| 31 | + exit(254); |
|
| 32 | + } |
|
| 28 | 33 | |
| 29 | 34 | |
| 30 | 35 | syslog (LOG_INFO,$cf['user'].': Successfully connected to <'.$cf['mailhost'].">; Reading <$folder> messages of last ".$cf['oldestday'].' days on account <'.$username.'>...'); |
@@ -36,29 +41,36 @@ discard block |
||
| 36 | 41 | // Order results starting from newest message |
| 37 | 42 | if ( empty($m_search) ) { |
| 38 | 43 | syslog (LOG_INFO,$cf['user'].": No suitable mail found in <$folder> folder."); |
| 39 | - if ( $ierr = imap_errors() ) |
|
| 40 | - foreach ( $ierr as $thiserr ) |
|
| 44 | + if ( $ierr = imap_errors() ) { |
|
| 45 | + foreach ( $ierr as $thiserr ) |
|
| 41 | 46 | syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); |
| 42 | - if ( $ierr = imap_alerts() ) |
|
| 43 | - foreach ( $ierr as $thiserr ) |
|
| 47 | + } |
|
| 48 | + if ( $ierr = imap_alerts() ) { |
|
| 49 | + foreach ( $ierr as $thiserr ) |
|
| 44 | 50 | syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); |
| 51 | + } |
|
| 45 | 52 | imap_close( $m_mail ); |
| 46 | 53 | return FALSE; |
| 47 | 54 | } |
| 48 | 55 | $nmes = count ($m_search); |
| 49 | 56 | syslog (LOG_INFO,$cf['user'].": Found $nmes mail in <$folder> folder."); |
| 50 | - if ($nmes>0) rsort($m_search); |
|
| 57 | + if ($nmes>0) { |
|
| 58 | + rsort($m_search); |
|
| 59 | + } |
|
| 51 | 60 | |
| 52 | 61 | // loop for each message |
| 53 | - foreach ($m_search as $onem) |
|
| 54 | - $head[] = imap_fetchheader($m_mail, $onem ); |
|
| 62 | + foreach ($m_search as $onem) { |
|
| 63 | + $head[] = imap_fetchheader($m_mail, $onem ); |
|
| 64 | + } |
|
| 55 | 65 | imap_close($m_mail); |
| 56 | 66 | return $head; |
| 57 | 67 | } |
| 58 | 68 | |
| 59 | 69 | function dspamLevel($prob, $conf) { |
| 60 | 70 | /* Calculate DSPAM Level as the Spamassassin Plugin */ |
| 61 | - if (is_null($prob) or is_null($conf)) return '-'; |
|
| 71 | + if (is_null($prob) or is_null($conf)) { |
|
| 72 | + return '-'; |
|
| 73 | + } |
|
| 62 | 74 | $t_prob = abs((($prob - 0.5) * 2) * 100); |
| 63 | 75 | return round(($t_prob + ($conf*100)) / 2); |
| 64 | 76 | } |
@@ -123,7 +135,9 @@ discard block |
||
| 123 | 135 | } |
| 124 | 136 | } |
| 125 | 137 | $received=NULL; |
| 126 | - if ($k>1) $result['warn'][] = 'The trusted DMARC AR Headers are present more than once. Something wrong.'; |
|
| 138 | + if ($k>1) { |
|
| 139 | + $result['warn'][] = 'The trusted DMARC AR Headers are present more than once. Something wrong.'; |
|
| 140 | + } |
|
| 127 | 141 | |
| 128 | 142 | if ( preg_match_all('/^Authentication\-Results:\s+(?<host>[\w\.]+);(?:\s+|\r\n\s+)spf=(?<spf>\w+)\s+smtp\.(?:mailfrom|helo)=(?<SPFfrom>[\w\.\-\+]+)/m',$header,$received) ) { |
| 129 | 143 | $k=0; |
@@ -139,7 +153,9 @@ discard block |
||
| 139 | 153 | } |
| 140 | 154 | } |
| 141 | 155 | $received=NULL; |
| 142 | - if ($k>1) $result['warn'][] = 'The trusted SPF AR Headers are present more than once. Something wrong.'; |
|
| 156 | + if ($k>1) { |
|
| 157 | + $result['warn'][] = 'The trusted SPF AR Headers are present more than once. Something wrong.'; |
|
| 158 | + } |
|
| 143 | 159 | |
| 144 | 160 | $k=0; |
| 145 | 161 | if ( preg_match_all('/^Authentication\-Results:\s+(?<host>[\w\.]+);(?:\s+|\r\n\s+)dkim=(?<dkim>\w+)\s+[\w\s\(\)\-]+header\.d=(?<DKIMdom>[\w\.]+)/m',$header,$received) ) { |
@@ -155,7 +171,9 @@ discard block |
||
| 155 | 171 | } |
| 156 | 172 | } |
| 157 | 173 | $received=NULL; |
| 158 | - if ($k>1) $result['warn'][] = 'The trusted DKIM AR Headers are present more than once. Something wrong.'; |
|
| 174 | + if ($k>1) { |
|
| 175 | + $result['warn'][] = 'The trusted DKIM AR Headers are present more than once. Something wrong.'; |
|
| 176 | + } |
|
| 159 | 177 | |
| 160 | 178 | if ($dpl) { /* Use Spamassassin Plugin */ |
| 161 | 179 | if ( preg_match_all('/^X\-Spam\-Status:\s(?P<spamstatus>\w+)\,(?:\s+|\r\n\s+)score=(?P<score>[\-\.\d]+)(?:\s+|\r\n\s+)tagged_above=\-{0,1}\d+(?:\s+|\r\n\s+)required=(?P<th>[\-\.\d]+)(?:\s+|\r\n\s+)tests=\[(?:.|\r\n\s+)*DSPAM_(?P<dtype>SPAM|HAM)_(?P<dlevel>\d\d)(?:.|\r\n\s+)*\]/m',$header,$received) ) { |
@@ -165,57 +183,66 @@ discard block |
||
| 165 | 183 | $result['dspam']['type'] = dspamType($received['dtype'][0]); |
| 166 | 184 | $result['dspam']['level'] =$received['dlevel'][0]; |
| 167 | 185 | } |
| 168 | - if (count($received[0])>1) $result['warn'][] = 'The Spamassassin Headers are present more than once. I consider only the last one.'; |
|
| 169 | - } |
|
| 170 | - else { /* Parse apart all DSPAM Header and calculate a level */ |
|
| 186 | + if (count($received[0])>1) { |
|
| 187 | + $result['warn'][] = 'The Spamassassin Headers are present more than once. I consider only the last one.'; |
|
| 188 | + } |
|
| 189 | + } else { /* Parse apart all DSPAM Header and calculate a level */ |
|
| 171 | 190 | if ( preg_match_all('/^X\-Spam\-Status:\s(?P<spamstatus>\w+)\,(?:\s+|\r\n\s+)score=(?P<score>[\-\.\d]+)(?:\s+|\r\n\s+)tagged_above=\-{0,1}\d+(?:\s+|\r\n\s+)required=(?P<th>[\-\.\d]+)(?:\s+|\r\n\s+)tests=\[(?:.|\r\n\s+)*\]/m',$header,$received) ) { |
| 172 | 191 | $result['spam']['status']=$received['spamstatus'][0]; |
| 173 | 192 | $result['spam']['score'] = $received['score'][0]; |
| 174 | 193 | $result['spam']['th'] = $received['th'][0]; |
| 175 | - if (count($received[0])>1) |
|
| 176 | - $result['warn'][]= 'The Spamassassin Headers are present more than once. I consider only the last one.'; |
|
| 194 | + if (count($received[0])>1) { |
|
| 195 | + $result['warn'][]= 'The Spamassassin Headers are present more than once. I consider only the last one.'; |
|
| 196 | + } |
|
| 177 | 197 | } |
| 178 | - if ( preg_match ('/\r\nX\-DSPAM\-Result:\s(?P<result>.*)\r\n/',$header,$received) != 1) |
|
| 179 | - $result['warn'] = 'DSPAM Result invalid, not present or present more than once.'; |
|
| 180 | - else |
|
| 181 | - $result['dspam']['type']=$received['result']; |
|
| 198 | + if ( preg_match ('/\r\nX\-DSPAM\-Result:\s(?P<result>.*)\r\n/',$header,$received) != 1) { |
|
| 199 | + $result['warn'] = 'DSPAM Result invalid, not present or present more than once.'; |
|
| 200 | + } else { |
|
| 201 | + $result['dspam']['type']=$received['result']; |
|
| 202 | + } |
|
| 182 | 203 | $prob = NULL; |
| 183 | 204 | $conf = NULL; |
| 184 | - if ( preg_match ('/\r\nX\-DSPAM\-Probability:\s(?P<prob>.*)\r\n/',$header,$received) != 1) |
|
| 185 | - $result['warn'][] = 'DSPAM Probability invalid, not present or present more than once.'; |
|
| 186 | - else |
|
| 187 | - $prob = $received['prob']; |
|
| 188 | - if ( preg_match ('/\r\nX\-DSPAM\-Confidence:\s(?P<conf>.*)\r\n/',$header,$received) != 1) |
|
| 189 | - $result['warn'][] = 'DSPAM Confidence invalid, not present or present more than once.'; |
|
| 190 | - else |
|
| 191 | - $conf = $received['conf']; |
|
| 205 | + if ( preg_match ('/\r\nX\-DSPAM\-Probability:\s(?P<prob>.*)\r\n/',$header,$received) != 1) { |
|
| 206 | + $result['warn'][] = 'DSPAM Probability invalid, not present or present more than once.'; |
|
| 207 | + } else { |
|
| 208 | + $prob = $received['prob']; |
|
| 209 | + } |
|
| 210 | + if ( preg_match ('/\r\nX\-DSPAM\-Confidence:\s(?P<conf>.*)\r\n/',$header,$received) != 1) { |
|
| 211 | + $result['warn'][] = 'DSPAM Confidence invalid, not present or present more than once.'; |
|
| 212 | + } else { |
|
| 213 | + $conf = $received['conf']; |
|
| 214 | + } |
|
| 192 | 215 | $result['dspam']['level'] = dspamLevel($prob,$conf); |
| 193 | 216 | } |
| 194 | 217 | $received=NULL; |
| 195 | - if ( preg_match ('/\r\nFrom:\s(?P<from>.*)\r\n/',$header,$received) != 1) |
|
| 196 | - $result['warn'][] = 'From header invalid or not present'; |
|
| 197 | - else |
|
| 198 | - $result['from'] = $received['from']; |
|
| 218 | + if ( preg_match ('/\r\nFrom:\s(?P<from>.*)\r\n/',$header,$received) != 1) { |
|
| 219 | + $result['warn'][] = 'From header invalid or not present'; |
|
| 220 | + } else { |
|
| 221 | + $result['from'] = $received['from']; |
|
| 222 | + } |
|
| 199 | 223 | |
| 200 | - if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$received) != 1) |
|
| 201 | - $result['warn'][] = 'Date header invalid or not present'; |
|
| 202 | - else |
|
| 203 | - $result['date'] = $received['date']; |
|
| 224 | + if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$received) != 1) { |
|
| 225 | + $result['warn'][] = 'Date header invalid or not present'; |
|
| 226 | + } else { |
|
| 227 | + $result['date'] = $received['date']; |
|
| 228 | + } |
|
| 204 | 229 | |
| 205 | 230 | $received=NULL; |
| 206 | - if ( preg_match ('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/',$header,$received) != 1) |
|
| 207 | - $result['warn'][] = 'Message-ID invalid, not present or present more than once.'; |
|
| 208 | - else |
|
| 209 | - $result['messageid']=$received['mid']; |
|
| 231 | + if ( preg_match ('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/',$header,$received) != 1) { |
|
| 232 | + $result['warn'][] = 'Message-ID invalid, not present or present more than once.'; |
|
| 233 | + } else { |
|
| 234 | + $result['messageid']=$received['mid']; |
|
| 235 | + } |
|
| 210 | 236 | |
| 211 | 237 | $received=NULL; |
| 212 | 238 | |
| 213 | 239 | switch ($learn) { |
| 214 | 240 | case 'dspamc': |
| 215 | - if ( preg_match ('/\r\nX\-DSPAM\-Signature:\s(?P<sig>.*)\r\n/',$header,$received) != 1) |
|
| 216 | - $result['warn'] = 'DSPAM Signature invalid, not present or present more than once.'; |
|
| 217 | - else |
|
| 218 | - $result['dspam']['learn']=$received['sig']; |
|
| 241 | + if ( preg_match ('/\r\nX\-DSPAM\-Signature:\s(?P<sig>.*)\r\n/',$header,$received) != 1) { |
|
| 242 | + $result['warn'] = 'DSPAM Signature invalid, not present or present more than once.'; |
|
| 243 | + } else { |
|
| 244 | + $result['dspam']['learn']=$received['sig']; |
|
| 245 | + } |
|
| 219 | 246 | break; |
| 220 | 247 | case false: |
| 221 | 248 | break; |
@@ -250,8 +277,9 @@ discard block |
||
| 250 | 277 | for ($i=0; $i<$cols; $i++) { |
| 251 | 278 | $key = $kcontent[$i]; |
| 252 | 279 | if (is_array($content[$key])&&($hs = array_keys($content[$key]))) { |
| 253 | - foreach ($hs as $h) |
|
| 254 | - printf('<th>%s</th>',$h); |
|
| 280 | + foreach ($hs as $h) { |
|
| 281 | + printf('<th>%s</th>',$h); |
|
| 282 | + } |
|
| 255 | 283 | } |
| 256 | 284 | } |
| 257 | 285 | |
@@ -267,15 +295,16 @@ discard block |
||
| 267 | 295 | |
| 268 | 296 | function formatVal($val, $learn) { |
| 269 | 297 | foreach (array_keys($val) as $key) { |
| 270 | - if (is_array($val["$key"]) and ($key!='warn')) |
|
| 271 | - $val["$key"] = formatVal($val["$key"], $learn); |
|
| 272 | - else { |
|
| 298 | + if (is_array($val["$key"]) and ($key!='warn')) { |
|
| 299 | + $val["$key"] = formatVal($val["$key"], $learn); |
|
| 300 | + } else { |
|
| 273 | 301 | switch ($key) { |
| 274 | 302 | case 'warn': |
| 275 | - if (empty($val["$key"])) |
|
| 276 | - $val["$key"] = '-'; |
|
| 277 | - else |
|
| 278 | - $val["$key"] = sprintf('<div title="%s">Y</div>',implode($val["$key"],"\n")); |
|
| 303 | + if (empty($val["$key"])) { |
|
| 304 | + $val["$key"] = '-'; |
|
| 305 | + } else { |
|
| 306 | + $val["$key"] = sprintf('<div title="%s">Y</div>',implode($val["$key"],"\n")); |
|
| 307 | + } |
|
| 279 | 308 | break; |
| 280 | 309 | case 'learn': |
| 281 | 310 | $val["$key"] = formLearn($learn, $val); |
@@ -297,9 +326,10 @@ discard block |
||
| 297 | 326 | $par['class'] = $class; |
| 298 | 327 | $val["$class"] = sprintf('dspamc --user dspam --deliver=summary --class=%s --source=error --signature=%s', |
| 299 | 328 | strtolower($class), $par['learn']); |
| 300 | - if (($class != $par['type'])||($par['level']<99)) |
|
| 301 | - $return .= sprintf(file_get_contents('formLearnDSPAM.htm'), |
|
| 329 | + if (($class != $par['type'])||($par['level']<99)) { |
|
| 330 | + $return .= sprintf(file_get_contents('formLearnDSPAM.htm'), |
|
| 302 | 331 | $class,$class,$val["$class"],base64_encode(json_encode($par)),$class); |
| 332 | + } |
|
| 303 | 333 | } |
| 304 | 334 | default: |
| 305 | 335 | return $return; |
@@ -308,37 +338,41 @@ discard block |
||
| 308 | 338 | |
| 309 | 339 | function printTableRow($row, $learn, $init=true) { |
| 310 | 340 | $color = 'inherit'; |
| 311 | - if ($init) |
|
| 312 | - $row=formatVal($row,$learn); |
|
| 341 | + if ($init) { |
|
| 342 | + $row=formatVal($row,$learn); |
|
| 343 | + } |
|
| 313 | 344 | foreach( $row as $key => $val) { |
| 314 | - if (is_array($val)) |
|
| 315 | - printTableRow($val, $learn, false); |
|
| 316 | - else { |
|
| 345 | + if (is_array($val)) { |
|
| 346 | + printTableRow($val, $learn, false); |
|
| 347 | + } else { |
|
| 317 | 348 | /* DSPAM format */ |
| 318 | - if (isset($row['type'])) |
|
| 319 | - switch($row['type']) { |
|
| 349 | + if (isset($row['type'])) { |
|
| 350 | + switch($row['type']) { |
|
| 320 | 351 | case 'Innocent': |
| 321 | 352 | case 'HAM': |
| 322 | 353 | $color = 'rgba(0,255,0, %.1f)'; |
| 354 | + } |
|
| 323 | 355 | break; |
| 324 | 356 | case 'Spam': |
| 325 | 357 | case 'SPAM': |
| 326 | 358 | $color = 'rgba(255,0,0,%.1f)'; |
| 327 | 359 | } |
| 328 | 360 | /* DMARC, DKIM, SPF format */ |
| 329 | - if (isset($row['result'])) |
|
| 330 | - switch($row['result']) { |
|
| 361 | + if (isset($row['result'])) { |
|
| 362 | + switch($row['result']) { |
|
| 331 | 363 | case 'pass': |
| 332 | 364 | $color = 'rgba(0,255,0, %.1f)'; |
| 365 | + } |
|
| 333 | 366 | break; |
| 334 | 367 | case 'fail': |
| 335 | 368 | $color = 'rgba(255,0,0,%.1f)'; |
| 336 | 369 | } |
| 337 | 370 | /* Spamassassin format */ |
| 338 | - if (isset($row['status'])) |
|
| 339 | - switch($row['status']) { |
|
| 371 | + if (isset($row['status'])) { |
|
| 372 | + switch($row['status']) { |
|
| 340 | 373 | case 'No': |
| 341 | 374 | $color = 'rgba(0,255,0, %.1f)'; |
| 375 | + } |
|
| 342 | 376 | break; |
| 343 | 377 | case 'Yes': |
| 344 | 378 | $color = 'rgba(255,0,0,%.1f)'; |