Пример #1
0
def requestServerData(url, webuser = None, webpass = None):
    if TLS_V1_NEG_ERROR:
        import httplib
        httplib.HTTPSConnection.connect = httpsConnectReplacment
    from urllib2 import (HTTPPasswordMgr, HTTPBasicAuthHandler, build_opener, install_opener, urlopen, HTTPError)
    password_mgr = HTTPPasswordMgr()	#WithDefaultRealm()
    password_mgr.add_password("Server Admin", url, webuser, webpass)
    handler = HTTPBasicAuthHandler(password_mgr)
    opener = build_opener(handler)
    install_opener(opener)
    request =  urllib2.Request(url)
    if webuser:
            base64string = base64.encodestring('%s:%s' % (webuser, webpass))[:-1]
            request.add_header("Authorization", "Basic %s" % base64string)
            request.add_header('WWW-Authenticate', 'Basic realm="Server Admin"')
    try:
        htmlFile = urllib2.urlopen(request) #, timeout=30)
        htmlData = htmlFile.read()
        htmlFile.close()
        # This bit identifies if it's leopard which adds extra unneeded info as a header
        if re.match("SupportsBinaryPlist", htmlData):
            xmlDump = re.split("\r\n\r\n", htmlData, 1)
            return 0, xmlDump[1]
        else:
            return 0, htmlData
    except:
        return 1, sys.exc_info()[1]
Пример #2
0
    def send_metadata(self):
        """ Send the metadata to the package index server.

            1. figure who the user is, and then
            2. send the data as a Basic auth'ed POST.

            First we try to read the username/password from $HOME/.pypirc,
            which is a ConfigParser-formatted file with a section
            [distutils] containing username and password entries (both
            in clear text) e.g.::

                [distutils]
                index-servers =
                    pypi

                [pypi]
                username: fred
                password: sekrit

            Otherwise, to figure who the user is, we offer the user three
            choices:

            1. use existing login,
            2. prompt to specify and alternate username

            You will always be prompted for a password unless it has already
            been set in the .pypirc file. There will be an option to save
            your credentials in a file to speed up future access to PyPI.
        """
        username, password = self.request_credentials(self.repository)

        # set up the authentication
        auth = HTTPPasswordMgr()
        host = urlparse(self.repository)[1]
        auth.add_password(self.realm, host, username, password)

        # send the info to the server and report the result
        code, result = self.post_to_server(self.build_post_data('submit'),
                                           auth)
        self.announce('Server response (%s): %s' % (code, result), log.INFO)

        # possibly save the login
        if code == 200:
            self.store_credentials(username, password)
Пример #3
0
    def send_metadata(self):
        """ Send the metadata to the package index server.

            1. figure who the user is, and then
            2. send the data as a Basic auth'ed POST.

            First we try to read the username/password from $HOME/.pypirc,
            which is a ConfigParser-formatted file with a section
            [distutils] containing username and password entries (both
            in clear text) e.g.::

                [distutils]
                index-servers =
                    pypi

                [pypi]
                username: fred
                password: sekrit

            Otherwise, to figure who the user is, we offer the user three
            choices:

            1. use existing login,
            2. prompt to specify and alternate username

            You will always be prompted for a password unless it has already
            been set in the .pypirc file. There will be an option to save
            your credentials in a file to speed up future access to PyPI.
        """
        username, password = self.request_credentials(self.repository)

        # set up the authentication
        auth = HTTPPasswordMgr()
        host = urlparse(self.repository)[1]
        auth.add_password(self.realm, host, username, password)

        # send the info to the server and report the result
        code, result = self.post_to_server(self.build_post_data('submit'), auth)
        self.announce('Server response (%s): %s' % (code, result), log.INFO)

        # possibly save the login
        if code == 200:
            self.store_credentials(username, password)
Пример #4
0
url = 'https://' + hostname + ':311/commands/servermgr_info?input=%3C%3Fxml+version%3D%221.0%22+encoding%3D%22UTF-8%22%3F%3E%0D%0A%3Cplist+version%3D%220.9%22%3E%0D%0A%3Cdict%3E%0D%0A%09%3Ckey%3Ecommand%3C%2Fkey%3E%0D%0A%09%3Cstring%3EgetHardwareInfo%3C%2Fstring%3E%0D%0A%09%3Ckey%3Evariant%3C%2Fkey%3E%0D%0A%09%3Cstring%3EwithQuotaUsage%3C%2Fstring%3E%0D%0A%3C%2Fdict%3E%0D%0A%3C%2Fplist%3E%0D%0A&send=Send+Command'

# Replacement for broken clients https connect using non v1 connections
def httpsConnectReplacement(self):
	import socket, ssl
	sock = socket.create_connection((self.host, self.port), self.timeout, self.source_address)
	if self._tunnel_host:
		self.sock = sock
		self._tunnel()
	self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file, ssl_version=ssl.PROTOCOL_TLSv1)

# Get the hardware information from the OS X server
httplib.HTTPSConnection.connect = httpsConnectReplacement
from urllib2 import (HTTPPasswordMgr, HTTPBasicAuthHandler, build_opener, install_opener, urlopen, HTTPError)
password_mgr = HTTPPasswordMgr()	#WithDefaultRealm()
password_mgr.add_password("Server Admin", url, webuser, webpass)
handler = HTTPBasicAuthHandler(password_mgr)
opener = build_opener(handler)
install_opener(opener)
request =  urllib2.Request(url)
if webuser:
	base64string = base64.encodestring('%s:%s' % (webuser, webpass))[:-1]
	request.add_header("Authorization", "Basic %s" % base64string)
	request.add_header('WWW-Authenticate', 'Basic realm="Server Admin"')
try:
  htmlFile = urllib2.urlopen(request) #, timeout=30)
  htmlData = htmlFile.read()
  htmlFile.close()
  # This bit identifies if it's leopard which adds extra unneeded info as a header
  if re.match("SupportsBinaryPlist", htmlData):
    xmlDump = re.split("\r\n\r\n", htmlData, 1)
Пример #5
0
                                    self.source_address)
    if self._tunnel_host:
        self.sock = sock
        self._tunnel()
    self.sock = ssl.wrap_socket(sock,
                                self.key_file,
                                self.cert_file,
                                ssl_version=ssl.PROTOCOL_TLSv1)


# Get the hardware information from the OS X server
httplib.HTTPSConnection.connect = httpsConnectReplacement
from urllib2 import (HTTPPasswordMgr, HTTPBasicAuthHandler, build_opener,
                     install_opener, urlopen, HTTPError)
password_mgr = HTTPPasswordMgr()  #WithDefaultRealm()
password_mgr.add_password("Server Admin", url, webuser, webpass)
handler = HTTPBasicAuthHandler(password_mgr)
opener = build_opener(handler)
install_opener(opener)
request = urllib2.Request(url)
if webuser:
    base64string = base64.encodestring('%s:%s' % (webuser, webpass))[:-1]
    request.add_header("Authorization", "Basic %s" % base64string)
    request.add_header('WWW-Authenticate', 'Basic realm="Server Admin"')
try:
    htmlFile = urllib2.urlopen(request)  #, timeout=30)
    htmlData = htmlFile.read()
    htmlFile.close()
    # This bit identifies if it's leopard which adds extra unneeded info as a header
    if re.match("SupportsBinaryPlist", htmlData):
        xmlDump = re.split("\r\n\r\n", htmlData, 1)