Skip to content

Sync v2: member list from the membership system (reader side) - #84

Merged
PeterTheOne merged 9 commits into
masterfrom
feature/sync-v2-consumer
Nov 1, 2026
Merged

PeterTheOne merged 9 commits into
masterfrom
feature/sync-v2-consumer

Conversation

@PeterTheOne

@PeterTheOne PeterTheOne commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Membership sync v2, reader side in pgacc: the member list comes as JSON from the membership system's internal members.php (PPOE/admidio-addons#1). This replaces the old encrypted adm_names.php fetch.

  • getusers.php fetches members_url with PHP streams: verify_peer/verify_peer_name on, cafile = members_cafile (the peer certificate), Bearer token, no redirects, 20 s timeout, HTTP 200 required. It uses fopen + stream_get_contents(4 MiB + 1) and refuses a body over 4 MiB or a read that timed out, the same shape as accsync_fetch on the membership side.
  • The whole list is validated: exactly the five fields, positive int ids, UUIDs, no duplicate id or uuid, lo int or null, paid 0/1. A malformed or duplicated list is refused (fail closed, as before). The LO mapping is unchanged (44, unknown or null → 10).
  • ppmembers stores the uuid. mb.php links Admidio profiles by user_uuid (only a valid UUID goes into the link); the ledger (closed.php) and the voucher form (new.php) show the member id as plain text.
  • Keys in sync-secrets.php: members_url, members_token, members_cafile. An unparsable or throwing file fails closed with "Mitgliederliste nicht konfiguriert!" (include in try/catch, only the exception class is logged) instead of a PHP fatal.
  • sync-secrets.php comes from the inventory. One Ansible template task (templates/sync-secrets.php.j2, root:pgacc 0640, no_log) writes it on every run. There is no creates: and no lineinfile. The template renders the members_* keys while pgacc_members_url is set and the payments_* keys (Sync v2: internal payment endpoint (provider side) #83) while the internal listener is on. The task and the template are identical in Sync v2: internal payment endpoint (provider side) #83, and so is tests/runtime/test-sync-secrets.php. Variables: pgacc_members_url, pgacc_members_token (64 hex, asserted) and pgacc_members_cert, empty by default. The certificate now goes to /etc/pgacc/admidio-addons-tls.crt, following the /etc/<app>/<peer>-tls.crt convention of PPOE/admidio-addons. The member-list asserts and certificate tasks are separate tasks, so the playbook merges with Sync v2: internal payment endpoint (provider side) #83 without conflicts.
  • Removes the adm_names.php fetch and membership_decrypt().
  • Docs: one "Sync v2 (membership sync)" entry in CHANGELOG (Unreleased) and in UPGRADING. deploy/README.md gets a "Sync v2 settings" section covering the secrets file, tokens, the cert path convention and the time zone, and recommends pgacc_timezone: Europe/Vienna. These shared sections are worded the same as in Sync v2: internal payment endpoint (provider side) #83.
  • Based on master, independent of Sync v2: internal payment endpoint (provider side) #83. A trial merge of both conflicts only in docs (CHANGELOG, UPGRADING, README, deploy/README: keep both sides) and in the files where both remove mcrypt code. The playbook, inventory, deploy.sh, template and test config merge cleanly.

Follow-up after both #83 and #84 are merged: delete the helpers that are orphaned only then (membership_cipher_params(), the membership stub helpers, the mcrypt vectors and their tests, the related receipt-crypto mutation targets, $datakey in the reference runtime). rijndael256_* stays (receipt v1).

Tests: new GetUsersTest cases (bad, wrong-name or untrusted certificate, 500/403/redirect, 19 malformed lists, UUID validation, link rendering). Red first in this round: a body of 4 MiB + 1 is refused while exactly 4 MiB is read; a stalled body (new stub mode stall) is refused on timeout; an unparsable or throwing sync-secrets.php fails closed. http-import checks the links on all three pages. The PHP 5 reference was re-recorded in the first round (links, uuid in the SQL, stub path); no re-record was needed this round. Mutation on the new fetch/config lines: 5/5 killed, plus 12/12 on the earlier getusers changes. Astra review of this round: not run, codex usage limit until 05:37.

🤖 Generated with Claude Code

…c v2)

The member list now comes from the membership system's members.php
(PPOE/admidio-addons) instead of the encrypted adm_names.php of the old,
shut-down membership system. Settings in the new configuration file
sync-secrets.php (release root, like constants.php): members_url (https
only), members_token (Authorization: Bearer) and members_cafile, the
only trust anchor (verify_peer and verify_peer_name on, no redirects,
20 s timeout, HTTP 200 required). The whole document is validated (a
non-empty list of rows with exactly id, uuid, name, lo, paid; positive
ids, UUIDs, no id or uuid twice); anything else fails closed as before.
ppmembers stores the uuid. mb.php links profiles by user_uuid (validated
as a UUID before it goes into the href); closed.php and new.php show the
member id as text. membership_decrypt() is removed.

deploy/: pgacc_members_url, pgacc_members_token, pgacc_members_cert
(empty by default) fill shared/sync-secrets.php (root:pgacc 0640) and
/etc/pgacc/members-tls.crt; pgacc-deploy links sync-secrets.php and
refuses archives that contain one.

Tests: the membership stub serves JSON and requires the token; new
GetUsersTest cases for the refused fetches (certificate, name, cafile
only, 500, redirect, 403), every kind of malformed list, the settings,
the UUID check and the links; http-import checks the links on the
member-fee page, the ledger and the voucher form (red against the old
pages). The reference is re-recorded for the links and the stub path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PeterTheOne and others added 2 commits November 1, 2026 03:31
mb.php was not in the phpunit coverage source, so the non-UUID branch of
mb_member_link(), exercised by GetUsersTest, did not count and the
changed-line coverage gate reported mb.php line 10 as uncovered. No
behaviour change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Align the consumer side with the sync v2 cross-review:

- One template task writes shared/sync-secrets.php from the inventory on
  every run (templates/sync-secrets.php.j2, root:pgacc 0640, no_log),
  replacing the "create if missing" shell task and the lineinfile loop.
  The template and the task are the same in the provider branch: the
  members_* keys while pgacc_members_url is set, the payments_* keys of
  the internal sync listener while it is on.
- getusers_fetch(): fopen + stream_get_contents(4 MiB + 1), refused when
  larger or when the read timed out (same shape as accsync_fetch on the
  membership side). The stub gets a "stall" mode for the timeout test.
- A sync-secrets.php that does not load (parse error, exception) fails
  closed with "Mitgliederliste nicht konfiguriert!" instead of a fatal
  error; only the class is logged.
- The membership system's certificate is /etc/pgacc/admidio-addons-tls.crt
  (/etc/<app>/<peer>-tls.crt, as on the membership side).
- The member list asserts move to their own task; the certificate tasks
  to their own section, so the two branches merge without conflicts in
  the playbook.
- Docs: one "Sync v2" CHANGELOG entry and UPGRADING section, the
  certificate path convention, pgacc_timezone Europe/Vienna recommended.
- tests/runtime/test-sync-secrets.php holds the payments_* and members_*
  test keys (same file in the provider branch).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PeterTheOne and others added 6 commits November 1, 2026 12:49
The membership system's listener must serve members.php before
pgacc_members_url is set; UPGRADING.md and deploy/README.md give a curl
check that must print 200.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…aders

tests/sync-secrets-template.sh renders the real template with the
template module (ansible-core of tests/playbook-settings.sh) for payments
only, members only and both, and loads each file with sync_api_config()
and getusers_config() where present. A broken template made every sync
request 403, which the deploy smoke test accepts. Wired into the
web-server CI job.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PHP's stream timeout applies to each read, so a membership system that
trickles the response could hold the request far longer. The fetch now
reads the response itself under one deadline and fails closed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both branches remove the old encrypted membership exchange: #83 the
export (public/mbapi.php, membership_encrypt()), this branch the import
(adm_names.php, membership_decrypt()). The conflicts keep neither helper,
their mcrypt vectors and tests; the docs describe both directions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With both directions on sync v2 nothing reads $datakey: drop
membership_cipher_params() and its mutants, $datakey of the test and
reference constants, and the $datakey placeholder that the playbook wrote
into a new constants.php. tests/sync-secrets-template.sh now requires both
readers (sync_api_config() and getusers_config()). Docs say what is true
with both PRs in: both directions on internal addresses, no public name or
CA bundle, allow_url_fopen not needed by getusers.php.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
As accsync.php of the add-ons: every Content-Length header, if there is
one, must be 1-18 digits and equal the body length; otherwise the fetch
fails closed on the same error path. Tests (red first): a 200 body cut
short by an early close (no timeout), a longer body and a malformed value
(stub modes short, long, badlength).

Also for the mutation and changed-line gates of the new HTTP client: the
four getusers mutants that still searched the old stream-wrapper code
match the socket client; new mutants for the deadline, the URL checks and
the Content-Length check; tests for a URL with user info, without a host,
with http, and the stall test refuses at the deadline. The deadline is a
clamped per-read timeout (no separate branch), the redundant password
check is gone (a password always comes with a user), and the timed_out
mutant is documented as equivalent (fread() returns false on a TLS read
timeout).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@PeterTheOne
PeterTheOne merged commit ded7c7e into master Nov 1, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant