MoonGem

所属分类:加密解密
开发工具:C
文件大小:38KB
下载次数:0
上传日期:2022-12-16 04:23:38
上 传 者sh-1993
说明:  具有服务器端内联Lua脚本功能的Gemini服务器
(A Gemini server featuring server-side inline Lua scripting)

文件列表:
.build.yml (563, 2022-12-16)
CMakeLists.txt (2444, 2022-12-16)
Dockerfile (1053, 2022-12-16)
LICENSE (1051, 2022-12-16)
container (0, 2022-12-16)
container\start.sh (430, 2022-12-16)
docker-compose.yml (153, 2022-12-16)
include (0, 2022-12-16)
include\cert.h (375, 2022-12-16)
include\gemini.h (2273, 2022-12-16)
include\hashdef.h (1409, 2022-12-16)
include\log.h (626, 2022-12-16)
include\net.h (269, 2022-12-16)
include\options.h (441, 2022-12-16)
include\parse.h (732, 2022-12-16)
include\script.h (847, 2022-12-16)
include\signals.h (251, 2022-12-16)
include\status.h (1379, 2022-12-16)
include\store.h (597, 2022-12-16)
include\uri.h (528, 2022-12-16)
include\util.h (273, 2022-12-16)
lib (0, 2022-12-16)
lib\CMakeLists.txt (336, 2022-12-16)
lib\argparse (0, 2022-12-16)
lib\wyhash (0, 2022-12-16)
src (0, 2022-12-16)
src\api.c (15272, 2022-12-16)
src\cert.c (2917, 2022-12-16)
src\gemini.c (13894, 2022-12-16)
src\main.c (3131, 2022-12-16)
src\net.c (2580, 2022-12-16)
src\options.c (5638, 2022-12-16)
src\parse.c (3627, 2022-12-16)
src\script.c (10217, 2022-12-16)
src\signals.c (1847, 2022-12-16)
src\store.c (4169, 2022-12-16)
... ...

[![builds.sr.ht status](https://builds.sr.ht/~panda-roux/MoonGem.svg)](https://builds.sr.ht/~panda-roux/MoonGem?) # MoonGem ## Introduction MoonGem is a Gemini protocol server written in C. It supports serving static files as well as Gemtext (.gmi) files with inline Lua scripting. An example page might look like this: ``` # Example 1 Lua scripts are enclosed by double curly-braces. {{ for i = 1, 10 do mg.line(i) end }} # Example 2 If a script returns a string, that string will be written to the page verbatim. {{ return "Meow!" }} # Example 3 {{ mg.head("Script blocks may span multiple lines", 2) mg.line("There are several methods that modify response headers") mg.set_language("en-US") }} ``` ## Dependencies - OpenSSL 1.1.1 or later - Lua 5.4 (5.3 may work but I haven't tried it) - LibMagic - LibEvent 2.1 ## Installation ``` git clone https://git.panda-roux.dev/MoonGem cd MoonGem && git submodule update --init cmake -B build . && cd build make && sudo make install ``` ## Usage ``` Usage: moongem [options] --cert=cert.pem --key=key.pem or: moongem [options] -c cert.pem -k key.pem A Gemini server with inline Lua scripting for generating dynamic content -h, --help show this help message and exit Cryptography -c, --cert= (required) certificate file path (.pem) -k, --key= (required) key file path (.pem) Network -p, --port= port to listen for Gemini requests on (default: 1965) Content -r, --root= root directory from which to serve content (default: current) -c, --chunk= size in bytes of the chunks loaded into memory while serving static files (default: 16384) Middleware -b, --before= script to be run before each request is handled -a, --after= script to be run after a request has resulted in a success response code (20) -e, --error= script to be run after a request has resulted in an error response code (40 thru 59) ``` ## Docker Compose Example Usage ``` # clone the repository git clone https://git.panda-roux.dev/MoonGem && cd MoonGem # generate a self-signed certificate openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 3650 -nodes -subj "/CN=localhost" # create a document echo "Hi you!" > index.gmi # allow the container to read files chmod ***4 *.pem chmod ***4 index.gmi # start the container docker-compose up ``` ## API The start and end of script sections are indicated with a double curly-braces. - Start: `{{` - End: `}}` All of the MoonGem-defined functionality is contained within a table called `mg`. ### Pre-Request These methods are only accessible from pre-request scripts. - `mg.set_path([new-path])` - Overrides the incoming request path with a new value, or `/` if one is not provided - This can be useful for implementing virtual directories and other URL-reinterpretation features - `mg.set_input([new-input])` - Overrides the incoming request's input string, or removes it if no new value is provided - `mg.interrupt()` - Instructs MoonGem to bypass the rest of the requet-handling pipeline and use the current response state - Unless otherwise set, the default response status code will be 20 (OK) ### Key/Value Store MoonGem implements an in-memory key/value store accessed via the `mg.store` table. This feature is useful for establishing state that's persistent across multiple requests. - `#mg.store` - Returns the number of stored key/value pairs - `mg.store.dump([path])` - Writes the contents of the data store in a tab-separated format to a file at `path`, or stdout if `path` is ommitted - `mg.store.get_info()` - Returns a table with the following fields: - `length`: The number of stored key/value pairs - `capacity`: The total number of slots allocated - `data_size`: The combined length of all of the stored values, in bytes ### Body These methods modify the body of the Gemini page. - `mg.include()` - Inserts the contents of the file at into the page verbatim - The file is not processed in any way - `mg.write()` - Writes `text` to the page - `mg.line([text])` - Writes `text` to the page followed by a line break - `mg.link(, [text])` - Writes a link to `url` on the page, and optionally includes the alt-text `text` - `mg.head(, [level])` - Writes a header line containing `text` to the page, with an optional header level - The default header level is 1 (i.e. a single '#' character) - `mg.quote()` - Writes `text` in a quotation line to the page - `mg.block()` - Writes `text` in a preformatted block to the page - `mg.begin_block([alt-text])` - Writes the beginning of a preformatted block to the page, with optional `alt-text` - `mg.end_block()` - Writes the end of a preformatted block to the page - Should follow `mg.begin_block` ### Header These methods modify the response header. If a method is called which modifies the response's status code (which all but the first of these do), then no further scripts will be run and the server will send the response immediately. - `mg.set_language()` - Sets the `lang` portion of the response header, indicating the language(s) that the page is written in - `mg.set_mimetype()` - Sets the response mimetype string, indicating the type of content being delivered. The default for gemtext documents is `text/gemini; charset=utf-8`. - `mg.success()` - Sets the response status code to 20 (OK) - Only really useful in pre- and post-request scripts - `mg.temp_redirect()` - Responds with a code-30 temporary redirect to `url` - `mg.redirect()` - Responds with a code-31 redirect to `url` - The following methods each causes the server to respond with one of the status codes in the 40 to 60 range. An optional `meta` string may be appended to the response in order to provide the client with more information. - `mg.temp_failure([meta])` - `mg.unavailable([meta])` - `mg.cgi_error([meta])` - `mg.proxy_error([meta])` - `mg.slow_down([meta])` - `mg.failure([meta])` - `mg.not_found([meta])` - `mg.gone([meta])` - `mg.proxy_refused([meta])` - `mg.bad_request([meta])` - `mg.cert_required([meta])` - `mg.unauthorized([meta])` ### Input These methods are concerned with handling user-input. - `mg.get_path()` - Returns the path portion of the requested URL - This path is standardized to include a default document (index.gmi) if one is not present (see get_raw_path) - `mg.get_raw_path()` - Returns the path as requested by the client, prior to standardization - `mg.get_input([meta])` - If an input argument was included in the request URL, this method returns that value - If no input was provided in the request, then the server responds with a code-10 status response and optional `meta` string - `mg.get_sensitive_input([meta])` - Same as `mg.get_input`, but uses status code 11 - Client support for this is status code is not guaranteed - `mg.has_input()` - Returns `true` if there was an input argument included in the request - Otherwise returns `false` ### Certificate - `mg.get_cert([meta])` - If a client certificate was provided along with the request, then a table with the following members is returned: - `fingerprint`: a string representing an SHA256 hash of the certificate's modulus in hexadecimal format - `not_after`: a unix timestamp representing the expiration time of the certificate - If no client certificate was provided with the request, then the server responds with a code-60 status and optional `meta` string - If client certificates are an optional feature of your application, use `mg.has_cert` to check whether one exists before calling this method in order to avoid the code-60 response - TODO: fetch additional fields from the cert (CN, etc.) - `mg.has_cert()` - Returns `true` if a client certificate was included along with the request - Otherwise returns `false`

近期下载者

相关文件


收藏者