forked from catchpoint/WebPageTest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_browsers.php
More file actions
150 lines (146 loc) · 5.67 KB
/
Copy pathcustom_browsers.php
File metadata and controls
150 lines (146 loc) · 5.67 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
<?php
$debug = true;
include 'common.inc';
if (!$admin) {
header('HTTP/1.0 403 Forbidden');
exit;
}
if (isset($_REQUEST['name']) && isset($_FILES['apk']['tmp_name']) && isset($_FILES['apk']['name'])) {
$lock = Lock('BrowserUpload', true, 30);
if ($lock) {
$valid = false;
$is_chromium_chrome = false;
$uploadResult = 'Error processing ' . htmlspecialchars($_FILES['apk']['name']);
$zip = new ZipArchive();
if ($zip->open($_FILES['apk']['tmp_name'])) {
if ($zip->statName('assets/chrome_100_percent.pak') !== false) {
$is_chromium_chrome = true;
}
if ($is_chromium_chrome || $zip->statName('assets/content_shell.pak') !== false) {
$name = $_REQUEST['name'];
if (preg_match('/[a-zA-Z0-9_\-]+/', $name)) {
if (!is_file("./browsers/$name.apk")) {
$valid = true;
} else {
$uploadResult = "ERROR: A browser named $name already exists";
}
} else {
$uploadResult = 'ERROR: Invalid browser name: ' . htmlspecialchars($name);
}
}
$zip->close();
}
if ($valid) {
if (move_uploaded_file($_FILES['apk']['tmp_name'], "./browsers/$name.apk")) {
$apk_settings = $is_chromium_chrome
// Chrome public
? array( 'package' => 'org.chromium.chrome',
'activity' => 'com.google.android.apps.chrome.Main',
'flagsFile' => '/data/local/chrome-command-line',
'socket' => 'localabstract:chrome_devtools_remote')
// content shell
: array( 'package' => 'org.chromium.content_shell_apk',
'activity' => 'org.chromium.content_shell_apk.ContentShellActivity',
'flagsFile' => '/data/local/tmp/content-shell-command-line',
'socket' => 'localabstract:content_shell_devtools_remote');
file_put_contents("./browsers/$name.json", json_encode($apk_settings));
$md5 = md5_file("./browsers/$name.apk");
if ($md5 !== false) {
$md5 = strtoupper($md5);
$browsers = @file_get_contents('./browsers/browsers.ini');
if (!$browsers || !strlen($browsers))
$browsers = "[browsers]";
$browsers .= "\n$name=$md5";
file_put_contents('./browsers/browsers.ini', $browsers);
$uploadResult = "Custom APK added: $name";
} else {
$uploadResult = "Error calculating md5";
unlink("./browsers/$name.apk");
unlink("./browsers/$name.json");
}
}
}
Unlock($lock);
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>WebPagetest - Custom Browsers</title>
<meta http-equiv="charset" content="iso-8859-1">
<meta name="keywords" content="Performance, Optimization, Pagetest, Page Design, performance site web, internet performance, website performance, web applications testing, web application performance, Internet Tools, Web Development, Open Source, http viewer, debugger, http sniffer, ssl, monitor, http header, http header viewer">
<meta name="description" content="Speed up the performance of your web pages with an automated analysis">
<meta name="author" content="Patrick Meenan">
<?php include ('head.inc'); ?>
<style type="text/css">
.browsers td {
text-align: left !important;
padding-right: 20px !important;
}
.browsers {
margin-left: 0 !important;
}
</style>
</head>
<body>
<div class="page">
<?php
$tab = 'custom';
include 'header.inc';
?>
<div class="translucent">
<?php
if (isset($uploadResult)) {
echo $uploadResult;
}
?>
<h2>Upload Custom Android Build</h2>
Upload an <a href="https://code.google.com/p/chromium/wiki/AndroidBuildInstructions">Android Content Shell or Chrome public apk</a> (content_shell_apk or chrome_public_apk build target).
<form name="upload" method="POST" action="custom_browsers.php" enctype="multipart/form-data">
<br>
<label for="name">
Friendly Name
</label>
<input type="text" name="name" id="name" size="40"> <small>(Alpha-numeric, underscores, dashes, no spaces)</small><br><br>
<label for="apk">
APK File
</label>
<input type="file" name="apk" id="apk" size="40" accept=".apk">
<input type="submit" value="Upload">
</form>
<h2>Available Android Browsers</h2>
<?php
DisplayBrowsers('apk');
?>
<h2>Available Desktop Browsers</h2>
<?php
DisplayBrowsers('zip');
?>
</div>
<?php include('footer.inc'); ?>
</div>
</body>
</html>
<?php
function DisplayBrowsers($ext) {
$browsers = array();
$files = glob("./browsers/*.$ext");
foreach ($files as $file) {
$name = basename($file, ".$ext");
$browsers[$name] = filemtime($file);
}
if (count($browsers)) {
arsort($browsers);
echo '<table class="pretty browsers"><tr><th>Browser</th><th>Uploaded</th></tr>';
foreach($browsers as $name => $time) {
echo '<tr><td>';
echo htmlspecialchars($name);
echo '</td><td>';
echo date('M j, Y h:i a', $time) . ' GMT';
echo '</td></tr>';
}
echo '</table>';
}
}
?>