Changeset 1231
- Timestamp:
- 06/19/08 14:25:16
(2 months ago)
- Author:
- zothos
- Message:
Fixed #1355 and Mail traffic accounting
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r1230 |
r1231 |
|
| 1 | 1 | ispCP ω 1.0.0 Changelog |
|---|
| 2 | 2 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| | 3 | |
|---|
| | 4 | 2008-06-19 Jochen Manz |
|---|
| | 5 | - GUI: |
|---|
| | 6 | * Fixed #1355: You can't create a mail alias account if the user part already exists as a subdomain mail account |
|---|
| | 7 | - ENGINE: |
|---|
| | 8 | * Fixed Mail traffic accounting |
|---|
| 3 | 9 | |
|---|
| 4 | 10 | 2008-06-17 Benedikt Heintel |
|---|
| r1206 |
r1231 |
|
| 317 | 317 | my $smtp_from_domain = undef; |
|---|
| 318 | 318 | my $smtp_to_domain = undef; |
|---|
| | 319 | my ($query, $rows) = (undef, undef); |
|---|
| | 320 | my $extra_size = undef; |
|---|
| | 321 | my $recipient_address = undef; |
|---|
| | 322 | my %forwarders_table; |
|---|
| 319 | 323 | |
|---|
| 320 | 324 | ($rs, $rlog) = gen_log_file($main::cfg{'MAIL_TRAFF_LOG'}, $main::cfg{'TRAFF_LOG_DIR'}, $main::cfg{'LOG_DIR'}); |
|---|
| … | … | |
| 341 | 345 | if(exists $main::cfg{'MAIL_LOG_INC_AMAVIS'} && $main::cfg{'MAIL_LOG_INC_AMAVIS'}) { |
|---|
| 342 | 346 | # Logs including AMAVIS/SPAMASSASSIN/CLAMAV entries |
|---|
| 343 | | $cmd = "$cat $smtp_delivery_log | $awk '{if ( \$10 != \"?\" && !(\$5 ~ /localhost|127.0.0.1/ && \$6 ~ /localhost|127.0.0.1/)) print substr(\$3, index(\$3, \"@\")+1, length(\$3)),substr(\$4, index(\$4, \"@\")+1, length(\$4)),\$10;}' 1>$smtp_log"; |
|---|
| | 347 | $cmd = "$cat $smtp_delivery_log | $awk '{if ( \$10 != \"?\" && !(\$5 ~ /localhost|127.0.0.1/ && \$6 ~ /localhost|127.0.0.1/)) print \$3,\$4,\$10;}' 1>$smtp_log"; |
|---|
| 344 | 348 | } else { |
|---|
| 345 | 349 | # Logs not including AMAVIS/SPAMASSASSIN/CLAMAV entries |
|---|
| 346 | | $cmd = "$cat $smtp_delivery_log | $awk '{if ( \$10 != \"?\" && \$6 !~ /virtual/ && !(\$5 ~ /localhost|127.0.0.1/ && \$6 ~ /localhost|127.0.0.1/)) print substr(\$3, index(\$3, \"@\")+1, length(\$3)),substr(\$4, index(\$4, \"@\")+1, length(\$4)),\$10;}' 1>$smtp_log"; |
|---|
| | 350 | $cmd = "$cat $smtp_delivery_log | $awk '{if ( \$10 != \"?\" && \$6 !~ /virtual/ && !(\$5 ~ /localhost|127.0.0.1/ && \$6 ~ /localhost|127.0.0.1/)) print \$3,\$4,\$10;}' 1>$smtp_log"; |
|---|
| 347 | 351 | } |
|---|
| 348 | 352 | |
|---|
| … | … | |
| 362 | 366 | } |
|---|
| 363 | 367 | |
|---|
| | 368 | # |
|---|
| | 369 | # Build address forwarding recipients table |
|---|
| | 370 | # |
|---|
| | 371 | my $query = <<"SQLEND"; |
|---|
| | 372 | SELECT |
|---|
| | 373 | concat( mail_acc, '\@', domain_name ) AS mail_from, domain_name, mail_forward |
|---|
| | 374 | FROM |
|---|
| | 375 | mail_users |
|---|
| | 376 | LEFT JOIN |
|---|
| | 377 | domain |
|---|
| | 378 | USING |
|---|
| | 379 | ( domain_id ) |
|---|
| | 380 | WHERE |
|---|
| | 381 | mail_type LIKE '%normal_forward' |
|---|
| | 382 | UNION |
|---|
| | 383 | SELECT |
|---|
| | 384 | concat( mail_acc, '\@', subdomain_name, '.', domain_name ) AS mail_from, domain_name, mail_forward |
|---|
| | 385 | FROM |
|---|
| | 386 | mail_users |
|---|
| | 387 | LEFT JOIN |
|---|
| | 388 | domain |
|---|
| | 389 | USING |
|---|
| | 390 | ( domain_id ) |
|---|
| | 391 | LEFT JOIN |
|---|
| | 392 | subdomain |
|---|
| | 393 | USING |
|---|
| | 394 | ( domain_id ) |
|---|
| | 395 | WHERE |
|---|
| | 396 | mail_type LIKE '%subdom_forward' |
|---|
| | 397 | UNION |
|---|
| | 398 | SELECT |
|---|
| | 399 | concat( mail_acc, '\@', alias_name ) AS mail_from, domain_name, mail_forward |
|---|
| | 400 | FROM |
|---|
| | 401 | mail_users |
|---|
| | 402 | LEFT JOIN |
|---|
| | 403 | domain |
|---|
| | 404 | USING |
|---|
| | 405 | ( domain_id ) |
|---|
| | 406 | LEFT JOIN |
|---|
| | 407 | domain_aliasses |
|---|
| | 408 | USING |
|---|
| | 409 | ( domain_id ) |
|---|
| | 410 | WHERE |
|---|
| | 411 | mail_type LIKE '%alias_forward' |
|---|
| | 412 | SQLEND |
|---|
| | 413 | |
|---|
| | 414 | ($rs, $rows) = doSQL($query); |
|---|
| | 415 | return $rs if ($rs != 0); |
|---|
| | 416 | foreach (@$rows) { |
|---|
| | 417 | $forwarders_table{@$_[0]} = (@$_[2] =~ tr/,//)+1; |
|---|
| | 418 | } |
|---|
| | 419 | |
|---|
| 364 | 420 | while (<F>) { |
|---|
| 365 | 421 | |
|---|
| 366 | 422 | my $line = $_; |
|---|
| 367 | 423 | |
|---|
| 368 | | if ($line =~ /^([^\,]+)\ ([^\,]+)\ (\d+)\n$/) { |
|---|
| 369 | | |
|---|
| 370 | | $smtp_from_domain = $1; |
|---|
| 371 | | $smtp_to_domain = $2; |
|---|
| 372 | | $traffic_size = $3; |
|---|
| | 424 | if ($line =~ /^([^@]+)@([^\,]+)\ ([^@]+)@([^\,]+)\ (\d+)\n$/) { |
|---|
| | 425 | |
|---|
| | 426 | $smtp_from_domain = $2; |
|---|
| | 427 | $smtp_to_domain = $4; |
|---|
| | 428 | $traffic_size = $5; |
|---|
| | 429 | $recipient_address = $3.'@'.$4; |
|---|
| | 430 | chomp($line); |
|---|
| | 431 | push_el(\@main::el, 'collect_mail_traffic()', $line); |
|---|
| 373 | 432 | |
|---|
| 374 | 433 | if($smtp_from_domain =~ /(.*)(\.)(.*\.)(.*)$/ && !exists $main::smtp_traffic{$smtp_from_domain}) { |
|---|
| … | … | |
| 379 | 438 | } |
|---|
| 380 | 439 | |
|---|
| | 440 | # Add extra size to account forwardings |
|---|
| | 441 | if (exists($forwarders_table{$recipient_address})) { |
|---|
| | 442 | $extra_size = $forwarders_table{$recipient_address} * $traffic_size; |
|---|
| | 443 | $main::smtp_traffic{$smtp_to_domain} += $extra_size; |
|---|
| | 444 | push_el(\@main::el, 'collect_mail_traffic()', $recipient_address . ' extra size: ' . $extra_size); |
|---|
| | 445 | } |
|---|
| | 446 | |
|---|
| 381 | 447 | if(exists $main::smtp_traffic{$smtp_from_domain}) { |
|---|
| 382 | 448 | $main::smtp_traffic{$smtp_from_domain} += $traffic_size; |
|---|
| 383 | | } |
|---|
| 384 | | else { |
|---|
| | 449 | push_el(\@main::el, 'collect_mail_traffic()', "Current traffic count for domain " . $smtp_from_domain . ':' . $main::smtp_traffic{$smtp_from_domain}); |
|---|
| | 450 | } |
|---|
| | 451 | elsif(exists $main::smtp_traffic{$smtp_to_domain}) { |
|---|
| 385 | 452 | $main::smtp_traffic{$smtp_to_domain} += $traffic_size; |
|---|
| | 453 | push_el(\@main::el, 'collect_mail_traffic()', "Current traffic count for domain " . $smtp_to_domain . ':' . $main::smtp_traffic{$smtp_to_domain}); |
|---|
| 386 | 454 | } |
|---|
| 387 | 455 | |
|---|
| r1229 |
r1231 |
|
| 310 | 310 | $mail_forward = implode(',', $mail_accs); |
|---|
| 311 | 311 | } |
|---|
| 312 | | |
|---|
| 313 | | $mail_type = implode(',', $mail_type); |
|---|
| | 312 | |
|---|
| | 313 | $mail_type = implode(',', $mail_type); |
|---|
| | 314 | list($t_, $foo) = split('_', $mail_type, 2); |
|---|
| 314 | 315 | |
|---|
| 315 | 316 | $check_acc_query = <<<SQL_QUERY |
|---|
| … | … | |
| 324 | 325 | AND |
|---|
| 325 | 326 | `sub_id` = ? |
|---|
| | 327 | AND |
|---|
| | 328 | LEFT (`mail_type`, LOCATE('_', `mail_type`)-1) = ? |
|---|
| 326 | 329 | SQL_QUERY; |
|---|
| 327 | 330 | |
|---|
| 328 | | $rs = exec_query($sql, $check_acc_query, array($mail_acc, $domain_id, $sub_id)); |
|---|
| | 331 | $rs = exec_query($sql, $check_acc_query, array($mail_acc, $domain_id, $sub_id, $t_)); |
|---|
| 329 | 332 | } |
|---|
| 330 | 333 | |
|---|
|