<html>
<head>
<title>sessiontester Source</title>
</head>
<body>
<plaintext>
sessiontester.ctf

<%
	display_form = true

	session = Request().getSession(false)

	action = Request().Form("action")
	
	if action <> null then
		action = action.toLowerCase()

		if action = "set value" then
			if session <> null then
				key = Request().Form("key")
				if key <> null then
					key = key.trim()

					if key.length() > 0 then
						value = Request().Form("value")
						if value = null then
							value = ""
						else
							value = value.trim()
						end

						session.setAttribute(key, value)
					end
				end
			end
		elseif action = "remove value" then
			if session <> null then
				key = Request().Form("key")
				if key <> null then
					key = key.trim()

					if key.length() > 0 then
						session.removeAttribute(key)
					end
				end
			end
		elseif action = "create session" then
			session = Request().getSession(true)
		elseif action = "remove session" then
			if session <> null then
				session.invalidate()
				session = null
			end
		elseif action = "redirect test" then
			Response().redirect(Response().encodeURL("./sessionredirect.ctf"))
			display_form = false
		end
	end

	if display_form then
%>
<html>
    <head>
        <title>Session Tester</title>
    </head>
    <body>
		<h1>Session Tester</h1>
		<hr>

		Session Status:
		<%
			if session = null then
				Response().println(" does not exist<br>")
			else
				if session.isNew() then
					Response().println("is new<br>")
				elseif Request().isSessionValid() then
					Response().println("is valid<br>")
				else
					Response().println("is invalid<br>")
				end
		%>

		Session Id: <%=session.getId()%><br>
		Creation Time: <%=Date(session.getCreationTime()).toString()%><br>
		Last Accessed Time: <%=Date(session.getLastAccessedTime()).toString()%><br>
		Maximum Inactive Interval: <%=session.getTimeout()%> seconds<br>

		Session From:
		<%
				if Request().isSessionFromURL() then
					Response().println("URL<br>")
				elseif Request().isSessionFromCookie() then
					Response().println("Cookie<br>")
				else
					Response().println("Other<br>")
				end
		%>

		<hr>

		Session Values:<br>
		<%
				count = 0

				e = session.getAttributeNames()

				do while e.hasMoreElements()
					count = count + 1

					name = e.nextElement().toString()

					Response().println(name + " = " + session.getAttribute(name).toString() + "<br>")
				loop

				if count = 0 then
					Response().println("None")
				end
			end
		%>

		<hr>

		<form action="<%=Response().encodeURL("./sessiontester.ctf"%>" method="get">
		Key:
		<input type="text" name="key" value="">
		<br>
		Value:
		<input type="text" name="value" value="">
		<p>
		<input type="submit" name = "action" value="Set Value">
		<input type="submit" name = "action" value="Remove Value">
		<input type="submit" name = "action" value="Create Session">
		<input type="submit" name = "action" value="Remove Session">
		<input type="submit" name = "action" value="Redirect Test">
		</form>

	</body>
</html>
<%	end%>

==================================================
sessionredirect.ctf

<html>
<head><title>Session Redirect Tester</title></head>
<body>
<a href="<%=Response().encodeURL("./sessiontester.ctf")%>">Click here to return to Session Tester.</a>
</body>
</html>

