Example #1
0
    def headerParserHandler(self, req):
        ret = basePackageUpload.BasePackageUpload.headerParserHandler(
            self, req)
        # Optional headers
        maps = [['Null-Org', 'null_org'], ['Packaging', 'packaging']]
        for hn, sn in maps:
            header_name = "%s-%s" % (self.header_prefix, hn)
            if req.headers_in.has_key(header_name):
                setattr(self, sn, req.headers_in[header_name])

        if ret != apache.OK:
            return ret

        if CFG.SEND_MESSAGE_TO_ALL:
            rhnSQL.closeDB()
            log_debug(1, "send_message_to_all is set")

            rhnFlags.set("apache-return-code", apache.HTTP_NOT_FOUND)
            try:
                outage_message = open(CFG.MESSAGE_TO_ALL).read()
            except IOError:
                log_error("Missing outage message file")
                outage_message = "Outage mode"
            raise rhnFault(20001, outage_message, explain=0)

        # Init the database connection
        rhnSQL.initDB()
        use_session = 0
        if self.field_data.has_key('Auth-Session'):
            session_token = self.field_data['Auth-Session']
            use_session = 1
        else:
            encoded_auth_token = self.field_data['Auth']

        if not use_session:
            auth_token = self.get_auth_token(encoded_auth_token)

            if len(auth_token) < 2:
                log_debug(3, auth_token)
                raise rhnFault(105, "Unable to autenticate")

            self.username, self.password = auth_token[:2]

        force = self.field_data['Force']
        force = int(force)
        log_debug(1, "Username", self.username, "Force", force)

        if use_session:
            self.org_id, self.force = rhnPackageUpload.authenticate_session(
                session_token, force=force, null_org=self.null_org)
        else:
            # We don't push to any channels
            self.org_id, self.force = rhnPackageUpload.authenticate(
                self.username,
                self.password,
                force=force,
                null_org=self.null_org)

        return apache.OK
Example #2
0
    def headerParserHandler(self, req):
        ret = basePackageUpload.BasePackageUpload.headerParserHandler(self, req)
        # Optional headers
        maps = [['Null-Org', 'null_org'], ['Packaging', 'packaging']]
        for hn, sn in maps:
            header_name = "%s-%s" % (self.header_prefix, hn)
            if req.headers_in.has_key(header_name):
                setattr(self, sn, req.headers_in[header_name])

        if ret != apache.OK:
            return ret

        if CFG.SEND_MESSAGE_TO_ALL:
            rhnSQL.closeDB()
            log_debug(1, "send_message_to_all is set")
        
            rhnFlags.set("apache-return-code", apache.HTTP_NOT_FOUND)
            try:
                outage_message = open(CFG.MESSAGE_TO_ALL).read()
            except IOError:
                log_error("Missing outage message file")
                outage_message = "Outage mode"
            raise rhnFault(20001, outage_message, explain=0)

        # Init the database connection
        rhnSQL.initDB()
        use_session = 0
        if self.field_data.has_key('Auth-Session'):
            session_token = self.field_data['Auth-Session']
            use_session = 1
        else:
            encoded_auth_token = self.field_data['Auth']
        
        if not use_session:
            auth_token = self.get_auth_token(encoded_auth_token)

            if len(auth_token) < 2:
                log_debug(3, auth_token)
                raise rhnFault(105, "Unable to autenticate")

            self.username, self.password = auth_token[:2]
        
        force = self.field_data['Force']
        force = int(force)
        log_debug(1, "Username", self.username, "Force", force)
        
        if use_session:
            self.org_id, self.force = rhnPackageUpload.authenticate_session(session_token,
                force=force, null_org=self.null_org)
        else:
            # We don't push to any channels
            self.org_id, self.force = rhnPackageUpload.authenticate(self.username,
                self.password, force=force, null_org=self.null_org)

        nevra = [self.package_name, "", self.package_version, 
            self.package_release, self.package_arch]

        return apache.OK
def db_backup(bkp):
    """captures the data from the db and stores it in the backup"""
    rhnSQL.initDB()
    # selects all packages that are from unknown providers
    query = """
    select  
        rp.id as "package_id", 
        rpn.name as "package_name",
        rpe.version as "package_version",
        rpe.release as "package_release",
        rpe.epoch as "package_epoch",
        rpa.label as "package_arch",
        rc.label as "channel_label",
        rc.id as "channel_id"
    from rhnpackage rp
        inner join rhnpackagename rpn on rpn.id = rp.name_id
        inner join rhnpackageevr rpe on rpe.id = rp.evr_id
        inner join rhnpackagearch rpa on rpa.id = rp.package_arch_id
        left outer join rhnchannelpackage rcp on rcp.package_id = rp.id
        left outer join rhnchannel rc on rc.id = rcp.channel_id
        left outer join rhnpackagekeyassociation rpka on rpka.package_id = rp.id
    where rpka.key_id is null
    order by 2, 3
    """
    cursor = rhnSQL.prepare(query)
    cursor.execute()
    rows = cursor.fetchall_dict()
    print "backing up the list of packages"
    if not rows is None:
        c = 0
        for row in rows:
            c += 1
            bkp.add(
                row['package_id'], row['channel_label'], {
                    'name': row['package_name'],
                    'version': row['package_version'],
                    'release': row['package_release'],
                    'epoch': row['package_epoch'],
                    'arch': row['package_arch']
                })
            if not verbose:
                print "\r%s of %s" % (str(c), str(len(rows))),
        if not verbose:
            print ""
        else:
            print "%s entries treated" % (str(len(rows)))
    else:
        print "no packages to backup"
    rhnSQL.closeDB()
def db_backup(bkp):
    """captures the data from the db and stores it in the backup"""
    rhnSQL.initDB()
    # selects all packages that are from unknown providers
    query = """
    select  
        rp.id as "package_id", 
        rpn.name as "package_name",
        rpe.version as "package_version",
        rpe.release as "package_release",
        rpe.epoch as "package_epoch",
        rpa.label as "package_arch",
        rc.label as "channel_label",
        rc.id as "channel_id"
    from rhnpackage rp
        inner join rhnpackagename rpn on rpn.id = rp.name_id
        inner join rhnpackageevr rpe on rpe.id = rp.evr_id
        inner join rhnpackagearch rpa on rpa.id = rp.package_arch_id
        left outer join rhnchannelpackage rcp on rcp.package_id = rp.id
        left outer join rhnchannel rc on rc.id = rcp.channel_id
        left outer join rhnpackagekeyassociation rpka on rpka.package_id = rp.id
    where rpka.key_id is null
    order by 2, 3
    """
    cursor = rhnSQL.prepare(query)
    cursor.execute()
    rows = cursor.fetchall_dict()
    print "backing up the list of packages"
    if not rows is None:
        c = 0
        for row in rows:
            c += 1
            bkp.add(row['package_id'],row['channel_label'], {'name': row['package_name'], 'version': row['package_version'], 'release': row['package_release'], 'epoch': row['package_epoch'], 'arch': row['package_arch']})
            if not verbose:
                print "\r%s of %s" % (str(c), str(len(rows))),
        if not verbose:
            print ""
        else:
            print "%s entries treated" % (str(len(rows)))
    else:
        print "no packages to backup"
    rhnSQL.closeDB()
    def headerParserHandler(self, req):
        # pylint: disable=W0201
        log_setreq(req)
        self.start_time = time.time()
        # init configuration options with proper component
        options = req.get_options()
        # if we are initializing out of a <Location> handler don't
        # freak out
        if "RHNComponentType" not in options:
            # clearly nothing to do
            return apache.OK
        initCFG(options["RHNComponentType"])
        initLOG(CFG.LOG_FILE, CFG.DEBUG)
        # short-circuit everything if sending a system-wide message.
        if CFG.SEND_MESSAGE_TO_ALL:
            # Drop the database connection
            # pylint: disable=W0702
            try:
                rhnSQL.closeDB()
            except:
                pass

            # Fetch global message being sent to clients if applicable.
            msg = open(CFG.MESSAGE_TO_ALL).read()
            log_debug(3, "Sending message to all clients: %s" % msg)
            return self._send_xmlrpc(
                req,
                rhnFault(-1,
                         _("IMPORTANT MESSAGE FOLLOWS:\n%s") % msg,
                         explain=0))

        rhnSQL.initDB()
        self.server = options['SERVER']

        self.server_classes = rhnImport.load("satellite_exporter/handlers")

        if self.server not in self.server_classes:
            # XXX do something interesting here
            log_error("Missing server", self.server)
            return apache.HTTP_NOT_FOUND

        return self._wrapper(req, self._headerParserHandler)
Example #6
0
    def headerParserHandler(self, req):
        # pylint: disable=W0201
        log_setreq(req)
        self.start_time = time.time()
        # init configuration options with proper component
        options = req.get_options()
        # if we are initializing out of a <Location> handler don't
        # freak out
        if "RHNComponentType" not in options:
            # clearly nothing to do
            return apache.OK
        initCFG(options["RHNComponentType"])
        initLOG(CFG.LOG_FILE, CFG.DEBUG)
        # short-circuit everything if sending a system-wide message.
        if CFG.SEND_MESSAGE_TO_ALL:
            # Drop the database connection
            # pylint: disable=W0702
            try:
                rhnSQL.closeDB()
            except:
                pass

            # Fetch global message being sent to clients if applicable.
            msg = open(CFG.MESSAGE_TO_ALL).read()
            log_debug(3, "Sending message to all clients: %s" % msg)
            return self._send_xmlrpc(req, rhnFault(-1,
                                                   _("IMPORTANT MESSAGE FOLLOWS:\n%s") % msg, explain=0))

        rhnSQL.initDB()
        self.server = options['SERVER']

        self.server_classes = rhnImport.load("satellite_exporter/handlers")

        if self.server not in self.server_classes:
            # XXX do something interesting here
            log_error("Missing server", self.server)
            return apache.HTTP_NOT_FOUND

        return self._wrapper(req, self._headerParserHandler)
Example #7
0
       AND ckt.id = ck.crypto_key_type_id
       AND ck.description = :description
       AND ck.org_id is NULL
""")

_queryInsertCryptoCertInfo = rhnSQL.Statement("""
    INSERT into rhnCryptoKey
           (id, org_id, description, crypto_key_type_id, key)
    SELECT :rhn_cryptokey_id, :org_id, :description, ckt.id, empty_blob()
      FROM rhnCryptoKeyType ckt
     WHERE ckt.label = 'SSL'
""")


def _test_store_rhnCryptoKey(caCert):
    description = 'RHN-ORG-TRUSTED-SSL-CERT'
    store_CaCert(description, caCert)


if __name__ == '__main__':
    rhnSQL.initDB()

    _test_store_rhnCryptoKey('ca.crt')

    # NOTE!!! This has be seg-faulting on exit, specifically upon closeDB()
    #         Bugzilla: 127324

    print("end of __main__")
    rhnSQL.closeDB()
    print("we have closed the database")
Example #8
0
    h = rhnSQL.prepare(_query_lookup_cfid)
    h.execute(orgid = orgid)
    cfid = h.fetchone_dict()
    if not cfid:
        return

    _query_create_priv_chfam = """
        INSERT INTO  rhnPrivateChannelFamily
            (channel_family_id, org_id, max_members, current_members)
        VALUES  (:id, :org_id, NULL, 0)
    """

    h = rhnSQL.prepare(_query_create_priv_chfam)
    h.execute(id=cfid['id'], org_id=orgid)


if __name__ == '__main__':
    rhnSQL.initDB()

    #_test_storeRhnCert(open('rhn.cert').read())
    _test_store_rhnCryptoKey('ca.crt')

    # NOTE!!! This has be seg-faulting on exit, specifically upon closeDB()
    #         Bugzilla: 127324

    print "end of __main__"
    rhnSQL.closeDB()
    print "we have closed the database"

def resultExit(code, msg=None):
    rhnSQL.closeDB()
    if msg:
        print msg
    sys.exit(code)