As a consultant I use the dude a lot. I connect to a myriad of dude servers on a regular basis, which can be somewhat cumbersome. Why is this cumbersome…because you don’t have the ability to save multiple sets of connection information in the dude. Sooooo, I wrote a little menu system so you can enter as many dude systems as you want, each with their own sets of credentials and IP information. All you have to do is choose the server from the list you want to connect to and click launch 🙂
Binary is here:
Here’s the code for all of my basement dwelling friends:
#include <Array.au3>
#include <file.au3>
;check for config file's existance
if not FileExists(@ScriptDir & "\config.txt") then
;file isn't here, generate it
$fConfig = FileOpen(@ScriptDir & "\config.txt", 1)
; Check if file opened for writing OK
If $fConfig = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf
FileWriteLine($fConfig, "C:\Program Files\Dude\dude.exe" & @CRLF)
FileWriteLine($fConfig, "delete me,username,password,Secure,1.1.1.1,2211")
FileClose($fConfig)
EndIf
Dim $aConfig
If Not _FileReadToArray(@ScriptDir & "\config.txt",$aConfig) Then
MsgBox(4096,"Error", " Error reading log to Array error:" & @error)
Exit
EndIf
;#############################
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=C:\Documents and Settings\greg\Desktop\autoit\dude menu\dudemenu.kxf
$Form1_1 = GUICreate("Dude Menu - GregSowell.com MikrotikUniversity.com", 325, 448, 192, 114)
$InDesc = GUICtrlCreateInput("", 72, 232, 225, 21)
$InUser = GUICtrlCreateInput("", 72, 277, 225, 21)
$InPassword = GUICtrlCreateInput("", 72, 301, 225, 21)
$Combo1 = GUICtrlCreateCombo("Secure", 72, 328, 225, 25)
GUICtrlSetData(-1, "Remote")
$InIP = GUICtrlCreateInput("", 72, 358, 225, 21)
$InPort = GUICtrlCreateInput("", 72, 389, 225, 21)
$List1 = GUICtrlCreateList("", 16, 8, 289, 201)
$Label1 = GUICtrlCreateLabel("Description", 8, 232, 57, 17)
$Label2 = GUICtrlCreateLabel("Username", 8, 271, 52, 17)
$Label3 = GUICtrlCreateLabel("Password", 8, 298, 50, 17)
$Label4 = GUICtrlCreateLabel("Type", 8, 327, 28, 17)
$Label5 = GUICtrlCreateLabel("IP Address", 8, 359, 55, 17)
$Label6 = GUICtrlCreateLabel("Port", 8, 388, 23, 17)
$BtnLaunch = GUICtrlCreateButton("Launch", 48, 416, 65, 25, $WS_GROUP)
$BtnAdd = GUICtrlCreateButton("Add/Edit", 130, 416, 65, 25, $WS_GROUP)
$BtnDelete = GUICtrlCreateButton("Delete", 211, 416, 65, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;fill in the listbox
_LoadConfig()
$ListLocation = 1
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
case $GUI_EVENT_PRIMARYUP
;mouse was pressed, lets check to see if they choose a new item in list
;check which list item is highlighted
$tempList = GUICtrlRead($List1)
;see if this is new item chosen or just a click somewhere on the prog
if $tempList <> $ListLocation and $tempList <> "" Then
;change, update everything
;set list location to the temp value
$ListLocation = $tempList
;set all our gui values
GUICtrlSetData($InDesc,stringleft($ListLocation,StringInStr($ListLocation,",") - 1))
GUICtrlSetData($InUser, StringMid($ListLocation, StringInStr($ListLocation,",") + 1, StringInStr($ListLocation,",", 0, 2) - StringInStr($ListLocation,",") - 1))
GUICtrlSetData($InPassword, StringMid($ListLocation, StringInStr($ListLocation,",", 0, 2) + 1, StringInStr($ListLocation,",", 0, 3) - StringInStr($ListLocation,",", 0, 2) - 1))
GUICtrlSetData($Combo1, StringMid($ListLocation, StringInStr($ListLocation,",", 0, 3) + 1, StringInStr($ListLocation,",", 0, 4) - StringInStr($ListLocation,",", 0, 3) - 1))
GUICtrlSetData($InIP, StringMid($ListLocation, StringInStr($ListLocation,",", 0, 4) + 1, StringInStr($ListLocation,",", 0, 5) - StringInStr($ListLocation,",", 0, 4) - 1))
GUICtrlSetData($InPort, StringMid($ListLocation, StringInStr($ListLocation,",", 0, 5) + 1))
EndIf
Case $BtnAdd
;update existing or commit the new one
;lets rock it
$new = 1
;where in the loop are we
$updateNum = 0
;check to see if it exists
for $y = 2 to $aConfig[0]
;check if the IP exists
if StringInStr($aConfig[$y], GUICtrlRead($InIP)) > 0 Then
;we have a match
$new = 0
$updateNum = $y
EndIf
Next
;ready to rock, save it
if $new = 1 Then
;new one
;add to end of the array
_ArrayAdd($aConfig, GUICtrlRead($InDesc) & "," & GUICtrlRead($InUser) & "," & GUICtrlRead($InPassword) & "," & GUICtrlRead($Combo1) & "," & GUICtrlRead($InIP) & "," & GUICtrlRead($InPort))
;sort our array
_ArraySort($aConfig,0,2)
;write the file
_FileWriteFromArray(@ScriptDir & "\config.txt",$aConfig,1)
;run plink to accept cert
;Run(@ComSpec & " /c " & FileGetShortName(@ScriptDir) & '\plink.exe -ssh ' & GUICtrlRead($IPAddress1))
;load the list again
_LoadConfig()
Else
;update
;set existing value
$aConfig[$updateNum] = GUICtrlRead($InDesc) & "," & GUICtrlRead($InUser) & "," & GUICtrlRead($InPassword) & "," & GUICtrlRead($Combo1) & "," & GUICtrlRead($InIP) & "," & GUICtrlRead($InPort)
;sort array
_ArraySort($aConfig,0,2)
;write the array to file
_FileWriteFromArray(@ScriptDir & "\config.txt",$aConfig,1)
;reload list
_LoadConfig()
EndIf
Case $BtnDelete
;delete an existing entry
$sure = MsgBox(4, "Delete Record?", "Are you sure you want to delete " & GUICtrlRead($InDesc) & "?")
if $sure == 6 Then
;delete it
$updateNum = 0
;find the array #
for $y = 1 to $aConfig[0]
;check if the IP exists
if StringInStr($aConfig[$y], GUICtrlRead($InIP)) > 0 Then
;we have a match
$updateNum = $y
EndIf
Next
;delete the entry
_ArrayDelete($aConfig,$updateNum)
;write it to file
_FileWriteFromArray(@ScriptDir & "\config.txt",$aConfig,1)
;reload list
_LoadConfig()
EndIf
Case $BtnLaunch
;launch it
run($aConfig[1])
;wait for the dude to start
$pie = 1
;loop while waiting for dude to start
while 1 == $pie
If ProcessExists("dude.exe") Then
$pie = 2
EndIf
sleep(1000)
WEnd
;activate the connect screen
$pie = 1
;loop while waiting for dude to start
while 1 == $pie
WinActivate("Connect")
if winactive("Connect") Then
$pie = 2
EndIf
sleep(200)
WEnd
;fill in the blanks and hit enter
Send("{TAB}")
Sleep(200)
Send("{TAB}")
Sleep(200)
if guictrlread($Combo1) == "Secure" Then
Send("s")
Else
Send("r")
EndIf
Sleep(200)
Send("{TAB}")
Sleep(200)
Send(guictrlread($InUser))
Sleep(200)
Send("{TAB}")
Sleep(200)
Send(guictrlread($InPassword))
Sleep(200)
Send("{TAB}")
Sleep(200)
Send("{TAB}")
Sleep(200)
Send("{TAB}")
Sleep(200)
Send(guictrlread($InIP))
Sleep(200)
Send("{TAB}")
Sleep(200)
Send(guictrlread($InPort))
Sleep(200)
Send("{TAB}")
Sleep(200)
Send("{ENTER}")
;Exit
GUISetState(@SW_MINIMIZE)
EndSwitch
WEnd
Func _LoadConfig()
gUICtrlSetData($List1, "")
Dim $aConfig
If Not _FileReadToArray(@ScriptDir & "\config.txt",$aConfig) Then
MsgBox(4096,"Error", " Error reading log to Array error:" & @error)
Exit
EndIf
For $x = 2 to $aConfig[0]
guictrlsetdata($List1,$aConfig[$x])
Next
EndFunc
Leave a Reply