@@ -12,7 +12,7 @@ |
||
| 12 | 12 | $user = username(); |
| 13 | 13 | |
| 14 | 14 | if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) |
| 15 | - exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
|
| 15 | + exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
|
| 16 | 16 | |
| 17 | 17 | if (changestatus($mysqli,username(),$_POST['value'],'0',$type,$table)) |
| 18 | 18 | print 'OK '.$_POST["type"].' <'.$_POST['value'].'> delisted.'; |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | require_once('config.php'); |
| 3 | 3 | require_once('function.php'); |
| 4 | -$typedesc=$_POST['type']; |
|
| 4 | +$typedesc = $_POST['type']; |
|
| 5 | 5 | $type = $tables["$typedesc"]['field']; |
| 6 | 6 | $table = ($tables["$typedesc"]['milter']) ? milterTable($type) : $tables["$typedesc"]['name']; |
| 7 | 7 | $cl = ($tables["$typedesc"]['milter']) ? 10 : 9; |
@@ -11,10 +11,10 @@ discard block |
||
| 11 | 11 | openlog($tag, LOG_PID, $fac); |
| 12 | 12 | $user = username(); |
| 13 | 13 | |
| 14 | -if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) |
|
| 15 | - exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
|
| 14 | +if (($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE) |
|
| 15 | + exit ($user.': Connect Error ('.$mysqli->connect_errno.') '.$mysqli->connect_error); |
|
| 16 | 16 | |
| 17 | -if (changestatus($mysqli,username(),$_POST['value'],'0',$type,$table)) |
|
| 17 | +if (changestatus($mysqli, username(), $_POST['value'], '0', $type, $table)) |
|
| 18 | 18 | print 'OK '.$_POST["type"].' <'.$_POST['value'].'> delisted.'; |
| 19 | 19 | else |
| 20 | 20 | print 'ERROR in delist <'.$_POST['value'].'>; check log'; |
@@ -11,13 +11,15 @@ |
||
| 11 | 11 | openlog($tag, LOG_PID, $fac); |
| 12 | 12 | $user = username(); |
| 13 | 13 | |
| 14 | -if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) |
|
| 14 | +if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) { |
|
| 15 | 15 | exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
| 16 | +} |
|
| 16 | 17 | |
| 17 | -if (changestatus($mysqli,username(),$_POST['value'],'0',$type,$table)) |
|
| 18 | +if (changestatus($mysqli,username(),$_POST['value'],'0',$type,$table)) { |
|
| 18 | 19 | print 'OK '.$_POST["type"].' <'.$_POST['value'].'> delisted.'; |
| 19 | -else |
|
| 20 | +} else { |
|
| 20 | 21 | print 'ERROR in delist <'.$_POST['value'].'>; check log'; |
| 22 | +} |
|
| 21 | 23 | print '</td>'; |
| 22 | 24 | $mysqli->close(); |
| 23 | 25 | closelog(); |
@@ -234,6 +234,9 @@ discard block |
||
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | |
| 237 | +/** |
|
| 238 | + * @param integer $id |
|
| 239 | + */ |
|
| 237 | 240 | function askMilter($myconn,$id,$obj,$typedesc,$miltId,$value,$user,$adm) { |
| 238 | 241 | $milts = readMiltName($myconn,$user); |
| 239 | 242 | $size = count($milts); |
@@ -264,6 +267,11 @@ discard block |
||
| 264 | 267 | } |
| 265 | 268 | |
| 266 | 269 | |
| 270 | +/** |
|
| 271 | + * @param integer $id |
|
| 272 | + * @param string $what |
|
| 273 | + * @param boolean $lock |
|
| 274 | + */ |
|
| 267 | 275 | function ask($myconn,$id,$what,$alltables,$typedesc,$value,$lock,$user,$adm) { |
| 268 | 276 | |
| 269 | 277 | $whynot=NULL; |
@@ -522,6 +530,9 @@ discard block |
||
| 522 | 530 | } |
| 523 | 531 | |
| 524 | 532 | |
| 533 | +/** |
|
| 534 | + * @param string $reason |
|
| 535 | + */ |
|
| 525 | 536 | function searchAndList ($myconn,$loguser,$tables,$typedesc,$value,$unit,&$quantity,&$reason) { |
| 526 | 537 | |
| 527 | 538 | /* Search and list value */ |
@@ -591,6 +602,9 @@ discard block |
||
| 591 | 602 | return array_map('long2ip', range( ip2long($range[0]), ip2long($range[1]) ) ); |
| 592 | 603 | } |
| 593 | 604 | |
| 605 | +/** |
|
| 606 | + * @param string $netA |
|
| 607 | + */ |
|
| 594 | 608 | function isIn($netA, $netB) { |
| 595 | 609 | /* TRUE if an IP of $netA is contained in netB */ |
| 596 | 610 | list($addressA,$maskA) = explode('/', $netA); |
@@ -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 | |
@@ -5,46 +5,46 @@ discard block |
||
| 5 | 5 | function username() { |
| 6 | 6 | if (isset ($_SERVER['REMOTE_USER'])) $user = $_SERVER['REMOTE_USER']; |
| 7 | 7 | else if (isset ($_SERVER['USER'])) $user = $_SERVER['USER']; |
| 8 | - else $user='unknown'; |
|
| 8 | + else $user = 'unknown'; |
|
| 9 | 9 | return $user; |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | 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' . |
|
| 15 | - '<pre>' . |
|
| 16 | - htmlspecialchars('<VirtualHost *:80>' . "\n" . |
|
| 17 | - ' ServerName %s' . "\n" . |
|
| 18 | - ' Redirect permanent / https://%s/' . "\n" . |
|
| 19 | - '</VirtualHost>') . |
|
| 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'. |
|
| 15 | + '<pre>'. |
|
| 16 | + htmlspecialchars('<VirtualHost *:80>'."\n". |
|
| 17 | + ' ServerName %s'."\n". |
|
| 18 | + ' Redirect permanent / https://%s/'."\n". |
|
| 19 | + '</VirtualHost>'). |
|
| 20 | 20 | '</pre></div>', gethostname(), gethostname()); |
| 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 | 26 | if ($mysqli->connect_error) { |
| 27 | - syslog (LOG_EMERG, $loguser.': Connect Error to DB <'.$db.'> (' . $mysqli->connect_errno . ') ' |
|
| 27 | + syslog(LOG_EMERG, $loguser.': Connect Error to DB <'.$db.'> ('.$mysqli->connect_errno.') ' |
|
| 28 | 28 | . $mysqli->connect_error); |
| 29 | 29 | return FALSE; |
| 30 | 30 | } |
| 31 | - syslog(LOG_INFO, $loguser.': Successfully MySQL connected at DB <'.$db.'> to ' . $mysqli->host_info) ; |
|
| 31 | + syslog(LOG_INFO, $loguser.': Successfully MySQL connected at DB <'.$db.'> to '.$mysqli->host_info); |
|
| 32 | 32 | return $mysqli; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | -function addtolist ($myconn,$user,$value,$tabledesc,$expUnit,$expQ,$myreason,&$err) { |
|
| 35 | +function addtolist($myconn, $user, $value, $tabledesc, $expUnit, $expQ, $myreason, &$err) { |
|
| 36 | 36 | // See MySQL manual for $expQ and $expUnit at |
| 37 | 37 | // https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_timestampadd |
| 38 | 38 | |
| 39 | - $result=FALSE; |
|
| 40 | - $sub=array(); |
|
| 39 | + $result = FALSE; |
|
| 40 | + $sub = array(); |
|
| 41 | 41 | $type = $tabledesc['field']; |
| 42 | 42 | $milt = $tabledesc['milter']; |
| 43 | 43 | $table = ($milt) ? milterTable($type) : $tabledesc['name']; |
| 44 | 44 | |
| 45 | 45 | switch ($type) { |
| 46 | 46 | case 'ip': |
| 47 | - $query= sprintf("INSERT INTO `$table` ( |
|
| 47 | + $query = sprintf("INSERT INTO `$table` ( |
|
| 48 | 48 | `$type` , |
| 49 | 49 | `date` , |
| 50 | 50 | `exp` , |
@@ -55,18 +55,18 @@ discard block |
||
| 55 | 55 | VALUES ( |
| 56 | 56 | INET_ATON( '%s' ) , |
| 57 | 57 | CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s' |
| 58 | - )" ,$value,$expUnit,$expQ,$user,$myreason); |
|
| 58 | + )", $value, $expUnit, $expQ, $user, $myreason); |
|
| 59 | 59 | break; |
| 60 | 60 | |
| 61 | 61 | case 'network': |
| 62 | 62 | if (!$milt) { |
| 63 | - if ( netOverlap($myconn, $tabledesc, $value, $overlappedNet, $user) ) { |
|
| 63 | + if (netOverlap($myconn, $tabledesc, $value, $overlappedNet, $user)) { |
|
| 64 | 64 | $err = "<$value> overlaps the existing network <$overlappedNet>"; |
| 65 | 65 | return FALSE; |
| 66 | 66 | } |
| 67 | 67 | } |
| 68 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
| 69 | - $query= sprintf("INSERT INTO `$table` ( |
|
| 68 | + list($sub['net'], $sub['mask']) = explode('/', $value); |
|
| 69 | + $query = sprintf("INSERT INTO `$table` ( |
|
| 70 | 70 | `$type` , |
| 71 | 71 | `netmask`, |
| 72 | 72 | `date` , |
@@ -78,11 +78,11 @@ discard block |
||
| 78 | 78 | VALUES ( |
| 79 | 79 | INET_ATON( '%s' ) , INET_ATON( '%s' ) , |
| 80 | 80 | CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s' |
| 81 | - )" ,$sub['net'],$sub['mask'],$expUnit,$expQ,$user,$myreason); |
|
| 81 | + )", $sub['net'], $sub['mask'], $expUnit, $expQ, $user, $myreason); |
|
| 82 | 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` , |
@@ -93,23 +93,23 @@ discard block |
||
| 93 | 93 | VALUES ( |
| 94 | 94 | '%s' , |
| 95 | 95 | CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s' |
| 96 | - )" ,$value,$expUnit,$expQ,$user,$myreason); |
|
| 96 | + )", $value, $expUnit, $expQ, $user, $myreason); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | if ($myconn->query($query) === TRUE) { |
| 100 | 100 | syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit."); |
| 101 | - $result=TRUE; |
|
| 101 | + $result = TRUE; |
|
| 102 | 102 | } |
| 103 | 103 | else syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
| 104 | 104 | return $result; |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | -function relist ($myconn,$user,$value,$type,$table,$expUnit,$expQ,$myreason, $exptime = 0) { |
|
| 107 | +function relist($myconn, $user, $value, $type, $table, $expUnit, $expQ, $myreason, $exptime = 0) { |
|
| 108 | 108 | |
| 109 | - $result=FALSE; |
|
| 110 | - if ( $exptime ) { /* Entry already listed */ |
|
| 109 | + $result = FALSE; |
|
| 110 | + if ($exptime) { /* Entry already listed */ |
|
| 111 | 111 | $nlist = '`nlist`'; |
| 112 | - $exptime = sprintf('\'%s\'', $exptime); /* Eh MySQL... an hour lost to notice this */ |
|
| 112 | + $exptime = sprintf('\'%s\'', $exptime); /* Eh MySQL... an hour lost to notice this */ |
|
| 113 | 113 | } |
| 114 | 114 | else { |
| 115 | 115 | $exptime = 'CURRENT_TIMESTAMP'; |
@@ -118,43 +118,43 @@ discard block |
||
| 118 | 118 | |
| 119 | 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), |
| 125 | 125 | `nlist` = %s, |
| 126 | 126 | `reason` = '%s' |
| 127 | - WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user,$expUnit,$expQ,$exptime,$nlist,$myreason,$value); |
|
| 127 | + WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1", $user, $expUnit, $expQ, $exptime, $nlist, $myreason, $value); |
|
| 128 | 128 | break; |
| 129 | 129 | case 'network': |
| 130 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
| 131 | - $query= sprintf("UPDATE `$table` SET |
|
| 130 | + list($sub['net'], $sub['mask']) = explode('/', $value); |
|
| 131 | + $query = sprintf("UPDATE `$table` SET |
|
| 132 | 132 | `active` = '1', |
| 133 | 133 | `user` = '%s', |
| 134 | 134 | `exp` = TIMESTAMPADD(%s,%d,%s), |
| 135 | 135 | `nlist` = %s, |
| 136 | 136 | `reason` = '%s' |
| 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']); |
|
| 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), |
| 144 | 144 | `nlist` = %s, |
| 145 | 145 | `reason` = '%s' |
| 146 | - WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user,$expUnit,$expQ,$exptime,$nlist,$myreason,$value); |
|
| 146 | + WHERE `$table`.`$type` = '%s' LIMIT 1", $user, $expUnit, $expQ, $exptime, $nlist, $myreason, $value); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | if ($myconn->query($query) === TRUE) { |
| 150 | 150 | syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit from $exptime."); |
| 151 | - $result=TRUE; |
|
| 151 | + $result = TRUE; |
|
| 152 | 152 | } |
| 153 | - else syslog (LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 153 | + else syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
|
| 154 | 154 | return $result; |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | -function remove ($myconn,$user,$value,$type,$table) { |
|
| 157 | +function remove($myconn, $user, $value, $type, $table) { |
|
| 158 | 158 | |
| 159 | 159 | switch ($type) { |
| 160 | 160 | case 'ip': |
@@ -162,10 +162,10 @@ discard block |
||
| 162 | 162 | `$table`.`$type` = INET_ATON('%s') LIMIT 1", $value); |
| 163 | 163 | break; |
| 164 | 164 | case 'network': |
| 165 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
| 165 | + list($sub['net'], $sub['mask']) = explode('/', $value); |
|
| 166 | 166 | $query = sprintf("DELETE FROM `$table` WHERE |
| 167 | 167 | `$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s') LIMIT 1", |
| 168 | - $sub['net'],$sub['mask']); |
|
| 168 | + $sub['net'], $sub['mask']); |
|
| 169 | 169 | break; |
| 170 | 170 | default: |
| 171 | 171 | $query = sprintf("DELETE FROM `$table` WHERE |
@@ -173,39 +173,39 @@ discard block |
||
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | |
| 176 | - if ($return=$myconn->query($query) === TRUE) |
|
| 176 | + if ($return = $myconn->query($query) === TRUE) |
|
| 177 | 177 | syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>."); |
| 178 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 178 | + else syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
|
| 179 | 179 | |
| 180 | 180 | return $return; |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | |
| 184 | -function changestatus ($myconn,$user,$value,$status,$type,$table) { |
|
| 184 | +function changestatus($myconn, $user, $value, $status, $type, $table) { |
|
| 185 | 185 | |
| 186 | 186 | switch ($type) { |
| 187 | 187 | case 'ip': |
| 188 | - $query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user, $value); |
|
| 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': |
| 191 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
| 192 | - $query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1" ,$user, $sub['net'],$sub['mask']); |
|
| 191 | + list($sub['net'], $sub['mask']) = explode('/', $value); |
|
| 192 | + $query = sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1", $user, $sub['net'], $sub['mask']); |
|
| 193 | 193 | break; |
| 194 | 194 | default: |
| 195 | - $query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user, $value); |
|
| 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) { |
|
| 198 | + if ($return = $myconn->query($query) === TRUE) { |
|
| 199 | 199 | syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>"); |
| 200 | 200 | } |
| 201 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 201 | + else syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
|
| 202 | 202 | return $return; |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | |
| 206 | -function expire ($myconn,$user,$tables,$expireTime) { |
|
| 207 | - $return=TRUE; |
|
| 208 | - $log=array(); |
|
| 206 | +function expire($myconn, $user, $tables, $expireTime) { |
|
| 207 | + $return = TRUE; |
|
| 208 | + $log = array(); |
|
| 209 | 209 | $desc = array_keys($tables); |
| 210 | 210 | foreach ($desc as $tdesc) { |
| 211 | 211 | /* QUERY */ |
@@ -224,11 +224,11 @@ discard block |
||
| 224 | 224 | } while ($myconn->next_result()); |
| 225 | 225 | } |
| 226 | 226 | else { |
| 227 | - syslog(LOG_ERR, "Expire job - Error: ". $myconn->error); |
|
| 227 | + syslog(LOG_ERR, "Expire job - Error: ".$myconn->error); |
|
| 228 | 228 | $return = FALSE; |
| 229 | 229 | } |
| 230 | 230 | } |
| 231 | - if ( !($return) ) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); |
|
| 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 | 233 | return $return; |
| 234 | 234 | } |
@@ -236,18 +236,18 @@ discard block |
||
| 236 | 236 | |
| 237 | 237 | function isListed($row) { |
| 238 | 238 | |
| 239 | - $exp=new DateTime($row['exp']); |
|
| 240 | - $now=new DateTime('NOW'); |
|
| 241 | - if (($exp > $now) and ($row['active'])) return true; |
|
| 239 | + $exp = new DateTime($row['exp']); |
|
| 240 | + $now = new DateTime('NOW'); |
|
| 241 | + if (($exp>$now) and ($row['active'])) return true; |
|
| 242 | 242 | else return false; |
| 243 | 243 | |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | |
| 247 | -function askMilter($myconn,$id,$obj,$typedesc,$miltId,$value,$user,$adm) { |
|
| 248 | - $milts = readMiltName($myconn,$user); |
|
| 247 | +function askMilter($myconn, $id, $obj, $typedesc, $miltId, $value, $user, $adm) { |
|
| 248 | + $milts = readMiltName($myconn, $user); |
|
| 249 | 249 | $size = count($milts); |
| 250 | - if (in_array($user,array_keys($adm))) { |
|
| 250 | + if (in_array($user, array_keys($adm))) { |
|
| 251 | 251 | $button = <<<END |
| 252 | 252 | <form style="margin:0; display:inline;" name="Milter$id" enctype="text/plain" method="post" target="_self" action="changeMilter.php" onSubmit="xmlhttpPost('changeMilter.php', 'Milter$id', 'id$id', '<img src=\'/include/pleasewait.gif\'>'); return false;" /> |
| 253 | 253 | <input name="object" type="hidden" value="$obj" /><input name="oldvalues" type="hidden" value="$value" /> |
@@ -257,12 +257,12 @@ discard block |
||
| 257 | 257 | <div class="noscroll"> |
| 258 | 258 | <select class="input_text" name="newvalues[]" multiple size="$size"> |
| 259 | 259 | END; |
| 260 | - $activeMilts = explode(',',$value); |
|
| 261 | - foreach ( $milts as $milter ) { |
|
| 262 | - if ( in_array($milter, $activeMilts) ) |
|
| 263 | - $selected= 'selected'; |
|
| 260 | + $activeMilts = explode(',', $value); |
|
| 261 | + foreach ($milts as $milter) { |
|
| 262 | + if (in_array($milter, $activeMilts)) |
|
| 263 | + $selected = 'selected'; |
|
| 264 | 264 | else |
| 265 | - $selected= NULL; |
|
| 265 | + $selected = NULL; |
|
| 266 | 266 | $button .= sprintf('<option value="%s" %s>%s</option>', $milter, $selected, $milter); |
| 267 | 267 | } |
| 268 | 268 | $button .= '</select></div><input class="button" name="Change" type="submit" value="Change" /></form>'; |
@@ -274,14 +274,14 @@ discard block |
||
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | |
| 277 | -function ask($myconn,$id,$what,$alltables,$typedesc,$value,$lock,$user,$adm) { |
|
| 277 | +function ask($myconn, $id, $what, $alltables, $typedesc, $value, $lock, $user, $adm) { |
|
| 278 | 278 | |
| 279 | - $whynot=NULL; |
|
| 279 | + $whynot = NULL; |
|
| 280 | 280 | switch ($what) { |
| 281 | 281 | case 'Ok': |
| 282 | 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'); |
|
| 283 | + if (in_array($user, array_keys($adm))) |
|
| 284 | + if (consistentListing($myconn, $alltables, $typedesc, $value, $whynot)) return require('relistButton.php'); |
|
| 285 | 285 | return htmlspecialchars($whynot); |
| 286 | 286 | case 'Listed': |
| 287 | 287 | case 'WhiteListed': |
@@ -290,18 +290,18 @@ discard block |
||
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | |
| 293 | -function consistentListing($myconn,$alltables,$typed,$value,&$warn) { |
|
| 293 | +function consistentListing($myconn, $alltables, $typed, $value, &$warn) { |
|
| 294 | 294 | /* Check if there are no pending mislisting */ |
| 295 | 295 | $warn = NULL; |
| 296 | - if (! isset($alltables["$typed"]['depend']) ) return TRUE; |
|
| 296 | + if (!isset($alltables["$typed"]['depend'])) return TRUE; |
|
| 297 | 297 | foreach ($alltables["$typed"]['depend'] as $listdep) { |
| 298 | - if ($alltables["$typed"]['field'] != $alltables["$listdep"]['field'] ) { |
|
| 298 | + if ($alltables["$typed"]['field'] != $alltables["$listdep"]['field']) { |
|
| 299 | 299 | $warn = "Config ERROR: <$typed> and <$listdep> are of different types! I can't check consistency!"; |
| 300 | 300 | return FALSE; |
| 301 | 301 | } |
| 302 | - $entry = searchentry($myconn,$value,$alltables["$listdep"]); |
|
| 303 | - if ( $entry->num_rows ) { |
|
| 304 | - if ( $entry->num_rows == 1 ) { |
|
| 302 | + $entry = searchentry($myconn, $value, $alltables["$listdep"]); |
|
| 303 | + if ($entry->num_rows) { |
|
| 304 | + if ($entry->num_rows == 1) { |
|
| 305 | 305 | $riga = $entry->fetch_array(MYSQLI_ASSOC); |
| 306 | 306 | if (isListed($riga)) { |
| 307 | 307 | $warn = "<$value> is already present in <$listdep> list!"; |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | return FALSE; |
| 310 | 310 | } |
| 311 | 311 | } |
| 312 | - if ( $entry->num_rows > 1 ) {$warn = "<$value> seems to be present more than once in <$listdep>. Contact a sysadmin NOW!";} |
|
| 312 | + if ($entry->num_rows>1) {$warn = "<$value> seems to be present more than once in <$listdep>. Contact a sysadmin NOW!"; } |
|
| 313 | 313 | } |
| 314 | 314 | $entry->free(); |
| 315 | 315 | } |
@@ -317,20 +317,20 @@ discard block |
||
| 317 | 317 | return TRUE; |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | -function searchentry ($myconn,$value,$tablelist) { |
|
| 320 | +function searchentry($myconn, $value, $tablelist) { |
|
| 321 | 321 | /* Make a MYSQL query and return result */ |
| 322 | 322 | |
| 323 | 323 | $type = $tablelist['field']; |
| 324 | 324 | |
| 325 | - if ( $tablelist['milter'] ) { |
|
| 325 | + if ($tablelist['milter']) { |
|
| 326 | 326 | $table = milterTable($type); |
| 327 | 327 | if ($value == 'ALL') |
| 328 | 328 | $query = sprintf('SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id) GROUP by idmilt', |
| 329 | - $table,$table); |
|
| 329 | + $table, $table); |
|
| 330 | 330 | else { |
| 331 | 331 | switch ($type) { |
| 332 | 332 | case 'network': |
| 333 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
| 333 | + list($sub['net'], $sub['mask']) = explode('/', $value); |
|
| 334 | 334 | $query = sprintf('SELECT * FROM ( |
| 335 | 335 | SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id) |
| 336 | 336 | WHERE ( |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | ) AS val WHERE val.ip IS NOT null', $table, $table, $value); |
| 349 | 349 | break; |
| 350 | 350 | default: |
| 351 | - syslog(LOG_EMERG, 'ALERT: The type <'.$type.'> is not allowed for milter lists.' ); |
|
| 351 | + syslog(LOG_EMERG, 'ALERT: The type <'.$type.'> is not allowed for milter lists.'); |
|
| 352 | 352 | return FALSE; |
| 353 | 353 | } |
| 354 | 354 | } |
@@ -360,11 +360,11 @@ discard block |
||
| 360 | 360 | else { |
| 361 | 361 | switch ($type) { |
| 362 | 362 | case 'ip': |
| 363 | - $query= "select * from $table where $type = INET_ATON('$value')"; |
|
| 363 | + $query = "select * from $table where $type = INET_ATON('$value')"; |
|
| 364 | 364 | break; |
| 365 | 365 | case 'network': |
| 366 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
| 367 | - $query= sprintf('select * from `%s` |
|
| 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) ) ) |
@@ -373,18 +373,18 @@ discard block |
||
| 373 | 373 | ; |
| 374 | 374 | break; |
| 375 | 375 | default: |
| 376 | - $query= "select * from $table where $type = '$value'"; |
|
| 376 | + $query = "select * from $table where $type = '$value'"; |
|
| 377 | 377 | } |
| 378 | 378 | } |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | $result = $myconn->query($query); |
| 382 | - if($result === false) |
|
| 382 | + if ($result === false) |
|
| 383 | 383 | syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error); |
| 384 | 384 | return $result; |
| 385 | 385 | } |
| 386 | 386 | |
| 387 | -function countListed ($myconn,$table) { |
|
| 387 | +function countListed($myconn, $table) { |
|
| 388 | 388 | /* Return number of current listed items into a rbl table */ |
| 389 | 389 | $query = "SELECT COUNT(*) as `count` FROM `$table` WHERE (`active`=1 AND TIMESTAMPDIFF(MICROSECOND,NOW(),`exp`)>0) GROUP BY `active` ORDER BY `count` DESC LIMIT 1"; |
| 390 | 390 | $row = $myconn->query($query); |
@@ -395,27 +395,27 @@ discard block |
||
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | |
| 398 | -function isFull($myconn,$typedesc,$alltables) { |
|
| 398 | +function isFull($myconn, $typedesc, $alltables) { |
|
| 399 | 399 | if (isset($alltables["$typedesc"]['limit'])) { |
| 400 | - if ( $alltables["$typedesc"]['milter'] ) |
|
| 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'] ) |
|
| 404 | + if (countListed($myconn, $tab)>=$alltables["$typedesc"]['limit']) |
|
| 405 | 405 | return TRUE; |
| 406 | 406 | } |
| 407 | 407 | return FALSE; |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | -function rlookup ($myconn,$user,$adm,$value,$typedesc,$tables) { |
|
| 410 | +function rlookup($myconn, $user, $adm, $value, $typedesc, $tables) { |
|
| 411 | 411 | |
| 412 | 412 | $type = $tables["$typedesc"]['field']; |
| 413 | - $whynot=NULL; |
|
| 413 | + $whynot = NULL; |
|
| 414 | 414 | |
| 415 | 415 | $tabhtm = <<<END |
| 416 | 416 | <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 | 417 | END; |
| 418 | - if ( $tables["$typedesc"]['milter'] ) |
|
| 418 | + if ($tables["$typedesc"]['milter']) |
|
| 419 | 419 | $tabhtm .= '<th title="Milter active for this object">Milters</th>'; |
| 420 | 420 | $tabhtm .= '<th>Authored by</th><th width="250">Reason</th><th>Action</th></tr></thead><tfoot><tr></tr></tfoot><tbody>'."\n"; |
| 421 | 421 | |
@@ -424,24 +424,24 @@ discard block |
||
| 424 | 424 | if (is_null($value)) |
| 425 | 425 | return FALSE; |
| 426 | 426 | |
| 427 | - $result = searchentry ($myconn,$value,$tables["$typedesc"]); |
|
| 427 | + $result = searchentry($myconn, $value, $tables["$typedesc"]); |
|
| 428 | 428 | if ($result) { |
| 429 | 429 | printf("<pre>Your request for $type <$value> returned %d items.\n</pre>", $result->num_rows); |
| 430 | 430 | |
| 431 | 431 | /* Check for limit in number of listed items */ |
| 432 | - $full = isFull($myconn,$typedesc,$tables); |
|
| 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 | - $i=0; |
|
| 437 | + $i = 0; |
|
| 438 | 438 | while ($riga = $result->fetch_array(MYSQLI_ASSOC)) { |
| 439 | 439 | if (isListed($riga)) { |
| 440 | - if ($tables["$typedesc"]['bl']) $listed='Listed'; |
|
| 441 | - else $listed='WhiteListed'; |
|
| 440 | + if ($tables["$typedesc"]['bl']) $listed = 'Listed'; |
|
| 441 | + else $listed = 'WhiteListed'; |
|
| 442 | 442 | } |
| 443 | 443 | else |
| 444 | - $listed='Ok'; |
|
| 444 | + $listed = 'Ok'; |
|
| 445 | 445 | |
| 446 | 446 | switch ($type) { |
| 447 | 447 | case 'ip': |
@@ -454,20 +454,20 @@ discard block |
||
| 454 | 454 | $element = $riga["$type"]; |
| 455 | 455 | } |
| 456 | 456 | |
| 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", |
|
| 459 | - $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)); |
|
| 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", |
|
| 459 | + $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 | 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", |
|
| 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)); |
|
| 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 | + $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 { |
| 468 | 468 | 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'); |
|
| 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 | 471 | else print '<p>'.htmlspecialchars($whynot).'</p>'; |
| 472 | 472 | |
| 473 | 473 | } |
@@ -479,12 +479,12 @@ discard block |
||
| 479 | 479 | |
| 480 | 480 | |
| 481 | 481 | |
| 482 | -function sendEmailWarn($tplf,$from,$to,$sbj,$emailListed,$intervalToExpire,$detail) { |
|
| 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); |
|
| 486 | - $messageID = md5(uniqid($now,1)) . '@' . gethostname(); |
|
| 487 | - $mua = 'PHP/' . phpversion(); |
|
| 484 | + setlocale(LC_TIME, 'it_IT'); |
|
| 485 | + $date = date("r", $now); |
|
| 486 | + $messageID = md5(uniqid($now, 1)).'@'.gethostname(); |
|
| 487 | + $mua = 'PHP/'.phpversion(); |
|
| 488 | 488 | |
| 489 | 489 | /* Parsing headers */ |
| 490 | 490 | if (!file_exists($tplf['header'])) { |
@@ -493,10 +493,10 @@ discard block |
||
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | $head_tmpl = file_get_contents($tplf['header']); |
| 496 | - $arr_tpl_vars = array('{from}','{to}','{date}','{messageID}','{mua}'); |
|
| 497 | - $arr_tpl_data = array($from,$to,$date,$messageID,$mua); |
|
| 496 | + $arr_tpl_vars = array('{from}', '{to}', '{date}', '{messageID}', '{mua}'); |
|
| 497 | + $arr_tpl_data = array($from, $to, $date, $messageID, $mua); |
|
| 498 | 498 | $headers = str_replace($arr_tpl_vars, $arr_tpl_data, $head_tmpl); |
| 499 | - $headers = preg_replace( '/\r|\n/', "\r\n", $headers ); |
|
| 499 | + $headers = preg_replace('/\r|\n/', "\r\n", $headers); |
|
| 500 | 500 | |
| 501 | 501 | /* Parsing body */ |
| 502 | 502 | |
@@ -506,62 +506,62 @@ discard block |
||
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | $body_tmpl = file_get_contents($tplf['body']); |
| 509 | - $arr_tpl_vars = array('{emailListed}','{expInterval}','{reason}'); |
|
| 510 | - $arr_tpl_data = array($emailListed,$intervalToExpire,$detail); |
|
| 509 | + $arr_tpl_vars = array('{emailListed}', '{expInterval}', '{reason}'); |
|
| 510 | + $arr_tpl_data = array($emailListed, $intervalToExpire, $detail); |
|
| 511 | 511 | $body = str_replace($arr_tpl_vars, $arr_tpl_data, $body_tmpl); |
| 512 | - $body = preg_replace( "/\r|\n/", "\r\n", $body ); |
|
| 513 | - $body = wordwrap ( $body, 75 , "\r\n" ); |
|
| 512 | + $body = preg_replace("/\r|\n/", "\r\n", $body); |
|
| 513 | + $body = wordwrap($body, 75, "\r\n"); |
|
| 514 | 514 | |
| 515 | 515 | /* Send the mail! */ |
| 516 | - if ( strlen(ini_get("safe_mode"))< 1) { |
|
| 516 | + if (strlen(ini_get("safe_mode"))<1) { |
|
| 517 | 517 | $old_mailfrom = ini_get("sendmail_from"); |
| 518 | 518 | ini_set("sendmail_from", $from); |
| 519 | 519 | $params = sprintf("-oi -f %s", '<>'); |
| 520 | - if (!(mail($to,$sbj, $body,$headers,$params))) $flag=FALSE; |
|
| 521 | - else $flag=TRUE; |
|
| 520 | + if (!(mail($to, $sbj, $body, $headers, $params))) $flag = FALSE; |
|
| 521 | + else $flag = TRUE; |
|
| 522 | 522 | if (isset($old_mailfrom)) |
| 523 | 523 | ini_set("sendmail_from", $old_mailfrom); |
| 524 | 524 | } |
| 525 | 525 | else { |
| 526 | - if (!(mail($to,$sbj, $body,$headers))) $flag=FALSE; |
|
| 527 | - else $flag=TRUE; |
|
| 526 | + if (!(mail($to, $sbj, $body, $headers))) $flag = FALSE; |
|
| 527 | + else $flag = TRUE; |
|
| 528 | 528 | } |
| 529 | 529 | return $flag; |
| 530 | 530 | } |
| 531 | 531 | |
| 532 | -function emailToNotify($notify_file,$dom) { |
|
| 532 | +function emailToNotify($notify_file, $dom) { |
|
| 533 | 533 | $ini_array = parse_ini_file($notify_file); |
| 534 | - if (in_array($dom,array_keys($ini_array))) |
|
| 534 | + if (in_array($dom, array_keys($ini_array))) |
|
| 535 | 535 | return $ini_array["$dom"]; |
| 536 | 536 | else return FALSE; |
| 537 | 537 | } |
| 538 | 538 | |
| 539 | 539 | |
| 540 | -function searchAndList ($myconn,$loguser,$tables,$typedesc,$value,$unit,&$quantity,&$reason) { |
|
| 540 | +function searchAndList($myconn, $loguser, $tables, $typedesc, $value, $unit, &$quantity, &$reason) { |
|
| 541 | 541 | |
| 542 | 542 | /* Search and list value */ |
| 543 | 543 | $type = $tables["$typedesc"]['field']; |
| 544 | 544 | $table = $tables["$typedesc"]['name']; |
| 545 | - $result = searchentry ($myconn,$value,$tables["$typedesc"]); |
|
| 545 | + $result = searchentry($myconn, $value, $tables["$typedesc"]); |
|
| 546 | 546 | |
| 547 | 547 | /* Manage abnormal conditions */ |
| 548 | 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."); |
|
| 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 | 551 | $result->free(); |
| 552 | 552 | return FALSE; |
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | /* Value already present in db or not present: to list anyway */ |
| 556 | - if ($result->num_rows >= 0) { |
|
| 556 | + if ($result->num_rows>=0) { |
|
| 557 | 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.'); |
|
| 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 | 560 | $result->free(); |
| 561 | 561 | return FALSE; |
| 562 | 562 | } |
| 563 | 563 | /* Second, check if the (re)list would be consistent now */ |
| 564 | - if (! consistentListing($myconn,$tables,$typedesc,$value,$whynot) ) { |
|
| 564 | + if (!consistentListing($myconn, $tables, $typedesc, $value, $whynot)) { |
|
| 565 | 565 | syslog(LOG_ERR, $loguser.': '.$whynot); |
| 566 | 566 | $result->free(); |
| 567 | 567 | return FALSE; |
@@ -575,7 +575,7 @@ discard block |
||
| 575 | 575 | switch ($result->num_rows) { |
| 576 | 576 | /* Relist value if already present */ |
| 577 | 577 | case 1: |
| 578 | - if ( isListed($thisentry) ) { |
|
| 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.', |
@@ -589,33 +589,33 @@ discard block |
||
| 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 | 594 | /* First time list value */ |
| 595 | 595 | case 0: |
| 596 | 596 | $result->free(); |
| 597 | - return addtolist ($myconn,$loguser,$value,$tables["$typedesc"],$unit,$quantity,$reason,$_); |
|
| 597 | + return addtolist($myconn, $loguser, $value, $tables["$typedesc"], $unit, $quantity, $reason, $_); |
|
| 598 | 598 | } |
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | |
| 602 | 602 | /*************** Functions to check if two net overlap each other ********************/ |
| 603 | 603 | |
| 604 | -function ipRange ($range) { |
|
| 604 | +function ipRange($range) { |
|
| 605 | 605 | /* List IP in range */ |
| 606 | - return array_map('long2ip', range( ip2long($range[0]), ip2long($range[1]) ) ); |
|
| 606 | + return array_map('long2ip', range(ip2long($range[0]), ip2long($range[1]))); |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | function isIn($netA, $netB) { |
| 610 | 610 | /* TRUE if an IP of $netA is contained in netB */ |
| 611 | - list($addressA,$maskA) = explode('/', $netA); |
|
| 612 | - list($addressB,$maskB) = explode('/', $netB); |
|
| 611 | + list($addressA, $maskA) = explode('/', $netA); |
|
| 612 | + list($addressB, $maskB) = explode('/', $netB); |
|
| 613 | 613 | require_once 'vendor/autoload.php'; |
| 614 | 614 | $net = new \dautkom\ipv4\IPv4(); |
| 615 | 615 | $range = $net->address($addressA)->mask($maskA)->getRange(); |
| 616 | 616 | $ips = ipRange($range); |
| 617 | - foreach ( $ips as $ip ) |
|
| 618 | - if ( $net->address($addressB)->mask($maskB)->has($ip) ) |
|
| 617 | + foreach ($ips as $ip) |
|
| 618 | + if ($net->address($addressB)->mask($maskB)->has($ip)) |
|
| 619 | 619 | return TRUE; |
| 620 | 620 | return FALSE; |
| 621 | 621 | } |
@@ -627,11 +627,11 @@ discard block |
||
| 627 | 627 | syslog(LOG_ERR, $loguser.': '.$tabletype['name'].' is not a network list.'); |
| 628 | 628 | return FALSE; |
| 629 | 629 | } |
| 630 | - $result = searchentry ($myconn,'ALL',$tabletype); |
|
| 630 | + $result = searchentry($myconn, 'ALL', $tabletype); |
|
| 631 | 631 | if ($result->num_rows) { |
| 632 | 632 | while ($row = $result->fetch_array(MYSQLI_ASSOC)) { |
| 633 | 633 | $thisNet = long2ip($row['network']).'/'.long2ip($row['netmask']); |
| 634 | - if ( isIn($thisNet, $net) ) { |
|
| 634 | + if (isIn($thisNet, $net)) { |
|
| 635 | 635 | $result->free(); |
| 636 | 636 | syslog(LOG_INFO, "$loguser: the net <$net> overlaps the existing network <$thisNet>."); |
| 637 | 637 | return TRUE; |
@@ -648,8 +648,8 @@ discard block |
||
| 648 | 648 | /* For miltermap */ |
| 649 | 649 | function checkMilterConf($table) { |
| 650 | 650 | if (isset($table['milter'])) { |
| 651 | - if ($table['milter'] === TRUE) { |
|
| 652 | - switch ( $table['field'] ) { |
|
| 651 | + if ($table['milter'] === TRUE) { |
|
| 652 | + switch ($table['field']) { |
|
| 653 | 653 | case 'network': |
| 654 | 654 | case 'ip': |
| 655 | 655 | return TRUE; |
@@ -683,12 +683,12 @@ discard block |
||
| 683 | 683 | } |
| 684 | 684 | |
| 685 | 685 | |
| 686 | -function readMiltName($myconn,$loguser) { |
|
| 687 | - $milters=array(); |
|
| 686 | +function readMiltName($myconn, $loguser) { |
|
| 687 | + $milters = array(); |
|
| 688 | 688 | $query = 'SELECT `name` FROM `config`'; |
| 689 | 689 | |
| 690 | 690 | $result = $myconn->query($query); |
| 691 | - if($result === false) { |
|
| 691 | + if ($result === false) { |
|
| 692 | 692 | syslog(LOG_EMERG, "$loguser: ALERT: Query <$query> failed: ".$myconn->error); |
| 693 | 693 | return FALSE; |
| 694 | 694 | } |
@@ -700,27 +700,27 @@ discard block |
||
| 700 | 700 | return $milters; |
| 701 | 701 | } |
| 702 | 702 | |
| 703 | -function changeMilter ($myconn,$loguser,$miltVal,$table,$miltID) { |
|
| 703 | +function changeMilter($myconn, $loguser, $miltVal, $table, $miltID) { |
|
| 704 | 704 | $query = array(); |
| 705 | - foreach ( $miltVal as $value => $action ) { |
|
| 706 | - switch ( $action ) { |
|
| 705 | + foreach ($miltVal as $value => $action) { |
|
| 706 | + switch ($action) { |
|
| 707 | 707 | case 'keep': |
| 708 | 708 | break; |
| 709 | 709 | case 'add': |
| 710 | - $query[] = sprintf( "INSERT INTO `milt` ( |
|
| 710 | + $query[] = sprintf("INSERT INTO `milt` ( |
|
| 711 | 711 | `id` , |
| 712 | 712 | `name` |
| 713 | 713 | ) |
| 714 | 714 | VALUES ( |
| 715 | 715 | %d , |
| 716 | 716 | '%s' |
| 717 | - )",$miltID,$value); |
|
| 717 | + )",$miltID, $value); |
|
| 718 | 718 | break; |
| 719 | 719 | case 'del': |
| 720 | 720 | $query[] = "DELETE FROM `milt` WHERE (`id` = '$miltID' AND `name` = '$value')"; |
| 721 | 721 | } |
| 722 | 722 | } |
| 723 | - if ( count($query) ) /* This "if" is redundant, because if I call this I already checked there is a change */ |
|
| 723 | + if (count($query)) /* This "if" is redundant, because if I call this I already checked there is a change */ |
|
| 724 | 724 | /* I update datemod because the user couldn't change */ |
| 725 | 725 | $query[] = sprintf('UPDATE `%s` SET |
| 726 | 726 | `user`=\'%s\', |
@@ -732,18 +732,18 @@ discard block |
||
| 732 | 732 | $myconn->autocommit(FALSE); |
| 733 | 733 | $myconn->begin_transaction(MYSQLI_TRANS_START_READ_ONLY); |
| 734 | 734 | $ok = TRUE; |
| 735 | - foreach ( $query as $q ) { |
|
| 735 | + foreach ($query as $q) { |
|
| 736 | 736 | if ($myconn->query($q) !== TRUE) { |
| 737 | 737 | $ok = FALSE; |
| 738 | 738 | syslog(LOG_ERR, "$loguser: Error: ".$myconn->error); |
| 739 | 739 | } |
| 740 | 740 | } |
| 741 | - if ( $ok ) { |
|
| 742 | - if ( $myconn->commit() ) |
|
| 741 | + if ($ok) { |
|
| 742 | + if ($myconn->commit()) |
|
| 743 | 743 | syslog(LOG_INFO, "$loguser: Milter setting changed successfully."); |
| 744 | 744 | else { |
| 745 | 745 | syslog(LOG_ERR, "$loguser: Milter setting NOT changed for an unpredictable COMMIT error."); |
| 746 | - if ( $myconn->rollback() ) |
|
| 746 | + if ($myconn->rollback()) |
|
| 747 | 747 | syslog(LOG_INFO, "$loguser: rollback succeeded."); |
| 748 | 748 | else |
| 749 | 749 | syslog(LOG_ERR, "$loguser: rollback failed. Your db could be compromized. Check it!"); |
@@ -760,15 +760,15 @@ discard block |
||
| 760 | 760 | function curl_get($url, array $get = NULL, array $options = array(), $loguser) |
| 761 | 761 | { |
| 762 | 762 | $defaults = array( |
| 763 | - CURLOPT_URL => $url. (strpos($url, '?') === FALSE ? '?' : ''). http_build_query($get), |
|
| 763 | + CURLOPT_URL => $url.(strpos($url, '?') === FALSE ? '?' : '').http_build_query($get), |
|
| 764 | 764 | CURLOPT_HEADER => 0, |
| 765 | 765 | CURLOPT_RETURNTRANSFER => TRUE, |
| 766 | 766 | CURLOPT_TIMEOUT => 4 |
| 767 | 767 | ); |
| 768 | 768 | |
| 769 | 769 | $ch = curl_init(); |
| 770 | - curl_setopt_array($ch, ($options + $defaults)); |
|
| 771 | - if( ! $result = curl_exec($ch)) |
|
| 770 | + curl_setopt_array($ch, ($options+$defaults)); |
|
| 771 | + if (!$result = curl_exec($ch)) |
|
| 772 | 772 | { |
| 773 | 773 | syslog(LOG_ERR, sprintf('%s: CURL Error: <%s>', $loguser, curl_error($ch))); |
| 774 | 774 | } |
@@ -780,19 +780,19 @@ discard block |
||
| 780 | 780 | function nsdom($dom) { |
| 781 | 781 | /* Return the first upper domain (or domain itself) with NS record */ |
| 782 | 782 | /* checkdnsrr doesn't work with alias... use dns_get_record */ |
| 783 | - if (dns_get_record ( $dom , DNS_NS )) |
|
| 783 | + if (dns_get_record($dom, DNS_NS)) |
|
| 784 | 784 | return rtrim($dom, '.'); |
| 785 | - if (dns_get_record ( $dom , DNS_A )) |
|
| 786 | - return nsdom( ltrim(strstr($dom, '.'), '.') ); |
|
| 785 | + if (dns_get_record($dom, DNS_A)) |
|
| 786 | + return nsdom(ltrim(strstr($dom, '.'), '.')); |
|
| 787 | 787 | return NULL; |
| 788 | 788 | } |
| 789 | 789 | |
| 790 | 790 | function isValid($dom) { |
| 791 | 791 | /* Return TRUE id domain has NS or A record */ |
| 792 | - 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' )) |
|
| 792 | + 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 | 794 | return TRUE; |
| 795 | - if (checkdnsrr ( $dom , 'A' )) |
|
| 795 | + if (checkdnsrr($dom, 'A')) |
|
| 796 | 796 | return TRUE; |
| 797 | 797 | } |
| 798 | 798 | return FALSE; |
@@ -3,22 +3,27 @@ discard block |
||
| 3 | 3 | ini_set('error_log', 'syslog'); |
| 4 | 4 | |
| 5 | 5 | function username() { |
| 6 | - if (isset ($_SERVER['REMOTE_USER'])) $user = $_SERVER['REMOTE_USER']; |
|
| 7 | - else if (isset ($_SERVER['USER'])) $user = $_SERVER['USER']; |
|
| 8 | - else $user='unknown'; |
|
| 6 | + if (isset ($_SERVER['REMOTE_USER'])) { |
|
| 7 | + $user = $_SERVER['REMOTE_USER']; |
|
| 8 | + } else if (isset ($_SERVER['USER'])) { |
|
| 9 | + $user = $_SERVER['USER']; |
|
| 10 | + } else { |
|
| 11 | + $user='unknown'; |
|
| 12 | + } |
|
| 9 | 13 | return $user; |
| 10 | 14 | } |
| 11 | 15 | |
| 12 | 16 | function checkSSL() { |
| 13 | - if ( empty( $_SERVER['HTTPS'] ) ) |
|
| 14 | - printf ('<div id="content">Ehi sysadmin! Your site is not secure. Please enable SSL on your server and configure a redirect, such as' . |
|
| 17 | + if ( empty( $_SERVER['HTTPS'] ) ) { |
|
| 18 | + printf ('<div id="content">Ehi sysadmin! Your site is not secure. Please enable SSL on your server and configure a redirect, such as' . |
|
| 15 | 19 | '<pre>' . |
| 16 | 20 | htmlspecialchars('<VirtualHost *:80>' . "\n" . |
| 17 | 21 | ' ServerName %s' . "\n" . |
| 18 | 22 | ' Redirect permanent / https://%s/' . "\n" . |
| 19 | 23 | '</VirtualHost>') . |
| 20 | 24 | '</pre></div>', gethostname(), gethostname()); |
| 21 | -} |
|
| 25 | + } |
|
| 26 | + } |
|
| 22 | 27 | |
| 23 | 28 | function myConnect($host, $user, $pass, $db, $port, $tablelist, $typedesc, $loguser) { |
| 24 | 29 | $db = ( $tablelist["$typedesc"]['milter'] ) ? $tablelist["$typedesc"]['name'] : $db; |
@@ -99,8 +104,9 @@ discard block |
||
| 99 | 104 | if ($myconn->query($query) === TRUE) { |
| 100 | 105 | syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit."); |
| 101 | 106 | $result=TRUE; |
| 107 | + } else { |
|
| 108 | + syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
|
| 102 | 109 | } |
| 103 | - else syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
|
| 104 | 110 | return $result; |
| 105 | 111 | } |
| 106 | 112 | |
@@ -110,8 +116,7 @@ discard block |
||
| 110 | 116 | if ( $exptime ) { /* Entry already listed */ |
| 111 | 117 | $nlist = '`nlist`'; |
| 112 | 118 | $exptime = sprintf('\'%s\'', $exptime); /* Eh MySQL... an hour lost to notice this */ |
| 113 | - } |
|
| 114 | - else { |
|
| 119 | + } else { |
|
| 115 | 120 | $exptime = 'CURRENT_TIMESTAMP'; |
| 116 | 121 | $nlist = '`nlist` + 1'; |
| 117 | 122 | } |
@@ -149,8 +154,9 @@ discard block |
||
| 149 | 154 | if ($myconn->query($query) === TRUE) { |
| 150 | 155 | syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit from $exptime."); |
| 151 | 156 | $result=TRUE; |
| 157 | + } else { |
|
| 158 | + syslog (LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 152 | 159 | } |
| 153 | - else syslog (LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 154 | 160 | return $result; |
| 155 | 161 | } |
| 156 | 162 | |
@@ -173,9 +179,11 @@ discard block |
||
| 173 | 179 | } |
| 174 | 180 | |
| 175 | 181 | |
| 176 | - if ($return=$myconn->query($query) === TRUE) |
|
| 177 | - syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>."); |
|
| 178 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 182 | + if ($return=$myconn->query($query) === TRUE) { |
|
| 183 | + syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>."); |
|
| 184 | + } else { |
|
| 185 | + syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 186 | + } |
|
| 179 | 187 | |
| 180 | 188 | return $return; |
| 181 | 189 | } |
@@ -197,8 +205,9 @@ discard block |
||
| 197 | 205 | |
| 198 | 206 | if ($return=$myconn->query($query) === TRUE) { |
| 199 | 207 | syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>"); |
| 208 | + } else { |
|
| 209 | + syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 200 | 210 | } |
| 201 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 202 | 211 | return $return; |
| 203 | 212 | } |
| 204 | 213 | |
@@ -222,14 +231,16 @@ discard block |
||
| 222 | 231 | $j++; |
| 223 | 232 | |
| 224 | 233 | } while ($myconn->next_result()); |
| 225 | - } |
|
| 226 | - else { |
|
| 234 | + } else { |
|
| 227 | 235 | syslog(LOG_ERR, "Expire job - Error: ". $myconn->error); |
| 228 | 236 | $return = FALSE; |
| 229 | 237 | } |
| 230 | 238 | } |
| 231 | - if ( !($return) ) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); |
|
| 232 | - else syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.'); |
|
| 239 | + if ( !($return) ) { |
|
| 240 | + syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); |
|
| 241 | + } else { |
|
| 242 | + syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.'); |
|
| 243 | + } |
|
| 233 | 244 | return $return; |
| 234 | 245 | } |
| 235 | 246 | |
@@ -238,8 +249,11 @@ discard block |
||
| 238 | 249 | |
| 239 | 250 | $exp=new DateTime($row['exp']); |
| 240 | 251 | $now=new DateTime('NOW'); |
| 241 | - if (($exp > $now) and ($row['active'])) return true; |
|
| 242 | - else return false; |
|
| 252 | + if (($exp > $now) and ($row['active'])) { |
|
| 253 | + return true; |
|
| 254 | + } else { |
|
| 255 | + return false; |
|
| 256 | + } |
|
| 243 | 257 | |
| 244 | 258 | } |
| 245 | 259 | |
@@ -259,10 +273,11 @@ discard block |
||
| 259 | 273 | END; |
| 260 | 274 | $activeMilts = explode(',',$value); |
| 261 | 275 | foreach ( $milts as $milter ) { |
| 262 | - if ( in_array($milter, $activeMilts) ) |
|
| 263 | - $selected= 'selected'; |
|
| 264 | - else |
|
| 265 | - $selected= NULL; |
|
| 276 | + if ( in_array($milter, $activeMilts) ) { |
|
| 277 | + $selected= 'selected'; |
|
| 278 | + } else { |
|
| 279 | + $selected= NULL; |
|
| 280 | + } |
|
| 266 | 281 | $button .= sprintf('<option value="%s" %s>%s</option>', $milter, $selected, $milter); |
| 267 | 282 | } |
| 268 | 283 | $button .= '</select></div><input class="button" name="Change" type="submit" value="Change" /></form>'; |
@@ -279,9 +294,12 @@ discard block |
||
| 279 | 294 | $whynot=NULL; |
| 280 | 295 | switch ($what) { |
| 281 | 296 | case 'Ok': |
| 282 | - if ($lock) return NULL; |
|
| 283 | - if (in_array($user,array_keys($adm))) |
|
| 284 | - if ( consistentListing($myconn,$alltables,$typedesc,$value,$whynot) ) return require('relistButton.php'); |
|
| 297 | + if ($lock) { |
|
| 298 | + return NULL; |
|
| 299 | + } |
|
| 300 | + if (in_array($user,array_keys($adm))) { |
|
| 301 | + if ( consistentListing($myconn,$alltables,$typedesc,$value,$whynot) ) return require('relistButton.php'); |
|
| 302 | + } |
|
| 285 | 303 | return htmlspecialchars($whynot); |
| 286 | 304 | case 'Listed': |
| 287 | 305 | case 'WhiteListed': |
@@ -293,7 +311,9 @@ discard block |
||
| 293 | 311 | function consistentListing($myconn,$alltables,$typed,$value,&$warn) { |
| 294 | 312 | /* Check if there are no pending mislisting */ |
| 295 | 313 | $warn = NULL; |
| 296 | - if (! isset($alltables["$typed"]['depend']) ) return TRUE; |
|
| 314 | + if (! isset($alltables["$typed"]['depend']) ) { |
|
| 315 | + return TRUE; |
|
| 316 | + } |
|
| 297 | 317 | foreach ($alltables["$typed"]['depend'] as $listdep) { |
| 298 | 318 | if ($alltables["$typed"]['field'] != $alltables["$listdep"]['field'] ) { |
| 299 | 319 | $warn = "Config ERROR: <$typed> and <$listdep> are of different types! I can't check consistency!"; |
@@ -324,10 +344,10 @@ discard block |
||
| 324 | 344 | |
| 325 | 345 | if ( $tablelist['milter'] ) { |
| 326 | 346 | $table = milterTable($type); |
| 327 | - if ($value == 'ALL') |
|
| 328 | - $query = sprintf('SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id) GROUP by idmilt', |
|
| 347 | + if ($value == 'ALL') { |
|
| 348 | + $query = sprintf('SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id) GROUP by idmilt', |
|
| 329 | 349 | $table,$table); |
| 330 | - else { |
|
| 350 | + } else { |
|
| 331 | 351 | switch ($type) { |
| 332 | 352 | case 'network': |
| 333 | 353 | list($sub['net'],$sub['mask'])=explode('/',$value); |
@@ -352,12 +372,11 @@ discard block |
||
| 352 | 372 | return FALSE; |
| 353 | 373 | } |
| 354 | 374 | } |
| 355 | - } |
|
| 356 | - |
|
| 357 | - else { |
|
| 375 | + } else { |
|
| 358 | 376 | $table = $tablelist['name']; |
| 359 | - if ($value == 'ALL') $query = 'select * from '.$table; |
|
| 360 | - else { |
|
| 377 | + if ($value == 'ALL') { |
|
| 378 | + $query = 'select * from '.$table; |
|
| 379 | + } else { |
|
| 361 | 380 | switch ($type) { |
| 362 | 381 | case 'ip': |
| 363 | 382 | $query= "select * from $table where $type = INET_ATON('$value')"; |
@@ -379,8 +398,9 @@ discard block |
||
| 379 | 398 | } |
| 380 | 399 | |
| 381 | 400 | $result = $myconn->query($query); |
| 382 | - if($result === false) |
|
| 383 | - syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error); |
|
| 401 | + if($result === false) { |
|
| 402 | + syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error); |
|
| 403 | + } |
|
| 384 | 404 | return $result; |
| 385 | 405 | } |
| 386 | 406 | |
@@ -397,12 +417,14 @@ discard block |
||
| 397 | 417 | |
| 398 | 418 | function isFull($myconn,$typedesc,$alltables) { |
| 399 | 419 | if (isset($alltables["$typedesc"]['limit'])) { |
| 400 | - if ( $alltables["$typedesc"]['milter'] ) |
|
| 401 | - $tab = 'net'; |
|
| 402 | - else |
|
| 403 | - $tab = $alltables["$typedesc"]['name']; |
|
| 404 | - if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) |
|
| 405 | - return TRUE; |
|
| 420 | + if ( $alltables["$typedesc"]['milter'] ) { |
|
| 421 | + $tab = 'net'; |
|
| 422 | + } else { |
|
| 423 | + $tab = $alltables["$typedesc"]['name']; |
|
| 424 | + } |
|
| 425 | + if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) { |
|
| 426 | + return TRUE; |
|
| 427 | + } |
|
| 406 | 428 | } |
| 407 | 429 | return FALSE; |
| 408 | 430 | } |
@@ -415,14 +437,17 @@ discard block |
||
| 415 | 437 | $tabhtm = <<<END |
| 416 | 438 | <table><thead><tr><th>$type</th><th title="The date this object has been listed for the first time">DateAdd</th><th>DateMod</th><th>Exp</th><th>Status</th><th title="Number of times this object has been listed">#List</th> |
| 417 | 439 | END; |
| 418 | - if ( $tables["$typedesc"]['milter'] ) |
|
| 419 | - $tabhtm .= '<th title="Milter active for this object">Milters</th>'; |
|
| 440 | + if ( $tables["$typedesc"]['milter'] ) { |
|
| 441 | + $tabhtm .= '<th title="Milter active for this object">Milters</th>'; |
|
| 442 | + } |
|
| 420 | 443 | $tabhtm .= '<th>Authored by</th><th width="250">Reason</th><th>Action</th></tr></thead><tfoot><tr></tr></tfoot><tbody>'."\n"; |
| 421 | 444 | |
| 422 | - if ($type == 'domain') |
|
| 423 | - $value = nsdom($value); |
|
| 424 | - if (is_null($value)) |
|
| 425 | - return FALSE; |
|
| 445 | + if ($type == 'domain') { |
|
| 446 | + $value = nsdom($value); |
|
| 447 | + } |
|
| 448 | + if (is_null($value)) { |
|
| 449 | + return FALSE; |
|
| 450 | + } |
|
| 426 | 451 | |
| 427 | 452 | $result = searchentry ($myconn,$value,$tables["$typedesc"]); |
| 428 | 453 | if ($result) { |
@@ -430,18 +455,23 @@ discard block |
||
| 430 | 455 | |
| 431 | 456 | /* Check for limit in number of listed items */ |
| 432 | 457 | $full = isFull($myconn,$typedesc,$tables); |
| 433 | - if ($full) print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>'; |
|
| 458 | + if ($full) { |
|
| 459 | + print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>'; |
|
| 460 | + } |
|
| 434 | 461 | |
| 435 | 462 | if ($result->num_rows) { |
| 436 | 463 | print $tabhtm; |
| 437 | 464 | $i=0; |
| 438 | 465 | while ($riga = $result->fetch_array(MYSQLI_ASSOC)) { |
| 439 | 466 | if (isListed($riga)) { |
| 440 | - if ($tables["$typedesc"]['bl']) $listed='Listed'; |
|
| 441 | - else $listed='WhiteListed'; |
|
| 442 | - } |
|
| 443 | - else |
|
| 444 | - $listed='Ok'; |
|
| 467 | + if ($tables["$typedesc"]['bl']) { |
|
| 468 | + $listed='Listed'; |
|
| 469 | + } else { |
|
| 470 | + $listed='WhiteListed'; |
|
| 471 | + } |
|
| 472 | + } else { |
|
| 473 | + $listed='Ok'; |
|
| 474 | + } |
|
| 445 | 475 | |
| 446 | 476 | switch ($type) { |
| 447 | 477 | case 'ip': |
@@ -454,27 +484,30 @@ discard block |
||
| 454 | 484 | $element = $riga["$type"]; |
| 455 | 485 | } |
| 456 | 486 | |
| 457 | - if ( $tables["$typedesc"]['milter'] AND checkMilterConf($tables["$typedesc"]) ) |
|
| 458 | - printf ("<tr id=id$i><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td nowrap id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td>%s</td></tr>\n", |
|
| 487 | + if ( $tables["$typedesc"]['milter'] AND checkMilterConf($tables["$typedesc"]) ) { |
|
| 488 | + printf ("<tr id=id$i><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td nowrap id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td>%s</td></tr>\n", |
|
| 459 | 489 | $element, $riga['date'], $riga['datemod'], $riga['exp'], $riga['active'], $riga['nlist'], askMilter($myconn,$i,$element,$typedesc,$riga['idmilt'],$riga['miltnames'],$user,$adm), $riga['user'],htmlspecialchars($riga['reason']),ask($myconn,$i,$listed,$tables,$typedesc,$element,$full,$user,$adm)); |
| 460 | - else |
|
| 461 | - printf ("<tr id=id$i><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td>%s</td></tr>\n", |
|
| 490 | + } else { |
|
| 491 | + printf ("<tr id=id$i><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td>%s</td></tr>\n", |
|
| 462 | 492 | $element, $riga['date'], $riga['datemod'], $riga['exp'], $riga['active'], $riga['nlist'], $riga['user'],htmlspecialchars($riga['reason']),ask($myconn,$i,$listed,$tables,$typedesc,$element,$full,$user,$adm)); |
| 493 | + } |
|
| 463 | 494 | $i++; |
| 464 | 495 | } |
| 465 | 496 | print '</tbody></table>'; |
| 466 | - } |
|
| 467 | - else { |
|
| 497 | + } else { |
|
| 468 | 498 | print "<pre>$type <$value> is not listed!\n</pre>"; |
| 469 | - if ( in_array($user,array_keys($adm)) AND ($value != 'ALL') ) |
|
| 470 | - if ( (!$full) AND (consistentListing($myconn,$tables,$typedesc,$value,$whynot)) ) require_once('listForm.php'); |
|
| 471 | - else print '<p>'.htmlspecialchars($whynot).'</p>'; |
|
| 499 | + if ( in_array($user,array_keys($adm)) AND ($value != 'ALL') ) { |
|
| 500 | + if ( (!$full) AND (consistentListing($myconn,$tables,$typedesc,$value,$whynot)) ) require_once('listForm.php'); |
|
| 501 | + } else { |
|
| 502 | + print '<p>'.htmlspecialchars($whynot).'</p>'; |
|
| 503 | + } |
|
| 472 | 504 | |
| 473 | 505 | } |
| 474 | 506 | $result->free(); |
| 507 | + } else { |
|
| 508 | + print '<pre>Query error or something wrong in DB schema'."\n</pre>"; |
|
| 509 | + } |
|
| 475 | 510 | } |
| 476 | - else print '<pre>Query error or something wrong in DB schema'."\n</pre>"; |
|
| 477 | -} |
|
| 478 | 511 | |
| 479 | 512 | |
| 480 | 513 | |
@@ -517,24 +550,32 @@ discard block |
||
| 517 | 550 | $old_mailfrom = ini_get("sendmail_from"); |
| 518 | 551 | ini_set("sendmail_from", $from); |
| 519 | 552 | $params = sprintf("-oi -f %s", '<>'); |
| 520 | - if (!(mail($to,$sbj, $body,$headers,$params))) $flag=FALSE; |
|
| 521 | - else $flag=TRUE; |
|
| 522 | - if (isset($old_mailfrom)) |
|
| 523 | - ini_set("sendmail_from", $old_mailfrom); |
|
| 524 | - } |
|
| 525 | - else { |
|
| 526 | - if (!(mail($to,$sbj, $body,$headers))) $flag=FALSE; |
|
| 527 | - else $flag=TRUE; |
|
| 553 | + if (!(mail($to,$sbj, $body,$headers,$params))) { |
|
| 554 | + $flag=FALSE; |
|
| 555 | + } else { |
|
| 556 | + $flag=TRUE; |
|
| 557 | + } |
|
| 558 | + if (isset($old_mailfrom)) { |
|
| 559 | + ini_set("sendmail_from", $old_mailfrom); |
|
| 560 | + } |
|
| 561 | + } else { |
|
| 562 | + if (!(mail($to,$sbj, $body,$headers))) { |
|
| 563 | + $flag=FALSE; |
|
| 564 | + } else { |
|
| 565 | + $flag=TRUE; |
|
| 566 | + } |
|
| 528 | 567 | } |
| 529 | 568 | return $flag; |
| 530 | 569 | } |
| 531 | 570 | |
| 532 | 571 | function emailToNotify($notify_file,$dom) { |
| 533 | 572 | $ini_array = parse_ini_file($notify_file); |
| 534 | - if (in_array($dom,array_keys($ini_array))) |
|
| 535 | - return $ini_array["$dom"]; |
|
| 536 | - else return FALSE; |
|
| 537 | -} |
|
| 573 | + if (in_array($dom,array_keys($ini_array))) { |
|
| 574 | + return $ini_array["$dom"]; |
|
| 575 | + } else { |
|
| 576 | + return FALSE; |
|
| 577 | + } |
|
| 578 | + } |
|
| 538 | 579 | |
| 539 | 580 | |
| 540 | 581 | function searchAndList ($myconn,$loguser,$tables,$typedesc,$value,$unit,&$quantity,&$reason) { |
@@ -582,8 +623,7 @@ discard block |
||
| 582 | 623 | $reason); |
| 583 | 624 | $quantity = 1; |
| 584 | 625 | $unit = 'DAY'; |
| 585 | - } |
|
| 586 | - else { |
|
| 626 | + } else { |
|
| 587 | 627 | /* Entry delisted */ |
| 588 | 628 | $quantity *= $thisentry['nlist']; |
| 589 | 629 | $expdate = 0; /* This forces expiration from CURRENT_TIMESTAMP */ |
@@ -614,9 +654,10 @@ discard block |
||
| 614 | 654 | $net = new \dautkom\ipv4\IPv4(); |
| 615 | 655 | $range = $net->address($addressA)->mask($maskA)->getRange(); |
| 616 | 656 | $ips = ipRange($range); |
| 617 | - foreach ( $ips as $ip ) |
|
| 618 | - if ( $net->address($addressB)->mask($maskB)->has($ip) ) |
|
| 657 | + foreach ( $ips as $ip ) { |
|
| 658 | + if ( $net->address($addressB)->mask($maskB)->has($ip) ) |
|
| 619 | 659 | return TRUE; |
| 660 | + } |
|
| 620 | 661 | return FALSE; |
| 621 | 662 | } |
| 622 | 663 | |
@@ -693,8 +734,9 @@ discard block |
||
| 693 | 734 | return FALSE; |
| 694 | 735 | } |
| 695 | 736 | if ($result->num_rows) { |
| 696 | - while ($milt = $result->fetch_array(MYSQLI_ASSOC)) |
|
| 697 | - $milters[] = $milt['name']; |
|
| 737 | + while ($milt = $result->fetch_array(MYSQLI_ASSOC)) { |
|
| 738 | + $milters[] = $milt['name']; |
|
| 739 | + } |
|
| 698 | 740 | } |
| 699 | 741 | $result->free(); |
| 700 | 742 | return $milters; |
@@ -720,12 +762,14 @@ discard block |
||
| 720 | 762 | $query[] = "DELETE FROM `milt` WHERE (`id` = '$miltID' AND `name` = '$value')"; |
| 721 | 763 | } |
| 722 | 764 | } |
| 723 | - if ( count($query) ) /* This "if" is redundant, because if I call this I already checked there is a change */ |
|
| 765 | + if ( count($query) ) { |
|
| 766 | + /* This "if" is redundant, because if I call this I already checked there is a change */ |
|
| 724 | 767 | /* I update datemod because the user couldn't change */ |
| 725 | 768 | $query[] = sprintf('UPDATE `%s` SET |
| 726 | 769 | `user`=\'%s\', |
| 727 | 770 | `datemod`= CURRENT_TIMESTAMP |
| 728 | 771 | WHERE `idmilt`=%d', $table, $loguser, $miltID); |
| 772 | + } |
|
| 729 | 773 | |
| 730 | 774 | |
| 731 | 775 | /* Start a safe transaction: it commits only if all queries happen */ |
@@ -739,19 +783,20 @@ discard block |
||
| 739 | 783 | } |
| 740 | 784 | } |
| 741 | 785 | if ( $ok ) { |
| 742 | - if ( $myconn->commit() ) |
|
| 743 | - syslog(LOG_INFO, "$loguser: Milter setting changed successfully."); |
|
| 744 | - else { |
|
| 786 | + if ( $myconn->commit() ) { |
|
| 787 | + syslog(LOG_INFO, "$loguser: Milter setting changed successfully."); |
|
| 788 | + } else { |
|
| 745 | 789 | syslog(LOG_ERR, "$loguser: Milter setting NOT changed for an unpredictable COMMIT error."); |
| 746 | - if ( $myconn->rollback() ) |
|
| 747 | - syslog(LOG_INFO, "$loguser: rollback succeeded."); |
|
| 748 | - else |
|
| 749 | - syslog(LOG_ERR, "$loguser: rollback failed. Your db could be compromized. Check it!"); |
|
| 790 | + if ( $myconn->rollback() ) { |
|
| 791 | + syslog(LOG_INFO, "$loguser: rollback succeeded."); |
|
| 792 | + } else { |
|
| 793 | + syslog(LOG_ERR, "$loguser: rollback failed. Your db could be compromized. Check it!"); |
|
| 794 | + } |
|
| 750 | 795 | $ok = FALSE; |
| 751 | 796 | } |
| 797 | + } else { |
|
| 798 | + syslog(LOG_ERR, "$loguser: Error: Milter setting NOT changed. See at above errors."); |
|
| 752 | 799 | } |
| 753 | - else |
|
| 754 | - syslog(LOG_ERR, "$loguser: Error: Milter setting NOT changed. See at above errors."); |
|
| 755 | 800 | return $ok; |
| 756 | 801 | |
| 757 | 802 | } |
@@ -780,20 +825,24 @@ discard block |
||
| 780 | 825 | function nsdom($dom) { |
| 781 | 826 | /* Return the first upper domain (or domain itself) with NS record */ |
| 782 | 827 | /* checkdnsrr doesn't work with alias... use dns_get_record */ |
| 783 | - if (dns_get_record ( $dom , DNS_NS )) |
|
| 784 | - return rtrim($dom, '.'); |
|
| 785 | - if (dns_get_record ( $dom , DNS_A )) |
|
| 786 | - return nsdom( ltrim(strstr($dom, '.'), '.') ); |
|
| 828 | + if (dns_get_record ( $dom , DNS_NS )) { |
|
| 829 | + return rtrim($dom, '.'); |
|
| 830 | + } |
|
| 831 | + if (dns_get_record ( $dom , DNS_A )) { |
|
| 832 | + return nsdom( ltrim(strstr($dom, '.'), '.') ); |
|
| 833 | + } |
|
| 787 | 834 | return NULL; |
| 788 | 835 | } |
| 789 | 836 | |
| 790 | 837 | function isValid($dom) { |
| 791 | 838 | /* Return TRUE id domain has NS or A record */ |
| 792 | 839 | if (preg_match('/^(?!:\/\/)([a-zA-Z0-9-]+\.){0,5}[a-zA-Z0-9-][a-zA-Z0-9-]+\.[a-zA-Z]{2,64}?\.{0,1}$/i',$dom) === 1) { |
| 793 | - if (checkdnsrr ( $dom , 'NS' )) |
|
| 794 | - return TRUE; |
|
| 795 | - if (checkdnsrr ( $dom , 'A' )) |
|
| 796 | - return TRUE; |
|
| 840 | + if (checkdnsrr ( $dom , 'NS' )) { |
|
| 841 | + return TRUE; |
|
| 842 | + } |
|
| 843 | + if (checkdnsrr ( $dom , 'A' )) { |
|
| 844 | + return TRUE; |
|
| 845 | + } |
|
| 797 | 846 | } |
| 798 | 847 | return FALSE; |
| 799 | 848 | } |
@@ -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\/app\/(?<splunkapp>[\w\.\-]+)\/\@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 */ |
@@ -16,11 +16,11 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | /************** Conf *******************/ |
| 18 | 18 | $base = '/var/www/html/RBL'; |
| 19 | -require_once($base . '/config.php'); |
|
| 19 | +require_once($base.'/config.php'); |
|
| 20 | 20 | |
| 21 | 21 | /* Syslog basic */ |
| 22 | -$tag .= 'SplunkLister'; |
|
| 23 | -$user = 'Splunk'; |
|
| 22 | +$tag .= 'SplunkLister'; |
|
| 23 | +$user = 'Splunk'; |
|
| 24 | 24 | |
| 25 | 25 | openlog($tag, LOG_PID, $fac); |
| 26 | 26 | |
@@ -28,43 +28,43 @@ discard block |
||
| 28 | 28 | if (!isset($_GET['conf'])) { |
| 29 | 29 | syslog(LOG_ALERT, |
| 30 | 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']) ); |
|
| 31 | + $user, $_SERVER['SCRIPT_NAME'])); |
|
| 32 | 32 | exit(254); |
| 33 | 33 | } |
| 34 | 34 | $fileconf = $_GET['conf']; |
| 35 | -if ( !file_exists(dirname(__FILE__) . '/../' . $fileconf) ) { |
|
| 35 | +if (!file_exists(dirname(__FILE__).'/../'.$fileconf)) { |
|
| 36 | 36 | syslog(LOG_ALERT, |
| 37 | 37 | sprintf('%s: the configuration file <%s> doesn\'t exist.', |
| 38 | - $user, $fileconf )); |
|
| 38 | + $user, $fileconf)); |
|
| 39 | 39 | exit(254); |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | closelog(); |
| 43 | -$conf = parse_ini_file( dirname(__FILE__) . '/../' . $fileconf ); |
|
| 43 | +$conf = parse_ini_file(dirname(__FILE__).'/../'.$fileconf); |
|
| 44 | 44 | |
| 45 | 45 | /* Splunk inherited parameters */ |
| 46 | -$threshold = $conf['threshold']; /* Threshold value on trigger condition; the same which engage the alert */ |
|
| 46 | +$threshold = $conf['threshold']; /* Threshold value on trigger condition; the same which engage the alert */ |
|
| 47 | 47 | |
| 48 | 48 | /* Blacklist name */ |
| 49 | 49 | $typedesc = $conf['typedesc']; |
| 50 | 50 | |
| 51 | 51 | /* How long to list's parameters */ |
| 52 | -$unit = $conf['unit']; /* MySQL language ;) */ |
|
| 52 | +$unit = $conf['unit']; /* MySQL language ;) */ |
|
| 53 | 53 | |
| 54 | 54 | /* Syslog extended info */ |
| 55 | -$tag .= $conf['tag']; |
|
| 55 | +$tag .= $conf['tag']; |
|
| 56 | 56 | |
| 57 | 57 | /* Splunk password of alert owner*/ |
| 58 | 58 | $splpwd = $conf['splunkpassword']; |
| 59 | 59 | /************** End of conf *************************/ |
| 60 | 60 | |
| 61 | 61 | openlog($tag, LOG_PID, $fac); |
| 62 | -require_once($base . '/function.php'); |
|
| 62 | +require_once($base.'/function.php'); |
|
| 63 | 63 | |
| 64 | 64 | |
| 65 | 65 | /* check you select a blocklist */ |
| 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."); |
|
| 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 | 68 | exit (254); |
| 69 | 69 | } |
| 70 | 70 | |
@@ -96,14 +96,14 @@ discard block |
||
| 96 | 96 | $webhook['results_link'], $out, PREG_PATTERN_ORDER) === FALSE) { |
| 97 | 97 | syslog(LOG_ALERT, |
| 98 | 98 | sprintf('%s: unexpected error: can\'t parse the results link returned by webhook (<%s>).', |
| 99 | - $user, $webhook['results_link']) ); |
|
| 99 | + $user, $webhook['results_link'])); |
|
| 100 | 100 | return 255; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | -if ( $webhook['app'] != $out['splunkapp'][0] ) { |
|
| 103 | +if ($webhook['app'] != $out['splunkapp'][0]) { |
|
| 104 | 104 | syslog(LOG_ALERT, |
| 105 | 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] ) ); |
|
| 106 | + $user, $webhook['app'], $out['splunkapp'][0])); |
|
| 107 | 107 | return 255; |
| 108 | 108 | } |
| 109 | 109 | |
@@ -135,13 +135,13 @@ discard block |
||
| 135 | 135 | |
| 136 | 136 | $tolist = array(); |
| 137 | 137 | |
| 138 | -$nr = count ($results); |
|
| 139 | -for ($i=1; $i<$nr; $i++) { /* We skip first header line (i=0) */ |
|
| 138 | +$nr = count($results); |
|
| 139 | +for ($i = 1; $i<$nr; $i++) { /* We skip first header line (i=0) */ |
|
| 140 | 140 | $data = str_getcsv($results[$i], ','); |
| 141 | 141 | $thisVal = $data[1]; |
| 142 | 142 | unset($data[1]); |
| 143 | 143 | $data = array_values($data); |
| 144 | - if ( !in_array($thisVal,array_keys($tolist)) ) |
|
| 144 | + if (!in_array($thisVal, array_keys($tolist))) |
|
| 145 | 145 | $tolist["$thisVal"] = $data; |
| 146 | 146 | else if ($data[3]>$tolist[$thisVal][3]) |
| 147 | 147 | $tolist["$thisVal"] = $data; |
@@ -150,42 +150,42 @@ discard block |
||
| 150 | 150 | /* Make MYSQL connection */ |
| 151 | 151 | |
| 152 | 152 | $mysqli = myConnect($host, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user); |
| 153 | -if ( $mysqli === FALSE ) |
|
| 153 | +if ($mysqli === FALSE) |
|
| 154 | 154 | exit (254); |
| 155 | 155 | |
| 156 | -foreach ( array_keys($tolist) as $value) { |
|
| 156 | +foreach (array_keys($tolist) as $value) { |
|
| 157 | 157 | $quantity = $conf['quantity']; |
| 158 | 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); |
|
| 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 | 162 | /* Send a email to domain admin if you list an email */ |
| 163 | - if ( ( $tables["$typedesc"]['field'] == 'email' ) OR ( $tables["$typedesc"]['field'] == 'username' ) ) { |
|
| 163 | + if (($tables["$typedesc"]['field'] == 'email') OR ($tables["$typedesc"]['field'] == 'username')) { |
|
| 164 | 164 | /* Sometime uid are in the form of <user>@<domain> ... */ |
| 165 | - if ( strpos($value, '@') !== FALSE ) { |
|
| 165 | + if (strpos($value, '@') !== FALSE) { |
|
| 166 | 166 | $domain = substr(strrchr($value, '@'), 1); |
| 167 | - if ( strpos($domain, '@') === FALSE ) { |
|
| 168 | - $recip = emailToNotify($domainNotify_file,$domain); |
|
| 167 | + if (strpos($domain, '@') === FALSE) { |
|
| 168 | + $recip = emailToNotify($domainNotify_file, $domain); |
|
| 169 | 169 | $subject = sprintf('%s <%s> is now blocked because exceedes limits on outgoing emails', |
| 170 | 170 | $tables["$typedesc"]['field'], $value); |
| 171 | 171 | if (!empty($recip)) |
| 172 | - if ( sendEmailWarn($tplfile,'[email protected]',$recip, |
|
| 173 | - $subject,$value,"$quantity $unit",$reason) ) |
|
| 172 | + if (sendEmailWarn($tplfile, '[email protected]', $recip, |
|
| 173 | + $subject, $value, "$quantity $unit", $reason)) |
|
| 174 | 174 | syslog(LOG_INFO, "$user: \"$recip\" was notified about the \"$value\" abuse."); |
| 175 | 175 | } |
| 176 | - else syslog(LOG_ERR,"$user: <$domain> contains the '@' char. Notification cannot be sent."); |
|
| 176 | + else syslog(LOG_ERR, "$user: <$domain> contains the '@' char. Notification cannot be sent."); |
|
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | } |
| 181 | 181 | else { |
| 182 | 182 | $reason .= " But it has NOT been listed because it doesn't apply to the trigger condition."; |
| 183 | - syslog (LOG_INFO, "$user: ".$reason); |
|
| 183 | + syslog(LOG_INFO, "$user: ".$reason); |
|
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /* Close connection */ |
| 188 | -syslog (LOG_INFO, "$user: ".'Successfully end of session.'); |
|
| 188 | +syslog(LOG_INFO, "$user: ".'Successfully end of session.'); |
|
| 189 | 189 | $mysqli->close(); |
| 190 | 190 | closelog(); |
| 191 | 191 | |
@@ -141,17 +141,19 @@ discard block |
||
| 141 | 141 | $thisVal = $data[1]; |
| 142 | 142 | unset($data[1]); |
| 143 | 143 | $data = array_values($data); |
| 144 | - if ( !in_array($thisVal,array_keys($tolist)) ) |
|
| 145 | - $tolist["$thisVal"] = $data; |
|
| 146 | - else if ($data[3]>$tolist[$thisVal][3]) |
|
| 147 | - $tolist["$thisVal"] = $data; |
|
| 148 | -} |
|
| 144 | + if ( !in_array($thisVal,array_keys($tolist)) ) { |
|
| 145 | + $tolist["$thisVal"] = $data; |
|
| 146 | + } else if ($data[3]>$tolist[$thisVal][3]) { |
|
| 147 | + $tolist["$thisVal"] = $data; |
|
| 148 | + } |
|
| 149 | + } |
|
| 149 | 150 | |
| 150 | 151 | /* Make MYSQL connection */ |
| 151 | 152 | |
| 152 | 153 | $mysqli = myConnect($host, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user); |
| 153 | -if ( $mysqli === FALSE ) |
|
| 154 | +if ( $mysqli === FALSE ) { |
|
| 154 | 155 | exit (254); |
| 156 | +} |
|
| 155 | 157 | |
| 156 | 158 | foreach ( array_keys($tolist) as $value) { |
| 157 | 159 | $quantity = $conf['quantity']; |
@@ -168,17 +170,18 @@ discard block |
||
| 168 | 170 | $recip = emailToNotify($domainNotify_file,$domain); |
| 169 | 171 | $subject = sprintf('%s <%s> is now blocked because exceedes limits on outgoing emails', |
| 170 | 172 | $tables["$typedesc"]['field'], $value); |
| 171 | - if (!empty($recip)) |
|
| 172 | - if ( sendEmailWarn($tplfile,'[email protected]',$recip, |
|
| 173 | + if (!empty($recip)) { |
|
| 174 | + if ( sendEmailWarn($tplfile,'[email protected]',$recip, |
|
| 173 | 175 | $subject,$value,"$quantity $unit",$reason) ) |
| 174 | 176 | syslog(LOG_INFO, "$user: \"$recip\" was notified about the \"$value\" abuse."); |
| 177 | + } |
|
| 178 | + } else { |
|
| 179 | + syslog(LOG_ERR,"$user: <$domain> contains the '@' char. Notification cannot be sent."); |
|
| 175 | 180 | } |
| 176 | - else syslog(LOG_ERR,"$user: <$domain> contains the '@' char. Notification cannot be sent."); |
|
| 177 | 181 | } |
| 178 | 182 | } |
| 179 | 183 | } |
| 180 | - } |
|
| 181 | - else { |
|
| 184 | + } else { |
|
| 182 | 185 | $reason .= " But it has NOT been listed because it doesn't apply to the trigger condition."; |
| 183 | 186 | syslog (LOG_INFO, "$user: ".$reason); |
| 184 | 187 | } |
@@ -14,11 +14,11 @@ discard block |
||
| 14 | 14 | require_once('function.php'); |
| 15 | 15 | |
| 16 | 16 | checkSSL(); |
| 17 | -if ( $require_auth ) |
|
| 18 | - if ( username() == 'unknown' ) exit ("<p>You MUST configure your server to use authentication.</p>"); |
|
| 17 | +if ($require_auth) |
|
| 18 | + if (username() == 'unknown') exit ("<p>You MUST configure your server to use authentication.</p>"); |
|
| 19 | 19 | |
| 20 | 20 | |
| 21 | -if ( $imapListActive ) |
|
| 21 | +if ($imapListActive) |
|
| 22 | 22 | print ' <p style="text-align: right"><a href="/spamreport" target="_new">SPAM Learn Observer</a></p>'; |
| 23 | 23 | |
| 24 | 24 | print <<<END |
@@ -27,10 +27,10 @@ discard block |
||
| 27 | 27 | END; |
| 28 | 28 | |
| 29 | 29 | |
| 30 | -$option=NULL; |
|
| 30 | +$option = NULL; |
|
| 31 | 31 | $desc = array_keys($tables); |
| 32 | 32 | foreach ($desc as $description) { |
| 33 | - $disabled = $tables["$description"]['active']==TRUE ? '' : ' disabled'; |
|
| 33 | + $disabled = $tables["$description"]['active'] == TRUE ? '' : ' disabled'; |
|
| 34 | 34 | $option .= '<option value="'.$description."\"$disabled>$description</option>"; |
| 35 | 35 | } |
| 36 | 36 | |
@@ -14,12 +14,14 @@ |
||
| 14 | 14 | require_once('function.php'); |
| 15 | 15 | |
| 16 | 16 | checkSSL(); |
| 17 | -if ( $require_auth ) |
|
| 17 | +if ( $require_auth ) { |
|
| 18 | 18 | if ( username() == 'unknown' ) exit ("<p>You MUST configure your server to use authentication.</p>"); |
| 19 | +} |
|
| 19 | 20 | |
| 20 | 21 | |
| 21 | -if ( $imapListActive ) |
|
| 22 | +if ( $imapListActive ) { |
|
| 22 | 23 | print ' <p style="text-align: right"><a href="/spamreport" target="_new">SPAM Learn Observer</a></p>'; |
| 24 | +} |
|
| 23 | 25 | |
| 24 | 26 | print <<<END |
| 25 | 27 | <form name="check" action="result.php" onSubmit="xmlhttpPost('result.php', 'check', 'Risultato', '<img src=\'/include/pleasewait.gif\'>'); return false;" enctype="text/plain" method="post" target="_self"> |
@@ -27,32 +27,32 @@ |
||
| 27 | 27 | |
| 28 | 28 | |
| 29 | 29 | $data = array( |
| 30 | - 'date' => NULL, |
|
| 31 | - 'from' => NULL, |
|
| 32 | - 'messageid' => NULL, |
|
| 33 | - 'dmarc' => array( |
|
| 34 | - 'result' => NULL, |
|
| 35 | - 'dom' => NULL |
|
| 36 | - ), |
|
| 37 | - 'spf' => array( |
|
| 38 | - 'result' => NULL, |
|
| 39 | - 'dom' => NULL |
|
| 40 | - ), |
|
| 41 | - 'dkim' => array( |
|
| 42 | - 'result' => NULL, |
|
| 43 | - 'dom' => NULL |
|
| 44 | - ), |
|
| 45 | - 'spam' => array( |
|
| 46 | - 'status' => NULL, |
|
| 47 | - 'score' => NULL, |
|
| 48 | - 'th' => NULL, |
|
| 49 | - ), |
|
| 50 | - 'dspam' => array( |
|
| 51 | - 'type' => NULL, |
|
| 52 | - 'level' => NULL, |
|
| 53 | - 'learn' => NULL |
|
| 54 | - ), |
|
| 55 | - 'warn' => NULL |
|
| 30 | + 'date' => NULL, |
|
| 31 | + 'from' => NULL, |
|
| 32 | + 'messageid' => NULL, |
|
| 33 | + 'dmarc' => array( |
|
| 34 | + 'result' => NULL, |
|
| 35 | + 'dom' => NULL |
|
| 36 | + ), |
|
| 37 | + 'spf' => array( |
|
| 38 | + 'result' => NULL, |
|
| 39 | + 'dom' => NULL |
|
| 40 | + ), |
|
| 41 | + 'dkim' => array( |
|
| 42 | + 'result' => NULL, |
|
| 43 | + 'dom' => NULL |
|
| 44 | + ), |
|
| 45 | + 'spam' => array( |
|
| 46 | + 'status' => NULL, |
|
| 47 | + 'score' => NULL, |
|
| 48 | + 'th' => NULL, |
|
| 49 | + ), |
|
| 50 | + 'dspam' => array( |
|
| 51 | + 'type' => NULL, |
|
| 52 | + 'level' => NULL, |
|
| 53 | + 'learn' => NULL |
|
| 54 | + ), |
|
| 55 | + 'warn' => NULL |
|
| 56 | 56 | ); |
| 57 | 57 | |
| 58 | 58 | if (empty($folder)) exit ('<p>No folder found.</p>'); /* This should not occur */ |
@@ -55,10 +55,15 @@ |
||
| 55 | 55 | 'warn' => NULL |
| 56 | 56 | ); |
| 57 | 57 | |
| 58 | -if (empty($folder)) exit ('<p>No folder found.</p>'); /* This should not occur */ |
|
| 58 | +if (empty($folder)) { |
|
| 59 | + exit ('<p>No folder found.</p>'); |
|
| 60 | +} |
|
| 61 | +/* This should not occur */ |
|
| 59 | 62 | $confimap['user'] = $username; |
| 60 | 63 | $headers = imapFind($confimap, $account, $folder); |
| 61 | -if (empty($headers)) exit (sprintf('<p>No suitable mail found in <b>%s</b> folder.</p>', htmlentities("<$folder>"))); |
|
| 64 | +if (empty($headers)) { |
|
| 65 | + exit (sprintf('<p>No suitable mail found in <b>%s</b> folder.</p>', htmlentities("<$folder>"))); |
|
| 66 | +} |
|
| 62 | 67 | print '<table>'; |
| 63 | 68 | printTableHeader($folder,$data,TRUE,sprintf('Found %d suitable mails.',count($headers))); |
| 64 | 69 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -$path='/var/www/html/RBL/'; |
|
| 2 | +$path = '/var/www/html/RBL/'; |
|
| 3 | 3 | include_once($path.'config.php'); |
| 4 | 4 | require_once($path.'function.php'); |
| 5 | 5 | |
@@ -14,14 +14,14 @@ discard block |
||
| 14 | 14 | $tag .= $conf['syslog']['tag']; |
| 15 | 15 | openlog($tag, LOG_PID, $fac); |
| 16 | 16 | |
| 17 | -if ( $confimap['learn']=='dspamc' ) { |
|
| 17 | +if ($confimap['learn'] == 'dspamc') { |
|
| 18 | 18 | $cmd = escapeshellcmd('which dspamc'); |
| 19 | 19 | $cmd = escapeshellcmd('which ls'); |
| 20 | - exec ( $cmd, $out, $ret ); |
|
| 20 | + exec($cmd, $out, $ret); |
|
| 21 | 21 | if ($ret != 0) { |
| 22 | 22 | $err = 'No DSPAM Client found on your system. Please, force your sysadmin to install "dspamc".'; |
| 23 | 23 | syslog(LOG_ERR, $username.': Error: '.$err); |
| 24 | - exit (sprintf('<p>%s</p>',htmlentities($err))); |
|
| 24 | + exit (sprintf('<p>%s</p>', htmlentities($err))); |
|
| 25 | 25 | } |
| 26 | 26 | } |
| 27 | 27 | |
@@ -60,10 +60,10 @@ discard block |
||
| 60 | 60 | $headers = imapFind($confimap, $account, $folder); |
| 61 | 61 | if (empty($headers)) exit (sprintf('<p>No suitable mail found in <b>%s</b> folder.</p>', htmlentities("<$folder>"))); |
| 62 | 62 | print '<table>'; |
| 63 | -printTableHeader($folder,$data,TRUE,sprintf('Found %d suitable mails.',count($headers))); |
|
| 63 | +printTableHeader($folder, $data, TRUE, sprintf('Found %d suitable mails.', count($headers))); |
|
| 64 | 64 | |
| 65 | -foreach ( $headers AS $header ) { |
|
| 66 | - $values = imapInfo($username, $header,$conf['host']['ar'],$confimap['dspamtospamass'],$confimap['learn']); |
|
| 65 | +foreach ($headers AS $header) { |
|
| 66 | + $values = imapInfo($username, $header, $conf['host']['ar'], $confimap['dspamtospamass'], $confimap['learn']); |
|
| 67 | 67 | print '<tr>'; |
| 68 | 68 | printTableRow($values, $confimap['learn']); |
| 69 | 69 | print '</tr>'; |
@@ -16,10 +16,10 @@ |
||
| 16 | 16 | require_once('function.php'); |
| 17 | 17 | |
| 18 | 18 | if ( !isset($version) ) { |
| 19 | - openlog('mailClassifierEmergency', LOG_PID, LOG_LOCAL0); |
|
| 20 | - syslog (LOG_EMERG, sprintf('unknown: I can\'t read the config files. Do you have configured the $path in %s?', __FILE__)); |
|
| 21 | - closelog(); |
|
| 22 | - exit(255); |
|
| 19 | + openlog('mailClassifierEmergency', LOG_PID, LOG_LOCAL0); |
|
| 20 | + syslog (LOG_EMERG, sprintf('unknown: I can\'t read the config files. Do you have configured the $path in %s?', __FILE__)); |
|
| 21 | + closelog(); |
|
| 22 | + exit(255); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | checkSSL(); |
@@ -10,24 +10,24 @@ |
||
| 10 | 10 | <body> |
| 11 | 11 | <h1> Mail Classifier</h1> |
| 12 | 12 | <?php |
| 13 | -$path='/var/www/html/RBL/'; |
|
| 13 | +$path = '/var/www/html/RBL/'; |
|
| 14 | 14 | require_once($path.'config.php'); |
| 15 | 15 | require_once($path.'function.php'); |
| 16 | 16 | require_once('function.php'); |
| 17 | 17 | |
| 18 | -if ( !isset($version) ) { |
|
| 18 | +if (!isset($version)) { |
|
| 19 | 19 | openlog('mailClassifierEmergency', LOG_PID, LOG_LOCAL0); |
| 20 | - syslog (LOG_EMERG, sprintf('unknown: I can\'t read the config files. Do you have configured the $path in %s?', __FILE__)); |
|
| 20 | + syslog(LOG_EMERG, sprintf('unknown: I can\'t read the config files. Do you have configured the $path in %s?', __FILE__)); |
|
| 21 | 21 | closelog(); |
| 22 | 22 | exit(255); |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | checkSSL(); |
| 26 | 26 | $user = username(); |
| 27 | -$isAdmin = in_array($user,array_keys($admins)); |
|
| 27 | +$isAdmin = in_array($user, array_keys($admins)); |
|
| 28 | 28 | $canChange = ($isAdmin) ? '' : 'readonly'; |
| 29 | -if ( $require_auth ) |
|
| 30 | - if ( $user == 'unknown' ) exit ("<p>You MUST configure your server to use authentication.</p>"); |
|
| 29 | +if ($require_auth) |
|
| 30 | + if ($user == 'unknown') exit ("<p>You MUST configure your server to use authentication.</p>"); |
|
| 31 | 31 | |
| 32 | 32 | |
| 33 | 33 | print <<<END |
@@ -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 |
@@ -15,7 +15,7 @@ |
||
| 15 | 15 | if (is_array($folders)) { |
| 16 | 16 | print '<option value="" selected disabled>Choose a folder</option>'; |
| 17 | 17 | foreach ( $folders as $folder ) |
| 18 | - printf('<option value="%s">%s</option>', |
|
| 18 | + printf('<option value="%s">%s</option>', |
|
| 19 | 19 | $folder, |
| 20 | 20 | htmlspecialchars(mb_convert_encoding($folder, "UTF-8", "UTF7-IMAP"))); |
| 21 | 21 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <select name="folder" style="width:215px" onChange="xmlhttpPost('result.php', 'Classify', 'Result', '<img src=\'/include/pleasewait.gif\'>', true); return false;"> |
| 2 | 2 | <?php |
| 3 | -$path='/var/www/html/RBL/'; |
|
| 3 | +$path = '/var/www/html/RBL/'; |
|
| 4 | 4 | require_once($path.'function.php'); |
| 5 | 5 | require_once($path.'config.php'); |
| 6 | 6 | require_once('function.php'); |
@@ -11,10 +11,10 @@ discard block |
||
| 11 | 11 | openlog($tag, LOG_PID, $fac); |
| 12 | 12 | |
| 13 | 13 | $conf['imap']['user'] = username(); |
| 14 | -$folders=imapFolder($conf['imap'], $_POST['username']); |
|
| 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 ) |
|
| 17 | + foreach ($folders as $folder) |
|
| 18 | 18 | printf('<option value="%s">%s</option>', |
| 19 | 19 | $folder, |
| 20 | 20 | htmlspecialchars(mb_convert_encoding($folder, "UTF-8", "UTF7-IMAP"))); |
@@ -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> |
@@ -56,6 +56,10 @@ discard block |
||
| 56 | 56 | return $head; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | +/** |
|
| 60 | + * @param null|string $prob |
|
| 61 | + * @param null|string $conf |
|
| 62 | + */ |
|
| 59 | 63 | function dspamLevel($prob, $conf) { |
| 60 | 64 | /* Calculate DSPAM Level as the Spamassassin Plugin */ |
| 61 | 65 | if (is_null($prob) or is_null($conf)) return '-'; |
@@ -63,6 +67,9 @@ discard block |
||
| 63 | 67 | return round(($t_prob + ($conf*100)) / 2); |
| 64 | 68 | } |
| 65 | 69 | |
| 70 | +/** |
|
| 71 | + * @param string $classSpam |
|
| 72 | + */ |
|
| 66 | 73 | function dspamType($classSpam) { |
| 67 | 74 | switch($classSpam) { |
| 68 | 75 | case 'HAM': |
@@ -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; |
@@ -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)'; |
@@ -2,56 +2,56 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | function imapFolder($cf, $username) { |
| 4 | 4 | $return = array(); |
| 5 | - $open='{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}'; |
|
| 5 | + $open = '{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}'; |
|
| 6 | 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); |
|
| 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.'>...'); |
|
| 11 | + syslog(LOG_INFO, $cf['user'].': Successfully connected to <'.$cf['mailhost'].'>; Listing folders of account <'.$username.'>...'); |
|
| 12 | 12 | //get all folder |
| 13 | 13 | $list = imap_list($m_mail, $open, "*"); |
| 14 | 14 | imap_close($m_mail); |
| 15 | 15 | if (is_array($list)) |
| 16 | 16 | foreach ($list as $mbox) |
| 17 | - $return[] = explode($open,$mbox,2)[1]; |
|
| 17 | + $return[] = explode($open, $mbox, 2)[1]; |
|
| 18 | 18 | else |
| 19 | - syslog (LOG_INFO,$cf['user'] . ': imap_list failed: ' . imap_last_error() ); |
|
| 19 | + syslog(LOG_INFO, $cf['user'].': imap_list failed: '.imap_last_error()); |
|
| 20 | 20 | return $return; |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | -function imapFind ($cf, $username, $folder) { |
|
| 24 | - $head=array(); |
|
| 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()); |
|
| 27 | - if ( !$m_mail ) exit(254); |
|
| 23 | +function imapFind($cf, $username, $folder) { |
|
| 24 | + $head = array(); |
|
| 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()); |
|
| 27 | + if (!$m_mail) exit(254); |
|
| 28 | 28 | |
| 29 | 29 | |
| 30 | - syslog (LOG_INFO,$cf['user'].': Successfully connected to <'.$cf['mailhost'].">; Reading <$folder> messages of last ".$cf['oldestday'].' days on account <'.$username.'>...'); |
|
| 30 | + syslog(LOG_INFO, $cf['user'].': Successfully connected to <'.$cf['mailhost'].">; Reading <$folder> messages of last ".$cf['oldestday'].' days on account <'.$username.'>...'); |
|
| 31 | 31 | //get all messages |
| 32 | - $dateTh = date ( "d-M-Y", strToTime ( '-'.$cf['oldestday'].' days' ) ); |
|
| 33 | - $m_search=imap_search ($m_mail, "SINCE \"$dateTh\" TEXT \"Authentication-Results: \"" ); |
|
| 32 | + $dateTh = date("d-M-Y", strToTime('-'.$cf['oldestday'].' days')); |
|
| 33 | + $m_search = imap_search($m_mail, "SINCE \"$dateTh\" TEXT \"Authentication-Results: \""); |
|
| 34 | 34 | |
| 35 | 35 | |
| 36 | 36 | // Order results starting from newest message |
| 37 | - if ( empty($m_search) ) { |
|
| 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"); |
|
| 45 | - imap_close( $m_mail ); |
|
| 37 | + if (empty($m_search)) { |
|
| 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"); |
|
| 45 | + imap_close($m_mail); |
|
| 46 | 46 | return FALSE; |
| 47 | 47 | } |
| 48 | - $nmes = count ($m_search); |
|
| 49 | - syslog (LOG_INFO,$cf['user'].": Found $nmes mail in <$folder> folder."); |
|
| 48 | + $nmes = count($m_search); |
|
| 49 | + syslog(LOG_INFO, $cf['user'].": Found $nmes mail in <$folder> folder."); |
|
| 50 | 50 | if ($nmes>0) rsort($m_search); |
| 51 | 51 | |
| 52 | 52 | // loop for each message |
| 53 | 53 | foreach ($m_search as $onem) |
| 54 | - $head[] = imap_fetchheader($m_mail, $onem ); |
|
| 54 | + $head[] = imap_fetchheader($m_mail, $onem); |
|
| 55 | 55 | imap_close($m_mail); |
| 56 | 56 | return $head; |
| 57 | 57 | } |
@@ -59,12 +59,12 @@ discard block |
||
| 59 | 59 | function dspamLevel($prob, $conf) { |
| 60 | 60 | /* Calculate DSPAM Level as the Spamassassin Plugin */ |
| 61 | 61 | if (is_null($prob) or is_null($conf)) return '-'; |
| 62 | - $t_prob = abs((($prob - 0.5) * 2) * 100); |
|
| 63 | - return round(($t_prob + ($conf*100)) / 2); |
|
| 62 | + $t_prob = abs((($prob-0.5) * 2) * 100); |
|
| 63 | + return round(($t_prob+($conf * 100)) / 2); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | function dspamType($classSpam) { |
| 67 | - switch($classSpam) { |
|
| 67 | + switch ($classSpam) { |
|
| 68 | 68 | case 'HAM': |
| 69 | 69 | return 'Innocent'; |
| 70 | 70 | case 'SPAM': |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | -function imapInfo($user,$header,$ARhosts,$dpl=false, $learn=false) { |
|
| 78 | +function imapInfo($user, $header, $ARhosts, $dpl = false, $learn = false) { |
|
| 79 | 79 | /* Get relevant Info from header's mail */ |
| 80 | 80 | /* Each line must end with /r/n */ |
| 81 | 81 | |
@@ -109,118 +109,118 @@ discard block |
||
| 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) ) { |
|
| 113 | - $k=0; |
|
| 114 | - for ($i = count($received[0])-1;$i>=0;$i--) { |
|
| 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 | + $k = 0; |
|
| 114 | + for ($i = count($received[0])-1; $i>=0; $i--) { |
|
| 115 | 115 | foreach ($ARhosts as $mx) { |
| 116 | 116 | if ($mx == $received['host'][$i]) { |
| 117 | 117 | /* This is a trusted AR result */ |
| 118 | - $result['dmarc']['result']=$received['dmarc'][$i]; |
|
| 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 | - $received=NULL; |
|
| 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) ) { |
|
| 129 | - $k=0; |
|
| 130 | - for ($i = count($received[0])-1;$i>=0;$i--) { |
|
| 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 | + $k = 0; |
|
| 130 | + for ($i = count($received[0])-1; $i>=0; $i--) { |
|
| 131 | 131 | foreach ($ARhosts as $mx) { |
| 132 | 132 | if ($mx == $received['host'][$i]) { |
| 133 | 133 | /* This is a trusted AR result */ |
| 134 | - $result['spf']['result']=$received['spf'][$i]; |
|
| 134 | + $result['spf']['result'] = $received['spf'][$i]; |
|
| 135 | 135 | $result['spf']['dom'] = $received['SPFfrom'][$i]; |
| 136 | 136 | $k++; |
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | } |
| 140 | 140 | } |
| 141 | - $received=NULL; |
|
| 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 | - $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) ) { |
|
| 146 | - for ($i = count($received[0])-1;$i>=0;$i--) { |
|
| 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)) { |
|
| 146 | + for ($i = count($received[0])-1; $i>=0; $i--) { |
|
| 147 | 147 | foreach ($ARhosts as $mx) { |
| 148 | 148 | if ($mx == $received['host'][$i]) { |
| 149 | 149 | /* This is a trusted AR result */ |
| 150 | - $result['dkim']['result']=$received['dkim'][$i]; |
|
| 150 | + $result['dkim']['result'] = $received['dkim'][$i]; |
|
| 151 | 151 | $result['dkim']['dom'] = $received['DKIMdom'][$i]; |
| 152 | 152 | $k++; |
| 153 | 153 | } |
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | } |
| 157 | - $received=NULL; |
|
| 157 | + $received = NULL; |
|
| 158 | 158 | if ($k>1) $result['warn'][] = 'The trusted DKIM AR Headers are present more than once. Something wrong.'; |
| 159 | 159 | |
| 160 | 160 | if ($dpl) { /* Use Spamassassin Plugin */ |
| 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 | - $result['spam']['status']=$received['spamstatus'][0]; |
|
| 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 | + $result['spam']['status'] = $received['spamstatus'][0]; |
|
| 163 | 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 | - $result['dspam']['level'] =$received['dlevel'][0]; |
|
| 166 | + $result['dspam']['level'] = $received['dlevel'][0]; |
|
| 167 | 167 | } |
| 168 | 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 | - 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]; |
|
| 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 | 173 | $result['spam']['score'] = $received['score'][0]; |
| 174 | 174 | $result['spam']['th'] = $received['th'][0]; |
| 175 | 175 | if (count($received[0])>1) |
| 176 | - $result['warn'][]= 'The Spamassassin Headers are present more than once. I consider only the last one.'; |
|
| 176 | + $result['warn'][] = 'The Spamassassin Headers are present more than once. I consider only the last one.'; |
|
| 177 | 177 | } |
| 178 | - if ( preg_match ('/\r\nX\-DSPAM\-Result:\s(?P<result>.*)\r\n/',$header,$received) != 1) |
|
| 178 | + if (preg_match('/\r\nX\-DSPAM\-Result:\s(?P<result>.*)\r\n/', $header, $received) != 1) |
|
| 179 | 179 | $result['warn'] = 'DSPAM Result invalid, not present or present more than once.'; |
| 180 | 180 | else |
| 181 | - $result['dspam']['type']=$received['result']; |
|
| 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) |
|
| 184 | + if (preg_match('/\r\nX\-DSPAM\-Probability:\s(?P<prob>.*)\r\n/', $header, $received) != 1) |
|
| 185 | 185 | $result['warn'][] = 'DSPAM Probability invalid, not present or present more than once.'; |
| 186 | 186 | else |
| 187 | 187 | $prob = $received['prob']; |
| 188 | - if ( preg_match ('/\r\nX\-DSPAM\-Confidence:\s(?P<conf>.*)\r\n/',$header,$received) != 1) |
|
| 188 | + if (preg_match('/\r\nX\-DSPAM\-Confidence:\s(?P<conf>.*)\r\n/', $header, $received) != 1) |
|
| 189 | 189 | $result['warn'][] = 'DSPAM Confidence invalid, not present or present more than once.'; |
| 190 | 190 | else |
| 191 | 191 | $conf = $received['conf']; |
| 192 | - $result['dspam']['level'] = dspamLevel($prob,$conf); |
|
| 192 | + $result['dspam']['level'] = dspamLevel($prob, $conf); |
|
| 193 | 193 | } |
| 194 | - $received=NULL; |
|
| 195 | - if ( preg_match ('/\r\nFrom:\s(?P<from>.*)\r\n/',$header,$received) != 1) |
|
| 194 | + $received = NULL; |
|
| 195 | + if (preg_match('/\r\nFrom:\s(?P<from>.*)\r\n/', $header, $received) != 1) |
|
| 196 | 196 | $result['warn'][] = 'From header invalid or not present'; |
| 197 | 197 | else |
| 198 | 198 | $result['from'] = $received['from']; |
| 199 | 199 | |
| 200 | - if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$received) != 1) |
|
| 200 | + if (preg_match('/\r\nDate:\s(?P<date>.*)\r\n/', $header, $received) != 1) |
|
| 201 | 201 | $result['warn'][] = 'Date header invalid or not present'; |
| 202 | 202 | else |
| 203 | 203 | $result['date'] = $received['date']; |
| 204 | 204 | |
| 205 | - $received=NULL; |
|
| 206 | - if ( preg_match ('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/',$header,$received) != 1) |
|
| 205 | + $received = NULL; |
|
| 206 | + if (preg_match('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/', $header, $received) != 1) |
|
| 207 | 207 | $result['warn'][] = 'Message-ID invalid, not present or present more than once.'; |
| 208 | 208 | else |
| 209 | - $result['messageid']=$received['mid']; |
|
| 209 | + $result['messageid'] = $received['mid']; |
|
| 210 | 210 | |
| 211 | - $received=NULL; |
|
| 211 | + $received = NULL; |
|
| 212 | 212 | |
| 213 | 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 | - $result['dspam']['learn']=$received['sig']; |
|
| 218 | + $result['dspam']['learn'] = $received['sig']; |
|
| 219 | 219 | break; |
| 220 | 220 | case false: |
| 221 | 221 | break; |
| 222 | 222 | default: |
| 223 | - syslog (LOG_INFO,$user.': Error in "learn" imap configuration value. Please, set "dspamc" or "false".'); |
|
| 223 | + syslog(LOG_INFO, $user.': Error in "learn" imap configuration value. Please, set "dspamc" or "false".'); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | return $result; |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | |
| 230 | 230 | |
| 231 | 231 | |
| 232 | -function printTableHeader($title,$content,$footer=FALSE,$fcontent) { |
|
| 232 | +function printTableHeader($title, $content, $footer = FALSE, $fcontent) { |
|
| 233 | 233 | print <<<END |
| 234 | 234 | <caption>$title</caption> |
| 235 | 235 | <thead> |
@@ -237,21 +237,19 @@ discard block |
||
| 237 | 237 | END; |
| 238 | 238 | $kcontent = array_keys($content); |
| 239 | 239 | $cols = count($kcontent); |
| 240 | - for ($i=0; $i<$cols; $i++) { |
|
| 240 | + for ($i = 0; $i<$cols; $i++) { |
|
| 241 | 241 | $key = $kcontent[$i]; |
| 242 | - printf ('<th colspan="%d" rowspan="%d">%s</th>', |
|
| 243 | - !is_array($content[$key]) ?: |
|
| 244 | - count(array_keys($content[$key])) ?: '1', |
|
| 245 | - !is_array($content[$key]) ?: |
|
| 246 | - empty(array_keys($content[$key])) ? '2' : '1', |
|
| 242 | + printf('<th colspan="%d" rowspan="%d">%s</th>', |
|
| 243 | + !is_array($content[$key]) ?: count(array_keys($content[$key])) ?: '1', |
|
| 244 | + !is_array($content[$key]) ?: empty(array_keys($content[$key])) ? '2' : '1', |
|
| 247 | 245 | $kcontent[$i]); |
| 248 | 246 | } |
| 249 | 247 | print '</tr><tr>'; |
| 250 | - for ($i=0; $i<$cols; $i++) { |
|
| 248 | + for ($i = 0; $i<$cols; $i++) { |
|
| 251 | 249 | $key = $kcontent[$i]; |
| 252 | - if (is_array($content[$key])&&($hs = array_keys($content[$key]))) { |
|
| 250 | + if (is_array($content[$key]) && ($hs = array_keys($content[$key]))) { |
|
| 253 | 251 | foreach ($hs as $h) |
| 254 | - printf('<th>%s</th>',$h); |
|
| 252 | + printf('<th>%s</th>', $h); |
|
| 255 | 253 | } |
| 256 | 254 | } |
| 257 | 255 | |
@@ -267,7 +265,7 @@ discard block |
||
| 267 | 265 | |
| 268 | 266 | function formatVal($val, $learn) { |
| 269 | 267 | foreach (array_keys($val) as $key) { |
| 270 | - if (is_array($val["$key"]) and ($key!='warn')) |
|
| 268 | + if (is_array($val["$key"]) and ($key != 'warn')) |
|
| 271 | 269 | $val["$key"] = formatVal($val["$key"], $learn); |
| 272 | 270 | else { |
| 273 | 271 | switch ($key) { |
@@ -275,7 +273,7 @@ discard block |
||
| 275 | 273 | if (empty($val["$key"])) |
| 276 | 274 | $val["$key"] = '-'; |
| 277 | 275 | else |
| 278 | - $val["$key"] = sprintf('<div title="%s">Y</div>',implode($val["$key"],"\n")); |
|
| 276 | + $val["$key"] = sprintf('<div title="%s">Y</div>', implode($val["$key"], "\n")); |
|
| 279 | 277 | break; |
| 280 | 278 | case 'learn': |
| 281 | 279 | $val["$key"] = formLearn($learn, $val); |
@@ -297,26 +295,26 @@ discard block |
||
| 297 | 295 | $par['class'] = $class; |
| 298 | 296 | $val["$class"] = sprintf('dspamc --user dspam --deliver=summary --class=%s --source=error --signature=%s', |
| 299 | 297 | strtolower($class), $par['learn']); |
| 300 | - if (($class != $par['type'])||($par['level']<99)) |
|
| 298 | + if (($class != $par['type']) || ($par['level']<99)) |
|
| 301 | 299 | $return .= sprintf(file_get_contents('formLearnDSPAM.htm'), |
| 302 | - $class,$class,$val["$class"],base64_encode(json_encode($par)),$class); |
|
| 300 | + $class, $class, $val["$class"], base64_encode(json_encode($par)), $class); |
|
| 303 | 301 | } |
| 304 | 302 | default: |
| 305 | 303 | return $return; |
| 306 | 304 | } |
| 307 | 305 | } |
| 308 | 306 | |
| 309 | -function printTableRow($row, $learn, $init=true) { |
|
| 307 | +function printTableRow($row, $learn, $init = true) { |
|
| 310 | 308 | $color = 'inherit'; |
| 311 | 309 | if ($init) |
| 312 | - $row=formatVal($row,$learn); |
|
| 313 | - foreach( $row as $key => $val) { |
|
| 310 | + $row = formatVal($row, $learn); |
|
| 311 | + foreach ($row as $key => $val) { |
|
| 314 | 312 | if (is_array($val)) |
| 315 | 313 | printTableRow($val, $learn, false); |
| 316 | 314 | else { |
| 317 | 315 | /* DSPAM format */ |
| 318 | 316 | if (isset($row['type'])) |
| 319 | - switch($row['type']) { |
|
| 317 | + switch ($row['type']) { |
|
| 320 | 318 | case 'Innocent': |
| 321 | 319 | case 'HAM': |
| 322 | 320 | $color = 'rgba(0,255,0, %.1f)'; |
@@ -327,7 +325,7 @@ discard block |
||
| 327 | 325 | } |
| 328 | 326 | /* DMARC, DKIM, SPF format */ |
| 329 | 327 | if (isset($row['result'])) |
| 330 | - switch($row['result']) { |
|
| 328 | + switch ($row['result']) { |
|
| 331 | 329 | case 'pass': |
| 332 | 330 | $color = 'rgba(0,255,0, %.1f)'; |
| 333 | 331 | break; |
@@ -336,7 +334,7 @@ discard block |
||
| 336 | 334 | } |
| 337 | 335 | /* Spamassassin format */ |
| 338 | 336 | if (isset($row['status'])) |
| 339 | - switch($row['status']) { |
|
| 337 | + switch ($row['status']) { |
|
| 340 | 338 | case 'No': |
| 341 | 339 | $color = 'rgba(0,255,0, %.1f)'; |
| 342 | 340 | break; |
@@ -344,9 +342,9 @@ discard block |
||
| 344 | 342 | $color = 'rgba(255,0,0,%.1f)'; |
| 345 | 343 | } |
| 346 | 344 | |
| 347 | - $alpha = (is_numeric($val)AND($key=='type')) ? round($val/100,1) : 1.0; |
|
| 345 | + $alpha = (is_numeric($val) AND ($key == 'type')) ? round($val / 100, 1) : 1.0; |
|
| 348 | 346 | $bg = sprintf(" style=\"background-color: $color\"", $alpha); |
| 349 | - printf ('<td class="cellfix"%s>%s</td>',$bg, $val); |
|
| 347 | + printf('<td class="cellfix"%s>%s</td>', $bg, $val); |
|
| 350 | 348 | } |
| 351 | 349 | } |
| 352 | 350 | } |
@@ -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> |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <div id="content"> |
| 2 | 2 | <h3>Log</h3> |
| 3 | 3 | <?php |
| 4 | -$path='/var/www/html/RBL/'; |
|
| 4 | +$path = '/var/www/html/RBL/'; |
|
| 5 | 5 | require_once($path.'function.php'); |
| 6 | 6 | require_once($path.'config.php'); |
| 7 | 7 | $conf = parse_ini_file('imap.conf', TRUE); |
@@ -16,17 +16,17 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | syslog(LOG_INFO, sprintf('%s: Learn as <%s> on signature: <%s>', $username, $par->class, $par->learn)); |
| 18 | 18 | $cmd = escapeshellcmd($_POST['cmd']); |
| 19 | -exec ( $cmd, $out, $ret ); |
|
| 19 | +exec($cmd, $out, $ret); |
|
| 20 | 20 | if ($ret != 0) { |
| 21 | 21 | $err = 'DSPAM Client returns a bad exit state. Sorry, probably the learn was successful, but I don\'t know...'; |
| 22 | 22 | syslog(LOG_ERR, $username.': Learn Error: '.$err); |
| 23 | - exit (sprintf('<p>%s</p>',htmlentities($err))); |
|
| 23 | + exit (sprintf('<p>%s</p>', htmlentities($err))); |
|
| 24 | 24 | } |
| 25 | -syslog(LOG_INFO, sprintf('%s: Learn result: "%s"',$username, $out[0])); |
|
| 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) { |
|
| 25 | +syslog(LOG_INFO, sprintf('%s: Learn result: "%s"', $username, $out[0])); |
|
| 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>', |