2020-07-30 00:55:37 +00:00
|
|
|
<?php
|
2022-02-04 20:30:52 +00:00
|
|
|
namespace Makai;
|
|
|
|
|
2022-09-26 23:06:12 +00:00
|
|
|
use Index\Http\HttpFx;
|
2022-02-04 20:30:52 +00:00
|
|
|
|
|
|
|
require_once __DIR__ . '/../makai.php';
|
|
|
|
|
2022-09-26 23:06:12 +00:00
|
|
|
define('MKI_REDIRS', [
|
|
|
|
'/about' => '/',
|
|
|
|
'/about.html' => '/',
|
|
|
|
'/about.php' => '/',
|
|
|
|
'/index.php' => '/',
|
|
|
|
'/index.html' => '/',
|
|
|
|
'/related.php' => '/',
|
|
|
|
'/related.html' => '/',
|
|
|
|
'/friends' => '/',
|
|
|
|
'/friends.php' => '/',
|
|
|
|
'/friends.html' => '/',
|
|
|
|
'/related' => '/',
|
|
|
|
'/etc.php' => '/',
|
|
|
|
'/etc.html' => '/',
|
|
|
|
'/etcetera' => '/',
|
|
|
|
'/etcetera.html' => '/',
|
|
|
|
'/etcetera.php' => '/',
|
|
|
|
'/misc' => '/',
|
|
|
|
'/misc.html' => '/',
|
|
|
|
'/misc.php' => '/',
|
|
|
|
'/etc' => '/',
|
|
|
|
'/365' => '/',
|
|
|
|
'/donate' => '/',
|
|
|
|
'/blog.php' => '/',
|
|
|
|
'/blog-post.php' => '/',
|
|
|
|
'/blog/:id' => '/',
|
|
|
|
'/old-blog' => '/',
|
|
|
|
'/old-blog/:id' => '/',
|
|
|
|
'/projects.php' => '/projects',
|
|
|
|
'/projects.html' => '/projects',
|
|
|
|
'/utilities' => '/projects',
|
|
|
|
'/utilities.php' => '/projects',
|
|
|
|
'/utilities.html' => '/projects',
|
|
|
|
'/contact.php' => '/contact',
|
|
|
|
'/contact.html' => '/contact',
|
|
|
|
'/nintendo' => '/contact',
|
|
|
|
'/nintendo.php' => '/contact',
|
2020-07-30 00:55:37 +00:00
|
|
|
]);
|
|
|
|
|
2022-09-26 23:06:12 +00:00
|
|
|
$router = new HttpFx;
|
2020-07-30 00:55:37 +00:00
|
|
|
|
2022-09-26 23:06:12 +00:00
|
|
|
$router->setDefaultErrorHandler(function($response, $request, $code, $text) use ($ctx) {
|
|
|
|
$path = 'errors/' . $code;
|
|
|
|
$tpl = $ctx->getTemplating();
|
|
|
|
$response->setContent($tpl->render($tpl->exists($path) ? $path : 'errors/master', [
|
|
|
|
'http_error_code' => $code,
|
|
|
|
'http_error_title' => $text,
|
|
|
|
]));
|
|
|
|
});
|
2020-07-30 00:55:37 +00:00
|
|
|
|
2022-09-26 23:06:12 +00:00
|
|
|
$router->get('/error/:code', function($response, $request, $code) {
|
|
|
|
return intval($code);
|
|
|
|
});
|
|
|
|
|
|
|
|
foreach(MKI_REDIRS as $source => $target)
|
|
|
|
$router->get($source, function($response) use ($target) {
|
|
|
|
$response->redirect($target);
|
|
|
|
});
|
|
|
|
|
|
|
|
$router->use('/', function($response) {
|
|
|
|
$response->setPoweredBy('Makai+Index');
|
|
|
|
});
|
|
|
|
|
|
|
|
$router->get('/header-bgs.json', function() {
|
|
|
|
return json_encode(FM_BGS);
|
|
|
|
});
|
|
|
|
|
|
|
|
$router->get('/now-listening', function() use ($ctx) {
|
|
|
|
return $ctx->getTemplating()->render('np', [
|
|
|
|
'header_offset' => (int)filter_input(INPUT_GET, 'offset', FILTER_SANITIZE_NUMBER_INT),
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
$router->get('/now-listening.json', function() {
|
|
|
|
$lfmInfo = json_decode(file_get_contents('https://now.flash.moe/get.php?u=flashwave_'));
|
2020-07-30 00:55:37 +00:00
|
|
|
|
2022-09-26 23:06:12 +00:00
|
|
|
if(empty($lfmInfo[0]->name))
|
|
|
|
return [];
|
|
|
|
|
|
|
|
$lfmInfo = $lfmInfo[0];
|
|
|
|
|
|
|
|
return [
|
|
|
|
'name' => strval($lfmInfo->name),
|
|
|
|
'now_playing' => !empty($lfmInfo->nowplaying),
|
|
|
|
'url' => strval($lfmInfo->url),
|
|
|
|
'cover' => !empty($lfmInfo->images->large) ? strval($lfmInfo->images->large) : '',
|
|
|
|
'artist' => [
|
|
|
|
'name' => !empty($lfmInfo->artist->name) ? strval($lfmInfo->artist->name) : '',
|
|
|
|
'url' => explode('/_/', strval($lfmInfo->url))[0],
|
|
|
|
],
|
2020-07-30 00:55:37 +00:00
|
|
|
];
|
2022-09-26 23:06:12 +00:00
|
|
|
});
|
2020-07-30 00:55:37 +00:00
|
|
|
|
2022-09-26 23:06:12 +00:00
|
|
|
$router->get('/home', function() use ($ctx) {
|
|
|
|
return $ctx->getTemplating()->render('home/index');
|
|
|
|
});
|
|
|
|
|
|
|
|
$router->get('/', function() use ($ctx) {
|
|
|
|
$legacyPage = (string)filter_input(INPUT_GET, 'p');
|
|
|
|
if(!empty($legacyPage)) {
|
|
|
|
$legacyPages = [
|
|
|
|
'projects' => '/projects',
|
|
|
|
'contact' => '/contact',
|
|
|
|
'about' => '/',
|
|
|
|
'etc' => '/etc',
|
|
|
|
'hosted' => '/etc',
|
|
|
|
'friends' => '/related',
|
|
|
|
];
|
|
|
|
|
|
|
|
if(isset($legacyPages[$legacyPage])) {
|
|
|
|
header('Location: ' . $legacyPages[$legacyPage]);
|
|
|
|
return 302;
|
|
|
|
}
|
2020-07-30 00:55:37 +00:00
|
|
|
}
|
|
|
|
|
2022-09-26 23:06:12 +00:00
|
|
|
$db = $ctx->getDatabase();
|
2020-07-30 00:55:37 +00:00
|
|
|
|
2022-09-26 23:06:12 +00:00
|
|
|
return $ctx->getTemplating()->render('index', [
|
|
|
|
'projects' => (new Projects($db))->getFeatured(),
|
|
|
|
'languages' => new Languages($db),
|
|
|
|
'contacts' => (new Contacts($db))->getHomePage(),
|
|
|
|
]);
|
|
|
|
});
|
2020-07-30 00:55:37 +00:00
|
|
|
|
2022-09-26 23:06:12 +00:00
|
|
|
$router->get('/contact', function() use ($ctx) {
|
|
|
|
return $ctx->getTemplating()->render('contact', [
|
|
|
|
'contacts' => (new Contacts($ctx->getDatabase()))->getAll(),
|
|
|
|
]);
|
|
|
|
});
|
2020-08-31 15:43:18 +00:00
|
|
|
|
2022-09-26 23:06:12 +00:00
|
|
|
$router->get('/projects', function() use ($ctx) {
|
|
|
|
$db = $ctx->getDatabase();
|
|
|
|
$projects = (new Projects($db))->getAll();
|
|
|
|
|
|
|
|
$sections = [
|
|
|
|
'projects' => [
|
|
|
|
'title' => 'Active Projects',
|
|
|
|
'desc' => 'Projects that I work on on a fairly regular basis.',
|
|
|
|
'items' => [],
|
|
|
|
],
|
|
|
|
'tools' => [
|
|
|
|
'title' => 'Tools',
|
|
|
|
'desc' => 'Personal quality of life tools that I update when I need something new from them.',
|
|
|
|
'items' => [],
|
|
|
|
],
|
|
|
|
'archives' => [
|
|
|
|
'title' => 'Archived Projects',
|
|
|
|
'desc' => 'Past projects that I no longer work on.',
|
|
|
|
'items' => [],
|
|
|
|
],
|
|
|
|
];
|
2020-07-30 00:55:37 +00:00
|
|
|
|
2022-09-26 23:06:12 +00:00
|
|
|
foreach($projects as $project) {
|
|
|
|
if($project->isArchived())
|
|
|
|
$sections['archives']['items'][] = $project;
|
|
|
|
else {
|
|
|
|
if($project->isTool())
|
|
|
|
$sections['tools']['items'][] = $project;
|
|
|
|
else
|
|
|
|
$sections['projects']['items'][] = $project;
|
|
|
|
}
|
|
|
|
}
|
2020-10-30 13:43:48 +00:00
|
|
|
|
2022-09-26 23:06:12 +00:00
|
|
|
return $ctx->getTemplating()->render('projects', [
|
|
|
|
'sections' => $sections,
|
|
|
|
'languages' => new Languages($db),
|
|
|
|
]);
|
|
|
|
});
|
2020-08-19 14:33:55 +00:00
|
|
|
|
2022-09-26 23:06:12 +00:00
|
|
|
$router->get('/ssh.php', function() {
|
|
|
|
$query = '';
|
2022-02-05 03:35:42 +00:00
|
|
|
|
2022-09-26 23:06:12 +00:00
|
|
|
$minLevel = (int)filter_input(INPUT_GET, 'l', FILTER_SANITIZE_NUMBER_INT);
|
|
|
|
if($minLevel > 0)
|
|
|
|
$query .= sprintf('l=%d&', $minLevel);
|
2022-02-05 03:35:42 +00:00
|
|
|
|
2022-09-26 23:06:12 +00:00
|
|
|
if(!empty($_GET['c']))
|
|
|
|
$query .= 'c=1&';
|
2022-02-05 03:35:42 +00:00
|
|
|
|
2022-09-26 23:06:12 +00:00
|
|
|
if(!empty($_GET['j']))
|
|
|
|
$query .= 'j=1&';
|
|
|
|
|
|
|
|
if($query !== '')
|
|
|
|
$query = '?' . substr($query, 0, -1);
|
|
|
|
|
|
|
|
header('Location: /ssh_keys' . $query);
|
|
|
|
return 302;
|
2022-02-05 03:35:42 +00:00
|
|
|
});
|
|
|
|
|
2022-09-26 23:06:12 +00:00
|
|
|
$router->get('/ssh_keys', function() use ($db) {
|
|
|
|
$minLevel = (int)filter_input(INPUT_GET, 'l', FILTER_SANITIZE_NUMBER_INT);
|
|
|
|
$includeComment = !empty($_GET['c']);
|
|
|
|
$json = !empty($_GET['j']);
|
|
|
|
|
|
|
|
$keys = (new SSHKeys($db))->getKeys($minLevel);
|
|
|
|
|
|
|
|
if($json) {
|
|
|
|
$items = [];
|
|
|
|
|
|
|
|
foreach($keys as $key) {
|
|
|
|
$items[] = $item = new \stdClass;
|
|
|
|
$item->algo = $key->getAlgorithm();
|
|
|
|
$item->key = $key->getBody();
|
|
|
|
if($includeComment) {
|
|
|
|
$item->comment = (string)$key->getComment();
|
|
|
|
$item->created = $key->getCreatedAt()->format(\DateTime::ATOM);
|
|
|
|
$item->level = $key->getLevel();
|
|
|
|
}
|
2022-02-05 03:35:42 +00:00
|
|
|
}
|
2022-09-26 23:06:12 +00:00
|
|
|
|
|
|
|
return $items;
|
2022-02-05 03:35:42 +00:00
|
|
|
}
|
2022-09-26 23:06:12 +00:00
|
|
|
|
|
|
|
header('Content-Type: text/plain; charset=us-ascii');
|
|
|
|
|
|
|
|
$body = '';
|
|
|
|
|
|
|
|
foreach($keys as $key)
|
|
|
|
$body .= $key->toString($includeComment) . "\n";
|
|
|
|
|
|
|
|
return $body;
|
|
|
|
});
|
|
|
|
|
|
|
|
$router->get('/authorized_keys', function() use ($db) {
|
|
|
|
$keys = (new SSHKeys($db))->getKeys(500);
|
|
|
|
|
|
|
|
header('Content-Type: text/plain; charset=us-ascii');
|
|
|
|
|
|
|
|
$body = '';
|
|
|
|
foreach($keys as $key)
|
|
|
|
$body .= $key->toString(true) . "\n";
|
|
|
|
|
|
|
|
return $body;
|
|
|
|
});
|
|
|
|
|
|
|
|
$router->get('/git_keys_ro', function() use ($db) {
|
|
|
|
$keys = (new SSHKeys($db))->getKeys(100);
|
|
|
|
|
|
|
|
header('Content-Type: text/plain; charset=us-ascii');
|
|
|
|
|
|
|
|
$body = '';
|
|
|
|
foreach($keys as $key)
|
|
|
|
$body .= $key->toString(false) . "\n";
|
|
|
|
|
|
|
|
return $body;
|
|
|
|
});
|
|
|
|
|
|
|
|
$router->get('/git_keys_rw', function() use ($db) {
|
|
|
|
$keys = (new SSHKeys($db))->getKeys(200);
|
|
|
|
|
|
|
|
header('Content-Type: text/plain; charset=us-ascii');
|
|
|
|
|
|
|
|
$body = '';
|
|
|
|
foreach($keys as $key)
|
|
|
|
$body .= $key->toString(false) . "\n";
|
|
|
|
|
|
|
|
return $body;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$router->dispatch();
|