diff --git a/.phpenv b/.phpenv new file mode 100644 index 00000000..2591ed4c --- /dev/null +++ b/.phpenv @@ -0,0 +1,19 @@ + \ No newline at end of file diff --git a/html_generator.php b/html_generator.php deleted file mode 100644 index 7107cb62..00000000 --- a/html_generator.php +++ /dev/null @@ -1,201 +0,0 @@ -" . PHP_EOL . - "" . PHP_EOL . - " " . PHP_EOL . - " " . PHP_EOL . - " " . PHP_EOL . - " " . PHP_EOL . - " " . PHP_EOL . - " " . $title . "" . PHP_EOL . - " " . PHP_EOL . - " " . PHP_EOL; - - $post = - " " . PHP_EOL . - "" . PHP_EOL; - - $html5 = $pre . $html_data . $post; - - return $html5; - } - - /* - * Writes HTML table with the following info: - * Token + shortened pubkey | Name | Description | Users | View Links(?) | Join URL - */ - function get_table_html($info_arrays) { - $table_lines = array(); - foreach($info_arrays as $id => $content) { - /* - * $id is "room token+shortened_pubkey", e.g. "example+09af" - * Each $content looks like this: - * $info_array = array( - * "name" => "Name of the room", - * "language" => "🇩🇪", - * "description" => "Some text that describes the community", - * "active_users" => 1234, - * "preview_link" => "https://example.com/r/example", - * "join_link" => "https://example.com/example?public_key=[64_hex_chars]" - * ); - */ - $exploded = explode("/", $content["join_link"]); // https: + "" + 1.2.3.4:56789 + token?public_key=0123456789abcdef - $server_url = $exploded[0] . "//" . $exploded[2]; // extract server_url - $token = explode("?", $exploded[3])[0]; // extract token - - $line = - " " . PHP_EOL . - " " . $id . "" . PHP_EOL . - " " . $content["language"] . "" . PHP_EOL . - " " . $content["name"] . "" . PHP_EOL . - " " . $content["description"] . "" . PHP_EOL . - " " . $content["active_users"] . "" . PHP_EOL . - " " . $content["preview_link"] . "" . PHP_EOL . - " \"Pictogram" . PHP_EOL . - " " . $content["join_link"] . "" . PHP_EOL . - " " . PHP_EOL; - $table_lines[] = $line; - } - - // prefix - $prefix = - "

Session Communities

" . PHP_EOL . - "" . PHP_EOL . - " " . PHP_EOL . - " " . PHP_EOL . - " " . PHP_EOL . - " " . PHP_EOL . - " " . PHP_EOL . - " " . PHP_EOL . - " " . PHP_EOL . - " " . PHP_EOL . - " " . PHP_EOL . - " " . PHP_EOL; - - // suffix - $suffix = - "
IdentifierLNameDescriptionUsersPreviewQRJoin URL
" . PHP_EOL . - "" . PHP_EOL . - " " . PHP_EOL . - " " . PHP_EOL . - " " . PHP_EOL . - " " . PHP_EOL . - " " . PHP_EOL . - " " . PHP_EOL . - "
" . count($table_lines) . " unique Session Communities on " . count_servers($info_arrays) . " servers have been found.
Last checked X minutes ago.
" . PHP_EOL; - - // concatenate html - $html = $prefix; - foreach($table_lines as $line) { - $html = $html . $line; - } - $html = $html . $suffix; - - return $html; - } - - /* - * Needed until all Community servers reliably generate QR codes again - */ - function get_qr_img_element_from_join_url($join_url) { - $data = get_base64_qr_code_from_join_url($join_url); - $mime = "image/png"; - $src = "data:" . $mime . ";base64," . $data; - - $result = - ""; -// echo($result . PHP_EOL); - - return $result; - } - - /* - * Use Google API to generate QR codes and encode them as base64 - */ - function get_base64_qr_code_from_join_url($join_url) { - // https://developers.google.com/chart/infographics/docs/qr_codes - $data = urlencode($join_url); - $size = "512x512"; - $api_url = - "https://chart.googleapis.com/chart?cht=qr" . - "&chs=" . $size . - "&chl=" . $data . - "&chld=L|0"; // error correction level: L = 7%, M = 15%, Q = 25%, H = 30% | margin in number of rows - $img_base64 = base64_encode(file_get_contents($api_url)); -// echo($img_base64 . PHP_EOL); - - return $img_base64; - } - - /* - * TODO: Description - */ - function create_qr_code_modals_html($info_arrays) { - $html = ""; - foreach($info_arrays as $id => $content) { - /* - * $id is "room token+shortened_pubkey", e.g. "example+09af" - * Each $content looks like this: - * $info_array = array( - * "name" => "Name of the room", - * "language" => "🇩🇪", - * "description" => "Some text that describes the community", - * "active_users" => 1234, - * "preview_link" => "https://example.com/r/example", - * "join_link" => "https://example.com/example?public_key=[64_hex_chars]" - * ); - */ - $img_elem = get_qr_img_element_from_join_url($content["join_link"]); // TODO: incorporate ID to use in js function - $modal_html = - "
" . PHP_EOL . - "
" . PHP_EOL . - " ×" . PHP_EOL . - " " . $img_elem . PHP_EOL . - "
" . PHP_EOL . - "
" . PHP_EOL; - - $html = $html . $modal_html; - } - - return $html; - } - - /* - * Generate the HTML for the toast/snackbar when you copy a join link - */ - function get_copy_snackbar() { - $snackbar_html = - "
" . - "Copied URL to clipboard. Paste into Session app to join." . - "
"; - - return $snackbar_html; - } - - /* - * TODO: Description - */ - function generateHTML($timestamp, $info_arrays) { - $title = "Self-updating list of active Session Communities"; - - $table_html = get_table_html($info_arrays); - $modal_html = create_qr_code_modals_html($info_arrays); - $snackbar_html = get_copy_snackbar(); - - $html = - $table_html . PHP_EOL . - $modal_html . PHP_EOL . - $snackbar_html . PHP_EOL; - - $final_html = create_html_page_from_html_data($html, $title, $timestamp); - - return $final_html; - } - -?> diff --git a/get_online_session_communities.php b/php/fetch-servers.php similarity index 94% rename from get_online_session_communities.php rename to php/fetch-servers.php index 0a83aa82..904ca6d8 100644 --- a/get_online_session_communities.php +++ b/php/fetch-servers.php @@ -2,21 +2,9 @@ // requires php-curl // require other php files - require "helper_functions.php"; - require "html_generator.php"; - include "languages/language_flags.php"; // actually runs fine without it - - // some global stuff - - // set timeout for file_get_contents() - ini_set('default_socket_timeout', 6); // in seconds, default is 60 - - // curl timeout is millisecons - $curl_connecttimeout_ms = 3000; // time for initiation of the connection - $curl_timeout_ms = 6000; // max time for whole connection (incl. transfer) - - // do not report warnings (timeouts, SSL/TLS errors) - error_reporting(E_ALL & ~E_WARNING); + require_once "getenv.php" + require_once "utils/server-utils.php"; + include_once "$LANGUAGES_ROOT/language_flags.php"; // actually runs fine without it // room token regex part, must consist of letters, numbers, underscores, or dashes: https://github.com/oxen-io/session-pysogs/blob/dev/administration.md $room_token_regex_part = "[0-9A-Za-z-_]+"; @@ -33,7 +21,6 @@ */ $room_join_regex = "/https?:\/\/[^\/]+\/" . $room_token_regex_part . "\?public_key=[0-9A-Fa-f]{64}/"; - /* * Some servers don't appear in the wild yet, but can be queried * Ideally this shouldn't be necessary, but it is for now @@ -50,8 +37,12 @@ ); // path for HTML output - $output = "output/index.html"; - + // $output = "output/index.html"; + + // path for room data output + $output = "$ROOMS_FILE"; + + file_exists($CACHE_ROOT) or mkdir($CACHE_ROOT, 700); // run main function main(); @@ -75,10 +66,11 @@ $addr_assignments = reduce_addresses_of_pubkeys($addr_assignments); $room_assignments = assign_rooms_to_address_assignments($addr_assignments, $rooms); $info_arrays = generate_info_arrays($room_assignments); + // $final_join_links = generate_join_links($room_assignments); - $final_html = generateHTML($timestamp, $info_arrays); +// $final_html = generateHTML($timestamp, $info_arrays); // print_r($wild_join_links); // print_r($servers); @@ -91,7 +83,7 @@ // write output to disk global $output; - file_put_contents($output, $final_html); // overwrites existing file + file_put_contents($output, json_encode($info_arrays)); // overwrites existing file echo("Done. " . count($info_arrays) . " unique Session Communities on " . count_servers($info_arrays) . " servers have been found." . PHP_EOL); } @@ -702,24 +694,6 @@ return $info_arrays; } - /* - * Counts every unique server from given $info_arrays and returns the count - */ - function count_servers($info_arrays) { - $servers = array(); - foreach($info_arrays as $i_arr) { - // https://sogs.example.com:1234/token?public_key=... - $join_link = $i_arr["join_link"]; - $exploded = explode("/", $join_link); // https: + "" + sogs.example.com:1234 + token?public_key=... - $servers[] = $exploded[0] . "//" . $exploded[2]; - } - $servers = array_unique($servers); - sort($servers); -// print_r($servers); - - return count($servers); - } - /* * Debug function to see which communities use pinned messages already */ diff --git a/php/generate-html.php b/php/generate-html.php new file mode 100644 index 00000000..b942f8bc --- /dev/null +++ b/php/generate-html.php @@ -0,0 +1,33 @@ + \ No newline at end of file diff --git a/php/getenv.php b/php/getenv.php new file mode 100644 index 00000000..baec93d0 --- /dev/null +++ b/php/getenv.php @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/php/update-listing.php b/php/update-listing.php new file mode 100644 index 00000000..401b3159 --- /dev/null +++ b/php/update-listing.php @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/helper_functions.php b/php/utils/server-utils.php similarity index 82% rename from helper_functions.php rename to php/utils/server-utils.php index b219c84f..c0e91a31 100644 --- a/helper_functions.php +++ b/php/utils/server-utils.php @@ -1,4 +1,23 @@ +?> \ No newline at end of file diff --git a/sites/+components/footer.php b/sites/+components/footer.php new file mode 100644 index 00000000..e69de29b diff --git a/sites/+components/qr_modals.php b/sites/+components/qr_modals.php new file mode 100644 index 00000000..3db6bc59 --- /dev/null +++ b/sites/+components/qr_modals.php @@ -0,0 +1,45 @@ + + + $room): ?> + + \ No newline at end of file diff --git a/sites/+components/tbl_communities.php b/sites/+components/tbl_communities.php new file mode 100644 index 00000000..200cb562 --- /dev/null +++ b/sites/+components/tbl_communities.php @@ -0,0 +1,67 @@ + "identifier", 'name' => "Identifier"], + ['id' => "language", 'name' => "L"], + ['id' => "name", 'name' => "Name"], + ['id' => "description", 'name' => "Description"], + ['id' => "users", 'name' => "Users"], + ['id' => "preview", 'name' => "Preview"], + ['id' => "qr", 'name' => "QR"], + ['id' => "join_url", 'name' => "Join URL"], + ]; +?> + + + + $column): ?> + id="th_"> + + + + + + $room): ?> + + + + + + + + + + + +
language?>name?> + description?> + + active_users?> + + preview_link?> + + + + Pictogram of a QR code + + + join_link?> + + +
\ No newline at end of file diff --git a/sites/+getenv.php b/sites/+getenv.php new file mode 120000 index 00000000..4953f846 --- /dev/null +++ b/sites/+getenv.php @@ -0,0 +1 @@ +../php/getenv.php \ No newline at end of file diff --git a/sites/index.php b/sites/index.php new file mode 100644 index 00000000..3e59f3d3 --- /dev/null +++ b/sites/index.php @@ -0,0 +1,42 @@ + + + + + + + + + Self-updating list of active Session communities + + +

Session Communities

+ + + + + + + + + + + + + +
+ Copied URL to clipboard. Paste into Session app to join +
+ + diff --git a/systemd/sessioncommunities.service b/systemd/sessioncommunities.service index 238f7810..57b749e4 100644 --- a/systemd/sessioncommunities.service +++ b/systemd/sessioncommunities.service @@ -5,4 +5,4 @@ Description=Scrape every known source for Session Communities and put the data t [Service] WorkingDirectory=/home/session/sessioncommunities.online User=session -ExecStart=/usr/bin/php get_online_session_communities.php +ExecStart=/usr/bin/php php/update-listing.php