You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
3.2 KiB
Python
110 lines
3.2 KiB
Python
#!/usr/local/monitoring/bin/python
|
|
|
|
import calendar, time, sys
|
|
sys.path.insert (1, '/usr/local/monitoring/princeton/lib')
|
|
#sys.path.insert (2, '/usr/local/monitoring/python/lib/python2.7/site-packages')
|
|
#sys.path.insert (3, '/usr/local/monitoring/python/lib/python2.7')
|
|
#sys.path.insert (4, '/usr/local/monitoring/python/lib64/python2.6/site-packages')
|
|
#sys.path.insert (5, '/usr/local/monitoring/python/lib/python2.6/site-packages')
|
|
#sys.path.insert (6, '/usr/local/monitoring/python/lib/python2.6/site-packages/selenium-2.48.0-py2.6.egg')
|
|
from puselenium import init_selenium
|
|
|
|
from selenium import webdriver
|
|
from selenium.webdriver.support.ui import WebDriverWait
|
|
from selenium.webdriver.common.by import By
|
|
from selenium.webdriver.support import expected_conditions as EC
|
|
from selenium.common import exceptions as EXCEP
|
|
from random import sample
|
|
|
|
if len (sys.argv) != 4:
|
|
print "Usage: %s <URL> <username> <password>" % sys.argv[0]
|
|
sys.exit (3)
|
|
|
|
url = sys.argv[1]
|
|
usr = sys.argv[2]
|
|
usrpass = sys.argv[3]
|
|
|
|
ff, fp = init_selenium ()
|
|
|
|
try:
|
|
prog_start = time.time()
|
|
ff.implicitly_wait (10)
|
|
|
|
try:
|
|
ff.get (url)
|
|
except:
|
|
print "Unable to retrieve the initial (Login) webpage \"%s\"" % url
|
|
sys.exit (2)
|
|
|
|
#WebDriverWait (ff, 20).until (EC.title_contains("Sign In"))
|
|
|
|
fed_login = time.time()
|
|
|
|
try:
|
|
uid = ff.find_element_by_id ("userNameInput")
|
|
uid.send_keys (usr)
|
|
except:
|
|
print "Unable to locate the login field. Page likely loaded incorrectly"
|
|
sys.exit (2)
|
|
|
|
#WebDriverWait (ff, 10).until (EC.presence_of_element_located((By.ID, "Bharosa_Password_PadDataField")))
|
|
try:
|
|
pupass = ff.find_element_by_id ("passwordInput")
|
|
pupass.send_keys (usrpass)
|
|
pupass.submit()
|
|
except:
|
|
print "Unable to locate the password field. Page likely loaded incorrectly"
|
|
sys.exit (2)
|
|
|
|
try:
|
|
WebDriverWait (ff, 30).until (EC.presence_of_element_located((By.XPATH, "//a[contains(@href, '/SiteAssets/OITmedallion_onWhite.gif')]")))
|
|
|
|
gwmenu = ff.find_element_by_id ("O365_MainLink_Me")
|
|
gwmenu.click()
|
|
|
|
|
|
logoutln = ff.find_element_by_xpath ("//*[text()='Sign Out']")
|
|
logoutln.click()
|
|
except:
|
|
print "Unable to locate the OIT logo and/or the \"Sign Out\" link. The webpage likely did not fully load"
|
|
sys.exit (2)
|
|
|
|
prog_finish = time.time()
|
|
|
|
|
|
try:
|
|
WebDriverWait (ff, 10).until (EC.title_contains("Please close the browser to complete sign out."))
|
|
except:
|
|
print "Failed to sign out of SharePoint. This is likely harmless"
|
|
sys.exit (1)
|
|
|
|
time.sleep(2)
|
|
|
|
except EXCEP.ErrorInResponseException, (resp, msg):
|
|
|
|
print "ERROR: An error occured communicating with the browser server: Response: %s; Message: %s" % (resp, msg)
|
|
sys.exit (1)
|
|
|
|
except EXCEP.NoSuchElementException, msg:
|
|
|
|
print "ERROR: Unable to locate webpage element. Probably the page loaded incompletely or incorrectly: %s" % msg
|
|
sys.exit (1)
|
|
|
|
except EXCEP.TimeoutException, msg:
|
|
|
|
print "ERROR: Request timed out. Network??? Response: %s" % msg
|
|
sys.exit (1)
|
|
|
|
except EXCEP.WebDriverException, msg:
|
|
|
|
print "ERROR: I don't know what happened. Read this - %s" % msg
|
|
sys.exit (1)
|
|
|
|
finally:
|
|
#fp.clean()
|
|
ff.quit()
|
|
|
|
print "Successfully logged on to SharePoint (\"%s\") and logged off | 'loginpage_get'=%ss;;; 'fulllogin'=%ss;;; 'total'=%ss;;;" % (url, (fed_login - prog_start), (prog_finish - fed_login), (prog_finish - prog_start))
|
|
|
|
sys.exit (0)
|