## ## Basic OpenVPN installation and configuration wrapper ## ## It will download a hash from the web server containing a MD5 hash of the current install wrapper. ## If the downloaded hash do not match the calculated hash for the installer, the installer aborts ## immediately. ## ## Then OpenVPN is downloaded, together with a new MD5 hash of that package. This hash is again ## validated against the downloaded OpenVPN installer, before the OpenVPN installer is started. ## ## The user is then asked for a ZIP file, containing certificate and configuration files. ## This file is then unpacked in the Program Files\OpenVPN\config directory. ## ## The uninstall section will empty all config files and .p12 certificates from the ## Program Files\OpenVPN\config directory, before starting the OpenVPN uninstaller. ## ## GPLv2 only - Copyright (C) 2010 ## David Sommerseth ## ## This program is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License ## as published by the Free Software Foundation; version 2 ## of the License. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## Name "OpenVPN install and configure wizard" OutFile "OpenVPN-InstCfgWiz.exe" !AddPluginDir ./plugins !include nsDialogs.nsh !include LogicLib.nsh # LoadLanguageFile "/usr/share/nsis/Contrib/Language files/.nlf" # The default installation directory - will be modified later on InstallDir $TEMP # Request application privileges for Windows Vista - required by OpenVPN installer too. RequestExecutionLevel admin XPStyle on # # Pages # Page components Page instfiles Page custom CertSelect Page custom CertInstall UninstPage instfiles # # Misc variables used by the functions and sections # Var fnc_OVPNabort Var HashFD Var HashDL Var HashCalc Var Dialog Var textfield_certfile Var CertFilename Var URL_InstCfgWizHash Var URL_OpenVPNinstaller Var URL_OpenVPNinstallerHash # # Validate installer # Function .onInit # # Download URLs ... **MUST BE CHANGED** # StrCpy $URL_InstCfgWizHash "http://www.example.com/vpninstall/OpenVPN-InstCfgWiz.exe.md5" StrCpy $URL_OpenVPNinstaller "http://www.example.com/vpninstall/openvpn-installer.exe" StrCpy $URL_OpenVPNinstallerHash "http://www.example.com/vpninstall/openvpn-installer.exe.md5" # Validate this installer inetc::get $URL_InstCfgWizHash hash.dat Pop $1 StrCmp $1 "OK" 0 doAbort FileOpen $HashFD "hash.dat" r IfErrors doAbort FileRead $HashFD $HashDL FileClose $HashFD Delete "hash.dat" md5dll::GetMD5File "$EXEPATH" Pop $HashCalc StrCmp $HashCalc $HashDL NoAbort 0 doAbort: MessageBox MB_OK|MB_ICONSTOP "Self-validation of OpenVPN-InstCfgWiz failed. Please contact your system administrator." Abort NoAbort: DetailPrint "Hash 1: Approved" FunctionEnd # # Download and install OpenVPN # Function OVPNabort MessageBox MB_OK|MB_ICONSTOP "Installation of OpenVPN failed. Aborting!" Abort FunctionEnd Section "OpenVPN - download and installation" AddSize 4000 SetOutPath $TEMP GetFunctionAddress $fnc_OVPNabort OVPNabort DetailPrint "Downloading OpenVPN from $URL_OpenVPNinstaller" inetc::get /TRANSLATE "Downloading: %s " "Connecting ... " s m t "" " %dkiB (%d%%) of %dkiB. (Speed: %d.%02dkiB/s) " "" $URL_OpenVPNinstaller openvpn-install.exe /END Pop $0 DetailPrint "Result: $0" StrCmp $0 "OK" 0 $fnc_OVPNabort inetc::get /TRANSLATE "Downloading: %s " "Connecting ... " s m t "" " %dkiB (%d%%) av %dkiB. (Speed: %d.%02dkiB/s) " "" $URL_OpenVPNinstallerHash hash.dat /END Pop $1 DetailPrint "Result: $1" StrCmp $1 "OK" 0 $fnc_OVPNabort FileOpen $HashFD "hash.dat" r IfErrors $fnc_OVPNabort FileRead $HashFD $HashDL FileClose $HashFD Delete "hash.dat" md5dll::GetMD5File "openvpn-install.exe" Pop $HashCalc StrCmp $HashCalc $HashDL 0 $fnc_OVPNabort DetailPrint "Installing OpenVPN" ExecWait 'openvpn-install.exe /S' $2 Delete openvpn-install.exe StrCmp $2 "0" 0 $fnc_OVPNabort SectionEnd # # Select certificate to be installed # Function fileSelect_Certfile # Set this path to desktop, to let the file selector start here SetOutPath $DESKTOP nsDialogs::SelectFileDialog "Open" "*.zip" "ZIP files|*.zip") Pop $CertFilename ${NSD_SetText} $textfield_certfile $CertFilename FunctionEnd Function CertSelect nsDialogs::Create 1018 Pop $Dialog ${If} $Dialog == error Abort ${EndIf} ${NSD_CreateLabel} 0 0 100% 36u "You should have received ZIP file with your OpenVPN configuration. Please locate and select this file in the file dialog and click 'Next'." ${NSD_CreateButton} 12% 40u 75% 12u "Locate your OpenVPN configuration setup file (ZIP file)" Pop $0 GetFunctionAddress $1 fileSelect_CertFile nsDialogs::OnClick $0 $1 ${NSD_CreateLabel} 0 65u 100% 12u "Chosen configuration setup file:" ${NSD_CreateText} 0 80u 100% 12u "" Pop $textfield_certfile nsDialogs::Show FunctionEnd # # Install certificate # Function unzipFailed MessageBox MB_OK|MB_ICONEXCLAMATION "Extraction of the configuration setup failed." Abort FunctionEnd Function certinst_noBack Abort FunctionEnd Function CertInstall GetFunctionAddress $1 unzipFailed nsUnzip::Extract /d=$PROGRAMFILES\OpenVPN\config $CertFilename /END Pop $0 StrCmp $0 "0" 0 $1 nsDialogs::Create 1018 Pop $Dialog ${If} $Dialog == error Abort ${EndIf} ${NSD_OnBack} certinst_noBack ${NSD_CreateLabel} 0 40% 100% 36u "Installation and configuration completed successfully. On your desktop you should now find a new icon named 'OpenVPN GUI'. Start this program to connect to your VPN." WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenVPN-InstCfgWiz" "DisplayName" "OpenVPN Installation and configuration wizard setup" WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenVPN-InstCfgWiz" "UninstallString" "$PROGRAMFILES\OpenVPN\uninst-ovpninstcfgwiz.exe" WriteUninstaller "$PROGRAMFILES\OpenVPN\uninst-ovpninstcfgwiz.exe" nsDialogs::Show FunctionEnd # # UNINSTALL # Section "Uninstall" Delete $PROGRAMFILES\OpenVPN\uninst-ovpninstcfgwiz.exe Delete $PROGRAMFILES\OpenVPN\config\*.ovpn Delete $PROGRAMFILES\OpenVPN\config\*.p12 Delete $PROGRAMFILES\OpenVPN\config\*.key Delete $PROGRAMFILES\OpenVPN\config\*.crt ExecWait '"$PROGRAMFILES\OpenVPN\Uninstall.exe"' RMDir $PROGRAMFILES\OpenVPN\config SectionEnd