If it has a plug, it's IT stuff:

Bandwidth

Sep 24 2008   12:36PM GMT

[TLBAT] Intranet: the download_special.asp



Posted by: Alessandro Panzetta
Networking, Database, Bandwidth, Active Server Pages, IT support, Intranet, Intranet portal

So we’re finally at the “interesting” stuff: the page that checks if a user is allowed or not to download a certain package.

As in previous posts in order to allow a user to download a certain file he/she must be a member of a given group; e.g. we want to restrict the downloads of MySoftware.exe and make this available only to the members of the grp_MySoftware group. We defined then in our database that this file has the following entry:

PackageDesc = “My beautiful software 1.0″

PackageName = “MySoftware.exe”

PackageType = “Special”

NeededGroup = “grp_MySoftware”

The code that you find below will check if the user that is visiting the page is part of the grp_MySoftware group and, if successful, build the download link by redirecting him/her to the closest distribution point. Example http://192.168.xxx.1/files/MySoftware.exe where xxx is the subnet of the client visiting the page.

So now let’s see the code and remember to change the MyDomain = “contoso” to your domain name (E.g. if you have mycompany.com just type mycompany).

The code that follows is self-explanatory so just…read it and check the commented lines!

‘======CODE======

<!– #include file=”adovbs.inc” –>

<%

Session.Timeout=10

Dim NEEDED_GROUP

Dim SOURCE

Dim FILE

Dim MyDomain

‘Dim USERID

FILE = Request.querystring(”file”)

USERID = Request.querystring(”UserName”)

MyDomain = “contoso”

Dim Licensed

Set cnnSearch = Server.CreateObject(”ADODB.Connection”)

cnnSearch.Open “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” & Server.Mappath(”db/downloads.mdb”) & “;”

strSQL2 = “SELECT Packages.NeededGroup FROM Packages WHERE (((Packages.PackageName)=’” & FILE & “‘)) GROUP BY Packages.NeededGroup;”

Set rstSearch2 = cnnSearch.Execute(strSQL2)

Do While Not rstSearch2.EOF

   NEEDED_GROUP= rstSearch2.Fields(”NeededGroup”).Value

    rstSearch2.MoveNext

Loop

Call CheckGroup

Sub CheckGroup

Set objDictionary = CreateObject(”Scripting.Dictionary”)

set User = GetObject(”WinNT://” & MyDomain & “/” + USERID)

For Each Prop In User.groups

    if instr Prop.Name,right(NEEDED_GROUP,3)) > 0 then

        Licensed = True

    end if

Next

End Sub

if Licensed = True then

Call GimmePack(FILE)

else

    Call RequestPack(NEEDED_GROUP, FILE)

End if

‘ *** 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

    Session(”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

Sub GimmePack(FILE)

    DOWNLOAD_LINK = Session(”SOURCE”) & FILE

    response.write “<html><head><META http-equiv=’refresh’ content=’3;URL=” & DOWNLOAD_LINK & “‘><title>Download page for ” & FILE & “</title></head><body>”

    response.write “<center><FONT FACE=TAHOMA SIZE=2 COLOR=#006699>You are registered to download <b>” & FILE & “</b></FONT><br>”

    response.write “<FONT FACE=TAHOMA SIZE=2 COLOR=#006699>Your download should start in few seconds, if this doesn’t happen, click <a href=” & DOWNLOAD_LINK & “>HERE</a></b> to download the file</FONT><center>”

    LogHit

End Sub

Sub LogHit

    CLIENT_IP = Request.ServerVariables(”REMOTE_ADDR”)

    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

    objRecordset.Fields(”IP_ADDR”) = CLIENT_IP

    objRecordset.Fields(”Date”) = Date

    objRecordset.Update

    objRecordset.Close

    Set objRecordset = Nothing

End Sub

Sub RequestPack(NEEDED_GROUP, FILE)

    Response.Redirect “request_package.asp?UserName=” & UCase(USERID) & “?Group=” & NEEDED_GROUP & “?File=” & FILE & ” “

‘    Session.Abandon

End Sub

%><head><title>..:: Download Center ::..</title></head>

‘======END CODE======

Sep 10 2008   3:21PM GMT

[TLBAT] Intranet : The home page



Posted by: Alessandro Panzetta
Database, Bandwidth, Active Server Pages, IT support, Intranet, Admin tools, Intranet portal

In this post I’ll present the home page and will explain how this works….so let’s play J

First in order to have this working we need a file called adovbs.inc that can be downloaded here, this file contains all instructions for connecting to the database via ADO.The we need to download some images that will be used in the pages, the images are available here. So now go to the directorywhere your site will be hosted (E.g. c:\inetpub\wwwroot) and unzip images in a directory called images. Also create a folder named dbwhere you will save the downloads.mdb file that you created as in my previous post so in the end you will have a folder structure as follows:

c:\inetpub\wwwroot\Download_Center

c:\inetpub\wwwroot\Download_Center\images

c:\inetpub\wwwroot\Download_Center\db

Now we need to create our default.asp page, the code is at the bottom of this post. let’s discuss on this code.

It consists of some basic HTML that uses some internal subroutines to build 4 tables (see screen shot) that contain: the software available to everyone, the software for users in given groups, the patches and the goodies.

In order to dynamically build these tables a subroutine called  DoTD is called, this subroutine accepts an option that specifies whic table must be built; possible values are  STANDARD, SPECIAL,PATCH, GOODIE.

In addition to this procedure there’s also a Counter subroutine that is called by the DoTD and that shows how many times the given package has been downloaded. In order fr this to work you need a hits.mdb file (available here) where the hits will be recorded; remember to save this file in the db directory.

Once you have finished downloading the files described above, create a new default.asp page  with the following code andsave it in the root folder of your website.

For now this is enough, in the next post I’ll describe the download_special.asp file  that is the one that checks if the user visiting the page is allowed to download a certain file or not….stay tuned!!!

‘======================

 <%
Session.Timeout=10
USERID = split(Request.ServerVariables(”LOGON_USER”),”\”)
%>
<title>..:: Download Center ::..</title>
<body bgcolor=”#B1C9E9″>

<div align=”center”>
<center>

<table border=”0″ cellpadding=”0″ cellspacing=”0″ style=”border-collapse: collapse” bordercolor=”#111111″ width=”90%”>
<tr>
<td width=”100%” background=”images/tile_sub.gif”>
<p align=”center”><b><font face=”Tahoma” color=”#006699″ size=”5″>..:: Download Center ::..</font></b></p>
</td>
</tr>
</table>

<center><font color=”#006699″ size=”2″ face=”Tahoma”> <img border=”0″ src=”images/dot.gif”> </font><font size=”2″ face=”Tahoma”>
<a style=”text-decoration: none” title=”Click to see all the packages you have downloaded from this site” href=”MY_downloads.asp”><font color=”#006699″>
Click here to view your Download History</font></a><font color=”#006699″>
<img border=”0″ src=”images/dot.gif”></font></font></center><br>

<table border=”0″ cellspacing=”1″ style=”border-collapse: collapse” bordercolor=”#111111″ width=”90%” id=”AutoNumber2″>
<tr>
<td width=”100%”><font face=”Tahoma” color=”#006699″ size=”2″>By clicking the <b>DOWNLOAD</b> button you are automatically
rerouted to the closest software distribution server. <br>
Please try to avoid
software downloads through RAS.</font></td>
</tr>
</table>
</center>
</div> <table border=0 align=center cellspacing=10>
<tr><td valign=top>
<table border=2 bordercolor=#006699 cellspacing=3 cellpadding=3 align=center>
<tr><td bgcolor=#006699 align=center background=”images/tile_sub.gif”>
<font color=”#006699″ size=”2″ face=”Tahoma”><b><img border=”0″ src=”images/dot.gif”>
No License Required <img border=”0″ src=”images/dot.gif”></b></font></td>
<td bgcolor=#006699 align=center background=”images/tile_sub.gif”><b>
<font size=”2″ color=”#006699″ face=”Tahoma”><img border=”0″ src=”images/dot.gif”>
</font></b><font size=”2″><b>
<font face=Tahoma color=#006699>Download</font></b></font><b><font size=”2″ color=”#006699″ face=”Tahoma”> <img border=”0″ src=”images/dot.gif”></font></b></td>
<td bgcolor=#006699 align=center background=”images/tile_sub.gif”><b>
<font size=”2″ color=”#006699″ face=”Tahoma”><img border=”0″ src=”images/dot.gif”>
</font></b><font size=”2″><b>
<font face=Tahoma color=#006699>Hits</font></b></font><b><font size=”2″ color=”#006699″ face=”Tahoma”> <img border=”0″ src=”images/dot.gif”></font></b></td></tr>
<%
Which = “Standard”
DoTD
%>
</table>
</td>
<td valign=top>
<table border=2 bordercolor=#006699 cellspacing=3 cellpadding=3 align=center>
<tr><td bgcolor=#006699 align=center background=”images/tile_sub.gif”>
<font color=”#006699″ size=”2″ face=”Tahoma”><b><img border=”0″ src=”images/dot.gif”>
License Required <img border=”0″ src=”images/dot.gif”></b></font></td>
<td bgcolor=#006699 align=center background=”images/tile_sub.gif”><b><font color=”#006699″ size=”2″ face=”Tahoma”><img border=”0″ src=”images/dot.gif”> Download <img border=”0″ src=”images/dot.gif”></font></b></td><td bgcolor=#006699 align=center background=”images/tile_sub.gif”><b><font color=”#006699″ size=”2″ face=”Tahoma”><img border=”0″ src=”images/dot.gif”> Hits <img border=”0″ src=”images/dot.gif”></font></b></td></tr>
<%
Which = “Special”
DoTD
%>
</table>
</td></tr>
<tr><td valign=top>
<table border=2 bordercolor=#006699 cellspacing=3 cellpadding=3 align=center>
<tr><td bgcolor=#006699 align=center background=”images/tile_sub.gif”>
<font color=”#006699″ size=”2″ face=”Tahoma”><img border=”0″ src=”images/dot.gif”> <b>Patches
</b><img border=”0″ src=”images/dot.gif”></font></td>
<td bgcolor=#006699 align=center background=”images/tile_sub.gif”><font color=”#006699″ size=”2″ face=”Tahoma”><img border=”0″ src=”images/dot.gif”> </font><b>
<font face=Tahoma color=#006699 size=2>Download </font></b><font color=”#006699″ size=”2″ face=”Tahoma”><img border=”0″ src=”images/dot.gif”></font></td>
<td bgcolor=#006699 align=center background=”images/tile_sub.gif”><font color=”#006699″ size=”2″ face=”Tahoma”><img border=”0″ src=”images/dot.gif”> </font><b>
<font face=Tahoma color=#006699 size=2>Hits </font></b><font color=”#006699″ size=”2″ face=”Tahoma”><img border=”0″ src=”images/dot.gif”></font></td></tr>
<%
Which = “Patch”
DoTD
%>
</table>
</td>
<td valign=top>
<table border=2 bordercolor=#006699 cellspacing=3 cellpadding=3 align=center>
<tr><td bgcolor=#006699 align=center background=”images/tile_sub.gif”>
<font color=”#006699″ size=”2″ face=”Tahoma”><b><img border=”0″ src=”images/dot.gif”> Goodies <img border=”0″ src=”images/dot.gif”></b></font></td>
<td bgcolor=#006699 align=center background=”images/tile_sub.gif”><b><font color=”#006699″ size=”2″ face=”Tahoma”><img border=”0″ src=”images/dot.gif”> Download <img border=”0″ src=”images/dot.gif”></font></b></td>
<td bgcolor=#006699 align=center background=”images/tile_sub.gif”><b><font color=”#006699″ size=”2″ face=”Tahoma”><img border=”0″ src=”images/dot.gif”>
Hits <img border=”0″ src=”images/dot.gif”></font></b></td></tr>
<%
Which = “Goodie”
DoTD
%>
</table>
</td></tr>
</table>

<%
Sub DoTD()
Dim cnnSearch
Dim rstSearch
Dim strDBPath
Dim strSQL
Dim strSearch
Set cnnSearch = Server.CreateObject(”ADODB.Connection”)
cnnSearch.Open “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” & Server.Mappath(”db/downloads.mdb”) & “;”
strSQL = “SELECT * FROM Packages WHERE (((Packages.PackageType)=’” & WHICH & “‘)) ORDER BY Packages.PackageName;”

Set rstSearch = cnnSearch.Execute(strSQL)
Do While Not rstSearch.EOF
Package = rstSearch.Fields(”PackageDesc”).Value
File =  rstSearch.Fields(”PackageName”).Value

If WHICH = “Special” then
response.write “<tr><td><font face=tahoma color=#006699 size=1><b>” & Package  & “</td><td><a href=download_special.asp?File=” & File & “&UserName=” & USERID(1) & “><img border=0 src=images/downloadnow.gif alt=’This page may take some time to load due to the license checking procedures, please be patient.’></a></td>”
response.write Counter(File) & “</tr>”
rstSearch.MoveNext

ElseIf WHICH = “Patch” then
response.write “<tr><td><font face=tahoma color=#006699 size=1><img src=images/alert.gif> <b>” & Package  & “</td><td><a href=download.asp?File=” & File & “><img  border=0 src=images/downloadnow.gif alt=Please download/apply this Patch asap!></a></td>”
response.write Counter(File) & “</tr>”
rstSearch.MoveNext
Else
response.write “<tr><td><font face=tahoma color=#006699 size=1><b>” & Package  & “</td><td align=center><a href=download.asp?File=” & File & “><img  border=0 src=images/downloadnow.gif alt=’This software is approved by EIT.’></a></td>”
response.write Counter(File) & “</tr>”
rstSearch.MoveNext
End if
Loop

Set rstSearch = Nothing
cnnSearch.Close
Set cnnSearch = Nothing
End Sub

Function Counter(FILENAME)
Dim cnnSearch
Dim rstSearch
Dim strDBPath
Dim strSQL
Dim strSearch
Set cnnSearch = Server.CreateObject(”ADODB.Connection”)
cnnSearch.Open “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” & Server.Mappath(”db/hits.mdb”) & “;”
strSQL = “SELECT Count(downloads.Package) AS HITS FROM downloads WHERE (((downloads.Package)=’” & FILENAME & “‘));”
Set rstSearch = cnnSearch.Execute(strSQL)

Do While Not rstSearch.EOF
response.write “<td align=center><b><font face=tahoma size=1 color=006699>” & rstSearch.Fields(”HITS”).Value & “</font></td>”
rstSearch.MoveNext
Loop

Set rstSearch = Nothing
cnnSearch.Close
Set cnnSearch = Nothing
End Function

%>

‘======================


Aug 29 2008   1:11PM GMT

[TLBAT] Intranet: The database behind



Posted by: Alessandro Panzetta
Security, Database, Bandwidth, Active Server Pages, self-service, IT support, Intranet, Intranet portal

As described in the last post, the Download Center relies on a Microsoft Access database that will be described in this post.

So, first create a new MSAccess database and then create a table called “Packages” like the following:

Packages
ID PackageDesc PackageName PackageType NeededGroup

ID:         Auto increment

PackageDesc:    Contains a short description of the file (E.g. Microsoft FrontPage)

PackageName:    Is the filename, avoid using spaces (E.g. “MSaccess.exe” better than “MS Access.exe”) because this will be used to construct the download link

PackageType:    Can be Special or Standard or Goodie. Standard/Goodie will be available for download to everyone while Special will be only for the users that are members of given groups.

NeededGroup:    In case of Special package the visiting user must be part of this group in order to download the package.

Then create another table called “Sites” as the following:

Sites
Country Subnet Distrib_Point

Country:    Short name of the Country (E.g. ITA=Italy, GER=Germany)

Subnet:        The third octet of the country/site’s IP address range (E.g. ITA= 192.168.39.x)

Distrib_Point:    The web server in the given country (E.g. websrv_ITA)

The first table will handle information on the packages themselves and whether they’re freely accessible or not; the second table instead will be used in order to redirect the user to his/her local web server in order to save bandwidth. This is applicable only in environments in which the IP subnets are correctly set for country level and where in every country or site there is a local IIS web site.

In the next post I’ll be showing you how to build the homepage for this site and the techniques used for it….keep on reading!


Jun 26 2008   4:43PM GMT

[TLBAT] Control and see your band….width!



Posted by: Alessandro Panzetta
Bandwidth, IT support, Admin tools, TLBAT

You just subscribed a new contract with your ISP and they promised a given download/upload rate but you don’t know how to monitor this.

What would you do? Buy famous branded software and reduce your low budget or save bucks and use a free one (so you have more money left that you can send to me?? )…I’d say that you’ll go for the second choice…obviously.

The tool I talk about is the great Paessler’s Router Grapher that can provide you nice graphs that show how your bandwidth is used.

Graph example