Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move template into file tree to allow templating #45

Merged
merged 2 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Types of changes:
## [Unreleased]
### Added
- URL prefix support to host, e.g., under `http://example.org/gosh/`
- Add goshy as bash script and NixOS program, [@riotbibt](https://github.com/riotbib) in [#27](https://github.com/oxzi/gosh/pull/27).
- Add goshy as bash script and NixOS program, [@riotbib](https://github.com/riotbib) in [#27](https://github.com/oxzi/gosh/pull/27).
- Created Store RPC working on Unix domain sockets to allow a `fork`+`exec`ed daemon.
- Configuration through YAML configuration file.

Expand All @@ -30,6 +30,7 @@ Types of changes:
- `goshd` became `gosh`.
- Made `gosh` a `chroot`ed, privilege dropped, `fork`+`exec`ed daemon.
- OpenBSD installation changed due to structural program changes.
- Extract web template into a more editable file, [@riotbib](https://github.com/riotbib) in [#45](https://github.com/oxzi/gosh/pull/45).

### Deprecated
### Removed
Expand Down
144 changes: 144 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<!DOCTYPE html>
<html>
<head>
<title>gosh! Go Share</title>

<style>
* {
font-family: monospace;
}

body {
margin: 0 auto;
padding: 1rem;
width: 50%;
}

h1 {
padding-top: 3rem;
}

h2 {
padding-top: 2rem;
}

h3 {
padding-top: 1rem;
}

pre {
background-color: #eee;
padding: 0.5rem;
}

form {
padding: 0.5rem;
position: relative;
margin: auto;
background-color: #eee;
}

#grid {
display: grid;
grid-gap: 1rem;
grid-template-columns: 1fr 1fr;
grid-template-rows: repeat(3, 3rem);
margin-bottom: 1rem;
}

#grid > * {
margin: auto 0;
}

#grid input[type="checkbox"] {
margin-right: auto;
}

button {
width: 100%;
}
</style>
</head>

<body>
<h1># gosh! Go Share</h1>
<p>
Upload your files to this server and share them with your friends or, if
non-existent, shady people from the Internet.
</p>
<p>
Your file will expire after {{.Expires}} or earlier, if explicitly
specified. Optionally, the file can be deleted directly after the first
retrieval. For each upload, a deletion URL will also be generated which
can be used to delete the file before expiration. In addition, the
maximum file size is {{.Size}}.
</p>
<p>
This is no place to share questionable or illegal data. Please use another
service or stop it completely. Get some help.
</p>
<p>
The gosh software can be obtained from
<a href="https://github.com/oxzi/gosh">https://github.com/oxzi/gosh</a>
</p>

<h2>## Posting</h2>

<h3>### curl</h3>

HTTP POST your file:

<pre>$ curl -F '[email protected]' {{.Proto}}://{{.Hostname}}{{.Prefix}}/</pre>

Burn after reading:

<pre>$ curl -F '[email protected]' -F 'burn=1' {{.Proto}}://{{.Hostname}}{{.Prefix}}/</pre>

Set a custom expiry date, e.g., one minute:

<pre>$ curl -F '[email protected]' -F 'time=1m' {{.Proto}}://{{.Hostname}}{{.Prefix}}/</pre>

Or all together:

<pre>$ curl -F '[email protected]' -F 'time=1m' -F 'burn=1' {{.Proto}}://{{.Hostname}}{{.Prefix}}/</pre>

Print only URL as response:

<pre>$ curl -F '[email protected]' -F {{.Proto}}://{{.Hostname}}{{.Prefix}}/?onlyURL</pre>

<h3>### form</h3>

<form
action="{{.Proto}}://{{.Hostname}}{{.Prefix}}/"
method="POST"
enctype="multipart/form-data">
<div id="grid">
<label for="file">Your file:</label>
<input type="file" name="file" />
<label for="burn">Burn after reading:</label>
<input type="checkbox" name="burn" value="1" />
<label for="time">Optionally, set a custom expiry date:</label>
<input
type="text"
name="time"
pattern="{{.DurationPattern}}"
title="A duration string is sequence of decimal numbers, each with a unit suffix. Valid time units in order are 'y', 'mo', 'w', 'd', 'h', 'm', 's'"
/>
</div>
<button>Upload</button>
</form>

<h2>## Privacy</h2>

This software stores the IP address for each upload. This information is
stored as long as the file is available. A normal download is logged without
user information.

<h2>## Abuse</h2>

If, for whatever reason, you would like to have a file removed prematurely,
please write an e-mail to
<a href="mailto:{{.EMail}}">&lt;{{.EMail}}&gt;</a>. Please allow me a
certain amount of time to react and work on your request.
</body>
</html>
151 changes: 5 additions & 146 deletions webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,163 +3,22 @@ package main
import (
"context"
"fmt"
"html/template"
"io"
"net"
"net/http"
"net/http/fcgi"
"os"
"strings"
"text/template"
"time"

_ "embed"

log "github.com/sirupsen/logrus"
)

const indexTpl = `<!DOCTYPE html>
<html>
<head>
<title>gosh! Go Share</title>

<style>
* {
font-family: monospace;
}

body {
margin: 0 auto;
padding: 1rem;
width: 50%;
}

h1 {
padding-top: 3rem;
}

h2 {
padding-top: 2rem;
}

h3 {
padding-top: 1rem;
}

pre {
background-color: #eee;
padding: 0.5rem;
}

form {
padding: 0.5rem;
position: relative;
margin: auto;
background-color: #eee;
}

#grid {
display: grid;
grid-gap: 1rem;
grid-template-columns: 1fr 1fr;
grid-template-rows: repeat(3, 3rem);
margin-bottom: 1rem;
}

#grid > * {
margin: auto 0;
}

#grid input[type="checkbox"] {
margin-right: auto;
}

button {
width: 100%;
}
</style>
</head>

<body>
<h1># gosh! Go Share</h1>
<p>
Upload your files to this server and share them with your friends or, if
non-existent, shady people from the Internet.
</p>
<p>
Your file will expire after {{.Expires}} or earlier, if explicitly
specified. Optionally, the file can be deleted directly after the first
retrieval. For each upload, a deletion URL will also be generated which
can be used to delete the file before expiration. In addition, the
maximum file size is {{.Size}}.
</p>
<p>
This is no place to share questionable or illegal data. Please use another
service or stop it completely. Get some help.
</p>
<p>
The gosh software can be obtained from
<a href="https://github.com/oxzi/gosh">https://github.com/oxzi/gosh</a>
</p>

<h2>## Posting</h2>

<h3>### curl</h3>

HTTP POST your file:

<pre>$ curl -F '[email protected]' {{.Proto}}://{{.Hostname}}{{.Prefix}}/</pre>

Burn after reading:

<pre>$ curl -F '[email protected]' -F 'burn=1' {{.Proto}}://{{.Hostname}}{{.Prefix}}/</pre>

Set a custom expiry date, e.g., one minute:

<pre>$ curl -F '[email protected]' -F 'time=1m' {{.Proto}}://{{.Hostname}}{{.Prefix}}/</pre>

Or all together:

<pre>$ curl -F '[email protected]' -F 'time=1m' -F 'burn=1' {{.Proto}}://{{.Hostname}}{{.Prefix}}/</pre>

Print only URL as response:

<pre>$ curl -F '[email protected]' -F {{.Proto}}://{{.Hostname}}{{.Prefix}}/?onlyURL</pre>

<h3>### form</h3>

<form
action="{{.Proto}}://{{.Hostname}}{{.Prefix}}/"
method="POST"
enctype="multipart/form-data">
<div id="grid">
<label for="file">Your file:</label>
<input type="file" name="file" />
<label for="burn">Burn after reading:</label>
<input type="checkbox" name="burn" value="1" />
<label for="time">Optionally, set a custom expiry date:</label>
<input
type="text"
name="time"
pattern="{{.DurationPattern}}"
title="A duration string is sequence of decimal numbers, each with a unit suffix. Valid time units in order are 'y', 'mo', 'w', 'd', 'h', 'm', 's'"
/>
</div>
<button>Upload</button>
</form>

<h2>## Privacy</h2>

This software stores the IP address for each upload. This information is
stored as long as the file is available. A normal download is logged without
user information.

<h2>## Abuse</h2>

If, for whatever reason, you would like to have a file removed prematurely,
please write an e-mail to
<a href="mailto:{{.EMail}}">&lt;{{.EMail}}&gt;</a>. Please allow me a
certain amount of time to react and work on your request.
</body>
</html>
`
//go:embed index.html
var indexTpl string

const (
msgDeletionKeyWrong = "Error: Deletion key is incorrect."
Expand Down