Keep dist/navis-release/ path and ship Navis.exe as a same-hash alias of EvilFox.exe so 3.x clients can still update from the Windows branch feed.
52 lines
1.4 KiB
Go
52 lines
1.4 KiB
Go
package remnawave
|
||
|
||
// Centralized (NordVPN-style) provisioning: the panel address and API token
|
||
// are baked into the binary at build time, so every user gets configs
|
||
// automatically and cannot change the panel.
|
||
//
|
||
// build.bat copies configs/remnawave-api.json into embeddedcfg/ before
|
||
// `go build`; the copy is gitignored so credentials never land in the repo.
|
||
// Without the embedded file the app falls back to the external
|
||
// configs/remnawave-api.json (developer mode).
|
||
|
||
import (
|
||
"crypto/rand"
|
||
"embed"
|
||
"encoding/hex"
|
||
"fmt"
|
||
"os"
|
||
"time"
|
||
)
|
||
|
||
//go:embed embeddedcfg
|
||
var embeddedCfgFS embed.FS
|
||
|
||
// EmbeddedAdminConfig returns the admin config baked into the binary,
|
||
// or nil when this build has no embedded credentials.
|
||
func EmbeddedAdminConfig() *AdminConfig {
|
||
data, err := embeddedCfgFS.ReadFile("embeddedcfg/remnawave-api.json")
|
||
if err != nil {
|
||
return nil
|
||
}
|
||
cfg, err := parseAdminConfig(data)
|
||
if err != nil {
|
||
return nil
|
||
}
|
||
return cfg
|
||
}
|
||
|
||
// GenerateUsername makes a unique panel username for silent auto-provisioning
|
||
// (users never type anything): "fox_" + 10 hex chars, e.g. fox_3fa9c02b71.
|
||
func GenerateUsername() string {
|
||
var b [5]byte
|
||
if _, err := rand.Read(b[:]); err != nil {
|
||
// Keep within Remnawave's 6–34 char username limit.
|
||
s := fmt.Sprintf("fox_%x%x", os.Getpid()&0xffff, time.Now().UnixNano()&0xffffffff)
|
||
if len(s) > 34 {
|
||
s = s[:34]
|
||
}
|
||
return s
|
||
}
|
||
return "fox_" + hex.EncodeToString(b[:])
|
||
}
|