dolibarr 24.0.0-beta
credentials.php
Go to the documentation of this file.
1<?php
26// Load Dolibarr environment
27require '../main.inc.php';
39require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
40require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
41require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
42require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
44require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
45require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
46require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
47require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
48require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
49require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
50require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
51if (isModEnabled('ldap')) {
52 require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
53}
54if (isModEnabled('member')) {
55 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
56}
57if (isModEnabled('category')) {
58 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
59}
60if (isModEnabled('stock')) {
61 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
62}
63
64// Load translation files required by page
65$langs->loadLangs(array('users', 'companies', 'ldap', 'admin', 'hrm', 'stocks', 'other'));
66
67$id = GETPOSTINT('id');
68$action = GETPOST('action', 'aZ09');
69$mode = GETPOST('mode', 'alpha');
70$confirm = GETPOST('confirm', 'alpha');
71$optioncss = GETPOST('optioncss', 'aZ09');
72$cancel = GETPOST('cancel', 'alpha');
73$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'usercredentials'; // To manage different context of search
74$backtopage = GETPOST('backtopage');
75$backtopageforcancel = GETPOST('backtopageforcancel');
76
77$group = GETPOSTINT("group", 3);
78$search_secret_key = GETPOST('search_secret_key');
79
80// Load variable for pagination
81$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
82$sortfield = GETPOST('sortfield', 'aZ09comma');
83$sortorder = GETPOST('sortorder', 'aZ09comma');
84$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
85if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
86 // If $page is not defined, or '' or -1 or if we click on clear filters
87 $page = 0;
88}
89$offset = $limit * $page;
90$pageprev = $page - 1;
91$pagenext = $page + 1;
92
93
94if (empty($id) && $action != 'add' && $action != 'create') {
95 $id = $user->id;
96}
97
98$object = new User($db);
99
100// fetch optionals attributes and labels
101$extrafields->fetch_name_optionals_label($object->table_element);
102
103// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
104$hookmanager->initHooks(array('usercard', 'globalcard'));
105
106$error = 0;
107
108if ($id > 0) {
109 $res = $object->fetch($id, '', '', 1);
110}
111
112// Security check
113$socid = 0;
114if ($user->socid > 0) {
115 $socid = $user->socid;
116}
117$feature2 = 'user';
118$result = restrictedArea($user, 'user', $id, 'user', $feature2);
119
120// Define value to know what current user can do on users. A test on logged user is done later to complete
121$permissiontoadd = (!empty($user->admin) || $user->hasRight("user", "user", "write")) && (empty($user->socid) || $user->socid == $object->socid);
122$permissiontoread = (!empty($user->admin) || $user->hasRight("user", "user", "read")) && (empty($user->socid) || $user->socid == $object->socid);
123$permissiontoedit = (!empty($user->admin) || $user->hasRight("user", "user", "write")) && (empty($user->socid) || $user->socid == $object->socid);
124$permissiontodisable = (!empty($user->admin) || $user->hasRight("user", "user", "delete")) && (empty($user->socid) || $user->socid == $object->socid);
125$permissiontoreadgroup = $permissiontoread;
126$permissiontoeditgroup = $permissiontoedit;
127if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) {
128 $permissiontoreadgroup = (!empty($user->admin) || $user->hasRight("user", "group_advance", "read")) && (empty($user->socid) || $user->socid == $object->socid);
129 $permissiontoeditgroup = (!empty($user->admin) || $user->hasRight("user", "group_advance", "write")) && (empty($user->socid) || $user->socid == $object->socid);
130}
131
132$permissiontoclonesuperadmin = ($permissiontoadd && empty($user->entity));
133$permissiontocloneadmin = ($permissiontoadd && !empty($user->admin));
134$permissiontocloneuser = $permissiontoadd;
135// Can clone only in master entity if transverse mode is used
136if (getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE') && $conf->entity > 1) {
137 $permissiontoclonesuperadmin = false;
138 $permissiontocloneadmin = false;
139 $permissiontocloneuser = false;
140}
141
142if ($user->id != $id && !$permissiontoread) {
144}
145
146$caneditpasswordandsee = false;
147$caneditpasswordandsend = false;
148
149// Define value to know what current user can do on properties of edited user
150$permissiontoeditpasswordandsee = false;
151$permissiontoeditpasswordandsend = false;
152if ($id > 0) {
153 // $user is the current logged user, $id is the user we want to edit
154 $permissiontoedit = ((($user->id == $id) && $user->hasRight("user", "self", "write")) || (($user->id != $id) && $user->hasRight("user", "user", "write"))) && (empty($user->socid) || $user->socid == $object->socid);
155 $permissiontoeditpasswordandsee = ((($user->id == $id) && $user->hasRight("user", "self", "password")) || (($user->id != $id) && $user->hasRight("user", "user", "password") && $user->admin)) && (empty($user->socid) || $user->socid == $object->socid);
156 $permissiontoeditpasswordandsend = ((($user->id == $id) && $user->hasRight("user", "self", "password")) || (($user->id != $id) && $user->hasRight("user", "user", "password"))) && (empty($user->socid) || $user->socid == $object->socid);
157}
158
159
160/*
161 * Actions
162 */
163
164$parameters = array('id' => $id, 'socid' => $socid, 'group' => $group, 'caneditgroup' => $permissiontoeditgroup);
165$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
166if ($reshook < 0) {
167 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
168}
169
170if (empty($reshook)) {
171 $backurlforlist = DOL_URL_ROOT.'/user/list.php';
172
173 if (empty($backtopage) || ($cancel && empty($id))) {
174 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
175 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
176 $backtopage = $backurlforlist;
177 } else {
178 $backtopage = DOL_URL_ROOT.'/user/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
179 }
180 }
181 }
182
183 if ($cancel) {
184 if (!empty($backtopageforcancel)) {
185 header("Location: ".$backtopageforcancel);
186 exit;
187 } elseif (!empty($backtopage)) {
188 header("Location: ".$backtopage);
189 exit;
190 }
191 $action = '';
192 }
193
194 // Action to initialize data from a LDAP record
195 if ($action == 'addtotp' && $permissiontoadd) { // @phan-suppress-current-line PhanPluginEmptyStatementIf
196 /*
197 $result = $xxx->create();
198 if ($result >= 0) {
199
200 } else {
201 setEventMessages($ldap->error, $ldap->errors, 'errors');
202 }
203 */
204 }
205}
206
207
208/*
209 * View
210 */
211
212$form = new Form($db);
213
214$person_name = !empty($object->firstname) ? $object->lastname.", ".$object->firstname : $object->lastname;
215$title = $person_name." - ".$langs->trans('Credentials');
216$help_url = '';
217
218llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-user page-credentials');
219
220$param = '';
221
222
223// Section TOTP
224print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
225print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
226print '<input type="hidden" name="token" value="'.newToken().'">';
227print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
228print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
229print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
230print '<input type="hidden" name="page" value="'.$page.'">';
231print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
232print '<input type="hidden" name="page_y" value="">';
233print '<input type="hidden" name="mode" value="'.$mode.'">';
234
235//$tmpurlforbutton = 'javascript:console.log("open add totp form");jQuery(".divsectiontotp").toggle(); void(0);';
236
237$newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=addtotp&token='.newToken().'&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd ? 1 : 0);
238
239//$listoftotps = $user->fetchAll($sortorder, $sortfield, 1000, 0, "(fk_user:=:".((int) $object->id).") AND (service:=:'dolibarr_totp')", true);
240$listoftotps = array();
241$sql = "SELECT rowid, token, state, restricted_ips, datec, tms, lastaccess FROM ".$db->prefix()."oauth_token";
242$sql .= " WHERE fk_user = ".((int) $object->id)." AND service = 'dolibarr_totp'";
243$resql = $db->query($sql);
244if ($resql) {
245 while ($obj = $db->fetch_object($resql)) {
246 $listoftotps = array('id' => $obj->rowid);
247 }
248} else {
250}
251
252$nbtotalofrecords = $num = count($listoftotps);
253
254$massactionbutton = '';
255
256print_barre_liste($langs->trans("TOTP"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $object->picto, 0, $newcardbutton, '', $limit, -1, 0, 1);
257
258/*
259print '<div class="hideobject divsectiontotp marginbottom">';
260print '<input placeholder="'.dolPrintHTML("TOPTSecret").'" class="minwidth300 maxwidth400 widthcentpercentminusx" minlength="12" maxlength="128" type="text" id="api_key" name="api_key" value="'.GETPOST('api_key', 'alphanohtml').'" autocomplete="off">';
261if (!empty($conf->use_javascript_ajax)) {
262 print img_picto($langs->transnoentities('Generate'), 'refresh', 'id="generate_api_key" class="linkobject paddingleft"');
263}
264print '</div><br>';
265*/
266
267print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
268print '<table class="tagtable nobottomiftotal liste">'."\n";
269
270// Fields title search
271// --------------------------------------------------------------------
272print '<tr class="liste_titre_filter">';
273// Action column
274if ($conf->main_checkbox_left_column) {
275 print '<td class="liste_titre center maxwidthsearch">';
276 $searchpicto = $form->showFilterButtons('left');
277 print $searchpicto;
278 print '</td>';
279}
280print '<td class="liste_titre"><input type="text" name="search_secret_key" class="maxwidth50" value="'.$search_secret_key.'"></td>';
281// Action column
282if (!$conf->main_checkbox_left_column) {
283 print '<td class="liste_titre maxwidthsearch">';
284 $searchpicto = $form->showFilterButtons();
285 print $searchpicto;
286 print '</td>';
287}
288print '</tr>'."\n";
289
290$totalarray = array();
291$totalarray['nbfield'] = 0;
292
293// Fields title label
294// --------------------------------------------------------------------
295print '<tr class="liste_titre">';
296if ($conf->main_checkbox_left_column) {
297 print getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
298 $totalarray['nbfield']++;
299}
300print_liste_field_titre('TOTPSecretKey', $_SERVER['PHP_SELF'], "u.rowid", '', $param, '', $sortfield, $sortorder);
301$totalarray['nbfield']++;
302// Action column
303if (!$conf->main_checkbox_left_column) {
304 print getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
305 $totalarray['nbfield']++;
306}
307print '</tr>'."\n";
308
309foreach ($listoftotps as $totp) {
310 // TODO
311 print '<tr>';
312 if ($conf->main_checkbox_left_column) {
313 print '<td></td>';
314 }
315 print '<td>';
316 print $totp['id'];
317 print '</td>';
318 if (!$conf->main_checkbox_left_column) {
319 print '<td></td>';
320 }
321 print '</tr>';
322}
323
324if (empty($listoftotps)) {
325 print '<tr><td colspan="2"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
326}
327
328print '</table>'."\n";
329print '</div>'."\n";
330
331print '</form>';
332
333// Add button to autosuggest a key
334include_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
335print dolJSToSetRandomPassword('password', 'generate_password', 0);
336if (isModEnabled('api')) {
337 print dolJSToSetRandomPassword('api_key', 'generate_api_key', 1);
338}
339
340
341
342
343// Section Other
344
345// ...
346
347
348
349// End of page
350llxFooter();
351$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$totalarray
Definition list.php:497
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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.
Definition wrapper.php:73
Class to manage generation of HTML components Only common components must be here.
Class to manage Dolibarr users.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dolJSToSetRandomPassword($htmlname, $htmlnameofbutton='generate_token', $generic=1)
Output javascript to autoset a generated password using default module into a HTML element.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.