Menu

#135 User log function support in NSBase

V1.11
closed
nobody
None
2024-12-28
2023-03-13
Anonymous
No

Ticket type : Evolution

Description : Good day,

Thank you for developing NSbase.
it is good alternative for MyVisualDataBase.
What I like about myvisualdatabase is the user management, where you can make a difference based on admin, user and reader based on CRUD model ( Create, Read, Update and Delete).
Maybe is worth to make this option avalible in NSBase. I use NSBase software on Linux Mint and Windows 11 (64 bits).

I want to use a function which i can log user activity which (workflow and following user activity) i can place on button click event or table event like OnAppend, OnPost etc.
This function ToUserLog (syntax ToUserLog('Description','LogType/category') It has to check if loguser tabel exitst. if Not automatically create in the main main database. (not in the configuration database nsb if someone uses a seperate database file).The follwing Fields are needed

Loguser (Table definition needed)

Description Text 250 (String)
Timestamp DateTime (now->system date and time)
LogTypeCategory Text 250 (String)
UserName Text 100 (generated from Envirment variable)
ComputerName Text 100 (generated from Envirment variable)
IP TEXT 30 (generated from Envirment variable or from Indy components-> client-ip)

Beneath I have find some lazarus example to fill the UserName and Computer which cab work for diffrent platforms
I use NS

function GetCurrentUserName: String;

{$IFDEF WINDOWS}
const
MaxLen = 256;
var
Len: DWORD;
WS: WideString;
Res: windows.BOOL;
{$ENDIF}
begin
Result := '';
{$IFDEF UNIX}
{$IF (DEFINED(LINUX)) OR (DEFINED(FREEBSD))}
Result := SysToUtf8(GetUserName(fpgetuid)); //GetUsername in unit Users, fpgetuid in unit BaseUnix
{$ELSE Linux/BSD}
Result := GetEnvironmentVariableUtf8('USERNAME');
{$ENDIF UNIX}
{$ELSE}
{$IFDEF WINDOWS}
Len := MaxLen;
{$IFnDEF WINCE}
if Win32MajorVersion <= 4 then
begin
SetLength(Result,MaxLen);
Res := Windows.GetuserName(@Result[1], Len);
//writeln('GetUserNameA = ',Res);
if Res then
begin
SetLength(Result,Len-1);
Result := SysToUtf8(Result);
end
else SetLength(Result,0);
end
else
{$ENDIF NOT WINCE}
begin
SetLength(WS, MaxLen-1);
Res := Windows.GetUserNameW(@WS[1], Len);
//writeln('GetUserNameW = ',Res);
if Res then
begin
SetLength(WS, Len - 1);
Result := Utf16ToUtf8(WS);
end
else SetLength(Result,0);
end;
{$ENDIF WINDOWS}
{$ENDIF UNIX}
end;

uses
{$IFDEF Win32} windows;{$ENDIF}

function GetThisComputerName: string;
var
c: array[0..127] of Char;
computer: string;
sz: dword;
AProcess: TProcess;
AStringList: TStringList;

begin
{$IFDEF Win32}
sz := SizeOf(c);
GetComputerName(c, sz);
Result := c;
{$ELSE}
AProcess := TProcess.Create(nil);
AStringList := TStringList.Create;
AProcess.CommandLine := 'echo $HOSTNAME';
AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes];
AProcess.Execute;
AStringList.LoadFromStream(AProcess.Output);
Result:=AStringList.Strings[0];
AStringList.Free;
AProcess.Free;
{$ENDIF}

end;

uses ...., blcksock;

function MyGetLocalIPs: string;
var
TcpSock: TTCPBlockSocket;
ipList: TStringList;
begin
Result := '';
ipList := TStringList.Create;
try
TcpSock := TTCPBlockSocket.create;
try
TcpSock.ResolveNameToIP(TcpSock.LocalName, ipList);
Result := ipList.CommaText;
finally
TcpSock.Free;
end;
finally
ipList.Free;
end;
end;

System information : Windows 64 bits / Windows 10 Pro

Discussion

  • neuts-jl

    neuts-jl - 2023-04-06

    Hello I take notes and I put in place a solution for the next version

     
  • neuts-jl

    neuts-jl - 2023-04-10

    Add this file https://sourceforge.net/projects/nsbase/files/nsbase-lua-libs/osutils.lua/download
    in runtime/lua folder and add this library in your nsbase project
    You use :
    os.computername()
    os.username()
    os.localipaddress()

     
  • Neuts-jl

    Neuts-jl - 2024-12-28
    • status: --> closed
    • Group: --> V1.11
     

Anonymous
Anonymous

Add attachments
Cancel





MongoDB Logo MongoDB