From 187cf8c48638b789e0f104eb7981460b07cc6ff6 Mon Sep 17 00:00:00 2001 From: tonnesen Date: Thu, 11 Jul 2002 19:43:10 +0000 Subject: [PATCH] Created a subroutine for loading /etc/koha.conf settings. Auth.pm will now accept the user and pass values from /etc/koha.conf as valid authentication. --- C4/Auth.pm | 9 +++++++++ C4/Database.pm | 27 +++++++-------------------- C4/Koha.pm | 27 ++++++++++++++++++++++++--- C4/Output.pm | 22 +++------------------- 4 files changed, 43 insertions(+), 42 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index d109cb6578..55186d6fcb 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -6,6 +6,7 @@ use Digest::MD5 qw(md5_base64); require Exporter; use C4::Database; +use C4::Koha; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); @@ -162,7 +163,9 @@ sub checkpw { # This should be modified to allow a select of authentication schemes (ie LDAP) # as well as local authentication through the borrowers tables passwd field # + my ($dbh, $userid, $password) = @_; + warn "Checking $userid $password"; my $sth=$dbh->prepare("select password from borrowers where userid=?"); $sth->execute($userid); if ($sth->rows) { @@ -179,6 +182,12 @@ sub checkpw { return 1; } } + my $configfile=configfile(); + warn "$userid $configfile->{'user'} $password $configfile->{'pass'}"; + if ($userid eq $configfile->{'user'} && $password eq $configfile->{'pass'}) { + # Koha superuser account + return 1; + } return 0; } diff --git a/C4/Database.pm b/C4/Database.pm index da25d4a8ac..af7c4c2bc3 100755 --- a/C4/Database.pm +++ b/C4/Database.pm @@ -5,6 +5,7 @@ package C4::Database; #asummes C4/Database use strict; require Exporter; use DBI; +use C4::Koha; use vars qw($VERSION @ISA @EXPORT); $VERSION = 0.01; @@ -17,26 +18,12 @@ $VERSION = 0.01; sub C4Connect { my $dbname="c4"; - my ($database,$hostname,$user,$pass,%configfile); - open (KC, "/etc/koha.conf"); - while () { - chomp; - (next) if (/^\s*#/); - if (/(.*)\s*=\s*(.*)/) { - my $variable=$1; - my $value=$2; - # Clean up white space at beginning and end - $variable=~s/^\s*//g; - $variable=~s/\s*$//g; - $value=~s/^\s*//g; - $value=~s/\s*$//g; - $configfile{$variable}=$value; - } - } - $database=$configfile{'database'}; - $hostname=$configfile{'hostname'}; - $user=$configfile{'user'}; - $pass=$configfile{'pass'}; + my ($database,$hostname,$user,$pass); + my $configfile=configfile(); + $database=$configfile->{'database'}; + $hostname=$configfile->{'hostname'}; + $user=$configfile->{'user'}; + $pass=$configfile->{'pass'}; my $dbh=DBI->connect("DBI:mysql:$database:$hostname",$user,$pass); return $dbh; diff --git a/C4/Koha.pm b/C4/Koha.pm index eae17c4707..c12f0d4d86 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -13,12 +13,33 @@ $VERSION = 0.01; &fixEthnicity &borrowercategories ðnicitycategories + &configfile $DEBUG); use vars qw(); my $DEBUG = 0; +sub configfile { + my $configfile; + open (KC, "/etc/koha.conf"); + while () { + chomp; + (next) if (/^\s*#/); + if (/(.*)\s*=\s*(.*)/) { + my $variable=$1; + my $value=$2; + # Clean up white space at beginning and end + $variable=~s/^\s*//g; + $variable=~s/\s*$//g; + $value=~s/^\s*//g; + $value=~s/\s*$//g; + $configfile->{$variable}=$value; + } + } + return $configfile; +} + sub slashifyDate { # accepts a date of the form xx-xx-xx[xx] and returns it in the # form xx/xx/xx[xx] @@ -29,7 +50,7 @@ sub slashifyDate { sub fixEthnicity($) { my $ethnicity = shift; - my $dbh=C4Connect; + my $dbh=C4Connect(); my $sth=$dbh->prepare("Select name from ethnicity where code = ?"); $sth->execute($ethnicity); my $data=$sth->fetchrow_hashref; @@ -39,7 +60,7 @@ sub fixEthnicity($) { } sub borrowercategories { - my $dbh=C4Connect; + my $dbh=C4Connect(); my $sth=$dbh->prepare("Select categorycode,description from categories order by description"); $sth->execute; my %labels; @@ -54,7 +75,7 @@ sub borrowercategories { } sub ethnicitycategories { - my $dbh=C4Connect; + my $dbh=C4Connect(); my $sth=$dbh->prepare("Select code,name from ethnicity order by name"); $sth->execute; my %labels; diff --git a/C4/Output.pm b/C4/Output.pm index 3ae7fbd94c..2b13f03c8e 100644 --- a/C4/Output.pm +++ b/C4/Output.pm @@ -53,25 +53,9 @@ my @more = (); # # Change this value to reflect where you will store your includes # -my %configfile; -open (KC, "/etc/koha.conf"); -while () { - chomp; - (next) if (/^\s*#/); - if (/(.*)\s*=\s*(.*)/) { - my $variable=$1; - my $value=$2; - - $variable =~ s/^\s*//g; - $variable =~ s/\s*$//g; - $value =~ s/^\s*//g; - $value =~ s/\s*$//g; - $configfile{$variable}=$value; - } # if -} # while -close(KC); - -my $path=$configfile{'includes'}; +my $configfile=configfile(); + +my $path=$configfile->{'includes'}; ($path) || ($path="/usr/local/www/hdl/htdocs/includes"); # make all your functions, whether exported or not; -- 2.39.5