-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathindex.php
124 lines (110 loc) · 3.54 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
<?php
#
# Web Interface for MDTest
#
# MDTest Web Interface
# Copyright (c) 2007 Michel Fortin
# <http://michelf.ca/>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
$impl = isset($_GET['impl']) ? $_GET['impl'] : "l-markdown.php";
$raw = isset($_GET['raw']);
$diff = isset($_GET['diff']);
header("Content-Type: text/html; charset=utf-8");
?>
<!DOCTYPE html>
<html>
<head>
<title>MDTest</title>
<style>
body { font-family: Palatino, "Palatino Linotype", serif; margin: 1ex 1em; }
form { background: #eed; margin: -1ex -1em 0 -1em; padding: 1ex 1em; }
h1 { font-style: italic; }
label { font: 80% "Lucida Grande", Tahoma, sans-serif; margin-right: 1em; }
input[type=submit] { min-width: 4em; }
</style>
</head>
<body>
<form>
<div>
<label>Implementation:
<select name="impl">
<?php
$all_options = array();
$files = glob(dirname(__FILE__). "/Implementations/*");
foreach ($files as $file) {
$name = htmlspecialchars(basename($file));
if (is_executable($file) && !is_dir($file) && substr($file, -4, 4) != '.php') {
// Script
$value = "s-$name";
$all_options[] = $value;
} else if (!is_dir($file) && substr($file, -4, 4) == '.php') {
// PHP Lib
$value = "l-$name";
$all_options[] = $value;
} else if (!is_dir($file) && substr($file, -8, 8) == '.phpcall') {
// PHP Call
$funcname = file_get_contents($file);
$value = "f-$funcname";
$all_options[] = $value;
} else {
continue;
}
$selected = $impl == $value;
if ($selected) $selected = " selected";
echo "\t\t\t<option value=\"$value\"$selected>$name</option>\n";
}
?>
</select>
</label>
<label><input type="checkbox" name="raw"<?php echo isset($_GET['raw']) ? " checked" : "" ?> /> Compare raw output</label>
<label><input type="checkbox" name="diff"<?php echo isset($_GET['diff']) ? " checked" : "" ?> /> Show diff</label>
<input type="submit" value="Test">
</div>
</form>
<h1>MDTest Results</h1>
<pre><?php
$options = "";
# Checking that value of $impl is in $all_options to protect against
# function call injection attacks.
if ($impl && array_search($impl, $all_options) !== FALSE) {
if ($impl{0} == 'f') {
$impl_arg = escapeshellarg(substr($impl, 2));
$options .= "-f $impl_arg";
} else {
$impl_arg = escapeshellarg(
dirname(__FILE__). "/Implementations/". substr($impl, 2));
if ($impl{0} == 's') {
$options .= "-s $impl_arg";
} else if ($impl{0} == 'l') {
$options .= "-l $impl_arg";
} else if ($impl{0} == 'f') {
$options .= "-f $impl_arg";
}
}
}
if ($diff) $options .= " -d";
if ($raw) $options .= " -r";
ob_start('htmlspecialchars', 64);
system("'". dirname(__FILE__). "/mdtest.php' $options");
ob_end_flush();
?></pre>
<p><small>MDTest<br />
Copyright © 2007-2013 <a href="http://michelf.ca/">Michel Fortin</a></small></p>
<p><small>Derived from Markdown Test<br />
Copyright © 2004 <a href="http://daringfireball.net/">John Gruber</a></small></p>
</body>
</html>