Tools.php
1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
use Action\WebAction;
use WebPlugin\Cache;
use Configs\CacheConfig;
use WebPlugin\AuthCode;
class ToolsController extends WebAction
{
public function init()
{
$valid_passwords = array ('test' => '123456');
$valid_users = array_keys($valid_passwords);
$user = $pass = '';
if(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_USER']))
{
$user = $_SERVER['PHP_AUTH_USER'];
$pass = $_SERVER['PHP_AUTH_PW'];
}
$validated = (in_array($user, $valid_users)) && ($pass == $valid_passwords[$user]);
if (!$validated) {
header('WWW-Authenticate: Basic realm="www.yohobuy.com"');
header('HTTP/1.0 401 Unauthorized');
die ("Not authorized");
}
}
/**
* 缓存html
*
*/
public function cacheAction()
{
//频道=>key
$channels = array(
'男生首页'=> CacheConfig::KEY_WEB_HOME_CHANNEL_DATA.'_boys',
'女生首页'=> CacheConfig::KEY_WEB_HOME_CHANNEL_DATA.'_girls',
'kids首页'=> CacheConfig::KEY_WEB_HOME_CHANNEL_DATA.'_kids',
'lifestyle首页'=> CacheConfig::KEY_WEB_HOME_CHANNEL_DATA.'_lifestyle',
);
$html = '';
foreach ($channels as $key => $val) {
$url = '/tools/cacheclear?key='.AuthCode::encode($val, 'yohobuy');
$html.= sprintf('<li><a href="%s" target="_blank">清除%s缓存</a></li>',$url, $key);
}
echo $html;
}
/**
* 清除缓存
*
* @return json
*/
public function cacheclearAction()
{
$key = $this->get('key');
if(!empty($key)) {
AuthCode::decode($key, 'yohobuy');
if(!empty($key)) {
Cache::delete($key);
echo '清除成功';
}
}
}
}
?>