6 Commits

Author SHA1 Message Date
f4ed36121e Update für Device GUID
All checks were successful
build-binaries / build (.exe, amd64, windows) (push) Successful in 10m24s
build-binaries / release (push) Successful in 14s
build-binaries / publish-agent (push) Successful in 13s
2025-12-11 10:16:19 +01:00
de66b186b2 main.go aktualisiert
All checks were successful
build-binaries / build (.exe, amd64, windows) (push) Successful in 10m12s
build-binaries / release (push) Successful in 13s
build-binaries / publish-agent (push) Successful in 9s
2025-11-12 07:58:36 +00:00
59d8fb3e5d Anpassung auf Breite 1200
All checks were successful
build-binaries / build (.exe, amd64, windows) (push) Successful in 10m14s
build-binaries / release (push) Successful in 15s
build-binaries / publish-agent (push) Successful in 10s
2025-11-02 17:33:39 +01:00
a2cb8450e2 Template angepasst (Hell).
All checks were successful
build-binaries / build (.exe, amd64, windows) (push) Has been skipped
build-binaries / release (push) Has been skipped
build-binaries / publish-agent (push) Has been skipped
2025-11-02 17:22:13 +01:00
fee5b400a6 Anschluss geändert auf :24000
All checks were successful
build-binaries / build (.exe, amd64, windows) (push) Successful in 10m13s
build-binaries / release (push) Successful in 12s
build-binaries / publish-agent (push) Successful in 8s
2025-10-30 21:28:56 +01:00
8e4325a1f8 Erkennung der Netzwerk-Profile hinzugefügt 2025-10-30 21:21:04 +01:00
2 changed files with 323 additions and 46 deletions

333
main.go
View File

@@ -10,6 +10,7 @@ import (
"net" "net"
"net/http" "net/http"
"os" "os"
"os/exec"
"os/user" "os/user"
"runtime" "runtime"
"sort" "sort"
@@ -31,6 +32,7 @@ type NetInterface struct {
MAC string `json:"mac"` MAC string `json:"mac"`
Addresses []string `json:"addresses"` Addresses []string `json:"addresses"`
IsLoopback bool `json:"is_loopback"` IsLoopback bool `json:"is_loopback"`
Profile string `json:"profile"`
} }
type DiskInfo struct { type DiskInfo struct {
@@ -79,11 +81,123 @@ type InstalledApp struct {
Source string `json:"source"` // HKLM-64, HKLM-32, HKCU Source string `json:"source"` // HKLM-64, HKLM-32, HKCU
} }
type DeviceInfo struct {
InstanceID string `json:"instance_id"`
Class string `json:"class"`
ClassGUID string `json:"class_guid"`
FriendlyName string `json:"friendly_name"`
Manufacturer string `json:"manufacturer"`
Status string `json:"status"`
Present bool `json:"present"`
}
var ( var (
mu sync.RWMutex mu sync.RWMutex
lastCPUUsage float64 lastCPUUsage float64
) )
func getPnpDevices() ([]DeviceInfo, error) {
// PowerShell: aktuelle PnP-Geräte, inkl. ClassGuid
cmd := exec.Command(
"powershell",
"-NoProfile",
"-NonInteractive",
"-Command",
`Get-PnpDevice -PresentOnly | Select-Object InstanceId,Class,ClassGuid,FriendlyName,Manufacturer,Status,Present | ConvertTo-Json -Depth 3`,
)
out, err := cmd.Output()
if err != nil {
log.Printf("getPnpDevices: powershell error: %v", err)
return nil, err
}
if len(out) == 0 {
return []DeviceInfo{}, nil
}
// PS gibt entweder ein Objekt oder ein Array zurück → wie bei getWinNetProfiles behandeln
type psDevice struct {
InstanceId string `json:"InstanceId"`
Class string `json:"Class"`
ClassGuid string `json:"ClassGuid"`
FriendlyName string `json:"FriendlyName"`
Manufacturer string `json:"Manufacturer"`
Status string `json:"Status"`
Present interface{} `json:"Present"`
}
parsePresent := func(v interface{}) bool {
switch t := v.(type) {
case bool:
return t
case string:
// "True"/"False" etc.
return strings.EqualFold(t, "true")
default:
return false
}
}
var arr []psDevice
if err := json.Unmarshal(out, &arr); err == nil {
res := make([]DeviceInfo, 0, len(arr))
for _, d := range arr {
res = append(res, DeviceInfo{
InstanceID: d.InstanceId,
Class: d.Class,
ClassGUID: d.ClassGuid,
FriendlyName: d.FriendlyName,
Manufacturer: d.Manufacturer,
Status: d.Status,
Present: parsePresent(d.Present),
})
}
return res, nil
}
// Ein einzelnes Objekt
var single psDevice
if err := json.Unmarshal(out, &single); err != nil {
log.Printf("getPnpDevices: cannot unmarshal: %v -- out: %s", err, string(out))
return nil, err
}
return []DeviceInfo{
{
InstanceID: single.InstanceId,
Class: single.Class,
ClassGUID: single.ClassGuid,
FriendlyName: single.FriendlyName,
Manufacturer: single.Manufacturer,
Status: single.Status,
Present: parsePresent(single.Present),
},
}, nil
}
func devicesHandler(w http.ResponseWriter, r *http.Request) {
devs, err := getPnpDevices()
if err != nil {
http.Error(w, "failed to enumerate devices: "+err.Error(), http.StatusInternalServerError)
return
}
// Optional: Filter nur USB-Geräte (InstanceID beginnt mit "USB\")
if r.URL.Query().Get("only_usb") == "1" {
filtered := make([]DeviceInfo, 0, len(devs))
for _, d := range devs {
if strings.HasPrefix(strings.ToUpper(d.InstanceID), "USB\\") {
filtered = append(filtered, d)
}
}
devs = filtered
}
w.Header().Set("Content-Type", "application/json")
enc := json.NewEncoder(w)
enc.SetIndent("", " ")
_ = enc.Encode(devs)
}
func readUninstallKey(base registry.Key, path, src string) []InstalledApp { func readUninstallKey(base registry.Key, path, src string) []InstalledApp {
k, err := registry.OpenKey(base, path, registry.ENUMERATE_SUB_KEYS|registry.QUERY_VALUE) k, err := registry.OpenKey(base, path, registry.ENUMERATE_SUB_KEYS|registry.QUERY_VALUE)
if err != nil { if err != nil {
@@ -206,6 +320,10 @@ func getInterfaces() []NetInterface {
if err != nil { if err != nil {
return nil return nil
} }
// Profile holen (best effort)
profilesByIndex, _ := getWinNetProfiles()
var out []NetInterface var out []NetInterface
for _, ifc := range ifaces { for _, ifc := range ifaces {
if (ifc.Flags & net.FlagUp) == 0 { if (ifc.Flags & net.FlagUp) == 0 {
@@ -222,10 +340,7 @@ func getInterfaces() []NetInterface {
case *net.IPAddr: case *net.IPAddr:
ip = v.IP ip = v.IP
} }
if ip == nil { if ip == nil || ip.IsLoopback() {
continue
}
if ip.IsLoopback() {
continue continue
} }
ips = append(ips, ip.String()) ips = append(ips, ip.String())
@@ -233,11 +348,15 @@ func getInterfaces() []NetInterface {
if isLoop { if isLoop {
continue continue
} }
profile := profilesByIndex[ifc.Index] // 👈 jetzt sicher über Index
out = append(out, NetInterface{ out = append(out, NetInterface{
Name: ifc.Name, Name: ifc.Name,
MAC: ifc.HardwareAddr.String(), MAC: ifc.HardwareAddr.String(),
Addresses: ips, Addresses: ips,
IsLoopback: isLoop, IsLoopback: isLoop,
Profile: profile,
}) })
} }
return out return out
@@ -352,31 +471,108 @@ var page = template.Must(template.New("index").Parse(`<!doctype html>
<meta name="viewport" content="width=device-width,initial-scale=1"> <meta name="viewport" content="width=device-width,initial-scale=1">
<title>Windows Systeminfo</title> <title>Windows Systeminfo</title>
<style> <style>
:root { --bg:#000000; --fg:#e7eefc; --muted:#a3b1cc; --card:#111a2e; --accent:#5aa9ff; } :root {
--bg: #f5f6f8;
--fg: #121826;
--muted: #5d6b82;
--card: #ffffff;
--accent: #0066ff;
--border: rgba(12, 21, 37, 0.08);
}
*{box-sizing:border-box} *{box-sizing:border-box}
body{max-width:980px;margin:0 auto;padding:24px;font-family:system-ui,-apple-system,Segoe UI,Roboto,Ubuntu,Cantarell,Noto Sans,sans-serif;background:var(--bg);color:var(--fg)} body{
h1{font-size:22px;margin:0 0 16px 0} max-width:1200px;
margin:0 auto;
padding:24px;
font-family:system-ui,-apple-system,Segoe UI,Roboto,Ubuntu,Cantarell,Noto Sans,sans-serif;
background:var(--bg);
color:var(--fg);
}
h1{font-size:22px;margin:0 0 6px 0}
h2{margin:0 0 16px 0}
.grid{display:flex;flex-direction:column;gap:12px} .grid{display:flex;flex-direction:column;gap:12px}
.card{width:100%} .card{
.k{font-size:12px;color:var(--muted);text-transform:uppercase;letter-spacing:.06em} width:100%;
background:var(--card);
border:1px solid var(--border);
border-radius:16px;
padding:14px 16px 10px 16px;
box-shadow:0 10px 30px rgba(15,23,42,0.03);
}
.k{font-size:13px;color:var(--muted);text-transform:uppercase;letter-spacing:.06em;margin-bottom:4px}
.v{font-weight:600} .v{font-weight:600}
.row{display:flex;justify-content:space-between;gap:8px;align-items:center;margin:6px 0} .row{display:flex;justify-content:space-between;gap:8px;align-items:center;margin:6px 0}
.mono{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace} .mono{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace}
.pill{display:inline-block;background:#0b2547;color:#b8d4ff;border-radius:999px;padding:2px 8px;margin:2px 6px 0 0;font-size:12px} .stereo{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;color: #ff0000ff}
.bar{height:10px;background:#091428;border-radius:999px;overflow:hidden} .pill{
.fill{height:100%;background:var(--accent);width:0%} display:inline-block;
background:#e8f1ff;
color:#0047cc;
border-radius:999px;
padding:2px 8px;
margin:2px 6px 0 0;
font-size:14px;
}
.pill2{
display:inline-block;
background:#ffe480;
color:#3e3e3e;
border-radius:999px;
padding:2px 8px;
margin:2px 6px 0 0;
font-size:14px;
}
.bar{
height:10px;
background:#edf0f5;
border-radius:999px;
overflow:hidden;
}
.fill{
height:100%;
background:var(--accent);
width:0%;
transition:width .3s ease-out;
}
footer{margin-top:18px;color:var(--muted);font-size:12px} footer{margin-top:18px;color:var(--muted);font-size:12px}
.disks table{width:100%;border-collapse:collapse} .disks table{width:100%;border-collapse:collapse}
.disks th,.disks td{padding:8px;border-bottom:1px solid #1b2a4a;text-align:left;font-size:14px} .disks th,.disks td{
padding:8px;
border-bottom:1px solid #e5e9f2;
text-align:left;
font-size:14px
}
.disks th{background:#f5f6f8;font-weight:500}
button#btnLoadApps{
border:none;
background:#e8f1ff;
color:#0047cc;
font-weight:500;
}
input#appsFilter{
background:#ffffff;
color:var(--fg);
border:1px solid #d0d7e2;
border-radius:8px;
}
table thead th{font-size:13px;color:#3b4560}
@media (prefers-color-scheme: dark) {
/* optional: falls Host dunkles Theme erzwingt */
:root {
--bg:#f5f6f8;
--fg:#121826;
--card:#ffffff;
}
}
</style> </style>
</head> </head>
<body> <body>
<h1>Windows Systeminfo</h1> <h1>Windows Systeminfo</h1>
<h2><div class="v mono" id="hostname2"></div></h2> <h2><div class="v stereo" id="hostname2"></div></h2>
<div class="grid"> <div class="grid">
<div class="card"> <div class="card">
<div class="k">Host</div> <div class="k">Host</div>
<div class="row"><div>Hostname</div><div class="v mono" id="hostname"></div></div> <div class="row"><div>Hostname</div><div class="v stereo" id="hostname"></div></div>
<div class="row"><div>User</div><div class="v mono" id="username"></div></div> <div class="row"><div>User</div><div class="v mono" id="username"></div></div>
<div class="row"><div>Uptime</div><div class="v" id="uptime"></div></div> <div class="row"><div>Uptime</div><div class="v" id="uptime"></div></div>
<div class="row"><div>Boot</div><div class="v" id="boottime"></div></div> <div class="row"><div>Boot</div><div class="v" id="boottime"></div></div>
@@ -424,17 +620,17 @@ var page = template.Must(template.New("index").Parse(`<!doctype html>
<div class="row" style="gap:8px;align-items:center;"> <div class="row" style="gap:8px;align-items:center;">
<button id="btnLoadApps" class="pill" style="cursor:pointer;">Laden</button> <button id="btnLoadApps" class="pill" style="cursor:pointer;">Laden</button>
<input id="appsFilter" type="text" placeholder="Suchen …" <input id="appsFilter" type="text" placeholder="Suchen …"
style="flex:1;padding:6px 10px;border-radius:8px;border:1px solid #1b2a4a;background:#0b1220;color:var(--fg)"> style="flex:1;padding:6px 10px;">
<span class="k" id="appsCount"></span> <span class="k" id="appsCount"></span>
</div> </div>
<div class="apps"> <div class="apps">
<table style="width:100%;border-collapse:collapse"> <table style="width:100%;border-collapse:collapse">
<thead> <thead>
<tr> <tr>
<th style="text-align:left;padding:8px;border-bottom:1px solid #1b2a4a">Name</th> <th style="text-align:left;padding:8px;border-bottom:1px solid #e5e9f2">Name</th>
<th style="text-align:left;padding:8px;border-bottom:1px solid #1b2a4a">Version</th> <th style="text-align:left;padding:8px;border-bottom:1px solid #e5e9f2">Version</th>
<th style="text-align:left;padding:8px;border-bottom:1px solid #1b2a4a">Publisher</th> <th style="text-align:left;padding:8px;border-bottom:1px solid #e5e9f2">Publisher</th>
<th style="text-align:left;padding:8px;border-bottom:1px solid #1b2a4a">Quelle</th> <th style="text-align:left;padding:8px;border-bottom:1px solid #e5e9f2">Quelle</th>
</tr> </tr>
</thead> </thead>
<tbody id="apps"></tbody> <tbody id="apps"></tbody>
@@ -482,6 +678,12 @@ async function load(){
(j.interfaces||[]).forEach(n=>{ (j.interfaces||[]).forEach(n=>{
const div = document.createElement('div'); const div = document.createElement('div');
div.innerHTML = '<div class="row"><div>'+n.name+'</div><div class="mono">'+(n.mac||'-')+'</div></div>'; div.innerHTML = '<div class="row"><div>'+n.name+'</div><div class="mono">'+(n.mac||'-')+'</div></div>';
if (n.profile) {
const p = document.createElement('span');
p.className = 'pill2';
p.textContent = n.profile;
div.appendChild(p);
}
(n.addresses||[]).forEach(ip=>{ const span=document.createElement('span'); span.className='pill mono'; span.textContent=ip; div.appendChild(span); }); (n.addresses||[]).forEach(ip=>{ const span=document.createElement('span'); span.className='pill mono'; span.textContent=ip; div.appendChild(span); });
wrap.appendChild(div); wrap.appendChild(div);
}); });
@@ -506,10 +708,10 @@ function renderApps(list){
(list||[]).forEach(a=>{ (list||[]).forEach(a=>{
const tr = document.createElement('tr'); const tr = document.createElement('tr');
tr.innerHTML = tr.innerHTML =
'<td class="mono" style="padding:6px 8px;border-bottom:1px solid #1b2a4a">'+(a.name||'-')+'</td>'+ '<td class="mono" style="padding:6px 8px;border-bottom:1px solid #e5e9f2">'+(a.name||'-')+'</td>'+
'<td style="padding:6px 8px;border-bottom:1px solid #1b2a4a">'+(a.version||'')+'</td>'+ '<td style="padding:6px 8px;border-bottom:1px solid #e5e9f2">'+(a.version||'')+'</td>'+
'<td style="padding:6px 8px;border-bottom:1px solid #1b2a4a">'+(a.publisher||'')+'</td>'+ '<td style="padding:6px 8px;border-bottom:1px solid #e5e9f2">'+(a.publisher||'')+'</td>'+
'<td style="padding:6px 8px;border-bottom:1px solid #1b2a4a">'+(a.source||'')+'</td>'; '<td style="padding:6px 8px;border-bottom:1px solid #e5e9f2">'+(a.source||'')+'</td>';
tbody.appendChild(tr); tbody.appendChild(tr);
}); });
const c = document.getElementById('appsCount'); const c = document.getElementById('appsCount');
@@ -517,7 +719,7 @@ function renderApps(list){
} }
async function loadAppsOnce(){ async function loadAppsOnce(){
if(appsCache) return; // schon geladen if(appsCache) return;
try{ try{
const r = await fetch('/api/apps'); const r = await fetch('/api/apps');
appsCache = await r.json(); appsCache = await r.json();
@@ -545,10 +747,10 @@ document.addEventListener('DOMContentLoaded', ()=>{
}); });
} }
}); });
</script> </script>
</body> </body>
</html>`)) </html>
`))
func indexHandler(w http.ResponseWriter, r *http.Request) { func indexHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8") w.Header().Set("Content-Type", "text/html; charset=utf-8")
@@ -577,8 +779,9 @@ func runHTTP(ctx context.Context) error {
mux.HandleFunc("/", indexHandler) mux.HandleFunc("/", indexHandler)
mux.HandleFunc("/api/apps", appsHandler) mux.HandleFunc("/api/apps", appsHandler)
mux.HandleFunc("/api/summary", apiHandler) mux.HandleFunc("/api/summary", apiHandler)
mux.HandleFunc("/api/devices", devicesHandler)
addr := "127.0.0.1:8080" addr := ":24000"
srv := &http.Server{ srv := &http.Server{
Addr: addr, Addr: addr,
@@ -660,3 +863,77 @@ func main() {
log.Fatal(err) log.Fatal(err)
} }
} }
type psConnProfile struct {
Name string `json:"Name"`
InterfaceAlias string `json:"InterfaceAlias"`
InterfaceIndex int `json:"InterfaceIndex"`
NetworkCategory string `json:"NetworkCategory"` // "Public", "Private", "DomainAuthenticated"
}
func getWinNetProfiles() (map[int]string, error) {
cmd := exec.Command(
"powershell",
"-NoProfile",
"-NonInteractive",
"-Command",
`Get-NetConnectionProfile | Select-Object InterfaceAlias,InterfaceIndex,NetworkCategory | ConvertTo-Json -Depth 3`,
)
out, err := cmd.Output()
if err != nil {
log.Printf("getWinNetProfiles: powershell error: %v", err)
return nil, err
}
if len(out) == 0 {
return map[int]string{}, nil
}
// Wir wissen nicht, ob PS ein Objekt oder ein Array zurückgibt → erst Array versuchen
type psConnProfile struct {
InterfaceAlias string `json:"InterfaceAlias"`
InterfaceIndex int `json:"InterfaceIndex"`
NetworkCategory interface{} `json:"NetworkCategory"`
}
normalizeCat := func(v interface{}) string {
switch vv := v.(type) {
case string:
// "Public", "Private", "DomainAuthenticated"
return vv
case float64:
switch int(vv) {
case 0:
return "Public"
case 1:
return "Private"
case 2:
return "DomainAuthenticated"
default:
return "Unknown"
}
default:
return ""
}
}
// 1) Array probieren
var arr []psConnProfile
if err := json.Unmarshal(out, &arr); err == nil {
res := make(map[int]string, len(arr))
for _, p := range arr {
res[p.InterfaceIndex] = normalizeCat(p.NetworkCategory)
}
return res, nil
}
// 2) Einzelnes Objekt probieren
var single psConnProfile
if err := json.Unmarshal(out, &single); err != nil {
log.Printf("getWinNetProfiles: cannot unmarshal: %v -- out: %s", err, string(out))
return nil, err
}
res := make(map[int]string, 1)
res[single.InterfaceIndex] = normalizeCat(single.NetworkCategory)
return res, nil
}

Binary file not shown.