Login: label for/id, autocomplete, inputmode for the 2FA code; clickable table rows, headers and client links work from the keyboard. One product name (OpenVPN Controller), own favicon (logo.svg) instead of vite.svg, footer text fixed. Minimal ESLint config (npm run lint, clean). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
360 lines
15 KiB
Vue
360 lines
15 KiB
Vue
<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">
|
|
<button type="button" class="btn-action btn-action-save" @click="handleSave" :disabled="isBusy">
|
|
<i class="fas fa-save"></i>
|
|
Save PKI
|
|
</button>
|
|
<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>
|
|
<i v-else class="fas fa-play-circle"></i>
|
|
Init PKI
|
|
</button>
|
|
<button type="button" class="btn-action btn-action-danger" @click="handleClear" :disabled="isBusy">
|
|
<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>
|
|
<div v-if="isInitRunning" class="config-label">{{ stepText }}</div>
|
|
</form>
|
|
</div>
|
|
|
|
<ConfirmModal ref="initModal" @confirm="runInit" />
|
|
<ConfirmModal ref="clearModal" @confirm="runClear" />
|
|
</div>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { ref, computed, onMounted, onUnmounted, reactive } from 'vue';
|
|
|
|
import { useApi } from '../composables/useApi';
|
|
import { useToast } from '../composables/useToast';
|
|
import { usePkiStatus } from '../composables/usePkiStatus';
|
|
import ConfirmModal from '../components/ConfirmModal.vue';
|
|
|
|
const { profilesApiClient } = useApi();
|
|
const toast = useToast();
|
|
const { refresh: refreshPkiStatus } = usePkiStatus();
|
|
|
|
// 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
|
|
});
|
|
|
|
const initModal = ref(null);
|
|
const clearModal = ref(null);
|
|
const isLoading = ref(false);
|
|
const action = ref(''); // 'save', 'init', 'clear'
|
|
|
|
// 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;
|
|
|
|
// Methods
|
|
const showMessage = (text, type = 'success') => toast.show(text, type);
|
|
|
|
// 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 => {
|
|
if (Object.hasOwn(form, key)) {
|
|
form[key] = data[key];
|
|
}
|
|
});
|
|
} catch (err) {
|
|
console.error(err);
|
|
showMessage('Failed to load PKI config from Management API.', 'error');
|
|
}
|
|
};
|
|
|
|
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();
|
|
if (wasRunning) refreshPkiStatus(); // unlock the sidebar without a reload
|
|
// 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');
|
|
}
|
|
};
|
|
|
|
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 = '';
|
|
}
|
|
};
|
|
|
|
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 () => {
|
|
isLoading.value = true;
|
|
action.value = 'init'; // locks the button until the server confirms the job state
|
|
try {
|
|
await profilesApiClient.post('/system/init');
|
|
initStatus.state = 'running'; // 202: the job is running in the background
|
|
startPolling();
|
|
} catch (err) {
|
|
if (err.response && err.response.status === 409) {
|
|
// Already running (second tab) or already initialized: attach to the server state
|
|
await loadStatus();
|
|
} else {
|
|
showMessage(`Error initializing: ${err.response?.data?.detail || err.message}`, 'error');
|
|
}
|
|
} finally {
|
|
isLoading.value = false;
|
|
action.value = '';
|
|
}
|
|
};
|
|
|
|
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'
|
|
});
|
|
};
|
|
|
|
const runClear = async () => {
|
|
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');
|
|
await loadStatus();
|
|
refreshPkiStatus();
|
|
} catch (err) {
|
|
showMessage(`Error clearing PKI: ${err.response?.data?.detail || err.message}`, 'error');
|
|
} finally {
|
|
isLoading.value = false;
|
|
action.value = '';
|
|
}
|
|
};
|
|
|
|
onMounted(() => {
|
|
loadConfig();
|
|
loadStatus(true);
|
|
});
|
|
|
|
onUnmounted(stopPolling);
|
|
</script>
|