lita-ssh-run 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b793719e3aa195e2c62439c4c422ffbc6265a454
4
+ data.tar.gz: 08c14c7a3c181c3bc538c326ed9f7011e110bff1
5
+ SHA512:
6
+ metadata.gz: 6d93b40502d91f6c41c65a9417721401920358d6e59bdf7d7a02d1d34d1a475b5f1e1572f32ed0307f45f3f74efb0ca5d134400889a0431d54d618264981ff44
7
+ data.tar.gz: eaa9647d43663756f0cc236c90589568287b9812acd43b13ba8c6d2150c27ac5233fefacbb35a611a1ad6b8c4ba0aff5614073c0def836b33c22a2ef4cb5675f
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2015 Dan Cash
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # lita-ssh-run
2
+
3
+ This will allow you to run commands via ssh
4
+ Example:
5
+ `Lita, run uptime on 192.168.1.10`
6
+
7
+ Usernames and passwords are stored in redis memory by chat userid and host passed. **Only tested on slack**
8
+ If not found, it will prompt via private message on how to enter user and password:
9
+ Currently passwords are passed via plaintext in private message. I have requested to Slack to add an obfuscation format block for things like this.
10
+
11
+ ## Installation
12
+
13
+ Add lita-ssh-run to your Lita instance's Gemfile:
14
+
15
+ ``` ruby
16
+ gem "lita-ssh-run"
17
+ ```
18
+
19
+
20
+ ## Configuration
21
+
22
+ None
23
+
24
+ ## Usage
25
+
26
+ `Lita, run uptime on 192.168.1.10`
27
+
28
+ `Lita, set username for 192.168.1.0 to USERNAME`
29
+
30
+ `Lita, set password for 192.168.1.0 to PASSWORD`
31
+
32
+
33
+ ## License
34
+
35
+ [MIT](http://opensource.org/licenses/MIT)
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,73 @@
1
+ module Lita
2
+ module Handlers
3
+ class SshRun < Handler
4
+ require 'net/ssh'
5
+
6
+ route(/^run\s+(.+)\s+on\s+(.+)/i, :run_ssh, command: true)
7
+
8
+ route(/^set\s+(username|password)\s+for\s+(.+)\s+to\s+(.+)/i, :set_user_pass, command: true)
9
+
10
+ route(/^clear\s+all\s+stored\s+(creds|credentials)/i, :flush_redis, command: true, restrict_to: :admins)
11
+
12
+ def run_ssh(response)
13
+
14
+ cmd = response.matches[0][0]
15
+ server = response.matches[0][1]
16
+ id_server_user = response.user.id + "_" + server + "_username"
17
+ id_server_pass = response.user.id + "_" + server + "_password"
18
+ usernm = redis.get(id_server_user)
19
+ passwd = redis.get(id_server_pass)
20
+ get_user_pass(response, server, "Username") unless usernm
21
+ get_user_pass(response, server, "Password") unless passwd
22
+
23
+ if usernm && passwd
24
+ Net::SSH.start(server, usernm, :password => passwd) do |ssh|
25
+ output = ssh.exec!(cmd)
26
+ response.reply("```" + output + "```")
27
+ end
28
+ elsif usernm
29
+ response.reply_with_mention("I was unable to find a password for you on #{server}, please check you direct messages from me.")
30
+ elsif passwd
31
+ response.reply_with_mention("I was unable to find a username for you on #{server}, please check you direct messages from me.")
32
+ else
33
+ response.reply_with_mention("I was unable to find a username or password for you on #{server}, please check you direct messages from me.")
34
+ end
35
+
36
+ end
37
+
38
+ def get_user_pass(response, server, *user_pass)
39
+ user_pass.each do |blah|
40
+ response.reply_privately("No #{blah.capitalize} found for you on #{server}\nPlease privately reply with:\n`Lita, Set #{blah.capitalize} for #{server} to #{blah.upcase}`")
41
+ end
42
+ end
43
+
44
+ def set_user_pass(response)
45
+ request = response.matches[0][0]
46
+ server = response.matches[0][1]
47
+ value = response.matches[0][2]
48
+ id_server_user_pass = response.user.id + "_" + server + "_" + request.downcase
49
+
50
+ if request && server && value
51
+ redis.set(id_server_user_pass, value)
52
+ response.reply_privately("#{request.capitalize} set")
53
+ id_server_user = response.user.id + "_" + server + "_username"
54
+ id_server_pass = response.user.id + "_" + server + "_password"
55
+ if redis.get(id_server_user) && redis.get(id_server_pass)
56
+ response.reply("Username and Password now set, please rerun your request")
57
+
58
+ end
59
+ else
60
+ response.reply_privately("There seems to have been a problem setting that for you")
61
+ end
62
+ end
63
+
64
+ def flush_redis(response)
65
+ redis.flushdb
66
+ end
67
+
68
+
69
+ end
70
+
71
+ Lita.register_handler(SshRun)
72
+ end
73
+ end
@@ -0,0 +1,7 @@
1
+ require "lita"
2
+
3
+ Lita.load_locales Dir[File.expand_path(
4
+ File.join("..", "..", "locales", "*.yml"), __FILE__
5
+ )]
6
+
7
+ require "lita/handlers/ssh_run"
@@ -0,0 +1,28 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "lita-ssh-run"
3
+ spec.version = "0.0.1"
4
+ spec.authors = ["Dan Cash"]
5
+ spec.email = ["dancash04@gmail.com"]
6
+ spec.description = %q{Runs commands against remote server via ssh}
7
+ spec.summary = %q{See description}
8
+ spec.homepage = "https://github.com/cashman04/lita-ssh-run"
9
+ spec.license = "MIT"
10
+ spec.metadata = { "lita_plugin_type" => "handler" }
11
+
12
+ spec.files = `git ls-files`.split($/)
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.add_runtime_dependency "lita", ">= 4.1"
18
+ spec.add_runtime_dependency 'net-ssh'
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rack-test"
23
+ spec.add_development_dependency "rspec", ">= 3.0.0"
24
+ spec.add_development_dependency "simplecov"
25
+ spec.add_development_dependency "coveralls"
26
+
27
+ spec.metadata = { "lita_plugin_type" => "handler" }
28
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,4 @@
1
+ en:
2
+ lita:
3
+ handlers:
4
+ ssh_run:
@@ -0,0 +1,4 @@
1
+ require "spec_helper"
2
+
3
+ describe Lita::Handlers::SshRun, lita_handler: true do
4
+ end
@@ -0,0 +1,14 @@
1
+ require "simplecov"
2
+ require "coveralls"
3
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
4
+ SimpleCov::Formatter::HTMLFormatter,
5
+ Coveralls::SimpleCov::Formatter
6
+ ]
7
+ SimpleCov.start { add_filter "/spec/" }
8
+
9
+ require "lita-ssh-run"
10
+ require "lita/rspec"
11
+
12
+ # A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
13
+ # was generated with Lita 4, the compatibility mode should be left disabled.
14
+ Lita.version_3_compatibility_mode = false
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-ssh-run
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dan Cash
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: net-ssh
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 3.0.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 3.0.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: coveralls
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Runs commands against remote server via ssh
126
+ email:
127
+ - dancash04@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - Gemfile
133
+ - LICENSE
134
+ - README.md
135
+ - Rakefile
136
+ - lib/lita-ssh-run.rb
137
+ - lib/lita/handlers/ssh_run.rb
138
+ - lita-ssh-run.gemspec
139
+ - locales/en.yml
140
+ - spec/lita/handlers/ssh_run_spec.rb
141
+ - spec/spec_helper.rb
142
+ homepage: https://github.com/cashman04/lita-ssh-run
143
+ licenses:
144
+ - MIT
145
+ metadata:
146
+ lita_plugin_type: handler
147
+ post_install_message:
148
+ rdoc_options: []
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ requirements: []
162
+ rubyforge_project:
163
+ rubygems_version: 2.4.5
164
+ signing_key:
165
+ specification_version: 4
166
+ summary: See description
167
+ test_files:
168
+ - spec/lita/handlers/ssh_run_spec.rb
169
+ - spec/spec_helper.rb