#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=icons\Home 2.ico #AutoIt3Wrapper_outfile=wan2web.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ; ================================================================================================================ ; LANGUAGE OPTIONS Opt("TrayMenuMode",3) AutoItSetOption("MustDeclareVars", 0) ; ================================================================================================================ ; INCLUDES (update as needed) #Include #include #include #include #Include ; ================================================================================================================ ; DUPLICATE INSTANCE CHECK (may need to remove or move this around depending on where it is needed) If UBound(ProcessList(@ScriptName)) > 2 Then Exit ; ================================================================================================================ ; SCRIPT IDENTITY $sAppDesc = "Utility for posting your WAN IP to a FTP site" $sAppName = "Wan2Web" $sAppAuthor = "Sean Shrum" $sAppVersion = "2.05" $sAppEmail = StringLower($sAppName)& "@shrum.net" $sAppHome = "http://www.shrum.net/sean/code/" & StringLower($sAppName) $sAppNews = $sAppHome & "/updates.html" $sAppSupport = $sAppHome & "/support.html" $sAppFileType ="." & StringLower($sAppName) $aAppBuild = FileGetTime(@ScriptFullPath) $sAppBuild = $aAppBuild[0] & "." & $aAppBuild[1] & "." & $aAppBuild[2] & " @ " & $aAppBuild[3] & ":" & $aAppBuild[4] & ":" & $aAppBuild[5] $sAppTitle = $sAppName & " v." & $sAppVersion $sAppSettings = "HKEY_CURRENT_USER\software\shrum.net\" & $sAppName ; ================================================================================================================ ; VARIABLE DECLARATIONS / DEFAULTS Global $bDebug=False, $bVerbose=True Global $sSettings, $sFilename, $sServer, $sUsername, $sPassword, $sWAN, $iMinutes, $sCurrentIP, $sStoredIP, $Open, $Conn, $Ftpp, $Ftpc ; ================================================================================================================ ; TRAY ICON AND TOOLTIP SET (looks for .ico in same folder as .exe otherwise uses the build icon) TraySetToolTip($sAppTitle) TraySetIcon($sAppName & ".ico") ; ================================================================================================================ ; SPLASH SCREEN / TRAYTIP BUBBLE (*only* if no command line params are present: automated run/batch call) if $CmdLine[0] = 0 Then Traytip($sAppTitle,$sAppHome & @CRLF & "By " & $sAppAuthor & " :: " & $sAppEmail,5) ; ================================================================================================================ ; REGISTRY UPDATES (location, version, runcount) $iRunCount = RegRead($sAppSettings, "Executed") RegWrite($sAppSettings, "Executed", "REG_SZ", $iRunCount + 1) RegWrite($sAppSettings, "", "REG_SZ", @Scriptdir) RegWrite($sAppSettings, "Version", "REG_SZ", $sAppVersion) ; ================================================================================================================ ; PROGRAM GROUP / SHORTCUTS CREATION (fires only when Executed reg value = "" from above) If $iRunCount = "" Then DirCreate(@ProgramsCommonDir & "\shrum.net\" & $sAppName) FileCreateShortcut(@ScriptFullPath, @ProgramsCommonDir & "\shrum.net\" & $sAppName & "\" & $sAppName & ".lnk") FileCreateShortcut($sAppHome, @ProgramsCommonDir & "\shrum.net\" & $sAppName & "\Homepage.lnk") FileCreateShortcut($sAppSupport, @ProgramsCommonDir & "\shrum.net\" & $sAppName & "\Support.lnk") FileCreateShortcut(@ScriptFullPath, @UserProfileDir & "\application data\microsoft\Internet Explorer\Quick Launch\" & $sAppName & ".lnk") EndIf ; ================================================================================================================ ; LAST RUN SETTINGS LOAD _SettingsLoad() ; ================================================================================================================ ; COMMAND-LINE EVALUATION if $CmdLine[0] <> 0 Then for $i = 1 to $CmdLine[0] $aParam = StringSplit($CmdLine[$i], "=") $sParam = StringUpper(stringleft($aParam[1],1)) Select case $sParam = "F";ilename $sFilename = $aParam[2] case $sParam = "M";inutes $iMinutes = $aParam[2] case $sParam = "P";assword $sPassword = $aParam[2] case $sParam = "S";erver $sServer = $aParam[2] case $sParam = "U";sername $sUsername = $aParam[2] case $sParam = "W";AN $sWAN = $aParam[2] case $sParam = "V";erbose $bVerbose = $aParam[2] case $sParam = "!"; debug (setting '!=' will turn debug on) $bDebug = True EndSelect Next else if fileexists($sAppName & ".ini") Then $sMsg = "Run with the following settings (pulled from INI file)?" & @CRLF & @CRLF $sKey = "Filename" $sTemp = IniRead($sAppName & ".ini", @ComputerName, $sKey, "") if $sTemp = "" Then $sTemp = IniRead($sAppName & ".ini", "Default", $sKey, "") $sMsg &= " " & $sKey & " = " & $sTemp & @crlf $sFilename = $sTemp $sKey = "Minutes" $sTemp = IniRead($sAppName & ".ini", @ComputerName, $sKey, "") if $sTemp = "" Then $sTemp = IniRead($sAppName & ".ini", "Default", $sKey, "") $sMsg &= " " & $sKey & " = " & $sTemp & @crlf $iMinutes = $sTemp $sKey = "Server" $sTemp = IniRead($sAppName & ".ini", @ComputerName, $sKey, "") if $sTemp = "" Then $sTemp = IniRead($sAppName & ".ini", "Default", $sKey, "") $sMsg &= " " & $sKey & " = " & $sTemp & @crlf $sServer = $sTemp $sKey = "Username" $sTemp = IniRead($sAppName & ".ini", @ComputerName, $sKey, "") if $sTemp = "" Then $sTemp = IniRead($sAppName & ".ini", "Default", $sKey, "") $sMsg &= " " & $sKey & " = " & $sTemp & @crlf $sUsername = $sTemp $sKey = "Password" $sTemp = IniRead($sAppName & ".ini", @ComputerName, $sKey, "") if $sTemp = "" Then $sTemp = IniRead($sAppName & ".ini", "Default", $sKey, "") $sMsg &= " " & $sKey & " = " & $sTemp & @crlf $sPassword = $sTemp $sKey = "WAN" $sTemp = IniRead($sAppName & ".ini", @ComputerName, $sKey, "") if $sTemp = "" Then $sTemp = IniRead($sAppName & ".ini", "Default", $sKey, "") $sMsg &= " " & $sKey & " = " & $sTemp & @crlf $sWAN = $sTemp $sKey = "Verbose" $sTemp = IniRead($sAppName & ".ini", @ComputerName, $sKey, "") if $sTemp = "" Then $sTemp = IniRead($sAppName & ".ini", "Default", $sKey, "") $sMsg &= " " & $sKey & " = " & $sTemp & @crlf $bVerbose = $sTemp if msgbox(4,$sAppTitle, $sMsg, 10) <> 6 then $sFilename="" $iMinutes="" $sServer="" $sUsername="" $sPassword="" $sWAN="" $bVerbose="" EndIf EndIf EndIf ; ================================================================================================================ ; ARGUMENT CHECKS / PROMPTS (if an argument is not supplied, check last run setting to use as default and prompt user) If $sWAN = "" Then _DefineSetting("WAN") If $sServer = "" Then _DefineSetting("Server") If $sUsername = "" Then _DefineSetting("Username") If $sPassword = "" Then _DefineSetting("Password") If $sFilename = "" Then _DefineSetting("Filename") If $iMinutes = "" Then _DefineSetting("Minutes") If $bVerbose = "" Then _DefineSetting("Verbose") if $bVerbose = "n" or $bVerbose = "false" or $bVerbose = False Then $bVerbose = False Else $bVerbose = True EndIf ; ================================================================================================================ ; LAST RUN SETTINGS SAVE _SettingsSave() ; ================================================================================================================ ; HOTKEY DEFINITIONS (if any) _HotkeySet() ; ================================================================================================================ ; SYSTRAY MENU DEFINITIONS (if any) AutoItSetOption ("TrayMenuMode", 2) TrayCreateItem ("[ Wan2Web ]") $mCheckNow = TrayCreateItem ("...Check now") TrayItemSetState (-1, $TRAY_DEFAULT) TrayCreateItem ("") TrayCreateItem ("[ Settings ]") $mWan = TrayCreateItem ("...WAN") $mServer = TrayCreateItem ("...Server") $mUsername = TrayCreateItem ("...Username") $mPassword = TrayCreateItem ("...Password") $mFilename = TrayCreateItem ("...Filename") $mMinutes = TrayCreateItem ("...Minutes") $mVerbose = TrayCreateItem ("...Verbose") TrayCreateItem ("") TrayCreateItem ("[ Project ]") $mAbout = TrayCreateItem ("...About") $mUpdate = TrayCreateItem ("...Update") $mHomepage = TrayCreateItem ("...Homepage") $mNews = TrayCreateItem ("...News") $mSupport = TrayCreateItem ("...Support") $mDebug = TrayCreateItem ("...Debug") $mExit = TrayCreateItem ("...Exit") TraySetState () TraySetClick (16) ; ================================================================================================================ ; DEBUG WINDOW (notepad; if requested) if $bDebug then _DebugSetup() ; ================================================================================================================ ; MAIN PROGRAM _ConsoleWrite("> " & @year & @mon & @mday & @hour & @min & @sec & " :: Pulling prior logged IP address") $sStoredIP = RegRead($sAppSettings, "IP") If $sStoredIP = "" Then $sStoredIP = "Not set" $sCurrentIP = $sStoredIP TraySetToolTip("WAN IP = " & $sCurrentIP) _ConsoleWrite("> " & @year & @mon & @mday & @hour & @min & @sec & " :: Last logged WAN IP was '" & $sCurrentIP & "'") _CheckNow() $iStopwatch = TimerInit() While 1 _MenuMonitor() if timerdiff($iStopwatch) >= $iMinutes * 60000 then _CheckNow() $iStopwatch = TimerInit() EndIf WEnd ; ================================================================================================================ ; FUNCTIONS Func _AboutDialog() _ConsoleWrite("+ _AboutDialog()") $iResult = msgbox(4,"About", $sAppTitle & " ( build " & $sAppBuild & " )" & @CRLF & @CRLF & _ $sAppDesc & @CRLF & @CRLF & _ "Would you like to visit the " & $sAppName & " web site for more information about this utility?") If $iResult = 6 Then ShellExecute($sAppHome) _ConsoleWrite("- _AboutDialog()") EndFunc Func _CheckNow() _ConsoleWrite("+ _CheckNow()") _SettingsLoad() _ConsoleWrite(": Querying WAN IP from " & $sWAN) If $bVerbose then TrayTip($sAppTitle, "Requesting WAN IP info from:" & @CRLF & $sWAN, 5) ;;sleep(5000) EndIf $sCurrentIP = _InetGetSource($sWAN) _ConsoleWrite(": WAN IP page returned '" & $sCurrentIP & "'") if $sCurrentIP <> $sStoredIP then _ConsoleWrite(": Current IP does not match registry stored IP") if $bVerbose then TrayTip($sAppTitle, "WAN IP change detected" & @CRLF & "Old IP: " & $sStoredIP & @CRLF & "New IP:" & $sCurrentIP, 5) ;;sleep(5000) EndIf RegWrite($sAppSettings, "IP", "REG_SZ", $sCurrentIP) $sStoredIP = $sCurrentIP Elseif $sCurrentIP = $sStoredIP Then _ConsoleWrite(": WAN IP address matches stored registry stored value") if $bVerbose then TrayTip($sAppTitle, "IP unchanged since last check" & @CRLF & "WAN IP = " & $sCurrentIP, 5) ;;sleep(5000) EndIf EndIf if $sCurrentIP = "" Then _ConsoleWrite(": Unable to retrieve WAN IP address from '" & $sWAN & "'") $sCurrentIP = "Unavailable" $sMsg = "Unable to retrieve WAN IP address from '" & $sWAN & "'" ;;Elseif $sCurrentIP = $sStoredIP Then ;; $sMsg = "Current IP = Stored IP" Else $sMsg = $sCurrentIP & " @ " & @year & "/" & @mon & "/" & @mday & " " & @hour & ":" & @min & ":" & @sec If $bVerbose then TrayTip($sAppTitle, "Posting update to " & $sServer, 5) _ConsoleWrite(": writing local '" & @tempdir & "\wanip.txt'") FileDelete(@tempdir & "\wanip.txt") Filewrite(@tempdir & "\wanip.txt", $sMsg) _ConsoleWrite(": writing local '" & @tempdir & "\wanip.html'") FileDelete(@tempdir & "\wanip.html") Filewrite(@tempdir & "\wanip.html", '') $Open = _FTP_Open('MyFTP Control') _ConsoleWrite(": Openning FTP connection to " & $sServer & " = " & $Open) _ConsoleWrite(": Passing creds: " & $sServer & " + " & $sUsername & " + " & $sPassword & " + PASSIVE") $Conn = _FTP_Connect($Open, $sServer, $sUsername, $sPassword, 1) _ConsoleWrite(": Passing login credentials = " & $conn) if $conn = 0 then traytip($sapptitle, "Failed to LOG IN to '" & $sServer & "'" & @CRLF & "Invalid creds or no FTP support", 5) ;;sleep(5000) Else _ConsoleWrite(": Posting update to " & $sServer & "/" & $sFilename & "(.txt/.html") $Ftpp = _FTP_FilePut($Conn, @tempdir & "\wanip.txt", $sFilename & ".txt") $Ftpp = _FTP_FilePut($Conn, @tempdir & "\wanip.html", $sFilename & ".html") $Ftpc = _FTP_Close($Open) _ConsoleWrite(": Closing FTP connection = " & $Ftpc) if $ftpp = 0 Then traytip($sapptitle, "Failed to POST to '" & $sServer & "'" & @CRLF & "Invalid location or unknown issue", 5) ;;sleep(5000) EndIf _ConsoleWrite(": Removing local temp files") FileDelete(@tempdir & "\wanip.txt") FileDelete(@tempdir & "\wanip.html") EndIf If $bVerbose and $ftpp > 0 then TrayTip($sAppTitle, "Updated WAN IP info transfered to:" & @CRLF & $sServer & "/" & $sFilename & ".txt"& @CRLF & $sServer & "/" & $sFilename & ".html", 5) ;;sleep(5000) EndIf endif TraySetToolTip($sMsg) ;;traytip("","",0) _ConsoleWrite("- _CheckNow()") EndFunc func _ConsoleWrite($sMsg) _DebugOut($sMsg) Consolewrite($sMsg & @CRLF) EndFunc Func _DefineSetting($sSetting="", $sValue="") _consolewrite("+ _DefineSetting()") _ConsoleWrite(": Setting '" & $sSetting & "' = '" & $sValue & "'") if $sSetting = "" or $sSetting = "Debug" Then if $sValue then $bDebug = $sValue Else if not $bDebug then $bDebug = True Else $bDebug = False EndIf endif if $bDebug Then _DebugSetup($sAppTitle & " - debugging info") _ConsoleWrite("Debug console :: " & $sAppTitle & " :: build " & $sAppBuild) _ConsoleWrite("========================[ START ]=============================") opt("TrayIconDebug",1) TrayItemSetState($mDebug,1) Else _ConsoleWrite("=========================[ END ]==============================") opt("TrayIconDebug",0) TraySetToolTip($sAppTitle) TrayItemSetState($mDebug,4) EndIf EndIf if $sSetting = "" or $sSetting = "WAN" Then $sResult = RegRead($sAppSettings, "WAN") if $sResult = "" then $sResult= "http://www.shrum.net/remote_addr.php" $sWAN = InputBox($sAppTitle,"[W]AN IP reporting page URL. This is the page that returns your WAN IP address in a plain text format such as 'http://www.shrum.net/sean/remote_addr.php'", $sResult) if @error then Return if $sWan = "" then _Exit() EndIf if $sSetting = "" or $sSetting = "Minutes" Then $sResult = RegRead($sAppSettings, "Minutes") if $sResult = "" then $sResult= "30" $iMinutes = InputBox($sAppTitle,"[M]intues to wait between IP change checks (setting this value to something low may get you blacklisted; try a number > 60 unless your IP is changing more often):", $sResult) if @error then Return if $iMinutes = "" then _Exit() EndIf if $sSetting = "" or $sSetting = "Server" Then $sResult = RegRead($sAppSettings, "Server") $sServer = InputBox($sAppTitle,"[S]erver name to post updated WAN IP file to. This is a website that you have simple FTP access to:", $sResult) if @error then Return if $sServer = "" then _Exit() EndIf if $sSetting = "" or $sSetting = "Username" Then $sUsername = InputBox($sAppTitle,"[U]sername to log into " & $sServer & " with:", "") if @error then Return if $sUsername = "" then _Exit() EndIf if $sSetting = "" or $sSetting = "Password" Then $sPassword = InputBox($sAppTitle,"[P]assword to log into " & $sServer & " with (this setting is not saved for security reasons and will need to be input each time the application starts):", "", "*") if @error then Return if $sPassword = "" then _exit() EndIf if $sSetting = "" or $sSetting = "Filename" Then $sResult = RegRead($sAppSettings, "Filename") $sFilename = InputBox($sAppTitle,"[F]ilename (no extension) to save the updated IP file to on " & $sServer & " (include subdirectories based on the inital root directory your FTP server returns). Wan2Web will post a .txt & a redirect .html file:", $sResult) if @error then Return if $sFilename = "" then _Exit() EndIf if $sSetting = "" or $sSetting = "Verbose" Then $iOffset = 0 $sResult = RegRead($sAppSettings, "Verbose") If $sResult = "False" then $iOffset = 256 $iResult = msgbox(4+32+$iOffset,$sAppTitle,"Enable [V]erbose notifications (bubbletips)?") if @error then Return if $iResult = 6 then $bVerbose = "y" else $bVerbose = "n" EndIf if $bVerbose = "y" or $bVerbose = "true" then $bVerbose = True Else $bVerbose = False EndIf EndIf _SettingsSave() _ConsoleWrite("- _DefineSetting()") EndFunc Func _Exit() _ConsoleWrite("+ _Exit()") ;~ ****** _ConsoleWrite("- _Exit()") Exit EndFunc func _HotkeySet() _ConsoleWrite("+ _HotkeySet()") ;~ ****** _ConsoleWrite("- _HotkeySet()") EndFunc func _MenuMonitor() $msg = TrayGetMsg () Select Case $msg = $TRAY_EVENT_PRIMARYDOWN _CheckNow() Case $msg = $mWAN _DefineSetting("WAN") Case $msg = $mServer _DefineSetting("Server") Case $msg = $mUsername _DefineSetting("Username") Case $msg = $mPassword _DefineSetting("Password") Case $msg = $mFilename _DefineSetting("Filename") Case $msg = $mMinutes _DefineSetting("Minutes") Case $msg = $mVerbose _DefineSetting("Verbose") Case $msg = $mCheckNow _CheckNow() Case $msg = $mAbout _AboutDialog() Case $msg = $mDebug _DefineSetting("Debug", Not $bDebug) case $msg = $mUpdate _UpdateCheck() case $msg = $mHomepage _ShellExecute($sAppHome) case $msg = $mSupport _ShellExecute($sAppSupport) case $msg = $mNews _ShellExecute($sAppNews) case $msg = $mExit _Exit() EndSelect EndFunc Func _SettingsLoad() _ConsoleWrite("+ _SettingsLoad()") $sFilename = Regread($sAppSettings, "Filename") $iMinutes = Regread($sAppSettings, "Minutes") $sServer = Regread($sAppSettings, "Server") $sUsername = Regread($sAppSettings, "Username") $sWAN = Regread($sAppSettings, "WAN") $sPassword = Regread($sAppSettings, "Password") $bVerbose = Regread($sAppSettings, "Verbose") _ConsoleWrite("- _SettingsLoad()") EndFunc Func _SettingsSave() _ConsoleWrite("+ _SettingsSave()") RegWrite($sAppSettings, "Filename", "REG_SZ", $sFilename) RegWrite($sAppSettings, "Minutes", "REG_SZ", $iMinutes) RegWrite($sAppSettings, "Server", "REG_SZ", $sServer) RegWrite($sAppSettings, "Username", "REG_SZ", $sUsername) RegWrite($sAppSettings, "WAN", "REG_SZ", $sWAN) RegWrite($sAppSettings, "Verbose", "REG_SZ", $bVerbose) _ConsoleWrite("- _SettingsSave()") EndFunc Func _ShellExecute($sCmd) _ConsoleWrite("+ _ShellExecute()") _ConsoleWrite(": Running '" & $sCmd & "'") shellExecute($sCmd) _ConsoleWrite("- _ShellExecute()") endfunc Func _ShellExecuteWait($sCmd) _ConsoleWrite("+ _ShellExecuteWait()") if $sCmd = "" Then _ConsoleWrite(": No command passed") Else _ConsoleWrite(": Running '" & $sCmd & "'") ShellExecuteWait($sCmd) EndIf _ConsoleWrite("- _ShellExecuteWait()") endfunc func _UpdateCheck() _ConsoleWrite("+ _UpdateCheck()") traytip($sAppTitle, "Pulling online version info...",10) $sTemp = "" $aTemp = stringsplit(_InetGetSource($sAppHome & "/" & stringlower($sAppName) & ".au3"), @CRLF) For $i = 1 to $aTemp[0] if StringInStr($aTemp[$i], "$sAppVersion") then $sTemp = $aTemp[$i] ExitLoop endif Next if $sTemp <> "" then $aOnlineVersion = StringSplit($sTemp, "=") $sOnlineVersion = StringReplace(StringStripWS($aOnlineVersion[2], 8), '"', "") _ConsoleWrite(": Online = " & $sOnlineVersion) _ConsoleWrite(": User = " & $sAppVersion) if $sOnlineVersion <> "" and Not Stringinstr($sOnlineVersion, "") Then If $sAppVersion < $sOnlineVersion Then _ConsoleWrite(": User is OLDER") $sMsg = "A newer version of this program is available for download." & @CRLF & @CRLF $sMsg &= "Do you want to visit the " & $sAppname & " site to download v." & $sOnlineVersion & "?" & @CRLF & @CRLF $sMsg &= "Selecting 'Yes' will close this app and take you to the website." If MsgBox(4, $sAppTitle, $sMsg) = 6 Then _ConsoleWrite(": Launching default web browser to " & $sAppHome) _ShellExecute($sAppHome) Exit EndIf ElseIf $sAppVersion >= $sOnlineVersion Then _ConsoleWrite(": User is UP-TO-DATE") TrayTip($sAppTitle, "Your version is up-to-date.",5) EndIf Else _ConsoleWrite(": Data received but no version info found") traytip($sAppTitle,"Unable to locate versioning info in data received." & @CRLF & "Please go to the homepage for further update details.",5) EndIf Else _ConsoleWrite(": Unable to obtain version content") traytip($sAppTitle,"Unable to obtain online version info." & @CRLF & "Check your connection and try again.",5) EndIf _ConsoleWrite("- _UpdateCheck()") EndFunc