Class: FreeipaEasy::User

Inherits:
Object
  • Object
show all
Defined in:
lib/freeipa_easy/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, user, password) ⇒ User

Returns a new instance of User.



6
7
8
9
10
# File 'lib/freeipa_easy/user.rb', line 6

def initialize(url, user, password)
  @url = url
  @user = user
  @password = password
end

Instance Attribute Details

#cookiesObject (readonly)

Returns the value of attribute cookies.



5
6
7
# File 'lib/freeipa_easy/user.rb', line 5

def cookies
  @cookies
end

#passwordObject (readonly)

Returns the value of attribute password.



5
6
7
# File 'lib/freeipa_easy/user.rb', line 5

def password
  @password
end

#urlObject (readonly)

Returns the value of attribute url.



5
6
7
# File 'lib/freeipa_easy/user.rb', line 5

def url
  @url
end

#userObject (readonly)

Returns the value of attribute user.



5
6
7
# File 'lib/freeipa_easy/user.rb', line 5

def user
  @user
end

Instance Method Details

#add_user(first_name, last_name, login, mail, password) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/freeipa_easy/user.rb', line 23

def add_user(first_name, last_name, , mail, password)
  begin
  cn = first_name + " " + last_name
  payload = {"method":"user_add",
  "params":[[],
  {"cn": cn, "mail": mail, "givenname": first_name, "sn": last_name, "userpassword": password}],
  "id":0}
  data_json = RestClient::Request.execute(method: :post, 
  url: @url +'/ipa/session/json',
  :verify_ssl => false, 
  :cookies => @cookies,
  :payload => payload.to_json,
  :headers => {:content_type => :json, :accept =>:json,
  :Referer => url + '/ipa'})
  data = JSON.parse(data_json)
  rescue Exception => e
    puts "#{e.class}" +": " +  "#{e.message}"
  end
  data["error"]
end

#authentication_passwordObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/freeipa_easy/user.rb', line 12

def authentication_password
  begin
   = RestClient::Request.execute(method: :post, url: url+'/ipa/session/login_password', :verify_ssl => false, :payload => "user=#{@user}&password=#{@password}",
  :headers => {:Referer => url+'/ipa'})
  @cookies = .cookies
  rescue Exception => e
    puts "#{e.class}" +": " +  "#{e.message}"
  end
  true
end

#delete_user(login) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/freeipa_easy/user.rb', line 44

def delete_user()
  begin
  payload = {"id": 0, "method": "user_del", "params": [[[]],{ }]}
  data_json = RestClient::Request.execute(method: :post,
  url: @url +'/ipa/session/json',
  :verify_ssl => false,
  :cookies => @cookies,
  :payload => payload.to_json,
  :headers => {:content_type => :json, :accept =>:json,
  :Referer => url + '/ipa'})
  data = JSON.parse(data_json)
  rescue Exception => e
    puts "#{e.class}" +": " +  "#{e.message}"
  end
  data["error"]
end

#disable_user(login) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/freeipa_easy/user.rb', line 78

def disable_user()
  begin
  payload = {"id": 0, "method": "user_disable", "params": [[], {}]}
  data_json = RestClient::Request.execute(method: :post,
  url: @url +'/ipa/session/json',
  :verify_ssl => false,
  :cookies => @cookies,
  :payload => payload.to_json,
  :headers => {:content_type => :json, :accept =>:json,
  :Referer => url + '/ipa'})
  data = JSON.parse(data_json)
  rescue Exception => e
    puts "#{e.class}" +": " +  "#{e.message}"
  end
  data["error"]
end

#enable_user(login) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/freeipa_easy/user.rb', line 112

def enable_user()
  begin
  payload = {"id": 0, "method": "user_enable", "params": [[], {}]}
  data_json = RestClient::Request.execute(method: :post,
  url: @url +'/ipa/session/json',
  :verify_ssl => false,
  :cookies => @cookies,
  :payload => payload.to_json,
  :headers => {:content_type => :json, :accept =>:json,
  :Referer => url + '/ipa'})
  data = JSON.parse(data_json)
  rescue Exception => e
    puts "#{e.class}" +": " +  "#{e.message}"
  end
  data["error"]
end

#modify_user(login, payload_options = {}) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/freeipa_easy/user.rb', line 129

def modify_user(,payload_options={})
  begin
  payload_options.merge!({"all": false, "no_members": false,"raw": false,"rights": false})
  test =  {"all": false, "no_members": false,"raw": false,"rights": false}
  payload = {"id": 0, "method": "user_mod", "params": [[], payload_options]}
  data_json = RestClient::Request.execute(method: :post,
  url: @url +'/ipa/session/json',
  :verify_ssl => false,
  :cookies => @cookies,
  :payload => payload.to_json,
  :headers => {:content_type => :json, :accept =>:json,
  :Referer => url + '/ipa'})
  data = JSON.parse(data_json)
  rescue Exception => e
    puts "#{e.class}" +": " +  "#{e.message}"
  end
 data["error"]
end

#show_user(login) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/freeipa_easy/user.rb', line 61

def show_user()
  begin
  payload = {"id": 0, "method": "user_show", "params": [[], {"all": false, "no_members": false,"raw": false,"rights": false}]}
  data_json = RestClient::Request.execute(method: :post,
  url: @url +'/ipa/session/json',
  :verify_ssl => false,
  :cookies => @cookies,
  :payload => payload.to_json,
  :headers => {:content_type => :json, :accept =>:json,
  :Referer => url + '/ipa'})
  data = JSON.parse(data_json)
  rescue Exception => e
    puts "#{e.class}" +": " +  "#{e.message}"
  end
  data["error"]
end

#unlock_user(login) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/freeipa_easy/user.rb', line 95

def unlock_user()
  begin
  payload = {"id": 0, "method": "user_unlock", "params": [[], {}]}
  data_json = RestClient::Request.execute(method: :post,
  url: @url +'/ipa/session/json',
  :verify_ssl => false,
  :cookies => @cookies,
  :payload => payload.to_json,
  :headers => {:content_type => :json, :accept =>:json,
  :Referer => url + '/ipa'})
  data = JSON.parse(data_json)
  rescue Exception => e
    puts "#{e.class}" +": " +  "#{e.message}"
  end
  data["error"]
end