use bootstrap css, net::telnet and allow custom CID

tags/0.1.1
Daniel Berteaud 13 years ago
parent 148c96666e
commit 8607266634
  1. 2
      root/etc/e-smith/templates/etc/callback/callback.conf/All
  2. 134
      root/usr/share/callback/cgi-bin/callback.cgi
  3. 10
      smeserver-callback.spec

@ -2,5 +2,7 @@ $host = "{$callback{'Host'} || '127.0.0.1';}";
$port = "{$callback{'Port'} || '5038';}"; $port = "{$callback{'Port'} || '5038';}";
$user = "{$callback{'User'} || 'callback';}"; $user = "{$callback{'User'} || 'callback';}";
$secret = "{$callback{'Secret'} || 'secret';}"; $secret = "{$callback{'Secret'} || 'secret';}";
$cid = "{$callback{'CallerID'} || ''}";
$webhost = "http://{$SystemName.'.'.$DomainName}";
1 1

@ -1,6 +1,7 @@
#!/usr/bin/perl -w #!/usr/bin/perl -w
use Asterisk::AMI; use Asterisk::AMI;
use Net::Telnet;
use CGI qw/:standard/; use CGI qw/:standard/;
require ('/etc/callback/callback.conf'); require ('/etc/callback/callback.conf');
@ -9,47 +10,122 @@ $host ||= '127.0.0.1';
$port ||= '5038'; $port ||= '5038';
$user ||= 'callback'; $user ||= 'callback';
$secret ||= 'secret'; $secret ||= 'secret';
$cid ||= '';
$webhost ||= '';
my $q = new CGI; my $q = new CGI;
print $q->header, print $q->header,
$q->start_html(-title=>'CallBack', $q->start_html(-title=>'CallBack',
), -style=>{"src"=>"$webhost/server-common/css/bootstrap.min.css"}
$q->h1('page de callback'), ),
$q->start_form,
"Entrez ici votre numero ",textfield('nback'),p, $q->div({
"Entrez ici le numero de votre destinataire ", textfield('ndest'),p, -class=>"well",
$q->submit, -style=>"width: 500px; margin-top: 40px; margin-right: auto; margin-left: auto"
$q->end_form, }),
$q->hr;
$q->h1('<center>Mise en relation t&eacute;l&eacute;phonique</center><p><p>'),
$q->start_form(-class=>"form-horizontal"),
$q->div({-class=>"control-group"},
"<label class= \"control-label\" for=\"nback\">Votre num&eacute;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&eacute;ro &agrave; 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&eacute;ro &agrave; pr&eacute;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()) { if ($q->param()) {
my $nback = $q->param('nback') || $ENV{'HTTP_USER_EXTENSION'}; my $nback = $q->param('nback') || $ENV{'HTTP_USER_EXTENSION'};
my $ndest = $q->param('ndest'); 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 ("");
$nback =~ s/[\s\(\)\.<>]//g; my ($status, $what) = $telnet->waitfor ("/Message: .*/");
$ndest =~ s/[\s\(\)\.<>]//g;
unless (($nback =~ m/^\d+$/) && ($ndest =~ m/^\d+$/)){ # Check login status
print $q->h1('un des numeros ne semble pas valide, ils ne doivent contenir que des chiffres'); unless (($status =~ m/Success/) && ($what =~ m/Authentication/)) {
die ('bad number'); print $q->div({-class=>"alert-message error",},
} "<strong>Erreur !</strong> Une erreur d'authentification est survenue"
);
die 'Authentication error';
}
my $astman = Asterisk::AMI->new(PeerAddr => "$host", $telnet->print ("Action: Originate");
PeerPort => "$port", $telnet->print ("Channel: Local/$nback\@from-internal");
Username => "$user", $telnet->print ("Context: from-internal");
Secret => "$secret" $telnet->print ("Exten: $ndest");
); $telnet->print ("Priority: 1");
$telnet->print ("Callerid: $cid");
$telnet->print ("");
die "Unable to connect to asterisk" unless ($astman); ($status, $what) = $telnet->waitfor ("/Message: .*/");
my $response = $astman->action({Action => 'Originate', # Check originate command status
Channel => "Local/$nback\@from-internal", unless (($status =~ m/Success/) && ($what =~ m/Originate/)) {
Context => 'from-internal', print $q->div({-class=>"alert-message error",},
CallerID => $ndest, "<strong>Erreur !</strong> Une erreur est survenue pendant la num&eacute;rotation"
Exten => $ndest, );
Priority => 1}); die 'Originate error';
}
} $telnet->close;
}

@ -1,8 +1,8 @@
Summary: A small page to originate calls through an asterisk server Summary: A small page to originate calls through an asterisk server
%define name smeserver-callback %define name smeserver-callback
Name: %{name} Name: %{name}
%define version 0.1 %define version 0.1.0
%define release 0.beta3 %define release 1
Version: %{version} Version: %{version}
Release: %{release}%{?dist} Release: %{release}%{?dist}
License: GPL License: GPL
@ -15,15 +15,15 @@ BuildArch: noarch
BuildRequires: e-smith-devtools BuildRequires: e-smith-devtools
Requires: e-smith-base Requires: e-smith-base
Requires: smeserver-webapps-common Requires: smeserver-webapps-common >= 0.2.3
Requires: perl(Asterisk::AMI) Requires: perl(Net::Telnet)
%description %description
This package contains all the needed scripts and templates This package contains all the needed scripts and templates
to run the callback form to run the callback form
%changelog %changelog
* Fri Nov 18 2011 Daniel Berteaud <daniel@firewall-services.com> - 0.1 * Fri Nov 18 2011 Daniel Berteaud <daniel@firewall-services.com> - 0.1.0
- Initiale release - Initiale release
%prep %prep

Loading…
Cancel
Save