-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
84 lines (71 loc) · 2.01 KB
/
main.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
package main
import (
"fmt"
"gitlab.ecoworkinc.com/subspace/softetherlib/softether"
)
var printMap = func(m map[string]string) {
for a, b := range m {
fmt.Printf("%s: %s\n", a, b)
}
fmt.Println("")
}
func main() {
s := softether.SoftEther{IP: "54.89.114.55", Password: "subspace", Hub: "subspace"}
// Get Server Status
serverStatus, _ := s.GetServerStatus()
fmt.Println("Server Status")
fmt.Println("-------------")
printMap(serverStatus)
// Set PreShared Key
err := s.SetPreSharedKey("abcdefg")
fmt.Println(err)
fmt.Println("ERROR: ", softether.Strerror(err))
// Get Session List
sessionList, _ := s.GetSessionList()
fmt.Println("Session List")
fmt.Println("-------------")
for a, session := range sessionList {
fmt.Printf("[Session %d]\n", a)
for c, d := range session {
fmt.Printf("%s: %s\n", c, d)
}
fmt.Println("")
}
fmt.Println("")
// Get Session Info
fmt.Println("Session Info")
fmt.Println("-------------")
sessionInfo, _ := s.GetSessionInfo("SID-SECURENAT-1")
printMap(sessionInfo)
// Create User, Set Password and Get User Info
s.CreateUser("1", "[email protected]", "New Account")
s.SetUserPassword("1", "abcde")
createdUser, _ := s.GetUserInfo("1")
fmt.Println("Created User")
fmt.Println("------------")
printMap(createdUser)
// Update User information
s.SetUserInfo("1", "[email protected]", "Modified Account Name")
updatedUser, _ := s.GetUserInfo("1")
fmt.Println("Updated User Alias")
fmt.Println("------------------")
printMap(updatedUser)
// Revoke user
s.SetUserEnabled("1", false)
revokedUser, _ := s.GetUserInfo("1")
fmt.Println("Revoked User")
fmt.Println("------------------")
printMap(revokedUser)
// Reenable user
s.SetUserEnabled("1", true)
enabledUser, _ := s.GetUserInfo("1")
fmt.Println("Revoked User")
fmt.Println("------------------")
printMap(enabledUser)
// Delete the user
s.DeleteUser("1")
_, err := s.GetUserInfo("1")
fmt.Println("User Deleted")
fmt.Println("------------")
fmt.Println("Return Code: ", softether.Strerror(err))
}