Rename: RDSFactorWeb -> web, RDSFactor -> server

This commit is contained in:
Jakob Aarøe Dam 2015-04-28 11:58:23 +02:00
parent c3c10e1fd2
commit eebdaf9551
88 changed files with 12 additions and 11 deletions

56
server/Conversion.vb Normal file
View file

@ -0,0 +1,56 @@

Friend Class Conversion
Friend Shared Function ConvertToString(ByRef bytes() As Byte) As String
Dim k As New System.Text.StringBuilder
Dim i As Integer
For i = 0 To bytes.Length - 1 : k.Append(Chr(bytes(i))) : Next
Return k.ToString
End Function
Friend Shared Function ConvertToBytes(ByVal str As String) As Byte()
Dim res() As Byte = {}
Array.Resize(Of Byte)(res, str.Length)
Dim i As Integer
For i = 0 To res.Length - 1
res(i) = Convert.ToByte(str.Chars(i))
Next
Return res
End Function
Friend Shared Function ConvertToDateTime(ByVal value As String) As DateTime
Dim ret As DateTime
value = LCase(value)
Try
value = Replace(value, "utc", "")
value = Replace(value, "mon", "")
value = Replace(value, "tue", "")
value = Replace(value, "wed", "")
value = Replace(value, "thu", "")
value = Replace(value, "fri", "")
value = Replace(value, "sat", "")
value = Replace(value, "sun", "")
value = Replace(value, "jan", "1/")
value = Replace(value, "feb", "2/")
value = Replace(value, "mar", "3/")
value = Replace(value, "apr", "4/")
value = Replace(value, "may", "5/")
value = Replace(value, "jun", "6/")
value = Replace(value, "jul", "7/")
value = Replace(value, "aug", "8/")
value = Replace(value, "sep", "9/")
value = Replace(value, "oct", "10/")
value = Replace(value, "nov", "11/")
value = Replace(value, "dec", "12/")
Do While InStr(value, " ") <> 0
value = Replace(value, " ", " ")
Loop
value = Replace(value, "/ ", "/")
ret = Convert.ToDateTime(value)
Catch ex As Exception
ret = Nothing
End Try
Return ret
End Function
End Class

376
server/IniFileVb.vb Normal file
View file

@ -0,0 +1,376 @@
' Programmer: Ludvik Jerabek
' Date: 08\23\2010
' Purpose: Allow INI manipulation in .NET
Imports System.IO
Imports System.Text.RegularExpressions
Imports System.Collections
Imports System.Diagnostics
' IniFile class used to read and write ini files by loading the file into memory
Public Class IniFile
' List of IniSection objects keeps track of all the sections in the INI file
Private m_sections As Hashtable
' Public constructor
Public Sub New()
m_sections = New Hashtable(StringComparer.InvariantCultureIgnoreCase)
End Sub
' Loads the Reads the data in the ini file into the IniFile object
Public Sub Load(ByVal sFileName As String, Optional ByVal bMerge As Boolean = False)
If Not bMerge Then
RemoveAllSections()
End If
' Clear the object...
Dim tempsection As IniSection = Nothing
Dim oReader As New StreamReader(sFileName)
Dim regexcomment As New Regex("^([\s]*#.*)", (RegexOptions.Singleline Or RegexOptions.IgnoreCase))
' Broken but left for history
'Dim regexsection As New Regex("\[[\s]*([^\[\s].*[^\s\]])[\s]*\]", (RegexOptions.Singleline Or RegexOptions.IgnoreCase))
Dim regexsection As New Regex("^[\s]*\[[\s]*([^\[\s].*[^\s\]])[\s]*\][\s]*$", (RegexOptions.Singleline Or RegexOptions.IgnoreCase))
Dim regexkey As New Regex("^\s*([^=\s]*)[^=]*=(.*)", (RegexOptions.Singleline Or RegexOptions.IgnoreCase))
While Not oReader.EndOfStream
Dim line As String = oReader.ReadLine()
If line <> String.Empty Then
Dim m As Match = Nothing
If regexcomment.Match(line).Success Then
m = regexcomment.Match(line)
Trace.WriteLine(String.Format("Skipping Comment: {0}", m.Groups(0).Value))
ElseIf regexsection.Match(line).Success Then
m = regexsection.Match(line)
Trace.WriteLine(String.Format("Adding section [{0}]", m.Groups(1).Value))
tempsection = AddSection(m.Groups(1).Value)
ElseIf regexkey.Match(line).Success AndAlso tempsection IsNot Nothing Then
m = regexkey.Match(line)
Trace.WriteLine(String.Format("Adding Key [{0}]=[{1}]", m.Groups(1).Value, m.Groups(2).Value))
tempsection.AddKey(m.Groups(1).Value).Value = m.Groups(2).Value
ElseIf tempsection IsNot Nothing Then
' Handle Key without value
Trace.WriteLine(String.Format("Adding Key [{0}]", line))
tempsection.AddKey(line)
Else
' This should not occur unless the tempsection is not created yet...
Trace.WriteLine(String.Format("Skipping unknown type of data: {0}", line))
End If
End If
End While
oReader.Close()
End Sub
' Used to save the data back to the file or your choice
Public Sub Save(ByVal sFileName As String)
Dim oWriter As New StreamWriter(sFileName, False)
For Each s As IniSection In Sections
Trace.WriteLine(String.Format("Writing Section: [{0}]", s.Name))
oWriter.WriteLine(String.Format("[{0}]", s.Name))
For Each k As IniSection.IniKey In s.Keys
If k.Value <> String.Empty Then
Trace.WriteLine(String.Format("Writing Key: {0}={1}", k.Name, k.Value))
oWriter.WriteLine(String.Format("{0}={1}", k.Name, k.Value))
Else
Trace.WriteLine(String.Format("Writing Key: {0}", k.Name))
oWriter.WriteLine(String.Format("{0}", k.Name))
End If
Next
Next
oWriter.Close()
End Sub
' Gets all the sections
Public ReadOnly Property Sections() As System.Collections.ICollection
Get
Return m_sections.Values
End Get
End Property
' Adds a section to the IniFile object, returns a IniSection object to the new or existing object
Public Function AddSection(ByVal sSection As String) As IniSection
Dim s As IniSection = Nothing
sSection = sSection.Trim()
' Trim spaces
If m_sections.ContainsKey(sSection) Then
s = DirectCast(m_sections(sSection), IniSection)
Else
s = New IniSection(Me, sSection)
m_sections(sSection) = s
End If
Return s
End Function
' Removes a section by its name sSection, returns trus on success
Public Function RemoveSection(ByVal sSection As String) As Boolean
sSection = sSection.Trim()
Return RemoveSection(GetSection(sSection))
End Function
' Removes section by object, returns trus on success
Public Function RemoveSection(ByVal Section As IniSection) As Boolean
If Section IsNot Nothing Then
Try
m_sections.Remove(Section.Name)
Return True
Catch ex As Exception
Trace.WriteLine(ex.Message)
End Try
End If
Return False
End Function
' Removes all existing sections, returns trus on success
Public Function RemoveAllSections() As Boolean
m_sections.Clear()
Return (m_sections.Count = 0)
End Function
' Returns an IniSection to the section by name, NULL if it was not found
Public Function GetSection(ByVal sSection As String) As IniSection
sSection = sSection.Trim()
' Trim spaces
If m_sections.ContainsKey(sSection) Then
Return DirectCast(m_sections(sSection), IniSection)
End If
Return Nothing
End Function
' Returns a KeyValue in a certain section
Public Function GetKeyValue(ByVal sSection As String, ByVal sKey As String) As String
Dim s As IniSection = GetSection(sSection)
If s IsNot Nothing Then
Dim k As IniSection.IniKey = s.GetKey(sKey)
If k IsNot Nothing Then
Return k.Value
End If
End If
Return String.Empty
End Function
' Sets a KeyValuePair in a certain section
Public Function SetKeyValue(ByVal sSection As String, ByVal sKey As String, ByVal sValue As String) As Boolean
Dim s As IniSection = AddSection(sSection)
If s IsNot Nothing Then
Dim k As IniSection.IniKey = s.AddKey(sKey)
If k IsNot Nothing Then
k.Value = sValue
Return True
End If
End If
Return False
End Function
' Renames an existing section returns true on success, false if the section didn't exist or there was another section with the same sNewSection
Public Function RenameSection(ByVal sSection As String, ByVal sNewSection As String) As Boolean
' Note string trims are done in lower calls.
Dim bRval As Boolean = False
Dim s As IniSection = GetSection(sSection)
If s IsNot Nothing Then
bRval = s.SetName(sNewSection)
End If
Return bRval
End Function
' Renames an existing key returns true on success, false if the key didn't exist or there was another section with the same sNewKey
Public Function RenameKey(ByVal sSection As String, ByVal sKey As String, ByVal sNewKey As String) As Boolean
' Note string trims are done in lower calls.
Dim s As IniSection = GetSection(sSection)
If s IsNot Nothing Then
Dim k As IniSection.IniKey = s.GetKey(sKey)
If k IsNot Nothing Then
Return k.SetName(sNewKey)
End If
End If
Return False
End Function
' Remove a key by section name and key name
Public Function RemoveKey(ByVal sSection As String, ByVal sKey As String) As Boolean
Dim s As IniSection = GetSection(sSection)
If s IsNot Nothing Then
Return s.RemoveKey(sKey)
End If
Return False
End Function
' IniSection class
Public Class IniSection
' IniFile IniFile object instance
Private m_pIniFile As IniFile
' Name of the section
Private m_sSection As String
' List of IniKeys in the section
Private m_keys As Hashtable
' Constuctor so objects are internally managed
Protected Friend Sub New(ByVal parent As IniFile, ByVal sSection As String)
m_pIniFile = parent
m_sSection = sSection
m_keys = New Hashtable(StringComparer.InvariantCultureIgnoreCase)
End Sub
' Returns all the keys in a section
Public ReadOnly Property Keys() As System.Collections.ICollection
Get
Return m_keys.Values
End Get
End Property
' Returns the section name
Public ReadOnly Property Name() As String
Get
Return m_sSection
End Get
End Property
' Adds a key to the IniSection object, returns a IniKey object to the new or existing object
Public Function AddKey(ByVal sKey As String) As IniKey
sKey = sKey.Trim()
Dim k As IniSection.IniKey = Nothing
If sKey.Length <> 0 Then
If m_keys.ContainsKey(sKey) Then
k = DirectCast(m_keys(sKey), IniKey)
Else
k = New IniSection.IniKey(Me, sKey)
m_keys(sKey) = k
End If
End If
Return k
End Function
' Removes a single key by string
Public Function RemoveKey(ByVal sKey As String) As Boolean
Return RemoveKey(GetKey(sKey))
End Function
' Removes a single key by IniKey object
Public Function RemoveKey(ByVal Key As IniKey) As Boolean
If Key IsNot Nothing Then
Try
m_keys.Remove(Key.Name)
Return True
Catch ex As Exception
Trace.WriteLine(ex.Message)
End Try
End If
Return False
End Function
' Removes all the keys in the section
Public Function RemoveAllKeys() As Boolean
m_keys.Clear()
Return (m_keys.Count = 0)
End Function
' Returns a IniKey object to the key by name, NULL if it was not found
Public Function GetKey(ByVal sKey As String) As IniKey
sKey = sKey.Trim()
If m_keys.ContainsKey(sKey) Then
Return DirectCast(m_keys(sKey), IniKey)
End If
Return Nothing
End Function
' Sets the section name, returns true on success, fails if the section
' name sSection already exists
Public Function SetName(ByVal sSection As String) As Boolean
sSection = sSection.Trim()
If sSection.Length <> 0 Then
' Get existing section if it even exists...
Dim s As IniSection = m_pIniFile.GetSection(sSection)
If s IsNot Me AndAlso s IsNot Nothing Then
Return False
End If
Try
' Remove the current section
m_pIniFile.m_sections.Remove(m_sSection)
' Set the new section name to this object
m_pIniFile.m_sections(sSection) = Me
' Set the new section name
m_sSection = sSection
Return True
Catch ex As Exception
Trace.WriteLine(ex.Message)
End Try
End If
Return False
End Function
' Returns the section name
Public Function GetName() As String
Return m_sSection
End Function
' IniKey class
Public Class IniKey
' Name of the Key
Private m_sKey As String
' Value associated
Private m_sValue As String
' Pointer to the parent CIniSection
Private m_section As IniSection
' Constuctor so objects are internally managed
Protected Friend Sub New(ByVal parent As IniSection, ByVal sKey As String)
m_section = parent
m_sKey = sKey
End Sub
' Returns the name of the Key
Public ReadOnly Property Name() As String
Get
Return m_sKey
End Get
End Property
' Sets or Gets the value of the key
Public Property Value() As String
Get
Return m_sValue
End Get
Set(ByVal value As String)
m_sValue = value
End Set
End Property
' Sets the value of the key
Public Sub SetValue(ByVal sValue As String)
m_sValue = sValue
End Sub
' Returns the value of the Key
Public Function GetValue() As String
Return m_sValue
End Function
' Sets the key name
' Returns true on success, fails if the section name sKey already exists
Public Function SetName(ByVal sKey As String) As Boolean
sKey = sKey.Trim()
If sKey.Length <> 0 Then
Dim k As IniKey = m_section.GetKey(sKey)
If k IsNot Me AndAlso k IsNot Nothing Then
Return False
End If
Try
' Remove the current key
m_section.m_keys.Remove(m_sKey)
' Set the new key name to this object
m_section.m_keys(sKey) = Me
' Set the new key name
m_sKey = sKey
Return True
Catch ex As Exception
Trace.WriteLine(ex.Message)
End Try
End If
Return False
End Function
' Returns the name of the Key
Public Function GetName() As String
Return m_sKey
End Function
End Class
' End of IniKey class
End Class
' End of IniSection class
End Class
' End of IniFile class

44
server/Log.vb Normal file
View file

@ -0,0 +1,44 @@
Imports System
Imports System.IO
Imports System.Data
Namespace LogFile
Public Class LogWriter
Public filePath As String
Private fileStream As FileStream
Private streamWriter As StreamWriter
Public Sub OpenFile()
Try
Dim strPath As String
strPath = filePath
If System.IO.File.Exists(strPath) Then
fileStream = New FileStream(strPath, FileMode.Append, FileAccess.Write)
Else
fileStream = New FileStream(strPath, FileMode.Create, FileAccess.Write)
End If
streamWriter = New StreamWriter(fileStream)
Catch
End Try
End Sub
Public Sub WriteLog(ByVal strComments As String)
Try
OpenFile()
streamWriter.WriteLine(strComments)
CloseFile()
Catch
End Try
End Sub
Public Sub CloseFile()
Try
streamWriter.Close()
fileStream.Close()
Catch
End Try
End Sub
End Class
End Namespace

View file

@ -0,0 +1,13 @@
'------------------------------------------------------------------------------
' <auto-generated>
' This code was generated by a tool.
' Runtime Version:4.0.30319.34014
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------
Option Strict On
Option Explicit On

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<MyApplicationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<MySubMain>true</MySubMain>
<MainForm>TestService</MainForm>
<SingleInstance>false</SingleInstance>
<ShutdownMode>0</ShutdownMode>
<EnableVisualStyles>true</EnableVisualStyles>
<AuthenticationMode>0</AuthenticationMode>
<SaveMySettingsOnExit>true</SaveMySettingsOnExit>
</MyApplicationData>

View file

@ -0,0 +1,35 @@
Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices
' General Information about an assembly is controlled through the following
' set of attributes. Change these attribute values to modify the information
' associated with an assembly.
' Review the values of the assembly attributes
<Assembly: AssemblyTitle("CICRadarR")>
<Assembly: AssemblyDescription("")>
<Assembly: AssemblyCompany("Microsoft")>
<Assembly: AssemblyProduct("CICRadarR")>
<Assembly: AssemblyCopyright("Copyright © Microsoft 2012")>
<Assembly: AssemblyTrademark("")>
<Assembly: ComVisible(False)>
'The following GUID is for the ID of the typelib if this project is exposed to COM
<Assembly: Guid("ce54c196-bc53-47c7-9e19-91495f15dcb6")>
' Version information for an assembly consists of the following four values:
'
' Major Version
' Minor Version
' Build Number
' Revision
'
' You can specify all the values or you can default the Build and Revision Numbers
' by using the '*' as shown below:
' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("1.0.0.0")>
<Assembly: AssemblyFileVersion("1.0.0.0")>

63
server/My Project/Resources.Designer.vb generated Normal file
View file

@ -0,0 +1,63 @@
'------------------------------------------------------------------------------
' <auto-generated>
' This code was generated by a tool.
' Runtime Version:4.0.30319.34014
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------
Option Strict On
Option Explicit On
Imports System
Namespace My.Resources
'This class was auto-generated by the StronglyTypedResourceBuilder
'class via a tool like ResGen or Visual Studio.
'To add or remove a member, edit your .ResX file then rerun ResGen
'with the /str option, or rebuild your VS project.
'''<summary>
''' A strongly-typed resource class, for looking up localized strings, etc.
'''</summary>
<Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0"), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _
Friend Module Resources
Private resourceMan As Global.System.Resources.ResourceManager
Private resourceCulture As Global.System.Globalization.CultureInfo
'''<summary>
''' Returns the cached ResourceManager instance used by this class.
'''</summary>
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager
Get
If Object.ReferenceEquals(resourceMan, Nothing) Then
Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("RDSFactor.Resources", GetType(Resources).Assembly)
resourceMan = temp
End If
Return resourceMan
End Get
End Property
'''<summary>
''' Overrides the current thread's CurrentUICulture property for all
''' resource lookups using this strongly typed resource class.
'''</summary>
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Friend Property Culture() As Global.System.Globalization.CultureInfo
Get
Return resourceCulture
End Get
Set
resourceCulture = value
End Set
End Property
End Module
End Namespace

View file

@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

73
server/My Project/Settings.Designer.vb generated Normal file
View file

@ -0,0 +1,73 @@
'------------------------------------------------------------------------------
' <auto-generated>
' This code was generated by a tool.
' Runtime Version:4.0.30319.34014
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------
Option Strict On
Option Explicit On
Namespace My
<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0"), _
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Partial Friend NotInheritable Class MySettings
Inherits Global.System.Configuration.ApplicationSettingsBase
Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings)
#Region "My.Settings Auto-Save Functionality"
#If _MyType = "WindowsForms" Then
Private Shared addedHandler As Boolean
Private Shared addedHandlerLockObject As New Object
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs)
If My.Application.SaveMySettingsOnExit Then
My.Settings.Save()
End If
End Sub
#End If
#End Region
Public Shared ReadOnly Property [Default]() As MySettings
Get
#If _MyType = "WindowsForms" Then
If Not addedHandler Then
SyncLock addedHandlerLockObject
If Not addedHandler Then
AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings
addedHandler = True
End If
End SyncLock
End If
#End If
Return defaultInstance
End Get
End Property
End Class
End Namespace
Namespace My
<Global.Microsoft.VisualBasic.HideModuleNameAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute()> _
Friend Module MySettingsProperty
<Global.System.ComponentModel.Design.HelpKeywordAttribute("My.Settings")> _
Friend ReadOnly Property Settings() As Global.RDSFactor.My.MySettings
Get
Return Global.RDSFactor.My.MySettings.Default
End Get
End Property
End Module
End Namespace

View file

@ -0,0 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" UseMySettingsClassName="true">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>

View file

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC Manifest Options
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
Specifying requestedExecutionLevel node will disable file and registry virtualization.
If you want to utilize File and Registry Virtualization for backward
compatibility then delete the requestedExecutionLevel node.
-->
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of all Windows versions that this application is designed to work with. Windows will automatically select the most compatible environment.-->
<!-- If your application is designed to work with Windows 7, uncomment the following supportedOS node-->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>-->
</application>
</compatibility>
<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
<!-- <dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>-->
</asmv1:assembly>

48
server/ProjectInstaller.Designer.vb generated Normal file
View file

@ -0,0 +1,48 @@
<System.ComponentModel.RunInstaller(True)> Partial Class ProjectInstaller
Inherits System.Configuration.Install.Installer
'Installer overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Component Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Component Designer
'It can be modified using the Component Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.ServiceProcessInstaller1 = New System.ServiceProcess.ServiceProcessInstaller()
Me.ServiceInstaller1 = New System.ServiceProcess.ServiceInstaller()
'
'ServiceProcessInstaller1
'
Me.ServiceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem
Me.ServiceProcessInstaller1.Password = Nothing
Me.ServiceProcessInstaller1.Username = Nothing
'
'ServiceInstaller1
'
Me.ServiceInstaller1.Description = "RDSFactor Radius Server"
Me.ServiceInstaller1.DisplayName = "RDSFactor Radius Server"
Me.ServiceInstaller1.ServiceName = "RDSFactor"
Me.ServiceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Automatic
'
'ProjectInstaller
'
Me.Installers.AddRange(New System.Configuration.Install.Installer() {Me.ServiceProcessInstaller1, Me.ServiceInstaller1})
End Sub
Friend WithEvents ServiceProcessInstaller1 As System.ServiceProcess.ServiceProcessInstaller
Friend WithEvents ServiceInstaller1 As System.ServiceProcess.ServiceInstaller
End Class

View file

@ -0,0 +1,129 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="ServiceProcessInstaller1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="ServiceInstaller1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>188, 17</value>
</metadata>
<metadata name="$this.TrayLargeIcon" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
</root>

View file

@ -0,0 +1,16 @@
Imports System.ComponentModel
Imports System.Configuration.Install
Public Class ProjectInstaller
Public Sub New()
MyBase.New()
'This call is required by the Component Designer.
InitializeComponent()
'Add initialization code after the call to InitializeComponent
End Sub
End Class

69
server/RDSFactor.Designer.vb generated Normal file
View file

@ -0,0 +1,69 @@
Imports System.ServiceProcess
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class RDSFactor
Inherits System.ServiceProcess.ServiceBase
'UserService overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
' The main entry point for the process
<MTAThread()> _
<System.Diagnostics.DebuggerNonUserCode()> _
Shared Sub Main(ByVal args() As String)
Dim ServicesToRun() As System.ServiceProcess.ServiceBase
' More than one NT Service may run within the same process. To add
' another service to this process, change the following line to
' create a second service object. For example,
'
' ServicesToRun = New System.ServiceProcess.ServiceBase () {New Service1, New MySecondUserService}
'
Dim server = New RDSFactor()
If Environment.UserInteractive Then
server.OnStart(args)
Console.WriteLine("Type any character to exit")
Console.Read()
server.OnStop()
Else
ServicesToRun = New System.ServiceProcess.ServiceBase() {server}
System.ServiceProcess.ServiceBase.Run(ServicesToRun)
End If
End Sub
'Required by the Component Designer
Private components As System.ComponentModel.IContainer
' NOTE: The following procedure is required by the Component Designer
' It can be modified using the Component Designer.
' Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.cleanupEvent = New System.Timers.Timer()
CType(Me.cleanupEvent, System.ComponentModel.ISupportInitialize).BeginInit()
'
'cleanupEvent
'
Me.cleanupEvent.Enabled = True
Me.cleanupEvent.Interval = 60000.0R
'
'RDSFactor
'
Me.ServiceName = "Service1"
CType(Me.cleanupEvent, System.ComponentModel.ISupportInitialize).EndInit()
End Sub
Public WithEvents cleanupEvent As System.Timers.Timer
End Class

126
server/RDSFactor.resx Normal file
View file

@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="cleanupEvent.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="$this.TrayLargeIcon" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
</root>

44
server/RDSFactor.sln Normal file
View file

@ -0,0 +1,44 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Express 2013 for Web
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "RDSFactor", "RDSFactor.vbproj", "{04C6C533-9FEA-41B2-B554-A166C7C7FE32}"
EndProject
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "RADAR", "..\radar-radius\RADAR\RADAR.vbproj", "{3AB08A4E-C4FA-4571-A5D4-32BBA807C31D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|Mixed Platforms = Debug|Mixed Platforms
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|Mixed Platforms = Release|Mixed Platforms
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{04C6C533-9FEA-41B2-B554-A166C7C7FE32}.Debug|Any CPU.ActiveCfg = Debug|x86
{04C6C533-9FEA-41B2-B554-A166C7C7FE32}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{04C6C533-9FEA-41B2-B554-A166C7C7FE32}.Debug|Mixed Platforms.Build.0 = Debug|x86
{04C6C533-9FEA-41B2-B554-A166C7C7FE32}.Debug|x86.ActiveCfg = Debug|x86
{04C6C533-9FEA-41B2-B554-A166C7C7FE32}.Debug|x86.Build.0 = Debug|x86
{04C6C533-9FEA-41B2-B554-A166C7C7FE32}.Release|Any CPU.ActiveCfg = Release|x86
{04C6C533-9FEA-41B2-B554-A166C7C7FE32}.Release|Mixed Platforms.ActiveCfg = Release|x86
{04C6C533-9FEA-41B2-B554-A166C7C7FE32}.Release|Mixed Platforms.Build.0 = Release|x86
{04C6C533-9FEA-41B2-B554-A166C7C7FE32}.Release|x86.ActiveCfg = Release|x86
{04C6C533-9FEA-41B2-B554-A166C7C7FE32}.Release|x86.Build.0 = Release|x86
{3AB08A4E-C4FA-4571-A5D4-32BBA807C31D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3AB08A4E-C4FA-4571-A5D4-32BBA807C31D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3AB08A4E-C4FA-4571-A5D4-32BBA807C31D}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{3AB08A4E-C4FA-4571-A5D4-32BBA807C31D}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{3AB08A4E-C4FA-4571-A5D4-32BBA807C31D}.Debug|x86.ActiveCfg = Debug|Any CPU
{3AB08A4E-C4FA-4571-A5D4-32BBA807C31D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3AB08A4E-C4FA-4571-A5D4-32BBA807C31D}.Release|Any CPU.Build.0 = Release|Any CPU
{3AB08A4E-C4FA-4571-A5D4-32BBA807C31D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{3AB08A4E-C4FA-4571-A5D4-32BBA807C31D}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{3AB08A4E-C4FA-4571-A5D4-32BBA807C31D}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

308
server/RDSFactor.vb Normal file
View file

@ -0,0 +1,308 @@
Imports System.DirectoryServices
Imports System.IO
Imports System.Reflection
Imports RDSFactor.SMSModem
Imports RDSFactor.LogFile
Imports System.Security.Cryptography
Imports System.Text
Imports System
Imports System.Net.Mail
Imports RADAR
Public Class RDSFactor
Public Shared LDAPDomain As String = ""
Public Shared ADField As String = ""
Public Shared ADMailField As String = ""
Public Shared EnableOTP As Boolean
Public Shared NetBiosDomain As String = ""
Public Shared secrets As NASAuthList
Public Shared SessionTimeOut As Integer = 30 ' in minutes
Public Shared LaunchTimeOut As Integer = 30 ' in seconds
Public Shared EnableSMS As Boolean = False
Public Shared EnableEmail As Boolean = False
Private Shared DEBUG As Boolean
Private Shared UserAccessLog As New LogWriter
Private Shared Log As New LogWriter
Private server As RADIUSServer
Private serverPort As Integer = 1812
Private userHash As New Hashtable
Private packetHash As New Hashtable
Private clientHash As New Hashtable
Private Shared Provider As String = ""
Private Shared ModemType As String = ""
Private Shared ComPort As String = ""
Private Shared SmsC As String = ""
Private Shared MailServer As String = ""
Private Shared SenderEmail As String = ""
Private TSGW As String = ""
Protected Overrides Sub OnStart(ByVal args() As String)
Log.filePath = ApplicationPath() & "\log.txt"
UserAccessLog.filePath = ApplicationPath() & "\UserAccessLog.txt"
Log.WriteLog("---------------------------------------------------------------------------------------------------")
ServerLog("Starting Service")
ServerLog("Loading Configuration...")
loadConfiguration()
ServerLog("Starting Radius listner ports...")
StartUpServer()
End Sub
Protected Overrides Sub OnStop()
ServerLog("Stopping Radius listner ports...")
End Sub
Public Sub StartUpServer()
secrets = New NASAuthList
For Each cl As DictionaryEntry In clientHash
ServerLog("Adding Shared Secrets to Radius Server")
secrets.AddSharedSecret(cl.Key, cl.Value)
Next
Try
server = New RADIUSServer(serverPort, AddressOf ProcessPacket, secrets)
ServerLog("Starting Radius Server on Port " & serverPort & " ...OK")
Catch
ServerLog("Starting Radius Server on Port " & serverPort & "...FAILED")
End Try
End Sub
' Every valid RADIUS request generated by the server(s) we created earlier
' will fire up the callback procedure. Invalid requests are dropped, per RFC.
Private Sub ProcessPacket(ByVal packet As RADIUSPacket)
If Not packet.IsValid Then
Console.WriteLine("Packet is not valid. Discarding.")
Exit Sub
End If
Dim handler = New RDSHandler(packet)
' If TSGW = "1" Then
' handler = New RDSHandler(packet)
' Else
' handler = New CitrixHandler(packet)
' End If
handler.ProcessRequest()
End Sub
Public Shared Sub AccessLog(packet As RADIUSPacket, message As String)
Dim from_address = packet.EndPoint.Address.ToString
message = "[" & packet.UserName & " " & from_address & "] " & message
AccessLog(message)
End Sub
Public Shared Sub AccessLog(message As String)
message = Now & ": DEBUG: " & message
If DEBUG = True Then
UserAccessLog.WriteLog(message)
' Also write to the console if not a service
If Environment.UserInteractive Then
Console.WriteLine(message)
End If
End If
End Sub
Public Shared Sub ServerLog(ByVal message)
message = Now & ": " & message
Log.WriteLog(message)
' Also write to the console if not a service
If Environment.UserInteractive Then
Console.WriteLine(message)
End If
End Sub
Public Shared Function GenerateCode() As String
Dim dummy As Integer = 0
Dim ordRand As New System.Random()
Dim temp As New System.Collections.ArrayList()
While temp.Count < 6
dummy = ordRand.[Next](1, 9)
If Not temp.Contains(dummy) Then
temp.Add(dummy)
End If
End While
Dim strVar As String = temp(0).ToString() + temp(1).ToString() + temp(2).ToString() + temp(3).ToString() + temp(4).ToString() + temp(5).ToString()
Return strVar
End Function
Public Sub loadConfiguration()
Dim ConfOk As Boolean = True
Dim RConfig As New IniFile
Try
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("RDSFactor", "LDAPDomain")
If LDAPDomain.Length = 0 Then
ServerLog("ERROR: LDAPDomain can not be empty")
ConfOk = False
End If
TSGW = RConfig.GetKeyValue("RDSFactor", "TSGW")
EnableOTP = RConfig.GetKeyValue("RDSFactor", "EnableOTP")
If EnableOTP = True Then
If RConfig.GetKeyValue("RDSFactor", "EnableEmail") = "1" Then
EnableEmail = True
SenderEmail = RConfig.GetKeyValue("RDSFactor", "SenderEmail")
MailServer = RConfig.GetKeyValue("RDSFactor", "MailServer")
ADMailField = RConfig.GetKeyValue("RDSFactor", "ADMailField")
End If
ADField = RConfig.GetKeyValue("RDSFactor", "ADField")
If ADField.Length = 0 Then
ServerLog("ERROR: ADField can not be empty")
ConfOk = False
End If
If RConfig.GetKeyValue("RDSFactor", "EnableSMS") = "1" Then
EnableSMS = True
ModemType = RConfig.GetKeyValue("RDSFactor", "USELOCALMODEM")
Select Case ModemType
Case "0"
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("RDSFactor", "COMPORT")
If ComPort.Length = 0 Then
ServerLog("ERROR: ComPort can not be empty")
ConfOk = False
End If
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
End If
Case Else
ServerLog("ERROR: USELOCALMODEM contain invalid configuration. Correct value are 1 or 0")
ConfOk = False
End Select
End If
End If
Dim ClientList As String = ""
ClientList = RConfig.GetKeyValue("RDSFactor", "ClientList")
Dim ClientArray() As String
ClientArray = Split(ClientList, ",")
For i As Integer = 0 To ClientArray.Length - 1
ServerLog("Loading Shared Secret for Client: " & ClientArray(i))
clientHash.Add(ClientArray(i), RConfig.GetKeyValue("Clients", ClientArray(i)))
Next
If ConfOk = True Then
ServerLog("Loading Configuration...OK")
Else
ServerLog("Loading Configuration...FAILED")
End If
Catch
ServerLog("ERROR: Missing RDSFactor.ini from startup path or RDSFactor.ini contains invalid configuration")
ServerLog("Loading Configuration...FAILED")
End
End Try
End Sub
Public Function ApplicationPath() As String
Return Path.GetDirectoryName([Assembly].GetExecutingAssembly().Location)
End Function
Public Shared Function SendSMS(ByVal number As String, ByVal passcode As String) As String
' test if using online sms provider or local modem
If ModemType = 1 Then ' local modem
Dim modem As New SMSModem(ComPort)
modem.Opens()
modem.send(number, passcode, SmsC)
modem.Closes()
modem = Nothing
Return "Ok"
Else
Dim baseurl As String = Provider.Split("?")(0)
Dim client As New System.Net.WebClient()
' Add a user agent header in case the requested URI contains a query.
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR1.0.3705;)")
Dim parameters As String = Provider.Split("?")(1)
Dim pary As String() = parameters.Split("&")
For i As Integer = 0 To pary.Length - 1
If pary(i).IndexOf("***TEXTMESSAGE***") > 0 Then
Dim qpar As String() = pary(i).Split("=")
client.QueryString.Add(qpar(0), passcode)
ElseIf pary(i).IndexOf("***NUMBER***") > 0 Then
Dim qpar As String() = pary(i).Split("=")
client.QueryString.Add(qpar(0), number)
Else
Dim qpar As String() = pary(i).Split("=")
client.QueryString.Add(qpar(0), qpar(1))
End If
Next
Dim data As Stream = client.OpenRead(baseurl)
Dim reader As New StreamReader(data)
Dim s As String = reader.ReadToEnd()
data.Close()
reader.Close()
Return (s)
End If
End Function
Public Shared Function SendEmail(email As String, passcode As String) As String
Dim mail As New MailMessage()
mail.To.Add(email)
mail.From = New MailAddress(SenderEmail)
mail.Subject = "Token: " & passcode
mail.Body = "Subject contains the token code to login to you site"
mail.IsBodyHtml = False
Dim smtp As New SmtpClient(MailServer)
Try
smtp.Send(mail)
If DEBUG = True Then
AccessLog(Now & ": Mail send to: " & email)
End If
Return "SEND"
Catch e As InvalidCastException
If DEBUG = True Then
AccessLog(Now & " : Debug: " & e.Message)
AccessLog(Now & " : Unable to send mail to: " & email & " ## Check that MAILSERVER and SENDEREMAIL are configured correctly in smscode.conf. Also check that your Webinterface server is allowed to relay through the mail server specified")
End If
Return "FAILED"
End Try
End Function
Public Sub CleanupEventHandler(sender, e) Handles cleanupEvent.Elapsed
RDSHandler.Cleanup()
End Sub
End Class

197
server/RDSFactor.vbproj Normal file
View file

@ -0,0 +1,197 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>
</ProductVersion>
<SchemaVersion>
</SchemaVersion>
<ProjectGuid>{04C6C533-9FEA-41B2-B554-A166C7C7FE32}</ProjectGuid>
<OutputType>Exe</OutputType>
<StartupObject>Sub Main</StartupObject>
<RootNamespace>RDSFactor</RootNamespace>
<AssemblyName>RDSFactor</AssemblyName>
<FileAlignment>512</FileAlignment>
<MyType>Console</MyType>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<DefineDebug>true</DefineDebug>
<DefineTrace>true</DefineTrace>
<OutputPath>bin\Debug\</OutputPath>
<DocumentationFile>RDSFactor.xml</DocumentationFile>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType>
<DefineDebug>false</DefineDebug>
<DefineTrace>true</DefineTrace>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DocumentationFile>RDSFactor.xml</DocumentationFile>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
</PropertyGroup>
<PropertyGroup>
<OptionExplicit>On</OptionExplicit>
</PropertyGroup>
<PropertyGroup>
<OptionCompare>Binary</OptionCompare>
</PropertyGroup>
<PropertyGroup>
<OptionStrict>Off</OptionStrict>
</PropertyGroup>
<PropertyGroup>
<OptionInfer>On</OptionInfer>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>My Project\app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.DirectoryServices" />
<Reference Include="System.Drawing" />
<Reference Include="System.ServiceProcess" />
<Reference Include="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
</ItemGroup>
<ItemGroup>
<Import Include="Microsoft.VisualBasic" />
<Import Include="System" />
<Import Include="System.Collections" />
<Import Include="System.Collections.Generic" />
<Import Include="System.Data" />
<Import Include="System.Diagnostics" />
<Import Include="System.Linq" />
<Import Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="exceptions\MissingRadiusSecret.vb" />
<Compile Include="exceptions\MissingUser.vb" />
<Compile Include="handlers\RDSHandler.vb" />
<Compile Include="IniFileVb.vb" />
<Compile Include="Log.vb" />
<Compile Include="My Project\Application.Designer.vb">
<AutoGen>True</AutoGen>
<DependentUpon>Application.myapp</DependentUpon>
</Compile>
<Compile Include="RDSFactor.vb">
<SubType>Component</SubType>
</Compile>
<Compile Include="RDSFactor.Designer.vb">
<DependentUpon>RDSFactor.vb</DependentUpon>
</Compile>
<Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="My Project\Resources.Designer.vb">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="My Project\Settings.Designer.vb">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="ProjectInstaller.Designer.vb">
<DependentUpon>ProjectInstaller.vb</DependentUpon>
</Compile>
<Compile Include="ProjectInstaller.vb">
<SubType>Component</SubType>
</Compile>
<Compile Include="SMSModem.vb" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="RDSFactor.resx">
<DependentUpon>RDSFactor.vb</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="My Project\Resources.resx">
<Generator>VbMyResourcesResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.vb</LastGenOutput>
<CustomToolNamespace>My.Resources</CustomToolNamespace>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="ProjectInstaller.resx">
<DependentUpon>ProjectInstaller.vb</DependentUpon>
</EmbeddedResource>
</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>
<LastGenOutput>Application.Designer.vb</LastGenOutput>
</None>
<None Include="My Project\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<CustomToolNamespace>My</CustomToolNamespace>
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\radar-radius\RADAR\RADAR.vbproj">
<Project>{3ab08a4e-c4fa-4571-a5d4-32bba807c31d}</Project>
<Name>RADAR</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.4.5">
<Visible>False</Visible>
<ProductName>Windows Installer 4.5</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishUrlHistory>publish\</PublishUrlHistory>
<InstallUrlHistory />
<SupportUrlHistory />
<UpdateUrlHistory />
<BootstrapperUrlHistory />
<ErrorReportUrlHistory />
<FallbackCulture>en-US</FallbackCulture>
<VerifyUploadedFiles>false</VerifyUploadedFiles>
</PropertyGroup>
</Project>

69
server/SMSModem.vb Normal file
View file

@ -0,0 +1,69 @@
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Threading
Imports System.IO.Ports
Imports System.Windows.Forms
Public Class SMSModem
Private serialPort As SerialPort
Public Sub New(ByVal comPort As String)
Me.serialPort = New SerialPort()
Me.serialPort.PortName = comPort
Me.serialPort.BaudRate = 38400
Me.serialPort.Parity = Parity.None
Me.serialPort.DataBits = 8
Me.serialPort.StopBits = StopBits.One
Me.serialPort.Handshake = Handshake.RequestToSend
Me.serialPort.DtrEnable = True
Me.serialPort.RtsEnable = True
Me.serialPort.NewLine = System.Environment.NewLine
End Sub
Public Function send(ByVal cellNo As String, ByVal sms As String, ByVal SMSC As String) As Boolean
Dim messages As String = Nothing
messages = sms
If Me.serialPort.IsOpen = True Then
Try
Me.serialPort.WriteLine("AT" + Chr(13))
Thread.Sleep(4)
Me.serialPort.WriteLine("AT+CSCA=""" + SMSC + """" + Chr(13))
Thread.Sleep(30)
Me.serialPort.WriteLine(Chr(13))
Thread.Sleep(30)
Me.serialPort.WriteLine("AT+CMGS=""" + cellNo + """")
Thread.Sleep(30)
Me.serialPort.WriteLine(messages + Chr(26))
Catch ex As Exception
MessageBox.Show(ex.Source)
End Try
Return True
Else
Return False
End If
End Function
Public Sub Opens()
If Me.serialPort.IsOpen = False Then
Try
'bool ok =this.serialPort.IsOpen //does not work between 2 treads
Me.serialPort.Open()
Catch
Thread.Sleep(1000)
'wait for the port to get ready if
Opens()
End Try
End If
End Sub
Public Sub Closes()
If Me.serialPort.IsOpen = True Then
Me.serialPort.Close()
End If
End Sub
End Class

131
server/VSA.vb Normal file
View file

@ -0,0 +1,131 @@
'Copyright (C) 2008-2011 Nikolay Semov
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
' You should have received a copy of the GNU General Public License
' along with this program. If not, see <http://www.gnu.org/licenses/>.
Imports CICRadarR.Conversion
Public Class CiscoAVPair
Private mVendorType As CiscoAVPairType
Private mVendorName As String
Private mVendorValue As String
Public ReadOnly Property VendorType() As CiscoAVPairType
Get
Return mVendorType
End Get
End Property
Public ReadOnly Property VendorName() As String
Get
Return mVendorName
End Get
End Property
Public ReadOnly Property VendorValue() As String
Get
Return mVendorValue
End Get
End Property
Public Function GetTimeStamp() As DateTime
Return ConvertToDateTime(mVendorValue)
End Function
Friend Sub New(ByRef value() As Byte)
mVendorType = CiscoAVPairType.Invalid
mVendorName = ""
mVendorValue = ""
If value.Length < 6 Then Exit Sub
If Not (value(0) = 0 And value(1) = 0 And value(2) = 0 And value(3) = 9) Then Exit Sub
If value.Length <> value(5) + 4 Then Exit Sub
mVendorType = value(4)
mVendorName = "generic"
Dim v() As Byte = {}
Array.Resize(v, value.Length - 6)
Array.Copy(value, 6, v, 0, v.Length)
mVendorValue = ConvertToString(v)
If VendorValue.Contains("=") Then
mVendorName = Left(VendorValue, InStr(VendorValue, "=") - 1)
mVendorValue = Right(VendorValue, VendorValue.Length - VendorName.Length - 1)
End If
If VendorName = "h323-ivr-in" Then mVendorType = CiscoAVPairType.IVR_In
If VendorName = "h323-ivr-out" Then mVendorType = CiscoAVPairType.IVR_Out
End Sub
Public Sub New(ByVal type As CiscoAVPairType, ByVal value As String)
mVendorType = type
If type = CiscoAVPairType.Invalid Then
mVendorName = ""
mVendorValue = ""
ElseIf type = CiscoAVPairType.Generic Then
mVendorName = "generic"
mVendorValue = value
Else
mVendorName = "h323-" & Replace(LCase(type.ToString), "_", "-")
mVendorValue = value
End If
End Sub
Public Sub New(ByVal name As String, ByVal value As String)
mVendorType = CiscoAVPairType.Generic
mVendorName = name
mVendorValue = value
End Sub
Public Sub GetRADIUSAttribute(ByRef attributes As RADIUSAttributes)
If attributes Is Nothing Then Exit Sub
If mVendorType = CiscoAVPairType.Invalid Then Exit Sub
Dim data() As Byte = {}
Dim len As Byte = 6
Dim lvt As Byte = mVendorType
If lvt = CiscoAVPairType.IVR_In Or lvt = CiscoAVPairType.IVR_Out Then lvt = 1
If VendorName = "generic" Then
len += VendorValue.Length
Array.Resize(data, len)
ConvertToBytes(VendorValue).CopyTo(data, 6)
Else
len += VendorName.Length + 1 + VendorValue.Length
Array.Resize(data, len)
ConvertToBytes(VendorName & "=" & VendorValue).CopyTo(data, 6)
End If
data(4) = lvt
data(5) = len - 4
data(0) = 0
data(1) = 0
data(2) = 0
data(3) = 9
Dim attr As New RADIUSAttribute(RadiusAttributeType.VendorSpecific, data)
attributes.Add(attr)
End Sub
End Class
Public Enum CiscoAVPairType As Byte
Invalid = 0
Generic = 1
Remote_Address = 23
Conf_Id = 24
Setup_Time = 25
Call_Origin = 26
Call_Type = 27
Connect_Time = 28
Disconnect_Time = 29
Disconnect_Cause = 30
Voice_Quality = 31
GW_Id = 33
IVR_In = 201
IVR_Out = 202
End Enum

23
server/app.config Normal file
View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.diagnostics>
<sources>
<!-- This section defines the logging configuration for My.Application.Log -->
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog"/>
<!-- Uncomment the below section to write to the Application Event Log -->
<!--<add name="EventLog"/>-->
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information"/>
</switches>
<sharedListeners>
<add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter"/>
<!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
</sharedListeners>
</system.diagnostics>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

19
server/conf/RDSFactor.ini Normal file
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

@ -0,0 +1,9 @@
Public Class MissingRadiusSecret
Inherits Exception
Public Sub New(ByVal ip As String)
MyBase.New("No shared secret for ip: " & ip & ". This MUST be inserted in the config file.")
End Sub
End Class

View file

@ -0,0 +1,3 @@
Public Class MissingUser
Inherits Exception
End Class

View file

@ -0,0 +1,341 @@
Imports System.DirectoryServices
Imports System.Web.Helpers
Imports RADAR
Public Class RDSHandler
' User -> Token that proves user has authenticated, but not yet proved
' herself with the 2. factor
Private Shared authTokens As New Hashtable
Private Shared userSessions As New Hashtable
Private Shared sessionTimestamps As New Hashtable
Private Shared encryptedChallangeResults As New Hashtable
Private Shared userLaunchTimestamps As New Hashtable
Private mPacket As RADIUSPacket
Private mUsername As String
Private mPassword As String
' RDS specific values
Private mIsAppLaunchRequest As Boolean
Private mIsGatewayRequest As Boolean
Private mUseSMSFactor As Boolean
Private mUseEmailFactor As Boolean
Public Sub New(packet As RADIUSPacket)
mPacket = packet
mUsername = mPacket.UserName
mPassword = mPacket.UserPassword
CleanUsername()
For Each atts As RADIUSAttribute In mPacket.Attributes.GetAllAttributes(RadiusAttributeType.VendorSpecific)
Dim value As String = atts.GetVendorSpecific.VendorValue.ToString
Select Case UCase(value)
Case "LAUNCH"
mIsAppLaunchRequest = True
Case "TSGATEWAY"
mIsGatewayRequest = True
Case "SMS"
mUseSMSFactor = True
Case "EMAIL"
mUseEmailFactor = True
End Select
Next
End Sub
Private Sub CleanUsername()
' RD Gateway sends EXAMPLE\username
' RD Web sends example\username or - TODO - even example.com\username
If Not mUsername = Nothing Then
mUsername = mUsername.ToLower
End If
End Sub
Public Sub ProcessRequest()
If mIsAppLaunchRequest Then
ProcessAppLaunchRequest()
ElseIf mIsGatewayRequest Then
ProcessGatewayRequest()
Else
ProcessAccessRequest()
End If
End Sub
' Process the RDS specific App Launch request.
' These requests are sent when an app is clicked in RD Web.
'
' It's checked whether the session is still valid. In which case, a
' window is opened for the user, where we allow the user to connect
' through the gateway, an Accept-Access is returned and the RD Web
' launches the RDP client.
'
' NOTE: Requests contain the session GUID in the password attribute
' of the packet.
Public Sub ProcessAppLaunchRequest()
RDSFactor.AccessLog(mPacket, "AppLaunchRequest")
' When the packet is an AppLaunchRequest the password attribute contains the session id!
Dim packetSessionId = mPassword
Dim storedSessionId = userSessions(mUsername)
If storedSessionId = Nothing Then
RDSFactor.AccessLog(mPacket, "User has no session. MUST re-authenticate!")
mPacket.RejectAccessRequest()
Exit Sub
End If
If Not storedSessionId = packetSessionId Then
RDSFactor.AccessLog(mPacket, "Stored session id didn't match packet session id!")
mPacket.RejectAccessRequest()
Exit Sub
End If
If HasValidSession(mUsername) Then
RDSFactor.AccessLog(mPacket, "Opening window")
' Pro-long user session
sessionTimestamps(mUsername) = Now
' Open gateway connection window
userLaunchTimestamps(mUsername) = Now
mPacket.AcceptAccessRequest()
Exit Sub
Else
RDSFactor.AccessLog(mPacket, "Session timed out -- User MUST re-authenticate")
userSessions.Remove(mUsername)
sessionTimestamps.Remove(mUsername)
mPacket.RejectAccessRequest()
End If
End Sub
Public Shared Function HasValidLaunchWindow(username) As Boolean
Dim timestamp = userLaunchTimestamps(username)
Dim secondsSinceLaunch = DateDiff(DateInterval.Second, timestamp, Now)
If secondsSinceLaunch < RDSFactor.LaunchTimeOut Then
Return True
Else
Return False
End If
End Function
Public Shared Function HasValidSession(username) As Boolean
Dim id = userSessions(username)
Dim timestamp = sessionTimestamps(username)
Dim minsSinceLastActivity = DateDiff(DateInterval.Minute, timestamp, Now)
If minsSinceLastActivity < RDSFactor.SessionTimeOut Then
Return True
Else
Return False
End If
End Function
' Process the request from the Network Policy Server in the RDS Gateway.
' These are sent when an RDP client tries to connect through the Gateway.
'
' Accept-Access is returned when the user has a
' * valid session; and a
' * valid app launch window
'
' The launch window is closed after this request.
'
' TODO: Fix race-condition RD Web vs. Gateway. Don't start RDP client in RD Web
' before ensuring App Launch request was successful
Public Sub ProcessGatewayRequest()
RDSFactor.AccessLog(mPacket, "Gateway Request")
Dim sessionId = userSessions(mUsername)
Dim launchTimestamp = userLaunchTimestamps(mUsername)
Dim attributes As New RADIUSAttributes
If sessionId = Nothing Or launchTimestamp = Nothing Then
RDSFactor.AccessLog(mPacket, "User's has no launch window. User must re-authenticate")
mPacket.RejectAccessRequest()
Exit Sub
End If
Dim hasProxyState = mPacket.Attributes.AttributeExists(RadiusAttributeType.ProxyState)
If hasProxyState Then
Dim proxyState = mPacket.Attributes.GetFirstAttribute(RadiusAttributeType.ProxyState)
attributes.Add(proxyState)
End If
If HasValidLaunchWindow(mUsername) Then
RDSFactor.AccessLog(mPacket, "Opening gateway launch window")
mPacket.AcceptAccessRequest(attributes)
Else
RDSFactor.AccessLog(mPacket, "Gateway launch window has timed out!")
mPacket.RejectAccessRequest()
End If
RDSFactor.AccessLog(mPacket, "Removing gateway launch window")
userLaunchTimestamps.Remove(mUsername)
End Sub
Public Sub ProcessAccessRequest()
Dim hasState = mPacket.Attributes.AttributeExists(RadiusAttributeType.State)
If hasState Then
' An Access-Request with a state is pr. definition a challange response.
ProcessChallengeResponse()
Exit Sub
End If
RDSFactor.AccessLog(mPacket, "AccessRequest")
Try
Dim ldapResult = Authenticate()
If RDSFactor.EnableOTP Then
TwoFactorChallenge()
Exit Sub
Else
Accept()
End If
Catch ex As Exception
RDSFactor.AccessLog(mPacket, "Authentication failed. Sending reject. Error: " & ex.Message)
mPacket.RejectAccessRequest()
End Try
End Sub
Private Sub Accept()
RDSFactor.AccessLog(mPacket, "AcceptAccessRequest")
Dim sGUID As String = System.Guid.NewGuid.ToString()
userSessions(mUsername) = sGUID
sessionTimestamps(mUsername) = Now
Dim attributes As New RADIUSAttributes
Dim guidAttribute As New RADIUSAttribute(RadiusAttributeType.ReplyMessage, sGUID)
attributes.Add(guidAttribute)
mPacket.AcceptAccessRequest(attributes)
End Sub
Private Sub ProcessChallengeResponse()
Dim authToken = mPacket.Attributes.GetFirstAttribute(RadiusAttributeType.State).ToString
If Not authToken = authTokens(mUsername) Then
Throw New Exception("User is trying to respond to challange without valid auth token")
End If
' When the packet is an Challange-Response the password attr. contains the encrypted result
Dim userEncryptedResult = mPassword
Dim localEncryptedResult = encryptedChallangeResults(mUsername)
If localEncryptedResult = userEncryptedResult Then
RDSFactor.AccessLog(mPacket, "ChallengeResponse Success")
encryptedChallangeResults.Remove(mUsername)
authTokens.Remove(mUsername)
Accept()
Else
RDSFactor.AccessLog(mPacket, "Wrong challange code!")
mPacket.RejectAccessRequest()
End If
End Sub
Private Sub TwoFactorChallenge()
Dim challangeCode = RDSFactor.GenerateCode
Dim authToken = System.Guid.NewGuid.ToString
Dim clientIP = mPacket.EndPoint.Address.ToString
Dim sharedSecret = RDSFactor.secrets(clientIP)
RDSFactor.AccessLog(mPacket, "Access Challange Code: " & challangeCode)
If sharedSecret = Nothing Then
Throw New Exception("No shared secret for client:" & clientIP)
End If
authTokens(mUsername) = authToken
Dim encryptedChallangeResult = Crypto.SHA256(mUsername & challangeCode & sharedSecret)
encryptedChallangeResults(mUsername) = encryptedChallangeResult
If mUseSMSFactor Then
RDSFactor.AccessLog(mPacket, "TODO: Send SMS")
End If
If mUseEmailFactor Then
RDSFactor.AccessLog(mPacket, "TODO: Send Email")
End If
Dim attributes As New RADIUSAttributes
Dim replyMessageAttr As New RADIUSAttribute(RadiusAttributeType.ReplyMessage, "SMS Token")
Dim stateAttr As New RADIUSAttribute(RadiusAttributeType.State, authToken)
attributes.Add(replyMessageAttr)
attributes.Add(stateAttr)
mPacket.SendAccessChallange(attributes)
End Sub
Private Function Authenticate() As System.DirectoryServices.SearchResult
Dim password As String = mPacket.UserPassword
Dim ldapDomain As String = RDSFactor.LDAPDomain
RDSFactor.AccessLog(mPacket, "Authenticating with LDAP: " & "LDAP://" & ldapDomain)
Dim dirEntry As New DirectoryEntry("LDAP://" & ldapDomain, mUsername, password)
Dim obj As Object = dirEntry.NativeObject
Dim search As New DirectorySearcher(dirEntry)
If InStr(mUsername, "@") > 0 Then
search.Filter = "(userPrincipalName=" + mUsername + ")"
Else
search.Filter = "(SAMAccountName=" + Split(mUsername, "\")(1) + ")"
End If
search.PropertiesToLoad.Add("distinguishedName")
If RDSFactor.EnableOTP = True Then
search.PropertiesToLoad.Add(RDSFactor.ADField)
search.PropertiesToLoad.Add(RDSFactor.ADMailField)
End If
Dim result = search.FindOne()
If IsDBNull(result) Then
RDSFactor.AccessLog(mPacket, "Failed to authenticate with Active Directory")
Throw New MissingUser
End If
Return result
End Function
Private Function LdapGetNumber(result As SearchResult) As String
Dim mobile = result.Properties(RDSFactor.ADField)(0)
mobile = Replace(mobile, "+", "")
If mobile.Trim.Length = 0 Then
RDSFactor.AccessLog(mPacket, "Unable to find correct phone number for user " & mUsername)
End If
Return mobile
End Function
Private Function LdapGetEmail(result As SearchResult) As String
Dim email = result.Properties(RDSFactor.ADMailField)(0)
If InStr(email, "@") = 0 Then
RDSFactor.AccessLog(mPacket, "Unable to find correct email for user " & mUsername)
End If
Return email
End Function
Public Shared Sub Cleanup()
RDSFactor.AccessLog("TimerCleanUp")
Dim users = New ArrayList(userSessions.Keys)
For Each username In users
If Not HasValidSession(username) Then
userSessions.Remove(username)
sessionTimestamps.Remove(username)
userLaunchTimestamps.Remove(username)
encryptedChallangeResults.Remove(username)
authTokens.Remove(username)
End If
Next
End Sub
End Class