mirror of
https://github.com/andrey271192/vps_monitoring.git
synced 2026-09-20 11:55:34 +00:00
fix(keenetic): safe delete URLs and not-found handling
Encode router names in Keenetic API calls and return an error when delete targets a missing device. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -320,6 +320,8 @@ async def keenetic_update(name: str, request: Request, user: str = Depends(requi
|
||||
@router.delete("/{name}")
|
||||
async def keenetic_delete(name: str, request: Request, user: str = Depends(require_auth)):
|
||||
devices = _load_keenetic()
|
||||
if not any(d["name"] == name for d in devices):
|
||||
return {"status": "error", "detail": "router not found"}
|
||||
devices = [d for d in devices if d["name"] != name]
|
||||
_save_keenetic(devices)
|
||||
keenetic_metrics.pop(name, None)
|
||||
|
||||
@@ -1378,7 +1378,7 @@ async function showKeeneticDetail(name) {
|
||||
|
||||
// Fetch clients + interfaces lazily
|
||||
try {
|
||||
const resp = await fetch(`/api/keenetic/detail/${name}`, {credentials: 'include'});
|
||||
const resp = await fetch(`/api/keenetic/detail/${encodeURIComponent(name)}`, {credentials: 'include'});
|
||||
const data = await resp.json();
|
||||
const extra = document.getElementById('keeneticDetailExtra');
|
||||
if (!extra) return;
|
||||
@@ -1558,7 +1558,7 @@ async function refreshKeenetic(name) {
|
||||
const card = document.querySelector(`[data-keen="${name}"]`);
|
||||
if (card) card.classList.add('loading');
|
||||
try {
|
||||
const resp = await fetch(`/api/keenetic/refresh/${name}`, {
|
||||
const resp = await fetch(`/api/keenetic/refresh/${encodeURIComponent(name)}`, {
|
||||
method: 'POST', credentials: 'include',
|
||||
});
|
||||
const resp2 = await fetch('/api/keenetic/list', {credentials: 'include'});
|
||||
@@ -1593,7 +1593,7 @@ async function refreshAllKeenetic() {
|
||||
async function rebootKeenetic(name) {
|
||||
if (!confirm(`Перезагрузить роутер "${name}"?`)) return;
|
||||
try {
|
||||
const resp = await fetch(`/api/keenetic/reboot/${name}`, {
|
||||
const resp = await fetch(`/api/keenetic/reboot/${encodeURIComponent(name)}`, {
|
||||
method: 'POST', credentials: 'include',
|
||||
});
|
||||
const data = await resp.json();
|
||||
@@ -1682,11 +1682,16 @@ async function saveKeeneticEdit(oldName) {
|
||||
}
|
||||
|
||||
async function deleteKeenetic(name) {
|
||||
if (!confirm(`Удалить роутер "${name}"?`)) return;
|
||||
if (!confirm(`Удалить роутер "${name}" из мониторинга?`)) return;
|
||||
try {
|
||||
await fetch(`/api/keenetic/${name}`, {
|
||||
const resp = await fetch(`/api/keenetic/${encodeURIComponent(name)}`, {
|
||||
method: 'DELETE', credentials: 'include',
|
||||
});
|
||||
const data = await resp.json();
|
||||
if (!resp.ok || data.status === 'error') {
|
||||
alert(`❌ Не удалось удалить: ${data.detail || resp.statusText}`);
|
||||
return;
|
||||
}
|
||||
await loadKeenetic();
|
||||
} catch (e) { alert('Error: ' + e.message); }
|
||||
}
|
||||
|
||||
@@ -601,6 +601,6 @@ loftliliana https://loftliliana.netcraze.pro 1020687391" style="width:100%;font-
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/xterm@5.3.0/lib/xterm.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/xterm-addon-fit@0.8.0/lib/xterm-addon-fit.min.js"></script>
|
||||
<script src="/static/js/app.js?v=20260524c"></script>
|
||||
<script src="/static/js/app.js?v=20260529a"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user