diff --git a/agent/app/service/app_install.go b/agent/app/service/app_install.go index bd44c7504..52828f22b 100644 --- a/agent/app/service/app_install.go +++ b/agent/app/service/app_install.go @@ -618,10 +618,10 @@ func (a *AppInstallService) DeleteCheck(installID uint) ([]dto.AppResource, erro if err != nil { return nil, err } - app, err := appRepo.GetFirst(commonRepo.WithByID(appInstall.AppId)) - if err != nil { - return nil, err - } + //app, err := appRepo.GetFirst(commonRepo.WithByID(appInstall.AppId)) + //if err != nil { + // return nil, err + //} websites, _ := websiteRepo.GetBy(websiteRepo.WithAppInstallId(appInstall.ID)) for _, website := range websites { res = append(res, dto.AppResource{ @@ -629,25 +629,17 @@ func (a *AppInstallService) DeleteCheck(installID uint) ([]dto.AppResource, erro Name: website.PrimaryDomain, }) } - if app.Key == constant.AppOpenresty { - websites, _ := websiteRepo.GetBy() - for _, website := range websites { - res = append(res, dto.AppResource{ - Type: "website", - Name: website.PrimaryDomain, - }) - } - } - if app.Type == constant.Runtime { - resources, _ := appInstallResourceRepo.GetBy(appInstallResourceRepo.WithLinkId(appInstall.ID), commonRepo.WithByFrom(constant.AppResourceLocal)) - for _, resource := range resources { - linkInstall, _ := appInstallRepo.GetFirst(commonRepo.WithByID(resource.AppInstallId)) - res = append(res, dto.AppResource{ - Type: "app", - Name: linkInstall.Name, - }) - } - } + //TODO 根据运行环境情况处理 + //if app.Type == constant.Runtime { + // resources, _ := appInstallResourceRepo.GetBy(appInstallResourceRepo.WithLinkId(appInstall.ID), commonRepo.WithByFrom(constant.AppResourceLocal)) + // for _, resource := range resources { + // linkInstall, _ := appInstallRepo.GetFirst(commonRepo.WithByID(resource.AppInstallId)) + // res = append(res, dto.AppResource{ + // Type: "app", + // Name: linkInstall.Name, + // }) + // } + //} return res, nil } diff --git a/agent/app/service/app_utils.go b/agent/app/service/app_utils.go index a877b3582..0141506d9 100644 --- a/agent/app/service/app_utils.go +++ b/agent/app/service/app_utils.go @@ -24,7 +24,6 @@ import ( "github.com/docker/docker/api/types" httpUtil "github.com/1Panel-dev/1Panel/agent/utils/http" - "github.com/1Panel-dev/1Panel/agent/utils/xpack" "github.com/docker/docker/api/types/container" "github.com/1Panel-dev/1Panel/agent/utils/cmd" @@ -405,25 +404,26 @@ func deleteAppInstall(deleteReq request.AppInstallDelete) error { switch install.App.Key { case constant.AppOpenresty: - websites, _ := websiteRepo.List() - for _, website := range websites { - if website.AppInstallID > 0 { - websiteAppInstall, _ := appInstallRepo.GetFirst(commonRepo.WithByID(website.AppInstallID)) - if websiteAppInstall.AppId > 0 { - websiteApp, _ := appRepo.GetFirst(commonRepo.WithByID(websiteAppInstall.AppId)) - if websiteApp.Type == constant.RuntimePHP { - go func() { - _, _ = compose.Down(websiteAppInstall.GetComposePath()) - _ = op.DeleteDir(websiteAppInstall.GetPath()) - }() - _ = appInstallRepo.Delete(ctx, websiteAppInstall) - } - } - } - } - _ = websiteRepo.DeleteAll(ctx) - _ = websiteDomainRepo.DeleteAll(ctx) - xpack.RemoveTamper("") + //TODO 删除 Openresty 不再删除网站 + //websites, _ := websiteRepo.List() + //for _, website := range websites { + // if website.AppInstallID > 0 { + // websiteAppInstall, _ := appInstallRepo.GetFirst(commonRepo.WithByID(website.AppInstallID)) + // if websiteAppInstall.AppId > 0 { + // websiteApp, _ := appRepo.GetFirst(commonRepo.WithByID(websiteAppInstall.AppId)) + // if websiteApp.Type == constant.RuntimePHP { + // go func() { + // _, _ = compose.Down(websiteAppInstall.GetComposePath()) + // _ = op.DeleteDir(websiteAppInstall.GetPath()) + // }() + // _ = appInstallRepo.Delete(ctx, websiteAppInstall) + // } + // } + // } + //} + //_ = websiteRepo.DeleteAll(ctx) + //_ = websiteDomainRepo.DeleteAll(ctx) + //xpack.RemoveTamper("") case constant.AppMysql, constant.AppMariaDB: _ = mysqlRepo.Delete(ctx, mysqlRepo.WithByMysqlName(install.Name)) case constant.AppPostgresql: diff --git a/agent/app/service/file.go b/agent/app/service/file.go index 4a1c9ebc8..74abceed5 100644 --- a/agent/app/service/file.go +++ b/agent/app/service/file.go @@ -433,12 +433,7 @@ func (f *FileService) ReadLogByLine(req request.FileReadByLineReq) (*response.Fi if err != nil { return nil, err } - nginx, err := getNginxFull(&website) - if err != nil { - return nil, err - } - sitePath := path.Join(nginx.SiteDir, "sites", website.Alias) - logFilePath = path.Join(sitePath, "log", req.Name) + logFilePath = GetSitePath(website, req.Name) case constant.TypePhp: php, err := runtimeRepo.GetFirst(commonRepo.WithByID(req.ID)) if err != nil { diff --git a/agent/app/service/nginx_utils.go b/agent/app/service/nginx_utils.go index 4d571bb10..0119ea01a 100644 --- a/agent/app/service/nginx_utils.go +++ b/agent/app/service/nginx_utils.go @@ -51,8 +51,7 @@ func getNginxFull(website *model.Website) (dto.NginxFull, error) { if website != nil { nginxFull.Website = *website var siteNginxConfig dto.NginxConfig - nginxFileName := website.Alias + ".conf" - siteConfigPath := path.Join(constant.AppInstallDir, constant.AppOpenresty, nginxInstall.Name, "conf", "conf.d", nginxFileName) + siteConfigPath := GetSitePath(*website, SiteConf) siteNginxConfig.FilePath = siteConfigPath siteNginxContent, err := os.ReadFile(siteConfigPath) if err != nil { diff --git a/agent/app/service/website.go b/agent/app/service/website.go index 54ffc602b..4b277249e 100644 --- a/agent/app/service/website.go +++ b/agent/app/service/website.go @@ -31,20 +31,18 @@ import ( "github.com/1Panel-dev/1Panel/agent/utils/env" "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" + "github.com/1Panel-dev/1Panel/agent/app/dto/request" + "github.com/1Panel-dev/1Panel/agent/app/dto/response" + "github.com/1Panel-dev/1Panel/agent/app/repo" + "github.com/1Panel-dev/1Panel/agent/buserr" "github.com/1Panel-dev/1Panel/agent/cmd/server/nginx_conf" + "github.com/1Panel-dev/1Panel/agent/global" "github.com/1Panel-dev/1Panel/agent/utils/cmd" "github.com/1Panel-dev/1Panel/agent/utils/nginx" "github.com/1Panel-dev/1Panel/agent/utils/nginx/components" "github.com/1Panel-dev/1Panel/agent/utils/nginx/parser" "golang.org/x/crypto/bcrypt" "gopkg.in/ini.v1" - "gorm.io/gorm" - - "github.com/1Panel-dev/1Panel/agent/app/dto/request" - "github.com/1Panel-dev/1Panel/agent/app/dto/response" - "github.com/1Panel-dev/1Panel/agent/app/repo" - "github.com/1Panel-dev/1Panel/agent/buserr" - "github.com/1Panel-dev/1Panel/agent/global" "github.com/1Panel-dev/1Panel/agent/app/dto" "github.com/1Panel-dev/1Panel/agent/app/model" @@ -72,7 +70,7 @@ type IWebsiteService interface { GetNginxConfigByScope(req request.NginxScopeReq) (*response.WebsiteNginxConfig, error) UpdateNginxConfigByScope(req request.NginxConfigUpdate) error - GetWebsiteNginxConfig(websiteId uint, configType string) (response.FileInfo, error) + GetWebsiteNginxConfig(websiteId uint, configType string) (*response.FileInfo, error) UpdateNginxConfigFile(req request.WebsiteNginxUpdate) error GetWebsiteHTTPS(websiteId uint) (response.WebsiteHTTPS, error) OpWebsiteHTTPS(ctx context.Context, req request.WebsiteHTTPSOp) (*response.WebsiteHTTPS, error) @@ -128,13 +126,6 @@ func (w WebsiteService) PageWebsite(req request.WebsiteSearch) (int64, []respons websiteDTOs []response.WebsiteRes opts []repo.DBOption ) - nginxInstall, err := getAppInstallByKey(constant.AppOpenresty) - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - return 0, nil, nil - } - return 0, nil, err - } opts = append(opts, commonRepo.WithOrderRuleBy(req.OrderBy, req.Order)) if req.Name != "" { domains, _ := websiteDomainRepo.GetBy(websiteDomainRepo.WithDomainLike(req.Name)) @@ -179,7 +170,7 @@ func (w WebsiteService) PageWebsite(req request.WebsiteSearch) (int64, []respons runtimeType = runtime.Type appInstallID = runtime.ID } - sitePath := path.Join(constant.AppInstallDir, constant.AppOpenresty, nginxInstall.Name, "www", "sites", web.Alias) + sitePath := GetSitePath(web, SiteDir) siteDTO := response.WebsiteRes{ ID: web.ID, @@ -566,13 +557,10 @@ func (w WebsiteService) GetWebsite(id uint) (response.WebsiteDTO, error) { } res.Website = website - nginxInstall, err := getAppInstallByKey(constant.AppOpenresty) - if err != nil { - return res, err - } - sitePath := path.Join(constant.AppInstallDir, constant.AppOpenresty, nginxInstall.Name, "www", "sites", website.Alias) - res.ErrorLogPath = path.Join(sitePath, "log", "error.log") - res.AccessLogPath = path.Join(sitePath, "log", "access.log") + sitePath := GetSitePath(website, SiteDir) + + res.ErrorLogPath = GetSitePath(website, SiteErrorLog) + res.AccessLogPath = GetSitePath(website, SiteAccessLog) res.SitePath = sitePath res.SiteDir = website.SiteDir return res, nil @@ -893,33 +881,26 @@ func (w WebsiteService) UpdateNginxConfigByScope(req request.NginxConfigUpdate) return updateNginxConfig(constant.NginxScopeServer, params, &website) } -func (w WebsiteService) GetWebsiteNginxConfig(websiteId uint, configType string) (response.FileInfo, error) { - website, err := websiteRepo.GetFirst(commonRepo.WithByID(websiteId)) +func (w WebsiteService) GetWebsiteNginxConfig(websiteID uint, configType string) (*response.FileInfo, error) { + website, err := websiteRepo.GetFirst(commonRepo.WithByID(websiteID)) if err != nil { - return response.FileInfo{}, err + return nil, err } configPath := "" switch configType { case constant.AppOpenresty: - nginxApp, err := appRepo.GetFirst(appRepo.WithKey(constant.AppOpenresty)) - if err != nil { - return response.FileInfo{}, err - } - nginxInstall, err := appInstallRepo.GetFirst(appInstallRepo.WithAppId(nginxApp.ID)) - if err != nil { - return response.FileInfo{}, err - } - configPath = path.Join(nginxInstall.GetPath(), "conf", "conf.d", website.Alias+".conf") + configPath = GetSitePath(website, SiteConf) + //TODO 删除下面的代码 case constant.ConfigFPM: runtimeInstall, err := appInstallRepo.GetFirst(commonRepo.WithByID(website.AppInstallID)) if err != nil { - return response.FileInfo{}, err + return nil, err } configPath = path.Join(runtimeInstall.GetPath(), "conf", "php-fpm.conf") case constant.ConfigPHP: runtimeInstall, err := appInstallRepo.GetFirst(commonRepo.WithByID(website.AppInstallID)) if err != nil { - return response.FileInfo{}, err + return nil, err } configPath = path.Join(runtimeInstall.GetPath(), "conf", "php.ini") } @@ -928,9 +909,9 @@ func (w WebsiteService) GetWebsiteNginxConfig(websiteId uint, configType string) Expand: true, }) if err != nil { - return response.FileInfo{}, err + return nil, err } - return response.FileInfo{FileInfo: *info}, nil + return &response.FileInfo{FileInfo: *info}, nil } func (w WebsiteService) GetWebsiteHTTPS(websiteId uint) (response.WebsiteHTTPS, error) { @@ -1633,12 +1614,8 @@ func (w WebsiteService) UpdateRewriteConfig(req request.NginxRewriteUpdate) erro if err != nil { return err } - nginxFull, err := getNginxFull(&website) - if err != nil { - return err - } - includePath := fmt.Sprintf("/www/sites/%s/rewrite/%s.conf", website.Alias, website.PrimaryDomain) - absolutePath := path.Join(nginxFull.Install.GetPath(), includePath) + includePath := fmt.Sprintf("/www/sites/%s/rewrite/%s.conf", website.Alias, website.Alias) + absolutePath := GetSitePath(website, SiteReWritePath) fileOp := files.NewFileOp() var oldRewriteContent []byte if !fileOp.Stat(path.Dir(absolutePath)) { @@ -1675,11 +1652,7 @@ func (w WebsiteService) GetRewriteConfig(req request.NginxRewriteReq) (*response } var contentByte []byte if req.Name == "current" { - nginxInstall, err := getAppInstallByKey(constant.AppOpenresty) - if err != nil { - return nil, err - } - rewriteConfPath := path.Join(nginxInstall.GetPath(), "www", "sites", website.Alias, "rewrite", fmt.Sprintf("%s.conf", website.PrimaryDomain)) + rewriteConfPath := GetSitePath(website, SiteReWritePath) fileOp := files.NewFileOp() if fileOp.Stat(rewriteConfPath) { contentByte, err = fileOp.GetContent(rewriteConfPath) @@ -1743,42 +1716,44 @@ func (w WebsiteService) UpdateSitePermission(req request.WebsiteUpdateDirPermiss func (w WebsiteService) OperateProxy(req request.WebsiteProxyConfig) (err error) { var ( - website model.Website - params []response.NginxParam - nginxInstall model.AppInstall - par *parser.Parser - oldContent []byte + website model.Website + //params []response.NginxParam + //nginxInstall model.AppInstall + par *parser.Parser + oldContent []byte ) website, err = websiteRepo.GetFirst(commonRepo.WithByID(req.ID)) if err != nil { return } - params, err = getNginxParamsByKeys(constant.NginxScopeHttp, []string{"proxy_cache"}, &website) - if err != nil { - return - } - nginxInstall, err = getAppInstallByKey(constant.AppOpenresty) - if err != nil { - return - } + //params, err = getNginxParamsByKeys(constant.NginxScopeHttp, []string{"proxy_cache"}, &website) + //if err != nil { + // return + //} + //nginxInstall, err = getAppInstallByKey(constant.AppOpenresty) + //if err != nil { + // return + //} fileOp := files.NewFileOp() - if len(params) == 0 || len(params[0].Params) == 0 { - commonDir := path.Join(nginxInstall.GetPath(), "www", "common", "proxy") - proxyTempPath := path.Join(commonDir, "proxy_temp_dir") - if !fileOp.Stat(proxyTempPath) { - _ = fileOp.CreateDir(proxyTempPath, 0755) - } - proxyCacheDir := path.Join(commonDir, "proxy_temp_dir") - if !fileOp.Stat(proxyCacheDir) { - _ = fileOp.CreateDir(proxyCacheDir, 0755) - } - nginxParams := getNginxParamsFromStaticFile(dto.CACHE, nil) - if err = updateNginxConfig(constant.NginxScopeHttp, nginxParams, &website); err != nil { - return - } - } - includeDir := path.Join(nginxInstall.GetPath(), "www", "sites", website.Alias, "proxy") + //TODO 代理缓存改为单独使用配置 + //if len(params) == 0 || len(params[0].Params) == 0 { + // commonDir := path.Join(nginxInstall.GetPath(), "www", "common", "proxy") + // proxyTempPath := path.Join(commonDir, "proxy_temp_dir") + // if !fileOp.Stat(proxyTempPath) { + // _ = fileOp.CreateDir(proxyTempPath, 0755) + // } + // proxyCacheDir := path.Join(commonDir, "proxy_temp_dir") + // if !fileOp.Stat(proxyCacheDir) { + // _ = fileOp.CreateDir(proxyCacheDir, 0755) + // } + // nginxParams := getNginxParamsFromStaticFile(dto.CACHE, nil) + // if err = updateNginxConfig(constant.NginxScopeHttp, nginxParams, &website); err != nil { + // return + // } + //} + + includeDir := GetSitePath(website, SiteProxyDir) if !fileOp.Stat(includeDir) { _ = fileOp.CreateDir(includeDir, 0755) } @@ -1873,19 +1848,14 @@ func (w WebsiteService) OperateProxy(req request.WebsiteProxyConfig) (err error) func (w WebsiteService) GetProxies(id uint) (res []request.WebsiteProxyConfig, err error) { var ( - website model.Website - nginxInstall model.AppInstall - fileList response.FileInfo + website model.Website + fileList response.FileInfo ) website, err = websiteRepo.GetFirst(commonRepo.WithByID(id)) if err != nil { return } - nginxInstall, err = getAppInstallByKey(constant.AppOpenresty) - if err != nil { - return - } - includeDir := path.Join(nginxInstall.GetPath(), "www", "sites", website.Alias, "proxy") + includeDir := GetSitePath(website, SiteProxyDir) fileOp := files.NewFileOp() if !fileOp.Stat(includeDir) { return @@ -2456,20 +2426,15 @@ func (w WebsiteService) GetAntiLeech(id uint) (*response.NginxAntiLeechRes, erro func (w WebsiteService) OperateRedirect(req request.NginxRedirectReq) (err error) { var ( - website model.Website - nginxInstall model.AppInstall - oldContent []byte + website model.Website + oldContent []byte ) website, err = websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID)) if err != nil { return err } - nginxInstall, err = getAppInstallByKey(constant.AppOpenresty) - if err != nil { - return - } - includeDir := path.Join(nginxInstall.GetPath(), "www", "sites", website.Alias, "redirect") + includeDir := GetSitePath(website, SiteRedirectDir) fileOp := files.NewFileOp() if !fileOp.Stat(includeDir) { _ = fileOp.CreateDir(includeDir, 0755) @@ -2610,19 +2575,14 @@ func (w WebsiteService) OperateRedirect(req request.NginxRedirectReq) (err error func (w WebsiteService) GetRedirect(id uint) (res []response.NginxRedirectConfig, err error) { var ( - website model.Website - nginxInstall model.AppInstall - fileList response.FileInfo + website model.Website + fileList response.FileInfo ) website, err = websiteRepo.GetFirst(commonRepo.WithByID(id)) if err != nil { return } - nginxInstall, err = getAppInstallByKey(constant.AppOpenresty) - if err != nil { - return - } - includeDir := path.Join(nginxInstall.GetPath(), "www", "sites", website.Alias, "redirect") + includeDir := GetSitePath(website, SiteRedirectDir) fileOp := files.NewFileOp() if !fileOp.Stat(includeDir) { return @@ -2780,11 +2740,7 @@ func (w WebsiteService) LoadWebsiteDirConfig(req request.WebsiteCommonReq) (*res return nil, err } res := &response.WebsiteDirConfig{} - nginxInstall, err := getAppInstallByKey(constant.AppOpenresty) - if err != nil { - return nil, err - } - absoluteIndexPath := path.Join(nginxInstall.GetPath(), "www", "sites", website.Alias, "index") + absoluteIndexPath := GetSitePath(website, SiteIndexDir) var appFs = afero.NewOsFs() info, err := appFs.Stat(absoluteIndexPath) if err != nil { diff --git a/agent/app/service/website_utils.go b/agent/app/service/website_utils.go index 5b1b5885b..7bd1adf14 100644 --- a/agent/app/service/website_utils.go +++ b/agent/app/service/website_utils.go @@ -541,16 +541,7 @@ func removeSSLListen(website model.Website, binds []string) error { } func createPemFile(website model.Website, websiteSSL model.WebsiteSSL) error { - nginxApp, err := appRepo.GetFirst(appRepo.WithKey(constant.AppOpenresty)) - if err != nil { - return err - } - nginxInstall, err := appInstallRepo.GetFirst(appInstallRepo.WithAppId(nginxApp.ID)) - if err != nil { - return err - } - - configDir := path.Join(constant.AppInstallDir, constant.AppOpenresty, nginxInstall.Name, "www", "sites", website.Alias, "ssl") + configDir := GetSitePath(website, SiteSSLDir) fileOp := files.NewFileOp() if !fileOp.Stat(configDir) { @@ -1160,3 +1151,56 @@ func getResourceContent(fileOp files.FileOp, resourcePath string) (string, error } return "", nil } + +func GetWebSiteRootDir() string { + siteSetting, _ := settingRepo.Get(settingRepo.WithByKey("WEBSITE_DIR")) + dir := siteSetting.Value + if dir == "" { + dir = path.Join(constant.DataDir, "www") + } + return dir +} + +func GteSiteDir(alias string) string { + return path.Join(GetWebSiteRootDir(), "sites", alias) +} + +const ( + SiteConf = "SiteConf" + SiteAccessLog = "access.log" + SiteErrorLog = "error.log" + WebsiteRootDir = "WebsiteRootDir" + SiteDir = "SiteDir" + SiteIndexDir = "SiteIndexDir" + SiteProxyDir = "SiteProxyDir" + SiteSSLDir = "SiteSSLDir" + SiteReWritePath = "SiteReWritePath" + SiteRedirectDir = "SiteRedirectDir" +) + +func GetSitePath(website model.Website, confType string) string { + switch confType { + case SiteConf: + return path.Join(GetWebSiteRootDir(), "conf.d", website.Alias+".conf") + case SiteAccessLog: + return path.Join(GteSiteDir(website.Alias), "log", "access.log") + case SiteErrorLog: + return path.Join(GteSiteDir(website.Alias), "log", "error.log") + case WebsiteRootDir: + return GetWebSiteRootDir() + case SiteDir: + return GteSiteDir(website.Alias) + case SiteIndexDir: + return path.Join(GteSiteDir(website.Alias), "index") + case SiteProxyDir: + return path.Join(GteSiteDir(website.Alias), "proxy") + case SiteSSLDir: + return path.Join(GteSiteDir(website.Alias), "ssl") + case SiteReWritePath: + return path.Join(GteSiteDir(website.Alias), "rewrite", website.Alias+".conf") + case SiteRedirectDir: + return path.Join(GteSiteDir(website.Alias), "redirect") + + } + return "" +} diff --git a/frontend/src/components/app-status/index.vue b/frontend/src/components/app-status/index.vue index c10455595..e3fa0f372 100644 --- a/frontend/src/components/app-status/index.vue +++ b/frontend/src/components/app-status/index.vue @@ -91,29 +91,10 @@ -