<commit_before>
#===============================================================================
#
# Apache::AuthCookieDBI
#
# An AuthCookie module backed by a DBI database.
#
# Copyright (C) 2002 SF Interactive.
#
# Author:  <NAME> <<EMAIL>>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# 
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
# 
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#===============================================================================

package Apache::AuthCookieDBI;

use strict;
use 5.004;
use vars qw( $VERSION );
( $VERSION ) = '$Revision: 1.2 $' =~ /([\d.]+)/;

use Apache::AuthCookie;
use vars qw( @ISA );
@ISA = qw( Apache::AuthCookie );

use Apache;
use Apache::DBI;
use Apache::Constants;
use Apache::File;
use Digest::MD5 qw( md5_hex );
use Date::Calc qw( Today_and_Now Add_Delta_DHMS );
# Also uses Crypt::CBC if you're using encrypted cookies.

#===============================================================================
# F U N C T I O N   D E C L A R A T I O N S
#===============================================================================

sub _log_not_set($$);
sub _dir_config_var($$);
sub _dbi_config_vars($);
sub _now_year_month_day_hour_minute_second();
sub _percent_encode($);
sub _percent_decode($);

sub authen_cred($$\@);
sub authen_ses_key($$$);
sub group($$\@);

#===============================================================================
# P A C K A G E   G L O B A L S
#===============================================================================

use vars qw( %CIPHERS );
# Stores Cipher::CBC objects in $CIPHERS{ idea:AuthName },
# $CIPHERS{ des:AuthName } etc.

use vars qw( %SECRET_KEYS );
# Stores secret keys for MD5 checksums and encryption for each auth realm in
# $SECRET_KEYS{ AuthName }.

#===============================================================================
# S E R V E R   S T A R T   I N I T I A L I Z A T I O N
#===============================================================================

BEGIN {
	my @keyfile_vars = grep {
		$_ =~ /DBI_SecretKeyFile$/
	} keys %{ Apache->server->dir_config() };
	foreach my $keyfile_var ( @keyfile_vars ) {
		my $keyfile = Apache->server->dir_config( $keyfile_var );
		my $auth_name = $keyfile_var;
		$auth_name =~ s/DBI_SecretKeyFile$//;
		unless ( open( KEY, "<$keyfile" ) ) {
			Apache::log_error( "Could not open keyfile for $auth_name in file $keyfile" );
		} else {
			$SECRET_KEYS{ $auth_name } = <KEY>;
			close KEY;
		}
	}
}

#===============================================================================
# P E R L D O C
#===============================================================================

=head1 NAME

Apache::AuthCookieDBI - An AuthCookie module backed by a DBI database.

=head1 VERSION

	$Revision: 1.2 $

=head1 SYNOPSIS

	# In httpd.conf or .htaccess
	# This PerlSetVar MUST precede the PerlModule line because the
	# key is read in a BEGIN block when the module is loaded.
	PerlSetVar WhatEverDBI_SecretKeyFile /etc/httpd/acme.com.key

	PerlModule Apache::AuthCookieDBI
	PerlSetVar WhatEverPath /
	PerlSetVar WhatEverLoginScript /login.pl
<commit_msg>*** empty log message ***<commit_after>#===============================================================================
#
# Apache::AuthCookieDBI
#
# An AuthCookie module backed by a DBI database.
#
# Copyright (C) 2002 SF Interactive.
#
# Author:  <NAME> <<EMAIL>>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# 
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
# 
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#===============================================================================

package Apache::AuthCookieDBI;

use strict;
use 5.004;
use vars qw( $VERSION );
( $VERSION ) = '$Revision: 1.3 $' =~ /([\d.]+)/;

use Apache::AuthCookie;
use vars qw( @ISA );
@ISA = qw( Apache::AuthCookie );

use Apache;
use Apache::DBI;
use Apache::Constants;
use Apache::File;
use Digest::MD5 qw( md5_hex );
use Date::Calc qw( Today_and_Now Add_Delta_DHMS );
# Also uses Crypt::CBC if you're using encrypted cookies.

#===============================================================================
# F U N C T I O N   D E C L A R A T I O N S
#===============================================================================

sub _log_not_set($$);
sub _dir_config_var($$);
sub _dbi_config_vars($);
sub _now_year_month_day_hour_minute_second();
sub _percent_encode($);
sub _percent_decode($);

sub authen_cred($$\@);
sub authen_ses_key($$$);
sub group($$\@);

#===============================================================================
# P A C K A G E   G L O B A L S
#===============================================================================

use vars qw( %CIPHERS );
# Stores Cipher::CBC objects in $CIPHERS{ idea:AuthName },
# $CIPHERS{ des:AuthName } etc.

use vars qw( %SECRET_KEYS );
# Stores secret keys for MD5 checksums and encryption for each auth realm in
# $SECRET_KEYS{ AuthName }.

#===============================================================================
# S E R V E R   S T A R T   I N I T I A L I Z A T I O N
#===============================================================================

BEGIN {
	my @keyfile_vars = grep {
		$_ =~ /DBI_SecretKeyFile$/
	} keys %{ Apache->server->dir_config() };
	foreach my $keyfile_var ( @keyfile_vars ) {
		my $keyfile = Apache->server->dir_config( $keyfile_var );
		my $auth_name = $keyfile_var;
		$auth_name =~ s/DBI_SecretKeyFile$//;
		unless ( open( KEY, "<$keyfile" ) ) {
			Apache::log_error( "Could not open keyfile for $auth_name in file $keyfile" );
		} else {
			$SECRET_KEYS{ $auth_name } = <KEY>;
			close KEY;
		}
	}
}

#===============================================================================
# P E R L D O C
#===============================================================================

=head1 NAME

Apache::AuthCookieDBI - An AuthCookie module backed by a DBI database.

=head1 VERSION

	$Revision: 1.3 $

=head1 SYNOPSIS

	# In httpd.conf or .htaccess
	# This PerlSetVar MUST precede the PerlModule line because the
	# key is read in a BEGIN block when the module is loaded.
	PerlSetVar WhatEverDBI_SecretKeyFile /etc/httpd/acme.com.key

	PerlModule Apache::AuthCookieDBI
	PerlSetVar WhatEverPath /
	PerlSetVar WhatEverLoginScript /login.pl

{'fraction_non_alphanumeric': 0.3014141414141414, 'fraction_numerical': 0.009158249158249159, 'mean_word_length': 5.2403361344537815, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '747915', 'n_tokens_mistral': 2320, 'n_tokens_neox': 2119, 'n_words': 784}