feat: import Sea vHost single-server testing release
This commit is contained in:
commit
248badd33e
441 files changed
+63221
No files matched your search
@@ -0,0 +1,43 @@
|
||||
package isolation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (a Agent) configureFTPIdentity(w http.ResponseWriter, r *http.Request) {
|
||||
var spec FTPIdentitySpec
|
||||
decoder := json.NewDecoder(r.Body)
|
||||
decoder.DisallowUnknownFields()
|
||||
if err := decoder.Decode(&spec); err != nil || decoder.Decode(&struct{}{}) != io.EOF ||
|
||||
!safeName.MatchString(spec.Project.HostName) || spec.Username != spec.Project.HostName ||
|
||||
spec.Project.TenantID == 0 || spec.Project.StorageBytes == 0 || spec.Project.ProcessLimit == 0 {
|
||||
http.Error(w, "invalid request", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
projectRoot, err := a.projectPath(spec.Project)
|
||||
if err != nil || requirePhysicalDirectory(projectRoot) != nil {
|
||||
http.Error(w, "project root unavailable", http.StatusPreconditionFailed)
|
||||
return
|
||||
}
|
||||
binary := strings.TrimSpace(a.PurePWBinary)
|
||||
if binary == "" {
|
||||
binary = "/www/server/pure-ftpd/bin/pure-pw"
|
||||
}
|
||||
if !filepath.IsAbs(binary) || filepath.Base(binary) != "pure-pw" {
|
||||
http.Error(w, "invalid Pure-FTPd identity tool", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 20*time.Second)
|
||||
defer cancel()
|
||||
if err = a.command(ctx, binary, "usermod", spec.Username, "-u", spec.Project.HostName, "-g", spec.Project.HostName, "-d", projectRoot, "-m"); err != nil {
|
||||
http.Error(w, "cannot bind FTP account to isolated identity", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
Reference in new issue
Block a user