Multidir Filecache

This commit is contained in:
seiichiro 2022-01-11 17:14:35 +01:00
parent d8cbfea8f4
commit 823b330b99
2 changed files with 6 additions and 14 deletions

View file

@ -22,6 +22,6 @@ $conf['defpage'] = 1;
// Images per Page if not specified // Images per Page if not specified
$conf['defslice'] = 34; $conf['defslice'] = 34;
// Default Subdirectory if none given // Default Subdirectory if none given
$conf['defdir'] = ''; $conf['defdir'] = '/';
?> ?>

View file

@ -32,21 +32,14 @@ session_start();
$t = new Thumb(Helpers::end_dir($imagedir.$dir), $thumbdir, 200, 200); $t = new Thumb(Helpers::end_dir($imagedir.$dir), $thumbdir, 200, 200);
// Filelist Cache Handling // Filelist Cache Handling
if (isset($_SESSION['files']) if (isset($_SESSION[$dir])
&& $_SESSION['dir'] == $dir && (time() - $_SESSION[$dir]['t']) < $conf['flcache']
&& (time() - $_SESSION['cachetime']) < $conf['flcache']
&& !isset($_GET['refcache'])) && !isset($_GET['refcache']))
{ {
$files = $_SESSION['files']; $files = $_SESSION[$dir]['f'];
} else { } else {
$r_imagedir = realpath($imagedir.$dir); $r_imagedir = realpath($imagedir.$dir);
if ($r_imagedir === false || strpos(Helpers::end_dir($r_imagedir), $r_basedir.DIRECTORY_SEPARATOR) !== 0) { if ($r_imagedir === false || strpos(Helpers::end_dir($r_imagedir), $r_basedir.DIRECTORY_SEPARATOR) !== 0) {
print_r($r_basedir);
print_r($r_imagedir);
print "Path Traversal Detected!"; print "Path Traversal Detected!";
exit(); exit();
} }
@ -59,9 +52,8 @@ if (isset($_SESSION['files'])
$rmdirs[] = '.'; $rmdirs[] = '.';
$rmdirs[] = '..'; $rmdirs[] = '..';
$files = array_diff(scandir($imagedir.$dir, SCANDIR_SORT_DESCENDING), $rmdirs); $files = array_diff(scandir($imagedir.$dir, SCANDIR_SORT_DESCENDING), $rmdirs);
$_SESSION['files'] = $files; $_SESSION[$dir]['f'] = $files;
$_SESSION['dir'] = $dir; $_SESSION[$dir]['t'] = time();
$_SESSION['cachetime'] = time();
} }
// Apply Filters to Filelist // Apply Filters to Filelist