From 9b70236bbbc3545d7499c84be1b57a280708036a Mon Sep 17 00:00:00 2001 From: Sherod Taylor Date: Thu, 31 May 2018 18:46:52 +0100 Subject: [PATCH 001/310] 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 5035933f1570e7215be40d3c55e06c34bc50b845 Mon Sep 17 00:00:00 2001 From: Farhad Farahi Date: Fri, 1 Jun 2018 21:06:24 +0430 Subject: [PATCH 002/310] added ipinfo mod --- ipinfo/widget.go | 81 ++++++++++++++++++++++++++++++++++++++++++++++++ wtf.go | 3 ++ 2 files changed, 84 insertions(+) create mode 100644 ipinfo/widget.go diff --git a/ipinfo/widget.go b/ipinfo/widget.go new file mode 100644 index 00000000..b5739e7b --- /dev/null +++ b/ipinfo/widget.go @@ -0,0 +1,81 @@ +package ipinfo + +import ( + "encoding/json" + "fmt" + "github.com/olebedev/config" + "github.com/senorprogrammer/wtf/wtf" + "net/http" +) + +// Config is a pointer to the global config object +var Config *config.Config + +type Widget struct { + wtf.TextWidget + result string +} + +type ipinfo struct { + Ip string `json:"ip"` + Hostname string `json:"hostname"` + City string `json:"city"` + Region string `json:"region"` + Country string `json:"country"` + Coordinates string `json:"loc"` + PostalCode string `json:"postal"` + Organization string `json:"org"` +} + +func NewWidget() *Widget { + widget := Widget{ + TextWidget: wtf.NewTextWidget("Ipinfo", "ipinfo", false), + } + + widget.View.SetWrap(true) + + return &widget +} + +func (widget *Widget) Refresh() { + if widget.Disabled() { + return + } + + widget.UpdateRefreshedAt() + widget.ipinfo() + widget.View.Clear() + widget.View.SetTitle(fmt.Sprintf(" %s ", widget.Name)) + + fmt.Fprintf(widget.View, "%s", widget.result) +} + +//this method reads the config and calls ipinfo for ip information +func (widget *Widget) ipinfo() { + client := &http.Client{} + req, err := http.NewRequest("GET", "https://ipinfo.io/", nil) + if err != nil { + widget.result = fmt.Sprintf("%s", err.Error()) + return + } + req.Header.Set("User-Agent", "curl") + response, err := client.Do(req) + if err != nil { + widget.result = fmt.Sprintf("%s", err.Error()) + return + } + defer response.Body.Close() + if err != nil { + widget.result = fmt.Sprintf("%s", err.Error()) + return + } + var info ipinfo + err = json.NewDecoder(response.Body).Decode(&info) + if err != nil { + widget.result = fmt.Sprintf("%s", err.Error()) + return + } + widget.result = fmt.Sprintf("[red]IP Address:[white] %s\n[red]Hostname:[white] %v\n[red]City:[white] %s\n[red]Region:[white] %s\n[red]Country:[white] %s\n[red]Coordinates:[white] %v\n[red]Postal Code:[white] %s\n[red]Organization:[white] %v", + info.Ip, info.Hostname, info.City, info.Region, info.Country, info.Coordinates, info.PostalCode, info.Organization) + +} diff --git a/wtf.go b/wtf.go index 1cac8af9..19641196 100644 --- a/wtf.go +++ b/wtf.go @@ -27,6 +27,7 @@ import ( "github.com/senorprogrammer/wtf/todo" "github.com/senorprogrammer/wtf/weather" "github.com/senorprogrammer/wtf/wtf" + "github.com/senorprogrammer/wtf/ipinfo" ) /* -------------------- Functions -------------------- */ @@ -157,6 +158,7 @@ func makeWidgets(app *tview.Application, pages *tview.Pages) { gcal.Config = Config git.Config = Config github.Config = Config + ipinfo.Config = Config jira.Config = Config newrelic.Config = Config opsgenie.Config = Config @@ -176,6 +178,7 @@ func makeWidgets(app *tview.Application, pages *tview.Pages) { gcal.NewWidget(), git.NewWidget(app, pages), github.NewWidget(app, pages), + ipinfo.NewWidget(), jira.NewWidget(), newrelic.NewWidget(), opsgenie.NewWidget(), From 2b6e96ea27f89a9409c7d916bc6bd35ab298115b Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Fri, 1 Jun 2018 18:17:50 -0700 Subject: [PATCH 003/310] Add image --- docs/img/dude_wtf.png | Bin 0 -> 13867 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 docs/img/dude_wtf.png diff --git a/docs/img/dude_wtf.png b/docs/img/dude_wtf.png new file mode 100644 index 0000000000000000000000000000000000000000..7ede2f724e81ee9cf53f992819405c310a0e6f91 GIT binary patch literal 13867 zcmV+`Hq^<9P){007Ad0{{R3(jK%j0005$P)t-sMR~6O z|Nj600QbYL&nq07hFSyz1VeYM3k?gKn3X+lp&T+v5FILfdU~+0uRm{})h!PN=HU2Om1{zT+}xw*S@%jZerKu?UI0Yo|BE%OFtz50FHfHO)DxI z003Z5K}b(bsUsLHDy<}OSDr!hk-C09Dq42errz`DJ!OfWTTUAzPG2UpNorjU{6On z%&2?8r)U1&aoWCU>A{E!3mdtZVB`B z01hT10hCC9kslyhL>BIrh%8w~!GuI1RzPDQJDUud^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>iOogu0i=#;dHhx`eQ&LZBCRI38p_ z2zi&S-Z1vqBkvoyS2Sk)Bpx{ci>|r>itlm-2h&?%oxEE?*q`}ndi%IG_@L-fp?~Ap zvwk2 z1@z{EZt!|)2LzW)PWz-Pwqe9-4qER%m>yl-=&MftIz#sr>A}GUG*146A6#Ap9(6)J z1Vi&C3E<*^rl_u^0krLq>D9-5VTV_r?KiReio?@!-3)HwuOo6NLGtXj%(I58hA~^SUvHSD%AY$u^pL2&t19(v$s?U{0uvOkf-mVDy zQi~{p-HtheIsdT*hTkssu2;WjEM~m?9&thqcu^jTeF#5*AZP$9W5a&!c(yN1KZsMq zZ&%`bO?`N#i^SvXttWV#$_|3!pRRF%Pc33!{#hot)9o9j(eQX!_%24z&-S?d4#klHD9_?p+@y~w399PX~FxSV}etT)lzOH}I zs6~3HJIwa$GWaYmP5tRdDEQBajiYJGM@nCbD>mwHEp6G~^|!%JSGS&kSLJ0+q#ZB# tFN5%B+J=2l?>n49W2@#`J^E(G{{_+&fo7?|V0i!l002ovPDHLkV1g Date: Thu, 31 May 2018 13:35:47 -0500 Subject: [PATCH 004/310] 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 005/310] 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 006/310] 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 007/310] 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 008/310] 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 009/310] 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 010/310] 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 011/310] 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 @@