Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup duplicated data config paths #4314

Merged
merged 1 commit into from
Mar 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions SQL/0000-00-03-ConfigTables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType,
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, Label, OrderNumber) VALUES ('paths', 'Specify directories where LORIS-related files are stored or created. Take care when editing these fields as changing them incorrectly can cause certain modules to lose functionality.', 1, 0, 'Paths', 2);
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'imagePath', 'Path to images for display in Imaging Browser (e.g. /data/$project/data/) ', 1, 0, 'text', ID, 'Images', 9 FROM ConfigSettings WHERE Name="paths";
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'base', 'The base filesystem path where LORIS is installed', 1, 0, 'text', ID, 'Base', 1 FROM ConfigSettings WHERE Name="paths";
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'data', 'Path to main imaging data directory (e.g. /data/$project/data/) ', 1, 0, 'text', ID, 'Imaging data', 5 FROM ConfigSettings WHERE Name="paths";
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'extLibs', 'Path to external libraries', 1, 0, 'text', ID, 'External libraries', 3 FROM ConfigSettings WHERE Name="paths";
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'mincPath', 'Path to MINC files (e.g. /data/$project/data/)', 1, 0, 'text', ID, 'MINC files', 8 FROM ConfigSettings WHERE Name="paths";
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'DownloadPath', 'Where files are downloaded', 1, 0, 'text', ID, 'Downloads', 4 FROM ConfigSettings WHERE Name="paths";
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'log', 'Path to logs (relative path starting from /var/www/$projectname)', 1, 0, 'text', ID, 'Logs', 2 FROM ConfigSettings WHERE Name="paths";
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'MRICodePath', 'Path to directory where Loris-MRI (git) code is installed', 1, 0, 'text', ID, 'LORIS-MRI code', 6 FROM ConfigSettings WHERE Name="paths";
Expand Down Expand Up @@ -187,9 +185,7 @@ INSERT INTO Config (ConfigID, Value) SELECT ID, "YMd" FROM ConfigSettings WHERE

INSERT INTO Config (ConfigID, Value) SELECT ID, "/data/%PROJECTNAME%/data/" FROM ConfigSettings WHERE Name="imagePath";
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imagePath is in this INSERT statement. I did not need to modify the default path in it which is why it does not show up in the diff, but the INSERT statement is still here :)

INSERT INTO Config (ConfigID, Value) SELECT ID, "%LORISROOT%" FROM ConfigSettings WHERE Name="base";
INSERT INTO Config (ConfigID, Value) SELECT ID, "/data/%PROJECTNAME%/data/" FROM ConfigSettings WHERE Name="data";
INSERT INTO Config (ConfigID, Value) SELECT ID, "/PATH/TO/EXTERNAL/LIBRARY/" FROM ConfigSettings WHERE Name="extLibs";
INSERT INTO Config (ConfigID, Value) SELECT ID, "/data/%PROJECTNAME%/data/" FROM ConfigSettings WHERE Name="mincPath";
INSERT INTO Config (ConfigID, Value) SELECT ID, "%LORISROOT%" FROM ConfigSettings WHERE Name="DownloadPath";
INSERT INTO Config (ConfigID, Value) SELECT ID, "tools/logs/" FROM ConfigSettings WHERE Name="log";
INSERT INTO Config (ConfigID, Value) SELECT ID, "/data/%PROJECTNAME%/bin/mri/" FROM ConfigSettings WHERE Name="MRICodePath";
Expand Down Expand Up @@ -230,7 +226,7 @@ INSERT INTO Config (ConfigID, Value) SELECT ID, "Produced by LorisDB" FROM Confi
INSERT INTO Config (ConfigID, Value) SELECT ID, "S3cret" FROM ConfigSettings WHERE Name="JWTKey";


INSERT INTO Config (ConfigID, Value) SELECT ID, "/PATH/TO/DATA/location" FROM ConfigSettings cs WHERE cs.Name="Loris-MRI Data Directory";
INSERT INTO Config (ConfigID, Value) SELECT ID, "/data/%PROJECTNAME%/data/" FROM ConfigSettings cs WHERE cs.Name="dataDirBasepath";
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@driusan in this line, I modified the default path of dataDirBasepath but I did not add it (the line in red above is for the same config setting)

INSERT INTO Config (ConfigID, Value) SELECT ID, "project" FROM ConfigSettings cs WHERE cs.Name="prefix";
INSERT INTO Config (ConfigID, Value) SELECT ID, "yourname\@example.com" FROM ConfigSettings cs WHERE cs.Name="mail_user";
INSERT INTO Config (ConfigID, Value) SELECT ID, "/PATH/TO/get_dicom_info.pl" FROM ConfigSettings cs WHERE cs.Name="get_dicom_info";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- Remove entries for mincPath and data from the Config table
DELETE
FROM Config
WHERE ConfigID IN (
SELECT ID
FROM ConfigSettings
WHERE Name IN ('mincPath', 'data')
);

-- Remove entries for mincPath and data from the ConfigSettings table
DELETE
FROM ConfigSettings
WHERE Name IN ('mincPath', 'data');
2 changes: 1 addition & 1 deletion htdocs/api/v0.0.2/candidates/visits/images/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ protected function getAssemblyRoot()
{
$factory = \NDB_Factory::singleton();
$config = $factory->Config();
return $config->getSetting("mincPath");
return $config->getSetting("imagePath");
}

/**
Expand Down
2 changes: 1 addition & 1 deletion htdocs/api/v0.0.3-dev/candidates/visits/images/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ protected function getAssemblyRoot()
{
$factory = \NDB_Factory::singleton();
$config = $factory->Config();
return $config->getSetting("mincPath");
return $config->getSetting("imagePath");
}

/**
Expand Down
19 changes: 8 additions & 11 deletions htdocs/mri/jiv/get_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,12 @@

$imagePath = $paths['imagePath'];
$DownloadPath = $paths['DownloadPath'];
$mincPath = $paths['mincPath'];
$tarchivePath = $pipeline['tarchiveLibraryDir'];
// Basic config validation
if (!validConfigPaths(
array(
$imagePath,
$DownloadPath,
$mincPath,
$tarchivePath,
)
)) {
Expand Down Expand Up @@ -90,17 +88,17 @@
$DownloadFilename = '';
switch($FileExt) {
case 'mnc':
$FullPath = $mincPath . '/' . $File;
$FullPath = $imagePath . '/' . $File;
$MimeType = "application/x-minc";
$DownloadFilename = basename($File);
break;
case 'nii':
$FullPath = $mincPath . '/' . $File;
$FullPath = $imagePath . '/' . $File;
$MimeType = "application/x-nifti";
$DownloadFilename = basename($File);
break;
case 'nii.gz':
$FullPath = $mincPath . '/' . $File;
$FullPath = $imagePath . '/' . $File;
$MimeType = "application/x-nifti-gz";
$DownloadFilename = basename($File);
break;
Expand Down Expand Up @@ -190,17 +188,16 @@ function validConfigPaths(array $paths): bool
foreach ($paths as $p) {
if (empty($p)) {
throw new \LorisException(
'Config paths are not initialized. Please ensure that valid ' .
'paths are set for imagePath, downloadPath, mincPath and ' .
'tarchiveLibraryDir'
'Config paths are not initialized. Please ensure that valid paths ' .
'are set for imagePath, downloadPath and tarchiveLibraryDir'
);
return false;
}
if ($p === '/') {
throw new \LorisException(
'Config path invalid. Paths cannot be set to root, i.e., `/`' .
' Please verify your path settings for imagePath, ' .
'downloadPath, mincPath and tarchiveLibraryDir.'
'downloadPath and tarchiveLibraryDir.'
);
return false;
}
Expand All @@ -226,8 +223,8 @@ function validDownloadPath($path): bool
}
// Make sure that the user isn't trying to break out of the $path by
// using a relative filename.
// No need to check for '/' since all downloads are relative to $imagePath,
// $DownloadPath or $mincPath
// No need to check for '/' since all downloads are relative to $imagePath or
// $DownloadPath
if (strpos($path, "..") !== false) {
error_log(
'ERROR: Invalid filename. Contains path traversal characters'
Expand Down
2 changes: 1 addition & 1 deletion modules/brainbrowser/ajax/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function getFileLocation()
{
$config = & NDB_Config::singleton();
$paths = $config->getSetting('paths');
$image_path = $paths['mincPath'];
$image_path = $paths['imagePath'];
return $image_path;
}

Expand Down
1 change: 0 additions & 1 deletion php/installer/Installer.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ class Installer

$this->_updateConfig($DB, "imagePath", $datadir);
$this->_updateConfig($DB, "data", $datadir);
$this->_updateConfig($DB, "mincPath", $datadir);
$this->_updateConfig($DB, "MRICodePath", $datadir);

// Update the host based and URL based on the location that
Expand Down