diff --git a/cmd/cmd_config.go b/cmd/cmd_config.go index 8a79062..be68b21 100644 --- a/cmd/cmd_config.go +++ b/cmd/cmd_config.go @@ -16,9 +16,13 @@ import ( var commandBuild = &cobra.Command{ Use: "build", Short: "Build configuration", - Args: cobra.ExactArgs(2), + Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - err := build(args[0], args[1]) + var optionsPath string + if len(args) > 1 { + optionsPath = args[1] + } + err := build(args[0], optionsPath) if err != nil { log.Fatal(err) } @@ -32,15 +36,20 @@ func init() { func build(path string, optionsPath string) error { if workingDir != "" { path = filepath.Join(workingDir, path) - optionsPath = filepath.Join(workingDir, optionsPath) + if optionsPath != "" { + optionsPath = filepath.Join(workingDir, optionsPath) + } } options, err := readConfigAt(path) if err != nil { return err } - configOptions, err := readConfigOptionsAt(optionsPath) - if err != nil { - return err + configOptions := shared.DefaultConfigOptions() + if optionsPath != "" { + configOptions, err = readConfigOptionsAt(optionsPath) + if err != nil { + return err + } } config, err := shared.BuildConfigJson(*configOptions, *options) if err != nil { diff --git a/shared/config.go b/shared/config.go index 0a85573..b876b21 100644 --- a/shared/config.go +++ b/shared/config.go @@ -8,6 +8,7 @@ import ( "net/netip" "net/url" "strings" + "time" C "github.com/sagernet/sing-box/constant" "github.com/sagernet/sing-box/option" @@ -54,6 +55,46 @@ type TLSTricks struct { PaddingSize string `json:"tls-padding-size"` } +func DefaultConfigOptions() *ConfigOptions { + return &ConfigOptions{ + ExecuteAsIs: false, + LogLevel: "info", + ResolveDestination: false, + IPv6Mode: option.DomainStrategy(dns.DomainStrategyAsIS), + RemoteDnsAddress: "1.1.1.1", + RemoteDnsDomainStrategy: option.DomainStrategy(dns.DomainStrategyAsIS), + DirectDnsAddress: "1.1.1.1", + DirectDnsDomainStrategy: option.DomainStrategy(dns.DomainStrategyAsIS), + MixedPort: 2334, + LocalDnsPort: 6450, + MTU: 9000, + StrictRoute: true, + TUNStack: "mixed", + ConnectionTestUrl: "https://cp.cloudflare.com/", + URLTestInterval: option.Duration(10 * time.Minute), + EnableClashApi: true, + ClashApiPort: 6756, + EnableTun: true, + SetSystemProxy: true, + BypassLAN: false, + AllowConnectionFromLAN: false, + EnableFakeDNS: false, + EnableDNSRouting: false, + IndependentDNSCache: false, + GeoIPPath: "geoip.db", + GeoSitePath: "geosite.db", + Rules: []Rule{}, + TLSTricks: TLSTricks{ + EnableFragment: false, + FragmentSize: "10-100", + FragmentSleep: "50-200", + EnableMixedSNICase: false, + EnablePadding: false, + PaddingSize: "100-200", + }, + } +} + func BuildConfigJson(configOpt ConfigOptions, input option.Options) (string, error) { options := BuildConfig(configOpt, input) var buffer bytes.Buffer