This repository has been archived on 2022-02-10. You can view files and clone it, but cannot push or open issues or pull requests.
rangitaki/bin/init_rcc.php

77 lines
1.6 KiB
PHP
Raw Permalink Normal View History

2016-04-21 09:56:53 +02:00
<?php
// Marcel Kapfer (mmk2410)
// PHP script for initializing the RCC
// License: MIT
require 'res/php/Config.php';
use mmk2410\rbe\config\Config as Config;
echo 'RCC Initializion Script' . "\n";
$username = readline("Username: ");
if ($username == "") {
echo "No username given. Aborting...\n";
exit();
}
echo 'Password: ';
2016-04-22 18:18:21 +02:00
$password = readline("Password: ");
2016-04-21 09:56:53 +02:00
if ($password == "") {
echo "No password given. Aborting...\n";
exit();
}
2016-05-17 22:37:36 +02:00
$options = [
'cost' => 12
];
$password = password_hash($password, PASSWORD_BCRYPT, $options);
2016-04-21 09:56:53 +02:00
$username = '$username = "' . $username . '";';
2016-05-17 22:37:36 +02:00
$password = '$password = \'' . $password . '\';';
2016-04-21 09:56:53 +02:00
2016-04-22 18:18:21 +02:00
$file = '<?php' . "\n" . $username . "\n" . $password . "\n";
2016-04-21 09:56:53 +02:00
if (file_put_contents('./rcc/password.php', $file)) {
2016-04-22 18:18:21 +02:00
chmod('./rcc/password.php', 0640);
echo "\nPassword successfully saved.\n";
2016-04-21 09:56:53 +02:00
}
$config = new Config('config.yaml', 'vendor/autoload.php');
$yaml = $config->getConfig();
$rccOn = "";
while (!(in_array($rccOn, array("y", "Y", "n", "N")))) {
$rccOn = readline("Enable RCC: (y/n) ");
}
if (in_array($rccOn, array("y", "Y"))) {
$yaml["rcc"]["rcc"] = "on";
} else {
$yaml["rcc"]["rcc"] = "off";
}
$apiOn = "";
while (!(in_array($apiOn, array("Y", "y", "n", "N")))) {
$apiOn = readline("Enable RCC API: (y/n) ");
}
if (in_array($apiOn, array("y", "Y"))) {
$yaml["rcc"]["api"] = "on";
} else {
$yaml["rcc"]["api"] = "off";
}
$config = new Config('config.yaml', 'vendor/autoload.php');
if ($config->writeConfig($yaml)) {
echo "Changes saved.\n";
} else {
echo "Failed to save changes.\n";
}