|
{
|
|
Adtos 1.6-5 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.30
|
|
|
|
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 clcomandosroot ;
|
|
|
|
{$mode objfpc}{$H+}
|
|
interface
|
|
|
|
uses
|
|
Classes,SysUtils, IdComponent, IdSSLOpenSSL, IdTCPClient;
|
|
|
|
type
|
|
ThrComandosRoot = class(TThread)
|
|
private
|
|
{ Private declarations }
|
|
fcodigo:integer;
|
|
fhost,fcomando:string;
|
|
fcliente:TIdTcpClient;
|
|
fIdSSLIOHandlerSocketOpenSSL: TIdSSLIOHandlerSocketOpenSSL;
|
|
protected
|
|
procedure Execute; override;
|
|
public
|
|
constructor Create(codigo:integer;host,comando:string);
|
|
end;
|
|
|
|
|
|
implementation
|
|
constructor ThrComandosRoot.Create(codigo:integer;host,comando:string);
|
|
begin
|
|
inherited Create(true);
|
|
fcodigo:=codigo;
|
|
fhost:=host;
|
|
fcomando:=comando;
|
|
FreeOnTerminate:=True;
|
|
end;
|
|
|
|
procedure ThrComandosRoot.Execute;
|
|
var
|
|
j:integer;
|
|
orden_enviada:Boolean;
|
|
begin
|
|
try
|
|
try
|
|
fIdSSLIOHandlerSocketOpenSSL:= TIdSSLIOHandlerSocketOpenSSL.Create(nil);
|
|
fIdSSLIOHandlerSocketOpenSSL.Port:= 37999;
|
|
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;
|
|
j:=0;
|
|
orden_enviada:=false;
|
|
while (not orden_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);
|
|
orden_enviada:=true;
|
|
except
|
|
if fcliente.Connected then fcliente.Disconnect;
|
|
end
|
|
finally
|
|
if fcliente.Connected then fcliente.Disconnect;
|
|
|
|
end
|
|
end;
|
|
except
|
|
//writeln('Error al ejecutar comando root');
|
|
end;
|
|
finally
|
|
fIdSSLIOHandlerSocketOpenSSL.Free;
|
|
fcliente.free;
|
|
end;
|
|
|
|
end;
|
|
|
|
end.
|
|
|