Merge branch 'master' of github.com:WoltLab/WCF
[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.system.exception
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.system.exception
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.util
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 = WCF_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 self::$mode = 0666;
316
317 $tmpFilename = '__permissions_'.sha1(time()).'.txt';
318 @touch($tmpFilename);
319
320 // create a new file and check the file owner, if it is the same
321 // as this file (uploaded through FTP), we can safely grant write
322 // permissions exclusively to the owner rather than everyone
323 if (file_exists($tmpFilename)) {
324 $scriptOwner = fileowner(__FILE__);
325 $fileOwner = fileowner($tmpFilename);
326
327 if ($scriptOwner === $fileOwner) {
328 self::$mode = 0644;
329 }
330
331 @unlink($tmpFilename);
332 }
333 }
334 }
335
336 $startIndex = 0;
337 if (is_dir($filename)) {
338 if (self::$mode == 0644) {
339 @chmod($filename, 0755);
340 }
341 else {
342 @chmod($filename, 0777);
343 }
344 }
345 else {
346 @chmod($filename, self::$mode);
347 }
348
349 if (!is_writable($filename)) {
350 throw new SystemException("Unable to make '".$filename."' writable. This is a misconfiguration of your server, please contact your system administrator or hosting provider.");
351 }
352 }
353 }
354
355 /**
356 * Opens tar or tar.gz archives.
357 *
358 * Usage:
359 * ------
360 * $tar = new Tar('archive.tar');
361 * $contentList = $tar->getContentList();
362 * foreach ($contentList as $key => $val) {
363 * $tar->extract($key, DESTINATION);
364 * }
365 */
366 class Tar {
367 protected $archiveName = '';
368 protected $contentList = array();
369 protected $opened = false;
370 protected $read = false;
371 protected $file = null;
372 protected $isZipped = false;
373 protected $mode = 'rb';
374
375 /**
376 * Creates a new Tar object.
377 * archiveName must be tarball or gzipped tarball
378 *
379 * @param string $archiveName
380 */
381 public function __construct($archiveName) {
382 if (!is_file($archiveName)) {
383 throw new SystemException("unable to find tar archive '".$archiveName."'");
384 }
385
386 $this->archiveName = $archiveName;
387 $this->open();
388 $this->readContent();
389 }
390
391 /**
392 * Destructor of this class, closes tar archive.
393 */
394 public function __destruct() {
395 $this->close();
396 }
397
398 /**
399 * Opens the tar archive and stores filehandle.
400 */
401 public function open() {
402 if (!$this->opened) {
403 if ($this->isZipped) $this->file = new ZipFile($this->archiveName, $this->mode);
404 else {
405 // test compression
406 $this->file = new File($this->archiveName, $this->mode);
407 if ($this->file->read(2) == "\37\213") {
408 $this->file->close();
409 $this->isZipped = true;
410 $this->file = new ZipFile($this->archiveName, $this->mode);
411 }
412 else {
413 $this->file->seek(0);
414 }
415 }
416 $this->opened = true;
417 }
418 }
419
420 /**
421 * Closes the opened file.
422 */
423 public function close() {
424 if ($this->opened) {
425 $this->file->close();
426 $this->opened = false;
427 }
428 }
429
430 /**
431 * Returns the table of contents (TOC) list for this tar archive.
432 *
433 * @return array list of content
434 */
435 public function getContentList() {
436 if (!$this->read) {
437 $this->open();
438 $this->readContent();
439 }
440 return $this->contentList;
441 }
442
443 /**
444 * Returns an associative array with information
445 * about a specific file in the archive.
446 *
447 * @param mixed $fileindex index or name of the requested file
448 * @return array $fileInfo
449 */
450 public function getFileInfo($fileIndex) {
451 if (!is_int($fileIndex)) {
452 $fileIndex = $this->getIndexByFilename($fileIndex);
453 }
454
455 if (!isset($this->contentList[$fileIndex])) {
456 throw new SystemException("Tar: could find file '".$fileIndex."' in archive");
457 }
458 return $this->contentList[$fileIndex];
459 }
460
461 /**
462 * Searchs a file in the tar archive
463 * and returns the numeric fileindex.
464 * Returns false if not found.
465 *
466 * @param string $filename
467 * @return integer index of the requested file
468 */
469 public function getIndexByFilename($filename) {
470 foreach ($this->contentList as $index => $file) {
471 if ($file['filename'] == $filename) {
472 return $index;
473 }
474 }
475 return false;
476 }
477
478 /**
479 * Extracts a specific file and returns the content as string.
480 * Returns false if extraction failed.
481 *
482 * @param mixed $index index or name of the requested file
483 * @return string content of the requested file
484 */
485 public function extractToString($index) {
486 if (!$this->read) {
487 $this->open();
488 $this->readContent();
489 }
490 $header = $this->getFileInfo($index);
491
492 // can not extract a folder
493 if ($header['type'] != 'file') {
494 return false;
495 }
496
497 // seek to offset
498 $this->file->seek($header['offset']);
499
500 // read data
501 $content = '';
502 $n = floor($header['size'] / 512);
503 for($i = 0; $i < $n; $i++) {
504 $content .= $this->file->read(512);
505 }
506 if(($header['size'] % 512) != 0) {
507 $buffer = $this->file->read(512);
508 $content .= substr($buffer, 0, ($header['size'] % 512));
509 }
510
511 return $content;
512 }
513
514 /**
515 * Extracts a specific file and writes it's content
516 * to the file specified with $destination.
517 *
518 * @param mixed $index index or name of the requested file
519 * @param string $destination
520 * @return boolean $success
521 */
522 public function extract($index, $destination) {
523 if (!$this->read) {
524 $this->open();
525 $this->readContent();
526 }
527 $header = $this->getFileInfo($index);
528
529 // can not extract a folder
530 if ($header['type'] != 'file') {
531 return false;
532 }
533
534 // seek to offset
535 $this->file->seek($header['offset']);
536
537 $targetFile = new File($destination);
538
539 // read data
540 $n = floor($header['size'] / 512);
541 for ($i = 0; $i < $n; $i++) {
542 $content = $this->file->read(512);
543 $targetFile->write($content, 512);
544 }
545 if (($header['size'] % 512) != 0) {
546 $content = $this->file->read(512);
547 $targetFile->write($content, ($header['size'] % 512));
548 }
549
550 $targetFile->close();
551 BasicFileUtil::makeWritable($destination);
552
553 if ($header['mtime']) {
554 @$targetFile->touch($header['mtime']);
555 }
556
557 // check filesize
558 if (filesize($destination) != $header['size']) {
559 throw new SystemException("Could not untar file '".$header['filename']."' to '".$destination."'. Maybe disk quota exceeded in folder '".dirname($destination)."'.");
560 }
561
562 return true;
563 }
564
565 /**
566 * Reads table of contents (TOC) from tar archive.
567 * This does not get the entire to memory but only parts of it.
568 */
569 protected function readContent() {
570 $this->contentList = array();
571 $this->read = true;
572 $i = 0;
573
574 // Read the 512 bytes header
575 while (strlen($binaryData = $this->file->read(512)) != 0) {
576 // read header
577 $header = $this->readHeader($binaryData);
578 if ($header === false) {
579 continue;
580 }
581 $this->contentList[$i] = $header;
582 $this->contentList[$i]['index'] = $i;
583 $i++;
584
585 $this->file->seek($this->file->tell() + (512 * ceil(($header['size'] / 512))));
586 }
587 }
588
589 /**
590 * Unpacks file header for one file entry.
591 *
592 * @param string $binaryData
593 * @return array $fileheader
594 */
595 protected function readHeader($binaryData) {
596 if (strlen($binaryData) != 512) {
597 return false;
598 }
599
600 $header = array();
601 $checksum = 0;
602 // First part of the header
603 for ($i = 0; $i < 148; $i++) {
604 $checksum += ord(substr($binaryData, $i, 1));
605 }
606 // Calculate the checksum
607 // Ignore the checksum value and replace it by ' ' (space)
608 for ($i = 148; $i < 156; $i++) {
609 $checksum += ord(' ');
610 }
611 // Last part of the header
612 for ($i = 156; $i < 512; $i++) {
613 $checksum += ord(substr($binaryData, $i, 1));
614 }
615
616 // Extract the values
617 //$data = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1typeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor", $binaryData);
618 $data = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1typeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor/a155prefix", $binaryData);
619
620 // Extract the properties
621 $header['checksum'] = octDec(trim($data['checksum']));
622 if ($header['checksum'] == $checksum) {
623 $header['filename'] = trim($data['filename']);
624 $header['mode'] = octDec(trim($data['mode']));
625 $header['uid'] = octDec(trim($data['uid']));
626 $header['gid'] = octDec(trim($data['gid']));
627 $header['size'] = octDec(trim($data['size']));
628 $header['mtime'] = octDec(trim($data['mtime']));
629 $header['prefix'] = trim($data['prefix']);
630 if ($header['prefix']) {
631 $header['filename'] = $header['prefix'].'/'.$header['filename'];
632 }
633 if (($header['typeflag'] = $data['typeflag']) == '5') {
634 $header['size'] = 0;
635 $header['type'] = 'folder';
636 }
637 else {
638 $header['type'] = 'file';
639 }
640 $header['offset'] = $this->file->tell();
641
642 return $header;
643 }
644 else {
645 return false;
646 }
647 }
648 }
649
650 /**
651 * The File class handles all file operations.
652 *
653 * Example:
654 * using php functions:
655 * $fp = fopen('filename', 'wb');
656 * fwrite($fp, '...');
657 * fclose($fp);
658 *
659 * using this class:
660 * $file = new File('filename');
661 * $file->write('...');
662 * $file->close();
663 *
664 * @author Marcel Werk
665 */
666 class File {
667 protected $resource = null;
668 protected $filename;
669
670 /**
671 * Opens a new file.
672 *
673 * @param string $filename
674 * @param string $mode
675 */
676 public function __construct($filename, $mode = 'wb') {
677 $this->filename = $filename;
678 $this->resource = fopen($filename, $mode);
679 if ($this->resource === false) {
680 throw new SystemException('Can not open file ' . $filename);
681 }
682 }
683
684 /**
685 * Calls the specified function on the open file.
686 * Do not call this function directly. Use $file->write('') instead.
687 *
688 * @param string $function
689 * @param array $arguments
690 */
691 public function __call($function, $arguments) {
692 if (function_exists('f' . $function)) {
693 array_unshift($arguments, $this->resource);
694 return call_user_func_array('f' . $function, $arguments);
695 }
696 else if (function_exists($function)) {
697 array_unshift($arguments, $this->filename);
698 return call_user_func_array($function, $arguments);
699 }
700 else {
701 throw new SystemException('Can not call file method ' . $function);
702 }
703 }
704 }
705
706 /**
707 * The File class handles all file operations on a zipped file.
708 *
709 * @author Marcel Werk
710 */
711 class ZipFile extends File {
712 /**
713 * Opens a new zipped file.
714 *
715 * @param string $filename
716 * @param string $mode
717 */
718 public function __construct($filename, $mode = 'wb') {
719 $this->filename = $filename;
720 if (!function_exists('gzopen')) {
721 throw new SystemException('Can not find functions of the zlib extension');
722 }
723 $this->resource = @gzopen($filename, $mode);
724 if ($this->resource === false) {
725 throw new SystemException('Can not open file ' . $filename);
726 }
727 }
728
729 /**
730 * Calls the specified function on the open file.
731 *
732 * @param string $function
733 * @param array $arguments
734 */
735 public function __call($function, $arguments) {
736 if (function_exists('gz' . $function)) {
737 array_unshift($arguments, $this->resource);
738 return call_user_func_array('gz' . $function, $arguments);
739 }
740 else if (function_exists($function)) {
741 array_unshift($arguments, $this->filename);
742 return call_user_func_array($function, $arguments);
743 }
744 else {
745 throw new SystemException('Can not call method ' . $function);
746 }
747 }
748
749 /**
750 * Returns the filesize of the unzipped file
751 */
752 public function getFileSize() {
753 $byteBlock = 1<<14;
754 $eof = $byteBlock;
755
756 // the correction is for zip files that are too small
757 // to get in the first while loop
758 $correction = 1;
759 while ($this->seek($eof) == 0) {
760 $eof += $byteBlock;
761 $correction = 0;
762 }
763
764 while ($byteBlock > 1) {
765 $byteBlock >>= 1;
766 $eof += $byteBlock * ($this->seek($eof) ? -1 : 1);
767 }
768
769 if ($this->seek($eof) == -1) $eof -= 1;
770
771 $this->rewind();
772 return $eof - $correction;
773 }
774 }
775
776 // let's go
777 // get temp file prefix
778 if (isset($_REQUEST['tmpFilePrefix'])) {
779 $prefix = preg_replace('/[^a-f0-9_]+/', '', $_REQUEST['tmpFilePrefix']);
780 }
781 else {
782 $prefix = substr(sha1(uniqid(microtime())), 0, 8);
783 }
784 define('TMP_FILE_PREFIX', $prefix);
785
786 // try to find the temp folder
787 define('TMP_DIR', BasicFileUtil::getInstallTempFolder());
788
789 /**
790 * Reads a file resource from temp folder.
791 *
792 * @param string $key
793 * @param string $directory
794 */
795 function readFileResource($key, $directory) {
796 if (preg_match('~[\w\-]+\.(css|jpg|png|svg|eot|woff|ttf)~', $_GET[$key], $match)) {
797 switch ($match[1]) {
798 case 'css':
799 header('Content-Type: text/css');
800 break;
801
802 case 'jpg':
803 header('Content-Type: image/jpg');
804 break;
805
806 case 'png':
807 header('Content-Type: image/png');
808 break;
809
810 case 'svg':
811 header('Content-Type: image/svg+xml');
812 break;
813
814 case 'eot':
815 header('Content-Type: application/vnd.ms-fontobject');
816 break;
817
818 case 'woff':
819 header('Content-Type: application/font-woff');
820 break;
821
822 case 'ttf':
823 header('Content-Type: application/octet-stream');
824 break;
825 }
826
827 header('Expires: '.gmdate('D, d M Y H:i:s', time() + 3600).' GMT');
828 header('Last-Modified: Mon, 26 Jul 1997 05:00:00 GMT');
829 header('Cache-Control: public, max-age=3600');
830
831 readfile($directory . $_GET[$key]);
832 }
833 exit;
834 }
835
836 // show image from temp folder
837 if (isset($_GET['showImage'])) {
838 readFileResource('showImage', TMP_DIR . 'install/files/acp/images/');
839 }
840 // show icon from temp folder
841 if (isset($_GET['showIcon'])) {
842 readFileResource('showIcon', TMP_DIR . 'install/files/icon/');
843 }
844 // show css from temp folder
845 if (isset($_GET['showCSS'])) {
846 readFileResource('showCSS', TMP_DIR . 'install/files/acp/style/setup/');
847 }
848 // show fonts from temp folder
849 if (isset($_GET['showFont'])) {
850 readFileResource('showFont', TMP_DIR . 'install/files/font/');
851 }
852
853 // check whether setup files are already unzipped
854 if (!file_exists(TMP_DIR . 'install/files/lib/system/WCFSetup.class.php')) {
855 // try to unzip all setup files into temp folder
856 $tar = new Tar(SETUP_FILE);
857 $contentList = $tar->getContentList();
858 if (empty($contentList)) {
859 throw new SystemException("Can not unpack 'WCFSetup.tar.gz'. File is probably broken.");
860 }
861
862 foreach ($contentList as $file) {
863 foreach ($neededFilesPattern as $pattern) {
864 if (preg_match($pattern, $file['filename'])) {
865 // create directory if not exists
866 $dir = TMP_DIR . dirname($file['filename']);
867 if (!@is_dir($dir)) {
868 @mkdir($dir, 0777, true);
869 BasicFileUtil::makeWritable($dir);
870 }
871
872 $tar->extract($file['index'], TMP_DIR . $file['filename']);
873 }
874 }
875 }
876 $tar->close();
877
878 // create cache folders
879 @mkdir(TMP_DIR . 'setup/lang/cache/', 0777);
880 BasicFileUtil::makeWritable(TMP_DIR . 'setup/lang/cache/');
881
882 @mkdir(TMP_DIR . 'setup/template/compiled/', 0777);
883 BasicFileUtil::makeWritable(TMP_DIR . 'setup/template/compiled/');
884 }
885
886 if (!class_exists('wcf\system\WCFSetup')) {
887 throw new SystemException("Can not find class 'WCFSetup'");
888 }
889
890 // start setup
891 new \wcf\system\WCFSetup();