/[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 20 by dpavlin, Fri May 7 23:35:39 2004 UTC revision 27 by dpavlin, Sat May 8 20:34:26 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;  my $debug = 1;
19    
20    my $config_file = shift @ARGV || 'global.conf';
21    
22    if (! -f $config_file) {
23            print qq{Usage: $0 [/path/to/local.conf]
24    
25    If local.conf is not specified, global.conf in current directory will
26    be used.
27    };
28            exit 1;
29    }
30    
31  my $d = HTTP::Daemon->new( Reuse => 1, LocalPort => 6969 ) || die;  my $d = HTTP::Daemon->new( Reuse => 1, LocalPort => 6969 ) || die;
32  my $cgi = new CGI::Lite;  my $cgi = new CGI::Lite;
33  my $mws = MWS->new('global.conf');  my $mws = MWS->new($config_file);
34  my $tt = Template->new({  my $tt = Template->new({
35          INCLUDE_PATH => $mws->{config}->val('global', 'templates'),          INCLUDE_PATH => $mws->{config}->val('global', 'templates'),
36          FILTERS => {          FILTERS => {
37                  'body5' => \&body5_filter,                  'body5' => \&body5_filter,
                 'subject_search' => \&subject_search_filter,  
38          },          },
39          EVAL_PERL => 1,          EVAL_PERL => 1,
40  });  });
41    
42    my $static_html = $mws->{config}->val('global', 'static_html');
43    
44  print "Web server ready at: ", $d->url, "\n";  print "Web server ready at: ", $d->url, "\n";
45    
46    
# Line 73  while ( my $c = $d->accept ) { Line 86  while ( my $c = $d->accept ) {
86                  # XXX LOG                  # XXX LOG
87                  print $r->method," ",$url,"\n",Dumper($param),"\n" if ($debug);                  print $r->method," ",$url,"\n",Dumper($param),"\n" if ($debug);
88    
89                    # is this static page?
90                    if ($static_html && -f "$static_html/$url") {
91                            print "static file: $static_html/$url\n" if ($debug);
92                            $c->send_file_response("$static_html/$url");
93                            $c->close;
94                            next;
95                    }
96    
97                  # template file name (use ?format=html as default)                  # template file name (use ?format=html as default)
98                  my $tpl_file = 'master.';                  my $tpl_file = 'master.';
99                  $tpl_file .= $param->{'format'} || 'html';                  $tpl_file .= $param->{'format'} || 'html';
# Line 110  while ( my $c = $d->accept ) { Line 131  while ( my $c = $d->accept ) {
131                          yyyy    => $yyyy,                          yyyy    => $yyyy,
132                          mm      => $mm,                          mm      => $mm,
133                          dd      => $dd,                          dd      => $dd,
134                            date_limit => $date_limit,
135                  };                  };
136    
137                  if ($date_limit) {                  # is this access to root of web server?
138                          $param->{'search'} .= "and " if ($param->{'search'});                  if ($url eq "/" && !$param->{'search'}) {
139                          $param->{'search'} .= $date_limit;                          # if first access, go to current year
140                            $date_limit = $mws->fmtdate($yyyy);
141                            $param->{sort} = "date desc";
142                  }                  }
143    
144                  # show search results                  # ?show_id=XXXXxxxx___message_id___xxxxXXXX
145                  # ?search=foo:bar                  if ($param->{'show_id'}) {
                 if ($param->{'search'}) {  
146    
147                          print STDERR "search: ",$param->{'search'},"\n";                          $mws->reset_counters;
148                            my $row = $mws->fetch_result_by_id($param->{'show_id'});
149                            $tpl_var->{message} = $row;
150                    } elsif ($param->{'search'} || $date_limit) {
151    
152                          my $results = $mws->search($param->{'search'});                          # show search results
153                          my @res = $mws->fetch_all_results();                          # ?search=foo:bar
154    
155                          $tpl_var->{results} = \@res if (@res);                          my @search;
156                          $tpl_var->{total_hits} = $mws->{total_hits};                          push @search, $param->{'search'} if ($param->{'search'});
157    
158                            if ($date_limit) {
159                                    push @search, "and" if (@search);
160                                    push @search, "date:\"$date_limit\"";
161                            }
162    
163                  #                          if ($param->{sort_by}) {
164                  # ?show_id=XXXXxxxx___message_id___xxxxXXXX                                  push @search, "sort:".$param->{sort_by};
165                  } elsif ($param->{'show_id'}) {                          }
166    
167                            print STDERR "search: ",join(" ",@search),"\n";
168    
169                            my $results = $mws->search(@search);
170                            my @res = $mws->fetch_all_results();
171    
172                            $tpl_var->{results} = \@res if (@res);
173                            $tpl_var->{total_hits} = $mws->{total_hits} || 0;
174    
                         $mws->reset_counters;  
                         my $row = $mws->fetch_result_by_id($param->{'show_id'});  
                         $tpl_var->{message} = $row;  
175                  }                  }
176    
 print Dumper($mws->{counter});  
177    
178                  # push counters to template                  # push counters to template
179                  foreach my $f (qw(from to cc bcc)) {                  foreach my $f (qw(from to cc bcc)) {
# Line 190  sub body5_filter { Line 224  sub body5_filter {
224          return $text;          return $text;
225  }  }
226    
 sub subject_search_filter {  
         my $s = shift;  
         # remove re: fdw: [list] preffixes from e-mail  
         while ( $s =~ s/^\s*\[(?:re|fwd|fw):\s+(.+)\]\s*$/$1/ig ||  
                 $s =~ s/^\s*(?:re|fwd|fw):\s+(.+?)\s*$/$1/ig ||  
                 $s =~ s/^\[\S+\]\s*//ig ||  
                 $s =~ s/^\[[^@]+@\w+\.\w+\s*:\s+(.+)\s*\]\s*$/$1/g ||  
                 $s =~ s/\(fwd\)\s*$//ig ||  
                 $s =~ s/\"//g  
         ) { };  
         return $s;  
 }  

Legend:
Removed from v.20  
changed lines
  Added in v.27

  ViewVC Help
Powered by ViewVC 1.1.26