diff options
author | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-04-08 21:34:03 +0000 |
---|---|---|
committer | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-04-08 21:34:03 +0000 |
commit | 58648d5307c185f97248019c3dcf2475735affc7 (patch) | |
tree | 34dd562f97f63b7bb4af71902d4b89b520a1bbaf /contrib | |
parent | e7e96bec86d091ed88bd325e483e6ae257d0434f (diff) |
Merged revisions 113559 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
........
r113559 | tilghman | 2008-04-08 16:33:11 -0500 (Tue, 08 Apr 2008) | 6 lines
Add commandline tool for doing CLI commands through AMI (instead of using asterisk -rx)
(closes issue #12389)
Reported by: davevg
Patches:
astcli uploaded by davevg (license 209)
........
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.0@113560 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'contrib')
-rwxr-xr-x | contrib/scripts/astcli | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/contrib/scripts/astcli b/contrib/scripts/astcli new file mode 100755 index 000000000..a3d5354a8 --- /dev/null +++ b/contrib/scripts/astcli @@ -0,0 +1,67 @@ +#!/usr/bin/perl + +use strict; +use Net::Telnet; +use Getopt::Long; + +# Created by: David Van Ginneken +# Bird's the Word Technologies +# davevg@btwtech.com +my ($user, $pw); +GetOptions("username=s" => \$user, "password=s" => \$pw); +if (undef ne $user) { + # Using CLI-specified options +} elsif (-e "$ENV{HOME}/.astcli") { + process_credentials("$ENV{HOME}/.astcli"); +} elsif (-e '/etc/asterisk/.astcli') { + process_credentials('/etc/asterisk/.astcli'); +} else { + print "User Credentials File Not Found\n"; +} +my $action = join(" ", @ARGV); + +&usage if (!defined $user || !defined $pw); + +my $tc = new Net::Telnet (Timeout => 10, + Errmode => "die", + Host => "localhost", + Port => 5038); +# Login with our username and secret. +$tc->open (); +$tc->print ("Action: Login"); +$tc->print ("Username: $user"); +$tc->print ("Secret: $pw"); +$tc->print ("Events: off"); +$tc->print (""); +# Check for login success. +my ($pre, $match) = $tc->waitfor ("/Message: .*/"); +unless (($pre =~ m/Success/) && ($match =~ m/Authentication/)) { + print "Server Authentication failed.\n"; + exit; +} +$tc->print ("Action: Command"); +$tc->print ("Command: $action"); +$tc->print (""); +($pre, undef) = $tc->waitfor ("/--END COMMAND--.*/"); +$pre =~ s/^\n\n//g; +$pre =~ s/Privilege: Command\n//; +$pre =~ s/Response: Follows\n//; +print $pre; + + +sub process_credentials { + # Process the credentials found.. + my $file = shift; + open (my $fh, "<$file") or die "Unable to open $file\n"; + while (<$fh>) { + chomp; + (undef,$user) = split(/[,=]/, $_) if $_ =~ /user(name)?[,=]/i; + (undef,$pw) = split(/[,=]/, $_) if $_ =~ /(secret|passw(or)?d)[,=]/i; + } +} + +sub usage { + print "astcli [-u <username> -p <passwd>] <cli-command>\n"; + exit; +} + |