summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Legler <alex@a3li.li>2015-02-20 00:18:07 +0100
committerAlex Legler <alex@a3li.li>2015-02-20 00:18:07 +0100
commit33bd4bef9af015236ca3a928f1c9b059e56ab96a (patch)
treee71d0850d1f9f6e4f3b6ac4ef0b40acdbb7dc7a5 /ag-web.rb
downloadfrontend-33bd4bef9af015236ca3a928f1c9b059e56ab96a.tar.gz
frontend-33bd4bef9af015236ca3a928f1c9b059e56ab96a.tar.bz2
frontend-33bd4bef9af015236ca3a928f1c9b059e56ab96a.zip
Initial version
Diffstat (limited to 'ag-web.rb')
-rw-r--r--ag-web.rb160
1 files changed, 160 insertions, 0 deletions
diff --git a/ag-web.rb b/ag-web.rb
new file mode 100644
index 0000000..850d1db
--- /dev/null
+++ b/ag-web.rb
@@ -0,0 +1,160 @@
+# /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')
+
+$valid_lists = %w[www-redesign gentoo-alt gentoo-dev gentoo-amd64]
+
+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 503
+ 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 = 'No, Larry does not make that sound (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 503
+ 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 503
+ 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
+
+ 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 503
+ 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 503
+ 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 503
+ end
+end
+
+get '/' do
+ erb :index
+end \ No newline at end of file