2026-01-28 22:37:47 +03:00
|
|
|
<template>
|
|
|
|
|
<div class="config-wrapper">
|
|
|
|
|
<div class="config-card">
|
|
|
|
|
<div class="config-header">
|
|
|
|
|
<h1>PKI Infrastructure Configuration</h1>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<form @submit.prevent="handleSave">
|
|
|
|
|
<div class="config-row">
|
|
|
|
|
<div class="config-col">
|
|
|
|
|
<label class="config-label">FQDN: CA Cert CN</label>
|
|
|
|
|
<input type="text" class="config-input" v-model="form.fqdn_ca">
|
|
|
|
|
</div>
|
|
|
|
|
<div class="config-col">
|
|
|
|
|
<label class="config-label">FQDN: Server Cert CN</label>
|
|
|
|
|
<input type="text" class="config-input" v-model="form.fqdn_server">
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="config-divider"></div>
|
|
|
|
|
|
|
|
|
|
<div class="config-row">
|
|
|
|
|
<div class="config-col" style="max-width: 50%;">
|
|
|
|
|
<label class="config-label">EASYRSA DN</label>
|
|
|
|
|
<div class="select-container">
|
|
|
|
|
<select class="config-select" v-model="form.easyrsa_dn">
|
|
|
|
|
<option value="cn_only">CN_ONLY</option>
|
|
|
|
|
<option value="org">ORG</option>
|
|
|
|
|
</select>
|
|
|
|
|
<div class="select-arrow">
|
|
|
|
|
<i class="fas fa-chevron-down"></i>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="config-col" style="max-width: 50%;">
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="config-row">
|
|
|
|
|
<div class="config-col">
|
|
|
|
|
<label class="config-label">Country</label>
|
|
|
|
|
<input type="text" class="config-input" v-model="form.easyrsa_req_country">
|
|
|
|
|
</div>
|
|
|
|
|
<div class="config-col">
|
|
|
|
|
<label class="config-label">Province / State</label>
|
|
|
|
|
<input type="text" class="config-input" v-model="form.easyrsa_req_province">
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="config-row">
|
|
|
|
|
<div class="config-col">
|
|
|
|
|
<label class="config-label">City</label>
|
|
|
|
|
<input type="text" class="config-input" v-model="form.easyrsa_req_city">
|
|
|
|
|
</div>
|
|
|
|
|
<div class="config-col">
|
|
|
|
|
<label class="config-label">Organization</label>
|
|
|
|
|
<input type="text" class="config-input" v-model="form.easyrsa_req_org">
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="config-row">
|
|
|
|
|
<div class="config-col">
|
|
|
|
|
<label class="config-label">E-mail</label>
|
|
|
|
|
<input type="email" class="config-input" v-model="form.easyrsa_req_email">
|
|
|
|
|
</div>
|
|
|
|
|
<div class="config-col">
|
|
|
|
|
<label class="config-label">Organization Unit</label>
|
|
|
|
|
<input type="text" class="config-input" v-model="form.easyrsa_req_ou">
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="config-divider"></div>
|
|
|
|
|
|
|
|
|
|
<div class="config-row">
|
|
|
|
|
<div class="config-col">
|
|
|
|
|
<label class="config-label">Key Size Length (Bits)</label>
|
|
|
|
|
<div class="select-container">
|
|
|
|
|
<select class="config-select" v-model="form.easyrsa_key_size">
|
|
|
|
|
<option value="2048">2048</option>
|
|
|
|
|
<option value="4096">4096</option>
|
|
|
|
|
</select>
|
|
|
|
|
<div class="select-arrow">
|
|
|
|
|
<i class="fas fa-chevron-down"></i>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="config-col">
|
|
|
|
|
<label class="config-label">CA Expire (Days)</label>
|
|
|
|
|
<div class="number-input-container">
|
|
|
|
|
<input type="number" class="config-input" v-model.number="form.easyrsa_ca_expire">
|
|
|
|
|
<div class="number-input-controls">
|
|
|
|
|
<button type="button" class="number-input-btn" @click="form.easyrsa_ca_expire++"><i class="fas fa-chevron-up"></i></button>
|
|
|
|
|
<button type="button" class="number-input-btn" @click="form.easyrsa_ca_expire--"><i class="fas fa-chevron-down"></i></button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="config-row">
|
|
|
|
|
<div class="config-col">
|
|
|
|
|
<label class="config-label">Cert Expire (Days)</label>
|
|
|
|
|
<div class="number-input-container">
|
|
|
|
|
<input type="number" class="config-input" v-model.number="form.easyrsa_cert_expire">
|
|
|
|
|
<div class="number-input-controls">
|
|
|
|
|
<button type="button" class="number-input-btn" @click="form.easyrsa_cert_expire++"><i class="fas fa-chevron-up"></i></button>
|
|
|
|
|
<button type="button" class="number-input-btn" @click="form.easyrsa_cert_expire--"><i class="fas fa-chevron-down"></i></button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="config-col">
|
|
|
|
|
<label class="config-label">Cert Renew (Days)</label>
|
|
|
|
|
<div class="number-input-container">
|
|
|
|
|
<input type="number" class="config-input" v-model.number="form.easyrsa_cert_renew">
|
|
|
|
|
<div class="number-input-controls">
|
|
|
|
|
<button type="button" class="number-input-btn" @click="form.easyrsa_cert_renew++"><i class="fas fa-chevron-up"></i></button>
|
|
|
|
|
<button type="button" class="number-input-btn" @click="form.easyrsa_cert_renew--"><i class="fas fa-chevron-down"></i></button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="config-row">
|
|
|
|
|
<div class="config-col">
|
|
|
|
|
<label class="config-label">CRL Valid (Days)</label>
|
|
|
|
|
<div class="number-input-container">
|
|
|
|
|
<input type="number" class="config-input" v-model.number="form.easyrsa_crl_days">
|
|
|
|
|
<div class="number-input-controls">
|
|
|
|
|
<button type="button" class="number-input-btn" @click="form.easyrsa_crl_days++"><i class="fas fa-chevron-up"></i></button>
|
|
|
|
|
<button type="button" class="number-input-btn" @click="form.easyrsa_crl_days--"><i class="fas fa-chevron-down"></i></button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="config-col">
|
|
|
|
|
<label class="config-label">Batch</label>
|
|
|
|
|
<div class="toggle-wrapper">
|
|
|
|
|
<label class="toggle-switch">
|
|
|
|
|
<input type="checkbox" v-model="form.easyrsa_batch">
|
|
|
|
|
<span class="toggle-slider"></span>
|
|
|
|
|
</label>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="config-divider"></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="btn-action-group">
|
2026-10-04 20:56:36 +03:00
|
|
|
<button type="button" class="btn-action btn-action-save" @click="handleSave" :disabled="isBusy">
|
2026-01-28 22:37:47 +03:00
|
|
|
<i class="fas fa-save"></i>
|
|
|
|
|
Save PKI
|
|
|
|
|
</button>
|
2026-10-04 20:56:36 +03:00
|
|
|
<button type="button" class="btn-action btn-action-primary" @click="handleInit" :disabled="isBusy || initStatus.initialized"
|
|
|
|
|
:title="initStatus.initialized ? 'PKI is already initialized. Use Clear PKI to start over' : ''">
|
|
|
|
|
<i v-if="isInitRunning" class="fas fa-spinner fa-spin"></i>
|
2026-01-28 22:37:47 +03:00
|
|
|
<i v-else class="fas fa-play-circle"></i>
|
|
|
|
|
Init PKI
|
|
|
|
|
</button>
|
2026-10-04 20:56:36 +03:00
|
|
|
<button type="button" class="btn-action btn-action-danger" @click="handleClear" :disabled="isBusy">
|
2026-01-28 22:37:47 +03:00
|
|
|
<i v-if="isLoading && action==='clear'" class="fas fa-spinner fa-spin"></i>
|
|
|
|
|
<i v-else class="fas fa-trash-alt"></i>
|
|
|
|
|
Clear PKI
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2026-10-04 20:56:36 +03:00
|
|
|
<div v-if="isInitRunning" class="config-label">{{ stepText }}</div>
|
2026-01-28 22:37:47 +03:00
|
|
|
</form>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-10-07 13:10:41 +03:00
|
|
|
<ConfirmModal ref="initModal" @confirm="runInit" />
|
|
|
|
|
<ConfirmModal ref="clearModal" @confirm="runClear" />
|
2026-01-28 22:37:47 +03:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2026-10-04 20:56:36 +03:00
|
|
|
import { ref, computed, onMounted, onUnmounted, reactive } 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-10-07 13:10:41 +03:00
|
|
|
import ConfirmModal from '../components/ConfirmModal.vue';
|
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 { refresh: refreshPkiStatus } = usePkiStatus();
|
2026-01-28 22:37:47 +03:00
|
|
|
|
|
|
|
|
// State
|
|
|
|
|
const form = reactive({
|
|
|
|
|
fqdn_ca: '',
|
|
|
|
|
fqdn_server: '',
|
|
|
|
|
easyrsa_dn: 'cn_only',
|
|
|
|
|
easyrsa_req_country: '',
|
|
|
|
|
easyrsa_req_province: '',
|
|
|
|
|
easyrsa_req_city: '',
|
|
|
|
|
easyrsa_req_org: '',
|
|
|
|
|
easyrsa_req_email: '',
|
|
|
|
|
easyrsa_req_ou: '',
|
|
|
|
|
easyrsa_key_size: 2048,
|
|
|
|
|
easyrsa_ca_expire: null,
|
|
|
|
|
easyrsa_cert_expire: null,
|
|
|
|
|
easyrsa_cert_renew: null,
|
|
|
|
|
easyrsa_crl_days: null,
|
|
|
|
|
easyrsa_batch: true
|
|
|
|
|
});
|
|
|
|
|
|
2026-10-07 13:10:41 +03:00
|
|
|
const initModal = ref(null);
|
|
|
|
|
const clearModal = ref(null);
|
2026-01-28 22:37:47 +03:00
|
|
|
const isLoading = ref(false);
|
|
|
|
|
const action = ref(''); // 'save', 'init', 'clear'
|
|
|
|
|
|
2026-10-04 20:56:36 +03:00
|
|
|
// PKI init job state, taken from the server (GET /system/init/status)
|
|
|
|
|
const initStatus = reactive({ state: 'idle', step: null, initialized: false, error: null });
|
|
|
|
|
const isInitRunning = computed(() => initStatus.state === 'running' || action.value === 'init');
|
|
|
|
|
const isBusy = computed(() => isLoading.value || isInitRunning.value);
|
|
|
|
|
|
|
|
|
|
const STEP_TEXTS = {
|
|
|
|
|
'init-pki': 'Initializing PKI...',
|
|
|
|
|
'ca': 'Building CA...',
|
|
|
|
|
'server-cert': 'Building server certificate...',
|
|
|
|
|
'dh': 'Generating DH parameters (this can take several minutes)...',
|
|
|
|
|
'ta-key': 'Generating TLS key...',
|
|
|
|
|
'crl': 'Generating CRL...'
|
|
|
|
|
};
|
|
|
|
|
const stepText = computed(() => STEP_TEXTS[initStatus.step] || 'Initializing PKI...');
|
|
|
|
|
|
|
|
|
|
let pollTimer = null;
|
|
|
|
|
|
2026-01-28 22:37:47 +03:00
|
|
|
// 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
|
|
|
|
|
|
|
|
// API Fetch Wrapper
|
|
|
|
|
// API Wrapper removed, using profilesApiClient directly
|
|
|
|
|
|
|
|
|
|
const loadConfig = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const res = await profilesApiClient.get('/config', { params: { section: 'pki' } });
|
|
|
|
|
const payload = res.data;
|
|
|
|
|
const data = payload.pki ? payload.pki : payload;
|
|
|
|
|
|
|
|
|
|
// Populate form
|
|
|
|
|
Object.keys(data).forEach(key => {
|
2026-10-07 13:13:25 +03:00
|
|
|
if (Object.hasOwn(form, key)) {
|
2026-01-28 22:37:47 +03:00
|
|
|
form[key] = data[key];
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error(err);
|
|
|
|
|
showMessage('Failed to load PKI config from Management API.', 'error');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-10-04 20:56:36 +03:00
|
|
|
const stopPolling = () => {
|
|
|
|
|
if (pollTimer) {
|
|
|
|
|
clearInterval(pollTimer);
|
|
|
|
|
pollTimer = null;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const startPolling = () => {
|
|
|
|
|
if (!pollTimer) pollTimer = setInterval(() => loadStatus(), 3000);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const loadStatus = async (initial = false) => {
|
|
|
|
|
const wasRunning = initStatus.state === 'running';
|
|
|
|
|
try {
|
|
|
|
|
const res = await profilesApiClient.get('/system/init/status');
|
|
|
|
|
Object.assign(initStatus, res.data);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error(err);
|
|
|
|
|
return; // keep polling, the next tick may succeed
|
|
|
|
|
}
|
|
|
|
|
if (initStatus.state === 'running') {
|
|
|
|
|
startPolling();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
stopPolling();
|
2026-10-04 21:52:40 +03:00
|
|
|
if (wasRunning) refreshPkiStatus(); // unlock the sidebar without a reload
|
2026-10-04 20:56:36 +03:00
|
|
|
// Report the result once: a job seen running on this page, or a failure found on page load
|
|
|
|
|
if (wasRunning && initStatus.state === 'done') {
|
|
|
|
|
showMessage('PKI initialized successfully!', 'success');
|
|
|
|
|
} else if ((wasRunning || initial) && initStatus.state === 'error') {
|
|
|
|
|
showMessage(`Error initializing: ${initStatus.error}`, 'error');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-01-28 22:37:47 +03:00
|
|
|
const handleSave = async () => {
|
|
|
|
|
isLoading.value = true;
|
|
|
|
|
action.value = 'save';
|
|
|
|
|
try {
|
|
|
|
|
await profilesApiClient.put('/config/pki', form);
|
|
|
|
|
showMessage('Configuration saved successfully!', 'success');
|
|
|
|
|
} catch (err) {
|
|
|
|
|
showMessage(`Error saving: ${err.message}`, 'error');
|
|
|
|
|
} finally {
|
|
|
|
|
isLoading.value = false;
|
|
|
|
|
action.value = '';
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-10-07 13:10:41 +03:00
|
|
|
const handleInit = () => {
|
|
|
|
|
initModal.value.open({
|
|
|
|
|
title: 'Initialize PKI?',
|
|
|
|
|
message: 'Are you sure you want to initialize the system? This will start the PKI initialization process.',
|
|
|
|
|
confirmText: 'Yes, initialize',
|
|
|
|
|
confirmBtnClass: 'btn-action-primary'
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const runInit = async () => {
|
2026-01-28 22:37:47 +03:00
|
|
|
isLoading.value = true;
|
2026-10-04 20:56:36 +03:00
|
|
|
action.value = 'init'; // locks the button until the server confirms the job state
|
2026-01-28 22:37:47 +03:00
|
|
|
try {
|
2026-10-04 20:56:36 +03:00
|
|
|
await profilesApiClient.post('/system/init');
|
|
|
|
|
initStatus.state = 'running'; // 202: the job is running in the background
|
|
|
|
|
startPolling();
|
2026-01-28 22:37:47 +03:00
|
|
|
} catch (err) {
|
2026-10-04 20:56:36 +03:00
|
|
|
if (err.response && err.response.status === 409) {
|
|
|
|
|
// Already running (second tab) or already initialized: attach to the server state
|
|
|
|
|
await loadStatus();
|
|
|
|
|
} else {
|
2026-10-04 21:52:40 +03:00
|
|
|
showMessage(`Error initializing: ${err.response?.data?.detail || err.message}`, 'error');
|
2026-10-04 20:56:36 +03:00
|
|
|
}
|
2026-01-28 22:37:47 +03:00
|
|
|
} finally {
|
|
|
|
|
isLoading.value = false;
|
|
|
|
|
action.value = '';
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-10-07 13:10:41 +03:00
|
|
|
const handleClear = () => {
|
|
|
|
|
clearModal.value.open({
|
|
|
|
|
title: 'Clear PKI?',
|
|
|
|
|
message: 'Are you sure you want to CLEAR the PKI? This will delete all certificates and cannot be undone.',
|
|
|
|
|
confirmText: 'Yes, clear',
|
|
|
|
|
confirmBtnClass: 'btn-action-danger'
|
|
|
|
|
});
|
|
|
|
|
};
|
2026-01-28 22:37:47 +03:00
|
|
|
|
2026-10-07 13:10:41 +03:00
|
|
|
const runClear = async () => {
|
2026-01-28 22:37:47 +03:00
|
|
|
isLoading.value = true;
|
|
|
|
|
action.value = 'clear';
|
|
|
|
|
try {
|
|
|
|
|
const res = await profilesApiClient.delete('/system/pki');
|
|
|
|
|
const data = res.data;
|
|
|
|
|
showMessage(data.message || 'PKI cleared successfully!', 'warning');
|
2026-10-04 20:56:36 +03:00
|
|
|
await loadStatus();
|
2026-10-04 21:52:40 +03:00
|
|
|
refreshPkiStatus();
|
2026-01-28 22:37:47 +03:00
|
|
|
} catch (err) {
|
2026-10-04 21:52:40 +03:00
|
|
|
showMessage(`Error clearing PKI: ${err.response?.data?.detail || err.message}`, 'error');
|
2026-01-28 22:37:47 +03:00
|
|
|
} finally {
|
|
|
|
|
isLoading.value = false;
|
|
|
|
|
action.value = '';
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
loadConfig();
|
2026-10-04 20:56:36 +03:00
|
|
|
loadStatus(true);
|
2026-01-28 22:37:47 +03:00
|
|
|
});
|
2026-10-04 20:56:36 +03:00
|
|
|
|
|
|
|
|
onUnmounted(stopPolling);
|
2026-01-28 22:37:47 +03:00
|
|
|
</script>
|