diff options
| author | spl3g <spleefer6@yandex.ru> | 2025-04-15 22:44:04 +0300 |
|---|---|---|
| committer | spl3g <spleefer6@yandex.ru> | 2025-05-01 14:59:18 +0300 |
| commit | ba1f63c6c5137dc9a7c8550ff2f1f052377a0091 (patch) | |
| tree | eee3c5159119b8359d03cd97a1bd8b7a41dec13e /home-manager/homeModules/attachments/hypr-scripts/toggle-vpn.sh | |
| parent | 841ee4137d95f7ed5aafd7f8e29c94e12e712665 (diff) | |
feat(hyprland): cleanup scripts
Diffstat (limited to 'home-manager/homeModules/attachments/hypr-scripts/toggle-vpn.sh')
| -rwxr-xr-x | home-manager/homeModules/attachments/hypr-scripts/toggle-vpn.sh | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/home-manager/homeModules/attachments/hypr-scripts/toggle-vpn.sh b/home-manager/homeModules/attachments/hypr-scripts/toggle-vpn.sh new file mode 100755 index 0000000..a712a1e --- /dev/null +++ b/home-manager/homeModules/attachments/hypr-scripts/toggle-vpn.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +ROFI_CMD="rofi -dmenu -theme-str listview{enabled:false;} -p" +LOCAL_STORAGE=~/.local/share/toggle +V2RAYA_URL="http://localhost:2017" + +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 +} + +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 [[ $STATUS == "true" ]]; then + NEW_STATUS=$(toggle $TOKEN DELETE) +else + NEW_STATUS=$(toggle $TOKEN POST) +fi + +if [[ $NEW_STATUS == "null" ]]; then + set_token +fi + +notify-send v2rayA "running: ${NEW_STATUS}" |
