ad_search 0.0.1 → 0.0.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.
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.homepage = ""
11
11
  s.summary = %q{Search Active Directory}
12
12
  s.description = %q{Allows you to connect to and search your Active Directory system for users that have
13
- not been disabled.}
13
+ not been disabled. Returns a hash.}
14
14
 
15
15
  s.rubyforge_project = "ad_search"
16
16
 
@@ -1,14 +1,12 @@
1
+ require 'net-ldap'
2
+
1
3
  require "ad_search/version"
2
4
 
5
+ # Search Active Directory and get a hash in return
3
6
  module AdSearch
4
- # Search Active Directory and get a hash in return
5
-
6
- def initialize(user, pw, domain, host, base)
7
- @ad_connection = connect_to_ad(user, pw, domain, host, base)
8
- end
9
7
 
10
8
  # Connection to Active Directory
11
- def connect_to_ad(username, password, domain, host, base)
9
+ def self.connect_to_ad(username, password, domain, host, base)
12
10
  ldap = Net::LDAP.new :host => host,
13
11
  :port => 389,
14
12
  :base => base,
@@ -24,7 +22,7 @@ module AdSearch
24
22
  end
25
23
  end
26
24
 
27
- def search_active_users_by_username(search_term, treebase)
25
+ def self.search_active_users_by_username(ad_connection, search_term, treebase)
28
26
  users = Hash.new
29
27
 
30
28
  #Create a filter based on the username
@@ -35,7 +33,7 @@ module AdSearch
35
33
  joined_filter = Net::LDAP::Filter.join(filter, filter2)
36
34
 
37
35
  count = 0
38
- @ad_connection.search(:base => treebase, :filter => joined_filter) do |entry|
36
+ ad_connection.search(:base => treebase, :filter => joined_filter) do |entry|
39
37
  if active_account?(entry)
40
38
  username = entry.sAMAccountName.to_s[2..-3]
41
39
  #Split the first name and last name and remove un-needed characters
@@ -78,17 +76,18 @@ module AdSearch
78
76
  return users
79
77
  end
80
78
 
81
- #Microsoft Active Directory's way of keeping track of time: BIGEPOCH (01/01/1970) is 116444916000000000 "100 nanosecond intervals since 01/01/1601"
79
+ #Microsoft Active Directories way of keeping track of time: BIGEPOCH (01/01/1970) is 116444916000000000 "100 nanosecond intervals since 01/01/1601"
82
80
  BIGEPOCH = 116444916000000000
83
- def active_account?(ad_object)
81
+ def self.active_account?(ad_object)
84
82
  #See if account is disabled or the account is expired
85
83
  tmpuac = ad_object.userAccountControl[0].to_i
86
84
  if tmpuac & 2 == 2
87
85
  return false
88
- elsif ad_object.accountExpires[0].to_i != 0 and Time.now > Time.at((ad_object.accountExpires[0].to_i - BIGEPOCH) / 10000000) #Microsoft time to epoch time
86
+ elsif ad_object.accountExpires[0].to_i != 0 and Time.now > Time.at((ad_object.accountExpires[0].to_i - BIGEPOCH) / 10000000) #Microsoft to epoch time
89
87
  return false
90
88
  else
91
89
  return true
92
90
  end
93
91
  end
92
+
94
93
  end
@@ -1,3 +1,3 @@
1
1
  module AdSearch
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ad_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-04-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &22654416 !ruby/object:Gem::Requirement
16
+ requirement: &25423128 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *22654416
24
+ version_requirements: *25423128
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: net-ldap
27
- requirement: &22653852 !ruby/object:Gem::Requirement
27
+ requirement: &25422648 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,9 +32,9 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *22653852
35
+ version_requirements: *25422648
36
36
  description: ! "Allows you to connect to and search your Active Directory system for
37
- users that have\n not been disabled."
37
+ users that have\n not been disabled. Returns a hash."
38
38
  email:
39
39
  - neilhoff@gmail.com
40
40
  executables: []