summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwangwei <[email protected]>2024-11-05 17:11:03 +0800
committerwangwei <[email protected]>2024-11-05 17:11:03 +0800
commit1479d02c1ae5b0d01b75bcfbcda35a85ad9a4865 (patch)
treeb16ca9a07437515ef59c1acb4fa83172a2698dcb
parentb1331fe9315f593b7435b9928d79aae00f8551f5 (diff)
parenta1dc94a796f79e4841dda0e1aa67b4c0dc03fbe8 (diff)
[Fix][ip-learning] 匹配模式更新为正则,支持Key IN() OR Key like 模式查询
-rw-r--r--src/main/java/com/mesalab/knowledge/strategy/FqdnProviderImpl.java6
-rw-r--r--src/main/java/com/mesalab/qgw/service/impl/DslServiceImpl.java29
2 files changed, 14 insertions, 21 deletions
diff --git a/src/main/java/com/mesalab/knowledge/strategy/FqdnProviderImpl.java b/src/main/java/com/mesalab/knowledge/strategy/FqdnProviderImpl.java
index 3b69f43d..c28c476f 100644
--- a/src/main/java/com/mesalab/knowledge/strategy/FqdnProviderImpl.java
+++ b/src/main/java/com/mesalab/knowledge/strategy/FqdnProviderImpl.java
@@ -152,11 +152,11 @@ public class FqdnProviderImpl implements QueryProvider {
private static void buildProtocol(StringBuffer protocolsb, List<Object> fieldValues) {
List<String> protocols = Lists.newArrayList();
for (Object protocol : fieldValues) {
- if (HTTP.equals(protocol)) {
+ if (HTTP.equals(protocol) || ("$" + HTTP).equals(protocol)) {
protocols.add("e.HTTP_CNT_TOTAL > 0");
- } else if (DNS.equals(protocol)) {
+ } else if (DNS.equals(protocol) || ("$" + DNS).equals(protocol)) {
protocols.add("e.DNS_CNT_TOTAL > 0");
- } else if (SSL.equals(protocol) || TLS.equals(protocol)) {
+ } else if (SSL.equals(protocol) || TLS.equals(protocol) || ("$" + SSL).equals(protocol) || ("$" + TLS).equals(protocol)) {
protocols.add("e.TLS_CNT_TOTAL > 0");
}
}
diff --git a/src/main/java/com/mesalab/qgw/service/impl/DslServiceImpl.java b/src/main/java/com/mesalab/qgw/service/impl/DslServiceImpl.java
index 53aa68fa..5a1f942d 100644
--- a/src/main/java/com/mesalab/qgw/service/impl/DslServiceImpl.java
+++ b/src/main/java/com/mesalab/qgw/service/impl/DslServiceImpl.java
@@ -377,22 +377,15 @@ public class DslServiceImpl implements DSLService {
public Object visit(LikeExpression expr, Object context) {
String left = String.valueOf(expr.getLeftExpression());
String right = ((StringValue) expr.getRightExpression()).getValue();
- String type = "";
- if (right.startsWith("%") && right.endsWith("%")) {
- type = MatchEnum.SUBSTRING.getType();
- right = right.substring(1, right.length() - 1);
- } else if (right.startsWith("%")) {
- type = MatchEnum.SUFFIX.getType();
- right = right.substring(1);
- } else if (right.endsWith("%")) {
- type = MatchEnum.PREFIX.getType();
- right = right.substring(0, right.length() - 1);
+ String type = MatchEnum.REGEX.getType();
+ if (right.startsWith("%") || right.endsWith("%")) {
+ right = right.replaceFirst("^%", "*"); // 替换开头的百分号
+ right = right.replaceFirst("%$", "*"); // 替换结尾的百分号
} else {
- type = MatchEnum.EXACTLY.getType();
+ right = "$" + right; // 没有百分号时添加前缀
}
- String finalType = type;
- if (matches.stream().anyMatch(o -> o.getFieldKey().equals(left) && o.getType().equals(finalType))) {
+ if (matches.stream().anyMatch(o -> o.getFieldKey().equals(left) && o.getType().equals(type))) {
for (Match match : matches) {
if (match.getFieldKey().equals(left) && match.getType().equals(type)) {
match.getFieldValues().add(right);
@@ -484,14 +477,14 @@ public class DslServiceImpl implements DSLService {
private void strParseIn(InExpression expr) {
String left = String.valueOf(expr.getLeftExpression());
- if (matches.stream().anyMatch(o -> o.getFieldKey().equals(left) && o.getType().equals(MatchEnum.EXACTLY.getType()))) {
+ if (matches.stream().anyMatch(o -> o.getFieldKey().equals(left) && o.getType().equals(MatchEnum.REGEX.getType()))) {
for (Match match : matches) {
- if (match.getFieldKey().equals(left) && match.getType().equals(MatchEnum.EXACTLY.getType())) {
+ if (match.getFieldKey().equals(left) && match.getType().equals(MatchEnum.REGEX.getType())) {
if (expr.getRightExpression() instanceof ExpressionList) {
List<Expression> expressionsList = (ExpressionList) expr.getRightExpression();
for (Expression expression : expressionsList) {
if (expression instanceof StringValue) {
- match.getFieldValues().add(((StringValue) expression).getValue());
+ match.getFieldValues().add("$" + ((StringValue) expression).getValue());
} else if (expression instanceof LongValue) {
match.getFieldValues().add(((LongValue) expression).getValue());
}
@@ -503,13 +496,13 @@ public class DslServiceImpl implements DSLService {
Match match = new Match();
match.setFieldKey(left);
match.setFieldValues(Lists.newArrayList());
- match.setType(MatchEnum.EXACTLY.getType());
+ match.setType(MatchEnum.REGEX.getType());
Expression rightExpression = expr.getRightExpression();
if (rightExpression instanceof ExpressionList) {
List<Expression> expressionsList = (ExpressionList) rightExpression;
for (Expression expression : expressionsList) {
if (expression instanceof StringValue) {
- match.getFieldValues().add(((StringValue) expression).getValue());
+ match.getFieldValues().add("$" + ((StringValue) expression).getValue());
} else if (expression instanceof LongValue) {
match.getFieldValues().add(((LongValue) expression).getValue());
}