Proyecto

General

Perfil

« Anterior | Siguiente » 

Revisión 517

Repositorio movido

Ver diferencias:

autorename/puppet/instala_autorename.pp
##############################################################################
# Project: Autorename
# Purpose: Puppet task
# Date: 23-May-2012.
# Author: Manuel Mora Gordillo
# Copyright: 2012 - Manuel Mora Gordillo <manuel.mora.gordillo @nospam@ gmail.com>
#
# Autorename is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# Autorename is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with Autorename. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
class instala_autorename {
file { "/var/cache/autorename-client_0.1-12_all.deb":
owner => root, group => root, mode => 644,
source => "puppet://puppetinstituto/files/autorename-client_0.1-12_all.deb"
}
exec { "instalar_paquete_autorename" :
path => "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
command => "dpkg -i /var/cache/autorename-client_0.1-12_all.deb",
unless => "dpkg -l autorename-client | grep ii | grep 0.1-12",
require => File["/var/cache/autorename-client_0.1-12_all.deb"]
}
}
autorename/puppet/LEEME
Instrucciones:
- Copiar el paquete autorename-client a /etc/puppet/files
- Copiar la tarea "instala_autorename.pp a /etc/puppet/manifest/clases/portatil-alumno/
- Añadir la clase "instala_autorename" a las clases especificas de los portatiles de alumnos
- Añadir "autorename-client" a /etc/puppet/files/mayhave.portatil y /etc/puppet/files/mayhave.portatil-basico para que no se desinstale
autorename/trunk/server.py
#!/usr/bin/env python
##############################################################################
# -*- coding: utf-8 -*-
# Project: Autorename
# Module: server.py
# Purpose: Autorename for laptops
# Language: Python 2.5
# Date: 23-Apr-2012.
# Ver: 23-Apr-2012.
# Author: Manuel Mora Gordillo
# Copyright: 2012 - Manuel Mora Gordillo <manuito @nospam@ gmail.com>
#
# Autorename is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# Autorename is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with Autorename. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from SimpleXMLRPCServer import SimpleXMLRPCServer
import socket, os, time
def getDomain():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
dom ='sindominio'
try:
s.connect(("servidor", 0))
inet_address= s.getsockname()[0]
nombre=socket.gethostbyname_ex(socket.gethostname())[0].split(".")
if len(nombre)>1:
dom=nombre[1]
except:
pass
return dom
def ping():
return "pong"
def removeCerts (hostname, newHostname):
os.system("puppetca --clean "+hostname)
os.system("puppetca --clean "+hostname+"."+getDomain())
os.system("rm -f /var/lib/puppet/yaml/node/"+hostname+".*")
os.system("rm -f /var/lib/puppet/yaml/facts/"+hostname+".*")
os.system("puppetca --clean "+newHostname)
os.system("puppetca --clean "+newHostname+"."+getDomain())
os.system("rm -f /var/lib/puppet/yaml/node/"+newHostname+".*")
os.system("rm -f /var/lib/puppet/yaml/facts/"+newHostname+".*")
return True
def setLog(text):
log="/var/log/autorename-server.log"
f = open(log,"a")
f.write(text+"#"+time.strftime("%Y-%m-%d %H:%M:%S")+"\n")
f.close()
server = SimpleXMLRPCServer (("servidor", 9997))
server.register_function (removeCerts)
server.register_function (ping)
server.register_function (setLog)
server.serve_forever ()
autorename/trunk/autorename
#!/bin/sh
### BEGIN INIT INFO
# Provides: autorename
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Autorename RPC Server
# Description: Debian init script for Autorename RCP Server root monitoring daemon
### END INIT INFO
#
# Author: Manuel Mora Gordillo <manuito at gmail.com>
#
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=autorenameRPCServer
message="Autorename RPC Server daemon"
rundir=/var/run
pidfile=$rundir/autorename/rpcServer.pid
logfile=/var/log/autorename-server.log
daemon="/usr/bin/python"
application=/usr/share/autorename-server/server.py
test -x $DAEMON || exit 0
test -r $application || exit 0
rm -rf /tmp/autorename*
. /lib/lsb/init-functions
if [ ! -d /var/run/autorename ]; then
rm -rf /var/run/autorename
mkdir -p /var/run/autorename
fi
case "$1" in
start)
log_daemon_msg "Starting $message"
[ ! -f $logfile ] && touch $logfile
start-stop-daemon --start --quiet --pidfile=$pidfile --make-pidfile --exec $daemon $application &
log_end_msg 0
;;
stop)
log_daemon_msg "Stopping $message"
start-stop-daemon --stop --quiet --pidfile $pidfile
rm -rf /tmp/autorename*
log_end_msg 0
;;
reload)
log_daemon_msg "Reloading $message"
start-stop-daemon --stop --quiet --signal HUP --pidfile $pidfile &
log_end_msg 0
;;
restart|force-reload)
log_daemon_msg "Restarting $message"
$0 stop
sleep 1
$0 start
log_end_msg 0
;;
*)
log_success_msg "Usage: $0 {start|stop|restart|force-reload|reload}"
exit 1
;;
esac
exit 0
autorename/trunk/debian/autorename-client.postinst
#!/bin/sh
# postinst script for autorename-client
#
# see: dh_installdeb(1)
set -e
case "$1" in
configure)
DIR="gdm"
if [ -f "/etc/init.d/gdm3" ]; then
DIR="gdm3"
fi
if [ ! -f /etc/$DIR/PostLogin/Default ]; then
echo "#!/bin/sh" >> /etc/$DIR/PostLogin/Default
fi
if ! grep "/usr/share/autorename-client/client.py \$LOGNAME" /etc/$DIR/PostLogin/Default
then
echo "/usr/share/autorename-client/client.py \$LOGNAME" >> /etc/$DIR/PostLogin/Default
fi
chmod +x /etc/$DIR/PostLogin/Default
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
exit 0
autorename/trunk/debian/autorename-client.postrm
#!/bin/sh
# postrm script for autorename-client
#
set -e
DIR="gdm"
if [ -f "/etc/init.d/gdm3" ]; then
DIR="gdm3"
fi
case "$1" in
remove)
if [ -f "/etc/$DIR/PostLogin/Default" ]; then
sed 's/\/usr\/share\/autorename-client\/client.py \$LOGNAME//g' /etc/$DIR/PostLogin/Default > /tmp/DefaultGDM.tmp
mv /tmp/DefaultGDM.tmp /etc/$DIR/PostLogin/Default
fi
;;
purge)
if [ -f "/etc/$DIR/PostLogin/Default" ]; then
sed 's/\/usr\/share\/autorename-client\/client.py \$LOGNAME//g' /etc/$DIR/PostLogin/Default > /tmp/DefaultGDM.tmp
mv /tmp/DefaultGDM.tmp /etc/$DIR/PostLogin/Default
fi
rm -f /var/log/autorename-client.log
rm -rf /var/lib/autorename-client
;;
upgrade|abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postrm called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
exit 0
autorename/trunk/debian/control
Source: autorename
Section: python
Priority: extra
Maintainer: Manuel Mora Gordillo <manuito@gmail.com>
Build-Depends: debhelper (>= 7.0.50~), python-support (>= 0.3)
Build-Depends-Indep: python
Package: autorename-client
Architecture: all
Depends: python
Conflicts: autorename-server
Description: Autorenombrado de portatiles
Autorename gestiona el autorenombrado de portatiles asignando
al portatil el nombre del usuario al que esta asignado
Package: autorename-server
Architecture: all
Depends: python
Conflicts: autorename-client
Description: Autorenombrado de portatiles
Tras el autorenombrado del portatil, el servidor borra los
certificados puppet del mismo y registra el cambio
autorename/trunk/debian/autorename-client.install
client.py usr/share/autorename-client
autorename/trunk/debian/compat
7
autorename/trunk/debian/autorename-server.dirs
usr/share/autorename-server
etc/init.d
autorename/trunk/debian/autorename-server.postinst
#!/bin/sh
# postinst script for autorename-server
#
# see: dh_installdeb(1)
set -e
case "$1" in
configure)
chmod +x /etc/init.d/autorename
update-rc.d autorename defaults
/etc/init.d/autorename start
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
exit 0
autorename/trunk/debian/changelog
autorename (0.1-12) unstable; urgency=low
* Changes in hosts file
-- Manuel Mora Gordillo <manuito@gmail.com> Wed, 30 May 2012 10:30:00 +0200
autorename (0.1-11) unstable; urgency=low
* Changes in postinst file. Logins to rename 10
-- Manuel Mora Gordillo <manuito@gmail.com> Mon, 9 May 2012 11:07:00 +0200
autorename (0.1-10) unstable; urgency=low
* Remove yaml files
-- Manuel Mora Gordillo <manuito@gmail.com> Mon, 3 May 2012 11:53:00 +0200
autorename (0.1-9) unstable; urgency=low
* Logging Serial Number of the computer
-- Manuel Mora Gordillo <manuito@gmail.com> Mon, 27 Apr 2012 11:14:00 +0200
autorename (0.1-8) unstable; urgency=low
* Changing order rules
-- Manuel Mora Gordillo <manuito@gmail.com> Mon, 27 Apr 2012 11:14:00 +0200
autorename (0.1-7) unstable; urgency=low
* Bug autorename-client.postinst: gdm and gdm3
-- Manuel Mora Gordillo <manuito@gmail.com> Mon, 26 Apr 2012 12:31:00 +0200
autorename (0.1-6) unstable; urgency=low
* Bug autorename-client.postinst
-- Manuel Mora Gordillo <manuito@gmail.com> Mon, 26 Apr 2012 12:31:00 +0200
autorename (0.1-5) unstable; urgency=low
* Change autorename-client.dirs
-- Manuel Mora Gordillo <manuito@gmail.com> Mon, 26 Apr 2012 12:00:00 +0200
autorename (0.1-4) unstable; urgency=low
* Purge and remove separated
-- Manuel Mora Gordillo <manuito@gmail.com> Mon, 25 Apr 2012 10:36:00 +0200
autorename (0.1-3) unstable; urgency=low
* Add gdm3 option
-- Manuel Mora Gordillo <manuito@gmail.com> Mon, 25 Apr 2012 10:36:00 +0200
autorename (0.1-2) unstable; urgency=low
* Add post remove rules
-- Manuel Mora Gordillo <manuito@gmail.com> Mon, 24 Apr 2012 09:51:00 +0200
autorename (0.1-1) unstable; urgency=low
* First Debian package
-- Manuel Mora Gordillo <manuito@gmail.com> Mon, 23 Apr 2012 19:40:00 +0200
autorename/trunk/debian/autorename-server.postrm
#!/bin/sh
# postrm script for autorename-server
#
set -e
case "$1" in
remove)
update-rc.d autorename remove
;;
purge)
update-rc.d autorename remove
rm -f /var/log/autorename-server.log
;;
upgrade|abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postrm called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
exit 0
autorename/trunk/debian/copyright
This work was packaged for Debian by:
Manuel Mora Gordillo <manuito@gmail.com> on Mon, 23 Apr 2012 19:40:00 +0200
Upstream Author(s):
Manuel Mora Gordillo <manuito @no-spam@ gmail.com>
Copyright:
Copyright (C) 2012 Manuel Mora Gordillo
License:
Autorename is Licensed under the LGPL license version 3
see "/usr/share/common-licenses/LGPL-3".
The Debian packaging is:
Copyright (C) 2012 Manuel Mora Gordillo <manuito@gmail.com>
and is licensed under the GPL version 3,
see "/usr/share/common-licenses/GPL-3".
autorename/trunk/debian/autorename-server.prerm
#!/bin/sh
# prerm script for autorename-server
#
set -e
case "$1" in
remove|purge|upgrade)
/etc/init.d/autorename stop
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postrm called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
exit 0
autorename/trunk/debian/autorename-server.install
server.py usr/share/autorename-server
autorename /etc/init.d
autorename/trunk/debian/rules
#!/usr/bin/make -f
# -*- makefile -*-
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
%:
dh $@
autorename/trunk/debian/autorename-client.dirs
var/lib/autorename-client
usr/share/autorename-client
autorename/trunk/client.py
#!/usr/bin/env python
##############################################################################
# -*- coding: utf-8 -*-
# Project: Autorename
# Module: client.py
# Purpose: Autorename for laptops
# Language: Python 2.5
# Date: 23-Apr-2012.
# Ver: 23-Apr-2012.
# Author: Manuel Mora Gordillo
# Copyright: 2012 - Manuel Mora Gordillo <manuito @nospam@ gmail.com>
#
# Autorename is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# Autorename is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with Autorename. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import sys, os, socket, time, shutil, xmlrpclib
loginsToRename=10
lastLogin=sys.argv[1]
loginsDir="/var/lib/autorename-client"
loginsFile=loginsDir+"/userlogins"
log="/var/log/autorename-client.log"
if not os.path.isdir(loginsDir):
os.mkdir(loginsDir)
# Escribimos el ultimo logueo
f = open(loginsFile,"a")
f.write(lastLogin+"\n")
f.close()
# Obtenemos los ultimos x logueos
f = open(loginsFile,"r")
f.seek(0,2)
fsize = f.tell()
f.seek (max (fsize-1024, 0), 0)
listLastLogins = f.readlines()[-loginsToRename:]
f.close()
# Le quitamos los saltos de linea
for x, i in enumerate(listLastLogins):
listLastLogins[x]=i.replace("\n","")
hostname = socket.gethostname()
# Si hay al menos x logins, todos son del ultimo usuario logueado
# y el nombre del equipo se llama de una forma diferente, renombramos
if len(listLastLogins)>=loginsToRename and listLastLogins.count(lastLogin)==loginsToRename and lastLogin!=hostname:
# Comprobamos que haya comunicacion con el Servidor
try:
server = xmlrpclib.ServerProxy("http://servidor:9997")
server.ping()
except:
exit()
newHostname = lastLogin
f = open("/etc/hostname","w")
f.write(newHostname)
f.close()
f = open("/etc/hosts","w")
f.write("127.0.0.1 localhost\n")
f.write("127.0.1.1 "+newHostname+"\n\n")
f.write("# The following lines are desirable for IPv6 capable hosts\n")
f.write("::1 localhost ip6-localhost ip6-loopback\n")
f.write("fe00::0 ip6-localnet\n")
f.write("ff00::0 ip6-mcastprefix\n")
f.write("ff02::1 ip6-allnodes\n")
f.write("ff02::2 ip6-allrouters")
f.close()
os.system("hostname -F /etc/hostname")
# Obtenemos el numero de serie de la maquina
f = open("/sys/class/dmi/id/product_serial","r")
serialNumber = f.read().replace("\n","")
f.close()
# Se lo comunicamos al servidor para que borre los certificados
try:
server.removeCerts(hostname, newHostname)
server.setLog(hostname+"#"+newHostname+"#"+serialNumber)
except:
pass
# Borramos los certificados locales y reiniciamos puppet
if os.path.isdir("/var/lib/puppet/ssl"):
shutil.rmtree("/var/lib/puppet/ssl")
os.system("/etc/init.d/puppet restart")
# Guardamos en el log
f = open(log,"a")
f.write(hostname+"#"+newHostname+"#"+serialNumber+"#"+time.strftime("%Y-%m-%d %H:%M:%S")+"\n")
f.close()
autorename/LEEME
##############################################################################
# Project: Autorename
# Purpose: Autorename of laptops
# Language: Python 2.5
# Date: 23-Apr-2012.
# Author: Manuel Mora Gordillo
# Copyright: 2012 - Manuel Mora Gordillo <manuito @nospam@ gmail.com>
#
# Autorename is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# Autorename is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with Autorename. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
Descripción
En el cambio de curso escolar se hace imprescindible la reasignación de portátiles
de unos alumnos a otros. Cada equipo se nombra con el username del alumno por lo
que al reasignar el portátil hay que renombrar el equipo.
Para aumentar la productividad del Administrador Informático se requieren automatizar
algunos procesos. El motivo de este software es el autorenombrado del portátil sin
ser necesaria la intervención del Administrador Informático.
Información técnica
Paquetes:
- autorename-client: Hay que instalarlo en los portátiles. Registra cada autenticación
de usuario y renombra el equipo si se cumplen cuatro condiciones:
* Al menos hay 10 autenticaciones de usuario
* Las últimas 10 autenticaciones tienen que ser del mismo usuario
* El equipo se llama de forma diferente al username de las últimas autenticaciones
* Hay conexión con el Servidor NFS
Si el autorenombrado se ha llevado a cabo se lo comunica al Servidor NFS
- autorename-server: Hay que instalarlo en el servidor NFS. Está a la escucha y borra los
certificados puppet cuando un portátil es renombrado.
Ficheros:
- autorename-client:
* /etc/gdm/PostLogin/Default: ejecuta client.py cuando un usuario se ha autenticado
pasándole como parámetro el username
* /usr/share/autorename-client/client.py: el script que realiza todo el proceso
* /var/lib/autorename-client/userlogin: donde se registran las autenticaciones de usuario
* /var/log/autorename-client.log: cuando un equipo es renombrado se registra con el
siguiente formato: nombre_actual#nuevo_nombre#fecha_hora
- autorename-server:
* /usr/share/autorename-server/server.py: script que realiza el proceso de escucha y
borrado de certificados puppet
* /etc/init.d/autorename: demonio del script server.py
* /var/log/autorename-server.log: registra cuando un equipo se ha renombrado con el
siguiente formato: nombre_actual#nuevo_nombre#numero_serie#fecha_hora
Repositorio movido a http://github.com/manumora/autorename

Exportar a: Unified diff