Changeset 29 in code
- Timestamp:
- Oct 19, 2021, 9:45:01 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/partage.go
r28 r29 6 6 "io" 7 7 "io/ioutil" 8 "log" 8 9 "net/http" 9 10 "os" … … 49 50 } 50 51 52 var verbose bool 53 51 54 func writefile(f *os.File, s io.ReadCloser, contentlength int64) error { 52 55 buffer := make([]byte, 4096) … … 94 97 } 95 98 99 if verbose { 100 log.Printf("Saving metadata for %s in %s", meta.Filename, conf.metapath + "/" + meta.Filename + ".json") 101 } 102 96 103 f, err := os.Create(conf.metapath + "/" + meta.Filename + ".json") 97 104 if err != nil { … … 115 122 http.Error(w, "Internal error", http.StatusInternalServerError) 116 123 return 124 } 125 126 if verbose { 127 log.Printf("Serving template %s", t.Name()) 117 128 } 118 129 … … 136 147 } 137 148 defer f.Close() 149 150 if verbose { 151 log.Printf("Writing %d bytes to %s", r.ContentLength, tmp) 152 } 138 153 139 154 if err = writefile(f, r.Body, r.ContentLength); err != nil { … … 207 222 } 208 223 224 if verbose { 225 log.Printf("Serving file %s", conf.rootdir + filename) 226 } 227 209 228 http.ServeFile(w, r, conf.rootdir + filename) 210 229 } 211 230 212 231 func uploader(w http.ResponseWriter, r *http.Request) { 232 if verbose { 233 log.Printf("%s: <%s> %s %s %s", r.Host, r.RemoteAddr, r.Method, r.RequestURI, r.Proto) 234 } 235 213 236 switch r.Method { 214 237 case "POST": … … 238 261 iniflags.Parse() 239 262 263 if verbose { 264 log.Printf("Applied configuration:\n%s", conf) 265 } 266 240 267 if (conf.chroot != "") { 268 if verbose { 269 log.Printf("Changing root to %s", conf.chroot) 270 } 241 271 syscall.Chroot(conf.chroot) 242 272 } … … 261 291 } 262 292 293 if verbose { 294 log.Printf("Dropping privileges to %s", conf.user) 295 } 296 263 297 syscall.Setuid(uid) 264 298 syscall.Setgid(gid) … … 267 301 http.HandleFunc("/", uploader) 268 302 http.Handle(conf.filectx, http.StripPrefix(conf.filectx, http.FileServer(http.Dir(conf.filepath)))) 303 304 if verbose { 305 log.Printf("Listening on %s", conf.bind) 306 } 307 269 308 http.ListenAndServe(conf.bind, nil) 270 309 }
Note:
See TracChangeset
for help on using the changeset viewer.