V4 IS GONE

This commit is contained in:
flash 2022-02-06 01:36:05 +00:00
parent 40a1d62466
commit c4d160a20c
19 changed files with 278 additions and 296 deletions

1
.gitignore vendored
View file

@ -7,3 +7,4 @@
.DS_Store .DS_Store
[Dd]esktop.ini [Dd]esktop.ini
/.debug /.debug
/config/*.ini

3
.gitmodules vendored
View file

@ -1,3 +1,6 @@
[submodule "lib/index"] [submodule "lib/index"]
path = lib/index path = lib/index
url = https://github.com/flashwave/index.git url = https://github.com/flashwave/index.git
[submodule "public/whois/whois-php"]
path = public/whois/whois-php
url = https://git.flash.moe/flash/whois-php.git

View file

@ -1,10 +1,13 @@
<?php <?php
namespace Makai; namespace Makai;
use ErrorException;
use Index\Autoloader; use Index\Autoloader;
use Index\Data\ConnectionFailedException; use Index\Data\ConnectionFailedException;
use Index\Data\MariaDB\MariaDBBackend; use Index\Data\MariaDB\MariaDBBackend;
use Index\Data\MariaDB\MariaDBConnectionInfo; use Index\Data\MariaDB\MariaDBConnectionInfo;
use Index\Data\NullDb\NullDbBackend;
use Index\Data\NullDb\NullDbConnectionInfo;
define('MKI_STARTUP', microtime(true)); define('MKI_STARTUP', microtime(true));
define('MKI_ROOT', __DIR__); define('MKI_ROOT', __DIR__);
@ -13,6 +16,7 @@ define('MKI_DIR_SRC', MKI_ROOT . '/src');
define('MKI_DIR_LIB', MKI_ROOT . '/lib'); define('MKI_DIR_LIB', MKI_ROOT . '/lib');
define('MKI_DIR_PUB', MKI_ROOT . '/public'); define('MKI_DIR_PUB', MKI_ROOT . '/public');
define('MKI_DIR_PAGES', MKI_ROOT . '/pages'); define('MKI_DIR_PAGES', MKI_ROOT . '/pages');
define('MKI_DIR_CONFIG', MKI_ROOT . '/config');
if(MKI_DEBUG) { if(MKI_DEBUG) {
ini_set('display_errors', 'on'); ini_set('display_errors', 'on');
@ -26,16 +30,26 @@ require_once MKI_DIR_LIB . '/index/index.php';
Autoloader::addNamespace(__NAMESPACE__, MKI_DIR_SRC); Autoloader::addNamespace(__NAMESPACE__, MKI_DIR_SRC);
try {
$dbConfig = parse_ini_file(MKI_DIR_CONFIG . DIRECTORY_SEPARATOR . 'database.ini');
} catch(ErrorException $ex) {
$dbConfig = null;
}
if(!empty($dbConfig))
try { try {
$db = (new MariaDBBackend)->createConnection(MariaDBConnectionInfo::create( $db = (new MariaDBBackend)->createConnection(MariaDBConnectionInfo::create(
'unix:/var/run/mysqld/mysqld.sock', $dbConfig['host'] ?? '',
'website', $dbConfig['user'] ?? '',
'A3NjVvHRkHAxiYgk8MM4ZrCwrLVyPIYX', $dbConfig['pass'] ?? '',
'website', $dbConfig['name'] ?? '',
'utf8mb4', $dbConfig['char'] ?? 'utf8mb4',
'SET SESSION time_zone = \'+00:00\', sql_mode = \'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION\'', 'SET SESSION time_zone = \'+00:00\', sql_mode = \'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION\'',
)); ));
} catch(ConnectionFailedException $ex) { } catch(ConnectionFailedException $ex) {
echo '<h3>Unable to connect to database</h3>'; //echo '<h3>Unable to connect to database</h3>';
die($ex->getMessage()); //die($ex->getMessage());
} }
if(empty($db))
$db = (new NullDbBackend)->createConnection(new NullDbConnectionInfo);

View file

@ -57,6 +57,13 @@ $router->get('/now-listening.json', function() {
]; ];
}); });
$router->get('/np.php', function() {
header('Content-Type: text/xml');
return cache_output('lastfm-xml', 10, function() {
return file_get_contents('https://now.flash.moe/get.php?u=flashwave_&f=xml');
});
});
$router->get('/home', function() { $router->get('/home', function() {
$body = fm_component('header', [ $body = fm_component('header', [
'title' => 'flash.moe / homepage', 'title' => 'flash.moe / homepage',

92
pages/ssh.php Normal file
View file

@ -0,0 +1,92 @@
<?php
namespace Makai;
$router->get('/ssh.php', function() {
$query = '';
$minLevel = (int)filter_input(INPUT_GET, 'l', FILTER_SANITIZE_NUMBER_INT);
if($minLevel > 0)
$query .= sprintf('l=%d&', $minLevel);
if(!empty($_GET['c']))
$query .= 'c=1&';
if(!empty($_GET['j']))
$query .= 'j=1&';
if($query !== '')
$query = '?' . substr($query, 0, -1);
header('Location: /ssh_keys' . $query);
return 302;
});
$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();
}
}
return $items;
}
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;
});

View file

@ -1,28 +0,0 @@
<?php
define('FM_DEBUG', false);
error_reporting(0);
ini_set('display_errors', 'off');
date_default_timezone_set('UTC');
mb_internal_encoding('UTF-8');
set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__);
try {
$pdo = new PDO('mysql:unix_socket=/var/run/mysqld/mysqld.sock;dbname=website;charset=utf8mb4', 'website', 'A3NjVvHRkHAxiYgk8MM4ZrCwrLVyPIYX', [
PDO::ATTR_CASE => PDO::CASE_NATURAL,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
PDO::ATTR_STRINGIFY_FETCHES => false,
PDO::ATTR_EMULATE_PREPARES => false,
PDO::MYSQL_ATTR_INIT_COMMAND => "
SET SESSION
sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION',
time_zone = '+00:00';
",
]);
} catch(Exception $ex) {
http_response_code(500);
echo '<h3>Unable to connect to database</h3>';
die($ex->getMessage());
}

View file

@ -1,132 +0,0 @@
<?php
require_once __DIR__ . '/../_v4/includes.php';
error_reporting(-1);
ini_set('display_errors', 'On');
$dbName = tempnam(sys_get_temp_dir(), 'v4d');
$sqlite = new SQLite3($dbName, SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
$sqlite->enableExceptions(true);
// tables
$sqlite->exec('CREATE TABLE "fm_blog_posts" ("post_id" INTEGER NOT NULL, "user_id" INTEGER DEFAULT NULL, "post_created" INTEGER NOT NULL, "post_published" INTEGER DEFAULT NULL, "post_updated" INTEGER DEFAULT NULL, "post_deleted" INTEGER DEFAULT NULL, "post_safe" INTEGER DEFAULT 0, "post_title" TEXT NOT NULL, "post_text" TEXT NOT NULL, "post_new_url" TEXT DEFAULT NULL);');
$sqlite->exec('CREATE TABLE "fm_blog_tags" ("tag_id" INTEGER NOT NULL, "tag_name" TEXT NOT NULL, "tag_slug" TEXT NOT NULL UNIQUE, "tag_description" TEXT, "tag_created" INTEGER NOT NULL, PRIMARY KEY("tag_id" AUTOINCREMENT));');
$sqlite->exec('CREATE TABLE "fm_blog_posts_tags" ("post_id" INTEGER NOT NULL, "tag_id" INTEGER NOT NULL, PRIMARY KEY("tag_id","post_id"), FOREIGN KEY("post_id") REFERENCES "fm_blog_posts"("post_id") ON UPDATE CASCADE ON DELETE CASCADE, FOREIGN KEY("post_id") REFERENCES "fm_blog_posts" ("post_id") ON UPDATE CASCADE ON DELETE CASCADE);');
$sqlite->exec('CREATE TABLE "fm_blog_wordpress" ("post_id" INTEGER NOT NULL, "wordpress_id" INTEGER NOT NULL UNIQUE, "wordpress_name" TEXT NOT NULL UNIQUE, FOREIGN KEY("post_id") REFERENCES "fm_blog_posts"("post_id") ON UPDATE CASCADE ON DELETE CASCADE, PRIMARY KEY("post_id"));');
$sqlite->exec('CREATE TABLE "fm_proglangs" ("language_id" INTEGER NOT NULL, "language_name" TEXT NOT NULL UNIQUE, "language_colour" INTEGER DEFAULT NULL, PRIMARY KEY("language_id" AUTOINCREMENT));');
$sqlite->exec('CREATE TABLE "fm_projects" ("project_id" INTEGER NOT NULL, "project_name" TEXT NOT NULL UNIQUE, "project_name_clean" TEXT DEFAULT NULL UNIQUE, "project_summary" TEXT DEFAULT NULL, "project_description" TEXT DEFAULT NULL, "project_order" INTEGER NOT NULL DEFAULT 0, "project_type" TEXT NOT NULL DEFAULT \'Project\', "project_featured" INTEGER NOT NULL, "project_colour" INTEGER DEFAULT NULL, "project_homepage" TEXT DEFAULT NULL, "project_repository" TEXT DEFAULT NULL, "project_forum" TEXT DEFAULT NULL, "project_created" INTEGER NOT NULL, "project_deleted" INTEGER DEFAULT NULL, "project_archived" INTEGER DEFAULT NULL, PRIMARY KEY("project_id" AUTOINCREMENT));');
$sqlite->exec('CREATE TABLE "fm_projects_proglangs" ("project_id" INTEGER NOT NULL, "language_id" INTEGER NOT NULL, "priority" INTEGER NOT NULL DEFAULT 0, FOREIGN KEY("project_id") REFERENCES "fm_projects"("project_id") ON UPDATE CASCADE ON DELETE CASCADE, FOREIGN KEY("language_id") REFERENCES "fm_proglangs"("language_id") ON UPDATE CASCADE ON DELETE CASCADE, PRIMARY KEY("project_id","language_id"));');
// indices
$sqlite->exec('CREATE INDEX "blog_posts_user_foreign" ON "fm_blog_posts" ("user_id");');
$sqlite->exec('CREATE INDEX "post_published" ON "fm_blog_posts" ("post_published");');
$sqlite->exec('CREATE INDEX "post_safe" ON "fm_blog_posts" ("post_safe");');
$sqlite->exec('CREATE UNIQUE INDEX "blog_tags_slug_unique" ON "fm_blog_tags" ("tag_slug");');
$sqlite->exec('CREATE UNIQUE INDEX "blog_post_tag_unique" ON "fm_blog_posts_tags" ("post_id", "tag_id");');
$sqlite->exec('CREATE INDEX "blog_post_tag_foreign" ON "fm_blog_posts_tags" ("tag_id");');
$sqlite->exec('CREATE UNIQUE INDEX "blog_wordpress_post_foreign" ON "fm_blog_wordpress" ("post_id");');
$sqlite->exec('CREATE UNIQUE INDEX "blog_wordpress_id_unique" ON "fm_blog_wordpress" ("wordpress_id");');
$sqlite->exec('CREATE UNIQUE INDEX "blog_wordpress_name_unique" ON "fm_blog_wordpress" ("wordpress_name");');
$sqlite->exec('CREATE UNIQUE INDEX "language_name" ON "fm_proglangs" ("language_name");');
$sqlite->exec('CREATE UNIQUE INDEX "project_name" ON "fm_projects" ("project_name");');
$sqlite->exec('CREATE UNIQUE INDEX "project_name_clean" ON "fm_projects" ("project_name_clean");');
$sqlite->exec('CREATE INDEX "project_order" ON "fm_projects" ("project_order");');
$sqlite->exec('CREATE INDEX "project_type" ON "fm_projects" ("project_type");');
$sqlite->exec('CREATE INDEX "project_archived" ON "fm_projects" ("project_archived");');
$sqlite->exec('CREATE INDEX "project_deleted" ON "fm_projects" ("project_deleted");');
$sqlite->exec('CREATE INDEX "project_created" ON "fm_projects" ("project_created");');
$sqlite->exec('CREATE INDEX "project_featured" ON "fm_projects" ("project_featured");');
$sqlite->exec('CREATE UNIQUE INDEX "projects_proglangs_unique" ON "fm_projects_proglangs" ("project_id", "language_id");');
$sqlite->exec('CREATE INDEX "projects_proglangs_language_foreign" ON "fm_projects_proglangs" ("language_id");');
$sqlite->exec('CREATE INDEX "projects_proglangs_priority_index" ON "fm_projects_proglangs" ("priority");');
$rows = $pdo->query('SELECT *, UNIX_TIMESTAMP(`post_created`) AS `post_created`, UNIX_TIMESTAMP(`post_published`) AS `post_published`, UNIX_TIMESTAMP(`post_deleted`) AS `post_deleted` FROM `fm_blog_posts`')->fetchAll(PDO::FETCH_OBJ);
$insert = $sqlite->prepare('INSERT INTO `fm_blog_posts` (`post_id`, `user_id`, `post_created`, `post_published`, `post_updated`, `post_deleted`, `post_safe`, `post_title`, `post_text`, `post_new_url`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
foreach($rows as $row) {
$insert->bindValue(1, $row->post_id);
$insert->bindValue(2, $row->user_id);
$insert->bindValue(3, $row->post_created);
$insert->bindValue(4, $row->post_published);
$insert->bindValue(5, $row->post_updated);
$insert->bindValue(6, $row->post_deleted);
$insert->bindValue(7, $row->post_safe);
$insert->bindValue(8, $row->post_title);
$insert->bindValue(9, $row->post_text);
$insert->bindValue(10, $row->post_new_url);
$insert->execute();
}
$rows = $pdo->query('SELECT *, UNIX_TIMESTAMP(`tag_created`) AS `tag_created` FROM `fm_blog_tags`')->fetchAll(PDO::FETCH_OBJ);
$insert = $sqlite->prepare('INSERT INTO `fm_blog_tags` (`tag_id`, `tag_name`, `tag_slug`, `tag_description`, `tag_created`) VALUES (?, ?, ?, ?, ?)');
foreach($rows as $row) {
$insert->bindValue(1, $row->tag_id);
$insert->bindValue(2, $row->tag_name);
$insert->bindValue(3, $row->tag_slug);
$insert->bindValue(4, $row->tag_description);
$insert->bindValue(5, $row->tag_created);
$insert->execute();
}
$rows = $pdo->query('SELECT * FROM `fm_blog_posts_tags`')->fetchAll(PDO::FETCH_OBJ);
$insert = $sqlite->prepare('INSERT INTO `fm_blog_posts_tags` (`post_id`, `tag_id`) VALUES (?, ?)');
foreach($rows as $row) {
$insert->bindValue(1, $row->post_id);
$insert->bindValue(2, $row->tag_id);
$insert->execute();
}
$rows = $pdo->query('SELECT * FROM `fm_blog_wordpress`')->fetchAll(PDO::FETCH_OBJ);
$insert = $sqlite->prepare('INSERT INTO `fm_blog_wordpress` (`post_id`, `wordpress_id`, `wordpress_name`) VALUES (?, ?, ?)');
foreach($rows as $row) {
$insert->bindValue(1, $row->post_id);
$insert->bindValue(2, $row->wordpress_id);
$insert->bindValue(3, $row->wordpress_name);
$insert->execute();
}
$rows = $pdo->query('SELECT * FROM `fm_proglangs`')->fetchAll(PDO::FETCH_OBJ);
$insert = $sqlite->prepare('INSERT INTO `fm_proglangs` (`language_id`, `language_name`, `language_colour`) VALUES (?, ?, ?)');
foreach($rows as $row) {
$insert->bindValue(1, $row->language_id);
$insert->bindValue(2, $row->language_name);
$insert->bindValue(3, $row->language_colour);
$insert->execute();
}
$rows = $pdo->query('SELECT *, UNIX_TIMESTAMP(`project_created`) AS `project_created`, UNIX_TIMESTAMP(`project_archived`) AS `project_archived`, UNIX_TIMESTAMP(`project_deleted`) AS `project_deleted` FROM `fm_projects`')->fetchAll(PDO::FETCH_OBJ);
$insert = $sqlite->prepare('INSERT INTO `fm_projects` (`project_id`, `project_name`, `project_name_clean`, `project_summary`, `project_description`, `project_order`, `project_type`, `project_featured`, `project_colour`, `project_homepage`, `project_repository`, `project_forum`, `project_created`, `project_deleted`, `project_archived`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
foreach($rows as $row) {
$insert->bindValue(1, $row->project_id);
$insert->bindValue(2, $row->project_name);
$insert->bindValue(3, $row->project_name_clean);
$insert->bindValue(4, $row->project_summary);
$insert->bindValue(5, $row->project_description);
$insert->bindValue(6, $row->project_order);
$insert->bindValue(7, $row->project_type);
$insert->bindValue(8, $row->project_featured);
$insert->bindValue(9, $row->project_colour);
$insert->bindValue(10, $row->project_homepage);
$insert->bindValue(11, $row->project_repository);
$insert->bindValue(12, $row->project_forum);
$insert->bindValue(13, $row->project_created);
$insert->bindValue(14, $row->project_deleted);
$insert->bindValue(15, $row->project_archived);
$insert->execute();
}
$rows = $pdo->query('SELECT * FROM `fm_projects_proglangs`')->fetchAll(PDO::FETCH_OBJ);
$insert = $sqlite->prepare('INSERT INTO `fm_projects_proglangs` (`project_id`, `language_id`, `priority`) VALUES (?, ?, ?)');
foreach($rows as $row) {
$insert->bindValue(1, $row->project_id);
$insert->bindValue(2, $row->language_id);
$insert->bindValue(3, $row->priority);
$insert->execute();
}
$sqlite->close();
header('Content-Type: application/vnd.sqlite3');
header('Content-Disposition: attachment; filename="v4.db"');
echo file_get_contents($dbName);

View file

@ -10,13 +10,11 @@ require_once __DIR__ . '/../makai.php';
define('FM_NAV', [ define('FM_NAV', [
['title' => 'Home', 'link' => '/'], ['title' => 'Home', 'link' => '/'],
//['title' => 'Blog', 'link' => '//blog.flash.moe'],
['title' => 'Blog', 'link' => '/old-blog'], ['title' => 'Blog', 'link' => '/old-blog'],
['title' => 'Projects', 'link' => '/projects'], ['title' => 'Projects', 'link' => '/projects'],
['title' => 'Contact', 'link' => '/contact'], ['title' => 'Contact', 'link' => '/contact'],
['title' => 'Related', 'link' => '/related'], ['title' => 'Related', 'link' => '/related'],
['title' => 'Etcetera', 'link' => '/etc'], ['title' => 'Etcetera', 'link' => '/etc'],
//['title' => 'Forum', 'link' => '//forum.flash.moe'],
]); ]);
define('FM_BGS', [ define('FM_BGS', [
@ -181,6 +179,7 @@ require_once MKI_DIR_PAGES . '/etcetera.php';
require_once MKI_DIR_PAGES . '/index.php'; require_once MKI_DIR_PAGES . '/index.php';
require_once MKI_DIR_PAGES . '/projects.php'; require_once MKI_DIR_PAGES . '/projects.php';
require_once MKI_DIR_PAGES . '/related.php'; require_once MKI_DIR_PAGES . '/related.php';
require_once MKI_DIR_PAGES . '/ssh.php';
header('X-Powered-By: Makai'); header('X-Powered-By: Makai');
@ -222,7 +221,6 @@ if($result !== null && !is_bool($result)) {
'raw_html' => $result, 'raw_html' => $result,
]); ]);
} else { } else {
header('Content-Type: text/plain; charset=us-ascii');
echo $result; echo $result;
} }
} }

View file

@ -1,3 +1,2 @@
<?php <?php
chdir('/www/now.flash.moe/public'); require_once __DIR__ . '/index.php';
require_once 'get-xml.php';

View file

@ -1,37 +1,2 @@
<?php <?php
require_once __DIR__ . '/_v4/includes.php'; require_once __DIR__ . '/index.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 ORDER BY `key_level` DESC, `key_id`');
$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";
}
}

View file

@ -1,5 +0,0 @@
{
"require": {
"flashwave/whois-php": "~1.0"
}
}

View file

@ -1,63 +0,0 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "3c3da6e044e59ea408eedaa45634f081",
"packages": [
{
"name": "flashwave/whois-php",
"version": "v1.0.3.3",
"source": {
"type": "git",
"url": "https://github.com/flashwave/whois-php.git",
"reference": "0eae1b4c863f8cfaee88bf3abdf2dd6d3d490bf8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/flashwave/whois-php/zipball/0eae1b4c863f8cfaee88bf3abdf2dd6d3d490bf8",
"reference": "0eae1b4c863f8cfaee88bf3abdf2dd6d3d490bf8",
"shasum": ""
},
"require": {
"php": ">=5.6"
},
"require-dev": {
"phpunit/phpunit": "5.5.*"
},
"type": "library",
"autoload": {
"psr-4": {
"Whois\\": "src/Whois/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Julian van de Groep",
"email": "me@flash.moe",
"homepage": "https://flash.moe"
}
],
"description": "Whois client library for PHP",
"keywords": [
"flashwave",
"php",
"whois"
],
"time": "2017-11-20T18:54:50+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": []
}

View file

@ -1,6 +1,13 @@
<?php <?php
require_once __DIR__ . '/vendor/autoload.php'; ini_set('display_errors', 'on');
require_once __DIR__ . '/../_v4/includes.php'; error_reporting(-1);
require_once __DIR__ . '/whois-php/src/Whois/WhoisException.php';
require_once __DIR__ . '/whois-php/src/Whois/Servers.php';
require_once __DIR__ . '/whois-php/src/Whois/Result.php';
require_once __DIR__ . '/whois-php/src/Whois/Client.php';
define('FMWHOIS_PREFIX', 'fm:whois:domain:');
$domain = isset($_GET['domain']) && is_string($_GET['domain']) $domain = isset($_GET['domain']) && is_string($_GET['domain'])
? idn_to_ascii(mb_strtolower($_GET['domain']), IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46) ? idn_to_ascii(mb_strtolower($_GET['domain']), IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46)
@ -8,23 +15,22 @@ $domain = isset($_GET['domain']) && is_string($_GET['domain'])
$domainHash = hash('sha256', $domain); $domainHash = hash('sha256', $domain);
if(!empty($domain)) { if(!empty($domain)) {
$getDomain = $pdo->prepare('SELECT `whois_result` FROM `fm_whois` WHERE `whois_hash` = :hash'); $redis = new Redis;
$getDomain->bindValue('hash', $domainHash); $redis->connect('/var/run/redis/redis-server.sock');
$result = $getDomain->execute() ? json_decode($getDomain->fetchColumn()) : null;
if($result === null) { $result = $redis->get(FMWHOIS_PREFIX . $domainHash);
if($result === false) {
$whois = new Whois\Client; $whois = new Whois\Client;
try { try {
$result = $whois->lookup($domain); $result = $whois->lookup($domain);
$redis->setEx(FMWHOIS_PREFIX . $domainHash, 1800, json_encode($result));
$setDomain = $pdo->prepare('REPLACE INTO `fm_whois` (`whois_hash`, `whois_result`) VALUES (:hash, :result)');
$setDomain->bindValue('hash', $domainHash);
$setDomain->bindValue('result', json_encode($result));
$setDomain->execute();
} catch (Whois\WhoisException $ex) { } catch (Whois\WhoisException $ex) {
$error = $ex->getMessage(); $error = $ex->getMessage();
} }
} else {
$result = json_decode($result);
} }
} }

@ -0,0 +1 @@
Subproject commit d07187e7a8010308e8513aee30e8dd7bee2bd73d

View file

@ -5,12 +5,12 @@ use Index\AString;
use Index\WString; use Index\WString;
class LanguageInfo { class LanguageInfo {
private AString $id; private string $id;
private WString $name; private WString $name;
private ?int $colour; private ?int $colour;
public function __construct( public function __construct(
AString $id, string $id,
WString $name, WString $name,
?int $colour ?int $colour
) { ) {
@ -19,7 +19,7 @@ class LanguageInfo {
$this->colour = $colour; $this->colour = $colour;
} }
public function getId(): AString { public function getId(): string {
return $this->id; return $this->id;
} }

View file

@ -45,7 +45,7 @@ class Languages {
private static function createObject(IDatabaseResult $result): LanguageInfo { private static function createObject(IDatabaseResult $result): LanguageInfo {
return new LanguageInfo( return new LanguageInfo(
$result->getAString(0), // id $result->getString(0), // id
$result->getWString(1, 'utf-8'), // name $result->getWString(1, 'utf-8'), // name
$result->isNull(2) ? null : $result->getInteger(2) // colour $result->isNull(2) ? null : $result->getInteger(2) // colour
); );

View file

@ -5,7 +5,7 @@ use Index\Data\IDatabaseConnection;
use Index\Data\IDatabaseResult; use Index\Data\IDatabaseResult;
class Projects { class Projects {
private const QUERY = 'SELECT `project_id`, `project_name`, COALESCE(`project_name_clean`, REPLACE(LOWER(`project_name`), \' \', \'-\')) AS `project_name_clean`, `project_summary`, `project_description`, `project_featured`, `project_order`, `project_homepage`, `project_repository`, `project_forum`, UNIX_TIMESTAMP(`project_archived`) AS `project_archived`, `project_type`, UNIX_TIMESTAMP(`project_created`) AS `project_created`, `project_colour` FROM `fm_projects` WHERE `project_deleted` IS NULL'; private const QUERY = 'SELECT `project_id`, `project_name`, COALESCE(`project_name_clean`, REPLACE(LOWER(`project_name`), \' \', \'-\')), `project_summary`, `project_description`, `project_featured`, `project_order`, `project_homepage`, `project_repository`, `project_forum`, UNIX_TIMESTAMP(`project_archived`), `project_type`, UNIX_TIMESTAMP(`project_created`), `project_colour` FROM `fm_projects` WHERE `project_deleted` IS NULL';
private const QUERY_ALL = self::QUERY . ' ORDER BY `project_order` DESC'; private const QUERY_ALL = self::QUERY . ' ORDER BY `project_order` DESC';
private const QUERY_FEATURED = self::QUERY . ' AND `project_featured` <> 0 ORDER BY RAND() LIMIT 3'; private const QUERY_FEATURED = self::QUERY . ' AND `project_featured` <> 0 ORDER BY RAND() LIMIT 3';

76
src/SSHKeyInfo.php Normal file
View file

@ -0,0 +1,76 @@
<?php
namespace Makai;
use Index\AString;
use Index\DateTime;
class SSHKeyInfo {
private string $id;
private int $level;
private string $algo;
private string $body;
private AString $comment;
private DateTime $createdAt;
private ?DateTime $deprecatedAt;
public function __construct(
string $id,
int $level,
string $algo,
string $body,
AString $comment,
int $createdAt,
?int $deprecatedAt
) {
$this->id = $id;
$this->level = $level;
$this->algo = $algo;
$this->body = $body;
$this->comment = $comment;
$this->createdAt = DateTime::fromUnixTimeSeconds($createdAt);
$this->deprecatedAt = $deprecatedAt === null ? null : DateTime::fromUnixTimeSeconds($deprecatedAt);
}
public function getId(): string {
return $this->id;
}
public function getLevel(): int {
return $this->level;
}
public function getAlgorithm(): string {
return $this->algo;
}
public function getBody(): string {
return $this->body;
}
public function getComment(): AString {
return $this->comment;
}
public function getCreatedAt(): DateTime {
return $this->createdAt;
}
public function isDeprecated(): bool {
return $this->deprecatedAt !== null;
}
public function getDeprecatedAt(): ?DateTime {
return $this->deprecatedAt;
}
public function toString(bool $includeComment): string {
$line = sprintf('ssh-%s %s', $this->getAlgorithm(), $this->getBody());
if($includeComment)
$line .= sprintf(' %s (%s)', (string)$this->getComment(), $this->getCreatedAt()->format('M Y'));
return $line;
}
public function __toString(): string {
return $this->toString(true);
}
}

48
src/SSHKeys.php Normal file
View file

@ -0,0 +1,48 @@
<?php
namespace Makai;
use Index\Data\DbType;
use Index\Data\IDatabaseConnection;
use Index\Data\IDatabaseResult;
class SSHKeys {
private const QUERY = 'SELECT `key_id`, `key_level`, `key_algo`, `key_body`, `key_comment`, UNIX_TIMESTAMP(`key_created`), UNIX_TIMESTAMP(`key_deprecated`) FROM `fm_public_keys` WHERE `key_level` >= ?';
private IDatabaseConnection $conn;
public function __construct(IDatabaseConnection $conn) {
$this->conn = $conn;
}
public function getKeys(int $minLevel, bool $includeDeprecated = false): array {
$query = self::QUERY;
if(!$includeDeprecated)
$query .= ' AND `key_deprecated` IS NULL';
$query .= ' ORDER BY `key_level` DESC, `key_id`';
$stmt = $this->conn->prepare($query);
$stmt->addParameter(1, $minLevel, DbType::INTEGER);
$stmt->execute();
$result = $stmt->getResult();
$objs = [];
while($result->next())
$objs[] = self::createObject($result);
return $objs;
}
private static function createObject(IDatabaseResult $result): SSHKeyInfo {
return new SSHKeyInfo(
$result->getString(0),
$result->getInteger(1),
$result->getString(2),
$result->getString(3),
$result->getAString(4),
$result->getInteger(5),
$result->isNull(6) ? null : $result->getInteger(6),
);
}
}