add inbound option and custom flags
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var defaultConfigs config.ConfigOptions
|
||||
var commandBuildOutputPath string
|
||||
|
||||
var commandBuild = &cobra.Command{
|
||||
@@ -46,8 +47,10 @@ var commandCheck = &cobra.Command{
|
||||
|
||||
func init() {
|
||||
commandBuild.Flags().StringVarP(&commandBuildOutputPath, "output", "o", "", "write result to file path instead of stdout")
|
||||
addHConfigFlags(commandBuild)
|
||||
|
||||
mainCommand.AddCommand(commandBuild)
|
||||
mainCommand.AddCommand(commandCheck)
|
||||
|
||||
}
|
||||
|
||||
func build(path string, optionsPath string) error {
|
||||
@@ -62,7 +65,8 @@ func build(path string, optionsPath string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
configOptions := config.DefaultConfigOptions()
|
||||
|
||||
configOptions := &defaultConfigs //config.DefaultConfigOptions()
|
||||
if optionsPath != "" {
|
||||
configOptions, err = readConfigOptionsAt(optionsPath)
|
||||
if err != nil {
|
||||
@@ -138,3 +142,24 @@ func readConfigOptionsAt(path string) (*config.ConfigOptions, error) {
|
||||
|
||||
return &options, nil
|
||||
}
|
||||
|
||||
func addHConfigFlags(commandRun *cobra.Command) {
|
||||
commandRun.Flags().BoolVar(&defaultConfigs.EnableFullConfig, "full-config", false, "allows including tags other than output")
|
||||
commandRun.Flags().StringVar(&defaultConfigs.LogLevel, "log", "warn", "log level")
|
||||
commandRun.Flags().BoolVar(&defaultConfigs.InboundOptions.EnableTun, "tun", false, "Enable Tun")
|
||||
commandRun.Flags().BoolVar(&defaultConfigs.InboundOptions.EnableTunService, "tun-service", false, "Enable Tun Service")
|
||||
commandRun.Flags().BoolVar(&defaultConfigs.InboundOptions.SetSystemProxy, "system-proxy", false, "Enable System Proxy")
|
||||
commandRun.Flags().Uint16Var(&defaultConfigs.InboundOptions.MixedPort, "in-proxy-port", 2334, "Input Mixed Port")
|
||||
commandRun.Flags().BoolVar(&defaultConfigs.TLSTricks.EnableFragment, "fragment", false, "Enable Fragment")
|
||||
commandRun.Flags().StringVar(&defaultConfigs.TLSTricks.FragmentSize, "fragment-size", "2-4", "FragmentSize")
|
||||
commandRun.Flags().StringVar(&defaultConfigs.TLSTricks.FragmentSleep, "fragment-sleep", "2-4", "FragmentSleep")
|
||||
|
||||
commandRun.Flags().BoolVar(&defaultConfigs.TLSTricks.EnablePadding, "padding", false, "Enable Padding")
|
||||
commandRun.Flags().StringVar(&defaultConfigs.TLSTricks.PaddingSize, "padding-size", "1300-1400", "PaddingSize")
|
||||
|
||||
commandRun.Flags().BoolVar(&defaultConfigs.TLSTricks.MixedSNICase, "mixed-sni-case", false, "MixedSNICase")
|
||||
|
||||
commandRun.Flags().StringVar(&defaultConfigs.RemoteDnsAddress, "dns-remote", "1.1.1.1", "RemoteDNS (1.1.1.1, https://1.1.1.1/dns-query)")
|
||||
commandRun.Flags().StringVar(&defaultConfigs.DirectDnsAddress, "dns-direct", "1.1.1.1", "DirectDNS (1.1.1.1, https://1.1.1.1/dns-query)")
|
||||
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ var commandParse = &cobra.Command{
|
||||
|
||||
func init() {
|
||||
commandParse.Flags().StringVarP(&commandParseOutputPath, "output", "o", "", "write result to file path instead of stdout")
|
||||
|
||||
mainCommand.AddCommand(commandParse)
|
||||
}
|
||||
|
||||
|
||||
@@ -22,12 +22,13 @@ func init() {
|
||||
commandRun.PersistentFlags().BoolP("help", "", false, "help for this command")
|
||||
commandRun.Flags().StringVarP(&hiddifySettingPath, "hiddify", "h", "", "Hiddify Setting JSON Path")
|
||||
commandRun.Flags().StringVarP(&configPath, "config", "c", "", "proxy config path or url")
|
||||
|
||||
addHConfigFlags(commandRun)
|
||||
commandRun.MarkFlagRequired("config")
|
||||
|
||||
mainCommand.AddCommand(commandRun)
|
||||
}
|
||||
|
||||
func runCommand(cmd *cobra.Command, args []string) {
|
||||
v2.RunStandalone(hiddifySettingPath, configPath)
|
||||
|
||||
v2.RunStandalone(hiddifySettingPath, configPath, defaultConfigs)
|
||||
}
|
||||
|
||||
@@ -61,6 +61,11 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro
|
||||
fmt.Printf("config options: %+v\n", opt)
|
||||
|
||||
var options option.Options
|
||||
if opt.EnableFullConfig {
|
||||
options.Inbounds = input.Inbounds
|
||||
options.DNS = input.DNS
|
||||
options.Route = input.Route
|
||||
}
|
||||
directDNSDomains := make(map[string]bool)
|
||||
dnsRules := []option.DefaultDNSRule{}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ type ConfigOptions struct {
|
||||
GeoSitePath string `json:"geosite-path"`
|
||||
Rules []Rule `json:"rules"`
|
||||
Warp WarpOptions `json:"warp"`
|
||||
Warp2 WarpOptions `json:"warp"`
|
||||
Warp2 WarpOptions `json:"warp2"`
|
||||
Mux MuxOptions `json:"mux"`
|
||||
TLSTricks TLSTricks `json:"tls-tricks"`
|
||||
DNSOptions
|
||||
|
||||
@@ -134,6 +134,7 @@ func GenerateWarpInfo(license string, oldAccountId string, oldAccessToken string
|
||||
res += fmt.Sprintf("\nAccount type: %s\n", identity.Account.AccountType)
|
||||
warpcfg = WarpWireguardConfig{
|
||||
PrivateKey: identity.PrivateKey,
|
||||
PeerPublicKey: identity.Config.Peers[0].PublicKey,
|
||||
LocalAddressIPv4: identity.Config.Interface.Addresses.V4,
|
||||
LocalAddressIPv6: identity.Config.Interface.Addresses.V6,
|
||||
ClientID: identity.Config.ClientID,
|
||||
|
||||
@@ -19,10 +19,10 @@ import (
|
||||
"github.com/sagernet/sing-box/option"
|
||||
)
|
||||
|
||||
func RunStandalone(hiddifySettingPath string, configPath string) error {
|
||||
func RunStandalone(hiddifySettingPath string, configPath string, defaultConfig config.ConfigOptions) error {
|
||||
fmt.Println("Running in standalone mode")
|
||||
useFlutterBridge = false
|
||||
current, err := readAndBuildConfig(hiddifySettingPath, configPath)
|
||||
current, err := readAndBuildConfig(hiddifySettingPath, configPath, &defaultConfig)
|
||||
if err != nil {
|
||||
fmt.Printf("Error in read and build config %v", err)
|
||||
return err
|
||||
@@ -48,26 +48,34 @@ func RunStandalone(hiddifySettingPath string, configPath string) error {
|
||||
}
|
||||
|
||||
type ConfigResult struct {
|
||||
Config string
|
||||
RefreshInterval int
|
||||
Config string
|
||||
RefreshInterval int
|
||||
HiddifyConfigOptions *config.ConfigOptions
|
||||
}
|
||||
|
||||
func readAndBuildConfig(hiddifySettingPath string, configPath string) (ConfigResult, error) {
|
||||
func readAndBuildConfig(hiddifySettingPath string, configPath string, defaultConfig *config.ConfigOptions) (ConfigResult, error) {
|
||||
var result ConfigResult
|
||||
|
||||
result, err := readConfigContent(configPath)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
hiddifyconfig := config.DefaultConfigOptions()
|
||||
|
||||
if defaultConfig != nil {
|
||||
hiddifyconfig = defaultConfig
|
||||
}
|
||||
|
||||
if hiddifySettingPath != "" {
|
||||
hiddifyconfig, err = readConfigOptionsAt(hiddifySettingPath)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
configOptions = hiddifyconfig
|
||||
result.Config, err = buildConfig(result.Config, *hiddifyconfig)
|
||||
|
||||
result.HiddifyConfigOptions = hiddifyconfig
|
||||
result.Config, err = buildConfig(result.Config, *result.HiddifyConfigOptions)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
@@ -186,7 +194,7 @@ func updateConfigInterval(current ConfigResult, hiddifySettingPath string, confi
|
||||
|
||||
for {
|
||||
<-time.After(time.Duration(current.RefreshInterval) * time.Hour)
|
||||
new, err := readAndBuildConfig(hiddifySettingPath, configPath)
|
||||
new, err := readAndBuildConfig(hiddifySettingPath, configPath, current.HiddifyConfigOptions)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user