vipnet_getter 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/vipnet_getter.rb +98 -0
- metadata +59 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ea7c82d98f3f9cdd3e8a65e4065d9dd24cda6cb9
|
4
|
+
data.tar.gz: 64816099b5f465ce1383c1dc2e694d4027743df1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b111c9a872efd3b0553287460335e10592a3e7c8cbbc7953693ec7df2e9dd6d9bab68b95b53ccde913bebe7b1fc45db5bfd2d46814b80bc8f71b057b8cbfaefa
|
7
|
+
data.tar.gz: edc7e640683983ec7062ee7002fc7e188c0d07358b509ac8402039debb3dfa93b24838973211b401c36e9b10bee4e5a088539310311ad8606fd20be4f169db2e
|
@@ -0,0 +1,98 @@
|
|
1
|
+
class VipnetGetter
|
2
|
+
ENTER_KEYCODE = 13
|
3
|
+
PGDN_KEYCODE = 34
|
4
|
+
|
5
|
+
def self.iplirconf(params)
|
6
|
+
hostname = params[:hostname]
|
7
|
+
password = params[:password]
|
8
|
+
output_file_path = params[:output_file_path]
|
9
|
+
|
10
|
+
username = "vipnet"
|
11
|
+
# adding digest to known_hosts if needed
|
12
|
+
require "ruby_expect"
|
13
|
+
exp_ssh_digest = RubyExpect::Expect.spawn("/usr/bin/ssh #{username}@#{hostname}")
|
14
|
+
exp_ssh_digest.timeout = 3
|
15
|
+
exp_ssh_digest.procedure do
|
16
|
+
each do
|
17
|
+
expect /Are you sure you want to continue connecting \(yes\/no\)\?\s*$/ do
|
18
|
+
send "yes"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
iplirconf = String.new
|
24
|
+
logged = false
|
25
|
+
|
26
|
+
# logging
|
27
|
+
exp = RubyExpect::Expect.spawn("/usr/bin/ssh #{username}@#{hostname}")
|
28
|
+
exp.timeout = 3
|
29
|
+
exp.procedure do
|
30
|
+
each do
|
31
|
+
expect /password:\s*$/ do
|
32
|
+
send password
|
33
|
+
puts "entering password"
|
34
|
+
end
|
35
|
+
# for some reason if pw is not incorrect, script wait for timeout and don't expect ">" for "iplir show config"
|
36
|
+
# thus, commented code below doesn't work
|
37
|
+
# expect /Permission denied, please try again/ do
|
38
|
+
# puts "permission denied"
|
39
|
+
# end
|
40
|
+
expect />\s*$/ do
|
41
|
+
send "iplir show config"
|
42
|
+
# when running with cron, message appears:
|
43
|
+
# WARNING: terminal is not fully functional
|
44
|
+
#- (press RETURN)
|
45
|
+
send ENTER_KEYCODE
|
46
|
+
logged = true
|
47
|
+
puts "iplir show config"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
return nil if !logged
|
51
|
+
|
52
|
+
# reading iplirconf until "default= auto" line appeared
|
53
|
+
retflag = false
|
54
|
+
while !retflag
|
55
|
+
retval = any do
|
56
|
+
expect /.*:/m do
|
57
|
+
iplirconf += last_match.to_s
|
58
|
+
last_match.to_s.split("\n").each do |line|
|
59
|
+
if line =~ /default= auto/
|
60
|
+
retflag = true
|
61
|
+
break
|
62
|
+
end
|
63
|
+
end
|
64
|
+
send PGDN_KEYCODE
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# remove regular trash caused by "send PGDN_KEYCODE"
|
71
|
+
iplirconf = iplirconf.gsub(":\e[K\r\e[K:\e[K3\b3\e[K4\b4\r\e[K", "")
|
72
|
+
# remove trash in the beginning
|
73
|
+
iplirconf = iplirconf.gsub("iplir show config\r\n\e[?1049h\e[?1h\e=\r", "")
|
74
|
+
# remove trash in the end
|
75
|
+
iplirconf = iplirconf[/.*default= auto\r\n/m, 0]
|
76
|
+
# replace \r\n by \n
|
77
|
+
iplirconf = iplirconf.gsub("\r", "")
|
78
|
+
# remove trash caused by send ENTER_KEYCODE
|
79
|
+
iplirconf = iplirconf.gsub(":\x1B[K\x1B[K:\x1B[K1\x081\x1B[K3\x083\x1B[K", "")
|
80
|
+
# remove trash caused by "terminal is not fully functional" issue when running script with cron
|
81
|
+
iplirconf = iplirconf.gsub("::3\x083", "")
|
82
|
+
iplirconf = iplirconf.gsub("4\x084", "")
|
83
|
+
iplirconf = iplirconf.gsub("iplir show config\nWARNING: terminal is not fully functional\n- (press RETURN):1\x081", "")
|
84
|
+
iplirconf = iplirconf.gsub("4\x084", "")
|
85
|
+
# add return if necessary
|
86
|
+
iplirconf += "\n" if iplirconf[-4..-1] != "\n\n"
|
87
|
+
if output_file_path
|
88
|
+
File.open(output_file_path, 'w') { |f| f.write(iplirconf) }
|
89
|
+
output_file_path
|
90
|
+
else
|
91
|
+
require "tempfile"
|
92
|
+
iplirconf_file = Tempfile.new("iplirconf")
|
93
|
+
iplirconf_file.write(iplirconf)
|
94
|
+
iplirconf_file.flush
|
95
|
+
iplirconf_file.path
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vipnet_getter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander Morozov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruby_expect
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1'
|
27
|
+
description: Allows to get configuration files like iplir.conf (and more) from ViPNet
|
28
|
+
products such as HW1000; no "enable" and "admin escape" needed.
|
29
|
+
email: ntcomp12@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- lib/vipnet_getter.rb
|
35
|
+
homepage: https://github.com/kengho/vipnet_getter
|
36
|
+
licenses:
|
37
|
+
- MIT
|
38
|
+
metadata: {}
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 2.5.1
|
56
|
+
signing_key:
|
57
|
+
specification_version: 4
|
58
|
+
summary: Gem for getting data from ViPNet products
|
59
|
+
test_files: []
|