Develop and Download Open Source Software

Browse CVS Repository

Contents of /h14m/hns-bbs/board.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download)
Sun Feb 3 04:34:20 2002 UTC (22 years, 2 months ago) by bonaim
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +14 -7 lines
some fixes

1 #!/usr/bin/perl
2 ################################################################
3 # board.cgi
4 #
5 # HyperNikkiSystem
6 # 2002/1/27 Yoichi Imai <yoichi@silver-forest.com>
7
8 # Copyright (C) 2002 Yoichi Imai <yoichi@silver-forest.com>
9
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License
12 # as published by the Free Software Foundation; either version 2
13 # of the License, or (at your option) any later version.
14
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24 # $Id: board.cgi,v 1.1 2002/02/03 03:28:54 bonaim Exp $
25 ################################################################
26
27 use strict;
28 use lib qw(lib);
29
30 use CGI::QueryString;
31 use CGI::Cookie;
32 use CGI::Tools;
33 use DateTime::Format;
34 use CodeConv;
35 use Board;
36 use Board::System;
37
38 require './config.ph';
39
40 BEGIN {
41 $| = 1;
42 $SIG{'__DIE__'} = \&die_handler;
43 }
44 sub die_handler {
45 my $msg = shift;
46 if ($msg !~ /unimplemented/ &&
47 $msg !~ /eval/){
48 print "Content-Type: text/html; charset=EUC-JP\r\n\r\n";
49 print "<br>";
50 print qq(<font color="red">Error Occured: $msg</font><br>);
51 }
52 }
53 ################################################################
54 # index action (default)
55
56 # list_num must be $#list+1 or @list.
57 sub print_page_control($$)
58 {
59 my ($cur_page, $list_num) = @_;
60
61 die 'ThreadsPerPage is zero' if ($Board::ThreadsPerPage == 0);
62
63 $cur_page = 0 if ($list_num / $Board::ThreadsPerPage < $cur_page);
64
65 print '<div align="center">', "\n";
66 print '[ ';
67 for (my $i = 0; $i < $list_num / $Board::ThreadsPerPage; $i++) {
68 print ' / ' unless $i == 0;
69 if ($i == $cur_page) {
70 print $i + 1;
71 } else {
72 print '<a href="board.cgi?page=', $i, '">', $i + 1, '</a>', "\n";
73 }
74 }
75 print ' ]</div>', "\n";
76 }
77 sub print_article_tree($$)
78 {
79 my ($tree, $msgid) = @_;
80
81 print ' <ul>', "\n";
82 foreach my $article (@{$tree->{$msgid}}) {
83 print ' <li>';
84 print $article->GetSubject(0);
85 print_article_tree($tree, $article->msgid);
86 print ' </li>', "\n";
87 }
88 print ' </ul>', "\n";
89 }
90
91 # usage: print_article_root($refid_hash);
92 sub print_article_root($)
93 {
94 my $tree = shift;
95 my ($cur_page, $start_num, $list_ref);
96
97 $cur_page = param('page');
98 die 'Invalid page number' if ($cur_page =~ /[^\d]/);
99
100 $start_num = $cur_page * $Board::ThreadsPerPage;
101
102 $list_ref = $tree->{'root'};
103 return unless $list_ref;
104
105 my @list = reverse(@{$list_ref});
106
107 print '<dl>', "\n";
108 print_page_control($cur_page, $#list+1);
109
110 if ($start_num > $#list) {
111 @list = @list[0..($Board::ThreadsPerPage-1)];
112 } else {
113 @list = @list[$start_num..($start_num+$Board::ThreadsPerPage-1)];
114 }
115
116 foreach my $article (@list) {
117 next unless $article;
118 print '<dt>';
119 print $article->GetSubject(1);
120 print '</dt>', "\n";
121
122 print '<dd>', "\n";
123 print_article_tree($tree, $article->msgid);
124 print '</dd>', "\n";
125 }
126
127 print '</dl>', "\n";
128 }
129
130 sub action_index
131 {
132 my $board = shift;
133
134 print_html_header();
135 print_article_root($board->refid_hash);
136 print_html_footer();
137 }
138
139 ################################################################
140 # html output
141 sub print_html_header
142 {
143 print "Content-Type: text/html\r\n\r\n";
144 print <<"CENTER_OF_HEADER";
145 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
146 "http://www.w3.org/TR/REC-html40/loose.dtd">
147 <html lang="ja">
148 <head>
149 <meta http-equiv="Content-Type" CONTENT="text/html; charset=euc-jp">
150 <meta http-equiv="Content-Style-Type" content="text/css">
151 CENTER_OF_HEADER
152
153 print qq(<link rel="STYLESHEET" type="text/css" href="${Board::CSSFile}">) if (defined($Board::CSSFile));
154
155 print <<"END_OF_HEADER";
156 <title>${Board::Title}</title>
157 <style type="text/css">
158 <!--
159 p#copyright { text-align: right }
160 span.new { color: #ff0000; font-size: smaller }
161 span.date { font-size: smaller }
162 -->
163 </style>
164 </head>
165
166 <body>
167 <h2>${Board::Title}</h2>
168 <div align="center">
169 <a href="${Board::HnsPath}">������</a> /
170 <a href="board.cgi">����������</a> /
171 <a href="board.cgi?act=write">��������</a> /
172 <a href="board.cgi?act=list">��������</a>
173 </div>
174 END_OF_HEADER
175
176 }
177 sub print_html_footer
178 {
179 print <<"END_OF_FOOTER";
180
181 <p id="copyright">
182 HNS Board-${Board::Version}
183 </p>
184
185 </body>
186 </html>
187 END_OF_FOOTER
188 }
189 ################################################################
190 # common subroutine
191 # $depth��style����������������class������������������������������������
192 # ������CSS��������������������������������������������blockquote����������������
193 sub thread_print
194 {
195 my ($depth, $article_list, $msgid_hash, $refid_hash) = @_;;
196
197 print '<blockquote>', "\n" if $depth != 0;
198 foreach my $article (@$article_list) {
199 $article->Print();
200 thread_print($depth+1, $refid_hash->{$article->msgid}, $msgid_hash, $refid_hash);
201 }
202 print '</blockquote>', "\n" if $depth != 0;
203 }
204 sub print_form
205 {
206 my ($form_action, $hidden_values, $subject, $name, $email, $site, $key, $cookie_checked, $body, $submit_value) = @_;
207
208 print '<form method="POST" action="board.cgi">', "\n";
209 if ($hidden_values) {
210 foreach my $key (keys %$hidden_values) {
211 print '<input type="hidden" name="', $key, '" value="', $hidden_values->{$key}, '">', "\n";
212 }
213 }
214 print 'Subject: <input type="text" name="subject" value="', $subject, '"><br>', "\n";
215 print '����: <input type="text" name="name" value="', $name, '"><br>', "\n";
216 print 'E-Mail: <input type="text" name="email" value="', $email, '"><br>', "\n";
217 print 'Web������: <input type="text" name="site" value="', $site, '"><br>', "\n";
218 print '��������: <input type="text" name="key" value="', $key, '"><br>', "\n";
219 print '<input type="checkbox" name="cookie" value="on" ';
220 print 'checked' if ($cookie_checked);
221 print '>Cookie����������������������<br>', "\n";
222 print '<textarea name="body" rows=5 cols=70>', "\n";
223 print $body;
224 print '</textarea>', "\n";
225 print '<br><input type="submit" value="', $submit_value, '"></form>', "\n";
226 }
227 sub html_convert
228 {
229 my ($str, $body_mode) = @_;
230
231 $str =~ tr/\t//d;
232 $str = Escape($str);
233 if ($body_mode) {
234 $str =~ s/\x0D\x0A/<br>/g;
235 $str =~ s/\x0D/<br>/g;
236 $str =~ s/\x0A/<br>/g;
237 $str =~ s/ /&nbsp;/;
238 } else {
239 $str =~ tr/\x0D\x0A/ /;
240 }
241 return $str;
242 }
243 ################################################################
244 # diary action
245 sub action_diary
246 {
247 my $board = shift;
248
249 my $fit_article;
250 my $ref_diary = param('diary');
251
252 die "unset diary parameter to find" unless $ref_diary;
253
254 foreach my $article (@{$board->article_list}) {
255 if ($article->IsRoot() && $article->ref_diary eq $ref_diary) {
256 $fit_article = $article;
257 }
258 }
259 die "Can't find the article for the article of diary" unless $fit_article;
260 print_html_header();
261 thread_print(0, [$fit_article], $board->msgid_hash, $board->refid_hash);
262 print_html_footer();
263
264 }
265 ################################################################
266 # list action
267 sub action_list
268 {
269 my $board = shift;
270
271 print_html_header();
272 my @article_list = reverse(@{$board->article_list});
273 for (my $i = 0; $i < $Board::RecentView; $i++) {
274 my $article = $article_list[$i];
275 next unless $article;
276 next if $article->IsRoot() && $article->ref_diary ne '';
277
278 $article->Print($board->msgid_hash, $board->refid_hash);
279 print '<hr>', "\n";
280 }
281 print_html_footer();
282 }
283 ################################################################
284 # read action
285 sub action_read
286 {
287 my $board = shift;
288
289 my ($fit_article);
290
291 my $msgid = param('msgid');
292 die 'msgid is unset' unless ($msgid);
293
294 $fit_article = $board->msgid_hash->{$msgid};
295 die 'Msgid is illegal' unless $fit_article;
296
297 print_html_header();
298 if (param('thr') eq 'on') {
299 thread_print(0, [$fit_article], $board->msgid_hash, $board->refid_hash);
300 } else {
301 $fit_article->Print($board->msgid_hash, $board->refid_hash);
302 }
303 print_html_footer();
304 }
305 ################################################################
306 # write action
307 sub action_write
308 {
309 my $board = shift;
310
311 my ($title, $ref_article, $diary_title, $refid);
312 my ($name, $email, $site, $key);
313 my $hidden_values = {};
314
315 $hidden_values->{'act'} = 'post';
316
317 $refid = param('refid');
318 if ($refid) {
319 $ref_article = $board->msgid_hash->{$refid};
320 die 'Original message not found' unless $ref_article;
321
322 if ($ref_article->IsRoot() && $ref_article->ref_diary ne '') {
323 undef($ref_article);
324 } else {
325 $title = $ref_article->title;
326 $title =~ s/^Re:(&nbsp;| )//g;
327 $title = "Re: " . $title;
328
329 $hidden_values->{'refid'} = $ref_article->msgid;
330 $hidden_values->{'diary'} = $ref_article->ref_diary;
331 }
332 }
333 if (param('diary')) {
334 $diary_title = Board::System::get_diary_title(param('diary'));
335 die 'Diary title getting error' unless ($diary_title);
336
337 $title = "Re: " . $diary_title;
338 $hidden_values->{'diary'} = param('diary');
339 }
340 my $cookie = GetCookie('HnsBoardProfile');
341 if ($cookie) {
342 $cookie = CGI::Tools::URIUnEscape($cookie);
343 ($name, $email, $site, $key) = split(/\|/, $cookie);
344 }
345 $site = "http://" unless ($site);
346
347 print_html_header();
348 if ($diary_title) {
349 print '<h3>[[' . $title, ']]������������</h3>', "\n";
350 } elsif ($ref_article) {
351 $ref_article->Print();
352 }
353
354 if ($cookie) {
355 print_form("POST", $hidden_values, $title, $name,
356 $email, $site, $key, 1, "", "��������");
357 } else {
358 print_form("POST", $hidden_values, $title, $name,
359 $email, $site, $key, 0, "", "��������");
360 }
361 print_html_footer();
362 }
363 ################################################################
364 # post action
365 sub action_post
366 {
367 my $board = shift;
368
369 my ($http_host, $refid, $diary, $ruri_code);
370
371 $http_host = $ENV{'REMOTE_ADDR'};
372
373 my ($name, $email, $site, $body, $subject, $delete_key, $diary, $refid) = (param('name'), param('email'), param('site'), param('body'), param('subject'), param('key'), param('diary'), param('refid'));
374
375 die 'name is too long' if length($name) > $Board::FieldMaxLen;
376 die 'email is too long' if length($email) > $Board::FieldMaxLen;
377 die 'subject is too long' if length($subject) > $Board::FieldMaxLen;
378 die 'delete key is too long' if length($delete_key) > $Board::FieldMaxLen;
379 die 'url is too long' if length($site) > $Board::URLMaxLen;
380 die 'body is too long' if length($body) > $Board::BodyMaxLen;
381
382 die 'input subject' unless $subject;
383
384 die 'invalid delete key' if (!$delete_key || !($delete_key =~ /^[-a-zA-Z0-9_]+$/) || $Board::UnDeletableKey eq $delete_key);
385 die 'invalid diary' if ($diary && (!($diary =~ /^[0-9]+$/) || length($diary) > 30));
386 die 'invalid refid' if ($refid && (!($refid =~ /^[0-9]+$/) || length($refid) > 10));
387
388 foreach ($name, $email, $site) {
389 die 'included invalid characters' if /\|/;
390 }
391
392 $name = html_convert($name, 0);
393 $email = html_convert($email, 0);
394 $site = html_convert($site, 0);
395 $subject = html_convert($subject, 0);
396
397 $body = html_convert($body, 1);
398
399 # $diary������ && $refid������
400 ## ����root���������� -> ����������
401 ## ����root������������ -> ����root����������
402 ## $refid = ����root.refid
403 # ������������refid������ -> $refid = 'root'
404 ## ����
405
406 my $fake_root;
407 if ($diary) {
408 unless ($refid) {
409 $fake_root = $board->SearchFakeRoot($diary);
410 unless($fake_root) {
411 my $diary_title = Board::System::get_diary_title($diary);
412 die 'Diary title getting error' unless $diary_title;
413 $fake_root = $board->AddNewMsg($Board::UnDeletableKey,
414 'root',
415 $diary,
416 "",
417 "[[$diary_title]]");
418 }
419 $refid = $fake_root->msgid;
420 }
421 }
422
423 $refid = 'root' unless ($refid);
424
425 $ruri_code = GetCookie('HnsClientID');
426 if($ruri_code && ($ruri_code =~ /\W/ || length($ruri_code) != 17)) {
427 die 'invalid RURI code', " '$ruri_code' ", length($ruri_code);
428 }
429
430 $board->AddNewMsg($delete_key,
431 $refid,
432 $diary,
433 "",
434 $subject, $name, $email, $site,
435 $http_host, $body);
436
437 $board->Save();
438
439 if(param('cookie') eq 'on') {
440 my $cookie = join("|", $name, $email, $site, $delete_key);
441 my $expires = $HNS::System::CookieExpires;
442 $cookie = CGI::Tools::URIEscape($cookie);
443 print AsCookieHeader('HnsBoardProfile', $cookie, $expires);
444 }
445
446 print_html_header();
447 print '<h3>��������������</h3>';
448 print_html_footer();
449 }
450 ################################################################
451 # delete action
452 sub action_delete
453 {
454 my $board = shift;
455
456 my $msgid = param('msgid');
457 die 'invalid message id' unless $msgid;
458
459 my $article = $board->msgid_hash->{$msgid};
460 die 'the message to delete is not found.' unless $article;
461
462 if (param('really') eq 'on') {
463 if ($article->delete_key eq param('key')) {
464 $article->Delete;
465 $board->Save();
466 print_html_header();
467 print "<h2>��������������������</h2>";
468 print_html_footer();
469 } else {
470 print_html_header();
471 print "<div>��������������������������������</div>";
472 print_html_footer();
473 }
474 return;
475 }
476
477 print_html_header();
478 $article->Print();
479 print <<"EOF";
480 <form method="POST" action="board.cgi">
481 <input type="hidden" name="act" value="delete">
482 <input type="hidden" name="msgid" value="${msgid}">
483 <input type="hidden" name="really" value="on">
484 ��������: <input type="text" name="key"><br>
485 <input type="submit" value="����">
486 </form>
487 <form method="POST" action="board.cgi">
488 <input type="hidden" name="act" value="delroot">
489 <input type="hidden" name="msgid" value="${msgid}">
490 <input type="submit" value="��������������">
491 </form>
492 EOF
493 print_html_footer();
494 }
495
496 ################################################################
497 # delroot
498 sub action_delroot
499 {
500 my $board = shift;
501
502 my $msgid = param('msgid');
503 die 'invalid message id' unless $msgid;
504
505 my $article = $board->msgid_hash->{$msgid};
506 die 'the message to delete is not found.' unless $article;
507
508 use HNS::Admini;
509
510 my $admini = new HNS::Admini;
511 $admini->PrintHeader('board.cgi��������������', '������������������������������');
512 $admini->CheckAuthorized;
513 $article->Delete();
514 $board->Save();
515 print "<h3>��������������������</h3>";
516 $admini->PrintFooter("HNS Board-${Board::Version}, ", "board.cgi", 'back');
517 }
518 ################################################################
519 # main method
520
521 unless ($Board::UseBoard) {
522 print "Content-Type: text/plain\r\n\r\n" ;
523 print "board features is disabled.";
524 exit(0);
525 }
526
527 my $board = new Board::System;
528 $board->Load();
529 $board->CreateMsgidHash();
530 $board->CreateRefidHash();
531
532 my $echo_lm = DateTime::Format::strftime("%a, %d %b %Y %H:%M:%S %Z",
533 (stat($Board::BoardData))[9]);
534 print "Last-Modified: $echo_lm\r\n";
535
536 my $act = param('act');
537 if($act) {
538 if($act eq 'read') {
539 action_read($board);
540 } elsif ($act eq 'list') {
541 action_list($board);
542 } elsif ($act eq 'diary') {
543 action_diary($board);
544 } elsif ($act eq 'write') {
545 action_write($board);
546 } elsif ($act eq 'delete') {
547 action_delete($board);
548 } elsif ($act eq 'delroot') {
549 action_delroot($board);
550 } elsif ($act eq 'post') {
551 action_post($board);
552 } else {
553 die 'invalid act';
554 }
555 } else {
556 action_index($board);
557 }
558
559

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26