Newer
Older
Digital_Repository / Old / pysocks / upload.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.  
  32.  
  33. def escape(data):
  34. data = data.replace('\\', '\\\\')
  35. data = data.replace('"', '\\"')
  36. data = data.replace('"', '\\"')
  37.  
  38. return data
  39. #------------------------ CODE ------------------------------------
  40. def main():
  41. db = access.Access(dbname="pysocks", user='crypt')
  42.  
  43. form = cgi.FieldStorage()
  44.  
  45. desc = escape(form['description'].value)
  46.  
  47. the_file = escape(form['the_file'].value)
  48.  
  49. db.put('the_data', {'description':description, 'file':the_file})
  50.  
  51. print 'Content-type: text/html\n\nfile uploaded'
  52.  
  53. #------------------------------------------------------------------------
  54.  
  55. if (DEBUG_MAIN):
  56. try:
  57. main()
  58. except SystemExit:
  59. pass
  60. except:
  61. # errMessage("an unkown error has occurred program terminating")
  62. sys.stderr = sys.stdout
  63. print '\n\n<PRE>'
  64. traceback.print_exc()
  65. else:
  66. main()
  67.  
  68. #------------------------ END ------------------------------------