2023-02-02 15:01:37 +08:00
|
|
|
package hook
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/repo"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/global"
|
2023-05-13 12:20:29 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/utils/cmd"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/utils/common"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/utils/encrypt"
|
2023-02-02 15:01:37 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func Init() {
|
|
|
|
settingRepo := repo.NewISettingRepo()
|
|
|
|
portSetting, err := settingRepo.Get(settingRepo.WithByKey("ServerPort"))
|
|
|
|
if err != nil {
|
|
|
|
global.LOG.Errorf("load service port from setting failed, err: %v", err)
|
|
|
|
}
|
|
|
|
global.CONF.System.Port = portSetting.Value
|
2023-02-13 11:04:14 +08:00
|
|
|
enptrySetting, err := settingRepo.Get(settingRepo.WithByKey("EncryptKey"))
|
|
|
|
if err != nil {
|
|
|
|
global.LOG.Errorf("load service encrypt key from setting failed, err: %v", err)
|
|
|
|
}
|
|
|
|
global.CONF.System.EncryptKey = enptrySetting.Value
|
2023-04-25 14:34:16 +08:00
|
|
|
sslSetting, err := settingRepo.Get(settingRepo.WithByKey("SSL"))
|
|
|
|
if err != nil {
|
|
|
|
global.LOG.Errorf("load service ssl from setting failed, err: %v", err)
|
|
|
|
}
|
|
|
|
global.CONF.System.SSL = sslSetting.Value
|
2023-02-02 15:01:37 +08:00
|
|
|
|
2023-05-19 21:47:46 +08:00
|
|
|
ipsSetting, err := settingRepo.Get(settingRepo.WithByKey("AllowIPs"))
|
|
|
|
if err != nil {
|
|
|
|
global.LOG.Errorf("load allow ips from setting failed, err: %v", err)
|
|
|
|
}
|
|
|
|
global.CONF.System.AllowIPs = ipsSetting.Value
|
|
|
|
|
|
|
|
domainSetting, err := settingRepo.Get(settingRepo.WithByKey("BindDomain"))
|
|
|
|
if err != nil {
|
|
|
|
global.LOG.Errorf("load bind domain from setting failed, err: %v", err)
|
|
|
|
}
|
|
|
|
global.CONF.System.BindDomain = domainSetting.Value
|
|
|
|
|
2023-02-02 15:01:37 +08:00
|
|
|
if _, err := settingRepo.Get(settingRepo.WithByKey("SystemStatus")); err != nil {
|
|
|
|
_ = settingRepo.Create("SystemStatus", "Free")
|
|
|
|
}
|
|
|
|
if err := settingRepo.Update("SystemStatus", "Free"); err != nil {
|
2023-05-13 12:20:29 +08:00
|
|
|
global.LOG.Fatalf("init service before start failed, err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if global.CONF.System.ChangeUserInfo {
|
|
|
|
if err := settingRepo.Update("UserName", common.RandStrAndNum(10)); err != nil {
|
|
|
|
global.LOG.Fatalf("init username before start failed, err: %v", err)
|
|
|
|
}
|
|
|
|
pass, _ := encrypt.StringEncrypt(common.RandStrAndNum(10))
|
|
|
|
if err := settingRepo.Update("Password", pass); err != nil {
|
|
|
|
global.LOG.Fatalf("init password before start failed, err: %v", err)
|
|
|
|
}
|
|
|
|
if err := settingRepo.Update("SecurityEntrance", common.RandStrAndNum(10)); err != nil {
|
|
|
|
global.LOG.Fatalf("init entrance before start failed, err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if cmd.HasNoPasswordSudo() {
|
|
|
|
_, _ = cmd.Exec("sudo sed -i '/CHANGE_USER_INFO=true/d' /usr/local/bin/1pctl")
|
|
|
|
} else {
|
|
|
|
_, _ = cmd.Exec("sed -i '/CHANGE_USER_INFO=true/d' /usr/local/bin/1pctl")
|
|
|
|
}
|
2023-02-02 15:01:37 +08:00
|
|
|
}
|
|
|
|
}
|