Added a new parameter authDataBaseInit for initializing the openvpn user database, added the DB initialization function and its call when initializing the ovpn-admin server if the auth.db-init flag is true
This commit is contained in:
parent
f9afd195c0
commit
2ed4fdb369
1 changed files with 12 additions and 0 deletions
12
main.go
12
main.go
|
@ -72,6 +72,7 @@ var (
|
|||
ccdTemplatePath = kingpin.Flag("templates.ccd-path", "path to custom ccd.tpl").Default("").Envar("OVPN_TEMPLATES_CCD_PATH").String()
|
||||
authByPassword = kingpin.Flag("auth.password", "enable additional password authentication").Default("false").Envar("OVPN_AUTH").Bool()
|
||||
authDatabase = kingpin.Flag("auth.db", "database path for password authentication").Default("./easyrsa/pki/users.db").Envar("OVPN_AUTH_DB_PATH").String()
|
||||
authDataBaseInit = kingpin.Flag("auth.db-init", "enable database initialization if db user not exists or size is 0").Default("false").Envar("OVPN_AUTH_DB_INIT").Bool()
|
||||
logLevel = kingpin.Flag("log.level", "set log level: trace, debug, info, warn, error (default info)").Default("info").Envar("LOG_LEVEL").String()
|
||||
logFormat = kingpin.Flag("log.format", "set log format: text, json (default text)").Default("text").Envar("LOG_FORMAT").String()
|
||||
storageBackend = kingpin.Flag("storage.backend", "storage backend: filesystem, kubernetes.secrets (default filesystem)").Default("filesystem").Envar("STORAGE_BACKEND").String()
|
||||
|
@ -505,6 +506,10 @@ func main() {
|
|||
*indexTxtPath = *easyrsaDirPath + "/pki/index.txt"
|
||||
}
|
||||
|
||||
if *authDataBaseInit {
|
||||
ovpnUserInitDb()
|
||||
}
|
||||
|
||||
ovpnAdmin := new(OvpnAdmin)
|
||||
|
||||
ovpnAdmin.lastSyncTime = "unknown"
|
||||
|
@ -1502,6 +1507,13 @@ func unArchiveCcd() {
|
|||
}
|
||||
}
|
||||
|
||||
func ovpnUserInitDb() {
|
||||
if fi, err := os.Stat(*authDatabase); errors.Is(err, os.ErrNotExist) || fi.Size() == 0 {
|
||||
i := runBash(fmt.Sprintf("openvpn-user --db.path %[1]s db-init && openvpn-user --db.path %[1]s db-migrate", *authDatabase))
|
||||
log.Debug(i)
|
||||
}
|
||||
}
|
||||
|
||||
func (oAdmin *OvpnAdmin) syncDataFromMaster() {
|
||||
retryCountMax := 3
|
||||
certsDownloadFailed := true
|
||||
|
|
Loading…
Reference in a new issue