home *** CD-ROM | disk | FTP | other *** search
- // EMPONLY.CPP - Implementation file for your Internet Server
- // EmpOnly Filter
-
- #include "stdafx.h"
- #include "EmpOnly.h"
-
- // Do not edit the following lines, which are needed by ClassWizard.
- #if 0
- BEGIN_MESSAGE_MAP(CEmpOnlyFilter, CHttpFilter)
- //{{AFX_MSG_MAP(CEmpOnlyFilter)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- #endif // 0
-
- ///////////////////////////////////////////////////////////////////////
- // The one and only CWinApp object
- CWinApp theApp;
-
- ///////////////////////////////////////////////////////////////////////
- // The one and only CEmpOnlyFilter object
- CEmpOnlyFilter theFilter;
-
- ///////////////////////////////////////////////////////////////////////
- // CEmpOnlyFilter implementation
- CEmpOnlyFilter::CEmpOnlyFilter()
- {
- // Read in employee "database" text file - Employ.dat.
- // Employ.dat must be located in Scripts subdirectory.
- // Since ctor is only called when EmpOnly.dll is loaded into memory,
- // any changes to database demands that web service be restarted.
-
- CString buf;
-
- // This next path is specific to the web server installation!
- // CStdioFile infile("c:\\Winnt351\\System32\\InetSrv\\Scripts\\Employ.dat",
- // CFile::modeRead);
-
- CStdioFile infile("c:\\webshare\\Scripts\\Employ.dat",
- CFile::modeRead);
-
- while (infile.ReadString(buf))
- {
- strAuthUsers += buf + "; ";
- buf.Empty();
- }
- }
-
- CEmpOnlyFilter::~CEmpOnlyFilter()
- {
- }
-
- BOOL CEmpOnlyFilter::GetFilterVersion(PHTTP_FILTER_VERSION pVer)
- {
- // Call default implementation for initialization
- CHttpFilter::GetFilterVersion(pVer);
-
- // Clear the flags set by base class
- pVer->dwFlags &= ~SF_NOTIFY_ORDER_MASK;
-
- // Set the flags we are interested in
- pVer->dwFlags |= SF_NOTIFY_ORDER_MEDIUM | SF_NOTIFY_NONSECURE_PORT | SF_NOTIFY_URL_MAP;
-
- // Load description string
- TCHAR sz[SF_MAX_FILTER_DESC_LEN+1];
- ISAPIVERIFY(::LoadString(AfxGetResourceHandle(),
- IDS_FILTER, sz, SF_MAX_FILTER_DESC_LEN));
- _tcscpy(pVer->lpszFilterDesc, sz);
- return TRUE;
- }
-
- DWORD CEmpOnlyFilter::OnUrlMap(CHttpFilterContext* pCtxt,
- PHTTP_FILTER_URL_MAP pMapInfo)
- {
- char pstrName[100], pstrIP[20], *pstrSearch;
- DWORD dwSize;
- BOOL bIsAuth = FALSE;
-
- //Check to see if client is requesting Employees Only page.
- //Use of _strlwr is possible because NT does not differentiate on case.
- _strlwr(pMapInfo->pszPhysicalPath);
- pstrSearch = strstr(pMapInfo->pszPhysicalPath, "emponly.htm");
- if (pstrSearch == NULL) //not asking for Employees Only page
- return SF_STATUS_REQ_NEXT_NOTIFICATION;
-
- dwSize = sizeof(pstrName);
- pCtxt->GetServerVariable("REMOTE_USER", pstrName, &dwSize);
- if (dwSize > 5) //check that is valid user (not anonymous)
- bIsAuth = IsAuthUserName(pstrName);
-
- if (bIsAuth == FALSE) //if not authorized name, then check IP
- {
- dwSize = sizeof(pstrIP);
- pCtxt->GetServerVariable("REMOTE_ADDR", pstrIP, &dwSize);
- if(dwSize > 6) //should always have client's IP, but...
- bIsAuth = IsAuthUserIP(pstrIP);
- }
-
- if (bIsAuth == TRUE) //if user is an authorized employee
- {
- return SF_STATUS_REQ_NEXT_NOTIFICATION;
- }
- else //if not, then redirect to consolation page
- {
- strcpy(pstrSearch, "Consoltn.htm");
- //preclude any other filter processing on this event
- return SF_STATUS_REQ_HANDLED_NOTIFICATION;
- }
- }
-
-
- BOOL CEmpOnlyFilter::IsAuthUserName(LPCSTR lpszUserName)
- {
- int hit = strAuthUsers.Find(lpszUserName);
- if (hit == -1)
- return FALSE;
- else
- return TRUE;
- }
-
- BOOL CEmpOnlyFilter::IsAuthUserIP(LPCSTR lpszIPAddress)
- {
- int hit = strAuthUsers.Find(lpszIPAddress);
- if (hit == -1)
- return FALSE;
- else
- return TRUE;
- }
-