Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJKM committed May 28, 2018
1 parent 33fc1b4 commit 7864685
Show file tree
Hide file tree
Showing 13 changed files with 1,184 additions and 3 deletions.
31 changes: 31 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# ---> Lazarus
# Lazarus compiler-generated binaries (safe to delete)
*.exe
*.so
*.dylib
*.lrs
*.res
*.compiled
*.dbg
*.ppu
*.o
*.or
*.a

# Lazarus autogenerated files (duplicated info)
*.rst
*.rsj
*.lrt

# Lazarus local files (user-specific info)
*.lps

# Lazarus backups and unit output folders.
# These can be changed by user in Lazarus/project options.
backup/
*.bak
lib/

# Application bundle for Mac OS
*.app/

9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Systemclient
This is the background client application for student machines of PhilleConnect
This is the background client application for student machines of PhilleConnect. It waites for requests from a teacher machine and will lock the monitor or shutdown the workstation if required. It also controls the VNC server and submitts a screenshot if requested.

# Placeholder repository
At the moment, this repository is a placeholder. This application is part of the Abitur 2018, so the source code will be published in may 2018.
# How to use this?
This is a part of the PhilleConnect system. To use this application, you'll need at least a PhilleConect Server. We recommend to use the Installer ([Windows](https://github.com/philleconnect/ClientSetup-Windows/releases), [Linux](https://github.com/philleconnect/ClientSetup-Linux/releases)) if you want to use PhilleConnect in a productive environment.

# How to compile this?
Follow the instructions here: [http://philleconnect.org/entwickler/HowToCompile](http://philleconnect.org/entwickler/HowToCompile)
Binary file added systemclient.ico
Binary file not shown.
134 changes: 134 additions & 0 deletions systemclient.lpi
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="10"/>
<PathDelim Value="\"/>
<General>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="systemclient"/>
<ResourceType Value="res"/>
<UseXPManifest Value="True"/>
<Icon Value="0"/>
</General>
<i18n>
<EnableI18N LFM="False"/>
</i18n>
<BuildModes Count="1">
<Item1 Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
</local>
</RunParams>
<RequiredPackages Count="2">
<Item1>
<PackageName Value="laz_synapse"/>
</Item1>
<Item2>
<PackageName Value="LCL"/>
</Item2>
</RequiredPackages>
<Units Count="11">
<Unit0>
<Filename Value="systemclient.lpr"/>
<IsPartOfProject Value="True"/>
</Unit0>
<Unit1>
<Filename Value="ulockscreen.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="Lockscreen"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="ULockscreen"/>
</Unit1>
<Unit2>
<Filename Value="ucreatewatchdogthread.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="UCreateWatchdogThread"/>
</Unit2>
<Unit3>
<Filename Value="ugetipadress.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="UGetIPAdress"/>
</Unit3>
<Unit4>
<Filename Value="ugetmacadress.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="UGetMacAdress"/>
</Unit4>
<Unit5>
<Filename Value="uvncserverthread.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="UVNCServerThread"/>
</Unit5>
<Unit6>
<Filename Value="ulockcaentf.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="ULockCAENTF"/>
</Unit6>
<Unit7>
<Filename Value="upingthread.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="UPingThread"/>
</Unit7>
<Unit8>
<Filename Value="..\..\..\Downloads\synapse-trunk\ssl_openssl.pas"/>
<IsPartOfProject Value="True"/>
</Unit8>
<Unit9>
<Filename Value="..\..\..\Downloads\synapse-trunk\ssl_openssl_lib.pas"/>
<IsPartOfProject Value="True"/>
</Unit9>
<Unit10>
<Filename Value="uxinitthreads.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="UXInitThreads"/>
</Unit10>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="systemclient"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<OtherUnitFiles Value="..\..\..\Downloads\synapse-trunk"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<CodeGeneration>
<Optimizations>
<OptimizationLevel Value="3"/>
</Optimizations>
</CodeGeneration>
<Linking>
<Debugging>
<GenerateDebugInfo Value="False"/>
</Debugging>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions Count="3">
<Item1>
<Name Value="EAbort"/>
</Item1>
<Item2>
<Name Value="ECodetoolError"/>
</Item2>
<Item3>
<Name Value="EFOpenError"/>
</Item3>
</Exceptions>
</Debugging>
</CONFIG>
22 changes: 22 additions & 0 deletions systemclient.lpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
program systemclient;

{$mode objfpc}{$H+}

uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, ULockscreen, ULockCAENTF
{ you can add units after this };

{$R *.res}

begin
RequireDerivedFormResource:=True;
Application.Initialize;
Application.ShowMainForm:=False;
Application.CreateForm(TLockscreen, Lockscreen);
Application.Run;
end.

86 changes: 86 additions & 0 deletions ucreatewatchdogthread.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
unit UCreateWatchdogThread;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils, Process, jwatlhelp32, Windows;

type
TCreateWatchdogThread = class(TThread)
private
givenPid: integer;
protected
procedure execute; override;
public
constructor create(given: string);
end;

implementation

constructor TCreateWatchdogThread.create(given: string);
begin
FreeOnTerminate:=true;
if (given = '') then begin
givenPid:=0;
end
else begin
givenPid:=StrToInt(given);
end;
inherited create(false);
end;

procedure TCreateWatchdogThread.execute;
var
ContinueLoop: boolean;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
foundProcess: boolean;
myProcess: TProcess;
DKMPPID: integer;
begin
if (givenPid = 0) then begin
myProcess:=TProcess.create(nil);
myProcess.executable:='C:\Program Files\PhilleConnect\DKMP.exe';
myProcess.parameters.add('startWatchdogAndKill');
myProcess.showWindow:=swoHIDE;
myProcess.execute;
myProcess.waitOnExit;
DKMPPID:=myProcess.exitStatus;
myProcess.free;
end
else begin
DKMPPID:=givenPid;
end;
while true do begin
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := SizeOf(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
foundProcess:=false;
while ContinueLoop do
begin
if (FProcessEntry32.th32ProcessId = DKMPPID) then
begin
foundProcess:=true;
end;
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
if not(foundProcess) then begin
myProcess:=TProcess.create(nil);
myProcess.executable:='C:\Program Files\PhilleConnect\DKMP.exe';
myProcess.parameters.add('startWatchdogAndKill');
myProcess.parameters.add(IntToStr(getProcessId));
myProcess.showWindow:=swoHIDE;
myProcess.execute;
myProcess.waitOnExit;
DKMPPID:=myProcess.exitStatus;
myProcess.free;
end;
sleep(50);
end;
end;

end.

83 changes: 83 additions & 0 deletions ugetipadress.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
unit UGetIPAdress;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils, Process;

type
TGetIPAdress = class
public
function getIP: string;
private
{$IFDEF WINDOWS}
function GetIpAddrList: string;
{$ENDIF}
end;

implementation

function TGetIPAdress.getIP: string;
var
response: TStringList;
{$IFDEF LINUX}
process: TProcess;
{$ENDIF}
begin
{$IFDEF WINDOWS}
response:=TStringList.create;
response.delimiter:=' ';
response.delimitedText:=GetIpAddrList;
result:=response[1];
{$ENDIF}
{$IFDEF LINUX}
process:=TProcess.create(nil);
process.executable:='sh';
process.parameters.add('-c');
process.parameters.add('hostname -I | awk ''{print $1}''');
process.options:=process.options + [poWaitOnExit, poUsePipes];
process.showWindow:=swoHIDE;
process.execute;
response:=TStringList.create;
response.LoadFromStream(process.output);
process.free;
result:=trim(response[0]);
response.free;
{$ENDIF}
end;

{$IFDEF WINDOWS}
function TGetIPAdress.GetIpAddrList: string;
var
AProcess: TProcess;
s: string;
sl: TStringList;
i, n: integer;
begin
Result:='';
sl:=TStringList.Create();
AProcess:=TProcess.Create(nil);
AProcess.CommandLine := 'ipconfig.exe';
AProcess.Options := AProcess.Options + [poUsePipes, poNoConsole];
try
AProcess.Execute();
Sleep(500); // poWaitOnExit don't work as expected
sl.LoadFromStream(AProcess.Output);
finally
AProcess.Free();
end;
for i:=0 to sl.Count-1 do
begin
if (Pos('IPv4', sl[i])=0) and (Pos('IP-', sl[i])=0) and (Pos('IP Address', sl[i])=0) then Continue;
s:=sl[i];
s:=Trim(Copy(s, Pos(':', s)+1, 999));
if Pos(':', s)>0 then Continue; // IPv6
Result:=Result+s+' ';
end;
sl.Free();
end;
{$ENDIF}

end.
Loading

0 comments on commit 7864685

Please sign in to comment.