From 4150dfcf5be81fea484c8f23cdd4aecf08f3afec Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Mon, 11 Mar 2024 23:20:48 +0100 Subject: [PATCH] Config stuff, docs --- README.md | 33 ++++++++++----------------- bin/mercureactd | 52 ++++++++++++++++++++++++++++++++++++++++++- mercureactd.conf.dist | 6 ++--- src/Configuration.php | 3 --- 4 files changed, 66 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 742aa88..b0a6fac 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,9 @@ # Mercureact -This is an implementation of the Mercure realtime protocol on steroids, built using ReactPHP. +This is an implementation of the Mercure realtime protocol, built using ReactPHP. It is intended to be used standalone, but it may also be integrated into another ReactPHP application. **Mercureact is under development, and not ready for use in anything important.** -It is intended to be used standalone, but it may also be integrated into another PHP application. - ## Installing As PHAR: @@ -14,44 +12,37 @@ As PHAR: As Composer dependency: -* `composer require noccylabs/mercureact` +* `composer require noccylabs/mercureact:@dev` ## Using as PHAR -*TODO.* +Running `mercureact.phar` without passing a config file with `-c` will spawn an insecure daemon that can be used for testing. Following tradition, the default JWT secret key is `!ChangeThisMercureHubJWTSecretKey!`; this key must be used to publish, but anonymous subscribers are allowed, and will be delivered any non-private updates. + +You should probably use a configuration file for just about every case. Mercureact contains a compact dist config that can be written to a file with `-C`, or you can use the `mercureact.conf.dist` file from the repository. ```shell -# Make a copy of the dist config and edit it +# If you got a mercureact.conf.dist file, make a copy and edit it $ cp mercureact.conf.dist mercureact.conf $ editor mercureact.conf -# Use the config file when launching + +# Or use the -C (capital C) option to generate and edit one +$ ./mercureact.phar -C mercureact.conf + +# Then use the config file when launching $ ./mercureact.phar -c mercureact.conf ``` ## Using as dependency -*TODO.* +Take a look at `src/Daemon.php` and `src/Http/Server.php` depending on how much of Mercureact you want to reuse. ## ToDos -* [x] Read config from file -* [ ] Security Security Security - * [x] Check JWTs on connect - * [x] Check claims on subscribe and publish - * [x] Extract JWT claims to request attributes, instead of JWTToken -* [x] Subscription/Topic manager - * [x] Unify distribution - * [x] Enumerate subscriptions and topics -* [x] Publish events -* [x] Server-Side Events distributor - * [x] Distribute events over SSE * [ ] WebSocket distributor * [ ] WebSocket authentication * [ ] Setup subscriptions * [ ] Dynamic subscriptions * [x] Distribute events over WS -* [x] Break out HTTP middleware into classes * [ ] HTTP middleware unittests * [ ] Replay missed events based on event id -* [x] Figure out how to determine last event IDs * [ ] Metrics endpoint diff --git a/bin/mercureactd b/bin/mercureactd index fa5bfb9..de75302 100755 --- a/bin/mercureactd +++ b/bin/mercureactd @@ -3,10 +3,60 @@ use NoccyLabs\Mercureact\Configuration; use NoccyLabs\Mercureact\Daemon; +use PHPUnit\TextUI\Help; require_once __DIR__."/../vendor/autoload.php"; -$opts = getopt("c:"); +$opts = getopt("c:C:h"); + +if (isset($opts['h'])) { + fwrite(STDERR, << '*', 'csp' => 'default-src * \'self\'', ], - 'websocket' => isset($config['websocket'])?[ - 'enable' => $config['websocket']['enable']??false - ]:null, ]; return $this; }