dolibarr 25.0.0-alpha
oauthlogintokens.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013-2016 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2014-2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2020 Nicolas ZABOURI <info@inovea-conseil.com>
5 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/oauth.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
32
33use OAuth\Common\Storage\DoliStorage;
34use OAuth\Common\Consumer\Credentials;
35
36$supportedoauth2array = getSupportedOauth2Array();
37
48// Load translation files required by the page
49$langs->loadLangs(array('admin', 'printing', 'oauth'));
50
51$action = GETPOST('action', 'aZ09');
52$mode = GETPOST('mode', 'alpha');
53$value = GETPOST('value', 'alpha');
54$varname = GETPOST('varname', 'alpha');
55$driver = GETPOST('driver', 'alpha');
56
57if (!empty($driver)) {
58 $langs->load($driver);
59}
60
61if (!$mode) {
62 $mode = 'setup';
63}
64
65if (!$user->admin) {
67}
68
69/*
70 * Action
71 */
72$error = 0;
73
74/*if (($mode == 'test' || $mode == 'setup') && empty($driver)) {
75 setEventMessages($langs->trans('PleaseSelectaDriverfromList'), null);
76 header("Location: ".$_SERVER['PHP_SELF'].'?mode=config');
77 exit;
78}*/
79
80if ($action == 'setconst' && $user->admin) {
81 $db->begin();
82
83 $setupconstarray = GETPOST('setupdriver', 'array');
84
85 foreach ($setupconstarray as $setupconst) {
86 $constname = dol_escape_htmltag($setupconst['varname']);
87 $constvalue = dol_escape_htmltag($setupconst['value']);
88 $consttype = dol_escape_htmltag($setupconst['type']);
89 $constnote = dol_escape_htmltag($setupconst['note']);
90
91 $result = dolibarr_set_const($db, $constname, $constvalue, $consttype, 0, $constnote, $conf->entity);
92 if (!($result > 0)) {
93 $error++;
94 }
95 }
96
97 if (!$error) {
98 $db->commit();
99 setEventMessages($langs->trans("SetupSaved"), null);
100 } else {
101 $db->rollback();
102 dol_print_error($db);
103 }
104 $action = '';
105}
106
107if ($action == 'setvalue' && $user->admin) {
108 $db->begin();
109
110 $result = dolibarr_set_const($db, $varname, $value, 'chaine', 0, '', $conf->entity);
111 if (!($result > 0)) {
112 $error++;
113 }
114
115 if (!$error) {
116 $db->commit();
117 setEventMessages($langs->trans("SetupSaved"), null);
118 } else {
119 $db->rollback();
120 dol_print_error($db);
121 }
122 $action = '';
123}
124
125// Test a refresh of a token using the refresh token
126if ($action == 'refreshtoken' && $user->admin) {
127 $keyforprovider = GETPOST('keyforprovider');
128 $OAUTH_SERVICENAME = GETPOST('service');
129
130 // Show value of token
131 $tokenobj = null;
132 $outputofrefresh = '';
133 // Load OAUth libraries
134 require_once DOL_DOCUMENT_ROOT.'/includes/OAuth/bootstrap.php';
135
136 $keyforsupportedoauth2array = $OAUTH_SERVICENAME;
137 if (preg_match('/^.*-/', $keyforsupportedoauth2array)) {
138 $keyforprovider = preg_replace('/^.*-/', '', $keyforsupportedoauth2array);
139 } else {
140 $keyforprovider = '';
141 }
142 $keyforsupportedoauth2array = preg_replace('/-.*$/', '', strtoupper($keyforsupportedoauth2array));
143 $keyforsupportedoauth2array = 'OAUTH_'.$keyforsupportedoauth2array.'_NAME';
144
145 $keyforparamtenant = 'OAUTH_'.strtoupper(empty($supportedoauth2array[$keyforsupportedoauth2array]['callbackfile']) ? 'Unknown' : $supportedoauth2array[$keyforsupportedoauth2array]['callbackfile']).($keyforprovider ? '-'.$keyforprovider : '').'_TENANT';
146
147 // Dolibarr storage
148 $storage = new DoliStorage($db, $conf, $keyforprovider, getDolGlobalString($keyforparamtenant));
149 try {
150 // $OAUTH_SERVICENAME is for example 'Google-keyforprovider'
151 //print '<!-- '.$OAUTH_SERVICENAME.' -->'."\n"; // No output in actions, it is before the HTML header
152
153 dol_syslog("oauthlogintokens.php: Read token for service ".$OAUTH_SERVICENAME);
154 $tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME);
155
156 // tokenobj uses time() @phan-suppress-next-line DolibarrForbiddenFunctionPlugin
157 $expire = ($tokenobj->getEndOfLife() !== -9002 && $tokenobj->getEndOfLife() !== -9001 && time() > ($tokenobj->getEndOfLife() - 30));
158 // We have to save the refresh token in a memory variable because Google give it only once
159 $refreshtoken = $tokenobj->getRefreshToken();
160 //print '<!-- data stored into field token: '.$storage->token.' - expire '.((string) $expire).' -->';
161
162 //print $tokenobj->getExtraParams()['id_token'].'<br>';
163 //print $tokenobj->getAccessToken().'<br>';
164 //print $tokenobj->getRefreshToken().'<br>';
165
166 //var_dump($expire);
167
168 // We do the refresh even if not expired, this is the goal of action.
169 $oauthname = explode('-', $OAUTH_SERVICENAME);
170 $keyforoauthservice = strtoupper($oauthname[0]).(empty($oauthname[1]) ? '' : '-'.$oauthname[1]);
171 $credentials = new Credentials(
172 getDolGlobalString('OAUTH_'.$keyforoauthservice.'_ID'),
173 getDolGlobalString('OAUTH_'.$keyforoauthservice.'_SECRET'),
174 getDolGlobalString('OAUTH_'.$keyforoauthservice.'_URLCALLBACK')
175 );
176
177 $serviceFactory = new \OAuth\ServiceFactory();
178 $httpClient = new \OAuth\Common\Http\Client\CurlClient();
179 // TODO Set options for proxy and timeout
180 // $params=array('CURLXXX'=>value, ...)
181 //$httpClient->setCurlParameters($params);
182 $serviceFactory->setHttpClient($httpClient);
183
184 $scopes = array();
185 if (preg_match('/^Microsoft/', $OAUTH_SERVICENAME)) {
186 //$extraparams = $tokenobj->getExtraParams();
187 $tmp = explode('-', $OAUTH_SERVICENAME);
188 $scopes = explode(',', getDolGlobalString('OAUTH_'.strtoupper($tmp[0]).(empty($tmp[1]) ? '' : '-'.$tmp[1]).'_SCOPE'));
189 }
190
191 // ex service is Google-Emails we need only the first part Google
192 $apiService = $serviceFactory->createService($oauthname[0], $credentials, $storage, $scopes);
193
194 if ($apiService instanceof OAuth\OAuth2\Service\AbstractService || $apiService instanceof OAuth\OAuth1\Service\AbstractService) {
195 // ServiceInterface does not provide refreshAccessToekn, AbstractService does
196 dol_syslog("oauthlogintokens.php: call refreshAccessToken to get the new access token");
197 // The OAuth library may print the error_description received, so we capture it to avoid output before the HTML header
198 ob_start();
199 try {
200 $tokenobj = $apiService->refreshAccessToken($tokenobj); // This call refresh and store the new token (but does not include the refresh token)
201 } finally {
202 $outputofrefresh = trim((string) ob_get_clean());
203 }
204
205 dol_syslog("oauthlogintokens.php: call setRefreshToken");
206 $tokenobj->setRefreshToken($refreshtoken); // Restore the refresh token
207
208 dol_syslog("oauthlogintokens.php: call storeAccessToken to save the new access token + the old refresh token");
209 $storage->storeAccessToken($OAUTH_SERVICENAME, $tokenobj); // This save the new token including the refresh token
210
211 if ($expire) {
212 setEventMessages($langs->trans("OldTokenWasExpiredItHasBeenRefresh"), null, 'mesgs');
213 } else {
214 setEventMessages($langs->trans("OldTokenWasNotExpiredButItHasBeenRefresh"), null, 'mesgs');
215 }
216 } else {
217 dol_print_error($db, 'apiService is not a correct OAUTH2 Abstract service');
218 }
219
220 dol_syslog("oauthlogintokens.php: Read token again for service ".$OAUTH_SERVICENAME);
221 $tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME);
222 } catch (Exception $e) {
223 // Return an error if token not found or if refresh failed
224 $errormessage = $e->getMessage().(empty($outputofrefresh) ? '' : ' - '.$outputofrefresh);
225 dol_syslog("oauthlogintokens.php: Error on refreshtoken for service ".$OAUTH_SERVICENAME.": ".$errormessage, LOG_WARNING);
226 setEventMessages($errormessage, null, 'errors');
227 }
228}
229
230
231/*
232 * View
233 */
234
235// Define $urlwithroot
236$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
237$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
238//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
239
240$form = new Form($db);
241
242$title = $langs->trans("TokenManager");
243$help_url = 'EN:Module_OAuth|FR:Module_OAuth_FR|ES:Módulo_OAuth_ES';
244
245llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-admin page-oauthlogintokens');
246
247$linkback = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
248
249print load_fiche_titre($langs->trans('ConfigOAuth'), $linkback, 'title_setup');
250
252
253print dol_get_fiche_head($head, 'tokengeneration', '', -1, '');
254
255if (GETPOST('error')) {
256 setEventMessages(GETPOST('error'), null, 'errors');
257}
258
259if ($mode == 'setup' && $user->admin) {
260 print '<span class="opacitymedium">'.$langs->trans("OAuthSetupForLogin")."</span><br><br>\n";
261
262 // Define $listinsetup
263 $listinsetup = array();
264 foreach ($conf->global as $key => $val) {
265 if (!empty($val) && preg_match('/^OAUTH_.*_ID$/', $key)) {
266 $provider = preg_replace('/_ID$/', '', $key);
267 $listinsetup[] = array(
268 $provider.'_NAME',
269 $provider.'_ID',
270 $provider.'_SECRET',
271 $provider.'_URL', // For custom oauth links
272 $provider.'_SCOPE' // For custom oauth links
273 );
274 }
275 }
276
277 $oauthstateanticsrf = bin2hex(random_bytes(128 / 8));
278
279 // $list is defined into oauth.lib.php to the list of supported OAuth providers.
280 if (!empty($listinsetup)) {
281 foreach ($listinsetup as $key) {
282 $supported = 0;
283 $keyforsupportedoauth2array = $key[0]; // May be OAUTH_GOOGLE_NAME or OAUTH_GOOGLE_xxx_NAME
284 $keyforsupportedoauth2array = preg_replace('/^OAUTH_/', '', $keyforsupportedoauth2array);
285 $keyforsupportedoauth2array = preg_replace('/_NAME$/', '', $keyforsupportedoauth2array);
286 if (preg_match('/^.*-/', $keyforsupportedoauth2array)) {
287 $keybeforeprovider = preg_replace('/-.*$/', '', $keyforsupportedoauth2array);
288 $keyforprovider = preg_replace('/^.*-/', '', $keyforsupportedoauth2array);
289 } else {
290 $keybeforeprovider = $keyforsupportedoauth2array;
291 $keyforprovider = '';
292 }
293 $keyforsupportedoauth2array = preg_replace('/-.*$/', '', strtoupper($keyforsupportedoauth2array));
294 $keyforsupportedoauth2array = 'OAUTH_'.$keyforsupportedoauth2array.'_NAME';
295
296 $nameofservice = ucfirst(strtolower(empty($supportedoauth2array[$keyforsupportedoauth2array]['callbackfile']) ? 'Unknown' : $supportedoauth2array[$keyforsupportedoauth2array]['callbackfile']));
297 $nameofservice .= ($keyforprovider ? '-'.$keyforprovider : '');
298 $OAUTH_SERVICENAME = $nameofservice;
299
300 $keyforparamtenant = 'OAUTH_'.strtoupper(empty($supportedoauth2array[$keyforsupportedoauth2array]['callbackfile']) ? 'Unknown' : $supportedoauth2array[$keyforsupportedoauth2array]['callbackfile']).($keyforprovider ? '-'.$keyforprovider : '').'_TENANT';
301
302 $shortscope = '';
303 if (getDolGlobalString($key[4])) {
304 $shortscope = getDolGlobalString($key[4]);
305 }
306 $state = $shortscope; // TODO USe a better state
307
308 $urltorefresh = $_SERVER["PHP_SELF"].'?action=refreshtoken&token='.newToken();
309
310 // Define $urltorenew, $urltodelete, $urltocheckperms
311 if ($keyforsupportedoauth2array == 'OAUTH_GITHUB_NAME') {
312 // List of keys that will be converted into scopes (from constants 'SCOPE_state_in_uppercase' in file of service).
313 // We pass this param list in to 'state' because we need it before and after the redirect.
314
315 // Note: github does not accept csrf key inside the state parameter (only known values)
316 $urltorenew = $urlwithroot.'/core/modules/oauth/github_oauthcallback.php?shortscope='.urlencode($shortscope).'&state='.urlencode($shortscope).'&backtourl='.urlencode(DOL_URL_ROOT.'/admin/oauthlogintokens.php');
317 $urltodelete = $urlwithroot.'/core/modules/oauth/github_oauthcallback.php?action=delete&token='.newToken().'&backtourl='.urlencode(DOL_URL_ROOT.'/admin/oauthlogintokens.php');
318 $urltocheckperms = 'https://github.com/settings/applications/';
319 } elseif ($keyforsupportedoauth2array == 'OAUTH_GOOGLE_NAME') {
320 // List of keys that will be converted into scopes (from constants 'SCOPE_state_in_uppercase' in file of service).
321 // List of scopes for Google are here: https://developers.google.com/identity/protocols/oauth2/scopes
322 // We pass this key list into the param 'state' because we need it before and after the redirect.
323 $urltorenew = $urlwithroot.'/core/modules/oauth/google_oauthcallback.php?shortscope='.urlencode($shortscope).'&state='.urlencode($state).'-'.$oauthstateanticsrf.'&backtourl='.urlencode(DOL_URL_ROOT.'/admin/oauthlogintokens.php');
324 $urltodelete = $urlwithroot.'/core/modules/oauth/google_oauthcallback.php?action=delete&token='.newToken().'&backtourl='.urlencode(DOL_URL_ROOT.'/admin/oauthlogintokens.php');
325 $urltocheckperms = 'https://security.google.com/settings/security/permissions';
326 } elseif (!empty($supportedoauth2array[$keyforsupportedoauth2array]['returnurl'])) {
327 $urltorenew = $urlwithroot.$supportedoauth2array[$keyforsupportedoauth2array]['returnurl'].'?shortscope='.urlencode($shortscope).'&state='.urlencode($state).'&backtourl='.urlencode(DOL_URL_ROOT.'/admin/oauthlogintokens.php');
328 $urltodelete = $urlwithroot.$supportedoauth2array[$keyforsupportedoauth2array]['returnurl'].'?action=delete&token='.newToken().'&backtourl='.urlencode(DOL_URL_ROOT.'/admin/oauthlogintokens.php');
329 $urltocheckperms = '';
330 } else {
331 $urltorenew = '';
332 $urltodelete = '';
333 $urltocheckperms = '';
334 }
335
336 if ($urltorenew) {
337 $urltorenew .= '&keyforprovider='.urlencode($keyforprovider);
338 }
339 if ($urltorefresh) {
340 $urltorefresh .= '&keyforprovider='.urlencode($keyforprovider).'&service='.urlencode($OAUTH_SERVICENAME);
341 }
342 if ($urltodelete) {
343 $urltodelete .= '&keyforprovider='.urlencode($keyforprovider);
344 }
345
346 // Show value of token
347 $tokenobj = null;
348 // Token
349 require_once DOL_DOCUMENT_ROOT.'/includes/OAuth/bootstrap.php';
350 // Dolibarr storage
351 $storage = new DoliStorage($db, $conf, $keyforprovider, getDolGlobalString($keyforparamtenant));
352 try {
353 // $OAUTH_SERVICENAME is for example 'Google-keyforprovider'
354 print '<!-- '.$OAUTH_SERVICENAME.' -->'."\n";
355 $tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME);
356 print '<!-- data stored into field token: '.$storage->token.' -->';
357 //print $tokenobj->getExtraParams()['id_token'].'<br>';
358 //print $tokenobj->getAccessToken().'<br>';
359 } catch (Exception $e) {
360 // Return an error if token not found
361 //print $e->getMessage();
362 }
363
364 // Set other properties
365 $refreshtoken = false;
366 $expiredat = '';
367
368 $expire = false;
369 // Is token expired or will token expire in the next 30 seconds
370 if (is_object($tokenobj)) {
371 // tokenobj uses time() @phan-suppress-next-line DolibarrForbiddenFunctionPlugin
372 $expire = ($tokenobj->getEndOfLife() !== $tokenobj::EOL_NEVER_EXPIRES && $tokenobj->getEndOfLife() !== $tokenobj::EOL_UNKNOWN && time() > ($tokenobj->getEndOfLife() - 30));
373 }
374 if ($key[1] != '' && $key[2] != '') {
375 if (is_object($tokenobj)) {
376 $refreshtoken = $tokenobj->getRefreshToken();
377
378 $endoflife = $tokenobj->getEndOfLife();
379 if ($endoflife == $tokenobj::EOL_NEVER_EXPIRES) {
380 $expiredat = $langs->trans("Never");
381 } elseif ($endoflife == $tokenobj::EOL_UNKNOWN) {
382 $expiredat = $langs->trans("Unknown");
383 } else {
384 $expiredat = dol_print_date($endoflife, "dayhour", 'tzuserrel');
385 }
386 }
387 }
388
389 $submit_enabled = 0;
390
391 print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?mode=setup&amp;driver='.$driver.'" autocomplete="off" spellcheck="false">';
392 print '<input type="hidden" name="token" value="'.newToken().'">';
393 print '<input type="hidden" name="action" value="setconst">';
394 print '<input type="hidden" name="page_y" value="">';
395
396 print '<div class="div-table-responsive-no-min">';
397 print '<table class="noborder centpercent">'."\n";
398
399 // Api Name
400 $label = $langs->trans($keyforsupportedoauth2array);
401 print '<tr class="liste_titre">';
402 print '<th class="titlefieldcreate">';
403 print img_picto('', $supportedoauth2array[$keyforsupportedoauth2array]['picto'], 'class="pictofixedwidth"');
404 if ($label == $keyforsupportedoauth2array) {
405 print $supportedoauth2array[$keyforsupportedoauth2array]['name'];
406 } else {
407 print $label;
408 }
409 if ($keyforprovider) {
410 print ' (<b>'.$keyforprovider.'</b>)';
411 } else {
412 print ' (<b>'.$langs->trans("NoName").'</b>)';
413 }
414 print '</th>';
415 print '<th></th>';
416 print '<th></th>';
417 print "</tr>\n";
418
419 print '<tr class="oddeven">';
420 print '<td>';
421 //var_dump($key);
422 print $langs->trans("OAuthIDSecret").'</td>';
423 print '<td>';
424 print '<span class="opacitymedium">'.$langs->trans("SeePreviousTab").'</span>';
425 print '</td>';
426 print '<td>';
427 print '</td>';
428 print '</tr>'."\n";
429
430 // Scopes
431 print '<tr class="oddeven">';
432 print '<td>'.$langs->trans("Scopes").'</td>';
433 print '<td colspan="2">';
434 $currentscopes = getDolGlobalString($key[4]);
435 print $currentscopes;
436 print '</td></tr>';
437
438 print '<tr class="oddeven">';
439 print '<td>';
440 //var_dump($key);
441 print $langs->trans("IsTokenGenerated");
442 print '</td>';
443 print '<td>';
444 if ($keyforprovider != 'Login') {
445 if (is_object($tokenobj)) {
446 print $form->textwithpicto(yn(1), $langs->trans("HasAccessToken").' : '.dol_print_date($storage->date_modification, 'dayhour').'<br>Scopes saved into field state='.dol_escape_htmltag($storage->state));
447 } else {
448 print '<span class="opacitymedium">'.$langs->trans("NoAccessToken").'</span>';
449 }
450 } else {
451 print '<span class="opacitymedium">'.$langs->trans("TokenNotRequiredForOAuthLogin").'</span>';
452 }
453 print '</td>';
454 print '<td width="50%">';
455 if ($keyforprovider != 'Login') {
456 // Links to delete/checks token
457 if (is_object($tokenobj)) {
458 //test on $storage->hasAccessToken($OAUTH_SERVICENAME) ?
459 if ($urltodelete) {
460 print '<a class="button button-delete smallpaddingimp reposition marginright" href="'.$urltodelete.'">'.$langs->trans('DeleteAccess').'</a>';
461 } else {
462 print '<span class="opacitymedium marginright">'.$langs->trans('GoOnTokenProviderToDeleteToken').'</span>';
463 }
464 }
465 // Request remote token
466 if ($urltorenew) {
467 print '<a class="button smallpaddingimp reposition classfortooltip marginright" href="'.$urltorenew.'" title="'.dolPrintHTMLForAttribute($langs->trans('RequestAccess')).'">'.$langs->trans('GetAccess').'</a>';
468 }
469 // Request remote token
470 if ($urltorefresh && $refreshtoken) {
471 print '<a class="button smallpaddingimp reposition classfortooltip marginright" href="'.$urltorefresh.'" title="'.dolPrintHTMLForAttribute($langs->trans('RefreshTokenHelp')).'">'.$langs->trans('RefreshToken').'</a>';
472 }
473
474 // Check remote access
475 if ($urltocheckperms) {
476 print '<br>'.$langs->trans("ToCheckDeleteTokenOnProvider", $OAUTH_SERVICENAME).': <a href="'.$urltocheckperms.'" target="_'.strtolower($OAUTH_SERVICENAME).'">'.$urltocheckperms.'</a>';
477 }
478 }
479 print '</td>';
480 print '</tr>';
481
482 if (is_object($tokenobj)) {
483 print '<tr class="oddeven">';
484 print '<td>';
485 //var_dump($key);
486 print $langs->trans("TokenRawValue").'</td>';
487 print '<td colspan="2">';
488 if (is_object($tokenobj)) {
489 print '<textarea class="quatrevingtpercent small" rows="'.ROWS_4.'">'.var_export($tokenobj, true).'</textarea><br>'."\n";
490 }
491 print '</td>';
492 print '</tr>'."\n";
493
494 print '<tr class="oddeven">';
495 print '<td>';
496 //var_dump($key);
497 print $langs->trans("AccessToken").'</td>';
498 print '<td colspan="2">';
499 $tokentoshow = $tokenobj->getAccessToken();
500 print '<span class="" title="'.dol_escape_htmltag($tokentoshow).'">'.showValueWithClipboardCPButton($tokentoshow, 1, dol_trunc($tokentoshow, 32)).'</span>';
501 //print 'Refresh: '.$tokenobj->getRefreshToken().'<br>';
502 //print 'EndOfLife: '.$tokenobj->getEndOfLife().'<br>';
503 //var_dump($tokenobj->getExtraParams());
504 /*print '<br>Extra: <br><textarea class="quatrevingtpercent">';
505 print ''.join(',',$tokenobj->getExtraParams());
506 print '</textarea>';*/
507
508 print '<span class="opacitymedium"> &nbsp; - &nbsp; ';
509 print $langs->trans("ExpirationDate").': ';
510 print '</span>';
511 print $expiredat;
512
513 print $expire ? ' ('.$langs->trans("TokenExpired").')' : ' ('.$langs->trans("TokenNotExpired").')';
514
515 print '</td>';
516 print '</tr>'."\n";
517
518 // Token refresh
519 print '<tr class="oddeven">';
520 print '<td>';
521 //var_dump($key);
522 print $langs->trans("TOKEN_REFRESH");
523 print '</td>';
524 print '<td colspan="2">';
525 print '<span class="" title="'.dol_escape_htmltag($refreshtoken).'">'.showValueWithClipboardCPButton($refreshtoken, 1, dol_trunc($refreshtoken, 32)).'</span>';
526 print '</td>';
527 print '</tr>';
528 }
529
530 print '</table>';
531 print '</div>';
532
533 if (!empty($driver)) {
534 if ($submit_enabled) {
535 print $form->buttonsSaveCancel("Modify", '');
536 }
537 }
538
539 print '</form>';
540 print '<br>';
541 }
542 }
543}
544
545if ($mode == 'test' && $user->admin) {
546 print $langs->trans('PrintTestDesc'.$driver)."<br><br>\n";
547
548 print '<div class="div-table-responsive-no-min">';
549 print '<table class="noborder centpercent">';
550 if (!empty($driver)) {
551 require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/'.$driver.'.modules.php';
552 $classname = 'printing_'.$driver;
553 $langs->load($driver);
554 $printer = new $classname($db);
555
556 '@phan-var-force PrintingDriver $printer';
557
558 //print '<pre>'.print_r($printer, true).'</pre>';
559 if (count($printer->getlistAvailablePrinters())) {
560 if ($printer->listAvailablePrinters() == 0) {
561 print $printer->resprint;
562 } else {
563 setEventMessages($printer->error, $printer->errors, 'errors');
564 }
565 } else {
566 print $langs->trans('PleaseConfigureDriverfromList');
567 }
568 }
569
570 print '</table>';
571 print '</div>';
572}
573
574if ($mode == 'userconf' && $user->admin) {
575 print $langs->trans('PrintUserConfDesc'.$driver)."<br><br>\n";
576
577 print '<div class="div-table-responsive">';
578 print '<table class="noborder centpercent">';
579 print '<tr class="liste_titre">';
580 print '<th>'.$langs->trans("User").'</th>';
581 print '<th>'.$langs->trans("PrintModule").'</th>';
582 print '<th>'.$langs->trans("PrintDriver").'</th>';
583 print '<th>'.$langs->trans("Printer").'</th>';
584 print '<th>'.$langs->trans("PrinterLocation").'</th>';
585 print '<th>'.$langs->trans("PrinterId").'</th>';
586 print '<th>'.$langs->trans("NumberOfCopy").'</th>';
587 print '<th class="center">'.$langs->trans("Delete").'</th>';
588 print "</tr>\n";
589 $sql = "SELECT p.rowid, p.printer_name, p.printer_location, p.printer_id, p.copy, p.module, p.driver, p.userid, u.login";
590 $sql .= " FROM ".MAIN_DB_PREFIX."printing as p, ".MAIN_DB_PREFIX."user as u WHERE p.userid = u.rowid";
591 $resql = $db->query($sql);
592 while ($obj = $db->fetch_object($resql)) {
593 print '<tr class="oddeven">';
594 print '<td>'.$obj->login.'</td>';
595 print '<td>'.$obj->module.'</td>';
596 print '<td>'.$obj->driver.'</td>';
597 print '<td>'.$obj->printer_name.'</td>';
598 print '<td>'.$obj->printer_location.'</td>';
599 print '<td>'.$obj->printer_id.'</td>';
600 print '<td>'.$obj->copy.'</td>';
601 print '<td class="center">'.img_picto($langs->trans("Delete"), 'delete').'</td>';
602 print "</tr>\n";
603 }
604 print '</table>';
605 print '</div>';
606}
607
608print dol_get_fiche_end();
609
610// End of page
611llxFooter();
612$db->close();
global $dolibarr_main_url_root
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
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:
Class to manage generation of HTML components Only common components must be here.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
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.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:542
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183
getSupportedOauth2Array()
Return array of tabs to use on pages to setup cron module.
oauthadmin_prepare_head()
Return array of tabs to used on pages to setup cron module.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.