import psutil import datetime import logging import os lProcessName = "OpenRPA_RobotRDPActive.exe" lStartFilePath = os.path.join(os.getcwd(), "..\\Utils\\RobotRDPActive\\pyOpenRPA.Tools.RobotRDPActive_x64.cmd") def RenderRobotRDPActive(inGlobalConfiguration): #Subheader Variants lSubheaderRunTrueText="State: Turned on" lSubheaderRunFalseText="State: Turned off" #Run button #Такое большое количество слэшей связано с тем, что этот текст отправляется сначала в браузер, рендерится там, а потом отправляется на процессор оркестратора lRobotRDPActivePath = f"start cmd /K {lStartFilePath}" lOnClickRunButton=f"mGlobal.Controller.CMDRunText('{lRobotRDPActivePath}');" #Safe turn off lOnClickSafeTurnOff = "mGlobal.Processor.ServerValueSet(['Storage','RobotRDPActive','OrchestratorToRobotResetStorage','SafeTurnOff'],true);" #Force close button lOnClickForceCloseButton=f"mGlobal.Controller.CMDRunText('taskkill /F /im {lProcessName}');" #Result template lResultDict={ "HeaderLeftText":"Keep active RDP sessions", "HeaderRightText":"Tech", "DataStorageKey":"RobotRDPActive", #Use key for set current dict in mGlobal.DataStorage["DtaaStorageKey"] on client side "SubheaderText":lSubheaderRunFalseText, "BodyKeyValueList":[ {"Key":"Session list","Value":""} ], "FooterText":"Last update: 9:38:00 09.10.2019", "FooterButtonX2List":[ {"Text":"Turn on", "Color":"green", "Link":"", "OnClick": lOnClickRunButton.replace("\\","\\\\")}, {"Text":"Safe turn off", "Color":"orange", "Link":"", "OnClick": lOnClickSafeTurnOff.replace("\\","\\\\")} ], "FooterButtonX1List":[ {"Text":"Kill", "Color":"red", "Link":"", "OnClick": lOnClickForceCloseButton.replace("\\","\\\\")} ]#, #"GlobalStorage": inGlobalConfiguration.get("Storage",{}) } #Read RDPList lRDPList = inGlobalConfiguration.get("Storage",{}).get("RobotRDPActive",{}).get("RobotToOrchestratorStorage",{}).get("RDPList",[]) lFullScreenSessionIndex = inGlobalConfiguration.get("Storage",{}).get("RobotRDPActive",{}).get("RobotToOrchestratorStorage",{}).get("FullScreenSessionIndex",None) lRDPListIndex = 0 for lItem in lRDPList: #Lable that session has fullscreen lLabelSessionFullScreen = "" #Link set full screen lOnClickSetFullScreen = f"mGlobal.Processor.ServerValueSet(['Storage','RobotRDPActive','OrchestratorToRobotStorage','FullScreenSessionIndex'],{lRDPListIndex});" lSetFullScreenA = f'Set fullscreen' if lRDPListIndex == lFullScreenSessionIndex: lLabelSessionFullScreen = 'Fullscreen' #Session state lItemSessionState='Disconnected' if lItem.get("FlagSessionIsActive",False): lItemSessionState='Connected' lResultDict["BodyKeyValueList"].append({"Key":f"[{str(lRDPListIndex)}]{lLabelSessionFullScreen}{lItem.get('Host','localhost')}:{lItem.get('Port','--')}","Value":f"{lItem.get('Login','--')}, {lItem.get('SessionHex','--')}, State {lItemSessionState}, {lSetFullScreenA}"}) lRDPListIndex = lRDPListIndex + 1 #Check if process running if CheckIfProcessRunning("OpenRPA_RobotRDPActive"): lResultDict["SubheaderText"]=lSubheaderRunTrueText #Process not running lResultDict["FooterText"]=f'Last update: {datetime.datetime.now().strftime("%H:%M:%S %d.%m.%Y")}' return lResultDict def CheckIfProcessRunning(processName): ''' Check if there is any running process that contains the given name processName. ''' #Iterate over the all the running process for proc in psutil.process_iter(): try: # Check if process name contains the given name string. if processName.lower() in proc.name().lower(): return True except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess): pass return False; #Orchestrator settings def SettingsUpdate(inDict): #Add RobotRDPActive in control panel inDict["ControlPanelDict"]["RobotList"].append({"RenderFunction": RenderRobotRDPActive}) #Default structure inDict["Storage"]["RobotRDPActive"]={ "OrchestratorToRobotResetStorage":{"SafeTurnOff":False}, "OrchestratorToRobotStorage":{"FullScreenSessionIndex":None} } return inDict