Browse Source

implement node info page

main
ghost 1 year ago
parent
commit
f0c8bd968d
  1. 12
      src/config/app.php.example
  2. 83
      src/library/database.php
  3. 2
      src/public/action.php
  4. 7
      src/public/assets/theme/default/css/common.css
  5. 15
      src/public/assets/theme/default/css/framework.css
  6. 10
      src/public/edit.php
  7. 4
      src/public/index.php
  8. 287
      src/public/info.php
  9. 4
      src/public/magnet.php

12
src/config/app.php.example

@ -59,8 +59,6 @@ define('WEBSITE_CSS_VERSION', 1); @@ -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); @@ -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) @@ -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',
],
// ...
]
@ -129,3 +133,7 @@ define('YGGDRASIL_URL_REGEX', '/^0{0,1}[2-3][a-f0-9]{0,2}:/'); // thanks to @ygg @@ -129,3 +133,7 @@ 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);
// Rules
define('RULE_SUBJECT', 'Common');
define('RULE_LANGUAGES', 'All');

83
src/library/database.php

@ -450,6 +450,17 @@ class Database { @@ -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 { @@ -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 { @@ -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 { @@ -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;
}

2
src/public/action.php

@ -756,6 +756,8 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false) @@ -756,6 +756,8 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false)
<a href="<?php echo $value->stats ?>"><?php echo _('Stats') ?></a>
|
<?php } ?>
<a href="<?php echo WEBSITE_URL ?>/info.php"><?php echo _('Info') ?></a>
|
<a href="<?php echo WEBSITE_URL ?>/index.php?rss"><?php echo _('RSS') ?></a>
|
<a href="https://github.com/YGGverse/YGGtracker"><?php echo _('GitHub') ?></a>

7
src/public/assets/theme/default/css/common.css

@ -17,6 +17,10 @@ h1, h2, h3, h4, h5 { @@ -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"] { @@ -71,6 +75,9 @@ input[type="submit"] {
cursor: pointer;
}
td {
padding: 2px 6px;
}
header a.logo {
color: #ccc;

15
src/public/assets/theme/default/css/framework.css

@ -133,11 +133,17 @@ @@ -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 @@ @@ -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 @@ @@ -172,6 +183,10 @@
margin-left: 8px;
}
.margin-l-16 {
margin-left: 16px;
}
.margin-r-4 {
margin-right: 4px;
}

10
src/public/edit.php

@ -201,7 +201,7 @@ else { @@ -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 { @@ -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 { @@ -606,6 +606,8 @@ else {
<a href="<?php echo $value->stats ?>"><?php echo _('Stats') ?></a>
|
<?php } ?>
<a href="<?php echo WEBSITE_URL ?>/info.php"><?php echo _('Info') ?></a>
|
<a href="<?php echo WEBSITE_URL ?>/index.php?rss"><?php echo _('RSS') ?></a>
|
<a href="https://github.com/YGGverse/YGGtracker"><?php echo _('GitHub') ?></a>

4
src/public/index.php

@ -170,7 +170,7 @@ else @@ -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 '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL ?> @@ -452,6 +452,8 @@ echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL ?>
<a href="<?php echo $value->stats ?>"><?php echo _('Stats') ?></a>
|
<?php } ?>
<a href="<?php echo WEBSITE_URL ?>/info.php"><?php echo _('Info') ?></a>
|
<a href="<?php echo WEBSITE_URL ?>/index.php?rss<?php echo $request->query ? sprintf('&query=%s', urlencode($request->query)) : false ?>"><?php echo _('RSS') ?></a>
|
<a href="https://github.com/YGGverse/YGGtracker"><?php echo _('GitHub') ?></a>

287
src/public/info.php

@ -0,0 +1,287 @@ @@ -0,0 +1,287 @@
<?php
// Load dependencies
require_once (__DIR__ . '/../config/app.php');
require_once (__DIR__ . '/../library/database.php');
require_once (__DIR__ . '/../../vendor/autoload.php');
// Connect database
try {
$db = new Database(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD);
} catch (Exception $e) {
var_dump($e);
exit;
}
// Define response
$response = (object)
[
'success' => 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;
}
}
}
}
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<link rel="stylesheet" type="text/css" href="<?php echo WEBSITE_URL ?>/assets/theme/default/css/common.css?<?php echo WEBSITE_CSS_VERSION ?>" />
<link rel="stylesheet" type="text/css" href="<?php echo WEBSITE_URL ?>/assets/theme/default/css/framework.css?<?php echo WEBSITE_CSS_VERSION ?>" />
<title>
<?php echo sprintf(_('%s instance info'), WEBSITE_NAME) ?>
</title>
<meta name="robots" content="noindex,nofollow"/>
<meta name="author" content="YGGtracker" />
<meta charset="UTF-8" />
</head>
<body>
<header>
<div class="container">
<div class="row margin-t-8 text-center">
<a class="logo" href="<?php echo WEBSITE_URL ?>"><?php echo str_replace('YGG', '<span>YGG</span>', WEBSITE_NAME) ?></a>
<form class="margin-t-8" name="search" method="get" action="<?php echo WEBSITE_URL ?>/index.php">
<input type="text" name="query" value="" placeholder="<?php echo _('search or submit magnet link') ?>" />
<input type="submit" value="<?php echo _('submit') ?>" />
</form>
</div>
</div>
</header>
<main>
<div class="container">
<div class="row">
<div class="column width-100">
<div class="padding-y-16 padding-x-8 margin-y-8 border-radius-3 background-color-night">
<?php if ($response->success) { ?>
<h1 class="padding-x-8 margin-b-16"><?php echo _('Node info') ?></h1>
<table>
<tbody>
<tr>
<td class="padding-b-8" colspan="2">
<h3><?php echo _('Rules') ?></h3>
</td>
</tr>
<tr>
<td><?php echo _('Subject') ?></td>
<td><?php echo _(RULE_SUBJECT) ?></td>
</tr>
<tr>
<td><?php echo _('Languages') ?></td>
<td><?php echo _(RULE_LANGUAGES) ?></td>
</tr>
<tr>
<td><?php echo _('Yggdrasil only') ?></td>
<td><?php echo MAGNET_DOWNLOAD_YGGDRASIL_URL_ONLY ? _('yes') : _('no') ?></td>
</tr>
<tr>
<td class="padding-t-16 colspan="2">
<h3><?php echo _('Totals') ?></h3>
</td>
</tr>
<tr>
<td><?php echo _('Users') ?></td>
<td><?php echo $db->getUsersTotal() ?></td>
</tr>
<tr>
<td><?php echo _('Magnets') ?></td>
<td><?php echo $db->getMagnetsTotal() ?></td>
</tr>
<tr>
<td><?php echo _('Comments') ?></td>
<td><?php echo $db->getMagnetCommentsTotal() ?></td>
</tr>
<tr>
<td><?php echo _('Moderators') ?></td>
<td><?php echo count(MODERATOR_IP_LIST) ?></td>
</tr>
<tr>
<td><?php echo _('Seeders') ?></td>
<td><?php echo sprintf('%s / %s', $localScrape->seeders, $totalScrape->seeders) ?></td>
</tr>
<tr>
<td><?php echo _('Peers') ?></td>
<td><?php echo sprintf('%s / %s', $localScrape->completed, $totalScrape->completed) ?></td>
</tr>
<tr>
<td><?php echo _('Leechers') ?></td>
<td><?php echo sprintf('%s / %s', $localScrape->leechers, $totalScrape->leechers) ?></td>
</tr>
<tr>
<td class="padding-t-16 padding-b-8" colspan="2">
<h3><?php echo _('Users') ?></h3>
</td>
</tr>
<tr>
<td><?php echo _('Identicon') ?></td>
<td><?php echo USER_DEFAULT_IDENTICON ? USER_DEFAULT_IDENTICON : _('no') ?></td>
</tr>
<tr>
<td><?php echo _('Identicon key') ?></td>
<td><?php echo USER_IDENTICON_FIELD ? USER_IDENTICON_FIELD : _('undefined') ?></td>
</tr>
<tr>
<td><?php echo _('Approved by default') ?></td>
<td><?php echo USER_DEFAULT_APPROVED ? _('yes') : _('no') ?></td>
</tr>
<tr>
<td><?php echo _('Auto-approved on magnet approve') ?></td>
<td><?php echo USER_AUTO_APPROVE_ON_MAGNET_APPROVE ? _('yes') : _('no') ?></td>
</tr>
<tr>
<td><?php echo _('Auto-approved on comment approve') ?></td>
<td><?php echo USER_AUTO_APPROVE_ON_COMMENT_APPROVE ? _('yes') : _('no') ?></td>
</tr>
<tr>
<td class="padding-t-16 padding-b-8" colspan="2">
<h3><?php echo _('Magnets') ?></h3>
</td>
</tr>
<tr>
<td><?php echo _('Approved by default') ?></td>
<td><?php echo MAGNET_DEFAULT_APPROVED ? _('yes') : _('no') ?></td>
</tr>
<tr>
<td><?php echo _('Title length') ?></td>
<td><?php echo MAGNET_META_TITLE_MIN_LENGTH ?>-<?php echo MAGNET_META_TITLE_MAX_LENGTH ?></td>
</tr>
<tr>
<td><?php echo _('Title length') ?></td>
<td><?php echo MAGNET_META_DESCRIPTION_MIN_LENGTH ?>-<?php echo MAGNET_META_DESCRIPTION_MAX_LENGTH ?></td>
</tr>
<tr>
<td class="padding-t-16 padding-b-8" colspan="2">
<h3><?php echo _('Comments') ?></h3>
</td>
</tr>
<tr>
<td><?php echo _('Approved by default') ?></td>
<td><?php echo COMMENT_DEFAULT_APPROVED ? _('yes') : _('no') ?></td>
</tr>
<tr>
<td><?php echo _('Length') ?></td>
<td><?php echo COMMENT_MIN_LENGTH ?>-<?php echo COMMENT_MAX_LENGTH ?></td>
</tr>
<tr>
<td class="padding-t-16 padding-b-8" colspan="2">
<h3><?php echo _('Trackers') ?></h3>
</td>
<?php foreach (TRACKER_LINKS as $name => $settings) { ?>
<tr>
<td><?php echo $name ?></td>
</tr>
<?php foreach ($settings as $key => $value) { ?>
<tr>
<td>
<span class="margin-l-16"><?php echo $key ?></span>
</td>
<td><?php echo $value ?></td>
</tr>
<?php } ?>
<?php } ?>
</tr>
</tbody>
</table>
<?php } else { ?>
<div class="text-center"><?php echo $response->message ?></div>
<?php } ?>
</div>
</div>
</div>
</div>
</main>
<footer>
<div class="container">
<div class="row">
<div class="column width-100 text-center margin-y-8">
<?php foreach (TRACKER_LINKS as $name => $value) { ?>
<a href="<?php echo $value->announce ?>"><?php echo $name ?></a>
/
<a href="<?php echo $value->stats ?>"><?php echo _('Stats') ?></a>
|
<?php } ?>
<a href="<?php echo WEBSITE_URL ?>/info.php"><?php echo _('Info') ?></a>
|
<a href="<?php echo WEBSITE_URL ?>/index.php?rss"><?php echo _('RSS') ?></a>
|
<a href="https://github.com/YGGverse/YGGtracker"><?php echo _('GitHub') ?></a>
</div>
</div>
</div>
</footer>
</body>
</html>

4
src/public/magnet.php

@ -147,7 +147,7 @@ else @@ -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 '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL ?> @@ -517,6 +517,8 @@ echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL ?>
<a href="<?php echo $value->stats ?>"><?php echo _('Stats') ?></a>
|
<?php } ?>
<a href="<?php echo WEBSITE_URL ?>/info.php"><?php echo _('Info') ?></a>
|
<a href="<?php echo WEBSITE_URL ?>/index.php?rss"><?php echo _('RSS') ?></a>
|
<a href="https://github.com/YGGverse/YGGtracker"><?php echo _('GitHub') ?></a>

Loading…
Cancel
Save