init
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
# Updated endpoints to use HTTPS
|
||||
SERVICES = [
|
||||
{"name": "Dashboard UI", "url": "https://localhost/"},
|
||||
{"name": "Mail UI", "url": "https://localhost/mail"},
|
||||
{"name": "Calendar UI", "url": "https://localhost/calendar"},
|
||||
{"name": "Files UI", "url": "https://localhost/files"},
|
||||
{"name": "DNS Management UI", "url": "https://localhost/dns"},
|
||||
{"name": "API Health", "url": "https://localhost/api/health", "is_api": True},
|
||||
{"name": "API Service Status", "url": "https://localhost/api/services/status", "is_api": True},
|
||||
]
|
||||
|
||||
def check_ui(url, name):
|
||||
try:
|
||||
resp = requests.get(url, timeout=5, verify=False)
|
||||
if resp.status_code == 200:
|
||||
# Try to parse HTML and look for a title or main element
|
||||
soup = BeautifulSoup(resp.text, "html.parser")
|
||||
title = soup.title.string if soup.title else "No title"
|
||||
print(f"[OK] {name} ({url}) - {title}")
|
||||
return True
|
||||
else:
|
||||
print(f"[FAIL] {name} ({url}) - HTTP {resp.status_code}")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"[ERROR] {name} ({url}) - {e}")
|
||||
return False
|
||||
|
||||
def check_api_status(url, name):
|
||||
try:
|
||||
resp = requests.get(url, timeout=5, verify=False)
|
||||
if resp.status_code == 200:
|
||||
print(f"[OK] {name}: {url}")
|
||||
if 'services/status' in url:
|
||||
data = resp.json()
|
||||
for service, status in data.items():
|
||||
s = status.get("status", "Unknown")
|
||||
print(f" {service}: {s}")
|
||||
else:
|
||||
print(f" Response: {resp.text.strip()}")
|
||||
return True
|
||||
else:
|
||||
print(f"[FAIL] {name}: HTTP {resp.status_code}")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"[ERROR] {name}: {e}")
|
||||
return False
|
||||
|
||||
def main():
|
||||
print("=== UI & API Sanity Checks (Caddy-proxied, HTTPS) ===")
|
||||
for svc in SERVICES:
|
||||
if svc.get("is_api"):
|
||||
check_api_status(svc["url"], svc["name"])
|
||||
else:
|
||||
check_ui(svc["url"], svc["name"])
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,99 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
# List of required directories (relative to project root)
|
||||
REQUIRED_DIRS = [
|
||||
'config/caddy/certs',
|
||||
'config/dns',
|
||||
'config/dhcp',
|
||||
'config/ntp',
|
||||
'config/mail/config',
|
||||
'config/mail/ssl',
|
||||
'config/radicale',
|
||||
'config/webdav',
|
||||
'config/wireguard',
|
||||
'config/api',
|
||||
'data/caddy',
|
||||
'data/dns',
|
||||
'data/dhcp',
|
||||
'data/maildata',
|
||||
'data/mailstate',
|
||||
'data/maillogs',
|
||||
'data/radicale',
|
||||
'data/files',
|
||||
'data/api',
|
||||
'data/vault/certs',
|
||||
'data/vault/keys',
|
||||
'data/vault/trust',
|
||||
'data/vault/ca',
|
||||
]
|
||||
|
||||
# List of required files (relative to project root)
|
||||
REQUIRED_FILES = [
|
||||
'config/caddy/Caddyfile',
|
||||
'config/dns/Corefile',
|
||||
'config/dhcp/dnsmasq.conf',
|
||||
'config/ntp/chrony.conf',
|
||||
'config/mail/mailserver.env',
|
||||
'config/webdav/users.passwd',
|
||||
]
|
||||
|
||||
# Helper to create directories
|
||||
def ensure_dir(path):
|
||||
if not os.path.exists(path):
|
||||
os.makedirs(path, exist_ok=True)
|
||||
print(f"[CREATED] Directory: {path}")
|
||||
# Add .gitkeep to empty dirs
|
||||
gitkeep = os.path.join(path, '.gitkeep')
|
||||
with open(gitkeep, 'w') as f:
|
||||
f.write('')
|
||||
else:
|
||||
print(f"[EXISTS] Directory: {path}")
|
||||
|
||||
# Helper to create empty files if missing
|
||||
def ensure_file(path):
|
||||
if not os.path.exists(path):
|
||||
parent = os.path.dirname(path)
|
||||
if parent and not os.path.exists(parent):
|
||||
os.makedirs(parent, exist_ok=True)
|
||||
print(f"[CREATED] Directory: {parent}")
|
||||
with open(path, 'w') as f:
|
||||
f.write('')
|
||||
print(f"[CREATED] File: {path}")
|
||||
else:
|
||||
print(f"[EXISTS] File: {path}")
|
||||
|
||||
# Optionally generate a self-signed CA cert for Caddy
|
||||
def ensure_caddy_ca_cert():
|
||||
cert_dir = os.path.join('config', 'caddy', 'certs')
|
||||
ca_key = os.path.join(cert_dir, 'ca.key')
|
||||
ca_crt = os.path.join(cert_dir, 'ca.crt')
|
||||
if os.path.exists(ca_key) and os.path.exists(ca_crt):
|
||||
print(f"[EXISTS] Caddy CA cert and key: {ca_crt}, {ca_key}")
|
||||
return
|
||||
print("[INFO] Generating self-signed CA certificate for Caddy...")
|
||||
try:
|
||||
subprocess.run([
|
||||
'openssl', 'req', '-x509', '-newkey', 'rsa:4096',
|
||||
'-keyout', ca_key, '-out', ca_crt, '-days', '365', '-nodes',
|
||||
'-subj', '/C=US/ST=State/L=City/O=PersonalInternetCell/CN=CellCA'
|
||||
], check=True)
|
||||
print(f"[CREATED] Caddy CA cert and key: {ca_crt}, {ca_key}")
|
||||
except FileNotFoundError:
|
||||
print("[WARN] openssl not found, skipping CA cert generation.")
|
||||
except subprocess.CalledProcessError:
|
||||
print("[ERROR] openssl failed to generate CA cert.")
|
||||
|
||||
def main():
|
||||
print("--- Personal Internet Cell: Setup Script ---")
|
||||
for d in REQUIRED_DIRS:
|
||||
ensure_dir(d)
|
||||
for f in REQUIRED_FILES:
|
||||
ensure_file(f)
|
||||
ensure_caddy_ca_cert()
|
||||
print("--- Setup complete! ---")
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user