1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-25 07:50:23 +01:00

Pull 8chan

This commit is contained in:
8chan 2014-08-10 14:43:16 +00:00
commit e59ee1c80e
6 changed files with 134 additions and 125 deletions

123
claim-old.php Normal file
View File

@ -0,0 +1,123 @@
<?php
/*
include "inc/functions.php";
include "inc/mod/auth.php";
function last_activity($board) {
// last post
$query = prepare(sprintf("SELECT MAX(time) AS time FROM posts_%s", $board));
$query->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 = '<p>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!</p><table class="modlog" style="width:auto"><thead><tr><th>Board</th><th>Last activity</th><th>Last mod login</th><th>Reclaim</th></thead></tr><tbody>';
$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') : '<em>never</em>';
$body .= "<tr><td><a href='/{$board}/'>/{$board}/</a></td><td>{$last_activity_date->format('Y-m-d H:i:s')}</td><td>{$last_mod_f}</td><td><form style='margin-bottom:0!important'><input type='hidden' name='claim' value='{$board}'><input type='submit' value='Claim!'></form></td></tr>";
}
}
$body .= "</table>";
}
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 = "<p>Please read the following instructions carefully:</p>
<p>The username of the admin of this board is <strong>{$mods[0]['username']}</strong>. Please write this down, you will need it to log in. It cannot be changed.</p>
<p>A new password has been generated for this board. It is <tt>{$password}</tt> . Please write this down, you will need it to log in. <em>If you forget your password, it cannot be changed. You must wait to reclaim the board again! Do not lose it.</em></p>
<p>The URL you use to manage your board is <a href='/mod.php'>8chan.co/mod.php</a>. 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!</p>
<p>
";
} 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));
*/

120
claim.php
View File

@ -1,121 +1,5 @@
<?php
include "inc/functions.php";
include "inc/mod/auth.php";
function last_activity($board) {
// last post
$query = prepare(sprintf("SELECT MAX(time) AS time FROM posts_%s", $board));
$query->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 = '<p>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!</p><table class="modlog" style="width:auto"><thead><tr><th>Board</th><th>Last activity</th><th>Last mod login</th><th>Reclaim</th></thead></tr><tbody>';
$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') : '<em>never</em>';
$body .= "<tr><td><a href='/{$board}/'>/{$board}/</a></td><td>{$last_activity_date->format('Y-m-d H:i:s')}</td><td>{$last_mod_f}</td><td><form style='margin-bottom:0!important'><input type='hidden' name='claim' value='{$board}'><input type='submit' value='Claim!'></form></td></tr>";
}
}
$body .= "</table>";
}
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 = "<p>Please read the following instructions carefully:</p>
<p>The username of the admin of this board is <strong>{$mods[0]['username']}</strong>. Please write this down, you will need it to log in. It cannot be changed.</p>
<p>A new password has been generated for this board. It is <tt>{$password}</tt> . Please write this down, you will need it to log in. <em>If you forget your password, it cannot be changed. You must wait to reclaim the board again! Do not lose it.</em></p>
<p>The URL you use to manage your board is <a href='/mod.php'>8chan.co/mod.php</a>. 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!</p>
<p>
";
} 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.');

View File

@ -13,8 +13,6 @@ $publisher_html = $ayah->getPublisherHTML();
$password = base64_encode(openssl_random_pseudo_bytes(9));
$body = <<<EOT
<p>Did you know? Many boards with popular names on 8chan.co are abandoned and can be claimed by you. <a href="/claim.php">Click here to see the list and claim yours!</a></p>
<form method="POST">
<table class="modlog" style="width:auto">
<tbody>

View File

@ -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();
@ -59,7 +59,8 @@ 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);
openBoard($d['board']);

View File

@ -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\]/", "<span class=\"spoiler\">\$1</span>");
$config['markup'][] = array("/~~(.+?)~~/", "<s>\$1</s>");
$config['boards'] = array(array('<i class="fa fa-home" title="Home"></i>' => '/', '<i class="fa fa-tags" title="Boards"></i>' => '/boards.html', '<i class="fa fa-question" title="FAQ"></i>' => '/faq.html', '<i class="fa fa-random" title="Random"></i>' => '/random.php', '<i class="fa fa-plus" title="New board"></i>' => '/create.php', '<i class="fa fa-search" title="Search"></i>' => '/search.php', '<i class="fa fa-chain-broken" title="Claim board"></i>' => '/claim.php', '<i class="fa fa-cog" title="Manage board"></i>' => '/mod.php', '<i class="fa fa-quote-right" title="Chat"></i>' => 'https://qchat.rizon.net/?channels=#8chan'), array('b', 'meta', 'int'), array('<i class="fa fa-twitter" title="Home"></i>'=>'https://twitter.com/infinitechan'));
$config['boards'] = array(array('<i class="fa fa-home" title="Home"></i>' => '/', '<i class="fa fa-tags" title="Boards"></i>' => '/boards.html', '<i class="fa fa-question" title="FAQ"></i>' => '/faq.html', '<i class="fa fa-random" title="Random"></i>' => '/random.php', '<i class="fa fa-plus" title="New board"></i>' => '/create.php', '<i class="fa fa-search" title="Search"></i>' => '/search.php', '<i class="fa fa-cog" title="Manage board"></i>' => '/mod.php', '<i class="fa fa-quote-right" title="Chat"></i>' => 'https://qchat.rizon.net/?channels=#8chan'), array('b', 'meta', 'int'), array('<i class="fa fa-twitter" title="Home"></i>'=>'https://twitter.com/infinitechan'));
$config['footer'][] = 'Proprietary Tinyboard changes &amp; 8chan.co trademark and logo &copy; 2013-2014 <a href="https://blog.8chan.co">Fredrick Brennan</a>';
$config['footer'][] = 'To make a DMCA request or report illegal content, please email <a href="mailto:admin@8chan.co">admin@8chan.co</a> or use the "Global Report" functionality on every page.';
@ -357,3 +358,5 @@ EOT;
'<object style="float: left;margin: 10px 20px;" width="148" height="44"><param name="movie" value="https://vocaroo.com/player.swf?playMediaID=$2&autoplay=0"></param><param name="wmode" value="transparent"></param><embed src="https://vocaroo.com/player.swf?playMediaID=$2&autoplay=0" width="148" height="44" wmode="transparent" type="application/x-shockwave-flash"></embed></object>'
)
);
$config['gzip_static'] = false;

View File

@ -16,4 +16,4 @@
</div>
{% endfor %}
{% endif %}
<a href="/mod.php?/recent/{{ limit|e }}&amp;last={{ last_time|e }}">Next {{ limit }} posts</a>
<a href="/mod.php?/recent/{{ limit }}&amp;last={{ last_time }}">Next {{ limit }} posts</a>