From 71f0e5d7cd64553c58eeaad6d5ab79c2b2af1087 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Sat, 22 Jul 2023 17:26:05 +0800 Subject: [PATCH] feat: auto setting website path user --- app/services/website.go | 17 ++++++++++++----- public/panel/views/website/add.html | 8 +------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/services/website.go b/app/services/website.go index a4c70a83..235159ab 100644 --- a/app/services/website.go +++ b/app/services/website.go @@ -128,7 +128,6 @@ func (r *WebsiteImpl) Add(website PanelWebsite) (models.Website, error) {

当您看到此页面,说明您的网站已创建成功。

- ` tools.WriteFile(website.Path+"/index.html", index, 0644) @@ -216,7 +215,6 @@ server access_log /www/wwwlogs/%s.log; error_log /www/wwwlogs/%s.log; } - `, portList, domainList, website.Path, website.Php, website.Name, website.Name, website.Name) tools.WriteFile("/www/server/vhost/"+website.Name+".conf", nginxConf, 0644) @@ -224,9 +222,20 @@ server tools.WriteFile("/www/server/vhost/ssl/"+website.Name+".pem", "", 0644) tools.WriteFile("/www/server/vhost/ssl/"+website.Name+".key", "", 0644) + tools.Chmod(r.setting.Get(models.SettingKeyWebsitePath), 0755) + tools.Chmod(website.Path, 0755) + tools.Chown(r.setting.Get(models.SettingKeyWebsitePath), "www", "www") + tools.Chown(website.Path, "www", "www") + tools.ExecShell("systemctl reload openresty") - // TODO 创建数据库 + rootPassword := r.setting.Get(models.SettingKeyMysqlRootPassword) + if website.Db && website.DbType == "mysql" { + tools.ExecShell("mysql -uroot -p" + rootPassword + " -e \"CREATE DATABASE IF NOT EXISTS " + website.DbName + " DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_general_ci;\"") + tools.ExecShell("mysql -uroot -p" + rootPassword + " -e \"CREATE USER '" + website.DbUser + "'@'localhost' IDENTIFIED BY '" + website.DbPassword + "';\"") + tools.ExecShell("mysql -uroot -p" + rootPassword + " -e \"GRANT ALL PRIVILEGES ON " + website.DbName + ".* TO '" + website.DbUser + "'@'localhost';\"") + tools.ExecShell("mysql -uroot -p" + rootPassword + " -e \"FLUSH PRIVILEGES;\"") + } return w, nil } @@ -250,8 +259,6 @@ func (r *WebsiteImpl) Delete(id int) error { tools.ExecShell("systemctl reload openresty") - // TODO 删除数据库 - return nil } diff --git a/public/panel/views/website/add.html b/public/panel/views/website/add.html index 8594d86b..bf3f71fe 100644 --- a/public/panel/views/website/add.html +++ b/public/panel/views/website/add.html @@ -130,12 +130,7 @@ Date: 2023-06-24 }) // 提交 form.on('submit(add-website-submit)', function (data) { - // 判断db_type是否为空 - if (data.field.db_type === '') { - data.field.db = 0 - } else { - data.field.db = 1 - } + data.field.db = data.field.db_type !== ''; admin.req({ url: '/api/panel/website/add' , type: 'post' @@ -153,7 +148,6 @@ Date: 2023-06-24 , btn: ['确定'] , yes: function (index) { layer.closeAll() - //location.reload(); } }) }