mirror of
https://gitlab.com/JKANetwork/powerfulcomputermanager.git
synced 2026-02-22 21:13:43 +01:00
Changes to doc and api/app for be able to record more things
This commit is contained in:
25
api.py
25
api.py
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/python3
|
||||
BUILD = 21
|
||||
BUILD = 24
|
||||
API_VER = 1
|
||||
##It can be run directly with "waitress-serve --port=3333 api:api"
|
||||
import falcon
|
||||
@@ -10,7 +10,7 @@ import sql # SQL work file
|
||||
import json,yaml
|
||||
from datetime import datetime
|
||||
|
||||
import sysopt #File of options
|
||||
sqlAddComputers = sql.retOption('AddComputers')
|
||||
|
||||
def logit(text):
|
||||
text = str(text)
|
||||
@@ -60,7 +60,7 @@ class getComputerExists(object):
|
||||
elif sql.select("SELECT COUNT(*) 'RESULT' FROM COMPUTERS WHERE Name='"+ComputerName+"'")[0]['RESULT'] != 0: #Not UUID match, but computer exists
|
||||
response.media = {'TEXT': 'Error, computer and UUID doesn\'t match in database', 'RESULT': 'ERROR','EXITCODE':'2'}
|
||||
return
|
||||
if sysopt.addComputers == True: #Computer doesn't exist, but you have enabled add all computers
|
||||
if sqlAddComputers == True: #Computer doesn't exist, but you have enabled add all computers
|
||||
sql.insert("INSERT INTO COMPUTERS (`Name`,`UUID`) VALUES('"+ComputerName+"','"+UUID+"')")
|
||||
response.media = {'RESULT': '1'}
|
||||
else: #Computer doesn't exist and you don't want to be added
|
||||
@@ -571,11 +571,17 @@ class delComputer(object): #Delete computer
|
||||
resp = sql.insert("DELETE FROM COMPUTERS WHERE ID_C='"+ComputerID+"'")
|
||||
logit(resp)
|
||||
|
||||
|
||||
##
|
||||
# updComputer: Upd computer data
|
||||
# /upd/computer?
|
||||
# @param ComputerID -> Computer ID
|
||||
# @param UUID -> UUID of computer
|
||||
# No need password, validate from ComputerID+UUID for updates..
|
||||
##
|
||||
class updComputer(object):
|
||||
def on_get(self, request, response):
|
||||
logit(request)
|
||||
ComputerID, UUID, Password= None, None,None
|
||||
ComputerID, UUID = None, None
|
||||
for key, value in request.params.items():
|
||||
if key == "ComputerName":
|
||||
try:
|
||||
@@ -587,10 +593,6 @@ class updComputer(object):
|
||||
ComputerID = value
|
||||
if key == "UUID":
|
||||
UUID = value
|
||||
if key == "Password" and value == retPassword():
|
||||
Password=value
|
||||
if Password is None:
|
||||
response.media = {'TEXT': 'Invalid password','RESULT':'ERROR'}
|
||||
if ComputerID is None and response.media is None:
|
||||
response.media = {'TEXT': 'Error, you need a ComputerName/ComputerID to update data','RESULT':'ERROR'}
|
||||
elif response.media is None and ComputerID is not None and UUID is not None:
|
||||
@@ -613,6 +615,10 @@ class updComputer(object):
|
||||
response.media = sql.insert("UPDATE COMPUTERS SET RAM='"+value+"' WHERE ID_C='"+ComputerID+"'")
|
||||
if key == "CPUName":
|
||||
response.media = sql.insert("UPDATE COMPUTERS SET CPUName='"+value+"' WHERE ID_C='"+ComputerID+"'")
|
||||
if key == "RAMFree":
|
||||
response.media = sql.insert("UPDATE COMPUTERS SET RAMFree='"+str(value)+"' WHERE ID_C='"+ComputerID+"'")
|
||||
if key == "HDD":
|
||||
response.media = sql.insert("UPDATE COMPUTERS SET HDD='"+str(value)+"' WHERE ID_C='"+ComputerID+"'")
|
||||
|
||||
##
|
||||
# updCookName: Rename cook name
|
||||
@@ -809,7 +815,6 @@ api.add_route('/get/grpcook', getGrpCook()) # See groups of a determinated cook
|
||||
api.add_route('/get/lastrevisioncook', getLastRevisionCook()) # Returns number of last revision of a cook
|
||||
api.add_route('/get/statuscook', getStatusCook()) # See status of a cook
|
||||
api.add_route('/load/cook', loadCook()) # Load a cook (Transfer in json way)
|
||||
api.add_route('/set/cookstatus', setCookStatus()) # Update status of a cook in a computer (OLD)
|
||||
api.add_route('/upd/cookstatus', setCookStatus()) # Update status of a cook in a computer
|
||||
api.add_route('/upd/computer', updComputer()) #Update data of computer
|
||||
api.add_route('/upd/cookname', updCookName()) #Update file name of cook and SQL references to it.
|
||||
|
||||
Reference in New Issue
Block a user