/[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 14 by dpavlin, Thu May 6 19:46:58 2004 UTC revision 25 by dpavlin, Sat May 8 16:06:58 2004 UTC
# Line 11  use IO::String; Line 11  use IO::String;
11  use CGI::Lite;  use CGI::Lite;
12  use Template;  use Template;
13  use MWS;  use MWS;
14    use URI::Escape;
15    
16  use Data::Dumper;  use Data::Dumper;
17    
18    my $debug = 1;
19    
20  my $d = HTTP::Daemon->new( Reuse => 1, LocalPort => 6969 ) || die;  my $d = HTTP::Daemon->new( Reuse => 1, LocalPort => 6969 ) || die;
21  my $cgi = new CGI::Lite;  my $cgi = new CGI::Lite;
22  my $mws = MWS->new('global.conf');  my $mws = MWS->new('global.conf');
# Line 21  my $tt = Template->new({ Line 24  my $tt = Template->new({
24          INCLUDE_PATH => $mws->{config}->val('global', 'templates'),          INCLUDE_PATH => $mws->{config}->val('global', 'templates'),
25          FILTERS => {          FILTERS => {
26                  'body5' => \&body5_filter,                  'body5' => \&body5_filter,
                 'subject_search' => \&subject_search_filter,  
27          },          },
28            EVAL_PERL => 1,
29  });  });
30    
31    my $static_html = $mws->{config}->val('global', 'static_html');
32    
33  print "Web server ready at: ", $d->url, "\n";  print "Web server ready at: ", $d->url, "\n";
34    
35    
# Line 68  while ( my $c = $d->accept ) { Line 73  while ( my $c = $d->accept ) {
73                  my $url = $r->url->path;                  my $url = $r->url->path;
74    
75                  # XXX LOG                  # XXX LOG
76                  print $r->method," ",$url,Dumper($param);                  print $r->method," ",$url,"\n",Dumper($param),"\n" if ($debug);
77    
78                    # is this static page?
79                    if ($static_html && -f "$static_html/$url") {
80                            print "static file: $static_html/$url\n" if ($debug);
81                            $c->send_file_response("$static_html/$url");
82                            $c->close;
83                            next;
84                    }
85    
86                  # template file name (use ?format=html as default)                  # template file name (use ?format=html as default)
87                  my $tpl_file = 'master.';                  my $tpl_file = 'master.';
88                  $tpl_file .= $param->{'format'} || 'html';                  $tpl_file .= $param->{'format'} || 'html';
89    
90                    # parse date from url
91                    my ($yyyy,$mm,$dd) = $mws->yyyymmdd;
92    
93                    my $yyyymm;
94    
95                    my $date_limit;
96    
97                    if ($url =~ m,^/(\d{4})[/-](\d+)[/-](\d+),) {
98                            ($yyyy, $mm, $dd) = $mws->fmtdate($1,$2,$3);
99                             $date_limit = "$yyyy-$mm-$dd";
100                    } elsif ($url =~ m,^/(\d{4})[/-](\d+),) {
101                            ($yyyy,$mm) = $mws->fmtdate($1,$2);
102                            $date_limit = "$yyyy-$mm";
103                    } elsif ($url =~ m,^/(\d{4}),) {
104                            $date_limit = $mws->fmtdate($1);
105                    }
106    
107                  #                  #
108                  # implement functionality and generate HTML                  # implement functionality and generate HTML
109                  #                  #
# Line 81  while ( my $c = $d->accept ) { Line 111  while ( my $c = $d->accept ) {
111    
112                  if ($param->{'search_val'} && $param->{'search_fld'} && !$param->{'search'}) {                  if ($param->{'search_val'} && $param->{'search_fld'} && !$param->{'search'}) {
113                          $param->{'search'} = $param->{'search_fld'}.":".$param->{'search_val'};                          $param->{'search'} = $param->{'search_fld'}.":".$param->{'search_val'};
114                    } elsif ($param->{'search'}) {
115                            ($param->{'search_fld'}, $param->{'search_val'}) = split(/:/,$param->{'search'},2);
116                  }                  }
117    
118                  my $tpl_var = {                  my $tpl_var = {
119                          param   => $param                          param   => $param,
120                            yyyy    => $yyyy,
121                            mm      => $mm,
122                            dd      => $dd,
123                            date_limit => $date_limit,
124                  };                  };
125    
126                  # show search results                  #
127                  # ?search=foo:bar                  # ?show_id=XXXXxxxx___message_id___xxxxXXXX
128                  if ($param->{'search'}) {                  if ($param->{'show_id'}) {
129    
130                            $mws->reset_counters;
131                            my $row = $mws->fetch_result_by_id($param->{'show_id'});
132                            $tpl_var->{message} = $row;
133                    } elsif ($param->{'search'} || $date_limit) {
134    
135                            # show search results
136                            # ?search=foo:bar
137    
138                          print STDERR "search: ",$param->{'search'},"\n";                          my @search = ( $param->{'search'} );
139    
140                          my $results = $mws->search($param->{'search'});                          if ($date_limit) {
141                                    push @search, "and" if (@search);
142                                    push @search, "date:\"$date_limit\"";
143                            }
144    
145                            if ($param->{sort_by}) {
146                                    push @search, "sort:".$param->{sort_by};
147                            }
148    
149                            print STDERR "search: ",join(" ",@search),"\n";
150    
151                            my $results = $mws->search(@search);
152                          my @res = $mws->fetch_all_results();                          my @res = $mws->fetch_all_results();
153    
154                          $tpl_var->{results} = \@res;                          $tpl_var->{results} = \@res if (@res);
155                            $tpl_var->{total_hits} = $mws->{total_hits} || 0;
156    
157                    }
158    
159                  #  
160                  # ?show_id=XXXXxxxx___message_id___xxxxXXXX                  # push counters to template
161                  } elsif ($param->{'show_id'}) {                  foreach my $f (qw(from to cc bcc)) {
162                                                    my $h = $mws->counter($f) || next;
163                          my $row = $mws->fetch_result_by_id($param->{'show_id'});                          my @a;
164                          $tpl_var->{message} = $row;                          foreach my $k (sort { $h->{$b}->{usage} <=> $h->{$a}->{usage} } keys %$h) {
165                                    push @a, $h->{$k};
166                            }
167                            $tpl_var->{counters}->{$f} = [ @a ] if (@a);
168                  }                  }
169    
170                    # push calendar in template
171                    $tpl_var->{calendar} = $mws->counter('calendar');
172    
173                  $tt->process($tpl_file, $tpl_var, \$html) || die $tt->error();                  $tt->process($tpl_file, $tpl_var, \$html) || die $tt->error();
174    
175                  #                  #
# Line 143  sub body5_filter { Line 206  sub body5_filter {
206          return $text;          return $text;
207  }  }
208    
 sub subject_search_filter {  
         my $s = shift;  
         # remove re: fdw: [list] preffixes from e-mail  
         while ( $s =~ s/^\s*\[(?:re|fwd):\s+(.+)\]\s*$/$1/ig ||  
                 $s =~ s/^\s*(?:re|fwd):\s+(.+?)\s*$/$1/ig ||  
                 $s =~ s/^\[\w+\]\s*//ig  
         ) { };  
         return $s;  
 }  

Legend:
Removed from v.14  
changed lines
  Added in v.25

  ViewVC Help
Powered by ViewVC 1.1.26