feat: add argument --reset-password

This commit is contained in:
mzz2017 committed 2020-02-24 19:43:17 +08:00
1 parent 9ae0e44bab
commit 793217bf9e
4 files changed
+20 -7

No files matched your search

+4 -4
View File
@@ -21,8 +21,8 @@ export default {
default: "V2RayA service is running,Version: {version}",
newVersion: "Detected new version: {version}",
messages: [
"There is no servers now.",
"You can create a server or import a subscription now. Vmess, SS and SSR are supported."
"There is no server.",
"You can create a server or import a subscription. Vmess, SS and SSR are supported."
]
},
v2ray: {
@@ -64,11 +64,11 @@ export default {
helpManual: "Help & Manual"
},
register: {
title: "Nice to meet you! Create an admin account now",
title: "Create an admin account first",
messages: [
"Remember your admin account which is importantly used to login.",
"Account information is stored in local. We never send information to any server.",
"Once password is forgot, you can delete the config file and restart V2RayA service to reset."
"Once password was forgot, you could delete the config file and restart V2RayA service to reset."
]
},
login: {
+2 -1
View File
@@ -12,8 +12,9 @@ type Params struct {
Address string `id:"address" short:"a" default:"0.0.0.0:2017" desc:"监听地址"`
Config string `id:"config" short:"c" default:"/etc/v2ray/v2raya.json" desc:"V2RayA配置文件路径"`
Mode string `id:"mode" short:"m" desc:"可选systemctl, service, docker, common. 不设置则自动检测"`
SSRListenPort int `short:"s" default:"12346" desc:"使用ss或ssr时的ssr server监听端口,默认12346"`
SSRListenPort int `short:"s" default:"12346" desc:"使用ss或ssr时的ssr server监听端口"`
PassCheckRoot bool `desc:"可跳过启动时的权限检查"`
ResetPassword bool `id:"reset-password"`
ShowVersion bool `id:"version"`
}
+11 -2
View File
@@ -34,12 +34,21 @@ func checkEnvironment() {
_, _ = fmt.Scanf("\n")
os.Exit(1)
}
if !global.GetEnvironmentConfig().PassCheckRoot {
conf := global.GetEnvironmentConfig()
if !conf.PassCheckRoot || conf.ResetPassword {
if os.Getegid() != 0 {
log.Fatal("请以sudo或root权限执行本程序. 如您确信已sudo或已拥有root权限, 可使用--passcheckroot参数跳过检查")
}
}
_, port, err := net.SplitHostPort(global.GetEnvironmentConfig().Address)
if conf.ResetPassword {
err := configure.ResetAccounts()
if err != nil {
log.Fatal(err)
}
fmt.Println("ok")
os.Exit(0)
}
_, port, err := net.SplitHostPort(conf.Address)
if err != nil {
log.Fatal(err)
}
@@ -213,6 +213,9 @@ func SetAccount(username, password string) (err error) {
path := fmt.Sprintf("accounts.%s", username)
return persistence.Set(path, password)
}
func ResetAccounts() (err error) {
return persistence.Set("accounts", nil)
}
func ExistsAccount(username string) bool {
return persistence.Exists(fmt.Sprintf("accounts.%s", username))
}