net-openvpn 0.2.1 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- Y2RiMDYyMjdiOWYxMzkzZWQyNjRjNTIzMTk4Y2UzZjVhMmM5OGNmMg==
5
- data.tar.gz: !binary |-
6
- NTU4NTI4MGM4MjBkZTI4ZjMxNzMzNGE5YWFiNmQ2ZWJkZGY4MTA1Zg==
2
+ SHA1:
3
+ metadata.gz: 31c5a0e4bcf580d2b27834d191891a01215ac82d
4
+ data.tar.gz: dc9bcbea63aa3f265560fac744ab085115a1968f
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MjFhZTcwODYzNzQxYjA2ODlkN2Q2OTFjZDU5ZTM4MTgyYjRhMTkxYTE3NzFk
10
- N2Y4Y2E2OGJlNDNmOTA4OWQwOTIxMmJhYzdhZTFkOGMxNjVkODAxMTE5NWFj
11
- NzdiYTYxOGM5MTRhZWJlMDFlZGM5YTgzZGMzMTkzMjYwMWE3M2Q=
12
- data.tar.gz: !binary |-
13
- Mzk1NTE5OWUyZjM2NmQwOWQxM2U5OGM4MzExMmJlMTE0M2VlYTQxMWQwZTll
14
- MjM2NzNiMzFhZGZmMmFmOTcxODkxYjY5YzRjZWFmM2RjYjM1NzdmMTRiZjRi
15
- NThlZTcxMDljNzgwMzIxYjk5ODY0YzE0OThmNzMzMTA3ZDEwOGM=
6
+ metadata.gz: 74270037b4c6b1bf017b85571609861321413f526e8b91677b42451e432ceca2bbc073ea63e196cc9ea04f5c59b9adeb80a59f1d4f5283b3f3644b9e65903185
7
+ data.tar.gz: 5c69397a66ae1086a7686074f3a19f495f10f366ca604b7059cee9807fdfa78550f277aeb8a3696f64e2e3383141df65d13495209c0f846556886943129858ff
@@ -0,0 +1 @@
1
+ /pkg
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- net-openvpn (0.2.1)
4
+ net-openvpn (0.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -17,6 +17,7 @@ GEM
17
17
  rspec-expectations (2.14.5)
18
18
  diff-lcs (>= 1.1.3, < 2.0)
19
19
  rspec-mocks (2.14.5)
20
+ serialport (1.3.0)
20
21
 
21
22
  PLATFORMS
22
23
  ruby
@@ -27,3 +28,4 @@ DEPENDENCIES
27
28
  net-openvpn!
28
29
  rake
29
30
  rspec
31
+ serialport
data/README.md CHANGED
@@ -16,6 +16,8 @@ server.save
16
16
 
17
17
  ### Host Configuration (read: client-config-directive)
18
18
 
19
+ **Technically this is a client**, and I should have named it `Client` instead of `Host`, but I don't want to break existing apps using this gem. So I aliased `Net::Openvpn::Client` to `Net::Openvpn::Host` so you can use the former. However, objects returned by initialization will still be of the type `Net::Openvpn::Host`.
20
+
19
21
  This is how you set the IP address of a VPN host with the hostname `optimus`:
20
22
 
21
23
  ```ruby
@@ -25,6 +27,12 @@ host.network = 10.8.0.0
25
27
  host.save
26
28
  ```
27
29
 
30
+ You can also use a ActiveModel kind of initialization to allow you to create a host in one fell swoop:
31
+
32
+ ```ruby
33
+ Net::Openvpn::Host.new("optimus", ip: "10.8.0.10", network: "10.8.0.0").save
34
+ ```
35
+
28
36
  This would create a file at `/etc/openvpn/ccd/optimus` containing the following:
29
37
 
30
38
  ```
@@ -33,6 +41,17 @@ ifconfig-push 10.8.0.24 10.8.0.0
33
41
 
34
42
  So that any host connecting to the VPN with a hostname of `optimus` get assigned `10.8.0.24`.
35
43
 
44
+ There are also some other handy methods on the host object:
45
+
46
+ ```ruby
47
+ host.file # where is the file kept?
48
+ host.remove # get rid of the host (delete the file)
49
+ host.exist? # does the file exist?
50
+ host.new? # has it been saved yet?
51
+ host.ip # what is the ip of this host
52
+ host.network # what is the network of this host
53
+ ```
54
+
36
55
  ## Rails Permissions
37
56
 
38
57
  If you are running rails and you want to give the rails user access, you could do it like this:
data/Rakefile CHANGED
@@ -6,3 +6,20 @@ RSpec::Core::RakeTask.new
6
6
 
7
7
  task :default => :spec
8
8
  task :test => :spec
9
+
10
+ task :console do
11
+ begin
12
+ # use Pry if it exists
13
+ require 'pry'
14
+ require 'net/openvpn'
15
+ Pry.start
16
+ rescue LoadError
17
+ require 'irb'
18
+ require 'irb/completion'
19
+ require 'net/openvpn'
20
+ ARGV.clear
21
+ IRB.start
22
+ end
23
+ end
24
+
25
+ task :c => :console
@@ -1,3 +1,5 @@
1
+ require 'fileutils'
2
+
1
3
  module Net
2
4
  module Openvpn
3
5
  class ClientConfig
@@ -36,8 +38,8 @@ module Net
36
38
  end
37
39
 
38
40
  def remove
39
- return true if File.exist? path
40
- File.delete path
41
+ return true if !File.exist? path
42
+ FileUtils.rm path
41
43
  end
42
44
 
43
45
  def save
@@ -2,9 +2,17 @@ module Net
2
2
  module Openvpn
3
3
  class Host
4
4
 
5
- def initialize(hostname)
5
+ attr_accessor :ip, :network
6
+ attr_reader :hostname
7
+ alias_method :name, :hostname
8
+
9
+ def initialize(hostname, **params)
6
10
  @hostname = hostname
7
11
  @config = Net::Openvpn::ClientConfig.new(@hostname)
12
+
13
+ params.each do |key, value|
14
+ self.send("#{key}=".to_sym, value)
15
+ end
8
16
  end
9
17
 
10
18
  def generate_key
@@ -15,15 +23,17 @@ module Net
15
23
 
16
24
  end
17
25
 
18
- def ip=(ip)
19
- @config.ip = ip
26
+ def file
27
+ @config.path
20
28
  end
21
29
 
22
- def network=(network)
23
- @config.network = network
30
+ def path
31
+ @config.path
24
32
  end
25
33
 
26
34
  def save
35
+ @config.ip = ip
36
+ @config.network = network
27
37
  @config.save
28
38
  end
29
39
 
@@ -35,6 +45,12 @@ module Net
35
45
  !@config.exists?
36
46
  end
37
47
 
48
+ def exist?
49
+ @config.exists?
50
+ end
51
+
38
52
  end
39
53
  end
40
- end
54
+ end
55
+
56
+ Net::Openvpn::Client = Net::Openvpn::Host
@@ -1,5 +1,5 @@
1
1
  module Net
2
2
  module Openvpn
3
- VERSION = "0.2.1"
3
+ VERSION = "0.3"
4
4
  end
5
5
  end
@@ -20,5 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.add_development_dependency "rake"
21
21
  spec.add_development_dependency "rspec"
22
22
  spec.add_development_dependency "fakefs"
23
+ spec.add_development_dependency "serialport"
24
+
23
25
  end
24
26
 
@@ -2,54 +2,81 @@ require 'spec_helper'
2
2
  require 'fileutils'
3
3
 
4
4
  describe Net::Openvpn::Host, fakefs: true do
5
-
6
- let(:network) { "10.8.0.0" }
7
- let(:ip) { "10.8.0.10" }
5
+ let(:hostname) { "test" }
6
+ let(:network) { "10.8.0.0" }
7
+ let(:ip) { "10.8.0.10" }
8
+ subject(:host) { Net::Openvpn::Host.new(hostname, ip: ip, network: network) }
8
9
 
9
10
  before(:each) do
10
11
  FileUtils.mkdir_p("/etc/openvpn/ccd")
11
12
  end
12
13
 
13
- def create_a_host
14
- host = Net::Openvpn.host("test")
15
- host.ip = ip
16
- host.network = network
14
+ it "should create a host client configuration" do
15
+ expect(host).to_not exist
17
16
  host.save
18
- host
17
+ expect(host).to exist
19
18
  end
20
19
 
21
- it "should create a host client configuration" do
22
- create_a_host
20
+ it "should remove a host client configuration" do
21
+ host.save
22
+ expect(host).to exist
23
+ host.remove
24
+ expect(host).to_not exist
25
+ end
23
26
 
24
- expect(File.exist?("/etc/openvpn/ccd/test")).to be_true
27
+ it "should have the correct info in the CCD file" do
28
+ host.save
29
+ expect(File.read host.file).to include ip
30
+ expect(File.read host.file).to include network
25
31
  end
26
32
 
27
- it "should remove a host client configuration" do
28
- host = create_a_host
33
+ it "should be new when it hasn't been saved" do
34
+ expect(host).to be_new
35
+ end
29
36
 
30
- host.remove
31
- expect(File.exist?("/etc/openvpn/ccd/test")).to be_false
37
+ it "should not be new when it has been saved" do
38
+ host.save
39
+ expect(host).to_not be_new
32
40
  end
33
41
 
34
- it "should have the correct info in the CCD file" do
35
- host = create_a_host
42
+ it "should assign the ip" do
43
+ ip = "10.10.0.10"
44
+ host.ip = ip
45
+ expect(host.ip).to eq ip
46
+ end
36
47
 
37
- expect(File.read("/etc/openvpn/ccd/test")).to include ip
38
- expect(File.read("/etc/openvpn/ccd/test")).to include network
48
+ it "should assign the network" do
49
+ network = "10.10.0.0"
50
+ host.network = network
51
+ expect(host.network).to eq network
39
52
  end
40
53
 
41
- it "should be new when it hasn't been saved" do
42
- host = Net::Openvpn.host("test")
54
+ it "should save the ip to the file" do
55
+ host.save
56
+ ip = "10.10.0.10"
43
57
  host.ip = ip
58
+ host.save
59
+ expect(File.read host.file).to include ip
60
+ end
61
+
62
+ it "should save the network to the file" do
63
+ host.save
64
+ network = "10.10.0.0"
44
65
  host.network = network
66
+ host.save
67
+ expect(File.read host.file).to include network
68
+ end
45
69
 
46
- expect(host.new?).to be_true
70
+ it "should return the name of the host" do
71
+ expect(host.name).to eq hostname
47
72
  end
48
73
 
49
- it "should not be new when it has been saved" do
50
- host = create_a_host
74
+ it "should return the ip of the host" do
75
+ expect(host.ip).to eq ip
76
+ end
51
77
 
52
- expect(host.new?).to be_false
78
+ it "should return the network of the host" do
79
+ expect(host.network).to eq network
53
80
  end
54
81
 
55
82
  end
metadata CHANGED
@@ -1,69 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-openvpn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert McLeod
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-04 00:00:00.000000000 Z
11
+ date: 2014-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.5'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: fakefs
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: serialport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
83
  description: Net-Openvpn is an openvpn library for configuring a local OpenVPN service
@@ -73,6 +87,7 @@ executables: []
73
87
  extensions: []
74
88
  extra_rdoc_files: []
75
89
  files:
90
+ - ".gitignore"
76
91
  - Gemfile
77
92
  - Gemfile.lock
78
93
  - README.md
@@ -96,17 +111,17 @@ require_paths:
96
111
  - lib
97
112
  required_ruby_version: !ruby/object:Gem::Requirement
98
113
  requirements:
99
- - - ! '>='
114
+ - - ">="
100
115
  - !ruby/object:Gem::Version
101
116
  version: '0'
102
117
  required_rubygems_version: !ruby/object:Gem::Requirement
103
118
  requirements:
104
- - - ! '>='
119
+ - - ">="
105
120
  - !ruby/object:Gem::Version
106
121
  version: '0'
107
122
  requirements: []
108
123
  rubyforge_project:
109
- rubygems_version: 2.2.1
124
+ rubygems_version: 2.2.2
110
125
  signing_key:
111
126
  specification_version: 4
112
127
  summary: Local OpenVPN configurator