add kerio format support

This commit is contained in:
2026-07-17 11:42:34 +07:00
parent 5d296c39b1
commit b352cda166
8 changed files with 393 additions and 2 deletions
+82
View File
@@ -0,0 +1,82 @@
import { useEffect, useState, type FormEvent } from 'react'
import { Modal } from './Modal'
// A bare DNS domain: no scheme, no user part, no whitespace. Mirrors the
// server-side check in csvimport.normalizeDomain so bad input is caught here.
const domainRe = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)+$/
type Props = {
open: boolean
busy: boolean
onClose: () => void
onSubmit: (file: File, domain: string) => void
}
export function KerioImportModal({ open, busy, onClose, onSubmit }: Props) {
const [domain, setDomain] = useState('')
const [file, setFile] = useState<File | null>(null)
const [error, setError] = useState<string | null>(null)
useEffect(() => {
if (!open) return
setDomain('')
setFile(null)
setError(null)
}, [open])
function submit(e: FormEvent) {
e.preventDefault()
const d = domain.trim().toLowerCase()
if (!domainRe.test(d)) {
setError('Enter a bare domain, e.g. galaxyhotel.kz')
return
}
if (!file) {
setError('Choose the Kerio export file')
return
}
setError(null)
onSubmit(file, d)
}
return (
<Modal open={open} title="Import from Kerio" onClose={onClose}>
<form onSubmit={submit}>
<p className="map-hint">
The Kerio user export lists a login and its password but no domain. The domain you enter is appended to every
login and used for both the source and the destination. Disabled accounts and <code>admin</code> are skipped.
</p>
<div className="field">
<label htmlFor="kerio_domain">Mail domain</label>
<input
id="kerio_domain"
data-modal-autofocus
value={domain}
onChange={(e) => setDomain(e.target.value)}
placeholder="galaxyhotel.kz"
disabled={busy}
/>
</div>
<div className="field">
<label htmlFor="kerio_file">Export file</label>
<input
id="kerio_file"
type="file"
accept=".csv,text/csv"
onChange={(e) => setFile(e.target.files?.[0] ?? null)}
disabled={busy}
/>
</div>
{error && <div className="error-banner">{error}</div>}
<div className="modal-actions">
<button type="button" className="btn" onClick={onClose} disabled={busy}>
Cancel
</button>
<button className="btn btn-primary" disabled={busy}>
{busy ? 'Importing…' : 'Import'}
</button>
</div>
</form>
</Modal>
)
}