-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherror.cgi
executable file
·82 lines (65 loc) · 3.29 KB
/
error.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env ruby
############################################################################
# Copyright 2009,2010 Benjamin Kellermann #
# #
# This file is part of dudle. #
# #
# Dudle is free software: you can redistribute it and/or modify it under #
# the terms of the GNU Affero General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# Dudle is distributed in the hope that it will be useful, but WITHOUT ANY #
# WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public #
# License for more details. #
# #
# You should have received a copy of the GNU Affero General Public License #
# along with dudle. If not, see <http://www.gnu.org/licenses/>. #
############################################################################
require "dudle"
# check for trailing slash
if ENV["REDIRECT_URL"] =~ /#{$cgi["poll"]}$/
$d = Dudle.new(:title => _("Error"), :hide_lang_chooser => true, :relative_dir => "#{$cgi["poll"]}/")
else
$d = Dudle.new(:title => _("Error"), :hide_lang_chooser => true)
end
def urlescape(str)
CGI.escapeHTML(CGI.escape(str).gsub("+","%20"))
end
if File.exists?($conf.errorlog)
begin
a = File.open($conf.errorlog,"r").to_a
rescue Exception => e
errorstr = "Exception while opening #{$conf.errorlog}:\n#{e}"
else
s = [a.pop]
s << a.pop while s.last.scan(/^\[([^\]]*)\] \[/).flatten[0] == a.last.scan(/^\[([^\]]*)\] \[/).flatten[0] || a.last =~ /^[^\[]/
errorstr = s.reverse.join
end
errormessage = "\n" + _("The following error was printed:") + "\n" + errorstr
end
errormessagebody = _("Hi!\n\nI found a bug in your application at %{urlofsite}.\nI did the following:\n\n<please describe what you did>\n<e.g., I wanted to sent a comment to the poll.>\n\nI am using <please state your browser and operating system>\n%{errormessage}\nYours,\n") % {:errormessage => errormessage, :urlofsite => $conf.siteurl}
subject = _("Bug in dudle")
$d << _("An error occured while executing dudle.<br/>Please send an error report, including your browser, operating system, and what you did to %{admin}.") % {:admin => "<a href='mailto:#{$conf.bugreportmail}?subject=#{urlescape(subject)}&body=#{urlescape(errormessagebody)}'>#{$conf.bugreportmail}</a>"}
if (errorstr)
errorheadstr = _("Please include the following as well:")
$d << <<ERROR
<br/>
#{errorheadstr}
<pre style='background:#DDD;padding : 1em'>#{CGI.escapeHTML(errorstr)}</pre>
ERROR
end
$d.out
known = false
$conf.known_errors.each{|err|
known = true if errorstr.index(err)
}
if $conf.auto_send_report && !known
tmpfile = "/tmp/error.#{rand(10000)}"
File.open(tmpfile,"w"){|f|
f << errorstr
}
%x{mail -s "Bug in dudle" #{$conf.bugreportmail} < #{tmpfile}}
File.delete(tmpfile)
end