dolibarr  17.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 
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 (!isset($conf->global->ASTERISK_HOST)) {
89  $conf->global->ASTERISK_HOST = "127.0.0.1";
90 }
91 if (!isset($conf->global->ASTERISK_TYPE)) {
92  $conf->global->ASTERISK_TYPE = "SIP/";
93 }
94 if (!isset($conf->global->ASTERISK_INDICATIF)) {
95  $conf->global->ASTERISK_INDICATIF = "0";
96 }
97 if (!isset($conf->global->ASTERISK_PORT)) {
98  $conf->global->ASTERISK_PORT = 5038;
99 }
100 if ($conf->global->ASTERISK_INDICATIF == 'NONE') {
101  $conf->global->ASTERISK_INDICATIF = '';
102 }
103 if (!isset($conf->global->ASTERISK_CONTEXT)) {
104  $conf->global->ASTERISK_CONTEXT = "from-internal";
105 }
106 if (!isset($conf->global->ASTERISK_WAIT_TIME)) {
107  $conf->global->ASTERISK_WAIT_TIME = "30";
108 }
109 if (!isset($conf->global->ASTERISK_PRIORITY)) {
110  $conf->global->ASTERISK_PRIORITY = "1";
111 }
112 if (!isset($conf->global->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 = $conf->global->ASTERISK_HOST;
124 // SpĂ©cifiez le type d'extension par laquelle vous poste est connecte.
125 // ex: SIP/, IAX2/, ZAP/, etc
126 $channel = $conf->global->ASTERISK_TYPE;
127 // Indicatif de la ligne sortante
128 $prefix = $conf->global->ASTERISK_INDICATIF;
129 // Port
130 $port = $conf->global->ASTERISK_PORT;
131 // Context ( generalement from-internal )
132 $strContext = $conf->global->ASTERISK_CONTEXT;
133 // Delai d'attente avant de raccrocher
134 $strWaitTime = $conf->global->ASTERISK_WAIT_TIME;
135 // Priority
136 $strPriority = $conf->global->ASTERISK_PRIORITY;
137 // Nomber of try
138 $strMaxRetry = $conf->global->ASTERISK_MAX_RETRY;
139 
140 
141 /*
142  * View
143  */
144 
145 llxHeader();
146 
147 $sql = "SELECT s.nom as name FROM ".MAIN_DB_PREFIX."societe as s";
148 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON sp.fk_soc = s.rowid";
149 $sql .= " WHERE s.entity IN (".getEntity('societe').")";
150 $sql .= " AND (s.phone='".$db->escape($called)."'";
151 $sql .= " OR sp.phone='".$db->escape($called)."'";
152 $sql .= " OR sp.phone_perso='".$db->escape($called)."'";
153 $sql .= " OR sp.phone_mobile='".$db->escape($called)."')";
154 $sql .= $db->plimit(1);
155 
156 dol_syslog('click to dial search information with phone '.$called, LOG_DEBUG);
157 $resql = $db->query($sql);
158 if ($resql) {
159  $obj = $db->fetch_object($resql);
160  if ($obj) {
161  $found = $obj->name;
162  } else {
163  $found = 'Not found';
164  }
165  $db->free($resql);
166 } else {
167  dol_print_error($db, 'Error');
168  $found = 'Error';
169 }
170 
171 $number = strtolower($called);
172 $pos = strpos($number, "local");
173 if (!empty($number)) {
174  if ($pos === false) {
175  $errno = 0;
176  $errstr = 0;
177  $strCallerId = "Dolibarr caller $found <".strtolower($number).">";
178  $oSocket = @fsockopen($strHost, $port, $errno, $errstr, 10);
179  if (!$oSocket) {
180  print '<body>'."\n";
181  $txt = "Failed to execute fsockopen($strHost, $port, \$errno, \$errstr, 10)<br>\n";
182  print $txt;
183  dol_syslog($txt, LOG_ERR);
184  $txt = $errstr." (".$errno.")<br>\n";
185  print $txt;
186  dol_syslog($txt, LOG_ERR);
187  print '</body>'."\n";
188  } else {
189  $txt = "Call Asterisk dialer for caller: ".$caller.", called: ".$called." clicktodiallogin: ".$login;
190  dol_syslog($txt);
191  print '<body onload="javascript:history.go(-1);">'."\n";
192  print '<!-- '.$txt.' -->';
193  fputs($oSocket, "Action: login\r\n");
194  fputs($oSocket, "Events: off\r\n");
195  fputs($oSocket, "Username: $login\r\n");
196  fputs($oSocket, "Secret: $password\r\n\r\n");
197  fputs($oSocket, "Action: originate\r\n");
198  fputs($oSocket, "Channel: ".$channel.$caller."\r\n");
199  fputs($oSocket, "WaitTime: $strWaitTime\r\n");
200  fputs($oSocket, "CallerId: $strCallerId\r\n");
201  fputs($oSocket, "Exten: ".$prefix.$number."\r\n");
202  fputs($oSocket, "Context: $strContext\r\n");
203  fputs($oSocket, "Priority: $strPriority\r\n\r\n");
204  fputs($oSocket, "Action: Logoff\r\n\r\n");
205  sleep(2);
206  fclose($oSocket);
207  print '</body>'."\n";
208  }
209  }
210 } else {
211  print 'Bad parameters in URL. Must be '.dol_escape_htmltag($_SERVER['PHP_SELF']).'?caller=99999&called=99999&login=xxxxx&password=xxxxx';
212 }
213 
214 // End of page
215 llxFooter();
216 $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('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("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->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
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.
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.