podcrawler.php 1.32 KB
Newer Older
David Morley's avatar
David Morley committed
1 2
<?php

3 4 5 6 7 8
/**
 * Crawl and add all pods from the-federation.info list.
 */

declare(strict_types=1);

9 10
use RedBeanPHP\R;

11
require_once __DIR__ . '/../boot.php';
12

David Morley's avatar
David Morley committed
13 14 15 16 17
if (!is_cli()) {
    header('HTTP/1.0 403 Forbidden');
    exit;
}

18
try {
19 20 21 22 23
    $sql  = '
        SELECT domain, status
        FROM pods
    ';
    $pods = R::getAll($sql);
24 25 26 27 28 29 30 31 32 33 34
} catch (\RedBeanPHP\RedException $e) {
    die('Error in SQL query: ' . $e->getMessage());
}

//get all existing pod domains
$existingpods = array_column($pods, 'domain');

$foundpods = [];

//pulling all nodes for now
if ($pods = json_decode(file_get_contents('https://the-federation.info/graphql?query=%7Bnodes%7Bhost%20platform%7Bname%7Dprotocols%7Bname%7D%7D%7D&raw'), true)) {
35 36
    foreach ($pods['data']['nodes'] ?? [] as $poddata) {
        $protocols = array_column($poddata['protocols'] ?? [], 'name');
37

38 39 40 41
        //limiting to diaspora compatible for now
        if (in_array('diaspora', $protocols, true)) {
            $foundpods[] = $poddata['host'];
        }
42
    }
43 44 45
}

if ($pods = json_decode(file_get_contents('https://diasp.org/pods.json'), true)) {
46 47 48
    foreach ($pods ?? [] as $poddata) {
        $foundpods[] = $poddata['host'];
    }
49 50 51 52
}

$results = array_diff($foundpods, $existingpods);
foreach ($results as $result) {
53
    echo $result . ' ';
54
    echo exec("php-cgi add.php domain={$result}") . "\r\n";
David Morley's avatar
David Morley committed
55
}