/[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 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 $d = HTTP::Daemon->new( Reuse => 1, LocalPort => 6969 ) || die;  my $debug = 1;
 print "Please contact me at: <URL:", $d->url, ">\n";  
19    
20    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');
23  my $tt = Template->new({  my $tt = Template->new({
# Line 24  my $tt = Template->new({ Line 25  my $tt = Template->new({
25          FILTERS => {          FILTERS => {
26                  'body5' => \&body5_filter,                  'body5' => \&body5_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";
34    
35    
36  while ( my $c = $d->accept ) {  while ( my $c = $d->accept ) {
37          while ( my $r = $c->get_request ) {          while ( my $r = $c->get_request ) {
# Line 67  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 80  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                  # show search results                  my $tpl_var = {
119                  # ?search=foo:bar                          param   => $param,
120                  if ($param->{'search'}) {                          yyyy    => $yyyy,
121                            mm      => $mm,
122                            dd      => $dd,
123                            date_limit => $date_limit,
124                    };
125    
126                    #
127                    # ?show_id=XXXXxxxx___message_id___xxxxXXXX
128                    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                            my @search = ( $param->{'search'} );
139    
140                            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: ",$param->{'search'},"\n";                          print STDERR "search: ",join(" ",@search),"\n";
150    
151                          my $results = $mws->search($param->{'search'});                          my $results = $mws->search(@search);
152                          my @res = $mws->fetch_all_results();                          my @res = $mws->fetch_all_results();
153    
154                          $tt->process($tpl_file, {                          $tpl_var->{results} = \@res if (@res);
155                                  query   => $param->{'search'},                          $tpl_var->{total_hits} = $mws->{total_hits} || 0;
                                 results => \@res,  
                                 param   => $param,  
                         }, \$html) || die $tt->error();  
156    
                 #  
                 # ?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();  
157                  }                  }
158    
159    
160                    # push counters to template
161                    foreach my $f (qw(from to cc bcc)) {
162                            my $h = $mws->counter($f) || next;
163                            my @a;
164                            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();
174    
175                  #                  #
176                  # send HTMLto client                  # send HTMLto client
177                  #                  #
178    
179                  my $res = HTTP::Response->new(RC_OK);                  my $res = HTTP::Response->new(RC_OK);
180                  $res->header( 'Content-type' => 'text/html; charset=iso-8859-2' );                  $res->header( 'Content-type' => 'text/html; charset=ISO-8859-2' );
181                  $res->content($html);                  $res->content($html);
182                  $c->send_response($res);                  $c->send_response($res);
183    
# Line 130  sub body5_filter { Line 195  sub body5_filter {
195          $text =~ s/^\s+//gs;          $text =~ s/^\s+//gs;
196          $text =~ s/^[\>:\|=]+\s*.*?$//msg;      # remove quoted text          $text =~ s/^[\>:\|=]+\s*.*?$//msg;      # remove quoted text
197          $text =~ s/[\n\r]+/\n/gs;               # compress cr/lf          $text =~ s/[\n\r]+/\n/gs;               # compress cr/lf
198          $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) {
199                    $text =~ s/[\n\r]*$/ .../;
200            }
201          $text =~ s/[\n\r]+--\s*[\n\r]+.*$//s;          $text =~ s/[\n\r]+--\s*[\n\r]+.*$//s;
202    
203  #       my $context = Text::Context::EitherSide->new($text, context => 5);  #       my $context = Text::Context::EitherSide->new($text, context => 5);

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

  ViewVC Help
Powered by ViewVC 1.1.26