mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-05-03 22:02:23 +03:00
fix: set random session secret if not set (#417)
This commit is contained in:
parent
364a43e3dc
commit
b55543f424
2 changed files with 12 additions and 1 deletions
2
main.go
2
main.go
|
@ -38,7 +38,7 @@ var (
|
|||
flagSendgridApiKey string
|
||||
flagEmailFrom string
|
||||
flagEmailFromName string = "WireGuard UI"
|
||||
flagSessionSecret string
|
||||
flagSessionSecret string = util.RandomString(32)
|
||||
flagWgConfTemplate string
|
||||
flagBasePath string
|
||||
)
|
||||
|
|
11
util/util.go
11
util/util.go
|
@ -9,6 +9,7 @@ import (
|
|||
"io"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"net"
|
||||
"os"
|
||||
"path"
|
||||
|
@ -529,3 +530,13 @@ func UpdateHashes(db store.IStore) error {
|
|||
clientServerHashes.Client, clientServerHashes.Server = GetCurrentHash(db)
|
||||
return db.SaveHashes(clientServerHashes)
|
||||
}
|
||||
|
||||
func RandomString(length int) string {
|
||||
var seededRand = rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
charset := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
b := make([]byte, length)
|
||||
for i := range b {
|
||||
b[i] = charset[seededRand.Intn(len(charset))]
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue