Skip to content

Instantly share code, notes, and snippets.

@f0xmulder
Forked from bigfreak85/1 Waybar OpenVPN Toggler
Created September 2, 2024 01:42
Show Gist options
  • Save f0xmulder/c81b9f8351e291d12e11c58803eb817b to your computer and use it in GitHub Desktop.
Save f0xmulder/c81b9f8351e291d12e11c58803eb817b to your computer and use it in GitHub Desktop.

Revisions

  1. @bigfreak85 bigfreak85 revised this gist Dec 10, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion add to waybar config
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    "custom/vpn": {
    "format": "{}",
    "exec": "sudo bash /home/bigfreak/.config/sway/tools/vpnupdown status",
    "exec": "bash /home/bigfreak/.config/sway/tools/vpnupdown status",
    // "exec-if": "test -d /proc/sys/net/ipv4/conf/tun0",
    "tooltip": "true",
    "return-type": "json",
  2. @bigfreak85 bigfreak85 revised this gist Dec 8, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion add to waybar config
    Original file line number Diff line number Diff line change
    @@ -5,5 +5,5 @@
    "tooltip": "true",
    "return-type": "json",
    "interval": 1,
    "on-click": "sudo bash /home/bigfreak/.config/sway/tools/vpnupdown toggle"
    "on-click": "bash /home/bigfreak/.config/sway/tools/vpnupdown toggle"
    },
  3. @bigfreak85 bigfreak85 renamed this gist Dec 7, 2023. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. @bigfreak85 bigfreak85 renamed this gist Dec 7, 2023. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. @bigfreak85 bigfreak85 revised this gist Dec 7, 2023. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions Waybar_OpenVPN_Toggler
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    This Scripts and Config Snippets are for a little Symbol in the Waybar. If you Click on the Tunnelsymbol the OpenVPN-Client
    establish a Connection to the given Config (Systemd Openvpn-Client). If you do not Need the Tunnel then you can Click again on
    the Symbol and the VPN-Tunnel gets closed. The following moving Parts are needed:

    1. The Waybar Config Snippit
    2. The Toggle/Status Script
    3. The Polkit Rule to allow the control of the OpenVPN-Client systemd-Unit by given user (a sudo nopasswd is also possible but
    not so granular and allows systemctl completly)
  6. @bigfreak85 bigfreak85 revised this gist Dec 7, 2023. No changes.
  7. @bigfreak85 bigfreak85 revised this gist Dec 7, 2023. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions 99-manage_openvpn_daemon.rules
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    polkit.addRule(function(action, subject) {
    if (action.id == "org.freedesktop.systemd1.manage-units" &&
    action.lookup("unit") == "[email protected]" &&
    subject.user == "bigfreak") {
    return polkit.Result.YES;
    }
    });
  8. @bigfreak85 bigfreak85 revised this gist Dec 6, 2023. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions vpnupdown
    Original file line number Diff line number Diff line change
    @@ -16,8 +16,6 @@ STATUS="$(systemctl is-active [email protected])"
    if [ "${STATUS}" = "inactive" ]; then
    if [ $1 = 'toggle' ]; then
    systemctl start [email protected]
    sleep 1
    ip route del 192.168.0.0/24 dev tun0
    text="{\"text\":\"󱠽 \",\"class\":\"enabled\"}"
    fi
    text="{\"text\":\"󱠾\",\"tooltip\":\"imc closed\"}"
  9. @bigfreak85 bigfreak85 renamed this gist Dec 6, 2023. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  10. @bigfreak85 bigfreak85 renamed this gist Dec 6, 2023. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  11. @bigfreak85 bigfreak85 created this gist Dec 6, 2023.
    9 changes: 9 additions & 0 deletions add to wayland config
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    "custom/vpn": {
    "format": "{}",
    "exec": "sudo bash /home/bigfreak/.config/sway/tools/vpnupdown status",
    // "exec-if": "test -d /proc/sys/net/ipv4/conf/tun0",
    "tooltip": "true",
    "return-type": "json",
    "interval": 1,
    "on-click": "sudo bash /home/bigfreak/.config/sway/tools/vpnupdown toggle"
    },
    32 changes: 32 additions & 0 deletions vpnupdown
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    # ******************************************************** #
    # #
    # #
    # vpnupdown #
    # #
    # By: Raffael Willems <[email protected]> #
    # #
    # Created: 2023/12/06 13:46:41 by Raffael Willems #
    # Updated: 2023/12/06 21:48:41 by Raffael Willems #
    # #
    # ******************************************************** #

    #!/bin/bash

    STATUS="$(systemctl is-active [email protected])"
    if [ "${STATUS}" = "inactive" ]; then
    if [ $1 = 'toggle' ]; then
    systemctl start [email protected]
    sleep 1
    ip route del 192.168.0.0/24 dev tun0
    text="{\"text\":\"󱠽 \",\"class\":\"enabled\"}"
    fi
    text="{\"text\":\"󱠾\",\"tooltip\":\"imc closed\"}"
    else
    if [ $1 = 'toggle' ]; then
    systemctl stop [email protected]
    text="{\"text\":\"󱠾\",\"tooltip\":\"imc closed\"}"
    fi
    ADDR="$(ip -br addr show dev tun0 | awk '{ print $3 }')"
    text="{\"text\":\"󱠽 \",\"class\":\"enabled\",\"tooltip\":\"$ADDR\"}"
    fi
    echo $text