fixed #269 - handle spaces in example commands

This commit is contained in:
Eugene Pankov 2022-08-25 23:47:55 +02:00
parent b0866d296b
commit bf6352dddc
No known key found for this signature in database
GPG key ID: 5896FCBBDD1CF4F4
3 changed files with 9 additions and 2 deletions

View file

@ -39,6 +39,7 @@
"format-duration": "^2.0.0", "format-duration": "^2.0.0",
"moment": "^2.29.4", "moment": "^2.29.4",
"sass": "^1.52.3", "sass": "^1.52.3",
"shell-escape": "^0.2.0",
"svelte": "^3.49.0", "svelte": "^3.49.0",
"svelte-check": "^2.7.2", "svelte-check": "^2.7.2",
"svelte-fa": "^3.0.1", "svelte-fa": "^3.0.1",

View file

@ -1,3 +1,4 @@
import shellEscape from 'shell-escape'
import type { Info } from 'gateway/lib/api' import type { Info } from 'gateway/lib/api'
export interface ConnectionOptions { export interface ConnectionOptions {
@ -16,7 +17,7 @@ export function makeSSHUsername (opt: ConnectionOptions): string {
} }
export function makeExampleSSHCommand (opt: ConnectionOptions): string { export function makeExampleSSHCommand (opt: ConnectionOptions): string {
return `ssh ${makeSSHUsername(opt)}@${opt.serverInfo?.externalHost ?? 'warpgate-host'} -p ${opt.serverInfo?.ports.ssh ?? 'warpgate-ssh-port'}` return shellEscape(['ssh', `${makeSSHUsername(opt)}@${opt.serverInfo?.externalHost ?? 'warpgate-host'}`, '-p', (opt.serverInfo?.ports.ssh ?? 'warpgate-ssh-port').toString()])
} }
export function makeMySQLUsername (opt: ConnectionOptions): string { export function makeMySQLUsername (opt: ConnectionOptions): string {
@ -27,7 +28,7 @@ export function makeMySQLUsername (opt: ConnectionOptions): string {
} }
export function makeExampleMySQLCommand (opt: ConnectionOptions): string { 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` let cmd = shellEscape(['mysql', '-u', makeMySQLUsername(opt), '--host', opt.serverInfo?.externalHost ?? 'warpgate-host', '--port', (opt.serverInfo?.ports.mysql ?? 'warpgate-mysql-port').toString(), '--ssl'])
if (!opt.ticketSecret) { if (!opt.ticketSecret) {
cmd += ' -p' cmd += ' -p'
} }

View file

@ -2124,6 +2124,11 @@ shebang-regex@^3.0.0:
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172" resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172"
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A== integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==
shell-escape@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/shell-escape/-/shell-escape-0.2.0.tgz#68fd025eb0490b4f567a027f0bf22480b5f84133"
integrity sha512-uRRBT2MfEOyxuECseCZd28jC1AJ8hmqqneWQ4VWUTgCAFvb3wKU1jLqj6egC4Exrr88ogg3dp+zroH4wJuaXzw==
side-channel@^1.0.4: side-channel@^1.0.4:
version "1.0.4" version "1.0.4"
resolved "https://registry.yarnpkg.com/side-channel/-/side-channel-1.0.4.tgz#efce5c8fdc104ee751b25c58d4290011fa5ea2cf" resolved "https://registry.yarnpkg.com/side-channel/-/side-channel-1.0.4.tgz#efce5c8fdc104ee751b25c58d4290011fa5ea2cf"