new awesome build

This commit is contained in:
Антон committed 2026-01-28 22:37:47 +03:00
1 parent 848646003c
commit fcb8f6bac7
119 files changed
+7291 -5575

No files matched your search

+169
View File
@@ -0,0 +1,169 @@
<template>
<div class="config-wrapper">
<div class="config-card">
<div class="config-header">
<h1>Server Process Management</h1>
</div>
<div v-if="message.text" :class="['toast-message', 'toast-' + message.type, 'show']">
<i :class="['fas', message.icon]"></i> {{ message.text }}
</div>
<!-- Stats Grid -->
<!-- User requested specific order: CPU (full), Status, PID, Memory, Uptime -->
<div class="stats-grid mb-4">
<!-- CPU Usage (Full Width) -->
<div class="stat-item full-width cpu-progress">
<label class="stat-label d-flex justify-content-between">
<span>CPU Usage</span>
<span>{{ stats.cpu_percent }}%</span>
</label>
<div class="progress">
<div class="progress-bar progress-bar-brand" role="progressbar"
:style="{ width: Math.min(stats.cpu_percent, 100) + '%' }"
:aria-valuenow="stats.cpu_percent" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
<!-- Status -->
<div class="stat-item">
<label class="stat-label">Status</label>
<div class="d-flex align-items-center">
<span :class="['status-badge', 'status-' + (stats.status === 'running' ? 'active' : 'revoked')]">
{{ stats.status.toUpperCase() }}
</span>
</div>
</div>
<!-- PID -->
<div class="stat-item">
<label class="stat-label">Process ID</label>
<div class="stat-value">{{ stats.pid || 'N/A' }}</div>
</div>
<!-- Memory -->
<div class="stat-item">
<label class="stat-label">Memory (RSS)</label>
<div class="stat-value">{{ stats.memory_mb }} MB</div>
</div>
<!-- Uptime -->
<div class="stat-item">
<label class="stat-label">Uptime</label>
<div class="stat-value monospace">{{ stats.uptime || 'N/A' }}</div>
</div>
</div>
<!-- Action Buttons -->
<div class="btn-action-group justify-content-center">
<!-- Start -->
<button type="button" class="btn-action btn-action-primary"
@click="handleControl('start')"
:disabled="isLoading || stats.status === 'running'">
<i v-if="isLoading && action==='start'" class="fas fa-spinner fa-spin"></i>
<i v-else class="fas fa-play"></i>
Start Service
</button>
<!-- Restart -->
<button type="button" class="btn-action btn-action-save"
@click="handleControl('restart')"
:disabled="isLoading">
<i v-if="isLoading && action==='restart'" class="fas fa-spinner fa-spin"></i>
<i v-else class="fas fa-sync-alt"></i>
Restart Service
</button>
<!-- Stop -->
<button type="button" class="btn-action btn-action-danger"
@click="handleControl('stop')"
:disabled="isLoading || stats.status !== 'running'">
<i v-if="isLoading && action==='stop'" class="fas fa-spinner fa-spin"></i>
<i v-else class="fas fa-stop"></i>
Stop Service
</button>
</div>
</div>
</div>
</template>
<script setup>
import { ref, reactive, onMounted, onUnmounted } from 'vue';
import { useApi } from '../composables/useApi';
const { profilesApiClient } = useApi();
// State
const stats = reactive({
status: 'unknown',
pid: null,
cpu_percent: 0.0,
memory_mb: 0.0,
uptime: null
});
const message = reactive({
text: '',
type: 'success',
icon: 'fa-check-circle'
});
const isLoading = ref(false);
const action = ref(''); // 'start', 'stop', 'restart'
let pollInterval = null;
// Methods
const showMessage = (text, type = 'success') => {
message.text = text;
message.type = type;
message.icon = type === 'success' ? 'fa-check-circle' : 'fa-exclamation-circle';
setTimeout(() => {
message.text = '';
}, 4000);
};
const fetchStats = async () => {
try {
const res = await profilesApiClient.get('/server/process/stats');
Object.assign(stats, res.data);
} catch (err) {
console.error("Failed to fetch stats:", err);
// Don't show error toast on every poll failure to avoid spam
}
};
const handleControl = async (cmd) => {
if (!confirm(`Are you sure you want to ${cmd.toUpperCase()} the OpenVPN service?`)) return;
isLoading.value = true;
action.value = cmd;
try {
const res = await profilesApiClient.post(`/server/process/${cmd}`);
showMessage(res.data.message || `Service ${cmd} successful`, 'success');
// Refresh stats immediately after action
setTimeout(fetchStats, 1000);
} catch (err) {
const errMsg = err.response?.data?.detail || err.message;
showMessage(`Failed to ${cmd}: ${errMsg}`, 'error');
} finally {
isLoading.value = false;
action.value = '';
}
};
onMounted(() => {
fetchStats();
// Poll every 5 seconds
pollInterval = setInterval(fetchStats, 5000);
});
onUnmounted(() => {
if (pollInterval) clearInterval(pollInterval);
});
</script>