Skip to content
Snippets Groups Projects
Commit 7e5fd33c authored by root's avatar root
Browse files

remove user-mgmt-ui folder to convert as submoddule

parent 1c912715
No related branches found
No related tags found
No related merge requests found
# SOCTools user management web
Simple web GUI for user management in SOCtools.
# Example of minimal working WSGI script
from flask import Flask, render_template, request, make_response, redirect, flash
from flask_wtf import FlaskForm
from wtforms import StringField
from wtforms.validators import DataRequired, Email
import subprocess
app = Flask(__name__)
app.secret_key = "ASDF1234 - CHANGE ME!"
class AddUserForm(FlaskForm):
username = StringField("Username", validators=[DataRequired()])
cn = StringField("Common name (CN)", validators=[DataRequired()])
firstname = StringField("First name", validators=[])
lastname = StringField("Last name", validators=[])
# TODO what about CN/DN - construct from first+last name or allow to redefine?
email = StringField("Email", validators=[DataRequired(), Email()])
@app.route("/", methods=["GET", "POST"])
def main():
# TODO Load existing users (from where?)
users = [{
"firstname": "User1",
"lastname": "SOC",
"username": "user1",
"email": "user1@example.org",
"DN": "CN=User1Soctools",
"CN": "User1Soctools",
},{
"firstname": "User2",
"lastname": "SOC",
"username": "user2",
"email": "user2@example.org",
"DN": "CN=User2Soctools",
"CN": "User2Soctools",
}]
# Add user
form_add_user = AddUserForm()
if form_add_user.validate_on_submit():
# TODO check that username doesn't exist, yet (and check validity, i.e. special characters etc.)
# TODO add user
result = subprocess.run(["echo", "test"], capture_output=True)
if result.returncode == 0:
flash(f'User "{form_add_user.username.data}" successfully created.', "success")
else:
flash(f'Error when creating user: {result.stderr}', "error")
return render_template("main.html", **locals())
# TODO AJAX endpoint to delete user
# TODO edit user? User detail page?
# TODO certificates??
# When the script is run directly, run the application on a local development server.
if __name__ == '__main__':
app.run()
body {
background-color: #fff;
}
table {
border: 1px solid black;
background: #ccc;
min-width: 50%;
}
td {
background: #fff;
}
p {
background-color: #fff;
padding: 0.5em;
}
.errors {
background-color: #fcc;
color: #c00;
}
ul.flashes {
color: #009;
}
li.flash-error {
color: #900;
}
li.flash-success {
color: #090;
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>SOCtools user management</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">
</head>
<body>
{# Flash messages #}
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
<div class="flashes">
{% for category, message in messages %}
<li class="flash-{{category}}">{{ message }}</li>
{% endfor %}
</div>
{% endif %}
{% endwith %}
<h1>SOCtools - User management</h1>
<table>
<tr><th>Username</th><th>First name</th><th>Last name</th><th>CN</th><th>email</th><th></th>
{% for user in users %}
<tr>
<td>{{ user.username }}</td>
<td>{{ user.firstname }}</td>
<td>{{ user.lastname }}</td>
<td>{{ user.CN }}</td>
<td>{{ user.email }}</td>
<td>... {#TODO actions#}</td>
</tr>
{% endfor %}
</table>
<p></p>
<h2>Add new user</h2>
<form action="{{ url_for("main") }}" method="POST">
{% if form_add_user.errors %}
<ul class="errors">
{% for field, errors in form_add_user.errors.items() %}
<li>{{ form_add_user[field].label if field else "" }}: {{ ' | '.join(errors) }}</li>
{% endfor %}
</ul>
{% endif %}
{{ form_add_user.csrf_token }}
{{ form_add_user.username.label }} {{ form_add_user.username(size=20) }}<br>
{{ form_add_user.firstname.label }} {{ form_add_user.firstname(size=20) }}<br>
{{ form_add_user.lastname.label }} {{ form_add_user.lastname(size=20) }}<br>
{{ form_add_user.cn.label }} {{ form_add_user.cn(size=20) }}<br>
{{ form_add_user.email.label }} {{ form_add_user.email(size=20) }}<br>
<input type="submit" value="Add user">
</form>
</body>
</html>
\ No newline at end of file
from main import app as application
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment