Skip to content

Commit

Permalink
feat: 支持 IPV6 和优化数据库位置
Browse files Browse the repository at this point in the history
  • Loading branch information
devhaozi committed Dec 13, 2023
1 parent 11ad8e5 commit d731efb
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up environment
run: |
cp panel-example.conf .env
echo "DB_FILE=$(pwd)/database/panel.db" >> .env
echo "DB_FILE=$(pwd)/storage/panel.db" >> .env
go run . artisan key:generate
go run . artisan migrate
- name: Run tests
Expand Down
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ unit_test:
- apt-get update
- apt-get install -y curl jq
- cp panel-example.conf .env
- echo "DB_FILE=$(pwd)/database/panel.db" >> .env
- echo "DB_FILE=$(pwd)/storage/panel.db" >> .env
- go run . artisan key:generate
- go run . artisan migrate
- go test -v -coverprofile=coverage.txt -covermode=atomic ./...
Expand Down
2 changes: 1 addition & 1 deletion config/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func init() {
"connections": map[string]any{
"panel": map[string]any{
"driver": "sqlite",
"database": config.Env("DB_FILE", "/www/panel/database/panel.db"),
"database": config.Env("DB_FILE", "/www/panel/storage/panel.db"),
"prefix": "",
"singular": false, // Table name is singular
},
Expand Down
8 changes: 4 additions & 4 deletions config/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ func init() {
// HTTP URL
"url": "http://localhost",
// HTTP Host
"host": config.Env("APP_HOST", "0.0.0.0"),
"host": "",
// HTTP Port
"port": config.Env("APP_PORT", "8888"),
// HTTP Entrance
"entrance": config.Env("APP_ENTRANCE", "/"),
// HTTPS Configuration
"tls": map[string]any{
// HTTPS Host
"host": config.Env("APP_HOST", "0.0.0.0"),
"host": "",
// HTTPS Port
"port": config.Env("APP_PORT", "8888"),
// SSL Certificate
"ssl": map[string]any{
// ca.pem
"cert": "",
"cert": "/www/panel/storage/cert.pem",
// ca.key
"key": "",
"key": "/www/panel/storage/key.pem",
},
},
})
Expand Down
4 changes: 2 additions & 2 deletions config/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ func init() {
},
"single": map[string]any{
"driver": "single",
"path": "storage/logs/goravel.log",
"path": "storage/logs/panel.log",
"level": "info",
"print": true,
},
"daily": map[string]any{
"driver": "daily",
"path": "storage/logs/goravel.log",
"path": "storage/logs/panel.log",
"level": "info",
"days": 7,
"print": true,
Expand Down
1 change: 1 addition & 0 deletions config/panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ func init() {
config.Add("panel", map[string]any{
"name": "耗子Linux面板",
"version": "v2.1.29",
"ssl": config.Env("APP_SSL", false),
})
}
1 change: 0 additions & 1 deletion database/.gitignore

This file was deleted.

4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ require (
github.com/gofiber/swagger v0.1.14
github.com/gookit/color v1.5.4
github.com/gookit/validate v1.5.1
github.com/goravel/fiber v1.1.11-0.20231121035208-8c744e1a4b62
github.com/goravel/fiber v1.1.11-0.20231213120052-2507f00aa821
github.com/goravel/framework v1.13.1-0.20231121034700-e91df530a997
github.com/iancoleman/strcase v0.3.0
github.com/imroc/req/v3 v3.42.1
github.com/mholt/archiver/v3 v3.5.1
github.com/mojocn/base64Captcha v1.3.5
github.com/shirou/gopsutil v3.21.11+incompatible
github.com/spf13/cast v1.5.1
github.com/spf13/cast v1.6.0
github.com/stretchr/testify v1.8.4
github.com/swaggo/swag v1.16.2
github.com/valyala/fasthttp v1.51.0
Expand Down
10 changes: 5 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ github.com/fasthttp/websocket v1.5.6 h1:4WtWgRJ0Gzj1Ou+xGKy66Ji+a0mUfgAj9ZdPqHiU
github.com/fasthttp/websocket v1.5.6/go.mod h1:yiKhNx2zFOv65YYtCJNhtl5VjdCFew3W+gt8U/9aFkI=
github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239/go.mod h1:Gdwt2ce0yfBxPvZrHkprdPPTTS3N5rwmLE8T22KBXlw=
github.com/fatih/color v1.14.1 h1:qfhVLaG5s+nCROl1zJsZRxFeYrHLqWroPOQ8BWiNb4w=
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
Expand Down Expand Up @@ -388,8 +388,8 @@ github.com/gookit/goutil v0.6.14 h1:96elyOG4BvVoDaiT7vx1vHPrVyEtFfYlPPBODR0/FGQ=
github.com/gookit/goutil v0.6.14/go.mod h1:YyDBddefmjS+mU2PDPgCcjVzTDM5WgExiDv5ZA/b8I8=
github.com/gookit/validate v1.5.1 h1:rPp64QZQJM+fysGFAhKpvekQAav4Ok6sjfTs9ZtxcpA=
github.com/gookit/validate v1.5.1/go.mod h1:SskOHUQokzMNt6T3r7N+N/4me/6fxDx+tmoXf/3ZQog=
github.com/goravel/fiber v1.1.11-0.20231121035208-8c744e1a4b62 h1:VtU6JHqlcA2nuI96H5wvv5vConFe3uC8+Y7BkZHTjGI=
github.com/goravel/fiber v1.1.11-0.20231121035208-8c744e1a4b62/go.mod h1:A6MujNl1WEkKv3m2ur0+ntQuy+SeG1W10gSNrv//x1k=
github.com/goravel/fiber v1.1.11-0.20231213120052-2507f00aa821 h1:uadmOrQUbBrt6btKgUyTn8ffKu/zXIiRkWBrY9mwUXM=
github.com/goravel/fiber v1.1.11-0.20231213120052-2507f00aa821/go.mod h1:FsIMZuNx7KBG04BNaYEZY97eSK7J/HFjhNJ4mkFCwTE=
github.com/goravel/file-rotatelogs v0.0.0-20211215053220-2ab31dd9575c h1:obhFK91JAhcf7s6h5sggZishm1VyGW/gBCreo+7/SwQ=
github.com/goravel/file-rotatelogs v0.0.0-20211215053220-2ab31dd9575c/go.mod h1:YSWsLXlG16u5CWFaXNZHhEQD10+NwF3xfgDV816OwLE=
github.com/goravel/file-rotatelogs/v2 v2.4.1 h1:ogkeIFcTHSBRUBpZYiyJbpul8hkVXxHPuDbOaP78O1M=
Expand Down Expand Up @@ -632,8 +632,8 @@ github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9yS
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
github.com/spf13/afero v1.10.0 h1:EaGW2JJh15aKOejeuJ+wpFSHnbd7GE6Wvp3TsNhb6LY=
github.com/spf13/afero v1.10.0/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ=
github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA=
github.com/spf13/cast v1.5.1/go.mod h1:b9PdjNptOpzXr7Rq1q9gJML/2cdGQAo69NKzQ10KN48=
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
Expand Down
18 changes: 13 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,19 @@ func main() {
bootstrap.Boot()

// 启动 HTTP 服务
go func() {
if err := facades.Route().Run(); err != nil {
facades.Log().Infof("Route run error: %v", err)
}
}()
if facades.Config().GetBool("panel.ssl") {
go func() {
if err := facades.Route().RunTLS(); err != nil {
facades.Log().Infof("Route run error: %v", err)
}
}()
} else {
go func() {
if err := facades.Route().Run(); err != nil {
facades.Log().Infof("Route run error: %v", err)
}
}()
}

// 启动计划任务
go facades.Schedule().Run()
Expand Down
2 changes: 1 addition & 1 deletion panel-example.conf
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
APP_ENV=local
APP_KEY=
APP_DEBUG=false
APP_HOST=0.0.0.0
APP_PORT=8888
APP_ENTRANCE=/
APP_SSL=false

JWT_SECRET=
37 changes: 14 additions & 23 deletions pkg/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,21 +402,21 @@ func UpdatePanel(panelInfo PanelInfo) error {
color.Greenln("下载链接: " + panelInfo.DownloadUrl)

color.Greenln("前置检查...")
if Exists("/tmp/panel.db.bak") || Exists("/tmp/panel.conf.bak") {
if Exists("/tmp/panel-storage.zip") || Exists("/tmp/panel.conf.bak") {
return errors.New("检测到/tmp存在临时文件,可能是上次更新失败导致的,请谨慎排除后重试")
}

color.Greenln("备份面板配置...")
if _, err := Exec("cp -f /www/panel/database/panel.db /tmp/panel.db.bak"); err != nil {
color.Redln("备份面板数据库失败")
color.Greenln("备份面板数据...")
if _, err := Exec("cd /www/panel/storage && zip -r /tmp/panel-storage.zip *"); err != nil {
color.Redln("备份面板数据失败")
return err
}
if _, err := Exec("cp -f /www/panel/panel.conf /tmp/panel.conf.bak"); err != nil {
color.Redln("备份面板配置失败")
return err
}
if !Exists("/tmp/panel.db.bak") || !Exists("/tmp/panel.conf.bak") {
return errors.New("备份面板配置失败")
if !Exists("/tmp/panel-storage.zip") || !Exists("/tmp/panel.conf.bak") {
return errors.New("备份面板数据失败")
}
color.Greenln("备份完成")

Expand Down Expand Up @@ -462,25 +462,22 @@ func UpdatePanel(panelInfo PanelInfo) error {
}
color.Greenln("更新完成")

color.Greenln("恢复面板配置...")
if _, err = Exec("cp -f /tmp/panel.db.bak /www/panel/database/panel.db"); err != nil {
color.Redln("恢复面板数据库失败")
color.Greenln("恢复面板数据...")
if _, err = Exec("cp -f /tmp/panel-storage.zip /www/panel/storage/panel-storage.zip && cd /www/panel/storage && unzip -o panel-storage.zip && rm -rf panel-storage.zip"); err != nil {
color.Redln("恢复面板数据失败")
return err
}
if _, err = Exec("cp -f /tmp/panel.conf.bak /www/panel/panel.conf"); err != nil {
color.Redln("恢复面板配置失败")
color.Redln("恢复面板数据失败")
return err
}
if !Exists("/www/panel/database/panel.db") || !Exists("/www/panel/panel.conf") {
if !Exists("/www/panel/storage/panel.db") || !Exists("/www/panel/panel.conf") {
return errors.New("恢复面板配置失败")
}
color.Greenln("恢复完成")

color.Greenln("设置面板文件权限...")
if _, err = Exec("chmod -R 700 /www/panel"); err != nil {
color.Redln("设置面板文件权限失败")
return err
}
_, _ = Exec("chmod -R 700 /www/panel")
color.Greenln("设置完成")

if _, err = Exec("/www/panel/panel --env=panel.conf artisan migrate"); err != nil {
Expand All @@ -496,14 +493,8 @@ func UpdatePanel(panelInfo PanelInfo) error {
return err
}

if _, err = Exec("rm -rf /tmp/panel.db.bak"); err != nil {
color.Redln("清理临时文件失败")
return err
}
if _, err = Exec("rm -rf /tmp/panel.conf.bak"); err != nil {
color.Redln("清理临时文件失败")
return err
}
_, _ = Exec("rm -rf /tmp/panel-storage.zip")
_, _ = Exec("rm -rf /tmp/panel.conf.bak")

return nil
}
Expand Down
8 changes: 8 additions & 0 deletions scripts/update_panel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ if version_lt "$oldVersion" "2.1.8"; then
panel deleteSetting entrance
fi

if version_lt "$oldVersion" "2.1.30"; then
echo "更新面板到 v2.1.30 ..."
echo "Update panel to v2.1.30 ..."
sed -i '/APP_HOST/d' $panelPath/panel.conf
echo "APP_SSL=false" >> $panelPath/panel.conf
mv $panelPath/database/panel.db $panelPath/storage/panel.db
fi

echo $HR
echo "更新结束"
echo "Update finished"
1 change: 1 addition & 0 deletions storage/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*

0 comments on commit d731efb

Please sign in to comment.