2022-11-11 09:41:39 +00:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
2023-11-28 09:27:31 +00:00
|
|
|
"net/http"
|
|
|
|
"net/url"
|
2023-01-04 14:31:51 +00:00
|
|
|
"reflect"
|
2023-11-28 09:27:31 +00:00
|
|
|
"strconv"
|
2023-01-04 14:31:51 +00:00
|
|
|
|
2022-11-11 09:41:39 +00:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
2022-12-14 07:26:51 +00:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
|
2022-11-11 09:41:39 +00:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags Website SSL
|
2023-01-05 03:57:03 +00:00
|
|
|
// @Summary Page website ssl
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Description 获取网站 ssl 列表分页
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body request.WebsiteSSLSearch true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /websites/ssl/search [post]
|
2022-11-11 09:41:39 +00:00
|
|
|
func (b *BaseApi) PageWebsiteSSL(c *gin.Context) {
|
2022-12-14 07:26:51 +00:00
|
|
|
var req request.WebsiteSSLSearch
|
2023-10-31 13:59:39 +00:00
|
|
|
if err := helper.CheckBind(&req, c); err != nil {
|
2022-11-11 09:41:39 +00:00
|
|
|
return
|
|
|
|
}
|
2022-11-20 10:32:56 +00:00
|
|
|
if !reflect.DeepEqual(req.PageInfo, dto.PageInfo{}) {
|
|
|
|
total, accounts, err := websiteSSLService.Page(req)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, dto.PageResult{
|
|
|
|
Total: total,
|
|
|
|
Items: accounts,
|
|
|
|
})
|
|
|
|
} else {
|
2023-07-04 08:14:11 +00:00
|
|
|
list, err := websiteSSLService.Search(req)
|
2022-11-20 10:32:56 +00:00
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, list)
|
2022-11-11 09:41:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags Website SSL
|
|
|
|
// @Summary Create website ssl
|
|
|
|
// @Description 创建网站 ssl
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body request.WebsiteSSLCreate true "request"
|
|
|
|
// @Success 200 {object} request.WebsiteSSLCreate
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /websites/ssl [post]
|
2023-10-07 07:46:44 +00:00
|
|
|
// @x-panel-log {"bodyKeys":["primaryDomain"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"创建网站 ssl [primaryDomain]","formatEN":"Create website ssl [primaryDomain]"}
|
2022-11-16 02:31:35 +00:00
|
|
|
func (b *BaseApi) CreateWebsiteSSL(c *gin.Context) {
|
2022-12-14 07:26:51 +00:00
|
|
|
var req request.WebsiteSSLCreate
|
2023-10-27 04:04:11 +00:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2022-11-16 02:31:35 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
res, err := websiteSSLService.Create(req)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, res)
|
|
|
|
}
|
|
|
|
|
2023-11-20 02:44:10 +00:00
|
|
|
// @Tags Website SSL
|
|
|
|
// @Summary Apply ssl
|
|
|
|
// @Description 申请证书
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body request.WebsiteSSLApply true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /websites/ssl/obtain [post]
|
|
|
|
// @x-panel-log {"bodyKeys":["ID"],"paramKeys":[],"BeforeFunctions":[{"input_column":"id","input_value":"ID","isList":false,"db":"website_ssls","output_column":"primary_domain","output_value":"domain"}],"formatZH":"申请证书 [domain]","formatEN":"apply ssl [domain]"}
|
|
|
|
func (b *BaseApi) ApplyWebsiteSSL(c *gin.Context) {
|
|
|
|
var req request.WebsiteSSLApply
|
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := websiteSSLService.ObtainSSL(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithOutData(c)
|
|
|
|
}
|
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags Website SSL
|
|
|
|
// @Summary Resolve website ssl
|
|
|
|
// @Description 解析网站 ssl
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body request.WebsiteDNSReq true "request"
|
2023-07-06 10:04:22 +00:00
|
|
|
// @Success 200 {array} response.WebsiteDNSRes
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /websites/ssl/resolve [post]
|
2022-11-16 02:31:35 +00:00
|
|
|
func (b *BaseApi) GetDNSResolve(c *gin.Context) {
|
2022-12-14 07:26:51 +00:00
|
|
|
var req request.WebsiteDNSReq
|
2023-10-27 04:04:11 +00:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2022-11-16 02:31:35 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
res, err := websiteSSLService.GetDNSResolve(req)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, res)
|
|
|
|
}
|
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags Website SSL
|
|
|
|
// @Summary Delete website ssl
|
|
|
|
// @Description 删除网站 ssl
|
|
|
|
// @Accept json
|
2023-11-27 09:00:09 +00:00
|
|
|
// @Param request body request.WebsiteBatchDelReq true "request"
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /websites/ssl/del [post]
|
2023-11-27 09:00:09 +00:00
|
|
|
// @x-panel-log {"bodyKeys":["ids"],"paramKeys":[],"BeforeFunctions":[{"input_column":"id","input_value":"ids","isList":true,"db":"website_ssls","output_column":"primary_domain","output_value":"domain"}],"formatZH":"删除 ssl [domain]","formatEN":"Delete ssl [domain]"}
|
2022-11-16 02:31:35 +00:00
|
|
|
func (b *BaseApi) DeleteWebsiteSSL(c *gin.Context) {
|
2023-11-27 09:00:09 +00:00
|
|
|
var req request.WebsiteBatchDelReq
|
2023-10-27 04:04:11 +00:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2022-11-16 02:31:35 +00:00
|
|
|
return
|
|
|
|
}
|
2023-11-27 09:00:09 +00:00
|
|
|
if err := websiteSSLService.Delete(req.IDs); err != nil {
|
2022-11-16 02:31:35 +00:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
2022-11-17 09:39:33 +00:00
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags Website SSL
|
|
|
|
// @Summary Search website ssl by website id
|
|
|
|
// @Description 通过网站 id 查询 ssl
|
|
|
|
// @Accept json
|
|
|
|
// @Param websiteId path integer true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /websites/ssl/website/:websiteId [get]
|
2022-12-29 06:55:20 +00:00
|
|
|
func (b *BaseApi) GetWebsiteSSLByWebsiteId(c *gin.Context) {
|
2022-11-17 09:39:33 +00:00
|
|
|
websiteId, err := helper.GetIntParamByKey(c, "websiteId")
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
websiteSSL, err := websiteSSLService.GetWebsiteSSL(websiteId)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, websiteSSL)
|
|
|
|
}
|
2022-12-29 06:55:20 +00:00
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags Website SSL
|
|
|
|
// @Summary Search website ssl by id
|
|
|
|
// @Description 通过 id 查询 ssl
|
|
|
|
// @Accept json
|
|
|
|
// @Param id path integer true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /websites/ssl/:id [get]
|
2022-12-29 06:55:20 +00:00
|
|
|
func (b *BaseApi) GetWebsiteSSLById(c *gin.Context) {
|
|
|
|
id, err := helper.GetParamID(c)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
websiteSSL, err := websiteSSLService.GetSSL(id)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, websiteSSL)
|
|
|
|
}
|
2023-03-21 06:42:50 +00:00
|
|
|
|
|
|
|
// @Tags Website SSL
|
|
|
|
// @Summary Update ssl
|
|
|
|
// @Description 更新 ssl
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body request.WebsiteSSLUpdate true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /websites/ssl/update [post]
|
2023-10-07 07:46:44 +00:00
|
|
|
// @x-panel-log {"bodyKeys":["id"],"paramKeys":[],"BeforeFunctions":[{"input_column":"id","input_value":"id","isList":false,"db":"website_ssls","output_column":"primary_domain","output_value":"domain"}],"formatZH":"更新证书设置 [domain]","formatEN":"Update ssl config [domain]"}
|
2023-03-21 06:42:50 +00:00
|
|
|
func (b *BaseApi) UpdateWebsiteSSL(c *gin.Context) {
|
|
|
|
var req request.WebsiteSSLUpdate
|
2023-10-27 04:04:11 +00:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2023-03-21 06:42:50 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := websiteSSLService.Update(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
2023-10-31 08:01:50 +00:00
|
|
|
|
|
|
|
// @Tags Website SSL
|
|
|
|
// @Summary Upload ssl
|
|
|
|
// @Description 上传 ssl
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body request.WebsiteSSLUpload true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /websites/ssl/upload [post]
|
|
|
|
// @x-panel-log {"bodyKeys":["type"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"上传 ssl [type]","formatEN":"Upload ssl [type]"}
|
|
|
|
func (b *BaseApi) UploadWebsiteSSL(c *gin.Context) {
|
|
|
|
var req request.WebsiteSSLUpload
|
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := websiteSSLService.Upload(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
2023-11-28 09:27:31 +00:00
|
|
|
|
|
|
|
// @Tags Website SSL
|
|
|
|
// @Summary Download SSL file
|
|
|
|
// @Description 下载证书文件
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body request.WebsiteResourceReq true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /websites/ssl/download [post]
|
|
|
|
// @x-panel-log {"bodyKeys":["id"],"paramKeys":[],"BeforeFunctions":[{"input_column":"id","input_value":"id","isList":false,"db":"website_ssls","output_column":"primary_domain","output_value":"domain"}],"formatZH":"下载证书文件 [domain]","formatEN":"download ssl file [domain]"}
|
|
|
|
func (b *BaseApi) DownloadWebsiteSSL(c *gin.Context) {
|
|
|
|
var req request.WebsiteResourceReq
|
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
file, err := websiteSSLService.DownloadFile(req.ID)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
info, err := file.Stat()
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
c.Header("Content-Length", strconv.FormatInt(info.Size(), 10))
|
|
|
|
c.Header("Content-Disposition", "attachment; filename*=utf-8''"+url.PathEscape(info.Name()))
|
|
|
|
http.ServeContent(c.Writer, c.Request, info.Name(), info.ModTime(), file)
|
|
|
|
}
|