Skip to content

Commit

Permalink
删除内部代码
Browse files Browse the repository at this point in the history
  • Loading branch information
xl1605368195 committed Jul 3, 2023
1 parent 395945c commit 32480b4
Show file tree
Hide file tree
Showing 20 changed files with 16 additions and 1,688 deletions.
1 change: 0 additions & 1 deletion server/common/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func dbAutoMigrate() {
&model.RaspFile{},
&model.RaspErrorLogs{},
&model.HostResource{},
&model.SystemSetting{},
)
if err != nil {
return
Expand Down
117 changes: 9 additions & 108 deletions server/common/init_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package common

import (
"errors"
"reflect"
"server/config"
"server/model"
"server/util"
Expand Down Expand Up @@ -97,7 +96,6 @@ func InitData() {
menuIcon := "menu"
roleIcon := "role"
userIcon := "user"
settingIcon := "config"

menus := []model.Menu{
{
Expand Down Expand Up @@ -252,72 +250,60 @@ func InitData() {
},
{
Model: gorm.Model{ID: systemId + 1},
Name: "Settings",
Title: "系统配置",
Icon: &settingIcon,
Path: "settings",
Component: "/system/settings/index",
Sort: systemId + 1,
ParentId: &systemId,
Roles: roles[:1],
Creator: "系统",
},
{
Model: gorm.Model{ID: systemId + 2},
Name: "User",
Title: "用户管理",
Icon: &userIcon,
Path: "user",
Component: "/system/user/index",
Sort: systemId + 2,
Sort: systemId + 1,
ParentId: &systemId,
Roles: roles[:1],
Creator: "系统",
},
{
Model: gorm.Model{ID: systemId + 3},
Model: gorm.Model{ID: systemId + 2},
Name: "Role",
Title: "角色管理",
Icon: &roleIcon,
Path: "role",
Component: "/system/role/index",
Sort: systemId + 3,
Sort: systemId + 2,
ParentId: &systemId,
Roles: roles[:1],
Creator: "系统",
},
{
Model: gorm.Model{ID: systemId + 4},
Model: gorm.Model{ID: systemId + 3},
Name: "Menu",
Title: "菜单管理",
Icon: &menuIcon,
Path: "menu",
Component: "/system/menu/index",
Sort: systemId + 4,
Sort: systemId + 3,
ParentId: &systemId,
Roles: roles[:1],
Creator: "系统",
},
{
Model: gorm.Model{ID: systemId + 5},
Model: gorm.Model{ID: systemId + 4},
Name: "Api",
Title: "接口管理",
Icon: &apiIcon,
Path: "api",
Component: "/system/api/index",
Sort: systemId + 5,
Sort: systemId + 4,
ParentId: &systemId,
Roles: roles[:1],
Creator: "系统",
},
{
Model: gorm.Model{ID: systemId + 6},
Model: gorm.Model{ID: systemId + 5},
Name: "OperationLog",
Title: "操作日志",
Icon: &apiLogIcon,
Path: "operation-log",
Component: "/system/operation-log/index",
Sort: systemId + 6,
Sort: systemId + 5,
ParentId: &systemId,
Roles: roles[:1],
Creator: "系统",
Expand Down Expand Up @@ -361,28 +347,6 @@ func InitData() {
Creator: "系统",
Roles: roles[:1],
},
//{
// Model: gorm.Model{ID: 3},
// Username: "user",
// Password: util.GenPasswd("123456"),
// Mobile: "13899999999",
// Avatar: "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
// Introduction: new(string),
// Status: 1,
// Creator: "系统",
// Roles: roles[1:2],
//},
//{
// Model: gorm.Model{ID: 4},
// Username: "guest",
// Password: util.GenPasswd("123456"),
// Mobile: "13833333333",
// Avatar: "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
// Introduction: new(string),
// Status: 1,
// Creator: "系统",
// Roles: roles[1:2],
//},
}

for _, user := range users {
Expand Down Expand Up @@ -947,27 +911,6 @@ func InitData() {
Desc: "批量删除rasp日志",
Creator: "系统",
},
{
Method: "POST",
Path: "/settings/update",
Category: "settings",
Desc: "更新系统配置",
Creator: "系统",
},
{
Method: "GET",
Path: "/settings/list",
Category: "settings",
Desc: "获取系统配置",
Creator: "系统",
},
{
Method: "POST",
Path: "/settings/getProjectInfo",
Category: "settings",
Desc: "获取项目guid",
Creator: "系统",
},
}
newApi := make([]model.Api, 0)
newRoleCasbin := make([]model.RoleCasbin, 0)
Expand Down Expand Up @@ -1029,46 +972,4 @@ func InitData() {
Log.Errorf("写入casbin数据失败:%v", err)
}
}

// 写入系统默认设置
settings := []model.SystemSetting{
{
Name: "autoUpdate",
Type: reflect.Bool.String(),
Value: "false",
},
{
Name: "reportUrl",
Type: reflect.String.String(),
Value: "",
},
{
Name: "projectGuid",
Type: reflect.String.String(),
Value: "",
},
{
Name: "updateUrl",
Type: reflect.String.String(),
Value: "ws://security.epoint.com.cn:8024",
},
{
Name: "projectType",
Type: reflect.String.String(),
Value: "live-project",
},
}
newSettings := make([]model.SystemSetting, 0)
for i, item := range settings {
item.ID = uint(i + 1)
err := DB.First(&item, item.ID).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
newSettings = append(newSettings, item)
}
}
if len(newSettings) > 0 {
if err := DB.Create(&newSettings).Error; err != nil {
Log.Errorf("写入settings数据失败:%v", err)
}
}
}
26 changes: 0 additions & 26 deletions server/common/install_scripts.go

This file was deleted.

52 changes: 0 additions & 52 deletions server/common/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,55 +103,3 @@ func InitLogger() {
Log = logger.Sugar()
Log.Info("初始化zap日志完成!")
}

func InitReportLog() {
now := time.Now()
attackLogFileName := fmt.Sprintf("%s/report-attack/%04d-%02d-%02d.log", config.Conf.Logs.Path, now.Year(), now.Month(), now.Day())
errorLogFileName := fmt.Sprintf("%s/report-error/%04d-%02d-%02d.log", config.Conf.Logs.Path, now.Year(), now.Month(), now.Day())
var coreArr []zapcore.Core

encoderConfig := zapcore.EncoderConfig{
MessageKey: "msg",
LineEnding: zapcore.DefaultLineEnding,
}
encoder := zapcore.NewConsoleEncoder(encoderConfig)

// 日志级别
highPriority := zap.LevelEnablerFunc(func(level zapcore.Level) bool {
return level == zap.ErrorLevel
})
lowPriority := zap.LevelEnablerFunc(func(level zapcore.Level) bool {
return level == zap.WarnLevel
})

// info文件writeSyncer
infoFileWriteSyncer := zapcore.AddSync(&lumberjack.Logger{
Filename: attackLogFileName, //日志文件存放目录,如果文件夹不存在会自动创建
MaxSize: config.Conf.Logs.MaxSize, //文件大小限制,单位MB
MaxAge: config.Conf.Logs.MaxAge, //日志文件保留天数
MaxBackups: config.Conf.Logs.MaxBackups, //最大保留日志文件数量
LocalTime: false,
Compress: config.Conf.Logs.Compress, //是否压缩处理
})
// 第三个及之后的参数为写入文件的日志级别,ErrorLevel模式只记录error级别的日志
infoFileCore := zapcore.NewCore(encoder, zapcore.NewMultiWriteSyncer(infoFileWriteSyncer), lowPriority)

// error文件writeSyncer
errorFileWriteSyncer := zapcore.AddSync(&lumberjack.Logger{
Filename: errorLogFileName, //日志文件存放目录
MaxSize: config.Conf.Logs.MaxSize, //文件大小限制,单位MB
MaxAge: config.Conf.Logs.MaxAge, //日志文件保留天数
MaxBackups: config.Conf.Logs.MaxBackups, //最大保留日志文件数量
LocalTime: false,
Compress: config.Conf.Logs.Compress, //是否压缩处理
})
// 第三个及之后的参数为写入文件的日志级别,ErrorLevel模式只记录error级别的日志
errorFileCore := zapcore.NewCore(encoder, zapcore.NewMultiWriteSyncer(errorFileWriteSyncer), highPriority)

coreArr = append(coreArr, infoFileCore)
coreArr = append(coreArr, errorFileCore)

logger := zap.New(zapcore.NewTee(coreArr...), zap.AddCaller())
ReportLog = logger.Sugar()
Log.Info("初始化上报日志完成!")
}
13 changes: 6 additions & 7 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,12 @@ type SystemConfig struct {
}

type LogsConfig struct {
Level zapcore.Level `mapstructure:"level" json:"level"`
Path string `mapstructure:"path" json:"path"`
MaxSize int `mapstructure:"max-size" json:"maxSize"`
MaxBackups int `mapstructure:"max-backups" json:"maxBackups"`
MaxAge int `mapstructure:"max-age" json:"maxAge"`
Compress bool `mapstructure:"compress" json:"compress"`
EnableReportLog bool `mapstructure:"enable-report-log" json:"enableReportLog"`
Level zapcore.Level `mapstructure:"level" json:"level"`
Path string `mapstructure:"path" json:"path"`
MaxSize int `mapstructure:"max-size" json:"maxSize"`
MaxBackups int `mapstructure:"max-backups" json:"maxBackups"`
MaxAge int `mapstructure:"max-age" json:"maxAge"`
Compress bool `mapstructure:"compress" json:"compress"`
}

type CasbinConfig struct {
Expand Down
Loading

0 comments on commit 32480b4

Please sign in to comment.