2024-07-19 19:04:11 +08:00
|
|
|
package migrations
|
|
|
|
|
|
|
|
import (
|
2024-08-08 15:38:37 +08:00
|
|
|
"fmt"
|
|
|
|
"path"
|
2024-07-19 19:04:11 +08:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/1Panel-dev/1Panel/core/app/model"
|
|
|
|
"github.com/1Panel-dev/1Panel/core/constant"
|
|
|
|
"github.com/1Panel-dev/1Panel/core/global"
|
|
|
|
"github.com/1Panel-dev/1Panel/core/utils/common"
|
|
|
|
"github.com/1Panel-dev/1Panel/core/utils/encrypt"
|
|
|
|
"github.com/go-gormigrate/gormigrate/v2"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
|
2024-07-22 16:14:59 +08:00
|
|
|
var AddTable = &gormigrate.Migration{
|
2024-08-19 18:04:43 +08:00
|
|
|
ID: "20240819-add-table",
|
2024-07-19 19:04:11 +08:00
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
return tx.AutoMigrate(
|
|
|
|
&model.OperationLog{},
|
|
|
|
&model.LoginLog{},
|
|
|
|
&model.Setting{},
|
2024-08-08 15:38:37 +08:00
|
|
|
&model.BackupAccount{},
|
2024-08-19 18:04:43 +08:00
|
|
|
&model.Group{},
|
|
|
|
&model.Host{},
|
|
|
|
&model.Command{},
|
2024-07-19 19:04:11 +08:00
|
|
|
)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var InitSetting = &gormigrate.Migration{
|
|
|
|
ID: "20200908-add-table-setting",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
encryptKey := common.RandStr(16)
|
|
|
|
if err := tx.Create(&model.Setting{Key: "UserName", Value: global.CONF.System.Username}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
global.CONF.System.EncryptKey = encryptKey
|
|
|
|
pass, _ := encrypt.StringEncrypt(global.CONF.System.Password)
|
|
|
|
if err := tx.Create(&model.Setting{Key: "Password", Value: pass}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "Theme", Value: "light"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "MenuTabs", Value: "disable"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "PanelName", Value: "1Panel"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "Language", Value: "zh"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "SessionTimeout", Value: "86400"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-07-23 10:11:43 +08:00
|
|
|
|
|
|
|
if err := tx.Create(&model.Setting{Key: "SSLType", Value: "self"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "SSLID", Value: "0"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "SSL", Value: "disable"}).Error; err != nil {
|
2024-07-19 19:04:11 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := tx.Create(&model.Setting{Key: "DeveloperMode", Value: "disable"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "ProxyType", Value: ""}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "ProxyUrl", Value: ""}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "ProxyPort", Value: ""}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "ProxyUser", Value: ""}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "ProxyPasswd", Value: ""}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "PrsoxyPasswdKeep", Value: ""}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-07-25 14:43:41 +08:00
|
|
|
if err := tx.Create(&model.Setting{Key: "XpackHideMenu", Value: "{\"id\":\"1\",\"label\":\"/xpack\",\"isCheck\":true,\"title\":\"xpack.menu\",\"children\":[{\"id\":\"2\",\"title\":\"xpack.waf.name\",\"path\":\"/xpack/waf/dashboard\",\"label\":\"Dashboard\",\"isCheck\":true},{\"id\":\"3\",\"title\":\"xpack.tamper.tamper\",\"path\":\"/xpack/tamper\",\"label\":\"Tamper\",\"isCheck\":true},{\"id\":\"4\",\"title\":\"xpack.gpu.gpu\",\"path\":\"/xpack/gpu\",\"label\":\"GPU\",\"isCheck\":true},{\"id\":\"5\",\"title\":\"xpack.setting.setting\",\"path\":\"/xpack/setting\",\"label\":\"XSetting\",\"isCheck\":true},{\"id\":\"6\",\"title\":\"xpack.monitor.name\",\"path\":\"/xpack/monitor/dashboard\",\"label\":\"MonitorDashboard\",\"isCheck\":true},{\"id\":\"7\",\"title\":\"xpack.node.nodeManagement\",\"path\":\"/xpack/node\",\"label\":\"Node\",\"isCheck\":true}]}"}).Error; err != nil {
|
2024-07-19 19:04:11 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := tx.Create(&model.Setting{Key: "ServerPort", Value: global.CONF.System.Port}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "SecurityEntrance", Value: global.CONF.System.Entrance}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "JWTSigningKey", Value: common.RandStr(16)}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "EncryptKey", Value: encryptKey}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "ExpirationTime", Value: time.Now().AddDate(0, 0, 10).Format(constant.DateTimeLayout)}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "ExpirationDays", Value: "0"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "ComplexityVerification", Value: "enable"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "MFAStatus", Value: "disable"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "MFASecret", Value: ""}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "SystemVersion", Value: global.CONF.System.Version}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-07-23 10:11:43 +08:00
|
|
|
if err := tx.Create(&model.Setting{Key: "SystemStatus", Value: "Free"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-08-13 15:33:34 +08:00
|
|
|
if err := tx.Create(&model.Setting{Key: "MasterRequestAddr", Value: ""}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-07-19 19:04:11 +08:00
|
|
|
if err := tx.Create(&model.Setting{Key: "BindAddress", Value: "0.0.0.0"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "Ipv6", Value: "disable"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-07-23 10:11:43 +08:00
|
|
|
if err := tx.Create(&model.Setting{Key: "BindDomain", Value: ""}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "AllowIPs", Value: ""}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-07-19 19:04:11 +08:00
|
|
|
if err := tx.Create(&model.Setting{Key: "NoAuthSetting", Value: "200"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2024-08-08 15:38:37 +08:00
|
|
|
|
2024-08-19 18:04:43 +08:00
|
|
|
var InitHost = &gormigrate.Migration{
|
|
|
|
ID: "20240816-init-host",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
hostGroup := &model.Group{Name: "default", Type: "host", IsDefault: true}
|
|
|
|
if err := tx.Create(hostGroup).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Group{Name: "default", Type: "node", IsDefault: true}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Group{Name: "default", Type: "command", IsDefault: true}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Group{Name: "default", Type: "website", IsDefault: true}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Group{Name: "default", Type: "redis", IsDefault: true}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
host := model.Host{
|
|
|
|
Name: "localhost", Addr: "127.0.0.1", User: "root", Port: 22, AuthMode: "password", GroupID: hostGroup.ID,
|
|
|
|
}
|
|
|
|
if err := tx.Create(&host).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2024-08-08 15:38:37 +08:00
|
|
|
var InitOneDrive = &gormigrate.Migration{
|
|
|
|
ID: "20240808-init-one-drive",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
if err := tx.Create(&model.Setting{Key: "OneDriveID", Value: "MDEwOTM1YTktMWFhOS00ODU0LWExZGMtNmU0NWZlNjI4YzZi"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "OneDriveSc", Value: "akpuOFF+YkNXOU1OLWRzS1ZSRDdOcG1LT2ZRM0RLNmdvS1RkVWNGRA=="}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.BackupAccount{
|
|
|
|
Name: "localhost",
|
|
|
|
Type: "LOCAL",
|
|
|
|
Vars: fmt.Sprintf("{\"dir\":\"%s\"}", path.Join(global.CONF.System.BaseDir, "1panel/backup")),
|
|
|
|
}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2024-08-14 10:15:55 +08:00
|
|
|
|
|
|
|
var InitMasterAddr = &gormigrate.Migration{
|
|
|
|
ID: "20240814-init-master-addr",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
if err := tx.Create(&model.Setting{Key: "MasterAddr", Value: ""}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2024-08-22 18:46:54 +08:00
|
|
|
|
|
|
|
var InitTerminalSetting = &gormigrate.Migration{
|
|
|
|
ID: "20240814-init-terminal-setting",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
if err := tx.Create(&model.Setting{Key: "LineHeight", Value: "1.2"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "LetterSpacing", Value: "0"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "FontSize", Value: "12"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "CursorBlink", Value: "enable"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "CursorStyle", Value: "block"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "Scrollback", Value: "1000"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "ScrollSensitivity", Value: "6"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2024-10-30 15:58:40 +08:00
|
|
|
|
|
|
|
var InitAppLauncher = &gormigrate.Migration{
|
|
|
|
ID: "20241029-init-app-launcher",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
return tx.AutoMigrate(&model.AppLauncher{})
|
|
|
|
},
|
|
|
|
}
|
2024-11-06 17:37:14 +08:00
|
|
|
|
|
|
|
var InitBackup = &gormigrate.Migration{
|
|
|
|
ID: "20241107-init-backup",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
return tx.AutoMigrate(&model.BackupAccount{})
|
|
|
|
},
|
|
|
|
}
|