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:
parent
60dbd75ce2
commit
bd91c88357
@ -104,8 +104,8 @@ func (f *FtpService) Sync() error {
|
|||||||
for _, itemInDB := range listsInDB {
|
for _, itemInDB := range listsInDB {
|
||||||
if item.User == itemInDB.User {
|
if item.User == itemInDB.User {
|
||||||
sameData[item.User] = struct{}{}
|
sameData[item.User] = struct{}{}
|
||||||
if item.Path != itemInDB.Path {
|
if item.Path != itemInDB.Path || item.Status != itemInDB.Status {
|
||||||
_ = ftpRepo.Update(itemInDB.ID, map[string]interface{}{"path": item.Path, "status": constant.StatusDisable})
|
_ = ftpRepo.Update(itemInDB.ID, map[string]interface{}{"path": item.Path, "status": item.Status})
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -113,7 +113,7 @@ func (f *FtpService) Sync() error {
|
|||||||
}
|
}
|
||||||
for _, item := range lists {
|
for _, item := range lists {
|
||||||
if _, ok := sameData[item.User]; !ok {
|
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 {
|
for _, item := range listsInDB {
|
||||||
@ -127,7 +127,7 @@ func (f *FtpService) Sync() error {
|
|||||||
func (f *FtpService) Create(req dto.FtpCreate) (uint, error) {
|
func (f *FtpService) Create(req dto.FtpCreate) (uint, error) {
|
||||||
if _, err := os.Stat(req.Path); err != nil {
|
if _, err := os.Stat(req.Path); err != nil {
|
||||||
if os.IsNotExist(err) {
|
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
|
return 0, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/backend/constant"
|
"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/cmd"
|
||||||
"github.com/1Panel-dev/1Panel/backend/utils/systemctl"
|
"github.com/1Panel-dev/1Panel/backend/utils/systemctl"
|
||||||
)
|
)
|
||||||
@ -152,14 +153,25 @@ func (f *Ftp) LoadList() ([]FtpList, error) {
|
|||||||
if len(parts) < 2 {
|
if len(parts) < 2 {
|
||||||
continue
|
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
|
return lists, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type FtpList struct {
|
type FtpList struct {
|
||||||
User string
|
User string
|
||||||
Path string
|
Path string
|
||||||
|
Status string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Ftp) Reload() error {
|
func (f *Ftp) Reload() error {
|
||||||
|
@ -122,12 +122,11 @@
|
|||||||
<Tooltip @click="toFolder(row.path)" :text="row.path" />
|
<Tooltip @click="toFolder(row.path)" :text="row.path" />
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column
|
<el-table-column :label="$t('commons.table.description')" prop="description">
|
||||||
:label="$t('commons.table.description')"
|
<template #default="{ row }">
|
||||||
:min-width="80"
|
<fu-input-rw-switch v-model="row.description" @blur="onChange(row)" />
|
||||||
prop="description"
|
</template>
|
||||||
show-overflow-tooltip
|
</el-table-column>
|
||||||
/>
|
|
||||||
<fu-table-operations
|
<fu-table-operations
|
||||||
width="200px"
|
width="200px"
|
||||||
:buttons="buttons"
|
: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> = {}) => {
|
const onOpenDialog = async (title: string, rowData: Partial<Toolbox.FtpInfo> = {}) => {
|
||||||
let params = {
|
let params = {
|
||||||
title,
|
title,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user