diff --git a/src/config/app.php.example b/src/config/app.php.example index 451b11f..7bcc2cf 100644 --- a/src/config/app.php.example +++ b/src/config/app.php.example @@ -59,8 +59,6 @@ define('WEBSITE_CSS_VERSION', 1); define('WEBSITE_PAGINATION_LIMIT', 20); -define('WEBSITE_MAGNET_SHORT_META_DESCRIPTION_LENGTH', 480); - // Moderation define('MODERATOR_IP_LIST', (array) [ @@ -87,7 +85,11 @@ define('MAGNET_DEFAULT_SENSITIVE', false); define('MAGNET_EDITOR_LOCK_TIMEOUT', 60*60); define('MAGNET_META_TITLE_MIN_LENGTH', 10); +define('MAGNET_META_TITLE_MAX_LENGTH', 255); + define('MAGNET_META_DESCRIPTION_MIN_LENGTH', 0); +define('MAGNET_META_DESCRIPTION_MAX_LENGTH', 10000); + define('MAGNET_STOP_WORDS_SIMILAR', [ @@ -113,11 +115,13 @@ define('TRACKER_LINKS', (object) [ 'announce' => 'http://[201:23b4:991a:634d:8359:4521:5576:15b7]/announce', 'stats' => 'http://[201:23b4:991a:634d:8359:4521:5576:15b7]/stats', + 'scrape' => 'http://[201:23b4:991a:634d:8359:4521:5576:15b7]/scrape', ], 'Tracker 2' => (object) [ 'announce' => 'http://[200:1e2f:e608:eb3a:2bf:1e62:87ba:e2f7]/announce', 'stats' => 'http://[200:1e2f:e608:eb3a:2bf:1e62:87ba:e2f7]/stats', + 'scrape' => 'http://[200:1e2f:e608:eb3a:2bf:1e62:87ba:e2f7]/scrape', ], // ... ] @@ -128,4 +132,8 @@ define('YGGDRASIL_URL_REGEX', '/^0{0,1}[2-3][a-f0-9]{0,2}:/'); // thanks to @ygg // Crawler define('CRAWLER_SCRAPE_QUEUE_LIMIT', 1); -define('CRAWLER_SCRAPE_TIME_OFFLINE_TIMEOUT', 60*60*24); \ No newline at end of file +define('CRAWLER_SCRAPE_TIME_OFFLINE_TIMEOUT', 60*60*24); + +// Rules +define('RULE_SUBJECT', 'Common'); +define('RULE_LANGUAGES', 'All'); \ No newline at end of file diff --git a/src/library/database.php b/src/library/database.php index 3ab541c..80d1f28 100644 --- a/src/library/database.php +++ b/src/library/database.php @@ -450,6 +450,17 @@ class Database { return $query->fetch(); } + public function getUsersTotal() { + + $this->_debug->query->select->total++; + + $query = $this->_db->prepare('SELECT COUNT(*) AS `result` FROM `user`'); + + $query->execute(); + + return $query->fetch()->result; + } + public function findUserByAddress(string $address) { $this->_debug->query->select->total++; @@ -536,6 +547,28 @@ class Database { return $query->fetch(); } + public function getMagnets() { + + $this->_debug->query->select->total++; + + $query = $this->_db->prepare('SELECT * FROM `magnet`'); + + $query->execute(); + + return $query->fetchAll(); + } + + public function getMagnetsTotal() { + + $this->_debug->query->select->total++; + + $query = $this->_db->prepare('SELECT COUNT(*) AS `result` FROM `magnet`'); + + $query->execute(); + + return $query->fetch()->result; + } + public function findMagnet(int $userId, string $xt) { $this->_debug->query->select->total++; @@ -783,6 +816,41 @@ class Database { return $this->addMagnetToAddressTracker($magnetId, $addressTrackerId); } + /* + public function getMagnetToAddressTrackerSeedersSum() { + + $this->_debug->query->select->total++; + + $query = $this->_db->prepare('SELECT SUM(`seeders`) AS `result` FROM `magnetToAddressTracker`'); + + $query->execute(); + + return $query->fetch()->result; + } + + public function getMagnetToAddressTrackerCompletedSum() { + + $this->_debug->query->select->total++; + + $query = $this->_db->prepare('SELECT SUM(`completed`) AS `result` FROM `magnetToAddressTracker`'); + + $query->execute(); + + return $query->fetch()->result; + } + + public function getMagnetToAddressTrackerLeechersSum() { + + $this->_debug->query->select->total++; + + $query = $this->_db->prepare('SELECT SUM(`leechers`) AS `result` FROM `magnetToAddressTracker`'); + + $query->execute(); + + return $query->fetch()->result; + } + */ + // Magnet to AcceptableSource public function addMagnetToAcceptableSource(int $magnetId, int $acceptableSourceId) : int { @@ -1038,13 +1106,22 @@ class Database { return $query->rowCount(); } - public function getMagnetCommentsTotal(int $magnetId) : int { + public function getMagnetCommentsTotal(mixed $magnetId = null) : int { $this->_debug->query->select->total++; - $query = $this->_db->prepare('SELECT COUNT(*) AS `result` FROM `magnetComment` WHERE `magnetId` = ?'); + if ($magnetId) + { + $query = $this->_db->prepare('SELECT COUNT(*) AS `result` FROM `magnetComment` WHERE `magnetId` = ?'); - $query->execute([$magnetId]); + $query->execute([$magnetId]); + } + else + { + $query = $this->_db->prepare('SELECT COUNT(*) AS `result` FROM `magnetComment`'); + + $query->execute(); + } return $query->fetch()->result; } diff --git a/src/public/action.php b/src/public/action.php index 52b222d..d2bee7e 100644 --- a/src/public/action.php +++ b/src/public/action.php @@ -756,6 +756,8 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false) | + + | | diff --git a/src/public/assets/theme/default/css/common.css b/src/public/assets/theme/default/css/common.css index 1636283..18d467a 100644 --- a/src/public/assets/theme/default/css/common.css +++ b/src/public/assets/theme/default/css/common.css @@ -17,6 +17,10 @@ h1, h2, h3, h4, h5 { font-weight: normal; } +h1 { + font-size: 18px; +} + h2 { font-size: 16px; } @@ -71,6 +75,9 @@ input[type="submit"] { cursor: pointer; } +td { + padding: 2px 6px; +} header a.logo { color: #ccc; diff --git a/src/public/assets/theme/default/css/framework.css b/src/public/assets/theme/default/css/framework.css index b277e18..65db5ed 100644 --- a/src/public/assets/theme/default/css/framework.css +++ b/src/public/assets/theme/default/css/framework.css @@ -133,11 +133,17 @@ padding-top: 4px; padding-bottom: 4px; } + .padding-x-4 { padding-left: 4px; padding-right: 4px; } +.padding-x-8 { + padding-left: 8px; + padding-right: 8px; +} + .padding-8 { padding: 8px; } @@ -155,6 +161,11 @@ padding-top: 16px; } +.padding-y-16 { + padding-top: 16px; + padding-bottom: 16px; +} + .padding-x-16 { padding-left: 16px; padding-right: 16px; @@ -172,6 +183,10 @@ margin-left: 8px; } +.margin-l-16 { + margin-left: 16px; +} + .margin-r-4 { margin-right: 4px; } diff --git a/src/public/edit.php b/src/public/edit.php index bb3580e..ae07590 100644 --- a/src/public/edit.php +++ b/src/public/edit.php @@ -201,7 +201,7 @@ else { } // Meta - if (MAGNET_META_TITLE_MIN_LENGTH <= mb_strlen($_POST['metaTitle'])) + if (MAGNET_META_TITLE_MIN_LENGTH <= mb_strlen($_POST['metaTitle']) && MAGNET_META_TITLE_MAX_LENGTH >= mb_strlen($_POST['metaTitle'])) { $db->updateMagnetMetaTitle($magnet->magnetId, trim(strip_tags(html_entity_decode($_POST['metaTitle']))), time()); @@ -211,17 +211,17 @@ else { else { $response->form->metaTitle->valid->success = false; - $response->form->metaTitle->valid->message = sprintf(_('* required, minimum %s chars'), MAGNET_META_TITLE_MIN_LENGTH); + $response->form->metaTitle->valid->message = sprintf(_('* required, minimum %s-%s chars'), MAGNET_META_TITLE_MIN_LENGTH, MAGNET_META_TITLE_MAX_LENGTH); } - if (MAGNET_META_DESCRIPTION_MIN_LENGTH <= mb_strlen($_POST['metaDescription'])) + if (MAGNET_META_DESCRIPTION_MIN_LENGTH <= mb_strlen($_POST['metaDescription']) && MAGNET_META_DESCRIPTION_MAX_LENGTH >= mb_strlen($_POST['metaDescription'])) { $db->updateMagnetMetaDescription($magnet->magnetId, trim(strip_tags(html_entity_decode($_POST['metaDescription']))), time()); } else { $response->form->metaDescription->valid->success = false; - $response->form->metaDescription->valid->message = sprintf(_('* required, minimum %s chars'), MAGNET_META_DESCRIPTION_MIN_LENGTH); + $response->form->metaDescription->valid->message = sprintf(_('* required, minimum %s-%s chars'), MAGNET_META_DESCRIPTION_MIN_LENGTH, MAGNET_META_DESCRIPTION_MAX_LENGTH); } // Social @@ -606,6 +606,8 @@ else { | + + | | diff --git a/src/public/index.php b/src/public/index.php index 94f9b2a..27fcf76 100644 --- a/src/public/index.php +++ b/src/public/index.php @@ -170,7 +170,7 @@ else 'metaTitle' => $magnet->metaTitle ? htmlentities($magnet->metaTitle) : ($magnet->dn ? htmlentities($magnet->dn): false), 'metaDescription' => $magnet->metaDescription ? nl2br( htmlentities( - substr($magnet->metaDescription, 0, WEBSITE_MAGNET_SHORT_META_DESCRIPTION_LENGTH) + substr($magnet->metaDescription, 0, MAGNET_META_DESCRIPTION_LENGTH_SHORT) ) ) : false, 'approved' => (bool) $magnet->approved, @@ -452,6 +452,8 @@ echo '' . PHP_EOL ?> | + + | | diff --git a/src/public/info.php b/src/public/info.php new file mode 100644 index 0000000..b0dce8a --- /dev/null +++ b/src/public/info.php @@ -0,0 +1,287 @@ + + true, + 'message' => _('Internal server error'), +]; + +// Yggdrasil connections only +if (!preg_match(YGGDRASIL_URL_REGEX, $_SERVER['REMOTE_ADDR'])) +{ + $response->success = false; + $response->message = _('Yggdrasil connection required for this action'); +} + +// Init session +else if (!$userId = $db->initUserId($_SERVER['REMOTE_ADDR'], USER_DEFAULT_APPROVED, time())) +{ + $response->success = false; + $response->message = _('Could not init user session'); +} + +else +{ + + // Scrapes + $localScrape = (object) + [ + 'seeders' => 0, + 'completed' => 0, + 'leechers' => 0, + ]; + + $totalScrape = (object) + [ + 'seeders' => 0, + 'completed' => 0, + 'leechers' => 0, + ]; + + $trackers = []; + + foreach (TRACKER_LINKS as $tracker) + { + $trackers[] = $tracker->announce; + } + + foreach ($db->getMagnets() as $magnet) + { + foreach ($db->findAddressTrackerByMagnetId($magnet->magnetId) as $magnetToAddressTracker) + { + if ($addressTracker = $db->getAddressTracker($magnetToAddressTracker->addressTrackerId)) + { + $scheme = $db->getScheme($addressTracker->schemeId); + $host = $db->getHost($addressTracker->hostId); + $port = $db->getPort($addressTracker->portId); + $uri = $db->getUri($addressTracker->uriId); + + $url = $port->value ? sprintf('%s://%s:%s%s', $scheme->value, + $host->value, + $port->value, + $uri->value) : sprintf('%s://%s%s', $scheme->value, + $host->value, + $uri->value); + + if (in_array($url, $trackers)) + { + $localScrape->seeders += (int) $magnetToAddressTracker->seeders; + $localScrape->completed += (int) $magnetToAddressTracker->completed; + $localScrape->leechers += (int) $magnetToAddressTracker->leechers; + } + + $totalScrape->seeders += (int) $magnetToAddressTracker->seeders; + $totalScrape->completed += (int) $magnetToAddressTracker->completed; + $totalScrape->leechers += (int) $magnetToAddressTracker->leechers; + } + } + } +} + +?> + + + + + + + <?php echo sprintf(_('%s instance info'), WEBSITE_NAME) ?> + + + + + + +
+
+ +
+
+
+
+
+
+
+ success) { ?> +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + $settings) { ?> + + + + $value) { ?> + + + + + + + + +
+

+
+

+
getUsersTotal() ?>
getMagnetsTotal() ?>
getMagnetCommentsTotal() ?>
seeders, $totalScrape->seeders) ?>
completed, $totalScrape->completed) ?>
leechers, $totalScrape->leechers) ?>
+

+
+

+
-
-
+

+
-
+

+
+ +
+ +
message ?>
+ +
+
+
+
+
+ + + \ No newline at end of file diff --git a/src/public/magnet.php b/src/public/magnet.php index a3b46f1..745d5c8 100644 --- a/src/public/magnet.php +++ b/src/public/magnet.php @@ -147,7 +147,7 @@ else 'metaTitle' => $magnet->metaTitle ? htmlentities($magnet->metaTitle) : ($magnet->dn ? htmlentities($magnet->dn): false), 'metaDescription' => $magnet->metaDescription ? nl2br( htmlentities( - substr($magnet->metaDescription, 0, WEBSITE_MAGNET_SHORT_META_DESCRIPTION_LENGTH) + substr($magnet->metaDescription, 0, MAGNET_META_DESCRIPTION_LENGTH_SHORT) ) ) : false, 'approved' => (bool) $magnet->approved, @@ -517,6 +517,8 @@ echo '' . PHP_EOL ?> | + + | |