PDO::CASE_NATURAL, PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING, PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, PDO::ATTR_STRINGIFY_FETCHES => false, PDO::ATTR_EMULATE_PREPARES => false, PDO::MYSQL_ATTR_INIT_COMMAND => 'SET SESSION time_zone = \'+00:00\'' . ', sql_mode = \'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION\'', ]); } catch(PDOException $ex) { die($ex->getMessage()); } require_once SERIA_SRC . '/user.php'; require_once SERIA_SRC . '/benben.php'; require_once SERIA_SRC . '/torrent.php'; require_once SERIA_SRC . '/announce.php'; header('X-Powered-By: Seria/' . SERIA_VERSION); $sInAnnounce = $_SERVER['SCRIPT_NAME'] === '/announce.php'; $sIsIPv4 = strlen(inet_pton($_SERVER['REMOTE_ADDR'])) === 4; if(!$sInAnnounce && !$sIsIPv4) die('The tracker is only supported over IPv4, please reset your DNS cache.'); $sUserInfo = SeriaUser::anonymous(); $sVerification = ''; if(!$sInAnnounce) { // replace this with id.flashii.net shit $mszAuth = (string)filter_input(INPUT_COOKIE, 'msz_auth'); if(!empty($mszAuth)) { $loginMethod = 'Misuzu'; $loginSignature = sprintf('verify#%s#%s#%s', $loginMethod, $mszAuth, $_SERVER['REMOTE_ADDR']); $loginSignature = hash_hmac('sha256', $loginSignature, SERIA_MSZ_SECRET); $login = curl_init(SERIA_CAUTH_ENDPOINT); curl_setopt_array($login, [ CURLOPT_AUTOREFERER => false, CURLOPT_FAILONERROR => false, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HEADER => false, CURLOPT_POST => true, CURLOPT_POSTFIELDS => http_build_query([ 'method' => $loginMethod, 'token' => $mszAuth, 'ipaddr' => $_SERVER['REMOTE_ADDR'], ], '', '&', PHP_QUERY_RFC3986), CURLOPT_RETURNTRANSFER => true, CURLOPT_TCP_FASTOPEN => true, CURLOPT_CONNECTTIMEOUT => 2, CURLOPT_MAXREDIRS => 2, CURLOPT_PROTOCOLS => CURLPROTO_HTTPS, CURLOPT_TIMEOUT => 5, CURLOPT_USERAGENT => 'Seria/' . SERIA_VERSION, CURLOPT_HTTPHEADER => [ 'Content-Type: application/x-www-form-urlencoded', 'X-SharpChat-Signature: ' . $loginSignature, ], ]); $loginResponse = json_decode(curl_exec($login)); curl_close($login); if(!empty($loginResponse->success)) $sUserInfo = SeriaUser::fromMisuzu($pdo, $loginResponse); unset($mszAuth, $loginMethod, $loginSignature, $loginMethod, $login, $loginResponse); } if(empty($_COOKIE['seria_random'])) { $sVerification = SeriaUser::generatePassKey(32); setcookie('seria_random', $sVerification, strtotime('1 day'), '/', $_SERVER['HTTP_HOST']); } else $sVerification = (string)filter_input(INPUT_COOKIE, 'seria_random'); $sVerification = hash('sha256', $sVerification); } function byte_symbol(int $bytes, bool $decimal = true, array $symbols = ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']): string { if($bytes < 1) return '0 B'; $divider = $decimal ? 1000 : 1024; $exp = floor(log($bytes) / log($divider)); $bytes = $bytes / pow($divider, $exp); $symbol = $symbols[$exp]; return sprintf("%.2f %s%sB", $bytes, $symbol, $symbol !== '' && !$decimal ? 'i' : ''); } function seria_weighted_number(float $num1, float $num2, float $weight): int { $weight = min(1, max(0, $weight)); return round(($num1 * $weight) + ($num2 * (1 - $weight))); } function seria_weighted_colour(int $colour1, int $colour2, float $weight): int { $colour1 = [ ($colour1 >> 16) & 0xFF, ($colour1 >> 8) & 0xFF, $colour1 & 0xFF ]; $colour2 = [ ($colour2 >> 16) & 0xFF, ($colour2 >> 8) & 0xFF, $colour2 & 0xFF ]; return (seria_weighted_number($colour1[0], $colour2[0], $weight) << 16) | (seria_weighted_number($colour1[1], $colour2[1], $weight) << 8) | seria_weighted_number($colour1[2], $colour2[2], $weight); } function seria_weighted_colour_hex(int $colour1, int $colour2, float $weight): string { return sprintf('#%06x', seria_weighted_colour($colour1, $colour2, $weight)); } function seria_easeInQuad(float $n): float { return $n * $n; } function seria_easeOutQuad(float $n): float { return 1 - (1 - $n) * (1 - $n); } function seria_ratio_colour(float $ratio): string { $ratio *= 2; if($ratio > 1) return seria_weighted_colour_hex(0x008000, 0xFFAA00, seria_easeInQuad($ratio - 1)); return seria_weighted_colour_hex(0xFFAA00, 0xFF0000, seria_easeOutQuad($ratio)); } function seria_size_colour(int $bytes): string { if($bytes >= 53687090000) return '#ec32a4'; if($bytes >= 21474840000) return '#db5ff1'; if($bytes >= 10737420000) return '#cca1f4'; if($bytes >= 5368709000) return '#cdd'; if($bytes >= 1073742000) return '#bae9c7'; return '#a0f5b8'; }