Пример #1
0
def browse_repository(url):
    import requests, zipfile, StringIO
    from libs.BeautifulSoup import BeautifulSoup
    r = requests.get(url, stream=True)
    zip_ref = zipfile.ZipFile(StringIO.StringIO(r.content))
    for f in zip_ref.namelist():
        if f.endswith('addon.xml'):
            xml = BeautifulSoup(zip_ref.read(f))
            url = xml.find('info').text
            xml = BeautifulSoup(requests.get(url).text)
            return xml
    return False
def browse_repository(url):
	import requests, zipfile, StringIO
	from libs.BeautifulSoup import BeautifulSoup
	r = requests.get(url, stream=True)
	zip_ref = zipfile.ZipFile(StringIO.StringIO(r.content))
	for f in zip_ref.namelist():
		if f.endswith('addon.xml'):
			xml = BeautifulSoup(zip_ref.read(f))
			url = xml.find('info').text
			xml=BeautifulSoup(requests.get(url).text)
			return xml
	return False
Пример #3
0
def getRemoteVersion():
    global remote, remote_version, url, hash
    
    dp = xbmcgui.DialogProgress()
    dp.create('idolpx Installer', 
            'Checking for update...', 
            '', 
            'Please wait...')
    dp.update(100)

    try:
        # Prompt for Device ID if it is not set
        if not kodi.get_setting('deviceid'):
            kb = xbmc.Keyboard('default', 'heading')
            kb.setHeading('Enter your name or something so I know who you are \r\nand will allow you access to updates')
            kb.setDefault('')
            kb.setHiddenInput(False)
            kb.doModal()
            if (kb.isConfirmed()):
                kb_input = kb.getText()
                if (len(kb_input) > 3):
                    kodi.set_setting('deviceid', kb_input)
                    kodi.notify('Device ID set!', '['+kb_input+']')
                else:
                    kodi.notify('Access denied!', 'Device ID not set.')
                    return
            else:
                kodi.notify('Access denied!', 'Device ID not set.')
                return

        params = getParams()
        params['cv'] = current_version
        kodi.debug('Config URL: '+kodi.get_setting('update_url'))
        response = requests.get(kodi.get_setting('update_url'), params=params)
        remote = json.loads(response.text)
        kodi.debug(json.dumps(remote))

        if kodi.get_setting('update_test') != 'true':
            remote_version = remote['config_version']
            url = remote['config_url']
        else:
            remote_version = remote['test_version']
            url = remote['test_url']
        
        response = requests.get(url+'.md5')
        hash = response.text
        kodi.debug('MD5 HASH: '+hash)

    except Exception, e: 
        kodi.debug('getRemoteVersion: '+str(e))
Пример #4
0
def dir_check(url):
    return requests.get(url,
                        stream=True,
                        headers=headers,
                        timeout=timeout,
                        proxies=proxies,
                        allow_redirects=allow_redirects)
Пример #5
0
def UserLogin(request, facebook_token):
    """
    :param request: request object
    :param facebook_token: user facebook token
    :return: json with user data
    """
    # Get and save user data
    url = 'https://graph.facebook.com/me?access_token={0}'.format(facebook_token)
    profile_json = requests.get(url + '&fields=email,first_name,last_name').json()
    # Is user already logged in?
    if not 'facebook_id' in request.session:
        user = User.all().filter('email', profile_json['email'])
        if not user.count() > 0:
            user = User(
                first_name=profile_json['first_name'],
                last_name=profile_json['last_name'],
                email=profile_json['email'],
                facebook_token=facebook_token,
                facebook_id=profile_json['id']
            )
            user.put()
            logging.info('New user with facebook id: {0}'.format(user.facebook_id))
        else:
            user = user.get()
            logging.info('User logged in with facebook id: {0}'.format(user.facebook_id))
        request.session['facebook_id'] = user.facebook_id
    else:
        logging.info('User already logged in with facebook id: {0}'.format(request.session['facebook_id']))
    return HttpResponse(json.dumps(request.session['facebook_id']))
Пример #6
0
def UserLogin(request, facebook_token):
    """
    :param request: request object
    :param facebook_token: user facebook token
    :return: json with user data
    """
    # Get and save user data
    url = 'https://graph.facebook.com/me?access_token={0}'.format(
        facebook_token)
    profile_json = requests.get(url +
                                '&fields=email,first_name,last_name').json()
    # Is user already logged in?
    if not 'facebook_id' in request.session:
        user = User.all().filter('email', profile_json['email'])
        if not user.count() > 0:
            user = User(first_name=profile_json['first_name'],
                        last_name=profile_json['last_name'],
                        email=profile_json['email'],
                        facebook_token=facebook_token,
                        facebook_id=profile_json['id'])
            user.put()
            logging.info('New user with facebook id: {0}'.format(
                user.facebook_id))
        else:
            user = user.get()
            logging.info('User logged in with facebook id: {0}'.format(
                user.facebook_id))
        request.session['facebook_id'] = user.facebook_id
    else:
        logging.info('User already logged in with facebook id: {0}'.format(
            request.session['facebook_id']))
    return HttpResponse(json.dumps(request.session['facebook_id']))
def web_search(q):
	from HTMLParser import HTMLParser
	class MLStripper(HTMLParser):
		def __init__(self):
			self.reset()
			self.fed = []
		def handle_data(self, d):
			self.fed.append(d)
		def get_data(self):
			return ''.join(self.fed)

	def strip_tags(html):
		s = MLStripper()
		s.feed(html)
		return s.get_data()
	base_url = "https://github.com/search"
	q = "%s extension:zip language:Python path:addon.xml language:Python" % q
	params = {"q":q, "type":"Repositories", "ref":"advsearch"}
	results = {"items": []}
	r = requests.get(base_url, params=params)
	links = dom_parser.parse_dom(r.text, 'a', {"class": "v-align-middle"})
	for link in links:
		link = strip_tags(link)
		temp = link.split("/")
		results["items"] += [{"owner": {"login": temp[0]}, "name": temp[1], "full_name": link}]
	return results
def download(url, addon_id, destination, unzip=False, quiet=False):
	version = None
	filename = addon_id + '.zip'
	r = requests.get(url, stream=True)
	kodi.log("Download: %s" % url)
	
	
	
	if r.status_code == requests.codes.ok:
		temp_file = kodi.vfs.join(kodi.get_profile(), "downloads")
		if not kodi.vfs.exists(temp_file): kodi.vfs.mkdir(temp_file, recursive=True)
		temp_file = kodi.vfs.join(temp_file, filename)
		try:
			total_bytes = int(r.headers["Content-Length"])
		except:
			total_bytes = 0
		block_size = 1000
		cached_bytes = 0
		if not quiet:
			pb = xbmcgui.DialogProgress()
			pb.create("Downloading",filename,' ', ' ')
		kodi.sleep(150)
		start = time.time()
		with open(temp_file, 'wb') as f:
			for block in r.iter_content(chunk_size=block_size):
				if not block: break
				if not quiet and pb.iscanceled():
					raise downloaderException('Download Aborted')
					return False
				cached_bytes += len(block)
				f.write(block)
				if total_bytes > 0:
					delta = int(time.time() - start)
					if delta:
						bs = int(cached_bytes / (delta))
					else: bs = 0
					if not quiet:
						percent = int(cached_bytes * 100 / total_bytes)
						pb.update(percent, "Downloading",filename, format_status(cached_bytes, total_bytes, bs))
		
		if not quiet: pb.close()
		if unzip:
			zip_ref = zipfile.ZipFile(temp_file, 'r')
			zip_ref.extractall(destination)
			zip_ref.close()
			kodi.vfs.rm(temp_file, quiet=True)
			try:
				xml = kodi.vfs.read_file(kodi.vfs.join(destination, kodi.vfs.join(addon_id, 'addon.xml')), soup=True)
				version = get_version_by_xml(xml)
				if not version:
					version = get_version_by_name(filename)
			except:
				kodi.log("Unable to fine version from addon.xml for addon: %s" % addon_id)
		else:
			kodi.vfs.mv(temp_file, kodi.vfs.join(destination, filename))
	else:
		kodi.close_busy_dialog()
		raise downloaderException(r.status_code)
	return version
Пример #9
0
def call(uri, query=None, params=False, append_base=True, web=False):
    if web:
        r = requests.get(uri)
        if r.status_code == requests.codes.ok:
            r.encoding = 'utf-8'
            return r.text
        else:
            raise githubException("Status %s: %s" % (r.status_code, r.text))
    kodi.sleep(random.randint(50, 250))  # random delay 50-250 ms
    url = base_url + uri if append_base else uri
    if query is not None:
        query = urllib.urlencode(query)
        for r in [('%3A', ":"), ("%2B", "+")]:
            f, t = r
            query = query.replace(f, t)
        url = url + '?' + query
    if kodi.get_setting('github_key'):
        headers = {
            "Authorization": "token %s" % kodi.get_setting('github_key')
        }
    else:
        headers = {}

    if params:
        r = requests.get(url, params, headers=headers)
    else:
        r = requests.get(url, headers=headers)
    if r.status_code == requests.codes.ok:
        return r.json()
    elif r.status_code == 401:
        kodi.notify("Unauthorized", "Bad credentials")
        kodi.log(r.text)
        return None
    elif r.status_code == 403:
        import time
        retry = int(r.headers['X-RateLimit-Reset']) - int(time.time())
        kodi.notify("Rate limit exceeded", "Retry in %s" % retry)
        kodi.log(r.text)
        return None
    elif r.status_code == 422:
        kodi.notify("No results found", "Review search terms")
        kodi.log(r.text)
        return None
    else:
        kodi.close_busy_dialog()
        raise githubException("Status %s: %s" % (r.status_code, r.text))
Пример #10
0
def http_request_get(url, body_content_workflow=False):
	result = requests.get(url, 
		stream=body_content_workflow, 
		headers=headers, 
		timeout=timeout, 
		proxies=proxies,
		allow_redirects=allow_redirects)
	return result
Пример #11
0
 def getSubscribers(self):
     try:
         response = requests.get(self.__prefix + 'subscribers', headers=self.__header)
     except requests.ConnectionError:
         raise Exception("REST Server not found!")
     json_data = json.loads(response.text)
     print json.dumps(json_data, indent=2)
     return
Пример #12
0
def GetDoc(docID):
    # Construct full url from parameter and value
    url = config.DOCDB_URL + 'ShowDocument?docid=' + str(
        docID) + '&outformat=xml'

    # Make HTTP request
    response = requests.get(url, auth=('uboone', config.PWD))
    return xmltodict.parse(response.content)
Пример #13
0
def CallDocDB(function, parameter, value):
    # Construct full url from parameter and value
    url = config.DOCDB_URL + function + '?' + parameter + '=' + value + '&outformat=xml'

    # Make HTTP request
    response = requests.get(url, auth=('uboone', config.PWD))

    return xmltodict.parse(response.content)
Пример #14
0
 def response(self):
     try:
         response = requests.get(str(self))
         rjson = response.json()
         if not isinstance(rjson, dict):
             raise Exception(response.text)
         return rjson
     except Exception as e:
         raise ResponseFanartError(str(e))
Пример #15
0
def can_deploy(pr):
  url = "https://api.github.com/repos/%s/%s/pulls/%s" % (owner, repo, pr)
  req = requests.get(url, headers=headers)
  results = req.json()
  can_deploy = req.status_code == 200 and is_mergable(results) and is_target(results)
  if not can_deploy:
    return False
  else:
    return True
Пример #16
0
 def ping(self):
     try:
         response = requests.get(self.__prefix + 'ping', headers=self.__header)
     except requests.ConnectionError:
         raise Exception("REST Server not found!")
     if response.status_code == 200:
         json_data = json.loads(response.text)['data']
         return True
     return False
Пример #17
0
 def response(self):
     try:
         response = requests.get(str(self))
         rjson = response.json()
         if not isinstance(rjson, dict):
             raise Exception(response.text)
         return rjson
     except Exception as e:
         raise ResponseFanartError(str(e))
Пример #18
0
    def process_media(self, post_proc, destination):

        if post_proc == "couchpotato":
            ssl = config.getboolean("CouchPotato", "ssl") if config.getboolean("CouchPotato", "ssl") else False
            host = config.get("CouchPotato", "host") if config.get("CouchPotato", "host") else 'localhost'
            port = config.get("CouchPotato", "port") if config.get("CouchPotato", "port") else 5050
            base_url = config.get("CouchPotato", "base_url") if config.get("CouchPotato", "base_url") else ''
            api_key = config.get("CouchPotato", "apikey")
            api_call = "/renamer.scan/?async=1&movie_folder="

            user = config.get("CouchPotato", "username") if config.get("CouchPotato", "username") else ''
            password = config.get("CouchPotato", "password") if config.get("CouchPotato", "username") else ''

        elif post_proc == "sickbeard":
            ssl = config.getboolean("Sickbeard", "ssl") if config.getboolean("Sickbeard", "ssl") else False
            host = config.get("Sickbeard", "host") if config.get("Sickbeard", "port") else 'localhost'
            port = config.get("Sickbeard", "port") if config.get("Sickbeard", "port") else 8081
            base_url = config.get("Sickbeard", "base_url") if config.get("Sickbeard", "baseURL") else ''
            api_key = config.get("Sickbeard", "apikey")
            api_call = "/home/postprocess/processEpisode?quiet=1&dir="

            user = config.get("Sickbeard", "username") if config.get("Sickbeard", "username") else ''
            password = config.get("Sickbeard", "password") if config.get("Sickbeard", "password") else ''

        else:
            return

        if not host.endswith(':'):
            host += ':'

        if not port.endswith('/'):
            port += '/'

        if base_url:
            if base_url.startswith('/'):
                base_url.replace('/', '')
            if not base_url.endswith('/'):
                base_url += '/'

        if ssl:
            protocol = "https://"
        else:
            protocol = "http://"

        if api_key:
            url = protocol + host + port + base_url + "api/" + api_key + api_call + destination
        else:
            url = protocol + host + port + base_url + api_call + destination

        try:
            r = requests.get(url, auth=(user, password))
            logger.debug(loggerHeader + "Postprocessing with %s :: Opening URL: %s", post_proc, url)
        except Exception, e:
            logger.error(loggerHeader + "Tried postprocessing with %s :: Unable to open URL: %s %s %s",
                         (post_proc, url, e, traceback.format_exc()))
            raise
Пример #19
0
 def getComponenets(self):
     try:
         response = requests.get(self.__prefix + 'components', headers=self.__header)
     except requests.ConnectionError:
         raise Exception("REST Server not found!")
     components = []
     json_data = json.loads(response.text)
     for component in json_data['data']:
         components.append(component)
     return components
Пример #20
0
def http_request_get(url, body_content_workflow=False):
    result = requests.get(
        url,
        stream=body_content_workflow,
        headers=headers,
        timeout=timeout,
        proxies=proxies,
        allow_redirects=allow_redirects,
    )
    return result
Пример #21
0
 def scan(self):
     while not self.urllist.empty():
         self.scan_url = self.scan_target + self.urllist.get()
         try:
             r = requests.get(self.scan_url, timeout=self.scan_timeout, headers=self.headers, allow_redirects=False)
             # print r.url
             if r.status_code == 200 or r.status_code == self.scan_status:
                 print '[' + str(r.status_code) + ']' + " " + r.url
         except Exception, e:
             pass
Пример #22
0
def http_request_get(url, body_content_workflow=False, allow_redirects=allow_redirects):
	try:
		result = requests.get(url, 
			stream=body_content_workflow, 
			headers=headers, 
			timeout=timeout, 
			proxies=proxies,
			allow_redirects=allow_redirects)
		return result
	except Exception, e:
		return None
Пример #23
0
def OPEN_URL(url):
    headers = {
        'user-agent':
        'Mozilla/5.0 (Linux; U; Android 4.2.2; en-us; AFTB Build/JDQ39) AppleWebKit/534.30'
        '(KHTML, like Gecko) Version/4.0 Mobile Safari/534.30'
    }
    try:
        r = requests.get(url, headers=headers)
        if r.status_code == requests.codes.ok:
            return r.text
    except:
        return ''
Пример #24
0
def http_request_get(url, body_content_workflow=False, allow_redirects=allow_redirects):
	try:
		result = requests.get(url, 
			stream=body_content_workflow, 
			headers=headers, 
			timeout=timeout, 
			proxies=proxies,
			allow_redirects=allow_redirects)
		return result
	except Exception, e:
		# 返回空的requests结果对象
		return __requests__.models.Response()
Пример #25
0
		def sr_resolver(unmet):
			url = 'https://cdimage.debian.org/mirror/addons.superrepo.org/v7/addons/%s' % unmet
			response = requests.get(url)
			if response.status_code == 200:
				for match in re.finditer('href="([^"]+)"', response.text):
					if match.group(1).endswith('zip'):
						f = match.group(1)
						dep_url = url + '/' + f
						self.met_addons.append(unmet)
						self.sources[unmet] = {"type": SOURCES.ZIP, "url": dep_url}
						kodi.log("%s dependency met in %s" % (unmet, dep_url))
						return True
			return False		
Пример #26
0
def http_request_get(url, body_content_workflow=False, allow_redirects=allow_redirects):
	try:
		result = requests.get(url, 
			stream=body_content_workflow, 
			headers=headers, 
			timeout=timeout, 
			proxies=proxies,
			allow_redirects=allow_redirects,
			verify=allow_ssl_verify)
		return result
	except Exception, e:
		# 返回空的requests结果对象
		return __requests__.models.Response()
Пример #27
0
def _call(url,
          params=None,
          headers=Default_Headers,
          verify_ssl=True,
          timeout=default_timeout):
    r = requests.get(base_url + url,
                     params=params,
                     headers=headers,
                     verify=verify_ssl,
                     allow_redirects=True,
                     timeout=timeout)
    print '\t\tr = ' + str(r)
    print '\t\turl = ' + str(base_url + url)
    result = r.json()
    return result
Пример #28
0
 def get(self, request, *args, **kwargs):
     """
     :return: json
     """
     user = User.all().filter('facebook_id', request.session['facebook_id']).get()
     url = 'https://graph.facebook.com/me/friends?access_token={0}'.format(user.facebook_token)
     friends_json = requests.get(url + '&fields=first_name,last_name').json()['data']
     friends = []
     for friend in friends_json:
         if User.all().filter('facebook_id', friend['id']).count() > 0:
             # Create user json and save friend to list
             friend = User.all().filter('facebook_id', friend['id']).get()
             friend = create_user_json(friend)
             friends.append(friend)
     return HttpResponse(json.dumps(friends), content_type="application/json")
Пример #29
0
def special_addons(query):
    base = special_path
    if query == 'featured':
        area = '/featuredAddons.json'
    if query == 'live':
        area = '/livetvAddons.json'
    if query == 'playlists':
        area = '/playlistsAddons.json'
    if query == 'sports':
        area = '/sportsAddons.json'
    feat = []
    links = requests.get(base+area)
    link = links.json()
    for a in link['addons']:
        feat.append(a)
    return feat
Пример #30
0
def special_addons(query):
    base = special_path
    if query == 'featured':
        area = '/featuredAddons.json'
    if query == 'live':
        area = '/livetvAddons.json'
    if query == 'playlists':
        area = '/playlistsAddons.json'
    if query == 'sports':
        area = '/sportsAddons.json'
    feat = []
    links = requests.get(base + area)
    link = links.json()
    for a in link['addons']:
        feat.append(a)
    return feat
Пример #31
0
def checkWaf(url, header="", proxy="", timeout=5, allow_redirects=False):
    payload = '/cdxy.old/.svn/.bashrc/.mdb/.inc/etc/passwd'
    retVal = False
    retVal1 = False
    infoMsg = "checking if the target is protected by \n"
    infoMsg += "some kind of WAF/IPS/IDS\n"
    CLIOutput().printInfo(infoMsg)

    try:
        code = requests.get(url, stream=True, headers=header, timeout=timeout,
                            proxies=proxy,
                            allow_redirects=allow_redirects).status_code
        if code != 200:
            retVal = True
    except Exception, e:
        print e
        retVal = True
Пример #32
0
def download(url, filename, destination, unzip=False):
    r = requests.get(url, stream=True)
    kodi.log("Download: %s" % url)
    if r.status_code == requests.codes.ok:
        temp_file = kodi.vfs.join(kodi.get_profile(), "downloads")
        if not kodi.vfs.exists(temp_file):
            kodi.vfs.mkdir(temp_file, recursive=True)
        temp_file = kodi.vfs.join(temp_file, filename)
        try:
            total_bytes = int(r.headers["Content-Length"])
        except:
            total_bytes = 0
        block_size = 1000
        cached_bytes = 0
        pb = xbmcgui.DialogProgress()
        pb.create("Downloading", filename, ' ', ' ')
        kodi.sleep(150)
        start = time.time()
        with open(temp_file, 'wb') as f:
            for block in r.iter_content(chunk_size=block_size):
                if not block: break
                if pb.iscanceled():
                    return False
                cached_bytes += len(block)
                f.write(block)
                if total_bytes > 0:
                    delta = int(time.time() - start)
                    if delta:
                        kbs = int(cached_bytes / (delta * 1000))
                    else:
                        kbs = 0
                    percent = int(cached_bytes * 100 / total_bytes)
                    pb.update(percent, "Downloading", filename,
                              format_speed(kbs))
        pb.close()
        if unzip:
            zip_ref = zipfile.ZipFile(temp_file, 'r')
            zip_ref.extractall(destination)
            zip_ref.close()
            kodi.vfs.rm(temp_file, quiet=True)
        else:
            kodi.vfs.mv(temp_file, kodi.vfs.join(destination, filename))
    else:
        kodi.close_busy_dialog()
        raise downloaderException(r.status_code)
    return True
Пример #33
0
def checkWaf(url, header="", proxy="", timeout=5, allow_redirects=False):
    payload = '/cdxy.old/.svn/.bashrc/.mdb/.inc/etc/passwd'
    retVal = False
    retVal1 = False
    infoMsg = "checking if the target is protected by \n"
    infoMsg += "some kind of WAF/IPS/IDS\n"
    CLIOutput().printInfo(infoMsg)

    try:
        code = requests.get(url, stream=True, headers=header, timeout=timeout,
                            proxies=proxy,
                            allow_redirects=allow_redirects).status_code
        if code != 200:
            retVal = True
    except Exception, e:
        print e
        retVal = True
Пример #34
0
 def get(self, request, *args, **kwargs):
     """
     :return: json
     """
     user = User.all().filter('facebook_id',
                              request.session['facebook_id']).get()
     url = 'https://graph.facebook.com/me/friends?access_token={0}'.format(
         user.facebook_token)
     friends_json = requests.get(
         url + '&fields=first_name,last_name').json()['data']
     friends = []
     for friend in friends_json:
         if User.all().filter('facebook_id', friend['id']).count() > 0:
             # Create user json and save friend to list
             friend = User.all().filter('facebook_id', friend['id']).get()
             friend = create_user_json(friend)
             friends.append(friend)
     return HttpResponse(json.dumps(friends),
                         content_type="application/json")
Пример #35
0
def send_document(chat, title, url):
    try:
        file = requests.get(url)
    except:
        print('Error getting file')

    try:
        headers = 'Content-Type: multipart/form-data'
        im = 'https://api.telegram.org/bot{}/sendDocument'.format(TOKEN_TG)
        r = requests.post(im,
                          data={'chat_id': chat},
                          files={'document': (title, file.content)})
    except:
        print('Error getting updates')
        return False

    if not r.status_code == 200:
        print('Error. Can\'t send doc')
        return False
    if not r.json()['ok']: return False
Пример #36
0
def web_search(q):
    from HTMLParser import HTMLParser

    class MLStripper(HTMLParser):
        def __init__(self):
            self.reset()
            self.fed = []

        def handle_data(self, d):
            self.fed.append(d)

        def get_data(self):
            return ''.join(self.fed)

    def strip_tags(html):
        s = MLStripper()
        s.feed(html)
        return s.get_data()

    base_url = "https://github.com/search"
    q = "%s extension:zip language:Python path:addon.xml language:Python" % q
    params = {"q": q, "type": "Repositories", "ref": "advsearch"}
    results = {"items": []}
    r = requests.get(base_url, params=params)
    links = dom_parser.parse_dom(r.text, 'a', {"class": "v-align-middle"})
    for link in links:
        link = strip_tags(link)
        temp = link.split("/")
        results["items"] += [{
            "owner": {
                "login": temp[0]
            },
            "name": temp[1],
            "full_name": link
        }]
    return results
Пример #37
0
    infoMsg += "some kind of WAF/IPS/IDS\n"
    CLIOutput().printInfo(infoMsg)

    try:
        code = requests.get(url, stream=True, headers=header, timeout=timeout,
                            proxies=proxy,
                            allow_redirects=allow_redirects).status_code
        if code != 200:
            retVal = True
    except Exception, e:
        print e
        retVal = True

    try:
        code1 = requests.get(url + payload, stream=True, headers=header, timeout=timeout,
                             proxies=proxy,
                             allow_redirects=allow_redirects).status_code
        if code1 != 404:
            retVal1 = True
    except Exception, e:
        print e
        retVal1 = True

    if retVal:
        warnMsg = 'Target URL not stable\n'
        warnMsg += '[' + str(code) + '] ' + url + '\n'
        CLIOutput().printWarning(warnMsg)

        message = "are you sure that you want to \n"
        message += "continue with further fuzzing? [y/N] \n"
        CLIOutput().printNewLine(message)
Пример #38
0
def system_info():
    systime = xbmc.getInfoLabel('System.Time ')
    dns1 = xbmc.getInfoLabel('Network.DNS1Address')
    gateway = xbmc.getInfoLabel('Network.GatewayAddress')
    ipaddy = xbmc.getInfoLabel('Network.IPAddress')
    linkstate = xbmc.getInfoLabel('Network.LinkState').replace("Link:", "")
    freespace, totalspace = maintool.get_free_space_mb(
        os.path.join(xbmc.translatePath('special://home')))
    freespace = maintool.convert_size(freespace) + ' Free'
    totalspace = maintool.convert_size(totalspace) + ' Total'
    screenres = xbmc.getInfoLabel('system.screenresolution')
    freemem = xbmc.getInfoLabel('System.FreeMemory')

    # FIND WHAT VERSION OF KODI IS RUNNING
    xbmc_version = xbmc.getInfoLabel("System.BuildVersion")
    versioni = xbmc_version[:4]
    VERSIONS = {
        10: 'Dharma',
        11: 'Eden',
        12: 'Frodo',
        13: 'Gotham',
        14: 'Helix',
        15: 'Isengard',
        16: 'Jarvis',
        17: 'Krypton'
    }
    codename = VERSIONS.get(int(xbmc_version[:2]))

    # Get External IP Address
    try:
        ext_ip = ("blue", requests.get('https://api.ipify.org').text)
    except Exception:
        ext_ip = ("red", "IP Check Not Available")

    # Get Python Version
    pv = sys.version_info

    # System Information Menu
    kodi.addItem(
        '[COLOR ghostwhite]Version: [/COLOR][COLOR lime] %s %s[/COLOR]' %
        (codename, versioni),
        '',
        100,
        artwork + 'icon.png',
        "",
        description=" ")
    kodi.addItem(
        '[COLOR ghostwhite]System Time: [/COLOR][COLOR lime] %s[/COLOR]' %
        systime,
        '',
        100,
        artwork + 'icon.png',
        "",
        description=" ")
    kodi.addItem('[COLOR ghostwhite]Gateway: [/COLOR][COLOR blue] %s[/COLOR]' %
                 gateway,
                 '',
                 100,
                 artwork + 'icon.png',
                 "",
                 description=" ")
    kodi.addItem(
        '[COLOR ghostwhite]Local IP: [/COLOR][COLOR blue] %s[/COLOR]' % ipaddy,
        '',
        100,
        artwork + 'icon.png',
        "",
        description=" ")
    kodi.addItem(
        '[COLOR ghostwhite]External IP: [/COLOR][COLOR %s] %s[/COLOR]' %
        ext_ip,
        '',
        100,
        artwork + 'icon.png',
        "",
        description=" ")
    kodi.addItem('[COLOR ghostwhite]DNS 1: [/COLOR][COLOR blue] %s[/COLOR]' %
                 dns1,
                 '',
                 100,
                 artwork + 'icon.png',
                 "",
                 description=" ")
    kodi.addItem('[COLOR ghostwhite]Network: [/COLOR][COLOR gold] %s[/COLOR]' %
                 linkstate,
                 '',
                 100,
                 artwork + 'icon.png',
                 "",
                 description=" ")
    kodi.addItem(
        '[COLOR ghostwhite]Disc Space: [/COLOR][COLOR gold] %s[/COLOR]' %
        totalspace,
        '',
        100,
        artwork + 'icon.png',
        "",
        description=" ")
    kodi.addItem(
        '[COLOR ghostwhite]Disc Space: [/COLOR][COLOR gold] %s[/COLOR]' %
        freespace,
        '',
        100,
        artwork + 'icon.png',
        "",
        description=" ")
    kodi.addItem(
        '[COLOR ghostwhite]Free Memory: [/COLOR][COLOR gold] %s[/COLOR]' %
        freemem,
        '',
        100,
        artwork + 'icon.png',
        "",
        description=" ")
    kodi.addItem(
        '[COLOR ghostwhite]Resolution: [/COLOR][COLOR gold] %s[/COLOR]' %
        screenres,
        '',
        100,
        artwork + 'icon.png',
        "",
        description=" ")
    kodi.addItem(
        '[COLOR ghostwhite]Python Version: [/COLOR][COLOR lime] %d.%d.%d[/COLOR]'
        % (pv[0], pv[1], pv[2]),
        '',
        100,
        artwork + 'icon.png',
        "",
        description=" ")
    viewsetter.set_view("files")
Пример #39
0
        code = requests.get(url,
                            stream=True,
                            headers=header,
                            timeout=timeout,
                            proxies=proxy,
                            allow_redirects=allow_redirects).status_code
        if code != 200:
            retVal = True
    except Exception, e:
        print e
        retVal = True

    try:
        code1 = requests.get(url + payload,
                             stream=True,
                             headers=header,
                             timeout=timeout,
                             proxies=proxy,
                             allow_redirects=allow_redirects).status_code
        if code1 != 404:
            retVal1 = True
    except Exception, e:
        print e
        retVal1 = True

    if retVal:
        warnMsg = 'Target URL not stable\n'
        warnMsg += '[' + str(code) + '] ' + url + '\n'
        CLIOutput().printWarning(warnMsg)

        message = "are you sure that you want to \n"
        message += "continue with further fuzzing? [y/N] \n"
Пример #40
0
                print u'Noeud désactivé.'
            else:
                print u'Active: ' + node['active']
                print u'Source: ' + node['src_domain'] + node['src_path']
                print u'Destination: ' + node['dst_path']
                print u'Pattern: ' + node['pattern'] % node['src_path']
                
                src_url = node['src_domain'] + node['src_path']
                pattern = node['pattern'] % node['src_path']
                
                # Remove dst directory and recreate it (empty)
                if os.path.isdir(node['dst_path']):
                    shutil.rmtree(node['dst_path'])
                os.mkdir(node['dst_path'])
                
                r = requests.get(src_url)

                print u'Start: ' + str(time.strftime("%Y-%m-%d %H:%M:%S"))
                
                for filename in re.findall(pattern, r.text):
                    r = requests.get(src_url+filename)
                    with open(node['dst_path']+filename, 'w') as f:
                        f.write(r.text.encode('utf-8'))
                    print '=> ' + filename + bcolors.OKGREEN + u' [OK]' + bcolors.ENDC

                print u'End: ' + str(time.strftime("%Y-%m-%d %H:%M:%S"))

                count_node += 1
                
        count_file += 1
        
Пример #41
0
def call(uri,
         query=None,
         params=False,
         append_base=True,
         web=False,
         page=1,
         cache_limit=0):
    if web:
        r = requests.get(uri)
        if r.status_code == requests.codes.ok:
            r.encoding = 'utf-8'
            return r.text
        else:
            raise githubException("Status %s: %s" % (r.status_code, r.text))

    url = base_url + uri if append_base else uri
    if query is None:
        query = {'page': 1}
    else:
        query['page'] = page
    if query is not None:
        _query = urllib.urlencode(query)
        for r in [('%3A', ":"), ("%2B", "+")]:
            f, t = r
            _query = _query.replace(f, t)
        url = url + '?' + _query
    if kodi.get_setting('github_key'):
        headers = {
            "Authorization": "token %s" % kodi.get_setting('github_key')
        }
    else:
        headers = {}
    cached, current_page, total_pages = _get_cached_response(url, cache_limit)
    if cached:
        return cached
    kodi.sleep(random.randint(100, 250))  # random delay 50-250 ms
    if params:
        r = requests.get(url, params, headers=headers)
    else:
        r = requests.get(url, headers=headers)
    if r.status_code == requests.codes.ok:
        results = r.json()
        total_count = float(results['total_count'])
        results['page_count'] = int(math.ceil(total_count / page_limit))
        page_count = int(results['page_count'])
        if page_count > 1 and page == 1:
            for p in range(page + 1, int(page_count + 1)):
                kodi.sleep(500)
                temp = call(uri,
                            query=query,
                            params=params,
                            append_base=append_base,
                            web=web,
                            page=p,
                            cache_limit=cache_limit)
                results['items'] += temp['items']
        _cache_response(url, results, page, results['page_count'])
        return results
    elif r.status_code == 401:
        kodi.notify("Unauthorized", "Bad credentials")
        kodi.log(r.text)
        return None
    elif r.status_code == 403 and 'X-RateLimit-Reset' in r.headers:
        import time
        retry = int(r.headers['X-RateLimit-Reset']) - int(time.time())
        for delay in range(retry, 0, -1):
            kodi.notify("API Rate limit exceeded",
                        "Retry in %s seconds(s)" % delay,
                        timeout=1000)
            kodi.sleep(1000)
        kodi.log(r.text)
        return call(uri,
                    query=query,
                    params=params,
                    append_base=append_base,
                    web=web,
                    page=page,
                    cache_limit=cache_limit)
    elif r.status_code == 422:
        kodi.notify("No results found", "Review search terms")
        kodi.log(r.text)
        return None
    else:
        kodi.close_busy_dialog()
        raise githubException("Status %s: %s" % (r.status_code, r.text))
Пример #42
0
import libs.requests as requests

sites = [['http://github.com', 0.02, 10.02], ['http://google.com', 20, 2]]
for site in sites:
    try:
        r = requests.get(site[0], timeout=(site[1], site[2]))

        print site[0] + " in " + str(r.elapsed)
    except requests.exceptions.RequestException as e:
        print(e.message)
        pass
Пример #43
0
def download_with_resume(url, file_path, callback=None, hash=None, timeout=10):
    """
    Performs a HTTP(S) download that can be restarted if prematurely terminated.
    The HTTP server must support byte ranges.
 
    :param file_path: the path to the file to write to disk
    :type file_path:  string
    :param hash: hash value for file validation
    :type hash:  string (MD5 hash value)
    """
    # don't download if the file exists
    if os.path.exists(file_path):
        kodi.log('File already downloaded.')
        return True

    try:
        block_size = 1000 * 1000  # 1MB
        filename = url.split('/')[-1]
        tmp_file_path = file_path + '.part'
        first_byte = os.path.getsize(tmp_file_path) if os.path.exists(
            tmp_file_path) else 0
        last_byte = first_byte
        file_mode = 'ab' if first_byte else 'wb'
        file_size = -1

        file_size = int(requests.head(url).headers['Content-length'])
        kodi.log('File size is %s' % file_size)
        kodi.log('Starting at %s' % first_byte)
        kodi.log('File Mode %s' % file_mode)

        # If tmp_file is bigger then something is screwy. Start over.
        if first_byte > file_size:
            kodi.log('File bigger. Starting over.')
            os.remove(tmp_file_path)
            first_byte = 0

        headers = {"Range": "bytes=%s-" % first_byte}
        r = requests.get(url, headers=headers, stream=True)
        with open(tmp_file_path, file_mode) as f:
            for chunk in r.iter_content(chunk_size=block_size):
                if chunk:  # filter out keep-alive new chunks
                    f.write(chunk)

                    if callback:
                        last_byte = last_byte + block_size \
                            if last_byte < file_size \
                            else file_size

                        # Update dialog
                        percent = callback(filename, last_byte, file_size)
                        if percent == -1:
                            kodi.log('Pausing transfer!')
                            return False

                        if percent % 10 == 0:
                            kodi.log('Download @ ' + str(percent) + '%')

    except IOError as e:
        kodi.log('IO Error - %s' % e)
        return False

    except Exception, e:
        kodi.log(str(e))
        return False
Пример #44
0
def _call(url, params=None, headers=Default_Headers, verify_ssl=True, timeout=default_timeout):
    r = requests.get(base_url+url, params=params, headers=headers, verify=verify_ssl, allow_redirects=True, timeout=timeout)
    print '\t\tr = ' + str(r)
    print '\t\turl = ' + str(base_url+url)
    result = r.json()
    return result
Пример #45
0
def dir_check(url):
	return requests.get(url, stream=True, headers=headers, timeout=timeout, proxies=proxies, allow_redirects=allow_redirects)
Пример #46
0
import libs.requests as requests

sites = [
    ['http://github.com',0.02,10.02],
    ['http://google.com',20,2]
]
for site in sites:
    try:
        r = requests.get(site[0], timeout=(site[1],site[2]))

        print site[0] + " in " + str(r.elapsed)
    except requests.exceptions.RequestException as e:
        print(e.message)
        pass
Пример #47
0
def Download(url, destination):
    r = requests.get(url, auth=('uboone', config.PWD))
    with open(destination, "wb") as dest:
        dest.write(r.content)
Пример #48
0
        else:
            kodi.log('Not Playing!')

            # Check for update
            kodi.log('Check for Update.')

            # Get Remote Settings
            try:
                if kodi.get_setting('update_test') != 'true':
                    current_version = current['config_version']
                else:
                    current_version = current['test_version']

                params = getParams()
                params['cv'] = current_version
                response = requests.get(kodi.get_setting('update_url'),
                                        params=params)
                remote = json.loads(response.text)

                # If kodi version is different on server then execute installer
                if kodi.get_setting('update_kodi') == 'true':
                    if kodi.platform() == 'android' and remote[
                            'kodi_version'] != kodi.get_version():

                        # Start idolpx Installer
                        kodi.execute('XBMC.RunScript(' + addon_id + ')', True)

                if kodi.get_setting('update_test') != 'true':
                    remote_version = remote['config_version']
                    url = remote['config_url']
                else:
                    remote_version = remote['test_version']
Пример #49
0
def download(url, addon_id, destination, unzip=False, quiet=False):
    version = None
    filename = addon_id + '.zip'
    r = requests.get(url, stream=True)
    kodi.log("Download: %s" % url)

    if r.status_code == requests.codes.ok:
        temp_file = kodi.vfs.join(kodi.get_profile(), "downloads")
        if not kodi.vfs.exists(temp_file):
            kodi.vfs.mkdir(temp_file, recursive=True)
        temp_file = kodi.vfs.join(temp_file, filename)
        try:
            total_bytes = int(r.headers["Content-Length"])
        except:
            total_bytes = 0
        block_size = 1000
        cached_bytes = 0
        if not quiet:
            pb = xbmcgui.DialogProgress()
            pb.create("Downloading", filename, ' ', ' ')
        kodi.sleep(150)
        start = time.time()
        with open(temp_file, 'wb') as f:
            for block in r.iter_content(chunk_size=block_size):
                if not block: break
                if not quiet and pb.iscanceled():
                    raise downloaderException('Download Aborted')
                    return False
                cached_bytes += len(block)
                f.write(block)
                if total_bytes > 0:
                    delta = int(time.time() - start)
                    if delta:
                        bs = int(cached_bytes / (delta))
                    else:
                        bs = 0
                    if not quiet:
                        percent = int(cached_bytes * 100 / total_bytes)
                        pb.update(percent, "Downloading", filename,
                                  format_status(cached_bytes, total_bytes, bs))

        if not quiet: pb.close()
        if unzip:
            zip_ref = zipfile.ZipFile(temp_file, 'r')
            zip_ref.extractall(destination)
            zip_ref.close()
            kodi.vfs.rm(temp_file, quiet=True)
            try:
                xml = kodi.vfs.read_file(kodi.vfs.join(
                    destination, kodi.vfs.join(addon_id, 'addon.xml')),
                                         soup=True)
                version = get_version_by_xml(xml)
                if not version:
                    version = get_version_by_name(filename)
            except:
                kodi.log(
                    "Unable to fine version from addon.xml for addon: %s" %
                    addon_id)
        else:
            kodi.vfs.mv(temp_file, kodi.vfs.join(destination, filename))
    else:
        kodi.close_busy_dialog()
        raise downloaderException(r.status_code)
    return version
def call(uri, query=None, params=False, append_base=True, web=False, page=1, cache_limit=0):
	if web:
		r = requests.get(uri)
		if r.status_code == requests.codes.ok:
			r.encoding = 'utf-8'
			return r.text
		else:
			raise githubException("Status %s: %s" % (r.status_code, r.text))
	
	url = base_url + uri if append_base else uri
	if query is None:
		query = {'page': 1}
	else:
		query['page'] = page
	if query is not None:
		_query = urllib.urlencode(query)
		for r in [('%3A', ":"), ("%2B", "+")]:
			f,t = r
			_query = _query.replace(f,t)
		url = url + '?' + _query
	if kodi.get_setting('github_key'):
		headers = {"Authorization": "token %s" % kodi.get_setting('github_key')}
	else:
		headers = {}
	cached, current_page, total_pages = _get_cached_response(url, cache_limit)
	if cached:
		return cached
	kodi.sleep(random.randint(100, 250)) # random delay 50-250 ms
	if params:
		r = requests.get(url, params, headers=headers)
	else:
		r = requests.get(url, headers=headers)
	if r.status_code == requests.codes.ok:
		results = r.json()
		total_count = float(results['total_count'])
		results['page_count'] = int(math.ceil(total_count / page_limit))
		page_count = int(results['page_count'])
		if page_count > 1 and page == 1:
			for p in range(page+1, int(page_count+1)):
				kodi.sleep(500)
				temp = call(uri, query=query, params=params, append_base=append_base, web=web, page=p, cache_limit=cache_limit)
				results['items'] += temp['items']
		_cache_response(url, results, page, results['page_count'])
		return results
	elif r.status_code == 401:
		kodi.notify("Unauthorized", "Bad credentials")
		kodi.log(r.text)
		return None
	elif r.status_code == 403 and 'X-RateLimit-Reset' in r.headers:
		import time
		retry = int(r.headers['X-RateLimit-Reset']) - int(time.time())
		for delay in range(retry, 0, -1):
			kodi.notify("API Rate limit exceeded", "Retry in %s seconds(s)" % delay, timeout=1000)
			kodi.sleep(1000)
		kodi.log(r.text)
		return call(uri, query=query, params=params, append_base=append_base, web=web, page=page, cache_limit=cache_limit)
	elif r.status_code == 422:
		kodi.notify("No results found", "Review search terms")
		kodi.log(r.text)
		return None
	else:
		kodi.close_busy_dialog()
		raise githubException("Status %s: %s" % (r.status_code, r.text))
Пример #51
0
 def content(self):
     if not self._content:
         self._content = requests.get(self.url).content
     return self._content
Пример #52
0
def main():
    dp = xbmcgui.DialogProgress()
    dp.create('idolpx Installer', 'Checking for update...', '',
              'Please wait...')
    dp.update(100)

    # Get Current Version
    update_file = xbmc.translatePath(os.path.join('special://',
                                                  'home')) + 'update.zip'

    current = json.loads(
        '{"config_version": "00000000","test_version": "00000000"}')
    path = xbmc.translatePath(os.path.join('special://', 'userdata'))
    version_file = path + 'version.json'
    try:
        current = json.load(open(version_file))
    except:
        pass

    # Get Remote Settings
    try:
        # Prompt for Device ID if it is not set
        if not kodi.get_setting('deviceid'):
            kb = xbmc.Keyboard('default', 'heading')
            kb.setHeading(
                'Enter your name or something so I know who you are \r\nand will allow you access to updates'
            )
            kb.setDefault('')
            kb.setHiddenInput(False)
            kb.doModal()
            if (kb.isConfirmed()):
                kb_input = kb.getText()
                if (len(kb_input) > 3):
                    kodi.set_setting('deviceid', kb_input)
                    kodi.notify('Device ID set!', '[' + kb_input + ']')
                else:
                    kodi.notify('Access denied!', 'Device ID not set.')
                    return
            else:
                kodi.notify('Access denied!', 'Device ID not set.')
                return

        # Prompt for Configuration Update
        if kodi.get_setting('update_test') != 'true':
            current_version = current['config_version']
        else:
            current_version = current['test_version']

        params = {
            'd': kodi.getInfoLabel('Network.MacAddress'),
            'os': kodi.getInfoLabel('System.OSVersionInfo'),
            'id': kodi.get_setting('deviceid'),
            'kv': kodi.get_version()
        }

        params['cv'] = current_version
        kodi.log('Config URL: ' + kodi.get_setting('update_url'))
        response = requests.get(kodi.get_setting('update_url'), params=params)
        remote = json.loads(response.text)
        kodi.log(json.dumps(remote))
        dp.close()

        if kodi.get_setting('update_test') != 'true':
            remote_version = remote['config_version']
            url = remote['config_url']
            hash = remote['config_md5']
        else:
            remote_version = remote['test_version']
            url = remote['test_url']
            hash = remote['test_md5']

        # Prompt for Kodi Update
        if kodi.get_setting('update_kodi') == 'true':
            if kodi.platform(
            ) == 'android' and remote['kodi_version'] != kodi.get_version():
                choice = xbmcgui.Dialog().yesno(
                    'idolpx Installer', 'A new version of Kodi is available!',
                    'Current version is [B]' + kodi.get_version() +
                    '[/B].[CR]', 'Would you like to install version [B]' +
                    remote['kodi_version'] + '[/B]?')
                if choice == 1:
                    installer.installAPK(remote['kodi_url'])

        kodi.log('Update File: ' + update_file)
        if os.path.exists(update_file):
            url = '/update.zip'
            hash = ''
            choice = xbmcgui.Dialog().yesno(
                'idolpx Installer', 'An update file exists!', '',
                'Would you like to install this update?')
        else:
            if remote_version != current_version:
                choice = xbmcgui.Dialog().yesno(
                    'idolpx Installer', 'A new configuration is available!',
                    'Current version is [B]' + current_version + '[/B].[CR]',
                    'Would you like to install version [COLOR green][B]' +
                    remote_version + '[/B][/COLOR]?')
            else:
                choice = xbmcgui.Dialog().yesno(
                    'idolpx Installer',
                    'Current version is [B]' + current_version + '[/B].[CR]',
                    'Would you like to reinstall version [B]' +
                    remote_version + '[/B]?')

        if choice == 1:
            # Give service enough time to stop downloading
            time.sleep(3)

            if installer.installConfig(url, hash):

                # Save Installed Version to file
                with open(version_file, "w") as outfile:
                    json.dump(remote, outfile)

                choice = xbmcgui.Dialog().yesno(
                    'idolpx Installer',
                    'A restart is required. Would you like to restart Kodi now?'
                )
                if choice == 1:
                    kodi.kill()

                xbmcgui.Dialog().ok('idolpx Installer',
                                    'Update checks complete!')
            else:

                xbmcgui.Dialog().ok('idolpx Installer', 'Update canelled!')

    except Exception, e:
        kodi.log(str(e))