diff --git a/bin/init.bat b/bin/init.bat index 5a8597e102..19fc718fbf 100644 --- a/bin/init.bat +++ b/bin/init.bat @@ -164,6 +164,13 @@ if %requestType% == 'PATH_INFO' ( echo %deletelog% > %baseDir%deletelog.bat echo deletelog.bat ok +:: encrypt. +if exist "%baseDir%php\encrypt.php" ( + SET encrypt= %phpcli% %baseDir%php\encrypt.php %%* + echo %encrypt% > %baseDir%encrypt.bat + echo encrypt.bat ok +) + :: create crond.bat SET cron= %phpcli% %baseDir%php\crond.php echo %cron% > %baseDir%crond.bat diff --git a/bin/init.sh b/bin/init.sh index ae1aeb3d47..ae18cd6aa9 100755 --- a/bin/init.sh +++ b/bin/init.sh @@ -167,6 +167,13 @@ fi echo $deletelog > $basePath/deletelog.sh echo "deletelog.sh ok" +# encrypt. +if [ -f "$basePath/php/encrypt.php" ]; then + encrypt="$phpcli $basePath/php/encrypt.php \$*" + echo $encrypt > $basePath/encrypt.sh + echo "encrypt.sh ok" +fi + # cron if [ ! -d "$basePath/cron" ]; then mkdir $basePath/cron diff --git a/framework/base/helper.class.php b/framework/base/helper.class.php index 1f5d488053..16fd13a7c9 100644 --- a/framework/base/helper.class.php +++ b/framework/base/helper.class.php @@ -267,6 +267,66 @@ class baseHelper return (function_exists('get_magic_quotes_gpc') and get_magic_quotes_gpc()) ? addslashes(json_encode($data)) : json_encode($data); } + /** + * Encrypt password + * + * @param string $password + * @static + * @access public + * @return string + */ + public static function encryptPassword($password) + { + global $config; + + $encrypted = ''; + if(!empty($config->encryptSecret) and $password) + { + $secret = $config->encryptSecret; + if(function_exists('mcrypt_encrypt')) + { + $encrypted = base64_encode(@mcrypt_encrypt(MCRYPT_DES, $secret, $password, MCRYPT_MODE_CBC)); + } + elseif(function_exists('openssl_encrypt')) + { + $encrypted = @openssl_encrypt($password, 'des-cbc', $secret); + } + } + if(empty($encrypted)) $encrypted = $password; + + return $encrypted; + } + + /** + * Decrypt password. + * + * @param string $password + * @static + * @access public + * @return string + */ + public static function decryptPassword($password) + { + global $config; + + $decryptedPassword = ''; + if(!empty($config->encryptSecret) and $password) + { + $secret = $config->encryptSecret; + if(function_exists('mcrypt_decrypt')) + { + $decryptedPassword = mcrypt_decrypt(MCRYPT_DES, $secret, base64_decode($password), MCRYPT_MODE_CBC); + } + elseif(function_exists('openssl_decrypt')) + { + $decryptedPassword = openssl_decrypt($password, 'des-cbc', $secret); + } + } + if(empty($decryptedPassword)) $decryptedPassword = $password; + + return $decryptedPassword; + } + /** * 判断是否是utf8编码 * Judge a string is utf-8 or not. diff --git a/framework/base/router.class.php b/framework/base/router.class.php index 2cdf1f303b..1e04967ed5 100644 --- a/framework/base/router.class.php +++ b/framework/base/router.class.php @@ -2147,7 +2147,9 @@ class baseRouter } try { - $dbh = new PDO($dsn, $params->user, $params->password, array(PDO::ATTR_PERSISTENT => $params->persistant)); + $dbPassword = helper::decryptPassword($params->password); + + $dbh = new PDO($dsn, $params->user, $dbPassword, array(PDO::ATTR_PERSISTENT => $params->persistant)); $dbh->exec("SET NAMES {$params->encoding}"); /*