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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
# /usr/bin/env ruby
# AgWeb -- displaying all the 'golden' flamewars on -dev
# Alex Legler <a3li@gentoo.org>
# AGPLv3
require 'bundler/setup'
require 'yaml'
require 'sinatra'
require 'sinatra/partial'
require 'elasticsearch'
require 'date'
require 'pony'
require_relative 'lib/index.rb'
require_relative 'lib/helpers.rb'
configure do
set :partial_template_engine, :erb
mime_type :atom, 'application/atom+xml'
end
$es = Elasticsearch::Client.new(log: false)
$es.transport.reload_connections!
$config = YAML.load_file('config.yml')
get '/:list/report/:msgid' do
return unless list_check
begin
result = get_message(params[:list], params[:msgid])
if result['hits']['total'] == 0
status 404
body "Message not found."
return
end
result_data = result['hits']['hits'].first
@title = "Report %s - %s" % [h(result_data['_source']['subject']), params[:list]]
erb :report, locals: { message: result_data, list: params[:list] }
rescue Exception => e
$stderr.puts e.to_s
status 500
end
end
post '/report' do
return unless list_check
begin
result = get_message(params[:list], params[:msgid])
if result['hits']['total'] == 0
status 404
body "Message not found."
return
end
result_data = result['hits']['hits'].first
@title = "Report %s - %s" % [h(result_data['_source']['subject']), params[:list]]
msg = ''
if params[:captcha] == $config['report_captcha']
Pony.mail(
to: $config['report_addr'],
from: 'archives.gentoo.org <postmaster@gentoo.org>',
subject: "Reported Message on #{params[:list]}: #{result_data['_source']['subject']}",
body: erb(:reportmail, locals: { message: result_data, list: params[:list] }, layout: false)
)
msg = 'Thanks for your report.'
else
msg = 'Invalid CAPTCHA. Report not sent.'
end
erb :reportsent, locals: { message: result_data, list: params[:list], msg: msg }
rescue Exception => e
$stderr.puts e.to_s
status 500
end
end
get '/:list/' do
return unless list_check
begin
result = get_month_listing(params[:list])
@title = params[:list]
current_monthint = to_monthint(Date.today.year, Date.today.month)
puts current_monthint
erb :listindex, locals: { results: result, list: params[:list], current_monthint: current_monthint }
rescue => e
$stderr.puts e.to_s
status 500
end
end
get '/:list/threads/:year-:month/:page?' do
return unless list_check
begin
@title = params[:list]
current_page = [(params[:page] || 1).to_i, 1].max
result = threads_in_month(params[:list], params[:year], params[:month], current_page)
max_pages = (result['hits']['total'].to_f / PER_PAGE).ceil
if result['hits']['total'] == 0
redirect "/%s/messages/%s-%s/?no_threads=1" % [params[:list], params[:year], params[:month]]
return
end
erb :listmonth, locals: { results: result, list: params[:list], current_page: current_page, max_pages: max_pages, mode: :threads }
rescue => e
$stderr.puts e.to_s
status 500
end
end
get '/:list/messages/:year-:month/:page?' do
return unless list_check
begin
@title = params[:list]
current_page = [(params[:page] || 1).to_i, 1].max
result = messages_in_month(params[:list], params[:year], params[:month], current_page)
max_pages = (result['hits']['total'].to_f / PER_PAGE).ceil
erb :listmonth, locals: { results: result, list: params[:list], current_page: current_page, max_pages: max_pages, mode: :messages }
rescue => e
$stderr.puts e.to_s
status 500
end
end
get '/:list/message/:msgid' do
return unless list_check
begin
result = get_message(params[:list], params[:msgid])
if result['hits']['total'] == 0
status 404
body "Message not found."
return
end
result_data = result['hits']['hits'].first
@title = "%s - %s" % [h(result_data['_source']['subject']), params[:list]]
parent_data = get_parent_data(params[:list], result_data['_source']['parent'])
child_data = get_child_data(params[:list], params[:msgid])
erb :message, locals: { message: result_data, list: params[:list], parent: parent_data, children: child_data }
rescue Exception => e
$stderr.puts e.to_s
status 500
end
end
get '/' do
erb :index
end
|