├── LICENSE ├── README.md ├── rofi.rasi ├── screenshots ├── password-prompt.png ├── vpn-off.png └── vpn-on.png └── wireguard-manager.sh /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Hugo Levy-Falk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Wireguard-manager 2 | 3 | This is a simple, stupid `waybar` extension for toggling `wireguard`. It uses 4 | `rofi` for password prompting, but you could use anything you like. 5 | 6 | ## Screenshots 7 | 8 | ![VPN switched off](screenshots/vpn-off.png) 9 | *VPN switched off, as seen in Waybar.* 10 | 11 | ![Password prompt](screenshots/password-prompt.png) 12 | *Password prompt with Rofi.* 13 | 14 | ![VPN switched on](screenshots/vpn-on.png) 15 | *VPN switched on, as seen in Waybar.* 16 | 17 | ## Prerequisites 18 | 19 | You need to be able to manage Wireguard using systemd, even though it should 20 | not be too difficult to change the script to use `wg` directly. 21 | 22 | If your Wireguard interface is `wg0`, enable the service using: 23 | 24 | ```bash 25 | sudo systemctl enable wg-quick@wg0.service 26 | sudo systemctl daemon-reload 27 | ``` 28 | 29 | You also need `rofi`. 30 | 31 | ## Installation 32 | 33 | Clone the repository in `~/.config/waybar/wireguard-manager`, then add this to 34 | `~/.config/waybar/config` : 35 | 36 | ```json 37 | "custom/wireguard-manager": { 38 | "exec": "exec ~/.config/waybar/wireguard-manager/wireguard-manager.sh -s", 39 | "format": "{icon}", 40 | "format-icons": { 41 | "connected": "VPN: 🔒", 42 | "disconnected": "VPN: 🔓", 43 | }, 44 | "interval": "once", 45 | "on-click": "~/.config/waybar/wireguard-manager/wireguard-manager.sh -t && pkill -SIGRTMIN+1 waybar", 46 | "return-type": "json", 47 | "signal": 1, 48 | } 49 | ``` 50 | 51 | See [Waybar's wiki](https://github.com/Alexays/Waybar/wiki/Module:-Custom) for 52 | more information on how to customize this. 53 | 54 | ### Toggling WireGuard "manually" 55 | 56 | If you intend on turning your Wireguard tunnel on and off through other means other than clicking on this waybar module, it can be useful to set the module itself in a different fashion: 57 | 58 | ```json 59 | "custom/wireguard-manager": { 60 | "interval": 3, 61 | "return-type": "json", 62 | "format-icons": { 63 | "connected": "VPN: 🔒", 64 | "disconnected": "VPN: 🔓" 65 | }, 66 | "on-click": "exec ~/.config/waybar/wireguard-manager/wireguard-manager.sh -t", 67 | "exec": "exec ~/.config/waybar/wireguard-manager/wireguard-manager.sh -s", 68 | "format": "{icon}" 69 | } 70 | ``` 71 | 72 | This is because the version of the module presented first updates itself only when clicked on, to avoid constant polling of the status of the systemd service for Wireguard. If you do use other means to set your tunnel up or down (such as `sudo systemctl stop wg-quick@wg0.service`), it is recommended to use this other version of the module, as it polls the current status of the systemd service every 3 seconds, updating the status of the module without requiring the user to click on it. 73 | 74 | ## Usage 75 | 76 | With the given configuration, the status of the connection will be updated every 77 | 3 seconds. You can switch on/off the connection to your peer by clicking on the 78 | icon in Waybar. 79 | 80 | ## Customization 81 | 82 | This module is simple enough for anyone to customize it. You can change the way 83 | the rofi prompt looks by editing `rofi.rasi`, or you can use any other way to 84 | prompt the password. You can also change the way things look in Waybar by 85 | editing the sample configuration. 86 | 87 | ## Contributions 88 | 89 | Contributions are most welcome, feel free to submit any idea or improvement you 90 | can think of. 91 | 92 | ## See also 93 | 94 | If you are a NetworkManager user, maybe you should rather use 95 | [wireguard-rofi-waybar ](https://github.com/HarHarLinks/wireguard-rofi-waybar), which seems to offer 96 | way more functionalities! 97 | -------------------------------------------------------------------------------- /rofi.rasi: -------------------------------------------------------------------------------- 1 | * { 2 | border: none; 3 | border-radius: 0; 4 | /* font: Roboto,'Font Awesome 5', 'SFNS Display', Helvetica, Arial, sans-serif; */ 5 | font-size: 15px; 6 | min-height: 0; 7 | background-color: #282a36; 8 | color: #f8f8f2; 9 | } 10 | 11 | #window { 12 | width: 300px; 13 | padding: 15px; 14 | 15 | border: 2px; 16 | border-color: #44475a; 17 | } 18 | 19 | #entry { 20 | expand: true; 21 | width: 200px; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /screenshots/password-prompt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Klafyvel/wireguard-manager/146a21e1f0d27e2b0e30aedf2726d047eea1a798/screenshots/password-prompt.png -------------------------------------------------------------------------------- /screenshots/vpn-off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Klafyvel/wireguard-manager/146a21e1f0d27e2b0e30aedf2726d047eea1a798/screenshots/vpn-off.png -------------------------------------------------------------------------------- /screenshots/vpn-on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Klafyvel/wireguard-manager/146a21e1f0d27e2b0e30aedf2726d047eea1a798/screenshots/vpn-on.png -------------------------------------------------------------------------------- /wireguard-manager.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SERVICE_NAME="wg-quick@wg0" 4 | STATUS_CONNECTED_STR='{"text":"Connected","class":"connected","alt":"connected"}' 5 | STATUS_DISCONNECTED_STR='{"text":"Disconnected","class":"disconnected","alt":"disconnected"}' 6 | 7 | function askpass() { 8 | rofi -dmenu -password -no-fixed-num-lines -p "Sudo password : " -theme ~/.config/waybar/wireguard-manager/rofi.rasi 9 | } 10 | 11 | function status_wireguard() { 12 | systemctl is-active $SERVICE_NAME >/dev/null 2>&1 13 | return $? 14 | } 15 | 16 | function toggle_wireguard() { 17 | status_wireguard && \ 18 | SUDO_ASKPASS=~/.config/waybar/wireguard-manager/wireguard-manager.sh sudo -A systemctl stop $SERVICE_NAME || \ 19 | SUDO_ASKPASS=~/.config/waybar/wireguard-manager/wireguard-manager.sh sudo -A systemctl start $SERVICE_NAME 20 | } 21 | 22 | case $1 in 23 | -s | --status) 24 | status_wireguard && echo $STATUS_CONNECTED_STR || echo $STATUS_DISCONNECTED_STR 25 | ;; 26 | -t | --toggle) 27 | toggle_wireguard 28 | ;; 29 | *) 30 | askpass 31 | ;; 32 | esac 33 | --------------------------------------------------------------------------------