28require
'../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
32$action =
GETPOST(
'action',
'aZ09');
35$langs->loadLangs(array(
"users",
"admin",
"other"));
42$allow_disable_encryption =
false;
49if ($action ==
'setgeneraterule') {
50 if (!
dolibarr_set_const($db,
'USER_PASSWORD_GENERATED',
GETPOST(
"value",
"alphanohtml"),
'chaine', 0,
'', $conf->entity)) {
55if ($action ==
'activate_encrypt') {
64 dolibarr_set_const($db,
"DATABASE_PWD_ENCRYPTED",
"1",
'chaine', 0,
'', $entityforall);
66 $sql =
"SELECT u.rowid, u.pass, u.pass_crypted";
67 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
68 $sql .=
" WHERE u.pass IS NOT NULL AND LENGTH(u.pass) < 32";
70 $resql = $db->query($sql);
72 $numrows = $db->num_rows($resql);
74 while ($i < $numrows) {
75 $obj = $db->fetch_object($resql);
77 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"user";
78 $sql .=
" SET pass_crypted = '".dol_hash($obj->pass).
"', pass = NULL";
79 $sql .=
" WHERE rowid=".((int) $obj->rowid);
82 $resql2 = $db->query($sql);
104} elseif ($action ==
'disable_encrypt') {
106 if ($allow_disable_encryption) {
111if ($action ==
'activate_encryptdbpassconf') {
118 header(
"Location: security.php");
123} elseif ($action ==
'disable_encryptdbpassconf') {
130 header(
"Location: security.php");
134 setEventMessages($langs->trans(
'InstrucToClearPass', $langs->transnoentitiesnoconv(
"DatabasePassword")),
null,
'warnings');
138if ($action ==
'activate_MAIN_SECURITY_DISABLEFORGETPASSLINK') {
139 dolibarr_set_const($db,
"MAIN_SECURITY_DISABLEFORGETPASSLINK",
'1',
'chaine', 0,
'', $conf->entity);
140} elseif ($action ==
'disable_MAIN_SECURITY_DISABLEFORGETPASSLINK') {
144if ($action ==
'updatepattern') {
145 $pattern =
GETPOST(
"pattern",
"alpha");
146 $explodePattern = explode(
';', $pattern);
148 $patternInError =
false;
149 if ((
int) $explodePattern[0] < 1 || (
int) $explodePattern[4] < 0) {
150 $patternInError =
true;
153 if ((
int) $explodePattern[0] < (
int) $explodePattern[1] + (
int) $explodePattern[2] + (
int) $explodePattern[3]) {
154 $patternInError =
true;
157 if (!$patternInError) {
158 dolibarr_set_const($db,
"USER_PASSWORD_PATTERN", $pattern,
'chaine', 0,
'', $conf->entity);
160 header(
"Location: security.php");
171$form =
new Form($db);
173$wikihelp =
'EN:Setup_Security|FR:Paramétrage_Sécurité|ES:Configuración_Seguridad';
174llxHeader(
'', $langs->trans(
"Passwords"), $wikihelp,
'', 0, 0,
'',
'',
'',
'mod-admin page-security');
178print
'<span class="opacitymedium">'.$langs->trans(
"GeneratedPasswordDesc").
"</span><br>\n";
189print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
190print
'<input type="hidden" name="token" value="'.newToken().
'">';
191print
'<input type="hidden" name="action" value="update">';
192print
'<input type="hidden" name="constname" value="USER_PASSWORD_GENERATED">';
193print
'<input type="hidden" name="consttype" value="yesno">';
196$dir =
"../core/modules/security/generate";
198$handle = opendir($dir);
200$arrayhandler = array();
201if (is_resource($handle)) {
202 while (($file = readdir($handle)) !==
false) {
203 if (preg_match(
'/(modGeneratePass[a-z]+)\.class\.php$/i', $file, $reg)) {
205 $classname = $reg[1];
206 require_once $dir.
'/'.$file;
208 $obj =
new $classname($db, $conf, $langs, $user);
209 '@phan-var-force ModeleGenPassword $obj';
210 $arrayhandler[$obj->id] = $obj;
218print
'<div class="div-table-responsive-no-min">';
219print
'<table class="noborder centpercent">';
220print
'<tr class="liste_titre">';
221print
'<td colspan="2">'.$langs->trans(
"RuleForGeneratedPasswords").
'</td>';
222print
'<td>'.$langs->trans(
"Example").
'</td>';
223print
'<td class="center">'.$langs->trans(
"Activated").
'</td>';
228foreach ($arrayhandler as $key => $module) {
230 if (!empty($module->version) && $module->version ==
'development' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 2) {
233 if (!empty($module->version) && $module->version ==
'experimental' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 1) {
237 if ($module->isEnabled()) {
238 print
'<tr class="oddeven"><td>';
239 print
img_picto(
'', $module->picto,
'class="width25 size15x marginrightonly"').
' ';
242 print $module->getDescription().
'<br>';
243 print $langs->trans(
"MinLength").
': <span class="opacitymedium">'.$module->length.
'</span>';
247 print
'<td class="nowraponall">';
248 $tmp = $module->getExample();
249 if (preg_match(
'/^Error/', $tmp)) {
250 $langs->load(
"errors");
251 print
'<div class="error">'.$langs->trans($tmp).
'</div>';
252 } elseif ($tmp ==
'NotConfigured') {
253 print
'<span class="opacitymedium">'.$langs->trans($tmp).
'</span>';
255 print
'<span class="opacitymedium">'.$tmp.
'</span>';
259 print
'<td class="center">';
260 if ($conf->global->USER_PASSWORD_GENERATED == $key) {
262 print
img_picto($langs->trans(
"Enabled"),
'switch_on');
264 print
'<a href="'.$_SERVER[
'PHP_SELF'].
'?action=setgeneraterule&token='.
newToken().
'&value='.$key.
'">';
266 print
img_picto($langs->trans(
"Disabled"),
'switch_off');
269 print
"</td></tr>\n";
282 print
'<div class="div-table-responsive-no-min">';
283 print
'<table class="noborder centpercent">';
284 print
'<tr class="liste_titre">';
285 print
'<td colspan="2"> '.$langs->trans(
"PasswordPatternDesc").
'</td>';
289 print
'<tr class="oddeven">';
290 print
'<td>'.$langs->trans(
"MinLength").
"</td>";
291 print
'<td><input type="number" class="width50 right" value="'.$tabConf[0].
'" id="minlength" min="1"></td>';
295 print
'<tr class="oddeven">';
296 print
'<td>'.$langs->trans(
"NbMajMin").
"</td>";
297 print
'<td><input type="number" class="width50 right" value="'.$tabConf[1].
'" id="NbMajMin" min="0"></td>';
301 print
'<tr class="oddeven">';
302 print
'<td>'.$langs->trans(
"NbNumMin").
"</td>";
303 print
'<td><input type="number" class="width50 right" value="'.$tabConf[2].
'" id="NbNumMin" min="0"></td>';
307 print
'<tr class="oddeven">';
308 print
'<td>'.$langs->trans(
"NbSpeMin").
"</td>";
309 print
'<td><input type="number" class="width50 right" value="'.$tabConf[3].
'" id="NbSpeMin" min="0"></td>';
313 print
'<tr class="oddeven">';
314 print
'<td>'.$langs->trans(
"NbIteConsecutive").
"</td>";
315 print
'<td><input type="number" class="width50 right" value="'.$tabConf[4].
'" id="NbIteConsecutive" min="0"></td>';
319 print
'<tr class="oddeven">';
320 print
'<td>'.$langs->trans(
"NoAmbiCaracAutoGeneration").
"</td>";
321 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>';
326 print
'<div class="center">';
327 print
'<a class="button button-save" id="linkChangePattern">'.$langs->trans(
"Save").
'</a>';
332 print
'<script type="text/javascript">';
333 print
' function getStringArg(){';
334 print
' var pattern = "";';
335 print
' pattern += $("#minlenght").val() + ";";';
336 print
' pattern += $("#NbMajMin").val() + ";";';
337 print
' pattern += $("#NbNumMin").val() + ";";';
338 print
' pattern += $("#NbSpeMin").val() + ";";';
339 print
' pattern += $("#NbIteConsecutive").val() + ";";';
340 print
' pattern += $("#NoAmbiCaracAutoGeneration")[0].checked ? "1" : "0";';
341 print
' return pattern;';
344 print
' function valuePossible(){';
345 print
' var fields = ["#minlenght", "#NbMajMin", "#NbNumMin", "#NbSpeMin", "#NbIteConsecutive"];';
346 print
' for(var i = 0 ; i < fields.length ; i++){';
347 print
' if($(fields[i]).val() < $(fields[i]).attr("min")){';
348 print
' return false;';
352 print
' var length = parseInt($("#minlenght").val());';
353 print
' var length_mini = parseInt($("#NbMajMin").val()) + parseInt($("#NbNumMin").val()) + parseInt($("#NbSpeMin").val());';
354 print
' return length >= length_mini;';
357 print
' function generatelink(){';
358 print
' return "security.php?action=updatepattern&token='.newToken().
'&pattern="+getStringArg();';
361 print
' function valuePatternChange(){';
362 print
' console.log("valuePatternChange");';
363 print
' var lang_save = "'.$langs->trans(
"Save").
'";';
364 print
' var lang_error = "'.$langs->trans(
"Error").
'";';
365 print
' var lang_Disabled = "'.$langs->trans(
"Disabled").
'";';
366 print
' var lang_Activated = "'.$langs->trans(
"Activated").
'";';
367 print
' $("#textcheckbox").html($("#NoAmbiCaracAutoGeneration")[0].checked ? unescape(lang_Activated) : unescape(lang_Disabled));';
368 print
' if(valuePossible()){';
369 print
' $("#linkChangePattern").attr("href",generatelink()).text(lang_save);';
372 print
' $("#linkChangePattern").attr("href", null).text(lang_error);';
376 print
' $("#minlenght").change(function(){valuePatternChange();});';
377 print
' $("#NbMajMin").change(function(){valuePatternChange();});';
378 print
' $("#NbNumMin").change(function(){valuePatternChange();});';
379 print
' $("#NbSpeMin").change(function(){valuePatternChange();});';
380 print
' $("#NbIteConsecutive").change(function(){valuePatternChange();});';
381 print
' $("#NoAmbiCaracAutoGeneration").change(function(){valuePatternChange();});';
390print
'<form method="post" action="'.$_SERVER[
"PHP_SELF"].
'">';
391print
'<input type="hidden" name="token" value="'.newToken().
'">';
392print
'<input type="hidden" name="action" value="encrypt">';
394print
'<table class="noborder centpercent">';
395print
'<tr class="liste_titre">';
396print
'<td colspan="3">'.$langs->trans(
"Parameters").
'</td>';
397print
'<td class="center">'.$langs->trans(
"Activated").
'</td>';
398print
'<td class="center"></td>';
402print
'<tr class="oddeven">';
403print
'<td colspan="3">'.$langs->trans(
"DoNotStoreClearPassword").
'</td>';
404print
'<td class="center" width="60">';
406 print
img_picto($langs->trans(
"Active"),
'tick');
410 print
'<td class="center" width="100">';
411 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=activate_encrypt&token='.
newToken().
'">'.$langs->trans(
"Activate").
'</a>';
414 print
'<td class="center" width="100">';
415 if ($allow_disable_encryption) {
418 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=disable_encrypt&token='.
newToken().
'">'.$langs->trans(
"Disable").
'</a>';
420 print
'<span class="opacitymedium">'.$langs->trans(
"Always").
'</span>';
430print
'<tr class="oddeven">';
431print
'<td colspan="3">'.$langs->trans(
"MainDbPasswordFileConfEncrypted").
'</td>';
432print
'<td align="center" width="60">';
433if (preg_match(
'/crypted:/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass)) {
434 print
img_picto($langs->trans(
"Active"),
'tick');
439print
'<td class="center" width="100">';
440if (empty($dolibarr_main_db_pass) && empty($dolibarr_main_db_encrypted_pass)) {
441 $langs->load(
"errors");
442 print
img_warning($langs->trans(
"WarningPassIsEmpty"));
444 if (empty($dolibarr_main_db_encrypted_pass)) {
445 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=activate_encryptdbpassconf&token='.
newToken().
'">'.$langs->trans(
"Activate").
'</a>';
447 if (!empty($dolibarr_main_db_encrypted_pass)) {
448 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=disable_encryptdbpassconf&token='.
newToken().
'">'.$langs->trans(
"Disable").
'</a>';
459print
'<tr class="oddeven">';
460print
'<td colspan="3">'.$langs->trans(
"DisableForgetPasswordLinkOnLogonPage").
'</td>';
461print
'<td class="center" width="60">';
463 print
img_picto($langs->trans(
"Active"),
'tick');
467 print
'<td class="center" width="100">';
468 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=activate_MAIN_SECURITY_DISABLEFORGETPASSLINK&token='.
newToken().
'">'.$langs->trans(
"Activate").
'</a>';
472 print
'<td center="center" width="100">';
473 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=disable_MAIN_SECURITY_DISABLEFORGETPASSLINK&token='.
newToken().
'">'.$langs->trans(
"Disable").
'</a>';
487 if (function_exists(
'password_hash')) {
488 print $langs->trans(
"Note: The function password_hash exists on your PHP").
"<br>\n";
490 print $langs->trans(
"Note: The function password_hash does not exist on your PHP").
"<br>\n";
492 print
'MAIN_SECURITY_HASH_ALGO = '.getDolGlobalString(
'MAIN_SECURITY_HASH_ALGO').
"<br>\n";
493 print
'MAIN_SECURITY_SALT = '.getDolGlobalString(
'MAIN_SECURITY_SALT').
"<br>\n";
security_prepare_head()
Prepare array with list of tabs.
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.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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 dolibarr global constant string value.
encodedecode_dbpassconf($level=0)
Encode or decode database password in config file.
dol_encode($chain, $key='1')
Encode a string with base 64 algorithm + specific delta change.
dol_hash($chain, $type='0', $nosalt=0)
Returns a hash (non reversible encryption) of a string.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.