sirius-press/plugins/sirius-press-sia-export/includes/class-spe-cli.php

145 lines
3.8 KiB
PHP
Raw Normal View History

feat(sirius-press): a WordPress where the account is a key, not a mailbox WordPress makes two assumptions this project cannot accept: that identity comes from an email address, and that a site lives at one server. Both are things somebody else can take away — a mailbox is rented from a provider who can close it or be compelled to open it, and a server is one seizure from being gone. Sirius Press replaces the first and hedges the second. Signing in means signing a challenge with the key that controls a CashAddress. The address is recovered from the signature, so nothing is typed but the signature itself, and the result is an ordinary WordPress session cookie — roles, capabilities, nonces and the REST API never learn the login was different. Three ways to produce one: a wallet the browser already exposes, a phrase used once in the page and wiped, or a signature pasted in from any BIP-137 wallet, which needs no JavaScript and lets the key stay on a machine that never touches the web. There is no password reset, and the recovery page says so plainly rather than offering a form that cannot work. A reset mechanism is by construction a way to take an account from its owner, and it is always easier to attack than the cryptography it bypasses. Publishing a post also exports it as static HTML to the name's storage on Sia, signed by the key that owns the name, so the site keeps answering when the server does not. Email as a feature is untouched. wp_mail() still works, SMTP still sends, and contact forms still deliver to addresses real people typed. Only mail to the site's own unroutable placeholder addresses is diverted to an in-app inbox. The objection was to email as identity, not to email. Core is pinned and patched rather than vendored. WordPress 7.1.1 is 149 MB and 5,008 files; the fork's entire core diff is 75 lines in wp-admin/install.php. Carrying the former to express the latter would bury the patch where nobody reviews it and make every clone of the monorepo pay for it. Upstream releases still merge through tools/update-wordpress.sh, which reapplies the series and says exactly which hunk needs a human. The cryptography is implemented twice — PHP on the server, JavaScript in the page — because the server must verify and the browser must sign. Both are pinned against libauth, the library the Sirius portal wallet and the BNS gateway already use, so a disagreement of one byte fails the test suite rather than presenting as a rejected login at three in the morning. 132 checks, no framework, about a second.
2026-09-21 01:39:38 +02:00
<?php
/**
* WP-CLI commands for publishing.
*
* The one place the fork is genuinely better driven from a terminal is the
* first full export of an existing site: thousands of pages, a long run, and
* a browser tab that must not be closed. `wp sirius export --all` does it
* with no tab involved.
*
* @package SiriusPress
*/
defined( 'ABSPATH' ) || exit;
if ( ! defined( 'WP_CLI' ) || ! WP_CLI ) {
return;
}
/**
* Publish this site to its BCNR name.
*/
final class SPE_CLI {
/**
* Queue pages and push them to the name's storage.
*
* ## OPTIONS
*
* [--all]
* : Queue every published page, archive and attachment page first.
*
* [--limit=<n>]
* : Stop after this many uploads. Default: everything queued.
*
* [--dry-run]
* : Build each file and report what would be uploaded, without uploading.
*
* ## EXAMPLES
*
* wp sirius export --all
* wp sirius export --limit=50
* wp sirius export --all --dry-run
*
* @when after_wp_load
*/
public function export( $args, $assoc ) {
if ( ! SP_Settings::is_configured() ) {
WP_CLI::error( 'No BCNR name is configured. Set one in Sirius Press settings first.' );
}
if ( ! empty( $assoc['all'] ) ) {
$queued = SPE_Runner::queue_full_site();
WP_CLI::log( sprintf( 'Queued %d paths.', $queued ) );
}
$dry = ! empty( $assoc['dry-run'] );
$limit = isset( $assoc['limit'] ) ? (int) $assoc['limit'] : 0;
if ( ! $dry && SP_Settings::MODE_SERVER !== SP_Settings::mode() ) {
WP_CLI::error(
'This site is set to manual signing, so no key is available here. '
. 'Switch to automatic publishing in settings, or sign from the Publishing screen in wp-admin.'
);
}
$done = 0;
$fail = 0;
$skip = 0;
while ( true ) {
$rows = SPE_Queue::claim( 10 );
if ( ! $rows ) {
break;
}
foreach ( $rows as $row ) {
if ( $limit > 0 && $done + $fail + $skip >= $limit ) {
break 2;
}
if ( $dry ) {
$body = SPE_Runner::build( $row );
if ( is_wp_error( $body ) ) {
WP_CLI::warning( sprintf( '%s — %s', $row->path, $body->get_error_message() ) );
$fail++;
continue;
}
WP_CLI::log( sprintf( '%s (%s)', $row->path, size_format( strlen( $body ) ) ) );
$skip++;
// A dry run must not consume the queue, so the row is left
// pending — which also means this loop would spin forever
// on the same rows. Stop after one pass instead.
continue;
}
$outcome = SPE_Runner::process( $row );
if ( 'done' === $outcome ) {
$done++;
WP_CLI::log( sprintf( '✓ %s', $row->path ) );
} elseif ( 'skipped' === $outcome ) {
$skip++;
} else {
$fail++;
WP_CLI::warning( sprintf( '✗ %s', $row->path ) );
}
}
if ( $dry ) {
break;
}
}
WP_CLI::success( sprintf( '%d uploaded, %d unchanged, %d failed.', $done, $skip, $fail ) );
}
/**
* Show the publishing status of this site.
*
* @when after_wp_load
*/
public function status() {
$counts = SPE_Queue::counts();
$owner = SP_Gateway::owner_of_name();
$mine = SP_Settings::publishing_address();
WP_CLI::log( 'Name: ' . ( SP_Settings::name() ?: '(not set)' ) );
WP_CLI::log( 'Network: ' . SP_Settings::network() );
WP_CLI::log( 'Gateway: ' . SP_Settings::gateway() );
WP_CLI::log( 'Mode: ' . SP_Settings::mode() );
WP_CLI::log( 'Signs as: ' . ( $mine ?: '(no key stored)' ) );
WP_CLI::log( 'Owner: ' . ( $owner ?: '(gateway did not answer)' ) );
if ( $owner && $mine && ! hash_equals( $owner, $mine ) ) {
WP_CLI::warning( 'The stored key does not own this name. Uploads will be refused.' );
}
WP_CLI::log(
sprintf(
'Queue: %d pending, %d done, %d failed',
$counts[ SPE_Queue::STATUS_PENDING ],
$counts[ SPE_Queue::STATUS_DONE ],
$counts[ SPE_Queue::STATUS_FAILED ]
)
);
}
}
WP_CLI::add_command( 'sirius', 'SPE_CLI' );