123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- unit BehaviorMonitor;
- interface
- uses
- mybean.core.objects, Classes, SysUtils, StrUtils, WindowsSysVersion, superobject,
- IdHTTP, InterfaceLogger, DateUtils, Dialogs;
-
- type
- TBehaviorMonitor = class(TMyBeanInterfacedObject, IBehaviorMonitor)
- private
- FLoginName: string;
- FIP: string;
- FPlatform: string;
- FComputerName: string;
- FEnable: Boolean;
- FUrl: string;
- public
- procedure LoginRecord(ALoginName: string); stdcall;
- procedure Init;
- procedure LoadConfig;
- constructor Create; override;
- end;
-
- implementation
- uses
- ULogger;
- const
- CONFIG_DIR: string = 'CEF\config\behavior.config';
- { TBehaviorMonitor }
- constructor TBehaviorMonitor.Create;
- begin
- inherited;
- LoadConfig;
- Init;
- end;
- procedure TBehaviorMonitor.Init;
- begin
- try
- FPlatform := 'δ֪';
- FIP := '0.0.0.0';
- case GetWindowsSystemVersion of
- WinNone: FPlatform := 'δ֪';
- Win95: FPlatform := 'Windows 95';
- Win98: FPlatform := 'Windows 98';
- WinMe: FPlatform := 'Windows Me';
- Win2000: FPlatform := 'Windows 2000';
- WinServer2000: FPlatform := 'Windows Server 2000';
- WinXp: FPlatform := 'Windows XP';
- WinXp64: FPlatform := 'Windows XP x64';
- WinServer2003: FPlatform := 'Windows Server 2003';
- WinHomeServer: FPlatform := 'Windows Home Server';
- WinServer2003R2: FPlatform := 'Windows Server 2003 R2';
- WinVista: FPlatform := 'Windows Vista';
- WinServer2008: FPlatform := 'Windows Server 2008';
- WinServer2008R2: FPlatform := 'Windows Server 2008 R2';
- Win7: FPlatform := 'Windows 7';
- end;
- FIP := LocalIP;
- FComputerName := GetHostName;
- except
- on E: Exception do
- begin
- Dialogs.ShowMessage(E.Message);
- end;
- end;
- end;
- procedure TBehaviorMonitor.LoadConfig;
- var
- AFullPath: string;
- jo: ISuperObject;
- begin
- AFullPath := ExtractFilePath(ParamStr(0)) + CONFIG_DIR;
- if not FileExists(AFullPath) then
- begin
- FEnable := False;
- Exit;
- end;
- try
- jo := TSuperObject.ParseFile(AFullPath, False);
- FEnable := jo['enable'].AsBoolean();
- FUrl := jo['url'].AsString();
- except
- on E: Exception do
- begin
- FEnable := False;
- Dialogs.ShowMessage(E.Message);
- end;
- end;
- end;
- procedure TBehaviorMonitor.LoginRecord(ALoginName: string);
- var
- AJo: ISuperObject;
- ASendThread: TSendLogThread;
- begin
- if not FEnable then
- Exit;
- AJo := SO('{}');
- AJo.S['loginName'] := ALoginName;
- AJo.S['localAddress'] := FIP;
- AJo.S['platform'] := FPlatform;
- AJo.S['computerName'] := FComputerName;
- AJo.I['ts'] := (DateTimeToUnix(Now) - 8*60*60) * 1000;
- ASendThread := TSendLogThread.Create(FUrl, AJo.AsJSon());
- end;
- end.
|