Monthly Archives: September 2005

MyISAWebAdmin

Simple ASP-script for ISA Server that allow adding/deleting of computers in a ComputerSet from a web page.
I use this to open up Remote Desktop to my computer when Im out on the big bad internet.
Usage: First add your rules and computersets to ISA Server.
Add the computersets you want to be able to update to the objDictComputerSets dictinary object
(don´t forget to secure the script properly)

Requirements:

– ISA-Server (this script is tested for version 2004)

– IIS

– At least 1 computer set in ISA Server

– Policy rules that use your computer set (obviously)

<%
'=================================================================================================== 
'MyISAWebAdmin.asp
'
'Created by: Goran Tornqvist. 
'This script is freeware, do what you like with it ;)
' 
'Description: 
'Simple ASP-script for ISA Server that allow adding/deleting of computers in a ComputerSet from a web page.
'I use this to open up Remote Desktop to my computer when Im out on the big bad internet.
'Usage: First add your rules and computersets to ISA Server.
'Add the computersets you want to be able to update to the objDictComputerSets dictinary object
'=================================================================================================== 

Option Explicit
Response.Expires = -1
Response.ExpiresAbsolute = Now() - 10
Response.AddHeader "pragma","nocache"
Response.CacheControl = "nocache"
Response.Buffer = True

'ISA Server Constants
Const fpcInclude = 0
Const fpcSpecifiedProtocols = 1

Dim objDictComputerSets : Set objDictComputerSets = Server.CreateObject("Scripting.Dictionary")
objDictComputerSets.Add "Remote Desktop Hosts", "Update list of IP addresses allowed to connect with Remote Desktop to this computer."
'=================================================================================================== 
Dim strComputerSet, ComputerSets, strCommand, Item, ComputerSet, Computer, ComputerSet_Computers, i, strMember, strName, strIPAddress

strComputerSet = Request.QueryString("computerset")
If strComputerSet <> "" Then
	If NOT objDictComputerSets.Exists(strComputerSet) Then
		Response.Clear()
		Response.Write "Invalid computerset specified!"
		Response.End()
	End If
End If

' Create the root object.
Dim root  ' The FPCLib.FPC root object
Set root = Server.CreateObject("FPC.Root")

'Declare the other objects needed.
Dim isaArray    ' An FPCArray object
Dim policyrules ' An FPCPolicyRules collection
Dim urlsets     ' An FPCURLSets collection
Dim urlset      ' An FPCURLSet object
Dim newrule     ' An FPCPolicyRule object

' Get references to the array object, the policy
' rules collection, and the URL sets collection.
Set isaArray = root.GetContainingArray()

'All ComputerSets - Collection
Set ComputerSets = isaArray.RuleElements.ComputerSets

strCommand = Request.QueryString("cmd")
Select Case strCommand
	Case "addmember"
		If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
			strName = Request.Form("Name")
			strIPAddress = Request.Form("IPAddress")
			If strName <> "" AND strIPAddress <> "" Then
				On Error Resume Next
				Set ComputerSet = ComputerSets.Item(strComputerSet)
				If Err.Number <> 0 Then
					Response.Clear()
					Response.Write "Error while trying to set computerset " & strComputerSet
					Response.End()
				End If
				On Error Goto 0

				On Error Resume Next
				Set ComputerSet_Computers = ComputerSet.computers
				If Err.Number <> 0 Then
					Response.Clear()
					Response.Write "Error while trying to set get computers of computerset " & strComputerSet
					Response.End()
				End If
				On Error Goto 0

				On Error Resume Next
				ComputerSet_Computers.Add strName, strIPAddress
				If Err.Number <> 0 Then
					Response.Clear()
					Response.Write "Error when trying to add " & strName & "/" & strIPAddress & " to computerset " & strComputerSet
					Response.End()
				End If
				On Error Goto 0

				Computerset_Computers.Save
				Response.Redirect "./?computerset=" & Server.UrlEncode(strComputerSet)
			Else
				Response.Clear()
				Response.Write "Name and/or IP-address not specificed!"
				Response.End()
			End If
		End If
	Case "deletemember"
		strMember = Request.QueryString("member")
		If strMember <> "" Then
			On Error Resume Next
			Set ComputerSet = ComputerSets.Item(strComputerSet)
			If Err.Number <> 0 Then
				Response.Clear()
				Response.Write "Error while trying to set computerset " & strComputerSet
				Response.End()
			End If
			On Error Goto 0

			On Error Resume Next
			Set ComputerSet_Computers = ComputerSet.computers
			If Err.Number <> 0 Then
				Response.Clear()
				Response.Write "Error while trying to set get computers of computerset " & strComputerSet
				Response.End()
			End If
			On Error Goto 0

			On Error Resume Next
			ComputerSet_Computers.Remove strMember
			If Err.Number <> 0 Then
				Response.Clear()
				Response.Write "Error when trying to delete " & strMember & " from computerset " & strComputerSet
				Response.End()
			End If
			On Error Goto 0

			Computerset_Computers.Save
			Response.Redirect "./?computerset=" & Server.UrlEncode(strComputerSet)
		Else
			Response.Clear()
			Response.Write "Invalid member specificed!"
			Response.End()
		End If
End Select
%>
<HTML>
<HEAD>
<TITLE>My ISA Server Administration</TITLE>
</HEAD>
<BODY>
<H1>My ISA Server Administration</H1>
<HR>
<P>The following administration tasks are available</P>
<%
For Each Item In objDictComputerSets
	Response.Write "<P><A HREF=""./?computerset=" & Server.URLEncode(Item) & """>" & Item & "</A><BR/><I>" & objDictComputerSets(Item) & "</I></P>"
	If Item = strComputerSet Then
		Response.Write "<FORM ACTION=""./?computerset=" & Server.UrlEncode(strComputerSet) & "&cmd=addmember"" METHOD=""POST"">" & _
				"<TABLE BORDER=""0"" CELLPADDING=""0"" CELLSPACING=""0"">" & _
				"<TR>" & _
				"<TD WIDTH=""50"">&nbsp;</TD>" & _
				"<TD COLSPAN=""3"" HEIGHT=""30""><U>Current members to list - <A HREF=""./?computerset=" & Server.URLEncode(Item) & "&cmd=addmember"">Add new member</A></U></TD>" & _
				"</TR>" & _
				"<TR>" & _
				"<TD WIDTH=""50"">&nbsp;</TD>" & _
				"<TD WIDTH=""150"">Name</TD>" & _
				"<TD WIDTH=""150"">IP-address</TD>" & _
				"<TD WIDTH=""50"">&nbsp;</TD>" & _
				"</TR>"

		If strCommand = "addmember" Then
			Response.Write "<TR>" & _
							"<TD WIDTH=""50"">&nbsp;</TD>" & _
							"<TD WIDTH=""150""><INPUT TYPE=""TEXT"" NAME=""Name"" VALUE=""""/></TD>" & _
							"<TD WIDTH=""150""><INPUT TYPE=""TEXT"" NAME=""IPAddress"" VALUE=""""/></TD>" & _
							"<TD WIDTH=""50""><INPUT TYPE=""SUBMIT"" VALUE=""Add"";</TD>" & _
							"</TR>"
		End If

		On Error Resume Next
		Set ComputerSet = ComputerSets.Item(strComputerSet)
		If Err.Number <> 0 Then
			Response.Clear()
			Response.Write "Error while trying to set computerset " & strComputerSet
			Response.End()
		End If
		On Error Goto 0

		On Error Resume Next
		Set ComputerSet_Computers = ComputerSet.computers
		If Err.Number <> 0 Then
			Response.Clear()
			Response.Write "Error while trying to set get computers of computerset " & strComputerSet
			Response.End()
		End If
		On Error Goto 0

		For i = 1 To ComputerSet_Computers.Count
			Set Computer = ComputerSet_Computers.Item(i)
			Response.Write "<TR>" & _
					"<TD WIDTH=""50"">&nbsp;</TD>" & _
					"<TD>" & Computer.Name & "</TD>" & _
					"<TD>" & Computer.IPAddress & "</TD>" & _
					"<TD><A HREF=""./?computerset=" & Server.URLEncode(Item) & "&cmd=deletemember&member=" & Server.URLEncode(Computer.Name) & """>Delete</A></TD>" & _
					"</TR>"
		Next
		Set ComputerSet = Nothing
		Set ComputerSet_Computers = Nothing
		Response.Write "</TABLE>" & _
						"</FORM>"
	End If
Next

Set root = Nothing
Set isaArray = Nothing
Set ComputerSets = Nothing
%>
</BODY>
</HTML>