{% extends "meta.html" %}
{% block title %}
<title>密钥管理 - {{cfg("sr.ht", "site-name")}} meta</title>
{% endblock %}
{% block content %}
<div class="row">
<div class="col-md-12 event-list">
<section class="event">
<h3>SSH 密钥</h3>
{% if any(current_user.ssh_keys) %}
<p>以下 SSH 密钥已关联到你的账户:</p>
<table class="table">
<thead>
<tr>
<th>名称</th>
<th>指纹</th>
<th>添加时间</th>
<th>最后使用</th>
<th></th>
</tr>
</thead>
<tbody>
{% for key in current_user.ssh_keys %}
<tr>
<td>{{key.comment}}</td>
<td>{{key.fingerprint}}</td>
<td>{{key.created|date}}</td>
<td>{{key.last_used|date}}</td>
<td style="width: 6rem">
<form method="POST" action="/keys/delete-ssh/{{key.id}}">
{{csrf_token()}}
<button type="submit" class="btn btn-danger btn-fill">
删除
</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
<form method="POST" action="/keys/ssh-keys">
{{csrf_token()}}
<div class="form-group">
<label for="ssh-key">SSH 公钥:</label>
<input
type="text"
class="form-control {{valid.cls("ssh-key")}}"
id="ssh-key"
name="ssh-key"
aria-describedBy="sshkey-details"
value="{{ssh_key or ""}}"
placeholder="ssh-ed25519 bWFyYmxlY2FrZQo= ..." />
<small id="sshkey-details" class="form-text text-muted">
你的 SSH 公钥列表可通过
<a
href="{{url_for("profile.user_keys_GET",
username=current_user.username)}}"
>{{current_user.canonical_name}}.keys</a> 公开访问
</small>
{{valid.summary("ssh-key")}}
</div>
{{valid.summary()}}
<button type="submit" class="btn btn-primary pull-right">
添加密钥 {{icon("caret-right")}}
</button>
</form>
</section>
<section class="event">
<h3>PGP 密钥</h3>
{% if any(current_user.pgp_keys) %}
<p>以下 PGP 密钥已关联到你的账户:</p>
<table class="table">
<thead>
<tr>
<th>指纹</th>
<th>添加时间</th>
<th>过期时间</th>
<th></th>
</tr>
</thead>
<tbody>
{% for key in current_user.pgp_keys %}
<tr>
<td>{{key.fingerprint_hex}}</td>
<td>{{key.created|date}}</td>
{% if not key.expiration %}
<td>永不过期</td>
{% elif key.expiration > now %}
<td>{{key.expiration|date}}</td>
{% else %}
<td><span class="text-danger">已过期 {{key.expiration|date}}</span></td>
{% endif %}
<td style="width: 6rem">
<form method="POST" action="/keys/delete-pgp/{{key.id}}">
{{csrf_token()}}
<button type="submit" class="btn btn-danger btn-fill">删除</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
{% if tried_to_delete_key_in_use %}
<div class="alert alert-danger">此密钥当前用于邮件加密。请先在
<a href="/privacy">隐私设置</a>中选择其他密钥或禁用邮件加密,
然后再删除此密钥。</div>
{% endif %}
<form method="POST" action="/keys/pgp-keys">
{{csrf_token()}}
<div class="form-group">
<label for="pgp-key">PGP 公钥:</label>
<textarea
class="form-control {{valid.cls("pgp-key")}}"
id="pgp-key"
name="pgp-key"
style="font-family: monospace"
rows="5"
placeholder="-----BEGIN PGP PUBLIC KEY BLOCK-----
[...]
-----END PGP PUBLIC KEY BLOCK-----"
>{{pgp_key or ""}}</textarea>
<div id="gpg-command-section" class="form-text text-muted">
你可以使用以下命令导出 PGP 密钥:<br>
<code id="gpg-command">gpg --armor --export-options export-minimal --export {{email or current_user.email}}</code>
</div>
<small id="sshkey-details" class="form-text text-muted">
你的 PGP 公钥列表可通过
<a
href="{{url_for("profile.user_pgp_keys_GET",
username=current_user.username)}}"
>{{current_user.canonical_name}}.pgp</a> 公开访问
</small>
{{valid.summary("pgp-key")}}
</div>
<button type="submit" class="btn btn-primary pull-right">
添加密钥 {{icon("caret-right")}}
</button>
</form>
</section>
</div>
</div>
{% endblock %}