changeset 499:3f11f8e93035

Prefix all system template variables with 'sys_' 2004/01/15 21:20:56-05:00 optonline.net!jeffpc Fix several bugs 2004/01/10 13:25:02-05:00 optonline.net!jeffpc Use templates (Logical change 1.148)
author optonline.net!jeffpc
date Fri, 16 Jan 2004 02:46:03 +0000
parents 3e6aa262fe04
children 2bd91e74e581
files av_conn.py
diffstat 1 files changed, 43 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/av_conn.py	Fri Jan 16 02:46:03 2004 +0000
+++ b/av_conn.py	Fri Jan 16 02:46:03 2004 +0000
@@ -25,6 +25,7 @@
 import re
 import cgi
 import time
+from htmltmpl import TemplateManager, TemplateProcessor
 
 import av_debug
 import av_db
@@ -36,12 +37,15 @@
 
 class Conn:
 	""" Class to hold all connection data and more """
-	def __init__(self):
+	def __init__(self,reqlogin=1):
 		""" Set all variables to their default values
 
 		does not return anything """
 		self.__compile_regexp()
-		
+		self.__reqlogin = reqlogin
+		self.templ = TemplateManager().prepare("templates/window.tmpl")
+		self.tproc = TemplateProcessor(html_escape=0)
+
 		self.db = av_db.DB()
 		self.html = av_html.HTML()
 		self.user = av_user.User()
@@ -52,6 +56,26 @@
 		self.user.attach(self)
 		self.utils.attach(self)
 
+		self.__set_template_vars()
+		self.__check_login()
+
+	def __check_login(self):
+		if ((self.__reqlogin) and (not self.user.isloggedin()) and (not self.user.timedout())):
+			self.html.header("Error")
+			self.html.heading("Error")
+			text = "ERROR" # default text, will be changed at run time
+			if (self.user.TEXTBUF["logincheckerror"]):
+				text  = self.user.TEXTBUF["logincheckerror"]
+			if (text=="ERROR"): # This should not happen
+				text = "<br />Sorry, but you must log in to access this page. To log in, select the appropreate option from the menu."
+				av_log.seclog(self,"User attempted to access " + self.currentpage() + " without specifying SESSION ID")
+			self.html.body.init()
+			self.html.body.set(text)
+			self.html.footer()
+			print self.flush()
+			self.conn.exit()
+
+	
 	def __compile_regexp(self):
 		""" Compiles all regural expressions used throughout the program
 		
@@ -60,20 +84,25 @@
 		self.regexp_Aa0 = re.compile('^[A-Za-z0-9]+$')
 		self.regexp_a0 = re.compile('^[a-z0-9]+$')
 		self.regexp_0 = re.compile('^[0-9]+$')
-	
+
+	def __set_template_vars(self):
+		self.tproc.set("sys_progname", av_settings.getSetting(self,"name"))
+		self.tproc.set("sys_sid",self.user.getSID())
+
 	def securitycheck(self,condition,loglevel,printtext="Sorry, but you don't have the necesarry priveledges to view this page.",logmessage=None):
 		""" Return printtext and add logmessage to loglevel log if condition is false
 		
 		does not return anything """
 		if (condition):
-			return ""
+			return None
 
 		if (logmessage is None):
 			logmessage = "User \"" + self.user.UID2User() + "\" tried to access " + self.currentscript() + " but lacks the necessary priv."
 		
 		av_log.genericlog(self,logmessage,loglevel)
-		print printtext
-		print self.html.footer()
+		self.html.body.set(printtext)
+		self.html.footer()
+		print self.flush()
 		self.exit()
 	
 	def getIP(self):
@@ -204,6 +233,14 @@
 			return "Yes"
 		return "No"
 	
+	def flush(self):
+		""" Sends all buffered output to the client
+
+		does not return anything """
+		self.html.menu(reqlogin=self.__reqlogin)
+		self.tproc.set("sys_body",self.html.body.get())
+		return self.tproc.process(self.templ)
+	
 	def exit(self):
 		""" Terminate the program