mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
fixed platform-specific stuff.
Mostly fixed character encoding and stuff. Signed-off-by: Mike Lloyd <mike@reboot3times.org>
This commit is contained in:
13
security/dns_windows.go
Normal file
13
security/dns_windows.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package security
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
|
||||
"github.com/senorprogrammer/wtf/wtf"
|
||||
)
|
||||
|
||||
|
||||
func DnsServers() string {
|
||||
cmd := exec.Command("powershell.exe", "Get-DnsClientServerAddress | Select-Object –ExpandProperty ServerAddresses")
|
||||
return wtf.ExecuteCommand(cmd)
|
||||
}
|
||||
23
security/users_windows.go
Normal file
23
security/users_windows.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package security
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/senorprogrammer/wtf/wtf"
|
||||
)
|
||||
|
||||
func LoggedInUsers() []string {
|
||||
cmd := exec.Command("powershell.exe", "(query user) -replace '\\s{2,}', ','")
|
||||
users := wtf.ExecuteCommand(cmd)
|
||||
return cleanUsers(strings.Split(users, "\n")[1:])
|
||||
}
|
||||
|
||||
func cleanUsers(users []string) []string {
|
||||
cleaned := make([]string, 0)
|
||||
for _, user := range users {
|
||||
usr := strings.Split(user, ",")
|
||||
cleaned = append(cleaned, usr[0])
|
||||
}
|
||||
return cleaned
|
||||
}
|
||||
@@ -17,7 +17,7 @@ type Widget struct {
|
||||
|
||||
func NewWidget() *Widget {
|
||||
widget := Widget{
|
||||
TextWidget: wtf.NewTextWidget(" 🤺 Security ", "security", false),
|
||||
TextWidget: wtf.NewTextWidget(" Security ", "security", false),
|
||||
}
|
||||
|
||||
return &widget
|
||||
57
security/widget_windows.go
Normal file
57
security/widget_windows.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package security
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/olebedev/config"
|
||||
"github.com/senorprogrammer/wtf/wtf"
|
||||
)
|
||||
|
||||
// Config is a pointer to the global config object
|
||||
var Config *config.Config
|
||||
|
||||
type Widget struct {
|
||||
wtf.TextWidget
|
||||
}
|
||||
|
||||
func NewWidget() *Widget {
|
||||
widget := Widget{
|
||||
TextWidget: wtf.NewTextWidget(" Security ", "security", false),
|
||||
}
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
/* -------------------- Exported Functions -------------------- */
|
||||
|
||||
func (widget *Widget) Refresh() {
|
||||
if widget.Disabled() {
|
||||
return
|
||||
}
|
||||
|
||||
data := NewSecurityData()
|
||||
data.Fetch()
|
||||
|
||||
widget.UpdateRefreshedAt()
|
||||
widget.View.Clear()
|
||||
|
||||
fmt.Fprintf(widget.View, "%s", widget.contentFrom(data))
|
||||
}
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
||||
func (widget *Widget) contentFrom(data *SecurityData) string {
|
||||
str := " [red]WiFi[white]\n"
|
||||
str = str + fmt.Sprintf(" %8s: %s\n", "Network", data.WifiName)
|
||||
str = str + fmt.Sprintf(" %8s: %s\n", "Crypto", data.WifiEncryption)
|
||||
str = str + "\n"
|
||||
str = str + " [red]Firewall[white] [red]DNS[white]\n"
|
||||
str = str + fmt.Sprintf(" %8s: %4s %12s\n", "Enabled", data.FirewallEnabled, data.DnsAt(0))
|
||||
str = str + fmt.Sprintf(" %8s: %4s %12s\n", "Stealth", data.FirewallStealth, data.DnsAt(1))
|
||||
str = str + "\n"
|
||||
str = str + " [red]Users[white]\n"
|
||||
str = str + fmt.Sprintf(" %s", strings.Join(data.LoggedInUsers, ","))
|
||||
|
||||
return str
|
||||
}
|
||||
Reference in New Issue
Block a user