vipnet_getter 0.2 → 0.3
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 +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02791c509ed3cb9d56085ff5b6181e3f2d1c3989
|
4
|
+
data.tar.gz: b3844f588742eebe97a6daf5d195ca7a4db3f6ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b0dcf0252d31b90930080fe7206fe30f4f5464542429ae371d5ce9669498a5f558f0b030ab32ba460b8d2db9599d38407afb88298e0c210ea7d2da0f7adc0b9
|
7
|
+
data.tar.gz: facdced06f47a81cd910b98c9c8020e3eb28dca353a39aa12d0315d8b34825046d60fb13235c56632d2418d38282d8a3a81f37e58e87d81fa590f1353b269749
|
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.3'
|
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
|
@@ -52,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
52
|
version: '0'
|
53
53
|
requirements: []
|
54
54
|
rubyforge_project:
|
55
|
-
rubygems_version: 2.
|
55
|
+
rubygems_version: 2.6.6
|
56
56
|
signing_key:
|
57
57
|
specification_version: 4
|
58
58
|
summary: Gem for getting data from ViPNet™ products
|