#!/usr/bin/env python2 # # @MASTER@ # # This is the CGI that processes the form return from GPS information form. # # The wackiness with output_sample_com happens because the user has to click # through twice - once to review and once to submit. Thus the content has # to be embedded as a hidden field - and base64-armored, because it might # otherwise have stuff in it that isn't legal in HTML attribute values. # import sys, os, smtplib, base64 from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.encoders import encode_base64 import cgi import cgitb; cgitb.enable() # for troubleshooting # All information on the project siting, mailing # lists, and originating host lives here. website = '@WEBSITE@' to_address = '@DEVMAIL@' servaddr = '@FORMSERVER@' # Get form value, send mail on submission form = cgi.FieldStorage() print "Content-type: text/html" print "" if form.has_key('output_sample_content'): output_sample_content = base64.b64decode(form.getvalue('output_sample_content')) else: output_sample_content = '' if not output_sample_content and form.has_key('output_sample_file'): fileitem = form['output_sample_file'] if fileitem.filename: output_sample_content = fileitem.file.read() def hasRequiredElements(form): for fld in ("submitter", "vendor", "model", "techdoc"): if not form.getvalue(fld): return False return not not output_sample_content formfields = ("submitter", "vendor", "model", "techdoc", "packaging", "chipset", "firmware", "nmea", "interfaces", "usbchip", "tested", "rating", "configurable", "output_sample_file", "output_sample_content", "location", "date", "sample_notes", ) if hasRequiredElements(form) and form.getvalue("action") == "Send Report": report = MIMEMultipart() report['Subject'] = 'New device report' report['To'] = to_address report.preamble = "Part 1 is form data, part 2 is the sample" # Render the form data as an entry for gpscap.ini msg = "[%s]\n" % form.getvalue('model').strip() for field in formfields: if form.getvalue(field) and not field == 'model' and not field.startswith('output_sample'): msg += "%s: %s\n" % (field, form.getvalue(field)) report.attach(MIMEText(msg)) # Decorate the log data with some canned headers. # Omitted: nmea, notes, techdoc, tested, usbchip, configurable, header = '' header += "# Name: %s %s\n" \ % (form.getvalue('vendor'), form.getvalue('model')) for fld in ("chipset", "firmware", 'date', 'submitter', 'location'): if form.has_key(fld) and form.getvalue(fld): header += "# %s = %s\n" % (fld.capitalize(), form.getvalue(fld)) if form.has_key('sample_notes') and form.getvalue('sample_notes'): header += "# Notes: %s\n" % form.getvalue('sample_notes') header += "type = device\n" content = MIMEText(header + output_sample_content) encode_base64(content) report.attach(content) # Ship it. msg = report.as_string() smtp = smtplib.SMTP("localhost") #smtp.set_debuglevel(1) try: smtp.sendmail(servaddr, [to_address], msg) smtp.quit() print "
Your report on the %s %s was successfully recorded. Thanks for helping improve GPSD.\n" \ % (form.getvalue('vendor'), form.getvalue('model')) except smtplib.SMTPSenderRefused, e: print "
The error code was %s: %s
" % (e.code, e.response) sys.exit(0) # Everything below here is page generation defaults = {} for key in formfields: if key in form.keys(): defaults[key] = form.getvalue(key).strip() else: defaults[key] = "" defaults['request_uri'] = os.getenv('REQUEST_URI') defaults["website"] = website defaults["to_address"] = to_address defaults["servaddr"] = servaddr defaults['output_sample_content'] = output_sample_content defaults['armored_sample_content'] = base64.b64encode(output_sample_content) print '''\Please use this form to report gpsd
successes or
failures with GPS and AIS units, and also to upload a sample of the receiver\'s
output so we can add it to our regression tests and ensure continued
support of the device.
Information gathered so far:
'''
if form.getvalue("vendor"):
print "Vendor is "+cgi.escape(form.getvalue("vendor"))+" \n"; else: print "No vendor. \n"; if form.getvalue("model"): print "Model is "+cgi.escape(form.getvalue("model"))+" \n"; else: print "No model specified. \n"; if form.getvalue("techdoc"): print "Document URL specified. \n"; else: print "No document URL. \n"; if output_sample_content: print "Output sample uploaded"; else: print "No output sample. \n"; if form.getvalue("submitter"): print "Contact address is "+cgi.escape(form.getvalue("submitter"))+" \n"; else: print "No contact address. \n"; print " | ";
if form.getvalue("packaging"):
print "Packaging type is "+cgi.escape(form.getvalue("packaging"))+" \n"; else: print "No packaging type specified. \n"; if form.getvalue("chipset"): print "Chipset is "+cgi.escape(form.getvalue("chipset"))+" \n"; else: print "Chipset not specified. \n"; if form.getvalue("firmware"): print "Firmware is "+cgi.escape(form.getvalue("firmware"))+" \n"; else: print "Firmware not specified. \n"; if form.getvalue("nmea"): print "NMEA version is "+cgi.escape(form.getvalue("nmea"))+" \n"; else: print "NMEA version not specified. \n"; if form.getvalue("interfaces"): print "Interface type is "+cgi.escape(form.getvalue("interfaces"))+" \n"; if form.getvalue("interfaces") == "USB": if form.getvalue("usbchip"): print "USB chip is "+cgi.escape(form.getvalue("usbchip"))+" \n"; else: print "No USB chip specified. \n"; else: print "No interface type specified. \n"; if form.getvalue("tested"): print "Tested with GPSD version "+cgi.escape(form.getvalue("tested"))+" \n"; else: print "No GPSD version specified. \n"; print " | ";
if form.getvalue("rating"):
print "GPSD compatibility is "+cgi.escape(form.getvalue("rating"))+" \n"; else: print "No GPSD compatiblity specified. \n"; if form.getvalue("noconfigure") == 'yes': print "Device can be sent catatonic by baud-rate changes. \n"; elif form.getvalue("noconfigure") == 'no': print "Device handles baud-rate changes correctly. \n"; else: print "How baud-rate changes are handled is unspecified. \n"; if form.getvalue("notes"): print "Technical notes have been entered. \n"; else: print "No technical notes. \n"; if form.getvalue("location"): print "Sample location "+cgi.escape(form.getvalue("location"))+" \n"; else: print "No sample location specified. \n"; if form.getvalue("date"): print "Sample date "+cgi.escape(form.getvalue("date"))+" \n"; else: print "No sample date specified. \n"; if form.getvalue("sample_notes"): print "Notes on the sample have been entered. \n"; else: print "No notes on the sample. \n"; print " |
The report is ready to be submitted.
' else: print 'Required fields are missing; please fill them in.
' print '''