27 require
'../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
31 $action =
GETPOST(
'action',
'aZ09');
34 $langs->loadLangs(array(
"users",
"admin",
"other"));
41 $allow_disable_encryption =
true;
48 if ($action ==
'setgeneraterule') {
49 if (!
dolibarr_set_const($db,
'USER_PASSWORD_GENERATED',
GETPOST(
"value",
"alphanohtml"),
'chaine', 0,
'', $conf->entity)) {
54 if ($action ==
'activate_encrypt') {
63 dolibarr_set_const($db,
"DATABASE_PWD_ENCRYPTED",
"1",
'chaine', 0,
'', $entityforall);
65 $sql =
"SELECT u.rowid, u.pass, u.pass_crypted";
66 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
67 $sql .=
" WHERE u.pass IS NOT NULL AND LENGTH(u.pass) < 32";
71 $numrows = $db->num_rows(
$resql);
73 while ($i < $numrows) {
74 $obj = $db->fetch_object(
$resql);
76 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"user";
77 $sql .=
" SET pass_crypted = '".dol_hash($obj->pass).
"', pass = NULL";
78 $sql .=
" WHERE rowid=".((int) $obj->rowid);
81 $resql2 = $db->query($sql);
103 } elseif ($action ==
'disable_encrypt') {
106 if ($allow_disable_encryption) {
111 if ($action ==
'activate_encryptdbpassconf') {
118 header(
"Location: security.php");
123 } elseif ($action ==
'disable_encryptdbpassconf') {
130 header(
"Location: security.php");
133 setEventMessages($langs->trans(
'InstrucToClearPass', $dolibarr_main_db_pass),
null,
'warnings');
137 if ($action ==
'activate_MAIN_SECURITY_DISABLEFORGETPASSLINK') {
138 dolibarr_set_const($db,
"MAIN_SECURITY_DISABLEFORGETPASSLINK",
'1',
'chaine', 0,
'', $conf->entity);
139 } elseif ($action ==
'disable_MAIN_SECURITY_DISABLEFORGETPASSLINK') {
143 if ($action ==
'updatepattern') {
144 $pattern =
GETPOST(
"pattern",
"alpha");
145 $explodePattern = explode(
';', $pattern);
147 $patternInError =
false;
148 if ($explodePattern[0] < 1 || $explodePattern[4] < 0) {
149 $patternInError =
true;
152 if ($explodePattern[0] < $explodePattern[1] + $explodePattern[2] + $explodePattern[3]) {
153 $patternInError =
true;
156 if (!$patternInError) {
157 dolibarr_set_const($db,
"USER_PASSWORD_PATTERN", $pattern,
'chaine', 0,
'', $conf->entity);
159 header(
"Location: security.php");
172 $wikihelp =
'EN:Setup_Security|FR:Paramétrage_Sécurité|ES:Configuración_Seguridad';
177 print
'<span class="opacitymedium">'.$langs->trans(
"GeneratedPasswordDesc").
"</span><br>\n";
188 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
189 print
'<input type="hidden" name="token" value="'.newToken().
'">';
190 print
'<input type="hidden" name="action" value="update">';
191 print
'<input type="hidden" name="constname" value="USER_PASSWORD_GENERATED">';
192 print
'<input type="hidden" name="consttype" value="yesno">';
195 $dir =
"../core/modules/security/generate";
197 $handle = opendir($dir);
199 if (is_resource($handle)) {
200 while (($file = readdir($handle)) !==
false) {
201 if (preg_match(
'/(modGeneratePass[a-z]+)\.class\.php$/i', $file, $reg)) {
203 $classname = $reg[1];
204 require_once $dir.
'/'.$file;
206 $obj =
new $classname($db, $conf, $langs, $user);
207 $arrayhandler[$obj->id] = $obj;
213 asort($arrayhandler);
215 print
'<div class="div-table-responsive-no-min">';
216 print
'<table class="noborder centpercent">';
217 print
'<tr class="liste_titre">';
218 print
'<td colspan="2">'.$langs->trans(
"RuleForGeneratedPasswords").
'</td>';
219 print
'<td>'.$langs->trans(
"Example").
'</td>';
220 print
'<td class="center">'.$langs->trans(
"Activated").
'</td>';
225 foreach ($arrayhandler as $key => $module) {
227 if (!empty($module->version) && $module->version ==
'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
230 if (!empty($module->version) && $module->version ==
'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
234 if ($module->isEnabled()) {
235 print
'<tr class="oddeven"><td>';
236 print
img_picto(
'', $module->picto,
'class="width25 size15x"').
' ';
239 print $module->getDescription().
'<br>';
240 print $langs->trans(
"MinLength").
': <span class="opacitymedium">'.$module->length.
'</span>';
244 print
'<td class="nowraponall">';
245 $tmp = $module->getExample();
246 if (preg_match(
'/^Error/', $tmp)) {
247 $langs->load(
"errors");
248 print
'<div class="error">'.$langs->trans($tmp).
'</div>';
249 } elseif ($tmp ==
'NotConfigured') {
250 print
'<span class="opacitymedium">'.$langs->trans($tmp).
'</span>';
252 print
'<span class="opacitymedium">'.$tmp.
'</span>';
256 print
'<td class="center">';
257 if ($conf->global->USER_PASSWORD_GENERATED == $key) {
259 print
img_picto($langs->trans(
"Enabled"),
'switch_on');
261 print
'<a href="'.$_SERVER[
'PHP_SELF'].
'?action=setgeneraterule&token='.
newToken().
'&value='.$key.
'">';
263 print
img_picto($langs->trans(
"Disabled"),
'switch_off');
266 print
"</td></tr>\n";
276 if ($conf->global->USER_PASSWORD_GENERATED ==
"Perso") {
279 print
'<div class="div-table-responsive-no-min">';
280 print
'<table class="noborder centpercent">';
281 print
'<tr class="liste_titre">';
282 print
'<td colspan="2"> '.$langs->trans(
"PasswordPatternDesc").
'</td>';
286 print
'<tr class="oddeven">';
287 print
'<td>'.$langs->trans(
"MinLength").
"</td>";
288 print
'<td><input type="number" value="'.$tabConf[0].
'" id="minlenght" min="1"></td>';
292 print
'<tr class="oddeven">';
293 print
'<td>'.$langs->trans(
"NbMajMin").
"</td>";
294 print
'<td><input type="number" value="'.$tabConf[1].
'" id="NbMajMin" min="0"></td>';
298 print
'<tr class="oddeven">';
299 print
'<td>'.$langs->trans(
"NbNumMin").
"</td>";
300 print
'<td><input type="number" value="'.$tabConf[2].
'" id="NbNumMin" min="0"></td>';
304 print
'<tr class="oddeven">';
305 print
'<td>'.$langs->trans(
"NbSpeMin").
"</td>";
306 print
'<td><input type="number" value="'.$tabConf[3].
'" id="NbSpeMin" min="0"></td>';
310 print
'<tr class="oddeven">';
311 print
'<td>'.$langs->trans(
"NbIteConsecutive").
"</td>";
312 print
'<td><input type="number" value="'.$tabConf[4].
'" id="NbIteConsecutive" min="0"></td>';
316 print
'<tr class="oddeven">';
317 print
'<td>'.$langs->trans(
"NoAmbiCaracAutoGeneration").
"</td>";
318 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>';
323 print
'<div class="center">';
324 print
'<a class="button button-save" id="linkChangePattern">'.$langs->trans(
"Save").
'</a>';
329 print
'<script type="text/javascript">';
330 print
' function getStringArg(){';
331 print
' var pattern = "";';
332 print
' pattern += $("#minlenght").val() + ";";';
333 print
' pattern += $("#NbMajMin").val() + ";";';
334 print
' pattern += $("#NbNumMin").val() + ";";';
335 print
' pattern += $("#NbSpeMin").val() + ";";';
336 print
' pattern += $("#NbIteConsecutive").val() + ";";';
337 print
' pattern += $("#NoAmbiCaracAutoGeneration")[0].checked ? "1" : "0";';
338 print
' return pattern;';
341 print
' function valuePossible(){';
342 print
' var fields = ["#minlenght", "#NbMajMin", "#NbNumMin", "#NbSpeMin", "#NbIteConsecutive"];';
343 print
' for(var i = 0 ; i < fields.length ; i++){';
344 print
' if($(fields[i]).val() < $(fields[i]).attr("min")){';
345 print
' return false;';
349 print
' var length = parseInt($("#minlenght").val());';
350 print
' var length_mini = parseInt($("#NbMajMin").val()) + parseInt($("#NbNumMin").val()) + parseInt($("#NbSpeMin").val());';
351 print
' return length >= length_mini;';
354 print
' function generatelink(){';
355 print
' return "security.php?action=updatepattern&token='.newToken().
'&pattern="+getStringArg();';
358 print
' function valuePatternChange(){';
359 print
' console.log("valuePatternChange");';
360 print
' var lang_save = "'.$langs->trans(
"Save").
'";';
361 print
' var lang_error = "'.$langs->trans(
"Error").
'";';
362 print
' var lang_Disabled = "'.$langs->trans(
"Disabled").
'";';
363 print
' var lang_Activated = "'.$langs->trans(
"Activated").
'";';
364 print
' $("#textcheckbox").html($("#NoAmbiCaracAutoGeneration")[0].checked ? unescape(lang_Activated) : unescape(lang_Disabled));';
365 print
' if(valuePossible()){';
366 print
' $("#linkChangePattern").attr("href",generatelink()).text(lang_save);';
369 print
' $("#linkChangePattern").attr("href", null).text(lang_error);';
373 print
' $("#minlenght").change(function(){valuePatternChange();});';
374 print
' $("#NbMajMin").change(function(){valuePatternChange();});';
375 print
' $("#NbNumMin").change(function(){valuePatternChange();});';
376 print
' $("#NbSpeMin").change(function(){valuePatternChange();});';
377 print
' $("#NbIteConsecutive").change(function(){valuePatternChange();});';
378 print
' $("#NoAmbiCaracAutoGeneration").change(function(){valuePatternChange();});';
387 print
'<form method="post" action="'.$_SERVER[
"PHP_SELF"].
'">';
388 print
'<input type="hidden" name="token" value="'.newToken().
'">';
389 print
'<input type="hidden" name="action" value="encrypt">';
391 print
'<table class="noborder centpercent">';
392 print
'<tr class="liste_titre">';
393 print
'<td colspan="3">'.$langs->trans(
"Parameters").
'</td>';
394 print
'<td class="center">'.$langs->trans(
"Activated").
'</td>';
395 print
'<td class="center"></td>';
399 print
'<tr class="oddeven">';
400 print
'<td colspan="3">'.$langs->trans(
"DoNotStoreClearPassword").
'</td>';
401 print
'<td class="center" width="60">';
403 print
img_picto($langs->trans(
"Active"),
'tick');
407 print
'<td class="center" width="100">';
408 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>';
430 print
'<tr class="oddeven">';
431 print
'<td colspan="3">'.$langs->trans(
"MainDbPasswordFileConfEncrypted").
'</td>';
432 print
'<td align="center" width="60">';
433 if (preg_match(
'/crypted:/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass)) {
434 print
img_picto($langs->trans(
"Active"),
'tick');
439 print
'<td class="center" width="100">';
440 if (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>';
459 print
'<tr class="oddeven">';
460 print
'<td colspan="3">'.$langs->trans(
"DisableForgetPasswordLinkOnLogonPage").
'</td>';
461 print
'<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>';
486 if (
GETPOST(
'info',
'int') > 0) {
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 exists 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($actionsave) if(!isset($conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY)) $wikihelp
View.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("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->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) 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')
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.