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.
'/core/lib/security2.lib.php';
42require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
45require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
46require_once DOL_DOCUMENT_ROOT.
'/core/lib/usergroups.lib.php';
47require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
48require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
49require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
50require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
51require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
53 require_once DOL_DOCUMENT_ROOT.
'/core/class/ldap.class.php';
56 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
59 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
62 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
66$langs->loadLangs(array(
'users',
'companies',
'ldap',
'admin',
'hrm',
'stocks',
'other'));
69$action =
GETPOST(
'action',
'aZ09');
70$mode =
GETPOST(
'mode',
'alpha');
71$confirm =
GETPOST(
'confirm',
'alpha');
72$optioncss =
GETPOST(
'optioncss',
'aZ09');
73$cancel =
GETPOST(
'cancel',
'alpha');
74$contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'usercredentials';
75$backtopage =
GETPOST(
'backtopage');
76$backtopageforcancel =
GETPOST(
'backtopageforcancel');
82$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
83$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
85if (empty($page) || $page < 0 ||
GETPOST(
'button_search',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
89$offset = $limit * $page;
94if (empty($id) && $action !=
'add' && $action !=
'create') {
101$extrafields->fetch_name_optionals_label(
$object->table_element);
104$hookmanager->initHooks(array(
'usercard',
'globalcard'));
109 $res =
$object->fetch($id,
'',
'', 1);
114if ($user->socid > 0) {
115 $socid = $user->socid;
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;
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);
132$permissiontoclonesuperadmin = ($permissiontoadd && empty($user->entity));
133$permissiontocloneadmin = ($permissiontoadd && !empty($user->admin));
134$permissiontocloneuser = $permissiontoadd;
137 $permissiontoclonesuperadmin =
false;
138 $permissiontocloneadmin =
false;
139 $permissiontocloneuser =
false;
142if ($user->id != $id && !$permissiontoread) {
146$caneditpasswordandsee =
false;
147$caneditpasswordandsend =
false;
150$permissiontoeditpasswordandsee =
false;
151$permissiontoeditpasswordandsend =
false;
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);
164$parameters = array(
'id' => $id,
'socid' => $socid,
'group' => $group,
'caneditgroup' => $permissiontoeditgroup);
165$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
167 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
170if (empty($reshook)) {
171 $backurlforlist = DOL_URL_ROOT.
'/user/list.php';
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;
178 $backtopage = DOL_URL_ROOT.
'/user/card.php?id='.((!empty($id) &&
$id > 0) ? $id :
'__ID__');
184 if (!empty($backtopageforcancel)) {
185 header(
"Location: ".$backtopageforcancel);
187 } elseif (!empty($backtopage)) {
188 header(
"Location: ".$backtopage);
195 if ($action ==
'addtotp' && $permissiontoeditpasswordandsee && $user->id ==
$object->id &&
getDolGlobalString(
'MAIN_SECURITY_ALLOW_TOTP')) {
197 setEventMessages($langs->trans(
"TOTPAlreadyEnrolled"),
null,
'warnings');
199 } elseif (empty($_SESSION[
'dol_totp_enroll'][
$object->id]) || $_SESSION[
'dol_totp_enroll'][
$object->id][
'expire'] <
dol_now()) {
207 if ($action ==
'confirmtotp' && $permissiontoeditpasswordandsee && $user->id ==
$object->id &&
getDolGlobalString(
'MAIN_SECURITY_ALLOW_TOTP')) {
208 $enroll = empty($_SESSION[
'dol_totp_enroll'][
$object->id]) ? array() : $_SESSION[
'dol_totp_enroll'][
$object->id];
209 if (empty($enroll[
'secret']) || $enroll[
'expire'] <
dol_now()) {
210 unset($_SESSION[
'dol_totp_enroll'][
$object->id]);
211 setEventMessages($langs->trans(
"TOTPEnrollmentExpired"),
null,
'errors');
215 if ($laststep <= 0) {
216 dol_syslog(
"Two-factor authentication enrollment of ".
$object->login.
": confirmation code refused", LOG_WARNING);
217 $_SESSION[
'dol_totp_enroll'][
$object->id][
'tries'] = (empty($enroll[
'tries']) ? 0 : $enroll[
'tries']) + 1;
218 if ($_SESSION[
'dol_totp_enroll'][
$object->id][
'tries'] >= 5) {
219 unset($_SESSION[
'dol_totp_enroll'][
$object->id]);
220 setEventMessages($langs->trans(
"TOTPEnrollmentExpired"),
null,
'errors');
223 setEventMessages($langs->trans(
"TOTPBadCode"),
null,
'errors');
229 unset($_SESSION[
'dol_totp_enroll'][
$object->id]);
231 setEventMessages($langs->trans(
"TOTPEnrolled"),
null,
'mesgs');
233 } elseif ($result == -2) {
234 unset($_SESSION[
'dol_totp_enroll'][
$object->id]);
235 setEventMessages($langs->trans(
"TOTPNoEncryptionKey"),
null,
'errors');
238 setEventMessages($db->lasterror(),
null,
'errors');
246 if ($action ==
'canceltotp' && $permissiontoeditpasswordandsee && $user->id ==
$object->id) {
247 unset($_SESSION[
'dol_totp_enroll'][
$object->id]);
252 if ($action ==
'confirm_deletetotp' && $confirm ==
'yes' && $permissiontoeditpasswordandsee) {
254 dol_syslog(
"Two-factor authentication disabled for ".
$object->login.
" by ".$user->login, LOG_WARNING);
255 setEventMessages($langs->trans(
"TOTPRemoved"),
null,
'mesgs');
257 setEventMessages($db->lasterror(),
null,
'errors');
268$form =
new Form($db);
271$title = $person_name.
" - ".$langs->trans(
'Credentials');
274if ($action ==
'addtotp') {
275 header(
"Cache-Control: no-cache, no-store, must-revalidate, max-age=0");
278llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-user page-credentials');
286if ($action ==
'addtotp' && $user->id ==
$object->id && !empty($_SESSION[
'dol_totp_enroll'][
$object->id][
'secret'])) {
287 $secrettoshow = $_SESSION[
'dol_totp_enroll'][
$object->id][
'secret'];
289 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
290 print
'<input type="hidden" name="token" value="'.newToken().
'">';
291 print
'<input type="hidden" name="action" value="confirmtotp">';
292 print
'<input type="hidden" name="id" value="'.((int)
$object->id).
'">';
293 print
'<div class="info">';
294 print
'<div class="paddingbottom">'.$langs->trans(
"TOTPScanQrCode").
'</div>';
296 require_once TCPDF_PATH.
'tcpdf_barcodes_2d.php';
298 $qrpng = $qrobj->getBarcodePngData(4, 4, array(0, 0, 0));
299 if (!empty($qrpng)) {
300 print
'<div class="paddingbottom"><img src="data:image/png;base64,'.base64_encode($qrpng).
'" alt=""></div>';
303 print
'<div class="paddingbottom">'.$langs->trans(
"TOTPOrTypeKey").
' <strong>'.dolPrintLabel(trim(chunk_split($secrettoshow, 4,
' '))).
'</strong></div>';
304 print
'<div>'.$langs->trans(
"TOTPConfirmCode").
' ';
305 print
'<input type="text" name="totpcode" class="width75" autocomplete="off" inputmode="numeric" maxlength="8" autofocus>';
306 print
' <input type="submit" class="button small" value="'.$langs->trans(
"Validate").
'">';
307 print
' <a class="button button-cancel small" href="'.$_SERVER[
"PHP_SELF"].
'?id='.((int)
$object->id).
'&action=canceltotp&token='.
newToken().
'">'.$langs->trans(
"Cancel").
'</a>';
313print
'<form method="POST" id="searchFormList" action="'.$_SERVER[
"PHP_SELF"].
'">'.
"\n";
314print
'<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
315print
'<input type="hidden" name="token" value="'.newToken().
'">';
316print
'<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
317print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
318print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
319print
'<input type="hidden" name="page" value="'.$page.
'">';
320print
'<input type="hidden" name="contextpage" value="'.$contextpage.
'">';
321print
'<input type="hidden" name="page_y" value="">';
322print
'<input type="hidden" name="mode" value="'.$mode.
'">';
328$cancreatetotp = ($permissiontoeditpasswordandsee && $user->id ==
$object->id &&
getDolGlobalString(
'MAIN_SECURITY_ALLOW_TOTP') && $totpenrollment ===
null);
330$newcardbutton =
dolGetButtonTitle($langs->trans(
'New'),
'',
'fa fa-plus-circle', $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=addtotp&token='.
newToken(),
'', $cancreatetotp ? 1 : 0);
333$nbtotalofrecords = $num = ($totpenrollment ===
null ? 0 : 1);
335$massactionbutton =
'';
337print_barre_liste($langs->trans(
"TOTP"), $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords,
$object->picto, 0, $newcardbutton,
'', $limit, -1, 0, 1);
349if ($action ==
'deletetotp' && $permissiontoeditpasswordandsee) {
350 print $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.((
int)
$object->id), $langs->trans(
'TOTPDisable'), $langs->trans(
'TOTPConfirmDisable',
$object->login),
'confirm_deletetotp',
'', 0, 1);
353print
'<div class="div-table-responsive">';
354print
'<table class="tagtable nobottomiftotal liste">'.
"\n";
358print
'<tr class="liste_titre">';
361print
getTitleFieldOfList(
'', 0, $_SERVER[
"PHP_SELF"],
'',
'',
'',
'', $sortfield, $sortorder,
'center maxwidthsearch ').
"\n";
365if ($totpenrollment !==
null) {
366 print
'<tr class="oddeven">';
367 if (is_array($totpenrollment)) {
368 print
'<td>'.dol_print_date($totpenrollment[
'datec'],
'dayhour').
'</td>';
369 print
'<td>'.($totpenrollment[
'lastaccess'] ?
dol_print_date($totpenrollment[
'lastaccess'],
'dayhour') :
'<span class="opacitymedium">'.$langs->trans(
"Never").
'</span>').
'</td>';
371 print
'<td colspan="2"><span class="error">'.$langs->trans(
"TOTPUnreadableEnrollment").
'</span></td>';
373 print
'<td class="center nowraponall">';
374 if ($permissiontoeditpasswordandsee) {
375 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.((int)
$object->id).
'&action=deletetotp&token='.
newToken().
'">'.img_delete($langs->trans(
"TOTPDisable")).
'</a>';
380 print
'<tr><td colspan="3"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
383print
'</table>'.
"\n";
389include_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
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:
Class to manage Dolibarr users.
dol_now($mode='gmt')
Return date for now.
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.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
dolTotpSaveEnrollment($db, $fk_user, $secret, $laststep, $entity=1)
Save a TOTP enrollment confirmed by a valid code.
dolJSToSetRandomPassword($htmlname, $htmlnameofbutton='generate_token', $generic=1)
Output javascript to autoset a generated password using default module into a HTML element.
dolTotpNewSecret($nbbytes=20)
Generate a new secret for a TOTP enrollment (RFC 6238), in the base32 form expected by the authentica...
dolTotpDeleteEnrollment($db, $fk_user)
Delete the TOTP enrollment of a user, who then logs in with the password only again.
dolTotpGetUri($login, $base32secret, $issuer='', $digits=6, $period=30)
Build the otpauth:// URI of an enrollment, to be shown as a QR code to the user.
dolTotpCheckCode($base32secret, $code, $timestamp=0, $period=30, $digits=6, $drift=1)
Check a code sent by a user against a secret, accepting a drift of some periods to tolerate a clock o...
dolTotpGetEnrollment($db, $fk_user)
Load the TOTP enrollment of a user.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
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.