Converting NCSA log files to W3C format

One of the great utilities that ships with IIS is the CONVLOG.EXE application, which converts W3C or MS Internet Standard log files to NCSA format, where they can be processed by any of the applications that only parse NCSA log file information. The trouble is, what happens when you already have NCSA log files and you want W3C log files? You can't use the CONVLOG.EXE application, it only works in the opposite direction.

With that in mind, I wrote the following Windows Script Host (WSH) script that will read the current directory and convert all NCSA-formatted log files to W3C format. To use this code, just copy the code into notepad, and save it with a ".vbs" file extension on your system. To run it, copy the script to a folder that contains NCSA log files, (named "nc*.log"), then double-click it.

Option Explicit

Dim objIISLog
Dim objFSO
Dim objFolder
Dim objFile
Dim objOutputFile
Dim strInputPath
Dim strOutputPath
Dim strLogRecord

Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")

Set objFolder = objFSO.GetFolder(".")

For Each objFile In objFolder.Files

 strInputPath = LCase(objFile.Name)

 If Left(strInputPath,2) = "nc" And Right(strInputPath,4) = ".log" Then

  strOutputPath = objFolder.Path & "\" & "ex" & Mid(strInputPath,3)
  strInputPath = objFolder.Path & "\" & strInputPath

  Set objIISLog = CreateObject("MSWC.IISLog")
  objIISLog.OpenLogFile strInputPath, 1, "", 0, ""
  Set objOutputFile = objFSO.CreateTextFile(strOutputPath)

  objIISLog.ReadLogRecord

  objOutputFile.WriteLine "#Software: Microsoft Internet Information Services 5.0"
  objOutputFile.WriteLine "#Version: 1.0"
  objOutputFile.WriteLine "#Date: " & BuildDateTime(objIISLog.DateTime)
  objOutputFile.WriteLine "#Fields: date time c-ip cs-username s-ip s-port cs-method cs-uri-stem cs-uri-query sc-status cs(User-Agent)"

  Do While Not objIISLog.AtEndOfLog

   strLogRecord = BuildDateTime(objIISLog.DateTime)
   strLogRecord = strLogRecord & " " & FormatField(objIISLog.ClientIP)
   strLogRecord = strLogRecord & " " & FormatField(objIISLog.UserName)
   strLogRecord = strLogRecord & " " & FormatField(objIISLog.ServerIP)
   strLogRecord = strLogRecord & " " & FormatField(objIISLog.ServerPort)
   strLogRecord = strLogRecord & " " & FormatField(objIISLog.Method)
   strLogRecord = strLogRecord & " " & FormatField(objIISLog.URIStem)
   strLogRecord = strLogRecord & " " & FormatField(objIISLog.URIQuery)
   strLogRecord = strLogRecord & " " & FormatField(objIISLog.ProtocolStatus)
   strLogRecord = strLogRecord & " " & FormatField(objIISLog.UserAgent)
   objOutputFile.WriteLine strLogRecord

   objIISLog.ReadLogRecord

  Loop

  objIISLog.CloseLogFiles 1
  objIISLog = Null
 
 End If

Next

Function FormatField(tmpField)
 On Error Resume Next
 FormatField = "-"
 If Len(tmpField) > 0 Then FormatField = Trim(tmpField)
End Function

Function BuildDateTime(tmpDateTime)
 On Error Resume Next
 tmpDateTime = CDate(tmpDateTime)
 BuildDateTime = Year(tmpDateTime) & "-" & _
  Right("0" & Month(tmpDateTime),2) & "-" & _
  Right("0" & Day(tmpDateTime),2) & " " & _
  Right("0" & Hour(tmpDateTime),2) & ":" & _
  Right("0" & Minute(tmpDateTime),2) & ":" & _
  Right("0" & Second(tmpDateTime),2)
End Function

I hope this helps!

Domestic Terrorists Come in Many Forms

As an honorably-discharged veteran, it should come as no surprise that an opinion piece with a title of "Why America needs to be Defeated in Iraq" would catch my attention. When I first read this ludicrous pile of drivel from a gentleman whom I shall henceforth refer to as "Mr. Whit," I was merely offended. His errant ramblings seemed to be another entry in a long line of deranged brain dumps from scores of deranged imbeciles that I seemed to discover whenever I ventured into another dark corner within the vast wastelands of west coast propaganda. I lived in Seattle for a decade or so, and I've seen this type of close-minded lunacy before. To paraphrase the Bard, the author of that particular op-ed, Mr. Whit, has no more intelligence in him than in a stewed prune. (Methinks he doth possess a great deal less.)

After a bit of time had passed, I pondered more about the context of Mr. Whit's article, and I was appalled by the abhorrent vulgarity of what his brief manifesto actually represents: Mr. Whit is a US Citizen who is outspoken and unapologetic about his desire that some form of harm should come to other US citizens. That admission makes him, using today's parlance, a domestic terrorist. Plain and simple. When one American's wish is that other Americans must suffer in order to make a political point, then that American is no better than the abomination that was Timothy McVeigh. After all, the late Mr. McVeigh only wanted to make a political statement when he and his accomplice bombed the Federal Building in Oklahoma City, right?

Mr. McVeigh's vicious manifestation of domestic terrorism was responsible for the deaths of 168 innocent men, women, and children. However, for Mr. McVeigh, those people's fates were secondary to his cause. He believed that his principles were more important than his victims' lives. In the same way, Mr. Whit regards his self-appointed role as an oracle of truth as more beneficial to society than the meager value of average peasants, and therefore he believes that he has the right to condemn other lives to death in order to satisfy his misguided philosophies. The fates of those whom Mr. Whit would send to their graves are secondary to his gargantuan ego, and their lives are worth less than his sanctimonious convictions.

On the one hand, Mr. Whit accuses the US government of believing that "might is right" when it decides who gets to live or die, while on the other hand he freely chooses (from the sanctity of his word-processor) who else gets to live or die. Like Mr. McVeigh before him, Mr. Whit's deplorable appetite for others to suffer for his wretched aberration of morality is fully-vindicated within the boundaries of his twisted, little worldview. I am sure that somewhere inside his hollow, rat-infested cranium, Mr. Whit believes that the "ends justify the means." However, Mr. Whit doesn't have to face the consequences of his brain-dead decrees, whereas the innocent lives that he has condemned to death and their unfortunate families are left to suffer.

History has had more than its fair share of sociopaths who fail to take responsibility for their murderous actions, and Mr. Whit follows their example to the letter when he wishes death upon US troops while skirting away from any personal culpability by laying the blame for their deaths on the government. What Mr. Whit does not realize is that he doesn't get to have it both ways; he cannot pronounce a death sentence on others without being found guilty for his own crimes. He cannot claim that our government is guilty of terrorism, then advocate for the deaths of other US citizens and not be found guilty of his own brand of repugnant and unctuous terrorism. His self-righteous delusions do not grant him the title of judge, jury, or executioner.

It is ironic that short-sighted morons like Mr. Whit are quick to exercise their first amendment right to freedom of speech, while overlooking the sacrifices that were made on his behalf in order to guarantee his right to speak his mind without fear of reprisal. Long before Mr. Whit's feckless mortal coil ventured forth upon the country that he despises and condemns, the same sort of men and women on whom he passes his misguided judgment fought and died so that he might one day have the freedom to spit on their collective memories. Liberals like Mr. Whit never seem to realize that no one can have freedom in this world unless someone is willing to fight for it. It is clear that Mr. Whit will never personally fight for his freedom; he will continue to sit in the shadows and dispatch his putrid, little missives whenever a contrary wind ruffles his delicate feathers.

To be clear, I do not mind when someone exercises their freedom of speech. I do not mind when someone protests the war. (I have my own misgivings about the directions we are taking - or not taking.) I do not mind when someone calls the President a "war-monger." I do not mind when someone wants our troops out of the Middle East, and organizes a "million-man-march" on the capitol to demand that Congress should bring our brave men and women home. When you get right down to it, I do not mind when someone informs me that something I believe to be right or wrong might be true or false.

However, I damn sure mind when some hypocritical, warthog-faced buffoon signs a death warrant for members of our country's armed forces from the safe haven of his computer keyboard, tucked safely away in an office where no harm will come to him. And yet, despite my personal loathing for Mr. Whit, and in deference to my belief that simpletons like Mr. Whit are utterly useless to society, I do not wish that any harm should come to him. I served in our nation's armed forces so that even a miserable, vomitus mass like Mr. Whit has the right to share his pathetic sentiments in a public forum. And to be honest, if push came to shove, I would do so again. And this is the paradox that makes our country great: the strong and the brave will thanklessly sacrifice their personal safety to fight and defend the rights of the weak and ungrateful cowards who condemn them.

I'll get off my soapbox now.


UPDATE: This post is one of several that I had written that I later discovered had never been set to "public."