mirror of
https://gitlab.com/JKANetwork/powerfulcomputermanager.git
synced 2026-02-20 12:11:30 +01:00
API 1
This commit is contained in:
27
api.py
27
api.py
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/python3
|
||||
BUILD = 16
|
||||
API_VER = 0 #Its beta, API 1 will have password checks enabled
|
||||
API_VER = 1
|
||||
##It can be run directly with "waitress-serve --port=3333 api:api"
|
||||
import falcon
|
||||
import random
|
||||
@@ -109,6 +109,12 @@ class getComputers(object):
|
||||
data = sql.select("SELECT * FROM COMPUTERS WHERE ID_C = '"+ComputerID+"')")
|
||||
response.media = data
|
||||
|
||||
|
||||
##
|
||||
# getComputersGrp: Know all computers that have a group
|
||||
# /get/computersgrp?
|
||||
# @param GroupName/GroupID -> Group to see computers
|
||||
##
|
||||
class getComputersGrp(object): #List of computers in a group
|
||||
def on_get(self,request, response):
|
||||
logit(request)
|
||||
@@ -182,11 +188,12 @@ class getCookPend(object): # Get the list of cooks for a computer to implement (
|
||||
# /add/cookgrp?
|
||||
# @param GroupName/GroupID -> Group to show cooks
|
||||
# @param CookName -> Cook to assign
|
||||
# @param Password -> Password to validate
|
||||
##
|
||||
class addCookGrp(object): #Assign Cook to group
|
||||
def on_get(self, request, response):
|
||||
logit(request)
|
||||
GroupID, CookName = None, None # Initialize
|
||||
GroupID, CookName, Password = None, None, None # Initialize
|
||||
for key, value in request.params.items():
|
||||
if key == "CookName":
|
||||
exists = os.path.isfile('cooks/'+value+'.yaml')
|
||||
@@ -195,8 +202,12 @@ class addCookGrp(object): #Assign Cook to group
|
||||
GroupID = str(sql.select("SELECT ID_G FROM GROUPS WHERE Name='"+value+"'")[0]['ID_G'])
|
||||
if key == "GroupID":
|
||||
GroupID = value
|
||||
if key == "Password" and value == retPassword():
|
||||
Password=value
|
||||
if GroupID is None or exists is False:
|
||||
response.media = {'TEXT': 'GroupID is not defined or Cook not exists','RESULT':'ERROR'}
|
||||
elif Password is None: # Validate password
|
||||
response.media = {'TEXT': 'Invalid password','RESULT':'ERROR'}
|
||||
elif int(sql.select("SELECT COUNT(*) 'COUNT' FROM COOKS_IDG WHERE `ID_G`='"+GroupID+"' AND `CookName`='"+CookName+"'")[0]['COUNT']) > 0:
|
||||
response.media = {'TEXT': 'This union GROUP-CookName exists','RESULT':'0'}
|
||||
else:
|
||||
@@ -550,7 +561,7 @@ class delComputer(object): #Delete computer
|
||||
class updComputer(object):
|
||||
def on_get(self, request, response):
|
||||
logit(request)
|
||||
ComputerID, UUID= None, None
|
||||
ComputerID, UUID, Password= None, None,None
|
||||
for key, value in request.params.items():
|
||||
if key == "ComputerName":
|
||||
try:
|
||||
@@ -562,6 +573,9 @@ class updComputer(object):
|
||||
ComputerID = value
|
||||
if key == "UUID":
|
||||
UUID = value
|
||||
if key == "Password" and value == retPassword():
|
||||
Password=value
|
||||
|
||||
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:
|
||||
@@ -590,6 +604,7 @@ class updComputer(object):
|
||||
# /upd/cookname?
|
||||
# @param CookName -> Original Cook Name
|
||||
# @param CookNewName -> New Cook Name
|
||||
# @param Password -> Password validated command
|
||||
##
|
||||
class updCookName(object):
|
||||
def on_get(self, request, response):
|
||||
@@ -608,9 +623,13 @@ class updCookName(object):
|
||||
break
|
||||
else:
|
||||
CookNewName= value
|
||||
if key == "Password" and value == retPassword():
|
||||
Password=value
|
||||
if CookName is None or CookNewName is None:
|
||||
response.media = {'TEXT': 'Error, you need the old and new Cook Name to update data','RESULT':'ERROR'}
|
||||
elif response.media is None:
|
||||
elif Password is None: # Validate password
|
||||
response.media = {'TEXT': 'Invalid password','RESULT':'ERROR'}
|
||||
elif response.media is None: #Like else
|
||||
old_file = os.path.join("cooks", CookName+'.yaml')
|
||||
new_file = os.path.join("cooks", CookNewName+'.yaml')
|
||||
os.rename(old_file, new_file)
|
||||
|
||||
Reference in New Issue
Block a user