#Orchestrator AccessUser for test

dev-linux
Ivan Maslov 5 years ago
parent 6d442a424e
commit f6ed0cf27a

@ -0,0 +1,3 @@
iAccessible
iAccessible2
MSAA

@ -76,14 +76,19 @@ def Settings():
"URL": "http://127.0.0.1:8081" "URL": "http://127.0.0.1:8081"
} }
], ],
"AccessUsers": { "AccessUsers": { #Defaul - all URL is blocked
"FlagCredentialsAsk": True, #Turn on Authentication "FlagCredentialsAsk": True, #Turn on Authentication
"FlagNoRulesBlock": True, #Block request, if user has no rules for requested URL (if FlagCredentialAsk is turned on) "RuleDict": {
"UserDict": {
#("Domain", "User"): { #("Domain", "User"): {
# "FunctionDict": { # "MethodMatchURLBeforeList": [
# # ("Method|GET|POST", "Match type|BeginWith|Contains", "URL"): def function (inRequest, inGlobalDict, inAuthenticateDict) # {
# } # "Method":"GET|POST",
# "MatchType":"BeginWith|Contains|Equal|EqualCase",
# "URL":"",
# "FlagAccessDefRequestGlobalAuthenticate": None, #Return bool
# "FlagAccess": True
# }
# ]
#} #}
}, },
"AuthTokensDict": { "AuthTokensDict": {

@ -111,6 +111,50 @@ def AuthenticateBlock(inRequest):
inRequest.end_headers() inRequest.end_headers()
# Write content as utf-8 data # Write content as utf-8 data
inRequest.wfile.write(bytes("", "utf8")) 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
#Check rules to find first appicable
lAuthToken = inRequest.OpenRPA["AuthToken"]
#go next if user is identified
lUserDict = None
if lAuthToken:
lUserDict = mGlobalDict["Server"]["AccessUsers"]["AuthTokensDict"][lAuthToken]
#Check rules
for lAccessRuleItem in mGlobalDict.get("Server", {}).get("AccessUsers", {}).get("RuleDict", {}).get((lUserDict["Domain"], lUserDict["User"]), {}).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":
if inRequest.path.startswith(lAccessRuleItem["URL"]):
lResult = HelpGetFlag(lAccessRuleItem, inRequest, mGlobalDict, lUserDict)
#check Match type variant: Contains
elif lAccessRuleItem["MatchType"].upper() == "CONTAINS":
if inRequest.path.contains(lAccessRuleItem["URL"]):
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 # HTTPRequestHandler class
class testHTTPServer_RequestHandler(BaseHTTPRequestHandler): class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
#ResponseContentTypeFile #ResponseContentTypeFile
@ -144,72 +188,79 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
AuthenticateBlock(self) AuthenticateBlock(self)
##################################### #####################################
else: else:
lOrchestratorFolder = "\\".join(__file__.split("\\")[:-1]) #Check the user access (if flag)
#Мост между файлом и http запросом (новый формат) ####################################
if self.path == "/": lFlagUserAccess = True
self.SendResponseContentTypeFile('text/html', os.path.join(lOrchestratorFolder, "Web\\Index.xhtml")) #If need user authentication
#Мост между файлом и http запросом (новый формат) if mGlobalDict.get("Server", {}).get("AccessUsers", {}).get("FlagCredentialsAsk", False):
if self.path == '/3rdParty/Semantic-UI-CSS-master/semantic.min.css': lFlagUserAccess = UserAccessCheckBefore("GET", self)
self.SendResponseContentTypeFile('text/css', os.path.join(lOrchestratorFolder, "..\\Resources\\Web\\Semantic-UI-CSS-master\\semantic.min.css")) ######################################
#Мост между файлом и http запросом (новый формат) if lFlagUserAccess:
if self.path == '/3rdParty/Semantic-UI-CSS-master/semantic.min.js': lOrchestratorFolder = "\\".join(__file__.split("\\")[:-1])
self.SendResponseContentTypeFile('application/javascript', os.path.join(lOrchestratorFolder, "..\\Resources\\Web\\Semantic-UI-CSS-master\\semantic.min.js")) #Мост между файлом и http запросом (новый формат)
#Мост между файлом и http запросом (новый формат) if self.path == "/":
if self.path == '/3rdParty/jQuery/jquery-3.1.1.min.js': self.SendResponseContentTypeFile('text/html', os.path.join(lOrchestratorFolder, "Web\\Index.xhtml"))
self.SendResponseContentTypeFile('application/javascript', os.path.join(lOrchestratorFolder,"..\\Resources\\Web\\jQuery\\jquery-3.1.1.min.js")) #Мост между файлом и http запросом (новый формат)
#Мост между файлом и http запросом (новый формат) if self.path == '/3rdParty/Semantic-UI-CSS-master/semantic.min.css':
if self.path == '/3rdParty/Google/LatoItalic.css': self.SendResponseContentTypeFile('text/css', os.path.join(lOrchestratorFolder, "..\\Resources\\Web\\Semantic-UI-CSS-master\\semantic.min.css"))
self.SendResponseContentTypeFile('font/css', os.path.join(lOrchestratorFolder, "..\\Resources\\Web\\Google\\LatoItalic.css")) #Мост между файлом и http запросом (новый формат)
#Мост между файлом и http запросом (новый формат) if self.path == '/3rdParty/Semantic-UI-CSS-master/semantic.min.js':
if self.path == '/3rdParty/Semantic-UI-CSS-master/themes/default/assets/fonts/icons.woff2': self.SendResponseContentTypeFile('application/javascript', os.path.join(lOrchestratorFolder, "..\\Resources\\Web\\Semantic-UI-CSS-master\\semantic.min.js"))
self.SendResponseContentTypeFile('font/woff2', os.path.join(lOrchestratorFolder,"..\\Resources\\Web\\Semantic-UI-CSS-master\\themes\\default\\assets\\fonts\\icons.woff2")) #Мост между файлом и http запросом (новый формат)
#Мост между файлом и http запросом (новый формат) if self.path == '/3rdParty/jQuery/jquery-3.1.1.min.js':
if self.path == '/favicon.ico': self.SendResponseContentTypeFile('application/javascript', os.path.join(lOrchestratorFolder,"..\\Resources\\Web\\jQuery\\jquery-3.1.1.min.js"))
self.SendResponseContentTypeFile('image/x-icon', os.path.join(lOrchestratorFolder, "Web\\favicon.ico")) #Мост между файлом и http запросом (новый формат)
#Мост между файлом и http запросом (новый формат) if self.path == '/3rdParty/Google/LatoItalic.css':
if self.path == '/3rdParty/Handlebars/handlebars-v4.1.2.js': self.SendResponseContentTypeFile('font/css', os.path.join(lOrchestratorFolder, "..\\Resources\\Web\\Google\\LatoItalic.css"))
self.SendResponseContentTypeFile('application/javascript', os.path.join(lOrchestratorFolder,"..\\Resources\\Web\\Handlebars\\handlebars-v4.1.2.js")) #Мост между файлом и http запросом (новый формат)
#Получить скриншот if self.path == '/3rdParty/Semantic-UI-CSS-master/themes/default/assets/fonts/icons.woff2':
if self.path.split("?")[0] == '/GetScreenshot': self.SendResponseContentTypeFile('font/woff2', os.path.join(lOrchestratorFolder,"..\\Resources\\Web\\Semantic-UI-CSS-master\\themes\\default\\assets\\fonts\\icons.woff2"))
#Сохранить файл на диск #Мост между файлом и http запросом (новый формат)
SaveScreenshot("Screenshot.png") if self.path == '/favicon.ico':
self.SendResponseContentTypeFile('image/png',"Screenshot.png") self.SendResponseContentTypeFile('image/x-icon', os.path.join(lOrchestratorFolder, "Web\\favicon.ico"))
#Monitor #Мост между файлом и http запросом (новый формат)
if self.path == '/Monitor/JSONDaemonListGet': if self.path == '/3rdParty/Handlebars/handlebars-v4.1.2.js':
# Send response status code self.SendResponseContentTypeFile('application/javascript', os.path.join(lOrchestratorFolder,"..\\Resources\\Web\\Handlebars\\handlebars-v4.1.2.js"))
self.send_response(200) #Получить скриншот
# Send headers if self.path.split("?")[0] == '/GetScreenshot':
self.send_header('Content-type','application/json') #Сохранить файл на диск
self.end_headers() SaveScreenshot("Screenshot.png")
# Send message back to client self.SendResponseContentTypeFile('image/png',"Screenshot.png")
message = json.dumps(mGlobalDict) #Monitor
# Write content as utf-8 data if self.path == '/Monitor/JSONDaemonListGet':
self.wfile.write(bytes(message, "utf8")) # Send response status code
if self.path == '/Monitor/ControlPanelDictGet': self.send_response(200)
# Send response status code # Send headers
self.send_response(200) self.send_header('Content-type','application/json')
# Send headers self.end_headers()
self.send_header('Content-type','application/json') # Send message back to client
self.end_headers() message = json.dumps(mGlobalDict)
#Create result JSON # Write content as utf-8 data
lResultJSON={"RenderRobotList":[]} self.wfile.write(bytes(message, "utf8"))
lRenderFunctionsRobotList=mGlobalDict["ControlPanelDict"]["RobotList"] if self.path == '/Monitor/ControlPanelDictGet':
for lItem in lRenderFunctionsRobotList: # Send response status code
#Выполнить вызов и записать результат self.send_response(200)
lItemResultDict=lItem["RenderFunction"](mGlobalDict) # Send headers
#RunFunction self.send_header('Content-type','application/json')
lResultJSON["RenderRobotList"].append(lItemResultDict) self.end_headers()
# Send message back to client #Create result JSON
message = json.dumps(lResultJSON) lResultJSON={"RenderRobotList":[]}
# Write content as utf-8 data lRenderFunctionsRobotList=mGlobalDict["ControlPanelDict"]["RobotList"]
self.wfile.write(bytes(message, "utf8")) for lItem in lRenderFunctionsRobotList:
#Filemanager function #Выполнить вызов и записать результат
if self.path.lower().startswith('/filemanager/'): lItemResultDict=lItem["RenderFunction"](mGlobalDict)
lFileURL=self.path[13:] #RunFunction
# check if file in FileURL - File Path Mapping Dict lResultJSON["RenderRobotList"].append(lItemResultDict)
if lFileURL.lower() in mGlobalDict["FileManager"]["FileURLFilePathDict"]: # Send message back to client
self.SendResponseContentTypeFile('application/octet-stream',mGlobalDict["FileManager"]["FileURLFilePathDict"][lFileURL]) message = json.dumps(lResultJSON)
# Auth function # 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])
# POST # POST
def do_POST(self): def do_POST(self):
##################################### #####################################
@ -226,22 +277,30 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
AuthenticateBlock(self) AuthenticateBlock(self)
##################################### #####################################
else: else:
#Централизованная функция получения запросов/отправки #Check the user access (if flag)
if self.path == '/Utils/Processor': ####################################
#ReadRequest lFlagUserAccess = True
lInputObject={} #If need user authentication
if self.headers.get('Content-Length') is not None: if mGlobalDict.get("Server", {}).get("AccessUsers", {}).get("FlagCredentialsAsk", False):
lInputByteArrayLength = int(self.headers.get('Content-Length')) lFlagUserAccess = UserAccessCheckBefore("GET", self)
lInputByteArray=self.rfile.read(lInputByteArrayLength) ######################################
#Превращение массива байт в объект if lFlagUserAccess:
lInputObject=json.loads(lInputByteArray.decode('utf8')) #Централизованная функция получения запросов/отправки
# Send response status code if self.path == '/Utils/Processor':
self.send_response(200) #ReadRequest
# Send headers lInputObject={}
self.send_header('Content-type','application/json') if self.headers.get('Content-Length') is not None:
self.end_headers() lInputByteArrayLength = int(self.headers.get('Content-Length'))
# Send message back to client lInputByteArray=self.rfile.read(lInputByteArrayLength)
message = json.dumps(Processor.ActivityListOrDict(lInputObject)) #Превращение массива байт в объект
# Write content as utf-8 data lInputObject=json.loads(lInputByteArray.decode('utf8'))
self.wfile.write(bytes(message, "utf8")) # Send response status code
return 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
Loading…
Cancel
Save