pound_config_generator 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in pound_config_generator.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2007 Shawn Veader
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,16 @@
1
+ A simple hack based off Chris Wanstrath's generate_nginx_config gem.
2
+
3
+ Use it:
4
+ $ generate_pound_config pound_config.yml /etc/pound/pound.conf
5
+
6
+ See an example config file:
7
+ $ generate_pound_config --example
8
+
9
+ You can set two environment variables:
10
+ - POUND_CONFIG_YAML to specify the YAML config file
11
+ - POUND_CONFIG_FILE to specify the pound config file
12
+
13
+ By default, generate_pound_config won't overwrite your OUT file. To override this behavior, pass in --overwrite or -o or -y or --force or -f.
14
+
15
+ >> Shawn Veader
16
+ => shawn[at]veader[dot]org
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,2 @@
1
+ #! /usr/bin/env ruby
2
+ load File.dirname(__FILE__) + '/../lib/pound_config_generator.rb'
@@ -0,0 +1,39 @@
1
+ # all your HTTPS sites (port 443)
2
+ https_sites:
3
+ # where to find the certificate PEM file
4
+ cert_path: /etc/pound/certs/cert.pem
5
+ sites:
6
+ site_1:
7
+ domain: test1.veader.org
8
+ backends:
9
+ - 192.168.0.10
10
+ - 192.168.0.11
11
+ start_port: 8000
12
+ num_ports: 5
13
+ # setup a rule under HTTP to redirect to HTTPS
14
+ redirect: true
15
+
16
+ site_static:
17
+ domain: test1.veader.org
18
+ backends: 192.168.0.14
19
+ start_port: 8040
20
+ num_ports: 1
21
+ static: true
22
+
23
+ # all your HTTP sites (port 80)
24
+ http_sites:
25
+ sites:
26
+ site_2:
27
+ domain: test2.veader.org
28
+ backends: 192.168.0.12
29
+ start_port: 8010
30
+ num_ports: 4
31
+ # setup a rule under HTTPS to redirect to HTTP
32
+ redirect: true
33
+
34
+ site_3:
35
+ domain: test3.veader.org
36
+ backends: 192.168.0.13
37
+ start_port: 8020
38
+ num_ports: 3
39
+ redirect: false
data/lib/headers.txt ADDED
@@ -0,0 +1,8 @@
1
+ HTTP/1.1 404 Not Found
2
+ Date: Thu, 18 Jun 2009 21:22:34 GMT
3
+ Server: Apache/2.2.3 (Debian) Phusion_Passenger/2.0.6
4
+ X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 2.0.6
5
+ Cache-Control: no-cache
6
+ Content-Length: 947
7
+ Content-Type: text/html; charset=utf-8
8
+
data/lib/output.txt ADDED
@@ -0,0 +1,30 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+
6
+ <head>
7
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
8
+ <title>The page you were looking for doesn't exist (404)</title>
9
+ <style type="text/css">
10
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
11
+ div.dialog {
12
+ width: 25em;
13
+ padding: 0 4em;
14
+ margin: 4em auto 0 auto;
15
+ border: 1px solid #ccc;
16
+ border-right-color: #999;
17
+ border-bottom-color: #999;
18
+ }
19
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
20
+ </style>
21
+ </head>
22
+
23
+ <body>
24
+ <!-- This file lives in public/404.html -->
25
+ <div class="dialog">
26
+ <h1>The page you were looking for doesn't exist.</h1>
27
+ <p>You may have mistyped the address or the page may have moved.</p>
28
+ </div>
29
+ </body>
30
+ </html>
data/lib/pound.erb ADDED
@@ -0,0 +1,136 @@
1
+ <%
2
+ all_sites = []
3
+ Array(config['https_sites']['sites']).each do |n,s|
4
+ all_sites << s['domain']
5
+ end if config['https_sites']
6
+ Array(config['http_sites']['sites'] ).each do |n,s|
7
+ all_sites << s['domain']
8
+ end if config['http_sites']
9
+ all_sites.uniq! # kill duplicates
10
+ all_sites.sort! # sort by domain
11
+
12
+ cert_path = \
13
+ config['https_sites']['cert_path'] || '/etc/pound/certs/cert.pem'
14
+
15
+ https_sites = \
16
+ config['https_sites'] ? Array(config['https_sites']['sites']) : nil
17
+ http_sites = \
18
+ config['http_sites'] ? Array(config['http_sites']['sites']) : nil
19
+ %>
20
+ User "www-data"
21
+ Group "www-data"
22
+ #WebDAV 0
23
+ ## Logging: (goes to syslog by default)
24
+ LogLevel 5
25
+ ## how often to check backends (seconds)
26
+ Alive 30
27
+ ## how long pound will wait for client connection (seconds)
28
+ Client 60
29
+ ## timout to backend servers (seconds)
30
+ TimeOut 100
31
+
32
+ <% if https_sites %>
33
+ # ----------------------------------------------------------------
34
+ ListenHTTPS
35
+ Address 0.0.0.0
36
+ Port 443
37
+ Cert "<%= cert_path %>"
38
+ xHTTP 1
39
+
40
+ # pass along https hint
41
+ AddHeader "X-Forwarded-Proto: https"
42
+ HeadRemove "X-Forwarded-Proto"
43
+ <% https_sites.sort_by { |n,s| s['domain'] }.each do |name, site| %>
44
+ <% this_domain = site['domain'] || 'test.domain.com' %>
45
+ # <%= name.upcase %>
46
+
47
+ Service
48
+ HeadRequire "Host: <%= this_domain.gsub(/\./, '\.') %>"
49
+ <% all_sites.reject { |d| this_domain == d }.each do |domain| %>
50
+ HeadDeny "Host: <%= domain.gsub(/\./, '\.') %>"
51
+ <% end # all_sites.each %>
52
+
53
+ <% if site['static'] %>
54
+ URL "<%= site['filter'] || '.*.(css|js|jpg|gif|png)' %>"
55
+ <% end %>
56
+
57
+ <% 1.upto(site['num_ports'] || 5) do |i| %>
58
+ <% Array(site['backends']).each do |backend| %>
59
+ BackEnd
60
+ Address <%= backend %>
61
+
62
+ Port <%= (site['start_port'] || 8000) + (i-1) %>
63
+
64
+ End
65
+ <% end # backends.each %>
66
+ <% end # 0 - num_ports %>
67
+ End
68
+ <% end # https_sites[:sites].each %>
69
+
70
+ <% if http_sites %>
71
+ <% http_sites.sort_by { |n,s| s['domain'] }.each do |name, site| %>
72
+ <% next unless site['redirect'] %>
73
+ <% this_domain = site['domain'] || 'test.domain.com' %>
74
+ # <%= name.upcase %> (redirect)
75
+ Service
76
+ HeadRequire "Host: <%= this_domain.gsub(/\./, '\.') %>"
77
+ <% all_sites.reject { |d| this_domain == d }.each do |domain| %>
78
+ HeadDeny "Host: <%= domain.gsub(/\./, '\.') %>"
79
+ <% end # all_sites.each %>
80
+
81
+ Redirect "http://<%= this_domain %>"
82
+ End
83
+
84
+ <% end # http_sites[:sites].each %>
85
+ <% end # if HTTP %>
86
+ End
87
+ <% end # if HTTPS %>
88
+
89
+ <% if http_sites %>
90
+ # ----------------------------------------------------------------
91
+ ListenHTTP
92
+ Address 0.0.0.0
93
+ Port 80
94
+ xHTTP 1
95
+ <% http_sites.sort_by { |n,s| s['domain'] }.each do |name, site| %>
96
+ <% this_domain = site['domain'] || 'test.domain.com' %>
97
+
98
+ # <%= name.upcase %>
99
+
100
+ Service
101
+ HeadRequire "Host: <%= this_domain.gsub(/\./, '\.') %>"
102
+ <% all_sites.reject { |d| this_domain == d }.each do |domain| %>
103
+ HeadDeny "Host: <%= domain.gsub(/\./, '\.') %>"
104
+ <% end # all_sites.each %>
105
+
106
+ <% 1.upto(site['num_ports'] || 5) do |i| %>
107
+ <% Array(site['backends']).each do |backend| %>
108
+ BackEnd
109
+ Address <%= backend %>
110
+
111
+ Port <%= (site['start_port'] || 8000) + (i-1) %>
112
+
113
+ End
114
+ <% end # backends.each %>
115
+ <% end # 0 - num_ports %>
116
+ End
117
+ <% end # http_site[:sites].each %>
118
+
119
+ <% if https_sites %>
120
+ <% https_sites.sort_by { |n,s| s['domain'] }.each do |name, site| %>
121
+ <% next unless site['redirect'] %>
122
+ <% this_domain = site['domain'] || 'test.domain.com' %>
123
+ # <%= name.upcase %> (redirect)
124
+ Service
125
+ HeadRequire "Host: <%= this_domain.gsub(/\./, '\.') %>"
126
+ <% all_sites.reject { |d| this_domain == d }.each do |domain| %>
127
+ HeadDeny "Host: <%= domain.gsub(/\./, '\.') %>"
128
+ <% end # all_sites.each %>
129
+
130
+ Redirect "https://<%= this_domain %>"
131
+ End
132
+
133
+ <% end # https_sites[:sites].each %>
134
+ <% end # if HTTPS %>
135
+ End
136
+ <% end # if HTTP %>
@@ -0,0 +1,3 @@
1
+ module PoundConfigGenerator
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,45 @@
1
+ #! /usr/bin/env ruby
2
+ require 'erb'
3
+ require 'yaml'
4
+ # %w(erb yaml).each &method(:require) # ooo... look how clever i am. pffftt...
5
+
6
+ def error(message) puts(message) || exit end
7
+ def file(file) "#{File.dirname(__FILE__)}/#{file}" end
8
+
9
+ if ARGV.include? '--example'
10
+ example = file:'config.yml.example'
11
+ error open(example).read
12
+ end
13
+
14
+ env_in = ENV['POUND_CONFIG_YAML']
15
+ env_out = ENV['POUND_CONFIG_FILE']
16
+
17
+ if ARGV.empty? && !env_in
18
+ error "Usage: generate_pound_config [config file] [out file]"
19
+ end
20
+
21
+ overwrite = %w(-y -o -f --force --overwrite).any? { |f| ARGV.delete(f) }
22
+
23
+ filename = env_in || ARGV.shift || 'config.yml'
24
+ config = YAML.load(ERB.new(File.read(filename)).result)
25
+ template = \
26
+ if custom_template_index = (ARGV.index('--template') || ARGV.index('-t'))
27
+ custom = ARGV[custom_template_index+1]
28
+ unless File.exist?(custom)
29
+ error "=> Specified template file #{custom} does not exist."
30
+ end
31
+ ARGV.delete_at(custom_template_index) # delete the --argument
32
+ ARGV.delete_at(custom_template_index) # and its value
33
+ custom
34
+ else
35
+ file:'pound.erb'
36
+ end
37
+
38
+ output_filename = env_out || ARGV.shift || 'pound.conf'
39
+ if File.exists?(output_filename) && !overwrite
40
+ error "=> #{output_filename} already exists, won't overwrite it. Quitting."
41
+ else
42
+ output = ERB.new(File.read(template), nil, '>').result(binding)
43
+ open(output_filename, 'w+').write(output)
44
+ error "=> Wrote #{output_filename} successfully."
45
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "pound_config_generator/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "pound_config_generator"
7
+ s.version = PoundConfigGenerator::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Eric Boehs"]
10
+ s.email = ["ericboehs@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{A simple hack based off Chris Wanstrath's generate_nginx_config gem.}
13
+ s.description = %q{This is a gem version of Shawn Veader's pound_config_generator located at https://github.com/veader/pound_config_generator}
14
+
15
+ s.rubyforge_project = "pound_config_generator"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pound_config_generator
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Eric Boehs
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-02 00:00:00 -06:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: This is a gem version of Shawn Veader's pound_config_generator located at https://github.com/veader/pound_config_generator
23
+ email:
24
+ - ericboehs@gmail.com
25
+ executables:
26
+ - generate_pound_config
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - LICENSE
35
+ - README
36
+ - Rakefile
37
+ - bin/generate_pound_config
38
+ - lib/config.yml.example
39
+ - lib/headers.txt
40
+ - lib/output.txt
41
+ - lib/pound.erb
42
+ - lib/pound_config_generator.rb
43
+ - lib/pound_config_generator/version.rb
44
+ - pound_config_generator.gemspec
45
+ has_rdoc: true
46
+ homepage: ""
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options: []
51
+
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ hash: 3
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ requirements: []
73
+
74
+ rubyforge_project: pound_config_generator
75
+ rubygems_version: 1.4.2
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: A simple hack based off Chris Wanstrath's generate_nginx_config gem.
79
+ test_files: []
80
+