Go to the documentation of this file.
26 require
'../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
30 $action =
GETPOST(
'action',
'aZ09');
33 $langs->loadLangs(array(
"users",
"admin",
"other"));
40 $allow_disable_encryption =
true;
47 if ($action ==
'setgeneraterule') {
48 if (!
dolibarr_set_const($db,
'USER_PASSWORD_GENERATED',
GETPOST(
"value",
"alphanohtml"),
'chaine', 0,
'', $conf->entity)) {
51 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
56 if ($action ==
'activate_encrypt') {
62 dolibarr_del_const($db,
"DATABASE_PWD_ENCRYPTED",
"1",
'chaine', 0,
'', $conf->entity);
65 dolibarr_set_const($db,
"DATABASE_PWD_ENCRYPTED",
"1",
'chaine', 0,
'', $entityforall);
67 $sql =
"SELECT u.rowid, u.pass, u.pass_crypted";
68 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
69 $sql .=
" WHERE u.pass IS NOT NULL AND LENGTH(u.pass) < 32";
73 $numrows = $db->num_rows(
$resql);
75 while ($i < $numrows) {
76 $obj = $db->fetch_object(
$resql);
78 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"user";
79 $sql .=
" SET pass_crypted = '".dol_hash($obj->pass).
"', pass = NULL";
80 $sql .=
" WHERE rowid=".((int) $obj->rowid);
83 $resql2 = $db->query($sql);
101 header(
"Location: security.php");
107 } elseif ($action ==
'disable_encrypt') {
110 if ($allow_disable_encryption) {
113 header(
"Location: security.php");
117 if ($action ==
'activate_encryptdbpassconf') {
124 header(
"Location: security.php");
129 } elseif ($action ==
'disable_encryptdbpassconf') {
136 header(
"Location: security.php");
139 setEventMessages($langs->trans(
'InstrucToClearPass', $dolibarr_main_db_pass),
null,
'warnings');
143 if ($action ==
'activate_MAIN_SECURITY_DISABLEFORGETPASSLINK') {
144 dolibarr_set_const($db,
"MAIN_SECURITY_DISABLEFORGETPASSLINK",
'1',
'chaine', 0,
'', $conf->entity);
145 header(
"Location: security.php");
147 } elseif ($action ==
'disable_MAIN_SECURITY_DISABLEFORGETPASSLINK') {
149 header(
"Location: security.php");
153 if ($action ==
'updatepattern') {
154 $pattern =
GETPOST(
"pattern",
"alpha");
155 $explodePattern = explode(
';', $pattern);
157 $patternInError =
false;
158 if ($explodePattern[0] < 1 || $explodePattern[4] < 0) {
159 $patternInError =
true;
162 if ($explodePattern[0] < $explodePattern[1] + $explodePattern[2] + $explodePattern[3]) {
163 $patternInError =
true;
166 if (!$patternInError) {
167 dolibarr_set_const($db,
"USER_PASSWORD_PATTERN", $pattern,
'chaine', 0,
'', $conf->entity);
169 header(
"Location: security.php");
182 $wikihelp =
'EN:Setup_Security|FR:Paramétrage_Sécurité|ES:Configuración_Seguridad';
187 print
'<span class="opacitymedium">'.$langs->trans(
"GeneratedPasswordDesc").
"</span><br>\n";
198 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
199 print
'<input type="hidden" name="token" value="'.newToken().
'">';
200 print
'<input type="hidden" name="action" value="update">';
201 print
'<input type="hidden" name="constname" value="USER_PASSWORD_GENERATED">';
202 print
'<input type="hidden" name="consttype" value="yesno">';
205 $dir =
"../core/modules/security/generate";
207 $handle = opendir($dir);
209 if (is_resource($handle)) {
210 while (($file = readdir($handle)) !==
false) {
211 if (preg_match(
'/(modGeneratePass[a-z]+)\.class\.php$/i', $file, $reg)) {
213 $classname = $reg[1];
214 require_once $dir.
'/'.$file;
216 $obj =
new $classname($db, $conf, $langs, $user);
217 $arrayhandler[$obj->id] = $obj;
223 asort($arrayhandler);
225 print
'<div class="div-table-responsive-no-min">';
226 print
'<table class="noborder centpercent">';
227 print
'<tr class="liste_titre">';
228 print
'<td colspan="2">'.$langs->trans(
"RuleForGeneratedPasswords").
'</td>';
229 print
'<td>'.$langs->trans(
"Example").
'</td>';
230 print
'<td class="center">'.$langs->trans(
"Activated").
'</td>';
233 foreach ($arrayhandler as $key => $module) {
235 if (!empty($module->version) && $module->version ==
'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
238 if (!empty($module->version) && $module->version ==
'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
242 if ($module->isEnabled()) {
243 print
'<tr class="oddeven"><td width="100">';
246 print $module->getDescription().
'<br>';
247 print $langs->trans(
"MinLength").
': '.$module->length;
251 print
'<td class="nowrap">';
252 $tmp = $module->getExample();
253 if (preg_match(
'/^Error/', $tmp)) {
254 $langs->load(
"errors");
255 print
'<div class="error">'.$langs->trans($tmp).
'</div>';
256 } elseif ($tmp ==
'NotConfigured') {
257 print
'<span class="opacitymedium">'.$langs->trans($tmp).
'</span>';
259 print
'<span class="opacitymedium">'.$tmp.
'</span>';
263 print
'<td width="100" align="center">';
264 if ($conf->global->USER_PASSWORD_GENERATED == $key) {
266 print
img_picto($langs->trans(
"Enabled"),
'switch_on');
268 print
'<a href="'.$_SERVER[
'PHP_SELF'].
'?action=setgeneraterule&token='.
newToken().
'&value='.$key.
'">';
270 print
img_picto($langs->trans(
"Disabled"),
'switch_off');
273 print
"</td></tr>\n";
283 if ($conf->global->USER_PASSWORD_GENERATED ==
"Perso") {
284 $tabConf = explode(
";", $conf->global->USER_PASSWORD_PATTERN);
287 print
'<div class="div-table-responsive-no-min">';
288 print
'<table class="noborder centpercent">';
289 print
'<tr class="liste_titre">';
290 print
'<td colspan="2"> '.$langs->trans(
"PasswordPatternDesc").
'</td>';
294 print
'<tr class="oddeven">';
295 print
'<td>'.$langs->trans(
"MinLength").
"</td>";
296 print
'<td><input type="number" value="'.$tabConf[0].
'" id="minlenght" min="1"></td>';
300 print
'<tr class="oddeven">';
301 print
'<td>'.$langs->trans(
"NbMajMin").
"</td>";
302 print
'<td><input type="number" value="'.$tabConf[1].
'" id="NbMajMin" min="0"></td>';
306 print
'<tr class="oddeven">';
307 print
'<td>'.$langs->trans(
"NbNumMin").
"</td>";
308 print
'<td><input type="number" value="'.$tabConf[2].
'" id="NbNumMin" min="0"></td>';
312 print
'<tr class="oddeven">';
313 print
'<td>'.$langs->trans(
"NbSpeMin").
"</td>";
314 print
'<td><input type="number" value="'.$tabConf[3].
'" id="NbSpeMin" min="0"></td>';
318 print
'<tr class="oddeven">';
319 print
'<td>'.$langs->trans(
"NbIteConsecutive").
"</td>";
320 print
'<td><input type="number" value="'.$tabConf[4].
'" id="NbIteConsecutive" min="0"></td>';
324 print
'<tr class="oddeven">';
325 print
'<td>'.$langs->trans(
"NoAmbiCaracAutoGeneration").
"</td>";
326 print
'<td><input type="checkbox" id="NoAmbiCaracAutoGeneration" '.($tabConf[5] ?
"checked" :
"").
' min="0"> <label for="NoAmbiCaracAutoGeneration" id="textcheckbox">'.($tabConf[5] ? $langs->trans(
"Activated") : $langs->trans(
"Disabled")).
'</label></td>';
332 print
'<div class="center">';
333 print
'<a class="button button-save" id="linkChangePattern">'.$langs->trans(
"Save").
'</a>';
337 print
'<script type="text/javascript">';
338 print
' function getStringArg(){';
339 print
' var pattern = "";';
340 print
' pattern += $("#minlenght").val() + ";";';
341 print
' pattern += $("#NbMajMin").val() + ";";';
342 print
' pattern += $("#NbNumMin").val() + ";";';
343 print
' pattern += $("#NbSpeMin").val() + ";";';
344 print
' pattern += $("#NbIteConsecutive").val() + ";";';
345 print
' pattern += $("#NoAmbiCaracAutoGeneration")[0].checked ? "1" : "0";';
346 print
' return pattern;';
349 print
' function valuePossible(){';
350 print
' var fields = ["#minlenght", "#NbMajMin", "#NbNumMin", "#NbSpeMin", "#NbIteConsecutive"];';
351 print
' for(var i = 0 ; i < fields.length ; i++){';
352 print
' if($(fields[i]).val() < $(fields[i]).attr("min")){';
353 print
' return false;';
357 print
' var length = parseInt($("#minlenght").val());';
358 print
' var length_mini = parseInt($("#NbMajMin").val()) + parseInt($("#NbNumMin").val()) + parseInt($("#NbSpeMin").val());';
359 print
' return length >= length_mini;';
362 print
' function generatelink(){';
363 print
' return "security.php?action=updatepattern&token='.newToken().
'&pattern="+getStringArg();';
366 print
' function valuePatternChange(){';
367 print
' console.log("valuePatternChange");';
368 print
' var lang_save = "'.$langs->trans(
"Save").
'";';
369 print
' var lang_error = "'.$langs->trans(
"Error").
'";';
370 print
' var lang_Disabled = "'.$langs->trans(
"Disabled").
'";';
371 print
' var lang_Activated = "'.$langs->trans(
"Activated").
'";';
372 print
' $("#textcheckbox").html($("#NoAmbiCaracAutoGeneration")[0].checked ? unescape(lang_Activated) : unescape(lang_Disabled));';
373 print
' if(valuePossible()){';
374 print
' $("#linkChangePattern").attr("href",generatelink()).text(lang_save);';
377 print
' $("#linkChangePattern").attr("href", null).text(lang_error);';
381 print
' $("#minlenght").change(function(){valuePatternChange();});';
382 print
' $("#NbMajMin").change(function(){valuePatternChange();});';
383 print
' $("#NbNumMin").change(function(){valuePatternChange();});';
384 print
' $("#NbSpeMin").change(function(){valuePatternChange();});';
385 print
' $("#NbIteConsecutive").change(function(){valuePatternChange();});';
386 print
' $("#NoAmbiCaracAutoGeneration").change(function(){valuePatternChange();});';
395 print
"<form method=\"post\" action=\"".$_SERVER[
"PHP_SELF"].
"\">";
396 print
'<input type="hidden" name="token" value="'.newToken().
'">';
397 print
"<input type=\"hidden\" name=\"action\" value=\"encrypt\">";
399 print
'<table class="noborder centpercent">';
400 print
'<tr class="liste_titre">';
401 print
'<td colspan="3">'.$langs->trans(
"Parameters").
'</td>';
402 print
'<td class="center">'.$langs->trans(
"Activated").
'</td>';
403 print
'<td class="center">'.$langs->trans(
"Action").
'</td>';
407 print
'<tr class="oddeven">';
408 print
'<td colspan="3">'.$langs->trans(
"DoNotStoreClearPassword").
'</td>';
409 print
'<td class="center" width="60">';
411 print
img_picto($langs->trans(
"Active"),
'tick');
415 print
'<td class="center" width="100">';
416 print
'<a href="security.php?action=activate_encrypt">'.$langs->trans(
"Activate").
'</a>';
422 print
'<td class="center" width="100">';
423 if ($allow_disable_encryption) {
426 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=disable_encrypt&token='.
newToken().
'">'.$langs->trans(
"Disable").
'</a>';
438 print
'<tr class="oddeven">';
439 print
'<td colspan="3">'.$langs->trans(
"MainDbPasswordFileConfEncrypted").
'</td>';
440 print
'<td align="center" width="60">';
441 if (preg_match(
'/crypted:/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass)) {
442 print
img_picto($langs->trans(
"Active"),
'tick');
447 print
'<td class="center" width="100">';
448 if (empty($dolibarr_main_db_pass) && empty($dolibarr_main_db_encrypted_pass)) {
449 $langs->load(
"errors");
450 print
img_warning($langs->trans(
"WarningPassIsEmpty"));
452 if (empty($dolibarr_main_db_encrypted_pass)) {
453 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=activate_encryptdbpassconf&token='.
newToken().
'">'.$langs->trans(
"Activate").
'</a>';
455 if (!empty($dolibarr_main_db_encrypted_pass)) {
456 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=disable_encryptdbpassconf&token='.
newToken().
'">'.$langs->trans(
"Disable").
'</a>';
467 print
'<tr class="oddeven">';
468 print
'<td colspan="3">'.$langs->trans(
"DisableForgetPasswordLinkOnLogonPage").
'</td>';
469 print
'<td class="center" width="60">';
471 print
img_picto($langs->trans(
"Active"),
'tick');
475 print
'<td class="center" width="100">';
476 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=activate_MAIN_SECURITY_DISABLEFORGETPASSLINK&token='.
newToken().
'">'.$langs->trans(
"Activate").
'</a>';
480 print
'<td class="center" width="100">';
481 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=disable_MAIN_SECURITY_DISABLEFORGETPASSLINK&token='.
newToken().
'">'.$langs->trans(
"Disable").
'</a>';
492 if (
GETPOST(
'info',
'int') > 0) {
493 if (function_exists(
'password_hash')) {
494 print $langs->trans(
"Note: The function password_hash exists on your PHP").
"<br>\n";
496 print $langs->trans(
"Note: The function password_hash does not exists on your PHP").
"<br>\n";
498 print
'MAIN_SECURITY_HASH_ALGO = '.getDolGlobalString(
'MAIN_SECURITY_HASH_ALGO').
"<br>\n";
499 print
'MAIN_SECURITY_SALT = '.getDolGlobalString(
'MAIN_SECURITY_SALT').
"<br>\n";
security_prepare_head()
Prepare array with list of tabs.
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
encodedecode_dbpassconf($level=0)
Encode or decode database password in config file.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_hash($chain, $type='0')
Returns a hash of a string.
if($actionsave) if(!isset($conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY)) $wikihelp
View.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_encode($chain, $key='1')
Encode a string with base 64 algorithm + specific delta change.
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).
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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 ...
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.