From ee6db3f06354d703f07e5db7b700150d041de281 Mon Sep 17 00:00:00 2001 From: 8chan Date: Sat, 19 Jul 2014 18:40:06 +0000 Subject: [PATCH 1/4] No more automatic claiming --- claim-old.php | 123 ++++++++++++++++++++++++++++++++++++++++ claim.php | 120 +-------------------------------------- create.php | 2 - expire.php | 5 +- inc/instance-config.php | 5 +- 5 files changed, 132 insertions(+), 123 deletions(-) create mode 100644 claim-old.php diff --git a/claim-old.php b/claim-old.php new file mode 100644 index 00000000..77168ab1 --- /dev/null +++ b/claim-old.php @@ -0,0 +1,123 @@ +execute(); + $row = $query->fetch(); + $ago = (new DateTime)->sub(new DateInterval('P1W')); + $mod_ago = (new DateTime)->sub(new DateInterval('P2W')); + + $last_activity_date = new DateTime(); + $last_mod_date = new DateTime(); + + $last_activity_date->setTimestamp($row['time']); + + $query = query("SELECT id, username FROM mods WHERE boards = '$board'"); + $mods = $query->fetchAll(); + + if ($mods) { + $mod = $mods[0]['id']; + $query = query("SELECT MAX(time) AS time FROM modlogs WHERE `mod` = $mod"); + $a = $query->fetchAll(PDO::FETCH_COLUMN); + + if ($a[0]) { + $last_mod_date->setTimestamp($a[0]); + if (!$row['time']) + $last_activity_date->setTimestamp($a[0]); + } else {// no one ever logged in, try board creation time + $query = query("SELECT UNIX_TIMESTAMP(time) AS time FROM board_create WHERE uri = '$board'"); + $crt = $query->fetchAll(PDO::FETCH_COLUMN); + $last_activity_date->setTimestamp($crt[0]); + $last_mod_date = false; + } + } + + if ($mods and ($last_activity_date < $ago or ($last_mod_date and $last_mod_date < $mod_ago))) { + return array($last_activity_date, $last_mod_date, $mods); + } + else { + return false; + } +} + +// Find out the last activity for our board +if (!isset($_GET['claim'])) { +$title = "Boards that need new owners"; +$q = query("SELECT uri FROM boards"); +$body = '

The following boards have been abandoned by their owners or have less than one post in a seventy-two hour period. Think you can do a better job? Claim one! Note: You can only reclaim one board per IP per 72 hours. Choose carefully!

'; +$boards = $q->fetchAll(PDO::FETCH_COLUMN); + +$delete = array(); +foreach($boards as $board) { + $last_activity = last_activity($board); + + if ($last_activity) { + list($last_activity_date, $last_mod_date, $mods) = $last_activity; + + $delete[] = array('board' => $board, 'last_activity' => $last_activity_date, 'last_mod' => $last_mod_date); + $last_mod_f = $last_mod_date ? $last_mod_date->format('Y-m-d H:i:s') : 'never'; + $body .= ""; + + } +} +$body .= "
BoardLast activityLast mod loginReclaim
/{$board}/{$last_activity_date->format('Y-m-d H:i:s')}{$last_mod_f}
"; +} +else { +$query = prepare('SELECT `last` FROM ``claim`` WHERE `ip` = :ip'); +$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']); +$query->execute(); + +$r_last = $query->fetch(PDO::FETCH_ASSOC); +$last = new DateTime($r_last['last'], new DateTimeZone('UTC')); +$ago = (new DateTime('',new DateTimeZone('UTC')))->sub(new DateInterval('P3D')); +if ($last > $ago and $r_last) { +error('You already claimed a board today'); +} + +openBoard($_GET['claim']); + +$title = "Claiming board /{$board['uri']}/"; +$last_activity = last_activity($board['uri']); +if ($last_activity) { +list($last_activity_date, $last_mod_date, $mods) = $last_activity; + +$query = prepare('INSERT INTO ``claim``(`ip`, `last`) VALUES(:ip, NOW()) ON DUPLICATE KEY UPDATE `last`=NOW()'); +$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']); +$query->execute(); + +$password = base64_encode(openssl_random_pseudo_bytes(9)); +$salt = generate_salt(); +$hashed = hash('sha256', $salt . sha1($password)); + +$query = prepare('UPDATE ``mods`` SET `password` = :hashed, `salt` = :salt WHERE BINARY username = :mod'); +$query->bindValue(':hashed', $hashed); +$query->bindValue(':salt', $salt); +$query->bindValue(':mod', $mods[0]['username']); +$query->execute(); + +query(sprintf("UPDATE posts_%s SET ip = '127.0.0.1'", $board['uri'])); +$query = prepare("DELETE FROM bans WHERE board = :board"); +$query->bindValue(":board", $board['uri']); +$query->execute(); +_syslog(LOG_NOTICE, "Board claimed: {$board['uri']}"); + +$body = "

Please read the following instructions carefully:

+ +

The username of the admin of this board is {$mods[0]['username']}. Please write this down, you will need it to log in. It cannot be changed.

+

A new password has been generated for this board. It is {$password} . Please write this down, you will need it to log in. If you forget your password, it cannot be changed. You must wait to reclaim the board again! Do not lose it.

+

The URL you use to manage your board is 8chan.co/mod.php. Log in using the details above. Note: The board can still be claimed by another user until you log in for the first time or if it still meets the inactivity criteria, so post something!

+

+ +"; +} else { +error('Board active or does not exist, cannot be reclaimed.'); +} +} + +$config['default_stylesheet'] = array('Yotsuba B', $config['stylesheets']['Yotsuba B']); +echo Element("page.html", array("config" => $config, "body" => $body, "title" => $title)); +*/ diff --git a/claim.php b/claim.php index 9645a0f7..edc6669a 100644 --- a/claim.php +++ b/claim.php @@ -1,121 +1,5 @@ execute(); - $row = $query->fetch(); - $ago = (new DateTime)->sub(new DateInterval('P1W')); - $mod_ago = (new DateTime)->sub(new DateInterval('P2W')); +include 'inc/functions.php'; - $last_activity_date = new DateTime(); - $last_mod_date = new DateTime(); - - $last_activity_date->setTimestamp($row['time']); - - $query = query("SELECT id, username FROM mods WHERE boards = '$board'"); - $mods = $query->fetchAll(); - - if ($mods) { - $mod = $mods[0]['id']; - $query = query("SELECT MAX(time) AS time FROM modlogs WHERE `mod` = $mod"); - $a = $query->fetchAll(PDO::FETCH_COLUMN); - - if ($a[0]) { - $last_mod_date->setTimestamp($a[0]); - if (!$row['time']) - $last_activity_date->setTimestamp($a[0]); - } else {// no one ever logged in, try board creation time - $query = query("SELECT UNIX_TIMESTAMP(time) AS time FROM board_create WHERE uri = '$board'"); - $crt = $query->fetchAll(PDO::FETCH_COLUMN); - $last_activity_date->setTimestamp($crt[0]); - $last_mod_date = false; - } - } - - if ($mods and ($last_activity_date < $ago or ($last_mod_date and $last_mod_date < $mod_ago))) { - return array($last_activity_date, $last_mod_date, $mods); - } - else { - return false; - } -} - -// Find out the last activity for our board -if (!isset($_GET['claim'])) { -$title = "Boards that need new owners"; -$q = query("SELECT uri FROM boards"); -$body = '

The following boards have been abandoned by their owners or have less than one post in a seventy-two hour period. Think you can do a better job? Claim one! Note: You can only reclaim one board per IP per 72 hours. Choose carefully!

'; -$boards = $q->fetchAll(PDO::FETCH_COLUMN); - -$delete = array(); -foreach($boards as $board) { - $last_activity = last_activity($board); - - if ($last_activity) { - list($last_activity_date, $last_mod_date, $mods) = $last_activity; - - $delete[] = array('board' => $board, 'last_activity' => $last_activity_date, 'last_mod' => $last_mod_date); - $last_mod_f = $last_mod_date ? $last_mod_date->format('Y-m-d H:i:s') : 'never'; - $body .= ""; - - } -} -$body .= "
BoardLast activityLast mod loginReclaim
/{$board}/{$last_activity_date->format('Y-m-d H:i:s')}{$last_mod_f}
"; -} -else { -$query = prepare('SELECT `last` FROM ``claim`` WHERE `ip` = :ip'); -$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']); -$query->execute(); - -$r_last = $query->fetch(PDO::FETCH_ASSOC); -$last = new DateTime($r_last['last'], new DateTimeZone('UTC')); -$ago = (new DateTime('',new DateTimeZone('UTC')))->sub(new DateInterval('P3D')); -if ($last > $ago and $r_last) { -error('You already claimed a board today'); -} - -openBoard($_GET['claim']); - -$title = "Claiming board /{$board['uri']}/"; -$last_activity = last_activity($board['uri']); -if ($last_activity) { -list($last_activity_date, $last_mod_date, $mods) = $last_activity; - -$query = prepare('INSERT INTO ``claim``(`ip`, `last`) VALUES(:ip, NOW()) ON DUPLICATE KEY UPDATE `last`=NOW()'); -$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']); -$query->execute(); - -$password = base64_encode(openssl_random_pseudo_bytes(9)); -$salt = generate_salt(); -$hashed = hash('sha256', $salt . sha1($password)); - -$query = prepare('UPDATE ``mods`` SET `password` = :hashed, `salt` = :salt WHERE BINARY username = :mod'); -$query->bindValue(':hashed', $hashed); -$query->bindValue(':salt', $salt); -$query->bindValue(':mod', $mods[0]['username']); -$query->execute(); - -query(sprintf("UPDATE posts_%s SET ip = '127.0.0.1'", $board['uri'])); -$query = prepare("DELETE FROM bans WHERE board = :board"); -$query->bindValue(":board", $board['uri']); -$query->execute(); -_syslog(LOG_NOTICE, "Board claimed: {$board['uri']}"); - -$body = "

Please read the following instructions carefully:

- -

The username of the admin of this board is {$mods[0]['username']}. Please write this down, you will need it to log in. It cannot be changed.

-

A new password has been generated for this board. It is {$password} . Please write this down, you will need it to log in. If you forget your password, it cannot be changed. You must wait to reclaim the board again! Do not lose it.

-

The URL you use to manage your board is 8chan.co/mod.php. Log in using the details above. Note: The board can still be claimed by another user until you log in for the first time or if it still meets the inactivity criteria, so post something!

-

- -"; -} else { -error('Board active or does not exist, cannot be reclaimed.'); -} -} - -$config['default_stylesheet'] = array('Yotsuba B', $config['stylesheets']['Yotsuba B']); -echo Element("page.html", array("config" => $config, "body" => $body, "title" => $title)); +error('Automatic claiming is no longer available. To claim a board, send your request to admin@8chan.co along with the IP you used to post on that board.'); diff --git a/create.php b/create.php index d7da028b..70629b28 100644 --- a/create.php +++ b/create.php @@ -13,8 +13,6 @@ $publisher_html = $ayah->getPublisherHTML(); $password = base64_encode(openssl_random_pseudo_bytes(9)); $body = <<Did you know? Many boards with popular names on 8chan.co are abandoned and can be claimed by you. Click here to see the list and claim yours!

-
diff --git a/expire.php b/expire.php index 0ecad5e6..fb1f14cf 100644 --- a/expire.php +++ b/expire.php @@ -8,8 +8,8 @@ if (!(php_sapi_name() == "cli")) { $q = query("SELECT uri FROM boards"); $boards = $q->fetchAll(PDO::FETCH_COLUMN); $now = new DateTime(); -$ago = (new DateTime)->sub(new DateInterval('P30D')); -$mod_ago = (new DateTime)->sub(new DateInterval('P30D')); +$ago = (new DateTime)->sub(new DateInterval('P14D')); +$mod_ago = (new DateTime)->sub(new DateInterval('P14D')); // Find out the last activity for our board $delete = array(); @@ -60,6 +60,7 @@ $f = fopen('rip.txt', 'a'); fwrite($f, "--\r\n"); foreach($delete as $i => $d){ $s = "RIP /".$d['board']."/, created by ".$d['mod']?$d['mod']:'?'." and last active on ".$d['last_activity']->format('Y-m-d H:i:s.').($d['last_mod'] ? ' Mod last active on ' . $d['last_mod']->format('Y-m-d H:i:s.') : ' Mod never active.') . " Number of posts: {$d['count']}." . "\r\n"; + echo $s; fwrite($f, $s); openBoard($d['board']); diff --git a/inc/instance-config.php b/inc/instance-config.php index 86eea09e..03326f1f 100644 --- a/inc/instance-config.php +++ b/inc/instance-config.php @@ -8,6 +8,7 @@ * You can copy values from config.php (defaults) and paste them here. */ require_once "htmlpurifier-4.5.0/library/HTMLPurifier.auto.php"; +require_once "8chan-functions.php"; $config['db']['server'] = 'localhost'; @@ -102,7 +103,7 @@ require_once "htmlpurifier-4.5.0/library/HTMLPurifier.auto.php"; $config['markup'][] = array("/\[spoiler\](.+?)\[\/spoiler\]/", "\$1"); $config['markup'][] = array("/~~(.+?)~~/", "\$1"); - $config['boards'] = array(array('' => '/', '' => '/boards.html', '' => '/faq.html', '' => '/random.php', '' => '/create.php', '' => '/search.php', '' => '/claim.php', '' => '/mod.php', '' => 'https://qchat.rizon.net/?channels=#8chan'), array('b', 'meta', 'int'), array(''=>'https://twitter.com/infinitechan')); + $config['boards'] = array(array('' => '/', '' => '/boards.html', '' => '/faq.html', '' => '/random.php', '' => '/create.php', '' => '/search.php', '' => '/mod.php', '' => 'https://qchat.rizon.net/?channels=#8chan'), array('b', 'meta', 'int'), array(''=>'https://twitter.com/infinitechan')); $config['footer'][] = 'Proprietary Tinyboard changes & 8chan.co trademark and logo © 2013-2014 Fredrick Brennan'; $config['footer'][] = 'To make a DMCA request or report illegal content, please email admin@8chan.co or use the "Global Report" functionality on every page.'; @@ -357,3 +358,5 @@ EOT; '' ) ); + +$config['gzip_static'] = false; From 1d4955081d6a24e39df1e767ba8abdffa4d96881 Mon Sep 17 00:00:00 2001 From: 8chan Date: Sat, 19 Jul 2014 18:41:48 +0000 Subject: [PATCH 2/4] Fix 55ch cancer; can now see next page of posts, ?/recent uses templating system --- inc/mod/pages.php | 33 +++++++++++++-------------------- templates/mod/recent_posts.html | 12 ++++++++++-- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/inc/mod/pages.php b/inc/mod/pages.php index dd6622bd..daba799f 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -2270,6 +2270,7 @@ function mod_recent_posts($lim) { error($config['error']['noaccess']); $limit = (is_numeric($lim))? $lim : 25; + $last_time = (isset($_GET['last']) && is_numeric($_GET['last'])) ? $_GET['last'] : 0; $mod_boards = array(); $boards = listBoards(); @@ -2290,37 +2291,29 @@ function mod_recent_posts($lim) { $query .= sprintf('SELECT *, %s AS `board` FROM ``posts_%s`` UNION ALL ', $pdo->quote($board['uri']), $board['uri']); } // Remove the last "UNION ALL" seperator and complete the query - $query = preg_replace('/UNION ALL $/', ') AS `all_posts` ORDER BY `time` DESC LIMIT ' . $limit, $query); - $query = query($query) or error(db_error()); + $query = preg_replace('/UNION ALL $/', ') AS `all_posts` WHERE (`time` < :last_time OR NOT :last_time) ORDER BY `time` DESC LIMIT ' . $limit, $query); + $query = prepare($query); + $query->bindValue(':last_time', $last_time); + $query->execute() or error(db_error($query)); $posts = $query->fetchAll(PDO::FETCH_ASSOC); - $body = '

Viewing last '.$limit.' posts

-

View 25 | 50 | 100

- Erase local data'; - foreach ($posts as $post) { + foreach ($posts as &$post) { openBoard($post['board']); if (!$post['thread']) { // Still need to fix this: $po = new Thread($post, '?/', $mod, false); - $string = $po->build(true); - $string = '

/'.$post['board'].'/'.$post['id'].'
' . $string; + $post['built'] = $po->build(true); } else { $po = new Post($post, '?/', $mod); - $string = $po->build(true); - $string = '

/'.$post['board'].'/'.$post['id'].'
' . $string; + $post['built'] = $po->build(true); } - $body .= $string . '
'; + $last_time = $post['time']; } - echo Element('page.html', array( - 'config' => $config, - 'mod' => $mod, - 'hide_dashboard_link' => true, - 'title' => _('Recent posts'), - 'subtitle' => '', - 'nojavascript' => false, - 'is_recent_posts' => true, - 'body' => $body + echo mod_page(_('Recent posts'), 'mod/recent_posts.html', array( + 'posts' => $posts, + 'limit' => $limit, + 'last_time' => $last_time ) ); diff --git a/templates/mod/recent_posts.html b/templates/mod/recent_posts.html index 4a2f9baa..7e38881b 100644 --- a/templates/mod/recent_posts.html +++ b/templates/mod/recent_posts.html @@ -1,6 +1,14 @@ -{% if posts|count %} +{% if not posts|count %}

({% trans 'There are no active posts.' %})

{% else %} - +

Viewing last {{ limit|e }} posts

+

View 25 | 50 | 100

+ Erase local data
+ {% for post in posts %} +

/{{ post.board }}/{{ post.id }}
+ {{ post.built }} +
+ {% endfor %} {% endif %} +Next {{ limit }} posts From 76bd2fe4fa15eca4f93d54dfa50febab4bd0c62c Mon Sep 17 00:00:00 2001 From: 8chan Date: Mon, 21 Jul 2014 16:54:16 +0000 Subject: [PATCH 3/4] Fix rip.txt bug --- expire.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/expire.php b/expire.php index fb1f14cf..59c9a0c9 100644 --- a/expire.php +++ b/expire.php @@ -59,7 +59,7 @@ if ($argc > 1) { $f = fopen('rip.txt', 'a'); fwrite($f, "--\r\n"); foreach($delete as $i => $d){ - $s = "RIP /".$d['board']."/, created by ".$d['mod']?$d['mod']:'?'." and last active on ".$d['last_activity']->format('Y-m-d H:i:s.').($d['last_mod'] ? ' Mod last active on ' . $d['last_mod']->format('Y-m-d H:i:s.') : ' Mod never active.') . " Number of posts: {$d['count']}." . "\r\n"; + $s = "RIP /".$d['board']."/, created by ".($d['mod']?$d['mod']:'?')." and last active on ".$d['last_activity']->format('Y-m-d H:i:s.').($d['last_mod'] ? ' Mod last active on ' . $d['last_mod']->format('Y-m-d H:i:s.') : ' Mod never active.') . " Number of posts: {$d['count']}." . "\r\n"; echo $s; fwrite($f, $s); From 429882fc3985580d1fbe5ffd9a7ed22400d0e34f Mon Sep 17 00:00:00 2001 From: 8chan Date: Mon, 21 Jul 2014 16:54:51 +0000 Subject: [PATCH 4/4] Fix post linking bug in ?/recent --- templates/mod/recent_posts.html | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/templates/mod/recent_posts.html b/templates/mod/recent_posts.html index 7e38881b..bc9175e0 100644 --- a/templates/mod/recent_posts.html +++ b/templates/mod/recent_posts.html @@ -6,7 +6,12 @@

View 25 | 50 | 100

Erase local data {% for post in posts %} -

/{{ post.board }}/{{ post.id }}
+ {% if not post.thread %} + {% set thread = post.id %} + {% else %} + {% set thread = post.thread %} + {% endif %} +

/{{ post.board }}/{{ post.id }}
{{ post.built }}
{% endfor %}