vipnet_getter 0.3 → 0.11

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vipnet_getter.rb +38 -52
  3. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 02791c509ed3cb9d56085ff5b6181e3f2d1c3989
4
- data.tar.gz: b3844f588742eebe97a6daf5d195ca7a4db3f6ad
3
+ metadata.gz: 53175c56a11abe74e7481275a13ca3070e37e050
4
+ data.tar.gz: b2e9f65e4dfdc39f3861ef460a3bb27ddd026ec6
5
5
  SHA512:
6
- metadata.gz: 0b0dcf0252d31b90930080fe7206fe30f4f5464542429ae371d5ce9669498a5f558f0b030ab32ba460b8d2db9599d38407afb88298e0c210ea7d2da0f7adc0b9
7
- data.tar.gz: facdced06f47a81cd910b98c9c8020e3eb28dca353a39aa12d0315d8b34825046d60fb13235c56632d2418d38282d8a3a81f37e58e87d81fa590f1353b269749
6
+ metadata.gz: 67e0425e2875304e96ec3c1f53e7d5988faaac767187468c879c9ea3e51cf6fd07660dfeaa1b8ee72c71511502045a38c733414d13a5bf0f03e961f4f6fcb6c8
7
+ data.tar.gz: de3f14189c75a4c8f5f3b5f56d6c2e4a6f838e4ec948b676c07f3c988d13472fbb3172ff391e012699c21bccc3af3dc838a9b8514d8655a55f13fbe71e924820
data/lib/vipnet_getter.rb CHANGED
@@ -1,8 +1,6 @@
1
- # encoding: UTF-8
2
-
3
1
  class VipnetGetter
4
2
  ENTER_KEYCODE = 13
5
- PGDN_KEYCODE = 34
3
+ PGDN_KEYCODE = 34
6
4
 
7
5
  def self.iplirconf(params)
8
6
  hostname = params[:hostname]
@@ -10,7 +8,7 @@ class VipnetGetter
10
8
  username = params[:username] || "vipnet"
11
9
  output_file_path = params[:output_file_path]
12
10
 
13
- # Adding digest to "known_hosts" if needed.
11
+ # adding digest to known_hosts if needed
14
12
  require "ruby_expect"
15
13
  exp_ssh_digest = RubyExpect::Expect.spawn("/usr/bin/ssh #{username}@#{hostname}")
16
14
  exp_ssh_digest.timeout = 3
@@ -22,52 +20,43 @@ class VipnetGetter
22
20
  end
23
21
  end
24
22
 
23
+ iplirconf = String.new
25
24
  logged = false
26
- puts "Logging to #{username}@#{hostname}..."
27
25
 
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}")
26
+ # logging
27
+ exp = RubyExpect::Expect.spawn("/usr/bin/ssh #{username}@#{hostname}")
31
28
  exp.timeout = 3
32
- iplirconf_content = ""
33
29
  exp.procedure do
34
30
  each do
35
31
  expect /password:\s*$/ do
36
32
  send password
37
- puts "Entering password..."
33
+ puts "entering password"
38
34
  end
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
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
43
37
  # expect /Permission denied, please try again/ do
44
- # puts "permission denied"
38
+ # puts "permission denied"
45
39
  # end
46
-
47
40
  expect />\s*$/ do
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>.
41
+ send "iplir show config"
42
+ # when running with cron, message appears:
43
+ # WARNING: terminal is not fully functional
44
+ #- (press RETURN)
56
45
  send ENTER_KEYCODE
57
46
  logged = true
47
+ puts "iplir show config"
58
48
  end
59
49
  end
60
- return nil unless logged
50
+ return nil if !logged
61
51
 
62
- # Reading iplirconf until "default= .*" or /tunneldefault= .*/ lines appeared.
63
- # ("default" for vipnet v3 and "tunneldefault" for vipnet v4.)
52
+ # reading iplirconf until "default= auto" line appeared
64
53
  retflag = false
65
54
  while !retflag
66
55
  retval = any do
67
56
  expect /.*:/m do
68
- iplirconf_content << last_match.to_s
57
+ iplirconf += last_match.to_s
69
58
  last_match.to_s.split("\n").each do |line|
70
- if line =~ /^default=\s.*/ || line =~ /^tunneldefault=\s.*/
59
+ if line =~ /default= auto/
71
60
  retflag = true
72
61
  break
73
62
  end
@@ -78,33 +67,30 @@ class VipnetGetter
78
67
  end
79
68
  end
80
69
 
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
-
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"
101
87
  if output_file_path
102
- File.open(output_file_path, "w:KOI8-R") { |f| f.write(iplirconf_content) }
88
+ File.open(output_file_path, 'w') { |f| f.write(iplirconf) }
103
89
  output_file_path
104
90
  else
105
91
  require "tempfile"
106
- iplirconf_file = Tempfile.new("iplirconf", encoding: "KOI8-R")
107
- iplirconf_file.write(iplirconf_content)
92
+ iplirconf_file = Tempfile.new("iplirconf")
93
+ iplirconf_file.write(iplirconf)
108
94
  iplirconf_file.flush
109
95
  iplirconf_file.path
110
96
  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.3'
4
+ version: '0.11'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Morozov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-24 00:00:00.000000000 Z
11
+ date: 2016-11-09 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: []