From 5ce65653adc427d5121aa97df9b27d0b72c3abd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Thu, 20 Jul 2023 01:06:49 +0800 Subject: [PATCH] refactor: packages to pkg --- .github/workflows/issue-auto-reply.yml | 4 +- .github/workflows/issue-close-question.yml | 2 +- app/console/commands/monitoring.go | 4 +- app/console/commands/panel.go | 14 +-- app/http/controllers/cron_controller.go | 20 +-- app/http/controllers/info_controller.go | 6 +- .../plugins/mysql80/mysql80_controller.go | 118 +++++++++--------- .../plugins/openresty/openresty_controller.go | 34 ++--- .../plugins/php74/php74_controller.go | 34 ++--- app/http/controllers/safe_controller.go | 92 +++++++------- app/http/controllers/setting_controller.go | 6 +- app/http/controllers/task_controller.go | 4 +- app/http/controllers/website_controller.go | 66 +++++----- app/models/monitor.go | 10 +- app/rules/captcha.go | 2 +- app/services/backup.go | 10 +- app/services/cron.go | 18 +-- app/services/website.go | 54 ++++---- config/app.go | 2 +- config/jwt.go | 2 +- {packages => pkg}/captcha/captcha.go | 0 {packages => pkg}/captcha/captcha_test.go | 0 {packages => pkg}/captcha/store_cache.go | 0 {packages => pkg}/str/str.go | 0 {packages => pkg}/str/str_test.go | 0 {packages/helper => pkg/tools}/os.go | 2 +- {packages/helper => pkg/tools}/os_test.go | 2 +- {packages/helper => pkg/tools}/string.go | 2 +- {packages/helper => pkg/tools}/string_test.go | 2 +- {packages/helper => pkg/tools}/system.go | 2 +- {packages/helper => pkg/tools}/system_test.go | 2 +- .../helper/helpers.go => pkg/tools/tools.go | 4 +- .../tools/tools_test.go | 2 +- 33 files changed, 260 insertions(+), 260 deletions(-) rename {packages => pkg}/captcha/captcha.go (100%) rename {packages => pkg}/captcha/captcha_test.go (100%) rename {packages => pkg}/captcha/store_cache.go (100%) rename {packages => pkg}/str/str.go (100%) rename {packages => pkg}/str/str_test.go (100%) rename {packages/helper => pkg/tools}/os.go (96%) rename {packages/helper => pkg/tools}/os_test.go (96%) rename {packages/helper => pkg/tools}/string.go (99%) rename {packages/helper => pkg/tools}/string_test.go (99%) rename {packages/helper => pkg/tools}/system.go (99%) rename {packages/helper => pkg/tools}/system_test.go (99%) rename packages/helper/helpers.go => pkg/tools/tools.go (98%) rename packages/helper/helpers_test.go => pkg/tools/tools_test.go (94%) diff --git a/.github/workflows/issue-auto-reply.yml b/.github/workflows/issue-auto-reply.yml index 0de5a00160..490f5640d7 100644 --- a/.github/workflows/issue-auto-reply.yml +++ b/.github/workflows/issue-auto-reply.yml @@ -16,7 +16,7 @@ jobs: steps: - name: ✏️ Feature if: github.event.label.name == '✏️ Feature' - uses: actions-cool/issues-helper@v3 + uses: actions-cool/issues-tools@v3 with: actions: 'create-comment' token: ${{ secrets.GITHUB_TOKEN }} @@ -30,7 +30,7 @@ jobs: "Talk is cheap, Show me the Code." - Linus Torvalds - name: ☢️ Bug if: github.event.label.name == '☢️ Bug' - uses: actions-cool/issues-helper@v3 + uses: actions-cool/issues-tools@v3 with: actions: 'create-comment' token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/issue-close-question.yml b/.github/workflows/issue-close-question.yml index 89554f0118..6c8c2d3ad4 100644 --- a/.github/workflows/issue-close-question.yml +++ b/.github/workflows/issue-close-question.yml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-latest steps: - name: needs more info - uses: actions-cool/issues-helper@v3 + uses: actions-cool/issues-tools@v3 with: actions: 'close-issues' labels: 'question' diff --git a/app/console/commands/monitoring.go b/app/console/commands/monitoring.go index 50faa4e309..415743dd5d 100644 --- a/app/console/commands/monitoring.go +++ b/app/console/commands/monitoring.go @@ -10,7 +10,7 @@ import ( "github.com/goravel/framework/support/carbon" "panel/app/models" - "panel/packages/helper" + "panel/pkg/tools" ) type Monitoring struct { @@ -43,7 +43,7 @@ func (receiver *Monitoring) Handle(ctx console.Context) error { return nil } - info := helper.GetMonitoringInfo() + info := tools.GetMonitoringInfo() err := facades.Orm().Query().Create(&models.Monitor{ Info: info, diff --git a/app/console/commands/panel.go b/app/console/commands/panel.go index 22a5304f73..615f0862a0 100644 --- a/app/console/commands/panel.go +++ b/app/console/commands/panel.go @@ -12,7 +12,7 @@ import ( "panel/app/models" "panel/app/services" - "panel/packages/helper" + "panel/pkg/tools" ) type Panel struct { @@ -57,7 +57,7 @@ func (receiver *Panel) Handle(ctx console.Context) error { return nil } - hash, err := facades.Hash().Make(helper.RandomString(32)) + hash, err := facades.Hash().Make(tools.RandomString(32)) if err != nil { color.Redln("初始化失败") return nil @@ -73,7 +73,7 @@ func (receiver *Panel) Handle(ctx console.Context) error { color.Greenln("初始化成功") case "update": - err := helper.UpdatePanel() + err := tools.UpdatePanel() if err != nil { color.Redln("更新失败: " + err.Error()) return nil @@ -89,14 +89,14 @@ func (receiver *Panel) Handle(ctx console.Context) error { return nil } - password := helper.RandomString(16) + password := tools.RandomString(16) hash, err := facades.Hash().Make(password) if err != nil { color.Redln("生成密码失败") return nil } - user.Username = helper.RandomString(8) + user.Username = tools.RandomString(8) user.Password = hash err = facades.Orm().Query().Save(&user) @@ -105,7 +105,7 @@ func (receiver *Panel) Handle(ctx console.Context) error { return nil } - port := helper.ExecShell("cat /www/panel/panel.conf | grep APP_PORT | awk -F '=' '{print $2}'") + port := tools.ExecShell("cat /www/panel/panel.conf | grep APP_PORT | awk -F '=' '{print $2}'") color.Greenln("用户名: " + user.Username) color.Greenln("密码: " + password) @@ -113,7 +113,7 @@ func (receiver *Panel) Handle(ctx console.Context) error { color.Greenln("面板入口: " + services.NewSettingImpl().Get(models.SettingKeyPanelEntrance, "/")) case "getPort": - port := helper.ExecShell("cat /www/panel/panel.conf | grep APP_PORT | awk -F '=' '{print $2}'") + port := tools.ExecShell("cat /www/panel/panel.conf | grep APP_PORT | awk -F '=' '{print $2}'") color.Greenln("面板端口: " + port) case "getEntrance": diff --git a/app/http/controllers/cron_controller.go b/app/http/controllers/cron_controller.go index 4c0242ab5e..360a604d2a 100644 --- a/app/http/controllers/cron_controller.go +++ b/app/http/controllers/cron_controller.go @@ -9,7 +9,7 @@ import ( "panel/app/models" "panel/app/services" - "panel/packages/helper" + "panel/pkg/tools" ) type CronController struct { @@ -59,23 +59,23 @@ func (r *CronController) Add(ctx http.Context) { // 写入shell shellDir := "/www/server/cron/" shellLogDir := "/www/server/cron/logs/" - if !helper.Exists(shellDir) { + if !tools.Exists(shellDir) { facades.Log().Error("[面板][CronController] 计划任务目录不存在") Error(ctx, http.StatusInternalServerError, "计划任务目录不存在") return } - if !helper.Exists(shellLogDir) { + if !tools.Exists(shellLogDir) { facades.Log().Error("[面板][CronController] 计划任务日志目录不存在") Error(ctx, http.StatusInternalServerError, "计划任务日志目录不存在") return } - shellFile := strconv.Itoa(int(carbon.Now().Timestamp())) + helper.RandomString(16) - if !helper.WriteFile(shellDir+shellFile+".sh", ctx.Request().Input("script"), 0644) { + shellFile := strconv.Itoa(int(carbon.Now().Timestamp())) + tools.RandomString(16) + if !tools.WriteFile(shellDir+shellFile+".sh", ctx.Request().Input("script"), 0644) { facades.Log().Error("[面板][CronController] 创建计划任务脚本失败 ", err) Error(ctx, http.StatusInternalServerError, "系统内部错误") return } - helper.ExecShell("dos2unix " + shellDir + shellFile + ".sh") + tools.ExecShell("dos2unix " + shellDir + shellFile + ".sh") var cron models.Cron cron.Name = ctx.Request().Input("name") @@ -122,12 +122,12 @@ func (r *CronController) Update(ctx http.Context) { return } - if !helper.WriteFile(cron.Shell, ctx.Request().Input("script"), 0644) { + if !tools.WriteFile(cron.Shell, ctx.Request().Input("script"), 0644) { facades.Log().Error("[面板][CronController] 更新计划任务脚本失败 ", err) Error(ctx, http.StatusInternalServerError, "系统内部错误") return } - helper.ExecShell("dos2unix " + cron.Shell) + tools.ExecShell("dos2unix " + cron.Shell) r.cron.DeleteFromSystem(cron) if cron.Status { @@ -226,12 +226,12 @@ func (r *CronController) Log(ctx http.Context) { return } - if !helper.Exists(cron.Log) { + if !tools.Exists(cron.Log) { Error(ctx, http.StatusBadRequest, "日志文件不存在") return } Success(ctx, http.Json{ - "log": helper.ReadFile(cron.Log), + "log": tools.ReadFile(cron.Log), }) } diff --git a/app/http/controllers/info_controller.go b/app/http/controllers/info_controller.go index 27fc0eae1f..a1f5d3552e 100644 --- a/app/http/controllers/info_controller.go +++ b/app/http/controllers/info_controller.go @@ -8,7 +8,7 @@ import ( "panel/app/models" "panel/app/services" - "panel/packages/helper" + "panel/pkg/tools" ) type MenuItem struct { @@ -81,11 +81,11 @@ func (r *InfoController) HomePlugins(ctx http.Context) { } func (r *InfoController) NowMonitor(ctx http.Context) { - Success(ctx, helper.GetMonitoringInfo()) + Success(ctx, tools.GetMonitoringInfo()) } func (r *InfoController) SystemInfo(ctx http.Context) { - monitorInfo := helper.GetMonitoringInfo() + monitorInfo := tools.GetMonitoringInfo() Success(ctx, http.Json{ "os_name": monitorInfo.Host.Platform + " " + monitorInfo.Host.PlatformVersion, diff --git a/app/http/controllers/plugins/mysql80/mysql80_controller.go b/app/http/controllers/plugins/mysql80/mysql80_controller.go index b5f2d5d05b..34f8286848 100644 --- a/app/http/controllers/plugins/mysql80/mysql80_controller.go +++ b/app/http/controllers/plugins/mysql80/mysql80_controller.go @@ -17,7 +17,7 @@ import ( "panel/app/http/controllers" "panel/app/http/controllers/plugins" "panel/app/services" - "panel/packages/helper" + "panel/pkg/tools" ) type Mysql80Controller struct { @@ -36,7 +36,7 @@ func (r *Mysql80Controller) Status(ctx http.Context) { return } - out := helper.ExecShell("systemctl status mysql | grep Active | grep -v grep | awk '{print $2}'") + out := tools.ExecShell("systemctl status mysql | grep Active | grep -v grep | awk '{print $2}'") status := strings.TrimSpace(out) if len(status) == 0 { controllers.Error(ctx, http.StatusInternalServerError, "获取MySQL状态失败") @@ -56,8 +56,8 @@ func (r *Mysql80Controller) Reload(ctx http.Context) { return } - helper.ExecShell("systemctl reload mysql") - out := helper.ExecShell("systemctl status mysql | grep Active | grep -v grep | awk '{print $2}'") + tools.ExecShell("systemctl reload mysql") + out := tools.ExecShell("systemctl status mysql | grep Active | grep -v grep | awk '{print $2}'") status := strings.TrimSpace(out) if len(status) == 0 { controllers.Error(ctx, http.StatusInternalServerError, "获取MySQL状态失败") @@ -77,8 +77,8 @@ func (r *Mysql80Controller) Restart(ctx http.Context) { return } - helper.ExecShell("systemctl restart mysql") - out := helper.ExecShell("systemctl status mysql | grep Active | grep -v grep | awk '{print $2}'") + tools.ExecShell("systemctl restart mysql") + out := tools.ExecShell("systemctl status mysql | grep Active | grep -v grep | awk '{print $2}'") status := strings.TrimSpace(out) if len(status) == 0 { controllers.Error(ctx, http.StatusInternalServerError, "获取MySQL状态失败") @@ -98,8 +98,8 @@ func (r *Mysql80Controller) Start(ctx http.Context) { return } - helper.ExecShell("systemctl start mysql") - out := helper.ExecShell("systemctl status mysql | grep Active | grep -v grep | awk '{print $2}'") + tools.ExecShell("systemctl start mysql") + out := tools.ExecShell("systemctl status mysql | grep Active | grep -v grep | awk '{print $2}'") status := strings.TrimSpace(out) if len(status) == 0 { controllers.Error(ctx, http.StatusInternalServerError, "获取MySQL状态失败") @@ -119,8 +119,8 @@ func (r *Mysql80Controller) Stop(ctx http.Context) { return } - helper.ExecShell("systemctl stop mysql") - out := helper.ExecShell("systemctl status mysql | grep Active | grep -v grep | awk '{print $2}'") + tools.ExecShell("systemctl stop mysql") + out := tools.ExecShell("systemctl status mysql | grep Active | grep -v grep | awk '{print $2}'") status := strings.TrimSpace(out) if len(status) == 0 { controllers.Error(ctx, http.StatusInternalServerError, "获取MySQL状态失败") @@ -141,7 +141,7 @@ func (r *Mysql80Controller) GetConfig(ctx http.Context) { } // 获取配置 - config := helper.ReadFile("mysql80") + config := tools.ReadFile("mysql80") if len(config) == 0 { controllers.Error(ctx, http.StatusInternalServerError, "获取MySQL配置失败") return @@ -162,7 +162,7 @@ func (r *Mysql80Controller) SaveConfig(ctx http.Context) { return } - if !helper.WriteFile("mysql80", config, 0644) { + if !tools.WriteFile("mysql80", config, 0644) { controllers.Error(ctx, http.StatusInternalServerError, "写入MySQL配置失败") return } @@ -182,13 +182,13 @@ func (r *Mysql80Controller) Load(ctx http.Context) { return } - status := helper.ExecShell("systemctl status mysqld | grep Active | grep -v grep | awk '{print $2}'") + status := tools.ExecShell("systemctl status mysqld | grep Active | grep -v grep | awk '{print $2}'") if strings.TrimSpace(status) != "active" { controllers.Error(ctx, http.StatusInternalServerError, "MySQL 已停止运行") return } - raw := helper.ExecShell("mysqladmin -uroot -p" + rootPassword + " extended-status 2>&1") + raw := tools.ExecShell("mysqladmin -uroot -p" + rootPassword + " extended-status 2>&1") if strings.Contains(raw, "Access denied for user") { controllers.Error(ctx, http.StatusBadRequest, "MySQL root密码错误") return @@ -231,7 +231,7 @@ func (r *Mysql80Controller) Load(ctx http.Context) { data[i] = map[string]string{"name": expression.name, "value": matches[1]} if expression.name == "发送" || expression.name == "接收" { - data[i]["value"] = helper.FormatBytes(cast.ToFloat64(matches[1])) + data[i]["value"] = tools.FormatBytes(cast.ToFloat64(matches[1])) } } } @@ -254,7 +254,7 @@ func (r *Mysql80Controller) ErrorLog(ctx http.Context) { return } - log := helper.ExecShell("tail -n 100 /www/server/mysql/mysql-error.log") + log := tools.ExecShell("tail -n 100 /www/server/mysql/mysql-error.log") controllers.Success(ctx, log) } @@ -264,7 +264,7 @@ func (r *Mysql80Controller) ClearErrorLog(ctx http.Context) { return } - helper.ExecShell("echo '' > /www/server/mysql/mysql-error.log") + tools.ExecShell("echo '' > /www/server/mysql/mysql-error.log") controllers.Success(ctx, "清空错误日志成功") } @@ -274,7 +274,7 @@ func (r *Mysql80Controller) SlowLog(ctx http.Context) { return } - log := helper.ExecShell("tail -n 100 /www/server/mysql/mysql-slow.log") + log := tools.ExecShell("tail -n 100 /www/server/mysql/mysql-slow.log") controllers.Success(ctx, log) } @@ -284,7 +284,7 @@ func (r *Mysql80Controller) ClearSlowLog(ctx http.Context) { return } - helper.ExecShell("echo '' > /www/server/mysql/mysql-slow.log") + tools.ExecShell("echo '' > /www/server/mysql/mysql-slow.log") controllers.Success(ctx, "清空慢查询日志成功") } @@ -309,7 +309,7 @@ func (r *Mysql80Controller) SetRootPassword(ctx http.Context) { return } - out := helper.ExecShell("systemctl status mysql | grep Active | grep -v grep | awk '{print $2}'") + out := tools.ExecShell("systemctl status mysql | grep Active | grep -v grep | awk '{print $2}'") status := strings.TrimSpace(out) if len(status) == 0 { controllers.Error(ctx, http.StatusInternalServerError, "获取MySQL状态失败") @@ -328,12 +328,12 @@ func (r *Mysql80Controller) SetRootPassword(ctx http.Context) { oldRootPassword := r.setting.Get(models.SettingKeyMysqlRootPassword) if oldRootPassword != rootPassword { - helper.ExecShell("mysql -uroot -p" + oldRootPassword + " -e \"ALTER USER 'root'@'localhost' IDENTIFIED BY '" + rootPassword + "';\"") - helper.ExecShell("mysql -uroot -p" + oldRootPassword + " -e \"FLUSH PRIVILEGES;\"") + tools.ExecShell("mysql -uroot -p" + oldRootPassword + " -e \"ALTER USER 'root'@'localhost' IDENTIFIED BY '" + rootPassword + "';\"") + tools.ExecShell("mysql -uroot -p" + oldRootPassword + " -e \"FLUSH PRIVILEGES;\"") err := r.setting.Set(models.SettingKeyMysqlRootPassword, rootPassword) if err != nil { - helper.ExecShell("mysql -uroot -p" + rootPassword + " -e \"ALTER USER 'root'@'localhost' IDENTIFIED BY '" + oldRootPassword + "';\"") - helper.ExecShell("mysql -uroot -p" + rootPassword + " -e \"FLUSH PRIVILEGES;\"") + tools.ExecShell("mysql -uroot -p" + rootPassword + " -e \"ALTER USER 'root'@'localhost' IDENTIFIED BY '" + oldRootPassword + "';\"") + tools.ExecShell("mysql -uroot -p" + rootPassword + " -e \"FLUSH PRIVILEGES;\"") controllers.Error(ctx, http.StatusInternalServerError, "设置root密码失败") return } @@ -348,7 +348,7 @@ func (r *Mysql80Controller) DatabaseList(ctx http.Context) { return } - out := helper.ExecShell("mysql -uroot -p" + r.setting.Get(models.SettingKeyMysqlRootPassword) + " -e \"show databases;\"") + out := tools.ExecShell("mysql -uroot -p" + r.setting.Get(models.SettingKeyMysqlRootPassword) + " -e \"show databases;\"") databases := strings.Split(out, "\n") databases = databases[1 : len(databases)-1] @@ -398,10 +398,10 @@ func (r *Mysql80Controller) AddDatabase(ctx http.Context) { user := ctx.Request().Input("user") password := ctx.Request().Input("password") - helper.ExecShell("mysql -uroot -p" + rootPassword + " -e \"CREATE DATABASE IF NOT EXISTS " + database + " DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_general_ci;\"") - helper.ExecShell("mysql -uroot -p" + rootPassword + " -e \"CREATE USER '" + user + "'@'localhost' IDENTIFIED BY '" + password + "';\"") - helper.ExecShell("mysql -uroot -p" + rootPassword + " -e \"GRANT ALL PRIVILEGES ON " + database + ".* TO '" + user + "'@'localhost';\"") - helper.ExecShell("mysql -uroot -p" + rootPassword + " -e \"FLUSH PRIVILEGES;\"") + tools.ExecShell("mysql -uroot -p" + rootPassword + " -e \"CREATE DATABASE IF NOT EXISTS " + database + " DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_general_ci;\"") + tools.ExecShell("mysql -uroot -p" + rootPassword + " -e \"CREATE USER '" + user + "'@'localhost' IDENTIFIED BY '" + password + "';\"") + tools.ExecShell("mysql -uroot -p" + rootPassword + " -e \"GRANT ALL PRIVILEGES ON " + database + ".* TO '" + user + "'@'localhost';\"") + tools.ExecShell("mysql -uroot -p" + rootPassword + " -e \"FLUSH PRIVILEGES;\"") controllers.Success(ctx, "添加数据库成功") } @@ -426,7 +426,7 @@ func (r *Mysql80Controller) DeleteDatabase(ctx http.Context) { rootPassword := r.setting.Get(models.SettingKeyMysqlRootPassword) database := ctx.Request().Input("database") - helper.ExecShell("mysql -uroot -p" + rootPassword + " -e \"DROP DATABASE IF EXISTS " + database + ";\"") + tools.ExecShell("mysql -uroot -p" + rootPassword + " -e \"DROP DATABASE IF EXISTS " + database + ";\"") controllers.Success(ctx, "删除数据库成功") } @@ -435,8 +435,8 @@ func (r *Mysql80Controller) DeleteDatabase(ctx http.Context) { func (r *Mysql80Controller) BackupList(ctx http.Context) { backupPath := "/www/backup/mysql" - if !helper.Exists(backupPath) { - helper.Mkdir(backupPath, 0644) + if !tools.Exists(backupPath) { + tools.Mkdir(backupPath, 0644) } files, err := os.ReadDir(backupPath) @@ -458,7 +458,7 @@ func (r *Mysql80Controller) BackupList(ctx http.Context) { backupFiles = append(backupFiles, map[string]string{ "file": file.Name(), - "size": helper.FormatBytes(float64(info.Size())), + "size": tools.FormatBytes(float64(info.Size())), }) } @@ -487,8 +487,8 @@ func (r *Mysql80Controller) CreateBackup(ctx http.Context) { rootPassword := r.setting.Get(models.SettingKeyMysqlRootPassword) database := ctx.Request().Input("database") backupFile := backupPath + "/" + database + "_" + carbon.Now().ToShortDateTimeString() + ".sql" - if !helper.Exists(backupPath) { - helper.Mkdir(backupPath, 0644) + if !tools.Exists(backupPath) { + tools.Mkdir(backupPath, 0644) } err = os.Setenv("MYSQL_PWD", rootPassword) if err != nil { @@ -497,9 +497,9 @@ func (r *Mysql80Controller) CreateBackup(ctx http.Context) { return } - helper.ExecShell("mysqldump -uroot " + database + " > " + backupFile) - helper.ExecShell("zip -r " + backupFile + ".zip " + backupFile) - helper.RemoveFile(backupFile) + tools.ExecShell("mysqldump -uroot " + database + " > " + backupFile) + tools.ExecShell("zip -r " + backupFile + ".zip " + backupFile) + tools.RemoveFile(backupFile) _ = os.Unsetenv("MYSQL_PWD") controllers.Success(ctx, "备份成功") @@ -525,7 +525,7 @@ func (r *Mysql80Controller) DeleteBackup(ctx http.Context) { backupPath := "/www/backup/mysql" file := ctx.Request().Input("file") - helper.RemoveFile(backupPath + "/" + file) + tools.RemoveFile(backupPath + "/" + file) controllers.Success(ctx, "删除备份成功") } @@ -553,7 +553,7 @@ func (r *Mysql80Controller) RestoreBackup(ctx http.Context) { rootPassword := r.setting.Get(models.SettingKeyMysqlRootPassword) file := ctx.Request().Input("file") backupFile := backupPath + "/" + file - if !helper.Exists(backupFile) { + if !tools.Exists(backupFile) { controllers.Error(ctx, http.StatusBadRequest, "备份文件不存在") return } @@ -569,35 +569,35 @@ func (r *Mysql80Controller) RestoreBackup(ctx http.Context) { ext := filepath.Ext(file) switch ext { case ".zip": - helper.ExecShell("unzip -o " + backupFile + " -d " + backupPath) + tools.ExecShell("unzip -o " + backupFile + " -d " + backupPath) backupFile = strings.TrimSuffix(backupFile, ext) case ".gz": if strings.HasSuffix(file, ".tar.gz") { // 解压.tar.gz文件 - helper.ExecShell("tar -zxvf " + backupFile + " -C " + backupPath) + tools.ExecShell("tar -zxvf " + backupFile + " -C " + backupPath) backupFile = strings.TrimSuffix(backupFile, ".tar.gz") } else { // 解压.gz文件 - helper.ExecShell("gzip -d " + backupFile) + tools.ExecShell("gzip -d " + backupFile) backupFile = strings.TrimSuffix(backupFile, ext) } case ".bz2": - helper.ExecShell("bzip2 -d " + backupFile) + tools.ExecShell("bzip2 -d " + backupFile) backupFile = strings.TrimSuffix(backupFile, ext) case ".tar": - helper.ExecShell("tar -xvf " + backupFile + " -C " + backupPath) + tools.ExecShell("tar -xvf " + backupFile + " -C " + backupPath) backupFile = strings.TrimSuffix(backupFile, ext) case ".rar": - helper.ExecShell("unrar x " + backupFile + " " + backupPath) + tools.ExecShell("unrar x " + backupFile + " " + backupPath) backupFile = strings.TrimSuffix(backupFile, ext) } - if !helper.Exists(backupFile) { + if !tools.Exists(backupFile) { controllers.Error(ctx, http.StatusBadRequest, "自动解压备份文件失败,请手动解压") return } - helper.ExecShell("mysql -uroot " + ctx.Request().Input("database") + " < " + backupFile) + tools.ExecShell("mysql -uroot " + ctx.Request().Input("database") + " < " + backupFile) _ = os.Unsetenv("MYSQL_PWD") controllers.Success(ctx, "还原成功") @@ -616,7 +616,7 @@ func (r *Mysql80Controller) UserList(ctx http.Context) { } rootPassword := r.setting.Get(models.SettingKeyMysqlRootPassword) - out := helper.ExecShell("mysql -uroot -p" + rootPassword + " -e 'select user,host from mysql.user'") + out := tools.ExecShell("mysql -uroot -p" + rootPassword + " -e 'select user,host from mysql.user'") rawUsers := strings.Split(out, "\n") users := make([]User, 0) for _, rawUser := range rawUsers { @@ -625,7 +625,7 @@ func (r *Mysql80Controller) UserList(ctx http.Context) { continue } - out := helper.ExecShell("mysql -uroot -p" + rootPassword + " -e 'show grants for " + user[0] + "@" + user[1] + "'") + out := tools.ExecShell("mysql -uroot -p" + rootPassword + " -e 'show grants for " + user[0] + "@" + user[1] + "'") rawPrivileges := strings.Split(out, "\n") privileges := make([]string, 0) for _, rawPrivilege := range rawPrivileges { @@ -665,9 +665,9 @@ func (r *Mysql80Controller) AddUser(ctx http.Context) { user := ctx.Request().Input("user") password := ctx.Request().Input("password") database := ctx.Request().Input("database") - helper.ExecShell("mysql -uroot -p" + rootPassword + " -e \"CREATE USER '" + user + "'@'localhost' IDENTIFIED BY '" + password + ";'\"") - helper.ExecShell("mysql -uroot -p" + rootPassword + " -e \"GRANT ALL PRIVILEGES ON " + database + ".* TO '" + user + "'@'localhost';\"") - helper.ExecShell("mysql -uroot -p" + rootPassword + " -e \"FLUSH PRIVILEGES;\"") + tools.ExecShell("mysql -uroot -p" + rootPassword + " -e \"CREATE USER '" + user + "'@'localhost' IDENTIFIED BY '" + password + ";'\"") + tools.ExecShell("mysql -uroot -p" + rootPassword + " -e \"GRANT ALL PRIVILEGES ON " + database + ".* TO '" + user + "'@'localhost';\"") + tools.ExecShell("mysql -uroot -p" + rootPassword + " -e \"FLUSH PRIVILEGES;\"") controllers.Success(ctx, "添加成功") } @@ -692,7 +692,7 @@ func (r *Mysql80Controller) DeleteUser(ctx http.Context) { rootPassword := r.setting.Get(models.SettingKeyMysqlRootPassword) user := ctx.Request().Input("user") - helper.ExecShell("mysql -uroot -p" + rootPassword + " -e \"DROP USER '" + user + "'@'localhost';\"") + tools.ExecShell("mysql -uroot -p" + rootPassword + " -e \"DROP USER '" + user + "'@'localhost';\"") controllers.Success(ctx, "删除成功") } @@ -719,8 +719,8 @@ func (r *Mysql80Controller) SetUserPassword(ctx http.Context) { rootPassword := r.setting.Get(models.SettingKeyMysqlRootPassword) user := ctx.Request().Input("user") password := ctx.Request().Input("password") - helper.ExecShell("mysql -uroot -p" + rootPassword + " -e \"ALTER USER '" + user + "'@'localhost' IDENTIFIED BY '" + password + "';\"") - helper.ExecShell("mysql -uroot -p" + rootPassword + " -e \"FLUSH PRIVILEGES;\"") + tools.ExecShell("mysql -uroot -p" + rootPassword + " -e \"ALTER USER '" + user + "'@'localhost' IDENTIFIED BY '" + password + "';\"") + tools.ExecShell("mysql -uroot -p" + rootPassword + " -e \"FLUSH PRIVILEGES;\"") controllers.Success(ctx, "修改成功") } @@ -747,9 +747,9 @@ func (r *Mysql80Controller) SetUserPrivileges(ctx http.Context) { rootPassword := r.setting.Get(models.SettingKeyMysqlRootPassword) user := ctx.Request().Input("user") database := ctx.Request().Input("database") - helper.ExecShell("mysql -uroot -p" + rootPassword + " -e \"REVOKE ALL PRIVILEGES ON *.* FROM '" + user + "'@'localhost';\"") - helper.ExecShell("mysql -uroot -p" + rootPassword + " -e \"GRANT ALL PRIVILEGES ON " + database + ".* TO '" + user + "'@'localhost';\"") - helper.ExecShell("mysql -uroot -p" + rootPassword + " -e \"FLUSH PRIVILEGES;\"") + tools.ExecShell("mysql -uroot -p" + rootPassword + " -e \"REVOKE ALL PRIVILEGES ON *.* FROM '" + user + "'@'localhost';\"") + tools.ExecShell("mysql -uroot -p" + rootPassword + " -e \"GRANT ALL PRIVILEGES ON " + database + ".* TO '" + user + "'@'localhost';\"") + tools.ExecShell("mysql -uroot -p" + rootPassword + " -e \"FLUSH PRIVILEGES;\"") controllers.Success(ctx, "修改成功") } diff --git a/app/http/controllers/plugins/openresty/openresty_controller.go b/app/http/controllers/plugins/openresty/openresty_controller.go index 874554882d..bc3aba8475 100644 --- a/app/http/controllers/plugins/openresty/openresty_controller.go +++ b/app/http/controllers/plugins/openresty/openresty_controller.go @@ -12,7 +12,7 @@ import ( "panel/app/http/controllers" "panel/app/http/controllers/plugins" - "panel/packages/helper" + "panel/pkg/tools" ) type OpenRestyController struct { @@ -31,7 +31,7 @@ func (r *OpenRestyController) Status(ctx http.Context) { return } - out := helper.ExecShell("systemctl status openresty | grep Active | grep -v grep | awk '{print $2}'") + out := tools.ExecShell("systemctl status openresty | grep Active | grep -v grep | awk '{print $2}'") status := strings.TrimSpace(out) if len(status) == 0 { controllers.Error(ctx, http.StatusInternalServerError, "获取OpenResty状态失败") @@ -51,8 +51,8 @@ func (r *OpenRestyController) Reload(ctx http.Context) { return } - helper.ExecShell("systemctl reload openresty") - out := helper.ExecShell("systemctl status openresty | grep Active | grep -v grep | awk '{print $2}'") + tools.ExecShell("systemctl reload openresty") + out := tools.ExecShell("systemctl status openresty | grep Active | grep -v grep | awk '{print $2}'") status := strings.TrimSpace(out) if len(status) == 0 { controllers.Error(ctx, http.StatusInternalServerError, "获取OpenResty状态失败") @@ -72,8 +72,8 @@ func (r *OpenRestyController) Start(ctx http.Context) { return } - helper.ExecShell("systemctl start openresty") - out := helper.ExecShell("systemctl status openresty | grep Active | grep -v grep | awk '{print $2}'") + tools.ExecShell("systemctl start openresty") + out := tools.ExecShell("systemctl status openresty | grep Active | grep -v grep | awk '{print $2}'") status := strings.TrimSpace(out) if len(status) == 0 { controllers.Error(ctx, http.StatusInternalServerError, "获取OpenResty状态失败") @@ -93,8 +93,8 @@ func (r *OpenRestyController) Stop(ctx http.Context) { return } - helper.ExecShell("systemctl stop openresty") - out := helper.ExecShell("systemctl status openresty | grep Active | grep -v grep | awk '{print $2}'") + tools.ExecShell("systemctl stop openresty") + out := tools.ExecShell("systemctl status openresty | grep Active | grep -v grep | awk '{print $2}'") status := strings.TrimSpace(out) if len(status) == 0 { controllers.Error(ctx, http.StatusInternalServerError, "获取OpenResty状态失败") @@ -114,8 +114,8 @@ func (r *OpenRestyController) Restart(ctx http.Context) { return } - helper.ExecShell("systemctl restart openresty") - out := helper.ExecShell("systemctl status openresty | grep Active | grep -v grep | awk '{print $2}'") + tools.ExecShell("systemctl restart openresty") + out := tools.ExecShell("systemctl status openresty | grep Active | grep -v grep | awk '{print $2}'") status := strings.TrimSpace(out) if len(status) == 0 { controllers.Error(ctx, http.StatusInternalServerError, "获取OpenResty状态失败") @@ -135,7 +135,7 @@ func (r *OpenRestyController) GetConfig(ctx http.Context) { return } - config := helper.ReadFile("/www/server/openresty/conf/nginx.conf") + config := tools.ReadFile("/www/server/openresty/conf/nginx.conf") if len(config) == 0 { controllers.Error(ctx, http.StatusInternalServerError, "获取OpenResty配置失败") return @@ -156,7 +156,7 @@ func (r *OpenRestyController) SaveConfig(ctx http.Context) { return } - if !helper.WriteFile("/www/server/openresty/conf/nginx.conf", config, 0644) { + if !tools.WriteFile("/www/server/openresty/conf/nginx.conf", config, 0644) { controllers.Error(ctx, http.StatusInternalServerError, "保存OpenResty配置失败") return } @@ -170,7 +170,7 @@ func (r *OpenRestyController) ErrorLog(ctx http.Context) { return } - out := helper.ExecShell("tail -n 100 /www/wwwlogs/nginx_error.log") + out := tools.ExecShell("tail -n 100 /www/wwwlogs/nginx_error.log") controllers.Success(ctx, out) } @@ -180,7 +180,7 @@ func (r *OpenRestyController) ClearErrorLog(ctx http.Context) { return } - _ = helper.ExecShell("echo '' > /www/wwwlogs/nginx_error.log") + _ = tools.ExecShell("echo '' > /www/wwwlogs/nginx_error.log") controllers.Success(ctx, "清空OpenResty错误日志成功") } @@ -201,13 +201,13 @@ func (r *OpenRestyController) Load(ctx http.Context) { raw := resp.String() var data map[int]map[string]any - out := helper.ExecShell("ps aux | grep nginx | grep 'worker process' | wc -l") + out := tools.ExecShell("ps aux | grep nginx | grep 'worker process' | wc -l") workers := strings.TrimSpace(out) data[0]["name"] = "工作进程" data[0]["value"] = workers - out = helper.ExecShell("ps aux | grep nginx | grep 'worker process' | awk '{memsum+=$6};END {print memsum}'") - mem := helper.FormatBytes(cast.ToFloat64(strings.TrimSpace(out))) + out = tools.ExecShell("ps aux | grep nginx | grep 'worker process' | awk '{memsum+=$6};END {print memsum}'") + mem := tools.FormatBytes(cast.ToFloat64(strings.TrimSpace(out))) data[1]["name"] = "内存占用" data[1]["value"] = mem diff --git a/app/http/controllers/plugins/php74/php74_controller.go b/app/http/controllers/plugins/php74/php74_controller.go index fd930333bd..c954da1aa4 100644 --- a/app/http/controllers/plugins/php74/php74_controller.go +++ b/app/http/controllers/plugins/php74/php74_controller.go @@ -14,7 +14,7 @@ import ( "panel/app/http/controllers/plugins" "panel/app/models" "panel/app/services" - "panel/packages/helper" + "panel/pkg/tools" ) type Php74Controller struct { @@ -36,7 +36,7 @@ func (c *Php74Controller) Status(ctx http.Context) { return } - out := helper.ExecShell("systemctl status php-fpm-" + c.version + " | grep Active | grep -v grep | awk '{print $2}'") + out := tools.ExecShell("systemctl status php-fpm-" + c.version + " | grep Active | grep -v grep | awk '{print $2}'") status := strings.TrimSpace(out) if len(status) == 0 { controllers.Error(ctx, http.StatusInternalServerError, "获取PHP-"+c.version+"运行状态失败") @@ -55,8 +55,8 @@ func (c *Php74Controller) Reload(ctx http.Context) { return } - helper.ExecShell("systemctl reload php-fpm-" + c.version) - out := helper.ExecShell("systemctl status php-fpm-" + c.version + " | grep Active | grep -v grep | awk '{print $2}'") + tools.ExecShell("systemctl reload php-fpm-" + c.version) + out := tools.ExecShell("systemctl status php-fpm-" + c.version + " | grep Active | grep -v grep | awk '{print $2}'") status := strings.TrimSpace(out) if len(status) == 0 { controllers.Error(ctx, http.StatusInternalServerError, "获取PHP-"+c.version+"运行状态失败") @@ -75,8 +75,8 @@ func (c *Php74Controller) Start(ctx http.Context) { return } - helper.ExecShell("systemctl start php-fpm-" + c.version) - out := helper.ExecShell("systemctl status php-fpm-" + c.version + " | grep Active | grep -v grep | awk '{print $2}'") + tools.ExecShell("systemctl start php-fpm-" + c.version) + out := tools.ExecShell("systemctl status php-fpm-" + c.version + " | grep Active | grep -v grep | awk '{print $2}'") status := strings.TrimSpace(out) if len(status) == 0 { controllers.Error(ctx, http.StatusInternalServerError, "获取PHP-"+c.version+"运行状态失败") @@ -95,8 +95,8 @@ func (c *Php74Controller) Stop(ctx http.Context) { return } - helper.ExecShell("systemctl stop php-fpm-" + c.version) - out := helper.ExecShell("systemctl status php-fpm-" + c.version + " | grep Active | grep -v grep | awk '{print $2}'") + tools.ExecShell("systemctl stop php-fpm-" + c.version) + out := tools.ExecShell("systemctl status php-fpm-" + c.version + " | grep Active | grep -v grep | awk '{print $2}'") status := strings.TrimSpace(out) if len(status) == 0 { controllers.Error(ctx, http.StatusInternalServerError, "获取PHP-"+c.version+"运行状态失败") @@ -115,8 +115,8 @@ func (c *Php74Controller) Restart(ctx http.Context) { return } - helper.ExecShell("systemctl restart php-fpm-" + c.version) - out := helper.ExecShell("systemctl status php-fpm-" + c.version + " | grep Active | grep -v grep | awk '{print $2}'") + tools.ExecShell("systemctl restart php-fpm-" + c.version) + out := tools.ExecShell("systemctl status php-fpm-" + c.version + " | grep Active | grep -v grep | awk '{print $2}'") status := strings.TrimSpace(out) if len(status) == 0 { controllers.Error(ctx, http.StatusInternalServerError, "获取PHP-"+c.version+"运行状态失败") @@ -135,7 +135,7 @@ func (c *Php74Controller) GetConfig(ctx http.Context) { return } - config := helper.ReadFile("/www/server/php/" + c.version + "/etc/php.ini") + config := tools.ReadFile("/www/server/php/" + c.version + "/etc/php.ini") controllers.Success(ctx, config) } @@ -145,7 +145,7 @@ func (c *Php74Controller) SaveConfig(ctx http.Context) { } config := ctx.Request().Input("config") - helper.WriteFile("/www/server/php/"+c.version+"/etc/php.ini", config, 0644) + tools.WriteFile("/www/server/php/"+c.version+"/etc/php.ini", config, 0644) c.Reload(ctx) } @@ -190,7 +190,7 @@ func (c *Php74Controller) ErrorLog(ctx http.Context) { return } - log := helper.ExecShell("tail -n 100 /www/server/php/" + c.version + "/var/log/php-fpm.log") + log := tools.ExecShell("tail -n 100 /www/server/php/" + c.version + "/var/log/php-fpm.log") controllers.Success(ctx, log) } @@ -199,7 +199,7 @@ func (c *Php74Controller) SlowLog(ctx http.Context) { return } - log := helper.ExecShell("tail -n 100 /www/server/php/" + c.version + "/var/log/slow.log") + log := tools.ExecShell("tail -n 100 /www/server/php/" + c.version + "/var/log/slow.log") controllers.Success(ctx, log) } @@ -208,7 +208,7 @@ func (c *Php74Controller) ClearErrorLog(ctx http.Context) { return } - helper.ExecShell("echo '' > /www/server/php/" + c.version + "/var/log/php-fpm.log") + tools.ExecShell("echo '' > /www/server/php/" + c.version + "/var/log/php-fpm.log") controllers.Success(ctx, true) } @@ -217,7 +217,7 @@ func (c *Php74Controller) ClearSlowLog(ctx http.Context) { return } - helper.ExecShell("echo '' > /www/server/php/" + c.version + "/var/log/slow.log") + tools.ExecShell("echo '' > /www/server/php/" + c.version + "/var/log/slow.log") controllers.Success(ctx, true) } @@ -356,7 +356,7 @@ func (c *Php74Controller) GetExtensions() []Extension { Installed: false, }) - raw := helper.ExecShell("/www/server/php/" + c.version + "/bin/php -m") + raw := tools.ExecShell("/www/server/php/" + c.version + "/bin/php -m") rawExtensionList := strings.Split(raw, "\n") for _, item := range rawExtensionList { diff --git a/app/http/controllers/safe_controller.go b/app/http/controllers/safe_controller.go index 89f0c8484e..7e7709af69 100644 --- a/app/http/controllers/safe_controller.go +++ b/app/http/controllers/safe_controller.go @@ -7,7 +7,7 @@ import ( "github.com/goravel/framework/contracts/http" "github.com/spf13/cast" - "panel/packages/helper" + "panel/pkg/tools" ) type SafeController struct { @@ -27,16 +27,16 @@ func (r *SafeController) GetFirewallStatus(ctx http.Context) { func (r *SafeController) SetFirewallStatus(ctx http.Context) { var out string if ctx.Request().QueryBool("status") { - if helper.IsRHEL() { - out = helper.ExecShell("systemctl start firewalld") + if tools.IsRHEL() { + out = tools.ExecShell("systemctl start firewalld") } else { - out = helper.ExecShell("echo y | ufw enable") + out = tools.ExecShell("echo y | ufw enable") } } else { - if helper.IsRHEL() { - out = helper.ExecShell("systemctl stop firewalld") + if tools.IsRHEL() { + out = tools.ExecShell("systemctl stop firewalld") } else { - out = helper.ExecShell("ufw disable") + out = tools.ExecShell("ufw disable") } } @@ -49,8 +49,8 @@ func (r *SafeController) GetFirewallRules(ctx http.Context) { return } - if helper.IsRHEL() { - out := helper.ExecShell("firewall-cmd --list-all 2>&1") + if tools.IsRHEL() { + out := tools.ExecShell("firewall-cmd --list-all 2>&1") match := regexp.MustCompile(`ports: (.*)`).FindStringSubmatch(out) if len(match) == 0 { Success(ctx, nil) @@ -68,7 +68,7 @@ func (r *SafeController) GetFirewallRules(ctx http.Context) { Success(ctx, rules) } else { - out := helper.ExecShell("ufw status numbered | grep ALLOW | awk '{print $2}'") + out := tools.ExecShell("ufw status numbered | grep ALLOW | awk '{print $2}'") if len(out) == 0 { Success(ctx, nil) return @@ -102,14 +102,14 @@ func (r *SafeController) AddFirewallRule(ctx http.Context) { return } - if helper.IsRHEL() { - helper.ExecShell("firewall-cmd --remove-port=" + cast.ToString(port) + "/" + protocol + " --permanent 2>&1") - helper.ExecShell("firewall-cmd --add-port=" + cast.ToString(port) + "/" + protocol + " --permanent 2>&1") - helper.ExecShell("firewall-cmd --reload") + if tools.IsRHEL() { + tools.ExecShell("firewall-cmd --remove-port=" + cast.ToString(port) + "/" + protocol + " --permanent 2>&1") + tools.ExecShell("firewall-cmd --add-port=" + cast.ToString(port) + "/" + protocol + " --permanent 2>&1") + tools.ExecShell("firewall-cmd --reload") } else { - helper.ExecShell("ufw delete allow " + cast.ToString(port) + "/" + protocol) - helper.ExecShell("ufw allow " + cast.ToString(port) + "/" + protocol) - helper.ExecShell("ufw reload") + tools.ExecShell("ufw delete allow " + cast.ToString(port) + "/" + protocol) + tools.ExecShell("ufw allow " + cast.ToString(port) + "/" + protocol) + tools.ExecShell("ufw reload") } Success(ctx, nil) @@ -128,12 +128,12 @@ func (r *SafeController) DeleteFirewallRule(ctx http.Context) { return } - if helper.IsRHEL() { - helper.ExecShell("firewall-cmd --remove-port=" + cast.ToString(port) + "/" + protocol + " --permanent 2>&1") - helper.ExecShell("firewall-cmd --reload") + if tools.IsRHEL() { + tools.ExecShell("firewall-cmd --remove-port=" + cast.ToString(port) + "/" + protocol + " --permanent 2>&1") + tools.ExecShell("firewall-cmd --reload") } else { - helper.ExecShell("ufw delete allow " + cast.ToString(port) + "/" + protocol) - helper.ExecShell("ufw reload") + tools.ExecShell("ufw delete allow " + cast.ToString(port) + "/" + protocol) + tools.ExecShell("ufw reload") } Success(ctx, nil) @@ -142,15 +142,15 @@ func (r *SafeController) DeleteFirewallRule(ctx http.Context) { func (r *SafeController) firewallStatus() bool { var out string var running bool - if helper.IsRHEL() { - out = helper.ExecShell("systemctl status firewalld | grep Active | awk '{print $3}'") + if tools.IsRHEL() { + out = tools.ExecShell("systemctl status firewalld | grep Active | awk '{print $3}'") if out == "(running)" { running = true } else { running = false } } else { - out = helper.ExecShell("ufw status | grep Status | awk '{print $2}'") + out = tools.ExecShell("ufw status | grep Status | awk '{print $2}'") if out == "active" { running = true } else { @@ -162,7 +162,7 @@ func (r *SafeController) firewallStatus() bool { } func (r *SafeController) GetSshStatus(ctx http.Context) { - out := helper.ExecShell("systemctl status sshd | grep Active | awk '{print $3}'") + out := tools.ExecShell("systemctl status sshd | grep Active | awk '{print $3}'") running := false if out == "(running)" { running = true @@ -173,18 +173,18 @@ func (r *SafeController) GetSshStatus(ctx http.Context) { func (r *SafeController) SetSshStatus(ctx http.Context) { if ctx.Request().QueryBool("status") { - helper.ExecShell("systemctl enable sshd") - helper.ExecShell("systemctl start sshd") + tools.ExecShell("systemctl enable sshd") + tools.ExecShell("systemctl start sshd") } else { - helper.ExecShell("systemctl stop sshd") - helper.ExecShell("systemctl disable sshd") + tools.ExecShell("systemctl stop sshd") + tools.ExecShell("systemctl disable sshd") } Success(ctx, nil) } func (r *SafeController) GetSshPort(ctx http.Context) { - out := helper.ExecShell("cat /etc/ssh/sshd_config | grep Port | awk '{print $2}'") + out := tools.ExecShell("cat /etc/ssh/sshd_config | grep Port | awk '{print $2}'") Success(ctx, out) } @@ -195,27 +195,27 @@ func (r *SafeController) SetSshPort(ctx http.Context) { return } - oldPort := helper.ExecShell("cat /etc/ssh/sshd_config | grep Port | awk '{print $2}'") - helper.ExecShell("sed -i 's/#Port " + oldPort + "/Port " + cast.ToString(port) + "/g' /etc/ssh/sshd_config") - helper.ExecShell("sed -i 's/Port " + oldPort + "/Port " + cast.ToString(port) + "/g' /etc/ssh/sshd_config") + oldPort := tools.ExecShell("cat /etc/ssh/sshd_config | grep Port | awk '{print $2}'") + tools.ExecShell("sed -i 's/#Port " + oldPort + "/Port " + cast.ToString(port) + "/g' /etc/ssh/sshd_config") + tools.ExecShell("sed -i 's/Port " + oldPort + "/Port " + cast.ToString(port) + "/g' /etc/ssh/sshd_config") - if status := helper.ExecShell("systemctl status sshd | grep Active | awk '{print $3}'"); status == "(running)" { - helper.ExecShell("systemctl restart sshd") + if status := tools.ExecShell("systemctl status sshd | grep Active | awk '{print $3}'"); status == "(running)" { + tools.ExecShell("systemctl restart sshd") } Success(ctx, nil) } func (r *SafeController) GetPingStatus(ctx http.Context) { - if helper.IsRHEL() { - out := helper.ExecShell("firewall-cmd --query-rich-rule='rule protocol value=icmp drop' 2>&1") + if tools.IsRHEL() { + out := tools.ExecShell("firewall-cmd --query-rich-rule='rule protocol value=icmp drop' 2>&1") if out == "no" { Success(ctx, true) } else { Success(ctx, false) } } else { - config := helper.ReadFile("/etc/ufw/before.rules") + config := tools.ReadFile("/etc/ufw/before.rules") if strings.Contains(config, "-A ufw-before-input -p icmp --icmp-type echo-request -j ACCEPT") { Success(ctx, true) } else { @@ -225,20 +225,20 @@ func (r *SafeController) GetPingStatus(ctx http.Context) { } func (r *SafeController) SetPingStatus(ctx http.Context) { - if helper.IsRHEL() { + if tools.IsRHEL() { if ctx.Request().QueryBool("status") { - helper.ExecShell("firewall-cmd --permanent --add-rich-rule='rule protocol value=icmp drop'") + tools.ExecShell("firewall-cmd --permanent --add-rich-rule='rule protocol value=icmp drop'") } else { - helper.ExecShell("firewall-cmd --permanent --remove-rich-rule='rule protocol value=icmp drop'") + tools.ExecShell("firewall-cmd --permanent --remove-rich-rule='rule protocol value=icmp drop'") } - helper.ExecShell("firewall-cmd --reload") + tools.ExecShell("firewall-cmd --reload") } else { if ctx.Request().QueryBool("status") { - helper.ExecShell("sed -i 's/-A ufw-before-input -p icmp --icmp-type echo-request -j ACCEPT/-A ufw-before-input -p icmp --icmp-type echo-request -j DROP/g' /etc/ufw/before.rules") + tools.ExecShell("sed -i 's/-A ufw-before-input -p icmp --icmp-type echo-request -j ACCEPT/-A ufw-before-input -p icmp --icmp-type echo-request -j DROP/g' /etc/ufw/before.rules") } else { - helper.ExecShell("sed -i 's/-A ufw-before-input -p icmp --icmp-type echo-request -j DROP/-A ufw-before-input -p icmp --icmp-type echo-request -j ACCEPT/g' /etc/ufw/before.rules") + tools.ExecShell("sed -i 's/-A ufw-before-input -p icmp --icmp-type echo-request -j DROP/-A ufw-before-input -p icmp --icmp-type echo-request -j ACCEPT/g' /etc/ufw/before.rules") } - helper.ExecShell("ufw reload") + tools.ExecShell("ufw reload") } Success(ctx, nil) diff --git a/app/http/controllers/setting_controller.go b/app/http/controllers/setting_controller.go index 0b61449813..65f16eba6a 100644 --- a/app/http/controllers/setting_controller.go +++ b/app/http/controllers/setting_controller.go @@ -3,7 +3,7 @@ package controllers import ( "github.com/goravel/framework/contracts/http" "github.com/goravel/framework/facades" - "panel/packages/helper" + "panel/pkg/tools" "panel/app/models" "panel/app/services" @@ -70,9 +70,9 @@ func (r *SettingController) Save(ctx http.Context) { return } - oldPort := helper.ExecShell("cat /www/panel/panel.conf | grep APP_PORT | awk -F '=' '{print $2}'") + oldPort := tools.ExecShell("cat /www/panel/panel.conf | grep APP_PORT | awk -F '=' '{print $2}'") if oldPort != port { - helper.ExecShell("sed -i 's/APP_PORT=" + oldPort + "/APP_PORT=" + port + "/g' /www/panel/panel.conf") + tools.ExecShell("sed -i 's/APP_PORT=" + oldPort + "/APP_PORT=" + port + "/g' /www/panel/panel.conf") } err = r.setting.Set(models.SettingKeyBackupPath, backupPath) if err != nil { diff --git a/app/http/controllers/task_controller.go b/app/http/controllers/task_controller.go index b6eb6601e5..13bb4c74bc 100644 --- a/app/http/controllers/task_controller.go +++ b/app/http/controllers/task_controller.go @@ -4,7 +4,7 @@ import ( "github.com/goravel/framework/contracts/http" "github.com/goravel/framework/facades" "panel/app/models" - "panel/packages/helper" + "panel/pkg/tools" ) type TaskController struct { @@ -62,7 +62,7 @@ func (r *TaskController) Log(ctx http.Context) { return } - log := helper.ExecShell("tail -n 30 " + task.Log) + log := tools.ExecShell("tail -n 30 " + task.Log) Success(ctx, log) } diff --git a/app/http/controllers/website_controller.go b/app/http/controllers/website_controller.go index 3dad35d684..7c80bdd4e3 100644 --- a/app/http/controllers/website_controller.go +++ b/app/http/controllers/website_controller.go @@ -9,7 +9,7 @@ import ( "github.com/goravel/framework/contracts/http" "github.com/goravel/framework/facades" "panel/app/models" - "panel/packages/helper" + "panel/pkg/tools" "panel/app/services" ) @@ -107,8 +107,8 @@ func (c *WebsiteController) Delete(ctx http.Context) { } func (c *WebsiteController) GetDefaultConfig(ctx http.Context) { - index := helper.ReadFile("/www/server/openresty/html/index.html") - stop := helper.ReadFile("/www/server/openresty/html/stop.html") + index := tools.ReadFile("/www/server/openresty/html/index.html") + stop := tools.ReadFile("/www/server/openresty/html/stop.html") Success(ctx, http.Json{ "index": index, @@ -120,13 +120,13 @@ func (c *WebsiteController) SaveDefaultConfig(ctx http.Context) { index := ctx.Request().Input("index") stop := ctx.Request().Input("stop") - if !helper.WriteFile("/www/server/openresty/html/index.html", index, 0644) { + if !tools.WriteFile("/www/server/openresty/html/index.html", index, 0644) { facades.Log().Error("[面板][WebsiteController] 保存默认配置失败") Error(ctx, http.StatusInternalServerError, "系统内部错误") return } - if !helper.WriteFile("/www/server/openresty/html/stop.html", stop, 0644) { + if !tools.WriteFile("/www/server/openresty/html/stop.html", stop, 0644) { facades.Log().Error("[面板][WebsiteController] 保存默认配置失败") Error(ctx, http.StatusInternalServerError, "系统内部错误") return @@ -178,16 +178,16 @@ func (c *WebsiteController) SaveConfig(ctx http.Context) { } // 原文 - raw := helper.ReadFile("/www/server/panel/vhost/openresty/" + website.Name + ".conf") + raw := tools.ReadFile("/www/server/panel/vhost/openresty/" + website.Name + ".conf") if strings.TrimSpace(raw) != strings.TrimSpace(ctx.Request().Input("raw")) { - helper.WriteFile("/www/server/panel/vhost/openresty/"+website.Name+".conf", ctx.Request().Input("raw"), 0644) + tools.WriteFile("/www/server/panel/vhost/openresty/"+website.Name+".conf", ctx.Request().Input("raw"), 0644) Success(ctx, nil) return } // 目录 path := ctx.Request().Input("path") - if !helper.Exists(path) { + if !tools.Exists(path) { Error(ctx, http.StatusBadRequest, "网站目录不存在") return } @@ -207,7 +207,7 @@ func (c *WebsiteController) SaveConfig(ctx http.Context) { domain += " " + v } domain += ";" - domainConfigOld := helper.Cut(raw, "# server_name标记位开始", "# server_name标记位结束") + domainConfigOld := tools.Cut(raw, "# server_name标记位开始", "# server_name标记位结束") if len(strings.TrimSpace(domainConfigOld)) == 0 { Error(ctx, http.StatusBadRequest, "配置文件中缺少server_name标记位") return @@ -235,7 +235,7 @@ func (c *WebsiteController) SaveConfig(ctx http.Context) { port.WriteString(" listen " + v + ";") } } - portConfigOld := helper.Cut(raw, "# port标记位开始", "# port标记位结束") + portConfigOld := tools.Cut(raw, "# port标记位开始", "# port标记位结束") if len(strings.TrimSpace(portConfigOld)) == 0 { Error(ctx, http.StatusBadRequest, "配置文件中缺少port标记位") return @@ -243,7 +243,7 @@ func (c *WebsiteController) SaveConfig(ctx http.Context) { raw = strings.Replace(raw, portConfigOld, "\n"+port.String()+"\n ", -1) // 运行目录 - root := helper.Cut(raw, "# root标记位开始", "# root标记位结束") + root := tools.Cut(raw, "# root标记位开始", "# root标记位结束") if len(strings.TrimSpace(root)) == 0 { Error(ctx, http.StatusBadRequest, "配置文件中缺少root标记位") return @@ -257,7 +257,7 @@ func (c *WebsiteController) SaveConfig(ctx http.Context) { raw = strings.Replace(raw, root, rootNew, -1) // 默认文件 - index := helper.Cut(raw, "# index标记位开始", "# index标记位结束") + index := tools.Cut(raw, "# index标记位开始", "# index标记位结束") if len(strings.TrimSpace(index)) == 0 { Error(ctx, http.StatusBadRequest, "配置文件中缺少index标记位") return @@ -275,10 +275,10 @@ func (c *WebsiteController) SaveConfig(ctx http.Context) { path += "/" } if ctx.Request().InputBool("open_basedir") { - helper.WriteFile(path+".user.ini", "open_basedir="+path+":/tmp/", 0644) + tools.WriteFile(path+".user.ini", "open_basedir="+path+":/tmp/", 0644) } else { - if helper.Exists(path + ".user.ini") { - helper.RemoveFile(path + ".user.ini") + if tools.Exists(path + ".user.ini") { + tools.RemoveFile(path + ".user.ini") } } @@ -296,7 +296,7 @@ func (c *WebsiteController) SaveConfig(ctx http.Context) { waf_cache ` + wafCache + `; ` - wafConfigOld := helper.Cut(raw, "# waf标记位开始", "# waf标记位结束") + wafConfigOld := tools.Cut(raw, "# waf标记位开始", "# waf标记位结束") if len(strings.TrimSpace(wafConfigOld)) != 0 { raw = strings.Replace(raw, wafConfigOld, "", -1) } @@ -306,8 +306,8 @@ func (c *WebsiteController) SaveConfig(ctx http.Context) { ssl := ctx.Request().InputBool("ssl") website.Ssl = ssl if ssl { - helper.WriteFile("/www/server/vhost/ssl/"+website.Name+".pem", ctx.Request().Input("ssl_certificate"), 0644) - helper.WriteFile("/www/server/vhost/ssl/"+website.Name+".key", ctx.Request().Input("ssl_certificate_key"), 0644) + tools.WriteFile("/www/server/vhost/ssl/"+website.Name+".pem", ctx.Request().Input("ssl_certificate"), 0644) + tools.WriteFile("/www/server/vhost/ssl/"+website.Name+".key", ctx.Request().Input("ssl_certificate_key"), 0644) sslConfig := ` # ssl标记位开始 ssl_certificate /www/server/vhost/ssl/` + website.Name + `.pem; @@ -342,13 +342,13 @@ func (c *WebsiteController) SaveConfig(ctx http.Context) { ` } - sslConfigOld := helper.Cut(raw, "# ssl标记位开始", "# ssl标记位结束") + sslConfigOld := tools.Cut(raw, "# ssl标记位开始", "# ssl标记位结束") if len(strings.TrimSpace(sslConfigOld)) != 0 { raw = strings.Replace(raw, sslConfigOld, "", -1) } raw = strings.Replace(raw, "# ssl标记位开始", sslConfig, -1) } else { - sslConfigOld := helper.Cut(raw, "# ssl标记位开始", "# ssl标记位结束") + sslConfigOld := tools.Cut(raw, "# ssl标记位开始", "# ssl标记位结束") if len(strings.TrimSpace(sslConfigOld)) != 0 { raw = strings.Replace(raw, sslConfigOld, "", -1) } @@ -356,7 +356,7 @@ func (c *WebsiteController) SaveConfig(ctx http.Context) { if website.Php != ctx.Request().InputInt("php") { website.Php = ctx.Request().InputInt("php") - phpConfigOld := helper.Cut(raw, "# php标记位开始", "# php标记位结束") + phpConfigOld := tools.Cut(raw, "# php标记位开始", "# php标记位结束") phpConfig := ` include enable-php` + strconv.Itoa(website.Php) + `.conf; @@ -373,9 +373,9 @@ func (c *WebsiteController) SaveConfig(ctx http.Context) { return } - helper.WriteFile("/www/server/vhost/"+website.Name+".conf", raw, 0644) - helper.WriteFile("/www/server/vhost/rewrite/"+website.Name+".conf", ctx.Request().Input("rewrite"), 0644) - helper.ExecShell("systemctl reload openresty") + tools.WriteFile("/www/server/vhost/"+website.Name+".conf", raw, 0644) + tools.WriteFile("/www/server/vhost/rewrite/"+website.Name+".conf", ctx.Request().Input("rewrite"), 0644) + tools.ExecShell("systemctl reload openresty") Success(ctx, nil) } @@ -395,7 +395,7 @@ func (c *WebsiteController) ClearSiteLpg(ctx http.Context) { return } - helper.RemoveFile("/www/wwwlogs/" + website.Name + ".log") + tools.RemoveFile("/www/wwwlogs/" + website.Name + ".log") Success(ctx, nil) } @@ -544,9 +544,9 @@ server `, website.Path, website.Php, website.Name, website.Name, website.Name) - helper.WriteFile("/www/server/vhost/"+website.Name+".conf", raw, 0644) - helper.WriteFile("/www/server/vhost/rewrite"+website.Name+".conf", "", 0644) - helper.ExecShell("systemctl reload openresty") + tools.WriteFile("/www/server/vhost/"+website.Name+".conf", raw, 0644) + tools.WriteFile("/www/server/vhost/rewrite"+website.Name+".conf", "", 0644) + tools.ExecShell("systemctl reload openresty") Success(ctx, nil) } @@ -572,10 +572,10 @@ func (c *WebsiteController) SetStatus(ctx http.Context) { return } - raw := helper.ReadFile("/www/server/vhost/" + website.Name + ".conf") + raw := tools.ReadFile("/www/server/vhost/" + website.Name + ".conf") // 运行目录 - rootConfig := helper.Cut(raw, "# root标记位开始", "# root标记位结束") + rootConfig := tools.Cut(raw, "# root标记位开始", "# root标记位结束") match := regexp.MustCompile(`root\s+(.+);`).FindStringSubmatch(rootConfig) if len(match) == 2 { if website.Status { @@ -587,7 +587,7 @@ func (c *WebsiteController) SetStatus(ctx http.Context) { } // 默认文件 - indexConfig := helper.Cut(raw, "# index标记位开始", "# index标记位结束") + indexConfig := tools.Cut(raw, "# index标记位开始", "# index标记位结束") match = regexp.MustCompile(`index\s+(.+);`).FindStringSubmatch(indexConfig) if len(match) == 2 { if website.Status { @@ -598,8 +598,8 @@ func (c *WebsiteController) SetStatus(ctx http.Context) { } } - helper.WriteFile("/www/server/vhost/"+website.Name+".conf", raw, 0644) - helper.ExecShell("systemctl reload openresty") + tools.WriteFile("/www/server/vhost/"+website.Name+".conf", raw, 0644) + tools.ExecShell("systemctl reload openresty") Success(ctx, nil) } diff --git a/app/models/monitor.go b/app/models/monitor.go index bad0b0a405..42ab1b2f86 100644 --- a/app/models/monitor.go +++ b/app/models/monitor.go @@ -3,12 +3,12 @@ package models import ( "github.com/goravel/framework/support/carbon" - "panel/packages/helper" + "panel/pkg/tools" ) type Monitor struct { - ID uint `gorm:"primaryKey" json:"id"` - Info helper.MonitoringInfo `gorm:"type:json;serializer:json" json:"info"` - CreatedAt carbon.DateTime `gorm:"autoCreateTime;column:created_at" json:"created_at"` - UpdatedAt carbon.DateTime `gorm:"autoUpdateTime;column:updated_at" json:"updated_at"` + ID uint `gorm:"primaryKey" json:"id"` + Info tools.MonitoringInfo `gorm:"type:json;serializer:json" json:"info"` + CreatedAt carbon.DateTime `gorm:"autoCreateTime;column:created_at" json:"created_at"` + UpdatedAt carbon.DateTime `gorm:"autoUpdateTime;column:updated_at" json:"updated_at"` } diff --git a/app/rules/captcha.go b/app/rules/captcha.go index f8637ba582..102f49728b 100644 --- a/app/rules/captcha.go +++ b/app/rules/captcha.go @@ -5,7 +5,7 @@ import ( "github.com/goravel/framework/contracts/validation" - "panel/packages/captcha" + "panel/pkg/captcha" ) type Captcha struct { diff --git a/app/services/backup.go b/app/services/backup.go index d90dae2e50..1acb82cee0 100644 --- a/app/services/backup.go +++ b/app/services/backup.go @@ -8,7 +8,7 @@ import ( "github.com/goravel/framework/support/carbon" "panel/app/models" - "panel/packages/helper" + "panel/pkg/tools" ) type Backup interface { @@ -51,7 +51,7 @@ func (s *BackupImpl) WebsiteList() ([]BackupFile, error) { } backupList = append(backupList, BackupFile{ Name: file.Name(), - Size: helper.FormatBytes(float64(info.Size())), + Size: tools.FormatBytes(float64(info.Size())), }) } @@ -65,12 +65,12 @@ func (s *BackupImpl) WebSiteBackup(website models.Website) error { } backupPath += "/website" - if !helper.Exists(backupPath) { - helper.Mkdir(backupPath, 0644) + if !tools.Exists(backupPath) { + tools.Mkdir(backupPath, 0644) } backupFile := backupPath + "/" + website.Name + carbon.Now().ToShortDateTimeString() + ".zip" - helper.ExecShell("cd " + website.Path + " && zip -r " + backupFile + " .") + tools.ExecShell("cd " + website.Path + " && zip -r " + backupFile + " .") return nil } diff --git a/app/services/cron.go b/app/services/cron.go index 63019df27b..3f2252ffbc 100644 --- a/app/services/cron.go +++ b/app/services/cron.go @@ -2,7 +2,7 @@ package services import ( "panel/app/models" - "panel/packages/helper" + "panel/pkg/tools" ) type Cron interface { @@ -19,22 +19,22 @@ func NewCronImpl() *CronImpl { // AddToSystem 添加到系统 func (r *CronImpl) AddToSystem(cron models.Cron) { - if helper.IsRHEL() { - helper.ExecShell("echo \"" + cron.Time + " " + cron.Shell + " >> " + cron.Log + " 2>&1\" >> /var/spool/cron/root") + if tools.IsRHEL() { + tools.ExecShell("echo \"" + cron.Time + " " + cron.Shell + " >> " + cron.Log + " 2>&1\" >> /var/spool/cron/root") } else { - helper.ExecShell("echo \"" + cron.Time + " " + cron.Shell + " >> " + cron.Log + " 2>&1\" >> /var/spool/cron/crontabs/root") + tools.ExecShell("echo \"" + cron.Time + " " + cron.Shell + " >> " + cron.Log + " 2>&1\" >> /var/spool/cron/crontabs/root") } - helper.ExecShell("systemctl restart crond") + tools.ExecShell("systemctl restart crond") } // DeleteFromSystem 从系统中删除 func (r *CronImpl) DeleteFromSystem(cron models.Cron) { - if helper.IsRHEL() { - helper.ExecShell("sed -i '/" + cron.Shell + "/d' /var/spool/cron/root") + if tools.IsRHEL() { + tools.ExecShell("sed -i '/" + cron.Shell + "/d' /var/spool/cron/root") } else { - helper.ExecShell("sed -i '/" + cron.Shell + "/d' /var/spool/cron/crontabs/root") + tools.ExecShell("sed -i '/" + cron.Shell + "/d' /var/spool/cron/crontabs/root") } - helper.ExecShell("systemctl restart crond") + tools.ExecShell("systemctl restart crond") } diff --git a/app/services/website.go b/app/services/website.go index 4616d501de..61fafd6f15 100644 --- a/app/services/website.go +++ b/app/services/website.go @@ -11,7 +11,7 @@ import ( "golang.org/x/exp/slices" "panel/app/models" - "panel/packages/helper" + "panel/pkg/tools" ) type Website interface { @@ -111,7 +111,7 @@ func (r *WebsiteImpl) Add(website PanelWebsite) (models.Website, error) { return w, err } - helper.Mkdir(website.Path, 0755) + tools.Mkdir(website.Path, 0755) index := ` @@ -128,7 +128,7 @@ func (r *WebsiteImpl) Add(website PanelWebsite) (models.Website, error) { ` - helper.WriteFile(website.Path+"/index.html", index, 0644) + tools.WriteFile(website.Path+"/index.html", index, 0644) domainArr := strings.Split(website.Domain, "\n") portList := "" @@ -218,12 +218,12 @@ server `, portList, domainList, website.Path, website.Php, website.Name, website.Name, website.Name) - helper.WriteFile("/www/server/panel/vhost/openresty/"+website.Name+".conf", nginxConf, 0644) - helper.WriteFile("/www/server/panel/vhost/openresty/rewrite/"+website.Name+".conf", "", 0644) - helper.WriteFile("/www/server/panel/vhost/openresty/ssl/"+website.Name+".pem", "", 0644) - helper.WriteFile("/www/server/panel/vhost/openresty/ssl/"+website.Name+".key", "", 0644) + tools.WriteFile("/www/server/panel/vhost/openresty/"+website.Name+".conf", nginxConf, 0644) + tools.WriteFile("/www/server/panel/vhost/openresty/rewrite/"+website.Name+".conf", "", 0644) + tools.WriteFile("/www/server/panel/vhost/openresty/ssl/"+website.Name+".pem", "", 0644) + tools.WriteFile("/www/server/panel/vhost/openresty/ssl/"+website.Name+".key", "", 0644) - helper.ExecShellAsync("systemctl reload openresty") + tools.ExecShellAsync("systemctl reload openresty") // TODO 创建数据库 @@ -241,13 +241,13 @@ func (r *WebsiteImpl) Delete(id int) error { return err } - helper.RemoveFile("/www/server/panel/vhost/openresty/" + website.Name + ".conf") - helper.RemoveFile("/www/server/panel/vhost/openresty/rewrite/" + website.Name + ".conf") - helper.RemoveFile("/www/server/panel/vhost/openresty/ssl/" + website.Name + ".pem") - helper.RemoveFile("/www/server/panel/vhost/openresty/ssl/" + website.Name + ".key") - helper.RemoveFile(website.Path) + tools.RemoveFile("/www/server/panel/vhost/openresty/" + website.Name + ".conf") + tools.RemoveFile("/www/server/panel/vhost/openresty/rewrite/" + website.Name + ".conf") + tools.RemoveFile("/www/server/panel/vhost/openresty/ssl/" + website.Name + ".pem") + tools.RemoveFile("/www/server/panel/vhost/openresty/ssl/" + website.Name + ".key") + tools.RemoveFile(website.Path) - helper.ExecShellAsync("systemctl reload openresty") + tools.ExecShellAsync("systemctl reload openresty") // TODO 删除数据库 @@ -261,7 +261,7 @@ func (r *WebsiteImpl) GetConfig(id int) (WebsiteSetting, error) { return WebsiteSetting{}, err } - config := helper.ReadFile("/www/server/panel/vhost/openresty/" + website.Name + ".conf") + config := tools.ReadFile("/www/server/panel/vhost/openresty/" + website.Name + ".conf") var setting WebsiteSetting setting.Name = website.Name @@ -270,7 +270,7 @@ func (r *WebsiteImpl) GetConfig(id int) (WebsiteSetting, error) { setting.Php = website.Php setting.Raw = config - ports := helper.Cut(config, "# port标记位开始", "# port标记位结束") + ports := tools.Cut(config, "# port标记位开始", "# port标记位结束") matches := regexp.MustCompile(`listen\s+(.*);`).FindAllStringSubmatch(ports, -1) for _, match := range matches { if len(match) < 2 { @@ -278,24 +278,24 @@ func (r *WebsiteImpl) GetConfig(id int) (WebsiteSetting, error) { } setting.Ports = append(setting.Ports, match[1]) } - serverName := helper.Cut(config, "# server_name标记位开始", "# server_name标记位结束") + serverName := tools.Cut(config, "# server_name标记位开始", "# server_name标记位结束") match := regexp.MustCompile(`server_name\s+(.*);`).FindStringSubmatch(serverName) if len(match) > 1 { setting.Domains = strings.Split(match[1], " ") } - root := helper.Cut(config, "# root标记位开始", "# root标记位结束") + root := tools.Cut(config, "# root标记位开始", "# root标记位结束") match = regexp.MustCompile(`root\s+(.*);`).FindStringSubmatch(root) if len(match) > 1 { setting.Root = match[1] } - index := helper.Cut(config, "# index标记位开始", "# index标记位结束") + index := tools.Cut(config, "# index标记位开始", "# index标记位结束") match = regexp.MustCompile(`index\s+(.*);`).FindStringSubmatch(index) if len(match) > 1 { setting.Index = match[1] } - if helper.Exists(setting.Root + "/.user.ini") { - userIni := helper.ReadFile(setting.Path + "/.user.ini") + if tools.Exists(setting.Root + "/.user.ini") { + userIni := tools.ReadFile(setting.Path + "/.user.ini") if strings.Contains(userIni, "open_basedir") { setting.OpenBasedir = true } else { @@ -306,14 +306,14 @@ func (r *WebsiteImpl) GetConfig(id int) (WebsiteSetting, error) { } if setting.Ssl { - ssl := helper.Cut(config, "# ssl标记位开始", "# ssl标记位结束") + ssl := tools.Cut(config, "# ssl标记位开始", "# ssl标记位结束") match = regexp.MustCompile(`ssl_certificate\s+(.*);`).FindStringSubmatch(ssl) if len(match) > 1 { - setting.SslCertificate = helper.ReadFile(match[1]) + setting.SslCertificate = tools.ReadFile(match[1]) } match = regexp.MustCompile(`ssl_certificate_key\s+(.*);`).FindStringSubmatch(ssl) if len(match) > 1 { - setting.SslCertificateKey = helper.ReadFile(match[1]) + setting.SslCertificateKey = tools.ReadFile(match[1]) } setting.HttpRedirect = strings.Contains(ssl, "# http重定向标记位") setting.Hsts = strings.Contains(ssl, "# hsts标记位") @@ -324,7 +324,7 @@ func (r *WebsiteImpl) GetConfig(id int) (WebsiteSetting, error) { setting.Hsts = false } - waf := helper.Cut(config, "# waf标记位开始", "# waf标记位结束") + waf := tools.Cut(config, "# waf标记位开始", "# waf标记位结束") setting.Waf = strings.Contains(waf, "waf on;") match = regexp.MustCompile(`waf_mode\s+(.+);`).FindStringSubmatch(waf) if len(match) > 1 { @@ -339,8 +339,8 @@ func (r *WebsiteImpl) GetConfig(id int) (WebsiteSetting, error) { setting.WafCache = match[1] } - setting.Rewrite = helper.ReadFile("/www/server/panel/vhost/openresty/rewrite/" + website.Name + ".conf") - setting.Log = helper.ExecShell("tail -n 100 /www/wwwlogs/" + website.Name + ".log") + setting.Rewrite = tools.ReadFile("/www/server/panel/vhost/openresty/rewrite/" + website.Name + ".conf") + setting.Log = tools.ExecShell("tail -n 100 /www/wwwlogs/" + website.Name + ".log") return setting, nil } diff --git a/config/app.go b/config/app.go index 5cbfcf8b31..3ba44ba5bf 100644 --- a/config/app.go +++ b/config/app.go @@ -32,7 +32,7 @@ func init() { // // This value is the name of your application. This value is used when the // framework needs to place the application's name in a notification or - // any other location as required by the application or its packages. + // any other location as required by the application or its pkg. "name": "Panel", // Application Environment diff --git a/config/jwt.go b/config/jwt.go index 46b954087d..e3d6cd1069 100644 --- a/config/jwt.go +++ b/config/jwt.go @@ -10,7 +10,7 @@ func init() { // JWT Authentication Secret // // Don't forget to set this in your panel.conf file, as it will be used to sign - // your tokens. A helper command is provided for this: + // your tokens. A tools command is provided for this: // `go run . artisan jwt:secret` "secret": config.Env("JWT_SECRET", ""), diff --git a/packages/captcha/captcha.go b/pkg/captcha/captcha.go similarity index 100% rename from packages/captcha/captcha.go rename to pkg/captcha/captcha.go diff --git a/packages/captcha/captcha_test.go b/pkg/captcha/captcha_test.go similarity index 100% rename from packages/captcha/captcha_test.go rename to pkg/captcha/captcha_test.go diff --git a/packages/captcha/store_cache.go b/pkg/captcha/store_cache.go similarity index 100% rename from packages/captcha/store_cache.go rename to pkg/captcha/store_cache.go diff --git a/packages/str/str.go b/pkg/str/str.go similarity index 100% rename from packages/str/str.go rename to pkg/str/str.go diff --git a/packages/str/str_test.go b/pkg/str/str_test.go similarity index 100% rename from packages/str/str_test.go rename to pkg/str/str_test.go diff --git a/packages/helper/os.go b/pkg/tools/os.go similarity index 96% rename from packages/helper/os.go rename to pkg/tools/os.go index 6cea4fcb3f..c3f9c5ebff 100644 --- a/packages/helper/os.go +++ b/pkg/tools/os.go @@ -1,4 +1,4 @@ -package helper +package tools import ( "os" diff --git a/packages/helper/os_test.go b/pkg/tools/os_test.go similarity index 96% rename from packages/helper/os_test.go rename to pkg/tools/os_test.go index 888597eeab..1f5a744f6d 100644 --- a/packages/helper/os_test.go +++ b/pkg/tools/os_test.go @@ -1,4 +1,4 @@ -package helper +package tools import ( "testing" diff --git a/packages/helper/string.go b/pkg/tools/string.go similarity index 99% rename from packages/helper/string.go rename to pkg/tools/string.go index 966faab8ee..71d33c09f8 100644 --- a/packages/helper/string.go +++ b/pkg/tools/string.go @@ -1,4 +1,4 @@ -package helper +package tools import ( "crypto/md5" diff --git a/packages/helper/string_test.go b/pkg/tools/string_test.go similarity index 99% rename from packages/helper/string_test.go rename to pkg/tools/string_test.go index 182e73ab27..3a30ac2117 100644 --- a/packages/helper/string_test.go +++ b/pkg/tools/string_test.go @@ -1,4 +1,4 @@ -package helper +package tools import ( "testing" diff --git a/packages/helper/system.go b/pkg/tools/system.go similarity index 99% rename from packages/helper/system.go rename to pkg/tools/system.go index 23ce067da0..1fc55b425e 100644 --- a/packages/helper/system.go +++ b/pkg/tools/system.go @@ -1,4 +1,4 @@ -package helper +package tools import ( "os" diff --git a/packages/helper/system_test.go b/pkg/tools/system_test.go similarity index 99% rename from packages/helper/system_test.go rename to pkg/tools/system_test.go index 6698d79778..80e8692e13 100644 --- a/packages/helper/system_test.go +++ b/pkg/tools/system_test.go @@ -1,4 +1,4 @@ -package helper +package tools import ( "os" diff --git a/packages/helper/helpers.go b/pkg/tools/tools.go similarity index 98% rename from packages/helper/helpers.go rename to pkg/tools/tools.go index 12c4d62c77..67d1ea2ba7 100644 --- a/packages/helper/helpers.go +++ b/pkg/tools/tools.go @@ -1,5 +1,5 @@ -// Package helper 存放辅助方法 -package helper +// Package tools 存放辅助方法 +package tools import ( "errors" diff --git a/packages/helper/helpers_test.go b/pkg/tools/tools_test.go similarity index 94% rename from packages/helper/helpers_test.go rename to pkg/tools/tools_test.go index 702484366f..eceebb1486 100644 --- a/packages/helper/helpers_test.go +++ b/pkg/tools/tools_test.go @@ -1,4 +1,4 @@ -package helper +package tools import ( "testing"