update lisensi prosess
tests / ci (push) Has been cancelled

This commit is contained in:
Wian Drs
2026-08-25 13:43:55 +07:00
parent 1e80be180e
commit 60946ddf37
58 changed files with 2903 additions and 165 deletions
+137 -36
View File
@@ -8,14 +8,20 @@ import { Label } from '@/components/ui/label';
type Item = { id: number; name: string; slug?: string };
type Model = Item & { device_vendor_id: number; device_type_id: number };
type Props = {
device: (Record<string, unknown> & { connection_ports?: Record<string, number> }) | null;
device:
| (Record<string, unknown> & {
connection_ports?: Record<string, number>;
})
| null;
vendors: Item[];
types: Item[];
models: Model[];
};
export default function DeviceForm({ device, vendors, types, models }: Props) {
const editing = !!device;
const initialVendor = vendors.find((vendor) => vendor.id === Number(device?.device_vendor_id));
const initialVendor = vendors.find(
(vendor) => vendor.id === Number(device?.device_vendor_id),
);
const [vendorSlug, setVendorSlug] = useState(initialVendor?.slug ?? '');
const fields = [
['name', 'Nama Perangkat'],
@@ -25,12 +31,20 @@ export default function DeviceForm({ device, vendors, types, models }: Props) {
const protocolProfiles: Record<string, Array<[string, string, number]>> = {
mikrotik: [['routeros_api', 'Port RouterOS API', 8728]],
zte: [['ssh', 'Port SSH', 22]],
hsgq: [['ssh', 'Port SSH', 22], ['telnet', 'Port Telnet', 23]],
hisfocus: [['telnet', 'Port Telnet', 23], ['web_http', 'Port WebGUI HTTP', 80]],
hsgq: [
['ssh', 'Port SSH', 22],
['telnet', 'Port Telnet', 23],
],
hisfocus: [
['telnet', 'Port Telnet', 23],
['web_http', 'Port WebGUI HTTP', 80],
],
};
const flexibleProtocols: Array<[string, string, number]> = [
['ssh', 'Port SSH', 22], ['telnet', 'Port Telnet', 23],
['web_http', 'Port WebGUI HTTP', 80], ['snmp', 'Port SNMP', 161],
['ssh', 'Port SSH', 22],
['telnet', 'Port Telnet', 23],
['web_http', 'Port WebGUI HTTP', 80],
['snmp', 'Port SNMP', 161],
['vendor_api', 'Port Vendor API', 0],
];
const protocols = protocolProfiles[vendorSlug] ?? flexibleProtocols;
@@ -84,7 +98,11 @@ export default function DeviceForm({ device, vendors, types, models }: Props) {
)}
required
onChange={(event) => {
const selected = vendors.find((vendor) => vendor.id === Number(event.target.value));
const selected = vendors.find(
(vendor) =>
vendor.id ===
Number(event.target.value),
);
setVendorSlug(selected?.slug ?? '');
}}
className="h-10 rounded-md border bg-background px-3"
@@ -139,24 +157,57 @@ export default function DeviceForm({ device, vendors, types, models }: Props) {
</select>
</div>
<div className="rounded-lg border p-4 md:col-span-2">
<h3 className="font-medium">Koneksi Management</h3>
<p className="mb-4 text-sm text-muted-foreground">Kosongkan port jika protokol tersebut tidak tersedia pada perangkat.</p>
<InputError message={errors.connection_ports} />
<h3 className="font-medium">
Koneksi Management
</h3>
<p className="mb-4 text-sm text-muted-foreground">
Kosongkan port jika protokol tersebut
tidak tersedia pada perangkat.
</p>
<InputError
message={errors.connection_ports}
/>
<div className="grid gap-4 md:grid-cols-2">
{protocols.map(([protocol, label, defaultPort]) => (
<div key={`${vendorSlug}-${protocol}`} className="grid gap-2">
<Label>{label}</Label>
<Input
name={`connection_ports[${protocol}]`}
type="number"
min={1}
max={65535}
placeholder={defaultPort ? String(defaultPort) : 'Port custom'}
defaultValue={device?.connection_ports?.[protocol] ?? ''}
/>
<InputError message={errors[`connection_ports.${protocol}`]} />
</div>
))}
{protocols.map(
([
protocol,
label,
defaultPort,
]) => (
<div
key={`${vendorSlug}-${protocol}`}
className="grid gap-2"
>
<Label>{label}</Label>
<Input
name={`connection_ports[${protocol}]`}
type="number"
min={1}
max={65535}
placeholder={
defaultPort
? String(
defaultPort,
)
: 'Port custom'
}
defaultValue={
device
?.connection_ports?.[
protocol
] ?? ''
}
/>
<InputError
message={
errors[
`connection_ports.${protocol}`
]
}
/>
</div>
),
)}
</div>
</div>
<div className="grid gap-2 md:col-span-2">
@@ -173,26 +224,76 @@ export default function DeviceForm({ device, vendors, types, models }: Props) {
<>
<div className="grid gap-2">
<Label>Username Awal</Label>
<Input name="initial_username" required autoComplete="off" />
<InputError message={errors.initial_username} />
<Input
name="initial_username"
required
autoComplete="off"
/>
<InputError
message={
errors.initial_username
}
/>
</div>
<div className="grid gap-2">
<Label>Password Awal</Label>
<Input name="initial_password" type="password" autoComplete="new-password" />
<p className="text-xs text-muted-foreground">Boleh kosong untuk perangkat MikroTik yang masih memakai password kosong.</p>
<InputError message={errors.initial_password} />
<Input
name="initial_password"
type="password"
autoComplete="new-password"
/>
<p className="text-xs text-muted-foreground">
Boleh kosong untuk perangkat
MikroTik yang masih memakai
password kosong.
</p>
<InputError
message={
errors.initial_password
}
/>
</div>
<div className="grid gap-2 md:col-span-2">
<Label>Enable Password (opsional)</Label>
<Input name="initial_enable_password" type="password" autoComplete="new-password" />
<p className="text-xs text-muted-foreground">Khusus perangkat CLI seperti ZTE C300/C320. Default pabrik tertentu adalah zxr10; isi sesuai kondisi perangkat.</p>
<InputError message={errors.initial_enable_password} />
<Label>
Enable Password (opsional)
</Label>
<Input
name="initial_enable_password"
type="password"
autoComplete="new-password"
/>
<p className="text-xs text-muted-foreground">
Khusus perangkat CLI seperti ZTE
C300/C320. Default pabrik
tertentu adalah zxr10; isi
sesuai kondisi perangkat.
</p>
<InputError
message={
errors.initial_enable_password
}
/>
</div>
<label className="flex items-start gap-3 rounded-lg border p-4 md:col-span-2">
<input type="checkbox" name="remove_legacy_users_on_activation" value="1" className="mt-1" />
<input
type="checkbox"
name="remove_legacy_users_on_activation"
value="1"
className="mt-1"
/>
<span>
<span className="block font-medium">Hapus user lama setelah koneksi pertama</span>
<span className="block text-sm text-muted-foreground">Dijalankan hanya setelah Base User RADIQ berhasil dibuat dan diuji login. User grup full tetap dipertahankan untuk mencegah perangkat terkunci.</span>
<span className="block font-medium">
Hapus user lama setelah
koneksi pertama
</span>
<span className="block text-sm text-muted-foreground">
Dijalankan hanya setelah
Base User RADIQ berhasil
dibuat dan diuji login. User
grup full tetap
dipertahankan untuk mencegah
perangkat terkunci.
</span>
</span>
</label>
</>
+19 -4
View File
@@ -166,7 +166,7 @@ export default function DeviceIndex({
<Button variant="outline">Filter</Button>
</form>
<div className="overflow-x-auto">
<table className="w-full min-w-[980px] table-fixed text-sm [&_td]:align-middle [&_td]:p-3 [&_th]:p-3">
<table className="w-full min-w-[980px] table-fixed text-sm [&_td]:p-3 [&_td]:align-middle [&_th]:p-3">
<colgroup>
<col className="w-[20%]" />
<col className="w-[18%]" />
@@ -202,10 +202,25 @@ export default function DeviceIndex({
'Model belum ditentukan'}
</div>
</td>
<td className="break-words p-3">
<div>{device.management_address}</div>
<td className="p-3 break-words">
<div>
{device.management_address}
</div>
<div className="text-xs text-muted-foreground">
{Object.entries(device.connection_ports ?? { [device.connection_type]: device.management_port }).map(([protocol, port]) => `${protocol}:${port}`).join(' · ')}
{Object.entries(
device.connection_ports ?? {
[device.connection_type]:
device.management_port,
},
)
.map(
([
protocol,
port,
]) =>
`${protocol}:${port}`,
)
.join(' · ')}
</div>
</td>
<td>
+91 -30
View File
@@ -48,11 +48,14 @@ export default function DeviceSettings({
const [revealing, setRevealing] = useState(false);
const hideTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
useEffect(() => () => {
if (hideTimer.current) {
clearTimeout(hideTimer.current);
}
}, []);
useEffect(
() => () => {
if (hideTimer.current) {
clearTimeout(hideTimer.current);
}
},
[],
);
const revealBasePassword = async () => {
setRevealing(true);
@@ -60,29 +63,47 @@ clearTimeout(hideTimer.current);
setRevealedPassword('');
try {
const csrf = document.querySelector<HTMLMetaElement>('meta[name="csrf-token"]')?.content ?? '';
const csrf =
document.querySelector<HTMLMetaElement>(
'meta[name="csrf-token"]',
)?.content ?? '';
const response = await fetch('/device-settings/reveal-password', {
method: 'POST',
credentials: 'same-origin',
headers: { 'Content-Type': 'application/json', Accept: 'application/json', 'X-CSRF-TOKEN': csrf },
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
'X-CSRF-TOKEN': csrf,
},
body: JSON.stringify({ current_password: loginPassword }),
});
const result = await response.json();
if (!response.ok) {
throw new Error(result.errors?.current_password?.[0] ?? result.message ?? 'Password tidak dapat ditampilkan.');
throw new Error(
result.errors?.current_password?.[0] ??
result.message ??
'Password tidak dapat ditampilkan.',
);
}
setRevealedPassword(result.password);
setLoginPassword('');
if (hideTimer.current) {
clearTimeout(hideTimer.current);
}
clearTimeout(hideTimer.current);
}
hideTimer.current = setTimeout(() => setRevealedPassword(''), 30000);
hideTimer.current = setTimeout(
() => setRevealedPassword(''),
30000,
);
} catch (error) {
setRevealError(error instanceof Error ? error.message : 'Password tidak dapat ditampilkan.');
setRevealError(
error instanceof Error
? error.message
: 'Password tidak dapat ditampilkan.',
);
} finally {
setRevealing(false);
}
@@ -106,9 +127,7 @@ clearTimeout(hideTimer.current);
{({ processing, errors }) => (
<Card>
<CardHeader>
<CardTitle>
Template Base User Tenant
</CardTitle>
<CardTitle>Template Base User Tenant</CardTitle>
<CardDescription>
Password disimpan terenkripsi dan tidak
pernah ditampilkan kembali.
@@ -200,31 +219,58 @@ clearTimeout(hideTimer.current);
<div className="rounded-lg border bg-muted/40 p-4 text-sm md:col-span-2">
<strong>Group yang dibuat:</strong>{' '}
RADIQ-READ, RADIQ-WRITE, dan RADIQ-NOC tanpa
permission <code>policy</code>, serta
group bawaan full untuk akun provisioning
permission <code>policy</code>, serta group
bawaan full untuk akun provisioning
terpusat.
</div>
{hasPassword && (
<div className="grid gap-3 rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm text-amber-950 md:col-span-2">
<div>
<strong>Lihat Base Password</strong>
<p>Masukkan password login Tenant Admin. Password perangkat akan disembunyikan otomatis setelah 30 detik.</p>
<p>
Masukkan password login Tenant
Admin. Password perangkat akan
disembunyikan otomatis setelah
30 detik.
</p>
</div>
<div className="flex flex-col gap-2 md:flex-row">
<Input
type="password"
value={loginPassword}
onChange={(event) => setLoginPassword(event.target.value)}
onChange={(event) =>
setLoginPassword(
event.target.value,
)
}
placeholder="Password login Tenant Admin"
autoComplete="current-password"
/>
<Button type="button" variant="outline" disabled={revealing || !loginPassword} onClick={revealBasePassword}>
{revealing ? 'Memverifikasi...' : 'Lihat Password'}
<Button
type="button"
variant="outline"
disabled={
revealing || !loginPassword
}
onClick={revealBasePassword}
>
{revealing
? 'Memverifikasi...'
: 'Lihat Password'}
</Button>
</div>
{revealError && <p className="text-destructive">{revealError}</p>}
{revealError && (
<p className="text-destructive">
{revealError}
</p>
)}
{revealedPassword && (
<Input value={revealedPassword} readOnly className="font-mono" aria-label="Base Password" />
<Input
value={revealedPassword}
readOnly
className="font-mono"
aria-label="Base Password"
/>
)}
</div>
)}
@@ -241,21 +287,36 @@ clearTimeout(hideTimer.current);
<CardHeader>
<CardTitle>Status Rotasi Base User</CardTitle>
<CardDescription>
Perangkat offline akan dicoba kembali oleh scheduler.
Vendor tanpa driver ditandai unsupported.
Perangkat offline akan dicoba kembali oleh
scheduler. Vendor tanpa driver ditandai unsupported.
</CardDescription>
</CardHeader>
<CardContent className="space-y-2">
{devices.map((device) => (
<div key={device.id} className="flex flex-wrap items-center justify-between gap-3 rounded-lg border p-3 text-sm">
<div
key={device.id}
className="flex flex-wrap items-center justify-between gap-3 rounded-lg border p-3 text-sm"
>
<div>
<div className="font-medium">{device.name}</div>
<div className="text-xs text-muted-foreground">{device.vendor.name} · {device.base_sync_message ?? 'Belum pernah disinkronkan'}</div>
<div className="font-medium">
{device.name}
</div>
<div className="text-xs text-muted-foreground">
{device.vendor.name} ·{' '}
{device.base_sync_message ??
'Belum pernah disinkronkan'}
</div>
</div>
<span className="rounded-full bg-muted px-2 py-1 text-xs uppercase">{device.base_sync_status}</span>
<span className="rounded-full bg-muted px-2 py-1 text-xs uppercase">
{device.base_sync_status}
</span>
</div>
))}
{devices.length === 0 && <p className="py-4 text-center text-sm text-muted-foreground">Belum ada perangkat.</p>}
{devices.length === 0 && (
<p className="py-4 text-center text-sm text-muted-foreground">
Belum ada perangkat.
</p>
)}
</CardContent>
</Card>
<Form
+50 -43
View File
@@ -47,7 +47,16 @@ export default function DeviceShow({ device, credentials }: Props) {
['Tipe', device.type.name],
['Model', device.model?.name ?? '-'],
['Alamat Management', device.management_address],
['Koneksi', Object.entries(device.connection_ports ?? { [device.connection_type]: device.management_port }).map(([protocol, port]) => `${protocol}: ${port}`).join(' · ')],
[
'Koneksi',
Object.entries(
device.connection_ports ?? {
[device.connection_type]: device.management_port,
},
)
.map(([protocol, port]) => `${protocol}: ${port}`)
.join(' · '),
],
['Hostname', device.hostname ?? '-'],
['Serial Number', device.serial_number ?? '-'],
['Versi RouterOS', device.software_version ?? '-'],
@@ -89,50 +98,48 @@ export default function DeviceShow({ device, credentials }: Props) {
</Button>
)}
</div>
{['mikrotik', 'zte', 'hsgq', 'hisfocus'].includes(device.vendor.slug) && (
<Card>
<CardHeader>
<CardTitle>
Aktivasi {device.vendor.name}
</CardTitle>
</CardHeader>
<CardContent className="flex flex-col justify-between gap-4 md:flex-row md:items-center">
<div className="text-sm">
<p>
Status:{' '}
<strong className="uppercase">
{device.activation_status}
</strong>
{['mikrotik', 'zte', 'hsgq', 'hisfocus'].includes(
device.vendor.slug,
) && (
<Card>
<CardHeader>
<CardTitle>Aktivasi {device.vendor.name}</CardTitle>
</CardHeader>
<CardContent className="flex flex-col justify-between gap-4 md:flex-row md:items-center">
<div className="text-sm">
<p>
Status:{' '}
<strong className="uppercase">
{device.activation_status}
</strong>
</p>
<p className="text-muted-foreground">
{device.activation_message ??
'Aktivasi akan menguji koneksi dan membuat Base User management dengan aman.'}
</p>
{errors.activation && (
<p className="mt-2 text-destructive">
{errors.activation}
</p>
<p className="text-muted-foreground">
{device.activation_message ??
'Aktivasi akan menguji koneksi dan membuat Base User management dengan aman.'}
</p>
{errors.activation && (
<p className="mt-2 text-destructive">
{errors.activation}
</p>
)}
</div>
{auth.permissions.includes(
'device.connect',
) && (
<Form
action={`/devices/${device.id}/activate`}
method="post"
>
{({ processing }) => (
<Button disabled={processing}>
{processing
? 'Mengaktifkan...'
: 'Cek & Aktifkan Perangkat'}
</Button>
)}
</Form>
)}
</CardContent>
</Card>
)}
</div>
{auth.permissions.includes('device.connect') && (
<Form
action={`/devices/${device.id}/activate`}
method="post"
>
{({ processing }) => (
<Button disabled={processing}>
{processing
? 'Mengaktifkan...'
: 'Cek & Aktifkan Perangkat'}
</Button>
)}
</Form>
)}
</CardContent>
</Card>
)}
<Card>
<CardHeader>
<CardTitle>Informasi</CardTitle>