1
1
require 'proxy/kerberos'
2
- require 'radcli'
2
+ # require 'radcli'
3
3
4
4
module Proxy ::AdRealm
5
5
class Provider
@@ -19,45 +19,106 @@ def check_realm realm
19
19
raise Exception . new "Unknown realm #{ realm } " unless realm . casecmp ( @realm ) . zero?
20
20
end
21
21
22
- def find hostname
22
+ def find hostfqdn
23
23
true
24
24
end
25
25
26
- def create realm , hostname , params
27
- logger . info "Proxy::AdRealm: create... #{ realm } , #{ hostname } , #{ params } "
26
+ def create realm , hostfqdn , params
27
+ logger . info "Proxy::AdRealm: create... #{ realm } , #{ hostfqdn } , #{ params } "
28
+ check_realm realm
29
+ kinit_racdli_connect
30
+
31
+ password = generate_password
32
+ result = { :randompassword => password }
33
+
34
+ begin
35
+ if params [ :rebuild ] == "true"
36
+ do_host_rebuild hostfqdn , password
37
+ else
38
+ do_host_create hostfqdn , password
39
+ end
40
+ rescue
41
+ raise
42
+ end
43
+
44
+ JSON . pretty_generate ( result )
28
45
end
29
46
30
- def delete realm , hostname
31
- logger . info "Proxy::AdRealm: delete... #{ realm } , #{ hostname } "
47
+ def delete realm , hostfqdn
48
+ logger . info "Proxy::AdRealm: delete... #{ realm } , #{ hostfqdn } "
49
+ kinit_radcli_connect ( )
50
+ check_realm realm
51
+ begin
52
+ radcli_delete hostfqdn
53
+ rescue Adcli ::AdEnroll ::Exception =>
54
+ raise
55
+ end
32
56
end
33
57
34
58
private
35
59
36
- def hostfqdn_hostname host_fqdn
60
+ def hostfqdn_to_hostname host_fqdn
61
+ begin
62
+ host_fqdn_split = host_fqdn . split ( '.' )
63
+ host_fqdn_split [ 0 ]
64
+ rescue
65
+ logger . debug "hostfqdn_to_hostname error"
66
+ raise
67
+ end
37
68
end
38
69
39
- def do_host_create hostname , password
70
+ def do_host_create hostfqdn , password
71
+ hostname = hostfqdn_to_hostname hostfqdn
72
+ radcli_join hostfqdn , hostname , password
40
73
end
41
74
42
- def do_host_rebuild hostname , password
75
+ def do_host_rebuild hostfqdn , password
76
+ hostname = hostfqdn_to_hostname hostfqdn
77
+ racli_password hostname , password
78
+
43
79
end
44
80
45
81
def kinit_racdli_connect
82
+ init_krb5_ccache @keytab_path , @principal
83
+ @adconn = radcli_connect ( )
46
84
end
47
85
48
86
def radcli_connect
87
+ # Connect to active directory
88
+ conn = Adcli ::AdConn . new ( @domain )
89
+ conn . set_domain_realm ( @realm )
90
+ conn . set_domain_controller ( @domain_controller )
91
+ conn . set_login_ccache_name ( "" )
92
+ conn . connect ( )
93
+ return conn
49
94
end
50
95
51
- def radcli_join
96
+ def radcli_join hostfqdn , hostname , password
97
+ # Join computer
98
+ enroll = Adcli ::AdEnroll . new ( @adconn )
99
+ enroll . set_computer_name ( hostname )
100
+ enroll . set_host_fqdn ( hostfqdn )
101
+ enroll . set_computer_password ( password )
102
+ enroll . join ( )
52
103
end
53
104
54
105
def generate_password
106
+ return "randompassword"
55
107
end
56
108
57
- def racli_password
109
+ def racli_password hostname , password
110
+ # Reset a computer's password
111
+ enroll = Adcli ::AdEnroll . new ( @adconn )
112
+ enroll . set_computer_name ( hostname )
113
+ enroll . set_computer_password ( password )
114
+ enroll . password ( )
58
115
end
59
116
60
- def radcli_delete
117
+ def radcli_delete hostname
118
+ # Delete a computer's account
119
+ enroll = Adcli ::AdEnroll . new ( @adconn )
120
+ enroll . set_computer_name ( hostname )
121
+ enroll . delete ( )
61
122
end
62
123
63
124
end
0 commit comments