port70 - a Gopher server (RFC-1436) written in Lua.  This currently runs my
own personal Gopher server at <gopher://gopher.conman.org/> but should be
usable by people other than myself, unlike my previous Gopher server.

Features:

* Configurable filenames for Gopher index files.
* A much nicer Gopher index file format native to this program.
* Generates Gopher indexes for directories that lack a Gopher index file.
* Support for user directories.
* Support for URL: selectors.
* Support for CGI scripts
* Easily extensible with support for custom handlers.
* Experiemental support for selector redirection.
* Configuration via file.

Prerequisites:

* Lua >= 5.3
* GNU libmagic (NOTE:  this is NOT image manipulation, but file
 identification)
* LPEG >= 1.0.0
* A whole bunch of other Lua modules, available at:
       * https://github.com/spc476/lua-conmanorg
       * https://github.com/spc476/LPeg-Parsers

Installation:

This will require some work.  You will need to download the modules listed
above from Github and get them installed.  The lua-conmanorg repository will
take some futzing around to get it compiled (first hint:  remove any mention
of tcc in the Makefile).  But once you have all the prerequisites installed,
the server should just work.

Bulding:

Just type "make".  If you have the Lua include files in a non-standard
location, you may need to do:

       make LUA_INCDIR=/path/to/Lua/includes

or even

       make LUA=<luaexec> LUA_INCDIR=/path/to/Lua/includes

You can do "make install" if you want to install the server onto the system:

       make install

This will install files in the following locations:

       /usr/local/bin/port70            # server
       /usr/local/lib/lua/5.3/port70/   # server modules (written in C)
       /usr/local/share/lua/5.3/port70/ # server modules (written in Lua)

To fine tune, you can from the command line:

       make [location] install

The various [location] options are (multiple can be specified)

       prefix=target-dir

               target-dir/bin/port70
               target-dir/lib/lua/5.3/port70/
               target-dir/share/lua/5.3/port70/

       LUADIR=target-dir

               target-dir/port70/      # modules written in Lua

       LIBDIR=target-dir

               target-dir/port70/      # modules written in C

       BINDIR=target-dir

               target-dir/port70/      # server program

Configuration:

The file "minimal-conf.lua" is the bare minimum configuration file you'll
need to serve up files from a directory, but do look at the sample-conf.lua
file as that has extensive comments about each section and what is required,
and what isn't.  It will help to know some Lua, especially Lua string
patterns (its form of regex) as various sections of the configuration are
applied to requests via pattern matching of the request.

Gopher Index files

While the standard gopher index file format described in RFC-1436:

       0This is a file<HT>file-selector<HT>example.com<HT>70<CRLF>

this program does have its own gopher index file that is easier to write and
less error prone.  Lines that do NOT start with a tab (<HT>) are converted
as is to the gopher 'i' type (information).  Lines that do start with a tab
are converted.  The generalized format is:

       <HT>type<HT>selector<HT>description

The following types supported are:

       file    selector refers to a text file (type 0)
       dir     selector refers to a directory (type 1)
       CSO     selector refers to a CSO phone-book server (type 2)
       binhex  selector refers to a BinHexed Macintosh file (type 4)
       EXE     selector refers to an executable file (type 5)
       uuencode selector refers to a UNIX uuencoded file (type 6)
       search  selector refers to an Index-Search server (type 7)
       telnet  selector refers to a text-based telnet session (type 8)
       binary  selector refers to a binary file (type 9)
       gif     selector refers to a GIF file (type g)
       image   selector refers to a non-GIF image file (type I)
       html    selector refers to an HTML file (type h)
       url     selector is a URL (more below)

The 'url' type is special since the selector is an actual URL---what type is
used determined by the URL given (a full URL is expected, with scheme).
Example:

       url     gopher://gopher.example.com/    Some random server

will create a type 1 entry (directory) with a blank selector, a host of
"gopher.example.com" and a port number of 70.

       url     https://www.example.com/        Some other random server

will create a type h entry (HTML) with a selector of
"URL:https://www.example.com".

One final type is supported to allow dynamic content in the page to be
generated.  If the type is "Lua{", the following lines until a "Lua}" will
be collected and executed as Lua code.  The only global available will be
the require() function, allowing one to include other Lua modules without
polluting the namespace of the main program.

The "share/index.port70" is an example of this format.  It will generate a
file that closely matches the "share/index.gopher" file (sans the dynamic
output).