219 lines
8.3 KiB
Python
219 lines
8.3 KiB
Python
|
|
||
|
class Gui:
|
||
|
def __init__(self, width, height):
|
||
|
Gui.chrome_gui = Chrome(width, height)
|
||
|
Gui.qwiklabs_gui = Qwiklabs(width, height)
|
||
|
|
||
|
class Chrome(Gui):
|
||
|
SEARCH_BAR_PERCENTAGE = (0.5, 0.1)
|
||
|
|
||
|
def __init__(self, width, height):
|
||
|
Chrome.SEARCH_BAR=width*Chrome.SEARCH_BAR_PERCENTAGE[0], height*Chrome.SEARCH_BAR_PERCENTAGE[1]
|
||
|
|
||
|
def click_searchbar(self):
|
||
|
pyautogui.moveTo(Chrome.SEARCH_BAR[0], Chrome.SEARCH_BAR[1])
|
||
|
pyautogui.click()
|
||
|
pyautogui.keyDown('ctrl')
|
||
|
pyautogui.press('a')
|
||
|
pyautogui.keyUp('ctrl')
|
||
|
|
||
|
|
||
|
class Qwiklabs(Gui):
|
||
|
JOIN_BTN_PERCENTAGE = (0.775, 0.183)
|
||
|
SIGN_IN_BTN_PERCENTAGE = (0.2125, 0.73)
|
||
|
EMAIL_TEXTBOX_PERCENTAGE = (0.5, 0.73)
|
||
|
COURSE_BTN_PERCENTAGE = (0.29, 0.45)
|
||
|
STARTLAB_BTN_PERCENTAGE = (0.125, 0.31)
|
||
|
CAPTCHA_BTN_PERCENTAGE = (0.075, 0.425)
|
||
|
EMAIL_COPY_BTN_PERCENTAGE = (0.3125, 0.7)
|
||
|
PASSWORD_COPY_BTN_PERCENTAGE = (0.3125, 0.82)
|
||
|
|
||
|
def __init__(self, width, height):
|
||
|
Qwiklabs.JOIN_BTN=width*Qwiklabs.JOIN_BTN_PERCENTAGE[0], height*Qwiklabs.JOIN_BTN_PERCENTAGE[1]
|
||
|
Qwiklabs.SIGN_IN_BTN=width*Qwiklabs.SIGN_IN_BTN_PERCENTAGE[0], height*Qwiklabs.SIGN_IN_BTN_PERCENTAGE[1]
|
||
|
Qwiklabs.EMAIL_TEXTBOX=width*Qwiklabs.EMAIL_TEXTBOX_PERCENTAGE[0], height*Qwiklabs.EMAIL_TEXTBOX_PERCENTAGE[1]
|
||
|
Qwiklabs.COURSE_BTN=width*Qwiklabs.COURSE_BTN_PERCENTAGE[0], height*Qwiklabs.COURSE_BTN_PERCENTAGE[1]
|
||
|
Qwiklabs.STARTLAB_BTN=width*Qwiklabs.STARTLAB_BTN_PERCENTAGE[0], height*Qwiklabs.STARTLAB_BTN_PERCENTAGE[1]
|
||
|
Qwiklabs.CAPTCHA_BTN=width*Qwiklabs.CAPTCHA_BTN_PERCENTAGE[0], height*Qwiklabs.CAPTCHA_BTN_PERCENTAGE[1]
|
||
|
Qwiklabs.EMAIL_COPY_BTN=width*Qwiklabs.EMAIL_COPY_BTN_PERCENTAGE[0], height*Qwiklabs.EMAIL_COPY_BTN_PERCENTAGE[1]
|
||
|
Qwiklabs.PASSWORD_COPY_BTN=width*Qwiklabs.PASSWORD_COPY_BTN_PERCENTAGE[0], height*Qwiklabs.PASSWORD_COPY_BTN_PERCENTAGE[1]
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
import time
|
||
|
import subprocess
|
||
|
import os
|
||
|
import pyautogui
|
||
|
import sys
|
||
|
import requests
|
||
|
|
||
|
pyautogui.FAILSAFE = False
|
||
|
|
||
|
screenWidth, screenHeight = pyautogui.size()
|
||
|
ui = Gui(screenWidth, screenHeight)
|
||
|
|
||
|
# print("[QL_GetGAccount] Screen is {} {}".format(screenWidth, screenHeight))
|
||
|
|
||
|
# print("[QL_GetGAccount] Accessing course on qwiklabs")
|
||
|
# Head over to the course on qwiklabs.com
|
||
|
Gui.chrome_gui.click_searchbar()
|
||
|
pyautogui.write("qwiklabs.com")
|
||
|
pyautogui.press('/')
|
||
|
pyautogui.write("focuses")
|
||
|
pyautogui.press('/')
|
||
|
pyautogui.write("2794")
|
||
|
pyautogui.press('?')
|
||
|
pyautogui.write("parent")
|
||
|
pyautogui.press('=')
|
||
|
pyautogui.write("catalog")
|
||
|
pyautogui.press('enter')
|
||
|
|
||
|
time.sleep(15)
|
||
|
|
||
|
# print("[QL_GetGAccount] Signing in")
|
||
|
pyautogui.moveTo(0,0)
|
||
|
|
||
|
# Click join button
|
||
|
pyautogui.moveTo(ui.qwiklabs_gui.JOIN_BTN[0], ui.qwiklabs_gui.JOIN_BTN[1], 3, pyautogui.easeOutQuad)
|
||
|
pyautogui.click(button='left')
|
||
|
time.sleep(5)
|
||
|
|
||
|
# Move to the end of the page
|
||
|
pyautogui.press('pgdn')
|
||
|
|
||
|
# print("Moving from sign up to sign in")
|
||
|
# switch to sign in button
|
||
|
pyautogui.moveTo(ui.qwiklabs_gui.SIGN_IN_BTN[0], ui.qwiklabs_gui.SIGN_IN_BTN[1], 3, pyautogui.easeOutQuad)
|
||
|
pyautogui.click(button='left')
|
||
|
time.sleep(5)
|
||
|
|
||
|
# switch to email textbox, the rest is done via kbd
|
||
|
pyautogui.moveTo(ui.qwiklabs_gui.EMAIL_TEXTBOX[0], ui.qwiklabs_gui.EMAIL_TEXTBOX[1], 3, pyautogui.easeOutQuad)
|
||
|
pyautogui.click(button='left')
|
||
|
time.sleep(2)
|
||
|
|
||
|
# print("[QL_GetGAccount] Inserting credentials")
|
||
|
# account; "mopopa1077@5sword.com", "hellogoodbye"
|
||
|
# account = ("hemerey688@kibwot.com", "hellogoodbye")
|
||
|
|
||
|
account_email = sys.argv[1]
|
||
|
account = (account_email, "hellogoodbye")
|
||
|
username = account[0]
|
||
|
password = account[1]
|
||
|
|
||
|
try:
|
||
|
first_part = username.split('@')[0]
|
||
|
second_part = username.split('@')[1]
|
||
|
except:
|
||
|
print(False)
|
||
|
exit()
|
||
|
|
||
|
pyautogui.press('@')
|
||
|
pyautogui.press('left')
|
||
|
pyautogui.write(first_part, interval=0.2)
|
||
|
pyautogui.press('right')
|
||
|
pyautogui.write(second_part, interval=0.2)
|
||
|
pyautogui.press('\t')
|
||
|
pyautogui.write(password, interval=0.2)
|
||
|
pyautogui.press('enter')
|
||
|
|
||
|
time.sleep(10)
|
||
|
|
||
|
|
||
|
# Start course
|
||
|
time.sleep(5)
|
||
|
# print("[QL_GetGAccount] Starting the course")
|
||
|
pyautogui.moveTo(ui.qwiklabs_gui.STARTLAB_BTN[0], ui.qwiklabs_gui.STARTLAB_BTN[1], 3, pyautogui.easeOutQuad)
|
||
|
pyautogui.click()
|
||
|
|
||
|
# Accept captcha - sometimes they don't even ask for actual verification
|
||
|
time.sleep(5)
|
||
|
# print("Accepting captcha (not needed really)")
|
||
|
pyautogui.moveTo(ui.qwiklabs_gui.CAPTCHA_BTN[0], ui.qwiklabs_gui.CAPTCHA_BTN[1], 3, pyautogui.easeOutQuad)
|
||
|
pyautogui.click()
|
||
|
|
||
|
|
||
|
time.sleep(20)
|
||
|
# Now the lab should be started, we can quit. Creds will be obtained by selenium
|
||
|
|
||
|
# bashCommand = "copyq clipboard"
|
||
|
# # Copy username to clipboard
|
||
|
# time.sleep(20)
|
||
|
# # print("Copying email")
|
||
|
# pyautogui.moveTo(ui.qwiklabs_gui.EMAIL_COPY_BTN[0], ui.qwiklabs_gui.EMAIL_COPY_BTN[1], 3, pyautogui.easeOutQuad)
|
||
|
# pyautogui.click()
|
||
|
# g_email = subprocess.check_output(['bash','-c', bashCommand]).decode('utf-8')
|
||
|
|
||
|
# # Copy password to clipboard
|
||
|
# time.sleep(5)
|
||
|
# # print("Copying password")
|
||
|
# pyautogui.moveTo(ui.qwiklabs_gui.PASSWORD_COPY_BTN[0], ui.qwiklabs_gui.PASSWORD_COPY_BTN[1], 3, pyautogui.easeOutQuad)
|
||
|
# pyautogui.click()
|
||
|
# g_password = subprocess.check_output(['bash','-c', bashCommand]).decode('utf-8')
|
||
|
# time.sleep(5)
|
||
|
|
||
|
# # a possible way of finding out we haven't got the password, therefore the account was probably blocked or there was a connection issue
|
||
|
# if '@' in g_email:
|
||
|
# print(g_email, g_password)
|
||
|
# else:
|
||
|
# # account_list.mark_account_for_deletition(account_email)
|
||
|
# print(False)
|
||
|
|
||
|
def get_google_account():
|
||
|
from utils import global_vars
|
||
|
from selenium.webdriver.common.by import By
|
||
|
from utils.browser_manager import clickButton, inputText, expand_shadow_element, start_browser
|
||
|
import subprocess
|
||
|
import json
|
||
|
import time
|
||
|
|
||
|
if global_vars.TEST_ACCOUNT:
|
||
|
print("[QL_GetAccount] Using Test Account {}".format(global_vars.TEST_ACCOUNT) )
|
||
|
driver = start_browser()
|
||
|
driver.get(global_vars.TEST_ACCOUNT[2])
|
||
|
return global_vars.TEST_ACCOUNT[0], global_vars.TEST_ACCOUNT[1], global_vars.TEST_ACCOUNT[2], driver
|
||
|
else:
|
||
|
print("[QL_GetAccount] Getting new google account..." )
|
||
|
#TODO: Handle failure in getting the account
|
||
|
|
||
|
if global_vars.TEST_QWIKLABS_ACCOUNT is False:
|
||
|
print("[QL_GetAccount] Using TEST Qwiklabs account to get it")
|
||
|
account = socket_request_new_account()
|
||
|
|
||
|
subprocess.call(['bash','-c', "src/qwiklabs/get_account.sh {} {} ".format(str(global_vars.PROXY), account)])
|
||
|
else:
|
||
|
print("[QL_GetAccount] Using Qwiklabs test account")
|
||
|
account = global_vars.TEST_QWIKLABS_ACCOUNT
|
||
|
|
||
|
driver = start_browser()
|
||
|
driver.get("https://www.qwiklabs.com/focuses/2794?catalog_rank=%7B%22rank%22%3A2%2C%22num_filters%22%3A0%2C%22has_search%22%3Atrue%7D&parent=catalog&search_id=12598152")
|
||
|
|
||
|
time.sleep(5)
|
||
|
clickButton(driver, By.XPATH, '/html/body/div[1]/div[1]/ql-toolbar/div[2]/a[2]')
|
||
|
time.sleep(5)
|
||
|
|
||
|
inputText(driver, By.CSS_SELECTOR, "#user_email", account)
|
||
|
inputText(driver, By.CSS_SELECTOR, "#user_password", "hellogoodbye" + '\n')
|
||
|
time.sleep(5)
|
||
|
|
||
|
panel = driver.find_element_by_xpath('/html/body/main/div/ql-drawer-container/ql-drawer-content/ql-drawer-container/ql-drawer[1]/ql-lab-control-panel')
|
||
|
details = panel.get_attribute('labdetails')
|
||
|
|
||
|
details_json = json.loads(details)
|
||
|
gshell_link = details_json[0]['href']
|
||
|
email = details_json[1]['value']
|
||
|
password = details_json[2]['value']
|
||
|
|
||
|
print("[QL_GetAccount] Got a Google account, it is", (email, password, gshell_link))
|
||
|
|
||
|
return email, password, gshell_link, driver
|
||
|
|
||
|
# Assumes the account server is already running on localhost:12345
|
||
|
def socket_request_new_account():
|
||
|
import socket
|
||
|
from utils import global_vars
|
||
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||
|
s.connect((global_vars.QWACCOUNTSERVER_HOSTNAME_DOCKER, 12345)) #ip
|
||
|
s.send(b"givacc")
|
||
|
account = s.recv(1024).decode("utf-8")
|
||
|
s.close()
|
||
|
return account
|