{{define "title"}} - Profile: {{.Profile.Name}}{{end}}
{{define "content"}}
<div class="page-header">
    <h2>Profile: {{.Profile.Name}}</h2>
    <div class="page-meta">
        <a href="/sshca">&larr; SSH CA</a>
    </div>
</div>

<div class="card">
    <div class="card-title">Configuration</div>
    <table class="kv-table">
        <tbody>
            <tr><th>Name</th><td>{{.Profile.Name}}</td></tr>
            <tr><th>Max TTL</th><td>{{if .Profile.MaxTTL}}{{.Profile.MaxTTL}}{{else}}&mdash;{{end}}</td></tr>
            <tr>
                <th>Allowed Principals</th>
                <td>
                    {{if .Profile.AllowedPrincipals}}
                    {{range .Profile.AllowedPrincipals}}<code>{{.}}</code> {{end}}
                    {{else}}
                    (any)
                    {{end}}
                </td>
            </tr>
            <tr>
                <th>Extensions</th>
                <td>
                    {{if .Profile.Extensions}}
                    {{range $k, $v := .Profile.Extensions}}<code>{{$k}}</code> {{end}}
                    {{else}}
                    (none)
                    {{end}}
                </td>
            </tr>
            <tr>
                <th>Critical Options</th>
                <td>
                    {{if .Profile.CriticalOptions}}
                    {{range $k, $v := .Profile.CriticalOptions}}<code>{{$k}}{{if $v}}={{$v}}{{end}}</code> {{end}}
                    {{else}}
                    (none)
                    {{end}}
                </td>
            </tr>
        </tbody>
    </table>
</div>

{{if .IsAdmin}}
<div class="card">
    <div class="card-title">Edit Profile</div>
    <details>
        <summary>Update configuration</summary>
        <form method="post" action="/sshca/profile/{{.Profile.Name}}/update">
            {{csrfField}}
            <div class="form-group">
                <label for="edit_max_ttl">Max TTL</label>
                <input type="text" id="edit_max_ttl" name="max_ttl" value="{{.Profile.MaxTTL}}" placeholder="8760h">
            </div>
            <div class="form-group">
                <label for="edit_principals">Allowed Principals <small style="text-transform:none;letter-spacing:0;">(one per line)</small></label>
                <textarea id="edit_principals" name="allowed_principals" rows="3">{{range .Profile.AllowedPrincipals}}{{.}}
{{end}}</textarea>
            </div>
            <div class="form-group">
                <label>Extensions</label>
                <div class="checkbox-group">
                    <label class="checkbox-label"><input type="checkbox" name="extensions" value="permit-pty"{{if index .Profile.Extensions "permit-pty"}} checked{{end}}> permit-pty</label>
                    <label class="checkbox-label"><input type="checkbox" name="extensions" value="permit-agent-forwarding"{{if index .Profile.Extensions "permit-agent-forwarding"}} checked{{end}}> permit-agent-forwarding</label>
                    <label class="checkbox-label"><input type="checkbox" name="extensions" value="permit-port-forwarding"{{if index .Profile.Extensions "permit-port-forwarding"}} checked{{end}}> permit-port-forwarding</label>
                    <label class="checkbox-label"><input type="checkbox" name="extensions" value="permit-X11-forwarding"{{if index .Profile.Extensions "permit-X11-forwarding"}} checked{{end}}> permit-X11-forwarding</label>
                    <label class="checkbox-label"><input type="checkbox" name="extensions" value="permit-user-rc"{{if index .Profile.Extensions "permit-user-rc"}} checked{{end}}> permit-user-rc</label>
                </div>
            </div>
            <details>
                <summary>Critical Options</summary>
                <div class="form-row">
                    <div class="form-group">
                        <label for="edit_force_cmd">Force Command</label>
                        <input type="text" id="edit_force_cmd" name="force_command" value="{{index .Profile.CriticalOptions "force-command"}}">
                    </div>
                    <div class="form-group">
                        <label for="edit_source_addr">Source Address</label>
                        <input type="text" id="edit_source_addr" name="source_address" value="{{index .Profile.CriticalOptions "source-address"}}">
                    </div>
                </div>
            </details>
            <div class="form-actions">
                <button type="submit">Update Profile</button>
            </div>
        </form>
    </details>
</div>

<div class="card">
    <div class="card-title">Admin Actions</div>
    <form method="post" action="/sshca/profile/{{.Profile.Name}}/delete">
        {{csrfField}}
        <button type="submit" class="btn-danger" onclick="return confirm('Delete profile {{.Profile.Name}}?')">Delete Profile</button>
    </form>
</div>
{{end}}
{{end}}
