Browse Source

Merge remote-tracking branch 'upstream/config' into frontpage2

pull/40/head
Comatoast 3 years ago
parent
commit
372919e849
  1. 14
      inc/config.php
  2. 34
      inc/filters.php
  3. 3
      inc/instance-config.php
  4. 22
      inc/mod/pages.php
  5. 2
      templates/themes/catalog/theme.php
  6. 43
      templates/themes/categories/news.html
  7. 72
      templates/themes/categories/theme.php

14
inc/config.php

@ -340,6 +340,8 @@
* Read more: http://tinyboard.org/docs/index.php?p=Config/Filters
*/
// Minimum time between between each opening post.
$config['flood_time_any'] = 40;
// Minimum time between between each post by the same IP address.
$config['flood_time'] = 10;
// Minimum time between between each post with the exact same content AND same IP address.
@ -347,6 +349,18 @@
// Same as above but by a different IP address. (Same content, not necessarily same IP address.)
$config['flood_time_same'] = 30;
$config['filters'][] = array(
'condition' => array(
'flood-match' => array('isreply'), // Only match IP address
'OP' => true,
'flood-time-any' => &$config['flood_time_any']
),
'noip' => true,
'find-time' => 60 * 60 * 1,
'action' => 'reject',
'message' => 'New threads are being created too quickly. Hmmm'
);
// Minimum time between posts by the same IP address (all boards).
$config['filters'][] = array(
'condition' => array(

34
inc/filters.php

@ -19,6 +19,7 @@ class Filter {
}
public function match($condition, $match) {
print_err("Filter condition: " . $condition);
$condition = strtolower($condition);
$post = &$this->post;
@ -68,9 +69,18 @@ class Filter {
$flood_check_matched[] = $flood_post;
}
// is there any reason for this assignment?
$this->flood_check = $flood_check_matched;
return !empty($this->flood_check);
case 'flood-time-any':
foreach ($this->flood_check as $flood_post) {
if (time() - $flood_post['time'] <= $match) {
print_err("rejecting post with flood id: " . $flood_post['id']);
return true;
}
}
return false;
case 'flood-time':
foreach ($this->flood_check as $flood_post) {
if (time() - $flood_post['time'] <= $match) {
@ -178,7 +188,9 @@ class Filter {
if ($condition[0] == '!') {
$NOT = true;
$condition = substr($condition, 1);
} else $NOT = false;
} else {
$NOT = false;
}
if ($this->match($condition, $value) == $NOT)
return false;
@ -217,14 +229,26 @@ function do_filters(array $post) {
if (!isset($config['filters']) || empty($config['filters']))
return;
// look at the flood table regardless of IP
$noip = false;
foreach ($config['filters'] as $filter) {
if (isset($filter['condition']['flood-match'])) {
if (isset($filter['condition']['flood-match']) && (!isset($filter['noip']) || $filter['noip'] == false)) {
$has_flood = true;
break;
} else if ($filter['noip'] == true) {
print_err("filters noip is true");
$noip = true;
$find_time = time() - $filter['find-time'];
}
}
if (isset($has_flood)) {
if ($noip) {
print_err("SELECT * FROM flood WHERE time > " . strval($find_time));
$query = prepare("SELECT * FROM ``flood`` WHERE `time` > $find_time");
$query->execute() or error(db_error($query));
$flood_check = $query->fetchAll(PDO::FETCH_ASSOC);
} else if (isset($has_flood)) {
if ($post['has_file']) {
$query = prepare("SELECT * FROM ``flood`` WHERE `ip` = :ip OR `posthash` = :posthash OR `filehash` = :filehash");
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
@ -242,11 +266,13 @@ function do_filters(array $post) {
}
foreach ($config['filters'] as $filter_array) {
print_err("creating new filter, running check");
$filter = new Filter($filter_array);
$filter->flood_check = $flood_check;
if ($filter->check($post))
if ($filter->check($post)) {
$filter->action();
}
}
purge_flood_table();
}

3
inc/instance-config.php

@ -82,6 +82,9 @@ $config['db']['password'] = '';
$config['cookies']['mod'] = 'mod';
$config['cookies']['salt'] = 'MGYwNjhlNjU5Y2QxNWU3YjQ3MzQ1Yj';
$config['flood_cache'] = 60 * 15; // 15 minutes. The oldest a post can be in the flood table
$config['flood_time_any'] = 40; // time between thread creation
$config['flood_time'] = 30;
$config['flood_time_ip'] = 60;
$config['flood_time_same'] = 60;

22
inc/mod/pages.php

@ -28,6 +28,12 @@ function mod_page($title, $template, $args, $subtitle = false) {
);
}
function clone_wrapped_with_exist_check($clonefn, $src, $dest) {
if (file_exists($src)) {
$clonefn($src, $dest);
}
}
function mod_login($redirect = false) {
global $config;
@ -1353,9 +1359,9 @@ function mod_move($originBoard, $postID) {
// copy image
foreach ($post['files'] as $i => &$file) {
if ($file['file'] !== 'deleted')
$clone($file['file_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $file['file']);
clone_wrapped_with_exist_check($clone, $file['file_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $file['file']);
if (isset($file['thumb']) && !in_array($file['thumb'], array('spoiler', 'deleted', 'file')))
$clone($file['thumb_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $file['thumb']);
clone_wrapped_with_exist_check($clone, $file['thumb_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $file['thumb']);
}
}
@ -1416,8 +1422,8 @@ function mod_move($originBoard, $postID) {
if ($post['has_file']) {
// copy image
foreach ($post['files'] as $i => &$file) {
$clone($file['file_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $file['file']);
$clone($file['thumb_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $file['thumb']);
clone_wrapped_with_exist_check($clone, $file['file_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $file['file']);
clone_wrapped_with_exist_check($clone, $file['thumb_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $file['thumb']);
}
}
// insert reply
@ -1610,9 +1616,9 @@ function mod_merge($originBoard, $postID) {
// copy image
foreach ($post['files'] as $i => &$file) {
if ($file['file'] !== 'deleted')
$clone($file['file_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $file['file']);
clone_wrapped_with_exist_check($clone, $file['file_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $file['file']);
if (isset($file['thumb']) && !in_array($file['thumb'], array('spoiler', 'deleted', 'file')))
$clone($file['thumb_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $file['thumb']);
clone_wrapped_with_exist_check($clone, $file['thumb_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $file['thumb']);
}
}
@ -1673,8 +1679,8 @@ function mod_merge($originBoard, $postID) {
if ($post['has_file']) {
// copy image
foreach ($post['files'] as $i => &$file) {
$clone($file['file_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $file['file']);
$clone($file['thumb_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $file['thumb']);
clone_wrapped_with_exist_check($clone, $file['file_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $file['file']);
clone_wrapped_with_exist_check($clone, $file['thumb_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $file['thumb']);
}
}
// insert reply

2
templates/themes/catalog/theme.php

@ -50,7 +50,7 @@
elseif ($action == 'rebuild') {
print_err("catalog_build calling Catalog.build 2");
$b->build($settings, $board);
if($settings['has_overboard']) {
if(isset($settings['has_overboard']) && $settings['has_overboard']) {
$b->buildOverboardCatalog($settings, $boards);
}
}

43
templates/themes/categories/news.html

@ -25,7 +25,48 @@
{% endfor %}
{% endif %}
</div>
{% if stats %}
<div class="ban" style="border: none; background: none;">
<h1 id="post-statistics">
{% trans "Post Statistics" %}
</h1>
</div>
<table class="modlog" style="width: 50%; text-align: left;">
<thead>
<tr>
<th>{% trans "Board" %}</th>
<th>{% trans "PPH" %}</th>
<th>{% trans "Recent IPs" %}</th>
</tr>
</thead>
<tbody>
<tr>
<td class="minimal">
<span>{% trans "Total" %}</span>
</td>
<td class="minimal">
<span>{{ stats.pph }}</span>
</td>
<td class="minimal">
<span>{{ stats.recent_ips }}</span>
</td>
</tr>
{% for boardStat in stats.boards %}
<tr>
<td class="minimal">
<span>{{ boardStat.title }}</span>
</td>
<td class="minimal">
<span>{{ boardStat.pph }}</span>
</td>
<td class="minimal">
<span>{{ boardStat.recent_ips }}</span>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
<footer>
<p class="unimportant" style="margin-top:20px;text-align:center;">- Tinyboard +
<a href="https://engine.vichan.net/">vichan</a> {{ config.version }} -

72
templates/themes/categories/theme.php

@ -15,21 +15,28 @@
public static function build($action, $settings) {
global $config;
if ($action == 'all')
if ($action == 'all' ||
$action == 'boards' ||
$action == 'news' ||
$action == 'post' ||
$action == 'post-thread' ||
$action == 'post-delete'){
file_write($config['dir']['home'] . $settings['file_main'], Categories::homepage($settings));
file_write($config['dir']['home'] . $settings['file_news'], Categories::news($settings));
}
if ($action == 'all' || $action == 'boards')
if ($action == 'all'){
file_write($config['dir']['home'] . $settings['file_sidebar'], Categories::sidebar($settings));
if ($action == 'all' || $action == 'news')
file_write($config['dir']['home'] . $settings['file_news'], Categories::news($settings));
}
}
// Build homepage
public static function homepage($settings) {
global $config;
$query = query("SELECT * FROM ``news`` ORDER BY `time` DESC") or error(db_error());
$news = $query->fetchAll(PDO::FETCH_ASSOC);
$stats = Categories::getPostStatistics($settings);
return Element(
'themes/categories/frames.html',
Array(
@ -37,6 +44,7 @@
'settings' => $settings,
'categories' => Categories::getCategories($config),
'news' => $news,
'stats' => $stats,
'boardlist' => createBoardlist(false)
)
@ -49,11 +57,12 @@
$query = query("SELECT * FROM ``news`` ORDER BY `time` DESC") or error(db_error());
$news = $query->fetchAll(PDO::FETCH_ASSOC);
$stats = Categories::getPostStatistics($settings);
return Element('themes/categories/news.html', Array(
'settings' => $settings,
'config' => $config,
'news' => $news,
'stats' => $stats,
'boardlist' => createBoardlist(false)
));
}
@ -83,6 +92,57 @@
return $categories;
}
private static function getPostStatistics($settings) {
global $config;
if (!isset($config['boards'])) {
return null;
}
$stats = [];
$unique = [];
foreach (array_merge(... $config['boards']) as $uri) {
$_board = getBoardInfo($uri);
if (!$_board) {
// board doesn't exist.
continue;
}
$boardStat['title'] = $_board['title'];
$pph_query = query(
sprintf("SELECT COUNT(*) AS count FROM ``posts_%s`` WHERE time > %d",
$_board['uri'],
time()-3600)
) or error(db_error());
$boardStat['pph'] = $pph_query->fetch()['count'];
$unique_query = query(
sprintf("SELECT DISTINCT ip FROM ``posts_%s`` WHERE time > %d",
$_board['uri'],
time()-3600)
) or error(db_error());
$unique_ips = $unique_query->fetchAll();
$boardStat['recent_ips'] = count($unique_ips);
foreach ($unique_ips as $_k => $row) {
$unique[$row['ip']] = true;
}
$stats['boards'][] = $boardStat;
}
$stats['recent_ips'] = count($unique);
$stats['pph'] = array_sum(array_column($stats['boards'], 'pph'));
return $stats;
}
};
?>

Loading…
Cancel
Save