2020-07-30 04:05:11 -06:00
|
|
|
<!--
|
|
|
|
Copyright (C) 2020 Yarmo Mackenbach
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU Affero General Public License as published by the Free
|
|
|
|
Software Foundation, either version 3 of the License, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
|
|
details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License along
|
|
|
|
with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
Also add information on how to contact you by electronic and paper mail.
|
|
|
|
|
|
|
|
If your software can interact with users remotely through a computer network,
|
|
|
|
you should also make sure that it provides a way for users to get its source.
|
|
|
|
For example, if your program is a web application, its interface could display
|
|
|
|
a "Source" link that leads users to an archive of the code. There are many
|
|
|
|
ways you could offer source, and different solutions will be better for different
|
|
|
|
programs; see section 13 for the specific requirements.
|
|
|
|
|
|
|
|
You should also get your employer (if you work as a programmer) or school,
|
|
|
|
if any, to sign a "copyright disclaimer" for the program, if necessary. For
|
|
|
|
more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>.
|
|
|
|
-->
|
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();
|
|
|
|
|
2020-07-01 18:36:15 -06:00
|
|
|
// Init templating
|
|
|
|
$templates = new League\Plates\Engine('views');
|
|
|
|
|
2020-06-26 09:00:22 -06:00
|
|
|
// 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');
|
2020-07-22 06:54:56 -06:00
|
|
|
$router->map('GET', '/util/qrfp/[:fp]', function() {}, 'util_qrfp');
|
2020-07-22 07:37:38 -06:00
|
|
|
$router->map('GET', '/util/qr/[**:uri]', function() {}, 'util_qr');
|
2020-07-01 18:36:15 -06:00
|
|
|
$router->map('GET', '/util/[:id]', function() {}, 'util');
|
2020-06-28 16:12:44 -06:00
|
|
|
$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');
|
2020-06-28 15:57:55 -06:00
|
|
|
$router->map('GET', '/verify/wkd/[**:uid]', function() {}, 'verifyWKD');
|
2020-07-05 07:04:12 -06:00
|
|
|
$router->map('GET', '/verify/keybase/[:uid]/[:fp]', function() {}, 'verifyKeybase');
|
2020-07-01 18:36:15 -06:00
|
|
|
$router->map('GET', '/verify/[**:uid]', function() {}, 'verifyAUTO');
|
2020-07-05 07:04:12 -06:00
|
|
|
$router->map('GET', '/encrypt/hkp/[**:uid]', function() {}, 'encryptHKP');
|
|
|
|
$router->map('GET', '/encrypt/wkd/[**:uid]', function() {}, 'encryptWKD');
|
|
|
|
$router->map('GET', '/encrypt/keybase/[:uid]/[:fp]', function() {}, 'encryptKeybase');
|
2020-07-01 18:36:15 -06:00
|
|
|
$router->map('GET', '/encrypt/[**:uid]', function() {}, 'encryptAUTO');
|
2020-07-05 07:04:12 -06:00
|
|
|
$router->map('GET', '/proofs/hkp/[**:uid]', function() {}, 'proofsHKP');
|
|
|
|
$router->map('GET', '/proofs/wkd/[**:uid]', function() {}, 'proofsWKD');
|
2020-07-01 18:36:15 -06:00
|
|
|
$router->map('GET', '/proofs/[**:uid]', function() {}, 'proofsAUTO');
|
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-07-05 07:04:12 -06:00
|
|
|
$router->map('GET', '/keybase/[:uid]/[:fp]', function() {}, 'profileKeybase');
|
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':
|
2020-07-01 18:36:15 -06:00
|
|
|
echo $templates->render('index');
|
2020-06-26 09:00:22 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'verify':
|
2020-07-01 18:36:15 -06:00
|
|
|
echo $templates->render('verify', ['title' => 'Verify — ', 'mode' => 'auto']);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'verifyAUTO':
|
|
|
|
echo $templates->render('verify', ['title' => 'Verify — ', 'mode' => 'auto', 'auto_input' => $match['params']['uid']]);
|
|
|
|
break;
|
|
|
|
|
2020-06-28 15:27:37 -06:00
|
|
|
case 'verifyHKP':
|
2020-07-01 18:36:15 -06:00
|
|
|
echo $templates->render('verify', ['title' => 'Verify — ', 'mode' => 'hkp', 'hkp_input' => $match['params']['uid']]);
|
2020-06-28 15:27:37 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'verifyWKD':
|
2020-07-01 18:36:15 -06:00
|
|
|
echo $templates->render('verify', ['title' => 'Verify — ', 'mode' => 'wkd', 'wkd_input' => $match['params']['uid']]);
|
2020-06-26 09:00:22 -06:00
|
|
|
break;
|
|
|
|
|
2020-07-05 07:04:12 -06:00
|
|
|
case 'verifyKeybase':
|
|
|
|
echo $templates->render('verify', ['title' => 'Verify — ', 'mode' => 'keybase', 'keybase_username' => htmlspecialchars($match['params']['uid']), 'keybase_fingerprint' => htmlspecialchars($match['params']['fp'])]);
|
|
|
|
break;
|
|
|
|
|
2020-06-26 09:00:22 -06:00
|
|
|
case 'encrypt':
|
2020-07-01 18:36:15 -06:00
|
|
|
echo $templates->render('encrypt', ['title' => 'Encrypt — ', 'mode' => 'auto']);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'encryptAUTO':
|
|
|
|
echo $templates->render('encrypt', ['title' => 'Encrypt — ', 'mode' => 'auto', 'auto_input' => $match['params']['uid']]);
|
|
|
|
break;
|
|
|
|
|
2020-06-28 15:27:37 -06:00
|
|
|
case 'encryptHKP':
|
2020-07-01 18:36:15 -06:00
|
|
|
echo $templates->render('encrypt', ['title' => 'Encrypt — ', 'mode' => 'hkp', 'hkp_input' => $match['params']['uid']]);
|
2020-06-28 15:27:37 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'encryptWKD':
|
2020-07-01 18:36:15 -06:00
|
|
|
echo $templates->render('encrypt', ['title' => 'Encrypt — ', 'mode' => 'wkd', 'wkd_input' => $match['params']['uid']]);
|
2020-06-26 09:00:22 -06:00
|
|
|
break;
|
|
|
|
|
2020-07-05 07:04:12 -06:00
|
|
|
case 'encryptKeybase':
|
|
|
|
echo $templates->render('encrypt', ['title' => 'Encrypt — ', 'mode' => 'keybase', 'keybase_username' => htmlspecialchars($match['params']['uid']), 'keybase_fingerprint' => htmlspecialchars($match['params']['fp'])]);
|
|
|
|
break;
|
|
|
|
|
2020-06-26 09:00:22 -06:00
|
|
|
case 'proofs':
|
2020-07-01 18:36:15 -06:00
|
|
|
echo $templates->render('proofs', ['title' => 'Proofs — ', 'mode' => 'auto']);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'proofsAUTO':
|
|
|
|
echo $templates->render('proofs', ['title' => 'Proofs — ', 'mode' => 'auto', 'auto_input' => $match['params']['uid']]);
|
|
|
|
break;
|
|
|
|
|
2020-06-28 15:27:37 -06:00
|
|
|
case 'proofsHKP':
|
2020-07-01 18:36:15 -06:00
|
|
|
echo $templates->render('proofs', ['title' => 'Proofs — ', 'mode' => 'hkp', 'hkp_input' => $match['params']['uid']]);
|
2020-06-28 15:27:37 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'proofsWKD':
|
2020-07-01 18:36:15 -06:00
|
|
|
echo $templates->render('proofs', ['title' => 'Proofs — ', 'mode' => 'wkd', 'wkd_input' => $match['params']['uid']]);
|
2020-06-26 09:00:22 -06:00
|
|
|
break;
|
2020-06-26 09:33:39 -06:00
|
|
|
|
|
|
|
case 'profile':
|
2020-07-01 18:36:15 -06:00
|
|
|
echo $templates->render('profile', ['mode' => 'auto', 'uid' => htmlspecialchars($match['params']['uid'])]);
|
2020-06-28 16:09:31 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'profileHKP':
|
2020-07-01 18:36:15 -06:00
|
|
|
echo $templates->render('profile', ['mode' => 'hkp', 'uid' => htmlspecialchars($match['params']['uid'])]);
|
2020-06-28 16:09:31 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'profileWKD':
|
2020-07-01 18:36:15 -06:00
|
|
|
echo $templates->render('profile', ['mode' => 'wkd', 'uid' => htmlspecialchars($match['params']['uid'])]);
|
2020-06-26 09:33:39 -06:00
|
|
|
break;
|
2020-06-27 06:51:31 -06:00
|
|
|
|
2020-07-05 07:04:12 -06:00
|
|
|
case 'profileKeybase':
|
|
|
|
echo $templates->render('profile', ['mode' => 'keybase', 'uid' => htmlspecialchars($match['params']['uid']).'/'.htmlspecialchars($match['params']['fp'])]);
|
|
|
|
break;
|
|
|
|
|
2020-06-28 12:14:31 -06:00
|
|
|
case 'guides':
|
2020-07-01 18:36:15 -06:00
|
|
|
echo $templates->render('guides');
|
2020-06-28 12:14:31 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'guideId':
|
2020-07-01 07:47:14 -06:00
|
|
|
$id = htmlspecialchars($match['params']['id']);
|
2020-07-04 19:21:44 -06:00
|
|
|
if (file_exists("views/guides/$id.title.php") && file_exists("views/guides/$id.content.php")) {
|
|
|
|
echo $templates->render('guide', ['id' => $id]);
|
2020-07-01 07:49:39 -06:00
|
|
|
} else {
|
2020-07-01 18:36:15 -06:00
|
|
|
echo $templates->render("404");
|
2020-07-01 07:49:39 -06:00
|
|
|
}
|
2020-06-28 12:14:31 -06:00
|
|
|
break;
|
|
|
|
|
2020-06-29 12:58:34 -06:00
|
|
|
case 'util':
|
2020-07-01 07:47:14 -06:00
|
|
|
$id = htmlspecialchars($match['params']['id']);
|
2020-07-01 18:36:15 -06:00
|
|
|
echo $templates->render("util/$id");
|
2020-06-29 12:58:34 -06:00
|
|
|
break;
|
|
|
|
|
2020-07-22 06:54:56 -06:00
|
|
|
case 'util_qrfp':
|
2020-07-02 14:39:56 -06:00
|
|
|
$fp = htmlspecialchars($match['params']['fp']);
|
2020-07-22 06:54:56 -06:00
|
|
|
echo $templates->render("util/qrfp", ['input' => $fp]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'util_qr':
|
2020-07-22 07:37:38 -06:00
|
|
|
$uri = htmlspecialchars($match['params']['uri']);
|
2020-07-22 06:54:56 -06:00
|
|
|
echo $templates->render("util/qr", ['input' => $uri]);
|
2020-07-02 14:39:56 -06:00
|
|
|
break;
|
|
|
|
|
2020-06-27 06:51:31 -06:00
|
|
|
case 'faq':
|
2020-07-01 18:36:15 -06:00
|
|
|
echo $templates->render("faq");
|
2020-06-27 06:51:31 -06:00
|
|
|
break;
|
2020-06-26 09:00:22 -06:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// No route was matched
|
2020-07-01 18:36:15 -06:00
|
|
|
echo $templates->render("404");
|
2020-06-26 09:00:22 -06:00
|
|
|
}
|