diff --git a/README.md b/README.md index 8604c49..020bff3 100644 --- a/README.md +++ b/README.md @@ -70,15 +70,14 @@ Packaged example: /usr/share/backtunnel/profiles.ini --- -## 🧰 Dolphin Service Menus +### 🖥️ Dolphin Service Menus -Two context actions for Dolphin: -- **Share via BackTunnel…** (right-click a folder on the sharing machine) -- **Access via BackTunnel…** (right-click a folder path on the remote machine) +Two context actions for Dolphin are installed: -Installed into: -- Plasma 6: `/usr/share/kio/servicemenus/` -- Plasma 5: `/usr/share/kservices5/ServiceMenus/` +- **Share via BackTunnel…** → launches the graphical wrapper `backtunnel-share-gui`, prompting for remote, duration, ports, etc. +- **Access via BackTunnel…** → now uses the new `backtunnel-access-gui` wrapper, providing dialogs for remote, port, and mount point instead of embedding a complex one-liner. + +Both wrappers run inside Konsole (or xterm) so you can see live logs, and they honor profile defaults from `~/.config/backtunnel/profiles.ini` (or `/etc`, `/usr/share`). ### 🖱️ Dolphin (GUI) Flow — Share with Invite diff --git a/scripts/backtunnel_access-gui b/scripts/backtunnel_access-gui new file mode 100644 index 0000000..9b90ee1 --- /dev/null +++ b/scripts/backtunnel_access-gui @@ -0,0 +1,61 @@ +#!/usr/bin/env bash +set -euo pipefail + +LOG="/tmp/backtunnel-access-gui.$UID.log" +exec > >(tee -a "$LOG") 2>&1 +export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH:-}" + +FOLDER="${1:-}" +if [[ -z "$FOLDER" ]]; then + kdialog --error "No folder selected." || true + exit 1 +fi + +# Defaults +REMOTE_DEFAULT="user@vps.example.com" +PORT_DEFAULT="2222" +MOUNT_DEFAULT="/mnt/remote-rssh" + +# Profiles (read-only prefill; access side does not use @profile) +PROFILES_USER="${XDG_CONFIG_HOME:-$HOME/.config}/backtunnel/profiles.ini" +PROFILES_SYS="/etc/backtunnel/profiles.ini" +PROFILES_PKG="/usr/share/backtunnel/profiles.ini" +if [[ -f "$PROFILES_USER" ]]; then PROFILES_FILE="$PROFILES_USER" +elif [[ -f "$PROFILES_SYS" ]]; then PROFILES_FILE="$PROFILES_SYS" +else PROFILES_FILE="$PROFILES_PKG" +fi + +if [[ -f "$PROFILES_FILE" ]]; then + # pick one to prefill user@host (optional) + mapfile -t profs < <(awk '/^\[/{gsub(/^\[|\]$/,"",$1); if ($1!="default") print $1}' "$PROFILES_FILE") + if (( ${#profs[@]} )); then + choice="$(kdialog --combobox "Prefill from profile (optional)" "${profs[@]}")" || choice="" + if [[ -n "$choice" ]]; then + getval() { awk -v s="[""$choice""]" -v k="$1" ' + $0==s{ok=1; next} /^\[/{ok=0} + ok && $0 ~ /^[[:alnum:]_.-]+[[:space:]]*=/ { + line=$0; sub(/[[:space:]]*=[[:space:]]*/, "=", line) + split(line,a,"="); if(a[1]==k){val=substr(line,index(line,"=")+1); gsub(/^[[:space:]]+|[[:space:]]+$/,"",val); print val; exit} + }' "$PROFILES_FILE" 2>/dev/null; } + u="$(getval user)"; h="$(getval host)"; p="$(getval tunnel_port)"; m="$(getval invite_mount)" + [[ -n "$u" && -n "$h" ]] && REMOTE_DEFAULT="$u@$h" + [[ -n "$p" ]] && PORT_DEFAULT="$p" + [[ -n "$m" ]] && MOUNT_DEFAULT="$m" + fi + fi +fi + +REMOTE="$(kdialog --inputbox "Remote (user@host or user:host):" "$REMOTE_DEFAULT")" || exit 0 +PORT="$(kdialog --inputbox "Tunnel port on remote:" "$PORT_DEFAULT")" || exit 0 +MP="$(kdialog --getexistingdirectory --title "Choose mount point" "$MOUNT_DEFAULT")" || exit 0 + +cmd=( backtunnel-access "$FOLDER" from "$REMOTE" -p "$PORT" -m "$MP" ) + +if command -v konsole >/dev/null 2>&1; then + exec konsole --noclose -e "${cmd[@]}" +elif command -v xterm >/dev/null 2>&1; then + exec xterm -hold -e "${cmd[@]}" +else + nohup "${cmd[@]}" >>"$LOG" 2>&1 & + kdialog --msgbox "Mount started in background.\nSee log: $LOG" +fi diff --git a/servicemenus/backtunnel_access.desktop b/servicemenus/backtunnel_access.desktop index d5e2966..de5cfbc 100644 --- a/servicemenus/backtunnel_access.desktop +++ b/servicemenus/backtunnel_access.desktop @@ -10,10 +10,4 @@ X-KDE-Priority=TopLevel [Desktop Action BackTunnelAccess] Name=Access via BackTunnel… Icon=folder-remote -Exec=bash -lc ' - FOLDER="%f"; - REMOTE="$(kdialog --inputbox "Remote (user@host or user:host):" "user@vps.example.com")" || exit 1; - PORT="$(kdialog --inputbox "Tunnel port on remote:" "2222")" || exit 1; - MP="$(kdialog --getexistingdirectory --title "Choose mount point" "/mnt/remote-rssh")" || exit 1; - konsole --noclose -e backtunnel-access "$FOLDER" from "$REMOTE" -p "$PORT" -m "$MP" -' +Exec=backtunnel-access-gui %f