DHCP Unterstützung implementiert
All checks were successful
release-tag / release-image (push) Successful in 1m53s
All checks were successful
release-tag / release-image (push) Successful in 1m53s
This commit is contained in:
24
main.go
24
main.go
@@ -47,6 +47,8 @@ var (
|
|||||||
rangeLimit int
|
rangeLimit int
|
||||||
singleTemplate *template.Template
|
singleTemplate *template.Template
|
||||||
rangeTemplate *template.Template
|
rangeTemplate *template.Template
|
||||||
|
dhcpServer string
|
||||||
|
dhcpScope string
|
||||||
)
|
)
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -57,7 +59,7 @@ type singleData struct {
|
|||||||
HaveResult bool
|
HaveResult bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type addrPair struct{ IPv4, IPv6 string }
|
type addrPair struct{ Name, IPv4, IPv6 string }
|
||||||
|
|
||||||
type rangeData struct {
|
type rangeData struct {
|
||||||
Start, End string
|
Start, End string
|
||||||
@@ -129,6 +131,16 @@ func handleRange(w http.ResponseWriter, r *http.Request) {
|
|||||||
d.HaveResult = true
|
d.HaveResult = true
|
||||||
d.Rows = rows
|
d.Rows = rows
|
||||||
}
|
}
|
||||||
|
for a, b := range rows {
|
||||||
|
fmt.Println(a, b)
|
||||||
|
octets := strings.Split(b.IPv4, ".")
|
||||||
|
if len(octets) != 4 {
|
||||||
|
fmt.Println("Ungültige IP-Adresse!")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
N := "PC" + octets[2] + octets[3]
|
||||||
|
d.Rows = append(d.Rows, addrPair{IPv4: b.IPv4, IPv6: b.IPv6, Name: N})
|
||||||
|
}
|
||||||
renderRange(w, d)
|
renderRange(w, d)
|
||||||
default:
|
default:
|
||||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||||
@@ -214,6 +226,9 @@ func initConfigAndTemplates() {
|
|||||||
pageIP = defaultIP
|
pageIP = defaultIP
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dhcpScope = os.Getenv("DHCP_SERVER")
|
||||||
|
dhcpServer = os.Getenv("DHCP_SCOPE")
|
||||||
|
|
||||||
// Range limit ---------------------------------
|
// Range limit ---------------------------------
|
||||||
if limStr := os.Getenv("RANGE_LIMIT"); limStr != "" {
|
if limStr := os.Getenv("RANGE_LIMIT"); limStr != "" {
|
||||||
if v, err := strconv.Atoi(limStr); err == nil && v > 0 {
|
if v, err := strconv.Atoi(limStr); err == nil && v > 0 {
|
||||||
@@ -227,7 +242,7 @@ func initConfigAndTemplates() {
|
|||||||
|
|
||||||
// Templates -----------------------------------
|
// Templates -----------------------------------
|
||||||
singleHTML := fmt.Sprintf(singlePageHTML, pageIP, ulaPrefix)
|
singleHTML := fmt.Sprintf(singlePageHTML, pageIP, ulaPrefix)
|
||||||
rangeHTML := fmt.Sprintf(rangePageHTML, ulaPrefix)
|
rangeHTML := fmt.Sprintf(rangePageHTML, dhcpServer, dhcpScope)
|
||||||
singleTemplate = template.Must(template.New("single").Parse(singleHTML))
|
singleTemplate = template.Must(template.New("single").Parse(singleHTML))
|
||||||
rangeTemplate = template.Must(template.New("range").Parse(rangeHTML))
|
rangeTemplate = template.Must(template.New("range").Parse(rangeHTML))
|
||||||
}
|
}
|
||||||
@@ -307,10 +322,9 @@ var rangePageHTML = `<!DOCTYPE html>
|
|||||||
</form>
|
</form>
|
||||||
{{if .HaveResult}}
|
{{if .HaveResult}}
|
||||||
<table>
|
<table>
|
||||||
<tr><th>IPv4</th><th>IPv6</th></tr>
|
<tr><th>IPv4</th><th>IPv6</th><th>DHCP-IPv4</th><th>DHCP-IPv6</th></tr>
|
||||||
{{range .Rows}}<tr><td>{{.IPv4}}</td><td>{{.IPv6}}</td></tr>{{end}}
|
{{range .Rows}}<tr><td>{{.IPv4}}</td><td>{{.IPv6}}</td><td>netsh DHCP Server %s Scope %s Add reservedip {{.IPv4}} "{{.Name}}.stadt-hilden.de" "" "DHCP"</td><td>---</td></tr>{{end}}
|
||||||
</table>
|
</table>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if .Error}}<p style="color:#b00">Fehler: {{.Error}}</p>{{end}}
|
{{if .Error}}<p style="color:#b00">Fehler: {{.Error}}</p>{{end}}
|
||||||
<p style="margin-top:1rem">Aktives Präfix: <code>%s</code> (/96)</p>
|
|
||||||
</body></html>`
|
</body></html>`
|
||||||
|
Reference in New Issue
Block a user