code layout improvement
This commit is contained in:
@@ -98,31 +98,4 @@ document.addEventListener('alpine:init', () => {
|
|||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
async function banAction(ip, action) {
|
|
||||||
const confirmed = await krawlModal.confirm(`Are you sure you want to ${action} IP <strong>${ip}</strong>?`);
|
|
||||||
if (!confirmed) return;
|
|
||||||
try {
|
|
||||||
const resp = await fetch(`${window.__DASHBOARD_PATH__}/api/ban-override`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
credentials: 'same-origin',
|
|
||||||
body: JSON.stringify({ ip, action }),
|
|
||||||
});
|
|
||||||
if (resp.ok) {
|
|
||||||
krawlModal.success(`${action} successful for ${ip}`);
|
|
||||||
const overrides = document.getElementById('overrides-container');
|
|
||||||
if (overrides) {
|
|
||||||
htmx.ajax('GET', `${window.__DASHBOARD_PATH__}/htmx/ban/overrides?page=1`, {
|
|
||||||
target: '#overrides-container',
|
|
||||||
swap: 'innerHTML'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const result = await resp.json().catch(() => ({}));
|
|
||||||
krawlModal.error(result.error || `Failed to ${action} IP ${ip}`);
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
krawlModal.error('Request failed');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
<td>{{ ip.city | default('') | e }}{% if ip.city and ip.country_code %}, {% endif %}{{ ip.country_code | default('N/A') | e }}</td>
|
<td>{{ ip.city | default('') | e }}{% if ip.city and ip.country_code %}, {% endif %}{{ ip.country_code | default('N/A') | e }}</td>
|
||||||
<td>{{ ip.last_seen | format_ts }}</td>
|
<td>{{ ip.last_seen | format_ts }}</td>
|
||||||
<td>
|
<td>
|
||||||
<button class="ban-icon-btn ban-icon-unban" onclick="banAction('{{ ip.ip | e }}', 'unban')" title="Unban">
|
<button class="ban-icon-btn ban-icon-unban" onclick="ipBanAction('{{ ip.ip | e }}', 'unban')" title="Unban">
|
||||||
<span class="material-symbols-outlined">health_and_safety</span>
|
<span class="material-symbols-outlined">health_and_safety</span>
|
||||||
<span class="ban-icon-tooltip">Unban</span>
|
<span class="ban-icon-tooltip">Unban</span>
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -44,7 +44,7 @@
|
|||||||
<td>{{ ip.city | default('') | e }}{% if ip.city and ip.country_code %}, {% endif %}{{ ip.country_code | default('N/A') | e }}</td>
|
<td>{{ ip.city | default('') | e }}{% if ip.city and ip.country_code %}, {% endif %}{{ ip.country_code | default('N/A') | e }}</td>
|
||||||
<td>{{ ip.last_seen | format_ts }}</td>
|
<td>{{ ip.last_seen | format_ts }}</td>
|
||||||
<td>
|
<td>
|
||||||
<button class="ban-icon-btn ban-icon-reset" onclick="banAction('{{ ip.ip | e }}', 'reset')" title="Reset to automatic">
|
<button class="ban-icon-btn ban-icon-reset" onclick="ipBanAction('{{ ip.ip | e }}', 'reset')" title="Reset to automatic">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16" fill="currentColor"><path d="M1.705 8.005a.75.75 0 0 1 .834.656 5.5 5.5 0 0 0 9.592 2.97l-1.204-1.204a.25.25 0 0 1 .177-.427h3.646a.25.25 0 0 1 .25.25v3.646a.25.25 0 0 1-.427.177l-1.38-1.38A7.002 7.002 0 0 1 1.05 8.84a.75.75 0 0 1 .656-.834ZM8 2.5a5.487 5.487 0 0 0-4.131 1.869l1.204 1.204A.25.25 0 0 1 4.896 6H1.25A.25.25 0 0 1 1 5.75V2.104a.25.25 0 0 1 .427-.177l1.38 1.38A7.002 7.002 0 0 1 14.95 7.16a.75.75 0 0 1-1.49.178A5.5 5.5 0 0 0 8 2.5Z"/></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16" fill="currentColor"><path d="M1.705 8.005a.75.75 0 0 1 .834.656 5.5 5.5 0 0 0 9.592 2.97l-1.204-1.204a.25.25 0 0 1 .177-.427h3.646a.25.25 0 0 1 .25.25v3.646a.25.25 0 0 1-.427.177l-1.38-1.38A7.002 7.002 0 0 1 1.05 8.84a.75.75 0 0 1 .656-.834ZM8 2.5a5.487 5.487 0 0 0-4.131 1.869l1.204 1.204A.25.25 0 0 1 4.896 6H1.25A.25.25 0 0 1 1 5.75V2.104a.25.25 0 0 1 .427-.177l1.38 1.38A7.002 7.002 0 0 1 14.95 7.16a.75.75 0 0 1-1.49.178A5.5 5.5 0 0 0 8 2.5Z"/></svg>
|
||||||
<span class="ban-icon-tooltip">Reset</span>
|
<span class="ban-icon-tooltip">Reset</span>
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -332,6 +332,13 @@ window.ipBanAction = async function(ip, action) {
|
|||||||
const result = await resp.json().catch(() => ({}));
|
const result = await resp.json().catch(() => ({}));
|
||||||
if (resp.ok) {
|
if (resp.ok) {
|
||||||
krawlModal.success(result.message || `${action} successful for ${ip}`);
|
krawlModal.success(result.message || `${action} successful for ${ip}`);
|
||||||
|
const overrides = document.getElementById('overrides-container');
|
||||||
|
if (overrides) {
|
||||||
|
htmx.ajax('GET', `${window.__DASHBOARD_PATH__}/htmx/ban/overrides?page=1`, {
|
||||||
|
target: '#overrides-container',
|
||||||
|
swap: 'innerHTML'
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
krawlModal.error(result.error || `Failed to ${action} IP ${ip}`);
|
krawlModal.error(result.error || `Failed to ${action} IP ${ip}`);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user