修复
This commit is contained in:
@@ -67,7 +67,11 @@
|
||||
"SlashCommand(/sc:analyze:*)",
|
||||
"Bash(test_dns_resolution:*)",
|
||||
"Bash(echo $?)",
|
||||
"Bash(git checkout:*)"
|
||||
"Bash(git checkout:*)",
|
||||
"Bash(echo:*)",
|
||||
"Bash(HYSTERIA_CONFIG=\"/tmp/test_config.yaml\" bash -c '\nsource /c/code/s-hy2/scripts/outbound-manager.sh 2>/dev/null\n\n# 测试提取配置文件中的规则\necho \"\"=== 配置文件中的规则 ===\"\"\nget_config_outbound_rules\n\necho \"\"\"\"\necho \"\"=== 测试删除配置文件中的规则 ===\"\"\n# 模拟删除 config_only_rule\nif remove_rule_from_config \"\"config_only_rule\"\"; then\n echo \"\"✅ 删除成功\"\"\n echo \"\"删除后的配置文件:\"\"\n cat /tmp/test_config.yaml\nelse\n echo \"\"❌ 删除失败\"\"\nfi\n')",
|
||||
"Bash(HYSTERIA_CONFIG=\"/tmp/test_config.yaml\" bash -c '\nsource /c/code/s-hy2/scripts/outbound-manager.sh 2>/dev/null\n\nrule_name=\"\"config_only_rule\"\"\necho \"\"=== 调试删除过程 ===\"\"\necho \"\"配置文件: $HYSTERIA_CONFIG\"\"\necho \"\"规则名称: $rule_name\"\"\necho \"\"\"\"\necho \"\"配置文件内容:\"\"\ncat \"\"$HYSTERIA_CONFIG\"\"\necho \"\"\"\"\necho \"\"=== 逐行检查 ===\"\"\nwhile IFS= read -r line; do\n echo \"\"处理行: \\\"\"$line\\\"\"\"\"\n if [[ \"\"$line\"\" =~ ^[[:space:]]*-[[:space:]]*name:[[:space:]]*[\\\"\"'\"''\"']*${rule_name}[\\\"\"'\"''\"']*[[:space:]]*$ ]]; then\n echo \"\" → 找到匹配!\"\"\n fi\ndone < \"\"$HYSTERIA_CONFIG\"\"\n')",
|
||||
"Bash(HYSTERIA_CONFIG=\"/tmp/test_config.yaml\" bash -c '\nsource /c/code/s-hy2/scripts/outbound-manager.sh 2>/dev/null\n\necho \"\"=== 测试删除配置文件中的规则 ===\"\"\necho \"\"删除前:\"\"\ncat /tmp/test_config.yaml\necho \"\"\"\"\n\nif remove_rule_from_config \"\"config_only_rule\"\"; then\n echo \"\"\"\"\n echo \"\"✅ 删除成功!\"\"\n echo \"\"删除后:\"\"\n cat /tmp/test_config.yaml\nelse\n echo \"\"\"\"\n echo \"\"❌ 删除失败\"\"\nfi\n')"
|
||||
],
|
||||
"deny": []
|
||||
}
|
||||
|
||||
+15
-14
@@ -1710,6 +1710,19 @@ get_rule_status_text() {
|
||||
fi
|
||||
}
|
||||
|
||||
# 安全移动配置文件并修复权限(全局函数)
|
||||
safe_move_config() {
|
||||
local temp_file="$1"
|
||||
local target_file="$2"
|
||||
|
||||
if mv "$temp_file" "$target_file" 2>/dev/null; then
|
||||
chmod 644 "$target_file" 2>/dev/null
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# 规则库目录变量
|
||||
RULES_DIR="/etc/hysteria/outbound-rules"
|
||||
RULES_LIBRARY="$RULES_DIR/rules-library.yaml"
|
||||
@@ -2239,19 +2252,6 @@ apply_rule_to_config_simple() {
|
||||
' "$RULES_LIBRARY"
|
||||
}
|
||||
|
||||
# 安全移动配置文件并修复权限
|
||||
safe_move_config() {
|
||||
local temp_file="$1"
|
||||
local target_file="$2"
|
||||
|
||||
if mv "$temp_file" "$target_file" 2>/dev/null; then
|
||||
# 修复配置文件权限,确保 Hysteria2 服务可以读取
|
||||
chmod 644 "$target_file" 2>/dev/null
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# 先提取配置参数(在使用前定义变量)- 完整参数支持
|
||||
local mode="" bindDevice="" bindIPv4="" bindIPv6="" fastOpen=""
|
||||
@@ -2873,7 +2873,8 @@ remove_rule_from_config() {
|
||||
local rule_found=false
|
||||
|
||||
while IFS= read -r line || [[ -n "$line" ]]; do
|
||||
if [[ "$line" =~ ^[[:space:]]*-[[:space:]]*name:[[:space:]]*[\"']*${rule_name}[\"']*[[:space:]]*$ ]]; then
|
||||
# 使用更灵活的匹配方式,支持带引号或不带引号
|
||||
if [[ "$line" =~ -[[:space:]]*name:[[:space:]]* ]] && [[ "$line" =~ $rule_name ]]; then
|
||||
in_target_rule=true
|
||||
rule_found=true
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user