mabe

Scripting a Java based website to auto login using AutoIT V3

10 posts in this topic

Good day All,

 

I need your help, i am a CyberArk Engineer. I have barely ever done scripting in my life but now i am faced with a very tough challenge of scripting a Java based Website to Auto-login through CyberArk. Please help, I am figured out a few things but its not going to work well for me in the long run because it would required for me to be constantly editing the script for each user. So i need a universal connector. 

Share this post


Link to post
Share on other sites



Welcome to the forum.

Please show us what you have coded so far.

1 person likes this

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites

#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                                       = "MyDispatcherName" ; CHANGE_ME
Global Const $CLIENT_EXECUTABLE                                    = "http://weblink" ; 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")
    MsgBox(1, "dispatcher initialized", "yay we have at least gotten three steps ahead")
    ; 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 & "...")
    $ConnectionClientPID = Run($CLIENT_EXECUTABLE)
    if ($ConnectionClientPID == 0) Then
        Error(StringFormat("Failed to execute process [%s]", $CLIENT_EXECUTABLE, @error))
    EndIf

    ; Send PID to PSM as early as possible so recording/monitoring can begin
    LogWrite("sending PID to PSM")
    if (PSMGenericClient_SendPID($ConnectionClientPID) <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
    EndIf

    ; ------------------
    ; Handle login here! ; CHANGE_ME
    ; ------------------

    ; Terminate PSM Dispatcher utils wrapper
    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 = 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("http://weblink", $TargetAddress) <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
    EndIf
EndFunc
 

Share this post


Link to post
Share on other sites
16 hours ago, Exit said:

Welcome to the forum.

Please show us what you have coded so far.

Thank you. i have shared @Exit Thank you, please see above :)

Share this post


Link to post
Share on other sites

When posting code on the forum please use the "<>" buttons in the editor to format them properly.

1 person likes this

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

please see attached error msg 

script error.GIF

Edited by mabe
to get attention of exit

Share this post


Link to post
Share on other sites

@Exit @mvp

 


;============================================================
;             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                                       = "MyDispatcherName" ; CHANGE_ME
Global Const $CLIENT_EXECUTABLE                                    = "c\Program Files (x86)\Internet Explorer\iexplore.exe" ; 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
 

Share this post


Link to post
Share on other sites

#9 ·  Posted

Even i am getting this error. Please help me as well whats the solution for it.

Share this post


Link to post
Share on other sites

#10 ·  Posted

@vcd This thread is over a year old. Suggest that you start a new one and be sure to provide as much information as possible.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now