Esempio n. 1
0
    def __init__(self, cookie_file=''):
        self.cjar = MozillaCookieJar()
        self.cFile = cookie_file

        # If we have a cookie file, load it:
        if self.cFile and exists(self.cFile):
            try:
                self.cjar.load(self.cFile, ignore_discard=True)
            except Exception as msg:
                self.cjar = MozillaCookieJar()  # Just to be safe

        self.opener = build_opener(HTTPCookieProcessor(self.cjar))
Esempio n. 2
0
	def GetWithCookie( url, cookie_name, data = '', retry = 3):
		global PATH_TMP, ACGINDEX_UA

		try:
			cj = MozillaCookieJar( PATH_TMP + cookie_name )

			try :
				cj.load( PATH_TMP + cookie_name )
			except:
				pass # 还没有cookie只好拉倒咯

			ckproc = urllib2.HTTPCookieProcessor( cj )

			AmagamiSS = urllib2.build_opener( ckproc )
			AmagamiSS.addheaders = [ ACGINDEX_UA ]

			if data != '':
				request = urllib2.Request( url = url, data = data )
				res = AmagamiSS.open( request )
				cj.save() # 只有在post时才保存新获得的cookie
			else:
				res = AmagamiSS.open( url )

			return Haruka.GetContent( res )

		except:
			# 这里有3次重新连接的机会,3次都超时就跳过
			if retry > 0 : 
				return Haruka.GetWithCookie( url, cookie_name, data , retry-1 )
			else:
				return False
Esempio n. 3
0
 def __init__(self):
     self.m_encrypt = NetEaseEncrypt()
     self.str_cookie_path = "file_cookie.txt"
     self.default_timeout = 200
     self.header = {
         "Accept": "*/*",
         "Accept-Encoding": "gzip,deflate,sdch",
         "Accept-Language": "zh-CN,zh;q=0.8,gl;q=0.6,zh-TW;q=0.4",
         "Connection": "keep-alive",
         "Content-Type": "application/x-www-form-urlencoded",
         "Host": "music.163.com",
         "Referer": "http://music.163.com/search/",
         "User-Agent":
         #"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36" 
         "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36"
     }
     self.session = requests.Session()
     self.session.cookies = MozillaCookieJar(self.str_cookie_path)
     try:
         self.session.cookies.load()
         cookie = ""
         if os.path.isfile(self.str_cookie_path):
             file_handle = open(self.str_cookie_path, "r")
             cookie = file_handle.read()
             file_handle.close()
         expire_time = re.compile(r"\d{4}-\d{2}-\d{2}").findall(cookie)
         print "expire_time",expire_time
         if expire_time:
             if expire_time[0] < time.strftime("%Y-%m-%d", time.localtime(time.time())):
                 print cookie
                 os.remove(self.str_cookie_path)
     except IOError as e:
         print str(e)
         self.session.cookies.save()
Esempio n. 4
0
    def __init__(self, args):
        super(HttpScan, self).__init__(args)
        self.session = requesocks.session()

        adapters.DEFAULT_RETRIES = self.args.max_retries
        self.tor = None
        if self.args.tor:
            self.out.log("Enabling TOR")
            self.tor = Torify()
            self.session.proxies = {'http': 'socks5://127.0.0.1:9050',
                                    'https': 'socks5://127.0.0.1:9050'}
            if self.args.check_tor:
                # Check TOR
                self.out.log("Checking IP via TOR")
                rip, tip = self.tor.check_ip(verbose=True)
                if tip is None:
                    self.out.log('TOR is not working properly!', logging.ERROR)
                    exit(-1)

        if self.args.cookies is not None:
            if path.exists(self.args.cookies) and path.isfile(self.args.cookies):
                self.cookies = MozillaCookieJar(self.args.cookies)
                self.cookies.load()
            else:
                # self.out.log('Could not find cookie file: %s' % self.args.load_cookies, logging.ERROR)
                self.cookies = Cookies.from_request(self.args.cookies)
        else:
            self.cookies = None

        self.ua = UserAgent() if self.args.user_agent is None else self.args.user_agent
Esempio n. 5
0
def asf_dl(d, opt_dict):
    user_name = password_config.asfuser
    user_password = password_config.asfpass
    url = d['downloadUrl']
    filename = os.path.basename(url)
    print("ASF Download:",filename)
    start = time.time()

    # SAA - 2 July 2018
    # Redid the downloader to support new cookie jars

    global cookie_jar_path
    cookie_jar_path = os.path.join( os.getcwd(), ".bulk_download_cookiejar.txt")
    cookie_jar = MozillaCookieJar()

    global asf_urs4
    asf_urs4 = { 'url': 'https://urs.earthdata.nasa.gov/oauth/authorize',
            'client': 'BO_n7nTIlMljdvU6kRRB3g',
            'redir': 'https://vertex-retired.daac.asf.alaska.edu/services/urs4_token_request'}

    # Make sure we can write it our current directory
    if os.access(os.getcwd(), os.W_OK) is False:
        print ("WARNING: Cannot write to current path! Check permissions for {0}".format(os.getcwd()))
        exit(-1)

    cj = get_cookie(user_name,user_password,cookie_jar_path)
    print('**********************  START 2nd COOKIE CHECK ******************')
    if check_cookie(cj):
        pass
    else:
        sys.exit('Did not pass check_cookie')

    print("ASF Download:",filename)
    start = time.time()
    try:
        request = Request(url)
        response = urlopen(request)
    except HTTPError as e:
        print(url)
        print(e)
        return
    dl_file_size = int(response.info()['Content-Length'])
    if os.path.exists(filename):
        file_size = os.path.getsize(filename)
        if dl_file_size == file_size:
            print("%s already downloaded" % filename)
            return
    start = time.time()
    CHUNK = 128*10240
    with open(filename, 'wb') as fp:
        while True:
            chunk = response.read(CHUNK)
            if not chunk: break
            fp.write(chunk)

    # Check to see if you got the file properly or not
    total_time = time.time() - start
    mb_sec = (os.path.getsize(filename) / (1024 * 1024.0)) / total_time
    print("%s download time: %.2f secs (%.2f MB/sec)" % (filename, total_time, mb_sec))
    fp.close()
    def get_cookie(self):

        # remove the cookie_jar_path file if its older than a day
        date_created = cookie_creation_date()
        if date_created:
            dx = datetime.now() - date_created
            hour = dx.total_seconds() / (3600)
            if hour > 10:
                print('cookie greater than 10 hours so removing it')
                os.remove(self.cookie_jar_path)

        if os.path.isfile(self.cookie_jar_path):
            self.cookie_jar = MozillaCookieJar()
            self.cookie_jar.load(self.cookie_jar_path)

            # make sure cookie is still valid
            if self.check_cookie():
                print(' > Re-using previous cookie jar.')
                return True
            else:
                print(' > Could not validate old cookie Jar')

        # We don't have a valid cookie, prompt user or creds
        print('No existing URS cookie found, creating one')
        print('(Credentials will not be stored, saved or logged anywhere)')

        # Keep trying 'till user gets the right U:P
        while self.check_cookie() is False:
            self.get_new_cookie()

        return True
Esempio n. 7
0
    def __init__(self,
                 appkey=APPKEY,
                 appsecret=APPSECRET,
                 width=720,
                 height=480):
        self.defaultHeader = {'Referer': 'http://www.bilibili.com'}
        #self.defaultHeader = {}
        self.appkey = appkey
        self.appsecret = appsecret
        self.WIDTH = width
        self.HEIGHT = height
        self.is_login = False
        cookie_path = os.path.dirname(os.path.abspath(__file__)) + '/.cookie'
        self.cj = MozillaCookieJar(cookie_path)
        if os.path.isfile(cookie_path):
            self.cj.load()
            key = None
            for ck in self.cj:
                if ck.name == 'DedeUserID':
                    key = ck.value
                    break
            if key is not None:
                self.is_login = True
                self.mid = str(key)
        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cj))
        urllib2.install_opener(opener)

        try:
            os.remove(self._get_tmp_dir() + '/tmp.ass')
        except:
            pass
    def __init__(self):
        self.ses = requests.session()
        self.ses.cookies = MozillaCookieJar('cookie.txt')
        self.user = None
        if not os.path.exists('cookie.txt'):
            if easygui.ynbox(
                    'Het bestand *cookie.txt* is niet gevonden. Wil je inloggen bij Google?',
                    'youtube-folower', ('Ja', 'Nee')):
                self.user = self.login()
        else:
            with open('cookie.txt', 'r') as cf:
                self.rawcookie = cf.read()
                if (self.rawcookie == ''):
                    if easygui.ynbox(
                            'Het bestand *cookie.txt* is leeg. Wil je inloggen bij Google?',
                            'youtube-folower', ('Ja', 'Nee')):
                        self.user = self.login()
                else:
                    self.ses.cookies.load(ignore_discard=True,
                                          ignore_expires=True)
                    self.user = self.check_login()
                    if self.user == None:
                        if easygui.ynbox(
                                'Het bestand *cookie.txt* is gevonden, maar geeft geen ingelogde gebruiker. Wil je inloggen bij Google?',
                                'youtube-folower', ('Ja', 'Nee')):
                            self.user = self.login()

        if self.user == None:
            print 'Nog logged in. Continuing anonymously.'
        else:
            print 'Logged in as: %s.' % self.user

        self.save_cookie()
Esempio n. 9
0
def get_cookiejar(ui):
    global current_user
    if os.name == 'nt':
        cookie_path = os.path.expanduser('~\\_hgcookies')
    else:
        cookie_path = os.path.expanduser('~/.hgcookies')

    if not os.path.isdir(cookie_path):
        if os.path.exists(cookie_path):
            os.remove(cookie_path)
        os.mkdir(cookie_path)
        if os.name == 'posix':
            os.chmod(cookie_path, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC)

    cookie_path = os.path.join(cookie_path, md5(current_user).hexdigest())
    # Cygwin's Python does not always expanduser() properly...
    if re.match(r'^[A-Za-z]:', cookie_path) is not None and re.match(
            r'[A-Za-z]:\\', cookie_path) is None:
        cookie_path = re.sub(r'([A-Za-z]):', r'\1:\\', cookie_path)

    try:
        cj = CookieJar(cookie_path)
        if not os.path.exists(cookie_path):
            cj.save()
            if os.name == 'posix':
                os.chmod(cookie_path, stat.S_IREAD | stat.S_IWRITE)
        cj.load(ignore_discard=True, ignore_expires=True)
        return cj
    except IOError, e:
        ui.warn(
            _('Cookie file %s exists, but could not be opened.\nContinuing without cookie authentication.\n'
              ) % cookie_path)
        return MozillaCookieJar()
Esempio n. 10
0
    def __init__(self,
                 mobile,
                 password=None,
                 status='0',
                 cachefile='Fetion.cache',
                 cookiesfile=''):
        '''登录状态:
        在线:400 隐身:0 忙碌:600 离开:100
        '''
        if cachefile:
            self.cache = Cache(cachefile)

        if not cookiesfile:
            cookiesfile = '%s.cookies' % mobile

        cookiejar = MozillaCookieJar(filename=cookiesfile)
        if not os.path.isfile(cookiesfile):
            open(cookiesfile, 'w').write(MozillaCookieJar.header)

        cookiejar.load(filename=cookiesfile)

        cookie_processor = HTTPCookieProcessor(cookiejar)

        self.opener = build_opener(cookie_processor, HTTPHandler)
        self.mobile, self.password = mobile, password
        if not self.alive():
            self._login()
            cookiejar.save()

        self.changestatus(status)
Esempio n. 11
0
def LIVE(url, relogin=False):
    if not (settings['username'] and settings['password']):
        xbmcgui.Dialog().ok('Chyba', 'Nastavte prosím moja.markiza.sk konto',
                            '', '')
        xbmcplugin.setResolvedUrl(int(sys.argv[1]), False, xbmcgui.ListItem())
        raise RuntimeError
    cj = MozillaCookieJar()
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    if not relogin:
        try:
            cj.load(cookiepath)
        except IOError:
            relogin = True
    if relogin:
        response = opener.open(loginurl).read()
        token = re.search(r'name=\"_token_\" value=\"(\S+?)\">',
                          response).group(1)
        logindata = urllib.urlencode({
            'email': settings['username'],
            'password': settings['password'],
            '_token_': token,
            '_do': 'content1-loginForm-form-submit'
        }) + '&login=Prihl%C3%A1si%C5%A5+sa'
        opener.open(loginurl, logindata)
        log('Saving cookies')
        cj.save(cookiepath)

    response = opener.open(url).read()
    link = re.search(r'<iframe src=\"(\S+?)\"', response).group(
        1)  #https://videoarchiv.markiza.sk/api/v1/user/live
    link = link.replace('&amp;', '&')
    response = opener.open(link).read()
    if '<iframe src=\"' not in response:  #handle expired cookies
        if relogin:
            xbmcgui.Dialog().ok('Chyba', 'Skontrolujte prihlasovacie údaje',
                                '', '')
            raise RuntimeError  # loop protection
        else:
            LIVE(url, relogin=True)
            return
    opener.addheaders = [('Referer', link)]
    link = re.search(r'<iframe src=\"(\S+?)\"',
                     response).group(1)  #https://media.cms.markiza.sk/embed/
    response = opener.open(link).read()
    if '<title>Error</title>' in response:
        error = re.search('<h2 class="e-title">(.*?)</h2>', response).group(
            1)  #Video nie je dostupné vo vašej krajine
        xbmcgui.Dialog().ok('Chyba', error, '', '')
        raise RuntimeError
    link = re.search(r'\"hls\": \"(\S+?)\"', response).group(
        1)  #https://h1-s6.c.markiza.sk/hls/markiza-sd-master.m3u8
    response = opener.open(link).read()

    cookies = '|Cookie='
    for cookie in cj:
        cookies += cookie.name + '=' + cookie.value + ';'
    cookies = cookies[:-1]
    play_item = xbmcgui.ListItem(path=link + cookies)
    xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem=play_item)
 def get_new_cookie(self):
     # Start by prompting user to input their credentials
     
     # Another Python2/3 workaround
     try:
         new_username = raw_input("Username: "******"Username: "******"Password (will not be displayed): ")
     
     # Build URS4 Cookie request
     auth_cookie_url = self.asf_urs4['url'] + '?client_id=' + self.asf_urs4['client'] + '&redirect_uri=' + \
                       self.asf_urs4['redir'] + '&response_type=code&state='
     
     try:
         # python2
         user_pass = base64.b64encode(bytes(new_username + ":" + new_password))
     except TypeError:
         # python3
         user_pass = base64.b64encode(bytes(new_username + ":" + new_password, "utf-8"))
         user_pass = user_pass.decode("utf-8")
     
     # Authenticate against URS, grab all the cookies
     self.cookie_jar = MozillaCookieJar()
     opener = build_opener(HTTPCookieProcessor(self.cookie_jar), HTTPHandler(), HTTPSHandler(**self.context))
     request = Request(auth_cookie_url, headers={"Authorization": "Basic {0}".format(user_pass)})
     
     # Watch out cookie rejection!
     try:
         response = opener.open(request)
     except HTTPError as e:
         if e.code == 401:
             print(" > Username and Password combo was not successful. Please try again.")
             return False
         else:
             # If an error happens here, the user most likely has not confirmed EULA.
             print("\nIMPORTANT: There was an error obtaining a download cookie!")
             print("Your user appears to lack permission to download data from the ASF Datapool.")
             print(
                 "\n\nNew users: you must first log into Vertex and accept the EULA. In addition, your Study Area must be set at Earthdata https://urs.earthdata.nasa.gov")
             exit(-1)
     except URLError as e:
         print("\nIMPORTANT: There was a problem communicating with URS, unable to obtain cookie. ")
         print("Try cookie generation later.")
         exit(-1)
     
     # Did we get a cookie?
     if self.check_cookie_is_logged_in(self.cookie_jar):
         # COOKIE SUCCESS!
         self.cookie_jar.save(self.cookie_jar_path)
         return True
     
     # if we aren't successful generating the cookie, nothing will work. Stop here!
     print("WARNING: Could not generate new cookie! Cannot proceed. Please try Username and Password again.")
     print("Response was {0}.".format(response.getcode()))
     print(
         "\n\nNew users: you must first log into Vertex and accept the EULA. In addition, your Study Area must be set at Earthdata https://urs.earthdata.nasa.gov")
     exit(-1)
Esempio n. 13
0
def getAccountInfo():
    print "getting account information"
    cookies = MozillaCookieJar(cookie_file)

    opener = getOpener(cookies)
    o = opener.open("https://real-debrid.com/api/account.php")

    print o.read(1024)
    o.close()
Esempio n. 14
0
def load_cookies3():
    """ 加载 cookie:cookies.txt -> load()  —— MozillaCookieJar格式
    """
    save_to_txt()
    cj = MozillaCookieJar()
    cj.load('localCookiesMoz.txt', ignore_discard=True,
            ignore_expires=True)  # 这里必须将参数置为True,否则登录失败
    for index, cookie in enumerate(cj):  # 显示cookies
        print('[', index, ']', cookie)
    return cj
Esempio n. 15
0
    def __init__(self, default_cookiejar=None):
        HTTPCookieProcessor.__init__(self, None)

        # Store the different cookie jars here, these represent the different
        # browser sessions that the plugins might request
        self.jars = {}

        if default_cookiejar is None:
            default_cookiejar = MozillaCookieJar()

        self.default_cookiejar = default_cookiejar
Esempio n. 16
0
def check_kilnauth_token(ui, url):
    cookiepath = _get_path('hgcookies')
    if (not os.path.exists(cookiepath)) or (not os.path.isdir(cookiepath)):
        return ''
    cookiepath = os.path.join(cookiepath, md5(get_username(get_dest(ui))).hexdigest())

    try:
        if not os.path.exists(cookiepath):
            return ''
        cj = MozillaCookieJar(cookiepath)
    except IOError, e:
        return ''
Esempio n. 17
0
 def __init__(self):
     super(Session, self).__init__()
     self.trust_env = False
     cookie_file = os.path.expanduser('~/.deis/cookies.txt')
     cookie_dir = os.path.dirname(cookie_file)
     self.cookies = MozillaCookieJar(cookie_file)
     # Create the $HOME/.deis dir if it doesn't exist
     if not os.path.isdir(cookie_dir):
         os.mkdir(cookie_dir, 0700)
     # Load existing cookies if the cookies.txt exists
     if os.path.isfile(cookie_file):
         self.cookies.load()
         self.cookies.clear_expired_cookies()
Esempio n. 18
0
def save_cookies_Moz(url):
    """保存cookies到文件 —— MozillaCookieJar格式
    """
    # 设置保存cookie的文件,同级目录下的cookie.txt
    filename = 'cookies_Moz.txt'
    # 声明一个MozillaCookieJar对象实例来保存cookie,之后写入文件
    cookie = MozillaCookieJar(filename)
    opener = build_opener(HTTPCookieProcessor(cookie))
    # 创建一个请求,原理同urllib2的urlopen
    response = opener.open(url)
    # 保存cookie到文件
    cookie.save(ignore_discard=True,
                ignore_expires=True)  # 这里必须将参数置为True,否则写入文件失败
Esempio n. 19
0
 def __init__(self, uAgent=None, headers=None):
     '''uAgent es el agente de usuario'''
     self.cookie_j = MozillaCookieJar()
     if uAgent is None:
         uAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36'
     self.opener = build_opener(HTTPCookieProcessor(self.cookie_j))
     self.user_agent = uAgent
     self.opener.addheaders = [('User-Agent', self.user_agent)]
     # self.session = requests.Session()
     # self.session.headers.update({ 'User-Agent': uAgent })
     # self.session.max_redirects = 20
     self.timeout = 25
     socket.setdefaulttimeout(self.timeout)
Esempio n. 20
0
 def __init__(self, appkey=APPKEY, appsecret=APPSECRET):
     self.appkey = appkey
     self.appsecret = appsecret
     self.is_login = False
     cookie_path = os.path.dirname(os.path.abspath(__file__)) + '/.cookie'
     self.cj = MozillaCookieJar(cookie_path)
     if os.path.isfile(cookie_path):
         self.cj.load()
         if requests.utils.dict_from_cookiejar(
                 self.cj).has_key('DedeUserID'):
             self.is_login = True
             self.mid = str(
                 requests.utils.dict_from_cookiejar(self.cj)['DedeUserID'])
     opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cj))
     urllib2.install_opener(opener)
Esempio n. 21
0
def init(cookieFile=None):
    if cookieFile is None:
        if 'COOKIE_FILE' not in os.environ:
            warning("cs.www.init(): no \$COOKIE_FILE")
            return
        cookieFile = os.environ['COOKIE_FILE']
    cookieHandler = HTTPCookieProcessor()
    cookieHandler.cookiejar = MozillaCookieJar()
    if not cookieFile.endswith('.sqlite'):
        # presume older mozilla cookie file
        cookieHandler.cookiejar.load(cookieFile)
    else:
        import sqlite3
        import time
        now = time.time()
        debug("SQLITE3 cookie file: %s" % cookieFile)
        db = sqlite3.connect(cookieFile)
        cursor = db.cursor()
        cursor.execute(
            'select id, name, value, host, path, expiry, isSecure, isHttpOnly from moz_cookies'
        )
        for id, name, value, host, path, expiry, isSecure, isHttpOnly in cursor:
            isSecure = bool(isSecure)
            isHttpOnly = bool(isHttpOnly)
            if name == "":
                # cookies.txt regards 'Set-Cookie: foo' as a cookie
                # with no name, whereas cookielib regards it as a
                # cookie with no value.
                name = value
                value = None
            initial_dot = host.startswith(".")
            domain_specified = initial_dot
            discard = False
            if expiry == "":
                expiry = None
                discard = True
            # assume path_specified is false
            c = Cookie(0, name, value, None, False, host, domain_specified,
                       initial_dot, path, False, isSecure, expiry, discard,
                       None, None, {})
            if c.is_expired(now):
                warning("skip expired cookie: name=%s, host=%s, path=%s", name,
                        host, path)
                continue
            warning("add cookie: name=%s, host=%s, path=%s", name, host, path)
            cookieHandler.cookiejar.set_cookie(c)
    install_opener(build_opener(cookieHandler))
Esempio n. 22
0
    def get_cookie_jar(self, request):
        """
        :param request: The HTTP request, with a browser session attribute, or
                        None if the default cookiejar should be used.

        :return: The cookiejar instance
        """
        if request.session is None:
            return self.default_cookiejar

        session = self.jars.get(request.session, None)
        if session is not None:
            return session

        new_session = MozillaCookieJar()
        self.jars[request.session] = new_session
        return new_session
    def __init__(self,
                 cache_dir=None,
                 web_time_out=30,
                 cookie_jar=None,
                 ignore_ssl_errors=False):
        """ Initialises the UriHandler class

        Keyword Arguments:
        :param str cache_dir:         A path for http caching. If specified, caching will be used.
        :param int web_time_out:      Timeout for requests in seconds
        :param str cookie_jar:        The path to the cookie jar (in case of file storage)
        :param ignore_ssl_errors:     Ignore any SSL certificate errors.

        """

        self.id = int(time.time())

        if cookie_jar:
            self.cookieJar = MozillaCookieJar(cookie_jar)
            if not os.path.isfile(cookie_jar):
                self.cookieJar.save()
            self.cookieJar.load()
            self.cookieJarFile = True
        else:
            self.cookieJar = CookieJar()
            self.cookieJarFile = False

        self.cacheDir = cache_dir
        self.cacheStore = None
        if cache_dir:
            self.cacheStore = StreamCache(cache_dir)
            Logger.debug("Opened %s", self.cacheStore)
        else:
            Logger.debug("No cache-store provided. Cached disabled.")

        self.userAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 (.NET CLR 3.5.30729)"
        self.webTimeOut = web_time_out  # max duration of request
        self.ignoreSslErrors = ignore_ssl_errors  # ignore SSL errors
        if self.ignoreSslErrors:
            Logger.warning("Ignoring all SSL errors in Python")

        # status of the most recent call
        self.status = UriStatus(code=0, url=None, error=False, reason=None)

        # for download animation
        self.__animationIndex = -1
Esempio n. 24
0
    def login_test(self, provider):
        with self.app.test_request_context('https://localhost.admin.eutaxia.eu:5000/login',
                                           base_url='https://localhost.admin.eutaxia.eu:5000/'):
            resp = oauth.authorize(provider)
            assert resp.status_code == 302
            location = resp.headers['Location']
            session_data = dict(flask.session)

        cj = MozillaCookieJar(os.path.join(os.path.dirname(__file__), 'cookies.%s.txt' % provider))
        cj.load()

        class NoRedirectHandler(HTTPRedirectHandler):

            def redirect_request(self, req, fp, code, msg, hdrs, newurl):
                if newurl.startswith('https://localhost.admin.eutaxia.eu:5000/login/%s' % provider):
                    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
                return HTTPRedirectHandler.redirect_request(self, req, fp, code, msg, hdrs, newurl)

        opener = build_opener(HTTPCookieProcessor(cj),
                              NoRedirectHandler())

        try:
            res = opener.open(location)
        except HTTPError as err:
            assert err.code == 302
            url = err.hdrs['Location']
            assert url.startswith('https://localhost.admin.eutaxia.eu:5000/login/%s' % provider)
        else:
            if provider == 'windowslive':
                # Unfortunately we can't configure Windows Live to accept two separate
                # redirect URLs
                return
            else:
                assert False, 'Wrong redirect'

        with self.app.test_client() as c:
            with c.session_transaction() as session:
                session.update(session_data)

            query_string = urlparse(url).query
            resp = c.get('/login/%s' % provider, query_string=query_string)
            assert resp.status_code == 666
Esempio n. 25
0
def check_kilnauth_token(ui, url):
    cookiepath = _get_path('hgcookies')
    if (not os.path.exists(cookiepath)) or (not os.path.isdir(cookiepath)):
        return ''
    cookiepath = os.path.join(cookiepath,
                              md5(get_username(get_dest(ui))).hexdigest())

    try:
        if not os.path.exists(cookiepath):
            return ''
        cj = MozillaCookieJar(cookiepath)
    except IOError:
        return ''

    domain = get_domain(url)

    cj.load(ignore_discard=True, ignore_expires=True)
    for cookie in cj:
        if domain == cookie.domain:
            if cookie.name == 'fbToken':
                return cookie.value
Esempio n. 26
0
def get_cookie(uname,pword,cookie_jar_path):
    print(cookie_jar_path)
    if os.path.isfile(cookie_jar_path):
       cookie_jar = MozillaCookieJar()
       cookie_jar.load(cookie_jar_path)
 
       ## make sure cookie is still valid
       print('*******************  FIRST COOKIE Check  ******************')
       if check_cookie(cookie_jar):
          print(" > Re-using previous cookie jar.")
          print('*******************  END FIRST COOKIE Check  ******************')
          return cookie_jar
       else:
          print(" > Could not validate old cookie Jar")
          cookie_jar = get_new_cookie(uname,pword,cookie_jar_path)
          check_cookie(cookie_jar)
    else:
        print('Could not find existing cookie jar -- Creating a new one')
        cookie_jar = get_new_cookie(uname,pword,cookie_jar_path)

    return cookie_jar
Esempio n. 27
0
    def get_cookie(self):
        if os.path.isfile(self.cookie_jar_path):
            self.cookie_jar = MozillaCookieJar()
            self.cookie_jar.load(self.cookie_jar_path)

            # make sure cookie is still valid
            if self.check_cookie():
                print(" > Re-using previous cookie jar.")
                return True
            else:
                print(" > Could not validate old cookie Jar")

        # We don't have a valid cookie, prompt user or creds
        print("No existing URS cookie found, please enter Earthdata username & password:"******"(Credentials will not be stored, saved or logged anywhere)")

        # Keep trying 'till user gets the right U:P
        while self.check_cookie() is False:
            self.get_new_cookie()

        return True
Esempio n. 28
0
	def __init__(self, loadconfig = None):
		# create config info
		self.app_state = Config(defaults=DEFAULTS, fpath=STATE_FILEPATH)
		self.has_error = False
		if loadconfig:
			self.app_state.Load()
		else:
			# if config file doesn't exist, save the defaults loaded above
			self.app_state.Save() #saves 
	
		self.CFG= Config2()
		err_text = self.CFG.Parse(CFG_FILEPATH)
		if err_text:
			print 'Config file read error: '+err_text
		# url opener for website retrieves
		self.cj = MozillaCookieJar(self.CFG.cookie_filename)
		self.session_cookie = None
		if os.path.exists(self.CFG.cookie_filename):
			self.cj.load()
			self.CheckSessionCookie() # set session cookie if it exists and hasn't expired
		# need to use build_opener to submit cookies and post form data
		self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cj))
 def __init__(self,
              starturl,
              index_html='',
              maxlevel=1,
              cookie_file=None,
              acldb=None,
              urldb=None,
              default_charset=None,
              delay=0,
              timeout=300,
              debug=0):
     (proto, self.hostport, _x, _y, _z) = urlsplit(starturl)
     #    assert proto == 'http'
     #Thread.__init__(self)
     self.debug = debug
     self.index_html = index_html
     if cookie_file:
         self.cookiejar = MozillaCookieJar(cookie_file)
         self.cookiejar.load()
     else:
         self.cookiejar = None
     self.robotstxt = RobotFileParser()
     self.robotstxt.set_url(urljoin(starturl, '/robots.txt'))
     try:
         self.robotstxt.read()
     except IOError:
         pass
     self.conn = None
     self.urldb = urldb
     self.acldb = acldb
     self.curlevel = 0
     self.delay = delay
     self.timeout = timeout
     self.default_charset = default_charset
     if starturl.endswith('/'):
         starturl += self.index_html
     self.urls = [(starturl, maxlevel)]
     self.crawled = {}  # 1:injected, 2:crawled
     return
Esempio n. 30
0
 def __init__(self):
     self.header = {
         'Accept': '*/*',
         'Accept-Encoding': 'gzip,deflate,sdch',
         'Accept-Language': 'zh-CN,zh;q=0.8,gl;q=0.6,zh-TW;q=0.4',
         'Connection': 'keep-alive',
         'Content-Type': 'application/x-www-form-urlencoded',
         'Host': 'music.163.com',
         'Referer': 'http://music.163.com/search/',
         'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36'
     }
     self.cookies = {
         'appver': '1.5.2'
     }
     self.playlist_class_dict = {}
     self.session = requests.Session()
     self.storage = Storage()
     self.session.cookies = MozillaCookieJar(self.storage.cookie_path)
     try:
         self.session.cookies.load()
         self.file = file(self.storage.cookie_path, 'r')
         cookie = self.file.read()
         self.file.close()
         pattern = re.compile(r'\d{4}-\d{2}-\d{2}')
         str = pattern.findall(cookie)
         if str:
             if str[0] < time.strftime('%Y-%m-%d', time.localtime(time.time())):
                 self.storage.database['user'] = {
                     "username": "",
                     "password": "",
                     "user_id": "",
                     "nickname": "",
                 }
                 self.storage.save()
                 os.remove(self.storage.cookie_path)
     except:
         self.session.cookies.save()