⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 h323detail2db.pl

📁 使用最广泛的radius的linux的源码
💻 PL
📖 第 1 页 / 共 2 页
字号:
                        $h323_call_type = $_;            };	if (s/h323-remote-address = \"h323-remote-address=//) {			$h323_remote_address = $_;		} elsif (s/h323-remote-address = //) {			$h323_remote_address = $_;	    };	if (s/h323-disconnect-cause = \"h323-disconnect-cause=//) {                        $h323_disconnect_cause = $_;                } elsif (s/h323-disconnect-cause = //) {                        $h323_disconnect_cause = $_;            };	if (s/h323-conf-id = \"h323-conf-id=//) {                        $h323_conf_id = substr($_, 0, -1);                } elsif (s/h323-conf-id = //) {                        $h323_conf_id = $_;            };	if (s/h323-connect-time = \"h323-connect-time=//) {                        $h323_connect_time = substr($_, 0, -1);                } elsif (s/h323-connect-time = //) {                        $h323_connect_time = $_;            };	if (s/h323-disconnect-time = \"h323-disconnect-time=//) {                        $h323_disconnect_time = substr($_, 0, -1);                } elsif (s/h323-disconnect-time = //) {                        $h323_disconnect_time = $_;            };	if (s/h323-setup-time = \"h323-setup-time=//) {                        $h323_setup_time = substr($_, 0, -1);                } elsif (s/h323-setup-time = //) {                        $h323_setup_time = $_;            };        if (s/h323-call-origin = \"h323-call-origin=//) {                        $h323_call_origin = substr($_, 0, -1);                } elsif (s/h323-call-origin = //) {                        $h323_call_origin = $_;            };        if (s/h323-gw-id = \"h323-gw-id=//) {                        $h323_gw_id = substr($_, 0, -1);                } elsif (s/h323-gw-id = //) {                        $h323_gw_id = $_;            };        if (s/h323-voice-quality = \"h323-voice-quality=//) {                        $h323_voice_quality = substr($_, 0, -1);                } elsif (s/h323-voice-quality = //) {                        $h323_voice_quality = $_;            };                # FIXME: ugh, definitely look into using backreference.                # something like s/(\S+)\s*=\s*\1/\1 = / or so	  }	# Remove quotation marks from a bunch of different fields (Stupid Cisco)	$UserName =~ s/\"//g;	$h323_remote_address =~ s/\"//g;	$Called_Station_Id =~ s/\"//g;	$h323_disconnect_cause =~ s/\"//g;	$h323_setup_time =~ s/\"//g;	$h323_connect_time =~ s/\"//g;	$h323_disconnect_time =~ s/\"//g;	$h323_conf_id =~ s/\"//g;	$h323_call_type =~ s/\"//g;	$h323_call_origin =~ s/\"//g;	$h323_voice_quality =~ s/\"//g;	$Cisco_NAS_Port =~ s/\"//g;	# Remove Remove . from the start of time fields (routers that have lost ntp timesync temporarily)	$h323_setup_time =~ s/^\.*//;	$h323_connect_time =~ s/^\.*//;	$h323_disconnect_time =~ s/^\.*//;	# Ignore broken fields from some stupid, non-cisco gateways (They shall remain nameless)	if ($h323_connect_time eq "0") { $h323_connect_time = "" };	if ($h323_disconnect_time eq "0") { $h323_disconnect_time = "" };	# If its a valid record continue onto the database functions	# FIXME: More checks needed here.	if ($h323_call_type) {		$passno++;		#@duplicate_records{$passno} += @record;		if (&procedure_get()) { &procedure_insert; }		else { &db_read; }	} else { if ($verbose > 1) { print "DEBUG: Skipping non-h323 record\n"; } }}sub read_record {	my $keepreading = 1;	@record = ();	while ($keepreading) {		$_ = <DETAIL>;		print "$_" if ($verbose > 1);		if ( /^$/ ) {			$keepreading = 0;	# End of record		} else {			$record[++$#record] = $_;		}	}	&process_record;}sub read_detailfile {	my $file_starttime = time(); my $filename = shift; my @record = (); my $record_no = 0;	if ($verbose > 1) { print "DEBUG: Reading detail file: $filename\n" }	if ((-r $filename) != 1) { 		# test if the file exists and is readable		if ($verbose >= 0) { print "INFO: Skipping file \"$filename\" as it is not readable or does not exist.\n" }		return;	 }	if ( $filename =~ /.gz$/ ) {		# Deal with compressed files		open (DETAIL, "$GZCAT $filename |") || warn "read_detailfile(\"$filename\"): $!\n";	} elsif ( $filename =~ /.Z$/ ) {		open (DETAIL, "$ZCAT $filename |") || warn "read_detailfile(\"$filename\"): $!\n";	} elsif ( $filename =~ /.bz2$/ ) {		open (DETAIL, "$BZCAT $filename |") || warn "read_detailfile(\"$filename\"): $!\n";	} else {		open (DETAIL, "<$filename") || warn "read_detailfile(\"$filename\"): $!\n";	}	$valid_input = (eof(DETAIL) ? 0 : 1);	if ($verbose > 1) { print "DEBUG: Starting to read records from $filename\n"; }	while($valid_input) {		$valid_input = 0 if (eof(DETAIL));		if ($verbose > 1) { print "DEBUG: Reading Record\n"; }		&read_record;		$record_no++;	}	my $file_runtime = (time() - $file_starttime);	if ($file_runtime < 1) { $file_runtime = 1; }	my $file_speed = ($record_no / $file_runtime);        if ($verbose >= 0) { print "\n $record_no total records read from $filename were processed in $file_runtime seconds ($file_speed records/sec) \n"; }}sub print_usage_info {	print "\n";	$leader = "$progname $version Usage Information";	$underbar = $leader;	$underbar =~ s/./-/g;	print "$leader\n$underbar\n";	print "\n";	print "  Syntax:   h323detail2db.pl [ options ] detailfile(s)\n";	print "\n";	print "    -d --database                    Database to use\n";	print "    -h --help                        Show this usage information\n";	print "    -H --host                        Database host to connect to (Default: localhost)\n";	print "    -p --procedure                   Use Postgresql stored procedure (BROKEN!)\n";	print "    -q --quiet                       Turn on quiet mode (No Output)\n";	print "    -v --verbose                     Turn on verbose\n";	print "    -V --version                     Show version and copyright\n";	print "    -x --debug                       Turn on debugging\n";	print "\n";}sub procedure_get() {        return $stored_procedure;}sub procedure_set($) {        $stored_procedure = $_[0];}sub main {        # Parse the command line for options        if (!scalar(@ARGV)) {        	&print_usage_info();		exit(SUCCESS);	};	# See the Getopt::Long man page for details on the syntax of this line	@valid_opts = ("h|help", "V|version", "f|file=s", "x|debug", "d|database=s", "v|verbose+" => \$verbose, "q|quiet+" => \$quiet, "D|date=s", "H|host=s", "p|procedure");	Getopt::Long::Configure("no_getopt_compat", "bundling", "no_ignore_case");	Getopt::Long::GetOptions(@valid_opts);	# Post-parse the options stuff	select STDOUT; $| = 1;	if ($opt_V) {		# Do not edit this variable.  It is updated automatically by CVS when you commit		my $rcs_info = 'CVS Revision $Revision: 1.19 $ created on $Date: 2007/05/14 22:26:58 $ by $Author: nbk $ ';		$rcs_info =~ s/\$\s*Revision: (\S+) \$/$1/;		$rcs_info =~ s/\$\s*Date: (\S+) (\S+) \$/$1 at $2/;		$rcs_info =~ s/\$\s*Author: (\S+) \$ /$1/;		print "\n";		print "$progname Version $version by Peter Nixon - http://www.peternixon.net/\n";		print "Copyright (c) 2002-2004 Peter Nixon\n";		print "  ($rcs_info)\n";		print "\n";		return SUCCESS;	} elsif ($opt_h) {	        &print_usage_info();	        exit(SUCCESS);	}	if ($opt_x) {		print "DEBUG: Debug mode is enabled.\n";		$verbose = 2;	} elsif ($quiet) { $verbose -= $quiet; }	&procedure_set($opt_p);	if ($opt_d) {		if ($verbose > 0) { print "Using database \"$opt_d\" instead of default database \"$database\"\n"; }		$database = $opt_d;	}	if (@ARGV) {		my $db_host;		if ($opt_H) { $db_host = $opt_H; }		else { $db_host = "localhost"; }		&db_connect($db_host);        	# Loop through the defined files	        foreach $file (@ARGV) {			&read_detailfile($file);	        }		&process_duplicates;		&db_disconnect($db_host);		my $runtime = (time() - $starttime);		if ($runtime < 1) { $runtime = 1; }		my $speed = ($passno / $runtime);	        if ($verbose >= 0) { print "\n $passno valid records were processed in $runtime seconds ($speed records/sec) \n"; }	} else {		print "ERROR: Please specify one or more detail file(s) to import.\n";		exit(FAILURE);	}}exit &main();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -