You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			75 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			PHP
		
	
			
		
		
	
	
			75 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			PHP
		
	
<?php
 | 
						|
	/**
 | 
						|
	 * \file
 | 
						|
	 * Fetch online Communities and write the resulting data to disk.
 | 
						|
	 */
 | 
						|
 | 
						|
	// requires php-curl
 | 
						|
 | 
						|
	require_once 'getenv.php';
 | 
						|
	require_once 'utils/getopt.php';
 | 
						|
	require_once 'utils/utils.php';
 | 
						|
	require_once 'servers/known-servers.php';
 | 
						|
	require_once 'servers/servers-rooms.php';
 | 
						|
	require_once 'servers/sources.php';
 | 
						|
	require_once 'languages/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 $CACHE_ROOT, $ROOMS_FILE, $KNOWN_SERVERS, $KNOWN_PUBKEYS, $DO_DRY_RUN;
 | 
						|
 | 
						|
		// Create default directories..
 | 
						|
		file_exists($CACHE_ROOT) or mkdir($CACHE_ROOT, 0700);
 | 
						|
 | 
						|
		// Query our sources and store the resulting HTML.
 | 
						|
		$sources = new CommunitySources();
 | 
						|
 | 
						|
		/**
 | 
						|
		 * @var CommunityServer[] $servers
 | 
						|
		 */
 | 
						|
		$servers = CommunityServer::from_join_urls($sources->get_join_urls());
 | 
						|
 | 
						|
		// 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);
 | 
						|
 | 
						|
		// Fill additional information from sources.
 | 
						|
		CommunityServer::source_additional_info($servers, $sources);
 | 
						|
 | 
						|
		// 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.
 | 
						|
		if (!$DO_DRY_RUN) file_put_contents($ROOMS_FILE, json_encode($servers));
 | 
						|
	}
 | 
						|
 | 
						|
	// Fetch servers
 | 
						|
	main();
 | 
						|
 | 
						|
?>
 |