dolibarr  13.0.2
oauth.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2015-2018 Frederic France <frederic.france@netlogic.fr>
3  * Copyright (C) 2016 RaphaĆ«l Doursenaud <rdoursenaud@gpcsolutions.fr>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  *
18  */
19 
26 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/oauth.lib.php';
29 
30 
31 // Define $urlwithroot
32 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
33 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
34 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
35 
36 // Load translation files required by the page
37 $langs->loadLangs(array('admin', 'oauth'));
38 
39 // Security check
40 if (!$user->admin)
42 
43 $action = GETPOST('action', 'aZ09');
44 
45 
46 /*
47  * Actions
48  */
49 
50 if ($action == 'update')
51 {
52  $error = 0;
53 
54  foreach ($list as $constname) {
55  $constvalue = GETPOST($constname[1], 'alpha');
56  if (!dolibarr_set_const($db, $constname[1], $constvalue, 'chaine', 0, '', $conf->entity))
57  $error++;
58  $constvalue = GETPOST($constname[2], 'alpha');
59  if (!dolibarr_set_const($db, $constname[2], $constvalue, 'chaine', 0, '', $conf->entity))
60  $error++;
61  }
62 
63  if (!$error)
64  {
65  setEventMessages($langs->trans("SetupSaved"), null);
66  } else {
67  setEventMessages($langs->trans("Error"), null, 'errors');
68  }
69 }
70 
71 /*
72  * View
73  */
74 
75 llxHeader();
76 
77 $form = new Form($db);
78 
79 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
80 print load_fiche_titre($langs->trans('ConfigOAuth'), $linkback, 'title_setup');
81 
82 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
83 print '<input type="hidden" name="token" value="'.newToken().'">';
84 print '<input type="hidden" name="action" value="update">';
85 
86 $head = oauthadmin_prepare_head();
87 
88 print dol_get_fiche_head($head, 'services', '', -1, 'technic');
89 
90 
91 print '<span class="opacitymedium">'.$langs->trans("ListOfSupportedOauthProviders").'</span><br><br>';
92 
93 print '<table class="noborder centpercent">';
94 
95 $i = 0;
96 
97 // $list is defined into oauth.lib.php
98 foreach ($list as $key)
99 {
100  $supported = 0;
101  if (in_array($key[0], array_keys($supportedoauth2array))) $supported = 1;
102  if (!$supported) continue; // show only supported
103 
104  $i++;
105 
106  print '<tr class="liste_titre'.($i > 1 ? ' liste_titre_add' : '').'">';
107  // Api Name
108  $label = $langs->trans($key[0]);
109  print '<td>'.$label.'</td>';
110  print '<td>';
111  if (!empty($key[3])) print $langs->trans($key[3]);
112  print '</td>';
113  print '</tr>';
114 
115  if ($supported)
116  {
117  $redirect_uri = $urlwithroot.'/core/modules/oauth/'.$supportedoauth2array[$key[0]].'_oauthcallback.php';
118  print '<tr class="oddeven value">';
119  print '<td>'.$langs->trans("UseTheFollowingUrlAsRedirectURI").'</td>';
120  print '<td><input style="width: 80%" type"text" name="uri'.$key[0].'" value="'.$redirect_uri.'">';
121  print '</td></tr>';
122  } else {
123  print '<tr class="oddeven value">';
124  print '<td>'.$langs->trans("UseTheFollowingUrlAsRedirectURI").'</td>';
125  print '<td>'.$langs->trans("FeatureNotYetSupported").'</td>';
126  print '</td></tr>';
127  }
128 
129  // Api Id
130  print '<tr class="oddeven value">';
131  print '<td><label for="'.$key[1].'">'.$langs->trans($key[1]).'</label></td>';
132  print '<td><input type="text" size="100" id="'.$key[1].'" name="'.$key[1].'" value="'.$conf->global->{$key[1]}.'">';
133  print '</td></tr>';
134 
135  // Api Secret
136  print '<tr class="oddeven value">';
137  print '<td><label for="'.$key[2].'">'.$langs->trans($key[2]).'</label></td>';
138  print '<td><input type="password" size="100" id="'.$key[2].'" name="'.$key[2].'" value="'.$conf->global->{$key[2]}.'">';
139  print '</td></tr>';
140 }
141 
142 print '</table>'."\n";
143 
145 
146 print '<div class="center"><input type="submit" class="button" value="'.$langs->trans('Modify').'" name="button"></div>';
147 
148 print '</form>';
149 
150 // End of page
151 llxFooter();
152 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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).
Definition: admin.lib.php:575
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
oauthadmin_prepare_head()
Return array of tabs to used on pages to setup cron module.
Definition: oauth.lib.php:272
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
dol_get_fiche_end($notab=0)
Return tab footer of a card.
llxFooter()
Empty footer.
Definition: wrapper.php:59