2012-04-12 19:29:08 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2013-01-20 05:23:46 -05:00
|
|
|
* Copyright (c) 2010-2013 Tinyboard Development Group
|
2012-04-12 19:29:08 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (realpath($_SERVER['SCRIPT_FILENAME']) == str_replace('\\', '/', __FILE__)) {
|
|
|
|
// You cannot request this file directly.
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
function parse_time($str) {
|
2012-04-12 19:47:27 -04:00
|
|
|
if (empty($str))
|
2012-04-12 19:29:08 -04:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (($time = @strtotime($str)) !== false)
|
|
|
|
return $time;
|
|
|
|
|
2012-04-16 02:40:24 -04:00
|
|
|
if (!preg_match('/^((\d+)\s?ye?a?r?s?)?\s?+((\d+)\s?mon?t?h?s?)?\s?+((\d+)\s?we?e?k?s?)?\s?+((\d+)\s?da?y?s?)?((\d+)\s?ho?u?r?s?)?\s?+((\d+)\s?mi?n?u?t?e?s?)?\s?+((\d+)\s?se?c?o?n?d?s?)?$/', $str, $matches))
|
2012-04-12 19:29:08 -04:00
|
|
|
return false;
|
|
|
|
|
2012-04-16 02:40:24 -04:00
|
|
|
$expire = 0;
|
|
|
|
|
|
|
|
if (isset($matches[2])) {
|
2012-04-12 19:29:08 -04:00
|
|
|
// Years
|
2012-04-16 02:40:24 -04:00
|
|
|
$expire += $matches[2]*60*60*24*365;
|
2012-04-12 19:29:08 -04:00
|
|
|
}
|
2012-04-16 02:40:24 -04:00
|
|
|
if (isset($matches[4])) {
|
2012-04-12 19:29:08 -04:00
|
|
|
// Months
|
2012-04-16 02:40:24 -04:00
|
|
|
$expire += $matches[4]*60*60*24*30;
|
2012-04-12 19:29:08 -04:00
|
|
|
}
|
2012-04-16 02:40:24 -04:00
|
|
|
if (isset($matches[6])) {
|
2012-04-12 19:29:08 -04:00
|
|
|
// Weeks
|
2012-04-16 02:40:24 -04:00
|
|
|
$expire += $matches[6]*60*60*24*7;
|
2012-04-12 19:29:08 -04:00
|
|
|
}
|
2012-04-16 02:40:24 -04:00
|
|
|
if (isset($matches[8])) {
|
2012-04-12 19:29:08 -04:00
|
|
|
// Days
|
2012-04-16 02:40:24 -04:00
|
|
|
$expire += $matches[8]*60*60*24;
|
2012-04-12 19:29:08 -04:00
|
|
|
}
|
2012-04-16 02:40:24 -04:00
|
|
|
if (isset($matches[10])) {
|
2012-04-12 19:29:08 -04:00
|
|
|
// Hours
|
2012-04-16 02:40:24 -04:00
|
|
|
$expire += $matches[10]*60*60;
|
2012-04-12 19:29:08 -04:00
|
|
|
}
|
2012-04-16 02:40:24 -04:00
|
|
|
if (isset($matches[12])) {
|
2012-04-12 19:29:08 -04:00
|
|
|
// Minutes
|
2012-04-16 02:40:24 -04:00
|
|
|
$expire += $matches[12]*60;
|
2012-04-12 19:29:08 -04:00
|
|
|
}
|
2012-04-16 02:40:24 -04:00
|
|
|
if (isset($matches[14])) {
|
2012-04-12 19:29:08 -04:00
|
|
|
// Seconds
|
2012-04-16 02:40:24 -04:00
|
|
|
$expire += $matches[14];
|
2012-04-12 19:29:08 -04:00
|
|
|
}
|
|
|
|
|
2012-04-16 02:40:24 -04:00
|
|
|
return time() + $expire;
|
2012-04-12 19:29:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function ban($mask, $reason, $length, $board) {
|
2012-04-16 02:40:24 -04:00
|
|
|
global $mod, $pdo;
|
2012-04-12 19:29:08 -04:00
|
|
|
|
2013-07-31 22:14:26 -04:00
|
|
|
$query = prepare("INSERT INTO ``bans`` VALUES (NULL, :ip, :mod, :time, :expires, :reason, :board, 0)");
|
2012-04-12 19:29:08 -04:00
|
|
|
$query->bindValue(':ip', $mask);
|
|
|
|
$query->bindValue(':mod', $mod['id']);
|
2012-04-12 19:47:27 -04:00
|
|
|
$query->bindValue(':time', time());
|
|
|
|
if ($reason !== '') {
|
2013-07-31 20:33:27 -04:00
|
|
|
$reason = escape_markup_modifiers($reason);
|
|
|
|
$reason = markup($reason);
|
2012-04-12 19:29:08 -04:00
|
|
|
$query->bindValue(':reason', $reason);
|
2012-04-12 19:47:27 -04:00
|
|
|
} else
|
2012-04-12 19:29:08 -04:00
|
|
|
$query->bindValue(':reason', null, PDO::PARAM_NULL);
|
|
|
|
|
|
|
|
if ($length > 0)
|
2012-04-12 19:47:27 -04:00
|
|
|
$query->bindValue(':expires', $length);
|
2012-04-12 19:29:08 -04:00
|
|
|
else
|
|
|
|
$query->bindValue(':expires', null, PDO::PARAM_NULL);
|
|
|
|
|
|
|
|
if ($board)
|
|
|
|
$query->bindValue(':board', $board);
|
|
|
|
else
|
|
|
|
$query->bindValue(':board', null, PDO::PARAM_NULL);
|
|
|
|
|
|
|
|
$query->execute() or error(db_error($query));
|
2012-04-16 02:40:24 -04:00
|
|
|
|
2012-05-07 10:42:17 -04:00
|
|
|
modLog('Created a new ' .
|
|
|
|
($length > 0 ? preg_replace('/^(\d+) (\w+?)s?$/', '$1-$2', until($length)) : 'permanent') .
|
2013-03-16 03:27:24 -04:00
|
|
|
' ban on ' .
|
|
|
|
($board ? '/' . $board . '/' : 'all boards') .
|
|
|
|
' for ' .
|
2012-05-07 10:42:17 -04:00
|
|
|
(filter_var($mask, FILTER_VALIDATE_IP) !== false ? "<a href=\"?/IP/$mask\">$mask</a>" : utf8tohtml($mask)) .
|
2013-03-16 03:27:24 -04:00
|
|
|
' (<small>#' . $pdo->lastInsertId() . '</small>)' .
|
2012-05-07 10:42:17 -04:00
|
|
|
' with ' . ($reason ? 'reason: ' . utf8tohtml($reason) . '' : 'no reason'));
|
2012-04-12 19:29:08 -04:00
|
|
|
}
|
2012-04-12 19:47:27 -04:00
|
|
|
|
2013-03-16 03:27:24 -04:00
|
|
|
function unban($id) {
|
2013-07-31 22:14:26 -04:00
|
|
|
$query = prepare("SELECT `ip` FROM ``bans`` WHERE `id` = :id");
|
2013-03-16 03:27:24 -04:00
|
|
|
$query->bindValue(':id', $id);
|
|
|
|
$query->execute() or error(db_error($query));
|
|
|
|
$mask = $query->fetchColumn();
|
|
|
|
|
2013-07-31 22:14:26 -04:00
|
|
|
$query = prepare("DELETE FROM ``bans`` WHERE `id` = :id");
|
2012-04-12 19:47:27 -04:00
|
|
|
$query->bindValue(':id', $id);
|
|
|
|
$query->execute() or error(db_error($query));
|
2012-04-16 02:40:24 -04:00
|
|
|
|
2013-03-16 03:27:24 -04:00
|
|
|
if ($mask)
|
|
|
|
modLog("Removed ban #{$id} for " . (filter_var($mask, FILTER_VALIDATE_IP) !== false ? "<a href=\"?/IP/$mask\">$mask</a>" : utf8tohtml($mask)));
|
2012-04-12 19:47:27 -04:00
|
|
|
}
|
|
|
|
|