28require
'../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/oauth.lib.php';
35$urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
36$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
40$langs->loadLangs(array(
'admin',
'oauth',
'modulebuilder'));
47$action =
GETPOST(
'action',
'aZ09');
48$provider =
GETPOST(
'provider',
'aZ09');
49$label =
GETPOST(
'label',
'aZ09');
51$servicetoeditname =
GETPOST(
'servicetoeditname',
'aZ09');
60if ($action ==
'add') {
61 if ($provider && $provider !=
'-1') {
62 $constname = strtoupper($provider).($label ?
'-'.$label :
'').
'_ID';
65 setEventMessages($langs->trans(
"AOAuthEntryForThisProviderAndLabelAlreadyHasAKey"),
null,
'errors');
68 dolibarr_set_const($db, $constname, $langs->trans(
'ToComplete'),
'chaine', 0,
'', $conf->entity);
73if ($action ==
'update') {
74 foreach ($conf->global as $key => $val) {
75 if (!empty($val) && preg_match(
'/^OAUTH_.+_ID$/', $key)) {
76 $constvalue = str_replace(
'_ID',
'', $key);
77 $newconstvalue = $constvalue;
78 if (GETPOSTISSET($constvalue.
'_NAME')) {
79 $newconstvalue = preg_replace(
'/-.*$/',
'', $constvalue).
'-'.
GETPOST($constvalue.
'_NAME');
82 if (GETPOSTISSET($constvalue.
'_ID')) {
88 if (GETPOSTISSET($constvalue.
'_SECRET')) {
93 if (GETPOSTISSET($constvalue.
'_URLAUTHORIZE')) {
94 if (!
dolibarr_set_const($db, $newconstvalue.
'_URLAUTHORIZE',
GETPOST($constvalue.
'_URLAUTHORIZE'),
'chaine', 0,
'', $conf->entity)) {
98 if (GETPOSTISSET($constvalue.
'_TENANT')) {
103 if (GETPOSTISSET($constvalue.
'_SCOPE')) {
104 if (is_array(
GETPOST($constvalue.
'_SCOPE'))) {
105 $scopestring = implode(
',',
GETPOST($constvalue.
'_SCOPE'));
107 $scopestring =
GETPOST($constvalue.
'_SCOPE');
109 if (!
dolibarr_set_const($db, $newconstvalue.
'_SCOPE', $scopestring,
'chaine', 0,
'', $conf->entity)) {
112 } elseif ($newconstvalue !== $constvalue) {
113 if (!
dolibarr_set_const($db, $newconstvalue.
'_SCOPE',
'',
'chaine', 0,
'', $conf->entity)) {
119 if ($constvalue !== $newconstvalue) {
126 $oldname = preg_replace(
'/^OAUTH_/',
'', $constvalue);
127 $oldprovider = ucfirst(strtolower(preg_replace(
'/-.*$/',
'', $oldname)));
128 $oldlabel = preg_replace(
'/^.*-/',
'', $oldname);
129 $newlabel = preg_replace(
'/^.*-/',
'', $newconstvalue);
132 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"oauth_token";
133 $sql.=
" SET service = '".$db->escape($oldprovider.
"-".$newlabel).
"'";
134 $sql.=
" WHERE service = '".$db->escape($oldprovider.
"-".$oldlabel).
"'";
137 $resql = $db->query($sql);
144 if (!
dolibarr_set_const($db,
'MAIN_MAIL_SMTPS_OAUTH_SERVICE', strtoupper($oldprovider).
'-'.$newlabel,
'chaine', 0,
'', $conf->entity)) {
160if ($action ==
'confirm_delete') {
161 $provider =
GETPOST(
'provider',
'aZ09');
164 $globalkey = empty($provider) ? $label : $label.
'-'.$provider;
167 $backtourl = DOL_URL_ROOT.
'/admin/oauth.php?action=delete_entry&provider='.$provider.
'&label='.$label.
'&token='.newToken();
168 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
169 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
170 $callbacktodel = $urlwithroot;
171 if ($label ==
'OAUTH_GOOGLE') {
172 $callbacktodel .=
'/core/modules/oauth/google_oauthcallback.php?action=delete&keyforprovider='.$provider.
'&token='.newToken().
'&backtourl='.urlencode($backtourl);
173 } elseif ($label ==
'OAUTH_GITHUB') {
174 $callbacktodel .=
'/core/modules/oauth/github_oauthcallback.php?action=delete&keyforprovider='.$provider.
'&token='.newToken().
'&backtourl='.urlencode($backtourl);
175 } elseif ($label ==
'OAUTH_STRIPE_LIVE') {
176 $callbacktodel .=
'/core/modules/oauth/stripelive_oauthcallback.php?action=delete&keyforprovider='.$provider.
'&token='.newToken().
'&backtourl='.urlencode($backtourl);
177 } elseif ($label ==
'OAUTH_STRIPE_TEST') {
178 $callbacktodel .=
'/core/modules/oauth/stripetest_oauthcallback.php?action=delete&keyforprovider='.$provider.
'&token='.newToken().
'&backtourl='.urlencode($backtourl);
179 } elseif ($label ==
'OAUTH_MICROSOFT') {
180 $callbacktodel .=
'/core/modules/oauth/microsoft_oauthcallback.php?action=delete&keyforprovider='.$provider.
'&token='.newToken().
'&backtourl='.urlencode($backtourl);
181 } elseif ($label ==
'OAUTH_OTHER') {
182 $callbacktodel .=
'/core/modules/oauth/generic_oauthcallback.php?action=delete&keyforprovider='.$provider.
'&token='.newToken().
'&backtourl='.urlencode($backtourl);
184 header(
"Location: ".$callbacktodel);
187 $action =
'delete_entry';
191if ($action ==
'delete_entry') {
192 $provider =
GETPOST(
'provider',
'aZ09');
195 $globalkey = empty($provider) ? $label : $label.
'-'.$provider;
197 if (!
dolibarr_del_const($db, $globalkey.
'_NAME', $conf->entity) || !
dolibarr_del_const($db, $globalkey.
'_ID', $conf->entity) || !
dolibarr_del_const($db, $globalkey.
'_SECRET', $conf->entity) || !
dolibarr_del_const($db, $globalkey.
'_URLAUTHORIZE', $conf->entity) || !
dolibarr_del_const($db, $globalkey.
'_SCOPE', $conf->entity)) {
211$form =
new Form($db);
213if ($action ==
'delete') {
214 $formquestion = array();
215 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?provider='.
GETPOST(
'provider').
'&label='.
GETPOST(
'label'), $langs->trans(
'OAuthServiceConfirmDeleteTitle'), $langs->trans(
'OAuthServiceConfirmDeleteMessage'),
'confirm_delete', $formquestion, 0, 1, 220);
220$linkback =
'<a href="'.DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToModuleList").
'</a>';
221print
load_fiche_titre($langs->trans(
'ConfigOAuth'), $linkback,
'title_setup');
223print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
224print
'<input type="hidden" name="token" value="'.newToken().
'">';
225print
'<input type="hidden" name="action" value="add">';
232print
'<span class="opacitymedium">'.$langs->trans(
"ListOfSupportedOauthProviders").
'</span><br><br>';
235print
'<select name="provider" id="provider" class="minwidth150">';
236print
'<option name="-1" value="-1">'.$langs->trans(
"OAuthProvider").
'</option>';
239foreach ($list as $key) {
241 $keyforsupportedoauth2array = $key[0];
243 if (in_array($keyforsupportedoauth2array, array_keys($supportedoauth2array))) {
250 print
'<option name="'.$keyforsupportedoauth2array.
'" value="'.str_replace(
'_NAME',
'', $keyforsupportedoauth2array).
'">'.$supportedoauth2array[$keyforsupportedoauth2array][
'name'].
'</option>'.
"\n";
254print
' <input type="text" name="label" value="" placeholder="'.$langs->trans(
"Label").
'" pattern="^\S+$" title="'.$langs->trans(
"SpaceOrSpecialCharAreNotAllowed").
'">';
255print
' <input type="submit" class="button small" name="add" value="'.$langs->trans(
"Add").
'">';
266foreach ($conf->global as $key => $val) {
267 if (!empty($val) && preg_match(
'/^OAUTH_.*_ID$/', $key)) {
268 $provider = preg_replace(
'/_ID$/',
'', $key);
269 $listinsetup[] = array(
273 $provider.
'_URLAUTHORIZE',
280if (count($listinsetup) > 0) {
281 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
282 print
'<input type="hidden" name="token" value="'.newToken().
'">';
283 print
'<input type="hidden" name="action" value="update">';
285 print
'<div class="div-table-responsive-no-min">';
290 foreach ($listinsetup as $key) {
292 $keyforsupportedoauth2array = $key[0];
293 $keyforsupportedoauth2array = preg_replace(
'/^OAUTH_/',
'', $keyforsupportedoauth2array);
294 $keyforsupportedoauth2array = preg_replace(
'/_NAME$/',
'', $keyforsupportedoauth2array);
295 if (preg_match(
'/^.*-/', $keyforsupportedoauth2array)) {
296 $keybeforeprovider = preg_replace(
'/-.*$/',
'', $keyforsupportedoauth2array);
297 $keyforprovider = preg_replace(
'/^.*-/',
'', $keyforsupportedoauth2array);
299 $keybeforeprovider = $keyforsupportedoauth2array;
300 $keyforprovider =
'';
302 $keyforsupportedoauth2array = preg_replace(
'/-.*$/',
'', $keyforsupportedoauth2array);
303 $keyforsupportedoauth2array =
'OAUTH_'.$keyforsupportedoauth2array.
'_NAME';
305 if (in_array($keyforsupportedoauth2array, array_keys($supportedoauth2array))) {
314 print
'<table class="noborder centpercent">';
317 $label = $langs->trans($keyforsupportedoauth2array);
318 print
'<tr class="liste_titre'.($i > 1 ?
' liste_titre_add' :
'').
'">';
319 print
'<td class="titlefieldcreate">';
320 print
img_picto(
'', $supportedoauth2array[$keyforsupportedoauth2array][
'picto'],
'class="pictofixedwidth"');
321 if ($label == $keyforsupportedoauth2array) {
322 print $supportedoauth2array[$keyforsupportedoauth2array][
'name'];
326 if ($servicetoeditname == $key[0]) {
327 print
' (<input style="width: 20%" type="text" name="'.$key[0].
'" value="'.$keyforprovider.
'" >)';
328 } elseif ($keyforprovider) {
329 print
' (<b>'.$keyforprovider.
'</b>)';
331 print
' (<b>'.$langs->trans(
"NoName").
'</b>)';
333 if (!($servicetoeditname == $key[0])) {
334 print
'<a class="editfielda reposition" href="'.$_SERVER[
"PHP_SELF"].
'?token='.newToken().
'&servicetoeditname='.urlencode($key[0]).
'">'.
img_edit($langs->transnoentitiesnoconv(
'Edit'), 1).
'</a>';
338 if (!empty($supportedoauth2array[$keyforsupportedoauth2array][
'urlforcredentials'])) {
339 print $langs->trans(
"OAUTH_URL_FOR_CREDENTIAL", $supportedoauth2array[$keyforsupportedoauth2array][
'urlforcredentials']);
345 $label = preg_replace(
'/_NAME$/',
'', $keyforsupportedoauth2array);
346 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=delete&token='.newToken().
'&provider='.urlencode($keyforprovider).
'&label='.urlencode($label).
'">';
356 $redirect_uri = $urlwithroot.
'/core/modules/oauth/'.$supportedoauth2array[$keyforsupportedoauth2array][
'callbackfile'].
'_oauthcallback.php';
357 print
'<tr class="oddeven value">';
358 print
'<td>'.$form->textwithpicto($langs->trans(
"RedirectURL"), $langs->trans(
"UseTheFollowingUrlAsRedirectURI")).
'</td>';
359 print
'<td><input style="width: 80%" type="text" name="uri'.$keyforsupportedoauth2array.
'" id="uri'.$keyforsupportedoauth2array.$keyforprovider.
'" value="'.$redirect_uri.
'" disabled>';
360 print
ajax_autoselect(
'uri'.$keyforsupportedoauth2array.$keyforprovider);
365 if ($keyforsupportedoauth2array ==
'OAUTH_OTHER_NAME') {
366 print
'<tr class="oddeven value">';
367 print
'<td>'.$langs->trans(
"URLOfServiceForAuthorization").
'</td>';
368 print
'<td><input style="width: 80%" type="text" name="'.$key[3].
'" value="'.
getDolGlobalString($key[3]).
'" >';
374 print
'<tr class="oddeven value">';
375 print
'<td>'.$langs->trans(
"UseTheFollowingUrlAsRedirectURI").
'</td>';
376 print
'<td>'.$langs->trans(
"FeatureNotYetSupported").
'</td>';
383 print
'<tr class="oddeven value">';
384 print
'<td><label for="'.$key[1].
'">'.$langs->trans(
"OAUTH_ID").
'</label></td>';
385 print
'<td><input type="text" size="100" id="'.$key[1].
'" name="'.$key[1].
'" value="'.
getDolGlobalString($key[1]).
'">';
391 print
'<tr class="oddeven value">';
392 print
'<td><label for="'.$key[2].
'">'.$langs->trans(
"OAUTH_SECRET").
'</label></td>';
393 print
'<td><input type="password" size="100" id="'.$key[2].
'" name="'.$key[2].
'" value="'.
getDolGlobalString($key[2]).
'">';
399 if ($keybeforeprovider ==
'MICROSOFT') {
400 print
'<tr class="oddeven value">';
401 print
'<td><label for="'.$key[2].
'">'.$langs->trans(
"OAUTH_TENANT").
'</label></td>';
402 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').
'">';
410 if ($keyforsupportedoauth2array ==
'OAUTH_OTHER_NAME') {
411 print
'<tr class="oddeven value">';
412 print
'<td>'.$langs->trans(
"Scopes").
'</td>';
414 print
'<input style="width: 80%" type"text" name="'.$key[4].
'" value="'.
getDolGlobalString($key[4]).
'" >';
419 $availablescopes = array_flip(explode(
',', $supportedoauth2array[$keyforsupportedoauth2array][
'availablescopes']));
421 $scopestodispay = array();
422 foreach ($availablescopes as $keyscope => $valscope) {
423 if (in_array($keyscope, $currentscopes)) {
424 $scopestodispay[$keyscope] = 1;
426 $scopestodispay[$keyscope] = 0;
430 print
'<tr class="oddeven value">';
431 print
'<td>'.$langs->trans(
"Scopes").
'</td>';
433 foreach ($scopestodispay as $scope => $val) {
434 print
'<input type="checkbox" id="'.$keyforprovider.$scope.
'" name="'.$key[4].
'[]" value="'.$scope.
'"'.($val ?
' checked' :
'').
'>';
435 print
'<label style="margin-right: 10px" for="'.$keyforprovider.$scope.
'">'.$scope.
'</label>';
442 print
'<tr class="oddeven value">';
443 print
'<td>'.$langs->trans(
"UseTheFollowingUrlAsRedirectURI").
'</td>';
444 print
'<td>'.$langs->trans(
"FeatureNotYetSupported").
'</td>';
450 print
'</table>'.
"\n";
457 print $form->buttonsSaveCancel(
"Save",
'');
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='')
Convert a html select field into an ajax combobox.
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.
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
ajax_autoselect($htmlname, $addlink='', $textonlink='Link')
Make content of an input box selected when we click into input field.
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
getAllOauth2Array()
Return array of possible OAUTH2 services.
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.