Skip to content

Commit 569aaf3

Browse files
fix: Fix issue where website auth_basic is not effective (#8045)
1 parent c3bd196 commit 569aaf3

File tree

15 files changed

+65
-51
lines changed

15 files changed

+65
-51
lines changed

agent/app/service/website.go

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,21 +1852,15 @@ func (w WebsiteService) ClearProxyCache(req request.NginxCommonReq) error {
18521852

18531853
func (w WebsiteService) GetAuthBasics(req request.NginxAuthReq) (res response.NginxAuthRes, err error) {
18541854
var (
1855-
website model.Website
1856-
nginxInstall model.AppInstall
1857-
authContent []byte
1858-
nginxParams []response.NginxParam
1855+
website model.Website
1856+
authContent []byte
1857+
nginxParams []response.NginxParam
18591858
)
18601859
website, err = websiteRepo.GetFirst(repo.WithByID(req.WebsiteID))
18611860
if err != nil {
18621861
return
18631862
}
1864-
nginxInstall, err = getAppInstallByKey(constant.AppOpenresty)
1865-
if err != nil {
1866-
return
1867-
}
1868-
authPath := fmt.Sprintf("/www/sites/%s/auth_basic/auth.pass", website.Alias)
1869-
absoluteAuthPath := path.Join(nginxInstall.GetPath(), authPath)
1863+
absoluteAuthPath := GetSitePath(website, SiteRootAuthBasicPath)
18701864
fileOp := files.NewFileOp()
18711865
if !fileOp.Stat(absoluteAuthPath) {
18721866
return
@@ -1896,22 +1890,17 @@ func (w WebsiteService) GetAuthBasics(req request.NginxAuthReq) (res response.Ng
18961890

18971891
func (w WebsiteService) UpdateAuthBasic(req request.NginxAuthUpdate) (err error) {
18981892
var (
1899-
website model.Website
1900-
nginxInstall model.AppInstall
1901-
params []dto.NginxParam
1902-
authContent []byte
1903-
authArray []string
1893+
website model.Website
1894+
params []dto.NginxParam
1895+
authContent []byte
1896+
authArray []string
19041897
)
19051898
website, err = websiteRepo.GetFirst(repo.WithByID(req.WebsiteID))
19061899
if err != nil {
19071900
return err
19081901
}
1909-
nginxInstall, err = getAppInstallByKey(constant.AppOpenresty)
1910-
if err != nil {
1911-
return
1912-
}
19131902
authPath := fmt.Sprintf("/www/sites/%s/auth_basic/auth.pass", website.Alias)
1914-
absoluteAuthPath := path.Join(nginxInstall.GetPath(), authPath)
1903+
absoluteAuthPath := GetSitePath(website, SiteRootAuthBasicPath)
19151904
fileOp := files.NewFileOp()
19161905
if !fileOp.Stat(path.Dir(absoluteAuthPath)) {
19171906
_ = fileOp.CreateDir(path.Dir(absoluteAuthPath), constant.DirPerm)
@@ -2025,21 +2014,15 @@ func (w WebsiteService) UpdateAuthBasic(req request.NginxAuthUpdate) (err error)
20252014

20262015
func (w WebsiteService) GetPathAuthBasics(req request.NginxAuthReq) (res []response.NginxPathAuthRes, err error) {
20272016
var (
2028-
website model.Website
2029-
nginxInstall model.AppInstall
2030-
authContent []byte
2017+
website model.Website
2018+
authContent []byte
20312019
)
20322020
website, err = websiteRepo.GetFirst(repo.WithByID(req.WebsiteID))
20332021
if err != nil {
20342022
return
20352023
}
2036-
nginxInstall, err = getAppInstallByKey(constant.AppOpenresty)
2037-
if err != nil {
2038-
return
2039-
}
20402024
fileOp := files.NewFileOp()
2041-
authDir := fmt.Sprintf("/www/sites/%s/path_auth", website.Alias)
2042-
absoluteAuthDir := path.Join(nginxInstall.GetPath(), authDir)
2025+
absoluteAuthDir := GetSitePath(website, SitePathAuthBasicDir)
20432026
passDir := path.Join(absoluteAuthDir, "pass")
20442027
if !fileOp.Stat(absoluteAuthDir) || !fileOp.Stat(passDir) {
20452028
return
@@ -2097,12 +2080,8 @@ func (w WebsiteService) UpdatePathAuthBasic(req request.NginxPathAuthUpdate) err
20972080
if err != nil {
20982081
return err
20992082
}
2100-
nginxInstall, err := getAppInstallByKey(constant.AppOpenresty)
2101-
if err != nil {
2102-
return err
2103-
}
21042083
fileOp := files.NewFileOp()
2105-
authDir := path.Join(nginxInstall.GetPath(), "www", "sites", website.Alias, "path_auth")
2084+
authDir := GetSitePath(website, SitePathAuthBasicDir)
21062085
if !fileOp.Stat(authDir) {
21072086
_ = fileOp.CreateDir(authDir, constant.DirPerm)
21082087
}

agent/app/service/website_utils.go

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,21 +1156,23 @@ func GteSiteDir(alias string) string {
11561156
}
11571157

11581158
const (
1159-
SiteConf = "SiteConf"
1160-
SiteAccessLog = "access.log"
1161-
SiteErrorLog = "error.log"
1162-
WebsiteRootDir = "WebsiteRootDir"
1163-
SiteDir = "SiteDir"
1164-
SiteIndexDir = "SiteIndexDir"
1165-
SiteProxyDir = "SiteProxyDir"
1166-
SiteSSLDir = "SiteSSLDir"
1167-
SiteReWritePath = "SiteReWritePath"
1168-
SiteRedirectDir = "SiteRedirectDir"
1169-
SiteCacheDir = "SiteCacheDir"
1170-
SiteConfDir = "SiteConfDir"
1171-
SitesRootDir = "SitesRootDir"
1172-
DefaultDir = "DefaultDir"
1173-
DefaultRewriteDir = "DefaultRewriteDir"
1159+
SiteConf = "SiteConf"
1160+
SiteAccessLog = "access.log"
1161+
SiteErrorLog = "error.log"
1162+
WebsiteRootDir = "WebsiteRootDir"
1163+
SiteDir = "SiteDir"
1164+
SiteIndexDir = "SiteIndexDir"
1165+
SiteProxyDir = "SiteProxyDir"
1166+
SiteSSLDir = "SiteSSLDir"
1167+
SiteReWritePath = "SiteReWritePath"
1168+
SiteRedirectDir = "SiteRedirectDir"
1169+
SiteCacheDir = "SiteCacheDir"
1170+
SiteConfDir = "SiteConfDir"
1171+
SitesRootDir = "SitesRootDir"
1172+
DefaultDir = "DefaultDir"
1173+
DefaultRewriteDir = "DefaultRewriteDir"
1174+
SiteRootAuthBasicPath = "SiteRootAuthBasicPath"
1175+
SitePathAuthBasicDir = "SitePathAuthBasicDir"
11741176
)
11751177

11761178
func GetSitePath(website model.Website, confType string) string {
@@ -1195,6 +1197,10 @@ func GetSitePath(website model.Website, confType string) string {
11951197
return path.Join(GteSiteDir(website.Alias), "rewrite", website.Alias+".conf")
11961198
case SiteRedirectDir:
11971199
return path.Join(GteSiteDir(website.Alias), "redirect")
1200+
case SiteRootAuthBasicPath:
1201+
return path.Join(GteSiteDir(website.Alias), "auth_basic", "auth.pass")
1202+
case SitePathAuthBasicDir:
1203+
return path.Join(GteSiteDir(website.Alias), "path_auth")
11981204
}
11991205
return ""
12001206
}

agent/i18n/lang/en.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ ErrStructTransform: "Type conversion failure: {{ .detail }}"
66
ErrNotSupportType: "The system does not support the current type: {{ .detail }}"
77

88
#common
9+
ErrUsernameIsExist: "Username already exists"
910
ErrNameIsExist: "Name is already exist"
1011
ErrDemoEnvironment: "Demo server, prohibit this operation!"
1112
ErrCmdTimeout: "Command execution timed out!"

agent/i18n/lang/ja.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ErrApiConfigIPInvalid: "APIインターフェイスIPはホワイトリストに
1414
ErrApiConfigDisable: "このインターフェイスは、APIインターフェイスコールの使用を禁止しています:{{.Detail}}"
1515

1616
#common
17+
ErrUsernameIsExist: "ユーザー名は既に存在します"
1718
ErrNameIsExist: "名前はすでに存在しています"
1819
ErrDemoEnvironment: "デモサーバー、この操作を禁止します!"
1920
ErrCmdTimeout: "コマンド実行がタイムアウトしました!"

agent/i18n/lang/ko.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ErrApiConfigDisable: "이 인터페이스는 API 호출을 금지합니다: {{ .
1515
ErrApiConfigKeyTimeInvalid: "API 인터페이스 타임스탬프 오류: {{ .detail }}"
1616

1717
# 공통
18+
ErrUsernameIsExist: "사용자 이름이 이미 존재합니다"
1819
ErrNameIsExist: "이름이 이미 존재합니다"
1920
ErrDemoEnvironment: "데모 서버에서는 이 작업이 금지되어 있습니다!"
2021
ErrCmdTimeout: "명령어 실행 시간이 초과되었습니다!"

agent/i18n/lang/ms.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ErrApiConfigDisable: "Antara muka ini melarang penggunaan panggilan API: {{ .det
1515
ErrApiConfigKeyTimeInvalid: "Ralat cap waktu antara muka API: {{ .detail }}"
1616

1717
#common
18+
ErrUsernameIsExist: "Nama pengguna sudah wujud"
1819
ErrNameIsExist: "Nama sudah wujud"
1920
ErrDemoEnvironment: "Pelayan demo, operasi ini dilarang!"
2021
ErrCmdTimeout: "Pelaksanaan arahan telah tamat masa!"

agent/i18n/lang/pt-BR.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ErrApiConfigIPInvalid: "O IP da interface da API não está na lista de permiss
1414
ErrApiConfigDisable: "Esta interface proíbe o uso de chamadas de API: {{ .detail }}"
1515

1616
#common
17+
ErrUsernameIsExist: "Nome de usuário já existe"
1718
ErrNameIsExist: "O nome já existe"
1819
ErrDemoEnvironment: "Servidor de demonstração, operação proibida!"
1920
ErrCmdTimeout: "Tempo limite de execução do comando excedido!"

agent/i18n/lang/ru.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ErrApiConfigDisable: "Этот интерфейс запрещает испол
1515
ErrApiConfigKeyTimeInvalid: "Ошибка временной метки интерфейса API: {{ .detail }}"
1616

1717
#common
18+
ErrUsernameIsExist: "Имя пользователя уже существует"
1819
ErrNameIsExist: "Имя уже существует"
1920
ErrDemoEnvironment: "Демо-сервер, операция запрещена!"
2021
ErrCmdTimeout: "Время выполнения команды истекло!"

agent/i18n/lang/zh-Hant.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ ErrApiConfigIPInvalid: "调用 API 接口 IP 不在白名单: {{ .detail }}"
1010
ErrApiConfigDisable: "此接口禁止使用 API 接口調用: {{ .detail }}"
1111

1212
#common
13+
ErrUsernameIsExist: "使用者名稱已存在"
1314
ErrNameIsExist: "名稱已存在"
1415
ErrDemoEnvironment: "演示伺服器,禁止此操作!"
1516
ErrCmdTimeout: "指令執行超時!"

agent/i18n/lang/zh.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ ErrApiConfigDisable: "此接口禁止使用 API 接口调用: {{ .detail }}"
1616
ErrApiConfigKeyTimeInvalid: "API 接口时间戳错误: {{ .detail }}"
1717

1818
#common
19+
ErrUsernameIsExist: "用户名已存在"
1920
ErrNameIsExist: "名称已存在"
2021
ErrDemoEnvironment: "演示服务器,禁止此操作!"
2122
ErrCmdTimeout: "命令执行超时!"

0 commit comments

Comments
 (0)