2007-12-30 20:23:07 -05:00
|
|
|
|
#!/usr/bin/perl
|
2006-07-22 17:49:52 -04:00
|
|
|
|
use FreeSWITCH::Client;
|
|
|
|
|
use Data::Dumper;
|
|
|
|
|
use Term::ReadLine;
|
|
|
|
|
my $password = "ClueCon";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
my $fs = init FreeSWITCH::Client {-password => $password} or die "Error $@";
|
2006-07-22 20:37:19 -04:00
|
|
|
|
my $term = new Term::ReadLine "FreeSWITCH CLI";
|
2007-02-06 16:24:43 -05:00
|
|
|
|
my $prompt = "[mFreeSWITCH>";
|
2006-07-22 17:49:52 -04:00
|
|
|
|
my $OUT = $term->OUT .. \*STDOUT;
|
2007-02-06 16:24:43 -05:00
|
|
|
|
my $pid;
|
2006-07-22 17:49:52 -04:00
|
|
|
|
|
|
|
|
|
my $log = shift;
|
|
|
|
|
|
2006-07-25 10:14:07 -04:00
|
|
|
|
$SIG{CHLD} = sub {$fs->disconnect(); die "done"};
|
|
|
|
|
|
2006-07-22 17:49:52 -04:00
|
|
|
|
if ($log) {
|
|
|
|
|
$pid = fork;
|
|
|
|
|
if (!$pid) {
|
|
|
|
|
my $fs2 = init FreeSWITCH::Client {-password => $password} or die "Error $@";
|
2006-07-25 10:14:07 -04:00
|
|
|
|
|
|
|
|
|
|
2007-02-06 16:24:43 -05:00
|
|
|
|
$fs2->sendmsg({ 'command' => "log $log" });
|
2006-07-22 17:49:52 -04:00
|
|
|
|
while (1) {
|
|
|
|
|
my $reply = $fs2->readhash(undef);
|
2006-07-25 10:14:07 -04:00
|
|
|
|
if ($reply->{socketerror}) {
|
|
|
|
|
die "socket error";
|
|
|
|
|
}
|
2007-02-06 16:24:43 -05:00
|
|
|
|
|
2006-07-22 17:49:52 -04:00
|
|
|
|
if ($reply->{body}) {
|
2007-02-06 16:24:43 -05:00
|
|
|
|
print $reply->{body};
|
|
|
|
|
}
|
2006-07-22 17:49:52 -04:00
|
|
|
|
}
|
2006-07-25 10:14:07 -04:00
|
|
|
|
exit;
|
2006-07-22 17:49:52 -04:00
|
|
|
|
}
|
2006-07-25 10:14:07 -04:00
|
|
|
|
|
2006-07-22 17:49:52 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while ( defined ($_ = $term->readline($prompt)) ) {
|
|
|
|
|
if ($_) {
|
2007-02-06 16:24:43 -05:00
|
|
|
|
if ($_ =~ /exit/) {
|
|
|
|
|
last;
|
|
|
|
|
}
|
|
|
|
|
my $reply = $fs->command($_);
|
2006-07-25 10:14:07 -04:00
|
|
|
|
if ($reply->{socketerror}) {
|
|
|
|
|
$fs2->disconnect();
|
|
|
|
|
die "socket error";
|
|
|
|
|
}
|
2007-02-06 16:24:43 -05:00
|
|
|
|
print "$reply\n";
|
|
|
|
|
|
2006-07-22 17:49:52 -04:00
|
|
|
|
}
|
|
|
|
|
$term->addhistory($_) if /\S/;
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-06 16:24:43 -05:00
|
|
|
|
if ($pid) {
|
|
|
|
|
kill 9 => $pid;
|
|
|
|
|
}
|