OSDN Git Service

a0a6db13844f06dd8fedf0c02432317dd719d5ee
[fswiki/sandbox.git] / kgsoft / plugin / bbsx.pm
1 ##########################################################################################
2 #
3 # ¥¹¥Ñ¥à¥Õ¥£¥ë¥¿¡¼¥×¥é¥°¥¤¥ó¡Ê³Ø½¬µ¡Ç½Ìµ¤·ÈÇ¡Ë
4 #¡Êbbsx¥×¥é¥°¥¤¥ó¤Î¥ª¡¼¥Ð¡¼¥é¥¤¥É¡Ë
5 #
6 ##########################################################################################
7 use strict;
8
9 use plugin::bbsx::BBSXHandler;
10
11 # plugin::bbsx::BBSXHandler¤Îdo_action¥á¥½¥Ã¥É¤ÎÃÖ¤­´¹¤¨
12 package plugin::bbsx::BBSXHandler;
13
14 sub do_action {\r
15         my $self = shift;\r
16         my $wiki = shift;\r
17         my $cgi  = $wiki->get_CGI;\r
18 \r
19         my $bbsname = $cgi->param("bbsname");\r
20         my $name    = $cgi->param("name");\r
21         my $subject = $cgi->param("subject");\r
22         my $message = $cgi->param("message");\r
23         my $password = $cgi->param("password");\r
24         my $page    = $cgi->param("page");\r
25         my $option  = $cgi->param("option");\r
26         my $filename = $cgi->param("file");\r
27         my $uploadable = $cgi->param("uploadable");\r
28 \r
29         if($name    eq ""){\r
30                 $name    = "̵̾¤·¤µ¤ó";\r
31         } else {\r
32                 # post_name¤È¤¤¤¦¥­¡¼¤Ç¥¯¥Ã¥­¡¼¤ò¥»¥Ã¥È¤¹¤ë\r
33                 my $cookie = $cgi->cookie(-name=>'post_name',-value=>$name,-expires=>'+1M');\r
34                 print "Set-Cookie: ",$cookie->as_string,"\n";\r
35         }\r
36 \r
37         if($subject eq ""){\r
38                 $subject = "̵Âê";\r
39         }\r
40 \r
41         if($bbsname eq ""){\r
42                 return $wiki->error("¥Ñ¥é¥á¡¼¥¿¤¬ÉÔÀµ¤Ç¤¹¡£");\r
43         }\r
44 \r
45         if($uploadable eq 'yes'){\r
46                 if($message eq "" and $filename eq ""){\r
47                 return $wiki->error("ËÜʸ¤«ÅºÉÕ¥Õ¥¡¥¤¥ë¤ò»ØÄꤷ¤Æ¤¯¤À¤µ¤¤¡£");\r
48                 }\r
49         } else {\r
50                 if($message eq ""){\r
51                 return $wiki->error("ËÜʸ¤òÆþÎϤ·¤Æ¤¯¤À¤µ¤¤¡£");\r
52                 }\r
53         }\r
54 \r
55         if($password eq ""){\r
56                 return $wiki->error("ºï½ü¥­¡¼¤òÆþÎϤ·¤Æ¤¯¤À¤µ¤¤¡£");\r
57         }\r
58 \r
59         my $pagename = $self->get_page_name($wiki,$bbsname);\r
60 \r
61         my $refpart='';\r
62 \r
63         if($filename ne ""){\r
64                 $filename =~ s/\\/\//g;\r
65                 $filename = substr($filename,rindex($filename,"/")+1);\r
66                 &Jcode::convert(\$filename,'euc');\r
67 \r
68                 my $hundle   = $cgi->upload("file");\r
69                 my $filecont;\r
70                 while(<$hundle>){ $filecont = $filecont.$_; }\r
71                 my $uploadfileNP = &Util::url_encode($pagename).".".&Util::url_encode($filename);\r
72                 my $uploadfile = $wiki->config('attach_dir')."/".$uploadfileNP;\r
73                 open(DATA,">$uploadfile") or die $!;\r
74                 binmode(DATA);\r
75                 print DATA $filecont;\r
76                 close(DATA);\r
77                 # ¥í¥°¤Îµ­Ï¿\r
78                 &plugin::attach::AttachHandler::write_log($wiki,"UPLOAD",$pagename,$filename);\r
79 \r
80                 # ÅºÉÕ¥Õ¥¡¥¤¥ë¤Îɽ¼¨·Á¼°È½Äê\r
81 \r
82                 my ($is_image,$infostring,$width,$height) = $self->getfileinfo($wiki,$uploadfile);\r
83                 if($is_image){\r
84                         $refpart = "{{bbsxfile $filename,show=1,page=$pagename,width=$width,height=$height,border=0}}\n";\r
85                 } else {\r
86                         my ($size) = (stat($uploadfile))[7];\r
87                         $refpart = "{{bbsxfile $filename,show=0,page=$pagename,size=$size}}\n";\r
88                 }\r
89                 if($plugin::bbsx::BBSXHandler::WRITEINFO){\r
90                         $refpart .= "$infostring\n";\r
91                 }\r
92 \r
93         }\r
94 \r
95         my $addr = $ENV{'REMOTE_ADDR'};\r
96         my $content = "!![[$subject|$pagename]] - $name (".&Util::format_date(time()).")\n";\r
97 \r
98         if($refpart ne ""){\r
99                 $content .= "$refpart";\r
100         }\r
101         if($message ne ""){\r
102                 $content .= "\n$message\n";\r
103         }\r
104
105 #--------------------------------------------------------------------------------------------------
106   if($message){
107     unless(&plugin::_ex_spam_filter_light::Install::judgment_text($message)){
108       my $time = Util::format_date(time());
109       my $file = $wiki->config('log_dir')."/spam_bbsx.txt";
110       if(open(SPAM_LOG, ">>$file")){
111         print SPAM_LOG "-" x 70 . "\n";
112         print SPAM_LOG "$bbsname:$subject - $name ($time)\n";
113         print SPAM_LOG "-" x 70 . "\n";
114         print SPAM_LOG "$message\n";
115         close(SPAM_LOG);
116       }
117       my $error_message = $wiki->error("Åê¹Æ¤µ¤ì¤¿Ê¸¾Ï¤Ï¥¹¥Ñ¥à¥á¥Ã¥»¡¼¥¸¤ÈȽÄꤵ¤ì¤Þ¤·¤¿¡£\n");
118       $subject = Util::escapeHTML($subject);
119       $message = Util::escapeHTML($message);
120       $message =~ s/\n/<br>/g;
121       $error_message .= "<p>\n";
122       $error_message .= "<div>Åê¹Æ¤µ¤ì¤¿Ê¸¾Ï¡§</div>\n";
123       $error_message .= "<div>¡ã·ï̾¡ä</div>\n";
124       $error_message .= "<div>$subject</div>\n";
125       $error_message .= "<div>¡ãËÜʸ¡ä</div>\n";
126       $error_message .= "<div>$message</div>\n";
127       $error_message .= "</p>\n";
128       return $error_message;
129     }
130   }
131 #--------------------------------------------------------------------------------------------------
132 \r
133         $content .= "//IP=$addr\n";\r
134         # ¥Ñ¥¹¥ï¡¼¥Éµ­Ï¿\r
135         $content .= "{{bbsxpassword $pagename," . crypt($password, 'aa') . "}}\n";\r
136 \r
137         # no_comment¥ª¥×¥·¥ç¥ó\r
138         if($option eq "no_comment"){\r
139 \r
140         # reverse_comment¥ª¥×¥·¥ç¥ó\r
141         } elsif($option eq "reverse_comment"){\r
142                 $content .= "{{bbsxcomment reverse}}\n";\r
143         # ¥Ç¥Õ¥©¥ë¥È\r
144         } else {\r
145                 $content .= "{{bbsxcomment}}\n";\r
146         }\r
147         $wiki->save_page($pagename,$content);\r
148 \r
149         # ¸µ¤Î¥Ú¡¼¥¸¤Ë¥ê¥À¥¤¥ì¥¯¥È\r
150         $wiki->redirect($bbsname);\r
151 }\r
152
153 use plugin::bbsx::BBSXCommentHandler;
154
155 # plugin::bbsx::BBSXCommentHandler¤Îdo_action¥á¥½¥Ã¥É¤ÎÃÖ¤­´¹¤¨
156 package plugin::bbsx::BBSXCommentHandler;
157
158 sub do_action {\r
159         my $self = shift;\r
160         my $wiki = shift;\r
161         my $cgi  = $wiki->get_CGI;\r
162 \r
163         my $name    = $cgi->param("name");\r
164         my $message = $cgi->param("message");\r
165         my $count   = $cgi->param("count");\r
166         my $page    = $cgi->param("page");\r
167         my $option  = $cgi->param("option");\r
168 \r
169         if($name eq ""){\r
170                 $name = "̵̾¤·¤µ¤ó";\r
171         } else {\r
172                 # post_name¤È¤¤¤¦¥­¡¼¤Ç¥¯¥Ã¥­¡¼¤ò¥»¥Ã¥È¤¹¤ë\r
173                 my $cookie = $cgi->cookie(-name=>'post_name',-value=>$name,-expires=>'+1M');\r
174                 print "Set-Cookie: ",$cookie->as_string,"\n";\r
175         }\r
176
177 #--------------------------------------------------------------------------------------------------
178   if($message){
179     unless(&plugin::_ex_spam_filter_light::Install::judgment_text($message)){
180       my $time = Util::format_date(time());
181       my $file = $wiki->config('log_dir')."/spam_bbsx_comment.txt";
182       if(open(SPAM_LOG, ">>$file")){
183         print SPAM_LOG "$page:$message - $name($time)\n";
184         close(SPAM_LOG);
185       }
186       my $error_message = $wiki->error("Åê¹Æ¤µ¤ì¤¿Ê¸¾Ï¤Ï¥¹¥Ñ¥à¥á¥Ã¥»¡¼¥¸¤ÈȽÄꤵ¤ì¤Þ¤·¤¿¡£\n");
187       $error_message .= "<p>\n";
188       $error_message .= "<div>Åê¹Æ¤µ¤ì¤¿Ê¸¾Ï¡§</div>\n";
189       $error_message .= "<div>" . Util::escapeHTML("$message") . "</div>\n";
190       $error_message .= "</p>\n";
191       return $error_message;
192     }
193   }
194 #--------------------------------------------------------------------------------------------------
195
196         if($page ne "" && $message ne "" && $count ne ""){\r
197 \r
198                 my @lines = split(/\n/,$wiki->get_page($page));\r
199                 my $flag       = 0;\r
200                 my $form_count = 1;\r
201                 my $content    = "";\r
202 \r
203                 my $addr = $ENV{'REMOTE_ADDR'};\r
204 \r
205                 # ¿·Ãå½ç¤Î¾ì¹ç\r
206                 if($option eq "reverse"){\r
207                         foreach(@lines){\r
208                                 if(/^{{bbsxpassword\s*.*}}$/){\r
209                                         # ¥Ñ¥¹¥ï¡¼¥É¹Ô¤òºï½ü\r
210                                         next;\r
211                                 }\r
212                                 $content = $content.$_."\n";\r
213                                 if(/^{{bbsxcomment\s*.*}}$/ && $flag==0){\r
214                                         if($form_count==$count){\r
215                                                 $content = $content."*$message - $name (".Util::format_date(time()).")\n";\r
216                                                 $flag = 1;\r
217                                                 $content = $content."//IP=$addr\n";\r
218                                         } else {\r
219                                                 $form_count++;\r
220                                         }\r
221                                 }\r
222 \r
223                         }\r
224                 # Åê¹Æ½ç¤Î¾ì¹ç\r
225                 } else {\r
226                         foreach(@lines){\r
227                                 if(/^{{bbsxpassword\s*.*}}$/){\r
228                                         # ¥Ñ¥¹¥ï¡¼¥É¹Ô¤òºï½ü\r
229                                         next;\r
230                                 }\r
231                                 if(/^{{bbsxcomment\s*.*}}$/ && $flag==0){\r
232                                         if($form_count==$count){\r
233                                                 $content = $content."*$message - $name (".Util::format_date(time()).")\n";\r
234                                                 $flag = 1;\r
235                                                 $content = $content."//IP=$addr\n";\r
236                                         } else {\r
237                                                 $form_count++;\r
238                                         }\r
239                                 }\r
240                                 $content = $content.$_."\n";\r
241                         }\r
242                 }\r
243                 if($flag==1){\r
244                         $wiki->save_page($page,$content);\r
245                 }\r
246         }\r
247 \r
248         my $bbsname = &plugin::bbsx::BBSXCommon::get_bbsname($wiki,$page);\r
249         # ¸µ¤Î¥Ú¡¼¥¸¤Ë¥ê¥À¥¤¥ì¥¯¥È\r
250         $wiki->redirect($bbsname);\r
251 }
252
253 1;