bmc_hub/static/js/link-targets.js
Christian 4871dd2d9e Add comprehensive test coverage for various modules
- Introduced tests for mail templates including ranking, rendering, and attachment handling.
- Added tests for time billing selection and approval processes, ensuring proper validation and state management.
- Implemented tests for case types in JavaScript, focusing on loading and editing functionality.
- Created tests for contact mail AI integration, ensuring proper parsing and error handling.
- Developed tests for dark theme CSS contrast and loading order.
- Added tests for invoice fee service, covering various scenarios including exemptions and invalid inputs.
- Implemented vendor resource tests, ensuring proper file handling and query validation.
2026-10-08 08:58:02 +02:00

28 lines
1.8 KiB
JavaScript

window.LinkTargets = (() => {
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};
})();