commit 8b8a3d66cc8823a65387517171231b00237a1b20 Author: Tim Peters Date: Sun Jul 10 21:05:39 2022 +0200 Initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..200fd9a --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +# URL Shortener + +*URL Shortener* ist eine grafische Oberfläche für [Kutt](https://github.com/thedevs-network/kutt), um [Kurzlinks](https://de.wikipedia.org/wiki/Kurz-URL-Dienst) zu beliebigen URLs zu erzeugen. + +## Anwendung + +### Ersteinrichtung + +In der Konfigurationsdatei `~/.urlshortener` werden die URL der Kutt-Instanz sowie der API-KEY gespeichert. + +![](img/Setup.png) + +### Kurzlink erzeugen + +- **URL** (obligatorisch): Eine beliebige URL einer existierenden Webseite, für die ein Kurzlink erzeugt werden soll. Befindet sich in der Zwischenablage eine URL, so wird sie hier automatisch eingefügt. + +- **Kurzlink** (optional): Frei wählbar oder zufällig erzeugt. + +- **Wiederverwendung** (obligatorisch): Existiert bereits ein Kurzlink zu der URL, dann wird bei *true* kein neuer Kurzlink erzeugt, bei *false* wohl. + +- **Verfallszeit** (optional): Der Kurzlink wird gelöscht, wenn die Verfallszeit abgelaufen ist: ***5m*** für *5 Minuten*, ***2h*** für *2 Stunden*, ***30d*** für *30 Tage*. + +- **Passwort** (optional): Beim Aufruf des Kurzlinks wird nach einem Passwort gefragt. + +- **Beschreibung** (optional): Die Beschreibung wird in der Weboberfläche von Kutt angezeigt. + +![](img/Options.png) + +## Installation + +Folgende Programme müssen installiert sein, damit *URL Shortener* ordnungsgemäss funktionieren kann: + +- bash + +- yad + +- jq + +- curl + +- notify-send + +- xclip + + + +*URL Shortener* ist auch als [AppImage](https://z3h.de/ez) verfügbar. diff --git a/img/Options.png b/img/Options.png new file mode 100644 index 0000000..78d4f26 Binary files /dev/null and b/img/Options.png differ diff --git a/img/Setup.png b/img/Setup.png new file mode 100644 index 0000000..bbd54d3 Binary files /dev/null and b/img/Setup.png differ diff --git a/urlshortener b/urlshortener new file mode 100755 index 0000000..eff196e --- /dev/null +++ b/urlshortener @@ -0,0 +1,103 @@ +#!/bin/bash +# +# Von Tim Peters, https://z3h.de/url-shortener +############################################## + +HOST= +API_KEY= +APP_NAME="URL Shortener" +FILE_CONFIG=~/.urlshortener + +addUrl() { + + local data= + local result= + local link= + local error= + + [ -n "$1" ] && data="${data}\"target\": \"$1\"" + [ -n "$2" ] && data="${data},\"customurl\": \"$2\"" + [ -n "$3" ] && data="${data},\"reuse\": $3" + [ -n "$4" ] && data="${data},\"expire_in\": \"$4\"" + [ -n "$5" ] && data="${data},\"password\": \"$5\"" + [ -n "$6" ] && data="${data},\"description\": \"$6\"" + + result="$( \ + curl \ + -s -H "X-API-KEY: $API_KEY" \ + -H "Content-Type: application/json" \ + --data "{$data}" \ + "$HOST/api/v2/links" + )" + + link="$( echo "$result" | jq .link | tr -d \" )" + error="$( echo "$result" | jq .error | tr -d \" )" + + if [ "$link" != "null" ]; then + echo -n "$link" | xclip -selection c + notify-send -t 5000 "$link wurde in die Zwischenablage kopiert" + elif [ "$error" != "null" ]; then + notify-send -t 10000 "$error" + fi + +} + +addConfig() { + + yad \ + --form \ + --title="URL Shortener" \ + --text="Ersteinrichtung" \ + --field="URL" \ + --field="API-KEY" > "$FILE_CONFIG" || exit + +} + +getConfig() { + + while true; do + [ -r "$FILE_CONFIG" ] || addConfig + HOST="$( cut -d\| -f1 < "$FILE_CONFIG" )" + API_KEY="$( cut -d\| -f2 < "$FILE_CONFIG" )" + if [ -z "$HOST" ] && [ -z "$API_KEY" ]; then + addConfig + else + break + fi + done +} + +getUrlFromClipboard() { + + xclip -o | grep -E "^https*://" + +} + +getConfig +FORM="$( \ + yad \ + --form \ + --title="$APP_NAME" \ + --text="URL und Einstellmöglichkeiten" \ + --field="URL" \ + --field="Kurzlink" \ + --field="Wiederverwendung:CB" \ + --field="Verfallszeit:CBE" \ + --field="Passwort:H" \ + --field="Beschreibung" \ + "$( getUrlFromClipboard )" \ + "" \ + "true\!false" \ + "\!7d\!30d\!180d\!365d" \ + "" \ + "" \ +)" + +[ -n "$FORM" ] && \ + addUrl \ + "$( echo "$FORM" | cut -d\| -f1 )" \ + "$( echo "$FORM" | cut -d\| -f2 )" \ + "$( echo "$FORM" | cut -d\| -f3 )" \ + "$( echo "$FORM" | cut -d\| -f4 )" \ + "$( echo "$FORM" | cut -d\| -f5 )" \ + "$( echo "$FORM" | cut -d\| -f6 )"