Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Constants.au3>
- #RequireAdmin
- ;
- ; AutoIt Version: 3.0
- ; Language: English
- ; Author: Srecko Menjic (smenjic at synchrotek dot com)
- If $CmdLine[0] < 1 Then
- MsgBox($MB_SYSTEMMODAL, "Error", "Please add Installation folder as command line parameter")
- Exit
- EndIf
- Local $InstallDir = $CmdLine[1]
- If not IsAdmin() Then
- MsgBox($MB_SYSTEMMODAL, "Error", "Please run as Admministrator")
- Exit
- EndIf
- MsgBox($MB_SYSTEMMODAL, "Install info", "You'll be asked to input your VPN certificate. Certificate is password protected, because it contains private key, so you'll need to input it's password after you chose it.")
- Local $certfile = FileOpenDialog("Please input VPN private certificate file", @DesktopDir & "\", "Certificate (*.p12;*.pfx)")
- if @error = 0 Then
- Local $certpassword = InputBox("Enter password", "Type your certificate password here," & @CRLF & "and click OK.", "", "*")
- Local $iReturn = RunWait(@ComSpec & " /c certutil -p " & $certpassword & ' -importPFX "' & $certfile & '"', "", @SW_HIDE)
- If $iReturn <> 0 Then
- MsgBox($MB_SYSTEMMODAL, "Error", "Bad certificate/password!" & @CRLF & "Not installing VPN Clinet!")
- Else
- Local $iStatus = 0
- If RunWait(@ComSpec & ' /c certutil -addstore root "' & @ScriptDir & '\Certificates\SynchrotekCA.cer"', "", @SW_HIDE) = 0 Then
- $iStatus += 1
- EndIf
- Local $sRegKey = 'HKLM\SYSTEM\CurrentControlSet\Services\PolicyAgent'
- If RegWrite($sRegKey, "AssumeUDPEncapsulationContextOnSendRule", "REG_DWORD", 2) Then
- $iStatus += 2
- EndIf
- ; Run(@ComSpec & " /c " & 'regedit /s "' & @ScriptDir & '\SyncVPN\IPSEC-NAT-T.reg"', "", @SW_HIDE)
- Local $iUseGW = MsgBox(BitOR($MB_YESNO, $MB_SYSTEMMODAL), "Synchrotek VPN", "Do you want to use Synchrotek's default gateway?")
- Local $sRasFile = @AppDataCommonDir & "\Microsoft\Network\Connections\Pbk\rasphone.pbk"
- If FileExists($sRasFile) Then
- Local $hFileW = FileOpen($sRasFile, $FO_READ)
- If $hFileW <> -1 Then
- FileSetPos($hFileW, 0, $FILE_BEGIN)
- Local $sFileWrite = StringRegExpReplace(FileRead($hFileW), "\[Synchrotek VPN\].*?\r\n(\[[\w ]+\])", "$1")
- Local $iSchedule = @extended
- FileClose($hFileW)
- If @error=0 Then
- If $iSchedule = 0 Then
- $sFileWrite = StringRegExpReplace($sFileWrite, "\[Synchrotek VPN\].*?$", "")
- $iSchedule = @extended
- MsgBox($MB_SYSTEMMODAL, "Error", $iSchedule & @CRLF & @CRLF & $sFileWrite)
- EndIf
- EndIf
- If $iSchedule <> 0 Then
- $iStatus += 4
- If RunWait(@ComSpec & ' /c schtasks.exe /Delete /tn "Event Viewer Tasks\Routes for Syncrotek VPN" /f', "", @SW_HIDE) = 0 Then
- $iStatus += 8
- EndIf
- Endif
- $hFileW = FileOpen($sRasFile, $FO_OVERWRITE)
- If $hFileW <> 1 And FileWrite($hFileW, $sFileWrite & ReadMyRasphone($iUseGW)) Then
- $iStatus += 32
- FileClose($hFileW)
- EndIf
- Else
- MsgBox($MB_SYSTEMMODAL, "Error", "Unable to open rasphone.pbk" & @CRLF & "VPN Client not installed!")
- EndIf
- Else
- Local $hFileW = FileOpen($sRasFile, $FO_CREATEPATH)
- If $hFileW <> -1 Then
- If FileWrite($hFileW, ReadMyRasphone($iUseGW)) Then
- $iStatus += 32
- EndIf
- FileClose($hFileW)
- Else
- MsgBox($MB_SYSTEMMODAL, "Error", "Could not write " & $sRasFile)
- EndIf
- EndIf
- If $iUseGW=7 Then
- Local $hFileW = FileOpen(@ScriptDir & "\SyncVPN\routes.in.xml", $FO_READ)
- If $hFileW <> -1 Then
- Local $sFileWrite = StringReplace(FileRead($hFileW), "%scriptdir%", @AppDataCommonDir & "\Microsoft\Network\Connections\Cm\Synchrotek VPN")
- FileClose($hFileW)
- $hFileW = FileOpen(@ScriptDir & "\SyncVPN\routes.xml", $FO_OVERWRITE)
- If $hFileW <> 1 And FileWrite($hFileW, $sFileWrite) Then
- FileCopy(@ScriptDir & "\SyncVPN\routes.netsh", @AppDataCommonDir & "\Microsoft\Network\Connections\Cm\Synchrotek VPN\routes.netsh", $FC_OVERWRITE + $FC_CREATEPATH)
- FileClose($hFileW)
- If RunWait(@ComSpec & ' /c schtasks.exe /Create /tn "Event Viewer Tasks\Routes for Syncrotek VPN" /xml "' & @ScriptDir & '\SyncVPN\routes.xml"', "", @SW_HIDE) = 0 Then
- $iStatus += 16
- Endif
- EndIf
- EndIf
- EndIf
- Local $sVPNmessage = "VPN Clinet installation:" & @CRLF & " Installed client certificate"
- If BitAND($iStatus, 1) <> 0 Then
- $sVPNmessage &= @CRLF & " Instaled Sycnhrotek Root Certificate."
- EndIf
- If BitAND($iStatus, 2) <> 0 Then
- $sVPNmessage &= @CRLF & " Enabled VPN NAT traversal."
- EndIf
- If BitAND($iStatus, 4) <> 0 Then
- $sVPNmessage &= @CRLF & " Removed old VPN client."
- EndIf
- If BitAND($iStatus, 8) <> 0 Then
- $sVPNmessage &= @CRLF & " Removed old routes."
- EndIf
- If BitAND($iStatus, 16) <> 0 Then
- $sVPNmessage &= @CRLF & " Instaled new routes."
- EndIf
- If BitAND($iStatus, 32) <> 0 Then
- $sVPNmessage &= @CRLF & " Instaled VPN client (you need to restart)."
- EndIf
- MsgBox($MB_SYSTEMMODAL, "Status", $sVPNmessage)
- EndIf
- Else
- MsgBox($MB_SYSTEMMODAL, "Error", "No certificate selected!" & @CRLF & "Not installing VPN Clinet!")
- EndIf
- Local $iAnswer = MsgBox(BitOR($MB_YESNO, $MB_SYSTEMMODAL), "Smart Card", "Do you want to Install Smart Card driver?")
- If $iAnswer = 7 Then
- Exit
- EndIf
- If @OSArch = "X64" Then
- FileCopy(@ScriptDir & "\SmartCard\opensc-minidriver.64.dll", $InstallDir & "\opensc-minidriver.dll", $FC_OVERWRITE + $FC_CREATEPATH)
- Else
- FileCopy(@ScriptDir & "\SmartCard\opensc-minidriver.32.dll", $InstallDir & "\opensc-minidriver.dll", $FC_OVERWRITE + $FC_CREATEPATH)
- EndIf
- FileCopy(@ScriptDir & "\SmartCard\opensc.conf", $InstallDir, $FC_OVERWRITE + $FC_CREATEPATH)
- FileCopy(@ScriptDir & "\SmartCard\muscle.profile", $InstallDir, $FC_OVERWRITE + $FC_CREATEPATH)
- FileCopy(@ScriptDir & "\SmartCard\ChangePin.exe", $InstallDir, $FC_OVERWRITE + $FC_CREATEPATH)
- FileCopy(@ScriptDir & "\SmartCard\pkcs15-tool.exe", $InstallDir, $FC_OVERWRITE + $FC_CREATEPATH)
- FileCopy(@ScriptDir & "\SmartCard\opensc.dll", $InstallDir, $FC_OVERWRITE + $FC_CREATEPATH)
- FileCopy(@ScriptDir & "\SmartCard\opensc.ico", $InstallDir, $FC_OVERWRITE + $FC_CREATEPATH)
- FileCreateShortcut($InstallDir & "\ChangePin.exe", @ProgramsCommonDir & "\ChangePin.lnk", $InstallDir, "", "", $InstallDir & "/opensc.ico", "", 0)
- FileCreateShortcut($InstallDir & "\ChangePin.exe", @DesktopDir & "\ChangePin.lnk", $InstallDir, "", "", $InstallDir & "/opensc.ico", "", 0)
- Local $sRegKey = "HKLM\SOFTWARE\Microsoft\Cryptography\Calais\SmartCards\SynchrotekID"
- RegWrite($sRegKey)
- RegWrite($sRegKey, "80000001", "REG_SZ", $InstallDir & "\opensc-minidriver.dll")
- RegWrite($sRegKey, "ATR", "REG_BINARY", "3BF81800008031FE450073C8401000900091")
- RegWrite($sRegKey, "ATRMask", "REG_BINARY", "ffffffffffffffffffffffffffffffffffff")
- RegWrite($sRegKey, "Crypto Provider", "REG_SZ", "Microsoft Base Smart Card Crypto Provider")
- RegWrite($sRegKey, "Smart Card Key Storage Provider", "REG_SZ" ,"Microsoft Smart Card Key Storage Provider")
- ; RunWait(@ComSpec & " /c " & 'regedit "' & @ScriptDir & '\SmartCard\opensc.reg" & pause') ;, "", @SW_HIDE)
- RunWait(@ComSpec & ' /c setx OPENSC_CONF "' & $InstallDir & '\opensc.conf" /M', "", @SW_HIDE)
- MsgBox($MB_SYSTEMMODAL, "Success", "Drivers installed.")
- Func ReadMyRasphone($iUseGW)
- Local $hFileR = FileOpen(@ScriptDir & "\SyncVPN\rasphone.pbk.txt", $FO_READ)
- Local $sFileRead = ''
- If $hFileR <> -1 Then
- FileSetPos($hFileR, 0, $FILE_BEGIN)
- If $iUseGW=7 Then
- $sFileRead = StringReplace(FileRead($hFileR), "IpPrioritizeRemote=1", "IpPrioritizeRemote=0")
- Else
- $sFileRead = FileRead($hFileR)
- EndIf
- Else
- SetError(1);
- EndIf
- Return $sFileRead
- EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement