From 43eb7bc003dd6b9b2725d0c9e6fb37a243bfde29 Mon Sep 17 00:00:00 2001 From: PiBa-NL Date: Mon, 5 Nov 2012 14:10:36 +0100 Subject: openvpn-client-export, added option to include OpenVPNManager in windows setup, this solves the issues with Windows7/Vista client machines where elevated permissions are required by running OpenVPN as a service. --- config/openvpn-client-export/source/dotnet2.nsh | 93 ++++++++++++ .../source/openvpn-postinstall.nsi | 157 +++++++++++++++++---- 2 files changed, 220 insertions(+), 30 deletions(-) create mode 100644 config/openvpn-client-export/source/dotnet2.nsh (limited to 'config/openvpn-client-export/source') diff --git a/config/openvpn-client-export/source/dotnet2.nsh b/config/openvpn-client-export/source/dotnet2.nsh new file mode 100644 index 00000000..5ec356e3 --- /dev/null +++ b/config/openvpn-client-export/source/dotnet2.nsh @@ -0,0 +1,93 @@ +; Plugin for installing .NET Framework v2.0 +; Written by Christopher St. John +; for EncounterPRO Healthcare Resources, Inc. + +!ifndef DOTNET2_INCLUDED +!define DOTNET2_INCLUDED + +; ----------------------------------------- +; Includes + !include "WordFunc.nsh" + !insertmacro VersionCompare + !include LogicLib.nsh + +; ----------------------------------------- +; Defines + ; Direct-download location of .NET 2.0 redist + !define BASE_URL http://download.microsoft.com/download + !define URL_DOTNET_1033 "${BASE_URL}/5/6/7/567758a3-759e-473e-bf8f-52154438565a/dotnetfx.exe" + +; ----------------------------------------- +; Variables + Var DotNetVersion2 + Var InstallDotNet2 + +; ----------------------------------------- +; Functions +Function GetDotNETVersion2 + Push $0 + Push $1 + + System::Call "mscoree::GetCORVersion(w .r0, i 1024, *i r2) i .r1" + StrCmp $1 0 +2 + StrCpy $0 0 + + Pop $1 + Exch $0 +FunctionEnd + +; ----------------------------------------- +; Macros +!macro CheckForDotNET2 + ; Check .NET version + StrCpy $InstallDotNET2 "No" + Call GetDotNETVersion2 + Pop $0 + StrCpy $DotNetVersion2 $0 + + ${If} $0 == "not found" + StrCpy $InstallDotNET2 "Yes" + MessageBox MB_OK|MB_ICONINFORMATION "Installer requires that the .NET Framework 2.0 is installed. The .NET Framework will be downloaded and installed automatically during installation." + Return + ${EndIf} + + StrCpy $0 $0 "" 1 # skip "v" + + ${VersionCompare} $0 "2.0" $1 + ${If} $1 == 2 + StrCpy $InstallDotNET2 "Yes" + MessageBox MB_OK|MB_ICONINFORMATION "Installer requires that the .NET Framework 2.0 is installed. The .NET Framework will be downloaded and installed automatically during installation." + Return + ${EndIf} +!macroend + +!macro InstallDotNET2 + ; Get .NET if required + ${If} $InstallDotNET2 == "Yes" + DetailPrint "Downloading .NET Framework v2.0..." + ;SetDetailsView hide + NSISdl::download /TIMEOUT=30000 "${URL_DOTNET_1033}" "$INSTDIR\dotnetfx.exe" + Pop $1 + + ${If} $1 != "success" + DetailPrint "Download failed: $1" + Delete "$INSTDIR\dotnetfx.exe" + Abort "Installation Cancelled" + ${EndIf} + + DetailPrint "Installing .NET Framework v2.0..." + ExecWait '"$INSTDIR\dotnetfx.exe" /q:a /c:"install /passive"' $1 + ${If} $1 == 0 + DetailPrint ".NET Framework v2.0 successfully installed." + ${ElseIf} $1 == 3010 + MessageBox MB_OK ".NET Framework v2.0 has been installed and requires a reboot. Please restart the computer and run this installer again." + Abort ".NET Framework v2.0 requires reboot." + ${Else} + MessageBox MB_OK ".NET Framework v2.0 reports a failure during installation ($1). Please try to install .NET Framework v2.0 via Windows Update before running this installer again." + Abort ".NET Framework v2.0 installation failed ($1)." + ${EndIf} + Delete "$INSTDIR\dotnetfx.exe" + ${EndIf} +!macroend + +!endif \ No newline at end of file diff --git a/config/openvpn-client-export/source/openvpn-postinstall.nsi b/config/openvpn-client-export/source/openvpn-postinstall.nsi index 4f03783d..fb4356e0 100755 --- a/config/openvpn-client-export/source/openvpn-postinstall.nsi +++ b/config/openvpn-client-export/source/openvpn-postinstall.nsi @@ -5,7 +5,10 @@ ;-------------------------------- ;Include Modern UI - !include "MUI.nsh" +Var /GLOBAL mui.FinishPage.Run +!define MUI_FINISHPAGE_RUN_VARIABLES + + !include "MUI2.nsh" !include "FileFunc.nsh" !include "LogicLib.nsh" @@ -19,6 +22,7 @@ ShowInstDetails show + !include "dotnet2.nsh" ;-------------------------------- ;Include Settings ;-------------------------------- @@ -30,7 +34,25 @@ ;Pages ;-------------------------------- +!define WELCOME_TITLE 'Welcome to OpenVPN installer.' + +!define WELCOME_TEXT "This wizard will guide you through the installation of the OpenVPN client and configuration.$\r$\n$\r$\n\ +This wil automaticaly install the configuration files needed for your connection. \ +And if needed install the required DotNet2 framework." + !define MUI_WELCOMEPAGE_TITLE '${WELCOME_TITLE}' + ;!define MUI_WELCOMEPAGE_TITLE_3LINES + !define MUI_WELCOMEPAGE_TEXT '${WELCOME_TEXT}' + !insertmacro MUI_PAGE_WELCOME + !insertmacro MUI_PAGE_INSTFILES + + + !define MUI_FINISHPAGE_RUN "C:\User\test.lnk" + !define MUI_FINISHPAGE_RUN_TEXT "Start OpenVPNManager." + !define MUI_FINISHPAGE_RUN_FUNCTION "LaunchLink" + !define MUI_PAGE_CUSTOMFUNCTION_SHOW finish_show + !insertmacro MUI_PAGE_FINISH + !insertmacro Locate !insertmacro GetParameters !insertmacro GetOptions @@ -46,55 +68,130 @@ ;-------------------------------- Function .onInit - + Var /GLOBAL BINPATH Var /GLOBAL CONFPATH - ReadRegStr $CONFPATH HKLM "Software\OpenVPN" "config_dir" - + Var /GLOBAL OpenVPNManager + + IfFileExists ".\OpenVPNManager" InstallOpenVPNManager1 DontInstallOpenVPNManager1 + InstallOpenVPNManager1: + strcpy $OpenVPNManager true + !insertmacro CheckForDotNET2 + Goto OpenVPNManagerDone1 + DontInstallOpenVPNManager1: + strcpy $OpenVPNManager false + OpenVPNManagerDone1: FunctionEnd Function CopyConfFile - CopyFiles $R9 $CONFPATH\$R7 Push $0 - FunctionEnd Function ImportConfFile - ExecWait "rundll32.exe cryptext.dll,CryptExtAddPFX $R9" Push $0 +FunctionEnd +Function CopyOpenVPNManager + DetailPrint "Installing OpenVPNManager..." + DetailPrint "Installing in: $BINPATH\OpenVPNManager\" + CreateDirectory "$BINPATH\OpenVPNManager" + CreateDirectory "$BINPATH\OpenVPNManager\config" + CopyFiles ".\OpenVPNManager\*.*" "$BINPATH\OpenVPNManager" + CreateShortcut "$desktop\OpenVPNManager.lnk" "$BINPATH\OpenVPNManager\OpenVPNManager.exe" + Push $0 FunctionEnd +Function finish_show + ${If} $OpenVPNManager != "true" + ;If OpenVPNManager is not installed then dont give the option to run it. (hide and uncheck the checkbox) + ShowWindow $mui.FinishPage.Run 0 + ${NSD_Uncheck} $mui.FinishPage.Run + ${EndIf} +FunctionEnd + +Function LaunchLink + ExecShell "" "$desktop\OpenVPNManager.lnk" +FunctionEnd ;-------------------------------- ;Installer Sections ;-------------------------------- -Section "Imort Configuration" SectionImport - - DetailPrint "Installing configuration files ..." - ${Locate} ".\config" "/L=F /M=*.ovpn" "CopyConfFile" - - DetailPrint "Installing certificate and key files ..." - ${Locate} ".\config" "/L=F /M=*.crt" "CopyConfFile" - ${Locate} ".\config" "/L=F /M=*.key" "CopyConfFile" - - ${GetParameters} $R0 - ${GetOptions} $R0 "/Import" $R1 - IfErrors p12_copy p12_import - - p12_copy: - ${Locate} ".\config" "/L=F /M=*.p12" "CopyConfFile" - Goto p12_done - - p12_import: - ${Locate} ".\config" "/L=F /M=*.p12" "ImportConfFile" - Goto p12_done - - p12_done: +Section "Import Configuration" SectionImport + ${If} $OpenVPNManager == "true" + ; OpenVPNManager needs dotnet2 + !insertmacro InstallDotNet2 + ${Endif} + + ClearErrors + ReadRegStr $BINPATH HKLM "Software\OpenVPN" "" + IfErrors OpenVPNInstall OpenVPNAlreadyInstalled + OpenVPNInstall: + DetailPrint "Pausing installation while OpenVPN installer runs." + ExecWait '".\openvpn-install.exe"' $1 + ${if} $OpenVPNManager == "true" + SetShellVarContext all + Delete "$desktop\OpenVPN GUI.lnk" + SetShellVarContext current + ${Endif} + Pop $0 + OpenVPNAlreadyInstalled: + + ClearErrors + ReadRegStr $BINPATH HKLM "Software\OpenVPN" "" + IfErrors OpenVPNnotFound OpenVPNok + OpenVPNnotFound: + Abort "OpenVPN installation not found, installation aborted." + OpenVPNok: + DetailPrint "Completed OpenVPN installation." + + ${If} $OpenVPNManager == "true" + strcpy $OpenVPNManager true + StrCpy $CONFPATH "$BINPATH\OpenVPNManager\config" + call "CopyOpenVPNManager" + ${Else} + strcpy $OpenVPNManager false + ClearErrors + ReadRegStr $CONFPATH HKLM "Software\OpenVPN" "config_dir" + IfErrors configNotFound configFound + configNotFound: + ReadRegStr $CONFPATH HKLM "Software\OpenVPN" "" + StrCpy $CONFPATH "$CONFPATH\config" + configFound: + + ${Endif} + + DetailPrint "Installing configuration files ..." + ${Locate} ".\config" "/L=F /M=*.ovpn" "CopyConfFile" + + DetailPrint "Installing certificate and key files ..." + ${Locate} ".\config" "/L=F /M=*.crt" "CopyConfFile" + ${Locate} ".\config" "/L=F /M=*.key" "CopyConfFile" + + ${If} $OpenVPNManager == "true" + DetailPrint "Registering OpenVPNManager service..." + ExecWait '"$BINPATH\OpenVPNManager\OpenVPNManager.exe" /install' + DetailPrint "Starting OpenVPNManager service..." + SimpleSC::StartService "OpenVPNManager" "" 30 + Pop $0 + ${Else} + ;DetailPrint "Starting OpenVPN Service..." + ;SimpleSC::StartService "OpenVPNService" "" 30 + ;Pop $0 + ${Endif} + + ${GetParameters} $R0 + ${GetOptions} $R0 "/Import" $R1 + IfErrors p12_copy p12_import + p12_copy: + ${Locate} ".\config" "/L=F /M=*.p12" "CopyConfFile" + Goto p12_done + p12_import: + ${Locate} ".\config" "/L=F /M=*.p12" "ImportConfFile" + Goto p12_done + p12_done: SectionEnd - ;-------------------------------- ;Descriptions ;-------------------------------- -- cgit v1.2.3