Files
CyberPanel/testPlugin/templates/testPlugin/plugin_home.html
Master3395 601434eab6 Add security and more documentation
Add security and more documentation
2025-09-11 20:17:54 +02:00

572 lines
16 KiB
HTML

{% extends "baseTemplate/index.html" %}
{% load i18n %}
{% load static %}
{% block title %}{% trans "Test Plugin - CyberPanel" %}{% endblock %}
{% block header_scripts %}
<style>
/* Test Plugin Specific Styles */
.test-plugin-wrapper {
background: transparent;
padding: 20px;
}
.test-plugin-container {
max-width: 1200px;
margin: 0 auto;
}
/* Page Header */
.plugin-header {
background: var(--bg-primary, white);
border-radius: 12px;
padding: 25px;
margin-bottom: 25px;
box-shadow: var(--shadow-md, 0 2px 8px rgba(0,0,0,0.08));
border: 1px solid var(--border-primary, #e8e9ff);
}
.plugin-header h1 {
font-size: 28px;
font-weight: 700;
color: var(--text-primary, #2f3640);
margin: 0 0 10px 0;
display: flex;
align-items: center;
gap: 15px;
}
.plugin-header .icon {
width: 48px;
height: 48px;
background: #5856d6;
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
color: white;
font-size: 24px;
box-shadow: 0 4px 12px rgba(88,86,214,0.3);
}
.plugin-header p {
font-size: 15px;
color: var(--text-secondary, #64748b);
margin: 0;
}
/* Control Panel */
.control-panel {
background: var(--bg-primary, white);
border-radius: 12px;
padding: 25px;
margin-bottom: 25px;
box-shadow: var(--shadow-md, 0 2px 8px rgba(0,0,0,0.08));
border: 1px solid var(--border-primary, #e8e9ff);
}
.control-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 20px;
flex-wrap: wrap;
gap: 15px;
}
.control-group {
display: flex;
align-items: center;
gap: 15px;
}
.toggle-switch {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}
.toggle-switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
transition: .4s;
border-radius: 34px;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
transition: .4s;
border-radius: 50%;
}
input:checked + .slider {
background-color: #5856d6;
}
input:checked + .slider:before {
transform: translateX(26px);
}
.btn-test {
background: linear-gradient(135deg, #5856d6, #4a90e2);
color: white;
border: none;
padding: 12px 24px;
border-radius: 8px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
display: flex;
align-items: center;
gap: 8px;
}
.btn-test:hover {
transform: translateY(-2px);
box-shadow: 0 8px 20px rgba(88,86,214,0.3);
}
.btn-test:disabled {
opacity: 0.6;
cursor: not-allowed;
transform: none;
}
.btn-secondary {
background: #6c757d;
color: white;
border: none;
padding: 10px 20px;
border-radius: 6px;
font-weight: 500;
cursor: pointer;
transition: all 0.3s ease;
text-decoration: none;
display: inline-flex;
align-items: center;
gap: 8px;
}
.btn-secondary:hover {
background: #5a6268;
color: white;
text-decoration: none;
}
/* Stats Cards */
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 20px;
margin-bottom: 25px;
}
.stat-card {
background: var(--bg-primary, white);
border-radius: 12px;
padding: 20px;
box-shadow: var(--shadow-md, 0 2px 8px rgba(0,0,0,0.08));
border: 1px solid var(--border-primary, #e8e9ff);
text-align: center;
}
.stat-value {
font-size: 32px;
font-weight: 700;
color: #5856d6;
margin-bottom: 8px;
}
.stat-label {
font-size: 14px;
color: var(--text-secondary, #64748b);
text-transform: uppercase;
letter-spacing: 0.5px;
}
/* Recent Logs */
.logs-section {
background: var(--bg-primary, white);
border-radius: 12px;
padding: 25px;
box-shadow: var(--shadow-md, 0 2px 8px rgba(0,0,0,0.08));
border: 1px solid var(--border-primary, #e8e9ff);
}
.logs-list {
max-height: 300px;
overflow-y: auto;
}
.log-item {
display: flex;
align-items: center;
padding: 12px 0;
border-bottom: 1px solid var(--border-primary, #e8e9ff);
}
.log-item:last-child {
border-bottom: none;
}
.log-icon {
width: 32px;
height: 32px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
margin-right: 12px;
font-size: 14px;
}
.log-icon.info {
background: #e3f2fd;
color: #1976d2;
}
.log-icon.success {
background: #e8f5e8;
color: #388e3c;
}
.log-icon.warning {
background: #fff3e0;
color: #f57c00;
}
.log-content {
flex: 1;
}
.log-action {
font-weight: 600;
color: var(--text-primary, #2f3640);
margin-bottom: 4px;
}
.log-message {
font-size: 14px;
color: var(--text-secondary, #64748b);
}
.log-time {
font-size: 12px;
color: var(--text-tertiary, #9ca3af);
margin-left: 12px;
}
/* Popup Message Styles */
.popup-message {
position: fixed;
top: 20px;
right: 20px;
background: white;
border-radius: 8px;
padding: 16px 20px;
box-shadow: 0 8px 24px rgba(0,0,0,0.15);
border-left: 4px solid #10b981;
z-index: 9999;
max-width: 400px;
transform: translateX(100%);
transition: transform 0.3s ease;
}
.popup-message.show {
transform: translateX(0);
}
.popup-message.error {
border-left-color: #ef4444;
}
.popup-message.warning {
border-left-color: #f59e0b;
}
.popup-title {
font-weight: 600;
color: var(--text-primary, #2f3640);
margin-bottom: 4px;
}
.popup-content {
font-size: 14px;
color: var(--text-secondary, #64748b);
margin-bottom: 8px;
}
.popup-time {
font-size: 12px;
color: var(--text-tertiary, #9ca3af);
}
.popup-close {
position: absolute;
top: 8px;
right: 8px;
background: none;
border: none;
font-size: 18px;
cursor: pointer;
color: var(--text-tertiary, #9ca3af);
}
/* Responsive */
@media (max-width: 768px) {
.test-plugin-wrapper {
padding: 15px;
}
.control-row {
flex-direction: column;
align-items: stretch;
}
.control-group {
justify-content: space-between;
}
.stats-grid {
grid-template-columns: 1fr;
}
.popup-message {
right: 10px;
left: 10px;
max-width: none;
}
}
</style>
{% endblock %}
{% block content %}
<div class="test-plugin-wrapper">
<div class="test-plugin-container">
<!-- Plugin Header -->
<div class="plugin-header">
<h1>
<div class="icon">
<i class="fas fa-vial"></i>
</div>
{% trans "Test Plugin" %}
</h1>
<p>{% trans "A comprehensive test plugin with enable/disable functionality, test button, and popup messages" %}</p>
</div>
<!-- Control Panel -->
<div class="control-panel">
<div class="control-row">
<div class="control-group">
<label for="plugin-toggle" style="font-weight: 600; color: var(--text-primary, #2f3640);">
{% trans "Enable Plugin" %}
</label>
<label class="toggle-switch">
<input type="checkbox" id="plugin-toggle" {% if plugin_enabled %}checked{% endif %}>
<span class="slider"></span>
</label>
</div>
<div class="control-group">
<button class="btn-test" id="test-button" {% if not plugin_enabled %}disabled{% endif %}>
<i class="fas fa-play"></i>
{% trans "Test Button" %}
</button>
<a href="{% url 'testPlugin:plugin_settings' %}" class="btn-secondary">
<i class="fas fa-cog"></i>
{% trans "Settings" %}
</a>
<a href="{% url 'testPlugin:plugin_logs' %}" class="btn-secondary">
<i class="fas fa-list"></i>
{% trans "Logs" %}
</a>
<a href="{% url 'testPlugin:plugin_docs' %}" class="btn-secondary">
<i class="fas fa-book"></i>
{% trans "Documentation" %}
</a>
<a href="{% url 'testPlugin:security_info' %}" class="btn-secondary">
<i class="fas fa-shield-alt"></i>
{% trans "Security Info" %}
</a>
</div>
</div>
</div>
<!-- Stats Cards -->
<div class="stats-grid">
<div class="stat-card">
<div class="stat-value" id="test-count">{{ settings.test_count|default:0 }}</div>
<div class="stat-label">{% trans "Test Clicks" %}</div>
</div>
<div class="stat-card">
<div class="stat-value">
{% if plugin_enabled %}
<i class="fas fa-check-circle" style="color: #10b981;"></i>
{% else %}
<i class="fas fa-times-circle" style="color: #ef4444;"></i>
{% endif %}
</div>
<div class="stat-label">{% trans "Plugin Status" %}</div>
</div>
<div class="stat-card">
<div class="stat-value">{{ recent_logs|length }}</div>
<div class="stat-label">{% trans "Recent Activities" %}</div>
</div>
</div>
<!-- Recent Logs -->
<div class="logs-section">
<h3 style="margin-bottom: 20px; color: var(--text-primary, #2f3640);">
<i class="fas fa-history" style="margin-right: 8px; color: #5856d6;"></i>
{% trans "Recent Activity" %}
</h3>
<div class="logs-list">
{% for log in recent_logs %}
<div class="log-item">
<div class="log-icon {% if 'error' in log.action %}warning{% elif 'success' in log.action or 'click' in log.action %}success{% else %}info{% endif %}">
{% if 'click' in log.action %}
<i class="fas fa-mouse-pointer"></i>
{% elif 'toggle' in log.action %}
<i class="fas fa-toggle-on"></i>
{% elif 'settings' in log.action %}
<i class="fas fa-cog"></i>
{% else %}
<i class="fas fa-info-circle"></i>
{% endif %}
</div>
<div class="log-content">
<div class="log-action">{{ log.action|title }}</div>
<div class="log-message">{{ log.message }}</div>
</div>
<div class="log-time">{{ log.timestamp|date:"M d, H:i" }}</div>
</div>
{% empty %}
<div style="text-align: center; padding: 40px; color: var(--text-secondary, #64748b);">
<i class="fas fa-inbox" style="font-size: 48px; margin-bottom: 16px; opacity: 0.5;"></i>
<p>{% trans "No recent activity" %}</p>
</div>
{% endfor %}
</div>
</div>
</div>
</div>
<!-- Popup Message Container -->
<div id="popup-container"></div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const toggleSwitch = document.getElementById('plugin-toggle');
const testButton = document.getElementById('test-button');
const testCountElement = document.getElementById('test-count');
// Toggle switch functionality
toggleSwitch.addEventListener('change', function() {
fetch('{% url "testPlugin:toggle_plugin" %}', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': '{{ csrf_token }}'
}
})
.then(response => response.json())
.then(data => {
if (data.status === 1) {
testButton.disabled = !data.enabled;
showPopup('success', 'Plugin Toggle', data.message);
location.reload(); // Refresh to update UI
} else {
showPopup('error', 'Error', data.error_message);
}
})
.catch(error => {
showPopup('error', 'Error', 'Failed to toggle plugin');
});
});
// Test button functionality
testButton.addEventListener('click', function() {
if (testButton.disabled) return;
testButton.disabled = true;
testButton.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Testing...';
fetch('{% url "testPlugin:test_button" %}', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': '{{ csrf_token }}'
}
})
.then(response => response.json())
.then(data => {
if (data.status === 1) {
testCountElement.textContent = data.test_count;
showPopup(data.popup_message.type, data.popup_message.title, data.popup_message.message);
} else {
showPopup('error', 'Error', data.error_message);
}
})
.catch(error => {
showPopup('error', 'Error', 'Failed to execute test');
})
.finally(() => {
testButton.disabled = false;
testButton.innerHTML = '<i class="fas fa-play"></i> Test Button';
});
});
// Popup message function
function showPopup(type, title, message) {
const popupContainer = document.getElementById('popup-container');
const popup = document.createElement('div');
popup.className = `popup-message ${type}`;
popup.innerHTML = `
<button class="popup-close" onclick="this.parentElement.remove()">&times;</button>
<div class="popup-title">${title}</div>
<div class="popup-content">${message}</div>
<div class="popup-time">${new Date().toLocaleTimeString()}</div>
`;
popupContainer.appendChild(popup);
// Show popup
setTimeout(() => popup.classList.add('show'), 100);
// Auto remove after 5 seconds
setTimeout(() => {
popup.classList.remove('show');
setTimeout(() => popup.remove(), 300);
}, 5000);
}
});
</script>
{% endblock %}