/*
uploader -- simplest form file uploader
-Copyright (C) 2018-2020 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2018-2021 Sergey Matveev <stargrave@stargrave.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
var (
Index = template.Must(template.New("index").Parse(`<html>
<head><title>Upload</title></head><body>
-<pre>
Example command line usage:
-
- $ curl -F file=@somedata.tar.gpg [-F comment="optional comment"] http://.../upload/
- $ b2sum -a blake2b somedata.tar.gpg # to verify checksum
+<pre>
+$ curl -F file=@somedata.tar.gpg [-F comment="optional comment"] http://.../upload/
+$ b2sum -a blake2b somedata.tar.gpg # to verify checksum
</pre>
<form enctype="multipart/form-data" action="/upload/" method="post">
<label for="file">File to upload:</label><br/>
tai64n.FromTime(t, ts)
tai := ts.Encode()[1:]
fnOrig := p.FileName()
- fd, err := os.OpenFile(tai+".part", os.O_WRONLY|os.O_CREATE, 0666)
+ fd, err := os.OpenFile(tai+".part", os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0666)
if err != nil {
log.Println(r.RemoteAddr, tai, fnOrig, err)
return
func main() {
bind := flag.String("bind", "[::]:8086", "Address to bind to")
conns := flag.Int("conns", 2, "Maximal number of connections")
- NotifyFromAddr = flag.String("notify-from", "uploader@example.com", "Address notifications are send to")
- NotifyToAddr = flag.String("notify-to", "", "Address notifications are send from")
+ NotifyFromAddr = flag.String("notify-from", "uploader@example.com", "Address notifications are sent to")
+ NotifyToAddr = flag.String("notify-to", "", "Address notifications are sent from")
flag.Parse()
+ log.SetFlags(log.Lshortfile)
+ log.SetOutput(os.Stdout)
if len(*NotifyFromAddr) == 0 && len(*NotifyToAddr) > 0 {
log.Fatalln("notify-from address can not be empty, if notify-to is set")
}