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 @@
Optional headers with the request
- {% if not forcerandom %} -Randomize the filename
- Linx-Randomize: yes
Specify a custom deletion key
Linx-Delete-Key: mysecret
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 %}
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 @@