use of io.jpom.permission.Feature 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, "修改成功");
}
use of io.jpom.permission.Feature in project Jpom by dromara.
the class SystemConfigController method saveConfig.
@PostMapping(value = "save_config.json", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EDIT)
@SystemPermission(superUser = true)
public String saveConfig(String nodeId, String content, String restart) throws IOException, SQLException {
if (StrUtil.isNotEmpty(nodeId)) {
return NodeForward.request(getNode(), getRequest(), NodeUrl.SystemSaveConfig).toString();
}
Assert.hasText(content, "内容不能为空");
try {
YamlPropertySourceLoader yamlPropertySourceLoader = new YamlPropertySourceLoader();
// @author hjk 前端编辑器允许使用tab键,并设定为2个空格,再转换为yml时要把tab键换成2个空格
ByteArrayResource resource = new ByteArrayResource(content.replace("\t", " ").getBytes(StandardCharsets.UTF_8));
yamlPropertySourceLoader.load("test", resource);
} catch (Exception e) {
DefaultSystemLog.getLog().warn("内容格式错误,请检查修正", e);
return JsonMessage.getString(500, "内容格式错误,请检查修正:" + e.getMessage());
}
boolean restartBool = Convert.toBool(restart, false);
// 修改数据库密码
DbExtConfig oldDbExtConfig = DbExtConfig.parse(ExtConfigBean.getResource().getInputStream());
DbExtConfig newDbExtConfig = DbExtConfig.parse(content);
if (!StrUtil.equals(oldDbExtConfig.getUserName(), newDbExtConfig.getUserName()) || !StrUtil.equals(oldDbExtConfig.getUserPwd(), newDbExtConfig.getUserPwd())) {
// 执行修改数据库账号密码
Assert.state(restartBool, "修改数据库密码必须重启");
initDb.alterUser(oldDbExtConfig.getUserName(), newDbExtConfig.getUserName(), newDbExtConfig.getUserPwd());
}
Assert.state(!JpomManifest.getInstance().isDebug(), "调试模式下不支持在线修改,请到resources目录下的bin目录修改extConfig.yml");
File resourceFile = ExtConfigBean.getResourceFile();
FileUtil.writeString(content, resourceFile, CharsetUtil.CHARSET_UTF_8);
if (restartBool) {
// 重启
ThreadUtil.execute(() -> {
ThreadUtil.sleep(2000);
JpomApplication.restart();
});
return JsonMessage.getString(200, Const.UPGRADE_MSG);
}
return JsonMessage.getString(200, "修改成功");
}
use of io.jpom.permission.Feature in project Jpom by dromara.
the class SystemConfigController method configData.
/**
* get server's config or node's config
* 加载服务端或者节点端配置
*
* @param nodeId 节点ID
* @return json
* @throws IOException io
* @author Hotstrip
*/
@RequestMapping(value = "config-data", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.LIST)
public String configData(String nodeId) throws IOException {
JSONObject jsonObject;
if (StrUtil.isNotEmpty(nodeId)) {
jsonObject = NodeForward.requestData(getNode(), NodeUrl.SystemGetConfig, getRequest(), JSONObject.class);
} else {
jsonObject = new JSONObject();
Resource resource = ExtConfigBean.getResource();
String content = IoUtil.read(resource.getInputStream(), CharsetUtil.CHARSET_UTF_8);
jsonObject.put("content", content);
jsonObject.put("file", FileUtil.getAbsolutePath(resource.getFile()));
}
return JsonMessage.getString(200, "", jsonObject);
}
use of io.jpom.permission.Feature in project Jpom by dromara.
the class SystemConfigController method saveNodeConfig.
@PostMapping(value = "save_node_config.json", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EDIT)
@SystemPermission(superUser = true)
public String saveNodeConfig(@ValidatorItem(msg = "请选择分发的节点") String nodeIds, String templateNodeId, String content, String restart) {
Assert.hasText(content, "内容不能为空");
HttpServletRequest httpServletRequest = getRequest();
String workspaceId = nodeService.getCheckUserWorkspace(httpServletRequest);
String id = StrUtil.format("node_config_{}", workspaceId);
JSONObject jsonObject = new JSONObject();
jsonObject.put("templateNodeId", templateNodeId);
jsonObject.put("nodeIds", nodeIds);
systemParametersServer.upsert(id, jsonObject, id);
//
List<String> nodeIdsStr = StrUtil.splitTrim(nodeIds, StrUtil.LF);
UserModel user = getUser();
for (String s : nodeIdsStr) {
NodeModel byKey = nodeService.getByKey(s, httpServletRequest);
JSONObject reqData = new JSONObject();
reqData.put("content", content);
reqData.put("restart", restart);
JsonMessage<String> request = NodeForward.request(byKey, NodeUrl.SystemSaveConfig, user, reqData);
Assert.state(request.getCode() == 200, "分发 " + byKey.getName() + " 节点配置失败" + request.getMsg());
}
return JsonMessage.getString(200, "修改成功");
}
use of io.jpom.permission.Feature in project Jpom by dromara.
the class SystemConfigController method saveWhitelist.
/**
* 保存白名单配置
*
* @return json
*/
@RequestMapping(value = "save_whitelist", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(cls = ClassFeature.SYSTEM_NODE_WHITELIST, method = MethodFeature.EDIT)
public String saveWhitelist(@ValidatorItem(msg = "请选择分发的节点") String nodeIds, String project, String certificate, String nginx, String allowEditSuffix, String allowRemoteDownloadHost) {
HttpServletRequest httpServletRequest = getRequest();
String workspaceId = nodeService.getCheckUserWorkspace(httpServletRequest);
NodeAgentWhitelist agentWhitelist = new NodeAgentWhitelist();
agentWhitelist.setNodeIds(nodeIds);
agentWhitelist.setProject(project);
agentWhitelist.setCertificate(certificate);
agentWhitelist.setNginx(nginx);
agentWhitelist.setAllowEditSuffix(allowEditSuffix);
agentWhitelist.setAllowRemoteDownloadHost(allowRemoteDownloadHost);
String format = StrUtil.format("node_whitelist_{}", workspaceId);
systemParametersServer.upsert(format, agentWhitelist, format);
//
List<String> nodeIdsStr = StrUtil.splitTrim(nodeIds, StrUtil.LF);
UserModel user = getUser();
for (String s : nodeIdsStr) {
NodeModel byKey = nodeService.getByKey(s, httpServletRequest);
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(agentWhitelist);
JsonMessage<String> request = NodeForward.request(byKey, NodeUrl.WhitelistDirectory_Submit, user, jsonObject);
Assert.state(request.getCode() == 200, "分发 " + byKey.getName() + " 节点配置失败" + request.getMsg());
}
return JsonMessage.getString(200, "保存成功");
}
Aggregations