fix(packaging): move templates into core/ for PyPI distribution

Templates were at project root (templates/) which is outside the Python
package, so `pip install mcphub-server` would not include them. Moved to
core/templates/ and updated path references in server.py and
core/dashboard/routes.py. Also added py-modules for server.py and
server_multi.py to pyproject.toml.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
airano
2026-02-18 02:41:28 +03:30
parent 5e0441c85e
commit 7daf604a32
18 changed files with 16 additions and 9 deletions

View File

@@ -16,10 +16,8 @@ from .auth import get_dashboard_auth
logger = logging.getLogger(__name__)
# Templates directory
TEMPLATES_DIR = os.path.join(
os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "templates"
)
# Templates directory (core/templates/ — one level up from core/dashboard/)
TEMPLATES_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "templates")
templates = Jinja2Templates(directory=TEMPLATES_DIR)
# Plugin display names mapping (for special cases like n8n)

62
core/templates/base.html Normal file
View File

@@ -0,0 +1,62 @@
<!DOCTYPE html>
<html lang="{{ lang|default('en') }}">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %}MCP Hub{% endblock %}</title>
<!-- Tailwind CSS from CDN -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Custom styling -->
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
.auth-container {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.auth-card {
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}
.btn-primary {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
transition: all 0.3s ease;
}
.btn-primary:hover {
transform: translateY(-2px);
box-shadow: 0 10px 20px rgba(102, 126, 234, 0.4);
}
.btn-secondary {
transition: all 0.3s ease;
}
.btn-secondary:hover {
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(107, 114, 128, 0.3);
}
.permission-badge {
animation: fadeInUp 0.5s ease;
}
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
</style>
{% block extra_head %}{% endblock %}
</head>
<body class="bg-gray-50 dark:bg-gray-900">
{% block content %}{% endblock %}
{% block scripts %}{% endblock %}
</body>
</html>

View File

@@ -0,0 +1,709 @@
{% extends "dashboard/base.html" %}
{% block title %}{{ t.api_keys }}{% endblock %}
{% block page_title %}{{ t.api_keys }}{% endblock %}
{% block content %}
<div class="space-y-6">
<!-- Header with Create Button -->
<div class="flex flex-wrap items-center justify-between gap-4">
<div>
<p class="text-gray-400 text-sm">
{% if lang == 'fa' %}مدیریت کلیدهای API برای دسترسی به ابزارها{% else %}Manage API keys for tool access{% endif %}
</p>
</div>
<button
onclick="openCreateModal()"
class="px-4 py-2 bg-primary-600 hover:bg-primary-700 rounded-lg text-white text-sm font-medium transition-colors flex items-center"
>
<svg class="w-5 h-5 {% if lang == 'fa' %}ml-2{% else %}mr-2{% endif %}" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
</svg>
{% if lang == 'fa' %}ایجاد کلید جدید{% else %}Create New Key{% endif %}
</button>
</div>
<!-- Filters -->
<div class="bg-gray-800 rounded-xl border border-gray-700 p-4">
<form method="GET" class="flex flex-wrap items-center gap-4">
{% if lang and lang != 'en' %}<input type="hidden" name="lang" value="{{ lang }}">{% endif %}
<!-- Project Filter -->
<div class="flex items-center gap-2">
<label class="text-sm text-gray-400">{{ t.filter }}:</label>
<select
name="project"
class="bg-gray-700 border border-gray-600 rounded-lg px-3 py-2 text-white text-sm focus:ring-2 focus:ring-primary-500 focus:border-transparent"
onchange="this.form.submit()"
>
<option value="">{% if lang == 'fa' %}همه پروژه‌ها{% else %}All Projects{% endif %}</option>
<option value="*" {% if selected_project == '*' %}selected{% endif %}>{% if lang == 'fa' %}کلیدهای عمومی (*){% else %}Global Keys (*){% endif %}</option>
{% for project in available_projects %}
<option value="{{ project.full_id }}" {% if selected_project == project.full_id %}selected{% endif %}>
{{ project.plugin_type }}: {{ project.alias or project.site_id }}
</option>
{% endfor %}
</select>
</div>
<!-- Status Filter -->
<div class="flex items-center gap-2">
<label class="text-sm text-gray-400">{% if lang == 'fa' %}وضعیت:{% else %}Status:{% endif %}</label>
<select
name="status"
class="bg-gray-700 border border-gray-600 rounded-lg px-3 py-2 text-white text-sm focus:ring-2 focus:ring-primary-500 focus:border-transparent"
onchange="this.form.submit()"
>
<option value="active" {% if selected_status == 'active' %}selected{% endif %}>{% if lang == 'fa' %}فعال{% else %}Active{% endif %}</option>
<option value="all" {% if selected_status == 'all' %}selected{% endif %}>{% if lang == 'fa' %}همه{% else %}All{% endif %}</option>
<option value="revoked" {% if selected_status == 'revoked' %}selected{% endif %}>{% if lang == 'fa' %}لغو شده{% else %}Revoked{% endif %}</option>
</select>
</div>
<!-- Search -->
<div class="flex-1 min-w-[200px]">
<input
type="text"
name="search"
value="{{ search_query }}"
placeholder="{% if lang == 'fa' %}جستجو در توضیحات...{% else %}Search description...{% endif %}"
class="w-full bg-gray-700 border border-gray-600 rounded-lg px-4 py-2 text-white text-sm placeholder-gray-400 focus:ring-2 focus:ring-primary-500 focus:border-transparent"
>
</div>
<button type="submit" class="px-4 py-2 bg-primary-600 hover:bg-primary-700 rounded-lg text-white text-sm transition-colors">
{{ t.search }}
</button>
{% if search_query or selected_project or selected_status != 'active' %}
<a href="/dashboard/api-keys{% if lang and lang != 'en' %}?lang={{ lang }}{% endif %}" class="px-4 py-2 bg-gray-700 hover:bg-gray-600 rounded-lg text-white text-sm transition-colors">
{{ t['clear'] }}
</a>
{% endif %}
</form>
</div>
<!-- API Keys Table -->
<div class="bg-gray-800 rounded-xl border border-gray-700 overflow-hidden">
<div class="overflow-x-auto">
<table class="w-full">
<thead class="bg-gray-700/50">
<tr>
<th class="px-6 py-4 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-sm font-medium text-gray-300">
{% if lang == 'fa' %}شناسه کلید{% else %}Key ID{% endif %}
</th>
<th class="px-6 py-4 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-sm font-medium text-gray-300">
{% if lang == 'fa' %}پروژه{% else %}Project{% endif %}
</th>
<th class="px-6 py-4 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-sm font-medium text-gray-300">
{% if lang == 'fa' %}دسترسی{% else %}Scope{% endif %}
</th>
<th class="px-6 py-4 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-sm font-medium text-gray-300">
{% if lang == 'fa' %}توضیحات{% else %}Description{% endif %}
</th>
<th class="px-6 py-4 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-sm font-medium text-gray-300">
{% if lang == 'fa' %}وضعیت{% else %}Status{% endif %}
</th>
<th class="px-6 py-4 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-sm font-medium text-gray-300">
{% if lang == 'fa' %}استفاده{% else %}Usage{% endif %}
</th>
<th class="px-6 py-4 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-sm font-medium text-gray-300">
{% if lang == 'fa' %}عملیات{% else %}Actions{% endif %}
</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-700">
{% if api_keys %}
{% for key in api_keys %}
<tr class="hover:bg-gray-700/30 transition-colors {% if key.revoked %}opacity-50{% endif %}">
<!-- Key ID -->
<td class="px-6 py-4">
<div class="flex items-center">
<span class="text-sm text-gray-300 font-mono">{{ key.key_id[:12] }}...</span>
<button
onclick="copyToClipboard('{{ key.key_id }}')"
class="{% if lang == 'fa' %}mr-2{% else %}ml-2{% endif %} text-gray-400 hover:text-white transition-colors"
title="{% if lang == 'fa' %}کپی شناسه{% else %}Copy ID{% endif %}"
>
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"/>
</svg>
</button>
</div>
</td>
<!-- Project -->
<td class="px-6 py-4">
{% if key.project_id == '*' %}
<span class="px-2 py-1 bg-yellow-500/20 text-yellow-400 text-xs rounded-lg font-medium">
{% if lang == 'fa' %}همه پروژه‌ها{% else %}All Projects{% endif %}
</span>
{% else %}
<span class="text-sm text-gray-300">{{ key.project_id }}</span>
{% endif %}
</td>
<!-- Scope -->
<td class="px-6 py-4">
<div class="flex flex-wrap gap-1">
{% for scope in key.scope.split() %}
<span class="px-2 py-0.5 {% if scope == 'admin' %}bg-red-500/20 text-red-400{% elif scope == 'write' %}bg-orange-500/20 text-orange-400{% else %}bg-blue-500/20 text-blue-400{% endif %} text-xs rounded font-medium">
{{ scope }}
</span>
{% endfor %}
</div>
</td>
<!-- Description -->
<td class="px-6 py-4">
<span class="text-sm text-gray-400">{{ key.description or '-' }}</span>
</td>
<!-- Status -->
<td class="px-6 py-4">
{% if key.revoked %}
<div class="flex items-center">
<span class="w-2 h-2 bg-red-500 rounded-full {% if lang == 'fa' %}ml-2{% else %}mr-2{% endif %}"></span>
<span class="text-sm text-red-400">{% if lang == 'fa' %}لغو شده{% else %}Revoked{% endif %}</span>
</div>
{% elif key.expires_at and key.is_expired %}
<div class="flex items-center">
<span class="w-2 h-2 bg-yellow-500 rounded-full {% if lang == 'fa' %}ml-2{% else %}mr-2{% endif %}"></span>
<span class="text-sm text-yellow-400">{% if lang == 'fa' %}منقضی شده{% else %}Expired{% endif %}</span>
</div>
{% else %}
<div class="flex items-center">
<span class="w-2 h-2 bg-green-500 rounded-full status-pulse {% if lang == 'fa' %}ml-2{% else %}mr-2{% endif %}"></span>
<span class="text-sm text-green-400">{% if lang == 'fa' %}فعال{% else %}Active{% endif %}</span>
</div>
{% endif %}
</td>
<!-- Usage -->
<td class="px-6 py-4">
<span class="text-sm text-gray-300">{{ key.usage_count }}</span>
<span class="text-xs text-gray-500">{% if lang == 'fa' %}بار{% else %}calls{% endif %}</span>
</td>
<!-- Actions -->
<td class="px-6 py-4">
<div class="flex items-center gap-2">
{% if not key.revoked %}
<button
onclick="openRevokeModal('{{ key.key_id }}', '{{ key.description or key.key_id[:12] }}')"
class="p-2 bg-red-500/20 hover:bg-red-500/30 rounded-lg text-red-400 transition-colors"
title="{% if lang == 'fa' %}لغو کلید{% else %}Revoke Key{% endif %}"
>
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636"/>
</svg>
</button>
{% endif %}
<button
onclick="openDeleteModal('{{ key.key_id }}', '{{ key.description or key.key_id[:12] }}')"
class="p-2 bg-gray-700 hover:bg-gray-600 rounded-lg text-gray-400 hover:text-white transition-colors"
title="{% if lang == 'fa' %}حذف کلید{% else %}Delete Key{% endif %}"
>
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
</svg>
</button>
</div>
</td>
</tr>
{% endfor %}
{% else %}
<tr>
<td colspan="7" class="px-6 py-12 text-center">
<svg class="w-12 h-12 mx-auto mb-4 text-gray-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z"/>
</svg>
<p class="text-gray-400">
{% if lang == 'fa' %}کلید API یافت نشد{% else %}No API keys found{% endif %}
</p>
<button
onclick="openCreateModal()"
class="mt-4 px-4 py-2 bg-primary-600 hover:bg-primary-700 rounded-lg text-white text-sm transition-colors"
>
{% if lang == 'fa' %}ایجاد اولین کلید{% else %}Create First Key{% endif %}
</button>
</td>
</tr>
{% endif %}
</tbody>
</table>
</div>
<!-- Pagination -->
{% if total_pages > 1 %}
<div class="px-6 py-4 border-t border-gray-700 flex items-center justify-between">
<p class="text-sm text-gray-400">
{% if lang == 'fa' %}
نمایش {{ ((page_number - 1) * per_page) + 1 }} تا {{ [page_number * per_page, total_count]|min }} از {{ total_count }} کلید
{% else %}
Showing {{ ((page_number - 1) * per_page) + 1 }} to {{ [page_number * per_page, total_count]|min }} of {{ total_count }} keys
{% endif %}
</p>
<div class="flex items-center gap-2">
{% if page_number > 1 %}
<a href="?page={{ page_number - 1 }}{% if selected_project %}&project={{ selected_project }}{% endif %}{% if selected_status %}&status={{ selected_status }}{% endif %}{% if search_query %}&search={{ search_query }}{% endif %}{% if lang and lang != 'en' %}&lang={{ lang }}{% endif %}"
class="px-3 py-1.5 bg-gray-700 hover:bg-gray-600 rounded-lg text-sm text-white transition-colors">
{% if lang == 'fa' %}قبلی{% else %}Previous{% endif %}
</a>
{% endif %}
{% for page_num in range(1, total_pages + 1) %}
{% if page_num == page_number %}
<span class="px-3 py-1.5 bg-primary-600 rounded-lg text-sm text-white">{{ page_num }}</span>
{% elif page_num == 1 or page_num == total_pages or (page_num >= page_number - 2 and page_num <= page_number + 2) %}
<a href="?page={{ page_num }}{% if selected_project %}&project={{ selected_project }}{% endif %}{% if selected_status %}&status={{ selected_status }}{% endif %}{% if search_query %}&search={{ search_query }}{% endif %}{% if lang and lang != 'en' %}&lang={{ lang }}{% endif %}"
class="px-3 py-1.5 bg-gray-700 hover:bg-gray-600 rounded-lg text-sm text-white transition-colors">
{{ page_num }}
</a>
{% elif page_num == page_number - 3 or page_num == page_number + 3 %}
<span class="text-gray-500">...</span>
{% endif %}
{% endfor %}
{% if page_number < total_pages %}
<a href="?page={{ page_number + 1 }}{% if selected_project %}&project={{ selected_project }}{% endif %}{% if selected_status %}&status={{ selected_status }}{% endif %}{% if search_query %}&search={{ search_query }}{% endif %}{% if lang and lang != 'en' %}&lang={{ lang }}{% endif %}"
class="px-3 py-1.5 bg-gray-700 hover:bg-gray-600 rounded-lg text-sm text-white transition-colors">
{% if lang == 'fa' %}بعدی{% else %}Next{% endif %}
</a>
{% endif %}
</div>
</div>
{% endif %}
</div>
</div>
<!-- Create Key Modal -->
<div id="createModal" class="fixed inset-0 bg-black/50 hidden items-center justify-center z-50">
<div class="bg-gray-800 rounded-xl border border-gray-700 w-full max-w-md mx-4">
<div class="p-6 border-b border-gray-700">
<h3 class="text-lg font-semibold text-white">
{% if lang == 'fa' %}ایجاد کلید API جدید{% else %}Create New API Key{% endif %}
</h3>
</div>
<form id="createKeyForm" method="POST" action="/api/dashboard/api-keys/create" class="p-6 space-y-4">
{% if lang and lang != 'en' %}<input type="hidden" name="lang" value="{{ lang }}">{% endif %}
<!-- Project -->
<div>
<label class="block text-sm font-medium text-gray-300 mb-2">
{% if lang == 'fa' %}پروژه{% else %}Project{% endif %}
</label>
<select
name="project_id"
required
class="w-full bg-gray-700 border border-gray-600 rounded-lg px-4 py-2 text-white focus:ring-2 focus:ring-primary-500 focus:border-transparent"
>
<option value="*">{% if lang == 'fa' %}همه پروژه‌ها (*){% else %}All Projects (*){% endif %}</option>
{% for project in available_projects %}
<option value="{{ project.full_id }}">{{ project.plugin_type }}: {{ project.alias or project.site_id }}</option>
{% endfor %}
</select>
</div>
<!-- Scope -->
<div>
<label class="block text-sm font-medium text-gray-300 mb-2">
{% if lang == 'fa' %}سطح دسترسی{% else %}Scope{% endif %}
</label>
<div class="space-y-2">
<label class="flex items-center">
<input type="checkbox" name="scope_read" value="read" checked class="bg-gray-700 border-gray-600 rounded text-primary-600 focus:ring-primary-500">
<span class="{% if lang == 'fa' %}mr-2{% else %}ml-2{% endif %} text-sm text-gray-300">read - {% if lang == 'fa' %}خواندن داده‌ها{% else %}Read data{% endif %}</span>
</label>
<label class="flex items-center">
<input type="checkbox" name="scope_write" value="write" class="bg-gray-700 border-gray-600 rounded text-primary-600 focus:ring-primary-500">
<span class="{% if lang == 'fa' %}mr-2{% else %}ml-2{% endif %} text-sm text-gray-300">write - {% if lang == 'fa' %}نوشتن داده‌ها{% else %}Write data{% endif %}</span>
</label>
<label class="flex items-center">
<input type="checkbox" name="scope_admin" value="admin" class="bg-gray-700 border-gray-600 rounded text-primary-600 focus:ring-primary-500">
<span class="{% if lang == 'fa' %}mr-2{% else %}ml-2{% endif %} text-sm text-gray-300">admin - {% if lang == 'fa' %}مدیریت کامل{% else %}Full admin{% endif %}</span>
</label>
</div>
</div>
<!-- Description -->
<div>
<label class="block text-sm font-medium text-gray-300 mb-2">
{% if lang == 'fa' %}توضیحات (اختیاری){% else %}Description (optional){% endif %}
</label>
<input
type="text"
name="description"
placeholder="{% if lang == 'fa' %}مثال: کلید برای CI/CD{% else %}e.g., Key for CI/CD{% endif %}"
class="w-full bg-gray-700 border border-gray-600 rounded-lg px-4 py-2 text-white placeholder-gray-400 focus:ring-2 focus:ring-primary-500 focus:border-transparent"
>
</div>
<!-- Expiration -->
<div>
<label class="block text-sm font-medium text-gray-300 mb-2">
{% if lang == 'fa' %}انقضا (اختیاری){% else %}Expiration (optional){% endif %}
</label>
<select
name="expires_in_days"
class="w-full bg-gray-700 border border-gray-600 rounded-lg px-4 py-2 text-white focus:ring-2 focus:ring-primary-500 focus:border-transparent"
>
<option value="">{% if lang == 'fa' %}بدون انقضا{% else %}Never expires{% endif %}</option>
<option value="7">{% if lang == 'fa' %}7 روز{% else %}7 days{% endif %}</option>
<option value="30">{% if lang == 'fa' %}30 روز{% else %}30 days{% endif %}</option>
<option value="90">{% if lang == 'fa' %}90 روز{% else %}90 days{% endif %}</option>
<option value="365">{% if lang == 'fa' %}1 سال{% else %}1 year{% endif %}</option>
</select>
</div>
</form>
<div class="p-6 border-t border-gray-700 flex justify-end gap-3">
<button
onclick="closeCreateModal()"
class="px-4 py-2 bg-gray-700 hover:bg-gray-600 rounded-lg text-white text-sm transition-colors"
>
{% if lang == 'fa' %}انصراف{% else %}Cancel{% endif %}
</button>
<button
onclick="submitCreateForm()"
class="px-4 py-2 bg-primary-600 hover:bg-primary-700 rounded-lg text-white text-sm transition-colors"
>
{% if lang == 'fa' %}ایجاد کلید{% else %}Create Key{% endif %}
</button>
</div>
</div>
</div>
<!-- New Key Modal (shows the actual key) -->
<div id="newKeyModal" class="fixed inset-0 bg-black/50 hidden items-center justify-center z-50">
<div class="bg-gray-800 rounded-xl border border-gray-700 w-full max-w-lg mx-4">
<div class="p-6 border-b border-gray-700">
<h3 class="text-lg font-semibold text-white flex items-center">
<svg class="w-6 h-6 text-green-400 {% if lang == 'fa' %}ml-2{% else %}mr-2{% endif %}" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
{% if lang == 'fa' %}کلید API ایجاد شد{% else %}API Key Created{% endif %}
</h3>
</div>
<div class="p-6 space-y-4">
<div class="bg-yellow-500/10 border border-yellow-500/30 rounded-lg p-4">
<p class="text-sm text-yellow-400">
{% if lang == 'fa' %}
این کلید فقط یکبار نمایش داده می‌شود. لطفا آن را در جای امنی ذخیره کنید.
{% else %}
This key will only be shown once. Please save it in a secure location.
{% endif %}
</p>
</div>
<div>
<label class="block text-sm font-medium text-gray-400 mb-2">API Key</label>
<div class="flex items-center gap-2">
<input
type="text"
id="newKeyValue"
readonly
class="flex-1 bg-gray-700 border border-gray-600 rounded-lg px-4 py-2 text-white font-mono text-sm"
>
<button
onclick="copyNewKey()"
class="px-4 py-2 bg-primary-600 hover:bg-primary-700 rounded-lg text-white text-sm transition-colors"
>
{% if lang == 'fa' %}کپی{% else %}Copy{% endif %}
</button>
</div>
</div>
</div>
<div class="p-6 border-t border-gray-700 flex justify-end">
<button
onclick="closeNewKeyModal()"
class="px-4 py-2 bg-primary-600 hover:bg-primary-700 rounded-lg text-white text-sm transition-colors"
>
{% if lang == 'fa' %}بستن{% else %}Done{% endif %}
</button>
</div>
</div>
</div>
<!-- Revoke Modal -->
<div id="revokeModal" class="fixed inset-0 bg-black/50 hidden items-center justify-center z-50">
<div class="bg-gray-800 rounded-xl border border-gray-700 w-full max-w-md mx-4">
<div class="p-6 border-b border-gray-700">
<h3 class="text-lg font-semibold text-white">
{% if lang == 'fa' %}لغو کلید API{% else %}Revoke API Key{% endif %}
</h3>
</div>
<div class="p-6">
<p class="text-gray-300">
{% if lang == 'fa' %}
آیا مطمئن هستید که می‌خواهید کلید <span id="revokeKeyName" class="font-mono text-white"></span> را لغو کنید؟
{% else %}
Are you sure you want to revoke the key <span id="revokeKeyName" class="font-mono text-white"></span>?
{% endif %}
</p>
<p class="mt-2 text-sm text-yellow-400">
{% if lang == 'fa' %}این عمل غیرقابل برگشت است و کلید دیگر کار نخواهد کرد.{% else %}This action cannot be undone and the key will stop working immediately.{% endif %}
</p>
</div>
<div class="p-6 border-t border-gray-700 flex justify-end gap-3">
<button
onclick="closeRevokeModal()"
class="px-4 py-2 bg-gray-700 hover:bg-gray-600 rounded-lg text-white text-sm transition-colors"
>
{% if lang == 'fa' %}انصراف{% else %}Cancel{% endif %}
</button>
<button
id="confirmRevokeBtn"
class="px-4 py-2 bg-red-600 hover:bg-red-700 rounded-lg text-white text-sm transition-colors"
>
{% if lang == 'fa' %}لغو کلید{% else %}Revoke Key{% endif %}
</button>
</div>
</div>
</div>
<!-- Delete Modal -->
<div id="deleteModal" class="fixed inset-0 bg-black/50 hidden items-center justify-center z-50">
<div class="bg-gray-800 rounded-xl border border-gray-700 w-full max-w-md mx-4">
<div class="p-6 border-b border-gray-700">
<h3 class="text-lg font-semibold text-white">
{% if lang == 'fa' %}حذف کلید API{% else %}Delete API Key{% endif %}
</h3>
</div>
<div class="p-6">
<p class="text-gray-300">
{% if lang == 'fa' %}
آیا مطمئن هستید که می‌خواهید کلید <span id="deleteKeyName" class="font-mono text-white"></span> را حذف کنید؟
{% else %}
Are you sure you want to delete the key <span id="deleteKeyName" class="font-mono text-white"></span>?
{% endif %}
</p>
<p class="mt-2 text-sm text-red-400">
{% if lang == 'fa' %}این عمل غیرقابل برگشت است و تمام سوابق استفاده از این کلید حذف خواهد شد.{% else %}This action cannot be undone and all usage records will be deleted.{% endif %}
</p>
</div>
<div class="p-6 border-t border-gray-700 flex justify-end gap-3">
<button
onclick="closeDeleteModal()"
class="px-4 py-2 bg-gray-700 hover:bg-gray-600 rounded-lg text-white text-sm transition-colors"
>
{% if lang == 'fa' %}انصراف{% else %}Cancel{% endif %}
</button>
<button
id="confirmDeleteBtn"
class="px-4 py-2 bg-red-600 hover:bg-red-700 rounded-lg text-white text-sm transition-colors"
>
{% if lang == 'fa' %}حذف کلید{% else %}Delete Key{% endif %}
</button>
</div>
</div>
</div>
{% endblock %}
{% block scripts %}
<script>
(function() {
// Prevent re-initialization on HTMX swaps
if (window.apiKeysPageInitialized) return;
window.apiKeysPageInitialized = true;
var currentRevokeKeyId = null;
var currentDeleteKeyId = null;
var lang = '{{ lang }}';
function copyToClipboard(text) {
navigator.clipboard.writeText(text).then(() => {
// Show toast notification
showToast(lang === 'fa' ? 'کپی شد!' : 'Copied!');
});
}
function showToast(message) {
const toast = document.createElement('div');
toast.className = 'fixed bottom-4 right-4 bg-gray-800 border border-gray-700 rounded-lg px-4 py-2 text-white text-sm z-50';
toast.textContent = message;
document.body.appendChild(toast);
setTimeout(() => toast.remove(), 2000);
}
// Create Modal
function openCreateModal() {
document.getElementById('createModal').classList.remove('hidden');
document.getElementById('createModal').classList.add('flex');
}
function closeCreateModal() {
document.getElementById('createModal').classList.add('hidden');
document.getElementById('createModal').classList.remove('flex');
}
function submitCreateForm() {
const form = document.getElementById('createKeyForm');
const formData = new FormData(form);
// Collect scopes
const scopes = [];
if (form.querySelector('[name="scope_read"]').checked) scopes.push('read');
if (form.querySelector('[name="scope_write"]').checked) scopes.push('write');
if (form.querySelector('[name="scope_admin"]').checked) scopes.push('admin');
if (scopes.length === 0) {
alert(lang === 'fa' ? 'لطفا حداقل یک سطح دسترسی انتخاب کنید' : 'Please select at least one scope');
return;
}
const data = {
project_id: formData.get('project_id'),
scope: scopes.join(' '),
description: formData.get('description') || null,
expires_in_days: formData.get('expires_in_days') ? parseInt(formData.get('expires_in_days')) : null
};
fetch('/api/dashboard/api-keys/create', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'same-origin',
body: JSON.stringify(data)
})
.then(response => {
if (!response.ok) {
return response.json().then(err => { throw new Error(err.error || 'Request failed'); });
}
return response.json();
})
.then(result => {
if (result.error) {
alert(result.error);
} else {
closeCreateModal();
document.getElementById('newKeyValue').value = result.key;
document.getElementById('newKeyModal').classList.remove('hidden');
document.getElementById('newKeyModal').classList.add('flex');
}
})
.catch(err => {
console.error('Create key error:', err);
alert(err.message || (lang === 'fa' ? 'خطا در ایجاد کلید' : 'Error creating key'));
});
}
// New Key Modal
function copyNewKey() {
const keyValue = document.getElementById('newKeyValue').value;
copyToClipboard(keyValue);
}
function closeNewKeyModal() {
document.getElementById('newKeyModal').classList.add('hidden');
document.getElementById('newKeyModal').classList.remove('flex');
location.reload();
}
// Revoke Modal
function openRevokeModal(keyId, keyName) {
currentRevokeKeyId = keyId;
document.getElementById('revokeKeyName').textContent = keyName;
document.getElementById('revokeModal').classList.remove('hidden');
document.getElementById('revokeModal').classList.add('flex');
}
function closeRevokeModal() {
document.getElementById('revokeModal').classList.add('hidden');
document.getElementById('revokeModal').classList.remove('flex');
currentRevokeKeyId = null;
}
document.getElementById('confirmRevokeBtn').addEventListener('click', function() {
if (!currentRevokeKeyId) return;
fetch(`/api/dashboard/api-keys/${currentRevokeKeyId}/revoke`, {
method: 'POST',
credentials: 'same-origin'
})
.then(response => {
if (!response.ok) {
return response.json().then(err => { throw new Error(err.error || 'Request failed'); });
}
return response.json();
})
.then(result => {
if (result.error) {
alert(result.error);
} else {
closeRevokeModal();
showToast(lang === 'fa' ? 'کلید لغو شد' : 'Key revoked');
location.reload();
}
})
.catch(err => {
console.error('Revoke error:', err);
alert(err.message || (lang === 'fa' ? 'خطا در لغو کلید' : 'Error revoking key'));
});
});
// Delete Modal
function openDeleteModal(keyId, keyName) {
currentDeleteKeyId = keyId;
document.getElementById('deleteKeyName').textContent = keyName;
document.getElementById('deleteModal').classList.remove('hidden');
document.getElementById('deleteModal').classList.add('flex');
}
function closeDeleteModal() {
document.getElementById('deleteModal').classList.add('hidden');
document.getElementById('deleteModal').classList.remove('flex');
currentDeleteKeyId = null;
}
document.getElementById('confirmDeleteBtn').addEventListener('click', function() {
if (!currentDeleteKeyId) return;
fetch(`/api/dashboard/api-keys/${currentDeleteKeyId}`, {
method: 'DELETE',
credentials: 'same-origin'
})
.then(response => {
if (!response.ok) {
return response.json().then(err => { throw new Error(err.error || 'Request failed'); });
}
return response.json();
})
.then(result => {
if (result.error) {
alert(result.error);
} else {
closeDeleteModal();
showToast(lang === 'fa' ? 'کلید حذف شد' : 'Key deleted');
location.reload();
}
})
.catch(err => {
console.error('Delete error:', err);
alert(err.message || (lang === 'fa' ? 'خطا در حذف کلید' : 'Error deleting key'));
});
});
// Close modals on outside click
['createModal', 'newKeyModal', 'revokeModal', 'deleteModal'].forEach(modalId => {
document.getElementById(modalId).addEventListener('click', function(e) {
if (e.target === this) {
this.classList.add('hidden');
this.classList.remove('flex');
}
});
});
// Expose functions to global scope for onclick handlers
window.copyToClipboard = copyToClipboard;
window.openCreateModal = openCreateModal;
window.closeCreateModal = closeCreateModal;
window.submitCreateForm = submitCreateForm;
window.copyNewKey = copyNewKey;
window.closeNewKeyModal = closeNewKeyModal;
window.openRevokeModal = openRevokeModal;
window.closeRevokeModal = closeRevokeModal;
window.openDeleteModal = openDeleteModal;
window.closeDeleteModal = closeDeleteModal;
})();
</script>
{% endblock %}

View File

@@ -0,0 +1,311 @@
{% extends "dashboard/base.html" %}
{% block title %}{{ t.audit_logs }}{% endblock %}
{% block page_title %}{{ t.audit_logs }}{% endblock %}
{% block content %}
<div class="space-y-6">
<!-- Filters -->
<div class="bg-gray-800 rounded-xl border border-gray-700 p-4">
<form method="GET" class="flex flex-wrap items-center gap-4">
{% if lang and lang != 'en' %}<input type="hidden" name="lang" value="{{ lang }}">{% endif %}
<!-- Project Filter -->
<div class="flex items-center gap-2">
<label class="text-sm text-gray-400">{% if lang == 'fa' %}پروژه:{% else %}Project:{% endif %}</label>
<select
name="project"
class="bg-gray-700 border border-gray-600 rounded-lg px-3 py-2 text-white text-sm focus:ring-2 focus:ring-primary-500 focus:border-transparent"
onchange="this.form.submit()"
>
<option value="">{% if lang == 'fa' %}همه پروژه‌ها{% else %}All Projects{% endif %}</option>
{% for project in available_projects %}
<option value="{{ project.full_id }}" {% if selected_project == project.full_id %}selected{% endif %}>
{{ project.alias or project.site_id }} ({{ project.plugin_type }})
</option>
{% endfor %}
</select>
</div>
<!-- Event Type Filter -->
<div class="flex items-center gap-2">
<label class="text-sm text-gray-400">{{ t.filter }}:</label>
<select
name="event_type"
class="bg-gray-700 border border-gray-600 rounded-lg px-3 py-2 text-white text-sm focus:ring-2 focus:ring-primary-500 focus:border-transparent"
onchange="this.form.submit()"
>
<option value="">{% if lang == 'fa' %}همه رویدادها{% else %}All Events{% endif %}</option>
<option value="tool_call" {% if selected_event_type == 'tool_call' %}selected{% endif %}>{% if lang == 'fa' %}فراخوانی ابزار{% else %}Tool Call{% endif %}</option>
<option value="authentication" {% if selected_event_type == 'authentication' %}selected{% endif %}>{% if lang == 'fa' %}احراز هویت{% else %}Authentication{% endif %}</option>
<option value="system" {% if selected_event_type == 'system' %}selected{% endif %}>{% if lang == 'fa' %}سیستم{% else %}System{% endif %}</option>
<option value="error" {% if selected_event_type == 'error' %}selected{% endif %}>{% if lang == 'fa' %}خطا{% else %}Error{% endif %}</option>
</select>
</div>
<!-- Level Filter -->
<div class="flex items-center gap-2">
<label class="text-sm text-gray-400">{% if lang == 'fa' %}سطح:{% else %}Level:{% endif %}</label>
<select
name="level"
class="bg-gray-700 border border-gray-600 rounded-lg px-3 py-2 text-white text-sm focus:ring-2 focus:ring-primary-500 focus:border-transparent"
onchange="this.form.submit()"
>
<option value="">{% if lang == 'fa' %}همه{% else %}All{% endif %}</option>
<option value="INFO" {% if selected_level == 'INFO' %}selected{% endif %}>INFO</option>
<option value="WARNING" {% if selected_level == 'WARNING' %}selected{% endif %}>WARNING</option>
<option value="ERROR" {% if selected_level == 'ERROR' %}selected{% endif %}>ERROR</option>
</select>
</div>
<!-- Date Filter -->
<div class="flex items-center gap-2">
<label class="text-sm text-gray-400">{% if lang == 'fa' %}تاریخ:{% else %}Date:{% endif %}</label>
<input
type="date"
name="date"
value="{{ selected_date }}"
class="bg-gray-700 border border-gray-600 rounded-lg px-3 py-2 text-white text-sm focus:ring-2 focus:ring-primary-500 focus:border-transparent"
onchange="this.form.submit()"
>
</div>
<!-- Search -->
<div class="flex-1 min-w-[200px]">
<input
type="text"
name="search"
value="{{ search_query }}"
placeholder="{% if lang == 'fa' %}جستجو...{% else %}Search...{% endif %}"
class="w-full bg-gray-700 border border-gray-600 rounded-lg px-4 py-2 text-white text-sm placeholder-gray-400 focus:ring-2 focus:ring-primary-500 focus:border-transparent"
>
</div>
<button type="submit" class="px-4 py-2 bg-primary-600 hover:bg-primary-700 rounded-lg text-white text-sm transition-colors">
{{ t.search }}
</button>
{% if search_query or selected_event_type or selected_level or selected_date or selected_project %}
<a href="/dashboard/audit-logs{% if lang and lang != 'en' %}?lang={{ lang }}{% endif %}" class="px-4 py-2 bg-gray-700 hover:bg-gray-600 rounded-lg text-white text-sm transition-colors">
{{ t['clear'] }}
</a>
{% endif %}
</form>
</div>
<!-- Stats Summary -->
<div class="grid grid-cols-1 md:grid-cols-4 gap-4">
<div class="bg-gray-800 rounded-xl border border-gray-700 p-4">
<div class="flex items-center justify-between">
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}کل رویدادها{% else %}Total Events{% endif %}</p>
<p class="text-2xl font-bold text-white">{{ stats.total }}</p>
</div>
<div class="w-10 h-10 bg-blue-500/20 rounded-lg flex items-center justify-center">
<svg class="w-5 h-5 text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"/>
</svg>
</div>
</div>
</div>
<div class="bg-gray-800 rounded-xl border border-gray-700 p-4">
<div class="flex items-center justify-between">
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}فراخوانی ابزار{% else %}Tool Calls{% endif %}</p>
<p class="text-2xl font-bold text-white">{{ stats.tool_calls }}</p>
</div>
<div class="w-10 h-10 bg-purple-500/20 rounded-lg flex items-center justify-center">
<svg class="w-5 h-5 text-purple-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35"/>
</svg>
</div>
</div>
</div>
<div class="bg-gray-800 rounded-xl border border-gray-700 p-4">
<div class="flex items-center justify-between">
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}احراز هویت{% else %}Auth Events{% endif %}</p>
<p class="text-2xl font-bold text-white">{{ stats.auth_events }}</p>
</div>
<div class="w-10 h-10 bg-green-500/20 rounded-lg flex items-center justify-center">
<svg class="w-5 h-5 text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"/>
</svg>
</div>
</div>
</div>
<div class="bg-gray-800 rounded-xl border border-gray-700 p-4">
<div class="flex items-center justify-between">
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}خطاها{% else %}Errors{% endif %}</p>
<p class="text-2xl font-bold text-white">{{ stats.errors }}</p>
</div>
<div class="w-10 h-10 bg-red-500/20 rounded-lg flex items-center justify-center">
<svg class="w-5 h-5 text-red-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/>
</svg>
</div>
</div>
</div>
</div>
<!-- Logs Table -->
<div class="bg-gray-800 rounded-xl border border-gray-700 overflow-hidden">
<div class="overflow-x-auto">
<table class="w-full">
<thead class="bg-gray-700/50">
<tr>
<th class="px-6 py-4 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-sm font-medium text-gray-300">
{% if lang == 'fa' %}زمان{% else %}Timestamp{% endif %}
</th>
<th class="px-6 py-4 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-sm font-medium text-gray-300">
{% if lang == 'fa' %}نوع{% else %}Type{% endif %}
</th>
<th class="px-6 py-4 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-sm font-medium text-gray-300">
{% if lang == 'fa' %}سطح{% else %}Level{% endif %}
</th>
<th class="px-6 py-4 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-sm font-medium text-gray-300">
{% if lang == 'fa' %}رویداد{% else %}Event{% endif %}
</th>
<th class="px-6 py-4 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-sm font-medium text-gray-300">
{% if lang == 'fa' %}جزئیات{% else %}Details{% endif %}
</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-700">
{% if logs %}
{% for log in logs %}
<tr class="hover:bg-gray-700/30 transition-colors">
<!-- Timestamp -->
<td class="px-6 py-4">
<span class="text-sm text-gray-300 font-mono">{{ log.timestamp[:19] }}</span>
</td>
<!-- Event Type -->
<td class="px-6 py-4">
{% set type_colors = {
'tool_call': 'bg-purple-500/20 text-purple-400',
'authentication': 'bg-green-500/20 text-green-400',
'system': 'bg-blue-500/20 text-blue-400',
'error': 'bg-red-500/20 text-red-400'
} %}
<span class="px-2 py-1 {{ type_colors.get(log.event_type, 'bg-gray-500/20 text-gray-400') }} text-xs rounded-lg font-medium">
{{ log.event_type }}
</span>
</td>
<!-- Level -->
<td class="px-6 py-4">
{% if log.level == 'ERROR' %}
<span class="px-2 py-1 bg-red-500/20 text-red-400 text-xs rounded-lg font-medium">ERROR</span>
{% elif log.level == 'WARNING' %}
<span class="px-2 py-1 bg-yellow-500/20 text-yellow-400 text-xs rounded-lg font-medium">WARNING</span>
{% else %}
<span class="px-2 py-1 bg-blue-500/20 text-blue-400 text-xs rounded-lg font-medium">INFO</span>
{% endif %}
</td>
<!-- Event/Message -->
<td class="px-6 py-4">
<span class="text-sm text-white">{{ log.event or log.message or log.tool_name or '-' }}</span>
{% if log.project_id %}
<span class="text-xs text-gray-500 block">{{ log.project_id }}</span>
{% endif %}
</td>
<!-- Details -->
<td class="px-6 py-4">
{% if log.details or log.metadata %}
<button
onclick="toggleDetails({{ loop.index }})"
class="text-sm text-primary-400 hover:text-primary-300"
>
{% if lang == 'fa' %}مشاهده{% else %}View{% endif %}
</button>
<div id="details-{{ loop.index }}" class="hidden mt-2 p-2 bg-gray-900 rounded text-xs text-gray-400 font-mono max-w-md overflow-auto">
<pre>{{ (log.details or log.metadata or {})|tojson(indent=2) }}</pre>
</div>
{% else %}
<span class="text-sm text-gray-500">-</span>
{% endif %}
</td>
</tr>
{% endfor %}
{% else %}
<tr>
<td colspan="5" class="px-6 py-12 text-center">
<svg class="w-12 h-12 mx-auto mb-4 text-gray-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"/>
</svg>
<p class="text-gray-400">
{% if lang == 'fa' %}لاگی یافت نشد{% else %}No logs found{% endif %}
</p>
</td>
</tr>
{% endif %}
</tbody>
</table>
</div>
<!-- Pagination -->
{% if total_pages > 1 %}
<div class="px-6 py-4 border-t border-gray-700 flex items-center justify-between">
<p class="text-sm text-gray-400">
{% if lang == 'fa' %}
نمایش {{ ((page_number - 1) * per_page) + 1 }} تا {{ [page_number * per_page, total_count]|min }} از {{ total_count }} لاگ
{% else %}
Showing {{ ((page_number - 1) * per_page) + 1 }} to {{ [page_number * per_page, total_count]|min }} of {{ total_count }} logs
{% endif %}
</p>
<div class="flex items-center gap-2">
{% if page_number > 1 %}
<a href="?page={{ page_number - 1 }}{% if selected_project %}&project={{ selected_project }}{% endif %}{% if selected_event_type %}&event_type={{ selected_event_type }}{% endif %}{% if selected_level %}&level={{ selected_level }}{% endif %}{% if selected_date %}&date={{ selected_date }}{% endif %}{% if search_query %}&search={{ search_query }}{% endif %}{% if lang and lang != 'en' %}&lang={{ lang }}{% endif %}"
class="px-3 py-1.5 bg-gray-700 hover:bg-gray-600 rounded-lg text-sm text-white transition-colors">
{% if lang == 'fa' %}قبلی{% else %}Previous{% endif %}
</a>
{% endif %}
{% for page_num in range(1, total_pages + 1) %}
{% if page_num == page_number %}
<span class="px-3 py-1.5 bg-primary-600 rounded-lg text-sm text-white">{{ page_num }}</span>
{% elif page_num == 1 or page_num == total_pages or (page_num >= page_number - 2 and page_num <= page_number + 2) %}
<a href="?page={{ page_num }}{% if selected_project %}&project={{ selected_project }}{% endif %}{% if selected_event_type %}&event_type={{ selected_event_type }}{% endif %}{% if selected_level %}&level={{ selected_level }}{% endif %}{% if selected_date %}&date={{ selected_date }}{% endif %}{% if search_query %}&search={{ search_query }}{% endif %}{% if lang and lang != 'en' %}&lang={{ lang }}{% endif %}"
class="px-3 py-1.5 bg-gray-700 hover:bg-gray-600 rounded-lg text-sm text-white transition-colors">
{{ page_num }}
</a>
{% elif page_num == page_number - 3 or page_num == page_number + 3 %}
<span class="text-gray-500">...</span>
{% endif %}
{% endfor %}
{% if page_number < total_pages %}
<a href="?page={{ page_number + 1 }}{% if selected_project %}&project={{ selected_project }}{% endif %}{% if selected_event_type %}&event_type={{ selected_event_type }}{% endif %}{% if selected_level %}&level={{ selected_level }}{% endif %}{% if selected_date %}&date={{ selected_date }}{% endif %}{% if search_query %}&search={{ search_query }}{% endif %}{% if lang and lang != 'en' %}&lang={{ lang }}{% endif %}"
class="px-3 py-1.5 bg-gray-700 hover:bg-gray-600 rounded-lg text-sm text-white transition-colors">
{% if lang == 'fa' %}بعدی{% else %}Next{% endif %}
</a>
{% endif %}
</div>
</div>
{% endif %}
</div>
</div>
{% endblock %}
{% block scripts %}
<script>
(function() {
if (window.auditLogsPageInitialized) return;
window.auditLogsPageInitialized = true;
function toggleDetails(index) {
var detailsDiv = document.getElementById('details-' + index);
if (detailsDiv) {
detailsDiv.classList.toggle('hidden');
}
}
window.toggleDetails = toggleDetails;
})();
</script>
{% endblock %}

View File

@@ -0,0 +1,227 @@
<!DOCTYPE html>
<html lang="{{ lang|default('en') }}" {% if lang == 'fa' %}dir="rtl"{% endif %}>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %}{{ t.dashboard }}{% endblock %} - MCP Hub</title>
<!-- Vazirmatn Font for Persian -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Vazirmatn:wght@100;200;300;400;500;600;700;800;900&display=swap" rel="stylesheet">
<!-- Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- HTMX for dynamic updates -->
<script src="https://unpkg.com/htmx.org@1.9.10"></script>
<!-- Alpine.js for simple interactions -->
<script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>
<!-- Custom Tailwind Config -->
<script>
tailwind.config = {
darkMode: 'class',
theme: {
extend: {
fontFamily: {
'vazirmatn': ['Vazirmatn', 'system-ui', 'sans-serif'],
},
colors: {
primary: {
50: '#f5f3ff',
100: '#ede9fe',
200: '#ddd6fe',
300: '#c4b5fd',
400: '#a78bfa',
500: '#8b5cf6',
600: '#7c3aed',
700: '#6d28d9',
800: '#5b21b6',
900: '#4c1d95',
}
}
}
}
}
</script>
<style>
[x-cloak] { display: none !important; }
/* Custom scrollbar */
::-webkit-scrollbar {
width: 8px;
height: 8px;
}
::-webkit-scrollbar-track {
background: #1f2937;
}
::-webkit-scrollbar-thumb {
background: #4b5563;
border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
background: #6b7280;
}
/* Sidebar transition */
.sidebar-transition {
transition: width 0.3s ease-in-out;
}
/* Card hover effect */
.card-hover {
transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.card-hover:hover {
transform: translateY(-2px);
box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
}
/* Status indicator pulse */
.status-pulse {
animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
/* RTL adjustments */
[dir="rtl"] .sidebar-icon {
margin-left: 0.75rem;
margin-right: 0;
}
[dir="ltr"] .sidebar-icon {
margin-right: 0.75rem;
margin-left: 0;
}
/* Vazirmatn font for Persian */
[dir="rtl"],
[dir="rtl"] * {
font-family: 'Vazirmatn', system-ui, sans-serif !important;
}
</style>
{% block extra_head %}{% endblock %}
</head>
<body class="bg-gray-900 text-gray-100 min-h-screen" x-data="{ sidebarOpen: true, darkMode: true }">
<div class="flex h-screen overflow-hidden">
<!-- Sidebar -->
<aside
class="sidebar-transition bg-gray-800 border-gray-700 flex flex-col"
:class="sidebarOpen ? 'w-64' : 'w-20'"
{% if lang == 'fa' %}style="border-left: 1px solid;"{% else %}style="border-right: 1px solid;"{% endif %}
>
<!-- Logo -->
<div class="flex items-center justify-between h-16 px-4 border-b border-gray-700">
<div class="flex items-center" x-show="sidebarOpen">
<div class="w-8 h-8 bg-primary-600 rounded-lg flex items-center justify-center">
<svg class="w-5 h-5 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"/>
</svg>
</div>
<span class="{% if lang == 'fa' %}mr-3{% else %}ml-3{% endif %} font-bold text-lg">MCP Hub</span>
</div>
<button
@click="sidebarOpen = !sidebarOpen"
class="p-2 rounded-lg hover:bg-gray-700 transition-colors"
>
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"/>
</svg>
</button>
</div>
<!-- Navigation -->
<nav class="flex-1 px-2 py-4 space-y-1 overflow-y-auto">
{% set nav_items = [
('dashboard', t.dashboard, 'M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6', '/dashboard'),
('projects', t.projects, 'M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z', '/dashboard/projects'),
('api_keys', t.api_keys, 'M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z', '/dashboard/api-keys'),
('oauth_clients', t.oauth_clients, 'M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z', '/dashboard/oauth-clients'),
('audit_logs', t.audit_logs, 'M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01', '/dashboard/audit-logs'),
('health', t.health, 'M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z', '/dashboard/health'),
('settings', t.settings, 'M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z M15 12a3 3 0 11-6 0 3 3 0 016 0z', '/dashboard/settings'),
] %}
{% for item_id, label, icon_path, url in nav_items %}
<a
href="{{ url }}{% if lang and lang != 'en' %}?lang={{ lang }}{% endif %}"
class="flex items-center px-3 py-2 rounded-lg transition-colors {% if current_page == item_id %}bg-primary-600 text-white{% else %}text-gray-300 hover:bg-gray-700 hover:text-white{% endif %}"
>
<svg class="w-5 h-5 sidebar-icon flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="{{ icon_path }}"/>
</svg>
<span x-show="sidebarOpen" class="truncate">{{ label }}</span>
</a>
{% endfor %}
</nav>
<!-- User Section -->
<div class="p-4 border-t border-gray-700">
<a
href="/dashboard/logout"
class="flex items-center px-3 py-2 text-gray-300 hover:bg-gray-700 hover:text-white rounded-lg transition-colors"
>
<svg class="w-5 h-5 sidebar-icon flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1"/>
</svg>
<span x-show="sidebarOpen">{{ t.logout }}</span>
</a>
</div>
</aside>
<!-- Main Content -->
<main class="flex-1 overflow-y-auto bg-gray-900">
<!-- Top Header -->
<header class="sticky top-0 z-10 bg-gray-800/95 backdrop-blur border-b border-gray-700">
<div class="flex items-center justify-between h-16 px-6">
<h1 class="text-xl font-semibold">{% block page_title %}{{ t.dashboard }}{% endblock %}</h1>
<div class="flex items-center space-x-4 {% if lang == 'fa' %}space-x-reverse{% endif %}">
<!-- Language Toggle -->
<a
href="?lang={% if lang == 'fa' %}en{% else %}fa{% endif %}"
class="px-3 py-1 text-sm bg-gray-700 hover:bg-gray-600 rounded-lg transition-colors"
>
{% if lang == 'fa' %}EN{% else %}FA{% endif %}
</a>
<!-- Refresh Button -->
<button
hx-get="{{ request.url.path }}{% if lang and lang != 'en' %}?lang={{ lang }}{% endif %}"
hx-target="body"
hx-swap="outerHTML"
class="p-2 text-gray-400 hover:text-white hover:bg-gray-700 rounded-lg transition-colors"
title="{{ t.refresh }}"
>
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/>
</svg>
</button>
<!-- User Info -->
{% if session %}
<div class="flex items-center text-sm text-gray-400">
<span class="w-2 h-2 bg-green-500 rounded-full {% if lang == 'fa' %}ml-2{% else %}mr-2{% endif %}"></span>
{{ session.user_type }}
</div>
{% endif %}
</div>
</div>
</header>
<!-- Page Content -->
<div class="p-6">
{% block content %}{% endblock %}
</div>
</main>
</div>
{% block scripts %}{% endblock %}
</body>
</html>

View File

@@ -0,0 +1,332 @@
{% extends "dashboard/base.html" %}
{% block title %}{{ t.health }}{% endblock %}
{% block page_title %}{{ t.health }}{% endblock %}
{% block content %}
<div class="space-y-6">
<!-- System Status Overview -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
<!-- Overall Status -->
<div class="bg-gray-800 rounded-xl border border-gray-700 p-4">
<div class="flex items-center justify-between">
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}وضعیت کلی{% else %}Overall Status{% endif %}</p>
{% if async_load %}
<p id="system-status-badge" class="text-2xl font-bold text-blue-400">
{% if lang == 'fa' %}در حال بررسی...{% else %}Checking...{% endif %}
</p>
{% elif system_status == 'healthy' %}
<p id="system-status-badge" class="text-2xl font-bold text-green-400">{{ t.healthy }}</p>
{% elif system_status == 'degraded' %}
<p id="system-status-badge" class="text-2xl font-bold text-yellow-400">{% if lang == 'fa' %}کاهش یافته{% else %}Degraded{% endif %}</p>
{% else %}
<p id="system-status-badge" class="text-2xl font-bold text-red-400">{{ t.error }}</p>
{% endif %}
</div>
<div id="system-status-icon" class="w-12 h-12 {% if async_load %}bg-blue-500/20{% elif system_status == 'healthy' %}bg-green-500/20{% elif system_status == 'degraded' %}bg-yellow-500/20{% else %}bg-red-500/20{% endif %} rounded-lg flex items-center justify-center">
{% if async_load %}
<svg class="w-6 h-6 text-blue-400 animate-spin" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
</svg>
{% elif system_status == 'healthy' %}
<svg class="w-6 h-6 text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
{% else %}
<svg class="w-6 h-6 {% if system_status == 'degraded' %}text-yellow-400{% else %}text-red-400{% endif %}" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/>
</svg>
{% endif %}
</div>
</div>
</div>
<!-- Uptime -->
<div class="bg-gray-800 rounded-xl border border-gray-700 p-4">
<div class="flex items-center justify-between">
<div>
<p class="text-sm text-gray-400">{{ t.system_uptime }}</p>
<p class="text-2xl font-bold text-white">{{ uptime.formatted }}</p>
</div>
<div class="w-12 h-12 bg-blue-500/20 rounded-lg flex items-center justify-center">
<svg class="w-6 h-6 text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
</div>
</div>
</div>
<!-- Total Requests -->
<div class="bg-gray-800 rounded-xl border border-gray-700 p-4">
<div class="flex items-center justify-between">
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}کل درخواست‌ها{% else %}Total Requests{% endif %}</p>
<p class="text-2xl font-bold text-white">{{ metrics.total_requests|default(0) }}</p>
<p class="text-xs text-gray-500">{{ metrics.requests_per_minute|default(0)|round(1) }} req/min</p>
</div>
<div class="w-12 h-12 bg-purple-500/20 rounded-lg flex items-center justify-center">
<svg class="w-6 h-6 text-purple-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"/>
</svg>
</div>
</div>
</div>
<!-- Error Rate -->
<div class="bg-gray-800 rounded-xl border border-gray-700 p-4">
<div class="flex items-center justify-between">
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}نرخ خطا{% else %}Error Rate{% endif %}</p>
<p class="text-2xl font-bold {% if (metrics.error_rate_percent|default(0)) > 10 %}text-red-400{% elif (metrics.error_rate_percent|default(0)) > 5 %}text-yellow-400{% else %}text-green-400{% endif %}">
{{ metrics.error_rate_percent|default(0)|round(2) }}%
</p>
<p class="text-xs text-gray-500">{{ metrics.failed_requests|default(0) }} {% if lang == 'fa' %}خطا{% else %}failed{% endif %}</p>
</div>
<div class="w-12 h-12 {% if (metrics.error_rate_percent|default(0)) > 10 %}bg-red-500/20{% elif (metrics.error_rate_percent|default(0)) > 5 %}bg-yellow-500/20{% else %}bg-green-500/20{% endif %} rounded-lg flex items-center justify-center">
<svg class="w-6 h-6 {% if (metrics.error_rate_percent|default(0)) > 10 %}text-red-400{% elif (metrics.error_rate_percent|default(0)) > 5 %}text-yellow-400{% else %}text-green-400{% endif %}" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"/>
</svg>
</div>
</div>
</div>
</div>
<!-- Alerts Section -->
{% if alerts and alerts|length > 0 %}
<div class="bg-red-900/30 border border-red-700 rounded-xl p-4">
<h3 class="text-lg font-semibold text-red-400 mb-3">
<svg class="w-5 h-5 inline-block mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/>
</svg>
{% if lang == 'fa' %}هشدارهای فعال{% else %}Active Alerts{% endif %} ({{ alerts|length }})
</h3>
<ul class="space-y-2">
{% for alert in alerts %}
<li class="text-sm text-red-300 font-mono">{{ alert }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
<!-- Response Time & Throughput -->
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
<!-- Response Time -->
<div class="bg-gray-800 rounded-xl border border-gray-700 p-6">
<h3 class="text-lg font-semibold text-white mb-4">
{% if lang == 'fa' %}زمان پاسخ{% else %}Response Time{% endif %}
</h3>
<div class="grid grid-cols-3 gap-4">
<div class="text-center">
<p class="text-3xl font-bold text-blue-400">{{ metrics.average_response_time_ms|default(0)|round(2) }}</p>
<p class="text-xs text-gray-400 mt-1">{% if lang == 'fa' %}میانگین (ms){% else %}Avg (ms){% endif %}</p>
</div>
<div class="text-center">
<p class="text-3xl font-bold text-green-400">{{ metrics.min_response_time_ms|default(0)|round(2) }}</p>
<p class="text-xs text-gray-400 mt-1">{% if lang == 'fa' %}حداقل (ms){% else %}Min (ms){% endif %}</p>
</div>
<div class="text-center">
<p class="text-3xl font-bold text-orange-400">{{ metrics.max_response_time_ms|default(0)|round(2) }}</p>
<p class="text-xs text-gray-400 mt-1">{% if lang == 'fa' %}حداکثر (ms){% else %}Max (ms){% endif %}</p>
</div>
</div>
</div>
<!-- Request Summary -->
<div class="bg-gray-800 rounded-xl border border-gray-700 p-6">
<h3 class="text-lg font-semibold text-white mb-4">
{% if lang == 'fa' %}خلاصه درخواست‌ها{% else %}Request Summary{% endif %}
</h3>
<div class="grid grid-cols-2 gap-4">
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}موفق{% else %}Successful{% endif %}</p>
<p class="text-2xl font-bold text-green-400">{{ metrics.successful_requests|default(0) }}</p>
</div>
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}ناموفق{% else %}Failed{% endif %}</p>
<p class="text-2xl font-bold text-red-400">{{ metrics.failed_requests|default(0) }}</p>
</div>
</div>
<div class="mt-4">
<div class="w-full bg-gray-700 rounded-full h-2">
{% set total = metrics.total_requests|default(0) %}
{% set successful = metrics.successful_requests|default(0) %}
{% set success_rate = ((successful / total) * 100) if total > 0 else 100 %}
<div class="bg-green-500 h-2 rounded-full" style="width: {{ success_rate }}%"></div>
</div>
<p class="text-xs text-gray-400 mt-1 text-right">{{ success_rate|round(1) }}% {% if lang == 'fa' %}نرخ موفقیت{% else %}success rate{% endif %}</p>
</div>
</div>
</div>
<!-- Alerts Container (populated by HTMX) -->
<div id="alerts-container"></div>
<!-- Projects Health -->
<div class="bg-gray-800 rounded-xl border border-gray-700 overflow-hidden">
<div class="px-6 py-4 border-b border-gray-700 flex items-center justify-between">
<h3 class="text-lg font-semibold text-white">
{% if lang == 'fa' %}سلامت پروژه‌ها{% else %}Project Health{% endif %}
</h3>
<span id="projects-summary" class="text-sm text-gray-400">
{% if async_load %}
{% if lang == 'fa' %}در حال بارگذاری...{% else %}Loading...{% endif %}
{% else %}
{{ projects_summary.healthy }}/{{ projects_summary.total }} {{ t.healthy }}
{% endif %}
</span>
</div>
<div class="overflow-x-auto">
<table class="w-full">
<thead class="bg-gray-700/50">
<tr>
<th class="px-6 py-4 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-sm font-medium text-gray-300">
{% if lang == 'fa' %}پروژه{% else %}Project{% endif %}
</th>
<th class="px-6 py-4 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-sm font-medium text-gray-300">
{% if lang == 'fa' %}وضعیت{% else %}Status{% endif %}
</th>
<th class="px-6 py-4 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-sm font-medium text-gray-300">
{% if lang == 'fa' %}زمان پاسخ{% else %}Response Time{% endif %}
</th>
<th class="px-6 py-4 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-sm font-medium text-gray-300">
{% if lang == 'fa' %}نرخ خطا{% else %}Error Rate{% endif %}
</th>
<th class="px-6 py-4 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-sm font-medium text-gray-300">
{% if lang == 'fa' %}آخرین بررسی{% else %}Last Check{% endif %}
</th>
</tr>
</thead>
{% if async_load %}
<!-- HTMX async loading - wraps tbody for proper swap -->
<tbody
id="projects-health-body"
class="divide-y divide-gray-700"
hx-get="/api/dashboard/health/projects{% if lang and lang != 'en' %}?lang={{ lang }}{% endif %}"
hx-trigger="load"
hx-swap="innerHTML"
>
<tr>
<td colspan="5" class="px-6 py-12 text-center">
<div class="flex flex-col items-center gap-2">
<svg class="w-8 h-8 text-blue-400 animate-spin" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
</svg>
<p class="text-gray-400">
{% if lang == 'fa' %}در حال بررسی سلامت پروژه‌ها...{% else %}Checking projects health...{% endif %}
</p>
</div>
</td>
</tr>
</tbody>
{% else %}
<tbody class="divide-y divide-gray-700">
{% if projects_health %}
{% for project_id, project in projects_health.items() %}
<tr class="hover:bg-gray-700/30 transition-colors">
<td class="px-6 py-4">
<span class="text-white font-medium">{{ project_id }}</span>
</td>
<td class="px-6 py-4">
{% if project.healthy or project.status == 'healthy' %}
<span class="px-2 py-1 bg-green-500/20 text-green-400 text-xs rounded-lg font-medium">{{ t.healthy }}</span>
{% elif project.status == 'warning' %}
<span class="px-2 py-1 bg-yellow-500/20 text-yellow-400 text-xs rounded-lg font-medium">{% if lang == 'fa' %}هشدار{% else %}Warning{% endif %}</span>
{% elif project.status == 'unhealthy' %}
<span class="px-2 py-1 bg-red-500/20 text-red-400 text-xs rounded-lg font-medium">{% if lang == 'fa' %}ناسالم{% else %}Unhealthy{% endif %}</span>
{% elif project.status == 'unknown' %}
<span class="px-2 py-1 bg-gray-500/20 text-gray-400 text-xs rounded-lg font-medium">{% if lang == 'fa' %}نامشخص{% else %}Unknown{% endif %}</span>
{% else %}
<span class="px-2 py-1 bg-gray-500/20 text-gray-400 text-xs rounded-lg font-medium">{% if lang == 'fa' %}نامشخص{% else %}Unknown{% endif %}</span>
{% endif %}
</td>
<td class="px-6 py-4">
<span class="text-gray-300">{{ project.response_time_ms|round(2) }} ms</span>
</td>
<td class="px-6 py-4">
<span class="{% if project.error_rate_percent > 10 %}text-red-400{% elif project.error_rate_percent > 5 %}text-yellow-400{% else %}text-green-400{% endif %}">
{{ project.error_rate_percent|round(2) }}%
</span>
</td>
<td class="px-6 py-4">
<span class="text-sm text-gray-400">{{ project.last_check[:19] if project.last_check else '-' }}</span>
</td>
</tr>
{% endfor %}
{% else %}
<tr>
<td colspan="5" class="px-6 py-12 text-center">
<p class="text-gray-400">
{% if lang == 'fa' %}هیچ پروژه‌ای برای بررسی یافت نشد{% else %}No projects found for health check{% endif %}
</p>
</td>
</tr>
{% endif %}
</tbody>
{% endif %}
</table>
</div>
</div>
<!-- System Information -->
<div class="bg-gray-800 rounded-xl border border-gray-700 p-6">
<h3 class="text-lg font-semibold text-white mb-4">
{% if lang == 'fa' %}اطلاعات سیستم{% else %}System Information{% endif %}
</h3>
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}زمان شروع{% else %}Start Time{% endif %}</p>
<p class="text-white font-mono text-sm">{{ uptime.start_time[:19] if uptime.start_time else '-' }}</p>
</div>
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}آپتایم (روز){% else %}Uptime (Days){% endif %}</p>
<p class="text-white font-mono text-sm">{{ uptime.days|default(0)|round(2) }}</p>
</div>
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}آپتایم (ساعت){% else %}Uptime (Hours){% endif %}</p>
<p class="text-white font-mono text-sm">{{ uptime.hours|default(0)|round(2) }}</p>
</div>
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}زمان فعلی{% else %}Current Time{% endif %}</p>
<p class="text-white font-mono text-sm">{{ uptime.current_time[:19] if uptime.current_time else '-' }}</p>
</div>
</div>
</div>
<!-- Refresh Buttons -->
<div class="flex justify-between items-center">
{% if is_cached %}
<p class="text-sm text-gray-400">
<svg class="w-4 h-4 inline-block {% if lang == 'fa' %}ml-1{% else %}mr-1{% endif %}" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
{% if lang == 'fa' %}نمایش داده‌های ذخیره شده{% else %}Showing cached data{% endif %}
</p>
{% else %}
<p class="text-sm text-green-400">
<svg class="w-4 h-4 inline-block {% if lang == 'fa' %}ml-1{% else %}mr-1{% endif %}" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
{% if lang == 'fa' %}بررسی زنده انجام شد{% else %}Live check completed{% endif %}
</p>
{% endif %}
<div class="flex gap-2">
<a href="/dashboard/health{% if lang and lang != 'en' %}?lang={{ lang }}{% endif %}"
class="px-4 py-2 bg-gray-700 hover:bg-gray-600 rounded-lg text-white text-sm transition-colors">
{{ t.refresh }}
</a>
<a href="/dashboard/health?refresh=true{% if lang and lang != 'en' %}&lang={{ lang }}{% endif %}"
class="px-4 py-2 bg-primary-600 hover:bg-primary-700 rounded-lg text-white text-sm transition-colors flex items-center">
<svg class="w-4 h-4 {% if lang == 'fa' %}ml-2{% else %}mr-2{% endif %}" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/>
</svg>
{% if lang == 'fa' %}بررسی زنده{% else %}Live Check{% endif %}
</a>
</div>
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,116 @@
<!-- Projects Table Rows -->
{% if projects_health %}
{% for project_id, project in projects_health.items() %}
<tr class="hover:bg-gray-700/30 transition-colors">
<td class="px-6 py-4">
<span class="text-white font-medium">{{ project_id }}</span>
</td>
<td class="px-6 py-4">
{% if project.healthy or project.status == 'healthy' %}
<span class="px-2 py-1 bg-green-500/20 text-green-400 text-xs rounded-lg font-medium">{{ t.healthy }}</span>
{% elif project.status == 'warning' %}
<span class="px-2 py-1 bg-yellow-500/20 text-yellow-400 text-xs rounded-lg font-medium">{% if lang == 'fa' %}هشدار{% else %}Warning{% endif %}</span>
{% elif project.status == 'unhealthy' %}
<span class="px-2 py-1 bg-red-500/20 text-red-400 text-xs rounded-lg font-medium">{% if lang == 'fa' %}ناسالم{% else %}Unhealthy{% endif %}</span>
{% else %}
<span class="px-2 py-1 bg-gray-500/20 text-gray-400 text-xs rounded-lg font-medium">{% if lang == 'fa' %}نامشخص{% else %}Unknown{% endif %}</span>
{% endif %}
</td>
<td class="px-6 py-4">
<span class="text-gray-300">{{ project.response_time_ms|round(2) }} ms</span>
</td>
<td class="px-6 py-4">
<span class="{% if project.error_rate_percent > 10 %}text-red-400{% elif project.error_rate_percent > 5 %}text-yellow-400{% else %}text-green-400{% endif %}">
{{ project.error_rate_percent|round(2) }}%
</span>
</td>
<td class="px-6 py-4">
<span class="text-sm text-gray-400">{{ project.last_check[:19] if project.last_check else '-' }}</span>
</td>
</tr>
{% endfor %}
{% else %}
<tr>
<td colspan="5" class="px-6 py-12 text-center">
<p class="text-gray-400">
{% if lang == 'fa' %}هیچ پروژه‌ای برای بررسی یافت نشد{% else %}No projects found for health check{% endif %}
</p>
</td>
</tr>
{% endif %}
<!-- JavaScript to update status elements (more reliable than OOB swaps) -->
<script>
(function() {
// Data from server
var systemStatus = '{{ system_status }}';
var projectsHealthy = {{ projects_summary.healthy }};
var projectsTotal = {{ projects_summary.total }};
var healthyText = '{{ t.healthy }}';
var errorText = '{{ t.error }}';
var lang = '{{ lang }}';
// Update status badge
var badge = document.getElementById('system-status-badge');
if (badge) {
badge.className = 'text-2xl font-bold ';
if (systemStatus === 'healthy') {
badge.className += 'text-green-400';
badge.textContent = healthyText;
} else if (systemStatus === 'degraded') {
badge.className += 'text-yellow-400';
badge.textContent = lang === 'fa' ? 'کاهش یافته' : 'Degraded';
} else {
badge.className += 'text-red-400';
badge.textContent = errorText;
}
}
// Update status icon
var icon = document.getElementById('system-status-icon');
if (icon) {
icon.className = 'w-12 h-12 rounded-lg flex items-center justify-center ';
var iconColor, iconBg;
if (systemStatus === 'healthy') {
iconBg = 'bg-green-500/20';
iconColor = 'text-green-400';
icon.innerHTML = '<svg class="w-6 h-6 ' + iconColor + '" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>';
} else if (systemStatus === 'degraded') {
iconBg = 'bg-yellow-500/20';
iconColor = 'text-yellow-400';
icon.innerHTML = '<svg class="w-6 h-6 ' + iconColor + '" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/></svg>';
} else {
iconBg = 'bg-red-500/20';
iconColor = 'text-red-400';
icon.innerHTML = '<svg class="w-6 h-6 ' + iconColor + '" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/></svg>';
}
icon.className += iconBg;
}
// Update projects summary
var summary = document.getElementById('projects-summary');
if (summary) {
summary.textContent = projectsHealthy + '/' + projectsTotal + ' ' + healthyText;
}
// Update alerts container
var alertsContainer = document.getElementById('alerts-container');
if (alertsContainer) {
{% if alerts and alerts|length > 0 %}
alertsContainer.className = 'bg-red-900/30 border border-red-700 rounded-xl p-4 mb-6';
alertsContainer.innerHTML = '<h3 class="text-lg font-semibold text-red-400 mb-3">' +
'<svg class="w-5 h-5 inline-block mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">' +
'<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/>' +
'</svg>' +
(lang === 'fa' ? 'هشدارهای فعال' : 'Active Alerts') + ' ({{ alerts|length }})' +
'</h3>' +
'<ul class="space-y-2">' +
{% for alert in alerts %}'<li class="text-sm text-red-300 font-mono">{{ alert }}</li>' +{% endfor %}
'</ul>';
{% else %}
alertsContainer.className = '';
alertsContainer.innerHTML = '';
{% endif %}
}
})();
</script>

View File

@@ -0,0 +1,292 @@
{% extends "dashboard/base.html" %}
{% block title %}{{ t.dashboard }}{% endblock %}
{% block page_title %}{{ t.overview }}{% endblock %}
{% block content %}
<div class="space-y-6">
<!-- Stats Cards -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
<!-- Projects Card -->
<div class="card-hover bg-gray-800 rounded-xl p-6 border border-gray-700">
<div class="flex items-center justify-between">
<div>
<p class="text-sm font-medium text-gray-400">{{ t.total_projects }}</p>
<p class="text-3xl font-bold text-white mt-1">{{ stats.projects_count }}</p>
</div>
<div class="w-12 h-12 bg-blue-500/20 rounded-lg flex items-center justify-center">
<svg class="w-6 h-6 text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"/>
</svg>
</div>
</div>
<a href="/dashboard/projects{% if lang and lang != 'en' %}?lang={{ lang }}{% endif %}" class="mt-4 text-sm text-blue-400 hover:text-blue-300 flex items-center">
{{ t.view_all }}
<svg class="w-4 h-4 {% if lang == 'fa' %}mr-1 rotate-180{% else %}ml-1{% endif %}" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/>
</svg>
</a>
</div>
<!-- API Keys Card -->
<div class="card-hover bg-gray-800 rounded-xl p-6 border border-gray-700">
<div class="flex items-center justify-between">
<div>
<p class="text-sm font-medium text-gray-400">{{ t.active_api_keys }}</p>
<p class="text-3xl font-bold text-white mt-1">{{ stats.api_keys_count }}</p>
</div>
<div class="w-12 h-12 bg-green-500/20 rounded-lg flex items-center justify-center">
<svg class="w-6 h-6 text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z"/>
</svg>
</div>
</div>
<a href="/dashboard/api-keys{% if lang and lang != 'en' %}?lang={{ lang }}{% endif %}" class="mt-4 text-sm text-green-400 hover:text-green-300 flex items-center">
{{ t.view_all }}
<svg class="w-4 h-4 {% if lang == 'fa' %}mr-1 rotate-180{% else %}ml-1{% endif %}" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/>
</svg>
</a>
</div>
<!-- Tools Card -->
<div class="card-hover bg-gray-800 rounded-xl p-6 border border-gray-700">
<div class="flex items-center justify-between">
<div>
<p class="text-sm font-medium text-gray-400">{{ t.total_tools }}</p>
<p class="text-3xl font-bold text-white mt-1">{{ stats.tools_count }}</p>
</div>
<div class="w-12 h-12 bg-purple-500/20 rounded-lg flex items-center justify-center">
<svg class="w-6 h-6 text-purple-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"/>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/>
</svg>
</div>
</div>
<p class="mt-4 text-sm text-gray-400">
{% if lang == 'fa' %}ابزارهای موجود{% else %}Available tools{% endif %}
</p>
</div>
<!-- Uptime Card -->
<div class="card-hover bg-gray-800 rounded-xl p-6 border border-gray-700">
<div class="flex items-center justify-between">
<div>
<p class="text-sm font-medium text-gray-400">{{ t.system_uptime }}</p>
<p class="text-3xl font-bold text-white mt-1">{{ "%.1f"|format(stats.uptime_days) }}d</p>
</div>
<div class="w-12 h-12 bg-orange-500/20 rounded-lg flex items-center justify-center">
<svg class="w-6 h-6 text-orange-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
</div>
</div>
<a href="/dashboard/health{% if lang and lang != 'en' %}?lang={{ lang }}{% endif %}" class="mt-4 text-sm text-orange-400 hover:text-orange-300 flex items-center">
{{ t.view_all }}
<svg class="w-4 h-4 {% if lang == 'fa' %}mr-1 rotate-180{% else %}ml-1{% endif %}" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/>
</svg>
</a>
</div>
</div>
<!-- Main Content Grid -->
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
<!-- Recent Activity -->
<div class="lg:col-span-2 bg-gray-800 rounded-xl border border-gray-700">
<div class="p-6 border-b border-gray-700">
<h2 class="text-lg font-semibold text-white">{{ t.recent_activity }}</h2>
</div>
<div class="divide-y divide-gray-700">
{% if recent_activity %}
{% for activity in recent_activity %}
<div class="p-4 hover:bg-gray-700/50 transition-colors">
<div class="flex items-center justify-between">
<div class="flex items-center">
<!-- Icon based on type -->
{% if activity.type == 'tool_call' %}
<div class="w-8 h-8 bg-blue-500/20 rounded-lg flex items-center justify-center {% if lang == 'fa' %}ml-3{% else %}mr-3{% endif %}">
<svg class="w-4 h-4 text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0"/>
</svg>
</div>
{% elif activity.type == 'auth' %}
<div class="w-8 h-8 bg-green-500/20 rounded-lg flex items-center justify-center {% if lang == 'fa' %}ml-3{% else %}mr-3{% endif %}">
<svg class="w-4 h-4 text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"/>
</svg>
</div>
{% elif activity.level == 'ERROR' %}
<div class="w-8 h-8 bg-red-500/20 rounded-lg flex items-center justify-center {% if lang == 'fa' %}ml-3{% else %}mr-3{% endif %}">
<svg class="w-4 h-4 text-red-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/>
</svg>
</div>
{% else %}
<div class="w-8 h-8 bg-gray-500/20 rounded-lg flex items-center justify-center {% if lang == 'fa' %}ml-3{% else %}mr-3{% endif %}">
<svg class="w-4 h-4 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
</div>
{% endif %}
<div>
<p class="text-sm font-medium text-white">{{ activity.message }}</p>
<p class="text-xs text-gray-400">{{ activity.project }}</p>
</div>
</div>
<span class="text-xs text-gray-500">{{ activity.timestamp[:19] }}</span>
</div>
</div>
{% endfor %}
{% else %}
<div class="p-8 text-center text-gray-400">
<svg class="w-12 h-12 mx-auto mb-4 opacity-50" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"/>
</svg>
<p>{{ t.no_activity }}</p>
</div>
{% endif %}
</div>
{% if recent_activity %}
<div class="p-4 border-t border-gray-700">
<a href="/dashboard/audit-logs{% if lang and lang != 'en' %}?lang={{ lang }}{% endif %}" class="text-sm text-primary-400 hover:text-primary-300">
{{ t.view_all }} →
</a>
</div>
{% endif %}
</div>
<!-- Right Column -->
<div class="space-y-6">
<!-- Projects by Type -->
<div class="bg-gray-800 rounded-xl border border-gray-700">
<div class="p-6 border-b border-gray-700">
<h2 class="text-lg font-semibold text-white">{{ t.projects_by_type }}</h2>
</div>
<div class="p-6 space-y-4">
{% set plugin_colors = {
'wordpress': 'bg-blue-500',
'woocommerce': 'bg-purple-500',
'wordpress_advanced': 'bg-indigo-500',
'gitea': 'bg-green-500',
'n8n': 'bg-orange-500',
'supabase': 'bg-emerald-500',
'openpanel': 'bg-cyan-500',
'appwrite': 'bg-pink-500',
'directus': 'bg-violet-500',
} %}
{% set plugin_icons = {
'wordpress': 'W',
'woocommerce': 'WC',
'wordpress_advanced': 'WA',
'gitea': 'G',
'n8n': 'n8n',
'supabase': 'SB',
'openpanel': 'OP',
'appwrite': 'AW',
'directus': 'DI',
} %}
{% if projects_by_type %}
{% for plugin_type, count in projects_by_type.items() %}
<div class="flex items-center justify-between">
<div class="flex items-center">
<div class="w-8 h-8 {{ plugin_colors.get(plugin_type, 'bg-gray-500') }} rounded-lg flex items-center justify-center {% if lang == 'fa' %}ml-3{% else %}mr-3{% endif %}">
<span class="text-xs font-bold text-white">{{ plugin_icons.get(plugin_type, plugin_type[:2]|upper) }}</span>
</div>
<span class="text-sm text-gray-300">{{ plugin_type|plugin_name }}</span>
</div>
<span class="text-sm font-medium text-white">{{ count }}</span>
</div>
{% endfor %}
{% else %}
<p class="text-center text-gray-400 text-sm">
{% if lang == 'fa' %}پروژه‌ای یافت نشد{% else %}No projects found{% endif %}
</p>
{% endif %}
</div>
</div>
<!-- Health Status -->
<div class="bg-gray-800 rounded-xl border border-gray-700">
<div class="p-6 border-b border-gray-700">
<h2 class="text-lg font-semibold text-white">{{ t.health_status }}</h2>
</div>
<div class="p-6 space-y-4">
{% for component, status in health_summary.components.items() %}
<div class="flex items-center justify-between">
<span class="text-sm text-gray-300 capitalize">{{ component }}</span>
<div class="flex items-center">
{% if status == 'healthy' %}
<span class="w-2 h-2 bg-green-500 rounded-full status-pulse {% if lang == 'fa' %}ml-2{% else %}mr-2{% endif %}"></span>
<span class="text-sm text-green-400">{{ t.healthy }}</span>
{% elif status == 'warning' %}
<span class="w-2 h-2 bg-yellow-500 rounded-full status-pulse {% if lang == 'fa' %}ml-2{% else %}mr-2{% endif %}"></span>
<span class="text-sm text-yellow-400">{{ t.warning }}</span>
{% else %}
<span class="w-2 h-2 bg-red-500 rounded-full status-pulse {% if lang == 'fa' %}ml-2{% else %}mr-2{% endif %}"></span>
<span class="text-sm text-red-400">{{ t.error }}</span>
{% endif %}
</div>
</div>
{% endfor %}
<div class="pt-4 border-t border-gray-700">
<p class="text-xs text-gray-500">
{% if lang == 'fa' %}آخرین بررسی:{% else %}Last check:{% endif %}
{{ health_summary.last_check[:19] }}
</p>
</div>
</div>
<div class="p-4 border-t border-gray-700">
<a href="/dashboard/health{% if lang and lang != 'en' %}?lang={{ lang }}{% endif %}" class="text-sm text-primary-400 hover:text-primary-300">
{{ t.view_all }} →
</a>
</div>
</div>
<!-- Support / Donate -->
<div class="bg-gradient-to-br from-primary-900/40 to-gray-800 rounded-xl border border-primary-700/30">
<div class="p-6 text-center">
<div class="w-10 h-10 bg-primary-500/20 rounded-full flex items-center justify-center mx-auto mb-3">
<svg class="w-5 h-5 text-primary-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z"/>
</svg>
</div>
<h3 class="text-sm font-semibold text-white mb-1">
{% if lang == 'fa' %}حمایت از پروژه{% else %}Support MCP Hub{% endif %}
</h3>
<p class="text-xs text-gray-400 mb-4">
{% if lang == 'fa' %}با حمایت مالی به توسعه این پروژه کمک کنید{% else %}Help us keep this project alive and growing{% endif %}
</p>
<a
href="https://nowpayments.io/donation/airano"
target="_blank"
rel="noopener noreferrer"
class="inline-flex items-center px-4 py-2 text-sm font-medium text-white bg-primary-600 hover:bg-primary-500 rounded-lg transition-colors"
>
<svg class="w-4 h-4 {% if lang == 'fa' %}ml-2{% else %}mr-2{% endif %}" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
{% if lang == 'fa' %}حمایت با رمزارز{% else %}Donate with Crypto{% endif %}
</a>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block scripts %}
<script>
// Auto-refresh dashboard every 30 seconds
htmx.config.defaultSwapStyle = 'outerHTML';
// Refresh stats periodically
setInterval(function() {
htmx.ajax('GET', '/api/dashboard/stats', {target: '#stats-container', swap: 'none'});
}, 30000);
</script>
{% endblock %}

View File

@@ -0,0 +1,138 @@
<!DOCTYPE html>
<html lang="{{ lang|default('en') }}" {% if lang == 'fa' %}dir="rtl"{% endif %}>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ t.login_title }} - MCP Hub</title>
<!-- Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
<style>
.login-gradient {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.card-shadow {
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}
.input-focus:focus {
box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.3);
}
.btn-primary {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
transition: all 0.3s ease;
}
.btn-primary:hover {
transform: translateY(-2px);
box-shadow: 0 10px 20px rgba(102, 126, 234, 0.4);
}
.animate-float {
animation: float 6s ease-in-out infinite;
}
@keyframes float {
0%, 100% { transform: translateY(0px); }
50% { transform: translateY(-20px); }
}
</style>
</head>
<body class="bg-gray-900 min-h-screen flex items-center justify-center p-4">
<!-- Background decoration -->
<div class="absolute inset-0 overflow-hidden pointer-events-none">
<div class="absolute -top-40 -right-40 w-80 h-80 bg-purple-500/20 rounded-full blur-3xl animate-float"></div>
<div class="absolute -bottom-40 -left-40 w-80 h-80 bg-blue-500/20 rounded-full blur-3xl animate-float" style="animation-delay: -3s;"></div>
</div>
<!-- Login Card -->
<div class="relative w-full max-w-md">
<div class="card-shadow bg-gray-800 rounded-2xl p-8">
<!-- Logo -->
<div class="text-center mb-8">
<div class="mx-auto w-16 h-16 login-gradient rounded-2xl flex items-center justify-center mb-4">
<svg class="w-10 h-10 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"/>
</svg>
</div>
<h1 class="text-2xl font-bold text-white">MCP Hub</h1>
<p class="text-gray-400 mt-2" {% if lang == 'fa' %}dir="rtl"{% endif %}>{{ t.login_subtitle }}</p>
</div>
<!-- Error Message -->
{% if error %}
<div class="mb-6 p-4 bg-red-500/20 border border-red-500/50 rounded-lg" {% if lang == 'fa' %}dir="rtl"{% endif %}>
<div class="flex items-center">
<svg class="w-5 h-5 text-red-400 {% if lang == 'fa' %}ml-2{% else %}mr-2{% endif %}" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
<span class="text-red-400 text-sm">
{% if error == 'rate_limit' %}
{{ t.rate_limit_error }}
{% else %}
{{ t.login_error }}
{% endif %}
</span>
</div>
</div>
{% endif %}
<!-- Login Form -->
<form method="POST" action="/dashboard/login" class="space-y-6">
<input type="hidden" name="next" value="{{ next_url }}">
<div {% if lang == 'fa' %}dir="rtl"{% endif %}>
<label for="api_key" class="block text-sm font-medium text-gray-300 mb-2">
{{ t.api_key_label }}
</label>
<input
type="password"
id="api_key"
name="api_key"
required
autocomplete="off"
placeholder="{{ t.api_key_placeholder }}"
class="input-focus w-full px-4 py-3 bg-gray-700 border border-gray-600 rounded-lg text-white placeholder-gray-400 focus:outline-none focus:border-purple-500 transition-colors"
{% if lang == 'fa' %}dir="ltr" style="text-align: right;"{% endif %}
>
</div>
<button
type="submit"
class="btn-primary w-full py-3 px-4 text-white font-semibold rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-offset-2 focus:ring-offset-gray-800"
>
{{ t.login_button }}
</button>
</form>
<!-- Security Note -->
<div class="mt-6 p-4 bg-blue-500/10 border border-blue-500/30 rounded-lg" {% if lang == 'fa' %}dir="rtl"{% endif %}>
<div class="flex items-start">
<svg class="w-5 h-5 text-blue-400 {% if lang == 'fa' %}ml-2{% else %}mr-2{% endif %} mt-0.5 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
<p class="text-sm text-blue-300">
{% if lang == 'fa' %}
برای دسترسی به داشبورد به Master API Key یا یک API Key با scope=admin نیاز دارید.
{% else %}
You need a Master API Key or an API Key with scope=admin to access the dashboard.
{% endif %}
</p>
</div>
</div>
<!-- Language Toggle -->
<div class="mt-6 text-center">
<a
href="?lang={% if lang == 'fa' %}en{% else %}fa{% endif %}{% if next_url %}&next={{ next_url }}{% endif %}"
class="text-sm text-gray-400 hover:text-white transition-colors"
>
{% if lang == 'fa' %}English{% else %}فارسی{% endif %}
</a>
</div>
</div>
<!-- Footer -->
<p class="text-center text-gray-500 text-sm mt-6">
MCP Hub v3.0.0
</p>
</div>
</body>
</html>

View File

@@ -0,0 +1,481 @@
{% extends "dashboard/base.html" %}
{% block title %}{{ t.oauth_clients }}{% endblock %}
{% block page_title %}{{ t.oauth_clients }}{% endblock %}
{% block content %}
<div class="space-y-6">
<!-- Header with Create Button -->
<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4">
<div>
<p class="text-gray-400">
{% if lang == 'fa' %}
مدیریت کلاینت‌های OAuth برای دسترسی امن به API
{% else %}
Manage OAuth clients for secure API access
{% endif %}
</p>
</div>
<button
onclick="openCreateModal()"
class="px-4 py-2 bg-primary-600 hover:bg-primary-700 rounded-lg text-white text-sm transition-colors inline-flex items-center gap-2"
>
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
</svg>
{% if lang == 'fa' %}ایجاد کلاینت{% else %}Create Client{% endif %}
</button>
</div>
<!-- Stats -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div class="bg-gray-800 rounded-xl border border-gray-700 p-4">
<div class="flex items-center justify-between">
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}کل کلاینت‌ها{% else %}Total Clients{% endif %}</p>
<p class="text-2xl font-bold text-white">{{ total_count }}</p>
</div>
<div class="w-10 h-10 bg-blue-500/20 rounded-lg flex items-center justify-center">
<svg class="w-5 h-5 text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z"/>
</svg>
</div>
</div>
</div>
<div class="bg-gray-800 rounded-xl border border-gray-700 p-4">
<div class="flex items-center justify-between">
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}کلاینت‌های فعال{% else %}Active Clients{% endif %}</p>
<p class="text-2xl font-bold text-green-400">{{ total_count }}</p>
</div>
<div class="w-10 h-10 bg-green-500/20 rounded-lg flex items-center justify-center">
<svg class="w-5 h-5 text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
</div>
</div>
</div>
<div class="bg-gray-800 rounded-xl border border-gray-700 p-4">
<div class="flex items-center justify-between">
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}پروتکل{% else %}Protocol{% endif %}</p>
<p class="text-2xl font-bold text-white">OAuth 2.1</p>
</div>
<div class="w-10 h-10 bg-purple-500/20 rounded-lg flex items-center justify-center">
<svg class="w-5 h-5 text-purple-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"/>
</svg>
</div>
</div>
</div>
</div>
<!-- Clients Table -->
<div class="bg-gray-800 rounded-xl border border-gray-700 overflow-hidden">
<div class="overflow-x-auto">
<table class="w-full">
<thead class="bg-gray-700/50">
<tr>
<th class="px-6 py-4 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-sm font-medium text-gray-300">
{% if lang == 'fa' %}نام کلاینت{% else %}Client Name{% endif %}
</th>
<th class="px-6 py-4 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-sm font-medium text-gray-300">
{% if lang == 'fa' %}شناسه کلاینت{% else %}Client ID{% endif %}
</th>
<th class="px-6 py-4 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-sm font-medium text-gray-300">
{% if lang == 'fa' %}دامنه‌ها{% else %}Scopes{% endif %}
</th>
<th class="px-6 py-4 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-sm font-medium text-gray-300">
{% if lang == 'fa' %}تاریخ ایجاد{% else %}Created{% endif %}
</th>
<th class="px-6 py-4 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-sm font-medium text-gray-300">
{% if lang == 'fa' %}عملیات{% else %}Actions{% endif %}
</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-700">
{% if clients %}
{% for client in clients %}
<tr class="hover:bg-gray-700/30 transition-colors">
<td class="px-6 py-4">
<span class="text-white font-medium">{{ client.client_name }}</span>
</td>
<td class="px-6 py-4">
<code class="text-sm text-gray-400 bg-gray-900 px-2 py-1 rounded">{{ client.client_id[:30] }}...</code>
</td>
<td class="px-6 py-4">
<div class="flex flex-wrap gap-1">
{% for scope in client.allowed_scopes %}
<span class="px-2 py-0.5 bg-blue-500/20 text-blue-400 text-xs rounded">{{ scope }}</span>
{% endfor %}
</div>
</td>
<td class="px-6 py-4">
<span class="text-sm text-gray-400">{{ client.created_at[:10] if client.created_at else '-' }}</span>
</td>
<td class="px-6 py-4">
<div class="flex items-center gap-2">
<button
onclick="showClientDetails({{ loop.index }})"
class="p-2 text-gray-400 hover:text-white transition-colors"
title="{% if lang == 'fa' %}جزئیات{% else %}Details{% endif %}"
>
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/>
</svg>
</button>
<button
onclick="confirmDeleteClient('{{ client.client_id }}', '{{ client.client_name }}')"
class="p-2 text-red-400 hover:text-red-300 transition-colors"
title="{{ t.delete }}"
>
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
</svg>
</button>
</div>
</td>
</tr>
<!-- Details Row (hidden by default) -->
<tr id="details-{{ loop.index }}" class="hidden bg-gray-900/50">
<td colspan="5" class="px-6 py-4">
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<p class="text-sm text-gray-400 mb-1">{% if lang == 'fa' %}آدرس‌های Redirect{% else %}Redirect URIs{% endif %}</p>
<div class="space-y-1">
{% for uri in client.redirect_uris %}
<code class="block text-xs text-gray-300 bg-gray-800 px-2 py-1 rounded">{{ uri }}</code>
{% endfor %}
</div>
</div>
<div>
<p class="text-sm text-gray-400 mb-1">{% if lang == 'fa' %}انواع Grant{% else %}Grant Types{% endif %}</p>
<div class="flex flex-wrap gap-1">
{% for grant in client.grant_types %}
<span class="px-2 py-0.5 bg-purple-500/20 text-purple-400 text-xs rounded">{{ grant }}</span>
{% endfor %}
</div>
</div>
</div>
</td>
</tr>
{% endfor %}
{% else %}
<tr>
<td colspan="5" class="px-6 py-12 text-center">
<svg class="w-12 h-12 mx-auto mb-4 text-gray-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z"/>
</svg>
<p class="text-gray-400 mb-4">
{% if lang == 'fa' %}هیچ کلاینت OAuth ثبت نشده{% else %}No OAuth clients registered{% endif %}
</p>
<button
onclick="openCreateModal()"
class="px-4 py-2 bg-primary-600 hover:bg-primary-700 rounded-lg text-white text-sm transition-colors"
>
{% if lang == 'fa' %}ایجاد اولین کلاینت{% else %}Create First Client{% endif %}
</button>
</td>
</tr>
{% endif %}
</tbody>
</table>
</div>
</div>
</div>
<!-- Create Client Modal -->
<div id="createModal" class="fixed inset-0 bg-black/50 hidden items-center justify-center z-50">
<div class="bg-gray-800 rounded-xl border border-gray-700 p-6 w-full max-w-lg mx-4">
<h3 class="text-xl font-semibold text-white mb-4">
{% if lang == 'fa' %}ایجاد کلاینت OAuth{% else %}Create OAuth Client{% endif %}
</h3>
<form id="createForm" class="space-y-4">
<div>
<label class="block text-sm text-gray-400 mb-1">{% if lang == 'fa' %}نام کلاینت{% else %}Client Name{% endif %}</label>
<input
type="text"
name="client_name"
required
class="w-full bg-gray-700 border border-gray-600 rounded-lg px-4 py-2 text-white focus:ring-2 focus:ring-primary-500 focus:border-transparent"
placeholder="{% if lang == 'fa' %}مثال: My MCP Client{% else %}e.g., My MCP Client{% endif %}"
>
</div>
<div>
<label class="block text-sm text-gray-400 mb-1">{% if lang == 'fa' %}آدرس‌های Redirect{% else %}Redirect URIs{% endif %}</label>
<textarea
name="redirect_uris"
required
rows="3"
class="w-full bg-gray-700 border border-gray-600 rounded-lg px-4 py-2 text-white focus:ring-2 focus:ring-primary-500 focus:border-transparent"
placeholder="https://example.com/callback&#10;https://app.example.com/oauth/callback"
></textarea>
<p class="text-xs text-gray-500 mt-1">
{% if lang == 'fa' %}هر آدرس را در یک خط جداگانه وارد کنید{% else %}Enter one URI per line{% endif %}
</p>
</div>
<div>
<label class="block text-sm text-gray-400 mb-1">{% if lang == 'fa' %}دامنه‌ها{% else %}Scopes{% endif %}</label>
<div class="flex flex-wrap gap-2">
<label class="flex items-center gap-2">
<input type="checkbox" name="scopes" value="read" checked class="rounded bg-gray-700 border-gray-600 text-primary-500">
<span class="text-sm text-gray-300">read</span>
</label>
<label class="flex items-center gap-2">
<input type="checkbox" name="scopes" value="write" class="rounded bg-gray-700 border-gray-600 text-primary-500">
<span class="text-sm text-gray-300">write</span>
</label>
<label class="flex items-center gap-2">
<input type="checkbox" name="scopes" value="admin" class="rounded bg-gray-700 border-gray-600 text-primary-500">
<span class="text-sm text-gray-300">admin</span>
</label>
</div>
<p class="text-xs text-gray-500 mt-1">
{% if lang == 'fa' %}admin: دسترسی کامل به همه عملیات{% else %}admin: Full access to all operations{% endif %}
</p>
</div>
<div class="flex justify-end gap-3 pt-4">
<button
type="button"
onclick="closeCreateModal()"
class="px-4 py-2 bg-gray-700 hover:bg-gray-600 rounded-lg text-white text-sm transition-colors"
>
{{ t.cancel }}
</button>
<button
type="submit"
class="px-4 py-2 bg-primary-600 hover:bg-primary-700 rounded-lg text-white text-sm transition-colors"
>
{{ t.create }}
</button>
</div>
</form>
</div>
</div>
<!-- Success Modal (shows client secret) -->
<div id="successModal" class="fixed inset-0 bg-black/50 hidden items-center justify-center z-50">
<div class="bg-gray-800 rounded-xl border border-gray-700 p-6 w-full max-w-lg mx-4">
<div class="text-center">
<div class="w-16 h-16 bg-green-500/20 rounded-full flex items-center justify-center mx-auto mb-4">
<svg class="w-8 h-8 text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>
</svg>
</div>
<h3 class="text-xl font-semibold text-white mb-2">
{% if lang == 'fa' %}کلاینت ایجاد شد{% else %}Client Created{% endif %}
</h3>
<p class="text-sm text-gray-400 mb-4">
{% if lang == 'fa' %}این رمز فقط یکبار نمایش داده می‌شود. آن را در جای امنی ذخیره کنید.{% else %}This secret is only shown once. Save it in a secure place.{% endif %}
</p>
</div>
<div class="space-y-3 mb-6">
<div>
<label class="block text-sm text-gray-400 mb-1">Client ID</label>
<div class="flex items-center gap-2">
<code id="newClientId" class="flex-1 bg-gray-900 px-3 py-2 rounded text-sm text-gray-300 overflow-x-auto"></code>
<button onclick="copyToClipboard('newClientId')" class="p-2 text-gray-400 hover:text-white">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"/>
</svg>
</button>
</div>
</div>
<div>
<label class="block text-sm text-gray-400 mb-1">Client Secret</label>
<div class="flex items-center gap-2">
<code id="newClientSecret" class="flex-1 bg-gray-900 px-3 py-2 rounded text-sm text-green-400 overflow-x-auto"></code>
<button onclick="copyToClipboard('newClientSecret')" class="p-2 text-gray-400 hover:text-white">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"/>
</svg>
</button>
</div>
</div>
</div>
<button
onclick="closeSuccessModal()"
class="w-full px-4 py-2 bg-primary-600 hover:bg-primary-700 rounded-lg text-white text-sm transition-colors"
>
{% if lang == 'fa' %}متوجه شدم{% else %}I understand{% endif %}
</button>
</div>
</div>
<!-- Delete Confirmation Modal -->
<div id="deleteModal" class="fixed inset-0 bg-black/50 hidden items-center justify-center z-50">
<div class="bg-gray-800 rounded-xl border border-gray-700 p-6 w-full max-w-md mx-4">
<div class="text-center">
<div class="w-16 h-16 bg-red-500/20 rounded-full flex items-center justify-center mx-auto mb-4">
<svg class="w-8 h-8 text-red-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
</svg>
</div>
<h3 class="text-xl font-semibold text-white mb-2">
{% if lang == 'fa' %}حذف کلاینت{% else %}Delete Client{% endif %}
</h3>
<p class="text-gray-400 mb-1">
{% if lang == 'fa' %}آیا مطمئن هستید که می‌خواهید این کلاینت را حذف کنید؟{% else %}Are you sure you want to delete this client?{% endif %}
</p>
<p id="deleteClientName" class="text-white font-medium mb-4"></p>
</div>
<div class="flex gap-3">
<button
onclick="closeDeleteModal()"
class="flex-1 px-4 py-2 bg-gray-700 hover:bg-gray-600 rounded-lg text-white text-sm transition-colors"
>
{{ t.cancel }}
</button>
<button
onclick="deleteClient()"
class="flex-1 px-4 py-2 bg-red-600 hover:bg-red-700 rounded-lg text-white text-sm transition-colors"
>
{{ t.delete }}
</button>
</div>
</div>
</div>
{% endblock %}
{% block scripts %}
<script>
(function() {
if (window.oauthClientsPageInitialized) return;
window.oauthClientsPageInitialized = true;
var currentDeleteClientId = null;
function openCreateModal() {
document.getElementById('createModal').classList.remove('hidden');
document.getElementById('createModal').classList.add('flex');
}
function closeCreateModal() {
document.getElementById('createModal').classList.add('hidden');
document.getElementById('createModal').classList.remove('flex');
document.getElementById('createForm').reset();
}
function closeSuccessModal() {
document.getElementById('successModal').classList.add('hidden');
document.getElementById('successModal').classList.remove('flex');
window.location.reload();
}
function showClientDetails(index) {
var row = document.getElementById('details-' + index);
if (row) {
row.classList.toggle('hidden');
}
}
function confirmDeleteClient(clientId, clientName) {
currentDeleteClientId = clientId;
document.getElementById('deleteClientName').textContent = clientName;
document.getElementById('deleteModal').classList.remove('hidden');
document.getElementById('deleteModal').classList.add('flex');
}
function closeDeleteModal() {
document.getElementById('deleteModal').classList.add('hidden');
document.getElementById('deleteModal').classList.remove('flex');
currentDeleteClientId = null;
}
function deleteClient() {
if (!currentDeleteClientId) return;
fetch('/api/dashboard/oauth-clients/' + currentDeleteClientId, {
method: 'DELETE',
credentials: 'same-origin'
})
.then(function(response) { return response.json(); })
.then(function(data) {
if (data.success) {
window.location.reload();
} else {
alert(data.error || 'Failed to delete client');
}
})
.catch(function(error) {
console.error('Error:', error);
alert('Failed to delete client');
});
closeDeleteModal();
}
function copyToClipboard(elementId) {
var text = document.getElementById(elementId).textContent;
navigator.clipboard.writeText(text).then(function() {
alert('{% if lang == "fa" %}کپی شد{% else %}Copied{% endif %}');
});
}
// Form submission
document.getElementById('createForm').addEventListener('submit', function(e) {
e.preventDefault();
var formData = new FormData(this);
var scopes = [];
document.querySelectorAll('input[name="scopes"]:checked').forEach(function(cb) {
scopes.push(cb.value);
});
// Parse redirect URIs (one per line)
var redirectUrisText = formData.get('redirect_uris') || '';
var redirectUris = redirectUrisText.split('\n')
.map(function(uri) { return uri.trim(); })
.filter(function(uri) { return uri.length > 0; });
var data = {
client_name: formData.get('client_name'),
redirect_uris: redirectUris,
scopes: scopes
};
fetch('/api/dashboard/oauth-clients/create', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
credentials: 'same-origin',
body: JSON.stringify(data)
})
.then(function(response) { return response.json(); })
.then(function(data) {
if (data.success) {
closeCreateModal();
document.getElementById('newClientId').textContent = data.client_id;
document.getElementById('newClientSecret').textContent = data.client_secret;
document.getElementById('successModal').classList.remove('hidden');
document.getElementById('successModal').classList.add('flex');
} else {
alert(data.error || 'Failed to create client');
}
})
.catch(function(error) {
console.error('Error:', error);
alert('Failed to create client');
});
});
// Expose functions to window
window.openCreateModal = openCreateModal;
window.closeCreateModal = closeCreateModal;
window.closeSuccessModal = closeSuccessModal;
window.showClientDetails = showClientDetails;
window.confirmDeleteClient = confirmDeleteClient;
window.closeDeleteModal = closeDeleteModal;
window.deleteClient = deleteClient;
window.copyToClipboard = copyToClipboard;
})();
</script>
{% endblock %}

View File

@@ -0,0 +1,372 @@
{% extends "dashboard/base.html" %}
{% block title %}{{ project.alias or project.site_id }} - {{ t.projects }}{% endblock %}
{% block page_title %}
<div class="flex items-center">
<a href="/dashboard/projects{% if lang and lang != 'en' %}?lang={{ lang }}{% endif %}" class="text-gray-400 hover:text-white {% if lang == 'fa' %}ml-3{% else %}mr-3{% endif %} transition-colors">
<svg class="w-5 h-5 {% if lang == 'fa' %}rotate-180{% endif %}" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/>
</svg>
</a>
<span>{{ project.plugin_type|plugin_name }}: {{ project.alias or project.site_id }}</span>
</div>
{% endblock %}
{% block content %}
<div class="space-y-6">
<!-- Stats Cards -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
<!-- Status Card -->
<div class="card-hover bg-gray-800 rounded-xl p-6 border border-gray-700">
<div class="flex items-center justify-between">
<div>
<p class="text-sm font-medium text-gray-400">{% if lang == 'fa' %}وضعیت{% else %}Status{% endif %}</p>
<div class="flex items-center mt-2">
{% if project.health.status == 'healthy' %}
<span class="w-3 h-3 bg-green-500 rounded-full status-pulse {% if lang == 'fa' %}ml-2{% else %}mr-2{% endif %}"></span>
<span class="text-xl font-bold text-green-400">{{ t.healthy }}</span>
{% elif project.health.status == 'warning' %}
<span class="w-3 h-3 bg-yellow-500 rounded-full {% if lang == 'fa' %}ml-2{% else %}mr-2{% endif %}"></span>
<span class="text-xl font-bold text-yellow-400">{% if lang == 'fa' %}هشدار{% else %}Warning{% endif %}</span>
{% elif project.health.status == 'unhealthy' %}
<span class="w-3 h-3 bg-red-500 rounded-full {% if lang == 'fa' %}ml-2{% else %}mr-2{% endif %}"></span>
<span class="text-xl font-bold text-red-400">{% if lang == 'fa' %}ناسالم{% else %}Unhealthy{% endif %}</span>
{% else %}
<span class="w-3 h-3 bg-gray-500 rounded-full {% if lang == 'fa' %}ml-2{% else %}mr-2{% endif %}"></span>
<span class="text-xl font-bold text-gray-400">{% if lang == 'fa' %}نامشخص{% else %}Unknown{% endif %}</span>
{% endif %}
</div>
</div>
<div class="w-12 h-12 {% if project.health.status == 'healthy' %}bg-green-500/20{% elif project.health.status == 'warning' %}bg-yellow-500/20{% elif project.health.status == 'unhealthy' %}bg-red-500/20{% else %}bg-gray-500/20{% endif %} rounded-lg flex items-center justify-center">
<svg class="w-6 h-6 {% if project.health.status == 'healthy' %}text-green-400{% elif project.health.status == 'warning' %}text-yellow-400{% elif project.health.status == 'unhealthy' %}text-red-400{% else %}text-gray-400{% endif %}" fill="none" stroke="currentColor" viewBox="0 0 24 24">
{% if project.health.status == 'healthy' %}
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
{% elif project.health.status == 'unknown' %}
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8.228 9c.549-1.165 2.03-2 3.772-2 2.21 0 4 1.343 4 3 0 1.4-1.278 2.575-3.006 2.907-.542.104-.994.54-.994 1.093m0 3h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
{% else %}
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/>
{% endif %}
</svg>
</div>
</div>
{% if project.health.error_rate and project.health.error_rate > 0 %}
<p class="mt-2 text-sm text-gray-400">{% if lang == 'fa' %}نرخ خطا:{% else %}Error rate:{% endif %} {{ project.health.error_rate|round(1) }}%</p>
{% elif project.health.last_check %}
<p class="mt-2 text-sm text-gray-400">{% if lang == 'fa' %}آخرین بررسی:{% else %}Last check:{% endif %} {{ project.health.last_check[:19] }}</p>
{% endif %}
</div>
<!-- Tools Card -->
<div class="card-hover bg-gray-800 rounded-xl p-6 border border-gray-700">
<div class="flex items-center justify-between">
<div>
<p class="text-sm font-medium text-gray-400">{% if lang == 'fa' %}ابزارها{% else %}Tools{% endif %}</p>
<p class="text-3xl font-bold text-white mt-1">{{ project.tools_count }}</p>
</div>
<div class="w-12 h-12 bg-purple-500/20 rounded-lg flex items-center justify-center">
<svg class="w-6 h-6 text-purple-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0"/>
</svg>
</div>
</div>
<p class="mt-2 text-sm text-gray-400">{% if lang == 'fa' %}ابزار موجود{% else %}available{% endif %}</p>
</div>
<!-- API Keys Card -->
<div class="card-hover bg-gray-800 rounded-xl p-6 border border-gray-700">
<div class="flex items-center justify-between">
<div>
<p class="text-sm font-medium text-gray-400">{% if lang == 'fa' %}کلیدهای API{% else %}API Keys{% endif %}</p>
<p class="text-3xl font-bold text-white mt-1">{{ project.api_keys_count }}</p>
</div>
<div class="w-12 h-12 bg-green-500/20 rounded-lg flex items-center justify-center">
<svg class="w-6 h-6 text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z"/>
</svg>
</div>
</div>
<a href="/dashboard/api-keys?project={{ project.full_id }}{% if lang and lang != 'en' %}&lang={{ lang }}{% endif %}" class="mt-2 text-sm text-green-400 hover:text-green-300">
{{ t.view_all }} →
</a>
</div>
<!-- Requests Card -->
<div class="card-hover bg-gray-800 rounded-xl p-6 border border-gray-700">
<div class="flex items-center justify-between">
<div>
<p class="text-sm font-medium text-gray-400">{% if lang == 'fa' %}درخواست‌ها{% else %}Requests{% endif %}</p>
<p class="text-3xl font-bold text-white mt-1">{{ project.requests_24h }}</p>
</div>
<div class="w-12 h-12 bg-blue-500/20 rounded-lg flex items-center justify-center">
<svg class="w-6 h-6 text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 7h8m0 0v8m0-8l-8 8-4-4-6 6"/>
</svg>
</div>
</div>
<p class="mt-2 text-sm text-gray-400">{% if lang == 'fa' %}در 24 ساعت{% else %}/24h{% endif %}</p>
</div>
</div>
<!-- Main Content Grid -->
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
<!-- Configuration -->
<div class="lg:col-span-2 space-y-6">
<!-- Config Section -->
<div class="bg-gray-800 rounded-xl border border-gray-700">
<div class="p-6 border-b border-gray-700">
<h2 class="text-lg font-semibold text-white">{% if lang == 'fa' %}تنظیمات{% else %}Configuration{% endif %}</h2>
</div>
<div class="p-6">
<dl class="space-y-4">
<div class="flex justify-between py-2 border-b border-gray-700">
<dt class="text-gray-400">{% if lang == 'fa' %}شناسه کامل{% else %}Full ID{% endif %}</dt>
<dd class="text-white font-mono">{{ project.full_id }}</dd>
</div>
<div class="flex justify-between py-2 border-b border-gray-700">
<dt class="text-gray-400">{% if lang == 'fa' %}نوع پلاگین{% else %}Plugin Type{% endif %}</dt>
<dd class="text-white">{{ project.plugin_type|plugin_name }}</dd>
</div>
<div class="flex justify-between py-2 border-b border-gray-700">
<dt class="text-gray-400">{% if lang == 'fa' %}شناسه سایت{% else %}Site ID{% endif %}</dt>
<dd class="text-white font-mono">{{ project.site_id }}</dd>
</div>
{% if project.alias %}
<div class="flex justify-between py-2 border-b border-gray-700">
<dt class="text-gray-400">{% if lang == 'fa' %}نام مستعار{% else %}Alias{% endif %}</dt>
<dd class="text-primary-400 font-medium">{{ project.alias }}</dd>
</div>
{% endif %}
{% if project.url %}
<div class="flex justify-between py-2 border-b border-gray-700">
<dt class="text-gray-400">URL</dt>
<dd>
<a href="{{ project.url }}" target="_blank" class="text-blue-400 hover:text-blue-300">
{{ project.url }}
<svg class="w-4 h-4 inline {% if lang == 'fa' %}mr-1{% else %}ml-1{% endif %}" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"/>
</svg>
</a>
</dd>
</div>
{% endif %}
<div class="flex justify-between py-2">
<dt class="text-gray-400">{% if lang == 'fa' %}اندپوینت MCP{% else %}MCP Endpoint{% endif %}</dt>
<dd class="text-white font-mono text-sm">/project/{{ project.alias or project.full_id }}/mcp</dd>
</div>
</dl>
</div>
</div>
<!-- Available Tools -->
<div class="bg-gray-800 rounded-xl border border-gray-700">
<div class="p-6 border-b border-gray-700 flex items-center justify-between">
<h2 class="text-lg font-semibold text-white">{% if lang == 'fa' %}ابزارهای موجود{% else %}Available Tools{% endif %}</h2>
<span class="px-2 py-1 bg-gray-700 rounded-lg text-sm text-gray-300">{{ project.tools|length }} {% if lang == 'fa' %}ابزار{% else %}tools{% endif %}</span>
</div>
<div class="max-h-96 overflow-y-auto">
<table class="w-full">
<thead class="bg-gray-700/50 sticky top-0">
<tr>
<th class="px-4 py-2 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-xs font-medium text-gray-400 uppercase">
{% if lang == 'fa' %}نام{% else %}Name{% endif %}
</th>
<th class="px-4 py-2 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-xs font-medium text-gray-400 uppercase">
{% if lang == 'fa' %}توضیحات{% else %}Description{% endif %}
</th>
<th class="px-4 py-2 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-xs font-medium text-gray-400 uppercase">
{% if lang == 'fa' %}دسترسی{% else %}Scope{% endif %}
</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-700">
{% for tool in project.tools[:50] %}
<tr class="hover:bg-gray-700/30">
<td class="px-4 py-2">
<span class="text-sm text-white font-mono">{{ tool.name }}</span>
</td>
<td class="px-4 py-2">
<span class="text-sm text-gray-400 truncate block max-w-xs" title="{{ tool.description }}">
{{ tool.description[:60] }}{% if tool.description|length > 60 %}...{% endif %}
</span>
</td>
<td class="px-4 py-2">
{% set scope_colors = {'read': 'bg-blue-500/20 text-blue-400', 'write': 'bg-orange-500/20 text-orange-400', 'admin': 'bg-red-500/20 text-red-400'} %}
<span class="px-2 py-0.5 rounded text-xs {{ scope_colors.get(tool.scope, 'bg-gray-500/20 text-gray-400') }}">
{{ tool.scope }}
</span>
</td>
</tr>
{% endfor %}
{% if project.tools|length > 50 %}
<tr>
<td colspan="3" class="px-4 py-3 text-center text-gray-400 text-sm">
{% if lang == 'fa' %}و {{ project.tools|length - 50 }} ابزار دیگر...{% else %}and {{ project.tools|length - 50 }} more tools...{% endif %}
</td>
</tr>
{% endif %}
</tbody>
</table>
</div>
</div>
</div>
<!-- Right Column -->
<div class="space-y-6">
<!-- Quick Actions -->
<div class="bg-gray-800 rounded-xl border border-gray-700">
<div class="p-6 border-b border-gray-700">
<h2 class="text-lg font-semibold text-white">{% if lang == 'fa' %}عملیات سریع{% else %}Quick Actions{% endif %}</h2>
</div>
<!-- Health Check Result Display -->
<div id="health-check-result" class="hidden p-4 rounded-lg mb-2"></div>
<div class="p-4 space-y-2">
<button
id="health-check-btn"
hx-post="/api/dashboard/projects/{{ project.full_id }}/health-check"
hx-swap="none"
hx-on::before-request="showHealthCheckLoading()"
hx-on::after-request="handleHealthCheckResponse(event)"
class="w-full flex items-center justify-between px-4 py-3 bg-gray-700 hover:bg-gray-600 rounded-lg text-white transition-colors"
>
<span id="health-check-text">{% if lang == 'fa' %}بررسی سلامت{% else %}Check Health{% endif %}</span>
<svg id="health-check-icon" class="w-5 h-5 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z"/>
</svg>
<svg id="health-check-spinner" class="hidden w-5 h-5 text-blue-400 animate-spin" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
</svg>
</button>
<a
href="/dashboard/api-keys?project={{ project.full_id }}{% if lang and lang != 'en' %}&lang={{ lang }}{% endif %}"
class="w-full flex items-center justify-between px-4 py-3 bg-gray-700 hover:bg-gray-600 rounded-lg text-white transition-colors"
>
<span>{% if lang == 'fa' %}مدیریت کلیدها{% else %}Manage API Keys{% endif %}</span>
<svg class="w-5 h-5 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z"/>
</svg>
</a>
<a
href="/dashboard/audit-logs?project={{ project.full_id }}{% if lang and lang != 'en' %}&lang={{ lang }}{% endif %}"
class="w-full flex items-center justify-between px-4 py-3 bg-gray-700 hover:bg-gray-600 rounded-lg text-white transition-colors"
>
<span>{% if lang == 'fa' %}مشاهده لاگ‌ها{% else %}View Logs{% endif %}</span>
<svg class="w-5 h-5 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"/>
</svg>
</a>
</div>
</div>
<!-- Recent Activity -->
<div class="bg-gray-800 rounded-xl border border-gray-700">
<div class="p-6 border-b border-gray-700">
<h2 class="text-lg font-semibold text-white">{{ t.recent_activity }}</h2>
</div>
<div class="divide-y divide-gray-700">
{% if project.recent_activity %}
{% for activity in project.recent_activity[:5] %}
<div class="p-4 hover:bg-gray-700/30">
<div class="flex items-center justify-between">
<div class="flex items-center">
{% if activity.level == 'ERROR' %}
<span class="w-2 h-2 bg-red-500 rounded-full {% if lang == 'fa' %}ml-2{% else %}mr-2{% endif %}"></span>
{% else %}
<span class="w-2 h-2 bg-green-500 rounded-full {% if lang == 'fa' %}ml-2{% else %}mr-2{% endif %}"></span>
{% endif %}
<span class="text-sm text-white">{{ activity.message }}</span>
</div>
<span class="text-xs text-gray-500">{{ activity.timestamp[:16] }}</span>
</div>
</div>
{% endfor %}
{% else %}
<div class="p-6 text-center text-gray-400 text-sm">
{{ t.no_activity }}
</div>
{% endif %}
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block scripts %}
<script>
(function() {
if (window.projectDetailPageInitialized) return;
window.projectDetailPageInitialized = true;
var lang = '{{ lang }}';
function showHealthCheckLoading() {
var icon = document.getElementById('health-check-icon');
var spinner = document.getElementById('health-check-spinner');
var text = document.getElementById('health-check-text');
var btn = document.getElementById('health-check-btn');
if (icon) icon.classList.add('hidden');
if (spinner) spinner.classList.remove('hidden');
if (text) text.textContent = lang === 'fa' ? 'در حال بررسی...' : 'Checking...';
if (btn) btn.disabled = true;
}
function handleHealthCheckResponse(event) {
var icon = document.getElementById('health-check-icon');
var spinner = document.getElementById('health-check-spinner');
var text = document.getElementById('health-check-text');
var btn = document.getElementById('health-check-btn');
var resultDiv = document.getElementById('health-check-result');
// Reset button state
if (icon) icon.classList.remove('hidden');
if (spinner) spinner.classList.add('hidden');
if (text) text.textContent = lang === 'fa' ? 'بررسی سلامت' : 'Check Health';
if (btn) btn.disabled = false;
// Show result
if (resultDiv && event.detail && event.detail.xhr) {
var response;
try {
response = JSON.parse(event.detail.xhr.responseText);
} catch (e) {
response = { status: 'error', message: 'Invalid response' };
}
resultDiv.classList.remove('hidden', 'bg-green-500/20', 'bg-red-500/20', 'bg-yellow-500/20');
if (response.status === 'healthy') {
resultDiv.classList.add('bg-green-500/20');
resultDiv.innerHTML = '<p class="text-green-400 font-medium">' +
(lang === 'fa' ? '✓ سالم' : '✓ Healthy') +
'</p><p class="text-sm text-gray-400">' +
(lang === 'fa' ? 'زمان پاسخ: ' : 'Response time: ') +
(response.response_time_ms || 0).toFixed(2) + ' ms</p>';
} else if (response.status === 'unhealthy') {
resultDiv.classList.add('bg-red-500/20');
resultDiv.innerHTML = '<p class="text-red-400 font-medium">' +
(lang === 'fa' ? '✗ ناسالم' : '✗ Unhealthy') +
'</p><p class="text-sm text-gray-400">' + (response.message || '') + '</p>';
} else {
resultDiv.classList.add('bg-yellow-500/20');
resultDiv.innerHTML = '<p class="text-yellow-400 font-medium">' +
(lang === 'fa' ? '⚠ خطا' : '⚠ Error') +
'</p><p class="text-sm text-gray-400">' + (response.message || 'Unknown error') + '</p>';
}
// Auto-hide after 5 seconds
setTimeout(function() {
resultDiv.classList.add('hidden');
}, 5000);
}
}
window.showHealthCheckLoading = showHealthCheckLoading;
window.handleHealthCheckResponse = handleHealthCheckResponse;
})();
</script>
{% endblock %}

View File

@@ -0,0 +1,259 @@
{% extends "dashboard/base.html" %}
{% block title %}{{ t.projects }}{% endblock %}
{% block page_title %}{{ t.projects }}{% endblock %}
{% block content %}
<div class="space-y-6">
<!-- Filters -->
<div class="bg-gray-800 rounded-xl border border-gray-700 p-4">
<form method="GET" class="flex flex-wrap items-center gap-4">
{% if lang and lang != 'en' %}<input type="hidden" name="lang" value="{{ lang }}">{% endif %}
<!-- Plugin Type Filter -->
<div class="flex items-center gap-2">
<label class="text-sm text-gray-400">{{ t.filter }}:</label>
<select
name="plugin_type"
onchange="this.form.submit()"
class="px-3 py-2 bg-gray-700 border border-gray-600 rounded-lg text-white text-sm focus:outline-none focus:border-primary-500"
>
<option value="">{{ t.all }} Types</option>
{% for plugin_type in available_plugin_types %}
<option value="{{ plugin_type }}" {% if selected_plugin_type == plugin_type %}selected{% endif %}>
{{ plugin_type|plugin_name }}
</option>
{% endfor %}
</select>
</div>
<!-- Status Filter -->
<div class="flex items-center gap-2">
<select
name="status"
onchange="this.form.submit()"
class="px-3 py-2 bg-gray-700 border border-gray-600 rounded-lg text-white text-sm focus:outline-none focus:border-primary-500"
>
<option value="">{% if lang == 'fa' %}همه وضعیت‌ها{% else %}All Status{% endif %}</option>
<option value="healthy" {% if selected_status == 'healthy' %}selected{% endif %}>{{ t.healthy }}</option>
<option value="warning" {% if selected_status == 'warning' %}selected{% endif %}>{% if lang == 'fa' %}هشدار{% else %}Warning{% endif %}</option>
<option value="unhealthy" {% if selected_status == 'unhealthy' %}selected{% endif %}>{% if lang == 'fa' %}ناسالم{% else %}Unhealthy{% endif %}</option>
<option value="unknown" {% if selected_status == 'unknown' %}selected{% endif %}>{% if lang == 'fa' %}نامشخص{% else %}Unknown{% endif %}</option>
</select>
</div>
<!-- Search -->
<div class="flex-1 min-w-[200px]">
<input
type="text"
name="search"
value="{{ search_query }}"
placeholder="{{ t.search }}..."
class="w-full px-3 py-2 bg-gray-700 border border-gray-600 rounded-lg text-white text-sm placeholder-gray-400 focus:outline-none focus:border-primary-500"
>
</div>
<button type="submit" class="px-4 py-2 bg-primary-600 hover:bg-primary-700 rounded-lg text-white text-sm transition-colors">
{{ t.search }}
</button>
{% if search_query or selected_plugin_type or selected_status %}
<a href="/dashboard/projects{% if lang and lang != 'en' %}?lang={{ lang }}{% endif %}" class="px-4 py-2 bg-gray-700 hover:bg-gray-600 rounded-lg text-white text-sm transition-colors">
{{ t['clear'] }}
</a>
{% endif %}
</form>
</div>
<!-- Projects Table -->
<div class="bg-gray-800 rounded-xl border border-gray-700 overflow-hidden">
<div class="overflow-x-auto">
<table class="w-full">
<thead class="bg-gray-700/50">
<tr>
<th class="px-6 py-4 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-sm font-medium text-gray-300">
{% if lang == 'fa' %}نوع{% else %}Plugin{% endif %}
</th>
<th class="px-6 py-4 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-sm font-medium text-gray-300">
{% if lang == 'fa' %}شناسه{% else %}Site ID{% endif %}
</th>
<th class="px-6 py-4 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-sm font-medium text-gray-300">
{% if lang == 'fa' %}نام مستعار{% else %}Alias{% endif %}
</th>
<th class="px-6 py-4 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-sm font-medium text-gray-300">
URL
</th>
<th class="px-6 py-4 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-sm font-medium text-gray-300">
{% if lang == 'fa' %}وضعیت{% else %}Status{% endif %}
</th>
<th class="px-6 py-4 text-{% if lang == 'fa' %}right{% else %}left{% endif %} text-sm font-medium text-gray-300">
{% if lang == 'fa' %}عملیات{% else %}Actions{% endif %}
</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-700">
{% if projects %}
{% for project in projects %}
<tr class="hover:bg-gray-700/30 transition-colors">
<!-- Plugin Type -->
<td class="px-6 py-4">
<div class="flex items-center">
{% set plugin_colors = {
'wordpress': 'bg-blue-500',
'woocommerce': 'bg-purple-500',
'wordpress_advanced': 'bg-indigo-500',
'gitea': 'bg-green-500',
'n8n': 'bg-orange-500',
'supabase': 'bg-emerald-500',
'openpanel': 'bg-cyan-500',
'appwrite': 'bg-pink-500',
'directus': 'bg-violet-500',
} %}
{% set plugin_icons = {
'wordpress': 'W',
'woocommerce': 'WC',
'wordpress_advanced': 'WA',
'gitea': 'G',
'n8n': 'n8n',
'supabase': 'SB',
'openpanel': 'OP',
'appwrite': 'AW',
'directus': 'DI',
} %}
<div class="w-8 h-8 {{ plugin_colors.get(project.plugin_type, 'bg-gray-500') }} rounded-lg flex items-center justify-center {% if lang == 'fa' %}ml-3{% else %}mr-3{% endif %}">
<span class="text-xs font-bold text-white">{{ plugin_icons.get(project.plugin_type, project.plugin_type[:2]|upper) }}</span>
</div>
<span class="text-sm text-white">{{ project.plugin_type|plugin_name }}</span>
</div>
</td>
<!-- Site ID -->
<td class="px-6 py-4">
<span class="text-sm text-gray-300 font-mono">{{ project.site_id }}</span>
</td>
<!-- Alias -->
<td class="px-6 py-4">
{% if project.alias %}
<span class="px-2 py-1 bg-primary-500/20 text-primary-400 text-xs rounded-lg font-medium">
{{ project.alias }}
</span>
{% else %}
<span class="text-gray-500 text-sm">-</span>
{% endif %}
</td>
<!-- URL -->
<td class="px-6 py-4">
{% if project.url %}
<a href="{{ project.url }}" target="_blank" class="text-sm text-blue-400 hover:text-blue-300 truncate max-w-[200px] block" title="{{ project.url }}">
{{ project.url[:40] }}{% if project.url|length > 40 %}...{% endif %}
</a>
{% else %}
<span class="text-gray-500 text-sm">-</span>
{% endif %}
</td>
<!-- Status -->
<td class="px-6 py-4">
{% if project.health_status == 'healthy' %}
<div class="flex items-center">
<span class="w-2 h-2 bg-green-500 rounded-full status-pulse {% if lang == 'fa' %}ml-2{% else %}mr-2{% endif %}"></span>
<span class="text-sm text-green-400">{{ t.healthy }}</span>
</div>
{% elif project.health_status == 'warning' %}
<div class="flex items-center">
<span class="w-2 h-2 bg-yellow-500 rounded-full {% if lang == 'fa' %}ml-2{% else %}mr-2{% endif %}"></span>
<span class="text-sm text-yellow-400">{% if lang == 'fa' %}هشدار{% else %}Warning{% endif %}</span>
</div>
{% elif project.health_status == 'unhealthy' %}
<div class="flex items-center">
<span class="w-2 h-2 bg-red-500 rounded-full {% if lang == 'fa' %}ml-2{% else %}mr-2{% endif %}"></span>
<span class="text-sm text-red-400">{% if lang == 'fa' %}ناسالم{% else %}Unhealthy{% endif %}</span>
</div>
{% else %}
<div class="flex items-center">
<span class="w-2 h-2 bg-gray-500 rounded-full {% if lang == 'fa' %}ml-2{% else %}mr-2{% endif %}"></span>
<span class="text-sm text-gray-400">{% if lang == 'fa' %}نامشخص{% else %}Unknown{% endif %}</span>
</div>
{% endif %}
</td>
<!-- Actions -->
<td class="px-6 py-4">
<a
href="/dashboard/projects/{{ project.full_id }}{% if lang and lang != 'en' %}?lang={{ lang }}{% endif %}"
class="inline-flex items-center px-3 py-1.5 bg-gray-700 hover:bg-gray-600 rounded-lg text-sm text-white transition-colors"
>
{{ t.view }}
<svg class="w-4 h-4 {% if lang == 'fa' %}mr-1 rotate-180{% else %}ml-1{% endif %}" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/>
</svg>
</a>
</td>
</tr>
{% endfor %}
{% else %}
<tr>
<td colspan="6" class="px-6 py-12 text-center">
<svg class="w-12 h-12 mx-auto mb-4 text-gray-500 opacity-50" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"/>
</svg>
<p class="text-gray-400">
{% if lang == 'fa' %}پروژه‌ای یافت نشد{% else %}No projects found{% endif %}
</p>
{% if search_query or selected_plugin_type %}
<p class="text-gray-500 text-sm mt-2">
{% if lang == 'fa' %}فیلترها را پاک کنید{% else %}Try clearing the filters{% endif %}
</p>
{% endif %}
</td>
</tr>
{% endif %}
</tbody>
</table>
</div>
<!-- Pagination -->
{% if total_pages > 1 %}
<div class="px-6 py-4 border-t border-gray-700 flex items-center justify-between">
<p class="text-sm text-gray-400">
{% if lang == 'fa' %}
نمایش {{ ((page_number - 1) * per_page) + 1 }} تا {{ [page_number * per_page, total_count]|min }} از {{ total_count }} پروژه
{% else %}
Showing {{ ((page_number - 1) * per_page) + 1 }} to {{ [page_number * per_page, total_count]|min }} of {{ total_count }} projects
{% endif %}
</p>
<div class="flex items-center gap-2">
{% if page_number > 1 %}
<a href="?page={{ page_number - 1 }}{% if selected_plugin_type %}&plugin_type={{ selected_plugin_type }}{% endif %}{% if search_query %}&search={{ search_query }}{% endif %}{% if lang and lang != 'en' %}&lang={{ lang }}{% endif %}"
class="px-3 py-1.5 bg-gray-700 hover:bg-gray-600 rounded-lg text-sm text-white transition-colors">
{% if lang == 'fa' %}قبلی{% else %}Previous{% endif %}
</a>
{% endif %}
{% for page_num in range(1, total_pages + 1) %}
{% if page_num == page_number %}
<span class="px-3 py-1.5 bg-primary-600 rounded-lg text-sm text-white">{{ page_num }}</span>
{% elif page_num == 1 or page_num == total_pages or (page_num >= page_number - 2 and page_num <= page_number + 2) %}
<a href="?page={{ page_num }}{% if selected_plugin_type %}&plugin_type={{ selected_plugin_type }}{% endif %}{% if search_query %}&search={{ search_query }}{% endif %}{% if lang and lang != 'en' %}&lang={{ lang }}{% endif %}"
class="px-3 py-1.5 bg-gray-700 hover:bg-gray-600 rounded-lg text-sm text-white transition-colors">
{{ page_num }}
</a>
{% elif page_num == page_number - 3 or page_num == page_number + 3 %}
<span class="text-gray-500">...</span>
{% endif %}
{% endfor %}
{% if page_number < total_pages %}
<a href="?page={{ page_number + 1 }}{% if selected_plugin_type %}&plugin_type={{ selected_plugin_type }}{% endif %}{% if search_query %}&search={{ search_query }}{% endif %}{% if lang and lang != 'en' %}&lang={{ lang }}{% endif %}"
class="px-3 py-1.5 bg-gray-700 hover:bg-gray-600 rounded-lg text-sm text-white transition-colors">
{% if lang == 'fa' %}بعدی{% else %}Next{% endif %}
</a>
{% endif %}
</div>
</div>
{% endif %}
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,210 @@
{% extends "dashboard/base.html" %}
{% block title %}{{ t.settings }}{% endblock %}
{% block page_title %}{{ t.settings }}{% endblock %}
{% block content %}
<div class="space-y-6">
<!-- Language Settings -->
<div class="bg-gray-800 rounded-xl border border-gray-700 p-6">
<h3 class="text-lg font-semibold text-white mb-4">
{% if lang == 'fa' %}تنظیمات زبان{% else %}Language Settings{% endif %}
</h3>
<div class="space-y-4">
<div class="flex items-center gap-4">
<a href="/dashboard/settings?lang=en"
class="px-4 py-2 rounded-lg transition-colors {% if lang != 'fa' %}bg-primary-600 text-white{% else %}bg-gray-700 text-gray-300 hover:bg-gray-600{% endif %}">
English
</a>
<a href="/dashboard/settings?lang=fa"
class="px-4 py-2 rounded-lg transition-colors {% if lang == 'fa' %}bg-primary-600 text-white{% else %}bg-gray-700 text-gray-300 hover:bg-gray-600{% endif %}">
فارسی
</a>
</div>
<p class="text-sm text-gray-400">
{% if lang == 'fa' %}
زبان فعلی: فارسی
{% else %}
Current language: English
{% endif %}
</p>
</div>
</div>
<!-- System Configuration -->
<div class="bg-gray-800 rounded-xl border border-gray-700 p-6">
<h3 class="text-lg font-semibold text-white mb-4">
{% if lang == 'fa' %}پیکربندی سیستم{% else %}System Configuration{% endif %}
</h3>
<div class="space-y-4">
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}حالت سرور{% else %}Server Mode{% endif %}</p>
<p class="text-white font-mono">{{ config.server_mode }}</p>
</div>
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}پورت{% else %}Port{% endif %}</p>
<p class="text-white font-mono">{{ config.port }}</p>
</div>
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}سطح لاگ{% else %}Log Level{% endif %}</p>
<p class="text-white font-mono">{{ config.log_level }}</p>
</div>
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}حالت احراز هویت OAuth{% else %}OAuth Auth Mode{% endif %}</p>
<p class="text-white font-mono">{{ config.oauth_auth_mode }}</p>
</div>
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}حد نرخ روزانه{% else %}Daily Rate Limit{% endif %}</p>
<p class="text-white font-mono">{{ config.rate_limit_per_day }}</p>
</div>
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}حد نرخ هر دقیقه{% else %}Per Minute Rate Limit{% endif %}</p>
<p class="text-white font-mono">{{ config.rate_limit_per_minute }}</p>
</div>
</div>
</div>
</div>
<!-- Security Settings -->
<div class="bg-gray-800 rounded-xl border border-gray-700 p-6">
<h3 class="text-lg font-semibold text-white mb-4">
{% if lang == 'fa' %}تنظیمات امنیتی{% else %}Security Settings{% endif %}
</h3>
<div class="space-y-4">
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}احراز هویت API فعال{% else %}API Auth Enabled{% endif %}</p>
<p class="text-white font-mono">{{ 'Yes' if config.api_auth_enabled else 'No' }}</p>
</div>
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}کوکی امن داشبورد{% else %}Dashboard Secure Cookie{% endif %}</p>
<p class="text-white font-mono">{{ 'Yes' if config.dashboard_secure_cookie else 'No' }}</p>
</div>
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}دامنه‌های مجاز OAuth{% else %}OAuth Trusted Domains{% endif %}</p>
<p class="text-white font-mono text-sm">{{ config.oauth_trusted_domains or 'localhost' }}</p>
</div>
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}مدت انقضا سشن داشبورد{% else %}Dashboard Session Expiry{% endif %}</p>
<p class="text-white font-mono">{{ config.dashboard_session_expiry }} {% if lang == 'fa' %}ساعت{% else %}hours{% endif %}</p>
</div>
</div>
</div>
</div>
<!-- Registered Plugins -->
<div class="bg-gray-800 rounded-xl border border-gray-700 p-6">
<div class="flex items-center justify-between mb-4">
<h3 class="text-lg font-semibold text-white">
{% if lang == 'fa' %}پلاگین‌های ثبت شده{% else %}Registered Plugins{% endif %}
</h3>
<span class="px-2 py-1 bg-blue-500/20 text-blue-400 text-xs rounded-lg">
{% if lang == 'fa' %}قابلیت آینده{% else %}Coming Soon{% endif %}
</span>
</div>
<div class="space-y-2">
{% if plugins %}
{% for plugin in plugins %}
<div class="flex items-center justify-between py-2 border-b border-gray-700 last:border-0">
<div>
<p class="text-white font-medium">{{ plugin.name }}</p>
<p class="text-sm text-gray-400">{{ plugin.description }}</p>
</div>
<span class="px-2 py-1 bg-green-500/20 text-green-400 text-xs rounded-lg">
{{ t.active }}
</span>
</div>
{% endfor %}
{% else %}
<div class="bg-gray-700/30 rounded-lg p-4">
<p class="text-gray-400 mb-2">
{% if lang == 'fa' %}هیچ پلاگینی ثبت نشده{% else %}No plugins registered{% endif %}
</p>
<p class="text-sm text-gray-500">
{% if lang == 'fa' %}
سیستم پلاگین در فاز‌های آینده اضافه خواهد شد. این امکان به شما اجازه می‌دهد قابلیت‌های سفارشی به MCP Hub اضافه کنید.
{% else %}
The plugin system will be added in future phases. This will allow you to extend MCP Hub with custom functionality.
{% endif %}
</p>
</div>
{% endif %}
</div>
</div>
<!-- About Section -->
<div class="bg-gray-800 rounded-xl border border-gray-700 p-6">
<h3 class="text-lg font-semibold text-white mb-4">
{% if lang == 'fa' %}درباره{% else %}About{% endif %}
</h3>
<div class="space-y-4">
<div class="flex items-center gap-4">
<div class="w-16 h-16 bg-primary-500/20 rounded-xl flex items-center justify-center">
<svg class="w-8 h-8 text-primary-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"/>
</svg>
</div>
<div>
<h4 class="text-xl font-bold text-white">MCP Hub</h4>
<p class="text-gray-400">{% if lang == 'fa' %}هاب پروتکل کانتکست مدل{% else %}Model Context Protocol Hub{% endif %}</p>
</div>
</div>
<div class="grid grid-cols-2 md:grid-cols-4 gap-4 mt-4">
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}نسخه{% else %}Version{% endif %}</p>
<p class="text-white font-mono">{{ about.version }}</p>
</div>
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}نسخه MCP{% else %}MCP Version{% endif %}</p>
<p class="text-white font-mono">{{ about.mcp_version }}</p>
</div>
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}نسخه Python{% else %}Python Version{% endif %}</p>
<p class="text-white font-mono">{{ about.python_version }}</p>
</div>
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}تعداد ابزار{% else %}Tools Count{% endif %}</p>
<p class="text-white font-mono">{{ about.tools_count }}</p>
</div>
</div>
<div class="mt-4 pt-4 border-t border-gray-700">
<p class="text-sm text-gray-400">
{% if lang == 'fa' %}
MCP Hub یک سرور MCP چند منظوره است که امکان اتصال به سرویس‌های مختلف از جمله WordPress، Gitea، n8n و دیگر سرویس‌ها را فراهم می‌کند.
{% else %}
MCP Hub is a multi-purpose MCP server that enables connection to various services including WordPress, Gitea, n8n, and other services.
{% endif %}
</p>
</div>
</div>
</div>
<!-- Session Information -->
<div class="bg-gray-800 rounded-xl border border-gray-700 p-6">
<h3 class="text-lg font-semibold text-white mb-4">
{% if lang == 'fa' %}اطلاعات سشن{% else %}Session Information{% endif %}
</h3>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}نوع کاربر{% else %}User Type{% endif %}</p>
<p class="text-white font-mono">{{ session.user_type }}</p>
</div>
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}ایجاد شده در{% else %}Created At{% endif %}</p>
<p class="text-white font-mono text-sm">{{ session.created_at[:19] if session.created_at else '-' }}</p>
</div>
<div>
<p class="text-sm text-gray-400">{% if lang == 'fa' %}انقضا در{% else %}Expires At{% endif %}</p>
<p class="text-white font-mono text-sm">{{ session.expires_at[:19] if session.expires_at else '-' }}</p>
</div>
</div>
<div class="mt-4 pt-4 border-t border-gray-700">
<a href="/dashboard/logout"
class="px-4 py-2 bg-red-600 hover:bg-red-700 rounded-lg text-white text-sm transition-colors inline-block">
{{ t.logout }}
</a>
</div>
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,170 @@
{% extends "base.html" %}
{% block title %}{{ t.page_title }}{% endblock %}
{% block content %}
<div class="auth-container px-4">
<div class="auth-card w-full max-w-md bg-white dark:bg-gray-800 rounded-lg shadow-xl p-8">
<!-- Header with Icon -->
<div class="text-center mb-6">
<div class="mx-auto flex items-center justify-center h-16 w-16 rounded-full bg-purple-100 dark:bg-purple-900 mb-4">
<svg class="h-10 w-10 text-purple-600 dark:text-purple-300" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"/>
</svg>
</div>
<h1 class="text-2xl font-bold text-gray-900 dark:text-white">{{ t.auth_required }}</h1>
<p class="text-gray-600 dark:text-gray-400 mt-2" {% if lang == 'fa' %}dir="rtl"{% endif %}>
<span class="font-semibold text-purple-600 dark:text-purple-400">{{ client_name }}</span>
{{ t.wants_access.replace('{client_name}', '') }}
</p>
</div>
<!-- Client Information -->
<div class="bg-gray-50 dark:bg-gray-700 rounded-lg p-4 mb-6">
<div class="space-y-2 text-sm" {% if lang == 'fa' %}dir="rtl"{% endif %}>
<div class="flex justify-between">
<span class="text-gray-600 dark:text-gray-400">{{ t.client_id_label }}</span>
<span class="font-mono text-gray-900 dark:text-white text-xs">{{ client_id }}</span>
</div>
{% if redirect_uri %}
<div class="flex justify-between">
<span class="text-gray-600 dark:text-gray-400">{{ t.redirect_uri_label }}</span>
<span class="font-mono text-xs text-gray-900 dark:text-white truncate ml-2" title="{{ redirect_uri }}">
{{ redirect_uri[:40] }}...
</span>
</div>
{% endif %}
</div>
</div>
<!-- Requested Permissions -->
{% if scopes %}
<div class="mb-6" {% if lang == 'fa' %}dir="rtl"{% endif %}>
<h3 class="text-sm font-semibold text-gray-700 dark:text-gray-300 mb-3">{{ t.requested_permissions }}</h3>
<div class="space-y-2">
{% for scope in scopes %}
<div class="permission-badge flex items-center p-3 bg-purple-50 dark:bg-purple-900/20 rounded-lg" {% if lang == 'fa' %}dir="rtl"{% endif %}>
<svg class="h-5 w-5 text-purple-600 dark:text-purple-400 {% if lang == 'fa' %}ml-3{% else %}mr-3{% endif %}" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
<span class="text-sm font-medium text-gray-900 dark:text-white">{{ scope }}</span>
</div>
{% endfor %}
</div>
</div>
{% endif %}
<!-- Authorization Form -->
<form method="POST" action="/oauth/authorize/confirm" id="authForm" class="space-y-4">
<!-- Hidden fields -->
<input type="hidden" name="client_id" value="{{ client_id }}">
<input type="hidden" name="redirect_uri" value="{{ redirect_uri }}">
<input type="hidden" name="response_type" value="{{ response_type }}">
<input type="hidden" name="code_challenge" value="{{ code_challenge }}">
<input type="hidden" name="code_challenge_method" value="{{ code_challenge_method }}">
{% if scope %}
<input type="hidden" name="scope" value="{{ scope }}">
{% endif %}
{% if state %}
<input type="hidden" name="state" value="{{ state }}">
{% endif %}
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
<!-- API Key Input -->
<div {% if lang == 'fa' %}dir="rtl"{% endif %}>
<label for="api_key" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
{{ t.enter_api_key }}
</label>
<input
type="password"
id="api_key"
name="api_key"
required
placeholder="{{ t.api_key_placeholder }}"
class="w-full px-4 py-3 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-purple-500 focus:border-transparent dark:bg-gray-700 dark:text-white transition"
autocomplete="off"
{% if lang == 'fa' %}dir="ltr" style="text-align: right;"{% endif %}
/>
<p class="text-xs text-gray-500 dark:text-gray-400 mt-2" {% if lang == 'fa' %}dir="rtl"{% endif %}>
{{ t.api_key_note }}
</p>
</div>
<!-- Action Buttons -->
<div class="flex gap-3 pt-4" {% if lang == 'fa' %}dir="rtl"{% endif %}>
<button
type="submit"
name="action"
value="approve"
class="btn-primary flex-1 px-6 py-3 text-white font-semibold rounded-lg"
>
{{ t.approve }}
</button>
<button
type="submit"
name="action"
value="deny"
class="btn-secondary flex-1 px-6 py-3 bg-gray-200 dark:bg-gray-700 text-gray-800 dark:text-gray-200 font-semibold rounded-lg"
>
{{ t.deny }}
</button>
</div>
</form>
<!-- Security Notice -->
<div class="mt-6 p-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg" {% if lang == 'fa' %}dir="rtl"{% endif %}>
<div class="flex {% if lang == 'fa' %}flex-row-reverse{% endif %}">
<svg class="h-5 w-5 text-blue-600 dark:text-blue-400 {% if lang == 'fa' %}mr-2{% else %}mr-2{% endif %} flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
<p class="text-xs text-blue-800 dark:text-blue-300">
<strong>{{ t.security_note }}</strong> {{ t.security_message }}
</p>
</div>
</div>
</div>
</div>
{% endblock %}
{% block scripts %}
<script>
// Client-side validation
document.getElementById('authForm').addEventListener('submit', function(e) {
const apiKey = document.getElementById('api_key').value;
const action = e.submitter.value;
if (action === 'approve') {
if (!apiKey || apiKey.length < 10) {
e.preventDefault();
const lang = '{{ lang }}';
const message = lang === 'fa'
? 'لطفاً یک API Key معتبر وارد کنید'
: 'Please enter a valid API key';
alert(message);
return false;
}
if (!apiKey.startsWith('cmp_') && !apiKey.startsWith('ckm_')) {
const lang = '{{ lang }}';
const message = lang === 'fa'
? 'فرمت API Key غیرمعمول به نظر می‌رسد. ادامه می‌دهید؟'
: 'The API key format looks unusual. Continue anyway?';
const confirm = window.confirm(message);
if (!confirm) {
e.preventDefault();
return false;
}
}
}
});
// Focus effect
const apiKeyInput = document.getElementById('api_key');
apiKeyInput.addEventListener('focus', function() {
this.parentElement.classList.add('ring-2', 'ring-purple-200');
});
apiKeyInput.addEventListener('blur', function() {
this.parentElement.classList.remove('ring-2', 'ring-purple-200');
});
</script>
{% endblock %}

View File

@@ -0,0 +1,87 @@
{% extends "base.html" %}
{% block title %}{{ t.error_title }}{% endblock %}
{% block content %}
<div class="auth-container px-4">
<div class="auth-card w-full max-w-md bg-white dark:bg-gray-800 rounded-lg shadow-xl p-8">
<!-- Error Icon -->
<div class="text-center mb-6">
<div class="mx-auto flex items-center justify-center h-16 w-16 rounded-full bg-red-100 dark:bg-red-900 mb-4">
<svg class="h-10 w-10 text-red-600 dark:text-red-300" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/>
</svg>
</div>
<h1 class="text-2xl font-bold text-gray-900 dark:text-white">{{ t.auth_error }}</h1>
<p class="text-gray-600 dark:text-gray-400 mt-2" {% if lang == 'fa' %}dir="rtl"{% endif %}>
{{ t.unable_to_complete }}
</p>
</div>
<!-- Error Details -->
<div class="bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 mb-6" {% if lang == 'fa' %}dir="rtl"{% endif %}>
<div class="space-y-3">
{% if error %}
<div>
<span class="text-sm font-semibold text-red-800 dark:text-red-300">{{ t.error_code }}</span>
<span class="text-sm font-mono text-red-900 dark:text-red-200 ml-2">{{ error }}</span>
</div>
{% endif %}
{% if error_description %}
<div>
<span class="text-sm font-semibold text-red-800 dark:text-red-300">{{ t.error_description }}</span>
<p class="text-sm text-red-900 dark:text-red-200 mt-1">{{ error_description }}</p>
</div>
{% endif %}
</div>
</div>
<!-- Common Solutions -->
<div class="mb-6" {% if lang == 'fa' %}dir="rtl"{% endif %}>
<h3 class="text-sm font-semibold text-gray-700 dark:text-gray-300 mb-3">{{ t.common_solutions }}</h3>
<ul class="space-y-2 text-sm text-gray-600 dark:text-gray-400">
<li class="flex items-start" {% if lang == 'fa' %}dir="rtl"{% endif %}>
<svg class="h-5 w-5 text-gray-400 {% if lang == 'fa' %}ml-2{% else %}mr-2{% endif %} flex-shrink-0 mt-0.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="{% if lang == 'fa' %}M15 19l-7-7 7-7{% else %}M9 5l7 7-7 7{% endif %}"/>
</svg>
<span>{{ t.solution_1 }}</span>
</li>
<li class="flex items-start" {% if lang == 'fa' %}dir="rtl"{% endif %}>
<svg class="h-5 w-5 text-gray-400 {% if lang == 'fa' %}ml-2{% else %}mr-2{% endif %} flex-shrink-0 mt-0.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="{% if lang == 'fa' %}M15 19l-7-7 7-7{% else %}M9 5l7 7-7 7{% endif %}"/>
</svg>
<span>{{ t.solution_2 }}</span>
</li>
<li class="flex items-start" {% if lang == 'fa' %}dir="rtl"{% endif %}>
<svg class="h-5 w-5 text-gray-400 {% if lang == 'fa' %}ml-2{% else %}mr-2{% endif %} flex-shrink-0 mt-0.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="{% if lang == 'fa' %}M15 19l-7-7 7-7{% else %}M9 5l7 7-7 7{% endif %}"/>
</svg>
<span>{{ t.solution_3 }}</span>
</li>
</ul>
</div>
<!-- Action Button -->
{% if redirect_uri %}
<a href="{{ redirect_uri }}?error={{ error }}&error_description={{ error_description|urlencode }}{% if state %}&state={{ state }}{% endif %}"
class="block w-full text-center px-6 py-3 bg-gray-200 dark:bg-gray-700 text-gray-800 dark:text-gray-200 font-semibold rounded-lg hover:bg-gray-300 dark:hover:bg-gray-600 transition">
{{ t.return_to_app }}
</a>
{% else %}
<button onclick="window.close()"
class="w-full px-6 py-3 bg-gray-200 dark:bg-gray-700 text-gray-800 dark:text-gray-200 font-semibold rounded-lg hover:bg-gray-300 dark:hover:bg-gray-600 transition">
{{ t.close_window }}
</button>
{% endif %}
<!-- Support Link -->
<div class="mt-6 text-center" {% if lang == 'fa' %}dir="rtl"{% endif %}>
<p class="text-xs text-gray-500 dark:text-gray-400">
{{ t.need_help }}
<a href="https://github.com/airano-ir/coolify-mcp-hub" class="text-purple-600 dark:text-purple-400 hover:underline">{{ t.documentation }}</a>
</p>
</div>
</div>
</div>
{% endblock %}