Commit inicial
This commit is contained in:
commit
789e50271f
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
class Agi
|
||||
{
|
||||
private static $initialized = FALSE;
|
||||
private static $agivars = array ();
|
||||
|
||||
static function init ()
|
||||
{
|
||||
if (self::$initialized)
|
||||
return;
|
||||
|
||||
self::$initialized = TRUE;
|
||||
pcntl_signal (SIGHUP, SIG_IGN);
|
||||
pcntl_signal (SIGTERM, SIG_IGN);
|
||||
|
||||
while (!feof (STDIN))
|
||||
{
|
||||
$agivar = trim (fgets (STDIN, 4096));
|
||||
|
||||
if ($agivar === '')
|
||||
break;
|
||||
|
||||
$agivar = explode (':', $agivar);
|
||||
self::$agivars[$agivar[0]] = trim ($agivar[1]);
|
||||
}
|
||||
}
|
||||
|
||||
static function get ($agivar)
|
||||
{
|
||||
if (self::$initialized && isset (self::$agivars[$agivar]))
|
||||
return self::$agivars[$agivar];
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static function exec ($cmd, &$result = NULL)
|
||||
{
|
||||
if (!self::$initialized)
|
||||
return -1;
|
||||
|
||||
fwrite (STDOUT, $cmd."\n");
|
||||
fflush (STDOUT);
|
||||
|
||||
$res = trim (fgets (STDIN, 4096));
|
||||
|
||||
if (preg_match ("/^([0-9]{1,3}) (.*)/", $res, $matches))
|
||||
{
|
||||
if (preg_match ('/^result=([0-9\-]*)( ?\((.*)\))?$/', $matches[2], $match))
|
||||
{
|
||||
$ret = (int) $match[1];
|
||||
if ($num > 0)
|
||||
$result = $match[3];
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
/**
|
||||
* Configuration file. Be careful to respect the PHP syntax.
|
||||
*
|
||||
* Do not modify this file! Instead, copy it to config.my.php and make
|
||||
* your changes there.
|
||||
*
|
||||
* Also, you can use a different config file depending on the virtual host. To
|
||||
* do it, you have to create another configuration file and rename it to
|
||||
* config.[subdomain].php. If no configutation file is found for a certain
|
||||
* domain, the main file will be used. Ej:
|
||||
*
|
||||
* - http://www.mydomain.org -> config.www.php
|
||||
* - http://test.mydomain.org -> config.test.php
|
||||
**/
|
||||
return [
|
||||
|
||||
/**
|
||||
* Database parameters.
|
||||
**/
|
||||
'db' => [
|
||||
'host' => 'localhost'
|
||||
,'port' => 3306
|
||||
,'schema' => 'pbx'
|
||||
,'user' => 'pbx'
|
||||
,'pass' => ''
|
||||
]
|
||||
|
||||
];
|
||||
|
||||
?>
|
|
@ -0,0 +1,72 @@
|
|||
#!/usr/bin/php -q
|
||||
<?php
|
||||
|
||||
require_once ('agi.php');
|
||||
require_once ('vn/lib/app.php');
|
||||
|
||||
$app = new Vn\Lib\App ('vn-asterisk');
|
||||
$app->init ();
|
||||
$db = $app->getSysConn ();
|
||||
|
||||
//Agi::init ();
|
||||
|
||||
// Formats the caller phone number
|
||||
|
||||
$callerId = str_replace ('+', '00', Agi::get ('agi_callerid'));
|
||||
|
||||
$countryPrefix = $db->getValue ('SELECT country_prefix FROM config');
|
||||
$prefixLen = strlen ($countryPrefix);
|
||||
|
||||
if (substr ($callerId, 0, $prefixLen) === $countryPrefix)
|
||||
$callerId = substr ($callerId, $prefixLen);
|
||||
|
||||
// Checks if phone number is on the blacklist
|
||||
|
||||
if ($db->getValue ('SELECT COUNT(*) > 0 FROM blacklist WHERE phone = #', [$callerId]))
|
||||
{
|
||||
Agi::exec ('HANGUP');
|
||||
exit ();
|
||||
}
|
||||
|
||||
// Checks whether its a festive day
|
||||
|
||||
$sundayFestive = $db->getValue ('SELECT sunday_festive FROM config');
|
||||
|
||||
if (date ('N') == 6 && $sundayFestive)
|
||||
{
|
||||
Agi::exec ('SET VARIABLE MACRO playback');
|
||||
Agi::exec ('SET VARIABLE ARG1 festive');
|
||||
exit ();
|
||||
}
|
||||
|
||||
// Gets the customer from the phone number
|
||||
|
||||
$customer = $db->getValue ('SELECT customer_from_phone(#)', [$callerId]);
|
||||
|
||||
if ($customer)
|
||||
{
|
||||
// Gets the customer salesperson extension
|
||||
|
||||
$extension = $db->getValue (
|
||||
'SELECT a.extension
|
||||
FROM vn2008.Trabajadores t
|
||||
JOIN pbx.sip a ON t.user_id = a.user_id
|
||||
WHERE t.id_trabajador = vn2008.Averiguar_ComercialCliente_Id(#, CURDATE())'
|
||||
,[$customer]
|
||||
);
|
||||
|
||||
if ($extension)
|
||||
{
|
||||
Agi::exec ('SET VARIABLE MACRO exten');
|
||||
Agi::exec ("SET VARIABLE ARG1 $extension");
|
||||
}
|
||||
else
|
||||
{
|
||||
Agi::exec ('SET VARIABLE MACRO playback');
|
||||
Agi::exec ('SET VARIABLE ARG1 heavy');
|
||||
}
|
||||
|
||||
exit ();
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
require_once (__DIR__.'/../php-vn-lib/configure.php');
|
||||
|
||||
set_include_path (
|
||||
get_include_path ()
|
||||
.PATH_SEPARATOR.__DIR__.'/lib'
|
||||
);
|
||||
|
||||
define ('_DEVELOPER_MODE', TRUE);
|
||||
define ('_CONFIG_DIR', '/home/juan/.config');
|
||||
define ('_LOG_DIR', '/tmp');
|
||||
|
||||
?>
|
|
@ -0,0 +1,17 @@
|
|||
Copyright (C) 2015 - Juan Ferrer Toribio
|
||||
|
||||
This package 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
On Debian systems, the complete text of the GNU General Public
|
||||
License can be found in "/usr/share/common-licenses/GPL-3".
|
|
@ -0,0 +1,5 @@
|
|||
vn-asterisk (1.001-deb7) stable; urgency=low
|
||||
|
||||
* Initial Release.
|
||||
|
||||
-- Juan Ferrer Toribio <juan@verdnatura.es> Wed, 19 Aug 2015 12:00:00 +0200
|
|
@ -0,0 +1 @@
|
|||
9
|
|
@ -0,0 +1,16 @@
|
|||
Source: vn-asterisk
|
||||
Priority: optional
|
||||
Maintainer: Juan Ferrer Toribio <juan@verdnatura.es>
|
||||
Build-Depends: build-essential, debhelper
|
||||
Standards-Version: 3.9.3
|
||||
Section: misc
|
||||
Homepage: http://www.verdnatura.es
|
||||
Vcs-Git: git://www.verdnatura.es/var/git/vn-asterisk
|
||||
|
||||
Package: vn-asterisk
|
||||
Architecture: all
|
||||
Depends: asterisk, php
|
||||
Section: net
|
||||
Priority: optional
|
||||
Description: Additional files of Verdnatura for Asterisk
|
||||
Contains php scripts, ivr recordings and additional music on hold.
|
|
@ -0,0 +1,24 @@
|
|||
Format: http://dep.debian.net/deps/dep5
|
||||
Name: vn-asterisk
|
||||
Source: git://www.verdnatura.es/var/git/
|
||||
|
||||
Files: *
|
||||
Copyright: 2011-2015 Juan Ferrer Toribio <juan@verdnatura.es>
|
||||
License: GPL-3.0+
|
||||
|
||||
License: GPL-3.0+
|
||||
This package 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
.
|
||||
On Debian systems, the complete text of the GNU General Public
|
||||
License can be found in "/usr/share/common-licenses/GPL-3".
|
|
@ -0,0 +1,3 @@
|
|||
agi-bin/* usr/share/asterisk/agi-bin
|
||||
sounds/* usr/share/asterisk/sounds
|
||||
moh/* usr/share/asterisk/moh
|
|
@ -0,0 +1 @@
|
|||
etc/hedera-web/apache.conf etc/apache2/conf-available/hedera-web.conf
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/bash
|
||||
|
||||
/etc/init.d/asterisk reload
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/bash
|
||||
|
||||
/etc/init.d/asterisk reload
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
#!/usr/bin/make -f
|
||||
|
||||
%:
|
||||
dh $@
|
||||
|
|
@ -0,0 +1,125 @@
|
|||
[general]
|
||||
|
||||
static=yes
|
||||
writeprotect=no
|
||||
|
||||
[default]
|
||||
|
||||
exten => s,1,Hangup
|
||||
|
||||
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++ Llamadas salientes
|
||||
|
||||
[outgoing]
|
||||
|
||||
;-------------- Llamadas urgencia
|
||||
|
||||
exten => _091,1,Macro(external,pri,${EXTEN})
|
||||
exten => _112,1,Macro(external,pri,${EXTEN})
|
||||
|
||||
;-------------- Extensiones internas
|
||||
|
||||
exten => _1006,1,Dial(SIP/${EXTEN},14,tT)
|
||||
same => n,GotoIf($["${DIALSTATUS}" != "ANSWER"]?redirect)
|
||||
same => n(redirect),Dial(SIP/1104,,tT)
|
||||
same => n,Hangup
|
||||
|
||||
exten => _XX00,1,Queue(${EXTEN},tT)
|
||||
same => n,Hangup
|
||||
|
||||
exten => _XX98,1,RemoveQueueMember(${EXTEN:0:2}00)
|
||||
same => n,Playback(removed)
|
||||
same => n,Hangup
|
||||
|
||||
exten => _XX99,1,AddQueueMember(${EXTEN:0:2}00)
|
||||
same => n,Playback(added)
|
||||
same => n,Hangup
|
||||
|
||||
exten => _XXXX,1,Dial(SIP/${EXTEN},,tT)
|
||||
same => n,Followme(${EXTEN})
|
||||
same => n,Hangup
|
||||
|
||||
;-------------- Números externos
|
||||
|
||||
exten => _[98][1-9]XXXXXXX,1,Macro(external,pri,${EXTEN})
|
||||
exten => _[67]XXXXXXXX,1,Macro(external,pri,${EXTEN})
|
||||
exten => _900XXXXXX,1,Macro(external,pri,${EXTEN})
|
||||
|
||||
exten => _0034XXXX,1,Goto(internal,0${EXTEN:4},1)
|
||||
exten => _0034X.,1,Goto(internal,${EXTEN:4},1)
|
||||
exten => _0031XXXXXXXXX,1,Macro(external,xtratelecom,${EXTEN})
|
||||
exten => _00X.,1,Macro(external,wcd,${EXTEN})
|
||||
|
||||
exten => _0XXXX,1,Macro(authenticate,pri,${EXTEN:1:4})
|
||||
exten => _X.,1,Macro(authenticate,pri,${EXTEN})
|
||||
|
||||
;-------------- Números invalidos
|
||||
|
||||
exten => i,1,Playback(invalid)
|
||||
same => n,Hangup
|
||||
|
||||
exten => t,1,Playback(invalid)
|
||||
same => n,Hangup
|
||||
|
||||
;-------------- Macros
|
||||
|
||||
[macro-authenticate]
|
||||
|
||||
exten => s,1,Authenticate(7070)
|
||||
same => n,Macro(external,${ARG1},${ARG2})
|
||||
|
||||
[macro-external]
|
||||
|
||||
exten => s,1,Dial(SIP/${ARG1}/${ARG2},,T)
|
||||
same => n,Hangup
|
||||
|
||||
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++ Llamadas entrantes
|
||||
|
||||
[incoming]
|
||||
|
||||
exten => s,1,AGI(incoming.php)
|
||||
same => GotoIf($["${MACRO}" != ""]?macro:ivr)
|
||||
same => n(macro),Macro(${MACRO},${ARG1})
|
||||
same => n,Hangup
|
||||
same => n(ivr),Goto(ivr,s,1)
|
||||
|
||||
exten => _XX00,1,Macro(queue,${EXTEN})
|
||||
exten => _XXXX,1,Macro(exten,${EXTEN})
|
||||
|
||||
[ivr]
|
||||
|
||||
exten => s,1,Answer
|
||||
same => n,BackGround(custom/ivr)
|
||||
same => n,WaitExten(5)
|
||||
|
||||
exten => 1,1,Macro(queue,1500)
|
||||
exten => 2,1,Macro(queue,1100)
|
||||
exten => 3,1,Macro(queue,1400)
|
||||
exten => 4,1,Macro(queue,1500)
|
||||
exten => 5,1,Macro(queue,1500)
|
||||
exten => 6,1,Macro(queue,1000)
|
||||
|
||||
exten => i,1,Playback(invalid)
|
||||
same => n,Goto(ivr,s,1)
|
||||
|
||||
exten => t,1,Playback(invalid)
|
||||
same => n,Goto(ivr,s,1)
|
||||
|
||||
;-------------- Macros
|
||||
|
||||
[macro-queue]
|
||||
|
||||
exten => s,1,Answer
|
||||
same => n,Queue(${ARG1},t,,,60)
|
||||
same => n,Macro(playback,busy)
|
||||
|
||||
[macro-exten]
|
||||
|
||||
exten => s,1,Dial(SIP/${ARG1},60,t)
|
||||
same => n,Followme(${ARG1})
|
||||
same => n,Macro(playback,busy)
|
||||
|
||||
[macro-playback]
|
||||
|
||||
exten => s,1,Playback(custom/${ARG1})
|
||||
same => n,Hangup
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
php5 -d auto_prepend_file=configure.php "$@"
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* Obtains a customer id from a phone number.
|
||||
*
|
||||
* @param v_phone The caller phone number
|
||||
* @return The customer id or %NULL if customer not exists or is inactive
|
||||
**/
|
||||
DROP FUNCTION IF EXISTS pbx.customer_from_phone;
|
||||
DELIMITER $$
|
||||
CREATE FUNCTION pbx.customer_from_phone (v_phone VARCHAR(255))
|
||||
RETURNS INT
|
||||
DETERMINISTIC
|
||||
BEGIN
|
||||
DECLARE v_customer INT DEFAULT NULL;
|
||||
|
||||
SET @phone = v_phone COLLATE 'utf8_unicode_ci';
|
||||
|
||||
-- Searchs a customer associated to the phone number
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.customer;
|
||||
CREATE TEMPORARY TABLE tmp.customer
|
||||
ENGINE = MEMORY
|
||||
SELECT id_cliente customer
|
||||
FROM vn2008.Clientes c
|
||||
WHERE telefono = @phone
|
||||
OR movil = @phone
|
||||
UNION
|
||||
SELECT id_cliente
|
||||
FROM vn2008.Consignatarios
|
||||
WHERE telefono = @phone
|
||||
OR movil = @phone
|
||||
UNION
|
||||
SELECT r.id_cliente
|
||||
FROM vn2008.Relaciones r
|
||||
JOIN vn2008.Contactos c ON r.Id_Contacto = c.Id_Contacto
|
||||
WHERE telefono = @phone
|
||||
OR movil = @phone;
|
||||
|
||||
SELECT t.customer INTO v_customer
|
||||
FROM tmp.customer t
|
||||
JOIN vn2008.Clientes c
|
||||
WHERE c.activo
|
||||
LIMIT 1;
|
||||
|
||||
DROP TEMPORARY TABLE tmp.customer;
|
||||
|
||||
RETURN v_customer;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,43 @@
|
|||
/**
|
||||
* Reformats a phone number
|
||||
*
|
||||
* @param v_phone The phone to format
|
||||
* @return The formated phone or %NULL if bad sintax
|
||||
**/
|
||||
DROP FUNCTION IF EXISTS pbx.phone_format;
|
||||
DELIMITER $$
|
||||
CREATE FUNCTION pbx.phone_format (phone VARCHAR(255))
|
||||
RETURNS VARCHAR(255)
|
||||
DETERMINISTIC
|
||||
BEGIN
|
||||
DECLARE i INT DEFAULT 0;
|
||||
DECLARE chr VARCHAR(1);
|
||||
DECLARE len INT DEFAULT LENGTH(phone);
|
||||
DECLARE newPhone VARCHAR(255) DEFAULT '';
|
||||
|
||||
WHILE i < len
|
||||
DO
|
||||
SET chr = SUBSTR(phone, i+1, 1);
|
||||
|
||||
IF chr REGEXP '^[0-9]$'
|
||||
THEN
|
||||
SET newPhone = CONCAT(newPhone, chr);
|
||||
ELSEIF chr = '+' AND i = 0
|
||||
THEN
|
||||
SET newPhone = CONCAT(newPhone, '00');
|
||||
END IF;
|
||||
|
||||
SET i = i + 1;
|
||||
END WHILE;
|
||||
|
||||
IF newPhone REGEXP '^0+$' OR newPhone = '' THEN
|
||||
RETURN NULL;
|
||||
END IF;
|
||||
|
||||
IF newPhone REGEXP '^0034' THEN
|
||||
SET newPhone = SUBSTR(newPhone, 5);
|
||||
END IF;
|
||||
|
||||
RETURN newPhone;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,24 @@
|
|||
/**
|
||||
* Checks whether a passed phone number has valid sintax
|
||||
*
|
||||
* @param v_phone The phone to check format
|
||||
* @return %TRUE if it's well formated
|
||||
**/
|
||||
DROP PROCEDURE IF EXISTS pbx.phone_is_valid;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE pbx.phone_is_valid (v_phone VARCHAR(255))
|
||||
BEGIN
|
||||
DECLARE v_is_valid BOOLEAN;
|
||||
|
||||
SET v_is_valid = v_phone IS NULL
|
||||
OR (v_phone REGEXP '^[0-9]+$'
|
||||
AND v_phone NOT REGEXP '^0+$'
|
||||
AND v_phone NOT REGEXP '^0034');
|
||||
|
||||
IF NOT v_is_valid
|
||||
THEN
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = 'PHONE_INVALID_FORMAT';
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,42 @@
|
|||
|
||||
-- Updates the bad formated phones
|
||||
|
||||
UPDATE vn2008.Clientes
|
||||
SET telefono = pbx.phone_format (telefono),
|
||||
fax = pbx.phone_format (fax),
|
||||
movil = pbx.phone_format (movil);
|
||||
|
||||
UPDATE vn2008.Consignatarios
|
||||
SET telefono = pbx.phone_format (telefono),
|
||||
movil = pbx.phone_format (movil);
|
||||
|
||||
UPDATE vn2008.Contactos
|
||||
SET telefono = pbx.phone_format (telefono),
|
||||
fax = pbx.phone_format (fax),
|
||||
movil = pbx.phone_format (movil);
|
||||
|
||||
-- Indexes the phone columns
|
||||
|
||||
ALTER TABLE vn2008.`Clientes` ADD INDEX(`Telefono`);
|
||||
ALTER TABLE vn2008.`Clientes` ADD INDEX(`movil`);
|
||||
|
||||
ALTER TABLE vn2008.`Consignatarios` ADD INDEX(`telefono`);
|
||||
ALTER TABLE vn2008.`Consignatarios` ADD INDEX(`movil`);
|
||||
|
||||
ALTER TABLE vn2008.`Contactos` ADD INDEX(`Telefono`);
|
||||
ALTER TABLE vn2008.`Contactos` ADD INDEX(`Movil`);
|
||||
|
||||
-- Returns all bad formated phones
|
||||
|
||||
SELECT telefono, movil c FROM vn2008.Clientes
|
||||
WHERE telefono NOT REGEXP '^[0-9]+$'
|
||||
OR movil NOT REGEXP '^[0-9]+$'
|
||||
UNION
|
||||
SELECT telefono, movil FROM vn2008.Consignatarios
|
||||
WHERE telefono NOT REGEXP '^[0-9]+$'
|
||||
OR movil NOT REGEXP '^[0-9]+$'
|
||||
UNION
|
||||
SELECT telefono, movil FROM vn2008.Contactos
|
||||
WHERE telefono NOT REGEXP '^[0-9]+$'
|
||||
OR movil NOT REGEXP '^[0-9]+$';
|
||||
|
Loading…
Reference in New Issue