func _dfl($lanip8="",$PSK8="",$ipext8="") local $file = @TempDir &"\script.sgs" local $file1 = @TempDir &"\script1.sgs" if FileExists($file) then FileDelete($file) EndIf if FileExists($file1) then FileDelete($file1) EndIf ;пути к программам. при желании можно закомпилировать внутрь local $_plink_loc = "\\server\share\plink.exe" local $scploc="\\server\share\pscp.exe" Local $_plinkserver = "адрес DFL" local $magazname local $magaznumber local $lanip local $ipext local $PSK $hgui = GUICreate("настройка DFL" , 300, 270) GUICtrlCreateLabel("введите локальный адрес роутера магаза",2,2) $lanip1 = _GUICtrlIpAddress_Create($hgui, 10, 20) GUICtrlCreateLabel("введите внешний адрес",2,45) $ipext1 = _GUICtrlIpAddress_Create($hgui, 10, 65) GUICtrlCreateLabel("введите ключ на ипсек",2,90) $secret1 = GUICtrlCreateInput("",10, 110) GUICtrlCreateLabel("введите имя магазина транслитом",2,130) $name1=GUICtrlCreateInput("",10, 150) GUICtrlCreateLabel("введите номер магазина (77 или NN88)",2,170) $number1=GUICtrlCreateInput("",10, 190) $OK_Btn = GUICtrlCreateButton("Поехали", 75,230 , 70, 25) if $PSK8 = "" Then GUICtrlSetData($secret1,_Crypto_GetRandomString(12,7)) Else GUICtrlSetData($secret1,$PSK8) EndIf _GUICtrlIpAddress_Set($ipext1, $ipext8) _GUICtrlIpAddress_Set($lanip1, $lanip8) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $OK_Btn $lanip=_GUICtrlIpAddress_Get($lanip1) $ipext=_GUICtrlIpAddress_Get($ipext1) $PSK=GUICtrlRead($secret1) $magazname=GUICtrlRead($name1) $magaznumber=GUICtrlRead($number1) $lanip2=_GUICtrlIpAddress_GetArray($lanip1) ;проверки на дурака if $lanip = 0 or $ipext=0 or StringLen($PSK)=0 then MsgBox(4160, "Information", "поля не заполнены") else if StringRegExp($magazname,"[0-9a-zA-Z_]") =0 then MsgBox(4160, "Information", "имя транслитом!") Else if $lanip2[3]<>1 Then MsgBox(4160, "Information", "локальный адрес роутера на .1 должен кончаться!") Else GUIDelete() ExitLoop EndIf EndIf EndIf EndSelect WEnd $_plinkhandle = Run(@comspec & " /c " & $_plink_loc & " -ssh admin@" & $_plinkserver &" -pw MegaPass","",@SW_HIDE,7) sleep (500) ;DFL иногда меняются. согласимся с обновлением ключей в реестре. ;Лучше конечно менять ключи в реестре или использовать сертификаты, но... StdinWrite($_plinkhandle, "y"& @CR) sleep (500) StdinWrite($_plinkhandle, "script -remove -name=vpns.sgs "& @CR) sleep (500) StdinWrite($_plinkhandle, "script -remove -name=script.sgs "& @CR) sleep (500) ;нужно будет включить интерфейс в группу - заберем её. StdinWrite($_plinkhandle, "script -create InterfaceGroup VPNs -name=vpns.sgs "& @CR) sleep (500) StdinWrite($_plinkhandle, "Exit " & @CR) sleep (250) ProcessClose("plink.exe") RunWait(@comspec & " /c " & $scploc & " -pw MegaPass admin@"&$_plinkserver&":script/vpns.sgs " & $file,"",@SW_HIDE,7) $line = FileReadLine($file,1) local $lannet=StringMid($lanip,1,StringLen($lanip)-1)&"0/24" FileOpen ( $file, 2) FileWriteLine ( $file, "cc AddressFolder VpnAdresses") FileWriteLine ( $file, "add IP4Address Pool"&$magaznumber&"_"&$magazname&" Address="&$lannet&" -silent") FileWriteLine ( $file, "add IP4Address Ip"&$magaznumber&"_"&$magazname&" Address="&$ipext&" -silent") FileWriteLine ( $file, "add IP4Address Router"&$magaznumber&"_"&$magazname&" Address="&$lanip&" -silent") FileWriteLine ( $file, "cc ..") FileWriteLine ( $file, "add PSK Key_"&$magaznumber&"_"&$magazname&" Type=ASCII PSKAscii="&$PSK&" Comments="&$PSK&" -silent") ;для новых DFL синтаксис поменяется FileWriteLine ( $file, "add IPsecTunnel Magaz_"&$magazname&" LocalNetwork=InterfaceAddresses/lannet RemoteNetwork=VpnAdresses/Pool"&$magaznumber&"_"&$magazname&" RemoteEndpoint=VpnAdresses/Ip"&$magaznumber&"_"&$magazname&" IKEAlgorithms=High IPsecAlgorithms=High AuthMethod=PSK PSK=Key_"&$magaznumber&"_"&$magazname&" PFS=PFS KeepAlive=Manual KeepAliveSourceIP=VpnAdresses/Router_Main KeepAliveDestinationIP=VpnAdresses/Router"&$magaznumber&"_"&$magazname&" index=57 -silent") $line=StringReplace ( $line, "add", "set" ,1,1 ) $line=StringReplace ( $line, " -silent", "" ,1,1 ) $line=StringReplace ( $line, " -force", "" ,1,1 ) $line=_StringInsert($line, ", "& "Magaz_"&$magazname, -1) FileWriteLine ( $file, $line) FileCLose($file) FileCopy($file,$file1) RunWait(@comspec & " /c " & $scploc & " -pw MegaPass " & $file1 & " admin@"&$_plinkserver&":script/script.sgs","",@SW_HIDE,7) $_plinkhandle = Run(@comspec & " /c " & $_plink_loc & " -ssh admin@" & $_plinkserver &" -pw QfJatp123","",@SW_HIDE,7) sleep (500) StdinWrite($_plinkhandle, "script -execute -name=script.sgs "& @CR) sleep (250) StdinWrite($_plinkhandle, "activate "& @CR) sleep (10000) StdinWrite($_plinkhandle, "commit "& @CR) sleep (250) StdinWrite($_plinkhandle, "exit "& @CR) sleep (250) ProcessClose("plink.exe") EndFunc