-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
user-info.go
49 lines (43 loc) · 1.18 KB
/
user-info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package cmd
import (
"fmt"
"github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/backend/utils/encrypt"
"github.com/spf13/cobra"
)
func init() {
RootCmd.AddCommand(userinfoCmd)
}
var userinfoCmd = &cobra.Command{
Use: "user-info",
Short: "获取用户信息",
RunE: func(cmd *cobra.Command, args []string) error {
if !isRoot() {
fmt.Println("请使用 sudo 1pctl user-info 或者切换到 root 用户")
return nil
}
db, err := loadDBConn()
if err != nil {
return fmt.Errorf("init my db conn failed, err: %v \n", err)
}
user := getSettingByKey(db, "UserName")
password := getSettingByKey(db, "Password")
port := getSettingByKey(db, "ServerPort")
ssl := getSettingByKey(db, "SSL")
entrance := getSettingByKey(db, "SecurityEntrance")
encryptSetting := getSettingByKey(db, "EncryptKey")
p := ""
if len(encryptSetting) == 16 {
global.CONF.System.EncryptKey = encryptSetting
p, _ = encrypt.StringDecrypt(password)
} else {
p = password
}
fmt.Printf("username: %s\n", user)
fmt.Printf("password: %s\n", p)
fmt.Printf("port: %s\n", port)
fmt.Printf("ssl: %s\n", ssl)
fmt.Printf("entrance: %s\n", entrance)
return nil
},
}