mirror of https://github.com/ZeroDream-CN/PHPMC7
parent
3117402098
commit
f06e0bcb30
|
@ -4,7 +4,7 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{SITENAME} - Minecraft 服务器管理面板</title>
|
||||
<title>{Option:SiteName} - {Option:Description}</title>
|
||||
<meta name="keywords" content="<block name='keywords'>">
|
||||
<meta name="description" content="<block name='description'>">
|
||||
<link rel="shortcut icon" href="{CONTENTDIR}/{THEME}/assets/favicon.ico">
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{SITENAME} - Minecraft 服务器管理面板</title>
|
||||
<title>{Option:SiteName} - {Option:Description}</title>
|
||||
<meta name="keywords" content="<block name='keywords'>">
|
||||
<meta name="description" content="<block name='description'>">
|
||||
<link rel="shortcut icon" href="{CONTENTDIR}/{THEME}/assets/favicon.ico">
|
||||
|
|
|
@ -1,6 +1,64 @@
|
|||
<?php
|
||||
class Event {
|
||||
|
||||
public $eventList;
|
||||
|
||||
public function registerClass($name, $class) {
|
||||
$arr = $this->eventList;
|
||||
$plug_one = @count($arr[$name]);
|
||||
$arr[$name][$plug_one] = $class;
|
||||
$this->eventList = $arr;
|
||||
}
|
||||
|
||||
public function EventHandle($name, $args) {
|
||||
try {
|
||||
// 如果此事件已经注册
|
||||
if(isset($this->eventList[$name])) {
|
||||
$breaked = false;
|
||||
// 遍历事件列表,将每个插件的事件处理函数执行一次
|
||||
foreach($this->eventList[$name] as $class) {
|
||||
$rs = call_user_func_array(array($class, $name), $args);
|
||||
// 如果事件被取消
|
||||
if($rs == true) {
|
||||
$breaked = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 如果事件未被取消
|
||||
if(!$breaked) {
|
||||
@call_user_func_array(array($this, $name), $args);
|
||||
}
|
||||
} else {
|
||||
// 如果事件未注册
|
||||
call_user_func_array(array($this, $name), $args);
|
||||
}
|
||||
} catch(Exception $ex) {
|
||||
// 出错时
|
||||
call_user_func_array(array($this, $name), $args);
|
||||
}
|
||||
}
|
||||
|
||||
public function defaultActionEvent($data) {
|
||||
$Loader = new Loader();
|
||||
$Option = new Option();
|
||||
echo $Loader->loadPage("404.html", ROOT . "/content/" . $Option->getOption("Theme") . "/error/");
|
||||
exit;
|
||||
}
|
||||
|
||||
public function defaultPageEvent($data) {
|
||||
$Loader = new Loader();
|
||||
$Option = new Option();
|
||||
echo $Loader->loadPage("panel.html", ROOT . "/content/" . $Option->getOption("Theme") . "/");
|
||||
exit;
|
||||
}
|
||||
|
||||
public function viewPageEvent($data) {
|
||||
$Loader = new Loader();
|
||||
$Option = new Option();
|
||||
echo $Loader->loadPage($data["page"] . ".html", ROOT . "/content/" . $Option->getOption("Theme") . "/");
|
||||
exit;
|
||||
}
|
||||
|
||||
public function LoginEvent($Data) {
|
||||
if(preg_match("/^[A-Za-z0-9\-\_]+$/", $Data['username'])) {
|
||||
if(PHPMC::User()->Login($Data['username'], $Data['password'])) {
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
<?php
|
||||
define("PHPMC_VERSION", "7.3.2105"); // Don't Change This!
|
||||
// PHPMC 7 Version define
|
||||
// Don't change this, because it will interfere your update.
|
||||
define("PHPMC_VERSION", "7.3.3156");
|
||||
|
||||
include(ROOT . "/include/core/PHPMC/Event.php");
|
||||
include(ROOT . "/include/core/PHPMC/User.php");
|
||||
include(ROOT . "/include/core/PHPMC/Utils.php");
|
||||
|
@ -13,7 +16,10 @@ include(ROOT . "/include/core/PHPMC/Option.php");
|
|||
include(ROOT . "/include/core/PHPMC/Permission.php");
|
||||
include(ROOT . "/include/core/PHPMC/Update.php");
|
||||
include(ROOT . "/include/core/PHPMC/Csrf.php");
|
||||
include(ROOT . "/include/core/PHPMC/Plugin.php");
|
||||
|
||||
class PHPMC {
|
||||
|
||||
public static function Event() {
|
||||
return new Event();
|
||||
}
|
||||
|
@ -54,6 +60,10 @@ class PHPMC {
|
|||
return new Update();
|
||||
}
|
||||
|
||||
public static function Plugin() {
|
||||
return new Plugin();
|
||||
}
|
||||
|
||||
public static function Error() {
|
||||
return new WebError();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
class Plugin {
|
||||
|
||||
public function __construct() {
|
||||
if(!file_exists("plugins/")) {
|
||||
mkdir("plugins/", 0775);
|
||||
}
|
||||
}
|
||||
|
||||
public function load($path = "./") {
|
||||
$realpath = realpath($path);
|
||||
$handle = opendir($path);
|
||||
while($file = readdir($handle)) {
|
||||
if($file !== "." && $file !== ".." && pathinfo($file)['extension'] == "php") {
|
||||
$target = pathinfo($file)['filename'] . ".json";
|
||||
$data = $this->pluginReader("{$realpath}/{$target}");
|
||||
$info = json_decode($data, true);
|
||||
if(!$info) {
|
||||
PHPMC::Error()->Println("Error when load plugin: " . $file . ": No such plugin info file: " . $target . "<br>" . $data);
|
||||
}
|
||||
include("{$realpath}/{$file}");
|
||||
eval('$' . $info['main'] . ' = new ' . $info['main'] . '();');
|
||||
eval('$' . $info['main'] . '->onload();');
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
|
||||
public function pluginReader($name) {
|
||||
$file = fopen($name, "r") or die("Unable to open file!");
|
||||
$data = fread($file, filesize($name));
|
||||
fclose($file);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,12 @@ include(ROOT . "/include/core/PHPMC/Main.php");
|
|||
include(ROOT . "/include/data/config.php");
|
||||
class Loader {
|
||||
|
||||
public $Event;
|
||||
|
||||
public function __construct() {
|
||||
$this->Event = new Event();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 页面框架显示控制函数
|
||||
|
@ -31,6 +37,7 @@ class Loader {
|
|||
}
|
||||
if(!PHPMC::User()->isLogin() && $pageName !== "login.html" && $pageName !== "404.html" && $pageName !== "403.html") {
|
||||
$pageName = "login.html";
|
||||
$pagePath = ROOT . "/content/" . $Option->getOption("Theme") . "/";
|
||||
}
|
||||
$str = file_get_contents($pagePath . $pageName);
|
||||
$str = str_replace("{CONTENTDIR}", "./content", $str);
|
||||
|
@ -82,7 +89,7 @@ class Loader {
|
|||
$Option = new Option();
|
||||
if(preg_match("/^[A-Za-z0-9\-\_]+$/", $_GET["page"])) {
|
||||
PHPMC::Permission()->checkSession("page:" . $_GET['page']);
|
||||
echo $this::loadPage($_GET["page"] . ".html", ROOT . "/content/" . $Option->getOption("Theme") . "/");
|
||||
$this->Event->EventHandle("viewPageEvent", array($_GET));
|
||||
exit;
|
||||
} elseif($_GET['action']) {
|
||||
switch($_GET['action']) {
|
||||
|
@ -90,98 +97,97 @@ class Loader {
|
|||
if(!PHPMC::Csrf()->verifyCsrfToken($_POST)) {
|
||||
PHPMC::Error()->Println("Csrf 验证失败,请刷新页面重试。");
|
||||
}
|
||||
PHPMC::Event()->LoginEvent($_POST);
|
||||
$this->Event->EventHandle("LoginEvent", array($_POST));
|
||||
break;
|
||||
case 'logout':
|
||||
PHPMC::Event()->LogoutEvent();
|
||||
$this->Event->EventHandle("LogoutEvent", array());
|
||||
break;
|
||||
case 'getserver':
|
||||
PHPMC::Permission()->checkSession("server:" . $_GET['id']);
|
||||
PHPMC::Event()->getServerEvent($_GET);
|
||||
$this->Event->EventHandle("getServerEvent", array($_GET));
|
||||
break;
|
||||
case 'start':
|
||||
PHPMC::Permission()->checkSession("server:" . $_GET['id']);
|
||||
PHPMC::Event()->startServerEvent($_GET);
|
||||
$this->Event->EventHandle("startServerEvent", array($_GET));
|
||||
break;
|
||||
case 'stop':
|
||||
PHPMC::Permission()->checkSession("server:" . $_GET['id']);
|
||||
PHPMC::Event()->stopServerEvent($_GET);
|
||||
$this->Event->EventHandle("stopServerEvent", array($_GET));
|
||||
break;
|
||||
case 'restart':
|
||||
PHPMC::Permission()->checkSession("server:" . $_GET['id']);
|
||||
PHPMC::Event()->restartServerEvent($_GET);
|
||||
$this->Event->EventHandle("restartServerEvent", array($_GET));
|
||||
break;
|
||||
case 'sendcommand':
|
||||
PHPMC::Permission()->checkSession("server:" . $_GET['id']);
|
||||
PHPMC::Event()->onCommandEvent($_GET);
|
||||
$this->Event->EventHandle("onCommandEvent", array($_GET));
|
||||
break;
|
||||
case 'status':
|
||||
PHPMC::Permission()->checkSession("server:" . $_GET['id']);
|
||||
PHPMC::Event()->getStatusEvent($_GET);
|
||||
$this->Event->EventHandle("getStatusEvent", array($_GET));
|
||||
break;
|
||||
case 'getserverinfo':
|
||||
PHPMC::Permission()->checkSession("server:" . $_GET['id']);
|
||||
PHPMC::Event()->getServerInfoEvent($_GET);
|
||||
$this->Event->EventHandle("getServerInfoEvent", array($_GET));
|
||||
break;
|
||||
case 'getdaemoninfo':
|
||||
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
|
||||
PHPMC::Event()->getDaemonInfoEvent($_GET);
|
||||
$this->Event->EventHandle("getDaemonInfoEvent", array($_GET));
|
||||
break;
|
||||
case 'getuserinfo':
|
||||
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
|
||||
PHPMC::Event()->getUserInfoEvent($_GET);
|
||||
$this->Event->EventHandle("getUserInfoEvent", array($_GET));
|
||||
break;
|
||||
case 'saveconfig':
|
||||
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
|
||||
PHPMC::Event()->saveConfigEvent($_GET);
|
||||
$this->Event->EventHandle("saveConfigEvent", array($_GET));
|
||||
break;
|
||||
case 'createserver':
|
||||
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
|
||||
PHPMC::Event()->createServerEvent($_GET);
|
||||
$this->Event->EventHandle("createServerEvent", array($_GET));
|
||||
break;
|
||||
case 'updateserver':
|
||||
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
|
||||
PHPMC::Event()->updateServerEvent($_GET);
|
||||
$this->Event->EventHandle("updateServerEvent", array($_GET));
|
||||
break;
|
||||
case 'deleteserver':
|
||||
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
|
||||
PHPMC::Event()->deleteServerEvent($_GET);
|
||||
$this->Event->EventHandle("deleteServerEvent", array($_GET));
|
||||
break;
|
||||
case 'createdaemon':
|
||||
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
|
||||
PHPMC::Event()->createDaemonEvent($_GET);
|
||||
$this->Event->EventHandle("createDaemonEvent", array($_GET));
|
||||
break;
|
||||
case 'updatedaemon':
|
||||
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
|
||||
PHPMC::Event()->updateDaemonEvent($_GET);
|
||||
$this->Event->EventHandle("updateDaemonEvent", array($_GET));
|
||||
break;
|
||||
case 'deletedaemon':
|
||||
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
|
||||
PHPMC::Event()->deleteDaemonEvent($_GET);
|
||||
$this->Event->EventHandle("deleteDaemonEvent", array($_GET));
|
||||
break;
|
||||
case 'createuser':
|
||||
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
|
||||
PHPMC::Event()->createUserEvent($_GET);
|
||||
$this->Event->EventHandle("createUserEvent", array($_GET));
|
||||
break;
|
||||
case 'updateuser':
|
||||
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
|
||||
PHPMC::Event()->updateUserEvent($_GET);
|
||||
$this->Event->EventHandle("updateUserEvent", array($_GET));
|
||||
break;
|
||||
case 'deleteuser':
|
||||
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
|
||||
PHPMC::Event()->deleteUserEvent($_GET);
|
||||
$this->Event->EventHandle("deleteUserEvent", array($_GET));
|
||||
break;
|
||||
case 'update':
|
||||
PHPMC::Permission()->checkSession("action:" . $_GET['action']);
|
||||
PHPMC::Event()->updateEvent();
|
||||
$this->Event->EventHandle("updateEvent", array());
|
||||
break;
|
||||
default:
|
||||
echo $this::loadPage("404.html", ROOT . "/content/" . $Option->getOption("Theme") . "/error/");
|
||||
$this->Event->EventHandle("defaultActionEvent", array($_GET));
|
||||
}
|
||||
exit;
|
||||
} elseif(empty($_GET['page'])) {
|
||||
echo $this::loadPage("panel.html", ROOT . "/content/" . $Option->getOption("Theme") . "/");
|
||||
exit;
|
||||
$this->Event->EventHandle("defaultPageEvent", array($_GET));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,6 +10,8 @@ if(!file_exists(ROOT . "/include/data/config.php") && !isset($_GET['installed'])
|
|||
exit;
|
||||
}
|
||||
include(ROOT . "/include/loader.php");
|
||||
$Plugin = new Plugin();
|
||||
$Loader = new Loader();
|
||||
$Plugin->load("plugins");
|
||||
$Loader->router();
|
||||
$Loader->frame();
|
||||
$Loader->frame();
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"main":"Register",
|
||||
"package":"com.phpmc.register",
|
||||
"author":"Akkariin",
|
||||
"website":"https://www.akkariin.com/"
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
class Register {
|
||||
|
||||
public static function onload() {
|
||||
global $Loader;
|
||||
$Loader->Event->registerClass("defaultActionEvent", new Register()); // 注册 defaultActionEvent 事件
|
||||
}
|
||||
|
||||
public function defaultActionEvent($test) {
|
||||
// print_r($test); // 输出 GET 参数数组
|
||||
return false; // 不取消事件
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue