Moved from ini to toml, fixed installation and new-domain permissions issues

This commit is contained in:
2026-02-27 12:51:54 +01:00
parent f4878e48d4
commit 2e52eae151
10 changed files with 683 additions and 305 deletions

35
util.go
View File

@@ -3,6 +3,7 @@ package main
import (
"errors"
"fmt"
"io/fs"
"os"
"path/filepath"
"strconv"
@@ -15,9 +16,9 @@ import (
)
var (
ErrorPIDInUse = errors.New("daemon is already running")
ErrLockFailed = errors.New("failed to acquire a lock on the PID file")
ErrRepoNotInit = errors.New("repo not initialized")
ErrorPIDInUse = errors.New("daemon is already running")
ErrLockFailed = errors.New("failed to acquire a lock on the PID file")
ErrBlankCert = errors.New("cert is blank")
)
type Domain struct {
@@ -208,10 +209,22 @@ func createFile(fileName string, filePermission os.FileMode, data []byte) {
}
}
func linkFile(source, target string) error {
err := os.Symlink(source, target)
func linkFile(source, target, domain, extension string) error {
if target == "" {
return ErrBlankCert
}
linkInfo, err := os.Stat(target)
if err != nil {
if !os.IsNotExist(err) {
return err
}
}
if linkInfo.IsDir() {
target = filepath.Join(target, domain+extension)
}
err = os.Symlink(source, target)
if err != nil {
fmt.Println("Error creating symlink:", err)
return err
}
return nil
@@ -269,3 +282,13 @@ func getDomainCertsDirWOnlyConf(domainConfig *viper.Viper) (string, error) {
domain := domainConfig.GetString("Domain.domain_name")
return getDomainCertsDirWConf(domain, domainConfig)
}
func ChownRecursive(path string, uid, gid int) error {
return filepath.WalkDir(path, func(name string, d fs.DirEntry, err error) error {
if err != nil {
return err // Stop if we encounter a permission error on a specific file
}
// Apply ownership change to the current item
return os.Chown(name, uid, gid)
})
}