-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
viewsource.php
58 lines (57 loc) · 1.52 KB
/
viewsource.php
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
55
56
57
58
<?php
/* License
viewsource.php - v1.0.1
GNU Lesser General Public License
http://www.gnu.org/licenses/lgpl.html
Author: Elijah Grey - www.eligrey.com
*/
if ( isset($_GET['file']) && $_GET['file'] != '' )
{
if ( isset($_GET['name']) ) {
$filename = $_GET['name'];
}
$file = $_GET['file'];
$file = preg_replace('/[\?#].*$/', '', (preg_replace('/^((.+:\/\/)([a-zA-Z\d\-\.]+)(:\d+)?)?[\.\/]*(\.\.*\/)*(.*)/', '$6', stripslashes($file))));
if ( !isset($filename) ) {
$filename = basename($file);
}
if ( is_file('./'.$file) )
{
header("Content-Type: text/plain");
header("content-disposition: inline; filename=\"".preg_replace('/\.txt$/','',$filename).".txt\"");
header("Content-Length: ".filesize('./'.$file));
flush();
echo file_get_contents('./'.$file);
}
else {
header("HTTP/1.1 404 Not Found");
header("Content-Type: text/plain");
echo "File not found.";
}
}
else { ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>View Source</title>
<style type="text/css">
/*<![CDATA[*/
input[type="text"] {
width: 90%;
}
input[type="submit"] {
width: 20px;
}
/*]]>*/
</style>
</head>
<body>
<p>Use this form to view the source of a file from <?php echo $_SERVER['HTTP_HOST']; ?></p>
<div>
<form method="get" action="./viewsource.php">
<div><label for="file">File: </label><input type="text" name="file" id="file" /><input type="submit" value="›" /></div>
</form>
</div>
</body>
</html>
<?php } ?>