# RobotRDPActiveTemplateFixes

Signed-off-by: Ivan Maslov <i.maslov@mail.ru>
dev-linux
Ivan Maslov 4 years ago
parent f93028125c
commit d809a9d5c7

@ -1,18 +1,21 @@
import psutil, datetime, logging, os, json import psutil, datetime, logging, os, json
# # # # # # # ORCHESTRATOR CONTROL PANEL <Robot name> # # # # # # # # # # # # # # ORCHESTRATOR CONTROL PANEL <Robot name> # # # # # # #
# Init parameters # Init parameters
gProcessNameWOEXE = "OpenRPA_RobotRDPActive" gProcessNameWOEXE = "OpenRPA_RobotRDPActive_<RobotKeyName>"
gRDPStartFilePath = os.path.abspath(os.path.join(os.getcwd(), "..\\Utils\\RobotRDPActive\\pyOpenRPA.Tools.RobotRDPActive_x64.cmd")) # cwd is orchestrator working directory gRDPOrchestratorStorageKey = "<RobotKeyName>"
gOrchestratorToRobotKeyList = ["Storage","RobotRDPActive","OrchestratorToRobotStorage"] gRDPStartFilePath = os.path.abspath(os.path.join(os.getcwd(), gRDPOrchestratorStorageKey+r"\pyOpenRPA.Tools.RobotRDPActive_x64.cmd")) # cwd is orchestrator working directory
gRobotToOrchestratorKeyList = ["Storage","RobotRDPActive","RobotToOrchestratorStorage"] gOrchestratorToRobotKeyList = ["Storage",gRDPOrchestratorStorageKey,"OrchestratorToRobotStorage"]
gOrchestratorToRobotResetKeyList = ["Storage",gRDPOrchestratorStorageKey,"OrchestratorToRobotResetStorage"]
gRobotToOrchestratorKeyList = ["Storage",gRDPOrchestratorStorageKey,"RobotToOrchestratorStorage"]
gRobotRDPActiveDefsFolderPath = "" gRobotRDPActiveDefsFolderPath = ""
gRobotProcessNameWOEXE = "<RobotProcessName>"
gRobotProcessFilePath = r"path\to\start\link"
# Function, which is generate Dict for front-endswith # Function, which is generate Dict for front-endswith
def ControlPanelRenderDict(inGSettings): def ControlPanelRenderDict(inGSettings):
"""result={ """result={
"HeaderLeftText":"<Robot name>", "HeaderLeftText":"<Robot name>",
"HeaderRightText":"<header>", "HeaderRightText":"<header>",
"DataStorageKey":"RobotRDPActive", #Use key for set current dict in mGlobal.DataStorage["DataStorageKey"] on client side "DataStorageKey":"Robot_Name", #Use key for set current dict in mGlobal.DataStorage["DataStorageKey"] on client side
"SubheaderText": "State: <span style=\"color:green\">Turned on</span>", "SubheaderText": "State: <span style=\"color:green\">Turned on</span>",
"BodyKeyValueList":[ "BodyKeyValueList":[
{"Key":"Session list","Value":""}, {"Key":"Session list","Value":""},
@ -28,29 +31,47 @@ def ControlPanelRenderDict(inGSettings):
}""" }"""
# START :: Create activities :: START # # START :: Create activities :: START #
## RDP Start ## RDP Start
lActivityRDPStartEscaped = (f"mGlobal.Controller.CMDRunText('start cmd /K {gRDPStartFilePath}');").replace("\\","\\\\") # Need escape because this is render on client side and after that it goes to server side :( lActivityRDPStartEscaped = (f"mGlobal.Controller.CMDRunText('start cmd /K {gRDPStartFilePath}');").replace("\\","\\\\").replace("\"","\'") # Need escape because this is render on client side and after that it goes to server side :(
## RDP Safe turn off ## RDP Safe turn off
lActivityRDPSafeOffEscaped = (f"mGlobal.Processor.ServerValueSet({json.dumps(gOrchestratorToRobotKeyList+['SafeTurnOff'])},true);").replace("\\","\\\\") lActivityRDPSafeOffEscaped = (f"mGlobal.Processor.ServerValueSet({json.dumps(gOrchestratorToRobotKeyList+['SafeTurnOff'])},true);").replace("\\","\\\\").replace("\"","\'")
## RDP Kill ## RDP Kill
lActivityRDPKillEscaped = (f"mGlobal.Controller.CMDRunText('taskkill /F /im {gProcessNameWOEXE}.exe');").replace("\\","\\\\") lActivityRDPKillEscaped = (f"mGlobal.Controller.CMDRunText('taskkill /F /im {gProcessNameWOEXE}.exe');").replace("\\","\\\\").replace("\"","\'")
## Recieve file from RDP session to Orchestrator session ## Robot start
lActivityFileRDP2OrchestratorDict = [ lActivityROBOTStartList = [
{ {
"ModulePath": f"{os.path.join(gRobotRDPActiveDefsFolderPath,'Defs_SessionIndex.py')}", # "Session\\SessionDefs.py" "ModulePath": f"{os.path.abspath(os.path.join(gRobotRDPActiveDefsFolderPath,'Defs_SessionIndex.py'))}", # "RobotRDPActive\\SessionDefs.py"
"DefName":"FileStoredRecieve", # Function name "DefName":"ProcessStartIfNotRunning", # Function name
"ArgList":[], # Args list "ArgList":[], # Args list
"ArgDict":{"inSessionIndex": 0, "inHostFilePath": "testRecieve.txt","inRDPFilePath": "C:\\Temp\\testRecieve.txt"} # Args dictionary "ArgDict":{"inSessionIndex": 0, "inProcessName": f"{gRobotProcessNameWOEXE}.exe", "inFilePath": gRobotProcessFilePath} # Args dictionary
} }
] ]
lActivityFileRDP2Orchestrator = f"mGlobal.Processor.ServerValueSet(['Storage','RobotRDPActive','OrchestratorToRobotResetStorage','ActivityList'],{json.dumps(lActivityFileRDP2OrchestratorDict)});" lActivityROBOTStartEscaped = f"mGlobal.Processor.ServerValueSet({json.dumps(gOrchestratorToRobotResetKeyList+['ActivityList'])},{json.dumps(lActivityROBOTStartList)});".replace("\"","\'")
## ROBOT r3 stop
lActivityROBOTStopList = [
{
"ModulePath": f"{os.path.abspath(os.path.join(gRobotRDPActiveDefsFolderPath,'Defs_SessionIndex.py'))}", # "Session\\SessionDefs.py"
"DefName":"ProcessStop", # Function name
"ArgList":[], # Args list
"ArgDict":{"inSessionIndex": 0, "inProcessName": f"{gRobotProcessNameWOEXE}.exe", "inFlagForceClose":True} # Args dictionary
}
]
lActivityROBOTStopEscaped = f"mGlobal.Processor.ServerValueSet({json.dumps(gOrchestratorToRobotResetKeyList+['ActivityList'])},{json.dumps(lActivityROBOTStopList)});".replace("\"","\'")
## ROBOT r3 restart
lActivityROBOTRestartList = lActivityROBOTStartList + lActivityROBOTStopList
lActivityROBOTRestartEscaped = f"mGlobal.Processor.ServerValueSet({json.dumps(gOrchestratorToRobotResetKeyList+['ActivityList'])},{json.dumps(lActivityROBOTRestartList)});".replace("\"","\'")
# END :: Create activities :: END # # END :: Create activities :: END #
# START :: Init result dict template :: START # # START :: Init result dict template :: START #
lBodyKeyValue_r3_start=f'<a onclick="{lActivityROBOTStartEscaped}" style=\"color:green\">Start</a>'
lBodyKeyValue_r3_stop=f'<a onclick="{lActivityROBOTStopEscaped}" style=\"color:red\">Stop</a>'
lBodyKeyValue_r3_restart=f'<a onclick="{lActivityROBOTRestartEscaped}" style=\"color:orange\">restart</a>'
lResultDict={ lResultDict={
"HeaderLeftText":"Keep active RDP sessions", "HeaderLeftText":"ROBOT r4",
"HeaderRightText":"Tech", "HeaderRightText":"r4",
"DataStorageKey":"RobotRDPActive", #Use key for set current dict in mGlobal.DataStorage["DataStorageKey"] on client side "DataStorageKey":gRDPOrchestratorStorageKey, #Use key for set current dict in mGlobal.DataStorage["DataStorageKey"] on client side
"SubheaderText":"<Subheader text>", "SubheaderText":"<Subheader text>",
"BodyKeyValueList":[ "BodyKeyValueList":[
{"Key":"ROBOT robots (r1-r5) list","Value":""},
{"Key":"r4","Value":f"{lBodyKeyValue_r3_start}, {lBodyKeyValue_r3_stop}, {lBodyKeyValue_r3_restart}"},
{"Key":"Session list","Value":""} {"Key":"Session list","Value":""}
], ],
"FooterText":"Last update: 9:38:00 09.10.2019", "FooterText":"Last update: 9:38:00 09.10.2019",
@ -60,32 +81,32 @@ def ControlPanelRenderDict(inGSettings):
], ],
"FooterButtonX1List":[ "FooterButtonX1List":[
{"Text":"Kill", "Color":"red", "Link":"", "OnClick": lActivityRDPKillEscaped} {"Text":"Kill", "Color":"red", "Link":"", "OnClick": lActivityRDPKillEscaped}
]#, ],
#"GlobalStorage": inGSettings.get("Storage",{}) # UNCOMMENT FOR DEBUG PURPOSE TO WATCH inGSettings on client side "GlobalStorage": inGSettings.get("Storage",{}) # UNCOMMENT FOR DEBUG PURPOSE TO WATCH inGSettings on client side
} }
# END :: Init result dict template :: END # # END :: Init result dict template :: END #
# START :: Fill BodyKeyValueList :: START # # START :: Fill BodyKeyValueList :: START #
## Read RDPList ## Read RDPList
lRDPList = TechDictKeyList_ItemGet(inDict=inGSettings, inKeyList=gRobotToOrchestratorKeyList+["RDPList"], inDefault=[]): lRDPList = TechDictKeyList_ItemGet(inDict=inGSettings, inKeyList=gRobotToOrchestratorKeyList+["RDPList"], inDefault=[])
lFullScreenSessionIndex = TechDictKeyList_ItemGet(inDict=inGSettings, inKeyList=gRobotToOrchestratorKeyList+["FullScreenSessionIndex"], inDefault=None): lFullScreenSessionIndex = TechDictKeyList_ItemGet(inDict=inGSettings, inKeyList=gRobotToOrchestratorKeyList+["FullScreenSessionIndex"], inDefault=None)
lRDPListIndex = 0 lRDPListIndex = 0
for lItem in lRDPList: for lItem in lRDPList:
### Lable that session has fullscreen ### Lable that session has fullscreen
lLabelSessionFullScreen = "" lLabelSessionFullScreen = ""
lLabelIsIgnored = "" lLabelIsIgnored = ""
### Link set full screen ### Link set full screen
lOnClickSetFullScreen = f"mGlobal.Processor.ServerValueSet(['Storage','RobotRDPActive','OrchestratorToRobotStorage','FullScreenSessionIndex'],{lRDPListIndex});" lOnClickSetFullScreen = f"mGlobal.Processor.ServerValueSet(['Storage','{gRDPOrchestratorStorageKey}','OrchestratorToRobotStorage','FullScreenSessionIndex'],{lRDPListIndex});"
lSetFullScreenA = f'<a onclick="{lOnClickSetFullScreen}" style=\"color:blue\">Set fullscreen</a>' lSetFullScreenA = f'<a onclick="{lOnClickSetFullScreen}" style=\"color:blue\">Set fullscreen</a>'
if lRDPListIndex == lFullScreenSessionIndex: if lRDPListIndex == lFullScreenSessionIndex:
lLabelSessionFullScreen = '<span style=\"color:blue\">[Fullscreen]</span>' lLabelSessionFullScreen = '<span style=\"color:blue\">[Fullscreen]</span>'
lOnClickSetFullScreen = f"mGlobal.Processor.ServerValueSet(['Storage','RobotRDPActive','OrchestratorToRobotStorage','FullScreenSessionIndex'],null);" lOnClickSetFullScreen = f"mGlobal.Processor.ServerValueSet(['Storage','{gRDPOrchestratorStorageKey}','OrchestratorToRobotStorage','FullScreenSessionIndex'],null);"
lSetFullScreenA = f'<a onclick="{lOnClickSetFullScreen}" style=\"color:blue\">Set minimized</a>' lSetFullScreenA = f'<a onclick="{lOnClickSetFullScreen}" style=\"color:blue\">Set minimized</a>'
lIgnoreIndexListOnClick = "$.ajax({type: 'POST', url: 'RobotRDPActive/IgnoreIndexListAppend', data: '"+str(lRDPListIndex)+"', success: function(lData,l2,l3){}, dataType: 'text'});" lIgnoreIndexListOnClick = "$.ajax({type: 'POST', url: '{gRDPOrchestratorStorageKey}/IgnoreIndexListAppend', data: '"+str(lRDPListIndex)+"', success: function(lData,l2,l3){}, dataType: 'text'});"
lIgnoreIndexListLink = f'<a onclick="{lIgnoreIndexListOnClick}" style=\"color:red\">Ignore</a>' lIgnoreIndexListLink = f'<a onclick="{lIgnoreIndexListOnClick}" style=\"color:red\">Ignore</a>'
### Check if in ignore ### Check if in ignore
if lRDPListIndex in inGSettings.get("Storage",{}).get("RobotRDPActive",{}).get("OrchestratorToRobotStorage",{}).get("IgnoreIndexList",[]): if lRDPListIndex in inGSettings.get("Storage",{}).get(gRDPOrchestratorStorageKey,{}).get("OrchestratorToRobotStorage",{}).get("IgnoreIndexList",[]):
lLabelIsIgnored = '<span style=\"color:red\">[Ignored]</span>' lLabelIsIgnored = '<span style=\"color:red\">[Ignored]</span>'
lIgnoreIndexListOnClick = "$.ajax({type: 'POST', url: 'RobotRDPActive/IgnoreIndexListRemove', data: '"+str(lRDPListIndex)+"', success: function(lData,l2,l3){}, dataType: 'text'});" lIgnoreIndexListOnClick = "$.ajax({type: 'POST', url: '"+gRDPOrchestratorStorageKey+"/IgnoreIndexListRemove', data: '"+str(lRDPListIndex)+"', success: function(lData,l2,l3){}, dataType: 'text'});"
lIgnoreIndexListLink = f'<a onclick="{lIgnoreIndexListOnClick}" style=\"color:red\">Unignore</a>' lIgnoreIndexListLink = f'<a onclick="{lIgnoreIndexListOnClick}" style=\"color:red\">Unignore</a>'
### Session state ### Session state
lItemSessionState='<span style=\"color:red\">Disconnected</span>' lItemSessionState='<span style=\"color:red\">Disconnected</span>'
@ -120,7 +141,7 @@ def CheckIfProcessRunning(processName):
return False return False
#Add to ignore list - AJAX request from client side #Add to ignore list - AJAX request from client side
def IgnoreIndexListAppend(inRequest,inConfiguration): def IgnoreIndexListAppend(inRequest,inConfiguration):
lIgnoreList = TechDictKeyList_ItemGet(inDict=inConfiguration, inKeyList=gOrchestratorToRobotKeyList+["IgnoreIndexList"], inDefault=[]): lIgnoreList = TechDictKeyList_ItemGet(inDict=inConfiguration, inKeyList=gOrchestratorToRobotKeyList+["IgnoreIndexList"], inDefault=[])
lIgnoreIndex={} lIgnoreIndex={}
if inRequest.headers.get('Content-Length') is not None: if inRequest.headers.get('Content-Length') is not None:
lInputByteArrayLength = int(inRequest.headers.get('Content-Length')) lInputByteArrayLength = int(inRequest.headers.get('Content-Length'))
@ -133,7 +154,7 @@ def IgnoreIndexListAppend(inRequest,inConfiguration):
lIgnoreList.append(lIgnoreIndex) lIgnoreList.append(lIgnoreIndex)
#remove from Ignore list - AJAX request from client side #remove from Ignore list - AJAX request from client side
def IgnoreIndexListRemove(inRequest,inConfiguration): def IgnoreIndexListRemove(inRequest,inConfiguration):
lIgnoreList = TechDictKeyList_ItemGet(inDict=inConfiguration, inKeyList=gOrchestratorToRobotKeyList+["IgnoreIndexList"], inDefault=[]): lIgnoreList = TechDictKeyList_ItemGet(inDict=inConfiguration, inKeyList=gOrchestratorToRobotKeyList+["IgnoreIndexList"], inDefault=[])
lIgnoreIndex={} lIgnoreIndex={}
if inRequest.headers.get('Content-Length') is not None: if inRequest.headers.get('Content-Length') is not None:
lInputByteArrayLength = int(inRequest.headers.get('Content-Length')) lInputByteArrayLength = int(inRequest.headers.get('Content-Length'))
@ -150,7 +171,7 @@ def TechDictKeyList_ItemGet(inDict, inKeyList, inDefault={}):
for lItem in inKeyList: for lItem in inKeyList:
if lResult: if lResult:
lResult = lResult.get(lItem,None) lResult = lResult.get(lItem,None)
if not lResult: if lResult is None:
lResult=inDefault lResult=inDefault
return lResult return lResult
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
@ -159,18 +180,18 @@ def SettingsUpdate(inGSettings):
#Add RobotRDPActive in control panel #Add RobotRDPActive in control panel
inGSettings["ControlPanelDict"]["RobotList"].append({"RenderFunction": ControlPanelRenderDict}) inGSettings["ControlPanelDict"]["RobotList"].append({"RenderFunction": ControlPanelRenderDict})
#Default structure #Default structure
inGSettings["Storage"]["RobotRDPActive"]={ inGSettings["Storage"][gRDPOrchestratorStorageKey]={
"OrchestratorToRobotResetStorage":{"SafeTurnOff":False}, "OrchestratorToRobotResetStorage":{"SafeTurnOff":False, "ActivityList":[]},
"OrchestratorToRobotStorage":{ "OrchestratorToRobotStorage":{
"FullScreenSessionIndex":None, "FullScreenSessionIndex":None,
"IgnoreIndexList": [] "IgnoreIndexList": []
} }
} }
#Add methods #Add methods
inGSettings["Server"]["URLList"].append( inGSettings["Server"]["URLList"].append(
{ {
"Method":"POST", "Method":"POST",
"URL": "/RobotRDPActive/IgnoreIndexListAppend", #URL of the request "URL": f"/{gRDPOrchestratorStorageKey}/IgnoreIndexListAppend", #URL of the request
"MatchType": "Equal", #"BeginWith|Contains|Equal|EqualCase", "MatchType": "Equal", #"BeginWith|Contains|Equal|EqualCase",
"ResponseDefRequestGlobal": IgnoreIndexListAppend #Function with str result "ResponseDefRequestGlobal": IgnoreIndexListAppend #Function with str result
} }
@ -178,7 +199,7 @@ def SettingsUpdate(inGSettings):
inGSettings["Server"]["URLList"].append( inGSettings["Server"]["URLList"].append(
{ {
"Method":"POST", "Method":"POST",
"URL": "/RobotRDPActive/IgnoreIndexListRemove", #URL of the request "URL": f"/{gRDPOrchestratorStorageKey}/IgnoreIndexListRemove", #URL of the request
"MatchType": "Equal", #"BeginWith|Contains|Equal|EqualCase", "MatchType": "Equal", #"BeginWith|Contains|Equal|EqualCase",
"ResponseDefRequestGlobal": IgnoreIndexListRemove #Function with str result "ResponseDefRequestGlobal": IgnoreIndexListRemove #Function with str result
} }

@ -10,7 +10,7 @@ lOrchestratorHost="localhost"
lOrchestratorPort=8081 lOrchestratorPort=8081
lOrchestratorProtocol="http" lOrchestratorProtocol="http"
lOrchestratorAuthToken="1992-04-03-0643-ru-b4ff-openrpa52zzz" lOrchestratorAuthToken="1992-04-03-0643-ru-b4ff-openrpa52zzz"
gRobotName="RobotRDPActive"
lRobotRDPActiveFolderPath = '\\'.join(RobotRDPActive.__file__.split('\\')[:-1]) lRobotRDPActiveFolderPath = '\\'.join(RobotRDPActive.__file__.split('\\')[:-1])
#print(f"{os.path.join(lRobotRDPActiveFolderPath,'SessionDefs.py')}") #print(f"{os.path.join(lRobotRDPActiveFolderPath,'SessionDefs.py')}")
def Settings(): def Settings():
@ -38,7 +38,7 @@ def Settings():
], ],
"ResponsibilityCheckIntervalSec": None, # Seconds interval when Robot check the RDP responsibility. if None - dont check "ResponsibilityCheckIntervalSec": None, # Seconds interval when Robot check the RDP responsibility. if None - dont check
"FullScreenSessionIndex": None, #Index of the current session which is full screened, None is no session in fullscreen "FullScreenSessionIndex": None, #Index of the current session which is full screened, None is no session in fullscreen
"Logger": logging.getLogger("RobotRDPActive"), "Logger": logging.getLogger(gRobotName),
"Logs": { "Logs": {
"FlagShowInConsole":True "FlagShowInConsole":True
}, },
@ -102,7 +102,7 @@ def Settings():
"Interval": 1.1, "Interval": 1.1,
"RobotStorage": mDict, "RobotStorage": mDict,
"RobotStorageKey": "RDPList", "RobotStorageKey": "RDPList",
"OrchestratorKeyList": ["Storage", "RobotRDPActive","RobotToOrchestratorStorage","RDPList"], "OrchestratorKeyList": ["Storage", gRobotName,"RobotToOrchestratorStorage","RDPList"],
"OrchestratorProtocol": lOrchestratorProtocol, "OrchestratorProtocol": lOrchestratorProtocol,
"OrchestratorHost": lOrchestratorHost, "OrchestratorHost": lOrchestratorHost,
"OrchestratorPort": lOrchestratorPort, "OrchestratorPort": lOrchestratorPort,
@ -112,7 +112,7 @@ def Settings():
"Interval": 1, "Interval": 1,
"RobotStorage": mDict, "RobotStorage": mDict,
"RobotStorageKey": "RDPList", "RobotStorageKey": "RDPList",
"OrchestratorKeyList": ["Storage", "RobotRDPActive","RobotToOrchestratorStorage","FullScreenSessionIndex"], "OrchestratorKeyList": ["Storage", gRobotName,"RobotToOrchestratorStorage","FullScreenSessionIndex"],
"OrchestratorProtocol": lOrchestratorProtocol, "OrchestratorProtocol": lOrchestratorProtocol,
"OrchestratorHost": lOrchestratorHost, "OrchestratorHost": lOrchestratorHost,
"OrchestratorPort": lOrchestratorPort, "OrchestratorPort": lOrchestratorPort,
@ -125,7 +125,7 @@ def Settings():
"RobotStorage": mDict, "RobotStorage": mDict,
"RobotStorageKey": "OrchestratorToRobotResetStorage", "RobotStorageKey": "OrchestratorToRobotResetStorage",
"RobotResetValue": mDict["OrchestratorToRobotResetStorage"], "RobotResetValue": mDict["OrchestratorToRobotResetStorage"],
"OrchestratorKeyList": ["Storage", "RobotRDPActive","OrchestratorToRobotResetStorage"], "OrchestratorKeyList": ["Storage", gRobotName,"OrchestratorToRobotResetStorage"],
"OrchestratorProtocol": lOrchestratorProtocol, "OrchestratorProtocol": lOrchestratorProtocol,
"OrchestratorHost": lOrchestratorHost, "OrchestratorHost": lOrchestratorHost,
"OrchestratorPort": lOrchestratorPort, "OrchestratorPort": lOrchestratorPort,
@ -137,7 +137,7 @@ def Settings():
"Interval": 1.25, "Interval": 1.25,
"RobotStorage": mDict, "RobotStorage": mDict,
"RobotStorageKey": "OrchestratorToRobotStorage", "RobotStorageKey": "OrchestratorToRobotStorage",
"OrchestratorKeyList": ["Storage", "RobotRDPActive","OrchestratorToRobotStorage"], "OrchestratorKeyList": ["Storage", gRobotName,"OrchestratorToRobotStorage"],
"OrchestratorProtocol": lOrchestratorProtocol, "OrchestratorProtocol": lOrchestratorProtocol,
"OrchestratorHost": lOrchestratorHost, "OrchestratorHost": lOrchestratorHost,
"OrchestratorPort": lOrchestratorPort, "OrchestratorPort": lOrchestratorPort,

Loading…
Cancel
Save