dolibarr  20.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  *
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 
31 if (!defined('NOREQUIRESOC')) {
32  define('NOREQUIRESOC', '1');
33 }
34 if (!defined('NOREQUIRETRAN')) {
35  define('NOREQUIRETRAN', '1');
36 }
37 if (!defined('NOTOKENRENEWAL')) {
38  define('NOTOKENRENEWAL', '1');
39 }
40 if (!defined('NOREQUIREMENU')) {
41  define('NOREQUIREMENU', '1');
42 }
43 if (!defined('NOREQUIREHTML')) {
44  define('NOREQUIREHTML', '1');
45 }
46 if (!defined('NOREQUIREAJAX')) {
47  define('NOREQUIREAJAX', '1');
48 }
49 
56 function llxHeader()
57 {
58  print '<html>'."\n";
59  print '<head>'."\n";
60  print '<title>Asterisk redirection from Dolibarr...</title>'."\n";
61  print '</head>'."\n";
62 }
63 
70 function llxFooter()
71 {
72  print "\n".'</html>'."\n";
73 }
74 
75 require_once '../main.inc.php';
76 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
77 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
78 
79 
80 // Security check
81 if (empty($conf->clicktodial->enabled)) {
83  exit;
84 }
85 
86 
87 // Define Asterisk setup
88 if (!getDolGlobalString('ASTERISK_HOST')) {
89  $conf->global->ASTERISK_HOST = "127.0.0.1";
90 }
91 if (!getDolGlobalString('ASTERISK_TYPE')) {
92  $conf->global->ASTERISK_TYPE = "SIP/";
93 }
94 if (!getDolGlobalString('ASTERISK_INDICATIF')) {
95  $conf->global->ASTERISK_INDICATIF = "0";
96 }
97 if (!getDolGlobalString('ASTERISK_PORT')) {
98  $conf->global->ASTERISK_PORT = 5038;
99 }
100 if (getDolGlobalString('ASTERISK_INDICATIF') == 'NONE') {
101  $conf->global->ASTERISK_INDICATIF = '';
102 }
103 if (!getDolGlobalString('ASTERISK_CONTEXT')) {
104  $conf->global->ASTERISK_CONTEXT = "from-internal";
105 }
106 if (!getDolGlobalString('ASTERISK_WAIT_TIME')) {
107  $conf->global->ASTERISK_WAIT_TIME = "30";
108 }
109 if (!getDolGlobalString('ASTERISK_PRIORITY')) {
110  $conf->global->ASTERISK_PRIORITY = "1";
111 }
112 if (!getDolGlobalString('ASTERISK_MAX_RETRY')) {
113  $conf->global->ASTERISK_MAX_RETRY = "2";
114 }
115 
116 
117 $login = GETPOST('login', 'alphanohtml');
118 $password = GETPOST('password', 'none');
119 $caller = GETPOST('caller', 'alphanohtml');
120 $called = GETPOST('called', 'alphanohtml');
121 
122 // IP address of Asterisk server
123 $strHost = getDolGlobalString('ASTERISK_HOST');
124 
125 // Specify the type of extension through which your extension is connected.
126 // ex: SIP/, IAX2/, ZAP/, etc
127 $channel = getDolGlobalString('ASTERISK_TYPE');
128 
129 // Outgoing call sign
130 $prefix = getDolGlobalString('ASTERISK_INDICATIF');
131 
132 // Asterisk Port
133 $port = getDolGlobalString('ASTERISK_PORT');
134 
135 // Context ( generalement from-internal )
136 $strContext = getDolGlobalString('ASTERISK_CONTEXT');
137 
138 // Waiting time before hanging up
139 $strWaitTime = getDolGlobalString('ASTERISK_WAIT_TIME');
140 
141 // Priority
142 $strPriority = getDolGlobalString('ASTERISK_PRIORITY');
143 
144 // Number of call attempts
145 $strMaxRetry = getDolGlobalString('ASTERISK_MAX_RETRY');
146 
147 
148 /*
149  * View
150  */
151 
152 llxHeader();
153 
154 $sql = "SELECT s.nom as name FROM ".MAIN_DB_PREFIX."societe as s";
155 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON sp.fk_soc = s.rowid";
156 $sql .= " WHERE s.entity IN (".getEntity('societe').")";
157 $sql .= " AND (s.phone='".$db->escape($called)."'";
158 $sql .= " OR sp.phone='".$db->escape($called)."'";
159 $sql .= " OR sp.phone_perso='".$db->escape($called)."'";
160 $sql .= " OR sp.phone_mobile='".$db->escape($called)."')";
161 $sql .= $db->plimit(1);
162 
163 dol_syslog('click to dial search information with phone '.$called, LOG_DEBUG);
164 $resql = $db->query($sql);
165 if ($resql) {
166  $obj = $db->fetch_object($resql);
167  if ($obj) {
168  $found = $obj->name;
169  } else {
170  $found = 'Not found';
171  }
172  $db->free($resql);
173 } else {
174  dol_print_error($db, 'Error');
175  $found = 'Error';
176 }
177 
178 $number = strtolower($called);
179 $pos = strpos($number, "local");
180 if (!empty($number)) {
181  if ($pos === false) {
182  $errno = 0;
183  $errstr = 0;
184  $strCallerId = "Dolibarr caller $found <".strtolower($number).">";
185  $oSocket = @fsockopen($strHost, (int) $port, $errno, $errstr, 10);
186  if (!$oSocket) {
187  print '<body>'."\n";
188  $txt = "Failed to execute fsockopen($strHost, $port, \$errno, \$errstr, 10)<br>\n";
189  print $txt;
190  dol_syslog($txt, LOG_ERR);
191  $txt = $errstr." (".$errno.")<br>\n";
192  print $txt;
193  dol_syslog($txt, LOG_ERR);
194  print '</body>'."\n";
195  } else {
196  $txt = "Call Asterisk dialer for caller: ".$caller.", called: ".$called." clicktodiallogin: ".$login;
197  dol_syslog($txt);
198  print '<body onload="history.go(-1);">'."\n";
199  print '<!-- '.$txt.' -->';
200  fwrite($oSocket, "Action: login\r\n");
201  fwrite($oSocket, "Events: off\r\n");
202  fwrite($oSocket, "Username: $login\r\n");
203  fwrite($oSocket, "Secret: $password\r\n\r\n");
204  fwrite($oSocket, "Action: originate\r\n");
205  fwrite($oSocket, "Channel: ".$channel.$caller."\r\n");
206  fwrite($oSocket, "WaitTime: $strWaitTime\r\n");
207  fwrite($oSocket, "CallerId: $strCallerId\r\n");
208  fwrite($oSocket, "Exten: ".$prefix.$number."\r\n");
209  fwrite($oSocket, "Context: $strContext\r\n");
210  fwrite($oSocket, "Priority: $strPriority\r\n\r\n");
211  fwrite($oSocket, "Action: Logoff\r\n\r\n");
212  sleep(2);
213  fclose($oSocket);
214  print '</body>'."\n";
215  }
216  }
217 } else {
218  print 'Bad parameters in URL. Must be '.dol_escape_htmltag($_SERVER['PHP_SELF']).'?caller=99999&called=99999&login=xxxxx&password=xxxxx';
219 }
220 
221 // End of page
222 llxFooter();
223 $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:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:744
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.