v1.1.8 UIDesktop minor bugfix from pywinauto with ctype.ArgumentError

Add Orchestrator UserRole model, Add Web render with user roles
dev-linux
Ivan Maslov 5 years ago
parent 0f22e8ebeb
commit 4c8d0e3187

@ -101,8 +101,19 @@ def Settings():
# "FlagAccess": True
# }
# ],
# "ControlPanelKeyAllowedList":[] # If empty - all is allowed
#}
# "ControlPanelKeyAllowedList":[], # If empty - all is allowed
# "RoleHierarchyAllowedDict": {
# "Orchestrator":{
# "Controls": {
# "RestartOrchestrator": {}, # Feature to restart orchestrator on virtual machine
# "LookMachineScreenshots": {} # Feature to look machina screenshots
# },
# "RDPActive": { # Robot RDP active module
# "ListRead": {} # Access to read RDP session list
# }
# }
# }
# }
},
"RuleMethodMatchURLBeforeList": [ #General MethodMatchURL list (no domain/user)
# {

@ -1,3 +1,19 @@
# Role model - if len of keys in dict is 0 - all access. If at least len is 1 - only this access
# "Orchestrator":{
# "Controls": {
# "RestartOrchestrator": {}, # Feature to restart orchestrator on virtual machine
# "LookMachineScreenshots": {} # Feature to look machina screenshots
# },
# "RDPActive": { # Robot RDP active module
# "ListRead": {} # Access to read RDP session list
# }
# }
# }
# USAGE in .py
# inRequest.
# inRequest.OpenRPA["DefUserRoleAccessAsk"](["Orchestrator","RDPActive","Controls"]) - return True or False
# inRequest.OpenRPA["DefUserRoleHierarchyGet"]() - Return dict of the role hierarchy or {}
# Init Section
gUserNameStr = "Login" # User name without domain name
gDomainNameStr = "" # DOMAIN or EMPTY str if no domain

@ -22,6 +22,8 @@ from http import cookies
global gSettingsDict
from . import ServerSettings
import copy
#Authenticate function ()
# return dict
# {
@ -33,10 +35,6 @@ def AuthenticateVerify(inRequest):
######################################
#Way 1 - try to find AuthToken
lCookies = cookies.SimpleCookie(inRequest.headers.get("Cookie", ""))
inRequest.OpenRPA = {}
inRequest.OpenRPA["AuthToken"] = None
inRequest.OpenRPA["Domain"] = None
inRequest.OpenRPA["User"] = None
#pdb.set_trace()
if "AuthToken" in lCookies:
lCookieAuthToken = lCookies.get("AuthToken", "").value
@ -193,6 +191,34 @@ def UserAccessCheckBefore(inMethod, inRequest):
return lResult
# HTTPRequestHandler class
class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
# Def to check User Role access grants
def UserRoleAccessAsk(self, inRoleKeyList):
lResult = True # Init flag
lRoleHierarchyDict = self.UserRoleHierarchyGet() # get the Hierarchy
# Try to get value from key list
lKeyValue = lRoleHierarchyDict # Init the base
for lItem in inRoleKeyList:
if type(lKeyValue) is dict:
if lItem in lKeyValue: # Has key
lKeyValue = lKeyValue[lItem] # Get the value and go to the next loop iteration
else: # Else branch - true or false
if len(lKeyValue)>0: # False - if Dict has some elements
lResult = False # Set the False Flag
else:
lResult = True # Set the True flag
break # Stop the loop
else: # Has element with no detalization - return True
lResult = True # Set the flag
break # Close the loop
return lResult # Return the result
# Def to get hierarchy of the current user roles
# if return {} - all is available
def UserRoleHierarchyGet(self):
lDomainUpperStr = self.OpenRPA["Domain"].upper()
lUserUpperStr = self.OpenRPA["User"].upper()
return gSettingsDict.get("Server", {}).get("AccessUsers", {}).get("RuleDomainUserDict", {}).get((lDomainUpperStr, lUserUpperStr), {}).get("RoleHierarchyAllowedDict", {})
#Tech def
#return {"headers":[],"body":"","statuscode":111}
def URLItemCheckDo(self, inURLItem, inMethod):
@ -287,6 +313,12 @@ 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
@ -350,6 +382,13 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
self.end_headers()
# 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}
@ -360,8 +399,14 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
#####################################
lFlagAccessUserBlock=False
lAuthenticateDict = {"Domain": "", "User": ""}
lIsSuperToken = False # Is supertoken
if gSettingsDict.get("Server", {}).get("AccessUsers", {}).get("FlagCredentialsAsk", False):
lAuthenticateDict = AuthenticateVerify(self)
# Get Flag is supertoken (True|False)
lDomainUpperStr = self.OpenRPA["Domain"].upper()
lUserUpperStr = self.OpenRPA["User"].upper()
lIsSuperToken = gSettingsDict.get("Server", {}).get("AccessUsers", {}).get("AuthTokensDict", {}).get(
(lDomainUpperStr, lUserUpperStr), {}).get("FlagDoNotExpire", False)
if not lAuthenticateDict["User"]:
lFlagAccessUserBlock=True
if lFlagAccessUserBlock:
@ -401,6 +446,9 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
# 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(Processor.ActivityListOrDict(lInputObject))
# Write content as utf-8 data

@ -47,6 +47,16 @@ def Monitor_ControlPanelDictGet(inRequest,inGlobalDict):
# Write content as utf-8 data
inResponseDict["Body"] = bytes(message, "utf8")
# UserAccess get rights hierarchy dict in json
def UserRoleHierarchyGet(inRequest,inGlobalDict):
inResponseDict = inRequest.OpenRPAResponseDict
# Create result JSON
lResultDict = inRequest.OpenRPA["DefUserRoleHierarchyGet"]() # Get the User Role Hierarchy list
# Send message back to client
message = json.dumps(lResultDict)
# Write content as utf-8 data
inResponseDict["Body"] = bytes(message, "utf8")
def GetScreenshot(inRequest,inGlobalDict):
# Get Screenshot
def SaveScreenshot(inFilePath):
@ -90,7 +100,8 @@ def SettingsUpdate(inGlobalConfiguration):
{"Method":"GET", "URL": "/3rdParty/Handlebars/handlebars-v4.1.2.js", "MatchType": "EqualCase", "ResponseFilePath": os.path.join(lOrchestratorFolder, "..\\Resources\\Web\\Handlebars\\handlebars-v4.1.2.js"), "ResponseContentType": "application/javascript"},
{"Method": "GET", "URL": "/Monitor/ControlPanelDictGet", "MatchType": "Equal", "ResponseDefRequestGlobal": Monitor_ControlPanelDictGet, "ResponseContentType": "application/json"},
{"Method": "GET", "URL": "/GetScreenshot", "MatchType": "BeginWith", "ResponseDefRequestGlobal": GetScreenshot, "ResponseContentType": "image/png"},
{"Method": "GET", "URL": "/Orchestrator/RobotRDPActive/ControlPanelDictGet", "MatchType": "Equal","ResponseDefRequestGlobal": RobotRDPActive_ControlPanelDictGet, "ResponseContentType": "application/json"}
{"Method": "GET", "URL": "/Orchestrator/RobotRDPActive/ControlPanelDictGet", "MatchType": "Equal","ResponseDefRequestGlobal": RobotRDPActive_ControlPanelDictGet, "ResponseContentType": "application/json"},
{"Method": "POST", "URL": "/Orchestrator/UserRoleHierarchyGet", "MatchType": "Equal","ResponseDefRequestGlobal": UserRoleHierarchyGet, "ResponseContentType": "application/json"}
]
inGlobalConfiguration["Server"]["URLList"]=inGlobalConfiguration["Server"]["URLList"]+lURLList
return inGlobalConfiguration

@ -388,37 +388,6 @@
dataType: "text"
});
}
///////////////////////////////
///Scheduler functions
///////////////////////////////
mGlobal.Scheduler = {}
mGlobal.Scheduler.ActivityTimeListShow = function() {
lData = [
{
"Type":"GlobalDictKeyListValueGet",
"KeyList":["Scheduler","ActivityTimeList"]
}
]
$.ajax({
type: "POST",
url: 'Utils/Processor',
data: JSON.stringify(lData),
success:
function(lData,l2,l3)
{
var lResponseJSON=JSON.parse(lData)
lResponseJSON[0]["Result"].forEach(function(lItem){lItem["processPathName"]=("processPath" in lItem ? lItem["processPath"] : lItem["processName"])})
///Отправить запрос на формирование таблицы
lHTMLCode=mGlobal.GeneralGenerateHTMLCodeHandlebars(".openrpa-hidden-info-table-planloglist",lResponseJSON[0]);
///Установить HTML код
$('.ui.modal.basic .content').html(lHTMLCode);
$('.ui.modal.basic').modal('show');
},
dataType: "text"
});
}
///////////////////////////////
///Processor functions
///////////////////////////////
@ -507,32 +476,6 @@
dataType: "text"
});
}
mGlobal.Processor.LogListShow = function() {
lData = [
{
"Type":"GlobalDictKeyListValueGet",
"KeyList":["Processor","LogList"]
}
]
///Обнулить таблицу
$('.ui.modal.basic .content').html("");
$.ajax({
type: "POST",
url: 'Utils/Processor',
data: JSON.stringify(lData),
success:
function(lData,l2,l3)
{
var lResponseJSON=JSON.parse(lData)
///Отправить запрос на формирование таблицы
lHTMLCode=mGlobal.GeneralGenerateHTMLCodeHandlebars(".openrpa-hidden-info-table-activitylogschedulelist",lResponseJSON["actionListResult"][0])
///Установить HTML код
$('.ui.modal.basic .content').html(lHTMLCode);
$('.ui.modal.basic').modal('show');
},
dataType: "text"
});
}
mGlobal.Server= {}
mGlobal.Server.JSONGet=function(inMethod, inURL, inDataJSON, inCallback)
{
@ -661,6 +604,37 @@
///Установить HTML код
lElementParentElement.insertAdjacentHTML("beforeend",lHTMLCode);
}
// Check user roles and update the Orchestrator UI
mGlobal.UserRoleUpdate=function() {
$.ajax({
type: "POST",
url: 'Orchestrator/UserRoleHierarchyGet',
data: "",
success:
function(lData,l2,l3)
{
var lResponseDict=JSON.parse(lData)
//Turn on the Lookmachine screenshot button
var lDict = ((lResponseDict["Orchestrator"] || {})["Controls"] || {}) // Get the Controls dict
if ("LookMachineScreenshots" in lDict || Object.keys(lDict).length == 0) {
$(".openrpa-control-lookmachinescreenshot").show() //Show button
}
//Turn on the restart orchestrator button
var lDict = ((lResponseDict["Orchestrator"] || {})["Controls"] || {}) // Get the Controls dict
if ("RestartOrchestrator" in lDict || Object.keys(lDict).length == 0) {
$(".openrpa-control-restartorchestrator").show() //Show button
}
//Turn on the rdp session list
var lDict = ((lResponseDict["Orchestrator"] || {})["RDPActive"] || {}) // Get the Controls dict
if ("ListRead" in lDict || Object.keys(lDict).length == 0) {
$(".openrpa-rdpactive-title").show() //Show section
$(".openrpa-robotrdpactive-control-panel-general").show() //Show section
}
},
dataType: "text"
});
}
mGlobal.UserRoleUpdate() // Cal the update User Roles function
})
;
</script>
@ -781,75 +755,20 @@
<h2 class="ui header inverted">...</h2>
</div>
<div class="nine wide column">
<h2 class="ui header inverted">Robot RDP active list</h2>
<h2 class="ui header inverted openrpa-rdpactive-title" style="display:none;">Robot RDP active list</h2>
</div>
</div>
<div class="row">
<div class="five wide column">
<button class="ui labeled icon button" onclick="mGlobal.Monitor.ScreenshotModal.Show();">
<button class="ui labeled icon button openrpa-control-lookmachinescreenshot" onclick="mGlobal.Monitor.ScreenshotModal.Show();" style="display: none;">
<i class="desktop icon"></i>
Look machine screenshot
</button>
<button class="ui labeled icon button red" onclick="mGlobal.Controller.OrchestratorRestart();">
<button class="ui labeled icon button red openrpa-control-restartorchestrator" onclick="mGlobal.Controller.OrchestratorRestart(); " style="display: none;>
<i class="redo icon"></i>
Restart Orchestrator
</button>
<button class="ui labeled icon button" onclick="mGlobal.Scheduler.ActivityTimeListShow();">
<i class="info icon"></i>
Scheduler activity time list
<script class="openrpa-hidden-info-table-planloglist" style="display:none" type="text/x-handlebars-template">
<table class="ui celled table">
<thead>
<tr>
<th>#</th>
<th>Activity type</th>
<th>Time</th>
<th>Process path/Process name</th>
</tr>
</thead>
<tbody>
{{#Result}}
<tr>
<td>{{@index}}</td>
<td>{{TimeHH:MM}}{{TimeHH:MMStart}}</td>
<td>{{TimeHH:MMStop}}</td>
<td>{{Activity}}</td>
</tr>
{{/Result}}
</tbody>
</table>
</script>
</button>
<button class="ui labeled icon button" onclick="mGlobal.Processor.LogListShow();">
<i class="info icon"></i>
Processor logs
<script class="openrpa-hidden-info-table-activitylogschedulelist" style="display:none" type="text/x-handlebars-template">
<table class="ui celled table">
<thead>
<tr>
<th>#</th>
<th>Activity type</th>
<th>Process</th>
<th>Activity DateTime plan</th>
<th>Activity DateTime fact</th>
</tr>
</thead>
<tbody>
{{#result}}
<tr>
<td>{{@index}}</td>
<td>{{activityType}}</td>
<td>{{processPath}}</td>
<td>{{activityDateTime}}</td>
<td class="negative
">{{activityStartDateTime}}</td>
</tr>
{{/result}}
</tbody>
</table>
</script>
</button>
<script class="openrpa-hidden-monitor-table-general" style="display:none" type="text/x-handlebars-template">
<table class="ui celled table">
@ -927,7 +846,7 @@
</div>
<div class="two wide column">
</div>
<div class="nine wide column openrpa-robotrdpactive-control-panel-general">
<div class="nine wide column openrpa-robotrdpactive-control-panel-general" style="display:none;">
<div class="ui info message">
<button class="ui icon button labeled " onclick="mGlobal.RobotRDPActive.fControlPanelRefresh();">
<i class="sync alternate icon"></i>

@ -118,7 +118,15 @@ def UIOSelector_Get_UIOList (inSpecificationList,inElement=None,inFlagRaiseExcep
#Елемент на вход поступил - выполнить его анализ
else:
#Получить список элементов
lElementChildrenList=inElement.children()
lElementChildrenList = None
# 2020 06 10 Some times exception ctypes.ArgumentError is apper - set try except with wait
lFlagBool = True
while lFlagBool:
try:
lElementChildrenList = inElement.children()
lFlagBool = False # turn off the loop - all is ok
except ctypes.ArgumentError as e:
time.sleep(30) # error has come - go in sleep and retry
#Поступил index - точное добавление
if 'index' in inSpecificationList[0]:
if inSpecificationList[0]['index']<len(lElementChildrenList):
@ -444,7 +452,15 @@ def PWASpecification_Get_UIO(inControlSpecificationArray):
lTempObject=None
if len(inControlSpecificationArray) > 0:
#Сформировать выборку элементов, которые подходят под первый уровень спецификации
lSpecificationLvL1List = pywinauto.findwindows.find_elements(**inControlSpecificationArray[0])
# 2020 06 10 Some times exception ctypes.ArgumentError is apper - set try except with wait
lSpecificationLvL1List = None
lFlagBool = True
while lFlagBool:
try:
lSpecificationLvL1List = pywinauto.findwindows.find_elements(**inControlSpecificationArray[0])
lFlagBool = False # turn off the loop - all is ok
except ctypes.ArgumentError as e:
time.sleep(30) # error has come - go in sleep and retry
for lItem in lSpecificationLvL1List:
#Сделать независимую копию и установить информацию о process_id и handle
lItemControlSpecificationArray=copy.deepcopy(inControlSpecificationArray)

Loading…
Cancel
Save