#!/usr/bin/perl
use DBI;
use cool_env;
use conf;

#conf read
$conf_name="billing.conf";
$ctest=conf->var_read($conf_name);
$main_table=$ctest->{'mysql_tables.data'};
$traf_log=$ctest->{'mysql_tables.traf'};
$script_log=$ctest->{'mysql_tables.slow'};
$pkt_log=$ctest->{'mysql_tables.ipkt'};
$log_timing=$ctest->{'log.slow'};
$ipt_log_path=$ctest->{'environment.ipt_log_path'};
#db_connect
$dbh = DBI->connect("DBI:mysql:database=$ctest->{'mysql_connect.db_db'};host=$ctest->{'mysql_connect.db_host'}",$ctest->{'mysql_connect.db_user'},$ctest->{'mysql_connect.db_password'});
open(my $ipt_log,$ipt_log_path);
while(<$ipt_log>)
    {
$syn=0;
$ack=0;
$fin=0;
$rst=0;
if(/^.+SYN.+$/) {$syn=1;}
if(/^.+ACK.+$/) {$ack=1;}
if(/^.+FIN.+$/) {$fin=1;}
if(/^.+RST.+$/) {$rst=1;}
    /^(\w+)\s(\d+).+(\d+:\d+:\d+).+IN=(\w+).+OUT=(\w+).+SRC=(\d+\.\d+\.\d+\.\d+).+DST=(\d+\.\d+\.\d+\.\d+).+LEN=(\d+).+TTL=(\d+).+PROTO=(\w+).+SPT=(\d+).+DPT=(\d+).+$/;
    $nip_src2=$dbh->selectrow_array("select inet_aton('$6')");
    $nip_dst2=$dbh->selectrow_array("select inet_aton('$7')");
if(defined $nip_dst2)    {$dbh->do("insert into $pkt_log (time,proto,int_in,nip_src,prt_src,int_out,nip_dst,prt_dst,len,ttl,syn,ack,fin,rst) values ('0000-00-00 $3','$10','$4',$nip_src2,$11,'$5',$nip_dst2,$12,$8,$9,$syn,$ack,$fin,$rst)");}
#    print"insert into $pkt_log (time,proto,int_in,nip_src,prt_src,int_out,nip_dst,prt_dst,len,ttl,syn,ack) values ('0000-00-00 $3','$10','$4',$nip_src2,$11,'$5',$nip_dst2,$12,$8,$9,$syn,$ack)\n";
    }
close($ipt_log);
$dbh->disconnect;
undef $ctest;