Commit 813d191f authored by Jeff MrBE4R's avatar Jeff MrBE4R
Browse files

second commit

parent 05fc976c
......@@ -89,6 +89,7 @@ def get_all_links():
links = config.Config.conn.execute(
select(
[
database.users_vms.c.id,
database.users.c.fullname,
database.vms.c.token,
]
......@@ -401,84 +402,33 @@ def admin_link():
if 'logged_in' in session:
if session['can_view_admin'] == str('True').decode('utf8'):
if request.method == 'POST':
if str(request.form['action']).decode('utf8') == str('Edit').decode('utf8'):
vm = get_vm_by_id(int(request.form['id']))
for u in vm:
vm = u
return render_template('Admin/Edit/adminEditVM.html', APP_NAME=config.Config.APP_NAME, APP_VERSION=config.Config.APP_VERSION, vm=user)
elif str(request.form['action']).decode('utf8') == str('Save').decode('utf8'):
if request.form.get('can_view_admin'):
can_view_admin = True
else:
can_view_admin = False
if request.form.get('enabled'):
enabled = True
else:
enabled = False
if str(request.form['login']).decode('utf8') and str(request.form['fullname']).decode('utf8') and str(request.form['email']).decode('utf8'):
if str(request.form['password']).decode('utf8') and str(request.form['password_confirm']).decode('utf8'):
if str(request.form['password']).decode('utf8') == str(request.form['password_confirm']).decode('utf8'):
try:
config.Config.conn.execute(
database.vms.update().values(
login=str(request.form['login']).decode('utf8'),
fullname=str(request.form['fullname']).decode('utf8'),
password=str(hashlib.sha256(str(request.form['password']).decode('utf8')).hexdigest()).decode('utf8'),
email=str(request.form['email']).decode('utf8'),
can_view_admin=can_view_admin,
enabled=enabled,
).where(
database.vms.c.id == int(request.form['id'])
)
)
except:
pass
try:
config.Config.conn.execute(
database.vms.update().values(
login=str(request.form['login']).decode('utf8'),
fullname=str(request.form['fullname']).decode('utf8'),
email=str(request.form['email']).decode('utf8'),
can_view_admin=can_view_admin,
enabled=enabled,
).where(
database.vms.c.id == int(request.form['id'])
)
)
except:
pass
elif request.form['action'] == str('Delete').decode('utf8'):
if request.form['action'] == str('Delete').decode('utf8'):
if str(request.form['id']).decode('utf8'):
try:
config.Config.conn.execute(
database.vms.delete().where(
database.vms.c.id == int(request.form['id'])
database.users_vms.delete().where(
database.users_vms.c.id == int(request.form['id'])
)
)
except:
pass
elif request.form['action'] == str('Add').decode('utf8'):
if str(request.form['login']).decode('utf8') \
and str(request.form['password']).decode('utf8') \
and str(request.form['password_confirm']).decode('utf8') \
and str(request.form['fullname']).decode('utf8') \
and str(request.form['email']).decode('utf8'):
if str(request.form['user-to-link']).decode('utf8') \
and str(request.form['server-to-link']).decode('utf8'):
try:
config.Config.conn.execute(
database.vms.insert().values(
login=str(request.form['login']).decode('utf8'),
password=str(hashlib.sha256(str(request.form['password']).decode('utf8')).hexdigest()).decode('utf8'),
fullname=str(request.form['fullname']).decode('utf8'),
email=str(request.form['email']).decode('utf8')
database.users_vms.insert().values(
user=int(request.form['user-to-link']),
vm=int(request.form['server-to-link']),
)
)
except:
import sys,traceback
print sys.exc_info()
pass
return redirect(url_for('admin_vm'))
return redirect(url_for('admin_link'))
elif request.method == 'GET':
return render_template('Admin/View/adminListLinks.html', APP_NAME=config.Config.APP_NAME, APP_VERSION=config.Config.APP_VERSION, links=get_all_links())
return render_template('Admin/View/adminListLinks.html', APP_NAME=config.Config.APP_NAME, APP_VERSION=config.Config.APP_VERSION, links=get_all_links(), users=get_all_users(), vms=get_all_vms())
else:
return redirect(url_for('home_page'))
else:
......
<div style="width: 33%; margin-left: auto; margin-right: auto;"><button class="btn btn-success" data-toggle="modal" data-target="#myModal">Ajouter un Utilisateur</button></div>
<form action="{{ url_for('admin_user') }}" method=POST>
<div style="width: 33%; margin-left: auto; margin-right: auto;"><button class="btn btn-success" data-toggle="modal" data-target="#myModal">Set User <=> VM link</button></div>
<form action="{{ url_for('admin_link') }}" method=POST>
<div style="display: none;" class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="divue">×</button>
<h4 class="modal-title" id="myModalLabel">Ajouter un utilisateur</h4>
<h4 class="modal-title" id="myModalLabel">Set User <=> VM link</h4>
</div>
<div class="modal-body" style="display: inline-block; width: 100%;">
<table id="userMod">
<tr>
<td style="border: none; text-align: left;">
<label for="login">Login</label>
<label>User</label>
</td>
<td>
<input type="hidden" value="newUser" name="todo">
<input name="login" type="text" maxlength="70" required size="9" id="login" class="form-control">
<label>VMs</label>
</td>
</tr>
<tr>
<td style="border: none; text-align: left;">
<label for="password">Mot de Passe</label>
<select class="form-control" name="user-to-link">
{% for u in users %}
<option value="{{ u.id }}">{{ u.fullname }}</option>
{% endfor %}
</select>
</td>
<td style="border: none; text-align: left;">
<input name="password" type="password" maxlength="70" required size="9" class="form-control" id="password">
</td>
</tr>
<tr>
<td style="border: none; text-align: left;">
<label for="password_confirm">Confirmation du Mot de Passe</label>
</td>
<td style="border: none; text-align: left;">
<input name="password_confirm" type="password" maxlength="70" required size="9" id="cpswd_con" class="form-control" id="password_confirm">
</td>
</tr>
<tr>
<td style="border: none; text-align: left;">
<label for="fullname">Nom complet</label>
</td>
<td><input name="fullname" type="text" maxlength="70" required size="9" class="form-control" id="fullname"></td>
</tr>
<tr>
<td style="border: none; text-align: left;">
<label for="email">Email</label>
<td>
<select class="form-control" name="server-to-link">
{% for vm in vms %}
<option value="{{ vm.id }}">{{ vm.token }}</option>
{% endfor %}
</select>
</td>
<td><input name="email" type="email" maxlength="254" required size="9" class="form-control" id="email"></td>
</tr>
</table>
</div>
......
{% extends "base.html" %}
{% block content %}
{% if session['can_view_admin'] == 'True' %}
{% include 'Admin/Edit/adminAddVM.html' %}
{% include 'Admin/Edit/adminAddLink.html' %}
<table class="table table-striped table-bordered table-hover" id="t_users">
<thead>
<tr>
......@@ -18,26 +18,13 @@
</td>
<td>{{ link.token }}</td>
<td>
<table style="border: none;">
<tr style="border: none;">
<td style="border: none;">
<form action="{{ url_for('admin_vm') }}" method=POST>
<input type="hidden" value="edit" name="todo">
<input type="hidden" value="{{ link.id }}" name="id">
<input type="submit" value="Edit" name="action" class="btn btn-primary">
</form>
</td>
<td style="border: none;">
<form action="{{ url_for('admin_vm') }}" method=POST>
<form action="{{ url_for('admin_link') }}" method=POST>
<input type="hidden" value="edit" name="todo">
<input type="hidden" value="{{ link.id }}" name="id">
<input type="submit" value="Delete" name="action" class="btn btn-danger">
</form>
</td>
</tr>
</table>
</td>
</tr>
{% endfor %}
</tbody>
</table>
......
......@@ -22,9 +22,6 @@
<link href="/static/theme/bower_components/bootstrap-toggle/css/bootstrap-toggle.css" rel="stylesheet">
<link rel=stylesheet type=text/css href="/static/style.css">
<script src="/static/scripts/jquery.min.2.1.1.js"></script>
<script src="/static/scripts/socket.io.min.0.9.16.js"></script>
<script src="/static/scripts/tinymce.min.4.1.js"></script>
<script src="/static/scripts/d3.v3.min.js"></script>
<script src="/static/theme/bower_components/jquery/dist/jquery.min.js"></script>
<script src="/static/theme/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="/static/theme/bower_components/metisMenu/dist/metisMenu.min.js"></script>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment