h2o-configurator 0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/LICENSE.txt +21 -0
- data/README.md +28 -0
- data/Rakefile +2 -0
- data/bin/h2o-configurator +7 -0
- data/h2o-configurator.gemspec +26 -0
- data/lib/h2o-configurator.rb +5 -0
- data/lib/h2o-configurator/auto-extension-handler.rb +15 -0
- data/lib/h2o-configurator/builder.rb +189 -0
- data/lib/h2o-configurator/redirect-handler.rb +22 -0
- data/lib/h2o-configurator/version.rb +5 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4d2957f2852560a37a815a8171aada782b3ea07cab3d9133d6a57c5717233de8
|
4
|
+
data.tar.gz: e9666263537665189b952a890566ffbe02d8e0b25dd66192864b40cbfc67c0a2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 17ec61f8ea25907e6ab70da9d8423c624fd2861d5af1289a47c218e26f58303f3ba86237752d088a82da44fc30ade271e5c114eb388f041849ac85a2228c9c4b
|
7
|
+
data.tar.gz: 592624ac582fcee91acbe29b9beaf123e537a8a8054fe1e9da80b739d76f5252a133e429361da5baedc2e5b3fe4423938c2fd7d9aeb117c92d80293e1e71ec95
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 John Labovitz
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# H2OConfigurator
|
2
|
+
|
3
|
+
H2OConfigurator builds config files for the [H2O web server](https://h2o.examp1e.net).
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
$ gem install h2o-configurator
|
9
|
+
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
TODO: Write usage instructions here
|
14
|
+
|
15
|
+
|
16
|
+
## Development
|
17
|
+
|
18
|
+
To install this gem onto your local machine, run `rake install`. To release a new version, update the version number in `version.rb`, and then run `rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
19
|
+
|
20
|
+
|
21
|
+
## Contributing
|
22
|
+
|
23
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jslabovitz/h2o-configurator.
|
24
|
+
|
25
|
+
|
26
|
+
## License
|
27
|
+
|
28
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require_relative 'lib/h2o-configurator/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'h2o-configurator'
|
7
|
+
spec.version = H2OConfigurator::VERSION
|
8
|
+
spec.authors = ['John Labovitz']
|
9
|
+
spec.email = ['johnl@johnlabovitz.com']
|
10
|
+
|
11
|
+
spec.summary = %q{Build H2O config files.}
|
12
|
+
spec.description = %q{H2OConfigurator builds H2O config files.}
|
13
|
+
spec.homepage = %q{https://github.com/jslabovitz/h2o-configurator}
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = 'bin'
|
20
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_dependency 'path', '~> 2.0'
|
24
|
+
|
25
|
+
spec.add_development_dependency 'rake', '~> 0'
|
26
|
+
end
|
@@ -0,0 +1,189 @@
|
|
1
|
+
module H2OConfigurator
|
2
|
+
|
3
|
+
SitesDirGlob = '/Users/*/Sites/*'
|
4
|
+
H2OEtcDir = Path.new('/usr/local/etc/h2o')
|
5
|
+
H2OLogDir = Path.new('/usr/local/var/log/h2o')
|
6
|
+
H2OConfFile = H2OEtcDir / 'h2o.conf'
|
7
|
+
AutoExtensionHandlerFile = Path.new(__FILE__).dirname / 'auto-extension-handler.rb'
|
8
|
+
RedirectHandlerFile = Path.new(__FILE__).dirname / 'redirect-handler.rb'
|
9
|
+
InstalledAutoExtensionHandlerFile = H2OEtcDir / AutoExtensionHandlerFile.basename
|
10
|
+
InstalledRedirectHandlerFile = H2OEtcDir / RedirectHandlerFile.basename
|
11
|
+
ErrorLogFile = H2OLogDir / 'error.log'
|
12
|
+
CertBaseDir = Path.new('/etc/letsencrypt/live')
|
13
|
+
ServerCertificateFilename = 'fullchain.pem'
|
14
|
+
PrivateKeyFilename = 'privkey.pem'
|
15
|
+
DomainPrefixes = %w{www.}
|
16
|
+
DomainSuffixes = %w{.test}
|
17
|
+
|
18
|
+
class Builder
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
H2OLogDir.mkpath
|
22
|
+
end
|
23
|
+
|
24
|
+
def make_config
|
25
|
+
config = {
|
26
|
+
'compress' => 'ON',
|
27
|
+
'reproxy' => 'ON',
|
28
|
+
'error-log' => ErrorLogFile.to_s,
|
29
|
+
'hosts' => {},
|
30
|
+
}
|
31
|
+
Path.glob(SitesDirGlob).reject { |p| p.extname == '.old' || p.extname == '.new' }.each do |site_dir|
|
32
|
+
site = Site.new(site_dir)
|
33
|
+
config['hosts'].merge!(site.make_config)
|
34
|
+
end
|
35
|
+
config
|
36
|
+
end
|
37
|
+
|
38
|
+
def write_config
|
39
|
+
RedirectHandlerFile.copy(InstalledRedirectHandlerFile)
|
40
|
+
AutoExtensionHandlerFile.copy(InstalledAutoExtensionHandlerFile)
|
41
|
+
H2OConfFile.write(YAML.dump(make_config))
|
42
|
+
check_config
|
43
|
+
end
|
44
|
+
|
45
|
+
def check_config
|
46
|
+
system('h2o', '-t', '-c', H2OConfFile.to_s)
|
47
|
+
exit($?.to_i) unless $?.success?
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
class Site
|
53
|
+
|
54
|
+
attr_accessor :dir
|
55
|
+
attr_accessor :name
|
56
|
+
|
57
|
+
def initialize(dir)
|
58
|
+
@dir = dir
|
59
|
+
@name = dir.basename.to_s
|
60
|
+
end
|
61
|
+
|
62
|
+
def make_config
|
63
|
+
config = {}
|
64
|
+
if cert_dir.exist?
|
65
|
+
https_redirect_host_config = make_https_redirect_host_config(80)
|
66
|
+
host_config = make_host_config(443)
|
67
|
+
else
|
68
|
+
https_redirect_host_config = nil
|
69
|
+
host_config = make_host_config(80)
|
70
|
+
end
|
71
|
+
domains.each do |domain|
|
72
|
+
if https_redirect_host_config
|
73
|
+
config["#{domain}:80"] = https_redirect_host_config
|
74
|
+
config["#{domain}:443"] = host_config
|
75
|
+
else
|
76
|
+
config["#{domain}:80"] = host_config
|
77
|
+
end
|
78
|
+
end
|
79
|
+
config
|
80
|
+
end
|
81
|
+
|
82
|
+
def domains
|
83
|
+
([''] + DomainPrefixes).map do |prefix|
|
84
|
+
([''] + DomainSuffixes).map do |suffix|
|
85
|
+
"#{prefix}#{@name}#{suffix}"
|
86
|
+
end
|
87
|
+
end.flatten
|
88
|
+
end
|
89
|
+
|
90
|
+
def make_host_config(port=80)
|
91
|
+
config = {
|
92
|
+
'listen' => {
|
93
|
+
'port' => port,
|
94
|
+
},
|
95
|
+
'access-log' => access_log_file.to_s,
|
96
|
+
'setenv' => { 'HOST_DIR' => @dir.to_s },
|
97
|
+
'paths' => {
|
98
|
+
'/' => make_handlers,
|
99
|
+
},
|
100
|
+
}
|
101
|
+
if server_certificate_file.exist? && private_key_file.exist?
|
102
|
+
config['listen']['ssl'] = {
|
103
|
+
'certificate-file' => server_certificate_file.to_s,
|
104
|
+
'key-file' => private_key_file.to_s,
|
105
|
+
}
|
106
|
+
end
|
107
|
+
config
|
108
|
+
end
|
109
|
+
|
110
|
+
def make_https_redirect_host_config(port=80)
|
111
|
+
{
|
112
|
+
'listen' => port,
|
113
|
+
'paths' => {
|
114
|
+
'/' => {
|
115
|
+
'redirect' => "https://#{@name}",
|
116
|
+
}
|
117
|
+
}
|
118
|
+
}
|
119
|
+
end
|
120
|
+
|
121
|
+
def make_handlers
|
122
|
+
handlers = []
|
123
|
+
if htpasswd_file.exist?
|
124
|
+
handlers << RubyHandler.make(
|
125
|
+
%Q{
|
126
|
+
require 'htpasswd'
|
127
|
+
Htpasswd.new('#{htpasswd_file}', '#{@name}')
|
128
|
+
}
|
129
|
+
)
|
130
|
+
end
|
131
|
+
handlers << RubyHandler.make(
|
132
|
+
%Q{
|
133
|
+
require '#{H2OConfigurator::InstalledRedirectHandlerFile}'
|
134
|
+
H2OConfigurator::RedirectHandler.new
|
135
|
+
},
|
136
|
+
)
|
137
|
+
handlers << RubyHandler.make(
|
138
|
+
%Q{
|
139
|
+
require '#{H2OConfigurator::InstalledAutoExtensionHandlerFile}'
|
140
|
+
H2OConfigurator::AutoExtensionHandler.new
|
141
|
+
}
|
142
|
+
)
|
143
|
+
handlers << FileDirHandler.make(@dir)
|
144
|
+
handlers
|
145
|
+
end
|
146
|
+
|
147
|
+
def cert_dir
|
148
|
+
H2OConfigurator::CertBaseDir / @name
|
149
|
+
end
|
150
|
+
|
151
|
+
def server_certificate_file
|
152
|
+
cert_dir / H2OConfigurator::ServerCertificateFilename
|
153
|
+
end
|
154
|
+
|
155
|
+
def private_key_file
|
156
|
+
cert_dir / H2OConfigurator::PrivateKeyFilename
|
157
|
+
end
|
158
|
+
|
159
|
+
def htpasswd_file
|
160
|
+
@dir / '.htpasswd'
|
161
|
+
end
|
162
|
+
|
163
|
+
def access_log_file
|
164
|
+
H2OConfigurator::H2OLogDir / "#{@name}.access.log"
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
|
169
|
+
class RubyHandler
|
170
|
+
|
171
|
+
def self.make(code)
|
172
|
+
{
|
173
|
+
'mruby.handler' => code.gsub(/\n\s+/, "\n").strip,
|
174
|
+
}
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
class FileDirHandler
|
180
|
+
|
181
|
+
def self.make(dir)
|
182
|
+
{
|
183
|
+
'file.dir' => dir.to_s,
|
184
|
+
}
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module H2OConfigurator
|
2
|
+
|
3
|
+
class RedirectHandler
|
4
|
+
|
5
|
+
def call(env)
|
6
|
+
host_dir = env['HOST_DIR']
|
7
|
+
path = env['PATH_INFO']
|
8
|
+
redirect_path = host_dir + path.sub(%r{/$}, '') + '.redirect'
|
9
|
+
if File.exist?(redirect_path)
|
10
|
+
location, status = File.read(redirect_path).split(/\s+/, 2)
|
11
|
+
status = status.to_i
|
12
|
+
[status, {'location' => location}, []]
|
13
|
+
elsif path !~ %r{/$} && File.directory?(host_dir + path)
|
14
|
+
[302, {'location' => path + '/'}, []]
|
15
|
+
else
|
16
|
+
[399, {}, []]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: h2o-configurator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.4'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Labovitz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: path
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: H2OConfigurator builds H2O config files.
|
42
|
+
email:
|
43
|
+
- johnl@johnlabovitz.com
|
44
|
+
executables:
|
45
|
+
- h2o-configurator
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- bin/h2o-configurator
|
54
|
+
- h2o-configurator.gemspec
|
55
|
+
- lib/h2o-configurator.rb
|
56
|
+
- lib/h2o-configurator/auto-extension-handler.rb
|
57
|
+
- lib/h2o-configurator/builder.rb
|
58
|
+
- lib/h2o-configurator/redirect-handler.rb
|
59
|
+
- lib/h2o-configurator/version.rb
|
60
|
+
homepage: https://github.com/jslabovitz/h2o-configurator
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.7.4
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Build H2O config files.
|
84
|
+
test_files: []
|