Загрузка данных


; ============================================================
; AutoIt Script for Automated Login to Corporate Mail via WAB
; Uses secure credential retrieval from SKDPU/WAB gateway
; FIXED username: skdpu@customserv.ru
; Password is retrieved from the gateway
; Path to libraries: C:\AutoIt\
; ============================================================

; Include necessary libraries for WAB integration and JSON parsing
#include <Array.au3>
#include "C:\AutoIt\WAB.au3" ; Custom function to get credentials from gateway
#include <MsgBoxConstants.au3> ; For error messages

; --- FIXED Username ---
Local $sUsername = "skdpu@customserv.ru"

; --- Retrieve ONLY PASSWORD from the gateway ---
; The gateway establishes a secure channel and provides the user's credentials
Local $parameters = WABGetApplicationParameters("wablnch") ; Channel name

; Extract ONLY PASSWORD from the received parameters
Local $sPassword = $parameters("password")

; Check if PASSWORD was received successfully
If $sPassword = "" Then
    MsgBox($MB_ICONERROR, "Gateway Error", "Failed to retrieve PASSWORD from the gateway. Cannot proceed.")
    Exit 1 ; Exit with error code
EndIf

; --- Path to Chrome executable ---
Local $sChromePath = "C:\Program Files\Google\Chrome\Application\chrome.exe"

; Fallback to 32-bit path if standard is not found
If Not FileExists($sChromePath) Then
    $sChromePath = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
EndIf

; Check if Chrome is installed
If Not FileExists($sChromePath) Then
    MsgBox($MB_ICONERROR, "Error", "Google Chrome not found. Please install it.")
    Exit 1
EndIf

; --- Launch Chrome and navigate to the mail login page ---
; FIXED: Correct corporate mail URL used here
Run($sChromePath & ' https://post.customserv.ru')

; Wait for the Chrome window to become active (max 10 seconds)
WinWaitActive("[CLASS:Chrome_WidgetWin_1]", "", 10)

; Check if Chrome window appeared
If Not WinExists("[CLASS:Chrome_WidgetWin_1]") Then
    MsgBox($MB_ICONERROR, "Error", "Chrome window failed to open. Exiting.")
    Exit 1
EndIf

; --- Allow time for the page (especially AngularJS) to fully load ---
; Increased sleep to ensure dynamic content is ready
Sleep(10000) ; Wait for 10 seconds

; --- Ensure the browser window has focus ---
; Click in the center of the active Chrome window to activate the webpage area
Local $aPos = WinGetPos("[CLASS:Chrome_WidgetWin_1]")
If Not @error Then
    Local $iCenterX = $aPos + ($aPos / 2)
    Local $iCenterY = $aPos + ($aPos / 2)
    MouseClick("left", $iCenterX, $iCenterY, 1, 0)
    Sleep(500)
EndIf

; --- Automated login sequence ---
; Focus on the username field
Send("{TAB}") ; Navigate to the first input field
Sleep(500) ; Short pause for UI stability

; RELIABLE FIELD CLEARING (Alternative to Ctrl+A, preventing the "a" character bug)
Send("{END}") ; Move cursor to the very end of the field
Sleep(100)
Send("+{HOME}") ; Select all text from end to beginning (Shift + Home)
Sleep(100)
Send("{DEL}") ; Delete selected text
Sleep(500)

; ENTER USERNAME VIA CLIPBOARD (Guarantees full text insertion regardless of layout)
ClipPut($sUsername)
Sleep(200)
Send("{CTRLDOWN}v{CTRLUP}") ; Explicit Ctrl+V execution
Sleep(500)

; Move to the password field
Send("{TAB}")
Sleep(500)

; ENTER PASSWORD VIA CLIPBOARD (Bypasses special character issues from SKDPU gateway)
ClipPut($sPassword)
Sleep(200)
Send("{CTRLDOWN}v{CTRLUP}") ; Explicit Ctrl+V execution
Sleep(500)

; SECURITY: Clear the clipboard so the password does not remain in memory
ClipPut("")

; Submit the login form
Send("{ENTER}")

; Script ends. Chrome remains open with the user logged in.