2 # -*- coding: utf-8 -*-
10 from email
.MIMEText
import MIMEText
13 from traceback
import format_exception
14 from sys
import exc_info
17 logging
.basicConfig(level
=logging
.DEBUG
,
18 format
="%(asctime)s %(levelname)-8s %(message)s",
19 datefmt
="%a, %d %b %Y %H:%M:%S",
23 # create table crash(ip TEXT, crashlog TEXT);
27 def mailreport(crashlog
, ip
, revision
):
28 mail
= MIMEText(crashlog
)
29 mail
["To"] = "bugs@cyberduck.ch"
30 mail
["From"] = "noreply@cyberduck.ch"
32 mail
["Subject"] = "Cyberduck Crash Report (r" + revision
+ ") from " + ip
34 mail
["Subject"] = "Cyberduck Crash Report from " + ip
35 mail
["Date"] = email
.Utils
.formatdate(localtime
=1)
36 mail
["Message-ID"] = email
.Utils
.make_msgid()
38 s
.connect("localhost")
39 s
.sendmail("noreply@cyberduck.ch", "bugs@cyberduck.ch", mail
.as_string())
43 if __name__
== "__main__":
44 print "Content-type: text/html"
47 form
= cgi
.FieldStorage()
49 if form
.has_key("revision"):
50 revision
= form
["revision"].value
52 if form
.has_key("os"):
53 platform
= form
["os"].value
55 useragent
= cgi
.escape(os
.environ
["HTTP_USER_AGENT"])
56 revision
= re
.match(r
"Cyberduck \(([0-9]+)\)", useragent
).group(1)
57 ip
= cgi
.escape(os
.environ
["REMOTE_ADDR"])
58 if form
.has_key("crashlog"):
59 logging
.info("Crash Report from %s for OS %s and revision %s", ip
, platform
, revision
)
60 crashlog
= form
["crashlog"].value
63 conn
= sqlite3
.connect(db
)
66 row
= (ip
, crashlog
, revision
, platform
)
68 c
.execute('insert into crash values(?,?,?,?)', row
)
69 except sqlite3
.IntegrityError
, (ErrorMessage
):
70 logging
.error('Error adding crashlog from IP %s:%s', ip
, ErrorMessage
)
73 # Save (commit) the changes
75 # We can also close the cursor if we are done with it
80 mailreport(crashlog
, ip
, revision
)
82 logging
.error("Unexpected error:".join(format_exception(*exc_info())))