26 require
'../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
30 $action =
GETPOST(
'action',
'aZ09');
33 $langs->loadLangs(array(
"users",
"admin",
"other"));
38 $allow_disable_encryption =
true;
43 if ($action ==
'setgeneraterule')
45 if (!
dolibarr_set_const($db,
'USER_PASSWORD_GENERATED', $_GET[
"value"],
'chaine', 0,
'', $conf->entity))
49 header(
"Location: ".
$_SERVER[
"PHP_SELF"]);
54 if ($action ==
'activate_encrypt')
60 dolibarr_set_const($db,
"DATABASE_PWD_ENCRYPTED",
"1",
'chaine', 0,
'', $conf->entity);
62 $sql =
"SELECT u.rowid, u.pass, u.pass_crypted";
63 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
64 $sql .=
" WHERE u.pass IS NOT NULL AND LENGTH(u.pass) < 32";
69 $numrows = $db->num_rows(
$resql);
73 $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=".$obj->rowid;
81 $resql2 = $db->query($sql);
99 header(
"Location: security.php");
105 } elseif ($action ==
'disable_encrypt')
109 if ($allow_disable_encryption)
113 header(
"Location: security.php");
117 if ($action ==
'activate_encryptdbpassconf')
126 header(
"Location: security.php");
131 } elseif ($action ==
'disable_encryptdbpassconf')
140 header(
"Location: security.php");
143 setEventMessages($langs->trans(
'InstrucToClearPass', $dolibarr_main_db_pass), null,
'warnings');
147 if ($action ==
'activate_MAIN_SECURITY_DISABLEFORGETPASSLINK')
149 dolibarr_set_const($db,
"MAIN_SECURITY_DISABLEFORGETPASSLINK",
'1',
'chaine', 0,
'', $conf->entity);
150 header(
"Location: security.php");
152 } elseif ($action ==
'disable_MAIN_SECURITY_DISABLEFORGETPASSLINK')
155 header(
"Location: security.php");
159 if ($action ==
'updatepattern')
161 $pattern =
GETPOST(
"pattern",
"alpha");
162 $explodePattern = explode(
';', $pattern);
164 $patternInError =
false;
165 if ($explodePattern[0] < 1 || $explodePattern[4] < 0) {
166 $patternInError =
true;
169 if ($explodePattern[0] < $explodePattern[1] + $explodePattern[2] + $explodePattern[3]) {
170 $patternInError =
true;
173 if (!$patternInError) {
174 dolibarr_set_const($db,
"USER_PASSWORD_PATTERN", $pattern,
'chaine', 0,
'', $conf->entity);
176 header(
"Location: security.php");
187 $form =
new Form($db);
189 $wikihelp =
'EN:Setup_Security|FR:Paramétrage_Sécurité|ES:Configuración_Seguridad';
194 print '<span class="opacitymedium">'.$langs->trans(
"GeneratedPasswordDesc").
"</span><br>\n";
204 print '<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
205 print '<input type="hidden" name="token" value="'.newToken().
'">';
206 print '<input type="hidden" name="action" value="update">';
207 print '<input type="hidden" name="constname" value="USER_PASSWORD_GENERATED">';
208 print '<input type="hidden" name="consttype" value="yesno">';
211 $dir =
"../core/modules/security/generate";
213 $handle = opendir($dir);
215 if (is_resource($handle))
217 while (($file = readdir($handle)) !==
false)
219 if (preg_match(
'/(modGeneratePass[a-z]+)\.class\.php$/i', $file, $reg))
222 $classname = $reg[1];
223 require_once $dir.
'/'.$file;
225 $obj =
new $classname($db, $conf, $langs, $user);
226 $arrayhandler[$obj->id] = $obj;
232 asort($arrayhandler);
234 print '<table class="noborder centpercent">';
235 print '<tr class="liste_titre">';
236 print '<td colspan="2">'.$langs->trans(
"RuleForGeneratedPasswords").
'</td>';
237 print '<td>'.$langs->trans(
"Example").
'</td>';
238 print '<td class="center">'.$langs->trans(
"Activated").
'</td>';
241 foreach ($arrayhandler as $key => $module)
244 if ($module->version ==
'development' && $conf->global->MAIN_FEATURES_LEVEL < 2)
continue;
245 if ($module->version ==
'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1)
continue;
247 if ($module->isEnabled())
249 print '<tr class="oddeven"><td width="100">';
252 print $module->getDescription().
'<br>';
253 print $langs->trans(
"MinLength").
': '.$module->length;
257 print '<td class="nowrap">';
258 $tmp = $module->getExample();
259 if (preg_match(
'/^Error/', $tmp)) {
260 $langs->load(
"errors");
261 print '<div class="error">'.$langs->trans($tmp).
'</div>';
262 } elseif ($tmp ==
'NotConfigured')
print $langs->trans($tmp);
266 print '<td width="100" align="center">';
267 if ($conf->global->USER_PASSWORD_GENERATED == $key)
271 print '<a href="'.$_SERVER[
'PHP_SELF'].
'?action=setgeneraterule&token='.
newToken().
'&value='.$key.
'">'.$langs->trans(
"Activate").
'</a>';
273 print "</td></tr>\n";
281 if ($conf->global->USER_PASSWORD_GENERATED ==
"Perso") {
282 $tabConf = explode(
";", $conf->global->USER_PASSWORD_PATTERN);
284 print '<table class="noborder centpercent">';
285 print '<tr class="liste_titre">';
286 print '<td colspan="3"> '.$langs->trans(
"PasswordPatternDesc").
'</td>';
290 print '<tr class="oddeven">';
291 print '<td>'.$langs->trans(
"MinLength").
"</td>";
292 print '<td colspan="2"><input type="number" value="'.$tabConf[0].
'" id="minlenght" min="1"></td>';
296 print '<tr class="oddeven">';
297 print '<td>'.$langs->trans(
"NbMajMin").
"</td>";
298 print '<td colspan="2"><input type="number" value="'.$tabConf[1].
'" id="NbMajMin" min="0"></td>';
302 print '<tr class="oddeven">';
303 print '<td>'.$langs->trans(
"NbNumMin").
"</td>";
304 print '<td colspan="2"><input type="number" value="'.$tabConf[2].
'" id="NbNumMin" min="0"></td>';
308 print '<tr class="oddeven">';
309 print '<td>'.$langs->trans(
"NbSpeMin").
"</td>";
310 print '<td colspan="2"><input type="number" value="'.$tabConf[3].
'" id="NbSpeMin" min="0"></td>';
314 print '<tr class="oddeven">';
315 print '<td>'.$langs->trans(
"NbIteConsecutive").
"</td>";
316 print '<td colspan="2"><input type="number" value="'.$tabConf[4].
'" id="NbIteConsecutive" min="0"></td>';
320 print '<tr class="oddeven">';
321 print '<td>'.$langs->trans(
"NoAmbiCaracAutoGeneration").
"</td>";
322 print '<td colspan="2"><input type="checkbox" id="NoAmbiCaracAutoGeneration" '.($tabConf[5] ?
"checked" :
"").
' min="0"> <span id="textcheckbox">'.($tabConf[5] ? $langs->trans(
"Activated") : $langs->trans(
"Disabled")).
'</span></td>';
328 print
'<div class="center">';
329 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&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();});';
390 print
"<form method=\"post\" action=\"".$_SERVER[
"PHP_SELF"].
"\">";
391 print
'<input type="hidden" name="token" value="'.newToken().
'">';
392 print
"<input type=\"hidden\" name=\"action\" value=\"encrypt\">";
394 print
'<table class="noborder centpercent">';
395 print
'<tr class="liste_titre">';
396 print
'<td colspan="3">'.$langs->trans(
"Parameters").
'</td>';
397 print
'<td class="center">'.$langs->trans(
"Activated").
'</td>';
398 print
'<td class="center">'.$langs->trans(
"Action").
'</td>';
402 print
'<tr class="oddeven">';
403 print
'<td colspan="3">'.$langs->trans(
"DoNotStoreClearPassword").
'</td>';
404 print
'<td align="center" width="60">';
405 if (!empty($conf->global->DATABASE_PWD_ENCRYPTED))
407 print
img_picto($langs->trans(
"Active"),
'tick');
410 if (!$conf->global->DATABASE_PWD_ENCRYPTED)
412 print
'<td align="center" width="100">';
413 print
'<a href="security.php?action=activate_encrypt">'.$langs->trans(
"Activate").
'</a>';
418 if (!empty($conf->global->DATABASE_PWD_ENCRYPTED))
420 print
'<td align="center" width="100">';
421 if ($allow_disable_encryption)
425 print
'<a href="security.php?action=disable_encrypt">'.$langs->trans(
"Disable").
'</a>';
436 print
'<tr class="oddeven">';
437 print
'<td colspan="3">'.$langs->trans(
"MainDbPasswordFileConfEncrypted").
'</td>';
438 print
'<td align="center" width="60">';
439 if (preg_match(
'/crypted:/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass))
441 print
img_picto($langs->trans(
"Active"),
'tick');
446 print
'<td align="center" width="100">';
447 if (empty($dolibarr_main_db_pass) && empty($dolibarr_main_db_encrypted_pass))
449 $langs->load(
"errors");
450 print
img_warning($langs->trans(
"WarningPassIsEmpty"));
452 if (empty($dolibarr_main_db_encrypted_pass))
454 print
'<a href="security.php?action=activate_encryptdbpassconf">'.$langs->trans(
"Activate").
'</a>';
456 if (!empty($dolibarr_main_db_encrypted_pass))
458 print
'<a href="security.php?action=disable_encryptdbpassconf">'.$langs->trans(
"Disable").
'</a>';
469 print
'<tr class="oddeven">';
470 print
'<td colspan="3">'.$langs->trans(
"DisableForgetPasswordLinkOnLogonPage").
'</td>';
471 print
'<td align="center" width="60">';
472 if (!empty($conf->global->MAIN_SECURITY_DISABLEFORGETPASSLINK))
474 print
img_picto($langs->trans(
"Active"),
'tick');
477 if (empty($conf->global->MAIN_SECURITY_DISABLEFORGETPASSLINK))
479 print
'<td align="center" width="100">';
480 print
'<a href="security.php?action=activate_MAIN_SECURITY_DISABLEFORGETPASSLINK">'.$langs->trans(
"Activate").
'</a>';
483 if (!empty($conf->global->MAIN_SECURITY_DISABLEFORGETPASSLINK))
485 print
'<td align="center" width="100">';
486 print
'<a href="security.php?action=disable_MAIN_SECURITY_DISABLEFORGETPASSLINK">'.$langs->trans(
"Disable").
'</a>';
497 if (
GETPOST(
'info',
'int') > 0)
499 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 exists on your PHP").
"<br>\n";
505 print
'MAIN_SECURITY_HASH_ALGO = '.$conf->global->MAIN_SECURITY_HASH_ALGO.
"<br>\n";
506 print
'MAIN_SECURITY_SALT = '.$conf->global->MAIN_SECURITY_SALT.
"<br>\n";
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_hash($chain, $type= '0')
Returns a hash of a string.
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).
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save"&&empty($cancel)) $wikihelp
View.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
dolibarr_del_const($db, $name, $entity=1)
Effacement d'une constante dans la base de donnees.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_encode($chain, $key= '1')
Encode a string with base 64 algorithm + specific delta change.
if(!GETPOST('transkey', 'alphanohtml')&&!GETPOST('transphrase', 'alphanohtml')) else
View.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
security_prepare_head()
Prepare array with list of tabs.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
encodedecode_dbpassconf($level=0)
Encode or decode database password in config file.
print $_SERVER["PHP_SELF"] n
Edit parameters.
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.