Hi,
I was not able to get the mysql authentication program to compile, after a
day of playing with it, it would still just give me an ld error. I found a
couple of examples of authentication software written in perl, so I
thought "why not custom write it". My oldest son does some programming so
he helped me with it, although both of us are at a loss as to why it
doesn't work. It always returns the right response from the command line,
either an OK or ERR. Maybe the response squid expects has changed. We have
it logging what is sent to the perl script from squid, so I know that it
is getting input from squid, but it doesn't look like it gives a response
back to squid or at least one that squid can understand, because after
putting in a username and password, the browser does nothing. Also,
ncsa_auth works with my current config, and I am just changing that line
in squid.conf to call custom_auth.pl.
Here is what we have:
#!/usr/bin/perl
use DBI;
# config
my $host = "localhost";
my $database = "filter";
my $tablename = "filteredusers";
my $user = "msyqlfilteruser";
my $pw = "faithhope";
# dbi connect
my $dbh = DBI->connect("DBI:mysql:database=$database;host=$host", $user,
$pw, {'RaiseError' => 1});
while (<STDIN>) {
chop $_;
open $file, '>>/var/log/custom_auth.log';
print $file "$_\n";
close $file;
# get email and password
my @info = split(/ /, $_);
my $email = $dbh->quote(shift(@info));
my $pass = $dbh->quote(shift(@info));
# query for user status
my $sth = $dbh->prepare("SELECT stat FROM $tablename WHERE
email=$email AND passwd=$pass LIMIT 1");
$sth->execute();
# check
if (my $ref = $sth->fetchrow_hashref()) {
if ($ref->{'stat'} =~ m/[AF]/) {
#$dbh->do("UPDATE $tablename SET
login_date='2010-06-15 00:00:00' WHERE id='2' LIMIT 1";
print "OK\n";
} else {
print "ERR\n";
}
} else {
print "ERR\n";
}
$sth->finish();
}
$dbh->disconnect();
Of course, I changed the username and password that we are using for the
database. Also, the line that is supposed to update the database is not
working yet, but as you can see it is commented out. I was supposed to
have this working Monday and it is now Thursday, so any help would be
greatly appreciated.
Best Regards,
Al