Search in sources :

Example 1 with SystemIpConfigModel

use of io.jpom.model.data.SystemIpConfigModel 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 2 with SystemIpConfigModel

use of io.jpom.model.data.SystemIpConfigModel in project Jpom by dromara.

the class SystemConfigController method ipConfigData.

/**
 * 加载服务端的 ip 白名单配置
 *
 * @return json
 */
@RequestMapping(value = "ip-config-data", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(cls = ClassFeature.SYSTEM_CONFIG_IP, method = MethodFeature.LIST)
public String ipConfigData() {
    SystemIpConfigModel config = systemParametersServer.getConfig(SystemIpConfigModel.ID, SystemIpConfigModel.class);
    JSONObject jsonObject = new JSONObject();
    if (config != null) {
        jsonObject.put("allowed", config.getAllowed());
        jsonObject.put("prohibited", config.getProhibited());
    }
    // jsonObject.put("path", FileUtil.getAbsolutePath(systemIpConfigService.filePath()));
    jsonObject.put("ip", getIp());
    return JsonMessage.getString(200, "加载成功", jsonObject);
}
Also used : SystemIpConfigModel(io.jpom.model.data.SystemIpConfigModel) JSONObject(com.alibaba.fastjson.JSONObject) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with SystemIpConfigModel

use of io.jpom.model.data.SystemIpConfigModel in project Jpom by dromara.

the class SystemConfigController method saveIpConfig.

@RequestMapping(value = "save_ip_config.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(cls = ClassFeature.SYSTEM_CONFIG_IP, method = MethodFeature.EDIT)
public String saveIpConfig(String allowed, String prohibited) {
    SystemIpConfigModel systemIpConfigModel = new SystemIpConfigModel();
    String allowed1 = StrUtil.emptyToDefault(allowed, StrUtil.EMPTY);
    this.checkIpV4(allowed1);
    systemIpConfigModel.setAllowed(allowed1);
    // 
    String prohibited1 = StrUtil.emptyToDefault(prohibited, StrUtil.EMPTY);
    systemIpConfigModel.setProhibited(prohibited1);
    this.checkIpV4(prohibited1);
    systemParametersServer.upsert(SystemIpConfigModel.ID, systemIpConfigModel, SystemIpConfigModel.ID);
    // 
    return JsonMessage.getString(200, "修改成功");
}
Also used : SystemIpConfigModel(io.jpom.model.data.SystemIpConfigModel) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SystemIpConfigModel (io.jpom.model.data.SystemIpConfigModel)3 ClassFeature (io.jpom.permission.ClassFeature)2 Feature (io.jpom.permission.Feature)2 MethodFeature (io.jpom.permission.MethodFeature)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 JSONObject (com.alibaba.fastjson.JSONObject)1 SystemParametersServer (io.jpom.service.system.SystemParametersServer)1