1.5.7 plugins don't load (rewinddir fails on server)

A place to report and discuss bugs - please mention CMSimple-version, server, platform and browser version
Post Reply
frost
Posts: 2
Joined: Wed May 22, 2013 7:00 am
Location: Finland

1.5.7 plugins don't load (rewinddir fails on server)

Post by frost » Wed May 22, 2013 7:32 am

Hi.

This is more server side problem than CMSimple problem, so I just document what I did. Probably dependes on apache version/configuration (?).

Background: I uploaded CMSimple_XH 1.5.7 to home page space offered by my service provider (so this is not even proper webhotel; no possiblity to change server configuration). What I noticed is that plugins did not load; for example WYSIWYG editor didn't have the "Meta" and "Page" tabs. When I looked the page source, I noticed that there was only one plugin line (<link rel="stylesheet"...), the pluginloader, and the others (like filebrowser and meta_tags) were missing.

Solution: I found that the plugins/index.php rewinddir() function, for some reason, does not work in this server (Apache 2.2.24).

So, I simply replaced rewinddir with closedir/opendir:

Code: Select all

/**
 * Bridge to page data
 */
 :
} // while (FALSE !== ($plugin = readdir($handle)))*/

// rewinddir replaced by closedir/opendir as server does not handle rewind
// rewinddir($handle);
closedir($handle);
$handle = opendir($pth['folder']['plugins']);

while (FALSE !== ($plugin = readdir($handle))) {
:
-- frost

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: 1.5.7 plugins don't load (rewinddir fails on server)

Post by cmb » Wed May 22, 2013 10:58 am

Hi frost,

thanks for reporting this issue. I'm not sure why rewinddir() fails on your server, but I have noticed that there is no closedir() at all in the original code. I wouldn't be too surprised, if that is causing the rewinddir() to fail.

In line 164 there's an opendir(), which is not closed until the same directory is opened again in line 206. IMO the first opendir() should be closed after line 176, and the second opendir() should be closed after line 262. In both cases:

Code: Select all

closedir($handle);
Could you please test, if that works on your server (with the original rewinddir()). If not, you might enable the XH debug mode to see what error message is reported by PHP.

Anyway, I suggest to add at least the closedir() calls in CMSimple_XH 1.1.7 and 1.5.8. For CMSimple_XH 1.6 the plugin directory will be traversed only once (caching the results in a variable), so there'll be definitely no issue regarding rewinddir().

Christoph
Christoph M. Becker – Plugins for CMSimple_XH

frost
Posts: 2
Joined: Wed May 22, 2013 7:00 am
Location: Finland

Re: 1.5.7 plugins don't load (rewinddir fails on server)

Post by frost » Wed May 22, 2013 12:04 pm

Hi.
cmb wrote:In line 164 there's an opendir(), which is not closed until the same directory is opened again in line 206. IMO the first opendir() should be closed after line 176, and the second opendir() should be closed after line 262. In both cases:

Code: Select all

closedir($handle);
Could you please test, if that works on your server (with the original rewinddir()).
Did this, no effect.

If not, you might enable the XH debug mode to see what error message is reported by PHP.

The debug mode says:
WARNING: rewinddir() has been disabled for security reasons
/home/f/r/frost/public_html/cms/plugins/index.php:222
So this might be the reason (code line in error message is a bit off from the original because of comments).
Guess I have to keep my solution with open/close.

-- frost

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: 1.5.7 plugins don't load (rewinddir fails on server)

Post by cmb » Wed May 22, 2013 12:29 pm

Hi frost,

thanks for investigating the issue further.
WARNING: rewinddir() has been disabled for security reasons
I'm quite puzzled that rewinddir() is disabled for security reasons, but opendir()/readdir() isn't. Seems a bit strange to me.
frost wrote:Guess I have to keep my solution with open/close.
If your provider won't change the respective PHP ini setting (may be disable_functions or maybe suhosin.executor.func.blacklist; you can check that in CMSimple_XH under Settings->Info->PHP Info), you'll have to stick with the modification.

It may be considered to change that accordingly for CMSimple_XH 1.5.8; another opendir()/closedir() is probably a bit slower than the rewinddir(), but it shouldn't hurt.

Christoph
Christoph M. Becker – Plugins for CMSimple_XH

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: 1.5.7 plugins don't load (rewinddir fails on server)

Post by cmb » Wed Jul 24, 2013 11:19 am

cmb wrote:Anyway, I suggest to add at least the closedir() calls in CMSimple_XH 1.1.7 and 1.5.8.
After reconsideration of the issue, it seems that this is the most reasonable solution (r798).
Christoph M. Becker – Plugins for CMSimple_XH

Post Reply