mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Security module now displays logged-in users
This commit is contained in:
@@ -8,6 +8,7 @@ type SecurityData struct {
|
||||
Dns string
|
||||
FirewallEnabled string
|
||||
FirewallStealth string
|
||||
LoggedInUsers []string
|
||||
WifiEncryption string
|
||||
WifiName string
|
||||
}
|
||||
@@ -30,6 +31,7 @@ func (data *SecurityData) Fetch() {
|
||||
data.Dns = DnsServers()
|
||||
data.FirewallEnabled = FirewallState()
|
||||
data.FirewallStealth = FirewallStealthState()
|
||||
data.LoggedInUsers = LoggedInUsers()
|
||||
data.WifiName = WifiName()
|
||||
data.WifiEncryption = WifiEncryption()
|
||||
}
|
||||
|
||||
39
security/users.go
Normal file
39
security/users.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package security
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/senorprogrammer/wtf/wtf"
|
||||
)
|
||||
|
||||
// http://applehelpwriter.com/2017/05/21/how-to-reveal-hidden-users/
|
||||
|
||||
func LoggedInUsers() []string {
|
||||
cmd := exec.Command("dscl", []string{".", "-list", "/Users"}...)
|
||||
users := wtf.ExecuteCommand(cmd)
|
||||
|
||||
return cleanUsers(strings.Split(users, "\n"))
|
||||
}
|
||||
|
||||
func cleanUsers(users []string) []string {
|
||||
rejects := []string{"_", "root", "nobody", "daemon", "Guest"}
|
||||
cleaned := []string{}
|
||||
|
||||
for _, user := range users {
|
||||
clean := true
|
||||
|
||||
for _, reject := range rejects {
|
||||
if strings.HasPrefix(user, reject) {
|
||||
clean = false
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if clean && user != "" {
|
||||
cleaned = append(cleaned, user)
|
||||
}
|
||||
}
|
||||
|
||||
return cleaned
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package security
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/olebedev/config"
|
||||
"github.com/senorprogrammer/wtf/wtf"
|
||||
@@ -41,7 +42,6 @@ func (widget *Widget) Refresh() {
|
||||
/* -------------------- 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)
|
||||
@@ -49,6 +49,9 @@ func (widget *Widget) contentFrom(data *SecurityData) string {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -1,65 +1,32 @@
|
||||
package security
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
|
||||
"github.com/senorprogrammer/wtf/wtf"
|
||||
)
|
||||
|
||||
// https://github.com/yelinaung/wifi-name/blob/master/wifi-name.go
|
||||
const osxWifiCmd = "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport"
|
||||
const osxWifiArg = "-I"
|
||||
|
||||
/* -------------------- Exported Functions -------------------- */
|
||||
|
||||
func WifiEncryption() string {
|
||||
cmd := exec.Command(osxWifiCmd, "-I")
|
||||
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
var str string
|
||||
if b, err := ioutil.ReadAll(stdout); err == nil {
|
||||
str += (string(b) + "\n")
|
||||
}
|
||||
|
||||
name := findMatch(`s*auth: (.+)s*`, str)
|
||||
name := wtf.FindMatch(`s*auth: (.+)s*`, wifiInfo())
|
||||
return matchStr(name)
|
||||
}
|
||||
|
||||
func WifiName() string {
|
||||
cmd := exec.Command(osxWifiCmd, "-I")
|
||||
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
var str string
|
||||
if b, err := ioutil.ReadAll(stdout); err == nil {
|
||||
str += (string(b) + "\n")
|
||||
}
|
||||
|
||||
name := findMatch(`s*SSID: (.+)s*`, str)
|
||||
name := wtf.FindMatch(`s*SSID: (.+)s*`, wifiInfo())
|
||||
return matchStr(name)
|
||||
}
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
||||
func findMatch(pattern string, data string) [][]string {
|
||||
r := regexp.MustCompile(pattern)
|
||||
|
||||
name := r.FindAllStringSubmatch(data, -1)
|
||||
return name
|
||||
func wifiInfo() string {
|
||||
cmd := exec.Command(osxWifiCmd, osxWifiArg)
|
||||
return wtf.ExecuteCommand(cmd)
|
||||
}
|
||||
|
||||
func matchStr(data [][]string) string {
|
||||
|
||||
Reference in New Issue
Block a user