Christopher Vagnetoft
b3476881e1
* The PHAR now gets tagged with version and buildtime * WebSocket support can now be disabled
83 lines
2.3 KiB
PHP
Executable File
83 lines
2.3 KiB
PHP
Executable File
#!/usr/bin/env php
|
|
<?php
|
|
|
|
use NoccyLabs\Mercureact\Configuration;
|
|
use NoccyLabs\Mercureact\Daemon;
|
|
|
|
file_exists(__DIR__."/../vendor") && require_once __DIR__."/../vendor/autoload.php";
|
|
file_exists(__DIR__."/../../../autoload.php") && require_once __DIR__."/../../../autoload.php";
|
|
|
|
if (file_exists(__DIR__."/../src/meta")) {
|
|
$meta = require_once(__DIR__."/../src/meta");
|
|
define("MERCUREACT_VERSION", $meta['version']??'0.0.0');
|
|
define("MERCUREACT_BUILDTIME", $meta['buildtime']);
|
|
} else {
|
|
define("MERCUREACT_VERSION", "DEV");
|
|
define("MERCUREACT_BUILDTIME", null);
|
|
}
|
|
|
|
$opts = getopt("c:C:h");
|
|
|
|
if (isset($opts['h'])) {
|
|
$info = "v".MERCUREACT_VERSION.(MERCUREACT_BUILDTIME?("\nBuilt on ".MERCUREACT_BUILDTIME):"");
|
|
fwrite(STDERR, <<<HELP
|
|
Mercureact Realtime SSE Daemon {$info}
|
|
(c) 2024, NoccyLabs - Distributed under GNU GPL v3 or later.
|
|
|
|
Options:
|
|
|
|
-c config Read configuration from file
|
|
-C config Write a new configuration to file and open with editor
|
|
|
|
|
|
HELP);
|
|
exit(0);
|
|
}
|
|
|
|
if (isset($opts['C'])) {
|
|
$file = $opts['C'];
|
|
if (file_exists($file)) {
|
|
fwrite(STDERR, "File {$file} already exists. Will not overwrite.\n");
|
|
exit(1);
|
|
}
|
|
file_put_contents($file, <<<DEFAULTS
|
|
server:
|
|
address: 0.0.0.0:9000
|
|
public_url: https://example.com
|
|
websockets: false
|
|
cors:
|
|
allow_origin: '*'
|
|
csp: "default-src * 'self' http: 'unsafe-eval' 'unsafe-inline'; connect-src * 'self'"
|
|
encryption:
|
|
cert: foo.pem
|
|
key: foo.key
|
|
|
|
publish:
|
|
overwrite_id: false
|
|
reject_duplicates: true
|
|
|
|
subscribe:
|
|
allow_anonymous: true
|
|
|
|
security:
|
|
jwt_secret: "!ChangeThisMercureHubJWTSecretKey!"
|
|
|
|
DEFAULTS);
|
|
passthru("editor ".escapeshellarg($file));
|
|
exit(1);
|
|
}
|
|
|
|
if (isset($opts['c'])) {
|
|
$config = Configuration::fromFile($opts['c']);
|
|
} else {
|
|
$config = Configuration::createDefault()
|
|
->setListenAddress('127.0.0.1:8888')
|
|
->setAllowOriginHeader("*")
|
|
->setContentSecurityPolicyHeader("default-src * 'self' http: 'unsafe-eval' 'unsafe-inline'; connect-src * 'self'")
|
|
->setAllowAnonymousSubscribe(true)
|
|
->setJwtSecret("!ChangeThisMercureHubJWTSecretKey!");
|
|
}
|
|
|
|
$daemon = new Daemon($config);
|
|
$daemon->start();
|