From bd91c883576c86b1f7935517cab4bd65c4992778 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Thu, 30 May 2024 17:11:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=20FTP=20=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E5=90=8C=E6=AD=A5=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20(#5224)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/ftp.go | 8 ++++---- backend/utils/toolbox/pure-ftpd.go | 18 +++++++++++++++--- frontend/src/views/toolbox/ftp/index.vue | 16 ++++++++++------ 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/backend/app/service/ftp.go b/backend/app/service/ftp.go index 22664b920..c41f1065f 100644 --- a/backend/app/service/ftp.go +++ b/backend/app/service/ftp.go @@ -104,8 +104,8 @@ func (f *FtpService) Sync() error { for _, itemInDB := range listsInDB { if item.User == itemInDB.User { sameData[item.User] = struct{}{} - if item.Path != itemInDB.Path { - _ = ftpRepo.Update(itemInDB.ID, map[string]interface{}{"path": item.Path, "status": constant.StatusDisable}) + if item.Path != itemInDB.Path || item.Status != itemInDB.Status { + _ = ftpRepo.Update(itemInDB.ID, map[string]interface{}{"path": item.Path, "status": item.Status}) } break } @@ -113,7 +113,7 @@ func (f *FtpService) Sync() error { } for _, item := range lists { if _, ok := sameData[item.User]; !ok { - _ = ftpRepo.Create(&model.Ftp{User: item.User, Path: item.Path, Status: constant.StatusDisable}) + _ = ftpRepo.Create(&model.Ftp{User: item.User, Path: item.Path, Status: item.Status}) } } for _, item := range listsInDB { @@ -127,7 +127,7 @@ func (f *FtpService) Sync() error { func (f *FtpService) Create(req dto.FtpCreate) (uint, error) { if _, err := os.Stat(req.Path); err != nil { if os.IsNotExist(err) { - if err := os.MkdirAll(req.Path, os.ModePerm); err != nil { + if err := os.MkdirAll(req.Path, os.ModePerm); err != nil { return 0, err } } else { diff --git a/backend/utils/toolbox/pure-ftpd.go b/backend/utils/toolbox/pure-ftpd.go index cbfc22af9..e4a1038dd 100644 --- a/backend/utils/toolbox/pure-ftpd.go +++ b/backend/utils/toolbox/pure-ftpd.go @@ -11,6 +11,7 @@ import ( "time" "github.com/1Panel-dev/1Panel/backend/constant" + "github.com/1Panel-dev/1Panel/backend/global" "github.com/1Panel-dev/1Panel/backend/utils/cmd" "github.com/1Panel-dev/1Panel/backend/utils/systemctl" ) @@ -152,14 +153,25 @@ func (f *Ftp) LoadList() ([]FtpList, error) { if len(parts) < 2 { continue } - lists = append(lists, FtpList{User: parts[0], Path: strings.ReplaceAll(parts[1], "/./", "")}) + std2, err := cmd.Execf("pure-pw show %s | grep 'Allowed client IPs :'", parts[0]) + if err != nil { + global.LOG.Errorf("handle pure-pw show %s faile, err: %v", parts[0], std2) + continue + } + status := constant.StatusDisable + itemStd := strings.ReplaceAll(std2, "\n", "") + if len(strings.TrimSpace(strings.ReplaceAll(itemStd, "Allowed client IPs :", ""))) == 0 { + status = constant.StatusEnable + } + lists = append(lists, FtpList{User: parts[0], Path: strings.ReplaceAll(parts[1], "/./", ""), Status: status}) } return lists, nil } type FtpList struct { - User string - Path string + User string + Path string + Status string } func (f *Ftp) Reload() error { diff --git a/frontend/src/views/toolbox/ftp/index.vue b/frontend/src/views/toolbox/ftp/index.vue index b9eda33d1..3b28e5a48 100644 --- a/frontend/src/views/toolbox/ftp/index.vue +++ b/frontend/src/views/toolbox/ftp/index.vue @@ -122,12 +122,11 @@ - + + + { }); }; +const onChange = async (row: any) => { + await await updateFtp(row); + MsgSuccess(i18n.global.t('commons.msg.operationSuccess')); +}; + const onOpenDialog = async (title: string, rowData: Partial = {}) => { let params = { title,