#include #include ;#RequireAdmin #AutoIt3Wrapper_UseX64=n Opt("MustDeclareVars", 1) AutoItSetOption("WinTitleMatchMode", 3) ; EXACT_MATCH! ;============================================================ ; PSM AutoIt Dispatcher Skeleton ; ------------------------------ ; ; Use this skeleton to create your own ; connection components integrated with the PSM. ; Areas you may want to modify are marked ; with the string "CHANGE_ME". ; ; Created : April 2013 ; Cyber-Ark Software Ltd. ;============================================================ #include "PSMGenericClientWrapper.au3" ;======================================= ; Consts & Globals ;======================================= Global Const $DISPATCHER_NAME = "Iexplorer_Fortigate" ; CHANGE_ME ;Global Const $LOGIN_WEBPAGE = "https://" & $TargetAddress ; CHANGE_ME ;Global Const $CLIENT_EXECUTABLE = "c:\Program Files (x86)\Internet Explorer\iexplore.exe " & $LOGIN_WEBPAGE ; CHANGE_ME Global Const $ERROR_MESSAGE_TITLE = "PSM " & $DISPATCHER_NAME & " Dispatcher error message" Global Const $LOG_MESSAGE_PREFIX = $DISPATCHER_NAME & " Dispatcher - " Global $TargetUsername Global $TargetPassword Global $TargetAddress Global $ConnectionClientPID = 0 ;======================================= ; Code ;======================================= Exit Main() ;======================================= ; Main ;======================================= Func Main() ; Init PSM Dispatcher utils wrapper ToolTip ("Initializing...") if (PSMGenericClient_Init() <> $PSM_ERROR_SUCCESS) Then Error(PSMGenericClient_PSMGetLastErrorString()) EndIf LogWrite("successfully initialized Dispatcher Utils Wrapper") ; Get the dispatcher parameters FetchSessionProperties() LogWrite("mapping local drives") if (PSMGenericClient_MapTSDrives() <> $PSM_ERROR_SUCCESS) Then Error(PSMGenericClient_PSMGetLastErrorString()) EndIf LogWrite("starting client application") ToolTip ("Starting " & $DISPATCHER_NAME & "...") _BlockInputEx(1) run("RunDll32.exe InetCpl.cpl,ResetIEtoDefaults") Sleep(1000) ControlClick("Reset Internet Explorer Settings","","Button2") Sleep(1000) ControlClick("Reset Internet Explorer Settings","","Button1") Local $oIE = _IECreate("https://"&$TargetAddress&":1453") ;Sleep(2000) ;$ConnectionClientPID = Run('"c:\Program Files (x86)\Internet Explorer\iexplore.exe" https://' &$TargetAddress) ;WinWaitActive("Certificate Error: Navigation Blocked") ;_IELoadWait($oIE) ;Sleep(3000) ;_IELinkClickByText($oIE, "Continue to this website (not recommended).") Sleep(5000) ;$ConnectionClientPID=WinGetProcess(_IEPropertyGet($oIE,"title")) $ConnectionClientPID = WinGetProcess(_IEPropertyGet($oIE, "hwnd")) if ($ConnectionClientPID == 0) Then Error(StringFormat("Failed to execute process [%s]",'"c:\Program Files (x86)\Internet Explorer\iexplore.exe" https://' &$TargetAddress, @error)) EndIf ; Send PID to PSM as early as possible so recording/monitoring can begin LogWrite("sending PID to PSM") ;Sleep(3000) if (PSMGenericClient_SendPID($ConnectionClientPID) <> $PSM_ERROR_SUCCESS) Then Error(PSMGenericClient_PSMGetLastErrorString()) EndIf Sleep(2000) WinWait("Certificate Error: Navigation Blocked - Internet Explorer") WinActivate("Certificate Error: Navigation Blocked - Internet Explorer") ControlClick("Certificate Error: Navigation Blocked - Internet Explorer","","","Left",1,125,282) Sleep(1000) ;send("{ENTER}") Sleep(2000) local $oUser = _IEGetObjById($oIE,"username") local $oPass = _IEGetObjById($oIE,"secretkey") ;local $oPersistBox = _IEGetObjById($oIE,"persist_box") local $oSubmit = _IEGetObjById($oIE,"login_button") _IEFormElementSetValue($oUser, $TargetUsername) _IEFormElementSetValue($oPass, $TargetPassword) ;_IEAction($oSubmit,"click") Sleep(1000) send("{ENTER}") _BlockInputEx(0) LogWrite("Terminating Dispatcher Utils Wrapper") PSMGenericClient_Term() Return $PSM_ERROR_SUCCESS EndFunc ;================================== ; Functions ;================================== ; #FUNCTION# ==================================================================================================================== ; Name...........: Error ; Description ...: An exception handler - displays an error message and terminates the dispatcher ; Parameters ....: $ErrorMessage - Error message to display ; $Code - [Optional] Exit error code ; =============================================================================================================================== Func Error($ErrorMessage, $Code = -1) ; If the dispatcher utils DLL was already initialized, write an error log message and terminate the wrapper if (PSMGenericClient_IsInitialized()) Then LogWrite($ErrorMessage, True) PSMGenericClient_Term() EndIf Local $MessageFlags = BitOr(0, 16, 262144) ; 0=OK button, 16=Stop-sign icon, 262144=MsgBox has top-most attribute set MsgBox($MessageFlags, $ERROR_MESSAGE_TITLE, $ErrorMessage) ; If the connection component was already invoked, terminate it if ($ConnectionClientPID <> 0) Then ProcessClose($ConnectionClientPID) $ConnectionClientPID = WinGetProcess(_IEPropertyGet($oIE, "hwnd")) ProcessClose($ConnectionClientPID) $ConnectionClientPID = 0 EndIf Exit $Code EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: LogWrite ; Description ...: Write a PSMWinSCPDispatcher log message to standard PSM log file ; Parameters ....: $sMessage - [IN] The message to write ; $LogLevel - [Optional] [IN] Defined if the message should be handled as an error message or as a trace messge ; Return values .: $PSM_ERROR_SUCCESS - Success, otherwise error - Use PSMGenericClient_PSMGetLastErrorString for details. ; =============================================================================================================================== Func LogWrite($sMessage, $LogLevel = $LOG_LEVEL_TRACE) Return PSMGenericClient_LogWrite($LOG_MESSAGE_PREFIX & $sMessage, $LogLevel) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: PSMGenericClient_GetSessionProperty ; Description ...: Fetches properties required for the session ; Parameters ....: None ; Return values .: None ; =============================================================================================================================== Func FetchSessionProperties() ; CHANGE_ME if (PSMGenericClient_GetSessionProperty("Username", $TargetUsername) <> $PSM_ERROR_SUCCESS) Then Error(PSMGenericClient_PSMGetLastErrorString()) EndIf if (PSMGenericClient_GetSessionProperty("Password", $TargetPassword) <> $PSM_ERROR_SUCCESS) Then Error(PSMGenericClient_PSMGetLastErrorString()) EndIf if (PSMGenericClient_GetSessionProperty("Address", $TargetAddress) <> $PSM_ERROR_SUCCESS) Then Error(PSMGenericClient_PSMGetLastErrorString()) EndIf EndFunc