From cd999b41f922cfbc71aae6c375f0971b9f29996c Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Tue, 30 Nov 2010 18:59:48 +1100
Subject: config
---
inc/config.php | 3 +++
1 file changed, 3 insertions(+)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 0fce2593..529fd6eb 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -98,6 +98,9 @@
define('POST_URL', ROOT . 'post.php', true);
define('FILE_INDEX', 'index.html', true);
define('FILE_PAGE', '%d.html', true);
+
+ // Multi-board (%s is board abbreviation)
+ define('BOARD_PATH', '%s', true);
// Automatically convert things like "..." to Unicode characters ("…")
define('AUTO_UNICODE', true, true);
--
cgit v1.3
From 27cc4af33a526ca56f9bd648e20c5669b4775139 Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Tue, 30 Nov 2010 19:12:35 +1100
Subject: boards
---
inc/config.php | 6 ++++--
inc/functions.php | 8 +++++---
post.php | 5 ++++-
3 files changed, 13 insertions(+), 6 deletions(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 529fd6eb..eeab72de 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -70,7 +70,6 @@
define('ALLOW_ZIP', false, true);
define('ZIP_IMAGE', 'src/zip.png', true);
-
/**
Redraw the image using GD functions to strip any excess data (commonly ZIP archives)
WARNING: Very beta. Currently strips animated GIFs too :(
@@ -88,7 +87,7 @@
define('DIR_RES', 'res/', true);
// The root directory, including the trailing slash, for Tinyboard.
- // examples: '/', '/board/', '/chan/'
+ // examples: '/', 'http://boards.chan.org/', '/chan/'
define('ROOT', '/', true);
// If for some reason the folders and static HTML index files aren't in the current working direcotry,
@@ -101,6 +100,9 @@
// Multi-board (%s is board abbreviation)
define('BOARD_PATH', '%s', true);
+
+ // Name of the boards. Typically '/%s/' (/b/, /mu/, etc)
+ define('BOARD_ABBREVIATION', '/%s/', true);
// Automatically convert things like "..." to Unicode characters ("…")
define('AUTO_UNICODE', true, true);
diff --git a/inc/functions.php b/inc/functions.php
index 4e03a531..ff568e30 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -25,10 +25,11 @@
}
function post($post, $OP) {
- global $sql;
+ global $sql, $board;
if($OP) {
mysql_query(
- sprintf("INSERT INTO `posts` VALUES ( NULL, NULL, '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%s', '%d', '%d', '%s', '%d', '%d', '%d', '%s', '%s', '%s', '%s' )",
+ sprintf("INSERT INTO `posts` VALUES ( NULL, '%d', NULL, '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%s', '%d', '%d', '%s', '%d', '%d', '%d', '%s', '%s', '%s', '%s' )",
+ $board['id'],
$post['subject'],
$post['email'],
$post['name'],
@@ -51,7 +52,8 @@
return mysql_insert_id($sql);
} else {
mysql_query(
- sprintf("INSERT INTO `posts` VALUES ( NULL, '%d', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%s', '%d', '%d', '%s', '%d', '%d', '%d', '%s', '%s', '%s', '%s' )",
+ sprintf("INSERT INTO `posts` VALUES ( NULL, '%d', '%d', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%s', '%d', '%d', '%s', '%d', '%d', '%d', '%s', '%s', '%s', '%s' )",
+ $board['id'],
$post['thread'],
$post['subject'],
$post['email'],
diff --git a/post.php b/post.php
index cbd6da59..3e4e6934 100644
--- a/post.php
+++ b/post.php
@@ -8,10 +8,13 @@
require 'inc/config.php';
require 'inc/user.php';
+ // For example, we're on /b/
$board = Array(
- 'url' => '/b/',
+ 'id' => 1,
+ 'uri' => 'b',
'name' => 'Beta',
'title' => 'In development.');
+ $board['url'] = sprintf(BOARD_ABBREVIATION, $board['uri']);
$body = '';
--
cgit v1.3
From 6f5966e38031557ca8b37905b594ed6541cb8a65 Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Tue, 30 Nov 2010 19:14:00 +1100
Subject: config comments
---
inc/config.php | 1 +
1 file changed, 1 insertion(+)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index eeab72de..83af50f8 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -102,6 +102,7 @@
define('BOARD_PATH', '%s', true);
// 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 ("…")
--
cgit v1.3
From 4dc13a3a92f711900a61335256f97f465a5067dd Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Tue, 30 Nov 2010 19:21:06 +1100
Subject: Fixed bug causing templates to fail after a chdir()
---
inc/config.php | 4 +++-
inc/template.php | 2 +-
post.php | 6 +++++-
test.php | 2 +-
4 files changed, 10 insertions(+), 4 deletions(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 83af50f8..dbb9bbd6 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -85,7 +85,9 @@
define('DIR_IMG', 'src/', true);
define('DIR_THUMB', 'thumb/', true);
define('DIR_RES', 'res/', true);
-
+
+ define('DIR_TEMPLATE', getcwd() . '/templates', true);
+
// The root directory, including the trailing slash, for Tinyboard.
// examples: '/', 'http://boards.chan.org/', '/chan/'
define('ROOT', '/', true);
diff --git a/inc/template.php b/inc/template.php
index 95fa2ff7..ff65c0c3 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -8,7 +8,7 @@
// Standard configuration
//
// Folder where the template files are kept
- $templateDir = './templates';
+ $templateDir = DIR_TEMPLATE;
//
// Enable global things like %gentime, etc.
$templateGlobals = true;
diff --git a/post.php b/post.php
index 3e4e6934..4458164c 100644
--- a/post.php
+++ b/post.php
@@ -1,11 +1,11 @@
'b',
'name' => 'Beta',
'title' => 'In development.');
+ $board['dir'] = sprintf(BOARD_PATH, $board['uri']);
$board['url'] = sprintf(BOARD_ABBREVIATION, $board['uri']);
+ if(!file_exists($board['dir'])) mkdir($board['dir'], 0777);
+ chdir($board['dir']);
+
$body = '';
// Fix for magic quotes
diff --git a/test.php b/test.php
index 06249c38..3e50443a 100644
--- a/test.php
+++ b/test.php
@@ -3,10 +3,10 @@
require 'inc/functions.php';
require 'inc/display.php';
- require 'inc/template.php';
if (file_exists('inc/instance-config.php')) {
require 'inc/instance-config.php';
}
+ require 'inc/template.php';
require 'inc/config.php';
require 'inc/user.php';
--
cgit v1.3
From c3178f7ab468afbe478ad0415b75ed3914f2742c Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Tue, 30 Nov 2010 19:22:23 +1100
Subject: comment
---
inc/config.php | 1 +
1 file changed, 1 insertion(+)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index dbb9bbd6..ca687da6 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -86,6 +86,7 @@
define('DIR_THUMB', 'thumb/', true);
define('DIR_RES', 'res/', true);
+ // Where to store the .html templates. This folder and templates must exist or fatal errors will be thrown.
define('DIR_TEMPLATE', getcwd() . '/templates', true);
// The root directory, including the trailing slash, for Tinyboard.
--
cgit v1.3
From 5719bcc2f05cc6ea12ab69d464d55de00121a395 Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Tue, 30 Nov 2010 19:31:52 +1100
Subject: chmod directories to 777 by default
---
inc/config.php | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index ca687da6..4f9617d5 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -131,8 +131,8 @@
chdir(ROOT_FILE);
}
if(!defined('IS_INSTALLATION')) {
- if(!file_exists(DIR_IMG)) @mkdir(DIR_IMG) or error("Couldn't create " . DIR_IMG . ". Install manually.", true);
- if(!file_exists(DIR_THUMB)) @mkdir(DIR_THUMB) or error("Couldn't create " . DIR_IMG . ". Install manually.", true);
- if(!file_exists(DIR_RES)) @mkdir(DIR_RES) or error("Couldn't create " . DIR_IMG . ". Install manually.", true);
+ if(!file_exists(DIR_IMG)) @mkdir(DIR_IMG, 0777) or error("Couldn't create " . DIR_IMG . ". Install manually.", true);
+ if(!file_exists(DIR_THUMB)) @mkdir(DIR_THUMB, 0777) or error("Couldn't create " . DIR_IMG . ". Install manually.", true);
+ if(!file_exists(DIR_RES)) @mkdir(DIR_RES, 0777) or error("Couldn't create " . DIR_IMG . ". Install manually.", true);
}
?>
\ No newline at end of file
--
cgit v1.3
From a1039adb5024138c19aad411068c309d1b4a25d9 Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Tue, 30 Nov 2010 19:36:36 +1100
Subject: INDEX_FILE in config.php
---
inc/config.php | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 4f9617d5..e6fd6d21 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -101,8 +101,10 @@
define('FILE_INDEX', 'index.html', true);
define('FILE_PAGE', '%d.html', true);
+ define('INDEX_FILE', 'index.html', true);
+
// Multi-board (%s is board abbreviation)
- define('BOARD_PATH', '%s', true);
+ define('BOARD_PATH', '%s/', true);
// Name of the boards. Typically '/%s/' (/b/, /mu/, etc)
// BOARD_ABBREVIATION - BOARD_TITLE
--
cgit v1.3
From 25bc80d9abeb0c7b67ed5856eee7fd532d3310e5 Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Tue, 30 Nov 2010 19:37:06 +1100
Subject: Disregard.
---
inc/config.php | 2 --
1 file changed, 2 deletions(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index e6fd6d21..109e99e9 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -101,8 +101,6 @@
define('FILE_INDEX', 'index.html', true);
define('FILE_PAGE', '%d.html', true);
- define('INDEX_FILE', 'index.html', true);
-
// Multi-board (%s is board abbreviation)
define('BOARD_PATH', '%s/', true);
--
cgit v1.3
From ec5b31455767f33b2b89604f21978ddb04d0c558 Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Tue, 30 Nov 2010 19:57:16 +1100
Subject: Commented out no-longer-needed code
---
inc/config.php | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 109e99e9..bb130bc4 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -125,14 +125,33 @@
define('ALWAYS_NOKO', false, true);
- define('URL_MATCH', '/^' . (@$_SERVER['HTTPS']?'https':'http').':\/\/'.$_SERVER['HTTP_HOST'] . '(' . preg_quote(ROOT, '/') . '|' . preg_quote(ROOT, '/') . '' . preg_quote(FILE_INDEX, '/') . '|' . preg_quote(ROOT, '/') . '' . str_replace('%d', '\d+', preg_quote(FILE_PAGE, '/')) . ')$/', true);
+ define('URL_MATCH', '/^' .
+ (@$_SERVER['HTTPS']?'https':'http').':\/\/'.$_SERVER['HTTP_HOST'] .
+ '(' .
+ preg_quote(ROOT, '/') .
+ str_replace('%s', '\w{1,8}', preg_quote(BOARD_PATH, '/')) .
+ '|' .
+ preg_quote(ROOT, '/') .
+ str_replace('%s', '\w{1,8}', preg_quote(BOARD_PATH, '/')) .
+ preg_quote(FILE_INDEX, '/') .
+ '|' .
+ preg_quote(ROOT, '/') .
+ str_replace('%s', '\w{1,8}', preg_quote(BOARD_PATH, '/')) .
+ str_replace('%d', '\d+', preg_quote(FILE_PAGE, '/')) .
+ ')$/', true);
+ var_dump(URL_MATCH);
if(ROOT_FILE) {
chdir(ROOT_FILE);
}
+
+ /*
+ Multi-board support removes any use for this.
+
if(!defined('IS_INSTALLATION')) {
if(!file_exists(DIR_IMG)) @mkdir(DIR_IMG, 0777) or error("Couldn't create " . DIR_IMG . ". Install manually.", true);
if(!file_exists(DIR_THUMB)) @mkdir(DIR_THUMB, 0777) or error("Couldn't create " . DIR_IMG . ". Install manually.", true);
if(!file_exists(DIR_RES)) @mkdir(DIR_RES, 0777) or error("Couldn't create " . DIR_IMG . ". Install manually.", true);
}
+ */
?>
\ No newline at end of file
--
cgit v1.3
From 342d1d2f6ba6ca85e78f4bef006a3aeea3ddf4aa Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Tue, 30 Nov 2010 20:05:20 +1100
Subject: Removed debug code I accidentally commited.
---
inc/config.php | 1 -
1 file changed, 1 deletion(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index bb130bc4..bc0f726a 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -139,7 +139,6 @@
str_replace('%s', '\w{1,8}', preg_quote(BOARD_PATH, '/')) .
str_replace('%d', '\d+', preg_quote(FILE_PAGE, '/')) .
')$/', true);
- var_dump(URL_MATCH);
if(ROOT_FILE) {
chdir(ROOT_FILE);
--
cgit v1.3
From 6f4c28f699369b87ed88f5676a08b69c8efb1cf2 Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Tue, 30 Nov 2010 20:40:54 +1100
Subject: A bunch of new variables
---
inc/config.php | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index bc0f726a..107f1cbc 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -48,10 +48,12 @@
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_NOPOST', 'You didn\'t make a post.', 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);
+ 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);
// For resizing, max values
define('THUMB_WIDTH', 200, true);
@@ -104,6 +106,10 @@
// Multi-board (%s is board abbreviation)
define('BOARD_PATH', '%s/', 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);
+
// Name of the boards. Typically '/%s/' (/b/, /mu/, etc)
// BOARD_ABBREVIATION - BOARD_TITLE
define('BOARD_ABBREVIATION', '/%s/', true);
@@ -116,7 +122,7 @@
define('MARKUP_URLS', true, true);
// Complex regular expression to catch URLs
define('URL_REGEX', '/' . '(https?|ftp):\/\/' . '([\w\-]+\.)+[a-zA-Z]{2,6}' . '(\/([\w\-~\.#\/?=&;:+%]+))?' . '/', true);
-
+
// Allowed file extensions
$allowed_ext = Array('jpg', 'jpeg', 'bmp', 'gif', 'png', true);
--
cgit v1.3
From b41a4a6ac7392175064c56dcc4d16cab66f541ab Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Tue, 30 Nov 2010 23:12:54 +1100
Subject: Check if thread exists before posting.
---
inc/config.php | 1 +
inc/functions.php | 18 +++++++++++++++++-
post.php | 2 ++
3 files changed, 20 insertions(+), 1 deletion(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 107f1cbc..f7ab10d6 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -49,6 +49,7 @@
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_NOPOST', 'You didn\'t make a post.', true);
define('ERR_INVALIDIMG','Invalid image.', true);
define('ERR_FILESIZE', 'Maximum file size: %maxsz% bytes
Your file\'s size: %filesz% bytes', true);
diff --git a/inc/functions.php b/inc/functions.php
index c4fd77dd..453f5146 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -44,13 +44,29 @@
function openBoard($uri) {
global $sql;
- $boards_res = mysql_query(sprintf("SELECT * FROM `boards` WHERE `uri` = '%s' LIMIT 1", mysql_real_escape_string($uri)), $sql) or error(mysql_error($sql));
+ $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);
return true;
} else return false;
}
+ function threadExists($id) {
+ global $sql;
+ $thread_res = mysql_query(sprintf(
+ "SELECT 1 FROM `posts` WHERE `id` = '%d' AND `thread` IS NULL LIMIT 1",
+ $id
+ ), $sql) or error(mysql_error($sql));
+
+ if(mysql_num_rows($thread_res) > 0) {
+ return true;
+ } else return false;
+ }
+
function post($post, $OP) {
global $sql, $board;
if($OP) {
diff --git a/post.php b/post.php
index d5cb9d13..bdc4819f 100644
--- a/post.php
+++ b/post.php
@@ -83,6 +83,8 @@
sql_open();
if(!openBoard($post['board'])) error(ERROR_NOBOARD);
+ if(!$OP && !threadExists($post['thread']))
+ error(ERROR_NONEXISTANT);
$trip = generate_tripcode($post['name']);
$post['name'] = $trip[0];
--
cgit v1.3
From 5e63b4b8a0c6e982bdb01299c1ce175d521b2d35 Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Wed, 1 Dec 2010 16:20:59 +1100
Subject: Optional force display of errors
---
inc/config.php | 8 ++++++++
1 file changed, 8 insertions(+)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index f7ab10d6..2cd3b71d 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -38,6 +38,9 @@
define('THREADS_PER_PAGE', 10, true);
define('MAX_PAGES', 5, true);
define('THREADS_PREVIEW', 5, true);
+
+ // For development purposes. Turns 'display_errors' on. Not recommended for production.
+ define('VERBOSE_ERRORS', true, true);
// Error messages
define('ERROR_LURK', 'Lurk some more before posting.', true);
@@ -151,6 +154,11 @@
chdir(ROOT_FILE);
}
+ if(VERBOSE_ERRORS) {
+ error_reporting(E_ALL);
+ ini_set('display_errors', 1);
+ }
+
/*
Multi-board support removes any use for this.
--
cgit v1.3
From 5c7de28ca61b00495fbf26c449bb5d5ed38d8669 Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Wed, 1 Dec 2010 16:42:48 +1100
Subject: JAIL_COOKIES config directive.
---
inc/config.php | 4 +++-
inc/user.php | 13 ++++++++++---
2 files changed, 13 insertions(+), 4 deletions(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 2cd3b71d..9dea8ad7 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -17,12 +17,14 @@
// The name of the session cookie (PHP's $_SESSION)
define('SESS_COOKIE', 'imgboard', true);
-
+
// 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);
+ // Where to set the 'path' parameter to ROOT when creating cookies. Recommended.
+ define('JAIL_COOKIES', true, true);
// How long should the cookies last (in seconds)
define('COOKIE_EXPIRE', 15778463, true); //6 months
diff --git a/inc/user.php b/inc/user.php
index 1dad35f9..0b9af643 100644
--- a/inc/user.php
+++ b/inc/user.php
@@ -1,14 +1,21 @@
false, 'appeared' => $time);
} else {
$user = Array('valid' => true, 'appeared' => $_COOKIE[TIME_COOKIE]);
--
cgit v1.3
From 84027c6d83d4a836ea362026df778b7507a9429e Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Wed, 1 Dec 2010 21:24:14 +1100
Subject: mod panel
---
inc/config.php | 12 ++++++-
inc/display.php | 14 ++++++++
inc/functions.php | 16 +++++++--
inc/instance-config.php | 14 ++++----
inc/user.php | 90 ++++++++++++++++++++++++++++++++++++++++++++++++-
5 files changed, 135 insertions(+), 11 deletions(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 9dea8ad7..2c1e9dc8 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -23,8 +23,13 @@
define('TIME_COOKIE', 'arrived', true);
// HASH_COOKIE contains an MD5 hash of TIME_COOKIE+SALT for verification.
define('HASH_COOKIE', 'hash', true);
+ // 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);
+
+ // Whether or not to lock moderator sessions to the IP address that was logged in with.
+ define('MOD_LOCK_IP', true, true);
// How long should the cookies last (in seconds)
define('COOKIE_EXPIRE', 15778463, true); //6 months
@@ -60,7 +65,12 @@
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);
-
+
+ // Moderator errors
+ 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);
+
// For resizing, max values
define('THUMB_WIDTH', 200, true);
define('THUMB_HEIGHT', 200, true);
diff --git a/inc/display.php b/inc/display.php
index c910e26c..29012046 100644
--- a/inc/display.php
+++ b/inc/display.php
@@ -34,6 +34,20 @@
)));
}
+ function loginForm($error=false, $username=false) {
+ if(function_exists('sql_close')) sql_close();
+ die(Element('page.html', Array(
+ 'index'=>ROOT,
+ 'title'=>'Login',
+ 'body'=>Element('login.html', Array(
+ 'index'=>ROOT,
+ 'error'=>$error,
+ 'username'=>$username
+ )
+ )
+ )));
+ }
+
class Post {
public function __construct($id, $thread, $subject, $email, $name, $trip, $body, $time, $thumb, $thumbx, $thumby, $file, $filex, $filey, $filesize, $filename) {
$this->id = $id;
diff --git a/inc/functions.php b/inc/functions.php
index 4a70da32..b20ed091 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -318,7 +318,7 @@
return $result;
}
- function buildThread($id) {
+ function buildThread($id, $return=false) {
global $sql, $board;
$id = round($id);
@@ -335,7 +335,19 @@
} 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']));
}
- @file_put_contents($board['dir'] . DIR_RES . $id . '.html', Element('thread.html', Array('button'=>BUTTON_REPLY, 'board'=>$board, 'body'=>$thread->build(), 'post_url' => POST_URL, 'index' => ROOT, 'id' => $id))) or error("Couldn't write to file.");
+ $body = Element('thread.html', Array(
+ 'button'=>BUTTON_REPLY,
+ 'board'=>$board,
+ 'body'=>$thread->build(),
+ 'post_url' => POST_URL,
+ 'index' => ROOT,
+ 'id' => $id
+ ));
+
+ if($return)
+ return $body;
+ else
+ @file_put_contents($board['dir'] . DIR_RES . $id . '.html', $body) or error("Couldn't write to file.");
}
mysql_free_result($query);
}
diff --git a/inc/instance-config.php b/inc/instance-config.php
index 1ae82a3f..1c433a9c 100644
--- a/inc/instance-config.php
+++ b/inc/instance-config.php
@@ -8,16 +8,16 @@
* You can copy values from config.php (defaults) and paste them here.
*/
- /*
+
// Database stuff
- define('MY_SERVER', 'localhost');
- define('MY_USER', '');
- define('MY_PASSWORD', '');
- define('MY_DATABASE', '');
+ define('MY_SERVER', '127.0.0.1');
+ define('MY_USER', 'imgboard');
+ define('MY_PASSWORD', 'DF3uHz4vvhUM6rCq');
+ define('MY_DATABASE', 'imgboard');
- define('ROOT', '/');
+ define('ROOT', '/board/');
// define('FOO', 'bar');
- */
+
?>
\ No newline at end of file
diff --git a/inc/user.php b/inc/user.php
index 2bdf5c05..05deb0e3 100644
--- a/inc/user.php
+++ b/inc/user.php
@@ -15,9 +15,97 @@
if(!isset($_COOKIE[HASH_COOKIE]) || !isset($_COOKIE[TIME_COOKIE]) || $_COOKIE[HASH_COOKIE] != md5($_COOKIE[TIME_COOKIE].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(HASH_COOKIE, md5($time.SALT), $time+COOKIE_EXPIRE, JAIL_COOKIES?ROOT:'/', null, false, true);
$user = Array('valid' => false, 'appeared' => $time);
} else {
$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
--
cgit v1.3
From 20fd2fc23224cf300086cba0f53e32e23a2e8421 Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Thu, 2 Dec 2010 18:02:04 +1100
Subject: Basic login and page handling.
---
inc/config.php | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 2c1e9dc8..0ca457c4 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -28,9 +28,6 @@
// Where to set the 'path' parameter to ROOT when creating cookies. Recommended.
define('JAIL_COOKIES', true, true);
- // Whether or not to lock moderator sessions to the IP address that was logged in with.
- define('MOD_LOCK_IP', true, true);
-
// How long should the cookies last (in seconds)
define('COOKIE_EXPIRE', 15778463, true); //6 months
@@ -122,6 +119,14 @@
// Multi-board (%s is board abbreviation)
define('BOARD_PATH', '%s/', true);
+ /*
+ Mod stuff
+ */
+ // Whether or not to lock moderator sessions to the IP address that was logged in with.
+ define('MOD_LOCK_IP', true, true);
+ // The page that is first shown when a moderator logs in. Defaults to the dashboard.
+ define('MOD_DEFAULT', '/', 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);
--
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 'inc/config.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 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 'inc/config.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 '';
+ }
+
?>
\ 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 .= '';
- 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 6d2813857efa308ed295048f047ea45b698ac093 Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Wed, 8 Dec 2010 04:32:07 +1100
Subject: Fix for IP address links
---
inc/config.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 3bb24b85..284692ce 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -154,7 +154,7 @@
// Whether to turn URLs into functional links
define('MARKUP_URLS', true, true);
// Complex regular expression to catch URLs
- define('URL_REGEX', '/' . '(https?|ftp):\/\/' . '([\w\-]+\.)+[a-zA-Z]{2,6}' . '(\/([\w\-~\.#\/?=&;:+%]+))?' . '/', true);
+ 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);
// Allowed file extensions
$allowed_ext = Array('jpg', 'jpeg', 'bmp', 'gif', 'png', true);
--
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 'inc/config.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 46ad66514a4baa4f83f67f457ed9e894e1804d4b Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Fri, 10 Dec 2010 20:39:56 +1100
Subject: A comment.
---
inc/config.php | 1 +
1 file changed, 1 insertion(+)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 832afffb..8411dd31 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -136,6 +136,7 @@
// The page that is first shown when a moderator logs in. Defaults to the dashboard.
define('MOD_DEFAULT', '/', true);
+ // Probably best not to change these:
define('MOD_JANITOR', 0, true);
define('MOD_MOD', 1, true);
define('MOD_ADMIN', 2, true);
--
cgit v1.3
From 0df2dfd6d5ba6b298b12568d5d4daf4ebfeb89fb Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Fri, 10 Dec 2010 20:53:30 +1100
Subject: MOD_NEVER_REAL_PASSWORD in config.php
---
inc/config.php | 2 ++
1 file changed, 2 insertions(+)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 8411dd31..5c1e5a0d 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -135,6 +135,8 @@
define('MOD_LOCK_IP', true, 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);
// Probably best not to change these:
define('MOD_JANITOR', 0, true);
--
cgit v1.3
From 5c557d44e8595f1381f3df1fe3ee5c7159837ac3 Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Fri, 10 Dec 2010 21:15:02 +1100
Subject: MOD_SHOW_IP in config.php
---
inc/config.php | 3 +++
1 file changed, 3 insertions(+)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 5c1e5a0d..2d2dddf6 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -143,6 +143,9 @@
define('MOD_MOD', 1, true);
define('MOD_ADMIN', 2, true);
+ // What level of administration you need to view IP addresses
+ define('MOD_SHOW_IP', MOD_MOD, 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);
--
cgit v1.3
From 5adfff925b144161c840f63ebb271c11c3c0c883 Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Mon, 13 Dec 2010 02:44:43 +1100
Subject: Post moderation controls
---
inc/config.php | 23 ++++++++++++++++++++++-
inc/display.php | 33 +++++++++++++++++++++++++++++++--
2 files changed, 53 insertions(+), 3 deletions(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 2d2dddf6..e3080316 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -143,8 +143,29 @@
define('MOD_MOD', 1, true);
define('MOD_ADMIN', 2, true);
- // What level of administration you need to view IP addresses
+ // Permissions
+ // What level of administration you need to:
+
+ // View IP addresses
define('MOD_SHOW_IP', MOD_MOD, true);
+ // Delete a post
+ define('MOD_DELETE', MOD_JANITOR, true);
+ // Ban a user for a post
+ define('MOD_BAN', MOD_MOD, true);
+ // Ban and delete (one click; instant)
+ define('MOD_BANDELETE', MOD_BAN, true);
+ // Delete file (and keep post)
+ define('MOD_DELETEFILE', MOD_JANITOR, true);
+ // Delete all posts by IP
+ define('MOD_DELETEBYIP', MOD_BAN, true);
+
+ // 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);
// 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 a5bb1c70..b8a58e2b 100644
--- a/inc/display.php
+++ b/inc/display.php
@@ -119,9 +119,38 @@
$built .= ', ' . $fraction;
}
// Filename
- $built .= ', ' . $this->filename . ')
' .
+ $built .= ', ' . $this->filename . ')' .
+
// Thumbnail
- '
';
+ '
';
+ }
+
+ 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 .= '
';
}
// Body
--
cgit v1.3
From f49bfa17c0d68c05b6c870b54dd451e2312516ab Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Thu, 16 Dec 2010 17:04:33 +1100
Subject: MOD_STICKY
---
inc/config.php | 4 ++++
1 file changed, 4 insertions(+)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index e3080316..78b78403 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -71,6 +71,7 @@
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);
+ define('ERROR_INVALIDPOST', 'That post doesn\'t exist…', true);
// For resizing, max values
define('THUMB_WIDTH', 200, true);
@@ -158,6 +159,8 @@
define('MOD_DELETEFILE', MOD_JANITOR, true);
// Delete all posts by IP
define('MOD_DELETEBYIP', MOD_BAN, true);
+ // Sticky a thread
+ define('MOD_STICKY', MOD_MOD, true);
// Mod links (full HTML)
// Correspond to above permission directives
@@ -166,6 +169,7 @@
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);
// 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.
--
cgit v1.3
From 627c6ac91a338cfbd9fcc618b28dd678902da8f7 Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Thu, 16 Dec 2010 23:08:52 +1100
Subject: Stickies
---
inc/config.php | 5 +++++
inc/display.php | 7 +++++--
inc/functions.php | 6 +++---
style.css | 6 ++++++
4 files changed, 19 insertions(+), 5 deletions(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 78b78403..4e48b6d5 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -72,6 +72,7 @@
define('ERROR_INVALIDFIELD', 'The %s field was invalid.', 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);
// For resizing, max values
define('THUMB_WIDTH', 200, true);
@@ -129,6 +130,10 @@
// "302" is recommended.
define('REDIRECT_HTTP', 302, true);
+ // Static images
+ // These can be URLs OR base64 (data URI scheme)
+ define('IMAGE_STICKY', 'data:image/gif;base64,R0lGODlhEgASAIcAACM8mR5BnAFPowNVpwBZqQBerhNPpRpLoxhSqABgrwBksgFvughltA5ttwBwuwR0vyN2vDdosDJ9tQB6wkJqtGN2tgODyweR1QCZ3gGc3wiR1ROr6SGGyCqJyDqEwjaX0Das4j256GaFu22Fs0qFwkyNx1mLxEun2k264lO76V+45WSezW2Vx2+fzGCrxWW30X6/5oaIvo+rvqidtr29vo+RwIWj0ISp1KSn0aG337euxbGwxry71KW84LbMvJLLzZDK1ZDI2Y3S76fJ5qbK6KrP6K3U7aDd8bzI6Mu6vMC/z83NwtDO39PW2drd0cPO7tXW5tje7MXk9t7u4+LJw+bX1ezhz+Hg8uDr9Obw+PHo6v//7gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAMAAFsALAAAAAASABIAAAieALcIHEiwoMGDRT6ckHLQYJYhRixcENKQIBYiUmBowHCkYRQWLVZ0AJFCBYYNB6FUiGCixAILFjRkCHEwxhUbAxI4mHCAA4opB2vk6EGigIMHB4JUVEIBwg0PCxYYAFJxywgBBBo4YBDgRVUtIgYoWAAAwY+qSHDIkHAAgIuqT3ZYEejDR1UmM5xUJZhEx5K9A6nwoAF4YJUmhRMXDAgAOw==', true);
+
/*
Mod stuff
*/
diff --git a/inc/display.php b/inc/display.php
index a485f906..8cf4a18e 100644
--- a/inc/display.php
+++ b/inc/display.php
@@ -180,7 +180,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, $root=ROOT) {
+ public function __construct($id, $subject, $email, $name, $trip, $body, $time, $thumb, $thumbx, $thumby, $file, $filex, $filey, $filesize, $filename, $ip, $sticky, $root=ROOT) {
$this->id = $id;
$this->subject = utf8tohtml($subject);
$this->email = $email;
@@ -199,13 +199,13 @@
$this->omitted = 0;
$this->posts = Array();
$this->ip = $ip;
+ $this->sticky = $sticky;
$this->root = $root;
}
public function add(Post $post) {
$this->posts[] = $post;
}
-
public function build($index=false) {
global $board, $mod;
@@ -255,8 +255,11 @@
' href="' . $this->root . $board['dir'] . DIR_RES . $this->id . '.html' . '#' . $this->id . '">No.' .
// JavaScript cite
'id . ');"') . 'href="' . ($index?$this->root . $board['dir'] . DIR_RES . $this->id . '.html' . '#q' . $this->id:'javascript:void(0);') . '">'.$this->id.'' .
+ // Sticky
+ ($this->sticky ? '
' : '') .
// [Reply]
($index ? '[Reply]' : '') .
+
// Mod controls
postControls($this->id, true) .
'';
diff --git a/inc/functions.php b/inc/functions.php
index 04340be1..fd87de43 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -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'], $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);
$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",
@@ -341,7 +341,7 @@
$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` FROM `posts_%s` WHERE (`thread` IS NULL AND `id` = '%d') OR `thread` = '%d' ORDER BY `thread`,`time`",
+ "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
@@ -349,7 +349,7 @@
while($post = mysql_fetch_array($query)) {
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'], $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);
} 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));
}
diff --git a/style.css b/style.css
index bc6314c0..d7646c5d 100644
--- a/style.css
+++ b/style.css
@@ -111,6 +111,12 @@ div.post img {
padding: 5px;
margin: 5px 20px 0 0;
}
+div.post img.icon {
+ display: inline;
+ float: none;
+ margin: 0 5px;
+ padding: 0;
+}
div.post.op {
margin-right: 20px;
margin-bottom: 5px;
--
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 'inc/config.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
+ $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 .= "";
+ }
+
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 fb576d7966cd72226e0b64f3bd70987cfa68d259 Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Fri, 17 Dec 2010 02:26:59 +1100
Subject: Moved "zip.png" file in code to new "static" directory
---
inc/config.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 8f265a78..116ad334 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -89,7 +89,7 @@
* Extremely beta and not recommended yet.
*/
define('ALLOW_ZIP', false, true);
- define('ZIP_IMAGE', 'src/zip.png', true);
+ define('ZIP_IMAGE', 'static/zip.png', true);
/**
Redraw the image using GD functions to strip any excess data (commonly ZIP archives)
--
cgit v1.3
From 46166888e9b6fc883c77eaece80fa2172c981bf3 Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Fri, 17 Dec 2010 02:31:10 +1100
Subject: ERROR_INVALIDAFTER was not configurable
---
inc/config.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 116ad334..d8831302 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -65,7 +65,7 @@
// Moderator errors
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_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);
--
cgit v1.3
From 68b98df6cd353f963170bb8fbbe649dbf3277f8f Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Fri, 17 Dec 2010 17:11:41 +1100
Subject: Changed sticky from base64 to an image
---
inc/config.php | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index d8831302..b936da29 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -106,6 +106,7 @@
define('DIR_IMG', 'src/', true);
define('DIR_THUMB', 'thumb/', true);
define('DIR_RES', 'res/', true);
+ define('DIR_STATIC', 'static/', true);
// Where to store the .html templates. This folder and templates must exist or fatal errors will be thrown.
define('DIR_TEMPLATE', getcwd() . '/templates', true);
@@ -132,7 +133,7 @@
// Static images
// These can be URLs OR base64 (data URI scheme)
- define('IMAGE_STICKY', 'data:image/gif;base64,R0lGODlhEgASAIcAACM8mR5BnAFPowNVpwBZqQBerhNPpRpLoxhSqABgrwBksgFvughltA5ttwBwuwR0vyN2vDdosDJ9tQB6wkJqtGN2tgODyweR1QCZ3gGc3wiR1ROr6SGGyCqJyDqEwjaX0Das4j256GaFu22Fs0qFwkyNx1mLxEun2k264lO76V+45WSezW2Vx2+fzGCrxWW30X6/5oaIvo+rvqidtr29vo+RwIWj0ISp1KSn0aG337euxbGwxry71KW84LbMvJLLzZDK1ZDI2Y3S76fJ5qbK6KrP6K3U7aDd8bzI6Mu6vMC/z83NwtDO39PW2drd0cPO7tXW5tje7MXk9t7u4+LJw+bX1ezhz+Hg8uDr9Obw+PHo6v//7gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAMAAFsALAAAAAASABIAAAieALcIHEiwoMGDRT6ckHLQYJYhRixcENKQIBYiUmBowHCkYRQWLVZ0AJFCBYYNB6FUiGCixAILFjRkCHEwxhUbAxI4mHCAA4opB2vk6EGigIMHB4JUVEIBwg0PCxYYAFJxywgBBBo4YBDgRVUtIgYoWAAAwY+qSHDIkHAAgIuqT3ZYEejDR1UmM5xUJZhEx5K9A6nwoAF4YJUmhRMXDAgAOw==', true);
+ define('IMAGE_STICKY', ROOT . DIR_STATIC . 'sticky.gif', true);
/*
Mod stuff
--
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 'inc/config.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 0b76cd535f21ea8746bbb41ef4103c14c85726fe Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Sat, 18 Dec 2010 01:43:56 +1100
Subject: Fixed config
---
inc/config.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 4d1b6d78..2e605b0b 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -11,7 +11,7 @@
// Database stuff
- // "mysql", "mysqli", "pgsql", "mssql"
+ // "mysql", "pgsql", etc
define('DB_TYPE', 'mysql', true);
// Hostname or IP address
define('DB_SERVER', 'localhost', true);
--
cgit v1.3
From 796a5445601c187bb7fa867d9c5b152ac8fd9797 Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Sat, 18 Dec 2010 02:24:27 +1100
Subject: Added DB_DSN
---
inc/config.php | 5 ++++-
inc/database.php | 5 ++++-
2 files changed, 8 insertions(+), 2 deletions(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 2e605b0b..60c8d5c2 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -11,7 +11,8 @@
// Database stuff
- // "mysql", "pgsql", etc
+ // SQL driver ("mysql", "pgsql", "sqlite", "dblib", etc)
+ // http://www.php.net/manual/en/pdo.drivers.php
define('DB_TYPE', 'mysql', true);
// Hostname or IP address
define('DB_SERVER', 'localhost', true);
@@ -20,6 +21,8 @@
define('DB_PASSWORD', '', true);
// TinyBoard database
define('DB_DATABASE', '', true);
+ // Anything more to add to the DSN string (eg. port=xxx;foo=bar)
+ define('DB_DSN', '', 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
index 8ffc9f84..e9780640 100644
--- a/inc/database.php
+++ b/inc/database.php
@@ -4,8 +4,11 @@
global $pdo;
if($pdo) return true;
+ $dsn = DB_TYPE . ':host=' . DB_SERVER . ';dbname=' . DB_DATABASE;
+ if(!empty($dsn))
+ $dsn .= ';' . DB_DSN;
try {
- return $pdo = new PDO(DB_TYPE . ':host=' . DB_SERVER . ';dbname=' . DB_DATABASE, DB_USER, DB_PASSWORD);
+ return $pdo = new PDO($dsn, DB_USER, DB_PASSWORD);
} catch(PDOException $e) {
$message = $e->getMessage();
--
cgit v1.3
From 9d5482874a6d3520486d8c12534bf8b71c8a243e Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Sat, 18 Dec 2010 02:52:06 +1100
Subject: Compressed URL_MATCH
---
inc/config.php | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 60c8d5c2..b83ce5e0 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -220,16 +220,13 @@
define('ALWAYS_NOKO', false, true);
define('URL_MATCH', '/^' .
- (@$_SERVER['HTTPS']?'https':'http').':\/\/'.$_SERVER['HTTP_HOST'] .
+ (@$_SERVER['HTTPS']?'https':'http').':\/\/'.$_SERVER['HTTP_HOST'] . preg_quote(ROOT, '/') .
'(' .
- preg_quote(ROOT, '/') .
str_replace('%s', '\w{1,8}', preg_quote(BOARD_PATH, '/')) .
'|' .
- preg_quote(ROOT, '/') .
str_replace('%s', '\w{1,8}', preg_quote(BOARD_PATH, '/')) .
preg_quote(FILE_INDEX, '/') .
'|' .
- preg_quote(ROOT, '/') .
str_replace('%s', '\w{1,8}', preg_quote(BOARD_PATH, '/')) .
str_replace('%d', '\d+', preg_quote(FILE_PAGE, '/')) .
')$/', true);
--
cgit v1.3
From 7e978cebd95261c1c5d8f76fe0e3228486eef215 Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Sat, 18 Dec 2010 03:01:46 +1100
Subject: Added a comment
---
inc/config.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index b83ce5e0..4f5bc92b 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -39,7 +39,7 @@
// How long should the cookies last (in seconds)
define('COOKIE_EXPIRE', 15778463, true); //6 months
-
+ // Make this something long and random for security
define('SALT', 'wefaw98YHEWUFuo', true);
// How many seconds before you can post, after the first visit
--
cgit v1.3
From 323fe4e61c722d2c6954f3b21ecd83ba8a22bda9 Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Sat, 18 Dec 2010 04:12:37 +1100
Subject: URL_MATCH when ROOT is a full URL
---
inc/config.php | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 4f5bc92b..24d522c7 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -220,16 +220,19 @@
define('ALWAYS_NOKO', false, true);
define('URL_MATCH', '/^' .
- (@$_SERVER['HTTPS']?'https':'http').':\/\/'.$_SERVER['HTTP_HOST'] . preg_quote(ROOT, '/') .
- '(' .
- str_replace('%s', '\w{1,8}', preg_quote(BOARD_PATH, '/')) .
- '|' .
- str_replace('%s', '\w{1,8}', preg_quote(BOARD_PATH, '/')) .
- preg_quote(FILE_INDEX, '/') .
- '|' .
- str_replace('%s', '\w{1,8}', preg_quote(BOARD_PATH, '/')) .
- str_replace('%d', '\d+', preg_quote(FILE_PAGE, '/')) .
- ')$/', true);
+ (preg_match(URL_REGEX, ROOT) ? '' :
+ (@$_SERVER['HTTPS']?'https':'http') .
+ ':\/\/'.$_SERVER['HTTP_HOST']) .
+ preg_quote(ROOT, '/') .
+ '(' .
+ str_replace('%s', '\w{1,8}', preg_quote(BOARD_PATH, '/')) .
+ '|' .
+ str_replace('%s', '\w{1,8}', preg_quote(BOARD_PATH, '/')) .
+ preg_quote(FILE_INDEX, '/') .
+ '|' .
+ str_replace('%s', '\w{1,8}', preg_quote(BOARD_PATH, '/')) .
+ str_replace('%d', '\d+', preg_quote(FILE_PAGE, '/')) .
+ ')$/i', true);
if(ROOT_FILE) {
chdir(ROOT_FILE);
--
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 'inc/config.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 9ba2638ad73c891e9a19247f0932fed3eb45ccff Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Sun, 2 Jan 2011 01:45:14 +1100
Subject: Configurable post time format
---
inc/config.php | 4 ++++
inc/display.php | 4 ++--
2 files changed, 6 insertions(+), 2 deletions(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 79f4bf1e..5e9aa365 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -220,6 +220,10 @@
define('BUTTON_NEWTOPIC', 'New Topic', true);
define('BUTTON_REPLY', 'New Reply', true);
+ // 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);
+
define('ALWAYS_NOKO', false, true);
define('URL_MATCH', '/^' .
diff --git a/inc/display.php b/inc/display.php
index 32eb9cb2..0f1a6c07 100644
--- a/inc/display.php
+++ b/inc/display.php
@@ -128,7 +128,7 @@
$built .= '';
// Date/time
- $built .= ' ' . date('m/d/y (D) H:i:s', $this->time);
+ $built .= ' ' . date(POST_DATE, $this->time);
$built .= ' time);
+ $built .= ' ' . date(POST_DATE, $this->time);
$built .= '
Date: Sun, 2 Jan 2011 02:00:40 +1100
Subject: Removed old, un-used, commented-out code
---
inc/config.php | 10 ----------
1 file changed, 10 deletions(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 5e9aa365..65a35506 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -252,14 +252,4 @@
error_reporting(E_ALL);
ini_set('display_errors', 1);
}
-
- /*
- Multi-board support removes any use for this.
-
- if(!defined('IS_INSTALLATION')) {
- if(!file_exists(DIR_IMG)) @mkdir(DIR_IMG, 0777) or error("Couldn't create " . DIR_IMG . ". Install manually.", true);
- if(!file_exists(DIR_THUMB)) @mkdir(DIR_THUMB, 0777) or error("Couldn't create " . DIR_IMG . ". Install manually.", true);
- if(!file_exists(DIR_RES)) @mkdir(DIR_RES, 0777) or error("Couldn't create " . DIR_IMG . ". Install manually.", true);
- }
- */
?>
\ No newline at end of file
--
cgit v1.3
From 55595e8cfdf3f103f8f15e4f1c76a2699d63ce42 Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Sun, 2 Jan 2011 15:30:20 +1100
Subject: Rearranged some stuff in config.php
---
inc/config.php | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 65a35506..96a1892d 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -97,11 +97,8 @@
* get dumped into the thread as replies.
* Extremely beta and not recommended yet.
*/
- define('ALLOW_ZIP', false, true);
- define('ZIP_IMAGE', 'static/zip.png', true);
+ define('ALLOW_ZIP', false, true);
- define('DELETED_IMAGE', 'static/deleted.png', true);
-
/**
Redraw the image using GD functions to strip any excess data (commonly ZIP archives)
WARNING: Very beta. Currently strips animated GIFs too :(
@@ -126,6 +123,12 @@
// examples: '/', 'http://boards.chan.org/', '/chan/'
define('ROOT', '/', true);
+ // Static images
+ // These can be URLs OR base64 (data URI scheme)
+ define('IMAGE_STICKY', ROOT . DIR_STATIC . 'sticky.gif', true);
+ define('DELETED_IMAGE', ROOT . DIR_STATIC . 'deleted.png', true);
+ define('ZIP_IMAGE', ROOT . DIR_STATIC . 'zip.png', true);
+
// 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);
@@ -143,10 +146,6 @@
// "302" is recommended.
define('REDIRECT_HTTP', 302, true);
- // Static images
- // These can be URLs OR base64 (data URI scheme)
- define('IMAGE_STICKY', ROOT . DIR_STATIC . 'sticky.gif', true);
-
/*
Mod stuff
*/
--
cgit v1.3
From a3b438104eeb7407e41033b5d079c438035f89f6 Mon Sep 17 00:00:00 2001
From: Chris
Date: Sun, 2 Jan 2011 16:18:10 +0800
Subject: start work on a web based installer
---
inc/config.php | 2 +-
install.php | 347 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 348 insertions(+), 1 deletion(-)
create mode 100644 install.php
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 96a1892d..8cbc6ba2 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -251,4 +251,4 @@
error_reporting(E_ALL);
ini_set('display_errors', 1);
}
-?>
\ No newline at end of file
+?>
diff --git a/install.php b/install.php
new file mode 100644
index 00000000..6333c281
--- /dev/null
+++ b/install.php
@@ -0,0 +1,347 @@
+Error:";
+ echo "inc/instance-config.php already exists. Please delete it before trying to re-install.
";
+ die();
+}
+
+$default_values = array(
+ // Database stuff
+ array(
+ 'output' => "Database settings
\n".
+ "Please change the following to reflect the setup of your database.
"
+ ),
+ array(
+ 'name' => 'DB_TYPE',
+ 'html' => 'dropdown',
+ 'values' => array('mysql'=>'MySQL'),
+ 'comment' => 'Database engine:'
+ ),
+ array(
+ 'name' => 'DB_SERVER',
+ 'html' => 'text',
+ 'values' => 'localhost',
+ 'comment' => 'Database hostname:'
+ ),
+ array(
+ 'name' => 'DB_USER',
+ 'html' => 'text',
+ 'values' => 'root',
+ 'comment' => 'Database username:'
+ ),
+ array(
+ 'name' => 'DB_PASSWORD',
+ 'html' => 'password',
+ 'values' => '',
+ 'comment' => 'Database password:'
+ ),
+ array(
+ 'name' => 'DB_DATABASE',
+ 'html' => 'text',
+ 'values' => 'tinyboard',
+ 'comment' => 'Database name (please create this database beforehand):'
+ ),
+
+ // General Config
+ array(
+ 'output' => "General Config
\n".
+ "General board configuration.
"
+ ),
+ array(
+ 'name' => 'LURKTIME',
+ 'html' => 'text',
+ 'values' => '30',
+ 'comment' => 'How many seconds before you can post, after the first visit:'
+ ),
+ array(
+ 'name' => 'MAX_BODY',
+ 'html' => 'text',
+ 'values' => '1800',
+ 'comment' => 'Max body length:'
+ ),
+ array(
+ 'name' => 'THREADS_PER_PAGE',
+ 'html' => 'text',
+ 'values' => '10',
+ 'comment' => 'Threads per page:'
+ ),
+ array(
+ 'name' => 'MAX_PAGES',
+ 'html' => 'text',
+ 'values' => '5',
+ 'comment' => 'Max pages:'
+ ),
+ array(
+ 'name' => 'THREADS_PREVIEW',
+ 'html' => 'text',
+ 'values' => '5',
+ 'comment' => 'Threads Preview:'
+ ),
+ array(
+ 'name' => 'VERBOSE_ERRORS',
+ 'html' => 'bool',
+ 'values' => true,
+ 'comment' => 'Turns \'display_errors\' on. Not recommended for production.:'
+ ),
+
+ // Image Config
+ array(
+ 'output' => "Image Config
\n".
+ "Image configuration.
"
+ ),
+ array(
+ 'name' => 'THUMB_WIDTH',
+ 'html' => 'text',
+ 'values' => '200',
+ 'comment' => 'Maximum thumbnail width:'
+ ),
+ array(
+ 'name' => 'THUMB_HEIGHT',
+ 'html' => 'text',
+ 'values' => '200',
+ 'comment' => 'Maximum thumbnail height:'
+ ),
+ array(
+ 'name' => 'MAX_FILESIZE',
+ 'html' => 'text',
+ 'values' => '10485760',
+ 'comment' => 'Maximum file size (in bytes; default: 10MB):'
+ ),
+ array(
+ 'name' => 'MAX_WIDTH',
+ 'html' => 'text',
+ 'values' => '10000',
+ 'comment' => 'Maximum image width:'
+ ),
+ array(
+ 'name' => 'MAX_HEIGHT',
+ 'html' => 'text',
+ 'values' => '10000',
+ 'comment' => 'Maximum image height:'
+ ),
+ array(
+ 'name' => 'ALLOW_ZIP',
+ 'html' => 'bool',
+ 'values' => false,
+ 'comment' => '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.)'
+ ),
+ array(
+ 'name' => 'REDRAW_IMAGE',
+ 'html' => 'bool',
+ 'values' => false,
+ 'comment' => 'Redraw the image using GD functions to strip any excess data (WARNING: VERY BETA).'
+ ),
+ array(
+ 'name' => 'SHOW_RATIO',
+ 'html' => 'bool',
+ 'values' => true,
+ 'comment' => 'Display the aspect ratio in a post\'s file info.'
+ ),
+
+ // Cookies
+ array(
+ 'output' => "Cookies
\n".
+ "The following deals with cookie setup. ".
+ "You probably don't need to change it.
"
+ ),
+ array(
+ 'name' => 'SESS_COOKIE',
+ 'html' => 'text',
+ 'values' => 'imgboard',
+ 'comment' => 'Name of the session cookie:'
+ ),
+ array(
+ 'name' => 'TIME_COOKIE',
+ 'html' => 'text',
+ 'values' => 'arrived',
+ 'comment' => 'Name of the time cookie:'
+ ),
+ array(
+ 'name' => 'HASH_COOKIE',
+ 'html' => 'text',
+ 'values' => 'hash',
+ 'comment' => 'Name of the hash cookie:'
+ ),
+ array(
+ 'name' => 'MOD_COOKIE',
+ 'html' => 'text',
+ 'values' => 'mod',
+ 'comment' => 'Name of the moderator cookie:'
+ ),
+ array(
+ 'name' => 'JAIL_COOKIES',
+ 'html' => 'text',
+ 'values' => 'true',
+ 'comment' => 'Where to set the \'path\' parameter to ROOT when creating cookies. Recommended.:'
+ ),
+ array(
+ 'name' => 'COOKIE_EXPIRE',
+ 'html' => 'text',
+ 'values' => '15778463',
+ 'comment' => 'How long should the cookies last (in seconds; default 6 months):'
+ ),
+ array(
+ 'name' => 'SALT',
+ 'html' => 'text',
+ 'values' => md5(rand(0,100)),
+ 'comment' => 'Make this something long and random for security:'
+ ),
+
+ );
+
+$sql = array(
+ 'SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";',
+ 'CREATE TABLE IF NOT EXISTS `boards` (
+ `id` smallint(6) NOT NULL AUTO_INCREMENT,
+ `uri` varchar(8) NOT NULL,
+ `title` varchar(20) NOT NULL,
+ `subtitle` varchar(40) DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `uri` (`uri`),
+ UNIQUE KEY `id` (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;',
+ 'INSERT INTO `boards` (`id`, `uri`, `title`, `subtitle`) VALUES
+(1, \'b\', \'Beta\', \'In development.\');',
+ 'CREATE TABLE IF NOT EXISTS `posts_b` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `thread` int(11) DEFAULT NULL,
+ `subject` varchar(40) NOT NULL,
+ `email` varchar(30) NOT NULL,
+ `name` varchar(25) NOT NULL,
+ `trip` varchar(15) DEFAULT NULL,
+ `body` text NOT NULL,
+ `time` int(11) NOT NULL,
+ `bump` int(11) DEFAULT NULL,
+ `thumb` varchar(50) DEFAULT NULL,
+ `thumbwidth` int(11) DEFAULT NULL,
+ `thumbheight` int(11) DEFAULT NULL,
+ `file` varchar(50) DEFAULT NULL,
+ `filewidth` int(11) DEFAULT NULL,
+ `fileheight` int(11) DEFAULT NULL,
+ `filesize` int(11) DEFAULT NULL,
+ `filename` varchar(30) DEFAULT NULL,
+ `filehash` varchar(32) DEFAULT NULL,
+ `password` varchar(20) DEFAULT NULL,
+ `ip` varchar(15) NOT NULL,
+ `sticky` int(1) NOT NULL,
+ UNIQUE KEY `id` (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;',
+ 'CREATE TABLE IF NOT EXISTS `mods` (
+ `id` smallint(6) NOT NULL AUTO_INCREMENT,
+ `username` varchar(30) NOT NULL,
+ `password` char(40) NOT NULL COMMENT \'SHA1\',
+ `type` smallint(1) NOT NULL COMMENT \'0: janitor, 1: mod, 2: admin\',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `id` (`id`,`username`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;',
+ 'INSERT INTO `mods` (`id`, `username`, `password`, `type`) VALUES
+(1, \'admin\', \'5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8\', 2);',
+ 'CREATE TABLE IF NOT EXISTS `bans` (
+ `ip` varchar( 15 ) NOT NULL ,
+ `mod` int NOT NULL COMMENT \'which mod made the ban\',
+ `set` int NOT NULL,
+ `expires` int NULL,
+ `reason` text NULL
+) ENGINE = InnoDB;',
+ );
+
+if (isset($_POST['submit'])) {
+ $date = date('H:i jS F Y (e)');
+ $config_file = "Install Complete.";
+ die();
+}
+
+echo "";
+
+?>
--
cgit v1.3
From 39515df99926e7c44cf547d2efec1d79722966e5 Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Sun, 2 Jan 2011 21:09:02 +1100
Subject: Added ERROR_NOTAMOD
---
inc/config.php | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 8cbc6ba2..52eb40bb 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -74,6 +74,7 @@
// 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);
@@ -251,4 +252,4 @@
error_reporting(E_ALL);
ini_set('display_errors', 1);
}
-?>
+?>
\ No newline at end of file
--
cgit v1.3
From bcda984255b5168cd0460364c863c083e08d9ad0 Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Sun, 2 Jan 2011 22:17:25 +1100
Subject: Fixed URL matching
---
inc/config.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 52eb40bb..1c6f94b6 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -212,7 +212,7 @@
// Whether to turn URLs into functional links
define('MARKUP_URLS', true, 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);
+ 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);
// Allowed file extensions
$allowed_ext = Array('jpg', 'jpeg', 'bmp', 'gif', 'png', true);
--
cgit v1.3
From 97e927bef9e5c69ece8f1c78c5dfe1b16493c842 Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Sun, 2 Jan 2011 22:30:30 +1100
Subject: Show locked threads
---
inc/config.php | 1 +
inc/display.php | 5 ++++-
inc/functions.php | 4 ++--
static/locked.gif | Bin 0 -> 423 bytes
4 files changed, 7 insertions(+), 3 deletions(-)
create mode 100644 static/locked.gif
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 1c6f94b6..6824e71d 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -127,6 +127,7 @@
// 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);
diff --git a/inc/display.php b/inc/display.php
index 555b78e8..ddced5c6 100644
--- a/inc/display.php
+++ b/inc/display.php
@@ -170,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, $mod=false) {
+ 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) {
$this->id = $id;
$this->subject = utf8tohtml($subject);
$this->email = $email;
@@ -190,6 +190,7 @@
$this->posts = Array();
$this->ip = $ip;
$this->sticky = $sticky;
+ $this->locked = $locked;
$this->root = $root;
$this->mod = $mod;
}
@@ -281,6 +282,8 @@
'id . ');"') . 'href="' . ($index?$this->root . $board['dir'] . DIR_RES . $this->id . '.html' . '#q' . $this->id:'javascript:void(0);') . '">'.$this->id.'' .
// Sticky
($this->sticky ? '
' : '') .
+ // Locked
+ ($this->locked ? '
' : '') .
// [Reply]
($index ? '[Reply]' : '') .
diff --git a/inc/functions.php b/inc/functions.php
index 57980283..99b8ac71 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -214,7 +214,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, $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 ? '?/' : 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']);
@@ -407,7 +407,7 @@
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, $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'], $th['locked'], $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, $mod));
}
diff --git a/static/locked.gif b/static/locked.gif
new file mode 100644
index 00000000..d178c7b6
Binary files /dev/null and b/static/locked.gif differ
--
cgit v1.3
From e23aa7a7368f9c373f7593976ab84f8f093e5cbd Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Sun, 2 Jan 2011 22:45:25 +1100
Subject: FILE_HASH in config.php
---
inc/config.php | 5 +++++
post.php | 3 ++-
2 files changed, 7 insertions(+), 1 deletion(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 6824e71d..0347846c 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -87,6 +87,11 @@
// For resizing, max values
define('THUMB_WIDTH', 200, true);
define('THUMB_HEIGHT', 200, true);
+
+ // Store image hash in the database for r9k-like boards implementation soon
+ // Function name for hashing
+ // sha1_file, md5_file, etc.
+ define('FILE_HASH', 'md5_file', true);
// Maximum image upload size in bytes
define('MAX_FILESIZE', 10*1024*1024, true); // 10MB
diff --git a/post.php b/post.php
index 56bddd5d..169a55e1 100644
--- a/post.php
+++ b/post.php
@@ -166,7 +166,8 @@
error(ERR_MAXSIZE);
}
- $post['filehash'] = md5_file($post['file']);
+ $hash_function = FILE_HASH;
+ $post['filehash'] = $hash_function($post['file']);
$post['filesize'] = filesize($post['file']);
$image = createimage($post['extension'], $post['file']);
--
cgit v1.3
From 5df6f85854f25581df787241773b8b39e23e8f00 Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Mon, 3 Jan 2011 01:23:34 +1100
Subject: Don't allow users to post in locked threads'
---
inc/config.php | 3 +++
inc/functions.php | 15 +++++++++++++++
post.php | 3 +++
3 files changed, 21 insertions(+)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 0347846c..26607d25 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -66,6 +66,7 @@
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('ERR_INVALIDIMG','Invalid image.', true);
define('ERR_FILESIZE', 'Maximum file size: %maxsz% bytes
Your file\'s size: %filesz% bytes', true);
@@ -186,6 +187,8 @@
define('MOD_DELETEBYIP', MOD_BAN, true);
// Sticky a thread
define('MOD_STICKY', MOD_MOD, true);
+ // Lock a thread
+ define('MOD_LOCK', MOD_MOD, true);
/* Administration */
// Display the contents of instant-config.php
diff --git a/inc/functions.php b/inc/functions.php
index e5a8023d..a5ec0093 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -118,6 +118,21 @@
}
}
+ function threadLocked($id) {
+ global $board;
+
+ $query = prepare(sprintf("SELECT `locked` FROM `posts_%s` WHERE `id` = :id AND `thread` IS NULL LIMIT 1", $board['uri']));
+ $query->bindValue(':id', $id, PDO::PARAM_INT);
+ $query->execute() or error(db_error());
+
+ if(!$post = $query->fetch()) {
+ // Non-existant, so it can't be locked...
+ return false;
+ }
+
+ return (bool) $post['locked'];
+ }
+
function threadExists($id) {
global $board;
diff --git a/post.php b/post.php
index cdc51ffd..452aa054 100644
--- a/post.php
+++ b/post.php
@@ -70,6 +70,9 @@
if(!$OP && !threadExists($post['thread']))
error(ERROR_NONEXISTANT);
+ if(!$OP && threadLocked($post['thread']))
+ error(ERROR_LOCKED);
+
// Check for a file
if($OP) {
if(!isset($_FILES['file']['tmp_name']) || empty($_FILES['file']['tmp_name']))
--
cgit v1.3
From 8fe1846e5642ad50790dc1626a025f9845d74d69 Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Mon, 3 Jan 2011 01:33:57 +1100
Subject: Allow mods to post in locked threads as per the config
---
inc/config.php | 2 ++
post.php | 13 +++++++++----
2 files changed, 11 insertions(+), 4 deletions(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 26607d25..ec697f79 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -189,6 +189,8 @@
define('MOD_STICKY', MOD_MOD, true);
// Lock a thread
define('MOD_LOCK', MOD_MOD, true);
+ // Post in a locked thread
+ define('MOD_POSTINLOCKED', MOD_MOD, true);
/* Administration */
// Display the contents of instant-config.php
diff --git a/post.php b/post.php
index 452aa054..f76b2c73 100644
--- a/post.php
+++ b/post.php
@@ -69,10 +69,7 @@
//Check if thread exists
if(!$OP && !threadExists($post['thread']))
error(ERROR_NONEXISTANT);
-
- if(!$OP && threadLocked($post['thread']))
- error(ERROR_LOCKED);
-
+
// Check for a file
if($OP) {
if(!isset($_FILES['file']['tmp_name']) || empty($_FILES['file']['tmp_name']))
@@ -102,6 +99,14 @@
if($post['locked'] && $mod['type'] < MOD_LOCK) error(ERROR_NOACCESS);
}
+ // Check if thread is locked
+ // but allow mods to post
+ if(!$OP && threadLocked($post['thread'])) {
+ if(!$mod || $mod['type'] < MOD_POSTINLOCKED) {
+ error(ERROR_LOCKED);
+ }
+ }
+
if($post['has_file']) {
$size = $_FILES['file']['size'];
if($size > MAX_FILESIZE)
--
cgit v1.3
From 8981e4b2759f1ae138824823c68e79995411f1e0 Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Mon, 3 Jan 2011 01:56:06 +1100
Subject: Changed FILE_HASH to default to sha1
---
inc/config.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index ec697f79..809e8148 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -92,7 +92,7 @@
// Store image hash in the database for r9k-like boards implementation soon
// Function name for hashing
// sha1_file, md5_file, etc.
- define('FILE_HASH', 'md5_file', true);
+ define('FILE_HASH', 'sha1_file', true);
// Maximum image upload size in bytes
define('MAX_FILESIZE', 10*1024*1024, true); // 10MB
--
cgit v1.3
From db1760322149162062e774cf2849357c76a6749e Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Mon, 3 Jan 2011 02:28:29 +1100
Subject: Locking permissions
---
inc/config.php | 3 ++-
inc/functions.php | 4 ++--
2 files changed, 4 insertions(+), 3 deletions(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index 809e8148..d40f7654 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -207,7 +207,8 @@
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);
// 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);
diff --git a/inc/functions.php b/inc/functions.php
index a5ec0093..8cea487e 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -99,9 +99,9 @@
formatDate($ban['set']) .
', and ' .
($ban['expires'] ?
- 'expires on ' .
+ 'expires ' . until($ban['expires']) . ' from now, which is on ' .
formatDate($ban['expires']) .
- ', which is ' . until($ban['expires']) . ' from now'
+ ''
: 'will not expire' ) .
'.
Your IP address is ' . $_SERVER['REMOTE_ADDR'] . '.
--
cgit v1.3
From 3a3578c80507d80d571297b6bbf2502d5da73fd9 Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Mon, 3 Jan 2011 16:29:34 +1100
Subject: Valid HTML5
---
inc/config.php | 2 +-
inc/display.php | 4 ++--
templates/index.html | 3 +--
templates/page.html | 2 +-
templates/thread.html | 3 +--
5 files changed, 6 insertions(+), 8 deletions(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index d40f7654..521d3eb3 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -202,7 +202,7 @@
// 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_BANDELETE', '[B&D]', true);
define('MOD_LINK_DELETEFILE', '[F]', true);
define('MOD_LINK_DELETEBYIP', '[D+]', true);
define('MOD_LINK_STICKY', '[Sticky]', true);
diff --git a/inc/display.php b/inc/display.php
index 58f26960..edcbf21b 100644
--- a/inc/display.php
+++ b/inc/display.php
@@ -138,7 +138,7 @@
($index?'':' onclick="highlightReply(' . $this->id . ');"') .
' href="' . $this->root . $board['dir'] . DIR_RES . $this->thread . '.html' . '#' . $this->id . '">No.' .
// JavaScript cite
- 'id . ');"') . 'href="' . ($index?$this->root . $board['dir'] . DIR_RES . $this->thread . '.html' . '#q' . $this->id:'javascript:void(0);') . '">'.$this->id.'' .
+ ''.$this->id.'' .
'
';
// File info
@@ -290,7 +290,7 @@
($index?'':' onclick="highlightReply(' . $this->id . ');"') .
' href="' . $this->root . $board['dir'] . DIR_RES . $this->id . '.html' . '#' . $this->id . '">No.' .
// JavaScript cite
- '
id . ');"') . 'href="' . ($index?$this->root . $board['dir'] . DIR_RES . $this->id . '.html' . '#q' . $this->id:'javascript:void(0);') . '">'.$this->id.'' .
+ '
'.$this->id.'' .
// Sticky
($this->sticky ? '

' : '') .
// Locked
diff --git a/templates/index.html b/templates/index.html
index 99c60d4f..d0702ba9 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -3,8 +3,7 @@
{board[url]} - {board[name]}
-
-
+
diff --git a/templates/page.html b/templates/page.html
index d8b78898..f8525e01 100644
--- a/templates/page.html
+++ b/templates/page.html
@@ -3,7 +3,7 @@
{title}
-
+
diff --git a/templates/thread.html b/templates/thread.html
index 58b5028c..2fd03418 100644
--- a/templates/thread.html
+++ b/templates/thread.html
@@ -3,8 +3,7 @@
{board[url]} - {board[name]}
-
-
+
--
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 'inc/config.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 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 'inc/config.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 .= '';
+ }
+
+ 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 d284b0d50dabef2627ba9e38291f07e736dd0721 Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Tue, 18 Jan 2011 17:11:28 +1100
Subject: flood prevention
---
inc/config.php | 12 ++++++++++--
inc/functions.php | 14 ++++++++++++++
post.php | 4 ++++
3 files changed, 28 insertions(+), 2 deletions(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index ae79edc4..f3906b1b 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -44,12 +44,19 @@
// How many seconds before you can post, after the first visit
define('LURKTIME', 30, true);
+
+ // How many seconds between each post
+ define('FLOOD_TIME', 4, true);
+ // How many seconds between each post with exactly the same content and same IP
+ define('FLOOD_TIME_IP_SAME', 120, true);
+ // Same as above but different IP address
+ define('FLOOD_TIME_SAME', 30, true);
// Max body length
define('MAX_BODY', 1800, true);
define('THREADS_PER_PAGE', 10, true);
- define('MAX_PAGES', 5, true);
+ define('MAX_PAGES', 10, true);
define('THREADS_PREVIEW', 5, true);
// For development purposes. Turns 'display_errors' on. Not recommended for production.
@@ -68,10 +75,11 @@
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('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);
+ define('ERR_INVALIDZIP', 'Invalid archive!', true);
// Moderator errors
define('ERROR_INVALID', 'Invalid username and/or password.', true);
diff --git a/inc/functions.php b/inc/functions.php
index de188f0b..70a17d23 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -45,6 +45,20 @@
return $boards;
}
+ function checkFlood($post) {
+ global $board;
+
+ $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->execute() or error(db_error($query));
+
+ return (bool)$query->fetch();
+ }
+
function until($timestamp) {
$difference = $timestamp - time();
if($difference < 60) {
diff --git a/post.php b/post.php
index d2306ca1..66247f4f 100644
--- a/post.php
+++ b/post.php
@@ -143,6 +143,10 @@
markup($post['body']);
+ // Check for a flood
+ if(checkFlood($post))
+ error(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).'…';
--
cgit v1.3
From 62bd2ee348f460b3d4cbbdbd8469a783b4c64c78 Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Wed, 19 Jan 2011 00:41:43 +1100
Subject: A bunch of stuff.
---
inc/config.php | 9 ++++++
inc/functions.php | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
inc/mod.php | 41 -------------------------
post.php | 9 ++++--
style.css | 10 ++++++
5 files changed, 117 insertions(+), 44 deletions(-)
(limited to 'inc/config.php')
diff --git a/inc/config.php b/inc/config.php
index f3906b1b..746efb63 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -76,6 +76,7 @@
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('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);
@@ -163,6 +164,12 @@
// "302" is recommended.
define('REDIRECT_HTTP', 302, true);
+ // Robot stuff
+ // Strip repeating characters when making hashes
+ define('ROBOT_ENABLE', true, true);
+ define('ROBOT_STRIP_REPEATING', true, true);
+
+
/*
Mod stuff
*/
@@ -206,6 +213,8 @@
define('MOD_LOCK', MOD_MOD, true);
// Post in a locked thread
define('MOD_POSTINLOCKED', MOD_MOD, true);
+ // Post bypass unoriginal content check
+ define('MOD_POSTUNORIGINAL', MOD_MOD, true);
/* Administration */
// Display the contents of instant-config.php
diff --git a/inc/functions.php b/inc/functions.php
index 70a17d23..4f4a69bd 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -261,7 +261,62 @@
$query->bindValue(':id', $id, PDO::PARAM_INT);
$query->execute() or error(db_error($query));
}
-
+
+ // Delete a post (reply or thread)
+ function deletePost($id) {
+ global $board;
+
+ // 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']));
+ $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 = $query->fetch()) {
+ if(!$post['thread']) {
+ // Delete thread HTML page
+ @unlink($board['dir'] . DIR_RES . sprintf(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']);
+ }
+ if($post['file']) {
+ // Delete file
+ @unlink($board['dir'] . DIR_IMG . $post['file']);
+ }
+ }
+
+ $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));
+
+ if(isset($rebuild)) {
+ buildThread($rebuild);
+ }
+ }
+
+ function clean() {
+ global $board;
+ $offset = round(MAX_PAGES*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']));
+ $query->bindValue(':offset', $offset, PDO::PARAM_INT);
+
+ $query->execute() or error(db_error($query));
+ while($post = $query->fetch()) {
+ deletePost($post['id']);
+ }
+ }
+
function index($page, $mod=false) {
global $board;
@@ -323,7 +378,41 @@
return $pages;
}
+
+ function makerobot($body) {
+ $body = strtolower($body);
+
+ // Leave only letters
+ $body = preg_replace('/[^a-z]/i', '', $body);
+ // Remove repeating characters
+ if(ROBOT_STRIP_REPEATING)
+ $body = preg_replace('/(.)\\1+/', '$1', $body);
+
+ return sha1($body);
+ }
+
+ function checkRobot($body) {
+ /* CREATE TABLE `robot` (
+`hash` VARCHAR( 40 ) NOT NULL COMMENT 'SHA1'
+) ENGINE = INNODB; */
+
+ $body = makerobot($body);
+ $query = prepare("SELECT 1 FROM `robot` WHERE `hash` = :hash LIMIT 1");
+ $query->bindValue(':hash', $body);
+ $query->execute() or error(db_error($query));
+ if($query->fetch()) {
+ return true;
+ } else {
+ // Insert new hash
+
+ $query = prepare("INSERT INTO `robot` VALUES (:hash)");
+ $query->bindValue(':hash', $body);
+ $query->execute() or error(db_error($query));
+ return false;
+ }
+ }
+
function buildIndex() {
global $board;
sql_open();
@@ -417,6 +506,7 @@
$body = preg_replace("/(^|\n)==(.+?)==\n?/m", "$2
", $body);
$body = preg_replace("/'''(.+?)'''/m", "$1", $body);
$body = preg_replace("/''(.+?)''/m", "$1", $body);
+ $body = preg_replace("/\*\*(.+?)\*\*/m", "$1", $body);
}
$body = preg_replace("/\n/", '
', $body);
}
diff --git a/inc/mod.php b/inc/mod.php
index a325d589..5e3a2c87 100644
--- a/inc/mod.php
+++ b/inc/mod.php
@@ -209,45 +209,4 @@
buildThread($post['thread']);
}
-
- // Delete a post (reply or thread)
- function deletePost($id) {
- global $board;
-
- // 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']));
- $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 = $query->fetch()) {
- if(!$post['thread']) {
- // Delete thread HTML page
- @unlink($board['dir'] . DIR_RES . sprintf(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']);
- }
- if($post['file']) {
- // Delete file
- @unlink($board['dir'] . DIR_IMG . $post['file']);
- }
- }
-
- $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));
-
- if(isset($rebuild)) {
- buildThread($rebuild);
- }
- }
?>
\ No newline at end of file
diff --git a/post.php b/post.php
index 66247f4f..40830f0f 100644
--- a/post.php
+++ b/post.php
@@ -147,6 +147,9 @@
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
if(strlen($post['filename']) > 30) $post['filename'] = substr($post['filename'], 0, 27).'…';
@@ -221,7 +224,6 @@
}
// Todo: Validate some more, remove messy code, allow more specific configuration
-
$id = post($post, $OP);
if($post['has_file'] && $post['zip']) {
@@ -322,10 +324,13 @@
buildThread(($OP?$id:$post['thread']));
- if(!$OP) {
+ if(!$OP && $post['email'] != 'sage') {
bumpThread($post['thread']);
}
+ if($OP)
+ clean();
+
buildIndex();
sql_close();
diff --git a/style.css b/style.css
index ca26a8da..60c36d19 100644
--- a/style.css
+++ b/style.css
@@ -199,6 +199,10 @@ span.controls.op {
span.controls a {
margin: 0;
}
+div#wrap {
+ width: 900px;
+ margin:0 auto;
+}
div.ban {
background: white;
border: 1px solid #98E;
@@ -219,4 +223,10 @@ div.ban p {
}
div.ban p.reason {
font-weight: bold;
+}
+span.spoiler {
+ background: black;
+}
+span.spoiler:hover {
+ color: white;
}
\ No newline at end of file
--
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 'inc/config.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