Files
tfm_ainventory/frontend/components/admin/LdapManager.tsx
2026-04-15 18:10:04 +03:00

166 lines
7.9 KiB
TypeScript

import React from 'react';
import { Globe, Power, Server, Shield, User, Layers, Lock, Wifi, RotateCcw } from 'lucide-react';
import { cn } from '@/lib/utils';
interface LdapManagerProps {
ldapConfig: any;
setLdapConfig: (config: any) => void;
testingLdap: boolean;
onTestLdap: () => void;
onUpdateLdap: () => void;
}
export default function LdapManager({
ldapConfig,
setLdapConfig,
testingLdap,
onTestLdap,
onUpdateLdap
}: LdapManagerProps) {
return (
<div className="bg-slate-900/40 backdrop-blur-xl border border-slate-800/50 rounded-[2.5rem] p-5 md:p-8 shadow-2xl space-y-6 transition-all group/ldap">
<div className="flex items-center justify-between mb-2">
<div className="flex items-center gap-4">
<div className="w-10 h-10 rounded-xl bg-indigo-500/10 flex items-center justify-center text-indigo-400 border border-indigo-500/20">
<Globe size={20} />
</div>
<h2 className="text-xl font-black text-white tracking-tight">Enterprise LDAP</h2>
</div>
</div>
<div className="flex items-center justify-between p-4 bg-slate-950/40 border border-slate-800/60 rounded-2xl group transition-all hover:border-indigo-500/30">
<div className="flex items-center gap-3">
<div className={cn(
"w-8 h-8 rounded-xl flex items-center justify-center transition-all shadow-inner",
ldapConfig.ldap_enabled ? "bg-green-500/10 text-green-500" : "bg-slate-800 text-slate-500"
)}>
<Power size={14} />
</div>
<div>
<p className="text-xs font-bold text-slate-200 tracking-tight leading-none">Ldap Authorization</p>
<p className={cn("text-[11px] font-bold mt-1.5", ldapConfig.ldap_enabled ? "text-green-500/80" : "text-slate-500")}>
{ldapConfig.ldap_enabled ? "External Directory Active" : "Internal Authentication Only"}
</p>
</div>
</div>
<button
onClick={() => setLdapConfig({...ldapConfig, ldap_enabled: !ldapConfig.ldap_enabled})}
className={cn(
"w-10 h-5 rounded-full relative transition-all duration-300 shadow-inner border",
ldapConfig.ldap_enabled ? "bg-indigo-600 border-indigo-500" : "bg-slate-800 border-slate-700"
)}
>
<div className={cn(
"absolute top-0.5 w-3.5 h-3.5 bg-white rounded-full transition-all shadow-sm",
ldapConfig.ldap_enabled ? "right-0.5" : "left-0.5"
)} />
</button>
</div>
<div className="grid sm:grid-cols-2 gap-4">
<div className="space-y-1.5">
<label className="text-sm font-bold text-slate-400 tracking-tight ml-1">Ldap Uri</label>
<div className="relative">
<Server className="absolute left-3.5 top-1/2 -translate-y-1/2 text-slate-700" size={14} />
<input
type="text"
placeholder="ldap://host:389"
value={ldapConfig.server_uri}
onChange={(e) => setLdapConfig({...ldapConfig, server_uri: e.target.value})}
className="w-full bg-slate-950/80 border border-slate-800 rounded-2xl py-2.5 pl-10 pr-4 text-xs font-bold text-white outline-none focus:border-indigo-500/50 transition-all font-mono"
/>
</div>
</div>
<div className="space-y-1.5">
<label className="text-sm font-bold text-slate-400 tracking-tight ml-1">Context Dn</label>
<div className="relative">
<Shield className="absolute left-3.5 top-1/2 -translate-y-1/2 text-slate-700" size={14} />
<input
type="text"
placeholder="dc=example,dc=com"
value={ldapConfig.base_dn}
onChange={(e) => setLdapConfig({...ldapConfig, base_dn: e.target.value})}
className="w-full bg-slate-950/80 border border-slate-800 rounded-2xl py-2.5 pl-10 pr-4 text-xs font-bold text-white outline-none focus:border-indigo-500/50 transition-all font-mono"
/>
</div>
</div>
</div>
<div className="grid sm:grid-cols-2 gap-4">
<div className="space-y-1.5">
<label className="text-sm font-bold text-slate-400 tracking-tight ml-1">User Dn Template</label>
<div className="relative">
<User className="absolute left-3.5 top-1/2 -translate-y-1/2 text-slate-700" size={14} />
<input
type="text"
placeholder="uid={username},ou=people..."
value={ldapConfig.user_template}
onChange={(e) => setLdapConfig({...ldapConfig, user_template: e.target.value})}
className="w-full bg-slate-950/80 border border-slate-800 rounded-2xl py-2.5 pl-10 pr-4 text-xs font-bold text-white outline-none focus:border-indigo-500/50 transition-all font-mono"
/>
</div>
</div>
<div className="space-y-1.5">
<label className="text-sm font-bold text-slate-400 tracking-tight ml-1">Groups Base Dn</label>
<div className="relative">
<Layers className="absolute left-3.5 top-1/2 -translate-y-1/2 text-slate-700" size={14} />
<input
type="text"
placeholder="ou=groups"
value={ldapConfig.groups_dn}
onChange={(e) => setLdapConfig({...ldapConfig, groups_dn: e.target.value})}
className="w-full bg-slate-950/80 border border-slate-800 rounded-2xl py-2.5 pl-10 pr-4 text-xs font-bold text-white outline-none focus:border-indigo-500/50 transition-all font-mono"
/>
</div>
</div>
</div>
<div className="flex items-center justify-between p-4 bg-slate-950/40 border border-slate-800/60 rounded-2xl group transition-all hover:border-indigo-500/30">
<div className="flex items-center gap-3">
<div className={cn(
"w-8 h-8 rounded-xl flex items-center justify-center transition-all shadow-inner",
ldapConfig.use_tls ? "bg-indigo-500/10 text-indigo-400" : "bg-slate-800 text-slate-500"
)}>
<Lock size={14} />
</div>
<div>
<p className="text-xs font-bold text-slate-200 tracking-tight leading-none">Use Tls</p>
<p className={cn("text-[11px] font-bold mt-1.5", ldapConfig.use_tls ? "text-indigo-400/80" : "text-slate-500")}>
{ldapConfig.use_tls ? "Encrypted Channel" : "Standard Link"}
</p>
</div>
</div>
<button
onClick={() => setLdapConfig({...ldapConfig, use_tls: !ldapConfig.use_tls})}
className={cn(
"w-10 h-5 rounded-full relative transition-all duration-300 shadow-inner border",
ldapConfig.use_tls ? "bg-indigo-600 border-indigo-500" : "bg-slate-800 border-slate-700"
)}
>
<div className={cn(
"absolute top-0.5 w-3.5 h-3.5 bg-white rounded-full transition-all shadow-sm",
ldapConfig.use_tls ? "right-0.5" : "left-0.5"
)} />
</button>
</div>
<div className="flex gap-2 pt-2">
<button
onClick={onTestLdap}
disabled={testingLdap}
className="flex-1 bg-indigo-600 hover:bg-indigo-500 text-white rounded-xl py-3 text-sm font-black shadow-xl shadow-indigo-600/10 transition-all active:scale-95 disabled:opacity-50 flex items-center justify-center gap-2 border border-indigo-500/30"
>
{testingLdap ? <RotateCcw size={14} className="animate-spin" /> : <Wifi size={14} />}
Test Connection
</button>
<button
onClick={onUpdateLdap}
className="flex-[2] bg-indigo-600 hover:bg-indigo-500 text-white rounded-xl py-3 text-sm font-black shadow-xl shadow-indigo-600/10 transition-all active:scale-95 flex items-center justify-center gap-2 border border-indigo-500/30 tracking-tight"
>
<Shield size={14} /> Save LDAP Policy
</button>
</div>
</div>
);
}