diff --git a/agent/go.mod b/agent/go.mod index 9f488df28..8d8310e20 100644 --- a/agent/go.mod +++ b/agent/go.mod @@ -277,5 +277,3 @@ require ( modernc.org/memory v1.11.0 // indirect modernc.org/sqlite v1.48.2 // indirect ) - -replace github.com/1Panel-dev/1Panel-pro/agent => ../../xpack-backend/agent diff --git a/core/app/repo/common.go b/core/app/repo/common.go index 6d29f5ee4..998f78c9e 100644 --- a/core/app/repo/common.go +++ b/core/app/repo/common.go @@ -42,6 +42,11 @@ func WithByName(name string) global.DBOption { return g.Where("`name` = ?", name) } } +func WithByUserID(userID string) global.DBOption { + return func(g *gorm.DB) *gorm.DB { + return g.Where("user_id = ?", userID) + } +} func WithoutByName(name string) global.DBOption { return func(g *gorm.DB) *gorm.DB { return g.Where("`name` != ?", name) diff --git a/core/app/service/auth.go b/core/app/service/auth.go index 2eb21b52c..70e059b8c 100644 --- a/core/app/service/auth.go +++ b/core/app/service/auth.go @@ -16,7 +16,6 @@ import ( "github.com/1Panel-dev/1Panel/core/app/repo" "github.com/1Panel-dev/1Panel/core/buserr" "github.com/1Panel-dev/1Panel/core/constant" - xpack "github.com/1Panel-dev/1Panel/core/edition" "github.com/1Panel-dev/1Panel/core/global" initauth "github.com/1Panel-dev/1Panel/core/init/auth" "github.com/1Panel-dev/1Panel/core/init/session/psession" @@ -24,6 +23,7 @@ import ( "github.com/1Panel-dev/1Panel/core/utils/encrypt" "github.com/1Panel-dev/1Panel/core/utils/mfa" "github.com/1Panel-dev/1Panel/core/utils/passkey" + "github.com/1Panel-dev/1Panel/core/utils/xpack" "github.com/gin-gonic/gin" "github.com/go-webauthn/webauthn/protocol" "github.com/go-webauthn/webauthn/webauthn" @@ -142,12 +142,13 @@ func (u *AuthService) generateSession(c *gin.Context, name string) (*dto.UserLog return nil, err } - sessionUser := psession.SessionUser{Name: name} + sessionUser := psession.SessionUser{Name: name, Role: "ADMIN"} + lifeTime = xpack.LoadSessionTimeout(sessionUser, lifeTime) if err := global.SESSION.SetFresh(c, sessionUser, httpsSetting.Value == constant.StatusEnable, lifeTime); err != nil { return nil, err } - return &dto.UserLoginInfo{Name: name}, nil + return &dto.UserLoginInfo{Name: name, Role: "ADMIN"}, nil } func (u *AuthService) LogOut(c *gin.Context) error { diff --git a/core/app/service/setting.go b/core/app/service/setting.go index f81da372b..8c958f897 100644 --- a/core/app/service/setting.go +++ b/core/app/service/setting.go @@ -34,7 +34,7 @@ import ( "github.com/1Panel-dev/1Panel/core/utils/firewall" "github.com/1Panel-dev/1Panel/core/utils/passkey" "github.com/1Panel-dev/1Panel/core/utils/req_helper/proxy_local" - xpack "github.com/1Panel-dev/1Panel/core/edition" + "github.com/1Panel-dev/1Panel/core/utils/xpack" "github.com/gin-gonic/gin" "golang.org/x/net/proxy" ) diff --git a/core/init/router/proxy.go b/core/init/router/proxy.go index 074aee8b4..bba96ac75 100644 --- a/core/init/router/proxy.go +++ b/core/init/router/proxy.go @@ -85,6 +85,7 @@ func checkSession(c *gin.Context) bool { return false } lifeTime, _ := strconv.Atoi(sessionTimeout) + lifeTime = xpack.LoadSessionTimeout(psession, lifeTime) ssl, err := settingRepo.GetValueByKey("SSL") if err != nil { return false diff --git a/core/init/session/psession/psession.go b/core/init/session/psession/psession.go index dd7799892..6a290d912 100644 --- a/core/init/session/psession/psession.go +++ b/core/init/session/psession/psession.go @@ -15,6 +15,7 @@ import ( type SessionUser struct { ID string `json:"id"` + Role string `json:"role"` Name string `json:"name"` } diff --git a/core/middleware/session.go b/core/middleware/session.go index de600a69f..5f5f8837a 100644 --- a/core/middleware/session.go +++ b/core/middleware/session.go @@ -9,6 +9,7 @@ import ( "github.com/1Panel-dev/1Panel/core/buserr" "github.com/1Panel-dev/1Panel/core/constant" "github.com/1Panel-dev/1Panel/core/global" + "github.com/1Panel-dev/1Panel/core/utils/xpack" "github.com/gin-gonic/gin" ) @@ -41,6 +42,7 @@ func SessionAuth() gin.HandlerFunc { return } lifeTime, _ := strconv.Atoi(sessionTimeout) + lifeTime = xpack.LoadSessionTimeout(psession, lifeTime) ssl, err := settingRepo.GetValueByKey("SSL") if err != nil { global.LOG.Errorf("create operation record failed, err: %v", err) diff --git a/core/utils/xpack/community.go b/core/utils/xpack/community.go index 90bbf2c0f..cc3bda4fc 100644 --- a/core/utils/xpack/community.go +++ b/core/utils/xpack/community.go @@ -4,11 +4,15 @@ package xpack import ( "crypto/tls" + "errors" "net" "net/http" "time" + baseDto "github.com/1Panel-dev/1Panel/core/app/dto" + "github.com/1Panel-dev/1Panel/core/init/session/psession" "github.com/1Panel-dev/1Panel/core/utils/ssh" + "github.com/1Panel-dev/1Panel/core/xpack/app/model" "github.com/gin-gonic/gin" ) @@ -40,3 +44,30 @@ func LoadNodeInfo(currentNode string) (*ssh.ConnInfo, string, error) { func Sync(dataType string) error { return nil } func AutoUpgradeWithMaster() {} + +func Login(_ *gin.Context, _ baseDto.Login, _ string) (*baseDto.UserLoginInfo, string, error) { + return nil, "", errors.New("not xpackee build") +} + +func LoadSessionTimeout(sessionUser psession.SessionUser, defaultTTL int) int { return defaultTTL } + +func RemoveBindNode(nodeID uint) error { return nil } + +func CheckLicenseStatus(isXpack bool, licenseID, nodeID uint) error { + return nil +} +func LoadLicenseByNodeID(nodeID uint) (bool, model.License, error) { + return false, model.License{}, nil +} +func Bind(node model.Node, license *model.License, withInit, withSync, withDryRun, withDockerRestart bool) error { + return nil +} +func BindFree(node model.Node, licenseID uint) error { + return nil +} +func Unbind(node model.Node, license model.License, withReset, withSync, withDockerRestart bool) error { + return nil +} +func UnbindFree(node model.Node, licenseID uint) error { + return nil +} diff --git a/core/utils/xpack/xpack.go b/core/utils/xpack/xpack.go index 155ebaf7c..007e2889c 100644 --- a/core/utils/xpack/xpack.go +++ b/core/utils/xpack/xpack.go @@ -3,9 +3,13 @@ package xpack import ( + "errors" "net/http" + baseDto "github.com/1Panel-dev/1Panel/core/app/dto" + "github.com/1Panel-dev/1Panel/core/init/session/psession" "github.com/1Panel-dev/1Panel/core/utils/ssh" + "github.com/1Panel-dev/1Panel/core/xpack/app/model" edition "github.com/1Panel-dev/1Panel/core/xpack/edition" "github.com/gin-gonic/gin" ) @@ -33,3 +37,30 @@ func LoadNodeInfo(currentNode string) (*ssh.ConnInfo, string, error) { func Sync(dataType string) error { return edition.Sync(dataType) } func AutoUpgradeWithMaster() { edition.AutoUpgradeWithMaster() } + +func Login(_ *gin.Context, _ baseDto.Login, _ string) (*baseDto.UserLoginInfo, string, error) { + return nil, "", errors.New("not xpackee build") +} + +func LoadSessionTimeout(sessionUser psession.SessionUser, defaultTTL int) int { return defaultTTL } + +func RemoveBindNode(nodeID uint) error { return nil } + +func CheckLicenseStatus(isXpack bool, licenseID, nodeID uint) error { + return edition.CheckLicenseStatus(isXpack, licenseID, nodeID) +} +func LoadLicenseByNodeID(nodeID uint) (bool, model.License, error) { + return edition.LoadLicenseByNodeID(nodeID) +} +func Bind(node model.Node, license *model.License, withInit, withSync, withDryRun, withDockerRestart bool) error { + return edition.Bind(node, license, withInit, withSync, withDryRun, withDockerRestart) +} +func BindFree(node model.Node, licenseID uint) error { + return edition.BindFree(node, licenseID) +} +func Unbind(node model.Node, license model.License, withReset, withSync, withDockerRestart bool) error { + return edition.Unbind(node, license, withReset, withSync, withDockerRestart) +} +func UnbindFree(node model.Node, licenseID uint) error { + return edition.UnbindFree(node, licenseID) +} diff --git a/core/utils/xpack/xpackee.go b/core/utils/xpack/xpackee.go index aa6e5b64f..7498b001e 100644 --- a/core/utils/xpack/xpackee.go +++ b/core/utils/xpack/xpackee.go @@ -6,8 +6,10 @@ import ( "net/http" "github.com/1Panel-dev/1Panel/core/app/dto" + "github.com/1Panel-dev/1Panel/core/init/session/psession" "github.com/1Panel-dev/1Panel/core/utils/ssh" edition "github.com/1Panel-dev/1Panel/core/xpack-ee/edition" + "github.com/1Panel-dev/1Panel/core/xpack/app/model" "github.com/gin-gonic/gin" ) @@ -39,6 +41,27 @@ func Login(c *gin.Context, info dto.Login, entrance string) (*dto.UserLoginInfo, return edition.Login(c, info, entrance) } -func MFALogin(c *gin.Context, info dto.MFALogin, entrance string) (*dto.UserLoginInfo, string, error) { - return edition.MFALogin(c, info, entrance) +func LoadSessionTimeout(sessionUser psession.SessionUser, defaultTTL int) int { + return edition.LoadSessionTimeout(sessionUser, defaultTTL) +} + +func RemoveBindNode(nodeID uint) error { return nil } + +func CheckLicenseStatus(isXpack bool, licenseID, nodeID uint) error { + return edition.CheckLicenseStatus(isXpack, licenseID, nodeID) +} +func LoadLicenseByNodeID(nodeID uint) (bool, model.License, error) { + return edition.LoadLicenseByNodeID(nodeID) +} +func Bind(node model.Node, license *model.License, withInit, withSync, withDryRun, withDockerRestart bool) error { + return edition.Bind(node, license, withInit, withSync, withDryRun, withDockerRestart) +} +func BindFree(node model.Node, licenseID uint) error { + return edition.BindFree(node, licenseID) +} +func Unbind(node model.Node, license model.License, withReset, withSync, withDockerRestart bool) error { + return edition.Unbind(node, license, withReset, withSync, withDockerRestart) +} +func UnbindFree(node model.Node, licenseID uint) error { + return edition.UnbindFree(node, licenseID) } diff --git a/frontend/src/extensions/optional.ts b/frontend/src/extensions/optional.ts index 83cc1ac1d..e9f315c0e 100644 --- a/frontend/src/extensions/optional.ts +++ b/frontend/src/extensions/optional.ts @@ -1,12 +1,15 @@ type VueComponent = { template?: string } | Record; const EmptyComponent: VueComponent = { template: '
' }; -const xpackViewModules = import.meta.glob('@/xpack/views/**/*.vue'); +const extensionViewModules = { + ...import.meta.glob('@/xpack/views/**/*.vue'), + ...import.meta.glob('@/xpack-ee/views/**/*.vue'), +}; function findLoader(suffix: string) { - for (const path in xpackViewModules) { + for (const path in extensionViewModules) { if (path.endsWith(suffix)) { - return xpackViewModules[path]; + return extensionViewModules[path]; } } return null; @@ -19,3 +22,5 @@ export async function loadOptionalComponent(key: string): Promise } return ((await loader()) as { default?: VueComponent }).default || EmptyComponent; } + +export const loadExtensionComponent = loadOptionalComponent; diff --git a/frontend/src/extensions/routes.ts b/frontend/src/extensions/routes.ts index 2febd9d2d..9f41bad89 100644 --- a/frontend/src/extensions/routes.ts +++ b/frontend/src/extensions/routes.ts @@ -1,5 +1,15 @@ import type { RouteRecordRaw } from 'vue-router'; export function getXpackRoutes(): Record { - return import.meta.glob('@/xpack/routers/*.ts', { eager: true }) as Record; + const xpackRoutes = import.meta.glob('@/xpack/routers/*.ts', { eager: true }) as Record; + const xpackEERoutes = import.meta.glob('@/xpack-ee/routers/*.ts', { eager: true }) as Record< + string, + RouteRecordRaw + >; + return { + ...xpackRoutes, + ...xpackEERoutes, + }; } + +export const getExtensionRoutes = getXpackRoutes; diff --git a/frontend/src/extensions/theme.ts b/frontend/src/extensions/theme.ts index a70270628..b6aa98aa6 100644 --- a/frontend/src/extensions/theme.ts +++ b/frontend/src/extensions/theme.ts @@ -12,16 +12,30 @@ function findModule(modules: Record, suffix: string): T | null { } export function loadXpackStyles() { - const modules = import.meta.glob('@/xpack/styles/index.scss'); - const loader = findModule(modules, '/styles/index.scss'); - loader?.(); + const xpackModules = import.meta.glob('@/xpack/styles/index.scss'); + const xpackLoader = findModule(xpackModules, '/styles/index.scss'); + xpackLoader?.(); + + const xpackEEModules = import.meta.glob('@/xpack-ee/styles/index.scss'); + const xpackEELoader = findModule(xpackEEModules, '/styles/index.scss'); + xpackEELoader?.(); } export function setXpackPrimaryColor(color: string) { - const modules = import.meta.glob('@/xpack/utils/theme/tool.ts', { eager: true }) as Record< + const xpackModules = import.meta.glob('@/xpack/utils/theme/tool.ts', { eager: true }) as Record< string, XpackThemeModule >; - const module = findModule(modules, '/utils/theme/tool.ts'); - return module?.setPrimaryColor?.(color); + const xpackModule = findModule(xpackModules, '/utils/theme/tool.ts'); + xpackModule?.setPrimaryColor?.(color); + + const xpackEEModules = import.meta.glob('@/xpack-ee/utils/theme/tool.ts', { eager: true }) as Record< + string, + XpackThemeModule + >; + const xpackEEModule = findModule(xpackEEModules, '/utils/theme/tool.ts'); + xpackEEModule?.setPrimaryColor?.(color); } + +export const loadExtensionStyles = loadXpackStyles; +export const setExtensionPrimaryColor = setXpackPrimaryColor; diff --git a/frontend/src/extensions/xpack.ts b/frontend/src/extensions/xpack.ts index 4002e9b75..431899c47 100644 --- a/frontend/src/extensions/xpack.ts +++ b/frontend/src/extensions/xpack.ts @@ -13,11 +13,19 @@ function findModule(modules: Record, suffix: string): T | null { } function getXpackSettingModule(): XpackSettingModule | null { - const modules = import.meta.glob('@/xpack/api/modules/setting.ts', { eager: true }) as Record< + const xpackModules = import.meta.glob('@/xpack/api/modules/setting.ts', { eager: true }) as Record< string, XpackSettingModule >; - return findModule(modules, '/api/modules/setting.ts'); + const xpackModule = findModule(xpackModules, '/api/modules/setting.ts'); + if (xpackModule) { + return xpackModule; + } + const xpackEEModules = import.meta.glob('@/xpack-ee/api/modules/setting.ts', { eager: true }) as Record< + string, + XpackSettingModule + >; + return findModule(xpackEEModules, '/api/modules/setting.ts'); } export async function searchXpackSetting() { @@ -35,3 +43,6 @@ export async function updateXpackSettingByKey(key: string, value: string) { } return module.updateXSettingByKey(key, value); } + +export const searchExtensionSetting = searchXpackSetting; +export const updateExtensionSettingByKey = updateXpackSettingByKey;