mirror of
https://github.com/h44z/wg-portal.git
synced 2025-08-25 14:31:14 +00:00
wip: dockerfile
This commit is contained in:
@@ -79,6 +79,11 @@ type Server struct {
|
||||
}
|
||||
|
||||
func (s *Server) Setup() error {
|
||||
dir := s.getExecutableDirectory()
|
||||
rDir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
|
||||
log.Infof("Real working directory: %s", rDir)
|
||||
log.Infof("Current working directory: %s", dir)
|
||||
|
||||
// Init rand
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
|
||||
@@ -102,7 +107,7 @@ func (s *Server) Setup() error {
|
||||
}
|
||||
|
||||
// Setup user manager
|
||||
if s.users = NewUserManager(s.wg, s.ldapUsers); s.users == nil {
|
||||
if s.users = NewUserManager(filepath.Join(dir, s.config.Core.DatabasePath), s.wg, s.ldapUsers); s.users == nil {
|
||||
return errors.New("unable to setup user manager")
|
||||
}
|
||||
if err := s.users.InitFromCurrentInterface(); err != nil {
|
||||
@@ -112,10 +117,7 @@ func (s *Server) Setup() error {
|
||||
return errors.New("unable to restore wirguard state")
|
||||
}
|
||||
|
||||
dir := s.getExecutableDirectory()
|
||||
rDir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
|
||||
log.Infof("Real working directory: %s", rDir)
|
||||
log.Infof("Current working directory: %s", dir)
|
||||
// Setup mail template
|
||||
var err error
|
||||
s.mailTpl, err = template.New("email.html").ParseFiles(filepath.Join(dir, "/assets/tpl/email.html"))
|
||||
if err != nil {
|
||||
|
@@ -6,6 +6,8 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"sort"
|
||||
@@ -281,12 +283,19 @@ type UserManager struct {
|
||||
ldapUsers *ldap.SynchronizedUserCacheHolder
|
||||
}
|
||||
|
||||
func NewUserManager(wg *wireguard.Manager, ldapUsers *ldap.SynchronizedUserCacheHolder) *UserManager {
|
||||
func NewUserManager(dbPath string, wg *wireguard.Manager, ldapUsers *ldap.SynchronizedUserCacheHolder) *UserManager {
|
||||
|
||||
um := &UserManager{wg: wg, ldapUsers: ldapUsers}
|
||||
var err error
|
||||
um.db, err = gorm.Open(sqlite.Open("wg_portal.db"), &gorm.Config{})
|
||||
if _, err = os.Stat(filepath.Dir(dbPath)); os.IsNotExist(err) {
|
||||
if err = os.MkdirAll(filepath.Dir(dbPath), 0700); err != nil {
|
||||
log.Errorf("failed to create database directory (%s): %v", filepath.Dir(dbPath), err)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
um.db, err = gorm.Open(sqlite.Open(dbPath), &gorm.Config{})
|
||||
if err != nil {
|
||||
log.Errorf("failed to open sqlite database: %v", err)
|
||||
log.Errorf("failed to open sqlite database (%s): %v", dbPath, err)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user