mirror of
https://github.com/YGGverse/bdoku.git
synced 2025-01-24 13:54:17 +00:00
initial commit
This commit is contained in:
parent
8c304ece78
commit
fab623885c
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
/vendor/
|
||||
|
||||
composer.lock
|
17
composer.json
Normal file
17
composer.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "yggverse/dokuwiki-gemini-server",
|
||||
"description": "DokuWiki bridge for Gemini Protocol",
|
||||
"keywords": [ "yggverse", "gemini", "gemini-protocol", "gemini-server", "wiki", "dokuwiki", "bridge", "server" ],
|
||||
"homepage": "https://github.com/yggverse/dokuwiki-to-gemini",
|
||||
"type": "project",
|
||||
"require": {
|
||||
"yggverse/gemini": "^0.1",
|
||||
"yggverse/titan-ii": "^1.0"
|
||||
},
|
||||
"license": "MIT",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Yggverse\\DokuwikiGeminiServer\\": "src/"
|
||||
}
|
||||
}
|
||||
}
|
21
example/config.json
Normal file
21
example/config.json
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"gemini":
|
||||
{
|
||||
"server":
|
||||
{
|
||||
"host":"127.0.0.1",
|
||||
"port":1965
|
||||
}
|
||||
},
|
||||
"dokuwiki":
|
||||
{
|
||||
"uri":
|
||||
{
|
||||
"home":"start"
|
||||
},
|
||||
"url":
|
||||
{
|
||||
"canonical":"http://.."
|
||||
}
|
||||
}
|
||||
}
|
1
host/.gitignore
vendored
Normal file
1
host/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/*/
|
164
src/server.php
Normal file
164
src/server.php
Normal file
@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
// Load dependencies
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
// Check arguments
|
||||
if (empty($argv[1]))
|
||||
{
|
||||
exit(_('Configured hostname required as argument!') . PHP_EOL);
|
||||
}
|
||||
|
||||
// Check cert exists
|
||||
if (!file_exists(__DIR__ . '/../host/' . $argv[1] . '/cert.pem'))
|
||||
{
|
||||
exit(
|
||||
sprintf(
|
||||
_('Certificate for host "%s" not found!') . PHP_EOL,
|
||||
$argv[1]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Check key exists
|
||||
if (!file_exists(__DIR__ . '/../host/' . $argv[1] . '/key.rsa'))
|
||||
{
|
||||
exit(
|
||||
sprintf(
|
||||
_('Key for host "%s" not found!') . PHP_EOL,
|
||||
$argv[1]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Check host configured
|
||||
if (!file_exists(__DIR__ . '/../host/' . $argv[1] . '/config.json'))
|
||||
{
|
||||
exit(
|
||||
sprintf(
|
||||
_('Host "%s" not configured!') . PHP_EOL,
|
||||
$argv[1]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Check data directory exist
|
||||
if (!is_dir(__DIR__ . '/../host/' . $argv[1] . '/data'))
|
||||
{
|
||||
exit(
|
||||
sprintf(
|
||||
_('Data directory "%s" not found!') . PHP_EOL,
|
||||
$argv[1]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Init config
|
||||
$config = json_decode(
|
||||
file_get_contents(
|
||||
__DIR__ . '/../host/' . $argv[1] . '/config.json'
|
||||
)
|
||||
);
|
||||
|
||||
// Init filesystem
|
||||
$filesystem = new \Yggverse\Gemini\Dokuwiki\Filesystem(
|
||||
sprintf(
|
||||
__DIR__ . '/../host/' . $argv[1] . '/data'
|
||||
)
|
||||
);
|
||||
|
||||
// Init server
|
||||
$server = new \Yggverse\TitanII\Server();
|
||||
|
||||
$server->setCert(
|
||||
__DIR__ . '/../host/' . $argv[1] . '/cert.pem'
|
||||
);
|
||||
|
||||
$server->setKey(
|
||||
__DIR__ . '/../host/' . $argv[1] . '/key.rsa'
|
||||
);
|
||||
|
||||
$server->setHandler(
|
||||
function (\Yggverse\TitanII\Request $request): \Yggverse\TitanII\Response
|
||||
{
|
||||
global $config;
|
||||
global $filesystem;
|
||||
|
||||
$response = new \Yggverse\TitanII\Response();
|
||||
|
||||
$response->setCode(
|
||||
20
|
||||
);
|
||||
|
||||
$response->setMeta(
|
||||
'text/gemini'
|
||||
);
|
||||
|
||||
// Route begin
|
||||
switch ($request->getPath())
|
||||
{
|
||||
// Home request
|
||||
case null:
|
||||
case '/':
|
||||
|
||||
if ($path = $filesystem->getPagePathByUri($config->dokuwiki->uri->home))
|
||||
{
|
||||
$reader = new \Yggverse\Gemini\Dokuwiki\Reader();
|
||||
|
||||
$response->setContent(
|
||||
$reader->toGemini(
|
||||
file_get_contents(
|
||||
$path
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
// Internal page request
|
||||
default:
|
||||
|
||||
if (preg_match('/^\/([^\/]*)$/', $request->getPath(), $matches))
|
||||
{
|
||||
if (!empty($matches[1]))
|
||||
{
|
||||
if ($path = $filesystem->getPagePathByUri($matches[1]))
|
||||
{
|
||||
$reader = new \Yggverse\Gemini\Dokuwiki\Reader();
|
||||
|
||||
$response->setContent(
|
||||
$reader->toGemini(
|
||||
file_get_contents(
|
||||
$path
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Route not found
|
||||
$response->setCode(
|
||||
51
|
||||
);
|
||||
|
||||
return $response;
|
||||
}
|
||||
);
|
||||
|
||||
// Start server
|
||||
echo sprintf(
|
||||
_('Server "%s" started on %s:%d') . PHP_EOL,
|
||||
$argv[1],
|
||||
$config->gemini->server->host,
|
||||
$config->gemini->server->port
|
||||
);
|
||||
|
||||
$server->start(
|
||||
$config->gemini->server->host,
|
||||
$config->gemini->server->port
|
||||
);
|
Loading…
x
Reference in New Issue
Block a user