2026-01-28 22:37:47 +03:00
|
|
|
<template>
|
|
|
|
|
<div class="config-wrapper">
|
|
|
|
|
<div class="config-card">
|
|
|
|
|
<div class="config-header">
|
|
|
|
|
<h1>Server Process Management</h1>
|
|
|
|
|
</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')"
|
2026-10-04 21:52:40 +03:00
|
|
|
:disabled="isLoading || stats.status === 'running' || !pkiStatus.server_ready"
|
|
|
|
|
:title="startHint">
|
2026-01-28 22:37:47 +03:00
|
|
|
<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')"
|
2026-10-04 21:52:40 +03:00
|
|
|
:disabled="isLoading || !pkiStatus.server_ready"
|
|
|
|
|
:title="startHint">
|
2026-01-28 22:37:47 +03:00
|
|
|
<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>
|
2026-10-04 21:52:40 +03:00
|
|
|
import { ref, reactive, computed, onMounted, onUnmounted } from 'vue';
|
2026-01-28 22:37:47 +03:00
|
|
|
import { useApi } from '../composables/useApi';
|
2026-10-04 21:05:41 +03:00
|
|
|
import { useToast } from '../composables/useToast';
|
2026-10-04 21:52:40 +03:00
|
|
|
import { usePkiStatus } from '../composables/usePkiStatus';
|
2026-01-28 22:37:47 +03:00
|
|
|
|
|
|
|
|
const { profilesApiClient } = useApi();
|
2026-10-04 21:05:41 +03:00
|
|
|
const toast = useToast();
|
2026-10-04 21:52:40 +03:00
|
|
|
const { status: pkiStatus, refresh: refreshPkiStatus } = usePkiStatus();
|
|
|
|
|
|
|
|
|
|
// Start/Restart need the PKI server files (Stop stays available)
|
|
|
|
|
const startHint = computed(() => {
|
|
|
|
|
if (pkiStatus.server_ready) return '';
|
|
|
|
|
return pkiStatus.pki_ready && pkiStatus.missing.length
|
|
|
|
|
? `Missing server files: ${pkiStatus.missing.join(', ')}`
|
|
|
|
|
: 'Initialize PKI first';
|
|
|
|
|
});
|
2026-01-28 22:37:47 +03:00
|
|
|
|
|
|
|
|
// State
|
|
|
|
|
const stats = reactive({
|
|
|
|
|
status: 'unknown',
|
|
|
|
|
pid: null,
|
|
|
|
|
cpu_percent: 0.0,
|
|
|
|
|
memory_mb: 0.0,
|
|
|
|
|
uptime: null
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const isLoading = ref(false);
|
|
|
|
|
const action = ref(''); // 'start', 'stop', 'restart'
|
|
|
|
|
let pollInterval = null;
|
|
|
|
|
|
|
|
|
|
// Methods
|
2026-10-04 21:05:41 +03:00
|
|
|
const showMessage = (text, type = 'success') => toast.show(text, type);
|
2026-01-28 22:37:47 +03:00
|
|
|
|
|
|
|
|
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(() => {
|
2026-10-04 21:52:40 +03:00
|
|
|
refreshPkiStatus();
|
2026-01-28 22:37:47 +03:00
|
|
|
fetchStats();
|
|
|
|
|
// Poll every 5 seconds
|
|
|
|
|
pollInterval = setInterval(fetchStats, 5000);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
|
if (pollInterval) clearInterval(pollInterval);
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
|