VERSION 5.00 Object = "{48E59290-9880-11CF-9754-00AA00C00908}#1.0#0"; "MSINET.OCX" Begin VB.Form fMain BorderStyle = 1 'Fixed Single Caption = "ZoneEdit Dynamic Update Client" ClientHeight = 3000 ClientLeft = 45 ClientTop = 330 ClientWidth = 3975 Icon = "zeDyn.frx":0000 LinkTopic = "Form1" MaxButton = 0 'False MinButton = 0 'False ScaleHeight = 3000 ScaleWidth = 3975 StartUpPosition = 3 'Windows Default Begin VB.PictureBox uImg BorderStyle = 0 'None Height = 255 Left = 2280 Picture = "zeDyn.frx":030A ScaleHeight = 255 ScaleWidth = 375 TabIndex = 8 Top = 1080 Visible = 0 'False Width = 375 End Begin InetCtlsObjects.Inet uInet Left = 2640 Top = 2400 _ExtentX = 1005 _ExtentY = 1005 _Version = 393216 End Begin VB.Timer uTick Interval = 30000 Left = 1920 Top = 2400 End Begin VB.CommandButton uLog Caption = "Log" Height = 375 Left = 2640 TabIndex = 7 Top = 2520 Width = 1215 End Begin VB.TextBox uHosts Height = 975 Left = 120 MultiLine = -1 'True ScrollBars = 2 'Vertical TabIndex = 6 Top = 1440 Width = 3735 End Begin VB.TextBox uPass Height = 285 IMEMode = 3 'DISABLE Left = 960 PasswordChar = "#" TabIndex = 5 Top = 480 Width = 2895 End Begin VB.TextBox uLogin Height = 285 Left = 960 TabIndex = 4 Top = 120 Width = 2895 End Begin VB.CommandButton uOK Caption = "OK" Height = 375 Left = 120 TabIndex = 3 Top = 2520 Width = 1215 End Begin VB.Label Label6 Caption = "Status:" Height = 255 Left = 120 TabIndex = 10 Top = 840 Width = 855 End Begin VB.Label uStatus Caption = "Starting" ForeColor = &H80000002& Height = 255 Left = 960 TabIndex = 9 Top = 840 Width = 2895 End Begin VB.Label Label3 Caption = "Password:" Height = 255 Left = 120 TabIndex = 2 Top = 480 Width = 1095 End Begin VB.Label Label2 Caption = "Username:" Height = 255 Left = 120 TabIndex = 1 Top = 120 Width = 1095 End Begin VB.Label Label1 Caption = "Host(s):" Height = 255 Left = 120 TabIndex = 0 Top = 1200 Width = 1095 End Begin VB.Menu mnuTray Caption = "Tray" Visible = 0 'False Begin VB.Menu mnuOpen Caption = "&Open" End Begin VB.Menu mnuQuit Caption = "&Quit" End End End Attribute VB_Name = "fMain" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit ' app globs Public gINIFile As String Public gLogFile As String Public gCurIP As String Public gIPDetectURL As String Public gIPDetectPrefix As String Public LastState As Integer ' ini stuff Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long ' tray code Private Declare Sub Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) Private Type NOTIFYICONDATA cbSize As Long hWnd As Long uID As Long uFlags As Long uCallbackMessage As Long hIcon As Long szTip As String * 64 End Type Private Const NIM_ADD = &H0 Private Const NIM_MODIFY = &H1 Private Const NIM_DELETE = &H2 Private Const NIF_MESSAGE = &H1 Private Const NIF_ICON = &H2 Private Const NIF_TIP = &H4 Private Const NIF_DOALL = NIF_MESSAGE Or NIF_ICON Or NIF_TIP Private Const WM_MOUSEMOVE = &H200 Private Const WM_LBUTTONDBLCLK = &H203 Private Const WM_LBUTTONDOWN = &H201 Private Const WM_RBUTTONDOWN = &H204 Private tic As NOTIFYICONDATA Private inTray As Boolean Public Function GetINIString(strINIFile As String, strSection As String, strKey As String, _ strDefault As String) As String Dim strTemp As String * 256 'set string max length to 256 chars Dim intLength As Integer strTemp = "" strTemp = Space$(256) 'initialize string with spaces intLength = GetPrivateProfileString(strSection, strKey, strDefault, strTemp, 255, strINIFile) GetINIString = Left$(strTemp, intLength) End Function Function ParseHosts(Data As String) Dim DLength As Integer Dim Extract() As String Dim i As Integer Dim Position As Integer Dim Character As String DLength = Len(Data) ReDim Extract(0) Position = 1 For i = 1 To DLength Character = Mid(Data, i, 1) If Asc(Character) <> 10 And Asc(Character) <> 13 And Asc(Character) <> 44 Then If UBound(Extract) < Position Then ReDim Preserve Extract(Position) Extract(Position) = Extract(Position) & Character Else If UBound(Extract) < Position Then ReDim Preserve Extract(Position) Extract(Position) = RTrim(Extract(Position)) If Extract(Position) <> "" Then Position = Position + 1 End If End If Next i Dim strFinal As String For i = 1 To UBound(Extract) strFinal = strFinal + Extract(i) + "," Next i If strFinal <> "" Then strFinal = Mid(strFinal, 1, Len(strFinal) - 1) End If ParseHosts = strFinal End Function Public Sub WriteINIString(strINIFile As String, strSection As String, strKey As String, strvalue As String) Dim indx As Integer Dim strTemp As String strTemp = strvalue 'a key value must not contain either a carriage return or a line feed, therefore check for these in 'the passed string, and substitute a " " if you find one. This is purely precautionary. For indx = 1 To Len(strvalue) If Mid$(strvalue, indx, 1) = vbCr Or Mid$(strvalue, indx, 1) = vbLf Then Mid$(strvalue, indx) = " " End If Next indx indx = WritePrivateProfileString(strSection, strKey, strTemp, strINIFile) End Sub Private Sub Form_Load() gINIFile = App.Path gINIFile = gINIFile + "\zeDyn.ini" gLogFile = App.Path gLogFile = gLogFile + "\zeDyn.log" LoadINI If uLogin.Text <> "" And uPass.Text <> "" And uHosts.Text <> "" Then Me.WindowState = vbMinimized End If Open gLogFile For Append As #1 Print #1, Now & vbTab & "Start" Close #1 End Sub Private Sub uLog_Click() Shell "notepad.exe " & gLogFile, vbNormalFocus End Sub Private Sub uOK_Click() WriteINIString gINIFile, "Settings", "Login", uLogin.Text WriteINIString gINIFile, "Settings", "Pass", uPass.Text Dim HostList As String HostList = ParseHosts(uHosts.Text) If uHosts.Text <> HostList Then uHosts.Text = HostList gCurIP = "" WriteINIString gINIFile, "Settings", "IP", "" End If WriteINIString gINIFile, "Settings", "Hosts", HostList Me.WindowState = vbMinimized uTick_Timer End Sub Private Sub IPError() Open gLogFile For Append As #1 Print #1, Now & vbTab & "IP Detect Failed" Close #1 uStatus.Caption = "IP Detect Failed" End Sub Private Sub uTick_Timer() Dim ip As String Dim i As Integer If Me.WindowState = vbNormal Then Exit Sub End If If uInet.StillExecuting Then Exit Sub End If ' get ip ip = uInet.OpenURL(gIPDetectURL, icString) i = InStr(ip, gIPDetectPrefix) If i < 1 Then IPError Exit Sub End If ip = Mid(ip, i + 11) i = InStr(ip, "<") If i < 1 Then IPError Exit Sub End If ip = Left(ip, i - 1) ip = Trim(ip) If ip <> gCurIP Then ' update dynamic Dim ok As String Dim hosts As String hosts = Replace(uHosts.Text, " ", "") uStatus.Caption = "Changing IP to " & ip uInet.URL = "http://dynamic.zoneedit.com/auth/dynamic.html?dnsto=" & ip & "&host=" & hosts uInet.UserName = uLogin.Text uInet.Password = uPass.Text ok = uInet.OpenURL ok = Replace(ok, Asc(13), " ") ok = Replace(ok, Asc(10), " ") Open gLogFile For Append As #1 Print #1, Now & vbTab & ok Close #1 If InStr(ok, " "" Then tip = tip & " (" & gCurIP & ")" End If tic.szTip = tip & Chr$(0) Me.Visible = False Shell_NotifyIcon NIM_ADD, tic inTray = True End Sub Private Sub SetTrayTip(tip As String) tic.cbSize = Len(tic) tic.hWnd = uImg.hWnd tic.uID = 1& tic.uFlags = NIF_TIP tic.szTip = tip & Chr$(0) Shell_NotifyIcon NIM_MODIFY, tic End Sub Private Sub LoadINI() uLogin.Text = GetINIString(gINIFile, "Settings", "Login", "") uPass.Text = GetINIString(gINIFile, "Settings", "Pass", "") uHosts.Text = GetINIString(gINIFile, "Settings", "Hosts", "") gIPDetectURL = GetINIString(gINIFile, "Settings", "IPDetectURL", "http://dynamic.zoneedit.com/checkip.html") gIPDetectPrefix = GetINIString(gINIFile, "Settings", "IPDetectPrefix", "IP Address:") gCurIP = GetINIString(gINIFile, "Settings", "IP", "") uStatus.Caption = "OK " & gCurIP End Sub