Beispiel #1
0
class CreateApp:
    DEBUG = False
    domain = 'gmail.com'
    loginUrl = 'https://appengine.google.com'
    loginPostUrl = 'https://www.google.com/accounts/ServiceLoginAuth?service=ah&sig=d71ef8b8d6150b23958ad03b3bf546b7'
    loginSuccessKey = 'CheckCookie?continue='
    SendMuti = True
    URL_GMAIL = 'https://appengine.google.com/_ah/login/continue?https://appengine.google.com/&ltmpl=ae&sig=c24697718eec1be75b7ab8f8a0c02416'
    SKIP_URL = 'https://appengine.google.com/_ah/conflogin?continue=https://appengine.google.com/'
    ACTION_TOKEN_COOKIE = "GMAIL_AT"
    
    def __init__(self, name, psw):
        self.web = SingleWeb()
        self.name = name
        self.psw = psw
        self.params = Storage()
    
    
    def _buildURL(self, **kwargs):
        return "%s%s" % (self.URL_GMAIL, urllib.urlencode(kwargs))
    
    def getLoginData(self, data):
        all = text.get_hidden(data)
        all.update({
            'Email' : self.name,
            'Passwd' : self.psw,
            'rmShown' : '0',
        })
        return all

    def _getActionToken(self):
        at = self.web.get_cookies(self.ACTION_TOKEN_COOKIE)
        if at is None:    
            params = {'search' : 'inbox',
                  'start': 0,
                  'view': 'tl',
                  }
            self.web.get_page(self._buildURL(**params))

            at = self.web.get_cookies(self.ACTION_TOKEN_COOKIE)
        return at
    
    def checkLoginSuccess(self, result):
        if self.DEBUG:
            if result:
                file('logindebug.html', 'w').write(result)
        if self.loginSuccessKey and result.find(self.loginSuccessKey) != -1:
            return True
        if self.loginBlockKey and result.find(self.loginBlockKey) != -1:
            return False
        return False
    
    
    def getLoginHeader(self, data):
        return {'referer' : self.loginUrl}
    
    
    def loginSuccess(self, data):
        RE_PAGE_REDIRECT = 'CheckCookie\?continue=([^"\']+)' 
        try:
            link = re.search(RE_PAGE_REDIRECT, data).group(1)
            redirectURL = urllib2.unquote(link)
            redirectURL = redirectURL.replace('\\x26', '&')
        
        except AttributeError:
            return False
        pageData = self.web.get_page(redirectURL)
        g = text.get_in(pageData, 'var GLOBALS=[,,', ',,')
        if g is None:
            return False
        self.GLOBALS = eval('[%s]' % g)
        return True
    
    def login(self):
        res = self.web.get_page(self.loginUrl)
        if res is None:
            print 'login:get %s fail' % self.loginUrl
            return False
        self.loginPostUrl = text.get_in(res, 'action="', '"').replace("&", '&')
        data = self.getLoginData(res)
        if data is None:
            return False
        header = {
            'referer' : self.web.resp.url
        }
        res = self.web.get_page(self.loginPostUrl, data, header)
        if res is None:
            print 'login:post %s fail' % self.loginPostUrl
            return False
        respurl = self.web.url
        if respurl.find('WITHOUT_PHONE') != -1:
            self.web.get_page(self.SKIP_URL)
        print respurl
        if respurl.find("accounts/CheckCookie") != -1:
            url = text.get_in(res, 'location.replace("', '"')
            url = url.replace('\\x3d', '=').replace('\\x26', '&')
            res = self.web.get_page(url)
            if self.web.resp.url.find('appengine.google.com') != -1:
                return True
        elif respurl.find('https://appengine.google.com') != -1:
            return True
        else:
            return False
    
    def loadApp(self):
        url = 'https://appengine.google.com/'
        page = self.web.get_page(url)
        if page is None:
            return []
        appids = text.get_in_list(page, 'app_id=', '"')
        return appids
    
    def createApp(self, appid=None):
        url = 'https://appengine.google.com/start/createapp'
        res = self.web.get_page(url)
        if appid is None:
            appid = text.rnd_str(11)
        data = text.get_hidden(res)
        data.update({
            'app_id' : appid,
            'title' : appid,
            'tos_accept' : 'on',
            'auth_domain' : '',
            'auth_config' : 'google',
            'submit' : 'Create Application',
        })
        posturl = "https://appengine.google.com/start/createapp.do"
        res = self.web.get_page(posturl, data, headers={'referer' : url})
        if res is None:
            return False
        file('a.html', 'w').write(res)
        
        if self.web.resp.url.find('/start/createapp_success?app_id=%s' % appid) != -1:
            return appid
        else:
            if str(res).find('Cannot create any more apps') != -1:
                raise 'Limit'
            return False
Beispiel #2
0
class MSNLive(LogBase):
    APP_URL = 'http://profile.live.com/'

    def __init__(self, name, psw):
        LogBase.__init__(self, name)
        self.web = SingleWeb()
        self.name = name
        self.psw = psw

    def login(self, *args, **kwargs):
        try:
            return self._login(*args, **kwargs)
        except:
            return False

    def do_submit(self, page):
        form = get_in(page, '<form name="fmHF" id="fmHF"', '</form>')
        if form is None:
            return page
        action = get_in(form, 'action="', '"')
        data = get_hidden(form)

        page = self.web.get_page(action, data, {'referer': self.web.url})
        return page

    def get_auto_refresh_url(self, page):
        page = page.lower()
        noscript = get_in(page, '<noscript>', '</noscript>')
        if not noscript:
            return None
        for meta in get_in_list(noscript, '<meta', '/>'):
            equiv = get_in(meta, 'http-equiv="', '"')
            if equiv and equiv == 'refresh':
                refresh = get_in(meta, 'content="', '"')
                ii = refresh.find(";")
                if ii != -1:
                    pause, newurl_spec = float(refresh[:ii]), refresh[ii + 1:]
                    jj = newurl_spec.find("=")
                    if jj != -1:
                        key, url = newurl_spec[:jj], newurl_spec[jj + 1:]
                    if key.strip().lower() != "url":
                        continue
                else:
                    continue

                if pause > 1E-3:
                    time.sleep(pause)
                url = iso_to_char(url)
                return url
        return None

    def process_cookies(self):
        auth = self.web.get_cookies('RPSTAuth')
        if auth:
            self.web.clear_cookies()
            self.web.set_cookie_obj(auth)
            return
        return

    def active(self, login_page):
        data = {
            'ctl00$ctl00$MainContent$MainContent$LoginMain$iPwdEncrypted':
            'lFFvlCtVl8t5loh5/B6pLO9w98Rn0koyrbw7XxveR2TMxlKI6oZ+2Sjk2Tzlc5G++xvDYDxL2+lQjBxKvK5OyuWe5fsoz1sVgZ8jOEgQdHu1iiCOUZN8BZ50h6uLn2RGnbfjAmrXDs1sC7LH2BojoFERYcWK6khY+zdNol3ao5s=',
            'ctl00$ctl00$MainContent$MainContent$LoginMain$iPublicKey':
            '1BEF90811CE78A99D0820E87F3BDF1F96622EB40',
            'ctl00$ctl00$MainContent$MainContent$LoginWrapper$LoginRepeater$ctl00$LoginOther$iEncryptedSecretAnswer':
            'HuGIQQaa2l8FUSnacZbzMm8zjDlX9po2hbGp3mAjLBELM16rOiNr8/870XoF3tLqoA8PsfwhlsJwVyEVVxAnJTYFaODxYCz861Vua6uDoUQjG1VFifpSBSSBPRY+5AiG139kNUZSPj+Uryuukx13mVAsj8TA/PGcHGH6P8Ae6Uw=',
            'ctl00$ctl00$MainContent$MainContent$LoginWrapper$LoginRepeater$ctl00$LoginOther$iQuestion':
            '母亲的出生地点'
        }
        page = self.web.submit(login_page, data, name='aspnetForm')

        return page

    def _login(self, to=None, login_page=None):

        login_page = self.web.get_page(self.APP_URL)

        url = self.get_auto_refresh_url(login_page)
        logging.error('url %s', url)
        if url and url.find('cid-') != -1:
            return True

        if url:
            login_page = self.web.get_page(url)

        post_url = get_in(login_page, "srf_uPost='", "'")
        logging.error('post_url %s', post_url)
        data = get_hidden(login_page)
        data.update({
            'login': self.name,
            'passwd': self.psw,
            'NewUser': '******',
        })

        #req = urllib2.Request(url, data=data, headers=headers)
        result = self.web.get_page(post_url, data=data)
        if result is None:
            return False
        if result.find('onload="javascript:DoSubmit();"') != -1:
            active_page = self.web.submit(result)
            result = self.active(active_page)

        url = self.get_auto_refresh_url(result)
        logging.error('finish %s', url)
        if url.find('profile.live.com/') != -1:
            #self.process_cookies()
            return True
        if self.web.url.lower().find('jsDisabled.srf') != -1:
            if result.find('action="https://security.live.com') != -1:
                self.error('Disable')
                raise DisabledException
            else:
                self.error('Auth Fail')
                raise AuthFailException
        return False

    def get_page(self, *args, **kwargs):
        res = self.web.get_page(*args, **kwargs)
        return self.auto_refresh(res)

    def auto_refresh(self, res):
        if res is None:
            return None
        lower_res = res.lower()
        if lower_res.find('onload="javascript:dosubmit();"') != -1:
            return self.web.submit(res)

        for meta in get_in_list(lower_res, '<meta', '/>'):
            if meta.find('http-equiv="refresh"') != -1:
                refresh = get_in(meta, 'content="', '"')
                ii = refresh.find(";")
                if ii != -1:
                    pause, newurl_spec = float(refresh[:ii]), refresh[ii + 1:]
                    jj = newurl_spec.find("=")
                    if jj != -1:
                        key, newurl = newurl_spec[:jj], newurl_spec[jj + 1:]
                    if key.strip().lower() != "url":
                        return res
                else:
                    return res

                if pause > 1E-3:
                    time.sleep(pause)
                newurl = iso_to_char(newurl)
                res = self.get_page(newurl)
                return res
        return res
Beispiel #3
0
class MSNLive(LogBase):
    APP_URL = 'http://profile.live.com/'
    def __init__(self, name, psw):
        LogBase.__init__(self, name)
        self.web = SingleWeb()
        self.name = name
        self.psw = psw

    def login(self, *args, **kwargs):
        try:
            return self._login(*args, **kwargs)
        except:
            return False

    def do_submit(self, page):
        form = get_in(page, '<form name="fmHF" id="fmHF"', '</form>')
        if form is None:
            return page
        action = get_in(form, 'action="', '"')
        data = get_hidden(form)

        page = self.web.get_page(action, data, {'referer' : self.web.url})
        return page

    def get_auto_refresh_url(self, page):
        page = page.lower()
        noscript = get_in(page, '<noscript>', '</noscript>')
        if not noscript:
            return None
        for meta in get_in_list(noscript, '<meta', '/>'):
            equiv = get_in(meta, 'http-equiv="', '"')
            if equiv and equiv == 'refresh':
                refresh = get_in(meta, 'content="', '"')
                ii = refresh.find(";")
                if ii != -1:
                    pause, newurl_spec = float(refresh[:ii]), refresh[ii+1:]
                    jj = newurl_spec.find("=")
                    if jj != -1:
                        key, url = newurl_spec[:jj], newurl_spec[jj+1:]
                    if key.strip().lower() != "url":
                        continue
                else:
                    continue
                
                if pause > 1E-3:
                    time.sleep(pause)
                url = iso_to_char(url)
                return url
        return None
        

    def process_cookies(self):
        auth = self.web.get_cookies('RPSTAuth')
        if auth:
            self.web.clear_cookies()
            self.web.set_cookie_obj(auth)
            return
        return
    
    def active(self, login_page):
        data = {
            'ctl00$ctl00$MainContent$MainContent$LoginMain$iPwdEncrypted' : 'lFFvlCtVl8t5loh5/B6pLO9w98Rn0koyrbw7XxveR2TMxlKI6oZ+2Sjk2Tzlc5G++xvDYDxL2+lQjBxKvK5OyuWe5fsoz1sVgZ8jOEgQdHu1iiCOUZN8BZ50h6uLn2RGnbfjAmrXDs1sC7LH2BojoFERYcWK6khY+zdNol3ao5s=',
        'ctl00$ctl00$MainContent$MainContent$LoginMain$iPublicKey' : '1BEF90811CE78A99D0820E87F3BDF1F96622EB40',
       'ctl00$ctl00$MainContent$MainContent$LoginWrapper$LoginRepeater$ctl00$LoginOther$iEncryptedSecretAnswer' : 'HuGIQQaa2l8FUSnacZbzMm8zjDlX9po2hbGp3mAjLBELM16rOiNr8/870XoF3tLqoA8PsfwhlsJwVyEVVxAnJTYFaODxYCz861Vua6uDoUQjG1VFifpSBSSBPRY+5AiG139kNUZSPj+Uryuukx13mVAsj8TA/PGcHGH6P8Ae6Uw=',
        'ctl00$ctl00$MainContent$MainContent$LoginWrapper$LoginRepeater$ctl00$LoginOther$iQuestion' : '母亲的出生地点'
        }
        page = self.web.submit(login_page, data, name='aspnetForm')
        
        return page
    
    def _login(self, to = None, login_page=None):
            
        login_page = self.web.get_page(self.APP_URL)

        url = self.get_auto_refresh_url(login_page)
        logging.error('url %s', url)
        if url and url.find('cid-') != -1:
            return True
        
        if url:
            login_page = self.web.get_page(url)

        post_url = get_in(login_page, "srf_uPost='", "'")
        logging.error('post_url %s', post_url)
        data = get_hidden(login_page)
        data.update({'login' : self.name,
                'passwd' : self.psw,
                'NewUser' : '1',
                
        })

        #req = urllib2.Request(url, data=data, headers=headers)
        result = self.web.get_page(post_url, data=data)
        if result is None:
            return False
        if result.find('onload="javascript:DoSubmit();"') != -1:
            active_page = self.web.submit(result)
            result = self.active(active_page)

        url = self.get_auto_refresh_url(result)
        logging.error('finish %s', url)
        if url.find('profile.live.com/') != -1:
            #self.process_cookies()
            return True
        if self.web.url.lower().find('jsDisabled.srf') != -1:
            if result.find('action="https://security.live.com') != -1:
                self.error('Disable')
                raise DisabledException
            else:
                self.error('Auth Fail')
                raise AuthFailException
        return False
    
    
    def get_page(self, *args, **kwargs):
        res = self.web.get_page(*args, **kwargs)
        return self.auto_refresh(res)
        
    def auto_refresh(self, res):
        if res is None:
            return None
        lower_res = res.lower()
        if lower_res.find('onload="javascript:dosubmit();"') != -1:
            return self.web.submit(res)
            
        for meta in get_in_list(lower_res, '<meta', '/>'):
            if meta.find('http-equiv="refresh"') != -1:
                refresh = get_in(meta, 'content="', '"')
                ii = refresh.find(";")
                if ii != -1:
                    pause, newurl_spec = float(refresh[:ii]), refresh[ii+1:]
                    jj = newurl_spec.find("=")
                    if jj != -1:
                        key, newurl = newurl_spec[:jj], newurl_spec[jj+1:]
                    if key.strip().lower() != "url":
                        return res
                else:
                    return res
                
                if pause > 1E-3:
                    time.sleep(pause)
                newurl = iso_to_char(newurl)
                res = self.get_page(newurl)
                return res
        return res