You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by cu...@apache.org on 2020/02/04 15:30:30 UTC
[whimsy] branch master updated: Guard against malformed JSON parse
This is an automated email from the ASF dual-hosted git repository.
curcuru pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git
The following commit(s) were added to refs/heads/master by this push:
new e8535ee Guard against malformed JSON parse
e8535ee is described below
commit e8535eeef8bed5c88da1d730ff430812cf6ff365
Author: Shane Curcuru <as...@shanecurcuru.org>
AuthorDate: Tue Feb 4 10:30:18 2020 -0500
Guard against malformed JSON parse
---
.ruby-version | 1 -
tools/mboxhdr2csv.rb | 103 ++++++++++++++++++++++++++-------------------------
tools/shane.rb | 22 +++++++++++
www/401.cgi | 49 ++++++++++++++++++++++++
4 files changed, 124 insertions(+), 51 deletions(-)
diff --git a/.ruby-version b/.ruby-version
deleted file mode 100644
index 005119b..0000000
--- a/.ruby-version
+++ /dev/null
@@ -1 +0,0 @@
-2.4.1
diff --git a/tools/mboxhdr2csv.rb b/tools/mboxhdr2csv.rb
index 1ebd520..83dd6c0 100644
--- a/tools/mboxhdr2csv.rb
+++ b/tools/mboxhdr2csv.rb
@@ -156,64 +156,67 @@ module MailUtils
# Return cached calculated data if present
cache_json = File.join(mailroot, "#{yearmonth}.json")
if File.file?(cache_json)
- return JSON.parse(File.read(cache_json))
- else
- emails = {}
- files = Dir[File.join(mailroot, yearmonth, '*')]
- return emails if files.empty?
- emails[MAILS] = []
- emails[TOOLS] = []
- files.each do |email|
- next if email.end_with? '/index'
- message = IO.read(email.untaint, mode: 'rb')
- data = {}
- data[DATE] = DateTime.parse(message[/^Date: (.*)/, 1]).iso8601
- data[FROM] = message[/^From: (.*)/, 1]
- # Originally (before 2265343) the local method #find_who_from expected an email address and returned who, committer
- # Emulate this with the version from MailUtils which expects and updates a hash
- temp = {from: data[FROM]} # pass a hash
- MailUtils.find_who_from(temp) # update the hash
- # pick out the bits we want
- data[WHO], data[COMMITTER] = temp[:who], temp[:committer]
+ begin
+ return JSON.parse(File.read(cache_json))
+ rescue StandardError => e
+ # No-op: If we can't read the cache, fall through and attempt to recreate
+ end
+ end
+ emails = {}
+ files = Dir[File.join(mailroot, yearmonth, '*')]
+ return emails if files.empty?
+ emails[MAILS] = []
+ emails[TOOLS] = []
+ files.each do |email|
+ next if email.end_with? '/index'
+ message = IO.read(email.untaint, mode: 'rb')
+ data = {}
+ data[DATE] = DateTime.parse(message[/^Date: (.*)/, 1]).iso8601
+ data[FROM] = message[/^From: (.*)/, 1]
+ # Originally (before 2265343) the local method #find_who_from expected an email address and returned who, committer
+ # Emulate this with the version from MailUtils which expects and updates a hash
+ temp = {from: data[FROM]} # pass a hash
+ MailUtils.find_who_from(temp) # update the hash
+ # pick out the bits we want
+ data[WHO], data[COMMITTER] = temp[:who], temp[:committer]
- data[SUBJECT] = message[/^Subject: (.*)/, 1]
- if nondiscuss
- nondiscuss.each do |typ, rx|
- if data[SUBJECT] =~ rx
- data[TOOLS] = typ
- break # regex.each
- end
+ data[SUBJECT] = message[/^Subject: (.*)/, 1]
+ if nondiscuss
+ nondiscuss.each do |typ, rx|
+ if data[SUBJECT] =~ rx
+ data[TOOLS] = typ
+ break # regex.each
end
end
- data.has_key?(TOOLS) ? emails[TOOLS] << data : emails[MAILS] << data
- end
- # Provide as sorted data for ease of use
- emails[TOOLS].sort_by! { |email| email[DATE] }
- emails[TOOLCOUNT] = Hash.new {|h, k| h[k] = 0 }
- emails[TOOLS].each do |mail|
- emails[TOOLCOUNT][mail[TOOLS]] += 1
end
- emails[TOOLCOUNT] = emails[TOOLCOUNT].sort_by { |k,v| -v}.to_h
-
- emails[MAILS].sort_by! { |email| email[DATE] }
- emails[MAILCOUNT] = Hash.new {|h, k| h[k] = 0 }
- emails[MAILS].each do |mail|
- emails[MAILCOUNT][mail[WHO]] += 1
- end
- emails[MAILCOUNT] = emails[MAILCOUNT].sort_by { |k,v| -v}.to_h
+ data.has_key?(TOOLS) ? emails[TOOLS] << data : emails[MAILS] << data
+ end
+ # Provide as sorted data for ease of use
+ emails[TOOLS].sort_by! { |email| email[DATE] }
+ emails[TOOLCOUNT] = Hash.new {|h, k| h[k] = 0 }
+ emails[TOOLS].each do |mail|
+ emails[TOOLCOUNT][mail[TOOLS]] += 1
+ end
+ emails[TOOLCOUNT] = emails[TOOLCOUNT].sort_by { |k,v| -v}.to_h
+
+ emails[MAILS].sort_by! { |email| email[DATE] }
+ emails[MAILCOUNT] = Hash.new {|h, k| h[k] = 0 }
+ emails[MAILS].each do |mail|
+ emails[MAILCOUNT][mail[WHO]] += 1
+ end
+ emails[MAILCOUNT] = emails[MAILCOUNT].sort_by { |k,v| -v}.to_h
- # If yearmonth is before current month, then write out yearmonth.json as cache
- if yearmonth < Date.today.strftime('%Y%m')
- begin
- File.open(cache_json, 'w') do |f|
- f.puts JSON.pretty_generate(emails)
- end
- rescue
- # No-op, just don't cache for now
+ # If yearmonth is before current month, then write out yearmonth.json as cache
+ if yearmonth < Date.today.strftime('%Y%m')
+ begin
+ File.open(cache_json, 'w') do |f|
+ f.puts JSON.pretty_generate(emails)
end
+ rescue
+ # No-op, just don't cache for now
end
- return emails
end
+ return emails
end
end
diff --git a/tools/shane.rb b/tools/shane.rb
new file mode 100644
index 0000000..4430b1b
--- /dev/null
+++ b/tools/shane.rb
@@ -0,0 +1,22 @@
+#!/usr/bin/env ruby
+# Utility functions Shane wrote (temporary)
+$LOAD_PATH.unshift '/srv/whimsy/lib'
+require 'whimsy/asf'
+SCANDIR = "../www"
+
+AUTHPATH = '/Users/curcuru/src/g/infrastructure-puppet/modules/subversion_server/files/authorization'
+# Use various functions
+def test()
+# auth = ASF::Authorization.initialize(file='asf', auth_path=AUTHPATH)
+ # ASF::Authorization.each do |k,v|
+ # puts "#{k} = #{v.join(',')}"
+ # end
+end
+
+p = ASF::Person['curcuru']
+puts p.inspect
+puts p.auth
+puts "----"
+puts p.public_name
+puts "----"
+puts p.member_emails
\ No newline at end of file
diff --git a/www/401.cgi b/www/401.cgi
new file mode 100755
index 0000000..2021e28
--- /dev/null
+++ b/www/401.cgi
@@ -0,0 +1,49 @@
+#!/usr/bin/env ruby
+PAGETITLE = "401 - Unauthorized Error - Apache Whimsy"
+$LOAD_PATH.unshift '/srv/whimsy/lib'
+require 'wunderbar'
+require 'wunderbar/bootstrap'
+require 'whimsy/asf'
+
+_html do
+ _body? do
+ _whimsy_body(
+ title: PAGETITLE,
+ subtitle: "URL #{ENV['REDIRECT_URL']} Unauthorized",
+ style: 'panel-danger',
+ related: {
+ "/" => "Whimsy Server Homepage",
+ "/committers/tools" => "Whimsy All Tools Listing",
+ "https://github.com/apache/whimsy/blob/master/www#{ENV['SCRIPT_NAME']}" => "See This Source Code",
+ "mailto:dev@whimsical.apache.org?subject=[SITE] 401 Error Page #{ENV['REDIRECT_URL']}" => "Questions? Email Whimsy PMC"
+ },
+ helpblock: -> {
+ _p do
+ _span.label.label_danger '401'
+ _ " Tsk, tsk, that's secret magician stuff. Sorry, but a good magician never reveals their tricks - you're not allowed to peek. "
+ _ "You must be a member of #{ENV['Www-Authenticate']} to view this page. "
+ _ "Use the same login credentials as you do for your Apache account at: "
+ _a 'https://id.apache.org/', href: 'https://id.apache.org/'
+ end
+ }
+ ) do
+ # No-op
+ params = _.params
+ params.each do |k,v|
+ _p "Param: #{k} #{v}"
+ end
+ _p "foo #{_.referer} "
+ _p "bar #{_.content_type} "
+ ENV.sort.each do |k,v|
+ if k.eql? 'HTTP_AUTHORIZATION'
+ # cannot use sub! because value is fozen
+ # redact non-empty string
+ if v and not v.empty?
+ v = '<redacted>'
+ end
+ end
+ _p "ENV: #{k} #{v}"
+ end
+ end
+ end
+end