diff --git a/.gitignore b/.gitignore
index 488056e..1fdc85d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@
.DS_Store
[Dd]esktop.ini
/.debug
+/config/*.ini
diff --git a/.gitmodules b/.gitmodules
index 19f950d..e0c1374 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +1,6 @@
[submodule "lib/index"]
path = lib/index
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
diff --git a/makai.php b/makai.php
index 516f51a..8568cc3 100644
--- a/makai.php
+++ b/makai.php
@@ -1,10 +1,13 @@
createConnection(MariaDBConnectionInfo::create(
- 'unix:/var/run/mysqld/mysqld.sock',
- 'website',
- 'A3NjVvHRkHAxiYgk8MM4ZrCwrLVyPIYX',
- 'website',
- '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\'',
- ));
-} catch(ConnectionFailedException $ex) {
- echo '
Unable to connect to database
';
- die($ex->getMessage());
+ $dbConfig = parse_ini_file(MKI_DIR_CONFIG . DIRECTORY_SEPARATOR . 'database.ini');
+} catch(ErrorException $ex) {
+ $dbConfig = null;
}
+
+if(!empty($dbConfig))
+ try {
+ $db = (new MariaDBBackend)->createConnection(MariaDBConnectionInfo::create(
+ $dbConfig['host'] ?? '',
+ $dbConfig['user'] ?? '',
+ $dbConfig['pass'] ?? '',
+ $dbConfig['name'] ?? '',
+ $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\'',
+ ));
+ } catch(ConnectionFailedException $ex) {
+ //echo 'Unable to connect to database
';
+ //die($ex->getMessage());
+ }
+
+if(empty($db))
+ $db = (new NullDbBackend)->createConnection(new NullDbConnectionInfo);
diff --git a/pages/index.php b/pages/index.php
index 60d80dc..75fa8d8 100644
--- a/pages/index.php
+++ b/pages/index.php
@@ -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() {
$body = fm_component('header', [
'title' => 'flash.moe / homepage',
diff --git a/pages/ssh.php b/pages/ssh.php
new file mode 100644
index 0000000..35f4b6a
--- /dev/null
+++ b/pages/ssh.php
@@ -0,0 +1,92 @@
+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;
+});
diff --git a/public/_v4/includes.php b/public/_v4/includes.php
deleted file mode 100644
index 1bc3357..0000000
--- a/public/_v4/includes.php
+++ /dev/null
@@ -1,28 +0,0 @@
- 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 'Unable to connect to database
';
- die($ex->getMessage());
-}
diff --git a/public/dumplite/index.php b/public/dumplite/index.php
deleted file mode 100644
index cc70757..0000000
--- a/public/dumplite/index.php
+++ /dev/null
@@ -1,132 +0,0 @@
-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);
diff --git a/public/index.php b/public/index.php
index 1f2ea0d..f37d86f 100644
--- a/public/index.php
+++ b/public/index.php
@@ -10,13 +10,11 @@ require_once __DIR__ . '/../makai.php';
define('FM_NAV', [
['title' => 'Home', 'link' => '/'],
- //['title' => 'Blog', 'link' => '//blog.flash.moe'],
['title' => 'Blog', 'link' => '/old-blog'],
['title' => 'Projects', 'link' => '/projects'],
['title' => 'Contact', 'link' => '/contact'],
['title' => 'Related', 'link' => '/related'],
['title' => 'Etcetera', 'link' => '/etc'],
- //['title' => 'Forum', 'link' => '//forum.flash.moe'],
]);
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 . '/projects.php';
require_once MKI_DIR_PAGES . '/related.php';
+require_once MKI_DIR_PAGES . '/ssh.php';
header('X-Powered-By: Makai');
@@ -222,7 +221,6 @@ if($result !== null && !is_bool($result)) {
'raw_html' => $result,
]);
} else {
- header('Content-Type: text/plain; charset=us-ascii');
echo $result;
}
}
diff --git a/public/np.php b/public/np.php
index d274b49..41cc616 100644
--- a/public/np.php
+++ b/public/np.php
@@ -1,3 +1,2 @@
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";
- }
-}
+require_once __DIR__ . '/index.php';
diff --git a/public/whois/composer.json b/public/whois/composer.json
deleted file mode 100644
index 00f5a79..0000000
--- a/public/whois/composer.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "require": {
- "flashwave/whois-php": "~1.0"
- }
-}
diff --git a/public/whois/composer.lock b/public/whois/composer.lock
deleted file mode 100644
index 518ba7d..0000000
--- a/public/whois/composer.lock
+++ /dev/null
@@ -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": []
-}
diff --git a/public/whois/index.php b/public/whois/index.php
index 98de138..782bb50 100644
--- a/public/whois/index.php
+++ b/public/whois/index.php
@@ -1,6 +1,13 @@
prepare('SELECT `whois_result` FROM `fm_whois` WHERE `whois_hash` = :hash');
- $getDomain->bindValue('hash', $domainHash);
- $result = $getDomain->execute() ? json_decode($getDomain->fetchColumn()) : null;
+ $redis = new Redis;
+ $redis->connect('/var/run/redis/redis-server.sock');
- if($result === null) {
+ $result = $redis->get(FMWHOIS_PREFIX . $domainHash);
+
+ if($result === false) {
$whois = new Whois\Client;
try {
$result = $whois->lookup($domain);
-
- $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();
+ $redis->setEx(FMWHOIS_PREFIX . $domainHash, 1800, json_encode($result));
} catch (Whois\WhoisException $ex) {
$error = $ex->getMessage();
}
+ } else {
+ $result = json_decode($result);
}
}
diff --git a/public/whois/whois-php b/public/whois/whois-php
new file mode 160000
index 0000000..d07187e
--- /dev/null
+++ b/public/whois/whois-php
@@ -0,0 +1 @@
+Subproject commit d07187e7a8010308e8513aee30e8dd7bee2bd73d
diff --git a/src/LanguageInfo.php b/src/LanguageInfo.php
index eeefc3a..491bcd6 100644
--- a/src/LanguageInfo.php
+++ b/src/LanguageInfo.php
@@ -5,12 +5,12 @@ use Index\AString;
use Index\WString;
class LanguageInfo {
- private AString $id;
+ private string $id;
private WString $name;
private ?int $colour;
public function __construct(
- AString $id,
+ string $id,
WString $name,
?int $colour
) {
@@ -19,7 +19,7 @@ class LanguageInfo {
$this->colour = $colour;
}
- public function getId(): AString {
+ public function getId(): string {
return $this->id;
}
diff --git a/src/Languages.php b/src/Languages.php
index 34b7409..c15c7c7 100644
--- a/src/Languages.php
+++ b/src/Languages.php
@@ -45,7 +45,7 @@ class Languages {
private static function createObject(IDatabaseResult $result): LanguageInfo {
return new LanguageInfo(
- $result->getAString(0), // id
+ $result->getString(0), // id
$result->getWString(1, 'utf-8'), // name
$result->isNull(2) ? null : $result->getInteger(2) // colour
);
diff --git a/src/Projects.php b/src/Projects.php
index a89fa78..876a03f 100644
--- a/src/Projects.php
+++ b/src/Projects.php
@@ -5,7 +5,7 @@ use Index\Data\IDatabaseConnection;
use Index\Data\IDatabaseResult;
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_FEATURED = self::QUERY . ' AND `project_featured` <> 0 ORDER BY RAND() LIMIT 3';
diff --git a/src/SSHKeyInfo.php b/src/SSHKeyInfo.php
new file mode 100644
index 0000000..d3ed2bb
--- /dev/null
+++ b/src/SSHKeyInfo.php
@@ -0,0 +1,76 @@
+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);
+ }
+}
diff --git a/src/SSHKeys.php b/src/SSHKeys.php
new file mode 100644
index 0000000..3c6a283
--- /dev/null
+++ b/src/SSHKeys.php
@@ -0,0 +1,48 @@
+= ?';
+
+ 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),
+ );
+ }
+}