package toolbox import ( "errors" "os/user" "strings" "github.com/1Panel-dev/1Panel/backend/constant" "github.com/1Panel-dev/1Panel/backend/utils/cmd" "github.com/1Panel-dev/1Panel/backend/utils/systemctl" ) type Ftp struct { DefaultUser string } type FtpClient interface { Status() (bool, error) LoadList() ([]FtpList, error) UserAdd(username, path, passwd string) error UserDel(username string) error SetPasswd(username, passwd string) error Reload() error } func NewFtpClient() (*Ftp, error) { userItem, err := user.LookupId("1000") if err == nil { return &Ftp{DefaultUser: userItem.Username}, err } if err.Error() != user.UnknownUserIdError(1000).Error() { return nil, err } groupItem, err := user.LookupGroupId("1000") if err == nil { stdout2, err := cmd.Execf("useradd -u 1000 -g %s %s", groupItem.Name, "1panel") if err != nil { return nil, errors.New(stdout2) } return &Ftp{DefaultUser: "1panel"}, nil } if err.Error() != user.UnknownGroupIdError("1000").Error() { return nil, err } stdout, err := cmd.Exec("groupadd -g 1000 1panel") if err != nil { return nil, errors.New(string(stdout)) } stdout2, err := cmd.Execf("useradd -u 1000 -g %s %s", groupItem.Name, userItem.Username) if err != nil { return nil, errors.New(stdout2) } return &Ftp{DefaultUser: "1panel"}, nil } func (f *Ftp) Status() (bool, error) { return systemctl.IsActive("pure-ftpd.service") } func (f *Ftp) UserAdd(username, passwd, path string) error { std, err := cmd.Execf("pure-pw useradd %s -u %s -d %s <