1
0
mirror of https://github.com/donaldzou/WGDashboard.git synced 2024-11-22 15:20:09 +01:00

v2.2 beta 4

This commit is contained in:
Donald Cheng Hong Zou 2021-08-14 17:13:16 -04:00
parent e2fb8dca5b
commit 0d380672f3
30 changed files with 8035 additions and 579 deletions

194
README.md
View File

@ -4,7 +4,7 @@
<p align="center"> <p align="center">
<img src="https://raw.githubusercontent.com/donaldzou/wireguard-dashboard/main/img/Group%202.png" width="128"> <img src="img/logo.png" width="128">
</p> </p>
<h1 align="center"> Wireguard Dashboard</h1> <h1 align="center"> Wireguard Dashboard</h1>
@ -26,6 +26,9 @@
- 🪚 **Bug Fixed** - 🪚 **Bug Fixed**
- When there are comments in the wireguard config file, will cause the dashboard to crash. - When there are comments in the wireguard config file, will cause the dashboard to crash.
- Used regex to search for config files. - Used regex to search for config files.
- **🧐 Other Changes**
- Moved all external CSS and JavaScript file to local hosting (Except Bootstrap Icon, due to large amount of SVG files).
- Updated `Flask` from`v1.1.2` to `v2.0.1`, and `Jinja` from `v2.10.1` to `v3.0.1`
<hr> <hr>
@ -59,45 +62,69 @@
## 📝 Requirement ## 📝 Requirement
- Recommend the following OS, tested by our beloved users: - Recommend the following OS, tested by our beloved users:
- [x] Ubuntu 18.04.1 LTS - 20.04.1 LTS - [x] Ubuntu 18.04.1 LTS - 20.04.1 LTS [@Me]
- [x] Debian GNU/Linux 10 (buster) [❤️ @[robchez](https://github.com/robchez)] - [x] Debian GNU/Linux 10 (buster) [❤️ @[robchez](https://github.com/robchez)]
- [x] AlmaLinux 8.4 (Electric Cheetah) [❤️ @[barry-smithjr](https://github.com/)] - [x] AlmaLinux 8.4 (Electric Cheetah) [❤️ @[barry-smithjr](https://github.com/)]
- [x] CentOS 7 [❤️ @[PrzemekSkw](https://github.com/PrzemekSkw)] - [x] CentOS 7 [❤️ @[PrzemekSkw](https://github.com/PrzemekSkw)]
- [ ] If you have tested on other OS and it works perfectly please provide it to me in [#31](https://github.com/donaldzou/wireguard-dashboard/issues/31). Thank you!
- Make sure you have **Wireguard** and **Wireguard-Tools (`wg-quick`)** installed. <a href="https://www.wireguard.com/install/">How to install?</a>
- Configuration files under **/etc/wireguard**
- **Note**: > **If you have tested on other OS and it works perfectly please provide it to me in [#31](https://github.com/donaldzou/wireguard-dashboard/issues/31). Thank you!**
- **For `[Interface]` in the `.conf` file, please make sure you have `SaveConfig = true` under `[Interface]`** (Bug mentioned in [#9](https://github.com/donaldzou/wireguard-dashboard/issues/9#issuecomment-852346481))
- **For peers, `PublicKey` & `AllowedIPs` is required.** - **WireGuard** and **Wireguard-Tools (`wg-quick`)** are installed.
> Don't know how? Check this <a href="https://www.wireguard.com/install/">official documentation</a>
- Configuration files under **`/etc/wireguard`**, but please note the following sample
```ini
[Interface]
...
SaveConfig = true
# Need to include this line to allow WireGuard Tool to save your configuration
[Peer]
PublicKey = abcd1234
AllowedIPs = 1.2.3.4/32
# Must have for each peer
```
- Python 3.7+ & Pip3 - Python 3.7+ & Pip3
## 🛠 Install ## 🛠 Install
1. **Download Wireguard Dashboard** 1. **Download Wireguard Dashboard**
```shell ```shell
$ git clone -b v2.2 https://github.com/donaldzou/wireguard-dashboard.git git clone -b v2.2 https://github.com/donaldzou/wireguard-dashboard.git
2. **Install Python Dependencies**
2. Open the Wireguard Dashboard folder
```shell ```shell
$ cd wireguard-dashboard/src cd wireguard-dashboard/src
$ python3 -m pip install -r requirements.txt ```
3. Install Python Dependencies
```shell
python3 -m pip install -r requirements.txt
``` ```
3. **Install & run Wireguard Dashboard** 4. Give read, write and execute permission to root of the WireGuard configuration folder, you can change the path if your configuration files is not stored in `/etc/wireguard`
```shell ```shell
$ sudo chmod -R 744 /etc/wireguard # Add read and execute permission of the wireguard config folder sudo chmod -R 744 /etc/wireguard
$ sudo chmod u+x wgd.sh ```
$ ./wgd.sh start
5. Install & run Wireguard Dashboard
```shell
sudo chmod u+x wgd.sh
./wgd.sh start
``` ```
**Note**: **Note**:
> For [`pivpn`](https://github.com/pivpn/pivpn) user, please use `sudo ./wgd.sh start` to run if your current account does not have the permission to run `wg show` and `wg-quick`. > For [`pivpn`](https://github.com/pivpn/pivpn) user, please use `sudo ./wgd.sh start` to run if your current account does not have the permission to run `wg show` and `wg-quick`.
4. **Access dashboard** 6. **Access dashboard**
Access your server with port `10086` ! e.g (http://your_server_ip:10086), continue to read to on how to change port and ip that dashboard is running with. Access your server with port `10086` ! e.g (http://your_server_ip:10086), continue to read to on how to change port and ip that dashboard is running with.
@ -107,45 +134,45 @@
```shell ```shell
$ cd Wireguard-Dashboard/src cd Wireguard-Dashboard/src
----------------------------- -----------------------------
$ ./wgd.sh start # Start the dashboard in background ./wgd.sh start # Start the dashboard in background
----------------------------- -----------------------------
$ ./wgd.sh debug # Start the dashboard in foreground (debug mode) ./wgd.sh debug # Start the dashboard in foreground (debug mode)
----------------------------- -----------------------------
$ ./wgd.sh stop # Stop the dashboard ./wgd.sh stop # Stop the dashboard
----------------------------- -----------------------------
$ ./wgd.sh restart # Restart the dasboard ./wgd.sh restart # Restart the dasboard
``` ```
#### Autostart Wireguard Dashboard on boot #### Autostart Wireguard Dashboard on boot (>= v2.2)
In the `src` folder, it contained a file called `wg-dashboard.service`, we can use this file to let our system to autostart the dashboard after reboot. The following has tested on Ubuntu 18.04.1 LTS, please don't hesitate to provide your system if you have tested the autostart on another system. In the `src` folder, it contained a file called `wg-dashboard.service`, we can use this file to let our system to autostart the dashboard after reboot. The following guide has tested on **Ubuntu**, most **Debian** based OS might be the same, but some might not. Please don't hesitate to provide your system if you have tested the autostart on another system.
1. **Changing the directory to the dashboard's directory** 1. Changing the directory to the dashboard's directory
```bash ```shell
$ cd wireguard-dashboard/src cd wireguard-dashboard/src
``` ```
2. **Get the full path of the dashboard's directory** 2. Get the full path of the dashboard's directory
```bash ```shell
$ pwd pwd
#Output: /root/wireguard-dashboard/src #Output: /root/wireguard-dashboard/src
``` ```
For me, my output is the one above, your's might be different since it depends on where you downloaded the dashboard. **Copy the the output to somewhere, we will need this in the next step.** For this example, the output is `/root/wireguard-dashboard/src`, your path might be different since it depends on where you downloaded the dashboard in the first place. **Copy the the output to somewhere, we will need this in the next step.**
3. **Edit the service file** 3. Edit the service file, the service file is located in `wireguard-dashboard/src`, you can use other editor you like, here will be using `nano`
```bash ```shell
$ nano wg-dashboard.service nano wg-dashboard.service
``` ```
You will see something like this: You will see something like this:
``` ```ini
[Unit] [Unit]
After=netword.service After=netword.service
@ -159,9 +186,9 @@ In the `src` folder, it contained a file called `wg-dashboard.service`, we can u
WantedBy=default.target WantedBy=default.target
``` ```
Now, we need to replace both `<your dashboard directory full path here>` to the one you just copied from step 2. After doing this, the file will become something like this: Now, we need to replace both `<your dashboard directory full path here>` to the one you just copied from step 2. After doing this, the file will become something like this, your file might be different:
``` ```ini
[Unit] [Unit]
After=netword.service After=netword.service
@ -175,9 +202,9 @@ In the `src` folder, it contained a file called `wg-dashboard.service`, we can u
WantedBy=default.target WantedBy=default.target
``` ```
**Be aware that after the value of `WorkingDirectory`, it does not have a `/` (slash).** You can save the file with `control+x` and press `Y`. **Be aware that after the value of `WorkingDirectory`, it does not have a `/` (slash).** And then save the file after you edited it
4. **Copy the service file to systemd folder** 4. Copy the service file to systemd folder
```bash ```bash
$ cp wg-dashboard.service /etc/systemd/system/wg-dashboard.service $ cp wg-dashboard.service /etc/systemd/system/wg-dashboard.service
@ -185,7 +212,7 @@ In the `src` folder, it contained a file called `wg-dashboard.service`, we can u
To make sure you copy the file successfully, you can use this command `cat /etc/systemd/system/wg-dashboard.service` to see if it will output the file you just edited. To make sure you copy the file successfully, you can use this command `cat /etc/systemd/system/wg-dashboard.service` to see if it will output the file you just edited.
5. **Enable the service** 5. Enable the service
```bash ```bash
$ sudo chmod 664 /etc/systemd/system/wg-dashboard.service $ sudo chmod 664 /etc/systemd/system/wg-dashboard.service
@ -194,7 +221,7 @@ In the `src` folder, it contained a file called `wg-dashboard.service`, we can u
$ sudo systemctl start wg-dashboard.service # <-- To start the service $ sudo systemctl start wg-dashboard.service # <-- To start the service
``` ```
6. **Check if the service run correctly** 6. Check if the service run correctly
```bash ```bash
$ sudo systemctl status wg-dashboard.service $ sudo systemctl status wg-dashboard.service
@ -202,7 +229,7 @@ In the `src` folder, it contained a file called `wg-dashboard.service`, we can u
And you should see something like this And you should see something like this
```bash ```shell
● wg-dashboard.service ● wg-dashboard.service
Loaded: loaded (/etc/systemd/system/wg-dashboard.service; enabled; vendor preset: enabled) Loaded: loaded (/etc/systemd/system/wg-dashboard.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2021-08-03 22:31:26 UTC; 4s ago Active: active (running) since Tue 2021-08-03 22:31:26 UTC; 4s ago
@ -223,17 +250,17 @@ In the `src` folder, it contained a file called `wg-dashboard.service`, we can u
Aug 03 22:31:27 ubuntu-wg python3[6602]: * Running on http://0.0.0.0:10086/ (Press CTRL+C to quit) Aug 03 22:31:27 ubuntu-wg python3[6602]: * Running on http://0.0.0.0:10086/ (Press CTRL+C to quit)
``` ```
If you see `Active:` followed by `active (running) since...` then it means it run correctly. If you see `Active:` followed by `active (running) since...` then it means it run correctly.
7. **Stop/Start/Restart the service** 7. Stop/Start/Restart the service
```bash ```bash
$ sudo systemctl stop wg-dashboard.service # <-- To stop the service sudo systemctl stop wg-dashboard.service # <-- To stop the service
$ sudo systemctl start wg-dashboard.service # <-- To start the service sudo systemctl start wg-dashboard.service # <-- To start the service
$ sudo systemctl restart wg-dashboard.service # <-- To restart the service sudo systemctl restart wg-dashboard.service # <-- To restart the service
``` ```
8. **And now you can reboot your system, and use the command at step 6 to see if it will auto start after the reboot. If you have any questions or problem, please report it in the issue page.** 8. **And now you can reboot your system, and use the command at step 6 to see if it will auto start after the reboot, or just simply access the dashboard through your browser. If you have any questions or problem, please report it in the issue page.**
## ✂️ Dashboard Configuration ## ✂️ Dashboard Configuration
@ -241,28 +268,28 @@ In the `src` folder, it contained a file called `wg-dashboard.service`, we can u
Since version 2.0, Wireguard Dashboard will be using a configuration file called `wg-dashboard.ini`, (It will generate automatically after first time running the dashboard). More options will include in future versions, and for now it included the following config: Since version 2.0, Wireguard Dashboard will be using a configuration file called `wg-dashboard.ini`, (It will generate automatically after first time running the dashboard). More options will include in future versions, and for now it included the following config:
| | Description | Default Value | | | Description | Default | Available in Setting |
| --------------- | ------------------------------------------------------------ | ------------------------ | | --------------- | ------------------------------------------------------------ | ------------------------ | -------------------- |
| **`[Account]`** | | | | **`[Account]`** | | | |
| `username` | Dashboard login username | `admin` | | `username` | Dashboard login username | `admin` | Yes |
| `password` | Password, will be hash with SHA256 | `admin` hashed in SHA256 | | `password` | Password, will be hash with SHA256 | `admin` hashed in SHA256 | Yes |
| **`[Server]`** | | | | **`[Server]`** | | | |
| `wg_conf_path` | The path of all the Wireguard configurations | `/etc/wireguard` | | `wg_conf_path` | The path of all the Wireguard configurations | `/etc/wireguard` | Yes |
| `app_ip` | IP address the dashboard will run with | `0.0.0.0` | | `app_ip` | IP address the dashboard will run with | `0.0.0.0` | Yes |
| `app_port` | Port the the dashboard will run with | `10086` | | `app_port` | Port the the dashboard will run with | `10086` | Yes |
| `auth_req` | Does the dashboard need authentication to access | `true` | | `auth_req` | Does the dashboard need authentication to access | `true` | No |
| | If `auth_req = false` , user will not be access the **Setting** tab due to security consideration. **User can only change the file directly in system**. | | | | If `auth_req = false` , user will not be access the **Setting** tab due to security consideration. **User can only edit the file directly in system**. | | |
| `version` | Dashboard Version | N/A | | `version` | Dashboard Version | `v2.2` | No |
<p align=center>Latest Version: V2.2</p> <p align=center>Latest Version: v2.2</p>
All these settings will be able to configure within the dashboard in **Settings** on the sidebar, without changing the actual file. **Except `version` and `auth_req` due to security consideration.** **Except `auth_req` due to security consideration.**
#### Generating QR code and peer configuration file (.conf) #### Generating QR code and peer configuration file (.conf)
Starting version 2.2, dashboard can now generate QR code and configuration file for each peer. Here is a template of what each QR code encoded with and the same content will be inside the file: Starting version 2.2, dashboard can now generate QR code and configuration file for each peer. Here is a template of what each QR code encoded with and the same content will be inside the file:
``` ```ini
[Interface] [Interface]
PrivateKey = QWERTYUIOPO234567890YUSDAKFH10E1B12JE129U21= PrivateKey = QWERTYUIOPO234567890YUSDAKFH10E1B12JE129U21=
Address = 0.0.0.0/32 Address = 0.0.0.0/32
@ -274,34 +301,34 @@ AllowedIPs = 0.0.0.0/0
Endpoint = 0.0.0.0:51820 Endpoint = 0.0.0.0:51820
``` ```
| | Description | Default Value | | | Description | Default Value | Available in Peer setting |
| ----------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | | ----------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------- |
| **`[Interface]`** | | | | **`[Interface]`** | | | |
| `PrivateKey` | The private key of this peer | N/A | | `PrivateKey` | The private key of this peer | Private key generated by WireGuard (`wg genkey`) or provided by user | Yes |
| `Address` | The `allowed_ips` of your peer | N/A | | `Address` | The `allowed_ips` of your peer | N/A | Yes |
| `DNS` | The DNS server your peer will use | `1.1.1.1` - Cloud flare DNS, you can change it when you adding the peer or in the peer setting. | | `DNS` | The DNS server your peer will use | `1.1.1.1` - Cloud flare DNS, you can change it when you adding the peer or in the peer setting. | Yes |
| **`[Peer]`** | | | | **`[Peer]`** | | | |
| `PublicKey` | The public key of your server | N/A | | `PublicKey` | The public key of your server | N/A | No |
| `AllowedIPs` | IP ranges for which a peer will route traffic | `0.0.0.0/0` - Indicated a default route to send all internet and VPN traffic through that peer. | | `AllowedIPs` | IP ranges for which a peer will route traffic | `0.0.0.0/0` - Indicated a default route to send all internet and VPN traffic through that peer. | No |
| `Endpoint` | Your wireguard server ip and port, the dashboard will search for your server's default interface's ip. | `<your server default interface ip>:<listen port>` | | `Endpoint` | Your wireguard server ip and port, the dashboard will search for your server's default interface's ip. | `<your server default interface ip>:<listen port>` | No |
## ❓ How to update the dashboard? ## ❓ How to update the dashboard?
1. Change your directory to `wireguard-dashboard` 1. Change your directory to `wireguard-dashboard`
``` ```shell
$ cd wireguard-dashboard cd wireguard-dashboard
``` ```
2. Get the newest version 2. Get the newest version
``` ```shell
$ sudo git pull https://github.com/donaldzou/wireguard-dashboard.git v2.2 --force sudo git pull https://github.com/donaldzou/wireguard-dashboard.git v2.2 --force
``` ```
3. Update and install all python dependencies 3. Update and install all python dependencies
``` ```shell
$ python3 -m pip install -r requirements.txt python3 -m pip install -r requirements.txt
``` ```
4. Start the dashboard 4. Start the dashboard
``` ```shell
$ ./wgd.sh start ./wgd.sh start
``` ```
## 🔍 Screenshot ## 🔍 Screenshot
@ -372,10 +399,11 @@ Endpoint = 0.0.0.0:51820
- [Bootstrap Icon](https://icons.getbootstrap.com) `v1.4.0` - [Bootstrap Icon](https://icons.getbootstrap.com) `v1.4.0`
- [jQuery](https://jquery.com) `v3.5.1` - [jQuery](https://jquery.com) `v3.5.1`
- Python - Python
- [Flask](https://pypi.org/project/Flask/) `v1.1.2` - [Flask](https://pypi.org/project/Flask/) `v2.0.1`
- [TinyDB](https://pypi.org/project/tinydb/) `v4.3.0` - [TinyDB](https://pypi.org/project/tinydb/) `v4.3.0`
- [ifcfg](https://pypi.org/project/ifcfg/) `v0.21` - [ifcfg](https://pypi.org/project/ifcfg/) `v0.21`
- [icmplib](https://pypi.org/project/icmplib/) `v2.1.1` - [icmplib](https://pypi.org/project/icmplib/) `v2.1.1`
- [flask-qrcode](https://pypi.org/project/Flask-QRcode/) `v3.0.0`
## ✨ Contributors ## ✨ Contributors

Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 198 KiB

BIN
img/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 KiB

View File

@ -23,13 +23,13 @@ dashboard_version = 'v2.2'
dashboard_conf = 'wg-dashboard.ini' dashboard_conf = 'wg-dashboard.ini'
# Default Wireguard IP # Default Wireguard IP
wg_ip = ifcfg.default_interface()['inet'] wg_ip = ifcfg.default_interface()['inet']
# Upgrade Required # Upgrade Required
update = "" update = ""
# Flask App Configuration # Flask App Configuration
app = Flask("Wireguard Dashboard") app = Flask("Wireguard Dashboard")
app.secret_key = secrets.token_urlsafe(16) app.secret_key = secrets.token_urlsafe(16)
app.config['TEMPLATES_AUTO_RELOAD'] = True app.config['TEMPLATES_AUTO_RELOAD'] = True
# Enable QR Code Generator
QRcode(app) QRcode(app)
@ -39,7 +39,8 @@ def get_conf_peer_key(config_name):
peer_key = peer_key.decode("UTF-8").split() peer_key = peer_key.decode("UTF-8").split()
return peer_key return peer_key
except Exception: except Exception:
return config_name+" is not running." return config_name + " is not running."
def get_conf_running_peer_number(config_name): def get_conf_running_peer_number(config_name):
running = 0 running = 0
@ -59,10 +60,12 @@ def get_conf_running_peer_number(config_name):
count += 2 count += 2
return running return running
def is_match(regex, text): def is_match(regex, text):
pattern = re.compile(regex) pattern = re.compile(regex)
return pattern.search(text) is not None return pattern.search(text) is not None
def read_conf_file(config_name): def read_conf_file(config_name):
# Read Configuration File Start # Read Configuration File Start
conf_location = wg_conf_path + "/" + config_name + ".conf" conf_location = wg_conf_path + "/" + config_name + ".conf"
@ -74,7 +77,7 @@ def read_conf_file(config_name):
} }
peers_start = 0 peers_start = 0
for i in range(len(file)): for i in range(len(file)):
if not is_match("#(.*)",file[i]): if not is_match("#(.*)", file[i]):
if file[i] == "[Peer]": if file[i] == "[Peer]":
peers_start = i peers_start = i
break break
@ -101,6 +104,7 @@ def read_conf_file(config_name):
# Read Configuration File End # Read Configuration File End
return conf_peer_data return conf_peer_data
def get_latest_handshake(config_name, db, peers): def get_latest_handshake(config_name, db, peers):
# Get latest handshakes # Get latest handshakes
try: try:
@ -124,6 +128,7 @@ def get_latest_handshake(config_name, db, peers):
db.update({"latest_handshake": "(None)", "status": status}, peers.id == data_usage[count]) db.update({"latest_handshake": "(None)", "status": status}, peers.id == data_usage[count])
count += 2 count += 2
def get_transfer(config_name, db, peers): def get_transfer(config_name, db, peers):
# Get transfer # Get transfer
try: try:
@ -158,6 +163,7 @@ def get_transfer(config_name, db, peers):
count += 3 count += 3
def get_endpoint(config_name, db, peers): def get_endpoint(config_name, db, peers):
# Get endpoint # Get endpoint
try: try:
@ -170,12 +176,14 @@ def get_endpoint(config_name, db, peers):
db.update({"endpoint": data_usage[count + 1]}, peers.id == data_usage[count]) db.update({"endpoint": data_usage[count + 1]}, peers.id == data_usage[count])
count += 2 count += 2
def get_allowed_ip(config_name, db, peers, conf_peer_data): def get_allowed_ip(config_name, db, peers, conf_peer_data):
# Get allowed ip # Get allowed ip
for i in conf_peer_data["Peers"]: for i in conf_peer_data["Peers"]:
db.update({"allowed_ip": i.get('AllowedIPs', '(None)')}, peers.id == i["PublicKey"]) db.update({"allowed_ip": i.get('AllowedIPs', '(None)')}, peers.id == i["PublicKey"])
def get_conf_peers_data(config_name):
def get_all_peers_data(config_name):
db = TinyDB('db/' + config_name + '.json') db = TinyDB('db/' + config_name + '.json')
peers = Query() peers = Query()
conf_peer_data = read_conf_file(config_name) conf_peer_data = read_conf_file(config_name)
@ -186,7 +194,8 @@ def get_conf_peers_data(config_name):
db.insert({ db.insert({
"id": i['PublicKey'], "id": i['PublicKey'],
"private_key": "", "private_key": "",
"DNS":"1.1.1.1", "DNS": "1.1.1.1",
"endpoint_allowed_ip":"0.0.0.0/0",
"name": "", "name": "",
"total_receive": 0, "total_receive": 0,
"total_sent": 0, "total_sent": 0,
@ -204,6 +213,8 @@ def get_conf_peers_data(config_name):
update_db['private_key'] = '' update_db['private_key'] = ''
if "DNS" not in search[0]: if "DNS" not in search[0]:
update_db['DNS'] = '1.1.1.1' update_db['DNS'] = '1.1.1.1'
if "endpoint_allowed_ip" not in search[0]:
update_db['endpoint_allowed_ip'] = '0.0.0.0/0'
db.update(update_db, peers.id == i['PublicKey']) db.update(update_db, peers.id == i['PublicKey'])
tic = time.perf_counter() tic = time.perf_counter()
@ -215,14 +226,21 @@ def get_conf_peers_data(config_name):
print(f"Finish fetching data in {toc - tic:0.4f} seconds") print(f"Finish fetching data in {toc - tic:0.4f} seconds")
db.close() db.close()
def get_peers(config_name):
get_conf_peers_data(config_name) def get_peers(config_name, search, sort_t):
get_all_peers_data(config_name)
db = TinyDB('db/' + config_name + '.json') db = TinyDB('db/' + config_name + '.json')
result = db.all() peer = Query()
result = sorted(result, key=lambda d: d['status']) print(search)
if len(search) == 0:
result = db.all()
else:
result = db.search(peer.name.matches('(.*)(' + re.escape(search) + ')(.*)'))
result = sorted(result, key=lambda d: d[sort_t])
db.close() db.close()
return result return result
def get_conf_pub_key(config_name): def get_conf_pub_key(config_name):
conf = configparser.ConfigParser(strict=False) conf = configparser.ConfigParser(strict=False)
conf.read(wg_conf_path + "/" + config_name + ".conf") conf.read(wg_conf_path + "/" + config_name + ".conf")
@ -231,6 +249,7 @@ def get_conf_pub_key(config_name):
conf.clear() conf.clear()
return pub.decode().strip("\n") return pub.decode().strip("\n")
def get_conf_listen_port(config_name): def get_conf_listen_port(config_name):
conf = configparser.ConfigParser(strict=False) conf = configparser.ConfigParser(strict=False)
conf.read(wg_conf_path + "/" + config_name + ".conf") conf.read(wg_conf_path + "/" + config_name + ".conf")
@ -238,6 +257,7 @@ def get_conf_listen_port(config_name):
conf.clear() conf.clear()
return port return port
def get_conf_total_data(config_name): def get_conf_total_data(config_name):
db = TinyDB('db/' + config_name + '.json') db = TinyDB('db/' + config_name + '.json')
upload_total = 0 upload_total = 0
@ -254,6 +274,7 @@ def get_conf_total_data(config_name):
db.close() db.close()
return [total, upload_total, download_total] return [total, upload_total, download_total]
def get_conf_status(config_name): def get_conf_status(config_name):
ifconfig = dict(ifcfg.interfaces().items()) ifconfig = dict(ifcfg.interfaces().items())
if config_name in ifconfig.keys(): if config_name in ifconfig.keys():
@ -261,6 +282,7 @@ def get_conf_status(config_name):
else: else:
return "stopped" return "stopped"
def get_conf_list(): def get_conf_list():
conf = [] conf = []
for i in os.listdir(wg_conf_path): for i in os.listdir(wg_conf_path):
@ -276,6 +298,7 @@ def get_conf_list():
conf = sorted(conf, key=itemgetter('conf')) conf = sorted(conf, key=itemgetter('conf'))
return conf return conf
def genKeys(): def genKeys():
gen = subprocess.check_output('wg genkey > private_key.txt && wg pubkey < private_key.txt > public_key.txt', gen = subprocess.check_output('wg genkey > private_key.txt && wg pubkey < private_key.txt > public_key.txt',
shell=True) shell=True)
@ -290,6 +313,7 @@ def genKeys():
os.remove('public_key.txt') os.remove('public_key.txt')
return data return data
def genPubKey(private_key): def genPubKey(private_key):
pri_key_file = open('private_key.txt', 'w') pri_key_file = open('private_key.txt', 'w')
pri_key_file.write(private_key) pri_key_file.write(private_key)
@ -300,10 +324,11 @@ def genPubKey(private_key):
public_key = public.readline().strip() public_key = public.readline().strip()
os.remove('private_key.txt') os.remove('private_key.txt')
os.remove('public_key.txt') os.remove('public_key.txt')
return {"status":'success', "msg":"", "data":public_key} return {"status": 'success', "msg": "", "data": public_key}
except subprocess.CalledProcessError as exc: except subprocess.CalledProcessError as exc:
os.remove('private_key.txt') os.remove('private_key.txt')
return {"status":'failed', "msg":"Key is not the correct length or format", "data":""} return {"status": 'failed', "msg": "Key is not the correct length or format", "data": ""}
def checkKeyMatch(private_key, public_key, config_name): def checkKeyMatch(private_key, public_key, config_name):
result = genPubKey(private_key) result = genPubKey(private_key)
@ -318,6 +343,7 @@ def checkKeyMatch(private_key, public_key, config_name):
else: else:
return {'status': 'success'} return {'status': 'success'}
def checkAllowedIP(public_key, ip, config_name): def checkAllowedIP(public_key, ip, config_name):
db = TinyDB('db/' + config_name + '.json') db = TinyDB('db/' + config_name + '.json')
peers = Query() peers = Query()
@ -327,9 +353,26 @@ def checkAllowedIP(public_key, ip, config_name):
else: else:
existed_ip = db.search((peers.id != public_key) & (peers.allowed_ip == ip)) existed_ip = db.search((peers.id != public_key) & (peers.allowed_ip == ip))
if len(existed_ip) != 0: if len(existed_ip) != 0:
return {'status':'failed', 'msg':"Allowed IP already taken by another peer."} return {'status': 'failed', 'msg': "Allowed IP already taken by another peer."}
else: else:
return {'status':'success'} return {'status': 'success'}
def checkIp(ip):
return is_match("((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4}",ip)
def cleanIp(ip):
return ip.replace(' ','')
def cleanIpWithRange(ip):
return cleanIp(ip).split(',')
def checkIpWithRange(ip):
return is_match("((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|\/)){4}(0|8|16|24|32)(,|$)", ip)
def checkAllowedIPs(ip):
ip = cleanIpWithRange(ip)
for i in ip:
if not checkIpWithRange(i): return False
return True
@app.before_request @app.before_request
def auth_req(): def auth_req():
@ -344,7 +387,7 @@ def auth_req():
request.endpoint != "signout" and \ request.endpoint != "signout" and \
request.endpoint != "auth" and \ request.endpoint != "auth" and \
"username" not in session: "username" not in session:
print("User not loggedin - Attemped access: "+str(request.endpoint)) print("User not loggedin - Attemped access: " + str(request.endpoint))
if request.endpoint != "index": if request.endpoint != "index":
session['message'] = "You need to sign in first!" session['message'] = "You need to sign in first!"
else: else:
@ -387,7 +430,9 @@ def settings():
required_auth = config.get("Server", "auth_req") required_auth = config.get("Server", "auth_req")
return render_template('settings.html', conf=get_conf_list(), message=message, status=status, return render_template('settings.html', conf=get_conf_list(), message=message, status=status,
app_ip=config.get("Server", "app_ip"), app_port=config.get("Server", "app_port"), app_ip=config.get("Server", "app_ip"), app_port=config.get("Server", "app_port"),
required_auth=required_auth, wg_conf_path=config.get("Server", "wg_conf_path")) required_auth=required_auth, wg_conf_path=config.get("Server", "wg_conf_path"),
peer_global_DNS=config.get("Peers","peer_global_DNS"),
peer_endpoint_allowed_ip=config.get("Peers","peer_endpoint_allowed_ip"))
@app.route('/auth', methods=['POST']) @app.route('/auth', methods=['POST'])
@ -408,6 +453,10 @@ def auth():
@app.route('/update_acct', methods=['POST']) @app.route('/update_acct', methods=['POST'])
def update_acct(): def update_acct():
if len(request.form['username']) == 0:
session['message'] = "Username cannot be empty."
session['message_status'] = "danger"
return redirect(url_for("settings"))
config = configparser.ConfigParser(strict=False) config = configparser.ConfigParser(strict=False)
config.read(dashboard_conf) config.read(dashboard_conf)
config.set("Account", "username", request.form['username']) config.set("Account", "username", request.form['username'])
@ -424,6 +473,46 @@ def update_acct():
config.clear() config.clear()
return redirect(url_for("settings")) return redirect(url_for("settings"))
@app.route('/update_peer_default_config', methods=['POST'])
def update_peer_default_config():
config = configparser.ConfigParser(strict=False)
config.read(dashboard_conf)
if len(request.form['peer_endpoint_allowed_ip']) == 0 or len(request.form['peer_global_DNS']) == 0:
session['message'] = "Peer DNS or Peer Endpoint Allowed IP cannot be empty."
session['message_status'] = "danger"
return redirect(url_for("settings"))
# Check DNS Format
DNS = request.form['peer_global_DNS']
DNS = cleanIp(DNS)
if not checkIp(DNS):
session['message'] = "Peer DNS Format Incorrect. Example: 1.1.1.1"
session['message_status'] = "danger"
return redirect(url_for("settings"))
# Check Endpoint Allowed IPs
ip = request.form['peer_endpoint_allowed_ip']
if not checkAllowedIPs(ip):
session['message'] = "Peer Endpoint Allowed IPs Format Incorrect. Example: 192.168.1.1/32 or 192.168.1.1/32,192.168.1.2/32"
session['message_status'] = "danger"
return redirect(url_for("settings"))
config.set("Peers", "peer_endpoint_allowed_ip", ','.join(cleanIpWithRange(ip)))
config.set("Peers", "peer_global_DNS", request.form['peer_global_DNS'])
try:
config.write(open(dashboard_conf, "w"))
session['message'] = "DNS and Enpoint Allowed IP update successfully!"
session['message_status'] = "success"
config.clear()
return redirect(url_for("settings"))
except Exception:
session['message'] = "DNS and Enpoint Allowed IP update failed."
session['message_status'] = "danger"
config.clear()
return redirect(url_for("settings"))
@app.route('/update_pwd', methods=['POST']) @app.route('/update_pwd', methods=['POST'])
def update_pwd(): def update_pwd():
@ -478,6 +567,22 @@ def update_wg_conf_path():
config.clear() config.clear()
os.system('bash wgd.sh restart') os.system('bash wgd.sh restart')
@app.route('/update_dashboard_sort', methods=['POST'])
def update_dashbaord_sort():
config = configparser.ConfigParser(strict=False)
config.read(dashboard_conf)
data = request.get_json()
sort_tag = ['name', 'status', 'allowed_ip']
if data['sort'] in sort_tag:
config.set("Server", "dashboard_sort", data['sort'])
else:
config.set("Server", "dashboard_sort", 'status')
config.write(open(dashboard_conf, "w"))
config.clear()
return "true"
@app.route('/update_dashboard_refresh_interval', methods=['POST']) @app.route('/update_dashboard_refresh_interval', methods=['POST'])
def update_dashboard_refresh_interval(): def update_dashboard_refresh_interval():
config = configparser.ConfigParser(strict=False) config = configparser.ConfigParser(strict=False)
@ -487,28 +592,30 @@ def update_dashboard_refresh_interval():
config.clear() config.clear()
return "true" return "true"
@app.route('/get_ping_ip', methods=['POST']) @app.route('/get_ping_ip', methods=['POST'])
def get_ping_ip(): def get_ping_ip():
config = request.form['config'] config = request.form['config']
db = TinyDB('db/' + config + '.json') db = TinyDB('db/' + config + '.json')
html = "" html = ""
for i in db.all(): for i in db.all():
html += '<optgroup label="'+i['name']+' - '+i['id']+'">' html += '<optgroup label="' + i['name'] + ' - ' + i['id'] + '">'
allowed_ip = str(i['allowed_ip']).split(",") allowed_ip = str(i['allowed_ip']).split(",")
for k in allowed_ip: for k in allowed_ip:
k = k.split("/") k = k.split("/")
if len(k) == 2: if len(k) == 2:
html += "<option value="+k[0]+">"+k[0]+"</option>" html += "<option value=" + k[0] + ">" + k[0] + "</option>"
endpoint = str(i['endpoint']).split(":") endpoint = str(i['endpoint']).split(":")
if len(endpoint) == 2: if len(endpoint) == 2:
html += "<option value=" + endpoint[0] + ">" + endpoint[0] + "</option>" html += "<option value=" + endpoint[0] + ">" + endpoint[0] + "</option>"
html += "</optgroup>" html += "</optgroup>"
return html return html
@app.route('/ping_ip', methods=['POST']) @app.route('/ping_ip', methods=['POST'])
def ping_ip(): def ping_ip():
try: try:
result = ping(''+request.form['ip']+'', count=int(request.form['count']),privileged=True, source=None) result = ping('' + request.form['ip'] + '', count=int(request.form['count']), privileged=True, source=None)
returnjson = { returnjson = {
"address": result.address, "address": result.address,
"is_alive": result.is_alive, "is_alive": result.is_alive,
@ -523,21 +630,24 @@ def ping_ip():
except Exception: except Exception:
return "Error" return "Error"
@app.route('/traceroute_ip', methods=['POST']) @app.route('/traceroute_ip', methods=['POST'])
def traceroute_ip(): def traceroute_ip():
try: try:
result = traceroute(''+request.form['ip']+'', first_hop=1, max_hops=30, count=1, fast=True) result = traceroute('' + request.form['ip'] + '', first_hop=1, max_hops=30, count=1, fast=True)
returnjson = [] returnjson = []
last_distance = 0 last_distance = 0
for hop in result: for hop in result:
if last_distance + 1 != hop.distance: if last_distance + 1 != hop.distance:
returnjson.append({"hop":"*", "ip":"*", "avg_rtt":"", "min_rtt":"", "max_rtt":""}) returnjson.append({"hop": "*", "ip": "*", "avg_rtt": "", "min_rtt": "", "max_rtt": ""})
returnjson.append({"hop": hop.distance, "ip": hop.address, "avg_rtt": hop.avg_rtt, "min_rtt": hop.min_rtt, "max_rtt": hop.max_rtt}) returnjson.append({"hop": hop.distance, "ip": hop.address, "avg_rtt": hop.avg_rtt, "min_rtt": hop.min_rtt,
"max_rtt": hop.max_rtt})
last_distance = hop.distance last_distance = hop.distance
return jsonify(returnjson) return jsonify(returnjson)
except Exception: except Exception:
return "Error" return "Error"
@app.route('/', methods=['GET']) @app.route('/', methods=['GET'])
def index(): def index():
return render_template('index.html', conf=get_conf_list()) return render_template('index.html', conf=get_conf_list())
@ -545,6 +655,8 @@ def index():
@app.route('/configuration/<config_name>', methods=['GET']) @app.route('/configuration/<config_name>', methods=['GET'])
def conf(config_name): def conf(config_name):
config = configparser.ConfigParser(strict=False)
config.read(dashboard_conf)
conf_data = { conf_data = {
"name": config_name, "name": config_name,
"status": get_conf_status(config_name), "status": get_conf_status(config_name),
@ -559,27 +671,34 @@ def conf(config_name):
config_list = get_conf_list() config_list = get_conf_list()
if config_name not in [conf['conf'] for conf in config_list]: if config_name not in [conf['conf'] for conf in config_list]:
return render_template('index.html', conf=get_conf_list()) return render_template('index.html', conf=get_conf_list())
return render_template('configuration.html', conf=get_conf_list(), conf_data=conf_data, dashboard_refresh_interval=int(config.get("Server","dashboard_refresh_interval"))) return render_template('configuration.html', conf=get_conf_list(), conf_data=conf_data,
dashboard_refresh_interval=int(config.get("Server", "dashboard_refresh_interval")),
DNS=config.get("Peers", "peer_global_DNS"),
endpoint_allowed_ip=config.get("Peers", "peer_endpoint_allowed_ip"), title=config_name)
@app.route('/get_config/<config_name>', methods=['GET']) @app.route('/get_config/<config_name>', methods=['GET'])
def get_conf(config_name): def get_conf(config_name):
search = request.args.get('search')
if len(search) == 0: search = ""
search = urllib.parse.unquote(search)
config = configparser.ConfigParser(strict=False)
config.read(dashboard_conf)
sort = config.get("Server", "dashboard_sort")
conf_data = { conf_data = {
"peer_data": get_peers(config_name), "peer_data": get_peers(config_name, search, sort),
"name": config_name, "name": config_name,
"status": get_conf_status(config_name), "status": get_conf_status(config_name),
"total_data_usage": get_conf_total_data(config_name), "total_data_usage": get_conf_total_data(config_name),
"public_key": get_conf_pub_key(config_name), "public_key": get_conf_pub_key(config_name),
"listen_port": get_conf_listen_port(config_name), "listen_port": get_conf_listen_port(config_name),
"running_peer": get_conf_running_peer_number(config_name), "running_peer": get_conf_running_peer_number(config_name),
} }
if conf_data['status'] == "stopped": if conf_data['status'] == "stopped":
# return redirect('/')
conf_data['checked'] = "nope" conf_data['checked'] = "nope"
else: else:
conf_data['checked'] = "checked" conf_data['checked'] = "checked"
return render_template('get_conf.html', conf=get_conf_list(), conf_data=conf_data, wg_ip=wg_ip) return render_template('get_conf.html', conf_data=conf_data, wg_ip=wg_ip, sort_tag=sort, dashboard_refresh_interval=int(config.get("Server", "dashboard_refresh_interval")))
@app.route('/switch/<config_name>', methods=['GET']) @app.route('/switch/<config_name>', methods=['GET'])
@ -609,21 +728,30 @@ def add_peer(config_name):
data = request.get_json() data = request.get_json()
public_key = data['public_key'] public_key = data['public_key']
allowed_ips = data['allowed_ips'] allowed_ips = data['allowed_ips']
endpoint_allowed_ip = data['endpoint_allowed_ip']
DNS = data['DNS']
keys = get_conf_peer_key(config_name) keys = get_conf_peer_key(config_name)
if type(keys) != list: if type(keys) != list:
return config_name+" is not running." return config_name + " is not running."
if public_key in keys: if public_key in keys:
return "Public key already exist." return "Public key already exist."
if len(db.search(peers.allowed_ip.matches(allowed_ips))) != 0: if len(db.search(peers.allowed_ip.matches(allowed_ips))) != 0:
return "Allowed IP already taken by another peer." return "Allowed IP already taken by another peer."
if not checkIp(DNS):
return "DNS formate is incorrect. Example: 1.1.1.1"
if not checkAllowedIPs(endpoint_allowed_ip):
return "Endpoint Allowed IPs format is incorrect."
else: else:
status = "" status = ""
try: try:
status = subprocess.check_output( status = subprocess.check_output(
"wg set " + config_name + " peer " + public_key + " allowed-ips " + allowed_ips, shell=True, stderr=subprocess.STDOUT) "wg set " + config_name + " peer " + public_key + " allowed-ips " + allowed_ips, shell=True,
stderr=subprocess.STDOUT)
status = subprocess.check_output("wg-quick save " + config_name, shell=True, stderr=subprocess.STDOUT) status = subprocess.check_output("wg-quick save " + config_name, shell=True, stderr=subprocess.STDOUT)
get_conf_peers_data(config_name) get_all_peers_data(config_name)
db.update({"name": data['name'], "private_key": data['private_key'], "DNS": data['DNS']}, peers.id == public_key) db.update({"name": data['name'], "private_key": data['private_key'], "DNS": data['DNS'], "endpoint_allowed_ip": endpoint_allowed_ip},
peers.id == public_key)
db.close() db.close()
return "true" return "true"
except subprocess.CalledProcessError as exc: except subprocess.CalledProcessError as exc:
@ -641,7 +769,7 @@ def remove_peer(config_name):
delete_key = data['peer_id'] delete_key = data['peer_id']
keys = get_conf_peer_key(config_name) keys = get_conf_peer_key(config_name)
if type(keys) != list: if type(keys) != list:
return config_name+" is not running." return config_name + " is not running."
if delete_key not in keys: if delete_key not in keys:
db.close() db.close()
return "This key does not exist" return "This key does not exist"
@ -665,6 +793,7 @@ def save_peer_setting(config_name):
private_key = data['private_key'] private_key = data['private_key']
DNS = data['DNS'] DNS = data['DNS']
allowed_ip = data['allowed_ip'] allowed_ip = data['allowed_ip']
endpoint_allowed_ip = data['endpoint_allowed_ip']
db = TinyDB("db/" + config_name + ".json") db = TinyDB("db/" + config_name + ".json")
peers = Query() peers = Query()
if len(db.search(peers.id == id)) == 1: if len(db.search(peers.id == id)) == 1:
@ -679,22 +808,25 @@ def save_peer_setting(config_name):
try: try:
if allowed_ip == "": if allowed_ip == "":
allowed_ip = '""' allowed_ip = '""'
change_ip = subprocess.check_output('wg set '+config_name+" peer "+id+" allowed-ips "+allowed_ip, shell=True, stderr=subprocess.STDOUT) change_ip = subprocess.check_output('wg set ' + config_name + " peer " + id + " allowed-ips " + allowed_ip,
save_change_ip = subprocess.check_output('wg-quick save '+ config_name, shell=True,stderr=subprocess.STDOUT) shell=True, stderr=subprocess.STDOUT)
save_change_ip = subprocess.check_output('wg-quick save ' + config_name, shell=True,
stderr=subprocess.STDOUT)
if change_ip.decode("UTF-8") != "": if change_ip.decode("UTF-8") != "":
return jsonify({"status":"failed", "msg": change_ip.decode("UTF-8")}) return jsonify({"status": "failed", "msg": change_ip.decode("UTF-8")})
db.update({"name": name, "private_key": private_key, "DNS": DNS}, peers.id == id)
db.update({"name": name, "private_key": private_key, "DNS": DNS, "endpoint_allowed_ip":endpoint_allowed_ip}, peers.id == id)
db.close() db.close()
return jsonify({"status": "success", "msg": ""}) return jsonify({"status": "success", "msg": ""})
except subprocess.CalledProcessError as exc: except subprocess.CalledProcessError as exc:
return jsonify({"status":"failed", "msg": str(exc.output.decode("UTF-8").strip())}) return jsonify({"status": "failed", "msg": str(exc.output.decode("UTF-8").strip())})
else: else:
return jsonify({"status":"failed","msg":"This peer does not exist."}) return jsonify({"status": "failed", "msg": "This peer does not exist."})
@app.route('/get_peer_data/<config_name>', methods=['POST']) @app.route('/get_peer_data/<config_name>', methods=['POST'])
@ -705,28 +837,35 @@ def get_peer_name(config_name):
peers = Query() peers = Query()
result = db.search(peers.id == id) result = db.search(peers.id == id)
db.close() db.close()
data = {"name": result[0]['name'], "allowed_ip":result[0]['allowed_ip'], "DNS": result[0]['DNS'], "private_key": result[0]['private_key']} data = {"name": result[0]['name'], "allowed_ip": result[0]['allowed_ip'], "DNS": result[0]['DNS'],
"private_key": result[0]['private_key'], "endpoint_allowed_ip": result[0]['endpoint_allowed_ip']}
return jsonify(data) return jsonify(data)
@app.route('/generate_peer', methods=['GET']) @app.route('/generate_peer', methods=['GET'])
def generate_peer(): def generate_peer():
return jsonify(genKeys()) return jsonify(genKeys())
@app.route('/generate_public_key', methods=['POST']) @app.route('/generate_public_key', methods=['POST'])
def generate_public_key(): def generate_public_key():
data = request.get_json() data = request.get_json()
private_key = data['private_key'] private_key = data['private_key']
return jsonify(genPubKey(private_key)) return jsonify(genPubKey(private_key))
@app.route('/check_key_match/<config_name>', methods=['POST']) @app.route('/check_key_match/<config_name>', methods=['POST'])
def check_key_match(config_name): def check_key_match(config_name):
data = request.get_json() data = request.get_json()
private_key = data['private_key'] private_key = data['private_key']
public_key = data['public_key'] public_key = data['public_key']
return jsonify(checkKeyMatch(private_key,public_key, config_name)) return jsonify(checkKeyMatch(private_key, public_key, config_name))
@app.route('/download/<config_name>', methods=['GET']) @app.route('/download/<config_name>', methods=['GET'])
def download(config_name): def download(config_name):
print(request.headers.get('User-Agent'))
id = request.args.get('id') id = request.args.get('id')
db = TinyDB("db/" + config_name + ".json") db = TinyDB("db/" + config_name + ".json")
peers = Query() peers = Query()
@ -738,23 +877,38 @@ def download(config_name):
if peer['private_key'] != "": if peer['private_key'] != "":
public_key = get_conf_pub_key(config_name) public_key = get_conf_pub_key(config_name)
listen_port = get_conf_listen_port(config_name) listen_port = get_conf_listen_port(config_name)
endpoint = wg_ip+":"+listen_port endpoint = wg_ip + ":" + listen_port
private_key = peer['private_key'] private_key = peer['private_key']
allowed_ip = peer['allowed_ip'] allowed_ip = peer['allowed_ip']
DNS = peer['DNS'] DNS = peer['DNS']
name = "".join(peer['name'].split(' '))
if name == "": name = public_key
def generate(private_key, allowed_ip, DNS, public_key, endpoint):
yield "[Interface]\nPrivateKey = "+private_key+"\nAddress = "+allowed_ip+"\nDNS = "+DNS+"\n\n[Peer]\nPublicKey = "+public_key+"\nAllowedIPs = 0.0.0.0/0\nEndpoint = "+endpoint
return app.response_class(generate(private_key,allowed_ip,DNS, public_key,endpoint), mimetype='text/conf', headers={"Content-Disposition":"attachment;filename="+name+".conf"}) filename = peer['name']
if len(filename) == 0:
filename = "Untitled_Peers"
else:
filename = peer['name']
# Clean filename
illegal_filename = [".", ",", "/", "?", "<", ">", "\\", ":", "*", '|' '\"', "com1", "com2", "com3",
"com4", "com5", "com6", "com7", "com8", "com9", "lpt1", "lpt2", "lpt3", "lpt4",
"lpt5", "lpt6", "lpt7", "lpt8", "lpt9", "con", "nul", "prn"]
for i in illegal_filename:
filename = filename.replace(i, "")
print(filename)
if len(filename) == 0:
filename = "Untitled_Peer"
filename = "".join(filename.split(' '))
filename = filename + "_" + config_name
def generate(private_key, allowed_ip, DNS, public_key, endpoint):
yield "[Interface]\nPrivateKey = " + private_key + "\nAddress = " + allowed_ip + "\nDNS = " + DNS + "\n\n[Peer]\nPublicKey = " + public_key + "\nAllowedIPs = 0.0.0.0/0\nEndpoint = " + endpoint
return app.response_class(generate(private_key, allowed_ip, DNS, public_key, endpoint),
mimetype='text/conf',
headers={"Content-Disposition": "attachment;filename=" + filename + ".conf"})
else: else:
return redirect("/configuration/" + config_name) return redirect("/configuration/" + config_name)
def init_dashboard(): def init_dashboard():
# Set Default INI File # Set Default INI File
if not os.path.isfile("wg-dashboard.ini"): if not os.path.isfile("wg-dashboard.ini"):
@ -783,6 +937,15 @@ def init_dashboard():
config['Server']['version'] = dashboard_version config['Server']['version'] = dashboard_version
if 'dashboard_refresh_interval' not in config['Server']: if 'dashboard_refresh_interval' not in config['Server']:
config['Server']['dashboard_refresh_interval'] = '15000' config['Server']['dashboard_refresh_interval'] = '15000'
if 'dashboard_sort' not in config['Server']:
config['Server']['dashboard_sort'] = 'status'
if "Peers" not in config:
config['Peers'] = {}
if 'peer_global_DNS' not in config['Peers']:
config['Peers']['peer_global_DNS'] = '1.1.1.1'
if 'peer_endpoint_allowed_ip' not in config['Peers']:
config['Peers']['peer_endpoint_allowed_ip'] = '0.0.0.0/0'
config.write(open(dashboard_conf, "w")) config.write(open(dashboard_conf, "w"))
config.clear() config.clear()

View File

@ -1,4 +1,4 @@
Flask==1.1.2 Flask==2.0.1
tinydb==4.3.0 tinydb==4.3.0
ifcfg==0.21 ifcfg==0.21
icmplib==2.1.1 icmplib==2.1.1

Binary file not shown.

Before

Width:  |  Height:  |  Size: 145 KiB

7
src/static/css/bootstrap.min.css vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,262 @@
body {
font-size: .875rem;
}
.feather {
width: 16px;
height: 16px;
vertical-align: text-bottom;
}
/*
* Sidebar
*/
.sidebar {
position: fixed;
top: 0;
bottom: 0;
left: 0;
z-index: 100; /* Behind the navbar */
padding: 48px 0 0; /* Height of navbar */
box-shadow: inset -1px 0 0 rgba(0, 0, 0, .1);
}
/*@media (max-width: 767.98px) {*/
/* .sidebar {*/
/* top: 5rem;*/
/* }*/
/*}*/
.sidebar-sticky {
position: relative;
top: 0;
height: calc(100vh - 48px);
padding-top: .5rem;
overflow-x: hidden;
overflow-y: auto; /* Scrollable contents if viewport is shorter than content. */
}
@supports ((position: -webkit-sticky) or (position: sticky)) {
.sidebar-sticky {
position: -webkit-sticky;
position: sticky;
}
}
.sidebar .nav-link {
font-weight: 500;
color: #333;
transition: 0.2s cubic-bezier(0.82, -0.07, 0, 1.01);
}
.nav-link:hover {
padding-left: 30px;
}
.sidebar .nav-link .feather {
margin-right: 4px;
color: #999;
}
.sidebar .nav-link.active {
color: #007bff;
}
.sidebar .nav-link:hover .feather,
.sidebar .nav-link.active .feather {
color: inherit;
}
.sidebar-heading {
font-size: .75rem;
text-transform: uppercase;
}
/*
* Navbar
*/
.navbar-brand {
padding-top: .75rem;
padding-bottom: .75rem;
font-size: 1rem;
background-color: rgba(0, 0, 0, .25);
box-shadow: inset -1px 0 0 rgba(0, 0, 0, .25);
}
.navbar .navbar-toggler {
top: .25rem;
right: 1rem;
}
.navbar .form-control {
padding: .75rem 1rem;
border-width: 0;
border-radius: 0;
}
.form-control-dark {
color: #fff;
background-color: rgba(255, 255, 255, .1);
border-color: rgba(255, 255, 255, .1);
}
.form-control-dark:focus {
border-color: transparent;
box-shadow: 0 0 0 3px rgba(255, 255, 255, .25);
}
.dot{
width: 10px;
height: 10px;
border-radius: 50px;
display: inline-block;
margin-left: 10px;
}
.dot-running{
background-color: #28a745!important;
}
.dot-stopped{
background-color: #6c757d!important;
}
.info h6{
line-break: anywhere;
}
.btn-control{
border: none !important;
padding: 0 1rem 0 0;
}
.share_peer_btn_group .btn-control{
padding: 0 0 0 1rem;
}
.btn-control:hover{
background: white;
}
.btn-delete-peer:hover{
color: #dc3545;
}
.btn-setting-peer:hover{
color:#007bff
}
.btn-download-peer:hover{
color: #17a2b8;
}
.login-container{
padding: 2rem;
}
@media (max-width: 992px){
.card-col{
margin-bottom: 1rem;
}
}
.switch{
font-size: 2rem;
}
.switch:hover{
text-decoration: none
}
.btn-group-label:hover{
color: #007bff;
border-color: #007bff;
background: white;
}
/*.peer_data_group{*/
/* text-align: right;*/
/*}*/
@media (max-width: 768px) {
.peer_data_group{
text-align: left;
}
}
.index-switch{
text-align: right;
}
main{
margin-bottom: 3rem;
}
/*.add_btn{*/
/* position: fixed;*/
/* bottom: 1.75rem;*/
/* right: 1.75rem;*/
/* z-index: 1000;*/
/* padding: 0.75rem 1.5rem;*/
/* border-radius: 3rem;*/
/* font-size: 1rem;*/
/*}*/
@-webkit-keyframes rotating /* Safari and Chrome */ {
from {
-webkit-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
-o-transform: rotate(360deg);
transform: rotate(360deg);
}
}
@keyframes rotating {
from {
-ms-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-webkit-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-ms-transform: rotate(360deg);
-moz-transform: rotate(360deg);
-webkit-transform: rotate(360deg);
-o-transform: rotate(360deg);
transform: rotate(360deg);
}
}
.rotating::before {
-webkit-animation: rotating 0.75s linear infinite;
-moz-animation: rotating 0.75s linear infinite;
-ms-animation: rotating 0.75s linear infinite;
-o-animation: rotating 0.75s linear infinite;
animation: rotating 0.75s linear infinite;
}
.peer_private_key_textbox_switch{
position: absolute;
right: 2rem;
transform: translateY(-28px);
font-size: 1.2rem;
cursor: pointer;
}
.progress-bar{
transition: 0.3s ease-in-out;
}
.key{
transition: 0.2s ease-in-out;
cursor: pointer;
}
.key:hover{
color: #007bff;
}

View File

@ -1,249 +0,0 @@
body {
font-size: .875rem;
}
.feather {
width: 16px;
height: 16px;
vertical-align: text-bottom;
}
/*
* Sidebar
*/
.sidebar {
position: fixed;
top: 0;
bottom: 0;
left: 0;
z-index: 100; /* Behind the navbar */
padding: 48px 0 0; /* Height of navbar */
box-shadow: inset -1px 0 0 rgba(0, 0, 0, .1);
}
/*@media (max-width: 767.98px) {*/
/* .sidebar {*/
/* top: 5rem;*/
/* }*/
/*}*/
.sidebar-sticky {
position: relative;
top: 0;
height: calc(100vh - 48px);
padding-top: .5rem;
overflow-x: hidden;
overflow-y: auto; /* Scrollable contents if viewport is shorter than content. */
}
@supports ((position: -webkit-sticky) or (position: sticky)) {
.sidebar-sticky {
position: -webkit-sticky;
position: sticky;
}
}
.sidebar .nav-link {
font-weight: 500;
color: #333;
transition: 0.2s cubic-bezier(0.82, -0.07, 0, 1.01);
}
.nav-link:hover {
padding-left: 30px;
}
.sidebar .nav-link .feather {
margin-right: 4px;
color: #999;
}
.sidebar .nav-link.active {
color: #007bff;
}
.sidebar .nav-link:hover .feather,
.sidebar .nav-link.active .feather {
color: inherit;
}
.sidebar-heading {
font-size: .75rem;
text-transform: uppercase;
}
/*
* Navbar
*/
.navbar-brand {
padding-top: .75rem;
padding-bottom: .75rem;
font-size: 1rem;
background-color: rgba(0, 0, 0, .25);
box-shadow: inset -1px 0 0 rgba(0, 0, 0, .25);
}
.navbar .navbar-toggler {
top: .25rem;
right: 1rem;
}
.navbar .form-control {
padding: .75rem 1rem;
border-width: 0;
border-radius: 0;
}
.form-control-dark {
color: #fff;
background-color: rgba(255, 255, 255, .1);
border-color: rgba(255, 255, 255, .1);
}
.form-control-dark:focus {
border-color: transparent;
box-shadow: 0 0 0 3px rgba(255, 255, 255, .25);
}
.dot{
width: 10px;
height: 10px;
border-radius: 50px;
display: inline-block;
margin-left: 10px;
}
.dot-running{
background-color: #28a745!important;
}
.dot-stopped{
background-color: #6c757d!important;
}
.info h6{
line-break: anywhere;
}
.btn-control{
border: none !important;
padding: 0 1rem 0 0;
}
.share_peer_btn_group .btn-control{
padding: 0 0 0 1rem;
}
.btn-control:hover{
background: white;
}
.btn-delete-peer:hover{
color: #dc3545;
}
.btn-setting-peer:hover{
color:#007bff
}
.btn-download-peer:hover{
color: #17a2b8;
}
.login-container{
padding: 2rem;
}
@media (max-width: 992px){
.card-col{
margin-bottom: 1rem;
}
}
.switch{
font-size: 2rem;
}
.switch:hover{
text-decoration: none
}
.btn-group-label:hover{
color: #007bff;
border-color: #007bff;
background: white;
}
.peer_data_group{
text-align: right;
}
@media (max-width: 768px) {
.peer_data_group{
text-align: left;
}
}
.index-switch{
text-align: right;
}
main{
margin-bottom: 3rem;
}
/*.add_btn{*/
/* position: fixed;*/
/* bottom: 1.75rem;*/
/* right: 1.75rem;*/
/* z-index: 1000;*/
/* padding: 0.75rem 1.5rem;*/
/* border-radius: 3rem;*/
/* font-size: 1rem;*/
/*}*/
@-webkit-keyframes rotating /* Safari and Chrome */ {
from {
-webkit-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
-o-transform: rotate(360deg);
transform: rotate(360deg);
}
}
@keyframes rotating {
from {
-ms-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-webkit-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-ms-transform: rotate(360deg);
-moz-transform: rotate(360deg);
-webkit-transform: rotate(360deg);
-o-transform: rotate(360deg);
transform: rotate(360deg);
}
}
.rotating::before {
-webkit-animation: rotating 0.75s linear infinite;
-moz-animation: rotating 0.75s linear infinite;
-ms-animation: rotating 0.75s linear infinite;
-o-animation: rotating 0.75s linear infinite;
animation: rotating 0.75s linear infinite;
}
.peer_private_key_textbox_switch{
position: absolute;
right: 2rem;
transform: translateY(-28px);
font-size: 1.2rem;
cursor: pointer;
}

View File

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 92 KiB

7045
src/static/js/bootstrap.bundle.js vendored Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

7
src/static/js/bootstrap.bundle.min.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -71,7 +71,8 @@ $("#save_peer").click(function(){
"public_key":$("#public_key").val(), "public_key":$("#public_key").val(),
"allowed_ips": $("#allowed_ips").val(), "allowed_ips": $("#allowed_ips").val(),
"name":$("#new_add_name").val(), "name":$("#new_add_name").val(),
"DNS": $("#DNS").val() "DNS": $("#new_add_DNS").val(),
"endpoint_allowed_ip": $("#new_add_endpoint_allowed_ip").val()
}), }),
success: function (response){ success: function (response){
if(response != "true"){ if(response != "true"){
@ -123,7 +124,7 @@ $("#delete_peer").click(function(){
} }
else{ else{
deleteModal.toggle(); deleteModal.toggle();
load_data(); load_data($('#search_peer_textbox').val());
$('#alertToast').toast('show'); $('#alertToast').toast('show');
$('#alertToast .toast-body').html("Peer deleted!"); $('#alertToast .toast-body').html("Peer deleted!");
} }
@ -136,7 +137,7 @@ var settingModal = new bootstrap.Modal(document.getElementById('setting_modal'),
keyboard: false keyboard: false
}) })
$("body").on("click", ".btn-setting-peer", function(){ $("body").on("click", ".btn-setting-peer", function(){
settingModal.toggle(); startProgressBar()
var peer_id = $(this).attr("id"); var peer_id = $(this).attr("id");
$("#save_peer_setting").attr("peer_id", peer_id); $("#save_peer_setting").attr("peer_id", peer_id);
$.ajax({ $.ajax({
@ -153,6 +154,9 @@ $("body").on("click", ".btn-setting-peer", function(){
$("#setting_modal #peer_private_key_textbox").val(response['private_key']) $("#setting_modal #peer_private_key_textbox").val(response['private_key'])
$("#setting_modal #peer_DNS_textbox").val(response['DNS']) $("#setting_modal #peer_DNS_textbox").val(response['DNS'])
$("#setting_modal #peer_allowed_ip_textbox").val(response['allowed_ip']) $("#setting_modal #peer_allowed_ip_textbox").val(response['allowed_ip'])
$("#setting_modal #peer_endpoint_allowed_ips").val(response['endpoint_allowed_ip'])
settingModal.toggle();
endProgressBar()
} }
}) })
}); });
@ -199,7 +203,8 @@ $("#save_peer_setting").click(function (){
name: $("#peer_name_textbox").val(), name: $("#peer_name_textbox").val(),
DNS: $("#peer_DNS_textbox").val(), DNS: $("#peer_DNS_textbox").val(),
private_key: $("#peer_private_key_textbox").val(), private_key: $("#peer_private_key_textbox").val(),
allowed_ip: $("#peer_allowed_ip_textbox").val() allowed_ip: $("#peer_allowed_ip_textbox").val(),
endpoint_allowed_ip: $("#peer_endpoint_allowed_ips").val()
}), }),
success: function (response){ success: function (response){
if (response['status'] === "failed"){ if (response['status'] === "failed"){
@ -207,7 +212,7 @@ $("#save_peer_setting").click(function (){
$("#setting_peer_alert").removeClass("d-none"); $("#setting_peer_alert").removeClass("d-none");
}else{ }else{
settingModal.toggle(); settingModal.toggle();
load_data(); load_data($('#search_peer_textbox').val())
$('#alertToast').toast('show'); $('#alertToast').toast('show');
$('#alertToast .toast-body').html("Peer Saved!"); $('#alertToast .toast-body').html("Peer Saved!");
} }
@ -225,4 +230,65 @@ $(".peer_private_key_textbox_switch").click(function (){
let icon = (($("#peer_private_key_textbox").attr('type') === 'password') ? "bi bi-eye-slash-fill":"bi bi-eye-fill") let icon = (($("#peer_private_key_textbox").attr('type') === 'password') ? "bi bi-eye-slash-fill":"bi bi-eye-fill")
$("#peer_private_key_textbox").attr('type',mode) $("#peer_private_key_textbox").attr('type',mode)
$(".peer_private_key_textbox_switch i").removeClass().addClass(icon) $(".peer_private_key_textbox_switch i").removeClass().addClass(icon)
}) })
// Search Peer
var typingTimer;
var doneTypingInterval = 200;
var $input = $('#search_peer_textbox');
$input.on('keyup', function () {
clearTimeout(typingTimer);
typingTimer = setTimeout(doneTyping, doneTypingInterval);
});
$input.on('keydown', function () {
clearTimeout(typingTimer);
});
function doneTyping () {
load_data($('#search_peer_textbox').val());
}
// Sorting
$("body").on("change", "#sort_by_dropdown", function (){
$.ajax({
method:"POST",
data: JSON.stringify({'sort':$("#sort_by_dropdown option:selected").val()}),
headers:{"Content-Type": "application/json"},
url: "/update_dashboard_sort",
success: function (res){
location.reload()
}
})
})
$("body").on("mouseenter", ".key", function(){
var label = $(this).parent().siblings().children()[1]
label.style.opacity = "100"
})
$("body").on("mouseout", ".key", function(){
var label = $(this).parent().siblings().children()[1]
label.style.opacity = "0"
setTimeout(function (){
label.innerHTML = "CLICK TO COPY"
},200)
});
$("body").on("click", ".key", function(){
var label = $(this).parent().siblings().children()[1]
copyToClipboard($(this))
label.innerHTML = "COPIED!"
})
function copyToClipboard(element) {
var $temp = $("<input>");
$("body").append($temp);
$temp.val($(element).text()).select();
document.execCommand("copy");
$temp.remove();
}
// $(".key").mouseenter(function(){
//
// })

2
src/static/js/jquery.min.js vendored Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 95 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

View File

@ -1,10 +1,21 @@
<html> <html>
{% include "header.html" %} {% with title=title%}
{% include "header.html"%}
{% endwith %}
<body> <body>
{% include "navbar.html" %} {% include "navbar.html" %}
<div class="container-fluid"> <div class="container-fluid">
{% include "sidebar.html" %} {% include "sidebar.html" %}
<div id="config_body"></div> <div class="col-md-9 ml-sm-auto col-lg-10 px-md-4 mt-4 mb-4">
<div class="form-group">
<input type="text" class="form-control" id="search_peer_textbox" placeholder="Search Peer..." value="" style="display: none">
</div>
</div>
<div id="config_body">
</div>
</div> </div>
<div class="modal fade" id="add_modal" data-backdrop="static" data-keyboard="false" tabindex="-1" <div class="modal fade" id="add_modal" data-backdrop="static" data-keyboard="false" tabindex="-1"
aria-labelledby="staticBackdropLabel" aria-hidden="true"> aria-labelledby="staticBackdropLabel" aria-hidden="true">
@ -44,22 +55,29 @@
<input type="text" class="form-control" id="public_key" aria-describedby="public_key" disabled> <input type="text" class="form-control" id="public_key" aria-describedby="public_key" disabled>
</div> </div>
<div class="row"> <div class="row">
<div class="col-sm"> <div class="col-sm-6">
<div class="form-group">
<label for="new_add_name">Name</label>
<input type="text" class="form-control" id="new_add_name">
</div>
</div>
<div class="col-sm-6">
<div class="form-group"> <div class="form-group">
<label for="allowed_ips">Allowed IPs <code>(Required)</code></label> <label for="allowed_ips">Allowed IPs <code>(Required)</code></label>
<input type="text" class="form-control" id="allowed_ips"> <input type="text" class="form-control" id="allowed_ips">
</div> </div>
</div> </div>
<div class="col-sm"> <div class="col-sm-6">
<div class="form-group"> <div class="form-group">
<label for="DNS">DNS</label> <label for="new_add_DNS">DNS</label>
<input type="text" class="form-control" id="DNS" value="1.1.1.1"> <input type="text" class="form-control" id="new_add_DNS" value="{{ DNS }}">
</div> </div>
</div> </div>
<div class="col-sm">
<div class="col-sm-6">
<div class="form-group"> <div class="form-group">
<label for="new_add_name">Name</label> <label for="new_add_endpoint_allowed_ip">Endpoint Allowed IPs</label>
<input type="text" class="form-control" id="new_add_name"> <input type="text" class="form-control" id="new_add_endpoint_allowed_ip" value="{{ endpoint_allowed_ip }}">
</div> </div>
</div> </div>
</div> </div>
@ -114,6 +132,10 @@
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>
</div> </div>
<div class="mb-3">
<label for="peer_name_textbox" class="form-label">Name</label>
<input type="text" class="form-control" id="peer_name_textbox" placeholder="">
</div>
<div class="mb-3"> <div class="mb-3">
<label for="peer_private_key_textbox" class="form-label">Private Key <code>(Required for QR Code and download)</code></label> <label for="peer_private_key_textbox" class="form-label">Private Key <code>(Required for QR Code and download)</code></label>
<input type="password" class="form-control" id="peer_private_key_textbox" style="padding-right: 40px"> <input type="password" class="form-control" id="peer_private_key_textbox" style="padding-right: 40px">
@ -128,10 +150,11 @@
<label for="peer_DNS_textbox" class="form-label">DNS <code>(Required)</code></label> <label for="peer_DNS_textbox" class="form-label">DNS <code>(Required)</code></label>
<input type="text" class="form-control" id="peer_DNS_textbox"> <input type="text" class="form-control" id="peer_DNS_textbox">
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="peer_name_textbox" class="form-label">Name</label> <label for="peer_endpoint_allowed_ips" class="form-label">Endpoint Allowed IPs <code>(Required)</code></label>
<input type="text" class="form-control" id="peer_name_textbox" placeholder=""> <input type="text" class="form-control" id="peer_endpoint_allowed_ips">
</div> </div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button> <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
@ -174,25 +197,59 @@
</body> </body>
{% include "footer.html" %} {% include "footer.html" %}
<script> <script>
$(".sb-{{conf_data['name']}}-url").addClass("active"); var conf_name = "{{ conf_data['name'] }}"
function load_data(){ $(".sb-"+conf_name+"-url").addClass("active");
// Progress Bar
let bar = $(".progress-bar")
function startProgressBar(){
bar.css("width","0%")
bar.css("opacity", "100")
bar.css("background", "rgb(255,69,69)")
bar.css("background", "linear-gradient(145deg, rgba(255,69,69,1) 0%, rgba(0,115,186,1) 100%)")
bar.css("width","25%")
setTimeout(function(){
stillLoadingProgressBar();
},300)
}
function stillLoadingProgressBar(){
bar.css("transition", "3s ease-in-out")
bar.css("width", "75%")
}
function endProgressBar(){
bar.css("transition", "0.3s ease-in-out")
bar.css("width","100%")
setTimeout(function(){
bar.css("opacity", "0")
},250)
}
function load_data(search){
startProgressBar()
$.ajax({ $.ajax({
method: "GET", method: "GET",
url: "/get_config/"+"{{conf_data['name']}}", url: "/get_config/"+conf_name+"?search="+encodeURIComponent(search),
headers:{ headers:{
"Content-Type": "application/json" "Content-Type": "application/json"
}, },
async:false,
success: function (response){ success: function (response){
$("#config_body").html(response); $("#config_body").html(response);
$("[refresh-interval={{ dashboard_refresh_interval }}]").addClass("active") {#$("[refresh-interval={{ dashboard_refresh_interval }}]").addClass("active")#}
$("#search_peer_textbox").css("display", "block")
if (bar.css("width") !== "0%"){
endProgressBar()
}
} }
}) })
} }
$(document).ready(function(){ $(document).ready(function(){
load_data(); load_data($('#search_peer_textbox').val());
setInterval(function(){ setInterval(function(){
load_data(); load_data($('#search_peer_textbox').val());
}, {{dashboard_refresh_interval}}) }, {{dashboard_refresh_interval}})
}); });
@ -207,8 +264,8 @@
}) })
}); });
$("body").on("click", ".refresh", function (){ $("body").on("click", ".refresh", function (){
load_data(); load_data($('#search_peer_textbox').val());
}); });
</script> </script>
<script src="{{ url_for('static',filename='configuration.js') }}"></script> <script src="{{ url_for('static',filename='js/configuration.js') }}"></script>
</html> </html>

View File

@ -1,9 +1,3 @@
<script src="https://code.jquery.com/jquery-3.5.1.min.js" <script src="{{ url_for('static', filename='js/jquery.min.js') }}"></script>
integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script> <script src="{{ url_for('static',filename='js/bootstrap.bundle.js') }}"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" <script src="{{ url_for('static',filename='js/tools.js') }}"></script>
integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.min.js"
integrity="sha384-w1Q4orYjBQndcko6MimVbzY0tgp4pWB4lZ7lr30WKz0vr/aWKhXdBNmNb5D92v7s"
crossorigin="anonymous"></script>
<script src="{{ url_for('static',filename='tools.js') }}"></script>

View File

@ -39,8 +39,11 @@
</div> </div>
<div class="w-100"></div> <div class="w-100"></div>
<div class="col-sm"> <div class="col-sm">
<small class="text-muted"><strong>PUBLIC KEY</strong></small> <small class="text-muted">
<h6 style="text-transform: uppercase;"><samp>{{conf_data['public_key']}}</samp></h6> <strong>PUBLIC KEY</strong>
<strong style="margin-left: auto!important; opacity: 0; transition: 0.2s ease-in-out" class="text-primary">CLICK TO COPY</strong></small>
</small>
<h6 style="text-transform: uppercase;"><samp class="key">{{conf_data['public_key']}}</samp></h6>
</div> </div>
<div class="col-sm"> <div class="col-sm">
<small class="text-muted"><strong>LISTEN PORT</strong></small> <small class="text-muted"><strong>LISTEN PORT</strong></small>
@ -48,85 +51,122 @@
</div> </div>
</div> </div>
<hr> <hr>
<div class="button-div mb-3" style="text-align: right;"> <div class="button-div mb-3">
<div class="btn-group" role="group" aria-label="Basic example"> <div class="row">
<button type="button" class="btn btn-outline-primary btn-sm btn-group-label refresh"><i class="bi bi-arrow-repeat"></i></button> <div class="col-sm">
<button type="button" class="btn btn-outline-primary btn-sm update_interval" refresh-interval="5000">5s</button> <div class="form-group">
<button type="button" class="btn btn-outline-primary btn-sm update_interval" refresh-interval="10000">10s</button> <label for="sort_by_dropdown"><small class="text-muted">Sort Peers By</small></label>
<button type="button" class="btn btn-outline-primary btn-sm update_interval" refresh-interval="30000">30s</button> <select class="form-control" id="sort_by_dropdown">
<button type="button" class="btn btn-outline-primary btn-sm update_interval" refresh-interval="60000">1m</button> <option value="status" {% if sort_tag == "status" %} {{ "selected" }} {% endif %}>Status</option>
</div> <option value="name" {% if sort_tag == "name" %} {{ "selected" }} {% endif %}>Name</option>
<button type="button" class="btn btn-primary add_btn btn-sm" data-toggle="modal" data-target="#add_modal"> <option value="allowed_ip" {% if sort_tag == "allowed_ip" %} {{ "selected" }} {% endif %}>Allowed IP</option>
<i class="bi bi-plus-circle-fill"></i> PEER </select>
</button> </div>
</div> </div>
</div> <div class="col-sm">
<div class="form-group">
{% for i in conf_data['peer_data']%} <label><small class="text-muted">Refresh Interval</small></label><br>
<div class="card mb-3"> <div class="btn-group" role="group">
<div class="card-header"> <button type="button" class="btn btn-outline-primary btn-group-label refresh"><i class="bi bi-arrow-repeat"></i></button>
<div class="row"> <button type="button" class="btn btn-outline-primary update_interval {% if dashboard_refresh_interval == 5000 %} {{ "active" }} {% endif %}" refresh-interval="5000">5s</button>
<div class="col-sm"> <button type="button" class="btn btn-outline-primary update_interval {% if dashboard_refresh_interval == 10000 %} {{ "active" }} {% endif %}" refresh-interval="10000">10s</button>
<div class="card-header-body "> <button type="button" class="btn btn-outline-primary update_interval {% if dashboard_refresh_interval == 30000 %} {{ "active" }} {% endif %}" refresh-interval="30000">30s</button>
{% if not i['name']%} <button type="button" class="btn btn-outline-primary update_interval {% if dashboard_refresh_interval == 60000 %} {{ "active" }} {% endif %}" refresh-interval="60000">1m</button>
{{ "Untitled Peer" }}
{% else %}
{{i['name']}}
{% endif %}
<span class="dot dot-{{i['status']}}"></span>
</div> </div>
</div> </div>
<div class="col-sm peer_data_group">
<p class="text-primary" style="text-transform: uppercase; display: inline-block; margin-bottom: 0; margin-right: 1rem"><i class="bi bi-arrow-down-right"></i> {{i['total_receive']}} GB</p>
<p class="text-success" style="text-transform: uppercase; display: inline-block; margin-bottom: 0"><i class="bi bi-arrow-up-right"></i> {{i['total_sent']}} GB</p>
</div>
</div> </div>
<div class="col-sm">
<div class="form-group">
<label><small class="text-muted">Add</small></label><br>
<button type="button" class="btn btn-primary add_btn" data-toggle="modal" data-target="#add_modal" style="width: 100%">
<i class="bi bi-plus-circle-fill"></i> Add Peer
</button>
</div>
</div>
</div> </div>
<div class="card-body"> <hr>
<div class="row">
<div class="col-sm">
<small class="text-muted"><strong>PEER</strong></small>
<h6><samp class="ml-auto">{{i['id']}}</samp></h6>
</div>
<div class="col-sm">
<small class="text-muted"><strong>ALLOWED IP</strong></small>
<h6 style="text-transform: uppercase;">{{i['allowed_ip']}}</h6>
</div>
<div class="w-100"></div>
<div class="col-sm">
<small class="text-muted"><strong>LATEST HANDSHAKE</strong></small>
<h6 style="text-transform: uppercase;">{{i['latest_handshake']}}</h6>
</div>
<div class="col-sm">
<small class="text-muted"><strong>END POINT</strong></small>
<h6 style="text-transform: uppercase;">{{i['endpoint']}}</h6>
</div>
<div class="w-100"></div>
<div class="col-sm">
<hr>
<div class="button-group" style="display:flex">
<button type="button" class="btn btn-outline-primary btn-setting-peer btn-control" id="{{i['id']}}" data-toggle="modal"><i class="bi bi-gear-fill"></i></button>
<button type="button" class="btn btn-outline-danger btn-delete-peer btn-control" id="{{i['id']}}" data-toggle="modal"><i class="bi bi-x-circle-fill"></i></button>
{% if i['private_key'] %}
<div class="share_peer_btn_group" style="margin-left: auto !important; display: inline">
<button type="button" class="btn btn-outline-success btn-qrcode-peer btn-control" img_src="{{ qrcode("[Interface]\nPrivateKey = "+i['private_key']+"\nAddress = "+i['allowed_ip']+"\nDNS = 1.1.1.1\n\n[Peer]\nPublicKey = "+conf_data['public_key']+"\nAllowedIPs = 0.0.0.0/0\nEndpoint = "+wg_ip+":"+conf_data['listen_port']) }}">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" style="width: 19px;" fill="#28a745"><path d="M3 11h8V3H3v8zm2-6h4v4H5V5zM3 21h8v-8H3v8zm2-6h4v4H5v-4zM13 3v8h8V3h-8zm6 6h-4V5h4v4zM13 13h2v2h-2zM15 15h2v2h-2zM13 17h2v2h-2zM17 17h2v2h-2zM19 19h2v2h-2zM15 19h2v2h-2zM17 13h2v2h-2zM19 15h2v2h-2z"/></svg>
</button>
<a href="/download/{{ conf_data['name'] }}?id={{ i['id']|urlencode }}" type="button" class="btn btn-outline-info btn-download-peer btn-control">
<i class="bi bi-download"></i>
</a>
</div>
{% endif %}
</div>
</div>
</div>
</div>
</div> </div>
{%endfor%} </div>
<div class="row">
{% if conf_data['peer_data']|length == 0 %}
<div class="col-12" style="text-align: center; margin-top: 1.5rem">
<h3 class="text-muted">Oops! No peers found ‘︿’</h3>
</div>
{% endif %}
{% for i in conf_data['peer_data']%}
<div class="col-sm-6 col-md-4">
<div class="card mb-3">
<div class="card-header">
<div class="row">
<div class="col-12">
<div class="card-header-body ">
{% if not i['name']%}
{{ "Untitled Peer" }}
{% else %}
{{i['name']}}
{% endif %}
<span class="dot dot-{{i['status']}}"></span>
</div>
</div>
<div class="col-12 peer_data_group">
<p class="text-primary" style="text-transform: uppercase; display: inline-block; margin-bottom: 0; margin-right: 1rem"><i class="bi bi-arrow-down-right"></i> {{i['total_receive']}} GB</p>
<p class="text-success" style="text-transform: uppercase; display: inline-block; margin-bottom: 0"><i class="bi bi-arrow-up-right"></i> {{i['total_sent']}} GB</p>
</div>
</div>
</div>
<div class="card-body">
<div class="row">
<div class="col-sm">
<small class="text-muted" style="display: flex">
<strong>PEER</strong>
<strong style="margin-left: auto!important; opacity: 0; transition: 0.2s ease-in-out" class="text-primary">CLICK TO COPY</strong></small>
<h6><samp class="ml-auto key">{{i['id']}}</samp></h6>
</div>
<div class="col-sm">
<small class="text-muted"><strong>ALLOWED IP</strong></small>
<h6 style="text-transform: uppercase;">{{i['allowed_ip']}}</h6>
</div>
<div class="w-100"></div>
<div class="col-sm">
<small class="text-muted"><strong>LATEST HANDSHAKE</strong></small>
<h6 style="text-transform: uppercase;">{{i['latest_handshake']}}</h6>
</div>
<div class="w-100"></div>
<div class="col-sm">
<small class="text-muted"><strong>END POINT</strong></small>
<h6 style="text-transform: uppercase;">{{i['endpoint']}}</h6>
</div>
<div class="w-100"></div>
<div class="col-sm">
<hr>
<div class="button-group" style="display:flex">
<button type="button" class="btn btn-outline-primary btn-setting-peer btn-control" id="{{i['id']}}" data-toggle="modal"><i class="bi bi-gear-fill"></i></button>
<button type="button" class="btn btn-outline-danger btn-delete-peer btn-control" id="{{i['id']}}" data-toggle="modal"><i class="bi bi-x-circle-fill"></i></button>
{% if i['private_key'] %}
<div class="share_peer_btn_group" style="margin-left: auto !important; display: inline">
<button type="button" class="btn btn-outline-success btn-qrcode-peer btn-control" img_src="{{ qrcode("[Interface]\nPrivateKey = "+i['private_key']+"\nAddress = "+i['allowed_ip']+"\nDNS = 1.1.1.1\n\n[Peer]\nPublicKey = "+conf_data['public_key']+"\nAllowedIPs = 0.0.0.0/0\nEndpoint = "+wg_ip+":"+conf_data['listen_port']) }}">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" style="width: 19px;" fill="#28a745"><path d="M3 11h8V3H3v8zm2-6h4v4H5V5zM3 21h8v-8H3v8zm2-6h4v4H5v-4zM13 3v8h8V3h-8zm6 6h-4V5h4v4zM13 13h2v2h-2zM15 15h2v2h-2zM13 17h2v2h-2zM17 17h2v2h-2zM19 19h2v2h-2zM15 19h2v2h-2zM17 13h2v2h-2zM19 15h2v2h-2z"/></svg>
</button>
<a href="/download/{{ conf_data['name'] }}?id={{ i['id']|urlencode }}" type="button" class="btn btn-outline-info btn-download-peer btn-control">
<i class="bi bi-download"></i>
</a>
</div>
{% endif %}
</div>
</div>
</div>
</div>
</div>
</div>
{%endfor%}
</div>
</main> </main>

View File

@ -1,10 +1,10 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Wireguard Dashboard</title> <title>Wireguard Dashboard - {{ title }}</title>
<link rel="icon" href="{{ url_for('static',filename='logo.png') }}"/> <link rel="icon" href="{{ url_for('static',filename='img/logo.png') }}"/>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous"> <link rel="stylesheet" href="{{ url_for('static',filename='css/bootstrap.min.css') }}">
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='dashboard.css') }}"> <link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='css/dashboard.css') }}">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.4.1/font/bootstrap-icons.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.4.1/font/bootstrap-icons.css">
</head> </head>

View File

@ -4,4 +4,7 @@
data-target="#sidebarMenu" aria-controls="sidebarMenu" aria-expanded="false" aria-label="Toggle navigation"> data-target="#sidebarMenu" aria-controls="sidebarMenu" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span> <span class="navbar-toggler-icon"></span>
</button> </button>
</nav> </nav>
<div class="progress" style="height: 3px; position: fixed; width: 100%; z-index: 10000; background-color: transparent">
<div class="progress-bar" role="progressbar" style="z-index: 10000; width: 0%"></div>
</div>

View File

@ -1,41 +1,64 @@
<html> <html>
{% include "header.html" %} {% include "header.html" %}
<body> <body>
{% include "navbar.html" %} {% include "navbar.html" %}
<div class="container-fluid"> <div class="container-fluid">
{% include "sidebar.html" %} {% include "sidebar.html" %}
<main role="main" class="col-md-9 ml-sm-auto col-lg-10 px-md-4"> <main role="main" class="col-md-9 ml-sm-auto col-lg-10 px-md-4">
<div class="setting-container mt-4"> <div class="setting-container mt-4">
{% if message != ""%} {% if message != "" %}
<div class="alert alert-{{ status }}" role="alert"> <div class="alert alert-{{ status }}" role="alert">
{{ message }} {{ message }}
</div> </div>
{% endif %} {% endif %}
<h1 class="pb-4">Settings</h1> <h1 class="pb-4">Settings</h1>
{% if required_auth == "true" %} {% if required_auth == "true" %}
<h3>Account</h3> <h3>Account</h3>
<form action="/update_acct" method="post"> <form action="/update_acct" method="post">
<div class="form-group"> <div class="form-group">
<label for="username">Username</label> <label for="username">Username</label>
<input type="text" class="form-control mb-4" id="username" name="username" value="{{ session['username'] }}"> <input type="text" class="form-control mb-4" id="username" name="username"
<button type="submit" class="btn btn-success" >Update Account</button> value="{{ session['username'] }}" required>
<button type="submit" class="btn btn-success">Update Account</button>
</div>
</form>
<hr>
<h3>New Peer Default Settings</h3>
<form action="/update_peer_default_config" method="post">
<div class="form-group">
<div class="row">
<div class="col-sm">
<label for="username">DNS</label>
<input type="text" class="form-control mb-4" id="peer_global_DNS" name="peer_global_DNS"
value="{{ peer_global_DNS }}" required>
</div>
<div class="col-sm">
<label for="username">Peer Endpoint Allowed IPs</label>
<input type="text" class="form-control mb-4" id="peer_endpoint_allowed_ip" name="peer_endpoint_allowed_ip"
value="{{ peer_endpoint_allowed_ip }}" required>
</div>
</div> </div>
</form> <button class="btn btn-success" type="submit">Update Peer Default Settings</button>
<hr> </div>
<h3>WireGuard Configuration Path</h3> </form>
<form action="/update_wg_conf_path" method="post" class="update_wg_conf_path"> <hr>
<div class="form-group">
<label for="username">Path</label>
<input type="text" class="form-control mb-4" id="wg_conf_path" name="wg_conf_path" value="{{ wg_conf_path }}">
<p>Remember to remove <code>/</code> at the end of your path. e.g <code>/etc/wireguard</code></p> <h3>WireGuard Configuration Path</h3>
<form action="/update_wg_conf_path" method="post" class="update_wg_conf_path">
<div class="form-group">
<label for="username">Path</label>
<input type="text" class="form-control mb-4" id="wg_conf_path" name="wg_conf_path"
value="{{ wg_conf_path }}">
<p>Remember to remove <code>/</code> at the end of your path. e.g <code>/etc/wireguard</code>
</p>
<button class="btn btn-danger change_path">Update Path & Restart Dashboard</button> <button class="btn btn-danger change_path">Update Path & Restart Dashboard</button>
</div> </div>
</form> </form>
<hr> <hr>
<h3>Security</h3> <h3>Security</h3>
<form action="/update_pwd", method="post"> <form action="/update_pwd" , method="post">
<div class="form-group"> <div class="form-group">
<label for="currentpass">Current Password</label> <label for="currentpass">Current Password</label>
<input type="password" class="form-control mb-2" id="currentpass" name="currentpass"> <input type="password" class="form-control mb-2" id="currentpass" name="currentpass">
<label for="newpass">New Password</label> <label for="newpass">New Password</label>
@ -43,37 +66,42 @@
<label for="repnewpass">Repeat New Password</label> <label for="repnewpass">Repeat New Password</label>
<input type="password" class="form-control mb-4" id="repnewpass" name="repnewpass"> <input type="password" class="form-control mb-4" id="repnewpass" name="repnewpass">
<button type="submit" class="btn btn-danger">Update Password</button> <button type="submit" class="btn btn-danger">Update Password</button>
</div>
</form>
<hr>
{% endif %}
<h3>Dashboard Configuration</h3>
<form action="/update_app_ip_port" method="post" class="update_app_ip_port">
<div class="form-group">
<div class="row">
<div class="col-sm">
<label for="app_ip">Dashboard IP</label>
<input type="text" class="form-control mb-2" id="app_ip" name="app_ip" value="{{ app_ip }}">
<p><small class="text-danger mb-4">0.0.0.0 means it can be access by anyone with your server
IP Address.</small></p>
</div> </div>
</form> <div class="col-sm">
<hr> <label for="app_port">Dashboard Port</label>
{% endif %} <input type="text" class="form-control mb-4" id="app_port" name="app_port"
<h3>Dashboard Configuration</h3> value="{{ app_port }}">
<form action="/update_app_ip_port" method="post" class="update_app_ip_port">
<div class="form-group">
<div class="row">
<div class="col-sm">
<label for="app_ip" >Dashboard IP</label>
<input type="text" class="form-control mb-2" id="app_ip" name="app_ip" value="{{ app_ip }}">
<p><small class="text-danger mb-4">0.0.0.0 means it can be access by anyone with your server IP Address.</small></p>
</div>
<div class="col-sm">
<label for="app_port">Dashboard Port</label>
<input type="text" class="form-control mb-4" id="app_port" name="app_port" value="{{ app_port }}">
</div>
</div>
<button type="button" class="btn btn-danger confirm_modal" data-toggle="modal" data-target="#confirmModal">Update Configuration & Restart</button>
</div> </div>
</form> </div>
<button type="button" class="btn btn-danger confirm_modal" data-toggle="modal"
data-target="#confirmModal">Update Configuration & Restart
</button>
</div> </div>
</main> </form>
<!-- Modal --> </div>
<div class="modal fade" id="confirmModal" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true"> </main>
<div class="modal-dialog"> <!-- Modal -->
<div class="modal-content"> <div class="modal fade" id="confirmModal" data-backdrop="static" data-keyboard="false" tabindex="-1"
<div class="modal-header"> aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="staticBackdropLabel">Confirm Dashboard Configuration</h5> <h5 class="modal-title" id="staticBackdropLabel">Confirm Dashboard Configuration</h5>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<small>Dashboard Original IP</small> <small>Dashboard Original IP</small>
<p>{{ app_ip }}</p> <p>{{ app_ip }}</p>
<small style="font-weight: bold" class="text-bold">Dashboard New IP</small> <small style="font-weight: bold" class="text-bold">Dashboard New IP</small>
@ -82,49 +110,49 @@
<p>{{ app_port }}</p> <p>{{ app_port }}</p>
<small style="font-weight: bold" class="text-bold">Dashboard New Port</small> <small style="font-weight: bold" class="text-bold">Dashboard New Port</small>
<p class="app_new_port text-bold text-danger" style="font-weight: bold"></p> <p class="app_new_port text-bold text-danger" style="font-weight: bold"></p>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-secondary cancel_restart" data-dismiss="modal">Cancel</button> <button type="button" class="btn btn-secondary cancel_restart" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-danger confirm_restart">Confirm & Restart Dashboard</button> <button type="button" class="btn btn-danger confirm_restart">Confirm & Restart Dashboard</button>
</div>
</div> </div>
</div>
</div> </div>
</div> </div>
</body> </div>
</div>
</body>
{% include "footer.html" %} {% include "footer.html" %}
<script> <script>
$(".sb-settings-url").addClass("active") $(".sb-settings-url").addClass("active")
$(".confirm_modal").click(function (){ $(".confirm_modal").click(function () {
$(".app_new_ip").html($("#app_ip")[0].value) $(".app_new_ip").html($("#app_ip")[0].value)
$(".app_new_port").html($("#app_port")[0].value) $(".app_new_port").html($("#app_port")[0].value)
}) })
$(".confirm_restart").click(function (){ $(".confirm_restart").click(function () {
$(".cancel_restart").remove() $(".cancel_restart").remove()
countdown = 7; countdown = 7;
$.post('/update_app_ip_port', $('.update_app_ip_port').serialize()) $.post('/update_app_ip_port', $('.update_app_ip_port').serialize())
url = $("#app_ip")[0].value+":"+$("#app_port")[0].value; url = $("#app_ip")[0].value + ":" + $("#app_port")[0].value;
$(".confirm_restart").attr("disabled", "disabled") $(".confirm_restart").attr("disabled", "disabled")
setInterval(function (){ setInterval(function () {
if (countdown === 0){ if (countdown === 0) {
window.location.replace("http://"+url); window.location.replace("http://" + url);
} }
$(".confirm_restart").html("Redirecting you in "+countdown+" seconds.") $(".confirm_restart").html("Redirecting you in " + countdown + " seconds.")
countdown--; countdown--;
},1000) }, 1000)
}); });
$(".change_path").click(function (){ $(".change_path").click(function () {
$(this).attr("disabled", "disabled"); $(this).attr("disabled", "disabled");
countdown = 5; countdown = 5;
setInterval(function (){ setInterval(function () {
if (countdown === 0){ if (countdown === 0) {
location.reload() location.reload()
} }
$(".change_path").html("Redirecting you in "+countdown+" seconds.") $(".change_path").html("Redirecting you in " + countdown + " seconds.")
countdown--; countdown--;
},1000) }, 1000)
$.post('/update_wg_conf_path', $('.update_wg_conf_path').serialize()) $.post('/update_wg_conf_path', $('.update_wg_conf_path').serialize())
}); });

View File

@ -5,7 +5,7 @@
<title>Wireguard Dashboard | Login</title> <title>Wireguard Dashboard | Login</title>
<link rel="icon" href="{{ url_for('static',filename='logo.png') }}"/> <link rel="icon" href="{{ url_for('static',filename='logo.png') }}"/>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='dashboard.css') }}"> <link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='css/dashboard.css') }}">
</head> </head>
<body> <body>
{% include "navbar.html" %} {% include "navbar.html" %}

0
src/wgd.sh Normal file → Executable file
View File