Fixed issues with broken stat cache
[GitHub/WoltLab/WCF.git] / wcfsetup / install.php
1 <?php
2 /**
3 * This script tries to find the temp folder and unzip all setup files into.
4 *
5 * @author Marcel Werk
6 * @copyright 2001-2013 WoltLab GmbH
7 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
8 */
9 // define constants
10 define('INSTALL_SCRIPT', __FILE__);
11 define('INSTALL_SCRIPT_DIR', dirname(__FILE__).'/');
12 define('SETUP_FILE', INSTALL_SCRIPT_DIR . 'WCFSetup.tar.gz');
13 define('NO_IMPORTS', 1);
14
15 // set exception handler
16 set_exception_handler('handleException');
17 // set php error handler
18 set_error_handler('handleError', E_ALL);
19
20 // define list of needed file
21 $neededFilesPattern = array(
22 '!^setup/.*!',
23 '!^install/files/acp/images/wcfLogo.*!',
24 '!^install/files/acp/style/setup/.*!',
25 '!^install/files/lib/data/.*!',
26 '!^install/files/icon/.*!',
27 '!^install/files/font/.*!',
28 '!^install/files/lib/system/.*!',
29 '!^install/files/lib/util/.*!',
30 '!^install/lang/.*!',
31 '!^install/packages/.*!');
32
33 // define needed functions and classes
34 /**
35 * WCF::handleException() calls the show method on exceptions that implement this interface.
36 *
37 * @package com.woltlab.wcf
38 * @author Marcel Werk
39 */
40 interface IPrintableException {
41 public function show();
42 }
43
44 // define needed classes
45 // needed are:
46 // SystemException, PrintableException, BasicFileUtil, Tar, File, ZipFile
47 /**
48 * A SystemException is thrown when an unexpected error occurs.
49 *
50 * @package com.woltlab.wcf
51 * @author Marcel Werk
52 */
53 class SystemException extends \Exception implements IPrintableException {
54 protected $description;
55 protected $information = '';
56 protected $functions = '';
57
58 /**
59 * Creates a new SystemException.
60 *
61 * @param message string error message
62 * @param code integer error code
63 * @param description string description of the error
64 */
65 public function __construct($message = '', $code = 0, $description = '') {
66 parent::__construct($message, $code);
67 $this->description = $description;
68 }
69
70 /**
71 * Returns the description of this exception.
72 *
73 * @return string
74 */
75 public function getDescription() {
76 return $this->description;
77 }
78
79 /**
80 * Prints this exception.
81 * This method is called by WCF::handleException().
82 */
83 public function show() {
84 ?>
85 <html>
86 <head>
87 <title>Fatal error: <?php echo htmlspecialchars($this->getMessage()); ?></title>
88
89 <style type="text/css">
90 body {
91 font-family: Verdana, Helvetica, sans-serif;
92 font-size: 0.8em;
93 }
94 div {
95 border: 1px outset lightgrey;
96 padding: 3px;
97 background-color: lightgrey;
98 }
99
100 div div {
101 border: 1px inset lightgrey;
102 padding: 4px;
103 }
104
105 h1 {
106 background-color: #154268;
107 padding: 4px;
108 color: #fff;
109 margin: 0 0 3px 0;
110 font-size: 1.15em;
111 }
112 h2 {
113 font-size: 1.1em;
114 margin-bottom: 0;
115 }
116
117 pre, p {
118 margin: 0;
119 }
120 </style>
121 </head>
122
123 <body>
124 <div>
125 <h1>Fatal error: <?php echo htmlspecialchars($this->getMessage()); ?></h1>
126
127 <div>
128 <p><?php echo $this->getDescription(); ?></p>
129 <?php if ($this->getCode()) { ?><p>You get more information about the problem in our knowledge base: <a href="http://www.woltlab.com/help/?code=<?php echo intval($this->getCode()); ?>">http://www.woltlab.com/help/?code=<?php echo intval($this->getCode()); ?></a></p><?php } ?>
130
131 <h2>Information:</h2>
132 <p>
133 <b>error message:</b> <?php echo htmlspecialchars($this->getMessage()); ?><br />
134 <b>error code:</b> <?php echo intval($this->getCode()); ?><br />
135 <?php echo $this->information; ?>
136 <b>file:</b> <?php echo htmlspecialchars($this->getFile()); ?> (<?php echo $this->getLine(); ?>)<br />
137 <b>php version:</b> <?php echo htmlspecialchars(phpversion()); ?><br />
138 <b>wcf version:</b> <?php if (defined('WCF_VERSION')) echo WCF_VERSION; ?><br />
139 <b>date:</b> <?php echo gmdate('r'); ?><br />
140 <b>request:</b> <?php if (isset($_SERVER['REQUEST_URI'])) echo htmlspecialchars($_SERVER['REQUEST_URI']); ?><br />
141 <b>referer:</b> <?php if (isset($_SERVER['HTTP_REFERER'])) echo htmlspecialchars($_SERVER['HTTP_REFERER']); ?><br />
142 </p>
143
144 <h2>Stacktrace:</h2>
145 <pre><?php echo htmlspecialchars($this->getTraceAsString()); ?></pre>
146 </div>
147
148 <?php echo $this->functions; ?>
149 </div>
150 </body>
151 </html>
152
153 <?php
154 }
155 }
156
157
158 /**
159 * Loads the required classes automatically.
160 */
161 function __autoload($className) {
162 $namespaces = explode('\\', $className);
163 if (count($namespaces) > 1) {
164 // remove 'wcf' component
165 array_shift($namespaces);
166
167 $className = implode('/', $namespaces);
168 $classPath = TMP_DIR . 'install/files/lib/' . $className . '.class.php';
169 if (file_exists($classPath)) {
170 require_once($classPath);
171 }
172 }
173 }
174
175 /**
176 * Escapes strings for execution in sql queries.
177 */
178 function escapeString($string) {
179 return \wcf\system\WCF::getDB()->escapeString($string);
180 }
181
182 /**
183 * Calls the show method on the given exception.
184 *
185 * @param Exception $e
186 */
187 function handleException(\Exception $e) {
188 if ($e instanceof IPrintableException || $e instanceof \wcf\system\exception\IPrintableException) {
189 $e->show();
190 exit;
191 }
192
193 print $e;
194 }
195
196 /**
197 * Catches php errors and throws instead a system exception.
198 *
199 * @param integer $errorNo
200 * @param string $message
201 * @param string $filename
202 * @param integer $lineNo
203 */
204 function handleError($errorNo, $message, $filename, $lineNo) {
205 if (error_reporting() != 0) {
206 $type = 'error';
207 switch ($errorNo) {
208 case 2: $type = 'warning';
209 break;
210 case 8: $type = 'notice';
211 break;
212 }
213
214 throw new SystemException('PHP '.$type.' in file '.$filename.' ('.$lineNo.'): '.$message, 0);
215 }
216 }
217
218 /**
219 * BasicFileUtil contains file-related functions.
220 *
221 * @package com.woltlab.wcf
222 * @author Marcel Werk
223 */
224 class BasicFileUtil {
225 /**
226 * chmod mode
227 * @var integer
228 */
229 protected static $mode = null;
230
231 /**
232 * Tries to find the temp folder.
233 *
234 * @return string
235 */
236 public static function getTempFolder() {
237 // use tmp folder in document root by default
238 if (!empty($_SERVER['DOCUMENT_ROOT'])) {
239 if (strpos($_SERVER['DOCUMENT_ROOT'], 'strato') !== false) {
240 // strato bugfix
241 // create tmp folder in document root automatically
242 if (!@file_exists($_SERVER['DOCUMENT_ROOT'].'/tmp')) {
243 @mkdir($_SERVER['DOCUMENT_ROOT'].'/tmp/', 0777);
244 try {
245 self::makeWritable($_SERVER['DOCUMENT_ROOT'].'/tmp/');
246 }
247 catch (SystemException $e) {}
248 }
249 }
250 if (@file_exists($_SERVER['DOCUMENT_ROOT'].'/tmp') && @is_writable($_SERVER['DOCUMENT_ROOT'].'/tmp')) {
251 return $_SERVER['DOCUMENT_ROOT'].'/tmp/';
252 }
253 }
254
255 if (isset($_ENV['TMP']) && @is_writable($_ENV['TMP'])) {
256 return $_ENV['TMP'] . '/';
257 }
258 if (isset($_ENV['TEMP']) && @is_writable($_ENV['TEMP'])) {
259 return $_ENV['TEMP'] . '/';
260 }
261 if (isset($_ENV['TMPDIR']) && @is_writable($_ENV['TMPDIR'])) {
262 return $_ENV['TMPDIR'] . '/';
263 }
264
265 if (($path = ini_get('upload_tmp_dir')) && @is_writable($path)) {
266 return $path . '/';
267 }
268 if (@file_exists('/tmp/') && @is_writable('/tmp/')) {
269 return '/tmp/';
270 }
271 if (function_exists('session_save_path') && ($path = session_save_path()) && @is_writable($path)) {
272 return $path . '/';
273 }
274
275 $path = INSTALL_SCRIPT_DIR.'tmp/';
276 if (@file_exists($path) && @is_writable($path)) {
277 return $path;
278 }
279 else {
280 throw new SystemException('There is no access to the system temporary folder due to an unknown reason and no user specific temporary folder exists in '.INSTALL_SCRIPT_DIR.'! This is a misconfiguration of your webserver software! Please create a folder called '.$path.' using your favorite ftp program, make it writable and then retry this installation.');
281 }
282 }
283
284 /**
285 * Returns the temp folder for the installation.
286 *
287 * @return string
288 */
289 public static function getInstallTempFolder() {
290 $dir = self::getTempFolder() . TMP_FILE_PREFIX . '/';
291 @mkdir($dir);
292 self::makeWritable($dir);
293
294 return $dir;
295 }
296
297 /**
298 * Tries to make a file or directory writable. It starts of with the least
299 * permissions and goes up until 0666 for files and 0777 for directories.
300 *
301 * @param string $filename
302 */
303 public static function makeWritable($filename) {
304 if (!file_exists($filename)) {
305 return;
306 }
307
308 // determine mode
309 if (self::$mode === null) {
310 // do not use PHP_OS here, as this represents the system it was built on != running on
311 if (strpos(php_uname(), 'Windows') !== false) {
312 self::$mode = 0777;
313 }
314 else {
315 clearstatcache();
316
317 self::$mode = 0666;
318
319 $tmpFilename = '__permissions_'.sha1(time()).'.txt';
320 @touch($tmpFilename);
321
322 // create a new file and check the file owner, if it is the same
323 // as this file (uploaded through FTP), we can safely grant write
324 // permissions exclusively to the owner rather than everyone
325 if (file_exists($tmpFilename)) {
326 $scriptOwner = fileowner(__FILE__);
327 $fileOwner = fileowner($tmpFilename);
328
329 if ($scriptOwner === $fileOwner) {
330 self::$mode = 0644;
331 }
332
333 @unlink($tmpFilename);
334 }
335 }
336 }
337
338 $startIndex = 0;
339 if (is_dir($filename)) {
340 if (self::$mode == 0644) {
341 @chmod($filename, 0755);
342 }
343 else {
344 @chmod($filename, 0777);
345 }
346 }
347 else {
348 @chmod($filename, self::$mode);
349 }
350
351 if (!is_writable($filename)) {
352 throw new SystemException("Unable to make '".$filename."' writable. This is a misconfiguration of your server, please contact your system administrator or hosting provider.");
353 }
354 }
355 }
356
357 /**
358 * Opens tar or tar.gz archives.
359 *
360 * Usage:
361 * ------
362 * $tar = new Tar('archive.tar');
363 * $contentList = $tar->getContentList();
364 * foreach ($contentList as $key => $val) {
365 * $tar->extract($key, DESTINATION);
366 * }
367 */
368 class Tar {
369 protected $archiveName = '';
370 protected $contentList = array();
371 protected $opened = false;
372 protected $read = false;
373 protected $file = null;
374 protected $isZipped = false;
375 protected $mode = 'rb';
376
377 /**
378 * Creates a new Tar object.
379 * archiveName must be tarball or gzipped tarball
380 *
381 * @param string $archiveName
382 */
383 public function __construct($archiveName) {
384 if (!is_file($archiveName)) {
385 throw new SystemException("unable to find tar archive '".$archiveName."'");
386 }
387
388 $this->archiveName = $archiveName;
389 $this->open();
390 $this->readContent();
391 }
392
393 /**
394 * Destructor of this class, closes tar archive.
395 */
396 public function __destruct() {
397 $this->close();
398 }
399
400 /**
401 * Opens the tar archive and stores filehandle.
402 */
403 public function open() {
404 if (!$this->opened) {
405 if ($this->isZipped) $this->file = new ZipFile($this->archiveName, $this->mode);
406 else {
407 // test compression
408 $this->file = new File($this->archiveName, $this->mode);
409 if ($this->file->read(2) == "\37\213") {
410 $this->file->close();
411 $this->isZipped = true;
412 $this->file = new ZipFile($this->archiveName, $this->mode);
413 }
414 else {
415 $this->file->seek(0);
416 }
417 }
418 $this->opened = true;
419 }
420 }
421
422 /**
423 * Closes the opened file.
424 */
425 public function close() {
426 if ($this->opened) {
427 $this->file->close();
428 $this->opened = false;
429 }
430 }
431
432 /**
433 * Returns the table of contents (TOC) list for this tar archive.
434 *
435 * @return array list of content
436 */
437 public function getContentList() {
438 if (!$this->read) {
439 $this->open();
440 $this->readContent();
441 }
442 return $this->contentList;
443 }
444
445 /**
446 * Returns an associative array with information
447 * about a specific file in the archive.
448 *
449 * @param mixed $fileindex index or name of the requested file
450 * @return array $fileInfo
451 */
452 public function getFileInfo($fileIndex) {
453 if (!is_int($fileIndex)) {
454 $fileIndex = $this->getIndexByFilename($fileIndex);
455 }
456
457 if (!isset($this->contentList[$fileIndex])) {
458 throw new SystemException("Tar: could find file '".$fileIndex."' in archive");
459 }
460 return $this->contentList[$fileIndex];
461 }
462
463 /**
464 * Searchs a file in the tar archive
465 * and returns the numeric fileindex.
466 * Returns false if not found.
467 *
468 * @param string $filename
469 * @return integer index of the requested file
470 */
471 public function getIndexByFilename($filename) {
472 foreach ($this->contentList as $index => $file) {
473 if ($file['filename'] == $filename) {
474 return $index;
475 }
476 }
477 return false;
478 }
479
480 /**
481 * Extracts a specific file and returns the content as string.
482 * Returns false if extraction failed.
483 *
484 * @param mixed $index index or name of the requested file
485 * @return string content of the requested file
486 */
487 public function extractToString($index) {
488 if (!$this->read) {
489 $this->open();
490 $this->readContent();
491 }
492 $header = $this->getFileInfo($index);
493
494 // can not extract a folder
495 if ($header['type'] != 'file') {
496 return false;
497 }
498
499 // seek to offset
500 $this->file->seek($header['offset']);
501
502 // read data
503 $content = '';
504 $n = floor($header['size'] / 512);
505 for($i = 0; $i < $n; $i++) {
506 $content .= $this->file->read(512);
507 }
508 if(($header['size'] % 512) != 0) {
509 $buffer = $this->file->read(512);
510 $content .= substr($buffer, 0, ($header['size'] % 512));
511 }
512
513 return $content;
514 }
515
516 /**
517 * Extracts a specific file and writes it's content
518 * to the file specified with $destination.
519 *
520 * @param mixed $index index or name of the requested file
521 * @param string $destination
522 * @return boolean $success
523 */
524 public function extract($index, $destination) {
525 if (!$this->read) {
526 $this->open();
527 $this->readContent();
528 }
529 $header = $this->getFileInfo($index);
530
531 // can not extract a folder
532 if ($header['type'] != 'file') {
533 return false;
534 }
535
536 // seek to offset
537 $this->file->seek($header['offset']);
538
539 $targetFile = new File($destination);
540
541 // read data
542 $n = floor($header['size'] / 512);
543 for ($i = 0; $i < $n; $i++) {
544 $content = $this->file->read(512);
545 $targetFile->write($content, 512);
546 }
547 if (($header['size'] % 512) != 0) {
548 $content = $this->file->read(512);
549 $targetFile->write($content, ($header['size'] % 512));
550 }
551
552 $targetFile->close();
553 BasicFileUtil::makeWritable($destination);
554
555 if ($header['mtime']) {
556 @$targetFile->touch($header['mtime']);
557 }
558
559 // check filesize
560 if (filesize($destination) != $header['size']) {
561 throw new SystemException("Could not untar file '".$header['filename']."' to '".$destination."'. Maybe disk quota exceeded in folder '".dirname($destination)."'.");
562 }
563
564 return true;
565 }
566
567 /**
568 * Reads table of contents (TOC) from tar archive.
569 * This does not get the entire to memory but only parts of it.
570 */
571 protected function readContent() {
572 $this->contentList = array();
573 $this->read = true;
574 $i = 0;
575
576 // Read the 512 bytes header
577 while (strlen($binaryData = $this->file->read(512)) != 0) {
578 // read header
579 $header = $this->readHeader($binaryData);
580 if ($header === false) {
581 continue;
582 }
583 $this->contentList[$i] = $header;
584 $this->contentList[$i]['index'] = $i;
585 $i++;
586
587 $this->file->seek($this->file->tell() + (512 * ceil(($header['size'] / 512))));
588 }
589 }
590
591 /**
592 * Unpacks file header for one file entry.
593 *
594 * @param string $binaryData
595 * @return array $fileheader
596 */
597 protected function readHeader($binaryData) {
598 if (strlen($binaryData) != 512) {
599 return false;
600 }
601
602 $header = array();
603 $checksum = 0;
604 // First part of the header
605 for ($i = 0; $i < 148; $i++) {
606 $checksum += ord(substr($binaryData, $i, 1));
607 }
608 // Calculate the checksum
609 // Ignore the checksum value and replace it by ' ' (space)
610 for ($i = 148; $i < 156; $i++) {
611 $checksum += ord(' ');
612 }
613 // Last part of the header
614 for ($i = 156; $i < 512; $i++) {
615 $checksum += ord(substr($binaryData, $i, 1));
616 }
617
618 // Extract the values
619 //$data = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1typeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor", $binaryData);
620 if (version_compare(PHP_VERSION, '5.5.0-dev', '>=')) {
621 $format = 'Z100filename/Z8mode/Z8uid/Z8gid/Z12size/Z12mtime/Z8checksum/Z1typeflag/Z100link/Z6magic/Z2version/Z32uname/Z32gname/Z8devmajor/Z8devminor/Z155prefix';
622 }
623 else {
624 $format = 'a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1typeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor/a155prefix';
625 }
626
627 $data = unpack($format, $binaryData);
628
629 // Extract the properties
630 $header['checksum'] = octDec(trim($data['checksum']));
631 if ($header['checksum'] == $checksum) {
632 $header['filename'] = trim($data['filename']);
633 $header['mode'] = octDec(trim($data['mode']));
634 $header['uid'] = octDec(trim($data['uid']));
635 $header['gid'] = octDec(trim($data['gid']));
636 $header['size'] = octDec(trim($data['size']));
637 $header['mtime'] = octDec(trim($data['mtime']));
638 $header['prefix'] = trim($data['prefix']);
639 if ($header['prefix']) {
640 $header['filename'] = $header['prefix'].'/'.$header['filename'];
641 }
642 if (($header['typeflag'] = $data['typeflag']) == '5') {
643 $header['size'] = 0;
644 $header['type'] = 'folder';
645 }
646 else {
647 $header['type'] = 'file';
648 }
649 $header['offset'] = $this->file->tell();
650
651 return $header;
652 }
653 else {
654 return false;
655 }
656 }
657 }
658
659 /**
660 * The File class handles all file operations.
661 *
662 * Example:
663 * using php functions:
664 * $fp = fopen('filename', 'wb');
665 * fwrite($fp, '...');
666 * fclose($fp);
667 *
668 * using this class:
669 * $file = new File('filename');
670 * $file->write('...');
671 * $file->close();
672 *
673 * @author Marcel Werk
674 */
675 class File {
676 protected $resource = null;
677 protected $filename;
678
679 /**
680 * Opens a new file.
681 *
682 * @param string $filename
683 * @param string $mode
684 */
685 public function __construct($filename, $mode = 'wb') {
686 $this->filename = $filename;
687 $this->resource = fopen($filename, $mode);
688 if ($this->resource === false) {
689 throw new SystemException('Can not open file ' . $filename);
690 }
691 }
692
693 /**
694 * Calls the specified function on the open file.
695 * Do not call this function directly. Use $file->write('') instead.
696 *
697 * @param string $function
698 * @param array $arguments
699 */
700 public function __call($function, $arguments) {
701 if (function_exists('f' . $function)) {
702 array_unshift($arguments, $this->resource);
703 return call_user_func_array('f' . $function, $arguments);
704 }
705 else if (function_exists($function)) {
706 array_unshift($arguments, $this->filename);
707 return call_user_func_array($function, $arguments);
708 }
709 else {
710 throw new SystemException('Can not call file method ' . $function);
711 }
712 }
713 }
714
715 /**
716 * The File class handles all file operations on a zipped file.
717 *
718 * @author Marcel Werk
719 */
720 class ZipFile extends File {
721 /**
722 * Opens a new zipped file.
723 *
724 * @param string $filename
725 * @param string $mode
726 */
727 public function __construct($filename, $mode = 'wb') {
728 $this->filename = $filename;
729 if (!function_exists('gzopen')) {
730 throw new SystemException('Can not find functions of the zlib extension');
731 }
732 $this->resource = @gzopen($filename, $mode);
733 if ($this->resource === false) {
734 throw new SystemException('Can not open file ' . $filename);
735 }
736 }
737
738 /**
739 * Calls the specified function on the open file.
740 *
741 * @param string $function
742 * @param array $arguments
743 */
744 public function __call($function, $arguments) {
745 if (function_exists('gz' . $function)) {
746 array_unshift($arguments, $this->resource);
747 return call_user_func_array('gz' . $function, $arguments);
748 }
749 else if (function_exists($function)) {
750 array_unshift($arguments, $this->filename);
751 return call_user_func_array($function, $arguments);
752 }
753 else {
754 throw new SystemException('Can not call method ' . $function);
755 }
756 }
757
758 /**
759 * Returns the filesize of the unzipped file
760 */
761 public function getFileSize() {
762 $byteBlock = 1<<14;
763 $eof = $byteBlock;
764
765 // the correction is for zip files that are too small
766 // to get in the first while loop
767 $correction = 1;
768 while ($this->seek($eof) == 0) {
769 $eof += $byteBlock;
770 $correction = 0;
771 }
772
773 while ($byteBlock > 1) {
774 $byteBlock >>= 1;
775 $eof += $byteBlock * ($this->seek($eof) ? -1 : 1);
776 }
777
778 if ($this->seek($eof) == -1) $eof -= 1;
779
780 $this->rewind();
781 return $eof - $correction;
782 }
783 }
784
785 // let's go
786 // get temp file prefix
787 if (isset($_REQUEST['tmpFilePrefix'])) {
788 $prefix = preg_replace('/[^a-f0-9_]+/', '', $_REQUEST['tmpFilePrefix']);
789 }
790 else {
791 $prefix = substr(sha1(uniqid(microtime())), 0, 8);
792 }
793 define('TMP_FILE_PREFIX', $prefix);
794
795 // try to find the temp folder
796 define('TMP_DIR', BasicFileUtil::getInstallTempFolder());
797
798 /**
799 * Reads a file resource from temp folder.
800 *
801 * @param string $key
802 * @param string $directory
803 */
804 function readFileResource($key, $directory) {
805 if (preg_match('~[\w\-]+\.(css|jpg|png|svg|eot|woff|ttf)~', $_GET[$key], $match)) {
806 switch ($match[1]) {
807 case 'css':
808 header('Content-Type: text/css');
809 break;
810
811 case 'jpg':
812 header('Content-Type: image/jpg');
813 break;
814
815 case 'png':
816 header('Content-Type: image/png');
817 break;
818
819 case 'svg':
820 header('Content-Type: image/svg+xml');
821 break;
822
823 case 'eot':
824 header('Content-Type: application/vnd.ms-fontobject');
825 break;
826
827 case 'woff':
828 header('Content-Type: application/font-woff');
829 break;
830
831 case 'ttf':
832 header('Content-Type: application/octet-stream');
833 break;
834 }
835
836 header('Expires: '.gmdate('D, d M Y H:i:s', time() + 3600).' GMT');
837 header('Last-Modified: Mon, 26 Jul 1997 05:00:00 GMT');
838 header('Cache-Control: public, max-age=3600');
839
840 readfile($directory . $_GET[$key]);
841 }
842 exit;
843 }
844
845 // show image from temp folder
846 if (isset($_GET['showImage'])) {
847 readFileResource('showImage', TMP_DIR . 'install/files/acp/images/');
848 }
849 // show icon from temp folder
850 if (isset($_GET['showIcon'])) {
851 readFileResource('showIcon', TMP_DIR . 'install/files/icon/');
852 }
853 // show css from temp folder
854 if (isset($_GET['showCSS'])) {
855 readFileResource('showCSS', TMP_DIR . 'install/files/acp/style/setup/');
856 }
857 // show fonts from temp folder
858 if (isset($_GET['showFont'])) {
859 readFileResource('showFont', TMP_DIR . 'install/files/font/');
860 }
861
862 // check whether setup files are already unzipped
863 if (!file_exists(TMP_DIR . 'install/files/lib/system/WCFSetup.class.php')) {
864 // try to unzip all setup files into temp folder
865 $tar = new Tar(SETUP_FILE);
866 $contentList = $tar->getContentList();
867 if (empty($contentList)) {
868 throw new SystemException("Can not unpack 'WCFSetup.tar.gz'. File is probably broken.");
869 }
870
871 foreach ($contentList as $file) {
872 foreach ($neededFilesPattern as $pattern) {
873 if (preg_match($pattern, $file['filename'])) {
874 // create directory if not exists
875 $dir = TMP_DIR . dirname($file['filename']);
876 if (!@is_dir($dir)) {
877 @mkdir($dir, 0777, true);
878 BasicFileUtil::makeWritable($dir);
879 }
880
881 $tar->extract($file['index'], TMP_DIR . $file['filename']);
882 }
883 }
884 }
885 $tar->close();
886
887 // create cache folders
888 @mkdir(TMP_DIR . 'setup/lang/cache/', 0777);
889 BasicFileUtil::makeWritable(TMP_DIR . 'setup/lang/cache/');
890
891 @mkdir(TMP_DIR . 'setup/template/compiled/', 0777);
892 BasicFileUtil::makeWritable(TMP_DIR . 'setup/template/compiled/');
893 }
894
895 if (!class_exists('wcf\system\WCFSetup')) {
896 throw new SystemException("Can not find class 'WCFSetup'");
897 }
898
899 // start setup
900 new \wcf\system\WCFSetup();