feat: import Sea vHost single-server testing release

This commit is contained in:
canglan committed 2026-10-30 08:39:10 +08:00
commit 248badd33e
441 files changed
+63221

No files matched your search

+63
View File
@@ -0,0 +1,63 @@
package isolation
import (
"context"
"errors"
"io"
"os"
"path/filepath"
"strings"
)
// The panel's disabled state still permits 127.0.0.1. A suspended host must
// also reject local FTP clients; normal TCP peers cannot originate at 0.0.0.0.
// The panel's enable operation clears this source restriction on recovery.
func (a Agent) freezeFTPLogin(ctx context.Context, username string) error {
binary := a.PurePWBinary
if binary == "" {
binary = "/www/server/pure-ftpd/bin/pure-pw"
}
if !filepath.IsAbs(binary) || filepath.Base(binary) != "pure-pw" || !safeName.MatchString(username) {
return errors.New("invalid FTP freeze identity")
}
directory := filepath.Join(filepath.Dir(filepath.Dir(binary)), "etc")
if a.PureFTPConfig != "" {
directory = filepath.Dir(a.PureFTPConfig)
}
if _, err := os.Lstat(directory); errors.Is(err, os.ErrNotExist) {
return nil
}
if err := requirePhysicalDirectory(directory); err != nil {
return err
}
root, err := os.OpenRoot(directory)
if err != nil {
return err
}
defer root.Close()
info, err := root.Lstat("pureftpd.passwd")
if errors.Is(err, os.ErrNotExist) {
return nil
}
if err != nil || !info.Mode().IsRegular() || info.Size() > 16<<20 {
return errors.New("unsafe FTP account database")
}
file, err := root.Open("pureftpd.passwd")
if err != nil {
return err
}
defer file.Close()
data, err := io.ReadAll(io.LimitReader(file, (16<<20)+1))
if err != nil {
return err
}
if len(data) > 16<<20 {
return errors.New("FTP account database exceeds limit")
}
for _, line := range strings.Split(string(data), "\n") {
if strings.HasPrefix(line, username+":") {
return a.command(ctx, binary, "usermod", username, "-r", "0.0.0.0", "-m")
}
}
return nil
}