dolibarr  16.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  *
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('NOCSRFCHECK')) {
38  define('NOCSRFCHECK', '1');
39 }
40 if (!defined('NOTOKENRENEWAL')) {
41  define('NOTOKENRENEWAL', '1');
42 }
43 if (!defined('NOREQUIREMENU')) {
44  define('NOREQUIREMENU', '1');
45 }
46 if (!defined('NOREQUIREHTML')) {
47  define('NOREQUIREHTML', '1');
48 }
49 if (!defined('NOREQUIREAJAX')) {
50  define('NOREQUIREAJAX', '1');
51 }
52 
59 function llxHeader()
60 {
61  print '<html>'."\n";
62  print '<head>'."\n";
63  print '<title>Asterisk redirection from Dolibarr...</title>'."\n";
64  print '</head>'."\n";
65 }
66 
73 function llxFooter()
74 {
75  print "\n".'</html>'."\n";
76 }
77 
78 
79 require_once '../main.inc.php';
80 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
81 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
82 
83 
84 // Security check
85 if (empty($conf->clicktodial->enabled)) {
87  exit;
88 }
89 
90 
91 // Define Asterisk setup
92 if (!isset($conf->global->ASTERISK_HOST)) {
93  $conf->global->ASTERISK_HOST = "127.0.0.1";
94 }
95 if (!isset($conf->global->ASTERISK_TYPE)) {
96  $conf->global->ASTERISK_TYPE = "SIP/";
97 }
98 if (!isset($conf->global->ASTERISK_INDICATIF)) {
99  $conf->global->ASTERISK_INDICATIF = "0";
100 }
101 if (!isset($conf->global->ASTERISK_PORT)) {
102  $conf->global->ASTERISK_PORT = 5038;
103 }
104 if ($conf->global->ASTERISK_INDICATIF == 'NONE') {
105  $conf->global->ASTERISK_INDICATIF = '';
106 }
107 if (!isset($conf->global->ASTERISK_CONTEXT)) {
108  $conf->global->ASTERISK_CONTEXT = "from-internal";
109 }
110 if (!isset($conf->global->ASTERISK_WAIT_TIME)) {
111  $conf->global->ASTERISK_WAIT_TIME = "30";
112 }
113 if (!isset($conf->global->ASTERISK_PRIORITY)) {
114  $conf->global->ASTERISK_PRIORITY = "1";
115 }
116 if (!isset($conf->global->ASTERISK_MAX_RETRY)) {
117  $conf->global->ASTERISK_MAX_RETRY = "2";
118 }
119 
120 
121 $login = GETPOST('login', 'alphanohtml');
122 $password = GETPOST('password', 'none');
123 $caller = GETPOST('caller', 'alphanohtml');
124 $called = GETPOST('called', 'alphanohtml');
125 
126 // IP address of Asterisk server
127 $strHost = $conf->global->ASTERISK_HOST;
128 // SpĂ©cifiez le type d'extension par laquelle vous poste est connecte.
129 // ex: SIP/, IAX2/, ZAP/, etc
130 $channel = $conf->global->ASTERISK_TYPE;
131 // Indicatif de la ligne sortante
132 $prefix = $conf->global->ASTERISK_INDICATIF;
133 // Port
134 $port = $conf->global->ASTERISK_PORT;
135 // Context ( generalement from-internal )
136 $strContext = $conf->global->ASTERISK_CONTEXT;
137 // Delai d'attente avant de raccrocher
138 $strWaitTime = $conf->global->ASTERISK_WAIT_TIME;
139 // Priority
140 $strPriority = $conf->global->ASTERISK_PRIORITY;
141 // Nomber of try
142 $strMaxRetry = $conf->global->ASTERISK_MAX_RETRY;
143 
144 
145 /*
146  * View
147  */
148 
149 llxHeader();
150 
151 $sql = "SELECT s.nom as name FROM ".MAIN_DB_PREFIX."societe as s";
152 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON sp.fk_soc = s.rowid";
153 $sql .= " WHERE s.entity IN (".getEntity('societe').")";
154 $sql .= " AND (s.phone='".$db->escape($called)."'";
155 $sql .= " OR sp.phone='".$db->escape($called)."'";
156 $sql .= " OR sp.phone_perso='".$db->escape($called)."'";
157 $sql .= " OR sp.phone_mobile='".$db->escape($called)."')";
158 $sql .= $db->plimit(1);
159 
160 dol_syslog('click to dial search information with phone '.$called, LOG_DEBUG);
161 $resql = $db->query($sql);
162 if ($resql) {
163  $obj = $db->fetch_object($resql);
164  if ($obj) {
165  $found = $obj->name;
166  } else {
167  $found = 'Not found';
168  }
169  $db->free($resql);
170 } else {
171  dol_print_error($db, 'Error');
172  $found = 'Error';
173 }
174 
175 $number = strtolower($called);
176 $pos = strpos($number, "local");
177 if (!empty($number)) {
178  if ($pos === false) {
179  $errno = 0;
180  $errstr = 0;
181  $strCallerId = "Dolibarr caller $found <".strtolower($number).">";
182  $oSocket = @fsockopen($strHost, $port, $errno, $errstr, 10);
183  if (!$oSocket) {
184  print '<body>'."\n";
185  $txt = "Failed to execute fsockopen($strHost, $port, \$errno, \$errstr, 10)<br>\n";
186  print $txt;
187  dol_syslog($txt, LOG_ERR);
188  $txt = $errstr." (".$errno.")<br>\n";
189  print $txt;
190  dol_syslog($txt, LOG_ERR);
191  print '</body>'."\n";
192  } else {
193  $txt = "Call Asterisk dialer for caller: ".$caller.", called: ".$called." clicktodiallogin: ".$login;
194  dol_syslog($txt);
195  print '<body onload="javascript:history.go(-1);">'."\n";
196  print '<!-- '.$txt.' -->';
197  fputs($oSocket, "Action: login\r\n");
198  fputs($oSocket, "Events: off\r\n");
199  fputs($oSocket, "Username: $login\r\n");
200  fputs($oSocket, "Secret: $password\r\n\r\n");
201  fputs($oSocket, "Action: originate\r\n");
202  fputs($oSocket, "Channel: ".$channel.$caller."\r\n");
203  fputs($oSocket, "WaitTime: $strWaitTime\r\n");
204  fputs($oSocket, "CallerId: $strCallerId\r\n");
205  fputs($oSocket, "Exten: ".$prefix.$number."\r\n");
206  fputs($oSocket, "Context: $strContext\r\n");
207  fputs($oSocket, "Priority: $strPriority\r\n\r\n");
208  fputs($oSocket, "Action: Logoff\r\n\r\n");
209  sleep(2);
210  fclose($oSocket);
211  print '</body>'."\n";
212  }
213  }
214 } else {
215  print 'Bad parameters in URL. Must be '.dol_escape_htmltag($_SERVER['PHP_SELF']).'?caller=99999&called=99999&login=xxxxx&password=xxxxx';
216 }
217 
218 // End of page
219 llxFooter();
220 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59