Browse Source

implement port check feature

yggdrasil-0.4.7
ghost 1 year ago
parent
commit
1950197b91
  1. BIN
      database/yggstate.mwb
  2. BIN
      media/db-prototype.png
  3. 2
      src/config/app.php.example
  4. 78
      src/library/mysql.php
  5. 15
      src/public/assets/theme/default/css/common.css
  6. 19
      src/public/assets/theme/default/css/framework.css
  7. 135
      src/public/peer.php

BIN
database/yggstate.mwb

Binary file not shown.

BIN
media/db-prototype.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 154 KiB

After

Width:  |  Height:  |  Size: 166 KiB

2
src/config/app.php.example

@ -69,5 +69,7 @@ define('WEBSITE_NAME', 'YGGstate');
define('WEBSITE_PEER_REMOTE_TIME_ONLINE_TIMEOUT', 60 * 5); define('WEBSITE_PEER_REMOTE_TIME_ONLINE_TIMEOUT', 60 * 5);
define('WEBSITE_PEER_REMOTE_PAGINATION_LIMIT', 20); define('WEBSITE_PEER_REMOTE_PAGINATION_LIMIT', 20);
define('WEBSITE_PEER_PORT_CHECK_TIMEOUT', 60 * 5);
// Crawler // Crawler
define('CRAWL_STOP_DISK_QUOTA_MB_LEFT', 128); define('CRAWL_STOP_DISK_QUOTA_MB_LEFT', 128);

78
src/library/mysql.php

@ -114,6 +114,84 @@ class MySQL {
return $query->fetchAll(); return $query->fetchAll();
} }
// Port
public function findPeerPortByValue(int $peerId, int $value) {
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT * FROM `peerPort` WHERE `peerId` = ? AND `value` = ? LIMIT 1');
$query->execute([$peerId, $value]);
return $query->fetch();
}
public function addPeerPort(int $peerId, int $value) {
$this->_debug->query->insert->total++;
$query = $this->_db->prepare('INSERT INTO `peerPort` SET `peerId` = ?, `value` = ?');
$query->execute([$peerId, $value]);
return $this->_db->lastInsertId();
}
public function addPeerPortStatus(int $peerPortId, bool $value, int $timeAdded) {
$this->_debug->query->insert->total++;
$query = $this->_db->prepare('INSERT INTO `peerPortStatus` SET `peerPortId` = ?, `value` = ?, `timeAdded` = ?');
$query->execute([$peerPortId, $value ? "1" : "0", $timeAdded]);
return $this->_db->lastInsertId();
}
public function findLastPeerPortStatusesByPeerId(int $peerId, int $limit = 5) {
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT `peerPort`.`value` AS `port`,
`peerPortStatus`.`value` AS `status`,
`peerPortStatus`.`timeAdded`
FROM `peerPort`
JOIN `peerPortStatus` ON (`peerPortStatus`.`peerPortId` = `peerPort`.`peerPortId`)
WHERE `peerPort`.`peerId` = ?
ORDER BY `peerPortStatus`.`timeAdded` DESC
LIMIT ' . (int) $limit);
$query->execute([$peerId]);
return $query->fetchAll();
}
public function findLastPeerPortStatusByPeerId(int $peerId) {
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT `peerPort`.`value` AS `port`,
`peerPortStatus`.`value` AS `status`,
`peerPortStatus`.`timeAdded`
FROM `peerPort`
JOIN `peerPortStatus` ON (`peerPortStatus`.`peerPortId` = `peerPort`.`peerPortId`)
WHERE `peerPort`.`peerId` = ?
ORDER BY `peerPortStatus`.`timeAdded` DESC
LIMIT 1');
$query->execute([$peerId]);
return $query->fetch();
}
// Geo // Geo
public function findGeo(mixed $geoCountryId, mixed $geoCityId, mixed $geoCoordinateId) { // int|null public function findGeo(mixed $geoCountryId, mixed $geoCityId, mixed $geoCoordinateId) { // int|null

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

@ -72,6 +72,10 @@ tbody tr:hover {
background: #f2f2f2; background: #f2f2f2;
} }
tfoot {
border-top: 1px #f2f2f2 solid;
}
a, a:hover, a:active, a:visited { a, a:hover, a:active, a:visited {
color: #5785b7; color: #5785b7;
text-decoration: none; text-decoration: none;
@ -89,9 +93,16 @@ form > input::placeholder {
color: #333; color: #333;
} }
form > input[type="text"] { form > input[name="query"] {
padding: 7px 4px; padding: 6px 4px;
min-width: 260px; min-width: 260px;
border: 1px #f2f2f2 solid;
}
form > input[name="port"] {
padding: 6px 4px;
min-width: 64px;
border: 1px #f2f2f2 solid;
} }
form > button { form > button {

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

@ -44,6 +44,10 @@
color: #5785b7; color: #5785b7;
} }
.line-height-26 {
line-height: 26px;
}
/* /*
.background-color-green { .background-color-green {
background-color: #e9f9e7; background-color: #e9f9e7;
@ -66,10 +70,25 @@
padding: 0; padding: 0;
} }
.padding-x-0 {
padding-left: 0;
padding-right: 0;
}
.padding-4 { .padding-4 {
padding: 4px; padding: 4px;
} }
.padding-x-4 {
padding-left: 4px;
padding-right: 4px;
}
.padding-y-8 {
padding-top: 8px;
padding-bottom: 8px;
}
.margin-y-8 { .margin-y-8 {
margin-top: 8px; margin-top: 8px;
margin-bottom: 8px; margin-bottom: 8px;

135
src/public/peer.php

@ -38,6 +38,7 @@ $requestSort = isset($_GET['sort']) && in_array($_GET['sort'], ['peerConnect
$requestOrder = isset($_GET['order']) && in_array($_GET['order'], ['ASC', 'DESC']) ? $_GET['order'] : 'DESC'; $requestOrder = isset($_GET['order']) && in_array($_GET['order'], ['ASC', 'DESC']) ? $_GET['order'] : 'DESC';
$requestPage = isset($_GET['page']) && $_GET['page'] > 1 ? (int) $_GET['page'] : 1; $requestPage = isset($_GET['page']) && $_GET['page'] > 1 ? (int) $_GET['page'] : 1;
$requestCalendar = isset($_GET['calendar']) && in_array($_GET['calendar'], ['traffic']) ? $_GET['calendar'] : 'traffic'; $requestCalendar = isset($_GET['calendar']) && in_array($_GET['calendar'], ['traffic']) ? $_GET['calendar'] : 'traffic';
$requestPort = isset($_POST['port']) && 5 > strlen($_POST['port']) && $_POST['port'] > 0 ? (int) $_POST['port'] : false;
// App controller begin // App controller begin
$calendar = new Yggverse\Graph\Calendar\Month($requestTime); $calendar = new Yggverse\Graph\Calendar\Month($requestTime);
@ -114,6 +115,77 @@ $peerRemoteConnections = $memory->getByMethodCallback(
$peerInfo = $memory->getByMethodCallback($db, 'getPeerInfo', [$requestPeerId]); $peerInfo = $memory->getByMethodCallback($db, 'getPeerInfo', [$requestPeerId]);
// Port check
$responsePort = (object)
[
'status' => false,
'message' => null,
];
if ($requestPort) {
if ($peerInfo) {
// Check requests quota
$lastPeerPortStatus = $db->findLastPeerPortStatusByPeerId($requestPeerId);
if ($lastPeerPortStatus &&
$lastPeerPortStatus->timeAdded > time() - WEBSITE_PEER_PORT_CHECK_TIMEOUT) {
$responsePort = (object)
[
'status' => false,
'message' => sprintf(_('request quota %s minutes'), WEBSITE_PEER_PORT_CHECK_TIMEOUT / 60),
];
} else {
// Get port connection
$connection = @fsockopen(
sprintf('[%s]', $peerInfo->address),
$requestPort,
$error_code,
$error_message,
5
);
if (is_resource($connection)) {
$responsePort = (object)
[
'status' => true,
'message' => sprintf(_('%s port open'), $requestPort),
];
fclose($connection);
} else {
$responsePort = (object)
[
'status' => false,
'message' => sprintf(_('%s port closed'), $requestPort),
];
}
// Init port
if ($peerPort = $db->findPeerPortByValue($requestPeerId, $requestPort)) {
$peerPortId = $peerPort->peerPortId;
} else {
$peerPortId = $db->addPeerPort($requestPeerId, $requestPort);
}
// Save connection result
$db->addPeerPortStatus($peerPortId, $responsePort->status, time());
}
}
}
$peerPortStatuses = $db->findLastPeerPortStatusesByPeerId($requestPeerId);
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
@ -123,10 +195,14 @@ $peerInfo = $memory->getByMethodCallback($db, 'getPeerInfo', [$requestPeerId]);
<link rel="stylesheet" type="text/css" href="<?php echo WEBSITE_URL ?>/assets/theme/<?php echo $requestTheme ?>/css/framework.css?<?php echo time() ?>" /> <link rel="stylesheet" type="text/css" href="<?php echo WEBSITE_URL ?>/assets/theme/<?php echo $requestTheme ?>/css/framework.css?<?php echo time() ?>" />
<link rel="stylesheet" type="text/css" href="<?php echo WEBSITE_URL ?>/assets/theme/<?php echo $requestTheme ?>/css/yggverse/graph/calendar/month.css?<?php echo time() ?>" /> <link rel="stylesheet" type="text/css" href="<?php echo WEBSITE_URL ?>/assets/theme/<?php echo $requestTheme ?>/css/yggverse/graph/calendar/month.css?<?php echo time() ?>" />
<title> <title>
<?php if ($peerInfo) { ?>
<?php echo sprintf(_('Peer %s - %s'), $peerInfo->address, WEBSITE_NAME) ?> <?php echo sprintf(_('Peer %s - %s'), $peerInfo->address, WEBSITE_NAME) ?>
<?php } else { ?>
<?php echo _('Not found') ?>
<?php } ?>
</title> </title>
<meta name="description" content="<?php echo _('Yggdrasil peer info analytics: ip, traffic, timing, routing, geo-location') ?>" /> <meta name="description" content="<?php echo _('Yggdrasil peer info analytics: ip, traffic, timing, routing, geo-location, port status') ?>" />
<meta name="keywords" content="yggdrasil, yggstate, yggverse, analytics, explorer, search engine, crawler, ip info, geo location, node city, node country, traffic stats, ports, node coordinates, connection time, routes, open-source, js-less" /> <meta name="keywords" content="yggdrasil, yggstate, yggverse, analytics, explorer, search engine, crawler, ip info, geo location, node city, node country, traffic stats, port open status, node coordinates, connection time, routes, open-source, js-less" />
<meta name="author" content="YGGverse" /> <meta name="author" content="YGGverse" />
<meta charset="UTF-8" /> <meta charset="UTF-8" />
</head> </head>
@ -311,6 +387,61 @@ $peerInfo = $memory->getByMethodCallback($db, 'getPeerInfo', [$requestPeerId]);
</div> </div>
</div> </div>
</div> </div>
<div class="row padding-0">
<div class="column width-50">
<table class="bordered width-100">
<thead>
<tr>
<th class="text-left" colspan="3"><?php echo _('Port') ?></th>
</tr>
</thead>
<tbody>
<?php if ($peerPortStatuses) { ?>
<?php foreach ($peerPortStatuses as $peerPortStatus) { ?>
<tr>
<td class="text-left"><?php echo $peerPortStatus->port ?></td>
<td class="text-left"><?php echo date('Y-m-d H:s:i', $peerPortStatus->timeAdded) ?></td>
<td class="text-center padding-0">
<?php if ($peerPortStatus->status) { ?>
<span class="font-size-22 cursor-default text-color-green" title="<?php echo _('open') ?>">
&bull;
</span>
</td>
<?php } else { ?>
<span class="font-size-22 cursor-default text-color-red" title="<?php echo _('closed') ?>">
&bull;
</span>
<?php } ?>
</tr>
<?php } ?>
<?php } else { ?>
<tr>
<td colspan="3"><?php echo _('no records found') ?></td>
</tr>
<?php } ?>
</tbody>
<tfoot>
<tr>
<td class="text-left padding-x-0 padding-y-8" colspan="3">
<?php if ($responsePort->status) { ?>
<span class="padding-x-4 line-height-26 text-color-green">
<?php echo $responsePort->message ?>
</span>
<?php } else { ?>
<span class="padding-x-4 line-height-26 text-color-red">
<?php echo $responsePort->message ?>
</span>
<?php } ?>
<form name="port" method="post" action="<?php echo WEBSITE_URL ?>/peer.php?peerId=<?php echo $requestPeerId ?>">
<input class="text-center" type="text" name="port" value="<?php echo $requestPort ?>" maxlength="5" size="5" placeholder="<?php echo _('port') ?>" />
<button type="submit"><?php echo _('check') ?></button>
</form>
</td>
</tr>
</tfoot>
</table>
</div>
</div>
<h2> <h2>
<?php echo _('Traffic') ?> <?php echo _('Traffic') ?>
<span class="float-right"> <span class="float-right">

Loading…
Cancel
Save