Add default config options

This commit is contained in:
problematicconsumer
2024-01-15 02:16:22 +03:30
parent e838e2f999
commit f6a6acb020
2 changed files with 56 additions and 6 deletions

View File

@@ -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 {

View File

@@ -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