diff --git a/EnvelopeGenerator.Common/Entities/DbConfig.vb b/EnvelopeGenerator.Common/Entities/DbConfig.vb index 441218ae..fc94f3d9 100644 --- a/EnvelopeGenerator.Common/Entities/DbConfig.vb +++ b/EnvelopeGenerator.Common/Entities/DbConfig.vb @@ -5,9 +5,10 @@ Public Property DocumentPath_DMZ As String = "" Public Property ExportPath_DMZ As String = "" Public Property DOCUMENT_PATH_MOVE_AFTSEND As String = "" - Public Property SignedMail_Path As String = "" + Public Property FINISHED_PATH_EX_DMZ As String = "" + Public Property EML_PATH_EX_DMZ As String = "" Public Property SendingProfile As Integer = 0 Public Property SignatureHost As String = "" - - + Public Property NetUse_necessary As Boolean = False + Public Property NetUse_Finish As Boolean = False End Class diff --git a/EnvelopeGenerator.Common/EnvelopeGenerator.Common.vbproj b/EnvelopeGenerator.Common/EnvelopeGenerator.Common.vbproj index b69b1e69..d0d1b92e 100644 --- a/EnvelopeGenerator.Common/EnvelopeGenerator.Common.vbproj +++ b/EnvelopeGenerator.Common/EnvelopeGenerator.Common.vbproj @@ -264,6 +264,7 @@ + MyApplicationCodeGenerator Application.Designer.vb diff --git a/EnvelopeGenerator.Common/Helpers.vb b/EnvelopeGenerator.Common/Helpers.vb index 0615f236..48df1bdc 100644 --- a/EnvelopeGenerator.Common/Helpers.vb +++ b/EnvelopeGenerator.Common/Helpers.vb @@ -1,9 +1,28 @@ Imports System.Drawing Imports System.IO +Imports System.Security.Cryptography +Imports System.Text Imports DevExpress.Utils.Svg Imports EnvelopeGenerator.Common.Constants Public Class Helpers + Private Shared key As String = "$xzBvyPETUS&amm8)D8x#)f;4%;?[BPd" ' Passwort-Schlüssel (16, 24, or 32 bytes) + Private Shared iv As String = "1wN&e[zrQ6_B7X/0" ' Initialisierungsvektor (16 bytes) + + ' Entschlüsselungsfunktion + Public Shared Function Decrypt(cipherText As String) As String + Dim aesAlg As Aes = Aes.Create() + aesAlg.Key = Encoding.UTF8.GetBytes(key) + aesAlg.IV = Encoding.UTF8.GetBytes(iv) + Dim decryptor As ICryptoTransform = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV) + Dim cipherBytes As Byte() = Convert.FromBase64String(cipherText) + Dim msDecrypt As New IO.MemoryStream(cipherBytes) + Using csDecrypt As New CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read) + Using srDecrypt As New IO.StreamReader(csDecrypt) + Return srDecrypt.ReadToEnd() + End Using + End Using + End Function ''' ''' Encodes the EnvelopeUUID and the ReceiverSignature into an EnvelopeKey diff --git a/EnvelopeGenerator.Common/Jobs/FinalizeDocument/FinalizeDocumentJob.vb b/EnvelopeGenerator.Common/Jobs/FinalizeDocument/FinalizeDocumentJob.vb index e5722466..0e6fe232 100644 --- a/EnvelopeGenerator.Common/Jobs/FinalizeDocument/FinalizeDocumentJob.vb +++ b/EnvelopeGenerator.Common/Jobs/FinalizeDocument/FinalizeDocumentJob.vb @@ -9,6 +9,9 @@ Imports EnvelopeGenerator.Common.Jobs.FinalizeDocument.FinalizeDocumentException Imports EnvelopeGenerator.Common.Jobs.FinalizeDocument Imports EnvelopeGenerator.Common.My.Resources Imports EnvelopeGenerator.Common.Constants +Imports DevExpress.XtraBars.Docking +Imports System.ServiceModel +Imports DevExpress.XtraRichEdit.Export Namespace Jobs Public Class FinalizeDocumentJob @@ -76,16 +79,48 @@ Namespace Jobs Logger.Debug("Loading ReportCreator..") ReportCreator = New ReportCreator(LogConfig, oState) + + If My.Settings.RuninDMZ = True Then + If Config.DocumentPath_DMZ <> String.Empty Then + Logger.Debug("RuninDMZ - Using DocumentPath_DMZ: [{0}] - Overwrite Document-Path", Config.DocumentPath_DMZ) + Config.DocumentPath = Config.DocumentPath_DMZ + Config.NetUse_necessary = True + Else + Config.DocumentPath = Config.DocumentPath + End If + Else + If Config.DOCUMENT_PATH_MOVE_AFTSEND <> String.Empty Then + Logger.Debug("Using DMZRemotePath: [{0}] - Overwrite Document-Path", Config.DOCUMENT_PATH_MOVE_AFTSEND) + Config.DocumentPath = Config.DOCUMENT_PATH_MOVE_AFTSEND + Config.NetUse_necessary = True + Else + Config.DocumentPath = Config.DocumentPath + End If + End If Logger.Debug("DocumentPath: [{0}]", Config.DocumentPath) - If Config.DocumentPath_DMZ <> String.Empty Then - Logger.Debug("DMZ-DocPath configured: [{0}] - Overwrite Document-Path", Config.DocumentPath_DMZ) - Config.DocumentPath = Config.DocumentPath_DMZ + If My.Settings.RuninDMZ = True Then + If Config.FINISHED_PATH_EX_DMZ <> String.Empty Then + Logger.Debug("RuninDMZ - FINISHED_PATH_EX_DMZ configured: [{0}]", Config.FINISHED_PATH_EX_DMZ) + Config.NetUse_Finish = True + End If + If Config.ExportPath_DMZ <> String.Empty Then + Logger.Debug("RuninDMZ - Using ExportPath_DMZ: [{0}] - Overwrite ExportPath", Config.ExportPath_DMZ) + Config.ExportPath = Config.ExportPath_DMZ + Else + Config.ExportPath = Config.ExportPath + End If + + ElseIf Config.DOCUMENT_PATH_MOVE_AFTSEND <> String.Empty Then + Logger.Debug("DOCUMENT_PATH_MOVE_AFTSEND configured: [{0}] - Overwrite ExportPath", Config.DOCUMENT_PATH_MOVE_AFTSEND) + Config.ExportPath = Config.DOCUMENT_PATH_MOVE_AFTSEND + Config.NetUse_Finish = True + Else + Config.ExportPath = Config.ExportPath End If + + Logger.Debug("ExportPath: [{0}]", Config.ExportPath) - If Config.ExportPath_DMZ <> String.Empty Then - Logger.Debug("DMZ-ExportPath configured: [{0}] - Overwrite ExportPath", Config.ExportPath_DMZ) - Config.ExportPath = Config.ExportPath_DMZ - End If + Dim oCompleteStatus As Integer = Constants.EnvelopeStatus.EnvelopeCompletelySigned Dim oSql = $"SELECT * FROM TBSIG_ENVELOPE WHERE STATUS = {oCompleteStatus} AND DATEDIFF(minute, CHANGED_WHEN, GETDATE()) >= {CompleteWaitTimeInMinutes}" Dim oTable = Database.GetDatatable(oSql) @@ -140,8 +175,8 @@ Namespace Jobs Logger.Debug("Documents merged.") Dim oOutputDirectoryPath = Config.ExportPath - Dim oOutputFilePath = Path.Combine(oOutputDirectoryPath, $"{oEnvelope.Uuid}.pdf") + Dim oOutputFilePath = Path.Combine(oOutputDirectoryPath, $"{oEnvelope.Uuid}.pdf") Logger.Info("Writing finalized Pdf to disk..") Logger.Info("Output path is [{0}]", oOutputFilePath) @@ -154,6 +189,22 @@ Namespace Jobs Logger.Info("Sending final Emails..") + If Config.NetUse_Finish = True Then + If Config.FINISHED_PATH_EX_DMZ <> String.Empty Then + If My.Settings.NetUse_PW <> String.Empty And My.Settings.NetUse_Usr <> String.Empty Then + Dim oReturnPath = MoveFileWithNetUse(oOutputFilePath, Config.FINISHED_PATH_EX_DMZ, My.Settings.NetUse_Usr, My.Settings.NetUse_PW) + If oReturnPath <> String.Empty Then + oOutputFilePath = oReturnPath + If Config.EML_PATH_EX_DMZ <> String.Empty Then + oOutputFilePath = oOutputFilePath.Replace(Config.FINISHED_PATH_EX_DMZ, Config.EML_PATH_EX_DMZ) + End If + End If + End If + End If + End If + + + If SendFinalEmails(oEnvelope, oOutputFilePath) = False Then Throw New ApplicationException("Final emails could not be sent!") End If @@ -188,6 +239,50 @@ Namespace Jobs Return Task.FromResult(True) End Function + Private Function MoveFileWithNetUse(pSourcePath As String, pDestinationPath As String, pUsername As String, pPassword As String) As String + Dim oDectryptedPW = Helpers.Decrypt(My.Settings.NetUse_PW) + Dim oFilename = System.IO.Path.GetFileName(pSourcePath) + + Dim netUseCommand As String = $"net use {pDestinationPath} /user:{pUsername} {oDectryptedPW}" + + Dim processInfo As New ProcessStartInfo("cmd.exe", $"/C {netUseCommand}") + processInfo.RedirectStandardOutput = True + processInfo.UseShellExecute = False + processInfo.CreateNoWindow = True + + Using process As Process = Process.Start(processInfo) + process.WaitForExit() + + ' Prüfe den Rückgabewert des net use Befehls + If process.ExitCode = 0 Then + ' Verschiebe die Datei + Try + Dim oFilePath As String = pSourcePath + + Dim split As String() = oFilePath.Split("\") + Dim parentFolder As String = split(split.Length - 2) + pDestinationPath &= "\" + parentFolder + If Not System.IO.Directory.Exists(pDestinationPath) Then + System.IO.Directory.CreateDirectory(pDestinationPath) + End If + pDestinationPath &= "\" + oFilename + If File.Exists(pDestinationPath) Then + File.Delete(pDestinationPath) + End If + Logger.Info($"MoveFileWithNetUse To {pDestinationPath} ...") + System.IO.File.Move(pSourcePath, pDestinationPath) + Return pDestinationPath + Catch ex As Exception + Logger.Error(ex) + Return "" + End Try + + Else + Logger.Warn("Error while connecting to network-path " & pDestinationPath) + Return "" + End If + End Using + End Function Private Function SendFinalEmails(pEnvelope As Envelope, pAttachment As String) As Boolean Dim oMailToCreator = pEnvelope.FinalEmailToCreator Dim oMailToReceivers = pEnvelope.FinalEmailToReceivers @@ -199,12 +294,7 @@ Namespace Jobs If oMailToReceivers <> FinalEmailType.No Then Logger.Debug("Sending emails to receivers..") - If Config.SignedMail_Path <> String.Empty And Config.ExportPath_DMZ <> String.Empty Then - Logger.Debug("SignedMailPath configured: [{0}] - Replacing Attachment-Path", Config.SignedMail_Path) - Logger.Debug("Attachment-Path BEFORE replace: [{0}]", pAttachment) - pAttachment.Replace(Config.ExportPath, Config.SignedMail_Path) - Logger.Debug("Attachment-Path AFTER replace: [{0}]", pAttachment) - End If + SendFinalEmailToReceivers(pEnvelope, pAttachment) End If diff --git a/EnvelopeGenerator.Common/Models/ConfigModel.vb b/EnvelopeGenerator.Common/Models/ConfigModel.vb index ad38df88..4769fc38 100644 --- a/EnvelopeGenerator.Common/Models/ConfigModel.vb +++ b/EnvelopeGenerator.Common/Models/ConfigModel.vb @@ -23,8 +23,9 @@ Public Class ConfigModel .SendingProfile = oRow.ItemEx("SENDING_PROFILE", 0), .SignatureHost = oRow.ItemEx("SIGNATURE_HOST", ""), .ExternalProgramName = oRow.ItemEx("EXTERNAL_PROGRAM_NAME", ""), - .SignedMail_Path = oRow.ItemEx("SIGNED_MAIL_PATH", ""), - .DOCUMENT_PATH_MOVE_AFTSEND = oRow.ItemEx("DOCUMENT_PATH_MOVE_AFTSEND", "") + .DOCUMENT_PATH_MOVE_AFTSEND = oRow.ItemEx("DOCUMENT_PATH_MOVE_AFTSEND", ""), + .FINISHED_PATH_EX_DMZ = oRow.ItemEx("FINISHED_PATH_EX_DMZ", ""), + .EML_PATH_EX_DMZ = oRow.ItemEx("EML_PATH_EX_DMZ", "") } Catch ex As Exception Logger.Error(ex) diff --git a/EnvelopeGenerator.Common/My Project/AssemblyInfo.vb b/EnvelopeGenerator.Common/My Project/AssemblyInfo.vb index 39d45912..9b4d76e6 100644 --- a/EnvelopeGenerator.Common/My Project/AssemblyInfo.vb +++ b/EnvelopeGenerator.Common/My Project/AssemblyInfo.vb @@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices ' indem Sie "*" wie unten gezeigt eingeben: ' - - + + diff --git a/EnvelopeGenerator.Common/My Project/Settings.Designer.vb b/EnvelopeGenerator.Common/My Project/Settings.Designer.vb index eb775715..576fa5a0 100644 --- a/EnvelopeGenerator.Common/My Project/Settings.Designer.vb +++ b/EnvelopeGenerator.Common/My Project/Settings.Designer.vb @@ -15,7 +15,7 @@ Option Explicit On Namespace My _ Partial Friend NotInheritable Class MySettings Inherits Global.System.Configuration.ApplicationSettingsBase @@ -53,6 +53,36 @@ Namespace My Return defaultInstance End Get End Property + + _ + Public ReadOnly Property RuninDMZ() As Boolean + Get + Return CType(Me("RuninDMZ"),Boolean) + End Get + End Property + + _ + Public ReadOnly Property NetUse_Usr() As String + Get + Return CType(Me("NetUse_Usr"),String) + End Get + End Property + + _ + Public Property NetUse_PW() As String + Get + Return CType(Me("NetUse_PW"),String) + End Get + Set + Me("NetUse_PW") = value + End Set + End Property End Class End Namespace diff --git a/EnvelopeGenerator.Common/My Project/Settings.settings b/EnvelopeGenerator.Common/My Project/Settings.settings index 85b890b3..daa425de 100644 --- a/EnvelopeGenerator.Common/My Project/Settings.settings +++ b/EnvelopeGenerator.Common/My Project/Settings.settings @@ -1,7 +1,15 @@  - - - - - - + + + + + False + + + dd-gan\Administrator + + + sY4vnATDXwosbTJGip6SqA== + + + \ No newline at end of file diff --git a/EnvelopeGenerator.Common/app.config b/EnvelopeGenerator.Common/app.config new file mode 100644 index 00000000..19b61a68 --- /dev/null +++ b/EnvelopeGenerator.Common/app.config @@ -0,0 +1,52 @@ + + + + + +
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + False + + + dd-gan\Administrator + + + + + + + sY4vnATDXwosbTJGip6SqA== + + + + diff --git a/EnvelopeGenerator.Form/frmEnvelopeEditor.vb b/EnvelopeGenerator.Form/frmEnvelopeEditor.vb index 4957c540..679d27e0 100644 --- a/EnvelopeGenerator.Form/frmEnvelopeEditor.vb +++ b/EnvelopeGenerator.Form/frmEnvelopeEditor.vb @@ -363,6 +363,14 @@ Partial Public Class frmEnvelopeEditor If process.ExitCode = 0 Then ' Verschiebe die Datei Try + Dim oFilePath As String = pSourcePath + + Dim split As String() = oFilePath.Split("\") + Dim parentFolder As String = split(split.Length - 2) + pDestinationPath &= "\" + parentFolder + If Not System.IO.Directory.Exists(pDestinationPath) Then + System.IO.Directory.CreateDirectory(pDestinationPath) + End If pDestinationPath &= "\" + oFilename If File.Exists(pDestinationPath) Then File.Delete(pDestinationPath) diff --git a/EnvelopeGenerator.Service/App.config b/EnvelopeGenerator.Service/App.config index c5280b07..a99d30ce 100644 --- a/EnvelopeGenerator.Service/App.config +++ b/EnvelopeGenerator.Service/App.config @@ -1,6 +1,9 @@ + +
+ @@ -13,4 +16,11 @@ + + + + False + + + diff --git a/EnvelopeGenerator.Service/My Project/AssemblyInfo.vb b/EnvelopeGenerator.Service/My Project/AssemblyInfo.vb index fd66d94c..b8a34bf4 100644 --- a/EnvelopeGenerator.Service/My Project/AssemblyInfo.vb +++ b/EnvelopeGenerator.Service/My Project/AssemblyInfo.vb @@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices ' übernehmen, indem Sie "*" eingeben: ' - + diff --git a/EnvelopeGenerator.Service/My Project/Settings.Designer.vb b/EnvelopeGenerator.Service/My Project/Settings.Designer.vb index f904eda1..223ade22 100644 --- a/EnvelopeGenerator.Service/My Project/Settings.Designer.vb +++ b/EnvelopeGenerator.Service/My Project/Settings.Designer.vb @@ -15,7 +15,7 @@ Option Explicit On Namespace My _ Partial Friend NotInheritable Class MySettings Inherits Global.System.Configuration.ApplicationSettingsBase @@ -53,6 +53,15 @@ Namespace My Return defaultInstance End Get End Property + + _ + Public ReadOnly Property RunInDMZ() As Boolean + Get + Return CType(Me("RunInDMZ"),Boolean) + End Get + End Property End Class End Namespace diff --git a/EnvelopeGenerator.Service/My Project/Settings.settings b/EnvelopeGenerator.Service/My Project/Settings.settings index f7f176ac..9000e76c 100644 --- a/EnvelopeGenerator.Service/My Project/Settings.settings +++ b/EnvelopeGenerator.Service/My Project/Settings.settings @@ -1,5 +1,9 @@  - + - + + + False + + \ No newline at end of file