Skip to content

Commit

Permalink
feat: 完成概览界面样式
Browse files Browse the repository at this point in the history
  • Loading branch information
ssongliu committed Nov 18, 2022
1 parent 8214744 commit cfac341
Show file tree
Hide file tree
Showing 52 changed files with 1,240 additions and 1,062 deletions.
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOARCH=$(shell go env GOARCH)
GOOS=$(shell go env GOOS )
GOARCH=amd64
GOOS=linux

BASE_PAH := $(shell pwd)
BUILD_PATH = $(BASE_PAH)/build
Expand All @@ -16,7 +16,6 @@ build_web:

build_bin:
cd $(SERVER_PATH) \
&& GOOS=$(GOOS) GOARCH=$(GOARCH) $(GOBUILD) -trimpath -ldflags "-s -w" -o $(BUILD_PATH)/$(APP_NAME) $(MAIN)

build_all: build_web build_bin
&& CGO_ENABLED=1 GOOS=$(GOOS) GOARCH=$(GOARCH) CC=x86_64-linux-musl-gcc CXX=x86_64-linux-musl-g++ $(GOBUILD) -trimpath -ldflags '-s -w --extldflags "-static -fpic"' -o $(BUILD_PATH)/$(APP_NAME) $(MAIN)

build_all: build_web build_bin
8 changes: 4 additions & 4 deletions backend/app/api/v1/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/backend/utils/captcha"
"github.com/1Panel-dev/1Panel/backend/utils/encrypt"
"github.com/1Panel-dev/1Panel/backend/utils/qqwry"
"github.com/gin-gonic/gin"
)
Expand Down Expand Up @@ -99,9 +98,10 @@ func (b *BaseApi) SafeEntrance(c *gin.Context) {
helper.ErrorWithDetail(c, constant.CodeErrUnSafety, constant.ErrTypeNotSafety, errors.New("missing code"))
return
}
codeWithMD5 := encrypt.Md5(code)
cookieValue, _ := encrypt.StringEncrypt(codeWithMD5)
c.SetCookie(codeWithMD5, cookieValue, 604800, "", "", false, false)
if err := authService.SafeEntrance(c, code); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrUnSafety, constant.ErrTypeNotSafety, errors.New("missing code"))
return
}

helper.SuccessWithData(c, nil)
}
Expand Down
26 changes: 26 additions & 0 deletions backend/app/dto/dashboard.go
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"`
}
1 change: 1 addition & 0 deletions backend/app/dto/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type SettingInfo struct {

ServerPort int `json:"serverPort"`
SecurityEntrance string `json:"securityEntrance"`
ExpirationDays int `json:"expirationDays"`
ExpirationTime string `json:"expirationTime"`
ComplexityVerification string `json:"complexityVerification"`
MFAStatus string `json:"mfaStatus"`
Expand Down
19 changes: 19 additions & 0 deletions backend/app/service/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package service

import (
"strconv"
"time"

"github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/backend/constant"
Expand All @@ -18,6 +19,7 @@ type AuthService struct{}
type IAuthService interface {
SafetyStatus(c *gin.Context) error
VerifyCode(code string) (bool, error)
SafeEntrance(c *gin.Context, code string) error
Login(c *gin.Context, info dto.Login) (*dto.UserLoginInfo, error)
LogOut(c *gin.Context) error
}
Expand All @@ -26,6 +28,23 @@ func NewIAuthService() IAuthService {
return &AuthService{}
}

func (u *AuthService) SafeEntrance(c *gin.Context, code string) error {
codeWithMD5 := encrypt.Md5(code)
cookieValue, _ := encrypt.StringEncrypt(codeWithMD5)
c.SetCookie(codeWithMD5, cookieValue, 604800, "", "", false, false)

expiredSetting, err := settingRepo.Get(settingRepo.WithByKey("ExpirationDays"))
if err != nil {
return err
}
timeout, _ := strconv.Atoi(expiredSetting.Value)
c.SetCookie(constant.PasswordExpiredName, encrypt.Md5(time.Now().Format("20060102150405")), 86400*timeout, "", "", false, false)
if err := settingRepo.Update("ExpirationTime", time.Now().AddDate(0, 0, timeout).Format("2006.01.02 15:04:05")); err != nil {
return err
}
return nil
}

func (u *AuthService) Login(c *gin.Context, info dto.Login) (*dto.UserLoginInfo, error) {
nameSetting, err := settingRepo.Get(settingRepo.WithByKey("UserName"))
if err != nil {
Expand Down
71 changes: 71 additions & 0 deletions backend/app/service/dashboard.go
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
}
1 change: 1 addition & 0 deletions backend/app/service/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func (u *SettingService) GetSettingInfo() (*dto.SettingInfo, error) {
info.MonitorStoreDays, _ = strconv.Atoi(settingMap["MonitorStoreDays"])
info.ServerPort, _ = strconv.Atoi(settingMap["ServerPort"])
info.SessionTimeout, _ = strconv.Atoi(settingMap["SessionTimeout"])
info.ExpirationDays, _ = strconv.Atoi(settingMap["ExpirationDays"])
info.LocalTime = time.Now().Format("2006-01-02 15:04:05")
return &info, err
}
Expand Down
1 change: 0 additions & 1 deletion backend/configs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package configs

type ServerConfig struct {
Sqlite Sqlite `mapstructure:"sqlite"`
Mysql Mysql `mapstructure:"mysql"`
System System `mapstructure:"system"`
LogConfig LogConfig `mapstructure:"log"`
CORS CORS `mapstructure:"cors"`
Expand Down
13 changes: 0 additions & 13 deletions backend/configs/general_db.go

This file was deleted.

11 changes: 0 additions & 11 deletions backend/configs/mysql.go

This file was deleted.

18 changes: 17 additions & 1 deletion backend/configs/sqlite.go
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
}
18 changes: 10 additions & 8 deletions backend/init/db/db.go
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
}
28 changes: 0 additions & 28 deletions backend/init/db/mysql.go

This file was deleted.

17 changes: 0 additions & 17 deletions backend/init/db/sqlite.go

This file was deleted.

1 change: 0 additions & 1 deletion backend/init/migration/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func Init() {
migrations.AddTableImageRepo,
migrations.AddTableWebsite,
migrations.AddTableDatabaseMysql,
migrations.AddTableLoginLog,
})
if err := m.Migrate(); err != nil {
global.LOG.Error(err)
Expand Down
4 changes: 2 additions & 2 deletions backend/init/migration/migrations/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion backend/router/ro_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ func (s *ContainerRouter) InitContainerRouter(Router *gin.RouterGroup) {
baseApi := v1.ApiGroupApp.BaseApi
{
baRouter.GET("/exec", baseApi.ContainerExec)
baRouter.GET("/stats/:id", baseApi.ContainerStats)

baRouter.POST("/search", baseApi.SearchContainer)
baRouter.POST("/inspect", baseApi.Inspect)
baRouter.POST("", baseApi.ContainerCreate)
withRecordRouter.POST("operate", baseApi.ContainerOperation)
withRecordRouter.POST("/log", baseApi.ContainerLogs)
withRecordRouter.GET("/stats/:id", baseApi.ContainerStats)

baRouter.POST("/repo/search", baseApi.SearchRepo)
baRouter.PUT("/repo/:id", baseApi.UpdateRepo)
Expand Down
Loading

0 comments on commit cfac341

Please sign in to comment.