diff --git a/htdocs/admin/adherent.php b/htdocs/admin/adherent.php index 1c1fc4c8fd6..4fb19d27654 100644 --- a/htdocs/admin/adherent.php +++ b/htdocs/admin/adherent.php @@ -265,12 +265,12 @@ function form_constantes($tableau) { $sql = "SELECT "; $sql.= "rowid"; - $sql.= ", ".$db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." as name"; - $sql.= ", ".$db->decrypt('value',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." as value"; + $sql.= ", ".$db->decrypt('name')." as name"; + $sql.= ", ".$db->decrypt('value')." as value"; $sql.= ", type"; $sql.= ", note"; $sql.= " FROM ".MAIN_DB_PREFIX."const"; - $sql.= " WHERE ".$db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." = '".$const."'"; + $sql.= " WHERE ".$db->decrypt('name')." = '".$const."'"; $sql.= " AND entity = ".$conf->entity; $result = $db->query($sql); diff --git a/htdocs/admin/const.php b/htdocs/admin/const.php index 715d1fd3bcc..77c0eea6a94 100644 --- a/htdocs/admin/const.php +++ b/htdocs/admin/const.php @@ -151,8 +151,8 @@ print ''; # Affiche lignes des constantes $sql = "SELECT"; $sql.= " rowid"; -$sql.= ", ".$db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." as name"; -$sql.= ", ".$db->decrypt('value',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." as value"; +$sql.= ", ".$db->decrypt('name')." as name"; +$sql.= ", ".$db->decrypt('value')." as value"; $sql.= ", type"; $sql.= ", note"; $sql.= ", entity"; diff --git a/htdocs/admin/editeur.php b/htdocs/admin/editeur.php index 94c8df252ec..751f1d13ba7 100644 --- a/htdocs/admin/editeur.php +++ b/htdocs/admin/editeur.php @@ -49,7 +49,7 @@ if ($_POST["action"] == 'set') if ($_GET["action"] == 'unset') { $sql = "DELETE FROM ".MAIN_DB_PREFIX."const"; - $sql.= " WHERE ".$db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey); + $sql.= " WHERE ".$db->decrypt('name'); $sql.= " LIKE 'EDITEUR_LIVRE_FORMAT_%'"; $sql.= " AND rowid='".$_GET["id"]."';"; if ($db->query($sql)) @@ -94,9 +94,9 @@ $var=true; $sql = "SELECT"; $sql.= " rowid"; -$sql.= ", ".$db->decrypt('value',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." as value"; +$sql.= ", ".$db->decrypt('value')." as value"; $sql.= " FROM ".MAIN_DB_PREFIX."const"; -$sql.= " WHERE ".$db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey); +$sql.= " WHERE ".$db->decrypt('name'); $sql.= " LIKE 'EDITEUR_LIVRE_FORMAT_%'"; $result = $db->query($sql); diff --git a/htdocs/admin/system/constall.php b/htdocs/admin/system/constall.php index d10f184eab8..098b6c6528a 100644 --- a/htdocs/admin/system/constall.php +++ b/htdocs/admin/system/constall.php @@ -50,8 +50,8 @@ print "\n"; $sql = "SELECT"; $sql.= " rowid"; -$sql.= ", ".$db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." as name"; -$sql.= ", ".$db->decrypt('value',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." as value"; +$sql.= ", ".$db->decrypt('name')." as name"; +$sql.= ", ".$db->decrypt('value')." as value"; $sql.= ", type"; $sql.= ", note"; $sql.= ", entity"; diff --git a/htdocs/core/conf.class.php b/htdocs/core/conf.class.php index f0e545489f1..5fc215d2d89 100644 --- a/htdocs/core/conf.class.php +++ b/htdocs/core/conf.class.php @@ -91,8 +91,8 @@ class Conf * - En constante php (TODO a virer) * - En $this->global->key=value */ - $sql = "SELECT ".$db->decrypt('name',$this->db->dolibarr_main_db_encryption,$this->db->dolibarr_main_db_cryptkey)." as name"; - $sql.= ",".$db->decrypt('value',$this->db->dolibarr_main_db_encryption,$this->db->dolibarr_main_db_cryptkey)." as value, entity"; + $sql = "SELECT ".$db->decrypt('name')." as name"; + $sql.= ",".$db->decrypt('value')." as value, entity"; $sql.= " FROM ".MAIN_DB_PREFIX."const"; $sql.= " WHERE entity IN (0,".$this->entity.")"; $sql.= " ORDER BY entity"; // This is to have entity 0 first, then entity 1 that overwrite. diff --git a/htdocs/includes/modules/DolibarrModules.class.php b/htdocs/includes/modules/DolibarrModules.class.php index 2d178d537f1..7867c9e1f5c 100644 --- a/htdocs/includes/modules/DolibarrModules.class.php +++ b/htdocs/includes/modules/DolibarrModules.class.php @@ -379,15 +379,15 @@ class DolibarrModules $entity = ((! empty($this->always_enabled) || ! empty($this->core_enabled)) ? 0 : $conf->entity); $sql = "DELETE FROM ".MAIN_DB_PREFIX."const"; - $sql.= " WHERE ".$this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." = '".$this->const_name."'"; + $sql.= " WHERE ".$this->db->decrypt('name')." = '".$this->const_name."'"; $sql.= " AND entity in (0, ".$entity.")"; dol_syslog("DolibarrModules::_active sql=".$sql, LOG_DEBUG); $this->db->query($sql); $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,value,visible,entity) VALUES"; - $sql.= " (".$this->db->encrypt($this->const_name,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1); - $sql.= ",".$this->db->encrypt('1',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1); + $sql.= " (".$this->db->encrypt($this->const_name,1); + $sql.= ",".$this->db->encrypt('1',1); $sql.= ",0,".$entity.")"; dol_syslog("DolibarrModules::_active sql=".$sql, LOG_DEBUG); @@ -414,7 +414,7 @@ class DolibarrModules $entity = ((! empty($this->always_enabled) || ! empty($this->core_enabled)) ? 0 : $conf->entity); $sql = "DELETE FROM ".MAIN_DB_PREFIX."const"; - $sql.= " WHERE ".$this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." = '".$this->const_name."'"; + $sql.= " WHERE ".$this->db->decrypt('name')." = '".$this->const_name."'"; $sql.= " AND entity in (0, ".$entity.")"; dol_syslog("DolibarrModules::_unactive sql=".$sql); @@ -611,7 +611,7 @@ class DolibarrModules if ($this->style_sheet) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."const"; - $sql.= " WHERE ".$this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." = '".$this->const_name."_CSS'"; + $sql.= " WHERE ".$this->db->decrypt('name')." = '".$this->const_name."_CSS'"; $sql.= " AND entity = ".$conf->entity; dol_syslog("DolibarrModules::delete_style_sheet sql=".$sql); @@ -637,7 +637,7 @@ class DolibarrModules $err=0; $sql = "DELETE FROM ".MAIN_DB_PREFIX."const"; - $sql.= " WHERE ".$this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." like '".$this->const_name."_TABS_%'"; + $sql.= " WHERE ".$this->db->decrypt('name')." like '".$this->const_name."_TABS_%'"; $sql.= " AND entity = ".$conf->entity; dol_syslog("DolibarrModules::delete_tabs sql=".$sql); @@ -672,9 +672,9 @@ class DolibarrModules $sql.= ", entity"; $sql.= ")"; $sql.= " VALUES ("; - $sql.= $this->db->encrypt($this->const_name."_CSS",$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1); + $sql.= $this->db->encrypt($this->const_name."_CSS",1); $sql.= ", 'chaine'"; - $sql.= ", ".$this->db->encrypt($this->style_sheet,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1); + $sql.= ", ".$this->db->encrypt($this->style_sheet,1); $sql.= ", 'Style sheet for module ".$this->name."'"; $sql.= ", '0'"; $sql.= ", ".$conf->entity; @@ -719,9 +719,9 @@ class DolibarrModules $sql.= ", entity"; $sql.= ")"; $sql.= " VALUES ("; - $sql.= $this->db->encrypt($this->const_name."_TABS_".$i,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1); + $sql.= $this->db->encrypt($this->const_name."_TABS_".$i,1); $sql.= ", 'chaine'"; - $sql.= ", ".$this->db->encrypt($value,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1); + $sql.= ", ".$this->db->encrypt($value,1); $sql.= ", null"; $sql.= ", '0'"; $sql.= ", ".$conf->entity; @@ -764,7 +764,7 @@ class DolibarrModules $sql = "SELECT count(*)"; $sql.= " FROM ".MAIN_DB_PREFIX."const"; - $sql.= " WHERE ".$this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." = '".$name."'"; + $sql.= " WHERE ".$this->db->decrypt('name')." = '".$name."'"; $sql.= " AND entity = ".$entity; $result=$this->db->query($sql); @@ -779,9 +779,9 @@ class DolibarrModules { $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,type,value,note,visible,entity)"; $sql.= " VALUES ("; - $sql.= $this->db->encrypt($name,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1); + $sql.= $this->db->encrypt($name,1); $sql.= ",'".$type."'"; - $sql.= ",".$this->db->encrypt($val,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1); + $sql.= ",".$this->db->encrypt($val,1); $sql.= ",'".addslashes($note)."'"; $sql.= ",'".$visible."'"; $sql.= ",".$entity; @@ -791,9 +791,9 @@ class DolibarrModules { $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,type,value,visible,entity)"; $sql.= " VALUES ("; - $sql.= $this->db->encrypt($name,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1); + $sql.= $this->db->encrypt($name,1); $sql.= ",'".$type."'"; - $sql.= ",".$this->db->encrypt($val,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1); + $sql.= ",".$this->db->encrypt($val,1); $sql.= ",'".$visible."'"; $sql.= ",".$entity; $sql.= ")"; @@ -802,7 +802,7 @@ class DolibarrModules { $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,type,visible,entity)"; $sql.= " VALUES ("; - $sql.= $this->db->encrypt($name,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1); + $sql.= $this->db->encrypt($name,1); $sql.= ",'".$type."'"; $sql.= ",'".$visible."'"; $sql.= ",".$entity; @@ -843,9 +843,9 @@ class DolibarrModules //print $this->rights_class." ".sizeof($this->rights)."
"; // Test si module actif - $sql_del = "SELECT ".$this->db->decrypt('value',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." as value"; + $sql_del = "SELECT ".$this->db->decrypt('value')." as value"; $sql_del.= " FROM ".MAIN_DB_PREFIX."const"; - $sql_del.= " WHERE ".$this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." = '".$this->const_name."'"; + $sql_del.= " WHERE ".$this->db->decrypt('name')." = '".$this->const_name."'"; $sql_del.= " AND entity IN (0,".$conf->entity.")"; $resql=$this->db->query($sql_del); @@ -1121,7 +1121,7 @@ class DolibarrModules $sql = "SELECT count(*)"; $sql.= " FROM ".MAIN_DB_PREFIX."const"; - $sql.= " WHERE ".$this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." = '".$name."'"; + $sql.= " WHERE ".$this->db->decrypt('name')." = '".$name."'"; $sql.= " AND entity = ".$conf->entity; dol_syslog("DolibarrModules::insert_dirs sql=".$sql); @@ -1133,7 +1133,7 @@ class DolibarrModules if ($row[0] == 0) { $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,type,value,note,visible,entity)"; - $sql.= " VALUES (".$this->db->encrypt($name,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1).",'chaine',".$this->db->encrypt($dir,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1).",'Directory for module ".$this->name."','0',".$conf->entity.")"; + $sql.= " VALUES (".$this->db->encrypt($name,1).",'chaine',".$this->db->encrypt($dir,1).",'Directory for module ".$this->name."','0',".$conf->entity.")"; dol_syslog("DolibarrModules::insert_dirs sql=".$sql); $resql=$this->db->query($sql); @@ -1161,7 +1161,7 @@ class DolibarrModules $err=0; $sql = "DELETE FROM ".MAIN_DB_PREFIX."const"; - $sql.= " WHERE ".$this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." like '".$this->const_name."_DIR_%'"; + $sql.= " WHERE ".$this->db->decrypt('name')." like '".$this->const_name."_DIR_%'"; $sql.= " AND entity = ".$conf->entity; dol_syslog("DolibarrModules::delete_dirs sql=".$sql); diff --git a/htdocs/install/etape5.php b/htdocs/install/etape5.php index c5f8a4b6103..3849f39ae35 100644 --- a/htdocs/install/etape5.php +++ b/htdocs/install/etape5.php @@ -188,24 +188,24 @@ if ($_POST["action"] == "set" || preg_match('/upgrade/i',$_POST["action"])) $db->begin(); dolibarr_install_syslog('install/etape5.php set MAIN_VERSION_LAST_INSTALL const to '.$targetversion, LOG_DEBUG); - $resql=$db->query("DELETE FROM llx_const WHERE ".$db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)."='MAIN_VERSION_LAST_INSTALL'"); + $resql=$db->query("DELETE FROM llx_const WHERE ".$db->decrypt('name')."='MAIN_VERSION_LAST_INSTALL'"); if (! $resql) dol_print_error($db,'Error in setup program'); - $resql=$db->query("INSERT INTO llx_const(name,value,type,visible,note,entity) values(".$db->encrypt('MAIN_VERSION_LAST_INSTALL',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1).",".$db->encrypt($targetversion,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1).",'chaine',0,'Dolibarr version when install',0)"); + $resql=$db->query("INSERT INTO llx_const(name,value,type,visible,note,entity) values(".$db->encrypt('MAIN_VERSION_LAST_INSTALL',1).",".$db->encrypt($targetversion,1).",'chaine',0,'Dolibarr version when install',0)"); if (! $resql) dol_print_error($db,'Error in setup program'); $conf->global->MAIN_VERSION_LAST_INSTALL=$targetversion; if ($usedoliwamp) { dolibarr_install_syslog('install/etape5.php set MAIN_REMOVE_INSTALL_WARNING const to 1', LOG_DEBUG); - $resql=$db->query("DELETE FROM llx_const WHERE ".$db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)."='MAIN_REMOVE_INSTALL_WARNING'"); + $resql=$db->query("DELETE FROM llx_const WHERE ".$db->decrypt('name')."='MAIN_REMOVE_INSTALL_WARNING'"); if (! $resql) dol_print_error($db,'Error in setup program'); - $resql=$db->query("INSERT INTO llx_const(name,value,type,visible,note,entity) values(".$db->encrypt('MAIN_REMOVE_INSTALL_WARNING',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1).",".$db->encrypt(1,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1).",'chaine',1,'Disable install warnings',0)"); + $resql=$db->query("INSERT INTO llx_const(name,value,type,visible,note,entity) values(".$db->encrypt('MAIN_REMOVE_INSTALL_WARNING',1).",".$db->encrypt(1,1).",'chaine',1,'Disable install warnings',0)"); if (! $resql) dol_print_error($db,'Error in setup program'); $conf->global->MAIN_REMOVE_INSTALL_WARNING=1; } dolibarr_install_syslog('install/etape5.php Remove MAIN_NOT_INSTALLED const', LOG_DEBUG); - $resql=$db->query("DELETE FROM llx_const WHERE ".$db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)."='MAIN_NOT_INSTALLED'"); + $resql=$db->query("DELETE FROM llx_const WHERE ".$db->decrypt('name')."='MAIN_NOT_INSTALLED'"); if (! $resql) dol_print_error($db,'Error in setup program'); $db->commit(); @@ -236,9 +236,9 @@ if ($_POST["action"] == "set" || preg_match('/upgrade/i',$_POST["action"])) if ($tagdatabase) { dolibarr_install_syslog('install/etape5.php set MAIN_VERSION_LAST_UPGRADE const to value '.$targetversion, LOG_DEBUG); - $resql=$db->query("DELETE FROM llx_const WHERE ".$db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)."='MAIN_VERSION_LAST_UPGRADE'"); + $resql=$db->query("DELETE FROM llx_const WHERE ".$db->decrypt('name')."='MAIN_VERSION_LAST_UPGRADE'"); if (! $resql) dol_print_error($db,'Error in setup program'); - $resql=$db->query("INSERT INTO llx_const(name,value,type,visible,note,entity) values(".$db->encrypt('MAIN_VERSION_LAST_UPGRADE',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1).",".$db->encrypt($targetversion,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1).",'chaine',0,'Dolibarr version for last upgrade',0)"); + $resql=$db->query("INSERT INTO llx_const(name,value,type,visible,note,entity) values(".$db->encrypt('MAIN_VERSION_LAST_UPGRADE',1).",".$db->encrypt($targetversion,1).",'chaine',0,'Dolibarr version for last upgrade',0)"); if (! $resql) dol_print_error($db,'Error in setup program'); $conf->global->MAIN_VERSION_LAST_UPGRADE=$targetversion; } @@ -258,7 +258,7 @@ if ($_POST["action"] == "set" || preg_match('/upgrade/i',$_POST["action"])) } // May fail if parameter already defined - $resql=$db->query("INSERT INTO llx_const(name,value,type,visible,note,entity) values(".$db->encrypt('MAIN_LANG_DEFAULT',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1).",".$db->encrypt($setuplang,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1).",'chaine',0,'Default language',1)"); + $resql=$db->query("INSERT INTO llx_const(name,value,type,visible,note,entity) values(".$db->encrypt('MAIN_LANG_DEFAULT',1).",".$db->encrypt($setuplang,1).",'chaine',0,'Default language',1)"); //if (! $resql) dol_print_error($db,'Error in setup program'); print ''; diff --git a/htdocs/lib/admin.lib.php b/htdocs/lib/admin.lib.php index ec62551ab66..91fb4c419f6 100644 --- a/htdocs/lib/admin.lib.php +++ b/htdocs/lib/admin.lib.php @@ -309,7 +309,7 @@ function dolibarr_del_const($db, $name, $entity=1) global $conf; $sql = "DELETE FROM ".MAIN_DB_PREFIX."const"; - $sql.=" WHERE (".$db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." = '".addslashes($name)."' OR rowid = '".addslashes($name)."')"; + $sql.=" WHERE (".$db->decrypt('name')." = '".addslashes($name)."' OR rowid = '".addslashes($name)."')"; if ($entity >= 0) $sql.= " AND entity = ".$entity; dol_syslog("admin.lib::dolibarr_del_const sql=".$sql); @@ -339,9 +339,9 @@ function dolibarr_get_const($db, $name, $entity=1) global $conf; $value=''; - $sql = "SELECT ".$db->decrypt('value',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." as value"; + $sql = "SELECT ".$db->decrypt('value')." as value"; $sql.= " FROM ".MAIN_DB_PREFIX."const"; - $sql.= " WHERE ".$db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." = '".addslashes($name)."'"; + $sql.= " WHERE ".$db->decrypt('name')." = '".addslashes($name)."'"; $sql.= " AND entity = ".$entity; dol_syslog("admin.lib::dolibarr_get_const sql=".$sql); @@ -381,7 +381,7 @@ function dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $not //dol_syslog("dolibarr_set_const name=$name, value=$value"); $sql = "DELETE FROM ".MAIN_DB_PREFIX."const"; - $sql.= " WHERE ".$db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." = '".addslashes($name)."'"; + $sql.= " WHERE ".$db->decrypt('name')." = '".addslashes($name)."'"; $sql.= " AND entity = ".$entity; dol_syslog("admin.lib::dolibarr_set_const sql=".$sql, LOG_DEBUG); @@ -391,8 +391,8 @@ function dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $not { $sql = "INSERT INTO llx_const(name,value,type,visible,note,entity)"; $sql.= " VALUES ("; - $sql.= $db->encrypt($name,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1); - $sql.= ", ".$db->encrypt($value,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1); + $sql.= $db->encrypt($name,1); + $sql.= ", ".$db->encrypt($value,1); $sql.= ",'".$type."',".$visible.",'".addslashes($note)."',".$entity.")"; dol_syslog("admin.lib::dolibarr_set_const sql=".$sql, LOG_DEBUG); diff --git a/htdocs/lib/databases/mssql.lib.php b/htdocs/lib/databases/mssql.lib.php index 7beb0f120c3..62be1119f55 100644 --- a/htdocs/lib/databases/mssql.lib.php +++ b/htdocs/lib/databases/mssql.lib.php @@ -705,27 +705,39 @@ class DoliDb /** * \brief Encrypt sensitive data in database * \param fieldorvalue Field name or value to encrypt - * \param cryptType Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) - * \param cryptKey Encryption key * \param withQuotes Return string with quotes * \return return XXX(field) or XXX('value') or field or 'value' */ - function encrypt($fieldorvalue, $cryptType=0, $cryptKey='', $withQuotes=0) + function encrypt($fieldorvalue, $withQuotes=0) { + global $conf; + + // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) + $cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0); + + //Encryption key + $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); + $return = $fieldorvalue; return ($withQuotes?"'":"").$return.($withQuotes?"'":""); } /** * \brief Decrypt sensitive data in database - * \param field Field name to decrypt - * \param cryptType Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) - * \param cryptKey Encryption key - * \return return Field to decrypt if used + * \param value Value to decrypt + * \return return Decrypted value if used */ - function decrypt($field, $cryptType=0, $cryptKey='') + function decrypt($value) { - $return = $field; + global $conf; + + // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) + $cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0); + + //Encryption key + $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); + + $return = $value; return $return; } diff --git a/htdocs/lib/databases/mysql.lib.php b/htdocs/lib/databases/mysql.lib.php index 9d384712db2..fd66f4b4281 100644 --- a/htdocs/lib/databases/mysql.lib.php +++ b/htdocs/lib/databases/mysql.lib.php @@ -692,13 +692,19 @@ class DoliDb /** * \brief Encrypt sensitive data in database * \param fieldorvalue Field name or value to encrypt - * \param cryptType Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) - * \param cryptKey Encryption key * \param withQuotes Return string with quotes * \return return XXX(field) or XXX('value') or field or 'value' */ - function encrypt($fieldorvalue, $cryptType=0, $cryptKey='', $withQuotes=0) + function encrypt($fieldorvalue, $withQuotes=0) { + global $conf; + + // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) + $cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0); + + //Encryption key + $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); + $return = ($withQuotes?"'":"").addslashes($fieldorvalue).($withQuotes?"'":""); if ($cryptType && !empty($cryptKey)) @@ -718,24 +724,30 @@ class DoliDb /** * \brief Decrypt sensitive data in database - * \param field Field name to decrypt - * \param cryptType Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) - * \param cryptKey Encryption key - * \return return Field to decrypt if used + * \param value Value to decrypt + * \return return Decrypted value if used */ - function decrypt($field, $cryptType=0, $cryptKey='') + function decrypt($value) { - $return = $field; + global $conf; + + // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) + $cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0); + + //Encryption key + $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); + + $return = $value; if ($cryptType && !empty($cryptKey)) { if ($cryptType == 2) { - $return = 'AES_DECRYPT('.$field.',\''.$cryptKey.'\')'; + $return = 'AES_DECRYPT('.$value.',\''.$cryptKey.'\')'; } else if ($cryptType == 1) { - $return = 'DES_DECRYPT('.$field.',\''.$cryptKey.'\')'; + $return = 'DES_DECRYPT('.$value.',\''.$cryptKey.'\')'; } } diff --git a/htdocs/lib/databases/mysqli.lib.php b/htdocs/lib/databases/mysqli.lib.php index 0511e3e54f3..8f47bf1c045 100644 --- a/htdocs/lib/databases/mysqli.lib.php +++ b/htdocs/lib/databases/mysqli.lib.php @@ -702,13 +702,19 @@ class DoliDb /** * \brief Encrypt sensitive data in database * \param fieldorvalue Field name or value to encrypt - * \param cryptType Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) - * \param cryptKey Encryption key * \param withQuotes Return string with quotes * \return return XXX(field) or XXX('value') or field or 'value' */ - function encrypt($fieldorvalue, $cryptType=0, $cryptKey='', $withQuotes=0) + function encrypt($fieldorvalue, $withQuotes=0) { + global $conf; + + // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) + $cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0); + + //Encryption key + $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); + $return = ($withQuotes?"'":"").addslashes($fieldorvalue).($withQuotes?"'":""); if ($cryptType && !empty($cryptKey)) @@ -728,24 +734,30 @@ class DoliDb /** * \brief Decrypt sensitive data in database - * \param field Field name to decrypt - * \param cryptType Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) - * \param cryptKey Encryption key - * \return return Field to decrypt if used + * \param value Value to decrypt + * \return return Decrypted value if used */ - function decrypt($field, $cryptType=0, $cryptKey='') + function decrypt($value) { - $return = $field; + global $conf; + + // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) + $cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0); + + //Encryption key + $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); + + $return = $value; if ($cryptType && !empty($cryptKey)) { if ($cryptType == 2) { - $return = 'AES_DECRYPT('.$field.',\''.$cryptKey.'\')'; + $return = 'AES_DECRYPT('.$value.',\''.$cryptKey.'\')'; } else if ($cryptType == 1) { - $return = 'DES_DECRYPT('.$field.',\''.$cryptKey.'\')'; + $return = 'DES_DECRYPT('.$value.',\''.$cryptKey.'\')'; } } diff --git a/htdocs/lib/databases/pgsql.lib.php b/htdocs/lib/databases/pgsql.lib.php index d1b82e1deb7..4b64115adfd 100644 --- a/htdocs/lib/databases/pgsql.lib.php +++ b/htdocs/lib/databases/pgsql.lib.php @@ -799,13 +799,19 @@ class DoliDb /** * \brief Encrypt sensitive data in database * \param fieldorvalue Field name or value to encrypt - * \param cryptType Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) - * \param cryptKey Encryption key * \param withQuotes Return string with quotes * \return return XXX(field) or XXX('value') or field or 'value' */ - function encrypt($fieldorvalue, $cryptType=0, $cryptKey='', $withQuotes=0) + function encrypt($fieldorvalue, $withQuotes=0) { + global $conf; + + // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) + $cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0); + + //Encryption key + $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); + $return = $fieldorvalue; return ($withQuotes?"'":"").$return.($withQuotes?"'":""); } @@ -813,14 +819,20 @@ class DoliDb /** * \brief Decrypt sensitive data in database - * \param field Field name to decrypt - * \param cryptType Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) - * \param cryptKey Encryption key - * \return return Field to decrypt if used + * \param value Value to decrypt + * \return return Decrypted value if used */ - function decrypt($field, $cryptType=0, $cryptKey='') + function decrypt($value) { - $return = $field; + global $conf; + + // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) + $cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0); + + //Encryption key + $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); + + $return = $value; return $return; } diff --git a/htdocs/multicompany/multicompany.class.php b/htdocs/multicompany/multicompany.class.php index 8adf656ba8e..3120340537b 100644 --- a/htdocs/multicompany/multicompany.class.php +++ b/htdocs/multicompany/multicompany.class.php @@ -97,10 +97,10 @@ class Multicompany global $conf; $sql = "SELECT "; - $sql.= $this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." as name"; - $sql.= ", ".$this->db->decrypt('value',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." as value"; + $sql.= $this->db->decrypt('name')." as name"; + $sql.= ", ".$this->db->decrypt('value')." as value"; $sql.= " FROM ".MAIN_DB_PREFIX."const"; - $sql.= " WHERE ".$this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." LIKE 'MAIN_%'"; + $sql.= " WHERE ".$this->db->decrypt('name')." LIKE 'MAIN_%'"; $sql.= " AND entity = ".$id; $result = $this->db->query($sql); @@ -152,7 +152,7 @@ class Multicompany $sql = "UPDATE ".MAIN_DB_PREFIX."const"; $sql.= " SET entity = ".$newid; - $sql.= " WHERE ".$this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." = 'MAIN_INFO_SOCIETE_NOM'"; + $sql.= " WHERE ".$this->db->decrypt('name')." = 'MAIN_INFO_SOCIETE_NOM'"; $sql.= " AND entity = ".$id; dol_syslog("Multicompany::setEntity sql=".$sql, LOG_DEBUG); @@ -168,10 +168,10 @@ class Multicompany global $conf; $sql = "SELECT "; - $sql.= $this->db->decrypt('value',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." as value"; + $sql.= $this->db->decrypt('value')." as value"; $sql.= ", entity"; $sql.= " FROM ".MAIN_DB_PREFIX."const"; - $sql.= " WHERE ".$this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." = 'MAIN_INFO_SOCIETE_NOM'"; + $sql.= " WHERE ".$this->db->decrypt('name')." = 'MAIN_INFO_SOCIETE_NOM'"; $sql.= " ORDER BY value ASC"; $result = $this->db->query($sql); diff --git a/htdocs/product/templates/product.livre.class.php b/htdocs/product/templates/product.livre.class.php index b0342f64068..814990ab01d 100644 --- a/htdocs/product/templates/product.livre.class.php +++ b/htdocs/product/templates/product.livre.class.php @@ -576,9 +576,9 @@ class ProductLivre extends Product $sql = "SELECT"; $sql.= " rowid"; - $sql.= ", ".$this->db->decrypt('value',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." as value"; + $sql.= ", ".$this->db->decrypt('value')." as value"; $sql.= " FROM ".MAIN_DB_PREFIX."const"; - $sql.= " WHERE ".$this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey); + $sql.= " WHERE ".$this->db->decrypt('name'); $sql.= " LIKE 'EDITEUR_LIVRE_FORMAT_%'"; $resql = $this->db->query($sql);