-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
245 lines (203 loc) · 9.83 KB
/
Copy pathindex.html
File metadata and controls
245 lines (203 loc) · 9.83 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
from flask import Flask, render_template, jsonify, request, send_file
from flask_socketio import SocketIO, emit
import json
import os
import uuid
import urllib.request
from datetime import datetime
from threading import Thread
from io import BytesIO
import time
import heapq
app = Flask(__name__)
app.config['SECRET_KEY'] = 'mission-control-v2-secret'
socketio = SocketIO(app, cors_allowed_origins="*", async_mode='threading')
DATA_DIR = "/root/.openclaw/workspace/mission-control-v2/data"
AGENTS_FILE = os.path.join(DATA_DIR, "agents.json")
TASKS_FILE = os.path.join(DATA_DIR, "tasks.json")
TIMELINE_FILE = os.path.join(DATA_DIR, "timeline.json")
os.makedirs(DATA_DIR, exist_ok=True)
task_queue = []
queue_lock = __import__('threading').Lock()
def load_json(filepath, default=None):
if os.path.exists(filepath):
try:
with open(filepath) as f:
return json.load(f)
except:
pass
return default if default is not None else {}
def save_json(filepath, data):
os.makedirs(os.path.dirname(filepath), exist_ok=True)
with open(filepath, 'w') as f:
json.dump(data, f, indent=2)
def init_agents():
default_agents = {
"snowden": {"name": "SNOWDEN", "role": "Leader/Orchestrator", "model": "kimi-k2.5:cloud", "endpoint": "192.168.40.90:11434", "capabilities": ["orchestration", "delegation", "analysis"], "status": "online", "last_seen": datetime.now().isoformat()},
"mitnick": {"name": "MITNICK", "role": "Network/Infrastructure", "model": "deepseek-r1:8b", "endpoint": "192.168.40.90:11434", "capabilities": ["network_scan", "infrastructure", "pentest"], "status": "online", "last_seen": datetime.now().isoformat()},
"mudge": {"name": "MUDGE", "role": "Web/API Security", "model": "deepseek-r1:8b", "endpoint": "192.168.40.90:11434", "capabilities": ["web_scan", "api_test", "vulnerability"], "status": "online", "last_seen": datetime.now().isoformat()},
"ritchie": {"name": "RITCHIE", "role": "Code/Malware", "model": "kimi-k2.5:cloud", "endpoint": "192.168.40.90:11434", "capabilities": ["code_audit", "malware_analysis", "reverse"], "status": "online", "last_seen": datetime.now().isoformat()},
"ada": {"name": "ADA", "role": "Reporting/Docs", "model": "deepseek-r1:8b", "endpoint": "192.168.40.90:11434", "capabilities": ["reporting", "documentation", "visualization"], "status": "online", "last_seen": datetime.now().isoformat()},
}
if not os.path.exists(AGENTS_FILE):
save_json(AGENTS_FILE, default_agents)
return load_json(AGENTS_FILE, default_agents)
def get_model_endpoint(model):
"""Get the correct endpoint for a model"""
# qwen3-coder:30b runs on 192.168.40.110
if model == "qwen3-coder:30b":
return "192.168.40.110:11434"
# baronllm runs on 192.168.40.100
elif "baronllm" in model:
return "192.168.40.100:11434"
# Default endpoint for other models
return "192.168.40.90:11434"
def execute_task_with_retry(agent_id, task_id, task_data, max_retries=3):
"""Execute task with retry logic"""
agents = init_agents()
agent = agents.get(agent_id, {})
model = task_data.get('model', agent.get('model', 'deepseek-r1:8b'))
# Convert qwen3:32b to qwen3-coder:30b and route to correct endpoint
if model == "qwen3:32b":
model = "qwen3-coder:30b"
endpoint = get_model_endpoint(model)
prompt = f"""You are {agent.get('name', agent_id)}, a specialist in {agent.get('role', 'general tasks')}.
TASK: {task_data.get('type', 'general').upper()}
TARGET: {task_data.get('target', 'N/A')}
DESCRIPTION: {task_data.get('description', 'No description')}
MODEL: {model}
Provide a comprehensive response with:
1. Executive Summary
2. Technical Findings
3. Code/Commands if applicable
4. Recommendations
5. Risk Assessment
Use markdown formatting."""
for attempt in range(max_retries):
try:
url = f"http://{endpoint}/api/generate"
data = json.dumps({
"model": model,
"prompt": prompt,
"stream": False,
"options": {"temperature": 0.7, "num_predict": 2000}
}).encode()
req = urllib.request.Request(url, data=data, headers={'Content-Type': 'application/json'}, method='POST')
with urllib.request.urlopen(req, timeout=300) as resp:
result = json.loads(resp.read().decode())
return result.get('response', 'No response')
except Exception as e:
if attempt == max_retries - 1:
return f"Error after {max_retries} attempts: {str(e)}"
time.sleep(2 ** attempt)
return "Task failed"
def process_task_queue():
"""Background worker to process tasks"""
while True:
with queue_lock:
if task_queue:
priority, task_id, agent_id, task_data = heapq.heappop(task_queue)
tasks = load_json(TASKS_FILE, {"tasks": []})
for t in tasks.get("tasks", []):
if t["id"] == task_id:
t["status"] = "running"
t["started"] = datetime.now().isoformat()
break
save_json(TASKS_FILE, tasks)
socketio.emit('task_update', {'task_id': task_id, 'status': 'running'})
result = execute_task_with_retry(agent_id, task_id, task_data)
tasks = load_json(TASKS_FILE, {"tasks": []})
for t in tasks.get("tasks", []):
if t["id"] == task_id:
t["status"] = "completed"
t["result"] = result
t["completed"] = datetime.now().isoformat()
break
save_json(TASKS_FILE, tasks)
socketio.emit('task_update', {'task_id': task_id, 'status': 'completed', 'result_preview': result[:200]})
time.sleep(1)
Thread(target=process_task_queue, daemon=True).start()
@app.route("/")
def index():
agents = init_agents()
tasks = load_json(TASKS_FILE, {"tasks": []})
timeline = load_json(TIMELINE_FILE, [])
task_types = [("general", "General Task"), ("web", "Web Assessment"), ("api", "API Testing"), ("network", "Network Scan"), ("infrastructure", "Infrastructure Audit"), ("code", "Code"), ("malware", "Malware Analysis"), ("reverse", "Reverse Engineering"), ("forensics", "Forensics"), ("incident", "Incident Response"), ("threat", "Threat Intel"), ("osint", "OSINT Investigation"), ("report", "Report Generation"), ("research", "Research"), ("automation", "Automation Script")]
# Updated models - qwen3:32b maps to qwen3-coder:30b on 192.168.40.110
models = [("kimi-k2.5:cloud", "kimi-k2.5:cloud (Advanced)"),
("deepseek-r1:8b", "deepseek-r1:8b (Reasoning)"),
("qwen3:8b", "qwen3:8b (Fast)"),
("qwen3-coder:30b", "qwen3-coder:30b (Powerful - 192.168.40.110)"),
("huihui_ai/baronllm-abliterated:8b", "baronllm-abliterated:8b (192.168.40.100)")]
return render_template("index.html", tasks=tasks.get("tasks", []), timeline=timeline[-20:], agents=agents, task_types=task_types, models=models)
@app.route("/agents")
def agents_page():
agents = init_agents()
tasks = load_json(TASKS_FILE, {"tasks": []})
return render_template("agents.html", agents=agents, tasks=tasks.get("tasks", []))
@app.route("/tasks")
def tasks_page():
tasks = load_json(TASKS_FILE, {"tasks": []})
return render_template("tasks.html", tasks=tasks.get("tasks", []))
@app.route("/task/<task_id>")
def task_detail(task_id):
tasks = load_json(TASKS_FILE, {"tasks": []})
task = next((t for t in tasks.get("tasks", []) if t["id"] == task_id), None)
if not task:
return "Task not found", 404
return render_template("task_detail.html", task=task)
@app.route("/findings")
def findings_page():
return render_template("findings.html", findings=[])
@app.route("/evidence")
def evidence_page():
return render_template("evidence.html", evidence=[])
@app.route("/api/task", methods=["POST"])
def create_task():
data = request.json
agent_id = data.get("agent", "snowden")
priority_map = {'high': 1, 'normal': 2, 'low': 3}
priority = priority_map.get(data.get('priority', 'normal'), 2)
agents = init_agents()
if agent_id not in agents:
return jsonify({"success": False, "error": "Agent not found"}), 404
# Get model, auto-convert qwen3:32b to qwen3-coder:30b
model = data.get("model", agents[agent_id]["model"])
if model == "qwen3:32b":
model = "qwen3-coder:30b"
task_id = str(uuid.uuid4())[:8]
task = {
"id": task_id,
"agent": agent_id,
"agent_name": agents[agent_id]["name"],
"type": data.get("type", "general"),
"target": data.get("target", ""),
"description": data.get("description", ""),
"model": model,
"priority": data.get("priority", "normal"),
"status": "queued",
"created": datetime.now().isoformat(),
"started": None,
"completed": None,
"result": None
}
tasks = load_json(TASKS_FILE, {"tasks": []})
tasks["tasks"].append(task)
save_json(TASKS_FILE, tasks)
with queue_lock:
heapq.heappush(task_queue, (priority, task_id, agent_id, data))
socketio.emit('new_task', task)
return jsonify({
"success": True,
"task_id": task_id,
"agent": agent_id,
"agent_name": agents[agent_id]["name"],
"status": task["status"]
})
@app.route("/api/tasks")
def get_tasks():
tasks = load_json(TASKS_FILE, {"tasks": []})
return jsonify(tasks.get("tasks", []))
if __name__ == "__main__":
init_agents()
socketio.run(app, host="0.0.0.0", port=4001, debug=False, allow_unsafe_werkzeug=True)