listing25-3.py 617 B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/env python
  2. print('Content-type: text/html\n')
  3. from os.path import join, abspath
  4. from hashlib import sha1
  5. import cgi, sys
  6. BASE_DIR = abspath('data')
  7. form = cgi.FieldStorage()
  8. text = form.getvalue('text')
  9. filename = form.getvalue('filename')
  10. password = form.getvalue('password')
  11. if not (filename and text and password):
  12. print('Invalid parameters.')
  13. sys.exit()
  14. if sha1(password.encode()).hexdigest() != '8843d7f92416211de9ebb963ff4ce28125932878':
  15. print('Invalid password')
  16. sys.exit()
  17. f = open(join(BASE_DIR,filename), 'w')
  18. f.write(text)
  19. f.close()
  20. print('The file has been saved.')