use of io.github.ihongs.CoreConfig in project HongsCORE by ihongs.
the class SignAction method signCreate.
/**
* 登录
* @param ah
* @throws HongsException
*/
@Action("create")
@Verify(conf = "master", form = "sign")
@CommitSuccess
@Override
public void signCreate(ActionHelper ah) throws HongsException {
CoreConfig cc = CoreConfig.getInstance("master");
if (!cc.getProperty("core.public.sign.open", true)) {
throw new HongsException(404, "Sign in is not allowed");
}
super.signCreate(ah);
}
use of io.github.ihongs.CoreConfig in project HongsCORE by ihongs.
the class SignAction method userCreate.
/**
* 注册
* @param ah
* @throws HongsException
*/
@Action("user/create")
@Verify(conf = "master", form = "regs", type = 0, trim = 1)
@CommitSuccess
public void userCreate(ActionHelper ah) throws HongsException {
CoreConfig cc = CoreConfig.getInstance("master");
if (!cc.getProperty("core.public.regs.open", true)) {
throw new HongsException(404, "Sign on is not allowed");
}
User uo = (User) DB.getInstance("master").getModel("user");
Map rd = ah.getRequestData();
String uuid = uo.create(rd);
String uname = Synt.declare(rd.get("name"), "");
String uhead = Synt.declare(rd.get("head"), "");
// 加入公共部门
Map sd = new HashMap();
sd.put("user_id", uuid);
sd.put("dept_id", cc.getProperty("core.public.regs.dept", "CENTRE"));
uo.db.getTable("dept_user").insert(sd);
// 赋予公共权限. 仅用部门即可(2019/02/28)
// Map sd = new HashMap();
// sd.put("user_id", uuid);
// sd.put("role" , cc.getProperty("core.public.regs.role", "centre"));
// uo.db.getTable("user_role").insert(sd);
// * 表示密码登录
Map ad = AuthKit.userSign(ah, "*", uuid, uname, uhead);
ah.reply(Synt.mapOf("info", ad));
}
use of io.github.ihongs.CoreConfig in project HongsCORE by ihongs.
the class ServerCmdlet method start.
@Cmdlet("start")
public static void start(String[] args) throws HongsException {
int port = args.length > 0 ? Integer.parseInt(args[0]) : 8080;
String conf = Core.CORE_PATH + File.separator + "web.xml";
if (!(new File(conf)).exists()) {
conf = Core.CONF_PATH + File.separator + "web.xml";
}
String serd = Core.DATA_PATH + File.separator + "server";
File ppid = new File(serd + File.separator + port + ".pid");
File ppcd = new File(serd);
// 检查进程
if (ppid.exists() != false) {
System.err.println("ERROR: The server has not exit, or did not exit normally.");
System.exit(126);
return;
}
if (ppcd.exists() == false) {
ppcd.mkdirs();
}
try (FileWriter fw = new FileWriter(ppid, true)) {
fw.write(ManagementFactory.getRuntimeMXBean().getName().split("@", 2)[0]);
fw.close();
} catch (IOException e) {
throw new HongsException(e);
}
CoreConfig cc = CoreConfig.getInstance("defines");
/**
* 取消名称
* 日志中将记录各独立的线程名
* 以便于区分不同的非动作任务
*/
Core.ACTION_NAME.remove();
Server server;
WebAppContext webapp;
ServerConnector conner;
Connector[] connes;
server = new Server(new QueuedThreadPool(cc.getProperty("jetty.pool.max.threads", 254), cc.getProperty("jetty.pool.min.threads", 010), cc.getProperty("jetty.pool.idle.timeout", 30000)));
webapp = new WebAppContext();
conner = new ServerConnector(server);
connes = new Connector[] { conner };
conner.setPort(port);
conner.setHost(null);
conner.setIdleTimeout(cc.getProperty("jetty.conn.idle.timeout", 30000L));
conner.setAcceptQueueSize(cc.getProperty("jetty.conn.accept.queue.size", 254));
conner.setAcceptedSendBufferSize(cc.getProperty("jetty.conn.accept.sndbuf.size", -1));
conner.setAcceptedReceiveBufferSize(cc.getProperty("jetty.conn.accept.rcvbuf.size", -1));
server.setConnectors(connes);
webapp.setDescriptor(conf);
webapp.setContextPath(Core.SERV_PATH);
webapp.setResourceBase(Core.BASE_PATH);
webapp.setTempDirectory(new File(Core.DATA_PATH + "/server/temp"));
webapp.setPersistTempDirectory(true);
webapp.setParentLoaderPriority(true);
webapp.setThrowUnavailableOnStartupException(true);
// webapp.setMaxFormKeys(cc.getProperty("jetty.serv.max.form.keys", 10000));
// webapp.setMaxFormContentSize(cc.getProperty("jetty.serv.max.form.size", 200000));
server.setHandler(webapp);
String x;
// 默认微调
x = org.eclipse.jetty.servlet.DefaultServlet.CONTEXT_INIT;
webapp.setInitParameter(x + "useFileMappedBuffer", "false");
webapp.setInitParameter(x + "dirAllowed", "false");
/**
* 初始设置
* 光能外部配置参数还不够方便
* 可能需要替换 JSP 解析器或 Session 容器
* 可以设置 jetty.init 来注入 Initer 对象
*/
x = cc.getProperty("jetty.init");
if (null != x) {
String[] a = x.split(";");
for (String n : a) {
n = n.trim();
if (n.isEmpty()) {
continue;
}
try {
((Initer) Class.forName(n).getDeclaredConstructor().newInstance()).init(webapp);
} catch (ClassNotFoundException e) {
throw new HongsExemption(e);
} catch (NoSuchMethodException e) {
throw new HongsExemption(e);
} catch (InstantiationException e) {
throw new HongsExemption(e);
} catch (IllegalAccessException e) {
throw new HongsExemption(e);
} catch (InvocationTargetException e) {
throw new HongsExemption(e);
}
}
}
// 中止机制
Runtime.getRuntime().addShutdownHook(new Stoper(server, ppid));
// 启动服务
try {
server.start();
if (Core.DEBUG == 0) {
System.err.println("HTTP server is started.");
}
/**
* URL 会话参数等同于对应的 Cookie, 总是小写
* server.start_ 执行之前 web.xml 还没解析
*/
x = webapp.getInitParameter(SessionHandler.__SessionIdPathParameterNameProperty);
if (x == null || x.isEmpty()) {
x = webapp.getServletContext().getSessionCookieConfig().getName();
x = x.toLowerCase();
webapp.getSessionHandler().setSessionIdPathParameterName(x);
}
server.join();
} catch (Exception e) {
throw new HongsException(e);
} catch (Error e) {
throw new HongsExemption(e);
}
}
use of io.github.ihongs.CoreConfig in project HongsCORE by ihongs.
the class FileAction method isDenyFile.
private boolean isDenyFile(File file) {
if (file.isDirectory()) {
return false;
}
String serv = System.getProperty("manage.file");
if ("all".equals(serv)) {
return false;
}
if ("no".equals(serv)) {
return true;
}
String name = file.getName();
String extn = name.replaceFirst("^.*\\.", "");
CoreConfig conf = CoreConfig.getInstance();
Set<String> extz = Synt.toTerms(conf.getProperty("fore.upload.deny.extns"));
Set<String> exts = Synt.toTerms(conf.getProperty("fore.upload.allow.extns"));
return (null != extz && extz.contains(extn)) || (null != exts && !exts.contains(extn));
}
use of io.github.ihongs.CoreConfig in project HongsCORE by ihongs.
the class ActionHelper method getRequestPart.
/**
* 解析 multipart/form-map 数据, 处理上传
* @return
*/
final Map getRequestPart() {
CoreConfig conf = CoreConfig.getInstance();
String x;
Set<String> allowTypes = null;
x = conf.getProperty("fore.upload.allow.types", null);
if (x != null) {
allowTypes = new HashSet(Arrays.asList(x.split(",")));
}
Set<String> denyTypes = null;
x = conf.getProperty("fore.upload.deny.types", null);
if (x != null) {
denyTypes = new HashSet(Arrays.asList(x.split(",")));
}
Set<String> allowExtns = null;
x = conf.getProperty("fore.upload.allow.extns", null);
if (x != null) {
allowExtns = new HashSet(Arrays.asList(x.split(",")));
}
Set<String> denyExtns = null;
x = conf.getProperty("fore.upload.deny.extns", null);
if (x != null) {
denyExtns = new HashSet(Arrays.asList(x.split(",")));
}
try {
Map rd = new HashMap();
Map ud = new HashMap();
for (Part part : request.getParts()) {
long size = part.getSize();
String name = part.getName();
String type = part.getContentType();
String extn = part.getSubmittedFileName();
// 无类型的普通参数已在外部处理
if (name == null || type == null || extn == null) {
continue;
}
// 在修改的操作中表示将其置为空
if (size == 0) {
if (null == request.getParameter(name)) {
Dict.setParam(rd, null, name);
}
continue;
}
// 检查类型
int pos = type.indexOf(',');
if (pos != -1) {
type = type.substring(0, pos);
}
if (allowTypes != null && !allowTypes.contains(type)) {
throw new HongsExemption(400, "File type '" + type + "' is not allowed");
}
if (denyTypes != null && denyTypes.contains(type)) {
throw new HongsExemption(400, "File type '" + type + "' is denied");
}
// 检查扩展
pos = extn.lastIndexOf('.');
if (pos != -1) {
extn = extn.substring(1 + pos);
} else {
extn = "";
}
if (allowExtns != null && !allowExtns.contains(extn)) {
throw new HongsExemption(400, "Extension '" + extn + "' is not allowed");
}
if (denyExtns != null && denyExtns.contains(extn)) {
throw new HongsExemption(400, "Extension '" + extn + "' is denied");
}
/**
* 临时存储文件
* 不再需要暂存
* 可以直接利用 Part 继续向下传递
*/
/*
String id = Core.getUniqueId();
String temp = path + File.separator + id + ".tmp";
String tenp = path + File.separator + id + ".tnp";
subn = subn.replaceAll("[\\r\\n\\\\/]", ""); // 清理非法字符: 换行和路径分隔符
subn = subn + "\r\n" + type + "\r\n" + size; // 拼接存储信息: 名称和类型及大小
try (
InputStream xmin = part.getInputStream();
FileOutputStream mout = new FileOutputStream(temp);
FileOutputStream nout = new FileOutputStream(tenp);
) {
byte[] nts = subn.getBytes("UTF-8");
byte[] buf = new byte[1024];
int cnt ;
while((cnt = xmin.read(buf)) != -1) {
mout.write(buf, 0, cnt);
}
nout.write(nts);
}
Dict.setParam( rd , id , name );
*/
Dict.setValue(ud, part, name, null);
Dict.setParam(rd, part, name);
}
// 记录在应用里以便有需要时候还可读取原始值
setAttribute(Cnst.UPLOAD_ATTR, ud);
return rd;
} catch (IllegalStateException e) {
// 上传受限, 如大小超标
throw new HongsExemption(400, e);
} catch (ServletException e) {
throw new HongsExemption(1113, e);
} catch (IOException e) {
throw new HongsExemption(1113, e);
}
}
Aggregations