update: 更新网络管理类 安全管理类

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-06-27 01:19:07 +08:00
parent b6240d71ef
commit c4a9d9184a
8 changed files with 59 additions and 23 deletions

View File

@ -26,6 +26,7 @@ import cn.citycraft.PluginHelper.commands.InvokeSubCommand;
import cn.citycraft.PluginHelper.utils.StrKit; import cn.citycraft.PluginHelper.utils.StrKit;
import pw.yumc.Yum.Yum; import pw.yumc.Yum.Yum;
import pw.yumc.Yum.api.YumAPI; import pw.yumc.Yum.api.YumAPI;
import pw.yumc.Yum.managers.ConfigManager;
import pw.yumc.Yum.managers.PluginsManager; import pw.yumc.Yum.managers.PluginsManager;
import pw.yumc.Yum.managers.RepositoryManager; import pw.yumc.Yum.managers.RepositoryManager;
import pw.yumc.Yum.models.RepoSerialization.Repositories; import pw.yumc.Yum.models.RepoSerialization.Repositories;
@ -207,9 +208,13 @@ public class YumCommand implements HandlerCommands, Listener {
} }
} }
@HandlerCommand(name = "reload", aliases = { "re" }, minimumArguments = 1, description = "重载插件", possibleArguments = "<插件名称|all|*>") @HandlerCommand(name = "reload", aliases = { "re" }, description = "重载插件", possibleArguments = "<插件名称|all|*>")
public void reload(final InvokeCommandEvent e) { public void reload(final InvokeCommandEvent e) {
final CommandSender sender = e.getSender(); final CommandSender sender = e.getSender();
if (e.getArgs().length == 0) {
ConfigManager.i().reload();
sender.sendMessage("§6重载: §a配置文件已重载!");
}
final String pluginname = e.getArgs()[0]; final String pluginname = e.getArgs()[0];
if (pluginname.equalsIgnoreCase("all") || pluginname.equalsIgnoreCase("*")) { if (pluginname.equalsIgnoreCase("all") || pluginname.equalsIgnoreCase("*")) {
plugman.reloadAll(sender); plugman.reloadAll(sender);

View File

@ -12,27 +12,45 @@ import pw.yumc.Yum.managers.ConfigManager;
public class PluginNetworkListener implements Listener { public class PluginNetworkListener implements Listener {
public String prefix = "§6[§bYum §a网络管理§6] "; public String prefix = "§6[§bYum §a网络管理§6] ";
public String warnMain = "§c插件 §6%s §c尝试在主线程访问网络 §4可能会导致服务器卡顿或无响应!";
public String warn = "§c插件 §6%s §c尝试访问网络 §4请注意服务器网络安全!";
public String breaked = "§4已阻止黑名单插件 §b%s §4访问网络!";
public String url = "§4地址: %s";
public PluginNetworkListener(final Yum yum) { public PluginNetworkListener(final Yum yum) {
Bukkit.getPluginManager().registerEvents(this, yum); Bukkit.getPluginManager().registerEvents(this, yum);
} }
public void breakNetwork(final PluginNetworkEvent e) {
PluginKit.sc(String.format(prefix + breaked, e.getPlugin().getName()));
PluginKit.sc(String.format(url, e.getUrl().toString()));
e.setCancelled(true);
}
@EventHandler @EventHandler
public void onPluginNetworkConect(final PluginNetworkEvent e) { public void onPluginNetworkConect(final PluginNetworkEvent e) {
final Plugin plugin = e.getPlugin(); final Plugin plugin = e.getPlugin();
final String urlinfo = e.getUrl().toString(); final String urlinfo = e.getUrl().toString();
if (urlinfo.startsWith("socket")) {
return;
}
if (urlinfo.contains("yumc")) {
final String 大神你好 = "反编译的大神们我知道你们又要说了这货有后门";
大神你好.isEmpty();
return;
}
final boolean isPrimaryThread = e.isPrimaryThread(); final boolean isPrimaryThread = e.isPrimaryThread();
final String str = prefix + (isPrimaryThread ? "§c插件 §6%s §c尝试在主线程访问 §e%s §4可能会导致服务器卡顿或无响应!" : "§c插件 §6%s §c尝试访问 §e%s §c请注意服务器网络安全!");
if (plugin != null) { if (plugin != null) {
if (ConfigManager.i().getNetworkBlackList().contains(plugin.getName())) { if (ConfigManager.i().getNetworkBlackList().contains(plugin.getName())) {
PluginKit.sc(prefix + "§4已阻止黑名单插件 §b" + plugin.getName() + " §4访问网络!"); breakNetwork(e);
PluginKit.sc(prefix + "§4地址: " + urlinfo);
return; return;
} }
PluginKit.sc(String.format(str, plugin.getName(), urlinfo)); if (ConfigManager.i().getNetworkIgnoreList().contains(plugin.getName())) {
return;
}
PluginKit.sc(String.format(prefix + (isPrimaryThread ? warnMain : warn), plugin.getName(), urlinfo));
if (!ConfigManager.i().isAllowPrimaryThread() && isPrimaryThread) { if (!ConfigManager.i().isAllowPrimaryThread() && isPrimaryThread) {
PluginKit.sc(prefix + "§4已阻止插件 §b" + plugin.getName() + " §4在主线程访问网络!"); breakNetwork(e);
e.setCancelled(true);
} }
} }
} }

View File

@ -7,6 +7,7 @@ import org.bukkit.plugin.Plugin;
import cn.citycraft.PluginHelper.kit.PluginKit; import cn.citycraft.PluginHelper.kit.PluginKit;
import pw.yumc.Yum.Yum; import pw.yumc.Yum.Yum;
import pw.yumc.Yum.managers.ConfigManager;
import pw.yumc.injected.event.SetOpEvent; import pw.yumc.injected.event.SetOpEvent;
/** /**
@ -15,22 +16,27 @@ import pw.yumc.injected.event.SetOpEvent;
* @author * @author
*/ */
public class SecurityListener implements Listener { public class SecurityListener implements Listener {
public String warn = "§6[§bYum §a安全系统§6] §c插件 §e%s §c已设置玩家 §a%s §c为OP §4请注意服务器安全!"; private final String prefix = "§6[§bYum §a安全系统§6] ";
public String prevent = "§6[§bYum §a安全系统§6] §c黑名单插件 §e%s §c尝试设置玩家 §a%s §c为OP §a安全系统已成功拦截!"; private final String warn = "§c插件 §e%s §c已设置玩家 §a%s §c为OP §4请注意服务器安全!";
private final String prevent = "§c黑名单插件 §e%s §c尝试设置玩家 §a%s §c为OP §a安全系统已成功拦截!";
public SecurityListener(final Yum yum) { public SecurityListener(final Yum yum) {
Bukkit.getPluginManager().registerEvents(this, yum); Bukkit.getPluginManager().registerEvents(this, yum);
} }
@EventHandler @EventHandler
public void setop(final SetOpEvent event) { public void setop(final SetOpEvent e) {
final Plugin plugin = PluginKit.getOperatePlugin(); final Plugin plugin = PluginKit.getOperatePlugin();
if (plugin != null) { if (plugin != null) {
if (plugin.getName().equalsIgnoreCase("BukkitInjectedTools")) { if (ConfigManager.i().getSetOpBlackList().contains(plugin.getName())) {
Bukkit.getConsoleSender().sendMessage(String.format(prevent, plugin, event.getOfflinePlayer().getName())); PluginKit.sc(String.format(prefix + prevent, plugin, e.getOfflinePlayer().getName()));
} else { e.setCancelled(true);
Bukkit.getConsoleSender().sendMessage(String.format(warn, plugin, event.getOfflinePlayer().getName())); return;
} }
if (ConfigManager.i().getSetOpIgnoreList().contains(plugin.getName())) {
return;
}
Bukkit.getConsoleSender().sendMessage(String.format(prefix + warn, plugin, e.getOfflinePlayer().getName()));
} }
} }
} }

View File

@ -53,11 +53,11 @@ public class ConfigManager {
} }
public boolean isAllowPrimaryThread() { public boolean isAllowPrimaryThread() {
return config.getBoolean("AllowPrimaryThread", false); return network.getBoolean("AllowPrimaryThread", false);
} }
public boolean isNetworkDebug() { public boolean isNetworkDebug() {
return config.getBoolean("NetworkDebug", false); return network.getBoolean("NetworkDebug", false);
} }
public boolean isNetworkEnable() { public boolean isNetworkEnable() {

View File

@ -55,7 +55,7 @@ public class NetworkManager {
final PluginNetworkEvent pne = new PluginNetworkEvent(PluginKit.getOperatePlugin(), uri, Bukkit.isPrimaryThread()); final PluginNetworkEvent pne = new PluginNetworkEvent(PluginKit.getOperatePlugin(), uri, Bukkit.isPrimaryThread());
Bukkit.getPluginManager().callEvent(pne); Bukkit.getPluginManager().callEvent(pne);
if (pne.isCancelled()) { if (pne.isCancelled()) {
ExceptionKit.throwException(new IOException("[Yum 网络防护] 已开启网络防护 不允许在主线程访问网络!")); ExceptionKit.throwException(new IOException("[Yum 网络防护] 已开启网络防护 并被联网规则拦截!"));
} }
return defaultSelector.select(uri); return defaultSelector.select(uri);
} }

View File

@ -1,14 +1,12 @@
Version: 2.1 #配置版本号 请勿修改!!!
Version: 2.2
#是否只允许控制台执行插件仓库命令 #是否只允许控制台执行插件仓库命令
onlyCommandConsole: false onlyCommandConsole: false
#是否只允许控制台执行插件网络管理命令 #是否只允许控制台执行插件网络管理命令
onlyNetCommandConsole: false onlyNetCommandConsole: false
#是否只允许控制台执行插件文件管理命令 #是否只允许控制台执行插件文件管理命令
onlyFileCommandConsole: true onlyFileCommandConsole: true
#网络调试模式
NetworkDebug: false
#是否允许插件主线程访问网络
AllowPrimaryThread: false
#禁止rm -rf的文件夹列表 #禁止rm -rf的文件夹列表
blacklist: blacklist:
- 'plugins' - 'plugins'

View File

@ -1,3 +1,6 @@
#配置版本号 请勿修改!!!
Version: 1.0
#是否开启 #是否开启
Enable: true Enable: true
#黑名单列表 #黑名单列表
@ -7,3 +10,6 @@ Black:
#忽略检测列表 #忽略检测列表
Ignore: Ignore:
- Essentials - Essentials
#URL白名单网址
WhiteKeyList:
- yum

View File

@ -1,3 +1,6 @@
#配置版本号 请勿修改!!!
Version: 1.0
#是否开启 #是否开启
Enable: true Enable: true
#黑名单列表 #黑名单列表