From 8d67a8290c8b2e1dc34f310a47805f9e501eb99c Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Wed, 11 Sep 2019 12:29:09 +0100 Subject: [PATCH] Add *all* the error messages to the unpacker --- core/07-unpack.php | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/core/07-unpack.php b/core/07-unpack.php index 067cbf4..cb87b4e 100644 --- a/core/07-unpack.php +++ b/core/07-unpack.php @@ -6,14 +6,33 @@ // ...extract it again if(!file_exists($paths->extra_data_directory) || filemtime(__FILE__) > filemtime($paths->extra_data_directory)) { + + $error_message_help = "

Have you checked that PHP has write access to the directory that index.php is located in (and all it's contents and subdirectories)? Try sudo chown USERNAME:USERNAME -R path/to/directory and sudo chmod -R 0644 path/to/directory; sudo chmod -R +X path/too/directory, where USERNAME is the username that the PHP process is running under.

"; + if(file_exists($paths->extra_data_directory)) delete_recursive($paths->extra_data_directory, false); - else - mkdir($paths->extra_data_directory, 0700); - touch($paths->extra_data_directory); + else { + if(!mkdir($paths->extra_data_directory, 0700)) { + http_response_code(503); + exit(page_renderer::render_minimal("Unpacking error - $settings->sitename", "

Oops! It looks like $settings->sitename couldn't create the extra data directory to unpack additional files to.

$error_message_help")); + } + } + + if(!touch($paths->extra_data_directory)) { + http_response_code(503); + exit(page_renderer::render_minimal("Unpacking error - $settings->sitename", "

Oops! It looks like $settings->sitename isn't able to change the last modified time of the extra data directory.

$error_message_help")); + } $temp_file = tmpfile(); + if($temp_file === false) { + http_response_code(503); + exit(page_renderer::render_minimal("Unpacking error - $settings->sitename", "

Oops! $settings->sitename wasn't able to create a new temporary file with tmpfile(). Perhaps your server is mis-configured?

")); + } $source = fopen(__FILE__, "r"); + if($source === false) { + http_response_code(503); + exit(page_renderer::render_minimal("Unpacking error - $settings->sitename", "

Oops! $settings->sitename wasn't able to open itself (i.e. index.php) for reading. $error_message_help

")); + } fseek($source, __COMPILER_HALT_OFFSET__); stream_copy_to_stream($source, $temp_file); @@ -24,5 +43,10 @@ if(!file_exists($paths->extra_data_directory) || $extractor->open($temp_filename); $extractor->extractTo($paths->extra_data_directory); $extractor->close(); - fclose($temp_file); + if(fclose($temp_file) === false) { + http_response_code(503); + exit(page_renderer::render_minimal("Unpacking error - $settings->sitename", "

Oops! $settings->sitename wasn't able to close the temporary file that it created with tmpfile(). Perhaps your server is mis-configured?

")); + } + + unset($error_message_help); }