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';
31use OAuth\Common\Storage\DoliStorage;
34$langs->loadLangs(array(
'admin',
'printing',
'oauth'));
36$action =
GETPOST(
'action',
'aZ09');
37$mode =
GETPOST(
'mode',
'alpha');
38$value =
GETPOST(
'value',
'alpha');
39$varname =
GETPOST(
'varname',
'alpha');
40$driver =
GETPOST(
'driver',
'alpha');
43 $langs->load($driver);
66if ($action ==
'setconst' && $user->admin) {
70 $setupconstarray =
GETPOST(
'setupdriver',
'array');
72 foreach ($setupconstarray as $setupconst) {
80 $result =
dolibarr_set_const($db, $constname, $constvalue, $consttype, 0, $constnote, $conf->entity);
96if ($action ==
'setvalue' && $user->admin) {
100 if (!($result > 0)) {
120$urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
121$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
124$form =
new Form($db);
126llxHeader(
'', $langs->trans(
"TokenManager"));
128$linkback =
'<a href="'.DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToModuleList").
'</a>';
129print
load_fiche_titre($langs->trans(
'ConfigOAuth'), $linkback,
'title_setup');
139if ($mode ==
'setup' && $user->admin) {
140 print
'<span class="opacitymedium">'.$langs->trans(
"OAuthSetupForLogin").
"</span><br><br>\n";
143 foreach ($conf->global as $key => $val) {
144 if (!empty($val) && preg_match(
'/^OAUTH_.*_ID$/', $key)) {
145 $provider = preg_replace(
'/_ID$/',
'', $key);
146 $listinsetup[] = array(
150 $provider.
'_URLAUTHORIZE',
156 $oauthstateanticsrf = bin2hex(random_bytes(128/8));
159 if (!empty($listinsetup)) {
160 foreach ($listinsetup as $key) {
162 $keyforsupportedoauth2array = $key[0];
163 $keyforsupportedoauth2array = preg_replace(
'/^OAUTH_/',
'', $keyforsupportedoauth2array);
164 $keyforsupportedoauth2array = preg_replace(
'/_NAME$/',
'', $keyforsupportedoauth2array);
165 if (preg_match(
'/^.*-/', $keyforsupportedoauth2array)) {
166 $keybeforeprovider = preg_replace(
'/-.*$/',
'', $keyforsupportedoauth2array);
167 $keyforprovider = preg_replace(
'/^.*-/',
'', $keyforsupportedoauth2array);
169 $keybeforeprovider = $keyforsupportedoauth2array;
170 $keyforprovider =
'';
172 $keyforsupportedoauth2array = preg_replace(
'/-.*$/',
'', $keyforsupportedoauth2array);
173 $keyforsupportedoauth2array =
'OAUTH_'.$keyforsupportedoauth2array.
'_NAME';
176 $OAUTH_SERVICENAME = (empty($supportedoauth2array[$keyforsupportedoauth2array][
'name']) ?
'Unknown' : $supportedoauth2array[$keyforsupportedoauth2array][
'name'].($keyforprovider ?
'-'.$keyforprovider :
''));
182 $state = $shortscope;
185 if ($keyforsupportedoauth2array ==
'OAUTH_GITHUB_NAME') {
190 $urltorenew = $urlwithroot.
'/core/modules/oauth/github_oauthcallback.php?shortscope='.urlencode($shortscope).
'&state='.urlencode($shortscope).
'&backtourl='.urlencode(DOL_URL_ROOT.
'/admin/oauthlogintokens.php');
191 $urltodelete = $urlwithroot.
'/core/modules/oauth/github_oauthcallback.php?action=delete&token='.newToken().
'&backtourl='.urlencode(DOL_URL_ROOT.
'/admin/oauthlogintokens.php');
192 $urltocheckperms =
'https://github.com/settings/applications/';
193 } elseif ($keyforsupportedoauth2array ==
'OAUTH_GOOGLE_NAME') {
197 $urltorenew = $urlwithroot.
'/core/modules/oauth/google_oauthcallback.php?shortscope='.urlencode($shortscope).
'&state='.urlencode($state).
'-'.$oauthstateanticsrf.
'&backtourl='.urlencode(DOL_URL_ROOT.
'/admin/oauthlogintokens.php');
198 $urltodelete = $urlwithroot.
'/core/modules/oauth/google_oauthcallback.php?action=delete&token='.newToken().
'&backtourl='.urlencode(DOL_URL_ROOT.
'/admin/oauthlogintokens.php');
199 $urltocheckperms =
'https://security.google.com/settings/security/permissions';
200 } elseif (!empty($supportedoauth2array[$keyforsupportedoauth2array][
'returnurl'])) {
201 $urltorenew = $urlwithroot.$supportedoauth2array[$keyforsupportedoauth2array][
'returnurl'].
'?shortscope='.urlencode($shortscope).
'&state='.urlencode($state).
'&backtourl='.urlencode(DOL_URL_ROOT.
'/admin/oauthlogintokens.php');
202 $urltodelete = $urlwithroot.$supportedoauth2array[$keyforsupportedoauth2array][
'returnurl'].
'?action=delete&token='.newToken().
'&backtourl='.urlencode(DOL_URL_ROOT.
'/admin/oauthlogintokens.php');
203 $urltocheckperms =
'';
207 $urltocheckperms =
'';
211 $urltorenew .=
'&keyforprovider='.urlencode($keyforprovider);
214 $urltodelete .=
'&keyforprovider='.urlencode($keyforprovider);
220 require_once DOL_DOCUMENT_ROOT.
'/includes/OAuth/bootstrap.php';
222 $storage =
new DoliStorage($db, $conf, $keyforprovider);
225 print
'<!-- '.$OAUTH_SERVICENAME.
' -->'.
"\n";
226 $tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME);
236 $refreshtoken =
false;
241 if (is_object($tokenobj)) {
242 $expire = ($tokenobj->getEndOfLife() !== $tokenobj::EOL_NEVER_EXPIRES && $tokenobj->getEndOfLife() !== $tokenobj::EOL_UNKNOWN && time() > ($tokenobj->getEndOfLife() - 30));
244 if ($key[1] !=
'' && $key[2] !=
'') {
245 if (is_object($tokenobj)) {
246 $refreshtoken = $tokenobj->getRefreshToken();
248 $endoflife = $tokenobj->getEndOfLife();
249 if ($endoflife == $tokenobj::EOL_NEVER_EXPIRES) {
250 $expiredat = $langs->trans(
"Never");
251 } elseif ($endoflife == $tokenobj::EOL_UNKNOWN) {
252 $expiredat = $langs->trans(
"Unknown");
261 print
'<form method="post" action="'.$_SERVER[
"PHP_SELF"].
'?mode=setup&driver='.$driver.
'" autocomplete="off">';
262 print
'<input type="hidden" name="token" value="'.newToken().
'">';
263 print
'<input type="hidden" name="action" value="setconst">';
265 print
'<div class="div-table-responsive-no-min">';
266 print
'<table class="noborder centpercent">'.
"\n";
269 $label = $langs->trans($keyforsupportedoauth2array);
270 print
'<tr class="liste_titre">';
271 print
'<th class="titlefieldcreate">';
272 print
img_picto(
'', $supportedoauth2array[$keyforsupportedoauth2array][
'picto'],
'class="pictofixedwidth"');
273 if ($label == $keyforsupportedoauth2array) {
274 print $supportedoauth2array[$keyforsupportedoauth2array][
'name'];
278 if ($keyforprovider) {
279 print
' (<b>'.$keyforprovider.
'</b>)';
281 print
' (<b>'.$langs->trans(
"NoName").
'</b>)';
288 print
'<tr class="oddeven">';
289 print
'<td'.(empty($key[
'required']) ?
'' :
' class="required"').
'>';
291 print $langs->trans(
"OAuthIDSecret").
'</td>';
293 print
'<span class="opacitymedium">'.$langs->trans(
"SeePreviousTab").
'</span>';
300 print
'<tr class="oddeven">';
301 print
'<td>'.$langs->trans(
"Scopes").
'</td>';
302 print
'<td colspan="2">';
304 print $currentscopes;
307 print
'<tr class="oddeven">';
308 print
'<td'.(empty($key[
'required']) ?
'' :
' class="required"').
'>';
310 print $langs->trans(
"IsTokenGenerated");
313 if (is_object($tokenobj)) {
314 print $form->textwithpicto(
yn(1), $langs->trans(
"HasAccessToken").
' : '.
dol_print_date($storage->date_modification,
'dayhour').
' state='.
dol_escape_htmltag($storage->state));
316 print
'<span class="opacitymedium">'.$langs->trans(
"NoAccessToken").
'</span>';
319 print
'<td width="50%">';
321 if (is_object($tokenobj)) {
324 print
'<a class="button smallpaddingimp" href="'.$urltodelete.
'">'.$langs->trans(
'DeleteAccess').
'</a><br>';
326 print
'<span class="opacitymedium">'.$langs->trans(
'GoOnTokenProviderToDeleteToken').
'</span><br>';
331 print
'<a class="button smallpaddingimp" href="'.$urltorenew.
'">'.$langs->trans(
'GetAccess').
'</a>';
332 print $form->textwithpicto(
'', $langs->trans(
'RequestAccess'));
336 if ($urltocheckperms) {
337 print
'<br>'.$langs->trans(
"ToCheckDeleteTokenOnProvider", $OAUTH_SERVICENAME).
': <a href="'.$urltocheckperms.
'" target="_'.strtolower($OAUTH_SERVICENAME).
'">'.$urltocheckperms.
'</a>';
342 print
'<tr class="oddeven">';
343 print
'<td'.(empty($key[
'required']) ?
'' :
' class="required"').
'>';
345 print $langs->trans(
"Token").
'</td>';
346 print
'<td colspan="2">';
348 if (is_object($tokenobj)) {
349 $tokentoshow = $tokenobj->getAccessToken();
361 if (is_object($tokenobj)) {
363 print
'<tr class="oddeven">';
364 print
'<td'.(empty($key[
'required']) ?
'' :
' class="required"').
'>';
366 print $langs->trans(
"TOKEN_REFRESH");
368 print
'<td colspan="2">';
374 print
'<tr class="oddeven">';
375 print
'<td'.(empty($key[
'required']) ?
'' :
' class="required"').
'>';
377 print $langs->trans(
"TOKEN_EXPIRED");
379 print
'<td colspan="2">';
385 print
'<tr class="oddeven">';
386 print
'<td'.(empty($key[
'required']) ?
'' :
' class="required"').
'>';
388 print $langs->trans(
"TOKEN_EXPIRE_AT");
390 print
'<td colspan="2">';
399 if (!empty($driver)) {
400 if ($submit_enabled) {
401 print $form->buttonsSaveCancel(
"Modify",
'');
411if ($mode ==
'test' && $user->admin) {
412 print $langs->trans(
'PrintTestDesc'.$driver).
"<br><br>\n";
414 print
'<div class="div-table-responsive-no-min">';
415 print
'<table class="noborder centpercent">';
416 if (!empty($driver)) {
417 require_once DOL_DOCUMENT_ROOT.
'/core/modules/printing/'.$driver.
'.modules.php';
418 $classname =
'printing_'.$driver;
419 $langs->load($driver);
420 $printer =
new $classname($db);
422 if (count($printer->getlistAvailablePrinters())) {
423 if ($printer->listAvailablePrinters() == 0) {
424 print $printer->resprint;
429 print $langs->trans(
'PleaseConfigureDriverfromList');
437if ($mode ==
'userconf' && $user->admin) {
438 print $langs->trans(
'PrintUserConfDesc'.$driver).
"<br><br>\n";
440 print
'<div class="div-table-responsive">';
441 print
'<table class="noborder centpercent">';
442 print
'<tr class="liste_titre">';
443 print
'<th>'.$langs->trans(
"User").
'</th>';
444 print
'<th>'.$langs->trans(
"PrintModule").
'</th>';
445 print
'<th>'.$langs->trans(
"PrintDriver").
'</th>';
446 print
'<th>'.$langs->trans(
"Printer").
'</th>';
447 print
'<th>'.$langs->trans(
"PrinterLocation").
'</th>';
448 print
'<th>'.$langs->trans(
"PrinterId").
'</th>';
449 print
'<th>'.$langs->trans(
"NumberOfCopy").
'</th>';
450 print
'<th class="center">'.$langs->trans(
"Delete").
'</th>';
452 $sql =
"SELECT p.rowid, p.printer_name, p.printer_location, p.printer_id, p.copy, p.module, p.driver, p.userid, u.login";
453 $sql .=
" FROM ".MAIN_DB_PREFIX.
"printing as p, ".MAIN_DB_PREFIX.
"user as u WHERE p.userid = u.rowid";
454 $resql = $db->query($sql);
455 while ($obj = $db->fetch_object($resql)) {
456 print
'<tr class="oddeven">';
457 print
'<td>'.$obj->login.
'</td>';
458 print
'<td>'.$obj->module.
'</td>';
459 print
'<td>'.$obj->driver.
'</td>';
460 print
'<td>'.$obj->printer_name.
'</td>';
461 print
'<td>'.$obj->printer_location.
'</td>';
462 print
'<td>'.$obj->printer_id.
'</td>';
463 print
'<td>'.$obj->copy.
'</td>';
464 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($titre, $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).
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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_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...
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.