From 812e1f4f043aa36e9d08ce994f6b560f5a92d76a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20Aar=C3=B8e=20Dam?= Date: Tue, 28 Apr 2015 07:54:37 +0200 Subject: [PATCH] Add conf to project Copied to bin/Debug/conf when running from Visual Studio. Fixes #7. --- RDSFactor/RDSFactor.vb | 41 +++++------ RDSFactor/RDSFactor.vbproj | 3 + RDSFactor/conf/RDSFactor.ini | 19 +++++ RDSFactor/random.vb | 135 ----------------------------------- 4 files changed, 43 insertions(+), 155 deletions(-) create mode 100644 RDSFactor/conf/RDSFactor.ini delete mode 100644 RDSFactor/random.vb diff --git a/RDSFactor/RDSFactor.vb b/RDSFactor/RDSFactor.vb index 7ca449d..73071b0 100644 --- a/RDSFactor/RDSFactor.vb +++ b/RDSFactor/RDSFactor.vb @@ -111,10 +111,11 @@ Public Class RDSFactor End Sub Public Shared Sub ServerLog(ByVal message) - Log.WriteLog(Now & ":" & message) + message = Now & ": " & message + Log.WriteLog(message) ' Also write to the console if not a service If Environment.UserInteractive Then - Console.WriteLine(Now & message) + Console.WriteLine(message) End If End Sub @@ -138,54 +139,54 @@ Public Class RDSFactor Dim ConfOk As Boolean = True Dim RConfig As New IniFile Try - RConfig.Load(ApplicationPath() & "\CICRadarR.ini") - DEBUG = RConfig.GetKeyValue("CICRadarR", "Debug") - NetBiosDomain = RConfig.GetKeyValue("CICRadarR", "NetBiosDomain") + RConfig.Load(ApplicationPath() & "\conf\RDSFactor.ini") + DEBUG = RConfig.GetKeyValue("RDSFactor", "Debug") + NetBiosDomain = RConfig.GetKeyValue("RDSFactor", "NetBiosDomain") If NetBiosDomain.Length = 0 Then ServerLog("ERROR: NetBiosDomain can not be empty") ConfOk = False End If - LDAPDomain = RConfig.GetKeyValue("CICRadarR", "LDAPDomain") + LDAPDomain = RConfig.GetKeyValue("RDSFactor", "LDAPDomain") If LDAPDomain.Length = 0 Then ServerLog("ERROR: LDAPDomain can not be empty") ConfOk = False End If - TSGW = RConfig.GetKeyValue("CICRadarR", "TSGW") + TSGW = RConfig.GetKeyValue("RDSFactor", "TSGW") - EnableOTP = RConfig.GetKeyValue("CICRadarR", "EnableOTP") + EnableOTP = RConfig.GetKeyValue("RDSFactor", "EnableOTP") If EnableOTP = True Then - If RConfig.GetKeyValue("CICRadarR", "EnableEmail") = "1" Then + If RConfig.GetKeyValue("RDSFactor", "EnableEmail") = "1" Then EnableEmail = True - SenderEmail = RConfig.GetKeyValue("CICRadarR", "SenderEmail") - MailServer = RConfig.GetKeyValue("CICRadarR", "MailServer") - ADMailField = RConfig.GetKeyValue("CICRadarR", "ADMailField") + SenderEmail = RConfig.GetKeyValue("RDSFactor", "SenderEmail") + MailServer = RConfig.GetKeyValue("RDSFactor", "MailServer") + ADMailField = RConfig.GetKeyValue("RDSFactor", "ADMailField") End If - ADField = RConfig.GetKeyValue("CICRadarR", "ADField") + ADField = RConfig.GetKeyValue("RDSFactor", "ADField") If ADField.Length = 0 Then ServerLog("ERROR: ADField can not be empty") ConfOk = False End If - If RConfig.GetKeyValue("CICRadarR", "EnableSMS") = "1" Then + If RConfig.GetKeyValue("RDSFactor", "EnableSMS") = "1" Then EnableSMS = True - ModemType = RConfig.GetKeyValue("CICRadarR", "USELOCALMODEM") + ModemType = RConfig.GetKeyValue("RDSFactor", "USELOCALMODEM") Select Case ModemType Case "0" - Provider = RConfig.GetKeyValue("CICRadarR", "Provider") + Provider = RConfig.GetKeyValue("RDSFactor", "Provider") If Provider.Length = 0 Then ServerLog("ERROR: Provider can not be empty") ConfOk = False End If Case "1" - ComPort = RConfig.GetKeyValue("CICRadarR", "COMPORT") + ComPort = RConfig.GetKeyValue("RDSFactor", "COMPORT") If ComPort.Length = 0 Then ServerLog("ERROR: ComPort can not be empty") ConfOk = False End If - SmsC = RConfig.GetKeyValue("CICRadarR", "SMSC") + SmsC = RConfig.GetKeyValue("RDSFactor", "SMSC") If SmsC.Length = 0 Then ServerLog("ERROR: SMSC can not be empty. See http://smsclist.com/downloads/default.txt for valid values") ConfOk = False @@ -199,7 +200,7 @@ Public Class RDSFactor End If Dim ClientList As String = "" - ClientList = RConfig.GetKeyValue("CICRadarR", "ClientList") + ClientList = RConfig.GetKeyValue("RDSFactor", "ClientList") Dim ClientArray() As String ClientArray = Split(ClientList, ",") @@ -215,7 +216,7 @@ Public Class RDSFactor ServerLog("Loading Configuration...FAILED") End If Catch - ServerLog("ERROR: Missing CICRadarR.ini from startup path or CICRadarR.ini contains invalid configuration") + ServerLog("ERROR: Missing RDSFactor.ini from startup path or RDSFactor.ini contains invalid configuration") ServerLog("Loading Configuration...FAILED") End End Try diff --git a/RDSFactor/RDSFactor.vbproj b/RDSFactor/RDSFactor.vbproj index 3ecda40..f1d555c 100644 --- a/RDSFactor/RDSFactor.vbproj +++ b/RDSFactor/RDSFactor.vbproj @@ -129,6 +129,9 @@ + + PreserveNewest + MyApplicationCodeGenerator diff --git a/RDSFactor/conf/RDSFactor.ini b/RDSFactor/conf/RDSFactor.ini new file mode 100644 index 0000000..9aea41c --- /dev/null +++ b/RDSFactor/conf/RDSFactor.ini @@ -0,0 +1,19 @@ +[RDSFactor] +ClientList=127.0.0.1 +SenderEmail=noreply@example.com +ADField=telephoneNumber +EnableOTP=1 +Provider=https://www.cpsms.dk/sms/?username=myuser&password=mypassword&recipient=***NUMBER***&message=***TEXTMESSAGE***&from=CPSMS +Debug=1 +MailServer= +NetBiosDomain=ad +TSGW=1 +LDAPDomain=ad.example.com +EnableEmail=0 +USELOCALMODEM=0 +SMSC=+4540390999 +EnableSMS=1 +COMPORT=com1 +ADMailfield=mail +[Clients] +127.0.0.1=helloworld \ No newline at end of file diff --git a/RDSFactor/random.vb b/RDSFactor/random.vb deleted file mode 100644 index c68f37d..0000000 --- a/RDSFactor/random.vb +++ /dev/null @@ -1,135 +0,0 @@ - -Imports System -Imports System.Security.Cryptography - - -Namespace Security - Public Enum RandomPasswordOptions - Alpha = 1 - Numeric = 2 - AlphaNumeric = Alpha + Numeric - AlphaNumericSpecial = 4 - End Enum - - Public Class RandomPasswordGenerator - ' Define default password length. - Private Shared DEFAULT_PASSWORD_LENGTH As Integer = 2 - - 'No characters that are confusing: i, I, l, L, o, O, 0, 1, u, v - - Private Shared PASSWORD_CHARS_Alpha As String = "abcdefghjkmnpqrstwxyzABCDEFGHJKMNPQRSTWXYZ" - Private Shared PASSWORD_CHARS_NUMERIC As String = "23456789" - Private Shared PASSWORD_CHARS_SPECIAL As String = "" - -#Region "Overloads" - - ''' - ''' Generates a random password with the default length. - ''' - ''' Randomly generated password. - Public Shared Function Generate() As String - Return Generate(DEFAULT_PASSWORD_LENGTH, RandomPasswordOptions.AlphaNumericSpecial) - End Function - - ''' - ''' Generates a random password with the default length. - ''' - ''' Randomly generated password. - Public Shared Function Generate(ByVal [option] As RandomPasswordOptions) As String - Return Generate(DEFAULT_PASSWORD_LENGTH, [option]) - End Function - - ''' - ''' Generates a random password with the default length. - ''' - ''' Randomly generated password. - Public Shared Function Generate(ByVal passwordLength As Integer) As String - Return Generate(DEFAULT_PASSWORD_LENGTH, RandomPasswordOptions.AlphaNumericSpecial) - End Function - - ''' - ''' Generates a random password. - ''' - ''' Randomly generated password. - Public Shared Function Generate(ByVal passwordLength As Integer, ByVal [option] As RandomPasswordOptions) As String - Return GeneratePassword(passwordLength, [option]) - End Function - -#End Region - - - ''' - ''' Generates the password. - ''' - ''' - Private Shared Function GeneratePassword(ByVal passwordLength As Integer, ByVal [option] As RandomPasswordOptions) As String - If passwordLength < 0 Then - Return Nothing - End If - - Dim passwordChars = GetCharacters([option]) - - If String.IsNullOrEmpty(passwordChars) Then - Return Nothing - End If - - Dim password = New Char(passwordLength - 1) {} - - Dim random = GetRandom() - - For i As Integer = 0 To passwordLength - 1 - Dim index = random.[Next](passwordChars.Length) - Dim passwordChar = passwordChars(index) - - password(i) = passwordChar - Next - - Return New String(password) - End Function - - - - ''' - ''' Gets the characters selected by the option - ''' - ''' - Private Shared Function GetCharacters(ByVal [option] As RandomPasswordOptions) As String - Select Case [option] - Case RandomPasswordOptions.Alpha - Return PASSWORD_CHARS_Alpha - Case RandomPasswordOptions.Numeric - Return PASSWORD_CHARS_NUMERIC - Case RandomPasswordOptions.AlphaNumeric - Return PASSWORD_CHARS_Alpha + PASSWORD_CHARS_NUMERIC - Case RandomPasswordOptions.AlphaNumericSpecial - Return PASSWORD_CHARS_Alpha + PASSWORD_CHARS_NUMERIC + PASSWORD_CHARS_SPECIAL - Case Else - Exit Select - End Select - Return String.Empty - End Function - - ''' - ''' Gets a random object with a real random seed - ''' - ''' - Private Shared Function GetRandom() As Random - ' Use a 4-byte array to fill it with random bytes and convert it then - ' to an integer value. - Dim randomBytes As Byte() = New Byte(3) {} - - ' Generate 4 random bytes. - Dim rng As New RNGCryptoServiceProvider() - rng.GetBytes(randomBytes) - - ' Convert 4 bytes into a 32-bit integer value. - Dim seed As Integer = (randomBytes(0) And &H7F) << 24 Or randomBytes(1) << 16 Or randomBytes(2) << 8 Or randomBytes(3) - - ' Now, this is real randomization. - Return New Random(seed) - End Function - - - End Class -End Namespace -