RE: rhn_register / up2date hacking

Hunter Matthews <[email protected]>
Newsgroups gmane.network.up2date.current.devel
Message-ID <[email protected]>
I've generally not wanted to modify the clients. 

As a (large) side project, I'd change my mind if someone could figure
out how to teach the client how to access multiple servers (a la
apt-get)

The only modifications I do here are config files and the attached
rhnreg_ks.

rhnreg_ks is a command line version of rhn_register, and this version
has been modified with a --anon option that 

<wait for it>

anonymously registers you against a current server. Since thats the only
mode we support at this moment, it saves all that useless typing.

This is a modified rhnreg_ks from 2.7.11, but I can't imagine why it
wouldn't work with a 2.7.6x version of up2date.


On Wed, 2002-05-29 at 14:49, Jeremy Johnson wrote:
> what kinda modifications are you talking about? i made my own rpms, and kickstart installation to interact with rhn_register
> 
> 	-----Original Message----- 
> 	From: Patrick Devine [mailto:[email protected]] 
> 	Sent: Wed 5/29/2002 11:44 AM 
> 	To: [email protected] 
> 	Cc: 
> 	Subject: [Current-server] rhn_register / up2date hacking
> 	
> 	
> 
> 
> 
> 	I was just wondering whether anyone on the list had done many (any?)
> 	modifications to rhn_register or up2date and whether there were any
> 	caveats to look out for.
> 	
> 	--Patrick.
> 	
> 	
> 	_______________________________________________
> 	Current-server mailing list
> 	[email protected]
> 	http://lists.dulug.duke.edu/mailman/listinfo/current-server
> 	
> 
-- 
Hunter Matthews                          Unix / Network Administrator
Office: BioScience 145/244               Duke Univ. Biology Department
Key: F0F88438 / FFB5 34C0 B350 99A4 BB02  9779 A5DB 8B09 F0F8 8438
Never take candy from strangers. Especially on the internet.
rhnreg_ks (text/plain, 7.5 KB)
#!/usr/bin/python
#
# Registration client for the Red Hat Network for useage with kickstart 
# Copyright (c) 1999-2001 Red Hat, Inc.  Distributed under GPL.
#
# Author: Adrian Likins <[email protected]>
#
#  see the output of "--help" for the valid options. 
#
#  The contact info is in the form or a "key: value" one per line.
#  valid keys are:
#       reg_num, title, first_name, last_name, company,
#       position, address1, address2, city, state, zip,
#       country, phone, fax, contact_email, contact_mail,
#       contact_phone, contact_fax, contact_special,
#       contact_newsletter
#
#
#
import getopt
import sys

sys.path.append("/usr/share/rhn/register")
import rhnreg
from translate import _, N_, cat
import hardware
import string


def printUseage():
    print _("Usage: rhnreg_ks [options]")
    print ""
    print _("Available command line options:")
    print _("-h, --help                     - this help ")
    print _("    --profilename=<value>      - specify a profilename")
    print _("    --username=<value>         - specify a username ")
    print _("    --password=<value>         - specify a password ")
    print _("    --orgid=<value>            - specify a organizational id ")
    print _("    --orgpassword=<value>      - specify a organizational password")
    print _("    --cryptedorgpassword=<value> - specify a crypted organizational password")
    print _("    --cryptedpassword=<value>  - specify a crypted password")
    print _("    --email=<value>            - specify a email address ")
    print _("    --serialnumber=<value>     - specify a serial number ")
    print _("    --contactinfo              - read contact info from stdin ")
    print _("    --nohardware               - do not probe or upload any hardware info ")
    print _("    --nopackages               - do not profile or upload any package info ")
    print _("    --force                    - register the system even if it is already registered")
    print _("    --version                  - display the version ")
    print _("    --anon                     - do anonymous registration ")
    print ""


def showVersion():
        print "Red Hat Network Registration Agent (Kickstart Version) v%s" % rhnreg.version()
        print "Copyright (c) 1999-2001 Red Hat, Inc."
        print _("Licensed under terms of the GPL.")


def readContactInfo():
    productInfo = [
        "reg_num",
        "title",
        "first_name",
        "last_name",
        "company",
        "position",
        "address1",
        "address2",
        "city",
        "state",
        "zip",
        "country",
        "phone",
        "fax",
        "contact_email",
        "contact_mail",
        "contact_phone",
        "contact_fax",
        "contact_special",
        "contact_newsletter"]
    
    # read a file from standard in or filename if specified
    L = sys.stdin.readlines()

    # parse it and build a dict
    info = {}
    for i in L:
        (key, value) = string.split(i, ':')
        info[key] = string.strip(value)

    #cleanse the hash for just the values we care about
    for i in info.keys():
        if i not in productInfo:
            del info[i]

    return info

def generateProfileName(hardwareList):
    hostname = None
    ipaddr = None
    profileName = None
    for hw in hardwareList:
        if hw['class'] == 'NETINFO':
            hostname = hw.get('hostname')
            ipaddr = hw.get('ipaddr')
            
    if hostname:
        profileName = hostname
    else:
        if ipaddr:
            profileName = ipaddr
            
    if not profileName:
        print _("A profilename wasnt specified, and hostname and IP address couldnt be determined to use as a profilename, please specify one.")
        sys.exit(-1)

    return profileName



def main(arglist=[]):
    
    if not len(arglist):
        arglist = sys.argv[1:]
    try:
        optlist, args = getopt.getopt(arglist,
                                      'h:',
                                      ['help',
                                       'username=','password=',
				       'cryptedpassword=',
                                       'orgid=','orgpassword=',
                                       'profilename=',
                                       'nopackages',
                                       'nohardware',
                                       'serialnumber=',
                                       'contactinfo',
                                       'email=',"force",'anon',])
    except getopt.error, e:
        print _("Error parsing command list arguments: %s") % e
        printUseage()
        sys.exit(1)

    username = password = orgid = orgPassword = profilename = email = None
    force = None
    nopackages = None
    nohardware = None
    serialnumber = None
    contactinfo = None
    oemInfo = {}
    
    for opt in optlist:
        if opt[0] == '-h' or opt[0] == "--help":
            printUseage()
            sys.exit(-1)
        if opt[0] == "--username":
            username = str(opt[1])
        if opt[0] == "--password":
            password = str(opt[1])
        if opt[0] == "--orgid":
            orgid = str(opt[1])
        if opt[0] == "--orgpassword":
            orgPassword = str(opt[1])
        if opt[0] == "--cryptedorgpassword":
            cryptOrgPassword = str(opt[1])
	if opt[0] == "--cryptedpassword":
	    cryptPassword = str(opt[1])
        if opt[0] == "--profilename":
            profilename = str(opt[1])
        if opt[0] == "--email":
            email = str(opt[1])
        if opt[0] == "--force":
            force = 1
        if opt[0] == "--nopackages":
            nopackages = 1
        if opt[0] == "--nohardware":
            nohardware = 1
        if opt[0] == "--serialnumber":
            serialnumber = str(opt[1])
        if opt[0] == "--contactinfo":
            contactinfo = readContactInfo()
	if opt[0] == "--anon":
            anon_reg = 1
        if opt[0] == "--version":
            showVersion()
            sys.exit(-1)

            
    if rhnreg.registered() and not force:
        print _("This system is already registered. Use --force to override")
        sys.exit(-1)

    if anon_reg:
	username = "Anonymous"
	password = "Anonymous"
        if not profilename:
            profilename = "Anonymous Profile"
        systemId = rhnreg.registerSystem(username, password, profilename)
        # write out the new id
        rhnreg.writeSystemId(systemId)
	return

    if not username or not password and not email:
        print _("A username,password,and email address are required to register a system.")
        sys.exit(-1)

    # reserver the username
    ret = rhnreg.reserveUser(username, password)

    rhnreg.registerUser(username, password, email, orgid, orgPassword)

    if not nopackages:
        packageList = rhnreg.buildPackageList()
    else:
        packageList = []
        
    # collect oemInfo 
    oemInfo = rhnreg.getOemInfo()
    
    hardwareList = hardware.Hardware()
    
    if not profilename:
        profilename = generateProfileName(hardwareList)

    systemId = rhnreg.registerSystem(username, password, profilename)

    # collect hardware info, inluding hostname
    if not nohardware:
        rhnreg.sendHardware(systemId, hardwareList)

    if not nopackages:
        rhnreg.sendPackages(systemId, packageList)

    if serialnumber:
        rhnreg.sendSerialNumber(systemId, serialnumber)

    if contactinfo:
        rhnreg.registerProduct(systemId, contactinfo, oemInfo)

    # write out the new id
    rhnreg.writeSystemId(systemId)

if __name__ == "__main__":
    main()
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.