diff --git a/database/yggstate.mwb b/database/yggstate.mwb index 9a2e43c..b0e06fb 100644 Binary files a/database/yggstate.mwb and b/database/yggstate.mwb differ diff --git a/media/db-prototype.png b/media/db-prototype.png index 3707538..e7c28f2 100644 Binary files a/media/db-prototype.png and b/media/db-prototype.png differ diff --git a/src/config/app.php.example b/src/config/app.php.example index 35bc19e..6aa87a6 100644 --- a/src/config/app.php.example +++ b/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_PAGINATION_LIMIT', 20); +define('WEBSITE_PEER_PORT_CHECK_TIMEOUT', 60 * 5); + // Crawler define('CRAWL_STOP_DISK_QUOTA_MB_LEFT', 128); \ No newline at end of file diff --git a/src/library/mysql.php b/src/library/mysql.php index 5372047..5e6c0dd 100644 --- a/src/library/mysql.php +++ b/src/library/mysql.php @@ -114,6 +114,84 @@ class MySQL { 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 public function findGeo(mixed $geoCountryId, mixed $geoCityId, mixed $geoCoordinateId) { // int|null diff --git a/src/public/assets/theme/default/css/common.css b/src/public/assets/theme/default/css/common.css index ade6b97..169c69a 100644 --- a/src/public/assets/theme/default/css/common.css +++ b/src/public/assets/theme/default/css/common.css @@ -72,6 +72,10 @@ tbody tr:hover { background: #f2f2f2; } +tfoot { + border-top: 1px #f2f2f2 solid; +} + a, a:hover, a:active, a:visited { color: #5785b7; text-decoration: none; @@ -89,9 +93,16 @@ form > input::placeholder { color: #333; } -form > input[type="text"] { - padding: 7px 4px; +form > input[name="query"] { + padding: 6px 4px; min-width: 260px; + border: 1px #f2f2f2 solid; +} + +form > input[name="port"] { + padding: 6px 4px; + min-width: 64px; + border: 1px #f2f2f2 solid; } form > button { diff --git a/src/public/assets/theme/default/css/framework.css b/src/public/assets/theme/default/css/framework.css index 5eb09cf..1b350b3 100644 --- a/src/public/assets/theme/default/css/framework.css +++ b/src/public/assets/theme/default/css/framework.css @@ -44,6 +44,10 @@ color: #5785b7; } +.line-height-26 { + line-height: 26px; +} + /* .background-color-green { background-color: #e9f9e7; @@ -66,10 +70,25 @@ padding: 0; } +.padding-x-0 { + padding-left: 0; + padding-right: 0; +} + .padding-4 { padding: 4px; } +.padding-x-4 { + padding-left: 4px; + padding-right: 4px; +} + +.padding-y-8 { + padding-top: 8px; + padding-bottom: 8px; +} + .margin-y-8 { margin-top: 8px; margin-bottom: 8px; diff --git a/src/public/peer.php b/src/public/peer.php index 9a20b9c..4debd18 100644 --- a/src/public/peer.php +++ b/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'; $requestPage = isset($_GET['page']) && $_GET['page'] > 1 ? (int) $_GET['page'] : 1; $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 $calendar = new Yggverse\Graph\Calendar\Month($requestTime); @@ -114,6 +115,77 @@ $peerRemoteConnections = $memory->getByMethodCallback( $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); + ?> @@ -123,10 +195,14 @@ $peerInfo = $memory->getByMethodCallback($db, 'getPeerInfo', [$requestPeerId]); - <?php echo sprintf(_('Peer %s - %s'), $peerInfo->address, WEBSITE_NAME) ?> + <?php if ($peerInfo) { ?> + <?php echo sprintf(_('Peer %s - %s'), $peerInfo->address, WEBSITE_NAME) ?> + <?php } else { ?> + <?php echo _('Not found') ?> + <?php } ?> - - + + @@ -227,7 +303,7 @@ $peerInfo = $memory->getByMethodCallback($db, 'getPeerInfo', [$requestPeerId]);
-

+

@@ -311,6 +387,61 @@ $peerInfo = $memory->getByMethodCallback($db, 'getPeerInfo', [$requestPeerId]); +
+
+
+ + + + + + + + + + + + + + + • + + + + + + + + + + + + + + + +
port ?>timeAdded) ?> + status) { ?> + + • + +
+ status) { ?> + + message ?> + + + + message ?> + + +
+ + +
+
+
+