Certificates: profile modal with notes, note tooltip; async PKI init
- Profiler: UserProfile.note (nullable, startup migration), PUT
/profiles/{id}/note (max 1000 chars); add missing `requests`
dependency (client creation failed without Public IP set).
- UI: clickable rows on Certificates open a compact profile details
modal with an editable note; tooltip with the note on the client
name (v-note-tooltip) and a note icon.
- PKI init runs in a background thread: POST /system/init returns 202,
GET /system/init/status, 409 for a second start, Clear PKI and client
creation are blocked while it runs. A marker file identifies an
interrupted run (only such a PKI is wiped on the next Init).
- PKI Configuration page: state from the server, progress spinner and
step text, polling, Init/Clear/Save locked while running, Init locked
once initialized.
- Tests: one pytest each for notes and async init (requirements-dev.txt).
- Docs: plans and summaries in DOCS/Changes, API reference, README, Index.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3836049230
commit
d251ec73d0
24 files changed
+722
-39
No files matched your search
@@ -1802,6 +1802,48 @@ input[type="number"].config-input {
|
||||
transform: scale(1.02);
|
||||
}
|
||||
|
||||
/* Profile note tooltip (v-note-tooltip) */
|
||||
.note-tooltip {
|
||||
--bs-tooltip-max-width: 320px;
|
||||
--bs-tooltip-bg: var(--bg-card);
|
||||
--bs-tooltip-color: var(--text-main);
|
||||
--bs-tooltip-opacity: 1;
|
||||
}
|
||||
|
||||
.note-tooltip .tooltip-inner {
|
||||
max-width: 320px;
|
||||
white-space: pre-wrap;
|
||||
text-align: left;
|
||||
word-break: break-word;
|
||||
background-color: var(--bg-card);
|
||||
color: var(--text-main);
|
||||
border: 1px solid var(--border-color);
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.note-tooltip .tooltip-arrow::before {
|
||||
border-top-color: var(--border-color);
|
||||
}
|
||||
|
||||
/* Compact label : value list (profile details modal) */
|
||||
.profile-meta {
|
||||
display: grid;
|
||||
grid-template-columns: 5.5rem 1fr;
|
||||
gap: 0.25rem 0.75rem;
|
||||
margin: 0 0 1rem;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.profile-meta dt {
|
||||
font-weight: 600;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.profile-meta dd {
|
||||
margin: 0;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
/* Shared Utilities */
|
||||
.cursor-pointer {
|
||||
cursor: pointer;
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
<template>
|
||||
<BaseModal id="profileDetailsModal" title="Profile Details" ref="modal">
|
||||
<template #header>
|
||||
<div class="d-flex align-items-center gap-2 flex-wrap">
|
||||
<h5 class="modal-title fw-bold mb-0" style="color: var(--text-heading);">{{ profile?.username }}</h5>
|
||||
<span v-if="profile" class="status-badge" :class="status.cls">{{ status.label }}</span>
|
||||
</div>
|
||||
</template>
|
||||
<template #body>
|
||||
<div v-if="profile">
|
||||
<dl class="profile-meta">
|
||||
<dt>Created</dt>
|
||||
<dd>{{ formatDate(profile.created_at) }}</dd>
|
||||
<dt>Expires</dt>
|
||||
<dd>{{ formatDate(profile.expiration_date) }}<span v-if="daysLabel" class="text-muted"> ({{ daysLabel }})</span></dd>
|
||||
<template v-if="profile.revoked_at">
|
||||
<dt>Revoked</dt>
|
||||
<dd>{{ formatDate(profile.revoked_at) }}</dd>
|
||||
</template>
|
||||
<dt>File</dt>
|
||||
<dd class="certificate-file text-muted small text-break mt-0">{{ profile.file_path || 'N/A' }}</dd>
|
||||
</dl>
|
||||
|
||||
<label for="profileNote" class="form-label small text-muted text-uppercase fw-bold">Note</label>
|
||||
<textarea class="form-control" id="profileNote" rows="3" maxlength="1000" v-model="note" placeholder="Add a note about this profile..."></textarea>
|
||||
<div class="form-text text-end">{{ note.length }} / 1000</div>
|
||||
</div>
|
||||
</template>
|
||||
<template #footer>
|
||||
<button type="button" class="btn-action btn-action-secondary" @click="close">Close</button>
|
||||
<button type="button" class="btn-action btn-action-save" @click="save" :disabled="!dirty">Save</button>
|
||||
</template>
|
||||
</BaseModal>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed } from 'vue';
|
||||
import BaseModal from './BaseModal.vue';
|
||||
|
||||
const emit = defineEmits(['save']);
|
||||
const modal = ref(null);
|
||||
const profile = ref(null);
|
||||
const note = ref('');
|
||||
|
||||
const dirty = computed(() => note.value !== (profile.value?.note || ''));
|
||||
|
||||
const status = computed(() => {
|
||||
const p = profile.value;
|
||||
if (p?.is_revoked) return { label: 'Revoked', cls: 'status-expired' };
|
||||
if (p?.is_expired) return { label: 'Expired', cls: 'status-expired' };
|
||||
if (p?.days_remaining != null && p.days_remaining <= 30) return { label: 'Expiring Soon', cls: 'status-warning' };
|
||||
return { label: 'Active', cls: 'status-valid' };
|
||||
});
|
||||
|
||||
const daysLabel = computed(() => {
|
||||
const days = profile.value?.days_remaining;
|
||||
if (days == null) return '';
|
||||
return days > 0 ? `${days} d` : 'expired';
|
||||
});
|
||||
|
||||
// YYYY-MM-DD HH:mm (local time)
|
||||
const formatDate = (dateStr) => {
|
||||
if (!dateStr) return 'N/A';
|
||||
const d = new Date(dateStr);
|
||||
if (isNaN(d)) return dateStr;
|
||||
const pad = (n) => String(n).padStart(2, '0');
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
||||
};
|
||||
|
||||
const open = (p) => {
|
||||
profile.value = p;
|
||||
note.value = p.note || '';
|
||||
modal.value.show();
|
||||
};
|
||||
|
||||
const close = () => {
|
||||
modal.value.hide();
|
||||
};
|
||||
|
||||
const save = () => {
|
||||
emit('save', { id: profile.value.id, note: note.value });
|
||||
close();
|
||||
};
|
||||
|
||||
defineExpose({ open, close });
|
||||
</script>
|
||||
@@ -0,0 +1,37 @@
|
||||
import { Tooltip } from 'bootstrap';
|
||||
|
||||
// v-note-tooltip="text": Bootstrap tooltip with the profile note.
|
||||
// No tooltip for an empty value; plain text only (html: false).
|
||||
const create = (el, text) => {
|
||||
el._noteTooltip = new Tooltip(el, {
|
||||
title: text,
|
||||
placement: 'top',
|
||||
container: 'body',
|
||||
html: false,
|
||||
trigger: 'hover',
|
||||
customClass: 'note-tooltip'
|
||||
});
|
||||
};
|
||||
|
||||
const destroy = (el) => {
|
||||
el._noteTooltip?.dispose();
|
||||
el._noteTooltip = null;
|
||||
};
|
||||
|
||||
// Hide on click: the row click opens the details modal
|
||||
const hideOnClick = (el) => el._noteTooltip?.hide();
|
||||
|
||||
export default {
|
||||
mounted(el, binding) {
|
||||
el.addEventListener('click', () => hideOnClick(el));
|
||||
if (binding.value) create(el, binding.value);
|
||||
},
|
||||
updated(el, binding) {
|
||||
if (binding.value === binding.oldValue) return;
|
||||
destroy(el);
|
||||
if (binding.value) create(el, binding.value);
|
||||
},
|
||||
unmounted(el) {
|
||||
destroy(el);
|
||||
}
|
||||
};
|
||||
@@ -88,9 +88,12 @@
|
||||
<tr v-if="activeCerts.length > 0" class="section-divider">
|
||||
<td colspan="6">Active Certificates ({{ activeCerts.length }})</td>
|
||||
</tr>
|
||||
<tr v-for="cert in activeCerts" :key="cert.id + '_active'">
|
||||
<td>
|
||||
<div class="fw-semibold" style="color: var(--text-heading);">{{ cert.username }}</div>
|
||||
<tr v-for="cert in activeCerts" :key="cert.id + '_active'" style="cursor: pointer;" @click="showDetails(cert)">
|
||||
<td v-note-tooltip="cert.note">
|
||||
<div class="fw-semibold" style="color: var(--text-heading);">
|
||||
{{ cert.username }}
|
||||
<i v-if="cert.note" class="fas fa-note-sticky text-muted ms-1 small"></i>
|
||||
</div>
|
||||
<div class="certificate-file text-muted small">{{ cert.file_path || 'N/A' }}</div>
|
||||
</td>
|
||||
<td><span class="status-badge status-client">Client</span></td>
|
||||
@@ -100,10 +103,10 @@
|
||||
</td>
|
||||
<td v-html="getStatusBadgeHTML(cert)"></td>
|
||||
<td>
|
||||
<button class="btn btn-sm btn-link text-warning p-0 me-2" title="Download Config" @click="downloadConfig(cert)">
|
||||
<button class="btn btn-sm btn-link text-warning p-0 me-2" title="Download Config" @click.stop="downloadConfig(cert)">
|
||||
<i class="fas fa-download"></i>
|
||||
</button>
|
||||
<button class="btn btn-sm btn-link text-danger p-0" title="Revoke" @click="revokeClient(cert)">
|
||||
<button class="btn btn-sm btn-link text-danger p-0" title="Revoke" @click.stop="revokeClient(cert)">
|
||||
<i class="fas fa-ban"></i>
|
||||
</button>
|
||||
</td>
|
||||
@@ -114,9 +117,12 @@
|
||||
<tr class="section-divider">
|
||||
<td colspan="6">Expired / Revoked ({{ expiredCerts.length }})</td>
|
||||
</tr>
|
||||
<tr v-for="cert in expiredCerts" :key="cert.id + '_expired'">
|
||||
<td>
|
||||
<div class="fw-semibold" style="color: var(--text-heading);">{{ cert.username }}</div>
|
||||
<tr v-for="cert in expiredCerts" :key="cert.id + '_expired'" style="cursor: pointer;" @click="showDetails(cert)">
|
||||
<td v-note-tooltip="cert.note">
|
||||
<div class="fw-semibold" style="color: var(--text-heading);">
|
||||
{{ cert.username }}
|
||||
<i v-if="cert.note" class="fas fa-note-sticky text-muted ms-1 small"></i>
|
||||
</div>
|
||||
<div class="certificate-file text-muted small">{{ cert.file_path || 'N/A' }}</div>
|
||||
</td>
|
||||
<td><span class="status-badge status-client">Client</span></td>
|
||||
@@ -126,7 +132,7 @@
|
||||
</td>
|
||||
<td v-html="getStatusBadgeHTML(cert)"></td>
|
||||
<td>
|
||||
<button class="btn btn-sm btn-link text-danger p-0" title="Revoke" @click="revokeClient(cert)" :disabled="cert.is_revoked">
|
||||
<button class="btn btn-sm btn-link text-danger p-0" title="Revoke" @click.stop="revokeClient(cert)" :disabled="cert.is_revoked">
|
||||
<i class="fas fa-ban"></i>
|
||||
</button>
|
||||
</td>
|
||||
@@ -140,6 +146,7 @@
|
||||
|
||||
<NewClientModal ref="newClientModal" @create="createClient" />
|
||||
<ConfirmModal ref="confirmModal" @confirm="confirmRevoke" />
|
||||
<ProfileDetailsModal ref="detailsModal" @save="saveNote" />
|
||||
|
||||
<div v-if="toastMessage" class="toast-message show" :class="'toast-' + toastType" style="position: fixed; bottom: 20px; right: 20px; z-index: 9999;">
|
||||
<i class="fas" :class="toastType === 'success' ? 'fa-check-circle' : 'fa-exclamation-circle'"></i>
|
||||
@@ -152,6 +159,8 @@ import { ref, computed, onMounted } from 'vue';
|
||||
import { useApi } from '../composables/useApi';
|
||||
import NewClientModal from '../components/NewClientModal.vue';
|
||||
import ConfirmModal from '../components/ConfirmModal.vue';
|
||||
import ProfileDetailsModal from '../components/ProfileDetailsModal.vue';
|
||||
import vNoteTooltip from '../directives/noteTooltip';
|
||||
|
||||
const { profilesApiClient } = useApi();
|
||||
|
||||
@@ -162,6 +171,7 @@ const hideExpired = ref(false);
|
||||
|
||||
const newClientModal = ref(null);
|
||||
const confirmModal = ref(null);
|
||||
const detailsModal = ref(null);
|
||||
const toastMessage = ref('');
|
||||
const toastType = ref('success');
|
||||
|
||||
@@ -276,6 +286,20 @@ const createClient = async (username) => {
|
||||
}
|
||||
};
|
||||
|
||||
const showDetails = (cert) => {
|
||||
detailsModal.value.open(cert);
|
||||
};
|
||||
|
||||
const saveNote = async ({ id, note }) => {
|
||||
try {
|
||||
await profilesApiClient.put(`/profiles/${id}/note`, { note });
|
||||
showToast('Note saved.', 'success');
|
||||
loadCerts();
|
||||
} catch(e) {
|
||||
showToast(e.response?.data?.detail || e.message, 'error');
|
||||
}
|
||||
};
|
||||
|
||||
const downloadConfig = async (cert) => {
|
||||
if (!cert.id) return;
|
||||
try {
|
||||
|
||||
@@ -149,21 +149,23 @@
|
||||
|
||||
|
||||
<div class="btn-action-group">
|
||||
<button type="button" class="btn-action btn-action-save" @click="handleSave" :disabled="isLoading">
|
||||
<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="isLoading">
|
||||
<i v-if="isLoading && action==='init'" class="fas fa-spinner fa-spin"></i>
|
||||
<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="isLoading">
|
||||
<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>
|
||||
|
||||
@@ -171,7 +173,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted, reactive } from 'vue';
|
||||
import { ref, computed, onMounted, onUnmounted, reactive } from 'vue';
|
||||
|
||||
import { useApi } from '../composables/useApi';
|
||||
|
||||
@@ -205,6 +207,23 @@ const message = reactive({
|
||||
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') => {
|
||||
message.text = text;
|
||||
@@ -238,6 +257,39 @@ const loadConfig = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
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();
|
||||
// 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';
|
||||
@@ -256,13 +308,18 @@ const handleInit = async () => {
|
||||
if (!confirm('Are you sure you want to Initialize system? This will start the PKI initialization process.')) return;
|
||||
|
||||
isLoading.value = true;
|
||||
action.value = 'init';
|
||||
action.value = 'init'; // locks the button until the server confirms the job state
|
||||
try {
|
||||
const res = await profilesApiClient.post('/system/init');
|
||||
const data = res.data;
|
||||
showMessage(data.message || 'System initialized successfully!', 'success');
|
||||
await profilesApiClient.post('/system/init');
|
||||
initStatus.state = 'running'; // 202: the job is running in the background
|
||||
startPolling();
|
||||
} catch (err) {
|
||||
showMessage(`Error initializing: ${err.message}`, 'error');
|
||||
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.message}`, 'error');
|
||||
}
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
action.value = '';
|
||||
@@ -278,6 +335,7 @@ const handleClear = async () => {
|
||||
const res = await profilesApiClient.delete('/system/pki');
|
||||
const data = res.data;
|
||||
showMessage(data.message || 'PKI cleared successfully!', 'warning');
|
||||
await loadStatus();
|
||||
} catch (err) {
|
||||
showMessage(`Error clearing PKI: ${err.message}`, 'error');
|
||||
} finally {
|
||||
@@ -288,5 +346,8 @@ const handleClear = async () => {
|
||||
|
||||
onMounted(() => {
|
||||
loadConfig();
|
||||
loadStatus(true);
|
||||
});
|
||||
|
||||
onUnmounted(stopPolling);
|
||||
</script>
|
||||
Reference in new issue
Block a user