Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions core/app/api/v2/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"net/http"
"os"
"path"
"path/filepath"
"regexp"
"strconv"
"strings"

"github.com/1Panel-dev/1Panel/core/app/api/v2/helper"
Expand Down Expand Up @@ -102,6 +104,50 @@ func (b *BaseApi) UpdateSetting(c *gin.Context) {
}
req.Value = value
}
if req.Key == "OpsReportExportFormat" {
if !global.CONF.Base.IsEnterprise {
helper.ErrorWithDetail(c, http.StatusBadRequest, "ErrNotSupportType", errors.New(req.Key))
return
}
if _, ok := constant.OpsReportExportFormats[req.Value]; !ok {
helper.ErrorWithDetail(c, http.StatusBadRequest, "ErrNotSupportType", errors.New(req.Value))
return
}
}
if req.Key == "OpsReportSchedule" {
if !global.CONF.Base.IsEnterprise {
helper.ErrorWithDetail(c, http.StatusBadRequest, "ErrNotSupportType", errors.New(req.Key))
return
}
if _, ok := constant.OpsReportSchedules[req.Value]; !ok {
helper.ErrorWithDetail(c, http.StatusBadRequest, "ErrNotSupportType", errors.New(req.Value))
return
}
}
if req.Key == "OpsReportSavePath" {
if !global.CONF.Base.IsEnterprise {
helper.ErrorWithDetail(c, http.StatusBadRequest, "ErrNotSupportType", errors.New(req.Key))
return
}
value := strings.TrimSpace(req.Value)
if value == "" || !filepath.IsAbs(value) {
helper.ErrorWithDetail(c, http.StatusBadRequest, "ErrInvalidParams", errors.New(req.Value))
return
}
req.Value = filepath.Clean(value)
}
if req.Key == "OpsReportThreshold" {
if !global.CONF.Base.IsEnterprise {
helper.ErrorWithDetail(c, http.StatusBadRequest, "ErrNotSupportType", errors.New(req.Key))
return
}
threshold, err := strconv.Atoi(strings.TrimSpace(req.Value))
if err != nil || threshold < 1 || threshold > 100 {
helper.ErrorWithDetail(c, http.StatusBadRequest, "ErrInvalidParams", errors.New(req.Value))
return
}
req.Value = strconv.Itoa(threshold)
}

if err := settingService.Update(c, req.Key, req.Value); err != nil {
helper.InternalServer(c, err)
Expand Down
5 changes: 5 additions & 0 deletions core/app/dto/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ type SettingInfo struct {
ProxyUser string `json:"proxyUser"`
ProxyPasswd string `json:"proxyPasswd"`
ProxyPasswdKeep string `json:"proxyPasswdKeep"`

OpsReportExportFormat string `json:"opsReportExportFormat"`
OpsReportSchedule string `json:"opsReportSchedule"`
OpsReportSavePath string `json:"opsReportSavePath"`
OpsReportThreshold string `json:"opsReportThreshold"`
}

type SettingBaseInfo struct {
Expand Down
30 changes: 30 additions & 0 deletions core/app/service/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,41 @@ func (u *SettingService) GetSettingInfo() (*dto.SettingInfo, error) {
}
if !global.CONF.Base.IsEnterprise {
info.IsOffline = constant.StatusDisable
} else {
u.ensureOpsReportSettingDefaults(&info)
}

return &info, err
}

func (u *SettingService) ensureOpsReportSettingDefaults(info *dto.SettingInfo) {
if _, ok := constant.OpsReportExportFormats[info.OpsReportExportFormat]; !ok {
info.OpsReportExportFormat = constant.OpsReportExportFormatPDF
_ = settingRepo.UpdateOrCreate("OpsReportExportFormat", info.OpsReportExportFormat)
}
if _, ok := constant.OpsReportSchedules[info.OpsReportSchedule]; !ok {
info.OpsReportSchedule = constant.OpsReportScheduleWeekly
_ = settingRepo.UpdateOrCreate("OpsReportSchedule", info.OpsReportSchedule)
}
if strings.TrimSpace(info.OpsReportSavePath) == "" {
info.OpsReportSavePath = defaultOpsReportSavePath()
_ = settingRepo.UpdateOrCreate("OpsReportSavePath", info.OpsReportSavePath)
}
if !isValidOpsReportThreshold(info.OpsReportThreshold) {
info.OpsReportThreshold = constant.OpsReportDefaultThreshold
_ = settingRepo.UpdateOrCreate("OpsReportThreshold", info.OpsReportThreshold)
}
}

func defaultOpsReportSavePath() string {
return path.Join(global.CONF.Base.InstallDir, constant.OpsReportDefaultSaveSubDir)
}

func isValidOpsReportThreshold(value string) bool {
threshold, err := strconv.Atoi(strings.TrimSpace(value))
return err == nil && threshold >= 1 && threshold <= 100
}

func (u *SettingService) GetSettingBaseInfo() (*dto.SettingBaseInfo, error) {
setting, err := settingRepo.List()
if err != nil {
Expand Down
38 changes: 34 additions & 4 deletions core/constant/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ const (
DateTimeLayout = "2006-01-02 15:04:05" // or use time.DateTime while go version >= 1.20
DateTimeSlimLayout = "20060102150405"

OpsReportExportFormatPDF = "PDF"
OpsReportExportFormatHTML = "HTML"
OpsReportExportFormatMarkdown = "Markdown"
OpsReportScheduleDaily = "daily"
OpsReportScheduleWeekly = "weekly"
OpsReportScheduleMonthly = "monthly"
OpsReportDefaultThreshold = "80"
OpsReportDefaultSaveSubDir = "1panel/data/ops-report"

OrderDesc = "descending"
OrderAsc = "ascending"

Expand Down Expand Up @@ -183,10 +192,31 @@ var WebUrlMap = map[string]struct{}{
"/xpack/cluster/postgres": {},
"/xpack/cluster/redis": {},

"/enterprise/users/list": {},
"/enterprise/users/roles": {},
"/enterprise/license": {},
"/enterprise/license-required": {},
"/enterprise/users/list": {},
"/enterprise/users/roles": {},
"/enterprise/license": {},
"/enterprise/license-required": {},
"/enterprise/ops-report": {},
"/enterprise/ops-report/overview": {},
"/enterprise/ops-report/system": {},
"/enterprise/ops-report/login": {},
"/enterprise/ops-report/website": {},
"/enterprise/ops-report/resource": {},
"/enterprise/ops-report/cronjob": {},
"/enterprise/ops-report/history": {},
"/enterprise/ops-report/settings": {},
}

var OpsReportExportFormats = map[string]struct{}{
OpsReportExportFormatPDF: {},
OpsReportExportFormatHTML: {},
OpsReportExportFormatMarkdown: {},
}

var OpsReportSchedules = map[string]struct{}{
OpsReportScheduleDaily: {},
OpsReportScheduleWeekly: {},
OpsReportScheduleMonthly: {},
}

var DynamicRoutes = []string{
Expand Down
10 changes: 10 additions & 0 deletions core/init/migration/helper/menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ func LoadMenus() string {
Path: "/enterprise/users",
Sort: 350,
}, "NodeDashboard")
item[i].Children = UpsertMenuByLabel(item[i].Children, dto.ShowMenu{
ID: "122",
Disabled: false,
Title: "xpack.opsReport.name",
IsShow: true,
Label: "OpsReport",
Path: "/enterprise/ops-report",
Sort: 360,
}, "UserManagement")
break
}
}
Expand Down Expand Up @@ -159,6 +168,7 @@ func MenuSort() []dto.MenuLabelSort {
{Label: "Node", Sort: 300},
{Label: "NodeDashboard", Sort: 300},
{Label: "UserManagement", Sort: 350},
{Label: "OpsReport", Sort: 360},
{Label: "Upage", Sort: 400},
{Label: "MonitorDashboard", Sort: 500},
{Label: "Tamper", Sort: 600},
Expand Down
4 changes: 4 additions & 0 deletions core/init/migration/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func Init() {
migrations.AddDocSourceSetting,
migrations.AddAppStoreInstallAllowPortSetting,
migrations.AddUserManagementMenu,
migrations.AddOpsReportMenu,
migrations.AddOpsReportSetting,
migrations.AddOpsReportScheduleSetting,
migrations.AddOpsReportThresholdSetting,
migrations.AddAIBenchmarkMenu,
migrations.AddAIProxyMenu,
migrations.AddOperationLogUser,
Expand Down
109 changes: 109 additions & 0 deletions core/init/migration/migrations/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,115 @@ var AddUserManagementMenu = &gormigrate.Migration{
},
}

var AddOpsReportMenu = &gormigrate.Migration{
ID: "20260512-add-ops-report-menu",
Migrate: func(tx *gorm.DB) error {
if !global.CONF.Base.IsEnterprise {
return nil
}
var menuJSON string
if err := tx.Model(&model.Setting{}).Where("key = ?", "HideMenu").Pluck("value", &menuJSON).Error; err != nil {
return err
}
if menuJSON == "" {
menuJSON = helper.LoadMenus()
}

var menus []dto.ShowMenu
if err := json.Unmarshal([]byte(menuJSON), &menus); err != nil {
return tx.Model(&model.Setting{}).
Where("key = ?", "HideMenu").
Update("value", helper.LoadMenus()).Error
}

newItem := dto.ShowMenu{
ID: "122",
Disabled: false,
Title: "xpack.opsReport.name",
IsShow: true,
Label: "OpsReport",
Path: "/enterprise/ops-report",
Sort: 360,
}

for i := range menus {
if menus[i].Label != "Xpack-Menu" {
continue
}
menus[i].Children = helper.UpsertMenuByLabel(menus[i].Children, newItem, "UserManagement")
break
}

updatedJSON, err := json.Marshal(menus)
if err != nil {
return tx.Model(&model.Setting{}).
Where("key = ?", "HideMenu").
Update("value", helper.LoadMenus()).Error
}
return tx.Model(&model.Setting{}).Where("key = ?", "HideMenu").Update("value", string(updatedJSON)).Error
},
}

var AddOpsReportSetting = &gormigrate.Migration{
ID: "20260512-add-ops-report-setting",
Migrate: func(tx *gorm.DB) error {
if !global.CONF.Base.IsEnterprise {
return nil
}
var count int64
if err := tx.Model(&model.Setting{}).Where("key = ?", "OpsReportExportFormat").Count(&count).Error; err != nil {
return err
}
if count > 0 {
return nil
}
return tx.Create(&model.Setting{Key: "OpsReportExportFormat", Value: constant.OpsReportExportFormatPDF}).Error
},
}

var AddOpsReportScheduleSetting = &gormigrate.Migration{
ID: "20260513-add-ops-report-schedule-setting",
Migrate: func(tx *gorm.DB) error {
if !global.CONF.Base.IsEnterprise {
return nil
}
settings := []model.Setting{
{Key: "OpsReportSchedule", Value: constant.OpsReportScheduleWeekly},
{Key: "OpsReportSavePath", Value: path.Join(global.CONF.Base.InstallDir, constant.OpsReportDefaultSaveSubDir)},
}
for _, item := range settings {
var count int64
if err := tx.Model(&model.Setting{}).Where("key = ?", item.Key).Count(&count).Error; err != nil {
return err
}
if count > 0 {
continue
}
if err := tx.Create(&item).Error; err != nil {
return err
}
}
return nil
},
}

var AddOpsReportThresholdSetting = &gormigrate.Migration{
ID: "20260513-add-ops-report-threshold-setting",
Migrate: func(tx *gorm.DB) error {
if !global.CONF.Base.IsEnterprise {
return nil
}
var count int64
if err := tx.Model(&model.Setting{}).Where("key = ?", "OpsReportThreshold").Count(&count).Error; err != nil {
return err
}
if count > 0 {
return nil
}
return tx.Create(&model.Setting{Key: "OpsReportThreshold", Value: constant.OpsReportDefaultThreshold}).Error
},
}

var AddOperationLogUser = &gormigrate.Migration{
ID: "20260424-add-operation-log-user",
Migrate: func(tx *gorm.DB) error {
Expand Down
4 changes: 4 additions & 0 deletions core/init/validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ var baseSettingKeys = map[string]struct{}{
"AppStoreLastModified": {},
"ScriptSync": {},
"HideMenu": {},
"OpsReportExportFormat": {},
"OpsReportSchedule": {},
"OpsReportSavePath": {},
"OpsReportThreshold": {},
}

func checkNamePattern(fl validator.FieldLevel) bool {
Expand Down
13 changes: 5 additions & 8 deletions frontend/src/api/interface/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@ export namespace Log {
id: number;
source: string;
user: string;
action: string;
node: string;
ip: string;
path: string;
method: string;
userAgent: string;
body: string;
resp: string;

status: number;
status: string;
latency: number;
errorMessage: string;

detail: string;
message: string;
detailZH: string;
detailEN: string;
createdAt: DateTimeFormats;
}
export interface SearchOpLog extends ReqPage {
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/api/interface/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ export namespace Setting {
proxyUser: string;
proxyPasswd: string;
proxyPasswdKeep: string;

opsReportExportFormat: string;
opsReportSchedule: string;
opsReportSavePath: string;
opsReportThreshold: string;
}
export interface SettingBaseInfo {
systemVersion: string;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/api/modules/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const getOperationLogs = (info: Log.SearchOpLog) => {
};

export const getLoginLogs = (info: Log.SearchLgLog) => {
return http.post<ResPage<Log.OperationLog>>(`/core/logs/login`, info);
return http.post<ResPage<Log.LoginLogs>>(`/core/logs/login`, info);
};

export const getSystemFiles = (node?: string) => {
Expand Down
Loading
Loading