|
|
|
@ -340,152 +340,160 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
|
|
|
|
# Write content as utf-8 data
|
|
|
|
|
self.wfile.write(inResponseDict["Body"])
|
|
|
|
|
def do_GET(self):
|
|
|
|
|
self.OpenRPA = {}
|
|
|
|
|
self.OpenRPA["AuthToken"] = None
|
|
|
|
|
self.OpenRPA["Domain"] = None
|
|
|
|
|
self.OpenRPA["User"] = None
|
|
|
|
|
self.OpenRPA["DefUserRoleAccessAsk"]=self.UserRoleAccessAsk # Alias for def
|
|
|
|
|
self.OpenRPA["DefUserRoleHierarchyGet"]=self.UserRoleHierarchyGet # Alias for def
|
|
|
|
|
# Prepare result dict
|
|
|
|
|
lResponseDict = {"Headers": {}, "SetCookies": {}, "Body": b"", "StatusCode": None}
|
|
|
|
|
self.OpenRPAResponseDict = lResponseDict
|
|
|
|
|
#####################################
|
|
|
|
|
#Do authentication
|
|
|
|
|
#Check if authentication is turned on
|
|
|
|
|
#####################################
|
|
|
|
|
lFlagAccessUserBlock=False
|
|
|
|
|
lAuthenticateDict = {"Domain": "", "User": ""}
|
|
|
|
|
if gSettingsDict.get("ServerDict", {}).get("AccessUsers", {}).get("FlagCredentialsAsk", False):
|
|
|
|
|
lAuthenticateDict = AuthenticateVerify(self)
|
|
|
|
|
if not lAuthenticateDict["User"]:
|
|
|
|
|
lFlagAccessUserBlock=True
|
|
|
|
|
# Logging
|
|
|
|
|
# gSettingsDict["Logger"].info(f"HTTP request /. Domain: {lAuthenticateDict['Domain']}, User: {lAuthenticateDict['User']}")
|
|
|
|
|
if lFlagAccessUserBlock:
|
|
|
|
|
AuthenticateBlock(self)
|
|
|
|
|
#####################################
|
|
|
|
|
else:
|
|
|
|
|
#Check the user access (if flag)
|
|
|
|
|
####################################
|
|
|
|
|
lFlagUserAccess = True
|
|
|
|
|
#If need user authentication
|
|
|
|
|
try:
|
|
|
|
|
self.OpenRPA = {}
|
|
|
|
|
self.OpenRPA["AuthToken"] = None
|
|
|
|
|
self.OpenRPA["Domain"] = None
|
|
|
|
|
self.OpenRPA["User"] = None
|
|
|
|
|
self.OpenRPA["DefUserRoleAccessAsk"]=self.UserRoleAccessAsk # Alias for def
|
|
|
|
|
self.OpenRPA["DefUserRoleHierarchyGet"]=self.UserRoleHierarchyGet # Alias for def
|
|
|
|
|
# Prepare result dict
|
|
|
|
|
lResponseDict = {"Headers": {}, "SetCookies": {}, "Body": b"", "StatusCode": None}
|
|
|
|
|
self.OpenRPAResponseDict = lResponseDict
|
|
|
|
|
#####################################
|
|
|
|
|
#Do authentication
|
|
|
|
|
#Check if authentication is turned on
|
|
|
|
|
#####################################
|
|
|
|
|
lFlagAccessUserBlock=False
|
|
|
|
|
lAuthenticateDict = {"Domain": "", "User": ""}
|
|
|
|
|
if gSettingsDict.get("ServerDict", {}).get("AccessUsers", {}).get("FlagCredentialsAsk", False):
|
|
|
|
|
lFlagUserAccess = UserAccessCheckBefore("GET", self)
|
|
|
|
|
######################################
|
|
|
|
|
if lFlagUserAccess:
|
|
|
|
|
lOrchestratorFolder = "\\".join(__file__.split("\\")[:-1])
|
|
|
|
|
############################
|
|
|
|
|
#New server engine (url from global dict (URLList))
|
|
|
|
|
############################
|
|
|
|
|
for lURLItem in gSettingsDict["ServerDict"]["URLList"]:
|
|
|
|
|
#Check if all condition are applied
|
|
|
|
|
lFlagURLIsApplied=False
|
|
|
|
|
lFlagURLIsApplied=self.URLItemCheckDo(lURLItem, "GET")
|
|
|
|
|
if lFlagURLIsApplied:
|
|
|
|
|
self.ResponseDictSend()
|
|
|
|
|
return
|
|
|
|
|
#Monitor
|
|
|
|
|
if self.path == '/Monitor/JSONDaemonListGet':
|
|
|
|
|
lAuthenticateDict = AuthenticateVerify(self)
|
|
|
|
|
if not lAuthenticateDict["User"]:
|
|
|
|
|
lFlagAccessUserBlock=True
|
|
|
|
|
# Logging
|
|
|
|
|
# gSettingsDict["Logger"].info(f"HTTP request /. Domain: {lAuthenticateDict['Domain']}, User: {lAuthenticateDict['User']}")
|
|
|
|
|
if lFlagAccessUserBlock:
|
|
|
|
|
AuthenticateBlock(self)
|
|
|
|
|
#####################################
|
|
|
|
|
else:
|
|
|
|
|
#Check the user access (if flag)
|
|
|
|
|
####################################
|
|
|
|
|
lFlagUserAccess = True
|
|
|
|
|
#If need user authentication
|
|
|
|
|
if gSettingsDict.get("ServerDict", {}).get("AccessUsers", {}).get("FlagCredentialsAsk", False):
|
|
|
|
|
lFlagUserAccess = UserAccessCheckBefore("GET", self)
|
|
|
|
|
######################################
|
|
|
|
|
if lFlagUserAccess:
|
|
|
|
|
lOrchestratorFolder = "\\".join(__file__.split("\\")[:-1])
|
|
|
|
|
############################
|
|
|
|
|
#New server engine (url from global dict (URLList))
|
|
|
|
|
############################
|
|
|
|
|
for lURLItem in gSettingsDict["ServerDict"]["URLList"]:
|
|
|
|
|
#Check if all condition are applied
|
|
|
|
|
lFlagURLIsApplied=False
|
|
|
|
|
lFlagURLIsApplied=self.URLItemCheckDo(lURLItem, "GET")
|
|
|
|
|
if lFlagURLIsApplied:
|
|
|
|
|
self.ResponseDictSend()
|
|
|
|
|
return
|
|
|
|
|
#Monitor
|
|
|
|
|
if self.path == '/Monitor/JSONDaemonListGet':
|
|
|
|
|
# Send response status code
|
|
|
|
|
self.send_response(200)
|
|
|
|
|
# Send headers
|
|
|
|
|
self.send_header('Content-type','application/json')
|
|
|
|
|
self.end_headers()
|
|
|
|
|
# Send message back to client
|
|
|
|
|
message = json.dumps(gSettingsDict)
|
|
|
|
|
# Write content as utf-8 data
|
|
|
|
|
self.wfile.write(bytes(message, "utf8"))
|
|
|
|
|
#Filemanager function
|
|
|
|
|
if self.path.lower().startswith('/filemanager/'):
|
|
|
|
|
lFileURL=self.path[13:]
|
|
|
|
|
# check if file in FileURL - File Path Mapping Dict
|
|
|
|
|
if lFileURL.lower() in gSettingsDict["FileManager"]["FileURLFilePathDict"]:
|
|
|
|
|
self.SendResponseContentTypeFile('application/octet-stream', gSettingsDict["FileManager"]["FileURLFilePathDict"][lFileURL])
|
|
|
|
|
else:
|
|
|
|
|
#Set access denied code
|
|
|
|
|
# Send response status code
|
|
|
|
|
self.send_response(200)
|
|
|
|
|
self.send_response(403)
|
|
|
|
|
# Send headers
|
|
|
|
|
self.send_header('Content-type','application/json')
|
|
|
|
|
self.end_headers()
|
|
|
|
|
# Send message back to client
|
|
|
|
|
message = json.dumps(gSettingsDict)
|
|
|
|
|
# Write content as utf-8 data
|
|
|
|
|
self.wfile.write(bytes(message, "utf8"))
|
|
|
|
|
#Filemanager function
|
|
|
|
|
if self.path.lower().startswith('/filemanager/'):
|
|
|
|
|
lFileURL=self.path[13:]
|
|
|
|
|
# check if file in FileURL - File Path Mapping Dict
|
|
|
|
|
if lFileURL.lower() in gSettingsDict["FileManager"]["FileURLFilePathDict"]:
|
|
|
|
|
self.SendResponseContentTypeFile('application/octet-stream', gSettingsDict["FileManager"]["FileURLFilePathDict"][lFileURL])
|
|
|
|
|
else:
|
|
|
|
|
#Set access denied code
|
|
|
|
|
# Send response status code
|
|
|
|
|
self.send_response(403)
|
|
|
|
|
# Send headers
|
|
|
|
|
self.end_headers()
|
|
|
|
|
except Exception as e:
|
|
|
|
|
lL = gSettingsDict["Logger"]
|
|
|
|
|
if lL: lL.exception(f"Server.do_GET: Global error handler - look traceback below.")
|
|
|
|
|
# POST
|
|
|
|
|
def do_POST(self):
|
|
|
|
|
lL = gSettingsDict["Logger"]
|
|
|
|
|
self.OpenRPA = {}
|
|
|
|
|
self.OpenRPA["AuthToken"] = None
|
|
|
|
|
self.OpenRPA["Domain"] = None
|
|
|
|
|
self.OpenRPA["User"] = None
|
|
|
|
|
self.OpenRPA["DefUserRoleAccessAsk"]=self.UserRoleAccessAsk # Alias for def
|
|
|
|
|
self.OpenRPA["DefUserRoleHierarchyGet"]=self.UserRoleHierarchyGet # Alias for def
|
|
|
|
|
# Prepare result dict
|
|
|
|
|
#pdb.set_trace()
|
|
|
|
|
lResponseDict = {"Headers": {}, "SetCookies":{}, "Body": b"", "StatusCode": None}
|
|
|
|
|
self.OpenRPAResponseDict = lResponseDict
|
|
|
|
|
#####################################
|
|
|
|
|
#Do authentication
|
|
|
|
|
#Check if authentication is turned on
|
|
|
|
|
#####################################
|
|
|
|
|
lFlagAccessUserBlock=False
|
|
|
|
|
lAuthenticateDict = {"Domain": "", "User": ""}
|
|
|
|
|
lIsSuperToken = False # Is supertoken
|
|
|
|
|
if gSettingsDict.get("ServerDict", {}).get("AccessUsers", {}).get("FlagCredentialsAsk", False):
|
|
|
|
|
lAuthenticateDict = AuthenticateVerify(self)
|
|
|
|
|
# Get Flag is supertoken (True|False)
|
|
|
|
|
lIsSuperToken = gSettingsDict.get("ServerDict", {}).get("AccessUsers", {}).get("AuthTokensDict", {}).get(
|
|
|
|
|
self.OpenRPA["AuthToken"], {}).get("FlagDoNotExpire", False)
|
|
|
|
|
if not lAuthenticateDict["User"]:
|
|
|
|
|
lFlagAccessUserBlock=True
|
|
|
|
|
if lFlagAccessUserBlock:
|
|
|
|
|
AuthenticateBlock(self)
|
|
|
|
|
#####################################
|
|
|
|
|
else:
|
|
|
|
|
#Check the user access (if flag)
|
|
|
|
|
####################################
|
|
|
|
|
lFlagUserAccess = True
|
|
|
|
|
#If need user authentication
|
|
|
|
|
try:
|
|
|
|
|
lL = gSettingsDict["Logger"]
|
|
|
|
|
self.OpenRPA = {}
|
|
|
|
|
self.OpenRPA["AuthToken"] = None
|
|
|
|
|
self.OpenRPA["Domain"] = None
|
|
|
|
|
self.OpenRPA["User"] = None
|
|
|
|
|
self.OpenRPA["DefUserRoleAccessAsk"]=self.UserRoleAccessAsk # Alias for def
|
|
|
|
|
self.OpenRPA["DefUserRoleHierarchyGet"]=self.UserRoleHierarchyGet # Alias for def
|
|
|
|
|
# Prepare result dict
|
|
|
|
|
#pdb.set_trace()
|
|
|
|
|
lResponseDict = {"Headers": {}, "SetCookies":{}, "Body": b"", "StatusCode": None}
|
|
|
|
|
self.OpenRPAResponseDict = lResponseDict
|
|
|
|
|
#####################################
|
|
|
|
|
#Do authentication
|
|
|
|
|
#Check if authentication is turned on
|
|
|
|
|
#####################################
|
|
|
|
|
lFlagAccessUserBlock=False
|
|
|
|
|
lAuthenticateDict = {"Domain": "", "User": ""}
|
|
|
|
|
lIsSuperToken = False # Is supertoken
|
|
|
|
|
if gSettingsDict.get("ServerDict", {}).get("AccessUsers", {}).get("FlagCredentialsAsk", False):
|
|
|
|
|
lFlagUserAccess = UserAccessCheckBefore("POST", self)
|
|
|
|
|
######################################
|
|
|
|
|
if lFlagUserAccess:
|
|
|
|
|
lOrchestratorFolder = "\\".join(__file__.split("\\")[:-1])
|
|
|
|
|
############################
|
|
|
|
|
#New server engine (url from global dict (URLList))
|
|
|
|
|
############################
|
|
|
|
|
for lURLItem in gSettingsDict["ServerDict"]["URLList"]:
|
|
|
|
|
#Check if all condition are applied
|
|
|
|
|
lFlagURLIsApplied=False
|
|
|
|
|
lFlagURLIsApplied=self.URLItemCheckDo(lURLItem, "POST")
|
|
|
|
|
if lFlagURLIsApplied:
|
|
|
|
|
self.ResponseDictSend()
|
|
|
|
|
return
|
|
|
|
|
#Централизованная функция получения запросов/отправки
|
|
|
|
|
if self.path == '/Utils/Processor':
|
|
|
|
|
#ReadRequest
|
|
|
|
|
lInputObject={}
|
|
|
|
|
if self.headers.get('Content-Length') is not None:
|
|
|
|
|
lInputByteArrayLength = int(self.headers.get('Content-Length'))
|
|
|
|
|
lInputByteArray=self.rfile.read(lInputByteArrayLength)
|
|
|
|
|
#Превращение массива байт в объект
|
|
|
|
|
lInputObject=json.loads(lInputByteArray.decode('utf8'))
|
|
|
|
|
lAuthenticateDict = AuthenticateVerify(self)
|
|
|
|
|
# Get Flag is supertoken (True|False)
|
|
|
|
|
lIsSuperToken = gSettingsDict.get("ServerDict", {}).get("AccessUsers", {}).get("AuthTokensDict", {}).get(
|
|
|
|
|
self.OpenRPA["AuthToken"], {}).get("FlagDoNotExpire", False)
|
|
|
|
|
if not lAuthenticateDict["User"]:
|
|
|
|
|
lFlagAccessUserBlock=True
|
|
|
|
|
if lFlagAccessUserBlock:
|
|
|
|
|
AuthenticateBlock(self)
|
|
|
|
|
#####################################
|
|
|
|
|
else:
|
|
|
|
|
#Check the user access (if flag)
|
|
|
|
|
####################################
|
|
|
|
|
lFlagUserAccess = True
|
|
|
|
|
#If need user authentication
|
|
|
|
|
if gSettingsDict.get("ServerDict", {}).get("AccessUsers", {}).get("FlagCredentialsAsk", False):
|
|
|
|
|
lFlagUserAccess = UserAccessCheckBefore("POST", self)
|
|
|
|
|
######################################
|
|
|
|
|
if lFlagUserAccess:
|
|
|
|
|
lOrchestratorFolder = "\\".join(__file__.split("\\")[:-1])
|
|
|
|
|
############################
|
|
|
|
|
#New server engine (url from global dict (URLList))
|
|
|
|
|
############################
|
|
|
|
|
for lURLItem in gSettingsDict["ServerDict"]["URLList"]:
|
|
|
|
|
#Check if all condition are applied
|
|
|
|
|
lFlagURLIsApplied=False
|
|
|
|
|
lFlagURLIsApplied=self.URLItemCheckDo(lURLItem, "POST")
|
|
|
|
|
if lFlagURLIsApplied:
|
|
|
|
|
self.ResponseDictSend()
|
|
|
|
|
return
|
|
|
|
|
#Централизованная функция получения запросов/отправки
|
|
|
|
|
if self.path == '/Utils/Processor':
|
|
|
|
|
#ReadRequest
|
|
|
|
|
lInputObject={}
|
|
|
|
|
if self.headers.get('Content-Length') is not None:
|
|
|
|
|
lInputByteArrayLength = int(self.headers.get('Content-Length'))
|
|
|
|
|
lInputByteArray=self.rfile.read(lInputByteArrayLength)
|
|
|
|
|
#Превращение массива байт в объект
|
|
|
|
|
lInputObject=json.loads(lInputByteArray.decode('utf8'))
|
|
|
|
|
# Send response status code
|
|
|
|
|
self.send_response(200)
|
|
|
|
|
# Send headers
|
|
|
|
|
self.send_header('Content-type','application/json')
|
|
|
|
|
self.end_headers()
|
|
|
|
|
# Logging info about processor activity if not SuperToken ()
|
|
|
|
|
if not lIsSuperToken:
|
|
|
|
|
if lL: lL.info(f"Server:: User activity from web. Domain: {self.OpenRPA['Domain']}, Username: {self.OpenRPA['User']}, Activity: {lInputObject}")
|
|
|
|
|
# Send message back to client
|
|
|
|
|
message = json.dumps(ProcessorOld.ActivityListOrDict(lInputObject))
|
|
|
|
|
# Write content as utf-8 data
|
|
|
|
|
self.wfile.write(bytes(message, "utf8"))
|
|
|
|
|
return
|
|
|
|
|
else:
|
|
|
|
|
#Set access denied code
|
|
|
|
|
# Send response status code
|
|
|
|
|
self.send_response(200)
|
|
|
|
|
self.send_response(403)
|
|
|
|
|
# Send headers
|
|
|
|
|
self.send_header('Content-type','application/json')
|
|
|
|
|
self.end_headers()
|
|
|
|
|
# Logging info about processor activity if not SuperToken ()
|
|
|
|
|
if not lIsSuperToken:
|
|
|
|
|
if lL: lL.info(f"Server:: User activity from web. Domain: {self.OpenRPA['Domain']}, Username: {self.OpenRPA['User']}, Activity: {lInputObject}")
|
|
|
|
|
# Send message back to client
|
|
|
|
|
message = json.dumps(ProcessorOld.ActivityListOrDict(lInputObject))
|
|
|
|
|
# Write content as utf-8 data
|
|
|
|
|
self.wfile.write(bytes(message, "utf8"))
|
|
|
|
|
return
|
|
|
|
|
else:
|
|
|
|
|
#Set access denied code
|
|
|
|
|
# Send response status code
|
|
|
|
|
self.send_response(403)
|
|
|
|
|
# Send headers
|
|
|
|
|
self.end_headers()
|
|
|
|
|
return
|
|
|
|
|
return
|
|
|
|
|
except Exception as e:
|
|
|
|
|
lL = gSettingsDict["Logger"]
|
|
|
|
|
if lL: lL.exception(f"Server.do_POST: Global error handler - look traceback below.")
|
|
|
|
|
#Logging
|
|
|
|
|
#!Turn it on to stop print in console
|
|
|
|
|
#def log_message(self, format, *args):
|
|
|
|
|