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

97
main.go
View File

@@ -4,13 +4,14 @@ import (
"context"
"fmt"
"os"
"regexp"
"sync"
"github.com/spf13/cobra"
)
var version = "1.0.0"
var build = "2"
var build = "1"
var (
configFile string
@@ -19,6 +20,8 @@ var (
wg sync.WaitGroup
)
var fqdnRegex = regexp.MustCompile(`^(?i:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,}$`)
//TODO create logic for gh vs gt repos
func main() {
@@ -33,9 +36,9 @@ func main() {
rootCmd.PersistentFlags().StringVarP(&configFile, "config", "c", "/etc/certman/certman.conf", "Configuration file")
rootCmd.AddCommand(basicCmd("version", "Show version", versionCmd))
rootCmd.AddCommand(basicCmd("gen-key", "Generates encryption key", newKeyCmd))
rootCmd.AddCommand(basicCmd("dev", "Dev Function", devCmd))
rootCmd.AddCommand(basicCmd("version", "Show version", versionResponse))
rootCmd.AddCommand(basicCmd("gen-key", "Generates encryption key", newKey))
rootCmd.AddCommand(basicCmd("dev", "Dev Function", devFunc))
var domainCertDir string
newDomainCmd := &cobra.Command{
@@ -72,6 +75,28 @@ func main() {
installCmd.Flags().BoolVarP(&thinInstallFlag, "thin", "t", false, "Thin install (skip creating dirs)")
rootCmd.AddCommand(installCmd)
certCmd := &cobra.Command{
Use: "cert",
Short: "Certificate management",
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
}
var noPush bool
renewCertCmd := &cobra.Command{
Use: "renew",
Short: "Renews a domains certificate",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return renewCertFunc(args[0], noPush)
},
}
renewCertCmd.Flags().BoolVar(&noPush, "no-push", false, "Don't push certs to repo, renew locally only [server mode only]")
certCmd.AddCommand(renewCertCmd)
rootCmd.AddCommand(certCmd)
daemonCmd := &cobra.Command{
Use: "daemon",
Short: "Daemon management",
@@ -85,7 +110,7 @@ func main() {
Short: "Start the daemon",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return runDaemonCmd()
return runDaemon()
},
})
@@ -94,7 +119,7 @@ func main() {
Short: "Stop the daemon",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return stopDaemonCmd()
return stopDaemon()
},
})
@@ -103,7 +128,16 @@ func main() {
Short: "Reload daemon configs",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return reloadDaemonCmd()
return reloadDaemon()
},
})
daemonCmd.AddCommand(&cobra.Command{
Use: "tick",
Short: "Manually triggers daemon tick",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return tickDaemon()
},
})
@@ -112,7 +146,7 @@ func main() {
Short: "Show daemon status",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return statusDaemonCmd()
return statusDaemon()
},
})
@@ -132,47 +166,6 @@ func basicCmd(use, short string, commandFunc func(cmd *cobra.Command, args []str
}
}
// case "gen":
// {
// url := createGiteaRepo(domain)
// if url == "" {
// return
// }
// gitWorkspace.Repo, gitWorkspace.WorkTree = cloneRepo(url, gitWorkspace)
// if gitWorkspace.Repo == nil {
// return
// }
// cmd = exec.Command("lego", legoNewSiteArgs...)
// }
// case "renew":
// {
// gitWorkspace.Repo, gitWorkspace.WorkTree = cloneRepo(config.GetAsString("Git.server")+"/"+config.GetAsString("Git.org_name")+"/"+domain+"-certificates.git", gitWorkspace)
// if gitWorkspace.Repo == nil {
// return
// }
// cmd = exec.Command("lego", legoRenewSiteArgs...)
// }
// case "gen-cert-only":
// {
// cmd = exec.Command("lego", legoNewSiteArgs...)
// }
// case "renew-cert-only":
// {
// cmd = exec.Command("lego", legoRenewSiteArgs...)
// }
// case "git":
// {
// url := createGiteaRepo(domain)
// if url == "" {
// return
// }
// gitWorkspace.Repo, gitWorkspace.WorkTree = cloneRepo(url, gitWorkspace)
// if gitWorkspace.Repo == nil {
// return
// }
// err := addAndPushCerts(domain, gitWorkspace)
// if err != nil {
// return
// }
// os.Exit(0)
// }
func IsValidFQDN(domain string) bool {
return len(domain) <= 253 && fqdnRegex.MatchString(domain)
}