29require
'../main.inc.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
42$action =
GETPOST(
'action',
'aZ09');
45$langs->loadLangs(array(
"users",
"admin",
"other"));
52$allow_disable_encryption =
false;
59if ($action ==
'setgeneraterule') {
65if ($action ==
'activate_encrypt') {
76 $sql =
"SELECT u.rowid, u.pass, u.pass_crypted";
77 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
78 $sql .=
" WHERE u.pass IS NOT NULL AND LENGTH(u.pass) < 32";
80 $resql =
$db->query($sql);
82 $numrows =
$db->num_rows($resql);
84 while ($i < $numrows) {
85 $obj =
$db->fetch_object($resql);
87 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"user";
88 $sql .=
" SET pass_crypted = '".dol_hash($obj->pass).
"', pass = NULL";
89 $sql .=
" WHERE rowid=".((int) $obj->rowid);
92 $resql2 =
$db->query($sql);
114} elseif ($action ==
'disable_encrypt') {
117 if ($allow_disable_encryption) {
123if ($action ==
'activate_encryptdbpassconf') {
130 header(
"Location: security.php");
135} elseif ($action ==
'disable_encryptdbpassconf') {
142 header(
"Location: security.php");
146 setEventMessages($langs->trans(
'InstrucToClearPass', $langs->transnoentitiesnoconv(
"DatabasePassword")),
null,
'warnings');
150if ($action ==
'activate_MAIN_SECURITY_DISABLEFORGETPASSLINK') {
152} elseif ($action ==
'disable_MAIN_SECURITY_DISABLEFORGETPASSLINK') {
156if ($action ==
'updatepattern') {
157 $pattern =
GETPOST(
"pattern",
"alpha");
158 $explodePattern = explode(
';', $pattern);
160 $patternInError =
false;
161 if ((
int) $explodePattern[0] < 1 || (
int) $explodePattern[4] < 0) {
162 $patternInError =
true;
165 if ((
int) $explodePattern[0] < (
int) $explodePattern[1] + (
int) $explodePattern[2] + (
int) $explodePattern[3]) {
166 $patternInError =
true;
169 if (!$patternInError) {
172 header(
"Location: security.php");
185$wikihelp =
'EN:Setup_Security|FR:Paramétrage_Sécurité|ES:Configuración_Seguridad';
186llxHeader(
'', $langs->trans(
"Passwords"), $wikihelp,
'', 0, 0,
'',
'',
'',
'mod-admin page-security');
190print
'<span class="opacitymedium">'.$langs->trans(
"GeneratedPasswordDesc").
"</span><br>\n";
201print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
202print
'<input type="hidden" name="token" value="'.newToken().
'">';
203print
'<input type="hidden" name="action" value="update">';
204print
'<input type="hidden" name="constname" value="USER_PASSWORD_GENERATED">';
205print
'<input type="hidden" name="consttype" value="yesno">';
208$dir =
"../core/modules/security/generate";
210$handle = opendir($dir);
212$arrayhandler = array();
213if (is_resource($handle)) {
214 while (($file = readdir($handle)) !==
false) {
216 if (preg_match(
'/(modGeneratePass[a-z]+)\.class\.php$/i', $file, $reg)) {
218 $classname = $reg[1];
219 require_once $dir.
'/'.$file;
221 $obj =
new $classname(
$db,
$conf, $langs, $user);
222 '@phan-var-force ModeleGenPassword $obj';
223 $arrayhandler[$obj->id] = $obj;
231print
'<div class="div-table-responsive-no-min">';
232print
'<table class="noborder centpercent">';
233print
'<tr class="liste_titre">';
234print
'<td colspan="2">'.$langs->trans(
"RuleForGeneratedPasswords").
'</td>';
235print
'<td>'.$langs->trans(
"Example").
'</td>';
236print
'<td class="center">'.$langs->trans(
"Activated").
'</td>';
241foreach ($arrayhandler as $key => $module) {
243 if (!empty($module->version) && $module->version ==
'development' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 2) {
246 if (!empty($module->version) && $module->version ==
'experimental' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 1) {
250 if ($module->isEnabled()) {
251 print
'<tr class="oddeven"><td>';
252 print
img_picto(
'', $module->picto,
'class="width25 size15x marginrightonly"').
' ';
253 print
'<div class="refid inline-block">'.ucfirst($key).
'</span>';
255 print $module->getDescription().
'<br>';
256 print $langs->trans(
"MinLength").
': <span class="opacitymedium">'.$module->length.
'</span>';
260 print
'<td class="nowraponall">';
261 $tmp = $module->getExample();
262 if (preg_match(
'/^Error/', $tmp)) {
263 $langs->load(
"errors");
264 print
'<div class="error">'.$langs->trans($tmp).
'</div>';
265 } elseif ($tmp ==
'NotConfigured') {
266 print
'<span class="opacitymedium">'.$langs->trans($tmp).
'</span>';
268 print
'<span class="opacitymedium">'.$tmp.
'</span>';
272 print
'<td class="center">';
275 print
img_picto($langs->trans(
"Enabled"),
'switch_on');
277 print
'<a href="'.$_SERVER[
'PHP_SELF'].
'?action=setgeneraterule&token='.newToken().
'&value='.$key.
'">';
279 print
img_picto($langs->trans(
"Disabled"),
'switch_off');
282 print
"</td></tr>\n";
295 print
'<div class="div-table-responsive-no-min">';
296 print
'<table class="noborder centpercent">';
297 print
'<tr class="liste_titre">';
298 print
'<td colspan="2"> '.$langs->trans(
"PasswordPatternDesc").
'</td>';
302 print
'<tr class="oddeven">';
303 print
'<td>'.$langs->trans(
"MinLength").
"</td>";
304 print
'<td><input type="number" class="width50 right" value="'.$tabConf[0].
'" id="minlength" min="1"></td>';
308 print
'<tr class="oddeven">';
309 print
'<td>'.$langs->trans(
"NbMajMin").
"</td>";
310 print
'<td><input type="number" class="width50 right" value="'.$tabConf[1].
'" id="NbMajMin" min="0"></td>';
314 print
'<tr class="oddeven">';
315 print
'<td>'.$langs->trans(
"NbNumMin").
"</td>";
316 print
'<td><input type="number" class="width50 right" value="'.$tabConf[2].
'" id="NbNumMin" min="0"></td>';
320 print
'<tr class="oddeven">';
321 print
'<td>'.$langs->trans(
"NbSpeMin").
"</td>";
322 print
'<td><input type="number" class="width50 right" value="'.$tabConf[3].
'" id="NbSpeMin" min="0"></td>';
326 print
'<tr class="oddeven">';
327 print
'<td>'.$langs->trans(
"NbIteConsecutive").
"</td>";
328 print
'<td><input type="number" class="width50 right" value="'.$tabConf[4].
'" id="NbIteConsecutive" min="0"></td>';
332 print
'<tr class="oddeven">';
333 print
'<td>'.$langs->trans(
"NoAmbiCaracAutoGeneration").
"</td>";
334 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>';
339 print
'<div class="center">';
340 print
'<a class="button button-save" id="linkChangePattern">'.$langs->trans(
"Save").
'</a>';
345 print
'<script type="text/javascript">';
346 print
' function getStringArg(){';
347 print
' var pattern = "";';
348 print
' pattern += $("#minlength").val() + ";";';
349 print
' pattern += $("#NbMajMin").val() + ";";';
350 print
' pattern += $("#NbNumMin").val() + ";";';
351 print
' pattern += $("#NbSpeMin").val() + ";";';
352 print
' pattern += $("#NbIteConsecutive").val() + ";";';
353 print
' pattern += $("#NoAmbiCaracAutoGeneration")[0].checked ? "1" : "0";';
354 print
' return pattern;';
357 print
' function valuePossible(){';
358 print
' var fields = ["#minlength", "#NbMajMin", "#NbNumMin", "#NbSpeMin", "#NbIteConsecutive"];';
359 print
' for(var i = 0 ; i < fields.length ; i++){';
360 print
' if($(fields[i]).val() < $(fields[i]).attr("min")){';
361 print
' return false;';
365 print
' var length = parseInt($("#minlength").val());';
366 print
' var length_mini = parseInt($("#NbMajMin").val()) + parseInt($("#NbNumMin").val()) + parseInt($("#NbSpeMin").val());';
367 print
' return length >= length_mini;';
370 print
' function generatelink(){';
371 print
' return "security.php?action=updatepattern&token='.newToken().
'&pattern="+getStringArg();';
374 print
' function valuePatternChange(){';
375 print
' console.log("valuePatternChange");';
376 print
' var lang_save = "'.$langs->trans(
"Save").
'";';
377 print
' var lang_error = "'.$langs->trans(
"Error").
'";';
378 print
' var lang_Disabled = "'.$langs->trans(
"Disabled").
'";';
379 print
' var lang_Activated = "'.$langs->trans(
"Activated").
'";';
380 print
' $("#textcheckbox").html($("#NoAmbiCaracAutoGeneration")[0].checked ? unescape(lang_Activated) : unescape(lang_Disabled));';
381 print
' if(valuePossible()){';
382 print
' $("#linkChangePattern").attr("href",generatelink()).text(lang_save);';
385 print
' $("#linkChangePattern").attr("href", null).text(lang_error);';
389 print
' $("#minlength").change(function(){valuePatternChange();});';
390 print
' $("#NbMajMin").change(function(){valuePatternChange();});';
391 print
' $("#NbNumMin").change(function(){valuePatternChange();});';
392 print
' $("#NbSpeMin").change(function(){valuePatternChange();});';
393 print
' $("#NbIteConsecutive").change(function(){valuePatternChange();});';
394 print
' $("#NoAmbiCaracAutoGeneration").change(function(){valuePatternChange();});';
403print
'<form method="post" action="'.dolBuildUrl($_SERVER[
"PHP_SELF"]).
'">';
404print
'<input type="hidden" name="token" value="'.newToken().
'">';
405print
'<input type="hidden" name="action" value="encrypt">';
407print
'<table class="noborder centpercent">';
408print
'<tr class="liste_titre">';
409print
'<td colspan="3">'.$langs->trans(
"Parameters").
'</td>';
410print
'<td class="center">'.$langs->trans(
"Activated").
'</td>';
411print
'<td class="center"></td>';
415print
'<tr class="oddeven">';
416print
'<td colspan="3">'.$langs->trans(
"DoNotStoreClearPassword").
'</td>';
417print
'<td class="center" width="60">';
419 print
img_picto($langs->trans(
"Active"),
'tick');
423 print
'<td class="center" width="100">';
424 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=activate_encrypt&token='.newToken().
'">'.$langs->trans(
"Activate").
'</a>';
427 print
'<td class="center" width="100">';
428 if ($allow_disable_encryption) {
431 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=disable_encrypt&token='.newToken().
'">'.$langs->trans(
"Disable").
'</a>';
433 print
'<span class="opacitymedium">'.$langs->trans(
"Always").
'</span>';
443print
'<tr class="oddeven">';
444print
'<td colspan="3">'.$langs->trans(
"MainDbPasswordFileConfEncrypted").
'</td>';
445print
'<td align="center" width="60">';
446if (preg_match(
'/(crypted|dolcrypt):/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass)) {
447 print
img_picto($langs->trans(
"Active"),
'tick');
452print
'<td class="center" width="100">';
453if (empty($dolibarr_main_db_pass) && empty($dolibarr_main_db_encrypted_pass)) {
454 $langs->load(
"errors");
455 print
img_warning($langs->trans(
"WarningPassIsEmpty"));
457 if (empty($dolibarr_main_db_encrypted_pass)) {
458 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=activate_encryptdbpassconf&token='.newToken().
'">'.$langs->trans(
"Activate").
'</a>';
460 if (!empty($dolibarr_main_db_encrypted_pass)) {
461 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=disable_encryptdbpassconf&token='.newToken().
'">'.$langs->trans(
"Disable").
'</a>';
472print
'<tr class="oddeven">';
473print
'<td colspan="3">'.$langs->trans(
"DisableForgetPasswordLinkOnLogonPage").
'</td>';
474print
'<td class="center" width="60">';
476 print
img_picto($langs->trans(
"Active"),
'tick');
480 print
'<td class="center" width="100">';
481 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=activate_MAIN_SECURITY_DISABLEFORGETPASSLINK&token='.newToken().
'">'.$langs->trans(
"Activate").
'</a>';
485 print
'<td class="center" width="100">';
486 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=disable_MAIN_SECURITY_DISABLEFORGETPASSLINK&token='.newToken().
'">'.$langs->trans(
"Disable").
'</a>';
500 if (function_exists(
'password_hash')) {
501 print $langs->trans(
"Note: The function password_hash exists on your PHP").
"<br>\n";
503 print $langs->trans(
"Note: The function password_hash does not exist on your PHP").
"<br>\n";
505 print
'MAIN_SECURITY_HASH_ALGO = '.getDolGlobalString(
'MAIN_SECURITY_HASH_ALGO').
"<br>\n";
506 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.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
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, $morecssdiv='')
Show tabs of a record.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
encodedecode_dbpassconf($level=0)
Encode or decode database password in config file.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.
dolEncrypt($chain, $key='', $ciphering='', $forceseed='', $obfuscationmode='dolcrypt')
Encode a string with a symmetric encryption.