vipnet_getter 0.11 → 0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vipnet_getter.rb +52 -38
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6afa6e90cb797a0e96abd0ccd2717549a4120cc
|
4
|
+
data.tar.gz: 8e09d23854f0cfa3518f2ff5430ae6a36f71d2bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f2a8db6d7f17ac66ea63a2764ca93898201e5182bd0a02811c7f02ce2ef95e45651a638e64b5907aadbd23eacb8a694ca1ec034924f834c74340da650d04277
|
7
|
+
data.tar.gz: 631ace20bbdc0708ec467349b21b860c7cf10b8a027f94cd2d05ea11f75e591c5009ef6a0eb213a598ca55022b8e0d7f046e824621f60629caf9fd1054dbe70a
|
data/lib/vipnet_getter.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
class VipnetGetter
|
2
4
|
ENTER_KEYCODE = 13
|
3
|
-
PGDN_KEYCODE
|
5
|
+
PGDN_KEYCODE = 34
|
4
6
|
|
5
7
|
def self.iplirconf(params)
|
6
8
|
hostname = params[:hostname]
|
@@ -8,7 +10,7 @@ class VipnetGetter
|
|
8
10
|
username = params[:username] || "vipnet"
|
9
11
|
output_file_path = params[:output_file_path]
|
10
12
|
|
11
|
-
#
|
13
|
+
# Adding digest to "known_hosts" if needed.
|
12
14
|
require "ruby_expect"
|
13
15
|
exp_ssh_digest = RubyExpect::Expect.spawn("/usr/bin/ssh #{username}@#{hostname}")
|
14
16
|
exp_ssh_digest.timeout = 3
|
@@ -20,43 +22,52 @@ class VipnetGetter
|
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
23
|
-
iplirconf = String.new
|
24
25
|
logged = false
|
26
|
+
puts "Logging to #{username}@#{hostname}..."
|
25
27
|
|
26
|
-
#
|
27
|
-
|
28
|
+
# "TERM=xterm" solves "WARNING: terminal is not fully functional" issue when running script with cron
|
29
|
+
# TODO: test.
|
30
|
+
exp = RubyExpect::Expect.spawn("TERM=xterm luit -encoding KOI8-R /usr/bin/ssh #{username}@#{hostname}")
|
28
31
|
exp.timeout = 3
|
32
|
+
iplirconf_content = ""
|
29
33
|
exp.procedure do
|
30
34
|
each do
|
31
35
|
expect /password:\s*$/ do
|
32
36
|
send password
|
33
|
-
puts "
|
37
|
+
puts "Entering password..."
|
34
38
|
end
|
35
|
-
|
36
|
-
#
|
39
|
+
|
40
|
+
# For some reason, if password is incorrect, script waits for timeout
|
41
|
+
# and don't expect ">" for "iplir show config".
|
42
|
+
# Thus, commented code below doesn't work
|
37
43
|
# expect /Permission denied, please try again/ do
|
38
|
-
#
|
44
|
+
# puts "permission denied"
|
39
45
|
# end
|
46
|
+
|
40
47
|
expect />\s*$/ do
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
48
|
+
command = "iplir show config"
|
49
|
+
send command
|
50
|
+
puts command
|
51
|
+
|
52
|
+
# When running with cron, message appears:
|
53
|
+
# "WARNING: terminal is not fully functional
|
54
|
+
# - (press RETURN)"
|
55
|
+
# So we imitate pressing <Enter>.
|
45
56
|
send ENTER_KEYCODE
|
46
57
|
logged = true
|
47
|
-
puts "iplir show config"
|
48
58
|
end
|
49
59
|
end
|
50
|
-
return nil
|
60
|
+
return nil unless logged
|
51
61
|
|
52
|
-
#
|
62
|
+
# Reading iplirconf until "default= .*" or /tunneldefault= .*/ lines appeared.
|
63
|
+
# ("default" for vipnet v3 and "tunneldefault" for vipnet v4.)
|
53
64
|
retflag = false
|
54
65
|
while !retflag
|
55
66
|
retval = any do
|
56
67
|
expect /.*:/m do
|
57
|
-
|
68
|
+
iplirconf_content << last_match.to_s
|
58
69
|
last_match.to_s.split("\n").each do |line|
|
59
|
-
if line =~
|
70
|
+
if line =~ /^default=\s.*/ || line =~ /^tunneldefault=\s.*/
|
60
71
|
retflag = true
|
61
72
|
break
|
62
73
|
end
|
@@ -67,30 +78,33 @@ class VipnetGetter
|
|
67
78
|
end
|
68
79
|
end
|
69
80
|
|
70
|
-
#
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
81
|
+
# Encode and remove unsupported characters.
|
82
|
+
iplirconf_content.force_encoding("UTF-8")
|
83
|
+
.gsub!("\r", "")
|
84
|
+
.gsub!(/[^\w\s\p{Cyrillic}=\(\)\[\]:\.\,@\#$%\^\-!]/, "")
|
85
|
+
|
86
|
+
# Remove trash in the beginning.
|
87
|
+
iplirconf_content.gsub!(/iplir show config.*1h=/m, "")
|
88
|
+
.gsub!("[7moptvipnetuseriplir.conf[27m[K[K:[K11[K33[K", "")
|
89
|
+
|
90
|
+
# Remove trash in the middle.
|
91
|
+
iplirconf_content.gsub!(/\[K\d+\[K\d+\[K/, "") # [K33[K44[K
|
92
|
+
iplirconf_content.gsub!(/:\[K\[K:/, "") # :[K[K:
|
93
|
+
|
94
|
+
# Remove trash in the end.
|
95
|
+
iplirconf_content.gsub!(/\[7m\(END\).*\[K\[K:/, "")
|
96
|
+
|
97
|
+
# Remove trailing spaces and add carriage return.
|
98
|
+
iplirconf_content.strip!
|
99
|
+
iplirconf_content << "\n\n"
|
100
|
+
|
87
101
|
if output_file_path
|
88
|
-
File.open(output_file_path,
|
102
|
+
File.open(output_file_path, "w:KOI8-R") { |f| f.write(iplirconf_content) }
|
89
103
|
output_file_path
|
90
104
|
else
|
91
105
|
require "tempfile"
|
92
|
-
iplirconf_file = Tempfile.new("iplirconf")
|
93
|
-
iplirconf_file.write(
|
106
|
+
iplirconf_file = Tempfile.new("iplirconf", encoding: "KOI8-R")
|
107
|
+
iplirconf_file.write(iplirconf_content)
|
94
108
|
iplirconf_file.flush
|
95
109
|
iplirconf_file.path
|
96
110
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vipnet_getter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.12'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Morozov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby_expect
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1'
|
27
|
-
description: Allows to get configuration files like iplir.conf (and more) from ViPNet
|
27
|
+
description: Allows to get configuration files like iplir.conf (and more) from ViPNet™
|
28
28
|
products such as HW1000; no "enable" and "admin escape" needed.
|
29
29
|
email: ntcomp12@gmail.com
|
30
30
|
executables: []
|
@@ -55,5 +55,5 @@ rubyforge_project:
|
|
55
55
|
rubygems_version: 2.6.6
|
56
56
|
signing_key:
|
57
57
|
specification_version: 4
|
58
|
-
summary: Gem for getting data from ViPNet products
|
58
|
+
summary: Gem for getting data from ViPNet™ products
|
59
59
|
test_files: []
|