forked from SagerNet/sing-box
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main'
- Loading branch information
Showing
111 changed files
with
2,312 additions
and
1,201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,14 @@ nfpms: | |
dst: /usr/lib/systemd/system/[email protected] | ||
- src: LICENSE | ||
dst: /usr/share/licenses/sing-box/LICENSE | ||
deb: | ||
signature: | ||
key_file: "{{ .Env.NFPM_KEY_PATH }}" | ||
fields: | ||
Bugs: https://github.com/SagerNet/sing-box/issues | ||
rpm: | ||
signature: | ||
key_file: "{{ .Env.NFPM_KEY_PATH }}" | ||
conflicts: | ||
- sing-box-beta | ||
- id: package_beta | ||
|
@@ -72,9 +80,8 @@ furies: | |
- account: sagernet | ||
ids: | ||
- package | ||
skip: "{{ .Prerelease }}" | ||
disable: "{{ not (not .Prerelease) }}" | ||
- account: sagernet | ||
ids: | ||
- package_beta | ||
skip: "{{ not .Prerelease }}" | ||
|
||
disable: "{{ not .Prerelease }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule android
updated
7 files
Submodule apple
updated
9 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"os" | ||
|
||
"github.com/sagernet/sing-box/adapter" | ||
"github.com/sagernet/sing-box/common/srs" | ||
C "github.com/sagernet/sing-box/constant" | ||
"github.com/sagernet/sing-box/log" | ||
"github.com/sagernet/sing-box/option" | ||
"github.com/sagernet/sing-box/route" | ||
E "github.com/sagernet/sing/common/exceptions" | ||
"github.com/sagernet/sing/common/json" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var flagRuleSetMatchFormat string | ||
|
||
var commandRuleSetMatch = &cobra.Command{ | ||
Use: "match <rule-set path> <domain>", | ||
Short: "Check if a domain matches the rule set", | ||
Args: cobra.ExactArgs(2), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
err := ruleSetMatch(args[0], args[1]) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
commandRuleSetMatch.Flags().StringVarP(&flagRuleSetMatchFormat, "format", "f", "source", "rule-set format") | ||
commandRuleSet.AddCommand(commandRuleSetMatch) | ||
} | ||
|
||
func ruleSetMatch(sourcePath string, domain string) error { | ||
var ( | ||
reader io.Reader | ||
err error | ||
) | ||
if sourcePath == "stdin" { | ||
reader = os.Stdin | ||
} else { | ||
reader, err = os.Open(sourcePath) | ||
if err != nil { | ||
return E.Cause(err, "read rule-set") | ||
} | ||
} | ||
content, err := io.ReadAll(reader) | ||
if err != nil { | ||
return E.Cause(err, "read rule-set") | ||
} | ||
var plainRuleSet option.PlainRuleSet | ||
switch flagRuleSetMatchFormat { | ||
case C.RuleSetFormatSource: | ||
var compat option.PlainRuleSetCompat | ||
compat, err = json.UnmarshalExtended[option.PlainRuleSetCompat](content) | ||
if err != nil { | ||
return err | ||
} | ||
plainRuleSet = compat.Upgrade() | ||
case C.RuleSetFormatBinary: | ||
plainRuleSet, err = srs.Read(bytes.NewReader(content), false) | ||
if err != nil { | ||
return err | ||
} | ||
default: | ||
return E.New("unknown rule set format: ", flagRuleSetMatchFormat) | ||
} | ||
for i, ruleOptions := range plainRuleSet.Rules { | ||
var currentRule adapter.HeadlessRule | ||
currentRule, err = route.NewHeadlessRule(nil, ruleOptions) | ||
if err != nil { | ||
return E.Cause(err, "parse rule_set.rules.[", i, "]") | ||
} | ||
if currentRule.Match(&adapter.InboundContext{ | ||
Domain: domain, | ||
}) { | ||
println("match rules.[", i, "]: "+currentRule.String()) | ||
} | ||
} | ||
return nil | ||
} |
Oops, something went wrong.