diff --git a/_site/content/posts/modules/security.md b/_site/content/posts/modules/security.md index 1329e2d4..5da13a1f 100644 --- a/_site/content/posts/modules/security.md +++ b/_site/content/posts/modules/security.md @@ -5,7 +5,7 @@ draft: false --- Displays some general information about the state of the machine's wifi -connection, firewall, and DNS settings. +connection, firewall, DNS settings, and logged-in users. security screenshot @@ -29,6 +29,13 @@ connection, firewall, and DNS settings.
  • Which DNS resolvers (servers) the machine is configured to use
  • +#### Users + + + ## Source Code ```bash diff --git a/cmdrunner/widget.go b/cmdrunner/widget.go index 2c2b81a8..d9188a98 100644 --- a/cmdrunner/widget.go +++ b/cmdrunner/widget.go @@ -23,12 +23,14 @@ type Widget struct { func NewWidget() *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(" 🏃 Runner ", "cmdrunner", true), + TextWidget: wtf.NewTextWidget(" 🏃 Runner ", "cmdrunner", false), args: wtf.ToStrs(Config.UList("wtf.mods.cmdrunner.args")), cmd: Config.UString("wtf.mods.cmdrunner.cmd"), } + widget.View.SetWrap(true) + return &widget } diff --git a/docs/index.xml b/docs/index.xml index 9e938200..e1d77472 100644 --- a/docs/index.xml +++ b/docs/index.xml @@ -197,8 +197,8 @@ position Where in the grid this module’s widget will be displayed.Tue, 08 May 2018 20:33:28 -0700 http://wtfutil.com/posts/modules/security/ - Displays some general information about the state of the machine’s wifi connection, firewall, and DNS settings. -Wifi Network The name of the current network Whether or not the network uses encryption and if so, what flavour Firewall Whether or not the firewall is enabled Whether or not Stealth Mode is enabled DNS Which DNS resolvers (servers) the machine is configured to use Source Code wtf/security Required ENV Variables None. + Displays some general information about the state of the machine’s wifi connection, firewall, DNS settings, and logged-in users. +Wifi Network The name of the current network Whether or not the network uses encryption and if so, what flavour Firewall Whether or not the firewall is enabled Whether or not Stealth Mode is enabled DNS Which DNS resolvers (servers) the machine is configured to use Users Which users are logged into the machine. diff --git a/docs/posts/index.xml b/docs/posts/index.xml index 943358fc..002e5fa4 100644 --- a/docs/posts/index.xml +++ b/docs/posts/index.xml @@ -197,8 +197,8 @@ position Where in the grid this module’s widget will be displayed.Tue, 08 May 2018 20:33:28 -0700 http://wtfutil.com/posts/modules/security/ - Displays some general information about the state of the machine’s wifi connection, firewall, and DNS settings. -Wifi Network The name of the current network Whether or not the network uses encryption and if so, what flavour Firewall Whether or not the firewall is enabled Whether or not Stealth Mode is enabled DNS Which DNS resolvers (servers) the machine is configured to use Source Code wtf/security Required ENV Variables None. + Displays some general information about the state of the machine’s wifi connection, firewall, DNS settings, and logged-in users. +Wifi Network The name of the current network Whether or not the network uses encryption and if so, what flavour Firewall Whether or not the firewall is enabled Whether or not Stealth Mode is enabled DNS Which DNS resolvers (servers) the machine is configured to use Users Which users are logged into the machine. diff --git a/docs/posts/modules/security/index.html b/docs/posts/modules/security/index.html index 2d752d23..1d7a721b 100644 --- a/docs/posts/modules/security/index.html +++ b/docs/posts/modules/security/index.html @@ -108,7 +108,7 @@

    Displays some general information about the state of the machine’s wifi -connection, firewall, and DNS settings.

    +connection, firewall, DNS settings, and logged-in users.

    security screenshot

    @@ -132,6 +132,13 @@ connection, firewall, and DNS settings.

  • Which DNS resolvers (servers) the machine is configured to use
  • +

    Users

    + + +

    Source Code

    wtf/security

    Required ENV Variables

    diff --git a/security/security_data.go b/security/security_data.go index 1b1a3b48..1959b8f2 100644 --- a/security/security_data.go +++ b/security/security_data.go @@ -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() } diff --git a/security/users.go b/security/users.go new file mode 100644 index 00000000..47e9f4c1 --- /dev/null +++ b/security/users.go @@ -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 +} diff --git a/security/widget.go b/security/widget.go index c240557e..37653640 100644 --- a/security/widget.go +++ b/security/widget.go @@ -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 } diff --git a/security/wifi.go b/security/wifi.go index 390db42e..d84b808d 100644 --- a/security/wifi.go +++ b/security/wifi.go @@ -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 { diff --git a/wtf/utils.go b/wtf/utils.go index 5ec2dbed..4a1f05da 100644 --- a/wtf/utils.go +++ b/wtf/utils.go @@ -4,6 +4,7 @@ import ( "fmt" "io/ioutil" "os/exec" + "regexp" "strings" "time" @@ -51,6 +52,11 @@ func Exclude(strs []string, val string) bool { return true } +func FindMatch(pattern string, data string) [][]string { + r := regexp.MustCompile(pattern) + return r.FindAllStringSubmatch(data, -1) +} + func NameFromEmail(email string) string { parts := strings.Split(email, "@") return strings.Title(strings.Replace(parts[0], ".", " ", -1)) @@ -68,10 +74,9 @@ func NamesFromEmails(emails []string) []string { // OpenFile opens the file defined in `path` via the operating system func OpenFile(path string) { - confDir, _ := ConfigDir() - filePath := fmt.Sprintf("%s/%s", confDir, path) - + filePath, _ := ExpandHomeDir(path) cmd := exec.Command("open", filePath) + ExecuteCommand(cmd) }