home *** CD-ROM | disk | FTP | other *** search
/ moodle.waes.ac.uk / moodle.waes.ac.uk.zip / moodle.waes.ac.uk / TMG / SP1-TMG-KB981324-AMD64-ENU.msp / PCW_CAB_SHFx2 / F2143_msfpcui.dll / BINARY / 25041 < prev    next >
Text File  |  2010-06-15  |  7KB  |  177 lines

  1. CREATE PROCEDURE [dbo].[ISA_spUserSummary]
  2. AS
  3. BEGIN
  4.     SET NOCOUNT ON;
  5.     IF OBJECT_ID ('tblUserSummary', 'u') IS NOT NULL
  6.         DROP TABLE [tblUserSummary]
  7.     IF OBJECT_ID ('tblMalwareUserSummary', 'u') IS NOT NULL
  8.         DROP TABLE [tblMalwareUserSummary]
  9.     IF OBJECT_ID ('tblUrlfUserSummary', 'u') IS NOT NULL
  10.         DROP TABLE [tblUrlfUserSummary]
  11.     DECLARE @FromDate datetime
  12.     SET @FromDate = (SELECT [FromDate] FROM [tblSummaryParams])
  13.     CREATE TABLE #Table1
  14.     (
  15.         UserName nvarchar(514),
  16.         BytesOut bigint,
  17.         BytesIn bigint,
  18.         TotalBytes bigint,
  19.         Requests bigint,
  20.         WebBytesOut bigint,
  21.         WebBytesIn bigint,
  22.         WebTotalBytes bigint,
  23.         WebRequests bigint,
  24.         AuthorizedFailures bigint,
  25.         MalwareIncidents bigint,
  26.         UrlfIncidents bigint,
  27.         MalwareInspectionAction int,
  28.         DeniedFailedIntra int
  29.     );
  30.     IF OBJECT_ID ('WEB_LOGS', 'view') IS NOT NULL
  31.     BEGIN
  32.         INSERT INTO #Table1
  33.         SELECT
  34.                 CASE
  35.                     WHEN ([ClientIP] = '00000000-0000-0000-0000-FFFF7F000001') THEN N'-'
  36.                     WHEN [ClientUserName] = N'anonymous' THEN '@\@' + CAST([ClientIP] AS nvarchar(500))
  37.                     WHEN [ClientUserName] = N'-' AND [ClientIP] = '00000000-0000-0000-0000-000000000000' THEN
  38.                          CASE
  39.                             WHEN CHARINDEX('Check Upstream',[ClientAgent])<>0 THEN N'{[23140]}'
  40.                             WHEN CHARINDEX('Member Ping',[ClientAgent])<>0 THEN N'{[23141]}'
  41.                             WHEN CHARINDEX('Fetch API',[ClientAgent])<>0 THEN N'{[23142]}'
  42.                             WHEN CHARINDEX('Delete API',[ClientAgent])<>0 THEN N'{[23143]}'
  43.                             ELSE N'-'
  44.                          END
  45.                     ELSE [ClientUserName]
  46.                 END AS UserName,
  47.                SUM([bytessent]) AS BytesOut,
  48.                SUM([bytesrecvd]) AS BytesIn,
  49.                SUM([bytessent]) + SUM([bytesrecvd]) AS TotalBytes,
  50.                COUNT(*) AS Requests,
  51.                SUM([bytessent]) AS WebBytesOut,
  52.                SUM([bytesrecvd]) AS WebBytesIn,
  53.                SUM([bytessent]) + SUM([bytesrecvd]) AS WebTotalBytes,
  54.                COUNT(*) AS WebRequests,
  55.                CASE
  56.                    WHEN ([resultcode] = 403) or ([resultcode] = 401) Then COUNT(*)
  57.                    ELSE 0
  58.                END AS AuthorizedFailures,
  59.                CASE
  60.                    WHEN ([ThreatName] = '-') THEN 0
  61.                    ELSE COUNT(*)
  62.                END AS MalwareIncidents,
  63.                CASE
  64.                    WHEN (([resultcode] = 13301) OR ([Action] = 8))
  65.                        AND ([InternalServiceInfo] &  1 <> 0)  THEN  COUNT(*)
  66.                    ELSE 0
  67.                END AS UrlfIncidents,
  68.                [MalwareInspectionAction],
  69.                CASE
  70.                     WHEN
  71.                         ([Action] = 8) OR
  72.                         ([resultcode] = 13301) OR
  73.                         ([Action] = 10) OR
  74.                         ([objectsource] = 6)
  75.                             THEN 1
  76.                     ELSE 0
  77.                END AS DeniedFailedIntra
  78.         FROM WEB_LOGS
  79.         WHERE
  80.             ([InternalServiceInfo] & 2) = 0
  81.         GROUP BY
  82.                CASE
  83.                     WHEN ([ClientIP] = '00000000-0000-0000-0000-FFFF7F000001') THEN N'-'
  84.                     WHEN [ClientUserName] = N'anonymous' THEN '@\@' + CAST([ClientIP] AS nvarchar(500))
  85.                     WHEN [ClientUserName] = N'-' AND [ClientIP] = '00000000-0000-0000-0000-000000000000' THEN
  86.                          CASE
  87.                             WHEN CHARINDEX('Check Upstream',[ClientAgent])<>0 THEN N'{[23140]}'
  88.                             WHEN CHARINDEX('Member Ping',[ClientAgent])<>0 THEN N'{[23141]}'
  89.                             WHEN CHARINDEX('Fetch API',[ClientAgent])<>0 THEN N'{[23142]}'
  90.                             WHEN CHARINDEX('Delete API',[ClientAgent])<>0 THEN N'{[23143]}'
  91.                             ELSE N'-'
  92.                          END
  93.                     ELSE [ClientUserName]
  94.                END,
  95.                [resultcode],
  96.                [ThreatName],
  97.                [MalwareInspectionAction],
  98.                [Action],
  99.                [objectsource],
  100.                [InternalServiceInfo]
  101.     END
  102.     IF OBJECT_ID ('FWS_LOGS', 'view') IS NOT NULL
  103.     BEGIN
  104.         INSERT INTO #Table1
  105.         SELECT
  106.                CASE
  107.                     WHEN [ClientUserName] = '-' OR  [ClientUserName] = 'SYSTEM'
  108.                             THEN '@\@' + CAST([OriginalClientIP] AS nvarchar(500))
  109.                     ELSE [ClientUserName]
  110.                END AS UserName,
  111.                SUM([bytessentDelta]) AS BytesOut,
  112.                SUM([bytesrecvdDelta]) AS BytesIn,
  113.                SUM([bytessentDelta]) + SUM([bytesrecvdDelta]) AS TotalBytes,
  114.     -- dont count intermediate packets
  115.                CASE
  116.                     WHEN ([Action] = 11) THEN 0
  117.                     ELSE COUNT(*)
  118.                END AS Requests,
  119.                0 AS WebBytesOut,
  120.                0 AS WebBytesIn,
  121.                0 AS WebTotalBytes,
  122.                0 AS WebRequests,
  123.                0 AS AuthorizedFailures,
  124.                0 AS MalwareIncidents,
  125.                0 AS UrlfIncidents,
  126.                0 AS MalwareInspectionAction,
  127.                0 AS DeniedFailedIntra
  128.         FROM FWS_LOGS
  129.         WHERE
  130.             ([InternalServiceInfo] & 2) = 0 AND
  131.             ([Action] != 8) AND
  132.             ([Action] != 10)
  133.         GROUP BY
  134.              CASE
  135.                  WHEN [ClientUserName] = '-' OR  [ClientUserName] = 'SYSTEM'
  136.                          THEN '@\@' + CAST([OriginalClientIP] AS nvarchar(500))
  137.                  ELSE [ClientUserName]
  138.              END,
  139.              [Action]
  140.     END
  141. -- now sum it all up
  142.     SELECT UserName,
  143.         SUM([BytesOut]) AS BytesOut,
  144.         SUM([BytesIn]) AS BytesIn,
  145.         SUM([TotalBytes]) AS TotalBytes,
  146.         SUM([Requests]) AS Requests,
  147.         SUM([AuthorizedFailures]) AS AuthorizedFailures,
  148.         SUM([WebBytesOut]) AS WebBytesOut,
  149.         SUM([WebBytesIn]) AS WebBytesIn,
  150.         SUM([WebTotalBytes]) AS WebTotalBytes,
  151.         SUM([WebRequests]) AS WebRequests,
  152.         @FromDate AS Date
  153.     INTO [tblUserSummary]
  154.     FROM #Table1 WITH(NOLOCK)
  155.     WHERE [DeniedFailedIntra] = 0
  156.     GROUP BY [UserName]
  157.     SELECT UserName,
  158.         SUM([MalwareIncidents]) AS MalwareIncidents,
  159.         [MalwareInspectionAction] AS [MalwareInspectionAction],
  160.         @FromDate AS Date
  161.     INTO [tblMalwareUserSummary]
  162.     FROM #Table1 WITH(NOLOCK)
  163.     WHERE [MalwareIncidents] > 0
  164.     GROUP BY [UserName],
  165.         [MalwareInspectionAction]
  166.     SELECT UserName,
  167.         SUM ([UrlfIncidents]) AS UrlfIncidents,
  168.         @FromDate AS Date
  169.     INTO [tblUrlfUserSummary]
  170.     FROM #Table1
  171.     WHERE [UrlfIncidents] > 0
  172.     GROUP BY [UserName]
  173.     INSERT INTO [tblSummaryTables] ([TableName]) VALUES ('tblUrlfUserSummary')
  174.     INSERT INTO [tblSummaryTables] ([TableName]) VALUES ('tblMalwareUserSummary')
  175.     INSERT INTO [tblSummaryTables] ([TableName]) VALUES ('tblUserSummary')
  176. END
  177.