2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-07 18:13:13 +08:00

fix: plugin check

This commit is contained in:
耗子
2023-07-04 02:25:47 +08:00
parent 9ad517863e
commit 4bb07f1a20
4 changed files with 51 additions and 12 deletions

View File

@@ -29,7 +29,9 @@ func NewOpenrestyController() *OpenRestyController {
// Status 获取运行状态
func (r *OpenRestyController) Status(ctx http.Context) {
Check(ctx, "openresty")
if !Check(ctx, "openresty") {
return
}
cmd := exec.Command("bash", "-c", "systemctl status openresty | grep Active | grep -v grep | awk '{print $2}'")
out, err := cmd.CombinedOutput()
@@ -53,7 +55,9 @@ func (r *OpenRestyController) Status(ctx http.Context) {
// Reload 重载配置
func (r *OpenRestyController) Reload(ctx http.Context) {
Check(ctx, "openresty")
if !Check(ctx, "openresty") {
return
}
cmd := exec.Command("bash", "-c", "systemctl reload openresty")
_, err := cmd.CombinedOutput()
@@ -86,7 +90,9 @@ func (r *OpenRestyController) Reload(ctx http.Context) {
// Start 启动OpenResty
func (r *OpenRestyController) Start(ctx http.Context) {
Check(ctx, "openresty")
if !Check(ctx, "openresty") {
return
}
cmd := exec.Command("bash", "-c", "systemctl start openresty")
_, err := cmd.CombinedOutput()
@@ -119,7 +125,9 @@ func (r *OpenRestyController) Start(ctx http.Context) {
// Stop 停止OpenResty
func (r *OpenRestyController) Stop(ctx http.Context) {
Check(ctx, "openresty")
if !Check(ctx, "openresty") {
return
}
cmd := exec.Command("bash", "-c", "systemctl stop openresty")
_, err := cmd.CombinedOutput()
@@ -152,6 +160,10 @@ func (r *OpenRestyController) Stop(ctx http.Context) {
// Restart 重启OpenResty
func (r *OpenRestyController) Restart(ctx http.Context) {
if !Check(ctx, "openresty") {
return
}
cmd := exec.Command("bash", "-c", "systemctl restart openresty")
_, err := cmd.CombinedOutput()
if err != nil {
@@ -183,6 +195,10 @@ func (r *OpenRestyController) Restart(ctx http.Context) {
// GetConfig 获取配置
func (r *OpenRestyController) GetConfig(ctx http.Context) {
if !Check(ctx, "openresty") {
return
}
config, err := os.ReadFile("/www/server/openresty/conf/nginx.conf")
if err != nil {
controllers.Error(ctx, http.StatusInternalServerError, "获取OpenResty配置失败")
@@ -194,6 +210,10 @@ func (r *OpenRestyController) GetConfig(ctx http.Context) {
// SaveConfig 保存配置
func (r *OpenRestyController) SaveConfig(ctx http.Context) {
if !Check(ctx, "openresty") {
return
}
config := ctx.Request().Input("config")
if len(config) == 0 {
controllers.Error(ctx, http.StatusInternalServerError, "配置不能为空")
@@ -245,6 +265,10 @@ func (r *OpenRestyController) SaveConfig(ctx http.Context) {
// ErrorLog 获取错误日志
func (r *OpenRestyController) ErrorLog(ctx http.Context) {
if !Check(ctx, "openresty") {
return
}
cmd := exec.Command("bash", "-c", "tail -n 100 /www/wwwlogs/nginx_error.log")
out, err := cmd.CombinedOutput()
if err != nil {
@@ -258,6 +282,10 @@ func (r *OpenRestyController) ErrorLog(ctx http.Context) {
// ClearErrorLog 清空错误日志
func (r *OpenRestyController) ClearErrorLog(ctx http.Context) {
if !Check(ctx, "openresty") {
return
}
cmd := exec.Command("bash", "-c", "echo '' > /www/wwwlogs/nginx_error.log")
_, err := cmd.CombinedOutput()
if err != nil {
@@ -271,6 +299,10 @@ func (r *OpenRestyController) ClearErrorLog(ctx http.Context) {
// Load 获取负载
func (r *OpenRestyController) Load(ctx http.Context) {
if !Check(ctx, "openresty") {
return
}
client := req.C().SetTimeout(10 * time.Second)
resp, err := client.R().Get("http://127.0.0.1/nginx_status")
if err != nil || !resp.IsSuccessState() {

View File

@@ -6,21 +6,24 @@ import (
"github.com/goravel/framework/contracts/http"
"github.com/goravel/framework/facades"
"panel/app/http/controllers"
"panel/app/services"
)
// Check 检查插件是否可用
func Check(ctx http.Context, slug string) {
func Check(ctx http.Context, slug string) bool {
plugin := services.NewPluginImpl().GetBySlug(slug)
installedPlugin := services.NewPluginImpl().GetInstalledBySlug(slug)
installedPlugins, err := services.NewPluginImpl().AllInstalled()
if err != nil {
facades.Log().Error("[面板][插件] 获取已安装插件失败")
ctx.Request().AbortWithStatusJson(http.StatusInternalServerError, "系统内部错误")
controllers.Error(ctx, http.StatusInternalServerError, "系统内部错误")
return false
}
if installedPlugin.Version != plugin.Version || installedPlugin.Slug != plugin.Slug {
ctx.Request().AbortWithStatusJson(http.StatusForbidden, "插件 "+slug+" 需要更新至 "+plugin.Version+" 版本")
controllers.Error(ctx, http.StatusForbidden, "插件 "+slug+" 需要更新至 "+plugin.Version+" 版本")
return false
}
var lock sync.RWMutex
@@ -37,7 +40,8 @@ func Check(ctx http.Context, slug string) {
_, requireFound := pluginsMap[require]
lock.RUnlock()
if !requireFound {
ctx.Request().AbortWithStatusJson(http.StatusForbidden, "插件 "+slug+" 需要依赖 "+require+" 插件")
controllers.Error(ctx, http.StatusForbidden, "插件 "+slug+" 需要依赖 "+require+" 插件")
return false
}
}
@@ -46,7 +50,10 @@ func Check(ctx http.Context, slug string) {
_, excludeFound := pluginsMap[exclude]
lock.RUnlock()
if excludeFound {
ctx.Request().AbortWithStatusJson(http.StatusForbidden, "插件 "+slug+" 不兼容 "+exclude+" 插件")
controllers.Error(ctx, http.StatusForbidden, "插件 "+slug+" 不兼容 "+exclude+" 插件")
return false
}
}
return true
}

View File

@@ -798,7 +798,7 @@ layui.define('view', function (exports) {
}
// 清理所有定时器
var highestTimeoutId = setTimeout('')
var highestTimeoutId = setTimeout(';')
for (var i = 0; i < highestTimeoutId; i++) {
clearTimeout(i)
}

View File

@@ -87,8 +87,8 @@ Date: 2023-06-22
</a>
</li>
{{# }); }}
{{# if(d.data.length === 0){ }}
这里好像啥也没有...
{{# if(d.data == null){ }}
这里好像啥也没有去插件中心看看吧
{{# } }}
</script>