Search in sources :

Example 1 with SystemParametersServer

use of io.jpom.service.system.SystemParametersServer in project Jpom by dromara.

the class LoadJsonConfigToDb method loadMailConfig.

public void loadMailConfig() {
    File backupOldData = FileUtil.file(ConfigBean.getInstance().getDataPath(), "backup_old_data");
    // 读取 MAIL_CONFIG 文件内容
    File file = FileUtil.file(ConfigBean.getInstance().getDataPath(), ServerConfigBean.MAIL_CONFIG);
    if (!FileUtil.exist(file)) {
        return;
    }
    try {
        JSON json = JsonFileUtil.readJson(file.getAbsolutePath());
        MailAccountModel mailAccountModel = json.toJavaObject(MailAccountModel.class);
        if (mailAccountModel == null) {
            return;
        }
        SystemParametersServer parametersServer = SpringUtil.getBean(SystemParametersServer.class);
        parametersServer.upsert(MailAccountModel.ID, mailAccountModel, MailAccountModel.ID);
        // 将 json 文件转移到备份目录
        FileUtil.move(file, FileUtil.mkdir(backupOldData), true);
        DefaultSystemLog.getLog().info("{} mv to {}", FileUtil.getAbsolutePath(file), FileUtil.getAbsolutePath(backupOldData));
    } catch (Exception e) {
        DefaultSystemLog.getLog().error("load mail config error ", e);
    }
}
Also used : JSON(com.alibaba.fastjson.JSON) File(java.io.File) SystemParametersServer(io.jpom.service.system.SystemParametersServer)

Example 2 with SystemParametersServer

use of io.jpom.service.system.SystemParametersServer in project Jpom by dromara.

the class LoadJsonConfigToDb method loadOutGivingWhitelistConfig.

public void loadOutGivingWhitelistConfig() {
    File backupOldData = FileUtil.file(ConfigBean.getInstance().getDataPath(), "backup_old_data");
    // 读取 OUTGIVING_WHITELIST 文件内容
    File file = FileUtil.file(ConfigBean.getInstance().getDataPath(), ServerConfigBean.OUTGIVING_WHITELIST);
    if (!FileUtil.exist(file)) {
        return;
    }
    try {
        JSON json = JsonFileUtil.readJson(file.getAbsolutePath());
        ServerWhitelist serverWhitelist = json.toJavaObject(ServerWhitelist.class);
        if (serverWhitelist == null) {
            return;
        }
        SystemParametersServer parametersServer = SpringUtil.getBean(SystemParametersServer.class);
        String id = ServerWhitelist.workspaceId(Const.WORKSPACE_DEFAULT_ID);
        parametersServer.upsert(id, serverWhitelist, id);
        // 将 json 文件转移到备份目录
        FileUtil.move(file, FileUtil.mkdir(backupOldData), true);
        DefaultSystemLog.getLog().info("{} mv to {}", FileUtil.getAbsolutePath(file), FileUtil.getAbsolutePath(backupOldData));
    } catch (Exception e) {
        DefaultSystemLog.getLog().error("load mail config error ", e);
    }
}
Also used : JSON(com.alibaba.fastjson.JSON) File(java.io.File) SystemParametersServer(io.jpom.service.system.SystemParametersServer)

Example 3 with SystemParametersServer

use of io.jpom.service.system.SystemParametersServer in project Jpom by dromara.

the class IpInterceptor method preHandle.

@Override
protected boolean preHandle(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod) throws Exception {
    String clientIp = ServletUtil.getClientIP(request);
    if (StrUtil.equals(NetUtil.LOCAL_IP, clientIp)) {
        return true;
    }
    SystemParametersServer bean = SpringUtil.getBean(SystemParametersServer.class);
    SystemIpConfigModel config = bean.getConfig(SystemIpConfigModel.ID, SystemIpConfigModel.class);
    if (config == null) {
        return true;
    }
    // 判断不允许访问
    String prohibited = config.getProhibited();
    if (StrUtil.isNotEmpty(prohibited) && this.checkIp(prohibited, clientIp, false)) {
        ServletUtil.write(response, JsonMessage.getString(IP_ACCESS_CODE, "Prohibition of access"), MediaType.APPLICATION_JSON_VALUE);
        return false;
    }
    String allowed = config.getAllowed();
    if (StrUtil.isEmpty(allowed) || this.checkIp(allowed, clientIp, true)) {
        return true;
    }
    ServletUtil.write(response, JsonMessage.getString(IP_ACCESS_CODE, "Prohibition of access"), MediaType.APPLICATION_JSON_VALUE);
    return false;
}
Also used : SystemIpConfigModel(io.jpom.model.data.SystemIpConfigModel) SystemParametersServer(io.jpom.service.system.SystemParametersServer)

Example 4 with SystemParametersServer

use of io.jpom.service.system.SystemParametersServer in project Jpom by dromara.

the class JpomServerApplication method main.

/**
 * 启动执行
 * --rest:ip_config 重置 IP 白名单配置
 * --rest:load_init_db 重新加载数据库初始化操作
 * --rest:super_user_pwd 重置超级管理员密码
 * --recover:h2db 当 h2 数据出现奔溃无法启动需要执行恢复逻辑
 * --close:super_user_mfa 重置超级管理员 mfa
 *
 * @param args 参数
 * @throws Exception 异常
 */
public static void main(String[] args) throws Exception {
    long time = SystemClock.now();
    if (ArrayUtil.containsIgnoreCase(args, "--rest:load_init_db")) {
        loadInitDb = true;
    }
    if (ArrayUtil.containsIgnoreCase(args, "--recover:h2db")) {
        recoverH2Db = true;
    }
    // 
    JpomApplication jpomApplication = new JpomApplication(Type.Server, JpomServerApplication.class, args);
    jpomApplication.addInterceptor(IpInterceptor.class).addInterceptor(LoginInterceptor.class).addInterceptor(OpenApiInterceptor.class).addInterceptor(PermissionInterceptor.class).run(args);
    // 重置 ip 白名单配置
    if (ArrayUtil.containsIgnoreCase(args, "--rest:ip_config")) {
        SystemParametersServer parametersServer = SpringUtil.getBean(SystemParametersServer.class);
        parametersServer.delByKey(SystemIpConfigModel.ID);
        Console.log("Clear IP whitelist configuration successfully");
    }
    // 重置超级管理员密码
    if (ArrayUtil.containsIgnoreCase(args, "--rest:super_user_pwd")) {
        UserService userService = SpringUtil.getBean(UserService.class);
        String restResult = userService.restSuperUserPwd();
        if (restResult != null) {
            Console.log(restResult);
        } else {
            Console.log("There is no super administrator account in the system");
        }
    }
    // 关闭超级管理员 mfa
    if (ArrayUtil.containsIgnoreCase(args, "--close:super_user_mfa")) {
        UserService userService = SpringUtil.getBean(UserService.class);
        String restResult = userService.closeSuperUserMfa();
        if (restResult != null) {
            Console.log(restResult);
        } else {
            Console.log("There is no super administrator account in the system");
        }
    }
    Console.log("Time-consuming to start this time:{}", DateUtil.formatBetween(SystemClock.now() - time, BetweenFormatter.Level.MILLISECOND));
}
Also used : LoginInterceptor(io.jpom.common.interceptor.LoginInterceptor) UserService(io.jpom.service.user.UserService) PermissionInterceptor(io.jpom.common.interceptor.PermissionInterceptor) SystemParametersServer(io.jpom.service.system.SystemParametersServer)

Example 5 with SystemParametersServer

use of io.jpom.service.system.SystemParametersServer in project Jpom by dromara.

the class LoadJsonConfigToDb method loadIpConfig.

public void loadIpConfig() {
    File backupOldData = FileUtil.file(ConfigBean.getInstance().getDataPath(), "backup_old_data");
    // 读取 IP_CONFIG 文件内容
    File file = FileUtil.file(ConfigBean.getInstance().getDataPath(), ServerConfigBean.IP_CONFIG);
    if (!FileUtil.exist(file)) {
        return;
    }
    try {
        JSON json = JsonFileUtil.readJson(file.getAbsolutePath());
        SystemIpConfigModel systemIpConfigModel = json.toJavaObject(SystemIpConfigModel.class);
        if (systemIpConfigModel == null) {
            return;
        }
        SystemParametersServer parametersServer = SpringUtil.getBean(SystemParametersServer.class);
        parametersServer.upsert(SystemIpConfigModel.ID, systemIpConfigModel, SystemIpConfigModel.ID);
        // 将 json 文件转移到备份目录
        FileUtil.move(file, FileUtil.mkdir(backupOldData), true);
        DefaultSystemLog.getLog().info("{} mv to {}", FileUtil.getAbsolutePath(file), FileUtil.getAbsolutePath(backupOldData));
    } catch (Exception e) {
        DefaultSystemLog.getLog().error("load ip config error ", e);
    }
}
Also used : JSON(com.alibaba.fastjson.JSON) File(java.io.File) SystemParametersServer(io.jpom.service.system.SystemParametersServer)

Aggregations

SystemParametersServer (io.jpom.service.system.SystemParametersServer)5 JSON (com.alibaba.fastjson.JSON)3 File (java.io.File)3 LoginInterceptor (io.jpom.common.interceptor.LoginInterceptor)1 PermissionInterceptor (io.jpom.common.interceptor.PermissionInterceptor)1 SystemIpConfigModel (io.jpom.model.data.SystemIpConfigModel)1 UserService (io.jpom.service.user.UserService)1