From: naoki i. <am...@us...> - 2008-03-30 05:33:53
|
Update of /cvsroot/popfile/engine/Classifier In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29156/Classifier Modified Files: Bayes.pm Log Message: Change Log 1. Add an interface and a function to change/initialize user's password UI/HTML.pm Classifier/Bayes.pm skins/default/users-page.thtml languages/English.msg 2. Bucket parameters are now copied from cloned user's Classifier/Bayes.pm 3. Non admin users can't access the Administration, Users and Advanced tabs. UI/HTML.pm 4. The history messages are now stored per user. 5. Users can't see/remove other users' history messages. Classifier/Bayes.pm POPFile/History.pm UI/HTML.pm 6. Sorting history messages now work correctly UI/HTML.pm skins/default/history-page.thtml 7. Server Mode options for SMTP and NNTP proxy are saved correctly 8. Server Mode checkboxes are disabled if all the modules are local UI/HTML.pm Proxy/POP3.pm Proxy/SMTP.pm Proxy/NNTP.pm 9. The 'Config Bar' string is now localizable skins/default/configration-bar.thtml languages/English.msg 10. The 'Stealth Mode' and 'Server Mode' strings are now localizable skins/default/administration-page.thtml languages/English.msg 11. Update language files languages/English.msg languages/Nihongo.msg Index: Bayes.pm =================================================================== RCS file: /cvsroot/popfile/engine/Classifier/Bayes.pm,v retrieving revision 1.357 retrieving revision 1.358 diff -C2 -d -r1.357 -r1.358 *** Bayes.pm 2 Dec 2007 17:27:47 -0000 1.357 --- Bayes.pm 30 Mar 2008 05:33:57 -0000 1.358 *************** *** 2384,2388 **** if ( $class eq '' ) { $self->{parser__}->start_parse(); ! ( $slot, $msg_file ) = $self->history_()->reserve_slot(); } else { $msg_file = $self->history_()->get_slot_file( $slot ); --- 2384,2389 ---- if ( $class eq '' ) { $self->{parser__}->start_parse(); ! my $userid = $self->valid_session_key__( $session ); ! ( $slot, $msg_file ) = $self->history_()->reserve_slot( $session, $userid ); } else { $msg_file = $self->history_()->get_slot_file( $slot ); *************** *** 2751,2755 **** push @{$work{$newbucket}}, $self->history_()->get_slot_file( $slot ); ! my @fields = $self->history_()->get_slot_fields( $slot); my $bucket = $fields[8]; $self->classifier_()->reclassified( --- 2752,2756 ---- push @{$work{$newbucket}}, $self->history_()->get_slot_file( $slot ); ! my @fields = $self->history_()->get_slot_fields( $slot, $session ); my $bucket = $fields[8]; $self->classifier_()->reclassified( *************** *** 3358,3371 **** } ! my $password = ''; ! my @chars = split( //,'abcdefghijklmnopqurstuvwxyz0123456789' ); ! ! while ( length( $password ) < 8 ) { ! my $c = $chars[int(rand($#chars+1))]; ! if ( int(rand(2)) == 1 ) { ! $c = uc($c); ! } ! $password .= $c; ! } my $password_hash = md5_hex( $new_user . '__popfile__' . $password ); --- 3359,3363 ---- } ! my $password = $self->generate_users_password(); my $password_hash = md5_hex( $new_user . '__popfile__' . $password ); *************** *** 3411,3415 **** } ! # TODO clone bucket parameters } else { --- 3403,3443 ---- } ! # Fetch new bucket ids and cloned bucket ids ! ! $h = $self->db_()->prepare( ! "select bucket1.id, bucket2.id from buckets as bucket1, buckets as bucket2 ! where bucket1.userid = $id and bucket1.name = bucket2.name and bucket2.userid = $clid;" ); ! $h->execute; ! my %new_buckets; ! while ( my $row = $h->fetchrow_arrayref ) { ! $new_buckets{$row->[1]} = $row->[0]; ! } ! $h->finish; ! ! # Clone bucket parameters ! ! $h = $self->db_()->prepare( ! "select bucketid, btid, val from buckets, bucket_params ! where userid = $clid and buckets.id = bucket_params.bucketid;" ); ! $h->execute; ! my %bucket_params; ! while (my $row = $h->fetchrow_arrayref ) { ! $bucket_params{$new_buckets{$row->[0]}}{$row->[1]} = $row->[2]; ! } ! $h->finish; ! ! foreach my $bucketid ( keys %bucket_params ) { ! foreach my $btid ( keys %{$bucket_params{$bucketid}} ) { ! my $val = $self->db_()->quote( $bucket_params{$bucketid}{$btid} ); ! $self->db_()->do( ! "insert into bucket_params ( bucketid, btid, val ) ! values ( $bucketid, $btid, $val );" ); ! } ! } ! ! # TODO : Clone magnets ! ! # TODO : Clone corpus data (optional) ! } else { *************** *** 3425,3428 **** --- 3453,3478 ---- #---------------------------------------------------------------------------- # + # generate_users_password + # + # Generates user's initial password + # + #---------------------------------------------------------------------------- + sub generate_users_password + { + my $password = ''; + my @chars = split( //,'abcdefghijklmnopqurstuvwxyz0123456789' ); + + while ( length( $password ) < 8 ) { + my $c = $chars[int(rand($#chars+1))]; + if ( int(rand(2)) == 1 ) { + $c = uc($c); + } + $password .= $c; + } + return $password; + } + + #---------------------------------------------------------------------------- + # # remove_user (ADMIN ONLY) # *************** *** 3470,3473 **** --- 3520,3605 ---- #---------------------------------------------------------------------------- # + # initialize_users_password (ADMIN ONLY) + # + # Initializes the password for the specified user + # + # $session A valid session ID for an administrator + # $user The name of the user to change password + # + # Returns 0 for success, undef for wrong permissions and 1 for user + # does not exist + # + # ---------------------------------------------------------------------------- + sub initialize_users_password + { + my ( $self, $session, $user ) = @_; + + my $userid = $self->valid_session_key__( $session ); + return undef if ( !defined( $userid ) ); + + # Check that this user is an administrator + + my $can_admin = $self->get_user_parameter( $session, 'GLOBAL_can_admin' ); + + if ( $can_admin != 1 ) { + return undef; + } + + my $id = $self->get_user_id( $session, $user ); + my $password = $self->generate_users_password(); + + if ( defined( $id ) ) { + my $result = $self->set_password_for_user( $session, $id, $password ); + if ( $result == 1 ) { + return (0, $password); + } + } + + return 1; + } + + #---------------------------------------------------------------------------- + # + # change_users_password (ADMIN ONLY) + # + # Changes the password for the specified user + # + # $session A valid session ID for an administrator + # $user The name of the user to change password + # $password The new password + # + # Returns 0 for success, undef for wrong permissions and 1 for user + # does not exist + # + # ---------------------------------------------------------------------------- + sub change_users_password + { + my ( $self, $session, $user, $password ) = @_; + + my $userid = $self->valid_session_key__( $session ); + return undef if ( !defined( $userid ) ); + + # Check that this user is an administrator + + my $can_admin = $self->get_user_parameter( $session, 'GLOBAL_can_admin' ); + + if ( $can_admin != 1 ) { + return undef; + } + + my $id = $self->get_user_id( $session, $user ); + + if ( defined( $id ) ) { + my $result = $self->set_password_for_user( $session, $id, $password ); + if ( $result == 1 ) { + return 0; + } + } + + return 1; + } + + #---------------------------------------------------------------------------- + # # validate_password # *************** *** 3523,3530 **** my ( $self, $session, $password ) = @_; # Lookup the user name from the session key my $user; ! my $h = $self->db_()->prepare( "select name from users where id = $self->{api_sessions__}{$session};" ); $h->execute; if ( my $row = $h->fetchrow_arrayref ) { --- 3655,3684 ---- my ( $self, $session, $password ) = @_; + my $userid = $self->{api_sessions__}{$session}; + + return $self->set_password_for_user( $session, $userid, $password ); + } + + #---------------------------------------------------------------------------- + # + # set_password_for_user + # + # Sets the password for the current user + # + # $session A valid session ID + # $userid A user's id for change password + # $password The new password + # + # Returns 1 if the password was updated, 0 if not + # + # ---------------------------------------------------------------------------- + sub set_password_for_user + { + my ( $self, $session, $userid, $password ) = @_; + # Lookup the user name from the session key my $user; ! my $h = $self->db_()->prepare( "select name from users where id = $userid;" ); $h->execute; if ( my $row = $h->fetchrow_arrayref ) { *************** *** 3537,3541 **** my $hash = md5_hex( $user . '__popfile__' . $password ); ! $self->db_()->do( "update users set password = '$hash' where id = $self->{api_sessions__}{$session};" ); return 1; --- 3691,3695 ---- my $hash = md5_hex( $user . '__popfile__' . $password ); ! $self->db_()->do( "update users set password = '$hash' where id = $userid;" ); return 1; *************** *** 3566,3576 **** } ! my @users; $self->{db_get_user_list__}->execute(); while ( my $row = $self->{db_get_user_list__}->fetchrow_arrayref ) { ! push @users, $row->[1]; } ! return \@users; } --- 3720,3730 ---- } ! my %users; $self->{db_get_user_list__}->execute(); while ( my $row = $self->{db_get_user_list__}->fetchrow_arrayref ) { ! $users{$row->[0]} = $row->[1]; } ! return \%users; } |