2020-06-26 09:00:22 -06:00
|
|
|
<?php
|
|
|
|
|
|
|
|
include_once __DIR__ . '/vendor/autoload.php';
|
|
|
|
use Pagerange\Markdown\MetaParsedown;
|
2020-06-28 15:27:37 -06:00
|
|
|
include_once 'server/functions.php';
|
2020-06-26 09:00:22 -06:00
|
|
|
|
|
|
|
// Init router
|
|
|
|
$router = new AltoRouter();
|
|
|
|
|
|
|
|
// Router mapping
|
|
|
|
$router->map('GET', '/', function() {}, 'index');
|
2020-06-28 16:12:44 -06:00
|
|
|
$router->map('GET', '/guides', function() {}, 'guides');
|
|
|
|
$router->map('GET', '/guides/[:id]', function() {}, 'guideId');
|
|
|
|
$router->map('GET', '/faq', function() {}, 'faq');
|
2020-06-26 09:00:22 -06:00
|
|
|
$router->map('GET', '/verify', function() {}, 'verify');
|
|
|
|
$router->map('GET', '/encrypt', function() {}, 'encrypt');
|
|
|
|
$router->map('GET', '/proofs', function() {}, 'proofs');
|
2020-06-28 15:58:31 -06:00
|
|
|
$router->map('GET', '/verify/hkp/[**:uid]', function() {}, 'verifyHKP');
|
|
|
|
$router->map('GET', '/encrypt/hkp/[**:uid]', function() {}, 'encryptHKP');
|
|
|
|
$router->map('GET', '/proofs/hkp/[**:uid]', function() {}, 'proofsHKP');
|
2020-06-28 15:57:55 -06:00
|
|
|
$router->map('GET', '/verify/wkd/[**:uid]', function() {}, 'verifyWKD');
|
|
|
|
$router->map('GET', '/encrypt/wkd/[**:uid]', function() {}, 'encryptWKD');
|
|
|
|
$router->map('GET', '/proofs/wkd/[**:uid]', function() {}, 'proofsWKD');
|
2020-06-28 16:12:44 -06:00
|
|
|
$router->map('GET', '/verify/[:uid]', function() {}, 'verifyUid');
|
|
|
|
$router->map('GET', '/encrypt/[:uid]', function() {}, 'encryptUid');
|
|
|
|
$router->map('GET', '/proofs/[:uid]', function() {}, 'proofsUid');
|
2020-06-28 16:14:21 -06:00
|
|
|
$router->map('GET', '/hkp/[**:uid]', function() {}, 'profileHKP');
|
2020-06-28 16:09:31 -06:00
|
|
|
$router->map('GET', '/wkd/[**:uid]', function() {}, 'profileWKD');
|
2020-06-28 16:12:44 -06:00
|
|
|
$router->map('GET', '/[**:uid]', function() {}, 'profile');
|
2020-06-26 09:00:22 -06:00
|
|
|
|
|
|
|
// Router matching
|
|
|
|
$match = $router->match();
|
|
|
|
|
|
|
|
// Render the appropriate route
|
|
|
|
if(is_array($match) && is_callable($match['target'])) {
|
|
|
|
switch ($match['name']) {
|
|
|
|
case 'index':
|
|
|
|
readfile('pages/index.html');
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'verify':
|
2020-06-27 06:51:31 -06:00
|
|
|
case 'verifyUid':
|
2020-06-28 15:27:37 -06:00
|
|
|
case 'verifyHKP':
|
|
|
|
$content = file_get_contents('pages/verify.html');
|
|
|
|
$content = str_replace('%HKP_UID%', (array_key_exists('uid', $match['params']) ? $match['params']['uid'] : ''), $content);
|
|
|
|
$content = str_replace('%WKD_UID%', '', $content);
|
|
|
|
header('Content-Type: text/html; charset=utf-8');
|
|
|
|
echo($content);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'verifyWKD':
|
2020-06-27 06:51:31 -06:00
|
|
|
$content = file_get_contents('pages/verify.html');
|
2020-06-28 15:27:37 -06:00
|
|
|
$content = str_replace('%HKP_UID%', '', $content);
|
|
|
|
$content = str_replace('%WKD_UID%', (array_key_exists('uid', $match['params']) ? $match['params']['uid'] : ''), $content);
|
2020-06-27 06:51:31 -06:00
|
|
|
header('Content-Type: text/html; charset=utf-8');
|
|
|
|
echo($content);
|
2020-06-26 09:00:22 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'encrypt':
|
2020-06-27 06:51:31 -06:00
|
|
|
case 'encryptUid':
|
2020-06-28 15:27:37 -06:00
|
|
|
case 'encryptHKP':
|
|
|
|
$content = file_get_contents('pages/encrypt.html');
|
|
|
|
$content = str_replace('%HKP_UID%', (array_key_exists('uid', $match['params']) ? $match['params']['uid'] : ''), $content);
|
|
|
|
$content = str_replace('%WKD_UID%', '', $content);
|
|
|
|
header('Content-Type: text/html; charset=utf-8');
|
|
|
|
echo($content);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'encryptWKD':
|
2020-06-27 06:51:31 -06:00
|
|
|
$content = file_get_contents('pages/encrypt.html');
|
2020-06-28 15:27:37 -06:00
|
|
|
$content = str_replace('%HKP_UID%', '', $content);
|
|
|
|
$content = str_replace('%WKD_UID%', (array_key_exists('uid', $match['params']) ? $match['params']['uid'] : ''), $content);
|
2020-06-27 06:51:31 -06:00
|
|
|
header('Content-Type: text/html; charset=utf-8');
|
|
|
|
echo($content);
|
2020-06-26 09:00:22 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'proofs':
|
2020-06-27 06:51:31 -06:00
|
|
|
case 'proofsUid':
|
2020-06-28 15:27:37 -06:00
|
|
|
case 'proofsHKP':
|
|
|
|
$content = file_get_contents('pages/proofs.html');
|
|
|
|
$content = str_replace('%HKP_UID%', (array_key_exists('uid', $match['params']) ? $match['params']['uid'] : ''), $content);
|
|
|
|
$content = str_replace('%WKD_UID%', '', $content);
|
|
|
|
header('Content-Type: text/html; charset=utf-8');
|
|
|
|
echo($content);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'proofsWKD':
|
2020-06-27 06:51:31 -06:00
|
|
|
$content = file_get_contents('pages/proofs.html');
|
2020-06-28 15:27:37 -06:00
|
|
|
$content = str_replace('%HKP_UID%', '', $content);
|
|
|
|
$content = str_replace('%WKD_UID%', (array_key_exists('uid', $match['params']) ? $match['params']['uid'] : ''), $content);
|
2020-06-27 06:51:31 -06:00
|
|
|
header('Content-Type: text/html; charset=utf-8');
|
|
|
|
echo($content);
|
2020-06-26 09:00:22 -06:00
|
|
|
break;
|
2020-06-26 09:33:39 -06:00
|
|
|
|
|
|
|
case 'profile':
|
2020-06-26 10:01:39 -06:00
|
|
|
$content = file_get_contents('pages/profile.html');
|
2020-06-26 10:04:31 -06:00
|
|
|
$content = str_replace('%UID%', $match['params']['uid'], $content);
|
2020-06-28 16:09:31 -06:00
|
|
|
$content = str_replace('%MODE%', "auto", $content);
|
|
|
|
header('Content-Type: text/html; charset=utf-8');
|
|
|
|
echo($content);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'profileHKP':
|
|
|
|
$content = file_get_contents('pages/profile.html');
|
|
|
|
$content = str_replace('%UID%', $match['params']['uid'], $content);
|
|
|
|
$content = str_replace('%MODE%', "hkp", $content);
|
|
|
|
header('Content-Type: text/html; charset=utf-8');
|
|
|
|
echo($content);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'profileWKD':
|
|
|
|
$content = file_get_contents('pages/profile.html');
|
|
|
|
$content = str_replace('%UID%', $match['params']['uid'], $content);
|
|
|
|
$content = str_replace('%MODE%', "wkd", $content);
|
2020-06-26 10:01:39 -06:00
|
|
|
header('Content-Type: text/html; charset=utf-8');
|
2020-06-26 10:04:31 -06:00
|
|
|
echo($content);
|
2020-06-26 09:33:39 -06:00
|
|
|
break;
|
2020-06-27 06:51:31 -06:00
|
|
|
|
2020-06-28 12:14:31 -06:00
|
|
|
case 'guides':
|
|
|
|
readfile('pages/guides.html');
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'guideId':
|
|
|
|
$id = $match['params']['id'];
|
|
|
|
$content = file_get_contents("pages/template.html");
|
|
|
|
$guideTitle = file_get_contents("pages/guides/$id.title.html");
|
|
|
|
$guideContent = file_get_contents("pages/guides/$id.content.html");
|
|
|
|
$guideContent = "<p><a href='/guides'>Back to guides</a></p>".$guideContent;
|
|
|
|
$content = str_replace('%TITLE%', $guideTitle, $content);
|
|
|
|
$content = str_replace('%CONTENT%', $guideContent, $content);
|
|
|
|
header('Content-Type: text/html; charset=utf-8');
|
|
|
|
echo($content);
|
|
|
|
break;
|
|
|
|
|
2020-06-27 06:51:31 -06:00
|
|
|
case 'faq':
|
|
|
|
readfile('pages/faq.html');
|
|
|
|
break;
|
2020-06-26 09:00:22 -06:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// No route was matched
|
2020-06-29 03:27:45 -06:00
|
|
|
$content = file_get_contents("pages/template.html");
|
|
|
|
$pageTitle = "404";
|
|
|
|
$pageContent = "404 - This page could not be found :(";
|
|
|
|
$content = str_replace('%TITLE%', $pageTitle, $content);
|
|
|
|
$content = str_replace('%CONTENT%', $pageContent, $content);
|
|
|
|
header('Content-Type: text/html; charset=utf-8');
|
|
|
|
echo($content);
|
2020-06-26 09:00:22 -06:00
|
|
|
}
|