27require
'../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/lib/oauth.lib.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
32use OAuth\Common\Storage\DoliStorage;
37$langs->loadLangs(array(
'admin',
'printing',
'oauth'));
39$action =
GETPOST(
'action',
'aZ09');
40$mode =
GETPOST(
'mode',
'alpha');
41$value =
GETPOST(
'value',
'alpha');
42$varname =
GETPOST(
'varname',
'alpha');
43$driver =
GETPOST(
'driver',
'alpha');
46 $langs->load($driver);
69if ($action ==
'setconst' && $user->admin) {
73 $setupconstarray =
GETPOST(
'setupdriver',
'array');
75 foreach ($setupconstarray as $setupconst) {
83 $result =
dolibarr_set_const($db, $constname, $constvalue, $consttype, 0, $constnote, $conf->entity);
99if ($action ==
'setvalue' && $user->admin) {
103 if (!($result > 0)) {
123$urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
124$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
127$form =
new Form($db);
129$title = $langs->trans(
"TokenManager");
130$help_url =
'EN:Module_OAuth|FR:Module_OAuth_FR|ES:Módulo_OAuth_ES';
132llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-admin page-oauthlogintokens');
134$linkback =
'<a href="'.DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToModuleList").
'</a>';
135print
load_fiche_titre($langs->trans(
'ConfigOAuth'), $linkback,
'title_setup');
145if ($mode ==
'setup' && $user->admin) {
146 print
'<span class="opacitymedium">'.$langs->trans(
"OAuthSetupForLogin").
"</span><br><br>\n";
149 $listinsetup = array();
150 foreach ($conf->global as $key => $val) {
151 if (!empty($val) && preg_match(
'/^OAUTH_.*_ID$/', $key)) {
152 $provider = preg_replace(
'/_ID$/',
'', $key);
153 $listinsetup[] = array(
157 $provider.
'_URLAUTHORIZE',
163 $oauthstateanticsrf = bin2hex(random_bytes(128 / 8));
166 if (!empty($listinsetup)) {
167 foreach ($listinsetup as $key) {
169 $keyforsupportedoauth2array = $key[0];
170 $keyforsupportedoauth2array = preg_replace(
'/^OAUTH_/',
'', $keyforsupportedoauth2array);
171 $keyforsupportedoauth2array = preg_replace(
'/_NAME$/',
'', $keyforsupportedoauth2array);
172 if (preg_match(
'/^.*-/', $keyforsupportedoauth2array)) {
173 $keybeforeprovider = preg_replace(
'/-.*$/',
'', $keyforsupportedoauth2array);
174 $keyforprovider = preg_replace(
'/^.*-/',
'', $keyforsupportedoauth2array);
176 $keybeforeprovider = $keyforsupportedoauth2array;
177 $keyforprovider =
'';
179 $keyforsupportedoauth2array = preg_replace(
'/-.*$/',
'', $keyforsupportedoauth2array);
180 $keyforsupportedoauth2array =
'OAUTH_'.$keyforsupportedoauth2array.
'_NAME';
183 $OAUTH_SERVICENAME = (empty($supportedoauth2array[$keyforsupportedoauth2array][
'name']) ?
'Unknown' : $supportedoauth2array[$keyforsupportedoauth2array][
'name'].($keyforprovider ?
'-'.$keyforprovider :
''));
189 $state = $shortscope;
192 if ($keyforsupportedoauth2array ==
'OAUTH_GITHUB_NAME') {
197 $urltorenew = $urlwithroot.
'/core/modules/oauth/github_oauthcallback.php?shortscope='.urlencode($shortscope).
'&state='.urlencode($shortscope).
'&backtourl='.urlencode(DOL_URL_ROOT.
'/admin/oauthlogintokens.php');
198 $urltodelete = $urlwithroot.
'/core/modules/oauth/github_oauthcallback.php?action=delete&token='.
newToken().
'&backtourl='.urlencode(DOL_URL_ROOT.
'/admin/oauthlogintokens.php');
199 $urltocheckperms =
'https://github.com/settings/applications/';
200 } elseif ($keyforsupportedoauth2array ==
'OAUTH_GOOGLE_NAME') {
204 $urltorenew = $urlwithroot.
'/core/modules/oauth/google_oauthcallback.php?shortscope='.urlencode($shortscope).
'&state='.urlencode($state).
'-'.$oauthstateanticsrf.
'&backtourl='.urlencode(DOL_URL_ROOT.
'/admin/oauthlogintokens.php');
205 $urltodelete = $urlwithroot.
'/core/modules/oauth/google_oauthcallback.php?action=delete&token='.
newToken().
'&backtourl='.urlencode(DOL_URL_ROOT.
'/admin/oauthlogintokens.php');
206 $urltocheckperms =
'https://security.google.com/settings/security/permissions';
207 } elseif (!empty($supportedoauth2array[$keyforsupportedoauth2array][
'returnurl'])) {
208 $urltorenew = $urlwithroot.$supportedoauth2array[$keyforsupportedoauth2array][
'returnurl'].
'?shortscope='.urlencode($shortscope).
'&state='.urlencode($state).
'&backtourl='.urlencode(DOL_URL_ROOT.
'/admin/oauthlogintokens.php');
209 $urltodelete = $urlwithroot.$supportedoauth2array[$keyforsupportedoauth2array][
'returnurl'].
'?action=delete&token='.
newToken().
'&backtourl='.urlencode(DOL_URL_ROOT.
'/admin/oauthlogintokens.php');
210 $urltocheckperms =
'';
214 $urltocheckperms =
'';
218 $urltorenew .=
'&keyforprovider='.urlencode($keyforprovider);
221 $urltodelete .=
'&keyforprovider='.urlencode($keyforprovider);
227 require_once DOL_DOCUMENT_ROOT.
'/includes/OAuth/bootstrap.php';
229 $storage =
new DoliStorage($db, $conf, $keyforprovider);
232 print
'<!-- '.$OAUTH_SERVICENAME.
' -->'.
"\n";
233 $tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME);
243 $refreshtoken =
false;
248 if (is_object($tokenobj)) {
249 $expire = ($tokenobj->getEndOfLife() !== $tokenobj::EOL_NEVER_EXPIRES && $tokenobj->getEndOfLife() !== $tokenobj::EOL_UNKNOWN && time() > ($tokenobj->getEndOfLife() - 30));
251 if ($key[1] !=
'' && $key[2] !=
'') {
252 if (is_object($tokenobj)) {
253 $refreshtoken = $tokenobj->getRefreshToken();
255 $endoflife = $tokenobj->getEndOfLife();
256 if ($endoflife == $tokenobj::EOL_NEVER_EXPIRES) {
257 $expiredat = $langs->trans(
"Never");
258 } elseif ($endoflife == $tokenobj::EOL_UNKNOWN) {
259 $expiredat = $langs->trans(
"Unknown");
268 print
'<form method="post" action="'.$_SERVER[
"PHP_SELF"].
'?mode=setup&driver='.$driver.
'" autocomplete="off">';
269 print
'<input type="hidden" name="token" value="'.newToken().
'">';
270 print
'<input type="hidden" name="action" value="setconst">';
271 print
'<input type="hidden" name="page_y" value="">';
273 print
'<div class="div-table-responsive-no-min">';
274 print
'<table class="noborder centpercent">'.
"\n";
277 $label = $langs->trans($keyforsupportedoauth2array);
278 print
'<tr class="liste_titre">';
279 print
'<th class="titlefieldcreate">';
280 print
img_picto(
'', $supportedoauth2array[$keyforsupportedoauth2array][
'picto'],
'class="pictofixedwidth"');
281 if ($label == $keyforsupportedoauth2array) {
282 print $supportedoauth2array[$keyforsupportedoauth2array][
'name'];
286 if ($keyforprovider) {
287 print
' (<b>'.$keyforprovider.
'</b>)';
289 print
' (<b>'.$langs->trans(
"NoName").
'</b>)';
296 print
'<tr class="oddeven">';
299 print $langs->trans(
"OAuthIDSecret").
'</td>';
301 print
'<span class="opacitymedium">'.$langs->trans(
"SeePreviousTab").
'</span>';
308 print
'<tr class="oddeven">';
309 print
'<td>'.$langs->trans(
"Scopes").
'</td>';
310 print
'<td colspan="2">';
312 print $currentscopes;
315 print
'<tr class="oddeven">';
318 print $langs->trans(
"IsTokenGenerated");
321 if ($keyforprovider !=
'Login') {
322 if (is_object($tokenobj)) {
323 print $form->textwithpicto(
yn(1), $langs->trans(
"HasAccessToken").
' : '.
dol_print_date($storage->date_modification,
'dayhour').
' state='.
dol_escape_htmltag($storage->state));
325 print
'<span class="opacitymedium">'.$langs->trans(
"NoAccessToken").
'</span>';
328 print
'<span class="opacitymedium">'.$langs->trans(
"TokenNotRequiredForOAuthLogin").
'</span>';
331 print
'<td width="50%">';
332 if ($keyforprovider !=
'Login') {
334 if (is_object($tokenobj)) {
337 print
'<a class="button smallpaddingimp reposition" href="'.$urltodelete.
'">'.$langs->trans(
'DeleteAccess').
'</a><br>';
339 print
'<span class="opacitymedium">'.$langs->trans(
'GoOnTokenProviderToDeleteToken').
'</span><br>';
344 print
'<a class="button smallpaddingimp reposition" href="'.$urltorenew.
'">'.$langs->trans(
'GetAccess').
'</a>';
345 print $form->textwithpicto(
'', $langs->trans(
'RequestAccess'));
349 if ($urltocheckperms) {
350 print
'<br>'.$langs->trans(
"ToCheckDeleteTokenOnProvider", $OAUTH_SERVICENAME).
': <a href="'.$urltocheckperms.
'" target="_'.strtolower($OAUTH_SERVICENAME).
'">'.$urltocheckperms.
'</a>';
356 print
'<tr class="oddeven">';
359 print $langs->trans(
"Token").
'</td>';
360 print
'<td colspan="2">';
362 if (is_object($tokenobj)) {
363 $tokentoshow = $tokenobj->getAccessToken();
375 if (is_object($tokenobj)) {
377 print
'<tr class="oddeven">';
380 print $langs->trans(
"TOKEN_REFRESH");
382 print
'<td colspan="2">';
388 print
'<tr class="oddeven">';
391 print $langs->trans(
"TOKEN_EXPIRED");
393 print
'<td colspan="2">';
399 print
'<tr class="oddeven">';
402 print $langs->trans(
"TOKEN_EXPIRE_AT");
404 print
'<td colspan="2">';
413 if (!empty($driver)) {
414 if ($submit_enabled) {
415 print $form->buttonsSaveCancel(
"Modify",
'');
425if ($mode ==
'test' && $user->admin) {
426 print $langs->trans(
'PrintTestDesc'.$driver).
"<br><br>\n";
428 print
'<div class="div-table-responsive-no-min">';
429 print
'<table class="noborder centpercent">';
430 if (!empty($driver)) {
431 require_once DOL_DOCUMENT_ROOT.
'/core/modules/printing/'.$driver.
'.modules.php';
432 $classname =
'printing_'.$driver;
433 $langs->load($driver);
434 $printer =
new $classname($db);
436 if (count($printer->getlistAvailablePrinters())) {
437 if ($printer->listAvailablePrinters() == 0) {
438 print $printer->resprint;
443 print $langs->trans(
'PleaseConfigureDriverfromList');
451if ($mode ==
'userconf' && $user->admin) {
452 print $langs->trans(
'PrintUserConfDesc'.$driver).
"<br><br>\n";
454 print
'<div class="div-table-responsive">';
455 print
'<table class="noborder centpercent">';
456 print
'<tr class="liste_titre">';
457 print
'<th>'.$langs->trans(
"User").
'</th>';
458 print
'<th>'.$langs->trans(
"PrintModule").
'</th>';
459 print
'<th>'.$langs->trans(
"PrintDriver").
'</th>';
460 print
'<th>'.$langs->trans(
"Printer").
'</th>';
461 print
'<th>'.$langs->trans(
"PrinterLocation").
'</th>';
462 print
'<th>'.$langs->trans(
"PrinterId").
'</th>';
463 print
'<th>'.$langs->trans(
"NumberOfCopy").
'</th>';
464 print
'<th class="center">'.$langs->trans(
"Delete").
'</th>';
466 $sql =
"SELECT p.rowid, p.printer_name, p.printer_location, p.printer_id, p.copy, p.module, p.driver, p.userid, u.login";
467 $sql .=
" FROM ".MAIN_DB_PREFIX.
"printing as p, ".MAIN_DB_PREFIX.
"user as u WHERE p.userid = u.rowid";
468 $resql = $db->query($sql);
469 while ($obj = $db->fetch_object($resql)) {
470 print
'<tr class="oddeven">';
471 print
'<td>'.$obj->login.
'</td>';
472 print
'<td>'.$obj->module.
'</td>';
473 print
'<td>'.$obj->driver.
'</td>';
474 print
'<td>'.$obj->printer_name.
'</td>';
475 print
'<td>'.$obj->printer_location.
'</td>';
476 print
'<td>'.$obj->printer_id.
'</td>';
477 print
'<td>'.$obj->copy.
'</td>';
478 print
'<td class="center">'.img_picto($langs->trans(
"Delete"),
'delete').
'</td>';
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).
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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 dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
getSupportedOauth2Array()
Return array of tabs to used 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.