Skip to content

Instantly share code, notes, and snippets.

@silvioq
Created August 17, 2011 20:07
Show Gist options
  • Save silvioq/1152471 to your computer and use it in GitHub Desktop.
Save silvioq/1152471 to your computer and use it in GitHub Desktop.
$host = "localhost";
$port = 5038;
$user = "admin";
$secret = "mysecret";
$EOL = "\015\012";
$BLANK = $EOL x 2;
$queue = param('queue');
$remote = IO::Socket::INET->new(
Proto => 'tcp', # protocol
PeerAddr=> $host, # Address of server
PeerPort=> $port, # port of server
Reuse => 1
) or die "$!";
$remote->autoflush(1); # Send immediately
# Login and get our booty from Asterisk
$logres = send_cmd("Action: Login${EOL}Username: $user${EOL}Secret: $secret$BLANK");
sub read_conn {
my $buf="";
while (<$remote>) {
last if $_ eq $EOL;
s/$EOL/\n/g;
$buf .= $_;
}
return $buf
}
sub send_cmd {
my $cmd = @_[0];
my $buf="";
print $remote $cmd;
$buf = read_conn();
return $buf;
}
#!/usr/bin/perl
use IO::Socket;
use CGI qw(:standard);
use CGI::Carp qw/fatalsToBrowser/;
use connect;
print header();
$origen = param("origen");
$destino = param("destino");
if( length( $origen ) > 0 ) {
$cmdoutcall = "Action: Originate${EOL}Channel: $destino${EOL}Context: default${EOL}Exten: $origen${EOL}Callerid: $origen${EOL}Priority: 1${EOL}Timeout: 15000${EOL}Async: yes${BLANK}";
$salida = send_cmd($cmdoutcall);
%nombre = map{ /(Uniqueid)\:\s(.*)/sg; } $salida;
if( $salida =~ /Response: Error/ ){
print "ERROR";
} else {
$xx = $nombre{Uniqueid};
print "OK $xx<pre>$salida</pre>";
}
} else {
print "ERROR: Parameters";
}
close $remote;
exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment