Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moodle authentication breaks elfinder (or vice-versa) #222

Closed
usernamenumber opened this issue Apr 6, 2015 · 4 comments
Closed

Moodle authentication breaks elfinder (or vice-versa) #222

usernamenumber opened this issue Apr 6, 2015 · 4 comments

Comments

@usernamenumber
Copy link
Contributor

I have Moodle authentication enabled, and doing anything that runs elfinder, like trying to upload an image to a page, results in a Data is not JSON error. This usually means the server can't write to USER_FILES/, but not this time.

elfinder makes an AJAX call to editor/elfinder/php/connector.php, expecting back AJAX, but connector.php has the following code:

if (!isset($_SESSION['toolkits_logon_id'])){
    header("location: ../../../index.php");
}

If you are using Moodle authentication, XOT just piggybacks on Moodle's session, and in fact auth_config.php avoids running session_start() to avoid "squashing" Moodle's session data. elfinder, unfortunately, doesn't know this and uses PHP's session or starts a new one, and $_SESSION only contains elfinder's session values.

This can be demonstrated by running session_id() on an XOT page and an elfinder page. The former will return the value of $_COOKIE['MoodleSession'], while the latter will return the value of $_COOKIE['PHPSESSID].

I'm not sure what the best solution to this is other than having Moodle authentication not try to use Moodle's session (is this even really needed if all we want is authentication?), or modifying the XOT version of elfinder to not start a new session. I've tried doing this with session_name('MoodleSession') in connector.php, and while session_id() returns the ID of Moodle's session after that, $_SESSION continues to only have elfinder's session data. This could just be me not fully understanding how PHP sessions work, though.

@ronm123
Copy link
Collaborator

ronm123 commented Apr 10, 2015

I've just had this problem on a test xampp install and remember having similar problems previously...

I've been testing some stuff on a localhost xampp installation on and off over the last few days and again this morning. This is recent develop code but not the very latest. I'm not sure what caused this but now when I try to edit an existing or new LO and browser for media I get the following error:

Invalid backend response. Data is not JSON.

This happens regardless of account, browser, project etc and I've completely shut down xampp, cleared session files and re-started but still the same problem. I remember having similar problems in a much earlier test version on the Techdis server where there was more than one install and liaising with Tom but never resolving it then and in this local xampp instance there's only a singe XOT install. It also inside a Moodle directory like the Techdis server was but has been working fine until this problem arose this morning and now even with auth_config set to guest or static effectively the install is broken because it's not possible to browse for media. In this case I can potentially just scrap and replace the install but I seem to recall when I tried that on the Techdis server previously it didn't resolve the problem and I'm worried about this happening on live installations. There are plenty using Moodle for authentication.

This happens when the pop-up opens:
http://localhost/moodle/xerte/editor/elfinder/browse.php?type=media&lang=en

And the FF console shows 2 repeat errors:
Line 1339 toolbox.js
console.log('Browse file: ' + id + ': ' + key + ', ' + name + ', ' + value);

@ronm123
Copy link
Collaborator

ronm123 commented Apr 10, 2015

Exploring this further I first tried using the purge all caches function via Moodle admin and same problem existed.
I then removed the integration_path from site_details and tried again via guest and all worked fine.
I then re-added the integration_path and tested again via guest and all still worked fine.
Changed auth_config back to using Moodle authentication and all still working fine.
Not sure if that helps apart from seemingly being a fix for a previously working install using Moodle authentication that had become broken but works again after removing and re-adding the integration_path. I guess somewhere these steps are killing the conflicting session or cache but not sure what's causing the conflict in the first place and clearly that's what we need to identify.
Ron

@torinfo
Copy link
Collaborator

torinfo commented Apr 11, 2015

Brad,

connector.php is custom code (written by me). Could you try the following:

//session_start();

require_once(dirname(__FILE__).DIRECTORY_SEPARATOR."../../../config.php");

It will start the session in exactly the same way as it is started in other parts of Xerte. I've verified that this keeps working in normal circumstances. Could you please check if this solves your issue? Than I will commit the fix.

@usernamenumber
Copy link
Contributor Author

This works! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants