openvpn_configurator 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5c1f39eb5fb9575fbd0cf3f65c293b2c85ba65773c840f6cf19a0c3a54c9f79
|
4
|
+
data.tar.gz: 88f0572ff291a1b5ec27d8bb66654a6671b4d54b2974ffdfc9d5d8f6265bf0cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14e4908a7f2b7f5d497e341fb429267cc5d33363514cf89c4ffde4411871864c37b4895006d514fb375a76f0c07352476b4d0f8284c05b92d1971c946bb72724
|
7
|
+
data.tar.gz: fc5de4cd52c552cdf919f0804d832004a0ff9d291efcacc1fa3a1c497e3be92388d84d5dd33dbd2f62c98648e271b7f5f4e3656767f0f32877691f532b6bf633
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## [1.1.0] - 2020-10-12
|
8
|
+
### Added
|
9
|
+
- Support for `--client` option
|
10
|
+
- Automatic pruning of overlapping/duplicate routes
|
11
|
+
|
7
12
|
## [1.0.0] - 2020-04-28
|
8
13
|
|
9
14
|
### Added
|
@@ -41,6 +41,7 @@ module OpenVPNConfigurator
|
|
41
41
|
banner self.synopsis
|
42
42
|
banner "Usage: #{$0} [options] <input-path> <output-path>"
|
43
43
|
banner 'Dynamic route collection options'
|
44
|
+
opt :client, "Run in client mode (directly assign routes instead of pushing them)", type: :boolean, default: false
|
44
45
|
opt :route_v4_aws_region, "Add IPv4 routes for an AWS region (like 'us-west-2')", type: :string, multi: true
|
45
46
|
opt :route_v4_dns, 'Add IPv4 routes for A record(s) returned by the specified DNS query', type: :string, multi: true
|
46
47
|
banner 'Actions'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module OpenVPNConfigurator
|
3
|
+
# Represents a comment to be inserted into the configuration file
|
4
|
+
class Comment
|
5
|
+
def initialize(message)
|
6
|
+
@message = message
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
"#{@message.gsub("\n", ' ')}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -5,6 +5,10 @@ require 'optimist'
|
|
5
5
|
require 'resolv'
|
6
6
|
require 'rest_client'
|
7
7
|
require 'semantic_logger'
|
8
|
+
require 'time'
|
9
|
+
|
10
|
+
require_relative 'comment'
|
11
|
+
|
8
12
|
|
9
13
|
module OpenVPNConfigurator
|
10
14
|
class RouteGatherer
|
@@ -18,9 +22,10 @@ module OpenVPNConfigurator
|
|
18
22
|
old_output = read_file options[:output_path], nonexistent_behavior: :empty_string
|
19
23
|
|
20
24
|
routes = gather_routes options
|
21
|
-
|
25
|
+
reduced = reduce_routes routes
|
26
|
+
rendered = render_routes reduced, client: !!options[:client]
|
22
27
|
|
23
|
-
result = format "%s\n\n\n# Added by OpenVPN Configurator v%s\n%s", template, VERSION, rendered
|
28
|
+
result = format "%s\n\n\n# Added by OpenVPN Configurator v%s at %s\n%s", template, VERSION, Time.now.iso8601(6), rendered
|
24
29
|
if result != old_output
|
25
30
|
logger.info "Output content changed, rewriting file #{options[:output_path].inspect}"
|
26
31
|
write_file options[:output_path], result
|
@@ -86,6 +91,51 @@ module OpenVPNConfigurator
|
|
86
91
|
end
|
87
92
|
|
88
93
|
|
94
|
+
# rel determines the relationship to another IPv4Net. Returns:
|
95
|
+
# * 1 if this IPv4Net is the supernet of other
|
96
|
+
# * 0 if the two are equal
|
97
|
+
# * -1 if this IPv4Net is a subnet of other
|
98
|
+
# * nil if the networks are unrelated
|
99
|
+
|
100
|
+
# @return [Hash<String, Array<NetAddr::IPv4Net, NetAddr::IPv6Net>]
|
101
|
+
def reduce_routes(routes)
|
102
|
+
seen_v4 = []
|
103
|
+
seen_v6 = []
|
104
|
+
reduction = false
|
105
|
+
result = {}
|
106
|
+
routes.each_pair do |name, entries|
|
107
|
+
result[name] = []
|
108
|
+
entries.each do |entry|
|
109
|
+
seen = case entry
|
110
|
+
when NetAddr::IPv4Net
|
111
|
+
seen_v4
|
112
|
+
when NetAddr::IPv6Net
|
113
|
+
seen_v6
|
114
|
+
else
|
115
|
+
nil
|
116
|
+
end
|
117
|
+
if seen
|
118
|
+
covered = seen.find { |s| [1, 0].include? s.rel(entry) }
|
119
|
+
if covered
|
120
|
+
reduction = true
|
121
|
+
result[name].push Comment.new("Route #{entry} already covered by route #{covered}")
|
122
|
+
else
|
123
|
+
seen.push entry
|
124
|
+
result[name].push entry
|
125
|
+
end
|
126
|
+
else
|
127
|
+
result[name].push entry
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
if reduction
|
132
|
+
reduce_routes result
|
133
|
+
else
|
134
|
+
result
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
|
89
139
|
# For tests, this method is stubbable
|
90
140
|
# @return [Array<NetAddr::IPv4, NetAddr::IPv6>]
|
91
141
|
def resolve_v4(name)
|
@@ -106,20 +156,27 @@ module OpenVPNConfigurator
|
|
106
156
|
|
107
157
|
|
108
158
|
# @param routes [Hash<String, Array<NetAddr::IPv4Net, NetAddr::IPv6Net>>] { "Configuration Source Name" => [NetAddr::IPv4Net, NetAddr::IPv6Net] }
|
109
|
-
def render_routes(routes)
|
159
|
+
def render_routes(routes, client: false)
|
160
|
+
indent = "\t\t\t"
|
161
|
+
directive_indent = client ? indent : ' '
|
162
|
+
prefix = client ? '' : "push#{indent}\""
|
163
|
+
postfix = client ? '' : '"'
|
164
|
+
|
110
165
|
result = []
|
111
166
|
routes.keys.sort.each do |source|
|
112
167
|
result << "##{source}"
|
113
168
|
routes[source].sort_by(&:to_s).each do |route|
|
114
169
|
directive = case route
|
115
170
|
when NetAddr::IPv4Net
|
116
|
-
format 'route
|
171
|
+
format 'route%s%s', directive_indent, route.extended
|
117
172
|
when NetAddr::IPv6Net
|
118
|
-
format 'route-ipv6
|
173
|
+
format 'route-ipv6%s%s', directive_indent, route.to_s
|
174
|
+
when Comment
|
175
|
+
format '# %s', route.to_s
|
119
176
|
else
|
120
177
|
raise "Only supporting IPv4 and IPv6 networks presently, got #{route.inspect} instead"
|
121
178
|
end
|
122
|
-
result << format("
|
179
|
+
result << format("%s%s%s", prefix, directive, postfix)
|
123
180
|
end
|
124
181
|
result << ''
|
125
182
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openvpn_configurator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Ten Clay
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gelf
|
@@ -214,6 +214,7 @@ files:
|
|
214
214
|
- exe/openvpn_configurator
|
215
215
|
- lib/openvpn_configurator.rb
|
216
216
|
- lib/openvpn_configurator/cli.rb
|
217
|
+
- lib/openvpn_configurator/comment.rb
|
217
218
|
- lib/openvpn_configurator/route_gatherer.rb
|
218
219
|
- lib/openvpn_configurator/version.rb
|
219
220
|
- openvpn_configurator.gemspec
|
@@ -239,8 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
239
240
|
- !ruby/object:Gem::Version
|
240
241
|
version: '0'
|
241
242
|
requirements: []
|
242
|
-
|
243
|
-
rubygems_version: 2.7.6
|
243
|
+
rubygems_version: 3.1.3
|
244
244
|
signing_key:
|
245
245
|
specification_version: 4
|
246
246
|
summary: Assists in generating OpenVPN configurations.
|