diff --git a/htdocs/admin/security.php b/htdocs/admin/security.php index 81803e3b570..fa5cf6391f2 100644 --- a/htdocs/admin/security.php +++ b/htdocs/admin/security.php @@ -87,6 +87,21 @@ else if ($_GET["action"] == 'disable_encrypt') exit; } +if ($_GET["action"] == 'activate_encryptdbpassconf') +{ + dolibarr_set_const($db, "MAIN_DATABASE_PWD_CONFIG_ENCRYPTED", "1"); + $result = encodedecode_dbpassconf(1); + Header("Location: security.php"); + exit; +} +else if ($_GET["action"] == 'disable_encryptdbpassconf') +{ + dolibarr_del_const($db, "MAIN_DATABASE_PWD_CONFIG_ENCRYPTED"); + $result = encodedecode_dbpassconf(0); + Header("Location: security.php"); + exit; +} + /* * Affichage onglet */ @@ -198,8 +213,8 @@ print ""; print ''; print ''; -print ''; -print ''; +print ''; +print ''; if ($conf->global->DATABASE_PWD_ENCRYPTED == 0 || $allow_disable_encryption) { print ''; @@ -207,8 +222,7 @@ if ($conf->global->DATABASE_PWD_ENCRYPTED == 0 || $allow_disable_encryption) print ''; print ""; -print ''; -print ''; +print ''; print '"; print ''; + +// Cryptage du mot de base de la base dans conf.php + +print ""; +print ''; +//print ''; +print ''; + +if ($conf->global->MAIN_DATABASE_PWD_CONFIG_ENCRYPTED == 0) +{ + print '"; +} +if($conf->global->MAIN_DATABASE_PWD_CONFIG_ENCRYPTED == 1) +{ + print '"; +} + +print ""; +print ''; + print '
'.$langs->trans("Encryption").''.$langs->trans("Activated").''.$langs->trans("Encryption").''.$langs->trans("Activated").''.$langs->trans("Action").'
'.$langs->trans("DoNotStoreClearPassword").' '.$langs->trans("DoNotStoreClearPassword").''; if($conf->global->DATABASE_PWD_ENCRYPTED == 1) { @@ -234,6 +248,36 @@ if($conf->global->DATABASE_PWD_ENCRYPTED == 1 && $allow_disable_encryption) print "
'.$langs->trans("MainDbPasswordFileConfEncrypted").' '; +if($conf->global->MAIN_DATABASE_PWD_CONFIG_ENCRYPTED == 1) +{ + print img_tick(); +} + +print ''; + print ''.$langs->trans("Activate").''; + print "'; + print ''.$langs->trans("Disable").''; + print "
'; print ''; diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 884716ab03c..b642d232e27 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -93,6 +93,7 @@ Required=Required Security=Security Passwords=Passwords DoNotStoreClearPassword=Do no store clear passwords in database +MainDbPasswordFileConfEncrypted=Password of the database encrypted in conf.php Feature=Feature DolibarrLicense=License DolibarrProjectLeader=Project leader diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index 9a45055227b..89251b5c5e5 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -93,6 +93,7 @@ Required=Requis Security=Sécurité Passwords=Mots de passe DoNotStoreClearPassword=Ne pas stocker de mot de passe en clair dans la base +MainDbPasswordFileConfEncrypted=Encrypter le mot de passe de la base dans le fichier conf.php Feature=Fonction DolibarrLicense=Licence DolibarrProjectLeader=Chef de projet diff --git a/htdocs/lib/functions.inc.php b/htdocs/lib/functions.inc.php index 1f72affaf09..0e048a995e4 100644 --- a/htdocs/lib/functions.inc.php +++ b/htdocs/lib/functions.inc.php @@ -2402,4 +2402,102 @@ function _dol_htmlentities($stringtoencode,$isstringalreadyhtml) return $stringtoencode; } +/** + \brief Encode\decode le mot de passe de la base de données dans le fichier de conf + \param level niveau d'encodage : 0 non encodé, 1 encodé +*/ +function encodedecode_dbpassconf($level=0) +{ + global $conf; + + $config = ''; + + if ($fp = fopen(DOL_DOCUMENT_ROOT.'/conf/conf.php','r')) + { + while(!feof($fp)) + { + $buffer = fgets($fp,4096); + if (strstr($buffer,"\$dolibarr_main_db_encrypted_pass")) + { + if ($level == 0) + { + $config .= "\$dolibarr_main_db_encrypted_pass=0;\n"; + } + else if ($level == 1) + { + $config .= "\$dolibarr_main_db_encrypted_pass=1;\n"; + } + } + else if (strstr($buffer,"\$dolibarr_main_db_pass")) + { + $passwd = strstr($buffer,"$dolibarr_main_db_pass="); + $passwd = substr(substr($passwd,2),0,-3); + if ($level == 0) + { + $passwd = dolibarr_decode($passwd); + } + else if ($level == 1) + { + $passwd = dolibarr_encode($passwd); + } + $config .= "\$dolibarr_main_db_pass=\"$passwd\";\n"; + } + else + { + $config .= $buffer; + } + } + fclose($fp); + + if ($fp = fopen(DOL_DOCUMENT_ROOT.'/conf/conf.php','w')) + { + fputs($fp, $config, strlen($config)); + fclose($fp); + return 1; + } + else + { + return -1; + } + } + else + { + return -2; + } +} + +/** + \brief Encode une chaine de caractère + \param chain chaine de caractères à encoder + \return string_coded chaine de caractères encodée +*/ +function dolibarr_encode($chain) +{ + for($i=0;$i diff --git a/htdocs/master.inc.php b/htdocs/master.inc.php index 6fbaeb6fce4..18e1ce5f915 100644 --- a/htdocs/master.inc.php +++ b/htdocs/master.inc.php @@ -84,7 +84,13 @@ define('DOL_URL_ROOT', $pos); // URL racine relative /* * Creation objet $conf */ + +// on décode le mot de passe de la base si besoin +require_once(DOL_DOCUMENT_ROOT ."/lib/functions.inc.php"); +if ($dolibarr_main_db_encrypted_pass == 1) $dolibarr_main_db_pass = dolibarr_decode($dolibarr_main_db_pass); + require_once(DOL_DOCUMENT_ROOT."/conf/conf.class.php"); + $conf = new Conf(); $conf->db->host = $dolibarr_main_db_host; $conf->db->name = $dolibarr_main_db_name; @@ -106,7 +112,6 @@ if (isset($_SERVER["HTTP_USER_AGENT"])) } // Chargement des includes principaux -require_once(DOL_DOCUMENT_ROOT ."/lib/functions.inc.php"); require_once(DOL_DOCUMENT_ROOT ."/user.class.php"); require_once(DOL_DOCUMENT_ROOT ."/menu.class.php"); require_once(DOL_DOCUMENT_ROOT ."/html.form.class.php");