mirror of
https://github.com/warp-tech/warpgate.git
synced 2024-09-20 06:46:17 +08:00
added proper connection instructions for tickets
This commit is contained in:
parent
9af4de71c5
commit
47e245f785
3
justfile
3
justfile
|
@ -12,6 +12,9 @@ fix *ARGS:
|
|||
clippy *ARGS:
|
||||
for p in {{projects}}; do cargo cranky -p $p {{ARGS}}; done
|
||||
|
||||
test:
|
||||
for p in {{projects}}; do cargo test -p $p; done
|
||||
|
||||
yarn *ARGS:
|
||||
cd warpgate-web && yarn {{ARGS}}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<script lang="ts">
|
||||
import { api, UserSnapshot, Target, TicketAndSecret } from 'admin/lib/api'
|
||||
import AsyncButton from 'common/AsyncButton.svelte'
|
||||
import ConnectionInstructions from 'common/ConnectionInstructions.svelte'
|
||||
import { TargetKind } from 'gateway/lib/api'
|
||||
import { link } from 'svelte-spa-router'
|
||||
import { Alert, FormGroup } from 'sveltestrap'
|
||||
|
@ -18,6 +19,7 @@ async function load () {
|
|||
api.getTargets(),
|
||||
api.getUsers(),
|
||||
])
|
||||
targets = targets.filter(x => x.options.kind !== TargetKind.WebAdmin)
|
||||
targets.sort(firstBy('name'))
|
||||
users.sort(firstBy('username'))
|
||||
}
|
||||
|
@ -57,28 +59,14 @@ async function create () {
|
|||
The secret is only shown once - you won't be able to see it again.
|
||||
</Alert>
|
||||
|
||||
{#if selectedTarget?.options.kind === TargetKind.Ssh}
|
||||
<h3>Connection instructions</h3>
|
||||
|
||||
<FormGroup floating label="SSH username">
|
||||
<input type="text" class="form-control" readonly value={'ticket-' + result.secret} />
|
||||
</FormGroup>
|
||||
|
||||
<FormGroup floating label="Example command">
|
||||
<input type="text" class="form-control" readonly value={'ssh ticket-' + result.secret + '@warpgate-host -p warpgate-port'} />
|
||||
</FormGroup>
|
||||
{/if}
|
||||
|
||||
{#if selectedTarget?.options.kind === TargetKind.MySql}
|
||||
<h3>Connection instructions</h3>
|
||||
|
||||
<FormGroup floating label="MySQL username">
|
||||
<input type="text" class="form-control" readonly value={'ticket-' + result.secret} />
|
||||
</FormGroup>
|
||||
|
||||
<FormGroup floating label="Example command">
|
||||
<input type="text" class="form-control" readonly value={'mysql -u ticket-' + result.secret + ' --host warpgate-host --port warpgate-port'} />
|
||||
</FormGroup>
|
||||
{#if selectedTarget && selectedUser}
|
||||
<ConnectionInstructions
|
||||
targetName={selectedTarget.name}
|
||||
targetKind={TargetKind[selectedTarget.options.kind]}
|
||||
username={selectedUser.username}
|
||||
targetExternalHost={selectedTarget.options['externalHost']}
|
||||
ticketSecret={result.secret}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<a
|
||||
|
|
|
@ -2,22 +2,28 @@
|
|||
import { Alert, FormGroup } from 'sveltestrap'
|
||||
import { TargetKind } from 'gateway/lib/api'
|
||||
import { serverInfo } from 'gateway/lib/store'
|
||||
import { makeExampleSSHCommand, makeSSHUsername } from 'common/ssh'
|
||||
import { makeExampleMySQLCommand, makeExampleMySQLURI, makeMySQLUsername } from 'common/mysql'
|
||||
import { makeTargetURL } from 'common/http'
|
||||
import { makeExampleSSHCommand, makeSSHUsername, makeExampleMySQLCommand, makeExampleMySQLURI, makeMySQLUsername, makeTargetURL } from 'common/protocols'
|
||||
import CopyButton from 'common/CopyButton.svelte'
|
||||
|
||||
export let targetName: string|undefined
|
||||
export let targetKind: TargetKind
|
||||
export let targetExternalHost: string|undefined = undefined
|
||||
export let username: string|undefined
|
||||
export let ticketSecret: string|undefined = undefined
|
||||
|
||||
$: sshUsername = makeSSHUsername(targetName, username)
|
||||
$: exampleSSHCommand = makeExampleSSHCommand(targetName, username, $serverInfo)
|
||||
$: mySQLUsername = makeMySQLUsername(targetName, username)
|
||||
$: exampleMySQLCommand = makeExampleMySQLCommand(targetName, username, $serverInfo)
|
||||
$: exampleMySQLURI = makeExampleMySQLURI(targetName, username, $serverInfo)
|
||||
$: targetURL = targetName ? makeTargetURL(targetName, targetExternalHost, $serverInfo) : ''
|
||||
$: opts = {
|
||||
targetName,
|
||||
username,
|
||||
serverInfo: $serverInfo,
|
||||
ticketSecret,
|
||||
targetExternalHost,
|
||||
}
|
||||
$: sshUsername = makeSSHUsername(opts)
|
||||
$: exampleSSHCommand = makeExampleSSHCommand(opts)
|
||||
$: mySQLUsername = makeMySQLUsername(opts)
|
||||
$: exampleMySQLCommand = makeExampleMySQLCommand(opts)
|
||||
$: exampleMySQLURI = makeExampleMySQLURI(opts)
|
||||
$: targetURL = targetName ? makeTargetURL(opts) : ''
|
||||
</script>
|
||||
|
||||
{#if targetKind === TargetKind.Ssh}
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
import type { Info } from 'gateway/lib/api'
|
||||
|
||||
export function makeTargetURL (targetName: string, targetExternalHost?: string, serverInfo?: Info): string {
|
||||
const host = targetExternalHost ? `${targetExternalHost}:${serverInfo?.ports.http ?? 443}` : location.host
|
||||
return `${location.protocol}//${host}/?warpgate-target=${targetName}`
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
import type { Info } from 'gateway/lib/api'
|
||||
|
||||
export function makeMySQLUsername (targetName?: string, username?: string): string {
|
||||
return `${username ?? 'username'}#${targetName ?? 'target'}`
|
||||
}
|
||||
|
||||
export function makeExampleMySQLCommand (targetName?: string, username?: string, serverInfo?: Info): string {
|
||||
return `mysql -u ${makeMySQLUsername(targetName, username)} --host ${serverInfo?.externalHost ?? 'warpgate-host'} --port ${serverInfo?.ports.mysql ?? 'warpgate-mysql-port'} -p --ssl`
|
||||
}
|
||||
|
||||
export function makeExampleMySQLURI (targetName?: string, username?: string, serverInfo?: Info): string {
|
||||
return `mysql://${makeMySQLUsername(targetName, username)}:<password>@${serverInfo?.externalHost ?? 'warpgate-host'}:${serverInfo?.ports.mysql ?? 'warpgate-mysql-port'}?sslMode=required`
|
||||
}
|
48
warpgate-web/src/common/protocols.ts
Normal file
48
warpgate-web/src/common/protocols.ts
Normal file
|
@ -0,0 +1,48 @@
|
|||
import type { Info } from 'gateway/lib/api'
|
||||
|
||||
export interface ConnectionOptions {
|
||||
targetName?: string
|
||||
username?: string
|
||||
serverInfo?: Info
|
||||
targetExternalHost?: string
|
||||
ticketSecret?: string
|
||||
}
|
||||
|
||||
export function makeSSHUsername (opt: ConnectionOptions): string {
|
||||
if (opt.ticketSecret) {
|
||||
return `ticket-${opt.ticketSecret}`
|
||||
}
|
||||
return `${opt.username ?? 'username'}:${opt.targetName ?? 'target'}`
|
||||
}
|
||||
|
||||
export function makeExampleSSHCommand (opt: ConnectionOptions): string {
|
||||
return `ssh ${makeSSHUsername(opt)}@${opt.serverInfo?.externalHost ?? 'warpgate-host'} -p ${opt.serverInfo?.ports.ssh ?? 'warpgate-ssh-port'}`
|
||||
}
|
||||
|
||||
export function makeMySQLUsername (opt: ConnectionOptions): string {
|
||||
if (opt.ticketSecret) {
|
||||
return `ticket-${opt.ticketSecret}`
|
||||
}
|
||||
return `${opt.username ?? 'username'}#${opt.targetName ?? 'target'}`
|
||||
}
|
||||
|
||||
export function makeExampleMySQLCommand (opt: ConnectionOptions): string {
|
||||
let cmd = `mysql -u ${makeMySQLUsername(opt)} --host ${opt.serverInfo?.externalHost ?? 'warpgate-host'} --port ${opt.serverInfo?.ports.mysql ?? 'warpgate-mysql-port'} --ssl`
|
||||
if (!opt.ticketSecret) {
|
||||
cmd += ' -p'
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
export function makeExampleMySQLURI (opt: ConnectionOptions): string {
|
||||
const pwSuffix = opt.ticketSecret ? '' : ':<password>'
|
||||
return `mysql://${makeMySQLUsername(opt)}${pwSuffix}@${opt.serverInfo?.externalHost ?? 'warpgate-host'}:${opt.serverInfo?.ports.mysql ?? 'warpgate-mysql-port'}?sslMode=required`
|
||||
}
|
||||
|
||||
export function makeTargetURL (opt: ConnectionOptions): string {
|
||||
const host = opt.targetExternalHost ? `${opt.targetExternalHost}:${opt.serverInfo?.ports.http ?? 443}` : location.host
|
||||
if (opt.ticketSecret) {
|
||||
return `${location.protocol}//${host}/?warpgate-ticket=${opt.ticketSecret}`
|
||||
}
|
||||
return `${location.protocol}//${host}/?warpgate-target=${opt.targetName}`
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
import type { Info } from 'gateway/lib/api'
|
||||
|
||||
export function makeSSHUsername (targetName?: string, username?: string): string {
|
||||
return `${username ?? 'username'}:${targetName ?? 'target'}`
|
||||
}
|
||||
|
||||
export function makeExampleSSHCommand (targetName?: string, username?: string, serverInfo?: Info): string {
|
||||
return `ssh ${makeSSHUsername(targetName, username)}@${serverInfo?.externalHost ?? 'warpgate-host'} -p ${serverInfo?.ports.ssh ?? 'warpgate-ssh-port'}`
|
||||
}
|
Loading…
Reference in a new issue