<div class="pure-u-1">
    <p>
        This page allows you to add, view and remove ssh keys to and from your distillery account.
    </p>
</div>

<div class="pure-u-1">
    <h2>My SSH Keys</h2>
    <p>
        This table shows ssh keys currently associated with your account.
        To add a new key, use the <em>Add New Key</em> button above.
        To remove an ssh key from your account, simply click the <em>Delete</em> button.
    </p>
    <div class="padding">
        <div class="overflow">

            <table class="pure-table pure-table-bordered">
                <thead>
                    <tr>
                        <th>
                            Comment
                        </th>
                        <th>
                            Signature
                        </th>
                        <th>
                            Actions
                        </th>
                    </tr>
                </thead>
                <tbody>
                    {{ $csrf := .CSRF }}
                    {{ range .Keys }}
                        {{ $sig := .SignatureString }}
                        <tr>
                            <td>
                                {{ .Comment }}
                            </td>
                            <td>
                                <code>
                                    {{ $sig }}
                                </code>
                            </td>
                            <td>
                                <div class="pure-button-group" role="group">
                                    <form action="/user/ssh/delete" method="POST" class="pure-form-group">
                                        <input type="hidden" name="signature" value="{{ $sig }}">
                                        <input type="submit" class="pure-button pure-button-danger" value="Delete">
                                        {{ $csrf }}
                                    </form>
                                </div>
                            </td>
                        </tr>
                    {{ end }}
                </tbody>
            </table>
        </div>
    </div>
</div>

<div class="pure-u-1-2">
    <h2 id="configuring-ssh-access">Configuring SSH Access</h2>
    <p>
        You can use these ssh keys to connect to the distillery via ssh.
        You can only connect to instances for which you appear as an <em>Administrator</em> on your user page.
    </p>
    <p>
        In the following we will provide instructions on how to connect to your WissKI instance via the distillery server. 
        In the following we will assume <code>{{ .Slug }}</code> is the name of the WissKI you want to you want to connect to.
    </p>
    <p>
        From a Linux (or Mac, or Windows 11) command line you may use:
    </p>
    <code class="copy">
        ssh -J {{ .PanelDomain }}:{{ .Port }} www-data@{{ .Hostname }}
    </code>
    <p>
        You may also place the following into your <code>$HOME/.ssh/config</code> file:
    </p>
    <code class="copy">
<pre>Host *.{{ .Domain }}
    ProxyJump {{ .Domain }}.proxy
    User www-data
Host {{ .Domain }}.proxy
    User www-data
    Hostname {{ .PanelDomain }}
    Port {{ .Port }}
</pre>
    </code>

    <p>
        and then connect simply via:
    </p>

    <code>
        ssh {{ .Hostname }}
    </code>
</div>

<div class="pure-u-1-2">
    <h2 id="accessing-services">Accessing Services</h2>

    <p>
        You can access the services powering the distillery if you have ssh access.
            To access a service, simply use ssh port forwarding, and then access them under <code>localhost</code>.
            Port forwarding is accomplished by appending  <code>-L localport:service:serverport</code> to your ssh command line.
    </p>
    <p>
        For example to connect to the triplestore, you can use:
    </p>
    <code class="copy">
        <pre>
ssh -p {{ .Port }} {{ .PanelDomain }} -L 7200:triplestore:7200
</pre>
    </code>
    <p>
        and then go to <a target="_blank" rel="noopener noreferrer" href="http://127.0.0.1:7200/">http://127.0.0.1:7200/</a>.
    </p>

    <p>
        Note that you can add port forwards both when connecting to the top-level distillery ssh server as well as any instance - the syntax is identical.
        You can also add multiple forwards at the same time, by adding multiple <code>-L</code> arguments. 
    </p>
    
    <p>
        The complete list of services you can access are:
        <ul>
            {{ range .Services }}
            <li>
                <b>{{ .Description }}</b>, use <code class="copy">-L {{.ExamplePort}}:{{ .Match.Host }}:{{.Match.Port}}</code> and access at <code>127.0.0.1:{{.ExamplePort}}</code>
            </li>
            {{ end }}
        </ul>
    </p>

    <p>
        Depending on the service you may need an additional password.
        Distillery administrators can reveal these passwords in the admin interface.
        Furthermore instance-specific passwords can typically be found in the <em>Drupal Configuration</em>, system-wide passwords in the <em>Distillery Configuration</em>.
    </p>
</div>
