-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
executable file
·173 lines (146 loc) · 4.97 KB
/
Copy pathindex.php
File metadata and controls
executable file
·173 lines (146 loc) · 4.97 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
// directory name with subdirectories for categories, images in subdirs.
$IMAGES_DIR = 'images';
$THUMBNAIL_WIDTH = 320; //pixels
$CODE_EXPIRES = 7; // days
$CODE_SIZE = 4; // numbers
// random number that protects YOUR version of portfolio against attack.
// You MUST change this number from the default otherwise others who know
// this source code will be able to access your images.
// make it a really big number.
$SALT = 0;
// Administrator password, you MUST change this for your site to be secure.
$PASSWORD = 'portfolio';
function get_categories()
{
global $IMAGES_DIR;
global $CODE_EXPIRES;
global $CODE_SIZE;
global $SALT;
global $PASSWORD;
$files = array();
$dir = opendir($IMAGES_DIR);
while( false !== ($file = readdir($dir))) {
$path = "${IMAGES_DIR}/${file}";
if( $file != "." && $file != ".." && is_dir( $path )) {
if ( stripos( $file, "Private" ) === false ) {
$files[] = $file;
} else if( array_key_exists( 'code', $_COOKIE )) {
$code = $_COOKIE['code'];
if( $code == $PASSWORD ) {
$files[] = $file;
} else {
$date = time();
$date = $date - ($date % 86400);
$enddate = $date + (86400 * $CODE_EXPIRES);
while( $date <= $enddate ) {
$cc = md5($date + $SALT);
$cc = substr( $cc, 0, $CODE_SIZE );
if( $code == $cc ) {
$files[] = $file;
break;
}
$date += 86400;
}
}
}
}
}
closedir($dir);
sort($files);
return $files;
}
function get_images( $category )
{
global $IMAGES_DIR;
$dir = $IMAGES_DIR . "/" . $category;
$files = array();
$dir = opendir($dir);
while( false !== ($file = readdir($dir))) {
$path = "${IMAGES_DIR}/${category}/${file}";
if( $file != "." && $file != ".." && strpos($file,"_thumbnail") === false && is_file( $path )) {
$files[] = $file;
}
}
closedir($dir);
sort($files);
return $files;
}
$SCRIPT = $_SERVER["REQUEST_URI"];
$SCRIPT_DIR = dirname($_SERVER["SCRIPT_NAME"]);
$QUERY = $_SERVER["QUERY_STRING"];
if( $QUERY == "cache.manifest" ) {
header("Content-type: text/cache-manifest");
print <<<EOF
CACHE MANIFEST
CACHE:
${SCRIPT_DIR}/resume.pdf
${SCRIPT_DIR}/jquery.min.js
${SCRIPT_DIR}/Animate.js
${SCRIPT_DIR}/Scroller.js
${SCRIPT_DIR}/EasyScroller.js
EOF;
$categories = get_categories();
foreach( $categories as $category ) {
$images = get_images( $category );
foreach( $images as $image ) {
print "${SCRIPT_DIR}/${IMAGES_DIR}/${category}/${image}" . PHP_EOL;
$thumbnail = preg_replace( '/(.jpg)$/i', '_thumbnail${1}', $image );
print "${SCRIPT}?thumbnail=${IMAGES_DIR}/${category}/${image}" . PHP_EOL;
}
}
print <<<EOF
NETWORK:
$SCRIPT?update
EOF;
} else if( $QUERY == "update" ) {
header("Content-type: application/json");
//header("Access-Control-Allow-Origin: " + $_SERVER["HTTP_HOST"]);
header("Cache-Control: no-cache");
print "{";
if( array_key_exists( 'code', $_COOKIE )) {
$code = $_COOKIE['code'];
if( $code == $PASSWORD ) {
$date = time();
$date = $date - ($date % 86400) + (86400 * $CODE_EXPIRES);
$cc = md5($date + $SALT);
$cc = substr( $cc, 0, $CODE_SIZE );
print "\"code\": \"${cc}\",";
}
}
$categories = get_categories();
foreach( $categories as $category ) {
print "\"${category}\":[";
$images = get_images( $category );
foreach( $images as $image ) {
print "\"${image}\",";
}
print "\"\"],";
}
print "\"path\": \"${SCRIPT_DIR}/${IMAGES_DIR}\"";
print "}";
} else if( substr( $QUERY, 0, 10 ) == "thumbnail=" ) {
$path = substr( $QUERY, 10 );
$path = rawurldecode( $path );
$path = "${IMAGES_DIR}/" . $path;
$thumbnail = preg_replace( '/(.jpg)$/i', '_thumbnail${1}', $path );
if( is_file( $path )) {
if( is_file( $thumbnail ) === false ) {
$image = imagecreatefromjpeg( $path );
$width = imagesx( $image );
$height = imagesy( $image );
$new_width = $THUMBNAIL_WIDTH;
$new_height = $height * $new_width / $width;
$new_image = imagecreatetruecolor( $new_width, $new_height );
imagecopyresampled( $new_image, $image, 0,0,0,0, $new_width, $new_height, $width, $height );
imagejpeg( $new_image, $thumbnail, 75 );
}
}
header("Content-Type: image/jpeg");
header("Content-Length: " . (string)filesize($thumbnail));
readfile($thumbnail);
} else {
header("Content-type: text/html; charset=iso-8859-1");
readfile("_index.html");
}
?>