PS. I've almost decided to go back to Windows just so I can use this script lol. I don't wanna do that, so pls help
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#Include <Rufaydium>
/*
************ Initial variable set-up ************
*/
GappUser = @example.com
GappPassword =
sudoUser = baba
sudoPassword =
sudoPutty =
sudoKeyFile =
FireFoxPath = C:\Program Files\Mozilla Firefox\firefox.exe
/*
******************* Hotstrings *******************
*/
<^>!p:: ; Password (sudo)
SendRaw %sudoPassword%
return
<^>![:: ; Password (putty)
SendRaw %sudoPutty%
return
/*
*** User data ***
*/
<^>!o:: ; User SSH password "o" as next to "P"assword
SendRaw %proxySSH%
return
<^>!u:: ; Username
SendRaw %uname%
return
<^>!y:: ; Servername "y" as next to "u"sername
SendRaw %sname%
return
/*
****************** Ctrl Hotkeys ******************
*/
^0:: ; Load customer data
; Exit Firefox not active
;if NOT isFireFoxActive()
; return
; Exit if user and servername not selected
uname := UserName()
sname := ServerName()
If !uname or !sname
return
; Connect to Chrome
Browser := new Rufaydium()
Page := Browser.NewSession()
; WinID := WinExist("A")
; Gapp Login
Page.querySelector("#id_username").value := GappUser
Page.querySelector("#id_password").value := GappPassword
Page.querySelector(".btn-info").click()
; Gapp User Proxy
; sleep 500
proxyEmail := Page.querySelector(".field-user").children
proxyEmail := html_decode(proxyEmail[0].innerHTML)
proxyUsername := html_decode(Page.querySelector(".field-username").innerHTML)
proxyUser := html_decode(Page.querySelector(".field-user__id").innerHTML)
proxySSH := html_decode(Page.querySelector(".field-shell_password").innerHTML)
Page.querySelector(".form-control[name=Nickname]").value := "" ; shouldn't be needed, but is!
Page.querySelector(".form-control[name=Nickname]").value := proxyUser
Page.querySelector(".btn").click()
Send, ^r
Sleep 500
/*
Page.querySelector(".form-control[name=email]").value := "" ; shouldn't be needed, but is!
Page.querySelector(".form-control[name=email]").value := proxyEmail
Page.querySelector(".btn").click()
uid := Page.getElementById("userId").innerHTML
MsgBox %uid%
*/
Browser.QuitAllSessions()
Page :=
Browser :=
return
^1:: ; Load Meter Client page
if isFireFoxActive()
{
Send, ^t
Send, https://example.com/sadmin/clients.php?email=%proxyEmail%{Enter}
}
return
^2:: ; Load Gapp Services page
if isFireFoxActive()
{
Send, ^t
if proxyEmail
Send, https://example.com/service/?q=%proxyEmail%{Enter}
else
Send, https://example.com/service/?q=%uname% + %sname%{Enter}
}
return
^3:: ; Load proxy Control Panel
if isFireFoxActive()
{
Send, ^t
Send, https://example.com/control/#/{Enter}
}
return
^4:: ; Load (user) account ssh
; SSH - PuTTY into Customer account
Run, "C:\Program Files\PuTTY\putty.exe" %sname%.abc.com -l %uname% -pw "%proxySSH%"
return
^5:: ; Load (server) staff account ssh
; SSH - PuTTY into Customer account
Run, "C:\Program Files\PuTTY\putty.exe" %sname%.abc.com -l %sudoUser% -i %sudoKeyFile%
return
^7:: ; Latest Transfer Set-up
; Exit Firefox not active
if NOT isFireFoxActive()
return
sids := GetServiceIDs()
if sids
for k, sid in sids
{
Send, ^#d
Sleep, 200
Run, %FireFoxpath%
Sleep, 2000
Send, https://example.com/sadmin/clientsservices.php?id=%sid%{Enter}
Sleep, 5000
Send, {tab 40}
Sleep, 1000
Send, ^{enter}
}
return
^8::
Send, XXX: New service as Notified by Email
return
^9:: ; Search for service by user/service
search := UserName()
if NOT isFireFoxActive()
{
Run, %FireFoxpath%
sleep 500
}
Send, ^t
Send, https://example.com/service/?q=%search%{Enter}
return
UserName()
{
return ExtractInfo(1)
}
ServerName()
{
return ExtractInfo(2)
}
isEmailAddress(emailstr){
static regex
regex := "is)^(?:""(?:\\\\.|[^""])*""|[^@]+)@(?=[^()]*(?:\([^)]*\)"
. "[^()]*)*\z)(?![^ ]* (?=[^)]+(?:\(|\z)))(?:(?:[a-z\d() ]+(?:[a-z\d() -]*[()a-"
. "z\d])?\.)+[a-z\d]{2,6}|\[(?:(?:1?\d\d?|2[0-4]\d|25[0-4])\.){3}(?:1?\d\d?|"
. "2[0-4]\d|25[0-4])\]) *\z"
return RegExMatch(emailstr, regex) != 0
}
ServiceID()
{
sid := ExtractInfo(1)
If RegexMatch(sid, "[^0-9]")
sid := ""
return sid
}
GetServiceIDs()
{
sids := Array()
SavedClipboard := ClipboardAll
Clipboard := ""
Send, ^c
ClipWait, 1
SelectedText := Clipboard
Clipboard := SavedClipboard
Loop, parse, SelectedText, `n, `r
{
arr := StrSplit(Trim(A_LoopField), A_Tab)
col1 := arr[1]
col2 := arr[2]
If col1 is digit
sids.push(col1)
else if col2 is digit
sids.push(col2)
}
return sids
}
ExtractInfo(pos)
{
SavedClipboard := ClipboardAll
Clipboard := ""
Send, ^c
ClipWait, 1
SelectedText := TidyInfo(Clipboard)
Clipboard := SavedClipboard
extract_arr := StrSplit(SelectedText,[".","@","-",A_Space,A_Tab])
extract := extract_arr[pos]
If RegexMatch(extract, "[^0-9a-zA-Z]")
extract := ""
return extract
}
ExtractEmail()
{
SavedClipboard := ClipboardAll
Clipboard := ""
Send, ^c
ClipWait, 1
SelectedText := TidyInfo(Clipboard)
Clipboard := SavedClipboard
if isEmailAddress(SelectedText)
return SelectedText
else
return ""
}
TidyInfo(strTidy)
{
strTidy :=
SubStr(
strTidy,
1,
InStr(
strTidy,
".abc.com")-
1)
; while InStr(strTidy,"-")
; strTidy := SubStr(strTidy, InStr(strTidy,"-")+1)
strTidy := Trim(strTidy)
return strTidy
}
ChromeActive()
{
return IsActive("Chrome.exe")
}
isFireFoxActive()
{
return IsActive("FireFox.exe")
}
IsActive(path)
{
WinGet, active, ProcessPath, A
return InStr(active, path)
}
html_decode(html) {
; original name: ComUnHTML() by 'Guest' from
; html := RegExReplace(html, "\r?\n|\r", "<br>") ; added this because original strips line breaks
oHTML := ComObjCreate("HtmlFile")
oHTML.write(html)
return % oHTML.documentElement.innerText
}