Func _ChangeSSH($filessh,$sshprofile) ;$sshprofile="candylop1.bscp"
Local $timeout=30
If Not FileExists($filessh) then
Msgbox(4096,$programtitle,"File dữ liệu ssh không tồn tại, vui lòng kiểm tra lại!")
GUICtrlSetState($Issh,$GUI_FOCUS)
Return SetError(-1,0,"Error")
EndIf
Local $fSshOpen=FileOpen($filessh,1)
Local $line=FileReadLine($filessh,1)
If @error=-1 then
Msgbox(4096,$programtitle,"Đã hết SSH trong list rồi, vui lòng mua thêm đi đồ keo kiệt.")
FileClose($fSshOpen)
Return SetError(-1,0,"Error")
Endif
Local $aIP=_SpitUserPass($line)
If Not IsArray($aIP) then
_FileWriteToLine($filessh,1,"",1)
FileClose($fSshOpen)
Return ""
Endif
Opt("WinTitleMatchMode",2)
$ParamSSH=" -profile="&$sshprofile&" -host="&$aIP[0] & " -user="&$aIP[1] & " -password="&$aIP[2] &" -hostKeyFile=candykey -loginOnStartup" ;" -profile="&$profile&
$Dirssh=@ProgramFilesDir&"\Bitvise SSH Client"
$spid_profile=_getpid("BvSsh.exe",$sshprofile)
If $spid_profile <> 0 Then
_SSHLoginLogout($spid_profile,"logout")
Sleep(2000)
_SSHLoginLogout($spid_profile,"exit")
Endif
Run(@COMSPEC & " /c "&"BvSsh" & $ParamSSH,$Dirssh,@SW_HIDE,0x2)
$code=WinWait($BITVISE_TITLE,"",$timeout)
$acceptkey=WinWaitActive("Host Key Verification","",$timeout)
if $acceptkey >0 then
ControlClick($acceptkey,"","[CLASS:Button; INSTANCE:2]","left")
sleep(5000)
Else
$sPid=WinGetProcess($code)
_SSHLoginLogout($sPid,"exit")
Msgbox(64,$programtitle,"Thời gian kết nối lâu quá "&$timeout&" giây",1)
_FileWriteToLine($filessh,1,"",1)
FileClose($fSshOpen)
Sleep(2000)
Return SetError(-1,0,"")
Endif
_FileWriteToLine($filessh,1,"",1)
FileClose($fSshOpen)
Local $thanhcong=_sockstatus(1080+1)
Local $wait=0
While $thanhcong <1 And $wait <7
sleep(5000)
$thanhcong=_sockstatus(1080+1)
$wait+=1
WEnd
If $wait >6 then return SetError(-1,0,"")
Return $aIP[0]
Endfunc ;---->_ChangeSSH
Func _SpitUserPass($string)
Local $st
$st=StringReplace($string," "," ",0,0)
$st=StringReplace($st," | ","|",0,0)
$pos1=StringInstr($st,"|",0,1)
$pos2 = StringInStr($st, "|", 0, 2)
$pos3= StringInStr($st,"|",0,3)
Local $aup=StringMid($st,1,$pos1-1)
Local $u=StringMid($st,$pos1+1,$pos2-$pos1-1)
Local $p=StringMid($st,$pos2+1,$pos3-$pos2-1)
Local $result[3]=[$aup,$u,$p]
If StringInStr($aup,".",0,3) < 1 then Return SetError(-1,0,"")
Return $result
EndFunc ;-----> _SpitUserPass