mc-cms-namelessmc/dev/scripts/cli_install.php

230 lines
7 KiB
PHP
Raw Permalink Normal View History

<?php
/*
* there is NO SUPPORT offered for this script.
* this script is provided AS IS and without any warranty.
* this script was made with the primary goal of making the install process automatic for hosting providers + our API test suite.
*/
function getEnvVar(string $name, ?string $fallback = null, ?array $valid_values = null)
{
$value = getenv($name);
2022-04-08 12:46:07 -07:00
$required = $fallback === null;
if ($value === false && $required) {
echo "⚠️ Required environment variable '$name' is not set!" . PHP_EOL;
exit(1);
}
2022-04-08 12:46:07 -07:00
if (!$value && $fallback !== null) {
2022-03-24 10:51:22 -07:00
$value = $fallback;
echo " Environment variable '$name' is not set, using fallback '$fallback'" . PHP_EOL;
2022-03-24 10:51:22 -07:00
}
if ($valid_values != null && !in_array($value, $valid_values)) {
echo "⚠️ Environment variable '$name' has invalid value";
exit(1);
}
2022-03-24 10:51:22 -07:00
return $value;
}
2022-03-24 10:51:22 -07:00
if (PHP_SAPI !== 'cli') {
die('This script must be run from the command line.');
}
if (!isset($argv[1]) || $argv[1] !== '--iSwearIKnowWhatImDoing') {
echo "🚫 You don't know what you're doing." . PHP_EOL;
2021-12-05 22:13:49 -08:00
exit(1);
}
echo PHP_EOL;
$reinstall = false;
if (isset($argv[2]) && $argv[2] == '--reinstall') {
$reinstall = true;
echo '🧨 Reinstall mode enabled! ' . PHP_EOL . PHP_EOL;
}
if (!file_exists('./vendor/autoload.php')) {
echo '⚠️ You need to run "composer install" first!' . PHP_EOL;
exit(1);
}
if (!$reinstall && file_exists('./core/config.php')) {
echo '⚠️ NamelessMC is already installed! ' . PHP_EOL;
echo "🧨 If you want to reinstall, run this script with the '--reinstall' flag." . PHP_EOL;
2021-12-05 22:13:49 -08:00
exit(1);
}
$start = microtime(true);
echo '🗑 Deleting cache directories...' . PHP_EOL;
// clear the cache directories
$folders = [
'./cache',
'./cache/templates_c',
];
Reactions revamp & profile widgets (#3272) * Initial work on reactions revamp and profile widgets * Remove unneeded changes * Remove unneeded change * fix style * Render emojis in reaction list StaffCP * wip minecraft account profile widget, sticky widgets on profile page * Add server name and IP to last seen * remove * rename to reaction score to match member list * align reactions table contents center * fix * wip - nicer abstraction, widgets never query db, skin 3d viewer (undecided) * wip - make reaction modals ajax, copy new reaction bar to profile posts * wip reaction modals * wip proper sorting * wip modals * wip get reaction submission working on profile wall posts * add back helpful and creative default reactions * reduce query amount on view topic * remove debug statement * wip * wip * simplify ProfileWidget pages * Revert forum dropdown * fix css syntax * fix emoji title and alt being strange * add back order input * sort widgets by order in list * fix settings link always showing * phpdoc * add widget name to exception * insert default widget data if not found * missing end if * properly cache forum news per-group * fix * fix cache key, news permission check * fix styling * wip * respect reaction ordering * wip * wip * support custom reaction scores, update member list to properly calculate * don't hardcode words * wip * allow multiple reactions * redirect to post * code style * phpstan * wip * remove hardcoded terms + fix copy * use npm for skinview3d * create ReactionContext and refactor * fix cache * docblocks * fix spelling * pr amendments
2023-06-21 10:19:46 -07:00
$whitelist = [
'0_DO_NOT_DELETE.txt',
'.htaccess',
];
foreach ($folders as $folder) {
if (is_dir($folder)) {
$files = glob($folder . '/*');
foreach ($files as $file) {
Reactions revamp & profile widgets (#3272) * Initial work on reactions revamp and profile widgets * Remove unneeded changes * Remove unneeded change * fix style * Render emojis in reaction list StaffCP * wip minecraft account profile widget, sticky widgets on profile page * Add server name and IP to last seen * remove * rename to reaction score to match member list * align reactions table contents center * fix * wip - nicer abstraction, widgets never query db, skin 3d viewer (undecided) * wip - make reaction modals ajax, copy new reaction bar to profile posts * wip reaction modals * wip proper sorting * wip modals * wip get reaction submission working on profile wall posts * add back helpful and creative default reactions * reduce query amount on view topic * remove debug statement * wip * wip * simplify ProfileWidget pages * Revert forum dropdown * fix css syntax * fix emoji title and alt being strange * add back order input * sort widgets by order in list * fix settings link always showing * phpdoc * add widget name to exception * insert default widget data if not found * missing end if * properly cache forum news per-group * fix * fix cache key, news permission check * fix styling * wip * respect reaction ordering * wip * wip * support custom reaction scores, update member list to properly calculate * don't hardcode words * wip * allow multiple reactions * redirect to post * code style * phpstan * wip * remove hardcoded terms + fix copy * use npm for skinview3d * create ReactionContext and refactor * fix cache * docblocks * fix spelling * pr amendments
2023-06-21 10:19:46 -07:00
if (!in_array(basename($file), $whitelist)) {
if (is_file($file)) {
unlink($file);
} elseif (is_dir($file)) {
Reactions revamp & profile widgets (#3272) * Initial work on reactions revamp and profile widgets * Remove unneeded changes * Remove unneeded change * fix style * Render emojis in reaction list StaffCP * wip minecraft account profile widget, sticky widgets on profile page * Add server name and IP to last seen * remove * rename to reaction score to match member list * align reactions table contents center * fix * wip - nicer abstraction, widgets never query db, skin 3d viewer (undecided) * wip - make reaction modals ajax, copy new reaction bar to profile posts * wip reaction modals * wip proper sorting * wip modals * wip get reaction submission working on profile wall posts * add back helpful and creative default reactions * reduce query amount on view topic * remove debug statement * wip * wip * simplify ProfileWidget pages * Revert forum dropdown * fix css syntax * fix emoji title and alt being strange * add back order input * sort widgets by order in list * fix settings link always showing * phpdoc * add widget name to exception * insert default widget data if not found * missing end if * properly cache forum news per-group * fix * fix cache key, news permission check * fix styling * wip * respect reaction ordering * wip * wip * support custom reaction scores, update member list to properly calculate * don't hardcode words * wip * allow multiple reactions * redirect to post * code style * phpstan * wip * remove hardcoded terms + fix copy * use npm for skinview3d * create ReactionContext and refactor * fix cache * docblocks * fix spelling * pr amendments
2023-06-21 10:19:46 -07:00
rmdir($file);
}
}
}
}
}
if ($reinstall) {
echo '🗑 Deleting old config.php file...' . PHP_EOL;
// delete the core/config.php file
if (is_file('./core/config.php')) {
unlink('./core/config.php');
}
}
2022-11-12 21:40:51 +01:00
const ROOT_PATH = __DIR__ . '/../..';
echo '♻️ Registering autoloader...' . PHP_EOL;
require './vendor/autoload.php';
echo '✍️ Creating new config.php file...' . PHP_EOL;
$conf = [
'mysql' => [
2022-04-08 12:46:07 -07:00
'host' => getEnvVar('NAMELESS_DATABASE_ADDRESS', '127.0.0.1'),
'port' => getEnvVar('NAMELESS_DATABASE_PORT', '3306'),
'username' => getEnvVar('NAMELESS_DATABASE_USERNAME', 'root'),
'password' => getEnvVar('NAMELESS_DATABASE_PASSWORD', ''),
'db' => getEnvVar('NAMELESS_DATABASE_NAME', 'nameless'),
'charset' => getEnvVar('NAMELESS_DATABASE_CHARSET', 'utf8mb4'),
'collation' => getEnvVar('NAMELESS_DATABASE_COLLATION', 'utf8mb4_unicode_ci'),
'initialise_charset' => true,
'initialise_collation' => true,
],
'remember' => [
'cookie_name' => 'nl2',
'cookie_expiry' => 2629800,
],
'session' => [
'session_name' => '2user',
'admin_name' => '2admin',
'token_name' => '2token',
],
'core' => [
2022-04-08 12:46:07 -07:00
'hostname' => getEnvVar('NAMELESS_HOSTNAME', 'localhost'),
'path' => getEnvVar('NAMELESS_PATH', ''),
'friendly' => getEnvVar('NAMELESS_FRIENDLY_URLS', 'false') === 'true',
'force_https' => false,
'force_www' => false,
'captcha' => false,
2022-05-22 00:46:28 +02:00
'date_format' => 'd M Y, H:i',
'trustedProxies' => null,
],
];
Config::write($conf);
if ($reinstall) {
echo '🗑️ Deleting old database...' . PHP_EOL;
2022-05-11 12:14:37 +02:00
$instance = DB::getCustomInstance(
$conf['mysql']['host'],
$conf['mysql']['db'],
$conf['mysql']['username'],
$conf['mysql']['password'],
2022-05-15 14:42:42 +02:00
$conf['mysql']['port']
);
2022-05-01 23:16:22 -07:00
$instance->query('DROP DATABASE IF EXISTS `' . $conf['mysql']['db'] . '`');
echo '✍️ Creating new database...' . PHP_EOL;
2022-05-01 23:16:22 -07:00
$instance->query('CREATE DATABASE `' . $conf['mysql']['db'] . '`');
}
echo '✍️ Creating tables...' . PHP_EOL;
$message = PhinxAdapter::migrate('Core');
if (!str_contains($message, 'All Done')) {
echo $message;
exit(1);
}
Use i18n for translations (#2658) * Dependency updates * Start i18n conversion * Switch to ellipsis character * Add Dutch language json * Remove Dutch PHP language files + fix variables * Further variable fixes * WIP i18n Language class conversion * Convert Cookie Consent module to new language format * Further progress including timeago translations * Misc * Replace {x} * Replace more {x} usage * {{time}} this took way too long * replace last {x} * Remove comments So searching for {x} produces relevant results * forgot to save * move to onPageLoad * Accept both string and int * types in doc * Remove unused (broken?) function * Don't convert to string first * Last arg doesn't seem to be used anywhere * Time `{x}` replacements * Email `{x}` replacements * misc `{x}` replacements * misc `{x}` replacements * misc `{x}` replacements * misc `{x}` replacements * misc `{x}` replacements * misc `{x}` replacements * misc `{x}` replacements * misc `{x}` replacements * misc `{x}` replacements * remove comments (makes searching for "{x}" nicer) * misc `{x}` replacements * JS `{x}` replacements * Cleanup language initialization * Change language constant + add pluralForm support * Misc language update things * Add script to find unused terms * Check all quote types * Remove most english translations from non-english languages * Also match with more args * Missed some apparently * Missed some (more) apparently * Misc work * Add script to convert *all* language files to json * Fix language codes * Remove a lot of unused terms * Remove a lot more unused terms * Convert everything to JSON, delete old files, get installer working with new system * Fix general configuration language dropdown + email messages * Fix page load time, fix language term `set` method * Fix discord integration command * Misc * Misc * Uncomment RTL definition * Misc * Convert links * Convert links * Convert links * Convert links * Misc work (bolding, fixes, etc) * Style fix * Fix variable * Fix #2668 * Fix old page load timers * Fix installer group sync injector error * Convert integration language terms * Fix more integration language things * Re-add upgrade script language things * Resolve PR comments * Remove unnecessary date() * Resolve some PR issues * Fix endpoint * Style * Fix Semantic -> Fomantic * Fix Semantic -> Fomantic * Return locale short code, not language id/name Only the short code is interesting to the API, return short code in user info endpoint just like in the website info endpoint. Also renamed to locale because it's language + region * Revert "warn people to not translate old language files" This reverts commit 690b77afff5ff7cc2f931d3b49feaa9a9072002b. * Fix query when there are no filters * Update 200-pr12.php * Update footer.php * insert time into string using placeholder * Fix getDisplayname case * Clean username * PR suggestions * Include newly created language in converted languages (migration) * PR suggestions * PR suggestions * Update init.php * Fix default language Co-authored-by: samerton <samerton@users.noreply.github.com> Co-authored-by: Robin <robinslot@hotmail.nl> Co-authored-by: Robin <robin+git@rkslot.nl> Co-authored-by: Partydragen <adrian_kili@outlook.com>
2022-04-23 06:27:10 -07:00
Session::put('default_language', getEnvVar('NAMELESS_DEFAULT_LANGUAGE', 'en_UK'));
echo '✍️ Inserting default data to database...' . PHP_EOL;
2022-05-31 11:29:47 -06:00
$_SESSION['install_timezone'] = in_array($timezone = getEnvVar('NAMELESS_TIMEZONE', 'Europe/London'), DateTimeZone::listIdentifiers())
? $timezone
: 'Europe/London';
DatabaseInitialiser::runPreUser();
Settings::set('sitename', getEnvVar('NAMELESS_SITE_NAME', 'NamelessMC'));
Settings::set('incoming_email', getEnvVar('NAMELESS_SITE_CONTACT_EMAIL', 'contact@example.com'));
Settings::set('outgoing_email', getEnvVar('NAMELESS_SITE_OUTGOING_EMAIL', 'no-reply@example.com'));
Settings::set('email_verification', getEnvVar('NAMELESS_EMAIL_VERIFICATION', '1', ['0', '1']));
echo '👮 Creating admin account...' . PHP_EOL;
2022-03-24 10:51:22 -07:00
2022-04-08 12:46:07 -07:00
$username = getEnvVar('NAMELESS_ADMIN_USERNAME', 'admin');
$password = getEnvVar('NAMELESS_ADMIN_PASSWORD', 'password');
$email = getEnvVar('NAMELESS_ADMIN_EMAIL', 'admin@example.com');
2022-03-24 10:51:22 -07:00
$user = new User();
$user->create([
2022-03-24 10:51:22 -07:00
'username' => $username,
'nickname' => $username,
'password' => password_hash($password, PASSWORD_BCRYPT, ['cost' => 13]),
'pass_method' => 'default',
'joined' => date('U'),
2022-03-24 10:51:22 -07:00
'email' => $email,
'lastip' => '127.0.0.1',
2022-05-31 11:29:47 -06:00
'active' => true,
'last_online' => date('U'),
'language_id' => DB::getInstance()->get('languages', ['is_default', 1])->results()[0]->id,
'timezone' => $_SESSION['install_timezone'],
'register_method' => 'nameless',
]);
2022-05-01 23:16:22 -07:00
DB::getInstance()->query('INSERT INTO `nl2_users_groups` (`user_id`, `group_id`, `received`, `expire`) VALUES (?, ?, ?, ?)', [
1,
2,
date('U'),
0,
]);
User Integrations systems (#2606) * Initial work for User Integrations systems * Convert a few endpoints to new user integration system * Finish minecraft part to new User Integration system * Fixes verify banner issue https://github.com/NamelessMC/Nameless/issues/2052 Fixes https://github.com/NamelessMC/Nameless/issues/2052 * Convert discord to new user integrations system * Update fields to show user integrations * Add user integrations to StaffCP user page / move over * Update UserInfo and Rename MinecraftVerify endpoint * Rework user listing endpoint * Password check never returns null * Add support for offline mode uuid * Fix documentation phpstan warnings * else if * remove die() * Revamp registration page * add integrations settings page * Convert authme & fix phpstan issues * refix settings page * Load uuid when user is loaded * Redirect user to complete required integrations * Fix translation for user connections page * Rework integrations registration in Register Endpoint Completes https://github.com/NamelessMC/Nameless/issues/2516 * make getIntegration ignore case sensitive * Update installer * Update upgrader script to convert users * Fix index for user integrations * Remove uuid from user data * Misc * Remove one unused query * Add event for integration linking, verify and unlink * Finish user transformer, Finish user integrations * Thx phpstan * Fix phpdocs * Fix user reports page * Remove validation banner * Change default field value * resolve samerton feedback * don't clean when inserting data * don't clean event data * remove more clean * increase reset_code length from 60 to 64 * pr13 confirmed * one more clean * Remove API verification setting * Register integrations edit permission * Resolve a few requested changes * Rework username and identifier validation * Add button to sync user integration * Fix Synchronisation text * Fix is verified term Co-authored-by: Robin <robinslot@hotmail.nl> Co-authored-by: Robin <robin+git@rkslot.nl>
2022-04-16 18:42:24 +02:00
$profile = ProfileUtils::getProfile($username);
if ($profile !== null) {
2022-04-17 20:10:53 -07:00
$result = $profile->getProfileAsArray();
User Integrations systems (#2606) * Initial work for User Integrations systems * Convert a few endpoints to new user integration system * Finish minecraft part to new User Integration system * Fixes verify banner issue https://github.com/NamelessMC/Nameless/issues/2052 Fixes https://github.com/NamelessMC/Nameless/issues/2052 * Convert discord to new user integrations system * Update fields to show user integrations * Add user integrations to StaffCP user page / move over * Update UserInfo and Rename MinecraftVerify endpoint * Rework user listing endpoint * Password check never returns null * Add support for offline mode uuid * Fix documentation phpstan warnings * else if * remove die() * Revamp registration page * add integrations settings page * Convert authme & fix phpstan issues * refix settings page * Load uuid when user is loaded * Redirect user to complete required integrations * Fix translation for user connections page * Rework integrations registration in Register Endpoint Completes https://github.com/NamelessMC/Nameless/issues/2516 * make getIntegration ignore case sensitive * Update installer * Update upgrader script to convert users * Fix index for user integrations * Remove uuid from user data * Misc * Remove one unused query * Add event for integration linking, verify and unlink * Finish user transformer, Finish user integrations * Thx phpstan * Fix phpdocs * Fix user reports page * Remove validation banner * Change default field value * resolve samerton feedback * don't clean when inserting data * don't clean event data * remove more clean * increase reset_code length from 60 to 64 * pr13 confirmed * one more clean * Remove API verification setting * Register integrations edit permission * Resolve a few requested changes * Rework username and identifier validation * Add button to sync user integration * Fix Synchronisation text * Fix is verified term Co-authored-by: Robin <robinslot@hotmail.nl> Co-authored-by: Robin <robin+git@rkslot.nl>
2022-04-16 18:42:24 +02:00
if (isset($result['uuid']) && !empty($result['uuid'])) {
$uuid = $result['uuid'];
2022-04-17 20:10:53 -07:00
2022-05-31 21:11:21 +02:00
DB::getInstance()->insert('users_integrations', [
User Integrations systems (#2606) * Initial work for User Integrations systems * Convert a few endpoints to new user integration system * Finish minecraft part to new User Integration system * Fixes verify banner issue https://github.com/NamelessMC/Nameless/issues/2052 Fixes https://github.com/NamelessMC/Nameless/issues/2052 * Convert discord to new user integrations system * Update fields to show user integrations * Add user integrations to StaffCP user page / move over * Update UserInfo and Rename MinecraftVerify endpoint * Rework user listing endpoint * Password check never returns null * Add support for offline mode uuid * Fix documentation phpstan warnings * else if * remove die() * Revamp registration page * add integrations settings page * Convert authme & fix phpstan issues * refix settings page * Load uuid when user is loaded * Redirect user to complete required integrations * Fix translation for user connections page * Rework integrations registration in Register Endpoint Completes https://github.com/NamelessMC/Nameless/issues/2516 * make getIntegration ignore case sensitive * Update installer * Update upgrader script to convert users * Fix index for user integrations * Remove uuid from user data * Misc * Remove one unused query * Add event for integration linking, verify and unlink * Finish user transformer, Finish user integrations * Thx phpstan * Fix phpdocs * Fix user reports page * Remove validation banner * Change default field value * resolve samerton feedback * don't clean when inserting data * don't clean event data * remove more clean * increase reset_code length from 60 to 64 * pr13 confirmed * one more clean * Remove API verification setting * Register integrations edit permission * Resolve a few requested changes * Rework username and identifier validation * Add button to sync user integration * Fix Synchronisation text * Fix is verified term Co-authored-by: Robin <robinslot@hotmail.nl> Co-authored-by: Robin <robin+git@rkslot.nl>
2022-04-16 18:42:24 +02:00
'integration_id' => 1,
'user_id' => 1,
'identifier' => $uuid,
'username' => $username,
2022-05-31 11:29:47 -06:00
'verified' => true,
User Integrations systems (#2606) * Initial work for User Integrations systems * Convert a few endpoints to new user integration system * Finish minecraft part to new User Integration system * Fixes verify banner issue https://github.com/NamelessMC/Nameless/issues/2052 Fixes https://github.com/NamelessMC/Nameless/issues/2052 * Convert discord to new user integrations system * Update fields to show user integrations * Add user integrations to StaffCP user page / move over * Update UserInfo and Rename MinecraftVerify endpoint * Rework user listing endpoint * Password check never returns null * Add support for offline mode uuid * Fix documentation phpstan warnings * else if * remove die() * Revamp registration page * add integrations settings page * Convert authme & fix phpstan issues * refix settings page * Load uuid when user is loaded * Redirect user to complete required integrations * Fix translation for user connections page * Rework integrations registration in Register Endpoint Completes https://github.com/NamelessMC/Nameless/issues/2516 * make getIntegration ignore case sensitive * Update installer * Update upgrader script to convert users * Fix index for user integrations * Remove uuid from user data * Misc * Remove one unused query * Add event for integration linking, verify and unlink * Finish user transformer, Finish user integrations * Thx phpstan * Fix phpdocs * Fix user reports page * Remove validation banner * Change default field value * resolve samerton feedback * don't clean when inserting data * don't clean event data * remove more clean * increase reset_code length from 60 to 64 * pr13 confirmed * one more clean * Remove API verification setting * Register integrations edit permission * Resolve a few requested changes * Rework username and identifier validation * Add button to sync user integration * Fix Synchronisation text * Fix is verified term Co-authored-by: Robin <robinslot@hotmail.nl> Co-authored-by: Robin <robin+git@rkslot.nl>
2022-04-16 18:42:24 +02:00
'date' => date('U'),
]);
}
}
2022-05-31 11:29:47 -06:00
DatabaseInitialiser::runPostUser();
Config::set('core.installed', true);
echo PHP_EOL . '✅ Installation complete! (Took ' . round(microtime(true) - $start, 2) . ' seconds)' . PHP_EOL;
echo PHP_EOL . '🖥 URL: http://' . $conf['core']['hostname'] . $conf['core']['path'];
echo PHP_EOL . '🔑 Admin username: ' . $username;
echo PHP_EOL . '🔑 Admin email: ' . $email;
echo PHP_EOL . '🔑 Admin password: ' . $password;
echo PHP_EOL;
exit(0);