forked from VisualPHPUnit/VisualPHPUnit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
177 lines (154 loc) · 6.35 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
<?php
/* VisualPHPUnit
*
* Copyright (c) 2011, Nick Sinopoli <[email protected]>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Nick Sinopoli nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
require 'config.php';
// Helper functions
function get_snapshots() {
$results = array();
$handler = opendir(SNAPSHOT_DIRECTORY);
while ( $file = readdir($handler) ) {
if ( strpos($file, '.') !== 0 && strtolower(pathinfo($file, PATHINFO_EXTENSION)) == 'html' ) {
$results[] = $file;
}
}
closedir($handler);
rsort($results);
return $results;
}
// AJAX calls
if ( isset($_GET['dir']) ) {
if ( !file_exists($_GET['dir']) ) {
if ( $_GET['type'] == 'dir' ) {
echo 'Directory does not exist!';
} else {
echo 'File does not exist!';
}
} elseif ( !is_writable($_GET['dir']) ) {
if ( $_GET['type'] == 'dir' ) {
echo 'Directory is not writable! (Check permissions.)';
} else {
echo 'File is not writable! (Check permissions.)';
}
} else {
echo 'OK';
}
exit;
} elseif ( isset($_GET['snapshots']) && $_GET['snapshots'] == '1' ) {
$results = get_snapshots();
echo json_encode($results);
exit;
}
if ( empty($_POST) ) {
$results = get_snapshots();
include 'ui/index.html';
exit;
}
// Archives
if ( isset($_POST['view_snapshot']) && $_POST['view_snapshot'] == 1 ) {
$dir = realpath(SNAPSHOT_DIRECTORY) . '/';
$snapshot = realpath($dir . trim(strval(filter_var($_POST['select_snapshot'], FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES))));
ob_start();
include $snapshot;
$content = ob_get_contents();
ob_end_clean();
echo $content;
exit;
}
require 'lib/VPU.php';
$vpu = new VPU();
// Graphs
if ( isset($_POST['graph_type']) ) {
$graph_type = trim(strval(filter_var($_POST['graph_type'], FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES)));
$time_frame = trim(strval(filter_var($_POST['time_frame'], FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES)));
$start_date = trim(strval(filter_var($_POST['start_date'], FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES)));
$end_date = trim(strval(filter_var($_POST['end_date'], FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES)));
require 'lib/PDO_MySQL.php';
$config = array(
'database' => DATABASE_NAME,
'host' => DATABASE_HOST,
'port' => DATABASE_PORT,
'username' => DATABASE_USER,
'password' => DATABASE_PASS
);
$db = new PDO_MySQL($config);
echo $vpu->build_graph($graph_type, $time_frame, $start_date, $end_date, $db);
exit;
}
// Tests
// Sanitize all the $_POST data
$store_statistics = (boolean) filter_var($_POST['store_statistics'], FILTER_SANITIZE_NUMBER_INT);
$create_snapshots = (boolean) filter_var($_POST['create_snapshots'], FILTER_SANITIZE_NUMBER_INT);
$snapshot_directory = trim(strval(filter_var($_POST['snapshot_directory'], FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES)));
$sandbox_errors = (boolean) filter_var($_POST['sandbox_errors'], FILTER_SANITIZE_NUMBER_INT);
$sandbox_filename = trim(strval(filter_var($_POST['sandbox_filename'], FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES)));
if ( isset($_POST['sandbox_ignore']) && !empty($_POST['sandbox_ignore']) ) {
$sandbox_ignore = array();
foreach ( $_POST['sandbox_ignore'] as $ignore ) {
$sandbox_ignore[] = trim(strval(filter_var($ignore, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES)));
}
$sandbox_ignore = implode('|', $sandbox_ignore);
} else {
$sandbox_ignore = '';
}
$test_files = trim(strval(filter_var($_POST['test_files'], FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES)));
$tests = explode('|', $test_files);
ob_start();
if ( $sandbox_errors ) {
set_error_handler(array($vpu, 'handle_errors'));
}
$results = $vpu->run($tests);
if ( $store_statistics ) {
require 'lib/PDO_MySQL.php';
$config = array(
'database' => DATABASE_NAME,
'host' => DATABASE_HOST,
'port' => DATABASE_PORT,
'username' => DATABASE_USER,
'password' => DATABASE_PASS
);
$db = new PDO_MySQL($config);
$vpu->save_results($results, $db);
}
ob_start();
include 'ui/header.html';
echo $vpu->to_HTML($results, $sandbox_errors);
$content = ob_get_contents();
ob_end_clean();
echo $content;
if ( $create_snapshots ) {
$snapshot = ob_get_contents();
$vpu->create_snapshot($snapshot, $snapshot_directory);
}
?>