MimeMaps.js

Description

This script parses the specified log file and identifies all the requests rejected with 404.2. If the file extension for a rejected request doesn't match a mimemap currently set for the web server, the user is warned that a corresponding mimemap entry should be added to the MimeMaps property.

Requirements

You must install and use the Log Parser tool.

Supported Platforms

Windows Server 2003

Yes

Windows XP

No

Windows 2000

No

Script Code

//Parse arguments first
var szInputLogFilename=null;
var szArgs = WScript.Arguments;
if(szArgs.length<1)
{
   WScript.Echo("Usage:");
   WScript.Echo(" -log:<log_filename>");
   WScript.Quit(-2);
}
for (var i=0; i < 1; i++)
{
   if(szArgs(i).substr(0,5).toLowerCase()=="-log:")
   {
      szInputLogFilename=szArgs(i).substr(5);
   }
   else
   {
  WScript.Echo("Unrecognized argument: " + szArgs(i));
 WScript.Quit(-1);
   }
}
if( szInputLogFilename==null )
{
   WScript.Echo("Not all the parameters have 
been specified");
   WScript.Quit(-1);
}
//Load the mimemaps
var g_szEnabledExtensions=new ActiveXObject
("Scripting.Dictionary");
LoadMimemaps();
//Create the main Log Parser Query object
var myQuery=new ActiveXObject("MSUtil.LogQuery");
//Create the text of the query
//
var szQuery =    "SELECT  DISTINCT SUBSTR
(cs-uri-stem, LAST_INDEX_OF(cs-uri-stem,'.'), 
STRLEN(cs-uri-stem)) AS Extension," +
"sc-substatus " +
"FROM " + szInputLogFilename + " WHERE 
(sc-status = 404) AND (sc-substatus IS NULL OR 
sc-substatus=2) ";
//Execute the query and get a recordset
var recordSet=myQuery.Execute(szQuery);
//Walk thru the recordset
var bWarningEmit=false;
for(; !recordSet.atEnd(); recordSet.moveNext())
{
   var record=recordSet.getRecord();
   if(!record.isNull(0))
   {
      var szExtension=record.getValue(0);
      //Check if this extension is in the Mimemaps
      if(!g_szEnabledExtensions.Exists(szExtension))
      {
    WScript.Echo("The extension \"" + szExtension + 
    "\" is not in the server's MimeMap list.");
         bWarningEmit=true;
      }
   }
}
if(!bWarningEmit)
 WScript.Echo("All extensions are in the MimeMap list.");
function LoadMimemaps()
{
   try
   {
      var objMimeMap=GetObject("IIS://localhost/MimeMap")
      .Mimemap;
      var arrayMimeMap=(new VBArray(objMimeMap)).toArray();
      for(var m=0;m<arrayMimeMap.length;m++)
      g_szEnabledExtensions.Add(arrayMimeMap[m].
      Extension,1);
   }
   catch(e)
   {
      WScript.Echo("Error loading the Mimemaps: " 
      + e.description);
      WScript.Quit(-1);
   }
}

For any feedback regarding the content of this sample script, please write to Microsoft TechNet.

Disclaimer

The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.