Ejemplo n.º 1
0
    def __init__(self):
        self.cfg = config.initUp2dateConfig()
        self.xmlrpcServerUrl = self.cfg["serverURL"]
        if self.cfg["useNoSSLForPackages"]:
            self.httpServerUrl = self.cfg["noSSLServerURL"]
        else:
            self.httpServerUrl = self.cfg["serverURL"]

        self.proxyUrl = None
        self.proxyUser = None
        self.proxyPassword = None

        if self.cfg["enableProxy"] and rhnUtils.getProxySetting():
            self.proxyUrl = rhnUtils.getProxySetting()
            if self.cfg["enableProxyAuth"]:
                if self.cfg["proxyUser"] and self.cfg["proxyPassword"]:
                    self.proxyPassword = self.cfg["proxyPassword"]
                    self.proxyUser = self.cfg["proxyUser"]
Ejemplo n.º 2
0
    def __init__(self):
        self.cfg = config.initUp2dateConfig()
        self.xmlrpcServerUrl = self.cfg["serverURL"]
        if self.cfg["useNoSSLForPackages"]:
            self.httpServerUrl = self.cfg["noSSLServerURL"]
        else:
            self.httpServerUrl = self.cfg["serverURL"]

        self.proxyUrl = None
        self.proxyUser = None
        self.proxyPassword = None

        if self.cfg["enableProxy"] and rhnUtils.getProxySetting():
            self.proxyUrl = rhnUtils.getProxySetting()
            if self.cfg["enableProxyAuth"]:
                if self.cfg["proxyUser"] and self.cfg["proxyPassword"]:
                    self.proxyPassword = self.cfg["proxyPassword"]
                    self.proxyUser = self.cfg["proxyUser"]
Ejemplo n.º 3
0
def findHostByRoute():
    cfg = config.initUp2dateConfig()
    s = socket.socket()
    serverUrl = cfg['serverURL']
    server = string.split(serverUrl, '/')[2]
    port = 80
    if cfg['enableProxy']:
        server_port = rhnUtils.getProxySetting()
        (server, port) = string.split(server_port, ':')
        port = int(port)

    s.connect((server, port))
    (intf, port) = s.getsockname()
    try:
        hostname = socket.gethostbyaddr(intf)[0]
    # I dislike generic excepts, but is the above fails
    # for any reason, were not going to be able to
    # find a good hostname....
    except:
        hostname = "unknown"
    s.close()
    return hostname, intf
Ejemplo n.º 4
0
def findHostByRoute():
    cfg = config.initUp2dateConfig()
    s = socket.socket()
    serverUrl = cfg['serverURL']
    server = string.split(serverUrl, '/')[2]
    port = 80
    if cfg['enableProxy']:
        server_port = rhnUtils.getProxySetting()
        (server, port) = string.split(server_port, ':')
        port = int(port)

    s.connect((server, port))
    (intf, port) = s.getsockname()
    try:
        hostname = socket.gethostbyaddr(intf)[0]
    # I dislike generic excepts, but is the above fails
    # for any reason, were not going to be able to
    # find a good hostname....
    except:
        hostname = "unknown"
    s.close()
    return hostname, intf
Ejemplo n.º 5
0
def getServer(refreshCallback=None):
    log = rhnLog.initLog()
    cfg = config.initUp2dateConfig()
# Where do we keep the CA certificate for RHNS?
# The servers we're talking to need to have their certs
# signed by one of these CA.
    ca = cfg["sslCACert"]
    if type(ca) == type(""):
    	ca = [ca]

    rhns_ca_certs = ca or ["%s/usr/share/rhn/RHNS-CA-CERT" % config.PREFIX]
    if cfg["enableProxy"]:
        proxyHost = rhnUtils.getProxySetting()
    else:
        proxyHost = None

    if hasSSL():
        serverUrl = cfg["serverURL"]
    else:
        serverUrl = cfg["noSSLServerURL"]

    proxyUser = None
    proxyPassword = None
    if cfg["enableProxyAuth"]:
        proxyUser = cfg["proxyUser"] or None
        proxyPassword = cfg["proxyPassword"] or None

    lang = None
    for env in 'LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG':
        if os.environ.has_key(env):
            if not os.environ[env]:
                # sometimes unset
                continue
            lang = string.split(os.environ[env], ':')[0]
            lang = string.split(lang, '.')[0]
            break


    s = rpclib.Server(serverUrl, refreshCallback=refreshCallback,
                      proxy=proxyHost,
                      username=proxyUser,
                      password=proxyPassword)
    s.add_header("X-Up2date-Version", rhnUtils.version())

    if lang:
        s.setlang(lang)

    # require RHNS-CA-CERT file to be able to authenticate the SSL connections
    for rhns_ca_cert in rhns_ca_certs:
        if not os.access(rhns_ca_cert, os.R_OK):
            log.log_me("ERROR: can not find RHNS CA file: %s" % rhns_ca_cert)
            sys.exit(-1)

        # force the validation of the SSL cert
        s.add_trusted_cert(rhns_ca_cert)

    clientCaps.loadLocalCaps()

    # send up the capabality info
    headerlist = clientCaps.caps.headerFormat()
    for (headerName, value) in headerlist:
        s.add_header(headerName, value)
    return s