diff --git a/.env.example b/.env.example index e4a23bc7..17367504 100644 --- a/.env.example +++ b/.env.example @@ -63,3 +63,5 @@ GOOGLE_DRIVE_FOLDER_ID= GEOIP2_DATABASE= EXAM_PROGRESS_UPDATE_PROBABILITY=20 + +ANNOUNCE_API_LOCAL_HOST= diff --git a/app/Repositories/TrackerRepository.php b/app/Repositories/TrackerRepository.php index 1671859f..29617fb1 100644 --- a/app/Repositories/TrackerRepository.php +++ b/app/Repositories/TrackerRepository.php @@ -76,15 +76,25 @@ class TrackerRepository extends BaseRepository $this->updateSnatch($peerSelf, $queries, $dataTraffic); $this->updateTorrent($torrent, $queries); - $this->userUpdates['uploaded'] = DB::raw('uploaded + ' . $dataTraffic['uploaded_increment_for_user']); - $this->userUpdates['downloaded'] = DB::raw('downloaded + ' . $dataTraffic['downloaded_increment_for_user']); - $this->userUpdates['clientselect'] = $clientAllow->id; - $this->userUpdates['showclienterror'] = 'no'; + if ($dataTraffic['uploaded_increment_for_user'] > 0) { + $this->userUpdates['uploaded'] = DB::raw('uploaded + ' . $dataTraffic['uploaded_increment_for_user']); + } + if ($dataTraffic['downloaded_increment_for_user'] > 0) { + $this->userUpdates['downloaded'] = DB::raw('downloaded + ' . $dataTraffic['downloaded_increment_for_user']); + } + if ($user->clientselect != $clientAllow->id) { + $this->userUpdates['clientselect'] = $clientAllow->id; + } + if ($user->showclienterror == 'yes') { + $this->userUpdates['showclienterror'] = 'no'; + } } $repDict = $this->generateSuccessAnnounceResponse($torrent, $queries, $user, $withPeers); } catch (ClientNotAllowedException $exception) { do_log("[ClientNotAllowedException] " . $exception->getMessage()); - $this->userUpdates['showclienterror'] = 'yes'; + if (isset($user) && $user->showclienterror == 'no') { + $this->userUpdates['showclienterror'] = 'yes'; + } $repDict = $this->generateFailedAnnounceResponse($exception->getMessage()); } catch (TrackerException $exception) { $repDict = $this->generateFailedAnnounceResponse($exception->getMessage()); @@ -105,6 +115,7 @@ class TrackerRepository extends BaseRepository * @param Request $request * @throws ClientNotAllowedException * @throws TrackerException + * @refs */ protected function checkClient(Request $request) { @@ -180,6 +191,11 @@ class TrackerRepository extends BaseRepository return compact('torrentId', 'uid'); } + /** + * @param Request $request + * @return array + * @throws TrackerException + */ protected function checkAnnounceFields(Request $request): array { $queries = []; @@ -336,7 +352,7 @@ class TrackerRepository extends BaseRepository $ratio = ($user->downloaded > 0) ? ($user->uploaded / $user->downloaded) : 1; $settingsMain = Setting::get('main'); if ($settingsMain['waitsystem'] == 'yes') { - $elapsed = Carbon::now()->diffInSeconds($torrent->added); + $elapsed = Carbon::now()->diffInHours($torrent->added); if ($ratio < 0.4) $wait = 24; elseif ($ratio < 0.5) $wait = 12; elseif ($ratio < 0.6) $wait = 6; diff --git a/artisan b/artisan index 5c23e2e2..d43ba8d3 100644 --- a/artisan +++ b/artisan @@ -14,6 +14,8 @@ define('LARAVEL_START', microtime(true)); | loading of any our classes "manually". Feels great to relax. | */ +require __DIR__ . '/include/globalfunctions.php'; +require __DIR__ . '/include/functions.php'; require __DIR__.'/vendor/autoload.php'; diff --git a/composer.json b/composer.json index 57beae5e..ebafe41b 100644 --- a/composer.json +++ b/composer.json @@ -17,8 +17,7 @@ "Database\\Seeders\\": "database/seeders/" }, "files": [ - "include/globalfunctions.php", - "include/functions.php" + ] }, "require": { diff --git a/include/bittorrent.php b/include/bittorrent.php index b423ce5d..c97dcf80 100644 --- a/include/bittorrent.php +++ b/include/bittorrent.php @@ -3,6 +3,8 @@ define('NEXUS_START', microtime(true)); define('IN_NEXUS', true); $rootpath = dirname(__DIR__) . '/'; set_include_path(get_include_path() . PATH_SEPARATOR . $rootpath); +require $rootpath . 'include/globalfunctions.php'; +require $rootpath . 'include/functions.php'; require $rootpath . 'include/core.php'; require $rootpath . 'classes/class_advertisement.php'; require $rootpath . 'classes/class_attendance.php'; diff --git a/include/bittorrent_announce.php b/include/bittorrent_announce.php index 92fa10c5..d5fa6c97 100644 --- a/include/bittorrent_announce.php +++ b/include/bittorrent_announce.php @@ -1,7 +1,9 @@ diff --git a/include/globalfunctions.php b/include/globalfunctions.php index 5527feca..4d450379 100644 --- a/include/globalfunctions.php +++ b/include/globalfunctions.php @@ -159,20 +159,11 @@ function do_log($log, $level = 'info') if (is_null($setLogLevel)) { $setLogLevel = nexus_env('LOG_LEVEL', 'debug'); } - $logLevels = [ - \Psr\Log\LogLevel::DEBUG, - \Psr\Log\LogLevel::INFO, - \Psr\Log\LogLevel::NOTICE, - \Psr\Log\LogLevel::WARNING, - \Psr\Log\LogLevel::ERROR, - \Psr\Log\LogLevel::CRITICAL, - \Psr\Log\LogLevel::ALERT, - \Psr\Log\LogLevel::EMERGENCY, - ]; + $logLevels = ['debug', 'info', 'notice', 'warning', 'error', 'critical', 'alert', 'emergency']; $setLogLevelKey = array_search($setLogLevel, $logLevels); $currentLogLevelKey = array_search($level, $logLevels); if ($currentLogLevelKey === false) { - $level = \Psr\log\LogLevel::ERROR; + $level = 'error'; $log = "[ERROR_LOG_LEVEL] $log"; $currentLogLevelKey = array_search($level, $logLevels); } @@ -310,7 +301,7 @@ function nexus_env($key = null, $default = null) { static $env; if (is_null($env)) { - $envFile = defined('ROOT_PATH') ? ROOT_PATH . '.env' : base_path('.env'); + $envFile = dirname(__DIR__) . '/.env'; $env = readEnvFile($envFile); } if (is_null($key)) { @@ -678,3 +669,24 @@ function get_hr_ratio($uped, $downed) return $ratio; } + +function request_local_announce_api($announceApiLocalHost) +{ + $start = microtime(true); + $ch = curl_init(); + $options = [ + CURLOPT_URL => sprintf('%s/api/announce?%s', trim($announceApiLocalHost, '/'), $_SERVER['QUERY_STRING']), + CURLOPT_USERAGENT => $_SERVER["HTTP_USER_AGENT"], + CURLOPT_RETURNTRANSFER => true, + CURLOPT_SSL_VERIFYPEER => false, + CURLOPT_TIMEOUT => 60, + ]; + curl_setopt_array($ch, $options); + $response = curl_exec($ch); + $log = sprintf( + "[LOCAL_ANNOUNCE_API] [%s] options: %s, response(%s): %s", + number_format(microtime(true) - $start, 3), json_encode($options), gettype($response), $response + ); + do_log($log); + return $response; +} diff --git a/nexus/Install/install_update_start.php b/nexus/Install/install_update_start.php index b03ee358..22aadfca 100644 --- a/nexus/Install/install_update_start.php +++ b/nexus/Install/install_update_start.php @@ -3,6 +3,8 @@ ini_set('error_reporting', E_ALL); ini_set('display_errors', 0); define('IN_NEXUS', true); define('NEXUS_START', microtime(true)); +require ROOT_PATH . 'include/globalfunctions.php'; +require ROOT_PATH . 'include/functions.php'; require ROOT_PATH . 'vendor/autoload.php'; require ROOT_PATH . 'nexus/Database/helpers.php'; require ROOT_PATH . 'include/constants.php'; diff --git a/public/announce.php b/public/announce.php index 0ba0f846..7ba5877e 100644 --- a/public/announce.php +++ b/public/announce.php @@ -1,6 +1,22 @@