Skip to content

Commit

Permalink
Merge pull request #4 from grumlimited/main
Browse files Browse the repository at this point in the history
NOJ - Made modules local
  • Loading branch information
bechampion authored Jun 24, 2024
2 parents 2f577cc + cc24aab commit 6f28812
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 109 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ gohip
command.log
.idea
*.iml
pkg
16 changes: 12 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
8 changes: 0 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
9 changes: 4 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -29,7 +29,6 @@ func logCommandAndArgs() {

func main() {
logCommandAndArgs()
systemd.FindClamdProcess()
cookie := flag.String("cookie", "", "")
_ = flag.String("client-os", "", "")
clientip := flag.String("client-ip", "", "")
Expand Down
6 changes: 4 additions & 2 deletions osdata/go.mod
Original file line number Diff line number Diff line change
@@ -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
)

Expand All @@ -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
2 changes: 0 additions & 2 deletions osdata/go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
86 changes: 42 additions & 44 deletions osdata/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -93,4 +92,3 @@ func GetOSVersion() (string, error) {
}
return fmt.Sprintf("%s %s", info.Platform, info.PlatformVersion), nil
}

6 changes: 4 additions & 2 deletions others/go.mod
Original file line number Diff line number Diff line change
@@ -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
2 changes: 0 additions & 2 deletions others/go.sum
Original file line number Diff line number Diff line change
@@ -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=
52 changes: 26 additions & 26 deletions others/others.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package others
import (
"bufio"
"fmt"
ctypes "github.com/bechampion/gohip/types"
ctypes "gohip/types"
"os"
"os/exec"
"os/user"
Expand Down Expand Up @@ -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

}
Expand Down
6 changes: 4 additions & 2 deletions systemd/go.mod
Original file line number Diff line number Diff line change
@@ -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
2 changes: 0 additions & 2 deletions systemd/go.sum
Original file line number Diff line number Diff line change
@@ -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=
33 changes: 24 additions & 9 deletions systemd/systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -68,5 +81,7 @@ func FindClamdProcess() ctypes.Prod {
}
}
}
return ctypes.Prod{}

WarningLogger.Println("clamd process not found")
return noClamAV
}
2 changes: 1 addition & 1 deletion types/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/bechampion/gohip/types
module gohip/types

go 1.22.3

0 comments on commit 6f28812

Please sign in to comment.