Skip to content

Commit

Permalink
Merge pull request #75 from peanut996:main
Browse files Browse the repository at this point in the history
自定义规则集添加Protocol选项
  • Loading branch information
7Sageer authored Dec 7, 2024
2 parents 1fcddd5 + 7d4aca4 commit 2f7d971
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/API-doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ Singbox 的规则集来自 [https://github.com/lyc8503/sing-box-rules](https://g
- `domain_suffix`: 域名后缀规则数组
- `domain_keyword`: 域名关键词规则数组
- `ip_cidr`: IP CIDR 规则数组
- `protocol`: 协议规则数组
- `outbound`: 出站名称

示例:
Expand All @@ -172,6 +173,7 @@ Singbox 的规则集来自 [https://github.com/lyc8503/sing-box-rules](https://g
"domain_suffix": [".com", ".org"],
"domain_keyword": ["Mijia Cloud", "push.apple"],
"ip_cidr": ["192.168.0.0/16", "10.0.0.0/8"],
"protocol": ["http", "tls", "dns"],
"outbound": "🤪 MyCustomRule"
}
]
Expand Down
1 change: 1 addition & 0 deletions src/SingboxConfigBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export class ConfigBuilder extends BaseConfigBuilder {
domain_suffix: rule.domain_suffix,
domain_keyword: rule.domain_keyword,
ip_cidr: rule.ip_cidr,
protocol: rule.protocol,
outbound: rule.outbound
}));
// Add any default rules that should always be present
Expand Down
2 changes: 2 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export function generateRules(selectedRules = [], customRules = [], pin) {
domain_suffix: rule.domain_suffix ? rule.domain_suffix.split(',') : [],
domain_keyword: rule.domain_keyword ? rule.domain_keyword.split(',') : [],
ip_cidr: rule.ip_cidr ? rule.ip_cidr.split(',') : [],
protocol: rule.protocol ? rule.protocol.split(',') : [],
outbound: rule.name
});
});
Expand All @@ -194,6 +195,7 @@ export function generateRules(selectedRules = [], customRules = [], pin) {
domain_suffix: rule.domain_suffix ? rule.domain_suffix.split(',') : [],
domain_keyword: rule.domain_keyword ? rule.domain_keyword.split(',') : [],
ip_cidr: rule.ip_cidr ? rule.ip_cidr.split(',') : [],
protocol: rule.protocol ? rule.protocol.split(',') : [],
outbound: rule.name
});
});
Expand Down
13 changes: 12 additions & 1 deletion src/htmlBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,8 @@ const submitFormFunction = () => `
name: rule.querySelector('input[name="customRuleName[]"]').value,
domain_suffix: rule.querySelector('input[name="customRuleDomainSuffix[]"]').value,
domain_keyword: rule.querySelector('input[name="customRuleDomainKeyword[]"]').value,
ip_cidr: rule.querySelector('input[name="customRuleIPCIDR[]"]').value
ip_cidr: rule.querySelector('input[name="customRuleIPCIDR[]"]').value,
protocol: rule.querySelector('input[name="customRuleProtocol[]"]').value
}));
const configParam = configId ? \`&configId=\${configId}\` : '';
Expand Down Expand Up @@ -659,6 +660,16 @@ const customRuleFunctions = `
<label class="form-label">IP CIDR</label>
<input type="text" class="form-control mb-2" name="customRuleIPCIDR[]" placeholder="IP CIDR (comma separated)">
</div>
<div class="mb-2">
<label class="form-label">Protocol</label>
<span class="tooltip-icon">
<i class="fas fa-question-circle"></i>
<span class="tooltip-content">
Protocol rules for specific traffic types. More details: https://sing-box.sagernet.org/configuration/route/sniff/
</span>
</span>
<input type="text" class="form-control mb-2" name="customRuleProtocol[]" placeholder="Protocol (comma separated, e.g, http,ssh,dns)">
</div>
<button type="button" class="btn btn-danger btn-sm" onclick="removeCustomRule(this)">Remove</button>
\`;
customRulesDiv.appendChild(newRuleDiv);
Expand Down

0 comments on commit 2f7d971

Please sign in to comment.