admin/config: harden code

Massimo Melina committed Nov 1, 2025 at 16:50 UTC a7949136a6560d71255f2cc51671c809d1177d44
1 file changed +3 -3
admin/src/ConfigFilePage.ts
+3 -3
@@ -3,7 +3,7 @@
3 import { createElement as h, Fragment, useEffect, useState } from 'react';
4 import { apiCall, useApiEx } from './api'
5 import { Alert, Box } from '@mui/material'
6 -import { downloadFileWithContent, focusSelector, isCtrlKey, KeepInScreen } from './misc'
6 +import { downloadFileWithContent, focusSelector, isCtrlKey, KeepInScreen, prefix } from './misc'
7 import { Btn, Flex, IconBtn, reloadBtn } from './mui';
8 import { Save, Edit, Download } from '@mui/icons-material'
9 import { TextEditor } from './TextEditor';
@@ -20,7 +20,7 @@ export default function ConfigFilePage() {
20 useEffect(() => { saved !== undefined && setText(saved || '') }, [saved])
21 return h(Fragment, {},
22 h(Flex, { flexWrap: 'wrap', justifyContent: 'space-between' },
23 - h(Btn, { icon: Download, onClick: exportConfig }, "Export without passwords"),
23 + h(Btn, { icon: Download, onClick: exportConfig, disabled: !data }, "Export without passwords"),
24 edit ? h(Fragment, {},
25 reloadBtn(reload),
26 h(IconBtn, {
@@ -63,7 +63,7 @@ export default function ConfigFilePage() {
63 const s = (text || '')
64 .replace(/^(\s*(\w*password(?!_change)\w*|srp):\s*).+\n/gm, '$1removed\n')
65 .replace(/(:\/\/)[^/@\s]+@/g, '$1removed@')
66 - + 'custom_html: | # this is currently ignored by hfs, just here for reference\n' + data.customHtml.replace(/^/gm, ' ')
66 + + prefix('custom_html: | # this is currently ignored by hfs, just here for reference\n', data.customHtml?.replace(/^/gm, ' '))
67 if (!s) return
68 downloadFileWithContent('config_no_passwords.yaml', s)
69 }