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.
		
		
		
		
		
			
		
			
				
	
	
		
			102 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			PHP
		
	
			
		
		
	
	
			102 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			PHP
		
	
| <?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';
 | |
| 	require_once 'utils/sources.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 $CACHE_ROOT, $ROOMS_FILE, $KNOWN_SERVERS, $KNOWN_PUBKEYS;
 | |
| 
 | |
| 		// 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.
 | |
| 		file_put_contents($ROOMS_FILE, json_encode($servers));
 | |
| 	}
 | |
| 
 | |
| 	/**
 | |
| 	 * 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();
 | |
| 
 | |
| ?>
 |