aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnirudh Oppiliappan <x@icyphox.sh>2021-06-07 09:59:31 +0530
committerAnirudh Oppiliappan <x@icyphox.sh>2021-06-07 09:59:31 +0530
commit3aa2ddf9aff1edf377745fc3593b8f0381470272 (patch)
treed5e739abc12aaaf386ed4b0045c3dd5b56fd34c9
parente997795d4345c01173e0af149cccf82b543e2eff (diff)
downloadfsrv-3aa2ddf9aff1edf377745fc3593b8f0381470272.tar.gz
Pretty html, etc.
-rw-r--r--index.html13
-rw-r--r--main.go4
-rw-r--r--readme30
3 files changed, 44 insertions, 3 deletions
diff --git a/index.html b/index.html
index 44f7770..ba5d0ac 100644
--- a/index.html
+++ b/index.html
@@ -4,12 +4,21 @@
4 <meta charset="UTF-8" /> 4 <meta charset="UTF-8" />
5 <meta name="viewport" content="width=device-width, initial-scale=1.0" /> 5 <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6 <meta http-equiv="X-UA-Compatible" content="ie=edge" /> 6 <meta http-equiv="X-UA-Compatible" content="ie=edge" />
7 <title>Document</title> 7 <title>fsrv</title>
8 <link rel="icon" type="image/png" sizes="16x16" href="https://icyphox.sh/favicon.png">
8 </head> 9 </head>
10 <style>
11 body {
12 max-width: 640px;
13 padding: 0 10px;
14 margin: 40px auto;
15 }
16 </style>
9 <body> 17 <body>
18 <h1>fsrv</h1>
10 <form 19 <form
11 enctype="multipart/form-data" 20 enctype="multipart/form-data"
12 action="http://localhost:4040" 21 action="https://x.icyphox.sh/"
13 method="post" 22 method="post"
14 > 23 >
15 <p>file:</p> 24 <p>file:</p>
diff --git a/main.go b/main.go
index 470d54f..997c242 100644
--- a/main.go
+++ b/main.go
@@ -18,6 +18,7 @@ type settings struct {
18 namelen int 18 namelen int
19 key string 19 key string
20 storepath string 20 storepath string
21 index string
21} 22}
22 23
23func randName(n int) string { 24func randName(n int) string {
@@ -62,7 +63,7 @@ func (s *settings) uploadFile(w http.ResponseWriter, r *http.Request) {
62 fileUrl := s.url + "/" + newFile 63 fileUrl := s.url + "/" + newFile
63 fmt.Fprintf(w, "%v", fileUrl) 64 fmt.Fprintf(w, "%v", fileUrl)
64 case "GET": 65 case "GET":
65 http.ServeFile(w, r, "index.html") 66 http.ServeFile(w, r, s.index)
66 default: 67 default:
67 fmt.Fprintf(w, "unsupported method") 68 fmt.Fprintf(w, "unsupported method")
68 } 69 }
@@ -74,6 +75,7 @@ func (s *settings) readSettings() {
74 flag.StringVar(&s.storepath, "storepath", "uploads", "path to store uploaded files") 75 flag.StringVar(&s.storepath, "storepath", "uploads", "path to store uploaded files")
75 flag.IntVar(&s.namelen, "namelen", 5, "length of random filename") 76 flag.IntVar(&s.namelen, "namelen", 5, "length of random filename")
76 flag.StringVar(&s.key, "key", "secret", "secret key; generate this yourself") 77 flag.StringVar(&s.key, "key", "secret", "secret key; generate this yourself")
78 flag.StringVar(&s.index, "index", "index.html", "path to index html file")
77 flag.Parse() 79 flag.Parse()
78} 80}
79 81
diff --git a/readme b/readme
new file mode 100644
index 0000000..c95c6d4
--- /dev/null
+++ b/readme
@@ -0,0 +1,30 @@
1FSRV
2
3Filehost server for https://x.icyphox.sh.
4
5
6(NON) FEATURES
7
8· Single-user
9· Only handles file upload. Serving is left to the reverse proxy.
10· Bring your own index.html (-index flag)
11· Requires a key to upload. Change the default!
12
13
14USAGE
15
16 Usage of ./fsrv:
17 -index string
18 path to index html file (default "index.html")
19 -key string
20 secret key; generate this yourself (default "secret")
21 -namelen int
22 length of random filename (default 5)
23 -port string
24 port to listen on (default "9393")
25 -storepath string
26 path to store uploaded files (default "uploads")
27 -url string
28 url for fsrv to serve files (default "localhost")
29
30Sample index.html is provided. Edit as required.