-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
80 lines (64 loc) · 2.8 KB
/
Copy pathserver.py
File metadata and controls
80 lines (64 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# =============================================================
# MYTHOS-SYNC — WEB SERVER
# Serves dashboard.html AND runs fusions via the browser UI
# =============================================================
import json
import os
from http.server import HTTPServer, SimpleHTTPRequestHandler
from console import use_utf8_output
from mythos_sync import build_legacy_profile, save_to_matrix, load_matrix, export_for_web
class MythosHandler(SimpleHTTPRequestHandler):
def log_message(self, format, *args):
pass # silence default server logs
def do_GET(self):
super().do_GET()
def end_headers(self):
self.send_header('Content-Security-Policy',
"default-src 'self'; "
"script-src 'self' 'unsafe-inline' 'unsafe-eval'; "
"style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; "
"font-src https://fonts.gstatic.com; "
"connect-src 'self';")
self.send_header('Access-Control-Allow-Origin', '*')
super().end_headers()
def do_POST(self):
if self.path == '/fuse':
length = int(self.headers.get('Content-Length', 0))
body = self.rfile.read(length)
data = json.loads(body)
alpha = data.get('alpha', '').strip()
beta = data.get('beta', '').strip()
dominance = int(data.get('dominance', 50))
if not alpha or not beta:
self._respond(400, {"error": "Alpha and Beta are required."})
return
try:
print(f"\n 🌐 [SERVER] Fusing: {alpha} x {beta} @ {dominance}% dominance")
profile = build_legacy_profile(alpha, beta, dominance)
save_to_matrix(profile)
export_for_web()
self._respond(200, {"status": "ok", "profile": profile})
except Exception as e:
self._respond(500, {"error": str(e)})
elif self.path == '/clear':
if os.path.exists('containment_matrix.json'):
os.remove('containment_matrix.json')
print("\n 🗑️ [SERVER] Matrix cleared.")
self._respond(200, {"status": "cleared"})
else:
self._respond(404, {"error": "Not found"})
def _respond(self, code, data):
body = json.dumps(data).encode()
self.send_response(code)
self.send_header('Content-Type', 'application/json')
self.send_header('Content-Length', str(len(body)))
self.end_headers()
self.wfile.write(body)
if __name__ == '__main__':
use_utf8_output()
port = 8000
print(f"\n{'═'*50}")
print(f" 🌌 MYTHOS-SYNC SERVER — LIVE ON PORT {port}")
print(f" Open: http://localhost:{port}/dashboard.html")
print(f"{'═'*50}\n")
HTTPServer(('', port), MythosHandler).serve_forever()