cinch-sudo 0.1.0
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 +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +25 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +34 -0
- data/Rakefile +7 -0
- data/cinch-sudo.gemspec +29 -0
- data/lib/cinch/plugins/sudo/entry.rb +50 -0
- data/lib/cinch/plugins/sudo/version.rb +7 -0
- data/lib/cinch/plugins/sudo.rb +41 -0
- data/lib/cinch-sudo.rb +3 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/sudo_spec.rb +26 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: cc1497b07ca294642789e83047b38cec6fdc94e3
|
4
|
+
data.tar.gz: 40993134495d038efaf1082d620886e0de7319c9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 36ddb817ddbd465c68d082f7b42bc7e3edb9112e513ded64e20d6b6649b716bea08d7e31a397ee141103ecf49500257a254f18385e36523d821de2d1558d107c
|
7
|
+
data.tar.gz: 79ac45b96436b4355e2e99dfdec2891325d4f1d60779c0eedf7a3eaa48c11a1cda14a6394984f6ceb5c186678d415cb662a4ba1e387b2e3cc9f86909d0bb2b1a
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
language: ruby
|
2
|
+
env:
|
3
|
+
global:
|
4
|
+
- "JRUBY_OPTS=-Xcext.enabled=true"
|
5
|
+
rvm:
|
6
|
+
- 2.1.0
|
7
|
+
- 2.0.0
|
8
|
+
- 1.9.3
|
9
|
+
- 1.9.2
|
10
|
+
- 1.8.7
|
11
|
+
- jruby-18mode
|
12
|
+
- jruby-19mode
|
13
|
+
- rbx
|
14
|
+
- ruby-head
|
15
|
+
- jruby-head
|
16
|
+
- ree
|
17
|
+
matrix:
|
18
|
+
allow_failures:
|
19
|
+
- rvm: 1.8.7
|
20
|
+
- rvm: ree
|
21
|
+
- rvm: rbx
|
22
|
+
- rvm: jruby-18mode
|
23
|
+
- rvm: jruby-19mode
|
24
|
+
- rvm: jruby-head
|
25
|
+
fast_finish: true
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Brian Haberer
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Cinch::Sudo
|
2
|
+
|
3
|
+
[](http://badge.fury.io/rb/cinch-sudo)
|
4
|
+
[](https://gemnasium.com/canonical-hackers/cinch-sudo)
|
5
|
+
[](https://travis-ci.org/canonical-hackers/cinch-sudo)
|
6
|
+
[](https://coveralls.io/r/canonical-hackers/cinch-sudo?branch=master)
|
7
|
+
[](https://codeclimate.com/github/canonical-hackers/cinch-sudo)
|
8
|
+
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'cinch-sudo'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install cinch-sudo
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
TODO: Write usage instructions here
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
1. Fork it
|
31
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
32
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
33
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
34
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/cinch-sudo.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cinch/plugins/sudo/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = 'cinch-sudo'
|
8
|
+
gem.version = Cinch::Plugins::Sudo::VERSION
|
9
|
+
gem.authors = ['Paul Visscher', 'Brian Haberer']
|
10
|
+
gem.email = ['bhaberer@gmail.com']
|
11
|
+
gem.description = %q{Cinch Plugin to report usage of Sudo to the channel}
|
12
|
+
gem.summary = %q{Cinch Plugin for monitoring Sudo}
|
13
|
+
gem.homepage = 'https://github.com/canonical-hackers/cinch-sudo'
|
14
|
+
gem.license = 'MIT'
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ['lib']
|
20
|
+
|
21
|
+
gem.add_development_dependency 'rake'
|
22
|
+
gem.add_development_dependency 'rspec-given'
|
23
|
+
gem.add_development_dependency 'rspec'
|
24
|
+
gem.add_development_dependency 'coveralls'
|
25
|
+
gem.add_development_dependency 'cinch-test'
|
26
|
+
|
27
|
+
gem.add_dependency 'cinch', '~> 2.0.12'
|
28
|
+
gem.add_dependency 'file-tail'
|
29
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Cinch
|
2
|
+
module Plugins
|
3
|
+
class Sudo
|
4
|
+
class Entry
|
5
|
+
# Might need to clean these up, make them nested?
|
6
|
+
SUDO_REGEX = /^\w{3}\s+\d+\s+\d{2}:\d{2}:\d{2}\s+[\w\.]+\s+sudo[\[\]\d]*:\s+(\w+)\s+:/
|
7
|
+
DATE_REGEX = /^(\w{3}\s+\d+\s+\d{2}:\d{2}:\d{2})\s+/
|
8
|
+
USER_REGEX = /sudo[\[\]\d]*:\s+(\w+)\s+:\s/
|
9
|
+
AUTH_REGEX = /sudo[\[\]\d]*:\s+\w+\s+:\sTTY=/
|
10
|
+
|
11
|
+
attr_accessor :date, :user, :tty, :pwd, :executedas, :command,
|
12
|
+
:success, :line
|
13
|
+
|
14
|
+
def initialize(line)
|
15
|
+
@line = line
|
16
|
+
@date = @line[DATE_REGEX, 1] || '(unknown timestamp)'
|
17
|
+
@user = @line[USER_REGEX, 1]
|
18
|
+
|
19
|
+
@success = line.match(AUTH_REGEX) ? true : false
|
20
|
+
|
21
|
+
scan_line
|
22
|
+
end
|
23
|
+
|
24
|
+
def valid?
|
25
|
+
return false unless @line.match(SUDO_REGEX)
|
26
|
+
true
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_text
|
30
|
+
if @success
|
31
|
+
"#{@date}: #{@user} ran (#{@command}) as "\
|
32
|
+
"#{@executedas} in (#{@pwd})"
|
33
|
+
else
|
34
|
+
"#{@date}: #{@user} tried to run (#{@command}) as #{@executedas} "\
|
35
|
+
"in (#{@pwd}), but failed (incorrect password?)"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def scan_line
|
42
|
+
vars = line.gsub(/USER=/, 'EXECUTEDAS=')
|
43
|
+
.scan(/ [A-Z]+=[^;\n]+/)
|
44
|
+
.map { |v| v.strip.split(/=/) }
|
45
|
+
vars.each { |v, value| send("#{v.downcase}=", value) }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'cinch'
|
2
|
+
require 'file-tail'
|
3
|
+
|
4
|
+
module Cinch
|
5
|
+
module Plugins
|
6
|
+
class Sudo
|
7
|
+
include Cinch::Plugin
|
8
|
+
|
9
|
+
listen_to :connect
|
10
|
+
|
11
|
+
def initialize(*args)
|
12
|
+
super
|
13
|
+
@logfile = config[:logfile]
|
14
|
+
@channel = config[:channel]
|
15
|
+
end
|
16
|
+
|
17
|
+
def listen(m)
|
18
|
+
if File.exist?(@logfile)
|
19
|
+
start_tail
|
20
|
+
else
|
21
|
+
debug "File (#{@filename}) not found!"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def start_tail
|
28
|
+
File.open(@logfile) do |log|
|
29
|
+
log.extend(File::Tail)
|
30
|
+
log.interval = 3
|
31
|
+
log.backward(0)
|
32
|
+
log.tail do |line|
|
33
|
+
entry = Entry.new(line)
|
34
|
+
next unless entry.valid?
|
35
|
+
Channel(@channel).send entry.to_text
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/cinch-sudo.rb
ADDED
data/spec/spec_helper.rb
ADDED
data/spec/sudo_spec.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# I need to add support for non triggered actions to cinch-test,
|
4
|
+
# so this will have to do.
|
5
|
+
def sudo_command(command = '/bin/echo foo', pass = true)
|
6
|
+
"Jun 3 17:32:16 localhost sudo: username : "\
|
7
|
+
"#{pass ? '' : '3 incorrect password attempts ; '}"\
|
8
|
+
"TTY=ttys007 ; "\
|
9
|
+
"PWD=/Users/username ; "\
|
10
|
+
"USER=root ; "\
|
11
|
+
"COMMAND=#{command}"
|
12
|
+
end
|
13
|
+
|
14
|
+
describe Cinch::Plugins::Sudo do
|
15
|
+
include Cinch::Test
|
16
|
+
|
17
|
+
it 'should recognize correct sudo lines' do
|
18
|
+
entry = Cinch::Plugins::Sudo::Entry.new(sudo_command)
|
19
|
+
expect(entry).to_not be nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should marke entries successful' do
|
23
|
+
entry = Cinch::Plugins::Sudo::Entry.new(sudo_command)
|
24
|
+
expect(entry.success).to be true
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cinch-sudo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paul Visscher
|
8
|
+
- Brian Haberer
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-06-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ! '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ! '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rspec-given
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: coveralls
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: cinch-test
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: cinch
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ~>
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 2.0.12
|
91
|
+
type: :runtime
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ~>
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 2.0.12
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: file-tail
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :runtime
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
description: Cinch Plugin to report usage of Sudo to the channel
|
113
|
+
email:
|
114
|
+
- bhaberer@gmail.com
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- .gitignore
|
120
|
+
- .travis.yml
|
121
|
+
- Gemfile
|
122
|
+
- LICENSE.txt
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- cinch-sudo.gemspec
|
126
|
+
- lib/cinch-sudo.rb
|
127
|
+
- lib/cinch/plugins/sudo.rb
|
128
|
+
- lib/cinch/plugins/sudo/entry.rb
|
129
|
+
- lib/cinch/plugins/sudo/version.rb
|
130
|
+
- spec/spec_helper.rb
|
131
|
+
- spec/sudo_spec.rb
|
132
|
+
homepage: https://github.com/canonical-hackers/cinch-sudo
|
133
|
+
licenses:
|
134
|
+
- MIT
|
135
|
+
metadata: {}
|
136
|
+
post_install_message:
|
137
|
+
rdoc_options: []
|
138
|
+
require_paths:
|
139
|
+
- lib
|
140
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ! '>='
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
requirements: []
|
151
|
+
rubyforge_project:
|
152
|
+
rubygems_version: 2.2.2
|
153
|
+
signing_key:
|
154
|
+
specification_version: 4
|
155
|
+
summary: Cinch Plugin for monitoring Sudo
|
156
|
+
test_files:
|
157
|
+
- spec/spec_helper.rb
|
158
|
+
- spec/sudo_spec.rb
|