8 Commits

Author SHA1 Message Date
bf25ef967d Update to Hub
All checks were successful
build-binaries / build (.exe, amd64, windows) (push) Successful in 10m46s
build-binaries / release (push) Successful in 15s
build-binaries / publish-agent (push) Successful in 7s
2025-10-26 02:08:30 +01:00
3b2827bf70 .gitea/workflows/release.yml aktualisiert
All checks were successful
build-binaries / build (.exe, amd64, windows) (push) Successful in 10m4s
build-binaries / release (push) Successful in 33s
2025-10-24 09:14:31 +00:00
530a1f1f9f test
Some checks failed
build-binaries / build (, arm, 7, linux) (push) Failing after 4m55s
build-binaries / build (, arm64, linux) (push) Failing after 5m31s
build-binaries / build (, amd64, linux) (push) Failing after 5m45s
build-binaries / build (.exe, amd64, windows) (push) Successful in 10m4s
build-binaries / release (push) Has been skipped
2025-10-24 11:02:57 +02:00
64f4a6c43d .gitea/workflows/release.yml hinzugefügt
Some checks failed
build-binaries / build (, arm, 7, linux) (push) Failing after 1m16s
build-binaries / build (, arm64, linux) (push) Failing after 1m23s
build-binaries / build (, amd64, linux) (push) Failing after 1m38s
build-binaries / build (.exe, amd64, windows) (push) Successful in 10m39s
build-binaries / release (push) Has been skipped
2025-10-24 08:38:23 +00:00
6b073567b9 Update to Go-1.25.3 2025-10-21 07:22:34 +02:00
53a5cb7895 update für SH 2025-09-18 11:40:57 +02:00
4aa84655e0 final client 2025-05-09 22:47:16 +02:00
00ce82e341 läuft 2025-05-09 20:34:54 +02:00
6 changed files with 531 additions and 1 deletions

View File

@@ -0,0 +1,202 @@
# Git(tea) Actions workflow: Build and publish standalone binaries **plus** bundled `static/` assets
# ────────────────────────────────────────────────────────────────────
# ✧ Builds the Gobased WoL server for four targets **and** packt das Verzeichnis
# `static` zusammen mit der Binary, sodass es relativ zur ausführbaren Datei
# liegt (wichtig für die eingebauten BootstrapAssets & favicon).
#
# • linux/amd64 → wol-server-linux-amd64.tar.gz
# • linux/arm64 → wol-server-linux-arm64.tar.gz
# • linux/arm/v7 → wol-server-linux-armv7.tar.gz
# • windows/amd64 → wol-server-windows-amd64.zip
#
# ✧ Artefakte landen im Workflow und bei TagPush (vX.Y.Z) als ReleaseAssets.
#
# Secrets/variables:
# GITEA_TOKEN optional, falls default token keine ReleaseRechte hat.
# ────────────────────────────────────────────────────────────────────
name: build-binaries
on:
push:
branches: [ "main" ]
tags: [ "v*" ]
jobs:
build:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-fast
strategy:
matrix:
include:
- goos: windows
goarch: amd64
ext: ".exe"
env:
GO_VERSION: "1.25"
BINARY_NAME: duidreader
steps:
- name: Checkout source
uses: actions/checkout@v3
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Build ${{ matrix.goos }}/${{ matrix.goarch }}${{ matrix.goarm && format('/v{0}', matrix.goarm) || '' }}
shell: bash
run: |
set -e
mkdir -p dist/package
if [ -n "${{ matrix.goarm }}" ]; then export GOARM=${{ matrix.goarm }}; fi
CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -trimpath -ldflags "-s -w" \
-o "dist/package/${BINARY_NAME}${{ matrix.ext }}" .
# Assets: statisches Verzeichnis beilegen
# cp -r static dist/package/
- name: Package archive with static assets
shell: bash
run: |
set -e
cd dist
if [ "${{ matrix.goos }}" == "windows" ]; then
ZIP_NAME="${BINARY_NAME}-windows-amd64.zip"
(cd package && zip -r "../$ZIP_NAME" .)
else
ARCH_SUFFIX="${{ matrix.goarch }}"
if [ "${{ matrix.goarch }}" == "arm" ]; then ARCH_SUFFIX="armv${{ matrix.goarm }}"; fi
TAR_NAME="${BINARY_NAME}-${{ matrix.goos }}-${ARCH_SUFFIX}.tar.gz"
tar -czf "$TAR_NAME" -C package .
fi
- name: Upload workflow artifact
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.goarm && format('v{0}', matrix.goarm) || '' }}
path: dist/*.tar.gz
if-no-files-found: ignore
- uses: actions/upload-artifact@v3
with:
name: windows-amd64
path: dist/*.zip
if-no-files-found: ignore
# Release Schritt für TagPushes
release:
if: startsWith(github.ref, 'refs/tags/')
needs: build
runs-on: ubuntu-fast
permissions:
contents: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v3
with:
path: ./dist
- name: Create / Update release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITEA_TOKEN || github.token }}
with:
name: "Release ${{ github.ref_name }}"
tag_name: ${{ github.ref_name }}
draft: false
prerelease: false
files: |
dist/**/duidreader-*.tar.gz
dist/**/duidreader-*.zip
publish-agent:
if: startsWith(github.ref, 'refs/tags/')
needs: release
runs-on: ubuntu-fast
env:
PRODUCT: duidreader
AGENT_URL: ${{ secrets.AGENT_URL }}
AGENT_TOKEN: ${{ secrets.AGENT_TOKEN }}
# Funktioniert in GitHub und Gitea (Actions) weitgehend gleich:
SERVER_URL: ${{ github.server_url }} # z.B. https://github.com oder https://gitea.example.com
REPOSITORY: ${{ github.repository }} # owner/repo
TAG: ${{ github.ref_name }} # vX.Y.Z
steps:
- name: Download artifacts
uses: actions/download-artifact@v3
with:
path: ./dist
- name: Publish release metadata to Version Agent
shell: bash
run: |
set -euo pipefail
if [[ -z "${AGENT_URL:-}" || -z "${AGENT_TOKEN:-}" ]]; then
echo "Missing AGENT_URL or AGENT_TOKEN" >&2; exit 1
fi
VERSION="${TAG#v}" # 12.3.1[-rc.1|-beta.1]
MAJOR="${VERSION%%.*}" # 12
BRANCH="${MAJOR}.x" # 12.x
CHANNEL="stable"
[[ "$VERSION" == *"-rc"* ]] && CHANNEL="rc"
[[ "$VERSION" == *"-beta"* ]] && CHANNEL="beta"
# Optional: Nightly-Channel bei Non-Tag-Builds (separater Job, siehe unten)
RELEASED_AT="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
NOTES_URL="${SERVER_URL}/${REPOSITORY}/releases/tag/${TAG}"
publish() { # args: OS ARCH FILE
local OS="$1" ARCH="$2" FILE="$3"
local BIT="64"
case "$ARCH" in 386|armv7) BIT="32";; esac
local FNAME="$(basename "$FILE")"
local URL="${SERVER_URL}/${REPOSITORY}/releases/download/${TAG}/${FNAME}"
local SHA256 SIZE
SHA256="$(sha256sum "$FILE" | awk '{print $1}')"
SIZE="$(stat -c%s "$FILE")"
jq -n \
--arg branch "$BRANCH" \
--arg channel "$CHANNEL" \
--arg arch "$ARCH" \
--arg bit "$BIT" \
--arg os "$OS" \
--arg version "$VERSION" \
--arg released_at "$RELEASED_AT" \
--arg notes "$NOTES_URL" \
--arg url "$URL" \
--arg sha256 "$SHA256" \
--argjson size "$SIZE" \
'{
branch:$branch, channel:$channel, arch:$arch, bit:$bit, os:$os,
release:{
version:$version, released_at:$released_at, notes_url:$notes,
assets:[{url:$url, sha256:$sha256, size_bytes:$size}]
}
}' > payload.json
echo @payload.json
curl -fsS -H "Content-Type: application/json" \
-H "Authorization: Bearer ${AGENT_TOKEN}" \
-d @payload.json "${AGENT_URL}/v1/publish"
}
shopt -s nullglob
# linux/amd64
# for f in dist/**/${PRODUCT}-linux-amd64.tar.gz; do publish linux amd64 "$f"; done
# linux/arm64
# for f in dist/**/${PRODUCT}-linux-arm64.tar.gz; do publish linux arm64 "$f"; done
# linux/armv7
# for f in dist/**/${PRODUCT}-linux-armv7.tar.gz; do publish linux armv7 "$f"; done
# windows/amd64
for f in dist/**/${PRODUCT}-windows-amd64.zip; do publish windows amd64 "$f"; done

View File

@@ -1,2 +1 @@
# duidreader # duidreader

BIN
duidreader.exe Normal file

Binary file not shown.

5
go.mod Normal file
View File

@@ -0,0 +1,5 @@
module git.send.nrw/sendnrw/duidreader
go 1.25.3
require golang.org/x/sys v0.33.0

2
go.sum Normal file
View File

@@ -0,0 +1,2 @@
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=

322
main.go Normal file
View File

@@ -0,0 +1,322 @@
// client.go
package main
import (
"bufio"
"bytes"
"encoding/binary"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"io/fs"
"net/http"
"os"
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"
"time"
"golang.org/x/sys/windows/registry"
)
type iaidInfo struct {
Source string // Pfad oder Registry-Key
IAID uint32
}
// ---------- Linux ----------
var (
reDhclientIAID = regexp.MustCompile(`\biaid\s+(\d+);`) // dhclient, NM
reKVIAID = regexp.MustCompile(`^IAID=(\d+)`) // systemd-networkd
)
func getenv(k, d string) string {
if v := os.Getenv(k); v != "" {
return v
}
return d
}
func enabled(k string, def bool) bool {
b, err := strconv.ParseBool(strings.ToLower(os.Getenv(k)))
if err != nil {
return def
}
return b
}
func iaidsLinux() ([]iaidInfo, error) {
candidates := []string{
"/var/lib/NetworkManager",
"/var/lib/dhclient", // manche Distros
"/run/systemd/netif/leases", // systemd-networkd
"/var/lib/dhcpcd", "/var/lib/dhcpcd5",
}
var out []iaidInfo
visit := func(path string, d fs.DirEntry, err error) error {
if err != nil || d.IsDir() {
return nil
}
f, err := os.Open(path)
if err != nil {
return nil
}
defer f.Close()
sc := bufio.NewScanner(f)
for sc.Scan() {
line := sc.Text()
if m := reDhclientIAID.FindStringSubmatch(line); len(m) == 2 {
if v, _ := strconv.ParseUint(m[1], 10, 32); v != 0 {
out = append(out, iaidInfo{path, uint32(v)})
break
}
}
if m := reKVIAID.FindStringSubmatch(line); len(m) == 2 {
if v, _ := strconv.ParseUint(m[1], 10, 32); v != 0 {
out = append(out, iaidInfo{path, uint32(v)})
break
}
}
}
return nil
}
for _, dir := range candidates {
_ = filepath.WalkDir(dir, visit)
}
if len(out) == 0 {
return nil, fmt.Errorf("keine IAID-Datei gefunden (root-Rechte?)")
}
return out, nil
}
// ---------- Windows ----------
/*func iaidsWindows() ([]iaidInfo, error) {
base := `SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters\Interfaces`
root, err := registry.OpenKey(registry.LOCAL_MACHINE, base, registry.READ)
if err != nil {
return nil, err
}
defer root.Close()
names, _ := root.ReadSubKeyNames(-1)
var out []iaidInfo
for _, n := range names {
k, err := registry.OpenKey(root, n, registry.READ)
if err != nil {
continue
}
val, _, err := k.GetIntegerValue("IAID")
k.Close()
if err == nil {
out = append(out, iaidInfo{
Source: base + `\` + n + `\IAID`,
IAID: uint32(val),
})
}
}
if len(out) == 0 {
return nil, fmt.Errorf("kein IAID-Wert in der Registry")
}
return out, nil
}*/
func iaidsWindows() ([]iaidInfo, error) {
const base = `SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters\Interfaces`
root, err := registry.OpenKey(registry.LOCAL_MACHINE, base, registry.READ)
if err != nil {
return nil, err
}
defer root.Close()
var out []iaidInfo
guidKeys, _ := root.ReadSubKeyNames(-1)
for _, g := range guidKeys {
k, err := registry.OpenKey(root, g, registry.READ)
if err != nil {
continue
}
if v, _, err := k.GetIntegerValue("Dhcpv6Iaid"); err == nil {
out = append(out, iaidInfo{Source: base + `\` + g, IAID: uint32(v)})
k.Close()
continue
}
// --- Fallback: MAC → IAID (letzte 3 Bytes), falls DWORD fehlt ---
if mac, _, err := k.GetBinaryValue("NetworkAddress"); err == nil && len(mac) >= 6 {
iaid := uint32(mac[3])<<16 | uint32(mac[4])<<8 | uint32(mac[5])
out = append(out, iaidInfo{Source: base + `\` + g + " (computed)", IAID: iaid})
}
k.Close()
}
if len(out) == 0 {
return nil, fmt.Errorf("weder Dhcpv6Iaid noch MAC-basierten Fallback gefunden - nutzt der Client überhaupt DHCPv6?")
}
return out, nil
}
// ---------- Fallback: IAID selbst ableiten (MAC → 3 Byte) ----------
func iaidFromMAC(mac []byte, ifindex int) uint32 {
if len(mac) >= 3 {
return binary.BigEndian.Uint32([]byte{0, mac[len(mac)-3], mac[len(mac)-2], mac[len(mac)-1]})
}
// Notlösung: Interface-Index + 0xA0 im obersten Byte
return uint32(0xA0000000 | (ifindex & 0x00FFFFFF))
}
/*######################################################################################################*/
/*######################################################################################################*/
/*######################################################################################################*/
/*######################################################################################################*/
/*######################################################################################################*/
// ---------- Datentyp, der an den Server geschickt wird ----------
type payload struct {
Hostname string `json:"hostname"`
DUIDs []string `json:"duids"` // hex-codiert
IAIDs []uint32
}
// ---------- Linux ----------
func duidsLinux() ([][]byte, error) {
candidates := []string{
"/var/lib/NetworkManager",
"/var/lib/dhcp",
"/var/lib/systemd/network",
"/run/systemd/netif/leases",
}
var out [][]byte
for _, dir := range candidates {
_ = filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error {
if err != nil || d.IsDir() {
return nil
}
buf, err := os.ReadFile(path)
if err != nil {
return nil
}
if duid := extractDUID(buf); len(duid) > 0 {
out = append(out, duid)
}
return nil
})
}
if len(out) == 0 {
return nil, errors.New("keine DUID gefunden")
}
return out, nil
}
// ---------- Windows ----------
func duidsWindows() ([][]byte, error) {
k, err := registry.OpenKey(registry.LOCAL_MACHINE,
`SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters`,
registry.READ)
if err != nil {
return nil, err
}
defer k.Close()
val, _, err := k.GetBinaryValue("Dhcpv6DUID")
if err != nil {
return nil, err
}
return [][]byte{val}, nil
}
// ---------- Hilfsfunktionen ----------
func extractDUID(b []byte) []byte {
if idx := bytes.Index(b, []byte("default-duid")); idx >= 0 {
start := bytes.IndexByte(b[idx:], '"') + idx + 1
end := bytes.IndexByte(b[start:], '"') + start
hexEsc := bytes.ReplaceAll(b[start:end], []byte(`\x`), nil)
duid, _ := hex.DecodeString(string(hexEsc))
return duid
}
hexOnly := strings.TrimSpace(string(b))
if len(hexOnly) >= 28 && allHex(hexOnly) { // plausibel?
duid, _ := hex.DecodeString(hexOnly)
return duid
}
return nil
}
func allHex(s string) bool {
for _, c := range s {
if !strings.ContainsRune("0123456789abcdefABCDEF", c) {
return false
}
}
return true
}
// ---------- main ----------
func main() {
var raw [][]byte
var all []iaidInfo
var err error
var err1 error
switch runtime.GOOS {
case "windows":
raw, err = duidsWindows()
all, err1 = iaidsWindows()
default:
raw, err = duidsLinux()
all, err1 = iaidsLinux()
}
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
if err1 != nil {
fmt.Fprintln(os.Stderr, err1)
}
for _, ia := range all {
fmt.Printf("%-60s 0x%08x (%d)\n", ia.Source, ia.IAID, ia.IAID)
}
var gh []uint32
for _, bh := range all {
gh = append(gh, bh.IAID)
}
host, _ := os.Hostname()
//host := "PC1020"
p := payload{
Hostname: host,
DUIDs: make([]string, len(raw)),
IAIDs: gh,
}
for i, d := range raw {
p.DUIDs[i] = hex.EncodeToString(d)
}
// --- JSON kodieren ---
body, _ := json.Marshal(p)
// --- HTTP senden ---
url := getenv("DUID_REGISTER_URL", "https://client-ipv6.stadt-hilden.de/register") // <-- ggf. anpassen
req, _ := http.NewRequest(http.MethodPost, url, bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
client := &http.Client{Timeout: 5 * time.Second}
resp, err := client.Do(req)
if err != nil {
fmt.Fprintln(os.Stderr, "HTTP-Fehler:", err)
os.Exit(1)
}
defer resp.Body.Close()
fmt.Println("Server-Antwort:", resp.Status)
}