Commit c033649c authored by Jeff MrBE4R's avatar Jeff MrBE4R
Browse files

second commit

parent 813d191f
......@@ -317,43 +317,19 @@ def admin_vm():
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)
return render_template('Admin/Edit/adminEditVM.html', APP_NAME=config.Config.APP_NAME, APP_VERSION=config.Config.APP_VERSION, vm=vm)
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'):
if str(request.form['token']).decode('utf8') and str(request.form['ip']).decode('utf8') and str(request.form['enabled']).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,
token=str(request.form['token']).decode('utf8'),
ip=str(request.form['ip']).decode('utf8'),
enabled=enabled,
).where(
database.vms.c.id == int(request.form['id'])
......@@ -372,22 +348,39 @@ def admin_vm():
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['token']).decode('utf8') and str(request.form['ip']).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')
token=str(request.form['token']).decode('utf8'),
ip=str(request.form['ip']).decode('utf8'),
)
)
except:
pass
elif request.form['action'] == str('token.cfg').decode('utf8)'):
### Backup token file
fobj_in = open('/opt/noVNC/token.cfg')
fobj_out = open('/opt/noVNC/token.cfg.bkp', "w")
fobj_out.truncate()
for line in fobj_in:
fobj_out.write(line)
fobj_in.close()
fobj_out.close()
fobj_out = open('/opt/noVNC/token.cfg', 'w')
res = config.Config.conn.execute(
select(
[
database.vms.c.token,
database.vms.c.ip
]
).where(
database.vms.c.enabled == True
)
)
for row in res:
fobj_out.write(str(str(row['vm_uuid']) + ': ' + str(row['address']) + ':5901\n'))
return 'a'
return redirect(url_for('admin_vm'))
elif request.method == 'GET':
return render_template('Admin/View/adminListVMs.html', APP_NAME=config.Config.APP_NAME, APP_VERSION=config.Config.APP_VERSION, vms=get_all_vms())
......
<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">Add a VM</button></div>
<form action="{{ url_for('admin_vm') }}" 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">Add a VM</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>Label</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">
<input name="token" type="text" maxlength="70" required size="9" class="form-control">
</td>
</tr>
<tr>
<td style="border: none; text-align: left;">
<label for="password">Mot de Passe</label>
<label>IP</label>
</td>
<td style="border: none; text-align: left;">
<input name="password" type="password" maxlength="70" required size="9" class="form-control" id="password">
<input name="ip" type="text" maxlength="70" required size="9" class="form-control">
</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>
<td><input name="email" type="email" maxlength="254" required size="9" class="form-control" id="email"></td>
</tr>
</table>
</div>
<div class="modal-footer">
......
{% extends "base.html" %}
{% block content %}
<h1>Modifier une VM</h1>
<div style="margin-left: auto; margin-right: auto; width: 60%;">
<form action="{{ url_for('admin_vm') }}" method=POST>
<table id="userMod">
<tr>
<td colspan="2">
<h1>Informations</h1>
</td>
</tr>
<tr>
<td style="border: none; text-align: left;">
<label>Label</label>
</td>
<td>
<input name="token" type="text" maxlength="70" required size="9" class="form-control" value="{{ vm.token }}">
</td>
</tr>
<tr>
<td style="border: none; text-align: left;">
<label>IP</label>
</td>
<td style="border: none; text-align: left;">
<input name="ip" type="text" maxlength="70" required size="9" class="form-control" value="{{ vm.ip }}">
</td>
</tr>
<tr>
<td style="border: none; text-align: left;">
<label for="enabled">Enabled ?</label>
</td>
<td style="border: none; text-align: left;">
<input type="checkbox" data-toggle="toggle" id="enabled" name="enabled" {% if vm.enabled %} checked {% endif %}>
</td>
</tr>
</table>
<input type="hidden" value="{{ vm.id }}" name="id">
<input type="submit" value="Save" name="action" class="btn btn-success">
<input type="submit" value="Cancel" name="action" class="btn btn-danger" data-dismiss="modal">
</form>
</div>
{% endblock %}
\ No newline at end of file
......@@ -5,7 +5,7 @@
<table class="table table-striped table-bordered table-hover" id="t_users">
<thead>
<tr>
<th>Token</th>
<th>Label</th>
<th>IP</th>
<th>Enabled</th>
<th>Actions</th>
......
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