mirror of
https://gitlab.com/JKANetwork/powerfulcomputermanager.git
synced 2026-03-01 00:03:59 +01:00
Enable setting password. Some EXITCODE for api<->control checking.
This commit is contained in:
23
api.py
23
api.py
@@ -32,6 +32,10 @@ def retPassword():
|
||||
# /get/computerexists?
|
||||
# @param ComputerName -> Computer to deploy it
|
||||
# @param UUID: Check UUID validation of this computer
|
||||
# Error exit code:
|
||||
# 1: No params supplied
|
||||
# 2: Computer and UUID not match database
|
||||
# 3: Computer doesn't exists in database
|
||||
##
|
||||
class getComputerExists(object):
|
||||
def on_get(self, request, response):
|
||||
@@ -44,7 +48,7 @@ class getComputerExists(object):
|
||||
UUID = value
|
||||
|
||||
if ComputerName is None:
|
||||
response.media = {'TEXT':'No params','RESULT': 'ERROR'}
|
||||
response.media = {'TEXT':'No params','RESULT': 'ERROR','EXITCODE':'1'}
|
||||
else:
|
||||
result = sql.select("SELECT COUNT(*) 'RESULT' FROM COMPUTERS WHERE Name='"+ComputerName+"' AND UUID='"+UUID+"'")
|
||||
|
||||
@@ -60,7 +64,7 @@ class getComputerExists(object):
|
||||
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
|
||||
response.media = {'TEXT':'Error: Computer not exists in database', 'RESULT': 'ERROR','EXITCODE':'1'}
|
||||
response.media = {'TEXT':'Error: Computer not exists in database', 'RESULT': 'ERROR','EXITCODE':'3'}
|
||||
|
||||
else: #Exists
|
||||
response.media = {'RESULT': '1'}
|
||||
@@ -684,6 +688,11 @@ class setCookStatus(object):
|
||||
# checkPassword: Check password
|
||||
# /check/password?
|
||||
# @param Password -> SHA-256 of password
|
||||
# Error exit code:
|
||||
# 0: No error
|
||||
# 1: No password supplied
|
||||
# 2: Password incorrect
|
||||
# 3: Password not set in app yet
|
||||
##
|
||||
class checkPassword(object): #Check password (ERROR if password not valid or no password and 1 if valid)
|
||||
def on_get(self, request, response):
|
||||
@@ -694,18 +703,18 @@ class checkPassword(object): #Check password (ERROR if password not valid or no
|
||||
Password = value
|
||||
|
||||
if Password is None:
|
||||
response.media = {'TEXT': 'Error, you need to supply a password','RESULT':'ERROR'}
|
||||
response.media = {'TEXT': 'Error, you need to supply a password','RESULT':'ERROR','EXITCODE':'1'}
|
||||
else:
|
||||
pass
|
||||
res = sql.select("SELECT COUNT(*) 'RESULT' FROM OPTIONS WHERE Option='Password' AND Value='"+Password+"'")[0]['RESULT']
|
||||
if res == 1:
|
||||
response.media = {'RESULT':'1','TEXT':'OK'}
|
||||
response.media = {'RESULT':'1','TEXT':'OK','EXITCODE':'0'}
|
||||
else:
|
||||
res = sql.select("SELECT COUNT(*) 'RESULT' FROM OPTIONS WHERE Option='Password'")[0]['RESULT']
|
||||
if res == 0: #Password doesn't exists in database
|
||||
response.media = {'RESULT':'ERROR','TEXT':'No password set. Please set it'}
|
||||
response.media = {'RESULT':'ERROR','TEXT':'No password set. Please set it','EXITCODE':'3'}
|
||||
else:
|
||||
response.media = {'RESULT':'ERROR','TEXT':'Password incorrect'}
|
||||
response.media = {'RESULT':'ERROR','TEXT':'Password incorrect','EXITCODE':'2'}
|
||||
|
||||
##
|
||||
# updPassword: Update password
|
||||
@@ -725,7 +734,7 @@ class updPassword(object): #Update password (ERROR if password not valid or no
|
||||
|
||||
res = sql.select("SELECT COUNT(*) 'RESULT' FROM OPTIONS WHERE Option='Password'")[0]['RESULT']
|
||||
if res == 0 and NewPassword is not None: #Password doesn't exists in database
|
||||
response.media = sql.insert("INSERT INTO COMMENTS VALUES('Password','"+NewPassword+"')")
|
||||
response.media = sql.insert("INSERT INTO OPTIONS VALUES('Password','"+NewPassword+"')")
|
||||
elif res == 0 and NewPassword is None: #No password supplied
|
||||
response.media = {'RESULT':'ERROR','TEXT':'Error, you need to supply a password'}
|
||||
elif res == 1 and OldPassword is not None: # Password exists in database (And you supplied OldPassword)
|
||||
|
||||
Reference in New Issue
Block a user