27 require
'../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/oauth.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
31 use 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');
42 if (!empty($driver)) {
43 $langs->load($driver);
66 if ($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);
96 if ($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;
126 llxHeader(
'', $langs->trans(
"TokenManager"));
128 $linkback =
'<a href="'.DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToModuleList").
'</a>';
129 print
load_fiche_titre($langs->trans(
'ConfigOAuth'), $linkback,
'title_setup');
139 if ($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 foreach ($listinsetup as $key) {
161 $keyforsupportedoauth2array = $key[0];
162 $keyforsupportedoauth2array = preg_replace(
'/^OAUTH_/',
'', $keyforsupportedoauth2array);
163 $keyforsupportedoauth2array = preg_replace(
'/_NAME$/',
'', $keyforsupportedoauth2array);
164 if (preg_match(
'/^.*-/', $keyforsupportedoauth2array)) {
165 $keyforprovider = preg_replace(
'/^.*-/',
'', $keyforsupportedoauth2array);
167 $keyforprovider =
'';
169 $keyforsupportedoauth2array = preg_replace(
'/-.*$/',
'', $keyforsupportedoauth2array);
170 $keyforsupportedoauth2array =
'OAUTH_'.$keyforsupportedoauth2array.
'_NAME';
173 $OAUTH_SERVICENAME = (empty($supportedoauth2array[$keyforsupportedoauth2array][
'name']) ?
'Unknown' : $supportedoauth2array[$keyforsupportedoauth2array][
'name'].($keyforprovider ?
'-'.$keyforprovider :
''));
179 $state = $shortscope;
183 if ($keyforsupportedoauth2array ==
'OAUTH_GITHUB_NAME') {
188 $urltorenew = $urlwithroot.
'/core/modules/oauth/github_oauthcallback.php?shortscope='.urlencode($shortscope).
'&state='.$shortscope.
'&backtourl='.urlencode(DOL_URL_ROOT.
'/admin/oauthlogintokens.php');
189 $urltodelete = $urlwithroot.
'/core/modules/oauth/github_oauthcallback.php?action=delete&token='.
newToken().
'&backtourl='.urlencode(DOL_URL_ROOT.
'/admin/oauthlogintokens.php');
190 $urltocheckperms =
'https://github.com/settings/applications/';
191 } elseif ($keyforsupportedoauth2array ==
'OAUTH_GOOGLE_NAME') {
195 $urltorenew = $urlwithroot.
'/core/modules/oauth/google_oauthcallback.php?shortscope='.urlencode($shortscope).
'&state='.urlencode($state).
'-'.$oauthstateanticsrf.
'&backtourl='.urlencode(DOL_URL_ROOT.
'/admin/oauthlogintokens.php');
196 $urltodelete = $urlwithroot.
'/core/modules/oauth/google_oauthcallback.php?action=delete&token='.
newToken().
'&backtourl='.urlencode(DOL_URL_ROOT.
'/admin/oauthlogintokens.php');
197 $urltocheckperms =
'https://security.google.com/settings/security/permissions';
198 } elseif ($keyforsupportedoauth2array ==
'OAUTH_STRIPE_TEST_NAME') {
199 $urltorenew = $urlwithroot.
'/core/modules/oauth/stripetest_oauthcallback.php?shortscope='.urlencode($shortscope).
'&state='.urlencode($state).
'&backtourl='.urlencode(DOL_URL_ROOT.
'/admin/oauthlogintokens.php');
201 $urltocheckperms =
'';
202 } elseif ($keyforsupportedoauth2array ==
'OAUTH_STRIPE_LIVE_NAME') {
203 $urltorenew = $urlwithroot.
'/core/modules/oauth/stripelive_oauthcallback.php?shortscope='.urlencode($shortscope).
'&state='.urlencode($state).
'&backtourl='.urlencode(DOL_URL_ROOT.
'/admin/oauthlogintokens.php');
205 $urltocheckperms =
'';
206 } elseif ($keyforsupportedoauth2array =
'OAUTH_OTHER_NAME') {
207 $urltorenew = $urlwithroot.
'/core/modules/oauth/generic_oauthcallback.php?shortscope='.urlencode($shortscope).
'&state='.urlencode($state).
'&backtourl='.urlencode(DOL_URL_ROOT.
'/admin/oauthlogintokens.php');
209 $urltocheckperms =
'';
213 $urltocheckperms =
'';
217 $urltorenew .=
'&keyforprovider='.urlencode($keyforprovider);
220 $urltodelete .=
'&keyforprovider='.urlencode($keyforprovider);
227 require_once DOL_DOCUMENT_ROOT.
'/includes/OAuth/bootstrap.php';
229 $storage =
new DoliStorage($db, $conf);
231 $tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME);
237 $refreshtoken =
false;
242 if (is_object($tokenobj)) {
243 $expire = ($tokenobj->getEndOfLife() !== $tokenobj::EOL_NEVER_EXPIRES && $tokenobj->getEndOfLife() !== $tokenobj::EOL_UNKNOWN && time() > ($tokenobj->getEndOfLife() - 30));
245 if ($key[1] !=
'' && $key[2] !=
'') {
246 if (is_object($tokenobj)) {
247 $refreshtoken = $tokenobj->getRefreshToken();
249 $endoflife = $tokenobj->getEndOfLife();
250 if ($endoflife == $tokenobj::EOL_NEVER_EXPIRES) {
251 $expiredat = $langs->trans(
"Never");
252 } elseif ($endoflife == $tokenobj::EOL_UNKNOWN) {
253 $expiredat = $langs->trans(
"Unknown");
262 print
'<form method="post" action="'.$_SERVER[
"PHP_SELF"].
'?mode=setup&driver='.$driver.
'" autocomplete="off">';
263 print
'<input type="hidden" name="token" value="'.newToken().
'">';
264 print
'<input type="hidden" name="action" value="setconst">';
266 print
'<div class="div-table-responsive-no-min">';
267 print
'<table class="noborder centpercent">'.
"\n";
270 $label = $langs->trans($keyforsupportedoauth2array);
271 print
'<tr class="liste_titre">';
272 print
'<th class="titlefieldcreate">';
273 print
img_picto(
'', $supportedoauth2array[$keyforsupportedoauth2array][
'picto'],
'class="pictofixedwidth"');
274 if ($label == $keyforsupportedoauth2array) {
275 print $supportedoauth2array[$keyforsupportedoauth2array][
'name'];
279 if ($keyforprovider) {
280 print
' (<b>'.$keyforprovider.
'</b>)';
282 print
' (<b>'.$langs->trans(
"NoName").
'</b>)';
289 print
'<tr class="oddeven">';
290 print
'<td'.(empty($key[
'required']) ?
'' :
' class="required"').
'>';
292 print $langs->trans(
"OAuthIDSecret").
'</td>';
294 print
'<span class="opacitymedium">'.$langs->trans(
"SeePreviousTab").
'</span>';
301 print
'<tr class="oddeven">';
302 print
'<td>'.$langs->trans(
"Scopes").
'</td>';
303 print
'<td colspan="2">';
305 print $currentscopes;
308 print
'<tr class="oddeven">';
309 print
'<td'.(empty($key[
'required']) ?
'' :
' class="required"').
'>';
311 print $langs->trans(
"IsTokenGenerated");
314 if (is_object($tokenobj)) {
317 print
'<span class="opacitymedium">'.$langs->trans(
"NoAccessToken").
'</span>';
320 print
'<td width="50%">';
322 if (is_object($tokenobj)) {
324 print
'<a class="button smallpaddingimp" href="'.$urltodelete.
'">'.$langs->trans(
'DeleteAccess').
'</a><br>';
328 print
'<a class="button smallpaddingimp" href="'.$urltorenew.
'">'.$langs->trans(
'GetAccess').
'</a>';
329 print
$form->textwithpicto(
'', $langs->trans(
'RequestAccess'));
333 if ($urltocheckperms) {
334 print
'<br>'.$langs->trans(
"ToCheckDeleteTokenOnProvider", $OAUTH_SERVICENAME).
': <a href="'.$urltocheckperms.
'" target="_'.strtolower($OAUTH_SERVICENAME).
'">'.$urltocheckperms.
'</a>';
339 print
'<tr class="oddeven">';
340 print
'<td'.(empty($key[
'required']) ?
'' :
' class="required"').
'>';
342 print $langs->trans(
"Token").
'</td>';
343 print
'<td colspan="2">';
345 if (is_object($tokenobj)) {
347 $tokentoshow = $tokenobj->getAccessToken();
359 if (is_object($tokenobj)) {
361 print
'<tr class="oddeven">';
362 print
'<td'.($key[
'required'] ?
' class="required"' :
'').
'>';
364 print $langs->trans(
"TOKEN_REFRESH");
366 print
'<td colspan="2">';
372 print
'<tr class="oddeven">';
373 print
'<td'.(empty($key[
'required']) ?
'' :
' class="required"').
'>';
375 print $langs->trans(
"TOKEN_EXPIRED");
377 print
'<td colspan="2">';
383 print
'<tr class="oddeven">';
384 print
'<td'.(empty($key[
'required']) ?
'' :
' class="required"').
'>';
386 print $langs->trans(
"TOKEN_EXPIRE_AT");
388 print
'<td colspan="2">';
397 if (!empty($driver)) {
398 if ($submit_enabled) {
399 print
$form->buttonsSaveCancel(
"Modify",
'');
408 if ($mode ==
'test' && $user->admin) {
409 print $langs->trans(
'PrintTestDesc'.$driver).
"<br><br>\n";
411 print
'<div class="div-table-responsive-no-min">';
412 print
'<table class="noborder centpercent">';
413 if (!empty($driver)) {
414 require_once DOL_DOCUMENT_ROOT.
'/core/modules/printing/'.$driver.
'.modules.php';
415 $classname =
'printing_'.$driver;
416 $langs->load($driver);
417 $printer =
new $classname($db);
419 if (count($printer->getlistAvailablePrinters())) {
420 if ($printer->listAvailablePrinters() == 0) {
421 print $printer->resprint;
426 print $langs->trans(
'PleaseConfigureDriverfromList');
434 if ($mode ==
'userconf' && $user->admin) {
435 print $langs->trans(
'PrintUserConfDesc'.$driver).
"<br><br>\n";
437 print
'<div class="div-table-responsive">';
438 print
'<table class="noborder centpercent">';
439 print
'<tr class="liste_titre">';
440 print
'<th>'.$langs->trans(
"User").
'</th>';
441 print
'<th>'.$langs->trans(
"PrintModule").
'</th>';
442 print
'<th>'.$langs->trans(
"PrintDriver").
'</th>';
443 print
'<th>'.$langs->trans(
"Printer").
'</th>';
444 print
'<th>'.$langs->trans(
"PrinterLocation").
'</th>';
445 print
'<th>'.$langs->trans(
"PrinterId").
'</th>';
446 print
'<th>'.$langs->trans(
"NumberOfCopy").
'</th>';
447 print
'<th class="center">'.$langs->trans(
"Delete").
'</th>';
449 $sql =
"SELECT p.rowid, p.printer_name, p.printer_location, p.printer_id, p.copy, p.module, p.driver, p.userid, u.login";
450 $sql .=
" FROM ".MAIN_DB_PREFIX.
"printing as p, ".MAIN_DB_PREFIX.
"user as u WHERE p.userid = u.rowid";
451 $resql = $db->query($sql);
452 while ($obj = $db->fetch_object(
$resql)) {
453 print
'<tr class="oddeven">';
454 print
'<td>'.$obj->login.
'</td>';
455 print
'<td>'.$obj->module.
'</td>';
456 print
'<td>'.$obj->driver.
'</td>';
457 print
'<td>'.$obj->printer_name.
'</td>';
458 print
'<td>'.$obj->printer_location.
'</td>';
459 print
'<td>'.$obj->printer_id.
'</td>';
460 print
'<td>'.$obj->copy.
'</td>';
461 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.
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.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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)
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.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.
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.