add creation of cert and cert-index per pubkey

This commit is contained in:
Jakobus Schürz 2019-09-23 16:41:15 +02:00
parent c8b9cd6150
commit 059749d89a
3 changed files with 75 additions and 6 deletions

View file

@ -23,6 +23,7 @@ def index():
' JOIN user u ON p.user_id = u.id'
' ORDER BY deleted ASC, revoked ASC, p.created DESC'
).fetchall()
print pubkeys[0]
users = db.execute(
'SELECT * FROM user WHERE id = ?', (g.user['id'],)
).fetchone()
@ -154,3 +155,59 @@ def revoke(id):
)
db.commit()
return redirect(url_for('pubkeys.index'))
#--------------#
# Certificates #
#--------------#
@bp.route('/<int:id>/certificates')
@login_required
def certs_index(id):
print "id : " + str(id)
print "user id: " + str(g.user['id'])
db = get_db()
user = db.execute(
'SELECT * FROM user WHERE id = ?', (g.user['id'],)
).fetchone()
pubkey = db.execute(
'SELECT'
' p.id pid, key_name, fullname, ssh_pubkey, p.created, user_id,'
' revoked, deleted, fingerprint'
' FROM pubkeys p'
' JOIN user u ON p.user_id = u.id'
' WHERE p.user_id = ? AND p.id = ?'
' ORDER BY deleted ASC, revoked ASC, p.created DESC', (g.user['id'], id,)
).fetchone()
certificates = db.execute(
'SELECT * FROM certificates c JOIN pubkeys p ON p.id = c.id'
' JOIN user u ON p.user_id = u.id'
' WHERE p.id = ?', (id,)
).fetchall()
#print "PUBKEY: " + pubkey['fingerprint']
#print "CERTIFICATES: " + str(certificates)
#print "USERS" + (users)
return render_template('certificates/index.html', pubkey=pubkey,
user=user, certificates=certificates)
@bp.route('/<int:id>/certificates/create', methods=('GET', 'POST'))
@login_required
def certs_create(id):
pubkey = get_pubkey(id)
print "Pubkey-ID: " + str(id)
print "create new certificate"
return redirect(url_for('pubkeys.index'))
@bp.route('/<int:id>/certificates/revoke')
@login_required
def certs_revoke(id):
print "Pubkey-ID: " + id[0]
print "create new certificate"
print "revoke certificate"
return redirect(url_for('pubkeys.index'))

View file

@ -3,13 +3,15 @@
{% block header %}
<h1>{% block title %}
{% if g.user %}
Certificates for Pubkey {{ g.pubkeys['fullname'] }}
Certificates for Pubkey <br>
{{ pubkey['key_name'] }}
{% else %}
Certificates
{% endif %}
{% endblock %}</h1>
{% if g.user %}
<a class="action" href="{{ url_for('certificates.create') }}">New</a>
<a class="action" href="{{ url_for('pubkeys.certs_create', id=1 ) }}">New</a>
{% endif %}
{% endblock %}
@ -22,7 +24,7 @@
<h1>Certificate ({{ certificate['id'] }}): {{ certificate['key_id'] }} </h1>
</div>
{% if g.user['id'] == pubkey['user_id'] %}
<a class="action" href="{{ url_for('certificates.revoke', id=certificate['id']) }}">Revoke</a>
<a class="action" href="{{ url_for('pubkeys.cert_revoke', id=certificate['id']) }}">Revoke</a>
{% endif %}
</header>
<p class="body{% if pubkey['revoked'] != 0 %} revoked {% endif %}">
@ -35,7 +37,7 @@
</p>
<p class="about">created on {{ certificate['created'].strftime('%Y-%m-%d') }}</p>
</form>
<form action="{{ url_for('certificates.revoke', id=certificate['id']) }}" method="POST">
<form action="{{ url_for('pubkeys.cert_revoke', id=certificate['id']) }}" method="POST">
<input class="danger" type="submit" value="Revoke" onclick="return confirm('Are you sure?');">
</form>
</article>

View file

@ -20,7 +20,14 @@
<article class="post{% if pubkey['revoked'] != 0 %} revoked{% endif %}{% if pubkey['deleted'] != 0 %} deleted{% endif %}">
<header>
<div>
<h1>{% if pubkey['revoked'] != 0 %}<div class="danger">revoked key<div> - {% endif %}({{ pubkey['id'] }}): {{ pubkey['key_name'] }} </h1>
<h1>
<a class="action" href="{{ url_for('pubkeys.certs_index', id=pubkey['id']) }}">
{% if pubkey['revoked'] != 0 %}
<div class="danger">revoked key<div> -
{% endif %}
({{ pubkey['id'] }}): {{ pubkey['key_name'] }}
</a>
</h1>
</div>
{% if g.user['id'] == pubkey['user_id'] %}
<a class="action" href="{{ url_for('pubkeys.update', id=pubkey['id']) }}">Edit</a>
@ -35,8 +42,11 @@
<div name="ssh_pubkey" id="ssh_pubkey">{{ request.form['ssh_pubkey'] or pubkey['ssh_pubkey'] }}</div>
<p class="about">registered on {{ pubkey['created'].strftime('%Y-%m-%d') }}</p>
</form>
<form action="{{ url_for('pubkeys.revoke', id=pubkey['id']) }}" method="POST">
<!--form action="{{ url_for('pubkeys.revoke', id=pubkey['id']) }}" method="POST">
<input class="danger" type="submit" value="Revoke" onclick="return confirm('Are you sure?');">
</form-->
<form action="{{ url_for('pubkeys.certs_index', id=pubkey['id']) }}" method="POST">
<input class="danger" type="submit" value="Certificates">
</form>
</article>
{% if not loop.last %}