From e7ccf2ab9b028a3f236eceb5850ad03dfc78d4ad Mon Sep 17 00:00:00 2001 From: vargenau Date: Thu, 12 Apr 2012 14:26:50 +0000 Subject: [PATCH] Viewing wiki documents on FusionForge private projects git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@8264 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- g | 6 ++- view.php | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 view.php diff --git a/g b/g index 6dc7df20f..186eadb08 100644 --- a/g +++ b/g @@ -104,7 +104,11 @@ if (!$group_id || !$project) { define('UPLOAD_FILE_PATH', '/opt/groups/'.WIKI_NAME.'/www/uploads/'); // define('UPLOAD_DATA_PATH', SERVER_URL . '/www/'.WIKI_NAME.'/uploads/'); - define('UPLOAD_DATA_PATH', '/www/'.WIKI_NAME.'/uploads/'); + if ($project->isPublic()) { + define('UPLOAD_DATA_PATH', '/www/'.WIKI_NAME.'/uploads/'); + } else { + define('UPLOAD_DATA_PATH', '/wiki/view.php/'.WIKI_NAME.'/uploads/'); + } // Do not use a directory per user but only one (per project) define('UPLOAD_USERDIR', false); diff --git a/view.php b/view.php new file mode 100644 index 000000000..bf4bb0b4e --- /dev/null +++ b/view.php @@ -0,0 +1,111 @@ +usesPlugin("wiki"))) { + exit_disabled('home'); +} + +// If project is private, check membership. +if (!$project->isPublic()) { + session_require_perm('project_read', $project->getID()); +} + +$arr = explode('/', urldecode(getStringFromServer('REQUEST_URI'))); +array_shift($arr); +array_shift($arr); +array_shift($arr); +array_shift($arr); +array_shift($arr); +$path = join('/', $arr); + +$basepath = realpath('/opt/groups/'.$project->getUnixName().'/www/uploads/'); +$filepath = realpath($basepath.'/'.$path); +$filename = basename($filepath); + +if (strncmp($basepath, $filepath, strlen($basepath)) !== 0) { + error_log("DEBUG: basepath=$basepath, filepath=$filepath"); + exit_error('Invalid path: No access'); +} + +if ($filepath && is_file($filepath)) { + if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) { + # workaround for IE filename bug with multiple periods/ multiple dots in filename + # that adds square brackets to filename - eg. setup.abc.exe becomes setup[1].abc.exe + $filename = preg_replace('/\./', '%2e', $filename, substr_count($filename, '.') - 1); + } + $filename = str_replace('"', '', $filename); + header('Content-disposition: filename="'.$filename.'"'); + + if (function_exists('finfo_open')) { + $finfo = finfo_open(FILEINFO_MIME_TYPE); + $mimetype = finfo_file($finfo, $filepath); + } else { + $mimetype = 'application/octet-stream'; + } + header("Content-type: $mimetype"); + + $length = filesize($filepath); + header("Content-length: $length"); + + readfile_chunked($filepath); + +} else { + header("HTTP/1.0 404 Not Found"); + require_once $gfwww.'404.php'; +} + +// Local Variables: +// mode: php +// c-file-style: "bsd" +// End: + +?> -- 2.45.0