forked from 1Panel-dev/1Panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
52 changed files
with
1,240 additions
and
1,062 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package dto | ||
|
||
type DashboardBase struct { | ||
HaloEnabled bool `json:"haloEnabled"` | ||
DateeaseEnabled bool `json:"dateeaseEnabled"` | ||
JumpServerEnabled bool `json:"jumpserverEnabled"` | ||
MeterSphereEnabled bool `json:"metersphereEnabled"` | ||
|
||
WebsiteNumber int `json:"websiteNumber"` | ||
DatabaseNumber int `json:"databaseNumber"` | ||
CronjobNumber int `json:"cronjobNumber"` | ||
AppInstalldNumber int `json:"appInstalldNumber"` | ||
|
||
HostName string `json:"hostname"` | ||
Os string `json:"os"` | ||
Platform string `json:"platform"` | ||
PlatformFamily string `json:"platformFamily"` | ||
PlatformVersion string `json:"platformVersion"` | ||
KernelArch string `json:"kernelArch"` | ||
VirtualizationSystem string `json:"virtualizationSystem"` | ||
|
||
CPUCores int `json:"cpuCores"` | ||
CPULogicalCores int `json:"cpuLogicalCores"` | ||
CPUModelName string `json:"cpuModelName"` | ||
CPUPercent float64 `json:"cpuPercent"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package service | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/1Panel-dev/1Panel/backend/app/dto" | ||
"github.com/jinzhu/copier" | ||
"github.com/shirou/gopsutil/cpu" | ||
"github.com/shirou/gopsutil/host" | ||
) | ||
|
||
type DashboardService struct{} | ||
|
||
type IDashboardService interface { | ||
LoadBaseInfo() (*dto.DashboardBase, error) | ||
} | ||
|
||
func NewIDashboardService() IDashboardService { | ||
return &DashboardService{} | ||
} | ||
func (u *DashboardService) LoadBaseInfo() (*dto.DashboardBase, error) { | ||
var baseInfo dto.DashboardBase | ||
hostInfo, err := host.Info() | ||
if err != nil { | ||
return nil, err | ||
} | ||
if err := copier.Copy(baseInfo, hostInfo); err != nil { | ||
return nil, err | ||
} | ||
appInstall, err := appInstallRepo.GetBy() | ||
if err != nil { | ||
return nil, err | ||
} | ||
for _, app := range appInstall { | ||
switch app.App.Key { | ||
case "dateease": | ||
baseInfo.DateeaseEnabled = true | ||
case "halo": | ||
baseInfo.HaloEnabled = true | ||
case "metersphere": | ||
baseInfo.MeterSphereEnabled = true | ||
case "jumpserver": | ||
baseInfo.JumpServerEnabled = true | ||
} | ||
} | ||
baseInfo.AppInstalldNumber = len(appInstall) | ||
dbs, err := mysqlRepo.List() | ||
if err != nil { | ||
return nil, err | ||
} | ||
baseInfo.DatabaseNumber = len(dbs) | ||
cornjobs, err := cronjobRepo.List() | ||
if err != nil { | ||
return nil, err | ||
} | ||
baseInfo.DatabaseNumber = len(cornjobs) | ||
|
||
cpuInfo, err := cpu.Info() | ||
if err != nil { | ||
return nil, err | ||
} | ||
baseInfo.CPUModelName = cpuInfo[0].ModelName | ||
baseInfo.CPUCores, _ = cpu.Counts(false) | ||
baseInfo.CPULogicalCores, _ = cpu.Counts(true) | ||
totalPercent, _ := cpu.Percent(1*time.Second, false) | ||
if len(totalPercent) == 1 { | ||
baseInfo.CPUPercent = totalPercent[0] | ||
} | ||
|
||
return &baseInfo, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,25 @@ | ||
package configs | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
type Sqlite struct { | ||
GeneralDB `yaml:",inline" mapstructure:",squash"` | ||
Path string `mapstructure:"path"` | ||
DbFile string `mapstructure:"db_file"` | ||
} | ||
|
||
func (s *Sqlite) Dsn() string { | ||
if _, err := os.Stat(s.Path); err != nil { | ||
if err := os.MkdirAll(s.Path, os.ModePerm); err != nil { | ||
panic(fmt.Errorf("init db dir falied, err: %v", err)) | ||
} | ||
} | ||
if _, err := os.Stat(s.Path + "/" + s.DbFile); err != nil { | ||
if _, err := os.Create(s.Path + "/" + s.DbFile); err != nil { | ||
panic(fmt.Errorf("init db file falied, err: %v", err)) | ||
} | ||
} | ||
return s.Path + "/" + s.DbFile | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
package db | ||
|
||
import "github.com/1Panel-dev/1Panel/backend/global" | ||
import ( | ||
"github.com/1Panel-dev/1Panel/backend/global" | ||
"gorm.io/driver/sqlite" | ||
"gorm.io/gorm" | ||
) | ||
|
||
func Init() { | ||
switch global.CONF.System.DbType { | ||
case "mysql": | ||
global.DB = MysqlGorm() | ||
case "sqlite": | ||
global.DB = SqliteGorm() | ||
default: | ||
global.DB = MysqlGorm() | ||
s := global.CONF.Sqlite | ||
db, err := gorm.Open(sqlite.Open(s.Dsn()), &gorm.Config{}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
global.DB = db | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,7 +57,7 @@ var AddTableSetting = &gormigrate.Migration{ | |
if err := tx.Create(&model.Setting{Key: "Password", Value: "Sr2qOhssQNg8rGRvqyWhsBDJx+tV5VfLEZXdbax//dA="}).Error; err != nil { | ||
return err | ||
} | ||
if err := tx.Create(&model.Setting{Key: "Email", Value: ""}).Error; err != nil { | ||
if err := tx.Create(&model.Setting{Key: "Email", Value: "[email protected]"}).Error; err != nil { | ||
return err | ||
} | ||
|
||
|
@@ -67,7 +67,7 @@ var AddTableSetting = &gormigrate.Migration{ | |
if err := tx.Create(&model.Setting{Key: "Language", Value: "zh"}).Error; err != nil { | ||
return err | ||
} | ||
if err := tx.Create(&model.Setting{Key: "Theme", Value: "auto"}).Error; err != nil { | ||
if err := tx.Create(&model.Setting{Key: "Theme", Value: "light"}).Error; err != nil { | ||
return err | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.