Search in sources :

Example 6 with CoreConfig

use of app.hongs.CoreConfig in project HongsCORE by ihongs.

the class FileAction method isDenyFile.

private boolean isDenyFile(File file) {
    if (file.isDirectory()) {
        return true;
    }
    String serv = System.getProperty("manage.file");
    if ("no".equals(serv)) {
        return true;
    }
    if ("all".equals(serv)) {
        return false;
    }
    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));
}
Also used : CoreConfig(app.hongs.CoreConfig)

Example 7 with CoreConfig

use of app.hongs.CoreConfig in project HongsCORE by ihongs.

the class MoreAction method call.

@Action("call")
public void call(ActionHelper helper) throws HongsException {
    CoreConfig cnf = CoreConfig.getInstance();
    HttpServletRequest req = helper.getRequest();
    HttpServletResponse rsp = helper.getResponse();
    // 许可及IP白名单
    boolean sw = cnf.getProperty("core.call.more.enable", false);
    String ia = cnf.getProperty("core.call.more.allows");
    String ip = addr(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(0x1100, "Illegal request!");
    }
    if (!ias.contains(ip)) {
        throw new HongsException(0x1100, "Illegal request.");
    }
    // 从参数提取参数
    Map map = helper.getRequestData();
    helper.setRequestData(data(map.get("request")));
    helper.setContextData(data(map.get("context")));
    helper.setSessionData(data(map.get("session")));
    helper.setCookiesData(data(map.get("cookies")));
    String uri = "/" + map.get("act") + Cnst.ACT_EXT;
    call(helper, uri, req, rsp);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Set(java.util.Set) HashSet(java.util.HashSet) CoreConfig(app.hongs.CoreConfig) HongsException(app.hongs.HongsException) HttpServletResponse(javax.servlet.http.HttpServletResponse) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) Action(app.hongs.action.anno.Action)

Example 8 with CoreConfig

use of app.hongs.CoreConfig in project HongsCORE by ihongs.

the class CmdletRunner method init.

public static String[] init(String[] args) throws IOException, HongsException {
    Map<String, Object> opts;
    opts = CmdletHelper.getOpts(args, "debug:i", "corepath:s", "confpath:s", "datapath:s", "basepath:s", "basehref:s", "language:s", "timezone:s");
    args = (String[]) opts.get("");
    Core.THREAD_CORE.set(Core.GLOBAL_CORE);
    Core.ACTION_TIME.set(Core.STARTS_TIME);
    /**
     * 核心属性配置 *
     */
    Core.ENVIR = 0;
    Core.DEBUG = Synt.declare(opts.get("debug"), (byte) 0);
    Core.CORE_PATH = Synt.declare(opts.get("corepath"), System.getProperty("user.dir"));
    Core.CORE_PATH = new File(Core.CORE_PATH).getAbsolutePath();
    Core.CONF_PATH = Synt.declare(opts.get("confpath"), Core.CORE_PATH + File.separator + "etc");
    Core.DATA_PATH = Synt.declare(opts.get("datapath"), Core.CORE_PATH + File.separator + "var");
    Core.BASE_PATH = Synt.declare(opts.get("basepath"), Core.CORE_PATH + File.separator + "web");
    Core.BASE_HREF = Synt.declare(opts.get("basehref"), "");
    // 如果 web 目录不存在, 则视为在 WEB-INF 下
    File bp = new File(Core.BASE_PATH);
    if (!bp.exists()) {
        Core.BASE_PATH = bp.getParentFile().getParent();
    }
    // 项目 url 须以 / 开头, 如有缺失则自动补全
    if (Core.BASE_HREF.length() != 0) {
        if (Core.BASE_HREF.startsWith("/") == false) {
            Core.BASE_HREF = "/" + Core.BASE_HREF;
        }
        if (Core.BASE_HREF.endsWith("/") == true) {
            Core.BASE_HREF = Core.BASE_HREF.substring(0, Core.BASE_HREF.length() - 1);
        }
    }
    /**
     * 系统属性配置 *
     */
    CoreConfig cnf;
    cnf = CoreConfig.getInstance();
    Core.SERVER_ID = cnf.getProperty("core.server.id", "0");
    cnf = CoreConfig.getInstance("defines");
    Map m = new HashMap();
    m.put("SERVER_ID", Core.SERVER_ID);
    m.put("BASE_PATH", Core.BASE_PATH);
    m.put("CORE_PATH", Core.CORE_PATH);
    m.put("CONF_PATH", Core.CONF_PATH);
    m.put("DATA_PATH", Core.DATA_PATH);
    // 启动系统属性
    for (Map.Entry et : cnf.entrySet()) {
        String k = (String) et.getKey();
        String v = (String) et.getValue();
        if (k.startsWith("envir.")) {
            k = k.substring(6);
            v = Tool.inject(v, m);
            System.setProperty(k, v);
        }
    }
    if (0 < Core.DEBUG && 8 != (8 & Core.DEBUG)) {
        // 调试系统属性
        for (Map.Entry et : cnf.entrySet()) {
            String k = (String) et.getKey();
            String v = (String) et.getValue();
            if (k.startsWith("debug.")) {
                k = k.substring(6);
                v = Tool.inject(v, m);
                System.setProperty(k, v);
            }
        }
    }
    /**
     * 实例属性配置 *
     */
    cnf = CoreConfig.getInstance();
    String act = null;
    if (args.length > 0) {
        List<String> argz = new ArrayList();
        argz.addAll(Arrays.asList(args));
        act = argz.remove(0);
        args = argz.toArray(new String[0]);
    }
    Core.ACTION_NAME.set(act);
    String zone = null;
    if (opts.containsKey("timezone")) {
        zone = (String) opts.get("timezone");
    }
    if (zone == null || zone.length() == 0) {
        if (cnf.getProperty("core.timezone.probing", false)) {
            zone = TimeZone.getDefault().getID();
        } else {
            zone = cnf.getProperty("core.timezone.default", "GMT+8");
        }
    }
    Core.ACTION_ZONE.set(zone);
    String lang = null;
    if (opts.containsKey("language")) {
        lang = (String) opts.get("language");
    }
    if (lang == null || lang.length() == 0) {
        if (cnf.getProperty("core.language.probing", false)) {
            /**
             * 获取系统默认的区域
             * 仅保留 语言[_地区]
             */
            lang = Locale.getDefault().toString();
            int pos = lang.indexOf('_');
            if (pos > 0) {
                pos = lang.indexOf('_', pos + 1);
                if (pos > 0) {
                    lang = lang.substring(0, pos);
                }
            }
            lang = CoreLocale.getAcceptLanguage(lang);
            if (lang == null) {
                lang = cnf.getProperty("core.language.default", "zh_CN");
            }
        } else {
            lang = cnf.getProperty("core.language.default", "zh_CN");
        }
    } else {
        /**
         * 检查语言参数设置
         */
        String leng;
        leng = lang;
        lang = CoreLocale.getAcceptLanguage(lang);
        if (lang == null) {
            CoreLogger.error("ERROR: Unsupported language: " + leng + ".");
            System.exit(1);
        }
    }
    Core.ACTION_LANG.set(lang);
    /**
     * 初始化动作助手, 可复用动作组件 *
     */
    ActionHelper hlpr = new ActionHelper(null, null, null, null);
    Core.getInstance().put(ActionHelper.class.getName(), hlpr);
    hlpr.updateOutput(System.out, new PrintWriter(System.out));
    // Clean instatnces fis core at exit
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            Core.THREAD_CORE.get().close();
            Core.GLOBAL_CORE.close();
        }
    });
    return args;
}
Also used : CoreConfig(app.hongs.CoreConfig) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ActionHelper(app.hongs.action.ActionHelper) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) PrintWriter(java.io.PrintWriter)

Example 9 with CoreConfig

use of app.hongs.CoreConfig in project HongsCORE by ihongs.

the class Capts method captcha.

public static Capts captcha(int h, String b, String f, String e) {
    if (h < 24 || h > 96) {
        throw new HongsExpedient(0x1100, "h must be 24~96 (px)");
    }
    // 获取配置
    CoreConfig cc = CoreConfig.getInstance();
    String ff = cc.getProperty("core.capts.font.file", "!Capts.ttf");
    String cs = cc.getProperty("core.capts.code.dict", "1234567890");
    int cn = cc.getProperty("core.capts.code.count", 4);
    int mn = cc.getProperty("core.capts.mask.count", 8);
    float sr = cc.getProperty("core.capts.size.ratio", 0.40f);
    float fr = cc.getProperty("core.capts.font.ratio", 0.80f);
    float mr = cc.getProperty("core.capts.mend.ratio", 0.10f);
    float xr = cc.getProperty("core.capts.mask.ratio", 0.05f);
    int w = (int) ((float) h * sr * (cn + 1));
    char[] cd = cs.toCharArray();
    Color bc = "".equals(b) ? new Color(0xffffff) : new Color(Integer.parseInt(b, 16));
    Color fc = "".equals(f) ? new Color(0x000000) : new Color(Integer.parseInt(f, 16));
    // 构建实例
    Capts vc = new Capts();
    vc.setSize(w, h);
    vc.setCodeCount(cn);
    vc.setMaskCount(mn);
    vc.setFontRatio(fr);
    vc.setMendRatio(mr);
    vc.setMaskRatio(xr);
    vc.setBackColor(bc);
    vc.setFontColor(fc);
    vc.setFontFile(ff);
    vc.setCodeDict(cd);
    return vc;
}
Also used : CoreConfig(app.hongs.CoreConfig) HongsExpedient(app.hongs.HongsExpedient) Color(java.awt.Color)

Example 10 with CoreConfig

use of app.hongs.CoreConfig in project HongsCORE by ihongs.

the class ConnKit method redirect.

/**
 * 登录成功后跳转
 * 依此检查 Parameters,Cookies,Session 中是否有指定返回路径
 * 都没有指定时则跳转到默认地址
 * 默认地址缺失则跳转到网站首页
 * @param helper
 * @throws HongsException
 */
public static void redirect(ActionHelper helper) throws HongsException {
    String k;
    String v;
    CoreConfig cc = CoreConfig.getInstance("oauth2");
    do {
        k = cc.getProperty("oauth2.bak.prm", "back");
        v = helper.getParameter(k);
        if (v != null && !v.isEmpty()) {
            break;
        }
        k = cc.getProperty("oauth2.bak.cok");
        if (k != null && !k.isEmpty()) {
            v = (String) helper.getCookibute(k);
            if (v != null && !v.isEmpty()) {
                // 清除 Cookies
                helper.setCookibute(k, null);
                break;
            }
        }
        k = cc.getProperty("oauth2.bak.ses");
        if (k != null && !k.isEmpty()) {
            v = (String) helper.getSessibute(k);
            if (v != null && !v.isEmpty()) {
                // 清除 Session
                helper.setSessibute(k, null);
                break;
            }
        }
        v = cc.getProperty("oauth2.bak.url", Core.BASE_HREF + "/");
    } while (false);
    // 跳转
    helper.redirect(v);
}
Also used : CoreConfig(app.hongs.CoreConfig)

Aggregations

CoreConfig (app.hongs.CoreConfig)19 Map (java.util.Map)12 HashMap (java.util.HashMap)11 Action (app.hongs.action.anno.Action)7 HongsExpedient (app.hongs.HongsExpedient)3 File (java.io.File)3 IOException (java.io.IOException)3 Core (app.hongs.Core)2 HongsException (app.hongs.HongsException)2 HashSet (java.util.HashSet)2 ServletException (javax.servlet.ServletException)2 Part (javax.servlet.http.Part)2 HongsError (app.hongs.HongsError)1 ActionHelper (app.hongs.action.ActionHelper)1 Cmdlet (app.hongs.cmdlet.anno.Cmdlet)1 Color (java.awt.Color)1 FileWriter (java.io.FileWriter)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1