Compare commits
6 Commits
fix/prod-r
...
fix/correc
| Author | SHA1 | Date | |
|---|---|---|---|
| c12387ac94 | |||
| bdb65a09ff | |||
| 13457ceb5a | |||
| f30d75141d | |||
|
|
99a5758f05 | ||
| 7261f9f0e9 |
20
.env.example
20
.env.example
@@ -10,14 +10,16 @@ BACKUPS_REMOTE_HOST=
|
||||
BACKUPS_REMOTE_ROOT=
|
||||
BACKUPS_MAX_FILES=
|
||||
|
||||
# DISK_COMMAND_REMOTE et DISK_COMMAND_LOCAL pour les commandes de vérification de l'espace disque
|
||||
DISK_COMMAND_REMOTE=
|
||||
DISK_COMMAND_LOCAL=
|
||||
|
||||
# BACKUP_SCRIPT_COMMAND_BACKUP_BDD_RECETTE, BACKUP_SCRIPT_COMMAND_CHECK_STATUT_RECETTE et BACKUP_SCRIPT_COMMAND_BACKUP_VAULTWARDEN pour les commandes de backup et de vérification des statuts
|
||||
BACKUP_SCRIPT_COMMAND_BACKUP_BDD_RECETTE=
|
||||
BACKUP_SCRIPT_COMMAND_CHECK_STATUT_RECETTE=
|
||||
BACKUP_SCRIPT_COMMAND_BACKUP_VAULTWARDEN=
|
||||
# Paramètres utilisés pour construire les commandes disque et backup
|
||||
DISK_REMOTE_HOST=malio-b
|
||||
DISK_LOCAL_SCRIPT_DIR=/home/malio/Malio-ops/CheckStorage
|
||||
DISK_REMOTE_SCRIPT_DIR=/home/malio-b/Malio-ops/CheckStorage
|
||||
RECETTE_SCRIPTS_DIR=/home/malio/Malio-ops/RecetteScripts
|
||||
VAULTWARDEN_SSH_HOST=bitwarden
|
||||
VAULTWARDEN_SCRIPTS_DIR=/home/matt/vaultwarden/Malio-ops/BackupVaultWarden
|
||||
|
||||
# A quelle heure les backups doivent être effectués (format 24h)
|
||||
BACKUPS_HOUR=19
|
||||
BACKUPS_HOUR=19
|
||||
|
||||
#Mettre à true pour que les cookies d'authentification soient sécurisés (HTTPS uniquement)
|
||||
AUTH_COOKIE_SECURE=
|
||||
|
||||
16
CHANGELOG.md
16
CHANGELOG.md
@@ -1,3 +1,19 @@
|
||||
# [1.4.0](https://gitea.malio.fr/MALIO-DEV/Supervisor/compare/v1.3.1...v1.4.0) (2026-03-17)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* lint ([69c192c](https://gitea.malio.fr/MALIO-DEV/Supervisor/commit/69c192c35ad2a743d01b96d834f509b2b1f0b4e6))
|
||||
* readme ([5184e26](https://gitea.malio.fr/MALIO-DEV/Supervisor/commit/5184e26293ef23944e874f4e938f1cc89ec85f82))
|
||||
* use env ([f7ac255](https://gitea.malio.fr/MALIO-DEV/Supervisor/commit/f7ac255820ca5a1fded47a6b0071d85c7d3c4214))
|
||||
* use env only ([829ac07](https://gitea.malio.fr/MALIO-DEV/Supervisor/commit/829ac07d38e81225017b3c6a33c3f34882ca02d1))
|
||||
* use env only ([e13e1eb](https://gitea.malio.fr/MALIO-DEV/Supervisor/commit/e13e1eb3dd48c1b5a6f2fe0347e43dea60e4406f))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add check backup ([5495e18](https://gitea.malio.fr/MALIO-DEV/Supervisor/commit/5495e18173c0778c6eaba4ae1eb8c30ea46bbef7))
|
||||
|
||||
## [1.3.1](https://gitea.malio.fr/MALIO-DEV/Supervisor/compare/v1.3.0...v1.3.1) (2026-03-16)
|
||||
|
||||
|
||||
|
||||
15
README.md
15
README.md
@@ -95,6 +95,19 @@ Consequence visible :
|
||||
- si `API_SECRET_KEY` est vide, les appels API sont refusés avec `401 Unauthorized`
|
||||
- l'application web pose aussi un cookie HTTP-only via `server/middleware/auth-cookie.ts` pour réutiliser ce secret coté navigateur
|
||||
|
||||
## Securite
|
||||
|
||||
Le comportement actuel du projet repose sur une hypothèse d'exposition très forte.
|
||||
|
||||
- `server/middleware/auth-cookie.ts` pose automatiquement le cookie `api_auth_token` à tout visiteur qui charge l'interface web
|
||||
- ce cookie permet ensuite d'accéder aux routes `/api/*` protégées par `API_SECRET_KEY`
|
||||
- il n'existe pas de login utilisateur ni de contrôle d'identité distinct dans le dépôt
|
||||
|
||||
Conséquence :
|
||||
|
||||
- `Supervisor` doit être déployé uniquement sur un réseau de confiance, derrière un VPN, une restriction d'IP, un proxy d'authentification ou un autre contrôle d'accès externe
|
||||
- si l'application est exposée publiquement sans protection supplémentaire, ce mécanisme ne constitue pas une authentification suffisante
|
||||
|
||||
### SSH pour les backups
|
||||
|
||||
Les fonctionnalités de backup utilisent `ssh` avec les options `BatchMode=yes` et `ConnectTimeout=5` dans `server/utils/ssh.ts`. Cela implique un accès sans saisie interactive de mot de passe.
|
||||
@@ -126,4 +139,4 @@ Usage :
|
||||
- `npm run generate` : généré une sortie statique si ce mode est compatible avec votre usage
|
||||
- `npm run preview` : prévisualisé le build Nuxt
|
||||
- `npm run lint` : execute ESLint
|
||||
- `npm run lint:fix` : applique les corrections ESLint automatiques : collecte périodique CPU, mémoire et réseau
|
||||
- `npm run lint:fix` : applique les corrections ESLint automatiques : collecte périodique CPU, mémoire et réseau
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
--color-m-success: rgb(var(--m-success));
|
||||
--color-m-accent: rgb(var(--m-accent));
|
||||
--color-m-warning: rgb(var(--m-warning));
|
||||
--color-m-succes: rgb(var(--m-success));
|
||||
--font-display: "Outfit", system-ui, sans-serif;
|
||||
--font-mono: "JetBrains Mono", "Fira Code", monospace;
|
||||
}
|
||||
|
||||
@@ -77,7 +77,6 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue"
|
||||
import { Icon as IconifyIcon } from "@iconify/vue"
|
||||
import { apiFetch } from "~/composables/useApiAuth"
|
||||
|
||||
@@ -116,7 +115,6 @@ const active = ref<string | null>(null)
|
||||
const loading = ref(true)
|
||||
const runningKey = ref<string | null>(null)
|
||||
const scripts = ref<BackupScript[]>([])
|
||||
const output = ref<string>("")
|
||||
const message = ref<string>("")
|
||||
const isError = ref(false)
|
||||
|
||||
@@ -125,7 +123,6 @@ const statusClass = computed(() => (isError.value ? "status-error" : "status-suc
|
||||
const loadScripts = async () => {
|
||||
loading.value = true
|
||||
message.value = ""
|
||||
output.value = ""
|
||||
isError.value = false
|
||||
emit("result", {
|
||||
key: null,
|
||||
@@ -156,7 +153,6 @@ const loadScripts = async () => {
|
||||
const runScript = async (key: string) => {
|
||||
active.value = key
|
||||
runningKey.value = key
|
||||
output.value = ""
|
||||
message.value = ""
|
||||
isError.value = false
|
||||
|
||||
@@ -165,30 +161,17 @@ const runScript = async (key: string) => {
|
||||
method: "POST",
|
||||
body: { key }
|
||||
})
|
||||
const resultOutput = data.output || "Aucune sortie retournee."
|
||||
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,
|
||||
output: resultOutput,
|
||||
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 execution script"
|
||||
output.value = ""
|
||||
message.value = (error as any)?.data?.statusMessage || "Erreur execution script"
|
||||
emit("result", {
|
||||
key,
|
||||
label: scripts.value.find((item) => item.key === key)?.label || key,
|
||||
|
||||
@@ -293,7 +293,7 @@ const visibleHistory = computed(() => {
|
||||
return history.value.filter((point) => point.sampledAt >= minTimestamp)
|
||||
})
|
||||
|
||||
const scaleMax = computed(() => 100)
|
||||
const scaleMax = 100
|
||||
|
||||
const formatValue = (value: number) => `${Math.round(value)}%`
|
||||
|
||||
|
||||
@@ -42,7 +42,6 @@ export function useApiAuthHeader() {
|
||||
|
||||
// Tous les appels frontend vers /api/* reutilisent ce header commun.
|
||||
return {
|
||||
Authorization: `Bearer ${token}`
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -146,7 +146,6 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import {ref} from "vue"
|
||||
import {Icon as IconifyIcon} from "@iconify/vue"
|
||||
import logoSrc from '~/assets/LOGO_CARRE_BLANC.png'
|
||||
|
||||
|
||||
@@ -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"
|
||||
@@ -36,6 +36,8 @@ export default defineNuxtConfig({
|
||||
},
|
||||
runtimeConfig: {
|
||||
apiSecretKey: process.env.API_SECRET_KEY,
|
||||
discordBotToken: process.env.DISCORD_BOT_TOKEN,
|
||||
discordChannelId: process.env.DISCORD_CHANNEL_ID,
|
||||
public: {
|
||||
appVersion: getRepoVersion(),
|
||||
apiKey: process.env.API_SECRET_KEY
|
||||
@@ -44,4 +46,4 @@ export default defineNuxtConfig({
|
||||
vite: {
|
||||
plugins: [tailwindcss()]
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
8
package-lock.json
generated
8
package-lock.json
generated
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"name": "disk-monitor",
|
||||
"name": "supervisor",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "disk-monitor",
|
||||
"name": "supervisor",
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"@iconify/vue": "^5.0.0",
|
||||
@@ -15,11 +15,13 @@
|
||||
"@semantic-release/changelog": "^6.0.3",
|
||||
"@semantic-release/commit-analyzer": "^13.0.1",
|
||||
"@semantic-release/git": "^10.0.1",
|
||||
"@semantic-release/github": "^12.0.6",
|
||||
"@semantic-release/release-notes-generator": "^14.1.0",
|
||||
"@tailwindcss/vite": "^4.2.1",
|
||||
"semantic-release": "^25.0.3",
|
||||
"tailwindcss": "^4.2.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"node_modules/@actions/core": {
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
{
|
||||
"name": "disk-monitor",
|
||||
"name": "supervisor",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "nuxt build",
|
||||
"dev": "nuxt dev",
|
||||
@@ -20,7 +23,6 @@
|
||||
"@semantic-release/changelog": "^6.0.3",
|
||||
"@semantic-release/commit-analyzer": "^13.0.1",
|
||||
"@semantic-release/git": "^10.0.1",
|
||||
"@semantic-release/github": "^12.0.6",
|
||||
"@semantic-release/release-notes-generator": "^14.1.0",
|
||||
"@tailwindcss/vite": "^4.2.1",
|
||||
"semantic-release": "^25.0.3",
|
||||
|
||||
@@ -66,7 +66,6 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import {computed, onMounted, ref} from "vue"
|
||||
import { apiFetch } from "~/composables/useApiAuth"
|
||||
import type { SystemMetrics } from "~/types/system";
|
||||
|
||||
@@ -334,14 +333,6 @@ onBeforeUnmount(() => {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.backup-selector {
|
||||
order: 2;
|
||||
}
|
||||
|
||||
.backup-list-mobile {
|
||||
order: 3;
|
||||
}
|
||||
|
||||
.speedtest-card-mobile {
|
||||
order: 4;
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
User-Agent: *
|
||||
Disallow:
|
||||
Disallow: /
|
||||
|
||||
@@ -3,12 +3,10 @@ import {
|
||||
shellQuote,
|
||||
resolveFolderRemoteDir,
|
||||
REMOTE_ROOT,
|
||||
isSafeFolder,
|
||||
} from "../utils/ssh.ts"
|
||||
|
||||
import {process} from "std-env";
|
||||
|
||||
const MAX_FILES_PER_FOLDER = Number(process.env.BACKUPS_MAX_FILES)
|
||||
const isSafeFolder = (value: string) => /^[a-zA-Z0-9._-]+$/.test(value)
|
||||
const MAX_FILES_PER_FOLDER = Math.max(1, Number(process.env.BACKUPS_MAX_FILES) || 50)
|
||||
|
||||
|
||||
function isMissingPathError(error: unknown): boolean {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
export default defineEventHandler(async () => {
|
||||
const token = process.env.DISCORD_BOT_TOKEN
|
||||
const channel = process.env.DISCORD_CHANNEL_ID
|
||||
export default defineEventHandler(async (event) => {
|
||||
const config = useRuntimeConfig(event)
|
||||
const token = config.discordBotToken
|
||||
const channel = config.discordChannelId
|
||||
|
||||
if (!token || !channel) {
|
||||
throw createError({
|
||||
|
||||
@@ -1,38 +1,49 @@
|
||||
import { exec } from "child_process"
|
||||
import { execFile } from "node:child_process"
|
||||
|
||||
type DiskSource = {
|
||||
key: string
|
||||
key: "remote" | "local"
|
||||
label: string
|
||||
}
|
||||
|
||||
type CommandSpec = {
|
||||
command: string
|
||||
args?: string[]
|
||||
args: string[]
|
||||
cwd?: string
|
||||
}
|
||||
|
||||
const diskSources: DiskSource[] = [
|
||||
{
|
||||
key: "remote",
|
||||
label: "Serveur distant",
|
||||
command: "ssh",
|
||||
args: []
|
||||
label: "Serveur distant"
|
||||
},
|
||||
{
|
||||
key: "local",
|
||||
label: "Machine locale",
|
||||
command: "bash",
|
||||
args: []
|
||||
label: "Machine locale"
|
||||
}
|
||||
]
|
||||
|
||||
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" : ""
|
||||
function getCommand(source: DiskSource): CommandSpec {
|
||||
const localScriptDir = process.env.DISK_LOCAL_SCRIPT_DIR || "/home/malio/Malio-ops/CheckStorage"
|
||||
const remoteHost = process.env.DISK_REMOTE_HOST || "malio-b"
|
||||
const remoteScriptDir = process.env.DISK_REMOTE_SCRIPT_DIR || "/home/malio-b/Malio-ops/CheckStorage"
|
||||
|
||||
return process.env[envKey] || (legacyEnvKey ? process.env[legacyEnvKey] : undefined) || null
|
||||
if (source.key === "local") {
|
||||
return {
|
||||
command: "bash",
|
||||
args: ["check-storage.sh"],
|
||||
cwd: localScriptDir
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
command: "ssh",
|
||||
args: [remoteHost, `cd ${remoteScriptDir} && ./check-storage.sh`]
|
||||
}
|
||||
}
|
||||
|
||||
function runShellCommand(command: string): Promise<string> {
|
||||
function runCommand({ command, args, cwd }: CommandSpec): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(command, (error, stdout, stderr) => {
|
||||
execFile(command, args, { cwd }, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
reject(stderr || error.message)
|
||||
return
|
||||
@@ -46,12 +57,7 @@ export default defineEventHandler(async () => {
|
||||
const results = await Promise.all(
|
||||
diskSources.map(async (source) => {
|
||||
try {
|
||||
const envCommand = getEnvCommand(source)
|
||||
if (!envCommand) {
|
||||
throw new Error(`Commande disque manquante pour ${source.key}`)
|
||||
}
|
||||
|
||||
const output = await runShellCommand(envCommand)
|
||||
const output = await runCommand(getCommand(source))
|
||||
return {
|
||||
key: source.key,
|
||||
label: source.label,
|
||||
|
||||
@@ -3,11 +3,10 @@ import {
|
||||
shellQuote,
|
||||
resolveFolderRemoteDir,
|
||||
REMOTE_HOST,
|
||||
isSafeFolder
|
||||
} from "../utils/ssh.ts"
|
||||
import { spawn } from "node:child_process"
|
||||
|
||||
const isSafeFolder = (value: string) => /^[a-zA-Z0-9._-]+$/.test(value)
|
||||
|
||||
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()
|
||||
@@ -45,6 +44,9 @@ export default defineEventHandler(async (event) => {
|
||||
}
|
||||
|
||||
const fileName = await getLatestRemoteFile(remoteDir)
|
||||
if (!fileName || !isSafeFolder(fileName)) {
|
||||
continue
|
||||
}
|
||||
if (!fileName) {
|
||||
continue
|
||||
}
|
||||
@@ -93,6 +95,6 @@ export default defineEventHandler(async (event) => {
|
||||
console.error(`Erreur archive SSH (${code}): ${stderr}`)
|
||||
}
|
||||
})
|
||||
|
||||
event.node.res.on("close", () => child.kill())
|
||||
return sendStream(event, child.stdout)
|
||||
})
|
||||
|
||||
@@ -3,13 +3,11 @@ import {
|
||||
shellQuote,
|
||||
resolveFolderRemoteDir,
|
||||
REMOTE_HOST,
|
||||
isSafeFolder,
|
||||
isSafeFile
|
||||
} from "../utils/ssh.ts"
|
||||
import { spawn } from "node:child_process"
|
||||
|
||||
const isSafeFolder = (value: string) => /^[a-zA-Z0-9._-]+$/.test(value)
|
||||
const isSafeFile = (value: string) => /^[a-zA-Z0-9._-]+$/.test(value)
|
||||
|
||||
|
||||
function buildContentDisposition(fileName: string) {
|
||||
const asciiName = fileName.replace(/[^\x20-\x7E]/g, "_").replace(/["\\]/g, "_")
|
||||
return `attachment; filename="${asciiName}"; filename*=UTF-8''${encodeURIComponent(fileName)}`
|
||||
@@ -61,6 +59,6 @@ export default defineEventHandler(async (event) => {
|
||||
console.error(`Erreur téléchargement SSH (${code}): ${stderr}`)
|
||||
}
|
||||
})
|
||||
|
||||
event.node.res.on("close", () => child.kill())
|
||||
return sendStream(event, child.stdout)
|
||||
})
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
const req = event.node.req
|
||||
|
||||
const MAX_UPLOAD_BYTES = 100 * 1024 * 1024 // 100MB
|
||||
let received = 0
|
||||
|
||||
for await (const chunk of req) {
|
||||
if (received > MAX_UPLOAD_BYTES) throw createError({ statusCode: 413, statusMessage: "Fichier trop volumineux" })
|
||||
received += chunk.length
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
import targets from "../config/version-status-targets.json"
|
||||
|
||||
const REQUEST_TIMEOUT_MS = 5000
|
||||
|
||||
export default defineEventHandler(async () => {
|
||||
const results = await Promise.all(
|
||||
targets.map(async (target) => {
|
||||
const controller = new AbortController()
|
||||
const timeoutId = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS)
|
||||
|
||||
try {
|
||||
const response = await fetch(target.url, {
|
||||
method: "GET",
|
||||
headers: { Accept: "application/json" }
|
||||
headers: { Accept: "application/json" },
|
||||
signal: controller.signal
|
||||
})
|
||||
|
||||
return {
|
||||
@@ -25,6 +31,8 @@ export default defineEventHandler(async () => {
|
||||
checkedAt: new Date().toISOString(),
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
}
|
||||
} finally {
|
||||
clearTimeout(timeoutId)
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
// SECURITE:
|
||||
// Ce middleware pose automatiquement le cookie d'authentification pour tout
|
||||
// visiteur de l'interface web. Ce comportement repose sur l'hypothèse que
|
||||
// Supervisor n'est exposé qu'à un réseau de confiance ou derrière un contrôle
|
||||
// d'accès externe. Si l'application devient publiquement accessible, ce
|
||||
// mécanisme ne constitue pas une authentification utilisateur.
|
||||
export default defineEventHandler((event) => {
|
||||
const path = event.path || event.node.req.url || ""
|
||||
|
||||
|
||||
@@ -25,7 +25,21 @@ export const backupScripts: BackupScript[] = [
|
||||
}
|
||||
]
|
||||
|
||||
const getDefaultBackupScriptCommands = (): Record<string, string> => {
|
||||
const recetteScriptsDir = process.env.RECETTE_SCRIPTS_DIR || "/home/malio/Malio-ops/RecetteScripts"
|
||||
const vaultwardenHost = process.env.VAULTWARDEN_SSH_HOST || "bitwarden"
|
||||
const vaultwardenScriptsDir =
|
||||
process.env.VAULTWARDEN_SCRIPTS_DIR || "/home/matt/vaultwarden/Malio-ops/BackupVaultWarden"
|
||||
|
||||
return {
|
||||
"backup-bdd-recette": `cd ${recetteScriptsDir} && bash backup-bdd-recette.sh`,
|
||||
"check-statut-recette": `cd ${recetteScriptsDir} && bash check-statut-recette.sh`,
|
||||
"backup-vaultwarden":
|
||||
`ssh ${vaultwardenHost} "cd ${vaultwardenScriptsDir} && bash backup-vaultwarden.sh"`
|
||||
}
|
||||
}
|
||||
|
||||
export function getBackupScriptCommand(key: string) {
|
||||
const envKey = `BACKUP_SCRIPT_COMMAND_${key.toUpperCase().replace(/-/g, "_")}`
|
||||
return process.env[envKey] || null
|
||||
return process.env[envKey] || getDefaultBackupScriptCommands()[key] || null
|
||||
}
|
||||
|
||||
@@ -1,20 +1,23 @@
|
||||
import { execFile } from "node:child_process"
|
||||
import {process} from "std-env";
|
||||
import {execFile} from "node:child_process"
|
||||
import folderMap from "#server/config/backup-folders.json";
|
||||
|
||||
export const REMOTE_HOST = process.env.BACKUPS_REMOTE_HOST
|
||||
export const REMOTE_ROOT = process.env.BACKUPS_REMOTE_ROOT || "/home/malio-b/backups"
|
||||
export const FOLDER_MAP = folderMap as Record<string, string>
|
||||
|
||||
export const isSafeFolder = (value: string) => /^[a-zA-Z0-9._-]+$/.test(value)
|
||||
export const isSafeFile = (value: string) => /^[a-zA-Z0-9._-]+$/.test(value)
|
||||
|
||||
export const shellQuote = (value: string) => `'${value.replace(/'/g, `'\\''`)}'`
|
||||
|
||||
export function runSsh(command: string): Promise<string> {
|
||||
if (!REMOTE_HOST) {
|
||||
return Promise.reject(new Error("BACKUPS_REMOTE_HOST is not configured"))
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
execFile(
|
||||
"ssh",
|
||||
["-o", "BatchMode=yes", "-o", "ConnectTimeout=5", REMOTE_HOST, command],
|
||||
{ maxBuffer: 10 * 1024 * 1024 },
|
||||
{maxBuffer: 10 * 1024 * 1024},
|
||||
(error, stdout, stderr) => {
|
||||
if (error) {
|
||||
reject(stderr || error.message)
|
||||
@@ -42,7 +45,7 @@ export async function resolveFolderRemoteDir(folderName: string): Promise<string
|
||||
return direct
|
||||
}
|
||||
|
||||
const nested = `${REMOTE_ROOT}/bdd_recette/${folderName}`
|
||||
const nested = `${REMOTE_ROOT}/bdd-recette/${folderName}`
|
||||
if (await remoteDirExists(nested)) {
|
||||
return nested
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user