From 19e864c15c33c7efce229bf1d134d6edd91feb77 Mon Sep 17 00:00:00 2001 From: 8chan Date: Thu, 25 Sep 2014 22:53:56 +0000 Subject: [PATCH] I don't know what I did. --- create.php | 63 +++++++++++++++++++++++++++++------- expire.php | 4 +++ inc/api.php | 5 +-- inc/config.php | 19 +++++++++++ inc/functions.php | 20 ++++++------ inc/instance-config.php | 1 + inc/mod/pages.php | 44 +++++++++++++++++-------- install.sql | 6 ++++ js/auto-reload.js | 9 ++++++ js/quick-post-controls.js | 4 +++ post.php | 8 ++--- random.php | 6 ++-- search.php | 2 +- templates/report_delete.html | 2 +- 14 files changed, 148 insertions(+), 45 deletions(-) diff --git a/create.php b/create.php index 306829fd..41efa666 100644 --- a/create.php +++ b/create.php @@ -3,13 +3,33 @@ include "inc/functions.php"; include "inc/lib/ayah/ayah.php"; include "inc/mod/auth.php"; +$cbRecaptcha = false; +//don't load recaptcha LIB unless its enabled! +if ($config['cbRecaptcha']){ +$cbRecaptcha = true; +include "inc/lib/recaptcha/recaptchalib.php"; +} + + checkBan('*'); $bannedWords = array('/^cake$/', '8ch', '/^cp$/', 'child', '/^inc$/', '/^static$/', '/^templates$/', '/^js$/', '/^stylesheets$/', '/^tools$/', '/^pedo$/'); -$ayah = new AYAH(); +$ayah = (($config['ayah_enabled']) ? new AYAH() : false); if (!isset($_POST['uri'], $_POST['title'], $_POST['subtitle'], $_POST['username'], $_POST['password'])) { -$publisher_html = $ayah->getPublisherHTML(); +if (!$ayah){ + $game_html = ''; +} else { + $game_html = 'Game' . $ayah->getPublisherHTML() . ''; +} + +if (!$cbRecaptcha){ + $recapcha_html = ''; +} else { + $recapcha_html = 'reCaptcha' . recaptcha_get_html($config['recaptcha_public']) . ''; +} + + $password = base64_encode(openssl_random_pseudo_bytes(9)); $body = <<Subtitle (must be < 200 chars) Username (must contain only alphanumeric, periods and underscores) Password (write this down) -Game{$publisher_html} +{$game_html} +{$recapcha_html}
@@ -38,8 +59,27 @@ $title = $_POST['title']; $subtitle = $_POST['subtitle']; $username = $_POST['username']; $password = $_POST['password']; -$score = $ayah->scoreResult(); + $resp = ($cbRecaptcha) ? recaptcha_check_answer ($config['recaptcha_private'], + $_SERVER["REMOTE_ADDR"], + $_POST["recaptcha_challenge_field"], + $_POST["recaptcha_response_field"]):false; + +if ($resp != false){ +$passedCaptcha = $resp->is_valid; +} else { +$passedCaptcha = true; +} + +if (!$ayah){ +$score = true; +} else { +$score = $ayah->scoreResult(); +} +if (!$score) + error('You failed the game'); +if (!$passedCaptcha) + error('You failed to enter the reCaptcha correctly'); if (!preg_match('/^[a-z0-9]{1,10}$/', $uri)) error('Invalid URI'); if (!(strlen($title) < 40)) @@ -48,8 +88,7 @@ if (!(strlen($subtitle) < 200)) error('Invalid subtitle'); if (!preg_match('/^[a-zA-Z0-9._]{1,30}$/', $username)) error('Invalid username'); -if (!$score) - error('You failed the game'); + foreach (listBoards() as $i => $board) { if ($board['uri'] == $uri) error('Board already exists!'); @@ -64,12 +103,13 @@ foreach ($bannedWords as $i => $w) { error("Cannot create board matching banned pattern $w"); } } -$query = prepare('SELECT * FROM ``mods``'); +$query = prepare('SELECT ``username`` FROM ``mods`` WHERE ``username`` = :username'); +$query->bindValue(':username', $username); $query->execute() or error(db_error($query)); $users = $query->fetchAll(PDO::FETCH_ASSOC); -foreach ($users as $i => $user) { - if ($user['username'] == $username) - error('Username taken!'); + +if (sizeof($users) > 0){ +error('The username you\'ve tried to enter already exists!'); } $salt = generate_salt(); @@ -112,9 +152,10 @@ $body = <<Make sure you don't forget your password, {$_POST['password']}!

-

You can manage your site at http://8chan.co/mod.php?/.

+

You can manage your board at http://8chan.co/mod.php?/.

EOT; echo Element("page.html", array("config" => $config, "body" => $body, "title" => "Success", "subtitle" => "This was a triumph")); } +?> diff --git a/expire.php b/expire.php index 8e822852..17356ac4 100644 --- a/expire.php +++ b/expire.php @@ -130,6 +130,10 @@ foreach($delete as $i => $d){ // Delete entire board directory rrmdir($board['uri'] . '/'); rrmdir('static/banners/' . $board['uri']); + // HAAAAAX + if($config['dir']['img_root'] != '') + rrmdir($config['dir']['img_root'] . $board['uri']); + cache::delete('board_' . $board['uri']); _syslog(LOG_NOTICE, "Board deleted: {$board['uri']}"); diff --git a/inc/api.php b/inc/api.php index a8ae9eed..a140cd7e 100644 --- a/inc/api.php +++ b/inc/api.php @@ -41,8 +41,8 @@ class Api { ); $this->fileFields = array( - 'thumbheight' => 'tn_w', - 'thumbwidth' => 'tn_h', + 'thumbheight' => 'tn_h', + 'thumbwidth' => 'tn_w', 'height' => 'w', 'width' => 'h', 'size' => 'fsize', @@ -113,6 +113,7 @@ class Api { $apiPost['ext'] = substr($file->file, $dotPos); $dotPos = strrpos($file->file, '.'); $apiPost['tim'] = substr($file->file, 0, $dotPos); + //$apiPost['md5'] = base64_encode(md5_file($file->file_path, true)); } return $apiPost; diff --git a/inc/config.php b/inc/config.php index e88f4935..3905f198 100644 --- a/inc/config.php +++ b/inc/config.php @@ -277,8 +277,21 @@ 'no_country' ); + + + /* Uses are you a human to stop automated requests to make boards disabled by default + * if you wish to use 'are you a human' to block automated board creation requests + + * to use AYAH you must enter your 'AYAH_PUBLISHER_KEY' and your 'AYAH_SCORING_KEY' in + * the configuration file for AYAH. The config file for AYAH + * is located in the following directory:'/inc/lib/ayah/ayah_config.php' + */ + $config['ayah_enabled'] = false; + // Enable reCaptcha to make spam even harder. Rarely necessary. $config['recaptcha'] = false; + // Enable reCaptcha on create.php to prevent automated requests. + $config['cbRecaptcha'] = false; // Public and private key pair from https://www.google.com/recaptcha/admin/create $config['recaptcha_public'] = '6LcXTcUSAAAAAKBxyFWIt2SO8jwx4W7wcSMRoN3f'; @@ -1119,6 +1132,12 @@ $config['dir']['thumb'] = 'thumb/'; $config['dir']['res'] = 'res/'; + // Images in a seperate directory - For CDN or media servers + // This is a particularly advanced feature - contact ctrlcctrlv or rails unless you + // really know what you're doing + $config['dir']['img_root'] = ''; + + // For load balancing, having a seperate server (and domain/subdomain) for serving static content is // possible. This can either be a directory or a URL. Defaults to $config['root'] . 'static/'. // $config['dir']['static'] = 'http://static.example.org/'; diff --git a/inc/functions.php b/inc/functions.php index 72c2e974..e127a87d 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -425,12 +425,12 @@ function setupBoard($array) { if (!file_exists($board['dir'])) @mkdir($board['dir'], 0777) or error("Couldn't create " . $board['dir'] . ". Check permissions.", true); - if (!file_exists($board['dir'] . $config['dir']['img'])) - @mkdir($board['dir'] . $config['dir']['img'], 0777) - or error("Couldn't create " . $board['dir'] . $config['dir']['img'] . ". Check permissions.", true); - if (!file_exists($board['dir'] . $config['dir']['thumb'])) - @mkdir($board['dir'] . $config['dir']['thumb'], 0777) - or error("Couldn't create " . $board['dir'] . $config['dir']['img'] . ". Check permissions.", true); + if (!file_exists($config['dir']['img_root'] . $board['dir'] . $config['dir']['img'])) + @mkdir($config['dir']['img_root'] . $board['dir'] . $config['dir']['img'], 0777) + or error("Couldn't create " . $config['dir']['img_root'] . $board['dir'] . $config['dir']['img'] . ". Check permissions.", true); + if (!file_exists($config['dir']['img_root'] . $board['dir'] . $config['dir']['thumb'])) + @mkdir($config['dir']['img_root'] . $board['dir'] . $config['dir']['thumb'], 0777) + or error("Couldn't create " . $config['dir']['img_root'] . $board['dir'] . $config['dir']['img'] . ". Check permissions.", true); if (!file_exists($board['dir'] . $config['dir']['res'])) @mkdir($board['dir'] . $config['dir']['res'], 0777) or error("Couldn't create " . $board['dir'] . $config['dir']['img'] . ". Check permissions.", true); @@ -997,11 +997,11 @@ function deleteFile($id, $remove_entirely_if_already=true, $file=null) { foreach ($files as $i => $f) { if (($file !== false && $i == $file) || $file === null) { // Delete thumbnail - file_unlink($board['dir'] . $config['dir']['thumb'] . $f->thumb); + file_unlink($config['dir']['img_root'] . $board['dir'] . $config['dir']['thumb'] . $f->thumb); unset($files[$i]->thumb); // Delete file - file_unlink($board['dir'] . $config['dir']['img'] . $f->file); + file_unlink($config['dir']['img_root'] . $board['dir'] . $config['dir']['img'] . $f->file); $files[$i]->file = 'deleted'; } } @@ -1080,8 +1080,8 @@ function deletePost($id, $error_if_doesnt_exist=true, $rebuild_after=true) { // Delete file foreach (json_decode($post['files']) as $i => $f) { if ($f->file !== 'deleted') { - file_unlink($board['dir'] . $config['dir']['img'] . $f->file); - file_unlink($board['dir'] . $config['dir']['thumb'] . $f->thumb); + file_unlink($config['dir']['img_root'] . $board['dir'] . $config['dir']['img'] . $f->file); + file_unlink($config['dir']['img_root'] . $board['dir'] . $config['dir']['thumb'] . $f->thumb); } } } diff --git a/inc/instance-config.php b/inc/instance-config.php index 96cc3c1c..5d7f7823 100644 --- a/inc/instance-config.php +++ b/inc/instance-config.php @@ -41,6 +41,7 @@ $config['allow_no_country'] = true; $config['thread_subject_in_title'] = true; $config['spam']['hidden_inputs_max_pass'] = 128; + $config['ayah_enabled'] = true; include "secrets.php"; diff --git a/inc/mod/pages.php b/inc/mod/pages.php index f7ccf1a6..21e7c248 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -429,6 +429,9 @@ function mod_edit_board($boardName) { // Delete entire board directory rrmdir($board['uri'] . '/'); + // To reiterate: HAAAAAX + if($config['dir']['img_root'] != '') + rrmdir($config['dir']['img_root'] . $board['uri']); } else { $query = prepare('UPDATE ``boards`` SET `title` = :title, `subtitle` = :subtitle WHERE `uri` = :uri'); $query->bindValue(':uri', $board['uri']); @@ -1121,8 +1124,8 @@ function mod_move_reply($originBoard, $postID) { $post['files'] = json_decode($post['files'], TRUE); $post['has_file'] = true; foreach ($post['files'] as $i => &$file) { - $file['file_path'] = sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $file['file']; - $file['thumb_path'] = sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $file['thumb']; + $file['file_path'] = sprintf($config['board_path'], $config['dir']['img_root'] . $board['uri']) . $config['dir']['img'] . $file['file']; + $file['thumb_path'] = sprintf($config['board_path'], $config['dir']['img_root'] . $board['uri']) . $config['dir']['thumb'] . $file['thumb']; } } else { $post['has_file'] = false; @@ -1140,9 +1143,9 @@ function mod_move_reply($originBoard, $postID) { if ($post['has_file']) { foreach ($post['files'] as $i => &$file) { // move the image - rename($file['file_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $file['file']); + rename($file['file_path'], sprintf($config['board_path'], $config['dir']['img_root'] . $board['uri']) . $config['dir']['img'] . $file['file']); if ($file['thumb'] != 'spoiler') { //trying to move/copy the spoiler thumb raises an error - rename($file['thumb_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $file['thumb']); + rename($file['thumb_path'], sprintf($config['board_path'], $config['dir']['img_root'] . $board['uri']) . $config['dir']['thumb'] . $file['thumb']); } } } @@ -1222,8 +1225,8 @@ function mod_move($originBoard, $postID) { foreach ($post['files'] as $i => &$file) { if ($file['file'] === 'deleted') continue; - $file['file_path'] = sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $file['file']; - $file['thumb_path'] = sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $file['thumb']; + $file['file_path'] = sprintf($config['board_path'], $config['dir']['img_root'] . $board['uri']) . $config['dir']['img'] . $file['file']; + $file['thumb_path'] = sprintf($config['board_path'], $config['dir']['img_root'] . $board['uri']) . $config['dir']['thumb'] . $file['thumb']; } } else { $post['has_file'] = false; @@ -1242,9 +1245,9 @@ function mod_move($originBoard, $postID) { // copy image foreach ($post['files'] as $i => &$file) { if ($file['file'] !== 'deleted') - $clone($file['file_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $file['file']); + $clone($file['file_path'], sprintf($config['board_path'], $config['dir']['img_root'] . $board['uri']) . $config['dir']['img'] . $file['file']); if (isset($file['thumb']) && !in_array($file['thumb'], array('spoiler', 'deleted', 'file'))) - $clone($file['thumb_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $file['thumb']); + $clone($file['thumb_path'], sprintf($config['board_path'], $config['dir']['img_root'] . $board['uri']) . $config['dir']['thumb'] . $file['thumb']); } } @@ -1265,8 +1268,8 @@ function mod_move($originBoard, $postID) { $post['files'] = json_decode($post['files'], TRUE); $post['has_file'] = true; foreach ($post['files'] as $i => &$file) { - $file['file_path'] = sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $file['file']; - $file['thumb_path'] = sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $file['thumb']; + $file['file_path'] = sprintf($config['board_path'], $config['dir']['img_root'] . $board['uri']) . $config['dir']['img'] . $file['file']; + $file['thumb_path'] = sprintf($config['board_path'], $config['dir']['img_root'] . $board['uri']) . $config['dir']['thumb'] . $file['thumb']; } } else { $post['has_file'] = false; @@ -1305,8 +1308,8 @@ function mod_move($originBoard, $postID) { if ($post['has_file']) { // copy image foreach ($post['files'] as $i => &$file) { - $clone($file['file_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $file['file']); - $clone($file['thumb_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $file['thumb']); + $clone($file['file_path'], sprintf($config['board_path'], $config['dir']['img_root'] . $board['uri']) . $config['dir']['img'] . $file['file']); + $clone($file['thumb_path'], sprintf($config['board_path'], $config['dir']['img_root'] . $board['uri']) . $config['dir']['thumb'] . $file['thumb']); } } // insert reply @@ -1582,7 +1585,7 @@ function mod_spoiler_image($board, $post, $file) { $result = $query->fetch(PDO::FETCH_ASSOC); $files = json_decode($result['files']); - file_unlink($board . '/' . $config['dir']['thumb'] . $files[$file]->thumb); + file_unlink($config['dir']['img_root'] . $board . '/' . $config['dir']['thumb'] . $files[$file]->thumb); $files[$file]->thumb = 'spoiler'; $files[$file]->thumbheight = 128; $files[$file]->thumbwidth = 128; @@ -1799,12 +1802,25 @@ function mod_user($uid) { $log = array(); } + if ($mod['type'] >= ADMIN){ + $boards = listBoards(); + } else { + $boards2 = explode(',', $user['boards']); + + foreach($boards2 as $string){ + + $boards[] = array("uri"=>$string, "title"=>"MY BOARD"); + + } + + + } $user['boards'] = explode(',', $user['boards']); mod_page(_('Edit user'), 'mod/user.html', array( 'user' => $user, 'logs' => $log, - 'boards' => listBoards(), + 'boards' => $boards, 'token' => make_secure_link_token('users/' . $user['id']) )); } diff --git a/install.sql b/install.sql index 969107a2..b8d95444 100644 --- a/install.sql +++ b/install.sql @@ -68,6 +68,11 @@ CREATE TABLE IF NOT EXISTS `boards` ( PRIMARY KEY (`uri`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4; +CREATE TABLE IF NOT EXISTS `board_create` ( + `time` text NOT NULL, + `uri` text NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + -- -- Dumping data for table `boards` -- @@ -220,6 +225,7 @@ CREATE TABLE IF NOT EXISTS `reports` ( `board` varchar(58) CHARACTER SET utf8 DEFAULT NULL, `post` int(11) NOT NULL, `reason` text NOT NULL, + `global` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1 ; diff --git a/js/auto-reload.js b/js/auto-reload.js index 535b9a04..583a43e8 100644 --- a/js/auto-reload.js +++ b/js/auto-reload.js @@ -16,8 +16,16 @@ * */ + +au = false; auto_reload_enabled = true; // for watch.js to interop +function makeIcon(){ + if(au) return; + au = true; + $("link[rel='icon']").attr("href", "../static/favicon_au.png"); +} + $(document).ready(function(){ if($('div.banner').length == 0) return; // not index @@ -98,6 +106,7 @@ $(document).ready(function(){ if($('#' + id).length == 0) { if (!new_posts) { first_new_post = this; + makeIcon(); } $(this).insertAfter($('div.post:last').next()).after('
'); new_posts++; diff --git a/js/quick-post-controls.js b/js/quick-post-controls.js index 10d74f98..4e8df1cb 100644 --- a/js/quick-post-controls.js +++ b/js/quick-post-controls.js @@ -34,6 +34,10 @@ $(document).ready(function(){ '
' + + '[' + + '' + + '] ' + + ': ' + '' + ' ' + diff --git a/post.php b/post.php index 88189572..87b53fc6 100644 --- a/post.php +++ b/post.php @@ -445,8 +445,8 @@ if (isset($_POST['delete'])) { if (sizeof($_FILES) > 1) $file['file_id'] .= "-$i"; - $file['file'] = $board['dir'] . $config['dir']['img'] . $file['file_id'] . '.' . $file['extension']; - $file['thumb'] = $board['dir'] . $config['dir']['thumb'] . $file['file_id'] . '.' . ($config['thumb_ext'] ? $config['thumb_ext'] : $file['extension']); + $file['file'] = $config['dir']['img_root'] . $board['dir'] . $config['dir']['img'] . $file['file_id'] . '.' . $file['extension']; + $file['thumb'] = $config['dir']['img_root'] . $board['dir'] . $config['dir']['thumb'] . $file['file_id'] . '.' . ($config['thumb_ext'] ? $config['thumb_ext'] : $file['extension']); $post['files'][] = $file; $i++; } @@ -771,9 +771,9 @@ if (isset($_POST['delete'])) { foreach ($post['files'] as $key => &$file) { $file['file_path'] = $file['file']; $file['thumb_path'] = $file['thumb']; - $file['file'] = mb_substr($file['file'], mb_strlen($board['dir'] . $config['dir']['img'])); + $file['file'] = mb_substr($file['file'], mb_strlen($config['dir']['img_root'] . $board['dir'] . $config['dir']['img'])); if ($file['is_an_image'] && $file['thumb'] != 'spoiler') - $file['thumb'] = mb_substr($file['thumb'], mb_strlen($board['dir'] . $config['dir']['thumb'])); + $file['thumb'] = mb_substr($file['thumb'], mb_strlen($config['dir']['img_root'] . $board['dir'] . $config['dir']['thumb'])); } } diff --git a/random.php b/random.php index 050b6c82..f930d073 100644 --- a/random.php +++ b/random.php @@ -2,7 +2,9 @@ include "inc/functions.php"; -$boards = listBoards(); +$boards = listBoards(true); $board = array_rand($boards); -header('Location: /'.$boards[$board]["uri"]); +header('Location: /'.$boards[$board]); + +?> diff --git a/search.php b/search.php index 394aa3ff..71f4ae5e 100644 --- a/search.php +++ b/search.php @@ -15,7 +15,7 @@ $boards = listBoards(TRUE); } - $body = Element('search_form.html', Array('boards' => $boards, 'board' => isset($_GET['board']) ? $_GET['board'] : false, 'search' => isset($_GET['search']) ? str_replace('"', '"', utf8tohtml($_GET['search'])) : false)); + $body = Element('search_form.html', Array('boards' => $boards, 'b' => isset($_GET['board']) ? $_GET['board'] : false, 'search' => isset($_GET['search']) ? str_replace('"', '"', utf8tohtml($_GET['search'])) : false)); if(isset($_GET['search']) && !empty($_GET['search']) && isset($_GET['board']) && in_array($_GET['board'], $boards)) { $phrase = $_GET['search']; diff --git a/templates/report_delete.html b/templates/report_delete.html index fc3ea8b4..d5d0debe 100644 --- a/templates/report_delete.html +++ b/templates/report_delete.html @@ -9,6 +9,6 @@
- [] + []