1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 08:19:15 +08:00

fix: 解决 FTP 状态同步失败的问题 (#5224)

This commit is contained in:
ssongliu 2024-05-30 17:11:16 +08:00 committed by GitHub
parent 60dbd75ce2
commit bd91c88357
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 13 deletions

View File

@ -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 {

View File

@ -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,7 +153,17 @@ 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
}
@ -160,6 +171,7 @@ func (f *Ftp) LoadList() ([]FtpList, error) {
type FtpList struct {
User string
Path string
Status string
}
func (f *Ftp) Reload() error {

View File

@ -122,12 +122,11 @@
<Tooltip @click="toFolder(row.path)" :text="row.path" />
</template>
</el-table-column>
<el-table-column
:label="$t('commons.table.description')"
:min-width="80"
prop="description"
show-overflow-tooltip
/>
<el-table-column :label="$t('commons.table.description')" prop="description">
<template #default="{ row }">
<fu-input-rw-switch v-model="row.description" @blur="onChange(row)" />
</template>
</el-table-column>
<fu-table-operations
width="200px"
:buttons="buttons"
@ -270,6 +269,11 @@ const onChangeStatus = async (row: Toolbox.FtpInfo, status: string) => {
});
};
const onChange = async (row: any) => {
await await updateFtp(row);
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
};
const onOpenDialog = async (title: string, rowData: Partial<Toolbox.FtpInfo> = {}) => {
let params = {
title,