feat: per-site SSL email and error display

This commit is contained in:
orohi
2026-06-17 06:05:34 +03:00
parent 02201fb4e3
commit f2c05d15ec
9 changed files with 151 additions and 59 deletions
+20 -2
View File
@@ -6,6 +6,7 @@ import (
"net/http"
"strconv"
"github.com/panelhosting/panel/internal/auth"
"github.com/panelhosting/panel/internal/middleware"
"github.com/panelhosting/panel/internal/sitesvc"
)
@@ -22,10 +23,15 @@ type createSiteRequest struct {
Name string `json:"name"`
Domain string `json:"domain"`
PHPVersion string `json:"php_version"`
SSLEmail string `json:"ssl_email"`
ServerID int64 `json:"server_id,omitempty"`
IssueSSL *bool `json:"issue_ssl"`
}
type reissueSSLRequest struct {
SSLEmail string `json:"ssl_email"`
}
func (h *SiteHandler) List(w http.ResponseWriter, r *http.Request) {
user, ok := middleware.UserFromContext(r.Context())
if !ok {
@@ -63,6 +69,7 @@ func (h *SiteHandler) Create(w http.ResponseWriter, r *http.Request) {
Name: req.Name,
Domain: req.Domain,
PHPVersion: req.PHPVersion,
SSLEmail: req.SSLEmail,
ServerID: req.ServerID,
OwnerID: user.ID,
IsAdmin: middleware.IsAdmin(user),
@@ -72,7 +79,9 @@ func (h *SiteHandler) Create(w http.ResponseWriter, r *http.Request) {
switch {
case errors.Is(err, sitesvc.ErrInvalidSiteName),
errors.Is(err, sitesvc.ErrInvalidDomain),
errors.Is(err, sitesvc.ErrInvalidPHPVersion):
errors.Is(err, sitesvc.ErrInvalidPHPVersion),
errors.Is(err, sitesvc.ErrInvalidSSLEmail),
errors.Is(err, sitesvc.ErrSSLEmailRequired):
writeError(w, http.StatusBadRequest, err.Error())
default:
writeError(w, http.StatusInternalServerError, "failed to create site: "+err.Error())
@@ -105,6 +114,15 @@ func (h *SiteHandler) ReissueSSL(w http.ResponseWriter, r *http.Request) {
return
}
h.svc.ReissueSSLAsync(siteID)
var req reissueSSLRequest
_ = json.NewDecoder(r.Body).Decode(&req)
if req.SSLEmail != "" {
if err := auth.ValidateEmail(req.SSLEmail); err != nil {
writeError(w, http.StatusBadRequest, "invalid ssl email")
return
}
}
h.svc.ReissueSSLAsync(siteID, req.SSLEmail)
writeJSON(w, http.StatusOK, map[string]string{"message": "ssl issuance started"})
}