mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-29 23:32:54 +09:00
Merge branch 'develop'
This commit is contained in:
commit
e8af9dacfe
37 changed files with 1124 additions and 184 deletions
7
classes/cache/CacheFile.class.php
vendored
7
classes/cache/CacheFile.class.php
vendored
|
|
@ -88,7 +88,8 @@ class CacheFile extends CacheBase
|
|||
* Return whether cache is valid or invalid
|
||||
*
|
||||
* @param string $key Cache key
|
||||
* @param int $modified_time Not used
|
||||
* @param int $modified_time Unix time of data modified.
|
||||
* If stored time is older then modified time, return false.
|
||||
* @return bool Return true on valid or false on invalid.
|
||||
*/
|
||||
function isValid($key, $modified_time = 0)
|
||||
|
|
@ -113,7 +114,8 @@ class CacheFile extends CacheBase
|
|||
* Fetch a stored variable from the cache
|
||||
*
|
||||
* @param string $key The $key used to store the value.
|
||||
* @param int $modified_time Not used
|
||||
* @param int $modified_time Unix time of data modified.
|
||||
* If stored time is older then modified time, return false.
|
||||
* @return false|mixed Return false on failure. Return the string associated with the $key on success.
|
||||
*/
|
||||
function get($key, $modified_time = 0)
|
||||
|
|
@ -169,6 +171,7 @@ class CacheFile extends CacheBase
|
|||
function truncate()
|
||||
{
|
||||
FileHandler::removeFilesInDir($this->cache_dir);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ class FileHandler
|
|||
* @param string $source path to change into absolute path
|
||||
* @return string Absolute path
|
||||
*/
|
||||
function getRealPath($source)
|
||||
public static function getRealPath($source)
|
||||
{
|
||||
if(strlen($source) >= 2 && substr_compare($source, './', 0, 2) === 0)
|
||||
{
|
||||
|
|
@ -36,7 +36,7 @@ class FileHandler
|
|||
* @param string $type If set as 'force'. Even if the file exists in target, the file is copied.
|
||||
* @return void
|
||||
*/
|
||||
function copyDir($source_dir, $target_dir, $filter = null, $type = null)
|
||||
public static function copyDir($source_dir, $target_dir, $filter = null, $type = null)
|
||||
{
|
||||
$source_dir = self::getRealPath($source_dir);
|
||||
$target_dir = self::getRealPath($target_dir);
|
||||
|
|
@ -101,7 +101,7 @@ class FileHandler
|
|||
* @param string $force Y: overwrite
|
||||
* @return void
|
||||
*/
|
||||
function copyFile($source, $target, $force = 'Y')
|
||||
public static function copyFile($source, $target, $force = 'Y')
|
||||
{
|
||||
setlocale(LC_CTYPE, 'en_US.UTF8', 'ko_KR.UTF8');
|
||||
$source = self::getRealPath($source);
|
||||
|
|
@ -124,7 +124,7 @@ class FileHandler
|
|||
* @param string $filename Path of target file
|
||||
* @return string The content of the file. If target file does not exist, this function returns nothing.
|
||||
*/
|
||||
function readFile($filename)
|
||||
public static function readFile($filename)
|
||||
{
|
||||
if(($filename = self::exists($filename)) === FALSE || filesize($filename) < 1)
|
||||
{
|
||||
|
|
@ -142,7 +142,7 @@ class FileHandler
|
|||
* @param string $mode a(append) / w(write)
|
||||
* @return void
|
||||
*/
|
||||
function writeFile($filename, $buff, $mode = "w")
|
||||
public static function writeFile($filename, $buff, $mode = "w")
|
||||
{
|
||||
$filename = self::getRealPath($filename);
|
||||
$pathinfo = pathinfo($filename);
|
||||
|
|
@ -164,7 +164,7 @@ class FileHandler
|
|||
* @param string $filename path of target file
|
||||
* @return bool Returns TRUE on success or FALSE on failure.
|
||||
*/
|
||||
function removeFile($filename)
|
||||
public static function removeFile($filename)
|
||||
{
|
||||
return (($filename = self::exists($filename)) !== FALSE) && @unlink($filename);
|
||||
}
|
||||
|
|
@ -178,7 +178,7 @@ class FileHandler
|
|||
* @param string $target Path of target file
|
||||
* @return bool Returns TRUE on success or FALSE on failure.
|
||||
*/
|
||||
function rename($source, $target)
|
||||
public static function rename($source, $target)
|
||||
{
|
||||
return @rename(self::getRealPath($source), self::getRealPath($target));
|
||||
}
|
||||
|
|
@ -190,7 +190,7 @@ class FileHandler
|
|||
* @param string $target Path of target file
|
||||
* @return bool Returns TRUE on success or FALSE on failure.
|
||||
*/
|
||||
function moveFile($source, $target)
|
||||
public static function moveFile($source, $target)
|
||||
{
|
||||
if(($source = self::exists($source)) !== FALSE)
|
||||
{
|
||||
|
|
@ -209,7 +209,7 @@ class FileHandler
|
|||
* @param string $target_dir Path of target directory
|
||||
* @return void
|
||||
*/
|
||||
function moveDir($source_dir, $target_dir)
|
||||
public static function moveDir($source_dir, $target_dir)
|
||||
{
|
||||
self::rename($source_dir, $target_dir);
|
||||
}
|
||||
|
|
@ -225,7 +225,7 @@ class FileHandler
|
|||
* @param bool $concat_prefix If TRUE, return file name as absolute path
|
||||
* @return string[] Array of the filenames in the path
|
||||
*/
|
||||
function readDir($path, $filter = '', $to_lower = FALSE, $concat_prefix = FALSE)
|
||||
public static function readDir($path, $filter = '', $to_lower = FALSE, $concat_prefix = FALSE)
|
||||
{
|
||||
$path = self::getRealPath($path);
|
||||
$output = array();
|
||||
|
|
@ -277,7 +277,7 @@ class FileHandler
|
|||
* @param string $path_string Path of target directory
|
||||
* @return bool TRUE if success. It might return nothing when ftp is used and connection to the ftp address failed.
|
||||
*/
|
||||
function makeDir($path_string)
|
||||
public static function makeDir($path_string)
|
||||
{
|
||||
if(self::exists($path_string) !== FALSE)
|
||||
{
|
||||
|
|
@ -358,7 +358,7 @@ class FileHandler
|
|||
* @param string $path Path of the target directory
|
||||
* @return void
|
||||
*/
|
||||
function removeDir($path)
|
||||
public static function removeDir($path)
|
||||
{
|
||||
if(($path = self::isDir($path)) === FALSE)
|
||||
{
|
||||
|
|
@ -399,7 +399,7 @@ class FileHandler
|
|||
* @param string $path Path of the target directory
|
||||
* @return void
|
||||
*/
|
||||
function removeBlankDir($path)
|
||||
public static function removeBlankDir($path)
|
||||
{
|
||||
if(($path = self::isDir($path)) === FALSE)
|
||||
{
|
||||
|
|
@ -433,7 +433,7 @@ class FileHandler
|
|||
* @param string $path Path of the target directory
|
||||
* @return void
|
||||
*/
|
||||
function removeFilesInDir($path)
|
||||
public static function removeFilesInDir($path)
|
||||
{
|
||||
if(($path = self::getRealPath($path)) === FALSE)
|
||||
{
|
||||
|
|
@ -475,7 +475,7 @@ class FileHandler
|
|||
* @param int $size Number of the size
|
||||
* @return string File size string
|
||||
*/
|
||||
function filesize($size)
|
||||
public static function filesize($size)
|
||||
{
|
||||
if(!$size)
|
||||
{
|
||||
|
|
@ -515,7 +515,7 @@ class FileHandler
|
|||
* @param string $post_data Request arguments array for POST method
|
||||
* @return string If success, the content of the target file. Otherwise: none
|
||||
*/
|
||||
function getRemoteResource($url, $body = null, $timeout = 3, $method = 'GET', $content_type = null, $headers = array(), $cookies = array(), $post_data = array(), $request_config = array())
|
||||
public static function getRemoteResource($url, $body = null, $timeout = 3, $method = 'GET', $content_type = null, $headers = array(), $cookies = array(), $post_data = array(), $request_config = array())
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -621,7 +621,7 @@ class FileHandler
|
|||
* @param string[] $headers Headers key value array.
|
||||
* @return bool TRUE: success, FALSE: failed
|
||||
*/
|
||||
function getRemoteFile($url, $target_filename, $body = null, $timeout = 3, $method = 'GET', $content_type = null, $headers = array(), $cookies = array(), $post_data = array(), $request_config = array())
|
||||
public static function getRemoteFile($url, $target_filename, $body = null, $timeout = 3, $method = 'GET', $content_type = null, $headers = array(), $cookies = array(), $post_data = array(), $request_config = array())
|
||||
{
|
||||
if(!($body = self::getRemoteResource($url, $body, $timeout, $method, $content_type, $headers,$cookies,$post_data,$request_config)))
|
||||
{
|
||||
|
|
@ -639,7 +639,7 @@ class FileHandler
|
|||
* @param $val Size in string (ex., 10, 10K, 10M, 10G )
|
||||
* @return int converted size
|
||||
*/
|
||||
function returnBytes($val)
|
||||
public static function returnBytes($val)
|
||||
{
|
||||
$unit = strtoupper(substr($val, -1));
|
||||
$val = (float)$val;
|
||||
|
|
@ -660,7 +660,7 @@ class FileHandler
|
|||
* @param array $imageInfo Image info retrieved by getimagesize function
|
||||
* @return bool TRUE: it's ok, FALSE: otherwise
|
||||
*/
|
||||
function checkMemoryLoadImage(&$imageInfo)
|
||||
public static function checkMemoryLoadImage(&$imageInfo)
|
||||
{
|
||||
$K64 = 65536;
|
||||
$TWEAKFACTOR = 2.0;
|
||||
|
|
@ -689,7 +689,7 @@ class FileHandler
|
|||
* @param string $thumbnail_type Thumbnail type(crop, ratio)
|
||||
* @return bool TRUE: success, FALSE: failed
|
||||
*/
|
||||
function createImageFile($source_file, $target_file, $resize_width = 0, $resize_height = 0, $target_type = '', $thumbnail_type = 'crop')
|
||||
public static function createImageFile($source_file, $target_file, $resize_width = 0, $resize_height = 0, $target_type = '', $thumbnail_type = 'crop')
|
||||
{
|
||||
// check params
|
||||
if (($source_file = self::exists($source_file)) === FALSE)
|
||||
|
|
@ -892,7 +892,7 @@ class FileHandler
|
|||
* @param string $filename Path of the ini file
|
||||
* @return array ini array (if the target file does not exist, it returns FALSE)
|
||||
*/
|
||||
function readIniFile($filename)
|
||||
public static function readIniFile($filename)
|
||||
{
|
||||
if(($filename = self::exists($filename)) === FALSE)
|
||||
{
|
||||
|
|
@ -923,7 +923,7 @@ class FileHandler
|
|||
* @param array $arr Array
|
||||
* @return bool if array contains nothing it returns FALSE, otherwise TRUE
|
||||
*/
|
||||
function writeIniFile($filename, $arr)
|
||||
public static function writeIniFile($filename, $arr)
|
||||
{
|
||||
if(!is_array($arr) || count($arr) == 0)
|
||||
{
|
||||
|
|
@ -939,7 +939,7 @@ class FileHandler
|
|||
* @param array $arr Array
|
||||
* @return string
|
||||
*/
|
||||
function _makeIniBuff($arr)
|
||||
public static function _makeIniBuff($arr)
|
||||
{
|
||||
$return = array();
|
||||
foreach($arr as $key => $val)
|
||||
|
|
@ -976,7 +976,7 @@ class FileHandler
|
|||
* @param string $mode File mode for fopen
|
||||
* @return FileObject File object
|
||||
*/
|
||||
function openFile($filename, $mode)
|
||||
public static function openFile($filename, $mode)
|
||||
{
|
||||
$pathinfo = pathinfo($filename);
|
||||
self::makeDir($pathinfo['dirname']);
|
||||
|
|
@ -991,7 +991,7 @@ class FileHandler
|
|||
* @param string $filename Target file name
|
||||
* @return bool Returns TRUE if the file exists and contains something.
|
||||
*/
|
||||
function hasContent($filename)
|
||||
public static function hasContent($filename)
|
||||
{
|
||||
return (is_readable($filename) && (filesize($filename) > 0));
|
||||
}
|
||||
|
|
@ -1002,7 +1002,7 @@ class FileHandler
|
|||
* @param string $filename Target file name
|
||||
* @return bool Returns FALSE if the file does not exists, or Returns full path file(string).
|
||||
*/
|
||||
function exists($filename)
|
||||
public static function exists($filename)
|
||||
{
|
||||
$filename = self::getRealPath($filename);
|
||||
return file_exists($filename) ? $filename : FALSE;
|
||||
|
|
@ -1014,7 +1014,7 @@ class FileHandler
|
|||
* @param string $dir Target dir path
|
||||
* @return bool Returns FALSE if the dir is not dir, or Returns full path of dir(string).
|
||||
*/
|
||||
function isDir($path)
|
||||
public static function isDir($path)
|
||||
{
|
||||
$path = self::getRealPath($path);
|
||||
return is_dir($path) ? $path : FALSE;
|
||||
|
|
@ -1026,7 +1026,7 @@ class FileHandler
|
|||
* @param string $path Target dir path
|
||||
* @return bool
|
||||
*/
|
||||
function isWritableDir($path)
|
||||
public static function isWritableDir($path)
|
||||
{
|
||||
$path = self::getRealPath($path);
|
||||
if(is_dir($path)==FALSE)
|
||||
|
|
|
|||
|
|
@ -238,4 +238,3 @@ class Mobile
|
|||
return ($db_info->use_mobile_view === 'Y');
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -477,7 +477,7 @@ class ModuleObject extends Object
|
|||
{
|
||||
if(Context::getResponseMethod() == 'XMLRPC' || Context::getResponseMethod() == 'JSON')
|
||||
{
|
||||
$oAPI = getAPI($this->module_info->module, 'api');
|
||||
$oAPI = getAPI($this->module_info->module);
|
||||
if(method_exists($oAPI, $this->act))
|
||||
{
|
||||
$oAPI->{$this->act}($this);
|
||||
|
|
|
|||
|
|
@ -12,6 +12,24 @@
|
|||
*/
|
||||
class Password
|
||||
{
|
||||
/**
|
||||
* @brief Custom algorithms are stored here
|
||||
* @var array
|
||||
*/
|
||||
protected static $_custom = array();
|
||||
|
||||
/**
|
||||
* @brief Register a custom algorithm for password checking
|
||||
* @param string $name The name of the algorithm
|
||||
* @param string $regexp The regular expression to detect the algorithm
|
||||
* @param callable $callback The function to call to regenerate the hash
|
||||
* @return void
|
||||
*/
|
||||
public static function registerCustomAlgorithm($name, $regexp, $callback)
|
||||
{
|
||||
self::$_custom[$name] = array('regexp' => $regexp, 'callback' => $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the list of hashing algorithms supported by this server
|
||||
* @return array
|
||||
|
|
@ -162,6 +180,16 @@ class Password
|
|||
return $this->strcmpConstantTime($hash_to_compare, $hash);
|
||||
|
||||
default:
|
||||
if($algorithm && isset(self::$_custom[$algorithm]))
|
||||
{
|
||||
$hash_callback = self::$_custom[$algorithm]['callback'];
|
||||
$hash_to_compare = $hash_callback($password, $hash);
|
||||
return $this->strcmpConstantTime($hash_to_compare, $hash);
|
||||
}
|
||||
if(in_array($algorithm, hash_algos()))
|
||||
{
|
||||
return $this->strcmpConstantTime(hash($algorithm, $password), $hash);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -173,6 +201,14 @@ class Password
|
|||
*/
|
||||
function checkAlgorithm($hash)
|
||||
{
|
||||
foreach(self::$_custom as $name => $definition)
|
||||
{
|
||||
if(preg_match($definition['regexp'], $hash))
|
||||
{
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
|
||||
if(preg_match('/^\$2[axy]\$([0-9]{2})\$/', $hash, $matches))
|
||||
{
|
||||
return 'bcrypt';
|
||||
|
|
@ -185,6 +221,22 @@ class Password
|
|||
{
|
||||
return 'md5';
|
||||
}
|
||||
elseif(strlen($hash) === 40 && ctype_xdigit($hash))
|
||||
{
|
||||
return 'sha1';
|
||||
}
|
||||
elseif(strlen($hash) === 64 && ctype_xdigit($hash))
|
||||
{
|
||||
return 'sha256';
|
||||
}
|
||||
elseif(strlen($hash) === 96 && ctype_xdigit($hash))
|
||||
{
|
||||
return 'sha384';
|
||||
}
|
||||
elseif(strlen($hash) === 128 && ctype_xdigit($hash))
|
||||
{
|
||||
return 'sha512';
|
||||
}
|
||||
elseif(strlen($hash) === 16 && ctype_xdigit($hash))
|
||||
{
|
||||
return 'mysql_old_password';
|
||||
|
|
@ -246,8 +298,13 @@ class Password
|
|||
$entropy_capped_bytes = min(32, $entropy_required_bytes);
|
||||
|
||||
// Find and use the most secure way to generate a random string
|
||||
$entropy = false;
|
||||
$is_windows = (defined('PHP_OS') && strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');
|
||||
if(function_exists('openssl_random_pseudo_bytes') && (!$is_windows || version_compare(PHP_VERSION, '5.4', '>=')))
|
||||
if(function_exists('random_bytes')) // PHP 7
|
||||
{
|
||||
$entropy = random_bytes($entropy_capped_bytes);
|
||||
}
|
||||
elseif(function_exists('openssl_random_pseudo_bytes') && (!$is_windows || version_compare(PHP_VERSION, '5.4', '>=')))
|
||||
{
|
||||
$entropy = openssl_random_pseudo_bytes($entropy_capped_bytes);
|
||||
}
|
||||
|
|
@ -262,10 +319,16 @@ class Password
|
|||
elseif(!$is_windows && @is_readable('/dev/urandom'))
|
||||
{
|
||||
$fp = fopen('/dev/urandom', 'rb');
|
||||
if (function_exists('stream_set_read_buffer')) // This function does not exist in HHVM
|
||||
{
|
||||
stream_set_read_buffer($fp, 0); // Prevent reading several KB of unnecessary data from urandom
|
||||
}
|
||||
$entropy = fread($fp, $entropy_capped_bytes);
|
||||
fclose($fp);
|
||||
}
|
||||
else
|
||||
|
||||
// Use built-in source of entropy if an error occurs while using other functions
|
||||
if($entropy === false || strlen($entropy) < $entropy_capped_bytes)
|
||||
{
|
||||
$entropy = '';
|
||||
for($i = 0; $i < $entropy_capped_bytes; $i += 2)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue