Update of /cvsroot/tmda/tmda/contrib/cgi
In directory sc8-pr-cvs1:/tmp/cvs-serv32729
Modified Files:
CgiUtil.py
Log Message:
Added a TermError function to cleanly display any terminal errors.
Index: CgiUtil.py
===================================================================
RCS file: /cvsroot/tmda/tmda/contrib/cgi/CgiUtil.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CgiUtil.py 26 Nov 2002 19:36:07 -0000 1.2
+++ CgiUtil.py 30 Nov 2002 18:11:57 -0000 1.3
@@ -22,6 +22,9 @@
"Utilities for tmda-cgi."
import cgi
+import os
+import sys
+import time
def Size(MsgObj):
MsgSize = len(MsgObj.as_string())
@@ -44,3 +47,60 @@
if s:
return cgi.escape(s)
return ""
+
+def FileDetails(Desc, Filename):
+ try:
+ Perm = os.stat(Filename)
+ Perm = "%03o" % (Perm[0] & 07777)
+ except OSError:
+ Perm = "???"
+ return "%s file <tt>%s</tt>, permissions %s" % (Desc, Filename, Perm)
+
+def TermError(Err, Cause, Failed, Other, Recommend):
+ if os.geteuid():
+ if os.access(os.environ["HOME"], os.W_OK):
+ Mode = "single-user"
+ else:
+ Mode = "no-su"
+ else:
+ Mode = "system-wide"
+ print """Expires: Mon, 26 Jul 1997 05:00:00 GMT
+Last-Modified: %s GMT
+Cache-Control: no-cache, must-revalidate
+Pragma: no-cache
+Content-type: text/html
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+<title>tmda-cgi Error</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+</head>
+
+<body>
+<p>tmda-cgi cannot continue because a terminal error has been encountered.</p>
+<table>
+ <tr>
+ <td width="100" valign="top"><b>Error:</b></td>
+ <td>%s</td>
+ </tr>
+ <tr>
+ <td valign="top"><b>Cause:</b></td>
+ <td>%s</td>
+ </tr>
+ <tr>
+ <td valign="top"><b>Additional:</b></td>
+ <td>Running in %s mode.<br>
+ Attempted to %s with euid %d, egid %d.<br>
+ %s
+ </td>
+ </tr>
+ <tr>
+ <td valign="top"><b>Recommend:</b></td>
+ <td>%s</td>
+ </tr>
+</table>
+</body>
+</html>""" % (time.strftime("%a, %d %b %Y %H:%M:%S"), Err, Cause, Mode, Failed,
+ os.geteuid(), os.getegid(), Other, Recommend)
+ sys.exit(0)
\ No newline at end of file
_______________________________________
tmda-cvs mailing list
http://tmda.net/lists/listinfo/tmda-cvs