Skip to content

Commit

Permalink
分割配置文件,添加环境变量
Browse files Browse the repository at this point in the history
  • Loading branch information
hsernos committed Mar 3, 2021
1 parent aaba0cb commit dfa6172
Show file tree
Hide file tree
Showing 51 changed files with 1,962 additions and 2,208 deletions.
249 changes: 126 additions & 123 deletions README.md

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions Txray.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@ package main

import (
"Txray/cmd"
"Txray/core/config"
"Txray/core/service"
"Txray/log"
"Txray/tools"
"github.com/abiosoft/ishell"
"os"
)

const (
version = "v2.0.1"
version = "v2.1.0"
name = "Txray"
)

func init() {
// 初始化日志
absPath := tools.PathJoin(tools.GetRunPath(), "info.log")
absPath := tools.PathJoin(config.GetConfigDir(), "info.log")
log.Init(
log.GetConsoleZapcore(log.INFO),
log.GetFileZapcore(absPath, log.INFO, 5),
Expand All @@ -33,5 +35,5 @@ func main() {
shell.Printf("%s - Xray Shell Client - %s\n", name, version)
shell.Run()
}
defer cmd.Kill()
defer service.Stop()
}
2 changes: 1 addition & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def build(goos, goarch, path, cgo=0):
path)
os.system(cmd)
shutil.copy("README.md", "build/"+"-".join([Name, syst, arch]))
make_zip("build/"+"-".join([Name, syst, arch]),"build/"+"-".join([Name, syst, arch])+".zip")
make_zip("build/"+"-".join([Name, syst, arch]), "build/"+"-".join([Name, syst, arch])+".zip")

if __name__ == '__main__':
if get_os() == 'win':
Expand Down
141 changes: 141 additions & 0 deletions cmd/base_setting_shell.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package cmd

import (
"Txray/core/setting"
"Txray/tools"
"Txray/tools/format"
"github.com/abiosoft/ishell"
"os"
)

func InitSettingShell(shell *ishell.Shell) {
baseSettingCmd := &ishell.Cmd{
Name: "base",
Help: "查看基础设置",
Func: func(c *ishell.Context) {
base := setting.Base()
data := []string{tools.UintToStr(base.Socks),
tools.UintToStr(base.Http),
tools.BoolToStr(base.UDP),
tools.BoolToStr(base.Sniffing),
tools.BoolToStr(base.Mux),
tools.BoolToStr(base.AllowLANConn),
tools.BoolToStr(base.BypassLanAndContinent),
base.DomainStrategy,
}
format.ShowSetting(os.Stdout, data)
},
}
baseSettingCmd.AddCmd(&ishell.Cmd{
Name: "help",
Help: "基础设置help文档",
Func: func(c *ishell.Context) {
c.Println(HelpSetting())
},
})
baseSettingCmd.AddCmd(&ishell.Cmd{
Name: "socks",
Help: "修改socks端口",
Func: func(c *ishell.Context) {
if len(c.Args) == 1 && tools.IsNetPort(c.Args[0]) {
setting.SetSocksPort(tools.StrToUint(c.Args[0]))
}
},
})
baseSettingCmd.AddCmd(&ishell.Cmd{
Name: "http",
Help: "修改http端口",
Func: func(c *ishell.Context) {
if len(c.Args) == 1 && tools.IsNetPort(c.Args[0]) {
setting.SetHttpPort(tools.StrToUint(c.Args[0]))
}
},
})
baseSettingCmd.AddCmd(&ishell.Cmd{
Name: "udp",
Help: "是否启用udp",
Func: func(c *ishell.Context) {
if len(c.Args) == 1 {
key := c.Args[0]
if key == "y" {
setting.SetUDP(true)
} else if key == "n" {
setting.SetUDP(false)
}
}
},
})
baseSettingCmd.AddCmd(&ishell.Cmd{
Name: "sniffing",
Help: "是否启用流量监听",
Func: func(c *ishell.Context) {
if len(c.Args) == 1 {
key := c.Args[0]
if key == "y" {
setting.SetSniffing(true)
} else if key == "n" {
setting.SetSniffing(false)
}
}
},
})
baseSettingCmd.AddCmd(&ishell.Cmd{
Name: "lanconn",
Help: "是否启用局域网连接",
Func: func(c *ishell.Context) {
if len(c.Args) == 1 {
key := c.Args[0]
if key == "y" {
setting.SetLANConn(true)
} else if key == "n" {
setting.SetLANConn(false)
}
}
},
})
baseSettingCmd.AddCmd(&ishell.Cmd{
Name: "mux",
Help: "是否启用多路复用",
Func: func(c *ishell.Context) {
if len(c.Args) == 1 {
key := c.Args[0]
if key == "y" {
setting.SetMux(true)
} else if key == "n" {
setting.SetMux(false)
}
}
},
})
baseSettingCmd.AddCmd(&ishell.Cmd{
Name: "bypass",
Help: "是否绕过局域网及大陆",
Func: func(c *ishell.Context) {
if len(c.Args) == 1 {
key := c.Args[0]
if key == "y" {
setting.SetBypassLanAndContinent(true)
} else if key == "n" {
setting.SetBypassLanAndContinent(false)
}
}
},
})
baseSettingCmd.AddCmd(&ishell.Cmd{
Name: "routing",
Help: "设置路由策略",
Func: func(c *ishell.Context) {
if len(c.Args) == 1 {
key := c.Args[0]
if key == "1" {
setting.SetDomainStrategy(1)
} else if key == "2" {
setting.SetDomainStrategy(2)
} else if key == "3" {
setting.SetDomainStrategy(3)
}
}
},
})
shell.AddCmd(baseSettingCmd)
}
64 changes: 64 additions & 0 deletions cmd/dns_setting_shell.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package cmd

import (
"Txray/core/setting"
"Txray/tools"
"Txray/tools/format"
"github.com/abiosoft/ishell"
"os"
"strings"
)

func InitDNSShell(shell *ishell.Shell) {
dnsCmd := &ishell.Cmd{
Name: "dns",
Help: "查看DNS设置",
Func: func(c *ishell.Context) {
data := []string{
tools.UintToStr(setting.DNSPort()),
setting.OutlandDNS(),
setting.InlandDNS(),
strings.Join(setting.BackupDNS(), ","),
}
format.ShowDNS(os.Stdout, data)
},
}
dnsCmd.AddCmd(&ishell.Cmd{
Name: "help",
Help: "查看帮助",
Func: func(c *ishell.Context) {
c.Println(HelpDNS())
},
})
dnsCmd.AddCmd(&ishell.Cmd{
Name: "port",
Help: "设置dns端口",
Func: func(c *ishell.Context) {
if len(c.Args) == 1 && tools.IsNetPort(c.Args[0]) {
setting.SetDNSPort(tools.StrToUint(c.Args[0]))
}
},
})
dnsCmd.AddCmd(&ishell.Cmd{
Name: "inland",
Help: "设置境内DNS",
Func: func(c *ishell.Context) {
setting.SetInlandDNS(c.Args[0])
},
})
dnsCmd.AddCmd(&ishell.Cmd{
Name: "outland",
Help: "设置境外DNS",
Func: func(c *ishell.Context) {
setting.SetOutlandDNS(c.Args[0])
},
})
dnsCmd.AddCmd(&ishell.Cmd{
Name: "backup",
Help: "设置备用DNS",
Func: func(c *ishell.Context) {
setting.SetBackupDNS(strings.Join(c.Args, ","))
},
})
shell.AddCmd(dnsCmd)
}
58 changes: 0 additions & 58 deletions cmd/dns_shell.go

This file was deleted.

Loading

0 comments on commit dfa6172

Please sign in to comment.