fix functions delete/edit/... on different state

This commit is contained in:
Jakobus Schürz 2019-09-30 01:38:23 +02:00
parent 1f52e54211
commit be374f5d77
5 changed files with 61 additions and 61 deletions

View file

@ -69,7 +69,8 @@ def create():
print(fingerprint)
ckfp = db.execute(
'SELECT id, fingerprint, deleted FROM pubkeys WHERE fingerprint = ?', (fingerprint, )
'SELECT id, fingerprint, deleted FROM pubkeys'
' WHERE fingerprint = ? AND user_id = ?', (fingerprint, g.user['id'] )
).fetchone()

View file

@ -29,4 +29,4 @@ nav ul li a, nav ul li span, header .action { display: block; padding: 0.5rem; }
.danger { color: #cc2f2e; }
input.danger { color: #cc2f2e; }
input[type=submit] { align-self: start; min-width: 10em; }
.key { color: #cc22ff; }
.key { border: 1px solid lightgray;}

View file

@ -8,7 +8,7 @@
Certificates
{% endif %}</h1>
{% endblock %}
{% if g.user %}
{% if g.user and pubkey['revoked'] == 0 %}
<!--a class="action" href="{{ url_for('pubkeys.certs_create', id=1 ) }}">New</a-->
<form class="action" action="{{ url_for('pubkeys.certs_create', id=pubkey['id'] ) }}" method="POST">
<input type="submit" value="Create new certificate">
@ -26,43 +26,43 @@
{% block content %}
{% if g.user %}
{% for certificate in certificates %}
{% if certificate['deleted'] == 0 and pubkey['user_id'] == g.user['id'] %}
{% if ( certificate['deleted'] == 0 and pubkey['user_id'] == g.user['id'] ) or user['admin'] == 1 %}
<article class="post">
<header>
<div>
<h1>Certificate ID: {{ certificate['key_id'] }} </h1>
{% if certificate['revoked'] != 0 %}
<div class="info">this certificate was manually revoked</div>
<div>
<h1>
Certificate ID: {{ certificate['key_id'] }}
</h1>
{% if certificate['revoked'] != 0 %}
<div class="info">this certificate was manually revoked</div>
{% endif %}
</div>
{% if g.user['id'] == certificate['user_id'] %}
{% if certificate['revoked'] == 0 or certificate['valid'] == 0 %}
<form action="{{ url_for('pubkeys.certs_revoke', id=certificate['pubkey_id'], cid=certificate['id']) }}" method="POST">
<input class="danger" type="submit" value="Revoke cert" onclick="return confirm('Are you sure?');">
</form>
{% else %}
<div class="action">revoked</div>
<a class="action" href="{{ url_for('pubkeys.certs_delete', id=certificate['pubkey_id'], cid=certificate['id']) }}">Delete</a>
{% endif %}
{% endif %}
</div>
{% if g.user['id'] == certificate['user_id'] %}
{% if certificate['revoked'] == 0 or certificate['valid'] == 0 %}
<form action="{{ url_for('pubkeys.certs_revoke', id=certificate['pubkey_id'], cid=certificate['id']) }}" method="POST">
<input class="danger" type="submit" value="Revoke cert" onclick="return confirm('Are you sure?');">
</form>
{% else %}
<div class="action">revoked</div>
<a class="action" href="{{ url_for('pubkeys.certs_delete', id=certificate['pubkey_id'], cid=certificate['id']) }}">Delete</a>
{% endif %}
{% endif %}
</header>
<p class="body{% if certificate['revoked'] != 0 %} revoked {% endif %}">
Serialnumber: {{ certificate['serial'] }}{% if certificate['c.revoked'] != 0 %} - revoked {% endif %}
Validity duration: {{ certificate['valid_from'].strftime('%Y-%m-%d %H:%M') }} - {{ certificate['valid_until'].strftime('%Y-%m-%d %H:%M') }}
Principals: {{ certificate['principals'] }}
Valid Client IP: {{ certificate['from_ip'] }}
Allowed Command: {{ certificate['commands'] }}
Capabilities: {{ certificate['capabilities'] }}
Internal DB-Id: {{ certificate['id'] }}
Deleted: {{ certificate['deleted'] }}
{% if user['admin'] == 1 %}
<div name="owner" id="owner">owner: {{ pubkey['username']}}</div>
{% endif %}
Serialnumber: {{ certificate['serial'] }}{% if certificate['c.revoked'] != 0 %} - revoked {% endif %}
Validity duration: {{ certificate['valid_from'].strftime('%Y-%m-%d %H:%M') }} - {{ certificate['valid_until'].strftime('%Y-%m-%d %H:%M') }}
Principals: {{ certificate['principals'] }}
Valid Client IP: {{ certificate['from_ip'] }}
Allowed Command: {{ certificate['commands'] }}
Capabilities: {{ certificate['capabilities'] }}
Internal DB-Id: {{ certificate['id'] }}
Deleted: {{ certificate['deleted'] }}
</p>
<p class="about">created on {{ certificate['created'].strftime('%Y-%m-%d') }}</p>
{% if certificate['revoked'] == 0 %}
</form>
{% endif %}
</article>
{% if not loop.last %}
<hr>

View file

@ -17,40 +17,41 @@
{% if g.user %}
{% for pubkey in pubkeys %}
{% if ( pubkey['deleted'] == 0 and pubkey['user_id'] == g.user['id'] ) or user['admin'] == 1 %}
<article class="post{% if pubkey['revoked'] != 0 %} revoked{% endif %}{% if pubkey['deleted'] != 0 %} deleted{% endif %}">
<article class="post{% if pubkey['deleted'] != 0 %} deleted{% endif %}">
<header>
<div>
<h1>
<a class="action" href="{{ url_for('pubkeys.certs_index', id=pubkey['id']) }}">
{% if pubkey['revoked'] != 0 %}
<div class="danger">revoked key<div> -
{% endif %}
<!--a class="action" href="{{ url_for('pubkeys.certs_index', id=pubkey['id']) }}">
({{ pubkey['id'] }}): {{ pubkey['key_name'] }}
</a>
</a-->
({{ pubkey['id'] }}): {{ pubkey['key_name'] }}
</h1>
{% if pubkey['revoked'] != 0 %}
<div class="info">this pubkey was revoked manually</div>
{% endif %}
</div>
{% if g.user['id'] == pubkey['user_id'] %}
<a class="action" href="{{ url_for('pubkeys.update', id=pubkey['id']) }}">Edit</a>
{% if pubkey['deleted'] == 0 %}
<a class="action" href="{{ url_for('pubkeys.delete', id=pubkey['id']) }}" onclick="return confirm('Are you sure?');">Delete</a>
<a class="action" href="{{ url_for('pubkeys.deletefinal', id=pubkey['id']) }}" onclick="return confirm('Are you sure?');">Delete final</a>
{% endif %}
{% if pubkey['revoked'] == 0 %}
<a class="action" href="{{ url_for('pubkeys.revoke', id=pubkey['id']) }}" onclick="return confirm('Are you sure?');">Revoke</a>
{% endif %}
<a class="action" href="{{ url_for('pubkeys.update', id=pubkey['id']) }}">Edit</a>
{% if pubkey['deleted'] == 0 %}
{% endif %}
{% if pubkey['revoked'] == 0 %}
<form action="{{ url_for('pubkeys.revoke', id=pubkey['id']) }}" method="POST">
<input class="danger" type="submit" value="Revoke cert" onclick="return confirm('Are you sure?');">
</form>
{% else %}
<a class="action" href="{{ url_for('pubkeys.delete', id=pubkey['id']) }}" onclick="return confirm('Are you sure?');">Delete</a>
{% endif %}
{% endif %}
</header>
{% if user['admin'] == 1 %}
<div name="owner" id="owner">owner: {{ pubkey['username']}}</div>
{% endif %}
<div name="fingerprint" id="fingerprint">fingerprint: {{ pubkey['fingerprint'] }}</div>
<br>
<div class="key" name="ssh_pubkey" id="ssh_pubkey">{{ request.form['ssh_pubkey'] or pubkey['ssh_pubkey'] }}</div>
<div class="body {% if pubkey['revoked'] != 0 %} revoked{% endif %}">
<!--div class="body"-->
{% if user['admin'] == 1 %}
<div name="owner" id="owner">owner: {{ pubkey['username']}}</div>
{% endif %}
<div>fingerprint: <div class="key" name="fingerprint" id="fingerprint">{{ pubkey['fingerprint'] }}</div></div>
<div>pubkey: <div class="key" name="ssh_pubkey" id="ssh_pubkey">{{ request.form['ssh_pubkey'] or pubkey['ssh_pubkey'] }}</div></div>
</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">
<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 type="submit" value="Certificates">
</form>

View file

@ -5,6 +5,9 @@
{% endblock %}
{% block content %}
<form action="{{ url_for('pubkeys.deletefinal', id=pubkey['id']) }}" method="post">
<input class="danger" type="submit" value="Delete final" onclick="return confirm('Are you sure?');">
</form>
<form method="post">
<label for="key_name">SSH-Pubkey ({{ pubkey['id'] }}) {{ pubkey['deleted'] }}</label>
<input name="key_name" id="key_name"
@ -19,9 +22,4 @@
<input type="submit" value="Save">
</form>
<hr>
<ul>
<li><form action="{{ url_for('pubkeys.delete', id=pubkey['id']) }}" method="post">
<input class="danger" type="submit" value="Delete" onclick="return confirm('Are you sure?');">
</form>
</ul>
{% endblock %}