Update static/js/script.js
Browse files- static/js/script.js +695 -536
static/js/script.js
CHANGED
@@ -1,537 +1,696 @@
|
|
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 |
-
data.
|
191 |
-
const
|
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 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
}
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
.
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
}
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
}
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
}
|
379 |
-
|
380 |
-
|
381 |
-
}
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
}
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
const
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
});
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
}
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
const
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
}
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
537 |
}
|
|
|
1 |
+
// script.js
|
2 |
+
const API_KEY = 'your_secret_api_key';
|
3 |
+
|
4 |
+
// Tab Switching
|
5 |
+
document.querySelectorAll('.sidebar-item[data-tab]').forEach(item => {
|
6 |
+
item.addEventListener('click', () => {
|
7 |
+
document.querySelectorAll('.sidebar-item').forEach(i => i.classList.remove('active'));
|
8 |
+
item.classList.add('active');
|
9 |
+
document.querySelectorAll('.tab-content').forEach(content => content.style.display = 'none');
|
10 |
+
const tabId = item.getAttribute('data-tab') + '-content';
|
11 |
+
document.getElementById(tabId).style.display = 'block';
|
12 |
+
loadTabContent(tabId);
|
13 |
+
});
|
14 |
+
});
|
15 |
+
|
16 |
+
// Profile Photo Click Event
|
17 |
+
document.getElementById('profilePhoto').addEventListener('click', function() {
|
18 |
+
const menu = document.getElementById('profileMenu');
|
19 |
+
if (menu.style.display === 'block') {
|
20 |
+
menu.style.display = 'none';
|
21 |
+
} else {
|
22 |
+
menu.style.display = 'block';
|
23 |
+
}
|
24 |
+
});
|
25 |
+
|
26 |
+
// Close Profile Menu when clicking outside
|
27 |
+
window.onclick = function(event) {
|
28 |
+
if (!event.target.matches('#profilePhoto')) {
|
29 |
+
const menu = document.getElementById('profileMenu');
|
30 |
+
if (menu.style.display === 'block') {
|
31 |
+
menu.style.display = 'none';
|
32 |
+
}
|
33 |
+
}
|
34 |
+
};
|
35 |
+
|
36 |
+
// Toggle Sidebar
|
37 |
+
document.getElementById('toggleSidebar').addEventListener('click', function() {
|
38 |
+
document.getElementById('sidebar').classList.toggle('active');
|
39 |
+
});
|
40 |
+
|
41 |
+
// Fetch System Info
|
42 |
+
async function fetchSystemInfo() {
|
43 |
+
try {
|
44 |
+
const response = await fetch('/api/system-info', {
|
45 |
+
headers: {
|
46 |
+
'Authorization': API_KEY
|
47 |
+
}
|
48 |
+
});
|
49 |
+
const data = await response.json();
|
50 |
+
document.getElementById('osName').textContent = data.os.name;
|
51 |
+
document.getElementById('osVersion').textContent = data.os.version;
|
52 |
+
document.getElementById('uptime').textContent = data.uptime;
|
53 |
+
document.getElementById('storage').textContent = `${(data.storage.total / (1024 ** 3)).toFixed(2)} GB / ${(data.storage.free / (1024 ** 3)).toFixed(2)} GB`;
|
54 |
+
} catch (error) {
|
55 |
+
console.error('Failed to fetch system info:', error);
|
56 |
+
}
|
57 |
+
}
|
58 |
+
|
59 |
+
// Fetch Bot Stats
|
60 |
+
async function fetchBotStats() {
|
61 |
+
try {
|
62 |
+
const response = await fetch('/api/bot-stats', {
|
63 |
+
headers: {
|
64 |
+
'Authorization': API_KEY
|
65 |
+
}
|
66 |
+
});
|
67 |
+
const data = await response.json();
|
68 |
+
document.getElementById('totalFiles').textContent = data.total_files;
|
69 |
+
document.getElementById('totalUsers').textContent = data.total_users;
|
70 |
+
document.getElementById('totalChats').textContent = data.total_chats;
|
71 |
+
document.getElementById('storageUsed').textContent = data.storage_used;
|
72 |
+
document.getElementById('storageFree').textContent = data.storage_free;
|
73 |
+
} catch (error) {
|
74 |
+
console.error('Failed to fetch bot stats:', error);
|
75 |
+
}
|
76 |
+
}
|
77 |
+
|
78 |
+
// Fetch Bot Status
|
79 |
+
async function fetchBotStatus() {
|
80 |
+
try {
|
81 |
+
const response = await fetch('/api/bot-status', {
|
82 |
+
headers: {
|
83 |
+
'Authorization': API_KEY
|
84 |
+
}
|
85 |
+
});
|
86 |
+
const data = await response.json();
|
87 |
+
document.getElementById('cpuUsage').textContent = `${data.cpu_usage}%`;
|
88 |
+
document.getElementById('ramUsage').textContent = `${data.ram_usage}%`;
|
89 |
+
document.getElementById('storageUsed').textContent = data.used_storage;
|
90 |
+
document.getElementById('storageFree').textContent = data.free_storage;
|
91 |
+
} catch (error) {
|
92 |
+
console.error('Failed to fetch bot status:', error);
|
93 |
+
}
|
94 |
+
}
|
95 |
+
|
96 |
+
// Load Tab Content
|
97 |
+
async function loadTabContent(tabId) {
|
98 |
+
if (tabId === 'filters-content') {
|
99 |
+
loadFilters();
|
100 |
+
} else if (tabId === 'global-filters-content') {
|
101 |
+
loadGlobalFilters();
|
102 |
+
} else if (tabId === 'users-content') {
|
103 |
+
loadUsers();
|
104 |
+
} else if (tabId === 'chats-content') {
|
105 |
+
loadChats();
|
106 |
+
} else if (tabId === 'files-content') {
|
107 |
+
loadFiles();
|
108 |
+
} else if (tabId === 'connections-content') {
|
109 |
+
loadConnections();
|
110 |
+
} else if (tabId === 'stats-content') {
|
111 |
+
fetchBotStatus();
|
112 |
+
}
|
113 |
+
}
|
114 |
+
|
115 |
+
// Load Filters
|
116 |
+
async function loadFilters() {
|
117 |
+
try {
|
118 |
+
const response = await fetch('/api/filters?chat_id=123456789', { // Replace with actual chat ID
|
119 |
+
headers: {
|
120 |
+
'Authorization': API_KEY
|
121 |
+
}
|
122 |
+
});
|
123 |
+
const data = await response.json();
|
124 |
+
const filtersList = document.getElementById('filtersList');
|
125 |
+
filtersList.innerHTML = '';
|
126 |
+
data.filters.forEach(filter => {
|
127 |
+
const filterItem = document.createElement('div');
|
128 |
+
filterItem.className = 'stat-card';
|
129 |
+
filterItem.innerHTML = `
|
130 |
+
<div class="stat-header">
|
131 |
+
<div>
|
132 |
+
<h3>${filter}</h3>
|
133 |
+
</div>
|
134 |
+
<div class="stat-icon">
|
135 |
+
<i class="fas fa-filter"></i>
|
136 |
+
</div>
|
137 |
+
</div>
|
138 |
+
<button onclick="deleteFilter('${filter}')">Delete</button>
|
139 |
+
`;
|
140 |
+
filtersList.appendChild(filterItem);
|
141 |
+
});
|
142 |
+
} catch (error) {
|
143 |
+
console.error('Failed to load filters:', error);
|
144 |
+
}
|
145 |
+
}
|
146 |
+
|
147 |
+
// Load Global Filters
|
148 |
+
async function loadGlobalFilters() {
|
149 |
+
try {
|
150 |
+
const response = await fetch('/api/gfilters', {
|
151 |
+
headers: {
|
152 |
+
'Authorization': API_KEY
|
153 |
+
}
|
154 |
+
});
|
155 |
+
const data = await response.json();
|
156 |
+
const gfiltersList = document.getElementById('gfiltersList');
|
157 |
+
gfiltersList.innerHTML = '';
|
158 |
+
data.filters.forEach(filter => {
|
159 |
+
const filterItem = document.createElement('div');
|
160 |
+
filterItem.className = 'stat-card';
|
161 |
+
filterItem.innerHTML = `
|
162 |
+
<div class="stat-header">
|
163 |
+
<div>
|
164 |
+
<h3>${filter}</h3>
|
165 |
+
</div>
|
166 |
+
<div class="stat-icon">
|
167 |
+
<i class="fas fa-globe"></i>
|
168 |
+
</div>
|
169 |
+
</div>
|
170 |
+
<button onclick="deleteGFilter('${filter}')">Delete</button>
|
171 |
+
`;
|
172 |
+
gfiltersList.appendChild(filterItem);
|
173 |
+
});
|
174 |
+
} catch (error) {
|
175 |
+
console.error('Failed to load global filters:', error);
|
176 |
+
}
|
177 |
+
}
|
178 |
+
|
179 |
+
// Load Users
|
180 |
+
async function loadUsers() {
|
181 |
+
try {
|
182 |
+
const response = await fetch('/api/users', {
|
183 |
+
headers: {
|
184 |
+
'Authorization': API_KEY
|
185 |
+
}
|
186 |
+
});
|
187 |
+
const data = await response.json();
|
188 |
+
const usersList = document.getElementById('usersList');
|
189 |
+
usersList.innerHTML = '';
|
190 |
+
data.users.forEach(user => {
|
191 |
+
const userItem = document.createElement('div');
|
192 |
+
userItem.className = 'stat-card';
|
193 |
+
userItem.innerHTML = `
|
194 |
+
<div class="stat-header">
|
195 |
+
<div>
|
196 |
+
<h3>${user.name}</h3>
|
197 |
+
<p>ID: ${user.id}</p>
|
198 |
+
</div>
|
199 |
+
<div class="stat-icon">
|
200 |
+
<i class="fas fa-user"></i>
|
201 |
+
</div>
|
202 |
+
</div>
|
203 |
+
<button onclick="banUser('${user.id}', '${user.ban_status.ban_reason}')">${user.ban_status.is_banned ? 'Unban' : 'Ban'}</button>
|
204 |
+
`;
|
205 |
+
usersList.appendChild(userItem);
|
206 |
+
});
|
207 |
+
} catch (error) {
|
208 |
+
console.error('Failed to load users:', error);
|
209 |
+
}
|
210 |
+
}
|
211 |
+
|
212 |
+
// Load Chats
|
213 |
+
async function loadChats() {
|
214 |
+
try {
|
215 |
+
const response = await fetch('/api/chats', {
|
216 |
+
headers: {
|
217 |
+
'Authorization': API_KEY
|
218 |
+
}
|
219 |
+
});
|
220 |
+
const data = await response.json();
|
221 |
+
const chatsList = document.getElementById('chatsList');
|
222 |
+
chatsList.innerHTML = '';
|
223 |
+
data.chats.forEach(chat => {
|
224 |
+
const chatItem = document.createElement('div');
|
225 |
+
chatItem.className = 'stat-card';
|
226 |
+
chatItem.innerHTML = `
|
227 |
+
<div class="stat-header">
|
228 |
+
<div>
|
229 |
+
<h3>${chat.title}</h3>
|
230 |
+
<p>ID: ${chat.id}</p>
|
231 |
+
</div>
|
232 |
+
<div class="stat-icon">
|
233 |
+
<i class="fas fa-comment-dots"></i>
|
234 |
+
</div>
|
235 |
+
</div>
|
236 |
+
<button onclick="disableChat('${chat.id}', '${chat.chat_status.reason}')">${chat.chat_status.is_disabled ? 'Enable' : 'Disable'}</button>
|
237 |
+
`;
|
238 |
+
chatsList.appendChild(chatItem);
|
239 |
+
});
|
240 |
+
} catch (error) {
|
241 |
+
console.error('Failed to load chats:', error);
|
242 |
+
}
|
243 |
+
}
|
244 |
+
|
245 |
+
// Load Files
|
246 |
+
async function loadFiles() {
|
247 |
+
try {
|
248 |
+
const response = await fetch('/api/files', {
|
249 |
+
headers: {
|
250 |
+
'Authorization': API_KEY
|
251 |
+
}
|
252 |
+
});
|
253 |
+
const data = await response.json();
|
254 |
+
const filesList = document.getElementById('filesList');
|
255 |
+
filesList.innerHTML = '';
|
256 |
+
data.files.forEach(file => {
|
257 |
+
const fileItem = document.createElement('div');
|
258 |
+
fileItem.className = 'stat-card';
|
259 |
+
fileItem.innerHTML = `
|
260 |
+
<div class="stat-header">
|
261 |
+
<div>
|
262 |
+
<h3>${file.file_name}</h3>
|
263 |
+
<p>Size: ${get_size(file.file_size)}</p>
|
264 |
+
</div>
|
265 |
+
<div class="stat-icon">
|
266 |
+
<i class="fas fa-file"></i>
|
267 |
+
</div>
|
268 |
+
</div>
|
269 |
+
<button onclick="deleteFile('${file.file_id}')">Delete</button>
|
270 |
+
`;
|
271 |
+
filesList.appendChild(fileItem);
|
272 |
+
});
|
273 |
+
} catch (error) {
|
274 |
+
console.error('Failed to load files:', error);
|
275 |
+
}
|
276 |
+
}
|
277 |
+
|
278 |
+
// Load Connections
|
279 |
+
async function loadConnections() {
|
280 |
+
try {
|
281 |
+
const response = await fetch('/api/connections', {
|
282 |
+
headers: {
|
283 |
+
'Authorization': API_KEY
|
284 |
+
}
|
285 |
+
});
|
286 |
+
const data = await response.json();
|
287 |
+
const connectionsList = document.getElementById('connectionsList');
|
288 |
+
connectionsList.innerHTML = '';
|
289 |
+
data.connections.forEach(connection => {
|
290 |
+
const connectionItem = document.createElement('div');
|
291 |
+
connectionItem.className = 'stat-card';
|
292 |
+
connectionItem.innerHTML = `
|
293 |
+
<div class="stat-header">
|
294 |
+
<div>
|
295 |
+
<h3>${connection.title}</h3>
|
296 |
+
<p>ID: ${connection.id}</p>
|
297 |
+
</div>
|
298 |
+
<div class="stat-icon">
|
299 |
+
<i class="fas fa-link"></i>
|
300 |
+
</div>
|
301 |
+
</div>
|
302 |
+
<button onclick="deleteConnection('${connection.id}', '${connection.user_id}')">Delete</button>
|
303 |
+
`;
|
304 |
+
connectionsList.appendChild(connectionItem);
|
305 |
+
});
|
306 |
+
} catch (error) {
|
307 |
+
console.error('Failed to load connections:', error);
|
308 |
+
}
|
309 |
+
}
|
310 |
+
|
311 |
+
// Add Filter
|
312 |
+
document.getElementById('addFilterForm').addEventListener('submit', async function(event) {
|
313 |
+
event.preventDefault();
|
314 |
+
const chatId = document.getElementById('chatId').value;
|
315 |
+
const text = document.getElementById('filterText').value;
|
316 |
+
const replyText = document.getElementById('replyText').value;
|
317 |
+
const btn = document.getElementById('btn').value;
|
318 |
+
const file = document.getElementById('file').value;
|
319 |
+
const alert = document.getElementById('alert').value;
|
320 |
+
try {
|
321 |
+
const response = await fetch('/api/add-filter', {
|
322 |
+
method: 'POST',
|
323 |
+
headers: {
|
324 |
+
'Content-Type': 'application/x-www-form-urlencoded',
|
325 |
+
'Authorization': API_KEY
|
326 |
+
},
|
327 |
+
body: `chat_id=${encodeURIComponent(chatId)}&text=${encodeURIComponent(text)}&reply_text=${encodeURIComponent(replyText)}&btn=${encodeURIComponent(btn)}&file=${encodeURIComponent(file)}&alert=${encodeURIComponent(alert)}`,
|
328 |
+
});
|
329 |
+
const data = await response.json();
|
330 |
+
alert(data.message);
|
331 |
+
loadFilters();
|
332 |
+
} catch (error) {
|
333 |
+
console.error('Failed to add filter:', error);
|
334 |
+
alert('Failed to add filter');
|
335 |
+
}
|
336 |
+
});
|
337 |
+
|
338 |
+
// Delete Filter
|
339 |
+
async function deleteFilter(text) {
|
340 |
+
try {
|
341 |
+
const response = await fetch('/api/delete-filter', {
|
342 |
+
method: 'POST',
|
343 |
+
headers: {
|
344 |
+
'Content-Type': 'application/x-www-form-urlencoded',
|
345 |
+
'Authorization': API_KEY
|
346 |
+
},
|
347 |
+
body: `chat_id=123456789&text=${encodeURIComponent(text)}`, // Replace with actual chat ID
|
348 |
+
});
|
349 |
+
const data = await response.json();
|
350 |
+
alert(data.message);
|
351 |
+
loadFilters();
|
352 |
+
} catch (error) {
|
353 |
+
console.error('Failed to delete filter:', error);
|
354 |
+
alert('Failed to delete filter');
|
355 |
+
}
|
356 |
+
}
|
357 |
+
|
358 |
+
// Add Global Filter
|
359 |
+
document.getElementById('addGFilterForm').addEventListener('submit', async function(event) {
|
360 |
+
event.preventDefault();
|
361 |
+
const text = document.getElementById('gfilterText').value;
|
362 |
+
const replyText = document.getElementById('greplyText').value;
|
363 |
+
const btn = document.getElementById('gbtn').value;
|
364 |
+
const file = document.getElementById('gfile').value;
|
365 |
+
const alert = document.getElementById('galert').value;
|
366 |
+
try {
|
367 |
+
const response = await fetch('/api/add-gfilter', {
|
368 |
+
method: 'POST',
|
369 |
+
headers: {
|
370 |
+
'Content-Type': 'application/x-www-form-urlencoded',
|
371 |
+
'Authorization': API_KEY
|
372 |
+
},
|
373 |
+
body: `text=${encodeURIComponent(text)}&reply_text=${encodeURIComponent(replyText)}&btn=${encodeURIComponent(btn)}&file=${encodeURIComponent(file)}&alert=${encodeURIComponent(alert)}`,
|
374 |
+
});
|
375 |
+
const data = await response.json();
|
376 |
+
alert(data.message);
|
377 |
+
loadGlobalFilters();
|
378 |
+
} catch (error) {
|
379 |
+
console.error('Failed to add global filter:', error);
|
380 |
+
alert('Failed to add global filter');
|
381 |
+
}
|
382 |
+
});
|
383 |
+
|
384 |
+
// Delete Global Filter
|
385 |
+
async function deleteGFilter(text) {
|
386 |
+
try {
|
387 |
+
const response = await fetch('/api/delete-gfilter', {
|
388 |
+
method: 'POST',
|
389 |
+
headers: {
|
390 |
+
'Content-Type': 'application/x-www-form-urlencoded',
|
391 |
+
'Authorization': API_KEY
|
392 |
+
},
|
393 |
+
body: `text=${encodeURIComponent(text)}`,
|
394 |
+
});
|
395 |
+
const data = await response.json();
|
396 |
+
alert(data.message);
|
397 |
+
loadGlobalFilters();
|
398 |
+
} catch (error) {
|
399 |
+
console.error('Failed to delete global filter:', error);
|
400 |
+
alert('Failed to delete global filter');
|
401 |
+
}
|
402 |
+
}
|
403 |
+
|
404 |
+
// Ban User
|
405 |
+
async function banUser(userId, banReason) {
|
406 |
+
try {
|
407 |
+
const response = await fetch('/api/ban-user', {
|
408 |
+
method: 'POST',
|
409 |
+
headers: {
|
410 |
+
'Content-Type': 'application/x-www-form-urlencoded',
|
411 |
+
'Authorization': API_KEY
|
412 |
+
},
|
413 |
+
body: `user_id=${encodeURIComponent(userId)}&ban_reason=${encodeURIComponent(banReason)}`,
|
414 |
+
});
|
415 |
+
const data = await response.json();
|
416 |
+
alert(data.message);
|
417 |
+
loadUsers();
|
418 |
+
} catch (error) {
|
419 |
+
console.error('Failed to ban user:', error);
|
420 |
+
alert('Failed to ban user');
|
421 |
+
}
|
422 |
+
}
|
423 |
+
|
424 |
+
// Unban User
|
425 |
+
async function unbanUser(userId) {
|
426 |
+
try {
|
427 |
+
const response = await fetch('/api/unban-user', {
|
428 |
+
method: 'POST',
|
429 |
+
headers: {
|
430 |
+
'Content-Type': 'application/x-www-form-urlencoded',
|
431 |
+
'Authorization': API_KEY
|
432 |
+
},
|
433 |
+
body: `user_id=${encodeURIComponent(userId)}`,
|
434 |
+
});
|
435 |
+
const data = await response.json();
|
436 |
+
alert(data.message);
|
437 |
+
loadUsers();
|
438 |
+
} catch (error) {
|
439 |
+
console.error('Failed to unban user:', error);
|
440 |
+
alert('Failed to unban user');
|
441 |
+
}
|
442 |
+
}
|
443 |
+
|
444 |
+
// Disable Chat
|
445 |
+
async function disableChat(chatId, reason) {
|
446 |
+
try {
|
447 |
+
const response = await fetch('/api/disable-chat', {
|
448 |
+
method: 'POST',
|
449 |
+
headers: {
|
450 |
+
'Content-Type': 'application/x-www-form-urlencoded',
|
451 |
+
'Authorization': API_KEY
|
452 |
+
},
|
453 |
+
body: `chat_id=${encodeURIComponent(chatId)}&reason=${encodeURIComponent(reason)}`,
|
454 |
+
});
|
455 |
+
const data = await response.json();
|
456 |
+
alert(data.message);
|
457 |
+
loadChats();
|
458 |
+
} catch (error) {
|
459 |
+
console.error('Failed to disable chat:', error);
|
460 |
+
alert('Failed to disable chat');
|
461 |
+
}
|
462 |
+
}
|
463 |
+
|
464 |
+
// Enable Chat
|
465 |
+
async function enableChat(chatId) {
|
466 |
+
try {
|
467 |
+
const response = await fetch('/api/enable-chat', {
|
468 |
+
method: 'POST',
|
469 |
+
headers: {
|
470 |
+
'Content-Type': 'application/x-www-form-urlencoded',
|
471 |
+
'Authorization': API_KEY
|
472 |
+
},
|
473 |
+
body: `chat_id=${encodeURIComponent(chatId)}`,
|
474 |
+
});
|
475 |
+
const data = await response.json();
|
476 |
+
alert(data.message);
|
477 |
+
loadChats();
|
478 |
+
} catch (error) {
|
479 |
+
console.error('Failed to enable chat:', error);
|
480 |
+
alert('Failed to enable chat');
|
481 |
+
}
|
482 |
+
}
|
483 |
+
|
484 |
+
// Upload File
|
485 |
+
document.getElementById('uploadFileForm').addEventListener('submit', async function(event) {
|
486 |
+
event.preventDefault();
|
487 |
+
const formData = new FormData(this);
|
488 |
+
try {
|
489 |
+
const response = await fetch('/api/upload-file', {
|
490 |
+
method: 'POST',
|
491 |
+
headers: {
|
492 |
+
'Authorization': API_KEY
|
493 |
+
},
|
494 |
+
body: formData,
|
495 |
+
});
|
496 |
+
const data = await response.json();
|
497 |
+
alert(data.message);
|
498 |
+
loadFiles();
|
499 |
+
} catch (error) {
|
500 |
+
console.error('Failed to upload file:', error);
|
501 |
+
alert('Failed to upload file');
|
502 |
+
}
|
503 |
+
});
|
504 |
+
|
505 |
+
// Delete File
|
506 |
+
async function deleteFile(fileId) {
|
507 |
+
try {
|
508 |
+
const response = await fetch('/api/delete-file', {
|
509 |
+
method: 'POST',
|
510 |
+
headers: {
|
511 |
+
'Content-Type': 'application/x-www-form-urlencoded',
|
512 |
+
'Authorization': API_KEY
|
513 |
+
},
|
514 |
+
body: `file_id=${encodeURIComponent(fileId)}`,
|
515 |
+
});
|
516 |
+
const data = await response.json();
|
517 |
+
alert(data.message);
|
518 |
+
loadFiles();
|
519 |
+
} catch (error) {
|
520 |
+
console.error('Failed to delete file:', error);
|
521 |
+
alert('Failed to delete file');
|
522 |
+
}
|
523 |
+
}
|
524 |
+
|
525 |
+
// Broadcast Message
|
526 |
+
document.getElementById('broadcastForm').addEventListener('submit', async function(event) {
|
527 |
+
event.preventDefault();
|
528 |
+
const messageText = document.getElementById('broadcastText').value;
|
529 |
+
try {
|
530 |
+
const response = await fetch('/api/broadcast', {
|
531 |
+
method: 'POST',
|
532 |
+
headers: {
|
533 |
+
'Content-Type': 'application/x-www-form-urlencoded',
|
534 |
+
'Authorization': API_KEY
|
535 |
+
},
|
536 |
+
body: `message_text=${encodeURIComponent(messageText)}`,
|
537 |
+
});
|
538 |
+
const data = await response.json();
|
539 |
+
alert(`Broadcast completed. Success: ${data.success}, Blocked: ${data.blocked}, Deleted: ${data.deleted}`);
|
540 |
+
} catch (error) {
|
541 |
+
console.error('Failed to broadcast message:', error);
|
542 |
+
alert('Failed to broadcast message');
|
543 |
+
}
|
544 |
+
});
|
545 |
+
|
546 |
+
// Add Connection
|
547 |
+
document.getElementById('addConnectionForm').addEventListener('submit', async function(event) {
|
548 |
+
event.preventDefault();
|
549 |
+
const groupId = document.getElementById('groupId').value;
|
550 |
+
const userId = document.getElementById('userId').value;
|
551 |
+
try {
|
552 |
+
const response = await fetch('/api/add-connection', {
|
553 |
+
method: 'POST',
|
554 |
+
headers: {
|
555 |
+
'Content-Type': 'application/x-www-form-urlencoded',
|
556 |
+
'Authorization': API_KEY
|
557 |
+
},
|
558 |
+
body: `group_id=${encodeURIComponent(groupId)}&user_id=${encodeURIComponent(userId)}`,
|
559 |
+
});
|
560 |
+
const data = await response.json();
|
561 |
+
alert(data.message);
|
562 |
+
loadConnections();
|
563 |
+
} catch (error) {
|
564 |
+
console.error('Failed to add connection:', error);
|
565 |
+
alert('Failed to add connection');
|
566 |
+
}
|
567 |
+
});
|
568 |
+
|
569 |
+
// Delete Connection
|
570 |
+
async function deleteConnection(groupId, userId) {
|
571 |
+
try {
|
572 |
+
const response = await fetch('/api/delete-connection', {
|
573 |
+
method: 'POST',
|
574 |
+
headers: {
|
575 |
+
'Content-Type': 'application/x-www-form-urlencoded',
|
576 |
+
'Authorization': API_KEY
|
577 |
+
},
|
578 |
+
body: `group_id=${encodeURIComponent(groupId)}&user_id=${encodeURIComponent(userId)}`,
|
579 |
+
});
|
580 |
+
const data = await response.json();
|
581 |
+
alert(data.message);
|
582 |
+
loadConnections();
|
583 |
+
} catch (error) {
|
584 |
+
console.error('Failed to delete connection:', error);
|
585 |
+
alert('Failed to delete connection');
|
586 |
+
}
|
587 |
+
}
|
588 |
+
|
589 |
+
// Save Settings
|
590 |
+
document.getElementById('saveSettingsForm').addEventListener('submit', async function(event) {
|
591 |
+
event.preventDefault();
|
592 |
+
const chatId = document.getElementById('settingsChatId').value;
|
593 |
+
const settingKey = document.getElementById('settingKey').value;
|
594 |
+
const settingValue = document.getElementById('settingValue').value;
|
595 |
+
try {
|
596 |
+
const response = await fetch('/api/save-settings', {
|
597 |
+
method: 'POST',
|
598 |
+
headers: {
|
599 |
+
'Content-Type': 'application/x-www-form-urlencoded',
|
600 |
+
'Authorization': API_KEY
|
601 |
+
},
|
602 |
+
body: `chat_id=${encodeURIComponent(chatId)}&setting_key=${encodeURIComponent(settingKey)}&setting_value=${encodeURIComponent(settingValue)}`,
|
603 |
+
});
|
604 |
+
const data = await response.json();
|
605 |
+
alert(data.message);
|
606 |
+
} catch (error) {
|
607 |
+
console.error('Failed to save settings:', error);
|
608 |
+
alert('Failed to save settings');
|
609 |
+
}
|
610 |
+
});
|
611 |
+
|
612 |
+
// Restart Bot
|
613 |
+
document.getElementById('restartBotForm').addEventListener('submit', async function(event) {
|
614 |
+
event.preventDefault();
|
615 |
+
try {
|
616 |
+
const response = await fetch('/api/restart-bot', {
|
617 |
+
method: 'POST',
|
618 |
+
headers: {
|
619 |
+
'Content-Type': 'application/x-www-form-urlencoded',
|
620 |
+
'Authorization': API_KEY
|
621 |
+
},
|
622 |
+
body: `admin_id=${encodeURIComponent(${ADMINS[0]})}`, // Replace with actual admin ID
|
623 |
+
});
|
624 |
+
const data = await response.json();
|
625 |
+
alert(data.message);
|
626 |
+
} catch (error) {
|
627 |
+
console.error('Failed to restart bot:', error);
|
628 |
+
alert('Failed to restart bot');
|
629 |
+
}
|
630 |
+
});
|
631 |
+
|
632 |
+
// Performance Chart
|
633 |
+
const performanceCtx = document.getElementById('performanceChart').getContext('2d');
|
634 |
+
new Chart(performanceCtx, {
|
635 |
+
type: 'line',
|
636 |
+
data: {
|
637 |
+
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
|
638 |
+
datasets: [{
|
639 |
+
label: 'Uploads',
|
640 |
+
data: [65, 59, 80, 81, 56, 55],
|
641 |
+
borderColor: '#3b82f6',
|
642 |
+
tension: 0.4
|
643 |
+
}]
|
644 |
+
},
|
645 |
+
options: {
|
646 |
+
responsive: true,
|
647 |
+
maintainAspectRatio: false,
|
648 |
+
scales: {
|
649 |
+
y: {
|
650 |
+
beginAtZero: true
|
651 |
+
}
|
652 |
+
}
|
653 |
+
}
|
654 |
+
});
|
655 |
+
|
656 |
+
// Platform Distribution Chart
|
657 |
+
const platformCtx = document.getElementById('platformChart').getContext('2d');
|
658 |
+
new Chart(platformCtx, {
|
659 |
+
type: 'doughnut',
|
660 |
+
data: {
|
661 |
+
labels: ['YouTube', 'Instagram', 'Facebook', 'WhatsApp', 'Pinterest', 'LinkedIn', 'TikTok', 'Twitter', 'Reddit', 'Telegram'],
|
662 |
+
datasets: [{
|
663 |
+
data: [45, 30, 25, 15, 10, 8, 7, 6, 5, 4],
|
664 |
+
backgroundColor: ['#ff0000', '#e4405f', '#1877F2', '#25D366', '#BD081C', '#0077B5', '#000000', '#1DA1F2', '#FF4500', '#0088CC']
|
665 |
+
}]
|
666 |
+
},
|
667 |
+
options: {
|
668 |
+
responsive: true,
|
669 |
+
maintainAspectRatio: false
|
670 |
+
}
|
671 |
+
});
|
672 |
+
|
673 |
+
// Fetch System Info on Page Load
|
674 |
+
document.addEventListener('DOMContentLoaded', function() {
|
675 |
+
fetchSystemInfo();
|
676 |
+
fetchBotStats();
|
677 |
+
fetchBotStatus();
|
678 |
+
loadFilters();
|
679 |
+
loadGlobalFilters();
|
680 |
+
loadUsers();
|
681 |
+
loadChats();
|
682 |
+
loadFiles();
|
683 |
+
loadConnections();
|
684 |
+
});
|
685 |
+
|
686 |
+
// Utility Function to Format Size
|
687 |
+
function get_size(size) {
|
688 |
+
const units = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB"];
|
689 |
+
size = parseFloat(size);
|
690 |
+
let i = 0;
|
691 |
+
while (size >= 1024.0 && i < units.length) {
|
692 |
+
i += 1;
|
693 |
+
size /= 1024.0;
|
694 |
+
}
|
695 |
+
return `${size.toFixed(2)} ${units[i]}`;
|
696 |
}
|