Skip to content

Commit

Permalink
Code Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sleroux-keep committed Jan 30, 2013
1 parent 2aa5046 commit be24883
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions lib/wiki_controller_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def show_with_decryption
if params[:format] == 'pdf'
params[:decode]='1'
@content.text = decodeContent(@content.text,params,0,1);
@page.content = @content
send_data(wiki_page_to_pdf(@page, @project), :type => 'application/pdf', :filename => "#{@page.title}.pdf")
return
elsif params[:format] == 'html'
Expand Down
29 changes: 16 additions & 13 deletions lib/wiki_page_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,26 @@ def self.included(base) # :nodoc:
end

module InstanceMethods

$key = Digest::SHA256.hexdigest(Redmine::Configuration['database_cipher_key'].to_s.strip)

def decrypt(encodedContent)

e = OpenSSL::Cipher::Cipher.new 'DES-EDE3-CBC'
e.decrypt $key
s = encodedContent.to_a.pack("H*").unpack("C*").pack("c*")
s = e.update s
decoded = s << e.final
return decoded
end



def decodeContentWithTags(originalText)
if Redmine::Configuration['database_cipher_key'].to_s.strip != ''
key = Digest::SHA256.hexdigest(Redmine::Configuration['database_cipher_key'].to_s.strip)
matches = originalText.scan(/\{\{coded\_start\}\}.*?\{\{coded\_stop\}\}/m)
matches.each do |m|
tagContent = m.gsub('{{coded_start}}','').gsub('{{coded_stop}}','').strip
e = OpenSSL::Cipher::Cipher.new 'DES-EDE3-CBC'
e.decrypt key
s = tagContent.to_a.pack("H*").unpack("C*").pack("c*")
s = e.update s
decoded = s << e.final
decoded = decrypt(tagContent)
decoded = '{{cipher}}'+decoded+'{{cipher}}'
originalText = originalText.gsub(m.strip, decoded.strip)
end
Expand All @@ -30,15 +38,10 @@ def decodeContentWithTags(originalText)
end

def decodeContent(originalText)
key = Digest::SHA256.hexdigest(Redmine::Configuration['database_cipher_key'].to_s.strip)
matches = originalText.scan(/\{\{history\_coded\_start\}\}.*?\{\{history\_coded\_stop\}\}/m)
matches.each do |m|
tagContent = m.gsub('{{history_coded_start}}','').gsub('{{history_coded_stop}}','').strip
e = OpenSSL::Cipher::Cipher.new 'DES-EDE3-CBC'
e.decrypt key
s = tagContent.to_a.pack("H*").unpack("C*").pack("c*")
s = e.update s
decoded = s << e.final
decoded = decrypt(tagContent)
decoded = ''+decoded+''
originalText = originalText.gsub(m.strip, decoded.strip)
end
Expand Down

0 comments on commit be24883

Please sign in to comment.