NEW: Basic login and altering of the record settings using selenium
This commit is contained in:
parent
c900582307
commit
3dc5009ac9
123
main.py
123
main.py
|
@ -1,91 +1,62 @@
|
||||||
|
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from bs4 import BeautifulSoup
|
|
||||||
import requests
|
|
||||||
import time
|
import time
|
||||||
|
from selenium import webdriver
|
||||||
|
|
||||||
headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:74.0)
|
def login(driver):
|
||||||
Gecko/20100101 Firefox/74.0'}
|
driver.get('https://admin.hostpoint.ch/customer/Auth/Login')
|
||||||
loginPage = 'https://admin.hostpoint.ch/customer/Auth/Login'
|
driver.find_element_by_name('username').send_keys('jeanggi90@gmail.com')
|
||||||
loginAction = 'https://admin.hostpoint.ch/customer/Auth/Login?site=%2Fcustomer%2FIndex%3Flang%3Dde%26suppress_errors%3D1'
|
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')
|
driver.get('https://admin.hostpoint.ch/customer/Domains/Overview')
|
||||||
csrf = soup.find('input', {"name" : "csrf_token"})['value']
|
driver.find_element_by_name('edit_dns').click()
|
||||||
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']
|
|
||||||
|
|
||||||
return {"username": "jeanggi90@gmail.com",
|
driver.implicitly_wait(10)
|
||||||
"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):
|
|
||||||
|
|
||||||
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):
|
except Exception as e:
|
||||||
# Navigate to the next page and scrape the data
|
print(f"Except: {str(e)}")
|
||||||
s = session.get('https://admin.hostpoint.ch/customer/Index')
|
|
||||||
|
|
||||||
print(s.status_code)
|
try:
|
||||||
|
|
||||||
soup = BeautifulSoup(s.text, 'html.parser')
|
e = driver.find_element_by_name('execute_now')
|
||||||
print(soup.prettify())
|
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__":
|
if __name__ == "__main__":
|
||||||
|
with webdriver.Firefox() as driver:
|
||||||
with requests.Session() as sess:
|
login(driver)
|
||||||
|
updateARecord(driver, '46.127.188.60')
|
||||||
sess.headers.update(headers)
|
time.sleep(60)
|
||||||
|
|
||||||
payload = preparePayload(sess) manageCookies(sess)
|
|
||||||
|
|
||||||
login(sess, payload) time.sleep(10)
|
|
||||||
print(sess.cookies)
|
|
||||||
getLoggedIn(sess)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue