mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 13:47:15 +08:00
feat: 面板入口调整
This commit is contained in:
@@ -56,7 +56,7 @@ func (receiver *Panel) Handle(ctx console.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
settings := []models.Setting{{Key: models.SettingKeyName, Value: "耗子Linux面板"}, {Key: models.SettingKeyMonitor, Value: "1"}, {Key: models.SettingKeyMonitorDays, Value: "30"}, {Key: models.SettingKeyBackupPath, Value: "/www/backup"}, {Key: models.SettingKeyWebsitePath, Value: "/www/wwwroot"}, {Key: models.SettingKeyEntrance, Value: "/"}, {Key: models.SettingKeyVersion, Value: facades.Config().GetString("panel.version")}}
|
||||
settings := []models.Setting{{Key: models.SettingKeyName, Value: "耗子Linux面板"}, {Key: models.SettingKeyMonitor, Value: "1"}, {Key: models.SettingKeyMonitorDays, Value: "30"}, {Key: models.SettingKeyBackupPath, Value: "/www/backup"}, {Key: models.SettingKeyWebsitePath, Value: "/www/wwwroot"}, {Key: models.SettingKeyVersion, Value: facades.Config().GetString("panel.version")}}
|
||||
err = facades.Orm().Query().Create(&settings)
|
||||
if err != nil {
|
||||
color.Redln("初始化失败")
|
||||
@@ -130,21 +130,18 @@ func (receiver *Panel) Handle(ctx console.Context) error {
|
||||
color.Greenln("用户名: " + user.Username)
|
||||
color.Greenln("密码: " + password)
|
||||
color.Greenln("面板端口: " + port)
|
||||
color.Greenln("面板入口: " + services.NewSettingImpl().Get(models.SettingKeyEntrance, "/"))
|
||||
color.Greenln("面板入口: " + facades.Config().GetString("http.entrance"))
|
||||
|
||||
case "getPort":
|
||||
port := tools.Exec("cat /www/panel/panel.conf | grep APP_PORT | awk -F '=' '{print $2}'")
|
||||
color.Greenln("面板端口: " + port)
|
||||
|
||||
case "getEntrance":
|
||||
color.Greenln("面板入口: " + services.NewSettingImpl().Get(models.SettingKeyEntrance, "/"))
|
||||
color.Greenln("面板入口: " + facades.Config().GetString("http.entrance"))
|
||||
|
||||
case "deleteEntrance":
|
||||
err := services.NewSettingImpl().Set(models.SettingKeyEntrance, "/")
|
||||
if err != nil {
|
||||
color.Redln("删除面板入口失败")
|
||||
return nil
|
||||
}
|
||||
oldEntrance := tools.Exec(`cat /www/panel/panel.conf | grep APP_ENTRANCE | awk -F '=' '{print $2}' | tr -d '\n'`)
|
||||
tools.Exec("sed -i 's!APP_ENTRANCE=" + oldEntrance + "!APP_ENTRANCE=/!g' /www/panel/panel.conf")
|
||||
|
||||
color.Greenln("删除面板入口成功")
|
||||
|
||||
|
||||
@@ -5,7 +5,8 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/goravel/framework/contracts/http"
|
||||
"panel/app/models"
|
||||
"github.com/goravel/framework/facades"
|
||||
|
||||
"panel/app/services"
|
||||
"panel/pkg/tools"
|
||||
)
|
||||
@@ -21,7 +22,7 @@ func NewAssetController() *AssetController {
|
||||
}
|
||||
|
||||
func (r *AssetController) Index(ctx http.Context) http.Response {
|
||||
entrance := r.setting.Get(models.SettingKeyEntrance)
|
||||
entrance := facades.Config().GetString("http.entrance")
|
||||
path := strings.TrimPrefix(ctx.Request().Path(), entrance)
|
||||
|
||||
// 自动纠正 URL 格式
|
||||
|
||||
@@ -5,10 +5,10 @@ import (
|
||||
|
||||
"github.com/goravel/framework/contracts/http"
|
||||
"github.com/goravel/framework/facades"
|
||||
"panel/pkg/tools"
|
||||
|
||||
"panel/app/models"
|
||||
"panel/app/services"
|
||||
"panel/pkg/tools"
|
||||
)
|
||||
|
||||
type SettingController struct {
|
||||
@@ -43,7 +43,7 @@ func (r *SettingController) List(ctx http.Context) http.Response {
|
||||
|
||||
var result data
|
||||
result.Name = r.setting.Get(models.SettingKeyName)
|
||||
result.Entrance = r.setting.Get(models.SettingKeyEntrance)
|
||||
result.Entrance = facades.Config().GetString("http.entrance")
|
||||
result.WebsitePath = r.setting.Get(models.SettingKeyWebsitePath)
|
||||
result.BackupPath = r.setting.Get(models.SettingKeyBackupPath)
|
||||
|
||||
@@ -85,6 +85,11 @@ func (r *SettingController) Save(ctx http.Context) http.Response {
|
||||
if oldPort != port {
|
||||
tools.Exec("sed -i 's/APP_PORT=" + oldPort + "/APP_PORT=" + port + "/g' /www/panel/panel.conf")
|
||||
}
|
||||
oldEntrance := tools.Exec(`cat /www/panel/panel.conf | grep APP_ENTRANCE | awk -F '=' '{print $2}' | tr -d '\n'`)
|
||||
if oldEntrance != entrance {
|
||||
tools.Exec("sed -i 's/APP_ENTRANCE=" + oldEntrance + "/APP_ENTRANCE=" + entrance + "/g' /www/panel/panel.conf")
|
||||
}
|
||||
|
||||
if !tools.Exists(backupPath) {
|
||||
tools.Mkdir(backupPath, 0644)
|
||||
}
|
||||
@@ -102,11 +107,6 @@ func (r *SettingController) Save(ctx http.Context) http.Response {
|
||||
facades.Log().Error("[面板][SettingController] 保存设置失败 ", err)
|
||||
return ErrorSystem(ctx)
|
||||
}
|
||||
err = r.setting.Set(models.SettingKeyEntrance, entrance)
|
||||
if err != nil {
|
||||
facades.Log().Error("[面板][SettingController] 保存设置失败 ", err)
|
||||
return ErrorSystem(ctx)
|
||||
}
|
||||
|
||||
var user models.User
|
||||
err = facades.Auth().User(ctx, &user)
|
||||
|
||||
@@ -9,7 +9,6 @@ const (
|
||||
SettingKeyMonitorDays = "monitor_days"
|
||||
SettingKeyBackupPath = "backup_path"
|
||||
SettingKeyWebsitePath = "website_path"
|
||||
SettingKeyEntrance = "entrance"
|
||||
SettingKeyMysqlRootPassword = "mysql_root_password"
|
||||
SettingKeySshHost = "ssh_host"
|
||||
SettingKeySshPort = "ssh_port"
|
||||
|
||||
@@ -85,12 +85,12 @@ func init() {
|
||||
&testing.ServiceProvider{},
|
||||
&providers.AppServiceProvider{},
|
||||
&providers.AuthServiceProvider{},
|
||||
&providers.DatabaseServiceProvider{},
|
||||
&providers.RouteServiceProvider{},
|
||||
&providers.ConsoleServiceProvider{},
|
||||
&providers.QueueServiceProvider{},
|
||||
&providers.EventServiceProvider{},
|
||||
&providers.ValidationServiceProvider{},
|
||||
&providers.DatabaseServiceProvider{},
|
||||
&fiber.ServiceProvider{},
|
||||
},
|
||||
})
|
||||
|
||||
@@ -27,6 +27,8 @@ func init() {
|
||||
"host": config.Env("APP_HOST", "0.0.0.0"),
|
||||
// HTTP Port
|
||||
"port": config.Env("APP_PORT", "8888"),
|
||||
// HTTP Entrance
|
||||
"entrance": config.Env("APP_ENTRANCE", "/"),
|
||||
// HTTPS Configuration
|
||||
"tls": map[string]any{
|
||||
// HTTPS Host
|
||||
|
||||
@@ -3,5 +3,6 @@ APP_KEY=
|
||||
APP_DEBUG=false
|
||||
APP_HOST=0.0.0.0
|
||||
APP_PORT=8888
|
||||
APP_ENTRANCE=/
|
||||
|
||||
JWT_SECRET=
|
||||
|
||||
@@ -6,8 +6,6 @@ import (
|
||||
|
||||
"panel/app/http/controllers"
|
||||
"panel/app/http/middleware"
|
||||
"panel/app/models"
|
||||
"panel/app/services"
|
||||
)
|
||||
|
||||
func Api() {
|
||||
@@ -134,11 +132,14 @@ func Api() {
|
||||
facades.Route().Get("swagger/{any}", swaggerController.Index)
|
||||
|
||||
// 静态文件
|
||||
entrance := services.NewSettingImpl().Get(models.SettingKeyEntrance) + "/"
|
||||
entrance := facades.Config().GetString("http.entrance")
|
||||
if entrance == "/" {
|
||||
entrance = ""
|
||||
}
|
||||
assetController := controllers.NewAssetController()
|
||||
facades.Route().Get("favicon.png", assetController.Favicon)
|
||||
facades.Route().Get("robots.txt", assetController.Robots)
|
||||
facades.Route().Get(entrance+"assets/{any}", assetController.Index)
|
||||
facades.Route().Get(entrance+"loading/{any}", assetController.Index)
|
||||
facades.Route().Get(entrance+"{any}", assetController.Index)
|
||||
facades.Route().Get(entrance+"/assets/{any}", assetController.Index)
|
||||
facades.Route().Get(entrance+"/loading/{any}", assetController.Index)
|
||||
facades.Route().Get(entrance+"/{any}", assetController.Index)
|
||||
}
|
||||
|
||||
@@ -19,4 +19,35 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
'
|
||||
|
||||
HR="+----------------------------------------------------"
|
||||
OldVersion=$(panel getSetting version)
|
||||
oldVersion=$(panel getSetting version)
|
||||
oldVersion=${oldVersion#v}
|
||||
panelPath="/www/panel"
|
||||
|
||||
# 大于
|
||||
function version_gt() { test "$(echo -e "$1\n$2" | tr " " "\n" | sort -V | head -n 1)" != "$1"; }
|
||||
# 小于
|
||||
function version_lt() { test "$(echo -e "$1\n$2" | tr " " "\n" | sort -rV | head -n 1)" != "$1"; }
|
||||
# 大于等于
|
||||
function version_ge() { test "$(echo -e "$1\n$2" | tr " " "\n" | sort -rV | head -n 1)" == "$1"; }
|
||||
# 小于等于
|
||||
function version_le() { test "$(echo -e "$1\n$2" | tr " " "\n" | sort -V | head -n 1)" == "$1"; }
|
||||
|
||||
if [ -z "$oldVersion" ]; then
|
||||
echo "错误:无法获取面板版本"
|
||||
echo "Error: can't get panel version"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo $HR
|
||||
|
||||
if version_lt "$oldVersion" "2.1.8"; then
|
||||
echo "更新面板到 v2.1.8 ..."
|
||||
echo "Update panel to v2.1.8 ..."
|
||||
oldEntrance=$(panel getSetting entrance)
|
||||
echo "APP_ENTRANCE=$oldEntrance" >> $panelPath/panel.conf
|
||||
panel deleteSetting entrance
|
||||
fi
|
||||
|
||||
echo $HR
|
||||
echo "更新结束"
|
||||
echo "Update finished"
|
||||
|
||||
Reference in New Issue
Block a user