From 460c77f1167c5e4964154bc6585f387bf9e86d21 Mon Sep 17 00:00:00 2001 From: Eric van der Vlist Date: Sun, 3 May 2020 11:22:24 +0200 Subject: [PATCH] Check that the archive directory is writable --- owark.php | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/owark.php b/owark.php index 6378fc6..caebee1 100644 --- a/owark.php +++ b/owark.php @@ -25,6 +25,18 @@ Author URI: http://eric.van-der-vlist.com License: GLP2 */ +/* + Log + */ +if ( ! function_exists('print_r_log')) { + function print_r_log ( $log ) { + if ( is_array( $log ) || is_object( $log ) ) { + error_log( print_r( $log, true ) ); + } else { + error_log( $log ); + } + } +} if (!class_exists("Owark")) { class Owark { @@ -93,6 +105,8 @@ if (!class_exists("Owark")) { */ function sanity_checks(){ + // print_r_log("Sanity checks"); + // Install or upgrade tables if needed $installed_ver = get_option( "owark_db_version" ); @@ -137,13 +151,15 @@ if (!class_exists("Owark")) { } // Check if we have an archive subdirectory - - if (!is_dir(dirname(__FILE__) . '/archives')) { - @mkdir(dirname(__FILE__) . '/archives'); - if (!is_dir(dirname(__FILE__) . '/archives')) { + $archives_dir = dirname(__FILE__) . '/archives'; + if (!is_dir($archives_dir)) { + @mkdir($archives_dir); + if (!is_dir($archives_dir)) { $this->notices = $this->notices . "

The Open Web Archive has not been able to create the folder /archives in its installation directory. Please create it by hand and make it writable for the web server.

"; } - } + } elseif (! is_writable($archives_dir)) { + $this->notices = $this->notices . "

The Open Web Archive needs a writable folder /archives in its installation directory. Please make it writable for the web server.

"; + } // Check that we can execute commands @@ -546,6 +562,7 @@ if (!class_exists("Owark")) { AND broken=0 AND final_url!=''"; $url = $wpdb->get_row($query); + print_r_log($url); $wpdb->flush(); if ($url != NULL) { @@ -558,7 +575,7 @@ if (!class_exists("Owark")) { $status = 0; exec("wget -t3 -E -H -k -K -p -nd -nv --timeout=60 --user-agent=\"Mozilla/5.0 (compatible; owark/0.2; http://owark.org/)\" -P $path {$url->final_url}", $output, $status); - + print_r_log("wget status: $status"); $q = $wpdb->insert("{$wpdb->prefix}owark", array( 'url' => $url->final_url, 'status' => $status,