-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbbs.php
More file actions
2815 lines (2564 loc) · 96.9 KB
/
Copy pathbbs.php
File metadata and controls
2815 lines (2564 loc) · 96.9 KB
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
// Start session for admin/mod login
session_start();
if (version_compare(PHP_VERSION, '8.0.0', '<')) {
echo 'Error: PHP version is '.phpversion().'. This script is compatible with PHP 8.0 and above.';
exit();
}
if (ini_get('register_globals') == 1) {
#print 'Error: register_globals is turned on. Please turn it off in your PHP configuration for security reasons.';
#exit();
}
/*
The instructions have been moved to readme.md.
*/
// Configuration file
require_once("./conf.php");
// Version (for copyright notice)
$CONF['VERSION'] = '[20260315] (<span title="Heyuri Applicable Research & Development">Heyuri</span>, <span title="Hiru-ga-take">ヶ</span>, @Links, <span title="Giko-neko">擬古猫</span>)';
/* Launch */
// Determine language-specific subdirectory
// eg. TEMPLATE_LANGUAGE = 'en' -> './sub/en/'
$tmpl_lang = $CONF['TEMPLATE_LANGUAGE'] ?? 'ja';
$SUBDIR = './sub/' . $tmpl_lang . '/';
// Load language strings to be used in this file
$langfile = $SUBDIR . 'lang.php';
if (file_exists($langfile)) {
require_once $langfile;
} else {
die("Language file not found: $langfile");
}
// Translation helper
function T($key) {
return $GLOBALS['MSG'][$key] ?? $key;
}
// Set error output level
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Demote "Undefined array key" warnings to notice
// https://github.com/php/php-src/issues/8906#issuecomment-1172810362
set_error_handler(function($errno, $error){
if (!str_starts_with($error, 'Undefined array key')){
return false; //default error handler.
}else{
trigger_error($error, E_USER_NOTICE);
return true;
}
}, E_WARNING);
if ($CONF['RUNMODE'] == 2) {
print T('BBS_OUT_OF_SERVICE');
exit();
}
/* Process to prohibit access by host name */
if (Func::hostname_match($CONF['HOSTNAME_BANNED'],$CONF['HOSTAGENT_BANNED'])) {
print T('ACCESS_PROHIBITED');
exit();
}
// Override template file paths according to language
$CONF['TEMPLATE'] = $SUBDIR . 'template.html';
$CONF['TEMPLATE_ADMIN'] = $SUBDIR . 'tmpladmin.html';
$CONF['TEMPLATE_LOG'] = $SUBDIR . 'tmpllog.html';
$CONF['TEMPLATE_TREEVIEW'] = $SUBDIR . 'tmpltree.html';
$CONF['TEMPLATE_LOGIN'] = $SUBDIR . 'login.html';
// ----------------------------------------------------------------------
// Include file paths
// ----------------------------------------------------------------------
/**
* Message log search module
* @const PHP_GETLOG
*/
define('PHP_GETLOG', $SUBDIR . 'bbslog.php');
/**
* Admin module
* @const PHP_BBSADMIN
*/
define('PHP_BBSADMIN', $SUBDIR . 'bbsadmin.php');
/**
* Tree view module
* @const PHP_TREEVIEW
*/
define('PHP_TREEVIEW', $SUBDIR . 'bbstree.php');
/**
* BBS with image upload function module
* @const PHP_IMAGEBBS
*/
define('PHP_IMAGEBBS', $SUBDIR . 'bbsimage.php');
/**
* HTML template library
* (not language-dependent)
* @const LIB_TEMPLATE
*/
define('LIB_TEMPLATE', './sub/patTemplate.php');
/**
* ZIP file creation library
* (not language-dependent)
* @const LIB_PHPZIP
*/
define('LIB_PHPZIP', './sub/phpzip.inc.php');
/**
* Constant for file include detection
* @const INCLUDED_FROM_BBS
*/
define('INCLUDED_FROM_BBS', TRUE);
/**
* Constant for current time
* @const CURRENT_TIME
*/
define('CURRENT_TIME', time() - $CONF['DIFFTIME'] * 60 * 60 + $CONF['DIFFSEC']);
/* Execute */
{
require_once(LIB_TEMPLATE);
script_run();
}
/**
* Script execution main process
*
* Basically, this is where the module branches are described
*/
function script_run() {
$CONF = &$GLOBALS['CONF'];
# Password setting page (bbsadmin.php)
if ($CONF['ADMINPOST'] == '') {
require_once(PHP_BBSADMIN);
$bbsadmin = new Bbsadmin();
$bbsadmin->procForm();
$bbsadmin->refcustom();
$bbsadmin->setusersession();
if ($_POST['ad'] == 'ps') {
$bbsadmin->prtpass($_POST['ps']);
}
else {
$bbsadmin->prtsetpass();
}
}
# Admin/mod login page (GET: ?m=login)
elseif ($_GET['m'] == 'login') {
if (isModerator()) {
header('Location: ' . $CONF['CGIURL'] . '?m=ad');
exit();
}
require_once(LIB_TEMPLATE);
$t = new patTemplate();
// Load both main template and login template for subtemplate support
$t->readTemplatesFromFile($CONF['TEMPLATE']);
$t->readTemplatesFromFile($CONF['TEMPLATE_LOGIN']);
$templateValues = removeArrayValues($CONF);
$t->addGlobalVars($templateValues);
$t->displayParsedTemplate('login');
exit();
}
# Admin/mod login POST
elseif ($_POST['m'] == 'login') {
$pass = trim($_POST['adminpass'] ?? '');
$is_mod = false;
if (crypt($pass, $CONF['ADMINPOST']) === $CONF['ADMINPOST']) {
$is_mod = true;
}
if ($is_mod) {
$_SESSION['is_mod'] = true;
header('Location: ' . $CONF['CGIURL'] . '?m=ad');
exit();
} else {
require_once(LIB_TEMPLATE);
$t = new patTemplate();
$t->readTemplatesFromFile($CONF['TEMPLATE']);
$t->readTemplatesFromFile($CONF['TEMPLATE_LOGIN']);
// environment vars for template
$templateValues = removeArrayValues($CONF);
$t->addGlobalVars($templateValues);
$t->addVar('login', 'LOGIN_ERROR', 'Invalid username or password.');
$t->setAttribute('login_error', 'visibility', 'visible');
$t->displayParsedTemplate('login');
exit();
}
}
# Admin mode (GET: ?m=ad) - session required
elseif ($_REQUEST['m'] == 'ad' && isModerator()) {
require_once(PHP_BBSADMIN);
$bbsadmin = new Bbsadmin();
$bbsadmin->main();
}
# Message log search mode (sub/bbslog.php)
elseif ($_GET['m'] == 'g' or $_POST['m'] == 'g') {
require_once(PHP_GETLOG);
$getlog = new Getlog();
$getlog->main();
}
# Legacy admin POST (disable: always redirect to login)
elseif ($_POST['m'] == 'ad') {
header('Location: ' . $CONF['CGIURL'] . '?m=login');
exit();
}
# Tree view (sub/bbstree.php)
elseif ($_GET['m'] == 'tree' or $_POST['m'] == 'tree') {
require_once(PHP_TREEVIEW);
$treeview = new Treeview();
$treeview->main();
}
# Image bulletin board (sub/bbsimage.php)
elseif ($CONF['BBSMODE_IMAGE'] == 1) {
require_once(PHP_IMAGEBBS);
$imagebbs = new Imagebbs();
$imagebbs->main();
}
# Bulletin board mode (bbs.php)
else {
$bbs = new Bbs();
$bbs->main();
}
exit();
}
/**
* Detects if any honeypot fields are filled (for spam prevention)
* @param array $fields Optional array of field values (defaults to $_POST)
* @return bool True if any honeypot field is filled, false otherwise
*/
function detectHoneyPot(?array $fields = null): bool {
// If no fields are provided, use $_POST by default
if ($fields === null) {
$fields = $_POST;
}
// List of honeypot field names to check
$honeypots = [
'e-mail',
'username',
'subject',
'comment',
'firstname',
'lastname',
'city',
'state',
'zipcode'
];
// Check if any of the honeypot fields are filled
foreach ($honeypots as $name) {
if (!empty($fields[$name])) {
return true;
}
}
// No honeypot fields are filled
return false;
}
/**
* Removes array values from an array, leaving only scalar values.
*
* @param array $array The input array
* @return array The array with only scalar values
*/
function removeArrayValues(array $array): array {
foreach ($array as $key => $value) {
if (is_array($value)) {
unset($array[$key]);
}
}
return $array;
}
/**
* Validates if the given string is a valid email address.
*
* @param string $email The email address to validate
* @return bool True if the email is valid, false otherwise
*/
function isModerator(): bool {
return isset($_SESSION['is_mod']) && $_SESSION['is_mod'];
}
/**
* Base web application class - Webapp
*
* Super class for each mode. Describes the processing common to each module.
*
* @package strangeworld.cnscript
* @access public
*/
class Webapp {
var $c; /* Settings information */
var $f; /* Form input */
var $s = array(); /* Session-specific information such as the user's host */
var $t; /* HTML template object */
/**
* Constructor
*
*/
function __construct() {
$this->c = &$GLOBALS['CONF'];
$this->t = new patTemplate();
$this->t->readTemplatesFromFile($this->c['TEMPLATE']);
}
/**
* Destructor
*/
function destroy() {
}
/*20210625 Neko/2chtrip http://www.mits-jp.com/2ch/ */
function tripuse($key) {
#$tripkey = '#istrip';? // String to be used as password (with #)
$key = mb_convert_encoding($key, "SJIS-win", "UTF-8,SJIS-win"); // to, from
# $key = '#'.substr($key, strpos($key, '#'));
# Trip
# $trip is used for 0thello
$trip = '';
if (preg_match("/([^\#]*)\#(.+)/", $key, $match)) {
if (strlen($match[2]) >= 12){
# New conversion method
$mark = substr($match[2], 0, 1);
if ($mark == '#' || $mark == '$'){
if (preg_match('|^#([[:xdigit:]]{16})([./0-9A-Za-z]{0,2})$|',$match[2],$str)){
$trip = substr(crypt(pack('H*', $str[1]), "$str[2].."), -10);
} else {
# For future expansion
$trip = '???';
}
} else {
// $trip = substr(base64_encode(pack('H*', sha1($match[2]))), 0, 12);
$trip = substr(base64_encode(sha1($match[2],TRUE)),0,12);
$trip = str_replace('+','.',$trip);
}
} else {
$salt = substr($match[2]."H.", 1, 2);
$salt = preg_replace("/[^\.-z]/", ".", $salt);
$salt = strtr($salt,":;<=>?@[\\]^_`","ABCDEFGabcdef");
$trip = substr(crypt($match[2], $salt),-10);
}
# $match[1] = str_replace("◆", "◇", $match[1]);
# $_POST['FROM'] = $match[1]."</b> ◆".$trip."<b>";
$trip ="◆".$trip;
} else {
$trip = str_replace("◆", "◇", $key);
}
return $trip;
}
/**
* Form acquisition preprocessing
*/
function procForm() {
if (!$this->c['BBSMODE_IMAGE'] and $_SERVER['CONTENT_LENGTH'] > $this->c['MAXMSGSIZE'] * 5) {
$this->prterror(T('POST_TOO_LARGE'));
}
if ($this->c['BBSHOST'] and $_SERVER['HTTP_HOST'] != $this->c['BBSHOST']) {
$this->prterror(T('INVALID_CALLER'));
}
# Limited to POST or GET only
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$this->f = $_POST;
}
else {
$this->f = $_GET;
}
# String replacement
foreach ($this->f as $name => $value) {
if (is_array($value)) {
foreach (array_keys($value) as $valuekey) {
$value[$valuekey] = Func::html_escape($value[$valuekey]);
}
}
else {
$value = Func::html_escape($value);
}
$this->f[$name] = $value;
}
}
/**
* Session-specific information settings
*/
function setusersession() {
$this->s['U'] = $this->f['u'];
$this->s['I'] = $this->f['i'];
$this->s['C'] = $this->f['c'];
$this->s['MSGDISP'] = $this->f['d'];
$this->s['TOPPOSTID'] = $this->f['p'];
# Get settings information cookies
if ($this->c['COOKIE'] and $_COOKIE['c']
and preg_match("/u=([^&]*)&i=([^&]*)&c=([^&]*)/", $_COOKIE['c'], $matches)) {
if (!isset($this->f['u'])) {
$this->s['U'] = urldecode($matches[1]);
}
if (!isset($this->f['i'])) {
$this->s['I'] = urldecode($matches[2]);
}
if (!isset($this->f['c'])) {
$this->s['C'] = $matches[3];
}
}
# Get cookie for the UNDO button
if ($this->c['COOKIE'] and $this->c['ALLOW_UNDO'] and $_COOKIE['undo']
and preg_match("/p=([^&]*)&k=([^&]*)/", $_COOKIE['undo'], $matches)) {
$this->s['UNDO_P'] = $matches[1];
$this->s['UNDO_K'] = $matches[2];
}
# Default query
$this->s['QUERY'] = "c=".$this->s['C'];
if ($this->s['MSGDISP']) {
$this->s['QUERY'] .= "&d=".$this->s['MSGDISP'];
}
if ($this->s['TOPPOSTID']) {
$this->s['QUERY'] .= "&p=".$this->s['TOPPOSTID'];
}
# Default URL
$this->s['DEFURL'] = $this->c['CGIURL'] . '?' . $this->s['QUERY'];
# Initialize template variables
$tmp = array_merge($this->c, $this->s);
$tmp = removeArrayValues($tmp);
$this->t->addGlobalVars($tmp);
}
/**
* Error indication
*
* @access public
* @param String $err_message Error message
*/
function prterror($err_message) {
$this->sethttpheader();
print $this->prthtmlhead ($this->c['BBSTITLE'] . ' Error');
$this->t->addVar('error', 'ERR_MESSAGE', $err_message);
if (isset($this->s['DEFURL'])) {
$this->t->setAttribute('backnavi', 'visibility', 'visible');
}
$this->t->displayParsedTemplate('error');
print $this->prthtmlfoot ();
$this->destroy();
exit();
}
/**
* Display HTML header section
*
* @access public
* @param String $title HTML title
* @param String $customhead Custom header in the head tag
* @param String $customstyle Custom style sheets in the style tag
* @return String HTML data
*/
function prthtmlhead($title = "", $customhead = "", $customstyle = "") {
$this->t->clearTemplate('header');
$this->t->addVars('header', array(
'TITLE' => $title,
'CUSTOMHEAD' => $customhead,
'CUSTOMSTYLE' => $customstyle,
));
$htmlstr = $this->t->getParsedTemplate('header');
return $htmlstr;
}
/**
* Display HTML footer section
*
* @access public
* @return String HTML data
*/
function prthtmlfoot() {
if ($this->c['SHOW_PRCTIME'] and $this->s['START_TIME']) {
$duration = Func::microtime_diff($this->s['START_TIME'], microtime());
$duration = sprintf("%0.6f", $duration);
$this->t->setAttribute('duration', 'visibility', 'visible');
$this->t->addVar('duration', 'DURATION', $duration);
}
$htmlstr = $this->t->getParsedTemplate('footer');
return $htmlstr;
}
/**
* Copyright notice
*/
function prtcopyright() {
$copyright = $this->t->getParsedTemplate('copyright');
return $copyright;
}
/**
* Redirector output with META tags
*
* @access public
* @param String $redirecturl URL to redirect
*/
function prtredirect($redirecturl) {
$this->sethttpheader();
print $this->prthtmlhead ($this->c['BBSTITLE'] . ' - ' . T('URL_REDIRECTION'),
"<meta http-equiv=\"refresh\" content=\"1;url={$redirecturl}\">\n");
$this->t->addVar('redirect', 'REDIRECTURL', $redirecturl);
$this->t->displayParsedTemplate('redirect');
print $this->prthtmlfoot ();
}
/**
* Display message contents definition
*/
function setmessage($message, $mode = 0, $tlog = '') {
if (count($message) < 10) {
return;
}
$message['WDATE'] = Func::getdatestr($message['NDATE'], $this->c['DATEFORMAT']);
#20181102 Gikoneko: Escape special characters
$message['MSG'] = preg_replace("/{/i","{", $message['MSG'], -1);
$message['MSG'] = preg_replace("/}/i","}", $message['MSG'], -1);
#20241016 Heyuri: Deprecated by ytthumb.js, embedding each video in browser slows stuff down a lot
##20200524 Gikoneko: youtube embedding
#$message['MSG'] = preg_replace("/<a href=\"https:\/\/youtu.be\/([^\"]+?)\" target=\"link\">([^<]+?)<\/a>/",
#"<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/$1\" frameborder=\"0\" allow=\"autoplay; encrypted-media\" allowfullscreen></iframe>\r<a href=\"https://youtu.be/$1\">$2</a>", $message['MSG']);
##20200524 Gikoneko: youtube embedding 2
#$message['MSG'] = preg_replace("/<a href=\"https:\/\/www.youtube.com\/watch\?v=([^\"]+?)\" target=\"link\">([^<]+?)<\/a>/",
#"<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/$1\" frameborder=\"0\" allow=\"autoplay; encrypted-media\" allowfullscreen></iframe>\r<a href=\"https://www.youtube.com/watch?v=$1\">$2</a>", $message['MSG']);
##20200524 Gikoneko: youtube embedding 3
#$message['MSG'] = preg_replace("/<a href=\"https:\/\/m.youtube.com\/watch\?v=([^\"]+?)\" target=\"link\">([^<]+?)<\/a>/",
#"<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/$1\" frameborder=\"0\" allow=\"autoplay; encrypted-media\" allowfullscreen></iframe>\r<a href=\"https://m.youtube.com/watch?v=$1\">$2</a>", $message['MSG']);
# "Reference"
if (!$mode) {
$message['MSG'] = preg_replace("/<a href=\"m=f&s=(\d+)[^>]+>([^<]+)<\/a>$/i",
"<a href=\"{$this->c['CGIURL']}?m=f&s=$1&{$this->s['QUERY']}\">$2</a>", $message['MSG'], 1);
$message['MSG'] = preg_replace("/<a href=\"mode=follow&search=(\d+)[^>]+>([^<]+)<\/a>$/i",
"<a href=\"{$this->c['CGIURL']}?m=f&s=$1&{$this->s['QUERY']}\">$2</a>", $message['MSG'], 1);
} else {
$message['MSG'] = preg_replace("/<a href=\"m=f&s=(\d+)[^>]+>([^<]+)<\/a>$/i",
"<a href=\"#a$1\">$2</a>", $message['MSG'], 1);
$message['MSG'] = preg_replace("/<a href=\"mode=follow&search=(\d+)[^>]+>([^<]+)<\/a>$/i",
"<a href=\"#a$1\">$2</a>", $message['MSG'], 1);
}
if ($mode == 0 or ($mode == 1 and $this->c['OLDLOGBTN'])) {
if (!$this->c['FOLLOWWIN']) { $newwin = " target=\"link\""; }
else { $newwin = ''; }
$spacer = " ";
$lnk_class = "class=\"internal\"";
# Follow-up post button
$message['BTNFOLLOW'] = '';
if ($this->c['BBSMODE_ADMINONLY'] != 1) {
$message['BTNFOLLOW'] = "$spacer<a href=\"{$this->c['CGIURL']}"
."?m=f&s={$message['POSTID']}&".$this->s['QUERY'];
if ($this->f['w']) {
$message['BTNFOLLOW'] .= "&w=".$this->f['w'];
}
if ($mode == 1) {
$message['BTNFOLLOW'] .= "&ff=$tlog";
}
$message['BTNFOLLOW'] .= "\"$newwin $lnk_class title=\"" . T('TITLE_FOLLOWUP') . "\" >{$this->c['TXTFOLLOW']}</a>";
}
# Search by user button
$message['BTNAUTHOR'] = '';
if ($message['USER'] != $this->c['ANONY_NAME'] and $this->c['BBSMODE_ADMINONLY'] != 1) {
$message['BTNAUTHOR'] = "$spacer<a href=\"{$this->c['CGIURL']}"
."?m=s&s=". urlencode(preg_replace("/<[^>]*>/", '', $message['USER'])) ."&".$this->s['QUERY'];
if ($this->f['w']) {
$message['BTNAUTHOR'] .= "&w=".$this->f['w'];
}
if ($mode == 1) {
$message['BTNAUTHOR'] .= "&ff=$tlog";
}
$message['BTNAUTHOR'] .= "\" target=\"link\" $lnk_class title=\"" . T('TITLE_SEARCH_BY_USER') . "\" >{$this->c['TXTAUTHOR']}</a>";
}
# Thread view button
if (!$message['THREAD']) {
$message['THREAD'] = $message['POSTID'];
}
$message['BTNTHREAD'] = '';
if ($this->c['BBSMODE_ADMINONLY'] != 1) {
$message['BTNTHREAD'] = "$spacer<a href=\"{$this->c['CGIURL']}?m=t&s={$message['THREAD']}&".$this->s['QUERY'];
if ($mode == 1) {
$message['BTNTHREAD'] .= "&ff=$tlog";
}
$message['BTNTHREAD'] .= "\" target=\"link\" $lnk_class title=\"" . T('TITLE_THREAD_VIEW') . "\" >{$this->c['TXTTHREAD']}</a>";
}
# Tree view button
$message['BTNTREE'] = '';
if ($this->c['BBSMODE_ADMINONLY'] != 1) {
$message['BTNTREE'] = "$spacer<a href=\"{$this->c['CGIURL']}?m=tree&s={$message['THREAD']}&".$this->s['QUERY'];
if ($mode == 1) {
$message['BTNTREE'] .= "&ff=$tlog";
}
$message['BTNTREE'] .= "\" target=\"link\" $lnk_class title=\"" . T('TITLE_TREE_VIEW') . "\" >{$this->c['TXTTREE']}</a>";
}
# UNDO button
$message['BTNUNDO'] = '';
if ($this->c['ALLOW_UNDO'] and isset($this->s['UNDO_P']) and $this->s['UNDO_P'] == $message['POSTID']) {
$message['BTNUNDO'] = "$spacer<a href=\"{$this->c['CGIURL']}?m=u&s={$message['POSTID']}&".$this->s['QUERY'];
$message['BTNUNDO'] .= "\" $lnk_class title=\"" . T('TITLE_DELETE_POST') . "\" >{$this->c['TXTUNDO']}</a>";
}
# Button integration
$message['BTN'] = $message['BTNFOLLOW']. $message['BTNAUTHOR']. $message['BTNTHREAD']. $message['BTNTREE']. $message['BTNUNDO'];
}
# Email address
if ($message['MAIL']) {
$message['USER'] = "<a href=\"mailto:{$message['MAIL']}\">{$message['USER']}</a>";
}
# Change quote color
$message['MSG'] = preg_replace("/(^|\r)(\>[^\r]*)/", "$1<span class=\"q\">$2</span>", $message['MSG']);
$message['MSG'] = str_replace("</span>\r<span class=\"q\">", "\r", $message['MSG']);
# Environment variables
$message['ENVADDR'] = '';
$message['ENVUA'] = '';
$message['ENVBR'] = '';
if ($this->c['IPPRINT'] or $this->c['UAPRINT']) {
if ($this->c['IPPRINT']) {
$message['ENVADDR'] = $message['PHOST'];
}
if ($this->c['UAPRINT']) {
$message['ENVUA'] = $message['AGENT'];
}
if ($this->c['IPPRINT'] and $this->c['UAPRINT']) {
$message['ENVBR'] = '<br>';
}
if ($message['ENVADDR'] or $message['ENVUA']) {
$this->t->clearTemplate('envlist');
$this->t->setAttribute("envlist", "visibility", "visible");
$this->t->addVars('envlist', array(
'ENVADDR' => $message['ENVADDR'],
'ENVUA' => $message['ENVUA'],
'ENVBR' => $message['ENVBR'],
));
}
}
# Whether or not to display images on the image BBS
if (!$this->c['SHOWIMG']) {
$message['MSG'] = Func::conv_imgtag($message['MSG']);
}
# Convert img tags even if there is no image file
elseif (preg_match("/<a href=[^>]+><img [^>]*?src=\"([^\"]+)\"[^>]+><\/a>/i", $message['MSG'], $matches)) {
if (!file_exists($matches[1])) {
$message['MSG'] = Func::conv_imgtag($message['MSG']);
}
}
# Message display content definition
$this->t->clearTemplate('message');
$this->t->addVars('message', $message);
}
/**
* Single message output
*
* Outputs the HTML of a message based on the message array.
* Supports the message log module.
*
* @access public
* @param Array $message Message
* @param Integer $mode 0: Bulletin board / 1: Message log search (with buttons displayed) / 2: Message log search (without buttons displayed) / 3: For message log output file
* @param String $tlog Specified log file
* @return String Message HTML data
*/
function prtmessage($message, $mode = 0, $tlog = '') {
$this->setmessage($message, $mode, $tlog);
$prtmessage = $this->t->getParsedTemplate('message');
return $prtmessage;
}
/**
* Log reading
*
* Reads the log file, returns it as a line array.
*
* @access public
* @param String $logfilename Log file name (optional)
* @return Array Log line array
*/
function loadmessage($logfilename = "") {
if ($logfilename) {
preg_match("/^([\w.]*)$/", $logfilename, $matches);
$logfilename = $this->c['OLDLOGFILEDIR']."/".$matches[1];
}
else {
$logfilename = $this->c['LOGFILENAME'];
}
if (!file_exists($logfilename)) {
$this->prterror(T('FAILED_TO_READ_MESSAGE'));
}
$logdata = file($logfilename);
return $logdata;
}
/**
* Get single message
*
* Converts a log line to a message array and returns it.
*
* @access public
* @param String $logline Log line
* @return Array Message array
*/
function getmessage($logline) {
$logsplit = @explode (',', rtrim($logline));
if (count($logsplit) < 10) {
return;
}
$i = 6;
while ($i <= 9) {
$logsplit[$i] = strtr ($logsplit[$i], "\0", ",");
$logsplit[$i] = str_replace (",", ",", $logsplit[$i]);
$i++;
}
$message = array();
$messagekey = array('NDATE', 'POSTID', 'PROTECT', 'THREAD', 'PHOST', 'AGENT', 'USER', 'MAIL', 'TITLE', 'MSG', 'REFID', 'RESERVED1', 'RESERVED2', 'RESERVED3', );
$logsplitcount = count($logsplit);
$i = 0;
while ($i < $logsplitcount) {
if ($i > 12) { break; }
$message[$messagekey[$i]] = $logsplit[$i];
$i++;
}
return $message;
}
/**
* Reflect user settings
*/
function refcustom() {
$this->c['LINKOFF'] = 0;
$this->c['HIDEFORM'] = 0;
$this->c['RELTYPE'] = 0;
if (!isset($this->c['SHOWIMG'])) {
$this->c['SHOWIMG'] = 0;
}
$flgcolorchanged = FALSE;
$colors = array(
'C_BACKGROUND',
'C_TEXT',
'C_A_COLOR',
'C_A_VISITED',
'C_SUBJ',
'C_QMSG',
'C_A_ACTIVE',
'C_A_HOVER',
);
$flags = array(
'GZIPU',
'RELTYPE',
'AUTOLINK',
'FOLLOWWIN',
'COOKIE',
'LINKOFF',
'HIDEFORM',
'SHOWIMG',
);
# Update from settings string
if ($this->f['c']) {
$strflag = '';
$formc = $this->f['c'];
if (strlen($formc) > 5) {
$formclen = strlen($formc);
$strflag = substr($formc, 0, 2);
$currentpos = 2;
foreach ($colors as $confname) {
$colorval = Func::base64_threebytehex(substr($formc, $currentpos, 4));
if (strlen($colorval) == 6 and strcasecmp($this->c[$confname], $colorval) != 0) {
$flgcolorchanged = TRUE;
$this->c[$confname] = $colorval;
}
$currentpos += 4;
if ($currentpos > $formclen) {
break;
}
}
}
elseif (strlen($formc) == 2) {
$strflag = $formc;
}
if ($strflag) {
$flagbin = str_pad(base_convert ($strflag, 32, 2), count($flags), "0", STR_PAD_LEFT);
$currentpos = 0;
foreach ($flags as $confname) {
$this->c[$confname] = substr($flagbin, $currentpos, 1);
$currentpos++;
}
}
}
# Update settings information
if ($this->f['m'] == 'p' or $this->f['m'] == 'c' or $this->f['m'] == 'g') {
$this->f['a'] ? $this->c['AUTOLINK'] = 1 : $this->c['AUTOLINK'] = 0;
$this->f['g'] ? $this->c['GZIPU'] = 1 : $this->c['GZIPU'] = 0;
$this->f['loff'] ? $this->c['LINKOFF'] = 1 : $this->c['LINKOFF'] = 0;
$this->f['hide'] ? $this->c['HIDEFORM'] = 1 : $this->c['HIDEFORM'] = 0;
$this->f['sim'] ? $this->c['SHOWIMG'] = 1 : $this->c['SHOWIMG'] = 0;
if ($this->f['m'] == 'c') {
$this->f['fw'] ? $this->c['FOLLOWWIN'] = 1 : $this->c['FOLLOWWIN'] = 0;
$this->f['rt'] ? $this->c['RELTYPE'] = 1 : $this->c['RELTYPE'] = 0;
$this->f['cookie'] ? $this->c['COOKIE'] = 1 : $this->c['COOKIE'] = 0;
}
}
# Special conditions
if ($this->c['BBSMODE_ADMINONLY'] != 0) {
($this->f['m'] == 'f' or ($this->f['m'] == 'p' and $this->f['write'])) ? $this->c['HIDEFORM'] = 0 : $this->c['HIDEFORM'] = 1;
}
# Update the settings string
{
$flagbin = '';
foreach ($flags as $confname) {
$this->c[$confname] ? $flagbin .= '1' : $flagbin .= '0';
}
$flagvalue = str_pad(base_convert ($flagbin, 2, 32), 2, "0", STR_PAD_LEFT);
if ($flgcolorchanged) {
$this->f['c'] = $flagvalue . substr($this->f['c'], 2);
}
else {
$this->f['c'] = $flagvalue;
}
}
}
/**
* HTTP header settings
*/
function sethttpheader() {
header('Content-Type: text/html; charset=UTF-8');
header("X-XSS-Protection: 1; mode=block");
// Remove X-Frame-Options (not needed when using CSP)
header_remove("X-Frame-Options");
// Allow embedding from anywhere
header("Content-Security-Policy: frame-ancestors *;");
}
/**
* Start execution time measurement
*/
function setstarttime() {
$this->s['START_TIME'] = microtime();
}
}
/**
* Standard bulletin board class - Bbs
*
* A bulletin board display class for PC.
* If you want to customize/extend the bulletin board function itself, inherit this class.
*
* @package strangeworld.cnscript
* @access public
*/
class Bbs extends Webapp {
/**
* Constructor
*
*/
function __construct() {
parent::__construct();
}
/**
* Main process
*/
function main() {
# Start execution time measurement
$this->setstarttime();
# Form acquisition preprocessing
$this->procForm();
# Reflect user settings
$this->refcustom();
$this->setusersession();
# gzip compression transfer
if ($this->c['GZIPU']) {
ob_start("ob_gzhandler");
}
# Prevent accidental posting when opening settings
if ($this->f['setup']) {
$this->prtcustom();
return;
}
# Post operation
if ($this->f['m'] == 'p' and trim($this->f['v'])) {
# Get environment variables
$this->setuserenv();
# Parameter check
$posterr = $this->chkmessage();
# Post operation
if (!$posterr) {
$posterr = $this->putmessage($this->getformmessage());
}
# Douple post error, etc.
if ($posterr == 1) {
$this->prtmain();
}
# Protect code redisplayed due to time lapse
elseif ($posterr == 2) {
if ($this->f['f']) {
$this->prtfollow(TRUE);
}
elseif ($this->f['write']) {
$this->prtnewpost(TRUE);
}
else {
$this->prtmain(TRUE);
}
}
# Admin mode via post is disabled
elseif ($posterr == 3) {
$this->prterror(T('ADMIN_POST_DISABLED'));
}
# Post completion page
elseif ($this->f['f']) {
$this->prtputcomplete();
}
else {
$this->prtmain();
}
}
# Display follow-up page
elseif ($this->f['m'] == 'f') {
$this->prtfollow();
}
# Post search
elseif ($this->f['m'] == 't' or $this->f['m'] == 's') {
$this->prtsearchlist();
}
# Display user settings page
elseif ($this->f['setup']) {
$this->prtcustom();
}
# User settings process
elseif ($this->f['m'] == 'c') {
$this->setcustom();
}
# New post
elseif ($this->f['m'] == 'p' and $this->f['write']) {
$this->prtnewpost();
}
# UNDO process
elseif ($this->f['m'] == 'u') {
$this->prtundo();
}
# Default: bulletin board display
else {
$this->prtmain();
}
if ($this->c['GZIPU']) {
ob_end_flush();
}
}
/**
* Display bulletin board
*
* @access public
* @param Boolean $retry Retry flag
*/
function prtmain($retry = FALSE) {
# Get display message
list ($logdatadisp, $bindex, $eindex, $lastindex) = $this->getdispmessage();
# Form section settings
$dtitle = "";
$dmsg = "";
$dlink = "";
if ($retry) {
$dtitle = $this->f['t'];
$dmsg = $this->f['v'];
$dlink = $this->f['l'];