diff --git a/main.py b/main.py index 167b415..716b3d9 100644 --- a/main.py +++ b/main.py @@ -1,91 +1,62 @@ + #!/usr/bin/env python -from bs4 import BeautifulSoup -import requests import time +from selenium import webdriver -headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:74.0) - Gecko/20100101 Firefox/74.0'} -loginPage = 'https://admin.hostpoint.ch/customer/Auth/Login' -loginAction = 'https://admin.hostpoint.ch/customer/Auth/Login?site=%2Fcustomer%2FIndex%3Flang%3Dde%26suppress_errors%3D1' +def login(driver): + driver.get('https://admin.hostpoint.ch/customer/Auth/Login') + driver.find_element_by_name('username').send_keys('jeanggi90@gmail.com') + driver.find_element_by_name('password').send_keys('`^0oVc2Yd9`tQ&l]&4X04QNV<') + driver.find_element_by_name('login').click() -def preparePayload(session): +def updateARecord(driver, ip): - s = session.get(loginPage) + rowId = ['record-70642858', 'record-70642859'] - soup = BeautifulSoup(s.text, 'html.parser') - csrf = soup.find('input', {"name" : "csrf_token"})['value'] - vscheck = soup.find('input', {"name" : "__vscheck__"})['value'] - viewstate = soup.find('input', {"name" : "__viewstate__"})['value'] - dflt_vsid = soup.find('input', {"name" : "_dflt_vsid_"})['value'] - vsid = soup.find('input', {"name" : "_vsid_"})['value'] - vsid__vsm_data_vscheck = soup.find('input', {"name" : "_vsid__vsm_data_vscheck_"})['value'] - vsid__vsm_data_viewstate = soup.find('input', {"name" : "_vsid__vsm_data_viewstate_"})['value'] - page_uuid = soup.find('input', {"name" : "__page_uuid__"})['value'] + driver.get('https://admin.hostpoint.ch/customer/Domains/Overview') + driver.find_element_by_name('edit_dns').click() - return {"username": "jeanggi90@gmail.com", - "password": "`^0oVc2Yd9`tQ&l]&4X04QNV<", - "locale": "de_CH", - "cloud_office_host": "", - "csrf_token": csrf , - "action_login": "", - "g_main_locale": "de_CH", - "__vscheck__": vscheck , - "__viewstate__": viewstate , - "_dflt_vsid_": dflt_vsid , - "_vsid_": vsid , - "_vsid__vsm_data_vscheck_": vsid__vsm_data_vscheck , - "_vsid__vsm_data_viewstate_": vsid__vsm_data_viewstate , - "__is_dirty__": "False", - "__dirty_actions__": "[\"apply\",+\"save\"]", - "__page_uuid__": page_uuid , - "__usage_count__": "", - "__usage_max_count__": "" - } - -def manageCookies(session): - - s = session.get(loginPage) - - cookies = {} - - for e in s.headers['Set-Cookie'].split(';'): - cookie = e.split('=') - try: - cookies[cookie[0].strip()] = cookie[1].strip() - except: - cookies[cookie[0].strip()] = True - - headers['cookie'] = cookies["secure, _SID_customer"] - - session.headers.update(headers) - -def login(session, payload): + driver.implicitly_wait(10) - s = session.post(loginAction, headers=headers, data=payload) + tableRows = driver.find_element_by_id('dns-record-list').find_elements_by_class_name('b-record') - print(s.status_code) + # The last two entries are my A records + for e in tableRows[-2:]: + try: + e.find_element_by_name('edit').click() + + # For some reason with each iteration it return one more such element + editForm = driver.find_elements_by_class_name('dns-record-list-edit') + editForm[-1].find_element_by_name('ip_address').clear() + editForm[-1].find_element_by_name('ip_address').send_keys(ip) + + editForm[-1].find_element_by_name('apply').click() -def getLoggedIn(session): - # Navigate to the next page and scrape the data - s = session.get('https://admin.hostpoint.ch/customer/Index') + except Exception as e: + print(f"Except: {str(e)}") - print(s.status_code) - - soup = BeautifulSoup(s.text, 'html.parser') - print(soup.prettify()) + try: + + e = driver.find_element_by_name('execute_now') + driver.execute_script("arguments[0].click();", e) + + # Give the site some time to save + time.sleep(10) + except Exception as e: + print(f"Except: {str(e)}") +# try: +# if driver.find_element_by_id('dns-editor-content-success').get_attribute('display') != 'none': +# print('Success') +# +# else: +# print('Not successful') +# except Exception as e: +# print("Not successful") if __name__ == "__main__": - - with requests.Session() as sess: - - sess.headers.update(headers) - - payload = preparePayload(sess) manageCookies(sess) - - login(sess, payload) time.sleep(10) - print(sess.cookies) - getLoggedIn(sess) - - + with webdriver.Firefox() as driver: + login(driver) + updateARecord(driver, '46.127.188.60') + time.sleep(60)