vpn 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +2 -0
- data/README.md +12 -0
- data/Rakefile +5 -0
- data/bin/vpn +90 -38
- data/vpn.gemspec +4 -2
- metadata +34 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3b30e5e0698a20cfbd6cae0492c65cafe1e7f3b
|
4
|
+
data.tar.gz: 351e5f0f442a281c53e2309258a17b44c07b3c82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fd83ca2d47d794c70039313d3943f1386b6feeb44c3b8aec7353aa3dfadebda1619701589b583628ec856eda8076fc4c9493beaa3d7bb004a92d23391756db0
|
7
|
+
data.tar.gz: f3d03676cb0f25cefa1b048dd53efb5b924c3de4d61b3000a6e6bcdab72dfc6a4a9855d5f221acad424b1a150bda84f72aa79588dcfc62e98685f51c86de3ae3
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
CHANGED
@@ -1,14 +1,18 @@
|
|
1
1
|
# vpn
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/vpn.png)](http://badge.fury.io/rb/vpn)
|
3
|
+
[![Build Status](https://travis-ci.org/ronen/vpn.svg?branch=master)](https://travis-ci.org/ronen/vpn)
|
3
4
|
|
4
5
|
A shell command for making vpn connections. It's a convenience wrapper around [openconnect](http://www.infradead.org/openconnect/), in which you set up a configuration file with connection details, then just "vpn up" to connect.
|
5
6
|
|
7
|
+
Requires ruby version >= 2.1.0
|
8
|
+
|
6
9
|
## Usage
|
7
10
|
|
8
11
|
```sh
|
9
12
|
$ vpn up [site]
|
10
13
|
$ vpn down
|
11
14
|
$ vpn reset # if your lan connection glitches
|
15
|
+
$ vpn status # tells you if vpn is up or down
|
12
16
|
```
|
13
17
|
|
14
18
|
The script will prompt for your vpn password on the site as well as for the sudo password on your machine (if needed).
|
@@ -42,6 +46,14 @@ mycompany:
|
|
42
46
|
|
43
47
|
Each entry must specify a `server`. All other fields get passed as options to openconnect -- see `$ man openconnect` to find out what they are. Options that don't take values can be specified using the value `true`.
|
44
48
|
|
49
|
+
## History
|
50
|
+
|
51
|
+
* 0.2.0 - add
|
52
|
+
* 0.1.0 - Initial release
|
53
|
+
|
54
|
+
## Last but not least...
|
55
|
+
|
56
|
+
Comments, suggestions, and pull requests are all welcome!
|
45
57
|
|
46
58
|
|
47
59
|
|
data/Rakefile
CHANGED
data/bin/vpn
CHANGED
@@ -1,55 +1,107 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'pathname'
|
4
|
+
require 'shellwords'
|
4
5
|
require 'yaml'
|
5
6
|
|
6
7
|
CONFIG_FILENAME = "~/.vpn"
|
7
8
|
PIDFILE = "/tmp/openconnect.pid"
|
8
9
|
|
9
|
-
|
10
|
-
"background" => true,
|
11
|
-
"passwd-on-stdin" => true,
|
12
|
-
"pid-file" => PIDFILE,
|
13
|
-
"quiet" => true,
|
14
|
-
}
|
10
|
+
class Vpn
|
15
11
|
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
DEFAULTS = {
|
13
|
+
"background" => true,
|
14
|
+
"passwd-on-stdin" => true,
|
15
|
+
"pid-file" => PIDFILE,
|
16
|
+
"quiet" => true,
|
17
|
+
}
|
18
|
+
|
19
|
+
def up(config)
|
20
|
+
abort "vpn is already up" if connected?
|
21
|
+
opts = DEFAULTS.merge config.opts
|
22
|
+
server = opts.delete("server") or abort "#{config.site} in #{config.filename} must specify a server"
|
23
|
+
args = opts.map{ |key, val| val == true ? "--#{key}" : "--#{key}=#{Shellwords.escape val}"}.join(' ')
|
24
|
+
sudo "openconnect #{args} #{server} <<< #{Shellwords.escape (passwd config.site)}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def down
|
28
|
+
abort "vpn is already down" unless connected?
|
29
|
+
kill(:HUP)
|
30
|
+
end
|
31
|
+
|
32
|
+
def reset
|
33
|
+
abort "vpn is not up" unless connected?
|
34
|
+
kill(:USR2)
|
35
|
+
end
|
36
|
+
|
37
|
+
def connected?
|
38
|
+
!!pid
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def pid
|
44
|
+
@pid ||= begin
|
45
|
+
pid = File.read(PIDFILE).to_i # get process id
|
46
|
+
Process.kill 0, pid # probe process
|
47
|
+
pid
|
48
|
+
rescue Errno::ENOENT # no PIDFILE
|
49
|
+
nil
|
50
|
+
rescue Errno::EPERM # process exists but no permission (because of sudo)
|
51
|
+
pid
|
52
|
+
rescue SystemCallError => e # no process
|
53
|
+
nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def sudo(cmd)
|
58
|
+
system "sudo -p 'sudo password: ' #{cmd}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def kill(signal)
|
62
|
+
sudo "kill -s #{signal} #{pid}"
|
63
|
+
end
|
64
|
+
|
65
|
+
def passwd(site)
|
66
|
+
$stdout.write "#{site} vpn password: "
|
67
|
+
$stdout.flush
|
68
|
+
begin
|
69
|
+
system "stty -echo"
|
70
|
+
@password = $stdin.gets.chomp
|
71
|
+
ensure
|
72
|
+
puts "\n"
|
73
|
+
system "stty echo"
|
74
|
+
end
|
75
|
+
end
|
19
76
|
|
20
|
-
def passwd(site)
|
21
|
-
STDOUT.write "#{site} vpn password: "
|
22
|
-
STDOUT.flush
|
23
|
-
begin
|
24
|
-
system "stty -echo"
|
25
|
-
@password = STDIN.gets.chomp
|
26
|
-
ensure
|
27
|
-
system "stty echo"
|
28
|
-
end
|
29
|
-
end
|
30
77
|
|
31
|
-
def sudo(cmd)
|
32
|
-
system "sudo -p 'sudo password: ' #{cmd}"
|
33
78
|
end
|
34
79
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
80
|
+
class ConfigData
|
81
|
+
attr_reader :site, :opts, :filename
|
82
|
+
def initialize(site)
|
83
|
+
@filename = CONFIG_FILENAME
|
84
|
+
begin
|
85
|
+
@config = YAML.load Pathname(@filename).expand_path.read
|
86
|
+
rescue Errno::ENOENT => e
|
87
|
+
abort "Could not open config file #{@filename}"
|
88
|
+
end
|
89
|
+
@site = site || @config.keys.first
|
90
|
+
@config.include? @site or abort "#{@site} not listed in #{CONFIG_FILENAME}"
|
91
|
+
@opts = @config[@site]
|
40
92
|
end
|
93
|
+
|
41
94
|
end
|
95
|
+
|
96
|
+
if __FILE__ == $0
|
42
97
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
when "down" then sudo "kill -s HUP #{pid}"
|
53
|
-
when "reset" then sudo "kill -s USR2 #{pid}"
|
54
|
-
else abort "usage: #{$0} up [site]|down|reset"
|
98
|
+
vpn = Vpn.new
|
99
|
+
|
100
|
+
case ARGV.shift
|
101
|
+
when "up" then vpn.up ConfigData.new(ARGV.shift)
|
102
|
+
when "down" then vpn.down
|
103
|
+
when "reset" then vpn.reset
|
104
|
+
when "status" then puts "vpn is #{vpn.connected? ? "up" : "down" }"
|
105
|
+
else abort "usage: #{File.basename $0} up [site]|down|reset|status"
|
106
|
+
end
|
55
107
|
end
|
data/vpn.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "vpn"
|
5
|
-
spec.version = "0.
|
5
|
+
spec.version = "0.2.0"
|
6
6
|
spec.authors = ["ronen barzel"]
|
7
7
|
spec.email = ["ronen@barzel.org"]
|
8
8
|
|
@@ -15,6 +15,8 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.bindir = "bin"
|
16
16
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
17
|
|
18
|
-
spec.add_development_dependency "bundler", "~> 1.
|
18
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
19
19
|
spec.add_development_dependency "rake", "~> 10.0"
|
20
|
+
spec.add_development_dependency "rspec", "~> 3.3"
|
21
|
+
spec.add_development_dependency "simplecov", "~> 0.10"
|
20
22
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vpn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ronen barzel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.6'
|
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
|
-
version: '1.
|
26
|
+
version: '1.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.10'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.10'
|
41
69
|
description: Lets you set up one or more vpn configurations, then connect via `vpn
|
42
70
|
up` and `vpn down`.
|
43
71
|
email:
|
@@ -48,6 +76,8 @@ extensions: []
|
|
48
76
|
extra_rdoc_files: []
|
49
77
|
files:
|
50
78
|
- ".gitignore"
|
79
|
+
- ".travis.yml"
|
80
|
+
- Gemfile
|
51
81
|
- LICENSE.txt
|
52
82
|
- README.md
|
53
83
|
- Rakefile
|