28require
'../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/oauth.lib.php';
46$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
50$langs->loadLangs(array(
'admin',
'oauth',
'modulebuilder'));
57$action =
GETPOST(
'action',
'aZ09');
58$provider =
GETPOST(
'provider',
'aZ09');
59$label =
GETPOST(
'label',
'aZ09');
61$servicetoeditname =
GETPOST(
'servicetoeditname',
'aZ09');
70if ($action ==
'add') {
71 if ($provider && $provider !=
'-1') {
72 $constname = strtoupper($provider).($label ?
'-'.$label :
'').
'_ID';
75 setEventMessages($langs->trans(
"AOAuthEntryForThisProviderAndLabelAlreadyHasAKey"),
null,
'errors');
79 setEventMessages($langs->trans(
"OAuthProviderAdded"),
null);
83if ($action ==
'update') {
84 foreach (
$conf->global as $key => $val) {
85 if (!empty($val) && preg_match(
'/^OAUTH_.+_ID$/', $key)) {
86 $constvalue = str_replace(
'_ID',
'', $key);
87 $newconstvalue = $constvalue;
89 $newconstvalue = preg_replace(
'/-.*$/',
'', $constvalue).
'-'.preg_replace(
'/[^a-z]/',
'',
GETPOST($constvalue.
'_NAME'));
104 $cleanurl =
GETPOST($constvalue.
'_URL');
105 $cleanurl = preg_replace(
'/\/$/',
'', $cleanurl);
121 if (is_array(
GETPOST($constvalue.
'_SCOPE'))) {
122 $scopestring = implode(
',',
GETPOST($constvalue.
'_SCOPE'));
124 $scopestring =
GETPOST($constvalue.
'_SCOPE');
129 } elseif ($newconstvalue !== $constvalue) {
136 if ($constvalue !== $newconstvalue) {
144 $oldname = preg_replace(
'/^OAUTH_/',
'', $constvalue);
145 $oldprovider = ucfirst(strtolower(preg_replace(
'/-.*$/',
'', $oldname)));
146 $oldlabel = preg_replace(
'/^.*-/',
'', $oldname);
147 $newlabel = preg_replace(
'/^.*-/',
'', $newconstvalue);
150 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"oauth_token";
151 $sql.=
" SET service = '".$db->escape($oldprovider.
"-".$newlabel).
"'";
152 $sql.=
" WHERE service = '".$db->escape($oldprovider.
"-".$oldlabel).
"'";
155 $resql = $db->query($sql);
162 if (!
dolibarr_set_const($db,
'MAIN_MAIL_SMTPS_OAUTH_SERVICE', strtoupper($oldprovider).
'-'.$newlabel,
'chaine', 0,
'',
$conf->entity)) {
172 setEventMessages($langs->trans(
"SetupSaved"),
null);
174 setEventMessages($langs->trans(
"Error"),
null,
'errors');
178if ($action ==
'confirm_delete') {
179 $provider =
GETPOST(
'provider',
'aZ09');
182 $globalkey = empty($provider) ? $label : $label.
'-'.$provider;
185 $backtourl = DOL_URL_ROOT.
'/admin/oauth.php?action=delete_entry&provider='.$provider.
'&label='.$label.
'&token='.
newToken();
187 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
188 $callbacktodel = $urlwithroot;
189 if ($label ==
'OAUTH_GOOGLE') {
190 $callbacktodel .=
'/core/modules/oauth/google_oauthcallback.php?action=delete&keyforprovider='.$provider.
'&token='.
newToken().
'&backtourl='.urlencode($backtourl);
191 } elseif ($label ==
'OAUTH_GITHUB') {
192 $callbacktodel .=
'/core/modules/oauth/github_oauthcallback.php?action=delete&keyforprovider='.$provider.
'&token='.
newToken().
'&backtourl='.urlencode($backtourl);
193 } elseif ($label ==
'OAUTH_STRIPELIVE') {
194 $callbacktodel .=
'/core/modules/oauth/stripelive_oauthcallback.php?action=delete&keyforprovider='.$provider.
'&token='.
newToken().
'&backtourl='.urlencode($backtourl);
195 } elseif ($label ==
'OAUTH_STRIPETEST') {
196 $callbacktodel .=
'/core/modules/oauth/stripetest_oauthcallback.php?action=delete&keyforprovider='.$provider.
'&token='.
newToken().
'&backtourl='.urlencode($backtourl);
197 } elseif ($label ==
'OAUTH_MICROSOFT') {
198 $callbacktodel .=
'/core/modules/oauth/microsoft_oauthcallback.php?action=delete&keyforprovider='.$provider.
'&token='.
newToken().
'&backtourl='.urlencode($backtourl);
199 } elseif ($label ==
'OAUTH_MICROSOFT2') {
200 $callbacktodel .=
'/core/modules/oauth/microsoft2_oauthcallback.php?action=delete&keyforprovider='.$provider.
'&token='.
newToken().
'&backtourl='.urlencode($backtourl);
201 } elseif ($label ==
'OAUTH_MICROSOFTAPP') {
202 $callbacktodel .=
'/core/modules/oauth/microsoftapp_oauthcallback.php?action=delete&keyforprovider='.$provider.
'&token='.
newToken().
'&backtourl='.urlencode($backtourl);
203 } elseif ($label ==
'OAUTH_GENERIC') {
204 $callbacktodel .=
'/core/modules/oauth/generic_oauthcallback.php?action=delete&keyforprovider='.$provider.
'&token='.
newToken().
'&backtourl='.urlencode($backtourl);
206 header(
"Location: ".$callbacktodel);
209 $action =
'delete_entry';
213if ($action ==
'delete_entry') {
214 $provider =
GETPOST(
'provider',
'aZ09');
217 $globalkey = empty($provider) ? $label : $label.
'-'.$provider;
226 setEventMessages($langs->trans(
"ErrorInEntryDeletion"),
null,
'errors');
229 setEventMessages($langs->trans(
"EntryDeleted"),
null);
237$form =
new Form($db);
239$title = $langs->trans(
'ConfigOAuth');
240$help_url =
'EN:Module_OAuth|FR:Module_OAuth_FR|ES:Módulo_OAuth_ES';
242llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-admin page-oauth');
245if ($action ==
'delete') {
246 $formquestion = array();
247 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?provider='.
GETPOST(
'provider').
'&label='.
GETPOST(
'label'), $langs->trans(
'OAuthServiceConfirmDeleteTitle'), $langs->trans(
'OAuthServiceConfirmDeleteMessage'),
'confirm_delete', $formquestion, 0, 1, 220);
252$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>';
256print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" spellcheck="false">';
257print
'<input type="hidden" name="token" value="'.newToken().
'">';
258print
'<input type="hidden" name="action" value="add">';
265print
'<span class="opacitymedium">'.$langs->trans(
"ListOfSupportedOauthProviders").
'</span><br><br>';
271print
'<select name="provider" id="provider" class="minwidth150">';
272print
'<option name="-1" value="-1">'.$langs->trans(
"OAuthProvider").
'</option>';
274foreach ($list as $key) {
276 $keyforsupportedoauth2array = $key[0];
278 if (in_array($keyforsupportedoauth2array, array_keys($supportedoauth2array))) {
285 print
'<option name="'.$keyforsupportedoauth2array.
'" value="'.str_replace(
'_NAME',
'', $keyforsupportedoauth2array).
'">';
287 $keyforsupportedoauth2array = preg_replace(
'/^OAUTH_/',
'', $keyforsupportedoauth2array);
288 $keyforsupportedoauth2array = preg_replace(
'/_NAME$/',
'', $keyforsupportedoauth2array);
289 $keyforsupportedoauth2array = preg_replace(
'/-.*$/',
'', $keyforsupportedoauth2array);
290 $keyforsupportedoauth2array =
'OAUTH_'.$keyforsupportedoauth2array.
'_NAME';
292 $label = $langs->trans($keyforsupportedoauth2array);
293 if ($label == $keyforsupportedoauth2array) {
294 print $supportedoauth2array[$keyforsupportedoauth2array][
'name'];
298 print
'</option>'.
"\n";
302print
' <input type="text" name="label" value="" placeholder="'.$langs->trans(
"Label").
'" pattern="^[a-zA-Z0-9]+$" title="'.$langs->trans(
"SpaceOrSpecialCharAreNotAllowed").
'">';
303print
' <input type="submit" class="button small" name="add" value="'.$langs->trans(
"Add").
'">';
314foreach (
$conf->global as $key => $val) {
315 if (!empty($val) && preg_match(
'/^OAUTH_.*_ID$/', $key)) {
316 $provider = preg_replace(
'/_ID$/',
'', $key);
317 $listinsetup[] = array(
328if (count($listinsetup) > 0) {
329 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" spellcheck="false">';
330 print
'<input type="hidden" name="token" value="'.newToken().
'">';
331 print
'<input type="hidden" name="action" value="update">';
333 print
'<div class="div-table-responsive-no-min">';
338 foreach ($listinsetup as $key) {
340 $keyforsupportedoauth2array = $key[0];
341 $keyforsupportedoauth2array = preg_replace(
'/^OAUTH_/',
'', $keyforsupportedoauth2array);
342 $keyforsupportedoauth2array = preg_replace(
'/_NAME$/',
'', $keyforsupportedoauth2array);
343 if (preg_match(
'/^.*-/', $keyforsupportedoauth2array)) {
344 $keybeforeprovider = preg_replace(
'/-.*$/',
'', $keyforsupportedoauth2array);
345 $keyforprovider = preg_replace(
'/^.*-/',
'', $keyforsupportedoauth2array);
347 $keybeforeprovider = $keyforsupportedoauth2array;
348 $keyforprovider =
'';
350 $keyforsupportedoauth2array = preg_replace(
'/-.*$/',
'', $keyforsupportedoauth2array);
351 $keyforsupportedoauth2array =
'OAUTH_'.$keyforsupportedoauth2array.
'_NAME';
353 if (in_array($keyforsupportedoauth2array, array_keys($supportedoauth2array))) {
362 print
'<table class="noborder centpercent">';
365 $label = $langs->trans($keyforsupportedoauth2array);
366 print
'<tr class="liste_titre'.($i > 1 ?
' liste_titre_add' :
'').
'">';
367 print
'<td class="titlefieldcreate">';
368 print img_picto(
'', $supportedoauth2array[$keyforsupportedoauth2array][
'picto'],
'class="pictofixedwidth"');
369 if ($label == $keyforsupportedoauth2array) {
370 print $supportedoauth2array[$keyforsupportedoauth2array][
'name'];
374 if ($servicetoeditname == $key[0]) {
375 print
' (<input style="width: 20%" type="text" name="'.$key[0].
'" value="'.$keyforprovider.
'" >)';
376 } elseif ($keyforprovider) {
377 print
' (<b>'.$keyforprovider.
'</b>)';
379 print
' (<b>'.$langs->trans(
"NoName").
'</b>)';
381 if (!($servicetoeditname == $key[0])) {
382 print
'<a class="editfielda reposition" href="'.$_SERVER[
"PHP_SELF"].
'?token='.
newToken().
'&servicetoeditname='.urlencode($key[0]).
'">'.img_edit($langs->transnoentitiesnoconv(
'Edit'), 1).
'</a>';
386 if (!empty($supportedoauth2array[$keyforsupportedoauth2array][
'urlforcredentials'])) {
387 print $langs->trans(
"OAUTH_URL_FOR_CREDENTIAL", $supportedoauth2array[$keyforsupportedoauth2array][
'urlforcredentials']);
393 $label = preg_replace(
'/_NAME$/',
'', $keyforsupportedoauth2array);
394 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=delete&token='.
newToken().
'&provider='.urlencode($keyforprovider).
'&label='.urlencode($label).
'">';
395 print img_picto(
'',
'delete');
404 if ($keyforsupportedoauth2array !=
'OAUTH_MICROSOFTAPP_NAME') {
405 $redirect_uri = $urlwithroot.
'/core/modules/oauth/'.$supportedoauth2array[$keyforsupportedoauth2array][
'callbackfile'].
'_oauthcallback.php';
406 print
'<tr class="oddeven value">';
407 print
'<td>'.$form->textwithpicto($langs->trans(
"RedirectURL"), $langs->trans(
"UseTheFollowingUrlAsRedirectURI")).
'</td>';
408 print
'<td><input style="width: 80%" type="text" name="uri'.$keyforsupportedoauth2array.
'" id="uri'.$keyforsupportedoauth2array.$keyforprovider.
'" value="'.$redirect_uri.
'" disabled>';
409 print
ajax_autoselect(
'uri'.$keyforsupportedoauth2array.$keyforprovider);
415 if ($keyforsupportedoauth2array ==
'OAUTH_GENERIC_NAME') {
416 print
'<tr class="oddeven value">';
418 $tooltiphelp = $langs->trans(
"Example").
'<br>https://mastodon.example.com<br>https://mastodon.social';
419 print $form->textwithpicto($langs->trans(
"URLOfOAuthServiceEndpoints"), $tooltiphelp);
421 print
'<td><input style="width: 80%" type="text" name="'.$key[3].
'" value="'.
getDolGlobalString($key[3]).
'" >';
427 print
'<tr class="oddeven value">';
428 print
'<td>'.$langs->trans(
"UseTheFollowingUrlAsRedirectURI").
'</td>';
429 print
'<td>'.$langs->trans(
"FeatureNotYetSupported").
'</td>';
436 print
'<tr class="oddeven value">';
437 print
'<td><label for="'.$key[1].
'">'.$langs->trans(
"OAUTH_ID").
'</label></td>';
438 print
'<td><input type="text" size="100" id="'.$key[1].
'" name="'.$key[1].
'" value="'.
getDolGlobalString($key[1]).
'">';
444 print
'<tr class="oddeven value">';
445 print
'<td><label for="'.$key[2].
'">'.$langs->trans(
"OAUTH_SECRET").
'</label></td>';
446 print
'<td><input type="password" size="100" id="'.$key[2].
'" name="'.$key[2].
'" value="'.
getDolGlobalString($key[2]).
'">';
455 if ($keybeforeprovider ==
'MICROSOFT' || $keybeforeprovider ==
'MICROSOFT2' || $keybeforeprovider ==
'MICROSOFT3' || $keybeforeprovider ==
'MICROSOFTAPP') {
456 print
'<tr class="oddeven value">';
457 print
'<td><label for="'.$key[2].
'">'.$langs->trans(
"OAUTH_TENANT").
'</label></td>';
458 print
'<td><input type="text" size="100" id="OAUTH_'.$keybeforeprovider.($keyforprovider ?
'-'.$keyforprovider :
'').
'_TENANT" name="OAUTH_'.$keybeforeprovider.($keyforprovider ?
'-'.$keyforprovider :
'').
'_TENANT" value="'.
getDolGlobalString(
'OAUTH_'.$keybeforeprovider.($keyforprovider ?
'-'.$keyforprovider :
'').
'_TENANT').
'">';
466 if ($keyforsupportedoauth2array ==
'OAUTH_GENERIC_NAME') {
467 print
'<tr class="oddeven value">';
469 print $form->textwithpicto($langs->trans(
"Scopes"), $langs->trans(
"ScopesDesc"));
472 print
'<input style="width: 80%" type"text" name="'.$key[4].
'" value="'.
getDolGlobalString($key[4]).
'" >';
477 $availablescopes = array_flip(explode(
',', $supportedoauth2array[$keyforsupportedoauth2array][
'availablescopes']));
479 $scopestodispay = array();
480 foreach ($availablescopes as $keyscope => $valscope) {
481 if (in_array($keyscope, $currentscopes)) {
482 $scopestodispay[$keyscope] = 1;
484 $scopestodispay[$keyscope] = 0;
488 print
'<tr class="oddeven value">';
489 print
'<td>'.$langs->trans(
"Scopes").
'</td>';
491 foreach ($scopestodispay as $scope => $val) {
492 print
'<input type="checkbox" id="'.$keyforprovider.$scope.
'" name="'.$key[4].
'[]" value="'.$scope.
'"'.($val ?
' checked' :
'').
'>';
493 print
'<label style="margin-right: 10px" for="'.$keyforprovider.$scope.
'">'.$scope.
'</label>';
500 print
'<tr class="oddeven value">';
501 print
'<td>'.$langs->trans(
"UseTheFollowingUrlAsRedirectURI").
'</td>';
502 print
'<td>'.$langs->trans(
"FeatureNotYetSupported").
'</td>';
508 print
'</table>'.
"\n";
515 print $form->buttonsSaveCancel(
"Save",
'');
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).
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='', $placeholder='')
Convert a html select field into an ajax combobox.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now 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, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
ajax_autoselect($htmlname, $addlink='', $textonlink='Link')
Make content of an input box selected when we click into input field.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getAllOauth2Array()
Return array of possible OAUTH2 services.
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.
showEyeForField($htmlname, $htmlnameofinput)
Output the eye picto to show/hide a password HTML field.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.