gps_report.cgi.in 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. #!/usr/bin/env python2
  2. #
  3. # @MASTER@
  4. # @GENERATED@
  5. #
  6. # This is the CGI that processes the form return from GPS information form.
  7. #
  8. # The wackiness with output_sample_com happens because the user has to click
  9. # through twice - once to review and once to submit. Thus the content has
  10. # to be embedded as a hidden field - and base64-armored, because it might
  11. # otherwise have stuff in it that isn't legal in HTML attribute values.
  12. #
  13. import sys, os, smtplib, base64
  14. from email.mime.text import MIMEText
  15. from email.mime.multipart import MIMEMultipart
  16. from email.encoders import encode_base64
  17. import cgi
  18. import cgitb; cgitb.enable() # for troubleshooting
  19. # All information on the project siting, mailing
  20. # lists, and originating host lives here.
  21. website = '@WEBSITE@'
  22. to_address = '@DEVMAIL@'
  23. servaddr = '@FORMSERVER@'
  24. # Get form value, send mail on submission
  25. form = cgi.FieldStorage()
  26. print "Content-type: text/html"
  27. print ""
  28. if form.has_key('output_sample_content'):
  29. output_sample_content = base64.b64decode(form.getvalue('output_sample_content'))
  30. else:
  31. output_sample_content = ''
  32. if not output_sample_content and form.has_key('output_sample_file'):
  33. fileitem = form['output_sample_file']
  34. if fileitem.filename:
  35. output_sample_content = fileitem.file.read()
  36. def hasRequiredElements(form):
  37. for fld in ("submitter", "vendor", "model", "techdoc"):
  38. if not form.getvalue(fld):
  39. return False
  40. return not not output_sample_content
  41. formfields = ("submitter",
  42. "vendor",
  43. "model",
  44. "techdoc",
  45. "packaging",
  46. "chipset",
  47. "firmware",
  48. "nmea",
  49. "interfaces",
  50. "usbchip",
  51. "tested",
  52. "rating",
  53. "configurable",
  54. "output_sample_file",
  55. "output_sample_content",
  56. "location",
  57. "date",
  58. "sample_notes",
  59. )
  60. if hasRequiredElements(form) and form.getvalue("action") == "Send Report":
  61. report = MIMEMultipart()
  62. report['Subject'] = 'New device report'
  63. report['To'] = to_address
  64. report.preamble = "Part 1 is form data, part 2 is the sample"
  65. # Render the form data as an entry for gpscap.ini
  66. msg = "[%s]\n" % form.getvalue('model').strip()
  67. for field in formfields:
  68. if form.getvalue(field) and not field == 'model' and not field.startswith('output_sample'):
  69. msg += "%s: %s\n" % (field, form.getvalue(field))
  70. report.attach(MIMEText(msg))
  71. # Decorate the log data with some canned headers.
  72. # Omitted: nmea, notes, techdoc, tested, usbchip, configurable,
  73. header = ''
  74. header += "# Name: %s %s\n" \
  75. % (form.getvalue('vendor'), form.getvalue('model'))
  76. for fld in ("chipset", "firmware", 'date', 'submitter', 'location'):
  77. if form.has_key(fld) and form.getvalue(fld):
  78. header += "# %s = %s\n" % (fld.capitalize(), form.getvalue(fld))
  79. if form.has_key('sample_notes') and form.getvalue('sample_notes'):
  80. header += "# Notes: %s\n" % form.getvalue('sample_notes')
  81. header += "type = device\n"
  82. content = MIMEText(header + output_sample_content)
  83. encode_base64(content)
  84. report.attach(content)
  85. # Ship it.
  86. msg = report.as_string()
  87. smtp = smtplib.SMTP("localhost")
  88. #smtp.set_debuglevel(1)
  89. try:
  90. smtp.sendmail(servaddr, [to_address], msg)
  91. smtp.quit()
  92. print "<H1>New device report accepted.</H1>\n"
  93. print "<p>Your report on the %s %s was successfully recorded. Thanks for helping improve GPSD.\n" \
  94. % (form.getvalue('vendor'), form.getvalue('model'))
  95. except smtplib.SMTPSenderRefused, e:
  96. print "<H1>Your submission failed.</H1>\n"
  97. print "<p>The error code was %s: %s</p>" % (e.code, e.response)
  98. sys.exit(0)
  99. # Everything below here is page generation
  100. defaults = {}
  101. for key in formfields:
  102. if key in form.keys():
  103. defaults[key] = form.getvalue(key).strip()
  104. else:
  105. defaults[key] = ""
  106. defaults['request_uri'] = os.getenv('REQUEST_URI')
  107. defaults["website"] = website
  108. defaults["to_address"] = to_address
  109. defaults["servaddr"] = servaddr
  110. defaults['output_sample_content'] = output_sample_content
  111. defaults['armored_sample_content'] = base64.b64encode(output_sample_content)
  112. print '''\
  113. <!DOCTYPE HTML>
  114. <html lang="en">
  115. <head lang="en">
  116. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  117. <meta name="Author" content="Eric S. Raymond">
  118. <meta name="Description" content="Report the GPSD compatibility of your GPS.">
  119. <meta name="Keywords" content="GPS, gpsd,report">
  120. <meta name="Revised" content="9 Apr 2015">
  121. <meta name="robots" content="index,follow">
  122. <title></title>
  123. <link rel="stylesheet" href="main.css" type="text/css">
  124. </head>
  125. <body>
  126. <div id="Content">
  127. <h1>GPSD Receiver Reporting Form</h1>
  128. <p>Please use this form to report <code>gpsd</code> successes or
  129. failures with GPS and AIS units, and also to upload a sample of the receiver\'s
  130. output so we can add it to our regression tests and ensure continued
  131. support of the device.</p>
  132. <p>Information gathered so far:</p>
  133. <table style="border:0;width:100%"><tr><td style="text-align:center">
  134. '''
  135. if form.getvalue("vendor"):
  136. print "Vendor is <code>"+cgi.escape(form.getvalue("vendor"))+"</code><br>\n";
  137. else:
  138. print "<span style='color:#ff0000;'>No vendor.</span><br>\n";
  139. if form.getvalue("model"):
  140. print "Model is <code>"+cgi.escape(form.getvalue("model"))+"</code><br>\n";
  141. else:
  142. print "<span style='color:#ff0000;'>No model specified.</span><br>\n";
  143. if form.getvalue("techdoc"):
  144. print "<a href='"+cgi.escape(form.getvalue("techdoc"))+"'>Document URL specified.</a><br>\n";
  145. else:
  146. print "<span style='color:#ff0000;'>No document URL.</span><br>\n";
  147. if output_sample_content:
  148. print "Output sample uploaded";
  149. else:
  150. print "<span style='color:#ff0000;'>No output sample.</span><br>\n";
  151. if form.getvalue("submitter"):
  152. print "Contact address is <code>"+cgi.escape(form.getvalue("submitter"))+"</code><br>\n";
  153. else:
  154. print "<span style='color:#ff0000;'>No contact address.</span><br>\n";
  155. print "</td><td style='text-align:center'>";
  156. if form.getvalue("packaging"):
  157. print "Packaging type is <code>"+cgi.escape(form.getvalue("packaging"))+"</code><br>\n";
  158. else:
  159. print "No packaging type specified.<br>\n";
  160. if form.getvalue("chipset"):
  161. print "Chipset is <code>"+cgi.escape(form.getvalue("chipset"))+"</code><br>\n";
  162. else:
  163. print "Chipset not specified.<br>\n";
  164. if form.getvalue("firmware"):
  165. print "Firmware is <code>"+cgi.escape(form.getvalue("firmware"))+"</code><br>\n";
  166. else:
  167. print "Firmware not specified.<br>\n";
  168. if form.getvalue("nmea"):
  169. print "NMEA version is <code>"+cgi.escape(form.getvalue("nmea"))+"</code><br>\n";
  170. else:
  171. print "NMEA version not specified.<br>\n";
  172. if form.getvalue("interfaces"):
  173. print "Interface type is <code>"+cgi.escape(form.getvalue("interfaces"))+"</code><br>\n";
  174. if form.getvalue("interfaces") == "USB":
  175. if form.getvalue("usbchip"):
  176. print "USB chip is <code>"+cgi.escape(form.getvalue("usbchip"))+"</code><br>\n";
  177. else:
  178. print "No USB chip specified.<br>\n";
  179. else:
  180. print "No interface type specified.<br>\n";
  181. if form.getvalue("tested"):
  182. print "Tested with GPSD version <code>"+cgi.escape(form.getvalue("tested"))+"</code><br>\n";
  183. else:
  184. print "No GPSD version specified.<br>\n";
  185. print "</td><td style='text-align:center'>";
  186. if form.getvalue("rating"):
  187. print "GPSD compatibility is <code>"+cgi.escape(form.getvalue("rating"))+"</code><br>\n";
  188. else:
  189. print "No GPSD compatibility specified.<br>\n";
  190. if form.getvalue("noconfigure") == 'yes':
  191. print "Device can be sent catatonic by baud-rate changes.<br>\n";
  192. elif form.getvalue("noconfigure") == 'no':
  193. print "Device handles baud-rate changes correctly.<br>\n";
  194. else:
  195. print "How baud-rate changes are handled is unspecified.<br>\n";
  196. if form.getvalue("notes"):
  197. print "Technical notes have been entered.<br>\n";
  198. else:
  199. print "No technical notes.<br>\n";
  200. if form.getvalue("location"):
  201. print "Sample location <code>"+cgi.escape(form.getvalue("location"))+"</code><br>\n";
  202. else:
  203. print "No sample location specified.<br>\n";
  204. if form.getvalue("date"):
  205. print "Sample date <code>"+cgi.escape(form.getvalue("date"))+"</code><br>\n";
  206. else:
  207. print "No sample date specified.<br>\n";
  208. if form.getvalue("sample_notes"):
  209. print "Notes on the sample have been entered.<br>\n";
  210. else:
  211. print "No notes on the sample.<br>\n";
  212. print "</td></tr></table>";
  213. if hasRequiredElements(form):
  214. print '<p>The report is ready to be submitted.</p>'
  215. else:
  216. print '<p style="color:#ff0000;">Required fields are missing; please fill them in.</p>'
  217. print '''
  218. <form action="%(request_uri)s" method=POST enctype="multipart/form-data">
  219. <p>Fields marked <em style="color: #ff0000;">Important!</em> have to be filled
  220. in for the report to be useful. These are: submitter contact address, vendor,
  221. model, documentation URL, and output sample. Other fields represent things we
  222. might be able to find out ourselves, but which are easier for you to determine.
  223. Every bit of information you can give us about your receiver will help make the
  224. support for it more reliable.</p>
  225. <hr>
  226. <h2>Receiver type identification</h2>
  227. <p><em style="color: #ff0000;">Important!</em> Identify the vendor and model of
  228. your device.</p>
  229. <p>Example: <code>Haicom</code> and <code>303S</code>.</p>
  230. <p><em>Vendor:&nbsp;</em>
  231. <input type="text"
  232. name="vendor"
  233. size="72"
  234. value="%(vendor)s"></p>
  235. <p><em>Model:&nbsp;&nbsp;</em>
  236. <input type="text"
  237. name="model"
  238. size="72"
  239. value="%(model)s"></p>
  240. <p><em style="color: #ff0000;">Important!</em> We need a URL pointing to a
  241. technical manual for the device. You can usually find this on the
  242. vendor\'s website by giving a search engine the product name. If it\'s
  243. not linked directly from the vendor\'s page for the individual product,
  244. look under "Technical Support" or "Product support" on the vendor\'s
  245. main page.</p>
  246. <p>Example: <code>http://www.haicom.com.tw/gps303s.shtml</code></p>
  247. <p><em>URL of a technical manual:</em>
  248. <input type="text"
  249. name="techdoc"
  250. size="72"
  251. value="%(techdoc)s"></p>
  252. <p>It is useful to have an indication of how the receiver is packaged.
  253. <p><em>Packaging:</em></p>
  254. ''' % defaults
  255. packagetypes = (
  256. ('mouse', 'A "mouse" is a standalone sensor in a display-less case '
  257. 'designed to be used as a peripheral cabled to a computer.'),
  258. ('dongle', 'A "dongle" is a standalone sensor in a display-less case '
  259. 'resembling a thumb drive intended to be plugged directly '
  260. 'into a USB port.'),
  261. ('handset', 'A "handset" is a standalone unit with a display and '
  262. 'human-usable controls.'),
  263. ('handsfree', 'A "handsfree" is a hands-free unit with display designed '
  264. 'for mounting on a car windshield or boat console.'),
  265. ('survey', 'A "survey" unit is packaged for field-survey use.'),
  266. ('OEM module','An "OEM module" is an un-cased circuit board with edge '
  267. 'connectors.'),
  268. ('chipset', 'A "chipset" is a bare chip or chips packaged for surface '
  269. 'mount.'),
  270. ('other', 'None of the above'),
  271. )
  272. for (ptype, plegend) in packagetypes:
  273. print '<input type="radio" name="packaging" value="%s">%s<br/>' % (ptype, plegend)
  274. print '''
  275. <p>Please identify the device chipset and firmware version, if possible. You
  276. may be able to get this from the display of <code>xgps</code>; look for
  277. a Device Type field or at the window title bar. Alternatively, you may find
  278. it in the technical manual.</p>
  279. <p>Example: <code>SiRF-II</code> and <code>2.31ES</code>.</p>
  280. <p><em>Chipset:&nbsp;&nbsp;</em>
  281. <input type="text"
  282. name="chipset"
  283. size="72"
  284. value="%(chipset)s"></p>
  285. <p><em>Firmware:&nbsp;</em>
  286. <input type="text"
  287. name="firmware"
  288. size="72"
  289. value="%(firmware)s"></p>
  290. <p>Please identify, if possible, the NMEA version the receiver emits. You may
  291. be able to get this information from the technical manual. Likely values are
  292. <code>2.0</code>, <code>2.2</code>, <code>2.3</code>, <code>3.0</code>, and
  293. <code>2000</code> for NMEA2000 devices. If the GPS emits only a vendor binary
  294. protocol, leave this field blank.</p>
  295. <p><em>NMEA version emitted:&nbsp;</em>
  296. <input type="text"
  297. name="nmea"
  298. size="6"
  299. value="%(nmea)s"></p>
  300. <hr/>
  301. <h2>Interfaces</h2>
  302. <p>Please identify the receiver\'s interface type (USB, RS-232, Bluetooth,
  303. Compact Flash, CAN bus, etc.). If the receiver has adapters that support other
  304. interfaces, tell us the one you have and mention the adapters in the "Technical
  305. Notes" box. If it has an exotic interface not listed here, select "Other" and
  306. tell us about it in "Technical Notes".</p>
  307. ''' % defaults
  308. ifline = '<td><input type="radio" name="interfaces" value="%s">%s</td>'
  309. print "<table style='border:1'><tr>"
  310. for itype in ('USB', 'Bluetooth', 'Compact Flash', 'RS-232', 'TTL', 'CAN', 'Other'):
  311. print ifline % (itype, itype)
  312. print "</tr></table>"
  313. print '''
  314. <p>If your device is USB, it probably uses a USB-to-serial adapter
  315. chip. Try to find out what this is by looking at the output of
  316. <code>lsusb(1)</code>.</p>
  317. '''
  318. cline = '<td><input type="radio" name="interfaces" value="%s">%s</td>'
  319. print "<table style='border:1'><tr>"
  320. for ctype in ('PL2303', 'UC-232A', 'FTDI', 'Cypress M8', 'CP210x', 'Other'):
  321. print cline % (ctype, ctype)
  322. print "</tr></table>"
  323. print '''
  324. <hr>
  325. <h2>GPSD compatibility</h2>
  326. <p>Please tell us what version you tested with. If you used a published
  327. release, give us the full release number, like <code>3.5</code>. If you built
  328. your code from our development repository, please give the revision ID.</p>
  329. <p><em>GPSD version:&nbsp;</em>
  330. <input type="text"
  331. name="tested"
  332. size="6"
  333. value="%(tested)s"></p>
  334. <p>Please rate how well this receiver functions with GPSD:</p>
  335. ''' % defaults
  336. ratings = (
  337. ("excellent",
  338. "Excellent -- gpsd recognizes the receiver rapidly and reliably, reports are complete and correct."),
  339. ("good",
  340. "Good -- gpsd has minor problems or lag recognizing the device, but reports are complete and correct."),
  341. ("fair",
  342. "Fair -- Reports have minor dropouts or problems, including occasional transient nonsense values."),
  343. ("poor",
  344. "Poor -- Reports frequently have values that are wrong or nonsense."),
  345. ("broken",
  346. "Broken -- gpsd frequently, or always, fails to recognize the device at all."),
  347. ("other",
  348. "Other -- See Technical Notes."),
  349. )
  350. rateline = '<input type="radio" name="rating" value="%s"%s>%s<br/>'
  351. for (rtype, rlegend) in ratings:
  352. if defaults['packaging'] == rtype:
  353. print rateline % (rtype, " checked", rlegend)
  354. else:
  355. print rateline % (rtype, "", rlegend)
  356. print '<p>Device sanity when probed or speed-switched:<br/>'
  357. sanity = (('sane', 'Sane: accepts baud-rate changes and probes.'),
  358. ('insane', 'Insane: goes catatonic on baud-rate changes and probes.'))
  359. saneline = '<input type="radio" name="sanity" value="%s"%s>%s<br/>'
  360. for (stype, slegend) in sanity:
  361. if defaults['configurable'] == stype:
  362. print saneline % (stype, " checked", slegend)
  363. else:
  364. print saneline % (stype, "", slegend)
  365. print '''
  366. <hr>
  367. <h2>Technical notes</h2>
  368. <p>Now tell us the things that didn\'t fit in the rest of the form.
  369. Appropriate things to put here include how to read any LEDs or other
  370. unlabeled indicators on the device, a warning that the product has
  371. been discontinued, a list of alternate interfaces, descriptions of
  372. errors in the documentation, descriptions of
  373. special abilities such as the ability to vary the sampling interval,
  374. and a note if it\'s an OEM module rather than a retail product.
  375. Anything else you think we need to know should go here too.</p>
  376. <textarea name="notes" rows="10", cols="72"></textarea>
  377. <hr>
  378. <h2>Output sample</h2>
  379. <p><em style=\'color: #ff0000;\'>Important!</em> We need a sample of the output
  380. from your receiver - not the gpsd logfile, just raw output. We\'ll use this for
  381. mechanical regression testing, which is your best guarantee that support for
  382. your device won\'t get broken in a future release. Please be advised that these
  383. logs will be sent to a publicly archived mailing list, and will be available in
  384. the public code repository.</p>
  385. <p>Almost all receivers will simply start throwing data to your port
  386. immediately when they\'re plugged in. You should normally be able to capture
  387. this output to a file with the <code>gpscat</code> utility.</p>
  388. <p>There will be some unusual cases in which this isn\'t possible,
  389. because the device needs some kind of activation sequence written to
  390. it before it will start reporting. Some Garmin GPSes (the ones that
  391. speak Garmin binary protocol rather than NMEA) are like this. If you
  392. think you have one of these, ask for help on GPSD\'s development mailing
  393. list</a>.</p>
  394. <p>A log file is most useful when it contains (a) some sentences
  395. generated when the receiver has no fix, (b) some sentences representing
  396. a fix with the unit stationary, and (c) some sentences representing
  397. a fix with the unit moving.</p>
  398. <input type="file" name="output_sample_file">
  399. <input type="hidden" name="output_sample_content" value="%(armored_sample_content)s">
  400. <p>There is some auxiliary data we like to have in our regression-test
  401. files.</p>
  402. <p>Location of the log capture. A good format would include your
  403. nearest city or other landmark, state/province, country code, and a
  404. rough latitude/longitude. A GPS will give an exact location; we
  405. want this as a sanity check.</p>
  406. <p>Example: <code>Groningen, NL, 53.2N 6.6E</code></p>
  407. <p><em>Location:&nbsp;</em>
  408. <input type="text"
  409. name="location"
  410. size="72"
  411. value="%(location)s"></p>
  412. <p>Year-Month-Day of the log capture (the receiver will give us
  413. hour/minute/second).</p>
  414. <p>Example: <code>2011-05-14</code>.</p>
  415. <p><em>Date:&nbsp;</em>
  416. <input type="text"
  417. name="date"
  418. size="72"
  419. value="%(date)s"></p>
  420. <p>Finally, add any notes you want to about how the sample was taken. One
  421. good thing to put here would a description of how the unit was moving while the
  422. log was being captured. If the sentence mix changes between "fix" and "no fix"
  423. states, that too is a good thing to note.</p>
  424. <textarea name="sample_notes" rows="10", cols="72"></textarea>
  425. <hr>
  426. <h2>Contact information</h2>
  427. <p><em style="color: #ff0000;">Important!</em> We need a valid email
  428. address for you in case we need to ask you followup questions about
  429. the device. While we won\'t use your address for anything other than
  430. asking you questions about your receiver, and maybe asking you to test
  431. specific changes, this device report will be sent to the gpsd-dev list
  432. which is publicly archived.</p>
  433. <p>Example: <code>Eric Raymond &lt;esr&#x40;thyrsus.com&gt;</code></p>
  434. <p><em>Name and email address: </em>
  435. <input type="text"
  436. name="submitter"
  437. size="72"
  438. value="%(submitter)s"></p>
  439. <p>(It is not actually very likely we will contact you, but we need to
  440. be able to do it if we can find no other way of getting information
  441. about the device. Expect to hear from us if your receiver is obsolescent or
  442. exotic and the information you provide in the rest of this form turns
  443. out to be insufficient. Or if your browser is broken enough to botch
  444. the output-sample upload.)</p>
  445. <hr>
  446. ''' % defaults
  447. print "<p>To see what you have entered so far, click <code>Review</code>\n";
  448. # Must have all critical fields to ship
  449. if hasRequiredElements(form):
  450. print '''
  451. <p>Click the <code>Send Report</code> button to send your report to the GPSD
  452. developers. Eventually, your report is likely to appear on our <a
  453. href="%(website)s/hardware.html">Hardware</a> page.</p>
  454. <table style="width:100%%;border:0">
  455. <tr>
  456. <td style="text-align:center">
  457. <a href="%(request_uri)s">Reset Form</a>
  458. <input type="submit" name="action" value="Review">
  459. <input type="submit" name="action" value="Send Report">
  460. </td>
  461. </tr>
  462. </table>
  463. ''' % defaults
  464. else:
  465. print '''
  466. <p style="color:#ff0000;">Required fields are missing; please fill them in.</p>
  467. <table style="width:100%%;border:0">
  468. <tr>
  469. <td style="text-align:center">
  470. <a href="%(request_uri)s">Reset Form</a>
  471. <input type="submit" name="action" value="Review">
  472. </td>
  473. </tr>
  474. </table>
  475. ''' % defaults
  476. print '''
  477. </form>
  478. </div>
  479. '''
  480. # The following sets edit modes for GNU EMACS
  481. # Local Variables:
  482. # mode: python
  483. # fill-column:79
  484. # End: