From cd8a9a1168768e7de103f645d6964462eaacd8b7 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Mon, 10 May 2021 13:23:30 +0000 Subject: [PATCH] initial commit Signed-off-by: Christine Dodrill --- .envrc | 1 + .gitignore | 4 ++++ gemini.moon | 55 +++++++++++++++++++++++++++++++++++++++++++++ nix/lua.nix | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ shell.nix | 13 +++++++++++ var/.gitignore | 2 ++ 6 files changed, 135 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 gemini.moon create mode 100644 nix/lua.nix create mode 100644 shell.nix create mode 100644 var/.gitignore diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..051d09d --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +eval "$(lorri direnv)" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0771553 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/luarocks +/lua +/lua_modules +/.luarocks diff --git a/gemini.moon b/gemini.moon new file mode 100644 index 0000000..f91f03d --- /dev/null +++ b/gemini.moon @@ -0,0 +1,55 @@ +cqueues = require "cqueues" +socket = require "cqueues.socket" +ln = require "ln" +url = require "net.url" + +srv = socket.listen "127.0.0.1", "58816" + +cq = cqueues.new! + +class ProxyRequestRefusedHandler + run: (ctx, conn) => + conn\write "53 Proxy request refused \r\n" + ln.log ctx, {status: 53} + +class Server + new: (cq, hdlr) => + @cq = cq + @hdlr = hdlr + + listen: (srv) => + @cq\wrap -> + for conn in srv\clients! + @cq\wrap -> + with conn + _, ip = \peername! + request = \read "*l" + u = url.parse request + ctx = + :ip + host: u.host + path: u.path + query: u.query + @hdlr\run ctx, conn + \close! + +-- cq\wrap -> +-- for conn in srv\clients! +-- cq\wrap -> +-- with conn +-- _, ip = \peername! +-- request = \read "*l" +-- u = url.parse request +-- ctx = +-- :ip +-- host: u.host +-- path: u.path +-- query: u.query +-- ln.log ctx +-- \write "53 Proxy request refused\r\n" +-- \close! + +with Server cq, ProxyRequestRefusedHandler! + \listen srv + +assert cq\loop! diff --git a/nix/lua.nix b/nix/lua.nix new file mode 100644 index 0000000..405432f --- /dev/null +++ b/nix/lua.nix @@ -0,0 +1,60 @@ +{ pkgs ? import { }, fetchurl ? pkgs.fetchurl }: + +with pkgs.lua5_3.pkgs; + +let + router = buildLuarocksPackage { + pname = "router"; + version = "2.1-0"; + + src = fetchurl { + url = "https://luarocks.org/router-2.1-0.src.rock"; + sha256 = "15v2ks5wwv6y7122a1p0r9mh6kfymvh756pb4ax13cy0d0vf362m"; + }; + disabled = (luaOlder "5.1"); + propagatedBuildInputs = [ lua ]; + + meta = with lib; { + homepage = "https://github.com/APItools/router.lua"; + description = + "A barebones router for Lua. It matches urls and executes lua functions"; + license.fullName = "MIT"; + }; + }; + + net-url = buildLuarocksPackage { + pname = "net-url"; + version = "0.9-1"; + + src = fetchurl { + url = "https://luarocks.org/net-url-0.9-1.src.rock"; + sha256 = "12qrb8x95qicq6fp5jfiq6v9h8flngk92bb5vnzph3avpllij3zx"; + }; + disabled = (luaOlder "5.1"); + propagatedBuildInputs = [ lua ]; + + meta = with lib; { + homepage = "https://github.com/golgote/neturl"; + description = "URL and Query string parser, builder, normalizer for Lua."; + license.fullName = "MIT/X11"; + }; + }; + + ln = buildLuarocksPackage { + pname = "ln"; + version = "0.2.1-2"; + + src = fetchurl { + url = "https://luarocks.org/ln-0.2.1-2.src.rock"; + sha256 = "1hb1vw68w407y05nprp352c0di6iybz4gjdhc0p521cpif4l8i1l"; + }; + propagatedBuildInputs = [ lua dkjson ]; + + meta = with lib; { + homepage = "https://tulpa.dev/cadey/lua-ln"; + description = "The natural log function"; + license.fullName = "0bsd"; + }; + }; + +in lua.withPackages (ps: with ps; [ cqueues luaossl router net-url ln ]) diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..d46943b --- /dev/null +++ b/shell.nix @@ -0,0 +1,13 @@ +{ pkgs ? import { } }: + +let lua = pkgs.callPackage ./nix/lua.nix { }; + +in pkgs.mkShell { + buildInputs = with pkgs; + with lua53Packages; [ + luarocks-nix + lua + busted + moonscript + ]; +} diff --git a/var/.gitignore b/var/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/var/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore