├── .dockerignore
├── .github
└── FUNDING.yml
├── Dockerfile
├── LICENSE
├── README.md
├── examples
└── webhook
│ ├── README.md
│ └── bin
│ ├── wgcg-gen.sh
│ ├── wgcg-html-gpg.sh
│ ├── wgcg-html-qrcode.sh
│ └── wh.py
├── images
└── wgcg.png
├── modules
└── wgcg-install-wireguard.sh
├── monitoring
└── wireguard-dashboard.json
├── wgcg-docker.sh
├── wgcg.conf
├── wgcg.sh
└── wgfw.rules
/.dockerignore:
--------------------------------------------------------------------------------
1 | # Include files
2 | *
3 | !wgcg.conf
4 | !wgcg.sh
5 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | patreon: # Replace with a single Patreon username
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: psyhomb
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
13 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
14 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM ubuntu:20.04
2 |
3 | LABEL maintainer="psyhomb"
4 |
5 | ARG USER
6 | ARG UID
7 |
8 | ENV USER=${USER:-wgcg} \
9 | UID=${UID:-1000}
10 |
11 | WORKDIR /data/wgcg
12 |
13 | COPY . ./
14 |
15 | RUN case ${UID} in \
16 | 0) HOME="/root" ;; \
17 | *) HOME="/home/${USER}"; useradd -ou ${UID} ${USER} ;; \
18 | esac \
19 | && mkdir -p ${HOME}/.gnupg ${HOME}/wireguard/wgcg \
20 | && chmod 700 ${HOME}/.gnupg \
21 | && mv wgcg.conf ${HOME}/wireguard/wgcg/ \
22 | && mv wgcg.sh /usr/local/bin/ \
23 | && chmod 644 ${HOME}/wireguard/wgcg/wgcg.conf \
24 | && chmod 755 /usr/local/bin/wgcg.sh \
25 | && chown -R ${USER}:${USER} ${HOME} \
26 | && apt-get update \
27 | && apt-get -y install --no-install-recommends wireguard-tools openssh-client gpg gpg-agent qrencode grepcidr \
28 | && apt-get -y --purge autoremove \
29 | && apt-get clean \
30 | && rm -vrf /var/lib/apt/lists/*
31 |
32 | USER ${USER}
33 | ENTRYPOINT ["/usr/local/bin/wgcg.sh"]
34 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Milos Buncic
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-tools
2 | ===============
3 |
4 | Full documentation about manual Wireguard installation and configuration process can be found [here](https://gitlab.com/snippets/1897102).
5 |
6 | wgcg.sh
7 | -------
8 |
9 |
10 |
11 |
12 |
13 | ### About
14 |
15 | This script is created to ease manual process of Wireguard configuration and will help you to automatically generate all the required configuration files (client and server), PKI key pairs and preshared key.
16 |
17 | ### Install dependencies
18 |
19 | **Arch**
20 |
21 | ```bash
22 | pacman -S wireguard-tools gnupg qrencode
23 | yay grepcidr
24 | ```
25 |
26 | **Ubuntu**
27 |
28 | ```bash
29 | apt-get install wireguard-tools gpg qrencode grepcidr
30 | ```
31 |
32 | **MacOS**
33 |
34 | ```bash
35 | brew install wireguard-tools gpg qrencode grepcidr
36 | ```
37 |
38 | Make sure to append following line to [wgcg.conf](./wgcg.conf) file only if using MacOS.
39 | By doing this we will force script to use GNU instead of BSD command line utilities (e.g. `grep`) and prevent any possible incompatibility issues.
40 |
41 | ```bash
42 | echo -e '\n# Make sure script is using GNU command line utilities on MacOS\nexport PATH="/usr/local/opt/grep/libexec/gnubin:${PATH}"' >> wgcg.conf
43 | ```
44 |
45 | ### Usage
46 |
47 | Before running the script we'll have to update [wgcg.conf](./wgcg.conf) configuration file.
48 | For most use cases the only variable we'd have to modify is `WGCG_SERVER_PUBLIC_IP`.
49 |
50 | ```bash
51 | # Server name (wireguard interface name e.g. wg0 || wg1 || wg2)
52 | WGCG_SERVER_NAME="wg0"
53 |
54 | # HostMin to HostMax range can be used to assign IP addresses to WireGuard clients
55 | # e.g. ./wgcg.sh -c foo 10.0.0.2
56 | #
57 | # Network: 10.0.0.0/22
58 | # HostMin: 10.0.0.1
59 | # HostMax: 10.0.3.254
60 | # HostIDs: 1022
61 | #
62 | # WireGuard server private IP address (with optional CIDR - default: 22)
63 | WGCG_SERVER_WG_IP="10.0.0.1"
64 |
65 | # Static server port
66 | WGCG_SERVER_PORT="52001"
67 |
68 | # Server's public IP or FQDN
69 | WGCG_SERVER_PUBLIC_IP="wg.yourdomain.com"
70 |
71 | # SSH server IP address (default: ${WGCG_SERVER_PUBLIC_IP}) (optional)
72 | # Note: This option can be used in case SSH server is listening on different IP address,
73 | # if not specified, ${WGCG_SERVER_PUBLIC_IP} will be used instead
74 | WGCG_SERVER_SSH_IP=""
75 |
76 | # SSH server port (optional)
77 | WGCG_SERVER_SSH_PORT="22"
78 |
79 | # Space separated list of DNS IPs (default: 1.1.1.1 1.0.0.1) (optional)
80 | WGCG_CLIENT_DNS_IPS="1.1.1.1 1.0.0.1"
81 |
82 | # Space separated list of subnets (with CIDR) required for split-tunneling (default: 0.0.0.0/0) (optional)
83 | WGCG_CLIENT_ALLOWED_IPS="0.0.0.0/0"
84 |
85 | # All configuration and key files will be stored in this directory
86 | WGCG_WORKING_DIR="${HOME}/wireguard/${WGCG_SERVER_NAME}"
87 | ```
88 |
89 | Copy [wgcg.conf](./wgcg.conf) and [wgfw.rules](./wgfw.rules) files to `wgcg` directory.
90 |
91 | ```bash
92 | mkdir -p ${HOME}/wireguard/wgcg
93 | cp wgcg.conf ${HOME}/wireguard/wgcg/
94 | cp wgfw.rules ${HOME}/wireguard/wgcg/
95 | ```
96 |
97 | Copy [wgcg.sh](./wgcg.sh) script to `/usr/local/bin` directory.
98 |
99 | ```bash
100 | cp wgcg.sh /usr/local/bin/
101 | ```
102 |
103 | It is also possible to specify custom configuration file by passing `WGCG_CONFIG_FILE` environment variable.
104 |
105 | ```bash
106 | WGCG_CONFIG_FILE="${HOME}/wireguard/wgcg/wgcg.conf" wgcg.sh
107 | ```
108 |
109 | Print help and current default options.
110 |
111 | ```bash
112 | wgcg.sh -h
113 | ```
114 |
115 | Output:
116 |
117 | ```plain
118 | Usage:
119 | wgcg.sh options
120 |
121 | Options:
122 | -P|--sysprep filename.sh Install WireGuard kernel module, required tools and scripts (will establish SSH connection with server)
123 | -s|--add-server-config Generate server configuration
124 | -c|--add-client-config client_name client_wg_ip Generate client configuration
125 | -B|--add-clients-batch filename.csv[:rewrite|:norewrite] Generate configuration for multiple clients in batch mode
126 | Supported action modes are 'rewrite' or 'norewrite' (default)
127 | 'rewrite' action mean regenerate ALL, 'norewrite' mean generate only configs and keys for new clients
128 | -e|--encrypt-config client_name [passphrase] Encrypt configuration file by using symmetric encryption (if passphrase not specified it will be generated - RECOMMENDED)
129 | -d|--decrypt-config client_name Decrypt configuration file and print it out on stdout
130 | -r|--rm-client-config client_name Remove client configuration
131 | -q|--gen-qr-code client_name [-] Generate QR code (PNG format) from client configuration file, if - is used, QR code will be printed out on stdout instead
132 | -l|--list-used-ips List all clients IPs that are currently in use
133 | -S|--sync Synchronize server configuration (will establish SSH connection with server)
134 | -h|--help Show this help
135 |
136 | Current default options:
137 | WGCG_SERVER_NAME="wg0"
138 | WGCG_SERVER_WG_IP="10.0.0.1"
139 | WGCG_SERVER_PORT="52001"
140 | WGCG_SERVER_PUBLIC_IP="wg.yourdomain.com"
141 | WGCG_SERVER_SSH_PORT="22"
142 | WGCG_CLIENT_DNS_IPS="1.1.1.1 1.0.0.1"
143 | WGCG_CLIENT_ALLOWED_IPS="0.0.0.0/0"
144 | WGCG_WORKING_DIR="/home/username/wireguard/wg0"
145 | ```
146 |
147 | [wgcg-install-wireguard.sh](./modules/wgcg-install-wireguard.sh) module will do all required system preparations on the WireGuard server (running the module is idempotent operation):
148 |
149 | - Install `wireguard` kernel module and tools
150 | - Load the module
151 | - Generate `wgfw.sh` script
152 | - Enable IP forwarding (routing)
153 |
154 | **Note:** You have to run it only once!
155 |
156 | ```bash
157 | wgcg.sh --sysprep modules/wgcg-install-wireguard.sh
158 | ```
159 |
160 | Generate server keys and config.
161 |
162 | ```bash
163 | wgcg.sh -s
164 | ```
165 |
166 | Generate client config, PKI key pairs and update server config (add new Peer block)
167 |
168 | ```bash
169 | wgcg.sh -c foo 10.0.0.2
170 | ```
171 |
172 | or to generate multiple client configs at once, create `client-configs.csv` file
173 |
174 | ```bash
175 | cat > client-configs.csv <<'EOF'
176 | foo,10.0.0.2
177 | bar,10.0.0.3
178 | EOF
179 | ```
180 |
181 | and run.
182 |
183 | ```bash
184 | wgcg.sh -B client-configs.csv
185 | ```
186 |
187 | By default `-B` will only generate client config and key files for newly added clients, if you plan to regenerate config and key files for ALL clients that are specified in the csv file,
188 | you'll have to use `rewrite` action mode, globally or per client line, in case both are specified last one has precedence.
189 |
190 | Global `rewrite` action mode
191 |
192 | ```bash
193 | wgcg.sh -B client-configs.csv:rewrite
194 | ```
195 |
196 | or per client line.
197 |
198 | **Note:** It is also possible to protect individual client from regenerating config and key files by specifying `norewrite` action.
199 |
200 | ```bash
201 | cat > client-configs.csv <<'EOF'
202 | foo,10.0.0.2,rewrite
203 | bar,10.0.0.3,norewrite
204 | EOF
205 | ```
206 |
207 | Remove client config, PKI key pairs and update server config (remove Peer block).
208 |
209 | ```bash
210 | wgcg.sh -r foo
211 | ```
212 |
213 | Synchronize local server configuration file with server (live update).
214 |
215 | ```bash
216 | wgcg.sh --sync
217 | ```
218 |
219 | In order to send client configuration file to a person safely, you can use GPG symmetric encryption to encrypt data before sending it, then you can send configuration file to a person via one channel ([webwormhole](https://webwormhole.io)) and passphrase via different channel ([ots](https://github.com/sniptt-official/ots)).
220 |
221 | Encrypt configuration file.
222 |
223 | ```bash
224 | wgcg.sh -e foo
225 | ```
226 |
227 | To test passphrase just run decrypt command, if everything is OK client configuration will be printed out on the standard output.
228 |
229 | ```bash
230 | wgcg.sh -d foo
231 | ```
232 |
233 | ### Multi-Configuration
234 |
235 | It is also possible to manage multiple clusters with single script.
236 | Create configuration file and command alias for every cluster.
237 |
238 | **Note:** Append following lines to `~/.zshrc` or `~/.bashrc` file.
239 |
240 | ```bash
241 | alias wgcg-office1.sh="WGCG_CONFIG_FILE=${HOME}/wireguard/wgcg/office1.conf wgcg.sh"
242 | alias wgcg-office2.sh="WGCG_CONFIG_FILE=${HOME}/wireguard/wgcg/office2.conf wgcg.sh"
243 | ```
244 |
245 | ```bash
246 | source ~/.zshrc
247 | # or
248 | source ~/.bashrc
249 | ```
250 |
251 | ```bash
252 | wgcg-office1.sh -h
253 | ```
254 |
255 | ### Firewall rules
256 |
257 | Custom firewall rules, in iptables compatible format, can be added using [wgfw.rules](./wgfw.rules) file. All rules from this file are going to be applied in idempotent manner on the server side at server startup time or each time `wgcg.sh --sync` command is executed.
258 |
259 | ### Demo
260 |
261 |
262 |
263 |
264 |
265 | ### Docker
266 |
267 | It is also possible to run the script inside of Docker container with already preinstalled dependecies.
268 |
269 | Build docker image.
270 |
271 | ```bash
272 | docker build --no-cache --force-rm --build-arg USER=${USER} --build-arg UID=${UID} -t wgcg .
273 | ```
274 |
275 | Run the script.
276 |
277 | ```bash
278 | ./wgcg-docker.sh -h
279 | ```
280 |
281 | or if you are not using default configuration filename (`wgcg.conf`).
282 |
283 | ```bash
284 | WGCG_CONFIG_FILE="${HOME}/wireguard/wgcg/wg0.conf" ./wgcg-docker.sh -h
285 | ```
286 |
287 | ### Monitoring
288 |
289 | #### Prometheus
290 |
291 | - [prometheus_wireguard_exporter](https://github.com/MindFlavor/prometheus_wireguard_exporter)
292 |
293 | #### Grafana
294 |
295 | - [wireguard-dashboard.json](./monitoring/wireguard-dashboard.json)
296 |
--------------------------------------------------------------------------------
/examples/webhook/README.md:
--------------------------------------------------------------------------------
1 | wgcg with webhook
2 | =================
3 |
4 | Here we're going to show how we can use [wgcg.sh](../../README.md) tool in combination with [webhook](https://github.com/adnanh/webhook) service to create endpoint from where client will be able to download WireGuard configuration.
5 |
6 | We'll assume that [wgcg.sh](../../README.md) is already configured and ready to use.
7 |
8 | The only difference from standard configuration is that you will have to create 2 configuration files if you plan to configure 2 WireGuard servers behind LB and to set valid SSH IP address (`WGCG_SERVER_SSH_IP`) in both configuration files, all other settings should be the same:
9 |
10 | - `/root/wireguard/wgcg/wg-1.conf`
11 | - `/root/wireguard/wgcg/wg-2.conf`
12 |
13 | Preparation
14 | -----------
15 |
16 | Copy all the scripts from local [bin](./bin) to `/usr/local/bin` directory on the remote server where [wgcg.sh](../../README.md) script is already installed.
17 |
18 | Download, install and configure `webhook` and `nginx` services.
19 |
20 | ### Webhook
21 |
22 | Install `webhook` binary.
23 |
24 | ```bash
25 | WEBHOOK_VERSION="2.7.0"
26 | wget https://github.com/adnanh/webhook/releases/download/${WEBHOOK_VERSION}/webhook-linux-amd64.tar.gz
27 | tar xzvf webhook-linux-amd64.tar.gz
28 | mv webhook-linux-amd64/webhook /usr/local/bin/webhook_${WEBHOOK_VERSION}
29 | cd /usr/local/bin
30 | chown root:root webhook_${WEBHOOK_VERSION}
31 | ln -snf webhook_${WEBHOOK_VERSION} webhook
32 | cd
33 | ```
34 |
35 | Specify command line options that will be used by `webhook` service.
36 |
37 | ```bash
38 | cat > /etc/default/webhook <<'EOF'
39 | ### SSL termination on Webhook layer
40 | #OPTIONS="-hooks=/etc/webhook/hooks.json -hotreload -ip 127.0.0.1 -port 9000 -secure -cert /etc/letsencrypt/live/wgcg.yourdomain.com/fullchain.pem -key /etc/letsencrypt/live/wgcg.yourdomain.com/privkey.pem -verbose"
41 |
42 | ### SSL termination on Nginx layer
43 | OPTIONS="-hooks=/etc/webhook/hooks.json -hotreload -ip 127.0.0.1 -port 9000 -verbose"
44 | EOF
45 | ```
46 |
47 | Create systemd unit for `webhook` service.
48 |
49 | ```bash
50 | systemctl edit --force --full webhook.service
51 | ```
52 |
53 | ```plain
54 | [Unit]
55 | Description=Webhook Service
56 | Documentation=https://github.com/adnanh/webhook
57 |
58 | [Service]
59 | EnvironmentFile=/etc/default/webhook
60 | ExecStart=/usr/local/bin/webhook $OPTIONS
61 | Restart=on-failure
62 |
63 | [Install]
64 | WantedBy=multi-user.target
65 | ```
66 |
67 | Create first part of `webhook` configuration file that will be used by our scripts to automatically generate the main configuration file => `/etc/webhook/hooks.json`
68 |
69 | ```bash
70 | mkdir -p /etc/webhook && cat > /etc/webhook/main.json <<'EOF'
71 | [
72 | {
73 | "id": "wgcg",
74 | "execute-command": "/usr/local/bin/wgcg-html-gpg.sh",
75 | "include-command-output-in-response": true,
76 | "response-headers": [
77 | {
78 | "name": "Cache-Control",
79 | "value": "no-store, no-cache, must-revalidate"
80 | }
81 | ],
82 | "pass-arguments-to-command": [
83 | {
84 | "source": "url",
85 | "name": "servername"
86 | },
87 | {
88 | "source": "url",
89 | "name": "username"
90 | }
91 | ],
92 | "trigger-rule": {}
93 | }
94 | ]
95 | EOF
96 | ```
97 |
98 | ### Nginx
99 |
100 | Install `nginx` service.
101 |
102 | ```bash
103 | apt install nginx
104 | ```
105 |
106 | Create vhost configuration.
107 |
108 | **Note:** Don't forget to replace `wgcg.yourdomain.com` domain name with real domain name and to generate certificate for it (see `certbot` section down below).
109 |
110 | ```bash
111 | cat > /etc/nginx/sites-available/wgcg.yourdomain.com.conf <<'EOF'
112 | # Disable emitting nginx version
113 | server_tokens off;
114 |
115 | # Sets the maximum allowed size of the client request body
116 | # Setting size to 0 disables checking of client request body size
117 | #client_max_body_size 0;
118 |
119 | server {
120 | listen 80 default_server;
121 | server_name wgcg.yourdomain.com;
122 |
123 | #access_log /var/log/nginx/wgcg.yourdomain.com-acme_access.log;
124 | #error_log /var/log/nginx/wgcg.yourdomain.com-acme_error.log;
125 |
126 | ## https://certbot.eff.org/docs/using.html#webroot
127 | #location ^~ /.well-known/acme-challenge/ {
128 | # root /usr/share/nginx/wgcg.yourdomain.com;
129 | #}
130 |
131 | location / {
132 | return 301 https://$server_name$request_uri;
133 | }
134 | }
135 |
136 | server {
137 | listen 443 ssl;
138 | server_name wgcg.yourdomain.com;
139 |
140 | access_log /var/log/nginx/wgcg.yourdomain.com_access.log;
141 | error_log /var/log/nginx/wgcg.yourdomain.com_error.log;
142 |
143 | ssl_certificate /etc/letsencrypt/live/wgcg.yourdomain.com/fullchain.pem;
144 | ssl_certificate_key /etc/letsencrypt/live/wgcg.yourdomain.com/privkey.pem;
145 | #ssl_trusted_certificate /etc/nginx/conf.d/ssl/ca-certs.pem;
146 |
147 | ssl_session_cache shared:SSL:20m;
148 | ssl_session_timeout 10m;
149 |
150 | ssl_prefer_server_ciphers on;
151 | ssl_protocols TLSv1.2 TLSv1.3;
152 | ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;
153 |
154 | add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
155 |
156 | location /healthcheck {
157 | add_header Content-Type "text/plain";
158 | return 200 "OK";
159 | }
160 |
161 | location / {
162 | #satisfy all;
163 |
164 | #allow 10.0.0.0/8;
165 | #deny all;
166 |
167 | auth_basic "wgcg";
168 | auth_basic_user_file /etc/nginx/.htpasswd;
169 |
170 | proxy_pass http://127.0.0.1:9000;
171 | proxy_set_header Host $host;
172 | proxy_set_header X-Real-IP $remote_addr;
173 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
174 | proxy_set_header X-Forwarded-Proto $scheme;
175 | }
176 | }
177 | EOF
178 | ```
179 |
180 | Disable `default` vhost and enable our newly added vhost configuration.
181 |
182 | ```bash
183 | cd /etc/nginx/sites-enabled
184 | rm -f default
185 | ln -snf /etc/nginx/sites-available/wgcg.yourdomain.com.conf
186 | cd
187 | ```
188 |
189 | Create `test` user that will be used for Nginx Basic Auth.
190 |
191 | Install required utils.
192 |
193 | ```bash
194 | apt install apache2-utils
195 | ```
196 |
197 | Create a user.
198 |
199 | ```bash
200 | htpasswd -c /etc/nginx/.htpasswd test
201 | ```
202 |
203 | Use Let's Encrypt with [certbot](https://certbot.eff.org/all-instructions) client to generate certificates if needed.
204 |
205 | ```bash
206 | apt install certbot
207 | ```
208 |
209 | **Note:** We're using DNS TXT RR for verification because our Nginx instance isn't internet-facing.
210 |
211 | ```bash
212 | certbot certonly --manual --preferred-challenges dns
213 | ```
214 |
215 | **Note:** Please be sure to name it exactly like it is specified in the Nginx configuration file.
216 |
217 | ```bash
218 | certbot certificates
219 | ```
220 |
221 | Fire up
222 | -------
223 |
224 | Now when all the components are in place we are ready to fire up the services.
225 |
226 | Generate webhook's main configuration file => `/etc/webhook/hooks.json`
227 |
228 | **Note:** This script has to be executed only once and before `webhook` service is started for the first time.
229 |
230 | ```bash
231 | wh.py
232 | ```
233 |
234 | Enable and start `webhook` and restart `nginx` service.
235 |
236 | ```bash
237 | systemctl enable --now webhook
238 | systemctl restart nginx
239 | ```
240 |
241 | Check if everything is running without errors.
242 |
243 | ```bash
244 | journalctl -fu webhook
245 | journalctl -fu nginx
246 | ```
247 |
248 | Usage
249 | -----
250 |
251 | Generate client configuration.
252 |
253 | ```bash
254 | wgcg-gen.sh add test@yourdomain.com 10.0.0.2
255 | ```
256 |
257 | Remove client configuration.
258 |
259 | ```bash
260 | wgcg-gen.sh remove test@yourdomain.com
261 | ```
262 |
263 | List existing clients.
264 |
265 | ```bash
266 | wgcg-gen.sh list
267 | ```
268 |
269 | When new client is added, URL where client can download configuration will be printed out.
270 |
271 | Example:
272 |
273 | https://wgcg.yourdomain.com/hooks/wgcg?servername=server1&username=test@yourdomain.com&token=QwhRKi2WNz9UFqqUE6nZsNckQ2jDQtGfqqvCl6kC
274 |
--------------------------------------------------------------------------------
/examples/webhook/bin/wgcg-gen.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Author: Milos Buncic
3 | # Date: 2020/06/10
4 | # Description: Generate and sync WireGuard configuration and publish the configuration via HTTP endpoint
5 |
6 | export WGCG_CONFIG_FILE="${HOME}/wireguard/wgcg/wg-1.conf"
7 | source ${WGCG_CONFIG_FILE}
8 |
9 | WEBHOOK_ENDPOINT="https://wgcg.yourdomain.com/hooks/wgcg?servername=${WGCG_SERVER_NAME}"
10 | WEBHOOK_CONFIG_PATH="/etc/webhook"
11 |
12 |
13 | help() {
14 | echo "Usage:"
15 | echo " $(basename ${0}) options"
16 | echo
17 | echo "Options:"
18 | echo " list List existing clients"
19 | echo " add client_name private_ip Add a new client"
20 | echo " remove client_name Remove client"
21 | echo " sync Synchronize server configuration"
22 | echo " help Show this help"
23 | }
24 |
25 |
26 | genpass() {
27 | local length=${1:-40}
28 | local re='^[0-9]*$'
29 |
30 | if [[ ${length} =~ ${re} ]]; then
31 | # LC_CTYPE=C required if running on MacOS
32 | LC_CTYPE=C tr -dc 'A-Za-z0-9' < /dev/urandom | head -c ${length} | xargs
33 | else
34 | return 1
35 | fi
36 | }
37 |
38 |
39 | gen_webhook_config() {
40 | local client_name=${1}
41 | local auth_file=${2}
42 | local client_token=$(genpass)
43 |
44 | cat > ${auth_file} <
15 |
16 | wgcg
17 |
18 |
71 |
72 |
73 |
74 |