add autoatom support to spartan

fixes #20
This commit is contained in:
tjpcc 2023-10-30 14:47:58 -06:00
parent 0b57acaa2d
commit e492c9d983
6 changed files with 42 additions and 20 deletions

View File

@ -310,7 +310,7 @@ The "autoatom" modifier customizes routing to recognize "<any other valid path>.
=> gemini://geminiprotocol.net/docs/companion/subscription.gmi "Subscribing to Gemini pages" gemini companion specification
Allowed contexts: static, cgi directives (no git), gemini servers (no gopher, spartan, or finger).
Allowed contexts: static, cgi directives (no git), gemini and spartan servers (no gopher or finger).
### titan <auth name>

View File

@ -29,7 +29,7 @@
The last airplane designed without the use of electronic calculators, the SR-71 was developed from concept to first flight in just over 2 years. It flew higher and faster than any jet of its time (holding the speed record to this day), and pioneered low-observability (stealth) characteristics.
This sr-71 project is a small web server, able to host your pages on the gemini, gopher, and finger protocols.
This sr-71 project is a small web server, able to host your pages on the gemini, gopher, spartan, and finger protocols.
# Getting it
@ -71,6 +71,12 @@ gopher {
static /var/gopher at / with dirdefault gophermap, dirlist, extendedgophermap
}
spartan {
host myhostname.com
static /var/spartan at / with dirdefault index.gmi, dirlist
}
finger {
static ~/.finger
}
@ -84,6 +90,8 @@ With the above configuration, sr-71 will:
* serve gopher by reading out of /var/gopher
* for gopher directory requests, it will look for a file called "gophermap", then fall back to listing the contents as gopher menu
* for any gopher files, it will apply the "extended gophermap" parsing documented below
* serve spartan by reading files from /var/spartan (perhaps imagine this being a symlink to /var/gemini)
* serve spartan directory requests by looking for index.gmi and falling back to a directory listing
* serve finger requests by reading a ".finger" file in the requested user's home directory
# Configuration Options In Detail
@ -137,6 +145,12 @@ Because of the TLS requirement, a gemini server must contain a "servertls" direc
sr-71 also supports virtualhosts in gemini, where multiple domains can be hosted on the same IP/port. This is done by having multiple "gemini {...}" blocks with the same IP and port (potentially defaults), but with "host" directives differentiating them. More on this in the section below on virtualhosting.
### spartan server
Spartan's default port is 300.
It also supports virtualhosting.
## Directives
Directives really come in two flavors: global directives and server directives. In either case, a directive is always contained on a single line, which begins (after any leading whitespace) with the type of the directive. What follows the directive type depends on that type.
@ -184,13 +198,13 @@ The "host" directive tells a server what hostname(s) it is serving. It is follow
A gopher server *must* contain a single host directive with just one hostname - this is to enable it to generate local links on generated gopher menus.
In gemini servers, host directives control virtual hosting behavior.
In gemini and spartan servers, host directives control virtual hosting behavior.
### [server] servertls
"servertls" provides servers with the paths to their TLS server credentials. It is followed by two clauses: "key <path to key file>", and "cert <path to cert file>". Both clauses are required (if a single file contains both then use that path for both clauses).
Gemini servers must always host with TLS and so require a "servertls" directive. In gopher and finger, the presence of a "servertls" directive will cause them to host their content tls-encrypted.
Gemini servers must always host with TLS and so require a "servertls" directive. In gopher and finger, the presence of a "servertls" directive will cause them to host their content tls-encrypted. It is not allowed in spartan servers.
### [server] static
@ -246,7 +260,7 @@ gemini {
}
```
"git" is not supported in finger servers, but otherwise it builds appropriate views according to the protocol of the server it is under (gemtext on gemini, gopher menu on gopher).
"git" is not supported in finger or spartan servers, but otherwise it builds appropriate views according to the protocol of the server it is under (gemtext on gemini, gopher menu on gopher).
The only supported modifier is "templates" - find more details on that in the section on "Git Viewing Templates".
@ -258,7 +272,7 @@ The routing directives "static", "cgi", and "git" support modifiers in the "with
"dirdefault" is followed by a file name, and it customizes the behavior of requests for directory paths. If the path exists and "dirdefault" is given, it will look for the provided file name within the requested directory and serve that *as the directory itself*. Think "index.html" in web servers.
Allowed contexts: static directive (neither cgi nor git), gemini or gopher servers (no finger).
Allowed contexts: static directive (neither cgi nor git), gemini, spartan, and gopher servers (no finger).
### dirlist
@ -266,7 +280,7 @@ Allowed contexts: static directive (neither cgi nor git), gemini or gopher serve
If both "dirdefault" and "dirlist" are in use then "dirdefault" will take precedence and the listing will only be built if the dirdefault filename doesn't exist.
Allowed contexts: static directive (neither cgi nor git), gemini or gopher servers (no finger).
Allowed contexts: static directive (neither cgi nor git), gemini, spartan, and gopher servers (no finger).
### exec
@ -274,7 +288,7 @@ Allowed contexts: static directive (neither cgi nor git), gemini or gopher serve
There is more detail in the section "Running CGIs" below.
Allowed contexts: static directive (neither cgi nor git), gemini/gopher/finger servers.
Allowed contexts: static directive (neither cgi nor git), gemini/gopher/spartan/finger servers.
### cmd <file path>
@ -288,13 +302,13 @@ Importantly, in all other ways it will still run as the located file:
So it can, for instance, be a good opportunity for a system administrator to impose boundaries on user CGIs in a shared hosting environment. The "cmd" script can set a nice level, increment a semaphore potentially waiting for a slot, set system resource limitations, chroot, and finally "exec ./$(basename $SCRIPT_NAME)".
Allowed contexts: "static...with exec", cgi (no git), gemini/gopher/finger servers.
Allowed contexts: "static...with exec", cgi (no git), gemini/gopher/spartan/finger servers.
### extendedgophermap
"extendedgophermap" enables lots of additional flexibility in writing the gopher menu format. The ideas are mostly borrowed from gophernicus, and sr-71's implementation is documented in more detail below in "Extended Gophermap Parsing".
Allowed contexts: static, cgi directives (no git), gopher servers (neither gemini nor finger).
Allowed contexts: static, cgi directives (no git), gopher servers (no gemini, spartan, or finger).
### autoatom
@ -302,13 +316,13 @@ The "autoatom" modifier customizes routing to recognize "<any other valid path>.
=> ["Subscribing to Gemini pages" gemini companion specification](gemini://geminiprotocol.net/docs/companion/subscription.gmi)
Allowed contexts: static, cgi directives (no git), gemini servers (neither gopher nor finger).
Allowed contexts: static, cgi directives (no git), gemini and spartan servers (no gopher or finger).
### titan <auth name>
The "titan" modifier takes an auth name (defined in a global "auth" directive) and enables the titan file upload protocol in a static route. Titan requests specifically will have to pass the named auth mechanism.
Allowed contexts: static (neither cgi nor git), gemini servers (neither gopher nor finger).
Allowed contexts: static (neither cgi nor git), gemini servers (no gopher, spartan, or finger).
### templates <dir path>
@ -316,7 +330,7 @@ Allowed contexts: static (neither cgi nor git), gemini servers (neither gopher n
The supported template names and their execution contexts are documented below in the section on "Git Viewing Templates".
Allowed contexts: git (neither static nor cgi), gemini or gopher servers (no finger).
Allowed contexts: git (neither static nor cgi), gemini or gopher servers (no spartan or finger).
# Git Viewing Templates
@ -465,7 +479,7 @@ When it runs a CGI process, sr-71 sets up a standard CGI environment for it, try
* TLS_CLIENT_SUBJECT is the subject field of the client TLS cert, if there is one
* TLS_CLIENT_SUBJECT_CN is the subject's common name of the client TLS cert, if there is one
Standard in of the CGI process is set to the request body, if there is one (this is only the case for titan requests). Standard out of the CGI process is used as the response body, and the default format for the protocol is assumed (gemtext for gemini, gopher menu for gopher, text/no format for finger). "extendedgophermap" is usable in conjunection with "cgi" or "static...with exec" in gopher servers, in which case the standard output will be processed with the gophermap extensions.
Standard in of the CGI process is set to the request body, if there is one (this is only the case for titan requests). Standard out of the CGI process is used as the response body, and the default format for the protocol is assumed (gemtext for gemini and spartan, gopher menu for gopher, text/no format for finger). "extendedgophermap" is usable in conjunection with "cgi" or "static...with exec" in gopher servers, in which case the standard output will be processed with the gophermap extensions.
The "cmd" modifier can be used on cgi and "static...with exec" directives, in which case the given world-executable file will be used in place of the resolved CGI program, however the environment will still be set up entirely as if the executable pointed at by the request is being run. This means the working directory is that of the located program (not the cmd override), and SCRIPT_NAME and PATH_INFO are set as if that program was being run. This means that a no-op cmd override could just "exec ./$(basename $SCRIPT_NAME)".
@ -502,7 +516,7 @@ gopher {
Gopher and Finger have no guarantee that a domain name will appear in a request. Therefore virtualhosting by domain doesn't make sense in these protocols. Multiple gopher or finger servers may still be defined in a configuration file, but they will have to appear on separate IPs and/or ports.
With Gemini, however, there can also be multiple servers defined on the same IP and port (perhaps defaults), which can be differentiated at request-time based on the requested domain and "host" directives in each server.
With Gemini and Spartan, however, there can also be multiple servers defined on the same IP and port (perhaps defaults), which can be differentiated at request-time based on the requested domain and "host" directives in each server.
```
gemini {

2
go.mod
View File

@ -4,7 +4,7 @@ go 1.21.0
require (
github.com/go-kit/log v0.2.1
tildegit.org/tjp/sliderule v1.4.2-0.20231010225006-0a7e966d5a09
tildegit.org/tjp/sliderule v1.4.2-0.20231030194212-634b82d24335
tildegit.org/tjp/syw v0.9.2
)

4
go.sum
View File

@ -10,7 +10,7 @@ github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKs
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
tildegit.org/tjp/sliderule v1.4.2-0.20231010225006-0a7e966d5a09 h1:dHtliQ1QrIDDO4T2Z6cQSih69p8M2SKCi5b4q9SzrTE=
tildegit.org/tjp/sliderule v1.4.2-0.20231010225006-0a7e966d5a09/go.mod h1:opdo8E25iS9X9pNismM8U7pCH8XO0PdRIIhdADn8Uik=
tildegit.org/tjp/sliderule v1.4.2-0.20231030194212-634b82d24335 h1:PUtIcLWqK0QxSt50CzxoVeA68pCOcUa2FgW2STE2GDo=
tildegit.org/tjp/sliderule v1.4.2-0.20231030194212-634b82d24335/go.mod h1:opdo8E25iS9X9pNismM8U7pCH8XO0PdRIIhdADn8Uik=
tildegit.org/tjp/syw v0.9.2 h1:bwLRXJqC5RHes2dfntgePHYnh6iIQC9FZpFBTReemQ0=
tildegit.org/tjp/syw v0.9.2/go.mod h1:Oo05KA7QibiXxoPh5jzpKUq/RG4U3nz7qs6QVitZw8I=

View File

@ -323,7 +323,7 @@ func validateRoute(serverType string, dir *RouteDirective) error {
return errors.New("'with extendedgophermap' outside gopher server")
}
if serverType != "gemini" && dir.Modifiers.AutoAtom {
if !(serverType == "gemini" || serverType == "spartan") && dir.Modifiers.AutoAtom {
return fmt.Errorf("%s servers don't support 'with autoatom'", serverType)
}
if dir.Modifiers.titanName != "" && (serverType != "gemini" || dir.Type != "static") {

View File

@ -8,6 +8,8 @@ import (
sr "tildegit.org/tjp/sliderule"
"tildegit.org/tjp/sliderule/contrib/cgi"
"tildegit.org/tjp/sliderule/contrib/fs"
"tildegit.org/tjp/sliderule/gemini"
"tildegit.org/tjp/sliderule/gemini/gemtext/atomconv"
"tildegit.org/tjp/sliderule/logging"
"tildegit.org/tjp/sliderule/spartan"
)
@ -106,6 +108,12 @@ func addSpartanStaticRoute(router *sr.Router, route RouteDirective) {
handlers = append(handlers, fs.SpartanDirectoryListing(route.FsPath, route.URLPath, nil))
}
return sr.FallthroughHandler(handlers...)
handler := sr.FallthroughHandler(handlers...)
if route.Modifiers.AutoAtom {
handler = atomconv.Auto(handler)
}
return handler
})
}