30if (!defined(
'NOREQUIRESOC')) {
31 define(
'NOREQUIRESOC',
'1');
33if (!defined(
'NOREQUIRETRAN')) {
34 define(
'NOREQUIRETRAN',
'1');
36if (!defined(
'NOTOKENRENEWAL')) {
37 define(
'NOTOKENRENEWAL',
'1');
39if (!defined(
'NOREQUIREMENU')) {
40 define(
'NOREQUIREMENU',
'1');
42if (!defined(
'NOREQUIREHTML')) {
43 define(
'NOREQUIREHTML',
'1');
45if (!defined(
'NOREQUIREAJAX')) {
46 define(
'NOREQUIREAJAX',
'1');
59 print
'<title>Asterisk redirection from Dolibarr...</title>'.
"\n";
71 print
"\n".
'</html>'.
"\n";
74require_once
'../main.inc.php';
75require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions.lib.php';
76require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
80if (!isModEnabled(
'clicktodial')) {
88 $conf->global->ASTERISK_HOST =
"127.0.0.1";
91 $conf->global->ASTERISK_TYPE =
"SIP/";
94 $conf->global->ASTERISK_INDICATIF =
"0";
97 $conf->global->ASTERISK_PORT = 5038;
100 $conf->global->ASTERISK_INDICATIF =
'';
103 $conf->global->ASTERISK_CONTEXT =
"from-internal";
106 $conf->global->ASTERISK_WAIT_TIME =
"30";
109 $conf->global->ASTERISK_PRIORITY =
"1";
112 $conf->global->ASTERISK_MAX_RETRY =
"2";
116$login =
GETPOST(
'login',
'alphanohtml');
117$password =
GETPOST(
'password',
'none');
118$caller =
GETPOST(
'caller',
'alphanohtml');
119$called =
GETPOST(
'called',
'alphanohtml');
122$login = preg_replace(
'/[\n\r]/',
'', $login);
123$password = preg_replace(
'/[\n\r]/',
'', $password);
124$caller = preg_replace(
'/[\n\r]/',
'', $caller);
125$called = preg_replace(
'/[\n\r]/',
'', $called);
159$sql =
"SELECT s.nom as name FROM ".MAIN_DB_PREFIX.
"societe as s";
160$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"socpeople as sp ON sp.fk_soc = s.rowid";
161$sql .=
" WHERE s.entity IN (".getEntity(
'societe').
")";
162$sql .=
" AND (s.phone='".$db->escape($called).
"'";
163$sql .=
" OR sp.phone='".$db->escape($called).
"'";
164$sql .=
" OR sp.phone_perso='".$db->escape($called).
"'";
165$sql .=
" OR sp.phone_mobile='".$db->escape($called).
"')";
166$sql .= $db->plimit(1);
168dol_syslog(
'click to dial search information with phone '.$called, LOG_DEBUG);
169$resql = $db->query($sql);
171 $obj = $db->fetch_object($resql);
175 $found =
'Not found';
183$number = strtolower($called);
184$pos = strpos($number,
"local");
185if (!empty($number)) {
186 if ($pos ===
false) {
189 $strCallerId =
"Dolibarr caller $found <".strtolower($number).
">";
190 $oSocket = @fsockopen($strHost, (
int) $port, $errno, $errstr, 10);
193 $txt =
"Failed to execute fsockopen($strHost, $port, \$errno, \$errstr, 10)<br>\n";
196 $txt = $errstr.
" (".$errno.
")<br>\n";
199 print
'</body>'.
"\n";
201 $txt =
"Call Asterisk dialer for caller: ".$caller.
", called: ".$called.
" clicktodiallogin: ".$login;
203 print
'<body onload="history.go(-1);">'.
"\n";
204 print
'<!-- '.$txt.
' -->';
205 fwrite($oSocket,
"Action: login\r\n");
206 fwrite($oSocket,
"Events: off\r\n");
207 fwrite($oSocket,
"Username: $login\r\n");
208 fwrite($oSocket,
"Secret: $password\r\n\r\n");
209 fwrite($oSocket,
"Action: originate\r\n");
210 fwrite($oSocket,
"Channel: ".$channel.$caller.
"\r\n");
211 fwrite($oSocket,
"WaitTime: $strWaitTime\r\n");
212 fwrite($oSocket,
"CallerId: $strCallerId\r\n");
213 fwrite($oSocket,
"Exten: ".$prefix.$number.
"\r\n");
214 fwrite($oSocket,
"Context: $strContext\r\n");
215 fwrite($oSocket,
"Priority: $strPriority\r\n\r\n");
216 fwrite($oSocket,
"Action: Logoff\r\n\r\n");
219 print
'</body>'.
"\n";
223 print
'Bad parameters in URL. Must be '.dol_escape_htmltag($_SERVER[
'PHP_SELF']).
'?caller=99999&called=99999&login=xxxxx&password=xxxxx';
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.