Changes to web gui and fixes

This commit is contained in:
2020-07-03 18:37:34 +02:00
parent 609d821501
commit 3deb367e89
9 changed files with 94 additions and 25 deletions

View File

@@ -38,12 +38,15 @@ def returnvalueapi(suburl,field="Name"):
r=(requests.post(c_server+suburl+twopart, verify=False).text).replace("\'", "\"").replace('\\"',"'").replace(': None',': "None"')
try:
#print(suburl+twopart+"->"+r)
#print(suburl+twopart+"->"+r)
jsonobj = json.loads(r)
if isinstance(jsonobj, list):
print("LIST")
jsonobj = jsonobj[0]
return jsonobj[field]
except:
print('Error: '+str(r))
return str({'TEXT':r,'RESULT':'ERROR'})
print('Error: '+str(r))
return str({'TEXT':r,'RESULT':'ERROR'})
def returnTable(suburl,field=["Name"]):
global c_server
@@ -82,7 +85,7 @@ def pAdminIndex(): #Admin Index page
table = returnTable("/get/computers",['ID_C','Name','RAM','CPUName','SOVersion','SOCaption','HDD','LastConnection','RAMFree'])
for lista in table:
lista.append(returnTable("/get/groups?ComputerID="+lista[0],["Name"])) #lista[9]¿
lista.append(returnTable("/get/groups?ComputerID="+lista[0],["ID_G","Name"])) #lista[9]¿
if lista[6] is not None:
try:
lista[6]=json.loads(base64.b64decode(lista[6]).decode('UTF-8'))
@@ -126,13 +129,18 @@ def pAdminComputer(): #Admin see one group
computerid=request.args.get('ID_C')
if computerid is not None and computerid.isnumeric():
computername = returnvalueapi('/get/computers?ComputerID='+str(computerid),"Name")
groups = returnTable("/get/groups?ComputerName="+str(computername),['ID_G','Name'])
#####IT DOESNT HAVE TEMPLATE CREATED
groups = returnTable("/get/groups?ComputerID="+str(computerid),['ID_G','Name'])
for key in range(len(groups)): #Cookgs of every group
print(groups[key])
groups[key].append(returnTable("/get/cookgrp?GroupID="+groups[key][0],['CookName']))
return render_template('/admincomputer.tmpl', title="Computer "+computername,computerid=computerid,computername=computername,groups=groups)
return redirect('/admin')
@app.route("/admin/groups",methods=['GET'])
@app.route("/admin/groups/",methods=['GET'])
def pAdminGroups(): #Admin Index groups
if returnvalueapi('/check/password?Password='+str(request.cookies.get('admin_logued')),'EXITCODE') != '0':
return render_template('/login.tmpl', title="Login")
@@ -159,8 +167,14 @@ def pAdminGroup(): #Admin see one group
for cook in tem:
to = []
to.append(cook[0])
to.append(returnvalueapi('/get/lastrevisioncook?CookName='+cook[0],"Revision"))
to.append(returnTable("/get/statuscook?CookName="+cook[0],'ASIS'))
to.append(int(returnvalueapi('/get/lastrevisioncook?CookName='+cook[0],"Revision"))) # Has to be a number
tabletemp = returnTable("/get/statuscook?CookName="+cook[0],'ASIS')
print (tabletemp)
for x in range(len(tabletemp)):
print(type(tabletemp[x]['Revision']))
if type(tabletemp[x]['Revision']) != int: # Si no es un número, cambiar.
tabletemp[x]['Revision'] = 0
to.append(tabletemp)
cooksdata.append(to)
tem = (returnTable("/get/cookall",'ASIS')) #Lista de todas las recetas
@@ -243,29 +257,44 @@ def pAdminCookDelgroup(): # Add cook to group
else:
return "Error of arguments"
#First time password set
@app.route("/firsttime",methods=['POST'])
def pFirstTime(): #Add computer form enter
passwd = request.args.get('password')
passwd = hashlib.sha256(passwd.encode()).hexdigest()
if passwd != None:
r = returnvalueapi("/upd/password?NewPassword="+passwd,field="RESULT")
if r == "OK":
res = make_response(redirect(url_for('pAdminIndex')))
res.set_cookie("admin_logued",value=passwd)
else: #Hmm..Unespecified error
render_template('/firsttime.tmpl')
else:
return render_template('/firsttime.tmpl')
@app.route("/",methods=['GET'])
def pIndex(): #Index page
howispasswd=returnvalueapi('/check/password?Password='+str(request.cookies.get('admin_logued')),'EXITCODE')
if howispasswd == '0': # Logued
return redirect(url_for('pAdminIndex'))
if howispasswd == '1' or howispasswd == '2': # Has to login
elif howispasswd == '1' or howispasswd == '2': # Has to login
return render_template('/login.tmpl')
if howispasswd == '3': # No password yet
return 'Yet to do it..'
elif howispasswd == '3': # No password yet
return render_template('/firsttime.tmpl')
@app.route("/login",methods=['GET','POST'])
def pLogin(): #Login
if request.values.get('password'):
trpass = hashlib.sha256(request.values.get('password').encode()).hexdigest()
#print(returnvalueapi('/check/password?Password='+trpass,'EXITCODE'))
if returnvalueapi('/check/password?Password='+trpass,'EXITCODE') == '0':
howispasswd = returnvalueapi('/check/password?Password='+trpass,'EXITCODE')
if howispasswd == '0':
res = make_response(redirect(url_for('pAdminIndex')))
res.set_cookie("admin_logued",value=trpass)
return res
else:
elif howispasswd in (1,2):
return render_template('/login.tmpl')
elif howispasswd == '3': # No password yet
return render_template('/firsttime.tmpl')
else:
return render_template('/login.tmpl')

View File

@@ -15,8 +15,9 @@
</tr>
</thead>
<tbody>
{% for item in tablegroups %} {#['ID_G','Name','Cooks[CookName]']#}
{% for item in groups %} {#['ID_G','Name','Cooks[CookName]']#}
<tr>
<td><a href="/admin/group?ID_G={{item.0}}">{{item.0}}</a></td>
<td><a href="/admin/group?ID_G={{item.0}}">{{item.1}}</a></td>
<td style='width:50%;'>
{% for x in item.2 %}

View File

@@ -130,7 +130,7 @@
<td>{{item.1}}</td>
<td>
{% for subitem in item.2|sort(attribute='Revision')|sort(attribute='Name') %} {# item.2 = AppliedTo #}
{{subitem.Name}}{% if subitem.Revision|int < item.1|int %}<span style="color:red">({{subitem.Revision}})</span>{% elif subitem.Error != 0 %}<span style="color:orange;font-weigth:bold;font-style:italic" title="{{subitem.ErrorDesc}}">(Error r.{{subitem.Revision}})</span>{% endif %},
{{subitem.Name}}{% if subitem.Revision|int < item.1|int %}<span style="color:red">({{subitem.Revision}})</span>{% elif subitem.Error > 0 %}<span style="color:orange;font-weigth:bold;font-style:italic" title="{{subitem.ErrorDesc}}">(Error r.{{subitem.Revision}})</span>{% endif %},
{% endfor %}
</tr>
{% endfor %}

View File

@@ -26,13 +26,13 @@
</div>
</div>
<!-- Modal Delete Computer To Database -->
<!-- Modal Delete Computer From Database -->
<div class="modal fade" id="modalDel" tabindex="-1" role="dialog" aria-labelledby="modalDelLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<form method="get" action="/admin/delcomputer">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="modalDelLabel">Delete computer to Database. NOT REVERSIBLE</h5>
<h5 class="modal-title" id="modalDelLabel">Delete computer from Database. NOT REVERSIBLE</h5>
</div>
<div class="modal-body">
<div class="form-group">
@@ -76,11 +76,11 @@
{% for item in tablecomputers %} {#['ID_C','Name','RAM','CPUName','SOVersion','SOCaption','HDD','LastConnection','RamFree','GroupsNames']#}
<tr>
<td>{{item.0}}</td>
<td>{{item.1}}</td>
<td><a href="/admin/computer?ID_C={{item.0}}">{{item.1}}</a></td>
<td>{{item.5}} {{item.4}}</td>
<td width='200px'>
{% for x in item.9 %}
{{x.0}},
<a href="/admin/group?ID_G={{x.0}}">{{x.1}}</a>,
{% endfor %}
</td>
<td>{{item.3}}</td>

View File

@@ -0,0 +1,17 @@
{# -*- coding: utf-8 -*- #}
{% extends 'baseadmin.tmpl' %}
{% block content %}
<h2>Login</h2>
<form action="/firsttime" method="POST">
<div class="table-responsive">
<table class="table table-striped table-sm">
<tr>
<td>Please put password for program. Do not forget it!<input type="password" name="password" id="password" /></td>
</tr>
<tr>
<td><button type="submit">Set password</button></td>
</tr>
</table>
</div>
</form>
{% endblock %}