The Client for an Internet Access Control Application
Recently we finished a series covering the server side for an Internet access control application; now we're ready to take on the client. The client application is what the Internet users will see shortly before a workstation is activated or when a session is completed. It is responsible for both time and user access management as you will see in the rest of the series. Crucially, it is also responsible for processing all communication between itself and the server.
The Client for an Internet Access Control Application - Retrieving the Workstation Name (Page 4 of 4 )
The function below retrieves the computer or workstation name, which is then saved and sent to the server when connecting:
//********computername
function TForm1.GetComputerName: string;
var
buffer: array[0..MAX_COMPUTERNAME_LENGTH + 1] of Char;
Size: Cardinal;
begin
Size := MAX_COMPUTERNAME_LENGTH + 1;
Windows.GetComputerName(@buffer, Size);
Result := StrPas(buffer);
end;
//*********end comp name function
The message synchronization functions have already been explained and should be easy to understand when looking through the code. The Dosychronize procedure is where the messages from the server are analyzed and processed. The server will send one of three commands, which this procedure needs to break down and execute:
//****** message synchronization functions
constructor TLog.Create(const AMsg: String);
begin
FMsg := AMsg;
inherited Create;
end;
procedure TLog.DoSynchronize;
var
cmd,mins,wstation:string;
begin
parsestring(FMsg,cmd,wstation,mins);
if cmd = 'activate' then begin
//remove screenblock
form1.Visible:=false;
form1.setoff:=true;
form2.times:=strtoint(mins);
form2.label1.caption:=mins;
form2.show;
end
else
if cmd='shutdown' then
begin
//initiate shut down
if not TimedShutDown(form1.GetComputerName, 'you have to shutdown', 30, true, true) then
ShowMessage('function failed...');
end
else
if cmd='lockstation' then
begin
//lock workstation
if not form1.Visible then
begin
form1.Visible:=true;
form1.setoff:=true;
end;
end;
end;
class procedure TLog.AddMsg(const AMsg: String);
begin
with Create(AMsg) do try
Synchronize;
finally
Free;
end;
end;
Conclusion
In the next article we will continue to explore some of the remaining procedures and functions.
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.