mirror of
https://gitlab.com/JKANetwork/powerfulcomputermanager.git
synced 2026-03-03 17:16:45 +01:00
Fixes from api 2
This commit is contained in:
29
api.py
29
api.py
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/python3
|
||||
BUILD = 24
|
||||
BUILD = 26
|
||||
API_VER = 2
|
||||
from flask import Flask, request
|
||||
import random
|
||||
@@ -59,10 +59,8 @@ def getComputerExists():
|
||||
if sql.select("SELECT COUNT(*) 'RESULT' FROM COMPUTERS WHERE Name='"+ComputerName+"' AND UUID IS NULL")[0]['RESULT'] != 0: #UUID doesn't in database, insert it
|
||||
sql.insert("UPDATE COMPUTERS SET UUID='"+UUID+"' WHERE Name='"+ComputerName+"'")
|
||||
return str({'RESULT': '1'})
|
||||
return
|
||||
elif sql.select("SELECT COUNT(*) 'RESULT' FROM COMPUTERS WHERE Name='"+ComputerName+"'")[0]['RESULT'] != 0: #Not UUID match, but computer exists
|
||||
return str({'TEXT': 'Error, computer and UUID doesn\'t match in database', 'RESULT': 'ERROR','EXITCODE':'2'})
|
||||
return
|
||||
if sqlAddComputers == True: #Computer doesn't exist, but you have enabled add all computers
|
||||
sql.insert("INSERT INTO COMPUTERS (`Name`,`UUID`) VALUES('"+ComputerName+"','"+UUID+"')")
|
||||
return str({'RESULT': '1'})
|
||||
@@ -77,23 +75,26 @@ def getComputerExists():
|
||||
# getGroups: Know all groups or groups of a computer
|
||||
# /get/groups?
|
||||
# @param ComputerName/ComputerID -> Computer to see groups (Not neccesary)
|
||||
# @param GroupID -> For know Name of a GroupID
|
||||
##
|
||||
@app.route("/get/groups",methods=['POST'])
|
||||
def getGroups(): #Get local groups of a Computer
|
||||
logit(request.base_url)
|
||||
ComputerID=None
|
||||
ComputerID,GroupID=None,None
|
||||
for key, value in request.args.to_dict().items():
|
||||
if key == "ComputerName":
|
||||
ComputerID = str(sql.select("SELECT ID_C FROM COMPUTERS WHERE Name='"+value+"'")[0]['ID_C'])
|
||||
if key == "ComputerID":
|
||||
ComputerID = value
|
||||
if key == "GroupID":
|
||||
GroupID = value
|
||||
|
||||
if GroupID is not None:
|
||||
return str(sql.select("SELECT * FROM GROUPS WHERE ID_G='"+str(GroupID)+"' LIMIT 1")[0]) #NOT RETURNS A TABLE
|
||||
if ComputerID is None:
|
||||
data = sql.select("SELECT * FROM GROUPS ORDER BY Name ASC")
|
||||
return str(data)
|
||||
return str(sql.select("SELECT * FROM GROUPS ORDER BY Name ASC"))
|
||||
else:
|
||||
data = sql.select("SELECT * FROM GROUPS WHERE ID_G IN (SELECT ID_G FROM COMPUTER_GROUP WHERE ID_C = '"+ComputerID+"') ORDER BY Name ASC")
|
||||
return str(data)
|
||||
return str(sql.select("SELECT * FROM GROUPS WHERE ID_G IN (SELECT ID_G FROM COMPUTER_GROUP WHERE ID_C = '"+ComputerID+"') ORDER BY Name ASC"))
|
||||
|
||||
##
|
||||
# getComputers: List all computers with data
|
||||
@@ -223,7 +224,7 @@ def addCookGrp(): #Assign Cook to group
|
||||
return str({'TEXT': 'This union GROUP-CookName exists','RESULT':'0'})
|
||||
else:
|
||||
result = sql.insert("INSERT INTO COOKS_IDG (`ID_G`,`CookName`) VALUES ('"+GroupID+"','"+CookName+"')")
|
||||
return str({'TEXT': 'OK'})
|
||||
return str(result) #str({'TEXT': 'OK'}) ?
|
||||
|
||||
##
|
||||
# delCookGrp: Delete cook from a group
|
||||
@@ -335,7 +336,7 @@ def getStatusCook(): # Get Status of a Cook (If Brief=1 is sent too, brief statu
|
||||
CookName = value
|
||||
|
||||
if CookName is not None:
|
||||
return str(sql.select("SELECT Name, Revision, Error FROM COMPUTERS,COOKS_STATUS WHERE CookName = '"+CookName+"' AND COMPUTERS.ID_C=COOKS_STATUS.ID_C"))
|
||||
return str(sql.select("SELECT Name, Revision, Error FROM COMPUTERS,COOKS_STATUS WHERE CookName = '"+CookName+"' AND COMPUTERS.ID_C=COOKS_STATUS.ID_C ORDER BY Name ASC"))
|
||||
else:
|
||||
return str({'TEXT': 'Error, no Cook selected','RESULT':'ERROR'})
|
||||
|
||||
@@ -627,7 +628,6 @@ def updComputer():
|
||||
ComputerID = str(sql.select("SELECT ID_C FROM COMPUTERS WHERE Name='"+value+"'")[0]['ID_C'])
|
||||
except:
|
||||
return str({'TEXT': 'Error: Computer not exists in database','RESULT':'ERROR','EXITCODE':'1'})
|
||||
break
|
||||
if key == "ComputerID":
|
||||
ComputerID = value
|
||||
if key == "UUID":
|
||||
@@ -714,7 +714,6 @@ def loadCook():
|
||||
CookName= value
|
||||
else:
|
||||
return str({'TEXT': 'Error: Cook not exists in folder','RESULT':'ERROR'})
|
||||
break
|
||||
if key == "ComputerName":
|
||||
ComputerID = str(sql.select("SELECT ID_C FROM COMPUTERS WHERE Name='"+value+"'")[0]['ID_C'])
|
||||
if key == "ComputerID":
|
||||
@@ -722,7 +721,7 @@ def loadCook():
|
||||
if key == "UUID":
|
||||
UUID = value
|
||||
|
||||
if CookName is None and response.media is None:
|
||||
if CookName is None:
|
||||
return str({'TEXT': 'Error, you need a CookName to load it','RESULT':'ERROR'})
|
||||
else:
|
||||
Count = str(sql.select("SELECT COUNT(*) 'Count' FROM COMPUTERS WHERE UUID='"+UUID+"' AND ID_C='"+ComputerID+"'")[0]['Count'])
|
||||
@@ -743,7 +742,6 @@ def setCookStatus():
|
||||
CookName= value
|
||||
else:
|
||||
return str({'TEXT': 'Error: Cook not exists in folder','RESULT':'ERROR'})
|
||||
break
|
||||
if key == "ComputerName":
|
||||
ComputerID = str(sql.select("SELECT ID_C FROM COMPUTERS WHERE Name='"+value+"'")[0]['ID_C'])
|
||||
if key == "ComputerID":
|
||||
@@ -767,7 +765,6 @@ def setCookStatus():
|
||||
return str(sql.insert("UPDATE COOKS_STATUS SET Revision='"+Revision+"',`Error`='"+Error+"',`ErrorDesc`='"+ErrorDesc+"' WHERE ID_C='"+ComputerID+"' AND CookName='"+CookName+"'"))
|
||||
else:
|
||||
return str({'TEXT': 'Error in parameters...','RESULT':'ERROR'})
|
||||
logit(response.media)
|
||||
|
||||
|
||||
##
|
||||
@@ -865,4 +862,4 @@ print("Build: "+str(BUILD))
|
||||
print("API Version: "+str(API_VER))
|
||||
|
||||
|
||||
app.run(debug=False,port=3333,ssl_context='adhoc',host='0.0.0.0')
|
||||
app.run(debug=False,port=3333,ssl_context='adhoc',host='0.0.0.0',threaded=True)
|
||||
Reference in New Issue
Block a user