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) {
204 if (preg_match(
'/(modGeneratePass[a-z]+)\.class\.php$/i', $file, $reg)) {
206 $classname = $reg[1];
207 require_once $dir.
'/'.$file;
209 $obj =
new $classname($db, $conf, $langs, $user);
210 '@phan-var-force ModeleGenPassword $obj';
211 $arrayhandler[$obj->id] = $obj;
219print
'<div class="div-table-responsive-no-min">';
220print
'<table class="noborder centpercent">';
221print
'<tr class="liste_titre">';
222print
'<td colspan="2">'.$langs->trans(
"RuleForGeneratedPasswords").
'</td>';
223print
'<td>'.$langs->trans(
"Example").
'</td>';
224print
'<td class="center">'.$langs->trans(
"Activated").
'</td>';
229foreach ($arrayhandler as $key => $module) {
231 if (!empty($module->version) && $module->version ==
'development' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 2) {
234 if (!empty($module->version) && $module->version ==
'experimental' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 1) {
238 if ($module->isEnabled()) {
239 print
'<tr class="oddeven"><td>';
240 print
img_picto(
'', $module->picto,
'class="width25 size15x marginrightonly"').
' ';
243 print $module->getDescription().
'<br>';
244 print $langs->trans(
"MinLength").
': <span class="opacitymedium">'.$module->length.
'</span>';
248 print
'<td class="nowraponall">';
249 $tmp = $module->getExample();
250 if (preg_match(
'/^Error/', $tmp)) {
251 $langs->load(
"errors");
252 print
'<div class="error">'.$langs->trans($tmp).
'</div>';
253 } elseif ($tmp ==
'NotConfigured') {
254 print
'<span class="opacitymedium">'.$langs->trans($tmp).
'</span>';
256 print
'<span class="opacitymedium">'.$tmp.
'</span>';
260 print
'<td class="center">';
261 if ($conf->global->USER_PASSWORD_GENERATED == $key) {
263 print
img_picto($langs->trans(
"Enabled"),
'switch_on');
265 print
'<a href="'.$_SERVER[
'PHP_SELF'].
'?action=setgeneraterule&token='.
newToken().
'&value='.$key.
'">';
267 print
img_picto($langs->trans(
"Disabled"),
'switch_off');
270 print
"</td></tr>\n";
283 print
'<div class="div-table-responsive-no-min">';
284 print
'<table class="noborder centpercent">';
285 print
'<tr class="liste_titre">';
286 print
'<td colspan="2"> '.$langs->trans(
"PasswordPatternDesc").
'</td>';
290 print
'<tr class="oddeven">';
291 print
'<td>'.$langs->trans(
"MinLength").
"</td>";
292 print
'<td><input type="number" class="width50 right" value="'.$tabConf[0].
'" id="minlength" min="1"></td>';
296 print
'<tr class="oddeven">';
297 print
'<td>'.$langs->trans(
"NbMajMin").
"</td>";
298 print
'<td><input type="number" class="width50 right" value="'.$tabConf[1].
'" id="NbMajMin" min="0"></td>';
302 print
'<tr class="oddeven">';
303 print
'<td>'.$langs->trans(
"NbNumMin").
"</td>";
304 print
'<td><input type="number" class="width50 right" value="'.$tabConf[2].
'" id="NbNumMin" min="0"></td>';
308 print
'<tr class="oddeven">';
309 print
'<td>'.$langs->trans(
"NbSpeMin").
"</td>";
310 print
'<td><input type="number" class="width50 right" value="'.$tabConf[3].
'" id="NbSpeMin" min="0"></td>';
314 print
'<tr class="oddeven">';
315 print
'<td>'.$langs->trans(
"NbIteConsecutive").
"</td>";
316 print
'<td><input type="number" class="width50 right" value="'.$tabConf[4].
'" id="NbIteConsecutive" min="0"></td>';
320 print
'<tr class="oddeven">';
321 print
'<td>'.$langs->trans(
"NoAmbiCaracAutoGeneration").
"</td>";
322 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>';
327 print
'<div class="center">';
328 print
'<a class="button button-save" id="linkChangePattern">'.$langs->trans(
"Save").
'</a>';
333 print
'<script type="text/javascript">';
334 print
' function getStringArg(){';
335 print
' var pattern = "";';
336 print
' pattern += $("#minlenght").val() + ";";';
337 print
' pattern += $("#NbMajMin").val() + ";";';
338 print
' pattern += $("#NbNumMin").val() + ";";';
339 print
' pattern += $("#NbSpeMin").val() + ";";';
340 print
' pattern += $("#NbIteConsecutive").val() + ";";';
341 print
' pattern += $("#NoAmbiCaracAutoGeneration")[0].checked ? "1" : "0";';
342 print
' return pattern;';
345 print
' function valuePossible(){';
346 print
' var fields = ["#minlenght", "#NbMajMin", "#NbNumMin", "#NbSpeMin", "#NbIteConsecutive"];';
347 print
' for(var i = 0 ; i < fields.length ; i++){';
348 print
' if($(fields[i]).val() < $(fields[i]).attr("min")){';
349 print
' return false;';
353 print
' var length = parseInt($("#minlenght").val());';
354 print
' var length_mini = parseInt($("#NbMajMin").val()) + parseInt($("#NbNumMin").val()) + parseInt($("#NbSpeMin").val());';
355 print
' return length >= length_mini;';
358 print
' function generatelink(){';
359 print
' return "security.php?action=updatepattern&token='.newToken().
'&pattern="+getStringArg();';
362 print
' function valuePatternChange(){';
363 print
' console.log("valuePatternChange");';
364 print
' var lang_save = "'.$langs->trans(
"Save").
'";';
365 print
' var lang_error = "'.$langs->trans(
"Error").
'";';
366 print
' var lang_Disabled = "'.$langs->trans(
"Disabled").
'";';
367 print
' var lang_Activated = "'.$langs->trans(
"Activated").
'";';
368 print
' $("#textcheckbox").html($("#NoAmbiCaracAutoGeneration")[0].checked ? unescape(lang_Activated) : unescape(lang_Disabled));';
369 print
' if(valuePossible()){';
370 print
' $("#linkChangePattern").attr("href",generatelink()).text(lang_save);';
373 print
' $("#linkChangePattern").attr("href", null).text(lang_error);';
377 print
' $("#minlenght").change(function(){valuePatternChange();});';
378 print
' $("#NbMajMin").change(function(){valuePatternChange();});';
379 print
' $("#NbNumMin").change(function(){valuePatternChange();});';
380 print
' $("#NbSpeMin").change(function(){valuePatternChange();});';
381 print
' $("#NbIteConsecutive").change(function(){valuePatternChange();});';
382 print
' $("#NoAmbiCaracAutoGeneration").change(function(){valuePatternChange();});';
391print
'<form method="post" action="'.$_SERVER[
"PHP_SELF"].
'">';
392print
'<input type="hidden" name="token" value="'.newToken().
'">';
393print
'<input type="hidden" name="action" value="encrypt">';
395print
'<table class="noborder centpercent">';
396print
'<tr class="liste_titre">';
397print
'<td colspan="3">'.$langs->trans(
"Parameters").
'</td>';
398print
'<td class="center">'.$langs->trans(
"Activated").
'</td>';
399print
'<td class="center"></td>';
403print
'<tr class="oddeven">';
404print
'<td colspan="3">'.$langs->trans(
"DoNotStoreClearPassword").
'</td>';
405print
'<td class="center" width="60">';
407 print
img_picto($langs->trans(
"Active"),
'tick');
411 print
'<td class="center" width="100">';
412 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=activate_encrypt&token='.
newToken().
'">'.$langs->trans(
"Activate").
'</a>';
415 print
'<td class="center" width="100">';
416 if ($allow_disable_encryption) {
419 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=disable_encrypt&token='.
newToken().
'">'.$langs->trans(
"Disable").
'</a>';
421 print
'<span class="opacitymedium">'.$langs->trans(
"Always").
'</span>';
431print
'<tr class="oddeven">';
432print
'<td colspan="3">'.$langs->trans(
"MainDbPasswordFileConfEncrypted").
'</td>';
433print
'<td align="center" width="60">';
434if (preg_match(
'/crypted:/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass)) {
435 print
img_picto($langs->trans(
"Active"),
'tick');
440print
'<td class="center" width="100">';
441if (empty($dolibarr_main_db_pass) && empty($dolibarr_main_db_encrypted_pass)) {
442 $langs->load(
"errors");
443 print
img_warning($langs->trans(
"WarningPassIsEmpty"));
445 if (empty($dolibarr_main_db_encrypted_pass)) {
446 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=activate_encryptdbpassconf&token='.
newToken().
'">'.$langs->trans(
"Activate").
'</a>';
448 if (!empty($dolibarr_main_db_encrypted_pass)) {
449 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=disable_encryptdbpassconf&token='.
newToken().
'">'.$langs->trans(
"Disable").
'</a>';
460print
'<tr class="oddeven">';
461print
'<td colspan="3">'.$langs->trans(
"DisableForgetPasswordLinkOnLogonPage").
'</td>';
462print
'<td class="center" width="60">';
464 print
img_picto($langs->trans(
"Active"),
'tick');
468 print
'<td class="center" width="100">';
469 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=activate_MAIN_SECURITY_DISABLEFORGETPASSLINK&token='.
newToken().
'">'.$langs->trans(
"Activate").
'</a>';
473 print
'<td center="center" width="100">';
474 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=disable_MAIN_SECURITY_DISABLEFORGETPASSLINK&token='.
newToken().
'">'.$langs->trans(
"Disable").
'</a>';
488 if (function_exists(
'password_hash')) {
489 print $langs->trans(
"Note: The function password_hash exists on your PHP").
"<br>\n";
491 print $langs->trans(
"Note: The function password_hash does not exist on your PHP").
"<br>\n";
493 print
'MAIN_SECURITY_HASH_ALGO = '.getDolGlobalString(
'MAIN_SECURITY_HASH_ALGO').
"<br>\n";
494 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($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
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.
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.