Hi, All!

I`d change source of OTRS for my needs. I think, that it can be useful for 
other. So, I posting it in this list.

In Kernel::Config.pm:
<cut>
    # --------------------------------------------------- #                            
                        
    #                                                     #                            
                        
    #             Start of config options!!!              #                            
                        
    #                 CustomerAuth stuff                  #                            
                        
    #                                                     #                            
                        
    # --------------------------------------------------- #                            
                        
                                                                                       
                        
    $Self->{'Customer::AuthModule'} = 'Kernel::System::CustomerAuth::DB';              
                        
                                                                                       
                        
    # CustomerAuth                                                                     
                        
    # (customer auth database backend and settings)                                    
                        
    $Self->{CustomerAuth} = {                                                          
                        
        Module => 'Kernel::System::CustomerAuth::DB',                                  
                        
        Params => {                                                                    
                        
            DSN => 'DBI:Pg:dbname=stats;host=194.44.58.68',                            
                        
            User => 'support',                                                         
                        
            Password => 'tekr_21',                                                     
                        
            Table => 'abons_for_otrs'                                                  
                        
        },                                                                             
                        
        # customer #                                                                   
                        
        CustomerID => 'customer_id',                                                   
                        
        ValidID => 'valid_id',                                                         
                        
        CustomerAuthUserField => 'login',                                              
                        
        CustomerAuthPwField => 'pw',                                                   
                        
        ReadOnly => 1,                                                                 
                        
        Map => [                                                                       
                        
#            # note: Login, Email and CustomerID needed!                               
                        
#            # var, frontend, storage, shown, required, storage-type,http-link         
                       
#            [ 'UserLastname', 'Lastname', 'firm_sh', 1, 1, 'var' ],                   
                        
            [ 'UserLogin', 'Login', 'login', 1, 1, 'var' ],                            
                        
            [ 'UserPassword', 'Password', 'pw', 0, 1, 'var' ],                         
                        
#            [ 'UserEmail', 'Email', 'email', 0, 1, 'var' ],                           
                        
            [ 'UserCustomerID', 'CustomerID', 'customer_id', 0, 1, 'var' ],            
                        
            [ 'ValidID', 'Valid', 'valid_id', 0, 1, 'int' ],                           
                        
        ],                                                                             
                        
    };
<cut>

Kernel::System::CustomerAuth::DB.pm was rewrited:
# --
# Kernel/System/CustomerAuth/DB.pm - provides the db authentification 
# Copyright (C) 2002-2003 Martin Edenhofer <[EMAIL PROTECTED]>
# --
# $Id: DB.pm,v 1.6 2003/04/03 13:14:20 martin Exp $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see 
# the enclosed file COPYING for license information (GPL). If you 
# did not receive this file, see http://www.gnu.org/licenses/gpl.txt.
# --
# Note: 
# available objects are: ConfigObject, LogObject and DBObject
# --

package Kernel::System::CustomerAuth::DB;

use strict;

use vars qw($VERSION);
$VERSION = '$Revision: 1.6 $';
$VERSION =~ s/^\$.*:\W(.*)\W.+?$/$1/;

# --
sub new {
    my $Type = shift;
    my %Param = @_;

    # allocate new hash for object
    my $Self = {};
    bless ($Self, $Type);

    # --
    # check needed objects
    # --
    foreach ('LogObject', 'ConfigObject', 'DBObject') {
        $Self->{$_} = $Param{$_} || die "No $_!";
    }

    $Self->{LogObject}->Log(
          Priority => 'notice',
          Message => "Значение $Self->{ConfigObject}",
        );

    # --                                                                               
                        
    # config options                                                                   
                        
    # --
    
    $Self->{ValidID} = $Self->{ConfigObject}->Get('CustomerAuth')->{ValidID}
      || die "Need CustomerAuth->ValidID in Kernel/Config.pm!";
    $Self->{UserField} = 
$Self->{ConfigObject}->Get('CustomerAuth')->{CustomerAuthUserField}
      || die "Need CustomerAuth->CustomerAuthUserField in Kernel/Config.pm!";
    $Self->{PwField} = 
$Self->{ConfigObject}->Get('CustomerAuth')->{CustomerAuthPwField}
      || die "Need CustomerAuth->CustomerAuthPwField in Kernel/Config.pm!";
    $Self->{AuthTable} = 
$Self->{ConfigObject}->Get('CustomerAuth')->{Params}->{Table}
      || die "Need CustomerAuth->Params->Table in Kernel/Config.pm!";
    $Self->{CustIDField} = 
$Self->{ConfigObject}->Get('CustomerAuth')->{CustomerID}
      || die "Need CustomerAuth->CustomerID in Kernel/Config.pm!";
    # --                                                                               
                        
    # create new db connect if DSN is given                                            
                        
    # --                                                                               
                        
    if ($Self->{ConfigObject}->Get('CustomerAuth')->{Params}->{DSN}) {                 
                        
        $Self->{DBObject} = Kernel::System::DB->new(                                   
                        
            LogObject => $Param{LogObject},                                            
                        
            ConfigObject => $Param{ConfigObject},                                      
                        
            DatabaseDSN => 
$Self->{ConfigObject}->Get('CustomerAuth')->{Params}->{DSN},                        
            DatabaseUser => 
$Self->{ConfigObject}->Get('CustomerAuth')->{Params}->{User},                      
            DatabasePw => 
$Self->{ConfigObject}->Get('CustomerAuth')->{Params}->{Password},                    
        ) || die $DBI::errstr;                                                         
                        
    }

    # --
    # Debug 0=off 1=on
    # --
    $Self->{Debug} = 0;

    # --                                                                               
                        
    # create check item object                                                         
                        
    # --                                                                               
                        
    $Self->{CheckItemObject} = Kernel::System::CheckItem->new(%Param);
    return $Self;
}
# --
sub Auth {
    my $Self = shift;
    my %Param = @_;
    # --
    # check needed stuff
    # --
    if (!$Param{User}) {
      $Self->{LogObject}->Log(Priority => 'error', Message => "Need User!");
      return;
    }
    # --
    # get params
    # --
    my $User = $Param{User} || ''; 
    my $Pw = $Param{Pw} || '';
    my $RemoteAddr = $ENV{REMOTE_ADDR} || 'Got no REMOTE_ADDR env!';
    my $UserID = '';
    my $GetPw = '';

    # --
    # sql query
    # --
    my $SQL = "SELECT ".$Self->{PwField}.", ".$Self->{CustIDField}.
            " FROM ".$Self->{AuthTable}." WHERE ".
            $Self->{UserField}." = '$User';";

    $Self->{DBObject}->Prepare(SQL => $SQL);
    while (my @RowTmp = $Self->{DBObject}->FetchrowArray()) { 
        $GetPw = $RowTmp[0];
        $UserID = $RowTmp[1];
    }

    # --
    # crypt given pw (unfortunately there is a mod_perl2 bug on RH8 - check if 
    # crypt() is working correctly) :-/
    # --
#    my $CryptedPw = '';
#    my $Salt = $GetPw;
#    $Salt =~ s/^(..).*/$1/;
#    if (crypt('root', '[EMAIL PROTECTED]') eq 'roK20XGbWEsSM') {
#        $CryptedPw = crypt($Pw, $Salt);
#    }
#    else {
#        $Self->{LogObject}->Log(
#            Priority => 'notice',
#            Message => "The crypt() of your mod_perl(2) is not working 
correctly! Update mod_perl!",
#        );
#        my $TempSalt = $Salt;
#        $TempSalt =~ s/'/\\'/g;
#        my $TempPw = $Pw;
#        $TempPw =~ s/'/\\'/g;
#        my $CMD = "perl -e \"print crypt('$TempPw', '$TempSalt');\"";
#        open (IO, " $CMD | ") || print STDERR "Can't open $CMD: $!";
#        while (<IO>) {
#            $CryptedPw .= $_;
#        }
#        close (IO);
#        chomp $CryptedPw;
#    }
    my $CryptedPw = $Pw;
    # --
    # just in case!
    # --
    if ($Self->{Debug} > 0) {
        $Self->{LogObject}->Log(
          Priority => 'notice',
          Message => "CustomerUser: '$User' tried to login with Pw: 
'$Pw' ($UserID/$CryptedPw/$GetPw/$RemoteAddr)"
        );
    }

    # --
    # just a note 
    # --
    if (!$Pw) {
        $Self->{LogObject}->Log(
          Priority => 'notice',
          Message => "CustomerUser: $User without Pw!!! (REMOTE_ADDR: 
$RemoteAddr)",
        );
        return;
    }
    # --
    # login note
    # --
    elsif ((($GetPw)&&($User)&&($UserID)) && $CryptedPw eq $GetPw) {
        $Self->{LogObject}->Log(
          Priority => 'notice',
          Message => "CustomerUser: $User logged in (REMOTE_ADDR: 
$RemoteAddr).",
        );
        return 1;
    }
    # --
    # just a note
    # --
    elsif (($UserID) && ($GetPw)) {
        $Self->{LogObject}->Log(
          Priority => 'notice',
          Message => "CustomerUser: $User with wrong Pw!!! (REMOTE_ADDR: 
$RemoteAddr)"
        ); 
        return;
    }
    # --
    # just a note
    # --
    else {
        $Self->{LogObject}->Log(
          Priority => 'notice',
          Message => "CustomerUser: $User doesn't exist or is invalid!!! 
(REMOTE_ADDR: $RemoteAddr)"
        ); 
        return;
    }
}
# --

1;

If this source will help anyone, i will be happy! :)

Sorry for my English, it isn`t my native language

-- 
With best regards,
        Dmitriy Borisov
        Network administrator of INTS ISP
        Ukraine, Donetsk
        E-mail: [EMAIL PROTECTED]
_______________________________________________
OTRS mailing list: dev - Webpage: http://otrs.org/
Archive: http://lists.otrs.org/pipermail/dev
To unsubscribe: http://lists.otrs.org/cgi-bin/listinfo/dev

Reply via email to