mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
75 lines
1.3 KiB
Go
75 lines
1.3 KiB
Go
package security
|
|
|
|
import (
|
|
"fmt"
|
|
"sort"
|
|
"time"
|
|
|
|
"github.com/gdamore/tcell"
|
|
"github.com/rivo/tview"
|
|
"github.com/senorprogrammer/wtf/wtf"
|
|
)
|
|
|
|
type Widget struct {
|
|
wtf.BaseWidget
|
|
View *tview.TextView
|
|
}
|
|
|
|
func NewWidget() *Widget {
|
|
widget := Widget{
|
|
BaseWidget: wtf.BaseWidget{
|
|
Name: "Security",
|
|
RefreshedAt: time.Now(),
|
|
RefreshInt: 3600,
|
|
},
|
|
}
|
|
|
|
widget.addView()
|
|
go wtf.Refresh(&widget)
|
|
|
|
return &widget
|
|
}
|
|
|
|
/* -------------------- Exported Functions -------------------- */
|
|
|
|
func (widget *Widget) Refresh() {
|
|
data := Fetch()
|
|
|
|
widget.View.SetTitle(" 🤺 Security ")
|
|
widget.RefreshedAt = time.Now()
|
|
|
|
widget.View.Clear()
|
|
fmt.Fprintf(widget.View, "%s", widget.contentFrom(data))
|
|
}
|
|
|
|
/* -------------------- Unexported Functions -------------------- */
|
|
|
|
func (widget *Widget) addView() {
|
|
view := tview.NewTextView()
|
|
|
|
view.SetBorder(true)
|
|
view.SetBorderColor(tcell.ColorGray)
|
|
view.SetDynamicColors(true)
|
|
view.SetTitle(widget.Name)
|
|
|
|
widget.View = view
|
|
}
|
|
|
|
func (widget *Widget) contentFrom(data map[string]string) string {
|
|
str := "\n"
|
|
|
|
// Sort the map keys in alphabetical order
|
|
var keys []string
|
|
for key, _ := range data {
|
|
keys = append(keys, key)
|
|
}
|
|
sort.Strings(keys)
|
|
|
|
for _, key := range keys {
|
|
val := data[key]
|
|
str = str + fmt.Sprintf(" %16s: %s\n", key, val)
|
|
}
|
|
|
|
return str
|
|
}
|