forked from open-mpi/mtt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
205 lines (173 loc) · 4.18 KB
/
index.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
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
<?php
#
# Copyright (c) 2006 Sun Microsystems, Inc.
# All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
#########################
# Web-based MTT Reporter
#########################
#
# Basic configuration
#
$topdir = ".";
if (file_exists("$topdir/config.inc")) {
include_once("$topdir/config.inc");
}
#
# Set PHP trace levels
#
if (isset($_GET['verbose']) or isset($_GET['debug'])) {
error_reporting(E_ALL);
} else {
error_reporting(E_ERROR | E_PARSE);
}
#
# Includes
#
include_once("$topdir/database.inc");
include_once("$topdir/reporter/util.inc");
include_once("$topdir/reporter/db_iface.inc");
include_once("$topdir/reporter/reporter.inc");
include_once("$topdir/reporter/dashboard.inc");
include_once("$topdir/reporter/main_reporter.inc");
#
# 'debug' is an aggregate trace
#
if (isset($_GET['debug'])) {
$_GET['verbose'] = 'on';
$_GET['dev'] = 'on';
$_GET['cgi'] = 'on';
}
#
# 'stats' and 'explain' would not make sense without 'sql'
#
if (isset($_GET['stats']) or
isset($_GET['explain']) or
isset($_GET['analyze'])) {
$_GET['sql'] = '2';
}
#
# In case we are using this script from the command-line
#
if ($argv) {
$_GET = getoptions($argv);
}
#
# Create or redirect to a permalink
# Neither of these return
#
$do_redir = $_GET['do_redir'];
$make_redir = $_GET['make_redir'];
if (! is_null($do_redir)) {
do_redir($do_redir);
exit;
}
elseif (! is_null($make_redir)) {
make_redir($_GET);
exit;
}
#
# Increase the memory limit for PHP so it can handle larger queries.
# This is a work around for bug #62
#
ini_set("memory_limit","64M");
#
# Keep track of time
#
$start = gettimeofday();
$start = $start['sec'] + ($start['usec'] / 1000000.0);
#
# Track time elapsed for sql
#
$global_sql_time_elapsed = 0;
#
# Display a query screen and report
#
display_report();
#
# Report on script's execution time
#
$finish = gettimeofday();
$finish = $finish['sec'] + ($finish['usec'] / 1000000.0);
$elapsed = $finish - $start;
#
# Display input parameters
#
debug_cgi($_GET, "GET " . __LINE__);
#
# Display cookie parameters
#
debug_cgi($_COOKIE, "COOKIE " . __LINE__);
#
# Footer
#
print hidden_carryover($_GET) ."\n".
"<hr></form>\n".
"<p> Time: ".round($elapsed,3)." sec. ".
"(PHP: " .round(($elapsed - $global_sql_time_elapsed), 3)." /".
" SQL: " .round($global_sql_time_elapsed,3).")<br>\n".
"$mtt_body_html_suffix\n".
"</body></html>";
exit;
#
# Create a tiny URL permalink (using the current URL), and exit
#
function make_redir($params) {
unset($params["make_redir"]);
unset($params["do_redir"]);
$qstring = arr2qstring($params);
$domain = $_SERVER['SERVER_NAME'];
$script = $_SERVER['SCRIPT_NAME'];
$url = "http://$domain$script?$qstring";
# Create tiny URLs for the permalinks
$query = "SELECT permalink_id FROM permalinks WHERE permalink = '$url'";
$id = select_scalar($query);
if (is_null($id)) {
$query = "SELECT nextval('permalinks_permalink_id_seq')";
$id = select_scalar($query);
$insert =
"INSERT INTO " .
"permalinks (permalink_id, permalink) " .
"VALUES ('$id', '$url');";
do_pg_query($insert);
}
$tinyurl = "http://$domain$script?do_redir=$id";
# Print tiny link in a tiny window
$t = 50;
print "<html>\n" . display_header("Tiny link") .
"<body>
<div align=center>
<p>The original permalink was " . strlen($url) . " chars long.
Here's a tiny link that is only $t chars long:</p>
<p><form name=url_form><code>
<input type=text name=url value='$tinyurl' size=$t
onFocus=\"this.value='$tinyurl';\" readonly>
</code>
</form></p>
<script language='javascript' type='text/javascript'>
document.url_form.url.focus();
document.url_form.url.select();
</script>
<p><form>
<input type=button value='Close this window' onClick='javascript:window.close();'>
</form></p>
</div>
</body>
</html>";
exit;
}
#
# Redirect the browser to the permalink shortcut
#
function do_redir($id) {
$query = "SELECT permalink FROM permalinks WHERE permalink_id = '$id'";
$url = select_scalar($query);
header("Location: $url");
exit;
}
?>