Skip to content

Commit

Permalink
Merge pull request #60 from HuaDeity/main
Browse files Browse the repository at this point in the history
Add 'no-resolve' to surge rules
  • Loading branch information
SunsetMkt authored Apr 25, 2024
2 parents 8ad830b + 9a5da05 commit 6200ee9
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
# surge.list Surge分流规则
# quantumultx.list QuantumultX分流规则
# quantumultx-domesticsocial.list QuantumultX分流规则,策略组名称为DomesticSocial
import copy
import os
import sys

import git
import yaml
import copy


def read_yaml(file):
Expand Down Expand Up @@ -251,10 +251,20 @@ def generate_surge(config):
'''生成surge.list'''
comment = get_head_comment(
config, 'surge.list', 'Surge分流规则')
rules = ''
for rule in config['config']['rules']:
rules += rule + '\n'
output = comment + rules

# 为了不影响其他软件规则的生成,使用深拷贝
rules = copy.deepcopy(config["config"]["rules"])

# 检查 IP rules 有无 `no-resolve` 字段,没有的话加上, 防止 DNS 泄漏
for i in range(len(rules)):
if rules[i].startswith("IP-CIDR") and "no-resolve" not in rules[i]:
rules[i] = rules[i] + ",no-resolve"

gen_rules = ''

for rule in rules:
gen_rules += rule + '\n'
output = comment + gen_rules
save_string(output, os.path.join('generated', 'surge.list'))


Expand Down

0 comments on commit 6200ee9

Please sign in to comment.