mxu

SrcBlock.cpp

mxu
Apr 6th, 2016
821
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // SRCBLOCK.CPP - Implementation file for your Internet Server
  2. //    srcblock Filter
  3.  
  4. /*  Possible Enhancements:
  5.     look for other strings (i.e., c:\inetpub\, _ids34234, etc.)
  6.  
  7. */
  8.  
  9.  
  10.  
  11. #include "stdafx.h"
  12. #include "srcblock.h"
  13.  
  14.  
  15. ///////////////////////////////////////////////////////////////////////
  16. // The one and only CSrcblockFilter object
  17.  
  18. CSrcblockFilter theFilter;
  19.  
  20.  
  21. ///////////////////////////////////////////////////////////////////////
  22. // CSrcblockFilter implementation
  23.  
  24. CSrcblockFilter::CSrcblockFilter()
  25. {
  26. }
  27.  
  28. CSrcblockFilter::~CSrcblockFilter()
  29. {
  30. }
  31.  
  32. BOOL CSrcblockFilter::GetFilterVersion(PHTTP_FILTER_VERSION pVer)
  33. {
  34.     // Call default implementation for initialization
  35.     CHttpFilter::GetFilterVersion(pVer);
  36.  
  37.     // Clear the flags set by base class
  38.     pVer->dwFlags &= ~SF_NOTIFY_ORDER_MASK;
  39.  
  40.     // Set the flags we are interested in
  41.     pVer->dwFlags |= SF_NOTIFY_ORDER_MEDIUM | SF_NOTIFY_SECURE_PORT | SF_NOTIFY_NONSECURE_PORT
  42.              | SF_NOTIFY_SEND_RAW_DATA;
  43.  
  44.     // Load description string
  45.     strcpy( pVer->lpszFilterDesc, "Source Code Blocking Filter, v1.0" );
  46.     return TRUE;
  47. }
  48.  
  49. DWORD CSrcblockFilter::OnSendRawData(CHttpFilterContext* pCtxt,
  50.     PHTTP_FILTER_RAW_DATA pRawData)
  51. {
  52.     CHAR*   pszBuffer;
  53.     pszBuffer=(char *)pRawData->pvInData;
  54.  
  55.     if (strstr(pszBuffer, "< your private string here>"))
  56.     {
  57.     static char szMessage[] =
  58.     "<HTML>"
  59.     "<HEAD><TITLE>Access Denied</TITLE>"
  60.     "</HEAD>\r\n"
  61.     "<BODY>"
  62.     "<P><p><b><font face=Arial size=2>Access Denied:&nbsp; You are not authorized to "
  63.     "view the requested page.</font></b></p>"
  64.     "<p><font face=Arial size=2>Please note that use of this system is monitored "
  65.     "and all access is logged.&nbsp; Any attempt to circumvent the security of this "
  66.     "server may result in prosecution under state, federal or other applicable laws.&nbsp; If you feel "
  67.     "you received this message in error, please contact the system administrator.</font></p>"
  68.     "</BODY></HTML>\r\n\r\n";
  69.  
  70.     HSE_SEND_HEADER_EX_INFO HeaderExInfo;
  71.  
  72.     HeaderExInfo.pszStatus = "200 OK";
  73.     HeaderExInfo.pszHeader = "Content-type: text/html\r\n\r\n";
  74.     HeaderExInfo.cchStatus = strlen( HeaderExInfo.pszStatus );
  75.     HeaderExInfo.cchHeader = strlen( HeaderExInfo.pszHeader );
  76.     HeaderExInfo.fKeepConn = FALSE;
  77.  
  78.  
  79.     DWORD dwBytesToWrite = strlen( szMessage );
  80.  
  81.     pCtxt->WriteClient( szMessage, &dwBytesToWrite, 0 );
  82.         return SF_STATUS_REQ_FINISHED;
  83.     }
  84.     else
  85.     {
  86.         return SF_STATUS_REQ_NEXT_NOTIFICATION;
  87.     }
  88.  
  89. }
  90.  
  91. // Do not edit the following lines, which are needed by ClassWizard.
  92. #if 0
  93. BEGIN_MESSAGE_MAP(CSrcblockFilter, CHttpFilter)
  94.     //{{AFX_MSG_MAP(CSrcblockFilter)
  95.     //}}AFX_MSG_MAP
  96. END_MESSAGE_MAP()
  97. #endif  // 0
Advertisement