■ ■ ■ ■ ■ ■ ■
internal/server/commands/list.go
1 | 1 | | package commands |
2 | 2 | | |
3 | 3 | | import ( |
| 4 | + | "encoding/json" |
4 | 5 | | "fmt" |
5 | 6 | | "io" |
| 7 | + | "log" |
6 | 8 | | "sort" |
7 | 9 | | "strings" |
8 | 10 | | |
| 11 | + | "github.com/NHAS/reverse_ssh/internal" |
9 | 12 | | "github.com/NHAS/reverse_ssh/internal/server/clients" |
10 | 13 | | "github.com/NHAS/reverse_ssh/internal/terminal" |
11 | 14 | | "github.com/NHAS/reverse_ssh/internal/terminal/autocomplete" |
| skipped 11 lines |
23 | 26 | | |
24 | 27 | | func fancyTable(tty io.ReadWriter, applicable []displayItem) { |
25 | 28 | | |
26 | | - | t, _ := table.NewTable("Targets", "ID", "Public Key ID", "Hostname", "IP Address", "Version") |
| 29 | + | t, _ := table.NewTable("Targets", "IDs", "Version", "Arch") |
27 | 30 | | for _, a := range applicable { |
28 | 31 | | |
| 32 | + | ok, result, err := a.sc.SendRequest("info", true, nil) |
| 33 | + | if err != nil { |
| 34 | + | continue |
| 35 | + | } |
| 36 | + | |
| 37 | + | arch := "-" |
| 38 | + | if ok { |
| 39 | + | c := internal.ClientInfo{} |
| 40 | + | err = json.Unmarshal(result, &c) |
| 41 | + | if err == nil { |
| 42 | + | arch = c.GoOS + "_" + c.GoArch |
| 43 | + | } |
| 44 | + | } |
| 45 | + | |
29 | 46 | | keyId := a.sc.Permissions.Extensions["pubkey-fp"] |
30 | 47 | | if a.sc.Permissions.Extensions["comment"] != "" { |
31 | 48 | | keyId = a.sc.Permissions.Extensions["comment"] |
32 | 49 | | } |
33 | 50 | | |
34 | | - | t.AddValues(a.id, keyId, clients.NormaliseHostname(a.sc.User()), a.sc.RemoteAddr().String(), string(a.sc.ClientVersion())) |
| 51 | + | if err := t.AddValues(fmt.Sprintf("%s\n%s\n%s\n%s\n", a.id, keyId, clients.NormaliseHostname(a.sc.User()), a.sc.RemoteAddr().String()), string(a.sc.ClientVersion()), arch); err != nil { |
| 52 | + | log.Println("Error drawing pretty ls table (THIS IS A BUG): ", err) |
| 53 | + | return |
| 54 | + | } |
35 | 55 | | } |
36 | 56 | | |
37 | 57 | | t.Fprint(tty) |
| skipped 51 lines |
89 | 109 | | |
90 | 110 | | for i, tr := range toReturn { |
91 | 111 | | |
| 112 | + | ok, result, err := tr.sc.SendRequest("info", true, nil) |
| 113 | + | if err != nil { |
| 114 | + | continue |
| 115 | + | } |
| 116 | + | |
| 117 | + | arch := "-" |
| 118 | + | if ok { |
| 119 | + | c := internal.ClientInfo{} |
| 120 | + | err = json.Unmarshal(result, &c) |
| 121 | + | if err == nil { |
| 122 | + | arch = c.GoOS + "_" + c.GoArch |
| 123 | + | } |
| 124 | + | } |
| 125 | + | |
92 | 126 | | keyId := tr.sc.Permissions.Extensions["pubkey-fp"] |
93 | 127 | | if tr.sc.Permissions.Extensions["comment"] != "" { |
94 | 128 | | keyId = tr.sc.Permissions.Extensions["comment"] |
95 | 129 | | } |
96 | 130 | | |
97 | | - | fmt.Fprintf(tty, "%s %s %s %s, version: %s", tr.id, keyId, clients.NormaliseHostname(tr.sc.User()), tr.sc.RemoteAddr().String(), tr.sc.ClientVersion()) |
| 131 | + | fmt.Fprintf(tty, "%s %s %s %s, version: %s arch: %s", tr.id, keyId, clients.NormaliseHostname(tr.sc.User()), tr.sc.RemoteAddr().String(), tr.sc.ClientVersion(), arch) |
98 | 132 | | |
99 | 133 | | if i != len(toReturn)-1 { |
100 | 134 | | fmt.Fprint(tty, sep) |
| skipped 28 lines |