mirror of
https://gitee.com/mirrors/AllinSSL.git
synced 2026-03-15 02:42:01 +08:00
【调整】暗色主题样式
This commit is contained in:
410
frontend/allinssl/backend/app/api/access.go
Normal file
410
frontend/allinssl/backend/app/api/access.go
Normal file
@@ -0,0 +1,410 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"ALLinSSL/backend/app/dto/response"
|
||||
"ALLinSSL/backend/internal/access"
|
||||
"ALLinSSL/backend/internal/cert/deploy"
|
||||
"ALLinSSL/backend/internal/cert/deploy/plugin"
|
||||
"ALLinSSL/backend/public"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func GetAccessList(c *gin.Context) {
|
||||
var form struct {
|
||||
Search string `form:"search"`
|
||||
Page int64 `form:"p"`
|
||||
Limit int64 `form:"limit"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
accessList, count, err := access.GetList(form.Search, form.Page, form.Limit)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessData(c, accessList, count)
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
func GetAllAccess(c *gin.Context) {
|
||||
var form struct {
|
||||
Type string `form:"type"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
accessList, err := access.GetAll(form.Type)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessData(c, accessList, 0)
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
func AddAccess(c *gin.Context) {
|
||||
var form struct {
|
||||
Name string `form:"name"`
|
||||
Type string `form:"type"`
|
||||
Config string `form:"config"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
form.Name = strings.TrimSpace(form.Name)
|
||||
if form.Name == "" {
|
||||
public.FailMsg(c, "名称不能为空")
|
||||
return
|
||||
}
|
||||
if form.Type == "" {
|
||||
public.FailMsg(c, "类型不能为空")
|
||||
return
|
||||
}
|
||||
if form.Config == "" {
|
||||
public.FailMsg(c, "配置不能为空")
|
||||
return
|
||||
}
|
||||
err = access.AddAccess(form.Config, form.Name, form.Type)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "添加成功")
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
func UpdateAccess(c *gin.Context) {
|
||||
var form struct {
|
||||
ID string `form:"id"`
|
||||
Name string `form:"name"`
|
||||
Config string `form:"config"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
form.Name = strings.TrimSpace(form.Name)
|
||||
if form.Name == "" {
|
||||
public.FailMsg(c, "名称不能为空")
|
||||
return
|
||||
}
|
||||
if form.Config == "" {
|
||||
public.FailMsg(c, "配置不能为空")
|
||||
return
|
||||
}
|
||||
err = access.UpdateAccess(form.ID, form.Config, form.Name)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "修改成功")
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
func DelAccess(c *gin.Context) {
|
||||
var form struct {
|
||||
ID string `form:"id"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
form.ID = strings.TrimSpace(form.ID)
|
||||
if form.ID == "" {
|
||||
public.FailMsg(c, "ID不能为空")
|
||||
return
|
||||
}
|
||||
err = access.DelAccess(form.ID)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "删除成功")
|
||||
return
|
||||
}
|
||||
|
||||
func GetAllEAB(c *gin.Context) {
|
||||
var form struct {
|
||||
CA string `form:"ca"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
eabList, err := access.GetAllEAB(form.CA)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessData(c, eabList, 0)
|
||||
return
|
||||
}
|
||||
|
||||
func GetEABList(c *gin.Context) {
|
||||
var form struct {
|
||||
Search string `form:"search"`
|
||||
Page int64 `form:"p"`
|
||||
Limit int64 `form:"limit"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
eabList, count, err := access.GetEABList(form.Search, form.Page, form.Limit)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessData(c, eabList, count)
|
||||
return
|
||||
}
|
||||
|
||||
func AddEAB(c *gin.Context) {
|
||||
var form struct {
|
||||
Name string `form:"name"`
|
||||
Kid string `form:"Kid"`
|
||||
HmacEncoded string `form:"HmacEncoded"`
|
||||
CA string `form:"ca"`
|
||||
Mail string `form:"mail"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
form.Name = strings.TrimSpace(form.Name)
|
||||
form.Kid = strings.TrimSpace(form.Kid)
|
||||
form.HmacEncoded = strings.TrimSpace(form.HmacEncoded)
|
||||
form.CA = strings.TrimSpace(form.CA)
|
||||
form.Mail = strings.TrimSpace(form.Mail)
|
||||
if form.Name == "" {
|
||||
public.FailMsg(c, "名称不能为空")
|
||||
return
|
||||
}
|
||||
if form.Kid == "" {
|
||||
public.FailMsg(c, "ID不能为空")
|
||||
return
|
||||
}
|
||||
if form.HmacEncoded == "" {
|
||||
public.FailMsg(c, "HmacEncoded不能为空")
|
||||
return
|
||||
}
|
||||
if form.CA == "" {
|
||||
public.FailMsg(c, "CA不能为空")
|
||||
return
|
||||
}
|
||||
if form.Mail == "" {
|
||||
public.FailMsg(c, "Email不能为空")
|
||||
return
|
||||
}
|
||||
err = access.AddEAB(form.Name, form.Kid, form.HmacEncoded, form.CA, form.Mail)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "添加成功")
|
||||
return
|
||||
}
|
||||
|
||||
func UpdEAB(c *gin.Context) {
|
||||
var form struct {
|
||||
ID string `form:"id"`
|
||||
Name string `form:"name"`
|
||||
Kid string `form:"Kid"`
|
||||
HmacEncoded string `form:"HmacEncoded"`
|
||||
CA string `form:"ca"`
|
||||
Mail string `form:"mail"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
form.Name = strings.TrimSpace(form.Name)
|
||||
form.Kid = strings.TrimSpace(form.Kid)
|
||||
form.HmacEncoded = strings.TrimSpace(form.HmacEncoded)
|
||||
form.CA = strings.TrimSpace(form.CA)
|
||||
form.Mail = strings.TrimSpace(form.Mail)
|
||||
if form.Name == "" {
|
||||
public.FailMsg(c, "名称不能为空")
|
||||
return
|
||||
}
|
||||
if form.Kid == "" {
|
||||
public.FailMsg(c, "ID不能为空")
|
||||
return
|
||||
}
|
||||
if form.HmacEncoded == "" {
|
||||
public.FailMsg(c, "HmacEncoded不能为空")
|
||||
return
|
||||
}
|
||||
if form.CA == "" {
|
||||
public.FailMsg(c, "CA不能为空")
|
||||
return
|
||||
}
|
||||
if form.Mail == "" {
|
||||
public.FailMsg(c, "mail不能为空")
|
||||
return
|
||||
}
|
||||
err = access.UpdEAB(form.ID, form.Name, form.Kid, form.HmacEncoded, form.CA, form.Mail)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
}
|
||||
public.SuccessMsg(c, "修改成功")
|
||||
return
|
||||
}
|
||||
|
||||
func DelEAB(c *gin.Context) {
|
||||
var form struct {
|
||||
ID string `form:"id"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
form.ID = strings.TrimSpace(form.ID)
|
||||
if form.ID == "" {
|
||||
public.FailMsg(c, "ID不能为空")
|
||||
return
|
||||
}
|
||||
err = access.DelEAB(form.ID)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "删除成功")
|
||||
return
|
||||
}
|
||||
|
||||
func TestAccess(c *gin.Context) {
|
||||
var form struct {
|
||||
ID string `form:"id"`
|
||||
Type string `form:"type"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
if form.Type == "" {
|
||||
public.FailMsg(c, "类型不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
var result error
|
||||
switch form.Type {
|
||||
case "btwaf":
|
||||
result = deploy.BtWafAPITest(form.ID)
|
||||
case "btpanel":
|
||||
result = deploy.BtPanelAPITest(form.ID)
|
||||
case "ssh":
|
||||
result = deploy.SSHAPITest(form.ID)
|
||||
case "safeline":
|
||||
result = deploy.SafeLineAPITest(form.ID)
|
||||
case "1panel":
|
||||
result = deploy.OnePanelAPITest(form.ID)
|
||||
case "tencentcloud":
|
||||
result = deploy.TencentCloudAPITest(form.ID)
|
||||
case "aliyun":
|
||||
result = deploy.AliyunCdnAPITest(form.ID)
|
||||
case "rainyun":
|
||||
result = deploy.RainyunApiTest(form.ID)
|
||||
case "qiniu":
|
||||
result = deploy.QiniuAPITest(form.ID)
|
||||
case "baidu":
|
||||
result = deploy.BaiduyunAPITest(form.ID)
|
||||
default:
|
||||
public.FailMsg(c, "不支持测试的提供商")
|
||||
return
|
||||
}
|
||||
|
||||
if result != nil {
|
||||
public.FailMsg(c, result.Error())
|
||||
return
|
||||
}
|
||||
|
||||
public.SuccessMsg(c, "请求测试成功!")
|
||||
return
|
||||
}
|
||||
|
||||
func GetSiteList(c *gin.Context) {
|
||||
var form struct {
|
||||
ID string `form:"id"`
|
||||
Type string `form:"type"`
|
||||
Search string `form:"search"`
|
||||
Page int64 `form:"p"`
|
||||
Limit int64 `form:"limit"`
|
||||
}
|
||||
err := c.ShouldBind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
var siteList []response.AccessSiteList
|
||||
switch form.Type {
|
||||
case "btpanel-site":
|
||||
siteList, err = deploy.BtPanelSiteList(form.ID)
|
||||
case "1panel-site":
|
||||
siteList, err = deploy.OnePanelSiteList(form.ID)
|
||||
default:
|
||||
public.FailMsg(c, "不支持的提供商")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
public.SuccessData(c, siteList, len(siteList))
|
||||
return
|
||||
}
|
||||
|
||||
public.SuccessData(c, siteList, len(siteList))
|
||||
}
|
||||
|
||||
func GetPluginActions(c *gin.Context) {
|
||||
var form struct {
|
||||
Name string `form:"name"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
form.Name = strings.TrimSpace(form.Name)
|
||||
if form.Name == "" {
|
||||
public.FailMsg(c, "插件名称不能为空")
|
||||
return
|
||||
}
|
||||
data, err := plugin.GetActions(form.Name)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessData(c, data, len(data))
|
||||
return
|
||||
}
|
||||
|
||||
func GetPlugins(c *gin.Context) {
|
||||
data, err := plugin.GetPlugins()
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessData(c, data, len(data))
|
||||
return
|
||||
}
|
||||
137
frontend/allinssl/backend/app/api/acme_account.go
Normal file
137
frontend/allinssl/backend/app/api/acme_account.go
Normal file
@@ -0,0 +1,137 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"ALLinSSL/backend/internal/cert/apply"
|
||||
"ALLinSSL/backend/public"
|
||||
"github.com/gin-gonic/gin"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func AddAccount(c *gin.Context) {
|
||||
var form struct {
|
||||
Email string `form:"email"`
|
||||
CA string `form:"ca"`
|
||||
Kid string `form:"Kid"`
|
||||
HmacEncoded string `form:"HmacEncoded"`
|
||||
CADirURL string `form:"CADirURL"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
form.Email = strings.TrimSpace(form.Email)
|
||||
if form.Email == "" {
|
||||
public.FailMsg(c, "邮件不能为空")
|
||||
return
|
||||
}
|
||||
if form.CA == "" {
|
||||
public.FailMsg(c, "CA不能为空")
|
||||
return
|
||||
}
|
||||
err = apply.AddAccount(form.Email, form.CA, form.Kid, form.HmacEncoded, form.CADirURL)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "添加成功")
|
||||
return
|
||||
}
|
||||
|
||||
func DelAccount(c *gin.Context) {
|
||||
var form struct {
|
||||
ID string `form:"id"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
form.ID = strings.TrimSpace(form.ID)
|
||||
if form.ID == "" {
|
||||
public.FailMsg(c, "ID不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
err = apply.DelAccount(form.ID)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "删除成功")
|
||||
return
|
||||
}
|
||||
|
||||
func UpdateAccount(c *gin.Context) {
|
||||
var form struct {
|
||||
ID string `form:"id"`
|
||||
Email string `form:"email"`
|
||||
CA string `form:"ca"`
|
||||
Kid string `form:"Kid"`
|
||||
HmacEncoded string `form:"HmacEncoded"`
|
||||
CADirURL string `form:"CADirURL"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
form.ID = strings.TrimSpace(form.ID)
|
||||
if form.ID == "" {
|
||||
public.FailMsg(c, "ID不能为空")
|
||||
return
|
||||
}
|
||||
form.Email = strings.TrimSpace(form.Email)
|
||||
if form.Email == "" {
|
||||
public.FailMsg(c, "邮件不能为空")
|
||||
return
|
||||
}
|
||||
if form.CA == "" {
|
||||
public.FailMsg(c, "CA不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
err = apply.UpdateAccount(form.ID, form.Email, form.CA, form.Kid, form.HmacEncoded, form.CADirURL)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "更新成功")
|
||||
return
|
||||
}
|
||||
|
||||
func GetAccountList(c *gin.Context) {
|
||||
var form struct {
|
||||
Page int64 `form:"p"`
|
||||
Limit int64 `form:"limit"`
|
||||
CA string `form:"ca"`
|
||||
Search string `form:"search"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
if form.Page <= 0 {
|
||||
form.Page = 1
|
||||
}
|
||||
if form.Limit <= 0 {
|
||||
form.Limit = 10
|
||||
}
|
||||
accounts, total, err := apply.GetAccountList(form.Search, form.CA, form.Page, form.Limit)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessData(c, accounts, total)
|
||||
}
|
||||
|
||||
func GetCaList(c *gin.Context) {
|
||||
cas, total, err := apply.GetCaList()
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessData(c, cas, total)
|
||||
|
||||
}
|
||||
182
frontend/allinssl/backend/app/api/cert.go
Normal file
182
frontend/allinssl/backend/app/api/cert.go
Normal file
@@ -0,0 +1,182 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"ALLinSSL/backend/internal/cert"
|
||||
"ALLinSSL/backend/public"
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"github.com/gin-gonic/gin"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetCertList(c *gin.Context) {
|
||||
var form struct {
|
||||
Search string `form:"search"`
|
||||
Page int64 `form:"p"`
|
||||
Limit int64 `form:"limit"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
certList, count, err := cert.GetList(form.Search, form.Page, form.Limit)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessData(c, certList, count)
|
||||
return
|
||||
}
|
||||
|
||||
func UploadCert(c *gin.Context) {
|
||||
var form struct {
|
||||
Key string `form:"key"`
|
||||
Cert string `form:"cert"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
form.Key = strings.TrimSpace(form.Key)
|
||||
form.Cert = strings.TrimSpace(form.Cert)
|
||||
|
||||
if form.Key == "" {
|
||||
public.FailMsg(c, "名称不能为空")
|
||||
return
|
||||
}
|
||||
if form.Cert == "" {
|
||||
public.FailMsg(c, "类型不能为空")
|
||||
return
|
||||
}
|
||||
sha256, err := cert.UploadCert(form.Key, form.Cert)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessData(c, sha256, 0)
|
||||
return
|
||||
}
|
||||
|
||||
func DelCert(c *gin.Context) {
|
||||
var form struct {
|
||||
ID string `form:"id"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
if form.ID == "" {
|
||||
public.FailMsg(c, "ID不能为空")
|
||||
return
|
||||
}
|
||||
err = cert.DelCert(form.ID)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "删除成功")
|
||||
return
|
||||
}
|
||||
|
||||
func DownloadCert(c *gin.Context) {
|
||||
ID := c.Query("id")
|
||||
|
||||
if ID == "" {
|
||||
public.FailMsg(c, "ID不能为空")
|
||||
return
|
||||
}
|
||||
certData, err := cert.GetCert(ID)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// 构建 zip 包(内存中)
|
||||
buf := new(bytes.Buffer)
|
||||
zipWriter := zip.NewWriter(buf)
|
||||
|
||||
// 写入PEM文件
|
||||
// cert.pem
|
||||
certStr := certData["cert"]
|
||||
certWriter, err := zipWriter.Create("Nginx/cert.pem")
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
if _, err := certWriter.Write([]byte(certStr)); err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
// key.pem
|
||||
keyStr := certData["key"]
|
||||
keyWriter, err := zipWriter.Create("Nginx/key.pem")
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
if _, err := keyWriter.Write([]byte(keyStr)); err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
// cert.pfx
|
||||
pfxPassword := "allinssl"
|
||||
pfxData, err := public.PEMToPFX(certStr, keyStr, pfxPassword)
|
||||
if err == nil && len(pfxData) > 0 {
|
||||
pfxWriter, err := zipWriter.Create("IIS/cert.pfx")
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
if _, err := pfxWriter.Write(pfxData); err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
txtWriter, err := zipWriter.Create("IIS/passwd.txt")
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
if _, err := txtWriter.Write([]byte(pfxPassword)); err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
// cert.jks
|
||||
jksData, err := public.PfxToJks(pfxData, pfxPassword, pfxPassword, "allinssl")
|
||||
if err == nil && jksData != nil {
|
||||
jksWriter, err := zipWriter.Create("Tomcat/cert.jks")
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
if _, err := jksWriter.Write(jksData.Bytes()); err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
txtWriter, err := zipWriter.Create("Tomcat/passwd.txt")
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
if _, err := txtWriter.Write([]byte(pfxPassword)); err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭 zipWriter
|
||||
if err := zipWriter.Close(); err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
// 设置响应头
|
||||
zipName := strings.ReplaceAll(certData["domains"], ".", "_")
|
||||
zipName = strings.ReplaceAll(zipName, ",", "-")
|
||||
c.Header("Content-Type", "application/zip")
|
||||
c.Header("Content-Disposition", "attachment; filename="+zipName+".zip")
|
||||
c.Data(200, "application/zip", buf.Bytes())
|
||||
return
|
||||
}
|
||||
161
frontend/allinssl/backend/app/api/login.go
Normal file
161
frontend/allinssl/backend/app/api/login.go
Normal file
@@ -0,0 +1,161 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"ALLinSSL/backend/public"
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"github.com/gin-contrib/sessions"
|
||||
"github.com/gin-gonic/gin"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Sign(c *gin.Context) {
|
||||
var form struct {
|
||||
Username string `form:"username" binding:"required"`
|
||||
Password string `form:"password" binding:"required"`
|
||||
Code string `form:"code"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
// c.JSON(http.StatusBadRequest, public.ResERR(err.Error()))
|
||||
public.FailMsg(c, err.Error())
|
||||
// return
|
||||
}
|
||||
form.Username = strings.TrimSpace(form.Username)
|
||||
form.Code = strings.TrimSpace(form.Code)
|
||||
|
||||
// 从数据库拿用户
|
||||
s, err := public.NewSqlite("data/settings.db", "")
|
||||
if err != nil {
|
||||
// c.JSON(http.StatusBadRequest, public.ResERR(err.Error()))
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
defer s.Close()
|
||||
s.TableName = "users"
|
||||
res, err := s.Where("username=?", []interface{}{form.Username}).Select()
|
||||
if err != nil {
|
||||
// c.JSON(http.StatusBadRequest, public.ResERR(err.Error()))
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
session := sessions.Default(c)
|
||||
now := time.Now()
|
||||
|
||||
loginErrCount := session.Get("__loginErrCount")
|
||||
loginErrEnd := session.Get("__loginErrEnd")
|
||||
ErrCount := 0
|
||||
ErrEnd := now
|
||||
// 获取登录错误次数
|
||||
if __loginErrCount, ok := loginErrCount.(int); ok {
|
||||
ErrCount = __loginErrCount
|
||||
}
|
||||
// 获取登录错误时间
|
||||
if __loginErrEnd, ok := loginErrEnd.(time.Time); ok {
|
||||
ErrEnd = __loginErrEnd
|
||||
}
|
||||
|
||||
// fmt.Println(ErrCount, ErrEnd)
|
||||
|
||||
// 判断登录错误次数
|
||||
switch {
|
||||
case ErrCount >= 5:
|
||||
// 登录错误次数超过5次,15分钟内禁止登录
|
||||
if now.Sub(ErrEnd) < 15*time.Minute {
|
||||
// c.JSON(http.StatusBadRequest, public.ResERR("登录次数过多,请15分钟后再试"))
|
||||
public.FailMsg(c, "登录次数过多,请15分钟后再试")
|
||||
return
|
||||
}
|
||||
session.Delete("__loginErrEnd")
|
||||
case ErrCount > 0:
|
||||
if form.Code == "" {
|
||||
// c.JSON(http.StatusBadRequest, public.ResERR("验证码错误1"))
|
||||
public.FailMsg(c, "验证码错误1")
|
||||
return
|
||||
} else {
|
||||
// 这里添加验证码的逻辑
|
||||
verifyCode := session.Get("_verifyCode")
|
||||
if _verifyCode, ok := verifyCode.(string); ok {
|
||||
if !strings.EqualFold(form.Code, _verifyCode) {
|
||||
// c.JSON(http.StatusBadRequest, public.ResERR("验证码错误2"))
|
||||
public.FailMsg(c, "验证码错误2")
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// c.JSON(http.StatusBadRequest, public.ResERR("验证码错误3"))
|
||||
public.FailMsg(c, "验证码错误3")
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 判断用户是否存在
|
||||
if len(res) == 0 {
|
||||
session.Set("__loginErrCount", ErrCount+1)
|
||||
session.Set("__loginErrEnd", now)
|
||||
_ = session.Save()
|
||||
// c.JSON(http.StatusBadRequest, public.ResERR("用户不存在"))
|
||||
// 设置cookie
|
||||
c.SetCookie("must_code", "1", 0, "/", "", false, false)
|
||||
public.FailMsg(c, "用户不存在")
|
||||
return
|
||||
}
|
||||
// 判断密码是否正确
|
||||
// qSalt := "_bt_all_in_ssl"
|
||||
// password := md5.Sum([]byte(form.Password + qSalt))
|
||||
// passwordMd5 := hex.EncodeToString(password[:])
|
||||
// fmt.Println(passwordMd5)
|
||||
salt, ok := res[0]["salt"].(string)
|
||||
if !ok {
|
||||
salt = "_bt_all_in_ssl"
|
||||
}
|
||||
passwd := form.Password + salt
|
||||
// fmt.Println(passwd)
|
||||
keyMd5 := md5.Sum([]byte(passwd))
|
||||
passwdMd5 := hex.EncodeToString(keyMd5[:])
|
||||
// fmt.Println(passwdMd5)
|
||||
|
||||
if res[0]["password"] != passwdMd5 {
|
||||
session.Set("__loginErrCount", ErrCount+1)
|
||||
session.Set("__loginErrEnd", now)
|
||||
_ = session.Save()
|
||||
// c.JSON(http.StatusBadRequest, public.ResERR("密码错误"))
|
||||
// 设置cookie
|
||||
c.SetCookie("must_code", "1", 0, "/", "", false, false)
|
||||
public.FailMsg(c, "密码错误")
|
||||
return
|
||||
}
|
||||
|
||||
// session := sessions.Default(c)
|
||||
session.Set("__loginErrCount", 0)
|
||||
session.Delete("__loginErrEnd")
|
||||
session.Set("login", true)
|
||||
session.Set("__login_key", public.LoginKey)
|
||||
_ = session.Save()
|
||||
// c.JSON(http.StatusOK, public.ResOK(0, nil, "登录成功"))
|
||||
// 设置cookie
|
||||
c.SetCookie("must_code", "1", -1, "/", "", false, false)
|
||||
public.SuccessMsg(c, "登录成功")
|
||||
return
|
||||
}
|
||||
|
||||
func GetCode(c *gin.Context) {
|
||||
_, bs64, code, _ := public.GenerateCode()
|
||||
session := sessions.Default(c)
|
||||
|
||||
session.Set("_verifyCode", code)
|
||||
_ = session.Save()
|
||||
public.SuccessData(c, bs64, 0)
|
||||
return
|
||||
}
|
||||
|
||||
func SignOut(c *gin.Context) {
|
||||
session := sessions.Default(c)
|
||||
session.Delete("login")
|
||||
_ = session.Save()
|
||||
// c.JSON(http.StatusOK, public.ResOK(0, nil, "登出成功"))
|
||||
public.SuccessMsg(c, "登出成功")
|
||||
return
|
||||
}
|
||||
232
frontend/allinssl/backend/app/api/monitor/monitor.go
Normal file
232
frontend/allinssl/backend/app/api/monitor/monitor.go
Normal file
@@ -0,0 +1,232 @@
|
||||
package monitor
|
||||
|
||||
import (
|
||||
"ALLinSSL/backend/internal/monitor"
|
||||
"ALLinSSL/backend/public"
|
||||
"ALLinSSL/static"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetMonitorList(c *gin.Context) {
|
||||
var form struct {
|
||||
Search string `form:"search"`
|
||||
Page int64 `form:"p"`
|
||||
Limit int64 `form:"limit"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
data, count, err := monitor.GetList(form.Search, form.Page, form.Limit)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessData(c, data, count)
|
||||
return
|
||||
}
|
||||
|
||||
func AddMonitor(c *gin.Context) {
|
||||
var form struct {
|
||||
Name string `form:"name"`
|
||||
Target string `form:"target"`
|
||||
MonitorType string `form:"monitor_type"`
|
||||
ReportTypes string `form:"report_types"`
|
||||
Cycle string `form:"cycle"`
|
||||
RepeatSendGap string `form:"repeat_send_gap"`
|
||||
Active string `form:"active"`
|
||||
AdvanceDay string `form:"advance_day"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
form.Name = strings.TrimSpace(form.Name)
|
||||
form.Target = strings.TrimSpace(form.Target)
|
||||
|
||||
err = monitor.AddMonitor(form.Name, form.Target, form.MonitorType, form.ReportTypes, form.Cycle, form.RepeatSendGap, form.Active, form.AdvanceDay)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "添加成功")
|
||||
return
|
||||
}
|
||||
|
||||
func UpdMonitor(c *gin.Context) {
|
||||
var form struct {
|
||||
ID string `form:"id"`
|
||||
Target string `form:"target"`
|
||||
Name string `form:"name"`
|
||||
Cycle string `form:"cycle"`
|
||||
ReportTypes string `form:"report_types"`
|
||||
RepeatSendGap string `form:"repeat_send_gap"`
|
||||
Active string `form:"active"`
|
||||
AdvanceDay string `form:"advance_day"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
form.ID = strings.TrimSpace(form.ID)
|
||||
form.Target = strings.TrimSpace(form.Target)
|
||||
form.Name = strings.TrimSpace(form.Name)
|
||||
form.ReportTypes = strings.TrimSpace(form.ReportTypes)
|
||||
|
||||
err = monitor.UpdMonitor(form.ID, form.Name, form.Target, form.ReportTypes, form.Cycle, form.RepeatSendGap, form.Active, form.AdvanceDay)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "修改成功")
|
||||
return
|
||||
}
|
||||
|
||||
func DelMonitor(c *gin.Context) {
|
||||
var form struct {
|
||||
ID string `form:"id"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
err = monitor.DelMonitor(form.ID)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "删除成功")
|
||||
return
|
||||
}
|
||||
|
||||
func SetMonitor(c *gin.Context) {
|
||||
var form struct {
|
||||
ID string `form:"id"`
|
||||
Active int `form:"active"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
err = monitor.SetMonitor(form.ID, form.Active)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "操作成功")
|
||||
return
|
||||
}
|
||||
|
||||
func GetMonitorInfo(c *gin.Context) {
|
||||
var form struct {
|
||||
ID string `form:"id"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
form.ID = strings.TrimSpace(form.ID)
|
||||
data, err := monitor.GetInfo(form.ID)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessData(c, data, 0)
|
||||
return
|
||||
}
|
||||
|
||||
func GetErrRecord(c *gin.Context) {
|
||||
var form struct {
|
||||
ID int64 `form:"id"`
|
||||
Page int64 `form:"p"`
|
||||
Limit int64 `form:"limit"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
data, count, err := monitor.GetErrRecord(form.ID, form.Page, form.Limit)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessData(c, data, count)
|
||||
return
|
||||
}
|
||||
|
||||
func FileAddMonitor(c *gin.Context) {
|
||||
file, err := c.FormFile("file")
|
||||
if err != nil {
|
||||
public.FailMsg(c, "上传文件失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
if file.Size > 10*1024*1024 { // 限制文件大小为10MB
|
||||
public.FailMsg(c, "上传文件过大,最大限制10MB")
|
||||
return
|
||||
}
|
||||
data, err := monitor.ParseMonitorFile(file)
|
||||
if err != nil {
|
||||
public.FailMsg(c, "文件解析失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
if len(data) == 0 {
|
||||
public.FailMsg(c, "文件中没有有效的监控数据")
|
||||
return
|
||||
}
|
||||
|
||||
err = monitor.MultiAddMonitor(data)
|
||||
if err != nil {
|
||||
public.FailMsg(c, "文件导入失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "文件导入成功")
|
||||
return
|
||||
}
|
||||
|
||||
func GetTemplate(c *gin.Context) {
|
||||
t := c.Query("type")
|
||||
if t == "" {
|
||||
c.String(http.StatusBadRequest, "参数 type 不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
fileMap := map[string]string{
|
||||
"txt": "monitor_templates/template.txt",
|
||||
"csv": "monitor_templates/template.csv",
|
||||
"json": "monitor_templates/template.json",
|
||||
"xlsx": "monitor_templates/template.xlsx",
|
||||
}
|
||||
|
||||
filePath, ok := fileMap[strings.ToLower(t)]
|
||||
if !ok {
|
||||
c.String(http.StatusBadRequest, "不支持的类型")
|
||||
return
|
||||
}
|
||||
|
||||
data, err := static.MonitorTemplatesFS.ReadFile(filePath)
|
||||
if err != nil {
|
||||
c.String(http.StatusInternalServerError, "模板文件读取失败")
|
||||
return
|
||||
}
|
||||
|
||||
// 设置 Content-Type
|
||||
contentTypes := map[string]string{
|
||||
"txt": "text/plain",
|
||||
"csv": "text/csv",
|
||||
"json": "application/json",
|
||||
"xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
"xls": "application/vnd.ms-excel",
|
||||
}
|
||||
c.Header("Content-Type", contentTypes[t])
|
||||
c.Header("Content-Disposition", "attachment; filename=template."+t)
|
||||
c.Data(http.StatusOK, contentTypes[t], data)
|
||||
}
|
||||
20
frontend/allinssl/backend/app/api/overview.go
Normal file
20
frontend/allinssl/backend/app/api/overview.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"ALLinSSL/backend/internal/overview"
|
||||
"ALLinSSL/backend/public"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func GetOverview(c *gin.Context) {
|
||||
// Get the overview data from the database
|
||||
overviewData, err := overview.GetOverviewData()
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// Return the overview data as JSON
|
||||
public.SuccessData(c, overviewData, 0)
|
||||
|
||||
}
|
||||
258
frontend/allinssl/backend/app/api/private_ca/private_ca.go
Normal file
258
frontend/allinssl/backend/app/api/private_ca/private_ca.go
Normal file
@@ -0,0 +1,258 @@
|
||||
package private_ca
|
||||
|
||||
import (
|
||||
"ALLinSSL/backend/internal/private_ca"
|
||||
"ALLinSSL/backend/public"
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"github.com/gin-gonic/gin"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func CreateRootCA(c *gin.Context) {
|
||||
var form private_ca.CAConfig
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
err = private_ca.CreateRootCA(form.Name, form.CN, form.O, form.OU, form.C, form.Province, form.Locality, form.Algorithm, form.KeyLength, form.ValidDays)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "根证书创建成功")
|
||||
return
|
||||
}
|
||||
|
||||
func CreateIntermediateCA(c *gin.Context) {
|
||||
var form private_ca.CAConfig
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
err = private_ca.CreateIntermediateCA(form.Name, form.CN, form.O, form.OU, form.C, form.Province, form.Locality, form.RootId, form.KeyLength, form.ValidDays)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "中间证书创建成功")
|
||||
return
|
||||
}
|
||||
|
||||
func GetCAList(c *gin.Context) {
|
||||
var form struct {
|
||||
Search string `form:"search"`
|
||||
Level string `form:"level"`
|
||||
Page int64 `form:"p"`
|
||||
Limit int64 `form:"limit"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
data, count, err := private_ca.ListCAs(form.Search, form.Level, form.Page, form.Limit)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessData(c, data, count)
|
||||
return
|
||||
}
|
||||
|
||||
func DeleteCA(c *gin.Context) {
|
||||
var form struct {
|
||||
Id int64 `form:"id"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
if form.Id <= 0 {
|
||||
public.FailMsg(c, "ID不能为空")
|
||||
return
|
||||
}
|
||||
err = private_ca.DeleteCA(form.Id)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "删除成功")
|
||||
return
|
||||
}
|
||||
|
||||
func CreateLeafCert(c *gin.Context) {
|
||||
var form private_ca.LeafCertConfig
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
_, err = private_ca.CreateLeafCert(form.CaId, form.Usage, form.KeyLength, form.ValidDays, form.CN, form.SAN)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "证书创建成功")
|
||||
return
|
||||
}
|
||||
|
||||
func GetLeafCertList(c *gin.Context) {
|
||||
var form struct {
|
||||
CaId int64 `form:"ca_id"`
|
||||
Search string `form:"search"`
|
||||
Page int64 `form:"p"`
|
||||
Limit int64 `form:"limit"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
data, count, err := private_ca.ListLeafCerts(form.CaId, form.Search, form.Page, form.Limit)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessData(c, data, count)
|
||||
return
|
||||
}
|
||||
|
||||
func DeleteLeafCert(c *gin.Context) {
|
||||
var form struct {
|
||||
Id int64 `form:"id"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
if form.Id <= 0 {
|
||||
public.FailMsg(c, "ID不能为空")
|
||||
return
|
||||
}
|
||||
err = private_ca.DeleteLeafCert(form.Id)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "删除成功")
|
||||
return
|
||||
}
|
||||
|
||||
func DownloadCert(c *gin.Context) {
|
||||
var form struct {
|
||||
Id int64 `form:"id"`
|
||||
Type string `form:"type"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
if form.Id <= 0 {
|
||||
public.FailMsg(c, "ID不能为空")
|
||||
return
|
||||
}
|
||||
certData, err := private_ca.GetCert(form.Id, form.Type)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
if certData == nil {
|
||||
public.FailMsg(c, "证书不存在")
|
||||
return
|
||||
}
|
||||
|
||||
// 构建 zip 包(内存中)
|
||||
buf := new(bytes.Buffer)
|
||||
zipWriter := zip.NewWriter(buf)
|
||||
|
||||
certStr := certData["cert"].(string)
|
||||
certWriter, err := zipWriter.Create("cert.pem")
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
if _, err := certWriter.Write([]byte(certStr)); err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
// key.pem
|
||||
keyStr := certData["key"].(string)
|
||||
keyWriter, err := zipWriter.Create("key.pem")
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
if _, err := keyWriter.Write([]byte(keyStr)); err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
if certData["en_cert"] != nil && certData["en_key"] != nil {
|
||||
// en_cert.pem
|
||||
enCertStr := certData["en_cert"].(string)
|
||||
enCertWriter, err := zipWriter.Create("en_cert.pem")
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
if _, err := enCertWriter.Write([]byte(enCertStr)); err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
// en_key.pem
|
||||
enKeyStr := certData["en_key"].(string)
|
||||
enKeyWriter, err := zipWriter.Create("en_key.pem")
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
if _, err := enKeyWriter.Write([]byte(enKeyStr)); err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if certData["algorithm"] == "ecdsa" || certData["algorithm"] == "rsa" {
|
||||
// cert.pfx
|
||||
pfxPassword := "allinssl"
|
||||
pfxData, err := public.PEMToPFX(certStr, keyStr, pfxPassword)
|
||||
if err == nil && len(pfxData) > 0 {
|
||||
pfxWriter, err := zipWriter.Create("IIS/cert.pfx")
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
if _, err := pfxWriter.Write(pfxData); err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
txtWriter, err := zipWriter.Create("IIS/passwd.txt")
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
if _, err := txtWriter.Write([]byte(pfxPassword)); err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭 zipWriter
|
||||
if err := zipWriter.Close(); err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
// 设置响应头
|
||||
zipName := strings.ReplaceAll(certData["cn"].(string), ".", "_")
|
||||
zipName = strings.ReplaceAll(zipName, ",", "-")
|
||||
c.Header("Content-Type", "application/zip")
|
||||
c.Header("Content-Disposition", "attachment; filename="+zipName+".zip")
|
||||
c.Data(200, "application/zip", buf.Bytes())
|
||||
return
|
||||
}
|
||||
102
frontend/allinssl/backend/app/api/report.go
Normal file
102
frontend/allinssl/backend/app/api/report.go
Normal file
@@ -0,0 +1,102 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"ALLinSSL/backend/internal/report"
|
||||
"ALLinSSL/backend/public"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func GetReportList(c *gin.Context) {
|
||||
var form struct {
|
||||
Search string `form:"search"`
|
||||
Page int64 `form:"p"`
|
||||
Limit int64 `form:"limit"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
certList, count, err := report.GetList(form.Search, form.Page, form.Limit)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessData(c, certList, count)
|
||||
return
|
||||
}
|
||||
|
||||
func AddReport(c *gin.Context) {
|
||||
var form struct {
|
||||
Name string `form:"name"`
|
||||
Type string `form:"type"`
|
||||
Config string `form:"config"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
// fmt.Println(err)
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
err = report.AddReport(form.Type, form.Config, form.Name)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "添加成功")
|
||||
return
|
||||
}
|
||||
|
||||
func UpdReport(c *gin.Context) {
|
||||
var form struct {
|
||||
Id string `form:"id"`
|
||||
Name string `form:"name"`
|
||||
Config string `form:"config"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
err = report.UpdReport(form.Id, form.Config, form.Name)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "修改成功")
|
||||
return
|
||||
}
|
||||
|
||||
func DelReport(c *gin.Context) {
|
||||
var form struct {
|
||||
Id string `form:"id"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
err = report.DelReport(form.Id)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "删除成功")
|
||||
}
|
||||
|
||||
func NotifyTest(c *gin.Context) {
|
||||
var form struct {
|
||||
Id string `form:"id"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
err = report.NotifyTest(form.Id)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "发送成功")
|
||||
}
|
||||
88
frontend/allinssl/backend/app/api/setting.go
Normal file
88
frontend/allinssl/backend/app/api/setting.go
Normal file
@@ -0,0 +1,88 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"ALLinSSL/backend/internal/setting"
|
||||
"ALLinSSL/backend/public"
|
||||
"github.com/gin-gonic/gin"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func GetSetting(c *gin.Context) {
|
||||
data, err := setting.Get()
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessData(c, data, 0)
|
||||
}
|
||||
|
||||
func SaveSetting(c *gin.Context) {
|
||||
var data setting.Setting
|
||||
if err := c.Bind(&data); err != nil {
|
||||
public.FailMsg(c, "参数错误")
|
||||
return
|
||||
}
|
||||
if err := setting.Save(&data); err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "保存成功")
|
||||
|
||||
}
|
||||
|
||||
func Shutdown(c *gin.Context) {
|
||||
setting.Shutdown()
|
||||
public.SuccessMsg(c, "关闭成功")
|
||||
}
|
||||
|
||||
func Restart(c *gin.Context) {
|
||||
setting.Restart()
|
||||
public.SuccessMsg(c, "正在重启...")
|
||||
}
|
||||
|
||||
func GetVersion(c *gin.Context) {
|
||||
data, err := setting.GetVersion()
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessData(c, data, 0)
|
||||
}
|
||||
|
||||
func DownloadData(c *gin.Context) {
|
||||
dbPath := "data/data.db"
|
||||
dbName := filepath.Base(dbPath)
|
||||
|
||||
// 设置响应头,让浏览器下载文件
|
||||
c.Header("Content-Type", "application/octet-stream")
|
||||
c.Header("Content-Disposition", "attachment; filename=\""+dbName+"\"")
|
||||
c.File(dbPath)
|
||||
}
|
||||
|
||||
func UploadData(c *gin.Context) {
|
||||
file, err := c.FormFile("file")
|
||||
if err != nil {
|
||||
public.FailMsg(c, "文件上传失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
// 检查文件类型
|
||||
if filepath.Ext(file.Filename) != ".db" {
|
||||
public.FailMsg(c, "只允许上传 .db 文件")
|
||||
return
|
||||
}
|
||||
// 备份源文件
|
||||
// 修改源文件名为 data.db.bak
|
||||
err = os.Rename("data/data.db", "data/data.db.bak")
|
||||
if err != nil {
|
||||
public.FailMsg(c, "备份源文件失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.SaveUploadedFile(file, "data/data.db"); err != nil {
|
||||
public.FailMsg(c, "保存文件失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
public.SuccessMsg(c, "数据上传成功")
|
||||
}
|
||||
236
frontend/allinssl/backend/app/api/workflow.go
Normal file
236
frontend/allinssl/backend/app/api/workflow.go
Normal file
@@ -0,0 +1,236 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"ALLinSSL/backend/internal/workflow"
|
||||
"ALLinSSL/backend/public"
|
||||
"github.com/gin-gonic/gin"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetWorkflowList(c *gin.Context) {
|
||||
var form struct {
|
||||
Search string `form:"search"`
|
||||
Page int64 `form:"p"`
|
||||
Limit int64 `form:"limit"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
// c.JSON(http.StatusBadRequest, public.ResERR(err.Error()))
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
data, count, err := workflow.GetList(form.Search, form.Page, form.Limit)
|
||||
if err != nil {
|
||||
// c.JSON(http.StatusBadRequest, public.ResERR(err.Error()))
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
// c.JSON(http.StatusOK, public.ResOK(len(data), data, ""))
|
||||
public.SuccessData(c, data, count)
|
||||
return
|
||||
}
|
||||
|
||||
func AddWorkflow(c *gin.Context) {
|
||||
var form struct {
|
||||
Name string `form:"name"`
|
||||
Content string `form:"content"`
|
||||
ExecType string `form:"exec_type"`
|
||||
Active string `form:"active"`
|
||||
ExecTime string `form:"exec_time"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
form.Name = strings.TrimSpace(form.Name)
|
||||
form.ExecType = strings.TrimSpace(form.ExecType)
|
||||
|
||||
err = workflow.AddWorkflow(form.Name, form.Content, form.ExecType, form.Active, form.ExecTime)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "添加成功")
|
||||
return
|
||||
}
|
||||
|
||||
func DelWorkflow(c *gin.Context) {
|
||||
var form struct {
|
||||
ID string `form:"id"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
form.ID = strings.TrimSpace(form.ID)
|
||||
|
||||
err = workflow.DelWorkflow(form.ID)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "删除成功")
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
func UpdWorkflow(c *gin.Context) {
|
||||
var form struct {
|
||||
ID string `form:"id"`
|
||||
Name string `form:"name"`
|
||||
Content string `form:"content"`
|
||||
ExecType string `form:"exec_type"`
|
||||
Active string `form:"active"`
|
||||
ExecTime string `form:"exec_time"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
form.ID = strings.TrimSpace(form.ID)
|
||||
form.Name = strings.TrimSpace(form.Name)
|
||||
form.ExecType = strings.TrimSpace(form.ExecType)
|
||||
|
||||
err = workflow.UpdWorkflow(form.ID, form.Name, form.Content, form.ExecType, form.Active, form.ExecTime)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "修改成功")
|
||||
return
|
||||
}
|
||||
|
||||
func UpdExecType(c *gin.Context) {
|
||||
var form struct {
|
||||
ID string `form:"id"`
|
||||
ExecType string `form:"exec_type"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
form.ID = strings.TrimSpace(form.ID)
|
||||
form.ExecType = strings.TrimSpace(form.ExecType)
|
||||
|
||||
err = workflow.UpdExecType(form.ID, form.ExecType)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "修改成功")
|
||||
return
|
||||
}
|
||||
|
||||
func UpdActive(c *gin.Context) {
|
||||
var form struct {
|
||||
ID string `form:"id"`
|
||||
Active string `form:"active"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
form.ID = strings.TrimSpace(form.ID)
|
||||
form.Active = strings.TrimSpace(form.Active)
|
||||
if form.ID == "" {
|
||||
public.FailMsg(c, "ID不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
err = workflow.UpdActive(form.ID, form.Active)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "修改成功")
|
||||
return
|
||||
}
|
||||
|
||||
func ExecuteWorkflow(c *gin.Context) {
|
||||
var form struct {
|
||||
ID string `form:"id"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
form.ID = strings.TrimSpace(form.ID)
|
||||
|
||||
err = workflow.ExecuteWorkflow(form.ID)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "执行成功")
|
||||
return
|
||||
}
|
||||
|
||||
func StopWorkflow(c *gin.Context) {
|
||||
var form struct {
|
||||
ID string `form:"id"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
form.ID = strings.TrimSpace(form.ID)
|
||||
|
||||
err = workflow.StopWorkflow(form.ID)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessMsg(c, "停止成功")
|
||||
return
|
||||
}
|
||||
|
||||
func GetWorkflowHistory(c *gin.Context) {
|
||||
var form struct {
|
||||
ID string `form:"id"`
|
||||
Page int64 `form:"p"`
|
||||
Limit int64 `form:"limit"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
form.ID = strings.TrimSpace(form.ID)
|
||||
|
||||
data, count, err := workflow.GetListWH(form.ID, form.Page, form.Limit)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessData(c, data, count)
|
||||
return
|
||||
}
|
||||
|
||||
func GetExecLog(c *gin.Context) {
|
||||
var form struct {
|
||||
ID string `form:"id"`
|
||||
}
|
||||
err := c.Bind(&form)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
form.ID = strings.TrimSpace(form.ID)
|
||||
|
||||
data, err := workflow.GetExecLog(form.ID)
|
||||
if err != nil {
|
||||
public.FailMsg(c, err.Error())
|
||||
return
|
||||
}
|
||||
public.SuccessData(c, data, 0)
|
||||
return
|
||||
}
|
||||
7
frontend/allinssl/backend/app/dto/response/access.go
Normal file
7
frontend/allinssl/backend/app/dto/response/access.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package response
|
||||
|
||||
type AccessSiteList struct {
|
||||
Id string `json:"id"`
|
||||
SiteName string `json:"siteName"`
|
||||
Domain []string `json:"domain"`
|
||||
}
|
||||
Reference in New Issue
Block a user