Proyecto

General

Perfil

Descargar (3,33 KB) Estadísticas
| Rama: | Revisión:
23a384b9 Elisa
unit globales ;

{$mode objfpc}{$H+}

interface

uses
unix,Classes, SysUtils,clservidor ;

type
Tdatos_equipos_alumno=record
nombre:String;
mac:string;
ip:String;
encendido:Boolean;
end;
TArray_datos_equipos = array of Tdatos_equipos_alumno;
const
TIEMPO_REFRESCO_USUARIO:integer=600;
TIEMPO_REFRESCO_ESTADO_AULA:integer=1800;
TIEMPO_HALLAIP_ENVIADATOS:integer=300;
var
g_ips_alumnos: TArray_datos_equipos;
g_datos_equipo_profesor:string;
g_tsEquiposAlumnos:TStringList;
miservidor:TServidor;
PUERTO_ROOT:integer=37999;
g_usuario:string=' ';
g_host:String='';
g_Dominio:String='';
g_DestinosLibres:Boolean=true;
g_ComandosLibres:Boolean=true;
g_ordenes_root:array of String;
g_procesos_root:array of String;
g_comandoRootEjecutar:String='';
g_procesoRootEjecutar:String='';
g_contador_usuario:integer=0;
g_contador_enviar_datos:integer=290;
g_contador_revision_equipos:integer=1800;
f_servidor_creado:Boolean=false;
g_IpEsteEquipo:String='';
g_tipo_aula:integer=-1;
//g_clessl:String='4rdt867ff12c98d76767';
g_clessl:String='mo0T710bh07MA';

procedure Ejecutar (comando:string);
function HallarDato(Cmd:string):String;
function EncriptaXOR(cadena,clave : string) : string;
function compruebaPasswordRoot(password:String):Boolean;
implementation
function EncriptaXOR(cadena,clave : string) : string;
var
i : integer;
begin
result:='';
for i:=1 to length(cadena) do
result:=result+chr(ord(cadena[i]) xor ord(clave[(i mod length(clave))+1]));
end;

function compruebaPasswordRoot(password:String):Boolean;
const
GENERA_PASSWORD:STRING=' mkpasswd -H md5 %s -S %s ';

HALLA_SALT:String='cat /etc/shadow | grep "^root:" | head -n 1| cut -f3 -d"$"';
HALLA_PASSWORD:String='cat /etc/shadow | grep "^root:" | cut -f4 -d"$" |cut -f1 -d":"';
HALLA_NUMERO:String='cat /etc/shadow | grep "^root:" | cut -f2 -d"$"';
var
clavecorrecta:Boolean;
passwordRoot:String;
passwordGenerado:String;
salt:String;
numero:String;
orden,ordenpasw:String;
begin
try
clavecorrecta:=false;
passwordRoot:=HallarDato(HALLA_PASSWORD);
salt:=HallarDato(HALLA_SALT);
numero:=HallarDato(HALLA_NUMERO);
ordenpasw:='perl -e '+ QuotedStr('print crypt("%s","\$%s\$%s"), "\n"');
ordenpasw:=Format(ordenpasw,[password,numero,salt]);
passwordRoot:='$'+numero+'$'+salt+'$'+passwordRoot;
orden:=Format(GENERA_PASSWORD,[password,salt]);
passwordGenerado:=HallarDato(ordenpasw);
if passwordGenerado = passwordRoot then
clavecorrecta:=true
else
clavecorrecta:=false ;
Result:=clavecorrecta;
except
Result:=false;;
end;
end;
procedure Ejecutar (comando:string);
begin;
unix.fpSystem(comando);
end;
function HallarDato(Cmd:string):String;
var
file1: TextFile;
s,t: ansistring;
n: longint;
j:integer;
begin
j:=0;
n:=popen(file1, Cmd, 'r');
if n=-1 then
begin
result:='';
Exit;
end;
t:='';
while not eof(file1) do begin
Readln(File1,s);
t:=t+s+Chr(10);
inc(j);
end;
pclose(file1);
result := trim(t);
end;

end .