net-openvpn 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/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Net-Openvpn
2
+
3
+ Net-Openvpn is a gem for configuring a local OpenVPN installation.
4
+
5
+ ## Usage
6
+
7
+ ### Server configuration
8
+
9
+ Modifying the config for a server (config file will be called `auckland-office.conf`):
10
+
11
+ ```ruby
12
+ server = Net::Openvpn.server("auckland-office")
13
+ server.set :port, 1194
14
+ server.save
15
+ ```
16
+
17
+ ### Host Configuration (read: client-config-directive)
18
+
19
+ This is how you set the IP address of a VPN host with the hostname `optimus`:
20
+
21
+ ```ruby
22
+ host = Net::Openvpn.host("optimus")
23
+ host.ip = 10.8.0.24
24
+ host.network = 10.8.0.0
25
+ host.save
26
+ ```
27
+
28
+ This would create a file at `/etc/openvpn/ccd/optimus` containing the following:
29
+
30
+ ```
31
+ ifconfig-push 10.8.0.24 10.8.0.0
32
+ ```
33
+
34
+ So that any host connecting to the VPN with a hostname of `optimus` get assigned `10.8.0.24`.
35
+
36
+ ## Rails Permissions
37
+
38
+ If you are running rails and you want to give the rails user access, you could do it like this:
39
+
40
+ ```sh
41
+ groupadd openvpn
42
+ chown root.openvpn /etc/openvpn -R
43
+ chmod ug+rwx /etc/openvpn -R
44
+ chmod o-rwx /etc/openvpn -R
45
+ cd /etc/openvpn
46
+ chmod g-rwx easy-rsa *.key *.crt *.pem
47
+ usermod -aG openvpn rails-app-user
48
+ ```
@@ -0,0 +1,30 @@
1
+ require 'net/openvpn/server'
2
+ require 'net/openvpn/host'
3
+ require 'net/openvpn/client_config'
4
+ require 'net/openvpn/parser/server_config'
5
+
6
+ module Net
7
+ module Openvpn
8
+ class << self
9
+
10
+ def basepath(path="")
11
+ path = "/#{path}" unless path.empty?
12
+ "/etc/openvpn#{path}"
13
+ end
14
+
15
+ def ccdpath(path="")
16
+ path = "/#{path}" unless path.empty?
17
+ basepath "ccd#{path}"
18
+ end
19
+
20
+ def host(hostname)
21
+ Net::Openvpn::Host.new(hostname)
22
+ end
23
+
24
+ def server(name)
25
+ Net::Openvpn::Server.new(name)
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,48 @@
1
+ module Net
2
+ module Openvpn
3
+ class ClientConfig
4
+
5
+ def initialize(hostname)
6
+ @hostname = hostname
7
+ load if exists?
8
+ end
9
+
10
+ def load
11
+ ccd = File.read(path)
12
+ matches = ccd.match /ifconfig-push ([0-9\.]+) ([0-9\.]+)/
13
+ @ip = matches[1]
14
+ @network = matches[2]
15
+ end
16
+
17
+ def path
18
+ Net::Openvpn.ccdpath @hostname
19
+ end
20
+
21
+ def exists?
22
+ File.exists? path
23
+ end
24
+
25
+ def ip=(ip)
26
+ @ip = ip
27
+ end
28
+
29
+ def network=(network)
30
+ @network = network
31
+ end
32
+
33
+ def validate!
34
+ raise ArgumentError, "No IP set!" if @ip.nil? or @ip.empty?
35
+ raise ArgumentError, "No network set!" if @network.nil? or @network.empty?
36
+ end
37
+
38
+ def save
39
+ validate!
40
+
41
+ File.open(path, "w") do |f|
42
+ f.puts "ifconfig-push #{@ip} #{@network}"
43
+ end
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,32 @@
1
+ module Net
2
+ module Openvpn
3
+ class Host
4
+
5
+ def initialize(hostname)
6
+ @hostname = hostname
7
+ @config = Net::Openvpn::ClientConfig.new(@hostname)
8
+ end
9
+
10
+ def generate_key
11
+
12
+ end
13
+
14
+ def generate_ovpn
15
+
16
+ end
17
+
18
+ def ip=(ip)
19
+ @config.ip = ip
20
+ end
21
+
22
+ def network=(network)
23
+ @config.network = network
24
+ end
25
+
26
+ def save
27
+ @config.save
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,33 @@
1
+ module Net
2
+ module Openvpn
3
+ module Parser
4
+ module ServerConfig
5
+ class << self
6
+
7
+ def parse(path)
8
+ config = {}
9
+
10
+ File.read(path).each_line do |line|
11
+ next if line =~ /^$/
12
+ parts = line.split(" ")
13
+ key = parts.first
14
+ value = parts[1..parts.size].join(" ")
15
+ config[key.to_sym] = value
16
+ end
17
+
18
+ config
19
+ end
20
+
21
+ def save(path, config)
22
+ File.open(path, "w") do |f|
23
+ config.each do |key, value|
24
+ f.puts "#{key} #{value}"
25
+ end
26
+ end
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,36 @@
1
+ module Net
2
+ module Openvpn
3
+ class Server
4
+
5
+ def initialize(name)
6
+ @name = name
7
+ load if exists?
8
+ end
9
+
10
+ def load
11
+ @config = Net::Openvpn::Parser::ServerConfig.parse(path)
12
+ end
13
+
14
+ def get(key)
15
+ @config[key]
16
+ end
17
+
18
+ def set(key, value)
19
+ @config[key] = value
20
+ end
21
+
22
+ def path
23
+ Net::Openvpn.basepath "#{@name}.conf"
24
+ end
25
+
26
+ def exists?
27
+ File.exists? path
28
+ end
29
+
30
+ def save
31
+ Net::Openvpn::Parser::ServerConfig.save(path, @config)
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,18 @@
1
+ #coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "net-openvpn"
7
+ spec.version = "0.1"
8
+ spec.authors = ["Robert McLeod"]
9
+ spec.email = ["robert@penguinpower.co.nz"]
10
+ spec.description = %q{Net-Openvpn is an openvpn library for configuring a local OpenVPN service}
11
+ spec.summary = %q{Local OpenVPN configurator}
12
+ spec.homepage = "https://github.com/penguinpowernz/net-openvpn"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.require_paths = ["lib", "lib/net", "lib/net/openvpn"]
17
+ end
18
+
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: net-openvpn
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Robert McLeod
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-07 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Net-Openvpn is an openvpn library for configuring a local OpenVPN service
15
+ email:
16
+ - robert@penguinpower.co.nz
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - README.md
22
+ - lib/net/openvpn.rb
23
+ - lib/net/openvpn/client_config.rb
24
+ - lib/net/openvpn/host.rb
25
+ - lib/net/openvpn/parser/server_config.rb
26
+ - lib/net/openvpn/server.rb
27
+ - net-openvpn.gemspec
28
+ homepage: https://github.com/penguinpowernz/net-openvpn
29
+ licenses:
30
+ - MIT
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ - lib/net
36
+ - lib/net/openvpn
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubyforge_project:
51
+ rubygems_version: 1.8.25
52
+ signing_key:
53
+ specification_version: 3
54
+ summary: Local OpenVPN configurator
55
+ test_files: []