Revisión 131
Añadido por Francisco Paniagua Sánchez hace alrededor de 14 años
scanies-ltsp/trunk/.directory | ||
---|---|---|
[Desktop Entry]
|
||
Icon=./.icon.png
|
||
scanies-ltsp/trunk/.project | ||
---|---|---|
# Gambas Project File 2.0
|
||
Title=scanies-ltsp
|
||
Startup=scaniesltsp
|
||
Version=0.0.23
|
||
TabSize=2
|
scanies-ltsp/trunk/scanies-ltsp | ||
---|---|---|
#!/bin/sh
|
||
### BEGIN INIT INFO
|
||
# Provides: scanies-ltsp
|
||
# Default-Start: 2
|
||
# Short-Description: Demonio para scanies
|
||
### END INIT INFO
|
||
#
|
||
# Autor: Francisco Paniagua S?nchez
|
||
#
|
||
|
||
|
||
PATH=/sbin:/bin:/usr/sbin:/usr/bin
|
||
DAEMON=/usr/bin/scanies-ltsp.gambas
|
||
NAME=scanies-ltsp
|
||
|
||
do_start()
|
||
{
|
||
echo -n "Iniciando $NAME ..."
|
||
/usr/bin/scanies-ltsp.gambas &
|
||
echo "."
|
||
}
|
||
|
||
do_stop()
|
||
{
|
||
echo -n "Parando $NAME ..."
|
||
PID=`ps -AF | grep scanies-ltsp.gambas | grep -v grep | awk '{print $2}'`
|
||
if [ ! -z "$PID" ]; then
|
||
kill -9 $PID
|
||
fi
|
||
PID=`ps -AF | grep _scanies._tcp | grep -v grep | awk '{print $2}'`
|
||
if [ ! -z "$PID" ]; then
|
||
kill -9 $PID
|
||
fi
|
||
echo "."
|
||
}
|
||
|
||
case "$1" in
|
||
start)
|
||
do_start
|
||
;;
|
||
|
||
stop)
|
||
do_stop
|
||
;;
|
||
|
||
restart|reload|force-reload)
|
||
do_stop
|
||
sleep 2
|
||
do_start
|
||
;;
|
||
|
||
*)
|
||
echo "Usage: /etc/init.d/scanies-ltsp {start|stop|restart}" >&2
|
||
exit 1
|
||
;;
|
||
esac
|
||
|
||
exit 0
|
scanies-ltsp/trunk/scaniesltsp.class | ||
---|---|---|
' Gambas class file
|
||
' This program 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 2 of the
|
||
' License, OR (at your option) any later version.
|
||
'
|
||
' This program IS distributed IN the hope that it will be useful, but
|
||
' IS provided AS IS, WITHOUT ANY WARRANTY; without even the implied
|
||
' warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||
' NON-INFRINGEMENT. See the GNU General PUBLIC License FOR more details.
|
||
'
|
||
' You should READ the GNU General PUBLIC License
|
||
' IF you have non, WRITE TO the Free Software
|
||
' Foundation, INC., 59 Temple Place - Suite 330, Boston,
|
||
' # MA 02111-1307, USA.
|
||
' ----------------------------------------------------------------------------
|
||
' ################################################
|
||
' # file name : scaniesltsp.class
|
||
' # created in project : scanies-ltsp
|
||
' # created by : Francisco Paniagua Sánchez
|
||
' # mail : adminies.franciscodeorellana@edu.juntaextremadura.net
|
||
' # created at : 10/03/2009
|
||
' # last test with : gambas-2.7-1
|
||
' ################################################
|
||
|
||
STATIC clase AS scaniesltsp
|
||
PRIVATE proceso AS Process
|
||
|
||
|
||
STATIC PUBLIC SUB Main()
|
||
|
||
clase = NEW scaniesltsp
|
||
|
||
END
|
||
|
||
PUBLIC SUB _New()
|
||
|
||
proceso = SHELL "avahi-browse _workstation._tcp -frpkl | grep \"eth0;IPv4\"" FOR INPUT
|
||
|
||
END
|
||
|
||
PRIVATE FUNCTION obtener_mac(cadena AS String[]) AS String
|
||
|
||
RETURN Right(cadena[2], 2) & ":" & Right(cadena[3], 2) & ":" & Right(cadena[4], 2) & ":" & Right(cadena[5], 2) & ":" & Right(cadena[6], 2) & ":" & Right(cadena[7], 2)
|
||
|
||
END
|
||
|
||
PRIVATE FUNCTION esportatil(servidor AS String, cliente AS String) AS String
|
||
DIM aula AS String[]
|
||
DIM caracteres AS Byte
|
||
DIM resultado AS String
|
||
|
||
aula = Split(servidor, "-")
|
||
caracteres = Len(aula[0])
|
||
|
||
IF (aula[0] = Left(cliente, caracteres)) THEN
|
||
'es cliente ligero mantenemos nombre
|
||
resultado = cliente
|
||
ELSE 'es portatil anexamos nombre clase
|
||
resultado = servidor & "--" & cliente
|
||
ENDIF
|
||
|
||
RETURN resultado
|
||
|
||
END
|
||
|
||
PRIVATE SUB publicar(aula AS String, nombre AS String, direccion AS String, mac AS String)
|
||
DIM texto AS String
|
||
DIM fichero AS String
|
||
DIM dato AS String
|
||
DIM ip AS String[]
|
||
DIM dirip AS String
|
||
DIM nombrefinal AS String
|
||
|
||
fichero = "/tmp/temporalscan"
|
||
|
||
'esto es porque a veces se meten direcciones ipv6
|
||
IF (Left(direccion, 7) = "192.168") THEN
|
||
texto = direccion & "#" & mac
|
||
ELSE
|
||
'Hay que resolverlo a mano
|
||
SHELL "avahi-resolve-host-name -4 " & nombre & ".local > " & fichero WAIT
|
||
|
||
TRY dato = File.Load(fichero)
|
||
|
||
'si el dato es vacio
|
||
IF (dato <> "") THEN
|
||
ip = Split(dato, "\t")
|
||
dirip = Left(ip[1], Len(ip[1]) - 1)
|
||
ELSE
|
||
dirip = "no-ip"
|
||
ENDIF
|
||
|
||
texto = dirip & "#" & mac
|
||
|
||
ENDIF
|
||
nombrefinal = esportatil(aula, nombre)
|
||
SHELL "avahi-publish-service -f " & nombrefinal & " _scanies._tcp 9013 " & texto & " 2>/dev/null &" WAIT
|
||
|
||
END
|
||
|
||
|
||
PUBLIC SUB borrar(nombre AS String)
|
||
DIM fichero AS String
|
||
DIM buscar AS String
|
||
|
||
fichero = "/tmp/buscar"
|
||
|
||
buscar = nombre & " _scanies._tcp"
|
||
|
||
'lo borro de la red
|
||
SHELL "ps aux | grep \"" & buscar & "\" | grep -v grep | awk '{print $2}' > " & fichero WAIT
|
||
'TRY pid = File.Load(fichero)
|
||
SHELL "kill -9 `cat " & fichero & "` 2>/dev/null" WAIT
|
||
|
||
|
||
END
|
||
|
||
|
||
|
||
PUBLIC SUB process_read()
|
||
DIM cadena AS String
|
||
DIM campos AS String[]
|
||
DIM mascampos AS String[]
|
||
DIM nombre AS String
|
||
DIM direccionip AS String
|
||
DIM mac AS String
|
||
DIM pid AS String
|
||
DIM nombreservidor AS String
|
||
DIM failedtemp AS String
|
||
DIM failedhost AS String
|
||
DIM aula AS String[]
|
||
|
||
|
||
nombreservidor = Trim(System.host)
|
||
aula = Split(nombreservidor, ".")
|
||
|
||
|
||
TRY LINE INPUT #LAST, cadena
|
||
|
||
IF NOT (Left(cadena, 6) = "Failed") THEN 'si no hay fallo se analiza
|
||
|
||
campos = Split(cadena, ";")
|
||
|
||
IF (campos[0] = "=") THEN 'esta encendido
|
||
|
||
direccionip = campos[7]
|
||
mascampos = Split(campos[3], "\\")
|
||
mac = obtener_mac(mascampos)
|
||
|
||
'publicar
|
||
publicar(aula[0], mascampos[0], direccionip, mac)
|
||
|
||
|
||
ELSE IF (campos[0] = "-") THEN 'se apaga
|
||
|
||
'fichero = "/tmp/buscar"
|
||
mascampos = Split(campos[3], "\\")
|
||
|
||
'componer nombre
|
||
nombre = esportatil(aula[0], mascampos[0])
|
||
'borrar
|
||
borrar(nombre)
|
||
|
||
ELSE 'descartamos
|
||
PRINT "Log1 (+): " & cadena
|
||
ENDIF
|
||
ELSE
|
||
'formato es: Failed to resolve service 'nombre-equipo [00:30:05:42:26:35]' of type ...
|
||
campos = Split(cadena, " ")
|
||
failedtemp = campos[4]
|
||
'obtener solo el nombre
|
||
mascampos = Split(failedtemp, " ")
|
||
failedhost = Right(mascampos[0], Len(mascampos[0]) - 1)
|
||
'y borrar de la lista
|
||
nombre = esportatil(aula[0], failedhost)
|
||
borrar(nombre)
|
||
|
||
ENDIF
|
||
|
||
END
|
||
|
||
|
||
PUBLIC SUB _free()
|
||
|
||
proceso.Kill
|
||
|
||
END
|
scanies-ltsp/trunk/.settings | ||
---|---|---|
[Breakpoints]
|
||
Count=0
|
||
|
||
[DebugWindow]
|
||
Count=0
|
||
|
||
[FFind]
|
||
SearchIn="Module"
|
||
CaseSensitive=False
|
||
SearchWord=False
|
||
SearchComment=False
|
||
SearchString=True
|
||
|
||
[OpenFile]
|
||
File[1]="scaniesltsp.class:150.15"
|
||
Active=1
|
||
Count=1
|
||
|
||
[Watches]
|
||
Count=0
|
||
|
||
Exportar a: Unified diff
Importación inicial