rails_pwnerer 0.6.108 → 0.6.109

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v0.6.109. Allow .crt for SSL certificate chains.
2
+
1
3
  v0.6.108. Re-release with X-Forwarded-For for real.
2
4
 
3
5
  v0.6.107. Added X-Forwarded-For header to nginx config.
@@ -3,7 +3,7 @@ require 'yaml'
3
3
 
4
4
  class RailsPwnerer::App::Config
5
5
  include RailsPwnerer::Base
6
-
6
+
7
7
  def random_db_password
8
8
  (0...16).map { |i| "abcdefghijklmnopqrstuvwxyz"[rand(26),1]}.join
9
9
  end
@@ -16,8 +16,8 @@ class RailsPwnerer::App::Config
16
16
  app_db[:app_path] = File.join(RailsPwnerer::Config.path_to(:apps), app_name + '.' + instance_name)
17
17
  # the path to application backups
18
18
  app_db[:backup_path] ||= File.join(RailsPwnerer::Config.path_to(:backups), app_name + '.' + instance_name)
19
-
20
- # the user which will receive the "keys" to the production system
19
+
20
+ # the user which will receive the "keys" to the production system
21
21
  app_db[:pwnerer_user] ||= RailsPwnerer::Config[:host][:pwnerer_user]
22
22
  # the number of frontends for the application instance
23
23
  app_db[:frontends] ||= 4 # most computers have 2 cores nowadays
@@ -25,7 +25,7 @@ class RailsPwnerer::App::Config
25
25
  app_db[:frontends_per_core] ||= 2 # best practice
26
26
  # the first internal port for the application instance
27
27
  app_db[:port0] = 0 # will be overwritten during allocation
28
- # the name of the database for the application instance
28
+ # the name of the database for the application instance
29
29
  app_db[:db_name] ||= (app_name + '_' + instance_name + '_prod')[0...60] # avoiding mySQL breakage
30
30
  # the datbase user for the given application
31
31
  app_db[:db_user] ||= (app_name + '_' + instance_name)[0...16] # mySQL doesn't like long user names
@@ -45,7 +45,7 @@ class RailsPwnerer::App::Config
45
45
  app_db[:gems] ||= ''
46
46
  # set to disable accidental db resets (on production vs. staging instances)
47
47
  app_db[:enable_db_reset] ||= false
48
-
48
+
49
49
  # the number of cores on the platform
50
50
  app_db[:detected_cores] ||= cpu_cores.length
51
51
  end
@@ -55,34 +55,40 @@ class RailsPwnerer::App::Config
55
55
  app_db_name = RailsPwnerer::Config.app_db_name(app_name, instance_name)
56
56
  app_db = RailsPwnerer::Config.create_db app_db_name
57
57
  populate_defaults app_name, instance_name, app_db
58
-
58
+
59
59
  FileUtils.mkpath app_db[:app_path]
60
-
61
- RailsPwnerer::Config.flush_db app_db
60
+
61
+ RailsPwnerer::Config.flush_db app_db
62
62
  return app_db[:app_path]
63
63
  end
64
-
64
+
65
65
  # pushes config changes from the application file to the database
66
66
  def update(app_name, instance_name)
67
67
  app_config = RailsPwnerer::Config[app_name, instance_name]
68
-
68
+
69
69
  db_name, db_user, db_pass = app_config[:db_name], app_config[:db_user], app_config[:db_pass]
70
70
  app_config.clear
71
71
  # NOTE: we don't restore the password on purpose, to get a new password on the update
72
72
  # this is useful so processes that were spawned before the update can't corrupt the db
73
73
  app_config[:db_name], app_config[:db_user] = db_name, db_user
74
-
74
+
75
75
  populate_defaults app_name, instance_name, app_config
76
76
  Dir.chdir app_config[:app_path] do
77
77
  # Populate the default SSL configuration if the right files exist.
78
78
  ssl_cert = File.expand_path "config/rails_pwnerer/#{instance_name}.cer"
79
- ssl_key = File.expand_path "config/rails_pwnerer/#{instance_name}.pem"
79
+
80
+ ssl_cert2 = File.expand_path "config/rails_pwnerer/#{instance_name}.crt"
81
+ if !File.exists?(ssl_cert) and File.exists?(ssl_cert2)
82
+ ssl_cert = ssl_cert2
83
+ end
84
+
85
+ ssl_key = File.expand_path "config/rails_pwnerer/#{instance_name}.pem"
80
86
  if File.exists?(ssl_cert) and File.exists?(ssl_key)
81
87
  app_config[:ssl_cert] = ssl_cert
82
88
  app_config[:ssl_key] = ssl_key
83
89
  app_config[:port] = 443
84
90
  end
85
-
91
+
86
92
  ["config/rails_pwnerer/.yml", "config/rails_pwnerer/#{instance_name}.yml"].each do |fname|
87
93
  next unless File.exists? fname
88
94
  config_update = File.open(fname, 'r') { |f| YAML.load f } rescue nil
@@ -95,17 +101,17 @@ class RailsPwnerer::App::Config
95
101
  end
96
102
  end
97
103
  end
98
-
104
+
99
105
  # TODO: if database settings changed, the database should be moved (re-created or re-keyed)
100
106
  if db_pass != app_config[:db_pass]
101
107
  db_pass = random_db_password if !db_pass || db_pass.empty?
102
108
  RailsPwnerer::App::Database.new.manage app_name, instance_name, :rekey
103
109
  end
104
-
110
+
105
111
  RailsPwnerer::Config.flush_db RailsPwnerer::Config.app_db_name(app_name, instance_name)
106
112
  end
107
-
108
- def manage(app_name, instance_name, action)
113
+
114
+ def manage(app_name, instance_name, action)
109
115
  case action
110
116
  when :rekey
111
117
  app_config = RailsPwnerer::Config[app_name, instance_name]
@@ -116,7 +122,7 @@ class RailsPwnerer::App::Config
116
122
  def setup(app_name, instance_name)
117
123
  update app_name, instance_name
118
124
  end
119
-
125
+
120
126
  def remove(app_name, instance_name)
121
127
  app_db_name = RailsPwnerer::Config.app_db_name(app_name, instance_name)
122
128
  RailsPwnerer::Config.drop_db app_db_name
@@ -31,7 +31,7 @@ class RailsPwnerer::App::NginxConfig
31
31
  # server configuration -- big and ugly
32
32
  f << <<NGINX_CONFIG
33
33
  server {
34
- listen #{app_port};
34
+ listen #{app_port}#{app_config[:ssl_key] ? ' ssl' : ''};
35
35
  charset utf-8;
36
36
  #{app_config[:ssl_key] ? 'ssl on;' : ''}
37
37
  #{app_config[:ssl_key] ? "ssl_certificate #{app_config[:ssl_cert]};" : ''}
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "rails_pwnerer"
5
- s.version = "0.6.108"
5
+ s.version = "0.6.109"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Victor Costan"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_pwnerer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.108
4
+ version: 0.6.109
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: