|
An example of ASP file and String functions...
Well a colleague of ours is running RealServer on his IIS5 server (for which we digitize, edit and encode audio/video recordings) and he wanted to be able to be able to check the logs without having to go to the server and login into the console. He also wanted some other folk to be able to see the access logs without giving them physical access to the server or any login permissions.
What was he to do?
Well he rightly figured there would be of doing this via web pages.
He knew we'd done something similar before for monitoring failed logins to a secure web site (see "anti-hammering") so we got the call...
background:
RealServer is a program which can be installed on various server systems, including Windows® 2000 IIS5 servers. This program handles the streaming of live or recorded events in an audio or video format. All the audience has to do is sit back and let Real Player (bundled with most browser installations or freely available) play the webcast.
If the server manager has configured RealServer accordingly a log is kept of all accesses to the RealServer, including the time and date, the IP address of the computers and which recordings were accessed. All of this data is stored in a simple text file. This access logs are totally uniform - perfect for any scripting language to handle.
description:
What this exceedingly simple script does is opens up the log file and reads each line into a string. Then using the string function instr(string, "[char]") the location of key markers in each log file line is loaded into a variable and this variable used to mark the beginning or end of a chunk of string of interest.. The chunk of string of interest is then loaded into an array position using the mid(string, begin, end) The number of lines in the array is loaded into nlines and this used to set the end point for a loop displaying the results in the document body.
the script:
<%
Dim iparray(), datearray(), talkarray()
pname="c:\Program Files\Real\RealServer\Logs\rmaccess.log"
Set FSYS=Server.CreateObject("Scripting.FileSystemObject")
Set logfile = FSYS.OpenTextFile(pname)
i=1
While Not logfile.AtEndOfStream
Redim Preserve iparray(i)
Redim Preserve talkarray(i)
Redim Preserve datearray(i)
textstring=logfile.ReadLine
finddash=instr(textstring,"-")
iparray(i)=mid(textstring,1,finddash-2)
leftover=trim(mid(textstring,finddash))
finddatestart=instr(leftover,"[")
finddatestop=instr(leftover,"]")
datearray(i)=mid(leftover,finddatestart+1,finddatestop-12)
leftover=trim(mid(leftover,finddatestop))
findG=instr(leftover,"GET")
leftover=trim(mid(leftover,findG+4))
findR=instr(leftover," ")
talkarray(i)=mid(leftover,1,findR)
i=i+1
Wend
nlines=i
Set FSYS = nothing
Set logfile = nothing
%>
<HTML>
<HEAD><TITLE>Real Server Log</TITLE></HEAD>
<BODY>
<H3 align=center>Real Server Log</H3>
<% Response.Write "<B>accesses = </B>" & nlines %>
<TABLE width="100%">
<%
i=1
Do Until i=nlines
response.write "<tr><td><FONT size='-2' Face=Arial,sans-serif>"& iparray(i) &"</FONT></td><td><FONT size='-2' Face=Arial,sans-serif>"& datearray(i) &"</FONT></td><TD><FONT size='-2' face=Arial, sans-serif>"& talkarray(i)
&"</FONT></TD></tr>"
i=i+1
Loop
%>
</TABLE>
</BODY>
</HTML>
the result:
The finished result can be viewed at www.arc.nottingham.ac.uk/realserver/
|
|
the powser of ASP
|
|
RealServer logs
|
| to come ... |
| databased content |
| anti-hammering |
|
|