2021-08-29 19:39:07 +02:00
< ? php
2021-10-08 20:39:33 +02:00
require 'require.php' ;
2021-08-29 19:39:07 +02:00
2021-10-12 07:30:29 +02:00
if ( $config [ 'generated_in' ] != true ) {
$start_time = false ;
}
2021-10-08 14:57:49 +02:00
if ( ! isset ( $_POST [ 'board' ])) {
//error('No board selected.');
$_POST [ 'board' ] = array_key_first ( $config [ 'boards' ]); //set a board and allow seeing bans instead:
}
2021-08-29 19:39:07 +02:00
2021-10-12 17:20:53 +02:00
//if modonly
if ( $config [ 'boards' ][ phpClean ( $_POST [ 'board' ])][ 'mod_only' ] == 1 ) {
if ( $config [ 'mod' ][ 'mod_only' ] > $mod_level ) {
error ( 'Permission denied. Authenticated staff only.' );
}
}
2021-10-07 00:23:13 +02:00
//CHECK BANS, move this to a different file maybe.
$check_ban = crypt ( $_SERVER [ 'REMOTE_ADDR' ] , $secure_hash );
$check_ban = preg_replace ( '/(\/|\.)/i' , '' , $check_ban );
2021-10-08 20:39:33 +02:00
if ( file_exists ( $path . '/' . $database_folder . '/bans/' . $check_ban )) {
2021-10-07 00:23:13 +02:00
$existing_bans = [];
2021-10-08 20:39:33 +02:00
$existing_bans = glob ( $path . '/' . $database_folder . '/bans/' . $check_ban . '/*' );
2021-10-07 00:23:13 +02:00
foreach ( $existing_bans as $bans ) {
$ban = [];
include $bans ;
//check if expired
if ( $ban [ 'is_active' ] == " 1 " ) {
if ( $ban [ 'duration' ] == 'permanent' ) {
//SHOW BAN MESSAGE
2021-10-13 23:25:38 +02:00
include $path . '/templates/banned.php' ;
echo $output_html ;
2021-10-07 00:23:13 +02:00
exit ();
}
if (( $ban [ 'time' ] + $ban [ 'duration' ]) < time ()) {
//edit file to inactive
$edit_ban = file_get_contents ( $bans );
$edit_ban = preg_replace ( '/ban\[\'is_active\'\] = "1";/i' , 'ban[\'is_active\'] = "0";' , $edit_ban );
//save as expired
file_put_contents ( $bans , $edit_ban );
2021-10-13 23:25:38 +02:00
$ban [ 'is_active' ] = " 0 " ; //remind banned.php that its no longer active
2021-10-07 00:23:13 +02:00
} else {
//this ban hasnt expired...
//SHOW BAN MESSAGE
2021-10-13 23:25:38 +02:00
include $path . '/templates/banned.php' ;
echo $output_html ;
2021-10-07 00:23:13 +02:00
exit ();
}
}
//then check if its been read
if ( $ban [ 'is_read' ] == " 0 " ) {
$edit_ban = file_get_contents ( $bans );
$edit_ban = preg_replace ( '/ban\[\'is_read\'\] = "0";/i' , 'ban[\'is_read\'] = "1";' , $edit_ban );
file_put_contents ( $bans , $edit_ban );
//SHOW BAN MESSAGE
2021-10-13 23:25:38 +02:00
include $path . '/templates/banned.php' ;
echo $output_html ;
2021-10-07 00:23:13 +02:00
exit ();
}
//cool lets continue
}
}
2021-09-20 02:24:19 +02:00
//MOD FIELDS:
if (( $config [ 'mod' ][ 'thread_sticky' ] <= $mod_level ) && isset ( $_POST [ 'sticky' ])) {
$info_sticky = 1 ;
}
if (( $config [ 'mod' ][ 'thread_lock' ] <= $mod_level ) && isset ( $_POST [ 'lock' ])) {
$info_locked = 1 ;
}
if (( $config [ 'mod' ][ 'thread_autosage' ] <= $mod_level ) && isset ( $_POST [ 'autosage' ])) {
$info_autosage = 1 ;
}
2021-08-30 05:16:23 +02:00
//POST FIELDS
2021-09-05 05:09:04 +02:00
$post_board = phpClean ( $_POST [ 'board' ]);
2021-10-12 17:20:53 +02:00
if ( isset ( $_POST [ 'name' ])) {
$post_name = phpClean ( $_POST [ 'name' ]);
} else {
$post_name = $default_name ;
}
2021-09-07 08:34:38 +02:00
2021-08-30 05:16:23 +02:00
if ( $disable_email !== true ) {
2021-09-17 22:54:49 +02:00
$post_email = phpClean ( $_POST [ 'link' ]);
2021-08-30 05:16:23 +02:00
} else {
$post_email = '' ;
}
if ( $post_email == 'sage' ) {
$_POST [ 'sage' ] = true ;
}
2021-09-02 06:11:31 +02:00
if ( $post_email == 'spoiler' || isset ( $_POST [ 'spoiler' ])) {
2021-08-31 22:50:56 +02:00
$isSpoiler_ = true ;
}
2021-09-05 11:36:39 +02:00
if ( isset ( $_POST [ 'sage' ])) { //show sage if sage, even if email = nothing or spoiler
$post_email = 'sage' ;
}
2021-12-29 21:58:32 +01:00
if ( isset ( $_POST [ 'subject' ])) {
$post_subject = phpClean ( $_POST [ 'subject' ]);
} else {
$post_subject = '' ;
}
2021-09-05 05:09:04 +02:00
$post_body = phpClean ( $_POST [ 'body' ]);
2021-08-29 19:39:07 +02:00
2021-12-27 17:58:30 +01:00
//filter zalgo from all
if ( $config [ 'filter_zalgo' ] == true ) {
$post_name = preg_replace ( " ~(?:[ \ p { M}] { 1})([ \ p { M}])~uis " , " " , $post_name );
$post_email = preg_replace ( " ~(?:[ \ p { M}] { 1})([ \ p { M}])~uis " , " " , $post_email );
$post_subject = preg_replace ( " ~(?:[ \ p { M}] { 1})([ \ p { M}])~uis " , " " , $post_subject );
$post_body = preg_replace ( " ~(?:[ \ p { M}] { 1})([ \ p { M}])~uis " , " " , $post_body );
}
2021-08-31 08:11:58 +02:00
2021-09-05 06:11:16 +02:00
//CHECK SOME REQS BEFORE BODY EDIT, length. Check newlines after by scanning <br>'s
//IF NEW REPLY
if ( isset ( $_POST [ 'thread' ])) {
//get thread info
2021-10-11 18:57:26 +02:00
$post_thread_number = phpClean ( $_POST [ 'thread_number' ]);
if ( ! is_numeric ( $post_thread_number )) {
error ( 'Invalid thread number.' );
}
2021-10-08 20:39:33 +02:00
include ( $path . '/' . $database_folder . '/boards/' . $post_board . '/' . phpClean ( $_POST [ 'thread_number' ]) . " /info.php " );
2021-10-09 18:13:14 +02:00
if (( $info_locked == 1 ) && ( $config [ 'mod' ][ 'post_in_locked' ] > $mod_level )) {
2021-09-05 06:11:16 +02:00
error ( 'This thread is locked...' );
}
if ( ! isset ( $_FILES [ 'file' ]) || $_FILES [ 'file' ][ 'error' ] == UPLOAD_ERR_NO_FILE ) {
if ( strlen ( $post_body ) < $config [ 'reply_body_min' ]) {
error ( 'Reply too short. Min: 10.' );
}
} else {
if ( $config [ 'reply_file_only' ] == false ) {
if ( strlen ( $post_body ) < $config [ 'reply_body_min' ]) {
error ( 'Reply too short. Min: 10.' );
}
}
}
if ( strlen ( $post_body ) > $config [ 'reply_body_max' ]) {
error ( 'Reply too long. Max: 4000.' );
}
}
//WORDFILTERS, CITATIONS, ETC.
if ( $post_body != '' ) {
2021-09-05 07:54:44 +02:00
//citations (probably gonna be a pain to fix dead links later?)
//todo
2021-10-11 18:57:26 +02:00
//VERY TEMPORARY REPLY-FUNCTION
if ( isset ( $_POST [ 'thread' ])) {
$post_body = preg_replace ( " />>([0-9]+)/ " , " <a class='quotelink' href=' " . $prefix_folder . '/' . $main_file . '?board=' . $post_board . '&thread=' . $post_thread_number . " # $ 1'> $ 0</a> " , $post_body );
}
if ( $config [ 'linkify_urls' ] == true ) {
2022-01-06 00:34:33 +01:00
$post_body = preg_replace ( " /((https?|ftp): \ / \ /( \ S*? \ . \ S*?))([ \ s) \ [ \ ] { },; \" \ ':<]| \ . \ s| $ )/i " , " <a class='post-link' href=' $ 0' target='_blank' rel='noopener noreferrer nofollow'> $ 0</a> " , $post_body );
2021-10-11 18:57:26 +02:00
}
2021-09-05 06:11:16 +02:00
//add quotes
$post_body = preg_replace ( " /^ \ s*>.* $ /m " , " <span class='quote'> $ 0</span> " , $post_body );
//add replyquotes
$post_body = preg_replace ( " /^ \ s*<.* $ /m " , " <span class='rquote'> $ 0</span> " , $post_body );
2021-09-05 07:54:44 +02:00
//AsciiArt [aa]
2021-10-11 18:57:26 +02:00
$post_body = preg_replace ( " / \ [aa \ ](.+?) \ [ \ /aa \ ]/ms " , " <span class='aa'> $ 1</span> " , $post_body );
2021-09-05 07:54:44 +02:00
//Code [code]
2021-10-11 18:57:26 +02:00
$post_body = preg_replace ( " / \ [code \ ](.+?) \ [ \ /code \ ]/ms " , " <div class='code'> $ 1</div> " , $post_body );
2021-09-05 07:54:44 +02:00
//Spoilers
2021-10-11 18:57:26 +02:00
$post_body = preg_replace ( " / \ [spoiler \ ](.+?) \ [ \ /spoiler \ ]/ms " , " <span class='spoiler'> $ 1</span> " , $post_body );
2021-09-05 07:54:44 +02:00
2021-09-05 06:11:16 +02:00
//remove newlines from start and end of string
$post_body = ltrim ( $post_body ); //start
$post_body = rtrim ( $post_body ); //end
//add newlines
$post_body = preg_replace ( '/\n/i' , '<br>' , $post_body );
//WORDFILTERS
foreach ( $config [ 'wordfilters' ] as $key => $wordfilter ) {
$post_body = preg_replace ( $wordfilter [ 0 ], $wordfilter [ 1 ], $post_body );
}
2021-08-31 08:11:58 +02:00
}
2021-09-05 06:11:16 +02:00
2021-08-29 19:39:07 +02:00
//Requirements met?
2021-09-05 06:11:16 +02:00
//max lines?
if ( preg_match_all ( '/<br>/' , $post_body ) > $config [ 'max_lines' ]) {
error ( 'Too many new lines. Max 40.' );
}
2021-08-29 19:39:07 +02:00
if ( $captcha_required == true ) {
if ( isset ( $_POST [ 'captcha' ])){
session_start ();
if (( $captcha_required == true ) && ( $_SESSION [ 'captcha_text' ] != strtolower ( $_POST [ 'captcha' ]))) {
error ( 'Wrong captcha!! How annoying...' );
} else {
session_destroy ();
}
} else {
error ( 'No captcha entered.' );
}
}
if ( $post_name === '' ) {
2021-08-30 05:16:23 +02:00
$post_name = $default_name ;
2021-08-29 19:39:07 +02:00
}
if ( strlen ( $post_name ) > 256 ) {
error ( 'Name too long. Max 256.' );
}
2021-10-08 22:46:11 +02:00
2021-10-12 17:20:53 +02:00
//if mod only board, show username and modlevel.
if ( $config [ 'boards' ][ phpClean ( $_POST [ 'board' ])][ 'mod_only' ] == 1 ) {
$post_name = $logged_in_user ;
$_POST [ 'mod_level' ] = true ;
}
2021-10-08 22:46:11 +02:00
//add extra stuff to name:
if ( $post_email == 'showlevel' || isset ( $_POST [ 'mod_level' ])) {
$post_email = '' ;
if ( $config [ 'mod' ][ 'public_mod_level' ] <= $mod_level ) {
switch ( $mod_level ) {
case 9001 :
$post_name .= ' <span class=\"modlevel admin\">## Admin</span>' ;
break ;
case 40 :
$post_name .= ' <span class=\"modlevel mod\">## Moderator</span>' ; //default configuration has moderator as minimum requirement to use this function.
break ;
case 10 :
$post_name .= ' <span class=\"modlevel janitor\">## Janitor</span>' ;
break ;
case 0 :
$post_name .= ' <span class=\"modlevel user\">## User</span>' ;
break ;
}
}
}
2021-08-29 19:39:07 +02:00
if ( strlen ( $post_email ) > 256 ) {
error ( 'Email too long. Max 256.' );
}
if ( strlen ( $post_subject ) > 256 ) {
error ( 'Subject too long. Max 256.' );
}
2021-09-17 22:54:49 +02:00
if ( strlen ( $post_password ) > 256 ) {
error ( 'Password too long. Max 256.' );
}
2021-08-29 19:39:07 +02:00
//IF NEW THREAD
if ( isset ( $_POST [ 'index' ])) {
if ( strlen ( $post_body ) > $config [ 'post_body_max' ]) {
error ( 'Post too long. Max: 4000.' );
}
if ( strlen ( $post_body ) < $config [ 'post_body_min' ]) {
error ( 'Comment too short. Min: 10.' );
}
}
//ARE WE POSTING?
if (( isset ( $post_board )) && ( isset ( $_POST [ 'index' ]))) {
//SHOULD IT EXIST?
if ( ! isset ( $config [ 'boards' ][ $post_board ])) {
error ( 'This board shouldn\'t exist...' );
}
//IF NOT EXIST, CREATE DIRECTORY
2021-10-08 20:39:33 +02:00
if ( ! file_exists ( $path . '/' . $database_folder . '/boards' )) {
mkdir ( $path . '/' . $database_folder . '/boards' , 0755 , true );
2021-08-31 08:11:58 +02:00
}
2021-10-08 20:39:33 +02:00
if (( ! file_exists ( $path . '/' . $database_folder . '/boards/' . $post_board ) && ( isset ( $config [ 'boards' ][ $post_board ])) === true )) {
mkdir ( $path . '/' . $database_folder . '/boards/' . $post_board , 0755 , true );
2021-08-29 19:39:07 +02:00
}
2021-09-02 09:52:04 +02:00
if ( $config [ 'boards' ][ $post_board ][ 'locked' ] == 1 ) {
error ( 'This board is locked. Sneaky.' );
}
2021-08-29 19:39:07 +02:00
//IS THIS OUR FIRST THREAD?
// if no file in folder
2021-10-08 20:39:33 +02:00
if ( dir_is_empty ( $path . '/' . $database_folder . '/boards/' . $post_board )) {
file_put_contents ( $path . '/' . $database_folder . '/boards/' . $post_board . '/counter.php' , 1 ); //create post count
2021-08-29 19:39:07 +02:00
}
//CREATE THREAD FOLDER
2021-10-08 20:39:33 +02:00
$counter = file_get_contents ( $path . '/' . $database_folder . '/boards/' . $post_board . '/counter.php' );
2021-08-31 08:11:58 +02:00
//CHECK FOR AND HANDLE FILES
2021-10-08 20:39:33 +02:00
include $path . '/includes/filehandler.php' ;
2021-08-29 19:39:07 +02:00
$current_count = $counter ;
2021-10-08 20:39:33 +02:00
mkdir ( $path . '/' . $database_folder . '/boards/' . $post_board . '/' . $current_count , 0755 , true ); //create thread folder
2021-08-29 19:39:07 +02:00
//COLLECT POST INFORMATION
$create_OP = '<?php $op_name = "' . $post_name . '";' ;
$create_OP .= '$op_email = "' . $post_email . '";' ;
$create_OP .= '$op_subject = "' . $post_subject . '";' ;
$create_OP .= '$op_body = "' . $post_body . '";' ;
2021-08-30 06:57:43 +02:00
$create_OP .= '$op_password = "' . $post_password . '";' ;
2021-08-31 22:50:56 +02:00
2021-09-02 06:11:31 +02:00
$create_OP .= '$op_file = array( array("' . $file_type . '","' . $new_filename . '","' . $original_filename . '","' . $upload_resolution . '","' . $filesize_ . '","' . $isSpoiler_ . '", "' . $new_thumbname . '","' . $thmb_res . '") );' ; //array in array to prepare for multifiles later, easy upgrade i guess
2021-08-31 22:50:56 +02:00
2021-08-30 09:06:39 +02:00
$create_OP .= '$op_ip = "' . crypt ( $_SERVER [ 'REMOTE_ADDR' ] , $secure_hash ) . '";' ;
2021-08-29 19:39:07 +02:00
$create_OP .= '$op_time = "' . time () . '"; ?>' ;
//SAVE POST INFORMATION
$current_count = $counter ;
2021-10-08 20:39:33 +02:00
file_put_contents ( $path . '/' . $database_folder . '/boards/' . $post_board . '/' . $current_count . '/OP.php' , $create_OP );
2021-08-29 19:39:07 +02:00
//INCREMENT COUNTER
2021-10-08 20:39:33 +02:00
$counter = file_get_contents ( $path . '/' . $database_folder . '/boards/' . $post_board . '/counter.php' );
2021-08-29 19:39:07 +02:00
$newcount = $counter + 1 ;
2021-10-08 20:39:33 +02:00
file_put_contents ( $path . '/' . $database_folder . '/boards/' . $post_board . '/counter.php' , $newcount );
2021-08-29 19:39:07 +02:00
2021-08-31 14:14:54 +02:00
//
2021-09-08 15:19:51 +02:00
UpdateOP ( $database_folder , $post_board , $current_count , 1 , 0 , $current_count , 1 , $info_sticky , $info_locked , $info_autosage ); //information about thread and replies
2021-09-07 15:40:49 +02:00
UpdateThreads ( $database_folder , $post_board , $current_count ); //update recents.php and board bumps.
UpdateRecents ( $database_folder , $post_board , $current_count , $recent_replies );
2021-10-08 20:39:33 +02:00
include $path . '/includes/update-frontpage.php' ;
2021-10-12 07:30:29 +02:00
PostSuccess ( $prefix_folder . $main_file . '/?board=' . $post_board . '&thread=' . $counter . '#' . $counter , true , $start_time );
2021-08-31 14:14:54 +02:00
2021-08-29 19:39:07 +02:00
}
if (( isset ( $post_board )) && ( isset ( $_POST [ 'thread' ]))) {
2021-09-05 05:09:04 +02:00
$post_is_thread = phpClean ( $_POST [ 'thread' ]);
$post_thread_number = phpClean ( $_POST [ 'thread_number' ]);
2021-10-11 18:57:26 +02:00
if ( ! is_numeric ( $post_thread_number )) {
error ( 'Invalid thread number.' );
}
2021-08-29 19:39:07 +02:00
//board exists?
if ( ! isset ( $config [ 'boards' ][ $post_board ])) {
error ( 'This board shouldn\'t exist...' );
}
//thread exists?
2021-10-08 20:39:33 +02:00
if (( $post_is_thread == 'thread' ) && ( file_exists ( $path . '/' . $database_folder . '/boards/' . $post_board . '/' . $post_thread_number . '/OP.php' ))) {
2021-08-29 19:39:07 +02:00
//THREAD EXISTS
2021-08-31 08:11:58 +02:00
2021-08-29 19:39:07 +02:00
//CREATE/INCREASE COUNTER+LAST BUMPED. to do: (reset bump on post deletion by user or mod, do elsewhere)
2021-10-08 20:39:33 +02:00
$counter = file_get_contents ( $path . '/' . $database_folder . '/boards/' . $post_board . '/counter.php' );
2021-08-31 08:11:58 +02:00
//CHECK FOR AND HANDLE FILES
2021-10-08 20:39:33 +02:00
include $path . '/includes/filehandler.php' ;
2021-08-29 19:39:07 +02:00
$newcount = $counter + 1 ;
//save it as last bumped if not sage tho
2021-09-08 15:19:51 +02:00
if ( ! isset ( $_POST [ 'sage' ]) && $info_autosage == 0 ) {
2021-10-08 20:39:33 +02:00
file_put_contents ( $path . '/' . $database_folder . '/boards/' . $post_board . '/' . $post_thread_number . '/bumped.php' , $counter );
2021-08-29 19:39:07 +02:00
}
//save it as last post number
2021-10-08 20:39:33 +02:00
file_put_contents ( $path . '/' . $database_folder . '/boards/' . $post_board . '/counter.php' , $newcount );
2021-08-29 19:39:07 +02:00
//counter handled... moving on:
//POST STUFF
//COLLECT POST INFORMATION
$create_reply = '<?php $reply_name = "' . $post_name . '";' ;
$create_reply .= '$reply_email = "' . $post_email . '";' ;
$create_reply .= '$reply_subject = "' . $post_subject . '";' ;
$create_reply .= '$reply_body = "' . $post_body . '";' ;
2021-08-30 06:57:43 +02:00
$create_reply .= '$reply_password = "' . $post_password . '";' ;
2021-08-31 22:50:56 +02:00
2021-09-02 06:11:31 +02:00
$create_reply .= '$reply_file = array( array("' . $file_type . '","' . $new_filename . '","' . $original_filename . '","' . $upload_resolution . '","' . $filesize_ . '","' . $isSpoiler_ . '", "' . $new_thumbname . '","' . $thmb_res . '") );' ; //array in array to prepare for multifiles later, easy upgrade i guess
2021-08-31 22:50:56 +02:00
2021-08-30 09:06:39 +02:00
$create_reply .= '$reply_ip = "' . crypt ( $_SERVER [ 'REMOTE_ADDR' ] , $secure_hash ) . '";' ;
2021-08-29 19:39:07 +02:00
$create_reply .= '$reply_time = "' . time () . '"; ?>' ;
//SAVE POST INFORMATION
$current_count = $counter ;
2021-10-08 20:39:33 +02:00
file_put_contents ( $path . '/' . $database_folder . '/boards/' . $post_board . '/' . $post_thread_number . '/' . $current_count . '.php' , $create_reply );
2021-08-31 08:11:58 +02:00
2021-08-31 14:14:54 +02:00
//how many replies do we have?
//FIND REPLIES
$replies_ = [];
2021-10-08 20:39:33 +02:00
$replies_ = glob ( $path . '/' . $database_folder . '/boards/' . $post_board . '/' . $post_thread_number . " /* " );
2021-08-31 14:14:54 +02:00
$reply_counter = 0 ;
foreach ( $replies_ as $reply ) {
2021-09-07 12:22:43 +02:00
if ( is_numeric ( basename ( $reply , '.php' ))) {
2021-08-31 14:14:54 +02:00
$reply_counter += 1 ;
}
}
//how many unique posters do we have?
$ip_counter = 1 ;
$ips_ = [];
//Get OP IP
2021-10-08 20:39:33 +02:00
include ( $path . '/' . $database_folder . '/boards/' . $post_board . '/' . $post_thread_number . " /OP.php " );
2021-08-31 14:14:54 +02:00
$ips_ = [];
$ips_ [] = $op_ip ;
//Get replies ips
foreach ( $replies_ as $reply ) {
include ( $reply );
$ips_ [] = $reply_ip ;
}
$ip_counter = count ( array_unique ( $ips_ ));
2021-09-08 15:19:51 +02:00
UpdateOP ( $database_folder , $post_board , $post_thread_number , 0 , $reply_counter , $current_count , $ip_counter , $info_sticky , $info_locked , $info_autosage );
UpdateThreads ( $database_folder , $post_board , $current_count ); //update recents.php and board bumps.
2021-09-07 15:40:49 +02:00
UpdateRecents ( $database_folder , $post_board , $post_thread_number , $recent_replies ); //update recents.php and board bumps.
2021-10-08 20:39:33 +02:00
include $path . '/includes/update-frontpage.php' ;
2021-10-12 07:30:29 +02:00
PostSuccess ( $prefix_folder . $main_file . '/?board=' . $post_board . '&thread=' . $post_thread_number . '#' . $current_count , true , $start_time );
2021-08-31 14:14:54 +02:00
2021-08-29 19:39:07 +02:00
}
}
2021-08-31 14:14:54 +02:00
error ( 'This shouldn\'t happen..' );
2021-10-12 18:55:14 +02:00
?>