Browse Source

fix multi server launch

main
ghost 9 months ago
parent
commit
6e1211fc22
  1. 4
      README.md
  2. 58
      src/server.php

4
README.md

@ -38,8 +38,8 @@ KevaChat is distributed chat platform for open, uncensored and privacy respectab @@ -38,8 +38,8 @@ KevaChat is distributed chat platform for open, uncensored and privacy respectab
## Start
* `php src/server.php`
* `php src/server.php 127.0.0.1`
## See also
* [web implementation](https://github.com/kevachat/webapp)
* [KevaChat Web Application](https://github.com/kevachat/webapp)

58
src/server.php

@ -3,52 +3,49 @@ @@ -3,52 +3,49 @@
// Load dependencies
require_once __DIR__ . '/../vendor/autoload.php';
// Scan host
foreach ((array) scandir(__DIR__ . '/../host') as $host)
// Check arguments
if (empty($argv[1]))
{
// Skip meta
if ($host == '.' || $host == '..' || is_file($host))
{
continue;
}
// Check host configured
if (!file_exists(__DIR__ . '/../host/' . $host . '/config.json'))
{
echo sprintf(
_('Host "%s" not configured!') . PHP_EOL,
$host
);
continue;
exit(_('Configured hostname required as argument!') . PHP_EOL);
}
// Check cert exists
if (!file_exists(__DIR__ . '/../host/' . $host . '/cert.pem'))
if (!file_exists(__DIR__ . '/../host/' . $argv[1] . '/cert.pem'))
{
echo sprintf(
exit(
sprintf(
_('Certificate for host "%s" not found!') . PHP_EOL,
$host
$argv[1]
)
);
continue;
}
// Check key exists
if (!file_exists(__DIR__ . '/../host/' . $host . '/key.rsa'))
if (!file_exists(__DIR__ . '/../host/' . $argv[1] . '/key.rsa'))
{
echo sprintf(
exit(
sprintf(
_('Key for host "%s" not found!') . PHP_EOL,
$host
$argv[1]
)
);
}
continue;
// Check host configured
if (!file_exists(__DIR__ . '/../host/' . $argv[1] . '/config.json'))
{
exit(
sprintf(
_('Host "%s" not configured!') . PHP_EOL,
$argv[1]
)
);
}
// Init config
$config = json_decode(
file_get_contents(
__DIR__ . '/../host/' . $host . '/config.json'
__DIR__ . '/../host/' . $argv[1] . '/config.json'
)
);
@ -64,11 +61,11 @@ foreach ((array) scandir(__DIR__ . '/../host') as $host) @@ -64,11 +61,11 @@ foreach ((array) scandir(__DIR__ . '/../host') as $host)
$server = new \Yggverse\TitanII\Server();
$server->setCert(
__DIR__ . '/../host/' . $host . '/cert.pem'
__DIR__ . '/../host/' . $argv[1] . '/cert.pem'
);
$server->setKey(
__DIR__ . '/../host/' . $host . '/key.rsa'
__DIR__ . '/../host/' . $argv[1] . '/key.rsa'
);
$server->setHandler(
@ -276,7 +273,7 @@ foreach ((array) scandir(__DIR__ . '/../host') as $host) @@ -276,7 +273,7 @@ foreach ((array) scandir(__DIR__ . '/../host') as $host)
// Start server
echo sprintf(
_('Server "%s" started on %s:%d') . PHP_EOL,
$host,
$argv[1],
$config->gemini->server->host,
$config->gemini->server->port
);
@ -285,4 +282,3 @@ foreach ((array) scandir(__DIR__ . '/../host') as $host) @@ -285,4 +282,3 @@ foreach ((array) scandir(__DIR__ . '/../host') as $host)
$config->gemini->server->host,
$config->gemini->server->port
);
}
Loading…
Cancel
Save