BehaviorMonitor.pas 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. unit BehaviorMonitor;
  2. interface
  3. uses
  4. mybean.core.objects, Classes, SysUtils, StrUtils, WindowsSysVersion, superobject,
  5. IdHTTP, InterfaceLogger, DateUtils, Dialogs;
  6. type
  7. TBehaviorMonitor = class(TMyBeanInterfacedObject, IBehaviorMonitor)
  8. private
  9. FLoginName: string;
  10. FIP: string;
  11. FPlatform: string;
  12. FComputerName: string;
  13. FEnable: Boolean;
  14. FUrl: string;
  15. public
  16. procedure LoginRecord(ALoginName: string); stdcall;
  17. procedure Init;
  18. procedure LoadConfig;
  19. constructor Create; override;
  20. end;
  21. implementation
  22. uses
  23. ULogger;
  24. const
  25. CONFIG_DIR: string = 'CEF\config\behavior.config';
  26. { TBehaviorMonitor }
  27. constructor TBehaviorMonitor.Create;
  28. begin
  29. inherited;
  30. LoadConfig;
  31. Init;
  32. end;
  33. procedure TBehaviorMonitor.Init;
  34. begin
  35. try
  36. FPlatform := 'δ֪';
  37. FIP := '0.0.0.0';
  38. case GetWindowsSystemVersion of
  39. WinNone: FPlatform := 'δ֪';
  40. Win95: FPlatform := 'Windows 95';
  41. Win98: FPlatform := 'Windows 98';
  42. WinMe: FPlatform := 'Windows Me';
  43. Win2000: FPlatform := 'Windows 2000';
  44. WinServer2000: FPlatform := 'Windows Server 2000';
  45. WinXp: FPlatform := 'Windows XP';
  46. WinXp64: FPlatform := 'Windows XP x64';
  47. WinServer2003: FPlatform := 'Windows Server 2003';
  48. WinHomeServer: FPlatform := 'Windows Home Server';
  49. WinServer2003R2: FPlatform := 'Windows Server 2003 R2';
  50. WinVista: FPlatform := 'Windows Vista';
  51. WinServer2008: FPlatform := 'Windows Server 2008';
  52. WinServer2008R2: FPlatform := 'Windows Server 2008 R2';
  53. Win7: FPlatform := 'Windows 7';
  54. end;
  55. FIP := LocalIP;
  56. FComputerName := GetHostName;
  57. except
  58. on E: Exception do
  59. begin
  60. Dialogs.ShowMessage(E.Message);
  61. end;
  62. end;
  63. end;
  64. procedure TBehaviorMonitor.LoadConfig;
  65. var
  66. AFullPath: string;
  67. jo: ISuperObject;
  68. begin
  69. AFullPath := ExtractFilePath(ParamStr(0)) + CONFIG_DIR;
  70. if not FileExists(AFullPath) then
  71. begin
  72. FEnable := False;
  73. Exit;
  74. end;
  75. try
  76. jo := TSuperObject.ParseFile(AFullPath, False);
  77. FEnable := jo['enable'].AsBoolean();
  78. FUrl := jo['url'].AsString();
  79. except
  80. on E: Exception do
  81. begin
  82. FEnable := False;
  83. Dialogs.ShowMessage(E.Message);
  84. end;
  85. end;
  86. end;
  87. procedure TBehaviorMonitor.LoginRecord(ALoginName: string);
  88. var
  89. AJo: ISuperObject;
  90. ASendThread: TSendLogThread;
  91. begin
  92. if not FEnable then
  93. Exit;
  94. AJo := SO('{}');
  95. AJo.S['loginName'] := ALoginName;
  96. AJo.S['localAddress'] := FIP;
  97. AJo.S['platform'] := FPlatform;
  98. AJo.S['computerName'] := FComputerName;
  99. AJo.I['ts'] := (DateTimeToUnix(Now) - 8*60*60) * 1000;
  100. ASendThread := TSendLogThread.Create(FUrl, AJo.AsJSon());
  101. end;
  102. end.