Switched to a tools directory for commands.
This commit is contained in:
parent
9cb0a04611
commit
69d04a7929
46 changed files with 699 additions and 1300 deletions
7
Vagrantfile
vendored
7
Vagrantfile
vendored
|
@ -1,7 +0,0 @@
|
|||
Vagrant.configure("2") do |config|
|
||||
config.vm.box = "ubuntu/focal64"
|
||||
config.vm.network "forwarded_port", guest: 80, host: 10080
|
||||
config.vm.network "forwarded_port", guest: 443, host: 10443
|
||||
config.vm.network "forwarded_port", guest: 3306, host: 13306
|
||||
config.vm.provision :shell, path: "devel/setup-devbox.sh"
|
||||
end
|
|
@ -14,8 +14,8 @@
|
|||
},
|
||||
"scripts": {
|
||||
"post-install-cmd": [
|
||||
"php misuzu.php migrate",
|
||||
"php misuzu.php cron low"
|
||||
"./tools/migrate",
|
||||
"./tools/cron slow"
|
||||
]
|
||||
},
|
||||
"config": {
|
||||
|
|
|
@ -1,482 +0,0 @@
|
|||
<?php
|
||||
// Rewrite this script when everything has proper objects associated with it and use those objects
|
||||
|
||||
require_once __DIR__ . '/../misuzu.php';
|
||||
|
||||
if(!MSZ_DEBUG)
|
||||
die('Not running in debug mode. Are you sure you want to run this?' . PHP_EOL);
|
||||
|
||||
require_once __DIR__ . '/sample/MarkovDictionary.php';
|
||||
|
||||
define('MKV_DICTS', __DIR__ . '/sample/dicts');
|
||||
define('MKV_PASSWD', '123456');
|
||||
define('MKV_MAIL', 'msz-%d@flash.moe');
|
||||
define('MKV_ALPHA', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ');
|
||||
define('MKV_ALPHA_LEN', strlen(MKV_ALPHA));
|
||||
|
||||
function mkv_log(string $string): void {
|
||||
printf('[%s] %s%s', date('H:i:s'), $string, PHP_EOL);
|
||||
}
|
||||
|
||||
mkv_log('Filling database with markov data...');
|
||||
|
||||
mkv_log('Yoinked Database instance from Misuzu...');
|
||||
$db = \Misuzu\DB::getInstance();
|
||||
|
||||
mkv_log('Opening role dictionaries...');
|
||||
$roleNames = new MarkovDictionary(MKV_DICTS . '/roles_names.fmk');
|
||||
$roleDescs = new MarkovDictionary(MKV_DICTS . '/roles_descs.fmk');
|
||||
$roleTitles = new MarkovDictionary(MKV_DICTS . '/roles_titles.fmk');
|
||||
|
||||
mkv_log('Nuking roles table...');
|
||||
$db->exec('DELETE FROM `msz_roles` WHERE `role_id` > 1');
|
||||
$db->exec('ALTER TABLE `msz_roles` AUTO_INCREMENT = 2');
|
||||
|
||||
mkv_log('Running slow cron to ensure main role exists...');
|
||||
|
||||
// running cron before fuckery
|
||||
(new \Misuzu\Console\Commands\CronCommand)->dispatch(
|
||||
new \Misuzu\Console\CommandArgs(['--slow'])
|
||||
);
|
||||
|
||||
mkv_log('Preparing role and permissions insert statements...');
|
||||
$cr = $db->prepare('INSERT INTO `msz_roles` (`role_hierarchy`, `role_name`, `role_title`, `role_description`, `role_hidden`, `role_can_leave`, `role_colour`) VALUES (:rank, :name, :title, :desc, :hide, :leave, :colour)');
|
||||
$cp = $db->prepare('REPLACE INTO `msz_permissions` (`role_id`, `general_perms_allow`, `user_perms_allow`, `changelog_perms_allow`, `news_perms_allow`, `forum_perms_allow`, `comments_perms_allow`) VALUES (:role, :general, :user, :changelog, :news, :forum, :comments)');
|
||||
|
||||
mkv_log('Adding permissions for main role...');
|
||||
$cp->bind('role', 1);
|
||||
$cp->bind('general', 0);
|
||||
$cp->bind('user', 59);
|
||||
$cp->bind('changelog', 0);
|
||||
$cp->bind('news', 0);
|
||||
$cp->bind('forum', 0);
|
||||
$cp->bind('comments', 137);
|
||||
$cp->execute();
|
||||
|
||||
mkv_log('Creating Global Moderator role...');
|
||||
$cr->bind('rank', 5);
|
||||
$cr->bind('name', 'Global Moderator');
|
||||
$cr->bind('title', 'Moderator');
|
||||
$cr->bind('desc', 'They are global and in moderation.');
|
||||
$cr->bind('hide', 0);
|
||||
$cr->bind('leave', 0);
|
||||
$cr->bind('colour', 1693465);
|
||||
$cr->execute();
|
||||
|
||||
mkv_log('Adding permissions for Global Moderator...');
|
||||
$cp->bind('role', $rIdMod = $db->lastId());
|
||||
$cp->bind('general', 3);
|
||||
$cp->bind('user', 25165887);
|
||||
$cp->bind('changelog', 0);
|
||||
$cp->bind('news', 0);
|
||||
$cp->bind('forum', 0);
|
||||
$cp->bind('comments', 57);
|
||||
$cp->execute();
|
||||
|
||||
mkv_log('Creating Administrator role...');
|
||||
$cr->bind('rank', 10);
|
||||
$cr->bind('name', 'Administrator');
|
||||
$cr->bind('title', 'Administrator');
|
||||
$cr->bind('desc', 'Administration nation.');
|
||||
$cr->bind('hide', 0);
|
||||
$cr->bind('leave', 0);
|
||||
$cr->bind('colour', 16711680);
|
||||
$cr->execute();
|
||||
|
||||
mkv_log('Adding permissions for Administrator...');
|
||||
$cp->bind('role', $rIdAdm = $db->lastId());
|
||||
$cp->bind('general', 39);
|
||||
$cp->bind('user', 28311615);
|
||||
$cp->bind('changelog', 3);
|
||||
$cp->bind('news', 3);
|
||||
$cp->bind('forum', 3);
|
||||
$cp->bind('comments', 249);
|
||||
$cp->execute();
|
||||
|
||||
mkv_log('Creating Bot role...');
|
||||
$cr->bind('rank', 7);
|
||||
$cr->bind('name', 'Bot');
|
||||
$cr->bind('title', null);
|
||||
$cr->bind('desc', 'Service users.');
|
||||
$cr->bind('hide', 0);
|
||||
$cr->bind('leave', 0);
|
||||
$cr->bind('colour', 10390951);
|
||||
$cr->execute();
|
||||
|
||||
$rIdBot = $db->lastId();
|
||||
|
||||
mkv_log('Creating Tester role...');
|
||||
$cr->bind('rank', 1);
|
||||
$cr->bind('name', 'Tester');
|
||||
$cr->bind('title', null);
|
||||
$cr->bind('desc', 'Experimentalists.');
|
||||
$cr->bind('hide', 1);
|
||||
$cr->bind('leave', 1);
|
||||
$cr->bind('colour', 1073741824);
|
||||
$cr->execute();
|
||||
|
||||
mkv_log('Adding permissions for Tester...');
|
||||
$cp->bind('role', $rIdTest = $db->lastId());
|
||||
$cp->bind('general', 16);
|
||||
$cp->bind('user', 0);
|
||||
$cp->bind('changelog', 3);
|
||||
$cp->bind('news', 0);
|
||||
$cp->bind('forum', 0);
|
||||
$cp->bind('comments', 0);
|
||||
$cp->execute();
|
||||
|
||||
mkv_log('Creating OG role...');
|
||||
$cr->bind('rank', 1);
|
||||
$cr->bind('name', 'OG');
|
||||
$cr->bind('title', null);
|
||||
$cr->bind('desc', 'Arbitrarily selected people that joined in 2013 and 2014.');
|
||||
$cr->bind('hide', 0);
|
||||
$cr->bind('leave', 0);
|
||||
$cr->bind('colour', 15740285);
|
||||
$cr->execute();
|
||||
|
||||
mkv_log('Creating Developer role...');
|
||||
$cr->bind('rank', 5);
|
||||
$cr->bind('name', 'Developer');
|
||||
$cr->bind('title', 'Developer');
|
||||
$cr->bind('desc', 'Moderators but without the requirement to moderate.');
|
||||
$cr->bind('hide', 0);
|
||||
$cr->bind('leave', 0);
|
||||
$cr->bind('colour', 7558084);
|
||||
$cr->execute();
|
||||
|
||||
mkv_log('Adding permissions for Developer...');
|
||||
$cp->bind('role', $rIdDev = $db->lastId());
|
||||
$cp->bind('general', 3);
|
||||
$cp->bind('user', 25165887);
|
||||
$cp->bind('changelog', 3);
|
||||
$cp->bind('news', 0);
|
||||
$cp->bind('forum', 0);
|
||||
$cp->bind('comments', 57);
|
||||
$cp->execute();
|
||||
|
||||
mkv_log('Creating Tenshi role...');
|
||||
$cr->bind('rank', 1);
|
||||
$cr->bind('name', 'Tenshi');
|
||||
$cr->bind('title', 'Supporter');
|
||||
$cr->bind('desc', 'Donators');
|
||||
$cr->bind('hide', 0);
|
||||
$cr->bind('leave', 0);
|
||||
$cr->bind('colour', 15635456);
|
||||
$cr->execute();
|
||||
|
||||
mkv_log('Adding permissions for Tenshi...');
|
||||
$cp->bind('role', $rIdTen = $db->lastId());
|
||||
$cp->bind('general', 0);
|
||||
$cp->bind('user', 4);
|
||||
$cp->bind('changelog', 0);
|
||||
$cp->bind('news', 0);
|
||||
$cp->bind('forum', 0);
|
||||
$cp->bind('comments', 0);
|
||||
$cp->execute();
|
||||
|
||||
for($i = 0; $i < 10; ++$i) {
|
||||
mkv_log('Creating bogus role ' . $i . '...');
|
||||
$cr->bind('rank', mt_rand(1, 4));
|
||||
$cr->bind('name', $roleNames->generate());
|
||||
$cr->bind('title', (mt_rand(0, 100) > 50) ? $roleTitles->generate() : null);
|
||||
$cr->bind('desc', (mt_rand(0, 100) > 10) ? $roleDescs->generate() : null);
|
||||
$cr->bind('hide', mt_rand(0, 1));
|
||||
$cr->bind('leave', mt_rand(0, 1));
|
||||
$cr->bind('colour', ((mt_rand(0, 255) << 16) | (mt_rand(0, 255) << 8) | mt_rand(0, 255)));
|
||||
$cr->execute();
|
||||
}
|
||||
|
||||
mkv_log('Opening user related markov dictionaries...');
|
||||
$userNames = new MarkovDictionary(MKV_DICTS . '/users_names.fmk');
|
||||
$userTitles = new MarkovDictionary(MKV_DICTS . '/users_titles.fmk');
|
||||
$userSigs = new MarkovDictionary(MKV_DICTS . '/users_sigs.fmk');
|
||||
$userAbouts = new MarkovDictionary(MKV_DICTS . '/users_abouts.fmk');
|
||||
|
||||
mkv_log('Nuking users table...');
|
||||
$db->exec('DELETE FROM `msz_users`');
|
||||
$db->exec('ALTER TABLE `msz_users` AUTO_INCREMENT = 1');
|
||||
|
||||
mkv_log('Preparing user insert statements...');
|
||||
$cu = $db->prepare('INSERT INTO `msz_users` (`username`, `password`, `email`, `register_ip`, `last_ip`, `user_super`, `user_country`, `user_about_content`, `user_about_parser`, `user_signature_content`, `user_signature_parser`, `user_birthdate`, `user_title`, `display_role`) VALUES (:name, :pass, :mail, :reg_addr, :last_addr, :super, :country, :about_text, :about_parse, :sig_text, :sig_parse, :birth, :title, :role)');
|
||||
|
||||
$ur = $db->prepare('REPLACE INTO `msz_user_roles` (`user_id`, `role_id`) VALUES (:user, :role)');
|
||||
|
||||
mkv_log('Creating admin user...');
|
||||
mkv_log('NOTICE: All passwords will be set to: ' . MKV_PASSWD);
|
||||
mkv_log('NOTICE: E-mail address will follow the format of: ' . MKV_MAIL);
|
||||
$cu->bind('name', 'admin');
|
||||
$cu->bind('pass', password_hash(MKV_PASSWD, PASSWORD_ARGON2ID));
|
||||
$cu->bind('mail', sprintf(MKV_MAIL, 1));
|
||||
$cu->bind('reg_addr', "\x7f\0\0\1");
|
||||
$cu->bind('last_addr', "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1");
|
||||
$cu->bind('super', 1);
|
||||
$cu->bind('country', 'NL');
|
||||
$cu->bind('about_text', '# Default administrator account');
|
||||
$cu->bind('about_parse', 2);
|
||||
$cu->bind('sig_text', '[b]Administrative Signature[/b]');
|
||||
$cu->bind('sig_parse', 1);
|
||||
$cu->bind('birth', '2013-01-27');
|
||||
$cu->bind('title', null);
|
||||
$cu->bind('role', 3);
|
||||
$cu->execute();
|
||||
|
||||
mkv_log('Adding Global Moderator role to admin...');
|
||||
$ur->bind('user', 1);
|
||||
$ur->bind('role', 2);
|
||||
$ur->execute();
|
||||
|
||||
mkv_log('Adding Administrator role to admin...');
|
||||
$ur->bind('user', 1);
|
||||
$ur->bind('role', 3);
|
||||
$ur->execute();
|
||||
|
||||
mkv_log('Adding Developer role to admin...');
|
||||
$ur->bind('user', 1);
|
||||
$ur->bind('role', 8);
|
||||
$ur->execute();
|
||||
|
||||
$cu->bind('super', 0);
|
||||
|
||||
for($i = 1; $i < 2000; ++$i) {
|
||||
mkv_log('Creating bogus user ' . $i . '...');
|
||||
$cu->bind('name', mb_substr($userNames->generate(), 0, 200, 'utf-8') . $i);
|
||||
$cu->bind('pass', password_hash(MKV_PASSWD, PASSWORD_ARGON2ID));
|
||||
$cu->bind('mail', sprintf(MKV_MAIL, ($i + 1)));
|
||||
$cu->bind('reg_addr', random_bytes(mt_rand(0, 1) ? 4 : 16));
|
||||
$cu->bind('last_addr', random_bytes(mt_rand(0, 1) ? 4 : 16));
|
||||
$cu->bind('country', MKV_ALPHA[mt_rand(0, MKV_ALPHA_LEN - 1)] . MKV_ALPHA[mt_rand(0, MKV_ALPHA_LEN - 1)]);
|
||||
$cu->bind('about_text', mb_substr($userAbouts->generate(), 0, 60000, 'utf-8'));
|
||||
$cu->bind('about_parse', mt_rand(0, 2));
|
||||
$cu->bind('sig_text', mb_substr($userSigs->generate(), 0, 1000, 'utf-8'));
|
||||
$cu->bind('sig_parse', mt_rand(0, 2));
|
||||
$cu->bind('birth', date('Y-m-d', mt_rand(1, 0x7FFFFFFF)));
|
||||
$cu->bind('title', mt_rand(0, 100) > 90 ? mb_substr($userTitles->generate(), 0, 64, 'utf-8') : null);
|
||||
$cu->bind('role', mt_rand(9, 18));
|
||||
$cu->execute();
|
||||
|
||||
$uId = $db->lastId();
|
||||
|
||||
for($j = 0; $j < mt_rand(1, 4); ++$j) {
|
||||
$brid = mt_rand(9, 18);
|
||||
mkv_log('Adding role ' . $brid . ' to bogus user id ' . $uId . '...');
|
||||
$ur->bind('user', $uId);
|
||||
$ur->bind('role', $brid);
|
||||
$ur->execute();
|
||||
}
|
||||
}
|
||||
|
||||
mkv_log('Opening changelog tag markov dictionaries...');
|
||||
$changeTagsNames = new MarkovDictionary(MKV_DICTS . '/changes_tags_names.fmk');
|
||||
$changeTagsDescs = new MarkovDictionary(MKV_DICTS . '/changes_tags_descs.fmk');
|
||||
|
||||
mkv_log('Nuking changelog tags table...');
|
||||
$db->exec('DELETE FROM `msz_changelog_tags`');
|
||||
$db->exec('ALTER TABLE `msz_changelog_tags` AUTO_INCREMENT = 1');
|
||||
|
||||
mkv_log('Preparing changelog insert statements...');
|
||||
$ct = $db->prepare('INSERT INTO `msz_changelog_tags` (`tag_name`, `tag_description`) VALUES (:name, :descr)');
|
||||
$cTagIds = [];
|
||||
|
||||
for($i = 0; $i < 20; ++$i) {
|
||||
mkv_log('Inserting bogus changelog tag...');
|
||||
$ct->bind('name', mb_substr($changeTagsNames->generate(), 0, 200, 'utf-8') . $i);
|
||||
$ct->bind('descr', mb_substr($changeTagsDescs->generate(), 0, 60000, 'utf-8'));
|
||||
$ct->execute();
|
||||
$cTagIds[] = $db->lastId();
|
||||
}
|
||||
|
||||
mkv_log('Opening changelog changes markov dictionaries...');
|
||||
$changeLogs = new MarkovDictionary(MKV_DICTS . '/changes_logs.fmk');
|
||||
$changeTexts = new MarkovDictionary(MKV_DICTS . '/changes_texts.fmk');
|
||||
|
||||
mkv_log('Nuking changelog changes tables...');
|
||||
$db->exec('DELETE FROM `msz_changelog_changes`');
|
||||
$db->exec('ALTER TABLE `msz_changelog_changes` AUTO_INCREMENT = 1');
|
||||
|
||||
mkv_log('Preparing changelog changes statements...');
|
||||
$cc = $db->prepare('INSERT INTO `msz_changelog_changes` (`user_id`, `change_action`, `change_created`, `change_log`, `change_text`) VALUES (:user, :action, FROM_UNIXTIME(:created), :log, :text)');
|
||||
$ctt = $db->prepare('REPLACE INTO `msz_changelog_change_tags` (`change_id`, `tag_id`) VALUES (:change, :tag)');
|
||||
|
||||
$max = mt_rand(1000, 10000);
|
||||
mkv_log('Inserting ' . $max . ' changelog entries...');
|
||||
for($i = 0; $i < $max; ++$i) {
|
||||
mkv_log('Inserting bogus change ' . $i . '...');
|
||||
$userId = mt_rand(-100, 2000);
|
||||
if($userId < 1)
|
||||
$userId = null;
|
||||
$cc->bind('user', $userId);
|
||||
$cc->bind('action', mt_rand(0, 6));
|
||||
$cc->bind('created', mt_rand(1, 0x7FFFFFFF));
|
||||
$cc->bind('log', mb_substr($changeLogs->generate(), 0, 240, 'utf-8'));
|
||||
$cc->bind('text', mt_rand(0, 100) > 90 ? mb_substr($changeTexts->generate(), 0, 60000, 'utf-8') : null);
|
||||
$cc->execute();
|
||||
|
||||
$ctt->bind('change', $db->lastId());
|
||||
|
||||
for($j = 0; $j < mt_rand(1, 5); ++$j) {
|
||||
$btag = $cTagIds[array_rand($cTagIds)];
|
||||
mkv_log('Adding tag ' . $btag . ' to bogus change ' . $i . '...');
|
||||
$ctt->bind('tag', $btag);
|
||||
$ctt->execute();
|
||||
}
|
||||
}
|
||||
|
||||
mkv_log('Opening news category markov dictionaries...');
|
||||
$newsCatsNames = new MarkovDictionary(MKV_DICTS . '/news_cats_names.fmk');
|
||||
$newsCatsDescs = new MarkovDictionary(MKV_DICTS . '/news_cats_descs.fmk');
|
||||
|
||||
mkv_log('Nuking news categories table...');
|
||||
$db->exec('DELETE FROM `msz_news_categories`');
|
||||
$db->exec('ALTER TABLE `msz_news_categories` AUTO_INCREMENT = 1');
|
||||
|
||||
mkv_log('Preparing news categories insert statements...');
|
||||
$nc = $db->prepare('INSERT INTO `msz_news_categories` (`category_name`, `category_description`, `category_is_hidden`) VALUES (:name, :descr, :hidden)');
|
||||
$ncIds = [];
|
||||
|
||||
for($i = 0; $i < 10; ++$i) {
|
||||
mkv_log('Creating bogus news category ' . $i . '...');
|
||||
$nc->bind('name', mb_substr($newsCatsNames->generate(), 0, 200, 'utf-8'));
|
||||
$nc->bind('descr', mb_substr($newsCatsDescs->generate(), 0, 60000, 'utf-8'));
|
||||
$nc->bind('hidden', mt_rand(0, 1));
|
||||
$nc->execute();
|
||||
$ncIds[] = $db->lastId();
|
||||
}
|
||||
|
||||
mkv_log('Opening news post markov dictionaries...');
|
||||
$newsPostsTitles = new MarkovDictionary(MKV_DICTS . '/news_posts_titles.fmk');
|
||||
$newsPostsTexts = new MarkovDictionary(MKV_DICTS . '/news_posts_texts.fmk');
|
||||
|
||||
mkv_log('Nuking news posts table...');
|
||||
$db->exec('DELETE FROM `msz_news_posts`');
|
||||
$db->exec('ALTER TABLE `msz_news_posts` AUTO_INCREMENT = 1');
|
||||
|
||||
mkv_log('Preparing news posts table...');
|
||||
$np = $db->prepare('INSERT INTO `msz_news_posts` (`category_id`, `user_id`, `post_is_featured`, `post_title`, `post_text`) VALUES (:category, :user, :featured, :title, :text)');
|
||||
|
||||
for($i = 0; $i < 200; ++$i) {
|
||||
mkv_log('Creating bogus news post ' . $i . '...');
|
||||
$np->bind('category', $ncIds[array_rand($ncIds)]);
|
||||
$np->bind('user', mt_rand(1, 2000));
|
||||
$np->bind('featured', mt_rand(0, 1));
|
||||
$np->bind('title', mb_substr($newsPostsTitles->generate(), 0, 200, 'utf-8'));
|
||||
$np->bind('text', mb_substr($newsPostsTexts->generate(), 0, 60000, 'utf-8'));
|
||||
$np->execute();
|
||||
}
|
||||
|
||||
mkv_log('Opening forum category markov dictionaries...');
|
||||
$forumCatsNames = new MarkovDictionary(MKV_DICTS . '/forums_cats_names.fmk');
|
||||
$forumCatsDescs = new MarkovDictionary(MKV_DICTS . '/forums_cats_descs.fmk');
|
||||
|
||||
mkv_log('Nuking forum category table...');
|
||||
$db->exec('DELETE FROM `msz_forum_categories`');
|
||||
$db->exec('ALTER TABLE `msz_forum_categories` AUTO_INCREMENT = 1');
|
||||
|
||||
mkv_log('Inserting 5 root categories and permissions...');
|
||||
for($i = 0; $i < 5; ++$i) {
|
||||
mkv_log('Inserting bogus category ' . $i . '...');
|
||||
$ic = $db->prepare('INSERT INTO `msz_forum_categories` (`forum_name`, `forum_type`) VALUES (:name, 1)');
|
||||
$ic->bind('name', mb_substr($forumCatsNames->generate(), 0, 240, 'utf-8'));
|
||||
$ic->execute();
|
||||
|
||||
mkv_log('Inserting permissions for bogus category ' . $i . '...');
|
||||
$ip = $db->prepare('INSERT INTO `msz_forum_permissions` (`forum_id`, `forum_perms_allow`) VALUES (:cat, 3)');
|
||||
$ip->bind('cat', $i + 1);
|
||||
$ip->execute();
|
||||
}
|
||||
|
||||
$categories = mt_rand(20, 40);
|
||||
mkv_log('Inserting ' . $categories . ' forum sections...');
|
||||
|
||||
$catIds = [];
|
||||
for($i = 0; $i < $categories; ++$i) {
|
||||
mkv_log('Inserting bogus forum section ' . $i . '...');
|
||||
$ic = $db->prepare('INSERT INTO `msz_forum_categories` (`forum_name`, `forum_type`, `forum_description`, `forum_parent`) VALUES (:name, 0, :desc, :parent)');
|
||||
$ic->bind('name', mb_substr($forumCatsNames->generate(), 0, 240, 'utf-8'));
|
||||
$ic->bind('desc', mb_substr($forumCatsDescs->generate(), 0, 1200, 'utf-8'));
|
||||
$ic->bind('parent', mt_rand(1, 5));
|
||||
$ic->execute();
|
||||
$catIds[] = $db->lastId();
|
||||
}
|
||||
|
||||
mkv_log('Opening forum topic title markov dictionary...');
|
||||
$forumTopicsTitles = new MarkovDictionary(MKV_DICTS . '/forums_topics_titles.fmk');
|
||||
|
||||
mkv_log('Nuking forum topics table...');
|
||||
$db->exec('DELETE FROM `msz_forum_topics`');
|
||||
$db->exec('ALTER TABLE `msz_forum_topics` AUTO_INCREMENT = 1');
|
||||
|
||||
mkv_log('Preparing forum topic insertion statement...');
|
||||
$ft = $db->prepare('INSERT INTO `msz_forum_topics` (`forum_id`, `user_id`, `topic_type`, `topic_title`, `topic_count_views`, `topic_created`, `topic_bumped`, `topic_deleted`, `topic_locked`) VALUES (:cat, :user, :type, :title, :views, FROM_UNIXTIME(:created), FROM_UNIXTIME(:bumped), FROM_UNIXTIME(:deleted), FROM_UNIXTIME(:locked))');
|
||||
|
||||
$topics = mt_rand(200, 2000);
|
||||
mkv_log('Creating ' . $topics . ' bogus forum topics...');
|
||||
|
||||
$topIds = [];
|
||||
for($i = 0; $i < $topics; ++$i) {
|
||||
mkv_log('Creating bogus topic ' . $i . '...');
|
||||
$userId = mt_rand(-100, 2000);
|
||||
if($userId < 1)
|
||||
$userId = null;
|
||||
$type = mt_rand(-1000, 2);
|
||||
if($type < 1)
|
||||
$type = 0;
|
||||
$ft->bind('cat', $catIds[array_rand($catIds)]);
|
||||
$ft->bind('user', $userId);
|
||||
$ft->bind('type', $type);
|
||||
$ft->bind('title', mb_substr($forumTopicsTitles->generate(), 0, 240, 'utf-8'));
|
||||
$ft->bind('views', mt_rand(0, 10000));
|
||||
$ft->bind('created', mt_rand(1, 0x7FFFFFFF));
|
||||
$ft->bind('bumped', mt_rand(1, 0x7FFFFFFF));
|
||||
$ft->bind('deleted', mt_rand(0, 10000) > 9999 ? mt_rand(1, 0x7FFFFFFF) : null);
|
||||
$ft->bind('locked', mt_rand(0, 10000) > 9900 ? mt_rand(1, 0x7FFFFFFF) : null);
|
||||
$ft->execute();
|
||||
$topIds[] = $db->lastId();
|
||||
}
|
||||
|
||||
mkv_log('Opening forum post text markov dictionary...');
|
||||
$forumPostsTexts = new MarkovDictionary(MKV_DICTS . '/forums_posts_texts.fmk');
|
||||
|
||||
mkv_log('Nuking forum posts table...');
|
||||
$db->exec('DELETE FROM `msz_forum_posts`');
|
||||
$db->exec('ALTER TABLE `msz_forum_posts` AUTO_INCREMENT = 1');
|
||||
|
||||
mkv_log('Preparing forum post insertion statement...');
|
||||
$fp = $db->prepare('INSERT INTO `msz_forum_posts` (`topic_id`, `forum_id`, `user_id`, `post_ip`, `post_text`, `post_parse`, `post_display_signature`, `post_created`, `post_edited`, `post_deleted`) VALUES (:topic, 1, :user, :addr, :text, :parse, :sig, FROM_UNIXTIME(:created), FROM_UNIXTIME(:edited), FROM_UNIXTIME(:deleted))');
|
||||
|
||||
$topCount = count($topIds);
|
||||
for($t = 0; $t < $topCount; ++$t) {
|
||||
$posts = mt_rand(1, 600);
|
||||
$topId = $topIds[$t];
|
||||
|
||||
mkv_log('Inserting ' . $posts . ' bogus forum posts for bogus topic ' . $topId . '...');
|
||||
|
||||
$fp->bind('topic', $topId);
|
||||
|
||||
for($i = 0; $i < $posts; ++$i) {
|
||||
mkv_log('Inserting bogus post ' . $i . ' into bogus topic ' . $topId . '...');
|
||||
|
||||
$userId = mt_rand(-100, 2000);
|
||||
if($userId < 1)
|
||||
$userId = null;
|
||||
$fp->bind('user', $userId);
|
||||
$fp->bind('addr', random_bytes(mt_rand(0, 1) ? 4 : 16));
|
||||
$fp->bind('text', mb_substr($forumPostsTexts->generate(), 0, 60000, 'utf-8'));
|
||||
$fp->bind('parse', mt_rand(0, 2));
|
||||
$fp->bind('sig', mt_rand(0, 1000) > 900 ? 0 : 1);
|
||||
$fp->bind('created', mt_rand(1, 0x7FFFFFFF));
|
||||
$fp->bind('created', mt_rand(1, 0x7FFFFFFF));
|
||||
$fp->bind('edited', mt_rand(0, 1000) > 900 ? mt_rand(1, 0x7FFFFFFF) : null);
|
||||
$fp->bind('deleted', mt_rand(0, 10000) > 9000 ? mt_rand(1, 0x7FFFFFFF) : null);
|
||||
$fp->execute();
|
||||
}
|
||||
}
|
||||
|
||||
mkv_log('Running slow cron once more...');
|
||||
|
||||
// running cron after fuckery
|
||||
(new \Misuzu\Console\Commands\CronCommand)->dispatch(
|
||||
new \Misuzu\Console\CommandArgs(['--slow'])
|
||||
);
|
||||
|
||||
mkv_log('Done! Enjoy your garbage filled forum.');
|
|
@ -1,7 +0,0 @@
|
|||
[Database]
|
||||
driver = mysql
|
||||
unix_socket = /var/run/mysqld/mysqld.sock
|
||||
username = misuzu
|
||||
password = toastiscool100
|
||||
dbname = misuzu
|
||||
charset = utf8mb4
|
|
@ -1,35 +0,0 @@
|
|||
fastcgi_param QUERY_STRING $query_string;
|
||||
fastcgi_param REQUEST_METHOD $request_method;
|
||||
fastcgi_param CONTENT_TYPE $content_type;
|
||||
fastcgi_param CONTENT_LENGTH $content_length;
|
||||
|
||||
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
|
||||
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
|
||||
fastcgi_param REQUEST_URI $request_uri;
|
||||
fastcgi_param DOCUMENT_URI $document_uri;
|
||||
#fastcgi_param DOCUMENT_ROOT $document_root;
|
||||
fastcgi_param DOCUMENT_ROOT $realpath_root;
|
||||
fastcgi_param SERVER_PROTOCOL $server_protocol;
|
||||
fastcgi_param REQUEST_SCHEME $scheme;
|
||||
fastcgi_param HTTPS $https if_not_empty;
|
||||
fastcgi_param PATH_INFO $fastcgi_path_info;
|
||||
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
|
||||
|
||||
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
|
||||
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
|
||||
|
||||
fastcgi_param REMOTE_ADDR $remote_addr;
|
||||
fastcgi_param REMOTE_PORT $remote_port;
|
||||
fastcgi_param SERVER_ADDR $server_addr;
|
||||
fastcgi_param SERVER_PORT $server_port;
|
||||
fastcgi_param SERVER_NAME $server_name;
|
||||
|
||||
fastcgi_param REDIRECT_STATUS 200;
|
||||
|
||||
fastcgi_connect_timeout 60;
|
||||
fastcgi_send_timeout 180;
|
||||
fastcgi_read_timeout 180;
|
||||
fastcgi_buffers 256 4k;
|
||||
fastcgi_busy_buffers_size 256k;
|
||||
fastcgi_temp_file_write_size 256k;
|
|
@ -1,94 +0,0 @@
|
|||
types {
|
||||
text/html html htm shtml;
|
||||
text/css css;
|
||||
text/xml xml;
|
||||
image/gif gif;
|
||||
image/jpeg jpeg jpg;
|
||||
application/javascript js;
|
||||
application/atom+xml atom;
|
||||
application/rss+xml rss;
|
||||
application/wasm wasm;
|
||||
|
||||
text/mathml mml;
|
||||
text/plain txt;
|
||||
text/vnd.sun.j2me.app-descriptor jad;
|
||||
text/vnd.wap.wml wml;
|
||||
text/x-component htc;
|
||||
|
||||
image/png png;
|
||||
image/tiff tif tiff;
|
||||
image/vnd.wap.wbmp wbmp;
|
||||
image/x-icon ico;
|
||||
image/x-jng jng;
|
||||
image/x-ms-bmp bmp;
|
||||
image/svg+xml svg svgz;
|
||||
image/webp webp;
|
||||
|
||||
application/font-woff woff;
|
||||
application/java-archive jar war ear;
|
||||
application/json json;
|
||||
application/mac-binhex40 hqx;
|
||||
application/msword doc;
|
||||
application/pdf pdf;
|
||||
application/postscript ps eps ai;
|
||||
application/rtf rtf;
|
||||
application/vnd.apple.mpegurl m3u8;
|
||||
application/vnd.ms-excel xls;
|
||||
application/vnd.ms-fontobject eot;
|
||||
application/vnd.ms-powerpoint ppt;
|
||||
application/vnd.wap.wmlc wmlc;
|
||||
application/vnd.google-earth.kml+xml kml;
|
||||
application/vnd.google-earth.kmz kmz;
|
||||
application/x-7z-compressed 7z;
|
||||
application/x-cocoa cco;
|
||||
application/x-java-archive-diff jardiff;
|
||||
application/x-java-jnlp-file jnlp;
|
||||
application/x-makeself run;
|
||||
application/x-perl pl pm;
|
||||
application/x-pilot prc pdb;
|
||||
application/x-rar-compressed rar;
|
||||
application/x-redhat-package-manager rpm;
|
||||
application/x-sea sea;
|
||||
application/x-shockwave-flash swf;
|
||||
application/x-stuffit sit;
|
||||
application/x-tcl tcl tk;
|
||||
application/x-x509-ca-cert der pem crt;
|
||||
application/x-xpinstall xpi;
|
||||
application/xhtml+xml xhtml;
|
||||
application/xspf+xml xspf;
|
||||
application/zip zip;
|
||||
|
||||
application/octet-stream bin exe dll;
|
||||
application/octet-stream deb;
|
||||
application/octet-stream dmg;
|
||||
application/octet-stream iso img;
|
||||
application/octet-stream msi msp msm;
|
||||
|
||||
application/vnd.openxmlformats-officedocument.wordprocessingml.document docx;
|
||||
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx;
|
||||
application/vnd.openxmlformats-officedocument.presentationml.presentation pptx;
|
||||
|
||||
audio/midi mid midi kar;
|
||||
audio/mpeg mp3;
|
||||
audio/ogg ogg;
|
||||
audio/x-m4a m4a;
|
||||
audio/x-realaudio ra;
|
||||
audio/opus opus;
|
||||
audio/x-caf caf;
|
||||
|
||||
video/3gpp 3gpp 3gp;
|
||||
video/mp2t ts;
|
||||
video/mp4 mp4;
|
||||
video/mpeg mpeg mpg;
|
||||
video/quicktime mov;
|
||||
video/webm webm;
|
||||
video/x-flv flv;
|
||||
video/x-m4v m4v;
|
||||
video/x-mng mng;
|
||||
video/x-ms-asf asx asf;
|
||||
video/x-ms-wmv wmv;
|
||||
video/x-msvideo avi;
|
||||
|
||||
font/ttf ttf;
|
||||
font/otf otf;
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
user vagrant;
|
||||
worker_processes auto;
|
||||
pid /var/run/nginx.pid;
|
||||
|
||||
events {
|
||||
worker_connections 768;
|
||||
}
|
||||
|
||||
http {
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
tcp_nodelay on;
|
||||
keepalive_timeout 65;
|
||||
types_hash_max_size 2048;
|
||||
server_tokens off;
|
||||
|
||||
charset utf-8;
|
||||
|
||||
gzip on;
|
||||
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
|
||||
|
||||
include mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
client_max_body_size 100M;
|
||||
disable_symlinks off;
|
||||
|
||||
add_header X-Content-Type-Options nosniff;
|
||||
add_header X-XSS-Protection "1; mode=block";
|
||||
|
||||
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
|
||||
ssl_prefer_server_ciphers on;
|
||||
ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS';
|
||||
ssl_ecdh_curve secp384r1;
|
||||
ssl_session_cache shared:SSL:10m;
|
||||
ssl_session_tickets off;
|
||||
ssl_stapling on;
|
||||
ssl_stapling_verify on;
|
||||
ssl_dhparam dhparam.pem;
|
||||
|
||||
error_log /var/log/nginx/error.log crit;
|
||||
|
||||
server {
|
||||
root /www/misuzu/public;
|
||||
server_name misuzu;
|
||||
index index.php;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.php?$query_string;
|
||||
}
|
||||
|
||||
location ~* \.(eot|otf|ttf|woff|woff2)$ {
|
||||
add_header Access-Control-Allow-Origin *;
|
||||
}
|
||||
|
||||
location /msz-storage {
|
||||
alias /www/misuzu/store;
|
||||
internal;
|
||||
}
|
||||
|
||||
listen 80;
|
||||
listen 443 ssl;
|
||||
listen [::]:80;
|
||||
listen [::]:443 ssl;
|
||||
|
||||
location = /favicon.ico {
|
||||
log_not_found off;
|
||||
access_log off;
|
||||
}
|
||||
|
||||
location = /robots.txt {
|
||||
log_not_found off;
|
||||
access_log off;
|
||||
}
|
||||
|
||||
ssl_certificate misuzu.crt;
|
||||
ssl_certificate_key misuzu.key;
|
||||
|
||||
location ~ [^/]\.php(/|$) {
|
||||
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
|
||||
|
||||
if (!-f $document_root$fastcgi_script_name) {
|
||||
return 404;
|
||||
}
|
||||
|
||||
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
|
||||
fastcgi_index index.php;
|
||||
include fastcgi_params;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
require_once __DIR__ . '/../misuzu.php';
|
||||
|
||||
if(!MSZ_DEBUG)
|
||||
die('Not running in debug mode. Are you sure you want to run this?' . PHP_EOL);
|
||||
|
||||
define('SRA_URL', 'https://abyss.flash.moe/dev-avatars/_random.php');
|
||||
|
||||
// oh boy this'll take a while
|
||||
$users = \Misuzu\Users\User::all();
|
||||
|
||||
printf('[%s] Altering avatars for %d users.%s', date('H:i:s'), count($users), PHP_EOL);
|
||||
|
||||
foreach($users as $user) {
|
||||
printf('[%s] Changing avatar for %d %s...%s', date('H:i:s'), $user->getId(), $user->getUsername(), PHP_EOL);
|
||||
|
||||
if(mt_rand(0, 1000) > 950) {
|
||||
printf('[%s] Skipping this one.%s', date('H:i:s'), PHP_EOL);
|
||||
continue;
|
||||
}
|
||||
|
||||
printf('[%s] Downloading image from %s...%s', date('H:i:s'), SRA_URL, PHP_EOL);
|
||||
$data = file_get_contents(SRA_URL);
|
||||
|
||||
printf('[%s] Applying through stupid roundabout method...%s', date('H:i:s'), PHP_EOL);
|
||||
$user->getAvatarInfo()->setFromData($data);
|
||||
}
|
|
@ -1,157 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# this is only intended for the vagrant shit
|
||||
# for the love of god don't run this on anything but that
|
||||
# configuration is almost identical to production
|
||||
|
||||
echo -e "> Misuzu Vagrant Auto Configurator "
|
||||
echo -e ""
|
||||
|
||||
echo -e "=> Installing apt requirements"
|
||||
apt-get update
|
||||
apt-get install -y software-properties-common dirmngr apt-transport-https
|
||||
|
||||
echo -e "=> Adding PHP PPA"
|
||||
add-apt-repository -y ppa:ondrej/php
|
||||
|
||||
echo -e "=> Adding MariaDB 10.6 repostiory"
|
||||
apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
|
||||
add-apt-repository -y 'deb [arch=amd64,arm64,ppc64el,s390x] https://ftp.nluug.nl/db/mariadb/repo/10.6/ubuntu focal main'
|
||||
|
||||
echo -e "=> Performing full package upgrade"
|
||||
apt-get update
|
||||
apt-get full-upgrade -y
|
||||
|
||||
echo -e "=> Installing required packages"
|
||||
apt-get install -y nginx-full mariadb-server-10.6 openssl git \
|
||||
php8.1 php8.1-bcmath php8.1-cli php8.1-common php8.1-curl php8.1-dev \
|
||||
php8.1-fpm php8.1-gd php8.1-igbinary php8.1-imagick php8.1-intl \
|
||||
php8.1-ldap php8.1-mbstring php8.1-mysql php8.1-opcache php8.1-readline \
|
||||
php8.1-redis php8.1-sqlite3 php8.1-xml php8.1-zip
|
||||
|
||||
SSL_DHPARAM=/vagrant/devel/nginx/dhparam.pem
|
||||
SSL_CRT=/vagrant/devel/nginx/misuzu.crt
|
||||
SSL_KEY=/vagrant/devel/nginx/misuzu.key
|
||||
|
||||
echo -e "=> Generating dhparam.pem"
|
||||
[ -f "$SSL_DHPARAM" ] || openssl dhparam -out $SSL_DHPARAM 2048
|
||||
|
||||
echo -e "=> Generating SSL certificate"
|
||||
[ -f "$SSL_CRT" ] || [ -f "$SSL_KEY" ] || openssl req -subj '/O=Flashii/C=NL/CN=localhost' -new -newkey rsa:2048 -sha256 -days 9001 -nodes -x509 -keyout $SSL_KEY -out $SSL_CRT
|
||||
|
||||
echo -e "=> Replacing NGINX configuration"
|
||||
|
||||
echo -e "==> Removing existing configuration folder"
|
||||
rm -rf /etc/nginx
|
||||
|
||||
echo -e "==> Linking Misuzu config folder"
|
||||
ln -fs /vagrant/devel/nginx /etc/nginx
|
||||
|
||||
echo -e "==> Restarting NGINX"
|
||||
service nginx restart
|
||||
|
||||
echo -e "=> Adjusting PHP configuration"
|
||||
|
||||
echo -e "==> Set display_startup_errors to On"
|
||||
sed -i 's/display_startup_errors = Off/display_startup_errors = On/g' /etc/php/8.1/fpm/php.ini
|
||||
|
||||
echo -e "==> Increase max upload size to 150M"
|
||||
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 150M/g' /etc/php/8.1/fpm/php.ini
|
||||
|
||||
echo -e "==> Increase max body size to 150M"
|
||||
sed -i 's/post_max_size = 8M/post_max_size = 150M/g' /etc/php/8.1/fpm/php.ini
|
||||
|
||||
echo -e "==> Change FPM user to vagrant"
|
||||
sed -i 's/user = www-data/user = vagrant/g' /etc/php/8.1/fpm/pool.d/www.conf
|
||||
sed -i 's/listen.owner = www-data/listen.owner = vagrant/g' /etc/php/8.1/fpm/pool.d/www.conf
|
||||
|
||||
echo -e "==> Change FPM group to vagrant"
|
||||
sed -i 's/group = www-data/group = vagrant/g' /etc/php/8.1/fpm/pool.d/www.conf
|
||||
sed -i 's/listen.group = www-data/listen.group = vagrant/g' /etc/php/8.1/fpm/pool.d/www.conf
|
||||
|
||||
echo -e "==> Restarting PHP-FPM"
|
||||
service php8.1-fpm restart
|
||||
|
||||
echo -e "=> Adjusting MariaDB configuration"
|
||||
|
||||
echo -e "==> Bind to all addresses"
|
||||
sed -i 's/= 127.0.0.1/= 0.0.0.0/g' /etc/mysql/mariadb.conf.d/50-server.cnf
|
||||
service mysql restart
|
||||
|
||||
echo -e "==> Creating MariaDB database"
|
||||
mysql -vv -e "CREATE DATABASE misuzu COLLATE 'utf8mb4_bin'"
|
||||
|
||||
echo -e "==> Creating MariaDB user"
|
||||
mysql -vv -e "CREATE USER 'misuzu'@'localhost' IDENTIFIED BY 'toastiscool100'"
|
||||
mysql -vv -e "CREATE USER 'misuzu'@'%' IDENTIFIED BY 'toastiscool100'"
|
||||
|
||||
echo -e "==> Granting database access to MariaDB user"
|
||||
mysql -vv -e "GRANT EXECUTE, SELECT, SHOW VIEW, ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE VIEW, DELETE, DROP, EVENT, INDEX, INSERT, REFERENCES, TRIGGER, UPDATE, LOCK TABLES ON misuzu.* TO 'misuzu'@'localhost'"
|
||||
mysql -vv -e "GRANT EXECUTE, SELECT, SHOW VIEW, ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE VIEW, DELETE, DROP, EVENT, INDEX, INSERT, REFERENCES, TRIGGER, UPDATE, LOCK TABLES ON misuzu.* TO 'misuzu'@'%'"
|
||||
|
||||
echo -e "==> Reloading MariaDB privileges"
|
||||
mysql -vv -e "FLUSH PRIVILEGES"
|
||||
|
||||
# Taken from https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md
|
||||
# Remove when composer dependencies are dropkicked
|
||||
|
||||
echo -e "=> Installing Composer"
|
||||
|
||||
echo -e "==> Fetching expecting checksum"
|
||||
EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')"
|
||||
|
||||
echo -e "==> Downloading installer"
|
||||
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
|
||||
|
||||
echo -e "==> Hashing installer"
|
||||
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"
|
||||
|
||||
echo -e "==> Confirming checksum"
|
||||
if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]
|
||||
then
|
||||
>&2 echo 'ERROR: Invalid installer checksum'
|
||||
rm composer-setup.php
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "==> Installing to /bin/composer"
|
||||
php composer-setup.php --quiet --install-dir=/bin --filename=composer
|
||||
|
||||
echo -e "==> Removing installer"
|
||||
rm composer-setup.php
|
||||
# End of composer things
|
||||
|
||||
echo -e "=> Adjusting Misuzu configuration"
|
||||
|
||||
MSZ_CONFIG=/vagrant/config/config.ini
|
||||
|
||||
echo -e "==> Replacing Misuzu config.ini"
|
||||
rm $MSZ_CONFIG
|
||||
cp /vagrant/devel/misuzu/config.ini $MSZ_CONFIG
|
||||
|
||||
echo -e "==> Updating Git submodules"
|
||||
sudo -u vagrant git -C /vagrant submodule update --init
|
||||
|
||||
# ENTER: JANK
|
||||
echo -e "==> Enable Misuzu debug mode"
|
||||
sudo -u vagrant touch /vagrant/.debug
|
||||
|
||||
echo -e "==> Running composer install as vagrant"
|
||||
sudo -u vagrant composer install -d /vagrant
|
||||
|
||||
echo -e "==> Adding frequent cron jobs as vagrant"
|
||||
(sudo -u vagrant crontab -l 2>/dev/null; echo "0,10,20,30,40 * * * * php8.1 /www/misuzu/msz cron") | sudo -u vagrant crontab -
|
||||
|
||||
echo -e "==> Adding infrequent cron jobs as vagrant"
|
||||
(sudo -u vagrant crontab -l 2>/dev/null; echo "50 * * * * php8.1 /www/misuzu/msz cron --slow") | sudo -u vagrant crontab -
|
||||
|
||||
echo -e "==> Nuking /www"
|
||||
rm -rf /www
|
||||
|
||||
echo -e "==> Creating /www"
|
||||
mkdir /www
|
||||
|
||||
echo -e "==> Linking /vagrant to /www/misuzu"
|
||||
ln -fs /vagrant /www/misuzu
|
||||
|
||||
echo -e "Done!"
|
|
@ -1 +1 @@
|
|||
Subproject commit 1cd1695429b5a313ac357f3f3faba365e425f504
|
||||
Subproject commit f3535117cea575d6ec5c86964da69b2c018028d1
|
|
@ -105,15 +105,8 @@ if(!is_dir(MSZ_STORAGE))
|
|||
|
||||
$msz = new MisuzuContext($db, $cfg);
|
||||
|
||||
if(MSZ_CLI) { // Temporary backwards compatibility measure, remove this later
|
||||
if(realpath($_SERVER['SCRIPT_FILENAME']) === __FILE__) {
|
||||
if(($argv[1] ?? '') === 'cron' && ($argv[2] ?? '') === 'low')
|
||||
$argv[2] = '--slow';
|
||||
array_shift($argv);
|
||||
echo shell_exec(__DIR__ . '/msz ' . implode(' ', $argv));
|
||||
}
|
||||
if(MSZ_CLI)
|
||||
return;
|
||||
}
|
||||
|
||||
// Everything below here should eventually be moved to index.php, probably only initialised when required.
|
||||
// Serving things like the css/js doesn't need to initialise sessions.
|
||||
|
|
19
msz
19
msz
|
@ -1,19 +0,0 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
namespace Misuzu;
|
||||
|
||||
use Misuzu\Console\CommandArgs;
|
||||
use Misuzu\Console\CommandCollection;
|
||||
|
||||
require_once __DIR__ . '/misuzu.php';
|
||||
|
||||
if(!MSZ_CLI)
|
||||
die('This tool is meant to be used through command line only.' . PHP_EOL);
|
||||
|
||||
$commands = new CommandCollection;
|
||||
$commands->addCommands(
|
||||
new \Misuzu\Console\Commands\CronCommand($msz),
|
||||
new \Misuzu\Console\Commands\MigrateCommand($msz),
|
||||
new \Misuzu\Console\Commands\NewMigrationCommand($msz),
|
||||
);
|
||||
$commands->dispatch(new CommandArgs($argv));
|
|
@ -1,49 +0,0 @@
|
|||
<?php
|
||||
namespace Misuzu\Console;
|
||||
|
||||
class CommandArgs {
|
||||
private $args = [];
|
||||
|
||||
public function __construct(array $args) {
|
||||
$this->args = $args;
|
||||
}
|
||||
|
||||
public function getArgs(): array {
|
||||
return array_slice($this->args, 2);
|
||||
}
|
||||
|
||||
public function getArgCount(): int {
|
||||
return count($this->args) - 2;
|
||||
}
|
||||
|
||||
public function getCommand(): string {
|
||||
return $this->args[1] ?? '';
|
||||
}
|
||||
|
||||
public function getArg(int $index): string {
|
||||
return $this->args[2 + $index] ?? '';
|
||||
}
|
||||
|
||||
public function flagIndex(string $long, string $short = ''): int {
|
||||
$long = '--' . $long;
|
||||
$short = '-' . $short;
|
||||
for($i = 2; $i < count($this->args); ++$i)
|
||||
if(($long !== '--' && $this->args[$i] === $long) || ($short !== '-' && $short === $this->args[$i]))
|
||||
return $i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public function hasFlag(string $long, string $short = ''): bool {
|
||||
return $this->flagIndex($long, $short) >= 0;
|
||||
}
|
||||
|
||||
public function getFlag(string $long, string $short = ''): string {
|
||||
$index = $this->flagIndex($long, $short);
|
||||
if($index < 0)
|
||||
return '';
|
||||
$arg = $this->args[$index + 1] ?? '';
|
||||
if($arg[0] == '-')
|
||||
return '';
|
||||
return $arg;
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
namespace Misuzu\Console;
|
||||
|
||||
class CommandManagerException extends ConsoleException {}
|
||||
class CommandNotFoundException extends CommandManagerException {}
|
||||
|
||||
class CommandCollection implements CommandDispatchInterface {
|
||||
private $commands = [];
|
||||
|
||||
public function addCommands(CommandInterface ...$commands): void {
|
||||
foreach($commands as $command)
|
||||
try {
|
||||
$this->matchCommand($command->getName());
|
||||
} catch(CommandNotFoundException $ex) {
|
||||
$this->commands[] = $command;
|
||||
}
|
||||
}
|
||||
|
||||
public function matchCommand(string $name): CommandInterface {
|
||||
foreach($this->commands as $command)
|
||||
if($command->getName() === $name)
|
||||
return $command;
|
||||
throw new CommandNotFoundException;
|
||||
}
|
||||
|
||||
public function dispatch(CommandArgs $args): void {
|
||||
try {
|
||||
$this->matchCommand($args->getCommand())->dispatch($args);
|
||||
} catch(CommandNotFoundException $ex) {
|
||||
echo 'Command not found.' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
<?php
|
||||
namespace Misuzu\Console;
|
||||
|
||||
interface CommandDispatchInterface {
|
||||
public function dispatch(CommandArgs $args): void;
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
<?php
|
||||
namespace Misuzu\Console;
|
||||
|
||||
interface CommandInterface extends CommandDispatchInterface {
|
||||
public function getName(): string;
|
||||
public function getSummary(): string;
|
||||
}
|
|
@ -1,166 +0,0 @@
|
|||
<?php
|
||||
namespace Misuzu\Console\Commands;
|
||||
|
||||
use Misuzu\DB;
|
||||
use Misuzu\MisuzuContext;
|
||||
use Misuzu\Console\CommandArgs;
|
||||
use Misuzu\Console\CommandInterface;
|
||||
|
||||
class CronCommand implements CommandInterface {
|
||||
private MisuzuContext $context;
|
||||
|
||||
public function __construct(MisuzuContext $ctx) {
|
||||
$this->context = $ctx;
|
||||
}
|
||||
|
||||
public function getName(): string {
|
||||
return 'cron';
|
||||
}
|
||||
public function getSummary(): string {
|
||||
return 'Runs scheduled tasks and cleanups.';
|
||||
}
|
||||
|
||||
public function dispatch(CommandArgs $args): void {
|
||||
$runSlow = $args->hasFlag('slow');
|
||||
|
||||
foreach(self::TASKS as $task) {
|
||||
if($runSlow || empty($task['slow'])) {
|
||||
echo $task['name'] . PHP_EOL;
|
||||
|
||||
switch($task['type']) {
|
||||
case 'sql':
|
||||
DB::exec($task['command']);
|
||||
break;
|
||||
|
||||
case 'func':
|
||||
call_user_func([$this, $task['command']]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function syncForumStats(): void {
|
||||
forum_count_synchronise();
|
||||
}
|
||||
|
||||
private const TASKS = [
|
||||
[
|
||||
'name' => 'Ensures main role exists.',
|
||||
'type' => 'sql',
|
||||
'slow' => true,
|
||||
'command' => "
|
||||
INSERT IGNORE INTO `msz_roles`
|
||||
(`role_id`, `role_name`, `role_hierarchy`, `role_colour`, `role_description`, `role_created`)
|
||||
VALUES
|
||||
(1, 'Member', 1, 1073741824, NULL, NOW())
|
||||
",
|
||||
],
|
||||
[
|
||||
'name' => 'Ensures all users are in the main role.',
|
||||
'type' => 'sql',
|
||||
'slow' => true,
|
||||
'command' => "
|
||||
INSERT INTO `msz_user_roles`
|
||||
(`user_id`, `role_id`)
|
||||
SELECT `user_id`, 1 FROM `msz_users` as u
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM `msz_user_roles` as ur
|
||||
WHERE `role_id` = 1
|
||||
AND u.`user_id` = ur.`user_id`
|
||||
)
|
||||
",
|
||||
],
|
||||
[
|
||||
'name' => 'Ensures all display_role values are correct with `msz_user_roles`.',
|
||||
'type' => 'sql',
|
||||
'slow' => true,
|
||||
'command' => "
|
||||
UPDATE `msz_users` as u
|
||||
SET `display_role` = (
|
||||
SELECT ur.`role_id`
|
||||
FROM `msz_user_roles` as ur
|
||||
LEFT JOIN `msz_roles` as r
|
||||
ON r.`role_id` = ur.`role_id`
|
||||
WHERE ur.`user_id` = u.`user_id`
|
||||
ORDER BY `role_hierarchy` DESC
|
||||
LIMIT 1
|
||||
)
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM `msz_user_roles` as ur
|
||||
WHERE ur.`role_id` = u.`display_role`
|
||||
AND `ur`.`user_id` = u.`user_id`
|
||||
)
|
||||
",
|
||||
],
|
||||
[
|
||||
'name' => 'Remove expired sessions.',
|
||||
'type' => 'sql',
|
||||
'command' => "
|
||||
DELETE FROM `msz_sessions`
|
||||
WHERE `session_expires` < NOW()
|
||||
",
|
||||
],
|
||||
[
|
||||
'name' => 'Remove old password reset records.',
|
||||
'type' => 'sql',
|
||||
'command' => "
|
||||
DELETE FROM `msz_users_password_resets`
|
||||
WHERE `reset_requested` < NOW() - INTERVAL 1 WEEK
|
||||
",
|
||||
],
|
||||
[
|
||||
'name' => 'Clean up login history.',
|
||||
'type' => 'sql',
|
||||
'command' => "
|
||||
DELETE FROM `msz_login_attempts`
|
||||
WHERE `attempt_created` < NOW() - INTERVAL 1 MONTH
|
||||
",
|
||||
],
|
||||
[
|
||||
'name' => 'Clean up audit log.',
|
||||
'type' => 'sql',
|
||||
'command' => "
|
||||
DELETE FROM `msz_audit_log`
|
||||
WHERE `log_created` < NOW() - INTERVAL 3 MONTH
|
||||
",
|
||||
],
|
||||
[
|
||||
'name' => 'Remove stale forum tracking entries.',
|
||||
'type' => 'sql',
|
||||
'command' => "
|
||||
DELETE tt FROM `msz_forum_topics_track` as tt
|
||||
LEFT JOIN `msz_forum_topics` as t
|
||||
ON t.`topic_id` = tt.`topic_id`
|
||||
WHERE t.`topic_bumped` < NOW() - INTERVAL 1 MONTH
|
||||
",
|
||||
],
|
||||
[
|
||||
'name' => 'Synchronise forum_id.',
|
||||
'type' => 'sql',
|
||||
'slow' => true,
|
||||
'command' => "
|
||||
UPDATE `msz_forum_posts` AS p
|
||||
INNER JOIN `msz_forum_topics` AS t
|
||||
ON t.`topic_id` = p.`topic_id`
|
||||
SET p.`forum_id` = t.`forum_id`
|
||||
",
|
||||
],
|
||||
[
|
||||
'name' => 'Recount forum topics and posts.',
|
||||
'type' => 'func',
|
||||
'slow' => true,
|
||||
'command' => 'syncForumStats',
|
||||
],
|
||||
[
|
||||
'name' => 'Clean up expired tfa tokens.',
|
||||
'type' => 'sql',
|
||||
'command' => "
|
||||
DELETE FROM `msz_auth_tfa`
|
||||
WHERE `tfa_created` < NOW() - INTERVAL 15 MINUTE
|
||||
",
|
||||
],
|
||||
];
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
<?php
|
||||
namespace Misuzu\Console\Commands;
|
||||
|
||||
use Misuzu\DB;
|
||||
use Misuzu\MisuzuContext;
|
||||
use Misuzu\Console\CommandArgs;
|
||||
use Misuzu\Console\CommandInterface;
|
||||
|
||||
class MigrateCommand implements CommandInterface {
|
||||
private MisuzuContext $context;
|
||||
|
||||
public function __construct(MisuzuContext $ctx) {
|
||||
$this->context = $ctx;
|
||||
}
|
||||
|
||||
public function getName(): string {
|
||||
return 'migrate';
|
||||
}
|
||||
public function getSummary(): string {
|
||||
return 'Runs database migrations.';
|
||||
}
|
||||
|
||||
public function dispatch(CommandArgs $args): void {
|
||||
if($args->getArg(0) === 'rollback') {
|
||||
echo 'Migration rollback is gone.' . PHP_EOL;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
touch(MSZ_ROOT . '/.migrating');
|
||||
chmod(MSZ_ROOT . '/.migrating', 0777);
|
||||
|
||||
echo 'Creating migration manager...' . PHP_EOL;
|
||||
$manager = $this->context->createMigrationManager();
|
||||
|
||||
echo 'Preparing to run migrations...' . PHP_EOL;
|
||||
$manager->init();
|
||||
|
||||
echo 'Creating migration repository...' . PHP_EOL;
|
||||
$repo = $this->context->createMigrationRepo();
|
||||
|
||||
echo 'Running migrations...' . PHP_EOL;
|
||||
$completed = $manager->processMigrations($repo);
|
||||
|
||||
if(empty($completed)) {
|
||||
echo 'There were no migrations to run!' . PHP_EOL;
|
||||
} else {
|
||||
echo 'The following migrations have been completed:' . PHP_EOL;
|
||||
foreach($completed as $migration)
|
||||
echo ' - ' . $migration . PHP_EOL;
|
||||
}
|
||||
|
||||
echo PHP_EOL;
|
||||
} finally {
|
||||
unlink(MSZ_ROOT . '/.migrating');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
<?php
|
||||
namespace Misuzu\Console\Commands;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Index\Data\Migration\FsDbMigrationRepo;
|
||||
use Misuzu\MisuzuContext;
|
||||
use Misuzu\Console\CommandArgs;
|
||||
use Misuzu\Console\CommandInterface;
|
||||
|
||||
class NewMigrationCommand implements CommandInterface {
|
||||
private MisuzuContext $context;
|
||||
|
||||
public function __construct(MisuzuContext $ctx) {
|
||||
$this->context = $ctx;
|
||||
}
|
||||
|
||||
public function getName(): string {
|
||||
return 'new-mig';
|
||||
}
|
||||
public function getSummary(): string {
|
||||
return 'Creates a new database migration.';
|
||||
}
|
||||
|
||||
public function dispatch(CommandArgs $args): void {
|
||||
$repo = $this->context->createMigrationRepo();
|
||||
if(!($repo instanceof FsDbMigrationRepo)) {
|
||||
echo 'Migration repository type does not support creation of templates.' . PHP_EOL;
|
||||
return;
|
||||
}
|
||||
|
||||
$baseName = implode(' ', $args->getArgs());
|
||||
$manager = $this->context->createMigrationManager();
|
||||
|
||||
try {
|
||||
$names = $manager->createNames($baseName);
|
||||
} catch(InvalidArgumentException $ex) {
|
||||
echo $ex->getMessage() . PHP_EOL;
|
||||
return;
|
||||
}
|
||||
|
||||
$repo->saveMigrationTemplate($names->name, $manager->template($names->className));
|
||||
|
||||
echo "Template for '{$names->className}' has been saved to {$names->name}.php." . PHP_EOL;
|
||||
}
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
<?php
|
||||
namespace Misuzu\Console;
|
||||
|
||||
use RuntimeException;
|
||||