From 1feb294a75d4572d7772533e29ae9a28e636d095 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 30 Apr 2020 16:46:41 +0200 Subject: htgen: 1.2.2 -> 1.2.3 --- krebs/5pkgs/simple/htgen/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'krebs/5pkgs/simple') diff --git a/krebs/5pkgs/simple/htgen/default.nix b/krebs/5pkgs/simple/htgen/default.nix index 0fca8bdf2..a44c1a7d0 100644 --- a/krebs/5pkgs/simple/htgen/default.nix +++ b/krebs/5pkgs/simple/htgen/default.nix @@ -1,14 +1,14 @@ { coreutils, dash, fetchgit, gnused, stdenv, ucspi-tcp }: with import ; let - version = "1.2.2"; + version = "1.2.3"; in stdenv.mkDerivation { name = "htgen-${version}"; src = fetchgit { url = "http://cgit.krebsco.de/htgen"; rev = "refs/tags/v${version}"; - sha256 = "0a8vn35vq6pxgk6d3d2cjp0vdxzq9nqf0zgkvnd6668v4cmdf91b"; + sha256 = "0lml336w31ckgspp633ym2jnppzln3f8mvmy3y2vz9yanf59j0hb"; }; installPhase = '' -- cgit v1.2.3 From 7603f9e568ffb5025027a0a433ba5bccb2951767 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 1 May 2020 10:24:18 +0200 Subject: xwaitforwindow: init --- krebs/5pkgs/simple/xwaitforwindow.nix | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 krebs/5pkgs/simple/xwaitforwindow.nix (limited to 'krebs/5pkgs/simple') diff --git a/krebs/5pkgs/simple/xwaitforwindow.nix b/krebs/5pkgs/simple/xwaitforwindow.nix new file mode 100644 index 000000000..41ce65022 --- /dev/null +++ b/krebs/5pkgs/simple/xwaitforwindow.nix @@ -0,0 +1,15 @@ +{ writeDashBin, xdotool, xorg }: +writeDashBin "xwaitforwindow" '' + # usage: xwaitforwindow ARGS + # see xdotool search for possible ARGS + # example: xwaitforwindow -name WINDOWNAME + set -efu + + if id=$(${xdotool}/bin/xdotool search "$@"); then + printf 'waiting for window %#x\n' "$id" >&2 + exec ${xorg.xprop}/bin/xprop -spy -id "$id" >/dev/null + else + printf 'no window found with xdotool search %s\n' "$*" >&2 + exit 1 + fi +'' -- cgit v1.2.3 From b0549ee61b60d658751e1088810acd307847fec6 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 1 May 2020 11:02:01 +0200 Subject: flameshot-once: 1.2.0 -> 1.3.0 --- krebs/5pkgs/simple/flameshot-once/default.nix | 1 + 1 file changed, 1 insertion(+) (limited to 'krebs/5pkgs/simple') diff --git a/krebs/5pkgs/simple/flameshot-once/default.nix b/krebs/5pkgs/simple/flameshot-once/default.nix index c442a2e96..20c709fb5 100644 --- a/krebs/5pkgs/simple/flameshot-once/default.nix +++ b/krebs/5pkgs/simple/flameshot-once/default.nix @@ -16,6 +16,7 @@ in pkgs.flameshot pkgs.qt5.qtbase pkgs.xclip + pkgs.xwaitforwindow ]} ${optionalString (config != null) /* sh */ '' . ${import ./profile.nix { inherit config pkgs; }} -- cgit v1.2.3 From 66a3597034c0f400a948b551e95234f94c227859 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 1 May 2020 23:51:47 +0200 Subject: flameshot-once: add imgur support --- krebs/5pkgs/simple/flameshot-once/profile.nix | 68 ++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) (limited to 'krebs/5pkgs/simple') diff --git a/krebs/5pkgs/simple/flameshot-once/profile.nix b/krebs/5pkgs/simple/flameshot-once/profile.nix index 8ea8a850c..4427e5b23 100644 --- a/krebs/5pkgs/simple/flameshot-once/profile.nix +++ b/krebs/5pkgs/simple/flameshot-once/profile.nix @@ -48,7 +48,9 @@ let "SAVE" "EXIT" "BLUR" - ]; + ] + ++ optional cfg.imgur.enable "IMAGEUPLOADER" + ; type = types.listOf (types.enum (attrNames ButtonType)); }; disabledTrayIcon = mkOption { @@ -65,6 +67,44 @@ let # This is types.filename extended by [%:][%:+]* types.addCheck types.str (test "[%:0-9A-Za-z._][%:+0-9A-Za-z._-]*"); }; + imgur = mkOption { + default = {}; + type = types.submodule { + options = { + enable = mkEnableOption "imgur"; + createUrl = mkOption { + example = "http://p.r/image"; + type = types.str; + }; + deleteUrl = mkOption { + example = "http://p.r/image/delete/%1"; + type = types.str; + }; + xdg-open = mkOption { + default = {}; + type = types.submodule { + options = { + enable = mkEnableOption "imgur.xdg-open" // { + default = true; + }; + browser = mkOption { + default = "${pkgs.coreutils}/bin/false"; + type = types.str; + }; + createPrefix = mkOption { + default = cfg.imgur.createUrl; + type = types.str; + }; + deletePrefix = mkOption { + default = removeSuffix "/%1" cfg.imgur.deleteUrl; + type = types.str; + }; + }; + }; + }; + }; + }; + }; savePath = mkOption { default = "/tmp"; type = types.absolute-pathname; @@ -135,4 +175,30 @@ in export FLAMESHOT_CAPTURE_PATH=${cfg.savePath} export FLAMESHOT_ONCE_TIMEOUT=${toString cfg.timeout} export XDG_CONFIG_HOME=${XDG_CONFIG_HOME} + ${optionalString cfg.imgur.enable /* sh */ '' + export IMGUR_CREATE_URL=${shell.escape cfg.imgur.createUrl} + export IMGUR_DELETE_URL=${shell.escape cfg.imgur.deleteUrl} + ${optionalString cfg.imgur.xdg-open.enable /* sh */ '' + PATH=$PATH:${makeBinPath [ + (pkgs.writeDashBin "xdg-open" '' + set -efu + uri=$1 + prefix=$(${pkgs.coreutils}/bin/dirname "$uri") + case $prefix in + (${shell.escape cfg.imgur.xdg-open.createPrefix}) + echo "opening image in browser: $uri" >&2 + exec ${config.imgur.xdg-open.browser} "$uri" + ;; + (${shell.escape cfg.imgur.xdg-open.deletePrefix}) + echo "deleting image: $uri" >&2 + exec ${pkgs.curl}/bin/curl -fsS -X DELETE "$uri" + ;; + (*) + echo "don't know how to open URI: $uri" >&2 + exit 1 + esac + '') + ]} + ''} + ''} '' -- cgit v1.2.3 From d437145ae1c3f5b4a4975cc681e6c0eadf05712f Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 5 May 2020 16:38:59 +0200 Subject: htgen-imgur: init at 1.0.0 --- krebs/5pkgs/simple/htgen-imgur/default.nix | 29 ++++ krebs/5pkgs/simple/htgen-imgur/src/htgen-imgur | 209 +++++++++++++++++++++++++ 2 files changed, 238 insertions(+) create mode 100644 krebs/5pkgs/simple/htgen-imgur/default.nix create mode 100644 krebs/5pkgs/simple/htgen-imgur/src/htgen-imgur (limited to 'krebs/5pkgs/simple') diff --git a/krebs/5pkgs/simple/htgen-imgur/default.nix b/krebs/5pkgs/simple/htgen-imgur/default.nix new file mode 100644 index 000000000..fe0b2ab04 --- /dev/null +++ b/krebs/5pkgs/simple/htgen-imgur/default.nix @@ -0,0 +1,29 @@ +with import ; +{ attr, coreutils, exiv2, findutils, gnugrep, jq, nix, utillinux, stdenv }: +stdenv.mkDerivation rec { + pname = "htgen-imgur"; + version = "1.0.0"; + + src = ./src; + + buildPhase = '' + ( + exec > htgen-imgur + echo PATH=${makeBinPath [ + attr + coreutils + exiv2 + findutils + gnugrep + jq + nix utillinux + ]} + echo STATEDIR=${shell.escape "\${STATEDIR-$HOME}"} + cat $src/htgen-imgur + ) + ''; + + installPhase = '' + install -D htgen-imgur $out/bin/htgen-imgur + ''; +} diff --git a/krebs/5pkgs/simple/htgen-imgur/src/htgen-imgur b/krebs/5pkgs/simple/htgen-imgur/src/htgen-imgur new file mode 100644 index 000000000..af092d007 --- /dev/null +++ b/krebs/5pkgs/simple/htgen-imgur/src/htgen-imgur @@ -0,0 +1,209 @@ +find_item() { + if test ${#1} -ge 7; then + set -- "$(find "$STATEDIR/items" -mindepth 1 -maxdepth 1 \ + -regex "$STATEDIR/items/$1[0-9A-Za-z]*$")" + if test -n "$1" && test $(echo "$1" | wc -l) = 1; then + echo "$1" + return 0 + fi + fi + return 1 +} + +# https://api.imgur.com/models/basic +basic_response() {( + status_code=$1 + status_reason=$2 + data=${3-null} + + response_body=$(jq -cn \ + --argjson data "$data" \ + --argjson status "$status_code" \ + ' + { + data: $data, + status: $status, + success: (200 <= $status and $status <= 299), + } + ') + + printf "HTTP/1.1 $status_code $status_reason\r\n" + printf 'Connection: close\r\n' + printf 'Content-Length: %d\r\n' $(expr ${#response_body} + 1) + printf 'Content-Type: application/json; charset=UTF-8\r\n' + printf 'Server: %s\r\n' "$Server" + printf '\r\n' + printf '%s\n' "$response_body" + +)} + +file_response() { + jq -n -r \ + --argjson data "$(attr -q -g data "$1")" \ + --arg server "$Server" \ + ' + [ "HTTP/1.1 200 OK\r" + , "Connection: close\r" + , "Content-Length: \($data.size)\r" + , "Content-Type: \($data.type)\r" + , "Server: \($server)\r" + , "\r" + ][] + ' + cat "$1" +} + +read_uri() { + jq -cn --arg uri "$1" ' + $uri | + capture("^((?[^:]*):)?(//(?[^/]*))?(?[^?#]*)([?](?[^#]*))?([#](?.*))?$") | + . + { + 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 /image') + echo create image >&2 + + content=$(mktemp -t htgen.$$.content.XXXXXXXX) + trap "rm $content >&2" EXIT + + case ${req_expect-} in 100-continue) + printf 'HTTP/1.1 100 Continue\r\n\r\n' + esac + + head -c $req_content_length > $content + + sha256=$(sha256sum -b $content | cut -d\ -f1) + base32=$(nix-hash --to-base32 --type sha256 $sha256) + item=$STATEDIR/items/$base32 + + if ! test -e $item; then + mkdir -v -p $STATEDIR/items >&2 + cp -v $content $item >&2 + fi + + base32short=$(echo $base32 | cut -b-7) + + scheme=${req_x_forwarded_proto-http} + link=$scheme://$req_host/image/$base32short + + if item=$(find_item $base32short); then + + deletehash=$(uuidgen) + + info=$( + exiv2 print "$item" | + jq -csR ' + split("\n") | + map( + match("^(.*\\S)\\s*:\\s*(.*)").captures | + map(.string) | + {key:.[0],value:.[1]} + ) | + from_entries | + + . + ( + .["Image size"] | + match("^(?[0-9]+)\\s*x\\s*(?[0-9]+)$").captures | + map({key:.name,value:(.string|tonumber)}) | + from_entries + ) | + . + ( + .["File size"] | + match("^(?[0-9]+)\\s*Bytes$").captures | + map({key:.name,value:(.string|tonumber)}) | + from_entries + ) | + . + ' + ) + + data=$(jq -cn \ + --arg deletehash "$deletehash" \ + --arg id "$base32" \ + --arg link "$link" \ + --argjson info "$info" \ + --argjson uri "$uri" \ + ' + { + id: $id, + title: $uri.query.title, + description: $uri.query.description, + datetime: now, + type: $info["MIME type"], + animated: false, + width: $info.width, + height: $info.height, + size: $info.size, + views: 0, + bandwidth: 0, + vote: null, + favorite: false, + nsfw: null, + section: null, + account_url: null, + acount_id: 0, + is_ad: false, + is_most_viral: false, + tags: [], + ad_type: 0, + ad_url: "", + in_gallery: false, + deletehash: @uri "\($id)?deletehash=\($deletehash)", + name: "", + link: $link, + } + ') + + attr -q -s deletehash -V "$deletehash" "$item" + attr -q -s data -V "$data" "$item" + + basic_response 200 OK "$data" + exit + fi + ;; + 'GET /image/'*) + basename=$(basename "$path") + if printf %s "$basename" | grep -q '^[0-9a-z]\+$'; then + if item=$(find_item "$basename"); then + echo get image >&2 + file_response "$item" + exit + fi + fi + ;; + 'DELETE /image/delete/'*) + basename=$(basename "$path") + if printf %s "$basename" | grep -q '^[0-9a-z]\+$'; then + if item=$(find_item "$basename"); then + + deletehash=$(jq -nr --argjson uri "$uri" '$uri.query.deletehash') + + stored_deletehash=$(attr -q -g deletehash "$item") + + if test "$deletehash" = "$stored_deletehash"; then + echo "delete image" >&2 + + rm -v "$item" >&2 + + basic_response 200 OK + exit + else + echo "delete image error: bad deletehash provided: $deletehash" >&2 + basic_response 401 'Unauthorized' + exit + fi + fi + fi + ;; +esac -- cgit v1.2.3