soderlind / read-offline

Read Offline allows you to download or print posts and pages. You can download the post as PDF, ePub and mobi
https://wordpress.org/plugins/read-offline/
31 stars 10 forks source link

"Access denied" everywhere in admin when Read Offline activated #18

Closed kerray closed 9 years ago

kerray commented 9 years ago

After upgrading to WP 4.1, Read Offline was deactivated because of a missing file (I think, I didn't pay attention to the message). When I activated it again, all admin pages just show a blank page with Access Denied in the middle, and wp-login page throws a 404.

When I delete read-offline directory from plugins, everythings runs smoothly again.

When I install it, it says it's installing version 0.2.2, but the filename says 0.2.3

When I activate it, I get to go to the configuration page, but when I save it, it's Access Denied all over again.

I tried to delete settings from database, this helps, but only until I save the Read Offline settings again - and it doesn't matter which tab I save.

Thanks for any ideas.

soderlind commented 9 years ago

Please download and install the latest version from GitHub.

soderlind commented 9 years ago

.. github will allways have the latest version (and my sync github with wordpress plugin directory script is broken, and I haven't had time to fix it .. yet)

kerray commented 9 years ago

Thanks, I should've tried it earlier :)

soderlind commented 9 years ago

It works fine with the latest version ?

kerray commented 9 years ago

Well, turns out that no - however instead of Access denied, it just keeps the whole page blank after saving any page of configuration. Deleting Read_Offline_Admin_Settings from wp_options helps, but the plugin itself still can't be used.

I have this in log: 2015/02/06 22:26:41 [error] 2310#0: *14064 FastCGI sent in stderr: "PHP message: PHP Parse error: syntax error, unexpected '[' in www/wp-con tent/plugins/read-offline/class-read-offline-parser.php on line 185" while readi ng response header from upstream, client: 1.1.1.1, server: xxx.cz, r equest: "GET /wp-admin/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: " xxx.cz"

the line in question contains $epub_file = sprintf("%s/%s",wp_upload_dir()['basedir'],$rel_url);

soderlind commented 9 years ago

Fixed in latest release https://github.com/soderlind/read-offline/commit/3a5e3a18e131eda72b4c6f7240834fa29e62e9a6, please download the latest version here at GitHub,

Note, I haven't changed the plugin version number.

kerray commented 9 years ago

I have uploaded the new version and it didn't help. I could log some extended debugging information or something...

soderlind commented 9 years ago

Yes please.It works fine on my test servers (nginx and apache)

kerray commented 9 years ago

Well, I'm running Nginx with php5-fpm, and I can't get any more errors to appear in the log. I just get access denied and no error gets written. I tried turning on WP_DEBUG, and there's a single (legitimate) warning from another plugin.

The permissions on read-offline directory and files are the same as on all the other plugin dirs and files.

I tried inserting various error_log statements into the code and wasn't able to find the problem.

If you have any idea what to try, I'll try it.

BTW I've noticed that after saving the configuration, the buttons start appearing in the site, except they throw a page not found.

soderlind commented 9 years ago

The plugin tries to create, and needs, a cache: WP_CONTENT . '/cache/read-offline', it should give you a "nice" error message if it couldn't create the cache

$directories = array(WP_CONTENT_DIR . '/cache/read-offline/tmp', WP_CONTENT_DIR . '/cache/read-offline/font');

foreach ($directories as $directory) {
    if (! wp_mkdir_p ($directory) ) {
        return add_action( 'admin_notices', function(){
            $msg[] = '<div class="error"><p>';
            $msg[] = '<strong>Read Offline</strong>: ';
            $msg[] = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?','read-offline' ), $directory );
            $msg[] = '</p></div>';
            echo implode( PHP_EOL, $msg );
        });
    }
}

Does WP_CONTENT_DIR . '/cache/' exist and is it writable?

kerray commented 9 years ago

There we go - it doesn't exist, and there's no error message, perhaps because the whole admin section just throws Access Denied instead of displaying anything.

I've added some logging throughout class-read-offline.php When I save the options, it ends up calling wp_die("hepp"), probably since there's no cache/tmp dir

When I try to open another admin page, it creates the class instance, and then goes to read offline update and tries to remove tmp dirs again, so again it just ends on wp_die.

But even if I create the wp-content/cache/read-offline/tmp and /font and even wp-content/cache/read-offline-tmp, and chown them to my user and the web-data group with write access to both, it still crashes the same way, trying to remove those tmp dirs, on every admin page.

kerray commented 9 years ago

Oh, but when I commented out $this->_remove_tmp_directories(); in read_offline_update(), the options get saved, the admin is up and running, and the files get downloaded correctly. Yay.

My logging says that the _create_tmp_directories passes OK (with my manually created directories), however they seem to be empty (might be OK though).

soderlind commented 9 years ago

It's a bug if the folder can't be created and you don't get an error message. I'll update this feed when it's fixed (meaning you should get an error message telling you to create a writeable WP_CONTENT_DIR . '/cache/'). The cache directory is needed for the mPDF library, and I don't want it to be in the library/mpdf60folder

soderlind commented 9 years ago

Rewrote _create_tmp_directories, please test the latest version here at GitHub, plugin version number is still 0.2.8

kerray commented 9 years ago

Instead of crashing it now reports

Read Offline: Unable to create directory "/home/xxx/www/wp-content/cache". Is its parent directory writable by the server?

So now I just have to find out why it doesn't have rights when it should - but everything seems to work regardless.

Thanks!