Advertisement
Guest User

install.au3

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