28 require
'../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
30 require_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');
58 if ($action ==
'add') {
59 if ($provider && $provider !=
'-1') {
60 $constname = strtoupper($provider).($label ?
'-'.$label :
'').
'_ID';
63 setEventMessages($langs->trans(
"AOAuthEntryForThisProviderAndLabelAlreadyHasAKey"),
null,
'errors');
66 dolibarr_set_const($db, $constname, $langs->trans(
'ToComplete'),
'chaine', 0,
'', $conf->entity);
71 if ($action ==
'update') {
72 foreach ($conf->global as $key => $val) {
73 if (!empty($val) && preg_match(
'/^OAUTH_.+_ID$/', $key)) {
74 $constvalue = str_replace(
'_ID',
'', $key);
83 if (!
dolibarr_set_const($db, $constvalue.
'_URLAUTHORIZE',
GETPOST($constvalue.
'_URLAUTHORIZE'),
'chaine', 0,
'', $conf->entity)) {
88 if (is_array(
GETPOST($constvalue.
'_SCOPE'))) {
89 $scopestring = implode(
',',
GETPOST($constvalue.
'_SCOPE'));
91 $scopestring =
GETPOST($constvalue.
'_SCOPE');
93 if (!
dolibarr_set_const($db, $constvalue.
'_SCOPE', $scopestring,
'chaine', 0,
'', $conf->entity)) {
97 if (!
dolibarr_set_const($db, $constvalue.
'_SCOPE',
'',
'chaine', 0,
'', $conf->entity)) {
112 if ($action ==
'confirm_delete') {
113 $provider =
GETPOST(
'provider',
'aZ09');
116 $globalkey = empty($provider) ? $label : $label.
'-'.$provider;
119 $backtourl = DOL_URL_ROOT.
'/admin/oauth.php?action=delete_entry&provider='.$provider.
'&label='.$label.
'&token='.
newToken();
120 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
121 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
122 $callbacktodel = $urlwithroot;
123 if ($label ==
'OAUTH_GOOGLE') {
124 $callbacktodel .=
'/core/modules/oauth/google_oauthcallback.php?action=delete&keyforprovider='.$provider.
'&token='.
newToken().
'&backtourl='.urlencode($backtourl);
125 } elseif ($label ==
'OAUTH_GITHUB') {
126 $callbacktodel .=
'/core/modules/oauth/github_oauthcallback.php?action=delete&keyforprovider='.$provider.
'&token='.
newToken().
'&backtourl='.urlencode($backtourl);
127 } elseif ($label ==
'OAUTH_STRIPE_LIVE') {
128 $callbacktodel .=
'/core/modules/oauth/stripelive_oauthcallback.php?action=delete&keyforprovider='.$provider.
'&token='.
newToken().
'&backtourl='.urlencode($backtourl);
129 } elseif ($label ==
'OAUTH_STRIPE_TEST') {
130 $callbacktodel .=
'/core/modules/oauth/stripetest_oauthcallback.php?action=delete&keyforprovider='.$provider.
'&token='.
newToken().
'&backtourl='.urlencode($backtourl);
131 } elseif ($label ==
'OAUTH_OTHER') {
132 $callbacktodel .=
'/core/modules/oauth/generic_oauthcallback.php?action=delete&keyforprovider='.$provider.
'&token='.
newToken().
'&backtourl='.urlencode($backtourl);
134 header(
"Location: ".$callbacktodel);
137 $action =
'delete_entry';
141 if ($action ==
'delete_entry') {
142 $provider =
GETPOST(
'provider',
'aZ09');
145 $globalkey = empty($provider) ? $label : $label.
'-'.$provider;
147 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)) {
163 if ($action ==
'delete') {
164 $formquestion = array();
165 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?provider='.
GETPOST(
'provider').
'&label='.
GETPOST(
'label'), $langs->trans(
'OAuthServiceConfirmDeleteTitle'), $langs->trans(
'OAuthServiceConfirmDeleteMessage'),
'confirm_delete', $formquestion, 0, 1, 220);
170 $linkback =
'<a href="'.DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToModuleList").
'</a>';
171 print
load_fiche_titre($langs->trans(
'ConfigOAuth'), $linkback,
'title_setup');
173 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
174 print
'<input type="hidden" name="token" value="'.newToken().
'">';
175 print
'<input type="hidden" name="action" value="add">';
182 print
'<span class="opacitymedium">'.$langs->trans(
"ListOfSupportedOauthProviders").
'</span><br><br>';
185 print
'<select name="provider" id="provider" class="minwidth150">';
186 print
'<option name="-1" value="-1">'.$langs->trans(
"OAuthProvider").
'</option>';
187 foreach ($list as $key) {
189 $keyforsupportedoauth2array = $key[0];
191 if (in_array($keyforsupportedoauth2array, array_keys($supportedoauth2array))) {
199 print
'<option name="'.$keyforsupportedoauth2array.
'" value="'.str_replace(
'_NAME',
'', $keyforsupportedoauth2array).
'">'.$supportedoauth2array[$keyforsupportedoauth2array][
'name'].
'</option>'.
"\n";
203 print
' <input type="text" name="label" value="" placeholder="'.$langs->trans(
"Label").
'" pattern="^\S+$" title="'.$langs->trans(
"SpaceOrSpecialCharAreNotAllowed").
'">';
204 print
' <input type="submit" class="button small" name="add" value="'.$langs->trans(
"Add").
'">';
215 foreach ($conf->global as $key => $val) {
216 if (!empty($val) && preg_match(
'/^OAUTH_.*_ID$/', $key)) {
217 $provider = preg_replace(
'/_ID$/',
'', $key);
218 $listinsetup[] = array(
222 $provider.
'_URLAUTHORIZE',
229 if (count($listinsetup) > 0) {
230 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
231 print
'<input type="hidden" name="token" value="'.newToken().
'">';
232 print
'<input type="hidden" name="action" value="update">';
234 print
'<div class="div-table-responsive-no-min">';
239 foreach ($listinsetup as $key) {
241 $keyforsupportedoauth2array = $key[0];
242 $keyforsupportedoauth2array = preg_replace(
'/^OAUTH_/',
'', $keyforsupportedoauth2array);
243 $keyforsupportedoauth2array = preg_replace(
'/_NAME$/',
'', $keyforsupportedoauth2array);
244 if (preg_match(
'/^.*-/', $keyforsupportedoauth2array)) {
245 $keyforprovider = preg_replace(
'/^.*-/',
'', $keyforsupportedoauth2array);
247 $keyforprovider =
'';
249 $keyforsupportedoauth2array = preg_replace(
'/-.*$/',
'', $keyforsupportedoauth2array);
250 $keyforsupportedoauth2array =
'OAUTH_'.$keyforsupportedoauth2array.
'_NAME';
252 if (in_array($keyforsupportedoauth2array, array_keys($supportedoauth2array))) {
261 print
'<table class="noborder centpercent">';
264 $label = $langs->trans($keyforsupportedoauth2array);
265 print
'<tr class="liste_titre'.($i > 1 ?
' liste_titre_add' :
'').
'">';
266 print
'<td class="titlefieldcreate">';
267 print
img_picto(
'', $supportedoauth2array[$keyforsupportedoauth2array][
'picto'],
'class="pictofixedwidth"');
268 if ($label == $keyforsupportedoauth2array) {
269 print $supportedoauth2array[$keyforsupportedoauth2array][
'name'];
273 if ($keyforprovider) {
274 print
' (<b>'.$keyforprovider.
'</b>)';
276 print
' (<b>'.$langs->trans(
"NoName").
'</b>)';
280 if (!empty($supportedoauth2array[$keyforsupportedoauth2array][
'urlforcredentials'])) {
281 print $langs->trans(
"OAUTH_URL_FOR_CREDENTIAL", $supportedoauth2array[$keyforsupportedoauth2array][
'urlforcredentials']);
287 $label = preg_replace(
'/_NAME$/',
'', $keyforsupportedoauth2array);
288 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=delete&token='.
newToken().
'&provider='.urlencode($keyforprovider).
'&label='.urlencode($label).
'">';
298 $redirect_uri = $urlwithroot.
'/core/modules/oauth/'.$supportedoauth2array[$keyforsupportedoauth2array][
'callbackfile'].
'_oauthcallback.php';
299 print
'<tr class="oddeven value">';
300 print
'<td>'.$langs->trans(
"UseTheFollowingUrlAsRedirectURI").
'</td>';
301 print
'<td><input style="width: 80%" type="text" name="uri'.$keyforsupportedoauth2array.
'" id="uri'.$keyforsupportedoauth2array.$keyforprovider.
'" value="'.$redirect_uri.
'" disabled>';
302 print
ajax_autoselect(
'uri'.$keyforsupportedoauth2array.$keyforprovider);
307 if ($keyforsupportedoauth2array ==
'OAUTH_OTHER_NAME') {
308 print
'<tr class="oddeven value">';
309 print
'<td>'.$langs->trans(
"URLOfServiceForAuthorization").
'</td>';
310 print
'<td><input style="width: 80%" type="text" name="'.$key[3].
'" value="'.
getDolGlobalString($key[3]).
'" >';
316 print
'<tr class="oddeven value">';
317 print
'<td>'.$langs->trans(
"UseTheFollowingUrlAsRedirectURI").
'</td>';
318 print
'<td>'.$langs->trans(
"FeatureNotYetSupported").
'</td>';
325 print
'<tr class="oddeven value">';
326 print
'<td><label for="'.$key[1].
'">'.$langs->trans(
"OAUTH_ID").
'</label></td>';
327 print
'<td><input type="text" size="100" id="'.$key[1].
'" name="'.$key[1].
'" value="'.
getDolGlobalString($key[1]).
'">';
333 print
'<tr class="oddeven value">';
334 print
'<td><label for="'.$key[2].
'">'.$langs->trans(
"OAUTH_SECRET").
'</label></td>';
335 print
'<td><input type="password" size="100" id="'.$key[2].
'" name="'.$key[2].
'" value="'.
getDolGlobalString($key[2]).
'">';
342 if ($keyforsupportedoauth2array ==
'OAUTH_OTHER_NAME') {
343 print
'<tr class="oddeven value">';
344 print
'<td>'.$langs->trans(
"Scopes").
'</td>';
346 print
'<input style="width: 80%" type"text" name="'.$key[4].
'" value="'.
getDolGlobalString($key[4]).
'" >';
351 $availablescopes = array_flip(explode(
',', $supportedoauth2array[$keyforsupportedoauth2array][
'availablescopes']));
353 $scopestodispay = array();
354 foreach ($availablescopes as $keyscope => $valscope) {
355 if (in_array($keyscope, $currentscopes)) {
356 $scopestodispay[$keyscope] = 1;
358 $scopestodispay[$keyscope] = 0;
362 print
'<tr class="oddeven value">';
363 print
'<td>'.$langs->trans(
"Scopes").
'</td>';
365 foreach ($scopestodispay as $scope => $val) {
366 print
'<input type="checkbox" id="'.$keyforprovider.$scope.
'" name="'.$key[4].
'[]" value="'.$scope.
'"'.($val ?
' checked' :
'').
'>';
367 print
'<label style="margin-right: 10px" for="'.$keyforprovider.$scope.
'">'.$scope.
'</label>';
374 print
'<tr class="oddeven value">';
375 print
'<td>'.$langs->trans(
"UseTheFollowingUrlAsRedirectURI").
'</td>';
376 print
'<td>'.$langs->trans(
"FeatureNotYetSupported").
'</td>';
382 print
'</table>'.
"\n";
389 print
$form->buttonsSaveCancel(
"Modify",
'');
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.
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.
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.
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.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
$formconfirm
if ($action == 'delbookkeepingyear') {
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.