Update to latest version
This commit is contained in:
1 parent
7125e29993
commit
c74ef9cf9c
15 files changed
+191
-70
No files matched your search
+13
-24
@@ -3,8 +3,8 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="csrf-token" content="{{ csrf_token() }}">
|
||||
<title>{% block title %}Dune Awakening Server Dashboard{% endblock %}</title>
|
||||
<meta name="csrf-token" content="{{ csrf_token() }}">
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
||||
</head>
|
||||
<body>
|
||||
@@ -40,8 +40,15 @@
|
||||
<div class="update-spinner"></div>
|
||||
</div>
|
||||
</div>
|
||||
{% block scripts %}{% endblock %}
|
||||
<script>
|
||||
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
|
||||
|
||||
async function csrfFetch(url, options = {}) {
|
||||
options.headers = options.headers || {};
|
||||
options.headers['X-CSRFToken'] = csrfToken;
|
||||
return fetch(url, options);
|
||||
}
|
||||
|
||||
let updateDismissed = false;
|
||||
async function checkForUpdate() {
|
||||
if (updateDismissed) return;
|
||||
@@ -58,7 +65,7 @@
|
||||
btn.textContent = 'Checking...';
|
||||
btn.disabled = true;
|
||||
try {
|
||||
const resp = await fetch('/api/update/check', { method: 'POST' });
|
||||
const resp = await csrfFetch('/api/update/check', { method: 'POST' });
|
||||
const data = await resp.json();
|
||||
if (data.available) {
|
||||
document.getElementById('update-banner').style.display = 'flex';
|
||||
@@ -84,7 +91,7 @@
|
||||
banner.style.display = 'none';
|
||||
progress.style.display = 'flex';
|
||||
try {
|
||||
const resp = await fetch('/api/update/apply', { method: 'POST' });
|
||||
const resp = await csrfFetch('/api/update/apply', { method: 'POST' });
|
||||
const data = await resp.json();
|
||||
statusText.textContent = data.message || 'Applying update...';
|
||||
if (data.success) {
|
||||
@@ -101,26 +108,8 @@
|
||||
}
|
||||
setInterval(checkForUpdate, 60000);
|
||||
checkForUpdate();
|
||||
|
||||
// CSRF: Attach token to all non-GET fetch requests
|
||||
(function() {
|
||||
const csrfToken = document.querySelector('meta[name="csrf-token"]')?.content;
|
||||
if (!csrfToken) return;
|
||||
const origFetch = window.fetch;
|
||||
window.fetch = function() {
|
||||
let [resource, config] = arguments;
|
||||
if (!config) config = {};
|
||||
if (!config.headers) config.headers = {};
|
||||
const method = (config.method || 'GET').toUpperCase();
|
||||
if (method !== 'GET' && method !== 'HEAD' && method !== 'OPTIONS') {
|
||||
if (typeof config.headers === 'object') {
|
||||
config.headers['X-CSRFToken'] = csrfToken;
|
||||
}
|
||||
}
|
||||
return origFetch(resource, config);
|
||||
};
|
||||
})();
|
||||
</script>
|
||||
{% block scripts %}{% endblock %}
|
||||
<style>
|
||||
.update-banner { background: var(--bg-hover); border-bottom: 2px solid var(--accent); padding: 10px 20px; display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--text); }
|
||||
.update-actions { display: flex; gap: 8px; }
|
||||
@@ -134,4 +123,4 @@
|
||||
@keyframes spin { to { transform: rotate(360deg); } }
|
||||
</style>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
@@ -634,7 +634,7 @@ document.getElementById('btn-clear-world')?.addEventListener('click', async func
|
||||
this.disabled = true;
|
||||
this.textContent = 'Clearing...';
|
||||
try {
|
||||
const resp = await fetch('/api/director/character_transfer_clear', { method: 'POST' });
|
||||
const resp = await csrfFetch('/api/director/character_transfer_clear', { method: 'POST' });
|
||||
if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
|
||||
document.getElementById('world-status-msg').textContent = 'World status overrides cleared.';
|
||||
this.textContent = 'Cleared!';
|
||||
@@ -655,7 +655,7 @@ document.getElementById('btn-apply-transfer')?.addEventListener('click', async f
|
||||
FreeToTransferCharactersTo: document.getElementById('free-transfer-to').checked
|
||||
};
|
||||
try {
|
||||
const resp = await fetch('/api/director/character_transfer', {
|
||||
const resp = await csrfFetch('/api/director/character_transfer', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(config)
|
||||
@@ -674,7 +674,7 @@ document.getElementById('btn-clear-transfer')?.addEventListener('click', async f
|
||||
this.disabled = true;
|
||||
this.textContent = 'Clearing...';
|
||||
try {
|
||||
const resp = await fetch('/api/director/character_transfer_clear', { method: 'POST' });
|
||||
const resp = await csrfFetch('/api/director/character_transfer_clear', { method: 'POST' });
|
||||
if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
|
||||
document.getElementById('transfer-status-msg').textContent = 'Transfer settings cleared.';
|
||||
this.textContent = 'Cleared!';
|
||||
|
||||
@@ -121,7 +121,7 @@ async function saveFile() {
|
||||
const form = new FormData();
|
||||
form.append('path', filePath);
|
||||
form.append('content', editor.value);
|
||||
const resp = await fetch('/api/files/save', { method: 'POST', body: form });
|
||||
const resp = await csrfFetch('/api/files/save', { method: 'POST', body: form });
|
||||
const data = await resp.json();
|
||||
if (!data.success) {
|
||||
error.textContent = 'Error: ' + (data.error || 'Failed to save file');
|
||||
|
||||
@@ -93,7 +93,7 @@ async function loadFiles(path) {
|
||||
try {
|
||||
const form = new FormData();
|
||||
form.append('path', path);
|
||||
const resp = await fetch('/api/files/list', { method: 'POST', body: form });
|
||||
const resp = await csrfFetch('/api/files/list', { method: 'POST', body: form });
|
||||
const data = await resp.json();
|
||||
if (!data.success) {
|
||||
list.innerHTML = '';
|
||||
|
||||
@@ -110,7 +110,7 @@
|
||||
{% endwith %}
|
||||
|
||||
<form method="POST">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
|
||||
<div class="form-group">
|
||||
<label for="username">Username</label>
|
||||
<input type="text" id="username" name="username" required autofocus>
|
||||
|
||||
@@ -468,7 +468,7 @@ function closeModal(id) {
|
||||
async function submitEdit(form, url) {
|
||||
const data = new FormData(form);
|
||||
try {
|
||||
const resp = await fetch(url, { method: 'POST', body: data });
|
||||
const resp = await csrfFetch(url, { method: 'POST', body: data });
|
||||
const result = await resp.json();
|
||||
if (result.success) {
|
||||
alert('Saved successfully!');
|
||||
@@ -486,7 +486,7 @@ async function submitSpecEdit() {
|
||||
const form = document.getElementById('spec-form');
|
||||
const data = new FormData(form);
|
||||
try {
|
||||
const resp = await fetch('/api/edit_tech_knowledge', { method: 'POST', body: data });
|
||||
const resp = await csrfFetch('/api/edit_tech_knowledge', { method: 'POST', body: data });
|
||||
const result = await resp.json();
|
||||
if (result.success) {
|
||||
alert('XP saved!');
|
||||
@@ -526,7 +526,7 @@ async function submitCurrencyEdit(currencyId) {
|
||||
data.append('currency_id', currencyId);
|
||||
data.append('new_balance', newBalance);
|
||||
try {
|
||||
const resp = await fetch('/api/edit_currency', { method: 'POST', body: data });
|
||||
const resp = await csrfFetch('/api/edit_currency', { method: 'POST', body: data });
|
||||
const result = await resp.json();
|
||||
if (result.success) {
|
||||
alert('Currency updated successfully!');
|
||||
@@ -543,7 +543,7 @@ async function submitVitalsEdit() {
|
||||
const form = document.getElementById('vitals-form');
|
||||
const data = new FormData(form);
|
||||
try {
|
||||
const resp = await fetch('/api/edit_vitals', { method: 'POST', body: data });
|
||||
const resp = await csrfFetch('/api/edit_vitals', { method: 'POST', body: data });
|
||||
const result = await resp.json();
|
||||
if (result.success) {
|
||||
alert('Vitals updated successfully!');
|
||||
@@ -565,7 +565,7 @@ async function editItem(itemId, field, currentValue) {
|
||||
data.append('field', field);
|
||||
data.append('value', newValue);
|
||||
try {
|
||||
const resp = await fetch('/api/edit_item', { method: 'POST', body: data });
|
||||
const resp = await csrfFetch('/api/edit_item', { method: 'POST', body: data });
|
||||
const result = await resp.json();
|
||||
if (result.success) {
|
||||
const span = document.getElementById('item-' + field.replace('_', '-') + '-' + itemId);
|
||||
@@ -584,7 +584,7 @@ async function deleteItem(itemId, templateName) {
|
||||
const data = new FormData();
|
||||
data.append('item_id', itemId);
|
||||
try {
|
||||
const resp = await fetch('/api/delete_item', { method: 'POST', body: data });
|
||||
const resp = await csrfFetch('/api/delete_item', { method: 'POST', body: data });
|
||||
const result = await resp.json();
|
||||
if (result.success) {
|
||||
const row = document.getElementById('item-row-' + itemId);
|
||||
@@ -606,7 +606,7 @@ async function submitAddItem() {
|
||||
const form = document.getElementById('add-item-form');
|
||||
const data = new FormData(form);
|
||||
try {
|
||||
const resp = await fetch('/api/add_item', { method: 'POST', body: data });
|
||||
const resp = await csrfFetch('/api/add_item', { method: 'POST', body: data });
|
||||
const result = await resp.json();
|
||||
if (result.success) {
|
||||
alert('Item added successfully!');
|
||||
|
||||
@@ -117,7 +117,7 @@ document.querySelectorAll('.btn-action[data-action="kick"]').forEach(btn => {
|
||||
try {
|
||||
const form = new FormData();
|
||||
form.append('player_id', pid);
|
||||
const resp = await fetch('/api/kick_player', { method: 'POST', body: form });
|
||||
const resp = await csrfFetch('/api/kick_player', { method: 'POST', body: form });
|
||||
const data = await resp.json();
|
||||
alert(data.success ? data.message : 'Error: ' + (data.error || 'Failed'));
|
||||
} catch (e) {
|
||||
@@ -141,7 +141,7 @@ document.querySelectorAll('.btn-action[data-action="ban"]').forEach(btn => {
|
||||
form.append('duration', duration);
|
||||
form.append('reason', reason);
|
||||
form.append('note', note);
|
||||
const resp = await fetch('/api/ban_player', { method: 'POST', body: form });
|
||||
const resp = await csrfFetch('/api/ban_player', { method: 'POST', body: form });
|
||||
const data = await resp.json();
|
||||
alert(data.success ? `Banned ${name} for ${duration} minutes` : 'Error: ' + (data.error || 'Failed'));
|
||||
} catch (e) {
|
||||
@@ -157,7 +157,7 @@ document.querySelectorAll('.btn-action[data-action="unban"]').forEach(btn => {
|
||||
try {
|
||||
const form = new FormData();
|
||||
form.append('player_id', pid);
|
||||
const resp = await fetch('/api/unban_player', { method: 'POST', body: form });
|
||||
const resp = await csrfFetch('/api/unban_player', { method: 'POST', body: form });
|
||||
const data = await resp.json();
|
||||
alert(data.success ? `Unbanned ${name}` : 'Error: ' + (data.error || 'Failed'));
|
||||
} catch (e) {
|
||||
@@ -172,7 +172,7 @@ document.querySelectorAll('.btn-action[data-action="viewban"]').forEach(btn => {
|
||||
try {
|
||||
const form = new FormData();
|
||||
form.append('player_id', pid);
|
||||
const resp = await fetch('/api/get_player_ban', { method: 'POST', body: form });
|
||||
const resp = await csrfFetch('/api/get_player_ban', { method: 'POST', body: form });
|
||||
const data = await resp.json();
|
||||
if (data.banned) {
|
||||
alert(`Ban Info for ${name}:\n\nDuration: ${data.duration} minutes\nReason: ${data.reason}\nNote: ${data.note || 'None'}\nBanned: ${data.banned_at}\nExpires: ${data.expires_at}`);
|
||||
@@ -191,7 +191,7 @@ document.querySelectorAll('.btn-action[data-action="history"]').forEach(btn => {
|
||||
try {
|
||||
const form = new FormData();
|
||||
form.append('player_id', pid);
|
||||
const resp = await fetch('/api/get_player_history', { method: 'POST', body: form });
|
||||
const resp = await csrfFetch('/api/get_player_history', { method: 'POST', body: form });
|
||||
const data = await resp.json();
|
||||
if (data.history && data.history.length > 0) {
|
||||
let msg = `Action History for ${name}:\n\n`;
|
||||
@@ -225,7 +225,7 @@ document.querySelectorAll('.ip-cell').forEach(cell => {
|
||||
const form = new FormData();
|
||||
form.append('player_id', pid);
|
||||
form.append('ip_address', newIp);
|
||||
const resp = await fetch('/api/set_player_ip', { method: 'POST', body: form });
|
||||
const resp = await csrfFetch('/api/set_player_ip', { method: 'POST', body: form });
|
||||
const data = await resp.json();
|
||||
if (data.success) {
|
||||
this.textContent = newIp || '—';
|
||||
@@ -244,7 +244,7 @@ async function detectIps() {
|
||||
try {
|
||||
const btn = document.querySelector('button[onclick="detectIps()"]');
|
||||
if (btn) { btn.disabled = true; btn.textContent = 'Detecting...'; }
|
||||
const resp = await fetch('/api/detect_player_ips', { method: 'POST' });
|
||||
const resp = await csrfFetch('/api/detect_player_ips', { method: 'POST' });
|
||||
const data = await resp.json();
|
||||
if (data.success) {
|
||||
console.log('IP detection:', data.message);
|
||||
|
||||
@@ -270,7 +270,7 @@ document.querySelectorAll('.btn-action').forEach(btn => {
|
||||
const form = new FormData();
|
||||
form.append('deployment', deploy);
|
||||
form.append('action', action);
|
||||
const resp = await fetch('/server/action', { method: 'POST', body: form });
|
||||
const resp = await csrfFetch('/server/action', { method: 'POST', body: form });
|
||||
const data = await resp.json();
|
||||
outputText.textContent = data.output || (data.success ? 'Done' : 'Failed');
|
||||
} catch (e) {
|
||||
@@ -298,7 +298,7 @@ document.querySelectorAll('.partition-btn').forEach(btn => {
|
||||
const form = new FormData();
|
||||
form.append('deployment', deploy);
|
||||
form.append('action', 'restart');
|
||||
const resp = await fetch('/server/action', { method: 'POST', body: form });
|
||||
const resp = await csrfFetch('/server/action', { method: 'POST', body: form });
|
||||
const data = await resp.json();
|
||||
outputText.textContent = data.output || (data.success ? 'Restart initiated' : 'Failed');
|
||||
} catch (e) {
|
||||
@@ -344,7 +344,7 @@ async function bgAction(action, btn) {
|
||||
const url = action === 'update' ? '/server/battlegroup/update' : '/server/battlegroup/action';
|
||||
const form = new FormData();
|
||||
form.append('action', action);
|
||||
const resp = await fetch(url, { method: 'POST', body: form });
|
||||
const resp = await csrfFetch(url, { method: 'POST', body: form });
|
||||
const data = await resp.json();
|
||||
pre.textContent = data.output || (data.success ? `${action} completed successfully` : `Failed: ${data.output}`);
|
||||
} catch (e) {
|
||||
@@ -435,7 +435,7 @@ async function loadFwStatus() {
|
||||
try {
|
||||
const form = new FormData();
|
||||
form.append('port', port);
|
||||
const resp = await fetch('/server/firewall/' + action, { method: 'POST', body: form });
|
||||
const resp = await csrfFetch('/server/firewall/' + action, { method: 'POST', body: form });
|
||||
const result = await resp.json();
|
||||
outputText.textContent = result.output || (result.success ? 'Done' : 'Failed');
|
||||
await loadFwStatus();
|
||||
|
||||
Reference in new issue
Block a user