desarrollosconsejeria/adtos-server/1.7-0/adtos/clenviarcarpetaroot.pas @ 23a384b9
23a384b9 | Elisa | {
|
|
Adtos 1.0 Software de gestión de Aulas Tecnológicas
|
|||
Copyright (C) 2008-2009, Consejería de Educación,Junta de Extremadura
|
|||
Programación: Manuel Narváez Martínez <mnarvaez007@gmail.com>
|
|||
Diseño gráfico: Ana María Zamora Moreno
|
|||
Desarrollado con Lazarus 0.9.26
|
|||
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 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 this program; if not, write to the Free Software
|
|||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|||
}
|
|||
unit clenviarcarpetaroot;
|
|||
{$mode objfpc}{$H+}
|
|||
interface
|
|||
uses
|
|||
globales,Classes,IdSSLOpenSSL, SysUtils,IdTCPClient;
|
|||
type
|
|||
ThrEnviarCarpetaRoot = class(TThread)
|
|||
private
|
|||
{ Private declarations }
|
|||
fnequipo:integer;
|
|||
fcarpeta:string;
|
|||
fhost,fcomando:string;
|
|||
fIdSSLIOHandlerSocketOpenSSL: TIdSSLIOHandlerSocketOpenSSL;
|
|||
fcliente:TIdTcpClient;
|
|||
fPuerto:integer;
|
|||
fcodigo:integer;
|
|||
protected
|
|||
procedure Execute; override;
|
|||
public
|
|||
constructor Create(nequipo:integer;host,comando,carpeta:string;codigo:integer);
|
|||
end;
|
|||
implementation
|
|||
constructor ThrEnviarCarpetaRoot.Create(nequipo:integer;host,comando,carpeta:string;codigo:integer);
|
|||
begin
|
|||
inherited Create(true);
|
|||
fnequipo:=nequipo;
|
|||
fhost:=host;
|
|||
FreeOnTerminate:=True;
|
|||
fcarpeta:=carpeta;
|
|||
fcomando:=comando;
|
|||
fcodigo:=codigo;
|
|||
fPuerto:=PUERTO_ROOT;
|
|||
end;
|
|||
procedure ThrEnviarCarpetaRoot.Execute;
|
|||
var
|
|||
j:integer;
|
|||
carpeta_enviada:Boolean;
|
|||
archivo_carpeta_enviada,archivo:string;
|
|||
carpeta_comprimida:Boolean=false;
|
|||
crcontador:integer=0;
|
|||
padre:string;
|
|||
micarpeta:string;
|
|||
orden:string;
|
|||
lstream:TFileStream;
|
|||
begin
|
|||
try
|
|||
try
|
|||
archivo_carpeta_enviada:='/tmp/adtos_cpenv_'+ inttostr(fnequipo)+'.tmp';
|
|||
micarpeta:=ExtractFileName(fcarpeta);
|
|||
padre:=ExtractFilePath(fcarpeta);
|
|||
orden:='cd "'+padre+'"; tar czvf adtos-carpeta'+inttostr(fnequipo)+'.tar.gz "'+micarpeta+'";touch '+archivo_carpeta_enviada;
|
|||
Ejecutar(orden);
|
|||
while ((crcontador<500)and (carpeta_comprimida = false) )do
|
|||
begin
|
|||
carpeta_comprimida:=FileExists(archivo_carpeta_enviada);
|
|||
inc(crcontador);
|
|||
sleep(100);
|
|||
end;
|
|||
sleep(1000);
|
|||
archivo:=padre+'adtos-carpeta'+inttostr(fnequipo)+'.tar.gz';
|
|||
lstream:= TFileStream.Create(archivo,fmOpenRead + fmShareDenyNone);
|
|||
except
|
|||
writeln('Error al crear la carpeta');
|
|||
lstream.Free;
|
|||
exit;
|
|||
end;
|
|||
fIdSSLIOHandlerSocketOpenSSL:= TIdSSLIOHandlerSocketOpenSSL.Create(nil);
|
|||
fIdSSLIOHandlerSocketOpenSSL.Port:= fpuerto;
|
|||
fIdSSLIOHandlerSocketOpenSSL.SSLOptions.Mode:=sslmClient;
|
|||
fIdSSLIOHandlerSocketOpenSSL.SSLOptions.Method:=sslvSSLv3;
|
|||
fIdSSLIOHandlerSocketOpenSSL.SSLOptions.SSLVersions:=[sslvSSLv3];
|
|||
fcliente:=TidTcpClient.create(nil);
|
|||
fcliente.IOHandler:=fIdSSLIOHandlerSocketOpenSSL;
|
|||
fcliente.Host:=fhost;
|
|||
fcliente.port:=37999;
|
|||
carpeta_enviada:=false;
|
|||
j:=0;
|
|||
while (not carpeta_enviada) and (j<7) do
|
|||
begin
|
|||
try
|
|||
Sleep(2*j*1000);
|
|||
inc(j);
|
|||
try
|
|||
fcliente.ConnectTimeout:=1000+1000*j*2;
|
|||
fcliente.connect;
|
|||
fcliente.GetResponse(200);
|
|||
fcliente.sendcmd(fcomando,fcodigo);
|
|||
fcliente.IOHandler.writebufferopen;
|
|||
fcliente.IOHandler.Write(lstream,0,true);
|
|||
fcliente.IOHandler.WriteBufferclose;
|
|||
carpeta_enviada:=true;
|
|||
except
|
|||
if fcliente.Connected then fcliente.Disconnect;
|
|||
end
|
|||
finally
|
|||
if fcliente.Connected then fcliente.Disconnect;
|
|||
end
|
|||
end;
|
|||
finally
|
|||
fcliente.free;
|
|||
fIdSSLIOHandlerSocketOpenSSL.Free;
|
|||
lstream.free;
|
|||
if fileexists(archivo) then
|
|||
deletefile(archivo);
|
|||
end;
|
|||
end;
|
|||
end.
|