29require
'../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
33$action =
GETPOST(
'action',
'aZ09');
46$langs->loadLangs(array(
"users",
"admin",
"other"));
53$allow_disable_encryption =
false;
60if ($action ==
'setgeneraterule') {
66if ($action ==
'activate_encrypt') {
75 dolibarr_set_const($db,
"DATABASE_PWD_ENCRYPTED",
"1",
'chaine', 0,
'', $entityforall);
77 $sql =
"SELECT u.rowid, u.pass, u.pass_crypted";
78 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
79 $sql .=
" WHERE u.pass IS NOT NULL AND LENGTH(u.pass) < 32";
81 $resql = $db->query($sql);
83 $numrows = $db->num_rows($resql);
85 while ($i < $numrows) {
86 $obj = $db->fetch_object($resql);
88 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"user";
89 $sql .=
" SET pass_crypted = '".dol_hash($obj->pass).
"', pass = NULL";
90 $sql .=
" WHERE rowid=".((int) $obj->rowid);
93 $resql2 = $db->query($sql);
115} elseif ($action ==
'disable_encrypt') {
118 if ($allow_disable_encryption) {
124if ($action ==
'activate_encryptdbpassconf') {
131 header(
"Location: security.php");
136} elseif ($action ==
'disable_encryptdbpassconf') {
143 header(
"Location: security.php");
147 setEventMessages($langs->trans(
'InstrucToClearPass', $langs->transnoentitiesnoconv(
"DatabasePassword")),
null,
'warnings');
151if ($action ==
'activate_MAIN_SECURITY_DISABLEFORGETPASSLINK') {
153} elseif ($action ==
'disable_MAIN_SECURITY_DISABLEFORGETPASSLINK') {
157if ($action ==
'updatepattern') {
158 $pattern =
GETPOST(
"pattern",
"alpha");
159 $explodePattern = explode(
';', $pattern);
161 $patternInError =
false;
162 if ((
int) $explodePattern[0] < 1 || (
int) $explodePattern[4] < 0) {
163 $patternInError =
true;
166 if ((
int) $explodePattern[0] < (
int) $explodePattern[1] + (
int) $explodePattern[2] + (
int) $explodePattern[3]) {
167 $patternInError =
true;
170 if (!$patternInError) {
173 header(
"Location: security.php");
184$form =
new Form($db);
186$wikihelp =
'EN:Setup_Security|FR:Paramétrage_Sécurité|ES:Configuración_Seguridad';
187llxHeader(
'', $langs->trans(
"Passwords"), $wikihelp,
'', 0, 0,
'',
'',
'',
'mod-admin page-security');
191print
'<span class="opacitymedium">'.$langs->trans(
"GeneratedPasswordDesc").
"</span><br>\n";
202print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
203print
'<input type="hidden" name="token" value="'.newToken().
'">';
204print
'<input type="hidden" name="action" value="update">';
205print
'<input type="hidden" name="constname" value="USER_PASSWORD_GENERATED">';
206print
'<input type="hidden" name="consttype" value="yesno">';
209$dir =
"../core/modules/security/generate";
211$handle = opendir($dir);
213$arrayhandler = array();
214if (is_resource($handle)) {
215 while (($file = readdir($handle)) !==
false) {
217 if (preg_match(
'/(modGeneratePass[a-z]+)\.class\.php$/i', $file, $reg)) {
219 $classname = $reg[1];
220 require_once $dir.
'/'.$file;
222 $obj =
new $classname($db,
$conf, $langs, $user);
223 '@phan-var-force ModeleGenPassword $obj';
224 $arrayhandler[$obj->id] = $obj;
232print
'<div class="div-table-responsive-no-min">';
233print
'<table class="noborder centpercent">';
234print
'<tr class="liste_titre">';
235print
'<td colspan="2">'.$langs->trans(
"RuleForGeneratedPasswords").
'</td>';
236print
'<td>'.$langs->trans(
"Example").
'</td>';
237print
'<td class="center">'.$langs->trans(
"Activated").
'</td>';
242foreach ($arrayhandler as $key => $module) {
244 if (!empty($module->version) && $module->version ==
'development' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 2) {
247 if (!empty($module->version) && $module->version ==
'experimental' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 1) {
251 if ($module->isEnabled()) {
252 print
'<tr class="oddeven"><td>';
253 print
img_picto(
'', $module->picto,
'class="width25 size15x marginrightonly"').
' ';
256 print $module->getDescription().
'<br>';
257 print $langs->trans(
"MinLength").
': <span class="opacitymedium">'.$module->length.
'</span>';
261 print
'<td class="nowraponall">';
262 $tmp = $module->getExample();
263 if (preg_match(
'/^Error/', $tmp)) {
264 $langs->load(
"errors");
265 print
'<div class="error">'.$langs->trans($tmp).
'</div>';
266 } elseif ($tmp ==
'NotConfigured') {
267 print
'<span class="opacitymedium">'.$langs->trans($tmp).
'</span>';
269 print
'<span class="opacitymedium">'.$tmp.
'</span>';
273 print
'<td class="center">';
274 if (
$conf->global->USER_PASSWORD_GENERATED == $key) {
276 print
img_picto($langs->trans(
"Enabled"),
'switch_on');
278 print
'<a href="'.$_SERVER[
'PHP_SELF'].
'?action=setgeneraterule&token='.
newToken().
'&value='.$key.
'">';
280 print
img_picto($langs->trans(
"Disabled"),
'switch_off');
283 print
"</td></tr>\n";
296 print
'<div class="div-table-responsive-no-min">';
297 print
'<table class="noborder centpercent">';
298 print
'<tr class="liste_titre">';
299 print
'<td colspan="2"> '.$langs->trans(
"PasswordPatternDesc").
'</td>';
303 print
'<tr class="oddeven">';
304 print
'<td>'.$langs->trans(
"MinLength").
"</td>";
305 print
'<td><input type="number" class="width50 right" value="'.$tabConf[0].
'" id="minlength" min="1"></td>';
309 print
'<tr class="oddeven">';
310 print
'<td>'.$langs->trans(
"NbMajMin").
"</td>";
311 print
'<td><input type="number" class="width50 right" value="'.$tabConf[1].
'" id="NbMajMin" min="0"></td>';
315 print
'<tr class="oddeven">';
316 print
'<td>'.$langs->trans(
"NbNumMin").
"</td>";
317 print
'<td><input type="number" class="width50 right" value="'.$tabConf[2].
'" id="NbNumMin" min="0"></td>';
321 print
'<tr class="oddeven">';
322 print
'<td>'.$langs->trans(
"NbSpeMin").
"</td>";
323 print
'<td><input type="number" class="width50 right" value="'.$tabConf[3].
'" id="NbSpeMin" min="0"></td>';
327 print
'<tr class="oddeven">';
328 print
'<td>'.$langs->trans(
"NbIteConsecutive").
"</td>";
329 print
'<td><input type="number" class="width50 right" value="'.$tabConf[4].
'" id="NbIteConsecutive" min="0"></td>';
333 print
'<tr class="oddeven">';
334 print
'<td>'.$langs->trans(
"NoAmbiCaracAutoGeneration").
"</td>";
335 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>';
340 print
'<div class="center">';
341 print
'<a class="button button-save" id="linkChangePattern">'.$langs->trans(
"Save").
'</a>';
346 print
'<script type="text/javascript">';
347 print
' function getStringArg(){';
348 print
' var pattern = "";';
349 print
' pattern += $("#minlength").val() + ";";';
350 print
' pattern += $("#NbMajMin").val() + ";";';
351 print
' pattern += $("#NbNumMin").val() + ";";';
352 print
' pattern += $("#NbSpeMin").val() + ";";';
353 print
' pattern += $("#NbIteConsecutive").val() + ";";';
354 print
' pattern += $("#NoAmbiCaracAutoGeneration")[0].checked ? "1" : "0";';
355 print
' return pattern;';
358 print
' function valuePossible(){';
359 print
' var fields = ["#minlength", "#NbMajMin", "#NbNumMin", "#NbSpeMin", "#NbIteConsecutive"];';
360 print
' for(var i = 0 ; i < fields.length ; i++){';
361 print
' if($(fields[i]).val() < $(fields[i]).attr("min")){';
362 print
' return false;';
366 print
' var length = parseInt($("#minlength").val());';
367 print
' var length_mini = parseInt($("#NbMajMin").val()) + parseInt($("#NbNumMin").val()) + parseInt($("#NbSpeMin").val());';
368 print
' return length >= length_mini;';
371 print
' function generatelink(){';
372 print
' return "security.php?action=updatepattern&token='.newToken().
'&pattern="+getStringArg();';
375 print
' function valuePatternChange(){';
376 print
' console.log("valuePatternChange");';
377 print
' var lang_save = "'.$langs->trans(
"Save").
'";';
378 print
' var lang_error = "'.$langs->trans(
"Error").
'";';
379 print
' var lang_Disabled = "'.$langs->trans(
"Disabled").
'";';
380 print
' var lang_Activated = "'.$langs->trans(
"Activated").
'";';
381 print
' $("#textcheckbox").html($("#NoAmbiCaracAutoGeneration")[0].checked ? unescape(lang_Activated) : unescape(lang_Disabled));';
382 print
' if(valuePossible()){';
383 print
' $("#linkChangePattern").attr("href",generatelink()).text(lang_save);';
386 print
' $("#linkChangePattern").attr("href", null).text(lang_error);';
390 print
' $("#minlength").change(function(){valuePatternChange();});';
391 print
' $("#NbMajMin").change(function(){valuePatternChange();});';
392 print
' $("#NbNumMin").change(function(){valuePatternChange();});';
393 print
' $("#NbSpeMin").change(function(){valuePatternChange();});';
394 print
' $("#NbIteConsecutive").change(function(){valuePatternChange();});';
395 print
' $("#NoAmbiCaracAutoGeneration").change(function(){valuePatternChange();});';
404print
'<form method="post" action="'.$_SERVER[
"PHP_SELF"].
'">';
405print
'<input type="hidden" name="token" value="'.newToken().
'">';
406print
'<input type="hidden" name="action" value="encrypt">';
408print
'<table class="noborder centpercent">';
409print
'<tr class="liste_titre">';
410print
'<td colspan="3">'.$langs->trans(
"Parameters").
'</td>';
411print
'<td class="center">'.$langs->trans(
"Activated").
'</td>';
412print
'<td class="center"></td>';
416print
'<tr class="oddeven">';
417print
'<td colspan="3">'.$langs->trans(
"DoNotStoreClearPassword").
'</td>';
418print
'<td class="center" width="60">';
420 print
img_picto($langs->trans(
"Active"),
'tick');
424 print
'<td class="center" width="100">';
425 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=activate_encrypt&token='.
newToken().
'">'.$langs->trans(
"Activate").
'</a>';
428 print
'<td class="center" width="100">';
429 if ($allow_disable_encryption) {
432 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=disable_encrypt&token='.
newToken().
'">'.$langs->trans(
"Disable").
'</a>';
434 print
'<span class="opacitymedium">'.$langs->trans(
"Always").
'</span>';
444print
'<tr class="oddeven">';
445print
'<td colspan="3">'.$langs->trans(
"MainDbPasswordFileConfEncrypted").
'</td>';
446print
'<td align="center" width="60">';
447if (preg_match(
'/crypted:/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass)) {
448 print
img_picto($langs->trans(
"Active"),
'tick');
453print
'<td class="center" width="100">';
454if (empty($dolibarr_main_db_pass) && empty($dolibarr_main_db_encrypted_pass)) {
455 $langs->load(
"errors");
456 print
img_warning($langs->trans(
"WarningPassIsEmpty"));
458 if (empty($dolibarr_main_db_encrypted_pass)) {
459 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=activate_encryptdbpassconf&token='.
newToken().
'">'.$langs->trans(
"Activate").
'</a>';
461 if (!empty($dolibarr_main_db_encrypted_pass)) {
462 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=disable_encryptdbpassconf&token='.
newToken().
'">'.$langs->trans(
"Disable").
'</a>';
473print
'<tr class="oddeven">';
474print
'<td colspan="3">'.$langs->trans(
"DisableForgetPasswordLinkOnLogonPage").
'</td>';
475print
'<td class="center" width="60">';
477 print
img_picto($langs->trans(
"Active"),
'tick');
481 print
'<td class="center" width="100">';
482 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=activate_MAIN_SECURITY_DISABLEFORGETPASSLINK&token='.
newToken().
'">'.$langs->trans(
"Activate").
'</a>';
486 print
'<td center="center" width="100">';
487 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=disable_MAIN_SECURITY_DISABLEFORGETPASSLINK&token='.
newToken().
'">'.$langs->trans(
"Disable").
'</a>';
501 if (function_exists(
'password_hash')) {
502 print $langs->trans(
"Note: The function password_hash exists on your PHP").
"<br>\n";
504 print $langs->trans(
"Note: The function password_hash does not exist on your PHP").
"<br>\n";
506 print
'MAIN_SECURITY_HASH_ALGO = '.getDolGlobalString(
'MAIN_SECURITY_HASH_ALGO').
"<br>\n";
507 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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.