blob: cfe005e9369794ed6c4c7bbe20cee99530e8142c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
<?php
/**
* Image download authorisation script
*
* To use, in LocalSettings.php set $wgUploadDirectory to point to a non-public
* directory, and $wgUploadPath to point to this file. Also set $wgWhitelistRead
* to an array of pages you want everyone to be able to access. Your server must
* support PATH_INFO, CGI-based configurations generally don't.
*/
require_once( './includes/WebStart.php' );
wfProfileIn( 'img_auth.php' );
require_once( './includes/StreamFile.php' );
if( !isset( $_SERVER['PATH_INFO'] ) ) {
wfForbidden();
}
# Get filenames/directories
$filename = realpath( $wgUploadDirectory . $_SERVER['PATH_INFO'] );
$realUploadDirectory = realpath( $wgUploadDirectory );
$imageName = $wgContLang->getNsText( NS_IMAGE ) . ":" . wfBaseName( $_SERVER['PATH_INFO'] );
# Check if the filename is in the correct directory
if ( substr( $filename, 0, strlen( $realUploadDirectory ) ) != $realUploadDirectory ) {
wfForbidden();
}
if ( is_array( $wgWhitelistRead ) && !in_array( $imageName, $wgWhitelistRead ) && !$wgUser->getID() ) {
wfForbidden();
}
if( !file_exists( $filename ) ) {
wfForbidden();
}
if( is_dir( $filename ) ) {
wfForbidden();
}
# Write file
wfStreamFile( $filename );
wfLogProfilingData();
function wfForbidden() {
header( 'HTTP/1.0 403 Forbidden' );
print
"<html><body>
<h1>Access denied</h1>
<p>You need to log in to access files on this server</p>
</body></html>";
wfLogProfilingData();
exit;
}
?>
|