Authored by whb

清除工具

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