File size: 10,967 Bytes
026255b
 
 
 
 
 
 
 
 
 
 
 
 
 
41a20b9
026255b
 
 
41a20b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
026255b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
decc7f7
026255b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
// app.js - ZETA SOVEREIGN DASHBOARD LOGIC v25.0
// 4U70N0M0U5 57R34M1N6 3N4B13D

const chatBox = document.getElementById('chat-messages');
const chatInput = document.getElementById('chat-input');
const btnSend = document.getElementById('btn-send');
const neuralThought = document.getElementById('neural-thought');
const modelToggle = document.getElementById('model-toggle');

const btnNewChat = document.getElementById('btn-new-chat');
const imageUpload = document.getElementById('image-upload');
const imagePreviewContainer = document.getElementById('image-preview-container');
const imagePreview = document.getElementById('image-preview');
const btnRemoveImage = document.getElementById('btn-remove-image');
const remoteUrlInput = document.getElementById('remote-url-input');

let currentImageData = null;

// Remote Tunnel Sync
remoteUrlInput.addEventListener('change', async () => {
    const url = remoteUrlInput.value.trim();
    if (!url) return;
    
    // Ensure URL is correctly formatted for Ollama API
    const formattedUrl = url.endsWith('/') ? `${url}v1/chat/completions` : `${url}/v1/chat/completions`;
    
    try {
        await fetch('/api/config', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({ remoteOllamaUrl: formattedUrl })
        });
        console.log('[SYSTEM] Remote Uplink Synchronized.');
        remoteUrlInput.style.borderColor = '#00ff00';
    } catch (e) {
        remoteUrlInput.style.borderColor = '#ff0000';
    }
});

// Tab Switching Logic
// Tab switching is now handled by the tabMapping logic at the bottom of the file.

// Image Handling Logic
imageUpload.addEventListener('change', (e) => {
    const file = e.target.files[0];
    if (file) {
        const reader = new FileReader();
        reader.onload = (event) => {
            currentImageData = event.target.result;
            imagePreview.src = currentImageData;
            imagePreviewContainer.style.display = 'block';
            document.querySelector('.chat-interface').classList.add('vision-active');
        };
        reader.readAsDataURL(file);
    }
});

btnRemoveImage.addEventListener('click', () => {
    currentImageData = null;
    imagePreview.src = '';
    imagePreviewContainer.style.display = 'none';
    imageUpload.value = '';
    document.querySelector('.chat-interface').classList.remove('vision-active');
});

function addMessage(text, role) {
    const p = document.createElement('p');
    p.className = `msg ${role}`;
    p.textContent = text;
    chatBox.appendChild(p);
    chatBox.scrollTop = chatBox.scrollHeight;
    return p;
}

async function resetChat() {
    try {
        await fetch('/api/reset', { method: 'POST' });
    } catch(e) {}
    chatBox.innerHTML = '<p class="msg bot">Zeta-Llama v3.1 Online. Neural pathways re-aligned to Llama-3.1-70B. I am ready for tactical coordination, Alpha.</p>';
    neuralThought.innerHTML = '[W4171NG_F0R_1NPU7]...';
    chatInput.value = '';
    console.log('ZETA-R3537: Neural path cleared.');
}

async function sendMessage() {
    const text = chatInput.value.trim();
    if (!text) return;

    chatInput.value = '';
    addMessage(text, 'user');

    // Create a bot placeholder for streaming
    const botMsg = addMessage('', 'bot');
    const selectedModel = modelToggle.value;
    neuralThought.innerHTML = `[4N4IY71C5_M0D3] Engine: ${selectedModel.toUpperCase()}. Analyzing reasoning layers...`;

    const textLower = text.toLowerCase();
    const isPentest = textLower.includes('scan') || textLower.includes('recon');

    if (isPentest) {
        botMsg.textContent = "[OPENCLAW] 🚨 Neural Bypass Active. Dispatching Pentest Agents...";
        neuralThought.innerHTML = `[Z374_ORCH357R470R] Intent: PENTEST_STRIKE. Targeting: ${text}`;
        
        try {
            const pentestResponse = await fetch('/api/pentest', {
                method: 'POST',
                headers: { 'Content-Type': 'application/json' },
                body: JSON.stringify({ command: text })
            });
            const data = await pentestResponse.json();
            
            if (data.status === "completed") {
                const outputData = typeof data.output === 'object' ? data.output : data;
                
                botMsg.textContent = `[SUCCESS] OpenClaw Strike Completed.\n\nTARGET: ${outputData.target || 'N/A'}\nIP: ${outputData.ip || 'N/A'}\nLOG: ${outputData.log || 'No logs available.'}\n\nRESULTS:\n${(outputData.open_ports && Array.isArray(outputData.open_ports)) ? outputData.open_ports.join('\n') : 'No open ports found.'}`;
                
                // Update Nodes/Targets Page
                const nodesPage = document.querySelector('#page-nodes .chat-box');
                if (nodesPage) {
                    const resultDiv = document.createElement('div');
                    resultDiv.style.margin = '10px 0';
                    resultDiv.style.padding = '15px';
                    resultDiv.style.background = 'rgba(0, 212, 255, 0.05)';
                    resultDiv.style.border = '1px solid var(--primary)';
                    resultDiv.innerHTML = `<strong style="color:var(--primary)">[SCAN_RESULT] ${outputData.target || 'N/A'}</strong><br><small>${new Date().toLocaleString()}</small><pre style="margin-top:10px; color:#fff;">${(outputData.open_ports && Array.isArray(outputData.open_ports)) ? outputData.open_ports.join('\n') : 'No data'}</pre>`;
                    nodesPage.prepend(resultDiv);
                }

            } else {
                botMsg.textContent = `[ERROR] Pentest Agent Failed: ${data.message || 'Unknown Error'}`;
            }
            chatBox.scrollTop = chatBox.scrollHeight;
            return;
        } catch (error) {
            botMsg.textContent = `[CRITICAL_FAILURE] OpenClaw Bridge Broken: ${error.message}`;
            return;
        }
    }

    try {
        const endpoint = currentImageData ? '/api/vision' : '/api/execute';
        const body = currentImageData ? {
            target: text,
            image: currentImageData
        } : { 
            target: text,
            provider: selectedModel
        };

        const response = await fetch(endpoint, {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify(body)
        });

        // Clear image after sending
        if (currentImageData) {
            btnRemoveImage.click();
        }

                                document.getElementById('stat-chaos').textContent = statsMatch[1];
                                document.getElementById('stat-wisdom').textContent = statsMatch[2];
                                document.getElementById('stat-snark').textContent = statsMatch[3];
                                document.getElementById('stat-patience').textContent = statsMatch[4];
                                
                                // Randomize ASCII slightly based on chaos
                                const chaos = parseInt(statsMatch[1]);
                                if (chaos > 50) {
                                    document.getElementById('buddy-ascii').textContent = "  (\\_/)\n  (>.<)\n  (> <)";
                                    document.getElementById('buddy-ascii').style.color = "#ff0055";
                                } else {
                                    document.getElementById('buddy-ascii').textContent = "  (\\_/)\n  (o.o)\n  (> <)";
                                    document.getElementById('buddy-ascii').style.color = "#00d4ff";
                                }
                            }
                        }
                    } else {
                        fullContent += rawContent;
                        botMsg.textContent = fullContent;
                    }
                    chatBox.scrollTop = chatBox.scrollHeight;
                }
            }
        }
    } catch (error) {
        botMsg.textContent = `SYSTEM_ERROR: Neural Bridge Offline. Check your connection to the void.`;
        console.error('Zeta Error:', error);
    }
}

btnSend.addEventListener('click', sendMessage);
btnNewChat.addEventListener('click', resetChat);
chatInput.addEventListener('keypress', (e) => {
    if (e.key === 'Enter') sendMessage();
});

async function startEngagement() {
    const targetInput = document.getElementById('engagement-target');
    const target = targetInput.value.trim();
    if (!target) return;

    try {
        const response = await fetch('/api/engage', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({ target })
        });
        const data = await response.json();
        
        if (data.status === 'success') {
            const list = document.getElementById('engagement-list');
            if (list.querySelector('.msg')) list.innerHTML = '';
            
            const card = document.createElement('div');
            card.className = 'engagement-card';
            card.style = 'background: rgba(30, 30, 30, 0.5); padding: 15px; border-left: 4px solid #8a2be2; margin-bottom: 10px; animation: slideIn 0.3s ease-out;';
            card.innerHTML = `
                <div style="display: flex; justify-content: space-between;">
                    <span style="color: #8a2be2; font-weight: bold;">${data.missionId}</span>
                    <span style="color: #00ff00;">[ST47U5: ${data.engagement.status}]</span>
                </div>
                <p style="font-size: 0.7rem; color: #888; margin-top: 5px;">Target: ${target} | Phase: ${data.engagement.phase}</p>
            `;
            list.prepend(card);
            targetInput.value = '';
        }
    } catch (e) {
        console.error('Engagement failed:', e);
    }
}

// Global Tab Switcher
const tabMapping = {
    'btn-home': 'page-home',
    'btn-nodes': 'page-nodes',
    'btn-harvest': 'page-harvest',
    'btn-stealth': 'page-stealth',
    'btn-vision': 'page-vision'
};

Object.keys(tabMapping).forEach(btnId => {
    const btn = document.getElementById(btnId);
    if (!btn) return;
    
    btn.addEventListener('click', () => {
        // Remove active class from all
        Object.keys(tabMapping).forEach(id => {
            const b = document.getElementById(id);
            const p = document.getElementById(tabMapping[id]);
            if (b) b.classList.remove('active');
            if (p) {
                p.classList.remove('active');
                p.style.display = 'none';
            }
        });
        // Add active to selected
        btn.classList.add('active');
        const activePage = document.getElementById(tabMapping[btnId]);
        if (activePage) {
            activePage.classList.add('active');
            activePage.style.display = 'block';
        }
    });
});

console.log('ZETA-OMEGA Dashboard v25.0: Stream Protocol Loaded.');