<?php
/*
 * @Author: 刘晓飞
 * @Date: 2021-10-31 10:59:16
 * @LastEditTime: 2022-08-22 14:53:36
 * @LastEditors: 刘晓飞
 * @Description: 
 * @FilePath: \yunyecms_v218\wwwroot\public\ueditor\php\controller.php
 * 
 */
//header('Access-Control-Allow-Origin: http://www.baidu.com'); //设置http://www.baidu.com允许跨域访问
//header('Access-Control-Allow-Headers: X-Requested-With,X_Requested_With'); //设置允许的跨域header
ini_set("display_errors","Off");
error_reporting(0);
define('IN_YUNYECMS',true);
define('IN_YUNYECMSAdmin',true);
require '../../../core/config/const.php';
require YUNYECMS_CORE.'init.php';
core::load_fun('core');
core::load_fun('content');
core::load_admin_class('admin');
$db=core::load_model('content_model');
IsAdmLogin($db);
function IsAdmLogin($db,$uid=0,$username='',$rnd=''){
	if(ROUTE_C != 'login'){
	$userid=$uid?$uid:ugetcookie('admuserid',1);
	$username=$username?$username:ugetcookie('admusername',1);
	$rnd=$rnd?$rnd:ugetcookie('admloginrnd',1);
	$userid=(int)$userid;
	$username=usafestr($username);

	if(!$userid||!$username||!$rnd)
	{
        messagebox(Lan('adminlogin_notlogin'),url_admin('init','login'),"warn","top");	

	}
	$roleid=(int)ugetcookie('admroleid',1);
	$truelogintime=(int)ugetcookie('admlogintruetime',1);
	//COOKIE验证
	//YUNYECMS_CHECKCookieRnd($userid,$username,$rnd,$roleid,$truelogintime);
	//db
	$cuser=$db->find("select userid,roleid,catid,rnd,realname from `#yunyecms_user` where userid='$userid' and username='".$username."' and rnd='".$rnd."' and status=1 limit 1");
	if(!$cuser['userid'])
	{
		 messagebox(Lan('adminlogin_SingleUser'),url_admin('init','login'),"warn","top");
	}

	//登陆超时
	$logintime=ugetcookie('admlogintime',1);
	if($logintime)
	{
		if(time()-$logintime>ADMLOGIN_OVERTIME*60)
		{
			usetcookie("admloginrnd","",1);
		    messagebox(Lan('adminlogin_overtime'),url_admin('init','login'),"info","top");	
	    }
		usetcookie("admlogintime",time(),1);
	}
	if(ugetcookie('admloginlicense',1)!="yunyecmslicense")
	{
		  messagebox(Lan('adminlogin_notlogin'),url_admin('init','login'),"warn","top");	
	}
	$admuser['userid']=$userid;
	$admuser['username']=$username;
	$admuser['rnd']=$rnd;
	$admuser['roleid']=$cuser['roleid'];
	$admuser['catid']=$cuser['catid'];
	return $admuser;
	}else{
	 return 0;
		}
    }



$CONFIG = json_decode(preg_replace("/\/\*[\s\S]+?\*\//", "", file_get_contents("config.json")), true);
$action = $_GET['action'];

switch ($action) {
    case 'config':
        $result =  json_encode($CONFIG);
        break;

    /* 上传图片 */
    case 'uploadimage':
    /* 上传涂鸦 */
    case 'uploadscrawl':
    /* 上传视频 */
    case 'uploadvideo':
    /* 上传文件 */
    case 'uploadfile':
        $result = include("action_upload.php");
        break;

    /* 列出图片 */
    case 'listimage':
        $result = include("action_list.php");
        break;
    /* 列出文件 */
    case 'listfile':
        $result = include("action_list.php");
        break;

    /* 抓取远程文件 */
    case 'catchimage':
        $result = include("action_crawler.php");
        break;

    default:
        $result = json_encode(array(
            'state'=> '请求地址出错'
        ));
        break;
}

/* 输出结果 */
if (isset($_GET["callback"])) {
    if (preg_match("/^[\w_]+$/", $_GET["callback"])) {
        echo htmlspecialchars($_GET["callback"]) . '(' . $result . ')';
    } else {
        echo json_encode(array(
            'state'=> 'callback参数不合法'
        ));
    }
} else {
    echo $result;
}