Skip to content

Commit c7b6e15

Browse files
feat(website): fix issues with create website with ftp failed (#8272)
1 parent 5ee392b commit c7b6e15

11 files changed

Lines changed: 75 additions & 48 deletions

File tree

agent/app/service/app_install.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,12 @@ func (a *AppInstallService) Operate(req request.AppInstalledOperate) error {
264264
}
265265
return syncAppInstallStatus(&install, false)
266266
case constant.Restart:
267+
if install.App.Key == "openresty" {
268+
websites, _ := websiteRepo.GetBy()
269+
if len(websites) > 0 {
270+
_ = createAllWebsitesWAFConfig(websites)
271+
}
272+
}
267273
out, err := compose.Restart(dockerComposePath)
268274
if err != nil {
269275
return handleErr(install, err, out)

agent/app/service/runtime_utils.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -331,20 +331,25 @@ func buildRuntime(runtime *model.Runtime, oldImageID string, oldEnv string, rebu
331331
if out, err := compose.Up(composePath); err != nil {
332332
runtime.Status = constant.StatusStartErr
333333
runtime.Message = out
334-
} else {
335-
extensions := getRuntimeEnv(runtime.Env, "PHP_EXTENSIONS")
336-
if extensions != "" {
337-
installCmd := fmt.Sprintf("docker exec -i %s %s %s", runtime.ContainerName, "install-ext", extensions)
338-
err = cmd2.ExecWithLogFile(installCmd, 60*time.Minute, logPath)
339-
if err != nil {
340-
runtime.Status = constant.StatusError
341-
runtime.Message = buserr.New("ErrImageBuildErr").Error() + ":" + err.Error()
342-
_ = runtimeRepo.Save(runtime)
343-
return
344-
}
334+
_ = runtimeRepo.Save(runtime)
335+
}
336+
extensions := getRuntimeEnv(runtime.Env, "PHP_EXTENSIONS")
337+
if extensions != "" {
338+
installCmd := fmt.Sprintf("docker exec -i %s %s %s", runtime.ContainerName, "install-ext", extensions)
339+
err = cmd2.ExecWithLogFile(installCmd, 60*time.Minute, logPath)
340+
if err != nil {
341+
runtime.Status = constant.StatusError
342+
runtime.Message = buserr.New("ErrImageBuildErr").Error() + ":" + err.Error()
343+
_ = runtimeRepo.Save(runtime)
344+
return
345345
}
346-
runtime.Status = constant.StatusRunning
347346
}
347+
if out, err := compose.DownAndUp(composePath); err != nil {
348+
runtime.Status = constant.StatusStartErr
349+
runtime.Message = out
350+
_ = runtimeRepo.Save(runtime)
351+
}
352+
runtime.Status = constant.StatusRunning
348353
}
349354
_ = runtimeRepo.Save(runtime)
350355
}

agent/app/service/website.go

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -410,26 +410,6 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error)
410410
website.ParentWebsiteID = parentWebsite.ID
411411
}
412412

413-
if len(create.FtpUser) != 0 && len(create.FtpPassword) != 0 {
414-
createFtpUser := func(t *task.Task) error {
415-
indexDir := GetSitePath(*website, SiteIndexDir)
416-
itemID, err := NewIFtpService().Create(dto.FtpCreate{User: create.FtpUser, Password: create.FtpPassword, Path: indexDir})
417-
if err != nil {
418-
createTask.Log(fmt.Sprintf("create ftp for website failed, err: %v", err))
419-
}
420-
website.FtpID = itemID
421-
return nil
422-
}
423-
deleteFtpUser := func(t *task.Task) {
424-
if website.FtpID > 0 {
425-
if err = NewIFtpService().Delete(dto.BatchDeleteReq{Ids: []uint{website.FtpID}}); err != nil {
426-
createTask.Log(err.Error())
427-
}
428-
}
429-
}
430-
createTask.AddSubTask(i18n.GetWithName("ConfigFTP", create.FtpUser), createFtpUser, deleteFtpUser)
431-
}
432-
433413
configNginx := func(t *task.Task) error {
434414
if err = configDefaultNginx(website, domains, appInstall, runtime); err != nil {
435415
return err
@@ -488,6 +468,19 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error)
488468
createTask.AddSubTaskWithIgnoreErr(i18n.GetMsgByKey("EnableSSL"), enableSSL)
489469
}
490470

471+
if len(create.FtpUser) != 0 && len(create.FtpPassword) != 0 {
472+
createFtpUser := func(t *task.Task) error {
473+
indexDir := GetSitePath(*website, SiteIndexDir)
474+
itemID, err := NewIFtpService().Create(dto.FtpCreate{User: create.FtpUser, Password: create.FtpPassword, Path: indexDir})
475+
if err != nil {
476+
return err
477+
}
478+
website.FtpID = itemID
479+
return nil
480+
}
481+
createTask.AddSubTaskWithIgnoreErr(i18n.GetWithName("ConfigFTP", create.FtpUser), createFtpUser)
482+
}
483+
491484
return createTask.Execute()
492485
}
493486

@@ -2061,7 +2054,7 @@ func (w WebsiteService) GetPathAuthBasics(req request.NginxAuthReq) (res []respo
20612054
}
20622055
directives := config.Directives
20632056
location, _ := directives[0].(*components.Location)
2064-
pathAuth.Path = location.Match
2057+
pathAuth.Path = strings.TrimPrefix(location.Match, "^")
20652058
passPath := path.Join(passDir, fmt.Sprintf("%s.pass", name))
20662059
authContent, err = fileOp.GetContent(passPath)
20672060
if err != nil {
@@ -2130,7 +2123,7 @@ func (w WebsiteService) UpdatePathAuthBasic(req request.NginxPathAuthUpdate) err
21302123
directives := config.Directives
21312124
location, _ := directives[0].(*components.Location)
21322125
location.UpdateDirective("auth_basic_user_file", []string{fmt.Sprintf("/www/sites/%s/path_auth/pass/%s", website.Alias, fmt.Sprintf("%s.pass", req.Name))})
2133-
location.ChangePath("~*", req.Path)
2126+
location.ChangePath("~*", fmt.Sprintf("^%s", req.Path))
21342127
var passwdHash []byte
21352128
passwdHash, err = bcrypt.GenerateFromPassword([]byte(req.Password), bcrypt.DefaultCost)
21362129
if err != nil {

agent/server/server.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ import (
2626
"github.com/1Panel-dev/1Panel/agent/init/viper"
2727
"github.com/1Panel-dev/1Panel/agent/utils/encrypt"
2828

29-
_ "net/http/pprof"
30-
3129
"github.com/gin-gonic/gin"
3230
)
3331

agent/utils/nginx/dumper.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ func DumpBlock(b components.IBlock, style *Style, startLine int) string {
9090
}
9191

9292
directives := b.GetDirectives()
93+
94+
var sortDirectives []components.IDirective
95+
var proxyIncludes []components.IDirective
96+
for _, directive := range directives {
97+
if directive.GetName() == "include" && strings.Contains(strings.Join(directive.GetParameters(), " "), "/proxy/") {
98+
proxyIncludes = append(proxyIncludes, directive)
99+
} else {
100+
sortDirectives = append(sortDirectives, directive)
101+
}
102+
}
103+
directives = append(sortDirectives, proxyIncludes...)
104+
93105
for i, directive := range directives {
94106

95107
if directive.GetLine() > line {

core/app/service/setting.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,19 +517,19 @@ func (u *SettingService) GenerateApiKey() (string, error) {
517517
}
518518

519519
func (u *SettingService) UpdateApiConfig(req dto.ApiInterfaceConfig) error {
520-
if err := settingRepo.Update("ApiInterfaceStatus", req.ApiInterfaceStatus); err != nil {
520+
if err := settingRepo.UpdateOrCreate("ApiInterfaceStatus", req.ApiInterfaceStatus); err != nil {
521521
return err
522522
}
523523
global.Api.ApiInterfaceStatus = req.ApiInterfaceStatus
524-
if err := settingRepo.Update("ApiKey", req.ApiKey); err != nil {
524+
if err := settingRepo.UpdateOrCreate("ApiKey", req.ApiKey); err != nil {
525525
return err
526526
}
527527
global.Api.ApiKey = req.ApiKey
528-
if err := settingRepo.Update("IpWhiteList", req.IpWhiteList); err != nil {
528+
if err := settingRepo.UpdateOrCreate("IpWhiteList", req.IpWhiteList); err != nil {
529529
return err
530530
}
531531
global.Api.IpWhiteList = req.IpWhiteList
532-
if err := settingRepo.Update("ApiKeyValidityTime", req.ApiKeyValidityTime); err != nil {
532+
if err := settingRepo.UpdateOrCreate("ApiKeyValidityTime", req.ApiKeyValidityTime); err != nil {
533533
return err
534534
}
535535
global.Api.ApiKeyValidityTime = req.ApiKeyValidityTime

core/init/router/proxy.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ func Proxy() gin.HandlerFunc {
4444
currentNode = c.Request.Header.Get("CurrentNode")
4545
}
4646

47-
if strings.HasPrefix(c.Request.URL.Path, "/api/v2/") && !checkSession(c) {
47+
apiReq := c.GetBool("API_AUTH")
48+
49+
if !apiReq && strings.HasPrefix(c.Request.URL.Path, "/api/v2/") && !checkSession(c) {
4850
data, _ := res.ErrorMsg.ReadFile("html/401.html")
4951
c.Data(401, "text/html; charset=utf-8", data)
5052
c.Abort()

core/middleware/api_auth.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func ApiAuth() gin.HandlerFunc {
3939
helper.BadAuth(c, "ErrApiConfigIPInvalid", nil)
4040
return
4141
}
42+
c.Set("API_AUTH", true)
4243
c.Next()
4344
return
4445
} else {

frontend/src/global/mimetype.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,6 @@ export const Algorithms = [
355355
value: 'least_conn',
356356
placeHolder: i18n.global.t('website.leastConnHelper'),
357357
},
358-
{
359-
label: i18n.global.t('website.leastTime'),
360-
value: 'least_time',
361-
placeHolder: i18n.global.t('website.leastTimeHelper'),
362-
},
363358
];
364359

365360
export const StatusStrategy = [

frontend/src/views/website/website/config/basic/auth-basic/index.vue

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/>
2626
</ComplexTable>
2727
</el-tab-pane>
28-
<el-tab-pane :label="$t('website.path')">
28+
<el-tab-pane :label="$t('website.path')" v-if="showPath">
2929
<ComplexTable :data="pathData" @search="searchPath" v-loading="loading" :heightDiff="420">
3030
<template #toolbar>
3131
<el-button type="primary" plain @click="openCreate('path')">
@@ -54,7 +54,13 @@
5454

5555
<script lang="ts" setup name="proxy">
5656
import { Website } from '@/api/interface/website';
57-
import { operateAuthConfig, getAuthConfig, getPathAuthConfig, operatePathAuthConfig } from '@/api/modules/website';
57+
import {
58+
operateAuthConfig,
59+
getAuthConfig,
60+
getPathAuthConfig,
61+
operatePathAuthConfig,
62+
getWebsite,
63+
} from '@/api/modules/website';
5864
import { computed, onMounted, ref } from 'vue';
5965
import i18n from '@/lang';
6066
import Create from './create/index.vue';
@@ -80,6 +86,7 @@ const createRef = ref();
8086
const enable = ref(false);
8187
const opRef = ref();
8288
const pathData = ref([]);
89+
const showPath = ref(false);
8390
8491
const buttons = [
8592
{
@@ -207,7 +214,14 @@ const searchAll = () => {
207214
searchPath();
208215
};
209216
217+
const getSiteDetail = async () => {
218+
getWebsite(id.value).then(async (res) => {
219+
showPath.value = res.data.type !== 'proxy' && res.data.type !== 'deployment';
220+
});
221+
};
222+
210223
onMounted(() => {
224+
getSiteDetail();
211225
searchAll();
212226
});
213227
</script>

0 commit comments

Comments
 (0)