diff --git a/.gitignore b/.gitignore index be70aab..7af1ea4 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ gohip command.log .idea *.iml +pkg diff --git a/go.mod b/go.mod index def7a7e..f842976 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,10 @@ module github.com/bechampion/gohip go 1.22.3 require ( - github.com/bechampion/gohip/osdata v0.0.0-20240615162838-24fd4fe6ae1c - github.com/bechampion/gohip/others v0.0.0-20240615163101-e647f8629345 - github.com/bechampion/gohip/systemd v0.0.0-20240615162649-e52f38b1aa94 - github.com/bechampion/gohip/types v0.0.0-20240615162838-24fd4fe6ae1c + gohip/osdata v0.0.0-00010101000000-000000000000 + gohip/others v0.0.0-00010101000000-000000000000 + gohip/systemd v0.0.0-00010101000000-000000000000 + gohip/types v0.0.0-00010101000000-000000000000 ) require ( @@ -20,3 +20,11 @@ require ( github.com/yusufpapurcu/wmi v1.2.4 // indirect golang.org/x/sys v0.19.0 // indirect ) + +replace gohip/types => ./types + +replace gohip/osdata => ./osdata + +replace gohip/others => ./others + +replace gohip/systemd => ./systemd diff --git a/go.sum b/go.sum index 44c0a67..1482767 100644 --- a/go.sum +++ b/go.sum @@ -1,11 +1,3 @@ -github.com/bechampion/gohip/osdata v0.0.0-20240615162838-24fd4fe6ae1c h1:o3vkZcBgKR8fEJtc9DX+7aUEGUAC8VC+WcBVbEV+qM4= -github.com/bechampion/gohip/osdata v0.0.0-20240615162838-24fd4fe6ae1c/go.mod h1:6dodTTH25bYxK/QqG4UkD5LTE8m/keZXLtMI/NAQYUE= -github.com/bechampion/gohip/others v0.0.0-20240615163101-e647f8629345 h1:kBcLtdQvi1rjHVuG5YUf1rAvwiUXg/EaCN/d3yhISWM= -github.com/bechampion/gohip/others v0.0.0-20240615163101-e647f8629345/go.mod h1:uicBZczvyva96qCHkjW2JRq3OxFus4T13OaTY+rzNnc= -github.com/bechampion/gohip/systemd v0.0.0-20240615162649-e52f38b1aa94 h1:cvTYKVvSTcRNH70EAxl/wL3mOzilcfkzaXZ6WzE1LpU= -github.com/bechampion/gohip/systemd v0.0.0-20240615162649-e52f38b1aa94/go.mod h1:f8KC+DIU838ggN5cCO4yCgcF54nQ0Rd7bPFx8UKS0ng= -github.com/bechampion/gohip/types v0.0.0-20240615162838-24fd4fe6ae1c h1:QTnpKqhL0/w393NPPO+f349ng5cIjCdEKHoy9SoiVJU= -github.com/bechampion/gohip/types v0.0.0-20240615162838-24fd4fe6ae1c/go.mod h1:53Die0OQJzRseQ5d54hf/bP8H6QhknWgg2XbZsiX55I= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/main.go b/main.go index 6818d73..f49f29d 100644 --- a/main.go +++ b/main.go @@ -4,10 +4,10 @@ import ( "encoding/xml" "flag" "fmt" - osdata "github.com/bechampion/gohip/osdata" - others "github.com/bechampion/gohip/others" - systemd "github.com/bechampion/gohip/systemd" - ctypes "github.com/bechampion/gohip/types" + osdata "gohip/osdata" + others "gohip/others" + systemd "gohip/systemd" + ctypes "gohip/types" "log" "net/url" "os" @@ -29,7 +29,6 @@ func logCommandAndArgs() { func main() { logCommandAndArgs() - systemd.FindClamdProcess() cookie := flag.String("cookie", "", "") _ = flag.String("client-os", "", "") clientip := flag.String("client-ip", "", "") diff --git a/osdata/go.mod b/osdata/go.mod index 4fb327c..3551a0e 100644 --- a/osdata/go.mod +++ b/osdata/go.mod @@ -1,9 +1,9 @@ -module github.com/bechampion/gohip/osdata +module gohip/osdata go 1.22.3 require ( - github.com/bechampion/gohip/types v0.0.0-20240615162649-e52f38b1aa94 + gohip/types v0.0.0-00010101000000-000000000000 github.com/shirou/gopsutil/v3 v3.24.4 ) @@ -17,3 +17,5 @@ require ( github.com/yusufpapurcu/wmi v1.2.4 // indirect golang.org/x/sys v0.19.0 // indirect ) + +replace gohip/types => ../types diff --git a/osdata/go.sum b/osdata/go.sum index cce6edd..1482767 100644 --- a/osdata/go.sum +++ b/osdata/go.sum @@ -1,5 +1,3 @@ -github.com/bechampion/gohip/types v0.0.0-20240615162649-e52f38b1aa94 h1:1LYyPBeCru47r5VwQnKNRpMcZlKzrqD8E/fStkc5dr8= -github.com/bechampion/gohip/types v0.0.0-20240615162649-e52f38b1aa94/go.mod h1:53Die0OQJzRseQ5d54hf/bP8H6QhknWgg2XbZsiX55I= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/osdata/main.go b/osdata/main.go index 784ccdc..da75cc5 100644 --- a/osdata/main.go +++ b/osdata/main.go @@ -3,72 +3,71 @@ package osdata import ( "encoding/json" "fmt" + "github.com/shirou/gopsutil/v3/host" + ctypes "gohip/types" "os" "os/exec" - - "github.com/bechampion/gohip/types" - ctypes "github.com/bechampion/gohip/types" - "github.com/shirou/gopsutil/v3/host" ) type MainInterface struct { - Dst string `json:"dst"` - Gateway string `json:"gateway"` - Dev string `json:"dev"` - PrefSrc string `json:"prefsrc"` - Flags []string `json:"flags"` - UID int `json:"uid"` - Cache []string `json:"cache"` + Dst string `json:"dst"` + Gateway string `json:"gateway"` + Dev string `json:"dev"` + PrefSrc string `json:"prefsrc"` + Flags []string `json:"flags"` + UID int `json:"uid"` + Cache []string `json:"cache"` } type MacAddress struct { - Address string `json:"address"` + Address string `json:"address"` } + func GetMac(dev string) (string, error) { - cmd := exec.Command("ip", "-json", "link", "show", dev) - output, err := cmd.Output() - if err != nil { - return "", err - } + cmd := exec.Command("ip", "-json", "link", "show", dev) + output, err := cmd.Output() + if err != nil { + return "", err + } - var address []MacAddress - err = json.Unmarshal(output, &address) - if err != nil { - return "", err - } - return address[0].Address,nil + var address []MacAddress + err = json.Unmarshal(output, &address) + if err != nil { + return "", err + } + return address[0].Address, nil } func GetInterfaces() ([]ctypes.NetworkEntry, error) { iface := ctypes.NetworkEntry{} - cmd := exec.Command("ip", "-json", "r", "get", "1.1.1.1") - output, err := cmd.Output() - if err != nil { - return nil, err - } + cmd := exec.Command("ip", "-json", "r", "get", "1.1.1.1") + output, err := cmd.Output() + if err != nil { + return nil, err + } - var routes []MainInterface - err = json.Unmarshal(output, &routes) - if err != nil { - return nil, err - } + var routes []MainInterface + err = json.Unmarshal(output, &routes) + if err != nil { + return nil, err + } - if len(routes) == 0 { - return nil, fmt.Errorf("no route found for destination %s", "1.1.1.1") - } + if len(routes) == 0 { + return nil, fmt.Errorf("no route found for destination %s", "1.1.1.1") + } var ipaddress ctypes.IPEntry ipaddress.Name = routes[0].Gateway - iface.IPAddress.Entries = append(iface.IPAddress.Entries,ipaddress) + iface.IPAddress.Entries = append(iface.IPAddress.Entries, ipaddress) iface.Name = routes[0].Dev // Let's get the mac - mac,err := GetMac(iface.Name) + mac, err := GetMac(iface.Name) if err != nil { return nil, err - } - iface.Description="This is your default dev" + } + iface.Description = "This is your default dev" iface.MacAddress = mac - ifaces := []types.NetworkEntry{} - ifaces = append(ifaces,iface) - return ifaces, nil + ifaces := []ctypes.NetworkEntry{} + ifaces = append(ifaces, iface) + return ifaces, nil } func GetHostname() (string, error) { @@ -93,4 +92,3 @@ func GetOSVersion() (string, error) { } return fmt.Sprintf("%s %s", info.Platform, info.PlatformVersion), nil } - diff --git a/others/go.mod b/others/go.mod index 47d068b..7acca9a 100644 --- a/others/go.mod +++ b/others/go.mod @@ -1,5 +1,7 @@ -module github.com/bechampion/gohip/others +module gohip/gohip/others go 1.22.3 -require github.com/bechampion/gohip/types v0.0.0-20240615162838-24fd4fe6ae1c +replace gohip/types => ../types + +require gohip/types v0.0.0-00010101000000-000000000000 diff --git a/others/go.sum b/others/go.sum index 04a6260..e69de29 100644 --- a/others/go.sum +++ b/others/go.sum @@ -1,2 +0,0 @@ -github.com/bechampion/gohip/types v0.0.0-20240615162838-24fd4fe6ae1c h1:QTnpKqhL0/w393NPPO+f349ng5cIjCdEKHoy9SoiVJU= -github.com/bechampion/gohip/types v0.0.0-20240615162838-24fd4fe6ae1c/go.mod h1:53Die0OQJzRseQ5d54hf/bP8H6QhknWgg2XbZsiX55I= diff --git a/others/others.go b/others/others.go index 8d5cc4a..0f49597 100644 --- a/others/others.go +++ b/others/others.go @@ -3,7 +3,7 @@ package others import ( "bufio" "fmt" - ctypes "github.com/bechampion/gohip/types" + ctypes "gohip/types" "os" "os/exec" "os/user" @@ -85,33 +85,33 @@ func GetFirewall() []ctypes.ListEntry { return listfw } func GetEncryptedPartitions() []ctypes.DriveEntry { -drives := []ctypes.DriveEntry{} -file, err := os.Open("/proc/mounts") - if err != nil { - return []ctypes.DriveEntry{} - } - defer file.Close() + drives := []ctypes.DriveEntry{} + file, err := os.Open("/proc/mounts") + if err != nil { + return []ctypes.DriveEntry{} + } + defer file.Close() - scanner := bufio.NewScanner(file) - for scanner.Scan() { - line := scanner.Text() - fields := strings.Fields(line) - if len(fields) < 2 { - continue - } - mountPoint := fields[1] - if mountPoint == "/" { - drives = append(drives, ctypes.DriveEntry{ - DriveName: fields[0], - //This is hardcoded , we need to fix - EncState: "unencrypted", - }) - } - } + scanner := bufio.NewScanner(file) + for scanner.Scan() { + line := scanner.Text() + fields := strings.Fields(line) + if len(fields) < 2 { + continue + } + mountPoint := fields[1] + if mountPoint == "/" { + drives = append(drives, ctypes.DriveEntry{ + DriveName: fields[0], + //This is hardcoded , we need to fix + EncState: "unencrypted", + }) + } + } - if err := scanner.Err(); err != nil { - return []ctypes.DriveEntry{} - } + if err := scanner.Err(); err != nil { + return []ctypes.DriveEntry{} + } return drives } diff --git a/systemd/go.mod b/systemd/go.mod index 905706e..d1d3b97 100644 --- a/systemd/go.mod +++ b/systemd/go.mod @@ -1,5 +1,7 @@ -module github.com/bechampion/gohip/systemd +module gohip/systemd go 1.22.3 -require github.com/bechampion/gohip/types v0.0.0-20240615162333-918ade08d726 +require gohip/types v0.0.0-00010101000000-000000000000 + +replace gohip/types => ../types diff --git a/systemd/go.sum b/systemd/go.sum index 73b1325..e69de29 100644 --- a/systemd/go.sum +++ b/systemd/go.sum @@ -1,2 +0,0 @@ -github.com/bechampion/gohip/types v0.0.0-20240615162333-918ade08d726 h1:QowXmrFAANXYtDIuQOE7kx95vqH0/jam09nHKMgGVbY= -github.com/bechampion/gohip/types v0.0.0-20240615162333-918ade08d726/go.mod h1:53Die0OQJzRseQ5d54hf/bP8H6QhknWgg2XbZsiX55I= diff --git a/systemd/systemd.go b/systemd/systemd.go index 5e43215..7215f84 100644 --- a/systemd/systemd.go +++ b/systemd/systemd.go @@ -3,13 +3,24 @@ package systemd import ( "bytes" "fmt" - ctypes "github.com/bechampion/gohip/types" + ctypes "gohip/types" + "log" + "os" "os/exec" "regexp" + "slices" "strings" "time" ) +var ( + WarningLogger *log.Logger +) + +func init() { + WarningLogger = log.New(os.Stderr, "[WARN] ", log.Ldate|log.Ltime|log.Lshortfile) +} + type ClamDetails struct { Version string Month string @@ -43,18 +54,20 @@ func FindClamdProcess() ctypes.Prod { var out bytes.Buffer cmd.Stdout = &out + noClamAV := ctypes.Prod{} + if err := cmd.Run(); err != nil { - return ctypes.Prod{} + return noClamAV } lines := strings.Split(out.String(), "\n") - for _, line := range lines { - if strings.Contains(line, "clamd") { - cd, err := GetClamDetails() - if err != nil { - return ctypes.Prod{} - } + isRunning := slices.ContainsFunc(lines, func(process string) bool { + return strings.Contains(process, "clamd") + }) + + if isRunning { + if cd, err := GetClamDetails(); err != nil { return ctypes.Prod{ Vendor: "Cisco Systems, Inc.", Name: "ClamAV", @@ -68,5 +81,7 @@ func FindClamdProcess() ctypes.Prod { } } } - return ctypes.Prod{} + + WarningLogger.Println("clamd process not found") + return noClamAV } diff --git a/types/go.mod b/types/go.mod index e6c76fa..33df76e 100644 --- a/types/go.mod +++ b/types/go.mod @@ -1,3 +1,3 @@ -module github.com/bechampion/gohip/types +module gohip/types go 1.22.3