From 9b70236bbbc3545d7499c84be1b57a280708036a Mon Sep 17 00:00:00 2001
From: Sherod Taylor
Date: Thu, 31 May 2018 18:46:52 +0100
Subject: [PATCH 001/127] 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 2109157edcff66bbab4ab467e6fcd9c98dff304f Mon Sep 17 00:00:00 2001
From: James Sapara
Date: Thu, 31 May 2018 12:29:32 -0700
Subject: [PATCH 002/127] 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 2e126c3d239f935ee930d5e49c5b10b2ab5247ea Mon Sep 17 00:00:00 2001
From: James Sapara
Date: Thu, 31 May 2018 12:30:52 -0700
Subject: [PATCH 003/127] 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 9adc0ea98d840e24ccee4d4e9fb6c27fd97ed475 Mon Sep 17 00:00:00 2001
From: James Sapara
Date: Thu, 31 May 2018 12:40:00 -0700
Subject: [PATCH 004/127] 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 1dae2456cc668566e3705e786c1d16afaae1f1a6 Mon Sep 17 00:00:00 2001
From: Chris Cummer
Date: Thu, 31 May 2018 08:48:10 -0700
Subject: [PATCH 005/127] Close #84. Add wtf.colors.background config option
---
_sample_configs/complex_config.yml | 6 ++++++
_sample_configs/simple_config.yml | 1 +
_site/content/posts/configuration/attributes.md | 8 ++++++++
docs/index.xml | 2 +-
docs/posts/configuration/attributes/index.html | 8 ++++++++
docs/posts/index.xml | 2 +-
todo/display.go | 2 +-
wtf.go | 2 ++
wtf/text_widget.go | 1 +
9 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/_sample_configs/complex_config.yml b/_sample_configs/complex_config.yml
index 8f443238..c21bdb72 100644
--- a/_sample_configs/complex_config.yml
+++ b/_sample_configs/complex_config.yml
@@ -1,4 +1,10 @@
wtf:
+ colors:
+ background: gray
+ border:
+ focusable: darkslateblue
+ focused: orange
+ normal: gray
grid:
# How _wide_ the columns are, in terminal characters. In this case we have
# five columns, each of which are 37 characters wide
diff --git a/_sample_configs/simple_config.yml b/_sample_configs/simple_config.yml
index f0fe3be9..3d08666d 100644
--- a/_sample_configs/simple_config.yml
+++ b/_sample_configs/simple_config.yml
@@ -1,5 +1,6 @@
wtf:
colors:
+ background: gray
border:
focusable: darkslateblue
focused: orange
diff --git a/_site/content/posts/configuration/attributes.md b/_site/content/posts/configuration/attributes.md
index 1228a2a3..d709a8fb 100644
--- a/_site/content/posts/configuration/attributes.md
+++ b/_site/content/posts/configuration/attributes.md
@@ -10,6 +10,7 @@ See this
+The color to draw the background of the app in. Use this to match your
+terminal colors. May be over-written by individual module
+configurations.
+Values: Any X11
+color name.
+
`colors.border.focusable`
The color in which to draw the border of widgets that can accept
keyboard focus.
diff --git a/docs/index.xml b/docs/index.xml
index aa614d56..22a96bce 100644
--- a/docs/index.xml
+++ b/docs/index.xml
@@ -82,7 +82,7 @@ cmd The terminal command to be run, withouth the arguments. Ie: ping, whoami, cu
https://wtfutil.com/posts/configuration/attributes/
The following top-level attributes are configurable in config.yml. See this example config file for more details.
-wtf:colors:border:Focusable:"darkslateblue"focused:"orange"normal:"gray"grid:# How _wide_ the columns are, in terminal characters. In this case we have# six columns, each of which are 35 characters widecolumns:[35,35,35,35,35,35]# How _high_ the rows are, in terminal lines. In this case we have five rows# that support ten line of text, one of three lines, and one of fourrows:[10,10,10,10,10,3,4]# The app redraws itself once a secondrefreshInterval:1 Attributes colors.
+wtf:colors:background:"red"border:Focusable:"darkslateblue"focused:"orange"normal:"gray"grid:# How _wide_ the columns are, in terminal characters. In this case we have# six columns, each of which are 35 characters widecolumns:[35,35,35,35,35,35]# How _high_ the rows are, in terminal lines. In this case we have five rows# that support ten line of text, one of three lines, and one of fourrows:[10,10,10,10,10,3,4]# The app redraws itself once a secondrefreshInterval:1 Attributes colors.
-
diff --git a/docs/posts/configuration/attributes/index.html b/docs/posts/configuration/attributes/index.html
index 33d24908..e06cedcc 100644
--- a/docs/posts/configuration/attributes/index.html
+++ b/docs/posts/configuration/attributes/index.html
@@ -113,6 +113,7 @@
See this example config file for more details.
wtf:
colors:
+ background: "red"
border:
Focusable: "darkslateblue"
focused: "orange"
@@ -129,6 +130,13 @@ See this refreshInterval: 1
Attributes
+colors.background
+The color to draw the background of the app in. Use this to match your
+terminal colors. May be over-written by individual module
+configurations.
+Values: Any X11
+color name.
+
colors.border.focusable
The color in which to draw the border of widgets that can accept
keyboard focus.
diff --git a/docs/posts/index.xml b/docs/posts/index.xml
index 1be94e36..b867dd86 100644
--- a/docs/posts/index.xml
+++ b/docs/posts/index.xml
@@ -82,7 +82,7 @@ cmd The terminal command to be run, withouth the arguments. Ie: ping, whoami, cu
https://wtfutil.com/posts/configuration/attributes/
The following top-level attributes are configurable in config.yml. See this example config file for more details.
-wtf:colors:border:Focusable:"darkslateblue"focused:"orange"normal:"gray"grid:# How _wide_ the columns are, in terminal characters. In this case we have# six columns, each of which are 35 characters widecolumns:[35,35,35,35,35,35]# How _high_ the rows are, in terminal lines. In this case we have five rows# that support ten line of text, one of three lines, and one of fourrows:[10,10,10,10,10,3,4]# The app redraws itself once a secondrefreshInterval:1 Attributes colors.
+wtf:colors:background:"red"border:Focusable:"darkslateblue"focused:"orange"normal:"gray"grid:# How _wide_ the columns are, in terminal characters. In this case we have# six columns, each of which are 35 characters widecolumns:[35,35,35,35,35,35]# How _high_ the rows are, in terminal lines. In this case we have five rows# that support ten line of text, one of three lines, and one of fourrows:[10,10,10,10,10,3,4]# The app redraws itself once a secondrefreshInterval:1 Attributes colors.
-
diff --git a/todo/display.go b/todo/display.go
index f66f578c..98f3eb72 100644
--- a/todo/display.go
+++ b/todo/display.go
@@ -33,7 +33,7 @@ func (widget *Widget) display() {
}
func (widget *Widget) formattedItemLine(item *Item, selectedItem *Item, maxLen int) string {
- foreColor, backColor := "white", "black"
+ foreColor, backColor := "white", Config.UString("wtf.colors.background", "black")
if item.Checked {
foreColor = Config.UString("wtf.mods.todo.colors.checked", "white")
diff --git a/wtf.go b/wtf.go
index 63819b53..1cac8af9 100644
--- a/wtf.go
+++ b/wtf.go
@@ -225,6 +225,8 @@ func main() {
pages.AddPage("grid", grid, true, true)
app.SetInputCapture(keyboardIntercept)
+ grid.SetBackgroundColor(wtf.ColorFor(Config.UString("wtf.colors.background", "black")))
+
// Loop in a routine to redraw the screen
go redrawApp(app)
go watchForConfigChanges(app, cmdFlags.Config, grid, pages)
diff --git a/wtf/text_widget.go b/wtf/text_widget.go
index 6acb1572..17342f0c 100644
--- a/wtf/text_widget.go
+++ b/wtf/text_widget.go
@@ -78,6 +78,7 @@ func (widget *TextWidget) TextView() *tview.TextView {
func (widget *TextWidget) addView() {
view := tview.NewTextView()
+ view.SetBackgroundColor(ColorFor(Config.UString("wtf.colors.background", "black")))
view.SetBorder(true)
view.SetBorderColor(ColorFor(widget.BorderColor()))
view.SetDynamicColors(true)
From 0a1b1376be80bb4df563754b72f6bc04b5c21dc4 Mon Sep 17 00:00:00 2001
From: Lasantha Kularatne
Date: Thu, 31 May 2018 13:35:47 -0500
Subject: [PATCH 006/127] 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 f1548bb10fe4bf9a597010fffd385ba82db2c5a5 Mon Sep 17 00:00:00 2001
From: Chris Cummer
Date: Thu, 31 May 2018 13:57:33 -0700
Subject: [PATCH 007/127] 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 9a532a4660939603104803601842a66e68ec44f6 Mon Sep 17 00:00:00 2001
From: Chris Cummer
Date: Thu, 31 May 2018 17:45:47 -0700
Subject: [PATCH 008/127] 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 bf4ab1056f8f50dd8269a2b639ed155c210e83b8 Mon Sep 17 00:00:00 2001
From: Chris Cummer
Date: Thu, 31 May 2018 18:01:11 -0700
Subject: [PATCH 009/127] 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 fe67bedc86db8c01c704f0bf142dba6c7ecf6a78 Mon Sep 17 00:00:00 2001
From: Chris Cummer
Date: Thu, 31 May 2018 21:49:10 -0700
Subject: [PATCH 010/127] 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 @@