WebCalendar not recognizing logged in users
| Project: | WebCalendar integration |
| Version: | 5.x-1.0-beta1 |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
The integration seems to be working, except that WebCalendar does not recognize when a drupal user is logged in. User access control gives all permissions to an admin user, but when logging in as an admin user on drupal, WebCalendar inside drupal does not seem to recognize that any user is logged in at all. I edited user-app-drupal.php to print out the debug settings and I got this:
uid=0
login=
Array
(
[access webcal] => Array
(
[0] => *
)
[login to webcal] => Array
(
[0] => 2
[1] => 3
[2] => 4
[3] => 5
[4] => 10
)
)
I added this statement to the debug print statements:
print_r( 'same database='.$app_same_db."\n");
and that returned:
same database=1
so I know the database is being shared by webcalendar and drupal.
I also added:
print_r( 'sid='.$sid."\n");
and that returns:
sid=
Clicking on the (login) link in WebCalendar just brings me back to the WebCalendar integrated page in Drupal (which makes sense since Drupal should be handing the login).
Not sure what I should try next. I suspect that the WebCalendar integration php code is looking for a cookie it isn't finding, but I really have no idea.
what am I doing wrong?
Thanks,
-John

#1
I had the same problem and made the following changes to correct it. I am using Drupal 5.3 and WebCalendar 1.1.6
There are two issues at hand:
1. at the point app-user-drupal.php is included WebCalendar doesn't yet know about its own settings. So globals like "$PUBLIC_ACCESS" are unknown, which causes the user_logged_in() function to fail. I resolved this by adding:
load_global_settings();just below the config section, just after the
$app_users_roles_table = $app_db_prefix . 'users_roles';line.2. The user_logged_in() function does not get the right session due to a change in the name of the Drupal session cookie described here http://drupal.org/node/56357
I fixed this by adding a line to define the correct session name in the config section:
// Drupal Session name for this installation// varies with each installation
// examine your cookies to determine correct value
$sid_key = "SESSc5276d63abd0f8b511386b7485f4e44b";
and adding
global $sid_key;inside the user_logged_in() function to pick it up.I then changed
$sid = $_COOKIE['PHPSESSID'];inside the user_logged_in() function to://if all else fails, assume an anonymous user
$sid = '';
$uid = 0;
//get the session key. Could use $_COOKIE here rather than $_REQUEST
if (array_key_exists($sid_key,$_REQUEST)) {
$sid = $_REQUEST[$sid_key];
}
#2
I tried the above and was able to get WebCalendar v1.1.2 integrated with Drupal 5.x using this WebCalendar integration module but I have not been able to get it to work properly with WebCalendar v1.1.4, v1.1.5 and v1.1.6. I have tried both the beta version of the WebCalendar integration module and the dev snapshot.
Using the debug code in user-app-drupal.php, the user_logged_in() function does return the uid of the current user as the $login, as it should. But the login itself does not appear to be working. All I get is the 'Public Access' calendar regardless of the user I am using, the permissions granted, etc. I should be getting the user's calendar. The 'Public Access' calendar is what is automatically served up to anonymous users, from WebCalendar's perspective.
Even logging in as user 1 results in the 'Public Access' calendar.
Does anybody have any idea why the login itself isn't working, or where I could check the code to see what is going on?
I would rather use v1.1.6 for security reasons.
#3
This is the error i got before trying the apove:
"Warning: assert(): Assertion "! empty ( $user )" failed in /Library/Apache2/htdocs/drupal/WebCalendar/includes/access.php on line 335
Error
Error executing query."
and the very same error after:
"Warning: assert(): Assertion "! empty ( $user )" failed in /Library/Apache2/htdocs/drupal/WebCalendar/includes/access.php on line 335
Error
Error executing query."
IT don't work folks, ...back to the drawing with this one.
#4
I tried to install Webcalendar 1.1.6 with Drupal 5.7 and I have the same issue. Trying the above fix does not fix it and produces the same result.
Warning: assert() [function.assert]: Assertion "! empty ( $user )" failed in /var/www/drupal/webcalendar/includes/access.php on line 335
Error
Error executing query.
Is there any progress on the resolution for this?
#5
The second patch here:
http://drupal.org/node/174215
did the trick for me. I applied the patch manually. For some reason, the patch command failed.
-John
#6
Thanks for the info John. I had looked at that post as well but the patch also failed for me when I tried to run it. I had to edit the user-app-drupal.php manually and this is what I did:
I removed the line:
$sid = $_COOKIE['PHPSESSID'];
and at line 86, I added the following:
//Get session name from Drupal
$olddir=getcwd();
chdir('..');
include 'includes/bootstrap.inc';
$oldsavehandler = ini_get('session.save_handler');
conf_init();
ini_set('session.save_handler', $oldsavehandler);
chdir($olddir);
$sid = $_COOKIE[session_name()];
Now, I don't get the previous error anymore but, now I get the problem of the Drupal user not being recognized on Webcalendar. I keep seeing the Public Access Calendar for all users including the Admin.
After making the changes as mentioned here http://drupal.org/node/174215, do I now have to apply the changes mentioned at the beginning of this post by Atratus?
#7
WebCalendar 1.1.6 working with Drupal 5.7
[Drupal 5.7, MySQL 5.0.45, PHP 5.2.4, Apache/2.2.6 (Win32)]
I used info gathered from Akom 174215 and Atratus 176815 to get things working. I must confess limited Drupal knowledge so my efforts are still a hack. But it does get WebCalendar 1.1.6 up and working inside Drupal and iFrame. New to WebCalendar but limited testing seems to show it working correctly.
I also tried the 'patch-user-app-drupal_0.txt' from 174215 but I could not get the module to access the Drupal session_name. Hard coding the session_name does work but there must be a way to get to this as a variable.
How can Drupal's session_name be accessed without hard coding value?
Doug
------------------------------------------------
Issues as I see them:
1) Drupal uses session_name which is a MD5 hash of the base drupal URL not PHPSESSID as used in WebCalendar integration 5.x-1.0-beta1. The sessions table contains the Drupal session_name not the PHPSESSID. When the sessions table is searched for the uid it never matches the PHPSESSID used by the 'user_logged_in' function in user-app-drupal.
Solution:
Change to 'user-app-drupal.php' to use Drupal session_name:
line 89:
global $app_host, $app_login, $app_pass, $app_db, $app_same_db;
global $c, $db_host, $db_login, $db_password, $db_database;
- $sid = $_COOKIE['PHPSESSID'];
+ //set up default to be anonymous user
+ $sid = '';
+ $uid = 0;
+ //Hard code Drupal session_name.
+ $sid = $_COOKIE['SESSf44e5c85323a4a4953144429cd5e1f25'];
if ($app_same_db != '1') $c = dbi_connect($app_host, $app_login, $app_pass, $app_db);
2) Endless loop when calendar accessed.
Solution:
[2008-March-21 Please note: corrections to example below have been made in regards to eevul's comments below.]
Change to 'includes/classes/WebCalendar.class' line 568:
// Use another application's authentication.- if ( $login != user_logged_in () )
+ if ( ! $login = user_logged_in () )
//echo "Setting to not found";
$session_not_found = true;
}
#8
I made the changes as you recommended and now I am getting the proper login. One problem that I saw was a minor difference though as line 568 from /webcalendar/includes/classes/WebCalendar.class seems to be different from your example above as mine is missing the "{" as seen below:
// Use another application's authentication.
if ( $login != user_logged_in () )
$session_not_found = true;
}
I left my file without the "{" and it worked fine. Initially, I had just copied and pasted yours but I was getting a function error. Anyway, it looks like it is working fine for now. I will keep playing with this module to see if it is worthwhile but so far, it looks like it will do the trick.
Thanks again for the help on this.
#9
part of original post removed because it was wrong...I need to improve my code reading ;)
With the new information, its time for me to look at installing 1.1.6 again. Using Drupal, I wasn't able to get webcalendar to log in with any version other than 1.1.2. It looked like it worked, but only the public access calendar would work since it would fail to authenticate.
#10
Your correct Eevul. The '{' is a typo and does cause an error further down in the code. I did a reinstall of WebCalendar and it got me... I will remove it from my example above.
Thanks,
Doug
#11
Thanks for the update Doug. Now if I could get Drupal with LDAP and Webcalendar working, I would be a happy man.
Ed
#12
This worked for me with WebCalender 1.1.6 and Drupal 5.7. I didn't realise at first that '-' character meant to remove the line and '+" meant to add (stupid mistake, I know). Originally I was just copying and pasting. I guess thats the price of being a newbie.
I wanted to post this in case any one else is doing the same.
One question though, does drupal session ID ever change? If so, is there a way to keep track of it for $sid?