diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analyze.yaml similarity index 93% rename from .github/workflows/codeql-analysis.yml rename to .github/workflows/codeql-analyze.yaml index 59c192e..18796f2 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analyze.yaml @@ -38,11 +38,11 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v1 + uses: github/codeql-action/init@v3 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -53,7 +53,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@v1 + uses: github/codeql-action/autobuild@v3 # ℹ️ Command-line programs to run using the OS shell. # πŸ“š https://git.io/JvXDl @@ -67,4 +67,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 + uses: github/codeql-action/analyze@v3 diff --git a/.github/workflows/docker-analyze.yaml b/.github/workflows/docker-analyze.yaml new file mode 100644 index 0000000..a3533a7 --- /dev/null +++ b/.github/workflows/docker-analyze.yaml @@ -0,0 +1,50 @@ +name: Docker-Analyze + +on: + schedule: + - cron: "0 0 * * *" # Daily at midnight UTC + workflow_dispatch: + inputs: + trigger-build: + description: 'Trigger a manual build and push' + default: 'true' + +env: + DOCKER_IMAGE: donaldzou/wgdashboard + +jobs: + docker_analyze: + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_PASSWORD }} + + - name: Install Docker Scout + run: | + echo "Installing Docker Scout..." + curl -fsSL https://raw.githubusercontent.com/docker/scout-cli/main/install.sh | sh -s -- + echo "Docker Scout installed successfully." + - name: Analyze Docker image with Docker Scout + id: analyze-image + run: | + echo "Analyzing Docker image with Docker Scout..." + docker scout cves ${{ env.DOCKER_IMAGE }}:latest > scout-results.txt + cat scout-results.txt + echo "Docker Scout analysis completed." + - name: Fail if critical CVEs are found + run: | + if grep -q "0C" scout-results.txt; then + echo "No critical vulnerabilities found! Continueing." + exit 0 + else + echo "At least one critical vulnerabilities found! Exiting." + exit 1 + fi diff --git a/.github/workflows/docker-build.yaml b/.github/workflows/docker-build.yaml new file mode 100644 index 0000000..200362c --- /dev/null +++ b/.github/workflows/docker-build.yaml @@ -0,0 +1,38 @@ +name: Docker-Build + +on: + push: + branches: [ main ] + workflow_dispatch: + inputs: + trigger-build: + description: 'Trigger a manual build and push' + default: 'true' + +env: + DOCKER_IMAGE: donaldzou/wgdashboard + +jobs: + docker_build: + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_PASSWORD }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and export + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: ${{ env.DOCKER_IMAGE }}:latest diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 5c097e7..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,56 +0,0 @@ -name: Docker Image Build and Analysis - -on: - schedule: - - cron: "0 0 * * *" # Schedule the workflow to run daily at midnight (UTC time). Adjust the time if needed. - workflow_dispatch: # Manual run trigger - inputs: - trigger-build: - description: 'Trigger a manual build and push' - default: 'true' - -jobs: - build-and-analyze: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Log in to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build Docker image - id: build-image - run: | - echo "Building Docker image..." - docker build -t my-app-image:latest . - echo "Docker image built successfully." - - - name: Install Docker Scout - run: | - echo "Installing Docker Scout..." - curl -sSfL https://raw.githubusercontent.com/docker/scout-cli/main/install.sh | sh -s -- - echo "Docker Scout installed successfully." - - - name: Analyze Docker image with Docker Scout - id: analyze-image - run: | - echo "Analyzing Docker image with Docker Scout..." - docker scout cves my-app-image:latest > scout-results.txt - cat scout-results.txt # Print the report to the workflow logs for easy viewing - echo "Docker Scout analysis completed." - - - name: Post Comment on Issue or PR - run: | - COMMENT="**Docker Image Build and Analysis Report**\n\nThe Docker image was built and analyzed successfully.\n\n**Build Summary:**\n- Image Tag: my-app-image:latest\n\n**Analysis Report:**\n\`\`\`\n$(cat scout-results.txt)\n\`\`\`" - - # Post comment using GitHub API - curl -X POST \ - -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ - -H "Accept: application/vnd.github.v3+json" \ - -d "{\"body\": \"$COMMENT\"}" \ - "https://api.github.com/repos/NOXCIS/WGDashboard/issues/1/comments" # Replace '1' with the issue or PR number diff --git a/README.md b/README.md index abc828e..f331caa 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ +> [!NOTE] +> **Help Wanted πŸŽ‰**: Localizing WGDashboard to other languages! If you're willing to help, please visit https://github.com/donaldzou/WGDashboard/issues/397. Many thanks! +
+

WGDashboard

WGDashboard

- -

@@ -17,570 +19,28 @@ wakatime

-

Monitoring WireGuard is not convenient, need to remote access to server and type wg show. That's why this project is being created, to view all configurations and manage them in a easy way.

-

With all these awesome features, while keeping it simple, easy to install and use

+

Monitoring WireGuard is not convenient, in most case, you'll need to login to your server and type wg show. That's why this project is being created, to view and manage all WireGuard configurations in a easy way.

+

With all these awesome features, while keeping it easy to install and use

This project is not affiliate to the official WireGuard Project

-## πŸ“£ What's New: v4.0 - -> [!TIP] -> [πŸ“Ή Demo video on YouTube](https://www.youtube.com/watch?v=0mwzd5Gr2eU) - -### πŸŽ‰ New Features - -- **Updated dashboard design**: Re-designed some of the section with more modern style and layout, the UI is faster and more responsive, it also uses less memory. But overall is still the same dashboard you're familiarized. -- **Docker Solution**: We now have 2 docker solutions! Thanks to @DaanSelen & @shuricksumy for providing them. For more information, please see the [Docker](#-docker-solutions) section below. -- **Peer Job Scheduler**: Now you can schedule jobs for each peer to either **restrict** or **delete** the peer if the peer's total / upload / download data usage exceeded a limit, or you can set a specific datetime to restrict or delete the peer. -- **Share Peer's QR Code with Public Link**: You can share a peer's QR code and `.conf` file without the need to loging in. -- **WGDashboard's REST API**: You can now request all the api endpoint used in the dashboard. For more details please review the [API Documentation](./docs/api-documents.md). -- **Logging**: Dashboard will now log all activity on the dashboard and API requests. -- **Time-Based One-Time Password (TOTP)**: You can enable this function to add one more layer of security, and generate the TOTP with your choice of authenticator. -- **Designs** - - **Real-time Graphs**: You can view real-time data changes with graphs in each configuration. - - **Night mode**: You know what that means, it avoids bugs ;) -- **Enforce Python Virtual Environment**: I noticed newer Python version (3.12) does not allow to install packages globally, and plus I think is a good idea to use venv. - -### 🧐 Other Changes -- **Deprecated jQuery from the project, and migrated and rewrote the whole front-end with Vue.js. This allows the dashboard is future proofed, and potential cross server access with a desktop app.** -- Rewrote the backend into a REST API structure -- Improved SQL query efficient -- Removed all templates, except for `index.html` where it will load the Vue.js app. -- Parsing names in `.conf` -- Minimized the need to read `.conf`, only when any `.conf` is modified - -### πŸ₯˜ New Experimental Features - - **Cross-Server Access**: Now you can access other servers that installed `v4` of WGDashboard through API key. - - **Desktop App**: Thanks to **Cross-Server Access**, you can now download an ElectronJS based desktop app of WGDashboard, and use that to access WGDashboard on different servers. - - > For more information, please scroll down to [πŸ₯˜ Experimental Functions](#-experimental-functions) - -> I can't thank enough for all of you who wait for this release, and for those who are new to this project, welcome :) -> Also, huge thanks to who contributed to this major release: -> @bolgovrussia, @eduardorosabales, @Profik, @airgapper, @tokon2000, @bkeenke, @kontorskiy777, @bugsse, @Johnnykson, @DaanSelen, @shuricksumy and many others! +

+ Join our Discord Server for quick help, or you wanna chat about this project! +

+

+ +


-## πŸ“‹ Table of Content - - - * [πŸ“£ What's New: v4.0](#-whats-new-v40) - * [πŸŽ‰ New Features](#-new-features) - * [🧐 Other Changes](#-other-changes) - * [πŸ₯˜ New Experimental Features](#-new-experimental-features) - * [πŸ“‹ Table of Content](#-table-of-content) - * [πŸ’‘ Features](#-features) - * [πŸ“ Requirements](#-requirements) - * [Supported Operating Systems](#supported-operating-systems) - * [Existing WireGuard Configurations](#existing-wireguard-configurations) - * [πŸ›  Install](#-install) - * [Install Commands](#install-commands) - * [Ubuntu 20.04 LTS](#ubuntu-2004-lts) - * [Ubuntu 22.04 LTS & Ubuntu 24.02 LTS](#ubuntu-2204-lts--ubuntu-2402-lts) - * [Debian 12.6](#debian-126) - * [Debian 11.10](#debian-1110) - * [Red Hat Enterprise Linux 9.4 & CentOS 9-Stream](#red-hat-enterprise-linux-94--centos-9-stream) - * [Fedora 40 & Fedora 39 & Fedora 38](#fedora-40--fedora-39--fedora-38) - * [Alpine Linux 3.20.2](#alpine-linux-3202) - * [Manual Installation](#manual-installation) - * [πŸͺœ Usage](#-usage) - * [Start/Stop/Restart WGDashboard](#startstoprestart-wgdashboard) - * [Autostart WGDashboard on boot (>= v2.2)](#autostart-wgdashboard-on-boot--v22) - * [βœ‚οΈ Dashboard Configuration](#-dashboard-configuration) - * [Dashboard Configuration file](#dashboard-configuration-file) - * [Generating QR code and peer configuration file (.conf)](#generating-qr-code-and-peer-configuration-file-conf) - * [❓ How to update the dashboard?](#-how-to-update-the-dashboard) - * [**Please note for users who are using `v3 - v3.0.6` want to update to `v4.0`**](#please-note-for-users-who-are-using-v3---v306-want-to-update-to-v40) - * [**Please note for users who are using `v2.3.1` or below**](#please-note-for-users-who-are-using-v231-or-below) - * [🐬 Docker Solutions](#-docker-solutions) - * [Solution 1 from @DaanSelen](#solution-1-from-daanselen) - * [Solution 2 from @shuricksumy](#solution-2-from-shuricksumy) - * [πŸ“– WGDashboard REST API Documentation & How to use API Key](#-wgdashboard-rest-api-documentation--how-to-use-api-key) - * [πŸ₯˜ Experimental Features](#-experimental-features) - * [Cross-Server Access](#cross-server-access) - * [Desktop App](#desktop-app) - * [πŸ” Screenshot](#-screenshot) - * [πŸ•°οΈ Changelogs](#-changelogs) - - -## πŸ’‘ Features - -- Automatically look for existing WireGuard configuration under `/etc/wireguard` -- Easy to use interface, provided credential and TOTP protection to the dashboard -- Manage peers and configuration - - Add Peers or by bulk with auto-generated information - - Edit peer information - - Delete peers with ease - - Restrict peers - - Generate QR Code and `.conf` file for peers, share it through a public link - - Schedule jobs to delete / restrict peer when conditions are met -- View real time peer status -- Testing tool: Ping and Traceroute to your peer - - -## πŸ“ Requirements - -1. Supported operating systems. Please view the list below. -2. WireGuard & WireGuard-Tools (`wg-quick`) -3. Python 3.10 / 3.11 / 3.12 -4. `git`, `net-tools`, `sudo` (_This should only apply to RHEL 9 & 8, interestingly it doesn't have it preinstalled)_ - -### Supported Operating Systems > [!NOTE] -> All operating systems below are tested by myself. All are ARM64 ran in UTM Virtual Machine. - -| Ubuntu | Debian | Red Hat Enterprise Linux | CentOS | Fedora | Alpine Linux | -|-----------|--------|--------------------------|----------|--------|------------------------| -| 20.04 LTS | 12.6 | 9.4 | 9-Stream | 40 | 3.20.2 (Under Testing) | -| 22.04 LTS | 11.10 | | | 39 | | -| 24.02 LTS | | | | 38 | | - -> [!TIP] -> If you installed WGDashboard on other systems without any issues, please let me know. Thank you! - -### Existing WireGuard Configurations - -> [!NOTE] -> This only applies to existing WireGuard Configuration under `/etc/wireguard` - -```ini -[Interface] -... -SaveConfig = true -# Need to include this line to allow WireGuard Tool to save your configuration, -# or if you just want it to monitor your WireGuard Interface and don't need to -# make any changes with the dashboard, you can set it to false. - -[Peer] -#Name# = Donald's iPhone -PublicKey = abcd1234 -AllowedIPs = 1.2.3.4/32 -``` -> [!TIP] -> With `v4`, WGDashboard will look for entry with `#Name# = abc...` in each peer and use that for the name. - -## πŸ›  Install - -### Install Commands - -These commands are tested by myself in each OS. It contains commands to install WireGuard, Git, Net Tools, and even Python on some OS. - -> [!WARNING] -> Please make sure you understand these commands before you run them. - -#### Ubuntu 20.04 LTS - -```shell -sudo add-apt-repository ppa:deadsnakes/ppa -y && \ -sudo apt-get update -y && \ -sudo apt-get install python3.10 python3.10-distutils wireguard-tools net-tools --no-install-recommends -y && \ -git clone https://github.com/donaldzou/WGDashboard.git && \ -cd WGDashboard/src && \ -chmod +x ./wgd.sh && \ -./wgd.sh install && \ -sudo echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf && \ -sudo sysctl -p -``` -#### Ubuntu 22.04 LTS & Ubuntu 24.02 LTS - -```shell -sudo apt-get update -y && \ -sudo apt install wireguard-tools net-tools --no-install-recommends -y && \ -git clone https://github.com/donaldzou/WGDashboard.git && \ -cd ./WGDashboard/src && \ -chmod +x ./wgd.sh && \ -./wgd.sh install && \ -sudo echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf && \ -sudo sysctl -p /etc/sysctl.conf -``` -#### Debian 12.6 - -```shell -apt-get install sudo git iptables -y && \ -sudo apt-get update && \ -sudo apt install wireguard-tools net-tools && \ -git clone https://github.com/donaldzou/WGDashboard.git && \ -cd ./WGDashboard/src && \ -chmod +x ./wgd.sh && \ -./wgd.sh install && \ -sudo echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf && \ -sudo sysctl -p /etc/sysctl.conf -``` - -#### Debian 11.10 - -> [!WARNING] -> This commands will download Python 3.10's source code and build from it, since Debian 11.10 doesn't comes with Python 3.10 - -```shell -apt-get install sudo -y && \ -sudo apt-get update && \ -sudo apt install -y git iptables build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev wireguard-tools net-tools && \ -wget https://www.python.org/ftp/python/3.10.0/Python-3.10.0.tgz && \ -tar -xvf Python-3.10.0.tgz && \ -cd Python-3.10.0 && \ -sudo ./configure --enable-optimizations && \ -sudo make && \ -sudo make altinstall && \ -cd .. && \ -git clone https://github.com/donaldzou/WGDashboard.git && \ -cd ./WGDashboard/src && \ -chmod +x ./wgd.sh && \ -./wgd.sh install && \ -sudo echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf && \ -sudo sysctl -p /etc/sysctl.conf -``` - -#### Red Hat Enterprise Linux 9.4 & CentOS 9-Stream - -```shell -sudo yum install wireguard-tools net-tools git python3.11 -y && \ -git clone https://github.com/donaldzou/WGDashboard.git && \ -cd ./WGDashboard/src && \ -chmod +x ./wgd.sh && \ -./wgd.sh install && \ -sudo echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf && \ -sudo sysctl -p /etc/sysctl.conf && \ -firewall-cmd --add-port=10086/tcp --permanent && \ -firewall-cmd --add-port=51820/udp --permanent && \ -firewall-cmd --reload -``` - -#### Fedora 40 & Fedora 39 & Fedora 38 - -```shell -sudo yum install wireguard-tools net-tools git -y && \ -git clone https://github.com/donaldzou/WGDashboard.git && \ -cd ./WGDashboard/src && \ -chmod +x ./wgd.sh && \ -./wgd.sh install && \ -sudo echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf && \ -sudo sysctl -p /etc/sysctl.conf && \ -firewall-cmd --add-port=10086/tcp --permanent && \ -firewall-cmd --add-port=51820/udp --permanent && \ -firewall-cmd --reload -``` - -#### Alpine Linux 3.20.2 - -```shell -setup-interfaces -a ; \ -rc-service networking --quiet start ; \ -printf "https://mirrors.aliyun.com/alpine/latest-stable/main\nhttps://mirrors.aliyun.com/alpine/latest-stable/community" > /etc/apk/repositories ; \ -apk update ; \ -apk add wireguard-tools python3 python3-dev git iptables net-tools gcc musl-dev linux-headers sudo ; \ -git clone -b v4.0-alpine-linux https://github.com/donaldzou/WGDashboard.git ; \ -cd ./WGDashboard/src ; \ -chmod +x ./wgd.sh ; \ -./wgd.sh install -``` - -### Manual Installation - -> [!NOTE] -> To ensure a smooth installation process, please make sure Python 3.10/3.11/3.12, `git`, `wireguard-tools` and `net-tools` are installed :) - -1. Download WGDashboard - - ```shell - git clone https://github.com/donaldzou/WGDashboard.git wgdashboard - -2. Open the WGDashboard folder - - ```shell - cd wgdashboard/src - ``` - -3. Install WGDashboard - - ```shell - sudo chmod u+x wgd.sh && \ - sudo ./wgd.sh install - ``` - -4. Give read and execute permission to root of the WireGuard configuration folder, you can change the path if your configuration files are not stored in `/etc/wireguard` - - ```shell - sudo chmod -R 755 /etc/wireguard - ``` - -5. Run WGDashboard - - ```shell - sudo ./wgd.sh start - ``` - -6. Access dashboard - - Access your server with port `10086` (e.g. http://your_server_ip:10086), using username `admin` and password `admin`. See below how to change port and ip that the dashboard is running with. - - - -## πŸͺœ Usage - -#### Start/Stop/Restart WGDashboard - - -```shell -cd wgdashboard/src ------------------------------ -./wgd.sh start # Start the dashboard in background ------------------------------ -./wgd.sh debug # Start the dashboard in foreground (debug mode) ------------------------------ -./wgd.sh stop # Stop the dashboard ------------------------------ -./wgd.sh restart # Restart the dasboard -``` - -#### Autostart WGDashboard 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 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 - - ```shell - cd wgdashboard/src - ``` - -2. Get the full path of the dashboard's directory - - ```shell - pwd - #Output: /root/wgdashboard/src - ``` - - 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, the service file is located in `wireguard-dashboard/src`, you can use other editor you like, here will be using `nano` - - ```shell - nano wg-dashboard.service - ``` - - You will see something like this: - - ```ini - [Unit] - After=syslog.target network-online.target - Wants=wg-quick.target - ConditionPathIsDirectory=/etc/wireguard - - [Service] - Type=forking - PIDFile=/gunicorn.pid - WorkingDirectory= - ExecStart=/wgd.sh start - ExecStop=/wgd.sh stop - ExecReload=/wgd.sh restart - TimeoutSec=120 - PrivateTmp=yes - Restart=always - - [Install] - WantedBy=multi-user.target - ``` - - Now, we need to replace all `` to the one you just copied from step 2. After doing this, the file will become something like this, your file might be different: - - **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 - - ```bash - $ sudo cp wg-dashboard.service /etc/systemd/system/wg-dashboard.service - ``` - - 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 - - ```bash - $ sudo chmod 664 /etc/systemd/system/wg-dashboard.service - $ sudo systemctl daemon-reload - $ sudo systemctl enable wg-dashboard.service - $ sudo systemctl start wg-dashboard.service # <-- To start the service - ``` - -6. Check if the service run correctly - - ```bash - $ sudo systemctl status wg-dashboard.service - ``` - And you should see something like this - - ```shell - ● wg-dashboard.service - Loaded: loaded (/etc/systemd/system/wg-dashboard.service; enabled; vendor preset: enabled) - Active: active (running) since Wed 2024-08-14 22:21:47 EDT; 55s ago - Process: 494968 ExecStart=/home/donaldzou/Wireguard-Dashboard/src/wgd.sh start (code=exited, status=0/SUCCESS) - Main PID: 495005 (gunicorn) - Tasks: 5 (limit: 4523) - Memory: 36.8M - CPU: 789ms - CGroup: /system.slice/wg-dashboard.service - β”œβ”€495005 /home/donaldzou/Wireguard-Dashboard/src/venv/bin/python3 ./venv/bin/gunicorn --config ./gunicorn.conf.py - └─495007 /home/donaldzou/Wireguard-Dashboard/src/venv/bin/python3 ./venv/bin/gunicorn --config ./gunicorn.conf.py - - Aug 14 22:21:40 wg sudo[494978]: root : PWD=/home/donaldzou/Wireguard-Dashboard/src ; USER=root ; COMMAND=./venv/bin/gunicorn --config ./gunicorn.conf.py - Aug 14 22:21:40 wg sudo[494978]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0) - Aug 14 22:21:40 wg wgd.sh[494979]: [WGDashboard] WGDashboard w/ Gunicorn will be running on 0.0.0.0:10086 - Aug 14 22:21:40 wg wgd.sh[494979]: [WGDashboard] Access log file is at ./log/access_2024_08_14_22_21_40.log - Aug 14 22:21:40 wg wgd.sh[494979]: [WGDashboard] Error log file is at ./log/error_2024_08_14_22_21_40.log - Aug 14 22:21:40 wg sudo[494978]: pam_unix(sudo:session): session closed for user root - Aug 14 22:21:45 wg wgd.sh[494968]: [WGDashboard] Checking if WGDashboard w/ Gunicorn started successfully - Aug 14 22:21:47 wg wgd.sh[494968]: [WGDashboard] WGDashboard w/ Gunicorn started successfully - Aug 14 22:21:47 wg wgd.sh[494968]: ------------------------------------------------------------ - Aug 14 22:21:47 wg systemd[1]: Started wg-dashboard.service. - ``` - - If you see `Active:` followed by `active (running) since...` then it means it run correctly. - -7. Stop/Start/Restart the service - - ```bash - sudo systemctl stop wg-dashboard.service # <-- To stop the service - sudo systemctl start wg-dashboard.service # <-- To start 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, 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 file - -Since version 2.0, WGDashboard 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 configurations: - -| | Description | Default | Edit Available | -|------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------|----------------| -| **`[Account]`** | *Configuration on account* | | | -| `username` | Dashboard login username | `admin` | Yes | -| `password` | Password, will be hash with SHA256 | `admin` hashed in SHA256 | Yes | -| | | | | -| **`[Server]`** | *Configuration on dashboard* | | | -| `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` | Yes | -| `app_port` | Port the the dashboard will run with | `10086` | Yes | -| `auth_req` | Does the dashboard need authentication to access, 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**. | `true` | **No** | -| `version` | Dashboard Version | `v4.0` | **No** | -| `dashboard_refresh_interval` | How frequent the dashboard will refresh on the configuration page | `60000ms` | Yes | -| `dashboard_sort` | How configuration is sorting | `status` | Yes | -| `dashboard_theme` | Dashboard Theme | `dark` | Yes | -| | | | | -| **`[Peers]`** | *Default Settings on a new peer* | | | -| `peer_global_dns` | DNS Server | `1.1.1.1` | Yes | -| `peer_endpoint_allowed_ip` | Endpoint Allowed IP | `0.0.0.0/0` | Yes | -| `peer_display_mode` | How peer will display | `grid` | Yes | -| `remote_endpoint` | Remote Endpoint (i.e where your peers will connect to) | *depends on your server's default network interface* | Yes | -| `peer_mtu` | Maximum Transmit Unit | `1420` | | -| `peer_keep_alive` | Keep Alive | `21` | Yes | - -#### 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: - -```ini -[Interface] -PrivateKey = QWERTYUIOPO234567890YUSDAKFH10E1B12JE129U21= -Address = 0.0.0.0/32 -DNS = 1.1.1.1 - -[Peer] -PublicKey = QWERTYUIOPO234567890YUSDAKFH10E1B12JE129U21= -AllowedIPs = 0.0.0.0/0 -Endpoint = 0.0.0.0:51820 -``` - -| | Description | Default Value | Available in Peer setting | -| ----------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------- | -| **`[Interface]`** | | | | -| `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 | 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. | Yes | -| **`[Peer]`** | | | | -| `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. | Yes | -| `Endpoint` | Your wireguard server ip and port, the dashboard will search for your server's default interface's ip. | `:` | Yes | - -## ❓ How to update the dashboard? - -#### **Please note for users who are using `v3 - v3.0.6` want to update to `v4.0`** -- Although theoretically updating through `wgd.sh` should work, but I still suggest you to update the dashboard manually. - -#### **Please note for users who are using `v2.3.1` or below** - -- For user who is using `v2.3.1` or below, please notice that all data that stored in the current database will **not** transfer to the new database. This is hard decision to move from TinyDB to SQLite. But SQLite does provide a thread-safe access and TinyDB doesn't. I couldn't find a safe way to transfer the data, so you need to do them manually... Sorry about that :pensive:。 But I guess this would be a great start for future development :sunglasses:. - - -1. Change your directory to `wgdashboard` - - ```shell - cd wgdashboard/src - ``` - -2. Update the dashboard - ```shell - git pull https://github.com/donaldzou/WGDashboard.git --force - ``` - -3. Install - - ```shell - sudo ./wgd.sh install - ``` - -Starting with `v3.0`, you can simply do `sudo ./wgd.sh update` !! (I hope) - -## 🐬 Docker Solutions - -Current, we have 2 beloved contributors provided solutions for hosting WGDashboard with Docker - -### Solution 1 from @DaanSelen - -Please visit [Docker-explain.md](./docker/Docker-explain.md) - -### Solution 2 from @shuricksumy - -Please visit [shuricksumy/docker-wgdashboard](https://github.com/shuricksumy/docker-wgdashboard) - -> For questions or issues related to Docker, please visit [#272](https://github.com/donaldzou/WGDashboard/issues/272) - -## πŸ“– WGDashboard REST API Documentation & How to use API Key - -Please visit the [API Documentation](./docs/api-documents.md) - -## πŸ₯˜ Experimental Features - -### Cross-Server Access - -Starting with `v4.0`, you can access WGDashboards on other server through one WGDashboard with API Keys - -![Cross Server Example](https://donaldzou.nyc3.cdn.digitaloceanspaces.com/wgdashboard-images/cross-server.gif) - -### Desktop App - -Since the major changes for `v4.0` is to move the whole front-end code to Vue.js. And with this change, we can take the -advantage of combining ElectronJS and Vue.js to create a Desktop version of WGDashboard. Currently, we provide an Universal macOS app and a Windows app. - -To download the app, please visit the [latest release](https://github.com/donaldzou/WGDashboard/releases). - -![ElectronJS App Demo](https://donaldzou.nyc3.cdn.digitaloceanspaces.com/wgdashboard-images/electronjs-app.gif) - -## πŸ” Screenshot - -![Sign In](https://donaldzou.nyc3.cdn.digitaloceanspaces.com/wgdashboard-images/sign-in.png) -![Cross Server](https://donaldzou.nyc3.cdn.digitaloceanspaces.com/wgdashboard-images/cross-server.png) -![Index](https://donaldzou.nyc3.cdn.digitaloceanspaces.com/wgdashboard-images/index.png) -![New Configuration](https://donaldzou.nyc3.cdn.digitaloceanspaces.com/wgdashboard-images/new-configuration.png) -![Settings](https://donaldzou.nyc3.cdn.digitaloceanspaces.com/wgdashboard-images/settings.png) -![Light-Dark Mode](https://donaldzou.nyc3.cdn.digitaloceanspaces.com/wgdashboard-images/light-dark.png) -![Configuration](https://donaldzou.nyc3.cdn.digitaloceanspaces.com/wgdashboard-images/configuration.png) -![Add Peers](https://donaldzou.nyc3.cdn.digitaloceanspaces.com/wgdashboard-images/add-peers.png) -![Ping](https://donaldzou.nyc3.cdn.digitaloceanspaces.com/wgdashboard-images/ping.png) -![Traceroute](https://donaldzou.nyc3.cdn.digitaloceanspaces.com/wgdashboard-images/traceroute.png) - -## πŸ•°οΈ Changelogs - -Please visit the [Changelogs.md](./docs/changelogs.md) +> To better manage documentation for this project. I've moved it to its own [repo](https://github.com/donaldzou/WGDashboard-Documentation). I will keep updating over there and leave this README only with important information. + +- [πŸ’‘ Features](https://donaldzou.github.io/WGDashboard-Documentation/features.html) +- [πŸ“ Requirements](https://donaldzou.github.io/WGDashboard-Documentation/requirements.html) +- [πŸ›  Installο»Ώ](https://donaldzou.github.io/WGDashboard-Documentation/install.html) +- [πŸͺœ Usageο»Ώ](https://donaldzou.github.io/WGDashboard-Documentation/usage.html) +- [πŸ“– API Documentationο»Ώ](https://donaldzou.github.io/WGDashboard-Documentation/api-documentation.html) +- [And much more...](https://donaldzou.github.io/WGDashboard-Documentation/) diff --git a/docker/README.md b/docker/README.md index 19953c4..1c27200 100644 --- a/docker/README.md +++ b/docker/README.md @@ -93,7 +93,9 @@ To build the image yourself, you need to do a couple things:
1. Clone the Github repository containing the source code of WGDashboard including the docker directory. For example do: `git clone https://github.com/donaldzou/WGDashboard.git` 1. Navigate into the cloned repository. 1. (Make sure you have Docker correctly installed, if not: [Click here](https://docs.docker.com/engine/install/)) and run: `docker build . -t :` as an example: `docker build . -t dselen/wgdashboard:latest`.
- This will make Docker compile the image from the resources in the directory you mention, in this case the source/root one. Let it compile, it takes only a couple seconds with a minute at most. + +This will make Docker compile the image from the resources in the directory you mention, in this case the source/root one. Let it compile, it takes only a couple seconds with a minute at most. + 1. If all went well, see your image with `docker images`. Example below: ```shell diff --git a/docker/compose.yaml b/docker/compose.yaml index f003d6b..2512aea 100644 --- a/docker/compose.yaml +++ b/docker/compose.yaml @@ -6,6 +6,10 @@ services: environment: - tz=Europe/Amsterdam # <--- Set container timezone, default: Europe/Amsterdam. - global_dns=9.9.9.9 # <--- Set global DNS address, default: 1.1.1.1. + + #- tz= # <--- Set container timezone, default: Europe/Amsterdam. + #- global_dns= # <--- Set global DNS address, default: 1.1.1.1. + #- enable= # <--- Set the interfaces that will be enabled on startup, default: 'none'. #- isolate= # <--- Set the interfaces that will disallow peer communication, default: 'none'. #- public_ip= # <--- Set public IP to ensure the correct one is chosen, defaulting to the IP give by ifconfig.me. diff --git a/entrypoint.sh b/entrypoint.sh index 537d6e3..4c23130 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -147,11 +147,13 @@ start_core() { break else + if [ ! -f "/etc/wireguard/${interface}.conf" ]; then echo "Ignoring ${interface}" elif [ -f "/etc/wireguard/${interface}.conf" ]; then + echo "Isolating interface:" "$interface" upblocking=$(grep -c "PostUp = iptables -I FORWARD -i ${interface} -o ${interface} -j DROP" /etc/wireguard/"${interface}".conf) @@ -172,12 +174,14 @@ start_core() { # Removing isolation for the configurations that did not match. + for interface in "${non_isolate[@]}"; do if [ ! -f "/etc/wireguard/${interface}.conf" ]; then echo "Ignoring ${interface}" elif [ -f "/etc/wireguard/${interface}.conf" ]; then + echo "Removing isolation, if isolation is present for:" "$interface" sed -i "/PostUp = iptables -I FORWARD -i ${interface} -o ${interface} -j DROP/d" /etc/wireguard/"${interface}".conf diff --git a/src/dashboard.py b/src/dashboard.py index dca3030..5d32b53 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -1500,7 +1500,9 @@ def _regexMatch(regex, text): return pattern.search(text) is not None def _getConfigurationList(startup: bool = False): - for i in os.listdir(DashboardConfig.GetConfig("Server", "wg_conf_path")[1]): + confs = os.listdir(DashboardConfig.GetConfig("Server", "wg_conf_path")[1]) + confs.sort() + for i in confs: if _regexMatch("^(.{1,}).(conf)$", i): i = i.replace('.conf', '') try: @@ -1618,8 +1620,11 @@ def sqlSelect(statement: str, paramters: tuple = ()) -> sqlite3.Cursor: try: cursor = sqldb.cursor() return cursor.execute(statement, paramters) + except sqlite3.OperationalError as error: print("[WGDashboard] SQLite Error:" + str(error) + " | Statement: " + statement) + return [] + def sqlUpdate(statement: str, paramters: tuple = ()) -> sqlite3.Cursor: with sqldb: diff --git a/src/iptable-rules/postdown.sh b/src/iptable-rules/postdown.sh deleted file mode 100644 index 962772a..0000000 --- a/src/iptable-rules/postdown.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -WIREGUARD_INTERFACE=ADMINS -WIREGUARD_LAN=10.0.0.1/24 -MASQUERADE_INTERFACE=eth0 - -CHAIN_NAME="WIREGUARD_$WIREGUARD_INTERFACE" - -iptables -t nat -D POSTROUTING -o $MASQUERADE_INTERFACE -j MASQUERADE -s $WIREGUARD_LAN - -# Remove and delete the WIREGUARD_wg0 chain -iptables -D FORWARD -j $CHAIN_NAME -iptables -F $CHAIN_NAME -iptables -X $CHAIN_NAME \ No newline at end of file diff --git a/src/iptable-rules/postup.sh b/src/iptable-rules/postup.sh deleted file mode 100644 index 0fc8b87..0000000 --- a/src/iptable-rules/postup.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -WIREGUARD_INTERFACE=ADMINS -WIREGUARD_LAN=10.0.0.1/24 -MASQUERADE_INTERFACE=eth0 - -iptables -t nat -I POSTROUTING -o $MASQUERADE_INTERFACE -j MASQUERADE -s $WIREGUARD_LAN - -# Add a WIREGUARD_wg0 chain to the FORWARD chain -CHAIN_NAME="WIREGUARD_$WIREGUARD_INTERFACE" -iptables -N $CHAIN_NAME -iptables -A FORWARD -j $CHAIN_NAME - -# Accept related or established traffic -iptables -A $CHAIN_NAME -o $WIREGUARD_INTERFACE -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT - -# Accept traffic from any Wireguard IP address connected to the Wireguard server -iptables -A $CHAIN_NAME -s $WIREGUARD_LAN -i $WIREGUARD_INTERFACE -j ACCEPT - -# Allow traffic to the local loopback interface -iptables -A $CHAIN_NAME -o lo -j ACCEPT - -# Drop everything else coming through the Wireguard interface -iptables -A $CHAIN_NAME -i $WIREGUARD_INTERFACE -j DROP - -# Return to FORWARD chain -iptables -A $CHAIN_NAME -j RETURN \ No newline at end of file diff --git a/src/wgd.sh b/src/wgd.sh index 845b9c7..22e1d25 100755 --- a/src/wgd.sh +++ b/src/wgd.sh @@ -66,7 +66,7 @@ _determineOS(){ elif [ -f /etc/redhat-release ]; then OS="redhat" else - printf "[WGDashboard] %s Sorry, your OS is not supported. Currently the install script only support Debian-based, Red Hat-based OS." "$heavy_crossmark" + printf "[WGDashboard] %s Sorry, your OS is not supported. Currently the install script only support Debian-based, Red Hat-based OS. With experimental support for Alpine Linux.\n" "$heavy_crossmark" printf "%s\n" "$helpMsg" kill $TOP_PID fi @@ -78,7 +78,7 @@ _installPython(){ ubuntu|debian) { sudo apt update ; sudo apt-get install -y python3 net-tools; printf "\n\n"; } &>> ./log/install.txt ;; - centos|fedora|redhat|rehl) + centos|fedora|redhat|rhel|almalinux|rocky) if command -v dnf &> /dev/null; then { sudo dnf install -y python3 net-tools; printf "\n\n"; } >> ./log/install.txt else @@ -86,8 +86,8 @@ _installPython(){ fi ;; alpine) - { apk update; apk add python3 net-tools; printf "\n\n"; } &>> ./log/install.txt - ;; + { sudo apk update; sudo apk add python3 net-tools --no-cache; printf "\n\n"; } >> ./log/install.txt + ;; esac if ! python3 --version > /dev/null 2>&1 @@ -106,7 +106,7 @@ _installPythonVenv(){ ubuntu|debian) { sudo apt update ; sudo apt-get install -y python3-venv; printf "\n\n"; } &>> ./log/install.txt ;; - centos|fedora|redhat|rhel) + centos|fedora|redhat|rhel|almalinux|rocky) if command -v dnf &> /dev/null; then { sudo dnf install -y python3-virtualenv; printf "\n\n"; } >> ./log/install.txt else @@ -114,10 +114,10 @@ _installPythonVenv(){ fi ;; alpine) - { apk add python3 py3-virtualenv; printf "\n\n"; } &>> ./log/install.txt + { sudo apk update; sudo apk add py3-virtualenv ; printf "\n\n"; } >> ./log/install.txt ;; *) - printf "[WGDashboard] %s Sorry, your OS is not supported. Currently the install script only support Debian-based, Red Hat-based OS.\n" "$heavy_crossmark" + printf "[WGDashboard] %s Sorry, your OS is not supported. Currently the install script only support Debian-based, Red Hat-based OS. With experimental support for Alpine Linux.\n" "$heavy_crossmark" printf "%s\n" "$helpMsg" kill $TOP_PID ;; @@ -140,7 +140,6 @@ _installPythonVenv(){ } _installPythonPip(){ - if ! $pythonExecutable -m pip -h > /dev/null 2>&1 then case "$OS" in @@ -151,7 +150,7 @@ _installPythonPip(){ { sudo apt update ; sudo apt-get install -y ${pythonExecutable}-distutil python3-pip; printf "\n\n"; } &>> ./log/install.txt fi ;; - centos|fedora|redhat|rhel) + centos|fedora|redhat|rhel|almalinux|rocky) if [ "$pythonExecutable" = "python3" ]; then { sudo dnf install -y python3-pip; printf "\n\n"; } >> ./log/install.txt else @@ -159,10 +158,10 @@ _installPythonPip(){ fi ;; alpine) - { apk add py3-pip; printf "\n\n"; } &>> ./log/install.txt + { sudo apk update; sudo apk add py3-pip --no-cache; printf "\n\n"; } >> ./log/install.txt ;; *) - printf "[WGDashboard] %s Sorry, your OS is not supported. Currently the install script only support Debian-based, Red Hat-based OS.\n" "$heavy_crossmark" + printf "[WGDashboard] %s Sorry, your OS is not supported. Currently the install script only support Debian-based, Red Hat-based OS. With experimental support for Alpine Linux.\n" "$heavy_crossmark" printf "%s\n" "$helpMsg" kill $TOP_PID ;; @@ -180,20 +179,41 @@ _installPythonPip(){ } _checkWireguard(){ - if ! wg -h > /dev/null 2>&1 - then - printf "[WGDashboard] %s WireGuard is not installed. Please follow instruction on https://www.wireguard.com/install/ to install. \n" "$heavy_crossmark" - kill $TOP_PID - fi - if ! wg-quick -h > /dev/null 2>&1 - then - printf "[WGDashboard] %s WireGuard is not installed. Please follow instruction on https://www.wireguard.com/install/ to install. \n" "$heavy_crossmark" - kill $TOP_PID - fi + if ! command -v wg > /dev/null 2>&1 || ! command -v wg-quick > /dev/null 2>&1 + then + case "$OS" in + ubuntu|debian) + { + sudo apt update && sudo apt-get install -y wireguard; + printf "\n[WGDashboard] WireGuard installed on %s.\n\n" "$OS"; + } &>> ./log/install.txt + ;; + centos|fedora|redhat|rhel|almalinux|rocky) + { + sudo dnf install -y wireguard-tools; + printf "\n[WGDashboard] WireGuard installed on %s.\n\n" "$OS"; + } &>> ./log/install.txt + ;; + alpine) + { + sudo apk update && sudo apk add wireguard-tools --no-cache; + printf "\n[WGDashboard] WireGuard installed on %s.\n\n" "$OS"; + } &>> ./log/install.txt + ;; + *) + printf "[WGDashboard] %s Sorry, your OS is not supported. Currently, the install script only supports Debian-based, Red Hat-based, and Alpine Linux.\n" "$heavy_crossmark" + printf "%s\n" "$helpMsg" + kill $TOP_PID + ;; + esac + else + printf "[WGDashboard] WireGuard is already installed.\n" + fi } + _checkPythonVersion(){ version_pass=$($pythonExecutable -c 'import sys; print("1") if (sys.version_info.major == 3 and sys.version_info.minor >= 10) else print("0");') version=$($pythonExecutable --version) @@ -221,8 +241,6 @@ _checkPythonVersion(){ install_wgd(){ printf "[WGDashboard] Starting to install WGDashboard\n" - _checkWireguard - sudo chmod -R 755 /etc/wireguard/ if [ ! -d "/etc/wireguard/WGDashboard_Backup" ] then @@ -247,6 +265,8 @@ install_wgd(){ _checkPythonVersion _installPythonVenv _installPythonPip + _checkWireguard + sudo chmod -R 755 /etc/wireguard/ if [ ! -d "db" ] then @@ -258,7 +278,7 @@ install_wgd(){ { date; python3 -m ensurepip --upgrade; printf "\n\n"; } >> ./log/install.txt { date; python3 -m pip install --upgrade pip; printf "\n\n"; } >> ./log/install.txt printf "[WGDashboard] Installing latest Python dependencies\n" - { date; python3 -m pip install -r requirements.txt ; printf "\n\n"; } >> ./log/install.txt + { date; python3 -m pip install -r requirements.txt ; printf "\n\n"; } >> ./log/install.txt #This all works on the default installation. printf "[WGDashboard] WGDashboard installed successfully!\n" printf "[WGDashboard] Enter ./wgd.sh start to start the dashboard\n" } @@ -336,14 +356,6 @@ startwgd_docker() { } start_core() { - local iptable_dir="/opt/wireguarddashboard/src/iptable-rules" - # Check if wg0.conf exists in /etc/wireguard - if [[ ! -f /etc/wireguard/wg0.conf ]]; then - echo "[WGDashboard][Docker] wg0.conf not found. Running generate configuration." - newconf_wgd - else - echo "[WGDashboard][Docker] wg0.conf already exists. Skipping WireGuard configuration generation." - fi # Re-assign config_files to ensure it includes any newly created configurations local config_files=$(find /etc/wireguard -type f -name "*.conf") @@ -400,20 +412,29 @@ update_wgd() { new_ver=$($venv_python -c "import json; import urllib.request; data = urllib.request.urlopen('https://api.github.com/repos/donaldzou/WGDashboard/releases/latest').read(); output = json.loads(data);print(output['tag_name'])") printf "%s\n" "$dashes" - printf "[WGDashboard] Are you sure you want to update to the %s? (Y/N): " "$new_ver" - read up + + if [ "$commandConfirmed" = "true" ]; then + printf "[WGDashboard] Confirmation granted.\n" + up="Y" + else + printf "[WGDashboard] Are you sure you want to update to the %s? (Y/N): " "$new_ver" + read up + fi + if [ "$up" = "Y" ] || [ "$up" = "y" ]; then printf "[WGDashboard] Shutting down WGDashboard\n" + if check_wgd_status; then stop_wgd fi - mv wgd.sh wgd.sh.old - printf "[WGDashboard] Downloading %s from GitHub..." "$new_ver" - { date; git stash; git pull https://github.com/donaldzou/WGDashboard.git $new_ver --force; } >> ./log/update.txt - chmod +x ./wgd.sh - sudo ./wgd.sh install - printf "[WGDashboard] Update completed!\n" - printf "%s\n" "$dashes" + + mv wgd.sh wgd.sh.old && \ + printf "[WGDashboard] Downloading %s from GitHub..." "$new_ver" && \ + { date; git stash; git pull https://github.com/donaldzou/WGDashboard.git $new_ver --force; } >> ./log/update.txt && \ + chmod +x ./wgd.sh && \ + sudo ./wgd.sh install && \ + printf "[WGDashboard] Update completed!\n" && \ + printf "%s\n" "$dashes"; \ rm wgd.sh.old else printf "%s\n" "$dashes" @@ -422,56 +443,55 @@ update_wgd() { fi } -if [ "$#" != 1 ]; - then - help - else - if [ "$1" = "start" ]; then - if check_wgd_status; then - printf "%s\n" "$dashes" - printf "[WGDashboard] WGDashboard is already running.\n" - printf "%s\n" "$dashes" - else - start_wgd - fi - elif [ "$1" = "docker_start" ]; then - printf "%s\n" "$dashes" - startwgd_docker - printf "%s\n" "$dashes" - elif [ "$1" = "stop" ]; then - if check_wgd_status; then - printf "%s\n" "$dashes" - stop_wgd - printf "[WGDashboard] WGDashboard is stopped.\n" - printf "%s\n" "$dashes" - else - printf "%s\n" "$dashes" - printf "[WGDashboard] WGDashboard is not running.\n" - printf "%s\n" "$dashes" - fi - elif [ "$1" = "update" ]; then - update_wgd - elif [ "$1" = "install" ]; then - printf "%s\n" "$dashes" - install_wgd - printf "%s\n" "$dashes" - elif [ "$1" = "restart" ]; then - if check_wgd_status; then - printf "%s\n" "$dashes" - stop_wgd - printf "[WGDashboard] WGDashboard is stopped.\n" - sleep 4 - start_wgd - else - start_wgd - fi - elif [ "$1" = "debug" ]; then - if check_wgd_status; then - printf "[WGDashboard] WGDashboard is already running.\n" - else - start_wgd_debug - fi - else - help +if [ "$#" -lt 1 ]; then + help +else + if [ "$2" = "-y" ] || [ "$2" = "-Y" ]; then + commandConfirmed="true" + fi + + if [ "$1" = "start" ]; then + if check_wgd_status; then + printf "%s\n" "$dashes" + printf "[WGDashboard] WGDashboard is already running.\n" + printf "%s\n" "$dashes" + else + start_wgd fi -fi \ No newline at end of file + elif [ "$1" = "stop" ]; then + if check_wgd_status; then + printf "%s\n" "$dashes" + stop_wgd + printf "[WGDashboard] WGDashboard is stopped.\n" + printf "%s\n" "$dashes" + else + printf "%s\n" "$dashes" + printf "[WGDashboard] WGDashboard is not running.\n" + printf "%s\n" "$dashes" + fi + elif [ "$1" = "update" ]; then + update_wgd + elif [ "$1" = "install" ]; then + printf "%s\n" "$dashes" + install_wgd + printf "%s\n" "$dashes" + elif [ "$1" = "restart" ]; then + if check_wgd_status; then + printf "%s\n" "$dashes" + stop_wgd + printf "| WGDashboard is stopped. |\n" + sleep 4 + start_wgd + else + start_wgd + fi + elif [ "$1" = "debug" ]; then + if check_wgd_status; then + printf "| WGDashboard is already running. |\n" + else + start_wgd_debug + fi + else + help + fi +fi