W dniu 2011-09-14 08:51, jczarniak@jarsat.pl pisze:
uzyj do tego modułu auth_mysql
Po wlaczeniu do dajesz na koncu apache2.conf: AuthMySQL_DefaultHost localhost AuthMySQL_DefaultUser USER AuthMySQL_DefaultPassword HASLO Auth_MySQL_General_DB lms
do .htaccess: AuthName "Private Site" AuthType Basic
<Limit GET POST> Auth_MySQL_Password_Table users Auth_MySQL_Username_Field login Auth_MySQL_Password_Field passwd AuthMySQL_Empty_Passwords off Auth_MySQL_Password_Clause " and deleted=0" AuthMySQL_Encryption_Types Crypt # PHP_MD5 SHA1Sum MySQL Plaintext Crypt_DES Crypt_MD5 Auth_MySQL On AuthUserFile /dev/null AuthBasicAuthoritative Off require valid-user </Limit>
i po temacie :)
Dziękuję za nawiązanie dialogu, mogłem porównać konfigurację z .htaccess, tam więc nie popełniłem błędu. Dość jednak mod_auth_mysql... Oto działający mod_authnz_external:
wpis w htaccess: - - - 8< - - - AuthType Basic AuthName "Authorized access only!" AuthBasicProvider external AuthExternal auth require valid-user - - - 8< - - -
wpis w virtualce apache: - - - 8< - - - AddExternalAuth auth /var/www/.common/mysql-auth.pl SetExternalAuthMethod auth pipe - - - 8< - - -
oraz kod programu sprawdzającego wskazanego wyżej: - - - 8< - - - #!/usr/bin/perl -Tw # MySQL-auth version 1.0b # Anders Nordby anders@fix.no, 2002-01-20 # This script is usable for authenticating users against a MySQL database with # the Apache module mod_auth_external. See # http://www.wwnet.net/~janc/mod_auth_external.html for mod_auth_external. # # Updates to this script will be made available on: # http://anders.fix.no/software/#unix
my $dbhost="localhost"; my $dbuser="apache"; my $dbpw="apache-haslo"; my $dbname="lms"; my $dbport="3306"; my $mychars="01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_,.";
# Below this, only the SQL query should be interesting to modify for users.
use DBI;
sub validchars { # 0: string 1: valid characters my $streng = $_[0];
my $ok = 1; my $i = 0; while ($ok && $i < length($_[0])) { if (index($_[1], substr($_[0],$i,1)) == -1) { $ok = 0; } $i++; } return($ok); }
# Get the name of this program $prog= join ' ',$0,@ARGV; $logprefix='[' . scalar (localtime) . '] ' . $prog;
# Get the user name $user= <STDIN>; chomp $user;
# Get the password name $pass= <STDIN>; chomp $pass;
# check for valid characters if (!validchars($user, $mychars) || !validchars($pass, $mychars)) { print STDERR "$logprefix: invalid characters used in login/password - Rejected\n"; exit 1; }
# check for password in mysql database #if my $dbh = DBI->connect("DBI:mysql:database=$dbname:host=$dbhost:port=$dbport",$dbuser,$dbpw,{PrintError=>0});
if (!$dbh) { print STDERR "$logprefix: could not connect to database - Rejected\n"; exit 1; }
my $dbq = $dbh->prepare("select login as username, passwd as password from users where login=?;"); $dbq->bind_param(1, $user); $dbq->execute; my $row = $dbq->fetchrow_hashref();
if ($row->{username} eq "") { print STDERR "$logprefix: could not find user $user - Rejected\n"; exit 1; } if ($row->{password} eq "") { print STDERR "$logprefix: empty password for user $user - Rejected\n"; exit 1; }
if ($row->{password} eq crypt($pass,$row->{password})) { print STDERR "$logprefix: password for user $user matches - Accepted\n"; exit 0; } else { print STDERR "$logprefix: password for user $user does not match - Rejected\n"; exit 1; }
$dbq->finish; $dbh->disconnect; - - - 8< - - -