BillionMail gives you open-source MailServer, NewsLetter, Email Marketing — fully self-hosted, dev-friendly, and free from monthly fees. Join the discord: https://discord.gg/asfXzBUhZr
added self-signed cert. added frontend single entry. added https support. fixed some bugs.
Jack7c85eb4d157f
diff --git a/core/api/rbac/v1/account.go b/core/api/rbac/v1/account.goindex 3c0c6b17..5065b146 100644--- a/core/api/rbac/v1/account.go+++ b/core/api/rbac/v1/account.go@@ -7,13 +7,12 @@ import (// AccountInfoItem defines the account information structuretype AccountInfoItem struct {- Id int64 `json:"id" dc:"Account ID"`- Username string `json:"username" dc:"Username"`- Email string `json:"email" dc:"Email"`- Status int `json:"status" dc:"Status(0:disabled, 1:enabled)"`- Lang string `json:"lang" dc:"Language setting"`- CreatedAt string `json:"createdAt" dc:"Creation time"`- UpdatedAt string `json:"updatedAt" dc:"Update time"`+ Id int64 `json:"id" dc:"Account ID"`+ Username string `json:"username" dc:"Username"`+ Email string `json:"email" dc:"Email"`+ Status int `json:"status" dc:"Status(0:disabled, 1:enabled)"`+ Language string `json:"language" dc:"Language setting"`+ CreateTime int64 `json:"create_time" dc:"Creation time"`}// AccountListReq defines the request for getting account listdiff --git a/core/api/rbac/v1/auth.go b/core/api/rbac/v1/auth.goindex d20bef8b..355799f4 100644--- a/core/api/rbac/v1/auth.go+++ b/core/api/rbac/v1/auth.go@@ -67,12 +67,11 @@ type CurrentUserRes struct {api_v1.StandardResData struct {Account struct {- Id int64 `json:"id" dc:"Account ID"`- Username string `json:"username" dc:"Username"`- Email string `json:"email" dc:"Email address"`- Status int `json:"status" dc:"Account status"`- Lang string `json:"lang" dc:"Preferred language"`- CreatedAt string `json:"createdAt" dc:"Creation time"`+ Id int64 `json:"id" dc:"Account ID"`+ Username string `json:"username" dc:"Username"`+ Email string `json:"email" dc:"Email address"`+ Status int `json:"status" dc:"Account status"`+ Lang string `json:"lang" dc:"Preferred language"`} `json:"account" dc:"Account information"`Roles []string `json:"roles" dc:"User roles"`Permissions []string `json:"permissions" dc:"User permissions"`diff --git a/core/api/rbac/v1/permission.go b/core/api/rbac/v1/permission.goindex 431cc635..e840ceef 100644--- a/core/api/rbac/v1/permission.go+++ b/core/api/rbac/v1/permission.go@@ -14,8 +14,8 @@ type PermissionInfoItem struct {Action string `json:"action" dc:"Action name (create/read/update/delete)"`Resource string `json:"resource" dc:"Resource name"`Status int `json:"status" dc:"Status (0:disabled, 1:enabled)"`- CreatedAt string `json:"createdAt" dc:"Creation time"`- UpdatedAt string `json:"updatedAt" dc:"Update time"`+ CreateTime int64 `json:"create_time" dc:"Creation time"`+ UpdateTime int64 `json:"update_time" dc:"Update time"`}// PermissionListReq defines the request for getting permission listdiff --git a/core/api/rbac/v1/role.go b/core/api/rbac/v1/role.goindex bb9f19fa..a89a26a1 100644--- a/core/api/rbac/v1/role.go+++ b/core/api/rbac/v1/role.go@@ -11,8 +11,7 @@ type RoleInfoItem struct {Name string `json:"name" dc:"Role name"`Description string `json:"description" dc:"Role description"`Status int `json:"status" dc:"Status (0:disabled, 1:enabled)"`- CreatedAt string `json:"createdAt" dc:"Creation time"`- UpdatedAt string `json:"updatedAt" dc:"Update time"`+ CreateTime int64 `json:"create_time" dc:"Creation time"`}// RoleListReq defines the request for getting role listdiff --git a/core/internal/cmd/cmd.go b/core/internal/cmd/cmd.goindex 9f1e79ad..c9ec94d2 100644--- a/core/internal/cmd/cmd.go+++ b/core/internal/cmd/cmd.go@@ -11,6 +11,7 @@ import (docker "billionmail-core/internal/service/dockerapi""billionmail-core/internal/service/middlewares""billionmail-core/internal/service/phpfpm"+ "billionmail-core/internal/service/public"rbac2 "billionmail-core/internal/service/rbac""billionmail-core/internal/service/redis_initialization""context"@@ -142,6 +143,16 @@ var (proxy.ServeHTTP(r.Response.Writer, r.Request)})+ s.BindHandler("/*", func(r *ghttp.Request) {+ r.Response.ServeFile("public/dist/index.html")+ })++ // Generate self-signed certificate if not exists+ public.SelfSignedCert().Generate()++ s.EnableHTTPS(public.AbsPath("../ssl/certificate.pem"), public.AbsPath("../ssl/privateKey.pem"))+ s.SetHTTPSPort(g.Cfg().MustGet(ctx, "server.httpsPort", 443).Int())+s.Run()return nildiff --git a/core/internal/controller/rbac/rbac_v1_account.go b/core/internal/controller/rbac/rbac_v1_account.goindex a59496a7..a2984c6e 100644--- a/core/internal/controller/rbac/rbac_v1_account.go+++ b/core/internal/controller/rbac/rbac_v1_account.go@@ -41,13 +41,12 @@ func (c *ControllerV1) AccountList(ctx context.Context, req *v1.AccountListReq)res.Data.List = make([]v1.AccountInfoItem, 0, len(accounts))for _, account := range accounts {res.Data.List = append(res.Data.List, v1.AccountInfoItem{- Id: account.Id,- Username: account.Username,- Email: account.Email,- Status: account.Status,- Lang: account.Lang,- CreatedAt: account.CreatedAt.Format("2006-01-02 15:04:05"),- UpdatedAt: account.UpdatedAt.Format("2006-01-02 15:04:05"),+ Id: account.AccountId,+ Username: account.Username,+ Email: account.Email,+ Status: account.Status,+ Language: account.Language,+ CreateTime: account.CreateTime,})}@@ -92,25 +91,23 @@ func (c *ControllerV1) AccountDetail(ctx context.Context, req *v1.AccountDetailR// Set account infores.Data.Account = v1.AccountInfoItem{- Id: account.Id,- Username: account.Username,- Email: account.Email,- Status: account.Status,- Lang: account.Lang,- CreatedAt: account.CreatedAt.Format("2006-01-02 15:04:05"),- UpdatedAt: account.UpdatedAt.Format("2006-01-02 15:04:05"),+ Id: account.AccountId,+ Username: account.Username,+ Email: account.Email,+ Status: account.Status,+ Language: account.Language,+ CreateTime: account.CreateTime,}// Set account rolesres.Data.Roles = make([]v1.RoleInfoItem, 0, len(roles))for _, role := range roles {res.Data.Roles = append(res.Data.Roles, v1.RoleInfoItem{- Id: role.Id,- Name: role.Name,+ Id: role.RoleId,+ Name: role.RoleName,Description: role.Description,Status: role.Status,- CreatedAt: role.CreatedAt.Format("2006-01-02 15:04:05"),- UpdatedAt: role.UpdatedAt.Format("2006-01-02 15:04:05"),+ CreateTime: role.CreateTime,})}@@ -118,12 +115,11 @@ func (c *ControllerV1) AccountDetail(ctx context.Context, req *v1.AccountDetailRres.Data.AllRoles = make([]v1.RoleInfoItem, 0, len(allRoles))for _, role := range allRoles {res.Data.AllRoles = append(res.Data.AllRoles, v1.RoleInfoItem{- Id: role.Id,- Name: role.Name,+ Id: role.RoleId,+ Name: role.RoleName,Description: role.Description,Status: role.Status,- CreatedAt: role.CreatedAt.Format("2006-01-02 15:04:05"),- UpdatedAt: role.UpdatedAt.Format("2006-01-02 15:04:05"),+ CreateTime: role.CreateTime,})}@@ -168,7 +164,7 @@ func (c *ControllerV1) AccountCreate(ctx context.Context, req *v1.AccountCreateRPassword: req.Password,Email: req.Email,Status: req.Status,- Lang: req.Lang,+ Language: req.Lang,}accountId, err := service.Account().Create(ctx, accountData)@@ -241,12 +237,12 @@ func (c *ControllerV1) AccountUpdate(ctx context.Context, req *v1.AccountUpdateR// Update account infoupdateData := &model.Account{- Id: req.AccountId,- Username: req.Username,- Email: req.Email,- Status: req.Status,- Lang: req.Lang,- UpdatedAt: time.Now(),+ AccountId: req.AccountId,+ Username: req.Username,+ Email: req.Email,+ Status: req.Status,+ Language: req.Lang,+ UpdateTime: time.Now().Unix(),}err = service.Account().Update(ctx, updateData)diff --git a/core/internal/controller/rbac/rbac_v1_auth.go b/core/internal/controller/rbac/rbac_v1_auth.goindex 088293e9..f342a25c 100644--- a/core/internal/controller/rbac/rbac_v1_auth.go+++ b/core/internal/controller/rbac/rbac_v1_auth.go@@ -1,11 +1,11 @@package rbacimport (+ "billionmail-core/api/rbac/v1"service "billionmail-core/internal/service/rbac""context"+ "fmt""github.com/gogf/gf/util/gconv"-- "billionmail-core/api/rbac/v1""github.com/gogf/gf/v2/errors/gerror")@@ -21,27 +21,27 @@ func (c *ControllerV1) Login(ctx context.Context, req *v1.LoginReq) (res *v1.Log}// Get account roles- roles, err := service.Account().GetAccountRoles(ctx, account.Id)+ roles, err := service.Account().GetAccountRoles(ctx, account.AccountId)if err != nil {- res.SetError(gerror.New("Failed to get account roles"))- return res, nil+ err = fmt.Errorf("Failed to get account roles: %w", err)+ return}// Convert roles to role namesroleNames := make([]string, 0, len(roles))for _, role := range roles {- roleNames = append(roleNames, role.Name)+ roleNames = append(roleNames, role.RoleName)}// Generate JWT token- token, _, err := service.JWT().GenerateToken(account.Id, account.Username, roleNames)+ token, _, err := service.JWT().GenerateToken(account.AccountId, account.Username, roleNames)if err != nil {res.SetError(gerror.New("Failed to generate token"))return res, nil}// Generate refresh token- refreshToken, err := service.JWT().GenerateRefreshToken(account.Id, account.Username)+ refreshToken, err := service.JWT().GenerateRefreshToken(account.AccountId, account.Username)if err != nil {res.SetError(gerror.New("Failed to generate refresh token"))return res, nil@@ -56,11 +56,11 @@ func (c *ControllerV1) Login(ctx context.Context, req *v1.LoginReq) (res *v1.Logres.Data.TTL = gconv.Int64(service.JWT().AccessExpiry.Seconds())// Set account basic information- res.Data.AccountInfo.Id = account.Id+ res.Data.AccountInfo.Id = account.AccountIdres.Data.AccountInfo.Username = account.Usernameres.Data.AccountInfo.Email = account.Emailres.Data.AccountInfo.Status = account.Status- res.Data.AccountInfo.Lang = account.Lang+ res.Data.AccountInfo.Lang = account.Languagereturn res, nil}@@ -133,29 +133,29 @@ func (c *ControllerV1) CurrentUser(ctx context.Context, req *v1.CurrentUserReq)// Get account ID from contextaccountId := service.GetCurrentAccountId(ctx)if accountId == 0 {- res.SetError(gerror.New("Unauthorized"))- return res, nil+ err = gerror.New("Unauthorized")+ return}// Get account detailsaccount, err := service.Account().GetById(ctx, accountId)if err != nil {- res.SetError(gerror.New("Failed to get account details"))- return res, nil+ err = gerror.New("Failed to get account details")+ return}// Get account rolesroles, err := service.Account().GetAccountRoles(ctx, accountId)if err != nil {- res.SetError(gerror.New("Failed to get account roles"))- return res, nil+ err = gerror.New("Failed to get account roles")+ return}// Get account permissionspermissions, err := service.Account().GetAccountPermissions(ctx, accountId)if err != nil {- res.SetError(gerror.New("Failed to get account permissions"))- return res, nil+ err = gerror.New("Failed to get account permissions")+ return}// Prepare response@@ -164,17 +164,16 @@ func (c *ControllerV1) CurrentUser(ctx context.Context, req *v1.CurrentUserReq)res.Msg = "Retrieved successfully"// Set account information- res.Data.Account.Id = account.Id+ res.Data.Account.Id = account.AccountIdres.Data.Account.Username = account.Usernameres.Data.Account.Email = account.Emailres.Data.Account.Status = account.Status- res.Data.Account.Lang = account.Lang- res.Data.Account.CreatedAt = account.CreatedAt.Format("2006-01-02 15:04:05")+ res.Data.Account.Lang = account.Language// Set rolesres.Data.Roles = make([]string, 0, len(roles))for _, role := range roles {- res.Data.Roles = append(res.Data.Roles, role.Name)+ res.Data.Roles = append(res.Data.Roles, role.RoleName)}// Set permissionsdiff --git a/core/internal/controller/rbac/rbac_v1_role.go b/core/internal/controller/rbac/rbac_v1_role.goindex fc64cbcf..8b00d7c9 100644--- a/core/internal/controller/rbac/rbac_v1_role.go+++ b/core/internal/controller/rbac/rbac_v1_role.go@@ -39,12 +39,11 @@ func (c *ControllerV1) RoleList(ctx context.Context, req *v1.RoleListReq) (res *res.Data.List = make([]v1.RoleInfoItem, 0, len(roles))for _, role := range roles {res.Data.List = append(res.Data.List, v1.RoleInfoItem{- Id: role.Id,- Name: role.Name,+ Id: role.RoleId,+ Name: role.RoleName,Description: role.Description,Status: role.Status,- CreatedAt: role.CreatedAt.Format("2006-01-02 15:04:05"),- UpdatedAt: role.UpdatedAt.Format("2006-01-02 15:04:05"),+ CreateTime: role.CreateTime,})}@@ -89,27 +88,26 @@ func (c *ControllerV1) RoleDetail(ctx context.Context, req *v1.RoleDetailReq) (r// Set role informationres.Data.Role = v1.RoleInfoItem{- Id: role.Id,- Name: role.Name,+ Id: role.RoleId,+ Name: role.RoleName,Description: role.Description,Status: role.Status,- CreatedAt: role.CreatedAt.Format("2006-01-02 15:04:05"),- UpdatedAt: role.UpdatedAt.Format("2006-01-02 15:04:05"),+ CreateTime: role.CreateTime,}// Set role permissionsres.Data.Permissions = make([]v1.PermissionInfoItem, 0, len(permissions))for _, perm := range permissions {res.Data.Permissions = append(res.Data.Permissions, v1.PermissionInfoItem{- Id: perm.Id,- Name: perm.Name,+ Id: perm.PermissionId,+ Name: perm.PermissionName,Description: perm.Description,Module: perm.Module,Action: perm.Action,Resource: perm.Resource,Status: perm.Status,- CreatedAt: perm.CreatedAt.Format("2006-01-02 15:04:05"),- UpdatedAt: perm.UpdatedAt.Format("2006-01-02 15:04:05"),+ CreateTime: perm.CreateTime,+ UpdateTime: perm.UpdateTime,})}@@ -117,15 +115,15 @@ func (c *ControllerV1) RoleDetail(ctx context.Context, req *v1.RoleDetailReq) (rres.Data.AllPermissions = make([]v1.PermissionInfoItem, 0, len(allPermissions))for _, perm := range allPermissions {res.Data.AllPermissions = append(res.Data.AllPermissions, v1.PermissionInfoItem{- Id: perm.Id,- Name: perm.Name,+ Id: perm.PermissionId,+ Name: perm.PermissionName,Description: perm.Description,Module: perm.Module,Action: perm.Action,Resource: perm.Resource,Status: perm.Status,- CreatedAt: perm.CreatedAt.Format("2006-01-02 15:04:05"),- UpdatedAt: perm.UpdatedAt.Format("2006-01-02 15:04:05"),+ CreateTime: perm.CreateTime,+ UpdateTime: perm.UpdateTime,})}@@ -196,13 +194,13 @@ func (c *ControllerV1) RoleUpdate(ctx context.Context, req *v1.RoleUpdateReq) (r}// Check if it's admin role- if role.Name == "admin" && req.Name != "admin" {+ if role.RoleName == "admin" && req.Name != "admin" {res.SetError(gerror.New("Cannot modify the name of admin role"))return res, nil}// Check if role name already exists- if req.Name != "" && req.Name != role.Name {+ if req.Name != "" && req.Name != role.RoleName {exists, err := service.Role().NameExists(ctx, req.Name)if err != nil {res.SetError(gerror.New("Failed to check role name: " + err.Error()))@@ -265,7 +263,7 @@ func (c *ControllerV1) RoleDelete(ctx context.Context, req *v1.RoleDeleteReq) (r}// Check if it's a reserved role- if role.Name == "admin" || role.Name == "user" {+ if role.RoleName == "admin" || role.RoleName == "user" {res.SetError(gerror.New("Cannot delete system reserved roles"))return res, nil}diff --git a/core/internal/model/entity/account.go b/core/internal/model/entity/account.goindex 1dc8a0bf..6e51d67d 100644--- a/core/internal/model/entity/account.go+++ b/core/internal/model/entity/account.go@@ -2,13 +2,13 @@ package entity// Account defines the account entitytype Account struct {- AccountId int `json:"account_id" dc:"Account ID"`+ AccountId int64 `json:"account_id" dc:"Account ID"`Username string `json:"username" dc:"Username"`- Password string `json:"password" dc:"Password"`+ Password string `json:"-" dc:"Password"`Email string `json:"email" dc:"Email address"`Status int `json:"status" dc:"Status: 1-active, 0-disabled"`Language string `json:"language" dc:"Language setting"`- LastLoginTime int `json:"last_login_time" dc:"Last login time"`- CreateTime int `json:"create_time" dc:"Creation time"`- UpdateTime int `json:"update_time" dc:"Update time"`+ LastLoginTime int64 `json:"last_login_time" dc:"Last login time"`+ CreateTime int64 `json:"create_time" dc:"Creation time"`+ UpdateTime int64 `json:"update_time" dc:"Update time"`}diff --git a/core/internal/model/entity/account_role.go b/core/internal/model/entity/account_role.goindex 97ce3a1b..35640f94 100644--- a/core/internal/model/entity/account_role.go+++ b/core/internal/model/entity/account_role.go@@ -2,8 +2,8 @@ package entity// AccountRole defines the account-role relationship entitytype AccountRole struct {- Id int `json:"id" dc:"Relation ID"`- AccountId int `json:"account_id" dc:"Account ID"`- RoleId int `json:"role_id" dc:"Role ID"`- CreateTime int `json:"create_time" dc:"Creation time"`+ Id int64 `json:"id" dc:"Relation ID"`+ AccountId int64 `json:"account_id" dc:"Account ID"`+ RoleId int64 `json:"role_id" dc:"Role ID"`+ CreateTime int64 `json:"create_time" dc:"Creation time"`}diff --git a/core/internal/model/entity/alias.go b/core/internal/model/entity/alias.goindex c07de7b4..806e8472 100644--- a/core/internal/model/entity/alias.go+++ b/core/internal/model/entity/alias.go@@ -5,7 +5,7 @@ type Alias struct {Address string `json:"address" dc:"Alias address"`Goto string `json:"goto" dc:"Forwarding target"`Domain string `json:"domain" dc:"Domain name"`- CreateTime int `json:"create_time" dc:"Creation time"`- UpdateTime int `json:"update_time" dc:"Update time"`+ CreateTime int64 `json:"create_time" dc:"Creation time"`+ UpdateTime int64 `json:"update_time" dc:"Update time"`Active int `json:"active" dc:"Status: 1-enabled, 0-disabled"`}diff --git a/core/internal/model/entity/alias_domain.go b/core/internal/model/entity/alias_domain.goindex cc41c71b..c07accd1 100644--- a/core/internal/model/entity/alias_domain.go+++ b/core/internal/model/entity/alias_domain.go@@ -4,7 +4,7 @@ package entitytype AliasDomain struct {AliasDomain string `json:"alias_domain" dc:"Alias domain name"`TargetDomain string `json:"target_domain" dc:"Target domain name"`- CreateTime int `json:"create_time" dc:"Creation time"`- UpdateTime int `json:"update_time" dc:"Update time"`+ CreateTime int64 `json:"create_time" dc:"Creation time"`+ UpdateTime int64 `json:"update_time" dc:"Update time"`Active int `json:"active" dc:"Status: 1-enabled, 0-disabled"`}diff --git a/core/internal/model/entity/permission.go b/core/internal/model/entity/permission.goindex fda2143e..3df5f980 100644--- a/core/internal/model/entity/permission.go+++ b/core/internal/model/entity/permission.go@@ -2,13 +2,13 @@ package entity// Permission defines the permission entitytype Permission struct {- PermissionId int `json:"permission_id" dc:"Permission ID"`+ PermissionId int64 `json:"permission_id" dc:"Permission ID"`PermissionName string `json:"permission_name" dc:"Permission name"`Description string `json:"description" dc:"Permission description"`Module string `json:"module" dc:"Module name"`Action string `json:"action" dc:"Action type: create/read/update/delete"`Resource string `json:"resource" dc:"Resource type"`Status int `json:"status" dc:"Status: 1-active, 0-disabled"`- CreateTime int `json:"create_time" dc:"Creation time"`- UpdateTime int `json:"update_time" dc:"Update time"`+ CreateTime int64 `json:"create_time" dc:"Creation time"`+ UpdateTime int64 `json:"update_time" dc:"Update time"`}diff --git a/core/internal/model/entity/role.go b/core/internal/model/entity/role.goindex 26e2683f..820fca65 100644--- a/core/internal/model/entity/role.go+++ b/core/internal/model/entity/role.go@@ -2,10 +2,10 @@ package entity// Role defines the role entitytype Role struct {- RoleId int `json:"role_id" dc:"Role ID"`+ RoleId int64 `json:"role_id" dc:"Role ID"`RoleName string `json:"role_name" dc:"Role name"`Description string `json:"description" dc:"Role description"`Status int `json:"status" dc:"Status: 1-active, 0-disabled"`- CreateTime int `json:"create_time" dc:"Creation time"`- UpdateTime int `json:"update_time" dc:"Update time"`+ CreateTime int64 `json:"create_time" dc:"Creation time"`+ UpdateTime int64 `json:"update_time" dc:"Update time"`}diff --git a/core/internal/model/entity/role_permission.go b/core/internal/model/entity/role_permission.goindex 9c3c7132..9a512311 100644--- a/core/internal/model/entity/role_permission.go+++ b/core/internal/model/entity/role_permission.go@@ -2,8 +2,8 @@ package entity// RolePermission defines the role-permission relationship entitytype RolePermission struct {- Id int `json:"id" dc:"Relation ID"`- RoleId int `json:"role_id" dc:"Role ID"`- PermissionId int `json:"permission_id" dc:"Permission ID"`- CreateTime int `json:"create_time" dc:"Creation time"`+ Id int64 `json:"id" dc:"Relation ID"`+ RoleId int64 `json:"role_id" dc:"Role ID"`+ PermissionId int64 `json:"permission_id" dc:"Permission ID"`+ CreateTime int64 `json:"create_time" dc:"Creation time"`}diff --git a/core/internal/model/rbac.go b/core/internal/model/rbac.goindex f28b28e5..fcb21ca9 100644--- a/core/internal/model/rbac.go+++ b/core/internal/model/rbac.go@@ -1,58 +1,18 @@package model-import (- "time"-)+import "billionmail-core/internal/model/entity"// Account defines the account model-type Account struct {- Id int64 `json:"account_id"` // ID- Username string `json:"username"` // Username- Email string `json:"email"` // Email- Password string `json:"-"` // Password (hidden in JSON output)- Status int `json:"status"` // Status 0:disabled 1:enabled- Lang string `json:"lang"` // Language setting- CreatedAt time.Time `json:"created_at"` // Creation time- UpdatedAt time.Time `json:"updated_at"` // Update time-}+type Account entity.Account// Role defines the role model-type Role struct {- Id int64 `json:"role_id"` // ID- Name string `json:"name"` // Role name- Description string `json:"description"` // Description- Status int `json:"status"` // Status 0:disabled 1:enabled- CreatedAt time.Time `json:"created_at"` // Creation time- UpdatedAt time.Time `json:"updated_at"` // Update time-}+type Role entity.Role// Permission defines the permission model-type Permission struct {- Id int64 `json:"id"` // ID- Name string `json:"name"` // Permission name- Description string `json:"description"` // Description- Module string `json:"module"` // Module- Action string `json:"action"` // Action- Resource string `json:"resource"` // Resource- Status int `json:"status"` // Status 0:disabled 1:enabled- CreatedAt time.Time `json:"created_at"` // Creation time- UpdatedAt time.Time `json:"updated_at"` // Update time-}+type Permission entity.Permission// AccountRole defines the account-role relationship model-type AccountRole struct {- Id int64 `json:"id"` // ID- AccountId int64 `json:"account_id"` // Account ID- RoleId int64 `json:"role_id"` // Role ID- CreatedAt time.Time `json:"created_at"` // Creation time- UpdatedAt time.Time `json:"updated_at"` // Update time-}+type AccountRole entity.AccountRole// RolePermission defines the role-permission relationship model-type RolePermission struct {- Id int64 `json:"id"` // ID- RoleId int64 `json:"role_id"` // Role ID- PermissionId int64 `json:"permission_id"` // Permission ID- CreatedAt time.Time `json:"created_at"` // Creation time- UpdatedAt time.Time `json:"updated_at"` // Update time-}+type RolePermission entity.RolePermissiondiff --git a/core/internal/service/public/common.go b/core/internal/service/public/common.goindex fef3826f..2e236ae2 100644--- a/core/internal/service/public/common.go+++ b/core/internal/service/public/common.go@@ -2070,6 +2070,36 @@ func GetServerIP() (string, error) {return strings.TrimSpace(string(ip)), nil}+// GetLocalIP retrieves the server's local IP address.+func GetLocalIP() (string, error) {+ addrs, err := net.InterfaceAddrs()+ if err != nil {+ return "", err+ }++ for _, addr := range addrs {+ if ipNet, ok := addr.(*net.IPNet); ok && !ipNet.IP.IsLoopback() && ipNet.IP.To4() != nil {+ return ipNet.IP.String(), nil+ }+ }+ return "", errors.New("local IP not found")+}++// GetServerIPAndLocalIP retrieves the server's public and local IP addresses.+func GetServerIPAndLocalIP() (string, string, error) {+ publicIP, err := GetServerIP()+ if err != nil {+ return "", "", err+ }++ localIP, err := GetLocalIP()+ if err != nil {+ return "", "", err+ }++ return publicIP, localIP, nil+}+// Get server portfunc GetServerPort(ctx context.Context) string {r := ghttp.RequestFromCtx(ctx)diff --git a/core/internal/service/public/self_signed_cert.go b/core/internal/service/public/self_signed_cert.gonew file mode 100644index 00000000..545ae407--- /dev/null+++ b/core/internal/service/public/self_signed_cert.go@@ -0,0 +1,261 @@+package public++import (+ "context"+ "crypto/rand"+ "crypto/rsa"+ "crypto/x509"+ "crypto/x509/pkix"+ "encoding/pem"+ "github.com/gogf/gf/v2/os/glog"+ "io/fs"+ "math/big"+ random "math/rand"+ "net"+ "os"+ "path/filepath"+ "time"+)++type selfSignedCertProvider struct {+ certFile string+ privateKeyFile string+}++// SelfSignedCert creates a new self-signed certificate provider+func SelfSignedCert() *selfSignedCertProvider {+ return &selfSignedCertProvider{+ certFile: AbsPath("../ssl/certificate.pem"),+ privateKeyFile: AbsPath("../ssl/privateKey.pem"),+ }+}++// Generate creates self-signed certificate if not exists+func (sp *selfSignedCertProvider) Generate() {+ // Only generate when SSL certificate not configured+ _, certFileExists := os.Stat(sp.certFile)+ _, privateKeyFileExists := os.Stat(sp.privateKeyFile)++ if certFileExists == nil && privateKeyFileExists == nil {+ return+ }++ glog.Debug(context.Background(), "No SSL certificate configured, generating self-signed certificate...")++ if err := sp.createOffline(); err != nil {+ return+ }++ glog.Debug(context.Background(), "Self-signed certificate generated successfully")+}++// createOffline creates self-signed certificate offline+func (sp *selfSignedCertProvider) createOffline() error {+ // Ensure ssl directory exists+ err := os.MkdirAll(filepath.Dir(sp.certFile), 0644)++ if err != nil {+ glog.Error(context.Background(), "Failed to generate self-signed certificate:", err)+ return err+ }++ csr, key, err := sp.createCertWithDynamic()++ if err != nil {+ glog.Error(context.Background(), "Failed to generate self-signed certificate:", err)+ return err+ }++ err = os.WriteFile(sp.certFile, csr, fs.ModePerm)++ if err != nil {+ glog.Error(context.Background(), "Failed to generate self-signed certificate:", err)+ return err+ }++ err = os.WriteFile(sp.privateKeyFile, key, fs.ModePerm)++ if err != nil {+ glog.Error(context.Background(), "Failed to generate self-signed certificate:", err)+ return err+ }++ return nil+}++// createCertWithRoot generates certificate using existing CA+func (sp *selfSignedCertProvider) createCertWithRoot(rootCa, rootKey []byte) ([]byte, []byte, error) {+ // Load CA certificate+ ca, caKey, err := sp.loadRootCertificate(rootCa, rootKey)++ if err != nil {+ glog.Error(context.Background(), "Failed to load CA certificate:", err)+ return []byte{}, []byte{}, err+ }++ // Generate certificate template+ templateCsr := sp.generateCertTemplate()++ // Issue certificate+ csr, key, err := sp.generateCert(ca, templateCsr, caKey)++ if err != nil {+ glog.Error(context.Background(), "Failed to issue certificate:", err)+ return []byte{}, []byte{}, err+ }++ return csr, key, nil+}++// createCertWithDynamic dynamically generates CA certificate and issues certificate+func (sp *selfSignedCertProvider) createCertWithDynamic() ([]byte, []byte, error) {+ templateCa := sp.generateCACertTemplate()++ caCsr, caKey, err := sp.generateCACert(templateCa)++ if err != nil {+ return []byte{}, []byte{}, err+ }++ return sp.createCertWithRoot(caCsr, caKey)+}++// loadRootCertificate loads CA certificate and private key+func (sp *selfSignedCertProvider) loadRootCertificate(rootCa, rootKey []byte) (*x509.Certificate, *rsa.PrivateKey, error) {+ // Parse root certificate+ caBlock, _ := pem.Decode(rootCa)+ rootCert, err := x509.ParseCertificate(caBlock.Bytes)++ if err != nil {+ return nil, nil, err+ }++ // Parse private key+ keyBlock, _ := pem.Decode(rootKey)+ praKey, err := x509.ParsePKCS1PrivateKey(keyBlock.Bytes)+ if err != nil {+ return nil, nil, err+ }++ return rootCert, praKey, nil+}++// generateCACertTemplate generates CA certificate template+func (sp *selfSignedCertProvider) generateCACertTemplate() *x509.Certificate {+ commonName := "Billion-Mail"+ rd := random.New(random.NewSource(time.Now().UnixNano()))+ cer := &x509.Certificate{+ SerialNumber: big.NewInt(rd.Int63()), // Certificate serial number+ Subject: pkix.Name{+ Country: []string{"HK"},+ Organization: []string{"aaPanel"},+ OrganizationalUnit: []string{"aaPanel"},+ Province: []string{"HongKong"},+ CommonName: commonName,+ Locality: []string{"HongKong"},+ },+ NotBefore: time.Now(), // Validity start time+ NotAfter: time.Now().AddDate(1, 0, 0), // Validity end time+ BasicConstraintsValid: true, // Basic constraints+ IsCA: true, // Is CA certificate+ ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth, x509.ExtKeyUsageServerAuth}, // Certificate purposes+ KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign,+ EmailAddresses: []string{"[email protected]"},+ }++ return cer+}++// generateCertTemplate generates certificate template+func (sp *selfSignedCertProvider) generateCertTemplate() *x509.Certificate {+ // Get server IP+ serverIp, localIp, err := GetServerIPAndLocalIP()++ if err != nil {+ glog.Error(context.Background(), "Failed to get server IP:", err)+ return nil+ }++ commonName := "Billion-Mail"+ rd := random.New(random.NewSource(time.Now().UnixNano()))+ cer := &x509.Certificate{+ SerialNumber: big.NewInt(rd.Int63()), // Certificate serial number+ Subject: pkix.Name{+ Country: []string{"HK"},+ Organization: []string{"aaPanel"},+ OrganizationalUnit: []string{"aaPanel"},+ Province: []string{"HongKong"},+ CommonName: commonName,+ Locality: []string{"HongKong"},+ },+ NotBefore: time.Now(), // Validity start time+ NotAfter: time.Now().AddDate(1, 0, 0), // Validity end time+ BasicConstraintsValid: true, // Basic constraints+ IsCA: false, // Is CA certificate+ ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth, x509.ExtKeyUsageServerAuth}, // Certificate purposes+ KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageDataEncipherment,+ EmailAddresses: []string{"[email protected]"},+ IPAddresses: []net.IP{net.ParseIP(serverIp), net.ParseIP(localIp)}, // Supported IP addresses+ DNSNames: []string{}, // Supported domains+ }++ return cer+}++// generateCACert issues CA certificate+func (sp *selfSignedCertProvider) generateCACert(templateCert *x509.Certificate) ([]byte, []byte, error) {+ // Generate key pair+ priKey, err := rsa.GenerateKey(rand.Reader, 4096)+ if err != nil {+ return nil, nil, err+ }++ ca, err := x509.CreateCertificate(rand.Reader, templateCert, templateCert, &priKey.PublicKey, priKey)+ if err != nil {+ return nil, nil, err+ }++ // Encode certificate and private key+ caPem := &pem.Block{+ Type: "CERTIFICATE",+ Bytes: ca,+ }+ ca = pem.EncodeToMemory(caPem)+ buf := x509.MarshalPKCS1PrivateKey(priKey)+ keyPem := &pem.Block{+ Type: "PRIVATE KEY",+ Bytes: buf,+ }+ key := pem.EncodeToMemory(keyPem)++ return ca, key, nil+}++// generateCert issues certificate using CA+func (sp *selfSignedCertProvider) generateCert(rootCert, templateCert *x509.Certificate, rootKey *rsa.PrivateKey) ([]byte, []byte, error) {+ // Generate key pair+ priKey, err := rsa.GenerateKey(rand.Reader, 1024)+ if err != nil {+ return nil, nil, err+ }++ ca, err := x509.CreateCertificate(rand.Reader, templateCert, rootCert, &priKey.PublicKey, rootKey)+ if err != nil {+ return nil, nil, err+ }++ // Encode certificate and private key+ caPem := &pem.Block{+ Type: "CERTIFICATE",+ Bytes: ca,+ }+ ca = pem.EncodeToMemory(caPem)+ buf := x509.MarshalPKCS1PrivateKey(priKey)+ keyPem := &pem.Block{+ Type: "PRIVATE KEY",+ Bytes: buf,+ }+ key := pem.EncodeToMemory(keyPem)++ return ca, key, nil+}diff --git a/core/internal/service/rbac/account.go b/core/internal/service/rbac/account.goindex a45339a0..5084cfb4 100644--- a/core/internal/service/rbac/account.go+++ b/core/internal/service/rbac/account.go@@ -66,13 +66,13 @@ func (s *accountService) Create(ctx context.Context, accountData *model.Account)}result, err := g.DB().Model("account").Data(g.Map{- "username": accountData.Username,- "password": string(hashedPassword),- "email": accountData.Email,- "status": accountData.Status,- "lang": accountData.Lang,- "created_at": time.Now(),- "updated_at": time.Now(),+ "username": accountData.Username,+ "password": string(hashedPassword),+ "email": accountData.Email,+ "status": accountData.Status,+ "language": accountData.Language,+ "create_time": time.Now(),+ "update_time": time.Now(),}).Insert()if err != nil {return 0, err@@ -89,12 +89,12 @@ func (s *accountService) Create(ctx context.Context, accountData *model.Account)// Update updates account informationfunc (s *accountService) Update(ctx context.Context, accountData *model.Account) error {_, err := g.DB().Model("account").Data(g.Map{- "username": accountData.Username,- "email": accountData.Email,- "status": accountData.Status,- "lang": accountData.Lang,- "updated_at": time.Now(),- }).Where("account_id = ?", accountData.Id).Update()+ "username": accountData.Username,+ "email": accountData.Email,+ "status": accountData.Status,+ "language": accountData.Language,+ "update_time": time.Now(),+ }).Where("account_id = ?", accountData.AccountId).Update()return err}@@ -148,6 +148,7 @@ func (s *accountService) GetAccountRoles(ctx context.Context, accountId int64) (err := g.DB().Model("role r").LeftJoin("account_role ar", "r.role_id = ar.role_id").Where("ar.account_id = ?", accountId).+ Fields("r.*").Scan(&roles)return roles, err}@@ -241,7 +242,7 @@ func (s *accountService) Login(ctx context.Context, username, password string) (// Update last login time_, err = g.DB().Model("account").Data(g.Map{"last_login_time": time.Now().Unix(),- }).Where("account_id = ?", account.Id).Update()+ }).Where("account_id = ?", account.AccountId).Update()if err != nil {return nil, err}@@ -257,7 +258,7 @@ func (s *accountService) IsAdmin(ctx context.Context, accountId int64) (bool, er}for _, role := range roles {- if role.Name == "admin" {+ if role.RoleName == "admin" {return true, nil}}diff --git a/core/internal/service/rbac/jwt.go b/core/internal/service/rbac/jwt.goindex d8299f14..379ccc76 100644--- a/core/internal/service/rbac/jwt.go+++ b/core/internal/service/rbac/jwt.go@@ -5,6 +5,7 @@ import ("billionmail-core/internal/service/public""context""fmt"+ "github.com/gogf/gf/v2/os/glog""github.com/gogf/gf/v2/util/gconv""strings""time"@@ -175,6 +176,8 @@ func (s *JWTService) JWTAuthMiddleware(r *ghttp.Request) {return}+ glog.Debug(r.GetCtx(), r.URL, claims)+// Set account info in contextr.SetCtxVar("accountId", claims.AccountId)r.SetCtxVar("username", claims.Username)diff --git a/core/internal/service/rbac/role.go b/core/internal/service/rbac/role.goindex 6f757868..c5c36d2c 100644--- a/core/internal/service/rbac/role.go+++ b/core/internal/service/rbac/role.go@@ -62,13 +62,9 @@ func (s *roleService) GetById(ctx context.Context, roleId int64) (*model.Role, e// Create creates a new rolefunc (s *roleService) Create(ctx context.Context, name, description string, status int) (int64, error) {- result, err := g.DB().Model("role").Data(g.Map{- "name": name,- "description": description,- "status": status,- "created_at": time.Now(),- "updated_at": time.Now(),- }).Insert()+ result, err := g.DB().Model("role").Insert(model.Role{+ RoleName: name,+ })if err != nil {return 0, err}