controller.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. header("Access-Control-Allow-Origin: *");//允许跨域
  3. header('Access-Control-Allow-Headers: X-Requested-With,X_Requested_With'); //设置允许的跨域header
  4. //date_default_timezone_set("Asia/chongqing");
  5. error_reporting(E_ERROR);
  6. header("Content-Type: text/html; charset=utf-8");
  7. if(isset($_GET['auth_key'])){
  8. define('AUTH_KEY',urldecode($_GET['auth_key']));
  9. }
  10. else
  11. {
  12. exit("缺少解密秘钥");
  13. }
  14. if(isset($_GET['base_path']))define('BASE_PATH',decode_path($_GET['base_path'],'DECODE'));
  15. if(isset($_GET['app_path']))define('APP_PATH',decode_path($_GET['app_path'],'DECODE'));
  16. if(isset($_GET['upload_path']))define('UPLOAD_PATH',decode_path($_GET['upload_path'],'DECODE'));
  17. $config = require_once BASE_PATH.'config'.DIRECTORY_SEPARATOR.'config.php';
  18. require BASE_PATH . 'vendor/autoload.php';
  19. require BASE_PATH . 'vendor/yiisoft/yii2/Yii.php';
  20. require_once BASE_PATH.'common'.DIRECTORY_SEPARATOR.'functions'.DIRECTORY_SEPARATOR.'global.php';
  21. require_once BASE_PATH.'common'.DIRECTORY_SEPARATOR.'functions'.DIRECTORY_SEPARATOR.'cus.php';
  22. require_once BASE_PATH.'common'.DIRECTORY_SEPARATOR.'functions'.DIRECTORY_SEPARATOR.'dir.php';
  23. defined('MYIP') or define('MYIP',ip());
  24. $domain = require_config('domain.php');
  25. define('COOKIE_DOMAIN', $domain['cookie_domain']);//定义cookie全局域
  26. define('WAP_URL', $domain['wap_url']);//WAP站域名
  27. define('WEB_URL', $domain['web_url']);//站点域名
  28. define('UPLOAD_DOMAIN', $domain['upload_domain']);//附件域名
  29. $config = array_merge_recursive(require_config('web.php'), $config);
  30. defined('UPLOAD_URL') or define('UPLOAD_URL',$config['params']['uploadUrl']);
  31. //主机协议
  32. define('SITE_PROTOCOL', isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://');
  33. new yii\web\Application($config);
  34. $ueditorConfig = $config['ueditor'];
  35. $CONFIG = json_decode(preg_replace("/\/\*[\s\S]+?\*\//", "", file_get_contents("config.json")), true);
  36. if(is_array($ueditorConfig))foreach($ueditorConfig as $key=>$value)//获取自定义配置
  37. {
  38. if(strpos($value,'|'))
  39. {
  40. $temp = explode('|',$value);
  41. $temp = ".".join('|.',$temp);
  42. $temp = explode('|',$temp);
  43. $CONFIG[$key] = $temp;
  44. }
  45. else
  46. {
  47. $CONFIG[$key] = $value;
  48. }
  49. }
  50. $action = $_GET['action'];
  51. switch ($action) {
  52. case 'config':
  53. $result = json_encode($CONFIG);
  54. break;
  55. /* 上传图片 */
  56. case 'uploadimage':
  57. /* 上传涂鸦 */
  58. case 'uploadscrawl':
  59. /* 上传视频 */
  60. case 'uploadvideo':
  61. /* 上传文件 */
  62. case 'uploadfile':
  63. $result = include("action_upload.php");
  64. break;
  65. /* 列出图片 */
  66. case 'listimage':
  67. $result = include("action_list.php");
  68. break;
  69. /* 列出文件 */
  70. case 'listfile':
  71. $result = include("action_list.php");
  72. break;
  73. /* 抓取远程文件 */
  74. case 'catchimage':
  75. $result = include("action_crawler.php");
  76. break;
  77. default:
  78. $result = json_encode(array(
  79. 'state'=> '请求地址出错'
  80. ));
  81. break;
  82. }
  83. /* 输出结果 */
  84. if (isset($_GET["callback"])) {
  85. if (preg_match("/^[\w_]+$/", $_GET["callback"])) {
  86. echo htmlspecialchars($_GET["callback"]) . '(' . $result . ')';
  87. } else {
  88. echo json_encode(array(
  89. 'state'=> 'callback参数不合法'
  90. ));
  91. }
  92. } else {
  93. echo $result;
  94. }
  95. /**
  96. * 字符串加密、解密函数
  97. * @param string $txt 字符串
  98. * @param string $operation ENCODE为加密,DECODE为解密,可选参数,默认为ENCODE,
  99. * @param string $key 密钥:数字、字母、下划线
  100. * @param string $expiry 过期时间
  101. * @return string
  102. *
  103. */
  104. function decode_path($string, $operation = 'ENCODE', $key = '', $expiry = 0) {
  105. $key_length = 4;
  106. $key = md5($key != '' ? $key : AUTH_KEY);
  107. $fixedkey = md5($key);
  108. $egiskeys = md5(substr($fixedkey, 16, 16));
  109. $runtokey = $key_length ? ($operation == 'ENCODE' ? substr(md5(microtime(true)), -$key_length) : substr($string, 0, $key_length)) : '';
  110. $keys = md5(substr($runtokey, 0, 16) . substr($fixedkey, 0, 16) . substr($runtokey, 16) . substr($fixedkey, 16));
  111. $string = $operation == 'ENCODE' ? sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$egiskeys), 0, 16) . $string : base64_decode(substr($string, $key_length));
  112. $i = 0; $result = '';
  113. $string_length = strlen($string);
  114. for ($i = 0; $i < $string_length; $i++){
  115. $result .= chr(ord($string{$i}) ^ ord($keys{$i % 32}));
  116. }
  117. if($operation == 'ENCODE') {
  118. return $runtokey . str_replace('=', '', base64_encode($result));
  119. } else {
  120. if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$egiskeys), 0, 16)) {
  121. return substr($result, 26);
  122. } else {
  123. return '';
  124. }
  125. }
  126. }