From: naoki i. <am...@us...> - 2008-04-17 15:13:03
|
Update of /cvsroot/popfile/engine/UI In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6287/UI Modified Files: HTML.pm HTTP.pm Log Message: Change Log 1. The session keys are now released when they are expired 2. New global parameter 'GLOBAL_session_timeout' (default : 1800 seconds) 3. Replaced get_administrator_session_key with get_single_user_session_key Classifier/Bayes.pm UI/HTML.pm POPFile/History.pm POPFile/Configuration.pm tests/TestConfiguration.tst The session keys which does not used in GLOBAL_session_timeout seconds will be released. NOTE : The session key for the administrator which got from get_administrator_session_key won't be expired. For this reason, please use get_single_user_session_key instead of get_administrator_session_key in the single user mode. NOTE : The 'last used time' is updated when valid_session_key__ is called with the session key. 4. Added 'Single User Mode Parameters' section in the Advanced tab UI/HTML.pm skins/default/advanced-page.thtml languages/English.msg languages/Nihongo.msg All POPFile parameters now can be changed in the single user mode. 'Single User Mode Parameters' section has been added below the 'Global POPFile Parameters' section. 5. Updated translation file languages/Nihongo.msg 6. The session cache is purged when the session key is released 7. The query is stopped when the session key is released UI/HTML.pm 8. Added escape_html_() function in HTTP.pm UI/HTTP.pm UI/HTML.pm tests/TestHTML.script This function is used for escaping ", <, >, &, ' characters. They are converted to ", <, >, & and ' 9. The matched header is showed/emphasized if the magnets are used UI/HTML.pm POPFile/History.pm Classifier/Bayes.pm tests/TestHTML.script The magnet icon's "title" will be like 'From:te...@ex...' in the history tab. The header information will be showed/emphasized in the single message view. 10. Minor fixes of the skins skins/default/common-bottom.thtml skins/default/users-page.thtml skins/default/administration-page.thtml skins/default/pop3-chain-panel.thtml skins/default/pop3-configuration-panel.thtml skins/default/socks-widget.thtml skins/default/nntp-configuration.thtml skins/default/smtp-configuration.thtml skins/default/windows-configuration.thtml Proxy/POP3.pm Proxy/NNTP.pm Proxy/SMTP.pm Platform/MSWin32.pm tests/TestPOP3.tst tests/TestHTML.tst Current state of the test suite: TestBayesScript PASS TestBayes PASS TestConfiguration PASS * TestHistory PASS TestHTML PASS * TestHTTP PASS TestIMAP PASS TestInsertScript PASS * TestLogger PASS TestMailParse PASS TestModule PASS TestMQ PASS TestMutex PASS TestPipeScript PASS TestPOP3 PASS TestProxy PASS TestWordMangle PASS TestXMLRPC PASS * : TODO : needs to add tests for multi user support Index: HTML.pm =================================================================== RCS file: /cvsroot/popfile/engine/UI/HTML.pm,v retrieving revision 1.389 retrieving revision 1.390 diff -C2 -d -r1.389 -r1.390 *** HTML.pm 16 Apr 2008 13:08:04 -0000 1.389 --- HTML.pm 17 Apr 2008 15:13:05 -0000 1.390 *************** *** 264,269 **** if ( $type eq 'RELSE' ) { ! if ( defined( $message[0] ) && defined( $self->{language__}{$message[0]} ) ) { ! delete $self->{language__}{$message[0]}; } } --- 264,279 ---- if ( $type eq 'RELSE' ) { ! my $session = $message[0]; ! ! # Purge the language cache ! ! if ( exists( $self->{language__}{$session} ) ) { ! delete $self->{language__}{$session}; ! } ! ! # Purge the session cache and stop query ! if ( exists( $self->{sessions__}{$session} ) ) { ! $self->history_()->stop_query( $self->{sessions__}{$session}{q} ); ! delete $self->{sessions__}{$session}; } } *************** *** 327,339 **** } - # Now see if this session has been recorded in the current - # sessions, if so then return it, because we can assume that it is - # valid - - if ( exists( $self->{sessions__}{$session} ) ) { - $self->{sessions__}{$session}{lastused} = time; - return $session; - } - # Let's see if the session key is the magic string LOGGED-OUT # in which case there's no session --- 337,340 ---- *************** *** 343,352 **** } ! # Otherwise check that the session ID is still valid in the API. my $user = $self->classifier_()->valid_session_key__( $session ); if ( defined( $user ) ) { ! $self->{sessions__}{$session}{lastused} = time; $self->{sessions__}{$session}{user} = $user; $self->{sessions__}{$session}{sort} = ''; --- 344,370 ---- } ! # Check that the session ID is still valid in the API. my $user = $self->classifier_()->valid_session_key__( $session ); + # Now see if this session has been recorded in the current + # sessions, if so then return it, because we can assume that it is + # valid + + if ( exists( $self->{sessions__}{$session} ) ) { + if ( defined($user) ) { + # $self->{sessions__}{$session}{lastused} = time; + return $session; + } else { + $self->history_()->stop_query( $self->{sessions__}{$session}{q} ); + delete $self->{sessions__}{$session}; + return undef; + } + } + + # Check that the session ID is still valid in the API. + if ( defined( $user ) ) { ! # $self->{sessions__}{$session}{lastused} = time; $self->{sessions__}{$session}{user} = $user; $self->{sessions__}{$session}{sort} = ''; *************** *** 466,477 **** } ! # In single user mode get the administrator key if ( !defined( $session ) && ! $self->global_config_( 'single_user' ) ) { ! $session = $self->classifier_()->get_session_key( 'admin', '' ); if ( defined ( $session ) ) { ! $self->{sessions__}{$session}{lastused} = time; $self->{sessions__}{$session}{user} = 1; $self->{sessions__}{$session}{sort} = ''; --- 484,495 ---- } ! # In single user mode get the single user mode key if ( !defined( $session ) && ! $self->global_config_( 'single_user' ) ) { ! $session = $self->classifier_()->get_single_user_session_key(); if ( defined ( $session ) ) { ! # $self->{sessions__}{$session}{lastused} = time; $self->{sessions__}{$session}{user} = 1; $self->{sessions__}{$session}{sort} = ''; *************** *** 1738,1742 **** $page, $session ); ! # Handle updating the parameter table if ( defined( $self->{form_}{update_params} ) ) { --- 1756,1762 ---- $page, $session ); ! my $single_mode = $self->global_config_( 'single_user' ); ! ! # Handle updating the global parameter table if ( defined( $self->{form_}{update_params} ) ) { *************** *** 1751,1754 **** --- 1771,1787 ---- } + # Handle updating the single user mode parameter table + + if ( $single_mode && defined( $self->{form_}{update_single_user_params} ) ) { + foreach my $param (sort keys %{$self->{form_}}) { + if ( $param =~ /parameter_(.*)/ ) { + $self->classifier_()->set_user_parameter_from_id( 1, + $1, $self->{form_}{$param} ); + } + } + } + + # Handle adding/removing words to/from stopwords + if ( defined($self->{form_}{newword}) ) { my $result = $self->classifier_()->add_stopword( $session, *************** *** 1771,1775 **** } ! # the word census my $last = ''; my $need_comma = 0; --- 1804,1809 ---- } ! # the word census ( stopword ) ! my $last = ''; my $need_comma = 0; *************** *** 1833,1836 **** --- 1867,1872 ---- } + # POPFile global parameters + $templ->param( 'Advanced_Loop_Word' => \@word_loop ); *************** *** 1868,1871 **** --- 1904,1934 ---- $templ->param( 'Advanced_Loop_Parameter' => \@param_loop ); + # Single user mode parameters + + $templ->param( 'Advanced_If_SingleUser' => $single_mode ); + + if ( $single_mode ) { + my @parameters = $self->classifier_()->get_user_parameter_list( $session ); + + my @parameter_list; + my $last = ''; + foreach my $param (sort @parameters) { + my %row_data; + $param =~ /^([^_]+)_/; + if ( ( $last ne '' ) && ( $last ne $1 ) ) { + $row_data{Users_If_New_Module} = 1; + } else { + $row_data{Users_If_New_Module} = 0; + } + $last = $1; + $row_data{Users_Parameter} = $param; + my ( $val, $default ) = $self->classifier_()->get_user_parameter_from_id( 1, $param ); + $row_data{Users_Value} = $val; + $row_data{Users_If_Changed} = !$default; + push ( @parameter_list, \%row_data ); + } + $templ->param( 'Users_Loop_Parameter' => \@parameter_list ); + } + $self->http_ok( $client, $templ, 5, $session ); } *************** *** 2098,2106 **** # field - my $validatingMagnet = $magnet; - $validatingMagnet =~ s/&/&/g; - $validatingMagnet =~ s/</</g; - $validatingMagnet =~ s/>/>/g; - # escape quotation characters to avoid orphan data # within tags todo: function to make arbitrary data --- 2161,2164 ---- *************** *** 2108,2112 **** # (inside double-quotes) ! $validatingMagnet =~ s/\"/\"\;/g; $row_data{Magnet_Row_ID} = $i; --- 2166,2170 ---- # (inside double-quotes) ! my $validatingMagnet = $self->escape_html_( $magnet ); $row_data{Magnet_Row_ID} = $i; *************** *** 2607,2613 **** if ( $max_bucket ne '' ) { ! $templ->param( 'Corpus_Lookup_Message' => sprintf( $self->language($session)->{Bucket_LookupMostLikely}, $word, $self->classifier_()->get_bucket_color( $session, $max_bucket ), $max_bucket ) ); } else { ! $templ->param( 'Corpus_Lookup_Message' => sprintf( $self->language($session)->{Bucket_DoesNotAppear}, $word ) ); } } --- 2665,2677 ---- if ( $max_bucket ne '' ) { ! $templ->param( 'Corpus_Lookup_Message' => ! sprintf( $self->language($session)->{Bucket_LookupMostLikely}, ! $self->escape_html_( $word ), ! $self->classifier_()->get_bucket_color( $session, $max_bucket ), ! $max_bucket ) ); } else { ! $templ->param( 'Corpus_Lookup_Message' => ! sprintf( $self->language($session)->{Bucket_DoesNotAppear}, ! $self->escape_html_( $word ) ) ); } } *************** *** 3016,3020 **** $templ->param( 'History_Field_Search' => $self->{form_}{search} ); ! $templ->param( 'History_Field_Not' => $self->{form_}{negate} ); $templ->param( 'History_If_Search' => defined( $self->{form_}{search} ) ); $templ->param( 'History_Field_Sort' => $self->{form_}{sort} ); --- 3080,3084 ---- $templ->param( 'History_Field_Search' => $self->{form_}{search} ); ! $templ->param( 'History_Field_Not' => $self->{form_}{negate} ); $templ->param( 'History_If_Search' => defined( $self->{form_}{search} ) ); $templ->param( 'History_Field_Sort' => $self->{form_}{sort} ); *************** *** 3241,3245 **** if ( $$row[11] ne '' ) { $col_data{History_If_Magnetized} = 1; ! $col_data{History_Magnet} = $$row[11]; } $col_data{History_If_Not_Pseudo} = --- 3305,3312 ---- if ( $$row[11] ne '' ) { $col_data{History_If_Magnetized} = 1; ! my ( $header, $value ) = ! $self->classifier_()->get_magnet_header_and_value( $session, $$row[13] ); ! $col_data{History_Magnet} = ! $self->language($session)->{$header} . ':' . $value; } $col_data{History_If_Not_Pseudo} = *************** *** 3342,3348 **** my ( $id, $from, $to, $cc, $subject, $date, $hash, $inserted, ! $bucket, $reclassified, $bucketid, $magnet ) = $self->history_()->get_slot_fields( $self->{form_}{view}, $session ); if ( !defined($id) ) { $self->http_redirect_( $client, "/history", $session ); --- 3409,3421 ---- my ( $id, $from, $to, $cc, $subject, $date, $hash, $inserted, ! $bucket, $reclassified, $bucketid, $magnet, $size, $magnetid ) = $self->history_()->get_slot_fields( $self->{form_}{view}, $session ); + my ( $header, $value ); + if ( $magnet ne '' ) { + ( $header, $value ) = + $self->classifier_()->get_magnet_header_and_value( $session, $magnetid ); + } + if ( !defined($id) ) { $self->http_redirect_( $client, "/history", $session ); *************** *** 3411,3415 **** $templ->param( 'View_Loop_Buckets' => \@bucket_data ); } else { ! $templ->param( 'View_Magnet' => $magnet ); } } --- 3484,3488 ---- $templ->param( 'View_Loop_Buckets' => \@bucket_data ); } else { ! $templ->param( 'View_Magnet' => $self->language($session)->{$header} . ':' . $value ); } } *************** *** 3478,3487 **** } else { - # TODO: See comment below for details - - # $magnet =~ /(.+): ([^\r\n]+)/; - # my $header = $1; - # my $text = $2; - my $body = '<tt>'; --- 3551,3554 ---- *************** *** 3490,3521 **** while ($line = <MESSAGE>) { ! $line =~ s/</</g; ! $line =~ s/>/>/g; $line =~ s/([^\r\n]{100,150} )/$1<br \/>/g; $line =~ s/([^ \r\n]{150})/$1<br \/>/g; $line =~ s/[\r\n]+/<br \/>/g; ! # TODO: This code is now useless because the magnet itself ! # doesn't contain the information about which header we ! # are looking for. Ultimately, we need to fix this but I ! # decided for v0.22.0 release to not make further changes ! # and leave this code as unfixed. ! ! # if ( $line =~ /^([A-Za-z-]+): ?([^\n\r]*)/ ) { ! # my $head = $1; ! # my $arg = $2; ! # ! # if ( $head =~ /\Q$header\E/i ) { ! # ! # $text =~ s/</</g; ! # $text =~ s/>/>/g; ! # ! # if ( $arg =~ /\Q$text\E/i ) { ! # my $new_color = $self->classifier_()->get_bucket_color( $session, $bucket ); ! # $line =~ s/(\Q$text\E)/<b style=\"color:$new_color\">$1<\/b>/; ! # } ! # } ! # } $body .= $line; --- 3557,3581 ---- while ($line = <MESSAGE>) { ! $line = $self->escape_html_( $line ); $line =~ s/([^\r\n]{100,150} )/$1<br \/>/g; $line =~ s/([^ \r\n]{150})/$1<br \/>/g; $line =~ s/[\r\n]+/<br \/>/g; + $line =~ s/\t/ /g; ! if ( $line =~ /^([A-Za-z-]+): ?([^\n\r]*)/ ) { ! my $head = $1; ! my $arg = $2; ! ! if ( $head =~ /\Q$header\E/i ) { ! ! $value = $self->escape_html_( $value ); ! ! if ( $arg =~ /\Q$value\E/i ) { ! my $new_color = $self->classifier_()->get_bucket_color( $session, $bucket ); ! $line =~ s/(\Q$header\E|\Q$value\E)/<b style=\"color:$new_color\">$1<\/b>/g; ! } ! } ! } $body .= $line; *************** *** 3526,3533 **** } ! if ($magnet ne '') { $templ->param( 'View_Magnet_Reason' => sprintf( $self->language($session)->{History_MagnetBecause}, # PROFILE BLOCK START $color, $bucket, ! Classifier::MailParse->splitline($magnet,0) ) ); # PROFILE BLOCK STOP } --- 3586,3593 ---- } ! if ( $magnet ne '' ) { $templ->param( 'View_Magnet_Reason' => sprintf( $self->language($session)->{History_MagnetBecause}, # PROFILE BLOCK START $color, $bucket, ! Classifier::MailParse->splitline( $self->language($session)->{$header} . ':' . $value, 0 ) ) ); # PROFILE BLOCK STOP } *************** *** 3596,3603 **** my ( $self, $templ, $message ) = @_; ! $message =~ s/&/&/g; ! $message =~ s/</</g; ! $message =~ s/>/>/g; ! $message =~ s/\"/"/g; $message =~ s/\n/<br \/>/g; --- 3656,3660 ---- my ( $self, $templ, $message ) = @_; ! $message = $self->escape_html_( $message ); $message =~ s/\n/<br \/>/g; *************** *** 3622,3629 **** my ( $self, $templ, $message ) = @_; ! $message =~ s/&/&/g; ! $message =~ s/</</g; ! $message =~ s/>/>/g; ! $message =~ s/\"/"/g; $message =~ s/\n/<br \/>/g; --- 3679,3683 ---- my ( $self, $templ, $message ) = @_; ! $message = $self->escape_html_( $message ); $message =~ s/\n/<br \/>/g; Index: HTTP.pm =================================================================== RCS file: /cvsroot/popfile/engine/UI/HTTP.pm,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** HTTP.pm 13 Apr 2008 03:08:09 -0000 1.39 --- HTTP.pm 17 Apr 2008 15:13:05 -0000 1.40 *************** *** 391,394 **** --- 391,416 ---- # ---------------------------------------------------------------------------- # + # escape_html_ + # + # $text Text to HTML-escaped + # + # Escape &, ", >, <, ' + # + # ---------------------------------------------------------------------------- + sub escape_html_ + { + my ( $self, $text ) = @_; + + $text =~ s/&/&/g; + $text =~ s/\"/"/g; + $text =~ s/>/>/g; + $text =~ s/</</g; + $text =~ s/'/'/g; + + return $text; + } + + # ---------------------------------------------------------------------------- + # # http_error_ - Output a standard HTTP error message # |