func hdeaddrop_fetch(w http.ResponseWriter, r *http.Request) { r.ParseForm() id := strings.TrimSpace(r.FormValue("id")) log.Println("Fetching " + id) dirname := "uploads" d, err := os.Open(dirname) if err != nil { fmt.Println(err) os.Exit(1) } defer d.Close() fi, err := d.Readdir(-1) if err != nil { fmt.Println(err) os.Exit(1) } for _, fi := range fi { log.Println(fi) splitString := strings.Split(fi.Name(), "_") log.Println("Testing " + splitString[0] + " against input Id of " + id) if strings.Contains(splitString[0], id) == true { decryptedFile := utils.DecryptContent("uploads/"+fi.Name(), cryptoKey) log.Println(decryptedFile) http.ServeFile(w, r, decryptedFile) /* Delete file */ os.Remove(decryptedFile) } } s1, _ := template.ParseFiles("tmpl/headersub.tmpl", "tmpl/content.tmpl", "tmpl/footer.tmpl") fbody, err := ioutil.ReadFile("views/notfound.html") if err != nil { } var buffer bytes.Buffer s1.ExecuteTemplate(&buffer, "header", nil) s1.ExecuteTemplate(&buffer, "content", template.HTML(string(fbody))) s1.ExecuteTemplate(&buffer, "footer", nil) w.Write(buffer.Bytes()) }
func hdeaddrop_fetchWithId(w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) id := params["id"] dirname := "uploads" d, err := os.Open(dirname) if err != nil { fmt.Println(err) os.Exit(1) } defer d.Close() fi, err := d.Readdir(-1) if err != nil { fmt.Println(err) os.Exit(1) } for _, fi := range fi { if fi.Mode().IsRegular() { splitString := strings.Split(fi.Name(), "_") if strings.Contains(splitString[0], id) == true { decryptedFile := utils.DecryptContent("uploads/"+fi.Name(), cryptoKey) log.Println(decryptedFile) http.ServeFile(w, r, decryptedFile) /* Delete file */ os.Remove(decryptedFile) } } } s1, _ := template.ParseFiles("tmpl/headersubsub.tmpl", "tmpl/content.tmpl", "tmpl/footer.tmpl") fbody, err := ioutil.ReadFile("views/notfound.html") if err != nil { } var buffer bytes.Buffer s1.ExecuteTemplate(&buffer, "header", nil) s1.ExecuteTemplate(&buffer, "content", template.HTML(string(fbody))) s1.ExecuteTemplate(&buffer, "footer", nil) w.Write(buffer.Bytes()) }