Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2f2e8f255 | ||
| 5cfafa88cf | |||
| 656917c776 | |||
| 90fd395a26 | |||
| 35cfcb1bcf | |||
| 92ed9b040f | |||
| e52fbaf799 | |||
| 00dc2daa3d | |||
| 7643600196 | |||
| b6375b4242 | |||
| 9393abc8df | |||
| b3fc6f77b1 | |||
| 47bc8ba966 | |||
| 31e101abbd | |||
|
|
126d6b505a | ||
| c758c4d904 | |||
| ffe463e130 | |||
|
|
a8447d6ee1 | ||
| 91d429c4dd | |||
| 505ebd9325 | |||
| d0e39c92b2 | |||
|
|
8bd78a610f | ||
| 975b0f9718 | |||
| 889d723e81 | |||
| 4757c766f6 | |||
| acee6d471c |
8
.env.example
Normal file
8
.env.example
Normal file
@@ -0,0 +1,8 @@
|
||||
API_SECRET_KEY=
|
||||
DISCORD_BOT_TOKEN=
|
||||
DISCORD_CHANNEL_ID=
|
||||
BACKUPS_REMOTE_HOST=
|
||||
BACKUPS_REMOTE_ROOT=
|
||||
BACKUPS_MAX_FILES=
|
||||
DISK_COMMAND_REMOTE=
|
||||
DISK_COMMAND_LOCAL=
|
||||
30
CHANGELOG.md
30
CHANGELOG.md
@@ -1,3 +1,33 @@
|
||||
# [1.3.0](https://gitea.malio.fr/MALIO-DEV/Supervisor/compare/v1.2.4...v1.3.0) (2026-03-13)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add system metrics dashboard ([31e101a](https://gitea.malio.fr/MALIO-DEV/Supervisor/commit/31e101abbd3ed82c22770d840a4f7fd20de1c936))
|
||||
|
||||
## [1.2.4](https://gitea.malio.fr/MALIO-DEV/Supervisor/compare/v1.2.3...v1.2.4) (2026-03-10)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* bundle latest backup downloads ([ffe463e](https://gitea.malio.fr/MALIO-DEV/Supervisor/commit/ffe463e13034601843446514abbd7c69cbaee081))
|
||||
|
||||
## [1.2.3](https://gitea.malio.fr/MALIO-DEV/Supervisor/compare/v1.2.2...v1.2.3) (2026-03-10)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* add scroll to backup history ([505ebd9](https://gitea.malio.fr/MALIO-DEV/Supervisor/commit/505ebd9325c0aa54adb034c012c45c913bb36d73))
|
||||
* restore backup history listing ([d0e39c9](https://gitea.malio.fr/MALIO-DEV/Supervisor/commit/d0e39c92b270993c99cde0eed8577c6dde817fdd))
|
||||
|
||||
## [1.2.2](https://gitea.malio.fr/MALIO-DEV/Supervisor/compare/v1.2.1...v1.2.2) (2026-03-10)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* align backup ui and downloads ([4757c76](https://gitea.malio.fr/MALIO-DEV/Supervisor/commit/4757c766f613a1888b62716a2c6852c8d92e3f6e))
|
||||
* ssh connection correctif ([acee6d4](https://gitea.malio.fr/MALIO-DEV/Supervisor/commit/acee6d471c63671bfb9bdef62a3b6e2ebe40ba55))
|
||||
|
||||
## [1.2.1](https://gitea.malio.fr/MALIO-DEV/Supervisor/compare/v1.2.0...v1.2.1) (2026-03-10)
|
||||
|
||||
|
||||
|
||||
@@ -22,6 +22,13 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else-if="errorMessage" class="empty-state error-state">
|
||||
<IconifyIcon icon="mdi:alert-circle-outline" class="text-3xl text-m-error/70" />
|
||||
<p class="mt-2 font-mono text-xs text-m-error/80">
|
||||
{{ errorMessage }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div v-else-if="backups.length === 0" class="empty-state">
|
||||
<IconifyIcon icon="mdi:file-hidden" class="text-3xl text-m-muted/40" />
|
||||
<p class="mt-2 font-mono text-xs text-m-muted/50">
|
||||
@@ -55,6 +62,7 @@
|
||||
import {Icon as IconifyIcon} from "@iconify/vue"
|
||||
import CircleSkeleton from "~/components/skeleton/CircleSkeleton.vue"
|
||||
import TextSkeleton from "~/components/skeleton/TextSkeleton.vue"
|
||||
import { apiFetch, downloadApiFile } from "~/composables/useApiAuth"
|
||||
|
||||
const props = defineProps<{
|
||||
folder: string | null
|
||||
@@ -62,31 +70,42 @@ const props = defineProps<{
|
||||
|
||||
const backups = ref<string[]>([])
|
||||
const loading = ref(false)
|
||||
const errorMessage = ref("")
|
||||
const title = computed(() => {
|
||||
if (!props.folder) return "Fichiers"
|
||||
return `Backup — ${props.folder.toUpperCase()}`
|
||||
})
|
||||
|
||||
const downloadBackup = (file: string) => {
|
||||
const downloadBackup = async (file: string) => {
|
||||
if (!props.folder) return
|
||||
const url = `/api/download?folder=${encodeURIComponent(props.folder)}&file=${encodeURIComponent(file)}`
|
||||
window.location.href = url
|
||||
errorMessage.value = ""
|
||||
|
||||
try {
|
||||
await downloadApiFile(url, file)
|
||||
} catch (error) {
|
||||
console.error("Erreur telechargement backup:", error)
|
||||
errorMessage.value = "Erreur lors de l'opération"
|
||||
}
|
||||
}
|
||||
|
||||
watch(() => props.folder, async (folder) => {
|
||||
if (!folder) {
|
||||
loading.value = false
|
||||
backups.value = []
|
||||
errorMessage.value = ""
|
||||
return
|
||||
}
|
||||
|
||||
loading.value = true
|
||||
errorMessage.value = ""
|
||||
try {
|
||||
const data = await $fetch<string[]>(`/api/backups?folder=${folder}`)
|
||||
backups.value = data.slice(0, 6)
|
||||
const data = await apiFetch<string[]>(`/api/backups?folder=${encodeURIComponent(folder)}`)
|
||||
backups.value = data
|
||||
} catch (error) {
|
||||
console.error("Erreur récupération backups:", error)
|
||||
backups.value = []
|
||||
errorMessage.value = "Erreur lors de l'opération"
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
@@ -120,10 +139,19 @@ watch(() => props.folder, async (folder) => {
|
||||
padding: 2.5rem 1rem;
|
||||
}
|
||||
|
||||
.error-state {
|
||||
border-radius: 8px;
|
||||
border: 1px solid rgb(var(--m-error) / 0.12);
|
||||
background: rgb(var(--m-error) / 0.06);
|
||||
}
|
||||
|
||||
.file-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.375rem;
|
||||
max-height: calc((2.875rem * 5) + (0.375rem * 4));
|
||||
overflow-y: auto;
|
||||
padding-right: 0.25rem;
|
||||
}
|
||||
|
||||
.file-row {
|
||||
|
||||
@@ -1,15 +1,31 @@
|
||||
<template>
|
||||
<div class="backup-card card-glow">
|
||||
<div
|
||||
class="backup-card card-glow"
|
||||
:class="{
|
||||
'card-glow-success': message && !isError,
|
||||
'card-glow-error': message && isError
|
||||
}"
|
||||
>
|
||||
<div class="card-header">
|
||||
<h2 class="card-title">Run Script</h2>
|
||||
<span class="font-mono text-[10px] text-m-muted tracking-widest uppercase">Scripts</span>
|
||||
</div>
|
||||
|
||||
<div v-if="loading" class="status-box">
|
||||
<div
|
||||
v-if="loading"
|
||||
class="status-box"
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
aria-busy="true"
|
||||
>
|
||||
Chargement des scripts...
|
||||
</div>
|
||||
|
||||
<div v-else class="backup-list">
|
||||
<div
|
||||
v-else-if="scripts.length"
|
||||
class="backup-list"
|
||||
:aria-busy="runningKey !== null"
|
||||
>
|
||||
<button
|
||||
v-for="item in scripts"
|
||||
:key="item.key"
|
||||
@@ -17,6 +33,8 @@
|
||||
class="backup-btn"
|
||||
:class="{ 'backup-btn-active': active === item.key }"
|
||||
:disabled="runningKey !== null"
|
||||
:aria-pressed="active === item.key"
|
||||
:aria-label="`Executer ${item.label}`"
|
||||
@click="runScript(item.key)"
|
||||
>
|
||||
<div class="flex items-center gap-2.5">
|
||||
@@ -36,21 +54,39 @@
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="message" class="status-box" :class="statusClass">
|
||||
<p class="status-title">{{ message }}</p>
|
||||
<pre v-if="output" class="status-output">{{ output }}</pre>
|
||||
<div
|
||||
v-else
|
||||
class="status-box status-empty"
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
>
|
||||
Aucun script disponible.
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="message"
|
||||
class="status-box"
|
||||
:class="statusClass"
|
||||
role="status"
|
||||
:aria-live="isError ? 'assertive' : 'polite'"
|
||||
>
|
||||
<p class="status-title">{{ message }}</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue"
|
||||
import { Icon as IconifyIcon } from "@iconify/vue"
|
||||
import { apiFetch } from "~/composables/useApiAuth"
|
||||
import { useApiAuthHeader } from "~/composables/useApiAuth"
|
||||
|
||||
type BackupScript = {
|
||||
key: string
|
||||
label: string
|
||||
icon: string
|
||||
downloadFolders?: string[]
|
||||
}
|
||||
|
||||
type BackupScriptListResponse = {
|
||||
@@ -61,27 +97,59 @@ type BackupScriptRunResponse = {
|
||||
ok: boolean
|
||||
key: string
|
||||
label: string
|
||||
downloadFolders?: string[]
|
||||
output: string
|
||||
}
|
||||
|
||||
type ScriptResult = {
|
||||
key: string | null
|
||||
label: string
|
||||
output: string
|
||||
isError: boolean
|
||||
downloadFolders: string[]
|
||||
}
|
||||
|
||||
const emit = defineEmits<{
|
||||
result: [payload: ScriptResult]
|
||||
}>()
|
||||
|
||||
const active = ref<string | null>(null)
|
||||
const loading = ref(true)
|
||||
const runningKey = ref<string | null>(null)
|
||||
const scripts = ref<BackupScript[]>([])
|
||||
const output = ref("")
|
||||
const message = ref("")
|
||||
const output = ref<string>("")
|
||||
const message = ref<string>("")
|
||||
const isError = ref(false)
|
||||
const apiAuthHeader = useApiAuthHeader()
|
||||
|
||||
const statusClass = computed(() => (isError.value ? "status-error" : "status-success"))
|
||||
|
||||
const loadScripts = async () => {
|
||||
loading.value = true
|
||||
message.value = ""
|
||||
output.value = ""
|
||||
isError.value = false
|
||||
emit("result", {
|
||||
key: null,
|
||||
label: "",
|
||||
output: "",
|
||||
isError: false,
|
||||
downloadFolders: []
|
||||
})
|
||||
try {
|
||||
const data = await $fetch<BackupScriptListResponse>("/api/backup-script")
|
||||
const data = await apiFetch<BackupScriptListResponse>("/api/backup-script")
|
||||
scripts.value = data.scripts
|
||||
} catch (error) {
|
||||
} catch {
|
||||
scripts.value = []
|
||||
isError.value = true
|
||||
message.value = `Erreur chargement scripts: ${error instanceof Error ? error.message : String(error)}`
|
||||
message.value = "Erreur lors de l'opération"
|
||||
emit("result", {
|
||||
key: null,
|
||||
label: "",
|
||||
output: "",
|
||||
isError: true,
|
||||
downloadFolders: []
|
||||
})
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
@@ -95,16 +163,42 @@ const runScript = async (key: string) => {
|
||||
isError.value = false
|
||||
|
||||
try {
|
||||
const data = await $fetch<BackupScriptRunResponse>("/api/backup-script", {
|
||||
const data = await apiFetch<BackupScriptRunResponse>("/api/backup-script", {
|
||||
method: "POST",
|
||||
body: { key }
|
||||
})
|
||||
message.value = `${data.label} execute`
|
||||
output.value = data.output
|
||||
} catch (error: any) {
|
||||
message.value = `${data.label} execute avec succes`
|
||||
output.value = data.output || "Aucune sortie retournee."
|
||||
emit("result", {
|
||||
key: data.key,
|
||||
label: data.label,
|
||||
output: output.value,
|
||||
isError: false,
|
||||
downloadFolders: data.downloadFolders || []
|
||||
})
|
||||
} catch (error: unknown) {
|
||||
isError.value = true
|
||||
const statusMessage =
|
||||
typeof error === "object" &&
|
||||
error !== null &&
|
||||
"data" in error &&
|
||||
typeof error.data === "object" &&
|
||||
error.data !== null &&
|
||||
"statusMessage" in error.data &&
|
||||
typeof error.data.statusMessage === "string"
|
||||
? error.data.statusMessage
|
||||
: null
|
||||
|
||||
message.value = statusMessage || "Erreur lors de l'opération"
|
||||
message.value = error?.data?.statusMessage || "Erreur execution script"
|
||||
output.value = ""
|
||||
emit("result", {
|
||||
key,
|
||||
label: scripts.value.find((item) => item.key === key)?.label || key,
|
||||
output: "",
|
||||
isError: true,
|
||||
downloadFolders: []
|
||||
})
|
||||
} finally {
|
||||
runningKey.value = null
|
||||
}
|
||||
@@ -154,6 +248,11 @@ onMounted(loadScripts)
|
||||
color: rgb(var(--m-text));
|
||||
}
|
||||
|
||||
.backup-btn:focus-visible {
|
||||
outline: 2px solid rgb(var(--m-accent) / 0.7);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.backup-btn:disabled {
|
||||
cursor: wait;
|
||||
opacity: 0.7;
|
||||
@@ -188,14 +287,12 @@ onMounted(loadScripts)
|
||||
border: 1px solid rgb(255 99 99 / 0.3);
|
||||
}
|
||||
|
||||
.status-title {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.status-output {
|
||||
margin: 0.75rem 0 0;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
.status-empty {
|
||||
color: rgb(var(--m-muted));
|
||||
}
|
||||
|
||||
.status-title {
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
<script setup>
|
||||
import {Icon as IconifyIcon} from "@iconify/vue"
|
||||
const { data: messages } = await useFetch('/api/discord/messages')
|
||||
import { apiFetch } from "~/composables/useApiAuth"
|
||||
|
||||
const { data: messages, error } = await useFetch('/api/discord/messages', {
|
||||
$fetch: apiFetch,
|
||||
server: false
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -13,7 +18,14 @@ const { data: messages } = await useFetch('/api/discord/messages')
|
||||
<span class="font-mono text-[10px] text-m-muted tracking-widest uppercase">Messages</span>
|
||||
</div>
|
||||
|
||||
<div v-if="!messages || messages.length === 0" class="empty-state">
|
||||
<div v-if="error" class="empty-state error-state">
|
||||
<IconifyIcon icon="mdi:alert-circle-outline" class="text-3xl text-m-error/70" />
|
||||
<p class="mt-2 font-mono text-xs text-m-error/80">
|
||||
Erreur lors de l'opération
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div v-else-if="!messages || messages.length === 0" class="empty-state">
|
||||
<IconifyIcon icon="mdi:chat-outline" class="text-3xl text-m-muted/40" />
|
||||
<p class="mt-2 font-mono text-xs text-m-muted/50">
|
||||
Aucun message
|
||||
@@ -74,6 +86,12 @@ const { data: messages } = await useFetch('/api/discord/messages')
|
||||
padding: 2rem 1rem;
|
||||
}
|
||||
|
||||
.error-state {
|
||||
border-radius: 8px;
|
||||
border: 1px solid rgb(var(--m-error) / 0.12);
|
||||
background: rgb(var(--m-error) / 0.06);
|
||||
}
|
||||
|
||||
.message-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
<h2 class="card-title">Speedtest</h2>
|
||||
<button
|
||||
class="reload-btn"
|
||||
@click="runTests"
|
||||
:disabled="isTesting"
|
||||
@click="runTests"
|
||||
>
|
||||
<IconifyIcon
|
||||
icon="mdi:reload"
|
||||
@@ -36,17 +36,23 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p v-if="errorMessage" class="error-text" role="status" aria-live="polite">
|
||||
{{ errorMessage }}
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import {computed, ref} from "vue"
|
||||
import {Icon as IconifyIcon} from "@iconify/vue"
|
||||
import { apiRequest } from "~/composables/useApiAuth"
|
||||
|
||||
const ping = ref<number | null>(null)
|
||||
const download = ref<number | null>(null)
|
||||
const upload = ref<number | null>(null)
|
||||
const isTesting = ref(false)
|
||||
const errorMessage = ref("")
|
||||
|
||||
const metrics = computed(() => [
|
||||
{ label: "Download", icon: "mdi:arrow-down-bold", value: download.value, unit: "Mbps" },
|
||||
@@ -56,7 +62,10 @@ const metrics = computed(() => [
|
||||
|
||||
async function testDownload() {
|
||||
const start = performance.now()
|
||||
const res = await fetch('/api/download')
|
||||
const res = await apiRequest('/api/download')
|
||||
if (!res.ok) {
|
||||
throw new Error(`HTTP ${res.status}`)
|
||||
}
|
||||
const blob = await res.blob()
|
||||
const end = performance.now()
|
||||
const size = blob.size
|
||||
@@ -68,7 +77,10 @@ async function testUpload() {
|
||||
const size = 5 * 1024 * 1024
|
||||
const data = new Uint8Array(size)
|
||||
const start = performance.now()
|
||||
await fetch('/api/upload', { method: 'POST', body: data })
|
||||
const response = await apiRequest('/api/upload', { method: 'POST', body: data })
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`)
|
||||
}
|
||||
const end = performance.now()
|
||||
const seconds = (end - start) / 1000
|
||||
upload.value = Math.round((size * 8) / seconds / 1000000)
|
||||
@@ -76,7 +88,10 @@ async function testUpload() {
|
||||
|
||||
async function testPing() {
|
||||
const start = performance.now()
|
||||
await fetch('/api/ping')
|
||||
const response = await fetch('/api/ping')
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`)
|
||||
}
|
||||
const end = performance.now()
|
||||
ping.value = Math.round(end - start)
|
||||
}
|
||||
@@ -86,11 +101,15 @@ async function runTests() {
|
||||
download.value = null
|
||||
upload.value = null
|
||||
ping.value = null
|
||||
errorMessage.value = ""
|
||||
|
||||
try {
|
||||
await testDownload()
|
||||
await testUpload()
|
||||
await testPing()
|
||||
} catch (error) {
|
||||
console.error("Erreur speedtest:", error)
|
||||
errorMessage.value = "Erreur lors de l'opération"
|
||||
} finally {
|
||||
isTesting.value = false
|
||||
}
|
||||
@@ -189,4 +208,15 @@ async function runTests() {
|
||||
letter-spacing: 0.1em;
|
||||
color: rgb(var(--m-muted));
|
||||
}
|
||||
|
||||
.error-text {
|
||||
margin-top: 0.75rem;
|
||||
border-radius: 8px;
|
||||
border: 1px solid rgb(var(--m-error) / 0.12);
|
||||
background: rgb(var(--m-error) / 0.06);
|
||||
padding: 0.75rem 0.875rem;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.75rem;
|
||||
color: rgb(var(--m-error));
|
||||
}
|
||||
</style>
|
||||
@@ -20,8 +20,8 @@
|
||||
</template>
|
||||
|
||||
<div
|
||||
v-else
|
||||
v-for="row in rows"
|
||||
v-else
|
||||
:key="`${row.label}-${row.url}`"
|
||||
class="status-row"
|
||||
:class="row.status === 200 ? 'row-ok' : 'row-error'"
|
||||
@@ -43,6 +43,7 @@
|
||||
import CircleSkeleton from "~/components/skeleton/CircleSkeleton.vue"
|
||||
import TextSkeleton from "~/components/skeleton/TextSkeleton.vue"
|
||||
import {onBeforeUnmount, onMounted, ref} from "vue"
|
||||
import { apiFetch } from "~/composables/useApiAuth"
|
||||
|
||||
interface StatusRow {
|
||||
label: string
|
||||
@@ -84,7 +85,7 @@ const checkStatus = async () => {
|
||||
loading.value = true
|
||||
}
|
||||
try {
|
||||
const data = await $fetch<StatusResponse>(props.endpoint)
|
||||
const data = await apiFetch<StatusResponse>(props.endpoint)
|
||||
rows.value = data.results
|
||||
} catch (error) {
|
||||
rows.value = [
|
||||
|
||||
333
components/SystemMetricsChart.vue
Normal file
333
components/SystemMetricsChart.vue
Normal file
@@ -0,0 +1,333 @@
|
||||
<template>
|
||||
<section class="chart-card card-glow">
|
||||
<div class="card-header">
|
||||
<div>
|
||||
<h2 class="card-title">Historique systeme</h2>
|
||||
<p class="card-copy">CPU, RAM et debit reseau sur les derniers releves</p>
|
||||
</div>
|
||||
|
||||
<div class="toggle-group" role="radiogroup" aria-label="Metrique affichee">
|
||||
<label
|
||||
v-for="option in options"
|
||||
:key="option.value"
|
||||
class="toggle-pill"
|
||||
:class="{ 'toggle-pill-active': selectedMetric === option.value }"
|
||||
>
|
||||
<input
|
||||
v-model="selectedMetric"
|
||||
type="radio"
|
||||
name="system-metric"
|
||||
class="sr-only"
|
||||
:value="option.value"
|
||||
>
|
||||
<span class="toggle-dot" :style="{ backgroundColor: option.color }" />
|
||||
<span>{{ option.label }}</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="chart-shell">
|
||||
<template v-if="loading && points.length === 0">
|
||||
<div class="chart-skeleton animate-shimmer" />
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="chart-meta">
|
||||
<div>
|
||||
<span class="meta-label">Actuel</span>
|
||||
<strong class="meta-value" :style="{ color: activeOption.color }">{{ formattedCurrentValue }}</strong>
|
||||
</div>
|
||||
<div>
|
||||
<span class="meta-label">Pic</span>
|
||||
<strong class="meta-value">{{ formattedPeakValue }}</strong>
|
||||
</div>
|
||||
<div>
|
||||
<span class="meta-label">Echelle</span>
|
||||
<strong class="meta-value">{{ scaleLabel }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<svg
|
||||
class="chart-svg"
|
||||
viewBox="0 0 960 320"
|
||||
preserveAspectRatio="none"
|
||||
aria-label="Graphique des ressources"
|
||||
>
|
||||
<line
|
||||
v-for="line in gridLines"
|
||||
:key="line"
|
||||
x1="0"
|
||||
:y1="line"
|
||||
x2="960"
|
||||
:y2="line"
|
||||
class="grid-line"
|
||||
/>
|
||||
<polyline
|
||||
:points="polylinePoints"
|
||||
class="chart-line"
|
||||
:style="{ stroke: activeOption.color }"
|
||||
/>
|
||||
</svg>
|
||||
</template>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import {computed, ref, watch} from "vue"
|
||||
|
||||
type MetricKey = "cpu" | "ram" | "incoming" | "outgoing"
|
||||
|
||||
type SystemMetrics = {
|
||||
cpuPercent: number
|
||||
memoryPercent: number
|
||||
totalMemory: number
|
||||
usedMemory: number
|
||||
incomingMbps: number
|
||||
outgoingMbps: number
|
||||
sampledAt: string
|
||||
}
|
||||
|
||||
type HistoryPoint = {
|
||||
sampledAt: string
|
||||
cpu: number
|
||||
ram: number
|
||||
incoming: number
|
||||
outgoing: number
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
metrics: SystemMetrics | null
|
||||
loading: boolean
|
||||
}>()
|
||||
|
||||
const selectedMetric = ref<MetricKey>("ram")
|
||||
const history = ref<HistoryPoint[]>([])
|
||||
const maxPoints = 40
|
||||
|
||||
const options: Array<{value: MetricKey; label: string; color: string}> = [
|
||||
{value: "cpu", label: "CPU", color: "#5aa9ff"},
|
||||
{value: "ram", label: "RAM", color: "#31c48d"},
|
||||
{value: "incoming", label: "Entrant", color: "#f59e0b"},
|
||||
{value: "outgoing", label: "Sortant", color: "#ef4444"}
|
||||
]
|
||||
|
||||
watch(
|
||||
() => props.metrics?.sampledAt,
|
||||
() => {
|
||||
if (!props.metrics) {
|
||||
return
|
||||
}
|
||||
|
||||
history.value = [
|
||||
...history.value,
|
||||
{
|
||||
sampledAt: props.metrics.sampledAt,
|
||||
cpu: props.metrics.cpuPercent,
|
||||
ram: props.metrics.memoryPercent,
|
||||
incoming: props.metrics.incomingMbps,
|
||||
outgoing: props.metrics.outgoingMbps
|
||||
}
|
||||
].slice(-maxPoints)
|
||||
},
|
||||
{immediate: true}
|
||||
)
|
||||
|
||||
const activeOption = computed(() => {
|
||||
return options.find((option) => option.value === selectedMetric.value) || options[0]
|
||||
})
|
||||
|
||||
const points = computed(() => history.value.map((point) => point[selectedMetric.value]))
|
||||
|
||||
const peakValue = computed(() => {
|
||||
return points.value.reduce((max, value) => Math.max(max, value), 0)
|
||||
})
|
||||
|
||||
const scaleMax = computed(() => {
|
||||
if (selectedMetric.value === "cpu" || selectedMetric.value === "ram") {
|
||||
return 100
|
||||
}
|
||||
|
||||
return Math.max(1, Math.ceil(peakValue.value))
|
||||
})
|
||||
|
||||
const formatValue = (value: number, metric: MetricKey) => {
|
||||
if (metric === "cpu" || metric === "ram") {
|
||||
return `${Math.round(value)}%`
|
||||
}
|
||||
|
||||
return `${value.toFixed(2)} Mbps`
|
||||
}
|
||||
|
||||
const formattedCurrentValue = computed(() => {
|
||||
const currentValue = points.value.at(-1) ?? 0
|
||||
return formatValue(currentValue, selectedMetric.value)
|
||||
})
|
||||
|
||||
const formattedPeakValue = computed(() => {
|
||||
return formatValue(peakValue.value, selectedMetric.value)
|
||||
})
|
||||
|
||||
const scaleLabel = computed(() => {
|
||||
return formatValue(scaleMax.value, selectedMetric.value)
|
||||
})
|
||||
|
||||
const gridLines = [40, 120, 200, 280]
|
||||
|
||||
const polylinePoints = computed(() => {
|
||||
if (points.value.length === 0) {
|
||||
return "0,280"
|
||||
}
|
||||
|
||||
if (points.value.length === 1) {
|
||||
const normalizedValue = points.value[0] / scaleMax.value
|
||||
const y = 280 - normalizedValue * 240
|
||||
return `0,${y} 960,${y}`
|
||||
}
|
||||
|
||||
return points.value
|
||||
.map((value, index) => {
|
||||
const x = (index / (points.value.length - 1)) * 960
|
||||
const normalizedValue = scaleMax.value > 0 ? value / scaleMax.value : 0
|
||||
const y = 280 - normalizedValue * 240
|
||||
|
||||
return `${x},${Math.max(24, Math.min(280, y))}`
|
||||
})
|
||||
.join(" ")
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.chart-card {
|
||||
margin-top: 1.5rem;
|
||||
background: rgb(var(--m-secondary));
|
||||
border-radius: 12px;
|
||||
padding: 1.25rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.card-header {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.card-title {
|
||||
font-family: var(--font-display);
|
||||
font-size: 1.25rem;
|
||||
font-weight: 700;
|
||||
color: rgb(var(--m-text));
|
||||
}
|
||||
|
||||
.card-copy {
|
||||
margin-top: 0.25rem;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.75rem;
|
||||
color: rgb(var(--m-muted));
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.12em;
|
||||
}
|
||||
|
||||
.toggle-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.625rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.toggle-pill {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
border-radius: 999px;
|
||||
border: 1px solid rgb(var(--m-accent) / 0.1);
|
||||
background: rgb(var(--m-tertiary));
|
||||
padding: 0.55rem 0.8rem;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.72rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.12em;
|
||||
color: rgb(var(--m-muted));
|
||||
cursor: pointer;
|
||||
transition: border-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
|
||||
}
|
||||
|
||||
.toggle-pill-active {
|
||||
border-color: rgb(var(--m-accent) / 0.28);
|
||||
color: rgb(var(--m-text));
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.toggle-dot {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 999px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.chart-shell {
|
||||
border-radius: 12px;
|
||||
padding: 1rem;
|
||||
background:
|
||||
linear-gradient(180deg, rgb(var(--m-tertiary)) 0%, rgb(var(--m-secondary)) 100%);
|
||||
border: 1px solid rgb(var(--m-accent) / 0.08);
|
||||
}
|
||||
|
||||
.chart-meta {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 0.75rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.meta-label {
|
||||
display: block;
|
||||
margin-bottom: 0.25rem;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.68rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.14em;
|
||||
color: rgb(var(--m-muted));
|
||||
}
|
||||
|
||||
.meta-value {
|
||||
font-family: var(--font-display);
|
||||
font-size: 1.1rem;
|
||||
font-weight: 700;
|
||||
color: rgb(var(--m-text));
|
||||
}
|
||||
|
||||
.chart-svg {
|
||||
width: 100%;
|
||||
height: 320px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.grid-line {
|
||||
stroke: rgb(var(--m-border) / 0.35);
|
||||
stroke-width: 1;
|
||||
stroke-dasharray: 6 10;
|
||||
}
|
||||
|
||||
.chart-line {
|
||||
fill: none;
|
||||
stroke-width: 4;
|
||||
stroke-linecap: round;
|
||||
stroke-linejoin: round;
|
||||
}
|
||||
|
||||
.chart-skeleton {
|
||||
width: 100%;
|
||||
height: 320px;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
@media (max-width: 820px) {
|
||||
.chart-meta {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
199
components/SystemResources.vue
Normal file
199
components/SystemResources.vue
Normal file
@@ -0,0 +1,199 @@
|
||||
<template>
|
||||
<div class="resources-card card-glow">
|
||||
<div class="card-header">
|
||||
<h2 class="card-title">Ressources</h2>
|
||||
<span class="font-mono text-[10px] uppercase tracking-widest text-m-muted">CPU / RAM</span>
|
||||
</div>
|
||||
|
||||
<div class="metrics-list">
|
||||
<div
|
||||
v-for="metric in metrics"
|
||||
:key="metric.label"
|
||||
class="metric-row"
|
||||
>
|
||||
<div class="metric-copy">
|
||||
<div class="metric-head">
|
||||
<span class="font-display text-sm font-semibold text-m-text">{{ metric.label }}</span>
|
||||
<span class="font-mono text-xs text-m-muted">{{ metric.detail }}</span>
|
||||
</div>
|
||||
|
||||
<template v-if="isLoading">
|
||||
<div class="metric-skeleton animate-shimmer" />
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="metric-bar">
|
||||
<div
|
||||
class="metric-bar-fill"
|
||||
:class="metric.toneClass"
|
||||
:style="{ width: `${metric.percent}%` }"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<div class="metric-value-area">
|
||||
<template v-if="isLoading">
|
||||
<div class="value-skeleton animate-shimmer" />
|
||||
</template>
|
||||
<template v-else>
|
||||
<span class="metric-value font-mono">{{ metric.percent }}%</span>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import {computed} from "vue"
|
||||
|
||||
type SystemMetrics = {
|
||||
cpuPercent: number
|
||||
memoryPercent: number
|
||||
totalMemory: number
|
||||
usedMemory: number
|
||||
incomingMbps: number
|
||||
outgoingMbps: number
|
||||
sampledAt: string
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
metrics: SystemMetrics | null
|
||||
loading: boolean
|
||||
}>()
|
||||
|
||||
const formatMemory = (value: number) => {
|
||||
if (!Number.isFinite(value) || value <= 0) {
|
||||
return "0 GB"
|
||||
}
|
||||
|
||||
return `${(value / 1024 / 1024 / 1024).toFixed(1)} GB`
|
||||
}
|
||||
|
||||
const toneClass = (percent: number) => {
|
||||
if (percent >= 85) return "tone-error"
|
||||
if (percent >= 65) return "tone-warning"
|
||||
return "tone-success"
|
||||
}
|
||||
|
||||
const isLoading = computed(() => props.loading || !props.metrics)
|
||||
|
||||
const metrics = computed(() => [
|
||||
{
|
||||
label: "CPU",
|
||||
percent: props.metrics?.cpuPercent ?? 0,
|
||||
detail: "Charge instantanee",
|
||||
toneClass: toneClass(props.metrics?.cpuPercent ?? 0)
|
||||
},
|
||||
{
|
||||
label: "RAM",
|
||||
percent: props.metrics?.memoryPercent ?? 0,
|
||||
detail: `${formatMemory(props.metrics?.usedMemory ?? 0)} / ${formatMemory(props.metrics?.totalMemory ?? 0)}`,
|
||||
toneClass: toneClass(props.metrics?.memoryPercent ?? 0)
|
||||
}
|
||||
])
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.resources-card {
|
||||
background: rgb(var(--m-secondary));
|
||||
border-radius: 12px;
|
||||
padding: 1.25rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
transition: background-color 0.4s ease;
|
||||
}
|
||||
|
||||
.card-header {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.card-title {
|
||||
font-family: var(--font-display);
|
||||
font-size: 1.25rem;
|
||||
font-weight: 700;
|
||||
color: rgb(var(--m-text));
|
||||
}
|
||||
|
||||
.metrics-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.875rem;
|
||||
}
|
||||
|
||||
.metric-row {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) auto;
|
||||
gap: 0.75rem;
|
||||
align-items: center;
|
||||
padding: 0.875rem 1rem;
|
||||
border-radius: 10px;
|
||||
background: rgb(var(--m-tertiary));
|
||||
border: 1px solid rgb(var(--m-accent) / 0.06);
|
||||
}
|
||||
|
||||
.metric-copy {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.metric-head {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
gap: 0.75rem;
|
||||
margin-bottom: 0.625rem;
|
||||
}
|
||||
|
||||
.metric-bar {
|
||||
height: 10px;
|
||||
border-radius: 999px;
|
||||
overflow: hidden;
|
||||
background: rgb(var(--m-bg) / 0.45);
|
||||
}
|
||||
|
||||
.metric-bar-fill {
|
||||
height: 100%;
|
||||
border-radius: inherit;
|
||||
transition: width 0.35s ease, background-color 0.35s ease;
|
||||
}
|
||||
|
||||
.metric-value-area {
|
||||
min-width: 54px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.metric-value {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 700;
|
||||
color: rgb(var(--m-text));
|
||||
}
|
||||
|
||||
.metric-skeleton {
|
||||
height: 10px;
|
||||
width: 100%;
|
||||
border-radius: 999px;
|
||||
}
|
||||
|
||||
.value-skeleton {
|
||||
width: 48px;
|
||||
height: 28px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.tone-success {
|
||||
background: rgb(var(--m-success));
|
||||
}
|
||||
|
||||
.tone-warning {
|
||||
background: rgb(var(--m-warning));
|
||||
}
|
||||
|
||||
.tone-error {
|
||||
background: rgb(var(--m-error));
|
||||
}
|
||||
</style>
|
||||
90
composables/useApiAuth.ts
Normal file
90
composables/useApiAuth.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
function toHeadersObject(headers?: HeadersInit): Record<string, string> {
|
||||
if (!headers) {
|
||||
return {}
|
||||
}
|
||||
|
||||
if (headers instanceof Headers) {
|
||||
return Object.fromEntries(headers.entries())
|
||||
}
|
||||
|
||||
if (Array.isArray(headers)) {
|
||||
return Object.fromEntries(headers)
|
||||
}
|
||||
|
||||
return { ...headers }
|
||||
}
|
||||
|
||||
function getDownloadFileName(contentDisposition: string | null, fallback: string) {
|
||||
if (!contentDisposition) {
|
||||
return fallback
|
||||
}
|
||||
|
||||
const utf8Match = contentDisposition.match(/filename\*=UTF-8''([^;]+)/i)
|
||||
if (utf8Match?.[1]) {
|
||||
return decodeURIComponent(utf8Match[1])
|
||||
}
|
||||
|
||||
const asciiMatch = contentDisposition.match(/filename="([^"]+)"/i)
|
||||
if (asciiMatch?.[1]) {
|
||||
return asciiMatch[1]
|
||||
}
|
||||
|
||||
return fallback
|
||||
}
|
||||
|
||||
export function useApiAuthHeader() {
|
||||
const runtimeConfig = useRuntimeConfig()
|
||||
const token = runtimeConfig.public.apiSecretKey
|
||||
|
||||
if (!token) {
|
||||
return {}
|
||||
}
|
||||
|
||||
// Tous les appels frontend vers /api/* reutilisent ce header commun.
|
||||
return {
|
||||
Authorization: `Bearer ${token}`
|
||||
}
|
||||
}
|
||||
|
||||
export const apiFetch = $fetch.create({})
|
||||
|
||||
export function apiRequest(input: RequestInfo | URL, init: RequestInit = {}) {
|
||||
return fetch(input, withApiAuth(init))
|
||||
}
|
||||
|
||||
export async function downloadApiFile(url: string, fileNameFallback: string) {
|
||||
// Les telechargements passent aussi par fetch pour pouvoir recuperer
|
||||
// le contenu et le nom de fichier renvoye par l'API.
|
||||
const response = await apiRequest(url)
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`)
|
||||
}
|
||||
|
||||
const blob = await response.blob()
|
||||
const objectUrl = URL.createObjectURL(blob)
|
||||
const fileName = getDownloadFileName(
|
||||
response.headers.get("content-disposition"),
|
||||
fileNameFallback
|
||||
)
|
||||
const link = document.createElement("a")
|
||||
|
||||
link.href = objectUrl
|
||||
link.download = fileName
|
||||
link.style.display = "none"
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
link.remove()
|
||||
URL.revokeObjectURL(objectUrl)
|
||||
}
|
||||
|
||||
export function withApiAuth(init: RequestInit = {}) {
|
||||
// Fusionne le header d'auth avec d'eventuels headers deja fournis.
|
||||
return {
|
||||
...init,
|
||||
headers: {
|
||||
...useApiAuthHeader(),
|
||||
...toHeadersObject(init.headers)
|
||||
}
|
||||
}
|
||||
}
|
||||
3
eslint.config.mjs
Normal file
3
eslint.config.mjs
Normal file
@@ -0,0 +1,3 @@
|
||||
import createConfigForNuxt from "@nuxt/eslint-config"
|
||||
|
||||
export default createConfigForNuxt()
|
||||
@@ -7,7 +7,7 @@
|
||||
:src="logoSrc"
|
||||
alt="Logo Malio"
|
||||
class="logo"
|
||||
/>
|
||||
>
|
||||
</div>
|
||||
<div class="brand-copy">
|
||||
<p class="brand-title">Supervisor</p>
|
||||
@@ -67,7 +67,7 @@
|
||||
:src="logoSrc"
|
||||
alt="Logo Malio"
|
||||
class="logo"
|
||||
/>
|
||||
>
|
||||
</div>
|
||||
<div class="brand-copy">
|
||||
<p class="brand-kicker">Control Center</p>
|
||||
|
||||
@@ -26,7 +26,7 @@ export default defineNuxtConfig({
|
||||
head: {
|
||||
link: [
|
||||
{ rel: "preconnect", href: "https://fonts.googleapis.com" },
|
||||
{ rel: "preconnect", href: "https://fonts.gstatic.com", crossorigin: "" },
|
||||
{ rel: "preconnect", href: "https://fonts.gstatic.com ", crossorigin: "" },
|
||||
{
|
||||
rel: "stylesheet",
|
||||
href: "https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&family=Outfit:wght@300;400;500;600;700;800;900&display=swap"
|
||||
@@ -35,6 +35,7 @@ export default defineNuxtConfig({
|
||||
}
|
||||
},
|
||||
runtimeConfig: {
|
||||
apiSecretKey: process.env.API_SECRET_KEY,
|
||||
public: {
|
||||
appVersion: getRepoVersion()
|
||||
}
|
||||
|
||||
3138
package-lock.json
generated
3138
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
10
package.json
10
package.json
@@ -7,14 +7,14 @@
|
||||
"dev": "nuxt dev",
|
||||
"generate": "nuxt generate",
|
||||
"preview": "nuxt preview",
|
||||
"postinstall": "nuxt prepare"
|
||||
"postinstall": "nuxt prepare",
|
||||
"lint": "eslint .",
|
||||
"lint:fix": "eslint . --fix"
|
||||
},
|
||||
"dependencies": {
|
||||
"@iconify/vue": "^5.0.0",
|
||||
"iconify": "^1.4.0",
|
||||
"nuxt": "^4.3.1",
|
||||
"vue": "^3.5.29",
|
||||
"vue-router": "^4.6.4"
|
||||
"@nuxt/eslint": "^1.15.2",
|
||||
"nuxt": "^4.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@semantic-release/changelog": "^6.0.3",
|
||||
|
||||
296
pages/backup.vue
296
pages/backup.vue
@@ -23,6 +23,7 @@
|
||||
<BackupRun
|
||||
class="animate-fade-in-up"
|
||||
style="animation-delay: 180ms"
|
||||
@result="handleScriptResult"
|
||||
/>
|
||||
</section>
|
||||
|
||||
@@ -45,6 +46,47 @@
|
||||
:folder="selectedBackup"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<section
|
||||
class="files-panel output-panel animate-fade-in-up"
|
||||
style="animation-delay: 300ms"
|
||||
aria-labelledby="backup-output-title"
|
||||
>
|
||||
<div class="files-panel-header">
|
||||
<div>
|
||||
<p class="section-kicker">Execution</p>
|
||||
<h2 id="backup-output-title" class="files-panel-title">Resultat du script</h2>
|
||||
</div>
|
||||
<span
|
||||
class="panel-badge"
|
||||
:class="{
|
||||
'panel-badge-idle': !scriptResult.label,
|
||||
'panel-badge-success': scriptResult.label && !scriptResult.isError,
|
||||
'panel-badge-error': scriptResult.isError
|
||||
}"
|
||||
>
|
||||
{{ scriptResult.label || "Pret" }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="!scriptResult.output"
|
||||
class="output-empty"
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
>
|
||||
<p class="output-empty-title">Aucune sortie disponible</p>
|
||||
<p class="output-empty-text">
|
||||
Lancez un script depuis le panneau de gauche pour afficher son retour ici.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<pre
|
||||
v-else
|
||||
class="output-console"
|
||||
:class="{ 'output-console-error': scriptResult.isError }"
|
||||
>{{ scriptResult.output }}</pre>
|
||||
</section>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
@@ -54,10 +96,72 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue"
|
||||
import BackupRun from "~/components/BackupRun.vue"
|
||||
import { apiFetch, downloadApiFile } from "~/composables/useApiAuth"
|
||||
|
||||
definePageMeta({ layout: false })
|
||||
|
||||
type ScriptResult = {
|
||||
key: string | null
|
||||
label: string
|
||||
output: string
|
||||
isError: boolean
|
||||
downloadFolders: string[]
|
||||
}
|
||||
|
||||
const emptyScriptResult = (): ScriptResult => ({
|
||||
key: null,
|
||||
label: "",
|
||||
output: "",
|
||||
isError: false,
|
||||
downloadFolders: []
|
||||
})
|
||||
|
||||
const selectedBackup = ref<string | null>(null)
|
||||
const scriptResult = ref<ScriptResult>(emptyScriptResult())
|
||||
|
||||
const fetchLatestBackup = async (folder: string) => {
|
||||
const files = await apiFetch<string[]>(`/api/backups?folder=${encodeURIComponent(folder)}`)
|
||||
return files[0] || null
|
||||
}
|
||||
|
||||
const triggerDownload = async (folder: string, file: string) => {
|
||||
const url = `/api/download?folder=${encodeURIComponent(folder)}&file=${encodeURIComponent(file)}`
|
||||
await downloadApiFile(url, file)
|
||||
}
|
||||
|
||||
const triggerBatchDownload = async (folders: string[]) => {
|
||||
const url = `/api/download-latest?folders=${encodeURIComponent(folders.join(","))}`
|
||||
await downloadApiFile(url, "backup-latest.tar.gz")
|
||||
}
|
||||
|
||||
const downloadLatestBackup = async (folder: string) => {
|
||||
const latestFile = await fetchLatestBackup(folder)
|
||||
|
||||
if (latestFile) {
|
||||
await triggerDownload(folder, latestFile)
|
||||
}
|
||||
}
|
||||
|
||||
const handleScriptResult = async (payload: ScriptResult) => {
|
||||
scriptResult.value = { ...emptyScriptResult(), ...payload }
|
||||
|
||||
if (payload.isError || payload.downloadFolders.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
if (payload.downloadFolders.length > 1) {
|
||||
await triggerBatchDownload(payload.downloadFolders)
|
||||
return
|
||||
}
|
||||
|
||||
for (const folder of payload.downloadFolders) {
|
||||
try {
|
||||
await downloadLatestBackup(folder)
|
||||
} catch (error) {
|
||||
console.error(`Erreur telechargement automatique pour ${folder}:`, error)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@@ -93,108 +197,6 @@ const selectedBackup = ref<string | null>(null)
|
||||
line-height: 1.65;
|
||||
}
|
||||
|
||||
.selection-card {
|
||||
padding: 1.25rem;
|
||||
border-radius: 16px;
|
||||
background:
|
||||
linear-gradient(180deg, rgb(var(--m-secondary)), rgb(var(--m-tertiary)));
|
||||
}
|
||||
|
||||
.selection-label {
|
||||
margin: 0;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.7rem;
|
||||
letter-spacing: 0.16em;
|
||||
text-transform: uppercase;
|
||||
color: rgb(var(--m-muted));
|
||||
}
|
||||
|
||||
.selection-value {
|
||||
margin: 0.65rem 0 0;
|
||||
font-size: 1.1rem;
|
||||
font-weight: 700;
|
||||
color: rgb(var(--m-text));
|
||||
}
|
||||
|
||||
.selection-description {
|
||||
margin: 0.5rem 0 0;
|
||||
color: rgb(var(--m-muted));
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.intro-panel {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
margin-bottom: 1.5rem;
|
||||
padding: 1.5rem;
|
||||
border-radius: 20px;
|
||||
background:
|
||||
radial-gradient(circle at top right, rgb(var(--m-accent) / 0.12), transparent 28%),
|
||||
linear-gradient(180deg, rgb(var(--m-secondary)), rgb(var(--m-secondary) / 0.82));
|
||||
}
|
||||
|
||||
.intro-panel::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
border: 1px solid rgb(var(--m-accent) / 0.08);
|
||||
border-radius: inherit;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.intro-title {
|
||||
margin: 0;
|
||||
font-family: var(--font-display);
|
||||
font-size: clamp(1.5rem, 2.2vw, 2rem);
|
||||
font-weight: 700;
|
||||
line-height: 1.15;
|
||||
color: rgb(var(--m-text));
|
||||
}
|
||||
|
||||
.intro-description {
|
||||
max-width: 68ch;
|
||||
margin: 0.85rem 0 0;
|
||||
color: rgb(var(--m-muted));
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.workflow-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 1rem;
|
||||
margin-top: 1.5rem;
|
||||
}
|
||||
|
||||
.workflow-step {
|
||||
padding: 1rem;
|
||||
border: 1px solid rgb(var(--m-accent) / 0.08);
|
||||
border-radius: 16px;
|
||||
background: rgb(var(--m-bg) / 0.24);
|
||||
backdrop-filter: blur(4px);
|
||||
}
|
||||
|
||||
.workflow-index {
|
||||
display: inline-block;
|
||||
margin-bottom: 0.75rem;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.75rem;
|
||||
letter-spacing: 0.16em;
|
||||
color: rgb(var(--m-accent));
|
||||
}
|
||||
|
||||
.workflow-title {
|
||||
margin: 0;
|
||||
font-size: 1rem;
|
||||
font-weight: 700;
|
||||
color: rgb(var(--m-text));
|
||||
}
|
||||
|
||||
.workflow-text {
|
||||
margin: 0.45rem 0 0;
|
||||
color: rgb(var(--m-muted));
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.dashboard-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 300px minmax(0, 1fr);
|
||||
@@ -217,6 +219,10 @@ const selectedBackup = ref<string | null>(null)
|
||||
border: 1px solid rgb(var(--m-accent) / 0.08);
|
||||
}
|
||||
|
||||
.output-panel {
|
||||
min-height: 220px;
|
||||
}
|
||||
|
||||
.files-panel-header {
|
||||
display: flex;
|
||||
align-items: end;
|
||||
@@ -243,10 +249,86 @@ const selectedBackup = ref<string | null>(null)
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.panel-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
border-radius: 999px;
|
||||
padding: 0.35rem 0.7rem;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.68rem;
|
||||
letter-spacing: 0.08em;
|
||||
text-transform: uppercase;
|
||||
border: 1px solid transparent;
|
||||
}
|
||||
|
||||
.panel-badge-idle {
|
||||
color: rgb(var(--m-muted));
|
||||
background: rgb(var(--m-tertiary) / 0.45);
|
||||
border-color: rgb(var(--m-border) / 0.25);
|
||||
}
|
||||
|
||||
.panel-badge-success {
|
||||
color: rgb(var(--m-success));
|
||||
background: rgb(var(--m-success) / 0.08);
|
||||
border-color: rgb(var(--m-success) / 0.18);
|
||||
}
|
||||
|
||||
.panel-badge-error {
|
||||
color: rgb(var(--m-error));
|
||||
background: rgb(var(--m-error) / 0.08);
|
||||
border-color: rgb(var(--m-error) / 0.18);
|
||||
}
|
||||
|
||||
.output-empty {
|
||||
display: flex;
|
||||
min-height: 132px;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
border-radius: 14px;
|
||||
border: 1px dashed rgb(var(--m-border) / 0.55);
|
||||
background: rgb(var(--m-tertiary) / 0.38);
|
||||
padding: 1.25rem;
|
||||
}
|
||||
|
||||
.output-empty-title {
|
||||
margin: 0;
|
||||
font-family: var(--font-display);
|
||||
font-size: 1rem;
|
||||
font-weight: 700;
|
||||
color: rgb(var(--m-text));
|
||||
}
|
||||
|
||||
.output-empty-text {
|
||||
margin: 0.5rem 0 0;
|
||||
max-width: 52ch;
|
||||
color: rgb(var(--m-muted));
|
||||
line-height: 1.65;
|
||||
}
|
||||
|
||||
.output-console {
|
||||
margin: 0;
|
||||
min-height: 132px;
|
||||
overflow-x: auto;
|
||||
border-radius: 14px;
|
||||
border: 1px solid rgb(var(--m-border) / 0.3);
|
||||
background:
|
||||
linear-gradient(180deg, rgb(var(--m-bg) / 0.96), rgb(var(--m-secondary) / 0.92));
|
||||
padding: 1rem 1.1rem;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.78rem;
|
||||
line-height: 1.7;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
color: rgb(var(--m-success));
|
||||
}
|
||||
|
||||
.output-console-error {
|
||||
color: rgb(var(--m-error));
|
||||
}
|
||||
|
||||
@media (max-width: 1180px) {
|
||||
.dashboard-header,
|
||||
.dashboard-grid,
|
||||
.workflow-grid {
|
||||
.dashboard-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
@@ -265,14 +347,8 @@ const selectedBackup = ref<string | null>(null)
|
||||
padding: 4.5rem 1.25rem 1.25rem;
|
||||
}
|
||||
|
||||
.intro-panel,
|
||||
.selection-card,
|
||||
.files-panel {
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.workflow-grid {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -33,9 +33,24 @@
|
||||
</div>
|
||||
|
||||
<div class="grid-middle">
|
||||
<Speedtest class="animate-fade-in-up speedtest-card-mobile" style="animation-delay: 150ms" />
|
||||
<SpeedTest class="animate-fade-in-up speedtest-card-mobile" style="animation-delay: 150ms" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="metrics-row">
|
||||
<SystemMetricsChart
|
||||
:metrics="systemMetrics"
|
||||
:loading="systemLoading"
|
||||
class="animate-fade-in-up"
|
||||
style="animation-delay: 200ms"
|
||||
/>
|
||||
<SystemResources
|
||||
:metrics="systemMetrics"
|
||||
:loading="systemLoading"
|
||||
class="animate-fade-in-up"
|
||||
style="animation-delay: 225ms"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="content-aside">
|
||||
@@ -47,8 +62,9 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
definePageMeta({layout: false})
|
||||
import {computed, onMounted, ref} from "vue"
|
||||
definePageMeta({layout: false})
|
||||
import { apiFetch } from "~/composables/useApiAuth"
|
||||
|
||||
type DiskSourceResult = {
|
||||
key: string
|
||||
@@ -74,11 +90,23 @@ type DiagramItem = {
|
||||
totalText: string
|
||||
}
|
||||
|
||||
const selectedBackup = ref<string | null>(null)
|
||||
type SystemMetrics = {
|
||||
cpuPercent: number
|
||||
memoryPercent: number
|
||||
totalMemory: number
|
||||
usedMemory: number
|
||||
incomingMbps: number
|
||||
outgoingMbps: number
|
||||
sampledAt: string
|
||||
}
|
||||
|
||||
const rawResults = ref<DiskSourceResult[]>([])
|
||||
const loading = ref(false)
|
||||
const systemMetrics = ref<SystemMetrics | null>(null)
|
||||
const systemLoading = ref(true)
|
||||
const chartRadius = 52
|
||||
const chartCircumference = 2 * Math.PI * chartRadius
|
||||
let systemTimer: ReturnType<typeof setInterval> | null = null
|
||||
|
||||
const getHostName = (output: string, fallback: string) => {
|
||||
const hostMatch = output.match(/Name:\s*(.+)/i)
|
||||
@@ -151,16 +179,15 @@ const runScript = async () => {
|
||||
rawResults.value = []
|
||||
|
||||
try {
|
||||
const output = await $fetch<DiskApiResponse>("/api/disk")
|
||||
const output = await apiFetch<DiskApiResponse>("/api/disk")
|
||||
rawResults.value = output.results
|
||||
} catch (error) {
|
||||
const message = `Erreur: ${error instanceof Error ? error.message : String(error)}`
|
||||
rawResults.value = [
|
||||
{
|
||||
key: "error",
|
||||
label: "Source indisponible",
|
||||
ok: false,
|
||||
output: message
|
||||
output: "Erreur lors de l'opération"
|
||||
}
|
||||
]
|
||||
} finally {
|
||||
@@ -168,8 +195,27 @@ const runScript = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const loadSystemMetrics = async () => {
|
||||
try {
|
||||
systemMetrics.value = await $fetch<SystemMetrics>("/api/system")
|
||||
} catch {
|
||||
systemMetrics.value = null
|
||||
} finally {
|
||||
systemLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
runScript()
|
||||
loadSystemMetrics()
|
||||
systemTimer = setInterval(loadSystemMetrics, 2000)
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (systemTimer) {
|
||||
clearInterval(systemTimer)
|
||||
systemTimer = null
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -229,6 +275,14 @@ onMounted(() => {
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
.metrics-row {
|
||||
margin-top: 1.5rem;
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) 280px;
|
||||
gap: 1.5rem;
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
.grid-left,
|
||||
.grid-middle,
|
||||
.grid-right {
|
||||
@@ -260,7 +314,8 @@ onMounted(() => {
|
||||
|
||||
.storage-grid,
|
||||
.content-grid,
|
||||
.dashboard-grid {
|
||||
.dashboard-grid,
|
||||
.metrics-row {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,15 +4,17 @@ type BackupScript = {
|
||||
key: string
|
||||
label: string
|
||||
icon?: string
|
||||
downloadFolders?: string[]
|
||||
command: string
|
||||
}
|
||||
|
||||
export default defineEventHandler(() => {
|
||||
return {
|
||||
scripts: (scripts as BackupScript[]).map(({ key, label, icon }) => ({
|
||||
scripts: (scripts as BackupScript[]).map(({ key, label, icon, downloadFolders }) => ({
|
||||
key,
|
||||
label,
|
||||
icon: icon || "mdi:play-circle-outline"
|
||||
icon: icon || "mdi:play-circle-outline",
|
||||
downloadFolders: downloadFolders || []
|
||||
}))
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
import { exec } from "node:child_process"
|
||||
import { execFile } from "node:child_process"
|
||||
import scripts from "../config/backup-script.json"
|
||||
|
||||
type BackupScript = {
|
||||
key: string
|
||||
label: string
|
||||
downloadFolders?: string[]
|
||||
command: string
|
||||
args?: string[]
|
||||
}
|
||||
|
||||
function runCommand(command: string): Promise<string> {
|
||||
function runCommand(command: string, args: string[] = []): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(command, { timeout: 10 * 60 * 1000 }, (error, stdout, stderr) => {
|
||||
execFile(command, args, { timeout: 10 * 60 * 1000 }, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
reject(stderr || error.message)
|
||||
return
|
||||
@@ -39,17 +41,20 @@ export default defineEventHandler(async (event) => {
|
||||
}
|
||||
|
||||
try {
|
||||
const output = await runCommand(script.command)
|
||||
const output = await runCommand(script.command, script.args || [])
|
||||
return {
|
||||
ok: true,
|
||||
key: script.key,
|
||||
label: script.label,
|
||||
downloadFolders: script.downloadFolders || [],
|
||||
output: output.trim()
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Erreur execution script:", error)
|
||||
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: `Erreur execution script: ${String(error)}`
|
||||
statusMessage: "Erreur lors de l'opération"
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { execFile } from "node:child_process"
|
||||
import folderMap from "../config/backup-folders.json"
|
||||
|
||||
const REMOTE_HOST = process.env.BACKUPS_REMOTE_HOST || "malio-b@192.168.0.179"
|
||||
const REMOTE_ROOT = process.env.BACKUPS_REMOTE_ROOT || "/home/malio-b/backups"
|
||||
const MAX_FILES_PER_FOLDER = Number(process.env.BACKUPS_MAX_FILES || "200")
|
||||
const REMOTE_HOST = process.env.BACKUPS_REMOTE_HOST
|
||||
const REMOTE_ROOT = process.env.BACKUPS_REMOTE_ROOT
|
||||
const MAX_FILES_PER_FOLDER = Number(process.env.BACKUPS_MAX_FILES)
|
||||
const isSafeFolder = (value: string) => /^[a-zA-Z0-9._-]+$/.test(value)
|
||||
const shellQuote = (value: string) => `'${value.replace(/'/g, `'\\''`)}'`
|
||||
const FOLDER_MAP = folderMap as Record<string, string>
|
||||
@@ -31,9 +31,11 @@ function isMissingPathError(error: unknown): boolean {
|
||||
}
|
||||
|
||||
function toServerError(error: unknown) {
|
||||
console.error("Erreur backups:", error)
|
||||
|
||||
return createError({
|
||||
statusCode: 500,
|
||||
statusMessage: `Erreur SSH backups: ${String(error)}`
|
||||
statusMessage: "Erreur lors de l'opération"
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,31 @@
|
||||
export default defineEventHandler(async () => {
|
||||
const token = process.env.DISCORD_BOT_TOKEN
|
||||
const channel = process.env.DISCORD_CHANNEL_ID
|
||||
const token = process.env.DISCORD_BOT_TOKEN
|
||||
const channel = process.env.DISCORD_CHANNEL_ID
|
||||
|
||||
if (!token || !channel) {
|
||||
throw createError({
|
||||
statusCode: 503,
|
||||
statusMessage: "Service indisponible"
|
||||
})
|
||||
}
|
||||
|
||||
try {
|
||||
const messages = await $fetch(
|
||||
`https://discord.com/api/v10/channels/${channel}/messages?limit=20`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bot ${token}`
|
||||
}
|
||||
`https://discord.com/api/v10/channels/${channel}/messages?limit=20`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bot ${token}`
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
return messages
|
||||
})
|
||||
} catch (error) {
|
||||
console.error("Erreur Discord messages:", error)
|
||||
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: "Erreur lors de l'opération"
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,21 +1,34 @@
|
||||
import { exec } from "child_process"
|
||||
import { exec, execFile } from "child_process"
|
||||
import diskSources from "../config/disk-commands.json"
|
||||
|
||||
type DiskSource = {
|
||||
key: string
|
||||
label: string
|
||||
command: string
|
||||
args?: string[]
|
||||
}
|
||||
|
||||
function getCommand(source: DiskSource) {
|
||||
function getEnvCommand(source: DiskSource) {
|
||||
const envKey = `DISK_COMMAND_${source.key.toUpperCase()}`
|
||||
const legacyEnvKey =
|
||||
source.key === "remote" ? "DISK_REMOTE_COMMAND" : source.key === "local" ? "DISK_LOCAL_COMMAND" : ""
|
||||
|
||||
return process.env[envKey] || (legacyEnvKey ? process.env[legacyEnvKey] : undefined) || source.command
|
||||
return process.env[envKey] || (legacyEnvKey ? process.env[legacyEnvKey] : undefined) || null
|
||||
}
|
||||
|
||||
function runCommand(command: string): Promise<string> {
|
||||
function runCommand(command: string, args: string[] = []): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
execFile(command, args, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
reject(stderr || error.message)
|
||||
return
|
||||
}
|
||||
resolve(stdout)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function runShellCommand(command: string): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(command, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
@@ -31,7 +44,10 @@ export default defineEventHandler(async () => {
|
||||
const results = await Promise.all(
|
||||
(diskSources as DiskSource[]).map(async (source) => {
|
||||
try {
|
||||
const output = await runCommand(getCommand(source))
|
||||
const envCommand = getEnvCommand(source)
|
||||
const output = envCommand
|
||||
? await runShellCommand(envCommand)
|
||||
: await runCommand(source.command, source.args || [])
|
||||
return {
|
||||
key: source.key,
|
||||
label: source.label,
|
||||
@@ -39,11 +55,12 @@ export default defineEventHandler(async () => {
|
||||
output
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Erreur disk source ${source.key}:`, error)
|
||||
return {
|
||||
key: source.key,
|
||||
label: source.label,
|
||||
ok: false,
|
||||
output: `Erreur: ${String(error)}`
|
||||
output: "Erreur lors de l'opération"
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
139
server/api/download-latest.get.ts
Normal file
139
server/api/download-latest.get.ts
Normal file
@@ -0,0 +1,139 @@
|
||||
import { execFile, spawn } from "node:child_process"
|
||||
import folderMap from "../config/backup-folders.json"
|
||||
|
||||
const REMOTE_HOST = process.env.BACKUPS_REMOTE_HOST || "malio-b"
|
||||
const REMOTE_ROOT = process.env.BACKUPS_REMOTE_ROOT || "/home/malio-b/backups"
|
||||
const FOLDER_MAP = folderMap as Record<string, string>
|
||||
|
||||
const isSafeFolder = (value: string) => /^[a-zA-Z0-9._-]+$/.test(value)
|
||||
const shellQuote = (value: string) => `'${value.replace(/'/g, `'\\''`)}'`
|
||||
|
||||
function runSsh(command: string): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
execFile(
|
||||
"ssh",
|
||||
["-o", "BatchMode=yes", "-o", "ConnectTimeout=5", REMOTE_HOST, command],
|
||||
{ maxBuffer: 10 * 1024 * 1024 },
|
||||
(error, stdout, stderr) => {
|
||||
if (error) {
|
||||
reject(stderr || error.message)
|
||||
return
|
||||
}
|
||||
resolve(stdout)
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
async function remoteDirExists(remoteDir: string): Promise<boolean> {
|
||||
const output = await runSsh(`[ -d ${shellQuote(remoteDir)} ] && echo yes || echo no`)
|
||||
return output.trim() === "yes"
|
||||
}
|
||||
|
||||
async function resolveFolderRemoteDir(folderName: string): Promise<string | null> {
|
||||
const mapped = FOLDER_MAP[folderName]
|
||||
if (mapped) {
|
||||
return `${REMOTE_ROOT}/${mapped}`
|
||||
}
|
||||
|
||||
const direct = `${REMOTE_ROOT}/${folderName}`
|
||||
if (await remoteDirExists(direct)) {
|
||||
return direct
|
||||
}
|
||||
|
||||
const nested = `${REMOTE_ROOT}/bdd_recette/${folderName}`
|
||||
if (await remoteDirExists(nested)) {
|
||||
return nested
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
async function getLatestRemoteFile(remoteDir: string): Promise<string | null> {
|
||||
const output = await runSsh(`cd ${shellQuote(remoteDir)} && ls -1A | sort -r | head -n 1`)
|
||||
const fileName = output.trim()
|
||||
return fileName || null
|
||||
}
|
||||
|
||||
function buildContentDisposition(fileName: string) {
|
||||
const asciiName = fileName.replace(/[^\x20-\x7E]/g, "_").replace(/["\\]/g, "_")
|
||||
return `attachment; filename="${asciiName}"; filename*=UTF-8''${encodeURIComponent(fileName)}`
|
||||
}
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const { folders } = getQuery(event)
|
||||
const folderParam = typeof folders === "string" ? folders : ""
|
||||
const folderNames = folderParam
|
||||
.split(",")
|
||||
.map((folder) => folder.trim())
|
||||
.filter(Boolean)
|
||||
|
||||
if (folderNames.length === 0) {
|
||||
throw createError({ statusCode: 400, statusMessage: "Paramètre folders invalide" })
|
||||
}
|
||||
|
||||
if (folderNames.some((folder) => !isSafeFolder(folder))) {
|
||||
throw createError({ statusCode: 400, statusMessage: "Paramètre folders invalide" })
|
||||
}
|
||||
|
||||
const uniqueFolders = [...new Set(folderNames)]
|
||||
const archiveEntries: Array<{ remoteDir: string; fileName: string; archiveName: string }> = []
|
||||
|
||||
for (const folderName of uniqueFolders) {
|
||||
const remoteDir = await resolveFolderRemoteDir(folderName)
|
||||
if (!remoteDir) {
|
||||
continue
|
||||
}
|
||||
|
||||
const fileName = await getLatestRemoteFile(remoteDir)
|
||||
if (!fileName) {
|
||||
continue
|
||||
}
|
||||
|
||||
archiveEntries.push({
|
||||
remoteDir,
|
||||
fileName,
|
||||
archiveName: `${folderName}/${fileName}`
|
||||
})
|
||||
}
|
||||
|
||||
if (archiveEntries.length === 0) {
|
||||
throw createError({ statusCode: 404, statusMessage: "Aucun fichier a telecharger" })
|
||||
}
|
||||
|
||||
const dateLabel = new Date().toISOString().slice(0, 19).replace(/[:T]/g, "-")
|
||||
const archiveName = `backup-latest-${dateLabel}.tar.gz`
|
||||
const tarArgs = archiveEntries.flatMap(({ remoteDir, fileName, archiveName: entryName }) => [
|
||||
"--transform",
|
||||
shellQuote(`s|^${fileName}$|${entryName}|`),
|
||||
"-C",
|
||||
shellQuote(remoteDir),
|
||||
shellQuote(fileName)
|
||||
])
|
||||
const remoteCommand = `tar -czf - ${tarArgs.join(" ")}`
|
||||
|
||||
setHeader(event, "Content-Type", "application/gzip")
|
||||
setHeader(event, "Content-Disposition", buildContentDisposition(archiveName))
|
||||
|
||||
const child = spawn("ssh", [
|
||||
"-o",
|
||||
"BatchMode=yes",
|
||||
"-o",
|
||||
"ConnectTimeout=5",
|
||||
REMOTE_HOST,
|
||||
remoteCommand
|
||||
])
|
||||
|
||||
let stderr = ""
|
||||
child.stderr.on("data", (chunk) => {
|
||||
stderr += chunk.toString()
|
||||
})
|
||||
|
||||
child.on("close", (code) => {
|
||||
if (code !== 0) {
|
||||
console.error(`Erreur archive SSH (${code}): ${stderr}`)
|
||||
}
|
||||
})
|
||||
|
||||
return sendStream(event, child.stdout)
|
||||
})
|
||||
@@ -2,12 +2,12 @@ import { execFile, spawn } from "node:child_process"
|
||||
import { Readable } from "node:stream"
|
||||
import folderMap from "../config/backup-folders.json"
|
||||
|
||||
const REMOTE_HOST = process.env.BACKUPS_REMOTE_HOST || "malio-b@192.168.0.179"
|
||||
const REMOTE_HOST = process.env.BACKUPS_REMOTE_HOST || "malio-b"
|
||||
const REMOTE_ROOT = process.env.BACKUPS_REMOTE_ROOT || "/home/malio-b/backups"
|
||||
const FOLDER_MAP = folderMap as Record<string, string>
|
||||
|
||||
const isSafeFolder = (value: string) => /^[a-zA-Z0-9._-]+$/.test(value)
|
||||
const isSafeFile = (value: string) => /^[^/\\]+$/.test(value)
|
||||
const isSafeFile = (value: string) => /^[a-zA-Z0-9._-]+$/.test(value)
|
||||
const shellQuote = (value: string) => `'${value.replace(/'/g, `'\\''`)}'`
|
||||
|
||||
function runSsh(command: string): Promise<string> {
|
||||
@@ -56,7 +56,7 @@ function buildContentDisposition(fileName: string) {
|
||||
return `attachment; filename="${asciiName}"; filename*=UTF-8''${encodeURIComponent(fileName)}`
|
||||
}
|
||||
|
||||
function speedtestStream(event: any) {
|
||||
function speedtestStream(event: H3Event) {
|
||||
const size = 128 * 1024 * 1024
|
||||
let sent = 0
|
||||
|
||||
|
||||
165
server/api/system.get.ts
Normal file
165
server/api/system.get.ts
Normal file
@@ -0,0 +1,165 @@
|
||||
import fs from "node:fs"
|
||||
import os from "node:os"
|
||||
|
||||
type CpuTimesSnapshot = {
|
||||
idle: number
|
||||
total: number
|
||||
}
|
||||
|
||||
type NetworkSnapshot = {
|
||||
rxBytes: number
|
||||
txBytes: number
|
||||
timestamp: number
|
||||
}
|
||||
|
||||
let previousNetworkSnapshot: NetworkSnapshot | null = null
|
||||
|
||||
function getCpuSnapshot(): CpuTimesSnapshot {
|
||||
const cpus = os.cpus()
|
||||
|
||||
return cpus.reduce(
|
||||
(snapshot, cpu) => {
|
||||
const total = Object.values(cpu.times).reduce((sum, value) => sum + value, 0)
|
||||
|
||||
snapshot.idle += cpu.times.idle
|
||||
snapshot.total += total
|
||||
|
||||
return snapshot
|
||||
},
|
||||
{idle: 0, total: 0}
|
||||
)
|
||||
}
|
||||
|
||||
function wait(durationMs: number) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, durationMs)
|
||||
})
|
||||
}
|
||||
|
||||
async function getCpuUsagePercent(sampleMs: number) {
|
||||
const start = getCpuSnapshot()
|
||||
await wait(sampleMs)
|
||||
const end = getCpuSnapshot()
|
||||
|
||||
const idleDelta = end.idle - start.idle
|
||||
const totalDelta = end.total - start.total
|
||||
|
||||
if (totalDelta <= 0) {
|
||||
return 0
|
||||
}
|
||||
|
||||
return Math.max(0, Math.min(100, Math.round((1 - idleDelta / totalDelta) * 100)))
|
||||
}
|
||||
|
||||
function getNetworkTotals() {
|
||||
try {
|
||||
const content = fs.readFileSync("/proc/net/dev", "utf8")
|
||||
const totals = content
|
||||
.split("\n")
|
||||
.slice(2)
|
||||
.map((line) => line.trim())
|
||||
.filter(Boolean)
|
||||
.reduce(
|
||||
(accumulator, line) => {
|
||||
const [namePart, valuesPart] = line.split(":")
|
||||
const interfaceName = namePart?.trim()
|
||||
|
||||
if (!interfaceName || interfaceName === "lo" || !valuesPart) {
|
||||
return accumulator
|
||||
}
|
||||
|
||||
const values = valuesPart.trim().split(/\s+/)
|
||||
const rxBytes = Number.parseInt(values[0] || "0", 10)
|
||||
const txBytes = Number.parseInt(values[8] || "0", 10)
|
||||
|
||||
if (Number.isFinite(rxBytes)) {
|
||||
accumulator.rxBytes += rxBytes
|
||||
}
|
||||
|
||||
if (Number.isFinite(txBytes)) {
|
||||
accumulator.txBytes += txBytes
|
||||
}
|
||||
|
||||
return accumulator
|
||||
},
|
||||
{rxBytes: 0, txBytes: 0}
|
||||
)
|
||||
|
||||
return totals
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
function getNetworkRatesMbps() {
|
||||
const totals = getNetworkTotals()
|
||||
const now = Date.now()
|
||||
|
||||
if (!totals) {
|
||||
previousNetworkSnapshot = null
|
||||
return {
|
||||
incomingMbps: 0,
|
||||
outgoingMbps: 0
|
||||
}
|
||||
}
|
||||
|
||||
const currentSnapshot: NetworkSnapshot = {
|
||||
...totals,
|
||||
timestamp: now
|
||||
}
|
||||
|
||||
if (!previousNetworkSnapshot) {
|
||||
previousNetworkSnapshot = currentSnapshot
|
||||
|
||||
return {
|
||||
incomingMbps: 0,
|
||||
outgoingMbps: 0
|
||||
}
|
||||
}
|
||||
|
||||
const elapsedSeconds = (currentSnapshot.timestamp - previousNetworkSnapshot.timestamp) / 1000
|
||||
|
||||
if (elapsedSeconds <= 0) {
|
||||
previousNetworkSnapshot = currentSnapshot
|
||||
|
||||
return {
|
||||
incomingMbps: 0,
|
||||
outgoingMbps: 0
|
||||
}
|
||||
}
|
||||
|
||||
const incomingMbps = Math.max(
|
||||
0,
|
||||
Number((((currentSnapshot.rxBytes - previousNetworkSnapshot.rxBytes) * 8) / elapsedSeconds / 1000000).toFixed(2))
|
||||
)
|
||||
const outgoingMbps = Math.max(
|
||||
0,
|
||||
Number((((currentSnapshot.txBytes - previousNetworkSnapshot.txBytes) * 8) / elapsedSeconds / 1000000).toFixed(2))
|
||||
)
|
||||
|
||||
previousNetworkSnapshot = currentSnapshot
|
||||
|
||||
return {
|
||||
incomingMbps,
|
||||
outgoingMbps
|
||||
}
|
||||
}
|
||||
|
||||
export default defineEventHandler(async () => {
|
||||
const totalMemory = os.totalmem()
|
||||
const freeMemory = os.freemem()
|
||||
const usedMemory = totalMemory - freeMemory
|
||||
const memoryPercent = totalMemory > 0 ? Math.round((usedMemory / totalMemory) * 100) : 0
|
||||
const cpuPercent = await getCpuUsagePercent(200)
|
||||
const {incomingMbps, outgoingMbps} = getNetworkRatesMbps()
|
||||
|
||||
return {
|
||||
cpuPercent,
|
||||
memoryPercent,
|
||||
totalMemory,
|
||||
usedMemory,
|
||||
incomingMbps,
|
||||
outgoingMbps,
|
||||
sampledAt: new Date().toISOString()
|
||||
}
|
||||
})
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"ferme": "bdd_recette/ferme",
|
||||
"inventory": "bdd_recette/inventory",
|
||||
"sirh": "bdd_recette/sirh",
|
||||
"user": "bdd_recette/user",
|
||||
"ferme": "bdd-recette/ferme",
|
||||
"inventory": "bdd-recette/inventory",
|
||||
"sirh": "bdd-recette/sirh",
|
||||
"user": "bdd-recette/user",
|
||||
"bitwarden": "bitwarden"
|
||||
}
|
||||
|
||||
@@ -3,18 +3,32 @@
|
||||
"key": "backup-bdd-recette",
|
||||
"label": "Backup BDD recette",
|
||||
"icon": "mdi:database-export",
|
||||
"command": "ssh malio-b@192.168.0.179 'cd /home/malio-b/Malio-ops/RecetteScripts && bash backup-bdd-recette.sh && exit'"
|
||||
"downloadFolders": ["ferme", "inventory", "sirh", "user"],
|
||||
"command": "ssh",
|
||||
"args": [
|
||||
"ferme",
|
||||
"cd /home/malio/Malio-ops/RecetteScripts && bash backup-bdd-recette.sh"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "check-statut-recette",
|
||||
"label": "Check statut recette",
|
||||
"icon": "mdi:server-network",
|
||||
"command": "ssh malio-b@192.168.0.179 'cd /home/malio-b/Malio-ops/RecetteScripts && bash check-statut-recette.sh && exit'"
|
||||
"command": "ssh",
|
||||
"args": [
|
||||
"ferme",
|
||||
"cd /home/malio/Malio-ops/RecetteScripts && bash check-statut-recette.sh"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "backup-vaultwarden",
|
||||
"label": "Backup vaultwarden",
|
||||
"icon": "mdi:data",
|
||||
"command": "ssh malio-b@192.168.0.179 'cd /home/malio-b/Malio-ops/BackupVaultWarden && bash backup-vaultwarden.sh && exit'"
|
||||
"downloadFolders": ["bitwarden"],
|
||||
"command": "ssh",
|
||||
"args": [
|
||||
"bitwarden",
|
||||
"cd /home/matt/vaultwarden/Malio-ops/BackupVaultWarden && bash backup-vaultwarden.sh"
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
||||
@@ -2,11 +2,18 @@
|
||||
{
|
||||
"key": "remote",
|
||||
"label": "Serveur distant",
|
||||
"command": "ssh malio-b@192.168.0.179 'cd /home/malio-b/Malio-ops/CheckStorage && bash check-storage.sh && exit'"
|
||||
"command": "ssh",
|
||||
"args": [
|
||||
"malio-b",
|
||||
"cd /home/malio-b/Malio-ops/CheckStorage && bash check-storage.sh"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "local",
|
||||
"label": "Machine locale",
|
||||
"command": "bash /home/kevin/check_storage.sh"
|
||||
"command": "bash",
|
||||
"args": [
|
||||
"/home/kevin/check_storage.sh"
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
||||
25
server/middleware/auth-cookie.ts
Normal file
25
server/middleware/auth-cookie.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
export default defineEventHandler((event) => {
|
||||
const path = event.path || event.node.req.url || ""
|
||||
|
||||
if (path.startsWith("/api/")) {
|
||||
return
|
||||
}
|
||||
|
||||
const runtimeConfig = useRuntimeConfig(event)
|
||||
const expectedToken = runtimeConfig.apiSecretKey
|
||||
|
||||
if (!expectedToken) {
|
||||
return
|
||||
}
|
||||
|
||||
if (getCookie(event, "api_auth_token") === expectedToken) {
|
||||
return
|
||||
}
|
||||
|
||||
setCookie(event, "api_auth_token", expectedToken, {
|
||||
httpOnly: true,
|
||||
sameSite: "lax",
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
path: "/"
|
||||
})
|
||||
})
|
||||
31
server/middleware/auth.ts
Normal file
31
server/middleware/auth.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
export default defineEventHandler((event) => {
|
||||
const path = event.path || event.node.req.url || ""
|
||||
|
||||
// Le middleware ne s'applique qu'aux routes API, sauf l'endpoint de ping
|
||||
// qui reste public pour les tests de connectivite.
|
||||
if (!path.startsWith("/api/") || path === "/api/ping") {
|
||||
return
|
||||
}
|
||||
|
||||
const runtimeConfig = useRuntimeConfig(event)
|
||||
const authorization = getHeader(event, "authorization")
|
||||
const cookieToken = getCookie(event, "api_auth_token")
|
||||
const expectedToken = runtimeConfig.apiSecretKey
|
||||
|
||||
// Si aucun secret n'est configure cote serveur, on refuse la requete.
|
||||
if (!expectedToken) {
|
||||
throw createError({
|
||||
statusCode: 401,
|
||||
statusMessage: "Unauthorized"
|
||||
})
|
||||
}
|
||||
|
||||
// Le secret peut venir soit d'un header serveur explicite,
|
||||
// soit du cookie httpOnly pose pour l'application web.
|
||||
if (authorization !== `Bearer ${expectedToken}` && cookieToken !== expectedToken) {
|
||||
throw createError({
|
||||
statusCode: 401,
|
||||
statusMessage: "Unauthorized"
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user