dolibarr 19.0.4
wrapper.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2009-2010 Laurent Destailleur <eldy@users.sourceforge.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
30if (!defined('NOREQUIRESOC')) {
31 define('NOREQUIRESOC', '1');
32}
33if (!defined('NOREQUIRETRAN')) {
34 define('NOREQUIRETRAN', '1');
35}
36if (!defined('NOTOKENRENEWAL')) {
37 define('NOTOKENRENEWAL', '1');
38}
39if (!defined('NOREQUIREMENU')) {
40 define('NOREQUIREMENU', '1');
41}
42if (!defined('NOREQUIREHTML')) {
43 define('NOREQUIREHTML', '1');
44}
45if (!defined('NOREQUIREAJAX')) {
46 define('NOREQUIREAJAX', '1');
47}
48
55function llxHeader()
56{
57 print '<html>'."\n";
58 print '<head>'."\n";
59 print '<title>Asterisk redirection from Dolibarr...</title>'."\n";
60 print '</head>'."\n";
61}
62
69function llxFooter()
70{
71 print "\n".'</html>'."\n";
72}
73
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';
77
78
79// Security check
80if (empty($conf->clicktodial->enabled)) {
82 exit;
83}
84
85
86// Define Asterisk setup
87if (!isset($conf->global->ASTERISK_HOST)) {
88 $conf->global->ASTERISK_HOST = "127.0.0.1";
89}
90if (!isset($conf->global->ASTERISK_TYPE)) {
91 $conf->global->ASTERISK_TYPE = "SIP/";
92}
93if (!isset($conf->global->ASTERISK_INDICATIF)) {
94 $conf->global->ASTERISK_INDICATIF = "0";
95}
96if (!isset($conf->global->ASTERISK_PORT)) {
97 $conf->global->ASTERISK_PORT = 5038;
98}
99if (getDolGlobalString('ASTERISK_INDICATIF') == 'NONE') {
100 $conf->global->ASTERISK_INDICATIF = '';
101}
102if (!isset($conf->global->ASTERISK_CONTEXT)) {
103 $conf->global->ASTERISK_CONTEXT = "from-internal";
104}
105if (!isset($conf->global->ASTERISK_WAIT_TIME)) {
106 $conf->global->ASTERISK_WAIT_TIME = "30";
107}
108if (!isset($conf->global->ASTERISK_PRIORITY)) {
109 $conf->global->ASTERISK_PRIORITY = "1";
110}
111if (!isset($conf->global->ASTERISK_MAX_RETRY)) {
112 $conf->global->ASTERISK_MAX_RETRY = "2";
113}
114
115
116$login = GETPOST('login', 'alphanohtml');
117$password = GETPOST('password', 'none');
118$caller = GETPOST('caller', 'alphanohtml');
119$called = GETPOST('called', 'alphanohtml');
120
121// IP address of Asterisk server
122$strHost = $conf->global->ASTERISK_HOST;
123
124// Specify the type of extension through which your extension is connected.
125// ex: SIP/, IAX2/, ZAP/, etc
126$channel = $conf->global->ASTERISK_TYPE;
127
128// Outgoing call sign
129$prefix = $conf->global->ASTERISK_INDICATIF;
130
131// Asterisk Port
132$port = $conf->global->ASTERISK_PORT;
133
134// Context ( generalement from-internal )
135$strContext = $conf->global->ASTERISK_CONTEXT;
136
137// Waiting time before hanging up
138$strWaitTime = $conf->global->ASTERISK_WAIT_TIME;
139
140// Priority
141$strPriority = $conf->global->ASTERISK_PRIORITY;
142
143// Number of call attempts
144$strMaxRetry = $conf->global->ASTERISK_MAX_RETRY;
145
146
147/*
148 * View
149 */
150
151llxHeader();
152
153$sql = "SELECT s.nom as name FROM ".MAIN_DB_PREFIX."societe as s";
154$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON sp.fk_soc = s.rowid";
155$sql .= " WHERE s.entity IN (".getEntity('societe').")";
156$sql .= " AND (s.phone='".$db->escape($called)."'";
157$sql .= " OR sp.phone='".$db->escape($called)."'";
158$sql .= " OR sp.phone_perso='".$db->escape($called)."'";
159$sql .= " OR sp.phone_mobile='".$db->escape($called)."')";
160$sql .= $db->plimit(1);
161
162dol_syslog('click to dial search information with phone '.$called, LOG_DEBUG);
163$resql = $db->query($sql);
164if ($resql) {
165 $obj = $db->fetch_object($resql);
166 if ($obj) {
167 $found = $obj->name;
168 } else {
169 $found = 'Not found';
170 }
171 $db->free($resql);
172} else {
173 dol_print_error($db, 'Error');
174 $found = 'Error';
175}
176
177$number = strtolower($called);
178$pos = strpos($number, "local");
179if (!empty($number)) {
180 if ($pos === false) {
181 $errno = 0;
182 $errstr = 0;
183 $strCallerId = "Dolibarr caller $found <".strtolower($number).">";
184 $oSocket = @fsockopen($strHost, $port, $errno, $errstr, 10);
185 if (!$oSocket) {
186 print '<body>'."\n";
187 $txt = "Failed to execute fsockopen($strHost, $port, \$errno, \$errstr, 10)<br>\n";
188 print $txt;
189 dol_syslog($txt, LOG_ERR);
190 $txt = $errstr." (".$errno.")<br>\n";
191 print $txt;
192 dol_syslog($txt, LOG_ERR);
193 print '</body>'."\n";
194 } else {
195 $txt = "Call Asterisk dialer for caller: ".$caller.", called: ".$called." clicktodiallogin: ".$login;
196 dol_syslog($txt);
197 print '<body onload="history.go(-1);">'."\n";
198 print '<!-- '.$txt.' -->';
199 fputs($oSocket, "Action: login\r\n");
200 fputs($oSocket, "Events: off\r\n");
201 fputs($oSocket, "Username: $login\r\n");
202 fputs($oSocket, "Secret: $password\r\n\r\n");
203 fputs($oSocket, "Action: originate\r\n");
204 fputs($oSocket, "Channel: ".$channel.$caller."\r\n");
205 fputs($oSocket, "WaitTime: $strWaitTime\r\n");
206 fputs($oSocket, "CallerId: $strCallerId\r\n");
207 fputs($oSocket, "Exten: ".$prefix.$number."\r\n");
208 fputs($oSocket, "Context: $strContext\r\n");
209 fputs($oSocket, "Priority: $strPriority\r\n\r\n");
210 fputs($oSocket, "Action: Logoff\r\n\r\n");
211 sleep(2);
212 fclose($oSocket);
213 print '</body>'."\n";
214 }
215 }
216} else {
217 print 'Bad parameters in URL. Must be '.dol_escape_htmltag($_SERVER['PHP_SELF']).'?caller=99999&called=99999&login=xxxxx&password=xxxxx';
218}
219
220// End of page
221llxFooter();
222$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.