code review
This commit is contained in:
parent
93539ccd97
commit
57639e78a1
@ -41,6 +41,7 @@ public class IpWhitelistController {
|
|||||||
return ApiResponse.success("删除成功");
|
return ApiResponse.success("删除成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//todo 要么分页写到@RequestParam,要么改用post
|
||||||
@GetMapping("/page")
|
@GetMapping("/page")
|
||||||
@Operation(summary = "分页查询IP白名单", description = "支持分页查询IP白名单列表")
|
@Operation(summary = "分页查询IP白名单", description = "支持分页查询IP白名单列表")
|
||||||
public ApiResponse<IPage<IpWhitelistResponse>> getWhitelistPage(@RequestBody IpWhitelistRequest req) {
|
public ApiResponse<IPage<IpWhitelistResponse>> getWhitelistPage(@RequestBody IpWhitelistRequest req) {
|
||||||
|
|||||||
@ -86,6 +86,7 @@ public class IpWhitelistFilter implements Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getClientIp(HttpServletRequest request) {
|
private String getClientIp(HttpServletRequest request) {
|
||||||
|
//todo 这几个header获取的ip可能是客户端伪造的
|
||||||
String[] headers = {
|
String[] headers = {
|
||||||
"X-Forwarded-For",
|
"X-Forwarded-For",
|
||||||
"Proxy-Client-IP",
|
"Proxy-Client-IP",
|
||||||
|
|||||||
@ -184,7 +184,7 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
|
|
||||||
String cidr = req.getIpv4() + "/" + maskLength;
|
String cidr = req.getIpv4() + "/" + maskLength;
|
||||||
|
//todo 这里需要判断hasGateway是否为true,再确定命令是否有 ipv4.gateway。
|
||||||
try {
|
try {
|
||||||
executeCommand("nmcli", "con", "mod", connectionName,
|
executeCommand("nmcli", "con", "mod", connectionName,
|
||||||
"ipv4.method", "manual",
|
"ipv4.method", "manual",
|
||||||
@ -411,7 +411,9 @@ public class NetworkConfigService {
|
|||||||
return "Bond [" + bondName + "] 删除成功";
|
return "Bond [" + bondName + "] 删除成功";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//todo
|
||||||
|
//这里是先删除物理网卡再添加bond,如果添加失败,那么之前删除的不可逆
|
||||||
|
//建议对添加的bondname和slaveList做存在性校验,再执行添加。 或者记录已删除连接 UUID/名称,失败后回滚。
|
||||||
public String addSlavesTOBond(BondAddSlavesRequest req) {
|
public String addSlavesTOBond(BondAddSlavesRequest req) {
|
||||||
String bondName = req.getBondName();
|
String bondName = req.getBondName();
|
||||||
List<String> slaves = req.getSlaveList();
|
List<String> slaves = req.getSlaveList();
|
||||||
@ -779,7 +781,7 @@ public class NetworkConfigService {
|
|||||||
String targetCidr = req.getTargetCidr();
|
String targetCidr = req.getTargetCidr();
|
||||||
String nextHop = req.getNextHop();
|
String nextHop = req.getNextHop();
|
||||||
|
|
||||||
|
//todo 对gatewayIp、targetCidr、nextHop增加格式校验。可用正则表达式
|
||||||
if (deviceName == null || deviceName.trim().isEmpty()) {
|
if (deviceName == null || deviceName.trim().isEmpty()) {
|
||||||
throw new IllegalArgumentException("网卡名称不能为空");
|
throw new IllegalArgumentException("网卡名称不能为空");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,12 +25,14 @@ public class TimeConfigServiceImpl implements TimeConfigService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String datetime = request.getDatetime();
|
String datetime = request.getDatetime();
|
||||||
|
//todo 建议用LocalDateTime进行校验格式
|
||||||
if (datetime == null || !datetime.matches("^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}$")) {
|
if (datetime == null || !datetime.matches("^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}$")) {
|
||||||
throw new IllegalArgumentException("Invalid or empty datetime format. Expected: YYYY-MM-DD HH:MM");
|
throw new IllegalArgumentException("Invalid or empty datetime format. Expected: YYYY-MM-DD HH:MM");
|
||||||
}
|
}
|
||||||
|
|
||||||
executeCommand("timedatectl set-timezone " + request.getTimezone().trim());
|
executeCommand("timedatectl set-timezone " + request.getTimezone().trim());
|
||||||
executeCommand("systemctl stop chronyd");
|
executeCommand("systemctl stop chronyd");
|
||||||
|
//todo 失败后重启chronyd
|
||||||
executeCommand("date -s '" + request.getDatetime() + "'");
|
executeCommand("date -s '" + request.getDatetime() + "'");
|
||||||
|
|
||||||
} else if ("NTP".equalsIgnoreCase(mode)) {
|
} else if ("NTP".equalsIgnoreCase(mode)) {
|
||||||
@ -39,7 +41,7 @@ public class TimeConfigServiceImpl implements TimeConfigService {
|
|||||||
if (servers == null || servers.isEmpty()) {
|
if (servers == null || servers.isEmpty()) {
|
||||||
throw new IllegalArgumentException("At least one NTP server IP must be provided in NTP mode");
|
throw new IllegalArgumentException("At least one NTP server IP must be provided in NTP mode");
|
||||||
}
|
}
|
||||||
|
//todo 参数校验SyncInterval:限制正数、范围或 2 的幂
|
||||||
int interval = request.getSyncInterval() != null ? request.getSyncInterval() : 600;
|
int interval = request.getSyncInterval() != null ? request.getSyncInterval() : 600;
|
||||||
int pollExp = (int) Math.round(Math.log(interval) / Math.log(2));
|
int pollExp = (int) Math.round(Math.log(interval) / Math.log(2));
|
||||||
StringBuilder serverConfLines = new StringBuilder();
|
StringBuilder serverConfLines = new StringBuilder();
|
||||||
@ -60,6 +62,7 @@ public class TimeConfigServiceImpl implements TimeConfigService {
|
|||||||
"driftfile /var/lib/chrony/drift\\n" +
|
"driftfile /var/lib/chrony/drift\\n" +
|
||||||
"makestep 1.0 3\\n" +
|
"makestep 1.0 3\\n" +
|
||||||
"rtcsync\\n";
|
"rtcsync\\n";
|
||||||
|
//todo 这里直接重写配置文件,如果失败则原配置丢失。建议备份,失败后回滚。
|
||||||
executeCommand("echo -e '" + confContent + "' > /etc/chrony.conf");
|
executeCommand("echo -e '" + confContent + "' > /etc/chrony.conf");
|
||||||
executeCommand("systemctl restart chronyd");
|
executeCommand("systemctl restart chronyd");
|
||||||
executeCommand("chronyc -a makestep");
|
executeCommand("chronyc -a makestep");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user