示例#1
0
 def login(self):
     if not self.username and not self.password:
         return True # fall back to free account
     elif self.username and self.password and len(self.username)>0 and len(self.password)>0:
         util.info('[SC] Login user=%s, pass=*****' % self.username)
         # get salt
         headers,req = self._create_request('',{'username_or_email':self.username})
         data = util.post(self._url('api/salt/'),req,headers=headers)
         xml = ET.fromstring(data)
         if not xml.find('status').text == 'OK':
             util.error('[SC] Server returned error status, response: %s' % data)
             return False
         salt = xml.find('salt').text
         # create hashes
         password = hashlib.sha1(md5crypt(self.password.encode('utf-8'), salt.encode('utf-8'))).hexdigest()
         digest = hashlib.md5(self.username + ':Webshare:' + self.password).hexdigest()
         # login
         headers,req = self._create_request('',{'username_or_email':self.username,'password':password,'digest':digest,'keep_logged_in':1})
         data = util.post(self._url('api/login/'),req,headers=headers)
         xml = ET.fromstring(data)
         if not xml.find('status').text == 'OK':
             util.error('[SC] Server returned error status, response: %s' % data)
             return False
         self.token = xml.find('token').text
         try:
             util.cache_cookies(None)
         except:
             pass
         util.info('[SC] Login successfull')
         return True
     return False
 def logout(self):
     util.info("[SC] logout")
     headers, req = self._create_request('/', {'wst': self.token})
     try:
         self.clearToken()
         post(self._url('api/logout/'), req, headers=headers)
         util.cache_cookies(None)
     except:
         util.debug("[SC] chyba logout")
         pass
示例#3
0
 def __del__(self):
     util.cache_cookies(self.cache)
 def __del__(self):
     util.cache_cookies(self.cache)
示例#5
0
                redir_url = response.info().getheader('location')
                if not redir_url.startswith('http'):
                    base_url = '%s://%s' % (scheme, domain)
                    redir_url = urlparse.urljoin(base_url, redir_url)

                request = urllib2.Request(redir_url)
                for key in headers:
                    request.add_header(key, headers[key])
                if cj is not None:
                    cj.add_cookie_header(request)

                response = urllib2.urlopen(request)
            final = response.read()
            if 'cf-browser-verification' in final:
                util.info('CF Failure: html: %s url: %s' % (html, url))
                tries += 1
                html = final
            else:
                break
        except urllib2.HTTPError, e:
            util.info('CloudFlare HTTP Error: %s on url: %s' % (e.code, url))
            return False
        except urllib2.URLError, e:
            util.info('CloudFlare URLError Error: %s on url: %s' % (e, url))
            return False

    if cj is not None:
        util.cache_cookies()

    return final
                if not redir_url.startswith('http'):
                    base_url = '%s://%s' % (scheme, domain)
                    redir_url = urlparse.urljoin(base_url, redir_url)

                request = urllib2.Request(redir_url)
                for key in headers:
                    request.add_header(key, headers[key])
                if cj is not None:
                    cj.add_cookie_header(request)

                response = urllib2.urlopen(request)
            final = response.read()
            if 'cf-browser-verification' in final:
                util.info('CF Failure: html: %s url: %s' % (html, url))
                tries += 1
                html = final
            else:
                break
        except urllib2.HTTPError, e:
            util.info('CloudFlare HTTP Error: %s on url: %s' % (e.code,
                      url))
            return False
        except urllib2.URLError, e:
            util.info('CloudFlare URLError Error: %s on url: %s' % (e,
                      url))
            return False

    if cj is not None:
        util.cache_cookies()

    return final
示例#7
0
def solve(url, cj, user_agent=None, wait=True):
    if user_agent is None:
        user_agent = util.UA
    headers = {'User-Agent': user_agent, 'Referer': url}
    if cj is not None:
        try:
            cj.load(ignore_discard=True)
        except:
            pass
        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
        urllib2.install_opener(opener)

    scheme = urlparse.urlparse(url).scheme
    domain = urlparse.urlparse(url).hostname
    request = urllib2.Request(url)
    for key in headers:
        request.add_header(key, headers[key])
    try:
        response = urllib2.urlopen(request)
        html = response.read()
    except urllib2.HTTPError as e:
        html = e.read()

    tries = 0
    while tries < MAX_TRIES:
        solver_pattern = \
            'var (?:s,t,o,p,b,r,e,a,k,i,n,g|t,r,a),f,\s*([^=]+)'
        solver_pattern += \
            '={"([^"]+)":([^}]+)};.+challenge-form\'\);'
        vc_pattern = \
            'input type="hidden" name="jschl_vc" value="([^"]+)'
        pass_pattern = 'input type="hidden" name="pass" value="([^"]+)'
        s_pattern = 'input type="hidden" name="s" value="([^"]+)'
        init_match = re.search(solver_pattern, html, re.DOTALL)
        vc_match = re.search(vc_pattern, html)
        pass_match = re.search(pass_pattern, html)
        s_match = re.search(s_pattern, html)

        if not init_match or not vc_match or not pass_match or not s_match:
            msg = \
                "[CF] Couldn't find attribute: init: |%s| vc: |%s| pass: |%s| No cloudflare check?"
            util.info(msg % (init_match, vc_match, pass_match))
            return False

        (init_dict, init_var, init_equation) = \
            init_match.groups()
        vc = vc_match.group(1)
        password = pass_match.group(1)
        s = s_match.group(1)

        equations = re.compile(r"challenge-form\'\);\s*(.*)a.v").findall(html)[0]
        # util.info("[CF] VC is: %s" % (vc))
        varname = (init_dict, init_var)
        # util.info('[CF] init: [{0}]'.format((init_equation.rstrip())))
        result = float(solve_equation(init_equation.rstrip()))
        util.info('[CF] Initial value: [ {0} ] Result: [ {1} ]'.format(init_equation,
                  result))

        for equation in equations.split(';'):
            equation = equation.rstrip()
            if len(equation) > len('.'.join(varname)):
                # util.debug('[CF] varname {0} line {1}'.format('.'.join(varname), equation))
                if equation[:len('.'.join(varname))] != '.'.join(varname):
                    util.info('[CF] Equation does not start with varname |%s|'
                              % equation)
                else:
                    equation = equation[len('.'.join(varname)):]

                expression = equation[2:]
                operator = equation[0]
                if operator not in ['+', '-', '*', '/']:
                    util.info('[CF] Unknown operator: |%s|' % equation)
                    continue

                result = float(str(eval(str(result) + operator + str(solve_equation(
                    expression)))))
                #util.info('[CF] intermediate: %s = %s' % (equation, result))

        #util.debug('[CF] POCET: {0} {1}'.format(result, len(domain)))
        result = '{0:.10f}'.format(eval('float({0} + {1})'.format(result, len(domain))))
        util.info('[CF] Final Result: |%s|' % result)

        if wait:
            util.info('[CF] Sleeping for 5 Seconds')
            xbmc.sleep(5000)

        url = \
            '%s://%s/cdn-cgi/l/chk_jschl?s=%s&jschl_vc=%s&pass=%s&jschl_answer=%s' \
            % (scheme, domain, urllib.quote(s), urllib.quote(vc), urllib.quote(password), urllib.quote(result))
        # util.info('[CF] url: %s' % url)
        # util.debug('[CF] headers: {0}'.format(headers))
        request = urllib2.Request(url)
        for key in headers:
            request.add_header(key, headers[key])

        try:
            opener = urllib2.build_opener(NoRedirection)
            urllib2.install_opener(opener)
            response = urllib2.urlopen(request)
            # util.info('[CF] code: {}'.format(response.getcode()))
            while response.getcode() in [301, 302, 303, 307]:
                if cj is not None:
                    cj.extract_cookies(response, request)

                redir_url = response.info().getheader('location')
                if not redir_url.startswith('http'):
                    base_url = '%s://%s' % (scheme, domain)
                    redir_url = urlparse.urljoin(base_url, redir_url)

                request = urllib2.Request(redir_url)
                for key in headers:
                    request.add_header(key, headers[key])
                if cj is not None:
                    cj.add_cookie_header(request)

                response = urllib2.urlopen(request)
            final = response.read()
            if 'cf-browser-verification' in final:
                util.info('[CF] Failure: html: %s url: %s' % (html, url))
                tries += 1
                html = final
            else:
                break
        except urllib2.HTTPError as e:
            util.info('[CF] HTTP Error: %s on url: %s' % (e.code,
                      url))
            return False
        except urllib2.URLError as e:
            util.info('[CF] URLError Error: %s on url: %s' % (e,
                      url))
            return False

    if cj is not None:
        util.cache_cookies()

    return final