installer: stabilize WebUI install (copy local frontend or minimal placeholder), fix heredoc corruption; ensure backend/frontend copied from repo; handle Mullvad repo codename robustly; make gpg import non-interactive
This commit is contained in:
parent
405a9955d9
commit
a5e4c68017
1 changed files with 35 additions and 214 deletions
245
install.sh
245
install.sh
|
@ -10,6 +10,8 @@
|
|||
#############################################################
|
||||
|
||||
set -e # Exit on error
|
||||
# Determine script directory (for copying local backend/frontend)
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
|
@ -627,12 +629,12 @@ install_mullvad() {
|
|||
|
||||
# Add Mullvad repository
|
||||
# Determine codename safely
|
||||
CODENAME="$(lsb_release -cs 2>/dev/null || . /etc/os-release 2>/dev/null && echo "$VERSION_CODENAME")"
|
||||
CODENAME=$(lsb_release -cs 2>/dev/null || { . /etc/os-release 2>/dev/null; echo "$VERSION_CODENAME"; } )
|
||||
[ -z "$CODENAME" ] && CODENAME="stable"
|
||||
echo "deb [signed-by=/usr/share/keyrings/mullvad-keyring.gpg arch=$( dpkg --print-architecture )] https://repository.mullvad.net/deb/stable $CODENAME main" | tee /etc/apt/sources.list.d/mullvad.list
|
||||
|
||||
# Update and install
|
||||
apt-get update &>/dev/null
|
||||
# Update and install (don't abort on failure)
|
||||
apt-get update &>/dev/null || warning "apt-get update failed for Mullvad repo; continuing"
|
||||
apt-get install -y mullvad-vpn &>/dev/null || {
|
||||
warning "Could not install Mullvad client, using WireGuard directly"
|
||||
}
|
||||
|
@ -748,45 +750,24 @@ install_backend() {
|
|||
pip install --upgrade pip &>/dev/null
|
||||
pip install flask flask-cors requests gunicorn pyyaml &>/dev/null
|
||||
|
||||
# Download or create the multi-provider backend
|
||||
# For production, this would be downloaded from GitHub
|
||||
# Here we create it inline for the complete solution
|
||||
|
||||
# Install backend from repo if available, else fallback to local backend/
|
||||
log "Installing multi-provider backend..."
|
||||
|
||||
# The backend app.py would be downloaded from GitHub in production:
|
||||
# wget -O "$INSTALL_DIR/app.py" "$GITHUB_REPO/app.py"
|
||||
|
||||
# For now, we use a simplified version that supports all providers
|
||||
cat > "$INSTALL_DIR/app.py" << 'EOFAPP'
|
||||
if [ -f "$SCRIPT_DIR/backend/app.py" ]; then
|
||||
cp "$SCRIPT_DIR/backend/app.py" "$INSTALL_DIR/app.py"
|
||||
else
|
||||
# Fallback minimal app
|
||||
cat > "$INSTALL_DIR/app.py" << 'EOFAPP'
|
||||
#!/usr/bin/env python3
|
||||
# Multi-Provider VPN Backend
|
||||
# This is a placeholder - in production, use the full backend from the artifact
|
||||
# Download from: https://github.com/yourusername/vpn-gateway/blob/main/backend/app.py
|
||||
|
||||
from flask import Flask, request, jsonify, send_from_directory
|
||||
from flask_cors import CORS
|
||||
import subprocess
|
||||
import json
|
||||
import os
|
||||
import logging
|
||||
|
||||
from flask import Flask
|
||||
app = Flask(__name__)
|
||||
CORS(app)
|
||||
|
||||
# ... (Full backend code would be here)
|
||||
# For production, download the complete multi-provider backend
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return send_from_directory('__INSTALL_DIR__/static', 'index.html')
|
||||
|
||||
return 'VPN Gateway running'
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0', port=5000)
|
||||
EOFAPP
|
||||
|
||||
# Replace placeholders
|
||||
sed -i "s|__INSTALL_DIR__|$INSTALL_DIR|g" "$INSTALL_DIR/app.py"
|
||||
fi
|
||||
|
||||
log "Backend installed"
|
||||
}
|
||||
|
@ -794,187 +775,27 @@ EOFAPP
|
|||
# Install WebUI
|
||||
install_webui() {
|
||||
log "Installing WebUI..."
|
||||
|
||||
# Download WebUI from GitHub or create inline
|
||||
cat > "$INSTALL_DIR/static/index.html" << 'EOFHTML'
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>VPN Gateway Control</title>
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 20px;
|
||||
}
|
||||
.container {
|
||||
background: rgba(255, 255, 255, 0.95);
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
|
||||
max-width: 800px;
|
||||
width: 100%;
|
||||
padding: 40px;
|
||||
}
|
||||
h1 { text-align: center; margin-bottom: 30px; }
|
||||
.status-card {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 30px;
|
||||
border-radius: 15px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
select, button {
|
||||
width: 100%;
|
||||
padding: 15px;
|
||||
margin: 10px 0;
|
||||
border-radius: 10px;
|
||||
font-size: 16px;
|
||||
}
|
||||
button {
|
||||
background: linear-gradient(135deg, #4ade80 0%, #22c55e 100%);
|
||||
color: white;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
button:hover { transform: translateY(-2px); }
|
||||
.btn-disconnect {
|
||||
background: linear-gradient(135deg, #f87171 0%, #ef4444 100%);
|
||||
}
|
||||
.security-notice {
|
||||
background: #4ade80;
|
||||
color: white;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>🔐 VPN Gateway Control</h1>
|
||||
|
||||
<div class="security-notice">
|
||||
<strong>🛡️ Security Status: PROTECTED</strong><br>
|
||||
✓ Killswitch permanently active<br>
|
||||
✓ No internet without VPN
|
||||
</div>
|
||||
|
||||
<div class="status-card">
|
||||
<h2>Status: <span id="status">Checking...</span></h2>
|
||||
<p>IP: <span id="ip">-</span></p>
|
||||
<p>Location: <span id="location">-</span></p>
|
||||
</div>
|
||||
|
||||
<select id="countrySelect" onchange="updateCities()">
|
||||
<option>Loading countries...</option>
|
||||
</select>
|
||||
|
||||
<select id="citySelect" onchange="updateServers()">
|
||||
<option>Select country first</option>
|
||||
</select>
|
||||
|
||||
<select id="serverSelect">
|
||||
<option>Select city first</option>
|
||||
</select>
|
||||
|
||||
<button onclick="connectVPN()">Connect</button>
|
||||
<button class="btn-disconnect" onclick="disconnectVPN()">Disconnect</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let servers = {};
|
||||
|
||||
async function loadServers() {
|
||||
const response = await fetch('/api/servers');
|
||||
const data = await response.json();
|
||||
servers = data.servers;
|
||||
|
||||
const countrySelect = document.getElementById('countrySelect');
|
||||
countrySelect.innerHTML = '<option value="">Select country</option>';
|
||||
Object.keys(servers).forEach(country => {
|
||||
countrySelect.innerHTML += '<option value="' + country + '">' + country + '</option>';
|
||||
});
|
||||
}
|
||||
|
||||
function updateCities() {
|
||||
const country = document.getElementById('countrySelect').value;
|
||||
const citySelect = document.getElementById('citySelect');
|
||||
|
||||
if (country && servers[country]) {
|
||||
citySelect.innerHTML = '<option value="">Select city</option>';
|
||||
Object.keys(servers[country]).forEach(city => {
|
||||
citySelect.innerHTML += '<option value="' + city + '">' + city + '</option>';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function updateServers() {
|
||||
const country = document.getElementById('countrySelect').value;
|
||||
const city = document.getElementById('citySelect').value;
|
||||
const serverSelect = document.getElementById('serverSelect');
|
||||
|
||||
if (country && city && servers[country][city]) {
|
||||
serverSelect.innerHTML = '<option value="">Select server</option>';
|
||||
servers[country][city].forEach(server => {
|
||||
serverSelect.innerHTML += '<option value="' + server.hostname + '">' + server.hostname + '</option>';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function updateStatus() {
|
||||
const response = await fetch('/api/status');
|
||||
const data = await response.json();
|
||||
|
||||
document.getElementById('status').textContent = data.connected ? 'Connected' : 'Disconnected';
|
||||
document.getElementById('ip').textContent = data.ip || '-';
|
||||
document.getElementById('location').textContent = data.location || '-';
|
||||
}
|
||||
|
||||
async function connectVPN() {
|
||||
const server = document.getElementById('serverSelect').value;
|
||||
if (!server) { alert('Select a server'); return; }
|
||||
|
||||
const response = await fetch('/api/connect', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({server: server})
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
if (data.success) {
|
||||
alert('Connected!');
|
||||
updateStatus();
|
||||
} else {
|
||||
alert('Connection failed: ' + data.error);
|
||||
}
|
||||
}
|
||||
|
||||
async function disconnectVPN() {
|
||||
const response = await fetch('/api/disconnect', {method: 'POST'});
|
||||
const data = await response.json();
|
||||
if (data.success) {
|
||||
alert('Disconnected - No internet (killswitch active)');
|
||||
updateStatus();
|
||||
}
|
||||
}
|
||||
|
||||
loadServers();
|
||||
updateStatus();
|
||||
setInterval(updateStatus, 10000);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
EOFHTML
|
||||
|
||||
mkdir -p "$INSTALL_DIR/static"
|
||||
if [ -f "$SCRIPT_DIR/frontend/index.html" ]; then
|
||||
cp "$SCRIPT_DIR/frontend/index.html" "$INSTALL_DIR/static/index.html"
|
||||
else
|
||||
echo "<!DOCTYPE html><html><body>VPN Gateway WebUI</body></html>" > "$INSTALL_DIR/static/index.html"
|
||||
fi
|
||||
log "WebUI installed"
|
||||
}
|
||||
log "Installing WebUI..."
|
||||
|
||||
# Install WebUI from repo if available, else fallback to local frontend/
|
||||
if [ -f "$SCRIPT_DIR/frontend/index.html" ]; then
|
||||
mkdir -p "$INSTALL_DIR/static"
|
||||
cp "$SCRIPT_DIR/frontend/index.html" "$INSTALL_DIR/static/index.html"
|
||||
else
|
||||
# Minimal fallback page
|
||||
cat > "$INSTALL_DIR/static/index.html" << 'EOFHTML'
|
||||
<!DOCTYPE html>
|
||||
<html><body>VPN Gateway WebUI</body></html>
|
||||
EOFHTML
|
||||
fi
|
||||
|
||||
# Setup systemd services
|
||||
setup_services() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue