dolibarr 25.0.0-alpha
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-2025 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';
104require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
105
106// Security check
107if (!isModEnabled('clicktodial')) {
109}
110
111
112// Define Asterisk setup
113if (getDolGlobalString('ASTERISK_INDICATIF') == 'NONE') {
114 $conf->global->ASTERISK_INDICATIF = '';
115}
116
117$login = GETPOST('login', 'alphanohtml');
118$password = GETPOST('password', 'password');
119$caller = GETPOST('caller', 'alphanohtml');
120$called = GETPOST('called', 'alphanohtml');
121
122// Sanitize input data to avoid to use the wrapper to inject malicious paylod into asterisk
123$login = preg_replace('/[\n\r]/', '', $login);
124$password = preg_replace('/[\n\r]/', '', $password);
125$caller = preg_replace('/[\n\r]/', '', $caller);
126$called = preg_replace('/[\n\r]/', '', $called);
127
128// IP address of Asterisk server
129$strHost = getDolGlobalString('ASTERISK_HOST', '127.0.0.1');
130
131// Specify the type of extension through which your extension is connected.
132// ex: SIP/, IAX2/, ZAP/, etc
133$channel = getDolGlobalString('ASTERISK_TYPE', 'SIP/');
134
135// Outgoing call sign
136$prefix = getDolGlobalString('ASTERISK_INDICATIF', '0');
137
138// Asterisk Port
139$port = getDolGlobalInt('ASTERISK_PORT', 5038);
140
141// Context ( generalement from-internal )
142$strContext = getDolGlobalString('ASTERISK_CONTEXT', 'from-internal');
143
144// Waiting time before hanging up
145$strWaitTime = getDolGlobalString('ASTERISK_WAIT_TIME', '30');
146
147// Priority
148$strPriority = getDolGlobalString('ASTERISK_PRIORITY', '1');
149
150// Number of call attempts
151$strMaxRetry = getDolGlobalString('ASTERISK_MAX_RETRY', "2");
152
153
154/*
155 * View
156 */
157
158llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-asterisk page-wrapper');
159
160$sql = "SELECT s.nom as name FROM ".MAIN_DB_PREFIX."societe as s";
161$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON sp.fk_soc = s.rowid";
162$sql .= " WHERE s.entity IN (".getEntity('societe').")";
163$sql .= " AND (s.phone='".$db->escape($called)."'";
164$sql .= " OR sp.phone='".$db->escape($called)."'";
165$sql .= " OR sp.phone_perso='".$db->escape($called)."'";
166$sql .= " OR sp.phone_mobile='".$db->escape($called)."')";
167$sql .= $db->plimit(1);
168
169dol_syslog('click to dial search information with phone '.$called, LOG_DEBUG);
170$resql = $db->query($sql);
171if ($resql) {
172 $obj = $db->fetch_object($resql);
173 if ($obj) {
174 $found = $obj->name;
175 } else {
176 $found = 'Not found';
177 }
178 $db->free($resql);
179} else {
180 dol_print_error($db, 'Error');
181 $found = 'Error';
182}
183
184$number = strtolower($called);
185$pos = strpos($number, "local");
186if (!empty($number)) {
187 if ($pos === false) {
188 $errno = 0;
189 $errstr = 0;
190 $strCallerId = "Dolibarr caller $found <".strtolower($number).">";
191 $oSocket = @fsockopen($strHost, (int) $port, $errno, $errstr, 10);
192 if (!$oSocket) {
193 print '<body>'."\n";
194 $txt = "Failed to execute fsockopen($strHost, $port, \$errno, \$errstr, 10)<br>\n";
195 print $txt;
196 dol_syslog($txt, LOG_ERR);
197 $txt = $errstr." (".$errno.")<br>\n";
198 print $txt;
199 dol_syslog($txt, LOG_ERR);
200 print '</body>'."\n";
201 } else {
202 $txt = "Call Asterisk dialer for caller: ".$caller.", called: ".$called." clicktodiallogin: ".$login;
203 dol_syslog($txt);
204 print '<body onload="history.go(-1);">'."\n";
205 print '<!-- '.$txt.' -->';
206 fwrite($oSocket, "Action: login\r\n");
207 fwrite($oSocket, "Events: off\r\n");
208 fwrite($oSocket, "Username: $login\r\n");
209 fwrite($oSocket, "Secret: $password\r\n\r\n");
210 fwrite($oSocket, "Action: originate\r\n");
211 fwrite($oSocket, "Channel: ".$channel.$caller."\r\n");
212 fwrite($oSocket, "WaitTime: $strWaitTime\r\n");
213 fwrite($oSocket, "CallerId: $strCallerId\r\n");
214 fwrite($oSocket, "Exten: ".$prefix.$number."\r\n");
215 fwrite($oSocket, "Context: $strContext\r\n");
216 fwrite($oSocket, "Priority: $strPriority\r\n\r\n");
217 fwrite($oSocket, "Action: Logoff\r\n\r\n");
218 sleep(2);
219 fclose($oSocket);
220 print '</body>'."\n";
221 }
222 }
223} else {
224 print 'Bad parameters in URL. Must be '.dol_escape_htmltag($_SERVER['PHP_SELF']).'?caller=99999&called=99999&login=xxxxx&password=xxxxx';
225}
226
227// End of page
228llxFooter();
229$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
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.