1
0
Fork 1

Merge branch 'main' of lokilocker.com:SomeGuy/sessioncommunities.online

main
mdPlusPlus 1 year ago
commit 9693a12f58

@ -9,6 +9,12 @@
include_once "$PROJECT_ROOT/php/utils/logging.php";
// 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;
}
// set timeout for file_get_contents()
ini_set('default_socket_timeout', 6); // in seconds, default is 60

@ -1,5 +1,7 @@
port = 8081
output = output
PORT ?= 8081
OUTPUT ?= output
FLAGS ?=
MAKE = make FLAGS=$(FLAGS)
# First goal is the default with `make`.
@ -14,54 +16,54 @@ all: fetch html
# Fetch room listing.
fetch:
/bin/php php/fetch-servers.php
# Fetch room listing with extra verbosity.
fetch-v:
/bin/php php/fetch-servers.php --verbose
/bin/php php/fetch-servers.php $(FLAGS)
# Generate HTML from data.
html:
/bin/php php/generate-html.php
# Last item run in foreground to receive interrupts.
/bin/php php/generate-html.php $(FLAGS)
# Serve a local copy which responds to file changes.
dev: FLAGS = --verbose
dev: open
make server &
make watchdog
$(MAKE) server &
$(MAKE) watchdog
# (Last item run in foreground to receive interrupts.)
# Serve a local copy on LAN which responds to file changes.
lan-dev: FLAGS = --verbose
lan-dev: open
ip addr | fgrep -e ' 192.' -e ' 10.'
make lan-server &
make watchdog
-which ip 1>/dev/null 2>/dev/null && ip addr | fgrep -e ' 192.' -e ' 10.' || true
$(MAKE) lan-server &
$(MAKE) watchdog
# Serve a local copy.
server:
/bin/php -S localhost:$(port) -t $(output)
/bin/php -S "localhost:$(PORT)" -t "$(OUTPUT)"
# Serve a local copy on all interfaces.
lan-server:
/bin/php -S 0.0.0.0:$(port) -t $(output)
/bin/php -S "0.0.0.0:$(PORT)" -t "$(OUTPUT)"
# Open locally served page in browser.
open:
xdg-open http://localhost:$(port) >/dev/null 2>/dev/null & disown
xdg-open "http://localhost:$(PORT)" >/dev/null 2>/dev/null & disown
# Update HTML on file change. Doesn't check for new files.
watchdog:
find . | entr -n -s "make html"
find . | grep -v ".git" | entr -n -s "$(MAKE) html"
# Remove artefacts
clean:
-rm -r cache
-rm -r output/*.html
-rm -r cache 2>/dev/null || true
-rm -r output/*.html 2>/dev/null || true
# Build everything from scratch and test functionality.
test: FLAGS = --verbose
test: clean all open server
# Build everything from scratch and test functionality on LAN.
test-lan: FLAGS = --verbose
test-lan: clean all open lan-server
# -- Aliases --

@ -1 +1 @@
Subproject commit 68672e0dea301345c1936303f168822849240321
Subproject commit 8da350aa55aa768b42d008b874761b7f5daf8cda

@ -58,7 +58,6 @@ html.js .noscript, .hidden {
}
html:not(.js) .js-only {
/* Dead style */
display: none;
}
@ -330,7 +329,7 @@ footer {
max-width: 100%;
text-align: center;
padding-top: var(--body-margin);
padding-bottom: var(--body-margin);
padding-inline: var(--body-margin);
}

@ -21,14 +21,6 @@
* 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.

@ -15,26 +15,34 @@
return $files;
}
foreach (rglob("$TEMPLATES_ROOT/*.php") as $phppath) {
// Do not render auxiliary PHP files.
if (str_contains("$phppath", "/+") || $phppath[0] == "+")
continue;
function generate_html() {
global $LOGGING_VERBOSITY, $TEMPLATES_ROOT, $DOCUMENT_ROOT;
$flags = LoggingVerbosity::getVerbosityFlags($LOGGING_VERBOSITY)[1];
$docpath = str_replace($TEMPLATES_ROOT, $DOCUMENT_ROOT, $phppath);
$relpath = str_replace($TEMPLATES_ROOT, "", $phppath);
$docpath = str_replace(".php", ".html", $docpath);
foreach (rglob("$TEMPLATES_ROOT/*.php") as $phppath) {
// Do not render auxiliary PHP files.
if (str_contains("$phppath", "/+") || $phppath[0] == "+")
continue;
// This works? Yes, yes it does.
// We do this to isolate the environment and include-once triggers,
// otherwise we could include the documents in an ob_* wrapper.
// Same as shell_exec, except we don't have to escape quotes.
log_info("Generating output for $relpath.");
$document = `cd "$TEMPLATES_ROOT"; php $phppath`;
$docpath = str_replace($TEMPLATES_ROOT, $DOCUMENT_ROOT, $phppath);
$relpath = str_replace($TEMPLATES_ROOT, "", $phppath);
$docpath = str_replace(".php", ".html", $docpath);
file_put_contents($docpath, $document);
// This works? Yes, yes it does.
// We do this to isolate the environment and include-once triggers,
// otherwise we could include the documents in an ob_* wrapper.
// Same as shell_exec, except we don't have to escape quotes.
log_info("Generating output for $relpath.");
$document = `cd "$TEMPLATES_ROOT"; php $phppath $flags`;
file_put_contents($docpath, $document);
}
log_info("Done generating HTML.");
}
log_info("Done generating HTML.");
generate_html();
?>

@ -30,10 +30,14 @@
"http://captain.geekgalaxy.com",
"http://session.hwreload.it",
"http://sogs.k9net.org",
"https://gaohuangse.work",
// Found via Reddit:
"http://5.39.117.98",
// legacy
// "http://3.69.29.128", // former https://reccacon.com
// Offline:
// "http://13.233.251.36:8081",
@ -52,13 +56,15 @@
"13.233.251.36:8081" => "efcaecf00aebf5b75e62cf1fd550c6052842e1415a9339406e256c8b27cd2039",
"164.92.176.135" => "e529311ec8fb6fdb950aaa4fb71fc4da3ea59c6c9ba2886708b9538eea6aa213",
"176.119.147.102" => "e093994156ec92e4c13d0387208bfa48ae56dd88b8f60a03980d9ef048af1e3f",
"3.69.29.128" => "02bdb3f74b59355724b1a59676127729602b5e34261efb965a94ccac94cd6a62",
"5.39.117.98" => "4bec6d6c7b502a819b47b3af75272c0774ab1214fba33fb5ec29949f864eb028",
"60a9fc9.online-server.cloud" => "7908bcd748313355f99e62f9c1f11c395d04019410edb7ee1618dbe26a423c4f",
"93.95.230.10" => "b501f2dc7dc912aa0981b0ba10f2ba739d2f729a7d9b37022aee505aaf72807c",
"94.176.239.60" => "2cbde327e9da216af9a69876bc57e16cc0c540b0aa2dfecdd1c115e67993b040",
"captain.geekgalaxy.com" => "7242ad657dc2dd20e902a6fa82c34465907b67e80daf50173f38d5745abbaa24",
"gaohuangse.work" => "2cd535b2e6a1fb40d1166910561d85a027782b1d751118897eca6056f4738a10",
"open.getsession.org" => "a03c383cf63c3c4efe67acc52112a6dd734b3a946b9545f488aaa93da7991238",
"session.hwreload.it" => "4b3e75eedd2116b4dab0bcb6443b0e9fbfce7bcf1d35970bdad8a57a0113fb20",
"sogs.k9net.org" => "fdcb047eb78520e925fda512a45ae74c6e2de9e0df206b3c0471bf1509919559",
);
?>
?>

@ -44,7 +44,7 @@
/**
* Returns the color marker for the given logging verbosity.
* @param $verbosity Logging verbosity to used for printing.
* @param int $verbosity Logging verbosity to used for printing.
* @return ?string Terminal escape sequence to color foreground text.
*/
static function getVerbosityColorMarker(int $verbosity): ?string {
@ -56,6 +56,18 @@
default => ''
};
}
/**
* Returns a pair of optíons trigerring the given verbosity.
* @param int $verbosity Logging verbosity to set using flag.
* @return string[] Pair of short and long command-line verbosity flags.
*/
static function getVerbosityFlags(int $verbosity): array {
return match($verbosity) {
LoggingVerbosity::Debug => ["-v", "--verbose"],
default => ['', '']
};
}
}
/**
@ -135,12 +147,12 @@
* Only logs when `$LOGGING_VERBOSITY` is debug and below.
* @param string $msg String message to log.
*/
function log_value(mixed $value) {
log_debug(var_export($value, true));
function log_value(mixed $value, int $message_verbosity = LoggingVerbosity::Debug) {
_log_message(var_export($value, true), $message_verbosity);
}
/**
* @var $LOGGING_VERBOSITY
* @var int $LOGGING_VERBOSITY
* Global setting.
* Controls how detailed the displayed logs are.
*/

@ -1,7 +1,11 @@
<?php
include_once "$PROJECT_ROOT/languages/language_flags.php";
$MINUTE_SECONDS = 60;
$HOUR_SECONDS = 60 * $MINUTE_SECONDS;
$DAY_SECONDS = 24 * $HOUR_SECONDS;
$WEEK_SECONDS = 7 * $DAY_SECONDS;
/**
* Representation of Session Community room.
*/
@ -130,6 +134,33 @@
}, $details);
}
/**
* Sorts Community rooms in-place by the given string property.
* @param \CommunityRoom[] $rooms Rooms to sort by given key.
* @param string $key String property of CommunityRoom to sort by.
*/
public static function sort_rooms_str(array &$rooms, string $key) {
usort($rooms, function(\CommunityRoom $a, \CommunityRoom $b) use ($key) {
return strcmp(
$a->$key,
$b->$key
);
});
}
/**
* Sorts Community rooms in-place by their server's public key.
* @param \CommunityRoom[] $rooms Rooms to sort by server pubkey.
*/
public static function sort_rooms_by_pubkey(array &$rooms) {
usort($rooms, function(\CommunityRoom $a, \CommunityRoom $b) {
return strcmp(
$a->server->get_pubkey(),
$b->server->get_pubkey()
);
});
}
/**
* Returns array of staff Session IDs.
* @return string[]
@ -147,6 +178,32 @@
return time() - $this->created;
}
/**
* Formats the period over which active users are counted as a duration string.
* @return string Active user cutoff period for this room, expressed in days.
*/
function format_user_cutoff_period(): ?string {
global $WEEK_SECONDS, $DAY_SECONDS, $HOUR_SECONDS, $MINUTE_SECONDS;
$active_users_cutoff = $this->active_users_cutoff;
if ($active_users_cutoff >= $WEEK_SECONDS) {
return floor($active_users_cutoff / $WEEK_SECONDS) . ' week(s)';
}
if ($active_users_cutoff >= $DAY_SECONDS) {
return floor($active_users_cutoff / $DAY_SECONDS) . ' day(s)';
}
if ($active_users_cutoff >= $HOUR_SECONDS) {
return floor($active_users_cutoff / $HOUR_SECONDS) . ' hour(s)';
}
if ($active_users_cutoff >= $MINUTE_SECONDS) {
return floor($active_users_cutoff / $MINUTE_SECONDS) . 'minute(s)';
}
return floor($active_users_cutoff) . 's';
}
/**
* Return the browser preview URL for this room.
*/
@ -220,7 +277,7 @@
/**
* @var bool $merge_error
*
*
* Flag specifying whether the server is invalidated as a result of merging.
*/
private bool $merge_error = false;

@ -9,15 +9,15 @@
// Once handlers are attached in JS, this check ceases to be useful.
function column_sortable($id) {
// Join URL contents are not guaranteed to have visible text.
return $id != "qr" && $id != "preview" && $id != "join_url";
return $id != "qr_code" && $id != "preview" && $id != "join_url";
}
function sort_onclick($colno) {
global $TABLE_COLUMNS;
$column = $TABLE_COLUMNS[$colno];
$name = isset($column['name_long']) ? $column['name_long'] : $column['name'];
if (!column_sortable($column['id'])) return " title='Column: $name'";
return " title='Click to sort by $name'";
if (!column_sortable($column['id'])) return " title='$name'";
return " title='Click to sort by $name'.";
}
// Note: Changing the names displayed requires updating
@ -28,11 +28,11 @@
['id' => "language", 'name' => "L", 'name_long' => "Language"],
['id' => "name", 'name' => "Name"],
['id' => "description", 'name' => "About", 'name_long' => "Description"],
['id' => "users", 'name' => "#", 'name_long' => "Weekly Active Users"],
['id' => "users", 'name' => "#", 'name_long' => "Active Users"],
['id' => "preview", 'name' => "Preview"],
['id' => "qr_code", 'name' => "QR"],
['id' => "qr_code", 'name' => "QR", 'name_long' => "QR Code (for use in-app)"],
['id' => "server_icon", 'name' => "Host", 'name_long' => "Server host"],
['id' => "join_url", 'name' => "URL", 'name_long' => "In-app Join URL"],
['id' => "join_url", 'name' => "URL", 'name_long' => "Join URL (for use in-app)"],
];
?>
@ -58,6 +58,7 @@
$name = html_sanitize($room->name);
$desc = html_sanitize($room->description);
$users = html_sanitize($room->active_users);
$users_cutoff = html_sanitize($room->format_user_cutoff_period());
$preview_link = html_sanitize($room->get_preview_url());
$join_link = html_sanitize($room->get_join_url());
$pubkey = html_sanitize($pubkey);
@ -70,17 +71,31 @@
data-hostname="<?=$hostname?>"
>
<td class="td_identifier" itemprop="identifier"><?=$id?></td>
<td class="td_language"><?=$language?></td>
<td class="td_name" title="'<?=$room->name?>' preview" itemprop="name">
<a href="<?=$room->get_preview_url()?>" target="_blank" rel="noopener noreferrer">
<?=$room->name?>
<td class="td_language" title="Language flag for '<?=$name?>'"><?=$language?></td>
<td class="td_name" title="Click here to preview '<?=$name?>'" itemprop="name">
<a href="<?=$preview_link?>" target="_blank" rel="noopener noreferrer">
<?=$name?>
</a>
</td>
<td class="td_description" itemprop="description"><?=$desc?></td>
<td class="td_users"><?=$users?></td>
<td
class="td_description"
title="Description for '<?=$name?>':
<?=$desc?>"
itemprop="description"
><?=$desc?></td>
<td
class="td_users"
title="'<?=$name?>' has had <?=$users?> active users in the last <?=$users_cutoff?>."
><?=$users?></td>
<td class="td_preview" itemprop="url">
<a href="<?=$preview_link?>" target="_blank" rel="noopener noreferrer nofollow">
<a
href="<?=$preview_link?>"
title="Click here to preview '<?=$name?>'"
target="_blank"
rel="noopener noreferrer nofollow"
>
<span class="protocol-indicator"></span>
</a>
</td>
@ -89,11 +104,12 @@
class="qr-code-icon"
src="qrcode-solid.svg"
alt="Pictogram of a QR code"
title="Click here to view the QR Code for '<?=$name?>'"
>
</td>
<td class="td_server_icon"
data-sort-by="<?=$pubkey?>"
title="<?=$hostname?> (<?=$pubkey?>)"
title="Host: <?=$hostname?> (<?=$pubkey?>)"
item="image"
>
<div class="td_server_icon-circle" style="background-color: <?=$icon_color?>">
@ -104,8 +120,12 @@
<div class="join_url_container" data-url="<?=$join_link?>">
<a class="join_url show-from-w5" title="<?=$join_link?>"
><?=truncate($join_link, 32)?></a>
<a class="noscript" href="<?=$join_link?>" rel="external nofollow"
>Copy link</a>
<a
class="noscript"
title="Copy this link to join '<?=$name?>'."
href="<?=$join_link?>"
rel="external nofollow"
>Copy link</a>
</div>
</td>
</tr>

@ -16,6 +16,10 @@
// List all rooms from the cached servers.
$rooms = CommunityServer::enumerate_rooms($servers);
// Sort rooms by name and then host.
CommunityRoom::sort_rooms_str($rooms, 'name');
CommunityRoom::sort_rooms_by_pubkey($rooms);
// Set the last-updated timestamp
// to the time the server data file was last modified.
$timestamp = filemtime($ROOMS_FILE);
@ -92,9 +96,15 @@
target="_blank"
>various sources</a>.
<br>
We make an attempt to hide communities containing
objectionable or illegal content, but
you should still proceed with caution.
<span class="js-only">
We make an attempt to hide communities containing
objectionable or illegal content, but
you should still proceed with caution.
</span>
<span class="noscript">
Proceed with caution when joining unofficial communities.
As JavaScript is disabled, no communities are filtered from the list.
</span>
</p>
<p class="noscript">
This site works fine without JavaScript.