#!/usr/bin/perl -w # # Aplicacion para ejecutar comandos de Asterisk desde la consola # # Autor: Elio Rojano # Web: http://www.sinologic.net/ # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA # 02111-1307 USA use strict; use IO::Socket; use Getopt::Long; $|=1; my $host = "localhost"; my $port = 5038; my $username = "usuario-manager"; # Aqui ponemos el usuario que tengamos configurado en el manager.conf my $password = "password-manager"; # Aqui ponemos la password del usuario my $verbose; my ( $version, $response, $message, $line, $help, $command, $comandos, $argnum, $sock, $key, $s, $i, ); unless ($sock = IO::Socket::INET->new(PeerAddr => $host, PeerPort => $port, Proto => 'tcp')) { print("Could not connect to asterisk server ".$host.":".$port."\n") if ($verbose); exit(2); } $version = <$sock>; print $version if ($verbose); print $sock "Action: Login\r\nUsername: $username\r\nSecret: $password\r\nEvents: off\r\n\r\n"; print "Action: Login\r\nUsername: $username\r\nSecret: $password\r\n\r\n" if ($verbose); $response = <$sock>; $message = <$sock>; $s = <$sock>; print $response.$message if ($verbose); print $s if ($verbose); #exit(1) unless ($response =~ m/^Response:\s+(.*)$/i); #exit(1) unless ($1 =~ m/Success/i); foreach $argnum (0 .. $#ARGV) { $comandos=$comandos." $ARGV[$argnum]"; } print "Ejecutando: $comandos\n" if ($verbose); print $sock "Action: Command\r\n"; print $sock "Command: $comandos\r\n\r\n"; while ($message !~ /END/i){ $message = <$sock>; if (($message !~ /END/i)&&($message !~ /Response/i)&&($message !~ /Privilege/i)){ print $message; } } # Log out print $sock "Action: Logoff\r\n\r\n"; undef($s);