mirror of
https://github.com/warp-tech/warpgate.git
synced 2024-09-20 14:56:18 +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:
|
clippy *ARGS:
|
||||||
for p in {{projects}}; do cargo cranky -p $p {{ARGS}}; done
|
for p in {{projects}}; do cargo cranky -p $p {{ARGS}}; done
|
||||||
|
|
||||||
|
test:
|
||||||
|
for p in {{projects}}; do cargo test -p $p; done
|
||||||
|
|
||||||
yarn *ARGS:
|
yarn *ARGS:
|
||||||
cd warpgate-web && yarn {{ARGS}}
|
cd warpgate-web && yarn {{ARGS}}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { api, UserSnapshot, Target, TicketAndSecret } from 'admin/lib/api'
|
import { api, UserSnapshot, Target, TicketAndSecret } from 'admin/lib/api'
|
||||||
import AsyncButton from 'common/AsyncButton.svelte'
|
import AsyncButton from 'common/AsyncButton.svelte'
|
||||||
|
import ConnectionInstructions from 'common/ConnectionInstructions.svelte'
|
||||||
import { TargetKind } from 'gateway/lib/api'
|
import { TargetKind } from 'gateway/lib/api'
|
||||||
import { link } from 'svelte-spa-router'
|
import { link } from 'svelte-spa-router'
|
||||||
import { Alert, FormGroup } from 'sveltestrap'
|
import { Alert, FormGroup } from 'sveltestrap'
|
||||||
|
@ -18,6 +19,7 @@ async function load () {
|
||||||
api.getTargets(),
|
api.getTargets(),
|
||||||
api.getUsers(),
|
api.getUsers(),
|
||||||
])
|
])
|
||||||
|
targets = targets.filter(x => x.options.kind !== TargetKind.WebAdmin)
|
||||||
targets.sort(firstBy('name'))
|
targets.sort(firstBy('name'))
|
||||||
users.sort(firstBy('username'))
|
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.
|
The secret is only shown once - you won't be able to see it again.
|
||||||
</Alert>
|
</Alert>
|
||||||
|
|
||||||
{#if selectedTarget?.options.kind === TargetKind.Ssh}
|
{#if selectedTarget && selectedUser}
|
||||||
<h3>Connection instructions</h3>
|
<ConnectionInstructions
|
||||||
|
targetName={selectedTarget.name}
|
||||||
<FormGroup floating label="SSH username">
|
targetKind={TargetKind[selectedTarget.options.kind]}
|
||||||
<input type="text" class="form-control" readonly value={'ticket-' + result.secret} />
|
username={selectedUser.username}
|
||||||
</FormGroup>
|
targetExternalHost={selectedTarget.options['externalHost']}
|
||||||
|
ticketSecret={result.secret}
|
||||||
<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}
|
{/if}
|
||||||
|
|
||||||
<a
|
<a
|
||||||
|
|
|
@ -2,22 +2,28 @@
|
||||||
import { Alert, FormGroup } from 'sveltestrap'
|
import { Alert, FormGroup } from 'sveltestrap'
|
||||||
import { TargetKind } from 'gateway/lib/api'
|
import { TargetKind } from 'gateway/lib/api'
|
||||||
import { serverInfo } from 'gateway/lib/store'
|
import { serverInfo } from 'gateway/lib/store'
|
||||||
import { makeExampleSSHCommand, makeSSHUsername } from 'common/ssh'
|
import { makeExampleSSHCommand, makeSSHUsername, makeExampleMySQLCommand, makeExampleMySQLURI, makeMySQLUsername, makeTargetURL } from 'common/protocols'
|
||||||
import { makeExampleMySQLCommand, makeExampleMySQLURI, makeMySQLUsername } from 'common/mysql'
|
|
||||||
import { makeTargetURL } from 'common/http'
|
|
||||||
import CopyButton from 'common/CopyButton.svelte'
|
import CopyButton from 'common/CopyButton.svelte'
|
||||||
|
|
||||||
export let targetName: string|undefined
|
export let targetName: string|undefined
|
||||||
export let targetKind: TargetKind
|
export let targetKind: TargetKind
|
||||||
export let targetExternalHost: string|undefined = undefined
|
export let targetExternalHost: string|undefined = undefined
|
||||||
export let username: string|undefined
|
export let username: string|undefined
|
||||||
|
export let ticketSecret: string|undefined = undefined
|
||||||
|
|
||||||
$: sshUsername = makeSSHUsername(targetName, username)
|
$: opts = {
|
||||||
$: exampleSSHCommand = makeExampleSSHCommand(targetName, username, $serverInfo)
|
targetName,
|
||||||
$: mySQLUsername = makeMySQLUsername(targetName, username)
|
username,
|
||||||
$: exampleMySQLCommand = makeExampleMySQLCommand(targetName, username, $serverInfo)
|
serverInfo: $serverInfo,
|
||||||
$: exampleMySQLURI = makeExampleMySQLURI(targetName, username, $serverInfo)
|
ticketSecret,
|
||||||
$: targetURL = targetName ? makeTargetURL(targetName, targetExternalHost, $serverInfo) : ''
|
targetExternalHost,
|
||||||
|
}
|
||||||
|
$: sshUsername = makeSSHUsername(opts)
|
||||||
|
$: exampleSSHCommand = makeExampleSSHCommand(opts)
|
||||||
|
$: mySQLUsername = makeMySQLUsername(opts)
|
||||||
|
$: exampleMySQLCommand = makeExampleMySQLCommand(opts)
|
||||||
|
$: exampleMySQLURI = makeExampleMySQLURI(opts)
|
||||||
|
$: targetURL = targetName ? makeTargetURL(opts) : ''
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if targetKind === TargetKind.Ssh}
|
{#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