window.LinkTargets = (() => { function rdpTarget(link) { const raw = String(link.url || '').trim(); if (/^rdp:\/\//i.test(raw)) return /[\r\n]/.test(raw) ? '' : raw; let host = String(link.host || raw).trim(), port = link.port || 3389; if (/^[^:]+:\d+$/.test(host)) { const parts = host.split(':'); host = parts[0]; port = link.port || Number(parts[1]); } if (!host || /[^a-zA-Z0-9.\-:\[\]]/.test(host) || host.startsWith('-')) return ''; if (!Number.isInteger(Number(port)) || Number(port) < 1 || Number(port) > 65535) return ''; const bareHost = host.replace(/^\[|\]$/g, ''); const address = `${bareHost.includes(':') ? '[' + bareHost + ']' : bareHost}:${port}`; const user = String(link.username || '').trim(); return `rdp://full%20address=${encodeURIComponent('s:' + address)}${user ? '&username=' + encodeURIComponent('s:' + user) : ''}`; } function sshTarget(link) { const raw=String(link.url || '').trim(); let host=String(link.host || '').trim(), user=String(link.username || '').trim(), port=link.port; if (/^ssh:\/\//i.test(raw)) { try { const uri=new URL(raw); if(uri.password || uri.search || uri.hash || (uri.pathname && uri.pathname!=='/'))return null; host=uri.hostname; user=decodeURIComponent(uri.username) || user; port=uri.port || port; } catch { return null; } } else if (!host && raw && !raw.includes('://')) host=raw; if (!host || /[^a-zA-Z0-9.\-:\[\]]/.test(host) || host.startsWith('-') || /[^a-zA-Z0-9._+-]/.test(user) || user.startsWith('-'))return null; // Plain hostname:port is accepted; IPv6 is enclosed in brackets for the URI. if (/^[^:]+:\d+$/.test(host)){const pieces=host.split(':');host=pieces[0];port=port || pieces[1];} if (port && (!Number.isInteger(Number(port)) || Number(port)<1 || Number(port)>65535))return null; const bareHost=host.replace(/^\[|\]$/g,''); const uriHost=bareHost.includes(':')?`[${bareHost}]`:bareHost; return {href:`ssh://${user?encodeURIComponent(user)+'@':''}${uriHost}${port?':'+Number(port):''}`, command:`ssh${port?' -p '+Number(port):''} ${user?user+'@':''}${bareHost}`}; } function href(link) { if(link.type==='ssh')return sshTarget(link)?.href || ''; if(link.type==='command')return ''; const raw=String(link.url || link.host || '').trim(); if(!raw || /^(javascript|data|vbscript|file):/i.test(raw))return ''; if(/^https?:\/\//i.test(raw))return raw; if(link.type==='http' && !raw.includes('://'))return `http://${raw}`; if(link.type==='rdp')return link.url || `//${raw}`; return ''; } return {href,sshTarget,rdpTarget}; })();