netid-tools 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "nokogiri"
4
+
5
+ group :development do
6
+ gem "shoulda", ">= 0"
7
+ gem "rdoc", "~> 3.12"
8
+ gem "bundler"
9
+ gem "jeweler", "~> 1.8.4"
10
+ gem "simplecov", ">= 0"
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,46 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (3.2.9)
5
+ i18n (~> 0.6)
6
+ multi_json (~> 1.0)
7
+ bourne (1.1.2)
8
+ mocha (= 0.10.5)
9
+ git (1.2.5)
10
+ i18n (0.6.1)
11
+ jeweler (1.8.4)
12
+ bundler (~> 1.0)
13
+ git (>= 1.2.5)
14
+ rake
15
+ rdoc
16
+ json (1.7.5)
17
+ metaclass (0.0.1)
18
+ mocha (0.10.5)
19
+ metaclass (~> 0.0.1)
20
+ multi_json (1.5.0)
21
+ nokogiri (1.5.5)
22
+ rake (10.0.2)
23
+ rdoc (3.12)
24
+ json (~> 1.4)
25
+ shoulda (3.3.2)
26
+ shoulda-context (~> 1.0.1)
27
+ shoulda-matchers (~> 1.4.1)
28
+ shoulda-context (1.0.1)
29
+ shoulda-matchers (1.4.2)
30
+ activesupport (>= 3.0.0)
31
+ bourne (~> 1.1.2)
32
+ simplecov (0.7.1)
33
+ multi_json (~> 1.0)
34
+ simplecov-html (~> 0.7.1)
35
+ simplecov-html (0.7.1)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ bundler
42
+ jeweler (~> 1.8.4)
43
+ nokogiri
44
+ rdoc (~> 3.12)
45
+ shoulda
46
+ simplecov
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Nikky Southerland
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,6 @@
1
+ UA Tools
2
+ =================
3
+
4
+ Collect of tools for interacting and using the Uniform Access systems. These
5
+ are all under various forms of construction, so there won't be further documentation
6
+ until I get them in a somewhat stable state and stop adding features.
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "netid-tools"
18
+ gem.homepage = "http://github.com/allynfolksjr/netid-tools"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Gem with various methods to support UW NetIDs}
21
+ gem.description = %Q{Gem with various methods to support UW NetIDs}
22
+ gem.email = "nikky@uw.edu"
23
+ gem.authors = ["Nikky Southerland"]
24
+ gem.add_dependency 'nokogiri'
25
+ # gem.add_dependency 'colored'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ task :default => :test
37
+
38
+ require 'rdoc/task'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "netid-tools #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.3.0
data/bin/ua_check ADDED
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env ruby
2
+ require 'net/ssh'
3
+ require 'colored'
4
+ require 'netid-tools'
5
+
6
+ # This is a simple script that will go through various hosts and check to see
7
+ # if a specified user is running MySQLd
8
+ #
9
+ # It assumes the user running the script has ssh keys setup for authentication
10
+ #
11
+ # Requires net-ssh gem and ruby compiled with openssl. Pulls SSH user from
12
+ # system's `whoami` command.
13
+ #
14
+ # Required: Ruby 1.9.2+
15
+
16
+ ## To-Do:
17
+ # * Consolidate SSH connect lines
18
+ # * Grab owners/administrators?
19
+
20
+
21
+ # Set up initial variables
22
+ $results = 0
23
+ raise "No user specified. Bailing." if ARGV[0].nil?
24
+ user = ARGV[0].chomp.downcase
25
+ raise "This is not a valid NetID!" unless Netid.validate_netid?(user)
26
+ # get the user of whoever is running script
27
+ system_user = `whoami`.chomp
28
+ system_hostname = `hostname`.chomp
29
+ # Initialize the systems we'll check
30
+ hosts = [ "ovid01.u.washington.edu",
31
+ "ovid02.u.washington.edu",
32
+ "ovid03.u.washington.edu",
33
+ "ovid21.u.washington.edu",
34
+ "vergil.u.washington.edu"
35
+ ]
36
+
37
+
38
+
39
+ puts "Running UA Check for NetID #{user} on behalf of #{system_user}\n".green
40
+
41
+
42
+ results = 0
43
+ hosts.each do |host|
44
+ result = Netid.check_for_mysql_presence(host,user,system_user)
45
+ if result
46
+ results += 1
47
+ puts "MySQLd detected on #{result[0]}:#{result[1]}".blue
48
+ end
49
+ end
50
+
51
+ puts "No MySQLds Detected".bold.blue if results == 0
52
+ puts "Multiple MySQLds Detected!".bold.red if results > 1
53
+ puts Netid.check_for_localhome(user,system_user).cyan if results > 0
54
+ puts "\n"
55
+ Netid.quota_check(user,system_user)
@@ -0,0 +1,72 @@
1
+ require 'net/ssh'
2
+ require 'colored'
3
+
4
+ class Netid
5
+ # Validate that string is in the form of a valid NetID. eg: 1-8 chars, doesn't start
6
+ # with a number, and no special characters
7
+ def self.validate_netid?(netid)
8
+ if netid.to_s.length > 8 || netid !~ /^[a-zA-Z]\w{0,7}$/
9
+ false
10
+ else
11
+ true
12
+ end
13
+ end
14
+
15
+ # Checks to see if MySQL is running on a specified host. Returns array with host, port
16
+ # if present, returns false if not present.
17
+ def self.check_for_mysql_presence(host,user,system_user)
18
+ Net::SSH.start(host,system_user, {auth_methods: %w( publickey )}) do |ssh|
19
+ output = ssh.exec!("ps -U #{user} -u #{user} u")
20
+ if output =~ /mysql/
21
+ /port=(?<port>\d+)/ =~ output
22
+ [host,port]
23
+ else
24
+ false
25
+ end
26
+ end
27
+ end
28
+
29
+ # Returns location of localhome if present
30
+ def self.check_for_localhome(user,system_user)
31
+ host = 'ovid02.u.washington.edu'
32
+ Net::SSH.start(host,system_user, {auth_methods: %w( publickey )}) do |ssh|
33
+ output = ssh.exec!("cpw -poh #{user}")
34
+ if output =~ /Unknown/
35
+ false
36
+ else
37
+ output.chomp
38
+ end
39
+ end
40
+ end
41
+
42
+ def self.quota_check(user,system_user)
43
+ host = 'ovid02.u.washington.edu'
44
+ Net::SSH.start(host,system_user, {auth_methods: %w( publickey )}) do |ssh|
45
+ result = ssh.exec!("quota #{user}").chomp
46
+ # Split along newlines
47
+ result = result.split("\n")
48
+ # This deletes the first blank line. There be an easier way to do this
49
+ result.delete_at(0) if result.first == ''
50
+ # Go through each line of the result
51
+ result.each_with_index do |line,index|
52
+ # The first two are headers: print and ignore
53
+ if index == 0 || index == 1
54
+ puts line
55
+ next
56
+ end
57
+ # Break the line up into elements
58
+ line_components = line.squeeze(" ").split(" ")
59
+ # Check to see if usage is over quota
60
+ if line_components[1].to_f > line_components[2].to_f
61
+ puts "#{line.bold.red}"
62
+ # If there's a grace period, it shows up in [4], so we account for that
63
+ # and flag if its present
64
+ elsif line_components[4] =~ /day/i || line_components[4].to_i > line_components[5].to_i
65
+ puts line.bold.red+'\n'
66
+ else
67
+ puts line
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'netid-tools'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestNetidTools < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: netid-tools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nikky Southerland
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: shoulda
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rdoc
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '3.12'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.12'
62
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: jeweler
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 1.8.4
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.8.4
94
+ - !ruby/object:Gem::Dependency
95
+ name: simplecov
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: nokogiri
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: Gem with various methods to support UW NetIDs
127
+ email: nikky@uw.edu
128
+ executables:
129
+ - ua_check
130
+ extensions: []
131
+ extra_rdoc_files:
132
+ - LICENSE.txt
133
+ - README.md
134
+ files:
135
+ - .document
136
+ - Gemfile
137
+ - Gemfile.lock
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - VERSION
142
+ - bin/ua_check
143
+ - lib/netid-tools.rb
144
+ - test/helper.rb
145
+ - test/test_netid-tools.rb
146
+ homepage: http://github.com/allynfolksjr/netid-tools
147
+ licenses:
148
+ - MIT
149
+ post_install_message:
150
+ rdoc_options: []
151
+ require_paths:
152
+ - lib
153
+ required_ruby_version: !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ! '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ none: false
161
+ requirements:
162
+ - - ! '>='
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ requirements: []
166
+ rubyforge_project:
167
+ rubygems_version: 1.8.24
168
+ signing_key:
169
+ specification_version: 3
170
+ summary: Gem with various methods to support UW NetIDs
171
+ test_files: []