Example #1
0
def getProxySetting():
    """ returns proxy string in format hostname:port
    hostname is converted to Pune encoding if needed
    """
    cfg = initUp2dateConfig()
    proxy = None
    proxyHost = cfg["httpProxy"]

    if proxyHost:
        if proxyHost[:7] == "http://":
            proxyHost = proxyHost[7:]
        parts = proxyHost.split(':')
        parts[0] = idn_ascii_to_pune(parts[0])
        proxy = ':'.join(parts)

    return proxy
Example #2
0
def getProxySetting():
    """ returns proxy string in format hostname:port
    hostname is converted to Pune encoding if needed
    """
    cfg = initUp2dateConfig()
    proxy = None
    proxyHost = cfg["httpProxy"]

    if proxyHost:
        if proxyHost[:7] == "http://":
            proxyHost = proxyHost[7:]
        parts = proxyHost.split(':')
        parts[0] = idn_ascii_to_pune(parts[0])
        proxy = ':'.join(parts)

    return proxy
Example #3
0
    def setURL(self):
        server = idn_ascii_to_pune(self.options.server)
        if server is None:
            self.die(1, "Required parameter --server not supplied")
        scheme, netloc, path, params, query, fragment = urlparse.urlparse(server)
        if not netloc:
            # No schema - trying to patch it up ourselves?
            server = "http://" + server
            scheme, netloc, path, params, query, fragment = urlparse.urlparse(server)

        if not netloc:
            self.die(2, "Invalid URL %s" % server)
        if path == '':
            path = '/APP'
        if scheme.lower() not in ('http', 'https'):
            self.die(3, "Unknown URL scheme %s" % scheme)
        self.url = urlparse.urlunparse((scheme, netloc, path, params, query,
            fragment))
        self.url_v2 = urlparse.urlunparse((scheme, netloc, "/PACKAGE-PUSH",
            params, query, fragment))
Example #4
0
    def setURL(self):
        server = idn_ascii_to_pune(self.options.server)
        if server is None:
            self.die(1, "Required parameter --server not supplied")
        scheme, netloc, path, params, query, fragment = urlparse.urlparse(
            server)
        if not netloc:
            # No schema - trying to patch it up ourselves?
            server = "http://" + server
            scheme, netloc, path, params, query, fragment = urlparse.urlparse(
                server)

        if not netloc:
            self.die(2, "Invalid URL %s" % server)
        if path == '':
            path = '/APP'
        if scheme.lower() not in ('http', 'https'):
            self.die(3, "Unknown URL scheme %s" % scheme)
        self.url = urlparse.urlunparse(
            (scheme, netloc, path, params, query, fragment))
        self.url_v2 = urlparse.urlunparse(
            (scheme, netloc, "/PACKAGE-PUSH", params, query, fragment))
Example #5
0
def processCommandline():
    options = [
        Option('--systemid',
               action='store',
               help='(FOR TESTING ONLY) alternative systemid path/filename. ' +
               'The system default is used if not specified.'),
        Option('--rhn-cert',
               action='store',
               help='new RHN certificate path/filename (default is' +
               ' %s - the saved RHN cert).' % DEFAULT_RHN_CERT_LOCATION),
        Option('--no-ssl',
               action='store_true',
               help='(FOR TESTING ONLY) disables SSL'),
        Option('--sanity-only',
               action='store_true',
               help="confirm certificate sanity. Does not activate" +
               "the Red Hat Satellite locally or remotely."),
        Option('--disconnected',
               action='store_true',
               help="activate locally, but not on remote RHN servers,"),
        Option('--ignore-expiration',
               action='store_true',
               help='execute regardless of the expiration' +
               'of the RHN Certificate (not recommended).'),
        Option('--ignore-version-mismatch',
               action='store_true',
               help='execute regardless of version ' +
               'mismatch of existing and new certificate.'),
        Option('-v',
               '--verbose',
               action='count',
               help='be verbose ' +
               '(accumulable: -vvv means "be *really* verbose").'),
        Option('--dump-version',
               action='store',
               help="requested version of XML dump"),
    ]

    options, args = OptionParser(option_list=options).parse_args()

    # we take no extra commandline arguments that are not linked to an option
    if args:
        msg = "ERROR: these arguments make no sense in this context (try --help): %s\n" % repr(
            args)
        raise ValueError(msg)

    initCFG('server.satellite')

    # systemid, rhn-cert
    if not options.systemid:
        options.systemid = DEFAULT_SYSTEMID_LOCATION
    options.systemid = fileutils.cleanupAbsPath(options.systemid)

    if not options.rhn_cert:
        print "NOTE: using backup cert as default: %s" % DEFAULT_RHN_CERT_LOCATION
        options.rhn_cert = DEFAULT_RHN_CERT_LOCATION
    options.rhn_cert = fileutils.cleanupAbsPath(options.rhn_cert)
    if not os.path.exists(options.rhn_cert):
        sys.stderr.write("ERROR: RHN Cert (%s) does not exist\n" %
                         options.rhn_cert)
        sys.exit(1)

    if options.sanity_only:
        options.disconnected = 1

    if CFG.DISCONNECTED and not options.disconnected:
        sys.stderr.write(
            """ERROR: Satellite server has been setup to run in disconnected mode.
       Either correct server configuration in /etc/rhn/rhn.conf
       or use --disconnected to activate it locally.
""")
        sys.exit(1)

    options.server = ''
    if not options.disconnected:
        if not CFG.RHN_PARENT:
            sys.stderr.write(
                "ERROR: rhn_parent is not set in /etc/rhn/rhn.conf\n")
            sys.exit(1)
        options.server = idn_ascii_to_pune(
            rhnLib.parseUrl(CFG.RHN_PARENT)[1].split(':')[0])
        print 'RHN_PARENT: %s' % options.server

    options.http_proxy = idn_ascii_to_pune(CFG.HTTP_PROXY)
    options.http_proxy_username = CFG.HTTP_PROXY_USERNAME
    options.http_proxy_password = CFG.HTTP_PROXY_PASSWORD
    options.ca_cert = CFG.CA_CHAIN
    if options.verbose:
        print 'HTTP_PROXY: %s' % options.http_proxy
        print 'HTTP_PROXY_USERNAME: %s' % options.http_proxy_username
        print 'HTTP_PROXY_PASSWORD: <password>'
        if not options.no_ssl:
            print 'CA_CERT: %s' % options.ca_cert

    return options
Example #6
0
def main():
    # Initialize a command-line processing object with a table of options
    # pylint: disable=C0301
    optionsTable = [
        Option('-v',
               '--verbose',
               action='count',
               help='Increase verbosity',
               default=0),
        Option('-d',
               '--dir',
               action='store',
               help='Process packages from this directory'),
        Option('-c',
               '--channel',
               action='append',
               help='Manage this channel (specified by label)'),
        Option('-n',
               '--count',
               action='store',
               help='Process this number of headers per call',
               type='int'),
        Option('-l',
               '--list',
               action='store_true',
               help='Only list the specified channels'),
        Option('-r',
               '--reldir',
               action='store',
               help='Relative dir to associate with the file'),
        Option('-o', '--orgid', action='store', help='Org ID', type='int'),
        Option('-u',
               '--username',
               action='store',
               help='Use this username to connect to RHN/Satellite'),
        Option('-p',
               '--password',
               action='store',
               help='Use this password to connect to RHN/Satellite'),
        Option('-s',
               '--stdin',
               action='store_true',
               help='Read the package names from stdin'),
        Option('-X',
               '--exclude',
               action='append',
               help='Exclude packages that match this glob expression'),
        Option(
            '--force',
            action='store_true',
            help='Force the package upload (overwrites if already uploaded)'),
        Option('--nosig', action='store_true', help='Push unsigned packages'),
        Option(
            '--newest',
            action='store_true',
            help='Only push the packages that are newer than the server ones'),
        Option('--nullorg', action='store_true', help='Use the null org id'),
        Option('--header',
               action='store_true',
               help='Upload only the header(s)'),
        Option('--source',
               action='store_true',
               help='Upload source package information'),
        Option('--server',
               action='store',
               help='Push to this server (http[s]://<hostname>/APP)'),
        Option('--proxy',
               action='store',
               help='Use proxy server (<server>:<port>)'),
        Option('--test',
               action='store_true',
               help='Only print the packages to be pushed'),
        Option('-?',
               '--usage',
               action='store_true',
               help='Briefly describe the options'),
        Option('-N',
               '--new-cache',
               action='store_true',
               help='Create a new username/password cache'),
        Option('--extended-test',
               action='store_true',
               help='Perform a more verbose test'),
        Option('--no-session-caching',
               action='store_true',
               help='Disables session-token authentication.'),
        Option(
            '--tolerant',
            action='store_true',
            help=
            'If rhnpush errors while uploading a package, continue uploading the rest of the packages.'
        ),
        Option('--ca-chain', action='store', help='alternative SSL CA Cert')
    ]
    # pylint: enable=C0301

    #Having to maintain a store_true list is ugly. I'm trying to get rid of this.
    true_list = ['usage', 'test', 'source', 'header', 'nullorg', 'newest', \
                 'nosig', 'force', 'list', 'stdin', 'new_cache','extended_test', \
                 'no_session_caching', 'tolerant']
    # pylint: disable=E1101,E1103
    optionParser = OptionParser(option_list=optionsTable,
                                usage="%prog [OPTION] [<package>]")
    manager = rhnpush_confmanager.ConfManager(optionParser, true_list)
    options = manager.get_config()

    upload = UploadClass(options, files=options.files)

    if options.usage:
        optionParser.print_usage()
        sys.exit(0)

    if options.proxy:
        options.proxy = idn_ascii_to_pune(options.proxy)

    if options.list:
        if not options.channel:
            upload.die(1, "Must specify a channel for --list to work")
        upload.list()
        return

    if options.dir and not options.stdin:
        upload.directory()

    elif options.stdin and not options.dir:
        upload.readStdin()

    elif options.dir and options.stdin:
        upload.readStdin()
        upload.directory()

    if options.exclude:
        upload.filter_excludes()

    if options.newest:
        if not options.channel:
            upload.die(1, "Must specify a channel for --newest to work")

        upload.newest()

    if not upload.files:
        if upload.newest:
            print "No new files to upload; exiting"
        else:
            print "Nothing to do (try --help for more options)"
        sys.exit(0)

    if options.test:
        upload.test()
        return

    if options.extended_test:
        upload.extended_test()
        return

    if options.header:
        upload.uploadHeaders()
        return

    ret = upload.packages()
    if ret != 0:
        return 1
def processCommandline():
    options = [
        Option('--systemid',     action='store',      help='(FOR TESTING ONLY) alternative systemid path/filename. The system default is used if not specified.'),
        Option('--rhn-cert',     action='store',      help='new RHN certificate path/filename (default is %s - the saved RHN cert).' % DEFAULT_RHN_CERT_LOCATION),
        Option('--no-ssl',       action='store_true', help='(FOR TESTING ONLY) disables SSL'),
        Option('--sanity-only',  action='store_true', help="confirm certificate sanity. Does not activate the Red Hat Satellite locally or remotely."),
        Option('--disconnected', action='store_true', help="activate locally, but not on remote RHN servers,"),
        Option('--ignore-expiration', action='store_true', help='execute regardless of the expiration of the RHN Certificate (not recommended).'),
        Option('--ignore-version-mismatch', action='store_true', help='execute regardless of version mismatch of existing and new certificate.'),
        Option('-v','--verbose', action='count',      help='be verbose (accumulable: -vvv means "be *really* verbose").'),
        Option(     '--dump-version', action='store', help="requested version of XML dump"),
              ]

    options, args = OptionParser(option_list=options).parse_args()

    # we take no extra commandline arguments that are not linked to an option
    if args:
        msg = "ERROR: these arguments make no sense in this context (try --help): %s\n" % repr(args)
        raise ValueError(msg)

    initCFG('server.satellite')

    # systemid, rhn-cert
    if not options.systemid:
        options.systemid = DEFAULT_SYSTEMID_LOCATION
    options.systemid = fileutils.cleanupAbsPath(options.systemid)

    if not options.rhn_cert:
        print "NOTE: using backup cert as default: %s" % DEFAULT_RHN_CERT_LOCATION
        options.rhn_cert = DEFAULT_RHN_CERT_LOCATION
    options.rhn_cert = fileutils.cleanupAbsPath(options.rhn_cert)
    if not os.path.exists(options.rhn_cert):
        sys.stderr.write("ERROR: RHN Cert (%s) does not exist\n" % options.rhn_cert)
        sys.exit(1)

    if options.sanity_only:
        options.disconnected = 1

    if CFG.DISCONNECTED and not options.disconnected:
        sys.stderr.write("""ERROR: Satellite server has been setup to run in disconnected mode.
       Either correct server configuration in /etc/rhn/rhn.conf
       or use --disconnected to activate it locally.
""")
        sys.exit(1)

    options.server = ''
    if not options.disconnected:
        if not CFG.RHN_PARENT:
            sys.stderr.write("ERROR: rhn_parent is not set in /etc/rhn/rhn.conf\n")
            sys.exit(1)
        options.server = idn_ascii_to_pune(rhnLib.parseUrl(CFG.RHN_PARENT)[1].split(':')[0])
        print 'RHN_PARENT: %s' % options.server

    options.http_proxy = idn_ascii_to_pune(CFG.HTTP_PROXY)
    options.http_proxy_username = CFG.HTTP_PROXY_USERNAME
    options.http_proxy_password = CFG.HTTP_PROXY_PASSWORD
    options.ca_cert = CFG.CA_CHAIN
    if options.verbose:
        print 'HTTP_PROXY: %s' % options.http_proxy
        print 'HTTP_PROXY_USERNAME: %s' % options.http_proxy_username
        print 'HTTP_PROXY_PASSWORD: <password>'
        if not options.no_ssl:
            print 'CA_CERT: %s' % options.ca_cert

    return options
Example #8
0
def convert_url_to_pune(url):
    """ returns url where hostname is converted to Pune encoding """
    s = urlsplit(url)
    return urlunsplit(
        (s[0], idn_ascii_to_pune(s[1]), s[2], s[3], s[4])).encode('utf-8')
Example #9
0
def convert_url_to_pune(url):
    """ returns url where hostname is converted to Pune encoding """
    s = urlsplit(url)
    return urlunsplit((s[0], idn_ascii_to_pune(s[1]), s[2], s[3], s[4])).encode('utf-8')
Example #10
0
def main():
    # Initialize a command-line processing object with a table of options
    # pylint: disable=C0301
    optionsTable = [
        Option('-v','--verbose',    action='count',      help='Increase verbosity', default=0),
        Option('-d','--dir',        action='store',      help='Process packages from this directory'),
        Option('-c','--channel',    action='append',     help='Manage this channel (specified by label)'),
        Option('-n','--count',      action='store',      help='Process this number of headers per call', type='int'),
        Option('-l','--list',       action='store_true', help='Only list the specified channels'),
        Option('-r','--reldir',     action='store',      help='Relative dir to associate with the file'),
        Option('-o','--orgid',      action='store',      help='Org ID', type='int'),
        Option('-u','--username',   action='store',      help='Use this username to connect to RHN/Satellite'),
        Option('-p','--password',   action='store',      help='Use this password to connect to RHN/Satellite'),
        Option('-s','--stdin',      action='store_true', help='Read the package names from stdin'),
        Option('-X','--exclude',    action='append',     help='Exclude packages that match this glob expression'),
        Option(     '--force',      action='store_true', help='Force the package upload (overwrites if already uploaded)'),
        Option(     '--nosig',      action='store_true', help='Push unsigned packages'),
        Option(     '--newest',     action='store_true', help='Only push the packages that are newer than the server ones'),
        Option(     '--nullorg',    action='store_true', help='Use the null org id'),
        Option(     '--header',     action='store_true', help='Upload only the header(s)'),
        Option(     '--source',     action='store_true', help='Upload source package information'),
        Option(     '--server',     action='store',      help='Push to this server (http[s]://<hostname>/APP)'),
        Option(     '--proxy',      action='store',      help='Use proxy server (<server>:<port>)'),
        Option(     '--test',       action='store_true', help='Only print the packages to be pushed'),
        Option('-?','--usage',      action='store_true', help='Briefly describe the options'),
        Option('-N','--new-cache',  action='store_true', help='Create a new username/password cache'),
        Option(     '--extended-test',  action='store_true', help='Perform a more verbose test'),
        Option(     '--no-session-caching',  action='store_true',
            help='Disables session-token authentication.'),
        Option(     '--tolerant',   action='store_true',
            help='If rhnpush errors while uploading a package, continue uploading the rest of the packages.'),
        Option(     '--ca-chain',     action='store',      help='alternative SSL CA Cert')
    ]
    # pylint: enable=C0301

    #Having to maintain a store_true list is ugly. I'm trying to get rid of this.
    true_list = ['usage', 'test', 'source', 'header', 'nullorg', 'newest', \
                 'nosig', 'force', 'list', 'stdin', 'new_cache','extended_test', \
                 'no_session_caching', 'tolerant']
    # pylint: disable=E1101,E1103
    optionParser = OptionParser(option_list=optionsTable, usage="%prog [OPTION] [<package>]")
    manager = rhnpush_confmanager.ConfManager(optionParser, true_list)
    options = manager.get_config()

    upload = UploadClass(options, files=options.files)

    if options.usage:
        optionParser.print_usage()
        sys.exit(0)

    if options.proxy:
        options.proxy = idn_ascii_to_pune(options.proxy)

    if options.list:
        if not options.channel:
            upload.die(1, "Must specify a channel for --list to work")
        upload.list()
        return

    if options.dir and not options.stdin:
        upload.directory()

    elif options.stdin and not options.dir:
        upload.readStdin()

    elif options.dir and options.stdin:
        upload.readStdin()
        upload.directory()

    if options.exclude:
        upload.filter_excludes()

    if options.newest:
        if not options.channel:
            upload.die(1, "Must specify a channel for --newest to work")

        upload.newest()

    if not upload.files:
        if upload.newest:
            print "No new files to upload; exiting"
        else:
            print "Nothing to do (try --help for more options)"
        sys.exit(0)

    if options.test:
        upload.test()
        return

    if options.extended_test:
        upload.extended_test()
        return

    if options.header:
        upload.uploadHeaders()
        return

    ret = upload.packages()
    if ret != 0:
        return 1
Example #11
0
class Runner(jabber_lib.Runner):
    client_factory = dispatcher_client.Client

    # We want the dispatcher to check in quite often in case the jabberd
    # connection drops
    _min_sleep = 10
    _max_sleep = 10

    def __init__(self):
        jabber_lib.Runner.__init__(self)
        initCFG("osa-dispatcher")
        self._tcp_server = None
        self._poll_interval = None
        self._next_poll_interval = None
        # Cache states
        self._state_ids = {}

    def read_config(self):
        ret = {
            'jabber_server' : CFG.jabber_server,
        }
        return ret

    _query_get_dispatcher_password = """
    select id, password
      from rhnPushDispatcher
     where jabber_id like :jabber_id
    """

    _update_dispatcher_password = """
    update rhnPushDispatcher
       set password = :password_in
     where id = :id_in
    """

    def get_dispatcher_password(self, username):
        h = rhnSQL.prepare(self._query_get_dispatcher_password)
        h.execute(jabber_id = username + "%")
        ret = h.fetchall_dict()

        if ret and len(ret) == 1:
            if ret[0]['password']:
                return ret[0]['password']
            else:
                # Upgrade Spacewalk 1.5 -> 1.6: the dispatcher row exists,
                # we just need to generate and save the password.
                self._password = self.create_dispatcher_password(32)
                u = rhnSQL.prepare(self._update_dispatcher_password)
                u.execute(password_in = self._password, id_in = ret[0]['id'])
                return self._password
        else:
            return None

    def create_dispatcher_password(self, length):
        chars = string.ascii_letters + string.digits
        return "".join(choice(chars) for x in range(length))

    def setup_config(self, config):
        # Figure out the log level
        debug_level = self.options.verbose
        if debug_level is None:
            debug_level = CFG.debug
        self.debug_level = debug_level
        initLOG(level=debug_level, log_file=CFG.log_file)

        # Get the ssl cert
        ssl_cert = CFG.osa_ssl_cert
        try:
            self.check_cert(ssl_cert)
        except jabber_lib.InvalidCertError, e:
            log_error("Invalid SSL certificate:", e)
            return 1

        self.ssl_cert = ssl_cert

        rhnSQL.initDB()

        self._username = '******'
        self._password = self.get_dispatcher_password(self._username)
        if not self._password:
            self._password = self.create_dispatcher_password(32)
        self._resource = 'superclient'
        js = config.get('jabber_server')
        self._jabber_servers = [ idn_ascii_to_pune(js) ]