diff options
Diffstat (limited to 'src/rhimportd/uploadWeb.go')
-rw-r--r-- | src/rhimportd/uploadWeb.go | 88 |
1 files changed, 69 insertions, 19 deletions
diff --git a/src/rhimportd/uploadWeb.go b/src/rhimportd/uploadWeb.go index 978f6cb..dc9b25c 100644 --- a/src/rhimportd/uploadWeb.go +++ b/src/rhimportd/uploadWeb.go @@ -33,6 +33,7 @@ import ( "net/http" "os" "strings" + "time" ) type webUploadResponseData struct { @@ -87,25 +88,26 @@ func webUploadHandler(conf *rhimport.Config, db *rddb.DBChan, sessions *rhimport } username := r.FormValue("LOGIN_NAME") - password := r.FormValue("PASSWORD") - if username == "" { - webUploadErrorResponse(w, http.StatusBadRequest, "missing field LOGIN_NAME") - return - } - if password == "" { - webUploadErrorResponse(w, http.StatusBadRequest, "missing field LOGIN_NAME") - return - } - - if authenticated, err := db.CheckPassword(username, password); err != nil { - rhl.Printf("WebUploadHandler: error checking username/password: %v", err) - webUploadErrorResponse(w, http.StatusUnauthorized, err.Error()) - return - } else if !authenticated { - rhl.Printf("WebUploadHandler: invalid username/password") - webUploadErrorResponse(w, http.StatusUnauthorized, "invalid username/password") - return - } + // TODO: re-add this after testing is done!!!! + // password := r.FormValue("PASSWORD") + // if username == "" { + // webUploadErrorResponse(w, http.StatusBadRequest, "missing field LOGIN_NAME") + // return + // } + // if password == "" { + // webUploadErrorResponse(w, http.StatusBadRequest, "missing field LOGIN_NAME") + // return + // } + + // if authenticated, err := db.CheckPassword(username, password); err != nil { + // rhl.Printf("WebUploadHandler: error checking username/password: %v", err) + // webUploadErrorResponse(w, http.StatusUnauthorized, err.Error()) + // return + // } else if !authenticated { + // rhl.Printf("WebUploadHandler: invalid username/password") + // webUploadErrorResponse(w, http.StatusUnauthorized, "invalid username/password") + // return + // } src, hdr, err := r.FormFile("FILENAME") if err != nil { @@ -137,3 +139,51 @@ func webUploadHandler(conf *rhimport.Config, db *rddb.DBChan, sessions *rhimport io.Copy(dst, src) webUploadResponse(w, "tmp://"+strings.TrimPrefix(dstfile, conf.TempDir)) } + +func webUploadCleanerRun(dir *os.File, conf *rhimport.Config) { + t := time.Tick(5 * time.Second) + for now := range t { + var err error + if _, err = dir.Seek(0, 0); err != nil { + rhl.Printf("webUploadCleaner: reading directory contents failed: %s", err) + return + } + + var entries []os.FileInfo + if entries, err = dir.Readdir(0); err != nil { + rhl.Printf("webUploadCleaner: reading directory contents failed: %s", err) + return + } + + for _, entry := range entries { + rhdl.Printf("webUploadCleaner: found file/dir '%s', Age: %v", entry.Name(), now.Sub(entry.ModTime())) + // TODO: delete file if it is a webupload and it is old enough + } + } +} + +func webUploadCleaner(conf *rhimport.Config) { + for { + dir, err := os.Open(conf.TempDir) + if err != nil { + rhl.Printf("webUploadCleaner: %s", err) + continue + } + if i, err := dir.Stat(); err != nil { + rhl.Printf("webUploadCleaner: %s", err) + dir.Close() + continue + } else { + if !i.IsDir() { + rhl.Printf("webUploadCleaner: %s is not a directory", conf.TempDir) + dir.Close() + continue + } + } + webUploadCleanerRun(dir, conf) + rhdl.Printf("webUploadCleanerRun: returned - restring in 5 sec...") + dir.Close() + + time.Sleep(5 * time.Second) + } +} |