Brozy123 commited on
Commit
95fe044
·
verified ·
1 Parent(s): 1561126

Update dashboard.html

Browse files
Files changed (1) hide show
  1. dashboard.html +71 -61
dashboard.html CHANGED
@@ -92,10 +92,27 @@ body {
92
  font-family: 'Inter', sans-serif;
93
  cursor: pointer;
94
  transition: all 0.2s;
 
 
 
 
95
  }
96
  .login-card button:hover { background: #4752c4; transform: translateY(-1px); box-shadow: 0 8px 30px var(--accent-glow); }
 
97
 
98
- .login-error { color: var(--red); font-size: 13px; margin-top: 10px; display: none; }
 
 
 
 
 
 
 
 
 
 
 
 
99
 
100
  /* ===== DASHBOARD ===== */
101
  #dashboard { display: none; }
@@ -361,10 +378,13 @@ body {
361
  <div class="login-card">
362
  <img src="/logo.png" alt="FriendlyBot">
363
  <h1>FriendlyBot</h1>
364
- <p>Enter your dashboard password to continue</p>
365
- <input type="password" id="login-password" placeholder="Dashboard Password" autocomplete="current-password">
366
- <button onclick="attemptLogin()">Sign In</button>
367
- <div class="login-error" id="login-error">Incorrect password. Please try again.</div>
 
 
 
368
  </div>
369
  </div>
370
 
@@ -413,6 +433,10 @@ body {
413
  <div class="topbar">
414
  <h2>Dashboard</h2>
415
  <div class="topbar-right">
 
 
 
 
416
  <div class="status-pill"><div class="status-dot"></div> Online</div>
417
  </div>
418
  </div>
@@ -546,69 +570,57 @@ body {
546
  </div>
547
 
548
  <script>
549
- // ===== AUTH =====
550
- const DASH_KEY = 'fb_dash_auth';
551
-
552
- function attemptLogin() {
553
- const pw = document.getElementById('login-password').value;
554
- fetch('/api/login', {
555
- method: 'POST',
556
- headers: { 'Content-Type': 'application/json' },
557
- body: JSON.stringify({ password: pw })
558
- })
 
 
 
 
 
 
559
  .then(r => r.json())
560
  .then(data => {
561
- if (data.success) {
562
- localStorage.setItem(DASH_KEY, pw);
563
  showDashboard();
564
- } else {
565
- document.getElementById('login-error').style.display = 'block';
 
 
566
  }
567
  })
568
- .catch(() => {
569
- document.getElementById('login-error').textContent = 'Connection failed.';
570
- document.getElementById('login-error').style.display = 'block';
571
- });
572
- }
573
-
574
- // Enter key for login
575
- document.addEventListener('DOMContentLoaded', () => {
576
- document.getElementById('login-password').addEventListener('keydown', e => {
577
- if (e.key === 'Enter') attemptLogin();
578
- });
579
- // Auto-login
580
- const saved = localStorage.getItem(DASH_KEY);
581
- if (saved) {
582
- fetch('/api/login', {
583
- method: 'POST',
584
- headers: { 'Content-Type': 'application/json' },
585
- body: JSON.stringify({ password: saved })
586
- })
587
- .then(r => r.json())
588
- .then(data => { if (data.success) showDashboard(); })
589
- .catch(() => {});
590
- }
591
  });
592
 
593
  function showDashboard() {
594
  document.getElementById('login-screen').style.display = 'none';
595
  document.getElementById('dashboard').style.display = 'block';
 
 
 
 
 
 
 
 
596
  loadStats();
597
  loadServers();
598
  loadCommands();
599
  loadLogs();
600
- // Auto-refresh every 10s
601
  setInterval(loadStats, 10000);
602
  setInterval(loadLogs, 8000);
603
  }
604
 
605
  function logout() {
606
- localStorage.removeItem(DASH_KEY);
607
- location.reload();
608
- }
609
-
610
- function getAuth() {
611
- return localStorage.getItem(DASH_KEY);
612
  }
613
 
614
  // ===== NAVIGATION =====
@@ -621,7 +633,7 @@ function showPage(name, el) {
621
 
622
  // ===== DATA LOADERS =====
623
  function loadStats() {
624
- fetch('/api/stats', { headers: { 'x-auth': getAuth() } })
625
  .then(r => r.json())
626
  .then(data => {
627
  document.getElementById('stat-servers').textContent = data.servers || 0;
@@ -629,27 +641,26 @@ function loadStats() {
629
  document.getElementById('stat-uptime').textContent = data.uptime || '—';
630
  document.getElementById('stat-commands').textContent = data.commands || 0;
631
  document.getElementById('server-count-label').textContent = (data.servers || 0) + ' Servers';
632
-
633
- // Update invite link
634
- if (data.inviteUrl) {
635
- document.getElementById('invite-link').href = data.inviteUrl;
636
- }
637
  }).catch(() => {});
638
  }
639
 
640
  function loadServers() {
641
- fetch('/api/servers', { headers: { 'x-auth': getAuth() } })
642
  .then(r => r.json())
643
  .then(data => {
644
  const container = document.getElementById('server-list');
645
  container.innerHTML = '';
646
  data.sort((a, b) => b.members - a.members);
647
  data.forEach((s, i) => {
 
 
 
648
  container.innerHTML += `
649
  <div class="server-row">
650
  <div class="server-info">
651
  <span class="server-rank">#${i + 1}</span>
652
- <div class="server-icon">${s.name.charAt(0).toUpperCase()}</div>
653
  <div>
654
  <div class="server-name">${escapeHtml(s.name)}</div>
655
  <div class="server-members">${s.id}</div>
@@ -662,7 +673,7 @@ function loadServers() {
662
  }
663
 
664
  function loadCommands() {
665
- fetch('/api/commands', { headers: { 'x-auth': getAuth() } })
666
  .then(r => r.json())
667
  .then(data => {
668
  const container = document.getElementById('command-list');
@@ -684,7 +695,7 @@ function loadCommands() {
684
  }
685
 
686
  function loadLogs() {
687
- fetch('/api/logs', { headers: { 'x-auth': getAuth() } })
688
  .then(r => r.json())
689
  .then(data => {
690
  const area = document.getElementById('log-area');
@@ -698,9 +709,8 @@ function loadLogs() {
698
  }).catch(() => {});
699
  }
700
 
701
- // ===== ACTIONS =====
702
  function triggerAction(action) {
703
- fetch('/api/action/' + action, { method: 'POST', headers: { 'x-auth': getAuth() } })
704
  .then(r => r.json())
705
  .then(data => {
706
  alert(data.message || 'Action triggered!');
 
92
  font-family: 'Inter', sans-serif;
93
  cursor: pointer;
94
  transition: all 0.2s;
95
+ display: inline-flex;
96
+ align-items: center;
97
+ justify-content: center;
98
+ gap: 10px;
99
  }
100
  .login-card button:hover { background: #4752c4; transform: translateY(-1px); box-shadow: 0 8px 30px var(--accent-glow); }
101
+ .login-card button svg { width: 20px; height: 20px; }
102
 
103
+ .login-error { color: var(--red); font-size: 13px; margin-top: 14px; display: none; }
104
+ .login-info { color: var(--text-dim); font-size: 12px; margin-top: 16px; line-height: 1.6; }
105
+
106
+ .user-pill {
107
+ display: flex;
108
+ align-items: center;
109
+ gap: 10px;
110
+ padding: 8px 14px;
111
+ background: var(--surface2);
112
+ border-radius: 100px;
113
+ }
114
+ .user-pill img { width: 28px; height: 28px; border-radius: 50%; }
115
+ .user-pill span { font-size: 13px; font-weight: 600; }
116
 
117
  /* ===== DASHBOARD ===== */
118
  #dashboard { display: none; }
 
378
  <div class="login-card">
379
  <img src="/logo.png" alt="FriendlyBot">
380
  <h1>FriendlyBot</h1>
381
+ <p>Sign in with your Discord account to access the dashboard</p>
382
+ <button onclick="window.location.href='/auth/login'">
383
+ <svg viewBox="0 0 24 24" fill="currentColor"><path d="M20.317 4.37a19.791 19.791 0 0 0-4.885-1.515.074.074 0 0 0-.079.037c-.21.375-.444.864-.608 1.25a18.27 18.27 0 0 0-5.487 0 12.64 12.64 0 0 0-.617-1.25.077.077 0 0 0-.079-.037A19.736 19.736 0 0 0 3.677 4.37a.07.07 0 0 0-.032.027C.533 9.046-.32 13.58.099 18.057a.082.082 0 0 0 .031.057 19.9 19.9 0 0 0 5.993 3.03.078.078 0 0 0 .084-.028c.462-.63.874-1.295 1.226-1.994a.076.076 0 0 0-.041-.106 13.107 13.107 0 0 1-1.872-.892.077.077 0 0 1-.008-.128 10.2 10.2 0 0 0 .372-.292.074.074 0 0 1 .077-.01c3.928 1.793 8.18 1.793 12.062 0a.074.074 0 0 1 .078.01c.12.098.246.198.373.292a.077.077 0 0 1-.006.127 12.299 12.299 0 0 1-1.873.892.077.077 0 0 0-.041.107c.36.698.772 1.362 1.225 1.993a.076.076 0 0 0 .084.028 19.839 19.839 0 0 0 6.002-3.03.077.077 0 0 0 .032-.054c.5-5.177-.838-9.674-3.549-13.66a.061.061 0 0 0-.031-.03z"/></svg>
384
+ Login with Discord
385
+ </button>
386
+ <div class="login-error" id="login-error"></div>
387
+ <div class="login-info">Only the bot owner and authorized users can access this dashboard.</div>
388
  </div>
389
  </div>
390
 
 
433
  <div class="topbar">
434
  <h2>Dashboard</h2>
435
  <div class="topbar-right">
436
+ <div class="user-pill" id="user-pill" style="display:none">
437
+ <img id="user-avatar" src="" alt="">
438
+ <span id="user-name"></span>
439
+ </div>
440
  <div class="status-pill"><div class="status-dot"></div> Online</div>
441
  </div>
442
  </div>
 
570
  </div>
571
 
572
  <script>
573
+ // ===== AUTH (Discord OAuth2 via httpOnly cookie) =====
574
+ let currentUser = null;
575
+
576
+ document.addEventListener('DOMContentLoaded', () => {
577
+ // Check URL params for errors
578
+ const params = new URLSearchParams(window.location.search);
579
+ if (params.get('error') === 'not_owner') {
580
+ document.getElementById('login-error').textContent = '❌ Access denied. Only the bot owner can access this dashboard.';
581
+ document.getElementById('login-error').style.display = 'block';
582
+ } else if (params.get('error')) {
583
+ document.getElementById('login-error').textContent = '❌ Login failed. Please try again.';
584
+ document.getElementById('login-error').style.display = 'block';
585
+ }
586
+
587
+ // Check for existing session
588
+ fetch('/api/me')
589
  .then(r => r.json())
590
  .then(data => {
591
+ if (data.loggedIn) {
592
+ currentUser = data.user;
593
  showDashboard();
594
+ // Clean URL
595
+ if (params.has('login') || params.has('error')) {
596
+ window.history.replaceState({}, '', '/');
597
+ }
598
  }
599
  })
600
+ .catch(() => {});
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
601
  });
602
 
603
  function showDashboard() {
604
  document.getElementById('login-screen').style.display = 'none';
605
  document.getElementById('dashboard').style.display = 'block';
606
+
607
+ // Show user info
608
+ if (currentUser) {
609
+ document.getElementById('user-avatar').src = currentUser.avatar;
610
+ document.getElementById('user-name').textContent = currentUser.username;
611
+ document.getElementById('user-pill').style.display = 'flex';
612
+ }
613
+
614
  loadStats();
615
  loadServers();
616
  loadCommands();
617
  loadLogs();
 
618
  setInterval(loadStats, 10000);
619
  setInterval(loadLogs, 8000);
620
  }
621
 
622
  function logout() {
623
+ window.location.href = '/auth/logout';
 
 
 
 
 
624
  }
625
 
626
  // ===== NAVIGATION =====
 
633
 
634
  // ===== DATA LOADERS =====
635
  function loadStats() {
636
+ fetch('/api/stats')
637
  .then(r => r.json())
638
  .then(data => {
639
  document.getElementById('stat-servers').textContent = data.servers || 0;
 
641
  document.getElementById('stat-uptime').textContent = data.uptime || '—';
642
  document.getElementById('stat-commands').textContent = data.commands || 0;
643
  document.getElementById('server-count-label').textContent = (data.servers || 0) + ' Servers';
644
+ if (data.inviteUrl) document.getElementById('invite-link').href = data.inviteUrl;
 
 
 
 
645
  }).catch(() => {});
646
  }
647
 
648
  function loadServers() {
649
+ fetch('/api/servers')
650
  .then(r => r.json())
651
  .then(data => {
652
  const container = document.getElementById('server-list');
653
  container.innerHTML = '';
654
  data.sort((a, b) => b.members - a.members);
655
  data.forEach((s, i) => {
656
+ const iconHtml = s.icon
657
+ ? `<img class="server-icon" src="${s.icon}" style="object-fit:cover">`
658
+ : `<div class="server-icon">${s.name.charAt(0).toUpperCase()}</div>`;
659
  container.innerHTML += `
660
  <div class="server-row">
661
  <div class="server-info">
662
  <span class="server-rank">#${i + 1}</span>
663
+ ${iconHtml}
664
  <div>
665
  <div class="server-name">${escapeHtml(s.name)}</div>
666
  <div class="server-members">${s.id}</div>
 
673
  }
674
 
675
  function loadCommands() {
676
+ fetch('/api/commands')
677
  .then(r => r.json())
678
  .then(data => {
679
  const container = document.getElementById('command-list');
 
695
  }
696
 
697
  function loadLogs() {
698
+ fetch('/api/logs')
699
  .then(r => r.json())
700
  .then(data => {
701
  const area = document.getElementById('log-area');
 
709
  }).catch(() => {});
710
  }
711
 
 
712
  function triggerAction(action) {
713
+ fetch('/api/action/' + action, { method: 'POST' })
714
  .then(r => r.json())
715
  .then(data => {
716
  alert(data.message || 'Action triggered!');