aboutsummaryrefslogtreecommitdiff
path: root/modules/homeModules/attachments/hypr-scripts/toggle-vpn.sh
diff options
context:
space:
mode:
authorspl3g <notspl3g@duck.com>2026-03-18 18:01:41 +0300
committerspl3g <notspl3g@duck.com>2026-03-18 18:01:59 +0300
commit03648b3d9f177227df40129bed22558f6924b91c (patch)
tree8a22eda142beeafd9002a8d5901ba9428a77ad52 /modules/homeModules/attachments/hypr-scripts/toggle-vpn.sh
parentdc19a2b583b3ab50d8e36ff0a90ca633495f675f (diff)
so.. v2 i guess
Diffstat (limited to 'modules/homeModules/attachments/hypr-scripts/toggle-vpn.sh')
-rwxr-xr-xmodules/homeModules/attachments/hypr-scripts/toggle-vpn.sh93
1 files changed, 93 insertions, 0 deletions
diff --git a/modules/homeModules/attachments/hypr-scripts/toggle-vpn.sh b/modules/homeModules/attachments/hypr-scripts/toggle-vpn.sh
new file mode 100755
index 0000000..8775f39
--- /dev/null
+++ b/modules/homeModules/attachments/hypr-scripts/toggle-vpn.sh
@@ -0,0 +1,93 @@
+#!/bin/sh
+
+ROFI_CMD="rofi -dmenu -theme-str listview{enabled:false;} -p"
+LOCAL_STORAGE=~/.local/share/toggle
+TMP_PATH=/tmp/vpn-status
+V2RAYA_URL="http://localhost:2017"
+
+DBUS_INTERFACE="com.vpn_status"
+DBUS_MEMBER="StatusChanged"
+
+set_token() {
+ login=$(echo "" | $ROFI_CMD "Enter login > ")
+ password=$(echo "" | $ROFI_CMD "Enter password > " -theme-str 'entry {enabled: false;}')
+ response=$(curl -s -X POST \
+ "${V2RAYA_URL}/api/login" \
+ -d "{\"username\": \"${login}\", \"password\": \"${password}\"}")
+
+ code=$(echo $response | jq -r ".code")
+ echo "${response}" | jq ".data.token" -r > "${LOCAL_STORAGE}/token"
+}
+
+get_status() {
+ token=$1
+ response=$(curl -s -X GET \
+ "${V2RAYA_URL}/api/touch" \
+ -H "Authorization: ${token}")
+ echo $response | jq ".data.running" -r
+}
+
+toggle() {
+ token=$1
+ method=$2
+ response=$(curl -s -X ${method} \
+ "${V2RAYA_URL}/api/v2ray" \
+ -H "Authorization: ${token}")
+ code=$(echo $response | jq ".code" -r)
+ echo $response | jq ".data.running" -r
+}
+
+check_status() {
+ case $(cat $TMP_PATH) in
+ true)
+ output='{"text": "󰠥"}'
+ ;;
+ *)
+ output='{"text": ""}'
+ ;;
+ esac
+ echo $output | jq --unbuffered --compact-output
+}
+
+
+if [[ ! -d "${LOCAL_STORAGE}" ]]; then
+ mkdir "${LOCAL_STORAGE}"
+fi
+
+if [[ ! -e "${LOCAL_STORAGE}/token" ]]; then
+ touch "${LOCAL_STORAGE}/token"
+fi
+
+TOKEN=$(cat "${LOCAL_STORAGE}/token")
+if [[ -z "${TOKEN}" ]]; then
+ set_token
+ TOKEN=$(cat "${LOCAL_STORAGE}/token")
+fi
+
+STATUS=$(get_status $TOKEN)
+
+if [[ $1 == "waybar" ]]; then
+ echo $STATUS > $TMP_PATH
+ check_status
+
+ dbus-monitor --profile "interface='${DBUS_INTERFACE}',member='${DBUS_MEMBER}'" |
+ while read -r line; do
+ check_status
+ done
+else
+ if [[ $STATUS == "true" ]]; then
+ NEW_STATUS=$(toggle $TOKEN DELETE)
+ else
+ NEW_STATUS=$(toggle $TOKEN POST)
+ fi
+
+ if [[ $NEW_STATUS == "null" ]]; then
+ set_token
+ exit 0
+ fi
+
+ echo $NEW_STATUS > $TMP_PATH
+ dbus-send --type=signal / "${DBUS_INTERFACE}.${DBUS_MEMBER}"
+
+ notify-send v2rayA "running: ${NEW_STATUS}"
+fi