-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.go
50 lines (37 loc) · 1.6 KB
/
functions.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
package main
import (
"fmt"
"time"
)
func display_sessions(s []session) {
if len(sessions) == 0 {
fmt.Printf("%s", "No Active Sessions.")
return
}
var timenow int64 = time.Now().UTC().Unix()
var longest_username int
for i:=0;i<len(sessions);i++ {
if len(sessions[i].Username+"@"+sessions[i].Hostname) > longest_username {
longest_username = len(sessions[i].Username+"@"+sessions[i].Hostname)
}
}
if longest_username < 4 {
longest_username = 4
}
fmt.Println("SessionID IPAddress Os User",gchar(" ", longest_username - 4)+"Status")
fmt.Println("-------------------- --------------- -------",gchar("-", longest_username)+" --------")
for i:=0;i<len(sessions);i++ {
var status string = Fore.RED+"Inactive"+Fore.RESET
if sessions[i].Seen > timenow - 5 {
status = Fore.GREEN+"Active"+Fore.RESET
}
fmt.Println(Fore.YELLOW+sessions[i].SessionId+Fore.RESET,Fore.BLUE+sessions[i].IPAddress+Fore.RESET+gchar(" ", 15 - len(sessions[i].IPAddress)),sessions[i].OperatingSystem+gchar(" ", 7 - len(sessions[i].OperatingSystem)),Fore.RED+sessions[i].Username+"@"+sessions[i].Hostname+Fore.RESET+gchar(" ", longest_username - len(sessions[i].Username+"@"+sessions[i].Hostname)),status)
}
}
func gchar(c string, l int) string {
var result string
for i:=0;i<l;i++ {
result+=c
}
return result
}