butlerx
4 years ago
4 changed files with 26 additions and 28 deletions
@ -1,5 +1,14 @@ |
|||||
export function address(referer: string, user: string, host: string): string { |
export function address( |
||||
const match = referer.match('.+/ssh/([^/]+)$'); |
headers: Record<string, string>, |
||||
|
user: string, |
||||
|
host: string, |
||||
|
): string { |
||||
|
// Check request-header for username
|
||||
|
const remoteUser = headers['remote-user']; |
||||
|
if (remoteUser) { |
||||
|
return `${remoteUser}@${host}`; |
||||
|
} |
||||
|
const match = headers.referer.match('.+/ssh/([^/]+)$'); |
||||
const fallback = user ? `${user}@${host}` : host; |
const fallback = user ? `${user}@${host}` : host; |
||||
return match ? `${match[1].split('?')[0]}@${host}` : fallback; |
return match ? `${match[1].split('?')[0]}@${host}` : fallback; |
||||
} |
} |
||||
|
Loading…
Reference in new issue