|
|
|
#!/usr/bin/perl -w
|
|
|
|
|
|
|
|
use Asterisk::AMI;
|
|
|
|
use Net::Telnet;
|
|
|
|
use CGI qw/:standard/;
|
|
|
|
|
|
|
|
require ('/etc/callback/callback.conf');
|
|
|
|
|
|
|
|
$host ||= '127.0.0.1';
|
|
|
|
$port ||= '5038';
|
|
|
|
$user ||= 'callback';
|
|
|
|
$secret ||= 'secret';
|
|
|
|
$cid ||= '';
|
|
|
|
$webhost ||= '';
|
|
|
|
|
|
|
|
my $q = new CGI;
|
|
|
|
|
|
|
|
print $q->header,
|
|
|
|
$q->start_html(-title=>'CallBack',
|
|
|
|
-style=>{"src"=>"$webhost/server-common/css/bootstrap.min.css"}
|
|
|
|
),
|
|
|
|
|
|
|
|
$q->div({
|
|
|
|
-class=>"well",
|
|
|
|
-style=>"width: 500px; margin-top: 40px; margin-right: auto; margin-left: auto"
|
|
|
|
}),
|
|
|
|
|
|
|
|
$q->h1('<center>Mise en relation téléphonique</center><p><p>'),
|
|
|
|
$q->start_form(-class=>"form-horizontal"),
|
|
|
|
|
|
|
|
$q->div({-class=>"control-group"},
|
|
|
|
"<label class= \"control-label\" for=\"nback\">Votre numéro</label>",
|
|
|
|
$q->div({-class=>"controls"},
|
|
|
|
$q->textfield(
|
|
|
|
-name=>"nback",
|
|
|
|
-class=>"input-xlarge",
|
|
|
|
-size=>"30",
|
|
|
|
-style=>"width: 300px; height: 25px"
|
|
|
|
),
|
|
|
|
)
|
|
|
|
),
|
|
|
|
$q->div({-class=>"control-group"},
|
|
|
|
"<label class= \"control-label\" for=\"ndest\">Le numéro à joindre</label>",
|
|
|
|
$q->div({-class=>"controls"},
|
|
|
|
$q->textfield(
|
|
|
|
-name=>"ndest",
|
|
|
|
-class=>"input-xlarge",
|
|
|
|
-size=>"30",
|
|
|
|
-style=>"width: 300px; height: 25px"
|
|
|
|
),
|
|
|
|
)
|
|
|
|
),
|
|
|
|
$q->div({-class=>"control-group"},
|
|
|
|
"<label class= \"control-label\" for=\"cid\">Le numéro à présenter</label>",
|
|
|
|
$q->div({-class=>"controls"},
|
|
|
|
$q->textfield(
|
|
|
|
-name=>"cid",
|
|
|
|
-class=>"input-xlarge",
|
|
|
|
-size=>"30",
|
|
|
|
-style=>"width: 300px; height: 25px"
|
|
|
|
),
|
|
|
|
)
|
|
|
|
),
|
|
|
|
$q->submit(
|
|
|
|
-name=>"submit",
|
|
|
|
-class=>"btn btn-primary",
|
|
|
|
-style=>"margin-left: 200px",
|
|
|
|
-value=>"Appeler",
|
|
|
|
),
|
|
|
|
$q->end_form;
|
|
|
|
|
|
|
|
|
|
|
|
if ($q->param()) {
|
|
|
|
my $nback = $q->param('nback') || $ENV{'HTTP_USER_EXTENSION'};
|
|
|
|
my $ndest = $q->param('ndest');
|
|
|
|
my $cid = $q->param('cid') || $cid;
|
|
|
|
|
|
|
|
$nback =~ s/[\s\(\)\.<>]//g;
|
|
|
|
$ndest =~ s/[\s\(\)\.<>]//g;
|
|
|
|
$nback =~ s/^\+/00/g;
|
|
|
|
$ndest =~ s/^\+/00/g;
|
|
|
|
|
|
|
|
unless (($nback =~ m/^\d+$/) && ($ndest =~ m/^\d+$/)){
|
|
|
|
print $q->div({-class=>"alert-message error",},
|
|
|
|
"<strong>Erreur !</strong> Un des numeros ne semble pas valide"
|
|
|
|
);
|
|
|
|
die 'bad number';
|
|
|
|
}
|
|
|
|
|
|
|
|
my $telnet = new Net::Telnet (Timeout => 5,
|
|
|
|
Errmode => "die",
|
|
|
|
Host => "$host",
|
|
|
|
Port => "$port");
|
|
|
|
# Login
|
|
|
|
$telnet->open ();
|
|
|
|
$telnet->print ("Action: Login");
|
|
|
|
$telnet->print ("Username: $user");
|
|
|
|
$telnet->print ("Secret: $secret");
|
|
|
|
$telnet->print ("");
|
|
|
|
|
|
|
|
my ($status, $what) = $telnet->waitfor ("/Message: .*/");
|
|
|
|
|
|
|
|
# Check login status
|
|
|
|
unless (($status =~ m/Success/) && ($what =~ m/Authentication/)) {
|
|
|
|
print $q->div({-class=>"alert-message error",},
|
|
|
|
"<strong>Erreur !</strong> Une erreur d'authentification est survenue"
|
|
|
|
);
|
|
|
|
die 'Authentication error';
|
|
|
|
}
|
|
|
|
|
|
|
|
$telnet->print ("Action: Originate");
|
|
|
|
$telnet->print ("Channel: Local/$nback\@from-internal");
|
|
|
|
$telnet->print ("Context: from-internal");
|
|
|
|
$telnet->print ("Exten: $ndest");
|
|
|
|
$telnet->print ("Priority: 1");
|
|
|
|
$telnet->print ("Callerid: $cid");
|
|
|
|
$telnet->print ("");
|
|
|
|
|
|
|
|
($status, $what) = $telnet->waitfor ("/Message: .*/");
|
|
|
|
|
|
|
|
# Check originate command status
|
|
|
|
unless (($status =~ m/Success/) && ($what =~ m/Originate/)) {
|
|
|
|
print $q->div({-class=>"alert-message error",},
|
|
|
|
"<strong>Erreur !</strong> Une erreur est survenue pendant la numérotation"
|
|
|
|
);
|
|
|
|
die 'Originate error';
|
|
|
|
}
|
|
|
|
|
|
|
|
$telnet->close;
|
|
|
|
}
|
|
|
|
|