This commit is contained in:
Pachira 2021-07-07 01:13:50 +00:00
parent 9e2274cd2d
commit fb23bda4d6
9 changed files with 294 additions and 26 deletions

View file

@ -126,10 +126,16 @@ if($reqPath === '/contact') {
],
[
'id' => 'nin-sw',
'name' => 'Nintendo Switch',
'name' => 'Nintendo Switch (EU)',
'icon' => 'fmi fmi-switch',
'display' => 'SW-7446-8163-4902',
],
[
'id' => 'nin-sw',
'name' => 'Nintendo Switch (JP)',
'icon' => 'fmi fmi-switch',
'display' => 'SW-6001-2763-7822',
],
[
'id' => 'nin-3ds',
'name' => 'Nintendo 3DS',

View file

@ -76,6 +76,21 @@ if($reqPath === '/related') {
'url' => 'https://devkitpro.org/',
'desc' => 'Amazing homebrew toolchains for Nintendo hardware.',
],
[
'name' => 'DeepL',
'url' => 'https://www.deepl.com/translator',
'desc' => 'A machine translator that doesn\'t exclusively produce garbage.',
],
[
'name' => 'ImgOps',
'url' => 'https://imgops.com/',
'desc' => 'Provides quick links to various image reverse search utilities.',
],
[
'name' => 'TETOMOMOWARP',
'url' => 'https://aidn.jp/tetomomowarp/',
'desc' => 'tet',
],
[
'name' => 'Peppy\'s Windows XP Resources',
'url' => 'https://web.archive.org/web/20011202115409/xp.xyu.ca/',

View file

@ -49,11 +49,11 @@ echo html_doctype();
</head>
<body>
<?php } ?>
<?php if($blogMode): ?>
<?php /*if($blogMode): ?>
<div style="max-width: 1000px; margin: 0 auto; font-size: 20px; line-height: 1.7em;">
<div style="margin: 5px; background-color: #222; border-radius: 5px; padding: 2px 5px;">New blog script is still work in progress, enjoy the old version!</div>
</div>
<?php endif; ?>
<?php endif;*/ ?>
<div class="wrapper">
<?php if(!$blogMode) echo html_sidebar(); ?>
<?php if(!empty($posts)): ?>

View file

@ -29,6 +29,7 @@ try {
",
]);
} catch(Exception $ex) {
http_response_code(500);
echo '<h3>Unable to connect to database</h3>';
die($ex->getMessage());
}

View file

@ -1,6 +1,25 @@
<?php
define('KEY_CHARS', 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789');
define('KEY_CHARS_LENGTH', strlen(KEY_CHARS));
function generateKey(int $length): string {
$bytes = random_bytes($length);
for($i = 0; $i < $length; ++$i)
$bytes[$i] = KEY_CHARS[ord($bytes[$i]) % KEY_CHARS_LENGTH];
return $bytes;
}
header('Content-Type: text/plain');
echo '16: ' . bin2hex(random_bytes(8)) . PHP_EOL;
echo '32: ' . bin2hex(random_bytes(16)) . PHP_EOL;
echo '64: ' . bin2hex(random_bytes(32)) . PHP_EOL;
echo '128: ' . bin2hex(random_bytes(64)) . PHP_EOL;
if(isset($_GET['length'])) {
$length = (int)filter_input(INPUT_GET, 'length', FILTER_SANITIZE_NUMBER_INT);
if($length > 0 && $length < 1000) {
echo generateKey($length);
return;
}
}
echo '16: ' . generateKey(8) . PHP_EOL;
echo '32: ' . generateKey(16) . PHP_EOL;
echo '64: ' . generateKey(32) . PHP_EOL;
echo '128: ' . generateKey(64) . PHP_EOL;

37
public/ssh.php Normal file
View file

@ -0,0 +1,37 @@
<?php
require_once __DIR__ . '/_v4/includes.php';
$minLevel = (int)filter_input(INPUT_GET, 'l', FILTER_SANITIZE_NUMBER_INT);
$includeComment = !empty($_GET['c']);
$json = !empty($_GET['j']);
header('Content-Type: ' . ($json ? 'application/json; charset=utf-8' : 'text/plain; charset=us-ascii'));
$keys = $pdo->prepare('SELECT *, UNIX_TIMESTAMP(`key_created`) AS `key_created` FROM `fm_public_keys` WHERE `key_deprecated` IS NULL AND `key_level` >= :level');
$keys->bindValue('level', $minLevel);
$keys->execute();
$keys = $keys->fetchAll(PDO::FETCH_OBJ);
if($json) {
$items = [];
foreach($keys as $key) {
$items[] = $item = new stdClass;
$item->algo = $key->key_algo;
$item->key = $key->key_body;
if($includeComment) {
$item->comment = $key->key_comment;
$item->created = date(DateTime::ATOM, $key->key_created);
$item->level = $key->key_level;
}
}
echo json_encode($items);
} else {
foreach($keys as $key) {
printf('ssh-%s %s', $key->key_algo, $key->key_body);
if($includeComment)
printf(' %s (%s)', $key->key_comment, date('M Y', $key->key_created));
echo "\n";
}
}

200
public/temp.php Normal file
View file

@ -0,0 +1,200 @@
<?php
require_once __DIR__ . '/_v4/includes.php';
define('FM_TEMP_KEY', 'kND861svbydCLywutu78tRmlpWdzoRLPcVZSrnxerh3KbLwfwvfvgC5hzax8gvYm');
define('FM_TEMP_INT', 10);
ini_set('display_errors', 'on');
error_reporting(-1);
if(isset($_POST['temp']) && isset($_POST['hash']) && isset($_POST['time'])) {
$temp = (string)filter_input(INPUT_POST, 'temp', FILTER_SANITIZE_STRING);
$hash = (string)filter_input(INPUT_POST, 'hash', FILTER_SANITIZE_STRING);
$time = (string)filter_input(INPUT_POST, 'time', FILTER_SANITIZE_NUMBER_INT);
if(!hash_equals(hash_hmac('sha256', $temp . '|' . $time, FM_TEMP_KEY), $hash))
return;
$time = floor((int)json_decode($time) / FM_TEMP_INT);
if($time !== floor(time() / FM_TEMP_INT))
return;
$insert = $pdo->prepare('INSERT INTO `fm_temperature` (`temp_celcius`) VALUES (:temp)');
$insert->bindValue('temp', (string)json_decode($temp));
$insert->execute();
return;
}
if(isset($_GET['since'])) {
$since = (int)filter_input(INPUT_GET, 'since', FILTER_SANITIZE_NUMBER_INT);
$temps = $pdo->prepare('SELECT `temp_celcius`, UNIX_TIMESTAMP(`temp_datetime`) AS `temp_datetime` FROM `fm_temperature` WHERE `temp_datetime` > FROM_UNIXTIME(:since) AND `temp_datetime` > NOW() - INTERVAL 1 DAY ORDER BY `temp_datetime` ASC LIMIT 288');
$temps->bindValue('since', $since);
$temps->execute();
header('Content-Type: application/json; charset=utf-8');
echo json_encode($temps->fetchAll(PDO::FETCH_ASSOC));
return;
}
if(!empty($_GET['siri'])) {
header('Content-Type: text/plain; charset=utf-8');
$temps = $pdo->prepare('SELECT `temp_celcius`, UNIX_TIMESTAMP(`temp_datetime`) AS `temp_datetime` FROM `fm_temperature` ORDER BY `temp_datetime` DESC LIMIT 1');
$temps->execute();
$temps = $temps->fetch(PDO::FETCH_ASSOC);
printf('It was %2$.1f°C at %1$s.', date('H:i:s', $temps['temp_datetime']), $temps['temp_celcius']);
return;
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>Room Temperature</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
<link href="/css/electrolize/style.css" type="text/css" rel="stylesheet"/>
<style type="text/css">
* {
margin: 0;
padding: 0;
box-sizing: border-box;
position: relative;
outline-style: none;
}
html, body {
width: 100%;
height: 100%;
}
body {
background-color: #111;
color: #fff;
font: 12px/20px Tahoma, Geneva, 'Dejavu Sans', Arial, Helvetica, sans-serif;
padding: 1px;
}
.current {
text-align: center;
background-color: #333;
margin: 10px;
padding: 10px;
border-radius: 10px;
}
.current-temp {
font-family: 'Electrolize', Verdana, 'Dejavu Sans', Arial, Helvetica, sans-serif;
font-size: 3em;
line-height: 1.2em;
}
.current-datetime {
font-size: .9em;
line-height: 1.4em;
}
.chart {
background-color: #ddd;
margin: 10px;
padding: 10px;
border-radius: 10px;
}
</style>
</head>
<body>
<div class="main">
<div class="current">
<div class="current-temp">
<span id="-last-temp">--</span> °C
</div>
<div class="current-datetime">
<span id="-last-datetime">--:--:--</span>
</div>
</div>
<div class="chart">
<canvas id="-chart" width="400" height="170"></canvas>
</div>
</div>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/chart.js@3.3.2/dist/chart.min.js"></script>
<script type="text/javascript">
var temp = {
last: 0,
history: [],
lastTemp: null,
lastDateTime: null,
chart: null,
};
temp.getLastTemperature = function() {
if(this.history.length === 0)
return {temp_datetime: 0, temp_celcius: 0};
return this.history[this.history.length - 1];
};
temp.refresh = function() {
var xhr = new XMLHttpRequest;
xhr.onload = function() {
var temps = JSON.parse(xhr.responseText);
for(var i = 0; i < temps.length; ++i) {
var temp = temps[i];
this.last = temp.temp_datetime;
this.history.push(temp);
}
this.refreshUI();
}.bind(this);
xhr.open('GET', '/temp.php?since=' + encodeURIComponent(parseInt(this.last).toString()));
xhr.send();
};
temp.refreshUI = function() {
var temp = this.getLastTemperature();
this.lastTemp.textContent = (parseInt(temp.temp_celcius * 10) / 10).toFixed(1).toLocaleString();
this.lastDateTime.textContent = new Date(temp.temp_datetime * 1000).toLocaleString();
var take = Math.min(288, this.history.length),
dataset = this.chart.data.datasets[0];
this.chart.data.labels = [];
dataset.data = [];
for(var i = this.history.length - take; i < this.history.length; ++i) {
var temp = this.history[i];
this.chart.data.labels.push(new Date(temp.temp_datetime * 1000).toLocaleString());
dataset.data.push(temp.temp_celcius);
}
this.chart.update();
};
window.onload = function() {
temp.lastTemp = document.getElementById('-last-temp');
temp.lastDateTime = document.getElementById('-last-datetime');
var ctx = document.getElementById('-chart').getContext('2d');
temp.chart = new Chart(ctx, {
type: 'line',
data: {
datasets: [
{
label: 'Temperature',
data: [],
borderColor: '#111',
backgroundColor: '#222',
},
],
},
options: {
responsive: true,
plugins: {
legend: {
position: 'top',
},
title: {
display: true,
text: 'Temperature History',
},
},
scales: {
y: {
suggestedMax: 34,
suggestedMin: 20,
ticks: {
stepSize: 1,
},
},
},
},
});
temp.refresh();
setInterval(temp.refresh.bind(temp), 5 * 60 * 1000);
};
</script>
</body>
</html>

0
public/tile-test.php Normal file
View file

View file

@ -1,28 +1,18 @@
// ==UserScript==
// @name Removed Trending tab
// @version 1
// @version 6
// @grant none
// @include https://www.youtube.com/*
// ==/UserScript==
window.addEventListener('load', () => {
const guideButton = document.getElementById('guide-button'),
appDrawer = document.querySelector('app-drawer');
window.addEventListener('load', function() {
var checkInterval = setInterval(function() {
var buttons = Array.from(document.querySelectorAll('[href="/feed/explore"], [href="/feed/trending"]'));
if (appDrawer.getAttribute('opened') !== null)
removeTrendingButton();
else
guideButton.addEventListener('click', () => removeTrendingButton());
});
function removeTrendingButton() {
const checkInterval = setInterval(() => {
const trendingButton = document.querySelector('[href="/feed/trending"]');
if (trendingButton) {
trendingButton.parentElement.remove();
if(buttons.length) {
while(buttons.length)
buttons.pop().parentElement.remove();
clearInterval(checkInterval);
}
}, 100);
}
});