From: naoki i. <am...@us...> - 2008-04-05 16:51:12
|
Update of /cvsroot/popfile/engine/Classifier In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9657/Classifier Modified Files: Bayes.pm MailParse.pm Log Message: Change Log 1. Added new subroutine Classifier/Bayes.pm is_admin_session check if the session is admin's 2. Use db_()->quote instead of hardcoded single quotes ("'") Classifier/Bayes.pm 3. Fixed almost of the test scripts to pass Classifier/Bayes.pm Classifier/MailParse.pm POPFile/History.pm Proxy/POP3.pm UI/HTML.pm UI/HTTP.pm tests/TestBayes.tst tests/TestBayesScript.tst tests/TestConfiguration.tst tests/TestHTML.script tests/TestHTML.tst tests/TestHistory.tst tests/TestMailParse.tst tests/TestMailParse015.clr tests/TestMailParse019.clr tests/TestNihongo002.wrd tests/TestNihongo008.wrd tests/TestNihongo016.wrd tests/TestNihongo017.wrd tests/TestNihongo021.qrn 4. Added new tests for the new subroutines tests/TestBayes.tst get_user_id_from_session get_user_name_from_session create_user (with cloning) initialize_users_password change_users_password get_user_name_from_id is_admin_session 5. Added new tests for the Japanese parsers (internal/MeCab) tests/TestMailParse.tst 6. make test now outputs the test results in STDERR instead of STDOUT 7. Snip long results tests.pl Current state of the test suite: TestBayesScript PASS TestBayes PASS TestConfiguration PASS * TestHistory PASS * TestHTML PASS * TestHTTP PASS TestIMAP not tested yet TestInsertScript PASS TestLogger PASS TestMailParse PASS TestModule PASS TestMQ PASS TestMutex PASS TestPipeScript PASS TestPOP3 fail (horribly) TestProxy PASS TestWordMangle PASS TestXMLRPC PASS (but child process does not terminate) * : needs to add tests for multi user support TODO 1. multi user mode tests are needed tests/TestConfiguration tests/TestHistory tests/HTML Index: Bayes.pm =================================================================== RCS file: /cvsroot/popfile/engine/Classifier/Bayes.pm,v retrieving revision 1.360 retrieving revision 1.361 diff -C2 -d -r1.360 -r1.361 *** Bayes.pm 5 Apr 2008 11:02:20 -0000 1.360 --- Bayes.pm 5 Apr 2008 16:50:45 -0000 1.361 *************** *** 329,338 **** if ( ( $nihongo_parser eq 'kakasi' ) && ( $^O eq 'MSWin32' ) && ! ( ( ( $self->user_module_config_( 1, 'pop3', 'enabled' ) ) && ! ( $self->user_module_config_( 1, 'pop3', 'force_fork' ) ) ) || ! ( ( $self->user_module_config_( 1, 'nntp', 'enabled' ) ) && ! ( $self->user_module_config_( 1, 'nntp', 'force_fork' ) ) ) || ! ( ( $self->user_module_config_( 1, 'smtp', 'enabled' ) ) && ! ( $self->user_module_config_( 1, 'smtp', 'force_fork' ) ) ) ) ) { $self->{parser__}->{need_kakasi_mutex__} = 1; --- 329,338 ---- if ( ( $nihongo_parser eq 'kakasi' ) && ( $^O eq 'MSWin32' ) && ! ( ( ( $self->module_config_( 'pop3', 'enabled' ) ) && ! ( $self->module_config_( 'pop3', 'force_fork' ) ) ) || ! ( ( $self->module_config_( 'nntp', 'enabled' ) ) && ! ( $self->module_config_( 'nntp', 'force_fork' ) ) ) || ! ( ( $self->module_config_( 'smtp', 'enabled' ) ) && ! ( $self->module_config_( 'smtp', 'force_fork' ) ) ) ) ) { $self->{parser__}->{need_kakasi_mutex__} = 1; *************** *** 1728,1732 **** # Verify that the user has an administrator session set up ! if ( $self->get_user_parameter( $session, 'GLOBAL_can_admin' ) != 1 ) { return undef; } --- 1728,1732 ---- # Verify that the user has an administrator session set up ! if ( !$self->is_admin_session( $session ) ) { return undef; } *************** *** 2816,2822 **** # Check that this user is an administrator ! my $can_admin = $self->get_user_parameter( $session, 'GLOBAL_can_admin' ); ! ! if ( $can_admin != 1 ) { return undef; } --- 2816,2820 ---- # Check that this user is an administrator ! if ( !$self->is_admin_session( $session ) ) { return undef; } *************** *** 2855,2861 **** # Check that this user is an administrator ! my $can_admin = $self->get_user_parameter( $session, 'GLOBAL_can_admin' ); ! ! if ( $can_admin != 1 ) { return 0; } --- 2853,2857 ---- # Check that this user is an administrator ! if ( !$self->is_admin_session( $session ) ) { return 0; } *************** *** 2900,2910 **** # Check that this user is an administrator ! my $can_admin = $self->get_user_parameter( $session, 'GLOBAL_can_admin' ); ! ! if ( $can_admin != 1 ) { return 0; } ! my $result = $self->db_()->do( "delete from accounts where account = '$module:$account';" ); return defined( $result ); --- 2896,2905 ---- # Check that this user is an administrator ! if ( !$self->is_admin_session( $session ) ) { return 0; } ! my $quoted_account = $self->db_()->quote( "$module:$account" ); ! my $result = $self->db_()->do( "delete from accounts where account = $quoted_account;" ); return defined( $result ); *************** *** 2957,2960 **** --- 2952,2956 ---- my $userid = $self->valid_session_key__( $session ); return undef if ( !defined( $userid ) ); + return undef if ( !defined( $self->{db_bucketid__}{$userid}{$bucket} ) ); return $self->{db_bucketid__}{$userid}{$bucket}{id}; *************** *** 2984,2988 **** } ! return ''; } --- 2980,2984 ---- } ! return undef; } *************** *** 3374,3380 **** # Check that this user is an administrator ! my $can_admin = $self->get_user_parameter( $session, 'GLOBAL_can_admin' ); ! ! if ( $can_admin != 1 ) { return ( undef, undef ); } --- 3370,3374 ---- # Check that this user is an administrator ! if ( !$self->is_admin_session( $session ) ) { return ( undef, undef ); } *************** *** 3390,3394 **** my $password_hash = md5_hex( $new_user . '__popfile__' . $password ); ! $self->db_()->do( "insert into users ( name, password ) values ( '$new_user', '$password_hash' );" ); my $id = $self->get_user_id( $session, $new_user ); --- 3384,3390 ---- my $password_hash = md5_hex( $new_user . '__popfile__' . $password ); ! my $quoted_user = $self->db_()->quote( $new_user ); ! my $quoted_hash = $self->db_()->quote( $password_hash ); ! $self->db_()->do( "insert into users ( name, password ) values ( $quoted_user, $quoted_hash );" ); my $id = $self->get_user_id( $session, $new_user ); *************** *** 3433,3437 **** $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; --- 3429,3433 ---- $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; *************** *** 3458,3462 **** my $val = $self->db_()->quote( $bucket_params{$bucketid}{$btid} ); $self->db_()->do( ! "insert into bucket_params ( bucketid, btid, val ) values ( $bucketid, $btid, $val );" ); } --- 3454,3458 ---- my $val = $self->db_()->quote( $bucket_params{$bucketid}{$btid} ); $self->db_()->do( ! "insert into bucket_params ( bucketid, btid, val ) values ( $bucketid, $btid, $val );" ); } *************** *** 3522,3528 **** # Check that this user is an administrator ! my $can_admin = $self->get_user_parameter( $session, 'GLOBAL_can_admin' ); ! ! if ( $can_admin != 1 ) { return undef; } --- 3518,3522 ---- # Check that this user is an administrator ! if ( !$self->is_admin_session( $session ) ) { return undef; } *************** *** 3533,3539 **** if ( defined( $id ) ) { ! my ( $val, $def ) = $self->get_user_parameter_from_id( $id,'GLOBAL_can_admin' ); if ( $val == 0 ) { ! $self->db_()->do( "delete from users where name = '$user';" ); return 0; } else { --- 3527,3534 ---- if ( defined( $id ) ) { ! my ( $val, $def ) = $self->get_user_parameter_from_id( $id, 'GLOBAL_can_admin' ); if ( $val == 0 ) { ! my $quoted_user = $self->db_()->quote( $user ); ! $self->db_()->do( "delete from users where name = $quoted_user;" ); return 0; } else { *************** *** 3567,3573 **** # Check that this user is an administrator ! my $can_admin = $self->get_user_parameter( $session, 'GLOBAL_can_admin' ); ! ! if ( $can_admin != 1 ) { return undef; } --- 3562,3566 ---- # Check that this user is an administrator ! if ( !$self->is_admin_session( $session ) ) { return undef; } *************** *** 3609,3615 **** # Check that this user is an administrator ! my $can_admin = $self->get_user_parameter( $session, 'GLOBAL_can_admin' ); ! ! if ( $can_admin != 1 ) { return undef; } --- 3602,3606 ---- # Check that this user is an administrator ! if ( !$self->is_admin_session( $session ) ) { return undef; } *************** *** 3645,3655 **** # 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 ) { ! $h->finish; ! $user = $row->[0]; ! } else { return 0; } --- 3636,3641 ---- # Lookup the user name from the session key ! my $user = $self->get_user_name_from_session( $session ); ! if ( !defined( $user ) ) { return 0; } *************** *** 3682,3686 **** my ( $self, $session, $password ) = @_; ! my $userid = $self->{api_sessions__}{$session}; return $self->set_password_for_user( $session, $userid, $password ); --- 3668,3673 ---- my ( $self, $session, $password ) = @_; ! my $userid = $self->valid_session_key__( $session ); ! return 0 if ( !defined( $userid ) ); return $self->set_password_for_user( $session, $userid, $password ); *************** *** 3704,3716 **** 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 ) { ! $h->finish; ! $user = $row->[0]; ! } else { return 0; } --- 3691,3711 ---- my ( $self, $session, $userid, $password ) = @_; ! # Get user id for the session ! my $current_userid = $self->valid_session_key__( $session ); ! return 0 if ( !defined( $current_userid ) ); ! ! if ( $current_userid != $userid ) { ! # If the current user id is not the specified user id, check can_admin ! ! if ( !$self->is_admin_session( $session ) ) { ! return 0; ! } ! } ! ! # Lookup the user name from the user id ! ! my $user = $self->get_user_name_from_id( $session, $userid ); ! if ( !defined( $user ) ) { return 0; } *************** *** 3718,3722 **** my $hash = md5_hex( $user . '__popfile__' . $password ); ! $self->db_()->do( "update users set password = '$hash' where id = $userid;" ); return 1; --- 3713,3718 ---- my $hash = md5_hex( $user . '__popfile__' . $password ); ! my $quoted_hash = $self->db_()->quote( $hash ); ! $self->db_()->do( "update users set password = $quoted_hash where id = $userid;" ); return 1; *************** *** 3741,3747 **** # Check that this user is an administrator ! my $can_admin = $self->get_user_parameter( $session, 'GLOBAL_can_admin' ); ! ! if ( $can_admin != 1 ) { return undef; } --- 3737,3741 ---- # Check that this user is an administrator ! if ( !$self->is_admin_session( $session ) ) { return undef; } *************** *** 3774,3780 **** # Check that this user is an administrator ! my $can_admin = $self->get_user_parameter( $session, 'GLOBAL_can_admin' ); ! ! if ( $can_admin != 1 ) { return undef; } --- 3768,3772 ---- # Check that this user is an administrator ! if ( !$self->is_admin_session( $session ) ) { return undef; } *************** *** 3824,3834 **** # 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 $h = $self->db_()->prepare( "select id from users where name = '$user';" ); $h->execute; if ( my $row = $h->fetchrow_arrayref ) { --- 3816,3825 ---- # Check that this user is an administrator ! if ( !$self->is_admin_session( $session ) ) { return undef; } ! my $quoted_user = $self->db_()->quote( $user ); ! my $h = $self->db_()->prepare( "select id from users where name = $quoted_user;" ); $h->execute; if ( my $row = $h->fetchrow_arrayref ) { *************** *** 3842,3845 **** --- 3833,3854 ---- #---------------------------------------------------------------------------- # + # is_admin_session + # + # Returns TRUE if the session is admin's + # + # $session The valid session ID + # + #---------------------------------------------------------------------------- + sub is_admin_session + { + my ( $self, $session ) = @_; + + my $result = $self->get_user_parameter( $session, 'GLOBAL_can_admin' ); + + return ( defined($result) ? ( $result == 1 ) : undef ); + } + + #---------------------------------------------------------------------------- + # # get_user_parameter_from_id # *************** *** 4127,4134 **** } $self->db_()->do( # PROFILE BLOCK START ! "delete from buckets where ! buckets.userid = $userid and ! buckets.name = '$bucket' and buckets.pseudo = 0;" ); # PROFILE BLOCK STOP $self->db_update_cache__( $session ); --- 4136,4144 ---- } + my $quoted_bucket = $self->db_()->quote( $bucket ); $self->db_()->do( # PROFILE BLOCK START ! "delete from buckets where ! buckets.userid = $userid and ! buckets.name = $quoted_bucket and buckets.pseudo = 0;" ); # PROFILE BLOCK STOP $self->db_update_cache__( $session ); *************** *** 4162,4165 **** --- 4172,4180 ---- } + if ( defined( $self->{db_bucketid__}{$userid}{$new_bucket} ) ) { + $self->log_( 0, "Bucket named $new_bucket already exists" ); + return 0; + } + my $id = $self->db_()->quote( $self->{db_bucketid__}{$userid}{$old_bucket}{id} ); $new_bucket = $self->db_()->quote( $new_bucket ); *************** *** 4311,4320 **** my $bucketid = $self->{db_bucketid__}{$userid}{$bucket}{id}; ! my $h = $self->db_()->prepare( "select magnet_types.mtype from magnet_types, magnets, buckets ! where magnet_types.id = magnets.mtid and ! magnets.bucketid = buckets.id and ! buckets.id = $bucketid ! group by magnet_types.mtype ! order by magnet_types.mtype;" ); $h->execute; --- 4326,4336 ---- my $bucketid = $self->{db_bucketid__}{$userid}{$bucket}{id}; ! my $h = $self->db_()->prepare( ! "select magnet_types.mtype from magnet_types, magnets, buckets ! where magnet_types.id = magnets.mtid and ! magnets.bucketid = buckets.id and ! buckets.id = $bucketid ! group by magnet_types.mtype ! order by magnet_types.mtype;" ); $h->execute; *************** *** 4393,4401 **** my $bucketid = $self->{db_bucketid__}{$userid}{$bucket}{id}; ! my $h = $self->db_()->prepare( "select magnets.val from magnets, magnet_types ! where magnets.bucketid = $bucketid and ! magnets.id != 0 and ! magnet_types.id = magnets.mtid and ! magnet_types.mtype = '$type' order by magnets.val;" ); $h->execute; --- 4409,4418 ---- my $bucketid = $self->{db_bucketid__}{$userid}{$bucket}{id}; ! my $h = $self->db_()->prepare( ! "select magnets.val from magnets, magnet_types ! where magnets.bucketid = $bucketid and ! magnets.id != 0 and ! magnet_types.id = magnets.mtid and ! magnet_types.mtype = '$type' order by magnets.val;" ); $h->execute; *************** *** 4428,4433 **** my $bucketid = $self->{db_bucketid__}{$userid}{$bucket}{id}; ! my $result = $self->db_()->selectrow_arrayref("select magnet_types.id from magnet_types ! where magnet_types.mtype = '$type';" ); my $mtid = $result->[0]; --- 4445,4451 ---- my $bucketid = $self->{db_bucketid__}{$userid}{$bucket}{id}; ! my $result = $self->db_()->selectrow_arrayref( ! "select magnet_types.id from magnet_types ! where magnet_types.mtype = '$type';" ); my $mtid = $result->[0]; *************** *** 4488,4493 **** my $bucketid = $self->{db_bucketid__}{$userid}{$bucket}{id}; ! my $result = $self->db_()->selectrow_arrayref("select magnet_types.id from magnet_types ! where magnet_types.mtype = '$type';" ); my $mtid = $result->[0]; --- 4506,4512 ---- my $bucketid = $self->{db_bucketid__}{$userid}{$bucket}{id}; ! my $result = $self->db_()->selectrow_arrayref( ! "select magnet_types.id from magnet_types ! where magnet_types.mtype = '$type';" ); my $mtid = $result->[0]; *************** *** 4535,4542 **** return undef if ( !defined( $userid ) ); ! my $result = $self->db_()->selectrow_arrayref( "select count(*) from magnets, buckets ! where buckets.userid = $userid and ! magnets.id != 0 and ! magnets.bucketid = buckets.id;" ); if ( defined( $result ) ) { --- 4554,4562 ---- return undef if ( !defined( $userid ) ); ! my $result = $self->db_()->selectrow_arrayref( ! "select count(*) from magnets, buckets ! where buckets.userid = $userid and ! magnets.id != 0 and ! magnets.bucketid = buckets.id;" ); if ( defined( $result ) ) { Index: MailParse.pm =================================================================== RCS file: /cvsroot/popfile/engine/Classifier/MailParse.pm,v retrieving revision 1.230 retrieving revision 1.231 diff -C2 -d -r1.230 -r1.231 *** MailParse.pm 27 Nov 2007 14:44:56 -0000 1.230 --- MailParse.pm 5 Apr 2008 16:50:45 -0000 1.231 *************** *** 350,354 **** # from hh hh hh format ! $self->{htmlcolordistance__} = $self->compute_rgb_distance( $self->{htmlfontcolor__}, $self->{htmlbackcolor__} ); } --- 350,357 ---- # from hh hh hh format ! if ( $self->{htmlfontcolor__} ne '' && $self->{htmlbackcolor__} ne '' ) { ! $self->{htmlcolordistance__} = $self->compute_rgb_distance( ! $self->{htmlfontcolor__}, $self->{htmlbackcolor__} ); ! } } *************** *** 830,834 **** $original = $1; $attribute = $2; ! $value = $5 || $6; $quote = ''; $end_quote = '[\> \t\&\n]'; --- 833,837 ---- $original = $1; $attribute = $2; ! $value = $5 || $6 || ''; $quote = ''; $end_quote = '[\> \t\&\n]'; *************** *** 2398,2405 **** $found = 0 if ($error); ! if ( defined($r) && ( 0 <= $r) && ($r <= 255) && # PROFILE BLOCK START defined($g) && ( 0 <= $g) && ($g <= 255) && ! defined($b) && ( 0 <= $b) && ($b <= 255) && ! $found ) { # PROFILE BLOCK STOP if (wantarray) { return ( $r, $g, $b ); --- 2401,2408 ---- $found = 0 if ($error); ! if ( $found && # PROFILE BLOCK START ! defined($r) && ( 0 <= $r) && ($r <= 255) && defined($g) && ( 0 <= $g) && ($g <= 255) && ! defined($b) && ( 0 <= $b) && ($b <= 255) ) { # PROFILE BLOCK STOP if (wantarray) { return ( $r, $g, $b ); |