-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
513 lines (465 loc) · 15.8 KB
/
index.html
File metadata and controls
513 lines (465 loc) · 15.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
<!doctype html>
<html lang="de">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>TaskPilot Dashboard</title>
<style>
body { font-family: system-ui, Arial, sans-serif; margin: 20px; }
h1 { font-size: 20px; margin-bottom: 10px; }
#status { margin-bottom: 8px; color: #555; font-weight: bold; }
#lastUpdate { font-size: 12px; color: #999; margin-bottom: 12px; }
table { border-collapse: collapse; width: 100%; }
th, td { border: 1px solid #ddd; padding: 8px; font-size: 14px; }
th { background: #f0f0f0; text-align: left; }
.ok { color: #2e7d32; }
.bad { color: #c62828; }
.actions { white-space: nowrap; }
.actions button { padding: 4px 10px; margin: 0 2px; font-size: 12px; cursor: pointer; }
.actions button:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-start { background: #2e7d32; color: white; border: none; border-radius: 3px; }
.btn-stop { background: #c62828; color: white; border: none; border-radius: 3px; }
/* Login Modal */
#loginModal {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
justify-content: center;
z-index: 1000;
}
#loginModal.hidden {
display: none;
}
.login-box {
background: white;
padding: 30px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
text-align: center;
min-width: 300px;
}
.login-box h2 {
margin: 0 0 20px 0;
font-size: 18px;
}
.login-box input {
width: 100%;
padding: 10px;
margin-bottom: 15px;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box;
font-size: 14px;
}
.login-box button {
width: 100%;
padding: 10px;
background: #1976d2;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
font-weight: bold;
}
.login-box button:hover {
background: #1565c0;
}
.login-box .error {
color: #c62828;
margin-bottom: 10px;
font-size: 12px;
}
#contentArea {
display: none;
}
#contentArea.visible {
display: block;
}
.logout-btn {
padding: 6px 12px;
background: #f44336;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 12px;
}
.logout-btn:hover {
background: #d32f2f;
}
.login-btn {
padding: 6px 12px;
background: #1976d2;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 12px;
}
.login-btn:hover {
background: #1565c0;
}
#autoStartNote {
display: inline;
}
#autoStartNote.hidden {
display: none;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/microsoft-signalr/8.0.0/signalr.min.js" integrity="sha512-1k6xgF2h1k1WmW85p0lPHi2tY1gq2tWnqWf+QmZVfCkHfQqz2Jz2E4M51vX1dW1Q1p7J0QjQpK9Y8V//a3oS9w==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
</head>
<body>
<!-- Login Modal (nur wenn nötig) -->
<div id="loginModal" class="hidden">
<div class="login-box">
<h2>Authentifizierung erforderlich</h2>
<p style="font-size: 12px; color: #666; margin: 0 0 15px 0;">Gib das Passwort ein um Prozesse zu steuern</p>
<div id="loginError" class="error"></div>
<input type="password" id="passwordInput" placeholder="Passwort eingeben" onkeypress="if(event.key==='Enter') login()">
<button onclick="login()">Anmelden</button>
</div>
</div>
<!-- Hauptinhalt -->
<div id="contentArea" class="visible">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px;">
<h1 style="margin: 0;">TaskPilot Dashboard</h1>
<div id="authStatus" style="font-size: 12px; color: #999;">
<span id="authStatusText">⏳ Nicht angemeldet</span>
<button id="loginBtn" class="login-btn" onclick="showLoginModal()" style="margin-left: 10px;">Anmelden</button>
<button id="logoutBtn" class="logout-btn" onclick="logout()" style="display: none; margin-left: 10px;">Abmelden</button>
</div>
</div>
<div id="status">⏳ Initialisiere...</div>
<div id="lastUpdate"></div>
<div style="margin-bottom: 12px;">
<label style="font-weight: bold; cursor: pointer;">
<input type="checkbox" id="globalAutoStart" onchange="toggleGlobalAutoStart(this.checked)" disabled>
AutoStart global aktiviert
</label>
<span style="font-size: 11px; color: #999; margin-left: 10px;" id="autoStartNote">(Anmelden um zu aktivieren)</span>
</div>
<table>
<thead>
<tr>
<th>Name</th>
<th>Status</th>
<th>PID</th>
<th>Seit</th>
<th>Aktionen</th>
</tr>
</thead>
<tbody id="tbody"></tbody>
</table>
</div>
<script>
const apiBase = location.origin;
const tbody = document.getElementById('tbody');
const statusEl = document.getElementById('status');
const lastUpdateEl = document.getElementById('lastUpdate');
const globalAutoStartEl = document.getElementById('globalAutoStart');
const loginModal = document.getElementById('loginModal');
const contentArea = document.getElementById('contentArea');
const passwordInput = document.getElementById('passwordInput');
const loginError = document.getElementById('loginError');
const logoutBtn = document.getElementById('logoutBtn');
const authStatusText = document.getElementById('authStatusText');
const autoStartNote = document.getElementById('autoStartNote');
let connection = null;
let isUpdatingCheckboxProgrammatically = false;
let authToken = localStorage.getItem('taskpilot_token');
function log(msg) {
const ts = new Date().toLocaleTimeString('de-DE');
console.log(`[${ts}] ${msg}`);
}
function getAuthHeaders() {
return {
'Content-Type': 'application/json',
'Authorization': `Bearer ${authToken}`
};
}
function isAuthenticated() {
return authToken !== null && authToken !== '';
}
function updateAuthUI() {
if (isAuthenticated()) {
authStatusText.textContent = '✓ Angemeldet';
document.getElementById('loginBtn').style.display = 'none';
logoutBtn.style.display = 'inline-block';
autoStartNote.classList.add('hidden');
globalAutoStartEl.disabled = false;
// Aktiviere alle Action-Buttons
document.querySelectorAll('.actions button').forEach(btn => {
btn.disabled = false;
});
} else {
authStatusText.textContent = '⏳ Nicht angemeldet';
document.getElementById('loginBtn').style.display = 'inline-block';
logoutBtn.style.display = 'none';
autoStartNote.classList.remove('hidden');
globalAutoStartEl.disabled = true;
// Deaktiviere Action-Buttons
document.querySelectorAll('.actions button').forEach(btn => {
btn.disabled = true;
});
}
}
async function login() {
const password = passwordInput.value;
if (!password) {
loginError.textContent = 'Passwort erforderlich';
return;
}
try {
loginError.textContent = '';
log('Login-Anfrage...');
const res = await fetch(`${apiBase}/api/auth/login`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ password })
});
if (res.ok) {
const data = await res.json();
authToken = data.token;
localStorage.setItem('taskpilot_token', authToken);
log('✓ Login erfolgreich');
loginModal.classList.add('hidden');
passwordInput.value = '';
updateAuthUI();
} else {
loginError.textContent = 'Passwort falsch';
log('✗ Login fehlgeschlagen');
}
} catch (e) {
loginError.textContent = `Fehler: ${e.message}`;
log(`Login-Fehler: ${e.message}`);
}
}
function logout() {
authToken = null;
localStorage.removeItem('taskpilot_token');
passwordInput.value = '';
loginError.textContent = '';
updateAuthUI();
log('Logout');
}
function showLoginModal() {
loginModal.classList.remove('hidden');
passwordInput.focus();
}
function updateTimestamp() {
const now = new Date();
lastUpdateEl.textContent = `Letzte Aktualisierung: ${now.toLocaleString('de-DE')}`;
}
function renderRows(items) {
tbody.innerHTML = '';
for (const it of items) {
const tr = document.createElement('tr');
const canStart = !it.isActive && it.hasStartCommand;
const canStop = it.isActive;
const isAuth = isAuthenticated();
tr.innerHTML = `
<td>${it.displayName}</td>
<td class="${it.isActive ? 'ok' : 'bad'}">${it.statusText}</td>
<td>${it.processId || ''}</td>
<td>${new Date(it.statusSince).toLocaleString('de-DE')}</td>
<td class="actions">
<button class="btn-start" ${(canStart && isAuth) ? '' : 'disabled'}
onclick="startProcess('${it.processName}')"
title="${!isAuth ? 'Anmelden erforderlich' : (canStart ? 'Prozess starten' : 'Nicht verfügbar')}">
Start
</button>
<button class="btn-stop" ${(canStop && isAuth) ? '' : 'disabled'}
onclick="stopProcess('${it.processName}')"
title="${!isAuth ? 'Anmelden erforderlich' : (canStop ? 'Prozess stoppen' : 'Nicht aktiv')}">
Stop
</button>
</td>
`;
tbody.appendChild(tr);
}
loadGlobalAutoStart();
updateTimestamp();
}
async function startProcess(processName) {
if (!isAuthenticated()) {
showLoginModal();
return;
}
try {
log(`Starte Prozess: ${processName}`);
const res = await fetch(`${apiBase}/api/processes/${processName}/start`, {
method: 'POST',
headers: getAuthHeaders()
});
const data = await res.json();
if (res.ok) {
log(`✓ Start erfolgreich: ${processName}`);
setTimeout(load, 1000);
} else if (res.status === 401) {
logout();
showLoginModal();
} else {
log(`✗ Start fehlgeschlagen: ${data.error || 'Unbekannt'}`);
}
} catch (e) {
log(`✗ Fehler beim Starten: ${e.message}`);
}
}
async function stopProcess(processName) {
if (!isAuthenticated()) {
showLoginModal();
return;
}
try {
log(`Stoppe Prozess: ${processName}`);
const res = await fetch(`${apiBase}/api/processes/${processName}/stop`, {
method: 'POST',
headers: getAuthHeaders()
});
const data = await res.json();
if (res.ok) {
log(`✓ Stop erfolgreich: ${processName}`);
setTimeout(load, 1000);
} else if (res.status === 401) {
logout();
showLoginModal();
} else {
log(`✗ Stop fehlgeschlagen: ${data.error || 'Unbekannt'}`);
}
} catch (e) {
log(`✗ Fehler beim Stoppen: ${e.message}`);
}
}
async function toggleGlobalAutoStart(checked) {
if (!isAuthenticated()) {
globalAutoStartEl.checked = !checked;
showLoginModal();
return;
}
if (isUpdatingCheckboxProgrammatically) {
log('Ignoriere toggleGlobalAutoStart da checkbox vom Programm aktualisiert wird');
return;
}
try {
log(`Toggle Global AutoStart: ${checked}`);
const res = await fetch(`${apiBase}/api/settings/autostart`, {
method: 'POST',
headers: getAuthHeaders(),
body: JSON.stringify({ enabled: checked })
});
if (res.ok) {
log(`✓ Global AutoStart geändert: ${checked}`);
} else if (res.status === 401) {
logout();
showLoginModal();
} else {
log(`✗ Fehler beim Ändern von Global AutoStart`);
globalAutoStartEl.checked = !checked;
}
} catch (e) {
log(`✗ Fehler: ${e.message}`);
globalAutoStartEl.checked = !checked;
}
}
async function loadGlobalAutoStart() {
try {
log('Lade GlobalAutoStart Status...');
const res = await fetch(`${apiBase}/api/settings/autostart`);
if (res.ok) {
const data = await res.json();
log(`GET /api/settings/autostart antwortet: enabled=${data.enabled}`);
isUpdatingCheckboxProgrammatically = true;
globalAutoStartEl.checked = data.enabled;
isUpdatingCheckboxProgrammatically = false;
log(`✓ Checkbox aktualisiert auf: ${data.enabled}`);
} else {
log(`Fehler: GET /api/settings/autostart antwortet mit Status ${res.status}`);
}
} catch (e) {
log(`Fehler beim Laden von AutoStart: ${e.message}`);
}
}
async function load() {
try {
log('Fetching /api/processes...');
const res = await fetch(`${apiBase}/api/processes`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
renderRows(data);
statusEl.textContent = `✓ Verbunden (${data.length} Prozesse)`;
log(`Loaded ${data.length} processes`);
} catch (e) {
statusEl.textContent = '✗ Fehler beim Laden';
log(`Error: ${e.message}`);
await loadGlobalAutoStart();
}
}
function startLiveUpdates() {
log('Lade initiale Daten...');
load();
loadGlobalAutoStart();
setTimeout(() => {
if (typeof signalR === 'undefined') {
log('SignalR nicht verfügbar - Polling-Fallback aktiv');
statusEl.textContent = '⚠ Polling-Modus (5s)';
setInterval(load, 5000);
return;
}
log('Initialisiere SignalR...');
try {
connection = new signalR.HubConnectionBuilder()
.withUrl(`${apiBase}/hub/status`)
.withAutomaticReconnect()
.configureLogging(signalR.LogLevel.Warning)
.build();
connection.onreconnecting(() => {
statusEl.textContent = '⟳ Verbindung wird wiederhergestellt...';
log('SignalR reconnecting...');
});
connection.onreconnected(() => {
statusEl.textContent = '✓ SignalR Live';
log('SignalR reconnected');
});
connection.onclose(() => {
statusEl.textContent = '✗ Verbindung getrennt';
log('SignalR closed');
});
connection.on('statusChanged', (s) => {
log(`Status geändert: ${s.displayName}`);
load();
});
connection.on('statusSnapshot', (items) => {
log(`Snapshot empfangen: ${items.length} Prozesse`);
renderRows(items);
statusEl.textContent = '✓ SignalR Live';
loadGlobalAutoStart();
});
connection.start()
.then(() => {
statusEl.textContent = '✓ SignalR Live';
log('SignalR verbunden');
})
.catch(err => {
statusEl.textContent = '⚠ Polling-Modus (5s)';
log('SignalR Fehler, verwende Polling: ' + err);
setInterval(load, 5000);
});
} catch (ex) {
log('Exception: ' + ex);
statusEl.textContent = '⚠ Polling-Modus (5s)';
setInterval(load, 5000);
}
}, 100);
}
// Beim Laden: Zeige Dashboard an und starte Updates
updateAuthUI();
startLiveUpdates();
</script>
</body>
</html>