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
@@ -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