From cc1245da1ecdae1157a30596d813168f345903e0 Mon Sep 17 00:00:00 2001 From: Ilker Manap Date: Sun, 1 Nov 2026 12:21:22 +0100 Subject: [PATCH] NetBox's web UI through Rollcall, and links to it from the web UI With NetBox as the IPAM under a path (its BASE_PATH) and ipam.url carrying it, Rollcall serves NetBox's UI at that same path, for admins only (the admin certificate, as for the API); NetBox keeps its own login. Redirects that name NetBox's own address are turned back to Rollcall's, Rollcall's credentials are not passed on. NetBox opens wherever Rollcall does: a lab NetBox on a segment the browser cannot reach, say. The web UI links to NetBox: the sidebar, sites, rooms, racks, switches and a machine's device (by its rollcall_machine field). ipam.ui_url points the links at NetBox directly instead. NetBox paging under a BASE_PATH doubled the path on the next page (the next link carries it already); fixed. The lab NetBox moves under /netbox/ and trusts the region's addresses for its forms. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 14 +++++++ README.md | 31 ++++++++++++++++ cmd/rollcall/ipam.go | 10 +++-- cmd/rollcall/nbproxy.go | 64 ++++++++++++++++++++++++++++++++ cmd/rollcall/nbproxy_test.go | 71 ++++++++++++++++++++++++++++++++++++ cmd/rollcall/server.go | 3 ++ cmd/rollcall/web/app.js | 9 ++++- cmd/rollcall/web/index.html | 1 + cmd/rollcall/web/sites.js | 11 +++--- cmd/rollcall/web/style.css | 2 + lab/netbox/install.sh | 10 ++++- 11 files changed, 214 insertions(+), 12 deletions(-) create mode 100644 cmd/rollcall/nbproxy.go create mode 100644 cmd/rollcall/nbproxy_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index a5f9451..e1cc495 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,15 @@ publish a tag that has no section here. ## [Unreleased] ### Added +- Rooms in 3D (three.js shipped in the binary, loaded on first use): racks at their places and + height, servers drawn from their model's front (drive bays, ears, vents; no photos or logos) with + the state on the ear, multi-node sleds side by side, backs with power supplies and the network + cards' ports. Drag to turn, double click to go to a rack; selection is shared with the floor plan. +- Cabling from LLDP: `GET /api/v1/cabling` (each machine's ports and the switch port they lead to), + switches placed from NetBox or by hand (`POST`/`DELETE /api/v1/switches`), cables drawn in the 3D + room from port to switch port, coloured per switch, and listed per rack in the side panel. +- NetBox's web UI through Rollcall at its `BASE_PATH` (admins only), and links to NetBox from the + web UI (sidebar, sites, rooms, racks, switches, machine devices); `ipam.ui_url` for direct links. - Sites page: sites on an OpenStreetMap map (Leaflet shipped in the binary), a site's rooms, and a room's floor plan with racks on 600 mm tiles coloured by their machines; a rack opens its front. Racks are placed by dragging and rotated in an edit mode; unplaced ones are laid out @@ -37,6 +46,11 @@ publish a tag that has no section here. ### Changed - `rollcall ca rotate -yes` (replace the root, racks join again) is gone; the three steps replace it. +### Fixed +- A rack typed in from a machine's location and the same rack from NetBox in another case showed + twice; the layout sync folds it into NetBox's spelling (place, comment and machines follow). +- NetBox paging under a `BASE_PATH` doubled the path on the next page. + ## [0.3.0] - 2026-10-30 Third release: working with a site's existing network services (DNS provider, fixed leases on diff --git a/README.md b/README.md index 1539bab..d6f2cac 100644 --- a/README.md +++ b/README.md @@ -878,6 +878,37 @@ The NetBox user needs `view/add/change/delete` on `dcim.device`, `dcim.devicetype` and `dcim.devicerole`, and `view` on `dcim.location` and `dcim.rack`, on top of the IPAM permissions. +### NetBox's UI through Rollcall + +When NetBox runs under a path (its `BASE_PATH`, e.g. `BASE_PATH = 'netbox/'`) +and `ipam.url` carries it (`"url": "https://netbox.example/netbox/"`), Rollcall +serves NetBox's web UI at that same path, `https:///netbox/`, for +admins only (the admin certificate, as for the API). NetBox keeps its own login. +This opens NetBox wherever Rollcall opens, also when the browser cannot reach +NetBox itself. Two settings on the NetBox side: + +```python +BASE_PATH = 'netbox/' +CSRF_TRUSTED_ORIGINS = ['https://rollcall.example'] # where browsers post from +``` + +The web UI then links to NetBox: the sidebar, a site, room and rack on the Sites +pages, a switch, and a machine's device. `ipam.ui_url` points those links +elsewhere (NetBox reached directly) when that is preferred; a NetBox at the root +of its host gets links to `ui_url` only. + +### Cabling and switches + +`GET /api/v1/cabling` gives each located machine's ports and the switch port +each is plugged into, from the LLDP its commissioning saw (`lldpd` in the +commissioning image). A switch's place is NetBox's (the device with that name, +its rack and position, read with the layout on every reconcile; the NetBox user +needs `view` on `dcim.device`) or set by hand (`POST /api/v1/switches +{"name","building","room","rack","unit"}`, which NetBox does not move; `DELETE +?name=` forgets it). The 3D room draws the backs of the servers, the switches +and the cables; a switch with no place is drawn where most of its cables are, +marked as estimated. + ### Infoblox The same contract over Infoblox WAPI (v2.12 by default; give a full diff --git a/cmd/rollcall/ipam.go b/cmd/rollcall/ipam.go index 3521802..9ecebe5 100644 --- a/cmd/rollcall/ipam.go +++ b/cmd/rollcall/ipam.go @@ -38,7 +38,8 @@ import ( type IPAMConfig struct { Provider string `json:"provider"` // "" = built-in only | netbox | infoblox - URL string `json:"url"` // https://netbox.example + URL string `json:"url"` // https://netbox.example; with NetBox's BASE_PATH (…/netbox/) its UI is served here too (nbproxy.go) + UIURL string `json:"ui_url"` // where "open in NetBox" links go when not through Rollcall TokenFile string `json:"token_file"` // API token (NetBox v2 "nbt_..." or v1) User string `json:"user"` // Infoblox WAPI user PasswordFile string `json:"password_file"` // Infoblox WAPI password @@ -415,7 +416,7 @@ func (a *App) handleIPAM(w http.ResponseWriter, r *http.Request) { a.ipamSt.mu.Lock() last := a.ipamSt.last a.ipamSt.mu.Unlock() - writeJSON(w, 200, obj{"provider": a.ipam.Name(), "url": a.cfg.IPAM.URL, "dns_zone": a.cfg.IPAM.DNSZone, + writeJSON(w, 200, obj{"provider": a.ipam.Name(), "url": a.cfg.IPAM.URL, "ui": a.netboxUILink(), "dns_zone": a.cfg.IPAM.DNSZone, "tag": a.cfg.IPAM.tag(), "machine_field": a.cfg.IPAM.field(), "last_sync": last}) } @@ -537,9 +538,10 @@ func (n *netBox) do(ctx context.Context, method, path string, body, out any) err rd = bytes.NewReader(b) } u := n.base + "/api/" + strings.TrimPrefix(path, "/") - if strings.HasPrefix(path, "http") { // a "next" link: keep our base, the server may name itself differently + if strings.HasPrefix(path, "http") { // a "next" link: keep our scheme and host, the server may name itself differently if p, err := url.Parse(path); err == nil { - u = n.base + p.Path + b, _ := url.Parse(n.base) + u = b.Scheme + "://" + b.Host + p.Path // p.Path has NetBox's BASE_PATH already if p.RawQuery != "" { u += "?" + p.RawQuery } diff --git a/cmd/rollcall/nbproxy.go b/cmd/rollcall/nbproxy.go new file mode 100644 index 0000000..41614eb --- /dev/null +++ b/cmd/rollcall/nbproxy.go @@ -0,0 +1,64 @@ +package main + +// The NetBox web UI through Rollcall, so it opens wherever Rollcall's does +// (a lab NetBox on a network the browser cannot reach, say). With NetBox as +// the IPAM and its url carrying a path (NetBox's BASE_PATH: +// "url": "https://netbox.example/netbox/"), that path on Rollcall is NetBox, +// for admins only (the admin certificate, as for the API). NetBox keeps its +// own login and session. Its CSRF_TRUSTED_ORIGINS must list Rollcall's +// address for its forms to work: the browser posts from there. +// +// ui_url, when set, is where links to NetBox point instead (NetBox reached +// directly); the proxy stays. + +import ( + "net/http" + "net/http/httputil" + "net/url" + "strings" +) + +// netboxUIPath: the path NetBox is served under here ("/netbox"), "" when there is no proxy +func (a *App) netboxUIPath() string { + if _, ok := a.ipam.(*netBox); !ok { + return "" + } + u, err := url.Parse(a.cfg.IPAM.URL) + if err != nil { + return "" + } + p := strings.TrimRight(u.Path, "/") + if p == "" || strings.HasPrefix(p, "/api") || strings.HasPrefix(p, "/rollcall") || strings.HasPrefix(p, "/images") || strings.HasPrefix(p, "/os") { + return "" // NetBox at the root would shadow Rollcall's own paths + } + return p +} + +// netboxUILink: where the UI's "open in NetBox" links go +func (a *App) netboxUILink() string { + if a.cfg.IPAM.UIURL != "" { + return strings.TrimRight(a.cfg.IPAM.UIURL, "/") + } + return a.netboxUIPath() +} + +func (a *App) netboxProxy() http.Handler { + nb := a.ipam.(*netBox) + target, _ := url.Parse(nb.base) + origin := target.Scheme + "://" + target.Host + return &httputil.ReverseProxy{ + Transport: nb.client.Transport, + Rewrite: func(pr *httputil.ProxyRequest) { + pr.Out.URL.Scheme, pr.Out.URL.Host = target.Scheme, target.Host + pr.Out.Host = target.Host + pr.Out.Header.Del("Authorization") // Rollcall's credentials are not NetBox's + pr.SetXForwarded() + }, + ModifyResponse: func(resp *http.Response) error { + if loc := resp.Header.Get("Location"); strings.HasPrefix(loc, origin+"/") { // keep the browser here + resp.Header.Set("Location", strings.TrimPrefix(loc, origin)) + } + return nil + }, + } +} diff --git a/cmd/rollcall/nbproxy_test.go b/cmd/rollcall/nbproxy_test.go new file mode 100644 index 0000000..1a76a42 --- /dev/null +++ b/cmd/rollcall/nbproxy_test.go @@ -0,0 +1,71 @@ +package main + +import ( + "context" + "fmt" + "net/http" + "net/http/httptest" + "testing" +) + +func TestNetBoxUIPath(t *testing.T) { + for url, want := range map[string]string{"https://nb.example/netbox/": "/netbox", "https://nb.example": "", "https://nb.example/api/": "", "http://10.0.0.6/ipam/nb": "/ipam/nb"} { + a := &App{cfg: &Config{IPAM: IPAMConfig{URL: url}}, ipam: &netBox{base: url}} + if got := a.netboxUIPath(); got != want { + t.Errorf("%s: %q, want %q", url, got, want) + } + } + if (&App{cfg: &Config{IPAM: IPAMConfig{URL: "https://x/netbox/"}}}).netboxUIPath() != "" { + t.Error("no NetBox IPAM, no proxy") + } +} + +func TestNetBoxProxy(t *testing.T) { + var seen *http.Request + up := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + seen = r + if r.URL.Path == "/netbox/" { + http.Redirect(w, r, "http://"+r.Host+"/netbox/login/?next=/netbox/", http.StatusFound) // NetBox names itself + return + } + fmt.Fprint(w, "netbox page") + })) + defer up.Close() + a := &App{cfg: &Config{IPAM: IPAMConfig{URL: up.URL + "/netbox/"}}, ipam: &netBox{base: up.URL + "/netbox", client: up.Client()}} + h := a.netboxProxy() + + req := httptest.NewRequest("GET", "https://rollcall.example/netbox/", nil) + req.Header.Set("Authorization", "Bearer rollcall-admin") + rec := httptest.NewRecorder() + h.ServeHTTP(rec, req) + if rec.Code != http.StatusFound || rec.Header().Get("Location") != "/netbox/login/?next=/netbox/" { + t.Fatalf("redirect: %d %q", rec.Code, rec.Header().Get("Location")) + } + if seen.Header.Get("Authorization") != "" { + t.Fatal("Rollcall's credentials went to NetBox") + } + rec = httptest.NewRecorder() + h.ServeHTTP(rec, httptest.NewRequest("GET", "https://rollcall.example/netbox/dcim/sites/?q=lab", nil)) + if rec.Body.String() != "netbox page" || seen.URL.RequestURI() != "/netbox/dcim/sites/?q=lab" || seen.Header.Get("X-Forwarded-Host") != "rollcall.example" { + t.Fatalf("page: %q %s %q", rec.Body.String(), seen.URL.RequestURI(), seen.Header.Get("X-Forwarded-Host")) + } +} + +// a NetBox under a BASE_PATH names its next pages with that path: it must not be doubled +func TestNetBoxNextLinkBasePath(t *testing.T) { + var paths []string + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + paths = append(paths, r.URL.Path) + if r.URL.Query().Get("offset") == "" { + fmt.Fprintf(w, `{"results": [{"id": 1}], "next": "http://elsewhere%s?limit=500&offset=500"}`, r.URL.Path) + return + } + fmt.Fprint(w, `{"results": [{"id": 2}], "next": null}`) + })) + defer srv.Close() + n := &netBox{base: srv.URL + "/netbox", token: "t", client: srv.Client()} + got, err := n.all(context.Background(), "dcim/sites/", nil) + if err != nil || len(got) != 2 || paths[1] != "/netbox/api/dcim/sites/" { + t.Fatalf("%v %d %v", err, len(got), paths) + } +} diff --git a/cmd/rollcall/server.go b/cmd/rollcall/server.go index e3d50c9..2f78b9f 100644 --- a/cmd/rollcall/server.go +++ b/cmd/rollcall/server.go @@ -287,6 +287,9 @@ func (a *App) routes() http.Handler { mux.HandleFunc("DELETE /api/v1/racks", a.adminAuth(a.handleRacks)) mux.HandleFunc("POST /api/v1/racks/positions", a.adminAuth(a.handleRackPositions)) mux.HandleFunc("GET /api/v1/cabling", a.adminAuth(a.handleCabling)) + if p := a.netboxUIPath(); p != "" { + mux.Handle(p+"/", a.adminAuth(a.netboxProxy().ServeHTTP)) + } mux.HandleFunc("POST /api/v1/switches", a.adminAuth(a.handleSwitches)) mux.HandleFunc("DELETE /api/v1/switches", a.adminAuth(a.handleSwitches)) mux.HandleFunc("GET /api/v1/sites", a.adminAuth(a.handleSites)) diff --git a/cmd/rollcall/web/app.js b/cmd/rollcall/web/app.js index ad91376..91d1f62 100644 --- a/cmd/rollcall/web/app.js +++ b/cmd/rollcall/web/app.js @@ -2,6 +2,12 @@ // Rollcall web UI: a fleet view first (filters, selection, bulk actions), machine detail second. const $ = (s, el = document) => el.querySelector(s); const $$ = (s, el = document) => Array.from(el.querySelectorAll(s)); +// nbLink: "open in NetBox" for a NetBox page (path and query), when NetBox is the IPAM +function nbLink(path, label = 'NetBox ↗') { + const ui = S.ipam && S.ipam.provider === 'netbox' && S.ipam.ui; + return ui ? `${esc(label)}` : ''; +} +const nbQ = o => '?' + new URLSearchParams(Object.entries(o).filter(([, v]) => v)).toString(); const esc = s => String(s ?? '').replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c])); const human = n => { n = Number(n || 0); const u = ['B', 'K', 'M', 'G', 'T', 'P']; let i = 0; while (n >= 1024 && i < u.length - 1) { n /= 1024; i++; } return (i <= 2 ? n.toFixed(0) : n.toFixed(1)) + u[i]; }; const ago = ts => { if (!ts) return '-'; const s = (Date.now() - new Date(ts)) / 1000; if (s < 90) return `${s | 0}s`; if (s < 5400) return `${(s / 60) | 0}m`; if (s < 172800) return `${(s / 3600) | 0}h`; return `${(s / 86400) | 0}d`; }; @@ -82,6 +88,7 @@ async function refresh(full) { [S.ips, S.ipam] = await Promise.all([api('GET', '/api/v1/ips'), api('GET', '/api/v1/ipam').catch(() => null)]); } $('#n-machines').textContent = machines.length; + const nb = $('#nav-netbox'), ui = S.ipam && S.ipam.provider === 'netbox' && S.ipam.ui; nb.hidden = !ui; if (ui) nb.href = ui + '/'; const active = S.jobs.filter(j => j.state === 'pending' || j.state === 'running').length; $('#n-jobs').textContent = active ? `${active} active` : ''; $('#status').textContent = `updated ${new Date().toLocaleTimeString()}`; @@ -513,7 +520,7 @@ function pageMachine(d, tab) { const hasJob = !!s.job; return ` -
← Machines

${esc(nameOf(s))}

${pill(s.state)}${esc(s.id)} +
← Machines

${esc(nameOf(s))}

${pill(s.state)}${esc(s.id)}${nbLink('/dcim/devices/' + nbQ({ ['cf_' + ((S.ipam || {}).machine_field || 'rollcall_machine')]: s.id }), 'NetBox device ↗')}
${menuBtn('Power', [['status', 'Status'], ['on', 'Power on'], ['off', 'Power off'], ['soft', 'Soft off'], ['cycle', 'Power cycle'], ['reset', 'Reset']], 'dpower')} ${menuBtn('Boot device', [['pxe', 'PXE'], ['disk', 'Disk'], ['bios', 'BIOS setup'], ['cdrom', 'CD-ROM']], 'dboot')} diff --git a/cmd/rollcall/web/index.html b/cmd/rollcall/web/index.html index 7999d5a..16e2cb6 100644 --- a/cmd/rollcall/web/index.html +++ b/cmd/rollcall/web/index.html @@ -19,6 +19,7 @@ Tags Profiles OS images +
diff --git a/cmd/rollcall/web/sites.js b/cmd/rollcall/web/sites.js index 443994b..dc1ead4 100644 --- a/cmd/rollcall/web/sites.js +++ b/cmd/rollcall/web/sites.js @@ -66,7 +66,7 @@ function pageSites() { const st = siteStats(s); const where = s.lat != null ? `${s.lat.toFixed(4)}, ${s.lon.toFixed(4)}` : 'not on the map'; return [`${esc(s.name)}${s.address ? `
${esc(s.address)}` : ''}`, - `${esc(s.source)}`, st.rooms.filter(Boolean).length || '—', st.racks.length, st.ms.length, + `${esc(s.source)}${s.source === 'netbox' ? ' ' + nbLink('/dcim/sites/' + nbQ({ slug: s.slug || '', name: s.slug ? '' : s.name }), '↗') : ''}`, st.rooms.filter(Boolean).length || '—', st.racks.length, st.ms.length, `${esc(groupLine(Object.fromEntries(st.ms.map(m => [m.state, st.ms.filter(x => x.state === m.state).length])), 40) || '—')}`, where, ``]; }); @@ -141,7 +141,7 @@ function pageSite(name) {
${racks.length} racks · ${ms.length} machines${bad ? ` · ${bad} failed` : ''}
`; }); return `

Sites / ${esc(site.name)}

${esc(site.address || '')} · ${st.racks.length} racks · ${st.ms.length} machines -
+
${site.source === 'netbox' ? nbLink('/dcim/sites/' + nbQ({ slug: site.slug || '', name: site.slug ? '' : site.name })) : ''}
${cards.length ? `
${cards.join('')}
` : '
No rooms or racks here yet: add a room, or set machines\' location to this site.
'}`; } function wireSite(name) { @@ -213,7 +213,8 @@ function pageRoom(siteName, roomArg) { const racks = racksOnFloor(site, room); const autoN = racks.filter(r => r.auto).length, v3 = !SITE.edit && roomView.get() === '3d'; const selRack = racks.find(r => r.name === SITE.sel); - const panel = selRack ? `

${esc(selRack.name)} ${selRack.height}U · front ${({ N: 'north', S: 'south', E: 'east', W: 'west' })[selRack.facing]}

+ const nbSite = (siteOf(site.name) || {}).slug || ''; + const panel = selRack ? `

${esc(selRack.name)} ${selRack.height}U · front ${({ N: 'north', S: 'south', E: 'east', W: 'west' })[selRack.facing]} ${nbLink('/dcim/racks/' + nbQ({ name: selRack.name, site: nbSite }))}

${SITE.edit ? `
` : ''} ${rackElev(selRack)}${cablingTable(site, selRack)}
` : `
Click a rack for its front.${autoN ? `

${autoN} rack(s) have no place yet and are laid out automatically (${v3 ? 'see-through' : 'dashed'}): Edit layout to place them.` : ''}
${v3 ? switchTable() : ''}
`; @@ -221,7 +222,7 @@ function pageRoom(siteName, roomArg) { : `emptythick edge: the front · bar: units used${SITE.edit ? ' · drag to move, select and Rotate' : ''}`; return `

Sites / ${esc(site.name)} / ${esc(room || '(no room)')}

${racks.length} racks · floor tiles of 600 mm -
${SITE.edit ? '' +
${room ? nbLink('/dcim/locations/' + nbQ({ name: room, site: nbSite })) : ''}${SITE.edit ? '' : `${v3 ? `` : ''}`}
${v3 ? '
' : floorSVG(site, room)}
deployed / readybusy / newfailed${legend}
${panel}
`; @@ -314,7 +315,7 @@ function switchTable() { const sws = (typeof R3 !== 'undefined' && R3.switches) || []; if (!sws.length) return ''; const where = s => s.away ? `in ${esc(s.away)}` : s.at ? `${esc(rackLabel(s.at.rack))} U${s.at.unit}${s.at.estimated ? ' estimated' : ` ${esc(s.source)}`}` : ''; return `

Switches

${sws.map(s => `
-
${esc(s.name)}${s.model ? ` ${esc(s.model)}` : ''}
${where(s)} · ${s.here} cables
+
${esc(s.name)}${s.model ? ` ${esc(s.model)}` : ''} ${s.source === 'netbox' ? nbLink('/dcim/devices/' + nbQ({ name: s.name }), '↗') : ''}
${where(s)} · ${s.here} cables
`).join('')}

A switch's place comes from NetBox (its rack and position) or is set here; without either it is drawn where most of its cables are.

`; } diff --git a/cmd/rollcall/web/style.css b/cmd/rollcall/web/style.css index 88f8673..8eb86bf 100644 --- a/cmd/rollcall/web/style.css +++ b/cmd/rollcall/web/style.css @@ -239,3 +239,5 @@ svg.floor .rk text { font-size: 9px; fill: var(--fg); pointer-events: none; font .r3-tip { position: absolute; pointer-events: none; background: var(--panel); border: 1px solid var(--line2); border-radius: 6px; padding: 4px 8px; font-size: 12px; white-space: nowrap; box-shadow: 0 4px 14px rgba(0,0,0,.18); } .sw-list { display: grid; gap: 6px; } .sw-row { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; gap: 8px; align-items: center; } .sw-row > div { min-width: 0; overflow-wrap: anywhere; } .sw-dot { width: 10px; height: 10px; border-radius: 2px; display: inline-block; } +.nb-link { font-size: 12px; font-weight: 400; text-transform: none; letter-spacing: 0; white-space: nowrap; align-self: center; } +.page-head .right .nb-link { margin-right: 6px; } diff --git a/lab/netbox/install.sh b/lab/netbox/install.sh index 5665b7f..5174e0a 100644 --- a/lab/netbox/install.sh +++ b/lab/netbox/install.sh @@ -3,6 +3,9 @@ # container on the lab segment, so tests never write to a real NetBox. # Same install as netops (altyapi hosts/netops/kurulum.sh) without PowerDNS, # ACME and backups; plain HTTP on :80 (the segment is isolated). +# NetBox lives under /netbox/ (BASE_PATH) so the region can serve its UI +# through Rollcall (cmd/rollcall/nbproxy.go): Rollcall's ipam url is then +# http://$MYIP/netbox/, and ROLLCALL_ORIGINS are where browsers post from. # # Run as root inside the container; rerunnable. Secrets are generated here: # /etc/lab-netbox/secrets.env (admin password, Rollcall's API token) @@ -16,6 +19,7 @@ set -euo pipefail NETBOX_VERSION=${NETBOX_VERSION:-4.7.4} MYIP=${MYIP:-10.213.77.6} SITE=${SITE:-lab} +ROLLCALL_ORIGINS=${ROLLCALL_ORIGINS:-"https://10.0.0.234 https://10.213.77.1"} PREFIXES=${PREFIXES:-"10.213.77.0/24 10.213.78.0/24 10.213.79.0/24 fd00:213:77::/64 fd00:213:78::/64"} export DEBIAN_FRONTEND=noninteractive @@ -69,7 +73,8 @@ REDIS = { SECRET_KEY = '$NETBOX_SECRET_KEY' API_TOKEN_PEPPERS = {1: '$NETBOX_PEPPER'} TIME_ZONE = 'Europe/Stockholm' -CSRF_TRUSTED_ORIGINS = ['http://$MYIP'] +BASE_PATH = 'netbox/' +CSRF_TRUSTED_ORIGINS = ['http://$MYIP'$(for o in $ROLLCALL_ORIGINS; do printf ", '%s'" "$o"; done)] EOF chown -R netbox:netbox $D/netbox/media $D/netbox/reports $D/netbox/scripts 2>/dev/null || true cd /opt/netbox && PYTHON=/usr/bin/python3 ./upgrade.sh >/var/log/netbox-upgrade.log 2>&1 || { tail -40 /var/log/netbox-upgrade.log; exit 1; } @@ -84,7 +89,8 @@ systemctl restart netbox netbox-rq cat > /etc/caddy/Caddyfile <