aboutsummaryrefslogtreecommitdiff
path: root/error.cgi
blob: 1e6f71ddac854b376869e46c5f5d284f0f2a2113 (plain)
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
#!/usr/bin/env ruby

############################################################################
# Copyright 2009-2019 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_relative "dudle"

if File.exists?("#{Dir.pwd}/#{File.dirname(ENV["REDIRECT_URL"])}/data.yaml")
	$d = Dudle.new(:title => _("Error"), :hide_lang_chooser => true, :load_extensions => false, :relative_dir => "../")
else
	$d = Dudle.new(:title => _("Error"), :hide_lang_chooser => true, :load_extensions => false)
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 post a comment to the poll.>\n\nI am using <please state your browser and operating system>\n%{errormessage}\nSincerely,\n") % {:errormessage => errormessage, :urlofsite => $conf.siteurl}
	subject = _("Bug in Dudle")

	$d << _("An error occurred 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=#{CGI.escape(subject)}&amp;body=#{CGI.escape(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
if (errorstr)
	$conf.known_errors.each{|err|
		known = true if errorstr.index(err)
	}
end

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