示例#1
0
def add_group(group='', guid='1000', root='/mnt/'):
    '''add_group(group='', guid=1000', root='/mnt/')

    Añade un grupo
    '''
    from utils import debug

    if group == '':
        debug.echo_debug('No se han pasado los parámetros correctos', 'ERROR')
        return False
    elif group_exist(group):
        return True
    from utils import shell

    file = 'etc/group'
    pass_list = []
    if is_shadow(root):
        file = 'shadow'
    else:
        file = 'passwd'
    filename = shell.joinpath(root, file)
    groupfile = open(filename, 'a')
    groupfile.write('%s:x:%s:' % (group, guid))
    if is_shadow('gshadow'):
        filename = shell.joinpath(root, 'etc/gshadow')
        groupfile = open(filename, 'a')
        groupfile.write('%s:!::' % group)
    return True
示例#2
0
def get_pci_modules(filename='pci.lst'):
    '''get_pci_modules(filename = 'pci.lst') -> list of modules

    Busca en el proc información sobre los dispositivos
    PCI y los compara con los mapas de módulos del kernel
    y la base de datos de hardware de Kudzu
    '''

    drivers = []
    lines = []
    proc = []

    import os.path
    path, file = os.path.split(__file__)
    del file
    filename = joinpath(path, filename)
    if not read_file(filename, lines):
        print 'pcimap'
        import sys
        sys.exit(1)
    if not read_file('/proc/bus/pci/devices', proc):
        print 'proc'
        import sys
        sys.exit(1)

    pcitable = []
    for line in lines:
        fields = line.split()
        pcitable.append(fields)
    for entry in proc:
        for line in pcitable:
            if line[0] in entry:
                drivers.append(line[1])

    return drivers
示例#3
0
def is_shadow(root='/mnt/', file='shadow'):
    from os.path import isfile
    from utils import debug, shell
    filename = shell.joinpath(root, 'etc/' + file)
    if file in ['shadow', 'gshadow']:
        return isfile(filename)
    else:
        debug.echo_debug(
            'is_shadow: No ha introducido un nombre de archivo válido',
            'ERROR')
        return False
示例#4
0
def user_exist(user='', root='/mnt/'):
    '''user_exist(user='', root='/mnt/')

    Devuelve True si esiste el usuario y False si no existe
    '''

    import re
    from utils import debug, shell

    if user == '':
        debug.echo_debug('No se ha pasado un nombre de usuario', 'ERROR')
        return False

    is_user = re.compile('^(%s):' % user)
    passwd = shell.joinpath(root, 'etc/passwd')
    lines = open(passwd).readlines()
    for line in lines:
        found = is_user.match(line)
        if found:
            return True
    return False
示例#5
0
def change_pass(user='', passwd='', root='/mnt/'):
    '''change_pass(user='', passwd='', root='/mnt/')

    Cambia la clave a un usuario
    '''
    from utils import debug

    if user == '' or passwd == '':
        debug.echo_debug('No se han pasado los parámetros correctos', 'ERROR')
        return False
    elif not user_exist(user):
        debug.echo_debug(
            'El usuario %s, no existe, no se ha podido cambiar la clave' %
            user, 'ERROR')
        return False

    import crypt
    from utils import shell

    pass_list = []
    if is_shadow(root):
        file = 'shadow'
    else:
        file = 'passwd'
    passfile = shell.joinpath(root, 'etc/' + file)
    lines = open(passfile).readlines()
    for line in lines:
        fields = line.split(':')
        if fields[0] == user:
            fields[1] = crypt.crypt(passwd, 'o3l*2_X<.3q¡^')
            line = ':'.join(fields)
        pass_list.append(line)

    filename = open(passfile, 'w')
    for line in pass_list:
        filename.write(line)

    filename.close()
    return True
示例#6
0
def make_interfaces(configs = None, root='/mnt'):
    '''make_interfaces(configs = None, root='/mnt') -> bool

    Crea el archivo /etc/network/interfaces a partir de los
    datos de un diccionario pasado por parametro.
    '''
    
    from os.path import isfile
    from utils.debug import echo_debug, read_file
    from utils.shell import joinpath
    
    filename = joinpath(root, 'etc/network/interfaces')
    if not isfile(filename):
    	echo_debug('make_interfaces: No exite el archivo %s' % filename,'ERROR')
	return False
    file = open(filename, 'w')
    file.write('''
# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)

# The loopback interface
auto lo
iface lo inet loopback

# The network cards
    ''')
    interfaces = get_interfaces()
    wireless = get_wireless()
    #FIXME: Terminar for 
    for iter in interfaces:
	if iter in wireless:
	    print 'configuraciones wireless'
	else:
	    print 'configuraciones ethernet'

    file.close()
    return True
示例#7
0
    def __init__(self, filename = 'cards.lst'):
        '''Xconf(self, filename = 'cards.lst')

        Detecta el driver de la tarjeta gráfica mediante
        el módulo "metaconf.kmodules", el identificador 
        del Bus lo obtiene del "/proc/bus/pci/devices" y
        usando Kudzu, detecta la frecuencia del monitor
        y la memoria de la tarjeta.

        Guarda todos estos datos en los atributos de 
        la clase
        '''
        # Se detecta el driver de la tarjeta gráfica
	lines = []
	proc = []

	import os.path
	from utils.shell import joinpath
	from utils.debug import read_file
	
	path, file = os.path.split(__file__)
	del file
	filename = joinpath(path, filename)
	if not read_file(filename, lines):
	    import sys
	    sys.exit(1)
	if not read_file('/proc/bus/pci/devices', proc):    
	    import sys
	    sys.exit(1)
	    
	pcitable = []
	for line in lines:
	    fields = line.split()
	    pcitable.append(fields)
	for entry in proc:
	    for line in pcitable:
		if line[0] in entry:
		    bus = entry.split()[0]
		    self.card = line[1]

        devfn = int(bus,16)
        bus = devfn >> 8
        idev = (devfn >> 3) & 0x1F
        func = devfn & 0x07
        # Se establece el identificador del Bus
        self.busid = 'PCI:%d:%d:%d' % (bus, idev, func)
        # Se comprueba si el bus es PCI o AGP
        if bus is 1:
            self.bus = 'AGP'


        # Se detecta la frecuencia del monitor
        import _kudzu


        for res in _kudzu.probe(_kudzu.CLASS_MONITOR, _kudzu.BUS_DDC, 0):
            self.hsync = '%d-%d' % (res["horizSyncMin"],res["horizSyncMax"])
            self.vsync = '%d-%d' % (res["vertRefreshMin"],res["vertRefreshMax"])

        # Se detecta la memoria de la tarjeta gráfica
        for res in _kudzu.probe(_kudzu.CLASS_VIDEO, _kudzu.BUS_DDC, 0):
            self.mem = res["mem"]
示例#8
0
def make_xf86config(root = '/'):
    '''make_xf86config(root = '/')

    Crea el archivo /etc/X11/XF86Config-4 a partir de la clase
    Xconf.

    Admite el parámetro "root" que indica el directorio
    padre del sistema donde se quieren configurar las X.
    '''
    template = '''
Section "Files"
	FontPath	"unix/:7100"			# local font server
	# if the local font server has problems, we can fall back on these
	FontPath	"/usr/lib/X11/fonts/Type1"
	FontPath	"/usr/lib/X11/fonts/CID"
	FontPath	"/usr/lib/X11/fonts/Speedo"
	FontPath	"/usr/lib/X11/fonts/misc"
	FontPath	"/usr/lib/X11/fonts/cyrillic"
	FontPath	"/usr/lib/X11/fonts/100dpi"
	FontPath	"/usr/lib/X11/fonts/75dpi"
EndSection

Section "Module"
	Load	"GLcore"
	Load	"bitmap"
	Load	"dbe"
	Load	"ddc"
	Load	"dri"
	Load	"extmod"
	Load	"glx"
	Load	"int10"
	Load	"record"
	Load	"speedo"
	Load	"type1"
	Load	"vbe"
	Load	"xtt"
EndSection

Section "InputDevice"
	Identifier	"Generic Keyboard"
	Driver		"keyboard"
	Option		"CoreKeyboard"
	Option		"XkbRules"	"xfree86"
	Option		"XkbModel"	"pc105"
	Option		"XkbLayout"	"es"
EndSection

Section "ServerFlags"
	Option "AllowMouseOpenFail"  "true"
EndSection

Section "InputDevice"
	Identifier	"Generic Mouse Serial"
	Driver		"mouse"
	Option		"CorePointer"
	Option		"Device"		"/dev/ttyS0"
	Option		"Protocol"		"Microsoft"
	Option		"Emulate3Buttons"	"true"
	Option		"ZAxisMapping"		"4 5"
EndSection

Section "InputDevice"
	Identifier  "Generic Mouse PS/2"
	Driver      "mouse"
	Option      "Protocol" "ImPS/2"
	Option      "Device" "/dev/psaux"
	Option      "Emulate3Buttons" "true"
	Option      "Emulate3Timeout" "70"
	Option      "ZAxisMapping"  "4 5"
	Option	    "SendCoreEvents"  "true"
EndSection

Section "InputDevice"
	Identifier	"Generic Mouse USB"
	Driver		"mouse"
	Option		"SendCoreEvents"	"true"
	Option		"Device"		"/dev/input/mice"
	Option		"Protocol"		"ImPS/2"
	Option		"Emulate3Buttons"	"true"
	Option		"ZAxisMapping"		"4 5"
EndSection

Section "Device"
	Identifier	"Generic Video Card"
	Driver		"@@DRIVER@@"
	BusID       "@@BUSID@@"
EndSection

Section "Monitor"
	Identifier	"Generic Monitor"
	HorizSync	@@HSYNC@@
	VertRefresh	@@VSYNC@@
EndSection

Section "Screen"
	Identifier	"Default Screen"
	Device		"Generic Video Card"
	Monitor		"Generic Monitor"
	DefaultDepth	16
	SubSection "Display"
		Depth		1
		Modes		"1024x768" "800x600" "640x480"
	EndSubSection
	SubSection "Display"
		Depth		4
		Modes		"1024x768" "800x600" "640x480"
	EndSubSection
	SubSection "Display"
		Depth		8
		Modes		"1024x768" "800x600" "640x480"
	EndSubSection
	SubSection "Display"
		Depth		15
		Modes		"1024x768" "800x600" "640x480"
	EndSubSection
	SubSection "Display"
		Depth		16
		Modes		"1024x768" "800x600" "640x480"
	EndSubSection
	SubSection "Display"
		Depth		24
		Modes		"1024x768" "800x600" "640x480"
	EndSubSection
EndSection

Section "ServerLayout"
	Identifier	"Default Layout"
	Screen		"Default Screen"
	InputDevice	"Generic Keyboard"
	InputDevice	"Generic Mouse Serial"
	InputDevice	"Generic Mouse PS/2"
	InputDevice	"Generic Mouse USB"
EndSection

Section "DRI"
	Mode	0666
EndSection
    '''
    from utils.debug import echo_debug
    from utils.shell import joinpath, mkdir
    # Se crea un objeto Xconf
    X = Xconf()
    
    # Se sustituyen los valores
    newx = template.replace('@@DRIVER@@',X.get_card())
    newx = newx.replace('@@BUSID@@',X.get_busid())
    newx = newx.replace('@@HSYNC@@',X.get_hsync())
    newx = newx.replace('@@VSYNC@@',X.get_vsync())
    
    # Se crea el archivo con los nuevos valores
    try:
	dirname = joinpath(root, 'etc/X11/')
	mkdir(dirname)
	filename =  dirname + 'XF86Config-4'
        xf86config = open(filename, 'w')
    except IOError:
        echo_debug('''No se ha podido crear el archivo XF86Config-4 en
                %s/etc/X11/, compruebe que existen los directorios.''' % root \
                , 'ERROR')
        import sys
        sys.exit(1)

    xf86config.write(newx)
    xf86config.close()