-
Notifications
You must be signed in to change notification settings - Fork 4
/
bugSelector.php
190 lines (169 loc) · 5.09 KB
/
bugSelector.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
<?php
//Set no caching
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
include("include.php");
?>
<html>
<head>
<title>RPITS Bug Selector</title>
<script src="js/lib/jquery-1.8.3.js" type="text/javascript"></script>
<style>
img {
width: 500px;
border: 1px solid black;
margin: 0 auto;
background-color: #eee;
background-image: linear-gradient(45deg, lightgray 25%, transparent 25%, transparent 75%, lightgray 75%, lightgray),
linear-gradient(45deg, lightgray 25%, transparent 25%, transparent 75%, lightgray 75%, lightgray);
background-size:20px 20px;
background-position:0 0, 30px 30px;
border: 8px solid rgba(0, 0, 0, .5);
}
.bugBox {
display: inline-block;
width: 520px;
margin-top: 10px;
text-align: center;
}
.bugBox .words {
width: 502px;
margin: 0 auto;
text-align: left;
}
#allBugs {
clear: both;
}
</style>
</head>
<body>
<h1>RPITS Bug Selector</h1>
<hr>
<?php
$setVal = $_GET['setBug'];
if ($_GET['setBug'] != "") {
$setVal = $_GET['setBug'];
}
$delVal = "";
if ($_GET['deleteBug'] != "") {
$delVal = $_GET['deleteBug'];
}
//delete file and auto go back
if ($delVal != "") {
unlink($delVal);
echo "<script type ='text/javascript'> javascript:history.go(-1) </script>";
}
//set the bug and auto go back
if ($setVal != "") {
#do_post_request("http://ip6-localhost:3005/key", file_get_contents($setVal));
do_post_request("http://localhost:3005/key", file_get_contents($setVal));
echo "<script type ='text/javascript'> javascript:history.go(-1) </script>";
}
?>
<div id="currentBug" class="bugBox"></div>
<script type="text/javascript">
$(document).ready( function() {
$("#currentBug").html('<img id="current" src="loadCurrentBug.php?n="' + Math.random() + '"/><br>Current Bug');
});
</script>
<?php
$bug_state_json = @file_get_contents($bug_keyer_url . 'state');
if ($bug_state_json !== FALSE) {
$bug_info = json_decode($bug_state_json);
if ($bug_info->state === 'up') { // show if bug is LIVE
?>
<script type="text/javascript">
$(document).ready( function() {
$('#current').css('border', '8px solid red');
});
</script>
<?php
}
}
?>
</div>
<hr>
<div id="allBugs">
<?php
function console_log($output, $with_script_tags = true) {
$js_code = 'console.log(' . json_encode($output, JSON_HEX_TAG) .
');';
if ($with_script_tags) {
$js_code = '<script>' . $js_code . '</script>';
}
echo $js_code;
}
//display all images in folder
$dirname = dirname(__FILENAME__) . '/bugs/';
$images = glob($dirname."*");
foreach($images as $image) {
echo '<div class="bugBox"><img src="'.$image.'" /><br>';
echo substr($image, strrpos($image, "/") + 1, 99);
echo "<br>";
//use this bug link
echo '<div class="words"><a href=" ' .$_SERVER['REQUEST_URI']. "?setBug=" .$image. ' ">Use This Bug</a> <br>';
//hard coded to not allow deletion of bug.png
if (substr($image, strrpos($image, "/") + 1, 99) == "bug.png") {
echo '<br>'; //don't include delete bug link
} else {
echo '<a href=" ' .$_SERVER['REQUEST_URI']. "?deleteBug=" .$image. ' " onclick="return confirm(\'Are you sure you want to delete this file?\')">Delete This Bug</a> <br>';
}
//line
echo '</div></div>';
}
//perform post request to the keyer
function do_post_request($url, $data, $optional_headers = null) {
console_log($url);
$params = array('http' => array('method' => 'POST','content' => $data));
if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
#$fp = @fopen($url, 'rb');
if (!$fp) {
//throw new Exception("Problem with $url, $php_errormsg <br>");
console_log(error_get_last());
}
if ($http_response_header[0] == "HTTP/1.1 503 Service Unavailable") {
echo "Error 503";
}
$response = @stream_get_contents($fp);
console_log($response);
if ($response === false) {
//throw new Exception("Problem reading data from $url, $php_errormsg <br>");
}
echo "done";
return $response;
}
?>
</div>
<hr>
<p>Upload another png to be used as a bug...</p>
<script>
window.onload = function() {
//this is all upload file stuff
var url = document.URL.substring(0, document.URL.lastIndexOf("/")) + "/upload_file.php";
//when the document is finished loading, replace everything
//between the <a ...> </a> tags with the setValue of splitText
document.getElementById("myurl").action=url;
}
</script>
<form id="myurl" action="" method="post" enctype="multipart/form-data">
<input type="hidden" name="url" id="url" setValue="" />
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" setValue="Submit">
<hr>
<p></p>
<p></p>
</form>
<script>
document.getElementById("url").setValue = document.URL;
console.log(document.URL);
</script>
</body>
</html>