mirror of
https://github.com/jakobadam/RDSFactor.git
synced 2025-07-23 18:15:55 +02:00
SMS sending
This commit is contained in:
parent
5b7c38ee96
commit
f886f3af72
9 changed files with 91 additions and 34 deletions
|
@ -7,12 +7,14 @@ Imports System.Security.Cryptography
|
|||
Imports System.Text
|
||||
Imports System
|
||||
Imports System.Net.Mail
|
||||
Imports System.Net.Http
|
||||
Imports System.Web
|
||||
Imports RADAR
|
||||
|
||||
Public Class RDSFactor
|
||||
|
||||
Public Shared LDAPDomain As String = ""
|
||||
Public Shared ADField As String = ""
|
||||
Public Shared ADMobileField As String = ""
|
||||
Public Shared ADMailField As String = ""
|
||||
Public Shared EnableOTP As Boolean
|
||||
Public Shared secrets As New NASAuthList
|
||||
|
@ -149,8 +151,8 @@ Public Class RDSFactor
|
|||
ADMailField = RConfig.GetKeyValue("RDSFactor", "ADMailField")
|
||||
End If
|
||||
|
||||
ADField = RConfig.GetKeyValue("RDSFactor", "ADField")
|
||||
If ADField.Length = 0 Then
|
||||
ADMobileField = RConfig.GetKeyValue("RDSFactor", "ADField")
|
||||
If ADMobileField.Length = 0 Then
|
||||
LogInfo("ERROR: ADField can not be empty")
|
||||
ConfOk = False
|
||||
End If
|
||||
|
@ -217,40 +219,31 @@ Public Class RDSFactor
|
|||
modem = Nothing
|
||||
Return "Ok"
|
||||
Else
|
||||
LogDebug("Sending OTP: " & passcode & " to: " & number)
|
||||
|
||||
' TODO: Use HttpUtility UrlEncode when
|
||||
' we figure out how to add the dll!!!
|
||||
Dim url As String = Provider
|
||||
url = url.Replace("***TEXTMESSAGE***", passcode)
|
||||
url = url.Replace("***NUMBER***", number)
|
||||
|
||||
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.
|
||||
Dim client As New HttpClient
|
||||
|
||||
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR1.0.3705;)")
|
||||
Dim response = client.GetAsync(url).Result
|
||||
Dim content = response.Content.ReadAsStringAsync().Result
|
||||
|
||||
Dim parameters As String = Provider.Split("?")(1)
|
||||
Dim pary As String() = parameters.Split("&")
|
||||
If response.IsSuccessStatusCode Then
|
||||
|
||||
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))
|
||||
If Not url.IndexOf("cpsms.dk") = -1 Then
|
||||
' NOTE: Yes cpsms does indeed return HTTP 200 on errors!?!
|
||||
If Not content.IndexOf("error") = -1 Then
|
||||
Throw New SMSSendException(content)
|
||||
End If
|
||||
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)
|
||||
Else
|
||||
Throw New SMSSendException(content)
|
||||
End If
|
||||
End If
|
||||
|
||||
End Function
|
||||
|
||||
Public Shared Function SendEmail(email As String, passcode As String) As String
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||
|
@ -14,7 +14,7 @@
|
|||
<AssemblyName>RDSFactor</AssemblyName>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<MyType>Console</MyType>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile>
|
||||
</TargetFrameworkProfile>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
|
@ -42,6 +42,7 @@
|
|||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DocumentationFile>RDSFactor.xml</DocumentationFile>
|
||||
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
|
@ -52,6 +53,7 @@
|
|||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DocumentationFile>RDSFactor.xml</DocumentationFile>
|
||||
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OptionExplicit>On</OptionExplicit>
|
||||
|
@ -69,12 +71,21 @@
|
|||
<ApplicationManifest>My Project\app.manifest</ApplicationManifest>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\web\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<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.Net.Http" />
|
||||
<Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\web\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>
|
||||
</Reference>
|
||||
<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" />
|
||||
|
@ -94,8 +105,12 @@
|
|||
<Import Include="System.Xml.Linq" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="exceptions\MissingEmail.vb" />
|
||||
<Compile Include="exceptions\MissingNumber.vb" />
|
||||
<Compile Include="exceptions\MissingLdapField.vb" />
|
||||
<Compile Include="exceptions\MissingRadiusSecret.vb" />
|
||||
<Compile Include="exceptions\MissingUser.vb" />
|
||||
<Compile Include="exceptions\SMSSendException.vb" />
|
||||
<Compile Include="handlers\RDSHandler.vb" />
|
||||
<Compile Include="IniFile.vb" />
|
||||
<Compile Include="Log.vb" />
|
||||
|
@ -157,6 +172,7 @@
|
|||
<CustomToolNamespace>My</CustomToolNamespace>
|
||||
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
|
||||
</None>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\radar-radius\RADAR\RADAR.vbproj">
|
||||
|
|
9
server/exceptions/MissingEmail.vb
Normal file
9
server/exceptions/MissingEmail.vb
Normal file
|
@ -0,0 +1,9 @@
|
|||
Public Class MissingEmail
|
||||
|
||||
Inherits Exception
|
||||
|
||||
Public Sub New(ByVal user As String)
|
||||
MyBase.New("User: " & user & " has no email")
|
||||
End Sub
|
||||
|
||||
End Class
|
9
server/exceptions/MissingLdapField.vb
Normal file
9
server/exceptions/MissingLdapField.vb
Normal file
|
@ -0,0 +1,9 @@
|
|||
Public Class MissingLdapField
|
||||
|
||||
Inherits Exception
|
||||
|
||||
Public Sub New(field As String, username As String)
|
||||
MyBase.New("No " & field & " entry in LDAP for " & username)
|
||||
End Sub
|
||||
|
||||
End Class
|
9
server/exceptions/MissingNumber.vb
Normal file
9
server/exceptions/MissingNumber.vb
Normal file
|
@ -0,0 +1,9 @@
|
|||
Public Class MissingNumber
|
||||
|
||||
Inherits Exception
|
||||
|
||||
Public Sub New(ByVal user As String)
|
||||
MyBase.New("User: " & user & " has no mobile number")
|
||||
End Sub
|
||||
|
||||
End Class
|
9
server/exceptions/SMSSendException.vb
Normal file
9
server/exceptions/SMSSendException.vb
Normal file
|
@ -0,0 +1,9 @@
|
|||
Public Class SMSSendException
|
||||
|
||||
Inherits Exception
|
||||
|
||||
Public Sub New(ByVal message As String)
|
||||
MyBase.New("SMS send error: " & message)
|
||||
End Sub
|
||||
|
||||
End Class
|
5
server/packages.config
Normal file
5
server/packages.config
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net451" />
|
||||
<package id="Newtonsoft.Json" version="6.0.4" targetFramework="net451" />
|
||||
</packages>
|
|
@ -10,7 +10,8 @@ EndProject
|
|||
Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "Pages", "http://localhost/RDWeb/Pages", "{B31FB884-C42E-417D-AF0D-409FE7D30351}"
|
||||
ProjectSection(WebsiteProperties) = preProject
|
||||
UseIISExpress = "false"
|
||||
TargetFrameworkMoniker = ".NETFramework,Version%3Dv4.5"
|
||||
TargetFrameworkMoniker = ".NETFramework,Version%3Dv4.5.1"
|
||||
ProjectReferences = "{3ab08a4e-c4fa-4571-a5d4-32bba807c31d}|RADAR.dll;"
|
||||
Debug.AspNetCompiler.VirtualPath = "/Pages"
|
||||
Debug.AspNetCompiler.PhysicalPath = "RDWeb\Pages\"
|
||||
Debug.AspNetCompiler.TargetPath = "PrecompiledWeb\Pages\"
|
||||
|
@ -27,6 +28,10 @@ Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "Pages", "http://localhost/R
|
|||
Release.AspNetCompiler.Debug = "False"
|
||||
SlnRelativePath = "RDWeb\Pages\"
|
||||
EndProjectSection
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{04C6C533-9FEA-41B2-B554-A166C7C7FE32} = {04C6C533-9FEA-41B2-B554-A166C7C7FE32}
|
||||
{3AB08A4E-C4FA-4571-A5D4-32BBA807C31D} = {3AB08A4E-C4FA-4571-A5D4-32BBA807C31D}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
|
|
@ -85,8 +85,10 @@
|
|||
</authorization>
|
||||
</personalization>
|
||||
</webParts>
|
||||
<compilation targetFramework="4.5" debug="true">
|
||||
<compilation targetFramework="4.5.1" debug="true">
|
||||
<assemblies>
|
||||
<add assembly="System.Net, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
|
||||
<add assembly="System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
|
||||
<add assembly="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
|
||||
</assemblies>
|
||||
</compilation>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue