2026-10-19 23:10:08 +02:00
|
|
|
import 'dart:convert';
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
import 'package:crypto/crypto.dart';
|
|
|
|
|
import 'package:serverpod/serverpod.dart';
|
|
|
|
|
|
|
|
|
|
/// How this server takes part in its instance's accounts (ADR 0016).
|
|
|
|
|
sealed class AccountsMode {
|
|
|
|
|
const AccountsMode();
|
|
|
|
|
|
|
|
|
|
/// The mode the operator's environment names: a member of the register at
|
|
|
|
|
/// `ACCOUNT_REGISTER_URL` where it is set, else the register, telling the
|
|
|
|
|
/// members at `INSTANCE_MEMBERS` (addresses separated by commas or spaces)
|
build(todo): Todo deployable beside Learn's server, and released as an APK, on F-Droid and as a snap (ADR 0033, step 5)
deploy/compose.todo.yaml adds Todo's server at todo.halkyon.eu, a member
of Learn's register, its database halkyon_todo in the instance's
PostgreSQL, its image built as Train's. redeploy.sh and backup.sh go over
every app server .env switches on (train, todo). Each compose file names
its server to the register in a variable of its own
(INSTANCE_MEMBER_TRAIN, INSTANCE_MEMBER_TODO), which halkyon_base adds to
INSTANCE_MEMBERS, each address once, as a second compose file's default
would have replaced Train's.
apps/todo/release.dart configures the release tool for Todo's APK and
snap: a key of its own (pinned once made; until then nothing is
released), the F-Droid listing (Time, NonFreeNet), and the snap from
apps/todo/snap/, which the tool builds in a clone of the repository at the
tag with that folder in place of snap/, as snapcraft builds one recipe a
folder and the root's is Learn's. What's new for 0.1.0 in English and
German, now shown. Android's backup and transfer are off, as Train's
(D53): the reminders scheduled keep their tasks' titles unsealed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-11-02 15:35:40 +01:00
|
|
|
/// and at each `INSTANCE_MEMBER_<NAME>` (one address each, in their names'
|
|
|
|
|
/// order: a service's compose file names itself, so that several such files
|
|
|
|
|
/// add up where one variable would be replaced by the last) when an account
|
|
|
|
|
/// goes, each address once. Empty values count as unset: Compose passes
|
|
|
|
|
/// unset variables on as empty strings.
|
2026-10-19 23:10:08 +02:00
|
|
|
factory AccountsMode.fromEnvironment([Map<String, String>? environment]) {
|
|
|
|
|
final env = environment ?? Platform.environment;
|
|
|
|
|
if (_address(env['ACCOUNT_REGISTER_URL'], 'ACCOUNT_REGISTER_URL')
|
|
|
|
|
case final register?) {
|
|
|
|
|
return MemberOfRegister(register);
|
|
|
|
|
}
|
build(todo): Todo deployable beside Learn's server, and released as an APK, on F-Droid and as a snap (ADR 0033, step 5)
deploy/compose.todo.yaml adds Todo's server at todo.halkyon.eu, a member
of Learn's register, its database halkyon_todo in the instance's
PostgreSQL, its image built as Train's. redeploy.sh and backup.sh go over
every app server .env switches on (train, todo). Each compose file names
its server to the register in a variable of its own
(INSTANCE_MEMBER_TRAIN, INSTANCE_MEMBER_TODO), which halkyon_base adds to
INSTANCE_MEMBERS, each address once, as a second compose file's default
would have replaced Train's.
apps/todo/release.dart configures the release tool for Todo's APK and
snap: a key of its own (pinned once made; until then nothing is
released), the F-Droid listing (Time, NonFreeNet), and the snap from
apps/todo/snap/, which the tool builds in a clone of the repository at the
tag with that folder in place of snap/, as snapcraft builds one recipe a
folder and the root's is Learn's. What's new for 0.1.0 in English and
German, now shown. Android's backup and transfer are off, as Train's
(D53): the reminders scheduled keep their tasks' titles unsealed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-11-02 15:35:40 +01:00
|
|
|
final named = [
|
|
|
|
|
for (final variable in env.keys)
|
|
|
|
|
if (variable.startsWith(_memberPrefix) &&
|
|
|
|
|
variable.length > _memberPrefix.length)
|
|
|
|
|
variable,
|
|
|
|
|
]..sort();
|
2026-10-19 23:10:08 +02:00
|
|
|
return HoldsRegister(
|
build(todo): Todo deployable beside Learn's server, and released as an APK, on F-Droid and as a snap (ADR 0033, step 5)
deploy/compose.todo.yaml adds Todo's server at todo.halkyon.eu, a member
of Learn's register, its database halkyon_todo in the instance's
PostgreSQL, its image built as Train's. redeploy.sh and backup.sh go over
every app server .env switches on (train, todo). Each compose file names
its server to the register in a variable of its own
(INSTANCE_MEMBER_TRAIN, INSTANCE_MEMBER_TODO), which halkyon_base adds to
INSTANCE_MEMBERS, each address once, as a second compose file's default
would have replaced Train's.
apps/todo/release.dart configures the release tool for Todo's APK and
snap: a key of its own (pinned once made; until then nothing is
released), the F-Droid listing (Time, NonFreeNet), and the snap from
apps/todo/snap/, which the tool builds in a clone of the repository at the
tag with that folder in place of snap/, as snapcraft builds one recipe a
folder and the root's is Learn's. What's new for 0.1.0 in English and
German, now shown. Android's backup and transfer are off, as Train's
(D53): the reminders scheduled keep their tasks' titles unsealed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-11-02 15:35:40 +01:00
|
|
|
members: {
|
2026-10-19 23:10:08 +02:00
|
|
|
for (final member in (env['INSTANCE_MEMBERS'] ?? '').split(
|
|
|
|
|
RegExp(r'[\s,]+'),
|
|
|
|
|
))
|
|
|
|
|
?_address(member, 'INSTANCE_MEMBERS'),
|
build(todo): Todo deployable beside Learn's server, and released as an APK, on F-Droid and as a snap (ADR 0033, step 5)
deploy/compose.todo.yaml adds Todo's server at todo.halkyon.eu, a member
of Learn's register, its database halkyon_todo in the instance's
PostgreSQL, its image built as Train's. redeploy.sh and backup.sh go over
every app server .env switches on (train, todo). Each compose file names
its server to the register in a variable of its own
(INSTANCE_MEMBER_TRAIN, INSTANCE_MEMBER_TODO), which halkyon_base adds to
INSTANCE_MEMBERS, each address once, as a second compose file's default
would have replaced Train's.
apps/todo/release.dart configures the release tool for Todo's APK and
snap: a key of its own (pinned once made; until then nothing is
released), the F-Droid listing (Time, NonFreeNet), and the snap from
apps/todo/snap/, which the tool builds in a clone of the repository at the
tag with that folder in place of snap/, as snapcraft builds one recipe a
folder and the root's is Learn's. What's new for 0.1.0 in English and
German, now shown. Android's backup and transfer are off, as Train's
(D53): the reminders scheduled keep their tasks' titles unsealed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-11-02 15:35:40 +01:00
|
|
|
for (final variable in named) ?_address(env[variable], variable),
|
|
|
|
|
}.toList(),
|
2026-10-19 23:10:08 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
build(todo): Todo deployable beside Learn's server, and released as an APK, on F-Droid and as a snap (ADR 0033, step 5)
deploy/compose.todo.yaml adds Todo's server at todo.halkyon.eu, a member
of Learn's register, its database halkyon_todo in the instance's
PostgreSQL, its image built as Train's. redeploy.sh and backup.sh go over
every app server .env switches on (train, todo). Each compose file names
its server to the register in a variable of its own
(INSTANCE_MEMBER_TRAIN, INSTANCE_MEMBER_TODO), which halkyon_base adds to
INSTANCE_MEMBERS, each address once, as a second compose file's default
would have replaced Train's.
apps/todo/release.dart configures the release tool for Todo's APK and
snap: a key of its own (pinned once made; until then nothing is
released), the F-Droid listing (Time, NonFreeNet), and the snap from
apps/todo/snap/, which the tool builds in a clone of the repository at the
tag with that folder in place of snap/, as snapcraft builds one recipe a
folder and the root's is Learn's. What's new for 0.1.0 in English and
German, now shown. Android's backup and transfer are off, as Train's
(D53): the reminders scheduled keep their tasks' titles unsealed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-11-02 15:35:40 +01:00
|
|
|
static const _memberPrefix = 'INSTANCE_MEMBER_';
|
|
|
|
|
|
2026-10-19 23:10:08 +02:00
|
|
|
static Uri? _address(String? value, String variable) {
|
|
|
|
|
final trimmed = value?.trim() ?? '';
|
|
|
|
|
if (trimmed.isEmpty) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
final uri = Uri.tryParse(trimmed);
|
|
|
|
|
if (uri == null ||
|
|
|
|
|
!(uri.isScheme('http') || uri.isScheme('https')) ||
|
|
|
|
|
uri.host.isEmpty) {
|
|
|
|
|
throw ArgumentError.value(trimmed, variable, 'is no HTTP(S) address');
|
|
|
|
|
}
|
|
|
|
|
return uri;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// This server holds the instance's register: its database keeps the
|
|
|
|
|
/// accounts, their ways in, handles and profiles. With a single service, it
|
|
|
|
|
/// is its own register and has no [members].
|
|
|
|
|
final class HoldsRegister extends AccountsMode {
|
|
|
|
|
const HoldsRegister({this.members = const []});
|
|
|
|
|
|
|
|
|
|
/// The web servers of the instance's other services, told when an account
|
|
|
|
|
/// goes so they delete that person's data too.
|
|
|
|
|
final List<Uri> members;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// This server is a member: it asks the instance's register at [register]
|
|
|
|
|
/// (its web server) for everything about accounts, and keeps only its own
|
|
|
|
|
/// data of each person, under the register's account ID.
|
|
|
|
|
final class MemberOfRegister extends AccountsMode {
|
|
|
|
|
const MemberOfRegister(this.register);
|
|
|
|
|
|
|
|
|
|
/// The register's web server, as this server reaches it (its address on
|
|
|
|
|
/// the instance's own network when both run on one host).
|
|
|
|
|
final Uri register;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The instance's shared secret (`instanceSecret` in the passwords;
|
|
|
|
|
/// `INSTANCE_SECRET` in a deploy's `.env`), which its services send with
|
|
|
|
|
/// every call between them; null without one, and then no such call is made
|
|
|
|
|
/// or taken.
|
|
|
|
|
String? instanceSecretOf(Serverpod pod) =>
|
|
|
|
|
_secretOf[pod] ??
|
|
|
|
|
switch (pod.getPassword('instanceSecret')) {
|
|
|
|
|
final secret? when secret.isNotEmpty => secret,
|
|
|
|
|
_ => null,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// Puts [secret] in place of [pod]'s passwords' `instanceSecret`, or with
|
|
|
|
|
/// null the passwords' back: tests do, as the passwords of a test run hold
|
|
|
|
|
/// none.
|
|
|
|
|
void useInstanceSecret(Serverpod pod, String? secret) =>
|
|
|
|
|
_secretOf[pod] = secret;
|
|
|
|
|
|
|
|
|
|
final _secretOf = Expando<String>('Instance secret');
|
|
|
|
|
|
|
|
|
|
/// Whether [presented] is [secret], compared in constant time: both hashed,
|
|
|
|
|
/// so neither their length nor where they first differ shows in how long it
|
|
|
|
|
/// takes.
|
|
|
|
|
bool isInstanceSecret(String presented, String secret) {
|
|
|
|
|
final a = sha256.convert(utf8.encode(presented)).bytes;
|
|
|
|
|
final b = sha256.convert(utf8.encode(secret)).bytes;
|
|
|
|
|
var difference = 0;
|
|
|
|
|
for (var i = 0; i < a.length; i++) {
|
|
|
|
|
difference |= a[i] ^ b[i];
|
|
|
|
|
}
|
|
|
|
|
return difference == 0;
|
|
|
|
|
}
|