|
|
|
@ -101,6 +101,8 @@ def AuthenticateVerify(inRequest):
|
|
|
|
|
#Set-cookie
|
|
|
|
|
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}")
|
|
|
|
@ -204,11 +206,14 @@ def UserAccessCheckBefore(inMethod, inRequest):
|
|
|
|
|
class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
|
|
|
|
#Tech def
|
|
|
|
|
#return {"headers":[],"body":"","statuscode":111}
|
|
|
|
|
def URLItemCheckDo(self, inURLItem, inMethod, inResponseDict):
|
|
|
|
|
def URLItemCheckDo(self, inURLItem, inMethod):
|
|
|
|
|
###############################
|
|
|
|
|
#Tech sub def - do item
|
|
|
|
|
################################
|
|
|
|
|
def URLItemDo(inURLItem,inRequest,inGlobalDict,inResponseDict):
|
|
|
|
|
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"]
|
|
|
|
@ -221,7 +226,7 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
|
|
|
|
lFileObject.close()
|
|
|
|
|
#If function is set
|
|
|
|
|
if "ResponseDefRequestGlobalResponse" in inURLItem:
|
|
|
|
|
inURLItem["ResponseDefRequestGlobalResponse"](inRequest,inGlobalDict,inResponseDict)
|
|
|
|
|
inURLItem["ResponseDefRequestGlobal"](inRequest,inGlobalDict)
|
|
|
|
|
# TODO If folder path is set
|
|
|
|
|
if "ResponseFolderPath" in inURLItem:
|
|
|
|
|
#
|
|
|
|
@ -233,24 +238,24 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
|
|
|
|
lURLPath = self.path
|
|
|
|
|
lURLPath = lURLPath.upper()
|
|
|
|
|
if lURLPath.startswith(inURLItem["URL"].upper()):
|
|
|
|
|
URLItemDo(inURLItem, self, mGlobalDict,inResponseDict)
|
|
|
|
|
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,inResponseDict)
|
|
|
|
|
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,inResponseDict)
|
|
|
|
|
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,inResponseDict)
|
|
|
|
|
URLItemDo(inURLItem, self, mGlobalDict)
|
|
|
|
|
return True
|
|
|
|
|
return False
|
|
|
|
|
#ResponseContentTypeFile
|
|
|
|
@ -269,20 +274,24 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
|
|
|
|
#Закрыть файловый объект
|
|
|
|
|
lFileObject.close()
|
|
|
|
|
# ResponseContentTypeFile
|
|
|
|
|
def ResponseDictSend(self, inResponseDict):
|
|
|
|
|
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"])
|
|
|
|
|
# GET
|
|
|
|
|
def do_GET(self):
|
|
|
|
|
# Prepare result dict
|
|
|
|
|
lResponseDict = {"Headers": {}, "Set-cookies":{}, "Body": "", "StatusCode": None}
|
|
|
|
|
lResponseDict = {"Headers": {}, "SetCookies":{}, "Body": "", "StatusCode": None}
|
|
|
|
|
self.OpenRPAResponseDict = lResponseDict
|
|
|
|
|
#####################################
|
|
|
|
|
#Do authentication
|
|
|
|
|
#Check if authentication is turned on
|
|
|
|
@ -309,38 +318,15 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
|
|
|
|
############################
|
|
|
|
|
#New server engine (url from global dict (URLList))
|
|
|
|
|
############################
|
|
|
|
|
for lURLItem in mGlobalDict["URLList"]:
|
|
|
|
|
for lURLItem in mGlobalDict["Server"]["URLList"]:
|
|
|
|
|
#Check if all condition are applied
|
|
|
|
|
lFlagURLIsApplied=False
|
|
|
|
|
lFlagURLIsApplied=self.URLItemCheckDo(lURLItem, "GET", lResponseDict)
|
|
|
|
|
lFlagURLIsApplied=self.URLItemCheckDo(lURLItem, "GET")
|
|
|
|
|
if lFlagURLIsApplied:
|
|
|
|
|
self.ResponseDictSend(lResponseDict)
|
|
|
|
|
print("New engine")
|
|
|
|
|
self.ResponseDictSend()
|
|
|
|
|
return
|
|
|
|
|
###################################################
|
|
|
|
|
#Мост между файлом и 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':
|
|
|
|
|
#Сохранить файл на диск
|
|
|
|
@ -389,6 +375,9 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
|
|
|
|
self.end_headers()
|
|
|
|
|
# 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
|
|
|
|
|