Newer
Older
Digital_Repository / Old / pysocks / pysocks.cgi
nstanger on 12 Nov 2005 1 KB - Second attempt at importing!
  1. #! /usr/bin/python
  2.  
  3. #------------------------------------------------------------------------
  4. # name:
  5. # author: J Skinner
  6. # Date Written:
  7. # Purpose:
  8. # Notes
  9. #------------------------------------------------------------------------
  10.  
  11.  
  12.  
  13. #------------------------ GLOBALS ------------------------------------
  14.  
  15. DEBUG_MAIN = 0
  16. DEBUG = 0
  17. IS_CGI = 1
  18. IS_DB = 1
  19.  
  20. #------------------------ IMPORTS ------------------------------------
  21.  
  22. import string
  23. import os
  24. import sys
  25.  
  26. import cgi
  27. import traceback
  28.  
  29. import access
  30.  
  31. #import cookie
  32. from auth import Auth
  33. from page import Page
  34.  
  35. #------------------------ GLOBALS ----------------------------------
  36.  
  37. HEADER_BLOCK = '''\
  38. Content-type: text/html
  39. %(cookie)s
  40.  
  41. '''
  42. #------------------------ CODE ------------------------------------
  43.  
  44.  
  45. def get_xtra_info(form):
  46. return None
  47.  
  48. def main():
  49. print 'Content-type: text/html'
  50. print
  51.  
  52. db = access.Access(dbname='pysocks', user='crypt')
  53. page_info = None
  54. auth = Auth(db)
  55.  
  56. form = cgi.FieldStorage()
  57.  
  58. status, page_id = auth.login_check(form)
  59.  
  60. xtra_info = get_xtra_info(form)
  61.  
  62. if form.has_key('page'):
  63. if page_id == None: page_id =form['page'].value
  64. the_page = Page(page_id, db, auth, page_info, xtra_info)
  65.  
  66. else:
  67. # render the default page
  68. the_page = Page(1, db, auth, page_info, xtra_info)
  69.  
  70.  
  71.  
  72. # output the actual page
  73.  
  74. print HEADER_BLOCK%{'cookie':auth.show()}
  75.  
  76. print the_page.show()
  77. print '-- END OF PAGE --'
  78. #------------------------------------------------------------------------
  79.  
  80. if (DEBUG_MAIN):
  81. try:
  82. main()
  83. except SystemExit:
  84. pass
  85. except:
  86. # errMessage("an unkown error has occurred program terminating")
  87. sys.stderr = sys.stdout
  88. print '\n\n<PRE>'
  89. traceback.print_exc()
  90. else:
  91. main()
  92.  
  93. #------------------------ END ------------------------------------