From 0385f465338ffa3fbcc10056c887b8c236c2533b Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Wed, 1 Dec 2010 21:53:11 +1100 Subject: created mod.php --- mod.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 mod.php (limited to 'mod.php') diff --git a/mod.php b/mod.php new file mode 100644 index 00000000..a2b2ef66 --- /dev/null +++ b/mod.php @@ -0,0 +1,42 @@ + + -- cgit v1.3 From 760ccab6355226bfc26a1aa39c267063cd439212 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Wed, 1 Dec 2010 23:25:39 +1100 Subject: Removed some code. --- inc/instance-config.php | 12 ++++++------ mod.php | 3 +-- 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'mod.php') diff --git a/inc/instance-config.php b/inc/instance-config.php index 1c433a9c..408e9b85 100644 --- a/inc/instance-config.php +++ b/inc/instance-config.php @@ -9,15 +9,15 @@ */ - + /* // Database stuff define('MY_SERVER', '127.0.0.1'); - define('MY_USER', 'imgboard'); - define('MY_PASSWORD', 'DF3uHz4vvhUM6rCq'); - define('MY_DATABASE', 'imgboard'); + define('MY_USER', ''); + define('MY_PASSWORD', ''); + define('MY_DATABASE', ''); - define('ROOT', '/board/'); + define('ROOT', '/'); // define('FOO', 'bar'); - + */ ?> \ No newline at end of file diff --git a/mod.php b/mod.php index a2b2ef66..af7e0844 100644 --- a/mod.php +++ b/mod.php @@ -34,8 +34,7 @@ loginForm(); } } else { - var_dump($_COOKIE); - openBoard('b'); + // The rest is not done yet... echo buildThread(1, true); } ?> -- cgit v1.3 From c2859e862ce068d2d1a0d0ba6dfdd9c81636b6e6 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Wed, 1 Dec 2010 23:41:48 +1100 Subject: Removed debugging code. --- inc/instance-config.php | 10 +++++----- mod.php | 1 - 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'mod.php') diff --git a/inc/instance-config.php b/inc/instance-config.php index 408e9b85..e372c8ef 100644 --- a/inc/instance-config.php +++ b/inc/instance-config.php @@ -9,15 +9,15 @@ */ - /* + // Database stuff define('MY_SERVER', '127.0.0.1'); - define('MY_USER', ''); - define('MY_PASSWORD', ''); - define('MY_DATABASE', ''); + define('MY_USER', 'imgboard'); + define('MY_PASSWORD', 'DF3uHz4vvhUM6rCq'); + define('MY_DATABASE', 'imgboard'); define('ROOT', '/'); // define('FOO', 'bar'); - */ + ?> \ No newline at end of file diff --git a/mod.php b/mod.php index af7e0844..bee64011 100644 --- a/mod.php +++ b/mod.php @@ -35,7 +35,6 @@ } } else { // The rest is not done yet... - echo buildThread(1, true); } ?> -- cgit v1.3 From 162fcff691f8bd4a14e1985131af3a1fd52a7ff9 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Thu, 2 Dec 2010 01:17:27 +1100 Subject: Added basis for query handling. --- mod.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'mod.php') diff --git a/mod.php b/mod.php index bee64011..462f6797 100644 --- a/mod.php +++ b/mod.php @@ -34,6 +34,22 @@ loginForm(); } } else { + $query = $_SERVER['QUERY_STRING']; + $regex = Array( + 'board' => str_replace('%s', '\w{1,8}', preg_quote(BOARD_PATH, '/')) + ); + + // Dashboard + if(preg_match('/^\/?$/', $query)) { + + + // Board index + } elseif(preg_match('/^\/' . $regex['board'] . '(' . preg_quote(FILE_INDEX, '/') . ')?$/', $query)) { + + + } else { + error("Page not found."); + } // The rest is not done yet... } ?> -- cgit v1.3 From c327056f13a8eabd22aae178a3ce1c962b5a044c Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Thu, 2 Dec 2010 18:02:48 +1100 Subject: Page handling --- mod.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'mod.php') diff --git a/mod.php b/mod.php index 462f6797..8a328092 100644 --- a/mod.php +++ b/mod.php @@ -9,7 +9,7 @@ require 'inc/user.php'; // If not logged in - if(!$user) { + if(!$mod) { if(isset($_POST['login'])) { // Check if inputs are set and not empty if( !isset($_POST['username']) || @@ -28,6 +28,9 @@ // Set cookies setCookies(); + // Redirect + header('Location: ?' . MOD_DEFAULT, true, 302); + // Close connection sql_close(); } else { @@ -36,21 +39,25 @@ } else { $query = $_SERVER['QUERY_STRING']; $regex = Array( - 'board' => str_replace('%s', '\w{1,8}', preg_quote(BOARD_PATH, '/')) + 'board' => str_replace('%s', '(\w{1,8})', preg_quote(BOARD_PATH, '/')) ); - // Dashboard if(preg_match('/^\/?$/', $query)) { + // Dashboard + + } elseif(preg_match('/^\/' . $regex['board'] . '(' . preg_quote(FILE_INDEX, '/') . ')?$/', $query, $matches)) { + // Board index - // Board index - } elseif(preg_match('/^\/' . $regex['board'] . '(' . preg_quote(FILE_INDEX, '/') . ')?$/', $query)) { + $boardName = $matches[1]; + // Open board + openBoard($boardName); + echo Element('index.html', index(1)); } else { - error("Page not found."); + error("Page not found."); } - // The rest is not done yet... } ?> -- cgit v1.3 From b2bd3303f96167bbc3812b01e386e3b1c5252eef Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Thu, 2 Dec 2010 18:07:24 +1100 Subject: REDIRECT_HTTP directive --- inc/config.php | 5 +++++ inc/functions.php | 1 + mod.php | 2 +- post.php | 4 ++-- res/index.php | 2 +- src/index.php | 2 +- thumb/index.php | 2 +- 7 files changed, 12 insertions(+), 6 deletions(-) (limited to 'mod.php') diff --git a/inc/config.php b/inc/config.php index 0ca457c4..164c1f1a 100644 --- a/inc/config.php +++ b/inc/config.php @@ -119,6 +119,11 @@ // Multi-board (%s is board abbreviation) define('BOARD_PATH', '%s/', true); + // The HTTP status code to use when redirecting. + // Should be 3xx (redirection). http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html + // "302" is recommended. + define('REDIRECT_HTTP', 302, true); + /* Mod stuff */ diff --git a/inc/functions.php b/inc/functions.php index b20ed091..2349197c 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -44,6 +44,7 @@ function openBoard($uri) { global $sql; + sql_open(); $boards_res = mysql_query(sprintf( "SELECT * FROM `boards` WHERE `uri` = '%s' LIMIT 1", mysql_real_escape_string($uri) diff --git a/mod.php b/mod.php index 8a328092..44aada37 100644 --- a/mod.php +++ b/mod.php @@ -29,7 +29,7 @@ setCookies(); // Redirect - header('Location: ?' . MOD_DEFAULT, true, 302); + header('Location: ?' . MOD_DEFAULT, true, REDIRECT_HTTP); // Close connection sql_close(); diff --git a/post.php b/post.php index 8653a2c3..78d1fd60 100644 --- a/post.php +++ b/post.php @@ -306,9 +306,9 @@ sql_close(); if(ALWAYS_NOKO || $noko) { - header('Location: ' . ROOT . $board['dir'] . DIR_RES . ($OP?$id:$post['thread']) . '.html' . (!$OP?'#'.$id:''), true, 302); + header('Location: ' . ROOT . $board['dir'] . DIR_RES . ($OP?$id:$post['thread']) . '.html' . (!$OP?'#'.$id:''), true, REDIRECT_HTTP); } else { - header('Location: ' . ROOT . $board['dir'] . FILE_INDEX, true, 302); + header('Location: ' . ROOT . $board['dir'] . FILE_INDEX, true, REDIRECT_HTTP); } exit; diff --git a/res/index.php b/res/index.php index c5619a58..1869b1dd 100644 --- a/res/index.php +++ b/res/index.php @@ -1,3 +1,3 @@ \ No newline at end of file diff --git a/src/index.php b/src/index.php index c5619a58..1869b1dd 100644 --- a/src/index.php +++ b/src/index.php @@ -1,3 +1,3 @@ \ No newline at end of file diff --git a/thumb/index.php b/thumb/index.php index c5619a58..1869b1dd 100644 --- a/thumb/index.php +++ b/thumb/index.php @@ -1,3 +1,3 @@ \ No newline at end of file -- cgit v1.3 From bbb791039821637c045b2378383b0eb167063a27 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Thu, 2 Dec 2010 18:26:09 +1100 Subject: Created basis for mod dashboard --- inc/mod.php | 25 +++++++++++++++++++++++++ mod.php | 18 +++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 inc/mod.php (limited to 'mod.php') diff --git a/inc/mod.php b/inc/mod.php new file mode 100644 index 00000000..00f94544 --- /dev/null +++ b/inc/mod.php @@ -0,0 +1,25 @@ + element with a list of linked + // boards and their subtitles. + function ulBoards() { + $body = ''; + } + +?> \ No newline at end of file diff --git a/mod.php b/mod.php index 44aada37..cbcddfb1 100644 --- a/mod.php +++ b/mod.php @@ -7,6 +7,7 @@ require 'inc/config.php'; require 'inc/template.php'; require 'inc/user.php'; + require 'inc/mod.php'; // If not logged in if(!$mod) { @@ -45,7 +46,19 @@ if(preg_match('/^\/?$/', $query)) { // Dashboard - + // Body + $body = ''; + + $body .= '
Boards' . + ulBoards() . + '
'; + + die(Element('page.html', Array( + 'index'=>ROOT, + 'title'=>'Dashboard', + 'body'=>$body + ) + )); } elseif(preg_match('/^\/' . $regex['board'] . '(' . preg_quote(FILE_INDEX, '/') . ')?$/', $query, $matches)) { // Board index @@ -59,5 +72,8 @@ error("Page not found."); } } + + // Close the connection in-case it's still open + sql_close(); ?> -- cgit v1.3 From cb0912754f826e468b32c178e1abc7739463c494 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Thu, 2 Dec 2010 20:55:56 +1100 Subject: "Create board" page --- inc/config.php | 9 +++- inc/mod.php | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- inc/user.php | 87 -------------------------------------- mod.php | 73 +++++++++++++++++++++++++++++--- 4 files changed, 201 insertions(+), 98 deletions(-) (limited to 'mod.php') diff --git a/inc/config.php b/inc/config.php index 164c1f1a..3bb24b85 100644 --- a/inc/config.php +++ b/inc/config.php @@ -67,6 +67,9 @@ define('ERROR_INVALID', 'Invalid username and/or password.', true); define('ERROR_INVALIDAFTER', 'Invalid username and/or password. Your user may have been deleted or changed.'); define('ERROR_MALFORMED','Invalid/malformed cookies.', true); + define('ERROR_MISSEDAFIELD', 'Your browser didn\'t submit an input when it should have.', true); + define('ERROR_REQUIRED', 'The %s field is required.', true); + define('ERROR_INVALIDFIELD', 'The %s field was invalid.', true); // For resizing, max values define('THUMB_WIDTH', 200, true); @@ -132,6 +135,10 @@ // The page that is first shown when a moderator logs in. Defaults to the dashboard. define('MOD_DEFAULT', '/', true); + define('MOD_JANITOR', 0, true); + define('MOD_MOD', 1, true); + define('MOD_ADMIN', 2, true); + // A small file in the main directory indicating that the script has been ran and the board(s) have been generated. // This keeps the script from querying the database and causing strain when not needed. define('HAS_INSTALLED', '.installed', true); @@ -139,7 +146,7 @@ // Name of the boards. Typically '/%s/' (/b/, /mu/, etc) // BOARD_ABBREVIATION - BOARD_TITLE define('BOARD_ABBREVIATION', '/%s/', true); - + // Automatically convert things like "..." to Unicode characters ("…") define('AUTO_UNICODE', true, true); // Use some Wiki-like syntax (''em'', '''strong''', ==Heading==, etc) diff --git a/inc/mod.php b/inc/mod.php index 00f94544..83e4cfdf 100644 --- a/inc/mod.php +++ b/inc/mod.php @@ -1,8 +1,96 @@ - $user['id'], + 'type' => $user['type'], + 'username' => $username, + 'password' => $password, + 'hash' => isset($_SESSION['mod']['hash']) ? $_SESSION['mod']['hash'] : mkhash() + ); + } else return false; + } + + function setCookies() { + global $mod; + if(!$mod) error('setCookies() was called for a non-moderator!'); + + // MOD_COOKIE contains username:hash + setcookie(MOD_COOKIE, $mod['username'] . ':' . $mod['hash'], time()+COOKIE_EXPIRE, JAIL_COOKIES?ROOT:'/', null, false, true); + + // Put $mod in the session + $_SESSION['mod'] = $mod; + + // Lock sessions to IP addresses + if(MOD_LOCK_IP) + $_SESSION['mod']['ip'] = $_SERVER['REMOTE_ADDR']; + } + + function destroyCookies() { + // Delete the cookies + setcookie(MOD_COOKIE, 'deleted', time()-COOKIE_EXPIRE, JAIL_COOKIES?ROOT:'/', null, false, true); + + // Unset the session + unset($_SESSION['mod']); + } + + if(isset($_COOKIE['mod']) && isset($_SESSION['mod']) && is_array($_SESSION['mod'])) { + // Should be username:session hash + $cookie = explode(':', $_COOKIE['mod']); + if(count($cookie) != 2) { + destroyCookies(); + error(ERROR_MALFORMED); + } + + // Validate session + if( $cookie[0] != $_SESSION['mod']['username'] || + $cookie[1] != $_SESSION['mod']['hash']) { + // Malformed cookies + destroyCookies(); + error(ERROR_MALFORMED); + } + + // Open connection + sql_open(); + + // Check username/password + if(!login($_SESSION['mod']['username'], $_SESSION['mod']['password'], false)) { + destroyCookies(); + error(ERROR_INVALIDAFTER); + } + + } + // Generates a
    element with a list of linked // boards and their subtitles. function ulBoards() { + global $mod; + $body = '
      '; // List of boards @@ -14,12 +102,44 @@ sprintf(BOARD_PATH, $b['uri']) . FILE_INDEX . '">' . sprintf(BOARD_ABBREVIATION, $b['uri']) . - '' . - (isset($b['subtitle']) ? ' - ' . $b['subtitle'] : '') . + ' - ' . + $b['title'] . + (isset($b['subtitle']) ? ' — ' . $b['subtitle'] . '' : '') . ''; } + if($mod['type'] == MOD_ADMIN) { + $body .= '
    • Create new board
    • '; + } return $body . '
    '; } - + + function form_newBoard() { + return '
    New board' . + '
    ' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '
    ' . + ' (eg. "b"; "mu")' . + '
    ' . + ' (eg. "Random")' . + '
    ' . + ' (optional)' . + '
    ' . + '
    ' . + '
    '; + } + ?> \ No newline at end of file diff --git a/inc/user.php b/inc/user.php index 05deb0e3..126777bd 100644 --- a/inc/user.php +++ b/inc/user.php @@ -21,91 +21,4 @@ $user = Array('valid' => true, 'appeared' => $_COOKIE[TIME_COOKIE]); } - // 'false' means that the user is not logged in as a moderator - $mod = false; - - // Creates a small random string for validating moderators' cookies - function mkhash($length=12) { - // The method here isn't really important, - // but I think this generates a relatively - // unique string that looks cool. - // If you choose to change this, make sure it cannot include a ':' character. - return substr(base64_encode(sha1(rand() . time(), true)), 0, $length); - } - - function login($username, $password, $makehash=true) { - global $sql, $mod; - - // SHA1 password - if($makehash) { - $password = sha1($password); - } - - $res = mysql_query(sprintf( - "SELECT `id`,`type` FROM `mods` WHERE `username` = '%s' AND `password` = '%s' LIMIT 1", - mysql_real_escape_string($username), - $password - ), $sql) or error(mysql_error($sql)); - - if($user = mysql_fetch_array($res)) { - return $mod = Array( - 'id' => $user['id'], - 'type' => $user['type'], - 'username' => $username, - 'password' => $password, - 'hash' => mkhash() - ); - } else return false; - } - - function setCookies() { - global $mod; - if(!$mod) error('setCookies() was called for a non-moderator!'); - - // MOD_COOKIE contains username:hash - setcookie(MOD_COOKIE, $mod['username'] . ':' . $mod['hash'], time()+COOKIE_EXPIRE, JAIL_COOKIES?ROOT:'/', null, false, true); - - // Put $mod in the session - $_SESSION['mod'] = $mod; - - // Lock sessions to IP addresses - if(MOD_LOCK_IP) - $_SESSION['mod']['ip'] = $_SERVER['REMOTE_ADDR']; - } - - function destroyCookies() { - // Delete the cookies - setcookie(MOD_COOKIE, 'deleted', time()-COOKIE_EXPIRE, JAIL_COOKIES?ROOT:'/', null, false, true); - - // Unset the session - unset($_SESSION['mod']); - } - - if(isset($_COOKIE['mod']) && isset($_SESSION['mod']) && is_array($_SESSION['mod'])) { - // Should be username:session hash - $cookie = explode(':', $_COOKIE['mod']); - if(count($cookie) != 2) { - destroyCookies(); - error(ERROR_MALFORMED); - } - - // Validate session - if( $cookie[0] != $_SESSION['mod']['username'] || - $cookie[1] != $_SESSION['mod']['hash']) { - // Malformed cookies - destroyCookies(); - error(ERROR_MALFORMED); - } - - // Open connection - sql_open(); - - // Check username/password - if(!login($_SESSION['mod']['username'], $_SESSION['mod']['password'], false)) { - destroyCookies(); - error(ERROR_INVALIDAFTER); - } - - $mod = $_SESSION['mod']; - } ?> \ No newline at end of file diff --git a/mod.php b/mod.php index cbcddfb1..3390d180 100644 --- a/mod.php +++ b/mod.php @@ -38,27 +38,90 @@ loginForm(); } } else { - $query = $_SERVER['QUERY_STRING']; + $query = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : ''; $regex = Array( 'board' => str_replace('%s', '(\w{1,8})', preg_quote(BOARD_PATH, '/')) ); if(preg_match('/^\/?$/', $query)) { // Dashboard - - // Body $body = ''; $body .= '
    Boards' . ulBoards() . '
    '; - die(Element('page.html', Array( + // TODO: Statistics, etc, in the dashboard. + + echo Element('page.html', Array( 'index'=>ROOT, 'title'=>'Dashboard', 'body'=>$body ) - )); + ); + } elseif(preg_match('/^\/new$/', $query)) { + // New board + $body = ''; + + if(isset($_POST['new_board'])) { + // Create new board + if( !isset($_POST['uri']) || + !isset($_POST['title']) || + !isset($_POST['subtitle']) + ) error(ERROR_MISSEDAFIELD); + + $b = Array( + 'uri' => $_POST['uri'], + 'title' => $_POST['title'], + 'subtitle' => $_POST['subtitle'] + ); + + // Check required fields + if(empty($b['uri'])) + error(sprintf(ERROR_REQUIRED, 'URI')); + if(empty($b['title'])) + error(sprintf(ERROR_REQUIRED, 'title')); + + // Check string lengths + if(strlen($b['uri']) > 8) + error(sprintf(ERROR_TOOLONG, 'URI')); + if(strlen($b['title']) > 20) + error(sprintf(ERROR_TOOLONG, 'title')); + if(strlen($b['subtitle']) > 40) + error(sprintf(ERROR_TOOLONG, 'subtitle')); + + if(!preg_match('/^\w+$/', $b['uri'])) + error(sprintf(ERROR_INVALIDFIELD, 'URI')); + + mysql_query(sprintf( + "INSERT INTO `boards` VALUES (NULL, '%s', '%s', " . + (empty($b['subtitle']) ? 'NULL' : "'%s'" ) . + ")", + mysql_real_escape_string($b['uri']), + mysql_real_escape_string($b['title']), + mysql_real_escape_string($b['subtitle']) + ), $sql) or error(mysql_error($sql)); + + // Open the board + openBoard($b['uri']) or error("Couldn't open board after creation."); + + // Create the posts table + mysql_query(Element('posts.sql', Array('board' => $board['uri'])), $sql) or error(mysql_error($sql)); + + // Build the board + buildIndex(); + } + + $body .= form_newBoard(); + + // TODO: Statistics, etc, in the dashboard. + + echo Element('page.html', Array( + 'index'=>ROOT, + 'title'=>'New board', + 'body'=>$body + ) + ); } elseif(preg_match('/^\/' . $regex['board'] . '(' . preg_quote(FILE_INDEX, '/') . ')?$/', $query, $matches)) { // Board index -- cgit v1.3 From e7c0a40f83227aedea96f6a4e62d8c0f880210fe Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Sat, 4 Dec 2010 14:58:24 +1100 Subject: Fix encoding issue. --- mod.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'mod.php') diff --git a/mod.php b/mod.php index 3390d180..744755c6 100644 --- a/mod.php +++ b/mod.php @@ -9,6 +9,9 @@ require 'inc/user.php'; require 'inc/mod.php'; + // Fix some encoding issues + header('Content-Type: text/html; charset=utf-8', true); + // If not logged in if(!$mod) { if(isset($_POST['login'])) { @@ -53,6 +56,8 @@ // TODO: Statistics, etc, in the dashboard. + $body .= '
    Configuration' . highlight_file('inc/instance-config.php', true) . '
    '; + echo Element('page.html', Array( 'index'=>ROOT, 'title'=>'Dashboard', -- cgit v1.3 From 88c4ef787e2ca0a954cfe41f60cb58eee461412b Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Fri, 10 Dec 2010 20:38:49 +1100 Subject: Simple permission handling --- inc/config.php | 1 + mod.php | 2 ++ 2 files changed, 3 insertions(+) (limited to 'mod.php') diff --git a/inc/config.php b/inc/config.php index 284692ce..832afffb 100644 --- a/inc/config.php +++ b/inc/config.php @@ -70,6 +70,7 @@ define('ERROR_MISSEDAFIELD', 'Your browser didn\'t submit an input when it should have.', true); define('ERROR_REQUIRED', 'The %s field is required.', true); define('ERROR_INVALIDFIELD', 'The %s field was invalid.', true); + define('ERROR_NOACCESS', 'You don\'t have permission to do that.', true); // For resizing, max values define('THUMB_WIDTH', 200, true); diff --git a/mod.php b/mod.php index 744755c6..5695ad8b 100644 --- a/mod.php +++ b/mod.php @@ -65,6 +65,8 @@ ) ); } elseif(preg_match('/^\/new$/', $query)) { + if($mod['type'] != MOD_ADMIN) error(ERROR_NOACCESS); + // New board $body = ''; -- cgit v1.3 From afd5f5b9cc75c0197acf1311b17f935e48917b0b Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Fri, 10 Dec 2010 20:42:16 +1100 Subject: Comment out useless code at this time --- mod.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'mod.php') diff --git a/mod.php b/mod.php index 5695ad8b..62200545 100644 --- a/mod.php +++ b/mod.php @@ -61,7 +61,8 @@ echo Element('page.html', Array( 'index'=>ROOT, 'title'=>'Dashboard', - 'body'=>$body + 'body'=>$body, + 'mod'=>true ) ); } elseif(preg_match('/^\/new$/', $query)) { @@ -126,7 +127,8 @@ echo Element('page.html', Array( 'index'=>ROOT, 'title'=>'New board', - 'body'=>$body + 'body'=>$body, + 'mod'=>true ) ); } elseif(preg_match('/^\/' . $regex['board'] . '(' . preg_quote(FILE_INDEX, '/') . ')?$/', $query, $matches)) { @@ -136,7 +138,7 @@ // Open board openBoard($boardName); - echo Element('index.html', index(1)); + // echo Element('index.html', index(1)); } else { error("Page not found."); -- cgit v1.3 From f4d35fd3410f84524a1d18ceca55a0b31f165c19 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Fri, 10 Dec 2010 20:45:09 +1100 Subject: Erorr handling --- mod.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'mod.php') diff --git a/mod.php b/mod.php index 62200545..a00d5ac8 100644 --- a/mod.php +++ b/mod.php @@ -136,7 +136,8 @@ $boardName = $matches[1]; // Open board - openBoard($boardName); + if(!openBoard($boardName)) + error(ERROR_NOBOARD); // echo Element('index.html', index(1)); -- cgit v1.3 From b5a4377e09176c171bd3c233d6a067548fb528ba Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Fri, 10 Dec 2010 20:57:34 +1100 Subject: Config page --- mod.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'mod.php') diff --git a/mod.php b/mod.php index a00d5ac8..05b4b491 100644 --- a/mod.php +++ b/mod.php @@ -56,11 +56,29 @@ // TODO: Statistics, etc, in the dashboard. - $body .= '
    Configuration' . highlight_file('inc/instance-config.php', true) . '
    '; - echo Element('page.html', Array( 'index'=>ROOT, 'title'=>'Dashboard', + 'body'=>$body + //,'mod'=>true /* All 'mod' does, at this point, is put the "Return to dashboard" link in. */ + ) + ); + } elseif(preg_match('/^\/config$/', $query)) { + if($mod['type'] != MOD_ADMIN) error(ERROR_NOACCESS); + + // Show instance-config.php + + $data = highlight_file('inc/instance-config.php', true); + if(MOD_NEVER_REAL_PASSWORD) { + // Rough and dirty removal of password + $data = str_replace(MY_PASSWORD, '*******', $data); + } + + $body = '
    Configuration' . $data . '
    '; + + echo Element('page.html', Array( + 'index'=>ROOT, + 'title'=>'Configuration', 'body'=>$body, 'mod'=>true ) -- cgit v1.3 From d97b1a56c4615c8b57991bcc40601225e0a87cbe Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Fri, 10 Dec 2010 21:15:44 +1100 Subject: View board --- mod.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'mod.php') diff --git a/mod.php b/mod.php index 05b4b491..ab59d43e 100644 --- a/mod.php +++ b/mod.php @@ -157,7 +157,10 @@ if(!openBoard($boardName)) error(ERROR_NOBOARD); - // echo Element('index.html', index(1)); + $page = index(1); + $page['mod'] = true; + + echo Element('index.html', $page); } else { error("Page not found."); -- cgit v1.3 From dcaeb7a81a39d9d0274dac0d3a389cb1e0b6954a Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Fri, 10 Dec 2010 21:22:46 +1100 Subject: Fixed links for mod pages --- inc/display.php | 8 ++++---- inc/functions.php | 6 +++--- mod.php | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'mod.php') diff --git a/inc/display.php b/inc/display.php index 25fbc6ba..83b1d3bf 100644 --- a/inc/display.php +++ b/inc/display.php @@ -108,7 +108,7 @@ // File info if(!empty($this->file)) { - $built .= '

    File: ' . $this->file . ' (' . + $built .= '

    File: ' . $this->file . ' (' . // Filesize format_bytes($this->filesize) . ', ' . // File dimensions @@ -121,7 +121,7 @@ // Filename $built .= ', ' . $this->filename . ')

    ' . // Thumbnail - ''; + ''; } // Body @@ -162,7 +162,7 @@ public function build($index=false) { global $board, $mod; - $built = '

    File: ' . $this->file . ' (' . + $built = '

    File: ' . $this->file . ' (' . // Filesize format_bytes($this->filesize) . ', ' . // File dimensions @@ -175,7 +175,7 @@ // Filename $built .= ', ' . $this->filename . ')

    ' . // Thumbnail - ''; + ''; $built .= '

    '; diff --git a/inc/functions.php b/inc/functions.php index c6ef451e..4c3f281a 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -135,7 +135,7 @@ } } - function index($page) { + function index($page, $mod) { global $sql, $board; $body = ''; @@ -151,7 +151,7 @@ if(mysql_num_rows($query) < 1 && $page > 1) return false; while($th = mysql_fetch_array($query)) { - $thread = new Thread($th['id'], $th['subject'], $th['email'], $th['name'], $th['trip'], $th['body'], $th['time'], $th['thumb'], $th['thumbwidth'], $th['thumbheight'], $th['file'], $th['filewidth'], $th['fileheight'], $th['filesize'], $th['filename'], $th['ip']); + $thread = new Thread($th['id'], $th['subject'], $th['email'], $th['name'], $th['trip'], $th['body'], $th['time'], $th['thumb'], $th['thumbwidth'], $th['thumbheight'], $th['file'], $th['filewidth'], $th['fileheight'], $th['filesize'], $th['filename'], $th['ip'], $mod ? '?/' : null); $newposts = mysql_query(sprintf( "SELECT `id`, `subject`, `email`, `name`, `trip`, `body`, `time`, `thumb`, `thumbwidth`, `thumbheight`, `file`, `filewidth`, `fileheight`, `filesize`, `filename`,`ip` FROM `posts_%s` WHERE `thread` = '%s' ORDER BY `time` DESC LIMIT %d", @@ -173,7 +173,7 @@ unset($omitted); } while($po = mysql_fetch_array($newposts)) { - $thread->add(new Post($po['id'], $th['id'], $po['subject'], $po['email'], $po['name'], $po['trip'], $po['body'], $po['time'], $po['thumb'], $po['thumbwidth'], $po['thumbheight'], $po['file'], $po['filewidth'], $po['fileheight'], $po['filesize'], $po['filename'], $po['ip'])); + $thread->add(new Post($po['id'], $th['id'], $po['subject'], $po['email'], $po['name'], $po['trip'], $po['body'], $po['time'], $po['thumb'], $po['thumbwidth'], $po['thumbheight'], $po['file'], $po['filewidth'], $po['fileheight'], $po['filesize'], $po['filename'], $po['ip'], $mod ? '?/' : null)); } mysql_free_result($newposts); diff --git a/mod.php b/mod.php index ab59d43e..6fe71720 100644 --- a/mod.php +++ b/mod.php @@ -157,7 +157,7 @@ if(!openBoard($boardName)) error(ERROR_NOBOARD); - $page = index(1); + $page = index(1, true); $page['mod'] = true; echo Element('index.html', $page); -- cgit v1.3 From 507513d5db688ed3231892ec8864ded723ca0e6a Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Thu, 16 Dec 2010 16:36:40 +1100 Subject: Delete thread --- mod.php | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'mod.php') diff --git a/mod.php b/mod.php index 6fe71720..590bd2df 100644 --- a/mod.php +++ b/mod.php @@ -42,8 +42,16 @@ } } else { $query = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : ''; + + // A sort of "cache" + // Stops calling preg_quote and str_replace when not needed; only does it once $regex = Array( - 'board' => str_replace('%s', '(\w{1,8})', preg_quote(BOARD_PATH, '/')) + 'board' => str_replace('%s', '(\w{1,8})', preg_quote(BOARD_PATH, '/')), + 'page' => str_replace('%d', '(\d+)', preg_quote(FILE_PAGE, '/')), + 'img' => preg_quote(DIR_IMG, '/'), + 'thumb' => preg_quote(DIR_THUMB, '/'), + 'res' => preg_quote(DIR_RES, '/'), + 'index' => preg_quote(FILE_INDEX, '/') ); if(preg_match('/^\/?$/', $query)) { @@ -149,7 +157,7 @@ 'mod'=>true ) ); - } elseif(preg_match('/^\/' . $regex['board'] . '(' . preg_quote(FILE_INDEX, '/') . ')?$/', $query, $matches)) { + } elseif(preg_match('/^\/' . $regex['board'] . '(' . $regex['index'] . ')?$/', $query, $matches)) { // Board index $boardName = $matches[1]; @@ -161,7 +169,32 @@ $page['mod'] = true; echo Element('index.html', $page); + } elseif(preg_match('/^\/' . $regex['board'] . $regex['res'] . $regex['page'] . '$/', $query, $matches)) { + // View thread + + $boardName = $matches[1]; + $thread = $matches[2]; + // Open board + if(!openBoard($boardName)) + error(ERROR_NOBOARD); + + $page = buildThread($thread, true, true); + + echo $page; + } elseif(preg_match('/^\/' . $regex['board'] . 'delete\/(\d+)$/', $query, $matches)) { + // Delete post + + $boardName = $matches[1]; + $post = $matches[2]; + // Open board + if(!openBoard($boardName)) + error(ERROR_NOBOARD); + + // Delete post + deletePost($post); + // Rebuild board + buildIndex(); } else { error("Page not found."); } -- cgit v1.3 From 9554c7ecb26b7e26cb395532c26845886a5d3541 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Thu, 16 Dec 2010 16:43:45 +1100 Subject: Redirect after deleting --- mod.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'mod.php') diff --git a/mod.php b/mod.php index 590bd2df..b44f502f 100644 --- a/mod.php +++ b/mod.php @@ -192,9 +192,10 @@ // Delete post deletePost($post); - // Rebuild board buildIndex(); + // Redirect to board + header('Location: ?/' . sprintf(BOARD_PATH, $boardName) . FILE_INDEX, true, REDIRECT_HTTP); } else { error("Page not found."); } -- cgit v1.3 From 130efdf467ed59670f108924199a42a33a26b5d2 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Thu, 16 Dec 2010 19:13:04 +1100 Subject: Redirect to referer --- mod.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'mod.php') diff --git a/mod.php b/mod.php index b44f502f..ddd58ab4 100644 --- a/mod.php +++ b/mod.php @@ -194,8 +194,13 @@ deletePost($post); // Rebuild board buildIndex(); - // Redirect to board - header('Location: ?/' . sprintf(BOARD_PATH, $boardName) . FILE_INDEX, true, REDIRECT_HTTP); + + // Redirect + if(isset($_SERVER['HTTP_REFERER'])) + header('Location: ' . $_SERVER['HTTP_REFERER'], true, REDIRECT_HTTP); + else + header('Location: ?/' . sprintf(BOARD_PATH, $boardName) . FILE_INDEX, true, REDIRECT_HTTP); + } else { error("Page not found."); } -- cgit v1.3 From a261dca0a5545f11114dddf85c81924b6491604d Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Thu, 16 Dec 2010 21:28:03 +1100 Subject: Pages on index pages in mod panel --- mod.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'mod.php') diff --git a/mod.php b/mod.php index ddd58ab4..e6b52060 100644 --- a/mod.php +++ b/mod.php @@ -157,15 +157,17 @@ 'mod'=>true ) ); - } elseif(preg_match('/^\/' . $regex['board'] . '(' . $regex['index'] . ')?$/', $query, $matches)) { + } elseif(preg_match('/^\/' . $regex['board'] . '(' . $regex['index'] . '|' . $regex['page'] . ')?$/', $query, $matches)) { // Board index $boardName = $matches[1]; + // Open board if(!openBoard($boardName)) error(ERROR_NOBOARD); - $page = index(1, true); + $page = index($matches[2] == FILE_INDEX ? 1 : $matches[2], true); + $page['pages'] = getPages(true); $page['mod'] = true; echo Element('index.html', $page); -- cgit v1.3 From a896abbd667fb8d1cb2f04be34a7a1a9daae6626 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Thu, 16 Dec 2010 21:42:31 +1100 Subject: Fixed bug causing errors when visiting a board index in a certain way --- mod.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mod.php') diff --git a/mod.php b/mod.php index e6b52060..e822e6ba 100644 --- a/mod.php +++ b/mod.php @@ -166,7 +166,7 @@ if(!openBoard($boardName)) error(ERROR_NOBOARD); - $page = index($matches[2] == FILE_INDEX ? 1 : $matches[2], true); + $page = index(empty($matches[2]) || $matches[2] == FILE_INDEX ? 1 : $matches[2], true); $page['pages'] = getPages(true); $page['mod'] = true; -- cgit v1.3 From 4052d6350214e5384cfe15823e29197d2eaf7326 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Thu, 16 Dec 2010 23:09:44 +1100 Subject: Better "page not found" code --- mod.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'mod.php') diff --git a/mod.php b/mod.php index e822e6ba..6b3d17c3 100644 --- a/mod.php +++ b/mod.php @@ -166,7 +166,9 @@ if(!openBoard($boardName)) error(ERROR_NOBOARD); - $page = index(empty($matches[2]) || $matches[2] == FILE_INDEX ? 1 : $matches[2], true); + if(!$page = index(empty($matches[2]) || $matches[2] == FILE_INDEX ? 1 : $matches[2], true)) { + error(ERROR_404); + } $page['pages'] = getPages(true); $page['mod'] = true; @@ -204,7 +206,7 @@ header('Location: ?/' . sprintf(BOARD_PATH, $boardName) . FILE_INDEX, true, REDIRECT_HTTP); } else { - error("Page not found."); + error(ERROR_404); } } -- cgit v1.3 From 9554291802cb8ac712ba25d1a59ced31d20b07f0 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Fri, 17 Dec 2010 02:20:16 +1100 Subject: Mod controls and permissions --- inc/config.php | 8 ++++ inc/display.php | 116 ++++++++++++++++++++++++++++++++++---------------------- inc/mod.php | 8 ++-- mod.php | 25 +++++++++--- 4 files changed, 101 insertions(+), 56 deletions(-) (limited to 'mod.php') diff --git a/inc/config.php b/inc/config.php index 4e48b6d5..8f265a78 100644 --- a/inc/config.php +++ b/inc/config.php @@ -152,6 +152,7 @@ // Permissions // What level of administration you need to: + /* Post Controls */ // View IP addresses define('MOD_SHOW_IP', MOD_MOD, true); // Delete a post @@ -167,6 +168,12 @@ // Sticky a thread define('MOD_STICKY', MOD_MOD, true); + /* Administration */ + // Display the contents of instant-config.php + define('MOD_SHOW_CONFIG', MOD_ADMIN, true); + // Create a new board + define('MOD_NEWBOARD', MOD_ADMIN, true); + // Mod links (full HTML) // Correspond to above permission directives define('MOD_LINK_DELETE', '[D]', true); @@ -175,6 +182,7 @@ define('MOD_LINK_DELETEFILE', '[F]', true); define('MOD_LINK_DELETEBYIP', '[D+]', true); define('MOD_LINK_STICKY', '[Sticky]', true); + define('MOD_LINK_DESTICKY', '[-Sticky]', true); // A small file in the main directory indicating that the script has been ran and the board(s) have been generated. // This keeps the script from querying the database and causing strain when not needed. diff --git a/inc/display.php b/inc/display.php index 8cf4a18e..5dbccc8f 100644 --- a/inc/display.php +++ b/inc/display.php @@ -48,50 +48,6 @@ ))); } - function postControls($id, $thread=false) { - global $mod; - - $built = ''; - if($mod) { - // Mod controls (on posts) - if($thread) { - $built .= ''; - } else { - $built .= ''; - } - - // Delete - if($mod['type'] >= MOD_DELETE) - $built .= ' ' . MOD_LINK_DELETE . ''; - - // Delete all posts by IP - if($mod['type'] >= MOD_DELETEBYIP) - $built .= ' ' . MOD_LINK_DELETEBYIP . ''; - - // Ban - if($mod['type'] >= MOD_BAN) - $built .= ' ' . MOD_LINK_BAN . ''; - - // Ban & Delete - if($mod['type'] >= MOD_BANDELETE) - $built .= ' ' . MOD_LINK_BANDELETE . ''; - - // Delete file (keep post) - if(!$thread && $mod['type'] >= MOD_DELETEFILE) - $built .= ' ' . MOD_LINK_DELETEFILE . ''; - - if($thread) { - // Delete file (keep post) - if($mod['type'] >= MOD_STICKY) - $built .= ' ' . MOD_LINK_STICKY . ''; - - } - - $built .= ''; - } - return $built; - } - class Post { public function __construct($id, $thread, $subject, $email, $name, $trip, $body, $time, $thumb, $thumbx, $thumby, $file, $filex, $filey, $filesize, $filename, $ip, $root=ROOT) { $this->id = $id; @@ -113,6 +69,39 @@ $this->ip = $ip; $this->root = $root; } + public function postControls() { + global $mod; + + $built = ''; + if($mod) { + // Mod controls (on posts) + $built .= ''; + + // Delete + if($mod['type'] >= MOD_DELETE) + $built .= ' ' . MOD_LINK_DELETE . ''; + + // Delete all posts by IP + if($mod['type'] >= MOD_DELETEBYIP) + $built .= ' ' . MOD_LINK_DELETEBYIP . ''; + + // Ban + if($mod['type'] >= MOD_BAN) + $built .= ' ' . MOD_LINK_BAN . ''; + + // Ban & Delete + if($mod['type'] >= MOD_BANDELETE) + $built .= ' ' . MOD_LINK_BANDELETE . ''; + + // Delete file (keep post) + if($mod['type'] >= MOD_DELETEFILE) + $built .= ' ' . MOD_LINK_DELETEFILE . ''; + + $built .= ''; + } + return $built; + } + public function build($index=false) { global $board, $mod; @@ -169,7 +158,7 @@ ''; } - $built .= postControls($this->id); + $built .= $this->postControls(); // Body $built .= '

    ' . $this->body . '


    '; @@ -205,6 +194,41 @@ public function add(Post $post) { $this->posts[] = $post; } + public function postControls() { + global $mod; + + $built = ''; + if($mod) { + // Mod controls (on posts) + $built .= ''; + + // Delete + if($mod['type'] >= MOD_DELETE) + $built .= ' ' . MOD_LINK_DELETE . ''; + + // Delete all posts by IP + if($mod['type'] >= MOD_DELETEBYIP) + $built .= ' ' . MOD_LINK_DELETEBYIP . ''; + + // Ban + if($mod['type'] >= MOD_BAN) + $built .= ' ' . MOD_LINK_BAN . ''; + + // Ban & Delete + if($mod['type'] >= MOD_BANDELETE) + $built .= ' ' . MOD_LINK_BANDELETE . ''; + + // Delete file (keep post) + if($mod['type'] >= MOD_STICKY) + if($this->sticky) + $built .= ' ' . MOD_LINK_DESTICKY . ''; + else + $built .= ' ' . MOD_LINK_STICKY . ''; + + $built .= ''; + } + return $built; + } public function build($index=false) { global $board, $mod; @@ -261,7 +285,7 @@ ($index ? '[Reply]' : '') . // Mod controls - postControls($this->id, true) . + $this->postControls() . '

    '; // Body diff --git a/inc/mod.php b/inc/mod.php index 200ffa20..b5e773f5 100644 --- a/inc/mod.php +++ b/inc/mod.php @@ -85,11 +85,11 @@ } // Generates a
      element with a list of linked - // boards and their subtitles. + // boards and their subtitles. (without the
        opening and ending tags) function ulBoards() { global $mod; - $body = '
          '; + $body = ''; // List of boards $boards = listBoards(); @@ -106,10 +106,10 @@ ''; } - if($mod['type'] == MOD_ADMIN) { + if($mod['type'] >= MOD_NEWBOARD) { $body .= '
        • Create new board
        • '; } - return $body . '
        '; + return $body; } function form_newBoard() { diff --git a/mod.php b/mod.php index 6b3d17c3..7b52735f 100644 --- a/mod.php +++ b/mod.php @@ -56,14 +56,26 @@ if(preg_match('/^\/?$/', $query)) { // Dashboard - $body = ''; + $fieldset = Array( + 'Boards' => '', + 'Administration' => '' + ); - $body .= '
        Boards' . - ulBoards() . - '
        '; + // Boards + $fieldset['Boards'] .= ulBoards(); + + if($mod['type'] >= MOD_SHOW_CONFIG) { + $fieldset['Administration'] .= '
      • Show configuration
      • '; + } // TODO: Statistics, etc, in the dashboard. + $body = ''; + foreach($fieldset as $title => $data) { + if($data) + $body .= "
        {$title}
          {$data}
        "; + } + echo Element('page.html', Array( 'index'=>ROOT, 'title'=>'Dashboard', @@ -72,7 +84,7 @@ ) ); } elseif(preg_match('/^\/config$/', $query)) { - if($mod['type'] != MOD_ADMIN) error(ERROR_NOACCESS); + if($mod['type'] < MOD_SHOW_CONFIG) error(ERROR_NOACCESS); // Show instance-config.php @@ -92,7 +104,7 @@ ) ); } elseif(preg_match('/^\/new$/', $query)) { - if($mod['type'] != MOD_ADMIN) error(ERROR_NOACCESS); + if($mod['type'] < MOD_NEWBOARD) error(ERROR_NOACCESS); // New board $body = ''; @@ -186,6 +198,7 @@ echo $page; } elseif(preg_match('/^\/' . $regex['board'] . 'delete\/(\d+)$/', $query, $matches)) { + if($mod['type'] < MOD_DELETE) error(ERROR_NOACCESS); // Delete post $boardName = $matches[1]; -- cgit v1.3 From 62e97732e8a060a7e1a0e6eb8b35a05c73ee92b3 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Fri, 17 Dec 2010 04:41:11 +1100 Subject: Fixed config page --- mod.php | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) (limited to 'mod.php') diff --git a/mod.php b/mod.php index 7b52735f..87514aec 100644 --- a/mod.php +++ b/mod.php @@ -88,13 +88,42 @@ // Show instance-config.php - $data = highlight_file('inc/instance-config.php', true); - if(MOD_NEVER_REAL_PASSWORD) { - // Rough and dirty removal of password - $data = str_replace(MY_PASSWORD, '*******', $data); + //$data = highlight_file('inc/instance-config.php', true); + //if(MOD_NEVER_REAL_PASSWORD) { + // // Rough and dirty removal of password + // $data = str_replace(MY_PASSWORD, '*******', $data); + //} + + $constants = get_defined_constants(true); + $constants = $constants['user']; + + $data = ''; + foreach($constants as $name => $value) { + if(MOD_NEVER_REAL_PASSWORD && $name == 'MY_PASSWORD') + $value = '********'; + else { + // For some reason PHP is only giving me the first defined value (the default), so use constant() + $value = constant($name); + if(gettype($value) == 'boolean') { + $value = $value ? 'On' : 'Off'; + } elseif(gettype($value) == 'string') { + $value = '' . utf8tohtml($value) . ''; + } elseif(gettype($value) == 'integer') { + $value = '' . $value . ''; + } + } + + $data .= + '' . + $name . + '' . + substr($value, 0, 120) . + '' . + (strlen($value) > 120 ? '…' : '') . + ''; } - $body = '
        Configuration' . $data . '
        '; + $body = '
        Configuration' . $data . '
        '; echo Element('page.html', Array( 'index'=>ROOT, -- cgit v1.3 From 02e990979ad54dd5a6f617626c1282024e48efa2 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Fri, 17 Dec 2010 16:25:32 +1100 Subject: Cleaned config page --- mod.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'mod.php') diff --git a/mod.php b/mod.php index 87514aec..fec65c02 100644 --- a/mod.php +++ b/mod.php @@ -100,15 +100,24 @@ $data = ''; foreach($constants as $name => $value) { if(MOD_NEVER_REAL_PASSWORD && $name == 'MY_PASSWORD') - $value = '********'; + $value = 'hidden'; else { // For some reason PHP is only giving me the first defined value (the default), so use constant() $value = constant($name); if(gettype($value) == 'boolean') { $value = $value ? 'On' : 'Off'; } elseif(gettype($value) == 'string') { - $value = '' . utf8tohtml($value) . ''; + $value = '' . utf8tohtml(substr($value, 0, 110) . (strlen($value) > 110 ? '…' : '')) . ''; } elseif(gettype($value) == 'integer') { + // Show permissions in a cleaner way + if(preg_match('/^MOD_/', $name) && $name != 'MOD_JANITOR' && $name != 'MOD_MOD' && $name != 'MOD_ADMIN') { + if($value == MOD_JANITOR) + $value = 'Janitor'; + elseif($value == MOD_MOD) + $value = 'Mod'; + elseif($value == MOD_ADMIN) + $value = 'Admin'; + } $value = '' . $value . ''; } } @@ -117,9 +126,7 @@ '' . $name . '' . - substr($value, 0, 120) . - '' . - (strlen($value) > 120 ? '…' : '') . + $value . ''; } -- cgit v1.3 From 574256a01a3250d3fef4bb1f4c41b7da8c7bf9f9 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Sat, 18 Dec 2010 01:18:03 +1100 Subject: Use PDO for databases --- inc/config.php | 14 ++- inc/database.php | 39 +++++++ inc/functions.php | 263 ++++++++++++++++++++++-------------------------- inc/instance-config.php | 21 ++-- inc/mod.php | 37 +++---- mod.php | 20 ++-- post.php | 15 +-- 7 files changed, 208 insertions(+), 201 deletions(-) create mode 100644 inc/database.php (limited to 'mod.php') diff --git a/inc/config.php b/inc/config.php index b936da29..4d1b6d78 100644 --- a/inc/config.php +++ b/inc/config.php @@ -10,10 +10,16 @@ */ // Database stuff - define('MY_SERVER', 'localhost', true); - define('MY_USER', '', true); - define('MY_PASSWORD', '', true); - define('MY_DATABASE', '', true); + + // "mysql", "mysqli", "pgsql", "mssql" + define('DB_TYPE', 'mysql', true); + // Hostname or IP address + define('DB_SERVER', 'localhost', true); + // Login + define('DB_USER', '', true); + define('DB_PASSWORD', '', true); + // TinyBoard database + define('DB_DATABASE', '', true); // The name of the session cookie (PHP's $_SESSION) define('SESS_COOKIE', 'imgboard', true); diff --git a/inc/database.php b/inc/database.php new file mode 100644 index 00000000..0d93c3c7 --- /dev/null +++ b/inc/database.php @@ -0,0 +1,39 @@ +prepare($query); + } + + function query($query) { + global $pdo; + return $pdo->query($query); + } + + function db_error($PDOStatement=null) { + global $pdo; + if(isset($PDOStatement)) { + $err = $PDOStatement->errorInfo(); + return $err[2]; + } else { + $err = $pdo->errorInfo(); + return $err[2]; + } + } +?> \ No newline at end of file diff --git a/inc/functions.php b/inc/functions.php index fd87de43..aadc8525 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -7,22 +7,6 @@ return str_replace(array_keys($replaces), array_values($replaces), $str); } - - function sql_open() { - global $sql; - $sql = @mysql_connect(MY_SERVER, MY_USER, MY_PASSWORD) or error('Database error.'); - @mysql_select_db(MY_DATABASE, $sql) or error('Database error.'); - } - function sql_close() { - global $sql; - @mysql_close($sql); - } - - function mysql_safe_array(&$array) { - foreach($array as &$item) { - $item = mysql_real_escape_string($item); - } - } function setupBoard($array) { global $board; @@ -45,94 +29,91 @@ function openBoard($uri) { global $sql; sql_open(); - $boards_res = mysql_query(sprintf( - "SELECT * FROM `boards` WHERE `uri` = '%s' LIMIT 1", - mysql_real_escape_string($uri) - ), $sql) or error(mysql_error($sql)); - if($_board = mysql_fetch_array($boards_res)) { - setupBoard($_board); + $query = prepare("SELECT * FROM `boards` WHERE `uri` = :uri LIMIT 1"); + $query->bindValue(':uri', $uri); + $query->execute() or error(db_error($query)); + + if($board = $query->fetch()) { + setupBoard($board); return true; } else return false; } function listBoards() { - global $sql; - sql_open(); - $boards_res = mysql_query("SELECT * FROM `boards`", $sql) or error(mysql_error($sql)); - - $boards = Array(); - while($_board = mysql_fetch_array($boards_res)) { - $boards[] = $_board; - } + $query = query("SELECT * FROM `boards`") or error(db_error()); + $boards = $query->fetchAll(); return $boards; } function threadExists($id) { - global $sql, $board; - $thread_res = mysql_query(sprintf( - "SELECT 1 FROM `posts_%s` WHERE `id` = '%d' AND `thread` IS NULL LIMIT 1", - mysql_real_escape_string($board['uri']), - $id - ), $sql) or error(mysql_error($sql)); + global $board; - if(mysql_num_rows($thread_res) > 0) { + $query = prepare(sprintf("SELECT 1 FROM `posts_%s` WHERE `id` = :id AND `thread` IS NULL LIMIT 1", $board['uri'])); + $query->bindParam(':id', $id, PDO::PARAM_INT); + $query->execute() or error(db_error()); + + if($query->rowCount()) { return true; } else return false; } function post($post, $OP) { - global $sql, $board; + global $pdo, $board; + + $query = prepare(sprintf("INSERT INTO `posts_%s` VALUES ( NULL, :thread, :subject, :email, :name, :trip, :body, :time, :time, :thumb, :thumbwidth, :thumbheight, :file, :width, :height, :filesize, :filename, :filehash, :password, :ip, :sticky)", $board['uri'])); + + // Basic stuff + $query->bindValue(':subject', $post['subject']); + $query->bindValue(':email', $post['email']); + $query->bindValue(':name', $post['name']); + $query->bindValue(':trip', $post['trip']); + $query->bindValue(':body', $post['body']); + $query->bindValue(':time', time(), PDO::PARAM_INT); + $query->bindValue(':password', $post['password']); + $query->bindValue(':ip', $_SERVER['REMOTE_ADDR']); + $query->bindValue(':sticky', 0, PDO::PARAM_INT); + if($OP) { - mysql_query( - sprintf("INSERT INTO `posts_%s` VALUES ( NULL, NULL, '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%s', '%d', '%d', '%s', '%d', '%d', '%d', '%s', '%s', '%s', '%s', '0')", - mysql_real_escape_string($board['uri']), - $post['subject'], - $post['email'], - $post['name'], - $post['trip'], - $post['body'], - time(), - time(), - $post['thumb'], - $post['thumbwidth'], - $post['thumbheight'], - $post['file'], - $post['width'], - $post['height'], - $post['filesize'], - $post['filename'], - $post['filehash'], - $post['password'], - mysql_real_escape_string($_SERVER['REMOTE_ADDR']) - ), $sql) or error(mysql_error($sql)); - return mysql_insert_id($sql); + // No parent thread, image + $query->bindValue(':thread', null, PDO::PARAM_NULL); } else { - mysql_query( - sprintf("INSERT INTO `posts_%s` VALUES ( NULL, '%d', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%s', '%d', '%d', '%s', '%d', '%d', '%d', '%s', '%s', '%s', '%s', '0')", - mysql_real_escape_string($board['uri']), - $post['thread'], - $post['subject'], - $post['email'], - $post['name'], - $post['trip'], - $post['body'], - time(), - time(), - $post['has_file']?$post['thumb']:null, - $post['has_file']?$post['thumbwidth']:null, - $post['has_file']?$post['thumbheight']:null, - $post['has_file']?$post['file']:null, - $post['has_file']?$post['width']:null, - $post['has_file']?$post['height']:null, - $post['has_file']?$post['filesize']:null, - $post['has_file']?$post['filename']:null, - $post['has_file']?$post['filehash']:null, - $post['password'], - mysql_real_escape_string($_SERVER['REMOTE_ADDR']) - ), $sql) or error(mysql_error($sql)); - return mysql_insert_id($sql); + $query->bindValue(':thread', $post['thread'], PDO::PARAM_INT); } + + if($post['has_file']) { + $query->bindValue(':thumb', $post['thumb']); + $query->bindValue(':thumbwidth', $post['thumbwidth'], PDO::PARAM_INT); + $query->bindValue(':thumbheight', $post['thumbheight'], PDO::PARAM_INT); + $query->bindValue(':file', $post['file']); + $query->bindValue(':width', $post['width'], PDO::PARAM_INT); + $query->bindValue(':height', $post['height'], PDO::PARAM_INT); + $query->bindValue(':filesize', $post['filesize'], PDO::PARAM_INT); + $query->bindValue(':filename', $post['filesize']); + $query->bindValue(':filehash', $post['filesize']); + } else { + $query->bindValue(':thumb', null, PDO::PARAM_NULL); + $query->bindValue(':thumbwidth', null, PDO::PARAM_NULL); + $query->bindValue(':thumbheight', null, PDO::PARAM_NULL); + $query->bindValue(':file', null, PDO::PARAM_NULL); + $query->bindValue(':width', null, PDO::PARAM_NULL); + $query->bindValue(':height', null, PDO::PARAM_NULL); + $query->bindValue(':filesize', null, PDO::PARAM_NULL); + $query->bindValue(':filename', null, PDO::PARAM_NULL); + $query->bindValue(':filehash', null, PDO::PARAM_NULL); + } + + $query->execute() or error(db_error($query)); + + return $pdo->lastInsertId(); + } + + function bumpThread($id) { + global $board; + $query = prepare(sprintf("UPDATE `posts_%s` SET `bump` = :time WHERE `id` = :id AND `thread` IS NULL", $board['uri'])); + $query->bindValue(':time', time(), PDO::PARAM_INT); + $query->bindValue(':id', $id, PDO::PARAM_INT); + $query->execute() or error(db_error($query)); } function index($page, $mod=false) { @@ -142,57 +123,52 @@ $offset = round($page*THREADS_PER_PAGE-THREADS_PER_PAGE); sql_open(); - $query = mysql_query(sprintf( - "SELECT * FROM `posts_%s` WHERE `thread` IS NULL ORDER BY `sticky` DESC, `bump` DESC LIMIT %d,%d", - mysql_real_escape_string($board['uri']), - $offset, - THREADS_PER_PAGE - ), $sql) or error(mysql_error($sql)); - - if(mysql_num_rows($query) < 1 && $page > 1) return false; - while($th = mysql_fetch_array($query)) { + + $query = prepare(sprintf("SELECT * FROM `posts_%s` WHERE `thread` IS NULL ORDER BY `sticky` DESC, `bump` DESC LIMIT ?,?", $board['uri'])); + $query->bindValue(1, $offset, PDO::PARAM_INT); + $query->bindValue(2, THREADS_PER_PAGE, PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + + if($query->rowcount() < 1 && $page > 1) return false; + while($th = $query->fetch()) { $thread = new Thread($th['id'], $th['subject'], $th['email'], $th['name'], $th['trip'], $th['body'], $th['time'], $th['thumb'], $th['thumbwidth'], $th['thumbheight'], $th['file'], $th['filewidth'], $th['fileheight'], $th['filesize'], $th['filename'], $th['ip'], $th['sticky'], $mod ? '?/' : ROOT); - $newposts = mysql_query(sprintf( - "SELECT `id`, `subject`, `email`, `name`, `trip`, `body`, `time`, `thumb`, `thumbwidth`, `thumbheight`, `file`, `filewidth`, `fileheight`, `filesize`, `filename`,`ip` FROM `posts_%s` WHERE `thread` = '%s' ORDER BY `time` DESC LIMIT %d", - mysql_real_escape_string($board['uri']), - $th['id'], - THREADS_PREVIEW - ), $sql) or error(mysql_error($sql)); - if(mysql_num_rows($newposts) == THREADS_PREVIEW) { - $count_query = mysql_query(sprintf( - "SELECT COUNT(`id`) as `num` FROM `posts_%s` WHERE `thread` = '%s'", - mysql_real_escape_string($board['uri']), - $th['id'] - ), $sql) or error(mysql_error($sql)); - $count = mysql_fetch_array($count_query); + $posts = prepare(sprintf("SELECT `id`, `subject`, `email`, `name`, `trip`, `body`, `time`, `thumb`, `thumbwidth`, `thumbheight`, `file`, `filewidth`, `fileheight`, `filesize`, `filename`,`ip` FROM `posts_%s` WHERE `thread` = ? ORDER BY `time` DESC LIMIT ?", $board['uri'])); + $posts->bindValue(1, $th['id']); + $posts->bindValue(2, THREADS_PREVIEW, PDO::PARAM_INT); + $posts->execute() or error(db_error($posts)); + + if($posts->rowCount() == THREADS_PREVIEW) { + $count = prepare(sprintf("SELECT COUNT(`id`) as `num` FROM `posts_%s` WHERE `thread` = ?", $board['uri'])); + $count->bindValue(1, $th['id']); + $count->execute() or error(db_error($count)); + + $count = $count->fetch(); $omitted = $count['num'] - THREADS_PREVIEW; $thread->omitted = $omitted; - mysql_free_result($count_query); unset($count); unset($omitted); } - while($po = mysql_fetch_array($newposts)) { + + while($po = $posts->fetch()) { $thread->add(new Post($po['id'], $th['id'], $po['subject'], $po['email'], $po['name'], $po['trip'], $po['body'], $po['time'], $po['thumb'], $po['thumbwidth'], $po['thumbheight'], $po['file'], $po['filewidth'], $po['fileheight'], $po['filesize'], $po['filename'], $po['ip'], $mod ? '?/' : ROOT)); } - mysql_free_result($newposts); $thread->posts = array_reverse($thread->posts); $body .= $thread->build(true); } - mysql_free_result($query); + return Array('button'=>BUTTON_NEWTOPIC, 'board'=>$board, 'body'=>$body, 'post_url' => POST_URL, 'index' => ROOT); } function getPages($mod=false) { global $sql, $board; - $res = mysql_query(sprintf( - "SELECT COUNT(`id`) as `num` FROM `posts_%s` WHERE `thread` IS NULL", - mysql_real_escape_string($board['uri']) - ), $sql) or error(mysql_error($sql)); - $arr = mysql_fetch_array($res); - $count = floor((THREADS_PER_PAGE + $arr['num'] - 1) / THREADS_PER_PAGE); + // Count threads + $query = query(sprintf("SELECT COUNT(`id`) as `num` FROM `posts_%s` WHERE `thread` IS NULL", $board['uri'])) or error(db_error()); + + $count = current($query->fetch()); + $count = floor((THREADS_PER_PAGE + $count - 1) / THREADS_PER_PAGE); $pages = Array(); for($x=0;$x<$count && $xbindValue(':id', $cite); + $query->execute() or error(db_error($query)); + + if($post = $query->fetch()) { $replacement = '>>' . $cite . ''; } else { $replacement = ">>{$cite}"; } - mysql_free_result($result); // Find the position of the cite $position = strpos($body, $cites[0][$index]); @@ -337,39 +310,39 @@ } function buildThread($id, $return=false, $mod=false) { - global $sql, $board; + global $board; $id = round($id); - $query = mysql_query(sprintf( - "SELECT `id`,`thread`,`subject`,`name`,`email`,`trip`,`body`,`time`,`thumb`,`thumbwidth`,`thumbheight`,`file`,`filewidth`,`fileheight`,`filesize`,`filename`,`ip`,`sticky` FROM `posts_%s` WHERE (`thread` IS NULL AND `id` = '%d') OR `thread` = '%d' ORDER BY `thread`,`time`", - mysql_real_escape_string($board['uri']), - $id, - $id - ), $sql) or error(mysql_error($sql)); - - while($post = mysql_fetch_array($query)) { + $query = prepare(sprintf("SELECT `id`,`thread`,`subject`,`name`,`email`,`trip`,`body`,`time`,`thumb`,`thumbwidth`,`thumbheight`,`file`,`filewidth`,`fileheight`,`filesize`,`filename`,`ip`,`sticky` FROM `posts_%s` WHERE (`thread` IS NULL AND `id` = :id) OR `thread` = :id ORDER BY `thread`,`time`", $board['uri'])); + $query->bindValue(':id', $id, PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + + while($post = $query->fetch()) { if(!isset($thread)) { $thread = new Thread($post['id'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['sticky'], $mod ? '?/' : ROOT); } else { $thread->add(new Post($post['id'], $thread->id, $post['subject'], $post['email'], $post['name'], $post['trip'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $mod ? '?/' : ROOT)); } } - $body = Element('thread.html', Array( - 'button'=>BUTTON_REPLY, - 'board'=>$board, - 'body'=>$thread->build(), - 'post_url' => POST_URL, - 'index' => ROOT, - 'id' => $id, - 'mod' => $mod, - 'return' => ($mod ? '?' . $board['url'] . FILE_INDEX : ROOT . $board['uri'] . '/' . FILE_INDEX) - )); + + // Check if any posts were found + if(!isset($thread)) error(ERROR_NONEXISTANT); + + $body = Element('thread.html', Array( + 'button'=>BUTTON_REPLY, + 'board'=>$board, + 'body'=>$thread->build(), + 'post_url' => POST_URL, + 'index' => ROOT, + 'id' => $id, + 'mod' => $mod, + 'return' => ($mod ? '?' . $board['url'] . FILE_INDEX : ROOT . $board['uri'] . '/' . FILE_INDEX) + )); if($return) return $body; else @file_put_contents($board['dir'] . DIR_RES . sprintf(FILE_PAGE, $id), $body) or error("Couldn't write to file."); - mysql_free_result($query); } function generate_tripcode ( $name, $length = 10 ) { diff --git a/inc/instance-config.php b/inc/instance-config.php index 408e9b85..88178f2c 100644 --- a/inc/instance-config.php +++ b/inc/instance-config.php @@ -7,17 +7,18 @@ * * You can copy values from config.php (defaults) and paste them here. */ - - - /* + + + // Database stuff - define('MY_SERVER', '127.0.0.1'); - define('MY_USER', ''); - define('MY_PASSWORD', ''); - define('MY_DATABASE', ''); - + define('DB_TYPE', 'mysql'); + define('DB_SERVER', 'localhost'); + define('DB_USER', ''); + define('DB_PASSWORD', ''); + define('DB_DATABASE', ''); + define('ROOT', '/'); - + // define('FOO', 'bar'); - */ + ?> \ No newline at end of file diff --git a/inc/mod.php b/inc/mod.php index b5e773f5..65675dff 100644 --- a/inc/mod.php +++ b/inc/mod.php @@ -17,13 +17,12 @@ $password = sha1($password); } - $res = mysql_query(sprintf( - "SELECT `id`,`type` FROM `mods` WHERE `username` = '%s' AND `password` = '%s' LIMIT 1", - mysql_real_escape_string($username), - $password - ), $sql) or error(mysql_error($sql)); + $query = prepare("SELECT `id`,`type` FROM `mods` WHERE `username` = :username AND `password` = :password LIMIT 1"); + $query->bindValue(':username', $username); + $query->bindValue(':password', $password); + $query->execute(); - if($user = mysql_fetch_array($res)) { + if($user = $query->fetch()) { return $mod = Array( 'id' => $user['id'], 'type' => $user['type'], @@ -142,22 +141,19 @@ // Delete a post (reply or thread) function deletePost($id) { - global $board, $sql; + global $board; // Select post and replies (if thread) in one query - $post_res = mysql_query(sprintf( - "SELECT `id`,`thread`,`thumb`,`file` FROM `posts_%s` WHERE `id` = '%d' OR `thread` = '%d'", - mysql_real_escape_string($board['uri']), - $id, - $id - ), $sql) or error(mysql_error($sql)); - - if(mysql_num_rows($post_res) < 1) { + $query = prepare(sprintf("SELECT `id`,`thread`,`thumb`,`file` FROM `posts_%s` WHERE `id` = :id OR `thread` = :id", $board['uri'])); + $query->bindValue(':id', $id, PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + + if($query->rowCount() < 1) { error(ERROR_INVALIDPOST); } // Delete posts and maybe replies - while($post = mysql_fetch_array($post_res)) { + while($post = $query->fetch()) { if(!$post['thread']) { // Delete thread HTML page @unlink($board['dir'] . DIR_RES . sprintf(FILE_PAGE, $post['id'])); @@ -172,11 +168,8 @@ } } - mysql_query(sprintf( - "DELETE FROM `posts_%s` WHERE `id` = '%d' OR `thread` = '%d'", - mysql_real_escape_string($board['uri']), - $id, - $id - ), $sql) or error(mysql_error($sql)); + $query = prepare(sprintf("DELETE FROM `posts_%s` WHERE `id` = :id OR `thread` = :id", $board['uri'])); + $query->bindValue(':id', $id, PDO::PARAM_INT); + $query->execute() or error(db_error($query)); } ?> \ No newline at end of file diff --git a/mod.php b/mod.php index fec65c02..0fdc0f5a 100644 --- a/mod.php +++ b/mod.php @@ -6,6 +6,7 @@ } require 'inc/config.php'; require 'inc/template.php'; + require 'inc/database.php'; require 'inc/user.php'; require 'inc/mod.php'; @@ -175,20 +176,21 @@ if(!preg_match('/^\w+$/', $b['uri'])) error(sprintf(ERROR_INVALIDFIELD, 'URI')); - mysql_query(sprintf( - "INSERT INTO `boards` VALUES (NULL, '%s', '%s', " . - (empty($b['subtitle']) ? 'NULL' : "'%s'" ) . - ")", - mysql_real_escape_string($b['uri']), - mysql_real_escape_string($b['title']), - mysql_real_escape_string($b['subtitle']) - ), $sql) or error(mysql_error($sql)); + $query = prepare("INSERT INTO `boards` VALUES (NULL, :uri, :title, :subtitle)"); + $query->bindValue(':uri', $b['uri']); + $query->bindValue(':title', $b['title']); + if(!empty($b['subtitle'])) { + $query->bindValue(':subtitle', $b['subtitle']); + } else { + $query->bindValue(':subtitle', null, PDO::PARAM_NULL); + } + $query->execute() or error(db_error($query)); // Open the board openBoard($b['uri']) or error("Couldn't open board after creation."); // Create the posts table - mysql_query(Element('posts.sql', Array('board' => $board['uri'])), $sql) or error(mysql_error($sql)); + query(Element('posts.sql', Array('board' => $board['uri']))) or error(db_error()); // Build the board buildIndex(); diff --git a/post.php b/post.php index 0b0e0a64..fccf3f16 100644 --- a/post.php +++ b/post.php @@ -6,6 +6,7 @@ } require 'inc/config.php'; require 'inc/template.php'; + require 'inc/database.php'; require 'inc/user.php'; // Fix for magic quotes @@ -191,9 +192,6 @@ // Todo: Validate some more, remove messy code, allow more specific configuration - // MySQLify - mysql_safe_array($post); - $id = post($post, $OP); if($post['has_file'] && $post['zip']) { @@ -295,12 +293,7 @@ buildThread(($OP?$id:$post['thread'])); if(!$OP) { - mysql_query( - sprintf("UPDATE `posts_%s` SET `bump` = '%d' WHERE `id` = '%s' AND `thread` IS NULL", - mysql_real_escape_string($board['uri']), - time(), - $post['thread'] - ), $sql) or error(mysql_error($sql)); + bumpThread($post['thread']); } buildIndex(); @@ -318,8 +311,8 @@ sql_open(); // Build all boards - $boards_res = mysql_query('SELECT * FROM `boards`', $sql) or error(mysql_error($sql)); - while($_board = mysql_fetch_array($boards_res)) { + $boards = listBoards(); + foreach($boards as &$_board) { setupBoard($_board); buildIndex(); } -- cgit v1.3 From ebed5b55dbc29d90b071373aae9c73fa929d0cac Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Sat, 18 Dec 2010 02:12:32 +1100 Subject: Fixed hiding passwords --- mod.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mod.php') diff --git a/mod.php b/mod.php index 0fdc0f5a..c23afb1f 100644 --- a/mod.php +++ b/mod.php @@ -100,7 +100,7 @@ $data = ''; foreach($constants as $name => $value) { - if(MOD_NEVER_REAL_PASSWORD && $name == 'MY_PASSWORD') + if(MOD_NEVER_REAL_PASSWORD && $name == 'DB_PASSWORD') $value = 'hidden'; else { // For some reason PHP is only giving me the first defined value (the default), so use constant() -- cgit v1.3 From 53b32ce8a5460f6d75685b38b62d84a80fdb7f8a Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Sat, 18 Dec 2010 03:15:12 +1100 Subject: Added "empty" text in the config page --- mod.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'mod.php') diff --git a/mod.php b/mod.php index c23afb1f..6bce948f 100644 --- a/mod.php +++ b/mod.php @@ -108,7 +108,10 @@ if(gettype($value) == 'boolean') { $value = $value ? 'On' : 'Off'; } elseif(gettype($value) == 'string') { - $value = '' . utf8tohtml(substr($value, 0, 110) . (strlen($value) > 110 ? '…' : '')) . ''; + if(empty($value)) + $value = 'empty'; + else + $value = '' . utf8tohtml(substr($value, 0, 110) . (strlen($value) > 110 ? '…' : '')) . ''; } elseif(gettype($value) == 'integer') { // Show permissions in a cleaner way if(preg_match('/^MOD_/', $name) && $name != 'MOD_JANITOR' && $name != 'MOD_MOD' && $name != 'MOD_ADMIN') { -- cgit v1.3 From e4016687321770054d134f13f3275fc0523588e8 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Sat, 1 Jan 2011 22:12:31 +1100 Subject: Fixed major security bug and image deleting --- inc/config.php | 6 ++++++ inc/display.php | 50 +++++++++++++++++++++++++------------------------- inc/functions.php | 8 ++++---- inc/mod.php | 5 +++++ mod.php | 26 ++++++++++++++++++++++++-- 5 files changed, 64 insertions(+), 31 deletions(-) (limited to 'mod.php') diff --git a/inc/config.php b/inc/config.php index 24d522c7..79f4bf1e 100644 --- a/inc/config.php +++ b/inc/config.php @@ -99,6 +99,8 @@ */ define('ALLOW_ZIP', false, true); define('ZIP_IMAGE', 'static/zip.png', true); + + define('DELETED_IMAGE', 'static/deleted.png', true); /** Redraw the image using GD functions to strip any excess data (commonly ZIP archives) @@ -131,6 +133,7 @@ define('POST_URL', ROOT . 'post.php', true); define('FILE_INDEX', 'index.html', true); define('FILE_PAGE', '%d.html', true); + define('FILE_MOD', 'mod.php', true); // Multi-board (%s is board abbreviation) define('BOARD_PATH', '%s/', true); @@ -232,6 +235,9 @@ '|' . str_replace('%s', '\w{1,8}', preg_quote(BOARD_PATH, '/')) . str_replace('%d', '\d+', preg_quote(FILE_PAGE, '/')) . + '|' . + preg_quote(FILE_MOD, '/') . + '\?\/.+' . ')$/i', true); if(ROOT_FILE) { diff --git a/inc/display.php b/inc/display.php index a5bfcf7b..32eb9cb2 100644 --- a/inc/display.php +++ b/inc/display.php @@ -49,7 +49,7 @@ } class Post { - public function __construct($id, $thread, $subject, $email, $name, $trip, $body, $time, $thumb, $thumbx, $thumby, $file, $filex, $filey, $filesize, $filename, $ip, $root=ROOT) { + public function __construct($id, $thread, $subject, $email, $name, $trip, $body, $time, $thumb, $thumbx, $thumby, $file, $filex, $filey, $filesize, $filename, $ip, $root=ROOT, $mod=false) { $this->id = $id; $this->thread = $thread; $this->subject = utf8tohtml($subject); @@ -68,34 +68,33 @@ $this->filename = $filename; $this->ip = $ip; $this->root = $root; + $this->mod = $mod; } public function postControls() { - global $mod; - $built = ''; - if($mod) { + if($this->mod) { // Mod controls (on posts) $built .= ''; // Delete - if($mod['type'] >= MOD_DELETE) + if($this->mod['type'] >= MOD_DELETE) $built .= ' ' . MOD_LINK_DELETE . ''; // Delete all posts by IP - if($mod['type'] >= MOD_DELETEBYIP) + if($this->mod['type'] >= MOD_DELETEBYIP) $built .= ' ' . MOD_LINK_DELETEBYIP . ''; // Ban - if($mod['type'] >= MOD_BAN) + if($this->mod['type'] >= MOD_BAN) $built .= ' ' . MOD_LINK_BAN . ''; // Ban & Delete - if($mod['type'] >= MOD_BANDELETE) + if($this->mod['type'] >= MOD_BANDELETE) $built .= ' ' . MOD_LINK_BANDELETE . ''; // Delete file (keep post) - if(!empty($this->file) && $mod['type'] >= MOD_DELETEFILE) - $built .= ' ' . MOD_LINK_DELETEFILE . ''; + if(!empty($this->file) && $this->mod['type'] >= MOD_DELETEFILE) + $built .= ' ' . MOD_LINK_DELETEFILE . ''; $built .= ''; } @@ -103,7 +102,7 @@ } public function build($index=false) { - global $board, $mod; + global $board; $built = '
        ' . '

        '; @@ -120,7 +119,7 @@ . (!empty($this->trip) ? ' '.$this->trip.'':''); // IP Address - if($mod && $mod['type'] >= MOD_SHOW_IP) { + if($this->mod && $this->mod['type'] >= MOD_SHOW_IP) { $built .= ' [' . $this->ip . ']'; } @@ -140,7 +139,7 @@ '

        '; // File info - if(!empty($this->file)) { + if(!empty($this->file) && $this->file != 'deleted') { $built .= '

        File: ' . $this->file . ' (' . // Filesize format_bytes($this->filesize) . ', ' . @@ -156,6 +155,8 @@ // Thumbnail ''; + } elseif($this->file == 'deleted') { + $built .= ''; } $built .= $this->postControls(); @@ -169,7 +170,7 @@ class Thread { public $omitted = 0; - public function __construct($id, $subject, $email, $name, $trip, $body, $time, $thumb, $thumbx, $thumby, $file, $filex, $filey, $filesize, $filename, $ip, $sticky, $root=ROOT) { + public function __construct($id, $subject, $email, $name, $trip, $body, $time, $thumb, $thumbx, $thumby, $file, $filex, $filey, $filesize, $filename, $ip, $sticky, $root=ROOT, $mod=false) { $this->id = $id; $this->subject = utf8tohtml($subject); $this->email = $email; @@ -190,36 +191,35 @@ $this->ip = $ip; $this->sticky = $sticky; $this->root = $root; + $this->mod = $mod; } public function add(Post $post) { $this->posts[] = $post; } - public function postControls() { - global $mod; - + public function postControls() { $built = ''; - if($mod) { + if($this->mod) { // Mod controls (on posts) $built .= ''; // Delete - if($mod['type'] >= MOD_DELETE) + if($this->mod['type'] >= MOD_DELETE) $built .= ' ' . MOD_LINK_DELETE . ''; // Delete all posts by IP - if($mod['type'] >= MOD_DELETEBYIP) + if($this->mod['type'] >= MOD_DELETEBYIP) $built .= ' ' . MOD_LINK_DELETEBYIP . ''; // Ban - if($mod['type'] >= MOD_BAN) + if($this->mod['type'] >= MOD_BAN) $built .= ' ' . MOD_LINK_BAN . ''; // Ban & Delete - if($mod['type'] >= MOD_BANDELETE) + if($this->mod['type'] >= MOD_BANDELETE) $built .= ' ' . MOD_LINK_BANDELETE . ''; // Delete file (keep post) - if($mod['type'] >= MOD_STICKY) + if($this->mod['type'] >= MOD_STICKY) if($this->sticky) $built .= ' ' . MOD_LINK_DESTICKY . ''; else @@ -231,7 +231,7 @@ } public function build($index=false) { - global $board, $mod; + global $board; $built = '

        File: ' . $this->file . ' (' . // Filesize @@ -262,7 +262,7 @@ . (!empty($this->trip) ? ' '.$this->trip.'':''); // IP Address - if($mod && $mod['type'] >= MOD_SHOW_IP) { + if($this->mod && $this->mod['type'] >= MOD_SHOW_IP) { $built .= ' [' . $this->ip . ']'; } diff --git a/inc/functions.php b/inc/functions.php index 2ba34827..36ee9807 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -131,7 +131,7 @@ if($query->rowcount() < 1 && $page > 1) return false; while($th = $query->fetch()) { - $thread = new Thread($th['id'], $th['subject'], $th['email'], $th['name'], $th['trip'], $th['body'], $th['time'], $th['thumb'], $th['thumbwidth'], $th['thumbheight'], $th['file'], $th['filewidth'], $th['fileheight'], $th['filesize'], $th['filename'], $th['ip'], $th['sticky'], $mod ? '?/' : ROOT); + $thread = new Thread($th['id'], $th['subject'], $th['email'], $th['name'], $th['trip'], $th['body'], $th['time'], $th['thumb'], $th['thumbwidth'], $th['thumbheight'], $th['file'], $th['filewidth'], $th['fileheight'], $th['filesize'], $th['filename'], $th['ip'], $th['sticky'], $mod ? '?/' : ROOT, $mod); $posts = prepare(sprintf("SELECT `id`, `subject`, `email`, `name`, `trip`, `body`, `time`, `thumb`, `thumbwidth`, `thumbheight`, `file`, `filewidth`, `fileheight`, `filesize`, `filename`,`ip` FROM `posts_%s` WHERE `thread` = ? ORDER BY `time` DESC LIMIT ?", $board['uri'])); $posts->bindValue(1, $th['id']); @@ -151,7 +151,7 @@ } while($po = $posts->fetch()) { - $thread->add(new Post($po['id'], $th['id'], $po['subject'], $po['email'], $po['name'], $po['trip'], $po['body'], $po['time'], $po['thumb'], $po['thumbwidth'], $po['thumbheight'], $po['file'], $po['filewidth'], $po['fileheight'], $po['filesize'], $po['filename'], $po['ip'], $mod ? '?/' : ROOT)); + $thread->add(new Post($po['id'], $th['id'], $po['subject'], $po['email'], $po['name'], $po['trip'], $po['body'], $po['time'], $po['thumb'], $po['thumbwidth'], $po['thumbheight'], $po['file'], $po['filewidth'], $po['fileheight'], $po['filesize'], $po['filename'], $po['ip'], $mod ? '?/' : ROOT, $mod)); } $thread->posts = array_reverse($thread->posts); @@ -319,9 +319,9 @@ while($post = $query->fetch()) { if(!isset($thread)) { - $thread = new Thread($post['id'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['sticky'], $mod ? '?/' : ROOT); + $thread = new Thread($post['id'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['sticky'], $mod ? '?/' : ROOT, $mod); } else { - $thread->add(new Post($post['id'], $thread->id, $post['subject'], $post['email'], $post['name'], $post['trip'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $mod ? '?/' : ROOT)); + $thread->add(new Post($post['id'], $thread->id, $post['subject'], $post['email'], $post['name'], $post['trip'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $mod ? '?/' : ROOT, $mod)); } } diff --git a/inc/mod.php b/inc/mod.php index a2ee93ce..c73b72f0 100644 --- a/inc/mod.php +++ b/inc/mod.php @@ -159,7 +159,12 @@ // Delete file @unlink($board['dir'] . DIR_IMG . $post['file']); + // Update database + $query = prepare(sprintf("UPDATE `posts_%s` SET `thumb` = NULL, `thumbwidth` = NULL, `thumbheight` = NULL, `filewidth` = NULL, `fileheight` = NULL, `filesize` = NULL, `filename` = NULL, `filehash` = NULL, `file` = 'deleted' WHERE `id` = :id OR `thread` = :id", $board['uri'])); + $query->bindValue(':id', $id, PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + buildThread($post['thread']); } // Delete a post (reply or thread) diff --git a/mod.php b/mod.php index 6bce948f..be9268a0 100644 --- a/mod.php +++ b/mod.php @@ -219,7 +219,7 @@ if(!openBoard($boardName)) error(ERROR_NOBOARD); - if(!$page = index(empty($matches[2]) || $matches[2] == FILE_INDEX ? 1 : $matches[2], true)) { + if(!$page = index(empty($matches[2]) || $matches[2] == FILE_INDEX ? 1 : $matches[2], $mod)) { error(ERROR_404); } $page['pages'] = getPages(true); @@ -235,9 +235,31 @@ if(!openBoard($boardName)) error(ERROR_NOBOARD); - $page = buildThread($thread, true, true); + $page = buildThread($thread, true, $mod); echo $page; + } elseif(preg_match('/^\/' . $regex['board'] . 'deletefile\/(\d+)$/', $query, $matches)) { + if($mod['type'] < MOD_DELETEFILE) error(ERROR_NOACCESS); + // Delete file from post + + $boardName = $matches[1]; + $post = $matches[2]; + // Open board + if(!openBoard($boardName)) + error(ERROR_NOBOARD); + + // Delete post + deleteFile($post); + // Rebuild board + buildIndex(); + + + // Redirect + if(isset($_SERVER['HTTP_REFERER'])) + header('Location: ' . $_SERVER['HTTP_REFERER'], true, REDIRECT_HTTP); + else + header('Location: ?/' . sprintf(BOARD_PATH, $boardName) . FILE_INDEX, true, REDIRECT_HTTP); + } elseif(preg_match('/^\/' . $regex['board'] . 'delete\/(\d+)$/', $query, $matches)) { if($mod['type'] < MOD_DELETE) error(ERROR_NOACCESS); // Delete post -- cgit v1.3 From ca7faa835ea8ed5004c66f81b4fb9cecc639bb5d Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Sun, 2 Jan 2011 00:27:30 +1100 Subject: Basic ban-adding --- inc/mod.php | 45 +++++++++++++++++++++++++---- mod.php | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+), 6 deletions(-) (limited to 'mod.php') diff --git a/inc/mod.php b/inc/mod.php index 1058cca8..4670dc8d 100644 --- a/inc/mod.php +++ b/inc/mod.php @@ -111,24 +111,57 @@ return $body; } + function form_newBan($ip=null, $reason='', $continue=false) { + return '

        New ban' . + '
        ' . + ($continue ? '' : '') . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '
        ' . + ' (eg. "2d1h30m" or "2 days")
        ' . + '
        ' . + '
        '; + } + function form_newBoard() { return '
        New board' . '
        ' . '' . '' . - '' . + '' . '' . '' . '' . - '' . + '' . '' . '' . '' . - '' . + '' . '' . '' . '' . '' . diff --git a/mod.php b/mod.php index be9268a0..57c385b2 100644 --- a/mod.php +++ b/mod.php @@ -280,7 +280,102 @@ header('Location: ' . $_SERVER['HTTP_REFERER'], true, REDIRECT_HTTP); else header('Location: ?/' . sprintf(BOARD_PATH, $boardName) . FILE_INDEX, true, REDIRECT_HTTP); + } elseif(preg_match('/^\/' . $regex['board'] . 'ban\/(\d+)$/', $query, $matches)) { + if($mod['type'] < MOD_DELETE) error(ERROR_NOACCESS); + // Ban by post + + $boardName = $matches[1]; + $post = $matches[2]; + // Open board + if(!openBoard($boardName)) + error(ERROR_NOBOARD); + + // Delete post + //deletePost($post); + // Rebuild board + //buildIndex(); + + $query = prepare(sprintf("SELECT `ip`,`id` FROM `posts_%s` WHERE `id` = :id LIMIT 1", $board['uri'])); + $query->bindValue(':id', $post, PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + if($query->rowCount() < 1) { + error(ERROR_INVALIDPOST); + } + + $post = $query->fetch(); + + if(isset($_POST['new_ban'])) { + if( !isset($_POST['ip']) || + !isset($_POST['reason']) || + !isset($_POST['length']) + ) error(ERROR_MISSEDAFIELD); + + // Check required fields + if(empty($_POST['ip'])) + error(sprintf(ERROR_REQUIRED, 'IP address')); + + $query = prepare("INSERT INTO `bans` VALUES (:ip, :mod, :expires, :reason)"); + + // 1yr2hrs30mins + // 1y2h30m + if(preg_match('/^((\d+)\s?ye?a?r?s?)?\s?+((\d+)\s?we?e?k?s?)?\s?+((\d+)\s?da?y?s?)?((\d+)\s?ho?u?r?s?)?\s?+((\d+)\s?m?i?n?u?t?e?s?)?\s?+((\d+)\s?s?e?c?o?n?d?s?)?$/', $_POST['length'], $m)) { + $expire = 0; + if(isset($m[2])) { + // Years + $expire += $m[2]*60*60*24*7*52; + } + if(isset($m[4])) { + // Weeks + $expire += $m[4]*60*60*24*7; + } + if(isset($m[6])) { + // Days + $expire += $m[6]*60*60*24; + } + if(isset($m[8])) { + // Hours + $expire += $m[8]*60*60; + } + if(isset($m[10])) { + // Minutes + $expire += $m[10]*60; + } + if(isset($m[12])) { + // Seconds + $expire += $m[12]; + } + $query->bindValue(':expires', time()+$expire, PDO::PARAM_INT); + } else { + // Never expire + $query->bindValue(':expires', null, PDO::PARAM_NULL); + } + + $query->bindValue(':ip', $_POST['ip'], PDO::PARAM_STR); + $query->bindValue(':mod', $mod['id'], PDO::PARAM_INT); + if(isset($_POST['reason'])) { + $query->bindValue(':reason', $_POST['reason'], PDO::PARAM_STR); + } else { + $query->bindValue(':reason', null, PDO::PARAM_NULL); + } + $query->execute() or error(db_error($query)); + + // Redirect + if(isset($_POST['continue'])) + header('Location: ' . $_POST['continue'], true, REDIRECT_HTTP); + else + header('Location: ?/' . sprintf(BOARD_PATH, $boardName) . FILE_INDEX, true, REDIRECT_HTTP); + } + + $body = form_newBan($post['ip'], null, isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false); + + echo Element('page.html', Array( + 'index'=>ROOT, + 'title'=>'New ban', + 'body'=>$body, + 'mod'=>true + ) + ); } else { error(ERROR_404); } -- cgit v1.3 From ed693335804765c4784a7cf24c718a43e5fb69bc Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Sun, 2 Jan 2011 02:05:30 +1100 Subject: Block banned clients from accessing the moderation panel --- mod.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'mod.php') diff --git a/mod.php b/mod.php index 57c385b2..35261e3f 100644 --- a/mod.php +++ b/mod.php @@ -8,6 +8,12 @@ require 'inc/template.php'; require 'inc/database.php'; require 'inc/user.php'; + + sql_open(); + + // Check if banned + checkBan(); + require 'inc/mod.php'; // Fix some encoding issues @@ -23,8 +29,6 @@ empty($_POST['password']) ) loginForm(ERROR_INVALID, $_POST['username']); - // Open connection - sql_open(); if(!login($_POST['username'], $_POST['password'])) loginForm(ERROR_INVALID, $_POST['username']); @@ -315,7 +319,7 @@ if(empty($_POST['ip'])) error(sprintf(ERROR_REQUIRED, 'IP address')); - $query = prepare("INSERT INTO `bans` VALUES (:ip, :mod, :expires, :reason)"); + $query = prepare("INSERT INTO `bans` VALUES (:ip, :mod, :set, :expires, :reason)"); // 1yr2hrs30mins // 1y2h30m @@ -353,6 +357,8 @@ $query->bindValue(':ip', $_POST['ip'], PDO::PARAM_STR); $query->bindValue(':mod', $mod['id'], PDO::PARAM_INT); + $query->bindValue(':set', time(), PDO::PARAM_INT); + if(isset($_POST['reason'])) { $query->bindValue(':reason', $_POST['reason'], PDO::PARAM_STR); } else { -- cgit v1.3 From a3143b5b3da3a9781b3e63826041e3b6a7f8b70e Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Sun, 2 Jan 2011 21:27:28 +1100 Subject: Stickies --- mod.php | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'mod.php') diff --git a/mod.php b/mod.php index 35261e3f..69d8dafe 100644 --- a/mod.php +++ b/mod.php @@ -263,7 +263,6 @@ header('Location: ' . $_SERVER['HTTP_REFERER'], true, REDIRECT_HTTP); else header('Location: ?/' . sprintf(BOARD_PATH, $boardName) . FILE_INDEX, true, REDIRECT_HTTP); - } elseif(preg_match('/^\/' . $regex['board'] . 'delete\/(\d+)$/', $query, $matches)) { if($mod['type'] < MOD_DELETE) error(ERROR_NOACCESS); // Delete post @@ -279,6 +278,36 @@ // Rebuild board buildIndex(); + // Redirect + if(isset($_SERVER['HTTP_REFERER'])) + header('Location: ' . $_SERVER['HTTP_REFERER'], true, REDIRECT_HTTP); + else + header('Location: ?/' . sprintf(BOARD_PATH, $boardName) . FILE_INDEX, true, REDIRECT_HTTP); + } elseif(preg_match('/^\/' . $regex['board'] . '(un)?sticky\/(\d+)$/', $query, $matches)) { + if($mod['type'] < MOD_DELETE) error(ERROR_NOACCESS); + // Ban by post + + $boardName = $matches[1]; + $post = $matches[3]; + // Open board + if(!openBoard($boardName)) + error(ERROR_NOBOARD); + + $query = prepare(sprintf("UPDATE `posts_%s` SET `sticky` = :sticky WHERE `id` = :id AND `thread` IS NULL", $board['uri'])); + $query->bindValue(':id', $post, PDO::PARAM_INT); + + if($matches[2] == 'un') { + $query->bindValue(':sticky', 0, PDO::PARAM_INT); + } else { + $query->bindValue(':sticky', 1, PDO::PARAM_INT); + } + + $query->execute() or error(db_error($query)); + + buildIndex(); + buildThread($post); + + // Redirect if(isset($_SERVER['HTTP_REFERER'])) header('Location: ' . $_SERVER['HTTP_REFERER'], true, REDIRECT_HTTP); @@ -294,11 +323,6 @@ if(!openBoard($boardName)) error(ERROR_NOBOARD); - // Delete post - //deletePost($post); - // Rebuild board - //buildIndex(); - $query = prepare(sprintf("SELECT `ip`,`id` FROM `posts_%s` WHERE `id` = :id LIMIT 1", $board['uri'])); $query->bindValue(':id', $post, PDO::PARAM_INT); $query->execute() or error(db_error($query)); -- cgit v1.3 From f1f68b0e7eedc26ea507e039bafffb20a083f918 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Sun, 2 Jan 2011 21:34:04 +1100 Subject: Fixed ban lengths --- mod.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'mod.php') diff --git a/mod.php b/mod.php index 69d8dafe..7d821f1d 100644 --- a/mod.php +++ b/mod.php @@ -347,8 +347,8 @@ // 1yr2hrs30mins // 1y2h30m - if(preg_match('/^((\d+)\s?ye?a?r?s?)?\s?+((\d+)\s?we?e?k?s?)?\s?+((\d+)\s?da?y?s?)?((\d+)\s?ho?u?r?s?)?\s?+((\d+)\s?m?i?n?u?t?e?s?)?\s?+((\d+)\s?s?e?c?o?n?d?s?)?$/', $_POST['length'], $m)) { - $expire = 0; + $expire = 0; + if(preg_match('/^((\d+)\s?ye?a?r?s?)?\s?+((\d+)\s?we?e?k?s?)?\s?+((\d+)\s?da?y?s?)?((\d+)\s?ho?u?r?s?)?\s?+((\d+)?mi?n?u?t?e?s?)?\s?+((\d+)\s?se?c?o?n?d?s?)?$/', $_POST['length'], $m)) { if(isset($m[2])) { // Years $expire += $m[2]*60*60*24*7*52; @@ -373,6 +373,8 @@ // Seconds $expire += $m[12]; } + } + if($expire) { $query->bindValue(':expires', time()+$expire, PDO::PARAM_INT); } else { // Never expire -- cgit v1.3 From cff02371ce9e638dcff5db152a49f5e437d4eb58 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Sun, 2 Jan 2011 21:34:31 +1100 Subject: Fixed permissions typo in stickies --- mod.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mod.php') diff --git a/mod.php b/mod.php index 7d821f1d..a06c424a 100644 --- a/mod.php +++ b/mod.php @@ -284,7 +284,7 @@ else header('Location: ?/' . sprintf(BOARD_PATH, $boardName) . FILE_INDEX, true, REDIRECT_HTTP); } elseif(preg_match('/^\/' . $regex['board'] . '(un)?sticky\/(\d+)$/', $query, $matches)) { - if($mod['type'] < MOD_DELETE) error(ERROR_NOACCESS); + if($mod['type'] < MOD_STICKY) error(ERROR_NOACCESS); // Ban by post $boardName = $matches[1]; -- cgit v1.3 From cb4ebae191db86ab8bdb4414af9b0ea340a61caf Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Mon, 3 Jan 2011 02:00:30 +1100 Subject: Unlock/lock operations --- mod.php | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'mod.php') diff --git a/mod.php b/mod.php index a06c424a..150ab6a5 100644 --- a/mod.php +++ b/mod.php @@ -285,7 +285,7 @@ header('Location: ?/' . sprintf(BOARD_PATH, $boardName) . FILE_INDEX, true, REDIRECT_HTTP); } elseif(preg_match('/^\/' . $regex['board'] . '(un)?sticky\/(\d+)$/', $query, $matches)) { if($mod['type'] < MOD_STICKY) error(ERROR_NOACCESS); - // Ban by post + // Add/remove sticky $boardName = $matches[1]; $post = $matches[3]; @@ -308,6 +308,36 @@ buildThread($post); + // Redirect + if(isset($_SERVER['HTTP_REFERER'])) + header('Location: ' . $_SERVER['HTTP_REFERER'], true, REDIRECT_HTTP); + else + header('Location: ?/' . sprintf(BOARD_PATH, $boardName) . FILE_INDEX, true, REDIRECT_HTTP); + } elseif(preg_match('/^\/' . $regex['board'] . '(un)?lock\/(\d+)$/', $query, $matches)) { + if($mod['type'] < MOD_LOCK) error(ERROR_NOACCESS); + // Lock/Unlock + + $boardName = $matches[1]; + $post = $matches[3]; + // Open board + if(!openBoard($boardName)) + error(ERROR_NOBOARD); + + $query = prepare(sprintf("UPDATE `posts_%s` SET `locked` = :locked WHERE `id` = :id AND `thread` IS NULL", $board['uri'])); + $query->bindValue(':id', $post, PDO::PARAM_INT); + + if($matches[2] == 'un') { + $query->bindValue(':locked', 0, PDO::PARAM_INT); + } else { + $query->bindValue(':locked', 1, PDO::PARAM_INT); + } + + $query->execute() or error(db_error($query)); + + buildIndex(); + buildThread($post); + + // Redirect if(isset($_SERVER['HTTP_REFERER'])) header('Location: ' . $_SERVER['HTTP_REFERER'], true, REDIRECT_HTTP); -- cgit v1.3 From 714e531303d6406a41c9b3b82c7f14964028d133 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Mon, 3 Jan 2011 02:04:32 +1100 Subject: Changed years expire time to 365 days instead of 52 weeks --- mod.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mod.php') diff --git a/mod.php b/mod.php index 150ab6a5..7c910a4a 100644 --- a/mod.php +++ b/mod.php @@ -381,7 +381,7 @@ if(preg_match('/^((\d+)\s?ye?a?r?s?)?\s?+((\d+)\s?we?e?k?s?)?\s?+((\d+)\s?da?y?s?)?((\d+)\s?ho?u?r?s?)?\s?+((\d+)?mi?n?u?t?e?s?)?\s?+((\d+)\s?se?c?o?n?d?s?)?$/', $_POST['length'], $m)) { if(isset($m[2])) { // Years - $expire += $m[2]*60*60*24*7*52; + $expire += $m[2]*60*60*24*365; } if(isset($m[4])) { // Weeks -- cgit v1.3 From 05712d745713944e2e2535879f1cc82fdae2070f Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Mon, 3 Jan 2011 17:28:18 +1100 Subject: Check if board already exists when creating it --- inc/config.php | 1 + mod.php | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'mod.php') diff --git a/inc/config.php b/inc/config.php index 521d3eb3..7bd2228c 100644 --- a/inc/config.php +++ b/inc/config.php @@ -81,6 +81,7 @@ define('ERROR_MISSEDAFIELD', 'Your browser didn\'t submit an input when it should have.', true); define('ERROR_REQUIRED', 'The %s field is required.', true); define('ERROR_INVALIDFIELD', 'The %s field was invalid.', true); + define('ERROR_BOARDEXISTS', 'There is already a %s board.', true); define('ERROR_NOACCESS', 'You don\'t have permission to do that.', true); define('ERROR_INVALIDPOST', 'That post doesn\'t exist…', true); define('ERROR_404', 'Page not found.', true); diff --git a/mod.php b/mod.php index 7c910a4a..00f4ab96 100644 --- a/mod.php +++ b/mod.php @@ -183,6 +183,9 @@ if(!preg_match('/^\w+$/', $b['uri'])) error(sprintf(ERROR_INVALIDFIELD, 'URI')); + if(openBoard($b['uri'])) + error(sprintf(ERROR_BOARDEXISTS, sprintf(BOARD_ABBREVIATION, $b['uri']))); + $query = prepare("INSERT INTO `boards` VALUES (NULL, :uri, :title, :subtitle)"); $query->bindValue(':uri', $b['uri']); $query->bindValue(':title', $b['title']); @@ -378,7 +381,7 @@ // 1yr2hrs30mins // 1y2h30m $expire = 0; - if(preg_match('/^((\d+)\s?ye?a?r?s?)?\s?+((\d+)\s?we?e?k?s?)?\s?+((\d+)\s?da?y?s?)?((\d+)\s?ho?u?r?s?)?\s?+((\d+)?mi?n?u?t?e?s?)?\s?+((\d+)\s?se?c?o?n?d?s?)?$/', $_POST['length'], $m)) { + if(preg_match('/^((\d+)\s?ye?a?r?s?)?\s?+((\d+)\s?we?e?k?s?)?\s?+((\d+)\s?da?y?s?)?((\d+)\s?ho?u?r?s?)?\s?+((\d+)\s?mi?n?u?t?e?s?)?\s?+((\d+)\s?se?c?o?n?d?s?)?$/', $_POST['length'], $m)) { if(isset($m[2])) { // Years $expire += $m[2]*60*60*24*365; -- cgit v1.3 From dbae5dbf56a6659b5c06740e8e41cdc5fecbc1d0 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Mon, 3 Jan 2011 17:30:17 +1100 Subject: Remove "return to board" link when showing "board already exists" error --- mod.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'mod.php') diff --git a/mod.php b/mod.php index 00f4ab96..41e593c9 100644 --- a/mod.php +++ b/mod.php @@ -183,8 +183,10 @@ if(!preg_match('/^\w+$/', $b['uri'])) error(sprintf(ERROR_INVALIDFIELD, 'URI')); - if(openBoard($b['uri'])) + if(openBoard($b['uri'])) { + unset($board); error(sprintf(ERROR_BOARDEXISTS, sprintf(BOARD_ABBREVIATION, $b['uri']))); + } $query = prepare("INSERT INTO `boards` VALUES (NULL, :uri, :title, :subtitle)"); $query->bindValue(':uri', $b['uri']); -- cgit v1.3 From a0ef70beab3ddcc1d61016d65f9687594d0db5b9 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Sat, 15 Jan 2011 15:05:58 +1100 Subject: "ban&delete" --- mod.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'mod.php') diff --git a/mod.php b/mod.php index 41e593c9..ecdfedcf 100644 --- a/mod.php +++ b/mod.php @@ -348,12 +348,13 @@ header('Location: ' . $_SERVER['HTTP_REFERER'], true, REDIRECT_HTTP); else header('Location: ?/' . sprintf(BOARD_PATH, $boardName) . FILE_INDEX, true, REDIRECT_HTTP); - } elseif(preg_match('/^\/' . $regex['board'] . 'ban\/(\d+)$/', $query, $matches)) { + } elseif(preg_match('/^\/' . $regex['board'] . 'ban(&delete)\/(\d+)$/', $query, $matches)) { if($mod['type'] < MOD_DELETE) error(ERROR_NOACCESS); // Ban by post $boardName = $matches[1]; - $post = $matches[2]; + $delete = isset($matches[2]) && $matches[2] == '&delete'; + $post = $matches[3]; // Open board if(!openBoard($boardName)) error(ERROR_NOBOARD); @@ -427,6 +428,10 @@ } $query->execute() or error(db_error($query)); + // Delete too + if($delete) + deletePost($post['id']); + // Redirect if(isset($_POST['continue'])) header('Location: ' . $_POST['continue'], true, REDIRECT_HTTP); -- cgit v1.3 From c2727787aba5cf837af747cfb8b5c61c750c1581 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Sat, 15 Jan 2011 15:29:05 +1100 Subject: Basic "IP" page --- inc/config.php | 6 ++++++ mod.php | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) (limited to 'mod.php') diff --git a/inc/config.php b/inc/config.php index 7bd2228c..ae79edc4 100644 --- a/inc/config.php +++ b/inc/config.php @@ -164,6 +164,12 @@ define('MOD_DEFAULT', '/', true); // Don't even display MySQL password to administrators (in the configuration page) define('MOD_NEVER_REAL_PASSWORD', true, true); + // Do a DNS lookup on IP addresses to get their hostname on the IP summary page + define('MOD_DNS_LOOKUP', true, true); + // Show ban form on the IP summary page + define('MOD_IP_BANFORM', true, true); + // How many recent posts, per board, to show in the IP summary page + define('MOD_IP_RECENTPOSTS', 5, true); // Probably best not to change these: define('MOD_JANITOR', 0, true); diff --git a/mod.php b/mod.php index ecdfedcf..f93430b8 100644 --- a/mod.php +++ b/mod.php @@ -448,6 +448,46 @@ 'mod'=>true ) ); + } elseif(preg_match('/^\/IP\/(\d+\.\d+\.\d+\.\d+)$/', $query, $matches)) { + // View information on an IP address + + $ip = $matches[1]; + $host = MOD_DNS_LOOKUP ? gethostbyaddr($ip) : false; + + $body = ''; + $boards = listBoards(); + foreach($boards as &$_board) { + openBoard($_board['uri']); + + $temp = ''; + $query = prepare(sprintf("SELECT * FROM `posts_%s` WHERE `ip` = :ip ORDER BY `sticky` DESC, `time` LIMIT :limit", $_board['uri'])); + $query->bindValue(':ip', $ip); + $query->bindValue(':limit', MOD_IP_RECENTPOSTS, PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + + while($post = $query->fetch()) { + $po = new Post($post['id'], $post['thread'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $mod ? '?/' : ROOT, $mod); + $temp .= $po->build(); + } + if(!empty($temp)) + $body .= '
        Last ' . $query->rowCount() . ' posts on ' . + sprintf(BOARD_ABBREVIATION, $_board['uri']) . ' - ' . $_board['title'] . + '' . $temp . '
        '; + } + + if(MOD_IP_BANFORM) + $body .= form_newBan($ip, null, isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false); + + echo Element('page.html', Array( + 'index'=>ROOT, + 'title'=>'IP: ' . $ip, + 'subtitle' => $host, + 'body'=>$body, + 'mod'=>true + ) + ); } else { error(ERROR_404); } -- cgit v1.3 From f47cccab019f3e7882a188c7d09e3070eb8f82ce Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Sat, 15 Jan 2011 15:37:39 +1100 Subject: fixed ban addition page --- inc/mod.php | 6 ++++-- mod.php | 50 +++++++++++++++++++++++++++----------------------- 2 files changed, 31 insertions(+), 25 deletions(-) (limited to 'mod.php') diff --git a/inc/mod.php b/inc/mod.php index 23ec43af..a325d589 100644 --- a/inc/mod.php +++ b/inc/mod.php @@ -111,10 +111,12 @@ return $body; } - function form_newBan($ip=null, $reason='', $continue=false) { + function form_newBan($ip=null, $reason='', $continue=false, $delete=false, $board=false) { return '
        New ban' . - '' . + '' . ($continue ? '' : '') . + ($delete ? '' : '') . + ($board ? '' : '') . '
        ' . - ' (eg. "b"; "mu")' . + ' (eg. "b"; "mu")
        ' . - ' (eg. "Random")' . + ' (eg. "Random")
        ' . - ' (optional)' . + ' (optional)
        ' . '' . '' . diff --git a/mod.php b/mod.php index f93430b8..b4355fe4 100644 --- a/mod.php +++ b/mod.php @@ -348,26 +348,8 @@ header('Location: ' . $_SERVER['HTTP_REFERER'], true, REDIRECT_HTTP); else header('Location: ?/' . sprintf(BOARD_PATH, $boardName) . FILE_INDEX, true, REDIRECT_HTTP); - } elseif(preg_match('/^\/' . $regex['board'] . 'ban(&delete)\/(\d+)$/', $query, $matches)) { - if($mod['type'] < MOD_DELETE) error(ERROR_NOACCESS); - // Ban by post - - $boardName = $matches[1]; - $delete = isset($matches[2]) && $matches[2] == '&delete'; - $post = $matches[3]; - // Open board - if(!openBoard($boardName)) - error(ERROR_NOBOARD); - - $query = prepare(sprintf("SELECT `ip`,`id` FROM `posts_%s` WHERE `id` = :id LIMIT 1", $board['uri'])); - $query->bindValue(':id', $post, PDO::PARAM_INT); - $query->execute() or error(db_error($query)); - - if($query->rowCount() < 1) { - error(ERROR_INVALIDPOST); - } - - $post = $query->fetch(); + } elseif(preg_match('/^\/ban$/', $query)) { + // Ban page if(isset($_POST['new_ban'])) { if( !isset($_POST['ip']) || @@ -429,8 +411,10 @@ $query->execute() or error(db_error($query)); // Delete too - if($delete) - deletePost($post['id']); + if($mod['type'] >= MOD_DELETE && isset($_POST['delete']) && isset($_POST['board'])) { + openBoard($_POST['board']); + deletePost(round($_POST['delete'])); + } // Redirect if(isset($_POST['continue'])) @@ -438,8 +422,28 @@ else header('Location: ?/' . sprintf(BOARD_PATH, $boardName) . FILE_INDEX, true, REDIRECT_HTTP); } + } elseif(preg_match('/^\/' . $regex['board'] . 'ban(&delete)?\/(\d+)$/', $query, $matches)) { + if($mod['type'] < MOD_DELETE) error(ERROR_NOACCESS); + // Ban by post + + $boardName = $matches[1]; + $delete = isset($matches[2]) && $matches[2] == '&delete'; + $post = $matches[3]; + // Open board + if(!openBoard($boardName)) + error(ERROR_NOBOARD); + + $query = prepare(sprintf("SELECT `ip`,`id` FROM `posts_%s` WHERE `id` = :id LIMIT 1", $board['uri'])); + $query->bindValue(':id', $post, PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + + if($query->rowCount() < 1) { + error(ERROR_INVALIDPOST); + } + + $post = $query->fetch(); - $body = form_newBan($post['ip'], null, isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false); + $body = form_newBan($post['ip'], null, isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false, $delete ? $post['id'] : false, $delete ? $boardName : false); echo Element('page.html', Array( 'index'=>ROOT, -- cgit v1.3 From c59f36f400eb718714154fa1ab125662bc7b89ea Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Wed, 19 Jan 2011 12:37:31 +1100 Subject: a bunch of things --- inc/config.php | 21 ++++++++++++++++++--- inc/functions.php | 35 ++++++++++++++++++++++++++++++++--- mod.php | 2 +- post.php | 45 ++++++++++++++++++++++++++++++++++++++++----- style.css | 4 ++++ templates/posts.sql | 2 +- templates/thread.html | 1 + 7 files changed, 97 insertions(+), 13 deletions(-) (limited to 'mod.php') diff --git a/inc/config.php b/inc/config.php index 746efb63..65346edd 100644 --- a/inc/config.php +++ b/inc/config.php @@ -41,7 +41,8 @@ define('COOKIE_EXPIRE', 15778463, true); //6 months // Make this something long and random for security define('SALT', 'wefaw98YHEWUFuo', true); - + define('SECURE_TRIP_SALT', '@#$&^@#)$(*&@!_$(&329-8347', true); + // How many seconds before you can post, after the first visit define('LURKTIME', 30, true); @@ -51,6 +52,8 @@ define('FLOOD_TIME_IP_SAME', 120, true); // Same as above but different IP address define('FLOOD_TIME_SAME', 30, true); + // Do you need a body for your non-OP posts? + define('FORCE_BODY', true, true); // Max body length define('MAX_BODY', 1800, true); @@ -77,6 +80,9 @@ define('ERROR_NOPOST', 'You didn\'t make a post.', true); define('ERROR_FLOOD', 'Flood detected; Post discared.', true); define('ERROR_UNORIGINAL', 'Unoriginal content!', true); + define('ERROR_MUTED', 'Unoriginal content! You have been muted for %d seconds.', true); + define('ERROR_TOR', 'Hmm… That looks like a Tor exit node.', true); + define('ERROR_TOOMANYLINKS', 'Too many links; flood detected.', true); define('ERR_INVALIDIMG','Invalid image.', true); define('ERR_FILESIZE', 'Maximum file size: %maxsz% bytes
        Your file\'s size: %filesz% bytes', true); define('ERR_MAXSIZE', 'The file was too big.', true); @@ -103,7 +109,11 @@ // Function name for hashing // sha1_file, md5_file, etc. define('FILE_HASH', 'sha1_file', true); - + + define('BLOCK_TOR', true, true); + // Typically spambots try to post a lot of links. Refuse a post with X standalone links? + define('MAX_LINKS', 7, true); + // Maximum image upload size in bytes define('MAX_FILESIZE', 10*1024*1024, true); // 10MB // Maximum image dimensions @@ -167,8 +177,13 @@ // Robot stuff // Strip repeating characters when making hashes define('ROBOT_ENABLE', true, true); + define('ROBOT_BOARD', 'r9k', true); define('ROBOT_STRIP_REPEATING', true, true); - + // Enable mutes + define('ROBOT_MUTE', true, true); + define('ROBOT_MUTE_MIN', 60, true); + define('ROBOT_MUTE_MAX', 120, true); + define('ROBOT_MUTE_DESCRIPTION', 'You have been muted for unoriginal content.', true); /* Mod stuff diff --git a/inc/functions.php b/inc/functions.php index 4f4a69bd..6193ab38 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -439,14 +439,43 @@ } } } + + function isDNSBL() { + $dns_black_lists = file('./dnsbl.txt', FILE_IGNORE_NEW_LINES); + + // Reverse the IP + $rev_ip = implode(array_reverse(explode('.', $_SERVER['REMOTE_ADDR'])), '.'); + $response = array(); + foreach ($dns_black_lists as $dns_black_list) { + $response = (gethostbynamel($rev_ip . '.' . $dns_black_list)); + if(!empty($response)) + return true; + } + + return false; + } + + function isTor() { + return gethostbyname( + ReverseIPOctets($_SERVER['REMOTE_ADDR']) . '.' . $_SERVER['SERVER_PORT'] . '.' . ReverseIPOctets($_SERVER['SERVER_ADDR']) . '.ip-port.exitlist.torproject.org' + ) == '127.0.0.2'; + } + + function ReverseIPOctets($inputip) { + $ipoc = explode('.', $inputip); + return $ipoc[3] . '.' . $ipoc[2] . '.' . $ipoc[1] . '.' . $ipoc[0]; + } function markup(&$body) { global $board; $body = utf8tohtml($body, true); - if(MARKUP_URLS) - $body = preg_replace(URL_REGEX, "$0", $body); + if(MARKUP_URLS) { + $body = preg_replace(URL_REGEX, "$0", $body, -1, $num_links); + if($num_links > MAX_LINKS) + error(ERROR_TOOMANYLINKS); + } if(AUTO_UNICODE) { $body = str_replace('...', '…', $body); @@ -602,7 +631,7 @@ $salt = strtr ( $salt, ':;<=>?@[\]^_`', 'ABCDEFGabcdef' ); if ( isset ( $t[2] ) ) { // secure - $trip = '!!' . substr ( crypt ( $trip, '@#$%^&*()' ), ( -1 * $length ) ); + $trip = '!!' . substr ( crypt ( $trip, SECURE_TRIP_SALT ), ( -1 * $length ) ); } else { // insecure $trip = '!' . substr ( crypt ( $trip, $salt ), ( -1 * $length ) ); diff --git a/mod.php b/mod.php index b4355fe4..80647471 100644 --- a/mod.php +++ b/mod.php @@ -464,7 +464,7 @@ openBoard($_board['uri']); $temp = ''; - $query = prepare(sprintf("SELECT * FROM `posts_%s` WHERE `ip` = :ip ORDER BY `sticky` DESC, `time` LIMIT :limit", $_board['uri'])); + $query = prepare(sprintf("SELECT * FROM `posts_%s` WHERE `ip` = :ip ORDER BY `sticky` DESC, `time` DESC LIMIT :limit", $_board['uri'])); $query->bindValue(':ip', $ip); $query->bindValue(':limit', MOD_IP_RECENTPOSTS, PDO::PARAM_INT); $query->execute() or error(db_error($query)); diff --git a/post.php b/post.php index 40830f0f..b8724522 100644 --- a/post.php +++ b/post.php @@ -62,6 +62,9 @@ // Check if banned checkBan(); + if(BLOCK_TOR && isTor()) + error(ERROR_TOR); + // Check if board exists if(!openBoard($post['board'])) error(ERROR_NOBOARD); @@ -85,6 +88,9 @@ $post['has_file'] = $OP || !empty($_FILES['file']['tmp_name']); $post['mod'] = isset($_POST['mod']) && $_POST['mod']; + if(empty($post['body']) && FORCE_BODY) + error(ERROR_TOOSHORTBODY); + if($post['mod']) { require 'inc/mod.php'; if(!$mod) { @@ -115,6 +121,15 @@ 'maxsz'=>commaize(MAX_FILESIZE)))); } + if($mod && $mod['type'] >= MOD_MOD && preg_match('/^((.+) )?## (.+)$/', $post['name'], $match)) { + if(($mod['type'] == MOD_MOD && $match[3] == 'Mod') || $mod['type'] >= MOD_ADMIN) { + $post['mod_tag'] = $match[3]; + $post['name'] = !empty($match[2])?$match[2]:'Anonymous'; + } + } else { + $post['mod_tag'] = false; + } + $trip = generate_tripcode($post['name']); $post['name'] = $trip[0]; $post['trip'] = (isset($trip[1])?$trip[1]:''); @@ -134,21 +149,40 @@ } // Check string lengths - if(strlen($post['name']) > 25) error(sprintf(ERROR_TOOLONG, 'name')); + if(strlen($post['name']) > 25) error(sprintf(ERROR_TOOLONG, 'name')); if(strlen($post['email']) > 30) error(sprintf(ERROR_TOOLONG, 'email')); if(strlen($post['subject']) > 40) error(sprintf(ERROR_TOOLONG, 'subject')); if(strlen($post['body']) > MAX_BODY) error(ERROR_TOOLONGBODY); if(!(!$OP && $post['has_file']) && strlen($post['body']) < 1) error(ERROR_TOOSHORTBODY); if(strlen($post['password']) > 20) error(sprintf(ERROR_TOOLONG, 'password')); + if($post['mod_tag']) + $post['trip'] .= ' ## ' . $post['mod_tag'] . ''; + + if(!($mod && $mod['type'] >= MOD_POSTUNORIGINAL) && ROBOT_ENABLE && $board['uri'] == ROBOT_BOARD && checkRobot($post['body'])) { + if(ROBOT_MUTE) { + $mutetime = ROBOT_MUTE_MIN+rand()%(ROBOT_MUTE_MAX-ROBOT_MUTE_MIN); + + $query = prepare("INSERT INTO `bans` VALUES (:ip, :mod, :set, :expires, :reason)"); + $query->bindValue(':ip', $_SERVER['REMOTE_ADDR']); + $query->bindValue(':mod', -1, PDO::PARAM_INT); + $query->bindValue(':set', time(), PDO::PARAM_INT); + $query->bindValue(':expires', time()+$mutetime, PDO::PARAM_INT); + $query->bindValue(':reason', ROBOT_MUTE_DESCRIPTION); + $query->execute() or error(db_error($query)); + + error(sprintf(ERROR_MUTED, $mutetime)); + } else { + error(ERROR_UNORIGINAL); + } + } + markup($post['body']); // Check for a flood - if(checkFlood($post)) + if(checkFlood($post)) { error(ERROR_FLOOD); - - if(!($mod && $mod['type'] >= MOD_POSTUNORIGINAL) && ROBOT_ENABLE && checkRobot($post['body'])) - error(ERROR_UNORIGINAL); + } if($post['has_file']) { // Just trim the filename if it's too long @@ -206,6 +240,7 @@ imagebmp($image, $post['file']); break; default: + unlink($post['file']); error('Unknwon file extension.'); } } diff --git a/style.css b/style.css index 60c36d19..058de230 100644 --- a/style.css +++ b/style.css @@ -146,6 +146,10 @@ p.intro span.name { color: #117743; font-weight: bold; } +p.intro a.nametag { + color: #F00000; + margin-left: 0; +} p.intro a { margin-left: 8px; } diff --git a/templates/posts.sql b/templates/posts.sql index 4163f125..f8e1b6fb 100644 --- a/templates/posts.sql +++ b/templates/posts.sql @@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS `posts_{board}` ( `subject` varchar(40) NOT NULL, `email` varchar(30) NOT NULL, `name` varchar(25) NOT NULL, - `trip` varchar(15) DEFAULT NULL, + `trip` varchar(45) DEFAULT NULL, `body` text NOT NULL, `time` int(11) NOT NULL, `bump` int(11) DEFAULT NULL, diff --git a/templates/thread.html b/templates/thread.html index 2fd03418..e1260ff5 100644 --- a/templates/thread.html +++ b/templates/thread.html @@ -71,6 +71,7 @@
        {body} + [Return.]

        Copyright © 2010 OmegaSDG

        \ No newline at end of file -- cgit v1.3 From d7f7b602efc6668557e1c0f544dd3bab0e677122 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Thu, 20 Jan 2011 19:25:11 +1100 Subject: ... --- mod.php | 17 +++++++++++++++++ templates/index.html | 3 ++- templates/thread.html | 3 ++- 3 files changed, 21 insertions(+), 2 deletions(-) (limited to 'mod.php') diff --git a/mod.php b/mod.php index 80647471..04b758f6 100644 --- a/mod.php +++ b/mod.php @@ -348,6 +348,23 @@ header('Location: ' . $_SERVER['HTTP_REFERER'], true, REDIRECT_HTTP); else header('Location: ?/' . sprintf(BOARD_PATH, $boardName) . FILE_INDEX, true, REDIRECT_HTTP); + } elseif(preg_match('/^\/' . $regex['board'] . 'deletebyip\/(\d+)$/', $query, $matches)) { + // Delete all posts by an IP + + $boardName = $matches[1]; + $post = $matches[2]; + // Open board + if(!openBoard($boardName)) + error(ERROR_NOBOARD); + + $query = prepare(sprintf("SELECT `id` FROM `posts_%s` WHERE `ip` = :ip", $board['uri'])); + $query->bindValue(':ip', $ip); + $query->execute() or error(db_error($query)); + + //if(isset($_SERVER['HTTP_REFERER'])) + // header('Location: ' . $_SERVER['HTTP_REFERER'], true, REDIRECT_HTTP); + //else + // header('Location: ?/' . sprintf(BOARD_PATH, $boardName) . FILE_INDEX, true, REDIRECT_HTTP); } elseif(preg_match('/^\/ban$/', $query)) { // Ban page diff --git a/templates/index.html b/templates/index.html index d0702ba9..acca2408 100644 --- a/templates/index.html +++ b/templates/index.html @@ -8,6 +8,7 @@ +

        {board[url]} - {board[name]}

        {board[title]?{board[title]}}

        {mod?Return to dashboard}

        @@ -38,7 +39,7 @@
        diff --git a/templates/thread.html b/templates/thread.html index e1260ff5..82867ec2 100644 --- a/templates/thread.html +++ b/templates/thread.html @@ -8,6 +8,7 @@ +

        {board[url]} - {board[name]}

        {board[title]?{board[title]}}

        {mod?Return to dashboard}

        @@ -39,7 +40,7 @@ -- cgit v1.3 From a3d22a79b7fc41f566f3ee07e1be4cc5b2108163 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Sat, 5 Feb 2011 15:43:42 +1100 Subject: Delete by IP --- mod.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'mod.php') diff --git a/mod.php b/mod.php index 04b758f6..c67bfd66 100644 --- a/mod.php +++ b/mod.php @@ -357,14 +357,21 @@ if(!openBoard($boardName)) error(ERROR_NOBOARD); - $query = prepare(sprintf("SELECT `id` FROM `posts_%s` WHERE `ip` = :ip", $board['uri'])); - $query->bindValue(':ip', $ip); + $query = prepare(sprintf("SELECT `id` FROM `posts_%s` WHERE `ip` = (SELECT `ip` FROM `posts_%s` WHERE `id` = :id)", $board['uri'], $board['uri'])); + $query->bindValue(':id', $post); $query->execute() or error(db_error($query)); - //if(isset($_SERVER['HTTP_REFERER'])) - // header('Location: ' . $_SERVER['HTTP_REFERER'], true, REDIRECT_HTTP); - //else - // header('Location: ?/' . sprintf(BOARD_PATH, $boardName) . FILE_INDEX, true, REDIRECT_HTTP); + if($query->rowCount() < 1) + error(ERROR_INVALIDPOST); + + while($post = $query->fetch()) { + deletePost($post['id'], false); + } + + if(isset($_SERVER['HTTP_REFERER'])) + header('Location: ' . $_SERVER['HTTP_REFERER'], true, REDIRECT_HTTP); + else + header('Location: ?/' . sprintf(BOARD_PATH, $boardName) . FILE_INDEX, true, REDIRECT_HTTP); } elseif(preg_match('/^\/ban$/', $query)) { // Ban page -- cgit v1.3 From bcfc8c4a70ba54b57582d244c8bcc683ef6d9cf7 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Mon, 7 Feb 2011 00:38:01 +1100 Subject: Started on ban list --- inc/config.php | 9 ++++++ mod.php | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) (limited to 'mod.php') diff --git a/inc/config.php b/inc/config.php index bf3956fe..f4040570 100644 --- a/inc/config.php +++ b/inc/config.php @@ -244,6 +244,15 @@ /* Administration */ // Display the contents of instant-config.php define('MOD_SHOW_CONFIG', MOD_ADMIN, true); + // View list of bans + define('MOD_VIEW_BANLIST', MOD_MOD, true); + // View the username of the mod who made a ban + define('MOD_VIEW_BANSTAFF', MOD_MOD, true); + // If the moderator doesn't fit the MOD_VIEW_BANSTAFF (previous) permission, + // show him just a "?" instead. Otherwise, it will be "Mod" or "Admin" + define('MOD_VIEW_BANQUESTIONMARK', false, true); + // Show expired bans in the ban list (they are kept in cache until the culprit returns) + define('MOD_VIEW_BANEXPIRED', true, true); // Create a new board define('MOD_NEWBOARD', MOD_ADMIN, true); diff --git a/mod.php b/mod.php index c67bfd66..c16676ad 100644 --- a/mod.php +++ b/mod.php @@ -19,6 +19,16 @@ // Fix some encoding issues header('Content-Type: text/html; charset=utf-8', true); + if (get_magic_quotes_gpc()) { + function strip_array($var) { + return is_array($var) ? array_map("strip_array", $var) : stripslashes($var); + } + + $_SESSION = strip_array($_SESSION); + $_GET = strip_array($_GET); + $_POST = strip_array($_POST); + } + // If not logged in if(!$mod) { if(isset($_POST['login'])) { @@ -69,6 +79,9 @@ // Boards $fieldset['Boards'] .= ulBoards(); + if($mod['type'] >= MOD_SHOW_CONFIG) { + $fieldset['Administration'] .= '
      • Ban list
      • '; + } if($mod['type'] >= MOD_SHOW_CONFIG) { $fieldset['Administration'] .= '
      • Show configuration
      • '; } @@ -88,6 +101,90 @@ //,'mod'=>true /* All 'mod' does, at this point, is put the "Return to dashboard" link in. */ ) ); + } elseif(preg_match('/^\/bans$/', $query)) { + if($mod['type'] < MOD_VIEW_BANLIST) error(ERROR_NOACCESS); + + if(MOD_VIEW_BANEXPIRED) { + $query = prepare("SELECT * FROM `bans` INNER JOIN `mods` ON `mod` = `id` GROUP BY `ip` ORDER BY `expires` < :time, `set` DESC"); + $query->bindValue(':time', time(), PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + } else { + // Filter out expired bans + $query = prepare("SELECT * FROM `bans` INNER JOIN `mods` ON `mod` = `id` GROUP BY `ip` WHERE `expires` = 0 OR `expires` > :time ORDER BY `set` DESC"); + $query->bindValue(':time', time(), PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + } + + if($query->rowCount() < 1) { + $body = '(There are no active bans.)'; + } else { + $body = '
        '; + $body .= '
        - +
        - +
        '; + + while($ban = $query->fetch()) { + $body .= + '' . + + '' . + + // Reason + '' . + + // Set + '' . + + // Expires + '' . + + // Staff + '' . + + '' . + + ''; + } + + $body .= '
        IP addressReasonSetExpiresStaffActions
        ' . + + // Checkbox + ' ' . + + // IP address + ''. $ban['ip'] . '' . $ban['reason'] . '' . date(POST_DATE, $ban['set']) . '' . + ($ban['expires'] == 0 ? + 'Never' + : + date(POST_DATE, $ban['expires']) + ) . + '' . + ($mod['type'] < MOD_VIEW_BANSTAFF ? + (MOD_VIEW_BANQUESTIONMARK ? + '?' + : + ($ban['type'] == MOD_JANITOR ? 'Janitor' : + ($ban['type'] == MOD_MOD ? 'Mod' : + ($ban['type'] == MOD_ADMIN ? 'Admin' : + '?'))) + ) + : + $ban['username'] + ) . + '
        '; + } + + echo Element('page.html', Array( + 'index'=>ROOT, + 'title'=>'Ban list', + 'body'=>$body, + 'mod'=>true + ) + ); } elseif(preg_match('/^\/config$/', $query)) { if($mod['type'] < MOD_SHOW_CONFIG) error(ERROR_NOACCESS); -- cgit v1.3 From 616c4179c96daa28d53341c09fccc15e87eb246b Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Mon, 7 Feb 2011 00:40:06 +1100 Subject: fixed small mistake --- mod.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mod.php') diff --git a/mod.php b/mod.php index c16676ad..43dd8d26 100644 --- a/mod.php +++ b/mod.php @@ -79,7 +79,7 @@ // Boards $fieldset['Boards'] .= ulBoards(); - if($mod['type'] >= MOD_SHOW_CONFIG) { + if($mod['type'] >= MOD_VIEW_BANLIST) { $fieldset['Administration'] .= '
      • Ban list
      • '; } if($mod['type'] >= MOD_SHOW_CONFIG) { -- cgit v1.3 From c34ea2e3af01d9a688fb14b3da550aa96615f312 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Fri, 11 Feb 2011 23:02:30 +1100 Subject: a Fixed delete by IP, plus a bunch of small stuff --- inc/functions.php | 12 ++++++++---- inc/mod.php | 12 +++++++++++- main.js | 7 +++++-- mod.php | 39 ++++++++++++++++++++++++++++++++++++++- post.php | 2 +- 5 files changed, 63 insertions(+), 9 deletions(-) (limited to 'mod.php') diff --git a/inc/functions.php b/inc/functions.php index c9b85ad4..6901de62 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -299,7 +299,7 @@ } // Delete a post (reply or thread) - function deletePost($id) { + function deletePost($id, $error_if_doesnt_exist=true) { global $board; // Select post and replies (if thread) in one query @@ -308,7 +308,9 @@ $query->execute() or error(db_error($query)); if($query->rowCount() < 1) { - error(ERROR_INVALIDPOST); + if($error_if_doesnt_exist) + error(ERROR_INVALIDPOST); + else return false; } // Delete posts and maybe replies @@ -337,6 +339,8 @@ if(isset($rebuild)) { buildThread($rebuild); } + + return true; } function clean() { @@ -370,7 +374,7 @@ while($th = $query->fetch()) { $thread = new Thread($th['id'], $th['subject'], $th['email'], $th['name'], $th['trip'], $th['body'], $th['time'], $th['thumb'], $th['thumbwidth'], $th['thumbheight'], $th['file'], $th['filewidth'], $th['fileheight'], $th['filesize'], $th['filename'], $th['ip'], $th['sticky'], $th['locked'], $mod ? '?/' : ROOT, $mod); - $posts = prepare(sprintf("SELECT `id`, `subject`, `email`, `name`, `trip`, `body`, `time`, `thumb`, `thumbwidth`, `thumbheight`, `file`, `filewidth`, `fileheight`, `filesize`, `filename`,`ip` FROM `posts_%s` WHERE `thread` = ? ORDER BY `time` DESC LIMIT ?", $board['uri'])); + $posts = prepare(sprintf("SELECT `id`, `subject`, `email`, `name`, `trip`, `body`, `time`, `thumb`, `thumbwidth`, `thumbheight`, `file`, `filewidth`, `fileheight`, `filesize`, `filename`,`ip` FROM `posts_%s` WHERE `thread` = ? ORDER BY `id` DESC LIMIT ?", $board['uri'])); $posts->bindValue(1, $th['id']); $posts->bindValue(2, THREADS_PREVIEW, PDO::PARAM_INT); $posts->execute() or error(db_error($posts)); @@ -859,7 +863,7 @@ switch($type) { case 'jpg': case 'jpeg': - if(!$image = imagecreatefromjpeg($source_pic)) { + if(!$image = @imagecreatefromjpeg($source_pic)) { unlink($source_pic); error(ERR_INVALIDIMG); } diff --git a/inc/mod.php b/inc/mod.php index 5a3e6157..115c595a 100644 --- a/inc/mod.php +++ b/inc/mod.php @@ -20,7 +20,7 @@ $query = prepare("SELECT `id`,`type` FROM `mods` WHERE `username` = :username AND `password` = :password LIMIT 1"); $query->bindValue(':username', $username); $query->bindValue(':password', $password); - $query->execute(); + $query->execute() or error(db_error($query)); if($user = $query->fetch()) { return $mod = Array( @@ -56,6 +56,16 @@ unset($_SESSION['mod']); } + function modLog($action) { + global $mod; + $query = prepare("INSERT INTO `modlogs` VALUES (:id, :ip, :time, :text)"); + $query->bindValue(':id', $mod['id'], PDO::PARAM_INT); + $query->bindValue(':ip', $_SERVER['REMOTE_ADDR']); + $query->bindValue(':time', time(), PDO::PARAM_INT); + $query->bindValue(':text', $action); + $query->execute() or error(db_error($query)); + } + if(isset($_COOKIE['mod']) && isset($_SESSION['mod']) && is_array($_SESSION['mod'])) { // Should be username:session hash $cookie = explode(':', $_COOKIE['mod']); diff --git a/main.js b/main.js index d0a82dda..038713cd 100644 --- a/main.js +++ b/main.js @@ -6,8 +6,11 @@ function highlightReply(id) if (divs[i].className.indexOf('post') != -1) divs[i].className = divs[i].className.replace(/highlighted/, ''); } - if (id) - document.getElementById('reply_'+id).className += ' highlighted'; + if (id) { + post = document.getElementById('reply_'+id); + if(post) + post.className += ' highlighted'; + } } function focusId(id) { diff --git a/mod.php b/mod.php index 43dd8d26..12b730a0 100644 --- a/mod.php +++ b/mod.php @@ -43,6 +43,8 @@ if(!login($_POST['username'], $_POST['password'])) loginForm(ERROR_INVALID, $_POST['username']); + modLog("Logged in."); + // Login successful // Set cookies setCookies(); @@ -295,6 +297,9 @@ } $query->execute() or error(db_error($query)); + // Record the action + modLog("Created a new board: {$b['title']}"); + // Open the board openBoard($b['uri']) or error("Couldn't open board after creation."); @@ -356,6 +361,10 @@ // Delete post deleteFile($post); + + // Record the action + modLog("Removed file from post #{$post}"); + // Rebuild board buildIndex(); @@ -377,6 +386,10 @@ // Delete post deletePost($post); + + // Record the action + modLog("Deleted post #{$post}"); + // Rebuild board buildIndex(); @@ -399,8 +412,12 @@ $query->bindValue(':id', $post, PDO::PARAM_INT); if($matches[2] == 'un') { + // Record the action + modLog("Unstickied post #{$post}"); $query->bindValue(':sticky', 0, PDO::PARAM_INT); } else { + // Record the action + modLog("Stickied post #{$post}"); $query->bindValue(':sticky', 1, PDO::PARAM_INT); } @@ -429,8 +446,12 @@ $query->bindValue(':id', $post, PDO::PARAM_INT); if($matches[2] == 'un') { + // Record the action + modLog("Unlocked post #{$post}"); $query->bindValue(':locked', 0, PDO::PARAM_INT); } else { + // Record the action + modLog("Locked post #{$post}"); $query->bindValue(':locked', 1, PDO::PARAM_INT); } @@ -454,10 +475,22 @@ if(!openBoard($boardName)) error(ERROR_NOBOARD); - $query = prepare(sprintf("SELECT `id` FROM `posts_%s` WHERE `ip` = (SELECT `ip` FROM `posts_%s` WHERE `id` = :id)", $board['uri'], $board['uri'])); + $query = prepare(sprintf("SELECT `ip` FROM `posts_%s` WHERE `id` = :id", $board['uri'])); $query->bindValue(':id', $post); $query->execute() or error(db_error($query)); + if(!$post = $query->fetch()) + error(ERROR_INVALIDPOST); + + $ip = $post['ip']; + + // Record the action + modLog("Deleted all posts by IP address: #{$ip}"); + + $query = prepare(sprintf("SELECT `id` FROM `posts_%s` WHERE `ip` = :ip", $board['uri'])); + $query->bindValue(':ip', $ip); + $query->execute() or error(db_error($query)); + if($query->rowCount() < 1) error(ERROR_INVALIDPOST); @@ -529,6 +562,10 @@ } else { $query->bindValue(':reason', null, PDO::PARAM_NULL); } + + // Record the action + modLog("Created a ban for {$_POST['ip']} with reason {$_POST['reason']}"); + $query->execute() or error(db_error($query)); // Delete too diff --git a/post.php b/post.php index 62260e1b..38599222 100644 --- a/post.php +++ b/post.php @@ -221,7 +221,7 @@ if(strlen($post['name']) > 50) error(sprintf(ERROR_TOOLONG, 'name')); if(strlen($post['email']) > 30) error(sprintf(ERROR_TOOLONG, 'email')); if(strlen($post['subject']) > 40) error(sprintf(ERROR_TOOLONG, 'subject')); - if(strlen($post['body']) > MAX_BODY) error(ERROR_TOOLONGBODY); + if(!$mod && strlen($post['body']) > MAX_BODY) error(ERROR_TOOLONGBODY); if(!(!$OP && $post['has_file']) && strlen($post['body']) < 1) error(ERROR_TOOSHORTBODY); if(strlen($post['password']) > 20) error(sprintf(ERROR_TOOLONG, 'password')); -- cgit v1.3 From 3737439338629890598abff0cc9e5c04528c66a9 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Sat, 12 Feb 2011 17:25:15 +1100 Subject: Changed config to an array --- inc/config.php | 376 ++++++++++++++++++++++++------------------------ inc/database.php | 14 +- inc/display.php | 122 ++++++++-------- inc/functions.php | 137 +++++++++--------- inc/instance-config.php | 47 ++++-- inc/template.php | 2 +- inc/user.php | 12 +- mod.php | 156 ++++++++++---------- post.php | 265 +++++++++------------------------- 9 files changed, 524 insertions(+), 607 deletions(-) (limited to 'mod.php') diff --git a/inc/config.php b/inc/config.php index f4040570..4fe7a988 100644 --- a/inc/config.php +++ b/inc/config.php @@ -8,318 +8,326 @@ * your instance-config.php * */ - + + $config = Array( + 'db' => Array(), + 'cookies' => Array(), + 'error' => Array(), + 'dir' => Array(), + 'mod' => Array() + ); // Database stuff + // SQL driver ("mysql", "pgsql", "sqlite", "dblib", etc) // http://www.php.net/manual/en/pdo.drivers.php - define('DB_TYPE', 'mysql', true); + $config['db']['type'] = 'mysql'; // Hostname or IP address - define('DB_SERVER', 'localhost', true); + $config['db']['server'] = 'localhost'; // Login - define('DB_USER', '', true); - define('DB_PASSWORD', '', true); - // TinyBoard database - define('DB_DATABASE', '', true); + $config['db']['user'] = ''; + $config['db']['password'] = ''; + // Tinyboard database + $config['db']['database'] = ''; // Anything more to add to the DSN string (eg. port=xxx;foo=bar) - define('DB_DSN', '', true); + $config['db']['dsn'] = ''; // The name of the session cookie (PHP's $_SESSION) - define('SESS_COOKIE', 'imgboard', true); + $config['cookies']['session']= 'imgboard'; - // Used to safely determine when the user was first seen, to prevent floods. - // time() - define('TIME_COOKIE', 'arrived', true); - // HASH_COOKIE contains an MD5 hash of TIME_COOKIE+SALT for verification. - define('HASH_COOKIE', 'hash', true); + // Used to safely determine when the user was first seen, to prevent floods. Contains a UNIX timestamp. + $config['cookies']['time'] = 'arrived'; + // Contains an MD5 hash of $config['cookies']['time'] for verification. + $config['cookies']['hash'] = 'hash'; // Used for moderation login - define('MOD_COOKIE', 'mod', true); - // Where to set the 'path' parameter to ROOT when creating cookies. Recommended. - define('JAIL_COOKIES', true, true); - + $config['cookies']['mod'] = 'mod'; + // Where to set the 'path' parameter to $config['root'] when creating cookies. Recommended. + $config['cookies']['jail'] = true; // How long should the cookies last (in seconds) - define('COOKIE_EXPIRE', 15778463, true); //6 months - // How long should moderators should remain logged in (0=browser session) (in seconds) - define('MOD_EXPIRE', 15778463, true); + $config['cookies']['expire']= 15778463; //6 months // Make this something long and random for security - define('SALT', 'wefaw98YHEWUFuo', true); - define('SECURE_TRIP_SALT', '@#$&^@#)$(*&@!_$(&329-8347', true); + $config['cookies']['salt'] = 'wefaw98YHEWUFuo'; + // How long should moderators should remain logged in (0=browser session) (in seconds) + $config['mod']['expire'] = 15778463; //6 months + // Used to salt secure tripcodes (##trip) + $config['secure_trip_salt'] = '@#$&^@#)$(*&@!_$(&329-8347'; // How many seconds before you can post, after the first visit - define('LURKTIME', 30, true); - + $config['lurktime'] = 30; // How many seconds between each post - define('FLOOD_TIME', 10, true); + $config['flood_time'] = 10; // How many seconds between each post with exactly the same content and same IP - define('FLOOD_TIME_IP_SAME', 120, true); + $config['flood_time_ip'] = 120; // Same as above but different IP address - define('FLOOD_TIME_SAME', 30, true); + $config['flood_time_same'] = 30; // Do you need a body for your non-OP posts? - define('FORCE_BODY', true, true); + $config['force_body'] = true; // Max body length - define('MAX_BODY', 1800, true); - - define('THREADS_PER_PAGE', 10, true); - define('MAX_PAGES', 10, true); - define('THREADS_PREVIEW', 5, true); + $config['max_body'] = 1800; + + $config['threads_per_page'] = 10; + $config['max_pages'] = 10; + $config['threads_preview'] = 5; // For development purposes. Turns 'display_errors' on. Not recommended for production. - define('VERBOSE_ERRORS', true, true); + $config['verbose_errors'] = true; // Error messages - define('ERROR_LURK', 'Lurk some more before posting.', true); - define('ERROR_BOT', 'You look like a bot.', true); - define('ERROR_TOOLONG', 'The %s field was too long.', true); - define('ERROR_TOOLONGBODY', 'The body was too long.', true); - define('ERROR_TOOSHORTBODY', 'The body was too short or empty.', true); - define('ERROR_NOIMAGE', 'You must upload an image.', true); - define('ERROR_NOMOVE', 'The server failed to handle your upload.', true); - define('ERROR_FILEEXT', 'Unsupported image format.', true); - define('ERROR_NOBOARD', 'Invalid board!', true); - define('ERROR_NONEXISTANT', 'Thread specified does not exist.', true); - define('ERROR_LOCKED', 'Thread locked. You may not reply at this time.', true); - define('ERROR_NOPOST', 'You didn\'t make a post.', true); - define('ERROR_FLOOD', 'Flood detected; Post discared.', true); - define('ERROR_UNORIGINAL', 'Unoriginal content!', true); - define('ERROR_MUTED', 'Unoriginal content! You have been muted for %d seconds.', true); - define('ERROR_YOUAREMUTED', 'You are muted! Expires in %d seconds.', true); - define('ERROR_TOR', 'Hmm… That looks like a Tor exit node.', true); - define('ERROR_TOOMANYLINKS', 'Too many links; flood detected.', true); - define('ERROR_NODELETE', 'You didn\'t select anything to delete.', true); - define('ERROR_INVALIDPASSWORD', 'Wrong password…', true); - define('ERR_INVALIDIMG','Invalid image.', true); - define('ERR_FILESIZE', 'Maximum file size: %maxsz% bytes
        Your file\'s size: %filesz% bytes', true); - define('ERR_MAXSIZE', 'The file was too big.', true); - define('ERR_INVALIDZIP', 'Invalid archive!', true); + $config['error']['lurk'] = 'Lurk some more before posting.'; + $config['error']['bot'] = 'You look like a bot.'; + $config['error']['toolong'] = 'The %s field was too long.'; + $config['error']['toolong_body'] = 'The body was too long.'; + $config['error']['tooshort_body'] = 'The body was too short or empty.'; + $config['error']['noimage'] = 'You must upload an image.'; + $config['error']['nomove'] = 'The server failed to handle your upload.'; + $config['error']['fileext'] = 'Unsupported image format.'; + $config['error']['noboard'] = 'Invalid board!'; + $config['error']['nonexistant'] = 'Thread specified does not exist.'; + $config['error']['locked'] = 'Thread locked. You may not reply at this time.'; + $config['error']['nopost'] = 'You didn\'t make a post.'; + $config['error']['flood'] = 'Flood detected; Post discared.'; + $config['error']['unoriginal'] = 'Unoriginal content!'; + $config['error']['muted'] = 'Unoriginal content! You have been muted for %d seconds.'; + $config['error']['youaremuted'] = 'You are muted! Expires in %d seconds.'; + $config['error']['tor'] = 'Hmm… That looks like a Tor exit node.'; + $config['error']['toomanylinks'] = 'Too many links; flood detected.'; + $config['error']['nodelete'] = 'You didn\'t select anything to delete.'; + $config['error']['invalidpassword'] = 'Wrong password…'; + $config['error']['invalidimg'] = 'Invalid image.'; + $config['error']['filesize'] = 'Maximum file size: %maxsz% bytes
        Your file\'s size: %filesz% bytes'; + $config['error']['maxsize'] = 'The file was too big.'; + $config['error']['invalidzip'] = 'Invalid archive!'; // Moderator errors - define('ERROR_INVALID', 'Invalid username and/or password.', true); - define('ERROR_NOTAMOD', 'You are not a mod…', true); - define('ERROR_INVALIDAFTER', 'Invalid username and/or password. Your user may have been deleted or changed.', true); - define('ERROR_MALFORMED','Invalid/malformed cookies.', true); - define('ERROR_MISSEDAFIELD', 'Your browser didn\'t submit an input when it should have.', true); - define('ERROR_REQUIRED', 'The %s field is required.', true); - define('ERROR_INVALIDFIELD', 'The %s field was invalid.', true); - define('ERROR_BOARDEXISTS', 'There is already a %s board.', true); - define('ERROR_NOACCESS', 'You don\'t have permission to do that.', true); - define('ERROR_INVALIDPOST', 'That post doesn\'t exist…', true); - define('ERROR_404', 'Page not found.', true); + $config['error']['invalid'] = 'Invalid username and/or password.'; + $config['error']['notamod'] = 'You are not a mod…'; + $config['error']['invalidafter'] = 'Invalid username and/or password. Your user may have been deleted or changed.'; + $config['error']['malformed'] = 'Invalid/malformed cookies.'; + $config['error']['missedafield'] = 'Your browser didn\'t submit an input when it should have.'; + $config['error']['required'] = 'The %s field is required.'; + $config['error']['invalidfield'] = 'The %s field was invalid.'; + $config['error']['boardexists'] = 'There is already a %s board.'; + $config['error']['noaccess'] = 'You don\'t have permission to do that.'; + $config['error']['invalidpost'] = 'That post doesn\'t exist…'; + $config['error']['404'] = 'Page not found.'; // Reply limit (deletes thread when this is reached) - define('REPLY_LIMIT', 250, true); + $config['reply_limit'] = 250; // For resizing, max values - define('THUMB_WIDTH', 225, true); - define('THUMB_HEIGHT', 225, true); + $config['thumb_width'] = 255; + $config['thumb_height'] = 255; // Store image hash in the database for r9k-like boards implementation soon // Function name for hashing // sha1_file, md5_file, etc. - define('FILE_HASH', 'sha1_file', true); + $config['file_hash'] = 'sha1_file'; - define('BLOCK_TOR', true, true); + $config['block_tor'] = true; // Typically spambots try to post a lot of links. Refuse a post with X standalone links? - define('MAX_LINKS', 20, true); + $config['max_links'] = 20; // Maximum image upload size in bytes - define('MAX_FILESIZE', 10*1024*1024, true); // 10MB + $config['max_filesize'] = 10*1024*1024; // 10MB // Maximum image dimensions - define('MAX_WIDTH', 10000, true); - define('MAX_HEIGHT', MAX_WIDTH, true); - - /* When you upload a ZIP as a file, all the images inside the archive - * get dumped into the thread as replies. - * Extremely beta and not recommended yet. - */ - define('ALLOW_ZIP', false, true); + $config['max_width'] = 1000; + $config['max_height'] = $config['max_width']; // 1:1 /** Redraw the image using GD functions to strip any excess data (commonly ZIP archives) - WARNING: Very beta. Currently strips animated GIFs too :( + WARNING: Currently strips animated GIFs too :( **/ - define('REDRAW_IMAGE', false, true); + $config['redraw_image'] = false; // Redrawing configuration - define('JPEG_QUALITY', 100, true); - define('REDRAW_GIF', false, true); - - // Display the aspect ratio in a post's file info - define('SHOW_RATIO', true, true); - - define('DIR_IMG', 'src/', true); - define('DIR_THUMB', 'thumb/', true); - define('DIR_RES', 'res/', true); - define('DIR_STATIC', 'static/', true); + $config['jpeg_quality'] = 100; + // Temporary fix for the animation-stripping bug + $config['redraw_gifs'] = false; - // Where to store the .html templates. This folder and templates must exist or fatal errors will be thrown. - define('DIR_TEMPLATE', getcwd() . '/templates', true); + // Display the aspect ratio in a post's file info + $config['show_ratio'] = true; // The root directory, including the trailing slash, for Tinyboard. // examples: '/', 'http://boards.chan.org/', '/chan/' - define('ROOT', '/', true); - + $config['root'] = '/'; + + $config['dir']['img'] = 'src/'; + $config['dir']['thumb'] = 'thumb/'; + $config['dir']['res'] = 'res/'; + // For load balancing, having a seperate server (and domain/subdomain) for serving static content is possible. + // This can either be a directory or a URL (eg. http://static.example.org/) + $config['dir']['static'] = $config['root'] . 'static/'; + // Where to store the .html templates. This folder and templates must exist or fatal errors will be thrown. + $config['dir']['template'] = getcwd() . '/templates'; // Static images // These can be URLs OR base64 (data URI scheme) - define('IMAGE_STICKY', ROOT . DIR_STATIC . 'sticky.gif', true); - define('IMAGE_LOCKED', ROOT . DIR_STATIC . 'locked.gif', true); - define('DELETED_IMAGE', ROOT . DIR_STATIC . 'deleted.png', true); - define('ZIP_IMAGE', ROOT . DIR_STATIC . 'zip.png', true); + $config['image_sticky'] = $config['dir']['static'] . 'sticky.gif'; + $config['image_locked'] = $config['dir']['static'] . 'locked.gif'; + $config['image_deleted'] = $config['dir']['static'] . 'deleted.png'; + $config['image_zip'] = $config['dir']['static'] . 'zip.png'; // If for some reason the folders and static HTML index files aren't in the current working direcotry, // enter the directory path here. Otherwise, keep it false. - define('ROOT_FILE', false, true); + $config['root_file'] = false; - define('POST_URL', ROOT . 'post.php', true); - define('FILE_INDEX', 'index.html', true); - define('FILE_PAGE', '%d.html', true); - define('FILE_MOD', 'mod.php', true); + $config['file_index'] = 'index.html'; + $config['file_page'] = '%d.html'; + $config['file_mod'] = 'mod.php'; // Multi-board (%s is board abbreviation) - define('BOARD_PATH', '%s/', true); + $config['board_path'] = '%s/'; // The HTTP status code to use when redirecting. // Should be 3xx (redirection). http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html // "302" is recommended. - define('REDIRECT_HTTP', 302, true); + $config['redirect_http'] = 302; + // TODO: Put this in per-board instance-config instead // Robot stuff // Strip repeating characters when making hashes - define('ROBOT_ENABLE', true, true); - define('ROBOT_BOARD', 'r9k', true); - define('ROBOT_STRIP_REPEATING', true, true); + $config['robot_enable'] = false; + $config['robot_strip_repeating'] = true; + // Enable mutes - define('ROBOT_MUTE', true, true); - define('ROBOT_MUTE_HOUR', 50, true); // How many mutes X hours ago to include in the algorithm - define('ROBOT_MUTE_MULTIPLIER', 2, true); - define('ROBOT_MUTE_DESCRIPTION', 'You have been muted for unoriginal content.', true); + // Tinyboard uses ROBOT9000's original 2^x implementation + $config['robot_mute'] = true; + // How many mutes x hours ago to include in the algorithm + $config['robot_mute_hour'] = 50; + // If you want to alter the algorithm a bit. Default value is 2. n^x + $config['robot_mute_multiplier'] = 2; + $config['robot_mute_descritpion'] = 'You have been muted for unoriginal content.'; /* Mod stuff */ // Whether or not to lock moderator sessions to the IP address that was logged in with. - define('MOD_LOCK_IP', true, true); + $config['mod']['lock_ip'] = true; // The page that is first shown when a moderator logs in. Defaults to the dashboard. - define('MOD_DEFAULT', '/', true); - // Don't even display MySQL password to administrators (in the configuration page) - define('MOD_NEVER_REAL_PASSWORD', true, true); + $config['mod']['default'] = '/'; + // Don't even display MySQL password to administrators (in the configuration page). + $config['mod']['never_reveal_password'] = true; // Do a DNS lookup on IP addresses to get their hostname on the IP summary page - define('MOD_DNS_LOOKUP', true, true); + $config['mod']['dns_lookup'] = true; // Show ban form on the IP summary page - define('MOD_IP_BANFORM', true, true); + $config['mod']['ip_banform'] = true; // How many recent posts, per board, to show in the IP summary page - define('MOD_IP_RECENTPOSTS', 5, true); + $config['mod']['ip_recentposts'] = 5; // Probably best not to change these: - define('MOD_JANITOR', 0, true); - define('MOD_MOD', 1, true); - define('MOD_ADMIN', 2, true); + define('JANITOR', 0, true); + define('MOD', 1, true); + define('ADMIN', 2, true); // Permissions // What level of administration you need to: /* Post Controls */ // View IP addresses - define('MOD_SHOW_IP', MOD_MOD, true); + $config['mod']['show_ip'] = MOD; // Delete a post - define('MOD_DELETE', MOD_JANITOR, true); + $config['mod']['delete'] = JANITOR; // Ban a user for a post - define('MOD_BAN', MOD_MOD, true); + $config['mod']['ban'] = MOD; // Ban and delete (one click; instant) - define('MOD_BANDELETE', MOD_BAN, true); + $config['mod']['bandelete'] = MOD; // Delete file (and keep post) - define('MOD_DELETEFILE', MOD_JANITOR, true); + $config['mod']['deletefile'] = JANITOR; // Delete all posts by IP - define('MOD_DELETEBYIP', MOD_BAN, true); + $config['mod']['deletebyip'] = MOD; // Sticky a thread - define('MOD_STICKY', MOD_MOD, true); + $config['mod']['sticky'] = MOD; // Lock a thread - define('MOD_LOCK', MOD_MOD, true); + $config['mod']['lock'] = MOD; // Post in a locked thread - define('MOD_POSTINLOCKED', MOD_MOD, true); + $config['mod']['postinlocked'] = MOD; // Post bypass unoriginal content check - define('MOD_POSTUNORIGINAL', MOD_MOD, true); + $config['mod']['postunoriginal'] = MOD; // Raw HTML posting - define('MOD_RAWHTML', MOD_MOD, true); + $config['mod']['rawhtml'] = MOD; /* Administration */ - // Display the contents of instant-config.php - define('MOD_SHOW_CONFIG', MOD_ADMIN, true); + // Display the contents of instance-config.php + $config['mod']['show_config'] = ADMIN; // View list of bans - define('MOD_VIEW_BANLIST', MOD_MOD, true); + $config['mod']['view_banlist'] = MOD; // View the username of the mod who made a ban - define('MOD_VIEW_BANSTAFF', MOD_MOD, true); - // If the moderator doesn't fit the MOD_VIEW_BANSTAFF (previous) permission, + $config['mod']['view_banstaff'] = MOD; + // If the moderator doesn't fit the $config['mod']['view_banstaff''] (previous) permission, // show him just a "?" instead. Otherwise, it will be "Mod" or "Admin" - define('MOD_VIEW_BANQUESTIONMARK', false, true); + $config['mod']['view_banquestionmark'] = false; // Show expired bans in the ban list (they are kept in cache until the culprit returns) - define('MOD_VIEW_BANEXPIRED', true, true); + $config['mod']['view_banexpired'] = true; // Create a new board - define('MOD_NEWBOARD', MOD_ADMIN, true); + $config['mod']['newboard'] = ADMIN; // Mod links (full HTML) // Correspond to above permission directives - define('MOD_LINK_DELETE', '[D]', true); - define('MOD_LINK_BAN', '[B]', true); - define('MOD_LINK_BANDELETE', '[B&D]', true); - define('MOD_LINK_DELETEFILE', '[F]', true); - define('MOD_LINK_DELETEBYIP', '[D+]', true); - define('MOD_LINK_STICKY', '[Sticky]', true); - define('MOD_LINK_DESTICKY', '[-Sticky]', true); - define('MOD_LINK_LOCK', '[Lock]', true); - define('MOD_LINK_UNLOCK', '[-Lock]', true); + $config['mod']['link_delete'] = '[D]'; + $config['mod']['link_ban'] = '[B]'; + $config['mod']['link_bandelete'] = '[B&D]'; + $config['mod']['link_deletefile'] = '[F]'; + $config['mod']['link_deletebyip'] = '[D+]'; + $config['mod']['link_sticky'] = '[Sticky]'; + $config['mod']['link_desticky'] = '[-Sticky]'; + $config['mod']['link_lock'] = '[Lock]'; + $config['mod']['link_unlock'] = '[-Lock]'; + // A small file in the main directory indicating that the script has been ran and the board(s) have been generated. // This keeps the script from querying the database and causing strain when not needed. - define('HAS_INSTALLED', '.installed', true); + $config['has_installed'] = '.installed'; - // Name of the boards. Typically '/%s/' (/b/, /mu/, etc) - // BOARD_ABBREVIATION - BOARD_TITLE - define('BOARD_ABBREVIATION', '/%s/', true); + // Name of the boards. Usually '/%s/' (/b/, /mu/, etc) + // $config['board_abbreviation'] - BOARD_TITLE + $config['board_abbreviation'] = '/%s/'; // Automatically convert things like "..." to Unicode characters ("…") - define('AUTO_UNICODE', true, true); + $config['auto_unicode'] = true; // Use some Wiki-like syntax (''em'', '''strong''', ==Heading==, etc) - define('WIKI_MARKUP', true, true); + $config['wiki_markup'] = true; // Whether to turn URLs into functional links - define('MARKUP_URLS', true, true); + $config['markup_urls'] = true; // Complex regular expression to catch URLs - define('URL_REGEX', '/' . '(https?|ftp):\/\/' . '(([\w\-]+\.)+[a-zA-Z]{2,6}|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' . '(\/([\w\-~\.#\/?=&;:+%]+)?)?' . '/', true); + $config['url_regex'] = '/' . '(https?|ftp):\/\/' . '(([\w\-]+\.)+[a-zA-Z]{2,6}|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' . '(\/([\w\-~\.#\/?=&;:+%]+)?)?' . '/'; // Allowed file extensions - $allowed_ext = Array('jpg', 'jpeg', 'bmp', 'gif', 'png', true); - - define('BUTTON_NEWTOPIC', 'New Topic', true); - define('BUTTON_REPLY', 'New Reply', true); + $config['allowed_ext'] = Array('jpg', 'jpeg', 'bmp', 'gif', 'png'); + + // The names on the post buttons. (On most imageboards, these are both "Post".) + $config['button_newtopic'] = 'New Topic'; + $config['button_reply'] = 'New Reply'; // The string passed to date() for post times // http://php.net/manual/en/function.date.php - define('POST_DATE', 'm/d/y (D) H:i:s', true); + $config['post_date'] = 'm/d/y (D) H:i:s'; - define('ALWAYS_NOKO', false, true); + // Always act as if they had typed "noko" in the email field no mattter what + $config['always_noko'] = false; - define('URL_MATCH', '/^' . - (preg_match(URL_REGEX, ROOT) ? '' : + $config['url_match'] = '/^' . + (preg_match($config['url_regex'], $config['root']) ? '' : (@$_SERVER['HTTPS']?'https':'http') . ':\/\/'.$_SERVER['HTTP_HOST']) . - preg_quote(ROOT, '/') . + preg_quote($config['root'], '/') . '(' . - str_replace('%s', '\w{1,8}', preg_quote(BOARD_PATH, '/')) . + str_replace('%s', '\w{1,8}', preg_quote($config['board_path'], '/')) . '|' . - str_replace('%s', '\w{1,8}', preg_quote(BOARD_PATH, '/')) . - preg_quote(FILE_INDEX, '/') . + str_replace('%s', '\w{1,8}', preg_quote($config['board_path'], '/')) . + preg_quote($config['file_index'], '/') . '|' . - str_replace('%s', '\w{1,8}', preg_quote(BOARD_PATH, '/')) . - str_replace('%d', '\d+', preg_quote(FILE_PAGE, '/')) . + str_replace('%s', '\w{1,8}', preg_quote($config['board_path'], '/')) . + str_replace('%d', '\d+', preg_quote($config['file_page'], '/')) . '|' . - preg_quote(FILE_MOD, '/') . + preg_quote($config['file_mod'], '/') . '\?\/.+' . - ')$/i', true); + ')$/i'; - if(ROOT_FILE) { - chdir(ROOT_FILE); + if($config['root_file']) { + chdir($config['root_file']); } - if(VERBOSE_ERRORS) { + if($config['verbose_errors']) { error_reporting(E_ALL); ini_set('display_errors', 1); } + ?> \ No newline at end of file diff --git a/inc/database.php b/inc/database.php index dca1fbd1..21fabe71 100644 --- a/inc/database.php +++ b/inc/database.php @@ -1,20 +1,20 @@ getMessage(); // Remove any sensitive information - $message = str_replace(DB_USER, 'hidden', $message); - $message = str_replace(DB_PASSWORD, 'hidden', $message); + $message = str_replace($config['db']['user'], 'hidden', $message); + $message = str_replace($config['db']['password'], 'hidden', $message); // Print error error('Database error: ' . $message); diff --git a/inc/display.php b/inc/display.php index 8423da0f..acf77e39 100644 --- a/inc/display.php +++ b/inc/display.php @@ -20,30 +20,32 @@ } function error($message) { - global $board, $mod; + global $board, $mod, $config; if(function_exists('sql_close')) sql_close(); die(Element('page.html', Array( - 'index'=>ROOT, + 'index'=>$config['root'], 'title'=>'Error', 'subtitle'=>'An error has occured.', 'body'=>"
        " . "

        $message

        " . (isset($board) ? - "

        Go back.

        " : ''). + "

        Go back.

        " : ''). "
        " ))); } function loginForm($error=false, $username=false) { + global $config; + if(function_exists('sql_close')) sql_close(); die(Element('page.html', Array( - 'index'=>ROOT, + 'index'=>$config['root'], 'title'=>'Login', 'body'=>Element('login.html', Array( - 'index'=>ROOT, + 'index'=>$config['root'], 'error'=>$error, 'username'=>$username ) @@ -52,7 +54,10 @@ } class Post { - public function __construct($id, $thread, $subject, $email, $name, $trip, $body, $time, $thumb, $thumbx, $thumby, $file, $filex, $filey, $filesize, $filename, $ip, $root=ROOT, $mod=false) { + public function __construct($id, $thread, $subject, $email, $name, $trip, $body, $time, $thumb, $thumbx, $thumby, $file, $filex, $filey, $filesize, $filename, $ip, $root=null, $mod=false) { + global $config; + if(!isset($root)) $root = $config['root']; + $this->id = $id; $this->thread = $thread; $this->subject = utf8tohtml($subject); @@ -77,13 +82,13 @@ // Fix internal links // Very complicated regex $this->body = preg_replace( - '/'; // Delete - if($this->mod['type'] >= MOD_DELETE) - $built .= ' ' . MOD_LINK_DELETE . ''; + if($this->mod['type'] >= $config['mod']['delete']) + $built .= ' ' . $config['mod']['link_delete'] . ''; // Delete all posts by IP - if($this->mod['type'] >= MOD_DELETEBYIP) - $built .= ' ' . MOD_LINK_DELETEBYIP . ''; + if($this->mod['type'] >= $config['mod']['deletebyip']) + $built .= ' ' . $config['mod']['link_deletebyip'] . ''; // Ban - if($this->mod['type'] >= MOD_BAN) - $built .= ' ' . MOD_LINK_BAN . ''; + if($this->mod['type'] >= $config['mod']['ban']) + $built .= ' ' . $config['mod']['link_ban'] . ''; // Ban & Delete - if($this->mod['type'] >= MOD_BANDELETE) - $built .= ' ' . MOD_LINK_BANDELETE . ''; + if($this->mod['type'] >= $config['mod']['bandelete']) + $built .= ' ' . $config['mod']['link_bandelete'] . ''; // Delete file (keep post) - if(!empty($this->file) && $this->mod['type'] >= MOD_DELETEFILE) - $built .= ' ' . MOD_LINK_DELETEFILE . ''; + if(!empty($this->file) && $this->mod['type'] >= $config['mod']['deletefile']) + $built .= ' ' . $config['mod']['link_deletefile'] . ''; $built .= ''; } @@ -116,7 +121,7 @@ } public function build($index=false) { - global $board; + global $board, $config; $built = '
        ' . '

        ' . @@ -135,7 +140,7 @@ . (!empty($this->trip) ? ' '.$this->trip.'':''); // IP Address - if($this->mod && $this->mod['type'] >= MOD_SHOW_IP) { + if($this->mod && $this->mod['type'] >= $config['mod']['show_ip']) { $built .= ' [' . $this->ip . ']'; } @@ -144,7 +149,7 @@ $built .= ''; // Date/time - $built .= ' ' . date(POST_DATE, $this->time); + $built .= ' ' . date($config['post_date'], $this->time); // End delete $built .= ''; @@ -152,20 +157,20 @@ $built .= ' No.' . + ' href="' . $this->root . $board['dir'] . $config['dir']['res'] . $this->thread . '.html' . '#' . $this->id . '">No.' . // JavaScript cite - ''.$this->id.'' . + ''.$this->id.'' . '

        '; // File info if(!empty($this->file) && $this->file != 'deleted') { - $built .= '

        File: ' . $this->file . ' (' . + $built .= '

        File: ' . $this->file . ' (' . // Filesize format_bytes($this->filesize) . ', ' . // File dimensions $this->filex . 'x' . $this->filey; // Aspect Ratio - if(SHOW_RATIO) { + if($config['show_ratio']) { $fraction = fraction($this->filex, $this->filey, ':'); $built .= ', ' . $fraction; } @@ -173,9 +178,9 @@ $built .= ', ' . $this->filename . ')

        ' . // Thumbnail - ''; + ''; } elseif($this->file == 'deleted') { - $built .= ''; + $built .= ''; } $built .= $this->postControls(); @@ -189,7 +194,10 @@ class Thread { public $omitted = 0; - public function __construct($id, $subject, $email, $name, $trip, $body, $time, $thumb, $thumbx, $thumby, $file, $filex, $filey, $filesize, $filename, $ip, $sticky, $locked, $root=ROOT, $mod=false) { + public function __construct($id, $subject, $email, $name, $trip, $body, $time, $thumb, $thumbx, $thumby, $file, $filex, $filey, $filesize, $filename, $ip, $sticky, $locked, $root=null, $mod=false) { + global $config; + if(!isset($root)) $root = $config['root']; + $this->id = $id; $this->subject = utf8tohtml($subject); $this->email = $email; @@ -217,7 +225,7 @@ // Fix internal links // Very complicated regex $this->body = preg_replace( - '/'; // Delete - if($this->mod['type'] >= MOD_DELETE) - $built .= ' ' . MOD_LINK_DELETE . ''; + if($this->mod['type'] >= $config['mod']['delete']) + $built .= ' ' . $config['mod']['link_delete'] . ''; // Delete all posts by IP - if($this->mod['type'] >= MOD_DELETEBYIP) - $built .= ' ' . MOD_LINK_DELETEBYIP . ''; + if($this->mod['type'] >= $config['mod']['deletebyip']) + $built .= ' ' . $config['mod']['link_deletebyip'] . ''; // Ban - if($this->mod['type'] >= MOD_BAN) - $built .= ' ' . MOD_LINK_BAN . ''; + if($this->mod['type'] >= $config['mod']['ban']) + $built .= ' ' . $config['mod']['link_ban'] . ''; // Ban & Delete - if($this->mod['type'] >= MOD_BANDELETE) - $built .= ' ' . MOD_LINK_BANDELETE . ''; + if($this->mod['type'] >= $config['mod']['bandelete']) + $built .= ' ' . $config['mod']['link_bandelete'] . ''; // Stickies - if($this->mod['type'] >= MOD_STICKY) + if($this->mod['type'] >= $config['mod']['sticky']) if($this->sticky) - $built .= ' ' . MOD_LINK_DESTICKY . ''; + $built .= ' ' . $config['mod']['link_desticky'] . ''; else - $built .= ' ' . MOD_LINK_STICKY . ''; + $built .= ' ' . $config['mod']['link_sticky'] . ''; // Lock - if($this->mod['type'] >= MOD_LOCK) + if($this->mod['type'] >= $config['mod']['lock']) if($this->locked) - $built .= ' ' . MOD_LINK_UNLOCK . ''; + $built .= ' ' . $config['mod']['link_unlock'] . ''; else - $built .= ' ' . MOD_LINK_LOCK . ''; + $built .= ' ' . $config['mod']['link_lock'] . ''; $built .= ''; @@ -270,22 +278,22 @@ } public function build($index=false) { - global $board; + global $board, $config; - $built = '

        File: ' . $this->file . ' (' . + $built = '

        File: ' . $this->file . ' (' . // Filesize format_bytes($this->filesize) . ', ' . // File dimensions $this->filex . 'x' . $this->filey; // Aspect Ratio - if(SHOW_RATIO) { + if($config['show_ratio']) { $fraction = fraction($this->filex, $this->filey, ':'); $built .= ', ' . $fraction; } // Filename $built .= ', ' . $this->filename . ')

        ' . // Thumbnail - ''; + ''; $built .= '

        '; @@ -304,7 +312,7 @@ . (!empty($this->trip) ? ' '.$this->trip.'':''); // IP Address - if($this->mod && $this->mod['type'] >= MOD_SHOW_IP) { + if($this->mod && $this->mod['type'] >= $config['mod']['show_ip']) { $built .= ' [' . $this->ip . ']'; } @@ -313,7 +321,7 @@ $built .= ''; // Date/time - $built .= ' ' . date(POST_DATE, $this->time); + $built .= ' ' . date($config['post_date'], $this->time); // End delete $built .= ''; @@ -321,15 +329,15 @@ $built .= ' No.' . + ' href="' . $this->root . $board['dir'] . $config['dir']['res'] . $this->id . '.html' . '#' . $this->id . '">No.' . // JavaScript cite - ''.$this->id.'' . + ''.$this->id.'' . // Sticky - ($this->sticky ? '' : '') . + ($this->sticky ? '' : '') . // Locked - ($this->locked ? '' : '') . + ($this->locked ? '' : '') . // [Reply] - ($index ? '[Reply]' : '') . + ($index ? '[Reply]' : '') . // Mod controls $this->postControls() . diff --git a/inc/functions.php b/inc/functions.php index 6901de62..cc2a02f8 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -9,7 +9,7 @@ } function setupBoard($array) { - global $board; + global $board, $config; $board = Array( 'id' => $array['id'], @@ -17,13 +17,13 @@ 'name' => $array['title'], 'title' => $array['subtitle']); - $board['dir'] = sprintf(BOARD_PATH, $board['uri']); - $board['url'] = sprintf(BOARD_ABBREVIATION, $board['uri']); + $board['dir'] = sprintf($config['board_path'], $board['uri']); + $board['url'] = sprintf($config['board_abbreviation'], $board['uri']); if(!file_exists($board['dir'])) mkdir($board['dir'], 0777); - if(!file_exists($board['dir'] . DIR_IMG)) @mkdir($board['dir'] . DIR_IMG, 0777) or error("Couldn't create " . DIR_IMG . ". Check permissions.", true); - if(!file_exists($board['dir'] . DIR_THUMB)) @mkdir($board['dir'] . DIR_THUMB, 0777) or error("Couldn't create " . DIR_THUMB . ". Check permissions.", true); - if(!file_exists($board['dir'] . DIR_RES)) @mkdir($board['dir'] . DIR_RES, 0777) or error("Couldn't create " . DIR_RES . ". Check permissions.", true); + if(!file_exists($board['dir'] . $config['dir']['img'])) @mkdir($board['dir'] . $config['dir']['img'], 0777) or error("Couldn't create " . $config['dir']['img'] . ". Check permissions.", true); + if(!file_exists($board['dir'] . $config['dir']['thumb'])) @mkdir($board['dir'] . $config['dir']['thumb'], 0777) or error("Couldn't create " . $config['dir']['thumb'] . ". Check permissions.", true); + if(!file_exists($board['dir'] . $config['dir']['res'])) @mkdir($board['dir'] . $config['dir']['res'], 0777) or error("Couldn't create " . $config['dir']['res'] . ". Check permissions.", true); } function openBoard($uri) { @@ -46,14 +46,14 @@ } function checkFlood($post) { - global $board; + global $board, $config; $query = prepare(sprintf("SELECT * FROM `posts_%s` WHERE (`ip` = :ip AND `time` >= :floodtime) OR (`ip` = :ip AND `body` = :body AND `time` >= :floodsameiptime) OR (`body` = :body AND `time` >= :floodsametime) LIMIT 1", $board['uri'])); $query->bindValue(':ip', $_SERVER['REMOTE_ADDR']); $query->bindValue(':body', $post['body'], PDO::PARAM_INT); - $query->bindValue(':floodtime', time()-FLOOD_TIME, PDO::PARAM_INT); - $query->bindValue(':floodsameiptime', time()-FLOOD_TIME_IP_SAME, PDO::PARAM_INT); - $query->bindValue(':floodsametime', time()-FLOOD_TIME_SAME, PDO::PARAM_INT); + $query->bindValue(':floodtime', time()-$config['flood_time'], PDO::PARAM_INT); + $query->bindValue(':floodsameiptime', time()-$config['flood_time_ip'], PDO::PARAM_INT); + $query->bindValue(':floodsametime', time()-$config['flood_time_same'], PDO::PARAM_INT); $query->execute() or error(db_error($query)); return (bool)$query->fetch(); @@ -81,6 +81,8 @@ } function checkBan() { + global $config; + if(!isset($_SERVER['REMOTE_ADDR'])) { // Server misconfiguration return; @@ -157,7 +159,7 @@ // Show banned page and exit die(Element('page.html', Array( - 'index' => ROOT, + 'index' => $config['root'], 'title' => 'Banned', 'subtitle' => 'You are banned!', 'body' => $body @@ -264,14 +266,14 @@ // Remove file from post function deleteFile($id, $remove_entirely_if_already=true) { - global $board; + global $board, $config; $query = prepare(sprintf("SELECT `thread`,`thumb`,`file` FROM `posts_%s` WHERE `id` = :id AND `thread` IS NOT NULL LIMIT 1", $board['uri'])); $query->bindValue(':id', $id, PDO::PARAM_INT); $query->execute() or error(db_error($query)); if($query->rowCount() < 1) { - error(ERROR_INVALIDPOST); + error($config['error']['invalidpost']); } $post = $query->fetch(); @@ -282,10 +284,10 @@ $query->bindValue(':file', null, PDO::PARAM_NULL); } else { // Delete thumbnail - @unlink($board['dir'] . DIR_THUMB . $post['thumb']); + @unlink($board['dir'] . $config['dir']['thumb'] . $post['thumb']); // Delete file - @unlink($board['dir'] . DIR_IMG . $post['file']); + @unlink($board['dir'] . $config['dir']['img'] . $post['file']); // Set file to 'deleted' $query->bindValue(':file', 'deleted', PDO::PARAM_INT); @@ -300,7 +302,7 @@ // Delete a post (reply or thread) function deletePost($id, $error_if_doesnt_exist=true) { - global $board; + global $board, $config; // Select post and replies (if thread) in one query $query = prepare(sprintf("SELECT `id`,`thread`,`thumb`,`file` FROM `posts_%s` WHERE `id` = :id OR `thread` = :id", $board['uri'])); @@ -309,7 +311,7 @@ if($query->rowCount() < 1) { if($error_if_doesnt_exist) - error(ERROR_INVALIDPOST); + error($config['error']['invalidpost']); else return false; } @@ -317,18 +319,18 @@ while($post = $query->fetch()) { if(!$post['thread']) { // Delete thread HTML page - @unlink($board['dir'] . DIR_RES . sprintf(FILE_PAGE, $post['id'])); + @unlink($board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $post['id'])); } elseif($query->rowCount() == 1) { // Rebuild thread $rebuild = $post['thread']; } if($post['thumb']) { // Delete thumbnail - @unlink($board['dir'] . DIR_THUMB . $post['thumb']); + @unlink($board['dir'] . $config['dir']['thumb'] . $post['thumb']); } if($post['file']) { // Delete file - @unlink($board['dir'] . DIR_IMG . $post['file']); + @unlink($board['dir'] . $config['dir']['img'] . $post['file']); } } @@ -344,8 +346,8 @@ } function clean() { - global $board; - $offset = round(MAX_PAGES*THREADS_PER_PAGE); + global $board, $config; + $offset = round($config['max_pages']*$config['threads_per_page']); // I too wish there was an easier way of doing this... $query = prepare(sprintf("SELECT `id` FROM `posts_%s` WHERE `thread` IS NULL ORDER BY `sticky` DESC, `bump` DESC LIMIT :offset, 9001", $board['uri'])); @@ -358,74 +360,75 @@ } function index($page, $mod=false) { - global $board; + global $board, $config; $body = ''; - $offset = round($page*THREADS_PER_PAGE-THREADS_PER_PAGE); + $offset = round($page*$config['threads_per_page']-$config['threads_per_page']); sql_open(); $query = prepare(sprintf("SELECT * FROM `posts_%s` WHERE `thread` IS NULL ORDER BY `sticky` DESC, `bump` DESC LIMIT ?,?", $board['uri'])); $query->bindValue(1, $offset, PDO::PARAM_INT); - $query->bindValue(2, THREADS_PER_PAGE, PDO::PARAM_INT); + $query->bindValue(2, $config['threads_per_page'], PDO::PARAM_INT); $query->execute() or error(db_error($query)); if($query->rowcount() < 1 && $page > 1) return false; while($th = $query->fetch()) { - $thread = new Thread($th['id'], $th['subject'], $th['email'], $th['name'], $th['trip'], $th['body'], $th['time'], $th['thumb'], $th['thumbwidth'], $th['thumbheight'], $th['file'], $th['filewidth'], $th['fileheight'], $th['filesize'], $th['filename'], $th['ip'], $th['sticky'], $th['locked'], $mod ? '?/' : ROOT, $mod); + $thread = new Thread($th['id'], $th['subject'], $th['email'], $th['name'], $th['trip'], $th['body'], $th['time'], $th['thumb'], $th['thumbwidth'], $th['thumbheight'], $th['file'], $th['filewidth'], $th['fileheight'], $th['filesize'], $th['filename'], $th['ip'], $th['sticky'], $th['locked'], $mod ? '?/' : $config['root'], $mod); $posts = prepare(sprintf("SELECT `id`, `subject`, `email`, `name`, `trip`, `body`, `time`, `thumb`, `thumbwidth`, `thumbheight`, `file`, `filewidth`, `fileheight`, `filesize`, `filename`,`ip` FROM `posts_%s` WHERE `thread` = ? ORDER BY `id` DESC LIMIT ?", $board['uri'])); $posts->bindValue(1, $th['id']); - $posts->bindValue(2, THREADS_PREVIEW, PDO::PARAM_INT); + $posts->bindValue(2, $config['threads_preview'], PDO::PARAM_INT); $posts->execute() or error(db_error($posts)); - if($posts->rowCount() == THREADS_PREVIEW) { + if($posts->rowCount() == $config['threads_preview']) { $count = prepare(sprintf("SELECT COUNT(`id`) as `num` FROM `posts_%s` WHERE `thread` = ?", $board['uri'])); $count->bindValue(1, $th['id']); $count->execute() or error(db_error($count)); $count = $count->fetch(); - $omitted = $count['num'] - THREADS_PREVIEW; + $omitted = $count['num'] - $config['threads_preview']; $thread->omitted = $omitted; unset($count); unset($omitted); } while($po = $posts->fetch()) { - $thread->add(new Post($po['id'], $th['id'], $po['subject'], $po['email'], $po['name'], $po['trip'], $po['body'], $po['time'], $po['thumb'], $po['thumbwidth'], $po['thumbheight'], $po['file'], $po['filewidth'], $po['fileheight'], $po['filesize'], $po['filename'], $po['ip'], $mod ? '?/' : ROOT, $mod)); + $thread->add(new Post($po['id'], $th['id'], $po['subject'], $po['email'], $po['name'], $po['trip'], $po['body'], $po['time'], $po['thumb'], $po['thumbwidth'], $po['thumbheight'], $po['file'], $po['filewidth'], $po['fileheight'], $po['filesize'], $po['filename'], $po['ip'], $mod ? '?/' : $config['root'], $mod)); } $thread->posts = array_reverse($thread->posts); $body .= $thread->build(true); } - return Array('button'=>BUTTON_NEWTOPIC, 'board'=>$board, 'body'=>$body, 'post_url' => POST_URL, 'index' => ROOT); + return Array('button'=>$config['button_newtopic'], 'board'=>$board, 'body'=>$body, 'post_url' => $config['post_url'], 'index' => $config['root']); } function getPages($mod=false) { - global $board; + global $board, $config; // Count threads $query = query(sprintf("SELECT COUNT(`id`) as `num` FROM `posts_%s` WHERE `thread` IS NULL", $board['uri'])) or error(db_error()); $count = current($query->fetch()); - $count = floor((THREADS_PER_PAGE + $count - 1) / THREADS_PER_PAGE); + $count = floor(($config['threads_per_page'] + $count - 1) / $config['threads_per_page']); $pages = Array(); - for($x=0;$x<$count && $x $x+1, 'link' => $x==0 ? ($mod ? '?/' : ROOT) . $board['dir'] . FILE_INDEX : ($mod ? '?/' : ROOT) . $board['dir'] . sprintf(FILE_PAGE, $x+1)); + for($x=0;$x<$count && $x<$config['max_pages'];$x++) { + $pages[] = Array('num' => $x+1, 'link' => $x==0 ? ($mod ? '?/' : $config['root']) . $board['dir'] . $config['file_index'] : ($mod ? '?/' : $config['root']) . $board['dir'] . sprintf($config['file_page'], $x+1)); } return $pages; } function makerobot($body) { + global $config; $body = strtolower($body); // Leave only letters $body = preg_replace('/[^a-z]/i', '', $body); // Remove repeating characters - if(ROBOT_STRIP_REPEATING) + if($config['robot_strip_repeating']) $body = preg_replace('/(.)\\1+/', '$1', $body); return sha1($body); @@ -468,6 +471,7 @@ } function muteTime() { + global $config; // Find number of mutes in the past X hours $query = prepare("SELECT COUNT(*) as `count` FROM `mutes` WHERE `time` >= :time AND `ip` = :ip"); $query->bindValue(':time', time()-(ROBOT_MUTE_HOUR*3600), PDO::PARAM_INT); @@ -476,7 +480,7 @@ $result = $query->fetch(); if($result['count'] == 0) return 0; - return pow(ROBOT_MUTE_MULTIPLIER, $result['count']); + return pow($config['robot_mute_multiplier'], $result['count']); } function mute() { @@ -504,7 +508,7 @@ if($mute['time'] + $mutetime > time()) { // Not expired yet - error(sprintf(ERROR_YOUAREMUTED, $mute['time'] + $mutetime - time())); + error(sprintf($config['error']['youaremuted'], $mute['time'] + $mutetime - time())); } else { // Already expired return; @@ -513,14 +517,14 @@ } function buildIndex() { - global $board; + global $board, $config; sql_open(); $pages = getPages(); $page = 1; - while($page <= MAX_PAGES && $content = index($page)) { - $filename = $board['dir'] . ($page==1 ? FILE_INDEX : sprintf(FILE_PAGE, $page)); + while($page <= $config['max_pages'] && $content = index($page)) { + $filename = $board['dir'] . ($page==1 ? $config['file_index'] : sprintf($config['file_page'], $page)); if(file_exists($filename)) $md5 = md5_file($filename); $content['pages'] = $pages; @@ -531,9 +535,9 @@ } $page++; } - if($page < MAX_PAGES) { - for(;$page<=MAX_PAGES;$page++) { - $filename = $page==1 ? FILE_INDEX : sprintf(FILE_PAGE, $page); + if($page < $config['max_pages']) { + for(;$page<=$config['max_pages'];$page++) { + $filename = $page==1 ? $config['file_index'] : sprintf($config['file_page'], $page); @unlink($filename); } } @@ -566,17 +570,17 @@ } function markup(&$body) { - global $board; + global $board, $config; $body = utf8tohtml($body, true); - if(MARKUP_URLS) { - $body = preg_replace(URL_REGEX, "$0", $body, -1, $num_links); - if($num_links > MAX_LINKS) - error(ERROR_TOOMANYLINKS); + if($config['markup_urls']) { + $body = preg_replace($config['url_regex'], "$0", $body, -1, $num_links); + if($num_links > $config['max_links']) + error($config['error']['toomanylinks']); } - if(AUTO_UNICODE) { + if($config['auto_unicode']) { $body = str_replace('...', '…', $body); $body = str_replace('<--', '←', $body); @@ -603,7 +607,7 @@ $query->execute() or error(db_error($query)); if($post = $query->fetch()) { - $replacement = '>>' . $cite . ''; + $replacement = '>>' . $cite . ''; } else { $replacement = ">>{$cite}"; } @@ -630,7 +634,7 @@ $body = preg_replace("/(^|\n)([\s]+)?(>)([^\n]+)?($|\n)/m", '$1$2$3$4$5', $body); - if(WIKI_MARKUP) { + if($config['wiki_markup']) { $body = preg_replace("/(^|\n)==(.+?)==\n?/m", "

        $2

        ", $body); $body = preg_replace("/'''(.+?)'''/m", "$1", $body); $body = preg_replace("/''(.+?)''/m", "$1", $body); @@ -679,7 +683,7 @@ } function buildThread($id, $return=false, $mod=false) { - global $board; + global $board, $config; $id = round($id); $query = prepare(sprintf("SELECT `id`,`thread`,`subject`,`name`,`email`,`trip`,`body`,`time`,`thumb`,`thumbwidth`,`thumbheight`,`file`,`filewidth`,`fileheight`,`filesize`,`filename`,`ip`,`sticky`,`locked` FROM `posts_%s` WHERE (`thread` IS NULL AND `id` = :id) OR `thread` = :id ORDER BY `thread`,`time`", $board['uri'])); @@ -688,33 +692,34 @@ while($post = $query->fetch()) { if(!isset($thread)) { - $thread = new Thread($post['id'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['sticky'], $post['locked'], $mod ? '?/' : ROOT, $mod); + $thread = new Thread($post['id'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['sticky'], $post['locked'], $mod ? '?/' : $config['root'], $mod); } else { - $thread->add(new Post($post['id'], $thread->id, $post['subject'], $post['email'], $post['name'], $post['trip'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $mod ? '?/' : ROOT, $mod)); + $thread->add(new Post($post['id'], $thread->id, $post['subject'], $post['email'], $post['name'], $post['trip'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $mod ? '?/' : $config['root'], $mod)); } } // Check if any posts were found - if(!isset($thread)) error(ERROR_NONEXISTANT); + if(!isset($thread)) error($config['error']['nonexistant']); $body = Element('thread.html', Array( - 'button'=>BUTTON_REPLY, + 'button'=>$config['button_reply'], 'board'=>$board, 'body'=>$thread->build(), - 'post_url' => POST_URL, - 'index' => ROOT, + 'post_url' => $config['post_url'], + 'index' => $config['root'], 'id' => $id, 'mod' => $mod, - 'return' => ($mod ? '?' . $board['url'] . FILE_INDEX : ROOT . $board['uri'] . '/' . FILE_INDEX) + 'return' => ($mod ? '?' . $board['url'] . $config['file_index'] : $config['root'] . $board['uri'] . '/' . $config['file_index']) )); if($return) return $body; else - @file_put_contents($board['dir'] . DIR_RES . sprintf(FILE_PAGE, $id), $body) or error("Couldn't write to file."); + @file_put_contents($board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $id), $body) or error("Couldn't write to file."); } function generate_tripcode ( $name, $length = 10 ) { + global $config; $name = stripslashes ( $name ); $t = explode('#', $name); $nameo = $t[0]; @@ -730,7 +735,7 @@ $salt = strtr ( $salt, ':;<=>?@[\]^_`', 'ABCDEFGabcdef' ); if ( isset ( $t[2] ) ) { // secure - $trip = '!!' . substr ( crypt ( $trip, SECURE_TRIP_SALT ), ( -1 * $length ) ); + $trip = '!!' . substr ( crypt ( $trip, $config['secure_trip_salt'] ), ( -1 * $length ) ); } else { // insecure $trip = '!' . substr ( crypt ( $trip, $salt ), ( -1 * $length ) ); @@ -865,25 +870,25 @@ case 'jpeg': if(!$image = @imagecreatefromjpeg($source_pic)) { unlink($source_pic); - error(ERR_INVALIDIMG); + error($config['error']['invalidimg']); } break; case 'png': if(!$image = @imagecreatefrompng($source_pic)) { unlink($source_pic); - error(ERR_INVALIDIMG); + error($config['error']['invalidimg']); } break; case 'gif': if(!$image = @imagecreatefromgif($source_pic)) { unlink($source_pic); - error(ERR_INVALIDIMG); + error($config['error']['invalidimg']); } break; case 'bmp': if(!$image = @imagecreatefrombmp($source_pic)) { unlink($source_pic); - error(ERR_INVALIDIMG); + error($config['error']['invalidimg']); } break; default: diff --git a/inc/instance-config.php b/inc/instance-config.php index 88178f2c..864a956c 100644 --- a/inc/instance-config.php +++ b/inc/instance-config.php @@ -11,14 +11,41 @@ // Database stuff - define('DB_TYPE', 'mysql'); - define('DB_SERVER', 'localhost'); - define('DB_USER', ''); - define('DB_PASSWORD', ''); - define('DB_DATABASE', ''); - - define('ROOT', '/'); - -// define('FOO', 'bar'); - + $config['db']['type'] = 'mysql'; + $config['db']['server'] = 'localhost'; + $config['db']['user'] = ''; + $config['db']['password'] = ''; + $config['db']['database'] = ''; + + $config['root'] = '/'; + + + + // The following looks ugly. I will find a better place to put this code soon. + $config['post_url'] = $config['root'] . 'post.php'; + + $config['url_match'] = '/^' . + (preg_match($config['url_regex'], $config['root']) ? '' : + (@$_SERVER['HTTPS']?'https':'http') . + ':\/\/'.$_SERVER['HTTP_HOST']) . + preg_quote($config['root'], '/') . + '(' . + str_replace('%s', '\w{1,8}', preg_quote($config['board_path'], '/')) . + '|' . + str_replace('%s', '\w{1,8}', preg_quote($config['board_path'], '/')) . + preg_quote($config['file_index'], '/') . + '|' . + str_replace('%s', '\w{1,8}', preg_quote($config['board_path'], '/')) . + str_replace('%d', '\d+', preg_quote($config['file_page'], '/')) . + '|' . + preg_quote($config['file_mod'], '/') . + '\?\/.+' . + ')$/i'; + + $config['dir']['static'] = $config['root'] . 'static/'; + + $config['image_sticky'] = $config['dir']['static'] . 'sticky.gif'; + $config['image_locked'] = $config['dir']['static'] . 'locked.gif'; + $config['image_deleted'] = $config['dir']['static'] . 'deleted.png'; + $config['image_zip'] = $config['dir']['static'] . 'zip.png'; ?> \ No newline at end of file diff --git a/inc/template.php b/inc/template.php index ff65c0c3..d8961167 100644 --- a/inc/template.php +++ b/inc/template.php @@ -8,7 +8,7 @@ // Standard configuration // // Folder where the template files are kept - $templateDir = DIR_TEMPLATE; + $templateDir = $config['dir']['template']; // // Enable global things like %gentime, etc. $templateGlobals = true; diff --git a/inc/user.php b/inc/user.php index 6470d2ff..021515a2 100644 --- a/inc/user.php +++ b/inc/user.php @@ -3,10 +3,10 @@ $mod = false; // Set the session name. - session_name(SESS_COOKIE); + session_name($config['cookies']['session']); // Set session parameters - session_set_cookie_params(0, JAIL_COOKIES?ROOT:'/'); + session_set_cookie_params(0, $config['cookies']['jail']?$config['root']:'/'); // Start the session session_start(); @@ -14,13 +14,13 @@ // Session creation time if(!isset($_SESSION['created'])) $_SESSION['created'] = time(); - if(!isset($_COOKIE[HASH_COOKIE]) || !isset($_COOKIE[TIME_COOKIE]) || $_COOKIE[HASH_COOKIE] != md5($_COOKIE[TIME_COOKIE].SALT)) { + if(!isset($_COOKIE[$config['cookies']['hash']]) || !isset($_COOKIE[$config['cookies']['time']]) || $_COOKIE[$config['cookies']['hash']] != md5($_COOKIE[$config['cookies']['time']] . $config['cookies']['salt'])) { $time = time(); - setcookie(TIME_COOKIE, $time, time()+COOKIE_EXPIRE, JAIL_COOKIES?ROOT:'/', null, false, true); - setcookie(HASH_COOKIE, md5($time.SALT), $time+COOKIE_EXPIRE, JAIL_COOKIES?ROOT:'/', null, false, true); + setcookie($config['cookies']['time'], $time, time()+$config['cookies']['expire'], $config['cookies']['jail']?$config['root']:'/', null, false, true); + setcookie($config['cookies']['hash'], md5($time . $config['cookies']['salt']), $time+$config['cookies']['expire'], $config['cookies']['jail']?$config['root']:'/', null, false, true); $user = Array('valid' => false, 'appeared' => $time); } else { - $user = Array('valid' => true, 'appeared' => $_COOKIE[TIME_COOKIE]); + $user = Array('valid' => true, 'appeared' => $_COOKIE[$config['cookies']['time']]); } ?> \ No newline at end of file diff --git a/mod.php b/mod.php index 12b730a0..40244b4a 100644 --- a/mod.php +++ b/mod.php @@ -1,10 +1,10 @@ str_replace('%s', '(\w{1,8})', preg_quote(BOARD_PATH, '/')), - 'page' => str_replace('%d', '(\d+)', preg_quote(FILE_PAGE, '/')), - 'img' => preg_quote(DIR_IMG, '/'), - 'thumb' => preg_quote(DIR_THUMB, '/'), - 'res' => preg_quote(DIR_RES, '/'), - 'index' => preg_quote(FILE_INDEX, '/') + 'board' => str_replace('%s', '(\w{1,8})', preg_quote($config['board_path'], '/')), + 'page' => str_replace('%d', '(\d+)', preg_quote($config['file_page'], '/')), + 'img' => preg_quote($config['dir']['img'], '/'), + 'thumb' => preg_quote($config['dir']['thumb'], '/'), + 'res' => preg_quote($config['dir']['res'], '/'), + 'index' => preg_quote($config['file_index'], '/') ); if(preg_match('/^\/?$/', $query)) { @@ -81,10 +81,10 @@ // Boards $fieldset['Boards'] .= ulBoards(); - if($mod['type'] >= MOD_VIEW_BANLIST) { + if($mod['type'] >= $config['mod']['view_banlist']) { $fieldset['Administration'] .= '
      • Ban list
      • '; } - if($mod['type'] >= MOD_SHOW_CONFIG) { + if($mod['type'] >= $config['mod']['show_config']) { $fieldset['Administration'] .= '
      • Show configuration
      • '; } @@ -97,16 +97,16 @@ } echo Element('page.html', Array( - 'index'=>ROOT, + 'index'=>$config['root'], 'title'=>'Dashboard', 'body'=>$body //,'mod'=>true /* All 'mod' does, at this point, is put the "Return to dashboard" link in. */ ) ); } elseif(preg_match('/^\/bans$/', $query)) { - if($mod['type'] < MOD_VIEW_BANLIST) error(ERROR_NOACCESS); + if($mod['type'] < $config['mod']['view_banlist']) error($config['error']['noaccess']); - if(MOD_VIEW_BANEXPIRED) { + if($config['mod']['view_banexpired']) { $query = prepare("SELECT * FROM `bans` INNER JOIN `mods` ON `mod` = `id` GROUP BY `ip` ORDER BY `expires` < :time, `set` DESC"); $query->bindValue(':time', time(), PDO::PARAM_INT); $query->execute() or error(db_error($query)); @@ -126,7 +126,7 @@ while($ban = $query->fetch()) { $body .= '' . @@ -145,26 +145,26 @@ '' . $ban['reason'] . '' . // Set - '' . date(POST_DATE, $ban['set']) . '' . + '' . date($config['post_date'], $ban['set']) . '' . // Expires '' . ($ban['expires'] == 0 ? 'Never' : - date(POST_DATE, $ban['expires']) + date($config['post_date'], $ban['expires']) ) . '' . // Staff '' . - ($mod['type'] < MOD_VIEW_BANSTAFF ? - (MOD_VIEW_BANQUESTIONMARK ? + ($mod['type'] < $config['mod']['view_banstaff'] ? + ($config['mod']['view_banquestionmark'] ? '?' : - ($ban['type'] == MOD_JANITOR ? 'Janitor' : - ($ban['type'] == MOD_MOD ? 'Mod' : - ($ban['type'] == MOD_ADMIN ? 'Admin' : + ($ban['type'] == JANITOR ? 'Janitor' : + ($ban['type'] == MOD ? 'Mod' : + ($ban['type'] == ADMIN ? 'Admin' : '?'))) ) : @@ -181,14 +181,14 @@ } echo Element('page.html', Array( - 'index'=>ROOT, + 'index'=>$config['root'], 'title'=>'Ban list', 'body'=>$body, 'mod'=>true ) ); } elseif(preg_match('/^\/config$/', $query)) { - if($mod['type'] < MOD_SHOW_CONFIG) error(ERROR_NOACCESS); + if($mod['type'] < $config['mod']['show_config']) error($config['error']['noaccess']); // Show instance-config.php @@ -240,14 +240,14 @@ $body = '
        Configuration' . $data . '
        '; echo Element('page.html', Array( - 'index'=>ROOT, + 'index'=>$config['root'], 'title'=>'Configuration', 'body'=>$body, 'mod'=>true ) ); } elseif(preg_match('/^\/new$/', $query)) { - if($mod['type'] < MOD_NEWBOARD) error(ERROR_NOACCESS); + if($mod['type'] < $config['mod']['newboard']) error($config['error']['noaccess']); // New board $body = ''; @@ -257,7 +257,7 @@ if( !isset($_POST['uri']) || !isset($_POST['title']) || !isset($_POST['subtitle']) - ) error(ERROR_MISSEDAFIELD); + ) error($config['error']['missedafield']); $b = Array( 'uri' => $_POST['uri'], @@ -267,24 +267,24 @@ // Check required fields if(empty($b['uri'])) - error(sprintf(ERROR_REQUIRED, 'URI')); + error(sprintf($config['error']['required'], 'URI')); if(empty($b['title'])) - error(sprintf(ERROR_REQUIRED, 'title')); + error(sprintf($config['error']['required'], 'title')); // Check string lengths if(strlen($b['uri']) > 8) - error(sprintf(ERROR_TOOLONG, 'URI')); + error(sprintf($config['error']['toolong'], 'URI')); if(strlen($b['title']) > 20) - error(sprintf(ERROR_TOOLONG, 'title')); + error(sprintf($config['error']['toolong'], 'title')); if(strlen($b['subtitle']) > 40) - error(sprintf(ERROR_TOOLONG, 'subtitle')); + error(sprintf($config['error']['toolong'], 'subtitle')); if(!preg_match('/^\w+$/', $b['uri'])) - error(sprintf(ERROR_INVALIDFIELD, 'URI')); + error(sprintf($config['error']['invalidfield'], 'URI')); if(openBoard($b['uri'])) { unset($board); - error(sprintf(ERROR_BOARDEXISTS, sprintf(BOARD_ABBREVIATION, $b['uri']))); + error(sprintf($config['error']['boardexists'], sprintf($config['board_abbreviation'], $b['uri']))); } $query = prepare("INSERT INTO `boards` VALUES (NULL, :uri, :title, :subtitle)"); @@ -315,7 +315,7 @@ // TODO: Statistics, etc, in the dashboard. echo Element('page.html', Array( - 'index'=>ROOT, + 'index'=>$config['root'], 'title'=>'New board', 'body'=>$body, 'mod'=>true @@ -328,10 +328,10 @@ // Open board if(!openBoard($boardName)) - error(ERROR_NOBOARD); + error($config['error']['noboard']); - if(!$page = index(empty($matches[2]) || $matches[2] == FILE_INDEX ? 1 : $matches[2], $mod)) { - error(ERROR_404); + if(!$page = index(empty($matches[2]) || $matches[2] == $config['file_index'] ? 1 : $matches[2], $mod)) { + error($config['error']['404']); } $page['pages'] = getPages(true); $page['mod'] = true; @@ -344,20 +344,20 @@ $thread = $matches[2]; // Open board if(!openBoard($boardName)) - error(ERROR_NOBOARD); + error($config['error']['noboard']); $page = buildThread($thread, true, $mod); echo $page; } elseif(preg_match('/^\/' . $regex['board'] . 'deletefile\/(\d+)$/', $query, $matches)) { - if($mod['type'] < MOD_DELETEFILE) error(ERROR_NOACCESS); + if($mod['type'] < $config['mod']['deletefile']) error($config['error']['noaccess']); // Delete file from post $boardName = $matches[1]; $post = $matches[2]; // Open board if(!openBoard($boardName)) - error(ERROR_NOBOARD); + error($config['error']['noboard']); // Delete post deleteFile($post); @@ -371,18 +371,18 @@ // Redirect if(isset($_SERVER['HTTP_REFERER'])) - header('Location: ' . $_SERVER['HTTP_REFERER'], true, REDIRECT_HTTP); + header('Location: ' . $_SERVER['HTTP_REFERER'], true, $config['redirect_http']); else - header('Location: ?/' . sprintf(BOARD_PATH, $boardName) . FILE_INDEX, true, REDIRECT_HTTP); + header('Location: ?/' . sprintf($config['board_path'], $boardName) . $config['file_index'], true, $config['redirect_http']); } elseif(preg_match('/^\/' . $regex['board'] . 'delete\/(\d+)$/', $query, $matches)) { - if($mod['type'] < MOD_DELETE) error(ERROR_NOACCESS); + if($mod['type'] < $config['mod']['delete']) error($config['error']['noaccess']); // Delete post $boardName = $matches[1]; $post = $matches[2]; // Open board if(!openBoard($boardName)) - error(ERROR_NOBOARD); + error($config['error']['noboard']); // Delete post deletePost($post); @@ -395,18 +395,18 @@ // Redirect if(isset($_SERVER['HTTP_REFERER'])) - header('Location: ' . $_SERVER['HTTP_REFERER'], true, REDIRECT_HTTP); + header('Location: ' . $_SERVER['HTTP_REFERER'], true, $config['redirect_http']); else - header('Location: ?/' . sprintf(BOARD_PATH, $boardName) . FILE_INDEX, true, REDIRECT_HTTP); + header('Location: ?/' . sprintf($config['board_path'], $boardName) . $config['file_index'], true, $config['redirect_http']); } elseif(preg_match('/^\/' . $regex['board'] . '(un)?sticky\/(\d+)$/', $query, $matches)) { - if($mod['type'] < MOD_STICKY) error(ERROR_NOACCESS); + if($mod['type'] < $config['mod']['sticky']) error($config['error']['noaccess']); // Add/remove sticky $boardName = $matches[1]; $post = $matches[3]; // Open board if(!openBoard($boardName)) - error(ERROR_NOBOARD); + error($config['error']['noboard']); $query = prepare(sprintf("UPDATE `posts_%s` SET `sticky` = :sticky WHERE `id` = :id AND `thread` IS NULL", $board['uri'])); $query->bindValue(':id', $post, PDO::PARAM_INT); @@ -429,18 +429,18 @@ // Redirect if(isset($_SERVER['HTTP_REFERER'])) - header('Location: ' . $_SERVER['HTTP_REFERER'], true, REDIRECT_HTTP); + header('Location: ' . $_SERVER['HTTP_REFERER'], true, $config['redirect_http']); else - header('Location: ?/' . sprintf(BOARD_PATH, $boardName) . FILE_INDEX, true, REDIRECT_HTTP); + header('Location: ?/' . sprintf($config['board_path'], $boardName) . $config['file_index'], true, $config['redirect_http']); } elseif(preg_match('/^\/' . $regex['board'] . '(un)?lock\/(\d+)$/', $query, $matches)) { - if($mod['type'] < MOD_LOCK) error(ERROR_NOACCESS); + if($mod['type'] < $config['mod']['lock']) error($config['error']['noaccess']); // Lock/Unlock $boardName = $matches[1]; $post = $matches[3]; // Open board if(!openBoard($boardName)) - error(ERROR_NOBOARD); + error($config['error']['noboard']); $query = prepare(sprintf("UPDATE `posts_%s` SET `locked` = :locked WHERE `id` = :id AND `thread` IS NULL", $board['uri'])); $query->bindValue(':id', $post, PDO::PARAM_INT); @@ -463,9 +463,9 @@ // Redirect if(isset($_SERVER['HTTP_REFERER'])) - header('Location: ' . $_SERVER['HTTP_REFERER'], true, REDIRECT_HTTP); + header('Location: ' . $_SERVER['HTTP_REFERER'], true, $config['redirect_http']); else - header('Location: ?/' . sprintf(BOARD_PATH, $boardName) . FILE_INDEX, true, REDIRECT_HTTP); + header('Location: ?/' . sprintf($config['board_path'], $boardName) . $config['file_index'], true, $config['redirect_http']); } elseif(preg_match('/^\/' . $regex['board'] . 'deletebyip\/(\d+)$/', $query, $matches)) { // Delete all posts by an IP @@ -473,14 +473,14 @@ $post = $matches[2]; // Open board if(!openBoard($boardName)) - error(ERROR_NOBOARD); + error($config['error']['noboard']); $query = prepare(sprintf("SELECT `ip` FROM `posts_%s` WHERE `id` = :id", $board['uri'])); $query->bindValue(':id', $post); $query->execute() or error(db_error($query)); if(!$post = $query->fetch()) - error(ERROR_INVALIDPOST); + error($config['error']['invalidpost']); $ip = $post['ip']; @@ -492,16 +492,16 @@ $query->execute() or error(db_error($query)); if($query->rowCount() < 1) - error(ERROR_INVALIDPOST); + error($config['error']['invalidpost']); while($post = $query->fetch()) { deletePost($post['id'], false); } if(isset($_SERVER['HTTP_REFERER'])) - header('Location: ' . $_SERVER['HTTP_REFERER'], true, REDIRECT_HTTP); + header('Location: ' . $_SERVER['HTTP_REFERER'], true, $config['redirect_http']); else - header('Location: ?/' . sprintf(BOARD_PATH, $boardName) . FILE_INDEX, true, REDIRECT_HTTP); + header('Location: ?/' . sprintf($config['board_path'], $boardName) . $config['file_index'], true, $config['redirect_http']); } elseif(preg_match('/^\/ban$/', $query)) { // Ban page @@ -509,11 +509,11 @@ if( !isset($_POST['ip']) || !isset($_POST['reason']) || !isset($_POST['length']) - ) error(ERROR_MISSEDAFIELD); + ) error($config['error']['missedafield']); // Check required fields if(empty($_POST['ip'])) - error(sprintf(ERROR_REQUIRED, 'IP address')); + error(sprintf($config['error']['required'], 'IP address')); $query = prepare("INSERT INTO `bans` VALUES (:ip, :mod, :set, :expires, :reason)"); @@ -569,19 +569,19 @@ $query->execute() or error(db_error($query)); // Delete too - if($mod['type'] >= MOD_DELETE && isset($_POST['delete']) && isset($_POST['board'])) { + if($mod['type'] >= $config['mod']['delete'] && isset($_POST['delete']) && isset($_POST['board'])) { openBoard($_POST['board']); deletePost(round($_POST['delete'])); } // Redirect if(isset($_POST['continue'])) - header('Location: ' . $_POST['continue'], true, REDIRECT_HTTP); + header('Location: ' . $_POST['continue'], true, $config['redirect_http']); else - header('Location: ?/' . sprintf(BOARD_PATH, $boardName) . FILE_INDEX, true, REDIRECT_HTTP); + header('Location: ?/' . sprintf($config['board_path'], $boardName) . $config['file_index'], true, $config['redirect_http']); } } elseif(preg_match('/^\/' . $regex['board'] . 'ban(&delete)?\/(\d+)$/', $query, $matches)) { - if($mod['type'] < MOD_DELETE) error(ERROR_NOACCESS); + if($mod['type'] < $config['mod']['delete']) error($config['error']['noaccess']); // Ban by post $boardName = $matches[1]; @@ -589,14 +589,14 @@ $post = $matches[3]; // Open board if(!openBoard($boardName)) - error(ERROR_NOBOARD); + error($config['error']['noboard']); $query = prepare(sprintf("SELECT `ip`,`id` FROM `posts_%s` WHERE `id` = :id LIMIT 1", $board['uri'])); $query->bindValue(':id', $post, PDO::PARAM_INT); $query->execute() or error(db_error($query)); if($query->rowCount() < 1) { - error(ERROR_INVALIDPOST); + error($config['error']['invalidpost']); } $post = $query->fetch(); @@ -604,7 +604,7 @@ $body = form_newBan($post['ip'], null, isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false, $delete ? $post['id'] : false, $delete ? $boardName : false); echo Element('page.html', Array( - 'index'=>ROOT, + 'index'=>$config['root'], 'title'=>'New ban', 'body'=>$body, 'mod'=>true @@ -614,7 +614,7 @@ // View information on an IP address $ip = $matches[1]; - $host = MOD_DNS_LOOKUP ? gethostbyaddr($ip) : false; + $host = $config['mod']['dns_lookup'] ? gethostbyaddr($ip) : false; $body = ''; $boards = listBoards(); @@ -624,26 +624,26 @@ $temp = ''; $query = prepare(sprintf("SELECT * FROM `posts_%s` WHERE `ip` = :ip ORDER BY `sticky` DESC, `time` DESC LIMIT :limit", $_board['uri'])); $query->bindValue(':ip', $ip); - $query->bindValue(':limit', MOD_IP_RECENTPOSTS, PDO::PARAM_INT); + $query->bindValue(':limit', $config['mod']['ip_recentposts'], PDO::PARAM_INT); $query->execute() or error(db_error($query)); while($post = $query->fetch()) { - $po = new Post($post['id'], $post['thread'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $mod ? '?/' : ROOT, $mod); + $po = new Post($post['id'], $post['thread'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $mod ? '?/' : $config['root'], $mod); $temp .= $po->build(); } if(!empty($temp)) $body .= '
        Last ' . $query->rowCount() . ' posts on ' . - sprintf(BOARD_ABBREVIATION, $_board['uri']) . ' - ' . $_board['title'] . + sprintf($config['board_abbreviation'], $_board['uri']) . ' - ' . $_board['title'] . '' . $temp . '
        '; } - if(MOD_IP_BANFORM) + if($config['mod']['ip_banform']) $body .= form_newBan($ip, null, isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false); echo Element('page.html', Array( - 'index'=>ROOT, + 'index'=>$config['root'], 'title'=>'IP: ' . $ip, 'subtitle' => $host, 'body'=>$body, @@ -651,7 +651,7 @@ ) ); } else { - error(ERROR_404); + error($config['error']['404']); } } diff --git a/post.php b/post.php index 38599222..431be0c0 100644 --- a/post.php +++ b/post.php @@ -1,10 +1,10 @@ $value) { @@ -45,15 +45,15 @@ // Check if banned checkBan(); - if(BLOCK_TOR && isTor()) - error(ERROR_TOR); + if($config['block_tor'] && isTor()) + error($config['error']['tor']); // Check if board exists if(!openBoard($_POST['board'])) - error(ERROR_NOBOARD); + error($config['error']['noboard']); if(empty($delete)) - error(ERROR_NODELETE); + error($config['error']['nodelete']); foreach($delete as &$id) { $query = prepare(sprintf("SELECT `password` FROM `posts_%s` WHERE `id` = :id", $board['uri'])); @@ -62,7 +62,7 @@ if($post = $query->fetch()) { if(!empty($password) && $post['password'] != $password) - error(ERROR_INVALIDPASSWORD); + error($config['error']['invalidpassword']); if(isset($_POST['file'])) { // Delete just the file @@ -79,9 +79,9 @@ sql_close(); $is_mod = isset($_POST['mod']) && $_POST['mod']; - $root = $is_mod ? ROOT . FILE_MOD . '?/' : ROOT; + $root = $is_mod ? $config['root'] . $config['file_mod'] . '?/' : $config['root']; - header('Location: ' . $root . $board['dir'] . FILE_INDEX, true, REDIRECT_HTTP); + header('Location: ' . $root . $board['dir'] . $config['file_index'], true, $config['redirect_http']); } elseif(isset($_POST['post'])) { if( !isset($_POST['name']) || @@ -90,7 +90,7 @@ !isset($_POST['body']) || !isset($_POST['board']) || !isset($_POST['password']) - ) error(ERROR_BOT); + ) error($config['error']['bot']); $post = Array('board' => $_POST['board']); @@ -99,13 +99,13 @@ $post['thread'] = round($_POST['thread']); } else $OP = true; - //if(!(($OP && $_POST['post'] == BUTTON_NEWTOPIC) || - // (!$OP && $_POST['post'] == BUTTON_REPLY))) - // error(ERROR_BOT); + if(!(($OP && $_POST['post'] == $config['button_newtopic']) || + (!$OP && $_POST['post'] == $config['button_reply']))) + error($config['error']['bot']); // Check the referrer if($OP) { - if(!isset($_SERVER['HTTP_REFERER']) || !preg_match(URL_MATCH, $_SERVER['HTTP_REFERER'])) error(ERROR_BOT); + if(!isset($_SERVER['HTTP_REFERER']) || !preg_match($config['url_match'], $_SERVER['HTTP_REFERER'])) error($config['error']['bot']); } // TODO: Since we're now using static HTML files, we can't give them cookies on their first page view @@ -113,7 +113,7 @@ /* // Check if he has a valid cookie. - if(!$user['valid']) error(ERROR_BOT); + if(!$user['valid']) error($config['error']['bot']); // Check how long he has been here. if(time()-$user['appeared'] MAX_FILESIZE) - error(sprintf3(ERR_FILESIZE, array( + if($size > $config['max_filesize']) + error(sprintf3($config['error']['filesize'], array( 'sz'=>commaize($size), 'filesz'=>commaize($size), - 'maxsz'=>commaize(MAX_FILESIZE)))); + 'maxsz'=>commaize($config['max_filesize'])))); } - if($mod && $mod['type'] >= MOD_MOD && preg_match('/^((.+) )?## (.+)$/', $post['name'], $match)) { - if(($mod['type'] == MOD_MOD && $match[3] == 'Mod') || $mod['type'] >= MOD_ADMIN) { + if($mod && $mod['type'] >= MOD && preg_match('/^((.+) )?## (.+)$/', $post['name'], $match)) { + if(($mod['type'] == MOD && $match[3] == 'Mod') || $mod['type'] >= ADMIN) { $post['mod_tag'] = $match[3]; $post['name'] = !empty($match[2])?$match[2]:'Anonymous'; } @@ -211,19 +211,17 @@ if($post['has_file']) { $post['extension'] = strtolower(substr($post['filename'], strrpos($post['filename'], '.') + 1)); $post['file_id'] = time() . rand(100, 999); - $post['file'] = $board['dir'] . DIR_IMG . $post['file_id'] . '.' . $post['extension']; - $post['thumb'] = $board['dir'] . DIR_THUMB . $post['file_id'] . '.png'; - $post['zip'] = $OP && $post['has_file'] && ALLOW_ZIP && $post['extension'] == 'zip' ? $post['file'] : false; - if(!($post['zip'] || in_array($post['extension'], $allowed_ext))) error(ERROR_FILEEXT); + $post['file'] = $board['dir'] . $config['dir']['img'] . $post['file_id'] . '.' . $post['extension']; + $post['thumb'] = $board['dir'] . $config['dir']['thumb'] . $post['file_id'] . '.png'; } // Check string lengths - if(strlen($post['name']) > 50) error(sprintf(ERROR_TOOLONG, 'name')); - if(strlen($post['email']) > 30) error(sprintf(ERROR_TOOLONG, 'email')); - if(strlen($post['subject']) > 40) error(sprintf(ERROR_TOOLONG, 'subject')); - if(!$mod && strlen($post['body']) > MAX_BODY) error(ERROR_TOOLONGBODY); - if(!(!$OP && $post['has_file']) && strlen($post['body']) < 1) error(ERROR_TOOSHORTBODY); - if(strlen($post['password']) > 20) error(sprintf(ERROR_TOOLONG, 'password')); + if(strlen($post['name']) > 50) error(sprintf($config['error']['toolong'], 'name')); + if(strlen($post['email']) > 30) error(sprintf($config['error']['toolong'], 'email')); + if(strlen($post['subject']) > 40) error(sprintf($config['error']['toolong'], 'subject')); + if(!$mod && strlen($post['body']) > $config['max_body']) error($config['error']['toolongbody']); + if(!(!$OP && $post['has_file']) && strlen($post['body']) < 1) error($config['error']['tooshortbody']); + if(strlen($post['password']) > 20) error(sprintf($config['error']['toolong'], 'password')); if($post['mod_tag']) $post['trip'] .= ' ## ' . $post['mod_tag'] . ''; @@ -235,26 +233,14 @@ // Check for a flood if(checkFlood($post)) { - error(ERROR_FLOOD); + error($config['error']['flood']); } if($post['has_file']) { // Just trim the filename if it's too long if(strlen($post['filename']) > 30) $post['filename'] = substr($post['filename'], 0, 27).'…'; // Move the uploaded file - if(!@move_uploaded_file($_FILES['file']['tmp_name'], $post['file'])) error(ERROR_NOMOVE); - - if($post['zip']) { - // Validate ZIP file - if(is_resource($zip = zip_open($post['zip']))) - // TODO: Check if it's not empty and has at least one (valid) image - zip_close($zip); - else - error(ERR_INVALIDZIP); - - $post['file'] = ZIP_IMAGE; - $post['extension'] = strtolower(substr($post['file'], strrpos($post['file'], '.') + 1)); - } + if(!@move_uploaded_file($_FILES['file']['tmp_name'], $post['file'])) error($config['error']['nomove']); $size = @getimagesize($post['file']); $post['width'] = $size[0]; @@ -263,165 +249,48 @@ // Check if the image is valid if($post['width'] < 1 || $post['height'] < 1) { unlink($post['file']); - error(ERR_INVALIDIMG); + error($config['error']['invalidimg']); } - if($post['width'] > MAX_WIDTH || $post['height'] > MAX_HEIGHT) { + if($post['width'] > $config['max_width'] || $post['height'] > $config['max_height']) { unlink($post['file']); - error(ERR_MAXSIZE); + error($config['error']['maxsize']); } - $hash_function = FILE_HASH; - $post['filehash'] = $hash_function($post['file']); + $post['filehash'] = $config['file_hash']($post['file']); $post['filesize'] = filesize($post['file']); $image = createimage($post['extension'], $post['file']); - if(REDRAW_IMAGE && !$post['zip']) { - switch($post['extension']) { - case 'jpg': - case 'jpeg': - imagejpeg($image, $post['file'], JPEG_QUALITY); - break; - case 'png': - imagepng($image, $post['file'], 7); - break; - case 'gif': - if(REDRAW_GIF) - imagegif($image, $post['file']); - break; - case 'bmp': - imagebmp($image, $post['file']); - break; - default: - unlink($post['file']); - error('Unknwon file extension.'); - } - } - // Create a thumbnail - $thumb = resize($image, $post['width'], $post['height'], $post['thumb'], THUMB_WIDTH, THUMB_HEIGHT); + $thumb = resize($image, $post['width'], $post['height'], $post['thumb'], $config['thumb_width'], $config['thumb_height']); $post['thumbwidth'] = $thumb['width']; $post['thumbheight'] = $thumb['height']; } - if(!($mod && $mod['type'] >= MOD_POSTUNORIGINAL) && ROBOT_ENABLE && $board['uri'] == ROBOT_BOARD && checkRobot($post['body_nomarkup'])) { + /* + if(!($mod && $mod['type'] >= $config['mod']['postunoriginal']) && ROBOT_ENABLE && $board['uri'] == ROBOT_BOARD && checkRobot($post['body_nomarkup'])) { if(ROBOT_MUTE) { - error(sprintf(ERROR_MUTED, mute())); + error(sprintf($config['error']['muted'], mute())); } else { - error(ERROR_UNORIGINAL); + error($config['error']['unoriginal']); } } + */ // Remove DIR_* before inserting them into the database. if($post['has_file']) { - $post['file'] = substr_replace($post['file'], '', 0, strlen($board['dir'] . DIR_IMG)); - $post['thumb'] = substr_replace($post['thumb'], '', 0, strlen($board['dir'] . DIR_THUMB)); + $post['file'] = substr_replace($post['file'], '', 0, strlen($board['dir'] . $config['dir']['img'])); + $post['thumb'] = substr_replace($post['thumb'], '', 0, strlen($board['dir'] . $config['dir']['thumb'])); } // Todo: Validate some more, remove messy code, allow more specific configuration $id = post($post, $OP); - if($post['has_file'] && $post['zip']) { - // Open ZIP - $zip = zip_open($post['zip']); - // Read files - while($entry = zip_read($zip)) { - $filename = basename(zip_entry_name($entry)); - $extension = strtolower(substr($filename, strrpos($filename, '.') + 1)); - - if(in_array($extension, $allowed_ext)) { - if (zip_entry_open($zip, $entry, 'r')) { - // Fake post - $dump_post = Array( - 'subject' => $post['subject'], - 'email' => $post['email'], - 'name' => $post['name'], - 'trip' => $post['trip'], - 'body' => '', - 'thread' => $id, - 'password' => '', - 'has_file' => true, - 'file_id' => rand(0, 1000000000), - 'filename' => $filename - ); - - $dump_post['file'] = $board['dir'] . DIR_IMG . $dump_post['file_id'] . '.' . $extension; - $dump_post['thumb'] = $board['dir'] . DIR_THUMB . $dump_post['file_id'] . '.png'; - - // Extract the image from the ZIP - $fp = fopen($dump_post['file'], 'w+'); - fwrite($fp, zip_entry_read($entry, zip_entry_filesize($entry))); - fclose($fp); - - $size = @getimagesize($dump_post['file']); - $dump_post['width'] = $size[0]; - $dump_post['height'] = $size[1]; - - // Check if the image is valid - if($dump_post['width'] < 1 || $dump_post['height'] < 1) { - unlink($dump_post['file']); - } else { - if($dump_post['width'] > MAX_WIDTH || $dump_post['height'] > MAX_HEIGHT) { - unlink($dump_post['file']); - error(ERR_MAXSIZE); - } else { - $dump_post['filehash'] = md5_file($dump_post['file']); - $dump_post['filesize'] = filesize($dump_post['file']); - - $image = createimage($extension, $dump_post['file']); - - $success = true; - if(REDRAW_IMAGE) { - switch($extension) { - case 'jpg': - case 'jpeg': - imagejpeg($image, $dump_post['file'], JPEG_QUALITY); - break; - case 'png': - imagepng($image, $dump_post['file'], 7); - break; - case 'gif': - if(REDRAW_GIF) - imagegif($image, $dump_post['file']); - break; - case 'bmp': - imagebmp($image, $dump_post['file']); - break; - default: - $success = false; - } - } - - - // Create a thumbnail - $thumb = resize($image, $dump_post['width'], $dump_post['height'], $dump_post['thumb'], THUMB_WIDTH, THUMB_HEIGHT); - - $dump_post['thumbwidth'] = $thumb['width']; - $dump_post['thumbheight'] = $thumb['height']; - - // Remove DIR_* before inserting them into the database. - $dump_post['file'] = substr_replace($dump_post['file'], '', 0, strlen($board['dir'] . DIR_IMG)); - $dump_post['thumb'] = substr_replace($dump_post['thumb'], '', 0, strlen($board['dir'] . DIR_THUMB)); - - // Create the post - post($dump_post, false); - } - } - - // Close the ZIP - zip_entry_close($entry); - } - } - } - zip_close($zip); - unlink($post['zip']); - } - buildThread(($OP?$id:$post['thread'])); - if(!$OP && strtolower($post['email']) != 'sage' && (REPLY_LIMIT == 0 || numPosts($post['thread']) < REPLY_LIMIT)) { + if(!$OP && strtolower($post['email']) != 'sage' && ($config['reply_limit'] == 0 || numPosts($post['thread']) < $config['reply_limit'])) { bumpThread($post['thread']); } @@ -431,17 +300,17 @@ buildIndex(); sql_close(); - $root = $post['mod'] ? ROOT . FILE_MOD . '?/' : ROOT; + $root = $post['mod'] ? $config['root'] . $config['file_mod'] . '?/' : $config['root']; - if(ALWAYS_NOKO || $noko) { - header('Location: ' . $root . $board['dir'] . DIR_RES . ($OP?$id:$post['thread']) . '.html' . (!$OP?'#'.$id:''), true, REDIRECT_HTTP); + if($config['always_noko'] || $noko) { + header('Location: ' . $root . $board['dir'] . $config['dir']['res'] . ($OP?$id:$post['thread']) . '.html' . (!$OP?'#'.$id:''), true, $config['redirect_http']); } else { - header('Location: ' . $root . $board['dir'] . FILE_INDEX, true, REDIRECT_HTTP); + header('Location: ' . $root . $board['dir'] . $config['file_index'], true, $config['redirect_http']); } exit; } else { - if(!file_exists(HAS_INSTALLED)) { + if(!file_exists($config['has_installed'])) { sql_open(); // Build all boards @@ -452,7 +321,7 @@ } sql_close(); - touch(HAS_INSTALLED, 0777); + touch($config['has_installed'], 0777); die(Element('page.html', Array( 'index'=>ROOT, @@ -464,7 +333,7 @@ } else { // They opened post.php in their browser manually. // Possible TODO: Redirect back to homepage. - error(ERROR_NOPOST); + error($config['error']['nopost']); } } ?> -- cgit v1.3