@@ -26,12 +26,12 @@ |
||
| 26 | 26 | if ( preg_match ('/^X-DSPAM-Result:\s+(?P<user>[\w\.\-\_\+\%\@]+);\s+result="(?P<result>\w+)";\s+class="(?P<class>\w+)";\s+probability=(?P<prob>[\d\.]+);\s+confidence=(?P<conf>[\d\.]+);\s+signature=(?P<sig>[\w\,]+)$/',$out[0],$received) != 1) { |
| 27 | 27 | $err = 'DSPAM Client returned an unparseable result.'; |
| 28 | 28 | syslog(LOG_ERR, $username.': Learn Error: '.$err); |
| 29 | - exit (sprintf('<p>%s</p>',htmlentities($err))); |
|
| 29 | + exit (sprintf('<p>%s</p>',htmlentities($err))); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | printf('<p>Message learned successfully with following result:</p><ul><li>Owner: <b>%s</b></li><li>Result: <b>%s</b></li><li>Class: <b>%s</b></li></ul>', |
| 33 | 33 | htmlentities($received['user']), |
| 34 | - $received['result'], $received['class']); |
|
| 34 | + $received['result'], $received['class']); |
|
| 35 | 35 | closelog(); |
| 36 | 36 | ?> |
| 37 | 37 | </div> |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | <?php |
| 3 | 3 | |
| 4 | 4 | if (PHP_SAPI != "cli") |
| 5 | - exit; |
|
| 5 | + exit; |
|
| 6 | 6 | |
| 7 | 7 | $home = '/var/www/html/RBL'; |
| 8 | 8 | require_once($home.'/config.php'); |
@@ -20,30 +20,30 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | $opts = getopt('f:t:'); |
| 22 | 22 | if ( isset($opts['f']) ) { |
| 23 | - $filetemplate = $opts['f']; |
|
| 23 | + $filetemplate = $opts['f']; |
|
| 24 | 24 | } else { |
| 25 | 25 | print "\nNo option for '-f' given.\n"; |
| 26 | - exit ( usage() ); |
|
| 26 | + exit ( usage() ); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | if ( isset($opts['t']) ) { |
| 30 | - $tablename = $opts['t']; |
|
| 30 | + $tablename = $opts['t']; |
|
| 31 | 31 | } else { |
| 32 | 32 | print "\nNo option for '-t' given.\n"; |
| 33 | - exit ( usage() ); |
|
| 33 | + exit ( usage() ); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | if ( ($typedescN = array_search( $tablename, array_column($tables, 'name'))) === FALSE ) { |
| 37 | - print "\nDB <$tablename> doesn't exist!\n"; |
|
| 38 | - syslog (LOG_EMERG, "$user: DB <$tablename> doesn't exist!"); |
|
| 39 | - exit ( usage() ); |
|
| 37 | + print "\nDB <$tablename> doesn't exist!\n"; |
|
| 38 | + syslog (LOG_EMERG, "$user: DB <$tablename> doesn't exist!"); |
|
| 39 | + exit ( usage() ); |
|
| 40 | 40 | } |
| 41 | 41 | $typedesc = array_keys($tables)[$typedescN]; |
| 42 | 42 | |
| 43 | 43 | if (! file_exists($filetemplate) ) { |
| 44 | - print "\nFile <$filetemplate> doesn't exists!\n"; |
|
| 44 | + print "\nFile <$filetemplate> doesn't exists!\n"; |
|
| 45 | 45 | syslog (LOG_EMERG, "$user: File <$filetemplate> doesn't exist!"); |
| 46 | - exit ( usage() ); |
|
| 46 | + exit ( usage() ); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | if (! in_array( $typedesc, array_keys($tables) ) ) { |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | if (! $tables["$typedesc"]['active'] ) { |
| 55 | 55 | print "\nList <$typedesc> is not active. Please provide an active list name.\n"; |
| 56 | - exit ( usage() ); |
|
| 56 | + exit ( usage() ); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | |
@@ -73,10 +73,10 @@ discard block |
||
| 73 | 73 | |
| 74 | 74 | $mysqli = new mysqli($dbhost, $userdb, $pwd, $db, $dbport); |
| 75 | 75 | if ($mysqli->connect_error) { |
| 76 | - syslog (LOG_EMERG, $user.': Connect Error (' . $mysqli->connect_errno . ') ' |
|
| 77 | - . $mysqli->connect_error); |
|
| 78 | - exit ($user.': Connect Error (' . $mysqli->connect_errno . ') ' |
|
| 79 | - . $mysqli->connect_error); |
|
| 76 | + syslog (LOG_EMERG, $user.': Connect Error (' . $mysqli->connect_errno . ') ' |
|
| 77 | + . $mysqli->connect_error); |
|
| 78 | + exit ($user.': Connect Error (' . $mysqli->connect_errno . ') ' |
|
| 79 | + . $mysqli->connect_error); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | syslog(LOG_INFO, $user.': Successfully mysql connected to ' . $mysqli->host_info) ; |
@@ -87,15 +87,15 @@ discard block |
||
| 87 | 87 | while ($riga = $result->fetch_array(MYSQLI_ASSOC)) { |
| 88 | 88 | if (isListed($riga)) { |
| 89 | 89 | switch ( $tables["$typedesc"]['field'] ) { |
| 90 | - case 'ip': |
|
| 91 | - $element[] = long2ip($riga['ip']); |
|
| 92 | - break; |
|
| 93 | - case 'network': |
|
| 94 | - $element[] = long2ip($riga['network']).'/'.long2ip($riga['netmask']); |
|
| 95 | - break; |
|
| 96 | - default: |
|
| 90 | + case 'ip': |
|
| 91 | + $element[] = long2ip($riga['ip']); |
|
| 92 | + break; |
|
| 93 | + case 'network': |
|
| 94 | + $element[] = long2ip($riga['network']).'/'.long2ip($riga['netmask']); |
|
| 95 | + break; |
|
| 96 | + default: |
|
| 97 | 97 | $type = $tables["$typedesc"]['field']; |
| 98 | - $element[] = $riga["$type"]; |
|
| 98 | + $element[] = $riga["$type"]; |
|
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | } |
@@ -4,8 +4,8 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | function username() { |
| 6 | 6 | if (isset ($_SERVER['REMOTE_USER'])) $user = $_SERVER['REMOTE_USER']; |
| 7 | - else if (isset ($_SERVER['USER'])) $user = $_SERVER['USER']; |
|
| 8 | - else $user='unknown'; |
|
| 7 | + else if (isset ($_SERVER['USER'])) $user = $_SERVER['USER']; |
|
| 8 | + else $user='unknown'; |
|
| 9 | 9 | return $user; |
| 10 | 10 | } |
| 11 | 11 | |
@@ -21,11 +21,11 @@ discard block |
||
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | function myConnect($host, $user, $pass, $db, $port, $tablelist, $typedesc, $loguser) { |
| 24 | - $db = ( $tablelist["$typedesc"]['milter'] ) ? $tablelist["$typedesc"]['name'] : $db; |
|
| 24 | + $db = ( $tablelist["$typedesc"]['milter'] ) ? $tablelist["$typedesc"]['name'] : $db; |
|
| 25 | 25 | $mysqli = new mysqli($host, $user, $pass, $db, $port); |
| 26 | - if ($mysqli->connect_error) { |
|
| 27 | - syslog (LOG_EMERG, $loguser.': Connect Error to DB <'.$db.'> (' . $mysqli->connect_errno . ') ' |
|
| 28 | - . $mysqli->connect_error); |
|
| 26 | + if ($mysqli->connect_error) { |
|
| 27 | + syslog (LOG_EMERG, $loguser.': Connect Error to DB <'.$db.'> (' . $mysqli->connect_errno . ') ' |
|
| 28 | + . $mysqli->connect_error); |
|
| 29 | 29 | return FALSE; |
| 30 | 30 | } |
| 31 | 31 | syslog(LOG_INFO, $loguser.': Successfully MySQL connected at DB <'.$db.'> to ' . $mysqli->host_info) ; |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | } |
| 67 | 67 | } |
| 68 | 68 | list($sub['net'],$sub['mask'])=explode('/',$value); |
| 69 | - $query= sprintf("INSERT INTO `$table` ( |
|
| 69 | + $query= sprintf("INSERT INTO `$table` ( |
|
| 70 | 70 | `$type` , |
| 71 | 71 | `netmask`, |
| 72 | 72 | `date` , |
@@ -79,10 +79,10 @@ discard block |
||
| 79 | 79 | INET_ATON( '%s' ) , INET_ATON( '%s' ) , |
| 80 | 80 | CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s' |
| 81 | 81 | )" ,$sub['net'],$sub['mask'],$expUnit,$expQ,$user,$myreason); |
| 82 | - break; |
|
| 82 | + break; |
|
| 83 | 83 | |
| 84 | 84 | default: |
| 85 | - $query= sprintf("INSERT INTO `$table` ( |
|
| 85 | + $query= sprintf("INSERT INTO `$table` ( |
|
| 86 | 86 | `$type` , |
| 87 | 87 | `date` , |
| 88 | 88 | `exp` , |
@@ -97,8 +97,8 @@ discard block |
||
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | if ($myconn->query($query) === TRUE) { |
| 100 | - syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit."); |
|
| 101 | - $result=TRUE; |
|
| 100 | + syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit."); |
|
| 101 | + $result=TRUE; |
|
| 102 | 102 | } |
| 103 | 103 | else syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
| 104 | 104 | return $result; |
@@ -116,9 +116,9 @@ discard block |
||
| 116 | 116 | $nlist = '`nlist` + 1'; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - switch ($type) { |
|
| 119 | + switch ($type) { |
|
| 120 | 120 | case 'ip': |
| 121 | - $query= sprintf("UPDATE `$table` SET |
|
| 121 | + $query= sprintf("UPDATE `$table` SET |
|
| 122 | 122 | `active` = '1', |
| 123 | 123 | `user` = '%s', |
| 124 | 124 | `exp` = TIMESTAMPADD(%s,%d,%s), |
@@ -126,9 +126,9 @@ discard block |
||
| 126 | 126 | `reason` = '%s' |
| 127 | 127 | WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user,$expUnit,$expQ,$exptime,$nlist,$myreason,$value); |
| 128 | 128 | break; |
| 129 | - case 'network': |
|
| 129 | + case 'network': |
|
| 130 | 130 | list($sub['net'],$sub['mask'])=explode('/',$value); |
| 131 | - $query= sprintf("UPDATE `$table` SET |
|
| 131 | + $query= sprintf("UPDATE `$table` SET |
|
| 132 | 132 | `active` = '1', |
| 133 | 133 | `user` = '%s', |
| 134 | 134 | `exp` = TIMESTAMPADD(%s,%d,%s), |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1" ,$user,$expUnit,$expQ,$exptime,$nlist,$myreason,$sub['net'],$sub['mask']); |
| 138 | 138 | break; |
| 139 | 139 | default: |
| 140 | - $query= sprintf("UPDATE `$table` SET |
|
| 140 | + $query= sprintf("UPDATE `$table` SET |
|
| 141 | 141 | `active` = '1', |
| 142 | 142 | `user` = '%s', |
| 143 | 143 | `exp` = TIMESTAMPADD(%s,%d,%s), |
@@ -146,18 +146,18 @@ discard block |
||
| 146 | 146 | WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user,$expUnit,$expQ,$exptime,$nlist,$myreason,$value); |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - if ($myconn->query($query) === TRUE) { |
|
| 150 | - syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit from $exptime."); |
|
| 149 | + if ($myconn->query($query) === TRUE) { |
|
| 150 | + syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit from $exptime."); |
|
| 151 | 151 | $result=TRUE; |
| 152 | - } |
|
| 153 | - else syslog (LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 152 | + } |
|
| 153 | + else syslog (LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 154 | 154 | return $result; |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | function remove ($myconn,$user,$value,$type,$table) { |
| 158 | 158 | |
| 159 | - switch ($type) { |
|
| 160 | - case 'ip': |
|
| 159 | + switch ($type) { |
|
| 160 | + case 'ip': |
|
| 161 | 161 | $query = sprintf("DELETE FROM `$table` WHERE |
| 162 | 162 | `$table`.`$type` = INET_ATON('%s') LIMIT 1", $value); |
| 163 | 163 | break; |
@@ -173,18 +173,18 @@ discard block |
||
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | |
| 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); |
|
| 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); |
|
| 179 | 179 | |
| 180 | - return $return; |
|
| 180 | + return $return; |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | |
| 184 | 184 | function changestatus ($myconn,$user,$value,$status,$type,$table) { |
| 185 | 185 | |
| 186 | 186 | switch ($type) { |
| 187 | - case 'ip': |
|
| 187 | + case 'ip': |
|
| 188 | 188 | $query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user, $value); |
| 189 | 189 | break; |
| 190 | 190 | case 'network': |
@@ -195,16 +195,16 @@ discard block |
||
| 195 | 195 | $query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user, $value); |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | - if ($return=$myconn->query($query) === TRUE) { |
|
| 199 | - syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>"); |
|
| 200 | - } |
|
| 201 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 198 | + if ($return=$myconn->query($query) === TRUE) { |
|
| 199 | + syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>"); |
|
| 200 | + } |
|
| 201 | + else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 202 | 202 | return $return; |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | |
| 206 | 206 | function expire ($myconn,$user,$tables,$expireTime) { |
| 207 | - $return=TRUE; |
|
| 207 | + $return=TRUE; |
|
| 208 | 208 | $log=array(); |
| 209 | 209 | $desc = array_keys($tables); |
| 210 | 210 | foreach ($desc as $tdesc) { |
@@ -214,11 +214,11 @@ discard block |
||
| 214 | 214 | /* END OF QUERY */ |
| 215 | 215 | $log[0] = 'expired for'; |
| 216 | 216 | $log[1] = 'disabled for'; |
| 217 | - if ($myconn->multi_query($query)) { |
|
| 217 | + if ($myconn->multi_query($query)) { |
|
| 218 | 218 | $j = 0; |
| 219 | 219 | do { |
| 220 | - $numdel = $myconn->affected_rows; |
|
| 221 | - syslog(LOG_INFO, "Expire job - <$user> Permanently DELETED $numdel records ".$log[$j]." $expireTime YEARS from <".$tables["$tdesc"]['name'].'>.'); |
|
| 220 | + $numdel = $myconn->affected_rows; |
|
| 221 | + syslog(LOG_INFO, "Expire job - <$user> Permanently DELETED $numdel records ".$log[$j]." $expireTime YEARS from <".$tables["$tdesc"]['name'].'>.'); |
|
| 222 | 222 | $j++; |
| 223 | 223 | |
| 224 | 224 | } while ($myconn->next_result()); |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | } |
| 231 | 231 | if ( !($return) ) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); |
| 232 | 232 | else syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.'); |
| 233 | - return $return; |
|
| 233 | + return $return; |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | if ( $entry->num_rows ) { |
| 304 | 304 | if ( $entry->num_rows == 1 ) { |
| 305 | 305 | $riga = $entry->fetch_array(MYSQLI_ASSOC); |
| 306 | - if (isListed($riga)) { |
|
| 306 | + if (isListed($riga)) { |
|
| 307 | 307 | $warn = "<$value> is already present in <$listdep> list!"; |
| 308 | 308 | $entry->free(); |
| 309 | 309 | return FALSE; |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | function searchentry ($myconn,$value,$tablelist) { |
| 321 | 321 | /* Make a MYSQL query and return result */ |
| 322 | 322 | |
| 323 | - $type = $tablelist['field']; |
|
| 323 | + $type = $tablelist['field']; |
|
| 324 | 324 | |
| 325 | 325 | if ( $tablelist['milter'] ) { |
| 326 | 326 | $table = milterTable($type); |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | case 'ip': |
| 345 | 345 | $query = sprintf('SELECT * FROM ( |
| 346 | 346 | SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id)' . |
| 347 | - 'WHERE `ip` = INET_ATON(\'%s\') |
|
| 347 | + 'WHERE `ip` = INET_ATON(\'%s\') |
|
| 348 | 348 | ) AS val WHERE val.ip IS NOT null', $table, $table, $value); |
| 349 | 349 | break; |
| 350 | 350 | default: |
@@ -355,33 +355,33 @@ discard block |
||
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | else { |
| 358 | - $table = $tablelist['name']; |
|
| 359 | - if ($value == 'ALL') $query = 'select * from '.$table; |
|
| 360 | - else { |
|
| 361 | - switch ($type) { |
|
| 362 | - case 'ip': |
|
| 363 | - $query= "select * from $table where $type = INET_ATON('$value')"; |
|
| 364 | - break; |
|
| 365 | - case 'network': |
|
| 366 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
| 367 | - $query= sprintf('select * from `%s` |
|
| 358 | + $table = $tablelist['name']; |
|
| 359 | + if ($value == 'ALL') $query = 'select * from '.$table; |
|
| 360 | + else { |
|
| 361 | + switch ($type) { |
|
| 362 | + case 'ip': |
|
| 363 | + $query= "select * from $table where $type = INET_ATON('$value')"; |
|
| 364 | + break; |
|
| 365 | + case 'network': |
|
| 366 | + list($sub['net'],$sub['mask'])=explode('/',$value); |
|
| 367 | + $query= sprintf('select * from `%s` |
|
| 368 | 368 | WHERE ( |
| 369 | 369 | inet_aton(\'%s\') >= network AND |
| 370 | 370 | ( inet_aton(\'%s\') | ( inet_aton(\'%s\') ^ (power(2,32)-1) ) ) |
| 371 | 371 | <= network | ( netmask ^ (power(2,32)-1) ) |
| 372 | 372 | )', $table, $sub['net'], $sub['net'], $sub['mask']); |
| 373 | 373 | ; |
| 374 | - break; |
|
| 375 | - default: |
|
| 376 | - $query= "select * from $table where $type = '$value'"; |
|
| 377 | - } |
|
| 378 | - } |
|
| 374 | + break; |
|
| 375 | + default: |
|
| 376 | + $query= "select * from $table where $type = '$value'"; |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | $result = $myconn->query($query); |
| 382 | 382 | if($result === false) |
| 383 | 383 | syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error); |
| 384 | - return $result; |
|
| 384 | + return $result; |
|
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | function countListed ($myconn,$table) { |
@@ -396,14 +396,14 @@ discard block |
||
| 396 | 396 | |
| 397 | 397 | |
| 398 | 398 | function isFull($myconn,$typedesc,$alltables) { |
| 399 | - if (isset($alltables["$typedesc"]['limit'])) { |
|
| 399 | + if (isset($alltables["$typedesc"]['limit'])) { |
|
| 400 | 400 | if ( $alltables["$typedesc"]['milter'] ) |
| 401 | 401 | $tab = 'net'; |
| 402 | 402 | else |
| 403 | 403 | $tab = $alltables["$typedesc"]['name']; |
| 404 | - if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) |
|
| 405 | - return TRUE; |
|
| 406 | - } |
|
| 404 | + if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) |
|
| 405 | + return TRUE; |
|
| 406 | + } |
|
| 407 | 407 | return FALSE; |
| 408 | 408 | } |
| 409 | 409 | |
@@ -428,14 +428,14 @@ discard block |
||
| 428 | 428 | if ($result) { |
| 429 | 429 | printf("<pre>Your request for $type <$value> returned %d items.\n</pre>", $result->num_rows); |
| 430 | 430 | |
| 431 | - /* Check for limit in number of listed items */ |
|
| 431 | + /* Check for limit in number of listed items */ |
|
| 432 | 432 | $full = isFull($myconn,$typedesc,$tables); |
| 433 | 433 | if ($full) print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>'; |
| 434 | 434 | |
| 435 | 435 | if ($result->num_rows) { |
| 436 | 436 | print $tabhtm; |
| 437 | 437 | $i=0; |
| 438 | - while ($riga = $result->fetch_array(MYSQLI_ASSOC)) { |
|
| 438 | + while ($riga = $result->fetch_array(MYSQLI_ASSOC)) { |
|
| 439 | 439 | if (isListed($riga)) { |
| 440 | 440 | if ($tables["$typedesc"]['bl']) $listed='Listed'; |
| 441 | 441 | else $listed='WhiteListed'; |
@@ -461,7 +461,7 @@ discard block |
||
| 461 | 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", |
| 462 | 462 | $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)); |
| 463 | 463 | $i++; |
| 464 | - } |
|
| 464 | + } |
|
| 465 | 465 | print '</tbody></table>'; |
| 466 | 466 | } |
| 467 | 467 | else { |
@@ -481,15 +481,15 @@ discard block |
||
| 481 | 481 | |
| 482 | 482 | function sendEmailWarn($tplf,$from,$to,$sbj,$emailListed,$intervalToExpire,$detail) { |
| 483 | 483 | $now = time(); |
| 484 | - setlocale (LC_TIME, 'it_IT'); |
|
| 485 | - $date = date("r",$now); |
|
| 484 | + setlocale (LC_TIME, 'it_IT'); |
|
| 485 | + $date = date("r",$now); |
|
| 486 | 486 | $messageID = md5(uniqid($now,1)) . '@' . gethostname(); |
| 487 | 487 | $mua = 'PHP/' . phpversion(); |
| 488 | 488 | |
| 489 | 489 | /* Parsing headers */ |
| 490 | 490 | if (!file_exists($tplf['header'])) { |
| 491 | - syslog(LOG_ERR, 'Sending email... template file <'.$tplf['header'].'> not found!'); |
|
| 492 | - exit; |
|
| 491 | + syslog(LOG_ERR, 'Sending email... template file <'.$tplf['header'].'> not found!'); |
|
| 492 | + exit; |
|
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | $head_tmpl = file_get_contents($tplf['header']); |
@@ -498,35 +498,35 @@ discard block |
||
| 498 | 498 | $headers = str_replace($arr_tpl_vars, $arr_tpl_data, $head_tmpl); |
| 499 | 499 | $headers = preg_replace( '/\r|\n/', "\r\n", $headers ); |
| 500 | 500 | |
| 501 | - /* Parsing body */ |
|
| 501 | + /* Parsing body */ |
|
| 502 | 502 | |
| 503 | - if (!file_exists($tplf['body'])) { |
|
| 504 | - syslog(LOG_ERR, 'Sending email... template file <'.$tplf['body'].'> not found!'); |
|
| 505 | - exit; |
|
| 506 | - } |
|
| 503 | + if (!file_exists($tplf['body'])) { |
|
| 504 | + syslog(LOG_ERR, 'Sending email... template file <'.$tplf['body'].'> not found!'); |
|
| 505 | + exit; |
|
| 506 | + } |
|
| 507 | 507 | |
| 508 | - $body_tmpl = file_get_contents($tplf['body']); |
|
| 509 | - $arr_tpl_vars = array('{emailListed}','{expInterval}','{reason}'); |
|
| 510 | - $arr_tpl_data = array($emailListed,$intervalToExpire,$detail); |
|
| 511 | - $body = str_replace($arr_tpl_vars, $arr_tpl_data, $body_tmpl); |
|
| 512 | - $body = preg_replace( "/\r|\n/", "\r\n", $body ); |
|
| 508 | + $body_tmpl = file_get_contents($tplf['body']); |
|
| 509 | + $arr_tpl_vars = array('{emailListed}','{expInterval}','{reason}'); |
|
| 510 | + $arr_tpl_data = array($emailListed,$intervalToExpire,$detail); |
|
| 511 | + $body = str_replace($arr_tpl_vars, $arr_tpl_data, $body_tmpl); |
|
| 512 | + $body = preg_replace( "/\r|\n/", "\r\n", $body ); |
|
| 513 | 513 | $body = wordwrap ( $body, 75 , "\r\n" ); |
| 514 | 514 | |
| 515 | 515 | /* Send the mail! */ |
| 516 | - if ( strlen(ini_get("safe_mode"))< 1) { |
|
| 517 | - $old_mailfrom = ini_get("sendmail_from"); |
|
| 518 | - ini_set("sendmail_from", $from); |
|
| 519 | - $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; |
|
| 528 | - } |
|
| 529 | - return $flag; |
|
| 516 | + if ( strlen(ini_get("safe_mode"))< 1) { |
|
| 517 | + $old_mailfrom = ini_get("sendmail_from"); |
|
| 518 | + ini_set("sendmail_from", $from); |
|
| 519 | + $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; |
|
| 528 | + } |
|
| 529 | + return $flag; |
|
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | function emailToNotify($notify_file,$dom) { |
@@ -540,62 +540,62 @@ discard block |
||
| 540 | 540 | function searchAndList ($myconn,$loguser,$tables,$typedesc,$value,$unit,&$quantity,&$reason) { |
| 541 | 541 | |
| 542 | 542 | /* Search and list value */ |
| 543 | - $type = $tables["$typedesc"]['field']; |
|
| 544 | - $table = $tables["$typedesc"]['name']; |
|
| 545 | - $result = searchentry ($myconn,$value,$tables["$typedesc"]); |
|
| 546 | - |
|
| 547 | - /* Manage abnormal conditions */ |
|
| 548 | - /* Value already present in db more than once. This is absurd. Panic! */ |
|
| 549 | - if ($result->num_rows > 1) { |
|
| 550 | - syslog(LOG_EMERG,"$loguser: PANIC! Select for $type '$value' returned ". $result->num_rows ." items instead of one. Abnormal. Contact a sysadmin or a developer."); |
|
| 551 | - $result->free(); |
|
| 552 | - return FALSE; |
|
| 553 | - } |
|
| 543 | + $type = $tables["$typedesc"]['field']; |
|
| 544 | + $table = $tables["$typedesc"]['name']; |
|
| 545 | + $result = searchentry ($myconn,$value,$tables["$typedesc"]); |
|
| 546 | + |
|
| 547 | + /* Manage abnormal conditions */ |
|
| 548 | + /* Value already present in db more than once. This is absurd. Panic! */ |
|
| 549 | + if ($result->num_rows > 1) { |
|
| 550 | + syslog(LOG_EMERG,"$loguser: PANIC! Select for $type '$value' returned ". $result->num_rows ." items instead of one. Abnormal. Contact a sysadmin or a developer."); |
|
| 551 | + $result->free(); |
|
| 552 | + return FALSE; |
|
| 553 | + } |
|
| 554 | 554 | |
| 555 | - /* Value already present in db or not present: to list anyway */ |
|
| 556 | - if ($result->num_rows >= 0) { |
|
| 557 | - /* First, check for limit in number of listed items */ |
|
| 558 | - if (isFull($myconn,$typedesc,$tables)) { |
|
| 559 | - syslog(LOG_EMERG,"$loguser: $typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items. Abnormal exit.'); |
|
| 560 | - $result->free(); |
|
| 561 | - return FALSE; |
|
| 562 | - } |
|
| 563 | - /* Second, check if the (re)list would be consistent now */ |
|
| 564 | - if (! consistentListing($myconn,$tables,$typedesc,$value,$whynot) ) { |
|
| 565 | - syslog(LOG_ERR, $loguser.': '.$whynot); |
|
| 566 | - $result->free(); |
|
| 567 | - return FALSE; |
|
| 568 | - } |
|
| 569 | - } |
|
| 570 | - /* End of abnormal conditions */ |
|
| 555 | + /* Value already present in db or not present: to list anyway */ |
|
| 556 | + if ($result->num_rows >= 0) { |
|
| 557 | + /* First, check for limit in number of listed items */ |
|
| 558 | + if (isFull($myconn,$typedesc,$tables)) { |
|
| 559 | + syslog(LOG_EMERG,"$loguser: $typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items. Abnormal exit.'); |
|
| 560 | + $result->free(); |
|
| 561 | + return FALSE; |
|
| 562 | + } |
|
| 563 | + /* Second, check if the (re)list would be consistent now */ |
|
| 564 | + if (! consistentListing($myconn,$tables,$typedesc,$value,$whynot) ) { |
|
| 565 | + syslog(LOG_ERR, $loguser.': '.$whynot); |
|
| 566 | + $result->free(); |
|
| 567 | + return FALSE; |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | + /* End of abnormal conditions */ |
|
| 571 | 571 | |
| 572 | 572 | |
| 573 | - /* Finally, here I can list the value! */ |
|
| 573 | + /* Finally, here I can list the value! */ |
|
| 574 | 574 | $thisentry = $result->fetch_array(MYSQLI_ASSOC); |
| 575 | - switch ($result->num_rows) { |
|
| 576 | - /* Relist value if already present */ |
|
| 577 | - case 1: |
|
| 578 | - if ( isListed($thisentry) ) { |
|
| 575 | + switch ($result->num_rows) { |
|
| 576 | + /* Relist value if already present */ |
|
| 577 | + case 1: |
|
| 578 | + if ( isListed($thisentry) ) { |
|
| 579 | 579 | /* Entry already listed */ |
| 580 | 580 | $expdate = $thisentry['exp']; |
| 581 | 581 | $reason = sprintf('%s. Already listed. Adding 1 DAY to previous expire date.', |
| 582 | 582 | $reason); |
| 583 | 583 | $quantity = 1; |
| 584 | 584 | $unit = 'DAY'; |
| 585 | - } |
|
| 585 | + } |
|
| 586 | 586 | else { |
| 587 | - /* Entry delisted */ |
|
| 587 | + /* Entry delisted */ |
|
| 588 | 588 | $quantity *= $thisentry['nlist']; |
| 589 | 589 | $expdate = 0; /* This forces expiration from CURRENT_TIMESTAMP */ |
| 590 | 590 | } |
| 591 | 591 | $result->free(); |
| 592 | - return relist ($myconn,$loguser,$value,$type,$table,$unit,$quantity,$reason, $expdate); |
|
| 592 | + return relist ($myconn,$loguser,$value,$type,$table,$unit,$quantity,$reason, $expdate); |
|
| 593 | 593 | |
| 594 | - /* First time list value */ |
|
| 595 | - case 0: |
|
| 596 | - $result->free(); |
|
| 597 | - return addtolist ($myconn,$loguser,$value,$tables["$typedesc"],$unit,$quantity,$reason,$_); |
|
| 598 | - } |
|
| 594 | + /* First time list value */ |
|
| 595 | + case 0: |
|
| 596 | + $result->free(); |
|
| 597 | + return addtolist ($myconn,$loguser,$value,$tables["$typedesc"],$unit,$quantity,$reason,$_); |
|
| 598 | + } |
|
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | |
@@ -628,7 +628,7 @@ discard block |
||
| 628 | 628 | return FALSE; |
| 629 | 629 | } |
| 630 | 630 | $result = searchentry ($myconn,'ALL',$tabletype); |
| 631 | - if ($result->num_rows) { |
|
| 631 | + if ($result->num_rows) { |
|
| 632 | 632 | while ($row = $result->fetch_array(MYSQLI_ASSOC)) { |
| 633 | 633 | $thisNet = long2ip($row['network']).'/'.long2ip($row['netmask']); |
| 634 | 634 | if ( isIn($thisNet, $net) ) { |
@@ -648,7 +648,7 @@ discard block |
||
| 648 | 648 | /* For miltermap */ |
| 649 | 649 | function checkMilterConf($table) { |
| 650 | 650 | if (isset($table['milter'])) { |
| 651 | - if ($table['milter'] === TRUE) { |
|
| 651 | + if ($table['milter'] === TRUE) { |
|
| 652 | 652 | switch ( $table['field'] ) { |
| 653 | 653 | case 'network': |
| 654 | 654 | case 'ip': |
@@ -671,15 +671,15 @@ discard block |
||
| 671 | 671 | |
| 672 | 672 | function milterTable($t) { |
| 673 | 673 | /* Return the milter object table for type t or FALSE on error */ |
| 674 | - switch ($t) { |
|
| 675 | - case 'network': |
|
| 676 | - return 'net'; |
|
| 677 | - case 'ip': |
|
| 678 | - return 'ips'; |
|
| 679 | - default: |
|
| 674 | + switch ($t) { |
|
| 675 | + case 'network': |
|
| 676 | + return 'net'; |
|
| 677 | + case 'ip': |
|
| 678 | + return 'ips'; |
|
| 679 | + default: |
|
| 680 | 680 | syslog(LOG_EMERG, "ALERT: type <$t> not allowed in configuration. "); |
| 681 | - return FALSE; |
|
| 682 | - } |
|
| 681 | + return FALSE; |
|
| 682 | + } |
|
| 683 | 683 | } |
| 684 | 684 | |
| 685 | 685 | |
@@ -687,9 +687,9 @@ discard block |
||
| 687 | 687 | $milters=array(); |
| 688 | 688 | $query = 'SELECT `name` FROM `config`'; |
| 689 | 689 | |
| 690 | - $result = $myconn->query($query); |
|
| 691 | - if($result === false) { |
|
| 692 | - syslog(LOG_EMERG, "$loguser: ALERT: Query <$query> failed: ".$myconn->error); |
|
| 690 | + $result = $myconn->query($query); |
|
| 691 | + if($result === false) { |
|
| 692 | + syslog(LOG_EMERG, "$loguser: ALERT: Query <$query> failed: ".$myconn->error); |
|
| 693 | 693 | return FALSE; |
| 694 | 694 | } |
| 695 | 695 | if ($result->num_rows) { |
@@ -759,21 +759,21 @@ discard block |
||
| 759 | 759 | |
| 760 | 760 | function curl_get($url, array $get = NULL, array $options = array(), $loguser) |
| 761 | 761 | { |
| 762 | - $defaults = array( |
|
| 763 | - CURLOPT_URL => $url. (strpos($url, '?') === FALSE ? '?' : ''). http_build_query($get), |
|
| 764 | - CURLOPT_HEADER => 0, |
|
| 765 | - CURLOPT_RETURNTRANSFER => TRUE, |
|
| 766 | - CURLOPT_TIMEOUT => 4 |
|
| 767 | - ); |
|
| 768 | - |
|
| 769 | - $ch = curl_init(); |
|
| 770 | - curl_setopt_array($ch, ($options + $defaults)); |
|
| 771 | - if( ! $result = curl_exec($ch)) |
|
| 772 | - { |
|
| 773 | - syslog(LOG_ERR, sprintf('%s: CURL Error: <%s>', $loguser, curl_error($ch))); |
|
| 774 | - } |
|
| 775 | - curl_close($ch); |
|
| 776 | - return $result; |
|
| 762 | + $defaults = array( |
|
| 763 | + CURLOPT_URL => $url. (strpos($url, '?') === FALSE ? '?' : ''). http_build_query($get), |
|
| 764 | + CURLOPT_HEADER => 0, |
|
| 765 | + CURLOPT_RETURNTRANSFER => TRUE, |
|
| 766 | + CURLOPT_TIMEOUT => 4 |
|
| 767 | + ); |
|
| 768 | + |
|
| 769 | + $ch = curl_init(); |
|
| 770 | + curl_setopt_array($ch, ($options + $defaults)); |
|
| 771 | + if( ! $result = curl_exec($ch)) |
|
| 772 | + { |
|
| 773 | + syslog(LOG_ERR, sprintf('%s: CURL Error: <%s>', $loguser, curl_error($ch))); |
|
| 774 | + } |
|
| 775 | + curl_close($ch); |
|
| 776 | + return $result; |
|
| 777 | 777 | } |
| 778 | 778 | |
| 779 | 779 | |
@@ -10,7 +10,7 @@ discard block |
||
| 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 (!(isValid($_POST['Value']))) |
|
| 13 | + if (!(isValid($_POST['Value']))) |
|
| 14 | 14 | exit ('<pre><'.$_POST['Value'].'> is NOT a valid domain.</pre>'); |
| 15 | 15 | |
| 16 | 16 | if ( ($tables["$_"]['field']=='ip') AND ($_POST['Value']!='ALL') ) |
@@ -27,8 +27,8 @@ discard block |
||
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | 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>'); |
|
| 30 | + if ( preg_match( '/[^\x20-\x7f]/', $_POST['Value']) ) |
|
| 31 | + exit('<pre><'.$_POST['Value'].'> contains NON ASCII chars.</pre>'); |
|
| 32 | 32 | if ( preg_match( '/[$~=#*+%,{}()\/\\<>;:\"`\[\]&?\s]/', $_POST['Value']) ) |
| 33 | 33 | exit('<pre><'.$_POST['Value'].'> contains invalid ASCII chars.</pre>'); |
| 34 | 34 | switch ( $_POST['Value'] ) { |
@@ -19,7 +19,7 @@ |
||
| 19 | 19 | <?php |
| 20 | 20 | $reports = array(); |
| 21 | 21 | foreach (glob("*.{htm,html}", GLOB_BRACE) as $filename) { |
| 22 | - $reports[$filename] = filemtime($filename); |
|
| 22 | + $reports[$filename] = filemtime($filename); |
|
| 23 | 23 | } |
| 24 | 24 | arsort($reports); |
| 25 | 25 | $newest = new DateTime('@'.array_shift($reports)); |
@@ -5,10 +5,10 @@ discard block |
||
| 5 | 5 | include_once($path.'config.php'); |
| 6 | 6 | require_once($path.'function.php'); |
| 7 | 7 | if ( !isset($version) ) { |
| 8 | - openlog('myRBLemergency', LOG_PID, LOG_LOCAL0); |
|
| 9 | - syslog (LOG_EMERG, 'unknown: I can\'t read the config files. Do you have configured the $path in getip.php?'); |
|
| 10 | - closelog(); |
|
| 11 | - exit(255); |
|
| 8 | + openlog('myRBLemergency', LOG_PID, LOG_LOCAL0); |
|
| 9 | + syslog (LOG_EMERG, 'unknown: I can\'t read the config files. Do you have configured the $path in getip.php?'); |
|
| 10 | + closelog(); |
|
| 11 | + exit(255); |
|
| 12 | 12 | } |
| 13 | 13 | include_once(dirname(__FILE__) . '/function.php'); |
| 14 | 14 | $conf = parse_ini_file($confImap_file, TRUE, INI_SCANNER_TYPED); |
@@ -35,50 +35,50 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | /* check you select a right list */ |
| 37 | 37 | if ( !$tables[$conf['listingip']['list']['spam']]['bl'] ) { |
| 38 | - syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingip']['list']['spam'].'> is not a blocklist. Are you stupid? Do you want to whitelist a spammer? I refuse to continue.'); |
|
| 39 | - exit (254); |
|
| 38 | + syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingip']['list']['spam'].'> is not a blocklist. Are you stupid? Do you want to whitelist a spammer? I refuse to continue.'); |
|
| 39 | + exit (254); |
|
| 40 | 40 | } |
| 41 | 41 | if ( !$tables[$conf['listingip']['list']['spam']]['active'] ) { |
| 42 | 42 | syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingip']['list']['spam'].'> is not active. Please, activate it to continue with this process.'); |
| 43 | 43 | exit (254); |
| 44 | - } |
|
| 44 | + } |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | if ( !$conf['listingip']['onlyReport']['ham'] ) { |
| 48 | 48 | if ( $tables[$conf['listingip']['list']['ham']]['bl'] ) { |
| 49 | - syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingip']['list']['ham'].'> is a blocklist. Are you stupid? Do you want to block a legitimate sender? I refuse to continue.'); |
|
| 50 | - exit (254); |
|
| 49 | + syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingip']['list']['ham'].'> is a blocklist. Are you stupid? Do you want to block a legitimate sender? I refuse to continue.'); |
|
| 50 | + exit (254); |
|
| 51 | 51 | } |
| 52 | - if ( !$tables[$conf['listingip']['list']['ham']]['active'] ) { |
|
| 53 | - syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingip']['list']['ham'].'> is not active. Please, activate it |
|
| 52 | + if ( !$tables[$conf['listingip']['list']['ham']]['active'] ) { |
|
| 53 | + syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingip']['list']['ham'].'> is not active. Please, activate it |
|
| 54 | 54 | to continue with this process.'); |
| 55 | - exit (254); |
|
| 56 | - } |
|
| 55 | + exit (254); |
|
| 56 | + } |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | if ( !$conf['listingdom']['onlyReport']['spam'] ) { |
| 60 | 60 | |
| 61 | - /* check you select a right list */ |
|
| 62 | - if ( !$tables[$conf['listingdom']['list']['spam']]['bl'] ) { |
|
| 63 | - syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingdom']['list']['spam'].'> is not a blocklist. Are you stupid? Do you want to whitelist a spam domain? I refuse to continue.'); |
|
| 64 | - exit (254); |
|
| 65 | - } |
|
| 66 | - if ( !$tables[$conf['listingdom']['list']['spam']]['active'] ) { |
|
| 67 | - syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingdom']['list']['spam'].'> is not active. Please, activate it to continue with this process.'); |
|
| 68 | - exit (254); |
|
| 69 | - } |
|
| 61 | + /* check you select a right list */ |
|
| 62 | + if ( !$tables[$conf['listingdom']['list']['spam']]['bl'] ) { |
|
| 63 | + syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingdom']['list']['spam'].'> is not a blocklist. Are you stupid? Do you want to whitelist a spam domain? I refuse to continue.'); |
|
| 64 | + exit (254); |
|
| 65 | + } |
|
| 66 | + if ( !$tables[$conf['listingdom']['list']['spam']]['active'] ) { |
|
| 67 | + syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingdom']['list']['spam'].'> is not active. Please, activate it to continue with this process.'); |
|
| 68 | + exit (254); |
|
| 69 | + } |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | if ( !$conf['listingdom']['onlyReport']['ham'] ) { |
| 73 | - if ( $tables[$conf['listingdom']['list']['ham']]['bl'] ) { |
|
| 74 | - syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingdom']['list']['ham'].'> is a blocklist. Are you stupid? Do you want to block a legitimate sender? I refuse to continue.'); |
|
| 75 | - exit (254); |
|
| 76 | - } |
|
| 77 | - if ( !$tables[$conf['listingdom']['list']['ham']]['active'] ) { |
|
| 78 | - syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingdom']['list']['ham'].'> is not active. Please, activate it |
|
| 73 | + if ( $tables[$conf['listingdom']['list']['ham']]['bl'] ) { |
|
| 74 | + syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingdom']['list']['ham'].'> is a blocklist. Are you stupid? Do you want to block a legitimate sender? I refuse to continue.'); |
|
| 75 | + exit (254); |
|
| 76 | + } |
|
| 77 | + if ( !$tables[$conf['listingdom']['list']['ham']]['active'] ) { |
|
| 78 | + syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingdom']['list']['ham'].'> is not active. Please, activate it |
|
| 79 | 79 | to continue with this process.'); |
| 80 | - exit (254); |
|
| 81 | - } |
|
| 80 | + exit (254); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | 83 | } |
| 84 | 84 | /* End of check list */ |
@@ -12,14 +12,14 @@ discard block |
||
| 12 | 12 | # print "Examine ".$received[0][$i]."\n"; |
| 13 | 13 | if ( preg_match($msa,$received['host'][$i]) ) |
| 14 | 14 | $dateR = $received['date'][$i]; |
| 15 | - foreach ($mxserver as $mx) { |
|
| 16 | - if (!$ip) |
|
| 15 | + foreach ($mxserver as $mx) { |
|
| 16 | + if (!$ip) |
|
| 17 | 17 | if ($mx == $received['host'][$i]) { |
| 18 | 18 | $host = $received['host'][$i]; |
| 19 | 19 | $ip = $received['ip'][$i]; |
| 20 | - } |
|
| 21 | - } |
|
| 22 | - } |
|
| 20 | + } |
|
| 21 | + } |
|
| 22 | + } |
|
| 23 | 23 | } |
| 24 | 24 | if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$dateC) != 1) |
| 25 | 25 | $dateC['date'] = 'Not found'; |
@@ -39,15 +39,15 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | |
| 41 | 41 | function summaryBadReport ($uidvet) { |
| 42 | - $nuid = $uidvet['count']; |
|
| 43 | - if ( empty($uidvet) ) return NULL; |
|
| 44 | - $return = '<hr><h3>Statistics by UID</h3><table><tr><th>UID</th><th>Learned times</th></tr>'."\n"; |
|
| 42 | + $nuid = $uidvet['count']; |
|
| 43 | + if ( empty($uidvet) ) return NULL; |
|
| 44 | + $return = '<hr><h3>Statistics by UID</h3><table><tr><th>UID</th><th>Learned times</th></tr>'."\n"; |
|
| 45 | 45 | |
| 46 | - /* Remove count index */ |
|
| 47 | - $uids = array_keys($uidvet['uid']); |
|
| 46 | + /* Remove count index */ |
|
| 47 | + $uids = array_keys($uidvet['uid']); |
|
| 48 | 48 | $totlearn = 0; |
| 49 | 49 | |
| 50 | - foreach ( $uids as $uid ) { |
|
| 50 | + foreach ( $uids as $uid ) { |
|
| 51 | 51 | $totlearn += $uidvet['uid']["$uid"]['count'];; |
| 52 | 52 | $return .= sprintf ('<tr><td>%s</td><td>%u</td></tr>',$uid,$uidvet['uid']["$uid"]['count']); |
| 53 | 53 | } |
@@ -60,26 +60,26 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | function array_msort($array, $cols) |
| 62 | 62 | { |
| 63 | - $colarr = array(); |
|
| 64 | - foreach ($cols as $col => $order) { |
|
| 65 | - $colarr[$col] = array(); |
|
| 66 | - foreach ($array as $k => $row) { $colarr[$col]['_'.$k] = strtolower($row[$col]); } |
|
| 67 | - } |
|
| 68 | - $eval = 'array_multisort('; |
|
| 69 | - foreach ($cols as $col => $order) { |
|
| 70 | - $eval .= '$colarr[\''.$col.'\'],'.$order.','; |
|
| 71 | - } |
|
| 72 | - $eval = substr($eval,0,-1).');'; |
|
| 73 | - eval($eval); |
|
| 74 | - $ret = array(); |
|
| 75 | - foreach ($colarr as $col => $arr) { |
|
| 76 | - foreach ($arr as $k => $v) { |
|
| 77 | - $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]; |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - return $ret; |
|
| 63 | + $colarr = array(); |
|
| 64 | + foreach ($cols as $col => $order) { |
|
| 65 | + $colarr[$col] = array(); |
|
| 66 | + foreach ($array as $k => $row) { $colarr[$col]['_'.$k] = strtolower($row[$col]); } |
|
| 67 | + } |
|
| 68 | + $eval = 'array_multisort('; |
|
| 69 | + foreach ($cols as $col => $order) { |
|
| 70 | + $eval .= '$colarr[\''.$col.'\'],'.$order.','; |
|
| 71 | + } |
|
| 72 | + $eval = substr($eval,0,-1).');'; |
|
| 73 | + eval($eval); |
|
| 74 | + $ret = array(); |
|
| 75 | + foreach ($colarr as $col => $arr) { |
|
| 76 | + foreach ($arr as $k => $v) { |
|
| 77 | + $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]; |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + return $ret; |
|
| 83 | 83 | |
| 84 | 84 | } |
| 85 | 85 | |
@@ -95,8 +95,8 @@ discard block |
||
| 95 | 95 | |
| 96 | 96 | foreach ( $values as $value ) { |
| 97 | 97 | if ( $value == 'count' ) continue; |
| 98 | - $nlearn = $vet["$key"]["$value"]['count']; |
|
| 99 | - unset($vet["$key"]["$value"]['count']); |
|
| 98 | + $nlearn = $vet["$key"]["$value"]['count']; |
|
| 99 | + unset($vet["$key"]["$value"]['count']); |
|
| 100 | 100 | $quantity = $cf["listing$key"]['quantity']["$category"]; /* In searchAndList this value is |
| 101 | 101 | passed by reference and modified */ |
| 102 | 102 | $nuid = count($vet["$key"]["$value"]); |
@@ -127,9 +127,9 @@ discard block |
||
| 127 | 127 | $return .='<tr><td rowspan="'.$nuid.'">'.$value.'</td>'; |
| 128 | 128 | $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 | 129 | $rowuid=NULL; |
| 130 | - for ($j=1;$j<$nuid;$j++) $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 130 | + for ($j=1;$j<$nuid;$j++) $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 131 | 131 | array_shift($vet["$key"]["$value"]); |
| 132 | - $return .= vsprintf ($rowuid,$vet["$key"]["$value"]); |
|
| 132 | + $return .= vsprintf ($rowuid,$vet["$key"]["$value"]); |
|
| 133 | 133 | |
| 134 | 134 | } |
| 135 | 135 | $return .= sprintf ('<tr><th title="unique %s">%u</th><th title="unique uids">%u</th><th>%u</th></table>',$key,$vet["$key"]['count'],$vet['uid']['count'],$nk); |
@@ -139,20 +139,20 @@ discard block |
||
| 139 | 139 | /* Not used for listing purpose, but useful to you! */ |
| 140 | 140 | $return .= sprintf('<h3>Statistics by UID</h3><table><tr><th>UID</th><th>%s learned</th><th>Learned times</th></tr>'."\n",$key); |
| 141 | 141 | $uids = array_keys($vet['uid']); |
| 142 | - foreach ( $uids as $uid ) { |
|
| 142 | + foreach ( $uids as $uid ) { |
|
| 143 | 143 | if ( $uid == 'count' ) continue; |
| 144 | - $nlearn = $vet['uid']["$uid"]['count']; |
|
| 145 | - unset ( $vet['uid']["$uid"]['count'] ); |
|
| 144 | + $nlearn = $vet['uid']["$uid"]['count']; |
|
| 145 | + unset ( $vet['uid']["$uid"]['count'] ); |
|
| 146 | 146 | $nip = count($vet['uid']["$uid"]); |
| 147 | 147 | $return .='<tr><td rowspan="'.$nip.'">'.$uid.'</td>'; |
| 148 | 148 | $return .= sprintf ('<td>%s</td><td rowspan="'.$nip.'">%u</td></tr>',$vet['uid']["$uid"][0],$nlearn); |
| 149 | - $rowuid=NULL; |
|
| 150 | - for ($j=1;$j<$nip;$j++) $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 151 | - array_shift($vet['uid']["$uid"]); |
|
| 152 | - $return .= vsprintf ($rowuid,$vet['uid']["$uid"]); |
|
| 149 | + $rowuid=NULL; |
|
| 150 | + for ($j=1;$j<$nip;$j++) $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 151 | + array_shift($vet['uid']["$uid"]); |
|
| 152 | + $return .= vsprintf ($rowuid,$vet['uid']["$uid"]); |
|
| 153 | 153 | |
| 154 | - } |
|
| 155 | - $return .= sprintf ('<tr><th title="unique uids">%u</th><th title="unique %s">%u</th><th>%u</th></table>', |
|
| 154 | + } |
|
| 155 | + $return .= sprintf ('<tr><th title="unique uids">%u</th><th title="unique %s">%u</th><th>%u</th></table>', |
|
| 156 | 156 | $vet['uid']['count'],$key,$vet["$key"]['count'],$nk); |
| 157 | 157 | |
| 158 | 158 | |
@@ -181,50 +181,50 @@ discard block |
||
| 181 | 181 | */ |
| 182 | 182 | |
| 183 | 183 | // A one shot search |
| 184 | - $searchParams = array( |
|
| 185 | - 'earliest_time' => date("c",strtotime ($date)-120), |
|
| 186 | - 'latest_time' => date("c",strtotime ($date)+60) |
|
| 187 | - ); |
|
| 184 | + $searchParams = array( |
|
| 185 | + 'earliest_time' => date("c",strtotime ($date)-120), |
|
| 186 | + 'latest_time' => date("c",strtotime ($date)+60) |
|
| 187 | + ); |
|
| 188 | 188 | |
| 189 | - // Run a oneshot search that returns the job's results |
|
| 190 | - $resultsStream = $service->oneshotSearch($searchQueryBlocking, $searchParams); |
|
| 191 | - $resultSearch = new Splunk_ResultsReader($resultsStream); |
|
| 189 | + // Run a oneshot search that returns the job's results |
|
| 190 | + $resultsStream = $service->oneshotSearch($searchQueryBlocking, $searchParams); |
|
| 191 | + $resultSearch = new Splunk_ResultsReader($resultsStream); |
|
| 192 | 192 | |
| 193 | 193 | // Use the built-in XML parser to display the job results |
| 194 | 194 | foreach ($resultSearch as $result) |
| 195 | 195 | { |
| 196 | - if ($result instanceof Splunk_ResultsFieldOrder) |
|
| 197 | - { |
|
| 198 | - // More than one field attribute returned by search |
|
| 199 | - // You must redefine the search |
|
| 200 | - if ( count($result->getFieldNames()) > 1 ) return FALSE; |
|
| 201 | - } |
|
| 202 | - else if ($result instanceof Splunk_ResultsMessage) |
|
| 203 | - { |
|
| 204 | - // I don't want messages in my search |
|
| 205 | - return FALSE; |
|
| 206 | - } |
|
| 207 | - else if (is_array($result)) |
|
| 208 | - { |
|
| 209 | - // Process a row |
|
| 210 | - foreach ($result as $key => $valueOrValues) |
|
| 211 | - { |
|
| 212 | - if (is_array($valueOrValues)) |
|
| 213 | - { |
|
| 214 | - return FALSE; |
|
| 215 | - } |
|
| 216 | - else |
|
| 217 | - { |
|
| 218 | - return $valueOrValues; |
|
| 219 | - #print " {$key} => {$value}\r\n"; |
|
| 220 | - } |
|
| 221 | - } |
|
| 222 | - } |
|
| 223 | - else |
|
| 224 | - { |
|
| 225 | - #print "Unknow result type"; |
|
| 226 | - return FALSE; |
|
| 227 | - } |
|
| 196 | + if ($result instanceof Splunk_ResultsFieldOrder) |
|
| 197 | + { |
|
| 198 | + // More than one field attribute returned by search |
|
| 199 | + // You must redefine the search |
|
| 200 | + if ( count($result->getFieldNames()) > 1 ) return FALSE; |
|
| 201 | + } |
|
| 202 | + else if ($result instanceof Splunk_ResultsMessage) |
|
| 203 | + { |
|
| 204 | + // I don't want messages in my search |
|
| 205 | + return FALSE; |
|
| 206 | + } |
|
| 207 | + else if (is_array($result)) |
|
| 208 | + { |
|
| 209 | + // Process a row |
|
| 210 | + foreach ($result as $key => $valueOrValues) |
|
| 211 | + { |
|
| 212 | + if (is_array($valueOrValues)) |
|
| 213 | + { |
|
| 214 | + return FALSE; |
|
| 215 | + } |
|
| 216 | + else |
|
| 217 | + { |
|
| 218 | + return $valueOrValues; |
|
| 219 | + #print " {$key} => {$value}\r\n"; |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | + else |
|
| 224 | + { |
|
| 225 | + #print "Unknow result type"; |
|
| 226 | + return FALSE; |
|
| 227 | + } |
|
| 228 | 228 | } |
| 229 | 229 | } |
| 230 | 230 | |
@@ -235,38 +235,38 @@ discard block |
||
| 235 | 235 | |
| 236 | 236 | function flattenParts($messageParts, $flattenedParts = array(), $prefix = '', $index = 1, $fullPrefix = true) { |
| 237 | 237 | |
| 238 | - foreach($messageParts as $part) { |
|
| 239 | - $flattenedParts[$prefix.$index] = $part; |
|
| 240 | - if(isset($part->parts)) { |
|
| 241 | - if($part->type == 2) { |
|
| 242 | - $flattenedParts = flattenParts($part->parts, $flattenedParts, $prefix.$index.'.', 0, false); |
|
| 243 | - } |
|
| 244 | - elseif($fullPrefix) { |
|
| 245 | - $flattenedParts = flattenParts($part->parts, $flattenedParts, $prefix.$index.'.'); |
|
| 246 | - } |
|
| 247 | - else { |
|
| 248 | - $flattenedParts = flattenParts($part->parts, $flattenedParts, $prefix); |
|
| 249 | - } |
|
| 250 | - unset($flattenedParts[$prefix.$index]->parts); |
|
| 251 | - } |
|
| 252 | - $index++; |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - return $flattenedParts; |
|
| 238 | + foreach($messageParts as $part) { |
|
| 239 | + $flattenedParts[$prefix.$index] = $part; |
|
| 240 | + if(isset($part->parts)) { |
|
| 241 | + if($part->type == 2) { |
|
| 242 | + $flattenedParts = flattenParts($part->parts, $flattenedParts, $prefix.$index.'.', 0, false); |
|
| 243 | + } |
|
| 244 | + elseif($fullPrefix) { |
|
| 245 | + $flattenedParts = flattenParts($part->parts, $flattenedParts, $prefix.$index.'.'); |
|
| 246 | + } |
|
| 247 | + else { |
|
| 248 | + $flattenedParts = flattenParts($part->parts, $flattenedParts, $prefix); |
|
| 249 | + } |
|
| 250 | + unset($flattenedParts[$prefix.$index]->parts); |
|
| 251 | + } |
|
| 252 | + $index++; |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + return $flattenedParts; |
|
| 256 | 256 | |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | function getPart($connection, $messageNumber, $partNumber, $encoding) { |
| 260 | 260 | |
| 261 | - $data = imap_fetchbody($connection, $messageNumber, $partNumber); |
|
| 262 | - switch($encoding) { |
|
| 263 | - case 0: return $data; // 7BIT |
|
| 264 | - case 1: return $data; // 8BIT |
|
| 265 | - case 2: return $data; // BINARY |
|
| 266 | - case 3: return base64_decode($data); // BASE64 |
|
| 267 | - case 4: return quoted_printable_decode($data); // QUOTED_PRINTABLE |
|
| 268 | - case 5: return $data; // OTHER |
|
| 269 | - } |
|
| 261 | + $data = imap_fetchbody($connection, $messageNumber, $partNumber); |
|
| 262 | + switch($encoding) { |
|
| 263 | + case 0: return $data; // 7BIT |
|
| 264 | + case 1: return $data; // 8BIT |
|
| 265 | + case 2: return $data; // BINARY |
|
| 266 | + case 3: return base64_decode($data); // BASE64 |
|
| 267 | + case 4: return quoted_printable_decode($data); // QUOTED_PRINTABLE |
|
| 268 | + case 5: return $data; // OTHER |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | 271 | |
| 272 | 272 | } |
@@ -341,16 +341,16 @@ discard block |
||
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | function writeFileHeader($f,$conf,$key,$type,$rtime) { |
| 344 | - fwrite( $f, file_get_contents(dirname(__FILE__) . '/' . $conf['report']['reportTemplateHeader']) ); |
|
| 345 | - fwrite( $f,sprintf('<h1> Report of %s %s</h1><h5>%s</h5><h2>Detailed Report</h2>',$type, strtoupper(humanKey($key)),$rtime) ); |
|
| 346 | - if ($conf["listing$key"]['onlyReport']["$type"]) { |
|
| 347 | - fwrite( $f,sprintf('<p>None of the below %s have been listed because listing is not active in configuration.</p>', |
|
| 344 | + fwrite( $f, file_get_contents(dirname(__FILE__) . '/' . $conf['report']['reportTemplateHeader']) ); |
|
| 345 | + fwrite( $f,sprintf('<h1> Report of %s %s</h1><h5>%s</h5><h2>Detailed Report</h2>',$type, strtoupper(humanKey($key)),$rtime) ); |
|
| 346 | + if ($conf["listing$key"]['onlyReport']["$type"]) { |
|
| 347 | + fwrite( $f,sprintf('<p>None of the below %s have been listed because listing is not active in configuration.</p>', |
|
| 348 | 348 | strtoupper(humanKey($key))) ); |
| 349 | 349 | syslog(LOG_INFO, sprintf('%s: Report only for %s %s: no listing activated in configuration.', |
| 350 | 350 | $conf['syslog']['user'],$type,humanKey($key)) |
| 351 | 351 | ); |
| 352 | 352 | } |
| 353 | - fwrite( $f,sprintf('<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>%s</th><th title="How many times this uid learns">#UID</th><th title="Number of times this learned %s appears in different mails">#%s</th><th nowrap>Received by</th><th>Message-Id</th></tr>', |
|
| 353 | + fwrite( $f,sprintf('<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>%s</th><th title="How many times this uid learns">#UID</th><th title="Number of times this learned %s appears in different mails">#%s</th><th nowrap>Received by</th><th>Message-Id</th></tr>', |
|
| 354 | 354 | strtoupper($key),strtoupper($key),strtoupper($key)) ); |
| 355 | 355 | } |
| 356 | 356 | |
@@ -360,25 +360,25 @@ discard block |
||
| 360 | 360 | $filed = dirname(__FILE__) . '/' . $cf['report']['reportDomFile']["$type"]; |
| 361 | 361 | $fileb= dirname(__FILE__) . '/' . $cf['report']['badreportFile']["$type"]; |
| 362 | 362 | $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) |
| 363 | - or syslog (LOG_EMERG, $cf['syslog']['user'].': Error in IMAP connection to <'.$cf['imap']['mailhost'].'>: ' . imap_last_error()); |
|
| 363 | + or syslog (LOG_EMERG, $cf['syslog']['user'].': Error in IMAP connection to <'.$cf['imap']['mailhost'].'>: ' . imap_last_error()); |
|
| 364 | 364 | if ( !$m_mail ) exit(254); |
| 365 | 365 | |
| 366 | 366 | |
| 367 | 367 | syslog (LOG_INFO,$cf['syslog']['user'].': Successfully connected to <'.$cf['imap']['mailhost'].">; Reading $type messages of last ".$cf['imap']['oldestday'].' days...'); |
| 368 | 368 | //get all messages |
| 369 | 369 | $dateTh = date ( "d-M-Y", strToTime ( '-'.$cf['imap']['oldestday'].' days' ) ); |
| 370 | - $dateN = date ( "d-M-Y", strToTime ( "now" ) ); |
|
| 371 | - $m_search=imap_search ($m_mail, "SINCE \"$dateTh\" BEFORE \"$dateN\"" ); |
|
| 370 | + $dateN = date ( "d-M-Y", strToTime ( "now" ) ); |
|
| 371 | + $m_search=imap_search ($m_mail, "SINCE \"$dateTh\" BEFORE \"$dateN\"" ); |
|
| 372 | 372 | |
| 373 | 373 | // Order results starting from newest message |
| 374 | 374 | if ( empty($m_search) ) { |
| 375 | 375 | syslog (LOG_INFO,$cf['syslog']['user'].": No mail found in $type folder. No reports written for $type."); |
| 376 | - if ( $ierr = imap_errors() ) |
|
| 377 | - foreach ( $ierr as $thiserr ) |
|
| 378 | - syslog (LOG_ERR, $cf['syslog']['user'].": IMAP Error: $thiserr"); |
|
| 379 | - if ( $ierr = imap_alerts() ) |
|
| 380 | - foreach ( $ierr as $thiserr ) |
|
| 381 | - syslog (LOG_ALERT, $cf['syslog']['user'].": IMAP Alert: $thiserr"); |
|
| 376 | + if ( $ierr = imap_errors() ) |
|
| 377 | + foreach ( $ierr as $thiserr ) |
|
| 378 | + syslog (LOG_ERR, $cf['syslog']['user'].": IMAP Error: $thiserr"); |
|
| 379 | + if ( $ierr = imap_alerts() ) |
|
| 380 | + foreach ( $ierr as $thiserr ) |
|
| 381 | + syslog (LOG_ALERT, $cf['syslog']['user'].": IMAP Alert: $thiserr"); |
|
| 382 | 382 | imap_close( $m_mail ); |
| 383 | 383 | if ( file_exists( $file ) ) unlink ($file); |
| 384 | 384 | if ( file_exists( $filed ) ) unlink ($filed); |
@@ -418,16 +418,16 @@ discard block |
||
| 418 | 418 | $uidbad['count'] = 0; |
| 419 | 419 | $uidbad['uid'] = array(); |
| 420 | 420 | |
| 421 | - // loop for each message |
|
| 421 | + // loop for each message |
|
| 422 | 422 | foreach ($m_search as $onem) { |
| 423 | 423 | |
| 424 | - //get imap header info for obj thang |
|
| 425 | - //$headers = imap_headerinfo($m_mail, $onem); |
|
| 426 | - //$head = imap_fetchheader($m_mail, $headers->Msgno); |
|
| 424 | + //get imap header info for obj thang |
|
| 425 | + //$headers = imap_headerinfo($m_mail, $onem); |
|
| 426 | + //$head = imap_fetchheader($m_mail, $headers->Msgno); |
|
| 427 | 427 | $head = imap_fetchheader($m_mail, $onem ); |
| 428 | - //$obj = imap_rfc822_parse_headers( $head); |
|
| 428 | + //$obj = imap_rfc822_parse_headers( $head); |
|
| 429 | 429 | |
| 430 | - list ($ip,$host,$dateReceived,$dateClient,$mid) = getIP( $head,$cf['mx_hostname']['mx'],$cf['msa']['msalearn'] ); |
|
| 430 | + list ($ip,$host,$dateReceived,$dateClient,$mid) = getIP( $head,$cf['mx_hostname']['mx'],$cf['msa']['msalearn'] ); |
|
| 431 | 431 | if (empty($mid)) { |
| 432 | 432 | $uid='NA'; |
| 433 | 433 | syslog (LOG_ERR, $cf['syslog']['user'].": Error retrieving data for empty Message-ID."); |
@@ -445,11 +445,11 @@ discard block |
||
| 445 | 445 | /* Extract domains url in body */ |
| 446 | 446 | $domains = parseURL ($m_mail,$onem,$cf['listingdom']['exclude']); |
| 447 | 447 | |
| 448 | - /* Update count of each ip */ |
|
| 449 | - if ($host and ($uid!='NA') and ($uid!='unauthenticated') and ($uid!='unknown')) { /* IP is received by MX servers and learned by valid uid */ |
|
| 448 | + /* Update count of each ip */ |
|
| 449 | + if ($host and ($uid!='NA') and ($uid!='unauthenticated') and ($uid!='unknown')) { /* IP is received by MX servers and learned by valid uid */ |
|
| 450 | 450 | $ipuid['count']++; //number of right messages |
| 451 | 451 | |
| 452 | - if (in_array($uid,array_keys($ipuid['uid']))) { |
|
| 452 | + if (in_array($uid,array_keys($ipuid['uid']))) { |
|
| 453 | 453 | $ipuid['uid']["$uid"]['count']++; //number of learn by this uid |
| 454 | 454 | if (!in_array($ip,$ipuid['uid']["$uid"])) |
| 455 | 455 | $ipuid['uid']["$uid"][]=$ip; //ips learned by this uid |
@@ -460,16 +460,16 @@ discard block |
||
| 460 | 460 | $ipuid['uid']['count']++; //number of unique uids |
| 461 | 461 | } |
| 462 | 462 | |
| 463 | - if (in_array($ip,array_keys($ipuid['ip']))) { |
|
| 464 | - $ipuid['ip']["$ip"]['count']++; //number of time this ip appears in different messages |
|
| 463 | + if (in_array($ip,array_keys($ipuid['ip']))) { |
|
| 464 | + $ipuid['ip']["$ip"]['count']++; //number of time this ip appears in different messages |
|
| 465 | 465 | if (!in_array($uid,$ipuid['ip']["$ip"])) |
| 466 | 466 | $ipuid['ip']["$ip"][]=$uid; //uids that learned this ip |
| 467 | 467 | } |
| 468 | - else { |
|
| 469 | - $ipuid['ip']["$ip"]['count'] = 1; |
|
| 468 | + else { |
|
| 469 | + $ipuid['ip']["$ip"]['count'] = 1; |
|
| 470 | 470 | $ipuid['ip']["$ip"][]=$uid; |
| 471 | 471 | $ipuid['ip']['count']++; //number of unique ips |
| 472 | - } |
|
| 472 | + } |
|
| 473 | 473 | |
| 474 | 474 | foreach ($domains as $dom) { |
| 475 | 475 | $domuid['count']++; |
@@ -504,18 +504,18 @@ discard block |
||
| 504 | 504 | ); |
| 505 | 505 | } |
| 506 | 506 | |
| 507 | - /* Update HTML report */ |
|
| 508 | - fwrite($fp,updateReport ( $ip,$uid,$ipuid['ip']["$ip"]['count'],$ipuid['uid']["$uid"]['count'],$host,$dateClient,$mid,$dateReceived) ); |
|
| 507 | + /* Update HTML report */ |
|
| 508 | + fwrite($fp,updateReport ( $ip,$uid,$ipuid['ip']["$ip"]['count'],$ipuid['uid']["$uid"]['count'],$host,$dateClient,$mid,$dateReceived) ); |
|
| 509 | 509 | } |
| 510 | - else { /* Bad learn */ |
|
| 510 | + else { /* Bad learn */ |
|
| 511 | 511 | |
| 512 | - if (in_array($uid,array_keys($uidbad['uid']))) |
|
| 513 | - $uidbad['uid']["$uid"]['count']++; //number of bad learn by this uid |
|
| 514 | - else { |
|
| 515 | - $uidbad['uid']["$uid"]['count'] = 1; |
|
| 512 | + if (in_array($uid,array_keys($uidbad['uid']))) |
|
| 513 | + $uidbad['uid']["$uid"]['count']++; //number of bad learn by this uid |
|
| 514 | + else { |
|
| 515 | + $uidbad['uid']["$uid"]['count'] = 1; |
|
| 516 | 516 | $uidbad['uid']["$uid"][]=$uid; |
| 517 | - $uidbad['count']++; //numeber of unique bad uids |
|
| 518 | - } |
|
| 517 | + $uidbad['count']++; //numeber of unique bad uids |
|
| 518 | + } |
|
| 519 | 519 | /* The reason of bad report */ |
| 520 | 520 | if ($host === FALSE) $reason = 'This mail was not received by recognized MX host'; |
| 521 | 521 | if ($dateReceived === FALSE) $reason = 'This mail was not submitted to recognized MSA for learn'; |
@@ -541,17 +541,17 @@ discard block |
||
| 541 | 541 | fwrite($fp, '<hr><h2>Summary Report</h2><h5>Listing policy: ip must be learned at least '.$cf['listingip']['threshold']["$type"].' times from at least '.$cf['listingip']['thresholduid']["$type"].' different valid uids.</h5>' ); |
| 542 | 542 | 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>' ); |
| 543 | 543 | |
| 544 | - /* Make MYSQL connection */ |
|
| 544 | + /* Make MYSQL connection */ |
|
| 545 | 545 | if ( $cf['listingip']['onlyReport']["$type"] && $cf['listingdom']['onlyReport']["$type"] ) |
| 546 | 546 | $mysqli = NULL; |
| 547 | 547 | else { |
| 548 | - $mysqli = new mysqli($myconnArray['dbhost'], $myconnArray['userdb'], $myconnArray['pwd'], $myconnArray['db'], $myconnArray['dbport']); |
|
| 549 | - if ($mysqli->connect_error) { |
|
| 550 | - syslog (LOG_EMERG, $cf['syslog']['user'].': Connect Error (' . $mysqli->connect_errno . ') ' |
|
| 551 | - . $mysqli->connect_error); |
|
| 552 | - exit (254); |
|
| 553 | - } |
|
| 554 | - syslog(LOG_INFO, $cf['syslog']['user'].': Successfully mysql connected to ' . $mysqli->host_info) ; |
|
| 548 | + $mysqli = new mysqli($myconnArray['dbhost'], $myconnArray['userdb'], $myconnArray['pwd'], $myconnArray['db'], $myconnArray['dbport']); |
|
| 549 | + if ($mysqli->connect_error) { |
|
| 550 | + syslog (LOG_EMERG, $cf['syslog']['user'].': Connect Error (' . $mysqli->connect_errno . ') ' |
|
| 551 | + . $mysqli->connect_error); |
|
| 552 | + exit (254); |
|
| 553 | + } |
|
| 554 | + syslog(LOG_INFO, $cf['syslog']['user'].': Successfully mysql connected to ' . $mysqli->host_info) ; |
|
| 555 | 555 | } |
| 556 | 556 | /***********************/ |
| 557 | 557 | |
@@ -576,8 +576,8 @@ discard block |
||
| 576 | 576 | foreach ( $ierr as $thiserr ) |
| 577 | 577 | syslog (LOG_ERR, $cf['syslog']['user'].": IMAP Error: $thiserr"); |
| 578 | 578 | if ( $ierr = imap_alerts() ) |
| 579 | - foreach ( $ierr as $thiserr ) |
|
| 580 | - syslog (LOG_ALERT, $cf['syslog']['user'].": IMAP Alert: $thiserr"); |
|
| 579 | + foreach ( $ierr as $thiserr ) |
|
| 580 | + syslog (LOG_ALERT, $cf['syslog']['user'].": IMAP Alert: $thiserr"); |
|
| 581 | 581 | imap_close($m_mail); |
| 582 | 582 | } |
| 583 | 583 | ?> |
@@ -26,17 +26,17 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | /* Conf */ |
| 28 | 28 | if (!isset($_GET['conf'])) { |
| 29 | - syslog(LOG_ALERT, |
|
| 30 | - sprintf('%s: you must insert the config file name as a GET parameter, such as %s?conf=listEmail.conf', |
|
| 31 | - $user, $_SERVER['SCRIPT_NAME']) ); |
|
| 32 | - exit(254); |
|
| 29 | + syslog(LOG_ALERT, |
|
| 30 | + sprintf('%s: you must insert the config file name as a GET parameter, such as %s?conf=listEmail.conf', |
|
| 31 | + $user, $_SERVER['SCRIPT_NAME']) ); |
|
| 32 | + exit(254); |
|
| 33 | 33 | } |
| 34 | 34 | $fileconf = $_GET['conf']; |
| 35 | 35 | if ( !file_exists(dirname(__FILE__) . '/../' . $fileconf) ) { |
| 36 | - syslog(LOG_ALERT, |
|
| 37 | - sprintf('%s: the configuration file <%s> doesn\'t exist.', |
|
| 38 | - $user, $fileconf )); |
|
| 39 | - exit(254); |
|
| 36 | + syslog(LOG_ALERT, |
|
| 37 | + sprintf('%s: the configuration file <%s> doesn\'t exist.', |
|
| 38 | + $user, $fileconf )); |
|
| 39 | + exit(254); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | closelog(); |
@@ -64,8 +64,8 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | /* check you select a blocklist */ |
| 66 | 66 | if ( !$tables["$typedesc"]['bl'] ) { |
| 67 | - syslog(LOG_EMERG,"$user: <$typedesc> is not a blocklist. Are you stupid? Do you want to whitelist a spammer? I refuse to continue."); |
|
| 68 | - exit (254); |
|
| 67 | + syslog(LOG_EMERG,"$user: <$typedesc> is not a blocklist. Are you stupid? Do you want to whitelist a spammer? I refuse to continue."); |
|
| 68 | + exit (254); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | |
@@ -95,15 +95,15 @@ discard block |
||
| 95 | 95 | if (preg_match_all('/^https?\:\/\/(?<splunkhost>[\w\.\-]+)\:8000(?:\/[\w\-\_\d]+)*\/app\/(?<splunkapp>[\w\.\-\_\d]+)\/\@go\?sid=(?<job>[\w\.\-\d]+)$/', |
| 96 | 96 | $webhook['results_link'], $out, PREG_PATTERN_ORDER) === FALSE) { |
| 97 | 97 | syslog(LOG_ALERT, |
| 98 | - sprintf('%s: unexpected error: can\'t parse the results link returned by webhook (<%s>).', |
|
| 98 | + sprintf('%s: unexpected error: can\'t parse the results link returned by webhook (<%s>).', |
|
| 99 | 99 | $user, $webhook['results_link']) ); |
| 100 | 100 | return 255; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | if ( $webhook['app'] != $out['splunkapp'][0] ) { |
| 104 | 104 | syslog(LOG_ALERT, |
| 105 | - sprintf('%s: unexpected error: the APP returned by webhook (<%s>) doesn\'t match the app (<%s>) in result link.', |
|
| 106 | - $user, $webhook['app'], $out['splunkapp'][0] ) ); |
|
| 105 | + sprintf('%s: unexpected error: the APP returned by webhook (<%s>) doesn\'t match the app (<%s>) in result link.', |
|
| 106 | + $user, $webhook['app'], $out['splunkapp'][0] ) ); |
|
| 107 | 107 | return 255; |
| 108 | 108 | } |
| 109 | 109 | |
@@ -137,14 +137,14 @@ discard block |
||
| 137 | 137 | |
| 138 | 138 | $nr = count ($results); |
| 139 | 139 | for ($i=1; $i<$nr; $i++) { /* We skip first header line (i=0) */ |
| 140 | - $data = str_getcsv($results[$i], ','); |
|
| 141 | - $thisVal = $data[1]; |
|
| 142 | - unset($data[1]); |
|
| 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; |
|
| 140 | + $data = str_getcsv($results[$i], ','); |
|
| 141 | + $thisVal = $data[1]; |
|
| 142 | + unset($data[1]); |
|
| 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 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /* Make MYSQL connection */ |
@@ -154,34 +154,34 @@ discard block |
||
| 154 | 154 | exit (254); |
| 155 | 155 | |
| 156 | 156 | foreach ( array_keys($tolist) as $value) { |
| 157 | - $quantity = $conf['quantity']; |
|
| 158 | - $reason = 'On ['.$tolist["$value"][0]."] <$value> sent ".$tolist["$value"][1].' messages to '.$tolist["$value"][2].' recipients.'; |
|
| 159 | - if ( $tolist["$value"][3] >= $threshold ) { |
|
| 160 | - if ( searchAndList ($mysqli,$user,$tables,$typedesc,$value,$unit,$quantity,$reason) ) { |
|
| 161 | - syslog (LOG_INFO, "$user: ".'Listing reason: '.$reason); |
|
| 162 | - /* Send a email to domain admin if you list an email */ |
|
| 163 | - if ( ( $tables["$typedesc"]['field'] == 'email' ) OR ( $tables["$typedesc"]['field'] == 'username' ) ) { |
|
| 164 | - /* Sometime uid are in the form of <user>@<domain> ... */ |
|
| 165 | - if ( strpos($value, '@') !== FALSE ) { |
|
| 166 | - $domain = substr(strrchr($value, '@'), 1); |
|
| 167 | - if ( strpos($domain, '@') === FALSE ) { |
|
| 168 | - $recip = emailToNotify($domainNotify_file,$domain); |
|
| 169 | - $subject = sprintf('%s <%s> is now blocked because exceedes limits on outgoing emails', |
|
| 170 | - $tables["$typedesc"]['field'], $value); |
|
| 171 | - if (!empty($recip)) |
|
| 172 | - if ( sendEmailWarn($tplfile,'[email protected]',$recip, |
|
| 173 | - $subject,$value,"$quantity $unit",$reason) ) |
|
| 174 | - syslog(LOG_INFO, "$user: \"$recip\" was notified about the \"$value\" abuse."); |
|
| 175 | - } |
|
| 176 | - else syslog(LOG_ERR,"$user: <$domain> contains the '@' char. Notification cannot be sent."); |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - else { |
|
| 182 | - $reason .= " But it has NOT been listed because it doesn't apply to the trigger condition."; |
|
| 183 | - syslog (LOG_INFO, "$user: ".$reason); |
|
| 184 | - } |
|
| 157 | + $quantity = $conf['quantity']; |
|
| 158 | + $reason = 'On ['.$tolist["$value"][0]."] <$value> sent ".$tolist["$value"][1].' messages to '.$tolist["$value"][2].' recipients.'; |
|
| 159 | + if ( $tolist["$value"][3] >= $threshold ) { |
|
| 160 | + if ( searchAndList ($mysqli,$user,$tables,$typedesc,$value,$unit,$quantity,$reason) ) { |
|
| 161 | + syslog (LOG_INFO, "$user: ".'Listing reason: '.$reason); |
|
| 162 | + /* Send a email to domain admin if you list an email */ |
|
| 163 | + if ( ( $tables["$typedesc"]['field'] == 'email' ) OR ( $tables["$typedesc"]['field'] == 'username' ) ) { |
|
| 164 | + /* Sometime uid are in the form of <user>@<domain> ... */ |
|
| 165 | + if ( strpos($value, '@') !== FALSE ) { |
|
| 166 | + $domain = substr(strrchr($value, '@'), 1); |
|
| 167 | + if ( strpos($domain, '@') === FALSE ) { |
|
| 168 | + $recip = emailToNotify($domainNotify_file,$domain); |
|
| 169 | + $subject = sprintf('%s <%s> is now blocked because exceedes limits on outgoing emails', |
|
| 170 | + $tables["$typedesc"]['field'], $value); |
|
| 171 | + if (!empty($recip)) |
|
| 172 | + if ( sendEmailWarn($tplfile,'[email protected]',$recip, |
|
| 173 | + $subject,$value,"$quantity $unit",$reason) ) |
|
| 174 | + syslog(LOG_INFO, "$user: \"$recip\" was notified about the \"$value\" abuse."); |
|
| 175 | + } |
|
| 176 | + else syslog(LOG_ERR,"$user: <$domain> contains the '@' char. Notification cannot be sent."); |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + else { |
|
| 182 | + $reason .= " But it has NOT been listed because it doesn't apply to the trigger condition."; |
|
| 183 | + syslog (LOG_INFO, "$user: ".$reason); |
|
| 184 | + } |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /* Close connection */ |
@@ -3,13 +3,13 @@ discard block |
||
| 3 | 3 | function imapFolder($cf, $username) { |
| 4 | 4 | $return = array(); |
| 5 | 5 | $open='{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}'; |
| 6 | - $m_mail = imap_open($open, $username, $cf['authpassword'], OP_READONLY) |
|
| 7 | - or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); |
|
| 8 | - if ( !$m_mail ) exit(254); |
|
| 6 | + $m_mail = imap_open($open, $username, $cf['authpassword'], OP_READONLY) |
|
| 7 | + or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); |
|
| 8 | + if ( !$m_mail ) exit(254); |
|
| 9 | 9 | |
| 10 | 10 | |
| 11 | - syslog (LOG_INFO,$cf['user'].': Successfully connected to <'.$cf['mailhost'].'>; Listing folders of account <'.$username.'>...'); |
|
| 12 | - //get all folder |
|
| 11 | + syslog (LOG_INFO,$cf['user'].': Successfully connected to <'.$cf['mailhost'].'>; Listing folders of account <'.$username.'>...'); |
|
| 12 | + //get all folder |
|
| 13 | 13 | $list = imap_list($m_mail, $open, "*"); |
| 14 | 14 | imap_close($m_mail); |
| 15 | 15 | if (is_array($list)) |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | function imapFind ($cf, $username, $folder) { |
| 24 | 24 | $head=array(); |
| 25 | 25 | $m_mail = imap_open('{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}'.$folder, $username,$cf['authpassword'], OP_READONLY) |
| 26 | - or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); |
|
| 26 | + or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); |
|
| 27 | 27 | if ( !$m_mail ) exit(254); |
| 28 | 28 | |
| 29 | 29 | |
@@ -36,12 +36,12 @@ discard block |
||
| 36 | 36 | // Order results starting from newest message |
| 37 | 37 | if ( empty($m_search) ) { |
| 38 | 38 | syslog (LOG_INFO,$cf['user'].": No suitable mail found in <$folder> folder."); |
| 39 | - if ( $ierr = imap_errors() ) |
|
| 40 | - foreach ( $ierr as $thiserr ) |
|
| 41 | - syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); |
|
| 42 | - if ( $ierr = imap_alerts() ) |
|
| 43 | - foreach ( $ierr as $thiserr ) |
|
| 44 | - syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); |
|
| 39 | + if ( $ierr = imap_errors() ) |
|
| 40 | + foreach ( $ierr as $thiserr ) |
|
| 41 | + syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); |
|
| 42 | + if ( $ierr = imap_alerts() ) |
|
| 43 | + foreach ( $ierr as $thiserr ) |
|
| 44 | + syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); |
|
| 45 | 45 | imap_close( $m_mail ); |
| 46 | 46 | return FALSE; |
| 47 | 47 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | syslog (LOG_INFO,$cf['user'].": Found $nmes mail in <$folder> folder."); |
| 50 | 50 | if ($nmes>0) rsort($m_search); |
| 51 | 51 | |
| 52 | - // loop for each message |
|
| 52 | + // loop for each message |
|
| 53 | 53 | foreach ($m_search as $onem) |
| 54 | 54 | $head[] = imap_fetchheader($m_mail, $onem ); |
| 55 | 55 | imap_close($m_mail); |
@@ -80,52 +80,52 @@ discard block |
||
| 80 | 80 | /* Each line must end with /r/n */ |
| 81 | 81 | |
| 82 | 82 | $result = array( |
| 83 | - 'date' => NULL, |
|
| 84 | - 'from' => NULL, |
|
| 85 | - 'messageid' => NULL, |
|
| 83 | + 'date' => NULL, |
|
| 84 | + 'from' => NULL, |
|
| 85 | + 'messageid' => NULL, |
|
| 86 | 86 | 'dmarc' => array( |
| 87 | 87 | 'result' => NULL, |
| 88 | 88 | 'dom' => NULL |
| 89 | 89 | ), |
| 90 | 90 | 'spf' => array( |
| 91 | - 'result' => NULL, |
|
| 92 | - 'dom' => NULL |
|
| 93 | - ), |
|
| 91 | + 'result' => NULL, |
|
| 92 | + 'dom' => NULL |
|
| 93 | + ), |
|
| 94 | 94 | 'dkim' => array( |
| 95 | - 'result' => NULL, |
|
| 96 | - 'dom' => NULL |
|
| 97 | - ), |
|
| 98 | - 'spam' => array( |
|
| 99 | - 'status' => NULL, |
|
| 100 | - 'score' => NULL, |
|
| 101 | - 'th' => NULL, |
|
| 102 | - ), |
|
| 103 | - 'dspam' => array( |
|
| 104 | - 'type' => NULL, |
|
| 105 | - 'level' => NULL, |
|
| 95 | + 'result' => NULL, |
|
| 96 | + 'dom' => NULL |
|
| 97 | + ), |
|
| 98 | + 'spam' => array( |
|
| 99 | + 'status' => NULL, |
|
| 100 | + 'score' => NULL, |
|
| 101 | + 'th' => NULL, |
|
| 102 | + ), |
|
| 103 | + 'dspam' => array( |
|
| 104 | + 'type' => NULL, |
|
| 105 | + 'level' => NULL, |
|
| 106 | 106 | 'learn' => NULL |
| 107 | - ), |
|
| 107 | + ), |
|
| 108 | 108 | 'warn' => NULL |
| 109 | - ); |
|
| 109 | + ); |
|
| 110 | 110 | |
| 111 | 111 | |
| 112 | - if ( preg_match_all ('/^Authentication\-Results:\s+(?<host>[\w\.]+);(?:\s+|\r\n\s+)dmarc=(?<dmarc>\w+)\s+\(p=\w+\s+dis=\w+\)\s+header\.from=(?<DMARCfrom>[\w\.]+)/m',$header,$received) ) { |
|
| 112 | + if ( preg_match_all ('/^Authentication\-Results:\s+(?<host>[\w\.]+);(?:\s+|\r\n\s+)dmarc=(?<dmarc>\w+)\s+\(p=\w+\s+dis=\w+\)\s+header\.from=(?<DMARCfrom>[\w\.]+)/m',$header,$received) ) { |
|
| 113 | 113 | $k=0; |
| 114 | - for ($i = count($received[0])-1;$i>=0;$i--) { |
|
| 115 | - foreach ($ARhosts as $mx) { |
|
| 114 | + for ($i = count($received[0])-1;$i>=0;$i--) { |
|
| 115 | + foreach ($ARhosts as $mx) { |
|
| 116 | 116 | if ($mx == $received['host'][$i]) { |
| 117 | 117 | /* This is a trusted AR result */ |
| 118 | 118 | $result['dmarc']['result']=$received['dmarc'][$i]; |
| 119 | 119 | $result['dmarc']['dom'] = $received['DMARCfrom'][$i]; |
| 120 | 120 | $k++; |
| 121 | 121 | } |
| 122 | - } |
|
| 122 | + } |
|
| 123 | + } |
|
| 123 | 124 | } |
| 124 | - } |
|
| 125 | 125 | $received=NULL; |
| 126 | 126 | if ($k>1) $result['warn'][] = 'The trusted DMARC AR Headers are present more than once. Something wrong.'; |
| 127 | 127 | |
| 128 | - 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) ) { |
|
| 128 | + 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 | 129 | $k=0; |
| 130 | 130 | for ($i = count($received[0])-1;$i>=0;$i--) { |
| 131 | 131 | foreach ($ARhosts as $mx) { |
@@ -134,25 +134,25 @@ discard block |
||
| 134 | 134 | $result['spf']['result']=$received['spf'][$i]; |
| 135 | 135 | $result['spf']['dom'] = $received['SPFfrom'][$i]; |
| 136 | 136 | $k++; |
| 137 | - } |
|
| 138 | - } |
|
| 139 | - } |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | 140 | } |
| 141 | 141 | $received=NULL; |
| 142 | 142 | if ($k>1) $result['warn'][] = 'The trusted SPF AR Headers are present more than once. Something wrong.'; |
| 143 | 143 | |
| 144 | 144 | $k=0; |
| 145 | - 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) ) { |
|
| 145 | + 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) ) { |
|
| 146 | 146 | for ($i = count($received[0])-1;$i>=0;$i--) { |
| 147 | - foreach ($ARhosts as $mx) { |
|
| 148 | - if ($mx == $received['host'][$i]) { |
|
| 149 | - /* This is a trusted AR result */ |
|
| 150 | - $result['dkim']['result']=$received['dkim'][$i]; |
|
| 151 | - $result['dkim']['dom'] = $received['DKIMdom'][$i]; |
|
| 147 | + foreach ($ARhosts as $mx) { |
|
| 148 | + if ($mx == $received['host'][$i]) { |
|
| 149 | + /* This is a trusted AR result */ |
|
| 150 | + $result['dkim']['result']=$received['dkim'][$i]; |
|
| 151 | + $result['dkim']['dom'] = $received['DKIMdom'][$i]; |
|
| 152 | 152 | $k++; |
| 153 | - } |
|
| 154 | - } |
|
| 155 | - } |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | 156 | } |
| 157 | 157 | $received=NULL; |
| 158 | 158 | if ($k>1) $result['warn'][] = 'The trusted DKIM AR Headers are present more than once. Something wrong.'; |
@@ -160,59 +160,59 @@ discard block |
||
| 160 | 160 | if ($dpl) { /* Use Spamassassin Plugin */ |
| 161 | 161 | 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) ) { |
| 162 | 162 | $result['spam']['status']=$received['spamstatus'][0]; |
| 163 | - $result['spam']['score'] = $received['score'][0]; |
|
| 163 | + $result['spam']['score'] = $received['score'][0]; |
|
| 164 | 164 | $result['spam']['th'] = $received['th'][0]; |
| 165 | 165 | $result['dspam']['type'] = dspamType($received['dtype'][0]); |
| 166 | 166 | $result['dspam']['level'] =$received['dlevel'][0]; |
| 167 | - } |
|
| 168 | - if (count($received[0])>1) $result['warn'][] = 'The Spamassassin Headers are present more than once. I consider only the last one.'; |
|
| 167 | + } |
|
| 168 | + if (count($received[0])>1) $result['warn'][] = 'The Spamassassin Headers are present more than once. I consider only the last one.'; |
|
| 169 | 169 | } |
| 170 | 170 | else { /* Parse apart all DSPAM Header and calculate a level */ |
| 171 | 171 | 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 | - $result['spam']['status']=$received['spamstatus'][0]; |
|
| 173 | - $result['spam']['score'] = $received['score'][0]; |
|
| 174 | - $result['spam']['th'] = $received['th'][0]; |
|
| 172 | + $result['spam']['status']=$received['spamstatus'][0]; |
|
| 173 | + $result['spam']['score'] = $received['score'][0]; |
|
| 174 | + $result['spam']['th'] = $received['th'][0]; |
|
| 175 | 175 | if (count($received[0])>1) |
| 176 | 176 | $result['warn'][]= 'The Spamassassin Headers are present more than once. I consider only the last one.'; |
| 177 | 177 | } |
| 178 | 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']; |
|
| 179 | + $result['warn'] = 'DSPAM Result invalid, not present or present more than once.'; |
|
| 180 | + else |
|
| 181 | + $result['dspam']['type']=$received['result']; |
|
| 182 | 182 | $prob = NULL; |
| 183 | 183 | $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.'; |
|
| 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 | 186 | else |
| 187 | 187 | $prob = $received['prob']; |
| 188 | 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.'; |
|
| 189 | + $result['warn'][] = 'DSPAM Confidence invalid, not present or present more than once.'; |
|
| 190 | 190 | else |
| 191 | 191 | $conf = $received['conf']; |
| 192 | 192 | $result['dspam']['level'] = dspamLevel($prob,$conf); |
| 193 | 193 | } |
| 194 | 194 | $received=NULL; |
| 195 | 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']; |
|
| 196 | + $result['warn'][] = 'From header invalid or not present'; |
|
| 197 | + else |
|
| 198 | + $result['from'] = $received['from']; |
|
| 199 | 199 | |
| 200 | - if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$received) != 1) |
|
| 201 | - $result['warn'][] = 'Date header invalid or not present'; |
|
| 200 | + if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$received) != 1) |
|
| 201 | + $result['warn'][] = 'Date header invalid or not present'; |
|
| 202 | 202 | else |
| 203 | 203 | $result['date'] = $received['date']; |
| 204 | 204 | |
| 205 | 205 | $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.'; |
|
| 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 | 208 | else |
| 209 | 209 | $result['messageid']=$received['mid']; |
| 210 | 210 | |
| 211 | - $received=NULL; |
|
| 211 | + $received=NULL; |
|
| 212 | 212 | |
| 213 | - switch ($learn) { |
|
| 213 | + switch ($learn) { |
|
| 214 | 214 | case 'dspamc': |
| 215 | - if ( preg_match ('/\r\nX\-DSPAM\-Signature:\s(?P<sig>.*)\r\n/',$header,$received) != 1) |
|
| 215 | + if ( preg_match ('/\r\nX\-DSPAM\-Signature:\s(?P<sig>.*)\r\n/',$header,$received) != 1) |
|
| 216 | 216 | $result['warn'] = 'DSPAM Signature invalid, not present or present more than once.'; |
| 217 | 217 | else |
| 218 | 218 | $result['dspam']['learn']=$received['sig']; |
@@ -223,23 +223,23 @@ discard block |
||
| 223 | 223 | syslog (LOG_INFO,$user.': Error in "learn" imap configuration value. Please, set "dspamc" or "false".'); |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - return $result; |
|
| 226 | + return $result; |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | |
| 230 | 230 | |
| 231 | 231 | |
| 232 | 232 | function printTableHeader($title,$content,$footer=FALSE,$fcontent) { |
| 233 | - print <<<END |
|
| 233 | + print <<<END |
|
| 234 | 234 | <caption>$title</caption> |
| 235 | 235 | <thead> |
| 236 | 236 | <tr> |
| 237 | 237 | END; |
| 238 | 238 | $kcontent = array_keys($content); |
| 239 | - $cols = count($kcontent); |
|
| 240 | - for ($i=0; $i<$cols; $i++) { |
|
| 239 | + $cols = count($kcontent); |
|
| 240 | + for ($i=0; $i<$cols; $i++) { |
|
| 241 | 241 | $key = $kcontent[$i]; |
| 242 | - printf ('<th colspan="%d" rowspan="%d">%s</th>', |
|
| 242 | + printf ('<th colspan="%d" rowspan="%d">%s</th>', |
|
| 243 | 243 | !is_array($content[$key]) ?: |
| 244 | 244 | count(array_keys($content[$key])) ?: '1', |
| 245 | 245 | !is_array($content[$key]) ?: |
@@ -255,13 +255,13 @@ discard block |
||
| 255 | 255 | } |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | - print '</tr></thead>'; |
|
| 259 | - if ($footer) { |
|
| 260 | - print '<tfoot><tr>'; |
|
| 261 | - print "<th colspan=\"$cols\">".$fcontent.'</th>'; |
|
| 262 | - print '</tr></tfoot>'; |
|
| 263 | - } |
|
| 264 | - return TRUE; |
|
| 258 | + print '</tr></thead>'; |
|
| 259 | + if ($footer) { |
|
| 260 | + print '<tfoot><tr>'; |
|
| 261 | + print "<th colspan=\"$cols\">".$fcontent.'</th>'; |
|
| 262 | + print '</tr></tfoot>'; |
|
| 263 | + } |
|
| 264 | + return TRUE; |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | } |
| 337 | 337 | /* Spamassassin format */ |
| 338 | 338 | if (isset($row['status'])) |
| 339 | - switch($row['status']) { |
|
| 339 | + switch($row['status']) { |
|
| 340 | 340 | case 'No': |
| 341 | 341 | $color = 'rgba(0,255,0, %.1f)'; |
| 342 | 342 | break; |