1
0
mirror of https://github.com/ZeroDream-CN/PHPMC7 synced 2024-11-28 07:32:55 +08:00
PHPMC7/include/loader.php

205 lines
7.0 KiB
PHP
Raw Normal View History

2018-09-10 14:53:00 +08:00
<?php
include(ROOT . "/include/core/PHPMC/Main.php");
include(ROOT . "/include/data/config.php");
// 想来想去还是在这里加载语言设置比较合适
$Lang = new Lang();
$Option = new Option();
$result = $Option->getOption("Lang");
$result = $result == "" ? "zh-CN" : $result;
$Lang->setLang($result);
2018-09-10 14:53:00 +08:00
class Loader {
public $Event;
public function __construct() {
global $Lang;
$this->Event = new Event();
}
2018-09-10 14:53:00 +08:00
/**
*
* 页面框架显示控制函数
*
**/
public function frame() {
global $Lang;
2018-09-10 14:53:00 +08:00
echo $this->loadPage("panel.html", ROOT . "/content/" . Config::Theme() . "/");
}
/**
*
* 页面加载函数
*
* $pageName 页面文件名
*
* $pagePath 页面所在路径
*
**/
public function loadPage($pageName, $pagePath) {
global $Lang;
2018-09-10 14:53:00 +08:00
SESSION_START();
$Option = new Option();
$Profile = new Profile($_SESSION["user"]);
if(!file_exists($pagePath . $pageName)) {
$pageName = "404.html";
$pagePath = ROOT . "/content/" . $Option->getOption("Theme") . "/error/";
}
if(!PHPMC::User()->isLogin() && $pageName !== "login.html" && $pageName !== "404.html" && $pageName !== "403.html") {
$pageName = "login.html";
$pagePath = ROOT . "/content/" . $Option->getOption("Theme") . "/";
2018-09-10 14:53:00 +08:00
}
$str = file_get_contents($pagePath . $pageName);
$str = str_replace("{CONTENTDIR}", "./content", $str);
$str = str_replace("{USERNAME}", $Profile->username, $str);
$str = str_replace("{USERMAIL}", $Profile->email, $str);
$str = str_replace("{AVATAR_HASH}", md5($Profile->email), $str);
$str = str_replace("{CSRF_TOKEN}", $_SESSION['token'], $str);
2018-09-10 14:53:00 +08:00
preg_match_all("/\{User\:(.*)\}/U", $str, $arr);
for($i = 0;$i < count($arr[0]);$i++) {
$User = new User();
$str = str_replace($arr[0][$i], call_user_func(Array($User, $arr[1][$i])), $str);
}
preg_match_all("/\{Daemon\:(.*)\}/U", $str, $arr);
for($i = 0;$i < count($arr[0]);$i++) {
$Daemon = new Daemon();
$str = str_replace($arr[0][$i], call_user_func(Array($Daemon, $arr[1][$i])), $str);
}
preg_match_all("/\{Server\:(.*)\}/U", $str, $arr);
for($i = 0;$i < count($arr[0]);$i++) {
$Server = new Server();
$str = str_replace($arr[0][$i], call_user_func(Array($Server, $arr[1][$i])), $str);
}
preg_match_all("/\{System\:(.*)\}/U", $str, $arr);
for($i = 0;$i < count($arr[0]);$i++) {
$System = new System();
$str = str_replace($arr[0][$i], call_user_func(Array($System, $arr[1][$i])), $str);
}
preg_match_all("/\{Option\:(.*)\}/U", $str, $arr);
for($i = 0;$i < count($arr[0]);$i++) {
$str = str_replace($arr[0][$i], $Option->getOption($arr[1][$i]), $str);
}
preg_match_all("/\{\{(.*)\}\}/U", $str, $arr);
for($i = 0;$i < count($arr[0]);$i++) {
$code = "return {$arr[1][$i]}; ";
$str = str_replace($arr[0][$i], eval($code), $str);
}
return $str;
}
/**
*
* 页面主路由函数
*
**/
public function router() {
global $Lang;
if(PHPMC::Csrf()->isemptyCsrfToken()) {
PHPMC::Csrf()->createCsrfToken();
}
2018-09-10 14:53:00 +08:00
$Option = new Option();
if(preg_match("/^[A-Za-z0-9\-\_]+$/", $_GET["page"])) {
PHPMC::Permission()->checkSession("page:" . $_GET['page']);
$this->Event->EventHandle("viewPageEvent", array($_GET));
2018-09-10 14:53:00 +08:00
exit;
} elseif($_GET['action']) {
switch($_GET['action']) {
case 'login':
if(!PHPMC::Csrf()->verifyCsrfToken($_POST)) {
PHPMC::Error()->Println("Csrf 验证失败,请刷新页面重试。");
}
$this->Event->EventHandle("LoginEvent", array($_POST));
2018-09-10 14:53:00 +08:00
break;
case 'logout':
$this->Event->EventHandle("LogoutEvent", array());
2018-09-10 14:53:00 +08:00
break;
case 'getserver':
PHPMC::Permission()->checkSession("server:" . $_GET['id']);
$this->Event->EventHandle("getServerEvent", array($_GET));
2018-09-10 14:53:00 +08:00
break;
case 'start':
PHPMC::Permission()->checkSession("server:" . $_GET['id']);
$this->Event->EventHandle("startServerEvent", array($_GET));
2018-09-10 14:53:00 +08:00
break;
case 'stop':
PHPMC::Permission()->checkSession("server:" . $_GET['id']);
$this->Event->EventHandle("stopServerEvent", array($_GET));
2018-09-10 14:53:00 +08:00
break;
case 'restart':
PHPMC::Permission()->checkSession("server:" . $_GET['id']);
$this->Event->EventHandle("restartServerEvent", array($_GET));
2018-09-10 14:53:00 +08:00
break;
case 'sendcommand':
PHPMC::Permission()->checkSession("server:" . $_GET['id']);
$this->Event->EventHandle("onCommandEvent", array($_GET));
2018-09-10 14:53:00 +08:00
break;
case 'status':
PHPMC::Permission()->checkSession("server:" . $_GET['id']);
$this->Event->EventHandle("getStatusEvent", array($_GET));
2018-09-10 14:53:00 +08:00
break;
case 'getserverinfo':
PHPMC::Permission()->checkSession("server:" . $_GET['id']);
$this->Event->EventHandle("getServerInfoEvent", array($_GET));
2018-09-10 14:53:00 +08:00
break;
case 'getdaemoninfo':
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
$this->Event->EventHandle("getDaemonInfoEvent", array($_GET));
2018-09-10 14:53:00 +08:00
break;
case 'getuserinfo':
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
$this->Event->EventHandle("getUserInfoEvent", array($_GET));
2018-09-10 14:53:00 +08:00
break;
case 'saveconfig':
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
$this->Event->EventHandle("saveConfigEvent", array($_GET));
2018-09-10 14:53:00 +08:00
break;
case 'createserver':
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
$this->Event->EventHandle("createServerEvent", array($_GET));
2018-09-10 14:53:00 +08:00
break;
case 'updateserver':
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
$this->Event->EventHandle("updateServerEvent", array($_GET));
2018-09-10 14:53:00 +08:00
break;
case 'deleteserver':
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
$this->Event->EventHandle("deleteServerEvent", array($_GET));
2018-09-10 14:53:00 +08:00
break;
case 'createdaemon':
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
$this->Event->EventHandle("createDaemonEvent", array($_GET));
2018-09-10 14:53:00 +08:00
break;
case 'updatedaemon':
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
$this->Event->EventHandle("updateDaemonEvent", array($_GET));
2018-09-10 14:53:00 +08:00
break;
case 'deletedaemon':
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
$this->Event->EventHandle("deleteDaemonEvent", array($_GET));
2018-09-10 14:53:00 +08:00
break;
case 'createuser':
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
$this->Event->EventHandle("createUserEvent", array($_GET));
2018-09-10 14:53:00 +08:00
break;
case 'updateuser':
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
$this->Event->EventHandle("updateUserEvent", array($_GET));
2018-09-10 14:53:00 +08:00
break;
case 'deleteuser':
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
$this->Event->EventHandle("deleteUserEvent", array($_GET));
2018-09-10 14:53:00 +08:00
break;
case 'update':
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
$this->Event->EventHandle("updateEvent", array());
break;
2018-09-10 14:53:00 +08:00
default:
$this->Event->EventHandle("defaultActionEvent", array($_GET));
2018-09-10 14:53:00 +08:00
}
exit;
} elseif(empty($_GET['page'])) {
$this->Event->EventHandle("defaultPageEvent", array($_GET));
2018-09-10 14:53:00 +08:00
}
}
}