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;
}
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);
}
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, "修改成功");
}
Aggregations