diff --git a/.gitignore b/.gitignore index 6e3ac62..c4930c3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,9 @@ -.vscode -.ftpignore +/.vscode/ +/vendor/ + +/database/yggstate.mwb.bak -/config/app.php -/database/yggstate.mwb.bak \ No newline at end of file +/src/config/app.php + +.ftpignore +composer.lock diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..d7c8992 --- /dev/null +++ b/composer.json @@ -0,0 +1,17 @@ +{ + "name": "yggverse/yggstate", + "description": "Yggdrasil Network Analytics", + "type": "project", + "require": { + "php": ">=8.1", + "yggverse/yggdrasilctl": ">=0.1.0", + "yggverse/parser": ">=0.1.0" + }, + "license": "MIT", + "autoload": { + "psr-4": { + "Yggverse\\Yggstate\\": "src/" + } + }, + "minimum-stability": "alpha" +} diff --git a/library/url.php b/library/url.php deleted file mode 100644 index bada461..0000000 --- a/library/url.php +++ /dev/null @@ -1,82 +0,0 @@ - (object) - [ - 'url' => null, - 'scheme' => null, - 'name' => null, - 'port' => null, - ], - 'page' => (object) - [ - 'url' => null, - 'uri' => null, - 'path' => null, - 'query' => null, - ] - ]; - - // Validate URL - if (!self::is($url)) { - - return false; - } - - // Parse host - if ($scheme = parse_url($url, PHP_URL_SCHEME)) { - - $result->host->url = $scheme . '://'; - $result->host->scheme = $scheme; - - } else { - - return false; - } - - if ($host = parse_url($url, PHP_URL_HOST)) { - - $result->host->url .= $host; - $result->host->name = $host; - - } else { - - return false; - } - - if ($port = parse_url($url, PHP_URL_PORT)) { - - $result->host->url .= ':' . $port; - $result->host->port = $port; - - // port is optional - } - - // Parse page - if ($path = parse_url($url, PHP_URL_PATH)) { - - $result->page->uri = $path; - $result->page->path = $path; - } - - if ($query = parse_url($url, PHP_URL_QUERY)) { - - $result->page->uri .= '?' . $query; - $result->page->query = '?' . $query; - } - - $result->page->url = $result->host->url . $result->page->uri; - - return $result; - } -} \ No newline at end of file diff --git a/library/yggdrasil.php b/library/yggdrasil.php deleted file mode 100644 index dd90f92..0000000 --- a/library/yggdrasil.php +++ /dev/null @@ -1,55 +0,0 @@ -peers)) { - - return false; - } - - foreach ((object) $result->peers as $peer) { - - switch (false) { - - case isset($peer->bytes_recvd): - case isset($peer->bytes_sent): - case isset($peer->remote): - case isset($peer->port): - case isset($peer->key): - case isset($peer->uptime): - case !empty($peer->coords): - - return false; - } - } - - return $result->peers; - } -} \ No newline at end of file diff --git a/config/app.php.example b/src/config/app.php.example similarity index 100% rename from config/app.php.example rename to src/config/app.php.example diff --git a/crontab/crawler.php b/src/crontab/crawler.php similarity index 95% rename from crontab/crawler.php rename to src/crontab/crawler.php index 4770c3a..8b71d9b 100644 --- a/crontab/crawler.php +++ b/src/crontab/crawler.php @@ -20,7 +20,7 @@ if (false === sem_acquire($semaphore, true)) { require_once(__DIR__ . '/../config/app.php'); require_once(__DIR__ . '/../library/yggdrasil.php'); require_once(__DIR__ . '/../library/mysql.php'); -require_once(__DIR__ . '/../library/url.php'); +require_once __DIR__ . '/../vendor/autoload.php'; // Check disk quota if (CRAWL_STOP_DISK_QUOTA_MB_LEFT > disk_free_space('/') / 1000000) { @@ -63,7 +63,7 @@ try { } // Collect connected peers -if ($connectedPeers = Yggdrasil::getPeers()) { +if ($connectedPeers = Yggverse\Yggdrasilctl\Yggdrasil::getPeers()) { foreach ($connectedPeers as $connectedPeerAddress => $connectedPeerInfo) { @@ -84,7 +84,7 @@ if ($connectedPeers = Yggdrasil::getPeers()) { } // Init peer data - if ($connectedPeerRemoteUrl = URL::parse($connectedPeerInfo->remote)) { + if ($connectedPeerRemoteUrl = Yggverse\parser\Url::parse($connectedPeerInfo->remote)) { if ($dbPeerRemote = $db->findPeerRemote($dbPeerId, $connectedPeerRemoteUrl->host->scheme, diff --git a/library/mysql.php b/src/library/mysql.php similarity index 100% rename from library/mysql.php rename to src/library/mysql.php diff --git a/public/index.html b/src/public/index.html similarity index 100% rename from public/index.html rename to src/public/index.html