-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
232 lines (197 loc) · 8.34 KB
/
index.php
File metadata and controls
232 lines (197 loc) · 8.34 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="assets/images/favicon.ico">
<title>PHP Object Browser</title>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/css/bootstrap.min.css">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/jstree/3.1.0/themes/default/style.min.css" />
<link rel="stylesheet" href="assets/css/object-browser.css" />
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="//oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="//oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<a href="https://github.com/jasonhinkle/php-object-browser"><img style="z-index: 9999; position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/a6677b08c955af8400f44c6298f40e7d19cc5b2d/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677261795f3664366436642e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png"></a>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="./"><i class="fa fa-cube"></i> PHP Object Browser</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="./">Browser</a></li>
<li><a href="instructions.php">Instructions</a></li>
<li><a href="credits.php">Credits</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<main class="container">
<?php
if (is_file('includes.php') && is_readable('includes.php')) {
require_once 'includes.php';
echo '<div class="alert alert-info"><i class="fa fa-info-circle"></i> Class definitions from includes.php loaded.</div>';
}
define('RECURSION_SANITY_LIMIT',25);
define('BASE_URL', str_replace('index.php', '', full_url($_SERVER)));
error_reporting(E_ALL & ~E_NOTICE);
$PARSED_OBJS = array();
$data = isset($_POST['data']) ? $_POST['data'] : '';
if ($data) {
$obj = unserialize($data);
if ($obj) {
echo '<div id="ajax-loader"><i class="fa fa-cog fa-spin fa-5x"></i></div>';
echo "<div id='tree-1' style='display: none;'>\n<ul>\n";
recurse_var("", $obj);
echo "<ul>\n</div>\n";
}
else {
echo '<div class="alert alert-danger"><strong>Error:</strong> The string could not be unserialized.</div>';
}
}
else {
echo '<div id="form-container">
<form action="index.php" method="post">
<h3>PHP Object To Inspect:</h3>
<p id="data-container"><textarea class="form-control" name="data" id="data" placeholder="Copy/paste serialized PHP code here"></textarea></p>
<p id="submit-container"><input class="btn btn-primary" type="submit" value="Let\'s Do This..."></p>
</form>
</div>
';
}
/**
*
* @param string $varname a name for the value being recursed
* @param mixed $value the value to recurse
* @param string $path string representation of the object path
* @param int $level number of levels deep into the recursion
*/
function recurse_var($varname, &$value, $path = '/', $level = 0)
{
global $PARSED_OBJS;
$classname = @get_class($value);
$is_incomplete_class = $classname == '__PHP_Incomplete_Class';
$is_object = is_object($value) || $is_incomplete_class;
$is_array = is_array($value);
$icon = 'value.png';
$cache_key = md5(print_r($value,true));
if (($is_object || $is_array) && $level > RECURSION_SANITY_LIMIT) {
$icon = $is_object ? 'object.png' : 'array.png';
$value = "!!! RECURSION LIMIT !!!";
$is_array = false;
$is_object = false;
}
if (($is_object) && array_key_exists($cache_key,$PARSED_OBJS)) {
$icon = 'object.png';
$value = "DUP OF ".$PARSED_OBJS[$cache_key]."";
$is_array = false;
$is_object = false;
}
// ensure var is encoded properly
$varname = htmlentities($varname);
if ($is_object) {
$icon = 'object.png';
// do this to make the property class type visible
if ($is_incomplete_class) {
// can't access "__PHP_Incomplete_Class_Name" directly so we have to enumerate properties
$innerVars = get_object_vars($value);
foreach ($innerVars as $innerVar => $innerVal) {
if ($innerVar == '__PHP_Incomplete_Class_Name') {
$classname = $innerVal;
break;
}
}
}
$styleClass = $level == 0 ? "jstree-open" : "";
echo "<li class='$styleClass' data-jstree='{\"icon\":\"".BASE_URL."assets/images/$icon\"}'><strong>$varname</strong> ($classname)\n";
echo "<ul>\n";
$innerVars = get_object_vars($value);
foreach ($innerVars as $innerVar => $innerVal) {
recurse_var($innerVar, $innerVal, $path . $innerVar . '/', $level + 1);
}
$methods = get_class_methods($value);
foreach ($methods as $method) {
echo "<li data-jstree='{\"icon\":\"".BASE_URL."assets/images/function.png\"}'><strong>$method</strong> (Function)\n";
}
echo "</ul></li>\n";
}
elseif ($is_array) {
$icon = 'array.png';
$styleClass = $level == 0 ? "jstree-open" : "";
//echo "<li class='$styleClass'><strong>$varname</strong> (Array)";
echo "<li class='$styleClass' data-jstree='{\"icon\":\"".BASE_URL."assets/images/$icon\"}'><strong>$varname</strong> (Array)";
echo "<ul>\n";
foreach ($value as $innerVar => $innerVal) {
recurse_var($innerVar, $innerVal, $path . $innerVar . '/', $level + 1);
}
echo "</ul></li>\n";
}
else {
if ($varname != '__PHP_Incomplete_Class_Name')
echo "<li data-jstree='{\"icon\":\"".BASE_URL."assets/images/$icon\"}'><strong>$varname</strong> = " . (is_string($value) ? '"' . htmlentities($value) . '"' : $value) . "</li>\n";
}
// if (!array_key_exists($cache_key,$PARSED_OBJS)) // this sometimes makes things even more weird
$PARSED_OBJS[$cache_key] = $path;
}
/**
* @param array $_SERVER
* @param bool $use_forwarded_host may need to be set to true if behind a load balancer
* @return string
*/
function url_origin($s, $use_forwarded_host=false)
{
$ssl = (!empty($s['HTTPS']) && $s['HTTPS'] == 'on') ? true:false;
$sp = strtolower($s['SERVER_PROTOCOL']);
$protocol = substr($sp, 0, strpos($sp, '/')) . (($ssl) ? 's' : '');
$port = $s['SERVER_PORT'];
$port = ((!$ssl && $port=='80') || ($ssl && $port=='443')) ? '' : ':'.$port;
$host = ($use_forwarded_host && isset($s['HTTP_X_FORWARDED_HOST'])) ? $s['HTTP_X_FORWARDED_HOST'] : (isset($s['HTTP_HOST']) ? $s['HTTP_HOST'] : null);
$host = isset($host) ? $host : $s['SERVER_NAME'] . $port;
return $protocol . '://' . $host;
}
/**
* @param array $_SERVER
* @param bool $use_forwarded_host may need to be set to true if behind a load balancer
* @return string
*/
function full_url($s, $use_forwarded_host=false)
{
return url_origin($s, $use_forwarded_host) . $s['REQUEST_URI'];
}
?>
<p class="top-buffer text-danger"><strong><i class="fa fa-exclamation-triangle"></i> Warning:</strong> This utility may possibly be used to
run untrusted code. Do not leave it installed on an unprotected public server.
<a href="http://php.net/manual/en/function.unserialize.php">More info...</a></p>
</main>
<footer class="footer">
<div class="container">
<div class="text-muted">Created out of spite by <a href="http://verysimple.com/">Jason Hinkle</a></div>
</div>
</footer>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jstree/3.1.0/jstree.min.js"></script>
<script>
$(document).ready(function(){
$('#tree-1').jstree();
$('#ajax-loader').hide();
$('#tree-1').show();
});
</script>
</body>
</html>