|
|
|
<?php
|
|
|
|
// requires php-curl
|
|
|
|
|
|
|
|
require_once 'getenv.php';
|
|
|
|
require_once 'utils/utils.php';
|
|
|
|
require_once 'servers/known-servers.php';
|
|
|
|
require_once 'utils/servers-rooms.php';
|
|
|
|
|
|
|
|
// Not required
|
|
|
|
include_once "$LANGUAGES_ROOT/language_flags.php";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch online Communities and write the resulting data to disk.
|
|
|
|
* Communities are fetched as follows:
|
|
|
|
*
|
|
|
|
* 1. Get join links from our sources
|
|
|
|
* 2. Parse join links into servers
|
|
|
|
* 3. Add hardcoded servers
|
|
|
|
* 4. De-dupe servers based on base URL
|
|
|
|
* 5. Fetch server rooms and pubkey
|
|
|
|
* 6. De-dupe servers based on pubkey
|
|
|
|
*/
|
|
|
|
function main() {
|
|
|
|
global $LOGGING_VERBOSITY;
|
|
|
|
|
|
|
|
// Read the -v|--verbose option increasing logging verbosity to debug.
|
|
|
|
$options = getopt("v", ["verbose"]);
|
|
|
|
if (isset($options["v"]) or isset($options["verbose"])) {
|
|
|
|
$LOGGING_VERBOSITY = LoggingVerbosity::Debug;
|
|
|
|
}
|
|
|
|
|
|
|
|
global $CACHE_ROOT, $ROOMS_FILE, $KNOWN_SERVERS, $KNOWN_PUBKEYS;
|
|
|
|
|
|
|
|
// Create default directories with conservative permissions.
|
|
|
|
file_exists($CACHE_ROOT) or mkdir($CACHE_ROOT, 0700);
|
|
|
|
|
|
|
|
// Query our sources and store the resulting HTML.
|
|
|
|
// TODO: Tag information is currently discarded. Feature needs triage.
|
|
|
|
$html_pages = query_known_sources();
|
|
|
|
// Find join links in each HTML document and merge the resulting arrays.
|
|
|
|
$join_links = array_merge([], ...array_map('parse_join_links', $html_pages));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var CommunityServer[] $servers
|
|
|
|
*/
|
|
|
|
$servers = CommunityServer::from_join_urls($join_links);
|
|
|
|
|
|
|
|
// Add known hosts.
|
|
|
|
$servers = [...CommunityServer::from_known_hosts($KNOWN_SERVERS, $KNOWN_PUBKEYS), ...$servers];
|
|
|
|
|
|
|
|
// Merge servers with the same URL.
|
|
|
|
$servers = CommunityServer::dedupe_by_url($servers);
|
|
|
|
|
|
|
|
// Fetch server data and filter unreachable servers.
|
|
|
|
$servers = CommunityServer::poll_reachable($servers);
|
|
|
|
|
|
|
|
// Merge servers with the same public key.
|
|
|
|
$servers = CommunityServer::dedupe_by_pubkey($servers);
|
|
|
|
|
|
|
|
// Count servers and rooms.
|
|
|
|
$servers_total = count($servers);
|
|
|
|
$rooms_total = count_rooms($servers);
|
|
|
|
|
|
|
|
log_info("Done fetching communities.");
|
|
|
|
log_info(
|
|
|
|
"Found $rooms_total unique Session Communities " .
|
|
|
|
"on $servers_total servers." . PHP_EOL
|
|
|
|
);
|
|
|
|
|
|
|
|
// Output fetching results to file.
|
|
|
|
file_put_contents($ROOMS_FILE, json_encode($servers));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetches known sources of Session Community join links.
|
|
|
|
* @return string[] HTML pages containing join URLs.
|
|
|
|
*/
|
|
|
|
function query_known_sources(): array {
|
|
|
|
global $SOURCES;
|
|
|
|
|
|
|
|
log_info("Requesting Awesome Session Group list...");
|
|
|
|
$pages_asgl[] = file_get_contents($SOURCES['ASGL']);
|
|
|
|
log_debug($http_response_header[0]); // Supposed to be "HTTP/1.1 200 OK"
|
|
|
|
|
|
|
|
log_info("Requesting Lokilocker Mods Open Group list...");
|
|
|
|
$pages_loki[] = file_get_contents($SOURCES['LOKI']);
|
|
|
|
log_debug($http_response_header[0]); // Supposed to be "HTTP/1.1 200 OK"
|
|
|
|
|
|
|
|
log_info("Requesting session.directory list...");
|
|
|
|
$pages_sdir = [];
|
|
|
|
$json_sdir = json_decode(file_get_contents($SOURCES['SDIR-JSON']));
|
|
|
|
log_debug($http_response_header[0]); // Supposed to be "HTTP/1.1 200 OK"
|
|
|
|
foreach ($json_sdir as $room) $pages_sdir[] = $room->url;
|
|
|
|
|
|
|
|
log_info("Requesting FreeArkham.cc list...");
|
|
|
|
$pages_fark[] = file_get_contents($SOURCES['FARK']);
|
|
|
|
log_debug($http_response_header[0]); // Supposed to be "HTTP/1.1 200 OK"
|
|
|
|
|
|
|
|
log_info('Done fetching sources.');
|
|
|
|
|
|
|
|
return [...$pages_asgl, ...$pages_loki, ...$pages_sdir, ...$pages_fark];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Debug function to see which communities use pinned messages already
|
|
|
|
* @deprecated
|
|
|
|
*/
|
|
|
|
function print_pinned_messages($room_assignments_arr) {
|
|
|
|
// for each server a.k.a. public key do
|
|
|
|
foreach($room_assignments_arr as $pubkey => $room_assignment) {
|
|
|
|
// for every room do
|
|
|
|
foreach($room_assignment[1] as $room_array) {
|
|
|
|
// info:
|
|
|
|
// $room_array = array(
|
|
|
|
// "token" => bla,
|
|
|
|
// "name" => Blabla,
|
|
|
|
// "active_users" => -1,
|
|
|
|
// "description" => Blabla bla bla
|
|
|
|
//);
|
|
|
|
$server_url = $room_assignment[0];
|
|
|
|
$room_json_url = $server_url . "/room/" . $room_array["token"];
|
|
|
|
echo($room_json_url . PHP_EOL);
|
|
|
|
$contents = file_get_contents($room_json_url);
|
|
|
|
if($contents) {
|
|
|
|
// print_r($contents);
|
|
|
|
$json_obj = json_decode($contents);
|
|
|
|
$pinned_messages = $json_obj->pinned_messages;
|
|
|
|
echo("Pinned messages:" . PHP_EOL);
|
|
|
|
print_r($pinned_messages);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fetch servers
|
|
|
|
main();
|
|
|
|
|
|
|
|
?>
|