/[mws]/trunk/httpd.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/httpd.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 12 by dpavlin, Thu May 6 12:40:11 2004 UTC revision 21 by dpavlin, Sat May 8 00:54:16 2004 UTC
# Line 14  use MWS; Line 14  use MWS;
14    
15  use Data::Dumper;  use Data::Dumper;
16    
17  my $d = HTTP::Daemon->new( Reuse => 1, LocalPort => 6969 ) || die;  my $debug = 1;
 print "Please contact me at: <URL:", $d->url, ">\n";  
18    
19    my $d = HTTP::Daemon->new( Reuse => 1, LocalPort => 6969 ) || die;
20  my $cgi = new CGI::Lite;  my $cgi = new CGI::Lite;
21  my $mws = MWS->new('global.conf');  my $mws = MWS->new('global.conf');
22  my $tt = Template->new({  my $tt = Template->new({
23          INCLUDE_PATH => $mws->{config}->val('global', 'templates'),          INCLUDE_PATH => $mws->{config}->val('global', 'templates'),
24          FILTERS => {          FILTERS => {
25                  'body5' => \&body5_filter,                  'body5' => \&body5_filter,
26                    'subject_search' => \&subject_search_filter,
27          },          },
28            EVAL_PERL => 1,
29  });  });
30    
31    print "Web server ready at: ", $d->url, "\n";
32    
33    
34  while ( my $c = $d->accept ) {  while ( my $c = $d->accept ) {
35          while ( my $r = $c->get_request ) {          while ( my $r = $c->get_request ) {
# Line 67  while ( my $c = $d->accept ) { Line 71  while ( my $c = $d->accept ) {
71                  my $url = $r->url->path;                  my $url = $r->url->path;
72    
73                  # XXX LOG                  # XXX LOG
74                  print $r->method," ",$url,Dumper($param);                  print $r->method," ",$url,"\n",Dumper($param),"\n" if ($debug);
75    
76                  # template file name (use ?format=html as default)                  # template file name (use ?format=html as default)
77                  my $tpl_file = 'master.';                  my $tpl_file = 'master.';
78                  $tpl_file .= $param->{'format'} || 'html';                  $tpl_file .= $param->{'format'} || 'html';
79    
80                    # parse date from url
81                    my ($yyyy,$mm,$dd) = $mws->yyyymmdd;
82    
83                    my $yyyymm;
84    
85                    my $date_limit;
86    
87                    if ($url =~ m,^/(\d{4})[/-](\d+)[/-](\d+),) {
88                            ($yyyy, $mm, $dd) = $mws->fmtdate($1,$2,$3);
89                             $date_limit = "$yyyy-$mm-$dd";
90                    } elsif ($url =~ m,^/(\d{4})[/-](\d+),) {
91                            ($yyyy,$mm) = $mws->fmtdate($1,$2);
92                            $date_limit = "$yyyy-$mm";
93                    } elsif ($url =~ m,^/(\d{4}),) {
94                            $date_limit = $mws->fmtdate($1);
95                    }
96    
97                  #                  #
98                  # implement functionality and generate HTML                  # implement functionality and generate HTML
99                  #                  #
# Line 80  while ( my $c = $d->accept ) { Line 101  while ( my $c = $d->accept ) {
101    
102                  if ($param->{'search_val'} && $param->{'search_fld'} && !$param->{'search'}) {                  if ($param->{'search_val'} && $param->{'search_fld'} && !$param->{'search'}) {
103                          $param->{'search'} = $param->{'search_fld'}.":".$param->{'search_val'};                          $param->{'search'} = $param->{'search_fld'}.":".$param->{'search_val'};
104                    } elsif ($param->{'search'}) {
105                            ($param->{'search_fld'}, $param->{'search_val'}) = split(/:/,$param->{'search'},2);
106                  }                  }
107    
108                  # show search results                  my $tpl_var = {
109                  # ?search=foo:bar                          param   => $param,
110                  if ($param->{'search'}) {                          yyyy    => $yyyy,
111                            mm      => $mm,
112                            dd      => $dd,
113                            date_limit => $date_limit,
114                    };
115    
116                    #
117                    # ?show_id=XXXXxxxx___message_id___xxxxXXXX
118                    if ($param->{'show_id'}) {
119    
120                            $mws->reset_counters;
121                            my $row = $mws->fetch_result_by_id($param->{'show_id'});
122                            $tpl_var->{message} = $row;
123                    } elsif ($param->{'search'} || $date_limit) {
124    
125                            # show search results
126                            # ?search=foo:bar
127    
128                          print STDERR "search: ",$param->{'search'},"\n";                          my @search = ( $param->{'search'} );
129    
130                          my $results = $mws->search($param->{'search'});                          if ($date_limit) {
131                                    push @search, "and" if (@search);
132                                    push @search, "date:\"$date_limit\"";
133                            }
134    
135                            print STDERR "search: ",join(" ",@search),"\n";
136    
137                            my $results = $mws->search(@search);
138                          my @res = $mws->fetch_all_results();                          my @res = $mws->fetch_all_results();
139    
140                          $tt->process($tpl_file, {                          $tpl_var->{results} = \@res if (@res);
141                                  query   => $param->{'search'},                          $tpl_var->{total_hits} = $mws->{total_hits};
                                 results => \@res,  
                                 param   => $param,  
                         }, \$html) || die $tt->error();  
142    
                 #  
                 # ?show_id=XXXXxxxx___message_id___xxxxXXXX  
                 } elsif ($param->{'show_id'}) {  
                           
                         my $row = $mws->fetch_result_by_id($param->{'show_id'});  
                         $tt->process($tpl_file, {  
                                 message => $row,  
                         }, \$html) || die $tt->error();  
143                  }                  }
144    
145    
146                    # push counters to template
147                    foreach my $f (qw(from to cc bcc)) {
148                            my $h = $mws->counter($f) || next;
149                            my @a;
150                            foreach my $k (sort { $h->{$b}->{usage} <=> $h->{$a}->{usage} } keys %$h) {
151                                    push @a, $h->{$k};
152                            }
153                            $tpl_var->{counters}->{$f} = [ @a ] if (@a);
154                    }
155    
156                    # push calendar in template
157                    $tpl_var->{calendar} = $mws->counter('calendar');
158    
159                    $tt->process($tpl_file, $tpl_var, \$html) || die $tt->error();
160    
161                  #                  #
162                  # send HTMLto client                  # send HTMLto client
163                  #                  #
164    
165                  my $res = HTTP::Response->new(RC_OK);                  my $res = HTTP::Response->new(RC_OK);
166                  $res->header( 'Content-type' => 'text/html; charset=iso-8859-2' );                  $res->header( 'Content-type' => 'text/html; charset=ISO-8859-2' );
167                  $res->content($html);                  $res->content($html);
168                  $c->send_response($res);                  $c->send_response($res);
169    
# Line 130  sub body5_filter { Line 181  sub body5_filter {
181          $text =~ s/^\s+//gs;          $text =~ s/^\s+//gs;
182          $text =~ s/^[\>:\|=]+\s*.*?$//msg;      # remove quoted text          $text =~ s/^[\>:\|=]+\s*.*?$//msg;      # remove quoted text
183          $text =~ s/[\n\r]+/\n/gs;               # compress cr/lf          $text =~ s/[\n\r]+/\n/gs;               # compress cr/lf
184          $text =~ s,^((?:.*?[\n\r]){5}).*$,$1<span style="color:#808080">--8&lt;--[cut]--8&lt;--</span>,s;          if ($text =~ s,^((?:.*?[\n\r]){5}).*$,$1,s) {
185                    $text =~ s/[\n\r]*$/ .../;
186            }
187          $text =~ s/[\n\r]+--\s*[\n\r]+.*$//s;          $text =~ s/[\n\r]+--\s*[\n\r]+.*$//s;
188    
189  #       my $context = Text::Context::EitherSide->new($text, context => 5);  #       my $context = Text::Context::EitherSide->new($text, context => 5);
# Line 139  sub body5_filter { Line 192  sub body5_filter {
192          return $text;          return $text;
193  }  }
194    
195    sub subject_search_filter {
196            my $s = shift;
197            # remove re: fdw: [list] preffixes from e-mail
198            while ( $s =~ s/^\s*\[(?:re|fwd|fw):\s+(.+)\]\s*$/$1/ig ||
199                    $s =~ s/^\s*(?:re|fwd|fw):\s+(.+?)\s*$/$1/ig ||
200                    $s =~ s/^\[\S+\]\s*//ig ||
201                    $s =~ s/^\[[^@]+@\w+\.\w+\s*:\s+(.+)\s*\]\s*$/$1/g ||
202                    $s =~ s/\(fwd\)\s*$//ig ||
203                    $s =~ s/\"//g
204            ) { };
205            return $s;
206    }

Legend:
Removed from v.12  
changed lines
  Added in v.21

  ViewVC Help
Powered by ViewVC 1.1.26