Add conf to project

Copied to bin/Debug/conf when running from Visual Studio.
Fixes #7.
This commit is contained in:
Jakob Aarøe Dam 2015-04-28 07:54:37 +02:00
parent 87181e1605
commit 812e1f4f04
4 changed files with 43 additions and 155 deletions

View file

@ -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

View file

@ -129,6 +129,9 @@
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="conf\RDSFactor.ini">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="My Project\app.manifest" />
<None Include="My Project\Application.myapp">
<Generator>MyApplicationCodeGenerator</Generator>

View file

@ -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

View file

@ -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"
''' <summary>
''' Generates a random password with the default length.
''' </summary>
''' <returns>Randomly generated password.</returns>
Public Shared Function Generate() As String
Return Generate(DEFAULT_PASSWORD_LENGTH, RandomPasswordOptions.AlphaNumericSpecial)
End Function
''' <summary>
''' Generates a random password with the default length.
''' </summary>
''' <returns>Randomly generated password.</returns>
Public Shared Function Generate(ByVal [option] As RandomPasswordOptions) As String
Return Generate(DEFAULT_PASSWORD_LENGTH, [option])
End Function
''' <summary>
''' Generates a random password with the default length.
''' </summary>
''' <returns>Randomly generated password.</returns>
Public Shared Function Generate(ByVal passwordLength As Integer) As String
Return Generate(DEFAULT_PASSWORD_LENGTH, RandomPasswordOptions.AlphaNumericSpecial)
End Function
''' <summary>
''' Generates a random password.
''' </summary>
''' <returns>Randomly generated password.</returns>
Public Shared Function Generate(ByVal passwordLength As Integer, ByVal [option] As RandomPasswordOptions) As String
Return GeneratePassword(passwordLength, [option])
End Function
#End Region
''' <summary>
''' Generates the password.
''' </summary>
''' <returns></returns>
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
''' <summary>
''' Gets the characters selected by the option
''' </summary>
''' <returns></returns>
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
''' <summary>
''' Gets a random object with a real random seed
''' </summary>
''' <returns></returns>
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