mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-09-22 08:00:53 +00:00
feat: update xpack integration behavior
This commit is contained in:
committed by
zhengkunwang223
parent
0e28f27819
commit
d9cedeca09
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
|
||||
type SessionUser struct {
|
||||
ID string `json:"id"`
|
||||
Role string `json:"role"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
type VueComponent = { template?: string } | Record<string, any>;
|
||||
|
||||
const EmptyComponent: VueComponent = { template: '<div></div>' };
|
||||
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<VueComponent>
|
||||
}
|
||||
return ((await loader()) as { default?: VueComponent }).default || EmptyComponent;
|
||||
}
|
||||
|
||||
export const loadExtensionComponent = loadOptionalComponent;
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
import type { RouteRecordRaw } from 'vue-router';
|
||||
|
||||
export function getXpackRoutes(): Record<string, RouteRecordRaw> {
|
||||
return import.meta.glob('@/xpack/routers/*.ts', { eager: true }) as Record<string, RouteRecordRaw>;
|
||||
const xpackRoutes = import.meta.glob('@/xpack/routers/*.ts', { eager: true }) as Record<string, RouteRecordRaw>;
|
||||
const xpackEERoutes = import.meta.glob('@/xpack-ee/routers/*.ts', { eager: true }) as Record<
|
||||
string,
|
||||
RouteRecordRaw
|
||||
>;
|
||||
return {
|
||||
...xpackRoutes,
|
||||
...xpackEERoutes,
|
||||
};
|
||||
}
|
||||
|
||||
export const getExtensionRoutes = getXpackRoutes;
|
||||
|
||||
@@ -12,16 +12,30 @@ function findModule<T>(modules: Record<string, T>, 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;
|
||||
|
||||
@@ -13,11 +13,19 @@ function findModule<T>(modules: Record<string, T>, 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;
|
||||
|
||||
Reference in New Issue
Block a user