2022-08-14 13:27:41 -07:00
|
|
|
<script>
|
2023-05-01 16:53:24 -07:00
|
|
|
import { onMount } from 'svelte';
|
2022-11-27 22:03:15 -08:00
|
|
|
import { invoke } from '@tauri-apps/api/tauri';
|
|
|
|
|
2023-04-24 12:05:11 -07:00
|
|
|
import { navigate } from '../lib/routing.js';
|
2023-05-01 16:53:24 -07:00
|
|
|
import { appState, completeRequest } from '../lib/state.js';
|
|
|
|
import ErrorAlert from '../ui/ErrorAlert.svelte';
|
2023-04-24 22:16:25 -07:00
|
|
|
import Link from '../ui/Link.svelte';
|
2023-09-10 14:04:09 -07:00
|
|
|
import KeyCombo from '../ui/KeyCombo.svelte';
|
2022-12-22 19:53:14 -08:00
|
|
|
|
2022-11-23 17:11:44 -08:00
|
|
|
|
2023-05-01 16:53:24 -07:00
|
|
|
// Send response to backend, display error if applicable
|
|
|
|
let error, alert;
|
|
|
|
async function respond() {
|
|
|
|
let {id, approval} = $appState.currentRequest;
|
|
|
|
try {
|
|
|
|
await invoke('respond', {response: {id, approval}});
|
|
|
|
navigate('ShowResponse');
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
if (error) {
|
|
|
|
alert.shake();
|
|
|
|
}
|
|
|
|
error = e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Approval has one of several outcomes depending on current credential state
|
2022-11-27 22:03:15 -08:00
|
|
|
async function approve() {
|
2023-05-01 13:27:28 -07:00
|
|
|
$appState.currentRequest.approval = 'Approved';
|
2022-12-13 21:50:34 -08:00
|
|
|
let status = await invoke('get_session_status');
|
2022-12-13 16:50:44 -08:00
|
|
|
if (status === 'unlocked') {
|
2023-05-01 16:53:24 -07:00
|
|
|
await respond();
|
2022-11-27 22:03:15 -08:00
|
|
|
}
|
2022-12-13 16:50:44 -08:00
|
|
|
else if (status === 'locked') {
|
2023-04-24 12:05:11 -07:00
|
|
|
navigate('Unlock');
|
2022-12-13 16:50:44 -08:00
|
|
|
}
|
2022-11-27 22:03:15 -08:00
|
|
|
else {
|
2023-04-24 12:05:11 -07:00
|
|
|
navigate('EnterCredentials');
|
2022-11-27 22:03:15 -08:00
|
|
|
}
|
2022-11-23 17:11:44 -08:00
|
|
|
}
|
|
|
|
|
2023-05-01 16:53:24 -07:00
|
|
|
// Denial has only one
|
|
|
|
async function deny() {
|
2023-05-01 13:27:28 -07:00
|
|
|
$appState.currentRequest.approval = 'Denied';
|
2023-05-01 16:53:24 -07:00
|
|
|
await respond();
|
2023-05-01 13:27:28 -07:00
|
|
|
}
|
|
|
|
|
2023-05-01 16:53:24 -07:00
|
|
|
// Extract executable name from full path
|
2023-09-18 20:13:29 -07:00
|
|
|
const client = $appState.currentRequest.client;
|
|
|
|
const m = client.exe?.match(/\/([^/]+?$)|\\([^\\]+?$)/);
|
|
|
|
const appName = m[1] || m[2];
|
2023-05-01 16:53:24 -07:00
|
|
|
|
|
|
|
// Executable paths can be long, so ensure they only break on \ or /
|
2023-09-18 20:13:29 -07:00
|
|
|
function breakPath(path) {
|
|
|
|
return path.replace(/(\\|\/)/g, '$1<wbr>');
|
2023-05-01 16:53:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// if the request has already been approved/denied, send response immediately
|
|
|
|
onMount(async () => {
|
|
|
|
if ($appState.currentRequest.approval) {
|
|
|
|
await respond();
|
|
|
|
}
|
|
|
|
})
|
2023-04-23 22:29:12 -07:00
|
|
|
</script>
|
2022-12-19 15:26:44 -08:00
|
|
|
|
2022-08-14 13:27:41 -07:00
|
|
|
|
2023-05-01 16:53:24 -07:00
|
|
|
<!-- Don't render at all if we're just going to immediately proceed to the next screen -->
|
2023-05-06 12:01:56 -07:00
|
|
|
{#if error || !$appState.currentRequest.approval}
|
2023-05-01 16:53:24 -07:00
|
|
|
<div class="flex flex-col space-y-4 p-4 m-auto max-w-xl h-screen items-center justify-center">
|
|
|
|
{#if error}
|
|
|
|
<ErrorAlert bind:this={alert}>
|
|
|
|
{error}
|
|
|
|
<svelte:fragment slot="buttons">
|
|
|
|
<button class="btn btn-sm btn-alert-error" on:click={completeRequest}>Cancel</button>
|
|
|
|
<button class="btn btn-sm btn-alert-error" on:click={respond}>Retry</button>
|
|
|
|
</svelte:fragment>
|
|
|
|
</ErrorAlert>
|
|
|
|
{/if}
|
|
|
|
|
2023-05-06 12:01:56 -07:00
|
|
|
{#if $appState.currentRequest.base}
|
|
|
|
<div class="alert alert-warning shadow-lg">
|
|
|
|
<div>
|
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current flex-shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" /></svg>
|
|
|
|
<span>
|
|
|
|
WARNING: This application is requesting your base (long-lived) AWS credentials.
|
2023-05-06 21:59:24 -07:00
|
|
|
These credentials are less secure than session credentials, since they don't expire automatically.
|
2023-05-06 12:01:56 -07:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
|
2023-04-23 22:29:12 -07:00
|
|
|
<div class="space-y-1 mb-4">
|
|
|
|
<h2 class="text-xl font-bold">{appName ? `"${appName}"` : 'An appplication'} would like to access your AWS credentials.</h2>
|
2023-05-01 16:53:24 -07:00
|
|
|
|
|
|
|
<div class="grid grid-cols-[auto_1fr] gap-x-3">
|
2023-09-18 20:13:29 -07:00
|
|
|
<div class="text-right">Path:</div>
|
|
|
|
<code class="">{@html client.exe ? breakPath(client.exe) : 'Unknown'}</code>
|
|
|
|
<div class="text-right">PID:</div>
|
|
|
|
<code>{client.pid}</code>
|
2023-05-01 16:53:24 -07:00
|
|
|
</div>
|
2023-04-23 22:29:12 -07:00
|
|
|
</div>
|
2022-12-21 13:42:12 -08:00
|
|
|
|
2023-05-01 16:53:24 -07:00
|
|
|
<div class="w-full flex justify-between">
|
|
|
|
<Link target={deny} hotkey="Escape">
|
2023-04-24 22:16:25 -07:00
|
|
|
<button class="btn btn-error justify-self-start">
|
2023-09-10 14:04:09 -07:00
|
|
|
<span class="mr-2">Deny</span>
|
|
|
|
<KeyCombo keys={['Esc']} />
|
2023-04-24 22:16:25 -07:00
|
|
|
</button>
|
|
|
|
</Link>
|
|
|
|
|
2023-05-01 16:53:24 -07:00
|
|
|
<Link target={approve} hotkey="Enter" shift="{true}">
|
2023-04-24 22:16:25 -07:00
|
|
|
<button class="btn btn-success justify-self-end">
|
2023-09-10 14:04:09 -07:00
|
|
|
<span class="mr-2">Approve</span>
|
|
|
|
<KeyCombo keys={['Shift', 'Enter']} />
|
2023-04-24 22:16:25 -07:00
|
|
|
</button>
|
|
|
|
</Link>
|
2023-04-23 22:29:12 -07:00
|
|
|
</div>
|
2023-05-01 16:53:24 -07:00
|
|
|
</div>
|
|
|
|
{/if}
|