From 72579c7e83f7e2f6eade20b2cc77299a1633d55e Mon Sep 17 00:00:00 2001 From: lijiahang Date: Thu, 9 Jan 2025 10:02:22 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E4=BC=98=E5=8C=96=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E6=A8=A1=E5=9D=97.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../visor/common/constant/FieldConst.java | 2 + .../visor/common/interfaces/FileClient.java | 19 ++++++++ ...cryptorUtils.java => RsaEncryptUtils.java} | 8 ++-- .../operator/log/core/utils/OperatorLogs.java | 43 +++++++++++++++++-- .../OrionEncryptAutoConfiguration.java | 4 +- .../core/client/AbstractFileClient.java | 10 +++++ .../OrionMockRedisTestConfiguration.java | 3 +- .../ParamDecryptDeserializer.java | 4 +- .../dromara/visor/launch/ReplaceVersion.java | 2 +- orion-visor-ui/.env.development | 9 ++-- orion-visor-ui/.env.production | 9 ++-- 11 files changed, 94 insertions(+), 19 deletions(-) rename orion-visor-common/src/main/java/org/dromara/visor/common/utils/{RsaEncryptorUtils.java => RsaEncryptUtils.java} (90%) diff --git a/orion-visor-common/src/main/java/org/dromara/visor/common/constant/FieldConst.java b/orion-visor-common/src/main/java/org/dromara/visor/common/constant/FieldConst.java index ae879dcf..7931edaf 100644 --- a/orion-visor-common/src/main/java/org/dromara/visor/common/constant/FieldConst.java +++ b/orion-visor-common/src/main/java/org/dromara/visor/common/constant/FieldConst.java @@ -105,4 +105,6 @@ public interface FieldConst { String ALL = "all"; + String CONFIG = "config"; + } diff --git a/orion-visor-common/src/main/java/org/dromara/visor/common/interfaces/FileClient.java b/orion-visor-common/src/main/java/org/dromara/visor/common/interfaces/FileClient.java index 9ed4ca9c..d6f62d4a 100644 --- a/orion-visor-common/src/main/java/org/dromara/visor/common/interfaces/FileClient.java +++ b/orion-visor-common/src/main/java/org/dromara/visor/common/interfaces/FileClient.java @@ -114,6 +114,25 @@ public interface FileClient { */ byte[] getContent(String path) throws Exception; + /** + * 获取文件内容 + * + * @param path path + * @return content + * @throws Exception Exception + */ + String getContentAsString(String path) throws Exception; + + /** + * 获取文件内容 + * + * @param path path + * @param charset charset + * @return content + * @throws Exception Exception + */ + String getContentAsString(String path, String charset) throws Exception; + /** * 获取文件输入流 * diff --git a/orion-visor-common/src/main/java/org/dromara/visor/common/utils/RsaEncryptorUtils.java b/orion-visor-common/src/main/java/org/dromara/visor/common/utils/RsaEncryptUtils.java similarity index 90% rename from orion-visor-common/src/main/java/org/dromara/visor/common/utils/RsaEncryptorUtils.java rename to orion-visor-common/src/main/java/org/dromara/visor/common/utils/RsaEncryptUtils.java index a91ec1ac..b048b6b2 100644 --- a/orion-visor-common/src/main/java/org/dromara/visor/common/utils/RsaEncryptorUtils.java +++ b/orion-visor-common/src/main/java/org/dromara/visor/common/utils/RsaEncryptUtils.java @@ -32,11 +32,11 @@ import org.dromara.visor.common.interfaces.RsaEncryptor; * @version 1.0.0 * @since 2025/1/5 21:13 */ -public class RsaEncryptorUtils { +public class RsaEncryptUtils { private static RsaEncryptor delegate; - private RsaEncryptorUtils() { + private RsaEncryptUtils() { } /** @@ -60,11 +60,11 @@ public class RsaEncryptorUtils { } public static void setDelegate(RsaEncryptor delegate) { - if (RsaEncryptorUtils.delegate != null) { + if (RsaEncryptUtils.delegate != null) { // unmodified throw Exceptions.state(); } - RsaEncryptorUtils.delegate = delegate; + RsaEncryptUtils.delegate = delegate; } } diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-biz-operator-log/src/main/java/org/dromara/visor/framework/biz/operator/log/core/utils/OperatorLogs.java b/orion-visor-framework/orion-visor-spring-boot-starter-biz-operator-log/src/main/java/org/dromara/visor/framework/biz/operator/log/core/utils/OperatorLogs.java index f0d8a67b..d8ea3486 100644 --- a/orion-visor-framework/orion-visor-spring-boot-starter-biz-operator-log/src/main/java/org/dromara/visor/framework/biz/operator/log/core/utils/OperatorLogs.java +++ b/orion-visor-framework/orion-visor-spring-boot-starter-biz-operator-log/src/main/java/org/dromara/visor/framework/biz/operator/log/core/utils/OperatorLogs.java @@ -23,8 +23,10 @@ package org.dromara.visor.framework.biz.operator.log.core.utils; import cn.orionsec.kit.lang.utils.Exceptions; +import cn.orionsec.kit.lang.utils.Strings; import cn.orionsec.kit.lang.utils.collect.Maps; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.serializer.SerializeFilter; import org.dromara.visor.common.constant.ExtraFieldConst; import org.dromara.visor.common.security.LoginUser; @@ -74,7 +76,7 @@ public class OperatorLogs implements ExtraFieldConst { * @param value value */ public static void addJson(String key, Object value) { - EXTRA_HOLDER.get().put(key, JSON.parseObject(JSON.toJSONString(value, serializeFilters))); + EXTRA_HOLDER.get().put(key, JSON.parseObject(toJsonString(value))); } /** @@ -96,13 +98,25 @@ public class OperatorLogs implements ExtraFieldConst { if (obj == null) { return; } - if (obj instanceof Map) { + if (obj instanceof JSONObject || obj instanceof com.alibaba.fastjson2.JSONObject) { + EXTRA_HOLDER.get().putAll(JSON.parseObject(toJsonString(obj))); + } else if (obj instanceof Map) { EXTRA_HOLDER.get().putAll((Map) obj); } else { - EXTRA_HOLDER.get().putAll(JSON.parseObject(JSON.toJSONString(obj, serializeFilters))); + EXTRA_HOLDER.get().putAll(JSON.parseObject(toJsonString(obj))); } } + /** + * 获取 json + * + * @param value value + * @return json + */ + public static String toJsonString(Object value) { + return JSON.toJSONString(value, serializeFilters); + } + /** * 设置不保存 */ @@ -167,6 +181,29 @@ public class OperatorLogs implements ExtraFieldConst { USER_HOLDER.remove(); } + /** + * 清空 html tag + * + * @param log log + * @return cleared + */ + public static String clearHtmlTag(String log) { + if (Strings.isBlank(log)) { + return log; + } + return log.replaceAll("", "") + .replaceAll("", "") + .replaceAll("", "") + .replaceAll("", "") + .replaceAll("", "") + .replaceAll("", "") + .replaceAll("", "") + .replaceAll("", "") + .replaceAll("", "") + .replaceAll("", "") + .replaceAll("
", "\n"); + } + public static void setSerializeFilters(SerializeFilter[] serializeFilters) { if (OperatorLogs.serializeFilters != null) { // unmodified diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-encrypt/src/main/java/org/dromara/visor/framework/encrypt/configuration/OrionEncryptAutoConfiguration.java b/orion-visor-framework/orion-visor-spring-boot-starter-encrypt/src/main/java/org/dromara/visor/framework/encrypt/configuration/OrionEncryptAutoConfiguration.java index d61a9cc1..2157a14b 100644 --- a/orion-visor-framework/orion-visor-spring-boot-starter-encrypt/src/main/java/org/dromara/visor/framework/encrypt/configuration/OrionEncryptAutoConfiguration.java +++ b/orion-visor-framework/orion-visor-spring-boot-starter-encrypt/src/main/java/org/dromara/visor/framework/encrypt/configuration/OrionEncryptAutoConfiguration.java @@ -27,7 +27,7 @@ import org.dromara.visor.common.constant.AutoConfigureOrderConst; import org.dromara.visor.common.interfaces.AesEncryptor; import org.dromara.visor.common.interfaces.RsaEncryptor; import org.dromara.visor.common.utils.AesEncryptUtils; -import org.dromara.visor.common.utils.RsaEncryptorUtils; +import org.dromara.visor.common.utils.RsaEncryptUtils; import org.dromara.visor.framework.encrypt.configuration.config.AesEncryptConfig; import org.dromara.visor.framework.encrypt.core.impl.AesEncryptorImpl; import org.dromara.visor.framework.encrypt.core.impl.RsaEncryptorImpl; @@ -70,7 +70,7 @@ public class OrionEncryptAutoConfiguration { // 加密器 RsaEncryptor encryptor = new RsaEncryptorImpl(configStore); // 设置工具类 - RsaEncryptorUtils.setDelegate(encryptor); + RsaEncryptUtils.setDelegate(encryptor); return encryptor; } diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-storage/src/main/java/org/dromara/visor/framework/storage/core/client/AbstractFileClient.java b/orion-visor-framework/orion-visor-spring-boot-starter-storage/src/main/java/org/dromara/visor/framework/storage/core/client/AbstractFileClient.java index c60087b9..05f7a896 100644 --- a/orion-visor-framework/orion-visor-spring-boot-starter-storage/src/main/java/org/dromara/visor/framework/storage/core/client/AbstractFileClient.java +++ b/orion-visor-framework/orion-visor-spring-boot-starter-storage/src/main/java/org/dromara/visor/framework/storage/core/client/AbstractFileClient.java @@ -79,6 +79,16 @@ public abstract class AbstractFileClient implem } } + @Override + public String getContentAsString(String path) throws Exception { + return this.getContentAsString(path, Const.UTF_8); + } + + @Override + public String getContentAsString(String path, String charset) throws Exception { + return new String(this.getContent(path), charset); + } + @Override public OutputStream getContentOutputStream(String path) throws Exception { return this.getContentOutputStream(path, false); diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-test/src/main/java/org/dromara/visor/framework/test/configuration/OrionMockRedisTestConfiguration.java b/orion-visor-framework/orion-visor-spring-boot-starter-test/src/main/java/org/dromara/visor/framework/test/configuration/OrionMockRedisTestConfiguration.java index 266cf7a4..7ffe8d85 100644 --- a/orion-visor-framework/orion-visor-spring-boot-starter-test/src/main/java/org/dromara/visor/framework/test/configuration/OrionMockRedisTestConfiguration.java +++ b/orion-visor-framework/orion-visor-spring-boot-starter-test/src/main/java/org/dromara/visor/framework/test/configuration/OrionMockRedisTestConfiguration.java @@ -32,6 +32,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Profile; +import java.net.InetAddress; import java.util.function.Supplier; /** @@ -52,7 +53,7 @@ public class OrionMockRedisTestConfiguration { */ @Bean public RedisServer redisMockServer(RedisProperties properties) { - RedisServer server = new RedisServer(properties.getPort()); + RedisServer server = new RedisServer(properties.getPort(), InetAddress.getLoopbackAddress()); try { server.start(); } catch (Exception ignore) { diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-web/src/main/java/org/dromara/visor/framework/web/core/deserializer/ParamDecryptDeserializer.java b/orion-visor-framework/orion-visor-spring-boot-starter-web/src/main/java/org/dromara/visor/framework/web/core/deserializer/ParamDecryptDeserializer.java index 710643c4..608367a2 100644 --- a/orion-visor-framework/orion-visor-spring-boot-starter-web/src/main/java/org/dromara/visor/framework/web/core/deserializer/ParamDecryptDeserializer.java +++ b/orion-visor-framework/orion-visor-spring-boot-starter-web/src/main/java/org/dromara/visor/framework/web/core/deserializer/ParamDecryptDeserializer.java @@ -28,7 +28,7 @@ import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonNode; import org.dromara.visor.common.constant.ErrorMessage; -import org.dromara.visor.common.utils.RsaEncryptorUtils; +import org.dromara.visor.common.utils.RsaEncryptUtils; import org.dromara.visor.common.utils.Valid; import java.io.IOException; @@ -51,7 +51,7 @@ public class ParamDecryptDeserializer extends JsonDeserializer { return value; } // 解密参数 - String decrypt = RsaEncryptorUtils.decrypt(value); + String decrypt = RsaEncryptUtils.decrypt(value); return Valid.notNull(decrypt, ErrorMessage.DECRYPT_ERROR); } diff --git a/orion-visor-launch/src/test/java/org/dromara/visor/launch/ReplaceVersion.java b/orion-visor-launch/src/test/java/org/dromara/visor/launch/ReplaceVersion.java index fef40fd8..18257b38 100644 --- a/orion-visor-launch/src/test/java/org/dromara/visor/launch/ReplaceVersion.java +++ b/orion-visor-launch/src/test/java/org/dromara/visor/launch/ReplaceVersion.java @@ -115,7 +115,7 @@ public class ReplaceVersion { */ private static void replaceViteEnvFiles() { for (String file : VITE_ENV_FILES) { - readAndWrite(file, s -> s.replaceAll("VITE_APP_VERSION= '" + TARGET_VERSION + "'", "VITE_APP_VERSION= '" + REPLACE_VERSION + "'")); + readAndWrite(file, s -> s.replaceAll("VITE_APP_VERSION=" + TARGET_VERSION, "VITE_APP_VERSION=" + REPLACE_VERSION)); } } diff --git a/orion-visor-ui/.env.development b/orion-visor-ui/.env.development index 0171bab0..ca4f042a 100644 --- a/orion-visor-ui/.env.development +++ b/orion-visor-ui/.env.development @@ -1,3 +1,6 @@ -VITE_API_BASE_URL= 'http://127.0.0.1:9200/orion-visor/api' -VITE_WS_BASE_URL= 'ws://127.0.0.1:9200/orion-visor/keep-alive' -VITE_APP_VERSION= '2.2.3' +# api 路径 +VITE_API_BASE_URL=http://127.0.0.1:9200/orion-visor/api +# websocket 路径 +VITE_WS_BASE_URL=ws://127.0.0.1:9200/orion-visor/keep-alive +# 版本号 +VITE_APP_VERSION=2.2.3 diff --git a/orion-visor-ui/.env.production b/orion-visor-ui/.env.production index 71d722e0..c5f0dec0 100644 --- a/orion-visor-ui/.env.production +++ b/orion-visor-ui/.env.production @@ -1,3 +1,6 @@ -VITE_API_BASE_URL= '/orion-visor/api' -VITE_WS_BASE_URL= '/orion-visor/keep-alive' -VITE_APP_VERSION= '2.2.3' +# api 路径 +VITE_API_BASE_URL=/orion-visor/api +# websocket 路径 +VITE_WS_BASE_URL=/orion-visor/keep-alive +# 版本号 +VITE_APP_VERSION=2.2.3