Advertisement
Guest User

install.au3

a guest
Jan 27th, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 7.72 KB | None | 0 0
  1. #include <Constants.au3>
  2. #include <FileConstants.au3>
  3. #RequireAdmin
  4. ;
  5. ; AutoIt Version: 3.0
  6. ; Language:       English
  7. ; Author:         Srecko Menjic (smenjic at synchrotek dot com)
  8.  
  9. If $CmdLine[0] < 1 Then
  10.     MsgBox($MB_SYSTEMMODAL, "Error", "Please add Installation folder as command line parameter")
  11.     Exit
  12. EndIf
  13. Local $InstallDir = $CmdLine[1]
  14.  
  15. If not IsAdmin() Then
  16.     MsgBox($MB_SYSTEMMODAL, "Error", "Please run as Admministrator")
  17.     Exit
  18. EndIf
  19.  
  20. 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.")
  21. Local $certfile = FileOpenDialog("Please input VPN private certificate file", @DesktopDir & "\", "Certificate (*.p12;*.pfx)")
  22. if @error = 0 Then
  23.     Local $certpassword = InputBox("Enter password", "Type your certificate password here," & @CRLF & "and click OK.", "", "*")
  24.     Local $iReturn = RunWait(@ComSpec & " /c certutil -p " & $certpassword & ' -importPFX "' & $certfile & '"', "", @SW_HIDE)
  25.  
  26.     If $iReturn <> 0 Then
  27.         MsgBox($MB_SYSTEMMODAL, "Error", "Bad certificate/password!" & @CRLF & "Not installing VPN Clinet!")
  28.     Else
  29.         Local $iStatus = 0
  30.         If RunWait(@ComSpec & ' /c certutil -addstore root "' & @ScriptDir & '\Certificates\SynchrotekCA.cer"', "", @SW_HIDE) = 0 Then
  31.             $iStatus += 1
  32.         EndIf
  33.         Local $sRegKey = 'HKLM\SYSTEM\CurrentControlSet\Services\PolicyAgent'
  34.         If RegWrite($sRegKey, "AssumeUDPEncapsulationContextOnSendRule", "REG_DWORD", 2) Then
  35.             $iStatus += 2
  36.         EndIf
  37. ;       Run(@ComSpec & " /c " & 'regedit /s "' & @ScriptDir & '\SyncVPN\IPSEC-NAT-T.reg"', "", @SW_HIDE)
  38.         Local $iUseGW = MsgBox(BitOR($MB_YESNO, $MB_SYSTEMMODAL), "Synchrotek VPN", "Do you want to use Synchrotek's default gateway?" & @CRLF & "Yes = All network traffic will go through VPN" & @CRLF & "No = Only subnet network traffic will go through VPN")
  39.         Local $sRasFile = @AppDataCommonDir & "\Microsoft\Network\Connections\Pbk\rasphone.pbk"
  40.         If FileExists($sRasFile) Then
  41.             Local $hFileR = FileOpen($sRasFile, $FO_READ)
  42.             If $hFileR <> -1 Then
  43.                 FileSetPos($hFileR, 0, $FILE_BEGIN)
  44.                 Local $sFileWrite = StringRegExpReplace(FileRead($hFileR), "(?s)\[Synchrotek VPN\].*?\r\n(\[[\w ]+\])", "$1")
  45.                 Local $iSchedule = @extended
  46.                 FileClose($hFileR)
  47.                 If @error=0 Then
  48.                     If $iSchedule = 0 Then
  49.                         $sFileWrite = StringRegExpReplace($sFileWrite, "(?s)\[Synchrotek VPN\].*?$", "")
  50.                         $iSchedule = @extended
  51.                     EndIf  
  52.                 EndIf
  53.                 If $iSchedule <> 0 Then
  54.                     $iStatus += 4
  55.                     If RunWait(@ComSpec & ' /c schtasks.exe /Delete /tn "Event Viewer Tasks\Routes for Syncrotek VPN" /f', "", @SW_HIDE) = 0 Then
  56.                         $iStatus += 8
  57.                     EndIf
  58.                 Endif
  59.                 Local $hFileW = FileOpen(@ScriptDir & "\SyncVPN\rasphone.pbk", $FO_OVERWRITE)
  60.                 If $hFileW <> -1 And FileWrite($hFileW, $sFileWrite & ReadMyRasphone($iUseGW)) Then
  61.                     $iStatus += 32
  62.                     FileClose($hFileW)
  63.                 EndIf
  64.             Else
  65.                 MsgBox($MB_SYSTEMMODAL, "Error", "Unable to open rasphone.pbk"  & @CRLF & "VPN Client not installed!")
  66.             EndIf
  67.         Else
  68.             Local $hFileW = FileOpen(@ScriptDir & "\SyncVPN\rasphone.pbk", $FO_OVERWRITE)
  69.             If $hFileW <> -1 Then
  70.                 If FileWrite($hFileW, ReadMyRasphone($iUseGW)) Then
  71.                     $iStatus += 32
  72.                 EndIf
  73.                 FileClose($hFileW)
  74.             EndIf
  75.         EndIf
  76.         If FileCopy(@ScriptDir & "\SyncVPN\rasphone.pbk", $sRasFile, $FC_OVERWRITE + $FC_CREATEPATH) Then
  77.             $iStatus += 64
  78.         EndIf
  79.         If $iUseGW=7 Then
  80.             Local $hFileR = FileOpen(@ScriptDir & "\SyncVPN\routes.in.xml", $FO_READ)
  81.             If $hFileR <> -1 Then
  82.                 Local $sFileWrite = StringReplace(FileRead($hFileR), "%scriptdir%", @AppDataCommonDir & "\Microsoft\Network\Connections\Cm\Synchrotek VPN")
  83.                 FileClose($hFileR)
  84.                 Local $hFileW = FileOpen(@ScriptDir & "\SyncVPN\routes.xml", $FO_OVERWRITE)
  85.                 If $hFileW <> -1 And FileWrite($hFileW, $sFileWrite) Then
  86.                     FileCopy(@ScriptDir & "\SyncVPN\routes.netsh", @AppDataCommonDir & "\Microsoft\Network\Connections\Cm\Synchrotek VPN\routes.netsh", $FC_OVERWRITE + $FC_CREATEPATH)
  87.                     FileClose($hFileW)
  88.                     If RunWait(@ComSpec & ' /c schtasks.exe /Create /tn "Event Viewer Tasks\Routes for Syncrotek VPN" /xml "' & @ScriptDir & '\SyncVPN\routes.xml"', "", @SW_HIDE) = 0 Then
  89.                         $iStatus += 16
  90.                     Endif
  91.                 EndIf
  92.             EndIf
  93.         EndIf
  94.         Local $sVPNmessage = "VPN Clinet installation:" & @CRLF & "   Installed client certificate"
  95.         If BitAND($iStatus, 1) <> 0 Then
  96.             $sVPNmessage &= @CRLF & "   Instaled Sycnhrotek Root Certificate."
  97.         EndIf
  98.         If BitAND($iStatus, 2) <> 0 Then
  99.             $sVPNmessage &= @CRLF & "   Enabled VPN NAT traversal."
  100.         EndIf
  101.         If BitAND($iStatus, 4) <> 0 Then
  102.             $sVPNmessage &= @CRLF & "   Removed old VPN client."
  103.         EndIf
  104.         If BitAND($iStatus, 8) <> 0 Then
  105.             $sVPNmessage &= @CRLF & "   Removed old routes."
  106.         EndIf
  107.         If BitAND($iStatus, 16) <> 0 Then
  108.             $sVPNmessage &= @CRLF & "   Instaled new routes."
  109.         EndIf
  110.         If BitAND($iStatus, 32) <> 0 And BitAND($iStatus, 64) <> 0 Then
  111.             $sVPNmessage &= @CRLF & "   Instaled VPN client (you need to restart)."
  112.         EndIf
  113.         MsgBox($MB_SYSTEMMODAL, "Status", $sVPNmessage)
  114.     EndIf
  115. Else
  116.     MsgBox($MB_SYSTEMMODAL, "Error", "No certificate selected!" & @CRLF & "Not installing VPN Clinet!")
  117. EndIf
  118.  
  119.  
  120. Local $iAnswer = MsgBox(BitOR($MB_YESNO, $MB_SYSTEMMODAL), "Smart Card", "Do you want to Install Smart Card driver?")
  121. If $iAnswer = 7 Then
  122.     Exit
  123. EndIf
  124.  
  125. If @OSArch = "X64" Then
  126.     FileCopy(@ScriptDir & "\SmartCard\opensc-minidriver.64.dll", $InstallDir & "\opensc-minidriver.dll", $FC_OVERWRITE + $FC_CREATEPATH)
  127. Else
  128.     FileCopy(@ScriptDir & "\SmartCard\opensc-minidriver.32.dll", $InstallDir & "\opensc-minidriver.dll", $FC_OVERWRITE + $FC_CREATEPATH)
  129. EndIf
  130. FileCopy(@ScriptDir & "\SmartCard\opensc.conf", $InstallDir, $FC_OVERWRITE + $FC_CREATEPATH)
  131. FileCopy(@ScriptDir & "\SmartCard\muscle.profile", $InstallDir, $FC_OVERWRITE + $FC_CREATEPATH)
  132. FileCopy(@ScriptDir & "\SmartCard\ChangePin.exe", $InstallDir, $FC_OVERWRITE + $FC_CREATEPATH)
  133. FileCopy(@ScriptDir & "\SmartCard\pkcs15-tool.exe", $InstallDir, $FC_OVERWRITE + $FC_CREATEPATH)
  134. FileCopy(@ScriptDir & "\SmartCard\opensc.dll", $InstallDir, $FC_OVERWRITE + $FC_CREATEPATH)
  135. FileCopy(@ScriptDir & "\SmartCard\opensc.ico", $InstallDir, $FC_OVERWRITE + $FC_CREATEPATH)
  136. FileCreateShortcut($InstallDir & "\ChangePin.exe", @ProgramsCommonDir & "\ChangePin.lnk", $InstallDir, "", "", $InstallDir & "/opensc.ico", "", 0)
  137. FileCreateShortcut($InstallDir & "\ChangePin.exe", @DesktopDir & "\ChangePin.lnk", $InstallDir, "", "", $InstallDir & "/opensc.ico", "", 0)
  138.  
  139. Local $sRegKey = "HKLM\SOFTWARE\Microsoft\Cryptography\Calais\SmartCards\SynchrotekID"
  140. RegWrite($sRegKey)
  141. RegWrite($sRegKey, "80000001", "REG_SZ", $InstallDir & "\opensc-minidriver.dll")
  142. RegWrite($sRegKey, "ATR", "REG_BINARY", "3BF81800008031FE450073C8401000900091")
  143. RegWrite($sRegKey, "ATRMask", "REG_BINARY", "ffffffffffffffffffffffffffffffffffff")
  144. RegWrite($sRegKey, "Crypto Provider", "REG_SZ", "Microsoft Base Smart Card Crypto Provider")
  145. RegWrite($sRegKey, "Smart Card Key Storage Provider", "REG_SZ" ,"Microsoft Smart Card Key Storage Provider")
  146. ; RunWait(@ComSpec & " /c " & 'regedit "' & @ScriptDir & '\SmartCard\opensc.reg" & pause') ;, "", @SW_HIDE)
  147. RunWait(@ComSpec & ' /c setx OPENSC_CONF "' & $InstallDir & '\opensc.conf" /M', "", @SW_HIDE)
  148.  
  149. MsgBox($MB_SYSTEMMODAL, "Success", "Drivers installed.")
  150.  
  151. Func ReadMyRasphone($iUseGW)
  152.     Local $hFileR = FileOpen(@ScriptDir & "\SyncVPN\rasphone.pbk.txt", $FO_READ)
  153.     Local $sFileRead = ''
  154.     If $hFileR <> -1 Then
  155.         FileSetPos($hFileR, 0, $FILE_BEGIN)
  156.         If $iUseGW=7 Then
  157.             $sFileRead = StringReplace(FileRead($hFileR), "IpPrioritizeRemote=1", "IpPrioritizeRemote=0")
  158.         Else
  159.             $sFileRead = FileRead($hFileR)
  160.         EndIf
  161.     Else
  162.         SetError(1);
  163.     EndIf
  164.     Return $sFileRead
  165. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement