From: John Graham-C. <jgr...@us...> - 2005-04-07 19:55:36
|
Update of /cvsroot/popfile/engine/Proxy In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21537/Proxy Modified Files: POP3.pm Proxy.pm SMTP.pm Log Message: More work on v0.23.0 (Multi-user Support) Add account association and allow different users to log in. Users can be associated with specific accounts when POPFile is in multi-user mode. Currently every user has a blank password. Also cloning of per-bucket parameters is not working. Would love to have volunteers to do the following: 1. Test out the new functionality for account association 2. Write code to do per-bucket parameter cloning (see Bayes.pm TODO) 3. Write code to set/reset user passwords. --- Classifer/Bayes.pm: Add functions for handling account creation and deletion and mapping of accounts to users. Add new message called CREAT used to pass a child generated session to the parent. Proxy/Proxy.pm Proxy/POP3.pm: Add code for handling users associated with accounts and use it in the POP3 module to lookup users dynamically when they are logged in. UI/HTML.pm: Update UI to be able to handle different users using the cookie and changes to the History API. Add code to the users_page to handle account association on a per user basis. UI/HTTP.pm: Add url_decode_ and decode form parameters. POPFile/MQ.pm: Comment the CREAT message. POPFile/History.pm: Make history mechanism aware of different users so that different users get a different view of the history. skins/default/user_page.thtml: Add code for handling account association. languages/English.msg: Additional strings needed for the account handling. --- Once this is all working we can start to fix the test suite and nail down the v0.23.0 release. Index: POP3.pm =================================================================== RCS file: /cvsroot/popfile/engine/Proxy/POP3.pm,v retrieving revision 1.109 retrieving revision 1.110 diff -C2 -d -r1.109 -r1.110 *** POP3.pm 22 Mar 2005 19:29:10 -0000 1.109 --- POP3.pm 7 Apr 2005 19:54:46 -0000 1.110 *************** *** 10,14 **** # This module handles proxying the POP3 protocol for POPFile. # ! # Copyright (c) 2001-2004 John Graham-Cumming # # This file is part of POPFile --- 10,14 ---- # This module handles proxying the POP3 protocol for POPFile. # ! # Copyright (c) 2001-2005 John Graham-Cumming # # This file is part of POPFile *************** *** 156,168 **** # child__ # ! # The worker method that is called when we get a good connection from a client # # $client - an open stream to a POP3 client ! # $session - API session key # # ---------------------------------------------------------------------------- sub child__ { ! my ( $self, $client, $session ) = @_; # Hash of indexes of downloaded messages mapped to their --- 156,169 ---- # child__ # ! # The worker method that is called when we get a good connection from ! # a client # # $client - an open stream to a POP3 client ! # $admin_session - administrator session # # ---------------------------------------------------------------------------- sub child__ { ! my ( $self, $client, $admin_session ) = @_; # Hash of indexes of downloaded messages mapped to their *************** *** 175,178 **** --- 176,185 ---- my $mail; + # Will hold the session key for the API, $token contains the + # string for the USER/APOP command that is used to get the key + + my $session = undef; + my $token; + $self->{apop_banner__} = undef; $self->{use_apop__} = 0; *************** *** 231,234 **** --- 238,242 ---- if ( $command =~ /$transparent/ ) { if ( $self->config_( 'secure_server' ) ne '' ) { + $token = $self->config_( 'secure_server' ). ":$1"; if ( $mail = $self->verify_connected_( $mail, $client, $self->config_( 'secure_server' ), $self->config_( 'secure_port' ) ) ) { last if ($self->echo_response_($mail, $client, $command) == 2 ); *************** *** 246,249 **** --- 254,258 ---- if ( $1 ne '' ) { my ( $host, $port, $user, $options ) = ($1, $3, $4, $6); + $token = "$host:$user"; $self->mq_post_( 'LOGIN', $user ); *************** *** 312,317 **** } ! # User is issuing the APOP command to start a session with the ! # remote server if ( ( $command =~ /PASS (.*)/i ) ) { --- 321,326 ---- } ! # The PASS command. Note how we only obtain a session key for ! # the user if the authentication is successful. if ( ( $command =~ /PASS (.*)/i ) ) { *************** *** 336,344 **** $self->tee_( $client, "+OK password ok$eol" ); } else { ! $self->tee_( $client, "$response" ); } } else { ! last if ($self->echo_response_($mail, $client, $command) == 2 ); } next; --- 345,362 ---- $self->tee_( $client, "+OK password ok$eol" ); + $session = $self->get_session_key_( $token ); + if ( !defined( $session ) ) { + last; + } } else { ! $self->tee_( $client, $response ); } } else { ! last if ($self->echo_response_($mail, $client, ! $command) == 2 ); ! $session = $self->get_session_key_( $token ); ! if ( !defined( $session ) ) { ! last; ! } } next; *************** *** 346,350 **** # User is issuing the APOP command to start a session with the ! # remote server We'd need a copy of the plaintext password to # support this. --- 364,368 ---- # User is issuing the APOP command to start a session with the ! # remote server. We'd need a copy of the plaintext password to # support this. *************** *** 496,500 **** $self->classifier_()->classify_and_modify( ! $session, $mail, $client, 1, $class, $slot, 1 ); } } --- 514,518 ---- $self->classifier_()->classify_and_modify( ! $session, $mail, $client, 1, $class, $slot, 1 ); } } *************** *** 665,668 **** --- 683,690 ---- } + if ( defined( $session ) ) { + $self->release_session_key_( $session ); + } + close $client; $self->mq_post_( 'CMPLT', $$ ); Index: Proxy.pm =================================================================== RCS file: /cvsroot/popfile/engine/Proxy/Proxy.pm,v retrieving revision 1.58 retrieving revision 1.59 diff -C2 -d -r1.58 -r1.59 *** Proxy.pm 28 Feb 2005 12:36:06 -0000 1.58 --- Proxy.pm 7 Apr 2005 19:54:47 -0000 1.59 *************** *** 5,9 **** # This module implements the base class for all POPFile proxy Modules # ! # Copyright (c) 2001-2004 John Graham-Cumming # # This file is part of POPFile --- 5,9 ---- # This module implements the base class for all POPFile proxy Modules # ! # Copyright (c) 2001-2005 John Graham-Cumming # # This file is part of POPFile *************** *** 59,66 **** $self->{pipe_cache__} = {}; ! # This is where we keep the session with the Classifier::Bayes ! # module ! $self->{api_session__} = ''; # This is the error message returned if the connection at any --- 59,65 ---- $self->{pipe_cache__} = {}; ! # Holds an administrator session ! $self->{api_session__} = undef; # This is the error message returned if the connection at any *************** *** 218,228 **** if ( my $client = $self->{server__}->accept() ) { - # Check to see if we have obtained a session key yet - - if ( $self->{api_session__} eq '' ) { - $self->{api_session__} = # PROFILE BLOCK START - $self->classifier_()->get_session_key( 'admin', '' ); # PROFILE BLOCK STOP - } - # Check that this is a connection from the local machine, # if it's not then we drop it immediately without any --- 217,220 ---- *************** *** 243,246 **** --- 235,242 ---- binmode( $client ); + if ( !defined( $self->{api_session__} ) ) { + $self->{api_session__} = $self->classifier_()->get_administrator_session_key(); + } + if ( $self->config_( 'force_fork' ) ) { my ( $pid, $pipe ) = &{$self->{forker_}}; *************** *** 468,471 **** --- 464,502 ---- # ---------------------------------------------------------------------------- # + # get_session_key_ + # + # Used by a proxy module to get a session key based on a token (usually an + # account name) + # + # $token The magic token + # + # Returns a session key if the token is associated with a user or undef + # + # ---------------------------------------------------------------------------- + sub get_session_key_ + { + my ( $self, $token ) = @_; + + return $self->classifier_()->get_session_key_from_token( $self->{api_session__}, $self->name(), $token ); + } + + # ---------------------------------------------------------------------------- + # + # release_session_key_ + # + # Release a session key obtained with get_session_key_ + # + # $session The session key to release + # + # ---------------------------------------------------------------------------- + sub release_session_key_ + { + my ( $self, $session ) = @_; + + $self->classifier_()->release_session_key( $session ); + } + + # ---------------------------------------------------------------------------- + # # verify_connected_ # *************** *** 474,481 **** # $hostname The host name of the remote server # $port The port ! # $ssl If set to 1 then the connection to the remote is established using SSL # ! # Check that we are connected to $hostname on port $port putting the open handle in $mail. ! # Any messages need to be sent to $client # # ---------------------------------------------------------------------------- --- 505,513 ---- # $hostname The host name of the remote server # $port The port ! # $ssl If set to 1 then the connection to the remote is established ! # using SSL # ! # Check that we are connected to $hostname on port $port putting the ! # open handle in $mail. Any messages need to be sent to $client # # ---------------------------------------------------------------------------- *************** *** 580,584 **** # configure_item # ! # $name The name of the item being configured, was passed in by the call # to register_configuration_item # $templ The loaded template --- 612,617 ---- # configure_item # ! # $name The name of the item being configured, was passed in by ! # the call # to register_configuration_item # $templ The loaded template Index: SMTP.pm =================================================================== RCS file: /cvsroot/popfile/engine/Proxy/SMTP.pm,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** SMTP.pm 25 Feb 2005 21:53:54 -0000 1.40 --- SMTP.pm 7 Apr 2005 19:54:47 -0000 1.41 *************** *** 9,13 **** # This module handles proxying the SMTP protocol for POPFile. # ! # Copyright (c) 2001-2004 John Graham-Cumming # # This file is part of POPFile --- 9,13 ---- # This module handles proxying the SMTP protocol for POPFile. # ! # Copyright (c) 2001-2005 John Graham-Cumming # # This file is part of POPFile *************** *** 147,154 **** # child__ # ! # The worker method that is called when we get a good connection from a client # # $client - an open stream to a SMTP client ! # $session - API session key # # ---------------------------------------------------------------------------- --- 147,155 ---- # child__ # ! # The worker method that is called when we get a good connection from ! # a client # # $client - an open stream to a SMTP client ! # $session - administrator session # # ---------------------------------------------------------------------------- *************** *** 158,171 **** # Number of messages downloaded in this session my $count = 0; # The handle to the real mail server gets stored here my $mail; ! # Tell the client that we are ready for commands and identify our version number $self->tee_( $client, "220 " . $self->config_( 'welcome_string' ) . "$eol" ); ! # Retrieve commands from the client and process them until the client disconnects or ! # we get a specific QUIT command while ( <$client> ) { my $command; --- 159,177 ---- # Number of messages downloaded in this session + my $count = 0; # The handle to the real mail server gets stored here + my $mail; ! # Tell the client that we are ready for commands and identify our ! # version number ! $self->tee_( $client, "220 " . $self->config_( 'welcome_string' ) . "$eol" ); ! # Retrieve commands from the client and process them until the ! # client disconnects or we get a specific QUIT command ! while ( <$client> ) { my $command; |