Changeset 1231

Show
Ignore:
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
  • trunk/CHANGELOG

    r1230 r1231  
    11ispCP ω 1.0.0 Changelog 
    22~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     3 
     42008-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 
    39 
    4102008-06-17 Benedikt Heintel 
  • trunk/engine/traffic/ispcp-vrl-traff

    r1206 r1231  
    317317        my $smtp_from_domain = undef; 
    318318        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; 
    319323 
    320324    ($rs, $rlog) = gen_log_file($main::cfg{'MAIL_TRAFF_LOG'}, $main::cfg{'TRAFF_LOG_DIR'}, $main::cfg{'LOG_DIR'}); 
     
    341345                if(exists  $main::cfg{'MAIL_LOG_INC_AMAVIS'} && $main::cfg{'MAIL_LOG_INC_AMAVIS'}) { 
    342346                        # 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"; 
    344348                } else { 
    345349                        # 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"; 
    347351                } 
    348352 
     
    362366        } 
    363367 
     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' 
     412SQLEND 
     413                 
     414                ($rs, $rows) = doSQL($query); 
     415                return $rs if ($rs != 0); 
     416                foreach (@$rows) { 
     417                        $forwarders_table{@$_[0]} = (@$_[2] =~ tr/,//)+1; 
     418                } 
     419 
    364420        while (<F>) { 
    365421 
    366422            my $line = $_; 
    367423 
    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); 
    373432 
    374433                                if($smtp_from_domain =~ /(.*)(\.)(.*\.)(.*)$/ && !exists $main::smtp_traffic{$smtp_from_domain}) { 
     
    379438                                } 
    380439 
     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 
    381447                if(exists $main::smtp_traffic{$smtp_from_domain}) { 
    382448                        $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}) { 
    385452                        $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}); 
    386454                } 
    387455 
  • trunk/gui/client/add_mail_acc.php

    r1229 r1231  
    310310                        $mail_forward = implode(',', $mail_accs); 
    311311                } 
    312  
    313                 $mail_type = implode(',', $mail_type); 
     312         
     313                $mail_type = implode(',', $mail_type); 
     314                list($t_, $foo) = split('_', $mail_type, 2); 
    314315 
    315316                $check_acc_query = <<<SQL_QUERY 
     
    324325                                AND 
    325326                                `sub_id` = ? 
     327                                AND 
     328                                LEFT (`mail_type`, LOCATE('_', `mail_type`)-1) = ? 
    326329SQL_QUERY; 
    327330 
    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_)); 
    329332    } 
    330333