Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ var createDomainCmd = &cobra.Command{
}
}

enableSSL, _ := cmd.Flags().GetBool("ssl")
if enableSSL && (serverType == "apache" || serverType == "nginx") {
err := internal.EnableSSLCertbot(domain, serverType)
if err != nil {
logger.Error(fmt.Sprintf("SSL setup failed: %v", err))
os.Exit(1)
}
}

logger.Success(fmt.Sprintf("%s configuration created and enabled for %s on port %s", serverType, domain, port))
},
}
Expand All @@ -193,6 +202,7 @@ func init() {
createDomainCmd.Flags().Bool("useridr", false, "Create user directory /home/<user>/public_html")
createDomainCmd.Flags().StringP("port", "p", "80", "Port for the configuration (default: 80)")
createDomainCmd.Flags().StringP("server", "s", "apache", "Web server type (e.g., apache, nginx, caddy)")
createDomainCmd.Flags().Bool("ssl", false, "Enable Let's Encrypt SSL (Apache/Nginx only)")
createDomainCmd.MarkFlagRequired("name")
}

Expand Down Expand Up @@ -277,4 +287,4 @@ func writeConfigFile(domain, content, extension string) error {

logger.Success(fmt.Sprintf("Configuration file written to %s", outputPath))
return nil
}
}
27 changes: 27 additions & 0 deletions internal/ssl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package internal

import (
"fmt"
"stackroost/internal/logger"
)

func EnableSSLCertbot(domain string, serverType string) error {
logger.Info(fmt.Sprintf("Requesting SSL certificate for %s using Certbot", domain))

cmd := []string{
fmt.Sprintf("--%s", serverType),
"-d", domain,
"-d", "www." + domain,
"--non-interactive",
"--agree-tos",
"--register-unsafely-without-email",
}

err := RunCommand("sudo", append([]string{"certbot"}, cmd...)...)
if err != nil {
return fmt.Errorf("certbot SSL generation failed: %v", err)
}

logger.Success(fmt.Sprintf("SSL certificate installed for %s", domain))
return nil
}