diff --git a/yealink_dialer/App.config b/yealink_dialer/App.config index 00c4b80..b43fe64 100644 --- a/yealink_dialer/App.config +++ b/yealink_dialer/App.config @@ -2,5 +2,5 @@ - + diff --git a/yealink_dialer/Form1.Designer.vb b/yealink_dialer/Form1.Designer.vb index 817e0f7..1f52c86 100644 --- a/yealink_dialer/Form1.Designer.vb +++ b/yealink_dialer/Form1.Designer.vb @@ -98,7 +98,7 @@ Partial Class Form1 Me.RichTextBox1.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None Me.RichTextBox1.Size = New System.Drawing.Size(238, 58) Me.RichTextBox1.TabIndex = 9 - Me.RichTextBox1.Text = "" + Me.RichTextBox1.Text = "PHONEIP=192.168.1.100" & Global.Microsoft.VisualBasic.ChrW(10) & "SIPACCOUNT=10@192.168.1.1" & Global.Microsoft.VisualBasic.ChrW(10) & "USERNAME=admin" & Global.Microsoft.VisualBasic.ChrW(10) & "PASSWORD=admin" & Global.Microsoft.VisualBasic.ChrW(10) Me.RichTextBox1.Visible = False ' 'Button2 diff --git a/yealink_dialer/Form1.resx b/yealink_dialer/Form1.resx index 2a83eac..ecfd93e 100644 --- a/yealink_dialer/Form1.resx +++ b/yealink_dialer/Form1.resx @@ -112,21 +112,21 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + 17, 17 - + 129, 17 - + 231, 17 - + AAABAAEAgIAAAAEAIAAoCAEAFgAAACgAAACAAAAAAAEAAAEAIAAAAAAAAAABABILAAASCwAAAAAAAAAA diff --git a/yealink_dialer/Form1.vb b/yealink_dialer/Form1.vb index 63d1050..e818764 100644 --- a/yealink_dialer/Form1.vb +++ b/yealink_dialer/Form1.vb @@ -1,9 +1,12 @@ Imports System.Security.Cryptography Imports System.IO Imports System.Text - +Imports System.Management Public Class Form1 Inherits System.Windows.Forms.Form + + Dim CFGSecret As String = My.Computer.FileSystem.ReadAllText(Application.StartupPath() & "\data\secret.cfg") + Dim DIAL As String Dim PHONEIP As String Dim SIPACCOUNT As String @@ -13,43 +16,57 @@ Public Class Form1 Dim CRDTA As String Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load + + 'Load application settings. Dim ConfigContent As String = My.Computer.FileSystem.ReadAllText(Application.StartupPath() & "\data\config.ini") RichTextBox2.Text = ConfigContent CTime = RichTextBox2.Lines(1).Replace("closedelay=", "") - 1 CallDelay.Interval = RichTextBox2.Lines(3).Replace("dialdelay=", "") & "000" - Dim PhoneContent As String = My.Computer.FileSystem.ReadAllText(Application.StartupPath() & "\data\phone.cfg") - - Dim rd As New RijndaelManaged - Dim rijndaelIvLength As Integer = 16 - Dim md5 As New MD5CryptoServiceProvider - Dim key() As Byte = md5.ComputeHash(Encoding.UTF8.GetBytes("duSK(57&5fHPskg8%$/3jalskg90DGNA51")) - md5.Clear() - Dim encdata() As Byte = Convert.FromBase64String(PhoneContent) - Dim ms As New MemoryStream(encdata) - Dim iv(15) As Byte - ms.Read(iv, 0, rijndaelIvLength) - rd.IV = iv - rd.Key = key - Dim cs As New CryptoStream(ms, rd.CreateDecryptor, CryptoStreamMode.Read) - Dim data(ms.Length - rijndaelIvLength) As Byte - Dim i As Integer = cs.Read(data, 0, data.Length) - CRDTA = System.Text.Encoding.UTF8.GetString(data, 0, i) - cs.Close() - rd.Clear() - - RichTextBox1.Text = CRDTA + 'Load phone configuration file and decrypt it. + Try + Dim PhoneContent As String = My.Computer.FileSystem.ReadAllText(Application.StartupPath() & "\data\phone.cfg") + Dim rd As New RijndaelManaged + Dim rijndaelIvLength As Integer = 16 + Dim md5 As New MD5CryptoServiceProvider + Dim key() As Byte = md5.ComputeHash(Encoding.UTF8.GetBytes(CFGSecret)) + md5.Clear() + Dim encdata() As Byte = Convert.FromBase64String(PhoneContent) + Dim ms As New MemoryStream(encdata) + Dim iv(15) As Byte + ms.Read(iv, 0, rijndaelIvLength) + rd.IV = iv + rd.Key = key + Dim cs As New CryptoStream(ms, rd.CreateDecryptor, CryptoStreamMode.Read) + Dim data(ms.Length - rijndaelIvLength) As Byte + Dim i As Integer = cs.Read(data, 0, data.Length) + CRDTA = System.Text.Encoding.UTF8.GetString(data, 0, i) + cs.Close() + rd.Clear() + RichTextBox1.Text = CRDTA + + Catch ex As Exception + + Finally + End Try + + 'Configure parameters PHONEIP = RichTextBox1.Lines(0).Replace("PHONEIP=", "") SIPACCOUNT = RichTextBox1.Lines(1).Replace("SIPACCOUNT=", "") USERNAME = RichTextBox1.Lines(2).Replace("USERNAME=", "") PASSWORD = RichTextBox1.Lines(3).Replace("PASSWORD=", "") + + + 'Grab command line args and sanitize them. Try DIAL = My.Application.CommandLineArgs(0).Replace("tel:", "") DIAL = DIAL.Replace("/", "") DIAL = DIAL.Replace("-", "") Label1.Text = "Calling: " & DIAL + + 'Start timers depending on config file. If RichTextBox2.Lines(0).Replace("autoclose=", "") = "true" Then CloseTimer.Start() If RichTextBox2.Lines(2).Replace("autodial=", "") = "true" Then CallDelay.Start() Catch @@ -64,11 +81,27 @@ Public Class Form1 End Sub Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click + 'This button serves 2 functions, depending on the mode. + If Button1.Text = "Save" Then + 'If application was not launched by a callto link, this saves the configuration with encryption. + + 'Generate new random crypto password and save it. + + CFGSecret = RandomString(250, 256) + Using writer As New System.IO.StreamWriter(Application.StartupPath() & "\data\secret.cfg") + For Each line In "A" + writer.Write(CFGSecret) + Next + End Using + + + 'Encrypt config with generated string. + Dim rd As New RijndaelManaged Dim md5 As New MD5CryptoServiceProvider - Dim key() As Byte = md5.ComputeHash(Encoding.UTF8.GetBytes("duSK(57&5fHPskg8%$/3jalskg90DGNA51")) + Dim key() As Byte = md5.ComputeHash(Encoding.UTF8.GetBytes(CFGSecret)) md5.Clear() rd.Key = key rd.GenerateIV() @@ -84,12 +117,17 @@ Public Class Form1 cs.Close() rd.Clear() + 'Save encrypted data. Using writer As New System.IO.StreamWriter(Application.StartupPath() & "\data\phone.cfg") For Each line In "A" writer.Write(CRDTA) Next End Using + Else + + 'If launched with callto link, this button instead is the CALL button and initiates the call once pressed. + CloseTimer.Stop() WebBrowser1.Navigate("http://" & USERNAME & ":" & PASSWORD & "@" & PHONEIP & "/servlet?key=number=" & DIAL & "&outgoing_uri=" & SIPACCOUNT & "") Closer.Start() @@ -98,6 +136,7 @@ Public Class Form1 End If End Sub + 'Autoclose after delay, if autoclose is enabled. Private Sub CloseTimer_Tick(sender As Object, e As EventArgs) Handles CloseTimer.Tick If CTime > 0 Then CTime = CTime - 1 @@ -106,23 +145,55 @@ Public Class Form1 End If End Sub + 'Execute call after delay, if autocall is enabled. Private Sub CallDelay_Tick(sender As Object, e As EventArgs) Handles CallDelay.Tick WebBrowser1.Navigate("http://" & USERNAME & ":" & PASSWORD & "@" & PHONEIP & "/servlet?key=number=" & DIAL & "&outgoing_uri=" & SIPACCOUNT & "") CallDelay.Stop() End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click - MsgBox("Initiate test call?" & vbNewLine & "(Calls 01234567890)", MsgBoxStyle.YesNo) - PHONEIP = RichTextBox1.Lines(0).Replace("PHONEIP=", "") - SIPACCOUNT = RichTextBox1.Lines(1).Replace("SIPACCOUNT=", "") - USERNAME = RichTextBox1.Lines(2).Replace("USERNAME=", "") - PASSWORD = RichTextBox1.Lines(3).Replace("PASSWORD=", "") - WebBrowser1.Navigate("http://" & USERNAME & ":" & PASSWORD & "@" & PHONEIP & "/servlet?key=number=" & DIAL & "&outgoing_uri=" & SIPACCOUNT & "") + 'Test Call Button + + Dim Buttons As MessageBoxButtons = MessageBoxButtons.YesNo + Dim Result As DialogResult + Result = MessageBox.Show("Initiate test call?" & vbNewLine & "(Calls 01234567890)", "Test call?", Buttons, MessageBoxIcon.Information) + + If Result = DialogResult.Yes Then + PHONEIP = RichTextBox1.Lines(0).Replace("PHONEIP=", "") + SIPACCOUNT = RichTextBox1.Lines(1).Replace("SIPACCOUNT=", "") + USERNAME = RichTextBox1.Lines(2).Replace("USERNAME=", "") + PASSWORD = RichTextBox1.Lines(3).Replace("PASSWORD=", "") + + WebBrowser1.Navigate("http://" & USERNAME & ":" & PASSWORD & "@" & PHONEIP & "/servlet?key=number=" & DIAL & "&outgoing_uri=" & SIPACCOUNT & "") + + End If End Sub Private Sub Closer_Tick(sender As Object, e As EventArgs) Handles Closer.Tick Close() End Sub + 'This function generated the random string to use for encrypting the config file. + Function RandomString(minCharacters As Integer, maxCharacters As Integer) + Dim s As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789=?!&+-#.$§" + Static r As New Random + Dim chactersInString As Integer = r.Next(minCharacters, maxCharacters) + Dim sb As New StringBuilder + For i As Integer = 1 To chactersInString + Dim idx As Integer = r.Next(0, s.Length) + sb.Append(s.Substring(idx, 1)) + Next + Return sb.ToString() + End Function + + 'Generate uinque computer ID for encryption (currently unused) + Public Shared Function GetComputerID() As Long + Dim objMOS As New ManagementObjectSearcher("Select * From Win32_Processor") + Dim computerinfo As String = My.Computer.Name + For Each objMO As Management.ManagementObject In objMOS.Get + computerinfo &= objMO("ProcessorID") + Next + Return computerinfo.GetHashCode + End Function End Class diff --git a/yealink_dialer/My Project/Resources.Designer.vb b/yealink_dialer/My Project/Resources.Designer.vb index 74ed869..cc5a110 100644 --- a/yealink_dialer/My Project/Resources.Designer.vb +++ b/yealink_dialer/My Project/Resources.Designer.vb @@ -22,7 +22,7 @@ Namespace My.Resources ''' ''' Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. ''' - _ diff --git a/yealink_dialer/My Project/Settings.Designer.vb b/yealink_dialer/My Project/Settings.Designer.vb index 2738b44..3ca25f3 100644 --- a/yealink_dialer/My Project/Settings.Designer.vb +++ b/yealink_dialer/My Project/Settings.Designer.vb @@ -15,7 +15,7 @@ Option Explicit On Namespace My _ Partial Friend NotInheritable Class MySettings Inherits Global.System.Configuration.ApplicationSettingsBase diff --git a/yealink_dialer/yealink_dialer.vbproj b/yealink_dialer/yealink_dialer.vbproj index d405773..a7d03aa 100644 --- a/yealink_dialer/yealink_dialer.vbproj +++ b/yealink_dialer/yealink_dialer.vbproj @@ -11,10 +11,11 @@ YDialer 512 WindowsForms - v3.5 + v4.5.2 true true - Client + + AnyCPU @@ -25,6 +26,7 @@ bin\Debug\ YDialer.xml 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + false AnyCPU @@ -35,6 +37,7 @@ bin\Release\ YDialer.xml 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + false On @@ -56,6 +59,7 @@ + @@ -88,6 +92,7 @@ True Application.myapp + True True