An open API service indexing awesome lists of open source software.

https://github.com/friedjof/wireguardadmin

A modern web interface for managing WireGuard VPNs with live status, firewall management, and real-time updates.
https://github.com/friedjof/wireguardadmin

admin api deshboard docker firewall flask iptables linux management monitoring network peer python realtime security vpn webinterface websocket wireguard

Last synced: 3 months ago
JSON representation

A modern web interface for managing WireGuard VPNs with live status, firewall management, and real-time updates.

Awesome Lists containing this project

README

          

# ๐Ÿ” WireGuard Management System

[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
[![Python 3.12+](https://img.shields.io/badge/python-3.12+-blue.svg)](https://www.python.org/downloads/)
[![Docker](https://img.shields.io/badge/docker-%230db7ed.svg?style=flat&logo=docker&logoColor=white)](https://www.docker.com/)
[![Flask](https://img.shields.io/badge/flask-%23000.svg?style=flat&logo=flask&logoColor=white)](https://flask.palletsprojects.com/)
[![CI/CD](https://img.shields.io/badge/CI%2FCD-GitHub%20Actions-green.svg)](https://github.com/features/actions)
[![Tests](https://img.shields.io/badge/Tests-Pytest-orange.svg)](https://pytest.org/)
[![Code Style](https://img.shields.io/badge/Code%20Style-Black-black.svg)](https://black.readthedocs.io/)

A professional, enterprise-ready web application for managing WireGuard VPN peers with **real-time monitoring**, **advanced firewall management**, and **WebSocket-powered live updates**.

> โš ๏ธ **Development Status**: This project is actively under development. The firewall management and VPN functionality are experimental and may contain bugs. Use with caution in production environments.

## โœจ **Key Features**

### ๐Ÿš€ **Real-Time Monitoring**
- **Live Status Updates** via WebSockets (2-second intervals)
- **Traffic Graphs** showing upload/download rates for last 40 seconds
- **Connection Monitoring** with visual indicators
- **Automatic Reconnection** with fallback to HTTP polling

### ๐Ÿ‘ฅ **Advanced Peer Management**
- **Auto-IP Assignment** with conflict detection
- **Bulk Operations** with validation
- **Multiple Allowed IPs** with descriptions
- **QR Code Generation** for mobile devices
- **Configuration Export** (file download + API)

### ๐Ÿ›ก๏ธ **Enterprise Firewall Management** โš ๏ธ *Experimental*
- **iptables Integration** with rule preview
- **Security Templates** (Admin, Guest, Restricted, etc.)
- **Custom Rule Builder** with priorities
- **Terminal-Style Interface** for rule management
- **Dry-Run Testing** before applying rules
- *Note: Firewall features are experimental and may require manual intervention*

### ๐Ÿ”ง **Professional Architecture**
- **REST API** with full CRUD operations
- **WebSocket Events** for real-time communication
- **Docker Support** with production-ready setup
- **Modular Design** with separated concerns
- **Comprehensive Logging** and error handling

## ๐ŸŽฏ **Quick Start**

### **Using Make Commands (Recommended)**

```bash
# Clone repository
git clone https://github.com/Friedjof/WireguardAdmin.git
cd wireguard-management

# Show all available commands
make help

# Setup development environment
make setup

# Run tests and linting
make check

# Start development server
make dev
```

### **Docker Deployment**

```bash
# Configure environment
cp .env.example .env
# Edit .env with your server details

# Build and start with Docker
make build
make up

# Check status
make status

# Access web interface
open http://localhost:5000
```

### **Manual Installation**

```bash
# Install system dependencies
sudo apt update
sudo apt install wireguard-tools iptables python3 python3-pip

# Clone and setup
git clone https://github.com/Friedjof/WireguardAdmin.git
cd wireguard-management

# Setup with Make
make setup

# Or manually
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

# Configure environment
cp .env.example .env
# Edit .env with your configuration

# Run application
python app.py
```

## ๐Ÿ“Š **Screenshots & Demo**

๐Ÿ–ผ๏ธ **Click to view screenshots**

### Dashboard with Real-Time Monitoring
![Dashboard](docs/images/dashboard.png)

### Peer Details with Traffic Graph
![Peer Details](docs/images/peer-details.png)

### Firewall Management Console
![Firewall Console](docs/images/firewall-console.png)

### Mobile QR Code Setup
![QR Code](docs/images/qr-code.png)

## ๐Ÿ—๏ธ **Architecture**

```
wireguard-management/
โ”œโ”€โ”€ ๐Ÿ“ app/ # Core application
โ”‚ โ”œโ”€โ”€ ๐Ÿ __init__.py # Flask app & WebSocket setup
โ”‚ โ”œโ”€โ”€ ๐Ÿ—ƒ๏ธ models.py # Database models
โ”‚ โ”œโ”€โ”€ ๐Ÿ›ฃ๏ธ routes.py # Web routes & API endpoints
โ”‚ โ”œโ”€โ”€ โš™๏ธ utils.py # Utility functions
โ”‚ โ”œโ”€โ”€ ๐Ÿ”ฅ iptables_manager.py # Firewall management
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ก websocket_manager.py # Real-time updates
โ”‚ โ”œโ”€โ”€ ๐Ÿ”Œ websocket_events.py # WebSocket event handlers
โ”‚ โ””โ”€โ”€ ๐Ÿ“Š wireguard_status.py # Status monitoring
โ”œโ”€โ”€ ๐Ÿ“ static/ # Frontend assets
โ”‚ โ”œโ”€โ”€ ๐ŸŽจ css/ # Stylesheets
โ”‚ โ””โ”€โ”€ โšก js/ # JavaScript modules
โ”œโ”€โ”€ ๐Ÿ“ templates/ # Jinja2 templates
โ”œโ”€โ”€ ๐Ÿ“ docker/ # Docker configuration
โ”œโ”€โ”€ ๐Ÿ“ docs/ # Documentation
โ”œโ”€โ”€ ๐Ÿ“ scripts/ # Utility scripts
โ””โ”€โ”€ ๐Ÿณ docker-compose.yml # Production setup
```

## ๐Ÿ”Œ **API Reference**

### **Peer Management**
```http
GET /api/v1/peers # List all peers
POST /api/v1/peers # Create new peer
GET /api/v1/peers/{id} # Get peer details
PUT /api/v1/peers/{id} # Update peer
DELETE /api/v1/peers/{id} # Delete peer
POST /api/v1/peers/{id}/toggle # Toggle peer status
```

### **Real-Time WebSocket Events**
```javascript
// Connect to WebSocket
const socket = io();

// Listen for real-time updates
socket.on('peer_status_update', (data) => {
// data.data contains all peer statuses
// data.data[peerId].graph_data contains traffic history
});

// Activate/deactivate peers
socket.emit('peer_action', {
peer_id: 123,
action: 'activate' // or 'deactivate'
});
```

### **Firewall Management**
```http
GET /api/v1/firewall/status # Check iptables access
GET /api/v1/firewall/rules/generate # Preview generated rules
POST /api/v1/firewall/rules/apply # Apply rules to system
POST /api/v1/firewall/backup # Backup current rules
```

## ๐Ÿ›ก๏ธ **Security Features**

> โš ๏ธ **Security Notice**: This application manages critical network infrastructure. The firewall and VPN features are experimental and should be thoroughly tested before production use. Always maintain backup access to your server.

### **Built-in Security**
- โœ… **Input Validation** with SQLAlchemy ORM protection
- โœ… **Rate Limiting** on API endpoints
- โœ… **CSRF Protection** on forms
- โœ… **Secure Headers** with Flask-Talisman
- โœ… **Environment-based Secrets** (no hardcoded keys)

### **Network Security** โš ๏ธ *Experimental*
- โš ๏ธ **iptables Integration** with custom rules *(may require manual fixes)*
- โš ๏ธ **Firewall Templates** for different security levels *(test thoroughly)*
- โš ๏ธ **Peer Isolation** options *(experimental feature)*
- โœ… **Traffic Monitoring** and logging

### **Production Deployment**
- โœ… **Docker Security** with non-root user
- โœ… **Reverse Proxy** support (nginx/Traefik)
- โœ… **SSL/TLS** certificate integration
- โœ… **Environment Isolation** with Docker networks

## โš™๏ธ **Configuration**

### **Environment Variables**

| Variable | Description | Default | Required |
|----------|-------------|---------|----------|
| `SERVER_PUBLIC_IP` | Your server's public IP/domain | - | โœ… |
| `SERVER_PRIVATE_KEY` | WireGuard server private key | - | โœ… |
| `SERVER_PUBLIC_KEY` | WireGuard server public key | - | โœ… |
| `LISTEN_PORT` | WireGuard listen port | `51820` | โŒ |
| `VPN_SUBNET` | VPN internal network | `10.0.0.0/24` | โŒ |
| `FLASK_ENV` | Flask environment | `production` | โŒ |

### **Docker Configuration**

```yaml
# docker-compose.yml
services:
vpn-manager:
build: .
ports:
- "5000:5000" # Web interface
- "51820:51820/udp" # WireGuard
environment:
- SERVER_PUBLIC_IP=your-server.com
- SERVER_PRIVATE_KEY=your_private_key
- SERVER_PUBLIC_KEY=your_public_key
volumes:
- ./instance:/app/instance # Database persistence
- ./logs:/app/logs # Logs
- ./backups:/app/backups # Backups
```

## ๐Ÿ”ง **Development**

### **Quick Development Setup**

```bash
# Clone repository
git clone https://github.com/Friedjof/WireguardAdmin.git
cd wireguard-management

# Complete setup with one command
make setup

# Show all available commands
make help
```

### **Development Commands**

#### **๐Ÿ”ง Setup & Development**
```bash
make setup # Setup development environment
make install # Install dependencies (alias for setup)
make dev # Start development server
make clean # Clean up development environment
```

#### **๐Ÿงช Testing & Quality**
```bash
make test # Run all tests
make test-watch # Run tests in watch mode
make lint # Run linting checks (dry-run)
make format # Format code with Black
make check # Run all checks (lint + test)
```

#### **๐Ÿณ Docker Operations**
```bash
make build # Build Docker container
make up # Start system (Docker)
make down # Stop system (Docker)
make logs # Show container logs
make shell # Open shell in container
make restart # Restart system
make docker-clean # Clean Docker resources
```

#### **๐Ÿ“Š Monitoring & Operations**
```bash
make status # Show system status
make keys # Show WireGuard server keys
make backup # Create backup of configuration
```

### **CI/CD Pipeline**

The project includes automated CI/CD with GitHub Actions:

- **Automated Testing**: All tests run on every push
- **Code Quality**: Flake8 linting and Black formatting checks
- **Release Automation**: Docker images built on version tags (`v*`)
- **Container Registry**: Images pushed to GitHub Container Registry

#### **Release Process**
```bash
# Create and push a release tag
git tag v1.0.0
git push origin v1.0.0

# This automatically triggers:
# 1. Run tests and linting
# 2. Build Docker image
# 3. Push to registry
# 4. Create GitHub release
```

## ๐Ÿ“‹ **Requirements**

### **System Requirements**
- **Linux Server** (Ubuntu 22.04+ recommended)
- **WireGuard Tools** (`wireguard-tools` package)
- **iptables** (for firewall management)
- **Docker** and **Docker Compose** (for containerized deployment)
- **Make** (for development commands)

### **Python Requirements**
- **Python 3.12+**
- **pytest** (testing framework)
- **flake8** (code linting)
- **black** (code formatting)
- See `requirements.txt` for complete list

### **Network Requirements**
- **Open Port 51820/UDP** (WireGuard)
- **Open Port 5000/TCP** (Web interface, can be proxied)
- **Root Access** (for WireGuard and iptables management)

## ๐Ÿค **Contributing**

We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.

### **Development Workflow**
1. **Fork** the repository
2. **Create** a feature branch (`git checkout -b feature/amazing-feature`)
3. **Commit** your changes (`git commit -m 'Add amazing feature'`)
4. **Push** to the branch (`git push origin feature/amazing-feature`)
5. **Open** a Pull Request

### **Bug Reports**
Please use the [GitHub Issues](https://github.com/Friedjof/WireguardAdmin/issues) for bug reports and feature requests.

## ๐Ÿ“„ **License**

This project is licensed under the **GNU General Public License v3.0** - see the [LICENSE](LICENSE) file for details.

## ๐Ÿ™ **Acknowledgments**

- **WireGuard** team for the amazing VPN technology
- **Flask** community for the excellent web framework
- **Bootstrap** team for the responsive UI components
- **Chart.js** for beautiful traffic visualization
- **Socket.IO** for real-time communication

## ๐Ÿ“ž **Support**

- ๐Ÿ“– **Documentation**: [Wiki](https://github.com/Friedjof/WireguardAdmin/wiki)
- ๐Ÿ› **Bug Reports**: [Issues](https://github.com/Friedjof/WireguardAdmin/issues)
- ๐Ÿ’ฌ **Discussions**: [GitHub Discussions](https://github.com/Friedjof/WireguardAdmin/discussions)
- ๐Ÿ“ง **Email**: dev@noweck.info

---

โญ **Star this repository if it helped you!**

Made with โค๏ธ by [Friedjof](https://github.com/Friedjof)