Prevent the Windows installer accepting paths containing invalid characters. Fixes #1365

pull/6/head
Paresh More 2017-11-20 16:37:18 +00:00 committed by Dave Page
parent 4568fe22f7
commit 8ff753deb8
3 changed files with 122 additions and 34 deletions

View File

@ -60,9 +60,11 @@ REM Main function Ends
:SET_PGADMIN4_ENVIRONMENT
IF "%PYTHON_HOME%" == "" SET "PYTHON_HOME=C:\Python27"
IF "%PYTHON_DLL%" == "" SET "PYTHON_DLL=C:\Windows\SysWOW64\python27.dll"
IF "%QTDIR%" == "" SET "QTDIR=C:\Qt\5.8\mingw53_32"
IF "%QTDIR%" == "" SET "QTDIR=C:\Qt\5.9.1\mingw53_32"
IF "%PGDIR%" == "" SET "PGDIR=C:\Program Files (x86)\PostgreSQL\9.6"
IF "%INNOTOOL%" == "" SET "INNOTOOL=C:\Program Files (x86)\Inno Setup 5"
IF "%YARNDIR%" == "" SET "YARNDIR=C:\Program Files\Yarn"
IF "%NODEJSDIR%" == "" SET "NODEJSDIR=C:\Program Files\nodejs"
IF "%VCDIR%" == "" SET "VCDIR=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC"
IF "%VCREDIST%" == "" SET "VCREDIST=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\redist\1033\vcredist_x86.exe"
IF "%SIGNTOOL%" == "" SET "SIGNTOOL=C:\Program Files\Microsoft SDKs\Windows\v7.1A\Bin\signtool.exe"
@ -104,6 +106,8 @@ REM Main function Ends
ECHO QTDIR = %QTDIR%
ECHO QMAKE = %QMAKE%
ECHO QT_VERSION = %QT_VERSION%
ECHO YARNDIR = %YARNDIR%
ECHO NODEJSDIR = %NODEJSDIR%
ECHO BROWSER = QtWebKit
ECHO PYTHON_HOME = %PYTHON_HOME%
ECHO PYTHON_DLL = %PYTHON_DLL%
@ -119,6 +123,8 @@ REM Main function Ends
IF NOT EXIST "%PYTHON_HOME%" GOTO err_handle_python
IF NOT EXIST "%PYTHON_DLL%" GOTO err_handle_python
IF NOT EXIST "%PGDIR%" GOTO err_handle_pg
IF NOT EXIST "%YARNDIR%" GOTO err_handle_yarn
IF NOT EXIST "%NODEJSDIR%" GOTO err_handle_nodejs
REM get Python version ex. 2.7.1 will get as 27
FOR /f "tokens=1 DELims=." %%G IN ('%PYTHON_HOME%/python.exe -c "import sys; print(sys.version.split(' ')[0])"') DO SET PYTHON_MAJOR=%%G
@ -127,8 +133,7 @@ REM Main function Ends
IF NOT EXIST "%PYTHON_HOME%\Scripts\virtualenv.exe" GOTO err_handle_pythonvirtualenv
SET PATH=%PGDIR%;%PGDIR%\bin;%PATH%
SET PATH=%PGDIR%;%PGDIR%\bin;%QTDIR%\..\..\Tools\mingw530_32\bin;%NODEJSDIR%;%YARNDIR%\bin;%PATH%;
GOTO:eof
:CREATE_VIRTUAL_ENV
@ -448,6 +453,20 @@ REM Main function Ends
exit /B 1
GOTO EXIT
:err_handle_yarn
ECHO %YARNDIR% does not exist.
ECHO Please Install YARN and SET the YARNDIR enviroment variable.
ECHO SET "YARNDIR=<YARN PATH>"
exit /B 1
GOTO EXIT
:err_handle_nodejs
ECHO %NODEJSDIR% does not exist.
ECHO Please Install NodeJs and SET the NODEJSDIR enviroment variable.
ECHO SET "NODEJSDIR=<NODEJS PATH>"
exit /B 1
GOTO EXIT
:err_handle_pg
ECHO %PGDIR% does not exist.
ECHO Please Install Postgres and SET enviroment Variable

View File

@ -12,7 +12,7 @@ To generate a pgAdmin 4 installer for Windows bit, the following packages must b
3. PostgreSQL installation
- PostgreSQL 9.1 or above from http://www.postgresql.org/
4. Inno Setup Installer
4. Inno Setup Installer (unicode)
- 5.0 and above from http://www.jrsoftware.org/isdl.php
5. Microsoft visual studio (2008 and above)

View File

@ -7,6 +7,8 @@
#define MyAppFullVersion MYAPP_FULLVERSION
#define MyAppArchitecturesMode MYAPP_ARCHITECTURESMODE
#define MyAppVCDist MYAPP_VCDIST
#define MyAppInvalidPath "Please provide a valid path."
[Setup]
AppId={#MyAppName}{#MyAppVersion}
AppName={#MyAppName}
@ -32,6 +34,15 @@ ArchitecturesInstallIn64BitMode={#MyAppArchitecturesMode}
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
;This section will override the standered error message by default which is called internally and we don't have a controll over this.
[Messages]
InvalidPath={#MyAppInvalidPath}
;This section would be used for customized error message display.
[CustomMessages]
english.NewerVersionExists=A newer version of {#MyAppName}
english.InvalidPath={#MyAppInvalidPath}
[Icons]
Name: {group}\{#MyAppName} {#MyAppVersion}; Filename: {app}\runtime\{#MyAppExeName}; IconFilename: {app}\pgAdmin4.ico; WorkingDir: {app}\runtime;
@ -42,9 +53,6 @@ Source: "..\..\win-build\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdi
Filename: "{app}\installer\{#MyAppVCDist}"; StatusMsg: "VC runtime redistributable package"; Parameters: "/passive /verysilent /norestart"; Check: InstallVC;
Filename: "{app}\runtime\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: runascurrentuser nowait postinstall skipifsilent
[CustomMessages]
english.NewerVersionExists=A newer version of {#MyAppName}
[Registry]
Root: HKLM; Subkey: "Software\{#MyAppName}\{#MyAppVersion}"; Flags: uninsdeletekeyifempty
Root: HKLM; Subkey: "Software\{#MyAppName}\{#MyAppVersion}"; Flags: uninsdeletekey
@ -52,28 +60,68 @@ Root: HKLM; Subkey: "Software\{#MyAppName}\{#MyAppVersion}"; ValueType: string;
Root: HKLM; Subkey: "Software\{#MyAppName}\{#MyAppVersion}"; ValueType: string; ValueName: "Version"; ValueData: "{#MyAppFullVersion}"
[Code]
// find current version before installation
var
UpgradeMode: Boolean;
function IsPathValid(Path: string): Boolean;
var
I: Integer;
Ret: Boolean;
begin
Ret := True;
Path := Uppercase(Path);
Result :=
(Length(Path) >= 3) and
(Path[1] >= 'A') and (Path[1] <= 'Z') and
(Path[2] = ':') and
(Path[3] = '\');
if Result then
begin
for I := 3 to Length(Path) do
begin
case Path[I] of
'0'..'9', 'A'..'Z', '\', ' ', '.', '-', '(', ')':
else
begin
Ret := False;
break;
end;
end;
end;
end;
Result := Ret;
end;
// Find current version before installation
function InitializeSetup: Boolean;
var
Version: String;
begin
if RegValueExists(HKEY_LOCAL_MACHINE,'Software\{#MyAppName}\{#MyAppVersion}', 'Version') then
begin
UpgradeMode := True;
RegQueryStringValue(HKEY_LOCAL_MACHINE,'Software\{#MyAppName}\{#MyAppVersion}', 'Version', Version);
if Version > '{#MyAppFullVersion}' then
begin
RegQueryStringValue(HKEY_LOCAL_MACHINE,'Software\{#MyAppName}\{#MyAppVersion}', 'Version', Version);
if Version > '{#MyAppFullVersion}' then
begin
MsgBox(ExpandConstant('{cm:NewerVersionExists}' + '(v' + Version + ') is already installed' ), mbInformation, MB_OK);
Result := False;
end
else
begin
Result := True;
end
MsgBox(ExpandConstant('{cm:NewerVersionExists}' + '(v' + Version + ') is already installed' ), mbInformation, MB_OK);
Result := False;
end
else
else
begin
Result := True;
end
end;
end
else
begin
Result := True;
UpgradeMode := False;
end;
end;
function IsUpgradeMode(): Boolean;
begin
Result := UpgradeMode;
end;
function InstallVC: Boolean;
@ -103,24 +151,45 @@ begin
end
end
else
begin
DelWebfolder(FilePath);
RemoveDir(FilePath);
end
end;
begin
DelWebfolder(FilePath);
RemoveDir(FilePath);
end;
end;
until not FindNext(FindRec);
finally
FindClose(FindRec);
end
end
finally
FindClose(FindRec);
end;
end;
end;
procedure CurPageChanged(CurPageID: Integer);
//procedure CurPageChanged(CurPageID: Integer);
function NextButtonClick(CurPageID: Integer): Boolean;
var
Ret: Boolean;
begin
if CurPageID=wpReady then
begin
DelWebfolder(ExpandConstant('{app}\web'));
end
Ret := True;
case CurPageID of
wpSelectDir:
begin
// Validate InstallDir path
if Not IsPathValid(ExpandConstant('{app}')) then
begin
MsgBox(ExpandConstant('{cm:InvalidPath}'), mbError, MB_OK);
Ret := False;
end;
end;
wpReady:
begin
if (IsUpgradeMode) then
begin
DelWebfolder(ExpandConstant('{app}\web'));
end;
end;
end;
Result := Ret;
end;
// End of program