add create

This commit is contained in:
Mateusz779 2023-04-13 12:55:06 +02:00
parent 6f4f048ce7
commit 78b5d21fbb
2 changed files with 99 additions and 1 deletions

20
app.py
View File

@ -29,9 +29,27 @@ def login():
if auth_token != "" or auth_token is not None: if auth_token != "" or auth_token is not None:
if db.get_user_bytoken(auth_token) is not None: if db.get_user_bytoken(auth_token) is not None:
return render_template('index.html') return render_template('index.html')
return render_template('login.html') return render_template('login.html')
@app.route('/create/conf')
def create_conf():
auth_token = request.cookies.get('auth_token')
if auth_token != "" or auth_token is not None:
if db.get_user_bytoken(auth_token) is None:
return redirect("/login")
return render_template("create.html")
@app.route('/api/createconf', methods=['POST'])
def create_conf_post():
config_name = request.form['config_name']
token_name = request.form['token_name']
key_length = request.form['key_length']
try:
authorized_keys_config = request.form['authorized_keys_config']
except:
pass
@app.route('/api/login', methods=['POST']) @app.route('/api/login', methods=['POST'])
def login_api(): def login_api():
username = request.form['username'] username = request.form['username']

80
templates/create.html Normal file
View File

@ -0,0 +1,80 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Formularz</title>
<style>
/* styl dla całej strony */
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
}
/* styl dla sekcji formularza */
form {
max-width: 500px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2);
}
/* styl dla tytułu formularza */
form h2 {
text-align: center;
font-weight: bold;
margin-bottom: 20px;
}
/* styl dla etykiet formularza */
form label {
display: block;
font-weight: bold;
margin-bottom: 5px;
}
/* styl dla pól formularza */
form input[type="text"],
form input[type="password"],
form textarea {
width: 100%;
padding: 10px;
border: 2px solid #ccc;
border-radius: 5px;
margin-bottom: 20px;
font-size: 16px;
}
/* styl dla przycisku formularza */
form button[type="submit"] {
background-color: #4CAF50;
color: #fff;
border: none;
padding: 10px 20px;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
}
/* styl dla przycisku formularza po najechaniu myszką */
form button[type="submit"]:hover {
background-color: #3e8e41;
}
</style>
</head>
<body>
<h1>Formularz tworzenia pliku konfiguracyjnego</h1>
<form method="POST" action="{{ url_for('submit_form') }}" enctype="multipart/form-data">
<label>Nazwa konfiguracji:</label><br>
<input type="text" name="config_name" required><br><br>
<label>Nazwa tokenu:</label><br>
<input type="text" name="token_name" required><br><br>
<label>Długość klucza:</label><br>
<input type="number" name="key_length" min="1024" required><br><br>
<label>Konfiguracja authorized_keys:</label><br>
<textarea name="authorized_keys_config" rows="4" cols="50"></textarea><br><br>
<input type="submit" value="Wyślij">
</form>
</body>
</html>