=head2 Aenderungen

2001-12-20 smurf Hole Dauer aus ISDN-ACCCT, nicht PPP-Debug

=cut

use utf8;
use strict;
use warnings;
use Cf qw($WDESCR);

sub acct_brick {
	my $acct_isdn = do_start(want=>"pers,uucp,kunde",dienst=>"isdn",quelle=>$WDESCR,logdir=>"isdn",do_reverse=>0);
	die "Kein Accounting ISDN" unless ref $acct_isdn;

	my $acct_ip = do_start(want=>"ip,ip_de,kunde",dienst=>"ip",quelle=>"isdn",logdir=>"ip.brick",do_reverse=>1);
	die "Kein Accounting IP" unless ref $acct_ip;

	my $acct_zeit = do_start(want=>"pers,uucp,kunde",dienst=>"zeit",quelle=>"isdn",logdir=>"zeit.brick",do_reverse=>0);
	die "Kein Accounting IP" unless ref $acct_ip;

	my $line;
	my $isdnziel = find_descr("isdn","ip");
	my $zeitziel = find_descr("ziel","lokal");

	my %ifmap;
	while(defined($line = get_line($acct_isdn))) {
		(undef,undef,undef,undef,$line)=split(/\s+/,$line,5)
			unless $line =~ /^(?:PPP|RADIUS|ACCT)\:/;
#		if ($line =~ /^PPP\:\s+(\S+):\s.*\sduration\s(\d+)\ssec/) {
#			my($cust,$volpack)=($1,$2);
#			if($volpack) {
#				$cust = $acct_zeit->{'hash_uucp'}{$cust};
#				$acct_zeit->acct($cust,undef, $zeitziel,undef, 1,$volpack, $line) if $cust;
#			}
#		}
		if($line =~ /^ACCT\:\sISDN\:[^,]+,[^,]+,[^,]+,([^,]+),.*,(?:(\d+) Units)?,[IO],.*,(\S*)$/) {
			my($cust,$volpack,$secs)=($3,$2,$1);
			if(defined $cust and $cust ne "") {
				$cust = $acct_isdn->{'hash_uucp'}{$cust} || $acct_isdn->{'hash_uucp'}{'unknown'};
			}
			$cust=1 unless $cust;

			$acct_isdn->acct($cust,undef, $isdnziel,undef, 1,$volpack,$line) if $volpack;
			$acct_zeit->acct($cust,undef, $zeitziel,undef, 1,$secs, $line);
			next;
		}
		if($line =~ /^RADIUS:/) {
			if($line =~ /^RADIUS\: (\S+)\: created temporary ifc \<(\d+)\>/) {
				$ifmap{$2} = $1;
			} elsif($line =~ /^RADIUS\: (\S+)\: link closed, delete temporary ifc \<(\d+)\>/) {
				delete $ifmap{$2};
			}
			next;
		}
		if($line =~ s/^ACCT\:\s+INET:\s+//) {
			my ($dat,$tim,$n1,$n2,$locadr,$arrow,$remadr,$numpack,$volpack,$numpack2,$volpack2) = split (/\s+/,$line);
			$locadr =~ s/\:(\d+\/)?(\d*)//; my $locif = $2;
			$remadr =~ s/\:(\d+\/)?(\d*)//; my $remif = $2;
			$numpack += $numpack2;
			$volpack += $volpack2;
			my ($cust,$idienst) = $acct_ip->who_ip($locadr);
			if(defined $ifmap{$locif}) {
				my $c2 = $acct_ip->{'hash_uucp'}{$ifmap{$locif}};
				$cust = $c2 if $c2 > 0;
			}
			my ($remagg,$rdienst) = $acct_ip->who_ip($remadr);
			if(defined $ifmap{$remif}) {
				my $r2 = $acct_ip->{'hash_uucp'}{$ifmap{$remif}};
				$remagg = $r2 if $r2 > 0;
			}
			$acct_ip->acct($cust,$idienst, $remagg,$rdienst, $numpack,$volpack, $line) if $cust;
			next;
		}

		# $acct->acct($cust,$idienst, $remagg,$rdienst, $numpack,$volpack);
		next;
	}
	do_end($acct_isdn);
	do_end($acct_ip);
	do_end($acct_zeit);
}
1;
