Пример #1
0
    def delete(self, user):
        ''' Delete the user on Github Enterprise '''

        # Initialize the PhantomJS selenium driver
        driver = PhantomJS()
        driver.implicitly_wait(10)
        driver.set_window_size(1400, 850)

        # Login as the admin user
        driver.get('https://%s/login' % (self.ghe_host))
        driver.find_element_by_name('login').send_keys(self.ghe_user)
        driver.find_element_by_name('password').send_keys(self.ghe_pass)
        driver.find_element_by_name('commit').click()

        # Check for two-factor auth code request
        if driver.current_url == 'https://%s/sessions/two-factor' % self.ghe_host:
            if self.ghe_totp:
                base = '.auth-form-body input'
                u = driver.find_element_by_css_selector('%s[name=utf8]' % base)
                t = driver.find_element_by_css_selector('%s[name=authenticity_token]' % base)
                otp = pyotp.TOTP(self.ghe_totp)

                driver.request('POST', 'https://%s/sessions/two-factor' % self.ghe_host,
                    data={
                        'utf8': u.get_attribute('value'),
                        'otp': otp.now(),
                        'authenticity_token': t.get_attribute('value')
                    }
                )
            else:
                print('Two-Factor authentication required.')
                sys.exit()

        # Retrieve the admin page for the designated user to be deleted
        driver.get('https://%s/stafftools/users/%s/admin' % (self.ghe_host, user))

        # Ensure that we were able to access the requested admin page
        if 'Page not found' in driver.title or user.lower() not in driver.title.lower():
            print('User not found, or insufficient access rights.')
            sys.exit()

        # Locate the necessary inputs to be able to delete a user
        base = '#confirm_deletion form input'
        u = driver.find_element_by_css_selector('%s[name=utf8]' % base)
        m = driver.find_element_by_css_selector('%s[name=_method]' % base)
        t = driver.find_element_by_css_selector('%s[name=authenticity_token]' % base)

        # Send the delete user request
        driver.request('POST', 'https://%s/stafftools/users/%s' % (self.ghe_host, user),
            data={
                'utf8': u.get_attribute('value'),
                '_method': m.get_attribute('value'),
                'authenticity_token': t.get_attribute('value')
            }
        )
Пример #2
0
p.find_element_by_name('PasswordField').send_keys(password + Keys.RETURN)

# NOTE: This will obviously break if the site ever changes layout
challenge_xpath = "id('AccessForm')/div/div[1]/div[2]/table/tbody/tr[2]/td[2]"

while p.current_url == 'https://www.mydatcu.org/User/AccessSignin/Challenge':
    text = p.find_elements_by_xpath(challenge_xpath)
    if not text:
        raise Exception('No results found!')

    text = text[0].text.replace('explain', '').strip()
    if text not in challenges:
        raise Exception("Question '%s' is unanswered!" % text)

    p.find_element_by_name('Answer').send_keys(challenges[text] + Keys.RETURN)

# All Transactions
p.find_elements_by_xpath("id('MasterHeaderMenuSub')/a[3]")[0].click()

# Options
p.find_elements_by_xpath("id('MasterMain')/div[3]/div/div[1]/div[2]/table/tbody/tr[2]/td/span[1]")[0].click()

# Options > Download as CSV
r = p.request('GET', 'https://www.mydatcu.org/User/MainTransactions/List?csv=true')
if r.status_code != 200:
    raise Exception('Could not GET https://www.mydatcu.org/User/MainTransactions/List?csv=true')

with open('test.csv', 'w') as fo:
    fo.write(r.text)
    print("Wrote to test.csv")
Пример #3
0
           formURL = checkform
           
   if 'resources' in formURL:
       checkform = 'contact'
   elif 'server-suite-form' in formURL or 'mac-form' in formURL:
       checkform = 'server'
   elif 'privilege-service-form' in formURL or 'identity-service-form' in formURL:
       checkform = 'identity'
   elif 'solutions' in formURL:
       checkform = 'solutions'
   else:
       checkform ='contact'
       
   checkingUrl = currentSite + formURL    
 
   response = subdriver.request('GET',  checkingUrl )
   print checkingUrl, response.status_code, checkform
   if response.status_code == 200 :
       
       if checkform=='identity':
           identityFormTest(checkingUrl)    
       elif checkform =='server':
           print checkform
           serverFormTest(checkingUrl)
       elif checkform =='solutions':
           print checkform
           solutionFormTest(checkingUrl)
       elif checkform =='contact':
           print checkform
           contactFormTest(checkingUrl)
       else:
Пример #4
0
class Vassar_Downloader(object):
    err_log_name = 'ERROR_LOG.txt'
    download_log = "temp.txt"
    raw_file_folder = 'Raw files -- %s' % str(time.localtime()[0:3])

    def __init__(self,
                 urn=None,
                 pwd=None,
                 init_dict=[res for res in permutation(lowercase, 2)]):
        if not os.path.exists(self.raw_file_folder):
            os.mkdir(self.raw_file_folder)
        os.chdir(self.raw_file_folder)
        if not urn:
            urn = raw_input('Enter the username: '******''
        else:
            print 'Username: '******'\n'
        if not pwd:
            pwd = getpass.getpass('Enter the password: '******'cls')
        with open(self.err_log_name, 'w') as f:
            f.write('Starting crawling from %s...\n' % time.ctime())

        self.url = 'https://aisapps.vassar.edu/directory/internal_auth_studir_srch.php'

        print 'Initializing...\n'
        self.browser = PhantomJS()

        self.i = 0

        self.urn = urn
        self.pwd = pwd
        self.DICT = init_dict

        self.searchReq = 'https://aisapps.vassar.edu/directory/internal_auth_studirctry_rslts.php'

        self.init()

    def init(self):
        self.if_continue()
        self.cluster()

    def if_continue(self):
        self.finished_list = []
        if os.path.exists(self.download_log):
            with open(self.download_log, 'r') as f:
                data = f.read()
                self.finished_list = data.split(',')
                self.finished_list.pop(-2)
                self.waiting_list = filter(
                    lambda x: x not in self.finished_list, self.DICT)
                self.status = "Continue from the last dumping... %d / %d\n" % (
                    len(self.DICT) - len(self.waiting_list), len(self.DICT))

                print self.status
        else:
            self.waiting_list = self.DICT

    def login(self):
        print 'Connecting to "%s"...' % self.url
        self.browser.get(self.url)
        self.status = '\nTrying to login as %s...' % self.urn
        print self.status

        username = self.browser.find_element_by_name("username")
        password = self.browser.find_element_by_name("password")
        username.send_keys(self.urn)
        password.send_keys(self.pwd)
        login_attempt = self.browser.find_element_by_xpath(
            "//*[@type='submit']")
        login_attempt.submit()
        return self.browser.page_source

    def request(self, data, method='POST', error_time=0):
        filename = 'source - %s.txt' % (str(data.values()))
        #print 'downloading %s...'%filename

        try:
            resp = self.browser.request(method, self.searchReq, data=data)
            with open(filename, 'w') as f:
                #f.write(clean_content(resp.content))
                f.write(resp.content)
            temp = data['lastname']
            self.finished_list.append(temp)
            self.waiting_list.remove(temp)
            self.status = '%d / %d done...' % (
                self.total - len(self.waiting_list), self.total)

            print self.status
            with open(self.download_log, 'a') as f:
                f.write('%s,' % temp)

        except Exception as e:
            error_time += 1
            if error_time <= 3:
                self.logger('Error! %s failed %d times.' %
                            (str(data), error_time))
                self.request(data, error_time=error_time)
            else:
                self.logger('<<Error! %s not downloaded!>>' % (str(data)))

    def cluster(self):
        s = self.login()
        if 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd' not in s:
            self.status = '\nAuthentification failed.\n'

            print self.status
            self.logger('Authentification failed.')
            return None
        else:
            self.status = '\nAuthentification succeeded.\n\nDownloading data...\n\n'
            print self.status

        self.total = len(self.DICT)
        threads = [
            MyThread(self.request, ({
                'lastname': ln
            }, 'POST'), name=ln) for ln in self.waiting_list
        ]
        for t in threads:
            t.start()

        for t in threads:
            t.join()

        self.status = '\nClearing cache...\n'
        print self.status
        os.remove(self.download_log)
        print 'Done...\n'

    def logger(self, msg):
        with open(self.err_log_name, 'a') as f:
            f.write('%s --- %s\n' % (msg, time.ctime()))
Пример #5
0
    def update(self, user, email):
        ''' Reset the users email address on Github Enterprise '''

        # Initialize the PhantomJS selenium driver
        driver = PhantomJS()
        driver.implicitly_wait(10)
        driver.set_window_size(1400, 850)

        # Login as the admin user
        driver.get('https://%s/login' % (self.ghe_host))
        driver.find_element_by_name('login').send_keys(self.ghe_user)
        driver.find_element_by_name('password').send_keys(self.ghe_pass)
        driver.find_element_by_name('commit').click()

        # Check for two-factor auth code request
        if driver.current_url == 'https://%s/sessions/two-factor' % self.ghe_host:
            if self.ghe_totp:
                base = '.auth-form-body input'
                u = driver.find_element_by_css_selector('%s[name=utf8]' % base)
                t = driver.find_element_by_css_selector(
                    '%s[name=authenticity_token]' % base)
                otp = pyotp.TOTP(self.ghe_totp)

                driver.request(
                    'POST',
                    'https://%s/sessions/two-factor' % self.ghe_host,
                    data={
                        'utf8': u.get_attribute('value'),
                        'otp': otp.now(),
                        'authenticity_token': t.get_attribute('value')
                    })
            else:
                print('Two-Factor authentication required.')
                sys.exit()

        # Retrieve the email admin page for the designated user to be updated
        driver.get('https://%s/stafftools/users/%s/emails' %
                   (self.ghe_host, user))

        # Ensure that we were able to access the requested admin page
        if 'Page not found' in driver.title or user.lower(
        ) not in driver.title.lower():
            print('User not found, or insufficient access rights.')
            sys.exit()

        # Locate the necessary inputs to be able to add an email address
        base = 'form[action="/stafftools/users/%s/emails"] input' % user
        u = driver.find_element_by_css_selector('%s[name=utf8]' % base)
        t = driver.find_element_by_css_selector('%s[name=authenticity_token]' %
                                                base)

        # Send the add email address request
        driver.request('POST',
                       'https://%s/stafftools/users/%s/emails' %
                       (self.ghe_host, user),
                       data={
                           'utf8': u.get_attribute('value'),
                           'email': email,
                           'authenticity_token': t.get_attribute('value')
                       })

        # Send password reset to new email address
        base = 'form[action="/stafftools/users/%s/password/send_reset_email"] input' % user
        u = driver.find_element_by_css_selector('%s[name=utf8]' % base)
        t = driver.find_element_by_css_selector('%s[name=authenticity_token]' %
                                                base)
        m = driver.find_element_by_css_selector('%s[name=_method]' % base)
        driver.request(
            'POST',
            'https://%s/stafftools/users/%s/password/send_reset_email' %
            (self.ghe_host, user),
            data={
                'utf8': u.get_attribute('value'),
                'email': email,
                'authenticity_token': t.get_attribute('value'),
                '_method': m.get_attribute('value')
            })

        # Get password reset link and display to console
        driver.get('https://%s/stafftools/users/%s/emails' %
                   (self.ghe_host, user))
        if email in driver.page_source:
            print('Email added and password reset email sent.')
        else:
            print(
                'New email not showing up on user page; please check manually.'
            )