···11-Description: Externalize session config to yml in /etc
22-Forwarded: not-needed
33-Author: Jérémy Lal <kapouer@melix.org>
44-Last-Update: 2010-01-10
55---- redmine.orig/lib/tasks/initializers.rake
66-+++ redmine/lib/tasks/initializers.rake
77-@@ -1,11 +1,12 @@
88- desc 'Generates a secret token for the application.'
99-+task :generate_secret_token do
1010-1111--file 'config/initializers/secret_token.rb' do
1212-- path = File.join(Rails.root, 'config', 'initializers', 'secret_token.rb')
1313-- secret = SecureRandom.hex(40)
1414-- File.open(path, 'w') do |f|
1515-- f.write <<"EOF"
1616--# This file was generated by 'rake generate_secret_token', and should
1717-+filename = ENV['YML_SESSION_FILENAME'] ? ENV['YML_SESSION_FILENAME'] : 'session.yml'
1818-+path = File.join(ENV['RAILS_ETC'] ? ENV['RAILS_ETC'] : File.join(Rails.root, 'config'), filename)
1919-+secret = SecureRandom.hex(40)
2020-+File.open(path, 'w') do |f|
2121-+ f.write <<"EOF"
2222-+# This file was generated by 'rake generate_session_store',
2323- # not be made visible to public.
2424- # If you have a load-balancing Redmine cluster, you will need to use the
2525- # same version of this file on each machine. And be sure to restart your
2626-@@ -15,10 +18,18 @@ file 'config/initializers/secret_token.r
2727- # change this key, all old sessions will become invalid! Make sure the
2828- # secret is at least 30 characters and all random, no regular words or
2929- # you'll be exposed to dictionary attacks.
3030--RedmineApp::Application.config.secret_token = '#{secret}'
3131-+
3232-+production:
3333-+ key: _redmine_
3434-+ secret: #{secret}
3535-+
3636-+development:
3737-+ key: _redmine_
3838-+ secret: #{secret}
3939-+
4040-+test:
4141-+ key: _redmine_
4242-+ secret: #{secret}
4343- EOF
4444- end
4545- end
4646--
4747--desc 'Generates a secret token for the application.'
4848--task :generate_secret_token => ['config/initializers/secret_token.rb']
4949---- redmine.orig/config/application.rb
5050-+++ redmine/config/application.rb
5151-@@ -66,7 +66,20 @@ module RedmineApp
5252- # move tmp directory to RAILS_TMP
5353- config.paths['tmp'] = ENV['RAILS_TMP']
5454-5555-- config.session_store :cookie_store, :key => '_redmine_session'
5656-+ # loads cookie based session session and secret keys
5757-+ # this is needed here because initializers are loaded after plugins,
5858-+ # and some plugins initialize ActionController which requires a secret to be set.
5959-+ # crash if file not found
6060-+ relativeUrlRoot = ENV['RAILS_RELATIVE_URL_ROOT']
6161-+ filename = ENV['RAILS_ETC'] ? File.join(ENV['RAILS_ETC'], 'session.yml') : File.join(File.dirname(__FILE__), '..', 'session.yml')
6262-+ if File.exists?(filename)
6363-+ sessionconfig = YAML::load_file(filename)
6464-+ config.session_store :cookie_store, :key => sessionconfig[Rails.env]['key'], :path => (relativeUrlRoot.blank?) ? '/' : relativeUrlRoot
6565-+ config.secret_token = sessionconfig[Rails.env]['secret']
6666-+ else
6767-+ # temporary settings before session.yml is created
6868-+ config.session_store :cookie_store, :key => '_redmine_session', :path => (relativeUrlRoot.blank?) ? '/' : relativeUrlRoot
6969-+ end
7070-7171- # log path
7272- config.paths['log'] = File.join(ENV['RAILS_LOG'], "#{Rails.env}.log") unless !ENV['RAILS_LOG']