A sandbox behind NAT could not reach the room. A reverse target dials a tunnel-only sshd on the server, forwards localhost:22 to a loopback port, and the worker connects there. The server assigns the port and writes one authorized_keys line per tunnel target. The key carries permitlisten for that port; the sshd allows remote forwarding only, with no shell or local forwarding. The tunnel private key is shown once and never stored; rotating it rewrites the file. The target list and setup dialog carry the command, and the docs include the sshd config and sidecar requirements.
868 lines
30 KiB
Vue
868 lines
30 KiB
Vue
<script setup lang="ts">
|
|
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
|
import { Check, Copy, ExternalLink, Plus, Trash2 } from 'lucide-vue-next'
|
|
import type {
|
|
CreateSandboxBody,
|
|
CreateSandboxResponse,
|
|
CreateProviderBody,
|
|
IdResponse,
|
|
LoginFlowStatus,
|
|
ProviderConfig,
|
|
ProviderListResponse,
|
|
SandboxKind,
|
|
SandboxListResponse,
|
|
SandboxTarget,
|
|
StartLoginResponse,
|
|
TestSandboxResponse,
|
|
} from '~/types'
|
|
import { apiErrorMessage } from '~/utils/errors'
|
|
import BaseDialog from '~/components/BaseDialog.vue'
|
|
|
|
useHead({ title: 'Settings · Rhema Together' })
|
|
|
|
const api = useApi()
|
|
|
|
const KIND_LABELS: Record<string, string> = {
|
|
anthropic: 'Anthropic',
|
|
openai: 'OpenAI',
|
|
openrouter: 'OpenRouter',
|
|
google: 'Google Gemini',
|
|
deepseek: 'DeepSeek',
|
|
zai: 'Z.ai',
|
|
mistral: 'Mistral API',
|
|
'mistral-vibe': 'Mistral Vibe',
|
|
copilot: 'GitHub Copilot',
|
|
chatgpt: 'ChatGPT',
|
|
opencode: 'OpenCode',
|
|
'llama-cpp': 'llama.cpp',
|
|
}
|
|
|
|
const providers = ref<ProviderConfig[]>([])
|
|
const kinds = ref<string[]>(['anthropic', 'openai', 'openrouter', 'google', 'deepseek', 'zai', 'mistral', 'mistral-vibe', 'copilot', 'chatgpt', 'opencode', 'llama-cpp'])
|
|
const flowKinds = ref<string[]>(['copilot', 'chatgpt', 'mistral-vibe'])
|
|
const targets = ref<SandboxTarget[]>([])
|
|
const loading = ref(true)
|
|
const loadError = ref('')
|
|
|
|
const providerName = ref('')
|
|
const providerKind = ref('anthropic')
|
|
const providerBaseUrl = ref('')
|
|
const providerKey = ref('')
|
|
const providerBusy = ref(false)
|
|
const providerError = ref('')
|
|
const llama = computed(() => providerKind.value === 'llama-cpp')
|
|
const flowKind = computed(() => flowKinds.value.includes(providerKind.value))
|
|
const kindName = computed(() => KIND_LABELS[providerKind.value] ?? providerKind.value)
|
|
|
|
const loginId = ref<string | null>(null)
|
|
const loginStatus = ref<LoginFlowStatus | null>(null)
|
|
const loginPollFailures = ref(0)
|
|
const copiedLoginCode = ref(false)
|
|
let loginTimer: ReturnType<typeof setTimeout> | null = null
|
|
let loginCopyTimer: ReturnType<typeof setTimeout> | null = null
|
|
let loginGeneration = 0
|
|
|
|
const providerDialogTitle = computed(() =>
|
|
loginId.value ? `Sign in to ${providerName.value.trim() || kindName.value}` : 'Add provider',
|
|
)
|
|
const providerDialogDescription = computed(() => {
|
|
if (loginId.value) {
|
|
if (loginStatus.value?.status === 'failed') return 'The sign-in did not finish. Try again or go back.'
|
|
return 'Finish the sign-in in your browser. This dialog updates on its own.'
|
|
}
|
|
if (flowKind.value) return 'Sign in with the provider. The credential stays sealed on the server.'
|
|
if (llama.value) return 'The server address is stored for this account.'
|
|
return 'The key stays sealed on the server and is never shown again.'
|
|
})
|
|
const loginUrl = computed(() => {
|
|
const url = loginStatus.value?.instruction?.url
|
|
return url && /^https?:\/\//i.test(url) ? url : null
|
|
})
|
|
const loginCode = computed(() => loginStatus.value?.instruction?.code ?? null)
|
|
const flowInstruction = computed(() => {
|
|
const instruction = loginStatus.value?.instruction
|
|
if (!instruction) return ''
|
|
switch (providerKind.value) {
|
|
case 'copilot':
|
|
return 'Enter the code on GitHub to authorize Rhema.'
|
|
case 'mistral-vibe':
|
|
return 'Sign in with your Mistral account to authorize Rhema for your Vibe plan.'
|
|
case 'chatgpt':
|
|
return sentence(instruction.text)
|
|
default:
|
|
return sentence(instruction.text)
|
|
}
|
|
})
|
|
|
|
const sandboxKind = ref<SandboxKind>('direct')
|
|
const sandboxName = ref('')
|
|
const sandboxHost = ref('')
|
|
const sandboxPort = ref<number | string>(22)
|
|
const sandboxUser = ref('root')
|
|
const sandboxRoot = ref('/root')
|
|
const sandboxKey = ref('')
|
|
const sandboxBusy = ref(false)
|
|
const sandboxError = ref('')
|
|
const tunnelSetup = ref<{ id: string; name: string; privateKey: string; command: string } | null>(null)
|
|
const tunnelBusy = ref(false)
|
|
const tunnelError = ref('')
|
|
const copiedTunnel = ref<string | null>(null)
|
|
|
|
const deletingProvider = ref<string | null>(null)
|
|
const deletingTarget = ref<string | null>(null)
|
|
const deleteBusy = ref(false)
|
|
const rowError = ref('')
|
|
|
|
const providerDialog = ref(false)
|
|
const sandboxDialog = ref(false)
|
|
const testingTarget = ref<string | null>(null)
|
|
const testResults = ref<Record<string, TestSandboxResponse>>({})
|
|
const copiedKey = ref<string | null>(null)
|
|
|
|
async function loadLists() {
|
|
loading.value = true
|
|
loadError.value = ''
|
|
try {
|
|
const [providerList, targetList] = await Promise.all([
|
|
api.get<ProviderListResponse>('/provider-configs'),
|
|
api.get<SandboxListResponse>('/sandbox-targets'),
|
|
])
|
|
providers.value = providerList.providers
|
|
if (providerList.kinds.length > 0) kinds.value = providerList.kinds
|
|
if (providerList.flow_kinds.length > 0) flowKinds.value = providerList.flow_kinds
|
|
targets.value = targetList.targets
|
|
} catch (err) {
|
|
loadError.value = apiErrorMessage(err)
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
onMounted(loadLists)
|
|
|
|
onBeforeUnmount(() => {
|
|
loginGeneration += 1
|
|
stopLoginPolling()
|
|
if (loginCopyTimer !== null) clearTimeout(loginCopyTimer)
|
|
const id = loginId.value
|
|
if (id) void api.del(`/provider-configs/login/${id}`).catch(() => {})
|
|
})
|
|
|
|
function openProviderDialog() {
|
|
providerError.value = ''
|
|
loginStatus.value = null
|
|
loginId.value = null
|
|
loginPollFailures.value = 0
|
|
copiedLoginCode.value = false
|
|
providerDialog.value = true
|
|
}
|
|
|
|
function closeProviderDialog() {
|
|
cancelLogin()
|
|
providerDialog.value = false
|
|
providerKey.value = ''
|
|
providerError.value = ''
|
|
}
|
|
|
|
function kindLabel(kind: string) {
|
|
return KIND_LABELS[kind] ?? kind
|
|
}
|
|
|
|
function sentence(text: string) {
|
|
return text ? text.charAt(0).toUpperCase() + text.slice(1) : text
|
|
}
|
|
|
|
function stopLoginPolling() {
|
|
if (loginTimer !== null) {
|
|
clearTimeout(loginTimer)
|
|
loginTimer = null
|
|
}
|
|
}
|
|
|
|
function cancelLogin() {
|
|
loginGeneration += 1
|
|
providerBusy.value = false
|
|
stopLoginPolling()
|
|
const id = loginId.value
|
|
loginId.value = null
|
|
loginStatus.value = null
|
|
loginPollFailures.value = 0
|
|
copiedLoginCode.value = false
|
|
if (loginCopyTimer !== null) {
|
|
clearTimeout(loginCopyTimer)
|
|
loginCopyTimer = null
|
|
}
|
|
if (id) void api.del(`/provider-configs/login/${id}`).catch(() => {})
|
|
}
|
|
|
|
function scheduleLoginPoll() {
|
|
stopLoginPolling()
|
|
loginTimer = window.setTimeout(() => {
|
|
void pollLogin()
|
|
}, 2000)
|
|
}
|
|
|
|
async function pollLogin() {
|
|
const id = loginId.value
|
|
if (!id) return
|
|
const generation = loginGeneration
|
|
try {
|
|
const status = await api.get<LoginFlowStatus>(`/provider-configs/login/${id}`)
|
|
if (loginId.value !== id || generation !== loginGeneration) return
|
|
loginPollFailures.value = 0
|
|
loginStatus.value = status
|
|
if (status.status === 'completed') {
|
|
stopLoginPolling()
|
|
loginId.value = null
|
|
loginStatus.value = null
|
|
providerName.value = ''
|
|
providerBaseUrl.value = ''
|
|
providerKey.value = ''
|
|
providerError.value = ''
|
|
if (id) void api.del(`/provider-configs/login/${id}`).catch(() => {})
|
|
providerDialog.value = false
|
|
await loadLists()
|
|
} else if (status.status === 'failed') {
|
|
stopLoginPolling()
|
|
} else {
|
|
scheduleLoginPoll()
|
|
}
|
|
} catch (err) {
|
|
if (loginId.value !== id || generation !== loginGeneration) return
|
|
loginPollFailures.value += 1
|
|
if (loginPollFailures.value >= 3) {
|
|
stopLoginPolling()
|
|
loginStatus.value = { status: 'failed', message: apiErrorMessage(err) }
|
|
} else {
|
|
scheduleLoginPoll()
|
|
}
|
|
}
|
|
}
|
|
|
|
async function startProviderLogin() {
|
|
if (providerBusy.value) return
|
|
const generation = ++loginGeneration
|
|
providerBusy.value = true
|
|
providerError.value = ''
|
|
stopLoginPolling()
|
|
const previous = loginId.value
|
|
loginId.value = null
|
|
loginStatus.value = null
|
|
loginPollFailures.value = 0
|
|
copiedLoginCode.value = false
|
|
if (previous) {
|
|
try {
|
|
await api.del(`/provider-configs/login/${previous}`)
|
|
} catch {
|
|
// The sweep drops an old record anyway; the new flow still starts.
|
|
}
|
|
}
|
|
if (generation !== loginGeneration) return
|
|
try {
|
|
const started = await api.post<StartLoginResponse>('/provider-configs/login', {
|
|
name: providerName.value.trim(),
|
|
kind: providerKind.value,
|
|
})
|
|
if (generation !== loginGeneration) {
|
|
void api.del(`/provider-configs/login/${started.id}`).catch(() => {})
|
|
return
|
|
}
|
|
loginId.value = started.id
|
|
loginStatus.value = { status: 'starting' }
|
|
scheduleLoginPoll()
|
|
} catch (err) {
|
|
if (generation === loginGeneration) providerError.value = apiErrorMessage(err)
|
|
} finally {
|
|
if (generation === loginGeneration) providerBusy.value = false
|
|
}
|
|
}
|
|
|
|
function backToProviderForm() {
|
|
cancelLogin()
|
|
providerError.value = ''
|
|
}
|
|
|
|
async function copyLoginCode() {
|
|
if (!loginCode.value) return
|
|
try {
|
|
await navigator.clipboard.writeText(loginCode.value)
|
|
providerError.value = ''
|
|
copiedLoginCode.value = true
|
|
if (loginCopyTimer !== null) clearTimeout(loginCopyTimer)
|
|
loginCopyTimer = window.setTimeout(() => {
|
|
copiedLoginCode.value = false
|
|
}, 1800)
|
|
} catch {
|
|
providerError.value = 'The clipboard is not available. Select the code and copy it by hand.'
|
|
}
|
|
}
|
|
|
|
async function submitProvider() {
|
|
if (flowKind.value) {
|
|
await startProviderLogin()
|
|
return
|
|
}
|
|
await addProvider()
|
|
}
|
|
|
|
function openSandboxDialog() {
|
|
sandboxError.value = ''
|
|
sandboxDialog.value = true
|
|
}
|
|
|
|
function closeSandboxDialog() {
|
|
sandboxDialog.value = false
|
|
sandboxKind.value = 'direct'
|
|
sandboxKey.value = ''
|
|
sandboxError.value = ''
|
|
}
|
|
|
|
async function addProvider() {
|
|
if (providerBusy.value) return
|
|
providerBusy.value = true
|
|
providerError.value = ''
|
|
const body: CreateProviderBody = {
|
|
name: providerName.value.trim(),
|
|
kind: providerKind.value,
|
|
}
|
|
if (providerBaseUrl.value.trim()) body.base_url = providerBaseUrl.value.trim()
|
|
if (!llama.value) body.api_key = providerKey.value
|
|
try {
|
|
await api.post<IdResponse>('/provider-configs', body)
|
|
providerName.value = ''
|
|
providerBaseUrl.value = ''
|
|
providerKey.value = ''
|
|
await loadLists()
|
|
providerDialog.value = false
|
|
} catch (err) {
|
|
providerError.value = apiErrorMessage(err)
|
|
} finally {
|
|
providerBusy.value = false
|
|
}
|
|
}
|
|
|
|
async function addSandbox() {
|
|
if (sandboxBusy.value) return
|
|
sandboxBusy.value = true
|
|
sandboxError.value = ''
|
|
const body: CreateSandboxBody = {
|
|
kind: sandboxKind.value,
|
|
name: sandboxName.value.trim(),
|
|
user_name: sandboxUser.value.trim() || 'root',
|
|
workspace_root: sandboxRoot.value.trim() || '/root',
|
|
}
|
|
if (sandboxKind.value === 'direct') {
|
|
body.host = sandboxHost.value.trim()
|
|
body.port = Number(sandboxPort.value) || 22
|
|
}
|
|
if (sandboxKey.value.trim()) body.private_key = sandboxKey.value.trim()
|
|
try {
|
|
const result = await api.post<CreateSandboxResponse>('/sandbox-targets', body)
|
|
if (result.kind === 'tunnel') {
|
|
tunnelSetup.value = {
|
|
id: result.id,
|
|
name: sandboxName.value.trim(),
|
|
privateKey: result.tunnel_private_key ?? '',
|
|
command: result.tunnel_command ?? '',
|
|
}
|
|
}
|
|
sandboxName.value = ''
|
|
sandboxHost.value = ''
|
|
sandboxPort.value = 22
|
|
sandboxUser.value = 'root'
|
|
sandboxRoot.value = '/root'
|
|
sandboxKey.value = ''
|
|
sandboxKind.value = 'direct'
|
|
await loadLists()
|
|
sandboxDialog.value = false
|
|
} catch (err) {
|
|
sandboxError.value = apiErrorMessage(err)
|
|
} finally {
|
|
sandboxBusy.value = false
|
|
}
|
|
}
|
|
|
|
function openTunnelSetup(target: SandboxTarget) {
|
|
tunnelError.value = ''
|
|
copiedTunnel.value = null
|
|
tunnelSetup.value = {
|
|
id: target.id,
|
|
name: target.name,
|
|
privateKey: '',
|
|
command: target.tunnel_command ?? '',
|
|
}
|
|
}
|
|
|
|
async function regenerateTunnelKey() {
|
|
const setup = tunnelSetup.value
|
|
if (!setup || tunnelBusy.value) return
|
|
tunnelBusy.value = true
|
|
tunnelError.value = ''
|
|
try {
|
|
const result = await api.post<CreateSandboxResponse>(`/sandbox-targets/${setup.id}/tunnel-key`)
|
|
setup.privateKey = result.tunnel_private_key ?? ''
|
|
setup.command = result.tunnel_command ?? setup.command
|
|
copiedTunnel.value = null
|
|
await loadLists()
|
|
} catch (err) {
|
|
tunnelError.value = apiErrorMessage(err)
|
|
} finally {
|
|
tunnelBusy.value = false
|
|
}
|
|
}
|
|
|
|
async function copyTunnelValue(value: string, key: string) {
|
|
try {
|
|
await navigator.clipboard.writeText(value)
|
|
copiedTunnel.value = key
|
|
window.setTimeout(() => {
|
|
if (copiedTunnel.value === key) copiedTunnel.value = null
|
|
}, 1800)
|
|
} catch {
|
|
tunnelError.value = 'The clipboard is not available. Select the text and copy it by hand.'
|
|
}
|
|
}
|
|
|
|
async function removeProvider(provider: ProviderConfig) {
|
|
if (deleteBusy.value) return
|
|
deleteBusy.value = true
|
|
rowError.value = ''
|
|
try {
|
|
await api.del(`/provider-configs/${provider.id}`)
|
|
deletingProvider.value = null
|
|
await loadLists()
|
|
} catch (err) {
|
|
rowError.value = apiErrorMessage(err)
|
|
} finally {
|
|
deleteBusy.value = false
|
|
}
|
|
}
|
|
|
|
async function removeTarget(target: SandboxTarget) {
|
|
if (deleteBusy.value) return
|
|
deleteBusy.value = true
|
|
rowError.value = ''
|
|
try {
|
|
await api.del(`/sandbox-targets/${target.id}`)
|
|
deletingTarget.value = null
|
|
await loadLists()
|
|
} catch (err) {
|
|
rowError.value = apiErrorMessage(err)
|
|
} finally {
|
|
deleteBusy.value = false
|
|
}
|
|
}
|
|
|
|
async function testTarget(target: SandboxTarget) {
|
|
if (testingTarget.value) return
|
|
testingTarget.value = target.id
|
|
rowError.value = ''
|
|
try {
|
|
testResults.value[target.id] = await api.post<TestSandboxResponse>(`/sandbox-targets/${target.id}/test`)
|
|
} catch (err) {
|
|
rowError.value = apiErrorMessage(err)
|
|
} finally {
|
|
testingTarget.value = null
|
|
}
|
|
}
|
|
|
|
async function copyKey(target: SandboxTarget) {
|
|
try {
|
|
await navigator.clipboard.writeText(target.public_key)
|
|
copiedKey.value = target.id
|
|
window.setTimeout(() => {
|
|
if (copiedKey.value === target.id) copiedKey.value = null
|
|
}, 1800)
|
|
} catch {
|
|
rowError.value = 'The clipboard is not available. Select the key and copy it by hand.'
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div class="page">
|
|
<div class="page-head">
|
|
<h1 class="page-title">Settings</h1>
|
|
</div>
|
|
|
|
<p v-if="loadError" class="form-error" role="alert">{{ loadError }}</p>
|
|
<p v-if="rowError" class="form-error" role="alert">{{ rowError }}</p>
|
|
<p v-if="loading" class="meta">Loading settings.</p>
|
|
|
|
<section class="section">
|
|
<div class="section-head">
|
|
<h2 class="section-title">Providers</h2>
|
|
<button type="button" class="btn btn-sm" @click="openProviderDialog">
|
|
<Plus :size="14" aria-hidden="true" />
|
|
Add provider
|
|
</button>
|
|
</div>
|
|
<p class="hint">A provider holds a backend and how to reach it. Each room picks a model from its provider.</p>
|
|
|
|
<div v-if="!loading && providers.length === 0" class="empty">No providers yet. Use Add provider to connect one.</div>
|
|
|
|
<div v-else class="list">
|
|
<div v-for="provider in providers" :key="provider.id" class="settings-row">
|
|
<div class="settings-row-main">
|
|
<div class="settings-row-title">{{ provider.name }}</div>
|
|
<div class="settings-row-detail">
|
|
{{ kindLabel(provider.kind) }}<template v-if="provider.base_url">, {{ provider.base_url }}</template>
|
|
</div>
|
|
</div>
|
|
<div class="settings-row-actions">
|
|
<template v-if="deletingProvider === provider.id">
|
|
<div class="confirm-line">
|
|
<span>Delete {{ provider.name }}?</span>
|
|
<button type="button" class="btn btn-sm btn-quiet" :disabled="deleteBusy" @click="deletingProvider = null">
|
|
Cancel
|
|
</button>
|
|
<button type="button" class="btn btn-sm btn-danger" :disabled="deleteBusy" @click="removeProvider(provider)">
|
|
{{ deleteBusy ? 'Deleting' : 'Delete' }}
|
|
</button>
|
|
</div>
|
|
</template>
|
|
<button
|
|
v-else
|
|
type="button"
|
|
class="icon-btn"
|
|
aria-label="Delete provider"
|
|
title="Delete provider"
|
|
@click="deletingProvider = provider.id"
|
|
>
|
|
<Trash2 :size="16" aria-hidden="true" />
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<BaseDialog
|
|
v-if="providerDialog"
|
|
:title="providerDialogTitle"
|
|
:description="providerDialogDescription"
|
|
@close="closeProviderDialog"
|
|
>
|
|
<form v-if="!loginId" class="form" @submit.prevent="submitProvider">
|
|
<div class="form-grid">
|
|
<div class="field">
|
|
<label class="field-label" for="provider-name">Name</label>
|
|
<input id="provider-name" v-model="providerName" class="input" type="text" maxlength="60" autofocus required>
|
|
</div>
|
|
<div class="field">
|
|
<label class="field-label" for="provider-kind">Kind</label>
|
|
<select id="provider-kind" v-model="providerKind" class="select">
|
|
<option v-for="kind in kinds" :key="kind" :value="kind">{{ kindLabel(kind) }}</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div v-if="!flowKind" class="field">
|
|
<label class="field-label" for="provider-base">
|
|
{{ llama ? 'Server URL' : 'Base URL' }}
|
|
<span v-if="!llama" class="field-optional">optional</span>
|
|
</label>
|
|
<input
|
|
id="provider-base"
|
|
v-model="providerBaseUrl"
|
|
class="input"
|
|
type="text"
|
|
spellcheck="false"
|
|
:placeholder="llama ? 'http://127.0.0.1:8080' : 'https://api.example.com/v1'"
|
|
:required="llama"
|
|
>
|
|
<span v-if="llama" class="hint">The address of the llama.cpp server.</span>
|
|
</div>
|
|
|
|
<div v-if="!flowKind && !llama" class="field">
|
|
<label class="field-label" for="provider-key">API key</label>
|
|
<input
|
|
id="provider-key"
|
|
v-model="providerKey"
|
|
class="input"
|
|
type="password"
|
|
autocomplete="off"
|
|
spellcheck="false"
|
|
required
|
|
>
|
|
<span class="hint">The key is sealed on the server and never shown again.</span>
|
|
</div>
|
|
|
|
<p v-if="providerError" class="form-error" role="alert">{{ providerError }}</p>
|
|
|
|
<div class="dialog-actions">
|
|
<button type="button" class="btn" :disabled="providerBusy" @click="closeProviderDialog">Cancel</button>
|
|
<button type="submit" class="btn btn-primary" :disabled="providerBusy">
|
|
{{ providerBusy ? (flowKind ? 'Starting' : 'Adding') : flowKind ? 'Sign in' : 'Add provider' }}
|
|
</button>
|
|
</div>
|
|
</form>
|
|
|
|
<div v-else class="signin" aria-live="polite">
|
|
<p v-if="!loginStatus || loginStatus.status === 'starting'" class="form-note">Starting sign-in.</p>
|
|
<template v-else>
|
|
<template v-if="loginStatus.status === 'instruct' || loginStatus.status === 'waiting'">
|
|
<p v-if="flowInstruction" class="form-note">{{ flowInstruction }}</p>
|
|
<div v-if="loginUrl || loginCode" class="signin-actions">
|
|
<a
|
|
v-if="loginUrl"
|
|
class="btn btn-primary signin-link"
|
|
:href="loginUrl"
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
>
|
|
Open sign-in page
|
|
<ExternalLink :size="14" aria-hidden="true" />
|
|
</a>
|
|
<button v-if="loginCode" type="button" class="btn" @click="copyLoginCode">
|
|
<component :is="copiedLoginCode ? Check : Copy" :size="14" aria-hidden="true" />
|
|
{{ copiedLoginCode ? 'Copied' : 'Copy code' }}
|
|
</button>
|
|
</div>
|
|
<div v-if="loginCode" class="signin-code">
|
|
<span class="field-label">Code</span>
|
|
<code class="signin-code-value">{{ loginCode }}</code>
|
|
</div>
|
|
<p v-if="loginStatus.message" class="form-note">{{ sentence(loginStatus.message) }}</p>
|
|
<p v-else class="form-note">Waiting for you to finish in the browser.</p>
|
|
</template>
|
|
<p v-else-if="loginStatus.status === 'failed'" class="form-error" role="alert">
|
|
{{ sentence(loginStatus.message ?? 'The sign-in failed.') }}
|
|
</p>
|
|
<p v-if="providerError" class="form-error" role="alert">{{ providerError }}</p>
|
|
</template>
|
|
|
|
<div class="dialog-actions">
|
|
<template v-if="loginStatus?.status === 'failed'">
|
|
<button type="button" class="btn" @click="backToProviderForm">Back</button>
|
|
<button type="button" class="btn btn-primary" :disabled="providerBusy" @click="startProviderLogin">
|
|
Try again
|
|
</button>
|
|
</template>
|
|
<button v-else type="button" class="btn" @click="closeProviderDialog">Cancel</button>
|
|
</div>
|
|
</div>
|
|
</BaseDialog>
|
|
</section>
|
|
|
|
<section class="section">
|
|
<div class="section-head">
|
|
<h2 class="section-title">Sandboxes</h2>
|
|
<button type="button" class="btn btn-sm" @click="openSandboxDialog">
|
|
<Plus :size="14" aria-hidden="true" />
|
|
Add sandbox
|
|
</button>
|
|
</div>
|
|
<p class="hint">A sandbox is an ssh machine the room works on. Direct targets are reached at their address. Reverse SSH targets dial this server, so they can sit behind NAT.</p>
|
|
|
|
<div v-if="!loading && targets.length === 0" class="empty">No sandboxes yet. Use Add sandbox to connect one.</div>
|
|
|
|
<div v-else class="list">
|
|
<div v-for="target in targets" :key="target.id" class="settings-row">
|
|
<div class="settings-row-main">
|
|
<div class="settings-row-title">{{ target.name }}</div>
|
|
<div v-if="target.kind === 'tunnel'" class="settings-row-detail">
|
|
Tunnel port {{ target.port }} on this server, sandbox {{ target.user_name }}@localhost:22
|
|
</div>
|
|
<div v-else class="settings-row-detail">{{ target.user_name }}@{{ target.host }}:{{ target.port }}</div>
|
|
<div class="settings-row-detail">Workspace root: {{ target.workspace_root }}</div>
|
|
<div class="key-line">
|
|
<span class="key-text">{{ target.public_key }}</span>
|
|
<button
|
|
type="button"
|
|
class="btn btn-sm btn-quiet"
|
|
:aria-label="`Copy public key for ${target.name}`"
|
|
title="Copy public key"
|
|
@click="copyKey(target)"
|
|
>
|
|
<component :is="copiedKey === target.id ? Check : Copy" :size="14" aria-hidden="true" />
|
|
{{ copiedKey === target.id ? 'Copied' : 'Copy' }}
|
|
</button>
|
|
</div>
|
|
<div v-if="target.host_fingerprint" class="settings-row-detail">
|
|
Host fingerprint: {{ target.host_fingerprint }}
|
|
</div>
|
|
|
|
<div v-if="testResults[target.id]" class="small" :class="testResults[target.id]?.ok ? 'muted' : 'form-error'">
|
|
{{ testResults[target.id]?.detail }}
|
|
</div>
|
|
</div>
|
|
<div class="settings-row-actions">
|
|
<button
|
|
v-if="target.kind === 'tunnel'"
|
|
type="button"
|
|
class="btn btn-sm"
|
|
@click="openTunnelSetup(target)"
|
|
>
|
|
Setup
|
|
</button>
|
|
<button
|
|
type="button"
|
|
class="btn btn-sm"
|
|
:disabled="testingTarget !== null"
|
|
@click="testTarget(target)"
|
|
>
|
|
{{ testingTarget === target.id ? 'Testing' : 'Test' }}
|
|
</button>
|
|
<template v-if="deletingTarget === target.id">
|
|
<div class="confirm-line">
|
|
<span>Delete {{ target.name }}?</span>
|
|
<button type="button" class="btn btn-sm btn-quiet" :disabled="deleteBusy" @click="deletingTarget = null">
|
|
Cancel
|
|
</button>
|
|
<button type="button" class="btn btn-sm btn-danger" :disabled="deleteBusy" @click="removeTarget(target)">
|
|
{{ deleteBusy ? 'Deleting' : 'Delete' }}
|
|
</button>
|
|
</div>
|
|
</template>
|
|
<button
|
|
v-else
|
|
type="button"
|
|
class="icon-btn"
|
|
aria-label="Delete sandbox"
|
|
title="Delete sandbox"
|
|
@click="deletingTarget = target.id"
|
|
>
|
|
<Trash2 :size="16" aria-hidden="true" />
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<BaseDialog
|
|
v-if="sandboxDialog"
|
|
title="Add sandbox"
|
|
description="The room runs commands on this machine with the matching private key."
|
|
@close="closeSandboxDialog"
|
|
>
|
|
<form class="form" @submit.prevent="addSandbox">
|
|
<div class="form-grid">
|
|
<div class="field">
|
|
<label class="field-label" for="sandbox-name">Name</label>
|
|
<input id="sandbox-name" v-model="sandboxName" class="input" type="text" maxlength="60" autofocus required>
|
|
</div>
|
|
<div class="field">
|
|
<label class="field-label" for="sandbox-kind">Connection</label>
|
|
<select id="sandbox-kind" v-model="sandboxKind" class="select">
|
|
<option value="direct">Direct SSH</option>
|
|
<option value="tunnel">Reverse SSH</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div v-if="sandboxKind === 'direct'" class="form-grid">
|
|
<div class="field">
|
|
<label class="field-label" for="sandbox-host">Host</label>
|
|
<input id="sandbox-host" v-model="sandboxHost" class="input" type="text" spellcheck="false" required>
|
|
</div>
|
|
<div class="field">
|
|
<label class="field-label" for="sandbox-port">Port</label>
|
|
<input id="sandbox-port" v-model.number="sandboxPort" class="input" type="number" min="1" max="65535" required>
|
|
</div>
|
|
</div>
|
|
|
|
<div v-else class="field">
|
|
<span class="hint">
|
|
The server assigns a loopback port. After adding, run the tunnel command on the sandbox and add this target's public key to its authorized_keys.
|
|
</span>
|
|
</div>
|
|
|
|
<div class="field">
|
|
<label class="field-label" for="sandbox-user">SSH user</label>
|
|
<input id="sandbox-user" v-model="sandboxUser" class="input" type="text" spellcheck="false">
|
|
</div>
|
|
|
|
<div class="field">
|
|
<label class="field-label" for="sandbox-root">Workspace root</label>
|
|
<input id="sandbox-root" v-model="sandboxRoot" class="input" type="text" spellcheck="false">
|
|
<span class="hint">An absolute path. Rooms create their workspace below it unless the owner sets one.</span>
|
|
</div>
|
|
|
|
<div class="field">
|
|
<label class="field-label" for="sandbox-key">Private key <span class="field-optional">optional</span></label>
|
|
<textarea
|
|
id="sandbox-key"
|
|
v-model="sandboxKey"
|
|
class="textarea"
|
|
rows="4"
|
|
spellcheck="false"
|
|
placeholder="Leave empty to generate an ed25519 key."
|
|
></textarea>
|
|
</div>
|
|
|
|
<p v-if="sandboxError" class="form-error" role="alert">{{ sandboxError }}</p>
|
|
|
|
<div class="dialog-actions">
|
|
<button type="button" class="btn" :disabled="sandboxBusy" @click="closeSandboxDialog">Cancel</button>
|
|
<button type="submit" class="btn btn-primary" :disabled="sandboxBusy">
|
|
{{ sandboxBusy ? 'Adding' : 'Add sandbox' }}
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</BaseDialog>
|
|
|
|
<BaseDialog
|
|
v-if="tunnelSetup"
|
|
title="Reverse SSH setup"
|
|
:description="`Run the tunnel on ${tunnelSetup.name}, then test the target.`"
|
|
@close="tunnelSetup = null"
|
|
>
|
|
<div class="form">
|
|
<p class="hint">
|
|
Add the target's public key to the sandbox's authorized_keys. The tunnel sshd reads the authorized_keys file this server writes.
|
|
</p>
|
|
|
|
<div class="field">
|
|
<label class="field-label">Tunnel command</label>
|
|
<pre class="command-block">{{ tunnelSetup.command }}</pre>
|
|
<button
|
|
type="button"
|
|
class="btn btn-sm btn-quiet"
|
|
@click="copyTunnelValue(tunnelSetup.command, 'setup-command')"
|
|
>
|
|
<component :is="copiedTunnel === 'setup-command' ? Check : Copy" :size="14" aria-hidden="true" />
|
|
{{ copiedTunnel === 'setup-command' ? 'Copied' : 'Copy' }}
|
|
</button>
|
|
</div>
|
|
|
|
<div class="field">
|
|
<label class="field-label">
|
|
Tunnel private key
|
|
<span v-if="tunnelSetup.privateKey" class="field-optional">shown once</span>
|
|
</label>
|
|
<textarea
|
|
v-if="tunnelSetup.privateKey"
|
|
:value="tunnelSetup.privateKey"
|
|
class="textarea"
|
|
rows="5"
|
|
readonly
|
|
></textarea>
|
|
<p v-else class="hint">
|
|
The key was shown when the target was added. Regenerate it if it was lost; the old key stops working.
|
|
</p>
|
|
<button
|
|
v-if="tunnelSetup.privateKey"
|
|
type="button"
|
|
class="btn btn-sm btn-quiet"
|
|
@click="copyTunnelValue(tunnelSetup.privateKey, 'setup-key')"
|
|
>
|
|
<component :is="copiedTunnel === 'setup-key' ? Check : Copy" :size="14" aria-hidden="true" />
|
|
{{ copiedTunnel === 'setup-key' ? 'Copied' : 'Copy key' }}
|
|
</button>
|
|
</div>
|
|
|
|
<p class="hint">
|
|
Save the key as <code>rhema-tunnel-{{ tunnelSetup.id }}</code> in the directory where you run the command, then run <code>chmod 600</code> on it.
|
|
</p>
|
|
<p v-if="tunnelError" class="form-error" role="alert">{{ tunnelError }}</p>
|
|
|
|
<div class="dialog-actions">
|
|
<button type="button" class="btn" @click="tunnelSetup = null">Close</button>
|
|
<button type="button" class="btn" :disabled="tunnelBusy" @click="regenerateTunnelKey">
|
|
{{ tunnelBusy ? 'Regenerating' : 'Regenerate key' }}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</BaseDialog>
|
|
</section>
|
|
</div>
|
|
</template>
|