dashboard.html 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. {% extends "layout.html" %}
  2. {% block content %}
  3. <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
  4. <div class="flex justify-between items-center mb-6">
  5. <div>
  6. <h2 class="text-4xl font-black text-white tracking-tighter italic">DNS Zones Dashboard</h2>
  7. {% if session.get('role') == 'admin' %}
  8. <div class="flex items-center gap-4 mt-2">
  9. <div class="flex items-center gap-2">
  10. <span id="status-dot" class="w-2.5 h-2.5 rounded-full bg-gray-600 transition-all duration-500"></span>
  11. <span id="status-text" class="text-[10px] font-bold text-gray-500 uppercase tracking-widest leading-none">Checking Service...</span>
  12. </div>
  13. <div class="flex gap-2 border-l border-gray-800 pl-4">
  14. <a href="/service/start" class="text-[9px] bg-green-600/20 text-green-400 px-3 py-1 rounded font-black border border-green-500/30">Start</a>
  15. <a href="/service/stop" class="text-[9px] bg-red-600/20 text-red-400 px-3 py-1 rounded font-black border border-red-500/30">Stop</a>
  16. <a href="/service/restart" class="text-[9px] bg-yellow-600/20 text-yellow-400 hover:bg-yellow-600/40 px-3 py-1 rounded font-black border border-yellow-500/30">Restart</a>
  17. <a href="/service/reload" title="Reload" class="text-[9px] bg-blue-600/20 text-blue-400 px-3 py-1 rounded font-black border border-blue-500/30">Apply</a>
  18. </div>
  19. </div>
  20. {% endif %}
  21. </div>
  22. <div class="flex gap-3">
  23. {% if session.get('role') == 'admin' %}
  24. <button onclick="openBackupModal()" class="bg-gray-800 hover:bg-gray-700 border border-gray-700 px-6 py-3 rounded-xl font-black shadow-lg transition text-white uppercase text-xs tracking-widest flex items-center gap-2">
  25. <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"></path></svg>Backup
  26. </button>
  27. {% endif %}
  28. <button onclick="openAddModal()" class="bg-blue-600 hover:bg-blue-500 px-8 py-3 rounded-xl font-black shadow-2xl transition transform hover:scale-105 text-white uppercase text-xs tracking-widest">+ New Zone</button>
  29. </div>
  30. </div>
  31. {% if session.get('role') == 'admin' %}
  32. <div class="grid grid-cols-1 lg:grid-cols-3 gap-6 mb-10">
  33. <div class="bg-[#12161f] border border-gray-800 rounded-2xl p-6 shadow-xl relative">
  34. <div class="flex justify-between items-center mb-4">
  35. <h3 class="text-[10px] font-black text-gray-500 uppercase tracking-widest">Requests Per Second</h3>
  36. <span class="flex h-2 w-2 relative"><span class="animate-ping absolute inline-flex h-full w-full rounded-full bg-blue-400 opacity-75"></span><span class="relative inline-flex rounded-full h-2 w-2 bg-blue-500"></span></span>
  37. </div>
  38. <div class="h-40"><canvas id="rpsChart"></canvas></div>
  39. </div>
  40. <div class="bg-[#12161f] border border-gray-800 rounded-2xl p-6 shadow-xl relative">
  41. <div class="flex justify-between items-center mb-4">
  42. <h3 class="text-[10px] font-black text-gray-500 uppercase tracking-widest">Top TLDs</h3>
  43. <span class="flex h-2 w-2 relative"><span class="animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75"></span><span class="relative inline-flex rounded-full h-2 w-2 bg-green-500"></span></span>
  44. </div>
  45. <div class="h-40 flex justify-center"><canvas id="tldChart"></canvas></div>
  46. </div>
  47. <div class="bg-[#12161f] border border-gray-800 rounded-2xl p-6 shadow-xl relative">
  48. <div class="flex justify-between items-center mb-4">
  49. <h3 class="text-[10px] font-black text-gray-500 uppercase tracking-widest">Unique IPs</h3>
  50. <span class="flex h-2 w-2 relative"><span class="animate-ping absolute inline-flex h-full w-full rounded-full bg-purple-400 opacity-75"></span><span class="relative inline-flex rounded-full h-2 w-2 bg-purple-500"></span></span>
  51. </div>
  52. <div class="h-40"><canvas id="ipsChart"></canvas></div>
  53. </div>
  54. </div>
  55. <script>
  56. let rpsChartInst = null, ipsChartInst = null, tldChartInst = null;
  57. function renderLiveCharts() {
  58. fetch('/api/stats').then(r => r.json()).then(data => {
  59. const today = new Date().toISOString().split('T')[0];
  60. const todayData = data[today] || { timeline: {}, tlds: {} };
  61. const times = Object.keys(todayData.timeline).sort();
  62. const rpsData = times.map(t => todayData.timeline[t].rps);
  63. const ipsData = times.map(t => todayData.timeline[t].unique_ips);
  64. const tldLabels = Object.keys(todayData.tlds).sort((a,b) => todayData.tlds[b] - todayData.tlds[a]).slice(0, 5);
  65. const tldData = tldLabels.map(t => todayData.tlds[t]);
  66. const chartOptions = { animation: false, interaction: { mode: 'index', intersect: false }, responsive: true, maintainAspectRatio: false, plugins: { legend: { display: false } }, scales: { x: { display: false }, y: { grid: { color: '#1f2937' }, beginAtZero: true } } };
  67. if(!rpsChartInst) {
  68. rpsChartInst = new Chart(document.getElementById('rpsChart'), { type: 'line', data: { labels: times, datasets: [{ label: 'RPS', data: rpsData, borderColor: '#3b82f6', fill: true, tension: 0.4 }] }, options: chartOptions });
  69. } else {
  70. rpsChartInst.data.labels = times; rpsChartInst.data.datasets[0].data = rpsData; rpsChartInst.update('none');
  71. }
  72. if(!ipsChartInst) {
  73. ipsChartInst = new Chart(document.getElementById('ipsChart'), { type: 'bar', data: { labels: times, datasets: [{ label: 'Unique IPs', data: ipsData, backgroundColor: '#8b5cf6' }] }, options: chartOptions });
  74. } else {
  75. ipsChartInst.data.labels = times; ipsChartInst.data.datasets[0].data = ipsData; ipsChartInst.update('none');
  76. }
  77. if(!tldChartInst) {
  78. tldChartInst = new Chart(document.getElementById('tldChart'), { type: 'doughnut', data: { labels: tldLabels, datasets: [{ data: tldData, backgroundColor: ['#3b82f6', '#10b981', '#f59e0b', '#8b5cf6', '#6366f1'], borderWidth: 0 }] }, options: { animation: false, interaction: { mode: 'index', intersect: false }, responsive: true, maintainAspectRatio: false, plugins: { legend: { position: 'right', labels: { color: '#9ca3af', font: { size: 10 } } } }, cutout: '70%' } });
  79. } else {
  80. tldChartInst.data.labels = tldLabels; tldChartInst.data.datasets[0].data = tldData; tldChartInst.update('none');
  81. }
  82. }).catch(e => console.log('Stats sync error:', e));
  83. }
  84. document.addEventListener("DOMContentLoaded", () => {
  85. renderLiveCharts();
  86. setInterval(renderLiveCharts, 10000);
  87. });
  88. </script>
  89. {% endif %}
  90. <div class="flex border-b border-gray-800 mb-6 gap-6 overflow-x-auto whitespace-nowrap scrollbar-hide">
  91. <button onclick="switchTab('master_forward')" id="btnTab_master_forward" class="pb-4 text-[10px] font-black uppercase tracking-widest text-blue-500 border-b-2 border-blue-500 transition focus:outline-none">Master Forward</button>
  92. <button onclick="switchTab('master_reverse')" id="btnTab_master_reverse" class="pb-4 text-[10px] font-black uppercase tracking-widest text-gray-500 border-b-2 border-transparent hover:text-gray-300 transition focus:outline-none">Master Reverse</button>
  93. <button onclick="switchTab('slave_forward')" id="btnTab_slave_forward" class="pb-4 text-[10px] font-black uppercase tracking-widest text-gray-500 border-b-2 border-transparent hover:text-gray-300 transition focus:outline-none">Slave Forward</button>
  94. <button onclick="switchTab('slave_reverse')" id="btnTab_slave_reverse" class="pb-4 text-[10px] font-black uppercase tracking-widest text-gray-500 border-b-2 border-transparent hover:text-gray-300 transition focus:outline-none">Slave Reverse</button>
  95. <button onclick="switchTab('forward_zones')" id="btnTab_forward_zones" class="pb-4 text-[10px] font-black uppercase tracking-widest text-gray-500 border-b-2 border-transparent hover:text-gray-300 transition focus:outline-none">Forward Zones</button>
  96. </div>
  97. <div class="flex flex-col md:flex-row gap-4 mb-8">
  98. <input type="text" id="zoneSearch" onkeyup="filterZones()" placeholder="Search zones..." class="flex-1 bg-[#12161f] border border-gray-800 rounded-2xl py-4 px-6 text-white font-mono outline-none focus:border-blue-500 transition text-sm">
  99. <div class="flex bg-[#12161f] border border-gray-800 rounded-2xl p-1 h-[54px]">
  100. <button onclick="changeViewMode('cards')" id="btnViewCards" class="px-6 rounded-xl text-xs font-black uppercase transition {% if view_mode != 'table' %}bg-blue-600 text-white shadow-lg{% else %}text-gray-500{% endif %}">Cards</button>
  101. <button onclick="changeViewMode('table')" id="btnViewTable" class="px-6 rounded-xl text-xs font-black uppercase transition {% if view_mode == 'table' %}bg-blue-600 text-white shadow-lg{% else %}text-gray-500{% endif %}">Table</button>
  102. </div>
  103. </div>
  104. <div id="dashboard-dynamic-content">
  105. <div class="{% if view_mode == 'table' %}hidden{% endif %} grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-6" id="zonesGrid">
  106. {% for zone_name, ztype in zones %}
  107. {% set url_param = 'root_zone' if zone_name == '.' else zone_name %}
  108. {% set is_reverse = '.arpa' in zone_name %}
  109. {% set is_master = ztype == 'master' or ztype == 'hint' %}
  110. {% set is_hint = ztype == 'hint' %}
  111. {% set is_forward = ztype == 'forward' %}
  112. {% set tab_cat = 'forward_zones' if is_forward else ('master_forward' if is_master and not is_reverse else 'master_reverse' if is_master and is_reverse else 'slave_forward' if not is_master and not is_reverse else 'slave_reverse') %}
  113. {% set friendly_name = zone_name %}
  114. {% if is_reverse %}
  115. {% set rev_parts = zone_name.replace('.in-addr.arpa', '').replace('.ip6.arpa', '').split('.') %}
  116. {% set friendly_name = (rev_parts | reverse | join('.')) ~ '.x (Reverse)' %}
  117. {% endif %}
  118. <div class="zone-item zone-card bg-[#12161f] border border-gray-800 rounded-2xl p-6 shadow-xl hover:border-blue-500/40 transition group relative" data-domain="{{ zone_name|lower }}" data-owner="{{ owners.get(zone_name, 'admin')|lower }}" data-category="{{ tab_cat }}">
  119. <div class="flex justify-between items-start mb-4">
  120. <div class="flex gap-2 flex-wrap">
  121. <span class="text-[9px] font-black uppercase tracking-widest px-2 py-1 rounded bg-gray-900 {% if is_hint %}text-yellow-400 border border-yellow-500/20{% elif ztype=='master' %}text-green-400 border border-green-500/20{% elif ztype=='forward' %}text-cyan-400 border border-cyan-500/20{% else %}text-blue-400 border border-blue-500/20{% endif %}">{{ ztype }}</span>
  122. {% if is_hint %}<span class="text-[9px] font-black uppercase tracking-widest px-2 py-1 rounded bg-red-900/30 text-red-500">ROOT</span>{% endif %}
  123. {% if session.get('role') == 'admin' %}
  124. <span class="text-[9px] font-black text-gray-400 bg-gray-800/50 px-2 py-1 rounded">{{ owners.get(zone_name, 'admin') }}</span>
  125. <button onclick="openAssignModal('{{ zone_name }}', '{{ owners.get(zone_name, 'admin') }}')" class="text-[9px] bg-blue-600/20 text-blue-400 px-2 py-1 rounded border border-blue-500/30">Assign</button>
  126. {% endif %}
  127. </div>
  128. <div class="flex gap-3 opacity-0 group-hover:opacity-100 transition items-center">
  129. {% if is_master and not is_hint %}
  130. <form action="/zones/manage/{{ url_param }}/cluster_sync" method="POST" onsubmit="handleAjaxForm(event, this, 'dashboard-dynamic-content', restoreDashboardState)">
  131. <button type="submit" class="text-blue-400 text-[10px] font-black uppercase tracking-widest hover:text-blue-300 transition">Cluster Sync</button>
  132. </form>
  133. {% endif %}
  134. <a href="/zones/delete/{{ url_param }}" onclick="handleAjaxLink(event, this, 'dashboard-dynamic-content', restoreDashboardState, 'Delete this zone permanently?')" class="text-red-500 text-[10px] font-black uppercase tracking-widest hover:text-red-400 transition">Delete</a>
  135. </div>
  136. </div>
  137. <h3 class="text-xl font-bold text-white {% if not is_reverse %}mb-6{% endif %} font-mono truncate" title="{{ zone_name }}">{% if zone_name == '.' %}. (Root Zone){% else %}{{ friendly_name }}{% endif %}</h3>
  138. {% if is_reverse %}<p class="text-[9px] text-gray-500 font-mono mb-4 truncate tracking-widest">{{ zone_name }}</p>{% endif %}
  139. <a href="/zones/manage/{{ url_param }}" class="block w-full text-center bg-gray-800 hover:bg-blue-600 py-3 rounded-xl text-gray-300 hover:text-white font-black text-xs transition uppercase tracking-widest">Manage</a>
  140. </div>
  141. {% endfor %}
  142. </div>
  143. <div id="zonesTableContainer" class="{% if view_mode != 'table' %}hidden{% endif %} bg-[#12161f] border border-gray-800 rounded-3xl overflow-x-auto shadow-2xl mb-8">
  144. <table class="w-full text-left whitespace-nowrap">
  145. <thead class="bg-black/20 text-[10px] font-black text-gray-500 uppercase border-b border-gray-800">
  146. <tr><th class="p-6">Domain / IP Subnet</th><th class="p-6">Type</th><th class="p-6">Owner</th><th class="p-6 text-right">Actions</th></tr>
  147. </thead>
  148. <tbody class="divide-y divide-gray-800">
  149. {% for zone_name, ztype in zones %}
  150. {% set url_param = 'root_zone' if zone_name == '.' else zone_name %}
  151. {% set is_reverse = '.arpa' in zone_name %}
  152. {% set is_master = ztype == 'master' or ztype == 'hint' %}{% set is_hint = ztype == 'hint' %}{% set is_forward = ztype == 'forward' %}
  153. {% set tab_cat = 'forward_zones' if is_forward else ('master_forward' if is_master and not is_reverse else 'master_reverse' if is_master and is_reverse else 'slave_forward' if not is_master and not is_reverse else 'slave_reverse') %}
  154. {% set friendly_name = zone_name %}
  155. {% if is_reverse %}{% set rev_parts = zone_name.replace('.in-addr.arpa', '').replace('.ip6.arpa', '').split('.') %}{% set friendly_name = (rev_parts | reverse | join('.')) ~ '.x (Reverse)' %}{% endif %}
  156. <tr class="zone-item group" data-domain="{{ zone_name|lower }}" data-owner="{{ owners.get(zone_name, 'admin')|lower }}" data-category="{{ tab_cat }}">
  157. <td class="p-6 font-mono font-bold text-white">{% if zone_name == '.' %}. (Root Zone){% else %}{{ friendly_name }}{% endif %}{% if is_reverse %}<br><span class="text-[9px] text-gray-500 tracking-widest">{{ zone_name }}</span>{% endif %}</td>
  158. <td class="p-6"><span class="text-[9px] font-black uppercase px-2 py-1 rounded bg-gray-900 {% if is_forward %}text-cyan-400{% else %}text-blue-400{% endif %}">{{ ztype }}</span></td>
  159. <td class="p-6 text-gray-400 text-xs uppercase">{{ owners.get(zone_name, 'admin') }}</td>
  160. <td class="p-6 text-right">
  161. <div class="flex justify-end gap-4 items-center">
  162. {% if session.get('role') == 'admin' %}<button onclick="openAssignModal('{{ zone_name }}', '{{ owners.get(zone_name, 'admin') }}')" class="opacity-0 group-hover:opacity-100 text-purple-400 text-[10px] font-black uppercase transition">Assign</button>{% endif %}
  163. {% if is_master and not is_hint %}<form action="/zones/manage/{{ url_param }}/cluster_sync" method="POST" onsubmit="handleAjaxForm(event, this, 'dashboard-dynamic-content', restoreDashboardState)" class="inline-block opacity-0 group-hover:opacity-100 transition"><button type="submit" class="text-blue-400 text-[10px] font-black uppercase tracking-widest hover:text-blue-300">Cluster Sync</button></form>{% endif %}
  164. <a href="/zones/manage/{{ url_param }}" class="text-green-400 font-black text-[10px] uppercase">Manage</a>
  165. <a href="/zones/delete/{{ url_param }}" onclick="handleAjaxLink(event, this, 'dashboard-dynamic-content', restoreDashboardState, 'Delete this zone permanently?')" class="opacity-0 group-hover:opacity-100 text-red-500 text-[10px] font-black uppercase transition">Delete</a>
  166. </div>
  167. </td>
  168. </tr>
  169. {% endfor %}
  170. </tbody>
  171. </table>
  172. </div>
  173. <div id="noZonesMsg" class="hidden py-20 text-center border-2 border-dashed border-gray-800 rounded-3xl mt-6"><span class="text-gray-600 font-black uppercase text-xs">No zones found in this category</span></div>
  174. <div id="assignZoneModal" class="hidden fixed inset-0 bg-black/90 flex items-center justify-center z-50 p-4">
  175. <div class="bg-[#12161f] border border-gray-800 w-full max-w-sm rounded-3xl p-8 shadow-2xl">
  176. <h3 class="text-xl font-black text-white mb-6 uppercase text-center">Assign Ownership</h3>
  177. <form action="/zones/assign" method="POST" class="space-y-6" onsubmit="handleAjaxForm(event, this, 'dashboard-dynamic-content', restoreDashboardState)">
  178. <input type="hidden" name="domain" id="assignDomainInput"><div class="text-center mb-4"><span id="assignDomainDisplay" class="text-lg font-mono text-blue-400 font-bold"></span></div>
  179. <select name="owner" id="assignOwnerSelect" class="w-full bg-[#0b0e14] border border-gray-800 rounded-xl p-4 text-white font-bold outline-none cursor-pointer"><option value="admin">admin (Unassign)</option>{% for u in all_usernames %}{% if u != 'admin' %}<option value="{{ u }}">{{ u }}</option>{% endif %}{% endfor %}</select>
  180. <div class="flex gap-4 pt-6"><button type="button" onclick="closeAssignModal()" class="flex-1 bg-gray-800 text-gray-400 font-bold py-4 rounded-xl uppercase text-xs">Cancel</button><button type="submit" class="flex-1 bg-blue-600 text-white font-black py-4 rounded-xl uppercase text-xs shadow-xl">Assign</button></div>
  181. </form>
  182. </div>
  183. </div>
  184. <div id="addZoneModal" class="hidden fixed inset-0 bg-black/90 flex items-center justify-center z-50 p-4">
  185. <div class="bg-[#12161f] border border-gray-800 w-full max-w-lg rounded-3xl p-8 shadow-2xl">
  186. <h3 class="text-2xl font-black text-white mb-8 uppercase border-b border-gray-800 pb-4 text-center">Create New Zone</h3>
  187. <form action="/zones/add" method="POST" id="addZoneForm" class="space-y-6" onsubmit="handleAjaxForm(event, this, 'dashboard-dynamic-content', restoreDashboardState)">
  188. <div class="grid grid-cols-2 gap-4">
  189. <div><label class="block text-[10px] font-bold text-gray-500 uppercase mb-2 ml-1">Direction</label><select name="direction" id="zoneDirection" onchange="updatePlaceholder()" class="w-full bg-[#0b0e14] border border-gray-800 rounded-xl p-4 text-white font-bold outline-none text-sm cursor-pointer"><option value="forward">Forward</option><option value="reverse">Reverse</option></select></div>
  190. <div><label class="block text-[10px] font-bold text-gray-500 uppercase mb-2 ml-1">Type</label><select name="type" id="zoneType" onchange="toggleZoneFields()" class="w-full bg-[#0b0e14] border border-gray-800 rounded-xl p-4 text-white font-bold outline-none text-sm cursor-pointer"><option value="master">Master</option><option value="slave">Slave</option><option value="forward">Forwarder</option><option value="hint">Hint (Root Zone)</option></select></div>
  191. </div>
  192. <div id="domainContainer"><label id="domainLabel" class="block text-[10px] font-bold text-gray-500 uppercase mb-2 ml-1">Domain Name</label><input type="text" name="domain" id="domainInput" placeholder="example.com" required class="w-full bg-[#0b0e14] border border-gray-800 rounded-xl p-4 text-white font-mono outline-none focus:border-blue-500 transition-colors"></div>
  193. <div id="masterFields" class="space-y-4"><label class="block text-[10px] font-bold text-gray-500 uppercase mb-2 ml-1">Template</label><select name="template_name" class="w-full bg-[#0b0e14] border border-gray-800 rounded-xl p-4 text-white font-bold outline-none cursor-pointer"><option value="">-- Blank (No Template) --</option>{% for tname in templates.keys() %}<option value="{{ tname }}">{{ tname }}</option>{% endfor %}</select></div>
  194. <div id="slaveFields" class="hidden space-y-4"><div class="flex justify-between items-center"><label class="text-[10px] font-bold text-gray-500 uppercase">Master IPs</label><button type="button" onclick="addDynamicIp('slaveIpCont', 'master_ips[]')" class="text-[9px] bg-purple-600/20 text-purple-400 px-3 py-1 rounded font-black uppercase">+ Add</button></div><div id="slaveIpCont" class="space-y-2"><input type="text" name="master_ips[]" placeholder="1.2.3.4" class="w-full bg-[#0b0e14] border border-gray-800 rounded-xl p-3 text-white font-mono"></div></div>
  195. <div id="forwardFields" class="hidden space-y-4"><div class="flex justify-between items-center"><label class="text-[10px] font-bold text-gray-500 uppercase">Forwarders</label><button type="button" onclick="addDynamicIp('forwardIpCont', 'forwarders[]')" class="text-[9px] bg-blue-600/20 text-blue-400 px-3 py-1 rounded font-black uppercase">+ Add</button></div><div id="forwardIpCont" class="space-y-2"><input type="text" name="forwarders[]" placeholder="8.8.8.8" class="w-full bg-[#0b0e14] border border-gray-800 rounded-xl p-3 text-white font-mono"></div></div>
  196. <div class="flex gap-4 pt-6 border-t border-gray-800"><button type="button" onclick="closeAddModal()" class="flex-1 bg-gray-800 text-gray-400 font-bold py-4 rounded-xl hover:text-white transition uppercase text-xs tracking-widest">Cancel</button><button type="submit" class="flex-1 bg-blue-600 text-white font-black py-4 rounded-xl shadow-xl transition uppercase text-xs tracking-widest hover:bg-blue-500">Create</button></div>
  197. </form>
  198. </div>
  199. </div>
  200. <div id="backupModal" class="hidden fixed inset-0 bg-black/90 flex items-center justify-center z-50 p-4">
  201. <div class="bg-[#12161f] border border-gray-800 w-full max-w-md rounded-3xl p-8 shadow-2xl">
  202. <h3 class="text-2xl font-black text-white mb-8 uppercase text-center italic">System Backup & Restore</h3>
  203. <div class="space-y-6">
  204. <div class="bg-gray-900/50 p-6 rounded-2xl border border-gray-800"><h4 class="text-xs font-black text-green-500 uppercase mb-2">Export Data</h4><a href="/backup/export" class="block w-full text-center bg-green-600/20 text-green-400 font-black py-3 rounded-xl border border-green-500/30 uppercase text-xs">Download ZIP</a></div>
  205. <div class="bg-gray-900/50 p-6 rounded-2xl border border-gray-800"><h4 class="text-xs font-black text-blue-500 uppercase mb-2">Restore Data</h4><form action="/backup/import" method="POST" enctype="multipart/form-data" class="space-y-4"><input type="file" name="backup_file" required class="block w-full text-xs text-gray-400 file:bg-gray-800 file:text-white file:border-0 file:py-2 file:px-4 file:rounded-lg"><button type="submit" class="w-full bg-blue-600 text-white font-black py-3 rounded-xl uppercase text-xs shadow-xl">Restore ZIP</button></form></div>
  206. </div>
  207. <button onclick="closeBackupModal()" class="w-full mt-6 bg-gray-800 text-gray-400 py-3 rounded-xl uppercase text-xs font-bold">Close</button>
  208. </div>
  209. </div>
  210. </div>
  211. <script>
  212. async function handleAjaxForm(e, form, containerId, callback) {
  213. e.preventDefault();
  214. const btn = form.querySelector('button[type="submit"]');
  215. if(btn) { btn.innerHTML = spinnerSvg + ' WAIT'; btn.disabled = true; }
  216. try {
  217. const res = await fetch(form.action, { method: form.method || 'POST', body: new FormData(form) });
  218. const html = await res.text();
  219. const doc = new DOMParser().parseFromString(html, 'text/html');
  220. const scriptContent = Array.from(doc.querySelectorAll('script')).map(s => s.innerHTML).join('\n');
  221. const errorMatch = scriptContent.match(/Toast\.fire\(\{\s*icon:\s*'error',\s*title:\s*'([^']+)'/);
  222. const successMatch = scriptContent.match(/Toast\.fire\(\{\s*icon:\s*'success',\s*title:\s*'([^']+)'/);
  223. const newCont = doc.getElementById(containerId);
  224. if(newCont) {
  225. document.getElementById(containerId).innerHTML = newCont.innerHTML;
  226. if(callback) callback();
  227. if(errorMatch) AppToast.fire({ icon: 'error', title: errorMatch[1] });
  228. else if(successMatch) AppToast.fire({ icon: 'success', title: successMatch[1] });
  229. else AppToast.fire({ icon: 'success', title: 'Action Completed!' });
  230. } else window.location.reload();
  231. } catch(err) { window.location.reload(); }
  232. }
  233. async function handleAjaxLink(e, link, containerId, callback, confirmMsg) {
  234. e.preventDefault(); if(confirmMsg && !confirm(confirmMsg)) return;
  235. try {
  236. const res = await fetch(link.href);
  237. const html = await res.text();
  238. const doc = new DOMParser().parseFromString(html, 'text/html');
  239. const scriptContent = Array.from(doc.querySelectorAll('script')).map(s => s.innerHTML).join('\n');
  240. const errorMatch = scriptContent.match(/Toast\.fire\(\{\s*icon:\s*'error',\s*title:\s*'([^']+)'/);
  241. const successMatch = scriptContent.match(/Toast\.fire\(\{\s*icon:\s*'success',\s*title:\s*'([^']+)'/);
  242. const newCont = doc.getElementById(containerId);
  243. if(newCont) {
  244. document.getElementById(containerId).innerHTML = newCont.innerHTML;
  245. if(callback) callback();
  246. if(errorMatch) AppToast.fire({ icon: 'error', title: errorMatch[1] });
  247. else if(successMatch) AppToast.fire({ icon: 'success', title: successMatch[1] });
  248. else AppToast.fire({ icon: 'success', title: 'Action Executed!' });
  249. } else window.location.reload();
  250. } catch(err) { window.location.reload(); }
  251. }
  252. function initTableSort(container) {
  253. const getCellValue = (tr, idx) => tr.children[idx].innerText.trim();
  254. const comparer = (idx, asc) => (a, b) => ((v1, v2) => v1 !== '' && v2 !== '' && !isNaN(v1) && !isNaN(v2) ? v1 - v2 : v1.localeCompare(v2, undefined, {numeric: true}))(getCellValue(asc ? a : b, idx), getCellValue(asc ? b : a, idx));
  255. container.querySelectorAll('table').forEach(table => {
  256. if(table.dataset.sortBound) return; table.dataset.sortBound = "true";
  257. table.querySelectorAll('th').forEach(th => {
  258. if (th.innerText.trim().toLowerCase() === 'actions') return;
  259. th.classList.add('cursor-pointer', 'hover:text-blue-400', 'transition-colors', 'select-none', 'group');
  260. const originalText = th.innerHTML;
  261. if(!originalText.includes('sort-icon')) { th.innerHTML = `<div class="flex items-center gap-2 justify-${th.classList.contains('text-right') ? 'end' : 'start'}">${originalText}<span class="sort-icon opacity-0 group-hover:opacity-50 transition-opacity text-blue-500 text-lg leading-none">↕</span></div>`; }
  262. th.addEventListener('click', function() {
  263. const tbody = table.querySelector('tbody'); if(!tbody) return;
  264. table.querySelectorAll('.sort-icon').forEach(icon => { icon.innerHTML = '↕'; icon.classList.remove('opacity-100', 'text-blue-400'); icon.classList.add('opacity-0', 'text-blue-500'); });
  265. this.asc = !this.asc; const icon = this.querySelector('.sort-icon'); icon.innerHTML = this.asc ? '↑' : '↓';
  266. icon.classList.remove('opacity-0', 'text-blue-500', 'group-hover:opacity-50'); icon.classList.add('opacity-100', 'text-blue-400');
  267. Array.from(tbody.querySelectorAll('tr')).sort(comparer(Array.from(th.parentNode.children).indexOf(th), this.asc)).forEach(tr => tbody.appendChild(tr));
  268. });
  269. });
  270. });
  271. }
  272. function openBackupModal() { document.getElementById('backupModal').classList.remove('hidden'); }
  273. function closeBackupModal() { document.getElementById('backupModal').classList.add('hidden'); }
  274. function openAddModal() { document.getElementById('addZoneModal').classList.remove('hidden'); setTimeout(() => document.getElementById('domainInput').focus(), 100); }
  275. function closeAddModal() { const m = document.getElementById('addZoneModal'); if(m) m.classList.add('hidden'); }
  276. function openAssignModal(d, o) { document.getElementById('assignDomainInput').value=d; document.getElementById('assignDomainDisplay').innerText=d; document.getElementById('assignOwnerSelect').value=o; document.getElementById('assignZoneModal').classList.remove('hidden'); }
  277. function closeAssignModal() { const m = document.getElementById('assignZoneModal'); if(m) m.classList.add('hidden'); }
  278. function toggleZoneFields() {
  279. const type = document.getElementById('zoneType').value, domCont = document.getElementById('domainContainer'), domInp = document.getElementById('domainInput');
  280. if(type === 'hint') { domCont.classList.add('hidden'); domInp.required = false; domInp.value = '.'; }
  281. else { domCont.classList.remove('hidden'); domInp.required = true; if(domInp.value === '.') domInp.value = ''; }
  282. document.getElementById('masterFields').style.display = (type === 'master') ? 'block' : 'none';
  283. document.getElementById('slaveFields').style.display = (type === 'slave') ? 'block' : 'none';
  284. document.getElementById('forwardFields').style.display = (type === 'forward') ? 'block' : 'none';
  285. }
  286. function updatePlaceholder() {
  287. const dir = document.getElementById('zoneDirection').value, inp = document.getElementById('domainInput'), lbl = document.getElementById('domainLabel');
  288. if(dir === 'reverse') { lbl.innerText = 'IP SUBNET (e.g. 192.168.1)'; inp.placeholder = '192.168.1 or 10.0'; }
  289. else { lbl.innerText = 'DOMAIN NAME'; inp.placeholder = 'example.com'; }
  290. }
  291. function addDynamicIp(contId, name) {
  292. const div = document.createElement('div'); div.className = 'flex gap-2 mt-2';
  293. div.innerHTML = `<input type="text" name="${name}" placeholder="0.0.0.0" class="w-full bg-[#0b0e14] border border-gray-800 rounded-xl p-3 text-white font-mono outline-none focus:border-blue-500 transition"><button type="button" onclick="this.parentElement.remove()" class="text-red-500 font-black px-4 hover:bg-red-500/10 rounded-xl transition">×</button>`;
  294. document.getElementById(contId).appendChild(div);
  295. }
  296. function changeViewMode(mode) { document.getElementById('zonesGrid').classList.toggle('hidden', mode==='table'); document.getElementById('zonesTableContainer').classList.toggle('hidden', mode==='cards'); fetch('/settings/view_mode', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({mode: mode}) }); }
  297. let activeTab = 'master_forward';
  298. function switchTab(tab) {
  299. activeTab = tab;
  300. ['master_forward', 'master_reverse', 'slave_forward', 'slave_reverse', 'forward_zones'].forEach(t => {
  301. const btn = document.getElementById('btnTab_' + t); if(btn) btn.className = (t === activeTab) ? "pb-4 text-[10px] font-black uppercase tracking-widest text-blue-500 border-b-2 border-blue-500 transition focus:outline-none" : "pb-4 text-[10px] font-black uppercase tracking-widest text-gray-500 border-b-2 border-transparent hover:text-gray-300 transition focus:outline-none";
  302. });
  303. filterZones();
  304. }
  305. function filterZones() {
  306. let input = document.getElementById('zoneSearch').value.toLowerCase(), items = document.querySelectorAll('.zone-item'), count = 0;
  307. items.forEach(item => {
  308. let domain = item.getAttribute('data-domain'), owner = item.getAttribute('data-owner') || '', category = item.getAttribute('data-category'), match = (domain.includes(input) || owner.includes(input)) && category === activeTab;
  309. item.classList.toggle('hidden', !match); if(match) count++;
  310. });
  311. const msg = document.getElementById('noZonesMsg'); if(msg) msg.classList.toggle('hidden', count === 0);
  312. }
  313. function restoreDashboardState() { switchTab(activeTab); initTableSort(document.getElementById('dashboard-dynamic-content')); const searchInput = document.getElementById('zoneSearch'); if(searchInput && searchInput.value) filterZones(); updateLiveStatus(); }
  314. function updateLiveStatus() {
  315. fetch('/api/service/status')
  316. .then(r => r.json())
  317. .then(data => {
  318. const dot = document.getElementById('status-dot');
  319. const text = document.getElementById('status-text');
  320. if(data.status === 'active') {
  321. dot.className = "w-2.5 h-2.5 rounded-full bg-green-500 shadow-[0_0_10px_rgba(34,197,94,0.8)] animate-pulse";
  322. text.innerHTML = `Service: Active <span class="text-gray-600 ml-2 font-normal italic lowercase">(since ${data.uptime})</span>`;
  323. text.classList.replace('text-gray-500', 'text-green-400');
  324. } else {
  325. dot.className = "w-2.5 h-2.5 rounded-full bg-red-500 shadow-[0_0_10px_rgba(239,68,68,0.8)]";
  326. text.innerText = "Service: Offline / Crashed";
  327. text.classList.replace('text-green-400', 'text-red-500');
  328. }
  329. })
  330. .catch(() => {
  331. const txt = document.getElementById('status-text');
  332. if(txt) txt.innerText = "Status: Connection Error";
  333. });
  334. }
  335. setInterval(updateLiveStatus, 5000);
  336. document.addEventListener("DOMContentLoaded", restoreDashboardState);
  337. </script>
  338. {% endblock %}