New version with security in transport (https selfsigned), change deps, and preparing web version

This commit is contained in:
2019-11-21 10:58:26 +01:00
parent fb4dca9b4e
commit ec991abeed
12 changed files with 730 additions and 637 deletions

View File

@@ -12,6 +12,13 @@ from translation import T
passha256 = None # Password (Global)
config = configparser.ConfigParser()
config.read('configpcm.ini')
c_server = config['General']['server']
c_resources = config['General']['resources'].replace('\\\\','\\')
def ping(host):
"""
Returns True if host (str) responds to a ping request.
@@ -30,6 +37,10 @@ def sendmenudot(text,title,choices):
return menu.split('.')[0]
else:
return menu
def retOpt(option):
return returnvalueapi('/get/optionvalue?Option='+str(option),field="Value")
## showchoicesapi, suburl has to have params (NOT inlcuding server part)
def showchoicesapi(text,title,suburl,field=['Name']):
global c_server
@@ -43,7 +54,8 @@ def showchoicesapi(text,title,suburl,field=['Name']):
else:
twopart= '?Password='+str(passha256)
try:
jsonobj = json.loads(requests.get(c_server+suburl+twopart).text)
r=(requests.post(c_server+suburl+twopart, verify=False).text).replace("\'", "\"").replace('\\"',"'").replace(': None',': "None"')
jsonobj = json.loads(r)
listitems = []
for ite in jsonobj: # Run in array from json
to = ""
@@ -66,8 +78,8 @@ def sendsettoapi(suburl,goodtext): # Send a add/del/modify to API. Doesn't retur
else:
twopart= '?Password='+str(passha256)
try:
jsonobj = json.loads(requests.get(c_server+suburl+twopart).text)
#jsonobj['RESULT'] has to exist for next if
r=(requests.post(c_server+suburl+twopart, verify=False).text).replace("\'", "\"").replace('\\"',"'").replace(': None',': "None"')
jsonobj = json.loads(r)
try:
jsonobj['RESULT']
except:
@@ -95,22 +107,16 @@ def returnvalueapi(suburl,field="Name"):
else:
twopart= '?Password='+str(passha256)
try:
jsonobj = json.loads(requests.get(c_server+suburl+twopart).text)
r=(requests.post(c_server+suburl+twopart, verify=False).text).replace("\'", "\"").replace('\\"',"'").replace(': None',': "None"')
jsonobj = json.loads(r)
return jsonobj[field]
except:
easygui.msgbox(msg=T('Error talking with API'), title="Error", ok_button='OK')
return None
config = configparser.ConfigParser()
config.read('configpcm.ini')
c_server = config['General']['server']
c_resources = config['General']['resources'].replace('\\\\','\\')
def menuprinc():
menu = sendmenudot(T('Main menu'),T('Select option'),['1.'+T('Computers'),'2.'+T('Groups'),'3.'+T('Cooks'),'4.Reportes/Listados'])
menu = sendmenudot(T('Main menu'),T('Select option'),['1.'+T('Computers'),'2.'+T('Groups'),'3.'+T('Cooks'),'4.Reportes/Listados','5.'+T('Options')])
if menu == '1':
mcomputers()
elif menu == '2':
@@ -119,6 +125,8 @@ def menuprinc():
mcooks()
elif menu == '4':
mreports()
elif menu == '5':
moptions()
def mcomputers():
menu = sendmenudot(T('Computers menu'),T('Select option'),['1.'+T('Add computer'),'2.'+T('Remove computer'),'3.'+T('Add computer to group'),'4.'+T('Computers list'),'5.'+T('Computer status')])
@@ -177,7 +185,8 @@ def mcooks():
cook = showchoicesapi("Lista de recetas implementadas en algún grupo. Selecciona una para ver sus datos","Detalles de una receta","/get/cookall",'CookName')
if cook is not None:
showchoicesapi("Lista de grupos de la receta "+cook,"Listado de grupos de una receta","/get/grpcook?CookName="+cook)
jsonobj = json.loads(requests.get(c_server+'/get/statuscook?CookName='+cook).text)
r=(requests.post(c_server+'/get/statuscook?CookName='+cook, verify=False).text).replace("\'", "\"").replace('\\"',"'").replace(': None',': "None"')
jsonobj = json.loads(r)
list = []
s_err = 0
s_com = 0
@@ -247,6 +256,20 @@ def mreports():
menuprinc()
return
mreports()
def moptions():
debugsql = retOpt('DebugSQL')
addcomputers = retOpt('AddComputers')
menu = sendmenudot(T('Options menu'),T('Select option'),['1.'+T('Debug SQL commands')+'-'+str(debugsql),'2.'+T('Allow auto add of new computers')+'-'+str(addcomputers)])
if menu == '1':
showchoicesapi(T('Computers list'),T('Computers list'),"/get/computers")
elif menu == '2':
showchoicesapi(T('Groups list'),T('Groups list'),"/get/groups")
elif menu is None:
menuprinc()
return
mreports()
def m_addcomputergroup():
@@ -272,6 +295,7 @@ def m_delcomputergroup():
# Check password before starting all
pa = returnvalueapi("/check/password?Password=None",field="EXITCODE")
print(pa)
if pa == "3": # No password stored yet
passw = easygui.passwordbox(T('There is no password yet in PCM. Please set one below'),T('Set password'))
passw2 = easygui.passwordbox(T('Confirm it'),T('Set password'))
@@ -292,6 +316,7 @@ else: # There is a password
quit()
passha256 = hashlib.sha256(passw.encode()).hexdigest()
re = returnvalueapi("/check/password?Password="+passha256,field="EXITCODE") # Create password in database
print(re)
if re == '0': # Password is right
menuprinc()
else: