1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Move the utils.go file into the /utils directory

This commit is contained in:
Chris Cummer
2019-08-05 10:50:12 -07:00
parent 0bd2d176d8
commit 4e46fff145
57 changed files with 190 additions and 188 deletions

View File

@@ -5,7 +5,7 @@ import (
"runtime"
"strings"
"github.com/wtfutil/wtf/wtf"
"github.com/wtfutil/wtf/utils"
)
/* -------------------- Exported Functions -------------------- */
@@ -28,7 +28,7 @@ func DnsServers() []string {
func dnsLinux() []string {
// This may be very Ubuntu specific
cmd := exec.Command("nmcli", "device", "show")
out := wtf.ExecuteCommand(cmd)
out := utils.ExecuteCommand(cmd)
lines := strings.Split(out, "\n")
@@ -46,7 +46,7 @@ func dnsLinux() []string {
func dnsMacOS() []string {
cmdString := `scutil --dns | head -n 7 | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'`
cmd := exec.Command("sh", "-c", cmdString)
out := wtf.ExecuteCommand(cmd)
out := utils.ExecuteCommand(cmd)
lines := strings.Split(out, "\n")
@@ -61,5 +61,5 @@ func dnsWindows() []string {
cmd := exec.Command("powershell.exe", "-NoProfile", "Get-DnsClientServerAddress | Select-Object ExpandProperty ServerAddresses")
return []string{wtf.ExecuteCommand(cmd)}
return []string{utils.ExecuteCommand(cmd)}
}

View File

@@ -7,7 +7,7 @@ import (
"runtime"
"strings"
"github.com/wtfutil/wtf/wtf"
"github.com/wtfutil/wtf/utils"
)
const osxFirewallCmd = "/usr/libexec/ApplicationFirewall/socketfilterfw"
@@ -66,35 +66,35 @@ func firewallStateLinux() string { // might be very Ubuntu specific
func firewallStateMacOS() string {
cmd := exec.Command(osxFirewallCmd, "--getglobalstate")
str := wtf.ExecuteCommand(cmd)
str := utils.ExecuteCommand(cmd)
return statusLabel(str)
}
func firewallStateWindows() string {
// The raw way to do this in PS, not using netsh, nor registry, is the following:
// if (((Get-NetFirewallProfile | select name,enabled)
// | where { $_.Enabled -eq $True } | measure ).Count -eq 3)
// { Write-Host "OK" -ForegroundColor Green} else { Write-Host "OFF" -ForegroundColor Red }
// The raw way to do this in PS, not using netsh, nor registry, is the following:
// if (((Get-NetFirewallProfile | select name,enabled)
// | where { $_.Enabled -eq $True } | measure ).Count -eq 3)
// { Write-Host "OK" -ForegroundColor Green} else { Write-Host "OFF" -ForegroundColor Red }
cmd := exec.Command("powershell.exe", "-NoProfile",
"-Command", "& { ((Get-NetFirewallProfile | select name,enabled) | where { $_.Enabled -eq $True } | measure ).Count }")
cmd := exec.Command("powershell.exe", "-NoProfile",
"-Command", "& { ((Get-NetFirewallProfile | select name,enabled) | where { $_.Enabled -eq $True } | measure ).Count }")
fwStat := wtf.ExecuteCommand(cmd)
fwStat = strings.TrimSpace(fwStat) // Always sanitize PowerShell output: "3\r\n"
fwStat := utils.ExecuteCommand(cmd)
fwStat = strings.TrimSpace(fwStat) // Always sanitize PowerShell output: "3\r\n"
//fmt.Printf("%d %q\n", len(fwStat), fwStat)
switch fwStat {
case "3":
return "[green]Good[white] (3/3)"
case "2":
return "[orange]Poor[white] (2/3)"
case "1":
return "[yellow]Bad[white] (1/3)"
case "0":
return "[red]Disabled[white]"
default:
return "[white]N/A[white]"
case "3":
return "[green]Good[white] (3/3)"
case "2":
return "[orange]Poor[white] (2/3)"
case "1":
return "[yellow]Bad[white] (1/3)"
case "0":
return "[red]Disabled[white]"
default:
return "[white]N/A[white]"
}
}
@@ -107,7 +107,7 @@ func firewallStealthStateLinux() string {
func firewallStealthStateMacOS() string {
cmd := exec.Command(osxFirewallCmd, "--getstealthmode")
str := wtf.ExecuteCommand(cmd)
str := utils.ExecuteCommand(cmd)
return statusLabel(str)
}
@@ -116,7 +116,6 @@ func firewallStealthStateWindows() string {
return "[white]N/A[white]"
}
func statusLabel(str string) string {
label := "off"

View File

@@ -7,7 +7,7 @@ import (
"runtime"
"strings"
"github.com/wtfutil/wtf/wtf"
"github.com/wtfutil/wtf/utils"
)
/* -------------------- Exported Functions -------------------- */
@@ -51,7 +51,7 @@ func cleanUsers(users []string) []string {
func loggedInUsersLinux() []string {
cmd := exec.Command("who", "-us")
users := wtf.ExecuteCommand(cmd)
users := utils.ExecuteCommand(cmd)
cleaned := []string{}
@@ -77,24 +77,24 @@ func loggedInUsersLinux() []string {
func loggedInUsersMacOs() []string {
cmd := exec.Command("dscl", []string{".", "-list", "/Users"}...)
users := wtf.ExecuteCommand(cmd)
users := utils.ExecuteCommand(cmd)
return cleanUsers(strings.Split(users, "\n"))
}
func loggedInUsersWindows() []string {
// We can use either one:
// (Get-WMIObject -class Win32_ComputerSystem | select username).username
// [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
// The original was:
// cmd := exec.Command("powershell.exe", "(query user) -replace '\\s{2,}', ','")
// But that didn't work!
// We can use either one:
// (Get-WMIObject -class Win32_ComputerSystem | select username).username
// [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
// The original was:
// cmd := exec.Command("powershell.exe", "(query user) -replace '\\s{2,}', ','")
// But that didn't work!
// The real powershell command reads:
// powershell.exe -NoProfile -Command "& { [System.Security.Principal.WindowsIdentity]::GetCurrent().Name }"
// But we here have to write it as:
cmd := exec.Command("powershell.exe", "-NoProfile", "-Command", "& { [System.Security.Principal.WindowsIdentity]::GetCurrent().Name }")
// ToDo: Make list for multi-user systems
// But we here have to write it as:
cmd := exec.Command("powershell.exe", "-NoProfile", "-Command", "& { [System.Security.Principal.WindowsIdentity]::GetCurrent().Name }")
// ToDo: Make list for multi-user systems
users := wtf.ExecuteCommand(cmd)
return cleanUsers(strings.Split(users, "\n"))
users := utils.ExecuteCommand(cmd)
return cleanUsers(strings.Split(users, "\n"))
}

View File

@@ -5,7 +5,7 @@ import (
"runtime"
"strings"
"github.com/wtfutil/wtf/wtf"
"github.com/wtfutil/wtf/utils"
)
// https://github.com/yelinaung/wifi-name/blob/master/wifi-name.go
@@ -44,9 +44,9 @@ func WifiName() string {
func wifiEncryptionLinux() string {
cmd := exec.Command("nmcli", "-t", "-f", "in-use,security", "dev", "wifi")
out := wtf.ExecuteCommand(cmd)
out := utils.ExecuteCommand(cmd)
name := wtf.FindMatch(`\*:(.+)`, out)
name := utils.FindMatch(`\*:(.+)`, out)
if len(name) > 0 {
return name[0][1]
@@ -56,19 +56,19 @@ func wifiEncryptionLinux() string {
}
func wifiEncryptionMacOS() string {
name := wtf.FindMatch(`s*auth: (.+)s*`, wifiInfo())
name := utils.FindMatch(`s*auth: (.+)s*`, wifiInfo())
return matchStr(name)
}
func wifiInfo() string {
cmd := exec.Command(osxWifiCmd, osxWifiArg)
return wtf.ExecuteCommand(cmd)
return utils.ExecuteCommand(cmd)
}
func wifiNameLinux() string {
cmd := exec.Command("nmcli", "-t", "-f", "in-use,ssid", "dev", "wifi")
out := wtf.ExecuteCommand(cmd)
name := wtf.FindMatch(`\*:(.+)`, out)
out := utils.ExecuteCommand(cmd)
name := utils.FindMatch(`\*:(.+)`, out)
if len(name) > 0 {
return name[0][1]
}
@@ -76,7 +76,7 @@ func wifiNameLinux() string {
}
func wifiNameMacOS() string {
name := wtf.FindMatch(`s*SSID: (.+)s*`, wifiInfo())
name := utils.FindMatch(`s*SSID: (.+)s*`, wifiInfo())
return matchStr(name)
}