Proyecto

General

Perfil

Descargar (8,09 KB) Estadísticas
| Rama: | Revisión:
{
Adtos 1.0 Software de gestión de Aulas Tecnológicas

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 clequipoadministrador;
interface
uses IniFiles,unix,ExtCtrls,SysUtils;
type

{ Tequipo }

{ TEquipoAdministrador }

TEquipoAdministrador= class
private
{ Private declarations }

fhost,fip,fmac:string;
fpuerto:integer;
//fnumeroconsultados:integer;
fUsuarioAdministrador, fHomeAdministrador, fdirAdtos:string;
fdirCuestiones,farcCuestion:string;
farcOrdenesRoot,farcmensaje:string;
fIdProcesos:string;
fProcesos:string;
fRealizandoProcesos:Boolean;
procedure CargarPathDirectorios();
function HallarDatos(Cmd: string): String;
function HallarDatosUsuario(const S: string): string;
function hallarHostAdministrador(): string;
function hallarMAC(): string;
function obtenerIP(): string;


public
constructor Create();
property Host:string read fhost write fhost;
property IP:string read fIP;
property Puerto:integer read fPuerto;
//property NumeroConsultados:integer read fnumeroconsultados write fnumeroconsultados;
property IdProcesos:string read fIdProcesos write fIdProcesos;
property Procesos:string read fProcesos write fProcesos;
property RealizandoProcesos:Boolean read fRealizandoProcesos write fRealizandoProcesos;
property UsuarioAdministrador:string read fUsuarioAdministrador;
property HomeAdministrador:string read fHomeAdministrador;
property DirAdtos:string read fdirAdtos;
property DirCuestiones:string read fdirCuestiones;
property ArcCuestion:string read farcCuestion write farcCuestion;
property ArcOrdenesRoot:string read farcOrdenesRoot;
property ArcMensaje:string read farcmensaje;
procedure LeerArchivoOrdenes();
procedure creaArchivoOrdenes();
end;


implementation
uses globales;
constructor TEquipoAdministrador.Create();
begin
fhost:=hallarHostAdministrador;
fRealizandoProcesos:=false;
fIdProcesos:='';
fip:=obtenerIP();
fmac:=hallarMAC();
//fnumeroconsultados:=0;
fUsuarioAdministrador:=HallarDatosUsuario('USER');
fHomeAdministrador:=HallarDatosUsuario('HOME');
CargarPathDirectorios();
end;

procedure TEquipoAdministrador.CargarPathDirectorios();
begin

fdirAdtos:=fHomeAdministrador+PathDelim+'.adtos';
fdirCuestiones:=fHomeAdministrador+PathDelim+'adtos_consultas';
farcOrdenesRoot:='/var/lib/adtos/ordenesadtos1.conf';
farcmensaje:=fdirAdtos +PathDelim+'mensaje.ini';
end;

Function TEquipoAdministrador.HallarDatosUsuario(const S :string):string;
begin
result:=getenvironmentvariable(S);
end;

Procedure TEquipoAdministrador.creaArchivoOrdenes();
const
ORDENES_ROOT:array[0..10] of String=('reboot','halt', 'puppetd -t', 'pkgsync','/etc/init.d/networking restart','/etc/init.d/dhcp3-server restart','ltsp-uptate-sshkeys', 'ltsp-update-image --arch i386','rm -f /var/lib/puppet/ssl/ca/signed/*', 'dpkg -reconfigure locales','/etc/init.d/serveradtosaula start');
PROCESOS_ROOT:array[0..13] of String=('who -a -H','last','free -mt', 'dmesg','lspci','df -H', 'fdisk -l','ifconfig','ls /etc/rc*.d', 'cat /var/log/syslog','cat /var/log/messages','cat /var/log/auth.log','cat /var/log/wtmp','cat /var/log/btmp' );
var
MiFichero:TMeminiFile;
i:integer;
begin
try

try
if not DirectoryExists('/var/lib/adtos') then CreateDir('/var/lib/adtos');
Mifichero:=TMeminifile.Create(farcOrdenesRoot);
with MIfichero do
begin
writeBool('Comandos libres', 'Permitidos',true);
writeBool('Destinos libres','Permitidos',true);
for i:=0 to high(ORDENES_ROOT) do
writeString('Comandos','Comando '+ NumOrdLet(i),ORDENES_ROOT[i]);
for i:=0 to high(PROCESOS_ROOT) do
writeString('Procesos','Proceso '+ NumOrdLet(i),PROCESOS_ROOT[i]);
UpdateFile;
end;
Ejecutar('chmod 644 ' + farcOrdenesRoot)
except
////writeln('Error al crear carpeta');
end;
finally
Mifichero.free;
end;
end;
Procedure TEquipoAdministrador.LeerArchivoOrdenes();
var
MiFichero:TMeminiFile;
k,j,i:integer;
proceso,orden:String;
begin
try
j:=0;
k:=0;
if not FileExists(farcOrdenesRoot) then
begin
Mensaje('No existe el archivo de ordenes ' + farcOrdenesRoot,Aceptar);
exit;
end;
Mifichero:=TMeminifile.Create(farcOrdenesRoot);
SetLength(g_ordenes_root,100);
SetLength (g_procesos_root,100);
with MIfichero do
begin
g_ComandosLibres:=ReadBool('Comandos libres', 'Permitidos',true);
g_DestinosLibres:=ReadBool('Destinos libres','Permitidos',true);
for i:=0 to High(g_ordenes_root) do
begin
orden:=ReadString ('Comandos','Comando '+ NumOrdLet(i),'');
if trim(orden)<>'' then
begin
g_ordenes_root[j]:=orden;
inc(j)
end;
end;
for i:=0 to High(g_procesos_root) do
begin
proceso:=ReadString ('Procesos','proceso '+ NumOrdLet(i),'');
if trim(proceso)<>'' then
begin
g_procesos_root[k]:=proceso;
inc(k)
end;
end;
end;
finally
SetLength(g_ordenes_root,j);
SetLength(g_procesos_root,k);
Mifichero.free;
end;
end;

function TEquipoAdministrador.HallarDatos(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:='';
Mensaje('Error al hallar dato',Aceptar);
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;

function TEquipoAdministrador.hallarHostAdministrador():string;
const
ORDEN_HOST:string='hostname | cut -f1 -d"."';
begin
result:=HallarDatos(ORDEN_HOST);
end;

function TEquipoAdministrador.hallarMAC():string;
const
ORDEN_MAC:string='/sbin/ifconfig | grep "Ethernet" |head -1 | tr -s " " | cut -f5 -d" "';

begin
result:=HallarDatos(ORDEN_MAC);

end;
function TEquipoAdministrador.obtenerIP():string;
const
ORD_IP:string='/sbin/ifconfig eth0 | grep "inet " | cut -f2 -d":" | cut -f1 -d" "';
begin
result:=HallarDatos(ORD_IP);

end;

end.

(21-21/57)