@@ -7,6 +7,7 @@ Handling of webserver and requests / uploads
77import (
88 "bytes"
99 "context"
10+ "crypto/subtle"
1011 "embed"
1112 "encoding/base64"
1213 "errors"
@@ -115,6 +116,7 @@ func Start() {
115116 mux .HandleFunc ("/login" , showLogin )
116117 mux .HandleFunc ("/logs" , requireLogin (showLogs , true , false ))
117118 mux .HandleFunc ("/logout" , doLogout )
119+ mux .HandleFunc ("/publicUpload" , showPublicUpload )
118120 mux .HandleFunc ("/uploadChunk" , requireLogin (uploadChunk , false , false ))
119121 mux .HandleFunc ("/uploadStatus" , requireLogin (sse .GetStatusSSE , false , false ))
120122 mux .HandleFunc ("/users" , requireLogin (showUserAdmin , true , false ))
@@ -357,9 +359,12 @@ func validateNewPassword(newPassword string, user models.User) (string, string,
357359
358360// Handling of /error
359361func showError (w http.ResponseWriter , r * http.Request ) {
360- const invalidFile = 0
361- const noCipherSupplied = 1
362- const wrongCipher = 2
362+ const (
363+ invalidFile = iota
364+ noCipherSupplied
365+ wrongCipher
366+ invalidFileRequest
367+ )
363368
364369 errorReason := invalidFile
365370 if r .URL .Query ().Has ("e2e" ) {
@@ -368,6 +373,9 @@ func showError(w http.ResponseWriter, r *http.Request) {
368373 if r .URL .Query ().Has ("key" ) {
369374 errorReason = wrongCipher
370375 }
376+ if r .URL .Query ().Has ("fr" ) {
377+ errorReason = invalidFileRequest
378+ }
371379 err := templateFolder .ExecuteTemplate (w , "error" , genericView {
372380 ErrorId : errorReason ,
373381 PublicName : configuration .Get ().PublicName ,
@@ -523,7 +531,7 @@ type LoginView struct {
523531// If it exists, a download form is shown, or a password needs to be entered.
524532func showDownload (w http.ResponseWriter , r * http.Request ) {
525533 addNoCacheHeader (w )
526- keyId := queryUrl (w , r , "error" )
534+ keyId := queryUrl (w , r , "id" , " error" )
527535 file , ok := storage .GetFile (keyId )
528536 if ! ok || file .IsFileRequest () {
529537 redirect (w , "error" )
@@ -597,8 +605,8 @@ func showHotlink(w http.ResponseWriter, r *http.Request) {
597605
598606// Checks if a file is associated with the GET parameter from the current URL
599607// Stops for 500ms to limit brute forcing if invalid key and redirects to redirectUrl
600- func queryUrl (w http.ResponseWriter , r * http.Request , redirectUrl string ) string {
601- keys , ok := r .URL .Query ()["id" ]
608+ func queryUrl (w http.ResponseWriter , r * http.Request , keyword string , redirectUrl string ) string {
609+ keys , ok := r .URL .Query ()[keyword ]
602610 if ! ok || len (keys [0 ]) < configuration .Get ().LengthId {
603611 select {
604612 case <- time .After (500 * time .Millisecond ):
@@ -883,6 +891,35 @@ type userInfo struct {
883891 User models.User
884892}
885893
894+ // Handling of /publicUpload
895+ func showPublicUpload (w http.ResponseWriter , r * http.Request ) {
896+ addNoCacheHeader (w )
897+ fileRequestId := queryUrl (w , r , "id" , "error?fr" )
898+ request , ok := filerequest .Get (fileRequestId )
899+ if ! ok {
900+ redirect (w , "error?fr" )
901+ return
902+ }
903+ apiKey := queryUrl (w , r , "key" , "error?fr" )
904+ if subtle .ConstantTimeCompare ([]byte (request .ApiKey ), []byte (apiKey )) != 1 {
905+ redirect (w , "error?fr" )
906+ return
907+ }
908+
909+ config := configuration .Get ()
910+
911+ view := filerequestView {
912+ PublicName : config .PublicName ,
913+ ApiKey : apiKey ,
914+ FileRequestId : fileRequestId ,
915+ ChunkSize : configuration .Get ().ChunkSize ,
916+ CustomContent : customStaticInfo ,
917+ }
918+
919+ err := templateFolder .ExecuteTemplate (w , "publicUpload" , view )
920+ helper .CheckIgnoreTimeout (err )
921+ }
922+
886923// Handling of /uploadChunk
887924// If the user is authenticated, this parses the uploaded chunk and stores it
888925func uploadChunk (w http.ResponseWriter , r * http.Request ) {
@@ -917,7 +954,7 @@ func downloadFileWithNameInUrl(w http.ResponseWriter, r *http.Request) {
917954// Handling of /downloadFile
918955// Outputs the file to the user and reduces the download remaining count for the file
919956func downloadFile (w http.ResponseWriter , r * http.Request ) {
920- id := queryUrl (w , r , "error" )
957+ id := queryUrl (w , r , "id" , " error" )
921958 serveFile (id , true , w , r )
922959}
923960
@@ -1065,3 +1102,14 @@ type oauthErrorView struct {
10651102 ErrorProvidedMessage string
10661103 CustomContent customStatic
10671104}
1105+
1106+ // A view containing parameters for a generic template
1107+ type filerequestView struct {
1108+ IsAdminView bool
1109+ IsDownloadView bool
1110+ PublicName string
1111+ ApiKey string
1112+ FileRequestId string
1113+ ChunkSize int
1114+ CustomContent customStatic
1115+ }
0 commit comments