mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-04-19 13:32:24 +00:00
Merge branch 'MHSanaei:main' into main
This commit is contained in:
commit
d405141ad0
3 changed files with 97 additions and 114 deletions
3
go.mod
3
go.mod
|
@ -14,7 +14,6 @@ require (
|
||||||
github.com/pelletier/go-toml/v2 v2.0.7
|
github.com/pelletier/go-toml/v2 v2.0.7
|
||||||
github.com/robfig/cron/v3 v3.0.1
|
github.com/robfig/cron/v3 v3.0.1
|
||||||
github.com/shirou/gopsutil/v3 v3.23.4
|
github.com/shirou/gopsutil/v3 v3.23.4
|
||||||
github.com/spf13/cobra v1.7.0
|
|
||||||
github.com/xtls/xray-core v1.8.1
|
github.com/xtls/xray-core v1.8.1
|
||||||
go.uber.org/atomic v1.11.0
|
go.uber.org/atomic v1.11.0
|
||||||
golang.org/x/text v0.9.0
|
golang.org/x/text v0.9.0
|
||||||
|
@ -36,7 +35,6 @@ require (
|
||||||
github.com/gorilla/context v1.1.1 // indirect
|
github.com/gorilla/context v1.1.1 // indirect
|
||||||
github.com/gorilla/securecookie v1.1.1 // indirect
|
github.com/gorilla/securecookie v1.1.1 // indirect
|
||||||
github.com/gorilla/sessions v1.2.1 // indirect
|
github.com/gorilla/sessions v1.2.1 // indirect
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
|
||||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||||
github.com/jinzhu/now v1.1.5 // indirect
|
github.com/jinzhu/now v1.1.5 // indirect
|
||||||
github.com/json-iterator/go v1.1.12 // indirect
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
|
@ -50,7 +48,6 @@ require (
|
||||||
github.com/pires/go-proxyproto v0.7.0 // indirect
|
github.com/pires/go-proxyproto v0.7.0 // indirect
|
||||||
github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b // indirect
|
github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b // indirect
|
||||||
github.com/shoenig/go-m1cpu v0.1.5 // indirect
|
github.com/shoenig/go-m1cpu v0.1.5 // indirect
|
||||||
github.com/spf13/pflag v1.0.5 // indirect
|
|
||||||
github.com/tklauser/go-sysconf v0.3.11 // indirect
|
github.com/tklauser/go-sysconf v0.3.11 // indirect
|
||||||
github.com/tklauser/numcpus v0.6.0 // indirect
|
github.com/tklauser/numcpus v0.6.0 // indirect
|
||||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||||
|
|
8
go.sum
8
go.sum
|
@ -14,7 +14,6 @@ github.com/bytedance/sonic v1.8.8/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZX
|
||||||
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
|
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
|
||||||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams=
|
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams=
|
||||||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
|
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
@ -73,8 +72,6 @@ github.com/gorilla/sessions v1.2.0/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/z
|
||||||
github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7FsgI=
|
github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7FsgI=
|
||||||
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
|
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
|
||||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
|
||||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
|
||||||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
||||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
||||||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
|
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
|
||||||
|
@ -133,7 +130,6 @@ github.com/refraction-networking/utls v1.3.2 h1:o+AkWB57mkcoW36ET7uJ002CpBWHu0KP
|
||||||
github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 h1:f/FNXud6gA3MNr8meMVVGxhp+QBTqY91tM8HjEuMjGg=
|
github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 h1:f/FNXud6gA3MNr8meMVVGxhp+QBTqY91tM8HjEuMjGg=
|
||||||
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
||||||
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
||||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
|
||||||
github.com/sagernet/sing v0.2.3 h1:V50MvZ4c3Iij2lYFWPlzL1PyipwSzjGeN9x+Ox89vpk=
|
github.com/sagernet/sing v0.2.3 h1:V50MvZ4c3Iij2lYFWPlzL1PyipwSzjGeN9x+Ox89vpk=
|
||||||
github.com/sagernet/sing-shadowsocks v0.2.1 h1:FvdLQOqpvxHBJUcUe4fvgiYP2XLLwH5i1DtXQviVEPw=
|
github.com/sagernet/sing-shadowsocks v0.2.1 h1:FvdLQOqpvxHBJUcUe4fvgiYP2XLLwH5i1DtXQviVEPw=
|
||||||
github.com/sagernet/wireguard-go v0.0.0-20221116151939-c99467f53f2c h1:vK2wyt9aWYHHvNLWniwijBu/n4pySypiKRhN32u/JGo=
|
github.com/sagernet/wireguard-go v0.0.0-20221116151939-c99467f53f2c h1:vK2wyt9aWYHHvNLWniwijBu/n4pySypiKRhN32u/JGo=
|
||||||
|
@ -144,10 +140,6 @@ github.com/shoenig/go-m1cpu v0.1.5 h1:LF57Z/Fpb/WdGLjt2HZilNnmZOxg/q2bSKTQhgbrLr
|
||||||
github.com/shoenig/go-m1cpu v0.1.5/go.mod h1:Wwvst4LR89UxjeFtLRMrpgRiyY4xPsejnVZym39dbAQ=
|
github.com/shoenig/go-m1cpu v0.1.5/go.mod h1:Wwvst4LR89UxjeFtLRMrpgRiyY4xPsejnVZym39dbAQ=
|
||||||
github.com/shoenig/test v0.6.3 h1:GVXWJFk9PiOjN0KoJ7VrJGH6uLPnqxR7/fe3HUPfE0c=
|
github.com/shoenig/test v0.6.3 h1:GVXWJFk9PiOjN0KoJ7VrJGH6uLPnqxR7/fe3HUPfE0c=
|
||||||
github.com/shoenig/test v0.6.3/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k=
|
github.com/shoenig/test v0.6.3/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k=
|
||||||
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
|
|
||||||
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
|
|
||||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
|
||||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
|
|
200
main.go
200
main.go
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
@ -71,10 +72,7 @@ func runWebServer() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
err := server.Stop()
|
server.Stop()
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -239,112 +237,108 @@ func removeSecret() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var rootCmd = &cobra.Command{
|
if len(os.Args) < 2 {
|
||||||
Use: "x-ui",
|
runWebServer()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var runCmd = &cobra.Command{
|
var showVersion bool
|
||||||
Use: "run",
|
flag.BoolVar(&showVersion, "v", false, "show version")
|
||||||
Short: "Run the web server",
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
runCmd := flag.NewFlagSet("run", flag.ExitOnError)
|
||||||
runWebServer()
|
|
||||||
},
|
v2uiCmd := flag.NewFlagSet("v2-ui", flag.ExitOnError)
|
||||||
|
var dbPath string
|
||||||
|
v2uiCmd.StringVar(&dbPath, "db", fmt.Sprintf("%s/v2-ui.db", config.GetDBFolderPath()), "set v2-ui db file path")
|
||||||
|
|
||||||
|
settingCmd := flag.NewFlagSet("setting", flag.ExitOnError)
|
||||||
|
var port int
|
||||||
|
var username string
|
||||||
|
var password string
|
||||||
|
var tgbottoken string
|
||||||
|
var tgbotchatid string
|
||||||
|
var enabletgbot bool
|
||||||
|
var tgbotRuntime string
|
||||||
|
var reset bool
|
||||||
|
var show bool
|
||||||
|
var remove_secret bool
|
||||||
|
settingCmd.BoolVar(&reset, "reset", false, "reset all settings")
|
||||||
|
settingCmd.BoolVar(&show, "show", false, "show current settings")
|
||||||
|
settingCmd.IntVar(&port, "port", 0, "set panel port")
|
||||||
|
settingCmd.StringVar(&username, "username", "", "set login username")
|
||||||
|
settingCmd.StringVar(&password, "password", "", "set login password")
|
||||||
|
settingCmd.StringVar(&tgbottoken, "tgbottoken", "", "set telegram bot token")
|
||||||
|
settingCmd.StringVar(&tgbotRuntime, "tgbotRuntime", "", "set telegram bot cron time")
|
||||||
|
settingCmd.StringVar(&tgbotchatid, "tgbotchatid", "", "set telegram bot chat id")
|
||||||
|
settingCmd.BoolVar(&enabletgbot, "enabletgbot", false, "enable telegram bot notify")
|
||||||
|
|
||||||
|
oldUsage := flag.Usage
|
||||||
|
flag.Usage = func() {
|
||||||
|
oldUsage()
|
||||||
|
fmt.Println()
|
||||||
|
fmt.Println("Commands:")
|
||||||
|
fmt.Println(" run run web panel")
|
||||||
|
fmt.Println(" v2-ui migrate form v2-ui")
|
||||||
|
fmt.Println(" migrate migrate form other/old x-ui")
|
||||||
|
fmt.Println(" setting set settings")
|
||||||
}
|
}
|
||||||
|
|
||||||
var migrateCmd = &cobra.Command{
|
flag.Parse()
|
||||||
Use: "migrate",
|
if showVersion {
|
||||||
Short: "Migrate from other/old x-ui",
|
fmt.Println(config.GetVersion())
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
return
|
||||||
migrateDb()
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var v2uiCmd = &cobra.Command{
|
switch os.Args[1] {
|
||||||
Use: "v2-ui",
|
case "run":
|
||||||
Short: "Migrate from v2-ui",
|
err := runCmd.Parse(os.Args[2:])
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
if err != nil {
|
||||||
dbPath, _ := cmd.Flags().GetString("db")
|
fmt.Println(err)
|
||||||
err := v2ui.MigrateFromV2UI(dbPath)
|
return
|
||||||
if err != nil {
|
}
|
||||||
fmt.Println("migrate from v2-ui failed:", err)
|
runWebServer()
|
||||||
}
|
case "migrate":
|
||||||
},
|
migrateDb()
|
||||||
}
|
case "v2-ui":
|
||||||
|
err := v2uiCmd.Parse(os.Args[2:])
|
||||||
v2uiCmd.Flags().String("db", fmt.Sprintf("%s/v2-ui.db", config.GetDBFolderPath()), "set v2-ui db file path")
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
var settingCmd = &cobra.Command{
|
return
|
||||||
Use: "setting",
|
}
|
||||||
Short: "Set settings",
|
err = v2ui.MigrateFromV2UI(dbPath)
|
||||||
}
|
if err != nil {
|
||||||
|
fmt.Println("migrate from v2-ui failed:", err)
|
||||||
var resetCmd = &cobra.Command{
|
}
|
||||||
Use: "reset",
|
case "setting":
|
||||||
Short: "Reset all settings",
|
err := settingCmd.Parse(os.Args[2:])
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if reset {
|
||||||
resetSetting()
|
resetSetting()
|
||||||
},
|
} else {
|
||||||
}
|
|
||||||
|
|
||||||
var showCmd = &cobra.Command{
|
|
||||||
Use: "show",
|
|
||||||
Short: "Show current settings",
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
|
||||||
showSetting(true)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
var updateCmd = &cobra.Command{
|
|
||||||
Use: "update",
|
|
||||||
Short: "Update settings",
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
|
||||||
port, _ := cmd.Flags().GetInt("port")
|
|
||||||
username, _ := cmd.Flags().GetString("username")
|
|
||||||
password, _ := cmd.Flags().GetString("password")
|
|
||||||
updateSetting(port, username, password)
|
updateSetting(port, username, password)
|
||||||
},
|
}
|
||||||
}
|
if show {
|
||||||
|
showSetting(show)
|
||||||
updateCmd.Flags().Int("port", 0, "set panel port")
|
}
|
||||||
updateCmd.Flags().String("username", "", "set login username")
|
if (tgbottoken != "") || (tgbotchatid != "") || (tgbotRuntime != "") {
|
||||||
updateCmd.Flags().String("password", "", "set login password")
|
updateTgbotSetting(tgbottoken, tgbotchatid, tgbotRuntime)
|
||||||
|
}
|
||||||
var tgbotCmd = &cobra.Command{
|
if remove_secret {
|
||||||
Use: "tgbot",
|
removeSecret()
|
||||||
Short: "Update telegram bot settings",
|
}
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
if enabletgbot {
|
||||||
tgbottoken, _ := cmd.Flags().GetString("tgbottoken")
|
updateTgbotEnableSts(enabletgbot)
|
||||||
tgbotchatid, _ := cmd.Flags().GetString("tgbotchatid")
|
}
|
||||||
tgbotRuntime, _ := cmd.Flags().GetString("tgbotRuntime")
|
default:
|
||||||
enabletgbot, _ := cmd.Flags().GetBool("enabletgbot")
|
fmt.Println("except 'run' or 'v2-ui' or 'setting' subcommands")
|
||||||
remove_secret, _ := cmd.Flags().GetBool("remove_secret")
|
fmt.Println()
|
||||||
|
runCmd.Usage()
|
||||||
if tgbottoken != "" || tgbotchatid != "" || tgbotRuntime != "" {
|
fmt.Println()
|
||||||
updateTgbotSetting(tgbottoken, tgbotchatid, tgbotRuntime)
|
v2uiCmd.Usage()
|
||||||
}
|
fmt.Println()
|
||||||
|
settingCmd.Usage()
|
||||||
if remove_secret {
|
|
||||||
removeSecret()
|
|
||||||
}
|
|
||||||
|
|
||||||
if enabletgbot {
|
|
||||||
updateTgbotEnableSts(enabletgbot)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
tgbotCmd.Flags().String("tgbottoken", "", "set telegram bot token")
|
|
||||||
tgbotCmd.Flags().String("tgbotchatid", "", "set telegram bot chat id")
|
|
||||||
tgbotCmd.Flags().String("tgbotRuntime", "", "set telegram bot cron time")
|
|
||||||
tgbotCmd.Flags().Bool("enabletgbot", false, "enable telegram bot notify")
|
|
||||||
tgbotCmd.Flags().Bool("remove_secret", false, "remove secret")
|
|
||||||
|
|
||||||
settingCmd.AddCommand(resetCmd, showCmd, updateCmd, tgbotCmd)
|
|
||||||
|
|
||||||
rootCmd.AddCommand(runCmd, migrateCmd, v2uiCmd, settingCmd)
|
|
||||||
|
|
||||||
if err := rootCmd.Execute(); err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue