-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathliderAhenkConfig.go
233 lines (204 loc) · 10 KB
/
liderAhenkConfig.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
package main
import (
"fmt"
"time"
"github.com/fatih/color"
"github.com/go-ldap/ldap/v3"
)
type LiderAhenkConfig struct {
LdapConn *ldap.Conn
LiderLocale string `json:"liderLocale"`
LdapServer string `json:"ldapServer"`
LdapPort string `json:"ldapPort"`
LdapUsername string `json:"ldapUsername"`
LdapPassword string `json:"ldapPassword"`
LdapRootDn string `json:"ldapRootDn"`
LdapUseSsl bool `json:"ldapUseSsl"`
LdapSearchAttributes string `json:"ldapSearchAttributes"`
LdapAllowSelfSignedCert bool `json:"ldapAllowSelfSignedCert"`
LdapMailNotifierAttributes string `json:"ldapMailNotifierAttributes"`
LdapEmailAttribute string `json:"ldapEmailAttribute"`
AgentLdapBaseDn string `json:"agentLdapBaseDn"`
AgentLdapIDAttribute string `json:"agentLdapIdAttribute"`
AgentLdapJidAttribute string `json:"agentLdapJidAttribute"`
AgentLdapObjectClasses string `json:"agentLdapObjectClasses"`
UserLdapBaseDn string `json:"userLdapBaseDn"`
UserLdapUIDAttribute string `json:"userLdapUidAttribute"`
UserLdapPrivilegeAttribute string `json:"userLdapPrivilegeAttribute"`
UserLdapObjectClasses string `json:"userLdapObjectClasses"`
UserAuthorizationEnabled bool `json:"userAuthorizationEnabled"`
GroupLdapObjectClasses string `json:"groupLdapObjectClasses"`
RoleLdapObjectClasses string `json:"roleLdapObjectClasses"`
UserLdapRolesDn string `json:"userLdapRolesDn"`
GroupLdapBaseDn string `json:"groupLdapBaseDn"`
UserGroupLdapBaseDn string `json:"userGroupLdapBaseDn"`
AhenkGroupLdapBaseDn string `json:"ahenkGroupLdapBaseDn"`
XMPPHost string `json:"xmppHost"`
XMPPPort int `json:"xmppPort"`
XMPPUsername string `json:"xmppUsername"`
XMPPPassword string `json:"xmppPassword"`
XMPPResource string `json:"xmppResource"`
XMPPServiceName string `json:"xmppServiceName"`
XMPPMaxRetryConnectionCount int `json:"xmppMaxRetryConnectionCount"`
XMPPPacketReplayTimeout int `json:"xmppPacketReplayTimeout"`
XMPPPingTimeout int `json:"xmppPingTimeout"`
XMPPUseSsl bool `json:"xmppUseSsl"`
XMPPAllowSelfSignedCert bool `json:"xmppAllowSelfSignedCert"`
XMPPUseCustomSsl bool `json:"xmppUseCustomSsl"`
XMPPPresencePriority int `json:"xmppPresencePriority"`
FileServerProtocol string `json:"fileServerProtocol"`
FileServerHost string `json:"fileServerHost"`
FileServerUsername string `json:"fileServerUsername"`
FileServerPassword string `json:"fileServerPassword"`
FileServerPluginPath string `json:"fileServerPluginPath"`
FileServerAgreementPath string `json:"fileServerAgreementPath"`
FileServerAgentFilePath string `json:"fileServerAgentFilePath"`
FileServerURL interface{} `json:"fileServerUrl"`
FileServerPort int `json:"fileServerPort"`
TaskManagerCheckFutureTask interface{} `json:"taskManagerCheckFutureTask"`
TaskManagerFutureTaskCheckPeriod interface{} `json:"taskManagerFutureTaskCheckPeriod"`
AlarmCheckReport interface{} `json:"alarmCheckReport"`
MailAddress interface{} `json:"mailAddress"`
MailPassword interface{} `json:"mailPassword"`
MailHost interface{} `json:"mailHost"`
MailSMTPPort interface{} `json:"mailSmtpPort"`
MailSMTPAuth interface{} `json:"mailSmtpAuth"`
MailSMTPStartTLSEnable interface{} `json:"mailSmtpStartTlsEnable"`
MailSMTPSslEnable interface{} `json:"mailSmtpSslEnable"`
MailSMTPConnTimeout interface{} `json:"mailSmtpConnTimeout"`
MailSMTPTimeout interface{} `json:"mailSmtpTimeout"`
MailSMTPWriteTimeout interface{} `json:"mailSmtpWriteTimeout"`
MailSendOnTaskCompletion interface{} `json:"mailSendOnTaskCompletion"`
MailCheckTaskCompletionPeriod interface{} `json:"mailCheckTaskCompletionPeriod"`
MailSendOnPolicyCompletion interface{} `json:"mailSendOnPolicyCompletion"`
MailCheckPolicyCompletionPeriod interface{} `json:"mailCheckPolicyCompletionPeriod"`
HotDeploymentPath interface{} `json:"hotDeploymentPath"`
CronTaskList interface{} `json:"cronTaskList"`
EntrySizeLimit interface{} `json:"entrySizeLimit"`
CronIntervalEntrySize interface{} `json:"cronIntervalEntrySize"`
AdDomainName string `json:"adDomainName"`
AdHostName string `json:"adHostName"`
AdIPAddress string `json:"adIpAddress"`
AdAdminUserName string `json:"adAdminUserName"`
AdAdminUserFullDN string `json:"adAdminUserFullDN"`
AdAdminPassword string `json:"adAdminPassword"`
AdPort string `json:"adPort"`
AdUseSSL bool `json:"adUseSSL"`
AdUseTLS bool `json:"adUseTLS"`
AdAllowSelfSignedCert bool `json:"adAllowSelfSignedCert"`
AllowDynamicDNSUpdate bool `json:"allowDynamicDNSUpdate"`
DisableLocalUser bool `json:"disableLocalUser"`
DomainType string `json:"domainType"`
AhenkRepoAddress string `json:"ahenkRepoAddress"`
AhenkRepoKeyAddress string `json:"ahenkRepoKeyAddress"`
AllowVNCConnectionWithoutPermission bool `json:"allowVNCConnectionWithoutPermission"`
PardusRepoAddress interface{} `json:"pardusRepoAddress"`
PardusRepoComponent interface{} `json:"pardusRepoComponent"`
}
func (lider *LiderAhenkConfig)PrintCredentials(){
color.Yellow("------------ Credentials ------------")
color.Yellow("LdapUsername : %s", lider.LdapUsername)
color.Yellow("LdapPassword : %s", lider.LdapPassword)
color.Yellow("LdapRootDn : %s", lider.LdapRootDn)
color.Yellow("XmppUsername : %s", lider.XMPPUsername)
color.Yellow("XmppPassword : %s", lider.XMPPPassword)
color.Yellow("FileServerProtocol : %s", lider.FileServerProtocol)
color.Yellow("FileServerUsername : %s", lider.FileServerUsername)
color.Yellow("FileServerPassword : %s", lider.FileServerPassword)
color.Yellow("Active Directory Hostname : %s", lider.AdHostName)
color.Yellow("Active Directory Username : %s", lider.AdAdminUserName)
color.Yellow("Active Directory Password : %s", lider.AdAdminPassword)
color.Yellow("-------------------------------------")
}
func (lider *LiderAhenkConfig)CheckLDAPCredentials() {
print_info("Checking LDAP credentials")
time.Sleep(1)
l , err := ldap.Dial("tcp", fmt.Sprintf("%s:%s", lider.LdapServer, lider.LdapPort))
if err != nil {
panic_with_msg("Unable to connect to the LDAP service", err)
}
if err = l.Bind(lider.LdapUsername, lider.LdapPassword); err != nil{
panic_with_msg("Failed to auth with LDAP credentials", err)
}
print_good("Great ! LDAP credentials are working !")
lider.LdapConn = l
}
func (l *LiderAhenkConfig)FetchAgentComputers() {
print_info("Fetching computer names managed via Ahenk service")
filter := "(objectClass=Device)"
r, err := l.LdapConn.Search(
ldap.NewSearchRequest(
l.AgentLdapBaseDn,
ldap.ScopeWholeSubtree,
ldap.NeverDerefAliases,
0,
0,
false,
filter,
[]string{},
nil,
),
)
if err != nil {
panic_with_msg("Cant find the computers managed via Ahenk.. Weird.", err)
}
print_good(fmt.Sprintf(
"Number of computers managed via Ahenk : %d",
len(r.Entries),
))
color.Magenta("------------ Computer List Managed via AHENK ------------")
for _, entry := range r.Entries {
for _, attr := range entry.Attributes {
switch attr.Name {
case "cn":
color.Magenta("Computer name : %s", attr.Values)
case "liderDeviceOSType":
color.Magenta("Computer OS Type : %s", attr.Values)
case "userPassword":
color.Magenta("Computer password : %s", attr.Values)
}
}
color.Magenta("\n")
}
color.Magenta("---------------------------------------------------------")
}
func (l *LiderAhenkConfig)FetchLiderConsoleUser() ConsoleUser {
cu := ConsoleUser{}
print_info("Fetching accounts with ROLE_ADMIN privileges")
filter := "(&(objectClass=pardusAccount)(liderPrivilege=ROLE_ADMIN))"
r, err := l.LdapConn.Search(
ldap.NewSearchRequest(
l.LdapRootDn,
ldap.ScopeWholeSubtree,
ldap.NeverDerefAliases,
0,
0,
false,
filter,
[]string{},
nil,
),
)
if err != nil {
panic_with_msg("Cant find the Users with ROLE_ADMIN privileges.. Weird.", err)
}
print_good(fmt.Sprintf(
"Number of user with high privileges : %d",
len(r.Entries),
))
color.Yellow("------------ LDAP Users With ROLE_ADMIN Privileges ------------")
for _, entry := range r.Entries {
for _, attr := range entry.Attributes {
switch attr.Name {
case "cn":
cu.username = attr.Values
color.Yellow("Username : %s", attr.Values)
case "userPassword":
cu.password = attr.Values
color.Yellow("Password : %s", attr.Values)
}
}
color.Yellow("----------------------------------------------------------------")
}
return cu
}