--- /tmp/dsg/dolibarr/htdocs/asterisk/github_19.0.3_cidlookup.php +++ /tmp/dsg/dolibarr/htdocs/asterisk/client_cidlookup.php @@ -0,0 +1,81 @@ + + * + * This program 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 . + */ + +/** + * \file htdocs/asterisk/cidlookup.php + * \brief Script to search companies names based on incoming calls, from caller phone number + * \remarks To use this script, your Asterisk must be compiled with CURL, + * and your dialplan must be something like this: + * + * exten => s,1,Set(CALLERID(name)=${CURL(http://IP-DOLIBARR:80/asterisk/cidlookup.php?phone=${CALLERID(num)})}) + * + * Change IP-DOLIBARR to the IP address of your dolibarr server + */ + + +include '../master.inc.php'; + +$phone = GETPOST('phone'); +$notfound = $langs->trans("Unknown"); + +// Security check +if (empty($conf->clicktodial->enabled)) +{ + print "Error: Module Click to dial is not enabled.\n"; + exit; +} + +// Check parameters +if (empty($phone)) +{ + print "Error: Url must be called with parameter phone=phone to search\n"; + exit; +} + +$sql = "SELECT s.nom as name FROM ".MAIN_DB_PREFIX."societe as s"; +$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON sp.fk_soc = s.rowid"; +$sql .= " WHERE s.entity IN (".getEntity('societe').")"; +$sql .= " AND (s.phone='".$db->escape($phone)."'"; +$sql .= " OR sp.phone='".$db->escape($phone)."'"; +$sql .= " OR sp.phone_perso='".$db->escape($phone)."'"; +$sql .= " OR sp.phone_mobile='".$db->escape($phone)."')"; +$sql .= $db->plimit(1); + +dol_syslog('cidlookup search information with phone '.$phone, LOG_DEBUG); +$resql = $db->query($sql); +if ($resql) +{ + $obj = $db->fetch_object($resql); + if ($obj) + { + $found = $obj->name; + } else { + $found = $notfound; + } + $db->free($resql); +} +else +{ + dol_print_error($db, 'Error'); + $found = 'Error'; +} +//Greek to Latin +$greek = array('α', 'β', 'γ', 'δ', 'ε', 'ζ', 'η', 'θ', 'ι', 'κ', 'λ', 'μ', 'ν', 'ξ', 'ο', 'π', 'ρ', 'ς', 'σ', 'τ', 'υ', 'φ', 'χ', 'ψ', 'ω', 'Α', 'Β', 'Γ', 'Δ', 'Ε', 'Ζ', 'Η', 'Θ', 'Ι', 'Κ', 'Λ', 'Μ', 'Ν', 'Ξ', 'Ο', 'Π', 'Ρ', 'Σ', 'Τ', 'Υ', 'Φ', 'Χ', 'Ψ', 'Ω', 'ά', 'έ', 'ή', 'ί', 'ό', 'ύ', 'ώ', 'ϊ', 'ΐ', 'Ά', 'Έ', 'Ή', 'Ί', 'Ό', 'Ύ', 'Ώ', 'Ϊ'); + +$latin = array('a', 'b', 'g', 'd', 'e', 'z', 'h', 'th', 'i', 'k', 'l', 'm', 'n', 'ks', 'o', 'p', 'r', 's', 's', 't', 'u', 'f', 'ch', 'ps', 'w', 'A', 'B', 'G', 'D', 'E', 'Z', 'H', 'TH', 'I', 'K', 'L', 'M', 'N', 'KS', 'O', 'P', 'R', 'S', 'T', 'U', 'F', 'CH', 'PS', 'W', 'a', 'e', 'h', 'i', 'o', 'u', 'w', 'i', 'i', 'A', 'E', 'H', 'I', 'O', 'U', 'W', 'I'); + +print str_replace($greek, $latin, $found); --- /tmp/dsg/dolibarr/htdocs/asterisk/github_19.0.3_wrapper.php +++ /tmp/dsg/dolibarr/htdocs/asterisk/client_wrapper.php @@ -21 +21,2 @@ - * \remarks To be used, an Asterisk user must be created by adding this in /etc/asterisk/manager.conf + * \remarks To be used, an Asterisk user must be created by adding this + * in /etc/asterisk/manager.conf @@ -30,18 +31,7 @@ -if (!defined('NOREQUIRESOC')) { - define('NOREQUIRESOC', '1'); -} -if (!defined('NOREQUIRETRAN')) { - define('NOREQUIRETRAN', '1'); -} -if (!defined('NOTOKENRENEWAL')) { - define('NOTOKENRENEWAL', '1'); -} -if (!defined('NOREQUIREMENU')) { - define('NOREQUIREMENU', '1'); -} -if (!defined('NOREQUIREHTML')) { - define('NOREQUIREHTML', '1'); -} -if (!defined('NOREQUIREAJAX')) { - define('NOREQUIREAJAX', '1'); -} +if (!defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); +if (!defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); +if (!defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); +if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); +if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); +if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); +if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); @@ -57,4 +47,4 @@ - print ''."\n"; - print ''."\n"; - print 'Asterisk redirection from Dolibarr...'."\n"; - print ''."\n"; + print ''."\n"; + print ''."\n"; + print 'Asterisk redirection from Dolibarr...'."\n"; + print ''."\n"; @@ -71 +61 @@ - print "\n".''."\n"; + print "\n".''."\n"; @@ -80,3 +70,4 @@ -if (empty($conf->clicktodial->enabled)) { - accessforbidden(); - exit; +if (empty($conf->clicktodial->enabled)) +{ + accessforbidden(); + exit; @@ -87,27 +78,9 @@ -if (!isset($conf->global->ASTERISK_HOST)) { - $conf->global->ASTERISK_HOST = "127.0.0.1"; -} -if (!isset($conf->global->ASTERISK_TYPE)) { - $conf->global->ASTERISK_TYPE = "SIP/"; -} -if (!isset($conf->global->ASTERISK_INDICATIF)) { - $conf->global->ASTERISK_INDICATIF = "0"; -} -if (!isset($conf->global->ASTERISK_PORT)) { - $conf->global->ASTERISK_PORT = 5038; -} -if (getDolGlobalString('ASTERISK_INDICATIF') == 'NONE') { - $conf->global->ASTERISK_INDICATIF = ''; -} -if (!isset($conf->global->ASTERISK_CONTEXT)) { - $conf->global->ASTERISK_CONTEXT = "from-internal"; -} -if (!isset($conf->global->ASTERISK_WAIT_TIME)) { - $conf->global->ASTERISK_WAIT_TIME = "30"; -} -if (!isset($conf->global->ASTERISK_PRIORITY)) { - $conf->global->ASTERISK_PRIORITY = "1"; -} -if (!isset($conf->global->ASTERISK_MAX_RETRY)) { - $conf->global->ASTERISK_MAX_RETRY = "2"; -} +if (!isset($conf->global->ASTERISK_HOST)) $conf->global->ASTERISK_HOST = "127.0.0.1"; +if (!isset($conf->global->ASTERISK_TYPE)) $conf->global->ASTERISK_TYPE = "SIP/"; +if (!isset($conf->global->ASTERISK_INDICATIF)) $conf->global->ASTERISK_INDICATIF = "0"; +if (!isset($conf->global->ASTERISK_PORT)) $conf->global->ASTERISK_PORT = 5038; +if ($conf->global->ASTERISK_INDICATIF == 'NONE') $conf->global->ASTERISK_INDICATIF = ''; +if (!isset($conf->global->ASTERISK_CONTEXT)) $conf->global->ASTERISK_CONTEXT = "from-internal"; +if (!isset($conf->global->ASTERISK_WAIT_TIME)) $conf->global->ASTERISK_WAIT_TIME = "30"; +if (!isset($conf->global->ASTERISK_PRIORITY)) $conf->global->ASTERISK_PRIORITY = "1"; +if (!isset($conf->global->ASTERISK_MAX_RETRY)) $conf->global->ASTERISK_MAX_RETRY = "2"; @@ -116,4 +89,4 @@ -$login = GETPOST('login', 'alphanohtml'); -$password = GETPOST('password', 'none'); -$caller = GETPOST('caller', 'alphanohtml'); -$called = GETPOST('called', 'alphanohtml'); +$login = GETPOST('login'); +$password = GETPOST('password'); +$caller = GETPOST('caller'); +$called = GETPOST('called'); @@ -123,2 +96 @@ - -// Specify the type of extension through which your extension is connected. +// Spécifiez le type d'extension par laquelle vous poste est connecte. @@ -127,2 +99 @@ - -// Outgoing call sign +// Indicatif de la ligne sortante @@ -130,2 +101 @@ - -// Asterisk Port +// Port @@ -133 +102,0 @@ - @@ -136,2 +105 @@ - -// Waiting time before hanging up +// Delai d'attente avant de raccrocher @@ -139 +106,0 @@ - @@ -142,2 +109 @@ - -// Number of call attempts +// Nomber of try @@ -164 +130,2 @@ -if ($resql) { +if ($resql) +{ @@ -166 +133,2 @@ - if ($obj) { + if ($obj) + { @@ -169 +137 @@ - $found = 'Not found'; + $found = $notfound; @@ -172 +140,3 @@ -} else { +} +else +{ @@ -179,39 +149,45 @@ -if (!empty($number)) { - if ($pos === false) { - $errno = 0; - $errstr = 0; - $strCallerId = "Dolibarr caller $found <".strtolower($number).">"; - $oSocket = @fsockopen($strHost, $port, $errno, $errstr, 10); - if (!$oSocket) { - print ''."\n"; - $txt = "Failed to execute fsockopen($strHost, $port, \$errno, \$errstr, 10)
\n"; - print $txt; - dol_syslog($txt, LOG_ERR); - $txt = $errstr." (".$errno.")
\n"; - print $txt; - dol_syslog($txt, LOG_ERR); - print ''."\n"; - } else { - $txt = "Call Asterisk dialer for caller: ".$caller.", called: ".$called." clicktodiallogin: ".$login; - dol_syslog($txt); - print ''."\n"; - print ''; - fputs($oSocket, "Action: login\r\n"); - fputs($oSocket, "Events: off\r\n"); - fputs($oSocket, "Username: $login\r\n"); - fputs($oSocket, "Secret: $password\r\n\r\n"); - fputs($oSocket, "Action: originate\r\n"); - fputs($oSocket, "Channel: ".$channel.$caller."\r\n"); - fputs($oSocket, "WaitTime: $strWaitTime\r\n"); - fputs($oSocket, "CallerId: $strCallerId\r\n"); - fputs($oSocket, "Exten: ".$prefix.$number."\r\n"); - fputs($oSocket, "Context: $strContext\r\n"); - fputs($oSocket, "Priority: $strPriority\r\n\r\n"); - fputs($oSocket, "Action: Logoff\r\n\r\n"); - sleep(2); - fclose($oSocket); - print ''."\n"; - } - } -} else { - print 'Bad parameters in URL. Must be '.dol_escape_htmltag($_SERVER['PHP_SELF']).'?caller=99999&called=99999&login=xxxxx&password=xxxxx'; +if (!empty($number)) +{ + if ($pos === false) + { + $errno = 0; + $errstr = 0; + $strCallerId = "Dolibarr call $found <".strtolower($number).">"; + $oSocket = @fsockopen($strHost, $port, $errno, $errstr, 10); + if (!$oSocket) + { + print ''."\n"; + $txt = "Failed to execute fsockopen($strHost, $port, \$errno, \$errstr, 10)
\n"; + print $txt; + dol_syslog($txt, LOG_ERR); + $txt = $errstr." (".$errno.")
\n"; + print $txt; + dol_syslog($txt, LOG_ERR); + print ''."\n"; + } + else + { + $txt = "Call Asterisk dialer for caller: ".$caller.", called: ".$called." clicktodiallogin: ".$login; + dol_syslog($txt); + print ''."\n"; + print ''; + fputs($oSocket, "Action: login\r\n"); + fputs($oSocket, "Events: off\r\n"); + fputs($oSocket, "Username: $login\r\n"); + fputs($oSocket, "Secret: $password\r\n\r\n"); + fputs($oSocket, "Action: originate\r\n"); + fputs($oSocket, "Channel: ".$channel.$caller."\r\n"); + fputs($oSocket, "WaitTime: $strWaitTime\r\n"); + fputs($oSocket, "CallerId: $strCallerId\r\n"); + fputs($oSocket, "Exten: ".$prefix.$number."\r\n"); + fputs($oSocket, "Context: $strContext\r\n"); + fputs($oSocket, "Priority: $strPriority\r\n\r\n"); + fputs($oSocket, "Action: Logoff\r\n\r\n"); + sleep(2); + fclose($oSocket); + print ''."\n"; + } + } +} +else { + print 'Bad parameters in URL. Must be '.$_SERVER['PHP_SELF'].'?caller=99999&called=99999&login=xxxxx&password=xxxxx';