From 9b70236bbbc3545d7499c84be1b57a280708036a Mon Sep 17 00:00:00 2001 From: Sherod Taylor Date: Thu, 31 May 2018 18:46:52 +0100 Subject: [PATCH 01/19] add optional more advanced jql queries and working usernames --- jira/client.go | 28 ++++++++++++++++++++++++++-- jira/widget.go | 2 +- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/jira/client.go b/jira/client.go index 0e140694..b7903018 100644 --- a/jira/client.go +++ b/jira/client.go @@ -7,11 +7,31 @@ import ( "io" "io/ioutil" "net/http" + "net/url" "os" + "strings" ) -func IssuesFor(username string) (*SearchResult, error) { - url := fmt.Sprintf("/rest/api/2/search?jql=assignee=%s", username) +func IssuesFor(username string, project string, jql string) (*SearchResult, error) { + query := []string{} + + if project != "" { + query = append(query, buildJql("project", project)) + } + + if username != "" { + query = append(query, buildJql("assignee", username)) + } + + if jql != "" { + query = append(query, jql) + } + + v := url.Values{} + + v.Set("jql", strings.Join(query, " AND ")) + + url := fmt.Sprintf("/rest/api/2/search?%s", v.Encode()) resp, err := jiraRequest(url) if err != nil { @@ -24,6 +44,10 @@ func IssuesFor(username string) (*SearchResult, error) { return searchResult, nil } +func buildJql(key string, value string) string { + return fmt.Sprintf("%s = \"%s\"", key, value) +} + /* -------------------- Unexported Functions -------------------- */ func jiraRequest(path string) (*http.Response, error) { diff --git a/jira/widget.go b/jira/widget.go index 4c69e2da..ed3c11c3 100644 --- a/jira/widget.go +++ b/jira/widget.go @@ -29,7 +29,7 @@ func (widget *Widget) Refresh() { return } - searchResult, err := IssuesFor(Config.UString("wtf.mods.jira.username")) + searchResult, err := IssuesFor(Config.UString("wtf.mods.jira.username"), Config.UString("wtf.mods.jira.project", ""), Config.UString("wtf.mods.jira.jql", "")) widget.UpdateRefreshedAt() widget.View.Clear() From bc70c13ca45505d016d12b0ad0a8b3e450107c35 Mon Sep 17 00:00:00 2001 From: Lasantha Kularatne Date: Thu, 31 May 2018 13:35:47 -0500 Subject: [PATCH 02/19] NewRelic Module - Fixing out of bound error --- newrelic/widget.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/newrelic/widget.go b/newrelic/widget.go index 70466174..c4076af9 100644 --- a/newrelic/widget.go +++ b/newrelic/widget.go @@ -68,9 +68,14 @@ func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string { lineColor = "lightblue" } + var revLen = 8 + if revLen > len(deploy.Revision) { + revLen = len(deploy.Revision) + } + str = str + fmt.Sprintf( " [green]%s[%s] %s %-.16s[white]\n", - deploy.Revision[0:8], + deploy.Revision[0:revLen], lineColor, deploy.Timestamp.Format("Jan 02, 15:04 MST"), wtf.NameFromEmail(deploy.User), From 5d349523983f8e055635c7f9b755e845cf523a17 Mon Sep 17 00:00:00 2001 From: James Sapara Date: Thu, 31 May 2018 12:29:32 -0700 Subject: [PATCH 03/19] linux/ubuntu wraps for security --- Makefile | 2 +- security/dns.go | 43 ++++++++++++++++++++++++++++++----- security/firewall.go | 36 ++++++++++++++++++++++++++++-- security/security_data.go | 17 +++++--------- security/users.go | 40 +++++++++++++++++++++++++++++++-- security/wifi.go | 47 +++++++++++++++++++++++++++++++++++++-- 6 files changed, 161 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 60ef00cf..0828bf38 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ dependencies: go get -v ./... install: - which wtf | xargs rm + which wtf | xargs rm || true go install -ldflags="-X main.version=$(shell git describe --always --abbrev=6)_$(BRANCH) -X main.date=$(shell date +%FT%T%z)" which wtf diff --git a/security/dns.go b/security/dns.go index c57a202b..93eadf43 100644 --- a/security/dns.go +++ b/security/dns.go @@ -2,13 +2,46 @@ package security import ( "os/exec" + "runtime" + "strings" "github.com/senorprogrammer/wtf/wtf" ) -const dnsCmd = "networksetup" - -func DnsServers() string { - cmd := exec.Command(dnsCmd, "-getdnsservers", "Wi-Fi") - return wtf.ExecuteCommand(cmd) +func dnsLinux() []string { + // This may be very Ubuntu specific + cmd := exec.Command("nmcli", "device", "show") + out := wtf.ExecuteCommand(cmd) + lines := strings.Split(out, "\n") + dns := []string{} + for _, l := range lines { + if strings.HasPrefix(l, "IP4.DNS") { + parts := strings.Split(l, ":") + dns = append(dns, strings.TrimSpace(parts[1])) + } + } + return dns +} + +func dnsMacOS() []string { + cmd := exec.Command("networksetup", "-getdnsservers", "Wi-Fi") + out := wtf.ExecuteCommand(cmd) + records := strings.Split(out, "\n") + + if len(records) > 0 { + return records + } else { + return []string{} + } +} + +func DnsServers() []string { + switch runtime.GOOS { + case "linux": + return dnsLinux() + case "macos": + return dnsMacOS() + default: + return []string{runtime.GOOS} + } } diff --git a/security/firewall.go b/security/firewall.go index 5d5cb95a..5a7f4c75 100644 --- a/security/firewall.go +++ b/security/firewall.go @@ -2,6 +2,7 @@ package security import ( "os/exec" + "runtime" "strings" "github.com/senorprogrammer/wtf/wtf" @@ -11,20 +12,51 @@ const osxFirewallCmd = "/usr/libexec/ApplicationFirewall/socketfilterfw" /* -------------------- Exported Functions -------------------- */ -func FirewallState() string { +func firewallStateLinux() string { + return "[red]NA[white]" +} + +func firewallStateMacOS() string { cmd := exec.Command(osxFirewallCmd, "--getglobalstate") str := wtf.ExecuteCommand(cmd) return status(str) } -func FirewallStealthState() string { +func FirewallState() string { + switch runtime.GOOS { + case "linux": + return firewallStateLinux() + case "macos": + return firewallStateMacOS() + default: + return "" + } +} + +func firewallStealthStateLinux() string { + return "[red]NA[white]" +} + +func firewallStealthStateMacOS() string { cmd := exec.Command(osxFirewallCmd, "--getstealthmode") str := wtf.ExecuteCommand(cmd) return status(str) } +func FirewallStealthState() string { + q + switch runtime.GOOS { + case "linux": + return firewallStealthStateLinux() + case "macos": + return firewallStealthStateMacOS() + default: + return "" + } +} + /* -------------------- Unexported Functions -------------------- */ func status(str string) string { diff --git a/security/security_data.go b/security/security_data.go index 1959b8f2..3a339340 100644 --- a/security/security_data.go +++ b/security/security_data.go @@ -1,11 +1,7 @@ package security -import ( - "strings" -) - type SecurityData struct { - Dns string + Dns []string FirewallEnabled string FirewallStealth string LoggedInUsers []string @@ -17,14 +13,11 @@ func NewSecurityData() *SecurityData { return &SecurityData{} } -func (data *SecurityData) DnsAt(idx int) string { - records := strings.Split(data.Dns, "\n") - - if len(records) > 0 && len(records) > idx { - return records[idx] - } else { - return "" +func (data SecurityData) DnsAt(idx int) string { + if len(data.Dns) > idx { + return data.Dns[idx] } + return "" } func (data *SecurityData) Fetch() { diff --git a/security/users.go b/security/users.go index 47e9f4c1..82479950 100644 --- a/security/users.go +++ b/security/users.go @@ -2,20 +2,56 @@ package security import ( "os/exec" + "runtime" "strings" "github.com/senorprogrammer/wtf/wtf" ) -// http://applehelpwriter.com/2017/05/21/how-to-reveal-hidden-users/ +func loggedInUsersLinux() []string { + cmd := exec.Command("who", "-us") + users := wtf.ExecuteCommand(cmd) -func LoggedInUsers() []string { + cleaned := []string{} + for _, u := range strings.Split(users, "\n") { + clean := true + col := strings.Split(u, " ") + if len(col) > 0 { + for _, cleanedU := range cleaned { + if strings.Compare(cleanedU, col[0]) == 0 { + clean = false + } + } + if clean { + cleaned = append(cleaned, col[0]) + } + } + + } + + return cleaned +} + +func loggedInUsersMacOs() []string { cmd := exec.Command("dscl", []string{".", "-list", "/Users"}...) users := wtf.ExecuteCommand(cmd) return cleanUsers(strings.Split(users, "\n")) } +// http://applehelpwriter.com/2017/05/21/how-to-reveal-hidden-users/ + +func LoggedInUsers() []string { + switch runtime.GOOS { + case "linux": + return loggedInUsersLinux() + case "macos": + return loggedInUsersMacOs() + default: + return []string{} + } +} + func cleanUsers(users []string) []string { rejects := []string{"_", "root", "nobody", "daemon", "Guest"} cleaned := []string{} diff --git a/security/wifi.go b/security/wifi.go index d84b808d..335a44f8 100644 --- a/security/wifi.go +++ b/security/wifi.go @@ -2,6 +2,7 @@ package security import ( "os/exec" + "runtime" "github.com/senorprogrammer/wtf/wtf" ) @@ -12,16 +13,58 @@ const osxWifiArg = "-I" /* -------------------- Exported Functions -------------------- */ -func WifiEncryption() string { +func wifiEncryptionLinux() string { + cmd := exec.Command("nmcli", "-t", "-f", "active,security", "dev", "wifi") + out := wtf.ExecuteCommand(cmd) + name := wtf.FindMatch(`yes:(.+)`, out) + if len(name) > 0 { + return name[0][1] + } + return "" +} + +func wifkEncryptionMacOS() string { name := wtf.FindMatch(`s*auth: (.+)s*`, wifiInfo()) return matchStr(name) } -func WifiName() string { +func WifiEncryption() string { + switch runtime.GOOS { + case "linux": + return wifiEncryptionLinux() + case "macos": + return wifkEncryptionMacOS() + default: + return "" + } +} + +func wifiNameMacOS() string { name := wtf.FindMatch(`s*SSID: (.+)s*`, wifiInfo()) return matchStr(name) } +func wifiNameLinux() string { + cmd := exec.Command("nmcli", "-t", "-f", "active,ssid", "dev", "wifi") + out := wtf.ExecuteCommand(cmd) + name := wtf.FindMatch(`yes:(.+)`, out) + if len(name) > 0 { + return name[0][1] + } + return "" +} + +func WifiName() string { + switch runtime.GOOS { + case "linux": + return wifiNameLinux() + case "macos": + return wifiNameMacOS() + default: + return "" + } +} + /* -------------------- Unexported Functions -------------------- */ func wifiInfo() string { From 60837104ca2e6a2962561f3c897ff6558af38310 Mon Sep 17 00:00:00 2001 From: James Sapara Date: Thu, 31 May 2018 12:30:52 -0700 Subject: [PATCH 04/19] removed q mistype --- security/firewall.go | 1 - 1 file changed, 1 deletion(-) diff --git a/security/firewall.go b/security/firewall.go index 5a7f4c75..33e0bfc8 100644 --- a/security/firewall.go +++ b/security/firewall.go @@ -46,7 +46,6 @@ func firewallStealthStateMacOS() string { } func FirewallStealthState() string { - q switch runtime.GOOS { case "linux": return firewallStealthStateLinux() From 1a53c50da6d781501f7e40eb0e168c26b8683c3b Mon Sep 17 00:00:00 2001 From: James Sapara Date: Thu, 31 May 2018 12:40:00 -0700 Subject: [PATCH 05/19] golang platform is darwin not macos --- security/dns.go | 2 +- security/firewall.go | 4 ++-- security/users.go | 2 +- security/wifi.go | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/security/dns.go b/security/dns.go index 93eadf43..343ddd94 100644 --- a/security/dns.go +++ b/security/dns.go @@ -39,7 +39,7 @@ func DnsServers() []string { switch runtime.GOOS { case "linux": return dnsLinux() - case "macos": + case "darwin": return dnsMacOS() default: return []string{runtime.GOOS} diff --git a/security/firewall.go b/security/firewall.go index 33e0bfc8..507103cc 100644 --- a/security/firewall.go +++ b/security/firewall.go @@ -27,7 +27,7 @@ func FirewallState() string { switch runtime.GOOS { case "linux": return firewallStateLinux() - case "macos": + case "darwin": return firewallStateMacOS() default: return "" @@ -49,7 +49,7 @@ func FirewallStealthState() string { switch runtime.GOOS { case "linux": return firewallStealthStateLinux() - case "macos": + case "darwin": return firewallStealthStateMacOS() default: return "" diff --git a/security/users.go b/security/users.go index 82479950..75b3cc2c 100644 --- a/security/users.go +++ b/security/users.go @@ -45,7 +45,7 @@ func LoggedInUsers() []string { switch runtime.GOOS { case "linux": return loggedInUsersLinux() - case "macos": + case "darwin": return loggedInUsersMacOs() default: return []string{} diff --git a/security/wifi.go b/security/wifi.go index 335a44f8..47c31fae 100644 --- a/security/wifi.go +++ b/security/wifi.go @@ -32,7 +32,7 @@ func WifiEncryption() string { switch runtime.GOOS { case "linux": return wifiEncryptionLinux() - case "macos": + case "darwin": return wifkEncryptionMacOS() default: return "" @@ -58,7 +58,7 @@ func WifiName() string { switch runtime.GOOS { case "linux": return wifiNameLinux() - case "macos": + case "darwin": return wifiNameMacOS() default: return "" From ac5cd6a48f435fee662d58e2d5e11e50ffbe08e3 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Thu, 31 May 2018 13:57:33 -0700 Subject: [PATCH 06/19] Update readme with Go version warning --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7e5a84f0..5148713e 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,8 @@ displaying infrequently-needed, but very important, daily data. ### Installation from Source -*Note:* Requires `go v1.7` or later (because it uses the `context` -package). +*Note:* This has only been tested to build against Go 1.9.2. It won't +work with Go versions < 1.7, and only _may_ work on other versions. ```bash go get github.com/senorprogrammer/wtf From 1a6a25799ac3f36306c6ae268f1b5363dd6ee919 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Thu, 31 May 2018 17:45:47 -0700 Subject: [PATCH 07/19] Clean up the Linux security code a bit --- security/dns.go | 36 +++++++++++++--------- security/firewall.go | 44 +++++++++++++-------------- security/users.go | 71 ++++++++++++++++++++++++-------------------- security/widget.go | 6 ++-- security/wifi.go | 65 +++++++++++++++++++++------------------- 5 files changed, 120 insertions(+), 102 deletions(-) diff --git a/security/dns.go b/security/dns.go index 343ddd94..7360d801 100644 --- a/security/dns.go +++ b/security/dns.go @@ -8,12 +8,30 @@ import ( "github.com/senorprogrammer/wtf/wtf" ) +/* -------------------- Exported Functions -------------------- */ + +func DnsServers() []string { + switch runtime.GOOS { + case "linux": + return dnsLinux() + case "darwin": + return dnsMacOS() + default: + return []string{runtime.GOOS} + } +} + +/* -------------------- Unexported Functions -------------------- */ + func dnsLinux() []string { // This may be very Ubuntu specific cmd := exec.Command("nmcli", "device", "show") out := wtf.ExecuteCommand(cmd) + lines := strings.Split(out, "\n") + dns := []string{} + for _, l := range lines { if strings.HasPrefix(l, "IP4.DNS") { parts := strings.Split(l, ":") @@ -26,22 +44,12 @@ func dnsLinux() []string { func dnsMacOS() []string { cmd := exec.Command("networksetup", "-getdnsservers", "Wi-Fi") out := wtf.ExecuteCommand(cmd) - records := strings.Split(out, "\n") - if len(records) > 0 { - return records + lines := strings.Split(out, "\n") + + if len(lines) > 0 { + return lines } else { return []string{} } } - -func DnsServers() []string { - switch runtime.GOOS { - case "linux": - return dnsLinux() - case "darwin": - return dnsMacOS() - default: - return []string{runtime.GOOS} - } -} diff --git a/security/firewall.go b/security/firewall.go index 507103cc..5867e983 100644 --- a/security/firewall.go +++ b/security/firewall.go @@ -12,17 +12,6 @@ const osxFirewallCmd = "/usr/libexec/ApplicationFirewall/socketfilterfw" /* -------------------- Exported Functions -------------------- */ -func firewallStateLinux() string { - return "[red]NA[white]" -} - -func firewallStateMacOS() string { - cmd := exec.Command(osxFirewallCmd, "--getglobalstate") - str := wtf.ExecuteCommand(cmd) - - return status(str) -} - func FirewallState() string { switch runtime.GOOS { case "linux": @@ -34,17 +23,6 @@ func FirewallState() string { } } -func firewallStealthStateLinux() string { - return "[red]NA[white]" -} - -func firewallStealthStateMacOS() string { - cmd := exec.Command(osxFirewallCmd, "--getstealthmode") - str := wtf.ExecuteCommand(cmd) - - return status(str) -} - func FirewallStealthState() string { switch runtime.GOOS { case "linux": @@ -58,6 +36,28 @@ func FirewallStealthState() string { /* -------------------- Unexported Functions -------------------- */ +func firewallStateLinux() string { + return "[red]NA[white]" +} + +func firewallStateMacOS() string { + cmd := exec.Command(osxFirewallCmd, "--getglobalstate") + str := wtf.ExecuteCommand(cmd) + + return status(str) +} + +func firewallStealthStateLinux() string { + return "[red]NA[white]" +} + +func firewallStealthStateMacOS() string { + cmd := exec.Command(osxFirewallCmd, "--getstealthmode") + str := wtf.ExecuteCommand(cmd) + + return status(str) +} + func status(str string) string { icon := "[red]off[white]" diff --git a/security/users.go b/security/users.go index 75b3cc2c..9bcab534 100644 --- a/security/users.go +++ b/security/users.go @@ -1,5 +1,7 @@ package security +// http://applehelpwriter.com/2017/05/21/how-to-reveal-hidden-users/ + import ( "os/exec" "runtime" @@ -8,38 +10,7 @@ import ( "github.com/senorprogrammer/wtf/wtf" ) -func loggedInUsersLinux() []string { - cmd := exec.Command("who", "-us") - users := wtf.ExecuteCommand(cmd) - - cleaned := []string{} - for _, u := range strings.Split(users, "\n") { - clean := true - col := strings.Split(u, " ") - if len(col) > 0 { - for _, cleanedU := range cleaned { - if strings.Compare(cleanedU, col[0]) == 0 { - clean = false - } - } - if clean { - cleaned = append(cleaned, col[0]) - } - } - - } - - return cleaned -} - -func loggedInUsersMacOs() []string { - cmd := exec.Command("dscl", []string{".", "-list", "/Users"}...) - users := wtf.ExecuteCommand(cmd) - - return cleanUsers(strings.Split(users, "\n")) -} - -// http://applehelpwriter.com/2017/05/21/how-to-reveal-hidden-users/ +/* -------------------- Exported Functions -------------------- */ func LoggedInUsers() []string { switch runtime.GOOS { @@ -52,6 +23,8 @@ func LoggedInUsers() []string { } } +/* -------------------- Unexported Functions -------------------- */ + func cleanUsers(users []string) []string { rejects := []string{"_", "root", "nobody", "daemon", "Guest"} cleaned := []string{} @@ -73,3 +46,37 @@ func cleanUsers(users []string) []string { return cleaned } + +func loggedInUsersLinux() []string { + cmd := exec.Command("who", "-us") + users := wtf.ExecuteCommand(cmd) + + cleaned := []string{} + + for _, user := range strings.Split(users, "\n") { + clean := true + col := strings.Split(user, " ") + + if len(col) > 0 { + for _, cleanedU := range cleaned { + if strings.Compare(cleanedU, col[0]) == 0 { + clean = false + } + } + + if clean { + cleaned = append(cleaned, col[0]) + } + } + + } + + return cleaned +} + +func loggedInUsersMacOs() []string { + cmd := exec.Command("dscl", []string{".", "-list", "/Users"}...) + users := wtf.ExecuteCommand(cmd) + + return cleanUsers(strings.Split(users, "\n")) +} diff --git a/security/widget.go b/security/widget.go index 37653640..7ad2d5bb 100644 --- a/security/widget.go +++ b/security/widget.go @@ -46,9 +46,9 @@ func (widget *Widget) contentFrom(data *SecurityData) string { 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 + " [red]Firewall[white] [red]DNS[white]\n" + str = str + fmt.Sprintf(" %8s: %4s %-16s\n", "Enabled", data.FirewallEnabled, data.DnsAt(0)) + str = str + fmt.Sprintf(" %8s: %4s %-16s\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, ", ")) diff --git a/security/wifi.go b/security/wifi.go index 47c31fae..30b75767 100644 --- a/security/wifi.go +++ b/security/wifi.go @@ -13,47 +13,17 @@ const osxWifiArg = "-I" /* -------------------- Exported Functions -------------------- */ -func wifiEncryptionLinux() string { - cmd := exec.Command("nmcli", "-t", "-f", "active,security", "dev", "wifi") - out := wtf.ExecuteCommand(cmd) - name := wtf.FindMatch(`yes:(.+)`, out) - if len(name) > 0 { - return name[0][1] - } - return "" -} - -func wifkEncryptionMacOS() string { - name := wtf.FindMatch(`s*auth: (.+)s*`, wifiInfo()) - return matchStr(name) -} - func WifiEncryption() string { switch runtime.GOOS { case "linux": return wifiEncryptionLinux() case "darwin": - return wifkEncryptionMacOS() + return wifiEncryptionMacOS() default: return "" } } -func wifiNameMacOS() string { - name := wtf.FindMatch(`s*SSID: (.+)s*`, wifiInfo()) - return matchStr(name) -} - -func wifiNameLinux() string { - cmd := exec.Command("nmcli", "-t", "-f", "active,ssid", "dev", "wifi") - out := wtf.ExecuteCommand(cmd) - name := wtf.FindMatch(`yes:(.+)`, out) - if len(name) > 0 { - return name[0][1] - } - return "" -} - func WifiName() string { switch runtime.GOOS { case "linux": @@ -67,11 +37,44 @@ func WifiName() string { /* -------------------- Unexported Functions -------------------- */ +func wifiEncryptionLinux() string { + cmd := exec.Command("nmcli", "-t", "-f", "active,security", "dev", "wifi") + out := wtf.ExecuteCommand(cmd) + + name := wtf.FindMatch(`yes:(.+)`, out) + + if len(name) > 0 { + return name[0][1] + } + + return "" +} + +func wifiEncryptionMacOS() string { + name := wtf.FindMatch(`s*auth: (.+)s*`, wifiInfo()) + return matchStr(name) +} + func wifiInfo() string { cmd := exec.Command(osxWifiCmd, osxWifiArg) return wtf.ExecuteCommand(cmd) } +func wifiNameLinux() string { + cmd := exec.Command("nmcli", "-t", "-f", "active,ssid", "dev", "wifi") + out := wtf.ExecuteCommand(cmd) + name := wtf.FindMatch(`yes:(.+)`, out) + if len(name) > 0 { + return name[0][1] + } + return "" +} + +func wifiNameMacOS() string { + name := wtf.FindMatch(`s*SSID: (.+)s*`, wifiInfo()) + return matchStr(name) +} + func matchStr(data [][]string) string { if len(data) <= 1 { return "" From 70b56c314ba5958047a323a4b0c0fe4a337ea5fb Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Thu, 31 May 2018 18:01:11 -0700 Subject: [PATCH 08/19] Close #90. Firewall 'off' values are properly formatted --- security/firewall.go | 12 ++++++------ security/widget.go | 17 ++++++++++++++--- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/security/firewall.go b/security/firewall.go index 5867e983..6323b5e1 100644 --- a/security/firewall.go +++ b/security/firewall.go @@ -44,7 +44,7 @@ func firewallStateMacOS() string { cmd := exec.Command(osxFirewallCmd, "--getglobalstate") str := wtf.ExecuteCommand(cmd) - return status(str) + return statusLabel(str) } func firewallStealthStateLinux() string { @@ -55,15 +55,15 @@ func firewallStealthStateMacOS() string { cmd := exec.Command(osxFirewallCmd, "--getstealthmode") str := wtf.ExecuteCommand(cmd) - return status(str) + return statusLabel(str) } -func status(str string) string { - icon := "[red]off[white]" +func statusLabel(str string) string { + label := "off" if strings.Contains(str, "enabled") { - icon = "[green]on[white]" + label = "on" } - return icon + return label } diff --git a/security/widget.go b/security/widget.go index 7ad2d5bb..61bab3b2 100644 --- a/security/widget.go +++ b/security/widget.go @@ -46,12 +46,23 @@ func (widget *Widget) contentFrom(data *SecurityData) string { 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 %-16s\n", "Enabled", data.FirewallEnabled, data.DnsAt(0)) - str = str + fmt.Sprintf(" %8s: %4s %-16s\n", "Stealth", data.FirewallStealth, data.DnsAt(1)) + str = str + " [red]Firewall[white] [red]DNS[white]\n" + str = str + fmt.Sprintf(" %8s: [%s]%-3s[white] %-16s\n", "Enabled", widget.labelColor(data.FirewallEnabled), data.FirewallEnabled, data.DnsAt(0)) + str = str + fmt.Sprintf(" %8s: [%s]%-3s[white] %-16s\n", "Stealth", widget.labelColor(data.FirewallStealth), 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 } + +func (widget *Widget) labelColor(label string) string { + switch label { + case "on": + return "green" + case "off": + return "red" + default: + return "white" + } +} From f86179b74ef7fd7f02d3542da326060252238d11 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Thu, 31 May 2018 21:49:10 -0700 Subject: [PATCH 09/19] Close #91. Site sidebar is now scrollable with main content. --- _site/themes/hyde-hyde/layouts/partials/sidebar.html | 2 +- _site/themes/hyde-hyde/static/css/custom.css | 11 +++++++---- _site/themes/hyde-hyde/static/css/hyde.css | 10 ++++++---- docs/404.html | 2 +- docs/categories/index.html | 2 +- docs/css/custom.css | 11 +++++++---- docs/css/hyde.css | 10 ++++++---- docs/index.html | 2 +- docs/posts/configuration/attributes/index.html | 2 +- docs/posts/configuration/index.html | 2 +- docs/posts/configuration/iterm2/index.html | 2 +- docs/posts/glossary/index.html | 2 +- docs/posts/index.html | 2 +- docs/posts/installation/index.html | 2 +- docs/posts/modules/bamboohr/index.html | 2 +- docs/posts/modules/clocks/index.html | 2 +- docs/posts/modules/cmdrunner/index.html | 2 +- docs/posts/modules/gcal/index.html | 2 +- docs/posts/modules/git/index.html | 2 +- docs/posts/modules/github/index.html | 2 +- docs/posts/modules/index.html | 2 +- docs/posts/modules/jira/index.html | 2 +- docs/posts/modules/newrelic/index.html | 2 +- docs/posts/modules/opsgenie/index.html | 2 +- docs/posts/modules/power/index.html | 2 +- docs/posts/modules/security/index.html | 2 +- docs/posts/modules/textfile/index.html | 2 +- docs/posts/modules/todo/index.html | 2 +- docs/posts/modules/weather/index.html | 2 +- docs/posts/overview/index.html | 2 +- docs/tags/index.html | 2 +- 31 files changed, 53 insertions(+), 43 deletions(-) diff --git a/_site/themes/hyde-hyde/layouts/partials/sidebar.html b/_site/themes/hyde-hyde/layouts/partials/sidebar.html index 7922fbc7..b3c4f515 100644 --- a/_site/themes/hyde-hyde/layouts/partials/sidebar.html +++ b/_site/themes/hyde-hyde/layouts/partials/sidebar.html @@ -1,5 +1,5 @@