Skip to content

Commit 1b6ab99

Browse files
committed
feat: add xpackee permission-aware settings flow
1 parent 32b8f05 commit 1b6ab99

55 files changed

Lines changed: 513 additions & 109 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

agent/router/entry_xpackee.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//go:build xpackee
2+
3+
package router
4+
5+
import (
6+
xpackRouter "github.com/1Panel-dev/1Panel/agent/xpack/router"
7+
)
8+
9+
func RouterGroups() []CommonRouter {
10+
baseRouter := commonGroups()
11+
for _, ro := range xpackRouter.XpackGroups() {
12+
if val, ok := ro.(CommonRouter); ok {
13+
baseRouter = append(baseRouter, val)
14+
}
15+
}
16+
return baseRouter
17+
}
18+
19+
var RouterGroupApp = RouterGroups()

agent/server/init_xpackee.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//go:build xpackee
2+
3+
package server
4+
5+
import (
6+
xpack "github.com/1Panel-dev/1Panel/agent/xpack"
7+
)
8+
9+
func InitOthers() {
10+
xpack.Init()
11+
}

agent/utils/xpack/xpackee.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
//go:build xpackee
2+
3+
package xpack
4+
5+
import (
6+
"net/http"
7+
8+
"github.com/1Panel-dev/1Panel/agent/app/dto"
9+
"github.com/1Panel-dev/1Panel/agent/app/model"
10+
edition "github.com/1Panel-dev/1Panel/agent/xpack/edition"
11+
"github.com/gin-gonic/gin"
12+
)
13+
14+
func RemoveTamper(website string) {
15+
edition.RemoveTamper(website)
16+
}
17+
18+
func StartClam(startClam *model.Clam, isUpdate bool) (int, error) {
19+
return edition.StartClam(startClam, isUpdate)
20+
}
21+
22+
func LoadNodeInfo(isBase bool) (model.NodeInfo, error) {
23+
return edition.LoadNodeInfo(isBase)
24+
}
25+
26+
func GetImagePrefix() string {
27+
return edition.GetImagePrefix()
28+
}
29+
30+
func IsUseCustomApp() bool {
31+
return edition.IsUseCustomApp()
32+
}
33+
34+
func IsXpack() bool {
35+
return edition.IsXpack()
36+
}
37+
38+
func CreateTaskScanSMSAlertLog(info dto.AlertDTO, alertType string, create dto.AlertLogCreate, pushAlert dto.PushAlert, method string) error {
39+
return edition.CreateTaskScanSMSAlertLog(info, alertType, create, pushAlert, method)
40+
}
41+
42+
func CreateSMSAlertLog(alertType string, info dto.AlertDTO, create dto.AlertLogCreate, project string, params []dto.Param, method string) error {
43+
return edition.CreateSMSAlertLog(alertType, info, create, project, params, method)
44+
}
45+
46+
func CreateTaskScanWebhookAlertLog(alert dto.AlertDTO, alertType string, create dto.AlertLogCreate, pushAlert dto.PushAlert, method string, transport *http.Transport, agentInfo *dto.AgentInfo) error {
47+
return edition.CreateTaskScanWebhookAlertLog(alert, alertType, create, pushAlert, method, transport, agentInfo)
48+
}
49+
50+
func CreateWebhookAlertLog(alertType string, info dto.AlertDTO, create dto.AlertLogCreate, project string, params []dto.Param, method string, transport *http.Transport, agentInfo *dto.AgentInfo) error {
51+
return edition.CreateWebhookAlertLog(alertType, info, create, project, params, method, transport, agentInfo)
52+
}
53+
54+
func GetLicenseErrorAlert() (uint, error) {
55+
return edition.GetLicenseErrorAlert()
56+
}
57+
58+
func GetNodeErrorAlert() (uint, error) {
59+
return edition.GetNodeErrorAlert()
60+
}
61+
62+
func LoadRequestTransport() *http.Transport { return edition.LoadRequestTransport() }
63+
64+
func ValidateCertificate(c *gin.Context) bool {
65+
return edition.ValidateCertificate(c)
66+
}
67+
68+
func PushSSLToNode(websiteSSL *model.WebsiteSSL) error {
69+
return edition.PushSSLToNode(websiteSSL)
70+
}
71+
72+
func GetAgentInfo() (*dto.AgentInfo, error) {
73+
return edition.GetAgentInfo()
74+
}

core/app/api/v2/helper/helper.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ func ErrorWithDetail(ctx *gin.Context, code int, msgKey string, err error) {
2222
res.Code = 401
2323
res.Message = msgKey
2424
}
25+
if msgKey == "ErrRBAC" {
26+
res.Code = 412
27+
if err != nil {
28+
res.Message = err.Error()
29+
ctx.JSON(http.StatusOK, res)
30+
ctx.Abort()
31+
return
32+
}
33+
}
2534
res.Message = i18n.GetMsgWithMap(msgKey, map[string]interface{}{"detail": err})
2635
ctx.JSON(http.StatusOK, res)
2736
ctx.Abort()

core/app/api/v2/setting.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (b *BaseApi) UpdateSetting(c *gin.Context) {
109109
req.Value = value
110110
}
111111

112-
if err := settingService.Update(req.Key, req.Value); err != nil {
112+
if err := settingService.Update(c, req.Key, req.Value); err != nil {
113113
helper.InternalServer(c, err)
114114
return
115115
}
@@ -187,7 +187,7 @@ func (b *BaseApi) UpdateMenu(c *gin.Context) {
187187
return
188188
}
189189

190-
if err := settingService.Update(req.Key, req.Value); err != nil {
190+
if err := settingService.Update(c, req.Key, req.Value); err != nil {
191191
helper.InternalServer(c, err)
192192
return
193193
}
@@ -411,17 +411,17 @@ func (b *BaseApi) MFABind(c *gin.Context) {
411411
return
412412
}
413413

414-
if err := settingService.Update("MFAInterval", req.Interval); err != nil {
414+
if err := settingService.Update(c, "MFAInterval", req.Interval); err != nil {
415415
helper.InternalServer(c, err)
416416
return
417417
}
418418

419-
if err := settingService.Update("MFAStatus", constant.StatusEnable); err != nil {
419+
if err := settingService.Update(c, "MFAStatus", constant.StatusEnable); err != nil {
420420
helper.InternalServer(c, err)
421421
return
422422
}
423423

424-
if err := settingService.Update("MFASecret", req.Secret); err != nil {
424+
if err := settingService.Update(c, "MFASecret", req.Secret); err != nil {
425425
helper.InternalServer(c, err)
426426
return
427427
}

core/app/service/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (u *AuthService) generateSession(c *gin.Context, name string) (*dto.UserLog
142142
return nil, err
143143
}
144144

145-
sessionUser := psession.SessionUser{Name: name, Role: "ADMIN"}
145+
sessionUser := psession.SessionUser{ID: psession.SuperAdminSessionUserID, Name: name, Role: "ADMIN"}
146146
lifeTime = xpack.LoadSessionTimeout(sessionUser, lifeTime)
147147
if err := global.SESSION.SetFresh(c, sessionUser, httpsSetting.Value == constant.StatusEnable, lifeTime); err != nil {
148148
return nil, err

core/app/service/setting.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type SettingService struct{}
4444
type ISettingService interface {
4545
GetSettingInfo() (*dto.SettingInfo, error)
4646
LoadInterfaceAddr() ([]string, error)
47-
Update(key, value string) error
47+
Update(c *gin.Context, key, value string) error
4848
UpdatePassword(c *gin.Context, old, new string) error
4949
UpdatePort(port uint) error
5050
UpdateBindInfo(req dto.BindInfo) error
@@ -127,7 +127,7 @@ func sortShowMenus(menus []dto.ShowMenu) {
127127
})
128128
}
129129

130-
func (u *SettingService) Update(key, value string) error {
130+
func (u *SettingService) Update(c *gin.Context, key, value string) error {
131131
oldVal, err := settingRepo.Get(repo.WithByKey(key))
132132
if err != nil {
133133
return err
@@ -180,7 +180,7 @@ func (u *SettingService) Update(key, value string) error {
180180
return err
181181
}
182182
case "UserName", "Password":
183-
_ = global.SESSION.DeleteByID("")
183+
u.deleteCurrentSession(c)
184184
case "Language":
185185
i18n.SetCachedDBLanguage(value)
186186
if err := xpack.Sync(constant.SyncLanguage); err != nil {
@@ -566,10 +566,21 @@ func (u *SettingService) UpdatePassword(c *gin.Context, old, new string) error {
566566
if err := u.HandlePasswordExpired(c, old, new); err != nil {
567567
return err
568568
}
569-
_ = global.SESSION.DeleteByID("")
569+
u.deleteCurrentSession(c)
570570
return nil
571571
}
572572

573+
func (u *SettingService) deleteCurrentSession(c *gin.Context) {
574+
if c == nil {
575+
return
576+
}
577+
sessionUser, err := global.SESSION.Get(c)
578+
if err != nil || sessionUser.ID == "" {
579+
return
580+
}
581+
_ = global.SESSION.DeleteByID(sessionUser.ID)
582+
}
583+
573584
func (u *SettingService) clearPasskeySettings() error {
574585
if err := settingRepo.Update(passkey.PasskeyUserIDSettingKey, ""); err != nil {
575586
return err
4.36 MB
Binary file not shown.

core/i18n/lang/en.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ AppInstallCheck: 'Check application installation environment'
5555

5656
# backup
5757
ErrBackupInUsed: "This backup account is used in scheduled tasks and cannot be deleted"
58+
ErrRolePresetCannotDelete: "System preset roles cannot be deleted"
59+
ErrRoleBoundToUser: "This role is already bound to users and cannot be deleted"
5860
ErrBackupCheck: "Backup account connection test failed {{ .err }}"
5961
ErrBackupLocal: "Local server backup account does not support this operation!"
6062
ErrBackupPublic: "Detected that this backup account is not public, check and try again!"

core/i18n/lang/es-ES.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ AppInstallCheck: 'Verificar entorno de instalación de aplicación'
5454

5555
# backup
5656
ErrBackupInUsed: 'Cuenta de respaldo en uso por tarea programada'
57+
ErrRolePresetCannotDelete: "System preset roles cannot be deleted"
58+
ErrRoleBoundToUser: "This role is already bound to users and cannot be deleted"
5759
ErrBackupCheck: 'Conexión de respaldo falló: {{ .err }}'
5860
ErrBackupLocal: "La cuenta de respaldo del servidor local no admite esta operación"
5961
ErrBackupPublic: "Se detectó que esta cuenta de respaldo no es pública, verifique e intente de nuevo"

0 commit comments

Comments
 (0)