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"));
40 $allow_disable_encryption =
true;
47 if ($action ==
'setgeneraterule') {
48 if (!
dolibarr_set_const($db,
'USER_PASSWORD_GENERATED', $_GET[
"value"],
'chaine', 0,
'', $conf->entity)) {
51 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
56 if ($action ==
'activate_encrypt') {
61 dolibarr_set_const($db,
"DATABASE_PWD_ENCRYPTED",
"1",
'chaine', 0,
'', $conf->entity);
63 $sql =
"SELECT u.rowid, u.pass, u.pass_crypted";
64 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
65 $sql .=
" WHERE u.pass IS NOT NULL AND LENGTH(u.pass) < 32";
69 $numrows = $db->num_rows(
$resql);
71 while ($i < $numrows) {
72 $obj = $db->fetch_object(
$resql);
74 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"user";
75 $sql .=
" SET pass_crypted = '".dol_hash($obj->pass).
"', pass = NULL";
76 $sql .=
" WHERE rowid=".((int) $obj->rowid);
79 $resql2 = $db->query($sql);
97 header(
"Location: security.php");
103 } elseif ($action ==
'disable_encrypt') {
106 if ($allow_disable_encryption) {
109 header(
"Location: security.php");
113 if ($action ==
'activate_encryptdbpassconf') {
120 header(
"Location: security.php");
125 } elseif ($action ==
'disable_encryptdbpassconf') {
132 header(
"Location: security.php");
135 setEventMessages($langs->trans(
'InstrucToClearPass', $dolibarr_main_db_pass), null,
'warnings');
139 if ($action ==
'activate_MAIN_SECURITY_DISABLEFORGETPASSLINK') {
140 dolibarr_set_const($db,
"MAIN_SECURITY_DISABLEFORGETPASSLINK",
'1',
'chaine', 0,
'', $conf->entity);
141 header(
"Location: security.php");
143 } elseif ($action ==
'disable_MAIN_SECURITY_DISABLEFORGETPASSLINK') {
145 header(
"Location: security.php");
149 if ($action ==
'updatepattern') {
150 $pattern =
GETPOST(
"pattern",
"alpha");
151 $explodePattern = explode(
';', $pattern);
153 $patternInError =
false;
154 if ($explodePattern[0] < 1 || $explodePattern[4] < 0) {
155 $patternInError =
true;
158 if ($explodePattern[0] < $explodePattern[1] + $explodePattern[2] + $explodePattern[3]) {
159 $patternInError =
true;
162 if (!$patternInError) {
163 dolibarr_set_const($db,
"USER_PASSWORD_PATTERN", $pattern,
'chaine', 0,
'', $conf->entity);
165 header(
"Location: security.php");
178 $wikihelp =
'EN:Setup_Security|FR:Paramétrage_Sécurité|ES:Configuración_Seguridad';
183 print
'<span class="opacitymedium">'.$langs->trans(
"GeneratedPasswordDesc").
"</span><br>\n";
194 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
195 print
'<input type="hidden" name="token" value="'.newToken().
'">';
196 print
'<input type="hidden" name="action" value="update">';
197 print
'<input type="hidden" name="constname" value="USER_PASSWORD_GENERATED">';
198 print
'<input type="hidden" name="consttype" value="yesno">';
201 $dir =
"../core/modules/security/generate";
203 $handle = opendir($dir);
205 if (is_resource($handle)) {
206 while (($file = readdir($handle)) !==
false) {
207 if (preg_match(
'/(modGeneratePass[a-z]+)\.class\.php$/i', $file, $reg)) {
209 $classname = $reg[1];
210 require_once $dir.
'/'.$file;
212 $obj =
new $classname($db, $conf, $langs, $user);
213 $arrayhandler[$obj->id] = $obj;
219 asort($arrayhandler);
221 print
'<div class="div-table-responsive-no-min">';
222 print
'<table class="noborder centpercent">';
223 print
'<tr class="liste_titre">';
224 print
'<td colspan="2">'.$langs->trans(
"RuleForGeneratedPasswords").
'</td>';
225 print
'<td>'.$langs->trans(
"Example").
'</td>';
226 print
'<td class="center">'.$langs->trans(
"Activated").
'</td>';
229 foreach ($arrayhandler as $key => $module) {
231 if (!empty($module->version) && $module->version ==
'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
234 if (!empty($module->version) && $module->version ==
'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
238 if ($module->isEnabled()) {
239 print
'<tr class="oddeven"><td width="100">';
242 print $module->getDescription().
'<br>';
243 print $langs->trans(
"MinLength").
': '.$module->length;
247 print
'<td class="nowrap">';
248 $tmp = $module->getExample();
249 if (preg_match(
'/^Error/', $tmp)) {
250 $langs->load(
"errors");
251 print
'<div class="error">'.$langs->trans($tmp).
'</div>';
252 } elseif ($tmp ==
'NotConfigured') {
253 print
'<span class="opacitymedium">'.$langs->trans($tmp).
'</span>';
255 print
'<span class="opacitymedium">'.$tmp.
'</span>';
259 print
'<td width="100" align="center">';
260 if ($conf->global->USER_PASSWORD_GENERATED == $key) {
262 print
img_picto($langs->trans(
"Enabled"),
'switch_on');
264 print
'<a href="'.$_SERVER[
'PHP_SELF'].
'?action=setgeneraterule&token='.
newToken().
'&value='.$key.
'">';
266 print
img_picto($langs->trans(
"Disabled"),
'switch_off');
269 print
"</td></tr>\n";
279 if ($conf->global->USER_PASSWORD_GENERATED ==
"Perso") {
280 $tabConf = explode(
";", $conf->global->USER_PASSWORD_PATTERN);
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" value="'.$tabConf[0].
'" id="minlenght" min="1"></td>';
296 print
'<tr class="oddeven">';
297 print
'<td>'.$langs->trans(
"NbMajMin").
"</td>";
298 print
'<td><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><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><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><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><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>';
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&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();});';
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">';
406 print
img_picto($langs->trans(
"Active"),
'tick');
410 print
'<td align="center" width="100">';
411 print
'<a href="security.php?action=activate_encrypt">'.$langs->trans(
"Activate").
'</a>';
417 print
'<td align="center" width="100">';
418 if ($allow_disable_encryption) {
421 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=disable_encrypt&token='.
newToken().
'">'.$langs->trans(
"Disable").
'</a>';
432 print
'<tr class="oddeven">';
433 print
'<td colspan="3">'.$langs->trans(
"MainDbPasswordFileConfEncrypted").
'</td>';
434 print
'<td align="center" width="60">';
435 if (preg_match(
'/crypted:/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass)) {
436 print
img_picto($langs->trans(
"Active"),
'tick');
441 print
'<td align="center" width="100">';
442 if (empty($dolibarr_main_db_pass) && empty($dolibarr_main_db_encrypted_pass)) {
443 $langs->load(
"errors");
444 print
img_warning($langs->trans(
"WarningPassIsEmpty"));
446 if (empty($dolibarr_main_db_encrypted_pass)) {
447 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=activate_encryptdbpassconf&token='.
newToken().
'">'.$langs->trans(
"Activate").
'</a>';
449 if (!empty($dolibarr_main_db_encrypted_pass)) {
450 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=disable_encryptdbpassconf&token='.
newToken().
'">'.$langs->trans(
"Disable").
'</a>';
461 print
'<tr class="oddeven">';
462 print
'<td colspan="3">'.$langs->trans(
"DisableForgetPasswordLinkOnLogonPage").
'</td>';
463 print
'<td align="center" width="60">';
465 print
img_picto($langs->trans(
"Active"),
'tick');
469 print
'<td align="center" width="100">';
470 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=activate_MAIN_SECURITY_DISABLEFORGETPASSLINK&token='.
newToken().
'">'.$langs->trans(
"Activate").
'</a>';
474 print
'<td align="center" width="100">';
475 print
'<a 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";
if($actionsave) if(!isset($conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY)) $wikihelp
View.
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.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
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).
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default= '')
Return dolibarr global constant string value.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
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)
Delete a constant.
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.
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.
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
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.