-
Notifications
You must be signed in to change notification settings - Fork 2
/
futaba.php
1402 lines (1291 loc) · 38.6 KB
/
futaba.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php require('repositories.php'); ?>
<?php require('models.php'); ?>
<?php
extract($_POST,EXTR_SKIP);
extract($_GET,EXTR_SKIP);
extract($_COOKIE,EXTR_SKIP);
$upfile_name=isset($_FILES["upfile"]["name"]) ? $_FILES["upfile"]["name"] : "";
$upfile=isset($_FILES["upfile"]["tmp_name"]) ? $_FILES["upfile"]["tmp_name"] : "";
define("LOGFILE", 'img.log'); //ログファイル名
define("TREEFILE", 'tree.log'); //ログファイル名
define("IMG_DIR", 'src/'); //画像保存ディレクトリ。futaba.phpから見て
define("THUMB_DIR",'thumb/'); //サムネイル保存ディレクトリ
define("TITLE", 'FutabaWall Imageboard'); //タイトル(<title>とTOP)
define("HOME", '../'); //「ホーム」へのリンク
define("MAX_KB", '500'); //投稿容量制限 KB(phpの設定により2Mまで
define("MAX_W", '250'); //投稿サイズ幅(これ以上はwidthを縮小
define("MAX_H", '250'); //投稿サイズ高さ
define("PAGE_DEF", '5'); //一ページに表示する記事
define("LOG_MAX", '500'); //ログ最大行数
define("ADMIN_PASS", 'admin_pass'); //管理者パス
define("RE_COL", '789922'); //>が付いた時の色
define("PHP_SELF", 'futaba.php'); //このスクリプト名
define("PHP_SELF2", 'index.html'); //入り口ファイル名
define("PHP_EXT", '.html'); //1ページ以降の拡張子
define("RENZOKU", '5'); //連続投稿秒数
define("RENZOKU2", '10'); //画像連続投稿秒数
define("MAX_RES", '30'); //強制sageレス数
define("USE_THUMB", 1); //サムネイルを作る する:1 しない:0
define("PROXY_CHECK", 0); //proxyの書込みを制限する y:1 n:0
define("DISP_ID", 0); //IDを表示する 強制:2 する:1 しない:0
define("BR_CHECK", 15); //改行を抑制する行数 しない:0
define("IDSEED", 'idの種'); //idの種
define("RESIMG", 0); //レスに画像を貼る:1 貼らない:0
$path = realpath("./").'/'.IMG_DIR;
$badstring = array("dummy_string","dummy_string2"); //拒絶する文字列
$badfile = array("dummy","dummy2"); //拒絶するファイルのmd5
$badip = array("addr.dummy.com","addr2.dummy.com"); //拒絶するホスト
$addinfo='';
?>
<?php
/**
* Rendering of message form.
*
* @params string $dat message log.
* @params integer $resno res number.
* @params string $admin administrator password.
* @return void
*/
function form(&$dat,$resno,$admin=""){
global $addinfo; $msg=""; $hidden="";
$maxbyte = MAX_KB * 1024;
$no=$resno;
if($resno){
$msg .= "[<a href=\"".PHP_SELF2."\">Return</a>]\n";
$msg .= "<table width='100%'><tr><th bgcolor=#e04000>\n";
$msg .= "<font color=#FFFFFF>Posting mode: Reply</font>\n";
$msg .= "</th></tr></table>\n";
}
if($admin){
$hidden = "<input type=hidden name=admin value=\"".ADMIN_PASS."\">";
$msg = "<h4>HTML tags are allowed.</h4>";
}
$dat.=$msg.'<center>
<form action="'.PHP_SELF.'" method="POST" enctype="multipart/form-data">
<input type=hidden name=mode value="regist">
'.$hidden.'
<input type=hidden name="MAX_FILE_SIZE" value="'.$maxbyte.'">
';
if($no){
$dat.='<input type=hidden name=resto value="'.$no.'">';
}
$dat.='<table cellpadding=1 cellspacing=1>
<tr><td bgcolor=#eeaa88><b>Name</b></td><td><input type=text name=name size="28"></td></tr>
<tr><td bgcolor=#eeaa88><b>E-mail</b></td><td><input type=text name=email size="28"></td></tr>
<tr><td bgcolor=#eeaa88><b>Subject</b></td><td><input type=text name=sub size="35">
<input type="submit" value="Submit"></td></tr>
<tr><td bgcolor=#eeaa88><b>Comment</b></td><td><textarea name=com cols="48" rows="4" wrap=soft></textarea></td></tr>
';
if(RESIMG || !$resno){
$dat.='<tr><td bgcolor=#eeaa88><b>File</b></td>
<td><input type=file name=upfile size="35">
[<label><input type=checkbox name=textonly value=on>No File</label>]</td></tr>';
}
$dat.='<tr><td bgcolor=#eeaa88><b>Password</b></td><td><input type=password name=pwd size=8 maxlength=8 value=""><small>(Password used for file deletion)</small></td></tr>
<tr><td colspan=2>
<small>
<ul>
<LI>Supported file types are: GIF, JPG, PNG</LI>
<LI>Maximum file size allowed is '.MAX_KB.' KB</LI>
<LI>Images greater than '.MAX_W.'x'.MAX_H.' pixels will be thumbnailed.</LI>
</ul>
'.$addinfo.'</small></td></tr></table></form></center><hr>';
}
?>
<?php
/**
* Update message.
*
* @params integer $resno target message number.
* @return void
*/
function updatelog($resno=0){
global $path;$p=0;
$tree = file(TREEFILE);
$find = false;
if($resno){
$counttree=count($tree);
for($i = 0;$i<$counttree;$i++){
list($artno,)=explode(",",rtrim($tree[$i]));
if($artno==$resno){ //レス先検索
$st=$i;$find=true;break;
}
}
if(!$find){
error("Error: Thread specified does not exist.");
}
}
$line = file(LOGFILE);
$countline=count($line);
for($i = 0; $i < $countline; $i++){
list($no,) = explode(",", $line[$i]);
$lineindex[$no]=$i + 1; //逆変換テーブル作成
}
$counttree = count($tree);
for($page=0;$page<$counttree;$page+=PAGE_DEF){
$dat='';
head($dat);
form($dat,$resno);
if(!$resno){
$st = $page;
}
$dat.='<form action="'.PHP_SELF.'" method=POST>';
for($i = $st; $i < $st+PAGE_DEF; $i++){
if(empty($tree[$i])){
continue;
}
$treeline = explode(",", rtrim($tree[$i]));
$disptree = $treeline[0];
$j=$lineindex[$disptree] - 1; //該当記事を探して$jにセット
if(empty($line[$j])){
continue;
} //$jが範囲外なら次の行
list($no,$now,$name,$email,$sub,$com,$url,
$host,$pwd,$ext,$w,$h,$time,$chk) = explode(",", $line[$j]);
// URLとメールにリンク
if($email){
$name = "<a href=\"mailto:$email\">$name</a>";
}
$com = auto_link($com);
$com = preg_replace("/(^|>)(>[^<]*)/i", "\\1<font color=".RE_COL.">\\2</font>", $com);
// 画像ファイル名
$img = $path.$time.$ext;
$src = IMG_DIR.$time.$ext;
// <imgタグ作成
$imgsrc = "";
if($ext && is_file($img)){
$size = filesize($img);//altにサイズ表示
if($w && $h){//サイズがある時
if(@is_file(THUMB_DIR.$time.'s.jpg')){
$imgsrc = "<small>Thumbnail displayed, click image for full size.</small><br><a href=\"".$src."\" target=_blank><img src=".THUMB_DIR.$time.'s.jpg'.
" border=0 align=left width=$w height=$h hspace=20 alt=\"".$size." B\"></a>";
}
else{
$imgsrc = "<a href=\"".$src."\" target=_blank><img src=".$src.
" border=0 align=left width=$w height=$h hspace=20 alt=\"".$size." B\"></a>";
}
}
else{//それ以外
$imgsrc = "<a href=\"".$src."\" target=_blank><img src=".$src.
" border=0 align=left hspace=20 alt=\"".$size." B\"></a>";
}
$dat.="File: <a href=\"$src\" target=_blank>$time$ext</a>-($size B)<br>$imgsrc";
}
// メイン作成
$dat.="<input type=checkbox name=\"$no\" value=delete><font color=#cc1105 size=+1><b>$sub</b></font> \n";
$dat.="Name <font color=#117743><b>$name</b></font> $now No.$no \n";
if(!$resno) $dat.="[<a href=".PHP_SELF."?res=$no>Reply</a>]";
$dat.="\n<blockquote>$com</blockquote>";
// そろそろ消える。
if($lineindex[$no]-1 >= LOG_MAX*0.95){
$dat.="<font color=\"#f00000\"><b>Since this thread is old, it will soon disappear.</b></font><br>\n";
}
//レス作成
if(!$resno){
$s=count($treeline) - 10;
if($s<1){
$s=1;
}
elseif($s>1){
$dat.="<font color=\"#707070\">レス".
($s - 1)."posts omitted. Click Reply to view.</font><br>\n";
}
}
else{
$s=1;
}
for($k = $s; $k < count($treeline); $k++){
$disptree = $treeline[$k];
$j=$lineindex[$disptree] - 1;
if($line[$j]==""){
continue;
}
list($no,$now,$name,$email,$sub,$com,$url,
$host,$pwd,$ext,$w,$h,$time,$chk) = explode(",", $line[$j]);
// URLとメールにリンク
if($email) $name = "<a href=\"mailto:$email\">$name</a>";
$com = auto_link($com);
$com = preg_replace("/(^|>)(>[^<]*)/i", "\\1<font color=".RE_COL.">\\2</font>", $com);
// 画像ファイル名
$img = $path.$time.$ext;
$src = IMG_DIR.$time.$ext;
// <imgタグ作成
$imgsrc = "";
if($ext && is_file($img)){
$size = filesize($img);//altにサイズ表示
if($w && $h){//サイズがある時
if(@is_file(THUMB_DIR.$time.'s.jpg')){
$imgsrc = "<small>Thumbnail displayed, click image for full size.</small><br><a href=\"".$src."\" target=_blank><img src=".THUMB_DIR.$time.'s.jpg'.
" border=0 align=left width=$w height=$h hspace=20 alt=\"".$size." B\"></a>";
}
else{
$imgsrc = "<a href=\"".$src."\" target=_blank><img src=".$src.
" border=0 align=left width=$w height=$h hspace=20 alt=\"".$size." B\"></a>";
}
}
else{//それ以外
$imgsrc = "<a href=\"".$src."\" target=_blank><img src=".$src.
" border=0 align=left hspace=20 alt=\"".$size." B\"></a>";
}
$imgsrc="<br> <a href=\"$src\" target=_blank>$time$ext</a>-($size B) $imgsrc";
}
// メイン作成
$dat.="<table border=0><tr><td nowrap align=right valign=top>…</td><td bgcolor=#F0E0D6 nowrap>\n";
$dat.="<input type=checkbox name=\"$no\" value=delete><font color=#cc1105 size=+1><b>$sub</b></font> \n";
$dat.="Name <font color=#117743><b>$name</b></font> $now No.$no \n";
$dat.="$imgsrc<blockquote>$com</blockquote>";
$dat.="</td></tr></table>\n";
}
$dat.="<br clear=left><hr>\n";
clearstatcache();//ファイルのstatをクリア
$p++;
if($resno){
break;
} //res時はtree1行だけ
}
$dat.='<table align=right><tr><td nowrap align=center>
<input type=hidden name=mode value=usrdel>Delete Post [<input type=checkbox name=onlyimgdel value=on>File Only]<br>
Password <input type=password name=pwd size=8 maxlength=8 value="">
<input type=submit value="Delete"></form></td></tr></table>';
if(!$resno){ //res時は表示しない
$prev = $st - PAGE_DEF;
$next = $st + PAGE_DEF;
// 改ページ処理
$dat.="<table align=left border=1><tr>";
if($prev >= 0){
if($prev==0){
$dat.="<form action=\"".PHP_SELF2."\" method=get><td>";
}
else{
$dat.="<form action=\"".$prev/PAGE_DEF.PHP_EXT."\" method=get><td>";
}
$dat.="<input type=submit value=\"Previous\">";
$dat.="</td></form>";
}
else{
$dat.="<td>Previous</td>";
}
$dat.="<td>";
for($i = 0; $i < count($tree) ; $i+=PAGE_DEF){
if($st==$i){
$dat.="[<b>".($i/PAGE_DEF)."</b>] ";
}
else{
if($i==0){
$dat.="[<a href=\"".PHP_SELF2."\">0</a>] ";
}
else{
$dat.="[<a href=\"".($i/PAGE_DEF).PHP_EXT."\">".($i/PAGE_DEF)."</a>] ";
}
}
}
$dat.="</td>";
if($p >= PAGE_DEF && count($tree) > $next){
$dat.="<form action=\"".$next/PAGE_DEF.PHP_EXT."\" method=get><td>";
$dat.="<input type=submit value=\"Next\">";
$dat.="</td></form>";
}
else{
$dat.="<td>Next</td>";
}
$dat.="</tr></table><br clear=all>\n";
}
foot($dat);
if($resno){
echo $dat;break;
}
if($page==0){
$logfilename=PHP_SELF2;
}
else{
$logfilename=$page/PAGE_DEF.PHP_EXT;
}
$fp = fopen($logfilename, "w");
set_file_buffer($fp, 0);
rewind($fp);
fputs($fp, $dat);
fclose($fp);
chmod($logfilename,0666);
}
if(!$resno&&is_file(($page/PAGE_DEF+1).PHP_EXT)){
unlink(($page/PAGE_DEF+1).PHP_EXT);
}
}
?>
<?php
/* フッタ */
/**
* Rendering of footer.
*
* @params string $dat string of log.
* @return void
*/
function foot(&$dat){
$dat.='
<center>
<small><!-- GazouBBS v3.0 --><!-- ふたば改0.8 -->
- <a href="http://php.s3.to" target=_top>GazouBBS</a> + <a href="http://www.2chan.net/" target=_top>futaba</a> + <a href="https://github.com/outrunning/futabawall" target=_top>futabawall</a> -
</small>
</center>
</body></html>';
}
?>
<?php
/**
* Create http link.
*
* @params string $message message.
* @return string Replaced to the link.
*/
function auto_link($message){
return preg_replace(
"/(https?|ftp|news)(:\/\/[[:alnum:]\+\$\;\?\.%,!#~*\/:@&=_-]+)/",
"<a href=\"\\1\\2\" target=\"_blank\">\\1\\2</a>",
$message
);
}
?>
<?php
/**
* Rendering of error page.
*
* @params string $mes message
* @params string $dest upload file path.
* @return void
*/
function error($mes,$dest=''){
global $upfile_name,$path;
if(is_file($dest)){
unlink($dest);
}
head($dat);
echo $dat;
echo "<br><br><hr size=1><br><br>
<center><font color=red size=5><b>$mes<br><br><a href=".PHP_SELF2.">Return</a></b></font></center>
<br><br><hr size=1>";
die("</body></html>");
}
?>
<?php
/**
* Connect to port with reverse proxy.
*
* @params integer $port target port.
* @return integer 1 then success.
* integer 0 then error.
*/
function proxy_connect($port){
$a="";$b="";
$fp = @fsockopen($_SERVER["REMOTE_ADDR"], $port,$a,$b,2);
if(!$fp){
return 0;
}
else{
return 1;
}
}
?>
<?php
//サムネイル作成
/**
* Build of thumbnail file.
*
* @params string $path file path.
* @params string $tim timestamp.
* @params string $ext extention name.
* @return void
*/
function thumb($path,$tim,$ext){
if(!function_exists("ImageCreate") ||
!function_exists("ImageCreateFromJPEG")){
return;
}
$fname=$path.$tim.$ext;
$thumb_dir = THUMB_DIR; //サムネイル保存ディレクトリ
$width = MAX_W; //出力画像幅
$height = MAX_H; //出力画像高さ
// 画像の幅と高さとタイプを取得
$size = GetImageSize($fname);
switch ($size[2]) {
case 1 :
if(function_exists("ImageCreateFromGIF")){
$im_in = @ImageCreateFromGIF($fname);
if($im_in){break;}
}
if(!is_executable(realpath("./gif2png")) ||
!function_exists("ImageCreateFromPNG")){
return;
}
@exec(realpath("./gif2png")." $fname",$a);
if(!file_exists($path.$tim.'.png')){
return;
}
$im_in = @ImageCreateFromPNG($path.$tim.'.png');
unlink($path.$tim.'.png');
if(!$im_in){
return;
}
break;
case 2 :
$im_in = @ImageCreateFromJPEG($fname);
if(!$im_in){
return;
}
break;
case 3 :
if(!function_exists("ImageCreateFromPNG")){
return;
}
$im_in = @ImageCreateFromPNG($fname);
if(!$im_in){
return;
}
break;
default :
return;
}
// リサイズ
if ($size[0] > $width || $size[1] >$height) {
$key_w = $width / $size[0];
$key_h = $height / $size[1];
($key_w < $key_h) ? $keys = $key_w : $keys = $key_h;
$out_w = ceil($size[0] * $keys) +1;
$out_h = ceil($size[1] * $keys) +1;
} else {
$out_w = $size[0];
$out_h = $size[1];
}
// 出力画像(サムネイル)のイメージを作成
if(function_exists("ImageCreateTrueColor")&&get_gd_ver()=="2"){
$im_out = ImageCreateTrueColor($out_w, $out_h);
}
else{
$im_out = ImageCreate($out_w, $out_h);
}
// 元画像を縦横とも コピーします。
ImageCopyResized($im_out, $im_in, 0, 0, 0, 0, $out_w, $out_h, $size[0], $size[1]);
// サムネイル画像を保存
ImageJPEG($im_out, $thumb_dir.$tim.'s.jpg',60);
chmod($thumb_dir.$tim.'s.jpg',0666);
// 作成したイメージを破棄
ImageDestroy($im_in);
ImageDestroy($im_out);
}
?>
<?php
/**
* Publish to futaba borad.
*
* @params string $name user name.
* @params string $email user email address.
* @params string $sub subject.
* @params string $comment user comment.
* @params string $url
* @params string $pwd user password.
* @params string $upfile upload file path.
* @params string $upfile_name upload filename.
* @params string $resto thread target number.
* @return void
*/
function regist($name,$email,$sub,$comment,$url,$pwd,$upfile,$upfile_name,$resto){
global $path,$badstring,$badfile,$badip,$pwdc,$textonly;
$dest="";$mes="";
// 時間
$time = time();
$tim = $time.substr(microtime(),2,3);
// アップロード処理
if($upfile&&file_exists($upfile)){
$dest = ImageFile::getNew()->createTempFileName($path, $tim);
move_uploaded_file($upfile, $dest);
//↑でエラーなら↓に変更
//copy($upfile, $dest);
$upfile_name = CleanStr($upfile_name);
if(!is_file($dest)){
error("Error: Upload failed.",$dest);
}
$size = getimagesize($dest);
if(!is_array($size)){
error("Error: Upload failed.",$dest);
}
$is_uploaded = ImageFile::getNew()->isUploaded($badfile, $dest);
if ($is_uploaded === true) {
error("Error: Duplicate md5 checksum detected.", $dest); //拒絶画像
return;
}
chmod($dest,0666);
// size[0] is width, size[1] is height.
$desired_size = ImageFile::adjustmentImageCanvasSize(
$size[0], $size[1]
);
$W = $desired_size['width'];
$H = $desired_size['height'];
$extension = ExtensionRepository::find($size[2]);
$mes = "$upfile_name uploaded!<br><br>";
}
foreach($badstring as $value){
$pattern = '/' . $value . '/';
if(preg_match($pattern, $comment) === 1 ||
preg_match($pattern, $sub) === 1 ||
preg_match($pattern, $name) === 1 ||
preg_match($pattern, $email) === 1 ){
error("Error: String refused.(str)",$dest);
};
}
if($_SERVER["REQUEST_METHOD"] != "POST"){
error("Error: Unjust POST.(post)",$dest);
}
// フォーム内容をチェック
if(!$name||preg_match("/^[ | |]*$/",$name) === 1){
$name="";
}
if(!$comment||preg_match("/^[ | |\t]*$/",$comment) === 1){
$comment="";
}
if(!$sub||preg_match("/^[ | |]*$/",$sub) === 1){
$sub="";
}
if(!$resto&&!$textonly&&!is_file($dest)){
error("Error: No file selected.",$dest);
}
if(!$comment&&!is_file($dest)){
error("Error: No text entered.",$dest);
}
$name=preg_replace("/Manager/","\"Manager\"",$name);
$name=preg_replace("/Deletion/","\"Deletion\"",$name);
if(strlen($comment) > 1000){
error("Error: Field too long.",$dest);
}
if(strlen($name) > 100){
error("Error: Field too long.",$dest);
}
if(strlen($email) > 100){
error("Error: Field too long.",$dest);
}
if(strlen($sub) > 100){
error("Error: Field too long.",$dest);
}
if(strlen($resto) > 10){
error("Error: Abnormal reply.",$dest);
}
if(strlen($url) > 10){
error("Error: Abnormal reply.",$dest);
}
//ホスト取得
$host = gethostbyaddr($_SERVER["REMOTE_ADDR"]);
foreach($badip as $value){ //拒絶host
if(preg_match("/$value$/i",$host)){
error("Error: String refused.(host)",$dest);
}
}
if(preg_match("/^mail/i",$host)
|| preg_match("/^ns/i",$host)
|| preg_match("/^dns/i",$host)
|| preg_match("/^ftp/i",$host)
|| preg_match("/^prox/i",$host)
|| preg_match("/^pc/i",$host)
|| preg_match("/^[^\.]\.[^\.]$/i",$host)){
$pxck = "on";
}
if(preg_match("/ne\\.jp$/i",$host)||
preg_match("/ad\\.jp$/i",$host)||
preg_match("/bbtec\\.net$/i",$host)||
preg_match("/aol\\.com$/i",$host)||
preg_match("/uu\\.net$/i",$host)||
preg_match("/asahi-net\\.or\\.jp$/i",$host)||
preg_match("/rim\\.or\\.jp$/i",$host)
){
$pxck = "off";
}
else{
$pxck = "on";
}
if($pxck=="on" && PROXY_CHECK){
if(proxy_connect('80') == 1){
error("ERROR! 公開PROXY規制中!!(80)",$dest);
} elseif(proxy_connect('8080') == 1){
error("ERROR! 公開PROXY規制中!!(8080)",$dest);
}
}
// No.とパスと時間とURLフォーマット
srand((double)microtime()*1000000);
if($pwd==""){
if($pwdc==""){
$pwd=rand();$pwd=substr($pwd,0,8);
}else{
$pwd=$pwdc;
}
}
$c_pass = $pwd;
$pass = ($pwd) ? substr(md5($pwd),2,8) : "*";
$youbi = array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
$yd = $youbi[gmdate("w", $time+9*60*60)] ;
$now = (
gmdate("y/m/d",$time+9*60*60) .
"(" .(string)$yd . ")" .
gmdate("H:i",$time+9*60*60)
);
if(DISP_ID){
if($email&&DISP_ID==1){
$now .= " ID:???";
}else{
$now.=" ID:".substr(crypt(md5($_SERVER["REMOTE_ADDR"].IDSEED.gmdate("Ymd", $time+9*60*60)),'id'),-8);
}
}
$email = PrettifyText::replaceStringOfMail($email);
$sub = PrettifyText::replaceStringOfSubject($sub);
$url = PrettifyText::replaceStringOfUrl($url);
$resto = PrettifyText::replaceStringOfResNumber($resto);
$comment = PrettifyText::replaceStringOfComment($comment);
$name = PrettifyText::replaceStringOfName($name);
$names = $name;
if(!$name){
$name="Anonymous";
}
if(!$comment){
$comment="No Text";
}
if(!$sub){
$sub="No Subject";
}
//ログ読み込み
$fp=fopen(LOGFILE,"r+");
flock($fp, 2);
rewind($fp);
$buf=fread($fp,1000000);
if($buf==''){
error("error load log",$dest);
}
$line = explode("\n",$buf);
$countline=count($line);
for($i = 0; $i < $countline; $i++){
if($line[$i]!=""){
list($artno,)=explode(",", rtrim($line[$i])); //逆変換テーブル作成
$lineindex[$artno]=$i+1;
$line[$i].="\n";
}
}
// 二重投稿チェック
$imax=count($line)>20 ? 20 : count($line)-1;
for($i=0;$i<$imax;$i++){
list($lastno,,$lname,,,$lcom,,$lhost,$lpwd,,,,$ltime,) = explode(",", $line[$i]);
if(strlen($ltime)>10){
$ltime=substr($ltime,0,-3);
}
if($host==$lhost||substr(md5($pwd),2,8)==$lpwd||substr(md5($pwdc),2,8)==$lpwd){
$p=1;
}
else{
$p=0;
}
if(RENZOKU && $p && $time - $ltime < RENZOKU){
error("Error: Flood detected, post discarded.",$dest);
}
if(RENZOKU && $p && $time - $ltime < RENZOKU2 && $upfile_name){
error("Error: Flood detected, file discarded.",$dest);
}
if(RENZOKU && $p && $comment == $lcom && !$upfile_name){
error("Error: Flood detected.",$dest);
}
}
// ログ行数オーバー
if(count($line) >= LOG_MAX){
for($d = count($line)-1; $d >= LOG_MAX-1; $d--){
list($dno,,,,,,,,,$dext,,,$dtime,) = explode(",", $line[$d]);
if(is_file($path.$dtime.$dext)){
unlink($path.$dtime.$dext);
}
if(is_file(THUMB_DIR.$dtime.'s.jpg')){
unlink(THUMB_DIR.$dtime.'s.jpg');
}
$line[$d] = "";
treedel($dno);
}
}
// アップロード処理
if($dest&&file_exists($dest)){
$imax=count($line)>200 ? 200 : count($line)-1;
for($i=0;$i<$imax;$i++){ //画像重複チェック
list(,,,,,,,,,$extensionp,,,$timep,$p,) = explode(",", $line[$i]);
if($p==$is_uploaded&&file_exists($path.$timep.$extensionp)){
error("Error: Duplicate file entry detected.",$dest);
}
}
}
list($lastno,) = explode(",", $line[0]);
$no = $lastno + 1;
isset($extension)?0:$extension="";
isset($W)?0:$W="";
isset($H)?0:$H="";
isset($chk)?0:$chk="";
$newline = "$no,$now,$name,$email,$sub,$comment,$url,$host,$pass,$extension,$W,$H,$tim,$,\n";
$newline.= implode('', $line);
ftruncate($fp,0);
set_file_buffer($fp, 0);
rewind($fp);
fputs($fp, $newline);
//ツリー更新
$find = false;
$newline = '';
$tp=fopen(TREEFILE,"r+");
set_file_buffer($tp, 0);
rewind($tp);
$buf=fread($tp,1000000);
if($buf==''){error("error tree update",$dest);}
$line = explode("\n",$buf);
$countline=count($line);
for($i = 0; $i < $countline; $i++){
if($line[$i]!=""){
$line[$i].="\n";
$j=explode(",", rtrim($line[$i]));
if($lineindex[$j[0]]==0){
$line[$i]='';
}
}
}
if($resto){
for($i = 0; $i < $countline; $i++){
$rtno = explode(",", rtrim($line[$i]));
if($rtno[0]==$resto){
$find = TRUE;
$line[$i]=rtrim($line[$i]).','.$no."\n";
$j=explode(",", rtrim($line[$i]));
if(count($j)>MAX_RES){
$email='sage';
}
if(!stristr($email,'sage')){
$newline=$line[$i];
$line[$i]='';
}
break;
}
}
}
if(!$find){
if(!$resto){
$newline="$no\n";
}
else{
error("Error: Thread specified does not exist.",$dest);
}
}
$newline.=implode('', $line);
ftruncate($tp,0);
set_file_buffer($tp, 0);
rewind($tp);
fputs($tp, $newline);
fclose($tp);
fclose($fp);
//クッキー保存
setcookie ("pwdc", $c_pass,time()+7*24*3600); /* 1週間で期限切れ */
if(function_exists("mb_internal_encoding")&&function_exists("mb_convert_encoding")
&&function_exists("mb_substr")){
if(preg_match("/MSIE|Opera/",$_SERVER["HTTP_USER_AGENT"]) === 1){
$i=0;$c_name='';
mb_internal_encoding("UTF-8");
while($j=mb_substr($names,$i,1)){
$j = mb_convert_encoding($j, "UTF-16", "UTF-8");
$c_name.="%u".bin2hex($j);
$i++;
}
header(
"Set-Cookie: namec=$c_name; expires=".gmdate("D, d-M-Y H:i:s",time()+7*24*3600)." GMT",false
);
}
else{
$c_name=$names;
setcookie ("namec", $c_name,time()+7*24*3600); /* 1週間で期限切れ */
}
}
if($dest&&file_exists($dest)){
rename($dest,$path.$tim.$extension);
if(USE_THUMB){thumb($path,$tim,$extension);}
}
updatelog();
echo "<html><head><meta charset=\"UTF-8\"><meta http-equiv=\"refresh\" content=\"1;URL=".PHP_SELF2."\"></head>";
echo "<body>$mes Updating page.</body></html>";
}
?>
<?php
/**
* Get GD Version.
*
* @return string GD Information.
*/
function get_gd_ver(){
if(function_exists("gd_info")){
$gdver=gd_info();
$phpinfo=$gdver["GD Version"];
}
else{ //php4.3.0未満用
ob_start();
phpinfo(8);
$phpinfo=ob_get_contents();
ob_end_clean();
$phpinfo=strip_tags($phpinfo);
$phpinfo=stristr($phpinfo,"gd version");
$phpinfo=stristr($phpinfo,"version");
}
$end=strpos($phpinfo,".");
$phpinfo=substr($phpinfo,0,$end);
$length = strlen($phpinfo)-1;
$phpinfo=substr($phpinfo,$length);
return $phpinfo;
}
?>
<?php
/**
* Seek MD5 checksum of file.
*
* @params string $inFile file path.
* @return string MD5 checksum.
* false Is error.
*/
function md5_of_file($in_file) {
if (file_exists($in_file)){
if(function_exists('md5_file')){
return md5_file($in_file);
}else{
$fd = fopen($in_file, 'r');
$fileContents = fread($fd, filesize($in_file));
fclose ($fd);
return md5($fileContents);
}
}else{
return false;
}
}
?>
<?php
/**
* Delete of message.
*
* @params integer $delno delete message number.
* @return void
*/
function treedel($delno){
$fp=fopen(TREEFILE,"r+");
set_file_buffer($fp, 0);
flock($fp, 2);
rewind($fp);
$buf=fread($fp,1000000);
if($buf==''){
error("error tree del");
}
$line = explode("\n",$buf);
$countline=count($line);
if($countline>2){
for($i = 0; $i < $countline; $i++){
if($line[$i]!=""){
$line[$i].="\n";
}
}
for($i = 0; $i < $countline; $i++){
$treeline = explode(",", rtrim($line[$i]));
$counttreeline=count($treeline);
for($j = 0; $j < $counttreeline; $j++){
if($treeline[$j] == $delno){
$treeline[$j]='';
if($j==0){
$line[$i]='';
}
else{
$line[$i]=implode(',', $treeline);
$line[$i]=preg_replace("/,,/",",",$line[$i]);
$line[$i]=preg_replace("/,$/","",$line[$i]);
$line[$i].="\n";
}
break 2;
}
}
}
ftruncate($fp,0);
set_file_buffer($fp, 0);
rewind($fp);
fputs($fp, implode('', $line));
}
fclose($fp);
}
?>
<?php
/**
* Delete of user post message.
*
* @params integer $no post message number.
* @params string $pwd post message password.
* @return void
*/
function usrdel($no,$pwd){
global $path,$pwdc,$onlyimgdel;
$host = gethostbyaddr($_SERVER["REMOTE_ADDR"]);
$delno = array("dummy");
$delflag = false;
reset($_POST);
while ($item = each($_POST)){
if($item[1]=='delete'){