roll back authentik login. removed and restore working state.

This commit is contained in:
2025-11-19 11:42:06 +01:00
parent e8eb2e954c
commit cb428a885d
23 changed files with 730 additions and 2512 deletions
@@ -15,106 +15,163 @@
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: transparent;
color: #e0e0e0;
padding: 10px;
padding: 15px;
}
.container {
max-width: 1200px;
margin: 0 auto;
max-width: 100%;
}
h2 {
.section {
margin-bottom: 30px;
}
.section-header {
color: #fff;
margin-bottom: 15px;
font-size: 20px;
font-weight: 500;
font-size: 18px;
font-weight: 600;
margin-bottom: 12px;
padding-bottom: 8px;
border-bottom: 2px solid rgba(255, 255, 255, 0.1);
}
.service-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
.service-list {
display: flex;
flex-direction: column;
gap: 8px;
}
.service-row {
background: rgba(40, 40, 40, 0.95);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 6px;
padding: 12px 16px;
display: flex;
align-items: center;
justify-content: space-between;
transition: all 0.2s ease;
gap: 15px;
}
.service-card {
background: rgba(40, 40, 40, 0.95);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 8px;
padding: 15px;
transition: all 0.3s ease;
.service-row:hover {
border-color: rgba(66, 153, 225, 0.4);
background: rgba(45, 45, 45, 0.95);
}
.service-card:hover {
border-color: rgba(66, 153, 225, 0.5);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.service-header {
.service-left {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 12px;
gap: 15px;
flex: 1;
min-width: 0;
}
.service-name {
font-size: 16px;
font-size: 15px;
font-weight: 600;
color: #fff;
text-transform: capitalize;
min-width: 300px;
}
.status-badge {
padding: 4px 12px;
border-radius: 12px;
font-size: 12px;
font-weight: 600;
text-transform: uppercase;
.service-status {
display: flex;
align-items: center;
gap: 8px;
min-width: 120px;
}
.status-running {
background: rgba(72, 187, 120, 0.2);
color: #48bb78;
border: 1px solid rgba(72, 187, 120, 0.4);
.status-indicator {
width: 8px;
height: 8px;
border-radius: 50%;
flex-shrink: 0;
}
.status-stopped {
background: rgba(245, 101, 101, 0.2);
color: #f56565;
border: 1px solid rgba(245, 101, 101, 0.4);
.status-indicator.running {
background: #48bb78;
box-shadow: 0 0 8px rgba(72, 187, 120, 0.6);
}
.status-loading {
background: rgba(237, 137, 54, 0.2);
color: #ed8936;
border: 1px solid rgba(237, 137, 54, 0.4);
.status-indicator.stopped {
background: #f56565;
box-shadow: 0 0 8px rgba(245, 101, 101, 0.6);
}
.service-info {
.status-text {
font-size: 13px;
color: #a0a0a0;
margin-bottom: 12px;
}
.service-actions {
.uptime-status {
display: flex;
align-items: center;
gap: 8px;
min-width: 150px;
padding: 4px 10px;
background: rgba(0, 0, 0, 0.2);
border-radius: 4px;
cursor: pointer;
transition: background 0.2s;
text-decoration: none;
color: inherit;
}
.uptime-status:hover {
background: rgba(0, 0, 0, 0.4);
}
.uptime-percentage {
font-size: 13px;
font-weight: 600;
}
.uptime-percentage.excellent {
color: #48bb78;
}
.uptime-percentage.good {
color: #68d391;
}
.uptime-percentage.warning {
color: #ed8936;
}
.uptime-percentage.critical {
color: #f56565;
}
.uptime-percentage.unknown {
color: #718096;
}
.uptime-icon {
font-size: 11px;
color: #a0a0a0;
}
.service-right {
display: flex;
align-items: center;
gap: 8px;
}
.btn {
flex: 1;
padding: 8px 12px;
padding: 6px 16px;
border: none;
border-radius: 6px;
font-size: 13px;
border-radius: 4px;
font-size: 12px;
font-weight: 600;
cursor: pointer;
transition: all 0.2s ease;
text-transform: uppercase;
letter-spacing: 0.5px;
min-width: 70px;
}
.btn:disabled {
opacity: 0.5;
opacity: 0.3;
cursor: not-allowed;
}
@@ -126,6 +183,7 @@
.btn-start:hover:not(:disabled) {
background: linear-gradient(135deg, #38a169 0%, #2f855a 100%);
transform: translateY(-1px);
box-shadow: 0 2px 8px rgba(72, 187, 120, 0.3);
}
.btn-stop {
@@ -136,21 +194,12 @@
.btn-stop:hover:not(:disabled) {
background: linear-gradient(135deg, #e53e3e 0%, #c53030 100%);
transform: translateY(-1px);
}
.btn-restart {
background: linear-gradient(135deg, #4299e1 0%, #3182ce 100%);
color: white;
}
.btn-restart:hover:not(:disabled) {
background: linear-gradient(135deg, #3182ce 0%, #2c5282 100%);
transform: translateY(-1px);
box-shadow: 0 2px 8px rgba(245, 101, 101, 0.3);
}
.loading {
text-align: center;
padding: 40px;
padding: 30px;
color: #a0a0a0;
}
@@ -164,14 +213,14 @@
}
.always-on-badge {
display: inline-block;
padding: 2px 8px;
background: rgba(66, 153, 225, 0.2);
font-size: 10px;
color: #4299e1;
border: 1px solid rgba(66, 153, 225, 0.4);
border-radius: 10px;
font-size: 11px;
background: rgba(66, 153, 225, 0.15);
padding: 2px 6px;
border-radius: 3px;
margin-left: 8px;
text-transform: uppercase;
font-weight: 600;
}
@keyframes spin {
@@ -180,45 +229,102 @@
.spinner {
display: inline-block;
width: 14px;
height: 14px;
width: 12px;
height: 12px;
border: 2px solid rgba(255, 255, 255, 0.3);
border-top-color: #fff;
border-radius: 50%;
animation: spin 0.6s linear infinite;
margin-right: 6px;
}
/* Responsive design */
@media (max-width: 768px) {
.service-row {
flex-wrap: wrap;
}
.service-name {
min-width: 100px;
}
.uptime-status {
min-width: 100px;
}
.service-right {
width: 100%;
justify-content: flex-end;
}
}
</style>
</head>
<body>
<div class="container">
<h2>🎛️ On-Demand Services</h2>
<div id="error-container"></div>
<div id="service-container" class="loading">Loading services...</div>
<div class="section">
<div class="section-header">🎛️ Stoppable Services</div>
<div id="stoppable-container" class="loading">Loading services...</div>
</div>
<div class="section">
<div class="section-header">🔒 Always-On Infrastructure</div>
<div id="always-on-container" class="loading">Loading infrastructure...</div>
</div>
</div>
<script>
// Auto-detect API base from current domain (works with NPM proxy)
const API_BASE = window.location.origin;
// Use relative URL to work in any context (iframe, direct access, etc.)
const API_BASE = '';
const KUMA_BASE = window.location.protocol + '//' + window.location.hostname + ':3001';
let services = [];
let alwaysOnServices = [];
let monitors = {};
async function fetchServices() {
async function fetchData() {
try {
const response = await fetch(`${API_BASE}/infrastructure/services`);
if (!response.ok) throw new Error('Failed to fetch services');
services = await response.json();
// Single API call to get all data
const response = await fetch(`${API_BASE}/infrastructure/widget-data`);
const groupsResponse = await fetch(`${API_BASE}/infrastructure/service-groups`);
if (groupsResponse.ok) {
const groupsData = await groupsResponse.json();
alwaysOnServices = groupsData.always_on || [];
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
const data = await response.json();
if (!data.success) {
throw new Error('API returned unsuccessful response');
}
// Update services
services = data.services || [];
// Update always-on services list
if (data.service_groups && data.service_groups.always_on) {
alwaysOnServices = data.service_groups.always_on;
}
// Build monitors map
const monitorsMap = {};
if (data.monitors) {
data.monitors.forEach(monitor => {
const name = monitor.name.toLowerCase().replace(/[^a-z0-9]/g, '-');
monitorsMap[name] = {
id: monitor.id,
uptime_24h: monitor.uptime_24h || 0,
active: monitor.active !== false
};
});
}
monitors = monitorsMap;
renderServices();
document.getElementById('error-container').innerHTML = '';
} catch (error) {
console.error('Error fetching services:', error);
console.error('Error fetching data:', error);
document.getElementById('error-container').innerHTML =
`<div class="error">❌ Failed to connect to API: ${error.message}</div>`;
}
@@ -228,80 +334,118 @@
return alwaysOnServices.includes(serviceName.toLowerCase());
}
function getServiceStatus(service) {
if (service.containers_running > 0) {
function getUptimeInfo(serviceName) {
const monitorKey = serviceName.toLowerCase().replace(/[^a-z0-9]/g, '-');
const monitor = monitors[monitorKey];
if (!monitor) {
return {
class: 'status-running',
text: `Running (${service.containers_running}/${service.containers_total})`
};
} else if (service.containers_total > 0) {
return {
class: 'status-stopped',
text: 'Stopped'
};
} else {
return {
class: 'status-stopped',
text: 'No containers'
percentage: 0,
class: 'unknown',
text: 'No monitor',
id: null
};
}
const uptime = monitor.uptime_24h;
let className = 'unknown';
if (uptime >= 99.5) className = 'excellent';
else if (uptime >= 95) className = 'good';
else if (uptime >= 90) className = 'warning';
else if (uptime > 0) className = 'critical';
return {
percentage: uptime,
class: className,
text: uptime > 0 ? `${uptime.toFixed(1)}% ↑` : 'Down',
id: monitor.id
};
}
function renderServiceRow(service) {
const isRunning = service.containers_running > 0;
const alwaysOn = isAlwaysOn(service.name);
const uptime = getUptimeInfo(service.name);
const kumaLink = uptime.id ?
`${KUMA_BASE}/dashboard/${uptime.id}` :
KUMA_BASE;
return `
<div class="service-row" data-service="${service.name}">
<div class="service-left">
<div class="service-name">
${service.name}
${alwaysOn ? '<span class="always-on-badge">Protected</span>' : ''}
</div>
<div class="service-status">
<div class="status-indicator ${isRunning ? 'running' : 'stopped'}"></div>
<span class="status-text">
${isRunning ? `Running (${service.containers_running}/${service.containers_total})` : 'Stopped'}
</span>
</div>
<a href="${kumaLink}" target="_blank" class="uptime-status" title="View in Uptime Kuma">
<span class="uptime-icon">📊</span>
<span class="uptime-percentage ${uptime.class}">${uptime.text}</span>
</a>
</div>
<div class="service-right">
<button class="btn btn-start"
onclick="controlService('${service.name}', 'start')"
${isRunning || alwaysOn ? 'disabled' : ''}>
Start
</button>
<button class="btn btn-stop"
onclick="controlService('${service.name}', 'stop')"
${!isRunning || alwaysOn ? 'disabled' : ''}>
Stop
</button>
</div>
</div>
`;
}
function renderServices() {
const container = document.getElementById('service-container');
const stoppableContainer = document.getElementById('stoppable-container');
const alwaysOnContainer = document.getElementById('always-on-container');
// Filter to only show stoppable services
// Stoppable services
const stoppableServices = services.filter(s => !isAlwaysOn(s.name));
if (stoppableServices.length === 0) {
container.innerHTML = '<div class="loading">No stoppable services found</div>';
return;
stoppableContainer.innerHTML = '<div class="loading">No stoppable services found</div>';
} else {
stoppableContainer.className = 'service-list';
stoppableContainer.innerHTML = stoppableServices
.sort((a, b) => a.name.localeCompare(b.name))
.map(service => renderServiceRow(service))
.join('');
}
container.className = 'service-grid';
container.innerHTML = stoppableServices.map(service => {
const status = getServiceStatus(service);
const isRunning = service.containers_running > 0;
const alwaysOn = isAlwaysOn(service.name);
// Always-on services
const alwaysOnServicesList = services.filter(s => isAlwaysOn(s.name));
return `
<div class="service-card" data-service="${service.name}">
<div class="service-header">
<span class="service-name">
${service.name}
${alwaysOn ? '<span class="always-on-badge">ALWAYS ON</span>' : ''}
</span>
<span class="status-badge ${status.class}">${status.text}</span>
</div>
<div class="service-info">
Stack ID: ${service.stack_id || 'N/A'}
</div>
<div class="service-actions">
<button class="btn btn-start"
onclick="controlService('${service.name}', 'start')"
${isRunning || alwaysOn ? 'disabled' : ''}>
Start
</button>
<button class="btn btn-stop"
onclick="controlService('${service.name}', 'stop')"
${!isRunning || alwaysOn ? 'disabled' : ''}>
Stop
</button>
</div>
</div>
`;
}).join('');
if (alwaysOnServicesList.length === 0) {
alwaysOnContainer.innerHTML = '<div class="loading">No infrastructure services found</div>';
} else {
alwaysOnContainer.className = 'service-list';
alwaysOnContainer.innerHTML = alwaysOnServicesList
.sort((a, b) => a.name.localeCompare(b.name))
.map(service => renderServiceRow(service))
.join('');
}
}
async function controlService(serviceName, action) {
const card = document.querySelector(`[data-service="${serviceName}"]`);
const buttons = card.querySelectorAll('button');
const row = document.querySelector(`[data-service="${serviceName}"]`);
const buttons = row.querySelectorAll('button');
// Disable all buttons and show loading
buttons.forEach(btn => {
btn.disabled = true;
if (btn.textContent.toLowerCase().includes(action)) {
btn.innerHTML = `<span class="spinner"></span>${action.toUpperCase()}...`;
btn.innerHTML = `<span class="spinner"></span>${action}`;
}
});
@@ -318,26 +462,26 @@
console.log(`${action} ${serviceName}:`, result);
// Wait a bit for containers to start/stop
// Wait for containers to start/stop
await new Promise(resolve => setTimeout(resolve, 2000));
// Refresh service list
await fetchServices();
await fetchData();
} catch (error) {
console.error(`Error ${action}ing ${serviceName}:`, error);
alert(`Failed to ${action} ${serviceName}: ${error.message}`);
// Re-enable buttons on error
await fetchServices();
await fetchData();
}
}
// Auto-refresh every 10 seconds
setInterval(fetchServices, 10000);
setInterval(fetchData, 10000);
// Initial load
fetchServices();
fetchData();
</script>
</body>
</html>