diff options
Diffstat (limited to 'krebs/5pkgs')
-rw-r--r-- | krebs/5pkgs/override/default.nix | 3 | ||||
-rw-r--r-- | krebs/5pkgs/simple/cyberlocker-tools/default.nix | 19 | ||||
-rw-r--r-- | krebs/5pkgs/simple/htgen-cyberlocker/default.nix | 29 | ||||
-rw-r--r-- | krebs/5pkgs/simple/htgen-cyberlocker/src/htgen-cyberlocker | 79 |
4 files changed, 130 insertions, 0 deletions
diff --git a/krebs/5pkgs/override/default.nix b/krebs/5pkgs/override/default.nix index 4cb6a1cb4..c2149ae55 100644 --- a/krebs/5pkgs/override/default.nix +++ b/krebs/5pkgs/override/default.nix @@ -18,6 +18,9 @@ self: super: { "0.9.0" = [ ./flameshot/flameshot_imgur_0.9.0.patch ]; + "0.10.1" = [ + ./flameshot/flameshot_imgur_0.9.0.patch + ]; }.${old.version}; }); diff --git a/krebs/5pkgs/simple/cyberlocker-tools/default.nix b/krebs/5pkgs/simple/cyberlocker-tools/default.nix new file mode 100644 index 000000000..80593bcae --- /dev/null +++ b/krebs/5pkgs/simple/cyberlocker-tools/default.nix @@ -0,0 +1,19 @@ +{ pkgs }: +pkgs.symlinkJoin { + name = "cyberlocker-tools"; + paths = [ + (pkgs.writers.writeDashBin "cput" '' + set -efu + path=''${1:-$(hostname)} + + ${pkgs.curl}/bin/curl -Ss --data-binary @- "http://c.r/$path" + echo "http://c.r/$path" + '') + (pkgs.writers.writeDashBin "cdel" '' + set -efu + path=$1 + + ${pkgs.curl}/bin/curl -X DELETE "http://c.r/$path" + '') + ]; +} diff --git a/krebs/5pkgs/simple/htgen-cyberlocker/default.nix b/krebs/5pkgs/simple/htgen-cyberlocker/default.nix new file mode 100644 index 000000000..515ea3cf9 --- /dev/null +++ b/krebs/5pkgs/simple/htgen-cyberlocker/default.nix @@ -0,0 +1,29 @@ +with import <stockholm/lib>; +{ pkgs, stdenv }: +stdenv.mkDerivation rec { + pname = "htgen-cyberlocker"; + version = "1.0.0"; + + src = ./src; + + buildPhase = '' + ( + exec > htgen-cyberlocker + echo PATH=${makeBinPath [ + pkgs.coreutils + pkgs.file + pkgs.findutils + pkgs.gnugrep + pkgs.jq + pkgs.nix + pkgs.utillinux + ]} + echo STATEDIR=${shell.escape "\${STATEDIR-$HOME}"} + cat $src/htgen-cyberlocker + ) + ''; + + installPhase = '' + install -D htgen-cyberlocker $out/bin/htgen-cyberlocker + ''; +} diff --git a/krebs/5pkgs/simple/htgen-cyberlocker/src/htgen-cyberlocker b/krebs/5pkgs/simple/htgen-cyberlocker/src/htgen-cyberlocker new file mode 100644 index 000000000..6c3ed6552 --- /dev/null +++ b/krebs/5pkgs/simple/htgen-cyberlocker/src/htgen-cyberlocker @@ -0,0 +1,79 @@ +delete_response() { + jq -n -r \ + --arg server "$Server" \ + ' + [ "HTTP/1.1 204 OK\r" + , "Connection: close\r" + , "Server: \($server)\r" + , "\r" + ][] + ' +} + +file_response() {( + type=$(file -ib "$1") + size=$(wc -c < "$1") + jq -n -r \ + --arg type "$type" \ + --arg size "$size" \ + --arg server "$Server" \ + ' + [ "HTTP/1.1 200 OK\r" + , "Connection: close\r" + , "Content-Length: \($size)\r" + , "Content-Type: \($type)\r" + , "Server: \($server)\r" + , "\r" + ][] + ' + cat "$1" +)} + +read_uri() { + jq -cn --arg uri "$1" ' + $uri | + capture("^((?<scheme>[^:]*):)?(//(?<authority>[^/]*))?(?<path>[^?#]*)([?](?<query>[^#]*))?([#](?<fragment>.*))?$") | + . + { + query: (.query | if . != null then + split("&") | + map(split("=") | {key:.[0],value:.[1]}) | + from_entries + else . end) + } + ' +} + +uri=$(read_uri "$Request_URI") +path=$(jq -nr --argjson uri "$uri" '$uri.path') + +case "$Method $path" in + 'POST /'*|'PUT /'*) + content=$(mktemp -t htgen.$$.content.XXXXXXXX) + trap "rm $content >&2" EXIT + + head -c $req_content_length > $content + + item=$STATEDIR/items/$(echo "$path" | jq -rR @uri) + + mkdir -v -p $STATEDIR/items >&2 + cp -v $content $item >&2 + + scheme=${req_x_forwarded_proto-http} + link=$scheme://$req_host/$path + + ;; + 'GET /'*) + item=$STATEDIR/items/$(echo "$path" | jq -rR @uri) + if [ -e "$item" ]; then + file_response "$item" + exit + fi + ;; + 'DELETE /'*) + item=$STATEDIR/items/$(echo "$path" | jq -rR @uri) + if [ -e "$item" ]; then + rm "$item" + delete_response + exit + fi +esac |