2009-11-05 18:01:43 -05:00
|
|
|
use ESL;
|
|
|
|
|
|
|
|
my $host = "localhost";
|
|
|
|
my $port = "8021";
|
|
|
|
my $pass = "ClueCon";
|
|
|
|
my $profile = "internal";
|
|
|
|
my $file = "";
|
|
|
|
my $debug = "";
|
|
|
|
my $paste = "";
|
|
|
|
my $i;
|
|
|
|
my $argc = @ARGV;
|
|
|
|
my $e;
|
|
|
|
my $running = 1;
|
|
|
|
my $con;
|
|
|
|
|
2009-11-05 18:19:20 -05:00
|
|
|
my $USAGE = "
|
|
|
|
FreeSWITCH Logger Utility
|
|
|
|
|
|
|
|
USAGE:
|
2010-11-23 20:17:46 -05:00
|
|
|
-h --help This help
|
2011-03-23 00:31:35 -04:00
|
|
|
-H --host Choose host
|
2009-11-05 18:19:20 -05:00
|
|
|
-p --port <port> Choose port
|
|
|
|
-P -pass <pass> Choose password
|
|
|
|
-f --file <file> Output file
|
|
|
|
-pb --paste-bin <name> Post to FreeSWITCH Paste Bin
|
|
|
|
-sp --sip-profiles <list> List of SIP profiles to trace
|
2010-11-23 20:17:46 -05:00
|
|
|
-sd --sip-debug <level> Set SIP debug level
|
2009-11-05 18:19:20 -05:00
|
|
|
|
|
|
|
No arguments given will trace profile 'internal' to STDOUT
|
|
|
|
";
|
|
|
|
|
2009-11-05 18:01:43 -05:00
|
|
|
$SIG{INT} = sub { $running = 0 };
|
|
|
|
|
|
|
|
sub parse(\$\$$) {
|
|
|
|
my ($index, $ref, $regex) = @_;
|
|
|
|
|
|
|
|
if ($ARGV[$$index] =~ $regex) {
|
|
|
|
die "missing arg!" if (!$ARGV[$$index+1]);
|
|
|
|
$$ref = $ARGV[++$$index];
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for($i = 0; $i < $argc; $i++) {
|
2011-03-23 00:25:19 -04:00
|
|
|
if ($ARGV[$i] =~ /^\-h$|^\-\-help$/) {
|
2009-11-05 18:19:20 -05:00
|
|
|
print $USAGE;
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2011-03-23 00:31:35 -04:00
|
|
|
if (! (parse($i, $host, '^-H$|^--host$') ||
|
2009-11-05 18:01:43 -05:00
|
|
|
parse($i, $port, '^-p$|^--port$') ||
|
|
|
|
parse($i, $pass, '^-P$|^--pass$') ||
|
|
|
|
parse($i, $file, '^-f$|^--file$') ||
|
|
|
|
parse($i, $paste, '^-pb$|^--paste-bin$') ||
|
|
|
|
parse($i, $profile, '^-sp$|^--sip-profile$') ||
|
|
|
|
parse($i, $debug, '^-sd$|^--sip-debug$')
|
|
|
|
)) {
|
|
|
|
die "invalid arg!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($paste) {
|
|
|
|
if (!$file) {
|
|
|
|
$file = "./logger_post.log";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($file) {
|
|
|
|
open (F, ">$file");
|
|
|
|
select F;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($paste) {
|
|
|
|
print F "paste=Send&remember=0&poster=${paste}&format=fslog&code2=";
|
|
|
|
}
|
|
|
|
|
|
|
|
$con = new ESL::ESLconnection($host, $port, $pass);
|
|
|
|
|
|
|
|
sub do_api($) {
|
|
|
|
my ($cmd, $args) = split(" ", $_[0], 2);
|
|
|
|
my $e = $con->api($cmd, $args);
|
|
|
|
if ($e) {
|
|
|
|
print STDERR $e->getBody() . "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (split(",", $profile)) {
|
|
|
|
do_api("sofia profile $_ siptrace on");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($debug) {
|
|
|
|
do_api("sofia loglevel all $debug");
|
|
|
|
}
|
|
|
|
|
|
|
|
$e = $con->sendRecv("log 7");
|
|
|
|
print STDERR $e->getBody() . "\n" if ($e);
|
|
|
|
|
|
|
|
while($con->connected() && $running) {
|
|
|
|
$e = $con->recvEventTimed(100);
|
|
|
|
if ($e and $e->getHeader("content-type") eq "log/data") {
|
|
|
|
print $e->getBody();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print STDERR "Stopping\n";
|
|
|
|
|
|
|
|
foreach (split(",", $profile)) {
|
|
|
|
do_api("sofia profile $_ siptrace off");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($debug) {
|
|
|
|
do_api("sofia loglevel all 0");
|
|
|
|
}
|
|
|
|
|
|
|
|
$e = $con->sendRecv("log 4");
|
|
|
|
print STDERR $e->getBody() . "\n" if ($e);
|
|
|
|
|
|
|
|
print STDERR "Done.....\n";
|
|
|
|
|
|
|
|
if ($file) {
|
|
|
|
close F;
|
|
|
|
print STDERR "Data written to $file\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($paste) {
|
|
|
|
my $path;
|
|
|
|
system("mkdir -p .fs_logger");
|
|
|
|
chdir(".fs_logger") or die "I/O Error!";
|
|
|
|
|
|
|
|
if ($file =~ /^\/.*/) {
|
|
|
|
$path = $file;
|
|
|
|
} else {
|
|
|
|
$path = "../$file";
|
|
|
|
}
|
|
|
|
|
|
|
|
print STDERR "Posting to pastebin, please wait...\n";
|
|
|
|
|
|
|
|
system("wget --output-file=/dev/null --http-user=pastebin --http-password=freeswitch http://pastebin.freeswitch.org --post-file=$path");
|
|
|
|
$pb = `ls [0-9]*`;
|
|
|
|
print STDERR "Data posted to pastebin [$paste] http://pastebin.freeswitch.org/$pb\n";
|
|
|
|
chdir("..") or die "I/O Error!";
|
|
|
|
system("rm -fr .fs_logger");
|
|
|
|
}
|