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 => { |
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 |
|
|
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'; |
134 |
date_limit => $date_limit, |
date_limit => $date_limit, |
135 |
}; |
}; |
136 |
|
|
137 |
# |
# is this access to root of web server? |
138 |
|
if ($url eq "/" && !$param->{'search'}) { |
139 |
|
# if first access, go to current year |
140 |
|
$date_limit = $mws->fmtdate($yyyy); |
141 |
|
$param->{sort} = "date desc"; |
142 |
|
} |
143 |
|
|
144 |
# ?show_id=XXXXxxxx___message_id___xxxxXXXX |
# ?show_id=XXXXxxxx___message_id___xxxxXXXX |
145 |
if ($param->{'show_id'}) { |
if ($param->{'show_id'}) { |
146 |
|
|
152 |
# show search results |
# show search results |
153 |
# ?search=foo:bar |
# ?search=foo:bar |
154 |
|
|
155 |
my @search = ( $param->{'search'} ); |
my @search; |
156 |
|
push @search, $param->{'search'} if ($param->{'search'}); |
157 |
|
|
158 |
if ($date_limit) { |
if ($date_limit) { |
159 |
push @search, "and" if (@search); |
push @search, "and" if (@search); |
170 |
my @res = $mws->fetch_all_results(); |
my @res = $mws->fetch_all_results(); |
171 |
|
|
172 |
$tpl_var->{results} = \@res if (@res); |
$tpl_var->{results} = \@res if (@res); |
173 |
$tpl_var->{total_hits} = $mws->{total_hits}; |
$tpl_var->{total_hits} = $mws->{total_hits} || 0; |
174 |
|
|
175 |
} |
} |
176 |
|
|