-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsleep.php
150 lines (136 loc) · 4.41 KB
/
sleep.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
<?php
// This php script is inspired by sleep.cgi which created by Steve Souders (http://stevesouders.com/hpws/sleep.txt)
if(isset($_GET['sleep']) && $_GET['sleep'] > 0) {
sleep($_GET['sleep']);
}
// come from http://bavotasan.com/2011/convert-hex-color-to-rgb-using-php/
function hex2rgb($hex) {
if(strlen($hex) == 3) {
$r = hexdec(substr($hex,0,1).substr($hex,0,1));
$g = hexdec(substr($hex,1,1).substr($hex,1,1));
$b = hexdec(substr($hex,2,1).substr($hex,2,1));
} else {
$r = hexdec(substr($hex,0,2));
$g = hexdec(substr($hex,2,2));
$b = hexdec(substr($hex,4,2));
}
$rgb = array($r, $g, $b);
return $rgb;
}
function echoHeaders() {
$type = $_GET['type'];
$headers = '';
if ( "css" == $type ) {
$headers = "Content-Type: text/css\n";
}
elseif ( "js" == $type ) {
$headers = "Content-Type: application/x-javascript\n";
}
elseif ( "html" == $type ) {
$headers = "Content-Type: text/html\n";
}
elseif ( "swf" == $type ) {
$headers = "Content-Type: application/x-shockwave-flash\n";
}
elseif ( "gif" == $type) {
$headers = "Content-Type: image/gif\n";
}
elseif ( "jpg" == $type) {
$headers = "Content-Type: image/jpeg\n";
}
elseif ( "png" == $type) {
$headers = "Content-Type: image/png\n";
}
header($headers);
if(isset($_GET['expires']) and $_GET['expires'] != 0) {
if($_GET['expires'] == 1) {
$epoch = time() + 30*60*60*24;
} elseif($_GET['expires'] == -1) {
$epoch = time() - 30*60*60*24;
}
$expires = "Expires: ". date("D, d M Y H:i:s" , $epoch) ." GMT\n";
header($expires);
}
if(isset($_GET['last']) and $_GET['last'] == 1) {
$epoch = 1137326400;
$last = "Last-Modified: ". date("D, d M Y H:i:s" , $epoch) ." GMT\n";
header($last);
}
}
function echoContent() {
$type = $_GET['type'];
if ("css" == $type) {
$content = ".sleepcgi { background: #EEE; color: #606; font-weight: bold; padding: 10px; }\n";
echo $content;
}
elseif ("js" == $type) {
$content = <<<OUTPUT
var sleepcgi = 1;
function sleepcgiFunc() {
sleepcgi++;
}
OUTPUT;
echo $content;
}
elseif ("html" == $type) {
$content = <<<OUTPUT
<html>
<head>
<title>sleep.cgi test page</title>
</head>
<body>
sleep.cgi test page
</body>
</html>
OUTPUT;
;
echo $content;
}
elseif ("swf" == $type) {
/*
* http://www.ibm.com/developerworks/cn/opensource/os-php-flash/
* 需要安装PHP 扩展 http://www.php.net/manual/en/book.ming.php
*
usage : <embed align="center" src="sleep.php?type=swf" width="100" height="100" type="application/x-shockwave-flash" wmode="transparent" quality="high"> </embed>
*/
$f = new SWFFont('_sans');
$t = new SWFTextField();
$t->setFont($f);
$t->setColor(0, 0, 0);
$t->setHeight(400);
$t->addString('flash');
$m = new SWFMovie();
$m->setDimension(1600, 900);
$m->add($t);
$m->output();
}
elseif ("gif" == $type or "png" == $type or "jpg" == $type) {
$width = isset($_GET['width']) ? $_GET['width'] : 100;
$height = isset($_GET['height']) ? $_GET['height'] : 100;
$fcolor = isset($_GET['fcolor']) ? $_GET['fcolor'] : 'fff';
$bgcolor = isset($_GET['bgcolor']) ? $_GET['bgcolor'] : '000';
$im = imagecreatetruecolor($width, $height);
list($r, $g, $b) = hex2rgb($fcolor);
$text_color = imagecolorallocate($im, $r, $g, $b);
list($r, $g, $b) = hex2rgb($bgcolor);
$background_color = imagecolorallocate($im, $r, $g, $b);
imagefill($im, 0, 0, $background_color);
if(isset($_GET['text']))
// array imagettftext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text )
imagettftext($im, 24, 0, 0, 100, $text_color, dirname(__FILE__) . DIRECTORY_SEPARATOR .'wqy-microhei.ttc', $_GET['text']);
else
imagestring($im, 4, 0, 0, "$width x $height", $text_color);
if ("gif" == $type) {
imagegif($im);
}
elseif ("jpg" == $type) {
imagejpeg($im);
}
elseif ("png" == $type) {
imagepng($im);
}
}
}
echoHeaders();
echoContent();
?>