Gossamer Forum
Home : Products : DBMan : Customization :

Cookies Mod

Quote Reply
Cookies Mod
I am going bananas! Crazy I have tried to install the cookie mod that Old Money made. No matter what I do, I get:

"DBman has encountered an internal error. Please enable debugging to view"

I have looked over the code so many times my eyes hurt. Unsure

Could you please look to see if I missed anything?

1. downloaded Matt's Cookie Library & put in the variable:

$Cookie_Domain = '.aallsafe.com';

2. In my .cgi under required libraries I added (in blue):

require "$db_setup.cfg"; # Database Definition File
require "auth.pl"; # Authorization Routines
require 'cookie.lib'; # Session Cookie Mod

3. In my cgi sub main I added (in blue):

elsif ($in{'change_email'}) { unless ($db_userid eq "default") { &change_email; } else { &html_unauth; } }
elsif ($in{'logoff'}) { &auth_logging('logged off') if ($auth_logging);
&SetCookies('session',' ');
(-e "$auth_dir/$db_uid") and ($db_uid =~ /^[\A-Za-z0-9]+\.\d+$/) and unlink ("$auth_dir/$db_uid");
$auth_logoff ? (print "Location: $auth_logoff\n\n") : (print "Location: $db_script_url\n\n");
}
elsif ((keys(%in) <= 2) ||
($in{'login'})) { &html_home; }
else { &html_unkown_action; }
}

In the auth.pl, I changed as instructed to (changes in blue):

open(AUTH, ">$auth_dir/$db_uid") or &cgierr("unable to open auth file: $auth_dir/$uid. Reason: $!\n");
print AUTH "$view:$add:$del:$mod:$admin:$ENV{'REMOTE_HOST'}\n"; # Session Cookie Mod
close AUTH;
foreach (0 .. 3) { $permissions[$_] = int($permissions[$_]); }
&auth_logging('logged on', $userid) if ($auth_logging);
&SetCookies('session',$db_uid); # Session Cookie Mod
return ('ok', $db_uid, $view, $add, $del, $mod, $admin);

}
}
return ("invalid username/password");
}
elsif ($db_uid) { # The user already has a user id given by the program.
(-e "$auth_dir/$db_uid") ?
return ('ok', $db_uid, &auth_check_permissions($db_uid)) :
return ('invalid/expired user session');
}
else { # Session Cookie Mod
&GetCookies('session');
if (length($Cookies{'session'}) > 4) {
$db_uid = $Cookies{'session'};
if (-e "$auth_dir/$db_uid") {
open(AUTH, "<$auth_dir/$db_uid") or &cgierr("unable to open auth file: $auth_dir/$uid. Reason: $!\n");
@perm = ;
close AUTH;
($view, $add, $del, $mod, $admin, $host) = split (/:/, @perm[0]);
return ('ok', $db_uid, $view, $add, $del, $mod, $admin); }
else { return ('invalid/expired user session'); }
}
else { return 'no login'; }
}
}

I have started over about 6 times now & I keep getting the same error. Yet, when I revert back to my original auth.pl & cgi my script again works fine.

Any advice would be greatly appreciated.
Diana Rae
Quote Reply
Re: [dianarae] Cookies Mod In reply to
OK I got the following error in DBMan which says:

CGI ERROR
==========================================
Error Message : Error loading required libraries.
Check that they exist, permissions are set correctly and that they compile.
Reason: syntax error at auth.pl line 88, near "= ;"

Line 88 is this:

@perm = ;

Which is exactly what the MOD has. Any ideas?
Diana Rae

Last edited by:

dianarae: Jan 27, 2002, 6:27 PM
Quote Reply
Re: [dianarae] Cookies Mod In reply to
Diana, the errors are being reported on that line however, the error is oftentimes on lines just before the errors. In the snipet of code you've posted, there is a double } (curly bracket) at the end.



return ('ok', $db_uid, $view, $add, $del, $mod, $admin);
}
}

return ("invalid username/password");
}


Perhaps one of those curly brackets belong at the start of the new code. ???

}
open(AUTH, ">$auth_dir/$db_uid") or &cgierr("unable to open auth file: $auth_dir/$uid. Reason: $!\n");


rest of code ...



return ('ok', $db_uid, $view, $add, $del, $mod, $admin);
}
return ("invalid username/password");
}




~ Karen
Quote Reply
Re: [Karen] Cookies Mod In reply to
Yes, Karen thank you...you are right I did have 1 too many curly brackets. I didnt see you post & I had edited that above to reflect what the DBMan log says instead of my server log.

Even with removing that curly bracket I still get that error on line 88:

Reason: syntax error at auth.pl line 88, near "= ;"

Yet it is exactly the way the sub is. Frown



Diana Rae
Quote Reply
Re: [dianarae] Cookies Mod In reply to
hmm I just noticed that the very top of the auth.pl has:

my ($pass, @passwd, $userid, $pw, @permissions, $file, $uid);

and no where else can I find the word @perm.

Is it possible it should really be spelled out @permissions?
Diana Rae
Quote Reply
Re: [dianarae] Cookies Mod In reply to
No. That isn't it. Unsure
Diana Rae
Quote Reply
Re: [dianarae] Cookies Mod In reply to
Diana, try both single and double quotes:

@perm = "";

or

@perm = '';
Quote Reply
Re: [Karen] Cookies Mod In reply to
Thank you, Karen.

That got rid of the error. Now to see how this works! Laugh
Diana Rae
Quote Reply
The other Cookies Mod In reply to
After I installed the Cookies mod by Oldmoney, I decided to give a shot to Eli Finkelman's "Save Login Info MOD".

I got the entire thing working...except it doesnt "remember" me when I try to log on later. Do me a favor anyone and go here (its just a test page):

Use Name: User password: test

at:

http://www.aallsafe.com/...ter/test/members.cgi

and see if it remembers you? Yes, I did remember to put the .cfg...right in the middle I have:

# Allows User to Save Cookies
# --------------------------------------------------------
# Allows saved cookies
$print_get_cookies = "1";

Still will not work for me and I tried it on 2 different computers (one IE 5.0) the other (IE 6.0).

I would appreciate anyone trying it as perhaps it does work & it's just me doing something wrong. Tongue

Thanks!
Diana Rae
Quote Reply
Re: [dianarae] The other Cookies Mod In reply to
It didn't remember me Frown

but it is writing the cookie:

Code:
username
User
www.aallsafe.com/NOR/roster/test/
0
241837056
29542314
2624913152
29468888
*
password
test
www.aallsafe.com/NOR/roster/test/
0
241837056
29542314
2624913152
29468888
*
remember_login
on
www.aallsafe.com/NOR/roster/test/
0
241837056
29542314
2625413152
29468888
*

So it must be something with the "get cookie" or "read" part (?).

I use the cookie mod that you are using and it does work, so hopefully that will help point you in the right direction.

Good Luck!
Quote Reply
Re: [Watts] The other Cookies Mod In reply to
OK I give. Pirate

The "save cookie mod" is not working for me.

I just don't see what is wrong. Unsure I have the "sub" exactly as it shows (I actually cut it and pasted it - so nothing was typed by hand).

I would appreciate if anyone could look below see anything wrong here to let me know.

I know it has to work, but if there was something changed in this sub..it sure isn't posted in this forum - I have looked for 2 days.

P.S. I do have the secure password lookup mod on this test and that code was added in the log on.

--------------------

Added right in the middle of my .cfg file:

# Allows User to Save Cookies
# --------------------------------------------------------
# Allows saved cookies
$print_get_cookies = "1";


the cookie sub (added to my html.pl) - this was copy & paste by the way - I changed nothing):

sub cookie {
# --------------------------------------------------------

print qq~
<SCRIPT LANGUAGE=JAVASCRIPT>
// Extract the value from the cookie at the given offset.

function GetValue( Offset )
{
var End = document.cookie.indexOf (";", Offset);
if( End == -1 )
End = document.cookie.length;

// Return the portion of the cookie beginning with the offset
// and ending with the ";".

return unescape( document.cookie.substring( Offset, End) );
}

function GetCookie( Name )
{
var Len = Name.length;

// Look at each substring that's the same length as the cookie name
// for a match. If found, look up the value and return it.

var i = 0;
while( i < document.cookie.length )
{
var j = i + Len + 1;
if( document.cookie.substring( i, j) == (Name + "=") )
return GetValue( j );
i = document.cookie.indexOf( " ", i ) + 1;
if( i == 0)
break;
}
var a = "";
return a;
}

// Create or change a cookie given its name and value. The name and value
// are required, but the expiration date isn't. Note that if you don't specify
// an expiration date, the cookie only exists for the current session.

function SetCookie( Name, Value, Expire )
{
document.cookie = Name + "=" + escape( Value ) + ";expires=" + Expire;
}

// Write all the cookies for the form1 form.

function WriteCookies()
{
// var Expire = "Friday,25-Feb-2000 12:00:00 GMT";
var Expire = "$cookie_expiration_date";

with( document.form1 )
{
SetCookie( "username", userid.value, Expire );
SetCookie( "password", pw.value, Expire );
}
}

// Load the form with the values in the cookie

function GetCookies()
{
with( document.form1 )
{
userid.value = GetCookie( "username" );
pw.value = GetCookie( "password" );
auth_remember_login.value = GetCookie( "remember_login" );

if ( auth_remember_login.value == "on" ) {
auth_remember_login.checked = true; }

}
}

function FixCookieDate (date) {
var base = new Date(0);
var skew = base.getTime(); // dawn of (Unix) time - should be 0
if (skew > 0) // Except on the Mac - ahead of its time
date.setTime (date.getTime() - skew);
}

var expdate = new Date ();
FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 365)); // 365 days from now

function IsValid()
{
blnValid = true;

with( document.form1 )
{
if(( userid.value == "" ) || ( pw.value == "" ))
{
window.alert( "You must enter both your user name and your password" );
blnValid = false;
}

var Username = userid.value;
var Password = pw.value;

if (auth_remember_login.checked) {
var Remember_login = "on";
}

}
if( blnValid )

if (Remember_login == "on") {
document.cookie = "username=" + Username + ";expires=" + expdate.toGMTString() + ";";
document.cookie = "password=" + Password + ";expires=" + expdate.toGMTString() + ";";
document.cookie = "remember_login=" + Remember_login + ";expires=" + expdate.toGMTString() + ";";
}

if (Remember_login != "on") {
var Expires = "-1";
document.cookie = "username=" + Username + ";expires=" + Expires + ";";
document.cookie = "password=" + Password + ";expires=" + Expires + ";";
document.cookie = "remember_login=" + Remember_login + ";expires=" + Expires + ";";
}

return blnValid;
}

</SCRIPT>~;
}


my Log in script:

sub html_login_form {
# --------------------------------------------------------
# The login screen.

$page_title = "Rathe Duchy Member Log On";
&html_page_top;

$submit_button = "Logon";
$reset_button = "Cancel";

# < -- Start page text -- >

&html_print_headers;
print qq|
<html>
<head>
<center>
<br>
<title>$html_title</title>
</head>
<body bgcolor="#DDDDDD" text="#000000"
|;
if ($print_get_cookies) { print qq~ onLoad="GetCookies()" onLoad="top.window.focus()" onLoad="document.form1.userid.focus()"~; }
print qq|>|;
&cookie;
# < -- End page text -->

if ($auth_signup) {
print qq|
<br>If you do not yet have an account, you may <a href="mailto:dianaraes\@hotmail.com,dianarae\@bellsouth.net">sign up for one here.</a><BR>|;
}
print qq|
<br> If you have forgotten your password, you may <a href="$db_script_url?db=$db_setup&lookup_form=1">receive a new password here.</a>
<p>
<form action="$db_script_url" method="POST" name="form1" OnSubmit="return IsValid()">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
<table border=0>
<tr><td><Font face="Verdana, Arial, Helvetica" Size=2 Color="#200000"><b>User ID:</b></FONT></td>
<td><input type="TEXT" name="userid"></td></tr>
<tr><td><Font face="Verdana, Arial, Helvetica" Size=2 Color="#200000"><b>Password:</b></FONT></td>
<td><input type="PASSWORD" name="pw"></td></tr>
<tr><td colspan=2><Font face="Verdana, Arial, Helvetica" Size=2 Color="#200000"><b>Remember username and password for future logins?</b></FONT>
<INPUT type="checkbox" name="auth_remember_login">
</td></tr>
</table>
<center>
<input type="SUBMIT" name="login" value="$submit_button">
<INPUT TYPE="SUBMIT" NAME="logoff" VALUE="$reset_button"></center></form> |;

&html_page_bottom;
}

Anyone have any clues? I have tried this on 4 computers now (3 differents ones have IE 6.0 & 1 was IE 5.0) & have re-done the MOD 3 times now & it will not work. Frown

http://www.aallsafe.com/...ter/test/members.cgi

Thanks so much for your help.




Diana Rae
Quote Reply
Re: [dianarae] The other Cookies Mod In reply to
This line could be a problem:

// var Expire = "Friday,25-Feb-2000 12:00:00 GMT";

notice that it will expire in 2000, you should change that to at least 2002.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [dianarae] The other Cookies Mod In reply to
Ok, stabbing in the dark here... Save a copy of your db in a different directory and try it without the "secure password look up mod". Could there be a conflict? What does your login mod look like?

Here is what I have for a login sub (attached at bottom) for reference, save it to disk and open in text-editor.

<edit>sorry didn't notice you'd posted the login sub in your above post</edit>

Last edited by:

Watts: Jan 30, 2002, 8:44 AM
Quote Reply
Re: [Watts] The other Cookies Mod In reply to
Two more "wild guesses"..

1. You're using this:
Code:
onLoad="GetCookies()" onLoad="top.window.focus()" onLoad="document.form1.userid.focus()"

which translates into this:
Code:
<body bgcolor="#DDDDDD" text="#000000"
onLoad="GetCookies()" onLoad="top.window.focus()" onLoad="document.form1.userid.focus()">

Try changing it to this:
Code:
<body bgcolor="#DDDDDD" text="#000000"
onLoad="GetCookies();top.window.focus();document.form1.userid.focus();">

You have multiple "onLoad" calls that could be a problem.


2. Your <BODY> tag has physical line break in it. Take it out in your html.pl (not a <BR> tag, but a "carriage return")

change this:
Code:
<body bgcolor="#DDDDDD" text="#000000"
|; if ($print_get_cookies) { print qq~ OnLoad="GetCookies()"~; }

to this:
Code:
<body bgcolor="#DDDDDD" text="#000000" |; if ($print_get_cookies) { print qq~ OnLoad="GetCookies()"~; }

which causes it to print this was in your login page. Javascript doesn't like hard returns in some cases.

See if that helps.

Ps: I compared the sub cookie routine you pasted with the original (TextPad --> compare files - what a useful tool) and they are for all practical purposes identical - so you *know* you are not crazy!

Last edited by:

Watts: Jan 30, 2002, 9:06 AM
Quote Reply
Re: [Watts] The other Cookies Mod In reply to
Oh my goodness, Watts!! Cool

With yours and Lois help I do believe it WORKS!! Sly

At least it is for me....does it for you now??

http://www.aallsafe.com/...ter/test/members.cgi

Oh please oh pleeeeeease say it does... Tongue
Diana Rae
Quote Reply
Re: [dianarae] The other Cookies Mod In reply to
Yeppers... it works!

Congrats!