-
Notifications
You must be signed in to change notification settings - Fork 8
/
discard_sessions.go
86 lines (66 loc) · 2.21 KB
/
discard_sessions.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
package Examples
import (
api "../APIFiles"
"fmt"
"os"
)
func DiscardSessions() {
var apiServer string
var username string
var password string
fmt.Printf("Enter server IP address or hostname: ")
fmt.Scanln(&apiServer)
fmt.Printf("Enter username: ")
fmt.Scanln(&username)
fmt.Printf("Enter password: ")
fmt.Scanln(&password)
args := api.APIClientArgs(api.DefaultPort, "", "", apiServer, "", -1, "", false, false, "deb.txt", api.WebContext, api.TimeOut, api.SleepTime, "", "", -1)
client := api.APIClient(args)
if x, _ := client.CheckFingerprint(); !x {
print("Could not get the server's fingerprint - Check connectivity with the server.\n")
os.Exit(1)
}
loginRes, err := client.Login(username, password, false, "", false, "")
if err != nil {
print("Login error.\n")
os.Exit(1)
}
if !loginRes.Success {
print("Login failed:\n" + loginRes.ErrorMsg)
os.Exit(1)
}
payload := map[string]interface{}{
"name": "fake_name2",
"ip-address": "1.1.1.2",
}
_, err = client.ApiCall("add-host", payload, client.GetSessionID(), false, false)
if err != nil {
print("error" + err.Error() + "\n")
}
//payload = map[string]interface{} {}
//client.ApiCall("publish", payload, client.GetSessionID(), false, false)
showSessionsRes, err := client.ApiQuery("show-sessions", "full", "objects", false, map[string]interface{}{})
if err != nil {
print("Failed to retrieve the sessions\n")
return
}
_, err2 := client.ApiQuery("show-hosts", "full", "objects", false, map[string]interface{}{})
if err2 != nil {
print("Failed to retrieve the sessions\n")
return
}
//fmt.Println(show_sessions_res.GetData())
var discardRes api.APIResponse
for _, sessionObj := range showSessionsRes.GetData() {
//fmt.Println(sessionObj)
if sessionObj.(map[string]interface{})["application"].(string) != "WEB_API" {
continue
}
discardRes, _ = client.ApiCall("discard", map[string]interface{}{"uid": sessionObj.(map[string]interface{})["uid"]}, "", false, false)
if discardRes.Success {
fmt.Println("Session " + sessionObj.(map[string]interface{})["uid"].(string)+ " discarded successfully")
} else {
fmt.Println("Session " + sessionObj.(map[string]interface{})["uid"].(string)+ " failed to discard")
}
}
}