bmc_hub/static/js/link-targets.js
Christian 1fb5b4a191 Add comprehensive tests for email and drift functionalities
- Introduced tests for drift operations UI and backend to ensure proper handling of ignore rules and UI elements.
- Added tests for email identity API to validate email linking and identity retrieval without updates.
- Implemented tests for email purchase link service to verify correct handling of purchase mail links and conflict scenarios.
- Created tests for email reply automation to ensure proper routing and processing of replies based on classification.
- Developed tests for email sender creation to validate suggestions and handling of existing contacts and companies.
- Added tests for email sender identity to ensure correct matching of contacts and domains.
- Implemented tests for work desk functionalities to validate task management, meeting registrations, and timer functionalities.
2026-11-03 01:16:12 +01:00

44 lines
2.7 KiB
JavaScript

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};
})();