2018-09-10 14:53:00 +08:00
|
|
|
<?php
|
|
|
|
include(ROOT . "/include/core/PHPMC/Main.php");
|
|
|
|
include(ROOT . "/include/data/config.php");
|
|
|
|
class Loader {
|
|
|
|
|
2018-09-16 01:49:48 +08:00
|
|
|
public $Event;
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
$this->Event = new Event();
|
|
|
|
}
|
|
|
|
|
2018-09-10 14:53:00 +08:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* 页面框架显示控制函数
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
public function frame() {
|
|
|
|
echo $this->loadPage("panel.html", ROOT . "/content/" . Config::Theme() . "/");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* 页面加载函数
|
|
|
|
*
|
|
|
|
* $pageName 页面文件名
|
|
|
|
*
|
|
|
|
* $pagePath 页面所在路径
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
public function loadPage($pageName, $pagePath) {
|
|
|
|
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";
|
2018-09-16 01:49:48 +08:00
|
|
|
$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);
|
2018-09-15 13:25:18 +08:00
|
|
|
$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() {
|
2018-09-15 13:25:18 +08:00
|
|
|
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']);
|
2018-09-16 01:49:48 +08:00
|
|
|
$this->Event->EventHandle("viewPageEvent", array($_GET));
|
2018-09-10 14:53:00 +08:00
|
|
|
exit;
|
|
|
|
} elseif($_GET['action']) {
|
|
|
|
switch($_GET['action']) {
|
|
|
|
case 'login':
|
2018-09-15 13:25:18 +08:00
|
|
|
if(!PHPMC::Csrf()->verifyCsrfToken($_POST)) {
|
|
|
|
PHPMC::Error()->Println("Csrf 验证失败,请刷新页面重试。");
|
|
|
|
}
|
2018-09-16 01:49:48 +08:00
|
|
|
$this->Event->EventHandle("LoginEvent", array($_POST));
|
2018-09-10 14:53:00 +08:00
|
|
|
break;
|
|
|
|
case 'logout':
|
2018-09-16 01:49:48 +08:00
|
|
|
$this->Event->EventHandle("LogoutEvent", array());
|
2018-09-10 14:53:00 +08:00
|
|
|
break;
|
|
|
|
case 'getserver':
|
|
|
|
PHPMC::Permission()->checkSession("server:" . $_GET['id']);
|
2018-09-16 01:49:48 +08:00
|
|
|
$this->Event->EventHandle("getServerEvent", array($_GET));
|
2018-09-10 14:53:00 +08:00
|
|
|
break;
|
|
|
|
case 'start':
|
|
|
|
PHPMC::Permission()->checkSession("server:" . $_GET['id']);
|
2018-09-16 01:49:48 +08:00
|
|
|
$this->Event->EventHandle("startServerEvent", array($_GET));
|
2018-09-10 14:53:00 +08:00
|
|
|
break;
|
|
|
|
case 'stop':
|
|
|
|
PHPMC::Permission()->checkSession("server:" . $_GET['id']);
|
2018-09-16 01:49:48 +08:00
|
|
|
$this->Event->EventHandle("stopServerEvent", array($_GET));
|
2018-09-10 14:53:00 +08:00
|
|
|
break;
|
|
|
|
case 'restart':
|
|
|
|
PHPMC::Permission()->checkSession("server:" . $_GET['id']);
|
2018-09-16 01:49:48 +08:00
|
|
|
$this->Event->EventHandle("restartServerEvent", array($_GET));
|
2018-09-10 14:53:00 +08:00
|
|
|
break;
|
|
|
|
case 'sendcommand':
|
|
|
|
PHPMC::Permission()->checkSession("server:" . $_GET['id']);
|
2018-09-16 01:49:48 +08:00
|
|
|
$this->Event->EventHandle("onCommandEvent", array($_GET));
|
2018-09-10 14:53:00 +08:00
|
|
|
break;
|
|
|
|
case 'status':
|
|
|
|
PHPMC::Permission()->checkSession("server:" . $_GET['id']);
|
2018-09-16 01:49:48 +08:00
|
|
|
$this->Event->EventHandle("getStatusEvent", array($_GET));
|
2018-09-10 14:53:00 +08:00
|
|
|
break;
|
|
|
|
case 'getserverinfo':
|
|
|
|
PHPMC::Permission()->checkSession("server:" . $_GET['id']);
|
2018-09-16 01:49:48 +08:00
|
|
|
$this->Event->EventHandle("getServerInfoEvent", array($_GET));
|
2018-09-10 14:53:00 +08:00
|
|
|
break;
|
|
|
|
case 'getdaemoninfo':
|
|
|
|
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
|
2018-09-16 01:49:48 +08:00
|
|
|
$this->Event->EventHandle("getDaemonInfoEvent", array($_GET));
|
2018-09-10 14:53:00 +08:00
|
|
|
break;
|
|
|
|
case 'getuserinfo':
|
|
|
|
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
|
2018-09-16 01:49:48 +08:00
|
|
|
$this->Event->EventHandle("getUserInfoEvent", array($_GET));
|
2018-09-10 14:53:00 +08:00
|
|
|
break;
|
|
|
|
case 'saveconfig':
|
|
|
|
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
|
2018-09-16 01:49:48 +08:00
|
|
|
$this->Event->EventHandle("saveConfigEvent", array($_GET));
|
2018-09-10 14:53:00 +08:00
|
|
|
break;
|
|
|
|
case 'createserver':
|
|
|
|
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
|
2018-09-16 01:49:48 +08:00
|
|
|
$this->Event->EventHandle("createServerEvent", array($_GET));
|
2018-09-10 14:53:00 +08:00
|
|
|
break;
|
|
|
|
case 'updateserver':
|
|
|
|
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
|
2018-09-16 01:49:48 +08:00
|
|
|
$this->Event->EventHandle("updateServerEvent", array($_GET));
|
2018-09-10 14:53:00 +08:00
|
|
|
break;
|
|
|
|
case 'deleteserver':
|
|
|
|
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
|
2018-09-16 01:49:48 +08:00
|
|
|
$this->Event->EventHandle("deleteServerEvent", array($_GET));
|
2018-09-10 14:53:00 +08:00
|
|
|
break;
|
|
|
|
case 'createdaemon':
|
|
|
|
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
|
2018-09-16 01:49:48 +08:00
|
|
|
$this->Event->EventHandle("createDaemonEvent", array($_GET));
|
2018-09-10 14:53:00 +08:00
|
|
|
break;
|
|
|
|
case 'updatedaemon':
|
|
|
|
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
|
2018-09-16 01:49:48 +08:00
|
|
|
$this->Event->EventHandle("updateDaemonEvent", array($_GET));
|
2018-09-10 14:53:00 +08:00
|
|
|
break;
|
|
|
|
case 'deletedaemon':
|
|
|
|
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
|
2018-09-16 01:49:48 +08:00
|
|
|
$this->Event->EventHandle("deleteDaemonEvent", array($_GET));
|
2018-09-10 14:53:00 +08:00
|
|
|
break;
|
|
|
|
case 'createuser':
|
|
|
|
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
|
2018-09-16 01:49:48 +08:00
|
|
|
$this->Event->EventHandle("createUserEvent", array($_GET));
|
2018-09-10 14:53:00 +08:00
|
|
|
break;
|
|
|
|
case 'updateuser':
|
|
|
|
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
|
2018-09-16 01:49:48 +08:00
|
|
|
$this->Event->EventHandle("updateUserEvent", array($_GET));
|
2018-09-10 14:53:00 +08:00
|
|
|
break;
|
|
|
|
case 'deleteuser':
|
|
|
|
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
|
2018-09-16 01:49:48 +08:00
|
|
|
$this->Event->EventHandle("deleteUserEvent", array($_GET));
|
2018-09-10 14:53:00 +08:00
|
|
|
break;
|
2018-09-15 05:31:23 +08:00
|
|
|
case 'update':
|
|
|
|
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
|
2018-09-16 01:49:48 +08:00
|
|
|
$this->Event->EventHandle("updateEvent", array());
|
2018-09-15 05:31:23 +08:00
|
|
|
break;
|
2018-09-10 14:53:00 +08:00
|
|
|
default:
|
2018-09-16 01:49:48 +08:00
|
|
|
$this->Event->EventHandle("defaultActionEvent", array($_GET));
|
2018-09-10 14:53:00 +08:00
|
|
|
}
|
|
|
|
exit;
|
|
|
|
} elseif(empty($_GET['page'])) {
|
2018-09-16 01:49:48 +08:00
|
|
|
$this->Event->EventHandle("defaultPageEvent", array($_GET));
|
2018-09-10 14:53:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|