diff options
| author | spl3g <spleefer6@yandex.ru> | 2024-10-23 22:10:07 +0300 |
|---|---|---|
| committer | spl3g <spleefer6@yandex.ru> | 2025-05-01 14:58:56 +0300 |
| commit | 200046bda5c03b62dcc9be1d4cb04adfb3d45e37 (patch) | |
| tree | 53a1800082e7f95a8d0e71abc2d480791b3d15aa /home-manager | |
| parent | 3b9099e4537e039b140294157ae18b1d1b41b366 (diff) | |
feat: add vpn toggle script
Diffstat (limited to 'home-manager')
| -rw-r--r-- | home-manager/homeModules/attachments/hypr-scripts/toggle_vpn.sh | 55 | ||||
| -rw-r--r-- | home-manager/homeModules/hyprland.nix | 4 |
2 files changed, 57 insertions, 2 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 100644 index 0000000..2654273 --- /dev/null +++ b/home-manager/homeModules/attachments/hypr-scripts/toggle_vpn.sh @@ -0,0 +1,55 @@ +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 + +notify-send v2rayA "running: ${NEW_STATUS}" diff --git a/home-manager/homeModules/hyprland.nix b/home-manager/homeModules/hyprland.nix index 5fb7d5a..52cec17 100644 --- a/home-manager/homeModules/hyprland.nix +++ b/home-manager/homeModules/hyprland.nix @@ -108,7 +108,6 @@ "float, class:^(firefox)$, title:^(Picture-in-Picture)$" "pin, class:^(firefox)$, title:^(Picture-in-Picture)$" "move 100%-w-20 100%-w-20, class:^(firefox)$, title:^(Picture-in-Picture)$" - "float, class:^(firefox)&, title:^Extension:.*\bBitwarden\b" "float, title:^(Save File)$" "pin, title:^(Save File)$" "pin, class:^(dragon)$" @@ -140,7 +139,8 @@ "$mainMod, E, exec, emacsclient -c -a emacs" "$mainMod CONTROL, E, exec, emacs" "$mainMod SHIFT, Esc, exec, swww img ${config.wallpaper}" - + ",Cancel, exec, bash $scripts/toggle_vpn.sh" + # Screenshooting ", Print, exec, grimblast save screen" "ALT, Print, exec, grimblast save active" |
