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' ' JOIN user u ON p.user_id = u.id'
' ORDER BY deleted ASC, revoked ASC, p.created DESC' ' ORDER BY deleted ASC, revoked ASC, p.created DESC'
).fetchall() ).fetchall()
print pubkeys[0]
users = db.execute( users = db.execute(
'SELECT * FROM user WHERE id = ?', (g.user['id'],) 'SELECT * FROM user WHERE id = ?', (g.user['id'],)
).fetchone() ).fetchone()
@ -154,3 +155,59 @@ def revoke(id):
) )
db.commit() db.commit()
return redirect(url_for('pubkeys.index')) 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 %} {% block header %}
<h1>{% block title %} <h1>{% block title %}
{% if g.user %} {% if g.user %}
Certificates for Pubkey {{ g.pubkeys['fullname'] }} Certificates for Pubkey <br>
{{ pubkey['key_name'] }}
{% else %} {% else %}
Certificates Certificates
{% endif %} {% endif %}
{% endblock %}</h1> {% endblock %}</h1>
{% if g.user %} {% 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 %} {% endif %}
{% endblock %} {% endblock %}
@ -22,7 +24,7 @@
<h1>Certificate ({{ certificate['id'] }}): {{ certificate['key_id'] }} </h1> <h1>Certificate ({{ certificate['id'] }}): {{ certificate['key_id'] }} </h1>
</div> </div>
{% if g.user['id'] == pubkey['user_id'] %} {% 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 %} {% endif %}
</header> </header>
<p class="body{% if pubkey['revoked'] != 0 %} revoked {% endif %}"> <p class="body{% if pubkey['revoked'] != 0 %} revoked {% endif %}">
@ -35,7 +37,7 @@
</p> </p>
<p class="about">created on {{ certificate['created'].strftime('%Y-%m-%d') }}</p> <p class="about">created on {{ certificate['created'].strftime('%Y-%m-%d') }}</p>
</form> </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?');"> <input class="danger" type="submit" value="Revoke" onclick="return confirm('Are you sure?');">
</form> </form>
</article> </article>

View file

@ -20,7 +20,14 @@
<article class="post{% if pubkey['revoked'] != 0 %} revoked{% endif %}{% if pubkey['deleted'] != 0 %} deleted{% endif %}"> <article class="post{% if pubkey['revoked'] != 0 %} revoked{% endif %}{% if pubkey['deleted'] != 0 %} deleted{% endif %}">
<header> <header>
<div> <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> </div>
{% if g.user['id'] == pubkey['user_id'] %} {% if g.user['id'] == pubkey['user_id'] %}
<a class="action" href="{{ url_for('pubkeys.update', id=pubkey['id']) }}">Edit</a> <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> <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> <p class="about">registered on {{ pubkey['created'].strftime('%Y-%m-%d') }}</p>
</form> </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?');"> <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> </form>
</article> </article>
{% if not loop.last %} {% if not loop.last %}