···1+Description: Externalize session config to yml in /etc
2+Forwarded: not-needed
3+Author: Jérémy Lal <kapouer@melix.org>
4+Last-Update: 2010-01-10
5+--- redmine.orig/lib/tasks/initializers.rake
6++++ redmine/lib/tasks/initializers.rake
7+@@ -1,11 +1,12 @@
8+ desc 'Generates a secret token for the application.'
9++task :generate_secret_token do
10+11+-file 'config/initializers/secret_token.rb' do
12+- path = File.join(Rails.root, 'config', 'initializers', 'secret_token.rb')
13+- secret = SecureRandom.hex(40)
14+- File.open(path, 'w') do |f|
15+- f.write <<"EOF"
16+-# This file was generated by 'rake generate_secret_token', and should
17++filename = ENV['YML_SESSION_FILENAME'] ? ENV['YML_SESSION_FILENAME'] : 'session.yml'
18++path = File.join(ENV['RAILS_ETC'] ? ENV['RAILS_ETC'] : File.join(Rails.root, 'config'), filename)
19++secret = SecureRandom.hex(40)
20++File.open(path, 'w') do |f|
21++ f.write <<"EOF"
22++# This file was generated by 'rake generate_session_store',
23+ # not be made visible to public.
24+ # If you have a load-balancing Redmine cluster, you will need to use the
25+ # same version of this file on each machine. And be sure to restart your
26+@@ -15,10 +18,18 @@ file 'config/initializers/secret_token.r
27+ # change this key, all old sessions will become invalid! Make sure the
28+ # secret is at least 30 characters and all random, no regular words or
29+ # you'll be exposed to dictionary attacks.
30+-RedmineApp::Application.config.secret_token = '#{secret}'
31++
32++production:
33++ key: _redmine_
34++ secret: #{secret}
35++
36++development:
37++ key: _redmine_
38++ secret: #{secret}
39++
40++test:
41++ key: _redmine_
42++ secret: #{secret}
43+ EOF
44+ end
45+ end
46+-
47+-desc 'Generates a secret token for the application.'
48+-task :generate_secret_token => ['config/initializers/secret_token.rb']
49+--- redmine.orig/config/application.rb
50++++ redmine/config/application.rb
51+@@ -66,7 +66,20 @@ module RedmineApp
52+ # move tmp directory to RAILS_TMP
53+ config.paths['tmp'] = ENV['RAILS_TMP']
54+55+- config.session_store :cookie_store, :key => '_redmine_session'
56++ # loads cookie based session session and secret keys
57++ # this is needed here because initializers are loaded after plugins,
58++ # and some plugins initialize ActionController which requires a secret to be set.
59++ # crash if file not found
60++ relativeUrlRoot = ENV['RAILS_RELATIVE_URL_ROOT']
61++ filename = ENV['RAILS_ETC'] ? File.join(ENV['RAILS_ETC'], 'session.yml') : File.join(File.dirname(__FILE__), '..', 'session.yml')
62++ if File.exists?(filename)
63++ sessionconfig = YAML::load_file(filename)
64++ config.session_store :cookie_store, :key => sessionconfig[Rails.env]['key'], :path => (relativeUrlRoot.blank?) ? '/' : relativeUrlRoot
65++ config.secret_token = sessionconfig[Rails.env]['secret']
66++ else
67++ # temporary settings before session.yml is created
68++ config.session_store :cookie_store, :key => '_redmine_session', :path => (relativeUrlRoot.blank?) ? '/' : relativeUrlRoot
69++ end
70+71+ # log path
72+ config.paths['log'] = File.join(ENV['RAILS_LOG'], "#{Rails.env}.log") unless !ENV['RAILS_LOG']