Changeset c216863 for server/lib/ipp.py
- Timestamp:
- Oct 30, 2010, 11:35:37 PM (14 years ago)
- Branches:
- no-cups
- Children:
- 84e8137
- Parents:
- efee0f1
- git-author:
- Jessica B. Hamrick <jhamrick@…> (10/30/10 23:35:37)
- git-committer:
- Jessica B. Hamrick <jhamrick@…> (10/30/10 23:35:37)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/lib/ipp.py
refee0f1 rc216863 1 1 #!/usr/bin/env python 2 2 3 # Adapted from the Quickprint IPP server code (http://qui ckprint.mit.edu)3 # Adapted from the Quickprint IPP server code (http://quikprint.mit.edu) 4 4 # Modifications and additions written by Jessica Hamrick (jhamrick@mit.edu) 5 5 6 6 # Notes and Todo: 7 7 # - make sure package creates gutenbach folder in /var/log 8 # - ok, so ipplib actually seems to be an unsupported library.9 # Maybe want to write this in perl instead since there is10 # Net::IPP::IPPRequest11 8 12 9 import os, sys … … 35 32 error("Could not create temporary directory '%s'" % TEMPDIR) 36 33 37 38 authfail = False 39 try: 40 printer_uri = 'http://%s%s' % (os.environ['SERVER_NAME'], os.environ['REQUEST_URI']) 41 except: 42 pass 43 44 try: 45 argv = cgi.parse(os.environ['QUERY_STRING']) 46 webauth = argv['BASIC'] 47 if type(webauth) is list: 48 webauth = webauth[0] 49 webauth = webauth.split(' ')[1] 50 if not len(webauth): 51 authfail = True 52 else: 53 (authu, authp) = webauth.decode('base64').split(':') 54 db=MySQLdb.connect(read_default_file="/mit/gutenbach/.my.cnf") 55 c = db.cursor() 56 c.execute("SELECT 1 FROM auth WHERE auser=%s AND apass=%s LIMIT 1", (authu,authp,)) 57 if c.fetchone() is None: 58 authfail = True 59 except Exception, e: 60 authfail = True 61 62 if authfail: 63 print "Status: 401 Authorization Required" 64 print "WWW-Authenticate: Basic realm=\"Gutenbach\"" 65 print "Content-type: application/ipp\n" 66 sys.exit(0) 67 else: 68 AUTH = authu.lower() 69 34 # print the content type for our request 70 35 print "Content-type: application/ipp\n" 71 36 72 37 class IPPServer(object): 38 39 # nothing to do in the init 73 40 def __init__(self): 74 41 pass 42 43 # this function processes an IPP request and sends a response 75 44 def process(self, request_in, response_out): 76 data_in = request_in.read() 77 if not len(data_in): 78 return 79 request = IPPRequest(data=data_in) 80 request.parse() 45 81 46 82 47 response = IPPRequest(version=request.version, 83 operation_id=request.operation_id,84 request_id=request.request_id)48 operation_id=request.operation_id, 49 request_id=request.request_id) 85 50 #file('/mit/gutenbach/tmp/requests/'+str(request.operation_id)).write() 86 51 handler = getattr(self, "_operation_%d" % request.operation_id, None)
Note: See TracChangeset
for help on using the changeset viewer.