lita-openvpnas 0.1.2 → 0.1.3
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +19 -0
- data/Gemfile +1 -1
- data/README.md +2 -0
- data/Rakefile +5 -3
- data/lib/lita-openvpnas.rb +6 -5
- data/lib/lita/handlers/openvpnas.rb +63 -14
- data/lita-openvpnas.gemspec +19 -18
- data/locales/en.yml +9 -0
- data/spec/lita/handlers/openvpnas_spec.rb +1 -1
- data/spec/spec_helper.rb +2 -2
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 988f886884de8479fd6eadab31adaa89b101e60a
|
4
|
+
data.tar.gz: 8c820c371be6d4d0da57c6306b407634aab6888a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec8cc8e0ab4d93ad3dabc7bdd7377b8c3bf005d673c45a7cab3b2df0b18da54503acdb116e463781c12ecdbf0d901aa0f944031686cb7d062849f5d762df03f9
|
7
|
+
data.tar.gz: 7d2898bcf2a54f76f35647134a18df5223569259e906e7fd91cb9ce61237766d44465fa74c6e4479f1b28bda5c5a75e676ec62ef277ce346044f27708b30b613
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Documentation:
|
2
|
+
Exclude:
|
3
|
+
- lib/lita/handlers/openvpnas.rb
|
4
|
+
|
5
|
+
FileName:
|
6
|
+
Exclude:
|
7
|
+
- lib/lita-openvpnas.rb
|
8
|
+
|
9
|
+
Metrics/LineLength:
|
10
|
+
Max: 100
|
11
|
+
|
12
|
+
Metrics/AbcSize:
|
13
|
+
Max: 25
|
14
|
+
|
15
|
+
Metrics/MethodLength:
|
16
|
+
Max: 25
|
17
|
+
|
18
|
+
Metrics/ClassLength:
|
19
|
+
Max: 150
|
data/Gemfile
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'rubocop/rake_task'
|
3
4
|
|
4
5
|
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
RuboCop::RakeTask.new(:rubocop)
|
5
7
|
|
6
|
-
task default: :spec
|
8
|
+
task default: [:spec, :rubocop]
|
data/lib/lita-openvpnas.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
|
-
require
|
1
|
+
require 'lita'
|
2
2
|
require 'rye'
|
3
3
|
require 'timeout'
|
4
|
+
require 'json'
|
4
5
|
|
5
6
|
Lita.load_locales Dir[File.expand_path(
|
6
|
-
File.join(
|
7
|
+
File.join('..', '..', 'locales', '*.yml'), __FILE__
|
7
8
|
)]
|
8
9
|
|
9
|
-
require
|
10
|
+
require 'lita/handlers/openvpnas'
|
10
11
|
|
11
12
|
Lita::Handlers::Openvpnas.template_root File.expand_path(
|
12
|
-
File.join(
|
13
|
-
|
13
|
+
File.join('..', '..', 'templates'),
|
14
|
+
__FILE__
|
14
15
|
)
|
@@ -11,7 +11,16 @@ module Lita
|
|
11
11
|
:openvpn_as_otp_unlock,
|
12
12
|
command: true,
|
13
13
|
help: {
|
14
|
-
|
14
|
+
'openvpn otp unlock <user>' => 'Unlock the OTP Authenticator for an OpenVPN AS user.'
|
15
|
+
}
|
16
|
+
)
|
17
|
+
|
18
|
+
route(
|
19
|
+
/(openvpn)\s+(active)\s+(users)/i,
|
20
|
+
:openvpn_as_active_users,
|
21
|
+
command: true,
|
22
|
+
help: {
|
23
|
+
'openvpn active users' => 'List the currently connected OpenVPN users.'
|
15
24
|
}
|
16
25
|
)
|
17
26
|
|
@@ -20,10 +29,57 @@ module Lita
|
|
20
29
|
ssh_user = config.ssh_user || 'lita'
|
21
30
|
ssh_host = config.hostname
|
22
31
|
path_to_sacli = config.sacli_dir || '/usr/local/openvpn_as/scripts'
|
23
|
-
username = response.user.name.split(/\s/).first
|
24
32
|
|
25
|
-
response.
|
33
|
+
response.reply_with_mention t('replies.otp_unlock.working')
|
34
|
+
|
35
|
+
command = "./sacli -u #{user} --lock 0 GoogleAuthLock 2>&1"
|
36
|
+
exception = over_ssh(ssh_user, ssh_host, command, path_to_sacli)[1]
|
37
|
+
|
38
|
+
if exception
|
39
|
+
response.reply_with_mention t('replies.otp_unlock.failure')
|
40
|
+
response.reply '/code ' + exception.message
|
41
|
+
end
|
42
|
+
|
43
|
+
# build a reply
|
44
|
+
response.reply_with_mention t('replies.otp_unlock.success', user: user)
|
45
|
+
end
|
46
|
+
|
47
|
+
def openvpn_as_active_users(response)
|
48
|
+
ssh_user = config.ssh_user || 'lita'
|
49
|
+
ssh_host = config.hostname
|
50
|
+
path_to_sacli = config.sacli_dir || '/usr/local/openvpn_as/scripts'
|
51
|
+
|
52
|
+
response.reply_with_mention t('replies.active_users.working')
|
26
53
|
|
54
|
+
command = './sacli VPNStatus 2>&1'
|
55
|
+
result, exception = over_ssh(ssh_user, ssh_host, command, path_to_sacli)
|
56
|
+
|
57
|
+
if exception
|
58
|
+
response.reply_with_mention t('replies.active_users.failure')
|
59
|
+
response.reply '/code ' + exception.message
|
60
|
+
end
|
61
|
+
|
62
|
+
# Figure out who is connected and what their client IP is
|
63
|
+
clients = extract_clients(result)
|
64
|
+
|
65
|
+
# build a reply
|
66
|
+
response.reply_with_mention t('replies.active_users.failure', number: clients.size.to_s)
|
67
|
+
response.reply '/code ' + clients.each { |client, ip| "#{client} @ #{ip}" }.join("\n")
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def extract_clients(json_data)
|
73
|
+
clients = []
|
74
|
+
JSON.parse(json_data).values.each do |data|
|
75
|
+
data['client_list'].each do |client|
|
76
|
+
clients << { user: client[0], ip: client[2] }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
clients
|
80
|
+
end
|
81
|
+
|
82
|
+
def over_ssh(_user, _host, command, cwd = '/tmp')
|
27
83
|
exception = nil
|
28
84
|
|
29
85
|
remote = Rye::Box.new(
|
@@ -34,14 +90,14 @@ module Lita
|
|
34
90
|
)
|
35
91
|
|
36
92
|
result = begin
|
37
|
-
Timeout
|
38
|
-
remote.cd
|
93
|
+
Timeout.timeout(60) do
|
94
|
+
remote.cd cwd
|
39
95
|
# Need to use sudo
|
40
96
|
remote.enable_sudo
|
41
97
|
# scary...
|
42
98
|
remote.disable_safe_mode
|
43
99
|
|
44
|
-
remote.execute
|
100
|
+
remote.execute command
|
45
101
|
end
|
46
102
|
rescue Rye::Err => e
|
47
103
|
exception = e
|
@@ -50,14 +106,7 @@ module Lita
|
|
50
106
|
ensure
|
51
107
|
remote.disconnect
|
52
108
|
end
|
53
|
-
|
54
|
-
if exception
|
55
|
-
response.reply_with_mention "That OpenVPN authenticator didn't seem to unlock... ;-("
|
56
|
-
response.reply "/code " + exception.message
|
57
|
-
end
|
58
|
-
|
59
|
-
# build a reply
|
60
|
-
response.reply_with_mention("That OpenVPN authenticator is now available for #{user}!")
|
109
|
+
[result, exception]
|
61
110
|
end
|
62
111
|
|
63
112
|
Lita.register_handler(self)
|
data/lita-openvpnas.gemspec
CHANGED
@@ -1,26 +1,27 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
|
-
spec.name =
|
3
|
-
spec.version =
|
4
|
-
spec.authors = [
|
5
|
-
spec.email = [
|
6
|
-
spec.description =
|
7
|
-
spec.summary =
|
8
|
-
spec.homepage =
|
9
|
-
spec.license =
|
10
|
-
spec.metadata = {
|
2
|
+
spec.name = 'lita-openvpnas'
|
3
|
+
spec.version = '0.1.3'
|
4
|
+
spec.authors = ['Jonathan Gnagy'].sort
|
5
|
+
spec.email = ['jgnagy@knuedge.com']
|
6
|
+
spec.description = 'Some basic OpenVPN Access Server interactions for Lita'
|
7
|
+
spec.summary = 'Allow the Lita bot to handle requests for OpenVPN Access Server tasks'
|
8
|
+
spec.homepage = 'https://github.com/knuedge/lita-openvpnas'
|
9
|
+
spec.license = 'MIT'
|
10
|
+
spec.metadata = { 'lita_plugin_type' => 'handler' }
|
11
11
|
|
12
|
-
spec.files = `git ls-files`.split(
|
12
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
13
13
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
14
14
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
15
|
-
spec.require_paths = [
|
15
|
+
spec.require_paths = ['lib']
|
16
16
|
|
17
|
-
spec.add_runtime_dependency
|
18
|
-
spec.add_runtime_dependency
|
17
|
+
spec.add_runtime_dependency 'lita', '~> 4.7'
|
18
|
+
spec.add_runtime_dependency 'rye'
|
19
19
|
|
20
|
-
spec.add_development_dependency
|
21
|
-
spec.add_development_dependency
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
21
|
+
spec.add_development_dependency 'pry-byebug'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'rack-test'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
25
|
+
spec.add_development_dependency 'rubocop'
|
25
26
|
spec.add_development_dependency 'travis', '~> 1.8'
|
26
27
|
end
|
data/locales/en.yml
CHANGED
@@ -2,3 +2,12 @@ en:
|
|
2
2
|
lita:
|
3
3
|
handlers:
|
4
4
|
openvpnas:
|
5
|
+
replies:
|
6
|
+
otp_unlock:
|
7
|
+
working: let me unlock that user's OpenVPN authenticator for you.
|
8
|
+
failure: That OpenVPN authenticator didn't seem to unlock... ;-(
|
9
|
+
success: "That OpenVPN authenticator is now available for %{user}!"
|
10
|
+
active_users:
|
11
|
+
working: let me see who is connected.
|
12
|
+
failure: The OpenVPN server didn't like my query... ;-(
|
13
|
+
success: "There are %{number} clients connect to the OpenVPN server:"
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'lita-openvpnas'
|
2
|
+
require 'lita/rspec'
|
3
3
|
|
4
4
|
# A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
|
5
5
|
# was generated with Lita 4, the compatibility mode should be left disabled.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-openvpnas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Gnagy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '3.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: travis
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,6 +144,7 @@ extensions: []
|
|
130
144
|
extra_rdoc_files: []
|
131
145
|
files:
|
132
146
|
- ".gitignore"
|
147
|
+
- ".rubocop.yml"
|
133
148
|
- ".travis.yml"
|
134
149
|
- CONTRIBUTING.md
|
135
150
|
- Gemfile
|