dolibarr 22.0.5
wrapper.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2009-2010 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
32if (!defined('NOREQUIRESOC')) {
33 define('NOREQUIRESOC', '1');
34}
35if (!defined('NOREQUIRETRAN')) {
36 define('NOREQUIRETRAN', '1');
37}
38if (!defined('NOTOKENRENEWAL')) {
39 define('NOTOKENRENEWAL', '1');
40}
41if (!defined('NOREQUIREMENU')) {
42 define('NOREQUIREMENU', '1');
43}
44if (!defined('NOREQUIREHTML')) {
45 define('NOREQUIREHTML', '1');
46}
47if (!defined('NOREQUIREAJAX')) {
48 define('NOREQUIREAJAX', '1');
49}
50
73function llxHeader($head = '', $title = '', $help_url = '', $target = '', $disablejs = 0, $disablehead = 0, $arrayofjs = '', $arrayofcss = '', $morequerystring = '', $morecssonbody = '', $replacemainareaby = '', $disablenofollow = 0, $disablenoindex = 0) // @phan-suppress-current-line PhanRedefineFunction
74{
75 print '<html>'."\n";
76 print '<head>'."\n";
77 print '<title>Asterisk redirection from Dolibarr...</title>'."\n";
78 print '</head>'."\n";
79}
80
91function llxFooter($comment = '', $zone = 'private', $disabledoutputofmessages = 0) // @phan-suppress-current-line PhanRedefineFunction
92{
93 print "\n".'</html>'."\n";
94}
95
96require_once '../main.inc.php';
97require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
98require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
99
108// Security check
109if (!isModEnabled('clicktodial')) {
111}
112
113
114// Define Asterisk setup
115if (!getDolGlobalString('ASTERISK_HOST')) {
116 $conf->global->ASTERISK_HOST = "127.0.0.1";
117}
118if (!getDolGlobalString('ASTERISK_TYPE')) {
119 $conf->global->ASTERISK_TYPE = "SIP/";
120}
121if (!getDolGlobalString('ASTERISK_INDICATIF')) {
122 $conf->global->ASTERISK_INDICATIF = "0";
123}
124if (!getDolGlobalString('ASTERISK_PORT')) {
125 $conf->global->ASTERISK_PORT = 5038;
126}
127if (getDolGlobalString('ASTERISK_INDICATIF') == 'NONE') {
128 $conf->global->ASTERISK_INDICATIF = '';
129}
130if (!getDolGlobalString('ASTERISK_CONTEXT')) {
131 $conf->global->ASTERISK_CONTEXT = "from-internal";
132}
133if (!getDolGlobalString('ASTERISK_WAIT_TIME')) {
134 $conf->global->ASTERISK_WAIT_TIME = "30";
135}
136if (!getDolGlobalString('ASTERISK_PRIORITY')) {
137 $conf->global->ASTERISK_PRIORITY = "1";
138}
139if (!getDolGlobalString('ASTERISK_MAX_RETRY')) {
140 $conf->global->ASTERISK_MAX_RETRY = "2";
141}
142
143
144$login = GETPOST('login', 'alphanohtml');
145$password = GETPOST('password', 'password');
146$caller = GETPOST('caller', 'alphanohtml');
147$called = GETPOST('called', 'alphanohtml');
148
149// Sanitize input data to avoid to use the wrapper to inject malicious paylod into asterisk
150$login = preg_replace('/[\n\r]/', '', $login);
151$password = preg_replace('/[\n\r]/', '', $password);
152$caller = preg_replace('/[\n\r]/', '', $caller);
153$called = preg_replace('/[\n\r]/', '', $called);
154
155// IP address of Asterisk server
156$strHost = getDolGlobalString('ASTERISK_HOST');
157
158// Specify the type of extension through which your extension is connected.
159// ex: SIP/, IAX2/, ZAP/, etc
160$channel = getDolGlobalString('ASTERISK_TYPE');
161
162// Outgoing call sign
163$prefix = getDolGlobalString('ASTERISK_INDICATIF');
164
165// Asterisk Port
166$port = getDolGlobalString('ASTERISK_PORT');
167
168// Context ( generalement from-internal )
169$strContext = getDolGlobalString('ASTERISK_CONTEXT');
170
171// Waiting time before hanging up
172$strWaitTime = getDolGlobalString('ASTERISK_WAIT_TIME');
173
174// Priority
175$strPriority = getDolGlobalString('ASTERISK_PRIORITY');
176
177// Number of call attempts
178$strMaxRetry = getDolGlobalString('ASTERISK_MAX_RETRY');
179
180
181/*
182 * View
183 */
184
185llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-asterisk page-wrapper');
186
187$sql = "SELECT s.nom as name FROM ".MAIN_DB_PREFIX."societe as s";
188$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON sp.fk_soc = s.rowid";
189$sql .= " WHERE s.entity IN (".getEntity('societe').")";
190$sql .= " AND (s.phone='".$db->escape($called)."'";
191$sql .= " OR sp.phone='".$db->escape($called)."'";
192$sql .= " OR sp.phone_perso='".$db->escape($called)."'";
193$sql .= " OR sp.phone_mobile='".$db->escape($called)."')";
194$sql .= $db->plimit(1);
195
196dol_syslog('click to dial search information with phone '.$called, LOG_DEBUG);
197$resql = $db->query($sql);
198if ($resql) {
199 $obj = $db->fetch_object($resql);
200 if ($obj) {
201 $found = $obj->name;
202 } else {
203 $found = 'Not found';
204 }
205 $db->free($resql);
206} else {
207 dol_print_error($db, 'Error');
208 $found = 'Error';
209}
210
211$number = strtolower($called);
212$pos = strpos($number, "local");
213if (!empty($number)) {
214 if ($pos === false) {
215 $errno = 0;
216 $errstr = 0;
217 $strCallerId = "Dolibarr caller $found <".strtolower($number).">";
218 $oSocket = @fsockopen($strHost, (int) $port, $errno, $errstr, 10);
219 if (!$oSocket) {
220 print '<body>'."\n";
221 $txt = "Failed to execute fsockopen($strHost, $port, \$errno, \$errstr, 10)<br>\n";
222 print $txt;
223 dol_syslog($txt, LOG_ERR);
224 $txt = $errstr." (".$errno.")<br>\n";
225 print $txt;
226 dol_syslog($txt, LOG_ERR);
227 print '</body>'."\n";
228 } else {
229 $txt = "Call Asterisk dialer for caller: ".$caller.", called: ".$called." clicktodiallogin: ".$login;
230 dol_syslog($txt);
231 print '<body onload="history.go(-1);">'."\n";
232 print '<!-- '.$txt.' -->';
233 fwrite($oSocket, "Action: login\r\n");
234 fwrite($oSocket, "Events: off\r\n");
235 fwrite($oSocket, "Username: $login\r\n");
236 fwrite($oSocket, "Secret: $password\r\n\r\n");
237 fwrite($oSocket, "Action: originate\r\n");
238 fwrite($oSocket, "Channel: ".$channel.$caller."\r\n");
239 fwrite($oSocket, "WaitTime: $strWaitTime\r\n");
240 fwrite($oSocket, "CallerId: $strCallerId\r\n");
241 fwrite($oSocket, "Exten: ".$prefix.$number."\r\n");
242 fwrite($oSocket, "Context: $strContext\r\n");
243 fwrite($oSocket, "Priority: $strPriority\r\n\r\n");
244 fwrite($oSocket, "Action: Logoff\r\n\r\n");
245 sleep(2);
246 fclose($oSocket);
247 print '</body>'."\n";
248 }
249 }
250} else {
251 print 'Bad parameters in URL. Must be '.dol_escape_htmltag($_SERVER['PHP_SELF']).'?caller=99999&called=99999&login=xxxxx&password=xxxxx';
252}
253
254// End of page
255llxFooter();
256$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
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 a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.