ssh-manager 1.1.1 → 1.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59aa22da8f515be9a7fe111618dd3ea02d7e790a
4
- data.tar.gz: e459ee67d54e5a0f2a38ebc429a653eedc3b2397
3
+ metadata.gz: 42ad60fcccaaa39c9aa677635f50e8055d3f3114
4
+ data.tar.gz: fd87b518c5b286678ed6e8f9e1ee552c33a5c212
5
5
  SHA512:
6
- metadata.gz: 3d6016baa8e8264fe02a57c77b301f643293bb27b352093b998a91d9cffd83f38f78b009def347a57d6787b04b8799e9db383f922301ed4a92a6e7d4ff1fdb36
7
- data.tar.gz: 41d3e995cf4b7e39a20d6fb98e0af35f81d4e4a6e0c1fe96eddf24243014a6219b4ec2be17657ff7993f43992e6e86522275a3083eab73cbe2caa77b73ce977f
6
+ metadata.gz: ed798fd1f65a2031fa3bb913afec5933c1a9e022568546bbe758386bf8d5a590323e5e020028a54ac20d75ba44c405fb90e47c4f67c1a07a23847b944cae80f6
7
+ data.tar.gz: f787cd59461fb2e13b259b6f4d7994871c04885c8048a41934c3135269d84a738049abee1a543afaf8efe7aff4fca83f7e054ef9f6a4d697a3d675b6b6f8613e
data/.gitignore CHANGED
@@ -16,3 +16,7 @@ spec/reports
16
16
  test/tmp
17
17
  test/version_tmp
18
18
  tmp
19
+ /idea
20
+ ./idea
21
+ /idea/*
22
+ idea/*
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in ssh-manager.gemspec
4
+ gem 'colorize'
4
5
  gem 'rspec'
5
6
  gem 'sequel'
6
7
  gem 'sqlite3'
@@ -1,4 +1,6 @@
1
1
  require_relative 'db'
2
+ require 'colorize'
3
+ require 'readline'
2
4
  require 'yaml'
3
5
  FileUtils.cp ("#{File.dirname(__FILE__)}/../../../config/settings.yml"), ("#{File.join(Dir.home)}" + '/.config/sshm/') unless File.exists?(("#{File.join(Dir.home)}" + '/.config/sshm/settings.yml'))
4
6
  CONFIG = YAML.load_file("#{File.join(ENV['HOME'])}/.config/sshm/settings.yml")
@@ -106,14 +108,17 @@ module SSH
106
108
  def transfer_key(id)
107
109
  #TODO connect_via
108
110
  #TODO options
109
- connection = DATABASE.get_connection_by_id(id)
110
- user = connection[:user]
111
- user = ENV['USER'] if user == ""
112
- %x(ssh-copy-id #{user}@#{connection[:ip]})
111
+ id.each do |con|
112
+ connection = DATABASE.get_connection_by_id(con)
113
+ user = connection[:user]
114
+ user = ENV['USER'] if user == ""
115
+ %x(ssh-copy-id #{user}@#{connection[:ip]})
116
+ end
113
117
  end
114
118
 
115
119
  def ping(id)
116
- connection = DATABASE.get_connection_by_id(id)
120
+ id.each do |con|
121
+ connection = DATABASE.get_connection_by_id(con)
117
122
  if connection[:connect_via]
118
123
  connect_via = DATABASE.get_connection_by_id(connection[:connect_via])
119
124
  ssh = "ssh #{connect_via[:user]}@#{connect_via[:ip]}"
@@ -121,8 +126,58 @@ module SSH
121
126
  else
122
127
  exec("ping #{connection[:ip]} -c 3")
123
128
  end
129
+ end
124
130
  end
131
+
132
+ def execute_command(id)
133
+ # id.first should be the command
134
+ cmd = id.shift
135
+ id.each do |con|
136
+ connection = DATABASE.get_connection_by_id(con)
137
+ if connection[:connect_via]
138
+ connect_via = DATABASE.get_connection_by_id(connection[:connect_via])
139
+ ssh = "ssh #{connect_via[:user]}@#{connect_via[:ip]}"
140
+ system("#{ssh} #{cmd}")
141
+ else
142
+ ssh = "ssh #{connection[:user]}@#{connection[:ip]}"
143
+ system("#{ssh} #{cmd}")
144
+ end
145
+ end
146
+ end
147
+
125
148
  def test(id)
149
+ require 'byebug'
150
+ byebug
151
+ end
152
+
153
+ def settings
154
+ CONFIG.keys.each do |key|
155
+ puts "#{key}=#{CONFIG[key]}"
156
+ end
157
+ possible_options ={terminal: %w(xfce4-terminal gnome-terminal urxvt),
158
+ deletion_interval: %w(never), tabbed: %w(true false),
159
+ self: %w(true false)}
160
+
161
+ # change tabbed to mode %w(tabbed whatelse)
162
+ print "Want to change? (y/n)"
163
+ answer = STDIN.gets.chomp
164
+ comp = proc { |s| possible_options.values.flatten.grep(/^#{Regexp.escape(s)}/) }
165
+ Readline.completion_append_character = " "
166
+ Readline.completion_proc = comp
167
+ if answer == "y"
168
+ CONFIG.keys.each do |key|
169
+ puts "#{key}:".colorize(:green)
170
+ puts "possible options are: #{possible_options[key.to_sym]}"
171
+ puts "leave blank to not make any changes (TAB-Completion avalaible)"
172
+ input = Readline.readline('> ', true)
173
+ CONFIG[key] = input if input != ""
174
+ end
175
+ File.open(("#{File.join(ENV['HOME'])}/.config/sshm/settings.yml"),'w') do |h|
176
+ h.write CONFIG.to_yaml
177
+ end
178
+ else
179
+ exit
180
+ end
126
181
  end
127
182
 
128
183
  def transfer_file(filename, id='', dest_path="/home/#{user}/")
@@ -168,14 +223,16 @@ module SSH
168
223
  end
169
224
 
170
225
  def update(id)
171
- connection = DATABASE.get_connection_by_id(id)
172
- @input_fields.each do |key|
173
- #TODO make this a method
174
- connection[key] = %x{source #{File.dirname(__FILE__)}/ask.sh; ask '#{@pretty_names[key]}' '#{connection[key]}'}.chomp
226
+ id.each do |con|
227
+ connection = DATABASE.get_connection_by_id(id)
228
+ @input_fields.each do |key|
229
+ #TODO make this a method
230
+ connection[key] = %x{source #{File.dirname(__FILE__)}/ask.sh; ask '#{@pretty_names[key]}' '#{connection[key]}'}.chomp
231
+ end
232
+ connection[:connect_via] = nil if connection[:connect_via] == ""
233
+ DATABASE.update_connection(connection)
234
+ #TODO catch SQLite3::ConstraintException
175
235
  end
176
- connection[:connect_via] = nil if connection[:connect_via] == ""
177
- DATABASE.update_connection(connection)
178
- #TODO catch SQLite3::ConstraintException
179
236
  end
180
237
 
181
238
  def search_for(term)
@@ -191,10 +248,42 @@ module SSH
191
248
  end
192
249
 
193
250
  def multiple_connection(term)
251
+ @cons = []
194
252
  DATABASE.search_for(term).each do |x|
195
253
  x.all.each do |dataset|
196
- self.connect_to(dataset[:id])
254
+ @cons.push(dataset)
197
255
  end
256
+ end
257
+ # FAIL, first push everything in cons, then do the rest !
258
+ puts "what yer gonna do?"
259
+ options = {execute_command: 'execute_command', connect_to: 'connect', ping: 'ping', info: 'info', delete: 'delete'}
260
+ comp = proc { |s| options.values.grep(/^#{Regexp.escape(s)}/) }
261
+ #Readline.completion_append_character = " "
262
+ Readline.completion_proc = comp
263
+ puts options.values.to_s
264
+ input= Readline.readline('> ', true)
265
+ ids = @cons.map {|x| x[:id].to_s}
266
+ input = input.chomp.gsub(/\s+\Z/, "")
267
+ case input
268
+ when 'execute_command'
269
+ # which commands
270
+ self.execute_command(ids)
271
+ exit
272
+ when 'connect'
273
+ self.connect_to(ids)
274
+ exit
275
+ when 'ping'
276
+ # exits after first ping
277
+ self.ping(ids)
278
+ exit
279
+ when 'info'
280
+ self.show_info(ids)
281
+ exit
282
+ when 'delete'
283
+ self.delete(ids)
284
+ exit
285
+ else
286
+ puts "That i dont know :/"
198
287
  end
199
288
  end
200
289
  end
@@ -33,6 +33,9 @@ module SSH
33
33
  elsif @options[:info]
34
34
  puts 'Printing info ..'
35
35
  cli.new(@options).show_info(@options[:info])
36
+ elsif @options[:execute]
37
+ puts 'Executing command..'
38
+ cli.new(@options).execute_command(@options[:execute])
36
39
  elsif @options[:transfer_file]
37
40
  puts 'Transfering file..'
38
41
  cli.new(@options).transfer_file(@options[:transfer_file].to_i, @argv[2], @argv[3])
@@ -50,22 +53,22 @@ module SSH
50
53
  cli.new(@options).update_available
51
54
  elsif @options[:update]
52
55
  puts 'Updating ..'
53
- cli.new(@options).update(@options[:update].to_i)
56
+ cli.new(@options).update(@options[:update])
54
57
  elsif @options[:multi]
55
58
  puts 'Connecting to multiple ips..'
56
59
  cli.new(@options).multiple_connection(@options[:multi])
57
60
  elsif @options[:transfer_key]
58
61
  puts 'Transfering key..'
59
- cli.new(@options).transfer_key(@options[:transfer_key].to_i)
60
- elsif @options[:codeing]
62
+ cli.new(@options).transfer_key(@options[:transfer_key])
63
+ elsif @options[:encoding]
61
64
  puts 'coding key..'
62
- cli.new(@options).test(@options[:coding].to_i)
65
+ cli.new(@options).test(@options[:encoding].to_i)
66
+ elsif @options[:settings]
67
+ puts 'Settings'
68
+ cli.new(@options).settings
63
69
  elsif @options[:search]
64
70
  puts 'Searching ..'
65
71
  cli.new(@options).search_for(@options[:search])
66
- # elsif @options[:settings]
67
- # puts 'Settings'
68
- # cli.new(@options).settings(@options[:settings])
69
72
  else
70
73
  if @argv.count == 1
71
74
  cli.new(@options).connect_to(@argv.first.split(',')) if @argv != []
@@ -78,6 +81,7 @@ module SSH
78
81
  end
79
82
 
80
83
  def extract_options
84
+ begin
81
85
  @optparse = OptionParser.new do |opts|
82
86
  opts.banner = "Usage: sshm [options] ..."
83
87
  @options[:add] = false
@@ -85,25 +89,30 @@ module SSH
85
89
  @options[:add] = true
86
90
  end
87
91
  @options[:transfer_key] = false
88
- opts.on( '-t', '--transferkey id', 'transfer key to <id>' ) do |opt|
92
+ opts.on( '-t', '--transferkey id,id,id', Array, 'transfer key to <id>' ) do |opt|
89
93
  @options[:transfer_key] = opt
90
94
  end
91
95
  @options[:transfer_file] = false
92
96
  opts.on( '-r', '--transferfile filename', 'file or dir / connection_ID / dest_path(default is /home/user/)' ) do |opt|
93
97
  @options[:transfer_file] = opt
94
98
  end
99
+ @options[:encoding] = false
95
100
  code_list = (CODE_ALIASES.keys + CODES).join(',')
96
101
  opts.on("--code CODE", CODES, CODE_ALIASES, "Select encoding"," (#{code_list})") do |encoding|
97
- options.encoding = encoding
102
+ @options[:encoding] = encoding
98
103
  end
99
104
  @options[:connect] = false
100
- opts.on( '-c', '--connect x y z', Array, 'connect to <ids>' ) do |opt|
105
+ opts.on( '-c', '--connect id1, id2, id3', Array, 'connect to <ids>' ) do |opt|
101
106
  @options[:connect] = opt
102
107
  end
103
108
  @options[:info] = false
104
109
  opts.on( '-i', '--info id1 id2 id3',Array, 'info about to <id>' ) do |opt|
105
110
  @options[:info] = opt
106
111
  end
112
+ @options[:execute] = false
113
+ opts.on( '-x', '--exec id1 id2 id3',Array, 'exec command on <id>' ) do |opt|
114
+ @options[:execute] = opt
115
+ end
107
116
  @options[:ping] = false
108
117
  opts.on( '-p', '--ping id', 'test connection of <id>' ) do |opt|
109
118
  @options[:ping] = opt
@@ -113,7 +122,7 @@ module SSH
113
122
  @options[:delete] = opt
114
123
  end
115
124
  @options[:update] = false
116
- opts.on( '-u', '--update id', 'update connection <id>' ) do |opt|
125
+ opts.on( '-u', '--update id,id,id',Array ,'update connection <id>' ) do |opt|
117
126
  @options[:update] = opt
118
127
  end
119
128
  @options[:search] = false
@@ -121,7 +130,7 @@ module SSH
121
130
  @options[:search] = opt
122
131
  end
123
132
  @options[:multi] = false
124
- opts.on( '-m', '--multi string', 'connect to multiple ips with given criteria' ) do |opt|
133
+ opts.on( '-m', '--multi searchterm', 'connect to multiple ips with given criteria' ) do |opt|
125
134
  @options[:multi] = opt
126
135
  end
127
136
  @options[:list] = false
@@ -132,6 +141,10 @@ module SSH
132
141
  opts.on( '-g', '--upgrade', 'checks for upgrade' ) do
133
142
  @options[:upgrade] = true
134
143
  end
144
+ @options[:settings] = false
145
+ opts.on( '--settings', 'update settings' ) do
146
+ @options[:settings] = true
147
+ end
135
148
  opts.on( '-h', '--help', 'display this screen' ) do
136
149
  puts opts
137
150
  exit
@@ -142,6 +155,9 @@ module SSH
142
155
  end
143
156
  end
144
157
  @optparse.parse(@argv)
158
+ rescue => e
159
+ catch "That didnt work: #{e.to_s}"
160
+ end
145
161
  end
146
162
  end
147
163
  end
@@ -1,5 +1,5 @@
1
1
  module SSH
2
2
  module Manager
3
- VERSION = "1.1.1"
3
+ VERSION = "1.1.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ssh-manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Schmid
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-13 00:00:00.000000000 Z
11
+ date: 2015-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -75,12 +75,6 @@ extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
77
  - ".gitignore"
78
- - ".idea/encodings.xml"
79
- - ".idea/misc.xml"
80
- - ".idea/modules.xml"
81
- - ".idea/scopes/scope_settings.xml"
82
- - ".idea/ssh-manager.iml"
83
- - ".idea/vcs.xml"
84
78
  - ".rspec"
85
79
  - Gemfile
86
80
  - LICENSE