-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-> Key regen logic
- Loading branch information
Showing
6 changed files
with
198 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of MythicalClient. | ||
* Please view the LICENSE file that was distributed with this source code. | ||
* | ||
* MIT License | ||
* | ||
* (c) MythicalSystems <mythicalsystems.xyz> - All rights reserved | ||
* (c) NaysKutzu <nayskutzu.xyz> - All rights reserved | ||
* (c) Cassian Gherman <nayskutzu.xyz> - All rights reserved | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
namespace MythicalClient\Cli\Commands; | ||
|
||
use MythicalClient\Cli\App; | ||
use MythicalClient\Cli\CommandBuilder; | ||
|
||
class Colors extends App implements CommandBuilder | ||
{ | ||
public static function execute(array $args): void | ||
{ | ||
$app = App::getInstance(); | ||
$colors = 'Colors: &0Black&r, &1Dark Blue&r, &2Dark Green&r, &3Dark Aqua&r, &4Dark Red&r, &5Dark Purple&r, &6Gold&r, &7Gray&r, &8Dark Gray&r, &9Blue&r, &aGreen&r, &bAqua&r, &cRed&r, &dLight Purple&r, &eYellow&r, &rWhite&r, &rReset&r, &lBold&r, &nUnderline&r, &mStrikethrough&r'; | ||
|
||
$app->send($colors); | ||
$colors = "&0 0 &1 1 &2 2 &3 3 &4 4 &5 5 &6 6 &7 7 &8 8 &9 9 &a a &b b &c c &d d &e e &r r &l l &n n&r &m m &r"; | ||
$app->send($colors); | ||
} | ||
|
||
public static function getDescription(): string | ||
{ | ||
return '&c&l&n&oS&6&l&n&ou&e&l&n&op&a&l&n&op&3&l&n&oo&9&l&n&or&5&l&n&ot&c&l&n&oe&6&l&n&od&e&l&n&o &a&l&n&oC&3&l&n&oo&9&l&n&ol&5&l&n&oo&c&l&n&or&6&l&n&os&e&l&n&o &a&l&n&oB&3&l&n&oy&9&l&n&o &5&l&n&oO&c&l&n&ou&6&l&n&or&e&l&n&o &a&l&n&oA&3&l&n&ow&9&l&n&os&5&l&n&oo&c&l&n&om&6&l&n&oe&e&l&n&o &a&l&n&oC&3&l&n&oL&9&l&n&oI'; | ||
} | ||
|
||
public static function getSubCommands(int $index): array | ||
{ | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of MythicalClient. | ||
* Please view the LICENSE file that was distributed with this source code. | ||
* | ||
* MIT License | ||
* | ||
* (c) MythicalSystems <mythicalsystems.xyz> - All rights reserved | ||
* (c) NaysKutzu <nayskutzu.xyz> - All rights reserved | ||
* (c) Cassian Gherman <nayskutzu.xyz> - All rights reserved | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
namespace MythicalClient\Cli\Commands; | ||
|
||
use MythicalClient\Cli\App; | ||
use MythicalClient\Cli\CommandBuilder; | ||
use MythicalClient\Config\ConfigInterface; | ||
use MythicalSystems\Utils\XChaCha20; | ||
|
||
class KeyRegen extends App implements CommandBuilder | ||
{ | ||
public static function execute(array $args): void | ||
{ | ||
$app = App::getInstance(); | ||
if (in_array('-force', $args)) { | ||
$isForced = true; | ||
} else { | ||
$isForced = false; | ||
} | ||
|
||
if (!$isForced) { | ||
$app->send('&7Are you sure you want to reset the key? This will corupt all data there may be in the database! Type &ayes &7to continue or &cno &7to cancel.'); | ||
$app->send('&7This action is irreversible!'); | ||
$app->send('&7Type your answer below:'); | ||
$line = trim(readline('> ')); | ||
if ($line !== 'yes') { | ||
$app->send('&cAction cancelled.'); | ||
return; | ||
} else { | ||
$isForced = true; // If the user types yes, then we can force the key reset | ||
} | ||
} | ||
|
||
if ($isForced) { | ||
$mainApp = \MythicalClient\App::getInstance(true); | ||
$mainApp->loadEnv(); | ||
$mainApp->getLogger()->warning('Old encryption key was: '.$_ENV['DATABASE_ENCRYPTION_KEY']); | ||
$app->send(message: '&7Old encryption key was: &e'.$_ENV['DATABASE_ENCRYPTION_KEY']); | ||
$newKey = XChaCha20::generateStrongKey(true); | ||
$mainApp->updateEnvValue('DATABASE_ENCRYPTION_KEY',$newKey,true); | ||
sleep(3); | ||
$_ENV['DATABASE_ENCRYPTION_KEY'] = $newKey; | ||
$mainApp->getLogger()->warning('New encryption key is: '.$_ENV['DATABASE_ENCRYPTION_KEY']); | ||
$app->send(message: '&7New encryption key is: &e'.$_ENV['DATABASE_ENCRYPTION_KEY']); | ||
$app->send(message: '&7Key reset successfully!'); | ||
} else { | ||
$app->send('&cAction cancelled.'); | ||
return; | ||
} | ||
} | ||
|
||
public static function getDescription(): string | ||
{ | ||
return 'Regenerate the encryption key'; | ||
} | ||
|
||
public static function getSubCommands(int $index): array | ||
{ | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters