diff --git a/README.md b/README.md index d509689..8fdd4f4 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,6 @@ maxexpiry = 86400 | ```xframeoptions = "..." ``` | X-Frame-Options header (default is "SAMEORIGIN") | ```remoteuploads = true``` | (optionally) enable remote uploads (/upload?url=https://...) | ```nologs = true``` | (optionally) disable request logs in stdout -| ```force-random-filename = true``` | (optionally) force the use of random filenames | ```custompagespath = custom_pages/``` | (optionally) specify path to directory containing markdown pages (must end in .md) that will be added to the site navigation (this can be useful for providing contact/support information and so on). For example, custom_pages/My_Page.md will become My Page in the site navigation diff --git a/display.go b/display.go index 066a3d3..c64e72d 100644 --- a/display.go +++ b/display.go @@ -131,7 +131,6 @@ func fileDisplayHandler(c web.C, w http.ResponseWriter, r *http.Request, fileNam "expiry": expiryHuman, "expirylist": listExpirationTimes(), "extra": extra, - "forcerandom": Config.forceRandomFilename, "lines": lines, "files": metadata.ArchiveFiles, "siteurl": strings.TrimSuffix(getSiteURL(r), "/"), diff --git a/linx-server.conf.example b/linx-server.conf.example index eb2e1f8..921d08a 100644 --- a/linx-server.conf.example +++ b/linx-server.conf.example @@ -8,5 +8,4 @@ maxexpiry = 86400 allowhotlink = true remoteuploads = true nologs = true -force-random-filename = false cleanup-every-minutes = 5 \ No newline at end of file diff --git a/pages.go b/pages.go index fdbfe42..70e9d3a 100644 --- a/pages.go +++ b/pages.go @@ -21,9 +21,8 @@ const ( func indexHandler(c web.C, w http.ResponseWriter, r *http.Request) { err := renderTemplate(Templates["index.html"], pongo2.Context{ - "maxsize": Config.maxSize, - "expirylist": listExpirationTimes(), - "forcerandom": Config.forceRandomFilename, + "maxsize": Config.maxSize, + "expirylist": listExpirationTimes(), }, r, w) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) @@ -32,8 +31,7 @@ func indexHandler(c web.C, w http.ResponseWriter, r *http.Request) { func pasteHandler(c web.C, w http.ResponseWriter, r *http.Request) { err := renderTemplate(Templates["paste.html"], pongo2.Context{ - "expirylist": listExpirationTimes(), - "forcerandom": Config.forceRandomFilename, + "expirylist": listExpirationTimes(), }, r, w) if err != nil { oopsHandler(c, w, r, RespHTML, "") @@ -43,7 +41,6 @@ func pasteHandler(c web.C, w http.ResponseWriter, r *http.Request) { func apiDocHandler(c web.C, w http.ResponseWriter, r *http.Request) { err := renderTemplate(Templates["API.html"], pongo2.Context{ "siteurl": getSiteURL(r), - "forcerandom": Config.forceRandomFilename, "keyless_delete": Config.anyoneCanDelete, }, r, w) if err != nil { @@ -54,11 +51,10 @@ func apiDocHandler(c web.C, w http.ResponseWriter, r *http.Request) { func makeCustomPageHandler(fileName string) func(c web.C, w http.ResponseWriter, r *http.Request) { return func(c web.C, w http.ResponseWriter, r *http.Request) { err := renderTemplate(Templates["custom_page.html"], pongo2.Context{ - "siteurl": getSiteURL(r), - "forcerandom": Config.forceRandomFilename, - "contents": customPages[fileName], - "filename": fileName, - "pagename": customPagesNames[fileName], + "siteurl": getSiteURL(r), + "contents": customPages[fileName], + "filename": fileName, + "pagename": customPagesNames[fileName], }, r, w) if err != nil { oopsHandler(c, w, r, RespHTML, "") diff --git a/server.go b/server.go index a3549c1..c9ffb93 100644 --- a/server.go +++ b/server.go @@ -69,7 +69,6 @@ var Config struct { s3Region string s3Bucket string s3ForcePathStyle bool - forceRandomFilename bool anyoneCanDelete bool accessKeyCookieExpiry uint64 customPagesDir string @@ -312,8 +311,6 @@ func main() { "S3 bucket to use for files and metadata") flag.BoolVar(&Config.s3ForcePathStyle, "s3-force-path-style", false, "Force path-style addressing for S3 (e.g. https://s3.amazonaws.com/linx/example.txt)") - flag.BoolVar(&Config.forceRandomFilename, "force-random-filename", false, - "Force all uploads to use a random filename") flag.BoolVar(&Config.anyoneCanDelete, "anyone-can-delete", false, "Anyone has delete button on the file page") flag.Uint64Var(&Config.accessKeyCookieExpiry, "access-cookie-expiry", 0, "Expiration time for access key cookies in seconds (set 0 to use session cookies)") diff --git a/server_test.go b/server_test.go index c47d028..8909c83 100644 --- a/server_test.go +++ b/server_test.go @@ -575,58 +575,6 @@ func TestPostExpiresJSONUpload(t *testing.T) { } } -func TestPostRandomizeJSONUpload(t *testing.T) { - mux := setup() - w := httptest.NewRecorder() - - filename := generateBarename() + ".txt" - - var b bytes.Buffer - mw := multipart.NewWriter(&b) - fw, err := mw.CreateFormFile("file", filename) - if err != nil { - t.Fatal(err) - } - fw.Write([]byte("File content")) - - rnd, err := mw.CreateFormField("randomize") - if err != nil { - t.Fatal(err) - } - rnd.Write([]byte("true")) - - mw.Close() - - req, err := http.NewRequest("POST", "/upload/", &b) - req.Header.Set("Content-Type", mw.FormDataContentType()) - req.Header.Set("Accept", "application/json") - req.Header.Set("Referer", Config.siteURL) - if err != nil { - t.Fatal(err) - } - - mux.ServeHTTP(w, req) - - if w.Code != 200 { - t.Log(w.Body.String()) - t.Fatalf("Status code is not 200, but %d", w.Code) - } - - var myjson RespOkJSON - err = json.Unmarshal([]byte(w.Body.String()), &myjson) - if err != nil { - t.Fatal(err) - } - - if myjson.Original_Name == filename { - t.Fatalf("Filename (%s) is not random (%s)", filename, myjson.Original_Name) - } - - if myjson.Size != "12" { - t.Fatalf("File size was not 12 but %s", myjson.Size) - } -} - func TestPostEmptyUpload(t *testing.T) { mux := setup() w := httptest.NewRecorder() @@ -753,52 +701,6 @@ func TestPutUpload(t *testing.T) { } } -func TestPutRandomizedUpload(t *testing.T) { - mux := setup() - w := httptest.NewRecorder() - - filename := generateBarename() + ".file" - - req, err := http.NewRequest("PUT", "/upload/"+filename, strings.NewReader("File content")) - if err != nil { - t.Fatal(err) - } - - req.Header.Set("Linx-Randomize", "yes") - - mux.ServeHTTP(w, req) - - if w.Body.String() == Config.siteURL+filename { - t.Fatal("Filename was not random") - } -} - -func TestPutForceRandomUpload(t *testing.T) { - mux := setup() - w := httptest.NewRecorder() - - oldFRF := Config.forceRandomFilename - Config.forceRandomFilename = true - filename := "randomizeme.file" - - req, err := http.NewRequest("PUT", "/upload/"+filename, strings.NewReader("File content")) - if err != nil { - t.Fatal(err) - } - - // while this should also work without this header, let's try to force - // the randomized filename off to be sure - req.Header.Set("Linx-Randomize", "no") - - mux.ServeHTTP(w, req) - - if w.Body.String() == Config.siteURL+filename { - t.Fatal("Filename was not random") - } - - Config.forceRandomFilename = oldFRF -} - func TestPutNoExtensionUpload(t *testing.T) { mux := setup() w := httptest.NewRecorder() @@ -810,8 +712,6 @@ func TestPutNoExtensionUpload(t *testing.T) { t.Fatal(err) } - req.Header.Set("Linx-Randomize", "yes") - mux.ServeHTTP(w, req) if w.Body.String() == Config.siteURL+filename { @@ -830,8 +730,6 @@ func TestPutEmptyUpload(t *testing.T) { t.Fatal(err) } - req.Header.Set("Linx-Randomize", "yes") - mux.ServeHTTP(w, req) if w.Code != 400 { @@ -853,8 +751,6 @@ func TestPutTooLargeUpload(t *testing.T) { t.Fatal(err) } - req.Header.Set("Linx-Randomize", "yes") - mux.ServeHTTP(w, req) if w.Code != 500 { @@ -896,34 +792,6 @@ func TestPutJSONUpload(t *testing.T) { } } -func TestPutRandomizedJSONUpload(t *testing.T) { - var myjson RespOkJSON - - mux := setup() - w := httptest.NewRecorder() - - filename := generateBarename() + ".file" - - req, err := http.NewRequest("PUT", "/upload/"+filename, strings.NewReader("File content")) - if err != nil { - t.Fatal(err) - } - - req.Header.Set("Accept", "application/json") - req.Header.Set("Linx-Randomize", "yes") - - mux.ServeHTTP(w, req) - - err = json.Unmarshal([]byte(w.Body.String()), &myjson) - if err != nil { - t.Fatal(err) - } - - if myjson.Original_Name == filename { - t.Fatal("Filename was not random ") - } -} - func TestPutExpireJSONUpload(t *testing.T) { var myjson RespOkJSON diff --git a/static/css/linx.css b/static/css/linx.css index 6bdd8fb..d508d4a 100644 --- a/static/css/linx.css +++ b/static/css/linx.css @@ -266,13 +266,7 @@ body { padding-top: 1px; } -#randomize { - vertical-align: bottom; - margin: 0; -} - #access_key { - min-width: 100%; line-height: 1.3em; } diff --git a/static/js/upload.js b/static/js/upload.js index 4cd8c16..4476b0e 100644 --- a/static/js/upload.js +++ b/static/js/upload.js @@ -69,10 +69,6 @@ Dropzone.options.dropzone = { file.uploadElement.setAttribute("style", 'background-image: -webkit-linear-gradient(left, #F2F4F7 ' + p + '%, #E2E2E2 ' + p + '%); background-image: -moz-linear-gradient(left, #F2F4F7 ' + p + '%, #E2E2E2 ' + p + '%); background-image: -ms-linear-gradient(left, #F2F4F7 ' + p + '%, #E2E2E2 ' + p + '%); background-image: -o-linear-gradient(left, #F2F4F7 ' + p + '%, #E2E2E2 ' + p + '%); background-image: linear-gradient(left, #F2F4F7 ' + p + '%, #E2E2E2 ' + p + '%)'); }, sending: function (file, xhr, formData) { - var randomize = document.getElementById("randomize"); - if (randomize != null) { - formData.append("randomize", randomize.checked); - } formData.append("expires", document.getElementById("expires").value); }, success: function (file, resp) { diff --git a/templates/API.html b/templates/API.html index 93a42b4..4447dec 100644 --- a/templates/API.html +++ b/templates/API.html @@ -30,11 +30,6 @@

Uploading a file

Optional headers with the request

- {% if not forcerandom %} -

Randomize the filename
- Linx-Randomize: yes

- {% endif %} - {% if !keyless_delete %}

Specify a custom deletion key
Linx-Delete-Key: mysecret

@@ -71,33 +66,33 @@

Uploading a file

Uploading myphoto.jpg

{% if auth != "none" %} -
$ curl -H "Linx-Api-Key: mysecretkey" -T myphoto.jpg {{ siteurl }}upload/  
-{{ siteurl }}{% if not forcerandom %}myphoto.jpg{% else %}7z4h4ut.jpg{% endif %}
+
$ curl -H "Linx-Api-Key: mysecretkey" -T myphoto.jpg {{ siteurl }}upload/  
+{{ siteurl }}7z4h4ut01.jpg
{% else %} -
$ curl -T myphoto.jpg {{ siteurl }}upload/  
-{{ siteurl }}{% if not forcerandom %}myphoto.jpg{% else %}wtq7pan.jpg{% endif %}
+
$ curl -T myphoto.jpg {{ siteurl }}upload/
+{{ siteurl }}wtq7pan4o.jpg
{% endif %}

Uploading myphoto.jpg with an expiry of 20 minutes

{% if auth != "none" %} -
$ curl -H "Linx-Api-Key: mysecretkey" -H "Linx-Expiry: 1200" -T myphoto.jpg {{ siteurl }}upload/
-{{ siteurl }}{% if not forcerandom %}myphoto.jpg{% else %}jm295snf.jpg{% endif %}
+
$ curl -H "Linx-Api-Key: mysecretkey" -H "Linx-Expiry: 1200" -T myphoto.jpg {{ siteurl }}upload/
+{{ siteurl }}jm295snf4h.jpg
{% else %} -
$ curl -H "Linx-Expiry: 1200" -T myphoto.jpg {{ siteurl }}upload/
-{{ siteurl }}{% if not forcerandom %}myphoto.jpg{% else %}1doym9u2.jpg{% endif %}
+
$ curl -H "Linx-Expiry: 1200" -T myphoto.jpg {{ siteurl }}upload/
+{{ siteurl }}1d7oym9u2o.jpg
{% endif %} -

Uploading myphoto.jpg with a random filename and getting a json response:

+

Uploading myphoto.jpg and getting a json response:

{% if auth != "none" %} -
$ curl -H "Linx-Api-Key: mysecretkey" -H "Accept: application/json"{% if not forcerandom %} -H "Linx-Randomize: yes"{% endif %} -T myphoto.jpg {{ siteurl }}upload/  
-{"delete_key":"...","expiry":"0","filename":"f34h4iu.jpg","mimetype":"image/jpeg",
-"sha256sum":"...","size":"...","url":"{{ siteurl }}f34h4iu.jpg"}
+
$ curl -H "Linx-Api-Key: mysecretkey" -H "Accept: application/json" -T myphoto.jpg {{ siteurl }}upload/
+{"delete_key":"...","expiry":"0","filename":"f34h4iuj7.jpg","mimetype":"image/jpeg",
+"sha256sum":"...","size":"...","url":"{{ siteurl }}f34h4iuj7.jpg","original_name":"myphoto.jpg"}
{% else %} -
$ curl -H "Accept: application/json"{% if not forcerandom %} -H "Linx-Randomize: yes"{% endif %} -T myphoto.jpg {{ siteurl }}upload/  
-{"delete_key":"...","expiry":"0","filename":"f34h4iu.jpg","mimetype":"image/jpeg",
-"sha256sum":"...","size":"...","url":"{{ siteurl }}f34h4iu.jpg"}
+
$ curl -H "Accept: application/json" -T myphoto.jpg {{ siteurl }}upload/
+{"delete_key":"...","expiry":"0","filename":"f34h4iuj7.jpg","mimetype":"image/jpeg",
+"sha256sum":"...","size":"...","url":"{{ siteurl }}f34h4iuj7.jpg","original_name":"myphoto.jpg"}
{% endif %}

Deleting a file

@@ -107,9 +102,9 @@

Deleting a file

Example

-

To delete myphoto.jpg

+

To delete f34h4iuj7.jpg

-
$ curl{% if auth != "none" %} -H"Linx-Api-Key: mysecretkey"{% endif %}{% if !keyless_delete %} -H "Linx-Delete-Key: mysecret"{% endif %} -X DELETE {{ siteurl }}myphoto.jpg
+			
$ curl{% if auth != "none" %} -H"Linx-Api-Key: mysecretkey"{% endif %}{% if !keyless_delete %} -H "Linx-Delete-Key: mysecret"{% endif %} -X DELETE {{ siteurl }}f34h4iuj7.jpg
 DELETED

Information about a file

@@ -130,8 +125,9 @@

Information about a file

Example

-
$ curl -H "Accept: application/json" {{ siteurl }}myphoto.jpg
-{"expiry":"0","filename":"myphoto.jpg","mimetype":"image/jpeg","sha256sum":"...","size":"..."}
+
$ curl -H "Accept: application/json" {{ siteurl }}f34h4iuj7.jpg
+{"expiry":"0","filename":"f34h4iuj7.jpg","mimetype":"image/jpeg","sha256sum":"...","size":"...",
+"original_name":"myphoto.jpg"}
diff --git a/templates/base.html b/templates/base.html index 8534a44..c5b430c 100644 --- a/templates/base.html +++ b/templates/base.html @@ -5,7 +5,7 @@ {% block title %}{{ sitename }}{% endblock %} - + {% block head %}{% endblock %} diff --git a/templates/display/bin.html b/templates/display/bin.html index cea7655..70351eb 100644 --- a/templates/display/bin.html +++ b/templates/display/bin.html @@ -14,7 +14,7 @@
- {% if not forcerandom %}{% endif %}. + .
{% endif %}. + .
Randomize filename - - +
+ + + + +
-
- - - - -
diff --git a/templates/paste.html b/templates/paste.html index 5940e7c..75b476b 100644 --- a/templates/paste.html +++ b/templates/paste.html @@ -7,9 +7,9 @@
- {% if not forcerandom %}{% endif %}..
diff --git a/upload.go b/upload.go index 2175edf..9803519 100644 --- a/upload.go +++ b/upload.go @@ -40,8 +40,7 @@ type UploadRequest struct { filename string expiry time.Duration // Seconds until expiry, 0 = never deleteKey string // Empty string if not defined - randomize bool - accessKey string // Empty string if not defined + accessKey string // Empty string if not defined } // Metadata associated with a file as it would actually be stored @@ -51,7 +50,7 @@ type Upload struct { } func uploadPostHandler(c web.C, w http.ResponseWriter, r *http.Request) { - if !strictReferrerCheck(r, getSiteURL(r), []string{"Linx-Delete-Key", "Linx-Expiry", "Linx-Randomize", "X-Requested-With"}) { + if !strictReferrerCheck(r, getSiteURL(r), []string{"Linx-Delete-Key", "Linx-Expiry", "X-Requested-With"}) { badRequestHandler(c, w, r, RespAUTO, "") return } @@ -95,10 +94,6 @@ func uploadPostHandler(c web.C, w http.ResponseWriter, r *http.Request) { upReq.expiry = parseExpiry(r.PostFormValue("expires")) upReq.accessKey = r.PostFormValue(accessKeyParamName) - if r.PostFormValue("randomize") == "true" { - upReq.randomize = true - } - upload, err := processUpload(upReq) if strings.EqualFold("application/json", r.Header.Get("Accept")) { @@ -200,7 +195,6 @@ func uploadRemote(c web.C, w http.ResponseWriter, r *http.Request) { upReq.src = http.MaxBytesReader(w, resp.Body, Config.maxSize) upReq.deleteKey = r.FormValue("deletekey") upReq.accessKey = r.FormValue(accessKeyParamName) - upReq.randomize = r.FormValue("randomize") == "yes" upReq.expiry = parseExpiry(r.FormValue("expiry")) upload, err := processUpload(upReq) @@ -229,10 +223,6 @@ func uploadRemote(c web.C, w http.ResponseWriter, r *http.Request) { } func uploadHeaderProcess(r *http.Request, upReq *UploadRequest) { - if r.Header.Get("Linx-Randomize") == "yes" { - upReq.randomize = true - } - upReq.deleteKey = r.Header.Get("Linx-Delete-Key") upReq.accessKey = r.Header.Get(accessKeyHeaderName) @@ -300,7 +290,7 @@ func processUpload(upReq UploadRequest) (upload Upload, err error) { upReq.deleteKey = uniuri.NewLen(30) } - if Config.forceRandomFilename || upReq.randomize || len(barename) == 0 { + if len(barename) == 0 { upReq.filename = upload.Filename }