commit c173c7e399a12c841fdcfb99482f00ada8b18348 Author: Daniel Berteaud Date: Thu Apr 12 19:13:19 2012 +0200 Initial commit diff --git a/createlinks b/createlinks new file mode 100644 index 0000000..2622623 --- /dev/null +++ b/createlinks @@ -0,0 +1,6 @@ +#!/usr/bin/perl -w + +use esmith::Build::CreateLinks qw(:all); + +templates2events("/etc/callback/callback.conf", qw(webapps-update bootstrape-ldap-save)); + diff --git a/root/etc/e-smith/db/configuration/defaults/callback/Host b/root/etc/e-smith/db/configuration/defaults/callback/Host new file mode 100644 index 0000000..7b9ad53 --- /dev/null +++ b/root/etc/e-smith/db/configuration/defaults/callback/Host @@ -0,0 +1 @@ +127.0.0.1 diff --git a/root/etc/e-smith/db/configuration/defaults/callback/User b/root/etc/e-smith/db/configuration/defaults/callback/User new file mode 100644 index 0000000..c0df748 --- /dev/null +++ b/root/etc/e-smith/db/configuration/defaults/callback/User @@ -0,0 +1 @@ +callback diff --git a/root/etc/e-smith/db/configuration/defaults/callback/access b/root/etc/e-smith/db/configuration/defaults/callback/access new file mode 100644 index 0000000..3e18ebf --- /dev/null +++ b/root/etc/e-smith/db/configuration/defaults/callback/access @@ -0,0 +1 @@ +private diff --git a/root/etc/e-smith/db/configuration/defaults/callback/status b/root/etc/e-smith/db/configuration/defaults/callback/status new file mode 100644 index 0000000..86981e6 --- /dev/null +++ b/root/etc/e-smith/db/configuration/defaults/callback/status @@ -0,0 +1 @@ +enabled diff --git a/root/etc/e-smith/db/configuration/defaults/callback/type b/root/etc/e-smith/db/configuration/defaults/callback/type new file mode 100644 index 0000000..1b93c9e --- /dev/null +++ b/root/etc/e-smith/db/configuration/defaults/callback/type @@ -0,0 +1 @@ +webapp diff --git a/root/etc/e-smith/db/configuration/migrate/callback-secret b/root/etc/e-smith/db/configuration/migrate/callback-secret new file mode 100644 index 0000000..4dd7884 --- /dev/null +++ b/root/etc/e-smith/db/configuration/migrate/callback-secret @@ -0,0 +1,31 @@ +{ + my $rec = $DB->get('callback') + || $DB->new_record('callback', {type => 'webapp'}); + my $pw = $rec->prop('Secret'); + if (not $pw or length($pw) < 30) + { + use MIME::Base64 qw(encode_base64); + + $pw = "not set due to error"; + if ( open( RANDOM, "/dev/urandom" ) ) + { + my $buf; + if ( read( RANDOM, $buf, 30 ) != 30 ) + { + warn("Short read from /dev/random: $!"); + } + else + { + $pw = encode_base64($buf); + chomp $pw; + } + close RANDOM; + } + else + { + warn "Could not open /dev/urandom: $!"; + } + $rec->set_prop('Secret', $pw); + } +} + diff --git a/root/etc/e-smith/templates.metadata/etc/callback/callback.conf b/root/etc/e-smith/templates.metadata/etc/callback/callback.conf new file mode 100644 index 0000000..bad4258 --- /dev/null +++ b/root/etc/e-smith/templates.metadata/etc/callback/callback.conf @@ -0,0 +1,3 @@ +PERMS=0640 +UID="root" +GID="www" diff --git a/root/etc/e-smith/templates/etc/callback/callback.conf/All b/root/etc/e-smith/templates/etc/callback/callback.conf/All new file mode 100644 index 0000000..3de9edc --- /dev/null +++ b/root/etc/e-smith/templates/etc/callback/callback.conf/All @@ -0,0 +1,6 @@ +$host = "{$callback{'Host'} || '127.0.0.1';}"; +$port = "{$callback{'Port'} || '5038';}"; +$user = "{$callback{'User'} || 'callback';}"; +$secret = "{$callback{'Secret'} || 'secret';}"; + +1 diff --git a/root/etc/e-smith/templates/etc/httpd/conf/httpd.conf/98CallBack b/root/etc/e-smith/templates/etc/httpd/conf/httpd.conf/98CallBack new file mode 100644 index 0000000..2dbeaf6 --- /dev/null +++ b/root/etc/e-smith/templates/etc/httpd/conf/httpd.conf/98CallBack @@ -0,0 +1,31 @@ +{ +my $access = $callback{'access'} || 'private'; +my $allow = ($access eq 'public')?'all':"$localAccess $externalSSLAccess"; + +my $requiressl = (($callback{'RequireSSL'} || 'yes') eq 'yes') ? + "SSLRequireSSL on":"# RequireSSL is disabled"; + +my $alias = (($callback{'AliasOnPrimary'} || 'enabled') eq 'enabled') ? + 'ScriptAlias /callback /usr/share/callback/cgi-bin/callback.cgi' : ''; + +if ($callback{'status'} eq 'enabled'){ + +$OUT .=<<"END" + +# Callback Configuration +$alias + + SetHandler cgi-script + Options ExecCGI + AllowOverride None + $requiressl + order deny,allow + deny from all + allow from $allow + +END +} +else{ + $OUT .= "# CallBack is disabled\n"; +} +} diff --git a/root/usr/share/callback/cgi-bin/callback.cgi b/root/usr/share/callback/cgi-bin/callback.cgi new file mode 100644 index 0000000..a1f3407 --- /dev/null +++ b/root/usr/share/callback/cgi-bin/callback.cgi @@ -0,0 +1,55 @@ +#!/usr/bin/perl -w + +use Asterisk::AMI; +use CGI qw/:standard/; + +require ('/etc/callback/callback.conf'); + +$host ||= '127.0.0.1'; +$port ||= '5038'; +$user ||= 'callback'; +$secret ||= 'secret'; + +my $q = new CGI; + +print $q->header, + $q->start_html(-title=>'CallBack', + ), + $q->h1('page de callback'), + $q->start_form, + "Entrez ici votre numero ",textfield('nback'),p, + "Entrez ici le numero de votre destinataire ", textfield('ndest'),p, + $q->submit, + $q->end_form, + $q->hr; + + +if ($q->param()) { + my $nback = $q->param('nback') || $ENV{'HTTP_USER_EXTENSION'}; + my $ndest = $q->param('ndest'); + + $nback =~ s/[\s\(\)\.<>]//g; + $ndest =~ s/[\s\(\)\.<>]//g; + + unless (($nback =~ m/^\d+$/) && ($ndest =~ m/^\d+$/)){ + print $q->h1('un des numeros ne semble pas valide, ils ne doivent contenir que des chiffres'); + die ('bad number'); + } + + my $astman = Asterisk::AMI->new(PeerAddr => "$host", + PeerPort => "$port", + Username => "$user", + Secret => "$secret" + ); + + die "Unable to connect to asterisk" unless ($astman); + + my $response = $astman->action({Action => 'Originate', + Channel => "Local/$nback\@from-internal", + Context => 'from-internal', + CallerID => $ndest, + Exten => $ndest, + Priority => 1}); + +} + diff --git a/root/usr/share/callback/index.html b/root/usr/share/callback/index.html new file mode 100644 index 0000000..9f5f297 --- /dev/null +++ b/root/usr/share/callback/index.html @@ -0,0 +1 @@ + diff --git a/smeserver-callback.spec b/smeserver-callback.spec new file mode 100644 index 0000000..87ddcc2 --- /dev/null +++ b/smeserver-callback.spec @@ -0,0 +1,58 @@ +Summary: A small page to originate calls through an asterisk server +%define name smeserver-callback +Name: %{name} +%define version 0.1 +%define release 0.beta3 +Version: %{version} +Release: %{release}%{?dist} +License: GPL +Group: Applications/System +Source: %{name}-%{version}.tar.gz + +BuildRoot: /var/tmp/%{name}-%{version}-%{release}-buildroot +BuildArch: noarch + +BuildRequires: e-smith-devtools + +Requires: e-smith-base +Requires: smeserver-webapps-common +Requires: perl(Asterisk::AMI) + +%description +This package contains all the needed scripts and templates +to run the callback form + +%changelog +* Fri Nov 18 2011 Daniel Berteaud - 0.1 +- Initiale release + +%prep + +%setup -q -n %{name}-%{version} + +%build +perl createlinks +%{__mkdir_p} root/etc/callback + + +%install +/bin/rm -rf $RPM_BUILD_ROOT +(cd root ; /usr/bin/find . -depth -print | /bin/cpio -dump $RPM_BUILD_ROOT) +/bin/rm -f %{name}-%{version}-filelist +/sbin/e-smith/genfilelist $RPM_BUILD_ROOT \ + --file /usr/share/callback/cgi-bin/callback.cgi 'attr(0750,root,www)' \ + > %{name}-%{version}-filelist + +%files -f %{name}-%{version}-filelist +%defattr(-,root,root) + +%clean +rm -rf $RPM_BUILD_ROOT + + +%post + +%preun + +true +