|
|
|
@ -9,27 +9,16 @@ import uuid
|
|
|
|
|
import datetime
|
|
|
|
|
import os #for path operations
|
|
|
|
|
from http import cookies
|
|
|
|
|
from desktopmagic.screengrab_win32 import (
|
|
|
|
|
getDisplayRects, saveScreenToBmp, saveRectToBmp, getScreenAsImage,
|
|
|
|
|
getRectAsImage, getDisplaysAsImages)
|
|
|
|
|
global mGlobalDict
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def SaveScreenshot(inFilePath):
|
|
|
|
|
# grab fullscreen
|
|
|
|
|
# Save the entire virtual screen as a PNG
|
|
|
|
|
lScreenshot = getScreenAsImage()
|
|
|
|
|
lScreenshot.save('screenshot.png', format='png')
|
|
|
|
|
#lScreenshot = ScreenshotSecondScreen.grab_screen()
|
|
|
|
|
# save image file
|
|
|
|
|
#lScreenshot.save('screenshot.png')
|
|
|
|
|
|
|
|
|
|
from . import ServerSettings
|
|
|
|
|
#inGlobalDict
|
|
|
|
|
# "JSONConfigurationDict":<JSON>
|
|
|
|
|
class RobotDaemonServer(Thread):
|
|
|
|
|
def __init__(self,name,inGlobalDict):
|
|
|
|
|
Thread.__init__(self)
|
|
|
|
|
self.name = name
|
|
|
|
|
# Update the global dict
|
|
|
|
|
ServerSettings.SettingsUpdate(mGlobalDict)
|
|
|
|
|
def run(self):
|
|
|
|
|
inServerAddress="";
|
|
|
|
|
inPort = mGlobalDict["Server"]["ListenPort"];
|
|
|
|
@ -52,6 +41,8 @@ def AuthenticateVerify(inRequest):
|
|
|
|
|
######################################
|
|
|
|
|
#Way 1 - try to find AuthToken
|
|
|
|
|
lCookies = cookies.SimpleCookie(inRequest.headers.get("Cookie", ""))
|
|
|
|
|
inRequest.OpenRPA = {}
|
|
|
|
|
inRequest.OpenRPA["AuthToken"] = None
|
|
|
|
|
#pdb.set_trace()
|
|
|
|
|
if "AuthToken" in lCookies:
|
|
|
|
|
lCookieAuthToken = lCookies.get("AuthToken", "").value
|
|
|
|
@ -61,6 +52,8 @@ def AuthenticateVerify(inRequest):
|
|
|
|
|
#Auth Token Has Been Founded
|
|
|
|
|
lResult["Domain"] = mGlobalDict["Server"]["AccessUsers"]["AuthTokensDict"][lCookieAuthToken]["Domain"]
|
|
|
|
|
lResult["User"] = mGlobalDict["Server"]["AccessUsers"]["AuthTokensDict"][lCookieAuthToken]["User"]
|
|
|
|
|
#Set auth token
|
|
|
|
|
inRequest.OpenRPA["AuthToken"] = lCookieAuthToken
|
|
|
|
|
#Exit earlier
|
|
|
|
|
return lResult
|
|
|
|
|
######################################
|
|
|
|
@ -71,7 +64,7 @@ def AuthenticateVerify(inRequest):
|
|
|
|
|
":")
|
|
|
|
|
lUser = llHeaderAuthorizationDecodedUserPasswordList[0]
|
|
|
|
|
lPassword = llHeaderAuthorizationDecodedUserPasswordList[1]
|
|
|
|
|
lDomain = None
|
|
|
|
|
lDomain = ""
|
|
|
|
|
if "\\" in lUser:
|
|
|
|
|
lDomain = lUser.split("\\")[0]
|
|
|
|
|
lUser = lUser.split("\\")[1]
|
|
|
|
@ -95,8 +88,10 @@ def AuthenticateVerify(inRequest):
|
|
|
|
|
mGlobalDict["Server"]["AccessUsers"]["AuthTokensDict"][lAuthToken]["User"] = lResult["User"]
|
|
|
|
|
mGlobalDict["Server"]["AccessUsers"]["AuthTokensDict"][lAuthToken]["TokenDatetime"] = datetime.datetime.now()
|
|
|
|
|
#Set-cookie
|
|
|
|
|
inRequest.OpenRPA={}
|
|
|
|
|
inRequest.OpenRPA["AuthToken"] = lAuthToken
|
|
|
|
|
inRequest.OpenRPASetCookie = {}
|
|
|
|
|
#New engine of server
|
|
|
|
|
inRequest.OpenRPAResponseDict["SetCookies"]["AuthToken"] = lAuthToken
|
|
|
|
|
#inRequest.OpenRPAResponse["Set-Cookie"]=[]lResult["Set-Cookie"] = lAuthToken
|
|
|
|
|
#pdb.set_trace()
|
|
|
|
|
#inRequest.send_header("Set-Cookie:", f"AuthToken={lAuthToken}")
|
|
|
|
@ -111,8 +106,156 @@ def AuthenticateBlock(inRequest):
|
|
|
|
|
inRequest.end_headers()
|
|
|
|
|
# Write content as utf-8 data
|
|
|
|
|
inRequest.wfile.write(bytes("", "utf8"))
|
|
|
|
|
#Check access before execute the action
|
|
|
|
|
#return bool True - go execute, False - dont execute
|
|
|
|
|
def UserAccessCheckBefore(inMethod, inRequest):
|
|
|
|
|
# Help def - Get access flag from dict
|
|
|
|
|
def HelpGetFlag(inAccessRuleItem, inRequest, inGlobalDict, inAuthenticateDict):
|
|
|
|
|
if "FlagAccess" in inAccessRuleItem:
|
|
|
|
|
return inAccessRuleItem["FlagAccess"]
|
|
|
|
|
elif "FlagAccessDefRequestGlobalAuthenticate" in inAccessRuleItem:
|
|
|
|
|
return inAccessRuleItem["FlagAccessDefRequestGlobalAuthenticate"](inRequest, inGlobalDict,
|
|
|
|
|
inAuthenticateDict)
|
|
|
|
|
##########################################
|
|
|
|
|
inMethod=inMethod.upper()
|
|
|
|
|
#Prepare result false
|
|
|
|
|
lResult = False
|
|
|
|
|
lAuthToken = inRequest.OpenRPA["AuthToken"]
|
|
|
|
|
#go next if user is identified
|
|
|
|
|
lUserDict = None
|
|
|
|
|
if lAuthToken:
|
|
|
|
|
lUserDict = mGlobalDict["Server"]["AccessUsers"]["AuthTokensDict"][lAuthToken]
|
|
|
|
|
#pdb.set_trace()
|
|
|
|
|
########################################
|
|
|
|
|
########################################
|
|
|
|
|
#Check general before rule (without User domain)
|
|
|
|
|
#Check rules
|
|
|
|
|
for lAccessRuleItem in mGlobalDict.get("Server", {}).get("AccessUsers", {}).get("RuleMethodMatchURLBeforeList", []):
|
|
|
|
|
#Go next execution if flag is false
|
|
|
|
|
if not lResult:
|
|
|
|
|
#Check if Method is identical
|
|
|
|
|
if lAccessRuleItem["Method"].upper() == inMethod:
|
|
|
|
|
#check Match type variant: BeginWith
|
|
|
|
|
if lAccessRuleItem["MatchType"].upper() == "BEGINWITH":
|
|
|
|
|
lURLPath = inRequest.path
|
|
|
|
|
lURLPath = lURLPath.upper()
|
|
|
|
|
if lURLPath.startswith(lAccessRuleItem["URL"].upper()):
|
|
|
|
|
lResult = HelpGetFlag(lAccessRuleItem, inRequest, mGlobalDict, lUserDict)
|
|
|
|
|
# check Match type variant: Contains
|
|
|
|
|
elif lAccessRuleItem["MatchType"].upper() == "CONTAINS":
|
|
|
|
|
lURLPath = inRequest.path
|
|
|
|
|
lURLPath = lURLPath.upper()
|
|
|
|
|
if lURLPath.contains(lAccessRuleItem["URL"].upper()):
|
|
|
|
|
lResult = HelpGetFlag(lAccessRuleItem, inRequest, mGlobalDict, lUserDict)
|
|
|
|
|
# check Match type variant: Equal
|
|
|
|
|
elif lAccessRuleItem["MatchType"].upper() == "EQUAL":
|
|
|
|
|
if lAccessRuleItem["URL"].upper() == inRequest.path.upper():
|
|
|
|
|
lResult = HelpGetFlag(lAccessRuleItem, inRequest, mGlobalDict, lUserDict)
|
|
|
|
|
# check Match type variant: EqualCase
|
|
|
|
|
elif lAccessRuleItem["MatchType"].upper() == "EQUALCASE":
|
|
|
|
|
if lAccessRuleItem["URL"] == inRequest.path:
|
|
|
|
|
lResult = HelpGetFlag(lAccessRuleItem, inRequest, mGlobalDict, lUserDict)
|
|
|
|
|
#########################################
|
|
|
|
|
#########################################
|
|
|
|
|
#Do check if lResult is false
|
|
|
|
|
if not lResult:
|
|
|
|
|
#Check access by User Domain
|
|
|
|
|
#Check rules to find first appicable
|
|
|
|
|
#Check rules
|
|
|
|
|
for lAccessRuleItem in mGlobalDict.get("Server", {}).get("AccessUsers", {}).get("RuleDomainUserDict", {}).get((lUserDict["Domain"].upper(), lUserDict["User"].upper()), {}).get("MethodMatchURLBeforeList", []):
|
|
|
|
|
#Go next execution if flag is false
|
|
|
|
|
if not lResult:
|
|
|
|
|
#Check if Method is identical
|
|
|
|
|
if lAccessRuleItem["Method"].upper() == inMethod:
|
|
|
|
|
#check Match type variant: BeginWith
|
|
|
|
|
if lAccessRuleItem["MatchType"].upper() == "BEGINWITH":
|
|
|
|
|
lURLPath = inRequest.path
|
|
|
|
|
lURLPath = lURLPath.upper()
|
|
|
|
|
if lURLPath.startswith(lAccessRuleItem["URL"].upper()):
|
|
|
|
|
lResult = HelpGetFlag(lAccessRuleItem, inRequest, mGlobalDict, lUserDict)
|
|
|
|
|
#check Match type variant: Contains
|
|
|
|
|
elif lAccessRuleItem["MatchType"].upper() == "CONTAINS":
|
|
|
|
|
lURLPath = inRequest.path
|
|
|
|
|
lURLPath = lURLPath.upper()
|
|
|
|
|
if lURLPath.contains(lAccessRuleItem["URL"].upper()):
|
|
|
|
|
lResult = HelpGetFlag(lAccessRuleItem, inRequest, mGlobalDict, lUserDict)
|
|
|
|
|
# check Match type variant: Equal
|
|
|
|
|
elif lAccessRuleItem["MatchType"].upper() == "EQUAL":
|
|
|
|
|
if lAccessRuleItem["URL"].upper() == inRequest.path.upper():
|
|
|
|
|
lResult = HelpGetFlag(lAccessRuleItem, inRequest, mGlobalDict, lUserDict)
|
|
|
|
|
# check Match type variant: EqualCase
|
|
|
|
|
elif lAccessRuleItem["MatchType"].upper() == "EQUALCASE":
|
|
|
|
|
if lAccessRuleItem["URL"] == inRequest.path:
|
|
|
|
|
lResult = HelpGetFlag(lAccessRuleItem, inRequest, mGlobalDict, lUserDict)
|
|
|
|
|
#####################################
|
|
|
|
|
#####################################
|
|
|
|
|
#Return lResult
|
|
|
|
|
return lResult
|
|
|
|
|
# HTTPRequestHandler class
|
|
|
|
|
class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
|
|
|
|
#Tech def
|
|
|
|
|
#return {"headers":[],"body":"","statuscode":111}
|
|
|
|
|
def URLItemCheckDo(self, inURLItem, inMethod):
|
|
|
|
|
###############################
|
|
|
|
|
#Tech sub def - do item
|
|
|
|
|
################################
|
|
|
|
|
def URLItemDo(inURLItem,inRequest,inGlobalDict):
|
|
|
|
|
inResponseDict = inRequest.OpenRPAResponseDict
|
|
|
|
|
#Set status code 200
|
|
|
|
|
inResponseDict["StatusCode"] = 200
|
|
|
|
|
#Content-type
|
|
|
|
|
if "ResponseContentType" in inURLItem:
|
|
|
|
|
inResponseDict["Headers"]["Content-type"] = inURLItem["ResponseContentType"]
|
|
|
|
|
#If file path is set
|
|
|
|
|
if "ResponseFilePath" in inURLItem:
|
|
|
|
|
lFileObject = open(inURLItem["ResponseFilePath"], "rb")
|
|
|
|
|
# Write content as utf-8 data
|
|
|
|
|
inResponseDict["Body"] = lFileObject.read()
|
|
|
|
|
# Закрыть файловый объект
|
|
|
|
|
lFileObject.close()
|
|
|
|
|
#If function is set
|
|
|
|
|
if "ResponseDefRequestGlobal" in inURLItem:
|
|
|
|
|
inURLItem["ResponseDefRequestGlobal"](inRequest, inGlobalDict)
|
|
|
|
|
if "ResponseFolderPath" in inURLItem:
|
|
|
|
|
lRequestPath = inRequest.path
|
|
|
|
|
lFilePathSecondPart = lRequestPath.replace(inURLItem["URL"],"")
|
|
|
|
|
lFilePath = os.path.join(inURLItem["ResponseFolderPath"],lFilePathSecondPart)
|
|
|
|
|
#print(f"File full path {lFilePath}")
|
|
|
|
|
#Check if file exist
|
|
|
|
|
if os.path.exists(lFilePath) and os.path.isfile(lFilePath):
|
|
|
|
|
lFileObject = open(lFilePath, "rb")
|
|
|
|
|
# Write content as utf-8 data
|
|
|
|
|
inResponseDict["Body"] = lFileObject.read()
|
|
|
|
|
inResponseDict["ContentType"]= "application/octet-stream"
|
|
|
|
|
# Закрыть файловый объект
|
|
|
|
|
lFileObject.close()
|
|
|
|
|
##############################################
|
|
|
|
|
if inURLItem["Method"].upper() == inMethod.upper():
|
|
|
|
|
# check Match type variant: BeginWith
|
|
|
|
|
if inURLItem["MatchType"].upper() == "BEGINWITH":
|
|
|
|
|
lURLPath = self.path
|
|
|
|
|
lURLPath = lURLPath.upper()
|
|
|
|
|
if lURLPath.startswith(inURLItem["URL"].upper()):
|
|
|
|
|
URLItemDo(inURLItem, self, mGlobalDict)
|
|
|
|
|
return True
|
|
|
|
|
# check Match type variant: Contains
|
|
|
|
|
elif inURLItem["MatchType"].upper() == "CONTAINS":
|
|
|
|
|
lURLPath = self.path
|
|
|
|
|
lURLPath = lURLPath.upper()
|
|
|
|
|
if lURLPath.contains(inURLItem["URL"].upper()):
|
|
|
|
|
URLItemDo(inURLItem, self, mGlobalDict)
|
|
|
|
|
return True
|
|
|
|
|
# check Match type variant: Equal
|
|
|
|
|
elif inURLItem["MatchType"].upper() == "EQUAL":
|
|
|
|
|
if inURLItem["URL"].upper() == self.path.upper():
|
|
|
|
|
URLItemDo(inURLItem, self, mGlobalDict)
|
|
|
|
|
return True
|
|
|
|
|
# check Match type variant: EqualCase
|
|
|
|
|
elif inURLItem["MatchType"].upper() == "EQUALCASE":
|
|
|
|
|
if inURLItem["URL"] == self.path:
|
|
|
|
|
URLItemDo(inURLItem, self, mGlobalDict)
|
|
|
|
|
return True
|
|
|
|
|
return False
|
|
|
|
|
#ResponseContentTypeFile
|
|
|
|
|
def SendResponseContentTypeFile(self, inContentType, inFilePath):
|
|
|
|
|
# Send response status code
|
|
|
|
@ -120,7 +263,7 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
|
|
|
|
# Send headers
|
|
|
|
|
self.send_header('Content-type', inContentType)
|
|
|
|
|
#Check if var exist
|
|
|
|
|
if hasattr(self, "OpenRPA"):
|
|
|
|
|
if hasattr(self, "OpenRPASetCookie"):
|
|
|
|
|
self.send_header("Set-Cookie", f"AuthToken={self.OpenRPA['AuthToken']}")
|
|
|
|
|
self.end_headers()
|
|
|
|
|
lFileObject = open(inFilePath, "rb")
|
|
|
|
@ -128,8 +271,25 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
|
|
|
|
self.wfile.write(lFileObject.read())
|
|
|
|
|
#Закрыть файловый объект
|
|
|
|
|
lFileObject.close()
|
|
|
|
|
# GET
|
|
|
|
|
# ResponseContentTypeFile
|
|
|
|
|
def ResponseDictSend(self):
|
|
|
|
|
inResponseDict = self.OpenRPAResponseDict
|
|
|
|
|
# Send response status code
|
|
|
|
|
self.send_response(inResponseDict["StatusCode"])
|
|
|
|
|
# Send headers
|
|
|
|
|
for lItemKey, lItemValue in inResponseDict["Headers"].items():
|
|
|
|
|
self.send_header(lItemKey, lItemValue)
|
|
|
|
|
# Send headers: Set-Cookie
|
|
|
|
|
for lItemKey, lItemValue in inResponseDict["SetCookies"].items():
|
|
|
|
|
self.send_header("Set-Cookie", f"{lItemKey}={lItemValue}")
|
|
|
|
|
#Close headers section in response
|
|
|
|
|
self.end_headers()
|
|
|
|
|
# Write content as utf-8 data
|
|
|
|
|
self.wfile.write(inResponseDict["Body"])
|
|
|
|
|
def do_GET(self):
|
|
|
|
|
# Prepare result dict
|
|
|
|
|
lResponseDict = {"Headers": {}, "SetCookies":{}, "Body": "", "StatusCode": None}
|
|
|
|
|
self.OpenRPAResponseDict = lResponseDict
|
|
|
|
|
#####################################
|
|
|
|
|
#Do authentication
|
|
|
|
|
#Check if authentication is turned on
|
|
|
|
@ -144,74 +304,54 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
|
|
|
|
AuthenticateBlock(self)
|
|
|
|
|
#####################################
|
|
|
|
|
else:
|
|
|
|
|
lOrchestratorFolder = "\\".join(__file__.split("\\")[:-1])
|
|
|
|
|
#Мост между файлом и http запросом (новый формат)
|
|
|
|
|
if self.path == "/":
|
|
|
|
|
self.SendResponseContentTypeFile('text/html', os.path.join(lOrchestratorFolder, "Web\\Index.xhtml"))
|
|
|
|
|
#Мост между файлом и http запросом (новый формат)
|
|
|
|
|
if self.path == '/3rdParty/Semantic-UI-CSS-master/semantic.min.css':
|
|
|
|
|
self.SendResponseContentTypeFile('text/css', os.path.join(lOrchestratorFolder, "..\\Resources\\Web\\Semantic-UI-CSS-master\\semantic.min.css"))
|
|
|
|
|
#Мост между файлом и http запросом (новый формат)
|
|
|
|
|
if self.path == '/3rdParty/Semantic-UI-CSS-master/semantic.min.js':
|
|
|
|
|
self.SendResponseContentTypeFile('application/javascript', os.path.join(lOrchestratorFolder, "..\\Resources\\Web\\Semantic-UI-CSS-master\\semantic.min.js"))
|
|
|
|
|
#Мост между файлом и http запросом (новый формат)
|
|
|
|
|
if self.path == '/3rdParty/jQuery/jquery-3.1.1.min.js':
|
|
|
|
|
self.SendResponseContentTypeFile('application/javascript', os.path.join(lOrchestratorFolder,"..\\Resources\\Web\\jQuery\\jquery-3.1.1.min.js"))
|
|
|
|
|
#Мост между файлом и http запросом (новый формат)
|
|
|
|
|
if self.path == '/3rdParty/Google/LatoItalic.css':
|
|
|
|
|
self.SendResponseContentTypeFile('font/css', os.path.join(lOrchestratorFolder, "..\\Resources\\Web\\Google\\LatoItalic.css"))
|
|
|
|
|
#Мост между файлом и http запросом (новый формат)
|
|
|
|
|
if self.path == '/3rdParty/Semantic-UI-CSS-master/themes/default/assets/fonts/icons.woff2':
|
|
|
|
|
self.SendResponseContentTypeFile('font/woff2', os.path.join(lOrchestratorFolder,"..\\Resources\\Web\\Semantic-UI-CSS-master\\themes\\default\\assets\\fonts\\icons.woff2"))
|
|
|
|
|
#Мост между файлом и http запросом (новый формат)
|
|
|
|
|
if self.path == '/favicon.ico':
|
|
|
|
|
self.SendResponseContentTypeFile('image/x-icon', os.path.join(lOrchestratorFolder, "Web\\favicon.ico"))
|
|
|
|
|
#Мост между файлом и http запросом (новый формат)
|
|
|
|
|
if self.path == '/3rdParty/Handlebars/handlebars-v4.1.2.js':
|
|
|
|
|
self.SendResponseContentTypeFile('application/javascript', os.path.join(lOrchestratorFolder,"..\\Resources\\Web\\Handlebars\\handlebars-v4.1.2.js"))
|
|
|
|
|
#Получить скриншот
|
|
|
|
|
if self.path.split("?")[0] == '/GetScreenshot':
|
|
|
|
|
#Сохранить файл на диск
|
|
|
|
|
SaveScreenshot("Screenshot.png")
|
|
|
|
|
self.SendResponseContentTypeFile('image/png',"Screenshot.png")
|
|
|
|
|
#Monitor
|
|
|
|
|
if self.path == '/Monitor/JSONDaemonListGet':
|
|
|
|
|
#Check the user access (if flag)
|
|
|
|
|
####################################
|
|
|
|
|
lFlagUserAccess = True
|
|
|
|
|
#If need user authentication
|
|
|
|
|
if mGlobalDict.get("Server", {}).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 mGlobalDict["Server"]["URLList"]:
|
|
|
|
|
#Check if all condition are applied
|
|
|
|
|
lFlagURLIsApplied=False
|
|
|
|
|
lFlagURLIsApplied=self.URLItemCheckDo(lURLItem, "GET")
|
|
|
|
|
if lFlagURLIsApplied:
|
|
|
|
|
#print("New engine")
|
|
|
|
|
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(mGlobalDict)
|
|
|
|
|
# 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 mGlobalDict["FileManager"]["FileURLFilePathDict"]:
|
|
|
|
|
self.SendResponseContentTypeFile('application/octet-stream',mGlobalDict["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(mGlobalDict)
|
|
|
|
|
# Write content as utf-8 data
|
|
|
|
|
self.wfile.write(bytes(message, "utf8"))
|
|
|
|
|
if self.path == '/Monitor/ControlPanelDictGet':
|
|
|
|
|
# Send response status code
|
|
|
|
|
self.send_response(200)
|
|
|
|
|
# Send headers
|
|
|
|
|
self.send_header('Content-type','application/json')
|
|
|
|
|
self.end_headers()
|
|
|
|
|
#Create result JSON
|
|
|
|
|
lResultJSON={"RenderRobotList":[]}
|
|
|
|
|
lRenderFunctionsRobotList=mGlobalDict["ControlPanelDict"]["RobotList"]
|
|
|
|
|
for lItem in lRenderFunctionsRobotList:
|
|
|
|
|
#Выполнить вызов и записать результат
|
|
|
|
|
lItemResultDict=lItem["RenderFunction"](mGlobalDict)
|
|
|
|
|
#RunFunction
|
|
|
|
|
lResultJSON["RenderRobotList"].append(lItemResultDict)
|
|
|
|
|
# Send message back to client
|
|
|
|
|
message = json.dumps(lResultJSON)
|
|
|
|
|
# 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 mGlobalDict["FileManager"]["FileURLFilePathDict"]:
|
|
|
|
|
self.SendResponseContentTypeFile('application/octet-stream',mGlobalDict["FileManager"]["FileURLFilePathDict"][lFileURL])
|
|
|
|
|
# Auth function
|
|
|
|
|
# POST
|
|
|
|
|
def do_POST(self):
|
|
|
|
|
# Prepare result dict
|
|
|
|
|
lResponseDict = {"Headers": {}, "SetCookies":{}, "Body": "", "StatusCode": None}
|
|
|
|
|
self.OpenRPAResponseDict = lResponseDict
|
|
|
|
|
#####################################
|
|
|
|
|
#Do authentication
|
|
|
|
|
#Check if authentication is turned on
|
|
|
|
@ -226,22 +366,30 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
|
|
|
|
AuthenticateBlock(self)
|
|
|
|
|
#####################################
|
|
|
|
|
else:
|
|
|
|
|
#Централизованная функция получения запросов/отправки
|
|
|
|
|
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()
|
|
|
|
|
# Send message back to client
|
|
|
|
|
message = json.dumps(Processor.ActivityListOrDict(lInputObject))
|
|
|
|
|
# Write content as utf-8 data
|
|
|
|
|
self.wfile.write(bytes(message, "utf8"))
|
|
|
|
|
return
|
|
|
|
|
#Check the user access (if flag)
|
|
|
|
|
####################################
|
|
|
|
|
lFlagUserAccess = True
|
|
|
|
|
#If need user authentication
|
|
|
|
|
if mGlobalDict.get("Server", {}).get("AccessUsers", {}).get("FlagCredentialsAsk", False):
|
|
|
|
|
lFlagUserAccess = UserAccessCheckBefore("GET", self)
|
|
|
|
|
######################################
|
|
|
|
|
if lFlagUserAccess:
|
|
|
|
|
#Централизованная функция получения запросов/отправки
|
|
|
|
|
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()
|
|
|
|
|
# Send message back to client
|
|
|
|
|
message = json.dumps(Processor.ActivityListOrDict(lInputObject))
|
|
|
|
|
# Write content as utf-8 data
|
|
|
|
|
self.wfile.write(bytes(message, "utf8"))
|
|
|
|
|
return
|