diff --git a/inc/anti-bot.php b/inc/anti-bot.php index d2b6d467..b6be5e60 100644 --- a/inc/anti-bot.php +++ b/inc/anti-bot.php @@ -9,7 +9,6 @@ defined('TINYBOARD') or exit; $hidden_inputs_twig = array(); $logfile = "/tmp/lainchan_err.out"; -file_put_contents($logfile, "\n\nSTART\n\n", FILE_APPEND); function print_err($s) { // global $logfile; @@ -20,6 +19,8 @@ function print_err2($s) { print_err($s); } +print_err("\n\nSTART\n\n"); + class AntiBot { public $salt, $inputs = array(), $index = 0; diff --git a/inc/instance-config.php b/inc/instance-config.php index ce25a6b1..14aa4e1b 100644 --- a/inc/instance-config.php +++ b/inc/instance-config.php @@ -122,6 +122,89 @@ $config['allowed_ext_files'][] = 'txt'; $config['allowed_ext_files'][] = 'zip'; $config['allowed_ext_files'][] = 'epub'; +/* + * Flags + */ +$config['country_flags_condensed'] = false; +$config['user_flag'] = true; +$config['flag_style'] = 'width:auto;height:11px;'; +$config['user_flags'] = array ( + '4th_international' => '4th International', + 'acceleration' => 'Acceleration', + 'ak-47' => 'AK-47', + 'albania' => 'Albania', + 'allende' => 'Allende', + 'anarcha-feminism' => 'Anarcha-Feminism', + 'anarchism' => 'Anarchism', + 'anarcho-capitalism' => 'Anarcho-Capitalism', + 'anarcho-communism' => 'Anarcho-Communism', + 'anarcho-nihilism' => 'Anarcho-Nihilism', + 'anarcho-primitivism' => 'Anarcho-Primitivism', + 'athiesm' => 'Athiesm', + 'bolshevik' => 'Bolshevik', + 'brocialism' => 'Brocialism', + 'burkina_faso' => 'Burkina Faso', + 'chavismo' => 'Chavismo', + 'che' => 'Che', + 'china' => 'China', + 'christian_communism' => 'Christian Communism', + 'cockshott' => 'Cockshott', + 'cuba' => 'Cuba', + 'ddr' => 'DDR', + 'democrap' => 'Democrap', + 'democratic_socialism' => 'Democratic Socialism', + 'dprk' => 'DPRK', + 'eurocommunism' => 'Eurocommunism', + 'fed' => 'Fed', + 'freud' => 'Freud', + 'gadsden' => 'Gadsden', + 'gay_nazi' => 'Gay Nazi', + 'gentoo' => 'Gentoo', + 'gorro' => 'Gorro', + 'groucho_marxism' => 'Groucho Marxism', + 'hammer_&_sickle' => 'Hammer & Sickle', + 'international_brigade' => 'International Brigade', + 'ira' => 'IRA', + 'islamic_communism' => 'Islamic Communism', + 'iww' => 'IWW', + 'juche' => 'Juche', + 'kampuchea' => 'Kampuchea', + 'left_communism' => 'Left Communism', + 'lenin_cap' => 'Lenin Cap', + 'luxemburg' => 'Luxemburg', + 'marx' => 'Marx', + 'mutualism' => 'Mutualism', + 'naxalite' => 'Naxalite', + 'nazbol' => 'Nazbol', + 'nazi' => 'Nazi', + 'ndfp' => 'NDFP', + 'palestine' => 'Palestine', + 'pan-africanism' => 'Pan-Africanism', + 'pirate' => 'Pirate', + 'porky' => 'Porky', + 'posadas' => 'Posadas', + 'punk' => 'Punk', + 'raised_fist' => 'Raised Fist', + 'read_a_fucking_book' => 'Read a Fucking Book', + 'rethuglican' => 'Rethuglican', + 'sabo-tabby' => 'Sabo-Tabby', + 'sandinista' => 'Sandinista', + 'sendero_luminoso' => 'Sendero Luminoso', + 'slavoj' => 'Slavoj', + 'socialism' => 'Socialism', + 'soviet_union' => 'Soviet Union', + 'spurdo' => 'Spurdo', + 'ssnp' => 'SSNP', + 'stalin' => 'Stalin', + 'syndicalism' => 'Syndicalism', + 'tankie' => 'Tankie', + 'think' => 'Think', + 'viet_cong' => 'Viet Cong', + 'yugoslavia' => 'Yugoslavia', + 'zapatista' => 'Zapatista', + 'ca' => 'Canadien' +); + // Changes made via web editor by "krates" @ Tue, 22 Dec 2020 16:28:45 -0800: $config['robot_mute'] = false; diff --git a/post.php b/post.php index cf4df990..e4f2a63f 100644 --- a/post.php +++ b/post.php @@ -9,341 +9,341 @@ require_once 'inc/bans.php'; // Fix for magic quotes if (get_magic_quotes_gpc()) { - function strip_array($var) { - return is_array($var) ? array_map('strip_array', $var) : stripslashes($var); - } - - $_GET = strip_array($_GET); - $_POST = strip_array($_POST); + function strip_array($var) { + return is_array($var) ? array_map('strip_array', $var) : stripslashes($var); + } + + $_GET = strip_array($_GET); + $_POST = strip_array($_POST); } $dropped_post = false; function handle_nntpchan() { - global $config; - if ($_SERVER['REMOTE_ADDR'] != $config['nntpchan']['trusted_peer']) { - error("NNTPChan: Forbidden. $_SERVER[REMOTE_ADDR] is not a trusted peer"); - } - - $_POST = array(); - $_POST['json_response'] = true; - - $headers = json_encode($_GET); - - if (!isset ($_GET['Message-Id'])) { - if (!isset ($_GET['Message-ID'])) { - error("NNTPChan: No message ID"); - } - else $msgid = $_GET['Message-ID']; - } - else $msgid = $_GET['Message-Id']; - - $groups = preg_split("/,\s*/", $_GET['Newsgroups']); - if (count($groups) != 1) { - error("NNTPChan: Messages can go to only one newsgroup"); - } - $group = $groups[0]; - - if (!isset($config['nntpchan']['dispatch'][$group])) { - error("NNTPChan: We don't synchronize $group"); - } - $xboard = $config['nntpchan']['dispatch'][$group]; - - $ref = null; - if (isset ($_GET['References'])) { - $refs = preg_split("/,\s*/", $_GET['References']); - - if (count($refs) > 1) { - error("NNTPChan: We don't support multiple references"); - } - - $ref = $refs[0]; - - $query = prepare("SELECT `board`,`id` FROM ``nntp_references`` WHERE `message_id` = :ref"); - $query->bindValue(':ref', $ref); - $query->execute() or error(db_error($query)); - - $ary = $query->fetchAll(PDO::FETCH_ASSOC); - - if (count($ary) == 0) { - error("NNTPChan: We don't have $ref that $msgid references"); - } - - $p_id = $ary[0]['id']; - $p_board = $ary[0]['board']; - - if ($p_board != $xboard) { - error("NNTPChan: Cross board references not allowed. Tried to reference $p_board on $xboard"); - } - - $_POST['thread'] = $p_id; - } - - $date = isset($_GET['Date']) ? strtotime($_GET['Date']) : time(); - - list($ct) = explode('; ', $_GET['Content-Type']); - - $query = prepare("SELECT COUNT(*) AS `c` FROM ``nntp_references`` WHERE `message_id` = :msgid"); - $query->bindValue(":msgid", $msgid); - $query->execute() or error(db_error($query)); - - $a = $query->fetch(PDO::FETCH_ASSOC); - if ($a['c'] > 0) { - error("NNTPChan: We already have this post. Post discarded."); - } - - if ($ct == 'text/plain') { - $content = file_get_contents("php://input"); - } - elseif ($ct == 'multipart/mixed' || $ct == 'multipart/form-data') { - _syslog(LOG_INFO, "MM: Files: ".print_r($GLOBALS, true)); // Debug - - $content = ''; - - $newfiles = array(); - foreach ($_FILES['attachment']['error'] as $id => $error) { - if ($_FILES['attachment']['type'][$id] == 'text/plain') { - $content .= file_get_contents($_FILES['attachment']['tmp_name'][$id]); - } - elseif ($_FILES['attachment']['type'][$id] == 'message/rfc822') { // Signed message, ignore for now - } - else { // A real attachment :^) - $file = array(); - $file['name'] = $_FILES['attachment']['name'][$id]; - $file['type'] = $_FILES['attachment']['type'][$id]; - $file['size'] = $_FILES['attachment']['size'][$id]; - $file['tmp_name'] = $_FILES['attachment']['tmp_name'][$id]; - $file['error'] = $_FILES['attachment']['error'][$id]; - - $newfiles["file$id"] = $file; - } - } - - $_FILES = $newfiles; - } - else { - error("NNTPChan: Wrong mime type: $ct"); - } - - $_POST['subject'] = isset($_GET['Subject']) ? ($_GET['Subject'] == 'None' ? '' : $_GET['Subject']) : ''; - $_POST['board'] = $xboard; - - if (isset ($_GET['From'])) { - list($name, $mail) = explode(" <", $_GET['From'], 2); - $mail = preg_replace('/>\s+$/', '', $mail); - - $_POST['name'] = $name; - //$_POST['email'] = $mail; - $_POST['email'] = ''; - } - - if (isset ($_GET['X_Sage'])) { - $_POST['email'] = 'sage'; - } - - $content = preg_replace_callback('/>>([0-9a-fA-F]{6,})/', function($id) use ($xboard) { - $id = $id[1]; - - $query = prepare("SELECT `board`,`id` FROM ``nntp_references`` WHERE `message_id_digest` LIKE :rule"); - $idx = $id . "%"; - $query->bindValue(':rule', $idx); - $query->execute() or error(db_error($query)); - - $ary = $query->fetchAll(PDO::FETCH_ASSOC); - if (count($ary) == 0) { - return ">>>>$id"; - } - else { - $ret = array(); - foreach ($ary as $v) { - if ($v['board'] != $xboard) { - $ret[] = ">>>/".$v['board']."/".$v['id']; - } - else { - $ret[] = ">>".$v['id']; - } - } - return implode($ret, ", "); - } - }, $content); - - $_POST['body'] = $content; - - $dropped_post = array( - 'date' => $date, - 'board' => $xboard, - 'msgid' => $msgid, - 'headers' => $headers, - 'from_nntp' => true, - ); - + global $config; + if ($_SERVER['REMOTE_ADDR'] != $config['nntpchan']['trusted_peer']) { + error("NNTPChan: Forbidden. $_SERVER[REMOTE_ADDR] is not a trusted peer"); + } + + $_POST = array(); + $_POST['json_response'] = true; + + $headers = json_encode($_GET); + + if (!isset ($_GET['Message-Id'])) { + if (!isset ($_GET['Message-ID'])) { + error("NNTPChan: No message ID"); + } + else $msgid = $_GET['Message-ID']; + } + else $msgid = $_GET['Message-Id']; + + $groups = preg_split("/,\s*/", $_GET['Newsgroups']); + if (count($groups) != 1) { + error("NNTPChan: Messages can go to only one newsgroup"); + } + $group = $groups[0]; + + if (!isset($config['nntpchan']['dispatch'][$group])) { + error("NNTPChan: We don't synchronize $group"); + } + $xboard = $config['nntpchan']['dispatch'][$group]; + + $ref = null; + if (isset ($_GET['References'])) { + $refs = preg_split("/,\s*/", $_GET['References']); + + if (count($refs) > 1) { + error("NNTPChan: We don't support multiple references"); + } + + $ref = $refs[0]; + + $query = prepare("SELECT `board`,`id` FROM ``nntp_references`` WHERE `message_id` = :ref"); + $query->bindValue(':ref', $ref); + $query->execute() or error(db_error($query)); + + $ary = $query->fetchAll(PDO::FETCH_ASSOC); + + if (count($ary) == 0) { + error("NNTPChan: We don't have $ref that $msgid references"); + } + + $p_id = $ary[0]['id']; + $p_board = $ary[0]['board']; + + if ($p_board != $xboard) { + error("NNTPChan: Cross board references not allowed. Tried to reference $p_board on $xboard"); + } + + $_POST['thread'] = $p_id; + } + + $date = isset($_GET['Date']) ? strtotime($_GET['Date']) : time(); + + list($ct) = explode('; ', $_GET['Content-Type']); + + $query = prepare("SELECT COUNT(*) AS `c` FROM ``nntp_references`` WHERE `message_id` = :msgid"); + $query->bindValue(":msgid", $msgid); + $query->execute() or error(db_error($query)); + + $a = $query->fetch(PDO::FETCH_ASSOC); + if ($a['c'] > 0) { + error("NNTPChan: We already have this post. Post discarded."); + } + + if ($ct == 'text/plain') { + $content = file_get_contents("php://input"); + } + elseif ($ct == 'multipart/mixed' || $ct == 'multipart/form-data') { + _syslog(LOG_INFO, "MM: Files: ".print_r($GLOBALS, true)); // Debug + + $content = ''; + + $newfiles = array(); + foreach ($_FILES['attachment']['error'] as $id => $error) { + if ($_FILES['attachment']['type'][$id] == 'text/plain') { + $content .= file_get_contents($_FILES['attachment']['tmp_name'][$id]); + } + elseif ($_FILES['attachment']['type'][$id] == 'message/rfc822') { // Signed message, ignore for now + } + else { // A real attachment :^) + $file = array(); + $file['name'] = $_FILES['attachment']['name'][$id]; + $file['type'] = $_FILES['attachment']['type'][$id]; + $file['size'] = $_FILES['attachment']['size'][$id]; + $file['tmp_name'] = $_FILES['attachment']['tmp_name'][$id]; + $file['error'] = $_FILES['attachment']['error'][$id]; + + $newfiles["file$id"] = $file; + } + } + + $_FILES = $newfiles; + } + else { + error("NNTPChan: Wrong mime type: $ct"); + } + + $_POST['subject'] = isset($_GET['Subject']) ? ($_GET['Subject'] == 'None' ? '' : $_GET['Subject']) : ''; + $_POST['board'] = $xboard; + + if (isset ($_GET['From'])) { + list($name, $mail) = explode(" <", $_GET['From'], 2); + $mail = preg_replace('/>\s+$/', '', $mail); + + $_POST['name'] = $name; + //$_POST['email'] = $mail; + $_POST['email'] = ''; + } + + if (isset ($_GET['X_Sage'])) { + $_POST['email'] = 'sage'; + } + + $content = preg_replace_callback('/>>([0-9a-fA-F]{6,})/', function($id) use ($xboard) { + $id = $id[1]; + + $query = prepare("SELECT `board`,`id` FROM ``nntp_references`` WHERE `message_id_digest` LIKE :rule"); + $idx = $id . "%"; + $query->bindValue(':rule', $idx); + $query->execute() or error(db_error($query)); + + $ary = $query->fetchAll(PDO::FETCH_ASSOC); + if (count($ary) == 0) { + return ">>>>$id"; + } + else { + $ret = array(); + foreach ($ary as $v) { + if ($v['board'] != $xboard) { + $ret[] = ">>>/".$v['board']."/".$v['id']; + } + else { + $ret[] = ">>".$v['id']; + } + } + return implode($ret, ", "); + } + }, $content); + + $_POST['body'] = $content; + + $dropped_post = array( + 'date' => $date, + 'board' => $xboard, + 'msgid' => $msgid, + 'headers' => $headers, + 'from_nntp' => true, + ); + } function handle_delete(){ - // Delete - global $config,$board; - if (!isset($_POST['board'], $_POST['password'])) - error($config['error']['bot']); - - $password = &$_POST['password']; - - if ($password == '') - error($config['error']['invalidpassword']); - - $delete = array(); - foreach ($_POST as $post => $value) { - if (preg_match('/^delete_(\d+)$/', $post, $m)) { - $delete[] = (int)$m[1]; - } - } - - checkDNSBL(); - - // Check if board exists - if (!openBoard($_POST['board'])) - error($config['error']['noboard']); - - // Check if banned - checkBan($board['uri']); - - // Check if deletion enabled - if (!$config['allow_delete']) - error(_('Post deletion is not allowed!')); - - if (empty($delete)) - error($config['error']['nodelete']); - - foreach ($delete as &$id) { - $query = prepare(sprintf("SELECT `thread`, `time`,`password` FROM ``posts_%s`` WHERE `id` = :id", $board['uri'])); - $query->bindValue(':id', $id, PDO::PARAM_INT); - $query->execute() or error(db_error($query)); - - if ($post = $query->fetch(PDO::FETCH_ASSOC)) { - $thread = false; - if ($config['user_moderation'] && $post['thread']) { - $thread_query = prepare(sprintf("SELECT `time`,`password` FROM ``posts_%s`` WHERE `id` = :id", $board['uri'])); - $thread_query->bindValue(':id', $post['thread'], PDO::PARAM_INT); - $thread_query->execute() or error(db_error($query)); - - $thread = $thread_query->fetch(PDO::FETCH_ASSOC); - } - - if ($password != '' && $post['password'] != $password && (!$thread || $thread['password'] != $password)) - error($config['error']['invalidpassword']); - - if ($post['time'] > time() - $config['delete_time'] && (!$thread || $thread['password'] != $password)) { - error(sprintf($config['error']['delete_too_soon'], until($post['time'] + $config['delete_time']))); - } - - if (isset($_POST['file'])) { - // Delete just the file - deleteFile($id); - modLog("User deleted file from his own post #$id"); - } else { - // Delete entire post - deletePost($id); - modLog("User deleted his own post #$id"); - } - - _syslog(LOG_INFO, 'Deleted post: ' . - '/' . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $id) . ($post['thread'] ? '#' . $id : '') - ); - } - } - - buildIndex(); - - $is_mod = isset($_POST['mod']) && $_POST['mod']; - $root = $is_mod ? $config['root'] . $config['file_mod'] . '?/' : $config['root']; - - if (!isset($_POST['json_response'])) { - header('Location: ' . $root . $board['dir'] . $config['file_index'], true, $config['redirect_http']); - } else { - header('Content-Type: text/json'); - echo json_encode(array('success' => true)); - } + // Delete + global $config,$board; + if (!isset($_POST['board'], $_POST['password'])) + error($config['error']['bot']); + + $password = &$_POST['password']; + + if ($password == '') + error($config['error']['invalidpassword']); + + $delete = array(); + foreach ($_POST as $post => $value) { + if (preg_match('/^delete_(\d+)$/', $post, $m)) { + $delete[] = (int)$m[1]; + } + } + + checkDNSBL(); + + // Check if board exists + if (!openBoard($_POST['board'])) + error($config['error']['noboard']); + + // Check if banned + checkBan($board['uri']); + + // Check if deletion enabled + if (!$config['allow_delete']) + error(_('Post deletion is not allowed!')); + + if (empty($delete)) + error($config['error']['nodelete']); + + foreach ($delete as &$id) { + $query = prepare(sprintf("SELECT `thread`, `time`,`password` FROM ``posts_%s`` WHERE `id` = :id", $board['uri'])); + $query->bindValue(':id', $id, PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + + if ($post = $query->fetch(PDO::FETCH_ASSOC)) { + $thread = false; + if ($config['user_moderation'] && $post['thread']) { + $thread_query = prepare(sprintf("SELECT `time`,`password` FROM ``posts_%s`` WHERE `id` = :id", $board['uri'])); + $thread_query->bindValue(':id', $post['thread'], PDO::PARAM_INT); + $thread_query->execute() or error(db_error($query)); + + $thread = $thread_query->fetch(PDO::FETCH_ASSOC); + } + + if ($password != '' && $post['password'] != $password && (!$thread || $thread['password'] != $password)) + error($config['error']['invalidpassword']); + + if ($post['time'] > time() - $config['delete_time'] && (!$thread || $thread['password'] != $password)) { + error(sprintf($config['error']['delete_too_soon'], until($post['time'] + $config['delete_time']))); + } + + if (isset($_POST['file'])) { + // Delete just the file + deleteFile($id); + modLog("User deleted file from his own post #$id"); + } else { + // Delete entire post + deletePost($id); + modLog("User deleted his own post #$id"); + } + + _syslog(LOG_INFO, 'Deleted post: ' . + '/' . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $id) . ($post['thread'] ? '#' . $id : '') + ); + } + } + + buildIndex(); + + $is_mod = isset($_POST['mod']) && $_POST['mod']; + $root = $is_mod ? $config['root'] . $config['file_mod'] . '?/' : $config['root']; + + if (!isset($_POST['json_response'])) { + header('Location: ' . $root . $board['dir'] . $config['file_index'], true, $config['redirect_http']); + } else { + header('Content-Type: text/json'); + echo json_encode(array('success' => true)); + } // We are already done, let's continue our heavy-lifting work in the background (if we run off FastCGI) if (function_exists('fastcgi_finish_request')) @fastcgi_finish_request(); - rebuildThemes('post-delete', $board['uri']); + rebuildThemes('post-delete', $board['uri']); } function handle_report(){ - global $config,$board; - if (!isset($_POST['board'], $_POST['reason'])) - error($config['error']['bot']); - - $report = array(); - foreach ($_POST as $post => $value) { - if (preg_match('/^delete_(\d+)$/', $post, $m)) { - $report[] = (int)$m[1]; - } - } - - checkDNSBL(); - - // Check if board exists - if (!openBoard($_POST['board'])) - error($config['error']['noboard']); - - // Check if banned - checkBan($board['uri']); - - if (empty($report)) - error($config['error']['noreport']); - - if (count($report) > $config['report_limit']) - error($config['error']['toomanyreports']); - - if ($config['report_captcha'] && !isset($_POST['captcha_text'], $_POST['captcha_cookie'])) { - error($config['error']['bot']); - } - - if ($config['report_captcha']) { - $resp = file_get_contents($config['captcha']['provider_check'] . "?" . http_build_query([ - 'mode' => 'check', - 'text' => $_POST['captcha_text'], - 'extra' => $config['captcha']['extra'], - 'cookie' => $_POST['captcha_cookie'] - ])); - - if ($resp !== '1') { + global $config,$board; + if (!isset($_POST['board'], $_POST['reason'])) + error($config['error']['bot']); + + $report = array(); + foreach ($_POST as $post => $value) { + if (preg_match('/^delete_(\d+)$/', $post, $m)) { + $report[] = (int)$m[1]; + } + } + + checkDNSBL(); + + // Check if board exists + if (!openBoard($_POST['board'])) + error($config['error']['noboard']); + + // Check if banned + checkBan($board['uri']); + + if (empty($report)) + error($config['error']['noreport']); + + if (count($report) > $config['report_limit']) + error($config['error']['toomanyreports']); + + if ($config['report_captcha'] && !isset($_POST['captcha_text'], $_POST['captcha_cookie'])) { + error($config['error']['bot']); + } + + if ($config['report_captcha']) { + $resp = file_get_contents($config['captcha']['provider_check'] . "?" . http_build_query([ + 'mode' => 'check', + 'text' => $_POST['captcha_text'], + 'extra' => $config['captcha']['extra'], + 'cookie' => $_POST['captcha_cookie'] + ])); + + if ($resp !== '1') { error($config['error']['captcha']); - } - } - - $reason = escape_markup_modifiers($_POST['reason']); - markup($reason); - - foreach ($report as &$id) { - $query = prepare(sprintf("SELECT `id`,`thread` , `body_nomarkup` FROM ``posts_%s`` WHERE `id` = :id", $board['uri'])); - $query->bindValue(':id', $id, PDO::PARAM_INT); - $query->execute() or error(db_error($query)); - - $thread = $query->fetch(PDO::FETCH_ASSOC); - - $error = event('report', array('ip' => $_SERVER['REMOTE_ADDR'], 'board' => $board['uri'], 'post' => $post, 'reason' => $reason, 'link' => link_for($post))); - if ($error) { - error($error); - } - - if ($config['syslog']) - _syslog(LOG_INFO, 'Reported post: ' . - '/' . $board['dir'] . $config['dir']['res'] . link_for($thread) . ($thread['thread'] ? '#' . $id : '') . - ' for "' . $reason . '"' - ); - $query = prepare("INSERT INTO ``reports`` VALUES (NULL, :time, :ip, :board, :post, :reason)"); - $query->bindValue(':time', time(), PDO::PARAM_INT); - $query->bindValue(':ip', $_SERVER['REMOTE_ADDR'], PDO::PARAM_STR); - $query->bindValue(':board', $board['uri'], PDO::PARAM_STR); - $query->bindValue(':post', $id, PDO::PARAM_INT); - $query->bindValue(':reason', $reason, PDO::PARAM_STR); - $query->execute() or error(db_error($query)); + } + } + + $reason = escape_markup_modifiers($_POST['reason']); + markup($reason); + + foreach ($report as &$id) { + $query = prepare(sprintf("SELECT `id`,`thread` , `body_nomarkup` FROM ``posts_%s`` WHERE `id` = :id", $board['uri'])); + $query->bindValue(':id', $id, PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + + $thread = $query->fetch(PDO::FETCH_ASSOC); + + $error = event('report', array('ip' => $_SERVER['REMOTE_ADDR'], 'board' => $board['uri'], 'post' => $post, 'reason' => $reason, 'link' => link_for($post))); + if ($error) { + error($error); + } + + if ($config['syslog']) + _syslog(LOG_INFO, 'Reported post: ' . + '/' . $board['dir'] . $config['dir']['res'] . link_for($thread) . ($thread['thread'] ? '#' . $id : '') . + ' for "' . $reason . '"' + ); + $query = prepare("INSERT INTO ``reports`` VALUES (NULL, :time, :ip, :board, :post, :reason)"); + $query->bindValue(':time', time(), PDO::PARAM_INT); + $query->bindValue(':ip', $_SERVER['REMOTE_ADDR'], PDO::PARAM_STR); + $query->bindValue(':board', $board['uri'], PDO::PARAM_STR); + $query->bindValue(':post', $id, PDO::PARAM_INT); + $query->bindValue(':reason', $reason, PDO::PARAM_STR); + $query->execute() or error(db_error($query)); if ($config['slack']) { @@ -369,1332 +369,1141 @@ function handle_report(){ return $result; } - - $postcontent = mb_substr($thread['body_nomarkup'], 0, 120) . '... _*(POST TRIMMED)*_'; - $slackmessage = '<' .$config['domain'] . "/mod.php?/" . $board['dir'] . $config['dir']['res'] . ( $thread['thread'] ? $thread['thread'] : $id ) . ".html" . ($thread['thread'] ? '#' . $id : '') . '> \n ' . $reason . '\n ' . $postcontent . '\n'; + + $postcontent = mb_substr($thread['body_nomarkup'], 0, 120) . '... _*(POST TRIMMED)*_'; + $slackmessage = '<' .$config['domain'] . "/mod.php?/" . $board['dir'] . $config['dir']['res'] . ( $thread['thread'] ? $thread['thread'] : $id ) . ".html" . ($thread['thread'] ? '#' . $id : '') . '> \n ' . $reason . '\n ' . $postcontent . '\n'; - $slackresult = slack($slackmessage, $config['slack_channel']); + $slackresult = slack($slackmessage, $config['slack_channel']); } - } - - $is_mod = isset($_POST['mod']) && $_POST['mod']; - $root = $is_mod ? $config['root'] . $config['file_mod'] . '?/' : $config['root']; - - if (!isset($_POST['json_response'])) { - $index = $root . $board['dir'] . $config['file_index']; - $reported_post = $root . $board['dir'] . $config['dir']['res'] . ( $thread['thread'] ? $thread['thread'] : $id ) . ".html" . ($thread['thread'] ? '#' . $id : '') ; - //header('Location: ' . $reported_post); + } + + $is_mod = isset($_POST['mod']) && $_POST['mod']; + $root = $is_mod ? $config['root'] . $config['file_mod'] . '?/' : $config['root']; + + if (!isset($_POST['json_response'])) { + $index = $root . $board['dir'] . $config['file_index']; + $reported_post = $root . $board['dir'] . $config['dir']['res'] . ( $thread['thread'] ? $thread['thread'] : $id ) . ".html" . ($thread['thread'] ? '#' . $id : '') ; + //header('Location: ' . $reported_post); echo Element('page.html', array('config' => $config, 'body' => '
[ ' . _('Close window') ." ] [ " . _('Return') . ' ]
', 'title' => _('Report submitted!'))); - } else { - header('Content-Type: text/json'); - echo json_encode(array('success' => true)); - } + } else { + header('Content-Type: text/json'); + echo json_encode(array('success' => true)); + } } -print_err("Hello Top Level"); - function handle_post(){ - global $config,$dropped_post,$board, $mod,$pdo; - - print_err("Hello Debugging"); - - if (!isset($_POST['body'], $_POST['board']) && !$dropped_post) { - print_err("We are a bot 1"); - error($config['error']['bot']); - } - - print_err("Not a bot 1"); - - $post = array('board' => $_POST['board'], 'files' => array()); - - // Check if board exists - if (!openBoard($post['board'])) - error($config['error']['noboard']); - - $board_locked_check = (!isset($_POST['mod']) || !$_POST['mod']) - && ($config['board_locked']===true - || (is_array($config['board_locked']) && in_array(strtolower($_POST['board']), $config['board_locked']))); - - if ($board_locked_check){ - error("Board is locked"); - } - - if (!isset($_POST['name'])) - $_POST['name'] = $config['anonymous']; - - if (!isset($_POST['email'])) - $_POST['email'] = ''; - - if (!isset($_POST['subject'])) - $_POST['subject'] = ''; - - if (!isset($_POST['password'])) - $_POST['password'] = ''; - - if (isset($_POST['thread'])) { - $post['op'] = false; - $post['thread'] = round($_POST['thread']); - } else { - $post['op'] = true; - } - - - if (!$dropped_post) { - print_err("not a dropped post"); - - // Check for CAPTCHA right after opening the board so the "return" link is in there - if ($config['recaptcha']) { - if (!isset($_POST['g-recaptcha-response'])) - error($config['error']['bot']); - // Check what reCAPTCHA has to say... - $resp = json_decode(file_get_contents(sprintf('https://www.google.com/recaptcha/api/siteverify?secret=%s&response=%s&remoteip=%s', - $config['recaptcha_private'], - urlencode($_POST['g-recaptcha-response']), - $_SERVER['REMOTE_ADDR'])), true); - - if (!$resp['success']) { - error($config['error']['captcha']); - } - } - - print_err("pass captcha block"); - - if(isset($config['securimage']) && $config['secureimage']){ - if(!isset($_POST['captcha'])){ - error($config['error']['securimage']['missing']); - } - if(empty($_POST['captcha'])){ - error($config['error']['securimage']['empty']); - } - $query=prepare('DELETE FROM captchas WHERE timebindValue(':ip', $_SERVER['REMOTE_ADDR']); - $query->bindValue(':code', $_POST['captcha']); - $query->execute(); - if($query->rowCount()==0){ - error($config['error']['securimage']['bad']); - } - } - - print_err("pass securimage block"); - - - if (!(($post['op'] && $_POST['post'] == $config['button_newtopic']) || - (!$post['op'] && $_POST['post'] == $config['button_reply']))) { - - print_err("we are a bot 2"); - error($config['error']['bot']); - } - - print_err("we are not a bot 2"); - - // Check the referrer - if ($config['referer_match'] !== false && - (!isset($_SERVER['HTTP_REFERER']) || !preg_match($config['referer_match'], rawurldecode($_SERVER['HTTP_REFERER'])))) { - - print_err("Missing REFERRER"); - print_err($config['referer_match']); - error($config['error']['referer']); - } - - print_err("ReferrerOK"); - - checkDNSBL(); - - // Check if banned - checkBan($board['uri']); - - print_err("Not banned"); - - if ($post['mod'] = isset($_POST['mod']) && $_POST['mod']) { - check_login(false); - if (!$mod) { - // Liar. You're not a mod. - error($config['error']['notamod']); - } - - $post['sticky'] = $post['op'] && isset($_POST['sticky']); - $post['locked'] = $post['op'] && isset($_POST['lock']); - $post['raw'] = isset($_POST['raw']); - - if ($post['sticky'] && !hasPermission($config['mod']['sticky'], $board['uri'])) - error($config['error']['noaccess']); - if ($post['locked'] && !hasPermission($config['mod']['lock'], $board['uri'])) - error($config['error']['noaccess']); - if ($post['raw'] && !hasPermission($config['mod']['rawhtml'], $board['uri'])) - error($config['error']['noaccess']); - } - - print_err("Mod block 1 pass"); - - if (!$post['mod'] && $config['spam']['enabled'] == true) { - $post['antispam_hash'] = checkSpam( - array($board['uri'], - isset($post['thread']) ? $post['thread'] : ($config['try_smarter'] && isset($_POST['page']) ? 0 - (int)$_POST['page'] : null)) - ); - //$post['antispam_hash'] = checkSpam(); - - if ($post['antispam_hash'] === true) { - print_err("Anti spam triggered"); - error($config['error']['spam']); - } - } - - if ($config['robot_enable'] && $config['robot_mute']) { - checkMute(); - } - - print_err("Mod block 2 pass"); - } - else { - $mod = $post['mod'] = false; - } - - print_err("not dropped block pass"); - - //Check if thread exists - if (!$post['op']) { - $query = prepare(sprintf("SELECT `sticky`,`locked`,`cycle`,`sage`,`slug` FROM ``posts_%s`` WHERE `id` = :id AND `thread` IS NULL LIMIT 1", $board['uri'])); - $query->bindValue(':id', $post['thread'], PDO::PARAM_INT); - $query->execute() or error(db_error()); - - if (!$thread = $query->fetch(PDO::FETCH_ASSOC)) { - // Non-existant - error($config['error']['nonexistant']); - } - } - else { - $thread = false; - } - - print_err("check OP ok"); - - - // Check for an embed field - if ($config['enable_embedding'] && isset($_POST['embed']) && !empty($_POST['embed'])) { - // yep; validate it - $value = $_POST['embed']; - foreach ($config['embedding'] as &$embed) { - if (preg_match($embed[0], $value)) { - // Valid link - $post['embed'] = $value; - // This is bad, lol. - $post['no_longer_require_an_image_for_op'] = true; - break; - } - } - if (!isset($post['embed'])) { - error($config['error']['invalid_embed']); - } - } - - print_err("embed field block pass"); - - if (!hasPermission($config['mod']['bypass_field_disable'], $board['uri'])) { - if ($config['field_disable_name']) - $_POST['name'] = $config['anonymous']; // "forced anonymous" - - if ($config['field_disable_email']) - $_POST['email'] = ''; - - if ($config['field_disable_password']) - $_POST['password'] = ''; - - if ($config['field_disable_subject'] || (!$post['op'] && $config['field_disable_reply_subject'])) - $_POST['subject'] = ''; - } - - print_err("mod bypass block ok"); - - if ($config['allow_upload_by_url'] && isset($_POST['file_url1']) && !empty($_POST['file_url1'])) { - function unlink_tmp_file($file) { - @unlink($file); - fatal_error_handler(); - } - - function upload_by_url($config,$post,$url) { - $post['file_url'] = $url; - if (!preg_match('@^https?://@', $post['file_url'])) - error($config['error']['invalidimg']); - - if (mb_strpos($post['file_url'], '?') !== false) - $url_without_params = mb_substr($post['file_url'], 0, mb_strpos($post['file_url'], '?')); - else - $url_without_params = $post['file_url']; - - $post['extension'] = strtolower(mb_substr($url_without_params, mb_strrpos($url_without_params, '.') + 1)); - - if ($post['op'] && $config['allowed_ext_op']) { - if (!in_array($post['extension'], $config['allowed_ext_op'])) - error($config['error']['unknownext']); - } - else if (!in_array($post['extension'], $config['allowed_ext']) && !in_array($post['extension'], $config['allowed_ext_files'])) - error($config['error']['unknownext']); - - $post['file_tmp'] = tempnam($config['tmp'], 'url'); - register_shutdown_function('unlink_tmp_file', $post['file_tmp']); - - $fp = fopen($post['file_tmp'], 'w'); - - $curl = curl_init(); - curl_setopt($curl, CURLOPT_URL, $post['file_url']); - curl_setopt($curl, CURLOPT_FAILONERROR, true); - curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false); - curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5); - curl_setopt($curl, CURLOPT_TIMEOUT, $config['upload_by_url_timeout']); - curl_setopt($curl, CURLOPT_USERAGENT, 'Tinyboard'); - curl_setopt($curl, CURLOPT_BINARYTRANSFER, true); - curl_setopt($curl, CURLOPT_FILE, $fp); - curl_setopt($curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); - curl_setopt($curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); - - if (curl_exec($curl) === false) - error($config['error']['nomove'] . '
Curl says: ' . curl_error($curl)); - - curl_close($curl); - - fclose($fp); - - $_FILES[$post['file_tmp']] = array( - 'name' => basename($url_without_params), - 'tmp_name' => $post['file_tmp'], - 'file_tmp' => true, - 'error' => 0, - 'size' => filesize($post['file_tmp']) - ); - } - - for( $counter = 1; $counter <= $config['max_images']; $counter++ ) { - $varname = "file_url". $counter; - if (isset($_POST[$varname]) && !empty($_POST[$varname])){ - upload_by_url($config,$post,$_POST[$varname]); - } - } - - } - - print_err("allow upload by url block ok"); - - $post['name'] = $_POST['name'] != '' ? $_POST['name'] : $config['anonymous']; - $post['subject'] = $_POST['subject']; - $post['email'] = str_replace(' ', '%20', htmlspecialchars($_POST['email'])); - $post['body'] = $_POST['body']; - $post['password'] = $_POST['password']; - $post['has_file'] = (!isset($post['embed']) && (($post['op'] && !isset($post['no_longer_require_an_image_for_op']) && $config['force_image_op']) || count($_FILES) > 0)); - - print_err("post vars set"); - - if (!$dropped_post) { - print_err("not dropped post"); - - if (!($post['has_file'] || isset($post['embed'])) || (($post['op'] && $config['force_body_op']) || (!$post['op'] && $config['force_body']))) { - if (!$post['has_file']) { - print_err("post has no file"); - } else { - print_err("post has file"); - } - - if (!isset($post['embed'])) { - print_err("post has no embed"); - } else { - print_err("post has embed"); - } - - if (!$post['op']) { - print_err("post is not op"); - } else { - print_err("post is op"); - } - - if (!$config['force_body_op']) { - print_err("force body op is off"); - } else { - print_err("force body op is on"); - } - - if (!$config['force_body']) { - print_err("force body is off"); - } else { - print_err("force body is on"); - } - - print_err("post body:\n" . $post['body']); - $stripped_whitespace = preg_replace('/[\s]/u', '', $post['body']); - - print_err(print_r(preg_last_error(), true)); - if (preg_last_error() == PREG_BAD_UTF8_ERROR) { - print_err("Bad unicode preg error"); - } - - if ($stripped_whitespace == '') { - print_err("error: body too short!"); - error($config['error']['tooshort_body']); - } - } - - if (!$post['op']) { - // Check if thread is locked - // but allow mods to post - if ($thread['locked'] && !hasPermission($config['mod']['postinlocked'], $board['uri'])) { - print_err("error thread locked"); - error($config['error']['locked']); - } - - $numposts = numPosts($post['thread']); - - $replythreshold = isset($thread['cycle']) && $thread['cycle'] ? $numposts['replies'] - 1 : $numposts['replies']; - $imagethreshold = isset($thread['cycle']) && $thread['cycle'] ? $numposts['images'] - 1 : $numposts['images']; - - if ($config['reply_hard_limit'] != 0 && $config['reply_hard_limit'] <= $replythreshold) { - print_err("reply hard limit"); - error($config['error']['reply_hard_limit']); - } - - if ($post['has_file'] && $config['image_hard_limit'] != 0 && $config['image_hard_limit'] <= $imagethreshold) { - print_err("image hard limit"); - error($config['error']['image_hard_limit']); - } - } - } - else { - print_err("dropped post active"); - if (!$post['op']) { - $numposts = numPosts($post['thread']); - } - } - - print_err("Not dropped post block 2 OK"); - - if ($post['has_file']) { - // Determine size sanity - $size = 0; - if ($config['multiimage_method'] == 'split') { - foreach ($_FILES as $key => $file) { - $size += $file['size']; - } - } elseif ($config['multiimage_method'] == 'each') { - foreach ($_FILES as $key => $file) { - if ($file['size'] > $size) { - $size = $file['size']; - } - } - } else { - error(_('Unrecognized file size determination method.')); - } - $max_size = $config['max_filesize']; - - if (array_key_exists('board_specific',$config)){ - if (array_key_exists($board['uri'],$config['board_specific'])){ - if (array_key_exists('max_filesize',$config['board_specific'][$board['uri']])){ - $max_size = $config['board_specific'][$board['uri']]['max_filesize']; - } - } - } - - if ($size > $max_size) - error(sprintf3($config['error']['filesize'], array( - 'sz' => number_format($size), - 'filesz' => number_format($size), - 'maxsz' => number_format($config['max_filesize']) - ))); - $post['filesize'] = $size; - } - - print_err("has File block OK"); - - $post['capcode'] = false; - - if ($mod && preg_match('/^((.+) )?## (.+)$/', $post['name'], $matches)) { - $name = $matches[2] != '' ? $matches[2] : $config['anonymous']; - $cap = $matches[3]; - - if (isset($config['mod']['capcode'][$mod['type']])) { - if ( $config['mod']['capcode'][$mod['type']] === true || - (is_array($config['mod']['capcode'][$mod['type']]) && - in_array($cap, $config['mod']['capcode'][$mod['type']]) - )) { - - $post['capcode'] = utf8tohtml($cap); - $post['name'] = $name; - } - } - } - else if ($config['joke_capcode']) { - if (strtolower($post['email']) == 'joke') { - if (isset($config['joke_capcode_default'])){ - $cap = $config['joke_capcode_default']; - } - else { - $cap = "joke"; - } - $post['capcode'] = utf8tohtml($cap); - $post['email'] = ''; - } - } - - $trip = generate_tripcode($post['name']); - $post['name'] = $trip[0]; - $post['trip'] = isset($trip[1]) ? $trip[1] : ''; // XX: Dropped posts and tripcodes - - $noko = false; - if (strtolower($post['email']) == 'noko') { - $noko = true; - $post['email'] = ''; - } elseif (strtolower($post['email']) == 'nonoko'){ - $noko = false; - $post['email'] = ''; - } else $noko = $config['always_noko']; - - if ($post['has_file']) { - $i = 0; - foreach ($_FILES as $key => $file) { - if ($file['size'] && $file['tmp_name']) { - $file['filename'] = urldecode($file['name']); - $file['extension'] = strtolower(mb_substr($file['filename'], mb_strrpos($file['filename'], '.') + 1)); - if (isset($config['filename_func'])) - $file['file_id'] = $config['filename_func']($file); - else - $file['file_id'] = time() . substr(microtime(), 2, 3); - - 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']); - $post['files'][] = $file; - $i++; - } - } - } - - print_err("has File block 2 OK"); - - if (empty($post['files'])) $post['has_file'] = false; - - if (!$dropped_post) { - // Check for a file - if ($post['op'] && !isset($post['no_longer_require_an_image_for_op'])) { - if (!$post['has_file'] && $config['force_image_op']) { - print_err("error No Image"); - error($config['error']['noimage']); - } - } - - // Check for too many files - if (sizeof($post['files']) > $config['max_images']) { - print_err("Too many images"); - error($config['error']['toomanyimages']); - } - } - - if ($config['strip_combining_chars']) { - $post['name'] = strip_combining_chars($post['name']); - $post['email'] = strip_combining_chars($post['email']); - $post['subject'] = strip_combining_chars($post['subject']); - $post['body'] = strip_combining_chars($post['body']); - } - - print_err("post fields strip"); - - if (!$dropped_post) { - // Check string lengths - if (mb_strlen($post['name']) > 35) { - print_err("name too long"); - error(sprintf($config['error']['toolong'], 'name')); - } - if (mb_strlen($post['email']) > 40) { - print_err("email too long"); - error(sprintf($config['error']['toolong'], 'email')); - } - if (mb_strlen($post['subject']) > 100) { - print_err("subject too long"); - error(sprintf($config['error']['toolong'], 'subject')); - } - if (!$mod && mb_strlen($post['body']) > $config['max_body']) { - print_err("body too long"); - error($config['error']['toolong_body']); - } - if (!$mod && mb_strlen($post['body']) > 0 && (mb_strlen($post['body']) < $config['min_body'])) { - print_err("body too short"); - error($config['error']['tooshort_body']); - } - if (mb_strlen($post['password']) > 20) { - print_err("password too long"); - error(sprintf($config['error']['toolong'], 'password')); - } - } - - print_err("wordfilters"); - - wordfilters($post['body']); - - print_err("Process post body"); - - $post['body'] = escape_markup_modifiers($post['body']); - - print_err("body escaped"); - - if ($mod && isset($post['raw']) && $post['raw']) { - $post['body'] .= "\n1"; - } - - if (!$dropped_post) - if (($config['country_flags'] && !$config['allow_no_country']) || ($config['country_flags'] && $config['allow_no_country'] && !isset($_POST['no_country']))) { - require 'inc/lib/geoip/geoip.inc'; - $gi=geoip\geoip_open('inc/lib/geoip/GeoIPv6.dat', GEOIP_STANDARD); - - function ipv4to6($ip) { - if (strpos($ip, ':') !== false) { - if (strpos($ip, '.') > 0) - $ip = substr($ip, strrpos($ip, ':')+1); - else return $ip; //native ipv6 - } - $iparr = array_pad(explode('.', $ip), 4, 0); - $part7 = base_convert(($iparr[0] * 256) + $iparr[1], 10, 16); - $part8 = base_convert(($iparr[2] * 256) + $iparr[3], 10, 16); - return '::ffff:'.$part7.':'.$part8; - } - - if ($country_code = geoip\geoip_country_code_by_addr_v6($gi, ipv4to6($_SERVER['REMOTE_ADDR']))) { - if (!in_array(strtolower($country_code), array('eu', 'ap', 'o1', 'a1', 'a2'))) - $post['body'] .= "\n".strtolower($country_code)."". - "\n".geoip\geoip_country_name_by_addr_v6($gi, ipv4to6($_SERVER['REMOTE_ADDR'])).""; - } - } - - print_err("flag stuff block OK"); - - if ($config['user_flag'] && isset($_POST['user_flag'])) - if (!empty($_POST['user_flag']) ){ - - $user_flag = $_POST['user_flag']; - - if (!isset($config['user_flags'][$user_flag])) - error(_('Invalid flag selection!')); - - $flag_alt = isset($user_flag_alt) ? $user_flag_alt : $config['user_flags'][$user_flag]; - - $post['body'] .= "\n" . strtolower($user_flag) . "" . - "\n" . $flag_alt . ""; - } - - print_err("user flag block ok"); - - if ($config['allowed_tags'] && $post['op'] && isset($_POST['tag']) && isset($config['allowed_tags'][$_POST['tag']])) { - $post['body'] .= "\n" . $_POST['tag'] . ""; - } - - print_err("allowed tags block ok"); - - if (!$dropped_post) + global $config,$dropped_post,$board, $mod,$pdo; + + if (!isset($_POST['body'], $_POST['board']) && !$dropped_post) { + error($config['error']['bot']); + } + + $post = array('board' => $_POST['board'], 'files' => array()); + + // Check if board exists + if (!openBoard($post['board'])) + error($config['error']['noboard']); + + $board_locked_check = (!isset($_POST['mod']) || !$_POST['mod']) + && ($config['board_locked']===true + || (is_array($config['board_locked']) && in_array(strtolower($_POST['board']), $config['board_locked']))); + + if ($board_locked_check){ + error("Board is locked"); + } + + if (!isset($_POST['name'])) + $_POST['name'] = $config['anonymous']; + + if (!isset($_POST['email'])) + $_POST['email'] = ''; + + if (!isset($_POST['subject'])) + $_POST['subject'] = ''; + + if (!isset($_POST['password'])) + $_POST['password'] = ''; + + if (isset($_POST['thread'])) { + $post['op'] = false; + $post['thread'] = round($_POST['thread']); + } else { + $post['op'] = true; + } + + + if (!$dropped_post) { + // Check for CAPTCHA right after opening the board so the "return" link is in there + if ($config['recaptcha']) { + if (!isset($_POST['g-recaptcha-response'])) + error($config['error']['bot']); + // Check what reCAPTCHA has to say... + $resp = json_decode(file_get_contents(sprintf('https://www.google.com/recaptcha/api/siteverify?secret=%s&response=%s&remoteip=%s', + $config['recaptcha_private'], + urlencode($_POST['g-recaptcha-response']), + $_SERVER['REMOTE_ADDR'])), true); + + if (!$resp['success']) { + error($config['error']['captcha']); + } + } + + if(isset($config['securimage']) && $config['secureimage']){ + if(!isset($_POST['captcha'])){ + error($config['error']['securimage']['missing']); + } + if(empty($_POST['captcha'])){ + error($config['error']['securimage']['empty']); + } + $query=prepare('DELETE FROM captchas WHERE timebindValue(':ip', $_SERVER['REMOTE_ADDR']); + $query->bindValue(':code', $_POST['captcha']); + $query->execute(); + if($query->rowCount()==0){ + error($config['error']['securimage']['bad']); + } + } + + + if (!(($post['op'] && $_POST['post'] == $config['button_newtopic']) || + (!$post['op'] && $_POST['post'] == $config['button_reply']))) { + + error($config['error']['bot']); + } + + // Check the referrer + if ($config['referer_match'] !== false && + (!isset($_SERVER['HTTP_REFERER']) || !preg_match($config['referer_match'], rawurldecode($_SERVER['HTTP_REFERER'])))) { + error($config['error']['referer']); + } + + checkDNSBL(); + + // Check if banned + checkBan($board['uri']); + + if ($post['mod'] = isset($_POST['mod']) && $_POST['mod']) { + check_login(false); + if (!$mod) { + // Liar. You're not a mod. + error($config['error']['notamod']); + } + + $post['sticky'] = $post['op'] && isset($_POST['sticky']); + $post['locked'] = $post['op'] && isset($_POST['lock']); + $post['raw'] = isset($_POST['raw']); + + if ($post['sticky'] && !hasPermission($config['mod']['sticky'], $board['uri'])) + error($config['error']['noaccess']); + if ($post['locked'] && !hasPermission($config['mod']['lock'], $board['uri'])) + error($config['error']['noaccess']); + if ($post['raw'] && !hasPermission($config['mod']['rawhtml'], $board['uri'])) + error($config['error']['noaccess']); + } + + if (!$post['mod'] && $config['spam']['enabled'] == true) { + $post['antispam_hash'] = checkSpam( + array($board['uri'], + isset($post['thread']) ? $post['thread'] : ($config['try_smarter'] && isset($_POST['page']) ? 0 - (int)$_POST['page'] : null)) + ); + //$post['antispam_hash'] = checkSpam(); + + if ($post['antispam_hash'] === true) { + error($config['error']['spam']); + } + } + + if ($config['robot_enable'] && $config['robot_mute']) { + checkMute(); + } + } + else { + $mod = $post['mod'] = false; + } + + //Check if thread exists + if (!$post['op']) { + $query = prepare(sprintf("SELECT `sticky`,`locked`,`cycle`,`sage`,`slug` FROM ``posts_%s`` WHERE `id` = :id AND `thread` IS NULL LIMIT 1", $board['uri'])); + $query->bindValue(':id', $post['thread'], PDO::PARAM_INT); + $query->execute() or error(db_error()); + + if (!$thread = $query->fetch(PDO::FETCH_ASSOC)) { + // Non-existant + error($config['error']['nonexistant']); + } + } + else { + $thread = false; + } + + + // Check for an embed field + if ($config['enable_embedding'] && isset($_POST['embed']) && !empty($_POST['embed'])) { + // yep; validate it + $value = $_POST['embed']; + foreach ($config['embedding'] as &$embed) { + if (preg_match($embed[0], $value)) { + // Valid link + $post['embed'] = $value; + // This is bad, lol. + $post['no_longer_require_an_image_for_op'] = true; + break; + } + } + if (!isset($post['embed'])) { + error($config['error']['invalid_embed']); + } + } + + if (!hasPermission($config['mod']['bypass_field_disable'], $board['uri'])) { + if ($config['field_disable_name']) + $_POST['name'] = $config['anonymous']; // "forced anonymous" + + if ($config['field_disable_email']) + $_POST['email'] = ''; + + if ($config['field_disable_password']) + $_POST['password'] = ''; + + if ($config['field_disable_subject'] || (!$post['op'] && $config['field_disable_reply_subject'])) + $_POST['subject'] = ''; + } + + if ($config['allow_upload_by_url'] && isset($_POST['file_url1']) && !empty($_POST['file_url1'])) { + function unlink_tmp_file($file) { + @unlink($file); + fatal_error_handler(); + } + + function upload_by_url($config,$post,$url) { + $post['file_url'] = $url; + if (!preg_match('@^https?://@', $post['file_url'])) + error($config['error']['invalidimg']); + + if (mb_strpos($post['file_url'], '?') !== false) + $url_without_params = mb_substr($post['file_url'], 0, mb_strpos($post['file_url'], '?')); + else + $url_without_params = $post['file_url']; + + $post['extension'] = strtolower(mb_substr($url_without_params, mb_strrpos($url_without_params, '.') + 1)); + + if ($post['op'] && $config['allowed_ext_op']) { + if (!in_array($post['extension'], $config['allowed_ext_op'])) + error($config['error']['unknownext']); + } + else if (!in_array($post['extension'], $config['allowed_ext']) && !in_array($post['extension'], $config['allowed_ext_files'])) + error($config['error']['unknownext']); + + $post['file_tmp'] = tempnam($config['tmp'], 'url'); + register_shutdown_function('unlink_tmp_file', $post['file_tmp']); + + $fp = fopen($post['file_tmp'], 'w'); + + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, $post['file_url']); + curl_setopt($curl, CURLOPT_FAILONERROR, true); + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false); + curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5); + curl_setopt($curl, CURLOPT_TIMEOUT, $config['upload_by_url_timeout']); + curl_setopt($curl, CURLOPT_USERAGENT, 'Tinyboard'); + curl_setopt($curl, CURLOPT_BINARYTRANSFER, true); + curl_setopt($curl, CURLOPT_FILE, $fp); + curl_setopt($curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); + curl_setopt($curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); + + if (curl_exec($curl) === false) + error($config['error']['nomove'] . '
Curl says: ' . curl_error($curl)); + + curl_close($curl); + + fclose($fp); + + $_FILES[$post['file_tmp']] = array( + 'name' => basename($url_without_params), + 'tmp_name' => $post['file_tmp'], + 'file_tmp' => true, + 'error' => 0, + 'size' => filesize($post['file_tmp']) + ); + } + + for( $counter = 1; $counter <= $config['max_images']; $counter++ ) { + $varname = "file_url". $counter; + if (isset($_POST[$varname]) && !empty($_POST[$varname])){ + upload_by_url($config,$post,$_POST[$varname]); + } + } + + } + + $post['name'] = $_POST['name'] != '' ? $_POST['name'] : $config['anonymous']; + $post['subject'] = $_POST['subject']; + $post['email'] = str_replace(' ', '%20', htmlspecialchars($_POST['email'])); + $post['body'] = $_POST['body']; + $post['password'] = $_POST['password']; + $post['has_file'] = (!isset($post['embed']) && (($post['op'] && !isset($post['no_longer_require_an_image_for_op']) && $config['force_image_op']) || count($_FILES) > 0)); + + if (!$dropped_post) { + if (!($post['has_file'] || isset($post['embed'])) || (($post['op'] && $config['force_body_op']) || (!$post['op'] && $config['force_body']))) { + $stripped_whitespace = preg_replace('/[\s]/u', '', $post['body']); + if ($stripped_whitespace == '') { + error($config['error']['tooshort_body']); + } + } + + if (!$post['op']) { + // Check if thread is locked + // but allow mods to post + if ($thread['locked'] && !hasPermission($config['mod']['postinlocked'], $board['uri'])) { + error($config['error']['locked']); + } + + $numposts = numPosts($post['thread']); + + $replythreshold = isset($thread['cycle']) && $thread['cycle'] ? $numposts['replies'] - 1 : $numposts['replies']; + $imagethreshold = isset($thread['cycle']) && $thread['cycle'] ? $numposts['images'] - 1 : $numposts['images']; + + if ($config['reply_hard_limit'] != 0 && $config['reply_hard_limit'] <= $replythreshold) { + error($config['error']['reply_hard_limit']); + } + + if ($post['has_file'] && $config['image_hard_limit'] != 0 && $config['image_hard_limit'] <= $imagethreshold) { + error($config['error']['image_hard_limit']); + } + } + } + else { + if (!$post['op']) { + $numposts = numPosts($post['thread']); + } + } + + if ($post['has_file']) { + // Determine size sanity + $size = 0; + if ($config['multiimage_method'] == 'split') { + foreach ($_FILES as $key => $file) { + $size += $file['size']; + } + } elseif ($config['multiimage_method'] == 'each') { + foreach ($_FILES as $key => $file) { + if ($file['size'] > $size) { + $size = $file['size']; + } + } + } else { + error(_('Unrecognized file size determination method.')); + } + $max_size = $config['max_filesize']; + + if (array_key_exists('board_specific',$config)){ + if (array_key_exists($board['uri'],$config['board_specific'])){ + if (array_key_exists('max_filesize',$config['board_specific'][$board['uri']])){ + $max_size = $config['board_specific'][$board['uri']]['max_filesize']; + } + } + } + + if ($size > $max_size) + error(sprintf3($config['error']['filesize'], array( + 'sz' => number_format($size), + 'filesz' => number_format($size), + 'maxsz' => number_format($config['max_filesize']) + ))); + $post['filesize'] = $size; + } + + $post['capcode'] = false; + + if ($mod && preg_match('/^((.+) )?## (.+)$/', $post['name'], $matches)) { + $name = $matches[2] != '' ? $matches[2] : $config['anonymous']; + $cap = $matches[3]; + + if (isset($config['mod']['capcode'][$mod['type']])) { + if ( $config['mod']['capcode'][$mod['type']] === true || + (is_array($config['mod']['capcode'][$mod['type']]) && + in_array($cap, $config['mod']['capcode'][$mod['type']]) + )) { + + $post['capcode'] = utf8tohtml($cap); + $post['name'] = $name; + } + } + } + else if ($config['joke_capcode']) { + if (strtolower($post['email']) == 'joke') { + if (isset($config['joke_capcode_default'])){ + $cap = $config['joke_capcode_default']; + } + else { + $cap = "joke"; + } + $post['capcode'] = utf8tohtml($cap); + $post['email'] = ''; + } + } + + $trip = generate_tripcode($post['name']); + $post['name'] = $trip[0]; + $post['trip'] = isset($trip[1]) ? $trip[1] : ''; // XX: Dropped posts and tripcodes + + $noko = false; + if (strtolower($post['email']) == 'noko') { + $noko = true; + $post['email'] = ''; + } elseif (strtolower($post['email']) == 'nonoko'){ + $noko = false; + $post['email'] = ''; + } else $noko = $config['always_noko']; + + if ($post['has_file']) { + $i = 0; + foreach ($_FILES as $key => $file) { + if ($file['size'] && $file['tmp_name']) { + $file['filename'] = urldecode($file['name']); + $file['extension'] = strtolower(mb_substr($file['filename'], mb_strrpos($file['filename'], '.') + 1)); + if (isset($config['filename_func'])) + $file['file_id'] = $config['filename_func']($file); + else + $file['file_id'] = time() . substr(microtime(), 2, 3); + + 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']); + $post['files'][] = $file; + $i++; + } + } + } + + if (empty($post['files'])) $post['has_file'] = false; + + if (!$dropped_post) { + // Check for a file + if ($post['op'] && !isset($post['no_longer_require_an_image_for_op'])) { + if (!$post['has_file'] && $config['force_image_op']) { + error($config['error']['noimage']); + } + } + + // Check for too many files + if (sizeof($post['files']) > $config['max_images']) { + error($config['error']['toomanyimages']); + } + } + + if ($config['strip_combining_chars']) { + $post['name'] = strip_combining_chars($post['name']); + $post['email'] = strip_combining_chars($post['email']); + $post['subject'] = strip_combining_chars($post['subject']); + $post['body'] = strip_combining_chars($post['body']); + } + + if (!$dropped_post) { + // Check string lengths + if (mb_strlen($post['name']) > 35) { + error(sprintf($config['error']['toolong'], 'name')); + } + if (mb_strlen($post['email']) > 40) { + error(sprintf($config['error']['toolong'], 'email')); + } + if (mb_strlen($post['subject']) > 100) { + error(sprintf($config['error']['toolong'], 'subject')); + } + if (!$mod && mb_strlen($post['body']) > $config['max_body']) { + error($config['error']['toolong_body']); + } + if (!$mod && mb_strlen($post['body']) > 0 && (mb_strlen($post['body']) < $config['min_body'])) { + error($config['error']['tooshort_body']); + } + if (mb_strlen($post['password']) > 20) { + error(sprintf($config['error']['toolong'], 'password')); + } + } + + wordfilters($post['body']); + + $post['body'] = escape_markup_modifiers($post['body']); + + if ($mod && isset($post['raw']) && $post['raw']) { + $post['body'] .= "\n1"; + } + + if (!$dropped_post) + if (($config['country_flags'] && !$config['allow_no_country']) || ($config['country_flags'] && $config['allow_no_country'] && !isset($_POST['no_country']))) { + require 'inc/lib/geoip/geoip.inc'; + $gi=geoip\geoip_open('inc/lib/geoip/GeoIPv6.dat', GEOIP_STANDARD); + + function ipv4to6($ip) { + if (strpos($ip, ':') !== false) { + if (strpos($ip, '.') > 0) + $ip = substr($ip, strrpos($ip, ':')+1); + else return $ip; //native ipv6 + } + $iparr = array_pad(explode('.', $ip), 4, 0); + $part7 = base_convert(($iparr[0] * 256) + $iparr[1], 10, 16); + $part8 = base_convert(($iparr[2] * 256) + $iparr[3], 10, 16); + return '::ffff:'.$part7.':'.$part8; + } + + if ($country_code = geoip\geoip_country_code_by_addr_v6($gi, ipv4to6($_SERVER['REMOTE_ADDR']))) { + if (!in_array(strtolower($country_code), array('eu', 'ap', 'o1', 'a1', 'a2'))) + $post['body'] .= "\n".strtolower($country_code)."". + "\n".geoip\geoip_country_name_by_addr_v6($gi, ipv4to6($_SERVER['REMOTE_ADDR'])).""; + } + } + + if ($config['user_flag'] && isset($_POST['user_flag'])) + if (!empty($_POST['user_flag']) ){ + + $user_flag = $_POST['user_flag']; + + if (!isset($config['user_flags'][$user_flag])) + error(_('Invalid flag selection!')); + + $flag_alt = isset($user_flag_alt) ? $user_flag_alt : $config['user_flags'][$user_flag]; + + $post['body'] .= "\n" . strtolower($user_flag) . "" . + "\n" . $flag_alt . ""; + } + + if ($config['allowed_tags'] && $post['op'] && isset($_POST['tag']) && isset($config['allowed_tags'][$_POST['tag']])) { + $post['body'] .= "\n" . $_POST['tag'] . ""; + } + + if (!$dropped_post) if ($config['proxy_save'] && isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { - $proxy = preg_replace("/[^0-9a-fA-F.,: ]/", '', $_SERVER['HTTP_X_FORWARDED_FOR']); - $post['body'] .= "\n".$proxy.""; - } - - print_err("proxy save block ok"); - - if (mysql_version() >= 50503) { - $post['body_nomarkup'] = $post['body']; // Assume we're using the utf8mb4 charset - } else { - // MySQL's `utf8` charset only supports up to 3-byte symbols - // Remove anything >= 0x010000 - - $chars = preg_split('//u', $post['body'], -1, PREG_SPLIT_NO_EMPTY); - $post['body_nomarkup'] = ''; - foreach ($chars as $char) { - $o = 0; - $ord = ordutf8($char, $o); - if ($ord >= 0x010000) - continue; - $post['body_nomarkup'] .= $char; - } - } - - print_err("body nomarkup block OK"); - - $post['tracked_cites'] = markup($post['body'], true); - - print_err("Process post tags flags and other stuff"); - - - if ($post['has_file']) { - $md5cmd = false; - if ($config['bsd_md5']) $md5cmd = '/sbin/md5 -r'; - if ($config['gnu_md5']) $md5cmd = 'md5sum'; - - $allhashes = ''; - - foreach ($post['files'] as $key => &$file) { - if ($post['op'] && $config['allowed_ext_op']) { - if (!in_array($file['extension'], $config['allowed_ext_op'])) { - print_err("Unknown extension (1)!"); - error($config['error']['unknownext']); - } - } elseif (!in_array($file['extension'], $config['allowed_ext']) && !in_array($file['extension'], $config['allowed_ext_files'])) { - print_err("Unknown extension (2)!"); - error($config['error']['unknownext']); - } - - $file['is_an_image'] = !in_array($file['extension'], $config['allowed_ext_files']); - - // Truncate filename if it is too long - $file['filename'] = mb_substr($file['filename'], 0, $config['max_filename_len']); - - $upload = $file['tmp_name']; - - if (!is_readable($upload)) - error($config['error']['nomove']); - - if ($md5cmd) { - $output = shell_exec_error($md5cmd . " " . escapeshellarg($upload)); - $output = explode(' ', $output); - $hash = $output[0]; - } - else { - $hash = md5_file($upload); - } - - $file['hash'] = $hash; - $allhashes .= $hash; - } - - if (count ($post['files']) == 1) { - $post['filehash'] = $hash; - } - else { - $post['filehash'] = md5($allhashes); - } - } - - print_err("has file block 2 OK"); - - if (!hasPermission($config['mod']['bypass_filters'], $board['uri']) && !$dropped_post) { - require_once 'inc/filters.php'; - - print_err("doing filters"); - do_filters($post); - print_err("filters OK"); - } - - print_err("filters block OK"); - - if ($post['has_file']) { - print_err("files block 3 start!"); - foreach ($post['files'] as $key => &$file) { - if ($file['is_an_image']) { - print_err("file is an image"); - if ($config['ie_mime_type_detection'] !== false) { - // Check IE MIME type detection XSS exploit - $buffer = file_get_contents($upload, null, null, null, 255); - if (preg_match($config['ie_mime_type_detection'], $buffer)) { - undoImage($post); - print_err("error mime exploit"); - error($config['error']['mime_exploit']); - } - } - - require_once 'inc/image.php'; - - // find dimensions of an image using GD - if (!$size = @getimagesize($file['tmp_name'])) { - print_err("error invalid image"); - error($config['error']['invalidimg']); - } - if (!in_array($size[2], array(IMAGETYPE_PNG, IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_BMP))) { - print_err("error invalid image2"); - error($config['error']['invalidimg']); - } - if ($size[0] > $config['max_width'] || $size[1] > $config['max_height']) { - print_err("error invalid maxsize"); - error($config['error']['maxsize']); - } - - print_err("initial image checks OK"); - - if ($config['convert_auto_orient'] && ($file['extension'] == 'jpg' || $file['extension'] == 'jpeg')) { - // The following code corrects the image orientation. - // Currently only works with the 'convert' option selected but it could easily be expanded to work with the rest if you can be bothered. - if (!($config['redraw_image'] || (($config['strip_exif'] && !$config['use_exiftool']) && ($file['extension'] == 'jpg' || $file['extension'] == 'jpeg')))) { - if (in_array($config['thumb_method'], array('convert', 'convert+gifsicle', 'gm', 'gm+gifsicle'))) { - $exif = @exif_read_data($file['tmp_name']); - $gm = in_array($config['thumb_method'], array('gm', 'gm+gifsicle')); - if (isset($exif['Orientation']) && $exif['Orientation'] != 1) { - if ($config['convert_manual_orient']) { - $error = shell_exec_error(($gm ? 'gm ' : '') . 'convert ' . - escapeshellarg($file['tmp_name']) . ' ' . - ImageConvert::jpeg_exif_orientation(false, $exif) . ' ' . - ($config['strip_exif'] ? '+profile "*"' : - ($config['use_exiftool'] ? '' : '+profile "*"') - ) . ' ' . - escapeshellarg($file['tmp_name'])); - if ($config['use_exiftool'] && !$config['strip_exif']) { - if ($exiftool_error = shell_exec_error( - 'exiftool -overwrite_original -q -q -orientation=1 -n ' . - escapeshellarg($file['tmp_name']))) - error(_('exiftool failed!'), null, $exiftool_error); - } else { - // TODO: Find another way to remove the Orientation tag from the EXIF profile - // without needing `exiftool`. - } - } else { - $error = shell_exec_error(($gm ? 'gm ' : '') . 'convert ' . - escapeshellarg($file['tmp_name']) . ' -auto-orient ' . escapeshellarg($upload)); - } - if ($error) { - print_err("Could not auto-orient image!"); - error(_('Could not auto-orient image!'), null, $error); - } - $size = @getimagesize($file['tmp_name']); - if ($config['strip_exif']) - $file['exif_stripped'] = true; - } - } - } - } - - print_err("convert auto orient block OK"); - - // create image object - $image = new Image($file['tmp_name'], $file['extension'], $size); - if ($image->size->width > $config['max_width'] || $image->size->height > $config['max_height']) { - $image->delete(); - - print_err("image too large"); - error($config['error']['maxsize']); - } - - print_err("create image object ok"); - - $file['width'] = $image->size->width; - $file['height'] = $image->size->height; - - print_err("image size width and height"); - - if ($config['spoiler_images'] && isset($_POST['spoiler'])) { - print_err("spoiler set"); - $file['thumb'] = 'spoiler'; - - $size = @getimagesize($config['spoiler_image']); - $file['thumbwidth'] = $size[0]; - $file['thumbheight'] = $size[1]; - } elseif ($config['minimum_copy_resize'] && - $image->size->width <= $config['thumb_width'] && - $image->size->height <= $config['thumb_height'] && - $file['extension'] == ($config['thumb_ext'] ? $config['thumb_ext'] : $file['extension'])) { - - print_err("minimum copy resize"); - // Copy, because there's nothing to resize - copy($file['tmp_name'], $file['thumb']); - - $file['thumbwidth'] = $image->size->width; - $file['thumbheight'] = $image->size->height; - } else { - print_err("thumbnail resize"); - $thumb = $image->resize( - $config['thumb_ext'] ? $config['thumb_ext'] : $file['extension'], - $post['op'] ? $config['thumb_op_width'] : $config['thumb_width'], - $post['op'] ? $config['thumb_op_height'] : $config['thumb_height'] - ); - print_err("thumbnail resize ok"); - - $thumb->to($file['thumb']); - - print_err("thumbnail save ok"); - - $file['thumbwidth'] = $thumb->width; - $file['thumbheight'] = $thumb->height; - - $thumb->_destroy(); - } - - print_err("something to do with thumbnails block OK"); - - if ($config['redraw_image'] || (!@$file['exif_stripped'] && $config['strip_exif'] && ($file['extension'] == 'jpg' || $file['extension'] == 'jpeg'))) { - if (!$config['redraw_image'] && $config['use_exiftool']) { - if($error = shell_exec_error('exiftool -overwrite_original -ignoreMinorErrors -q -q -all= ' . - escapeshellarg($file['tmp_name']))) - error(_('Could not strip EXIF metadata!'), null, $error); - } else { - $image->to($file['file']); - $dont_copy_file = true; - } - } - $image->destroy(); - } else { - if (($file['extension'] == "pdf" && $config['pdf_file_thumbnail']) || - ($file['extension'] == "djvu" && $config['djvu_file_thumbnail']) ){ - $path = $file['thumb']; - $error = shell_exec_error( 'convert -thumbnail x300 -background white -alpha remove ' . - escapeshellarg($file['tmp_name']. '[0]') . ' ' . - escapeshellarg($file['thumb'])); - - if ($error){ - $path = sprintf($config['file_thumb'],isset($config['file_icons'][$file['extension']]) ? $config['file_icons'][$file['extension']] : $config['file_icons']['default']); - } - - $file['thumb'] = basename($file['thumb']); - $size = @getimagesize($path); - $file['thumbwidth'] = $size[0]; - $file['thumbheight'] = $size[1]; - $file['width'] = $size[0]; - $file['height'] = $size[1]; - } - /*if (($file['extension'] == "epub" && $config['epub_file_thumbnail'])){ - $path = $file['thumb']; - // Open epub - // Get file list - // Check if cover file exists according to regex if it does use it - // Otherwise check if metadata file exists, and if does get rootfile and search for manifest for cover file name - // Otherwise Check if other image files exist and use them, based on criteria to pick the best one. - // Once we have filename extract said file from epub to file['thumb'] location. - $zip = new ZipArchive(); - if(@$zip->open($path)){ - $filename = ""; - // Go looking for a file name, current implementation just uses regex but should fallback to - // getting all images and then choosing one. - for( $i = 0; $i < $zip->numFiles; $i++ ){ - $stat = $zip->statIndex( $i ); - $matches = array(); - if (preg_match('/.*cover.*\.(jpg|jpeg|png)/', $stat['name'], $matches)) { - $filename = $matches[0]; - break; - } - } - // We have a cover filename to extract. - if (strlen($filename) > 0){ - //$zip->extractTo(dirname($file['thumb']), array($filename)); - } - else { - $error = 1; - } - - } - else { - $error = 1; - } - - if ($error){ - $path = sprintf($config['file_thumb'],isset($config['file_icons'][$file['extension']]) ? $config['file_icons'][$file['extension']] : $config['file_icons']['default']); - } - - $file['thumb'] = basename($file['thumb']); - $size = @getimagesize($path); - $file['thumbwidth'] = $size[0]; - $file['thumbheight'] = $size[1]; - $file['width'] = $size[0]; - $file['height'] = $size[1]; - }*/ - else if ($file['extension'] == "txt" && $config['txt_file_thumbnail']){ - $path = $file['thumb']; - $error = shell_exec_error( 'convert -thumbnail x300 xc:white -pointsize 12 -fill black -annotate +15+15 ' . - escapeshellarg( '@' . $file['tmp_name']) . ' ' . - escapeshellarg($file['thumb'])); - - if ($error){ - $path = sprintf($config['file_thumb'],isset($config['file_icons'][$file['extension']]) ? $config['file_icons'][$file['extension']] : $config['file_icons']['default']); - } - - $file['thumb'] = basename($file['thumb']); - $size = @getimagesize($path); - $file['thumbwidth'] = $size[0]; - $file['thumbheight'] = $size[1]; - $file['width'] = $size[0]; - $file['height'] = $size[1]; - } - else if ($file['extension'] == "svg"){ - // Copy, because there's nothing to resize - $file['thumb'] = substr_replace($file['thumb'] , $file['extension'], strrpos($file['thumb'] , '.') +1); - copy($file['tmp_name'], $file['thumb']); - $file['thumbwidth'] = $config['thumb_width']; - $file['thumbheight'] = $config['thumb_height']; - $file['thumb'] = basename($file['thumb']); - - } - else { - // not an image - //copy($config['file_thumb'], $post['thumb']); - $file['thumb'] = 'file'; - - $size = @getimagesize(sprintf($config['file_thumb'], - isset($config['file_icons'][$file['extension']]) ? - $config['file_icons'][$file['extension']] : $config['file_icons']['default'])); - $file['thumbwidth'] = $size[0]; - $file['thumbheight'] = $size[1]; - } - } - - print_err("is an image block OK"); - - if ($config['tesseract_ocr'] && $file['thumb'] != 'file') { // Let's OCR it! - $fname = $file['tmp_name']; - - if ($file['height'] > 500 || $file['width'] > 500) { - $fname = $file['thumb']; - } - - if ($fname == 'spoiler') { // We don't have that much CPU time, do we? - } - else { - $tmpname = __DIR__ . "/tmp/tesseract/".rand(0,10000000); - - // Preprocess command is an ImageMagick b/w quantization - $error = shell_exec_error(sprintf($config['tesseract_preprocess_command'], escapeshellarg($fname)) . " | " . + $proxy = preg_replace("/[^0-9a-fA-F.,: ]/", '', $_SERVER['HTTP_X_FORWARDED_FOR']); + $post['body'] .= "\n".$proxy.""; + } + + if (mysql_version() >= 50503) { + $post['body_nomarkup'] = $post['body']; // Assume we're using the utf8mb4 charset + } else { + // MySQL's `utf8` charset only supports up to 3-byte symbols + // Remove anything >= 0x010000 + + $chars = preg_split('//u', $post['body'], -1, PREG_SPLIT_NO_EMPTY); + $post['body_nomarkup'] = ''; + foreach ($chars as $char) { + $o = 0; + $ord = ordutf8($char, $o); + if ($ord >= 0x010000) + continue; + $post['body_nomarkup'] .= $char; + } + } + + $post['tracked_cites'] = markup($post['body'], true); + + if ($post['has_file']) { + $md5cmd = false; + if ($config['bsd_md5']) $md5cmd = '/sbin/md5 -r'; + if ($config['gnu_md5']) $md5cmd = 'md5sum'; + + $allhashes = ''; + + foreach ($post['files'] as $key => &$file) { + if ($post['op'] && $config['allowed_ext_op']) { + if (!in_array($file['extension'], $config['allowed_ext_op'])) { + error($config['error']['unknownext']); + } + } elseif (!in_array($file['extension'], $config['allowed_ext']) && !in_array($file['extension'], $config['allowed_ext_files'])) { + error($config['error']['unknownext']); + } + + $file['is_an_image'] = !in_array($file['extension'], $config['allowed_ext_files']); + + // Truncate filename if it is too long + $file['filename'] = mb_substr($file['filename'], 0, $config['max_filename_len']); + + $upload = $file['tmp_name']; + + if (!is_readable($upload)) + error($config['error']['nomove']); + + if ($md5cmd) { + $output = shell_exec_error($md5cmd . " " . escapeshellarg($upload)); + $output = explode(' ', $output); + $hash = $output[0]; + } + else { + $hash = md5_file($upload); + } + + $file['hash'] = $hash; + $allhashes .= $hash; + } + + if (count ($post['files']) == 1) { + $post['filehash'] = $hash; + } + else { + $post['filehash'] = md5($allhashes); + } + } + + if (!hasPermission($config['mod']['bypass_filters'], $board['uri']) && !$dropped_post) { + require_once 'inc/filters.php'; + + do_filters($post); + } + + if ($post['has_file']) { + foreach ($post['files'] as $key => &$file) { + if ($file['is_an_image']) { + if ($config['ie_mime_type_detection'] !== false) { + // Check IE MIME type detection XSS exploit + $buffer = file_get_contents($upload, null, null, null, 255); + if (preg_match($config['ie_mime_type_detection'], $buffer)) { + undoImage($post); + error($config['error']['mime_exploit']); + } + } + + require_once 'inc/image.php'; + + // find dimensions of an image using GD + if (!$size = @getimagesize($file['tmp_name'])) { + error($config['error']['invalidimg']); + } + if (!in_array($size[2], array(IMAGETYPE_PNG, IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_BMP))) { + error($config['error']['invalidimg']); + } + if ($size[0] > $config['max_width'] || $size[1] > $config['max_height']) { + error($config['error']['maxsize']); + } + + if ($config['convert_auto_orient'] && ($file['extension'] == 'jpg' || $file['extension'] == 'jpeg')) { + // The following code corrects the image orientation. + // Currently only works with the 'convert' option selected but it could easily be expanded to work with the rest if you can be bothered. + if (!($config['redraw_image'] || (($config['strip_exif'] && !$config['use_exiftool']) && ($file['extension'] == 'jpg' || $file['extension'] == 'jpeg')))) { + if (in_array($config['thumb_method'], array('convert', 'convert+gifsicle', 'gm', 'gm+gifsicle'))) { + $exif = @exif_read_data($file['tmp_name']); + $gm = in_array($config['thumb_method'], array('gm', 'gm+gifsicle')); + if (isset($exif['Orientation']) && $exif['Orientation'] != 1) { + if ($config['convert_manual_orient']) { + $error = shell_exec_error(($gm ? 'gm ' : '') . 'convert ' . + escapeshellarg($file['tmp_name']) . ' ' . + ImageConvert::jpeg_exif_orientation(false, $exif) . ' ' . + ($config['strip_exif'] ? '+profile "*"' : + ($config['use_exiftool'] ? '' : '+profile "*"') + ) . ' ' . + escapeshellarg($file['tmp_name'])); + if ($config['use_exiftool'] && !$config['strip_exif']) { + if ($exiftool_error = shell_exec_error( + 'exiftool -overwrite_original -q -q -orientation=1 -n ' . + escapeshellarg($file['tmp_name']))) + error(_('exiftool failed!'), null, $exiftool_error); + } else { + // TODO: Find another way to remove the Orientation tag from the EXIF profile + // without needing `exiftool`. + } + } else { + $error = shell_exec_error(($gm ? 'gm ' : '') . 'convert ' . + escapeshellarg($file['tmp_name']) . ' -auto-orient ' . escapeshellarg($upload)); + } + if ($error) { + error(_('Could not auto-orient image!'), null, $error); + } + $size = @getimagesize($file['tmp_name']); + if ($config['strip_exif']) + $file['exif_stripped'] = true; + } + } + } + } + + // create image object + $image = new Image($file['tmp_name'], $file['extension'], $size); + if ($image->size->width > $config['max_width'] || $image->size->height > $config['max_height']) { + $image->delete(); + + error($config['error']['maxsize']); + } + + $file['width'] = $image->size->width; + $file['height'] = $image->size->height; + + if ($config['spoiler_images'] && isset($_POST['spoiler'])) { + $file['thumb'] = 'spoiler'; + + $size = @getimagesize($config['spoiler_image']); + $file['thumbwidth'] = $size[0]; + $file['thumbheight'] = $size[1]; + } elseif ($config['minimum_copy_resize'] && + $image->size->width <= $config['thumb_width'] && + $image->size->height <= $config['thumb_height'] && + $file['extension'] == ($config['thumb_ext'] ? $config['thumb_ext'] : $file['extension'])) { + + // Copy, because there's nothing to resize + copy($file['tmp_name'], $file['thumb']); + + $file['thumbwidth'] = $image->size->width; + $file['thumbheight'] = $image->size->height; + } else { + $thumb = $image->resize( + $config['thumb_ext'] ? $config['thumb_ext'] : $file['extension'], + $post['op'] ? $config['thumb_op_width'] : $config['thumb_width'], + $post['op'] ? $config['thumb_op_height'] : $config['thumb_height'] + ); + + $thumb->to($file['thumb']); + + $file['thumbwidth'] = $thumb->width; + $file['thumbheight'] = $thumb->height; + + $thumb->_destroy(); + } + + if ($config['redraw_image'] || (!@$file['exif_stripped'] && $config['strip_exif'] && ($file['extension'] == 'jpg' || $file['extension'] == 'jpeg'))) { + if (!$config['redraw_image'] && $config['use_exiftool']) { + if($error = shell_exec_error('exiftool -overwrite_original -ignoreMinorErrors -q -q -all= ' . + escapeshellarg($file['tmp_name']))) + error(_('Could not strip EXIF metadata!'), null, $error); + } else { + $image->to($file['file']); + $dont_copy_file = true; + } + } + $image->destroy(); + } else { + if (($file['extension'] == "pdf" && $config['pdf_file_thumbnail']) || + ($file['extension'] == "djvu" && $config['djvu_file_thumbnail']) ){ + $path = $file['thumb']; + $error = shell_exec_error( 'convert -thumbnail x300 -background white -alpha remove ' . + escapeshellarg($file['tmp_name']. '[0]') . ' ' . + escapeshellarg($file['thumb'])); + + if ($error){ + $path = sprintf($config['file_thumb'],isset($config['file_icons'][$file['extension']]) ? $config['file_icons'][$file['extension']] : $config['file_icons']['default']); + } + + $file['thumb'] = basename($file['thumb']); + $size = @getimagesize($path); + $file['thumbwidth'] = $size[0]; + $file['thumbheight'] = $size[1]; + $file['width'] = $size[0]; + $file['height'] = $size[1]; + } + /*if (($file['extension'] == "epub" && $config['epub_file_thumbnail'])){ + $path = $file['thumb']; + // Open epub + // Get file list + // Check if cover file exists according to regex if it does use it + // Otherwise check if metadata file exists, and if does get rootfile and search for manifest for cover file name + // Otherwise Check if other image files exist and use them, based on criteria to pick the best one. + // Once we have filename extract said file from epub to file['thumb'] location. + $zip = new ZipArchive(); + if(@$zip->open($path)){ + $filename = ""; + // Go looking for a file name, current implementation just uses regex but should fallback to + // getting all images and then choosing one. + for( $i = 0; $i < $zip->numFiles; $i++ ){ + $stat = $zip->statIndex( $i ); + $matches = array(); + if (preg_match('/.*cover.*\.(jpg|jpeg|png)/', $stat['name'], $matches)) { + $filename = $matches[0]; + break; + } + } + // We have a cover filename to extract. + if (strlen($filename) > 0){ + //$zip->extractTo(dirname($file['thumb']), array($filename)); + } + else { + $error = 1; + } + + } + else { + $error = 1; + } + + if ($error){ + $path = sprintf($config['file_thumb'],isset($config['file_icons'][$file['extension']]) ? $config['file_icons'][$file['extension']] : $config['file_icons']['default']); + } + + $file['thumb'] = basename($file['thumb']); + $size = @getimagesize($path); + $file['thumbwidth'] = $size[0]; + $file['thumbheight'] = $size[1]; + $file['width'] = $size[0]; + $file['height'] = $size[1]; + }*/ + else if ($file['extension'] == "txt" && $config['txt_file_thumbnail']){ + $path = $file['thumb']; + $error = shell_exec_error( 'convert -thumbnail x300 xc:white -pointsize 12 -fill black -annotate +15+15 ' . + escapeshellarg( '@' . $file['tmp_name']) . ' ' . + escapeshellarg($file['thumb'])); + + if ($error){ + $path = sprintf($config['file_thumb'],isset($config['file_icons'][$file['extension']]) ? $config['file_icons'][$file['extension']] : $config['file_icons']['default']); + } + + $file['thumb'] = basename($file['thumb']); + $size = @getimagesize($path); + $file['thumbwidth'] = $size[0]; + $file['thumbheight'] = $size[1]; + $file['width'] = $size[0]; + $file['height'] = $size[1]; + } + else if ($file['extension'] == "svg"){ + // Copy, because there's nothing to resize + $file['thumb'] = substr_replace($file['thumb'] , $file['extension'], strrpos($file['thumb'] , '.') +1); + copy($file['tmp_name'], $file['thumb']); + $file['thumbwidth'] = $config['thumb_width']; + $file['thumbheight'] = $config['thumb_height']; + $file['thumb'] = basename($file['thumb']); + + } + else { + // not an image + //copy($config['file_thumb'], $post['thumb']); + $file['thumb'] = 'file'; + + $size = @getimagesize(sprintf($config['file_thumb'], + isset($config['file_icons'][$file['extension']]) ? + $config['file_icons'][$file['extension']] : $config['file_icons']['default'])); + $file['thumbwidth'] = $size[0]; + $file['thumbheight'] = $size[1]; + } + } + + if ($config['tesseract_ocr'] && $file['thumb'] != 'file') { // Let's OCR it! + $fname = $file['tmp_name']; + + if ($file['height'] > 500 || $file['width'] > 500) { + $fname = $file['thumb']; + } + + if ($fname == 'spoiler') { // We don't have that much CPU time, do we? + } + else { + $tmpname = __DIR__ . "/tmp/tesseract/".rand(0,10000000); + + // Preprocess command is an ImageMagick b/w quantization + $error = shell_exec_error(sprintf($config['tesseract_preprocess_command'], escapeshellarg($fname)) . " | " . 'tesseract stdin '.escapeshellarg($tmpname).' '.$config['tesseract_params']); - $tmpname .= ".txt"; - - $value = @file_get_contents($tmpname); - @unlink($tmpname); - - if ($value && trim($value)) { - // This one has an effect, that the body is appended to a post body. So you can write a correct - // spamfilter. - $post['body_nomarkup'] .= "".htmlspecialchars($value).""; - } - } - } - - print_err("OCR block pass"); - - if (!isset($dont_copy_file) || !$dont_copy_file) { - if (isset($file['file_tmp'])) { - if (!@rename($file['tmp_name'], $file['file'])) - error($config['error']['nomove']); - chmod($file['file'], 0644); - } elseif (!@move_uploaded_file($file['tmp_name'], $file['file'])) - error($config['error']['nomove']); - } - } - - print_err("image reject repost begin"); - - if ($config['image_reject_repost']) { - if ($p = getPostByHash($post['filehash'])) { - undoImage($post); - print_err("file exists!"); - error(sprintf($config['error']['fileexists'], - ($post['mod'] ? $config['root'] . $config['file_mod'] . '?/' : $config['root']) . - ($board['dir'] . $config['dir']['res'] . - ($p['thread'] ? - $p['thread'] . '.html#' . $p['id'] - : - $p['id'] . '.html' - )) - )); - } - } else if (!$post['op'] && $config['image_reject_repost_in_thread']) { - if ($p = getPostByHashInThread($post['filehash'], $post['thread'])) { - undoImage($post); - print_err("file exists ITT!"); - error(sprintf($config['error']['fileexistsinthread'], - ($post['mod'] ? $config['root'] . $config['file_mod'] . '?/' : $config['root']) . - ($board['dir'] . $config['dir']['res'] . - ($p['thread'] ? - $p['thread'] . '.html#' . $p['id'] - : - $p['id'] . '.html' - )) - )); - } - } - - print_err("End of has file block 3"); - } - - print_err("has file block 3 OK"); - - // Do filters again if OCRing - if ($config['tesseract_ocr'] && !hasPermission($config['mod']['bypass_filters'], $board['uri']) && !$dropped_post) { - do_filters($post); - } - - if (!hasPermission($config['mod']['postunoriginal'], $board['uri']) && $config['robot_enable'] && checkRobot($post['body_nomarkup']) && !$dropped_post) { - print_err("muted or unoriginal"); - undoImage($post); - if ($config['robot_mute']) { - print_err("muted"); - error(sprintf($config['error']['muted'], mute())); - } else { - print_err("unoriginal"); - error($config['error']['unoriginal']); - } - } - - // Remove board directories before inserting them into the database. - if ($post['has_file']) { - 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'])); - if ($file['is_an_image'] && $file['thumb'] != 'spoiler') - $file['thumb'] = mb_substr($file['thumb'], mb_strlen($board['dir'] . $config['dir']['thumb'])); - } - } - - print_err("has file block 5 OK"); - - $post = (object)$post; - $post->files = array_map(function($a) { return (object)$a; }, $post->files); - - $error = event('post', $post); - $post->files = array_map(function($a) { return (array)$a; }, $post->files); - - print_err("post set files map"); - - if ($error) { - print_err("Error " . $error); - undoImage((array)$post); - error($error); - } - - print_err("no error yet"); - - $post = (array)$post; - - if ($post['files']) { - $post['files'] = $post['files']; - } - - print_err("no error yet2"); - - $post['num_files'] = sizeof($post['files']); - - print_err("no error yet3"); - $post['id'] = $id = post($post); - print_err("no error yet 4"); - $post['slug'] = slugify($post); - - print_err("Set post props OK"); - - if ($dropped_post && $dropped_post['from_nntp']) { - $query = prepare("INSERT INTO ``nntp_references`` (`board`, `id`, `message_id`, `message_id_digest`, `own`, `headers`) VALUES ". - "(:board , :id , :message_id , :message_id_digest , false, :headers)"); - - $query->bindValue(':board', $dropped_post['board']); - $query->bindValue(':id', $id); - $query->bindValue(':message_id', $dropped_post['msgid']); - $query->bindValue(':message_id_digest', sha1($dropped_post['msgid'])); - $query->bindValue(':headers', $dropped_post['headers']); - $query->execute() or error(db_error($query)); - } // ^^^^^ For inbound posts ^^^^^ - elseif ($config['nntpchan']['enabled'] && $config['nntpchan']['group']) { - // vvvvv For outbound posts vvvvv - - require_once('inc/nntpchan/nntpchan.php'); - $msgid = gen_msgid($post['board'], $post['id']); - - list($headers, $files) = post2nntp($post, $msgid); - - $message = gen_nntp($headers, $files); - - $query = prepare("INSERT INTO ``nntp_references`` (`board`, `id`, `message_id`, `message_id_digest`, `own`, `headers`) VALUES ". - "(:board , :id , :message_id , :message_id_digest , true , :headers)"); - - $query->bindValue(':board', $post['board']); + $tmpname .= ".txt"; + + $value = @file_get_contents($tmpname); + @unlink($tmpname); + + if ($value && trim($value)) { + // This one has an effect, that the body is appended to a post body. So you can write a correct + // spamfilter. + $post['body_nomarkup'] .= "".htmlspecialchars($value).""; + } + } + } + + if (!isset($dont_copy_file) || !$dont_copy_file) { + if (isset($file['file_tmp'])) { + if (!@rename($file['tmp_name'], $file['file'])) + error($config['error']['nomove']); + chmod($file['file'], 0644); + } elseif (!@move_uploaded_file($file['tmp_name'], $file['file'])) + error($config['error']['nomove']); + } + } + + if ($config['image_reject_repost']) { + if ($p = getPostByHash($post['filehash'])) { + undoImage($post); + error(sprintf($config['error']['fileexists'], + ($post['mod'] ? $config['root'] . $config['file_mod'] . '?/' : $config['root']) . + ($board['dir'] . $config['dir']['res'] . + ($p['thread'] ? + $p['thread'] . '.html#' . $p['id'] + : + $p['id'] . '.html' + )) + )); + } + } else if (!$post['op'] && $config['image_reject_repost_in_thread']) { + if ($p = getPostByHashInThread($post['filehash'], $post['thread'])) { + undoImage($post); + error(sprintf($config['error']['fileexistsinthread'], + ($post['mod'] ? $config['root'] . $config['file_mod'] . '?/' : $config['root']) . + ($board['dir'] . $config['dir']['res'] . + ($p['thread'] ? + $p['thread'] . '.html#' . $p['id'] + : + $p['id'] . '.html' + )) + )); + } + } + + } + + // Do filters again if OCRing + if ($config['tesseract_ocr'] && !hasPermission($config['mod']['bypass_filters'], $board['uri']) && !$dropped_post) { + do_filters($post); + } + + if (!hasPermission($config['mod']['postunoriginal'], $board['uri']) && $config['robot_enable'] && checkRobot($post['body_nomarkup']) && !$dropped_post) { + undoImage($post); + if ($config['robot_mute']) { + error(sprintf($config['error']['muted'], mute())); + } else { + error($config['error']['unoriginal']); + } + } + + // Remove board directories before inserting them into the database. + if ($post['has_file']) { + 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'])); + if ($file['is_an_image'] && $file['thumb'] != 'spoiler') + $file['thumb'] = mb_substr($file['thumb'], mb_strlen($board['dir'] . $config['dir']['thumb'])); + } + } + + $post = (object)$post; + $post->files = array_map(function($a) { return (object)$a; }, $post->files); + + $error = event('post', $post); + $post->files = array_map(function($a) { return (array)$a; }, $post->files); + + if ($error) { + undoImage((array)$post); + error($error); + } + + $post = (array)$post; + + if ($post['files']) { + $post['files'] = $post['files']; + } + + $post['num_files'] = sizeof($post['files']); + + $post['id'] = $id = post($post); + $post['slug'] = slugify($post); + + if ($dropped_post && $dropped_post['from_nntp']) { + $query = prepare("INSERT INTO ``nntp_references`` (`board`, `id`, `message_id`, `message_id_digest`, `own`, `headers`) VALUES ". + "(:board , :id , :message_id , :message_id_digest , false, :headers)"); + + $query->bindValue(':board', $dropped_post['board']); + $query->bindValue(':id', $id); + $query->bindValue(':message_id', $dropped_post['msgid']); + $query->bindValue(':message_id_digest', sha1($dropped_post['msgid'])); + $query->bindValue(':headers', $dropped_post['headers']); + $query->execute() or error(db_error($query)); + } // ^^^^^ For inbound posts ^^^^^ + elseif ($config['nntpchan']['enabled'] && $config['nntpchan']['group']) { + // vvvvv For outbound posts vvvvv + + require_once('inc/nntpchan/nntpchan.php'); + $msgid = gen_msgid($post['board'], $post['id']); + + list($headers, $files) = post2nntp($post, $msgid); + + $message = gen_nntp($headers, $files); + + $query = prepare("INSERT INTO ``nntp_references`` (`board`, `id`, `message_id`, `message_id_digest`, `own`, `headers`) VALUES ". + "(:board , :id , :message_id , :message_id_digest , true , :headers)"); + + $query->bindValue(':board', $post['board']); $query->bindValue(':id', $post['id']); $query->bindValue(':message_id', $msgid); $query->bindValue(':message_id_digest', sha1($msgid)); $query->bindValue(':headers', json_encode($headers)); $query->execute() or error(db_error($query)); - // Let's broadcast it! - nntp_publish($message, $msgid); - } - - print_err("insert flood post"); - insertFloodPost($post); - - // Handle cyclical threads - if (!$post['op'] && isset($thread['cycle']) && $thread['cycle']) { - // Query is a bit weird due to "This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'" (MariaDB Ver 15.1 Distrib 10.0.17-MariaDB, for Linux (x86_64)) - $query = prepare(sprintf('DELETE FROM ``posts_%s`` WHERE `thread` = :thread AND `id` NOT IN (SELECT `id` FROM (SELECT `id` FROM ``posts_%s`` WHERE `thread` = :thread ORDER BY `id` DESC LIMIT :limit) i)', $board['uri'], $board['uri'])); - $query->bindValue(':thread', $post['thread']); - $query->bindValue(':limit', $config['cycle_limit'], PDO::PARAM_INT); - $query->execute() or error(db_error($query)); - } - - print_err("increment antispam"); - if (isset($post['antispam_hash'])) { - incrementSpamHash($post['antispam_hash']); - } - - if (isset($post['tracked_cites']) && !empty($post['tracked_cites'])) { - $insert_rows = array(); - foreach ($post['tracked_cites'] as $cite) { - $insert_rows[] = '(' . - $pdo->quote($board['uri']) . ', ' . (int)$id . ', ' . - $pdo->quote($cite[0]) . ', ' . (int)$cite[1] . ')'; - } - query('INSERT INTO ``cites`` VALUES ' . implode(', ', $insert_rows)) or error(db_error()); - } - - print_err("tracked cites block ok"); - - if (!$post['op'] && strtolower($post['email']) != 'sage' && !$thread['sage'] && ($config['reply_limit'] == 0 || $numposts['replies']+1 < $config['reply_limit'])) { - bumpThread($post['thread']); - } - - print_err("thread bumped"); - - if (isset($_SERVER['HTTP_REFERER'])) { - // Tell Javascript that we posted successfully - if (isset($_COOKIE[$config['cookies']['js']])) - $js = json_decode($_COOKIE[$config['cookies']['js']]); - else - $js = (object) array(); - // Tell it to delete the cached post for referer - $js->{$_SERVER['HTTP_REFERER']} = true; - // Encode and set cookie - setcookie($config['cookies']['js'], json_encode($js), 0, $config['cookies']['jail'] ? $config['cookies']['path'] : '/', null, false, false); - } - - $root = $post['mod'] ? $config['root'] . $config['file_mod'] . '?/' : $config['root']; - - if ($noko) { - $redirect = $root . $board['dir'] . $config['dir']['res'] . - link_for($post, false, false, $thread) . (!$post['op'] ? '#' . $id : ''); - - if (!$post['op'] && isset($_SERVER['HTTP_REFERER'])) { - $regex = array( - 'board' => str_replace('%s', '(\w{1,8})', preg_quote($config['board_path'], '/')), - 'page' => str_replace('%d', '(\d+)', preg_quote($config['file_page'], '/')), - 'page50' => '(' . str_replace('%d', '(\d+)', preg_quote($config['file_page50'], '/')) . '|' . - str_replace(array('%d', '%s'), array('(\d+)', '[a-z0-9-]+'), preg_quote($config['file_page50_slug'], '/')) . ')', - 'res' => preg_quote($config['dir']['res'], '/'), - ); - - if (preg_match('/\/' . $regex['board'] . $regex['res'] . $regex['page50'] . '([?&].*)?$/', $_SERVER['HTTP_REFERER'])) { - $redirect = $root . $board['dir'] . $config['dir']['res'] . - link_for($post, true, false, $thread) . (!$post['op'] ? '#' . $id : ''); - } - } - } else { - $redirect = $root . $board['dir'] . $config['file_index']; - - } - - print_err("Redirect or noko block OK"); - - buildThread($post['op'] ? $id : $post['thread']); - - print_err("build thread OK"); - - if ($config['syslog']) - _syslog(LOG_INFO, 'New post: /' . $board['dir'] . $config['dir']['res'] . - link_for($post) . (!$post['op'] ? '#' . $id : '')); - - if (!$post['mod']) header('X-Associated-Content: "' . $redirect . '"'); - - if (!isset($_POST['json_response'])) { - header('Location: ' . $redirect, true, $config['redirect_http']); - } else { - header('Content-Type: text/json; charset=utf-8'); - echo json_encode(array( - 'redirect' => $redirect, - 'noko' => $noko, - 'id' => $id - )); - } - - if ($config['try_smarter'] && $post['op']) - $build_pages = range(1, $config['max_pages']); - - if ($post['op']) - clean($id); - - event('post-after', $post); - - buildIndex(); - - // We are already done, let's continue our heavy-lifting work in the background (if we run off FastCGI) - if (function_exists('fastcgi_finish_request')) { - @fastcgi_finish_request(); - } - - if ($post['op']) { - rebuildThemes('post-thread', $board['uri']); - } else { - rebuildThemes('post', $board['uri']); - } - - - print_err("handle post DONE"); + // Let's broadcast it! + nntp_publish($message, $msgid); + } + + insertFloodPost($post); + + // Handle cyclical threads + if (!$post['op'] && isset($thread['cycle']) && $thread['cycle']) { + // Query is a bit weird due to "This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'" (MariaDB Ver 15.1 Distrib 10.0.17-MariaDB, for Linux (x86_64)) + $query = prepare(sprintf('DELETE FROM ``posts_%s`` WHERE `thread` = :thread AND `id` NOT IN (SELECT `id` FROM (SELECT `id` FROM ``posts_%s`` WHERE `thread` = :thread ORDER BY `id` DESC LIMIT :limit) i)', $board['uri'], $board['uri'])); + $query->bindValue(':thread', $post['thread']); + $query->bindValue(':limit', $config['cycle_limit'], PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + } + + if (isset($post['antispam_hash'])) { + incrementSpamHash($post['antispam_hash']); + } + + if (isset($post['tracked_cites']) && !empty($post['tracked_cites'])) { + $insert_rows = array(); + foreach ($post['tracked_cites'] as $cite) { + $insert_rows[] = '(' . + $pdo->quote($board['uri']) . ', ' . (int)$id . ', ' . + $pdo->quote($cite[0]) . ', ' . (int)$cite[1] . ')'; + } + query('INSERT INTO ``cites`` VALUES ' . implode(', ', $insert_rows)) or error(db_error()); + } + + if (!$post['op'] && strtolower($post['email']) != 'sage' && !$thread['sage'] && ($config['reply_limit'] == 0 || $numposts['replies']+1 < $config['reply_limit'])) { + bumpThread($post['thread']); + } + + if (isset($_SERVER['HTTP_REFERER'])) { + // Tell Javascript that we posted successfully + if (isset($_COOKIE[$config['cookies']['js']])) + $js = json_decode($_COOKIE[$config['cookies']['js']]); + else + $js = (object) array(); + // Tell it to delete the cached post for referer + $js->{$_SERVER['HTTP_REFERER']} = true; + // Encode and set cookie + setcookie($config['cookies']['js'], json_encode($js), 0, $config['cookies']['jail'] ? $config['cookies']['path'] : '/', null, false, false); + } + + $root = $post['mod'] ? $config['root'] . $config['file_mod'] . '?/' : $config['root']; + + if ($noko) { + $redirect = $root . $board['dir'] . $config['dir']['res'] . + link_for($post, false, false, $thread) . (!$post['op'] ? '#' . $id : ''); + + if (!$post['op'] && isset($_SERVER['HTTP_REFERER'])) { + $regex = array( + 'board' => str_replace('%s', '(\w{1,8})', preg_quote($config['board_path'], '/')), + 'page' => str_replace('%d', '(\d+)', preg_quote($config['file_page'], '/')), + 'page50' => '(' . str_replace('%d', '(\d+)', preg_quote($config['file_page50'], '/')) . '|' . + str_replace(array('%d', '%s'), array('(\d+)', '[a-z0-9-]+'), preg_quote($config['file_page50_slug'], '/')) . ')', + 'res' => preg_quote($config['dir']['res'], '/'), + ); + + if (preg_match('/\/' . $regex['board'] . $regex['res'] . $regex['page50'] . '([?&].*)?$/', $_SERVER['HTTP_REFERER'])) { + $redirect = $root . $board['dir'] . $config['dir']['res'] . + link_for($post, true, false, $thread) . (!$post['op'] ? '#' . $id : ''); + } + } + } else { + $redirect = $root . $board['dir'] . $config['file_index']; + + } + + buildThread($post['op'] ? $id : $post['thread']); + + if ($config['syslog']) + _syslog(LOG_INFO, 'New post: /' . $board['dir'] . $config['dir']['res'] . + link_for($post) . (!$post['op'] ? '#' . $id : '')); + + if (!$post['mod']) header('X-Associated-Content: "' . $redirect . '"'); + + if (!isset($_POST['json_response'])) { + header('Location: ' . $redirect, true, $config['redirect_http']); + } else { + header('Content-Type: text/json; charset=utf-8'); + echo json_encode(array( + 'redirect' => $redirect, + 'noko' => $noko, + 'id' => $id + )); + } + + if ($config['try_smarter'] && $post['op']) + $build_pages = range(1, $config['max_pages']); + + if ($post['op']) + clean($id); + + event('post-after', $post); + + buildIndex(); + + // We are already done, let's continue our heavy-lifting work in the background (if we run off FastCGI) + if (function_exists('fastcgi_finish_request')) { + @fastcgi_finish_request(); + } + + if ($post['op']) { + rebuildThemes('post-thread', $board['uri']); + } else { + rebuildThemes('post', $board['uri']); + } } function handle_appeal(){ - global $config; - if (!isset($_POST['ban_id'])) - error($config['error']['bot']); - - $ban_id = (int)$_POST['ban_id']; - - $bans = Bans::find($_SERVER['REMOTE_ADDR']); - foreach ($bans as $_ban) { - if ($_ban['id'] == $ban_id) { - $ban = $_ban; - break; - } - } - - if (!isset($ban)) { - error(_("That ban doesn't exist or is not for you.")); - } - - if ($ban['expires'] && $ban['expires'] - $ban['created'] <= $config['ban_appeals_min_length']) { - error(_("You cannot appeal a ban of this length.")); - } - - $query = query("SELECT `denied` FROM ``ban_appeals`` WHERE `ban_id` = $ban_id") or error(db_error()); - $ban_appeals = $query->fetchAll(PDO::FETCH_COLUMN); - - if (count($ban_appeals) >= $config['ban_appeals_max']) { - error(_("You cannot appeal this ban again.")); - } - - foreach ($ban_appeals as $is_denied) { - if (!$is_denied) - error(_("There is already a pending appeal for this ban.")); - } - - $query = prepare("INSERT INTO ``ban_appeals`` VALUES (NULL, :ban_id, :time, :message, 0)"); - $query->bindValue(':ban_id', $ban_id, PDO::PARAM_INT); - $query->bindValue(':time', time(), PDO::PARAM_INT); - $query->bindValue(':message', $_POST['appeal']); - $query->execute() or error(db_error($query)); - - displayBan($ban); + global $config; + if (!isset($_POST['ban_id'])) + error($config['error']['bot']); + + $ban_id = (int)$_POST['ban_id']; + + $bans = Bans::find($_SERVER['REMOTE_ADDR']); + foreach ($bans as $_ban) { + if ($_ban['id'] == $ban_id) { + $ban = $_ban; + break; + } + } + + if (!isset($ban)) { + error(_("That ban doesn't exist or is not for you.")); + } + + if ($ban['expires'] && $ban['expires'] - $ban['created'] <= $config['ban_appeals_min_length']) { + error(_("You cannot appeal a ban of this length.")); + } + + $query = query("SELECT `denied` FROM ``ban_appeals`` WHERE `ban_id` = $ban_id") or error(db_error()); + $ban_appeals = $query->fetchAll(PDO::FETCH_COLUMN); + + if (count($ban_appeals) >= $config['ban_appeals_max']) { + error(_("You cannot appeal this ban again.")); + } + + foreach ($ban_appeals as $is_denied) { + if (!$is_denied) + error(_("There is already a pending appeal for this ban.")); + } + + $query = prepare("INSERT INTO ``ban_appeals`` VALUES (NULL, :ban_id, :time, :message, 0)"); + $query->bindValue(':ban_id', $ban_id, PDO::PARAM_INT); + $query->bindValue(':time', time(), PDO::PARAM_INT); + $query->bindValue(':message', $_POST['appeal']); + $query->execute() or error(db_error($query)); + + displayBan($ban); } // Is it a post coming from NNTP? Let's extract it and pretend it's a normal post. if (isset($_GET['Newsgroups'])) { - if($config['nntpchan']['enabled']){ - handle_nntpchan(); - } - else { - error("NNTPChan: NNTPChan support is disabled"); - } + if($config['nntpchan']['enabled']){ + handle_nntpchan(); + } + else { + error("NNTPChan: NNTPChan support is disabled"); + } } if (isset($_POST['delete'])) { - handle_delete(); + handle_delete(); } elseif (isset($_POST['report'])) { - handle_report(); + handle_report(); } elseif (isset($_POST['post']) || $dropped_post) { - handle_post(); + handle_post(); } elseif (isset($_POST['appeal'])) { - handle_appeal(); + handle_appeal(); } else { - if (!file_exists($config['has_installed'])) { - header('Location: install.php', true, $config['redirect_http']); - } else { - // They opened post.php in their browser manually. - error($config['error']['nopost']); - } + if (!file_exists($config['has_installed'])) { + header('Location: install.php', true, $config['redirect_http']); + } else { + // They opened post.php in their browser manually. + error($config['error']['nopost']); + } } diff --git a/static/flags/4th_international.png b/static/flags/4th_international.png new file mode 100644 index 00000000..533f03da Binary files /dev/null and b/static/flags/4th_international.png differ diff --git a/static/flags/a1.png b/static/flags/a1.png old mode 100755 new mode 100644 diff --git a/static/flags/a2.png b/static/flags/a2.png old mode 100755 new mode 100644 diff --git a/static/flags/ac.png b/static/flags/ac.png old mode 100755 new mode 100644 diff --git a/static/flags/acceleration.png b/static/flags/acceleration.png new file mode 100644 index 00000000..d285ff4b Binary files /dev/null and b/static/flags/acceleration.png differ diff --git a/static/flags/ad.png b/static/flags/ad.png old mode 100755 new mode 100644 diff --git a/static/flags/ae.png b/static/flags/ae.png old mode 100755 new mode 100644 diff --git a/static/flags/af.png b/static/flags/af.png old mode 100755 new mode 100644 diff --git a/static/flags/ag.png b/static/flags/ag.png old mode 100755 new mode 100644 diff --git a/static/flags/ai.png b/static/flags/ai.png old mode 100755 new mode 100644 diff --git a/static/flags/ak-47.png b/static/flags/ak-47.png new file mode 100644 index 00000000..bcbe74fc Binary files /dev/null and b/static/flags/ak-47.png differ diff --git a/static/flags/al.png b/static/flags/al.png old mode 100755 new mode 100644 diff --git a/static/flags/albania.png b/static/flags/albania.png new file mode 100644 index 00000000..8699a558 Binary files /dev/null and b/static/flags/albania.png differ diff --git a/static/flags/allende.png b/static/flags/allende.png new file mode 100644 index 00000000..b84de796 Binary files /dev/null and b/static/flags/allende.png differ diff --git a/static/flags/am.png b/static/flags/am.png old mode 100755 new mode 100644 diff --git a/static/flags/an.png b/static/flags/an.png old mode 100755 new mode 100644 diff --git a/static/flags/anarcha-feminism.png b/static/flags/anarcha-feminism.png new file mode 100644 index 00000000..8a369027 Binary files /dev/null and b/static/flags/anarcha-feminism.png differ diff --git a/static/flags/anarchism.png b/static/flags/anarchism.png new file mode 100644 index 00000000..874fa8c9 Binary files /dev/null and b/static/flags/anarchism.png differ diff --git a/static/flags/anarcho-capitalism.png b/static/flags/anarcho-capitalism.png new file mode 100644 index 00000000..56a8e2bc Binary files /dev/null and b/static/flags/anarcho-capitalism.png differ diff --git a/static/flags/anarcho-communism.png b/static/flags/anarcho-communism.png new file mode 100644 index 00000000..4ca49ae0 Binary files /dev/null and b/static/flags/anarcho-communism.png differ diff --git a/static/flags/anarcho-nihilism.png b/static/flags/anarcho-nihilism.png new file mode 100644 index 00000000..230c4ce4 Binary files /dev/null and b/static/flags/anarcho-nihilism.png differ diff --git a/static/flags/anarcho-primitivism.png b/static/flags/anarcho-primitivism.png new file mode 100644 index 00000000..daf71fe4 Binary files /dev/null and b/static/flags/anarcho-primitivism.png differ diff --git a/static/flags/ao.png b/static/flags/ao.png old mode 100755 new mode 100644 diff --git a/static/flags/ap.png b/static/flags/ap.png old mode 100755 new mode 100644 diff --git a/static/flags/aq.png b/static/flags/aq.png old mode 100755 new mode 100644 diff --git a/static/flags/ar.png b/static/flags/ar.png old mode 100755 new mode 100644 diff --git a/static/flags/as.png b/static/flags/as.png old mode 100755 new mode 100644 diff --git a/static/flags/at.png b/static/flags/at.png old mode 100755 new mode 100644 diff --git a/static/flags/athiesm.png b/static/flags/athiesm.png new file mode 100644 index 00000000..9dae35c4 Binary files /dev/null and b/static/flags/athiesm.png differ diff --git a/static/flags/au.png b/static/flags/au.png old mode 100755 new mode 100644 diff --git a/static/flags/aw.png b/static/flags/aw.png old mode 100755 new mode 100644 diff --git a/static/flags/ax.png b/static/flags/ax.png old mode 100755 new mode 100644 diff --git a/static/flags/az.png b/static/flags/az.png old mode 100755 new mode 100644 diff --git a/static/flags/ba.png b/static/flags/ba.png old mode 100755 new mode 100644 diff --git a/static/flags/bb.png b/static/flags/bb.png old mode 100755 new mode 100644 diff --git a/static/flags/bd.png b/static/flags/bd.png old mode 100755 new mode 100644 diff --git a/static/flags/be.png b/static/flags/be.png old mode 100755 new mode 100644 diff --git a/static/flags/bf.png b/static/flags/bf.png old mode 100755 new mode 100644 diff --git a/static/flags/bg.png b/static/flags/bg.png old mode 100755 new mode 100644 diff --git a/static/flags/bh.png b/static/flags/bh.png old mode 100755 new mode 100644 diff --git a/static/flags/bi.png b/static/flags/bi.png old mode 100755 new mode 100644 diff --git a/static/flags/bj.png b/static/flags/bj.png old mode 100755 new mode 100644 diff --git a/static/flags/bl.png b/static/flags/bl.png old mode 100755 new mode 100644 diff --git a/static/flags/bm.png b/static/flags/bm.png old mode 100755 new mode 100644 diff --git a/static/flags/bn.png b/static/flags/bn.png old mode 100755 new mode 100644 diff --git a/static/flags/bo.png b/static/flags/bo.png old mode 100755 new mode 100644 diff --git a/static/flags/bolshevik.png b/static/flags/bolshevik.png new file mode 100644 index 00000000..1f8be7c6 Binary files /dev/null and b/static/flags/bolshevik.png differ diff --git a/static/flags/bq.png b/static/flags/bq.png old mode 100755 new mode 100644 diff --git a/static/flags/br.png b/static/flags/br.png old mode 100755 new mode 100644 diff --git a/static/flags/brocialism.png b/static/flags/brocialism.png new file mode 100644 index 00000000..aead15a1 Binary files /dev/null and b/static/flags/brocialism.png differ diff --git a/static/flags/bs.png b/static/flags/bs.png old mode 100755 new mode 100644 diff --git a/static/flags/bt.png b/static/flags/bt.png old mode 100755 new mode 100644 diff --git a/static/flags/bu.png b/static/flags/bu.png old mode 100755 new mode 100644 diff --git a/static/flags/burkina_faso.png b/static/flags/burkina_faso.png new file mode 100644 index 00000000..b95f0aa8 Binary files /dev/null and b/static/flags/burkina_faso.png differ diff --git a/static/flags/bv.png b/static/flags/bv.png old mode 100755 new mode 100644 diff --git a/static/flags/bw.png b/static/flags/bw.png old mode 100755 new mode 100644 diff --git a/static/flags/by.png b/static/flags/by.png old mode 100755 new mode 100644 diff --git a/static/flags/bz.png b/static/flags/bz.png old mode 100755 new mode 100644 diff --git a/static/flags/ca.png b/static/flags/ca.png old mode 100755 new mode 100644 diff --git a/static/flags/cat.png b/static/flags/cat.png old mode 100755 new mode 100644 diff --git a/static/flags/cc.png b/static/flags/cc.png old mode 100755 new mode 100644 diff --git a/static/flags/cd.png b/static/flags/cd.png old mode 100755 new mode 100644 diff --git a/static/flags/cf.png b/static/flags/cf.png old mode 100755 new mode 100644 diff --git a/static/flags/cg.png b/static/flags/cg.png old mode 100755 new mode 100644 diff --git a/static/flags/ch.png b/static/flags/ch.png old mode 100755 new mode 100644 diff --git a/static/flags/chavismo.png b/static/flags/chavismo.png new file mode 100644 index 00000000..aad7b228 Binary files /dev/null and b/static/flags/chavismo.png differ diff --git a/static/flags/che.png b/static/flags/che.png new file mode 100644 index 00000000..4bd2d5d5 Binary files /dev/null and b/static/flags/che.png differ diff --git a/static/flags/china.png b/static/flags/china.png new file mode 100644 index 00000000..d14198d8 Binary files /dev/null and b/static/flags/china.png differ diff --git a/static/flags/christian_communism.png b/static/flags/christian_communism.png new file mode 100644 index 00000000..90417239 Binary files /dev/null and b/static/flags/christian_communism.png differ diff --git a/static/flags/ci.png b/static/flags/ci.png old mode 100755 new mode 100644 diff --git a/static/flags/ck.png b/static/flags/ck.png old mode 100755 new mode 100644 diff --git a/static/flags/cl.png b/static/flags/cl.png old mode 100755 new mode 100644 diff --git a/static/flags/cm.png b/static/flags/cm.png old mode 100755 new mode 100644 diff --git a/static/flags/cn.png b/static/flags/cn.png old mode 100755 new mode 100644 diff --git a/static/flags/co.png b/static/flags/co.png old mode 100755 new mode 100644 diff --git a/static/flags/cockshott.png b/static/flags/cockshott.png new file mode 100644 index 00000000..08a3cd1e Binary files /dev/null and b/static/flags/cockshott.png differ diff --git a/static/flags/cp.png b/static/flags/cp.png old mode 100755 new mode 100644 diff --git a/static/flags/cr.png b/static/flags/cr.png old mode 100755 new mode 100644 diff --git a/static/flags/cs.png b/static/flags/cs.png old mode 100755 new mode 100644 diff --git a/static/flags/cu.png b/static/flags/cu.png old mode 100755 new mode 100644 diff --git a/static/flags/cuba.png b/static/flags/cuba.png new file mode 100644 index 00000000..e620bf5c Binary files /dev/null and b/static/flags/cuba.png differ diff --git a/static/flags/cv.png b/static/flags/cv.png old mode 100755 new mode 100644 diff --git a/static/flags/cw.png b/static/flags/cw.png old mode 100755 new mode 100644 diff --git a/static/flags/cx.png b/static/flags/cx.png old mode 100755 new mode 100644 diff --git a/static/flags/cy.png b/static/flags/cy.png old mode 100755 new mode 100644 diff --git a/static/flags/cz.png b/static/flags/cz.png old mode 100755 new mode 100644 diff --git a/static/flags/ddr.png b/static/flags/ddr.png new file mode 100644 index 00000000..03fae1a1 Binary files /dev/null and b/static/flags/ddr.png differ diff --git a/static/flags/de.png b/static/flags/de.png old mode 100755 new mode 100644 diff --git a/static/flags/democrap.png b/static/flags/democrap.png new file mode 100644 index 00000000..70cfe3ac Binary files /dev/null and b/static/flags/democrap.png differ diff --git a/static/flags/democratic_socialism.png b/static/flags/democratic_socialism.png new file mode 100644 index 00000000..420b0a12 Binary files /dev/null and b/static/flags/democratic_socialism.png differ diff --git a/static/flags/dg.png b/static/flags/dg.png old mode 100755 new mode 100644 diff --git a/static/flags/dj.png b/static/flags/dj.png old mode 100755 new mode 100644 diff --git a/static/flags/dk.png b/static/flags/dk.png old mode 100755 new mode 100644 diff --git a/static/flags/dm.png b/static/flags/dm.png old mode 100755 new mode 100644 diff --git a/static/flags/do.png b/static/flags/do.png old mode 100755 new mode 100644 diff --git a/static/flags/dprk.png b/static/flags/dprk.png new file mode 100644 index 00000000..265285d8 Binary files /dev/null and b/static/flags/dprk.png differ diff --git a/static/flags/dz.png b/static/flags/dz.png old mode 100755 new mode 100644 diff --git a/static/flags/ea.png b/static/flags/ea.png old mode 100755 new mode 100644 diff --git a/static/flags/ec.png b/static/flags/ec.png old mode 100755 new mode 100644 diff --git a/static/flags/ee.png b/static/flags/ee.png old mode 100755 new mode 100644 diff --git a/static/flags/eg.png b/static/flags/eg.png old mode 100755 new mode 100644 diff --git a/static/flags/eh.png b/static/flags/eh.png old mode 100755 new mode 100644 diff --git a/static/flags/er.png b/static/flags/er.png old mode 100755 new mode 100644 diff --git a/static/flags/es.png b/static/flags/es.png old mode 100755 new mode 100644 diff --git a/static/flags/et.png b/static/flags/et.png old mode 100755 new mode 100644 diff --git a/static/flags/eu.png b/static/flags/eu.png old mode 100755 new mode 100644 diff --git a/static/flags/eurocommunism.png b/static/flags/eurocommunism.png new file mode 100644 index 00000000..3d73f8b8 Binary files /dev/null and b/static/flags/eurocommunism.png differ diff --git a/static/flags/fed.png b/static/flags/fed.png new file mode 100644 index 00000000..0030a026 Binary files /dev/null and b/static/flags/fed.png differ diff --git a/static/flags/fi.png b/static/flags/fi.png old mode 100755 new mode 100644 diff --git a/static/flags/fj.png b/static/flags/fj.png old mode 100755 new mode 100644 diff --git a/static/flags/fk.png b/static/flags/fk.png old mode 100755 new mode 100644 diff --git a/static/flags/fm.png b/static/flags/fm.png old mode 100755 new mode 100644 diff --git a/static/flags/fo.png b/static/flags/fo.png old mode 100755 new mode 100644 diff --git a/static/flags/fr.png b/static/flags/fr.png old mode 100755 new mode 100644 diff --git a/static/flags/freud.png b/static/flags/freud.png new file mode 100644 index 00000000..2e077c5f Binary files /dev/null and b/static/flags/freud.png differ diff --git a/static/flags/fx.png b/static/flags/fx.png old mode 100755 new mode 100644 diff --git a/static/flags/ga.png b/static/flags/ga.png old mode 100755 new mode 100644 diff --git a/static/flags/gadsden.png b/static/flags/gadsden.png new file mode 100644 index 00000000..3ffae9fa Binary files /dev/null and b/static/flags/gadsden.png differ diff --git a/static/flags/gay_nazi.png b/static/flags/gay_nazi.png new file mode 100644 index 00000000..93d509ec Binary files /dev/null and b/static/flags/gay_nazi.png differ diff --git a/static/flags/gb.png b/static/flags/gb.png old mode 100755 new mode 100644 diff --git a/static/flags/gd.png b/static/flags/gd.png old mode 100755 new mode 100644 diff --git a/static/flags/ge.png b/static/flags/ge.png old mode 100755 new mode 100644 diff --git a/static/flags/gentoo.png b/static/flags/gentoo.png new file mode 100644 index 00000000..068b2c6b Binary files /dev/null and b/static/flags/gentoo.png differ diff --git a/static/flags/gf.png b/static/flags/gf.png old mode 100755 new mode 100644 diff --git a/static/flags/gg.png b/static/flags/gg.png old mode 100755 new mode 100644 diff --git a/static/flags/gh.png b/static/flags/gh.png old mode 100755 new mode 100644 diff --git a/static/flags/gi.png b/static/flags/gi.png old mode 100755 new mode 100644 diff --git a/static/flags/gl.png b/static/flags/gl.png old mode 100755 new mode 100644 diff --git a/static/flags/gm.png b/static/flags/gm.png old mode 100755 new mode 100644 diff --git a/static/flags/gn.png b/static/flags/gn.png old mode 100755 new mode 100644 diff --git a/static/flags/gorro.png b/static/flags/gorro.png new file mode 100644 index 00000000..c43af754 Binary files /dev/null and b/static/flags/gorro.png differ diff --git a/static/flags/gp.png b/static/flags/gp.png old mode 100755 new mode 100644 diff --git a/static/flags/gq.png b/static/flags/gq.png old mode 100755 new mode 100644 diff --git a/static/flags/gr.png b/static/flags/gr.png old mode 100755 new mode 100644 diff --git a/static/flags/groucho_marxism.png b/static/flags/groucho_marxism.png new file mode 100644 index 00000000..4ed90672 Binary files /dev/null and b/static/flags/groucho_marxism.png differ diff --git a/static/flags/gs.png b/static/flags/gs.png old mode 100755 new mode 100644 diff --git a/static/flags/gt.png b/static/flags/gt.png old mode 100755 new mode 100644 diff --git a/static/flags/gu.png b/static/flags/gu.png old mode 100755 new mode 100644 diff --git a/static/flags/gw.png b/static/flags/gw.png old mode 100755 new mode 100644 diff --git a/static/flags/gy.png b/static/flags/gy.png old mode 100755 new mode 100644 diff --git a/static/flags/hammer_&_sickle.png b/static/flags/hammer_&_sickle.png new file mode 100644 index 00000000..e3f7f54f Binary files /dev/null and b/static/flags/hammer_&_sickle.png differ diff --git a/static/flags/hk.png b/static/flags/hk.png old mode 100755 new mode 100644 diff --git a/static/flags/hm.png b/static/flags/hm.png old mode 100755 new mode 100644 diff --git a/static/flags/hn.png b/static/flags/hn.png old mode 100755 new mode 100644 diff --git a/static/flags/hr.png b/static/flags/hr.png old mode 100755 new mode 100644 diff --git a/static/flags/ht.png b/static/flags/ht.png old mode 100755 new mode 100644 diff --git a/static/flags/hu.png b/static/flags/hu.png old mode 100755 new mode 100644 diff --git a/static/flags/ic.png b/static/flags/ic.png old mode 100755 new mode 100644 diff --git a/static/flags/id.png b/static/flags/id.png old mode 100755 new mode 100644 diff --git a/static/flags/ie.png b/static/flags/ie.png old mode 100755 new mode 100644 diff --git a/static/flags/il.png b/static/flags/il.png old mode 100755 new mode 100644 diff --git a/static/flags/im.png b/static/flags/im.png old mode 100755 new mode 100644 diff --git a/static/flags/in.png b/static/flags/in.png old mode 100755 new mode 100644 diff --git a/static/flags/international_brigade.png b/static/flags/international_brigade.png new file mode 100644 index 00000000..98e6129f Binary files /dev/null and b/static/flags/international_brigade.png differ diff --git a/static/flags/io.png b/static/flags/io.png old mode 100755 new mode 100644 diff --git a/static/flags/iq.png b/static/flags/iq.png old mode 100755 new mode 100644 diff --git a/static/flags/ir.png b/static/flags/ir.png old mode 100755 new mode 100644 diff --git a/static/flags/ira.png b/static/flags/ira.png new file mode 100644 index 00000000..5fc50ec4 Binary files /dev/null and b/static/flags/ira.png differ diff --git a/static/flags/is.png b/static/flags/is.png old mode 100755 new mode 100644 diff --git a/static/flags/islamic_communism.png b/static/flags/islamic_communism.png new file mode 100644 index 00000000..87bad7a9 Binary files /dev/null and b/static/flags/islamic_communism.png differ diff --git a/static/flags/it.png b/static/flags/it.png old mode 100755 new mode 100644 diff --git a/static/flags/iww.png b/static/flags/iww.png new file mode 100644 index 00000000..8d3f6358 Binary files /dev/null and b/static/flags/iww.png differ diff --git a/static/flags/je.png b/static/flags/je.png old mode 100755 new mode 100644 diff --git a/static/flags/jm.png b/static/flags/jm.png old mode 100755 new mode 100644 diff --git a/static/flags/jo.png b/static/flags/jo.png old mode 100755 new mode 100644 diff --git a/static/flags/jp.png b/static/flags/jp.png old mode 100755 new mode 100644 diff --git a/static/flags/juche.png b/static/flags/juche.png new file mode 100644 index 00000000..1df65494 Binary files /dev/null and b/static/flags/juche.png differ diff --git a/static/flags/kampuchea.png b/static/flags/kampuchea.png new file mode 100644 index 00000000..6df06b21 Binary files /dev/null and b/static/flags/kampuchea.png differ diff --git a/static/flags/ke.png b/static/flags/ke.png old mode 100755 new mode 100644 diff --git a/static/flags/kg.png b/static/flags/kg.png old mode 100755 new mode 100644 diff --git a/static/flags/kh.png b/static/flags/kh.png old mode 100755 new mode 100644 diff --git a/static/flags/ki.png b/static/flags/ki.png old mode 100755 new mode 100644 diff --git a/static/flags/km.png b/static/flags/km.png old mode 100755 new mode 100644 diff --git a/static/flags/kn.png b/static/flags/kn.png old mode 100755 new mode 100644 diff --git a/static/flags/kp.png b/static/flags/kp.png old mode 100755 new mode 100644 diff --git a/static/flags/kr.png b/static/flags/kr.png old mode 100755 new mode 100644 diff --git a/static/flags/kw.png b/static/flags/kw.png old mode 100755 new mode 100644 diff --git a/static/flags/ky.png b/static/flags/ky.png old mode 100755 new mode 100644 diff --git a/static/flags/kz.png b/static/flags/kz.png old mode 100755 new mode 100644 diff --git a/static/flags/la.png b/static/flags/la.png old mode 100755 new mode 100644 diff --git a/static/flags/lb.png b/static/flags/lb.png old mode 100755 new mode 100644 diff --git a/static/flags/lc.png b/static/flags/lc.png old mode 100755 new mode 100644 diff --git a/static/flags/left_communism.png b/static/flags/left_communism.png new file mode 100644 index 00000000..0ba0c5fa Binary files /dev/null and b/static/flags/left_communism.png differ diff --git a/static/flags/lenin_cap.png b/static/flags/lenin_cap.png new file mode 100644 index 00000000..bfca6c7f Binary files /dev/null and b/static/flags/lenin_cap.png differ diff --git a/static/flags/li.png b/static/flags/li.png old mode 100755 new mode 100644 diff --git a/static/flags/lk.png b/static/flags/lk.png old mode 100755 new mode 100644 diff --git a/static/flags/lr.png b/static/flags/lr.png old mode 100755 new mode 100644 diff --git a/static/flags/ls.png b/static/flags/ls.png old mode 100755 new mode 100644 diff --git a/static/flags/lt.png b/static/flags/lt.png old mode 100755 new mode 100644 diff --git a/static/flags/lu.png b/static/flags/lu.png old mode 100755 new mode 100644 diff --git a/static/flags/luxemburg.png b/static/flags/luxemburg.png new file mode 100644 index 00000000..137cb664 Binary files /dev/null and b/static/flags/luxemburg.png differ diff --git a/static/flags/lv.png b/static/flags/lv.png old mode 100755 new mode 100644 diff --git a/static/flags/ly.png b/static/flags/ly.png old mode 100755 new mode 100644 diff --git a/static/flags/ma.png b/static/flags/ma.png old mode 100755 new mode 100644 diff --git a/static/flags/marx.png b/static/flags/marx.png new file mode 100644 index 00000000..ed80b898 Binary files /dev/null and b/static/flags/marx.png differ diff --git a/static/flags/mc.png b/static/flags/mc.png old mode 100755 new mode 100644 diff --git a/static/flags/md.png b/static/flags/md.png old mode 100755 new mode 100644 diff --git a/static/flags/me.png b/static/flags/me.png old mode 100755 new mode 100644 diff --git a/static/flags/mf.png b/static/flags/mf.png old mode 100755 new mode 100644 diff --git a/static/flags/mg.png b/static/flags/mg.png old mode 100755 new mode 100644 diff --git a/static/flags/mh.png b/static/flags/mh.png old mode 100755 new mode 100644 diff --git a/static/flags/mk.png b/static/flags/mk.png old mode 100755 new mode 100644 diff --git a/static/flags/ml.png b/static/flags/ml.png old mode 100755 new mode 100644 diff --git a/static/flags/mm.png b/static/flags/mm.png old mode 100755 new mode 100644 diff --git a/static/flags/mn.png b/static/flags/mn.png old mode 100755 new mode 100644 diff --git a/static/flags/mo.png b/static/flags/mo.png old mode 100755 new mode 100644 diff --git a/static/flags/mp.png b/static/flags/mp.png old mode 100755 new mode 100644 diff --git a/static/flags/mq.png b/static/flags/mq.png old mode 100755 new mode 100644 diff --git a/static/flags/mr.png b/static/flags/mr.png old mode 100755 new mode 100644 diff --git a/static/flags/ms.png b/static/flags/ms.png old mode 100755 new mode 100644 diff --git a/static/flags/mt.png b/static/flags/mt.png old mode 100755 new mode 100644 diff --git a/static/flags/mu.png b/static/flags/mu.png old mode 100755 new mode 100644 diff --git a/static/flags/mutualism.png b/static/flags/mutualism.png new file mode 100644 index 00000000..d41efd1b Binary files /dev/null and b/static/flags/mutualism.png differ diff --git a/static/flags/mv.png b/static/flags/mv.png old mode 100755 new mode 100644 diff --git a/static/flags/mw.png b/static/flags/mw.png old mode 100755 new mode 100644 diff --git a/static/flags/mx.png b/static/flags/mx.png old mode 100755 new mode 100644 diff --git a/static/flags/my.png b/static/flags/my.png old mode 100755 new mode 100644 diff --git a/static/flags/mz.png b/static/flags/mz.png old mode 100755 new mode 100644 diff --git a/static/flags/na.png b/static/flags/na.png old mode 100755 new mode 100644 diff --git a/static/flags/naxalite.png b/static/flags/naxalite.png new file mode 100644 index 00000000..61699ecb Binary files /dev/null and b/static/flags/naxalite.png differ diff --git a/static/flags/nazbol.png b/static/flags/nazbol.png new file mode 100644 index 00000000..13a0d883 Binary files /dev/null and b/static/flags/nazbol.png differ diff --git a/static/flags/nazi.png b/static/flags/nazi.png new file mode 100644 index 00000000..096153b6 Binary files /dev/null and b/static/flags/nazi.png differ diff --git a/static/flags/nc.png b/static/flags/nc.png old mode 100755 new mode 100644 diff --git a/static/flags/ndfp.png b/static/flags/ndfp.png new file mode 100644 index 00000000..428f7e21 Binary files /dev/null and b/static/flags/ndfp.png differ diff --git a/static/flags/ne.png b/static/flags/ne.png old mode 100755 new mode 100644 diff --git a/static/flags/nf.png b/static/flags/nf.png old mode 100755 new mode 100644 diff --git a/static/flags/ng.png b/static/flags/ng.png old mode 100755 new mode 100644 diff --git a/static/flags/ni.png b/static/flags/ni.png old mode 100755 new mode 100644 diff --git a/static/flags/nl.png b/static/flags/nl.png old mode 100755 new mode 100644 diff --git a/static/flags/no.png b/static/flags/no.png old mode 100755 new mode 100644 diff --git a/static/flags/np.png b/static/flags/np.png old mode 100755 new mode 100644 diff --git a/static/flags/nr.png b/static/flags/nr.png old mode 100755 new mode 100644 diff --git a/static/flags/nt.png b/static/flags/nt.png old mode 100755 new mode 100644 diff --git a/static/flags/nu.png b/static/flags/nu.png old mode 100755 new mode 100644 diff --git a/static/flags/nz.png b/static/flags/nz.png old mode 100755 new mode 100644 diff --git a/static/flags/o1.png b/static/flags/o1.png old mode 100755 new mode 100644 diff --git a/static/flags/om.png b/static/flags/om.png old mode 100755 new mode 100644 diff --git a/static/flags/pa.png b/static/flags/pa.png old mode 100755 new mode 100644 diff --git a/static/flags/palestine.png b/static/flags/palestine.png new file mode 100644 index 00000000..c92eafa6 Binary files /dev/null and b/static/flags/palestine.png differ diff --git a/static/flags/pan-africanism.png b/static/flags/pan-africanism.png new file mode 100644 index 00000000..3b017f87 Binary files /dev/null and b/static/flags/pan-africanism.png differ diff --git a/static/flags/pe.png b/static/flags/pe.png old mode 100755 new mode 100644 diff --git a/static/flags/pf.png b/static/flags/pf.png old mode 100755 new mode 100644 diff --git a/static/flags/pg.png b/static/flags/pg.png old mode 100755 new mode 100644 diff --git a/static/flags/ph.png b/static/flags/ph.png old mode 100755 new mode 100644 diff --git a/static/flags/pirate.png b/static/flags/pirate.png new file mode 100644 index 00000000..854a584d Binary files /dev/null and b/static/flags/pirate.png differ diff --git a/static/flags/pk.png b/static/flags/pk.png old mode 100755 new mode 100644 diff --git a/static/flags/pl.png b/static/flags/pl.png old mode 100755 new mode 100644 diff --git a/static/flags/pm.png b/static/flags/pm.png old mode 100755 new mode 100644 diff --git a/static/flags/pn.png b/static/flags/pn.png old mode 100755 new mode 100644 diff --git a/static/flags/porky.png b/static/flags/porky.png new file mode 100644 index 00000000..beef13fe Binary files /dev/null and b/static/flags/porky.png differ diff --git a/static/flags/posadas.png b/static/flags/posadas.png new file mode 100644 index 00000000..b3682a5b Binary files /dev/null and b/static/flags/posadas.png differ diff --git a/static/flags/pr.png b/static/flags/pr.png old mode 100755 new mode 100644 diff --git a/static/flags/ps.png b/static/flags/ps.png old mode 100755 new mode 100644 diff --git a/static/flags/pt.png b/static/flags/pt.png old mode 100755 new mode 100644 diff --git a/static/flags/punk.png b/static/flags/punk.png new file mode 100644 index 00000000..feb9a01b Binary files /dev/null and b/static/flags/punk.png differ diff --git a/static/flags/pw.png b/static/flags/pw.png old mode 100755 new mode 100644 diff --git a/static/flags/py.png b/static/flags/py.png old mode 100755 new mode 100644 diff --git a/static/flags/qa.png b/static/flags/qa.png old mode 100755 new mode 100644 diff --git a/static/flags/raised_fist.png b/static/flags/raised_fist.png new file mode 100644 index 00000000..e1920ba9 Binary files /dev/null and b/static/flags/raised_fist.png differ diff --git a/static/flags/re.png b/static/flags/re.png old mode 100755 new mode 100644 diff --git a/static/flags/read_a_fucking_book.png b/static/flags/read_a_fucking_book.png new file mode 100644 index 00000000..1a4ccf52 Binary files /dev/null and b/static/flags/read_a_fucking_book.png differ diff --git a/static/flags/rethuglican.png b/static/flags/rethuglican.png new file mode 100644 index 00000000..e214f645 Binary files /dev/null and b/static/flags/rethuglican.png differ diff --git a/static/flags/ro.png b/static/flags/ro.png old mode 100755 new mode 100644 diff --git a/static/flags/ru.png b/static/flags/ru.png old mode 100755 new mode 100644 diff --git a/static/flags/rw.png b/static/flags/rw.png old mode 100755 new mode 100644 diff --git a/static/flags/sa.png b/static/flags/sa.png old mode 100755 new mode 100644 diff --git a/static/flags/sabo-tabby.png b/static/flags/sabo-tabby.png new file mode 100644 index 00000000..2f7fabfd Binary files /dev/null and b/static/flags/sabo-tabby.png differ diff --git a/static/flags/sandinista.png b/static/flags/sandinista.png new file mode 100644 index 00000000..72f85eec Binary files /dev/null and b/static/flags/sandinista.png differ diff --git a/static/flags/sb.png b/static/flags/sb.png old mode 100755 new mode 100644 diff --git a/static/flags/sc.png b/static/flags/sc.png old mode 100755 new mode 100644 diff --git a/static/flags/sd.png b/static/flags/sd.png old mode 100755 new mode 100644 diff --git a/static/flags/se.png b/static/flags/se.png old mode 100755 new mode 100644 diff --git a/static/flags/sendero_luminoso.png b/static/flags/sendero_luminoso.png new file mode 100644 index 00000000..b3f159fc Binary files /dev/null and b/static/flags/sendero_luminoso.png differ diff --git a/static/flags/sf.png b/static/flags/sf.png old mode 100755 new mode 100644 diff --git a/static/flags/sg.png b/static/flags/sg.png old mode 100755 new mode 100644 diff --git a/static/flags/sh.png b/static/flags/sh.png old mode 100755 new mode 100644 diff --git a/static/flags/si.png b/static/flags/si.png old mode 100755 new mode 100644 diff --git a/static/flags/sj.png b/static/flags/sj.png old mode 100755 new mode 100644 diff --git a/static/flags/sk.png b/static/flags/sk.png old mode 100755 new mode 100644 diff --git a/static/flags/sl.png b/static/flags/sl.png old mode 100755 new mode 100644 diff --git a/static/flags/slavoj.png b/static/flags/slavoj.png new file mode 100644 index 00000000..42a8a60a Binary files /dev/null and b/static/flags/slavoj.png differ diff --git a/static/flags/sm.png b/static/flags/sm.png old mode 100755 new mode 100644 diff --git a/static/flags/sn.png b/static/flags/sn.png old mode 100755 new mode 100644 diff --git a/static/flags/so.png b/static/flags/so.png old mode 100755 new mode 100644 diff --git a/static/flags/socialism.png b/static/flags/socialism.png new file mode 100644 index 00000000..dc5b4dd7 Binary files /dev/null and b/static/flags/socialism.png differ diff --git a/static/flags/soviet_union.png b/static/flags/soviet_union.png new file mode 100644 index 00000000..f8745d4f Binary files /dev/null and b/static/flags/soviet_union.png differ diff --git a/static/flags/spurdo.png b/static/flags/spurdo.png new file mode 100644 index 00000000..0f8997cd Binary files /dev/null and b/static/flags/spurdo.png differ diff --git a/static/flags/sr.png b/static/flags/sr.png old mode 100755 new mode 100644 diff --git a/static/flags/ss.png b/static/flags/ss.png old mode 100755 new mode 100644 diff --git a/static/flags/ssnp.png b/static/flags/ssnp.png new file mode 100644 index 00000000..949d777d Binary files /dev/null and b/static/flags/ssnp.png differ diff --git a/static/flags/st.png b/static/flags/st.png old mode 100755 new mode 100644 diff --git a/static/flags/stalin.png b/static/flags/stalin.png new file mode 100644 index 00000000..e52410c0 Binary files /dev/null and b/static/flags/stalin.png differ diff --git a/static/flags/su.png b/static/flags/su.png old mode 100755 new mode 100644 diff --git a/static/flags/sv.png b/static/flags/sv.png old mode 100755 new mode 100644 diff --git a/static/flags/sx.png b/static/flags/sx.png old mode 100755 new mode 100644 diff --git a/static/flags/sy.png b/static/flags/sy.png old mode 100755 new mode 100644 diff --git a/static/flags/syndicalism.png b/static/flags/syndicalism.png new file mode 100644 index 00000000..78823ed9 Binary files /dev/null and b/static/flags/syndicalism.png differ diff --git a/static/flags/sz.png b/static/flags/sz.png old mode 100755 new mode 100644 diff --git a/static/flags/ta.png b/static/flags/ta.png old mode 100755 new mode 100644 diff --git a/static/flags/tankie.png b/static/flags/tankie.png new file mode 100644 index 00000000..abeb2d73 Binary files /dev/null and b/static/flags/tankie.png differ diff --git a/static/flags/tc.png b/static/flags/tc.png old mode 100755 new mode 100644 diff --git a/static/flags/td.png b/static/flags/td.png old mode 100755 new mode 100644 diff --git a/static/flags/tf.png b/static/flags/tf.png old mode 100755 new mode 100644 diff --git a/static/flags/tg.png b/static/flags/tg.png old mode 100755 new mode 100644 diff --git a/static/flags/th.png b/static/flags/th.png old mode 100755 new mode 100644 diff --git a/static/flags/think.png b/static/flags/think.png new file mode 100644 index 00000000..350664ff Binary files /dev/null and b/static/flags/think.png differ diff --git a/static/flags/ti.png b/static/flags/ti.png old mode 100755 new mode 100644 diff --git a/static/flags/tj.png b/static/flags/tj.png old mode 100755 new mode 100644 diff --git a/static/flags/tk.png b/static/flags/tk.png old mode 100755 new mode 100644 diff --git a/static/flags/tl.png b/static/flags/tl.png old mode 100755 new mode 100644 diff --git a/static/flags/tm.png b/static/flags/tm.png old mode 100755 new mode 100644 diff --git a/static/flags/tn.png b/static/flags/tn.png old mode 100755 new mode 100644 diff --git a/static/flags/to.png b/static/flags/to.png old mode 100755 new mode 100644 diff --git a/static/flags/tp.png b/static/flags/tp.png old mode 100755 new mode 100644 diff --git a/static/flags/tr.png b/static/flags/tr.png old mode 100755 new mode 100644 diff --git a/static/flags/tt.png b/static/flags/tt.png old mode 100755 new mode 100644 diff --git a/static/flags/tv.png b/static/flags/tv.png old mode 100755 new mode 100644 diff --git a/static/flags/tw.png b/static/flags/tw.png old mode 100755 new mode 100644 diff --git a/static/flags/tz.png b/static/flags/tz.png old mode 100755 new mode 100644 diff --git a/static/flags/ua.png b/static/flags/ua.png old mode 100755 new mode 100644 diff --git a/static/flags/ug.png b/static/flags/ug.png old mode 100755 new mode 100644 diff --git a/static/flags/uk.png b/static/flags/uk.png old mode 100755 new mode 100644 diff --git a/static/flags/um.png b/static/flags/um.png old mode 100755 new mode 100644 diff --git a/static/flags/us.png b/static/flags/us.png old mode 100755 new mode 100644 diff --git a/static/flags/uy.png b/static/flags/uy.png old mode 100755 new mode 100644 diff --git a/static/flags/uz.png b/static/flags/uz.png old mode 100755 new mode 100644 diff --git a/static/flags/va.png b/static/flags/va.png old mode 100755 new mode 100644 diff --git a/static/flags/vc.png b/static/flags/vc.png old mode 100755 new mode 100644 diff --git a/static/flags/ve.png b/static/flags/ve.png old mode 100755 new mode 100644 diff --git a/static/flags/vg.png b/static/flags/vg.png old mode 100755 new mode 100644 diff --git a/static/flags/vi.png b/static/flags/vi.png old mode 100755 new mode 100644 diff --git a/static/flags/viet_cong.png b/static/flags/viet_cong.png new file mode 100644 index 00000000..4e124d88 Binary files /dev/null and b/static/flags/viet_cong.png differ diff --git a/static/flags/vn.png b/static/flags/vn.png old mode 100755 new mode 100644 diff --git a/static/flags/vu.png b/static/flags/vu.png old mode 100755 new mode 100644 diff --git a/static/flags/wf.png b/static/flags/wf.png old mode 100755 new mode 100644 diff --git a/static/flags/ws.png b/static/flags/ws.png old mode 100755 new mode 100644 diff --git a/static/flags/xx.png b/static/flags/xx.png old mode 100755 new mode 100644 diff --git a/static/flags/ye.png b/static/flags/ye.png old mode 100755 new mode 100644 diff --git a/static/flags/yt.png b/static/flags/yt.png old mode 100755 new mode 100644 diff --git a/static/flags/yu.png b/static/flags/yu.png old mode 100755 new mode 100644 diff --git a/static/flags/yugoslavia.png b/static/flags/yugoslavia.png new file mode 100644 index 00000000..d316bc7e Binary files /dev/null and b/static/flags/yugoslavia.png differ diff --git a/static/flags/za.png b/static/flags/za.png old mode 100755 new mode 100644 diff --git a/static/flags/zapatista.png b/static/flags/zapatista.png new file mode 100644 index 00000000..79d5e58d Binary files /dev/null and b/static/flags/zapatista.png differ diff --git a/static/flags/zm.png b/static/flags/zm.png old mode 100755 new mode 100644 diff --git a/static/flags/zr.png b/static/flags/zr.png old mode 100755 new mode 100644 diff --git a/static/flags/zw.png b/static/flags/zw.png old mode 100755 new mode 100644