From 3679f2c78b4ad4c4204738ab0739c9aaad88f751 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Thu, 2 Dec 2010 20:50:14 +1100 Subject: SQL table creation template --- templates/posts.sql | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 templates/posts.sql (limited to 'templates/posts.sql') diff --git a/templates/posts.sql b/templates/posts.sql new file mode 100644 index 00000000..d9c91886 --- /dev/null +++ b/templates/posts.sql @@ -0,0 +1,23 @@ +CREATE TABLE IF NOT EXISTS `posts_{board}` ( + `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, + UNIQUE KEY `id` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; \ No newline at end of file -- cgit v1.3 From 22641bdc58909485cfcd9c05e4ac4f231022fe6f Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Thu, 16 Dec 2010 21:28:38 +1100 Subject: Basic stickies --- inc/functions.php | 31 ++++++++++++++++++------------- install.sql | 1 + templates/posts.sql | 1 + 3 files changed, 20 insertions(+), 13 deletions(-) (limited to 'templates/posts.sql') diff --git a/inc/functions.php b/inc/functions.php index 69c719ba..bc6fce45 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -85,7 +85,7 @@ global $sql, $board; 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' )", + 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'], @@ -109,7 +109,7 @@ return mysql_insert_id($sql); } 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' )", + 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'], @@ -143,7 +143,7 @@ sql_open(); $query = mysql_query(sprintf( - "SELECT * FROM `posts_%s` WHERE `thread` IS NULL ORDER BY `bump` DESC LIMIT %d,%d", + "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 @@ -183,11 +183,10 @@ mysql_free_result($query); return Array('button'=>BUTTON_NEWTOPIC, 'board'=>$board, 'body'=>$body, 'post_url' => POST_URL, 'index' => ROOT); } - - function buildIndex() { + + function getPages($mod=false) { global $sql, $board; - sql_open(); - + $res = mysql_query(sprintf( "SELECT COUNT(`id`) as `num` FROM `posts_%s` WHERE `thread` IS NULL", mysql_real_escape_string($board['uri']) @@ -197,12 +196,17 @@ $pages = Array(); for($x=0;$x<$count && $x $x+1, 'link' => $x==0 ? ROOT . $board['dir'] . FILE_INDEX : ROOT . $board['dir'] . sprintf(FILE_PAGE, $x+1)); - } + $pages[] = Array('num' => $x+1, 'link' => $x==0 ? ($mod ? '?/' : ROOT) . $board['dir'] . FILE_INDEX : ($mod ? '?/' : ROOT) . $board['dir'] . sprintf(FILE_PAGE, $x+1)); + } + + return $pages; + } - mysql_free_result($res); - unset($arr); - unset($count); + function buildIndex() { + global $sql, $board; + sql_open(); + + $pages = getPages(); $page = 1; while($page <= MAX_PAGES && $content = index($page)) { @@ -356,7 +360,8 @@ 'body'=>$thread->build(), 'post_url' => POST_URL, 'index' => ROOT, - 'id' => $id + 'id' => $id, + 'mod' => $mod )); if($return) diff --git a/install.sql b/install.sql index b3039f3c..051b596b 100644 --- a/install.sql +++ b/install.sql @@ -69,6 +69,7 @@ CREATE TABLE IF NOT EXISTS `posts_b` ( `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 ; diff --git a/templates/posts.sql b/templates/posts.sql index d9c91886..9806a10b 100644 --- a/templates/posts.sql +++ b/templates/posts.sql @@ -19,5 +19,6 @@ CREATE TABLE IF NOT EXISTS `posts_{board}` ( `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 ; \ No newline at end of file -- cgit v1.3 From 69956021fc50d904d4050378543524a3e2e0b4e0 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Sun, 2 Jan 2011 22:21:53 +1100 Subject: Locked field in database --- install.php | 10 ++++++++-- install.sql | 1 + templates/posts.sql | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) (limited to 'templates/posts.sql') diff --git a/install.php b/install.php index 6333c281..fb171397 100644 --- a/install.php +++ b/install.php @@ -32,7 +32,12 @@ $default_values = array( array( 'name' => 'DB_TYPE', 'html' => 'dropdown', - 'values' => array('mysql'=>'MySQL'), + 'values' => array( + 'mysql' => 'MySQL', + 'dblib' => 'FreeTDS / Microsoft SQL Server / Sybase', + 'pgsql' => 'PostgreSQL', + 'sqlite' => 'SQLite' + ), 'comment' => 'Database engine:' ), array( @@ -243,6 +248,7 @@ $sql = array( `password` varchar(20) DEFAULT NULL, `ip` varchar(15) NOT NULL, `sticky` int(1) NOT NULL, + `locked` int(1) NOT NULL, UNIQUE KEY `id` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;', 'CREATE TABLE IF NOT EXISTS `mods` ( @@ -290,7 +296,7 @@ if (isset($_POST['submit'])) { require 'inc/functions.php'; require 'inc/display.php'; require 'inc/instance-config.php'; - require 'inc/config.php'; + //require 'inc/config.php'; require 'inc/template.php'; require 'inc/database.php'; diff --git a/install.sql b/install.sql index 6a828e3a..0955c153 100644 --- a/install.sql +++ b/install.sql @@ -70,6 +70,7 @@ CREATE TABLE IF NOT EXISTS `posts_b` ( `password` varchar(20) DEFAULT NULL, `ip` varchar(15) NOT NULL, `sticky` int(1) NOT NULL, + `locked` int(1) NOT NULL, UNIQUE KEY `id` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; diff --git a/templates/posts.sql b/templates/posts.sql index 9806a10b..4163f125 100644 --- a/templates/posts.sql +++ b/templates/posts.sql @@ -20,5 +20,6 @@ CREATE TABLE IF NOT EXISTS `posts_{board}` ( `password` varchar(20) DEFAULT NULL, `ip` varchar(15) NOT NULL, `sticky` int(1) NOT NULL, + `locked` int(1) NOT NULL, UNIQUE KEY `id` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; \ 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 'templates/posts.sql') diff --git a/inc/config.php b/inc/config.php index 746efb63..65346edd 100644 --- a/inc/config.php +++ b/inc/config.php @@ -41,7 +41,8 @@ define('COOKIE_EXPIRE', 15778463, true); //6 months // Make this something long and random for security define('SALT', 'wefaw98YHEWUFuo', true); - + define('SECURE_TRIP_SALT', '@#$&^@#)$(*&@!_$(&329-8347', true); + // How many seconds before you can post, after the first visit define('LURKTIME', 30, true); @@ -51,6 +52,8 @@ define('FLOOD_TIME_IP_SAME', 120, true); // Same as above but different IP address define('FLOOD_TIME_SAME', 30, true); + // Do you need a body for your non-OP posts? + define('FORCE_BODY', true, true); // Max body length define('MAX_BODY', 1800, true); @@ -77,6 +80,9 @@ define('ERROR_NOPOST', 'You didn\'t make a post.', true); define('ERROR_FLOOD', 'Flood detected; Post discared.', true); define('ERROR_UNORIGINAL', 'Unoriginal content!', true); + define('ERROR_MUTED', 'Unoriginal content! You have been muted for %d seconds.', true); + define('ERROR_TOR', 'Hmm… That looks like a Tor exit node.', true); + define('ERROR_TOOMANYLINKS', 'Too many links; flood detected.', true); define('ERR_INVALIDIMG','Invalid image.', true); define('ERR_FILESIZE', 'Maximum file size: %maxsz% bytes
Your file\'s size: %filesz% bytes', true); define('ERR_MAXSIZE', 'The file was too big.', true); @@ -103,7 +109,11 @@ // Function name for hashing // sha1_file, md5_file, etc. define('FILE_HASH', 'sha1_file', true); - + + define('BLOCK_TOR', true, true); + // Typically spambots try to post a lot of links. Refuse a post with X standalone links? + define('MAX_LINKS', 7, true); + // Maximum image upload size in bytes define('MAX_FILESIZE', 10*1024*1024, true); // 10MB // Maximum image dimensions @@ -167,8 +177,13 @@ // Robot stuff // Strip repeating characters when making hashes define('ROBOT_ENABLE', true, true); + define('ROBOT_BOARD', 'r9k', true); define('ROBOT_STRIP_REPEATING', true, true); - + // Enable mutes + define('ROBOT_MUTE', true, true); + define('ROBOT_MUTE_MIN', 60, true); + define('ROBOT_MUTE_MAX', 120, true); + define('ROBOT_MUTE_DESCRIPTION', 'You have been muted for unoriginal content.', true); /* Mod stuff diff --git a/inc/functions.php b/inc/functions.php index 4f4a69bd..6193ab38 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -439,14 +439,43 @@ } } } + + function isDNSBL() { + $dns_black_lists = file('./dnsbl.txt', FILE_IGNORE_NEW_LINES); + + // Reverse the IP + $rev_ip = implode(array_reverse(explode('.', $_SERVER['REMOTE_ADDR'])), '.'); + $response = array(); + foreach ($dns_black_lists as $dns_black_list) { + $response = (gethostbynamel($rev_ip . '.' . $dns_black_list)); + if(!empty($response)) + return true; + } + + return false; + } + + function isTor() { + return gethostbyname( + ReverseIPOctets($_SERVER['REMOTE_ADDR']) . '.' . $_SERVER['SERVER_PORT'] . '.' . ReverseIPOctets($_SERVER['SERVER_ADDR']) . '.ip-port.exitlist.torproject.org' + ) == '127.0.0.2'; + } + + function ReverseIPOctets($inputip) { + $ipoc = explode('.', $inputip); + return $ipoc[3] . '.' . $ipoc[2] . '.' . $ipoc[1] . '.' . $ipoc[0]; + } function markup(&$body) { global $board; $body = utf8tohtml($body, true); - if(MARKUP_URLS) - $body = preg_replace(URL_REGEX, "$0", $body); + if(MARKUP_URLS) { + $body = preg_replace(URL_REGEX, "$0", $body, -1, $num_links); + if($num_links > MAX_LINKS) + error(ERROR_TOOMANYLINKS); + } if(AUTO_UNICODE) { $body = str_replace('...', '…', $body); @@ -602,7 +631,7 @@ $salt = strtr ( $salt, ':;<=>?@[\]^_`', 'ABCDEFGabcdef' ); if ( isset ( $t[2] ) ) { // secure - $trip = '!!' . substr ( crypt ( $trip, '@#$%^&*()' ), ( -1 * $length ) ); + $trip = '!!' . substr ( crypt ( $trip, SECURE_TRIP_SALT ), ( -1 * $length ) ); } else { // insecure $trip = '!' . substr ( crypt ( $trip, $salt ), ( -1 * $length ) ); diff --git a/mod.php b/mod.php index b4355fe4..80647471 100644 --- a/mod.php +++ b/mod.php @@ -464,7 +464,7 @@ openBoard($_board['uri']); $temp = ''; - $query = prepare(sprintf("SELECT * FROM `posts_%s` WHERE `ip` = :ip ORDER BY `sticky` DESC, `time` LIMIT :limit", $_board['uri'])); + $query = prepare(sprintf("SELECT * FROM `posts_%s` WHERE `ip` = :ip ORDER BY `sticky` DESC, `time` DESC LIMIT :limit", $_board['uri'])); $query->bindValue(':ip', $ip); $query->bindValue(':limit', MOD_IP_RECENTPOSTS, PDO::PARAM_INT); $query->execute() or error(db_error($query)); diff --git a/post.php b/post.php index 40830f0f..b8724522 100644 --- a/post.php +++ b/post.php @@ -62,6 +62,9 @@ // Check if banned checkBan(); + if(BLOCK_TOR && isTor()) + error(ERROR_TOR); + // Check if board exists if(!openBoard($post['board'])) error(ERROR_NOBOARD); @@ -85,6 +88,9 @@ $post['has_file'] = $OP || !empty($_FILES['file']['tmp_name']); $post['mod'] = isset($_POST['mod']) && $_POST['mod']; + if(empty($post['body']) && FORCE_BODY) + error(ERROR_TOOSHORTBODY); + if($post['mod']) { require 'inc/mod.php'; if(!$mod) { @@ -115,6 +121,15 @@ 'maxsz'=>commaize(MAX_FILESIZE)))); } + if($mod && $mod['type'] >= MOD_MOD && preg_match('/^((.+) )?## (.+)$/', $post['name'], $match)) { + if(($mod['type'] == MOD_MOD && $match[3] == 'Mod') || $mod['type'] >= MOD_ADMIN) { + $post['mod_tag'] = $match[3]; + $post['name'] = !empty($match[2])?$match[2]:'Anonymous'; + } + } else { + $post['mod_tag'] = false; + } + $trip = generate_tripcode($post['name']); $post['name'] = $trip[0]; $post['trip'] = (isset($trip[1])?$trip[1]:''); @@ -134,21 +149,40 @@ } // Check string lengths - if(strlen($post['name']) > 25) error(sprintf(ERROR_TOOLONG, 'name')); + if(strlen($post['name']) > 25) error(sprintf(ERROR_TOOLONG, 'name')); if(strlen($post['email']) > 30) error(sprintf(ERROR_TOOLONG, 'email')); if(strlen($post['subject']) > 40) error(sprintf(ERROR_TOOLONG, 'subject')); if(strlen($post['body']) > MAX_BODY) error(ERROR_TOOLONGBODY); if(!(!$OP && $post['has_file']) && strlen($post['body']) < 1) error(ERROR_TOOSHORTBODY); if(strlen($post['password']) > 20) error(sprintf(ERROR_TOOLONG, 'password')); + if($post['mod_tag']) + $post['trip'] .= ' ## ' . $post['mod_tag'] . ''; + + if(!($mod && $mod['type'] >= MOD_POSTUNORIGINAL) && ROBOT_ENABLE && $board['uri'] == ROBOT_BOARD && checkRobot($post['body'])) { + if(ROBOT_MUTE) { + $mutetime = ROBOT_MUTE_MIN+rand()%(ROBOT_MUTE_MAX-ROBOT_MUTE_MIN); + + $query = prepare("INSERT INTO `bans` VALUES (:ip, :mod, :set, :expires, :reason)"); + $query->bindValue(':ip', $_SERVER['REMOTE_ADDR']); + $query->bindValue(':mod', -1, PDO::PARAM_INT); + $query->bindValue(':set', time(), PDO::PARAM_INT); + $query->bindValue(':expires', time()+$mutetime, PDO::PARAM_INT); + $query->bindValue(':reason', ROBOT_MUTE_DESCRIPTION); + $query->execute() or error(db_error($query)); + + error(sprintf(ERROR_MUTED, $mutetime)); + } else { + error(ERROR_UNORIGINAL); + } + } + markup($post['body']); // Check for a flood - if(checkFlood($post)) + if(checkFlood($post)) { error(ERROR_FLOOD); - - if(!($mod && $mod['type'] >= MOD_POSTUNORIGINAL) && ROBOT_ENABLE && checkRobot($post['body'])) - error(ERROR_UNORIGINAL); + } if($post['has_file']) { // Just trim the filename if it's too long @@ -206,6 +240,7 @@ imagebmp($image, $post['file']); break; default: + unlink($post['file']); error('Unknwon file extension.'); } } diff --git a/style.css b/style.css index 60c36d19..058de230 100644 --- a/style.css +++ b/style.css @@ -146,6 +146,10 @@ p.intro span.name { color: #117743; font-weight: bold; } +p.intro a.nametag { + color: #F00000; + margin-left: 0; +} p.intro a { margin-left: 8px; } diff --git a/templates/posts.sql b/templates/posts.sql index 4163f125..f8e1b6fb 100644 --- a/templates/posts.sql +++ b/templates/posts.sql @@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS `posts_{board}` ( `subject` varchar(40) NOT NULL, `email` varchar(30) NOT NULL, `name` varchar(25) NOT NULL, - `trip` varchar(15) DEFAULT NULL, + `trip` varchar(45) DEFAULT NULL, `body` text NOT NULL, `time` int(11) NOT NULL, `bump` int(11) DEFAULT NULL, diff --git a/templates/thread.html b/templates/thread.html index 2fd03418..e1260ff5 100644 --- a/templates/thread.html +++ b/templates/thread.html @@ -71,6 +71,7 @@
{body} + [Return.]

Copyright © 2010 OmegaSDG

\ No newline at end of file -- cgit v1.3