2020-04-10 19:35:22 +00:00
|
|
|
# Gophor
|
|
|
|
|
|
|
|
A Gopher server written in GoLang as a means of learning about the Gopher
|
|
|
|
protocol, and more GoLang.
|
|
|
|
|
2020-04-29 22:52:07 +00:00
|
|
|
Linux only _for now_. Cross-compiled to way too many architectures.
|
|
|
|
Build-script now much improved, but still not pretty...
|
2020-04-15 18:59:12 +00:00
|
|
|
|
2020-04-22 12:46:14 +00:00
|
|
|
I'm unemployed and work on open-source projects like this and many others for
|
|
|
|
free. If you would like to help support my work that would be hugely
|
|
|
|
appreciated 💕 https://liberapay.com/grufwub/
|
2020-04-10 19:35:22 +00:00
|
|
|
|
2020-04-19 19:46:39 +00:00
|
|
|
WARNING: the development branch is filled with lava, fear and capitalism.
|
|
|
|
|
2020-04-30 15:02:13 +00:00
|
|
|
# Features
|
|
|
|
|
|
|
|
- Built with concurrency and efficiency in mind.
|
|
|
|
|
|
|
|
- ZERO external dependencies.
|
|
|
|
|
2020-05-01 16:17:12 +00:00
|
|
|
- Security focused -- by default chroots to server directory and drops
|
|
|
|
privileges, though `-rootless` flag may be applied to skip these steps
|
|
|
|
(e.g. when running on a shared host).
|
2020-04-30 15:02:13 +00:00
|
|
|
|
|
|
|
- LRU file caching -- with user-controlled cache size, max cached file size
|
|
|
|
and cache refresh frequency.
|
|
|
|
|
|
|
|
- Insert files within gophermaps, including automating reflowing of lines
|
|
|
|
longer than (user definable) page width.
|
|
|
|
|
|
|
|
- Automatic replacement of `$hostname` or `$port` with the information of
|
|
|
|
the host the client is connecting to.
|
|
|
|
|
|
|
|
- User supplied footer text appended to gophermaps and directory listings.
|
|
|
|
|
|
|
|
- Item type characters beyond RFC 1436 standard (see below).
|
|
|
|
|
|
|
|
- Separate system and access logging with output to file if requested (or to
|
|
|
|
disable both).
|
|
|
|
|
2020-04-15 16:01:00 +00:00
|
|
|
# Usage
|
|
|
|
|
|
|
|
```
|
|
|
|
gophor [args]
|
2020-05-01 16:17:12 +00:00
|
|
|
-root-dir Change server root directory.
|
2020-04-30 12:58:50 +00:00
|
|
|
|
|
|
|
-port Change server NON-TLS listening port.
|
|
|
|
|
|
|
|
-hostname Change server hostname (FQDN, used to craft dir
|
|
|
|
lists).
|
|
|
|
|
|
|
|
-bind-addr Change server bind-address (used in creating
|
|
|
|
socket).
|
|
|
|
|
|
|
|
-user Drop to supplied user's UID and GID permissions
|
|
|
|
before execution.
|
|
|
|
|
|
|
|
-system-log Path to gophor system log file, else use stderr.
|
|
|
|
|
|
|
|
-access-log Path to gophor access log file, else use stderr.
|
|
|
|
|
|
|
|
-cache-check Change file-cache freshness check frequency.
|
|
|
|
|
|
|
|
-cache-size Change max no. files in file-cache.
|
|
|
|
|
|
|
|
-cache-file-max Change maximum allowed size of a cached file.
|
|
|
|
|
|
|
|
-page-width Change page width used when formatting output.
|
|
|
|
|
|
|
|
-footer Change gophermap footer text (Unix new-line
|
|
|
|
separated lines).
|
|
|
|
|
|
|
|
-no-footer-separator Disable footer text line separator.
|
|
|
|
|
|
|
|
-restrict-files New-line separated list of regex statements
|
|
|
|
restricting files from showing in directory listing.
|
|
|
|
|
|
|
|
-description Change server description in generated caps.txt.
|
|
|
|
|
|
|
|
-admin-email Change admin email in generated caps.txt.
|
|
|
|
|
|
|
|
-geoloc Change geolocation in generated caps.txt.
|
|
|
|
|
2020-05-01 16:17:12 +00:00
|
|
|
-rootless Run without root privileges (no chroot, no privilege
|
|
|
|
drop, no restricted ports).
|
|
|
|
|
2020-04-30 12:58:50 +00:00
|
|
|
-version Print version string.
|
2020-04-15 16:01:00 +00:00
|
|
|
```
|
|
|
|
|
2020-04-12 20:31:50 +00:00
|
|
|
# Supported gophermap item types
|
|
|
|
|
2020-04-19 15:00:08 +00:00
|
|
|
All of the following item types are supported by Gophor, separated into
|
|
|
|
grouped standards. Most handling of item types is performed by the clients
|
|
|
|
connecting to Gophor, but when performing directory listings Gophor will
|
|
|
|
attempt to automatically classify files according to the below types.
|
|
|
|
|
|
|
|
Item types listed as `[SERVER ONLY]` means that these are item types
|
|
|
|
recognised ONLY by Gophor and to be used when crafting a gophermap. They
|
|
|
|
provide additional methods of formatting / functionality within a gophermap,
|
|
|
|
and the output of these item types is usually converted to informational
|
|
|
|
text lines before sending to connecting clients.
|
|
|
|
|
2020-04-12 20:31:50 +00:00
|
|
|
```
|
2020-04-19 15:00:08 +00:00
|
|
|
RFC 1436 Standard:
|
|
|
|
Type | Treat as | Meaning
|
|
|
|
0 | TEXT | Regular file (text)
|
|
|
|
1 | MENU | Directory (menu)
|
|
|
|
2 | EXTERNAL | CCSO flat db; other db
|
|
|
|
3 | ERROR | Error message
|
|
|
|
4 | TEXT | Macintosh BinHex file
|
|
|
|
5 | BINARY | Binary archive (zip, rar, 7zip, tar, gzip, etc)
|
|
|
|
6 | TEXT | UUEncoded archive
|
|
|
|
7 | INDEX | Query search engine or CGI script
|
|
|
|
8 | EXTERNAL | Telnet to: VT100 series server
|
|
|
|
9 | BINARY | Binary file (see also, 5)
|
|
|
|
T | EXTERNAL | Telnet to: tn3270 series server
|
|
|
|
g | BINARY | GIF format image file (just use I)
|
|
|
|
I | BINARY | Any format image file
|
|
|
|
+ | - | Redundant (indicates mirror of previous item)
|
|
|
|
|
|
|
|
GopherII Standard:
|
|
|
|
Type | Treat as | Meaning
|
|
|
|
c | BINARY | Calendar file
|
|
|
|
d | BINARY | Word-processing document; PDF document
|
|
|
|
h | TEXT | HTML document
|
|
|
|
i | - | Informational text (not selectable)
|
|
|
|
p | TEXT | Page layout or markup document (plain text w/ ASCII tags)
|
|
|
|
m | BINARY | Email repository (MBOX)
|
|
|
|
s | BINARY | Audio recordings
|
|
|
|
x | TEXT | eXtensible Markup Language document
|
|
|
|
; | BINARY | Video files
|
|
|
|
|
|
|
|
Commonly used:
|
|
|
|
Type | Treat as | Meaning
|
2020-04-20 07:31:42 +00:00
|
|
|
! | - | [SERVER ONLY] Menu title (set title ONCE per gophermap)
|
2020-04-19 15:00:08 +00:00
|
|
|
# | - | [SERVER ONLY] Comment, rest of line is ignored
|
|
|
|
- | - | [SERVER ONLY] Hide file/directory from directory listing
|
|
|
|
. | - | [SERVER ONLY] Last line -- stop processing gophermap default
|
|
|
|
* | - | [SERVER ONLY] Last line + directory listing -- stop processing
|
|
|
|
| | gophermap and end on a directory listing
|
|
|
|
= | - | [SERVER ONLY] Include subgophermap / regular file here. Prints
|
|
|
|
| | and formats file / gophermap in-place
|
|
|
|
|
|
|
|
Planned to be supported:
|
|
|
|
Type | Treat as | Meaning
|
|
|
|
$ | - | [SERVER ONLY] Execute shell command and print stdout here
|
2020-04-12 20:31:50 +00:00
|
|
|
```
|
|
|
|
|
2020-04-19 19:46:39 +00:00
|
|
|
# Compliance
|
|
|
|
|
|
|
|
## Item types
|
|
|
|
|
|
|
|
Supported item types are listed above.
|
|
|
|
|
|
|
|
Informational lines are sent as `i<text here>\t/\tnull.host\t0`.
|
|
|
|
|
|
|
|
Titles are sent as `i<title text>\tTITLE\tnull.host\t0`.
|
|
|
|
|
|
|
|
Web address links are sent as `h<text here>\tURL:<address>\thostname\tport`.
|
|
|
|
An HTML redirect is sent in response to any requests beginning with `URL:`.
|
|
|
|
|
|
|
|
## Policy files
|
|
|
|
|
|
|
|
Upon request, `caps.txt` can be provided from the server root directory
|
|
|
|
containing server capabiities. This can either be user or server generated.
|
|
|
|
|
|
|
|
Upon request, `robots.txt` can be provided from the server root directory
|
|
|
|
containing robot access restriction policies. This can either be user or
|
|
|
|
server generated.
|
|
|
|
|
|
|
|
## Errors
|
|
|
|
|
|
|
|
Errors are sent according to GopherII standards, terminating with a last
|
2020-04-24 11:28:55 +00:00
|
|
|
line:
|
2020-04-20 14:19:22 +00:00
|
|
|
`3<error text>CR-LF`
|
2020-04-19 19:46:39 +00:00
|
|
|
|
|
|
|
Possible Gophor errors:
|
|
|
|
```
|
|
|
|
Text | Meaning
|
|
|
|
400 Bad Request | Request not understood by server due to malformed
|
|
|
|
| syntax
|
|
|
|
401 Unauthorised | Request requires authentication
|
|
|
|
403 Forbidden | Request received but not fulfilled
|
|
|
|
404 Not Found | Server could not find anything matching requested
|
|
|
|
| URL
|
|
|
|
408 Request Time-out | Client did not produce request within server wait
|
|
|
|
| time
|
|
|
|
410 Gone | Requested resource no longer available with no
|
|
|
|
| forwarding address
|
|
|
|
500 Internal Server Error | Server encountered an unexpected condition which
|
|
|
|
| prevented request being fulfilled
|
|
|
|
501 Not Implemented | Server does not support the functionality
|
|
|
|
| required to fulfil the request
|
|
|
|
503 Service Unavailable | Server currently unable to handle the request
|
|
|
|
| due to temporary overload / maintenance
|
|
|
|
```
|
|
|
|
|
|
|
|
## Terminating full stop
|
|
|
|
|
|
|
|
Gophor will send a terminating full-stop for menus, but not for served
|
|
|
|
files.
|
|
|
|
|
|
|
|
## Placeholder text
|
|
|
|
|
2020-04-25 18:57:53 +00:00
|
|
|
All of the following are used as placeholder text in responses...
|
2020-04-19 19:46:39 +00:00
|
|
|
|
2020-04-25 18:57:53 +00:00
|
|
|
Null selector: `-`
|
2020-04-19 19:46:39 +00:00
|
|
|
|
2020-04-25 18:57:53 +00:00
|
|
|
Null host: `null.host`
|
|
|
|
|
|
|
|
Null port: `0`
|
2020-04-19 19:46:39 +00:00
|
|
|
|
2020-04-10 19:35:22 +00:00
|
|
|
# Todos
|
|
|
|
|
2020-04-20 14:19:22 +00:00
|
|
|
Shortterm:
|
2020-04-11 13:17:21 +00:00
|
|
|
|
2020-04-20 20:28:52 +00:00
|
|
|
- Set default charset -- need to think about implementation here...
|
2020-04-13 21:49:25 +00:00
|
|
|
|
2020-05-01 16:17:12 +00:00
|
|
|
- Neaten codebase after recent RequestPath addition.
|
|
|
|
|
2020-04-20 20:28:52 +00:00
|
|
|
- Fix file cache only updating if main gophermap changes (but not sub files)
|
|
|
|
-- need to either rethink how we keep track of files, or rethink how
|
|
|
|
gophermaps are stored in memory.
|
2020-04-15 11:51:34 +00:00
|
|
|
|
2020-04-20 14:19:22 +00:00
|
|
|
Longterm:
|
|
|
|
|
2020-05-01 16:17:12 +00:00
|
|
|
- Finish inline shell scripting support -- current thinking is to only allow
|
|
|
|
during rootless operation.
|
2020-04-29 17:29:54 +00:00
|
|
|
|
|
|
|
- Rotating logs -- have a check on start for a file-size, rotate out if the
|
|
|
|
file is too large. Possibly checks during run-time too?
|
|
|
|
|
|
|
|
- Add last-mod-time to directory listings -- have global time parser
|
|
|
|
object, maybe separate out separate global instances of objects (e.g.
|
|
|
|
worker related, cache related, config related?)
|
|
|
|
|
2020-04-23 20:48:42 +00:00
|
|
|
- TLS support -- ~~requires a rethink of how we're passing port functions
|
2020-04-20 20:28:52 +00:00
|
|
|
generating gopher directory entries, also there is no definitive standard
|
2020-04-23 20:48:42 +00:00
|
|
|
for this yet~~ implemented these changes! figuring out gopher + TLS itself
|
|
|
|
though? no luck yet.
|
2020-04-20 14:19:22 +00:00
|
|
|
|
2020-04-20 20:28:52 +00:00
|
|
|
- Connection throttling + timeouts -- thread to keep track of list of
|
|
|
|
recently connected IPs. Keep incremementing connection count and only
|
|
|
|
remove from list when `lastIncremented` time is greater than timeout
|
2020-04-20 14:19:22 +00:00
|
|
|
|
2020-04-20 20:28:52 +00:00
|
|
|
- More closely follow GoLang built-in net/http code style for worker -- just
|
|
|
|
a neatness thing, maybe bring some performance improvements too and a
|
|
|
|
generally different way of approaching some of the solutions to problems we
|
|
|
|
have
|
2020-04-20 14:19:22 +00:00
|
|
|
|
2020-04-13 21:55:06 +00:00
|
|
|
# Please note
|
|
|
|
|
|
|
|
During the initial writing phase the quality of git commit messages may be
|
|
|
|
low and many changes are likely to be bundled together at a time, just
|
|
|
|
because the pace of development right now is rather break-neck.
|
|
|
|
|
|
|
|
As soon as we reach a stable point in development, or if other people start
|
|
|
|
contributing issues or PRs, whichever comes first, this will be changed
|
|
|
|
right away.
|
|
|
|
|
2020-04-19 15:00:08 +00:00
|
|
|
# Resources used
|
2020-04-11 13:17:21 +00:00
|
|
|
|
|
|
|
Gopher-II (The Next Generation Gopher WWIS):
|
|
|
|
https://tools.ietf.org/html/draft-matavka-gopher-ii-00
|
|
|
|
|
2020-04-19 15:00:08 +00:00
|
|
|
Gophernicus supported item types:
|
|
|
|
https://github.com/gophernicus/gophernicus/blob/master/README.gophermap
|
|
|
|
|
2020-04-11 13:17:21 +00:00
|
|
|
All of the below can be viewed from your standard web browser using
|
|
|
|
floodgap's Gopher proxy:
|
2020-04-11 13:21:21 +00:00
|
|
|
https://gopher.floodgap.com/gopher/gw
|
2020-04-11 13:17:21 +00:00
|
|
|
|
|
|
|
RFC 1436 (The Internet Gopher Protocol:
|
|
|
|
gopher://gopher.floodgap.com:70/0/gopher/tech/rfc1436.txt
|
|
|
|
|
|
|
|
Gopher+ (upward compatible enhancements):
|
|
|
|
gopher://gopher.floodgap.com:70/0/gopher/tech/gopherplus.txt
|