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
|
|
|
|
|
2020-05-03 21:43:49 +00:00
|
|
|
- Built with security, concurrency and efficiency in mind.
|
2020-04-30 15:02:13 +00:00
|
|
|
|
|
|
|
- ZERO external dependencies.
|
|
|
|
|
2020-05-03 21:43:49 +00:00
|
|
|
- LRU file caching with user-controlled cache size, max cached file size
|
2020-04-30 15:02:13 +00:00
|
|
|
and cache refresh frequency.
|
|
|
|
|
2020-05-06 10:39:24 +00:00
|
|
|
- CGI/1.1 support (see below for CGI environment variables set).
|
2020-05-03 21:43:49 +00:00
|
|
|
|
2020-05-03 22:04:59 +00:00
|
|
|
- HTTP style URL query and encoding support.
|
|
|
|
|
2020-05-14 12:14:51 +00:00
|
|
|
- Serve `DIR/gophermap` by default, else falls back to directory listing.
|
|
|
|
|
|
|
|
- Parsing of any files named `gophermap` / ending in `.gophermap` as
|
|
|
|
gophermaps.
|
|
|
|
|
2020-05-03 21:43:49 +00:00
|
|
|
- Executable gophermap support.
|
|
|
|
|
2020-05-14 12:14:51 +00:00
|
|
|
- Insert files with automated line reflowing, output of any CGI scripts
|
|
|
|
or executable gophermaps WITHIN gophermaps.
|
2020-04-30 15:02:13 +00:00
|
|
|
|
2020-05-03 21:43:49 +00:00
|
|
|
- Support for all commonly accepted item type characters (beyond just
|
|
|
|
RFC1436 support).
|
|
|
|
|
|
|
|
- Automatic replacement of `$hostname` or `$port` in gophermap lines with
|
|
|
|
current host information.
|
2020-04-30 15:02:13 +00:00
|
|
|
|
|
|
|
- User supplied footer text appended to gophermaps and directory listings.
|
|
|
|
|
2020-05-03 21:43:49 +00:00
|
|
|
- Separate system and access logging with output and formatting options.
|
|
|
|
|
2020-05-06 10:39:24 +00:00
|
|
|
## Please note
|
|
|
|
|
|
|
|
### Gophermap parsing
|
|
|
|
|
|
|
|
Due to the way that gophermap parsing is handled, if a gophermap is larger than
|
2020-05-08 16:53:10 +00:00
|
|
|
the max cache'd file size or file caching is disabled (same as
|
|
|
|
same as setting max size to 0), these gophermaps WILL NOT be parsed by the server.
|
|
|
|
The features you will miss out on for these files are features listed
|
2020-05-06 10:39:24 +00:00
|
|
|
`[SERVER ONLY]` in the gophermap item types section below.
|
|
|
|
|
|
|
|
### Chroots and privilege dropping
|
|
|
|
|
|
|
|
Previously, chrooting to server directory and dropping privileges was supported
|
2020-05-08 16:53:10 +00:00
|
|
|
by using Go C bindings. This is not officially supported due to weird behaviour
|
|
|
|
with `.Set{U,G}id()` under Linux. As such, the feature has been dropped for
|
|
|
|
now.
|
|
|
|
|
|
|
|
There is a near 10 year ongoing tracked issue
|
|
|
|
(https://github.com/golang/go/issues/1435), and as soon as this patch gets
|
|
|
|
merged I'll add support: https://go-review.googlesource.com/c/go/+/210639
|
2020-05-03 21:43:49 +00:00
|
|
|
|
2020-05-03 21:49:38 +00:00
|
|
|
In place of removing this, request sanitization has been majorly improved and
|
|
|
|
checks are in place to prevent running Gophor as root.
|
2020-05-03 21:43:49 +00:00
|
|
|
|
|
|
|
If you run into issues binding to a lower port number due to insufficient
|
|
|
|
permissions then there are a few alternatives:
|
|
|
|
|
2020-05-08 16:53:10 +00:00
|
|
|
- set gophor process capabilities: e.g.
|
|
|
|
`setcap 'cap_net_bind_service=+ep' /usr/local/bin/gophor`
|
2020-05-03 21:43:49 +00:00
|
|
|
|
|
|
|
- use Docker (or some other solution) and configure port forwarding on the
|
|
|
|
host
|
|
|
|
|
2020-05-03 21:49:38 +00:00
|
|
|
- start gopher in it's own namespace in a chroot
|
2020-04-30 15:02:13 +00:00
|
|
|
|
2020-04-15 16:01:00 +00:00
|
|
|
# Usage
|
|
|
|
|
|
|
|
```
|
|
|
|
gophor [args]
|
2020-05-06 11:02:49 +00:00
|
|
|
-root Change server root directory.
|
|
|
|
-bind-addr Change server bind-address (used in creating
|
|
|
|
socket).
|
2020-05-06 10:39:24 +00:00
|
|
|
-port Change server bind port.
|
2020-05-06 11:02:49 +00:00
|
|
|
|
2020-05-06 10:39:24 +00:00
|
|
|
-fwd-port Change port used in $port replacement strings
|
|
|
|
(e.g. when port forwarding).
|
2020-05-06 11:02:49 +00:00
|
|
|
-hostname Change server hostname (FQDN).
|
2020-04-30 12:58:50 +00:00
|
|
|
|
2020-05-02 21:58:31 +00:00
|
|
|
-system-log Path to gophor system log file.
|
|
|
|
-access-log Path to gophor access log file.
|
|
|
|
-log-output Change log output type (disable|stderr|file)
|
|
|
|
-log-opts Comma-separated list of lop opts (timestamp|ip)
|
2020-04-30 12:58:50 +00:00
|
|
|
|
2020-05-06 11:02:49 +00:00
|
|
|
-file-monitor-freq Change file-cache freshness check frequency.
|
2020-05-12 12:53:16 +00:00
|
|
|
-file-remap New-line separated list of file remappings of format:
|
|
|
|
/virtual/relative/path -> /actual/relative/path
|
|
|
|
|
2020-04-30 12:58:50 +00:00
|
|
|
-cache-size Change max no. files in file-cache.
|
|
|
|
-cache-file-max Change maximum allowed size of a cached file.
|
2020-05-03 21:43:49 +00:00
|
|
|
-disable-cache Disable file caching.
|
2020-04-30 12:58:50 +00:00
|
|
|
|
|
|
|
-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.
|
2020-05-06 11:02:49 +00:00
|
|
|
|
2020-04-30 12:58:50 +00:00
|
|
|
-restrict-files New-line separated list of regex statements
|
2020-05-06 11:02:49 +00:00
|
|
|
(checked against absolute paths) restricting
|
|
|
|
file access.
|
2020-04-30 12:58:50 +00:00
|
|
|
|
|
|
|
-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-08 16:53:10 +00:00
|
|
|
-disable-cgi Disable CGI and all executable support.
|
2020-05-10 09:08:57 +00:00
|
|
|
-http-compat-cgi Enable HTTP CGI script compatibility (will strip
|
|
|
|
HTTP headers).
|
|
|
|
-http-header-buf Change max CGI read count to look for and strip
|
|
|
|
HTTP headers before sending raw (bytes).
|
2020-05-08 16:53:10 +00:00
|
|
|
-safe-path Set safe PATH variable to be used when executing
|
|
|
|
CGI scripts, gophermaps and inline shell
|
|
|
|
commands.
|
|
|
|
-max-exec-time Change max executable CGI, gophermap and inline
|
|
|
|
shell command runtime.
|
|
|
|
|
|
|
|
-socket-write-buf Change socket write buffer size (bytes).
|
|
|
|
-socket-read-buf Change socket read buffer size (bytes).
|
|
|
|
-socket-read-max Change socket read count max (integer multiplier
|
|
|
|
to socket-read-buf-max).
|
|
|
|
-file-read-buf Change file read buffer size (bytes).
|
|
|
|
|
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
|
2020-05-06 10:39:24 +00:00
|
|
|
--------------------------
|
2020-04-19 15:00:08 +00:00
|
|
|
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
|
2020-05-06 10:39:24 +00:00
|
|
|
--------------------------
|
2020-04-19 15:00:08 +00:00
|
|
|
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-05-06 10:39:24 +00:00
|
|
|
--------------------------
|
|
|
|
. | - | Last line -- stop processing gophermap default
|
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 + directory listing -- stop processing
|
|
|
|
| | gophermap and end on a directory listing
|
2020-05-12 12:51:01 +00:00
|
|
|
= | - | [SERVER ONLY] Include or execute subgophermap, cgi-bin or regular
|
|
|
|
| | file here.
|
2020-04-12 20:31:50 +00:00
|
|
|
```
|
|
|
|
|
2020-04-19 19:46:39 +00:00
|
|
|
# Compliance
|
|
|
|
|
2020-05-08 16:53:10 +00:00
|
|
|
We aim to comply more with GopherII (see in references below).
|
2020-05-06 11:44:40 +00:00
|
|
|
|
2020-04-19 19:46:39 +00:00
|
|
|
## 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:`.
|
|
|
|
|
2020-05-06 10:39:24 +00:00
|
|
|
## CGI/1.1
|
|
|
|
|
|
|
|
The list of environment variables that gophor sets are as follows.
|
|
|
|
|
|
|
|
RFC 3875 standard:
|
|
|
|
|
|
|
|
```
|
|
|
|
# Set
|
|
|
|
GATEWAY INTERFACE
|
|
|
|
SERVER_SOFTWARE
|
|
|
|
SERVER_PROTOCOL
|
|
|
|
CONTENT_LENGTH
|
|
|
|
REQUEST_METHOD
|
|
|
|
SERVER_NAME
|
|
|
|
SERVER_PORT
|
|
|
|
REMOTE_ADDR
|
|
|
|
QUERY_STRING
|
|
|
|
SCRIPT_NAME
|
|
|
|
SCRIPT_FILENAME
|
|
|
|
|
|
|
|
# NOT set
|
|
|
|
Env Var | Reasoning
|
|
|
|
----------------------------------------------
|
|
|
|
PATH_INFO | This variable can fuck off, having to find the shortest
|
|
|
|
| valid part of path heirarchy in a URI every single
|
|
|
|
| CGI request so you can split and set this variable is SO
|
|
|
|
| inefficient. However, if someone more knowledgeable has
|
|
|
|
| other opinions or would like to point out where I'm wrong I
|
|
|
|
| will happily change my tune on this.
|
|
|
|
PATH_TRANSLATED | See above.
|
|
|
|
AUTH_TYPE | Until we implement authentication of some kind, ignoring.
|
|
|
|
CONTENT_TYPE | Very HTTP-centric relying on 'content-type' header.
|
|
|
|
REMOTE_IDENT | Remote client identity information.
|
|
|
|
REMOTE_HOST | Basically if the client has a resolving name (not just
|
|
|
|
| IP), not really necessary.
|
|
|
|
REMOTE_USER | Remote user id, not used as again no user auth yet.
|
|
|
|
```
|
|
|
|
|
|
|
|
Non-standard:
|
|
|
|
|
|
|
|
```
|
|
|
|
# Set
|
|
|
|
SELECTOR
|
|
|
|
DOCUMENT_ROOT
|
|
|
|
REQUEST_URI
|
|
|
|
PATH
|
|
|
|
COLUMNS
|
|
|
|
GOPHER_CHARSET
|
|
|
|
```
|
|
|
|
|
2020-04-19 19:46:39 +00:00
|
|
|
## 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
|
2020-05-06 11:11:42 +00:00
|
|
|
or executed files.
|
2020-04-19 19:46:39 +00:00
|
|
|
|
2020-05-06 11:11:42 +00:00
|
|
|
## Placeholder (null) text
|
2020-04-19 19:46:39 +00:00
|
|
|
|
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-05-08 16:53:10 +00:00
|
|
|
- Set default character encoding as US-ASCII
|
|
|
|
|
2020-05-12 12:51:01 +00:00
|
|
|
- Move filesystem_read functions to FileSystem struct function
|
2020-05-01 16:17:12 +00:00
|
|
|
|
2020-05-08 16:53:10 +00:00
|
|
|
- FastCGI support
|
2020-04-15 11:51:34 +00:00
|
|
|
|
2020-05-04 19:01:36 +00:00
|
|
|
- Personal user gopherspaces
|
|
|
|
|
2020-05-03 21:43:49 +00:00
|
|
|
- Rotating logs
|
2020-04-20 14:19:22 +00:00
|
|
|
|
2020-05-03 21:43:49 +00:00
|
|
|
- TLS support
|
2020-04-13 21:55:06 +00:00
|
|
|
|
2020-05-03 21:43:49 +00:00
|
|
|
- Connection throttling + timeouts
|
2020-04-13 21:55:06 +00:00
|
|
|
|
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-05-06 11:44:40 +00:00
|
|
|
Gophernicus source (a great gopher daemon in C):
|
|
|
|
https://github.com/gophernicus/gophernicus
|
2020-04-19 15:00:08 +00:00
|
|
|
|
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
|