[TLBAT] Intranet: download.asp
Posted by: Alessandro Panzetta
In this post we will build the page that downloads the packages that we have defined as: STANDARD, GOODIE or PATCH. These software packages are the ones that are available to all users in our domain so no special need is required except being a user in the domain.
What the page will do is to identify in which IP subnet the user is located and build the download URL relative to his or her site; this will save bandwidth and reduce download times for the users.
The page uses an ASP Server Variable that is used to obtain the client’s IP address and then compare this to our sites’ definition in our database, indeed if we look at the code we will see the: Request.ServerVariables(”REMOTE_ADDR”)
string, this variable is the IP address of the computer that is visiting the page.
As an example let’s consider the IP address 192.168.39.123, in this page we will check the 3rd octet of the IP address and compare it to our database; in this case the “39″ part identifies the Italian site located in Milan so the final URL will be “http://iis_ita1/download/free/myfile.exe ” where the myfile.exe is passed by the default.asp page.
The page then will also log the hit for the given file to the hits database; this is done by calling the LogHit subroutine.
The next post will discuss the SPECIAL packages where in order to be allowed to download a given file, the user is required to be member of a given domain group…stay tuned!!
<!– #include file=”adovbs.inc” –>
<%
Dim cnnSearch
Dim rstSearch
Dim strDBPath
Dim strSQL
Dim strSearch
Dim SOURCE
Set cnnSearch = Server.CreateObject(”ADODB.Connection”)
cnnSearch.Open “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” & Server.Mappath(”db/downloads.mdb”) & “;”
FILE = Request.QueryString(”file”)
‘ *** Get the visitor’s subnet
CLIENT_IP = Request.ServerVariables(”REMOTE_ADDR”)
SUBNET0 = Split(CLIENT_IP,”.”)
‘ *** Check the distribution point for the given subnet
strSQL = “SELECT Sites.Subnet, Sites.Distrib_Point FROM Sites WHERE (((Sites.Subnet)=’” & SUBNET0(2) & “‘)) GROUP BY Sites.Subnet, Sites.Distrib_Point;”
Set rstSearch = cnnSearch.Execute(strSQL)
Do While Not rstSearch.EOF
SOURCE = rstSearch.Fields(”Distrib_Point”).Value
rstSearch.MoveNext
Loop
‘ *** Create the download link and redirect the by using the REFRESH metatag so the package automatically starts downloading
DOWNLOAD_LINK = “http://” & SOURCE & “/download/free/” & FILE
response.write “<html><head><META http-equiv=’refresh’ content=’3;URL=” & DOWNLOAD_LINK & “‘><title>Download page for ” & FILE & “</title></head><body bgcolor=’#B1C9E9′>”
response.write “<br><center><font face=tahoma size=3 color=#006699>Your download should start automatically in 3 seconds.<br> If the download doesn’t start, click <b><a href=’” & DOWNLOAD_LINK & “‘ style=’text-decoration:none’> HERE</a></b> to download the file you requested.</center></body></html>”
‘ *** Free up some memory
Set rstSearch = Nothing
Set cnnSearch = Nothing
LogHit
Sub LogHit
USERID = split(Request.ServerVariables(”LOGON_USER”),”\”)
Dim DB_CONNECTIONSTRING
DB_CONNECTIONSTRING = “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” & Server.Mappath(”db/hits.mdb”) & “;”
Dim objRecordset
Set objRecordset = Server.CreateObject(”ADODB.Recordset”)
strSQL = “SELECT * FROM downloads;”
objRecordset.Open strSQL, DB_CONNECTIONSTRING, adOpenKeyset, adLockPessimistic, adCmdText
objRecordset.AddNew
objRecordset.Fields(”Package”) = FILE
objRecordset.Fields(”UserName”) = USERID(1)
objRecordset.Fields(”IP_ADDR”) = CLIENT_IP
objRecordset.Fields(”Date”) = Date
objRecordset.Update
objRecordset.Close
Set objRecordset = Nothing
End Sub
%><head><title>..:: EIT Download Center ::..</title></head>



You must be logged-in to post a comment. Log-in/Register