commit e86e3f6c9865760dc752502f16e7e7187e00aaee Author: Dmitro Date: Tue Jan 24 00:25:24 2023 +0200 create diff --git a/README.md b/README.md new file mode 100644 index 0000000..214a462 --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +#WireGuard2MikroTik + +## Introduction + +Конверторы конвигурации WireGuard в файл формата src, +для быстрого розвёртывания клиэнта на оборудовании MikroTik + + Написано на Autoit3 + +![WireGuard2MikroTik](others_files/gif.gif) \ No newline at end of file diff --git a/Wg.au3 b/Wg.au3 new file mode 100644 index 0000000..a79393c --- /dev/null +++ b/Wg.au3 @@ -0,0 +1,88 @@ +#NoTrayIcon +#Region ;**** Directives created by AutoIt3Wrapper_GUI **** +#AutoIt3Wrapper_Version=Beta +#AutoIt3Wrapper_Icon=icon.ico +#AutoIt3Wrapper_Res_Fileversion=0.0.0.1 +#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p +#AutoIt3Wrapper_Res_ProductName=WG2MT +#AutoIt3Wrapper_Res_ProductVersion=0.0.0.1 +#AutoIt3Wrapper_Res_Language=1058 +#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** +#pragma compile(Out, WG2MT.exe) +##pragma compile(Icon, image/Setting_ico.ico) +;~ #pragma compile(UPX, True) ; Commented out by AutoIt3Wrapper to be able to do the requested resource updates +#pragma compile(FileDescription, 'dima101097') +#pragma compile(Fileversion, 0.0.0.7) +FileChangeDir(@ScriptDir) +#include +#include +global $iFolder +GUICreate( "WireGuard2MikroTik", 400, 100 ) + GUICtrlCreateLabel ("Wireguard config:", 10, 30) + Global $iFolders = GUICtrlCreateInput ($iFolder, 100, 25, 200) + $folderChoose = GUICtrlCreateButton("Вибрати", 310, 23, 50, 25) + $next= GUICtrlCreateButton("Далі", 10, 60, 50, 25) +GUISetState(@SW_SHOW) + +Do + $gMsg = GUIGetMsg() + Switch $gMsg + Case $folderChoose + GUICtrlSetData($iFolders, FileOpenDialog("Вкажіть файл конфігурації WireGuard", @WorkingDir & "\", "Конфігурація WireGuard (*.conf)", 1)) + Case $next + _next(GUICtrlRead($iFolders)) + Case $GUI_EVENT_CLOSE + ExitLoop + + EndSwitch +Until $gMsg = $GUI_EVENT_CLOSE + + + +Func _next ($iFolders) + $save_file = FileSaveDialog("Папка збереження.", @ScriptDir, " MikroTik (*.rsc)", 2) +If @error Then + MsgBox(4096, "", "Збереження відмінено.") +Else + _toScript ($save_file,$iFolders) +EndIf +EndFunc + + +Func _toScript ($save_file, $iFolders) + $localAdres = _regexp(IniRead ($iFolders,"Interface", "Address", ""),'[0-9]{0,3}\.[0-9]{0,3}\.[0-9]{0,3}\.[0-9]{0,3}') + $PrivatKey = IniRead ($iFolders,"Interface", "PrivateKey", "") + $ListenPort = IniRead ($iFolders,"Interface", "ListenPort", "") + $DNS = IniRead ($iFolders,"Interface", "DNS", "") + + $PublicKey = IniRead ($iFolders,"Peer", "PublicKey", "") + $PresharedKey = IniRead ($iFolders,"Peer", "PresharedKey", "") + $Endpoint = IniRead ($iFolders,"Peer", "Endpoint", "") + $EndpointIP=_regexp($Endpoint,'(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]') + $EndpointPort= _regexp($Endpoint,'\d{1,5}$') + $AllowedIPs = IniRead ($iFolders,"Peer", "AllowedIPs", "") + + ;$wgName = _regexp($save_file,'[A-Za-z0-9\.]{0,100}\.rsc$') + $wgName = _regexp($save_file,'([^.\\]+)\.') + if $EndpointPort = "" Then $EndpointPort = $ListenPort + if $ListenPort = "" Then $ListenPort = $EndpointPort + + ;MsgBox(0,"", "Local IP: " & $localAdres & @CR & "Listen PORT: " & $ListenPort & @CR & "DNS: " & $DNS & @CR & "Private KEY: " & $PrivatKey & @CR & @CR & "Host IP/Domen: " & $EndpointIP & @CR & "Host PORT: " & $EndpointPort & @CR & "Allowed IPs: " & $AllowedIPs & @CR & "Public KEY: " & $PublicKey & @CR & "Preshared KEY: " & $PresharedKey,5) + + + $hFile = FileOpen($save_file, 2) + $sCode ='/interface wireguard add listen-port=' & $ListenPort & ' name="'& $wgName&'"' & ' private-key="' & $PrivatKey & '"' & @CRLF & _ + '/interface wireguard peers add allowed-address=' & $AllowedIPs & ' endpoint-address=' & $EndpointIP & ' endpoint-port=' & $EndpointPort & ' interface='& $wgName & ' preshared-key="'& $PresharedKey &'" public-key="' & $PublicKey & '"' & @CRLF & _ + '/ip address add address=' & $localAdres & '/24 interface="'& $wgName &'"' + FileWrite($hFile, $sCode) + FileClose($hFile) + MsgBox (0,"","Завершено.",5) + + +EndFunc + +Func _regexp (ByRef Const $text, ByRef Const $regexpPatern ) + local $res = StringRegExp ( $text,$regexpPatern ,$STR_REGEXPARRAYMATCH) + If Not @error Then Return $res[0] + Return SetError(1, 0, Null) +EndFunc \ No newline at end of file diff --git a/others_files/gif.gif b/others_files/gif.gif new file mode 100644 index 0000000..fc3ee13 Binary files /dev/null and b/others_files/gif.gif differ diff --git a/others_files/icon.ico b/others_files/icon.ico new file mode 100644 index 0000000..010269f Binary files /dev/null and b/others_files/icon.ico differ diff --git a/others_files/icon.png b/others_files/icon.png new file mode 100644 index 0000000..6d3f5c3 Binary files /dev/null and b/others_files/icon.png differ