Created
October 6, 2009 03:48
-
-
Save Woody2143/202756 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package MergeFunctions; | |
# Usage: `use MergeFunctions qw( getURL, mergeFiles );` | |
use strict; | |
use warnings; | |
use base qw(Exporter); | |
our $VERSION = 1.00; | |
our @EXPORT_OK = qw( &getURL &mergeFiles ); | |
sub getURL { | |
use Expect; | |
$Expect::Exp_Internal = 0; | |
$Expect::Log_Stdout = 0; | |
$Expect::Multiline_Matching = 1; | |
my $timeout = 600; | |
my ($url) = @_; | |
my $wget = new Expect; | |
$wget->raw_pty(1); | |
my $command = "/usr/bin/wget $url -P /var/www/localhost/htdocs/snoop/files/"; | |
$wget->spawn($command) | |
or die "Failed to spawn wget session... $!\n"; | |
$wget->expect($timeout, | |
[qr/100%/, ], | |
["PASSCODE:" => sub { $wget->soft_close(); | |
die "FAILED: Received PASSCODE prompt."; | |
}], | |
["Please Enter the Next Code from Your Token:" => sub { $wget->soft_close(); | |
die "FAILED: Received NEXT PASSCODE prompt."; | |
}], | |
["RADIUS DOWN, Unix password:" => sub { $wget->soft_close(); | |
die "FAILED: Received PASSWORD prompt."; | |
}], | |
["continue connecting" => sub { $wget->send("yes\n"); | |
exp_continue; | |
}], | |
[timeout => sub { $wget->soft_close(); | |
die "FAILED: Process to pull $url timed out."; | |
}], | |
) or die "FAILED: to get $url. $!.\n"; | |
$wget->soft_close(); | |
my($directory, $filename) = $url =~ m/(.*\/)(.*)$/; | |
return $filename; | |
} | |
sub mergeFiles { | |
my ($sip_file, $rtp_file) = @_; | |
my $merge = new Expect; | |
$merge->raw_pty(1); | |
my $command = "/usr/bin/mergecap -w /var/www/localhost/htdocs/snoop/files/merged-$sip_file /var/www/localhost/htdocs/snoop/files/$sip_file /var/www/localhost/htdocs/snoop/files/$rtp_file"; | |
system($command); | |
my $filename = "http://hostname/snoop/files/merged-$sip_file"; | |
return $filename; | |
} | |
1;b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment