Search in sources :

Example 21 with CoreConfig

use of io.github.ihongs.CoreConfig in project HongsCORE by ihongs.

the class MoreAction method eval.

@Action("eval")
public void eval(ActionHelper helper) throws HongsException {
    CoreConfig cnf = CoreConfig.getInstance();
    HttpServletRequest req = helper.getRequest();
    HttpServletResponse rsp = helper.getResponse();
    // 许可及IP白名单
    boolean sw = cnf.getProperty("core.eval.more.enable", false);
    String ia = cnf.getProperty("core.eval.more.allows");
    String ip = ActionDriver.getClientAddr(req);
    Set ias = Synt.toTerms(ia);
    if (ias == null || ias.isEmpty()) {
        ias = new HashSet();
        ias.add("::1");
        ias.add("127.0.0.1");
        ias.add("0:0:0:0:0:0:0:1");
    }
    if (!sw) {
        throw new HongsException(400, "Illegal request!");
    }
    if (!ias.contains(ip)) {
        throw new HongsException(400, "Illegal request.");
    }
    Map map = helper.getRequestData();
    String act = Core.ACTION_NAME.get();
    String uri = (String) map.get("act");
    // 从参数提取参数
    helper.setRequestData(data(map.get("request")));
    helper.setContextData(data(map.get("context")));
    helper.setSessionData(data(map.get("session")));
    helper.setCookiesData(data(map.get("cookies")));
    try {
        eval(helper, uri, req, rsp);
    } finally {
        Core.ACTION_NAME.set(act);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HashSet(java.util.HashSet) Set(java.util.Set) CoreConfig(io.github.ihongs.CoreConfig) HongsException(io.github.ihongs.HongsException) HttpServletResponse(javax.servlet.http.HttpServletResponse) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) Action(io.github.ihongs.action.anno.Action)

Example 22 with CoreConfig

use of io.github.ihongs.CoreConfig in project HongsCORE by ihongs.

the class ActionDriver method doCommit.

private void doCommit(Core core, ActionHelper hlpr, HttpServletRequest req, HttpServletResponse rsp) throws ServletException, IOException {
    /**
     * 输出特定服务信息
     */
    if (rsp.isCommitted() == false) {
        String pb;
        CoreConfig cc = core.got(CoreConfig.class);
        pb = cc.getProperty("core.service.by");
        if (pb != null && pb.length() != 0) {
            rsp.setHeader("Server", pb);
        }
        pb = cc.getProperty("core.powered.by");
        if (pb != null && pb.length() != 0) {
            rsp.setHeader("X-Powered-By", pb);
        }
    }
    Map dat = hlpr.getResponseData();
    if (dat != null) {
        req.setAttribute(Cnst.RESPON_ATTR, dat);
        hlpr.updateHelper(req, rsp);
        hlpr.flush();
    }
}
Also used : CoreConfig(io.github.ihongs.CoreConfig) HashMap(java.util.HashMap) Map(java.util.Map)

Example 23 with CoreConfig

use of io.github.ihongs.CoreConfig in project HongsCORE by ihongs.

the class AuthFilter method isJsop.

private boolean isJsop(HttpServletRequest req) {
    String c = Cnst.CB_KEY;
    c = req.getParameter(c);
    if (c != null && !c.isEmpty()) {
        return true;
    }
    CoreConfig cnf = CoreConfig.getInstance("default");
    c = cnf.getProperty("core.callback", "callback");
    c = req.getParameter(c);
    if (c != null && !c.isEmpty()) {
        return true;
    }
    return false;
}
Also used : CoreConfig(io.github.ihongs.CoreConfig)

Aggregations

CoreConfig (io.github.ihongs.CoreConfig)23 Map (java.util.Map)12 HashMap (java.util.HashMap)11 HongsException (io.github.ihongs.HongsException)10 Action (io.github.ihongs.action.anno.Action)9 CommitSuccess (io.github.ihongs.action.anno.CommitSuccess)7 IOException (java.io.IOException)4 HongsExemption (io.github.ihongs.HongsExemption)3 Verify (io.github.ihongs.action.anno.Verify)3 File (java.io.File)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 ActionHelper (io.github.ihongs.action.ActionHelper)1 Cmdlet (io.github.ihongs.cmdlet.anno.Cmdlet)1 DB (io.github.ihongs.db.DB)1 Table (io.github.ihongs.db.Table)1