|
@@ -27,24 +27,23 @@ import (
|
|
|
CPUFreq: Refers to the CPU frequency in terms of gigahertz, e.g. 0.8GHz
|
|
|
*/
|
|
|
|
|
|
-const UNKNOWN_STRING = "??? "
|
|
|
-const QUERY_FREQUENCY_COMMAND = "sysctl hw.model | awk '{print $NF}'"
|
|
|
-const QUERY_CPUMODEL_COMMAND = "sysctl hw.model | awk '{for(i=1;++i<=NF-3;) printf $i\" \"; print $(NF-2)}'"
|
|
|
-const QUERY_CPUARCH_COMMAND = "sysctl hw.machine_arch | awk '{print $NF}'"
|
|
|
-const QUERY_CPUHARDWARE_COMMAND = "sysctl kern.hwpmc.cpuid | awk '{print $NF}'"
|
|
|
-const QUERY_NETINFO_COMMAND = "ifconfig -a"
|
|
|
-const QUERY_USBINFO_COMMAND = "usbconfig"
|
|
|
-const QUERY_MEMSIZE_COMMAND = "sysctl hw.physmem | awk '{print $NF}'"
|
|
|
+const unknown_string = "??? "
|
|
|
+const query_frequency_command = "sysctl hw.model | awk '{print $NF}'"
|
|
|
+const query_cpumodel_command = "sysctl hw.model | awk '{for(i=1;++i<=NF-3;) printf $i\" \"; print $(NF-2)}'"
|
|
|
+const query_cpuarch_command = "sysctl hw.machine_arch | awk '{print $NF}'"
|
|
|
+const query_cpuhardware_command = "sysctl kern.hwpmc.cpuid | awk '{print $NF}'"
|
|
|
+const query_netinfo_command = "ifconfig -a"
|
|
|
+const query_usbinfo_command = "usbconfig"
|
|
|
+const query_memsize_command = "sysctl hw.physmem | awk '{print $NF}'"
|
|
|
|
|
|
// GetCPUFreq() -> String
|
|
|
// Returns the CPU frequency in the terms of MHz
|
|
|
func GetCPUFreq() string {
|
|
|
- cmd := QUERY_FREQUENCY_COMMAND // Query CPUFreq w/ sysctl
|
|
|
- shell := exec.Command("bash", "-c", cmd) // Run command
|
|
|
- freqByteArr, err := shell.CombinedOutput() // Response from cmdline
|
|
|
- if err != nil { // If done w/ errors then
|
|
|
+ shell := exec.Command("bash", "-c", query_frequency_command) // Run command
|
|
|
+ freqByteArr, err := shell.CombinedOutput() // Response from cmdline
|
|
|
+ if err != nil { // If done w/ errors then
|
|
|
log.Println(err)
|
|
|
- return UNKNOWN_STRING
|
|
|
+ return unknown_string
|
|
|
}
|
|
|
|
|
|
freqStr := strings.ReplaceAll(string(freqByteArr), "GHz", "")
|
|
@@ -60,12 +59,11 @@ func GetCPUFreq() string {
|
|
|
// GetCPUModel -> String
|
|
|
// Returns the CPU model name string
|
|
|
func GetCPUModel() string {
|
|
|
- cmd := QUERY_CPUMODEL_COMMAND // Query CPUModel w/ sysctl
|
|
|
- shell := exec.Command("bash", "-c", cmd) // Run command
|
|
|
- modelStr, err := shell.CombinedOutput() // Response from cmdline
|
|
|
- if err != nil { // If done w/ errors then
|
|
|
+ shell := exec.Command("bash", "-c", query_cpumodel_command) // Run command
|
|
|
+ modelStr, err := shell.CombinedOutput() // Response from cmdline
|
|
|
+ if err != nil { // If done w/ errors then
|
|
|
log.Println(err)
|
|
|
- return UNKNOWN_STRING
|
|
|
+ return unknown_string
|
|
|
}
|
|
|
|
|
|
return string(modelStr)
|
|
@@ -74,12 +72,11 @@ func GetCPUModel() string {
|
|
|
// GetCPUHardware -> String
|
|
|
// Returns the CPU ID string
|
|
|
func GetCPUHardware() string {
|
|
|
- cmd := QUERY_CPUHARDWARE_COMMAND // Query CPUHW w/ sysctl
|
|
|
- shell := exec.Command("bash", "-c", cmd) // Run command
|
|
|
- hwStr, err := shell.CombinedOutput() // Response from cmdline
|
|
|
- if err != nil { // If done w/ errors then
|
|
|
+ shell := exec.Command("bash", "-c", query_cpuhardware_command) // Run command
|
|
|
+ hwStr, err := shell.CombinedOutput() // Response from cmdline
|
|
|
+ if err != nil { // If done w/ errors then
|
|
|
log.Println(err)
|
|
|
- return UNKNOWN_STRING
|
|
|
+ return unknown_string
|
|
|
}
|
|
|
|
|
|
return string(hwStr)
|
|
@@ -88,12 +85,11 @@ func GetCPUHardware() string {
|
|
|
// GetCPUArch -> String
|
|
|
// Returns the CPU architecture string
|
|
|
func GetCPUArch() string {
|
|
|
- cmd := QUERY_CPUARCH_COMMAND // Query CPUArch w/ sysctl
|
|
|
- shell := exec.Command("bash", "-c", cmd) // Run command
|
|
|
- archStr, err := shell.CombinedOutput() // Response from cmdline
|
|
|
- if err != nil { // If done w/ errors then
|
|
|
+ shell := exec.Command("bash", "-c", query_cpuarch_command) // Run command
|
|
|
+ archStr, err := shell.CombinedOutput() // Response from cmdline
|
|
|
+ if err != nil { // If done w/ errors then
|
|
|
log.Println(err)
|
|
|
- return UNKNOWN_STRING
|
|
|
+ return unknown_string
|
|
|
}
|
|
|
|
|
|
return string(archStr)
|
|
@@ -119,7 +115,7 @@ func GetCPUInfo(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
// Inherited code from sysinfo.go
|
|
|
func Ifconfig(w http.ResponseWriter, r *http.Request) {
|
|
|
- cmdin := QUERY_NETINFO_COMMAND
|
|
|
+ cmdin := query_netinfo_command
|
|
|
cmd := exec.Command("bash", "-c", cmdin)
|
|
|
networkInterfaces, err := cmd.CombinedOutput()
|
|
|
if err != nil {
|
|
@@ -192,7 +188,7 @@ func GetDriveStat(w http.ResponseWriter, r *http.Request) {
|
|
|
// Takes in http.ResponseWriter w and *http.Request r,
|
|
|
// Send TextResponse containing USB information extracted from shell in JSON
|
|
|
func GetUSB(w http.ResponseWriter, r *http.Request) {
|
|
|
- cmdin := QUERY_USBINFO_COMMAND
|
|
|
+ cmdin := query_usbinfo_command
|
|
|
cmd := exec.Command("bash", "-c", cmdin)
|
|
|
usbd, err := cmd.CombinedOutput()
|
|
|
if err != nil {
|
|
@@ -219,7 +215,7 @@ func GetUSB(w http.ResponseWriter, r *http.Request) {
|
|
|
// Send TextResponse containing physical memory size
|
|
|
// extracted from shell in JSON
|
|
|
func GetRamInfo(w http.ResponseWriter, r *http.Request) {
|
|
|
- cmd := exec.Command("bash", "-c", QUERY_MEMSIZE_COMMAND)
|
|
|
+ cmd := exec.Command("bash", "-c", query_memsize_command)
|
|
|
out, _ := cmd.CombinedOutput()
|
|
|
|
|
|
strOut := string(out)
|