-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathshells.go
158 lines (123 loc) · 3.35 KB
/
shells.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package main
import (
"context"
"fmt"
"net/url"
"os"
"github.com/KarpelesLab/rest"
)
type Shell struct {
Id string `json:"Shell__"`
Label string
Egine string // "full"
Size int
Status string
State string
SshPort int `json:"Ssh_Port"`
Username string
Hostname string
MAC string
IPv4 string // internal ipv4
IPv6 string // internal ipv6
Created rest.Time
Expires rest.Time
Host *ShellHost
IPs []*ShellIP
OS *ShellOs
Datacenter *ShellDatacenter `json:"Shell_Datacenter"`
// Ephemeral_Viewer
EphemeralViewer string `json:"Ephemeral_Viewer"`
}
type ShellHost struct {
Id string `json:"Shell_Host__"`
Name string // "ams01-09"
IP string
PublicIP string `json:"Public_IP"`
IPv6 string
Kernel string // host kernel
}
type ShellIP struct {
IP string
Family string // "ipv4"
Type string // "nat", "route" or "anycast"
}
type ShellDatacenter struct {
Name string // "ams01"
Location string // "Amsterdam (Europe)"
Country string `json:"Country__"`
}
func shellsList(ri *runInfo) error {
// list available shells
var list []Shell
err := ri.auth.Apply(context.Background(), "Shell", "GET", map[string]any{}, &list)
if err != nil {
return err
}
for _, shell := range list {
fmt.Fprintf(os.Stdout, "%s %s (%s)\r\n", shell.Id, shell.Label, shell.State)
}
return nil
}
func shellsInfo(ri *runInfo) error {
var shell *Shell
err := ri.auth.Apply(context.Background(), "Shell/"+ri.flags["shell"], "GET", map[string]any{}, &shell)
if err != nil {
return err
}
fmt.Fprintf(os.Stdout, "Id: %s\r\n", shell.Id)
fmt.Fprintf(os.Stdout, "Label: %s\r\n", shell.Label)
fmt.Fprintf(os.Stdout, "Size: %d units\r\n", shell.Size)
fmt.Fprintf(os.Stdout, "State: %s\r\n", shell.State)
fmt.Fprintf(os.Stdout, "Host: %s\r\n", shell.Host.Name)
return nil
}
func shellsState(ri *runInfo) error {
var shell *Shell
err := ri.auth.Apply(context.Background(), "Shell/"+ri.flags["shell"], "GET", map[string]any{}, &shell)
if err != nil {
return err
}
fmt.Fprintf(os.Stdout, "%s\r\n", shell.State)
return nil
}
func shellsView(ri *runInfo) error {
var res linkAccess
err := ri.auth.Apply(context.Background(), "MetaObject/"+ri.flags["shell"]+":linkAccess", "POST", map[string]any{"access": "A", "expires": "+2 hour"}, &res)
if err != nil {
return err
}
fmt.Fprintf(os.Stdout, "https://view.shells.com/?id=%s\r\n", url.QueryEscape(res.Link))
return nil
}
func shellsStart(ri *runInfo) error {
var res map[string]any
err := ri.auth.Apply(context.Background(), "Shell/"+ri.flags["shell"]+":start", "POST", map[string]any{}, &res)
if err != nil {
return err
}
return nil
}
func shellsStop(ri *runInfo) error {
var res map[string]any
err := ri.auth.Apply(context.Background(), "Shell/"+ri.flags["shell"]+":stop", "POST", map[string]any{}, &res)
if err != nil {
return err
}
return nil
}
func shellsRestart(ri *runInfo) error {
var res map[string]any
err := ri.auth.Apply(context.Background(), "Shell/"+ri.flags["shell"]+":restart", "POST", map[string]any{}, &res)
if err != nil {
return err
}
return nil
}
func shellsReboot(ri *runInfo) error {
var res map[string]any
err := ri.auth.Apply(context.Background(), "Shell/"+ri.flags["shell"]+":reboot", "POST", map[string]any{}, &res)
if err != nil {
return err
}
return nil
}