private static function cmd($cmd, $name, $ttl = 0) { if ('file' == getini('cache/cacher')) { return self::dblock($cmd, $name, $ttl); } return cache($cmd, 'process_' . $name, time(), $ttl); }
/** * @param $request * @param $response * @return mixed */ public function dispatching(Swoole\Request $request, Swoole\Response $response) { if (defined('ROUTE') && ROUTE) { $uri = $request->getRequestTarget(); $router = Route::parse_routes($uri); if ($router) { $_controllerName = array_shift($router); $_actionName = array_shift($router); } else { $_controllerName = $request->get(self::_dCTL) ?: getini('site/defaultController'); $_actionName = $request->get(self::_dACT) ?: getini('site/defaultAction'); } } else { $_controllerName = $request->get(self::_dCTL) ?: getini('site/defaultController'); $_actionName = $request->get(self::_dACT) ?: getini('site/defaultAction'); } $controllerName = preg_replace('/[^a-z0-9_]+/i', '', $_controllerName); $actionName = preg_replace('/[^a-z0-9_]+/i', '', $_actionName); if (defined('AUTH') && AUTH) { $allow = Rbac::check($controllerName, $actionName, AUTH); if (!$allow) { $this->response(' 你没有权限访问 ' . $controllerName . ' - ' . $actionName, 500, $response); return false; } } return $this->execute($controllerName, $actionName, $request, $response); }
public function clear() { $cachedir = getini('data/_cache'); $files = \Rsf\Helper\File::getInstance()->list_files($cachedir); foreach ($files as $file) { unlink($cachedir . $file); } return true; }
/** * @param array $data * @param int $code */ protected function repjson($data = [], $code = 200) { if ($code !== 200) { $this->response->withStatus($code, Http\Http::getStatus($code)); } $this->response->withHeader('Content-Type', 'application/json; charset=' . getini('site/charset')); $data = $data ? output_json($data) : ''; $this->response->write($data); }
public function __construct($cacher = null) { $this->config = getini('cache'); $this->prefix = $this->config['prefix']; $cacher = $cacher ?: $this->config['cacher']; if (in_array($cacher, array('file', 'memcache', 'redis', 'xcache'))) { $class = '\\Rsf\\Cache\\' . ucfirst($cacher); $this->cacher = $class::getInstance()->init(Context::dsn($cacher . '.cache')); $this->enable = $this->cacher->enable; $this->type = $cacher; } return $this; }
/** * @param $utimeoffset * @return array */ function loctime($utimeoffset) { static $dtformat = null, $timeoffset = 8; if (is_null($dtformat)) { $dtformat = ['d' => getini('settings/dateformat') ?: 'Y-m-d', 't' => getini('settings/timeformat') ?: 'H:i:s']; $dtformat['dt'] = $dtformat['d'] . ' ' . $dtformat['t']; $timeoffset = getini('settings/timezone') ?: $timeoffset; //defualt is Asia/Shanghai } $offset = $utimeoffset == 999 ? $timeoffset : $utimeoffset; return [$offset, $dtformat]; }
/** * @param $file * @return string */ function template($file) { $_tplid = getini('site/themes'); $tplfile = $_tplid . '/' . $file . '.htm'; $cachefile = strtolower(APPKEY) . '_' . $_tplid . '_' . str_replace('/', '_', $file) . '_tpl.php'; $cachetpl = getini('data/_view') . $cachefile; $cachetime = is_file($cachetpl) ? filemtime($cachetpl) : 0; checktplrefresh($tplfile, $tplfile, $cachetime, $cachefile, $file); ob_get_length() && ob_clean(); ob_start(); return $cachetpl; }
/** * @param $controllerName * @return null * @throws Exception\Exception */ private static function _getACT($controllerName) { static $globalAcl = []; if (empty($globalAcl)) { $jsonacl = (include getini('data/_acl') . strtolower(APPKEY) . 'ACT.php'); if (!$jsonacl) { throw new Exception\Exception('ACL文件不存在'); } $globalAcl = json_decode($jsonacl, true); } if (isset($globalAcl[$controllerName])) { return $globalAcl[$controllerName]; } return null; }
/** * @param $string * @param string $operation * @param string $key * @param int $expiry * @return string */ public static function authCode($string, $operation = 'DECODE', $key = '', $expiry = 0) { static $hash_auth = null; if (is_null($hash_auth)) { $hash_key = getini('auth/key') ?: PHP_VERSION; $hash_auth = md5($hash_key . PHP_VERSION); } $timestamp = time(); $ckey_length = 4; $_key = md5($key ?: $hash_auth); $keya = md5(substr($_key, 0, 16)); $keyb = md5(substr($_key, 16, 16)); $keyc = $ckey_length ? 'DECODE' == $operation ? substr($string, 0, $ckey_length) : substr(md5(microtime()), -$ckey_length) : ''; $cryptkey = $keya . md5($keya . $keyc); $key_length = strlen($cryptkey); $_string = 'DECODE' == $operation ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + $timestamp : 0) . substr(md5($string . $keyb), 0, 16) . $string; $string_length = strlen($_string); $result = ''; $box = range(0, 255); $rndkey = []; for ($i = 0; $i <= 255; $i++) { $rndkey[$i] = ord($cryptkey[$i % $key_length]); } for ($j = $i = 0; $i < 256; $i++) { $j = ($j + $box[$i] + $rndkey[$i]) % 256; $tmp = $box[$i]; $box[$i] = $box[$j]; $box[$j] = $tmp; } for ($a = $j = $i = 0; $i < $string_length; $i++) { $a = ($a + 1) % 256; $j = ($j + $box[$a]) % 256; $tmp = $box[$a]; $box[$a] = $box[$j]; $box[$j] = $tmp; $result .= chr(ord($_string[$i]) ^ $box[($box[$a] + $box[$j]) % 256]); } if ('DECODE' == $operation) { if ((0 == substr($result, 0, 10) || substr($result, 0, 10) - $timestamp > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26) . $keyb), 0, 16)) { return substr($result, 26); } return ''; } return $keyc . str_replace('=', '', base64_encode($result)); }