Sistema SGSI
Gestión de Seguridad de la Información
ISO/IEC 27001:2022
Usuario o contraseña incorrectos
Bytelink SAS © Todos los derechos reservados.
📧
Verificación en dos pasos
Ingresa el código de 6 dígitos enviado a
tu correo
Código incorrecto. Intenta de nuevo.
El código expira en 5:00
Dashboard
Resumen ejecutivo
Archivo ⬇ Descargar
🗑️
Confirmar eliminación
¿Eliminar este registro?
Esta acción no se puede deshacer.
'); w.document.close(); } notifyAdmin('newReport','Informe PDF generado','Por: '+(SESSION&&SESSION.name||'')+' | '+new Date().toLocaleString('es-CO')); /* ═══════════════════════════════════════════════════════ EMAIL & NOTIFICATION SYSTEM ═══════════════════════════════════════════════════════ */ async function deliverCode(code, email, name){ if(SYSCFG.emailjs.enabled && SYSCFG.emailjs.serviceId && SYSCFG.emailjs.template2fa){ try{ await emailjs.send(SYSCFG.emailjs.serviceId, SYSCFG.emailjs.template2fa,{ to_email:email, to_name:name||'Usuario', otp_code:code.split('').join(' '), otp_plain:code, valid_minutes:'5', app_name:'SGSI Bytelink', }); showDevCode(code,email,true); return; }catch(err){console.warn('EmailJS 2FA error:',err);} } showDevCode(code,email,false); } function showDevCode(code,email,sent=false){ const t=document.createElement('div'); const isSent=sent&&SYSCFG.emailjs.enabled; Object.assign(t.style,{position:'fixed',top:'20px',right:'20px',zIndex:'10000', background:'var(--s1)',border:'2px solid '+(isSent?'var(--grn)':'var(--acc)'), borderRadius:'12px',padding:'16px 20px',fontFamily:"'Poppins',sans-serif", boxShadow:'0 8px 32px rgba(0,179,255,.3)',maxWidth:'300px'}); t.innerHTML='
'+(isSent?'📧 Código enviado a':'💻 Código (modo desarrollo):')+'
'+esc(email||'')+'
' +'
'+code+'
' +'
Válido por 5 minutos
' +(!isSent?'
⚠ Configura EmailJS en ⚙️ Config. del sistema
':''); document.body.appendChild(t); setTimeout(()=>t.remove(),isSent?8000:120000); window._devOTPNotif=t; } async function notifyAdmin(eventType,subject,body){ if(!SYSCFG.emailjs.enabled||!SYSCFG.emailjs.serviceId||!SYSCFG.emailjs.templateNotif)return; if(SYSCFG.notifications.events[eventType]===false)return; const adminEmail=SYSCFG.notifications.adminEmail; if(!adminEmail)return; const entry={ts:Date.now(),type:eventType,subject,sent:false}; try{ await emailjs.send(SYSCFG.emailjs.serviceId,SYSCFG.emailjs.templateNotif,{ to_email:adminEmail,subject_line:subject,body_text:body, event_type:eventType,user_name:SESSION?.name||'Sistema', app_name:'SGSI Bytelink ISO 27001:2022',timestamp:new Date().toLocaleString('es-CO'), }); entry.sent=true; showNotifToast('✉ Notificación enviada al administrador','ok'); }catch(e){console.warn('Notif email error:',e);} finally{ if(!SYSCFG.notifLog)SYSCFG.notifLog=[]; SYSCFG.notifLog.unshift(entry); if(SYSCFG.notifLog.length>50)SYSCFG.notifLog=SYSCFG.notifLog.slice(0,50); saveCFG(); } } function showNotifToast(msg,type='ok'){ const t=document.createElement('div'); Object.assign(t.style,{position:'fixed',bottom:'50px',left:'50%',transform:'translateX(-50%)', zIndex:'9998',background:type==='ok'?'var(--grn)':'var(--amb)',color:'#fff', padding:'7px 16px',borderRadius:'8px',fontSize:'12px', fontFamily:"'Poppins',sans-serif",fontWeight:'500', boxShadow:'0 4px 14px rgba(0,0,0,.3)',whiteSpace:'nowrap'}); t.textContent=msg; document.body.appendChild(t); setTimeout(()=>t.remove(),3500); } async function testEmailConfig(){ const btn=document.getElementById('testEmailBtn'); if(btn){btn.disabled=true;btn.textContent='Enviando...';} try{ initEmailJS(); await emailjs.send(SYSCFG.emailjs.serviceId,SYSCFG.emailjs.templateNotif,{ to_email:SYSCFG.notifications.adminEmail, subject_line:'✅ Prueba de conexión SGSI Bytelink', body_text:'La configuración de correo del sistema SGSI está funcionando correctamente.\n\nFecha: '+new Date().toLocaleString('es-CO'), event_type:'test',user_name:SESSION?.name||'Administrador', app_name:'SGSI Bytelink ISO 27001:2022',timestamp:new Date().toLocaleString('es-CO'), }); alert('✅ Correo de prueba enviado a '+SYSCFG.notifications.adminEmail); if(btn){btn.textContent='✓ Enviado';setTimeout(()=>{btn.disabled=false;btn.textContent='Enviar correo de prueba';},3000);} }catch(e){ if(btn){btn.disabled=false;btn.textContent='Enviar correo de prueba';} alert('❌ Error al enviar:\n'+(e.text||e.message||JSON.stringify(e))+'\n\nVerifica las credenciales de EmailJS.'); } } function saveSysCfg(){ const G=id=>document.getElementById(id)?.value?.trim()||''; const GB=id=>document.getElementById(id)?.checked||false; SYSCFG.emailjs={publicKey:G('cfg_pk'),serviceId:G('cfg_sid'),template2fa:G('cfg_t2fa'),templateNotif:G('cfg_tnotif'),enabled:GB('cfg_enabled')}; SYSCFG.notifications.adminEmail=G('cfg_adminemail'); saveCFG();initEmailJS();render(); _toast('Configuración de correo guardada','ok'); } function saveNotifCfg(){ ['newFile','newReport','highRisk','newNC','login'].forEach(k=>{ SYSCFG.notifications.events[k]=document.getElementById('ev_'+k)?.checked||false; }); saveCFG();_toast('Preferencias guardadas','ok'); } function exportConfig(){ const safe={...SYSCFG,emailjs:{...SYSCFG.emailjs,publicKey:'***REDACTED***'}}; const a=document.createElement('a'); a.href=URL.createObjectURL(new Blob([JSON.stringify(safe,null,2)],{type:'application/json'})); a.download='sgsi_config_'+today()+'.json';a.click(); } function confirmResetDB(){ showDelModal('TODOS los datos del SGSI',()=>{ const emptyDB={assets:[],risks:[],incidents:[], soa:DB.soa.map(ctrl=>({...ctrl,applicable:true,justification:'',implemented:false,responsible:'',evidence:'',control_url:''})), docs:[],audits:[],ncrs:[],kpis:[],c4issues:[],c4stake:[],c4scope:{}, c5policy:[],c5roles:[],c6obj:[],c6changes:[],c7res:[],c7comp:[], c7aware:[],c7comms:[],c8ops:[],c8risklog:[],c9review:[],committees:[]}; Object.assign(DB,emptyDB);saveDB();render(); _toast('Base de datos reiniciada','del'); }); } /* ===== AI ===== */ let aiOpen=false; function toggleAI(){aiOpen=!aiOpen;document.getElementById('aiBox').className='ai-box'+(aiOpen?' open':'');} async function sendAI(){ const inp=document.getElementById('aiIn');const q=inp.value.trim();if(!q)return;inp.value=''; addAI(q,'user');const lid='l'+uid();addAI('Pensando…','ai',lid); try{ const r=await fetch('https://api.anthropic.com/v1/messages',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({model:'claude-sonnet-4-20250514',max_tokens:1200,system:'Eres experto en ISO 27001:2022. Respondes en español, conciso y práctico. Contexto: Bytelink SAS, empresa colombiana de tecnología, certificada ISO 9001/14001/45001, implementando ISO 27001:2022 completo.',messages:[{role:'user',content:q}]})}); const data=await r.json();document.getElementById(lid).textContent=data.content?.[0]?.text||'Sin respuesta'; }catch(e){document.getElementById(lid).textContent='Error de conexión con la IA.';} } function askAI(q){if(!aiOpen)toggleAI();document.getElementById('aiIn').value=q;sendAI();} function addAI(text,role,id=null){const msgs=document.getElementById('aiMsgs');const d=document.createElement('div');d.className=`ai-msg ${role}`;d.textContent=text;if(id)d.id=id;msgs.appendChild(d);msgs.scrollTop=msgs.scrollHeight;} /* ===== INIT ===== */ window.addEventListener('DOMContentLoaded',async()=>{ loadDB();loadUsers(); if(USERS.length===0)await initUsers(); if(!tryAutoLogin())document.getElementById('loginScreen').style.display='flex'; });