diff --git a/DDUserManager/DDUserManager/App.config b/DDUserManager/DDUserManager/App.config index 8005d0b..1b93a2f 100644 --- a/DDUserManager/DDUserManager/App.config +++ b/DDUserManager/DDUserManager/App.config @@ -1,25 +1,23 @@ - -
+ +
- -
+ +
- + - + - + diff --git a/DDUserManager/DDUserManager/ClassData.vb b/DDUserManager/DDUserManager/ClassData.vb index 1e9222d..3f2df71 100644 --- a/DDUserManager/DDUserManager/ClassData.vb +++ b/DDUserManager/DDUserManager/ClassData.vb @@ -1,67 +1,72 @@ -Imports DD_LIB_Standards +Imports DigitalData.Modules.Database +Imports DigitalData.Modules.Logging Public Class ClassData - Public Sub New() + Private _logger As Logger + Private _database As MSSQLServer + Public Sub New(LogConfig As LogConfig, Database As MSSQLServer) + _logger = LogConfig.GetLogger() + _database = Database End Sub - Private Shared Function IntToBool(int As Integer) As Boolean + Private Function IntToBool(int As Integer) As Boolean Return int >= 1 End Function - Private Shared Function BoolToInt(bool As Boolean) As Integer + Private Function BoolToInt(bool As Boolean) As Integer Return IIf(bool, 1, 0) End Function - Public Shared Function GroupExists(groupName As String) As Boolean + Public Function GroupExists(groupName As String) As Boolean Try Dim sql As String = $"SELECT COUNT(GUID) FROM TBDD_GROUPS WHERE NAME = '{groupName}'" - Dim result = clsDatabase.Execute_Scalar(sql) + Dim result = _database.GetScalarValue(sql) Return IntToBool(result) Catch ex As Exception - clsLogger.Add($"Error in GroupExists: {ex.Message}") + _logger.Error($"Error in GroupExists: {ex.Message}") Return Nothing End Try End Function - Public Shared Function UserExists(userName As String) As Boolean + Public Function UserExists(userName As String) As Boolean Try Dim sql As String = $"SELECT COUNT(GUID) FROM TBDD_USER WHERE USERNAME = '{userName}'" - Dim result = clsDatabase.Execute_Scalar(sql) + Dim result = _database.GetScalarValue(sql) Return IntToBool(result) Catch ex As Exception - clsLogger.Add($"Error in UserExists: {ex.Message}") + _logger.Error($"Error in UserExists: {ex.Message}") Return Nothing End Try End Function - Public Shared Function InsertUser(username As String, prename As String, name As String, email As String) + Public Function InsertUser(username As String, prename As String, name As String, email As String) Try Dim addedWho As String = Environment.UserName Dim sql As String = $"INSERT INTO TBDD_USER (PRENAME, NAME, USERNAME, EMAIL, ADDED_WHO) VALUES ('{prename}','{name}','{username}','{email}','{addedWho}')" - Dim result = clsDatabase.Execute_non_Query(sql) + Dim result = _database.ExecuteNonQuery(sql) Return True Catch ex As Exception - clsLogger.Add($"Error in InsertUser: {ex.Message}") + _logger.Error(ex) Return False End Try End Function - Public Shared Function InsertGroup(name As String, Optional ECM_FK_ID As Integer = 1, Optional adSync As Boolean = True, Optional internal As Boolean = False, Optional active As Boolean = True) + Public Function InsertGroup(name As String, Optional ECM_FK_ID As Integer = 1, Optional adSync As Boolean = True, Optional internal As Boolean = False, Optional active As Boolean = True) Try Dim addedWho As String = Environment.UserName Dim sql As String = $"INSERT INTO TBDD_GROUPS (NAME, ADDED_WHO, ECM_FK_ID, AD_SYNC, INTERNAL, ACTIVE) VALUES ('{name}', '{addedWho}', {ECM_FK_ID}, {BoolToInt(adSync)}, {BoolToInt(internal)}, {BoolToInt(active)} )" - Dim result = clsDatabase.Execute_non_Query(sql) + Dim result = _database.ExecuteNonQuery(sql) Return True Catch ex As Exception - clsLogger.Add($"Error in InsertGroup: {ex.Message}") + _logger.Error(ex) Return False End Try End Function diff --git a/DDUserManager/DDUserManager/DDUserManager.vbproj b/DDUserManager/DDUserManager/DDUserManager.vbproj index 07125f3..c4fbbd6 100644 --- a/DDUserManager/DDUserManager/DDUserManager.vbproj +++ b/DDUserManager/DDUserManager/DDUserManager.vbproj @@ -11,7 +11,7 @@ DDUserManager 512 WindowsForms - v4.5.2 + v4.6.1 true @@ -51,9 +51,6 @@ user.ico - - P:\Visual Studio Projekte\Bibliotheken\DD_LIB_Standards.dll - @@ -62,6 +59,21 @@ + + ..\..\..\DDMonorepo\Modules.Config\bin\Debug\DigitalData.Modules.Config.dll + + + ..\..\..\DDMonorepo\Modules.Database\bin\Debug\DigitalData.Modules.Database.dll + + + ..\..\..\DDMonorepo\Modules.Filesystem\bin\Debug\DigitalData.Modules.Filesystem.dll + + + ..\..\..\DDMonorepo\Modules.Interfaces\bin\Debug\DigitalData.Modules.Interfaces.dll + + + ..\..\..\DDMonorepo\Modules.Logging\bin\Debug\DigitalData.Modules.Logging.dll + P:\Visual Studio Projekte\Bibliotheken\NLog\NLog.dll @@ -152,6 +164,7 @@ Settings.settings True + True True diff --git a/DDUserManager/DDUserManager/ModuleRuntime.vb b/DDUserManager/DDUserManager/ModuleRuntime.vb index 220705e..fe0d018 100644 --- a/DDUserManager/DDUserManager/ModuleRuntime.vb +++ b/DDUserManager/DDUserManager/ModuleRuntime.vb @@ -1,160 +1,17 @@ Imports System.IO -Imports DD_LIB_Standards +Imports DigitalData.Modules.Config +Imports DigitalData.Modules.Database +Imports DigitalData.Modules.Filesystem +Imports DigitalData.Modules.Logging Module ModuleRuntime Public MyConnectionString As String + Public MyDatabase As MSSQLServer + Public MyLogConfig As LogConfig + Public MyLogger As Logger + Public MyConfig As ConfigManager(Of UserConfig) + Public LogErrorsOnly As Boolean = True Public ConfigPath As String = Path.Combine(Application.UserAppDataPath, "UserConfig.xml") Public ActiveDirectoryRootNode As String = $"LDAP://{Environment.UserDomainName}" - - Public Function SaveMySettingsValue(name As String, value As String, type As String) - Try - Dim DT As DataTable = Nothing - If type = "ConfigMain" Then - DT = GetTablefromXML(ConfigPath) - End If - - If Not IsNothing(DT) Then - For Each Row As DataRow In DT.Rows - If Row.Item("ConfigName") = name Then - Row.Item("Value") = value - End If - Next - DT.AcceptChanges() - DT.WriteXml(ConfigPath) - Else - MsgBox("Setting could not be saved! Check logfile.", MsgBoxStyle.Critical) - End If - - Catch ex As Exception - MsgBox("Error in SaveConfigValue" & vbNewLine & ex.Message, MsgBoxStyle.Critical) - Return False - End Try - Return True - - End Function - - Private Function GetTablefromXML(path As String) As DataTable - Try - Dim DS As New DataSet - DS.ReadXml(path) - Return DS.Tables(0) - Catch ex As Exception - MsgBox("Error in GetTablefromXML" & vbNewLine & ex.Message & vbNewLine & "ConfigPath: " & vbNewLine & path, MsgBoxStyle.Critical) - clsLogger.Add("Error in GetTablefromXML: " & ex.Message, True) - clsLogger.Add(">> ConfigPath: " & ConfigPath, False) - Return Nothing - End Try - End Function - - Public Function MySettings_Load() - Try - Dim DT As DataTable - 'if file doesn't exist, create the file with its default xml table - If Not File.Exists(ConfigPath) Then - clsLogger.Add(">> ConfigFile was created in: " & ConfigPath, False) - DT = CreateConfigTable() - DT.WriteXml(ConfigPath) - clsLogger.Add(">> Defaultvalues were saved.", False) - End If - DT = GetTablefromXML(ConfigPath) - If DT Is Nothing Then - MsgBox("Configuration could not be loaded!! Check LogFile!", MsgBoxStyle.Critical) - Return False - End If - For Each Row As DataRow In DT.Rows - Select Case Row.Item("ConfigName") - Case "MyConnectionString" - Dim connstring As String - 'Den ConnectonString mit verschlüsseltem PW laden - Dim csb As New SqlClient.SqlConnectionStringBuilder - csb.ConnectionString = Row.Item("Value") - If Not csb.ConnectionString = "" Then - If csb.ConnectionString.Contains("Password=") Then - 'sa- - 'Jetzt das Passwort entschlüsseln - Dim PWplainText As String - Dim wrapper As New clsEncryption("!35452didalog=") - ' DecryptData throws if the wrong password is used. - Try - PWplainText = wrapper.DecryptData(csb.Password) - connstring = Row.Item("Value").ToString.Replace(csb.Password, PWplainText) - Catch ex As Exception - clsLogger.Add("- the Password '" & csb.Password & "' could not be decrypted", False) - connstring = "" - End Try - - Else - 'Windows-Auth - connstring = Row.Item("Value").ToString - End If - - MyConnectionString = connstring - Else - MyConnectionString = "" - End If - Case "LogErrorsOnly" - LogErrorsOnly = CBool(Row.Item("Value")) - Case "ActiveDirectoryRootNode" - Dim rootNode As String = Row.Item("Value") - - If rootNode <> String.Empty Then - ActiveDirectoryRootNode = rootNode - End If - End Select - Next - - Catch ex As Exception - MsgBox("Error in LoadMyConfig" & vbNewLine & ex.Message, MsgBoxStyle.Critical) - clsLogger.Add("Error in LoadMyConfig: " & ex.Message, True) - Return False - End Try - Return True - - End Function - - Private Function CreateConfigTable() As DataTable - Try - ' Create sample Customers table, in order - ' to demonstrate the behavior of the DataTableReader. - Dim table As New DataTable - table.TableName = "MyConfig" - - ' Create two columns, ID and Name. - Dim idColumn As DataColumn = table.Columns.Add("ID", - GetType(System.Int32)) - - idColumn.AutoIncrement = True - idColumn.AutoIncrementSeed = 0 - idColumn.AutoIncrementStep = 1 - table.Columns.Add("ConfigName", GetType(System.String)) - table.Columns.Add("Value", GetType(System.String)) - 'Set the ID column as the primary key column. - table.PrimaryKey = New DataColumn() {idColumn} - - Dim newRow As DataRow - - newRow = table.NewRow() - newRow.Item("ConfigName") = "MyConnectionString" - newRow.Item("Value") = "" - table.Rows.Add(newRow) - - newRow = table.NewRow() - newRow.Item("ConfigName") = "LogErrorsOnly" - newRow.Item("Value") = "True" - table.Rows.Add(newRow) - - newRow = table.NewRow() - newRow.Item("ConfigName") = "ActiveDirectoryRootNode" - newRow.Item("Value") = "" - table.Rows.Add(newRow) - - table.AcceptChanges() - clsLogger.Add(">> CreateConfigTable su...", False) - Return table - Catch ex As Exception - MsgBox("Error in CreateConfigTable" & vbNewLine & ex.Message, MsgBoxStyle.Critical) - Return Nothing - End Try - End Function End Module diff --git a/DDUserManager/DDUserManager/UserConfig.vb b/DDUserManager/DDUserManager/UserConfig.vb new file mode 100644 index 0000000..0253d7e --- /dev/null +++ b/DDUserManager/DDUserManager/UserConfig.vb @@ -0,0 +1,11 @@ +Imports DigitalData.Modules.Config +Imports DigitalData.Modules.Filesystem + +Public Class UserConfig + + Public Property ConnectionString As String = "" + Public Property LogErrorsOnly As Boolean = True + Public Property AdGroupFilter As String = "(&(objectClass=group) (samAccountName=*))" + Public Property AdUserFilter As String = "" + Public Property ActiveDirectoryRootNode As String = $"LDAP://{Environment.UserDomainName}" +End Class diff --git a/DDUserManager/DDUserManager/frmADImport_Groups.vb b/DDUserManager/DDUserManager/frmADImport_Groups.vb index ae6f600..18a5eac 100644 --- a/DDUserManager/DDUserManager/frmADImport_Groups.vb +++ b/DDUserManager/DDUserManager/frmADImport_Groups.vb @@ -1,10 +1,15 @@ Imports DevExpress.XtraGrid.Views.Grid +Imports DigitalData.Modules.Logging Public Class frmADImport_Groups - Private Shared logger As NLog.Logger = NLog.LogManager.GetCurrentClassLogger() + Private logger As Logger + Private data As ClassData Private Sub frmADImport_Groups_Load(sender As Object, e As EventArgs) Handles MyBase.Load Try + logger = MyLogConfig.GetLogger() + data = New ClassData(MyLogConfig, MyDatabase) + Dim groups = ClassActiveDirectory.GetActiveDirectoryGroups(My.Settings.AD_GROUP_QUERY) logger.Info("Found {0} groups", groups.Count) @@ -36,8 +41,8 @@ Public Class frmADImport_Groups Dim internal As Boolean = False Dim sync As Boolean = True - If Not ClassData.GroupExists(groupRow.GROUPNAME) Then - ClassData.InsertGroup(groupRow.GROUPNAME) + If Not data.GroupExists(groupRow.GROUPNAME) Then + data.InsertGroup(groupRow.GROUPNAME) importedGroups = importedGroups + 1 End If Next diff --git a/DDUserManager/DDUserManager/frmADImport_Users.vb b/DDUserManager/DDUserManager/frmADImport_Users.vb index 94408a5..d425640 100644 --- a/DDUserManager/DDUserManager/frmADImport_Users.vb +++ b/DDUserManager/DDUserManager/frmADImport_Users.vb @@ -1,15 +1,18 @@ -Imports System.DirectoryServices -Imports System.DirectoryServices.AccountManagement -Imports DDUserManager.UserDataSet +Imports DDUserManager.UserDataSet Imports DevExpress.XtraGrid.Views.Grid -Imports DD_LIB_Standards +Imports DigitalData.Modules.Logging Public Class frmADImport_Users - Private Shared logger As NLog.Logger = NLog.LogManager.GetCurrentClassLogger() + Private logger As Logger + Private data As ClassData + Private Sub frmADImport_Load(sender As Object, e As EventArgs) Handles MyBase.Load Try + logger = MyLogConfig.GetLogger() + data = New ClassData(MyLogConfig, MyDatabase) + Dim groups = ClassActiveDirectory.GetActiveDirectoryGroups(My.Settings.AD_GROUP_QUERY) gridAD_Groups.DataSource = groups.Select(Of String)(Function(g) @@ -63,8 +66,8 @@ Public Class frmADImport_Users Dim Email As String = IIf(IsDBNull(userRow.EMAIL), Nothing, userRow.EMAIL) - If Not ClassData.UserExists(Username) Then - If ClassData.InsertUser(Username, Prename, Name, Email) Then + If Not data.UserExists(Username) Then + If data.InsertUser(Username, Prename, Name, Email) Then importedUsers = importedUsers + 1 Else Throw New Exception($"Could not insert user {Username} into Database. Check the log.") diff --git a/DDUserManager/DDUserManager/frmConfigDatabase.vb b/DDUserManager/DDUserManager/frmConfigDatabase.vb index 68caf65..126e4db 100644 --- a/DDUserManager/DDUserManager/frmConfigDatabase.vb +++ b/DDUserManager/DDUserManager/frmConfigDatabase.vb @@ -1,11 +1,16 @@ -Imports System.IO -Imports DD_LIB_Standards +Imports DigitalData.Modules.Database +Imports DigitalData.Modules.Filesystem +Imports DigitalData.Modules.Logging Public Class frmConfigDatabase Private ConnectionChanged As Boolean = False Private Sub frmConfigDatabase_Load(sender As Object, e As EventArgs) Handles MyBase.Load + If MyLogConfig Is Nothing Then + MyLogConfig = New LogConfig(LogConfig.PathType.AppData) + End If + If Not MyConnectionString = String.Empty Then ConnectionChanged = False @@ -95,17 +100,21 @@ Public Class frmConfigDatabase ConnectionChanged = True 'Set the construction string MyConnectionString = con - clsDatabase.Init(MyConnectionString) + + + MyDatabase = New MSSQLServer(MyLogConfig, MyConnectionString) + My.Settings.Save() If chkbxUserAut.Checked = False Then - Dim wrapper As New clsEncryption("!35452didalog=") + Dim wrapper As New EncryptionLegacy("!35452didalog=") Dim cipherText As String = wrapper.EncryptData(Me.txtPasswort.Text) Dim pw As String = cipherText con = "Server=" & Me.txtServer.Text & ";Database=" & Me.cmbDatenbank.Text & ";User Id=" & Me.txtUser.Text & ";Password=" & pw & ";" End If - SaveMySettingsValue("MyConnectionString", con, "ConfigMain") + MyConfig.Config.ConnectionString = con + MyConfig.Save() Dim csb As New SqlClient.SqlConnectionStringBuilder csb.ConnectionString = MyConnectionString diff --git a/DDUserManager/DDUserManager/frmMain.Designer.vb b/DDUserManager/DDUserManager/frmMain.Designer.vb index 36bba75..332d324 100644 --- a/DDUserManager/DDUserManager/frmMain.Designer.vb +++ b/DDUserManager/DDUserManager/frmMain.Designer.vb @@ -356,6 +356,11 @@ Partial Class frmMain Me.TableAdapterManager1 = New DDUserManager.DS_ChangeSTableAdapters.TableAdapterManager() Me.TBDD_GROUPS_USERTableAdapter = New DDUserManager.UserDataSetTableAdapters.TBDD_GROUPS_USERTableAdapter() Me.QueriesTableAdapter1 = New DDUserManager.UserDataSetTableAdapters.QueriesTableAdapter() + Me.Button3 = New System.Windows.Forms.Button() + Me.GroupBox3 = New System.Windows.Forms.GroupBox() + Me.Button4 = New System.Windows.Forms.Button() + Me.txtLDAPUserQuery = New System.Windows.Forms.TextBox() + Me.Button5 = New System.Windows.Forms.Button() GUIDLabel = New System.Windows.Forms.Label() PRENAMELabel = New System.Windows.Forms.Label() NAMELabel = New System.Windows.Forms.Label() @@ -517,6 +522,7 @@ Partial Class frmMain CType(Me.TBDD_CLIENT_USERBindingSource, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.TBDD_USER_MODULESBindingSource, System.ComponentModel.ISupportInitialize).BeginInit() Me.StatusStrip1.SuspendLayout() + Me.GroupBox3.SuspendLayout() Me.SuspendLayout() ' 'GUIDLabel @@ -3500,6 +3506,7 @@ Partial Class frmMain 'tabPageSettings ' Me.tabPageSettings.Controls.Add(Me.Button2) + Me.tabPageSettings.Controls.Add(Me.GroupBox3) Me.tabPageSettings.Controls.Add(Me.GroupBox2) Me.tabPageSettings.Controls.Add(Me.GroupBox1) Me.tabPageSettings.Controls.Add(Me.btnOpenLogDir) @@ -3523,6 +3530,7 @@ Partial Class frmMain ' 'GroupBox2 ' + Me.GroupBox2.Controls.Add(Me.Button3) Me.GroupBox2.Controls.Add(Me.btnDebugGroupQuery) Me.GroupBox2.Controls.Add(Me.txtLDAPGroupQuery) Me.GroupBox2.Location = New System.Drawing.Point(486, 17) @@ -3530,7 +3538,7 @@ Partial Class frmMain Me.GroupBox2.Size = New System.Drawing.Size(700, 200) Me.GroupBox2.TabIndex = 5 Me.GroupBox2.TabStop = False - Me.GroupBox2.Text = "LDAP Gruppenabfrage" + Me.GroupBox2.Text = "LDAP Filter für Gruppenabfrage" ' 'btnDebugGroupQuery ' @@ -3730,6 +3738,55 @@ Partial Class frmMain ' Me.TBDD_GROUPS_USERTableAdapter.ClearBeforeFill = True ' + 'Button3 + ' + Me.Button3.Location = New System.Drawing.Point(438, 171) + Me.Button3.Name = "Button3" + Me.Button3.Size = New System.Drawing.Size(112, 23) + Me.Button3.TabIndex = 7 + Me.Button3.Text = "Speichern" + Me.Button3.UseVisualStyleBackColor = True + ' + 'GroupBox3 + ' + Me.GroupBox3.Controls.Add(Me.Button4) + Me.GroupBox3.Controls.Add(Me.Button5) + Me.GroupBox3.Controls.Add(Me.txtLDAPUserQuery) + Me.GroupBox3.Location = New System.Drawing.Point(486, 239) + Me.GroupBox3.Name = "GroupBox3" + Me.GroupBox3.Size = New System.Drawing.Size(700, 200) + Me.GroupBox3.TabIndex = 5 + Me.GroupBox3.TabStop = False + Me.GroupBox3.Text = "LDAP Filter für Benutzerabfrage" + ' + 'Button4 + ' + Me.Button4.Location = New System.Drawing.Point(438, 171) + Me.Button4.Name = "Button4" + Me.Button4.Size = New System.Drawing.Size(112, 23) + Me.Button4.TabIndex = 7 + Me.Button4.Text = "Speichern" + Me.Button4.UseVisualStyleBackColor = True + ' + 'txtLDAPUserQuery + ' + Me.txtLDAPUserQuery.Location = New System.Drawing.Point(6, 20) + Me.txtLDAPUserQuery.Multiline = True + Me.txtLDAPUserQuery.Name = "txtLDAPUserQuery" + Me.txtLDAPUserQuery.ScrollBars = System.Windows.Forms.ScrollBars.Vertical + Me.txtLDAPUserQuery.Size = New System.Drawing.Size(688, 145) + Me.txtLDAPUserQuery.TabIndex = 2 + Me.txtLDAPUserQuery.Text = "(&(objectClass=group) (samAccountName=*))" + ' + 'Button5 + ' + Me.Button5.Location = New System.Drawing.Point(556, 171) + Me.Button5.Name = "Button5" + Me.Button5.Size = New System.Drawing.Size(138, 23) + Me.Button5.TabIndex = 6 + Me.Button5.Text = "Abfrage starten" + Me.Button5.UseVisualStyleBackColor = True + ' 'frmMain ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) @@ -3884,6 +3941,8 @@ Partial Class frmMain CType(Me.TBDD_USER_MODULESBindingSource, System.ComponentModel.ISupportInitialize).EndInit() Me.StatusStrip1.ResumeLayout(False) Me.StatusStrip1.PerformLayout() + Me.GroupBox3.ResumeLayout(False) + Me.GroupBox3.PerformLayout() Me.ResumeLayout(False) Me.PerformLayout() @@ -4189,4 +4248,9 @@ Partial Class frmMain Friend WithEvents btnDebugGroupQuery As Button Friend WithEvents txtLDAPGroupQuery As TextBox Friend WithEvents QueriesTableAdapter1 As UserDataSetTableAdapters.QueriesTableAdapter + Friend WithEvents Button3 As Button + Friend WithEvents GroupBox3 As GroupBox + Friend WithEvents Button4 As Button + Friend WithEvents txtLDAPUserQuery As TextBox + Friend WithEvents Button5 As Button End Class diff --git a/DDUserManager/DDUserManager/frmMain.vb b/DDUserManager/DDUserManager/frmMain.vb index f64caca..3cf53d9 100644 --- a/DDUserManager/DDUserManager/frmMain.vb +++ b/DDUserManager/DDUserManager/frmMain.vb @@ -1,9 +1,10 @@ Imports DevExpress.XtraGrid Imports DevExpress.XtraGrid.Views.Grid Imports DDUserManager.UserDataSet -Imports DDUserManager.DS_ChangeS -Imports DD_LIB_Standards +Imports DigitalData.Modules.Logging +Imports DigitalData.Modules.Config Imports System.Reflection +Imports DigitalData.Modules.Filesystem ''' ''' Anmerkungen: @@ -19,32 +20,32 @@ Public Class frmMain Private DragDropManager As ClassDragDrop = Nothing - Private Shared logger As NLog.Logger = NLog.LogManager.GetCurrentClassLogger() - Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load Try - NLog.LogManager.Configuration = ClassNLog.GetLoggerConfigFor(MODULE_NAME) + MyLogConfig = New LogConfig(LogConfig.PathType.AppData) + MyLogger = MyLogConfig.GetLogger() + MyConfig = New ConfigManager(Of UserConfig)(MyLogConfig, Application.UserAppDataPath) + + LoadConfig(MyConfig) + CurrentVersion = Assembly.GetEntryAssembly().GetName().Version.ToString() txtLDAPGroupQuery.DataBindings.Add(New Binding("Text", My.Settings, "AD_GROUP_QUERY")) + MyLogger.Info("Starting UserManager v" & CurrentVersion) + MyLogger.Info($"Current Username: {Environment.UserName}") - logger.Info("Starting UserManager v" & CurrentVersion) - logger.Info($"Current Username: {Environment.UserName}") - - If InitDatabase() = False Then - MsgBox($"Unexpected error in Database Init(1). {vbCrLf & vbCrLf}Please contact Your admin.", MsgBoxStyle.Critical, "UserManager") - logger.Fatal($"Unexpected error in Database Init(1). {vbCrLf & vbCrLf}Please contact Your admin.") - Application.Exit() - Exit Sub - End If If MyConnectionString = "" Then - MsgBox($"Unexpected error in Database Init(2). {vbCrLf & vbCrLf}Please contact Your admin.", MsgBoxStyle.Critical, "UserManager") - logger.Fatal($"Unexpected error in Database Init(2). {vbCrLf & vbCrLf}Please contact Your admin.") + frmConfigDatabase.ShowDialog() + + 'MsgBox($"Unexpected error in Database Init(2). {vbCrLf & vbCrLf}Please contact Your admin.", MsgBoxStyle.Critical, "UserManager") + 'MyLogger.Error($"Unexpected error in Database Init(2). {vbCrLf & vbCrLf}Please contact Your admin.") Application.Exit() Exit Sub End If + MyDatabase = New DigitalData.Modules.Database.MSSQLServer(MyLogConfig, MyConnectionString) + TBDD_CLIENTTableAdapter.Connection.ConnectionString = MyConnectionString TBDD_CLIENT_USERTableAdapter.Connection.ConnectionString = MyConnectionString TBDD_GROUPSTableAdapter.Connection.ConnectionString = MyConnectionString @@ -56,11 +57,11 @@ Public Class frmMain TBDD_USER_MODULESTableAdapter.Connection.ConnectionString = MyConnectionString Dim sql = String.Format("SELECT * FROM [dbo].[FNDD_CHECK_USER_MODULE] ('{0}','UM',{1})", Environment.UserName, 1) - Dim DT_CHECKUSER_MODULE As DataTable = clsDatabase.Return_Datatable(sql) + Dim DT_CHECKUSER_MODULE As DataTable = MyDatabase.GetDatatable(sql) If DT_CHECKUSER_MODULE.Rows.Count = 0 Then MsgBox($"Der Benutzer '{Environment.UserName}' ist nicht zur Benutzerverwaltung berechtigt. {vbCrLf & vbCrLf}Bitte kontaktieren Sie den Administrator, wenn dies ein Fehler ist.", MsgBoxStyle.Critical, "UserManager") - logger.Warn($"Der Benutzer '{Environment.UserName}' ist nicht zur Benutzerverwaltung berechtigt.") + MyLogger.Warn($"Der Benutzer '{Environment.UserName}' ist nicht zur Benutzerverwaltung berechtigt.") Application.ExitThread() End If @@ -69,7 +70,7 @@ Public Class frmMain If userId = 0 Then MsgBox($"Der Benutzer '{Environment.UserName}' ist nicht in der Benutzerverwaltung vorhanden. {vbCrLf & vbCrLf}Bitte kontaktieren Sie den Administrator, wenn dies ein Fehler ist.", MsgBoxStyle.Critical, "UserManager") - logger.Warn($"Der Benutzer '{Environment.UserName}' ist nicht in der Benutzerverwaltung vorhanden.") + MyLogger.Warn($"Der Benutzer '{Environment.UserName}' ist nicht in der Benutzerverwaltung vorhanden.") Application.ExitThread() End If @@ -112,51 +113,55 @@ Public Class frmMain DragDropManager.AddGridView(viewModulesGroups_AvailableGroups) Else MsgBox($"Der Benutzer '{Environment.UserName}' ist nicht zur Benutzerverwaltung berechtigt. {vbCrLf & vbCrLf}Bitte kontaktieren Sie den Administrator, wenn dies ein Fehler ist.", MsgBoxStyle.Critical, "UserManager") - logger.Warn($"Der Benutzer '{Environment.UserName}' ist nicht zur Benutzerverwaltung berechtigt.") + MyLogger.Warn($"Der Benutzer '{Environment.UserName}' ist nicht zur Benutzerverwaltung berechtigt.") Application.ExitThread() End If If TBDD_USERTableAdapter.IsUserManagerAdmin(Environment.UserName) <> 1 Then MsgBox($"Der Benutzer '{Environment.UserName}' ist nicht zur Benutzerverwaltung berechtigt. {vbCrLf & vbCrLf}Bitte kontaktieren Sie den Administrator, wenn dies ein Fehler ist.", MsgBoxStyle.Critical, "UserManager") - logger.Warn($"Der Benutzer '{Environment.UserName}' ist nicht zur Benutzerverwaltung berechtigt.") + MyLogger.Warn($"Der Benutzer '{Environment.UserName}' ist nicht zur Benutzerverwaltung berechtigt.") Application.ExitThread() End If Catch ex As Exception MsgBox("Unexpected Error while loading. Please check the log.", MsgBoxStyle.Critical, "User Manager") - logger.Fatal(ex, "Unexpected Error while loading.") + MyLogger.Fatal(ex, "Unexpected Error while loading.") End Try End Sub - Public Function InitDatabase() - Try - Dim dbResult As Boolean + Private Sub LoadConfig(ConfigManager As ConfigManager(Of UserConfig)) + Dim oConnectionString As String = "" + Dim csb As New SqlClient.SqlConnectionStringBuilder + csb.ConnectionString = ConfigManager.Config.ConnectionString - MySettings_Load() + If Not csb.ConnectionString = "" Then + If csb.ConnectionString.Contains("Password=") Then + 'sa- + 'Jetzt das Passwort entschlüsseln + Dim PWplainText As String + Dim wrapper As New EncryptionLegacy("!35452didalog=") + ' DecryptData throws if the wrong password is used. + Try + PWplainText = wrapper.DecryptData(csb.Password) + oConnectionString = ConfigManager.Config.ConnectionString.Replace(csb.Password, PWplainText) + Catch ex As Exception + MyLogger.Error(ex) + MyLogger.Warn("- the Password '" & csb.Password & "' could not be decrypted", False) + oConnectionString = "" + End Try - clsDatabase.GUI = True - If MyConnectionString <> String.Empty Then - dbResult = clsDatabase.Init(MyConnectionString) Else - frmConfigDatabase.ShowDialog() - dbResult = clsDatabase.Init(MyConnectionString) + 'Windows-Auth + oConnectionString = ConfigManager.Config.ConnectionString End If - clsDatabase.Init(MyConnectionString) - If dbResult = False Then - If clsLogger.LOGG_MSG <> String.Empty Then - Throw New Exception("Error while Initializing database:" & vbNewLine & clsLogger.LOGG_MSG) - Else - Throw New Exception("Find more information in the logfile.") - End If - End If - Return True - Catch ex As Exception - logger.Fatal(ex, "Unexpected Error in Init Database:") - MsgBox("Unexpected Error in Init Database:" & vbNewLine & ex.Message, MsgBoxStyle.Critical) + MyConnectionString = oConnectionString + Else + MyConnectionString = "" + End If - Return False - End Try - End Function + LogErrorsOnly = MyConfig.Config.LogErrorsOnly + ActiveDirectoryRootNode = MyConfig.Config.ActiveDirectoryRootNode + End Sub Private Sub btnImportUsers_Click(sender As Object, e As EventArgs) Handles btnImportUsers.Click Dim frm As New frmADImport_Users() @@ -1036,7 +1041,7 @@ Public Class frmMain #End Region Private Sub ShowErrorMessage(errorText As String, ex As Exception) - logger.Error(ex, errorText) + MyLogger.Error(ex, errorText) MsgBox(errorText & vbCrLf & vbCrLf & ex.Message, MsgBoxStyle.Critical, "User Manager") End Sub @@ -1069,8 +1074,9 @@ Public Class frmMain Process.Start(ClassNLog.GetLogPathFor(MODULE_NAME)) End Sub - Private Sub txtADRootNode_Leave(sender As Object, e As EventArgs) Handles txtADRootNode.Leave, txtLDAPGroupQuery.Leave - SaveMySettingsValue("ActiveDirectoryRootNode", txtADRootNode.Text, "ConfigMain") + Private Sub txtADRootNode_Leave(sender As Object, e As EventArgs) Handles txtADRootNode.Leave, txtLDAPGroupQuery.Leave, txtLDAPUserQuery.Leave + MyConfig.Config.ActiveDirectoryRootNode = txtADRootNode.Text + MyConfig.Save() End Sub @@ -1081,8 +1087,10 @@ Public Class frmMain If ClassActiveDirectory.ConnectionTest(txtADRootNode.Text) Then MsgBox("Verbindung erfolgreich aufgebaut!", MsgBoxStyle.Information) - SaveMySettingsValue("ActiveDirectoryRootNode", txtADRootNode.Text, "ConfigMain") - logger.Info($"New ActiveDirectory Path saved: {txtADRootNode.Text}") + MyConfig.Config.ActiveDirectoryRootNode = txtADRootNode.Text + MyConfig.Save() + + MyLogger.Info($"New ActiveDirectory Path saved: {txtADRootNode.Text}") End If End Sub @@ -1090,9 +1098,7 @@ Public Class frmMain Process.Start("https://didalog.de/support") End Sub - Private Async Sub btnDebugQuery_Click(sender As Object, e As EventArgs) Handles btnDebugGroupQuery.Click - My.Settings.Save() - + Private Async Sub btnDebugQuery_Click(sender As Object, e As EventArgs) Handles btnDebugGroupQuery.Click, Button5.Click btnDebugGroupQuery.Text = "Abfrage läuft..." btnDebugGroupQuery.Enabled = False @@ -1116,7 +1122,7 @@ Public Class frmMain If MessageBox.Show(oMessage, "Benutzer löschen", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then Dim osql = $"EXEC PRDD_DELETE_USER {oUserId}" - If clsDatabase.Execute_Scalar(osql) = -1 Then + If MyDatabase.GetScalarValue(osql) = -1 Then MessageBox.Show("Fehler beim Löschen des Benutzers.", "Benutzer löschen", MessageBoxButtons.OK, MessageBoxIcon.Warning) Else UpdateSavedLabel() @@ -1124,4 +1130,17 @@ Public Class frmMain End If End If End Sub + + Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click, Button4.Click + MyConfig.Config.AdGroupFilter = txtLDAPGroupQuery.Text + MyConfig.Save() + End Sub + + Private Sub XtraTabControl1_SelectedPageChanged(sender As Object, e As DevExpress.XtraTab.TabPageChangedEventArgs) Handles XtraTabControl1.SelectedPageChanged + If e.Page.Name = tabPageSettings.Name Then + txtADRootNode.Text = MyConfig.Config.ActiveDirectoryRootNode + txtLDAPGroupQuery.Text = MyConfig.Config.AdGroupFilter + txtLDAPUserQuery.Text = MyConfig.Config.AdUserFilter + End If + End Sub End Class