-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathSettings.ascx.vb
294 lines (262 loc) · 15.5 KB
/
Settings.ascx.vb
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
'
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2013
' by DotNetNuke Corporation
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
' DEALINGS IN THE SOFTWARE.
'
Imports DotNetNuke.UI.Skins.Controls
Imports DotNetNuke.Authentication.ActiveDirectory.ADSI
Imports DotNetNuke.Services.Authentication
Imports DotNetNuke.Entities.Portals
Imports DotNetNuke.Framework.Providers
Namespace DotNetNuke.Authentication.ActiveDirectory
Partial Class Settings
Inherits AuthenticationSettingsBase
#Region "Private Members"
Private _strError As String = Null.NullString
#End Region
#Region "Private Methods"
Private Sub DisplayIpError(ByVal strInvalidIP As String)
Dim _
strError As String = strInvalidIP & " " &
Localization.GetString("InValidIPAddress", Me.LocalResourceFile)
tblSettings.Visible = True
pnlError.Visible = True
lblError.Text = strError
End Sub
Private Function GetUserDomainName(ByVal UserName As String) As String
Dim strReturn As String = ""
If UserName.IndexOf("\") > 0 Then
strReturn = Left(UserName, (UserName.IndexOf("\")))
End If
Return strReturn
End Function
Private Function LocalizedStatus(ByVal InputText As String) As String
'Return InputText
Dim strReturn As String = InputText
strReturn =
strReturn.Replace("[Global Catalog Status]",
Localization.GetString("[Global Catalog Status]", Me.LocalResourceFile))
strReturn =
strReturn.Replace("[Root Domain Status]",
Localization.GetString("[Root Domain Status]", Me.LocalResourceFile))
strReturn =
strReturn.Replace("[LDAP Status]", Localization.GetString("[LDAP Status]", Me.LocalResourceFile))
strReturn =
strReturn.Replace("[Network Domains Status]",
Localization.GetString("[Network Domains Status]", Me.LocalResourceFile))
strReturn =
strReturn.Replace("[LDAP Error Message]",
Localization.GetString("[LDAP Error Message]", Me.LocalResourceFile))
strReturn = strReturn.Replace("OK", Localization.GetString("OK", Me.LocalResourceFile))
strReturn = strReturn.Replace("FAIL", Localization.GetString("FAIL", Me.LocalResourceFile))
'
Return strReturn
End Function
Private Function CheckEnteredIPAddr() As Boolean
If Right(Me.txtAutoIP.Text, 1) = ";" Then
Me.txtAutoIP.Text = Left(Me.txtAutoIP.Text, Me.txtAutoIP.Text.Length - 1)
End If
Dim arrIPArray As New ArrayList
Dim arrAutoIP() = Me.txtAutoIP.Text.Split(";")
For intCount As Integer = 0 To arrAutoIP.Length - 1
Dim strAutoIP As String = arrAutoIP(intCount)
Dim intFullIPAddr As Integer = 0
If (InStr(strAutoIP, "-")) Then
Dim arrIPRange() = strAutoIP.Split("-")
For intIPCount As Integer = 0 To arrIPRange.Length - 1
intFullIPAddr = arrIPRange(intIPCount).ToString.Split(".").GetUpperBound(0)
Select Case intFullIPAddr
Case 3
arrIPArray.Add(arrIPRange(intIPCount).ToString)
Case Else
DisplayIpError(arrIPRange(intIPCount).ToString)
Return False
'Exit Function
End Select
Next
Else
intFullIPAddr = arrAutoIP(intCount).ToString.Split(".").GetUpperBound(0)
Select Case intFullIPAddr
Case 3
arrIPArray.Add(arrAutoIP(intCount).ToString)
Case Else
DisplayIpError(arrAutoIP(intCount).ToString)
Return False
'Exit Function
End Select
End If
Next
For intIPCheck As Integer = 0 To arrIPArray.Count - 1
Try
Dim strIPAddr As String = Utilities.GetIP4Address(arrIPArray(intIPCheck))
Catch ex As Exception
DisplayIpError(arrIPArray(intIPCheck))
Return False
'Exit Function
End Try
Next
Return True
End Function
#End Region
#Region "Public Methods"
Public Overrides Sub UpdateSettings()
Dim _portalSettings As PortalSettings = CType(HttpContext.Current.Items("PortalSettings"), PortalSettings)
Try
'Code Cleanup
If Not chkAuthentication.Checked Then
Configuration.UpdateConfig(_portalSettings.PortalId, False, False, "", "", "", "", False, False,
False, "", "", "", "", False, "", False, False, False)
Configuration.ResetConfig()
Else
Dim providerTypeName As String = cboProviders.SelectedItem.Value
Dim authenticationType As String = cboAuthenticationType.SelectedItem.Value
If Not (txtAutoIP.Text = String.Empty) Then
If Not (CheckEnteredIPAddr()) Then
Exit Sub
End If
End If
'ACD-5585
'WorkItems 4766 and 4077
If chkAuthentication.Checked And Not chkHidden.Checked Then
Configuration.UpdateConfig(_portalSettings.PortalId, chkAuthentication.Checked,
chkHidden.Checked,
txtRootDomain.Text, txtEmailDomain.Text, txtUserName.Text,
txtPassword.Text, chkSynchronizeRole.Checked,
chkSynchronizePassword.Checked, chkStripDomainName.Checked,
providerTypeName, authenticationType, txtAutoIP.Text,
txtDefaultDomain.Text, chkAutoCreate.Checked, txtBots.Text,
chkSynchronizePhoto.Checked, chkAutoLogin.Checked, chkDebugMode.Checked)
Else
Configuration.UpdateConfig(_portalSettings.PortalId, False, chkHidden.Checked,
txtRootDomain.Text, txtEmailDomain.Text,
txtUserName.Text, txtPassword.Text, chkSynchronizeRole.Checked,
chkSynchronizePassword.Checked,
chkStripDomainName.Checked, providerTypeName, authenticationType,
txtAutoIP.Text, txtDefaultDomain.Text, chkAutoCreate.Checked, txtBots.Text,
chkSynchronizePhoto.Checked, chkAutoLogin.Checked, chkDebugMode.Checked)
End If
Configuration.ResetConfig()
Dim objAuthenticationController As New AuthenticationController
Dim statusMessage As String = objAuthenticationController.NetworkStatus
If statusMessage.ToLower.IndexOf("fail") > -1 Then
MessageCell.Controls.Add(Skins.Skin.GetModuleMessageControl("", LocalizedStatus(
statusMessage),
ModuleMessage.
ModuleMessageType _
.RedError))
Else
MessageCell.Controls.Add(Skins.Skin.GetModuleMessageControl("", LocalizedStatus(
statusMessage),
ModuleMessage.
ModuleMessageType _
.GreenSuccess))
End If
End If
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
#End Region
#Region "Event Handlers"
Private Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Init
Dim objAuthenticationController As New AuthenticationController
Dim _
objProviderConfiguration As ProviderConfiguration =
ProviderConfiguration.GetProviderConfiguration(Configuration.AUTHENTICATION_KEY)
Dim _Provider As Object
' Bind Authentication provider list, this allows each portal could use different provider for authentication
For Each _Provider In objProviderConfiguration.Providers
Dim objProvider As DictionaryEntry = CType(_Provider, DictionaryEntry)
Dim ProviderName As String = CType(objProvider.Key, String)
Dim ProviderType As String = CType(objProvider.Value, Provider).Type
Me.cboProviders.Items.Add(New ListItem(ProviderName, ProviderType))
Next
' Bind AuthenticationTypes list, on first configure, it could obtains only from default authentication provider
Try
Me.cboAuthenticationType.DataSource = objAuthenticationController.AuthenticationTypes
Catch exc As TypeInitializationException
_strError = Localization.GetString("AuthProviderError", Me.LocalResourceFile)
End Try
Me.cboAuthenticationType.DataBind()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Try
'ACD-8217
'Test for Full Trust
Dim permission As AspNetHostingPermissionLevel = Utilities.GetCurrentTrustLevel()
If Not (permission = AspNetHostingPermissionLevel.Unrestricted) Then
Response.Redirect("~/DesktopModules/AuthenticationServices/ActiveDirectory/trusterror.htm", True)
Else
' Obtain PortalSettings from Current Context
Dim _portalSettings As PortalSettings = PortalController.Instance.GetCurrentPortalSettings
' Reset config
Configuration.ResetConfig()
Dim config As Configuration = Configuration.GetConfig()
If UserInfo.Username.IndexOf("\") > 0 Then
Dim strDomain As String = GetUserDomainName(UserInfo.Username)
If strDomain.ToLower = Request.ServerVariables("SERVER_NAME").ToLower Then
_strError =
String.Format(Localization.GetString("SameDomainError", Me.LocalResourceFile),
strDomain,
HttpUtility.HtmlEncode(Request.ServerVariables("SERVER_NAME")))
End If
End If
If Not Page.IsPostBack Then
chkAuthentication.Checked = config.WindowsAuthentication
chkHidden.Checked = config.HideWindowsLogin
If chkHidden.Checked Then
chkAuthentication.Checked = True
End If
chkSynchronizeRole.Checked = config.SynchronizeRole
chkSynchronizePhoto.Checked = config.Photo
chkSynchronizePassword.Checked = config.SynchronizePassword
chkStripDomainName.Checked = config.StripDomainName
txtRootDomain.Text = config.RootDomain
txtUserName.Text = config.UserName
txtEmailDomain.Text = config.EmailDomain
txtAutoIP.Text = config.AutoIP
'ACD-5585
txtDefaultDomain.Text = config.DefaultDomain
'ACD-4259
chkAutoCreate.Checked = config.AutoCreateUsers
chkAutoLogin.Checked = config.EnableAutoLogin
chkDebugMode.Checked = config.EnableDebugMode
'WorkItems 4766 and 4077
txtBots.Text = config.Bots
If (txtBots.Text = "") Then
txtBots.Text = "gsa-crawler;MS Search 5.0 Robot"
End If
Me.cboAuthenticationType.Items.FindByText(config.AuthenticationType).Selected = True
End If
valConfirm.ErrorMessage = Localization.GetString("PasswordMatchFailure", Me.LocalResourceFile)
If String.IsNullOrEmpty(_strError) Then
tblSettings.Visible = True
pnlError.Visible = False
Else
tblSettings.Visible = False
pnlError.Visible = True
lblError.Text = _strError
End If
End If
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
#End Region
End Class
End Namespace