Browse Source

feat: 修改main路径,增加打包静态资源

pull/32/head
zhengkunwang223 2 years ago committed by zhengkunwang223
parent
commit
115b75c1cb
  1. 6
      .gitignore
  2. 22
      Makefile
  3. 2
      apps/apps.json
  4. 16
      apps/list.json
  5. 6
      apps/mysql/5.7.39/docker-compose.yml
  6. 8
      apps/nginx/1.23.1/docker-compose.yml
  7. 0
      apps/redis/6.0.16/README.md
  8. 20
      apps/redis/6.0.16/config.json
  9. 15
      apps/redis/6.0.16/docker-compose.yml
  10. 0
      apps/redis/7.0.5/README.md
  11. 20
      apps/redis/7.0.5/config.json
  12. 15
      apps/redis/7.0.5/docker-compose.yml
  13. 6
      backend/app/api/v1/app.go
  14. 12
      backend/app/api/v1/auth.go
  15. 8
      backend/app/api/v1/backup.go
  16. 8
      backend/app/api/v1/command.go
  17. 8
      backend/app/api/v1/cronjob.go
  18. 2
      backend/app/api/v1/entry.go
  19. 10
      backend/app/api/v1/file.go
  20. 8
      backend/app/api/v1/group.go
  21. 6
      backend/app/api/v1/helper/helper.go
  22. 12
      backend/app/api/v1/host.go
  23. 10
      backend/app/api/v1/monitor.go
  24. 8
      backend/app/api/v1/operation_log.go
  25. 12
      backend/app/api/v1/setting.go
  26. 12
      backend/app/api/v1/terminal.go
  27. 2
      backend/app/dto/app.go
  28. 2
      backend/app/dto/file.go
  29. 2
      backend/app/model/app_install.go
  30. 11
      backend/app/model/app_install_backup.go
  31. 2
      backend/app/repo/app.go
  32. 2
      backend/app/repo/app_detail.go
  33. 2
      backend/app/repo/app_install.go
  34. 13
      backend/app/repo/app_install_backup.go
  35. 4
      backend/app/repo/app_install_resource.go
  36. 4
      backend/app/repo/app_tag.go
  37. 4
      backend/app/repo/backup.go
  38. 4
      backend/app/repo/command.go
  39. 2
      backend/app/repo/common.go
  40. 6
      backend/app/repo/cronjob.go
  41. 4
      backend/app/repo/database.go
  42. 4
      backend/app/repo/group.go
  43. 4
      backend/app/repo/host.go
  44. 4
      backend/app/repo/operation_log.go
  45. 4
      backend/app/repo/setting.go
  46. 4
      backend/app/repo/tag.go
  47. 56
      backend/app/service/app.go
  48. 65
      backend/app/service/app_utils.go
  49. 10
      backend/app/service/auth.go
  50. 8
      backend/app/service/backup.go
  51. 6
      backend/app/service/command.go
  52. 10
      backend/app/service/cornjob.go
  53. 8
      backend/app/service/cronjob_helper.go
  54. 2
      backend/app/service/entry.go
  55. 8
      backend/app/service/file.go
  56. 4
      backend/app/service/group.go
  57. 2
      backend/app/service/helper.go
  58. 6
      backend/app/service/host.go
  59. 8
      backend/app/service/operation_log.go
  60. 8
      backend/app/service/setting.go
  61. 10
      backend/cron/cron.go
  62. 6
      backend/cron/job/monitor.go
  63. 6
      backend/global/global.go
  64. 4
      backend/init/cache/cache.go
  65. 2
      backend/init/db/db.go
  66. 2
      backend/init/db/mysql.go
  67. 2
      backend/init/db/sqlite.go
  68. 6
      backend/init/log/log.go
  69. 4
      backend/init/migration/migrate.go
  70. 2
      backend/init/migration/migrations/init.go
  71. 13
      backend/init/router/router.go
  72. 2
      backend/init/session/psession/psession.go
  73. 4
      backend/init/session/session.go
  74. 2
      backend/init/validator/validator.go
  75. 6
      backend/init/viper/viper.go
  76. 7
      backend/main.go
  77. 4
      backend/middleware/cors.go
  78. 2
      backend/middleware/csrf.go
  79. 10
      backend/middleware/jwt.go
  80. 6
      backend/middleware/operation.go
  81. 4
      backend/middleware/password_expired.go
  82. 6
      backend/middleware/safety.go
  83. 8
      backend/middleware/session.go
  84. 4
      backend/router/operation_log.go
  85. 4
      backend/router/ro_app.go
  86. 4
      backend/router/ro_backup.go
  87. 4
      backend/router/ro_base.go
  88. 4
      backend/router/ro_command.go
  89. 4
      backend/router/ro_cronjob.go
  90. 4
      backend/router/ro_file.go
  91. 4
      backend/router/ro_group.go
  92. 4
      backend/router/ro_host.go
  93. 4
      backend/router/ro_monitor.go
  94. 4
      backend/router/ro_setting.go
  95. 4
      backend/router/ro_terminal.go
  96. 36
      backend/server/server.go
  97. 4
      backend/utils/captcha/captcha.go
  98. 2
      backend/utils/cloud_storage/client/minio.go
  99. 2
      backend/utils/cloud_storage/client/oss.go
  100. 2
      backend/utils/cloud_storage/client/s3.go
  101. Some files were not shown because too many files have changed in this diff Show More

6
.gitignore vendored

@ -5,6 +5,12 @@
*.so *.so
*.dylib *.dylib
.idea .idea
cmd/server/web/assets/
cmd/server/web/monacoeditorwork
cmd/server/web/favicon.ico
cmd/server/web/index.html
build
# Test binary, built with `go test -c` # Test binary, built with `go test -c`
*.test *.test

22
Makefile

@ -0,0 +1,22 @@
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOARCH=$(shell go env GOARCH)
GOOS=$(shell go env GOOS )
BASE_PAH := $(shell pwd)
BUILD_PATH = $(BASE_PAH)/build
WEB_PATH=$(BASE_PAH)/frontend
SERVER_PATH=$(BASE_PAH)/backend
MAIN= $(BASE_PAH)/cmd/server/main.go
APP_NAME=1panel
build_web:
cd $(WEB_PATH) && npm install && npm run build:dev
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

2
apps/apps.json

@ -1,4 +1,4 @@
{ {
"version": "0.0.1", "version": "0.0.3",
"package": "" "package": ""
} }

16
apps/list.json

@ -1,5 +1,5 @@
{ {
"version": "0.1", "version": "0.0.2",
"tags": [ "tags": [
{ {
"key": "WebSite", "key": "WebSite",
@ -56,6 +56,20 @@
"limit": 0, "limit": 0,
"crossVersionUpdate": true, "crossVersionUpdate": true,
"source": "http://wordpress.org/" "source": "http://wordpress.org/"
},
{
"key": "redis",
"name": "redis",
"tags": ["Datastore"],
"versions": ["7.0.5","6.0.16"],
"short_desc": "缓存数据库",
"icon": "redis.png",
"author": "Salvatore Sanfilippo",
"type": "runtime",
"required": [""],
"limit": 0,
"crossVersionUpdate": true,
"source": "https://redis.io/"
} }
] ]
} }

6
apps/mysql/5.7.39/docker-compose.yml

@ -19,4 +19,8 @@ services:
--character-set-server=utf8mb4 --character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci --collation-server=utf8mb4_general_ci
--explicit_defaults_for_timestamp=true --explicit_defaults_for_timestamp=true
--lower_case_table_names=1 --lower_case_table_names=1
networks:
1panel:
external: true

8
apps/nginx/1.23.1/docker-compose.yml

@ -3,6 +3,8 @@ services:
container_name: ${CONTAINER_NAME} container_name: ${CONTAINER_NAME}
image: nginx:1.23.1 image: nginx:1.23.1
restart: always restart: always
networks:
- 1panel
ports: ports:
- ${PANEL_APP_PORT_HTTP}:80 - ${PANEL_APP_PORT_HTTP}:80
- ${PANEL_APP_PORT_HTTPS}:443 - ${PANEL_APP_PORT_HTTPS}:443
@ -11,4 +13,8 @@ services:
- ./www:/home/www - ./www:/home/www
- ./log:/var/log/nginx - ./log:/var/log/nginx
- ./conf/conf.d:/etc/nginx/conf.d/ - ./conf/conf.d:/etc/nginx/conf.d/
- ./html:/usr/share/nginx/html - ./html:/usr/share/nginx/html
networks:
1panel:
external: true

0
apps/redis/6.0.16/README.md

20
apps/redis/6.0.16/config.json

@ -0,0 +1,20 @@
{
"formFields": [
{
"type": "text",
"labelZh": "密码",
"labelEn": "Password",
"required": true,
"default": "eYVX7EwVmmxKPCDmwMtyKVge8oLd2t81",
"envKey": "PANEL_DB_ROOT_PASSWORD"
},
{
"type": "number",
"labelZh": "端口",
"labelEn": "Port",
"required": true,
"default": 6379,
"envKey": "PANEL_APP_PORT_HTTP"
}
]
}

15
apps/redis/6.0.16/docker-compose.yml

@ -0,0 +1,15 @@
version: '3'
services:
redis-6.0.16:
image: redis:6.0.16
restart: always
networks:
- 1panel
ports:
- ${PANEL_APP_PORT_HTTP}:6379
command: redis-server --save 20 1 --loglevel warning --requirepass eYVX7EwVmmxKPCDmwMtyKVge8oLd2t81
volumes:
- ./data:/data
networks:
1panel:
external: true

0
apps/redis/7.0.5/README.md

20
apps/redis/7.0.5/config.json

@ -0,0 +1,20 @@
{
"formFields": [
{
"type": "text",
"labelZh": "密码",
"labelEn": "Password",
"required": true,
"default": "eYVX7EwVmmxKPCDmwMtyKVge8oLd2t81",
"envKey": "PANEL_DB_ROOT_PASSWORD"
},
{
"type": "number",
"labelZh": "端口",
"labelEn": "Port",
"required": true,
"default": 6379,
"envKey": "PANEL_APP_PORT_HTTP"
}
]
}

15
apps/redis/7.0.5/docker-compose.yml

@ -0,0 +1,15 @@
version: '3'
services:
redis-7.0.5:
image: redis:7.0.5
restart: always
networks:
- 1panel
ports:
- ${PANEL_APP_PORT_HTTP}:6379
command: redis-server --save 20 1 --loglevel warning --requirepass eYVX7EwVmmxKPCDmwMtyKVge8oLd2t81
volumes:
- ./data:/data
networks:
1panel:
external: true

6
backend/app/api/v1/app.go

@ -1,9 +1,9 @@
package v1 package v1
import ( import (
"github.com/1Panel-dev/1Panel/app/api/v1/helper" "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
"github.com/1Panel-dev/1Panel/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"strconv" "strconv"
) )

12
backend/app/api/v1/auth.go

@ -3,12 +3,12 @@ package v1
import ( import (
"errors" "errors"
"github.com/1Panel-dev/1Panel/app/api/v1/helper" "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
"github.com/1Panel-dev/1Panel/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/utils/captcha" "github.com/1Panel-dev/1Panel/backend/utils/captcha"
"github.com/1Panel-dev/1Panel/utils/encrypt" "github.com/1Panel-dev/1Panel/backend/utils/encrypt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

8
backend/app/api/v1/backup.go

@ -1,10 +1,10 @@
package v1 package v1
import ( import (
"github.com/1Panel-dev/1Panel/app/api/v1/helper" "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
"github.com/1Panel-dev/1Panel/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

8
backend/app/api/v1/command.go

@ -1,10 +1,10 @@
package v1 package v1
import ( import (
"github.com/1Panel-dev/1Panel/app/api/v1/helper" "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
"github.com/1Panel-dev/1Panel/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

8
backend/app/api/v1/cronjob.go

@ -4,10 +4,10 @@ import (
"os" "os"
"time" "time"
"github.com/1Panel-dev/1Panel/app/api/v1/helper" "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
"github.com/1Panel-dev/1Panel/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

2
backend/app/api/v1/entry.go

@ -1,6 +1,6 @@
package v1 package v1
import "github.com/1Panel-dev/1Panel/app/service" import "github.com/1Panel-dev/1Panel/backend/app/service"
type ApiGroup struct { type ApiGroup struct {
BaseApi BaseApi

10
backend/app/api/v1/file.go

@ -2,11 +2,11 @@ package v1
import ( import (
"fmt" "fmt"
"github.com/1Panel-dev/1Panel/app/api/v1/helper" "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
"github.com/1Panel-dev/1Panel/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
websocket2 "github.com/1Panel-dev/1Panel/utils/websocket" websocket2 "github.com/1Panel-dev/1Panel/backend/utils/websocket"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"net/http" "net/http"

8
backend/app/api/v1/group.go

@ -1,10 +1,10 @@
package v1 package v1
import ( import (
"github.com/1Panel-dev/1Panel/app/api/v1/helper" "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
"github.com/1Panel-dev/1Panel/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

6
backend/app/api/v1/helper/helper.go

@ -6,9 +6,9 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/1Panel-dev/1Panel/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/i18n" "github.com/1Panel-dev/1Panel/backend/i18n"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

12
backend/app/api/v1/host.go

@ -1,12 +1,12 @@
package v1 package v1
import ( import (
"github.com/1Panel-dev/1Panel/app/api/v1/helper" "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
"github.com/1Panel-dev/1Panel/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/utils/copier" "github.com/1Panel-dev/1Panel/backend/utils/copier"
"github.com/1Panel-dev/1Panel/utils/ssh" "github.com/1Panel-dev/1Panel/backend/utils/ssh"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

10
backend/app/api/v1/monitor.go

@ -3,11 +3,11 @@ package v1
import ( import (
"time" "time"
"github.com/1Panel-dev/1Panel/app/api/v1/helper" "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
"github.com/1Panel-dev/1Panel/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/shirou/gopsutil/net" "github.com/shirou/gopsutil/net"
) )

8
backend/app/api/v1/operation_log.go

@ -1,10 +1,10 @@
package v1 package v1
import ( import (
"github.com/1Panel-dev/1Panel/app/api/v1/helper" "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
"github.com/1Panel-dev/1Panel/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

12
backend/app/api/v1/setting.go

@ -3,12 +3,12 @@ package v1
import ( import (
"errors" "errors"
"github.com/1Panel-dev/1Panel/app/api/v1/helper" "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
"github.com/1Panel-dev/1Panel/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/utils/mfa" "github.com/1Panel-dev/1Panel/backend/utils/mfa"
"github.com/1Panel-dev/1Panel/utils/ntp" "github.com/1Panel-dev/1Panel/backend/utils/ntp"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

12
backend/app/api/v1/terminal.go

@ -5,12 +5,12 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/1Panel-dev/1Panel/app/api/v1/helper" "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/utils/copier" "github.com/1Panel-dev/1Panel/backend/utils/copier"
"github.com/1Panel-dev/1Panel/utils/ssh" "github.com/1Panel-dev/1Panel/backend/utils/ssh"
"github.com/1Panel-dev/1Panel/utils/terminal" "github.com/1Panel-dev/1Panel/backend/utils/terminal"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"github.com/pkg/errors" "github.com/pkg/errors"

2
backend/app/dto/app.go

@ -2,7 +2,7 @@ package dto
import ( import (
"encoding/json" "encoding/json"
"github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
) )
type AppRes struct { type AppRes struct {

2
backend/app/dto/file.go

@ -1,7 +1,7 @@
package dto package dto
import ( import (
"github.com/1Panel-dev/1Panel/utils/files" "github.com/1Panel-dev/1Panel/backend/utils/files"
) )
type FileOption struct { type FileOption struct {

2
backend/app/model/app_install.go

@ -1,7 +1,7 @@
package model package model
import ( import (
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"path" "path"
) )

11
backend/app/model/app_install_backup.go

@ -2,9 +2,10 @@ package model
type AppInstallBackup struct { type AppInstallBackup struct {
BaseModel BaseModel
Name string `gorm:"type:varchar(64);not null" json:"name"` Name string `gorm:"type:varchar(64);not null" json:"name"`
Path string `gorm:"type:varchar(64);not null" json:"path"` Path string `gorm:"type:varchar(64);not null" json:"path"`
Param string `gorm:"type:longtext;" json:"param"` Param string `gorm:"type:longtext;" json:"param"`
AppDetailId uint `gorm:"type:integer;not null" json:"app_detail_id"` AppDetailId uint `gorm:"type:integer;not null" json:"app_detail_id"`
AppInstallId uint `gorm:"type:integer;not null" json:"app_install_id"` AppInstallId uint `gorm:"type:integer;not null" json:"app_install_id"`
AppDetail AppDetail `json:"-"`
} }

2
backend/app/repo/app.go

@ -2,7 +2,7 @@ package repo
import ( import (
"context" "context"
"github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"gorm.io/gorm" "gorm.io/gorm"
"gorm.io/gorm/clause" "gorm.io/gorm/clause"
) )

2
backend/app/repo/app_detail.go

@ -2,7 +2,7 @@ package repo
import ( import (
"context" "context"
"github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"gorm.io/gorm" "gorm.io/gorm"
) )

2
backend/app/repo/app_install.go

@ -2,7 +2,7 @@ package repo
import ( import (
"context" "context"
"github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"gorm.io/gorm" "gorm.io/gorm"
) )

13
backend/app/repo/app_install_backup.go

@ -2,7 +2,7 @@ package repo
import ( import (
"context" "context"
"github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"gorm.io/gorm" "gorm.io/gorm"
"gorm.io/gorm/clause" "gorm.io/gorm/clause"
) )
@ -20,12 +20,13 @@ func (a AppInstallBackupRepo) Create(ctx context.Context, backup model.AppInstal
return getTx(ctx).Omit(clause.Associations).Create(&backup).Error return getTx(ctx).Omit(clause.Associations).Create(&backup).Error
} }
func (a AppInstallBackupRepo) Delete(opts ...DBOption) error { func (a AppInstallBackupRepo) Delete(ctx context.Context, opts ...DBOption) error {
return getDb(opts...).Omit(clause.Associations).Delete(&model.AppInstallBackup{}).Error return getTx(ctx, opts...).Omit(clause.Associations).Delete(&model.AppInstallBackup{}).Error
} }
func (a AppInstallBackupRepo) GetBy(opts ...DBOption) ([]model.AppInstallBackup, error) { func (a AppInstallBackupRepo) GetBy(opts ...DBOption) ([]model.AppInstallBackup, error) {
var backups []model.AppInstallBackup var backups []model.AppInstallBackup
if err := getDb(opts...).Find(&backups); err != nil { if err := getDb(opts...).Preload("AppDetail").Find(&backups); err != nil {
return backups, nil return backups, nil
} }
return backups, nil return backups, nil
@ -34,7 +35,7 @@ func (a AppInstallBackupRepo) GetBy(opts ...DBOption) ([]model.AppInstallBackup,
func (a AppInstallBackupRepo) GetFirst(opts ...DBOption) (model.AppInstallBackup, error) { func (a AppInstallBackupRepo) GetFirst(opts ...DBOption) (model.AppInstallBackup, error) {
var backup model.AppInstallBackup var backup model.AppInstallBackup
db := getDb(opts...).Model(&model.AppInstallBackup{}) db := getDb(opts...).Model(&model.AppInstallBackup{})
err := db.First(&backup).Error err := db.Preload("AppDetail").First(&backup).Error
return backup, err return backup, err
} }
@ -43,6 +44,6 @@ func (a AppInstallBackupRepo) Page(page, size int, opts ...DBOption) (int64, []m
db := getDb(opts...).Model(&model.AppInstallBackup{}) db := getDb(opts...).Model(&model.AppInstallBackup{})
count := int64(0) count := int64(0)
db = db.Count(&count) db = db.Count(&count)
err := db.Debug().Limit(size).Offset(size * (page - 1)).Find(&backups).Error err := db.Limit(size).Offset(size * (page - 1)).Preload("AppDetail").Find(&backups).Error
return count, backups, err return count, backups, err
} }

4
backend/app/repo/app_install_resource.go

@ -2,8 +2,8 @@ package repo
import ( import (
"context" "context"
"github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"gorm.io/gorm" "gorm.io/gorm"
) )

4
backend/app/repo/app_tag.go

@ -2,8 +2,8 @@ package repo
import ( import (
"context" "context"
"github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"gorm.io/gorm" "gorm.io/gorm"
) )

4
backend/app/repo/backup.go

@ -1,8 +1,8 @@
package repo package repo
import ( import (
"github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
) )
type BackupRepo struct{} type BackupRepo struct{}

4
backend/app/repo/command.go

@ -1,8 +1,8 @@
package repo package repo
import ( import (
"github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"gorm.io/gorm" "gorm.io/gorm"
) )

2
backend/app/repo/common.go

@ -2,7 +2,7 @@ package repo
import ( import (
"context" "context"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"gorm.io/gorm" "gorm.io/gorm"
) )

6
backend/app/repo/cronjob.go

@ -3,9 +3,9 @@ package repo
import ( import (
"time" "time"
"github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"gorm.io/gorm" "gorm.io/gorm"
) )

4
backend/app/repo/database.go

@ -2,8 +2,8 @@ package repo
import ( import (
"context" "context"
"github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"gorm.io/gorm" "gorm.io/gorm"
) )

4
backend/app/repo/group.go

@ -1,8 +1,8 @@
package repo package repo
import ( import (
"github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"gorm.io/gorm" "gorm.io/gorm"
) )

4
backend/app/repo/host.go

@ -1,8 +1,8 @@
package repo package repo
import ( import (
"github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"gorm.io/gorm" "gorm.io/gorm"
) )

4
backend/app/repo/operation_log.go

@ -1,8 +1,8 @@
package repo package repo
import ( import (
"github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
) )
type OperationRepo struct{} type OperationRepo struct{}

4
backend/app/repo/setting.go

@ -1,8 +1,8 @@
package repo package repo
import ( import (
"github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"gorm.io/gorm" "gorm.io/gorm"
) )

4
backend/app/repo/tag.go

@ -2,8 +2,8 @@ package repo
import ( import (
"context" "context"
"github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"gorm.io/gorm" "gorm.io/gorm"
) )

56
backend/app/service/app.go

@ -5,15 +5,15 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"github.com/1Panel-dev/1Panel/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/app/repo" "github.com/1Panel-dev/1Panel/backend/app/repo"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/utils/common" "github.com/1Panel-dev/1Panel/backend/utils/common"
"github.com/1Panel-dev/1Panel/utils/compose" "github.com/1Panel-dev/1Panel/backend/utils/compose"
"github.com/1Panel-dev/1Panel/utils/docker" "github.com/1Panel-dev/1Panel/backend/utils/docker"
"github.com/1Panel-dev/1Panel/utils/files" "github.com/1Panel-dev/1Panel/backend/utils/files"
"golang.org/x/net/context" "golang.org/x/net/context"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"os" "os"
@ -175,35 +175,9 @@ func (a AppService) OperateInstall(req dto.AppInstallOperate) error {
} }
install.Status = constant.Running install.Status = constant.Running
case dto.Delete: case dto.Delete:
op := files.NewFileOp() return deleteAppInstall(install)
appDir := install.GetPath()
dir, _ := os.Stat(appDir)
if dir != nil {
out, err := compose.Down(dockerComposePath)
if err != nil {
return handleErr(install, err, out)
}
if err := op.DeleteDir(appDir); err != nil {
return err
}
}
tx, ctx := getTxAndContext()
if err := appInstallRepo.Delete(ctx, install); err != nil {
tx.Rollback()
return err
}
if err := deleteLink(ctx, &install); err != nil {
tx.Rollback()
return err
}
tx.Commit()
return nil
case dto.Sync: case dto.Sync:
if err := a.SyncInstalled(install.ID); err != nil { return a.SyncInstalled(install.ID)
return err
}
return nil
case dto.Backup: case dto.Backup:
tx, ctx := getTxAndContext() tx, ctx := getTxAndContext()
if err := backupInstall(ctx, install); err != nil { if err := backupInstall(ctx, install); err != nil {
@ -213,11 +187,7 @@ func (a AppService) OperateInstall(req dto.AppInstallOperate) error {
tx.Commit() tx.Commit()
return nil return nil
case dto.Restore: case dto.Restore:
installBackup, err := appInstallBackupRepo.GetFirst(commonRepo.WithByID(req.BackupId)) return restoreInstall(install, req.BackupId)
if err != nil {
return err
}
return restoreInstall(install, installBackup)
case dto.Update: case dto.Update:
return updateInstall(install.ID, req.DetailId) return updateInstall(install.ID, req.DetailId)
default: default:
@ -344,7 +314,7 @@ func (a AppService) DeleteBackup(req dto.AppBackupDeleteRequest) error {
errStr.WriteString(err.Error()) errStr.WriteString(err.Error())
continue continue
} }
if err := appInstallBackupRepo.Delete(commonRepo.WithIdsIn(req.Ids)); err != nil { if err := appInstallBackupRepo.Delete(nil, commonRepo.WithIdsIn(req.Ids)); err != nil {
errStr.WriteString(err.Error()) errStr.WriteString(err.Error())
} }
} }

65
backend/app/service/app_utils.go

@ -4,14 +4,14 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/1Panel-dev/1Panel/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/utils/cmd" "github.com/1Panel-dev/1Panel/backend/utils/cmd"
"github.com/1Panel-dev/1Panel/utils/common" "github.com/1Panel-dev/1Panel/backend/utils/common"
"github.com/1Panel-dev/1Panel/utils/compose" "github.com/1Panel-dev/1Panel/backend/utils/compose"
"github.com/1Panel-dev/1Panel/utils/files" "github.com/1Panel-dev/1Panel/backend/utils/files"
"github.com/joho/godotenv" "github.com/joho/godotenv"
"github.com/pkg/errors" "github.com/pkg/errors"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
@ -140,6 +140,37 @@ func createLink(ctx context.Context, app model.App, appInstall *model.AppInstall
return nil return nil
} }
func deleteAppInstall(install model.AppInstall) error {
op := files.NewFileOp()
appDir := install.GetPath()
dir, _ := os.Stat(appDir)
if dir != nil {
out, err := compose.Down(install.GetComposePath())
if err != nil {
return handleErr(install, err, out)
}
if err := op.DeleteDir(appDir); err != nil {
return err
}
}
tx, ctx := getTxAndContext()
if err := appInstallRepo.Delete(ctx, install); err != nil {
tx.Rollback()
return err
}
if err := deleteLink(ctx, &install); err != nil {
tx.Rollback()
return err
}
if err := appInstallBackupRepo.Delete(ctx, appInstallBackupRepo.WithAppInstallID(install.ID)); err != nil {
tx.Rollback()
return err
}
tx.Commit()
return nil
}
func deleteLink(ctx context.Context, install *model.AppInstall) error { func deleteLink(ctx context.Context, install *model.AppInstall) error {
resources, _ := appInstallResourceRepo.GetBy(appInstallResourceRepo.WithAppInstallId(install.ID)) resources, _ := appInstallResourceRepo.GetBy(appInstallResourceRepo.WithAppInstallId(install.ID))
if len(resources) == 0 { if len(resources) == 0 {
@ -171,12 +202,20 @@ func updateInstall(installId uint, detailId uint) error {
if err != nil { if err != nil {
return err return err
} }
oldDetail, err := appDetailRepo.GetFirst(commonRepo.WithByID(install.AppDetailId))
if err != nil {
return err
}
detail, err := appDetailRepo.GetFirst(commonRepo.WithByID(detailId)) detail, err := appDetailRepo.GetFirst(commonRepo.WithByID(detailId))
if err != nil { if err != nil {
return err return err
} }
if oldDetail.LastVersion == detail.Version {
install.CanUpdate = false
}
if install.Version == detail.Version { if install.Version == detail.Version {
return errors.New("two version is save") return errors.New("two version is same")
} }
tx, ctx := getTxAndContext() tx, ctx := getTxAndContext()
if err := backupInstall(ctx, install); err != nil { if err := backupInstall(ctx, install); err != nil {
@ -188,6 +227,7 @@ func updateInstall(installId uint, detailId uint) error {
} }
install.DockerCompose = detail.DockerCompose install.DockerCompose = detail.DockerCompose
install.Version = detail.Version install.Version = detail.Version
fileOp := files.NewFileOp() fileOp := files.NewFileOp()
if err := fileOp.WriteFile(install.GetComposePath(), strings.NewReader(install.DockerCompose), 0775); err != nil { if err := fileOp.WriteFile(install.GetComposePath(), strings.NewReader(install.DockerCompose), 0775); err != nil {
return err return err
@ -221,7 +261,11 @@ func backupInstall(ctx context.Context, install model.AppInstall) error {
return nil return nil
} }
func restoreInstall(install model.AppInstall, backup model.AppInstallBackup) error { func restoreInstall(install model.AppInstall, backupId uint) error {
backup, err := appInstallBackupRepo.GetFirst(commonRepo.WithByID(backupId))
if err != nil {
return err
}
if _, err := compose.Down(install.GetComposePath()); err != nil { if _, err := compose.Down(install.GetComposePath()); err != nil {
return err return err
} }
@ -284,6 +328,7 @@ func restoreInstall(install model.AppInstall, backup model.AppInstallBackup) err
return handleErr(install, err, out) return handleErr(install, err, out)
} }
install.AppDetailId = backup.AppDetailId install.AppDetailId = backup.AppDetailId
install.Version = backup.AppDetail.Version
install.Status = constant.Running install.Status = constant.Running
return appInstallRepo.Save(&install) return appInstallRepo.Save(&install)
} }

10
backend/app/service/auth.go

@ -3,11 +3,11 @@ package service
import ( import (
"strconv" "strconv"
"github.com/1Panel-dev/1Panel/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/utils/encrypt" "github.com/1Panel-dev/1Panel/backend/utils/encrypt"
"github.com/1Panel-dev/1Panel/utils/jwt" "github.com/1Panel-dev/1Panel/backend/utils/jwt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/pkg/errors" "github.com/pkg/errors"
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"

8
backend/app/service/backup.go

@ -3,10 +3,10 @@ package service
import ( import (
"encoding/json" "encoding/json"
"github.com/1Panel-dev/1Panel/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/utils/cloud_storage" "github.com/1Panel-dev/1Panel/backend/utils/cloud_storage"
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
"github.com/pkg/errors" "github.com/pkg/errors"
) )

6
backend/app/service/command.go

@ -1,9 +1,9 @@
package service package service
import ( import (
"github.com/1Panel-dev/1Panel/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
"github.com/pkg/errors" "github.com/pkg/errors"
) )

10
backend/app/service/cornjob.go

@ -8,11 +8,11 @@ import (
"strings" "strings"
"time" "time"
"github.com/1Panel-dev/1Panel/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/utils/cloud_storage" "github.com/1Panel-dev/1Panel/backend/utils/cloud_storage"
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/robfig/cron/v3" "github.com/robfig/cron/v3"

8
backend/app/service/cronjob_helper.go

@ -11,10 +11,10 @@ import (
"strings" "strings"
"time" "time"
"github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/utils/cloud_storage" "github.com/1Panel-dev/1Panel/backend/utils/cloud_storage"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/robfig/cron/v3" "github.com/robfig/cron/v3"
) )

2
backend/app/service/entry.go

@ -1,6 +1,6 @@
package service package service
import "github.com/1Panel-dev/1Panel/app/repo" import "github.com/1Panel-dev/1Panel/backend/app/repo"
type ServiceGroup struct { type ServiceGroup struct {
AuthService AuthService

8
backend/app/service/file.go

@ -2,10 +2,10 @@ package service
import ( import (
"fmt" "fmt"
"github.com/1Panel-dev/1Panel/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/utils/common" "github.com/1Panel-dev/1Panel/backend/utils/common"
"github.com/1Panel-dev/1Panel/utils/files" "github.com/1Panel-dev/1Panel/backend/utils/files"
"github.com/pkg/errors" "github.com/pkg/errors"
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
"io/fs" "io/fs"

4
backend/app/service/group.go

@ -1,8 +1,8 @@
package service package service
import ( import (
"github.com/1Panel-dev/1Panel/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
"github.com/pkg/errors" "github.com/pkg/errors"
) )

2
backend/app/service/helper.go

@ -2,7 +2,7 @@ package service
import ( import (
"context" "context"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"gorm.io/gorm" "gorm.io/gorm"
) )

6
backend/app/service/host.go

@ -3,9 +3,9 @@ package service
import ( import (
"fmt" "fmt"
"github.com/1Panel-dev/1Panel/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
"github.com/pkg/errors" "github.com/pkg/errors"
) )

8
backend/app/service/operation_log.go

@ -3,10 +3,10 @@ package service
import ( import (
"encoding/json" "encoding/json"
"github.com/1Panel-dev/1Panel/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
"github.com/pkg/errors" "github.com/pkg/errors"
) )

8
backend/app/service/setting.go

@ -5,10 +5,10 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/1Panel-dev/1Panel/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/utils/encrypt" "github.com/1Panel-dev/1Panel/backend/utils/encrypt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

10
backend/cron/cron.go

@ -3,11 +3,11 @@ package cron
import ( import (
"time" "time"
"github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/app/service" "github.com/1Panel-dev/1Panel/backend/app/service"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/cron/job" "github.com/1Panel-dev/1Panel/backend/cron/job"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/robfig/cron/v3" "github.com/robfig/cron/v3"
) )

6
backend/cron/job/monitor.go

@ -4,9 +4,9 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/app/repo" "github.com/1Panel-dev/1Panel/backend/app/repo"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/shirou/gopsutil/cpu" "github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/disk" "github.com/shirou/gopsutil/disk"
"github.com/shirou/gopsutil/load" "github.com/shirou/gopsutil/load"

6
backend/global/global.go

@ -1,9 +1,9 @@
package global package global
import ( import (
"github.com/1Panel-dev/1Panel/configs" "github.com/1Panel-dev/1Panel/backend/configs"
"github.com/1Panel-dev/1Panel/init/cache/badger_db" "github.com/1Panel-dev/1Panel/backend/init/cache/badger_db"
"github.com/1Panel-dev/1Panel/init/session/psession" "github.com/1Panel-dev/1Panel/backend/init/session/psession"
"github.com/go-playground/validator/v10" "github.com/go-playground/validator/v10"
"github.com/robfig/cron/v3" "github.com/robfig/cron/v3"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"

4
backend/init/cache/cache.go vendored

@ -1,8 +1,8 @@
package cache package cache
import ( import (
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/init/cache/badger_db" "github.com/1Panel-dev/1Panel/backend/init/cache/badger_db"
"github.com/dgraph-io/badger/v3" "github.com/dgraph-io/badger/v3"
"time" "time"
) )

2
backend/init/db/db.go

@ -1,6 +1,6 @@
package db package db
import "github.com/1Panel-dev/1Panel/global" import "github.com/1Panel-dev/1Panel/backend/global"
func Init() { func Init() {
switch global.CONF.System.DbType { switch global.CONF.System.DbType {

2
backend/init/db/mysql.go

@ -1,7 +1,7 @@
package db package db
import ( import (
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"gorm.io/driver/mysql" "gorm.io/driver/mysql"
"gorm.io/gorm" "gorm.io/gorm"

2
backend/init/db/sqlite.go

@ -1,7 +1,7 @@
package db package db
import ( import (
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"gorm.io/driver/sqlite" "gorm.io/driver/sqlite"
"gorm.io/gorm" "gorm.io/gorm"

6
backend/init/log/log.go

@ -6,8 +6,8 @@ import (
"strings" "strings"
"time" "time"
"github.com/1Panel-dev/1Panel/configs" "github.com/1Panel-dev/1Panel/backend/configs"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/natefinch/lumberjack" "github.com/natefinch/lumberjack"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -45,7 +45,7 @@ func (s *MineFormatter) Format(entry *logrus.Entry) ([]byte, error) {
var cstSh, _ = time.LoadLocation(global.CONF.LogConfig.TimeZone) var cstSh, _ = time.LoadLocation(global.CONF.LogConfig.TimeZone)
detailInfo := "" detailInfo := ""
if entry.Caller != nil { if entry.Caller != nil {
funcion := strings.ReplaceAll(entry.Caller.Function, "github.com/1Panel-dev/1Panel/", "") funcion := strings.ReplaceAll(entry.Caller.Function, "github.com/1Panel-dev/1Panel/backend/", "")
detailInfo = fmt.Sprintf("(%s: %d)", funcion, entry.Caller.Line) detailInfo = fmt.Sprintf("(%s: %d)", funcion, entry.Caller.Line)
} }
if len(entry.Data) == 0 { if len(entry.Data) == 0 {

4
backend/init/migration/migrate.go

@ -1,8 +1,8 @@
package migration package migration
import ( import (
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/init/migration/migrations" "github.com/1Panel-dev/1Panel/backend/init/migration/migrations"
"github.com/go-gormigrate/gormigrate/v2" "github.com/go-gormigrate/gormigrate/v2"
) )

2
backend/init/migration/migrations/init.go

@ -3,7 +3,7 @@ package migrations
import ( import (
"time" "time"
"github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/go-gormigrate/gormigrate/v2" "github.com/go-gormigrate/gormigrate/v2"
"gorm.io/gorm" "gorm.io/gorm"

13
backend/init/router/router.go

@ -1,17 +1,16 @@
package router package router
import ( import (
"html/template" v1 "github.com/1Panel-dev/1Panel/backend/app/api/v1"
"github.com/1Panel-dev/1Panel/backend/docs"
v1 "github.com/1Panel-dev/1Panel/app/api/v1" "github.com/1Panel-dev/1Panel/backend/i18n"
"github.com/1Panel-dev/1Panel/docs" "github.com/1Panel-dev/1Panel/backend/middleware"
"github.com/1Panel-dev/1Panel/i18n" rou "github.com/1Panel-dev/1Panel/backend/router"
"github.com/1Panel-dev/1Panel/middleware"
rou "github.com/1Panel-dev/1Panel/router"
ginI18n "github.com/gin-contrib/i18n" ginI18n "github.com/gin-contrib/i18n"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
swaggerfiles "github.com/swaggo/files" swaggerfiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger" ginSwagger "github.com/swaggo/gin-swagger"
"html/template"
) )
func Routers() *gin.Engine { func Routers() *gin.Engine {

2
backend/init/session/psession/psession.go

@ -2,7 +2,7 @@ package psession
import ( import (
"encoding/json" "encoding/json"
"github.com/1Panel-dev/1Panel/init/cache/badger_db" "github.com/1Panel-dev/1Panel/backend/init/cache/badger_db"
"time" "time"
) )

4
backend/init/session/session.go

@ -1,8 +1,8 @@
package session package session
import ( import (
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/init/session/psession" "github.com/1Panel-dev/1Panel/backend/init/session/psession"
) )
func Init() { func Init() {

2
backend/init/validator/validator.go

@ -4,7 +4,7 @@ import (
"regexp" "regexp"
"unicode" "unicode"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/go-playground/validator/v10" "github.com/go-playground/validator/v10"
) )

6
backend/init/viper/viper.go

@ -2,9 +2,9 @@ package viper
import ( import (
"fmt" "fmt"
"github.com/1Panel-dev/1Panel/configs" "github.com/1Panel-dev/1Panel/backend/configs"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"path" "path"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"

7
backend/main.go

@ -1,7 +0,0 @@
package main
import "github.com/1Panel-dev/1Panel/server"
func main() {
server.Start()
}

4
backend/middleware/cors.go

@ -3,8 +3,8 @@ package middleware
import ( import (
"net/http" "net/http"
"github.com/1Panel-dev/1Panel/configs" "github.com/1Panel-dev/1Panel/backend/configs"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

2
backend/middleware/csrf.go

@ -3,7 +3,7 @@ package middleware
import ( import (
"net/http" "net/http"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/gorilla/csrf" "github.com/gorilla/csrf"
adapter "github.com/gwatts/gin-adapter" adapter "github.com/gwatts/gin-adapter"

10
backend/middleware/jwt.go

@ -4,11 +4,11 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/1Panel-dev/1Panel/app/api/v1/helper" "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
"github.com/1Panel-dev/1Panel/app/repo" "github.com/1Panel-dev/1Panel/backend/app/repo"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
jwtUtils "github.com/1Panel-dev/1Panel/utils/jwt" jwtUtils "github.com/1Panel-dev/1Panel/backend/utils/jwt"
"github.com/golang-jwt/jwt/v4" "github.com/golang-jwt/jwt/v4"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"

6
backend/middleware/operation.go

@ -9,9 +9,9 @@ import (
"strings" "strings"
"time" "time"
"github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/app/service" "github.com/1Panel-dev/1Panel/backend/app/service"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

4
backend/middleware/password_expired.go

@ -1,8 +1,8 @@
package middleware package middleware
import ( import (
"github.com/1Panel-dev/1Panel/app/api/v1/helper" "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

6
backend/middleware/safety.go

@ -1,9 +1,9 @@
package middleware package middleware
import ( import (
"github.com/1Panel-dev/1Panel/app/api/v1/helper" "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
"github.com/1Panel-dev/1Panel/app/service" "github.com/1Panel-dev/1Panel/backend/app/service"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

8
backend/middleware/session.go

@ -3,10 +3,10 @@ package middleware
import ( import (
"strconv" "strconv"
"github.com/1Panel-dev/1Panel/app/api/v1/helper" "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
"github.com/1Panel-dev/1Panel/app/repo" "github.com/1Panel-dev/1Panel/backend/app/repo"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

4
backend/router/operation_log.go

@ -1,8 +1,8 @@
package router package router
import ( import (
v1 "github.com/1Panel-dev/1Panel/app/api/v1" v1 "github.com/1Panel-dev/1Panel/backend/app/api/v1"
"github.com/1Panel-dev/1Panel/middleware" "github.com/1Panel-dev/1Panel/backend/middleware"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

4
backend/router/ro_app.go

@ -1,8 +1,8 @@
package router package router
import ( import (
v1 "github.com/1Panel-dev/1Panel/app/api/v1" v1 "github.com/1Panel-dev/1Panel/backend/app/api/v1"
"github.com/1Panel-dev/1Panel/middleware" "github.com/1Panel-dev/1Panel/backend/middleware"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

4
backend/router/ro_backup.go

@ -1,8 +1,8 @@
package router package router
import ( import (
v1 "github.com/1Panel-dev/1Panel/app/api/v1" v1 "github.com/1Panel-dev/1Panel/backend/app/api/v1"
"github.com/1Panel-dev/1Panel/middleware" "github.com/1Panel-dev/1Panel/backend/middleware"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

4
backend/router/ro_base.go

@ -1,8 +1,8 @@
package router package router
import ( import (
v1 "github.com/1Panel-dev/1Panel/app/api/v1" v1 "github.com/1Panel-dev/1Panel/backend/app/api/v1"
"github.com/1Panel-dev/1Panel/middleware" "github.com/1Panel-dev/1Panel/backend/middleware"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

4
backend/router/ro_command.go

@ -1,8 +1,8 @@
package router package router
import ( import (
v1 "github.com/1Panel-dev/1Panel/app/api/v1" v1 "github.com/1Panel-dev/1Panel/backend/app/api/v1"
"github.com/1Panel-dev/1Panel/middleware" "github.com/1Panel-dev/1Panel/backend/middleware"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

4
backend/router/ro_cronjob.go

@ -1,8 +1,8 @@
package router package router
import ( import (
v1 "github.com/1Panel-dev/1Panel/app/api/v1" v1 "github.com/1Panel-dev/1Panel/backend/app/api/v1"
"github.com/1Panel-dev/1Panel/middleware" "github.com/1Panel-dev/1Panel/backend/middleware"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

4
backend/router/ro_file.go

@ -1,8 +1,8 @@
package router package router
import ( import (
v1 "github.com/1Panel-dev/1Panel/app/api/v1" v1 "github.com/1Panel-dev/1Panel/backend/app/api/v1"
"github.com/1Panel-dev/1Panel/middleware" "github.com/1Panel-dev/1Panel/backend/middleware"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

4
backend/router/ro_group.go

@ -1,8 +1,8 @@
package router package router
import ( import (
v1 "github.com/1Panel-dev/1Panel/app/api/v1" v1 "github.com/1Panel-dev/1Panel/backend/app/api/v1"
"github.com/1Panel-dev/1Panel/middleware" "github.com/1Panel-dev/1Panel/backend/middleware"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

4
backend/router/ro_host.go

@ -1,8 +1,8 @@
package router package router
import ( import (
v1 "github.com/1Panel-dev/1Panel/app/api/v1" v1 "github.com/1Panel-dev/1Panel/backend/app/api/v1"
"github.com/1Panel-dev/1Panel/middleware" "github.com/1Panel-dev/1Panel/backend/middleware"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

4
backend/router/ro_monitor.go

@ -1,8 +1,8 @@
package router package router
import ( import (
v1 "github.com/1Panel-dev/1Panel/app/api/v1" v1 "github.com/1Panel-dev/1Panel/backend/app/api/v1"
"github.com/1Panel-dev/1Panel/middleware" "github.com/1Panel-dev/1Panel/backend/middleware"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

4
backend/router/ro_setting.go

@ -1,8 +1,8 @@
package router package router
import ( import (
v1 "github.com/1Panel-dev/1Panel/app/api/v1" v1 "github.com/1Panel-dev/1Panel/backend/app/api/v1"
"github.com/1Panel-dev/1Panel/middleware" "github.com/1Panel-dev/1Panel/backend/middleware"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

4
backend/router/ro_terminal.go

@ -1,8 +1,8 @@
package router package router
import ( import (
v1 "github.com/1Panel-dev/1Panel/app/api/v1" v1 "github.com/1Panel-dev/1Panel/backend/app/api/v1"
"github.com/1Panel-dev/1Panel/middleware" "github.com/1Panel-dev/1Panel/backend/middleware"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

36
backend/server/server.go

@ -3,20 +3,22 @@ package server
import ( import (
"encoding/gob" "encoding/gob"
"fmt" "fmt"
"github.com/1Panel-dev/1Panel/cmd/server/web"
"net/http"
"time" "time"
"github.com/1Panel-dev/1Panel/cron" "github.com/1Panel-dev/1Panel/backend/cron"
"github.com/1Panel-dev/1Panel/init/cache" "github.com/1Panel-dev/1Panel/backend/init/cache"
"github.com/1Panel-dev/1Panel/init/session" "github.com/1Panel-dev/1Panel/backend/init/session"
"github.com/1Panel-dev/1Panel/init/session/psession" "github.com/1Panel-dev/1Panel/backend/init/session/psession"
"github.com/1Panel-dev/1Panel/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/init/db" "github.com/1Panel-dev/1Panel/backend/init/db"
"github.com/1Panel-dev/1Panel/init/log" "github.com/1Panel-dev/1Panel/backend/init/log"
"github.com/1Panel-dev/1Panel/init/migration" "github.com/1Panel-dev/1Panel/backend/init/migration"
"github.com/1Panel-dev/1Panel/init/router" "github.com/1Panel-dev/1Panel/backend/init/router"
"github.com/1Panel-dev/1Panel/init/validator" "github.com/1Panel-dev/1Panel/backend/init/validator"
"github.com/1Panel-dev/1Panel/init/viper" "github.com/1Panel-dev/1Panel/backend/init/viper"
"github.com/fvbock/endless" "github.com/fvbock/endless"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -34,9 +36,17 @@ func Start() {
gin.SetMode(global.CONF.System.Level) gin.SetMode(global.CONF.System.Level)
cron.Run() cron.Run()
routers := router.Routers() rootRouter := router.Routers()
address := fmt.Sprintf(":%d", global.CONF.System.Port) address := fmt.Sprintf(":%d", global.CONF.System.Port)
s := initServer(address, routers) rootRouter.StaticFS("/login/onepanel", http.FS(web.IndexHtml))
rootRouter.StaticFS("/1panel", http.FS(web.IndexHtml))
rootRouter.GET("/assets/*filepath", func(c *gin.Context) {
staticServer := http.FileServer(http.FS(web.Assets))
staticServer.ServeHTTP(c.Writer, c.Request)
})
s := initServer(address, rootRouter)
global.LOG.Infof("server run success on %d", global.CONF.System.Port) global.LOG.Infof("server run success on %d", global.CONF.System.Port)
if err := s.ListenAndServe(); err != nil { if err := s.ListenAndServe(); err != nil {
global.LOG.Error(err) global.LOG.Error(err)

4
backend/utils/captcha/captcha.go

@ -3,8 +3,8 @@ package captcha
import ( import (
"strings" "strings"
"github.com/1Panel-dev/1Panel/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/mojocn/base64Captcha" "github.com/mojocn/base64Captcha"
) )

2
backend/utils/cloud_storage/client/minio.go

@ -8,7 +8,7 @@ import (
"os" "os"
"strings" "strings"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials" "github.com/minio/minio-go/v7/pkg/credentials"
) )

2
backend/utils/cloud_storage/client/oss.go

@ -1,7 +1,7 @@
package client package client
import ( import (
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
osssdk "github.com/aliyun/aliyun-oss-go-sdk/oss" osssdk "github.com/aliyun/aliyun-oss-go-sdk/oss"
) )

2
backend/utils/cloud_storage/client/s3.go

@ -3,7 +3,7 @@ package client
import ( import (
"os" "os"
"github.com/1Panel-dev/1Panel/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/aws/credentials"

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save