Proyecto

General

Perfil

« Anterior | Siguiente » 

Revisión 50

Añadido por jredrejo hace alrededor de 14 años

modificado nombre de archivo y añadidas cabeceras de copyright

Ver diferencias:

wifi-ltsp/trunk/script2.py
#!/usr/bin/python -tt
# -*- coding: utf-8 -*-
#-*- coding: <iso-8859-1> -*-
#-*- coding: <utf-8> -*-
#-*- coding: <ascii> -*-
# Project: wifi-ltsp
# Module: Announce.py
# Purpose: genera un archivo hostapc.accept para dar acceso a internet a los alumnos.
# Language: Python 2.5
# Date: 07-Feb-2011.
# Ver: 07-Feb-2011.
# Author: Isabel Aparicio Pérez
# Copyright: 2011 - Isabel Aparicio Pérez <prog5pe@edu.juntaextremadura.net>
#
# script2 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.
# Script2 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 como_se_llame. If not, see <http://www.gnu.org/licenses/>.
""" Este programa genera el archivo hostapd.access necesario para que en el momento del logueo del
profesor se de acceso a internet a los alumnos que tienen clase en esa hora con ese profesor. Para ello
tenemos que recoger el dia de la semana y la hora actual que tiene el servidor de aula y con el dia actual
buscar en el servidor nfs el fichero del dia de la semana que corresponde con el dia concreto. El fichero
descargado del servidor nfs se almacena en el servidor de aula en la ruta /wifi con el nombre horario.txt.
Tambien controlamos el usuario que esta logueado en ese preciso momento en el servidor. A partir del usuario
logueado, de la hora del sistema y del fichero descargado del servidor nfs se genera el fichero hostapd.access
con las mac de los alumnos correspondientes.
Isabel Aparicio Pérez
Consejería de Educacion.
prog5pe@edu.juntaextremadura.net
"""
import time
import urllib
import os
import errno
import sys
import re
#Expresiones regulares
fecha=[]
ip=[]
dia_semana={"Mon":"lunes.txt","Tue":"martes.txt","Wed":"miercoles.txt","Thu":"jueves.txt","Fri":"viernes.txt"}
def dia_actual():
"""con esta funcion se obtiene la fecha actual que tiene el servidor de aula"""
fecha = time.asctime()
return fecha
def fichero_semana(fecha):
"""Con esta funcion se obtiene la parte de la fecha actual que corresponde con el dia de la semana"""
dia= fecha[0:3]
if dia not in ["Mon","Tue","Web","Thu","Fri"]:
print "El formato de la fecha del sistema no es el esperado"
# break
else:
fichero=dia_semana[dia]
return fichero
def hora_actual(fecha):
"""Con esta funcion se obtiene la hora actual del sistema sin los : de forma que la 08:45 se representaran
como la 0845"""
hora= fecha[11:13]+fecha[14:16]
h=int(hora)
if (h<int(0000) or h>int(2500)):
print "El formato de la hora del sistema no es el esperado"
# break
else:
return hora
def descargar_fichero(fichero):
"""funcion que se encarga de descargar el fichero del dia de la semana correspondiente al dia actual del
servidor nfs y colocarlo en la ubicacion correcta en el servidor de terminales con el nombre de horario.txt"""
file="http://servidor/wifi/"+fichero
print file
destino="/wifi/horario.txt"
destino2="/wifi"
if not os.path.exists(destino2):
print "La ruta destino no existe y hay que crearla"
try:
os.makedirs(destino2)
except OSError:
print "Hay algun error a la hora de crear el directorio /wifi en el servidor de aula"
urllib.urlretrieve(file, destino)
return destino
def devuelve_usuario():
"""con esta funcion recogemos el usuario que esta logueado en ese momento en el ordenador, seguira intentandolo
hasta que se loguee antes"""
resultado = sys.argv[1]
return resultado
def crea_hostapd(destino,resultado,hora):
"""con esta funcion generamos el fichero hostapd con las mac correspondientes a los alumnos a los que se
les va a dar acceso a internet y lo colocamos en la ruta correcta."""
if not os.path.exists(destino):
print "Hay un error el el fichero horario.txt en el servidor de aula"
else:
f=open(destino,"r")
if not os.path.exists("/etc/hostapd"):
try:
os.makedirs("/etc/hostapd")
except IOError:
print "Ha habido algun error a la hora de crear el directorio /etc/hostapd"
# break
if not os.access("/etc/hostapd", os.W_OK):
print "No tiene permisos de escritura sobre el directorio /etc/hostapd"
# break
else:
g=open("/etc/hostapd/hostapd.accept","w")
while True:
dato=f.readline()
if not dato:
break
else:
lin=dato.split("|")
if lin[0]==resultado:
if hora>lin[2] and hora<lin[3]:
g.write(lin[1])
g.write("\n")
f.close()
g.close()
return g
def reinicia_hostapd():
resultado = os.system("invoke-rc.d hostapd restart")
if __name__ == '__main__':
dia_hoy=""
hora=""
user=""
fich=""
hos=""
res=""
f=""
dia_hoy=dia_actual()
hora=hora_actual(dia_hoy)
fich=fichero_semana(dia_hoy)
f=descargar_fichero(fich)
user=devuelve_usuario()
hos=crea_hostapd(f,user,hora)
res=reinicia_hostapd()
if hos=="":
print "El script no ha funcionado correctamente"
else:
print "Todo ha ido bien"
wifi-ltsp/trunk/transformaArchivos.py
#!/usr/bin/python -tt
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Project: wifi-ltsp
# Module: transformaArchivos.py
# Purpose: Genera archivo de macs con horarios desde Rayuela y Ldap
# Language: Python 2.5
# Date: 03-Feb-2011.
# Ver: 07-Feb-2011.
# Author: Francisco Mora Sánchez
# Copyright: 2011 - Francisco Mora Sánchez <adminies.maestrojuancalero@edu.juntaextremadura.net>
#
# wifi-ltsp 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.
# Script2 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 wifi-ltsp. If not, see <http://www.gnu.org/licenses/>.
""" Programa para generar los archivos necesarios para permitir
que los portátiles de los alumnos puedan unirse al punto de acceso
wifi-ltsp/trunk/configura_hostapd.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Project: wifi-ltsp
# Module: configura_hostapd.py
# Purpose: genera un archivo hostapc.accept para dar acceso a internet a los alumnos.
# Language: Python 2.5
# Date: 07-Feb-2011.
# Ver: 07-Feb-2011.
# Author: Isabel Aparicio Pérez
# Copyright: 2011 - Isabel Aparicio Pérez <prog5pe@edu.juntaextremadura.net>
#
# wifi-ltsp 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.
# Script2 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 wifi-ltsp. If not, see <http://www.gnu.org/licenses/>.
""" Este programa genera el archivo hostapd.access necesario para que en el momento del logueo del
profesor se de acceso a internet a los alumnos que tienen clase en esa hora con ese profesor. Para ello
tenemos que recoger el dia de la semana y la hora actual que tiene el servidor de aula y con el dia actual
buscar en el servidor nfs el fichero del dia de la semana que corresponde con el dia concreto. El fichero
descargado del servidor nfs se almacena en el servidor de aula en la ruta /wifi con el nombre horario.txt.
Tambien controlamos el usuario que esta logueado en ese preciso momento en el servidor. A partir del usuario
logueado, de la hora del sistema y del fichero descargado del servidor nfs se genera el fichero hostapd.access
con las mac de los alumnos correspondientes.
Isabel Aparicio Pérez
Consejería de Educacion.
prog5pe@edu.juntaextremadura.net
"""
import time
import urllib
import os
import errno
import sys
import re
#Expresiones regulares
fecha=[]
ip=[]
dia_semana={"Mon":"lunes.txt","Tue":"martes.txt","Wed":"miercoles.txt","Thu":"jueves.txt","Fri":"viernes.txt"}
def dia_actual():
"""con esta funcion se obtiene la fecha actual que tiene el servidor de aula"""
fecha = time.asctime()
return fecha
def fichero_semana(fecha):
"""Con esta funcion se obtiene la parte de la fecha actual que corresponde con el dia de la semana"""
dia= fecha[0:3]
if dia not in ["Mon","Tue","Web","Thu","Fri"]:
print "El formato de la fecha del sistema no es el esperado"
# break
else:
fichero=dia_semana[dia]
return fichero
def hora_actual(fecha):
"""Con esta funcion se obtiene la hora actual del sistema sin los : de forma que la 08:45 se representaran
como la 0845"""
hora= fecha[11:13]+fecha[14:16]
h=int(hora)
if (h<int(0000) or h>int(2500)):
print "El formato de la hora del sistema no es el esperado"
# break
else:
return hora
def descargar_fichero(fichero):
"""funcion que se encarga de descargar el fichero del dia de la semana correspondiente al dia actual del
servidor nfs y colocarlo en la ubicacion correcta en el servidor de terminales con el nombre de horario.txt"""
file="http://servidor/wifi/"+fichero
print file
destino="/wifi/horario.txt"
destino2="/wifi"
if not os.path.exists(destino2):
print "La ruta destino no existe y hay que crearla"
try:
os.makedirs(destino2)
except OSError:
print "Hay algun error a la hora de crear el directorio /wifi en el servidor de aula"
urllib.urlretrieve(file, destino)
return destino
def devuelve_usuario():
"""con esta funcion recogemos el usuario que esta logueado en ese momento en el ordenador, seguira intentandolo
hasta que se loguee antes"""
resultado = sys.argv[1]
return resultado
def crea_hostapd(destino,resultado,hora):
"""con esta funcion generamos el fichero hostapd con las mac correspondientes a los alumnos a los que se
les va a dar acceso a internet y lo colocamos en la ruta correcta."""
if not os.path.exists(destino):
print "Hay un error el el fichero horario.txt en el servidor de aula"
else:
f=open(destino,"r")
if not os.path.exists("/etc/hostapd"):
try:
os.makedirs("/etc/hostapd")
except IOError:
print "Ha habido algun error a la hora de crear el directorio /etc/hostapd"
# break
if not os.access("/etc/hostapd", os.W_OK):
print "No tiene permisos de escritura sobre el directorio /etc/hostapd"
# break
else:
g=open("/etc/hostapd/hostapd.accept","w")
while True:
dato=f.readline()
if not dato:
break
else:
lin=dato.split("|")
if lin[0]==resultado:
if hora>lin[2] and hora<lin[3]:
g.write(lin[1])
g.write("\n")
f.close()
g.close()
return g
def reinicia_hostapd():
resultado = os.system("invoke-rc.d hostapd restart")
if __name__ == '__main__':
dia_hoy=""
hora=""
user=""
fich=""
hos=""
res=""
f=""
dia_hoy=dia_actual()
hora=hora_actual(dia_hoy)
fich=fichero_semana(dia_hoy)
f=descargar_fichero(fich)
user=devuelve_usuario()
hos=crea_hostapd(f,user,hora)
res=reinicia_hostapd()
if hos=="":
print "El script no ha funcionado correctamente"
else:
print "Todo ha ido bien"
wifi-ltsp/trunk/parsehostapd/parsehostapd.py
#!/usr/bin/python -tt
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Project: wifi-ltsp
# Module: parsehostapd.py
# Purpose: Parsea el fichero /etc/hostapd/hostapd.conf
# Language: Python 2.5
# Date: 26-Enero-2011.
# Ver: 07-Feb-2011.
# Author: Francisco Mora Sánchez
# Copyright: 2011 - Francisco Mora Sánchez <adminies.maestrojuancalero@edu.juntaextremadura.net>
#
# wifi-ltsp 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.
# Script2 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 wifi-ltsp. If not, see <http://www.gnu.org/licenses/>.
""" Módulo que contiene la función selectbestchannel()
Función que escanea el espectro de canales de redes
wifi-ltsp/trunk/parsehostapd/escanea.py
#!/usr/bin/python -tt
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Project: wifi-ltsp
# Module: escanea.py
# Purpose: Busca el canal libre más adecuado para la wifi
# Language: Python 2.5
# Date: 03-Feb-2011.
# Ver: 07-Feb-2011.
# Author: Francisco Mora Sánchez
# Copyright: 2011 - Francisco Mora Sánchez <adminies.maestrojuancalero@edu.juntaextremadura.net>
#
# wifi-ltsp 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.
# Script2 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 wifi-ltsp. If not, see <http://www.gnu.org/licenses/>.
"""Módulo auxiliar para obtener información a través
del comando iwlist, perteneciente a las herramientas
wireless-tools

Exportar a: Unified diff