Merge remote-tracking branch 'origin/V1.00' into V1.00
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.sunyard.cisd</groupId>
|
<groupId>com.sunyard.cisd</groupId>
|
||||||
<artifactId>device-fingerprint-tool</artifactId>
|
<artifactId>device-fingerprint-tool</artifactId>
|
||||||
<version>1.0.1</version>
|
<version>1.0.2</version>
|
||||||
<name>device-fingerprint-tool</name>
|
<name>device-fingerprint-tool</name>
|
||||||
<description>设备指纹信息获取工具</description>
|
<description>设备指纹信息获取工具</description>
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -58,11 +58,11 @@ public class DeviceFingerprintService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getCpuModel() {
|
private String getCpuModel() {
|
||||||
return executeCommand("dmidecode -t processor | grep \"Version\" | awk -F\\ '{print $2$3$4}'");
|
return executeCommand("sudo dmidecode -t processor | grep \"Version\" | awk -F\\ '{print $2$3$4}'");
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getCpuSerialNumber() {
|
private String getCpuSerialNumber() {
|
||||||
return executeCommand("dmidecode -t processor | grep \"Serial Number\" | awk -F\\ '{print $3}'");
|
return executeCommand("sudo dmidecode -t processor | grep \"Serial Number\" | awk -F\\ '{print $3}'");
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getHardDiskSerialNumber() {
|
private String getHardDiskSerialNumber() {
|
||||||
|
|||||||
@@ -128,7 +128,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.sunyard.cisd</groupId>
|
<groupId>com.sunyard.cisd</groupId>
|
||||||
<artifactId>device-fingerprint-tool</artifactId>
|
<artifactId>device-fingerprint-tool</artifactId>
|
||||||
<version>1.0.1</version>
|
<version>1.0.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -1,25 +1,13 @@
|
|||||||
package com.cisd.tms;
|
package com.cisd.tms;
|
||||||
|
|
||||||
import com.cisd.tms.common.crypto.config.ConfigCryptoCli;
|
import com.cisd.tms.common.crypto.config.ConfigCryptoCli;
|
||||||
import com.cisd.tms.modules.log.entity.OperationAuditLogEntity;
|
|
||||||
import com.cisd.tms.modules.log.enums.ActionType;
|
|
||||||
import com.cisd.tms.modules.log.enums.AuthLevel;
|
|
||||||
import com.cisd.tms.modules.log.enums.AuditStatus;
|
|
||||||
import com.cisd.tms.modules.log.enums.ModuleCode;
|
|
||||||
import com.cisd.tms.modules.log.enums.OperationResult;
|
|
||||||
import com.cisd.tms.modules.log.enums.OperatorRoleCode;
|
|
||||||
import com.cisd.tms.modules.log.repository.OperationAuditLogRepository;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
|
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@ConfigurationPropertiesScan
|
@ConfigurationPropertiesScan
|
||||||
@EnableScheduling
|
@EnableScheduling
|
||||||
|
|||||||
+23
-9
@@ -1,17 +1,31 @@
|
|||||||
package com.cisd.tms.infrastructure.persistence.mybatis;
|
package com.cisd.tms.infrastructure.persistence.mybatis;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||||
import java.time.LocalDateTime;
|
import com.cisd.tms.integration.crypto.pcie.service.JnaPcieCryptoService;
|
||||||
|
import com.cisd.tms.modules.datamac.helper.Sm2EntitySigner;
|
||||||
import com.cisd.tms.modules.datamac.helper.Sm3MacCalculator;
|
|
||||||
import org.apache.ibatis.reflection.MetaObject;
|
import org.apache.ibatis.reflection.MetaObject;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Primary
|
@Primary
|
||||||
public class CommonMetaObjectHandler implements MetaObjectHandler {
|
public class CommonMetaObjectHandler implements MetaObjectHandler {
|
||||||
|
|
||||||
|
@Lazy
|
||||||
|
@Autowired
|
||||||
|
private final JnaPcieCryptoService sdf;
|
||||||
|
|
||||||
|
public CommonMetaObjectHandler(@Lazy JnaPcieCryptoService cryptoService) {
|
||||||
|
this.sdf = cryptoService;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 密钥对的索引
|
||||||
|
private final int KEYPAIR_INDEX = 1;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void insertFill(MetaObject metaObject) {
|
public void insertFill(MetaObject metaObject) {
|
||||||
if ( metaObject.hasSetter("createTime") ) {
|
if ( metaObject.hasSetter("createTime") ) {
|
||||||
@@ -22,11 +36,11 @@ public class CommonMetaObjectHandler implements MetaObjectHandler {
|
|||||||
this.strictInsertFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
|
this.strictInsertFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 插入时,直接基于当前实体对象计算 MAC
|
// 插入时,直接基于当前实体对象计算签名
|
||||||
if (metaObject.hasSetter("mac")) {
|
if (metaObject.hasSetter("signature")) {
|
||||||
Object entity = metaObject.getOriginalObject();
|
Object entity = metaObject.getOriginalObject();
|
||||||
String mac = Sm3MacCalculator.calculateForEntity(entity);
|
String signature = Sm2EntitySigner.signMayNull(sdf, KEYPAIR_INDEX, entity);
|
||||||
this.strictInsertFill(metaObject, "mac", String.class, mac);
|
this.strictInsertFill(metaObject, "signature", String.class, signature);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,8 +52,8 @@ public class CommonMetaObjectHandler implements MetaObjectHandler {
|
|||||||
// 插入时,直接基于当前实体对象计算 MAC
|
// 插入时,直接基于当前实体对象计算 MAC
|
||||||
if (metaObject.hasSetter("mac")) {
|
if (metaObject.hasSetter("mac")) {
|
||||||
Object entity = metaObject.getOriginalObject();
|
Object entity = metaObject.getOriginalObject();
|
||||||
String mac = Sm3MacCalculator.calculateForEntity(entity);
|
String signature = Sm2EntitySigner.signMayNull(sdf, KEYPAIR_INDEX, entity);
|
||||||
this.strictInsertFill(metaObject, "mac", String.class, mac);
|
this.strictInsertFill(metaObject, "signature", String.class, signature);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
//import lombok.NoArgsConstructor;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -39,6 +42,7 @@ public class JnaPcieCryptoService implements PcieCryptoService {
|
|||||||
private final boolean strictAlgIdValidation;
|
private final boolean strictAlgIdValidation;
|
||||||
private final long recoverUserKeyAsyncDelayMillis;
|
private final long recoverUserKeyAsyncDelayMillis;
|
||||||
|
|
||||||
|
|
||||||
public JnaPcieCryptoService(PcieSessionTemplate sessionTemplate, CryptoCardProperties properties) {
|
public JnaPcieCryptoService(PcieSessionTemplate sessionTemplate, CryptoCardProperties properties) {
|
||||||
this(sessionTemplate, properties, RECOVER_USER_KEY_ASYNC_DELAY_MILLIS);
|
this(sessionTemplate, properties, RECOVER_USER_KEY_ASYNC_DELAY_MILLIS);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ public class KeyEntity extends BaseEntity {
|
|||||||
private String signData;
|
private String signData;
|
||||||
private String createBy;
|
private String createBy;
|
||||||
|
|
||||||
// 标记此字段在插入和更新时都需要自动填充
|
// 临时性添加。
|
||||||
|
// 改进方案可以通过直接扩展 BaseEntity 实现。暂时没有全量需求,所以单独添加。
|
||||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||||
private String mac;
|
private String signature;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -5,8 +5,8 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class DataMacEntity {
|
public class ImportantDataEntity {
|
||||||
// 标记此字段在插入和更新时都需要自动填充
|
// 标记此字段在插入和更新时都需要自动填充
|
||||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||||
private String mac;
|
private String signature;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package com.cisd.tms.modules.datamac.helper;
|
||||||
|
|
||||||
|
import com.cisd.tms.TmsApplication;
|
||||||
|
import com.cisd.tms.integration.crypto.pcie.model.BackupDataResult;
|
||||||
|
import com.cisd.tms.integration.crypto.pcie.model.UserKeySm2SignRequest;
|
||||||
|
import com.cisd.tms.integration.crypto.pcie.service.JnaPcieCryptoService;
|
||||||
|
import com.cisd.tms.integration.crypto.pcie.service.PcieCryptoService;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
public class Sm2EntitySigner {
|
||||||
|
|
||||||
|
private static final byte[] DEFAULT_SM2_USER_ID = "1234567812345678".getBytes(StandardCharsets.UTF_8);
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(Sm2EntitySigner.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对对象计算签名
|
||||||
|
* @param sdf
|
||||||
|
* @param keyIdx
|
||||||
|
* @param entity
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String signMayNull(PcieCryptoService sdf, int keyIdx, Object entity){
|
||||||
|
try {
|
||||||
|
return sign(sdf, keyIdx, entity);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("入库数据签名失败", e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对对象计算签名
|
||||||
|
* @param sdf
|
||||||
|
* @param keyIdx
|
||||||
|
* @param entity
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String sign(PcieCryptoService sdf, int keyIdx, Object entity){
|
||||||
|
// 1. 获取所有字段并按字段名排序,保证不同实体计算的顺序一致
|
||||||
|
Field[] fields = entity.getClass().getDeclaredFields();
|
||||||
|
Arrays.sort(fields, Comparator.comparing(Field::getName));
|
||||||
|
|
||||||
|
// 2. 构建待摘要的数据
|
||||||
|
StringBuilder dataBuilder = new StringBuilder();
|
||||||
|
for (Field field : fields) {
|
||||||
|
// 排除 signature 字段自身
|
||||||
|
if ("signature".equals(field.getName())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
field.setAccessible(true);
|
||||||
|
Object value = field.get(entity);
|
||||||
|
dataBuilder.append(field.getName()).append("=")
|
||||||
|
.append(value != null ? value.toString() : "")
|
||||||
|
.append(";");
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
// 适当的日志记录
|
||||||
|
throw new RuntimeException("Failed to read field: " + field.getName(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
UserKeySm2SignRequest request = new UserKeySm2SignRequest();
|
||||||
|
request.setKeyIndex(keyIdx);
|
||||||
|
request.setData(dataBuilder.toString().getBytes(StandardCharsets.UTF_8));
|
||||||
|
request.setUserId(DEFAULT_SM2_USER_ID);
|
||||||
|
|
||||||
|
BackupDataResult result = sdf.userKeySignWithSm2Sm3(request);
|
||||||
|
|
||||||
|
// Base64 格式返回
|
||||||
|
return java.util.Base64.getEncoder().encodeToString(result.getData());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -112,6 +112,7 @@ public class NetworkConfigService {
|
|||||||
List<String> result = new ArrayList<>();
|
List<String> result = new ArrayList<>();
|
||||||
|
|
||||||
List<String> lines = executeCommand(
|
List<String> lines = executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"-t",
|
"-t",
|
||||||
"-f",
|
"-f",
|
||||||
@@ -164,6 +165,7 @@ public class NetworkConfigService {
|
|||||||
List<String> result = new ArrayList<>();
|
List<String> result = new ArrayList<>();
|
||||||
|
|
||||||
List<String> lines = executeCommand(
|
List<String> lines = executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"-t",
|
"-t",
|
||||||
"-f",
|
"-f",
|
||||||
@@ -226,6 +228,7 @@ public class NetworkConfigService {
|
|||||||
int pageSize = req.getPageSize();
|
int pageSize = req.getPageSize();
|
||||||
|
|
||||||
List<String> lines = executeCommand(
|
List<String> lines = executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"-t",
|
"-t",
|
||||||
"-f",
|
"-f",
|
||||||
@@ -286,6 +289,7 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
if ("connected".equalsIgnoreCase(state)) {
|
if ("connected".equalsIgnoreCase(state)) {
|
||||||
List<String> infoLines = executeCommand(
|
List<String> infoLines = executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"-t",
|
"-t",
|
||||||
"-f",
|
"-f",
|
||||||
@@ -319,6 +323,7 @@ public class NetworkConfigService {
|
|||||||
if (connectionName != null && !connectionName.trim().isEmpty()) {
|
if (connectionName != null && !connectionName.trim().isEmpty()) {
|
||||||
try {
|
try {
|
||||||
List<String> conLines = executeCommand(
|
List<String> conLines = executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"-g",
|
"-g",
|
||||||
"ipv4.addresses,ipv4.gateway,ipv6.addresses,ipv6.gateway",
|
"ipv4.addresses,ipv4.gateway,ipv6.addresses,ipv6.gateway",
|
||||||
@@ -425,6 +430,7 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
if (isNewConnection) {
|
if (isNewConnection) {
|
||||||
cmdArgs = new ArrayList<>(Arrays.asList(
|
cmdArgs = new ArrayList<>(Arrays.asList(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"con",
|
"con",
|
||||||
"add",
|
"add",
|
||||||
@@ -441,6 +447,7 @@ public class NetworkConfigService {
|
|||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
cmdArgs = new ArrayList<>(Arrays.asList(
|
cmdArgs = new ArrayList<>(Arrays.asList(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"con",
|
"con",
|
||||||
"mod",
|
"mod",
|
||||||
@@ -474,14 +481,14 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
if ("Active".equalsIgnoreCase(status)) {
|
if ("Active".equalsIgnoreCase(status)) {
|
||||||
try {
|
try {
|
||||||
executeCommand("nmcli", "dev", "reapply", deviceName);
|
executeCommand("sudo", "nmcli", "dev", "reapply", deviceName);
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
log.warn("reapply 网卡 [{}] 失败,尝试重新激活连接 [{}]: {}", deviceName, connectionName, e.getMessage());
|
log.warn("reapply 网卡 [{}] 失败,尝试重新激活连接 [{}]: {}", deviceName, connectionName, e.getMessage());
|
||||||
executeCommand("nmcli", "con", "up", connectionName);
|
executeCommand("sudo", "nmcli", "con", "up", connectionName);
|
||||||
}
|
}
|
||||||
} else if ("Inactive".equalsIgnoreCase(status)) {
|
} else if ("Inactive".equalsIgnoreCase(status)) {
|
||||||
try {
|
try {
|
||||||
executeCommand("nmcli", "con", "down", connectionName);
|
executeCommand("sudo", "nmcli", "con", "down", connectionName);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("设置网卡为未激活时,down网卡操作抛出异常: {}", e.getMessage());
|
log.warn("设置网卡为未激活时,down网卡操作抛出异常: {}", e.getMessage());
|
||||||
}
|
}
|
||||||
@@ -526,6 +533,7 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
List<String> lines = executeCommand(
|
List<String> lines = executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"-g",
|
"-g",
|
||||||
addressesKey,
|
addressesKey,
|
||||||
@@ -574,6 +582,7 @@ public class NetworkConfigService {
|
|||||||
String newAddresses = String.join(",", remainAddressList);
|
String newAddresses = String.join(",", remainAddressList);
|
||||||
|
|
||||||
executeCommand(
|
executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"con",
|
"con",
|
||||||
"mod",
|
"mod",
|
||||||
@@ -630,7 +639,7 @@ public class NetworkConfigService {
|
|||||||
int pageNum = req.getPageNum();
|
int pageNum = req.getPageNum();
|
||||||
int pageSize = req.getPageSize();
|
int pageSize = req.getPageSize();
|
||||||
|
|
||||||
List<String> lines = executeCommand("nmcli", "-t", "-f", "NAME,TYPE,DEVICE", "con", "show");
|
List<String> lines = executeCommand("sudo", "nmcli", "-t", "-f", "NAME,TYPE,DEVICE", "con", "show");
|
||||||
|
|
||||||
for (String line : lines) {
|
for (String line : lines) {
|
||||||
if (line == null || line.trim().isEmpty()) {
|
if (line == null || line.trim().isEmpty()) {
|
||||||
@@ -665,6 +674,7 @@ public class NetworkConfigService {
|
|||||||
List<String> slaveList = getBondSlaves(bondName);
|
List<String> slaveList = getBondSlaves(bondName);
|
||||||
|
|
||||||
List<String> conLines = executeCommand(
|
List<String> conLines = executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"-g",
|
"-g",
|
||||||
"IPv4.ADDRESSES,IPv4.GATEWAY,IPv6.ADDRESSES,IPv6.GATEWAY",
|
"IPv4.ADDRESSES,IPv4.GATEWAY,IPv6.ADDRESSES,IPv6.GATEWAY",
|
||||||
@@ -718,6 +728,7 @@ public class NetworkConfigService {
|
|||||||
Map<String, String> result = new HashMap<>();
|
Map<String, String> result = new HashMap<>();
|
||||||
|
|
||||||
List<String> lines = executeCommand(
|
List<String> lines = executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"-t",
|
"-t",
|
||||||
"-f",
|
"-f",
|
||||||
@@ -765,7 +776,7 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
validateIpAndPrefix(ipAddress, gateway, prefixLength, isIpv6);
|
validateIpAndPrefix(ipAddress, gateway, prefixLength, isIpv6);
|
||||||
|
|
||||||
List<String> lines = executeCommand("nmcli", "-g", "NAME", "con", "show");
|
List<String> lines = executeCommand("sudo", "nmcli", "-g", "NAME", "con", "show");
|
||||||
for (String line : lines) {
|
for (String line : lines) {
|
||||||
if (bondName.equals(line.trim())) {
|
if (bondName.equals(line.trim())) {
|
||||||
throw new BizException(
|
throw new BizException(
|
||||||
@@ -786,6 +797,7 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
executeCommand(
|
executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"con",
|
"con",
|
||||||
"add",
|
"add",
|
||||||
@@ -800,6 +812,7 @@ public class NetworkConfigService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
List<String> ipCmdArgs = new ArrayList<>(Arrays.asList(
|
List<String> ipCmdArgs = new ArrayList<>(Arrays.asList(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"con",
|
"con",
|
||||||
"mod",
|
"mod",
|
||||||
@@ -838,6 +851,7 @@ public class NetworkConfigService {
|
|||||||
oldConnectionSnapshots.addAll(downOldConnectionByDevice(slaveName));
|
oldConnectionSnapshots.addAll(downOldConnectionByDevice(slaveName));
|
||||||
|
|
||||||
executeCommand(
|
executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"con",
|
"con",
|
||||||
"add",
|
"add",
|
||||||
@@ -854,7 +868,7 @@ public class NetworkConfigService {
|
|||||||
createdSlaveConnectionNames.add(slaveConnectionName);
|
createdSlaveConnectionNames.add(slaveConnectionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
executeCommand("nmcli", "con", "up", bondName);
|
executeCommand("sudo", "nmcli", "con", "up", bondName);
|
||||||
|
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
rollbackCreateBond(bondName, createdSlaveConnectionNames, oldConnectionSnapshots);
|
rollbackCreateBond(bondName, createdSlaveConnectionNames, oldConnectionSnapshots);
|
||||||
@@ -893,6 +907,7 @@ public class NetworkConfigService {
|
|||||||
String bondOptions = String.format("mode=%s,miimon=100", mapBondMode(mode));
|
String bondOptions = String.format("mode=%s,miimon=100", mapBondMode(mode));
|
||||||
|
|
||||||
executeCommand(
|
executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"con",
|
"con",
|
||||||
"mod",
|
"mod",
|
||||||
@@ -902,6 +917,7 @@ public class NetworkConfigService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
List<String> ipCmdArgs = new ArrayList<>(Arrays.asList(
|
List<String> ipCmdArgs = new ArrayList<>(Arrays.asList(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"con",
|
"con",
|
||||||
"mod",
|
"mod",
|
||||||
@@ -931,10 +947,10 @@ public class NetworkConfigService {
|
|||||||
syncBondSlaves(bondName, newSlaveList);
|
syncBondSlaves(bondName, newSlaveList);
|
||||||
|
|
||||||
if ("Active".equalsIgnoreCase(status)) {
|
if ("Active".equalsIgnoreCase(status)) {
|
||||||
executeCommand("nmcli", "con", "up", bondName);
|
executeCommand("sudo", "nmcli", "con", "up", bondName);
|
||||||
} else if ("Inactive".equalsIgnoreCase(status)) {
|
} else if ("Inactive".equalsIgnoreCase(status)) {
|
||||||
try {
|
try {
|
||||||
executeCommand("nmcli", "con", "down", bondName);
|
executeCommand("sudo", "nmcli", "con", "down", bondName);
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
log.warn("停用 Bond [{}] 失败: {}", bondName, e.getMessage());
|
log.warn("停用 Bond [{}] 失败: {}", bondName, e.getMessage());
|
||||||
}
|
}
|
||||||
@@ -967,6 +983,7 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
List<String> lines = executeCommand(
|
List<String> lines = executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"-t",
|
"-t",
|
||||||
"-f",
|
"-f",
|
||||||
@@ -997,6 +1014,7 @@ public class NetworkConfigService {
|
|||||||
if ("ethernet".equals(type) || "802-3-ethernet".equals(type)) {
|
if ("ethernet".equals(type) || "802-3-ethernet".equals(type)) {
|
||||||
try {
|
try {
|
||||||
List<String> masterLines = executeCommand(
|
List<String> masterLines = executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"-g",
|
"-g",
|
||||||
"connection.master",
|
"connection.master",
|
||||||
@@ -1026,13 +1044,13 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
for (String uuid : uuidToDeleteList) {
|
for (String uuid : uuidToDeleteList) {
|
||||||
try {
|
try {
|
||||||
executeCommand("nmcli", "con", "down", "uuid", uuid);
|
executeCommand("sudo", "nmcli", "con", "down", "uuid", uuid);
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
log.warn("停用 Bond 从属连接 [{}] 失败,继续删除: {}", uuid, e.getMessage());
|
log.warn("停用 Bond 从属连接 [{}] 失败,继续删除: {}", uuid, e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
executeCommand("nmcli", "con", "delete", "uuid", uuid);
|
executeCommand("sudo", "nmcli", "con", "delete", "uuid", uuid);
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
throw new BizException(
|
throw new BizException(
|
||||||
ErrorCode.BIZ_ERROR.getCode(),
|
ErrorCode.BIZ_ERROR.getCode(),
|
||||||
@@ -1042,12 +1060,12 @@ public class NetworkConfigService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
executeCommand("nmcli", "con", "down", "uuid", bondUuid);
|
executeCommand("sudo", "nmcli", "con", "down", "uuid", bondUuid);
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
log.warn("停用 Bond 主连接 [{}] 失败,继续删除: {}", bondName, e.getMessage());
|
log.warn("停用 Bond 主连接 [{}] 失败,继续删除: {}", bondName, e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
executeCommand("nmcli", "con", "delete", "uuid", bondUuid);
|
executeCommand("sudo", "nmcli", "con", "delete", "uuid", bondUuid);
|
||||||
|
|
||||||
} catch (BizException e) {
|
} catch (BizException e) {
|
||||||
throw e;
|
throw e;
|
||||||
@@ -1118,6 +1136,7 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
executeCommand(
|
executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"con",
|
"con",
|
||||||
"mod",
|
"mod",
|
||||||
@@ -1224,6 +1243,7 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
executeCommand(
|
executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"con",
|
"con",
|
||||||
"mod",
|
"mod",
|
||||||
@@ -1233,6 +1253,7 @@ public class NetworkConfigService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
executeCommand(
|
executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"con",
|
"con",
|
||||||
"mod",
|
"mod",
|
||||||
@@ -1289,6 +1310,7 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
executeCommand(
|
executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"con",
|
"con",
|
||||||
"mod",
|
"mod",
|
||||||
@@ -1314,6 +1336,7 @@ public class NetworkConfigService {
|
|||||||
Set<String> result = new HashSet<>();
|
Set<String> result = new HashSet<>();
|
||||||
|
|
||||||
List<String> lines = executeCommand(
|
List<String> lines = executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"-t",
|
"-t",
|
||||||
"-f",
|
"-f",
|
||||||
@@ -1352,6 +1375,7 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
private void clearProtocolConfig(String connectionName, String protocol) {
|
private void clearProtocolConfig(String connectionName, String protocol) {
|
||||||
executeCommand(
|
executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"con",
|
"con",
|
||||||
"mod",
|
"mod",
|
||||||
@@ -1439,6 +1463,7 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
executeCommand(
|
executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"con",
|
"con",
|
||||||
"mod",
|
"mod",
|
||||||
@@ -1500,6 +1525,7 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
executeCommand(
|
executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"con",
|
"con",
|
||||||
"mod",
|
"mod",
|
||||||
@@ -1525,6 +1551,7 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
List<String> lines = executeCommand(
|
List<String> lines = executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"-g",
|
"-g",
|
||||||
routeKey,
|
routeKey,
|
||||||
@@ -1553,6 +1580,7 @@ public class NetworkConfigService {
|
|||||||
try {
|
try {
|
||||||
if (snapshot.bondOptions != null && !snapshot.bondOptions.trim().isEmpty()) {
|
if (snapshot.bondOptions != null && !snapshot.bondOptions.trim().isEmpty()) {
|
||||||
executeCommand(
|
executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"con",
|
"con",
|
||||||
"mod",
|
"mod",
|
||||||
@@ -1567,6 +1595,7 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
List<String> ipv4Args = new ArrayList<>(Arrays.asList(
|
List<String> ipv4Args = new ArrayList<>(Arrays.asList(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"con",
|
"con",
|
||||||
"mod",
|
"mod",
|
||||||
@@ -1588,6 +1617,7 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
List<String> ipv6Args = new ArrayList<>(Arrays.asList(
|
List<String> ipv6Args = new ArrayList<>(Arrays.asList(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"con",
|
"con",
|
||||||
"mod",
|
"mod",
|
||||||
@@ -1615,10 +1645,10 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (snapshot.active) {
|
if (snapshot.active) {
|
||||||
executeCommand("nmcli", "con", "up", bondName);
|
executeCommand("sudo", "nmcli", "con", "up", bondName);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
executeCommand("nmcli", "con", "down", bondName);
|
executeCommand("sudo", "nmcli", "con", "down", bondName);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("回滚停用 Bond [{}] 失败: {}", bondName, e.getMessage());
|
log.warn("回滚停用 Bond [{}] 失败: {}", bondName, e.getMessage());
|
||||||
}
|
}
|
||||||
@@ -1631,6 +1661,7 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
private BondConfigSnapshot snapshotBondConfig(String bondName) {
|
private BondConfigSnapshot snapshotBondConfig(String bondName) {
|
||||||
List<String> lines = executeCommand(
|
List<String> lines = executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"-g",
|
"-g",
|
||||||
"bond.options,IPv4.METHOD,IPv4.ADDRESSES,IPv4.GATEWAY,IPv6.METHOD,IPv6.ADDRESSES,IPv6.GATEWAY",
|
"bond.options,IPv4.METHOD,IPv4.ADDRESSES,IPv4.GATEWAY,IPv6.METHOD,IPv6.ADDRESSES,IPv6.GATEWAY",
|
||||||
@@ -1685,6 +1716,7 @@ public class NetworkConfigService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<String> activeUuids = executeCommand(
|
List<String> activeUuids = executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"-t",
|
"-t",
|
||||||
"-f",
|
"-f",
|
||||||
@@ -1695,6 +1727,7 @@ public class NetworkConfigService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
List<String> lines = executeCommand(
|
List<String> lines = executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"-t",
|
"-t",
|
||||||
"-f",
|
"-f",
|
||||||
@@ -1726,6 +1759,7 @@ public class NetworkConfigService {
|
|||||||
String interfaceName = "";
|
String interfaceName = "";
|
||||||
try {
|
try {
|
||||||
List<String> ifLines = executeCommand(
|
List<String> ifLines = executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"-g",
|
"-g",
|
||||||
"connection.interface-name",
|
"connection.interface-name",
|
||||||
@@ -1750,6 +1784,7 @@ public class NetworkConfigService {
|
|||||||
String autoconnect = "yes";
|
String autoconnect = "yes";
|
||||||
try {
|
try {
|
||||||
List<String> autoLines = executeCommand(
|
List<String> autoLines = executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"-g",
|
"-g",
|
||||||
"connection.autoconnect",
|
"connection.autoconnect",
|
||||||
@@ -1773,6 +1808,7 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
executeCommand(
|
executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"con",
|
"con",
|
||||||
"modify",
|
"modify",
|
||||||
@@ -1788,7 +1824,7 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
if (active) {
|
if (active) {
|
||||||
try {
|
try {
|
||||||
executeCommand("nmcli", "con", "down", "uuid", uuid);
|
executeCommand("sudo", "nmcli", "con", "down", "uuid", uuid);
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
log.warn("停用旧连接 [{}] 失败,uuid: {}, 原因: {}", name, uuid, e.getMessage());
|
log.warn("停用旧连接 [{}] 失败,uuid: {}, 原因: {}", name, uuid, e.getMessage());
|
||||||
}
|
}
|
||||||
@@ -1886,6 +1922,7 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
List<String> lines = executeCommand(
|
List<String> lines = executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"-t",
|
"-t",
|
||||||
"-f",
|
"-f",
|
||||||
@@ -1916,6 +1953,7 @@ public class NetworkConfigService {
|
|||||||
String interfaceName = "";
|
String interfaceName = "";
|
||||||
try {
|
try {
|
||||||
List<String> interfaceLines = executeCommand(
|
List<String> interfaceLines = executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"-g",
|
"-g",
|
||||||
"connection.interface-name",
|
"connection.interface-name",
|
||||||
@@ -1971,13 +2009,13 @@ public class NetworkConfigService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
executeCommand("nmcli", "con", "down", slaveConnectionName);
|
executeCommand("sudo", "nmcli", "con", "down", slaveConnectionName);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("回滚停用 Bond 从属连接失败: {}, 原因: {}", slaveConnectionName, e.getMessage());
|
log.warn("回滚停用 Bond 从属连接失败: {}, 原因: {}", slaveConnectionName, e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
executeCommand("nmcli", "con", "delete", slaveConnectionName);
|
executeCommand("sudo", "nmcli", "con", "delete", slaveConnectionName);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("回滚删除 Bond 从属连接失败: {}, 原因: {}", slaveConnectionName, e.getMessage());
|
log.warn("回滚删除 Bond 从属连接失败: {}, 原因: {}", slaveConnectionName, e.getMessage());
|
||||||
}
|
}
|
||||||
@@ -1987,13 +2025,13 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
if (bondName != null && !bondName.trim().isEmpty()) {
|
if (bondName != null && !bondName.trim().isEmpty()) {
|
||||||
try {
|
try {
|
||||||
executeCommand("nmcli", "con", "down", bondName);
|
executeCommand("sudo", "nmcli", "con", "down", bondName);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("回滚停用 Bond 主连接失败: {}, 原因: {}", bondName, e.getMessage());
|
log.warn("回滚停用 Bond 主连接失败: {}, 原因: {}", bondName, e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
executeCommand("nmcli", "con", "delete", bondName);
|
executeCommand("sudo", "nmcli", "con", "delete", bondName);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("回滚删除 Bond 主连接失败: {}, 原因: {}", bondName, e.getMessage());
|
log.warn("回滚删除 Bond 主连接失败: {}, 原因: {}", bondName, e.getMessage());
|
||||||
}
|
}
|
||||||
@@ -2013,6 +2051,7 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
executeCommand(
|
executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"con",
|
"con",
|
||||||
"modify",
|
"modify",
|
||||||
@@ -2027,7 +2066,7 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
if (snapshot.active) {
|
if (snapshot.active) {
|
||||||
try {
|
try {
|
||||||
executeCommand("nmcli", "con", "up", "uuid", uuid);
|
executeCommand("sudo", "nmcli", "con", "up", "uuid", uuid);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("回滚恢复旧连接激活失败,uuid: {}, 原因: {}", uuid, e.getMessage());
|
log.warn("回滚恢复旧连接激活失败,uuid: {}, 原因: {}", uuid, e.getMessage());
|
||||||
}
|
}
|
||||||
@@ -2046,6 +2085,7 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
List<String> lines = executeCommand(
|
List<String> lines = executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"-g",
|
"-g",
|
||||||
"connection.type",
|
"connection.type",
|
||||||
@@ -2108,7 +2148,7 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
|
|
||||||
private void checkSlaveDevicesExist(List<String> slaveList) {
|
private void checkSlaveDevicesExist(List<String> slaveList) {
|
||||||
List<String> deviceLines = executeCommand("nmcli", "-t", "-f", "DEVICE,TYPE", "dev");
|
List<String> deviceLines = executeCommand("sudo", "nmcli", "-t", "-f", "DEVICE,TYPE", "dev");
|
||||||
|
|
||||||
for (String slave : slaveList) {
|
for (String slave : slaveList) {
|
||||||
String slaveName = slave.trim();
|
String slaveName = slave.trim();
|
||||||
@@ -2153,6 +2193,7 @@ public class NetworkConfigService {
|
|||||||
private boolean isConnectionActive(String connectionName) {
|
private boolean isConnectionActive(String connectionName) {
|
||||||
try {
|
try {
|
||||||
List<String> lines = executeCommand(
|
List<String> lines = executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"-t",
|
"-t",
|
||||||
"-f",
|
"-f",
|
||||||
@@ -2274,6 +2315,7 @@ public class NetworkConfigService {
|
|||||||
Map<String, String> statusMap = new HashMap<>();
|
Map<String, String> statusMap = new HashMap<>();
|
||||||
|
|
||||||
List<String> lines = executeCommand(
|
List<String> lines = executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"-t",
|
"-t",
|
||||||
"-f",
|
"-f",
|
||||||
@@ -2361,10 +2403,10 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
private void applyConnection(String connectionName, String interfaceName) {
|
private void applyConnection(String connectionName, String interfaceName) {
|
||||||
try {
|
try {
|
||||||
executeCommand("nmcli", "dev", "reapply", interfaceName);
|
executeCommand("sudo", "nmcli", "dev", "reapply", interfaceName);
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
log.warn("reapply 网口 [{}] 失败,尝试重新激活连接 [{}]: {}", interfaceName, connectionName, e.getMessage());
|
log.warn("reapply 网口 [{}] 失败,尝试重新激活连接 [{}]: {}", interfaceName, connectionName, e.getMessage());
|
||||||
executeCommand("nmcli", "con", "up", connectionName);
|
executeCommand("sudo", "nmcli", "con", "up", connectionName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2401,6 +2443,7 @@ public class NetworkConfigService {
|
|||||||
oldConnectionSnapshots.addAll(downOldConnectionByDevice(slaveName));
|
oldConnectionSnapshots.addAll(downOldConnectionByDevice(slaveName));
|
||||||
|
|
||||||
executeCommand(
|
executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"con",
|
"con",
|
||||||
"add",
|
"add",
|
||||||
@@ -2417,7 +2460,7 @@ public class NetworkConfigService {
|
|||||||
createdSlaveConnectionNames.add(slaveConnectionName);
|
createdSlaveConnectionNames.add(slaveConnectionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
executeCommand("nmcli", "con", "up", bondName);
|
executeCommand("sudo", "nmcli", "con", "up", bondName);
|
||||||
|
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
rollbackAddSlavesToBond(createdSlaveConnectionNames, oldConnectionSnapshots);
|
rollbackAddSlavesToBond(createdSlaveConnectionNames, oldConnectionSnapshots);
|
||||||
@@ -2464,18 +2507,18 @@ public class NetworkConfigService {
|
|||||||
try {
|
try {
|
||||||
for (BondSlaveSnapshot snapshot : targetSlaveSnapshots) {
|
for (BondSlaveSnapshot snapshot : targetSlaveSnapshots) {
|
||||||
try {
|
try {
|
||||||
executeCommand("nmcli", "con", "down", "uuid", snapshot.uuid);
|
executeCommand("sudo", "nmcli", "con", "down", "uuid", snapshot.uuid);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("停用从属网卡连接 [{}] 失败,忽略并继续删除: {}", snapshot.name, e.getMessage());
|
log.warn("停用从属网卡连接 [{}] 失败,忽略并继续删除: {}", snapshot.name, e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
executeCommand("nmcli", "con", "delete", "uuid", snapshot.uuid);
|
executeCommand("sudo", "nmcli", "con", "delete", "uuid", snapshot.uuid);
|
||||||
deletedSlaveSnapshots.add(snapshot);
|
deletedSlaveSnapshots.add(snapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!deletedSlaveSnapshots.isEmpty()) {
|
if (!deletedSlaveSnapshots.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
executeCommand("nmcli", "con", "up", bondName);
|
executeCommand("sudo", "nmcli", "con", "up", bondName);
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
rollbackDeletedBondSlaves(bondName, deletedSlaveSnapshots);
|
rollbackDeletedBondSlaves(bondName, deletedSlaveSnapshots);
|
||||||
throw new BizException(
|
throw new BizException(
|
||||||
@@ -2508,6 +2551,7 @@ public class NetworkConfigService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<String> lines = executeCommand(
|
List<String> lines = executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"-t",
|
"-t",
|
||||||
"-f",
|
"-f",
|
||||||
@@ -2562,6 +2606,7 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
List<String> detailLines = executeCommand(
|
List<String> detailLines = executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"-g",
|
"-g",
|
||||||
"connection.master,connection.interface-name",
|
"connection.master,connection.interface-name",
|
||||||
@@ -2627,6 +2672,7 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
executeCommand(
|
executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"con",
|
"con",
|
||||||
"add",
|
"add",
|
||||||
@@ -2651,7 +2697,7 @@ public class NetworkConfigService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
executeCommand("nmcli", "con", "up", bondName);
|
executeCommand("sudo", "nmcli", "con", "up", bondName);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("恢复 Bond [{}] 激活失败: {}", bondName, e.getMessage());
|
log.warn("恢复 Bond [{}] 激活失败: {}", bondName, e.getMessage());
|
||||||
}
|
}
|
||||||
@@ -2668,13 +2714,13 @@ public class NetworkConfigService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
executeCommand("nmcli", "con", "down", slaveConnectionName);
|
executeCommand("sudo", "nmcli", "con", "down", slaveConnectionName);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("回滚停用 Bond 从属连接 [{}] 失败: {}", slaveConnectionName, e.getMessage());
|
log.warn("回滚停用 Bond 从属连接 [{}] 失败: {}", slaveConnectionName, e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
executeCommand("nmcli", "con", "delete", slaveConnectionName);
|
executeCommand("sudo", "nmcli", "con", "delete", slaveConnectionName);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("回滚删除 Bond 从属连接 [{}] 失败: {}", slaveConnectionName, e.getMessage());
|
log.warn("回滚删除 Bond 从属连接 [{}] 失败: {}", slaveConnectionName, e.getMessage());
|
||||||
}
|
}
|
||||||
@@ -2686,7 +2732,7 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
private void checkConnectionNameNotExists(String connectionName) {
|
private void checkConnectionNameNotExists(String connectionName) {
|
||||||
try {
|
try {
|
||||||
executeCommand("nmcli", "con", "show", connectionName);
|
executeCommand("sudo", "nmcli", "con", "show", connectionName);
|
||||||
|
|
||||||
throw new BizException(
|
throw new BizException(
|
||||||
ErrorCode.BIZ_ERROR.getCode(),
|
ErrorCode.BIZ_ERROR.getCode(),
|
||||||
@@ -2717,6 +2763,7 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
executeCommand(
|
executeCommand(
|
||||||
|
"sudo",
|
||||||
"nmcli",
|
"nmcli",
|
||||||
"con",
|
"con",
|
||||||
"modify",
|
"modify",
|
||||||
@@ -2731,7 +2778,7 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
if (snapshot.active) {
|
if (snapshot.active) {
|
||||||
try {
|
try {
|
||||||
executeCommand("nmcli", "con", "up", "uuid", uuid);
|
executeCommand("sudo", "nmcli", "con", "up", "uuid", uuid);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("恢复旧连接激活失败,uuid: {}, 原因: {}", uuid, e.getMessage());
|
log.warn("恢复旧连接激活失败,uuid: {}, 原因: {}", uuid, e.getMessage());
|
||||||
}
|
}
|
||||||
@@ -2781,7 +2828,7 @@ public class NetworkConfigService {
|
|||||||
List<String> slaveList = new ArrayList<>();
|
List<String> slaveList = new ArrayList<>();
|
||||||
List<String> lines;
|
List<String> lines;
|
||||||
try {
|
try {
|
||||||
lines = executeCommand("nmcli", "-t", "-f", "UUID,DEVICE,NAME,TYPE", "con", "show");
|
lines = executeCommand("sudo", "nmcli", "-t", "-f", "UUID,DEVICE,NAME,TYPE", "con", "show");
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
throw new BizException(ErrorCode.BIZ_ERROR.getCode(), "查询 Bond 从属网卡列表失败");
|
throw new BizException(ErrorCode.BIZ_ERROR.getCode(), "查询 Bond 从属网卡列表失败");
|
||||||
}
|
}
|
||||||
@@ -2805,7 +2852,7 @@ public class NetworkConfigService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (type != null && type.contains("ethernet")) {
|
if (type != null && type.contains("ethernet")) {
|
||||||
List<String> masterOutputs = executeCommand("nmcli", "-g", "connection.master", "con", "show", uuid);
|
List<String> masterOutputs = executeCommand("sudo", "nmcli", "-g", "connection.master", "con", "show", uuid);
|
||||||
String master = masterOutputs.isEmpty() ? "" : masterOutputs.get(0).trim();
|
String master = masterOutputs.isEmpty() ? "" : masterOutputs.get(0).trim();
|
||||||
|
|
||||||
if (bondName.equals(master)) {
|
if (bondName.equals(master)) {
|
||||||
@@ -2837,7 +2884,7 @@ public class NetworkConfigService {
|
|||||||
|
|
||||||
List<String> lines;
|
List<String> lines;
|
||||||
try {
|
try {
|
||||||
lines = executeCommand("nmcli", "-g", "bond.options", "con", "show", bondName);
|
lines = executeCommand("sudo", "nmcli", "-g", "bond.options", "con", "show", bondName);
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
throw new BizException(ErrorCode.BIZ_ERROR.getCode(), "读取 Bond 配置信息失败,请检查名称 [" + bondName + "] 是否存在");
|
throw new BizException(ErrorCode.BIZ_ERROR.getCode(), "读取 Bond 配置信息失败,请检查名称 [" + bondName + "] 是否存在");
|
||||||
}
|
}
|
||||||
@@ -2874,7 +2921,7 @@ public class NetworkConfigService {
|
|||||||
private String getConnectionNameByDeviceName(String deviceName) {
|
private String getConnectionNameByDeviceName(String deviceName) {
|
||||||
if (deviceName == null || deviceName.trim().isEmpty()) return null;
|
if (deviceName == null || deviceName.trim().isEmpty()) return null;
|
||||||
try {
|
try {
|
||||||
List<String> lines = executeCommand("nmcli", "-t", "-f", "DEVICE,CONNECTION", "dev", "status");
|
List<String> lines = executeCommand("sudo", "nmcli", "-t", "-f", "DEVICE,CONNECTION", "dev", "status");
|
||||||
|
|
||||||
for (String line : lines) {
|
for (String line : lines) {
|
||||||
String[] parts = line.split("(?<!\\\\):", -1);
|
String[] parts = line.split("(?<!\\\\):", -1);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.cisd.tms.modules.datamac.entity.DataMacEntity;
|
import com.cisd.tms.modules.datamac.entity.ImportantDataEntity;
|
||||||
import com.cisd.tms.modules.log.enums.*;
|
import com.cisd.tms.modules.log.enums.*;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
@@ -14,7 +14,7 @@ import java.time.LocalDateTime;
|
|||||||
@Data
|
@Data
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
@TableName("tms_operation_audit_log")
|
@TableName("tms_operation_audit_log")
|
||||||
public class OperationAuditLogEntity extends DataMacEntity {
|
public class OperationAuditLogEntity extends ImportantDataEntity {
|
||||||
@TableId(type = IdType.ASSIGN_ID)
|
@TableId(type = IdType.ASSIGN_ID)
|
||||||
private Long id;
|
private Long id;
|
||||||
private String logId;
|
private String logId;
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import com.cisd.tms.integration.crypto.pcie.model.BackupDataResult;
|
|||||||
import com.cisd.tms.integration.crypto.pcie.model.EccExternalVerifyRequest;
|
import com.cisd.tms.integration.crypto.pcie.model.EccExternalVerifyRequest;
|
||||||
import com.cisd.tms.integration.crypto.pcie.model.UserKeySm2SignRequest;
|
import com.cisd.tms.integration.crypto.pcie.model.UserKeySm2SignRequest;
|
||||||
import com.cisd.tms.integration.crypto.pcie.service.JnaPcieCryptoService;
|
import com.cisd.tms.integration.crypto.pcie.service.JnaPcieCryptoService;
|
||||||
|
import com.cisd.tms.integration.crypto.pcie.service.PcieCryptoService;
|
||||||
import com.cisd.tms.modules.cert.entity.KeyEntity;
|
import com.cisd.tms.modules.cert.entity.KeyEntity;
|
||||||
import com.cisd.tms.modules.cert.service.CertificateService;
|
import com.cisd.tms.modules.cert.service.CertificateService;
|
||||||
import com.cisd.tms.modules.cert.service.EntityService;
|
import com.cisd.tms.modules.cert.service.EntityService;
|
||||||
@@ -31,7 +32,7 @@ public class OpenApiService implements IOpenApiService {
|
|||||||
private static final Logger log = LoggerFactory.getLogger(OpenApiService.class);
|
private static final Logger log = LoggerFactory.getLogger(OpenApiService.class);
|
||||||
|
|
||||||
private final PcieSessionTemplate sessionTemplate;
|
private final PcieSessionTemplate sessionTemplate;
|
||||||
private final JnaPcieCryptoService sdf;
|
private final PcieCryptoService sdf;
|
||||||
|
|
||||||
// 签名验签均从证书 dn 作为索引,所以引入证书服务类
|
// 签名验签均从证书 dn 作为索引,所以引入证书服务类
|
||||||
private final CertificateService certificateService;
|
private final CertificateService certificateService;
|
||||||
|
|||||||
@@ -708,5 +708,30 @@ INSERT IGNORE INTO tms_master_key_activate (
|
|||||||
) VALUES (1, true, true);
|
) VALUES (1, true, true);
|
||||||
|
|
||||||
|
|
||||||
ALTER TABLE TMS.tms_operation_audit_log ADD mac varchar(100) NULL COMMENT '完整性校验值';
|
ALTER TABLE tms_access_whitelist ADD signature varchar(250) NULL COMMENT '数据真实性签名值';
|
||||||
ALTER TABLE TMS.tms_key_entity ADD mac varchar(100) NULL COMMENT '完整性校验值';
|
ALTER TABLE tms_auth_audit_log ADD signature varchar(250) NULL COMMENT '数据真实性签名值';
|
||||||
|
ALTER TABLE tms_auth_challenge ADD signature varchar(250) NULL COMMENT '数据真实性签名值';
|
||||||
|
ALTER TABLE tms_auth_full_account ADD signature varchar(250) NULL COMMENT '数据真实性签名值';
|
||||||
|
ALTER TABLE tms_auth_session ADD signature varchar(250) NULL COMMENT '数据真实性签名值';
|
||||||
|
ALTER TABLE tms_backup_config ADD signature varchar(250) NULL COMMENT '数据真实性签名值';
|
||||||
|
ALTER TABLE tms_certificate ADD signature varchar(250) NULL COMMENT '数据真实性签名值';
|
||||||
|
ALTER TABLE tms_certificate_crl ADD signature varchar(250) NULL COMMENT '数据真实性签名值';
|
||||||
|
ALTER TABLE tms_certificate_crl_import_task ADD signature varchar(250) NULL COMMENT '数据真实性签名值';
|
||||||
|
ALTER TABLE tms_certificate_crl_revoked ADD signature varchar(250) NULL COMMENT '数据真实性签名值';
|
||||||
|
ALTER TABLE tms_device_node ADD signature varchar(250) NULL COMMENT '数据真实性签名值';
|
||||||
|
ALTER TABLE tms_device_software_version ADD signature varchar(250) NULL COMMENT '数据真实性签名值';
|
||||||
|
ALTER TABLE tms_file_record ADD signature varchar(250) NULL COMMENT '数据真实性签名值';
|
||||||
|
ALTER TABLE tms_init_task ADD signature varchar(250) NULL COMMENT '数据真实性签名值';
|
||||||
|
ALTER TABLE tms_init_task_step ADD signature varchar(250) NULL COMMENT '数据真实性签名值';
|
||||||
|
ALTER TABLE tms_key_entity ADD signature varchar(250) NULL COMMENT '数据真实性签名值';
|
||||||
|
ALTER TABLE tms_log_backup_record ADD signature varchar(250) NULL COMMENT '数据真实性签名值';
|
||||||
|
ALTER TABLE tms_master_key_activate ADD signature varchar(250) NULL COMMENT '数据真实性签名值';
|
||||||
|
ALTER TABLE tms_operation_audit_log ADD signature varchar(250) NULL COMMENT '数据真实性签名值';
|
||||||
|
ALTER TABLE tms_replay_nonce ADD signature varchar(250) NULL COMMENT '数据真实性签名值';
|
||||||
|
ALTER TABLE tms_resource_backup_task ADD signature varchar(250) NULL COMMENT '数据真实性签名值';
|
||||||
|
ALTER TABLE tms_resource_restore_task ADD signature varchar(250) NULL COMMENT '数据真实性签名值';
|
||||||
|
ALTER TABLE tms_role_account ADD signature varchar(250) NULL COMMENT '数据真实性签名值';
|
||||||
|
ALTER TABLE tms_role_ukey_binding ADD signature varchar(250) NULL COMMENT '数据真实性签名值';
|
||||||
|
ALTER TABLE tms_security_event ADD signature varchar(250) NULL COMMENT '数据真实性签名值';
|
||||||
|
ALTER TABLE tms_trusted_cert ADD signature varchar(250) NULL COMMENT '数据真实性签名值';
|
||||||
|
ALTER TABLE tms_upgrade_task ADD signature varchar(250) NULL COMMENT '数据真实性签名值';
|
||||||
|
|||||||
Reference in New Issue
Block a user