mirror of https://github.com/sipwise/rtpengine.git
parent
fb30ef8ccd
commit
cca0f2bf71
@ -1,70 +1,76 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/perl
|
||||||
#
|
|
||||||
|
|
||||||
host=127.0.0.1
|
use IO::Socket::INET;
|
||||||
port=9900
|
|
||||||
error_rc=255
|
|
||||||
|
|
||||||
prgname=${0##*/}
|
$num_args = $#ARGV + 1;
|
||||||
prgdir=${0%$prgname}
|
if ($num_args == 0) {
|
||||||
|
showusage();
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
# auto-flush on socket
|
||||||
|
$| = 1;
|
||||||
|
|
||||||
showusage() {
|
my $argumentstring = "";
|
||||||
echo ""
|
my $ip = "127.0.0.1";
|
||||||
echo " $0 [ -ip <ipaddress> -port <port> ] <command>"
|
my $port = "9900";
|
||||||
echo ""
|
|
||||||
echo " Supported commands are:"
|
for (my $argnum=0; $argnum <= $#ARGV; $argnum++) {
|
||||||
echo ""
|
if ($ARGV[$argnum] eq "-ip") {
|
||||||
echo " list [ numsessions | sessions | session <callid> ]"
|
die "No argument after -ip\n" unless $argnum+1<=$#ARGV;
|
||||||
echo " numsessions : prints the number of sessions"
|
$argnum = $argnum+1;
|
||||||
echo " sessions : print one-liner session information"
|
$ip = $ARGV[$argnum];
|
||||||
echo " session <callid> : print detail about one session"
|
} elsif ($ARGV[$argnum] eq "-port") {
|
||||||
echo " totals : print total statistics (does not include current sessions)"
|
die "No argument after -port\n" unless $argnum+1<=$#ARGV;
|
||||||
echo ""
|
$argnum = $argnum+1;
|
||||||
echo " terminate [ all | <callid> ]"
|
$port = $ARGV[$argnum];
|
||||||
echo " all : terminates all current sessions"
|
} else {
|
||||||
echo " <callid> : session is immediately terminated"
|
$argumentstring .= "$ARGV[$argnum] ";
|
||||||
echo ""
|
}
|
||||||
echo ""
|
|
||||||
echo " Return Value:"
|
|
||||||
echo " 0 on success with ouput from server side, other values for failure."
|
|
||||||
echo ""
|
|
||||||
exit 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ $# -eq 0 ]; then showusage; fi
|
# create a connecting socket
|
||||||
|
my $socket = new IO::Socket::INET (
|
||||||
|
PeerHost => $ip,
|
||||||
|
PeerPort => $port,
|
||||||
|
Proto => 'tcp',
|
||||||
|
);
|
||||||
|
die "Cannot connect to the rtpengine $!\n" unless $socket;
|
||||||
|
|
||||||
|
$argumentstring = trim($argumentstring);
|
||||||
|
my $size = $socket->send($argumentstring);
|
||||||
|
|
||||||
|
# notify server that request has been sent
|
||||||
|
shutdown($socket, 1);
|
||||||
|
|
||||||
command -v nc 2>&1 >/dev/null
|
# receive a response of up to 10MB
|
||||||
if [ $? -ne 0 ]; then
|
my $response = "";
|
||||||
echo "Error: $0 requires netcat to be installed."
|
$socket->recv($response, 1024*1024*10);
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
while [ $# -gt 0 ]; do
|
print $response;
|
||||||
case $1 in
|
|
||||||
"-?"|"-help"|"-h")
|
$socket->close();
|
||||||
showusage
|
|
||||||
;;
|
sub showusage {
|
||||||
"-ip")
|
print "\n";
|
||||||
shift
|
print " rtpengine-ctl [ -ip <ipaddress> -port <port> ] <command>\n";
|
||||||
if [ $# -gt 0 ]; then
|
print "\n";
|
||||||
host=$1
|
print " Supported commands are:\n";
|
||||||
else
|
print "\n";
|
||||||
echo "Missing parameter for option '-ip'" >&2
|
print " list [ numsessions | sessions | session <callid> | totals ]\n";
|
||||||
fi
|
print " numsessions : prints the number of sessions\n";
|
||||||
;;
|
print " sessions : print one-liner session information\n";
|
||||||
"-port")
|
print " session <callid> : print detail about one session\n";
|
||||||
shift
|
print " totals : print total statistics\n";
|
||||||
if [ $# -gt 0 ]; then
|
print "\n";
|
||||||
port=$1
|
print " terminate [ all | <callid> ]\n";
|
||||||
else
|
print " all : terminates all current sessions\n";
|
||||||
echo "Missing parameter for option '-port'" >&2
|
print " <callid> : session is immediately terminated\n";
|
||||||
fi
|
print "\n";
|
||||||
;;
|
print "\n";
|
||||||
*)
|
print " Return Value:\n";
|
||||||
varargs="$varargs $1"
|
print " 0 on success with ouput from server side, other values for failure.\n";
|
||||||
esac
|
print "\n";
|
||||||
shift
|
}
|
||||||
done
|
|
||||||
|
|
||||||
echo -n ${varargs} | nc ${host} ${port}
|
sub trim { my $s = shift; $s =~ s/^\s+|\s+$//g; return $s };
|
||||||
|
|||||||
Loading…
Reference in new issue