Go to file
kim (grufwub) 1b21e1571e cachemap+filelist --> fixedmap implementation, delete on file stat fail
Signed-off-by: kim (grufwub) <grufwub@gmail.com>
2020-04-19 20:44:48 +01:00
.gitignore ignore *.old files (these are part of my weird dev flow) 2020-04-16 09:13:18 +01:00
build.sh add simple build script 2020-04-15 17:09:10 +01:00
cache.go cachemap+filelist --> fixedmap implementation, delete on file stat fail 2020-04-19 20:44:48 +01:00
constants.go Add support for regex-matched file restrictions in dir listings 2020-04-19 13:42:56 +01:00
error.go add error string for InvalidGophermapErr 2020-04-16 11:41:33 +01:00
file.go refactor most of file reading/caching code to use one global cache 2020-04-17 16:39:25 +01:00
fixedmap.go cachemap+filelist --> fixedmap implementation, delete on file stat fail 2020-04-19 20:44:48 +01:00
flags.go correct 'RestrictedFiles' flag description 2020-04-19 13:45:22 +01:00
format.go add function pointers for getItemType() 2020-04-19 15:21:54 +01:00
fs.go Add support for regex-matched file restrictions in dir listings 2020-04-19 13:42:56 +01:00
gophermap.go add better support for item type title 2020-04-18 23:05:25 +01:00
gophor.go additional chdir("/") made after chroot performed 2020-04-19 15:59:36 +01:00
LICENSE Create LICENSE 2020-04-10 18:54:44 +01:00
logger.go add support for different types of logging 2020-04-12 09:49:13 +01:00
policy.go fix use of CrLf with DOSLineEnd 2020-04-19 20:44:14 +01:00
README.md remove TLS port from usage instructions for now 2020-04-19 16:01:26 +01:00
regex.go add function pointers for getItemType() 2020-04-19 15:21:54 +01:00
sample.gophermap add sample gophermap 2020-04-13 14:40:03 +01:00
worker.go add support for DOS or Unix line endings in all files 2020-04-17 18:51:30 +01:00

Gophor

A Gopher server written in GoLang as a means of learning about the Gopher protocol, and more GoLang.

Possibly beta quality soon? More likely alpha right now.

build.sh and you're set to go! Just put gophor somewhere in your path.

Linux only for now.

I'm unemployed (not due to lack of effort...) 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/

Usage

gophor [args]
       -root           Change server root directory.
       -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).
       -uid            Change UID to drop privileges to.
       -gid            Change GID to drop privileges to.
       -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 (in secs).
       -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.
       -restrict-files New-line separated list of regex statements restricting
                       files from showing in directory listing.

Features

  • Built with concurrency and efficiency in mind.

  • ZERO external dependencies.

  • Security focused -- chroots into server direrctory and drops privileges. maybe wait until stable release before use outside of hobby setups.

  • 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 with your server's selected hostname if you put $hostname in your gophermap... Wanna hear me say hostname one more time?

  • Item type characters beyond RFC 1436 standard (see below).

  • Separate system and access logging with output to file if requested (or to disable both).

Supported gophermap item types

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.

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
 !   |     -    | Menu title (use on first line)
 #   |     -    | [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

Todos

  • TLS support

  • Connection throttling + timeouts

  • Header + footer text

  • Rotating logs

  • Set default charset

  • Autogenerated caps.txt

  • Proxy over HTTP support

  • Finish inline shell scripting support

  • Allow setting UID+GID via username string

  • Fix file cache only updating if main gophermap changes (but not sub files)

  • More fine-tuned handling of OS signals

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.

Resources used

Gopher-II (The Next Generation Gopher WWIS): https://tools.ietf.org/html/draft-matavka-gopher-ii-00

Gophernicus supported item types: https://github.com/gophernicus/gophernicus/blob/master/README.gophermap

All of the below can be viewed from your standard web browser using floodgap's Gopher proxy: https://gopher.floodgap.com/gopher/gw

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