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.
Waybar Plugin openvpn toggler Shellscript for start/stop/status openvpn client (Systemd-unit)
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)
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;
}
});
"custom/vpn": {
"format": "{}",
"exec": "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": "bash /home/bigfreak/.config/sway/tools/vpnupdown toggle"
},
# ******************************************************** #
# #
# #
# 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]
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment