2020-03-18 10:40:15 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Http\Requests\Setup\StoreSetupRequest;
|
2020-03-25 22:34:35 +01:00
|
|
|
use App\Jobs\Account\CreateAccount;
|
2020-03-18 10:40:15 +01:00
|
|
|
use App\Models\Account;
|
|
|
|
use App\Utils\SystemHealth;
|
2020-03-26 22:43:44 +01:00
|
|
|
use Illuminate\Http\Response;
|
2020-03-18 10:40:15 +01:00
|
|
|
use Illuminate\Support\Facades\Artisan;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class SetupController
|
|
|
|
*/
|
|
|
|
class SetupController extends Controller
|
|
|
|
{
|
2020-03-21 06:37:30 +01:00
|
|
|
public function index()
|
|
|
|
{
|
2020-03-26 04:23:57 +01:00
|
|
|
$data = SystemHealth::check();
|
2020-03-18 10:40:15 +01:00
|
|
|
|
2020-03-26 04:23:57 +01:00
|
|
|
if ($data['system_health'] !== false) {
|
|
|
|
return view('setup.index', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($system_health !== true) {
|
2020-03-24 10:15:30 +01:00
|
|
|
return redirect('/');
|
2020-03-26 04:23:57 +01:00
|
|
|
}
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2020-03-18 10:40:15 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
public function doSetup(StoreSetupRequest $request)
|
|
|
|
{
|
2020-03-18 10:40:15 +01:00
|
|
|
$_ENV['APP_URL'] = $request->input('url');
|
|
|
|
$_ENV['APP_DEBUG'] = $request->input('debug') ? 'true' : 'false';
|
|
|
|
$_ENV['REQUIRE_HTTPS'] = $request->input('https') ? 'true' : 'false';
|
2020-03-21 06:37:30 +01:00
|
|
|
$_ENV['DB_TYPE'] = 'mysql';
|
2020-03-18 10:40:15 +01:00
|
|
|
$_ENV['DB_HOST1'] = $request->input('host');
|
|
|
|
$_ENV['DB_DATABASE1'] = $request->input('db_username');
|
|
|
|
$_ENV['DB_USERNAME1'] = $request->input('db_password');
|
|
|
|
$_ENV['DB_PASSWORD1'] = $request->input('db_password');
|
2020-03-21 06:37:30 +01:00
|
|
|
$_ENV['MAIL_DRIVER'] = $request->input('mail_driver');
|
|
|
|
$_ENV['MAIL_PORT'] = $request->input('port');
|
|
|
|
$_ENV['MAIL_ENCRYPTION'] = $request->input('encryption');
|
|
|
|
$_ENV['MAIL_HOST'] = $request->input('mail_host');
|
|
|
|
$_ENV['MAIL_USERNAME'] = $request->input('mail_username');
|
|
|
|
$_ENV['MAIL_FROM_NAME'] = $request->input('mail_name');
|
|
|
|
$_ENV['MAIL_FROM_ADDRESS'] = $request->input('mail_address');
|
|
|
|
$_ENV['MAIL_PASSWORD'] = $request->input('mail_password');
|
2020-03-18 10:40:15 +01:00
|
|
|
$_ENV['NINJA_ENVIRONMENT'] = 'selfhost';
|
2020-03-21 06:37:30 +01:00
|
|
|
$_ENV['SELF_UPDATER_REPO_VENDOR'] = 'invoiceninja';
|
|
|
|
$_ENV['SELF_UPDATER_REPO_NAME'] = 'invoiceninja';
|
|
|
|
$_ENV['SELF_UPDATER_USE_BRANCH'] = 'v2';
|
|
|
|
$_ENV['SELF_UPDATER_MAILTO_ADDRESS'] = $request->input('mail_address');
|
|
|
|
$_ENV['SELF_UPDATER_MAILTO_NAME'] = $request->input('mail_name');
|
|
|
|
$_ENV['DB_CONNECTION'] = 'db-ninja-01';
|
|
|
|
$_ENV['APP_DEBUG'] = false;
|
2020-03-18 10:40:15 +01:00
|
|
|
|
|
|
|
$config = '';
|
|
|
|
|
|
|
|
foreach ($_ENV as $key => $val) {
|
|
|
|
if (is_array($val)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (preg_match('/\s/', $val)) {
|
|
|
|
$val = "'{$val}'";
|
|
|
|
}
|
|
|
|
$config .= "{$key}={$val}\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
$filePath = base_path().'/.env';
|
|
|
|
$fp = fopen($filePath, 'w');
|
|
|
|
fwrite($fp, $config);
|
|
|
|
fclose($fp);
|
|
|
|
|
|
|
|
Artisan::call('optimize');
|
|
|
|
Artisan::call('migrate');
|
|
|
|
Artisan::call('db:seed');
|
2020-03-24 10:15:30 +01:00
|
|
|
Artisan::call('horizon');
|
2020-03-18 10:40:15 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
if (Account::count() == 0) {
|
|
|
|
$account = CreateAccount::dispatchNow($request->all());
|
|
|
|
}
|
2020-03-18 10:40:15 +01:00
|
|
|
|
|
|
|
return view('index.index');
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2020-03-26 04:23:57 +01:00
|
|
|
|
2020-03-26 22:43:44 +01:00
|
|
|
/**
|
|
|
|
* Return status based on check of database connection.
|
|
|
|
*
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function checkDB(): Response
|
2020-03-26 04:23:57 +01:00
|
|
|
{
|
2020-03-28 04:45:11 +01:00
|
|
|
if (Account::count() == 0) {
|
|
|
|
}
|
2020-03-26 22:43:44 +01:00
|
|
|
|
|
|
|
// test db - > /setup/check_db (POST) please send array of DB variables - response 200/success or 400 [message]
|
|
|
|
// test mail -> /setup/check_mail (POST) please send array of MAIL xvariables - response 200/success or 400 [message]
|
|
|
|
|
|
|
|
$randomStatus = rand(0, 1);
|
|
|
|
|
2020-03-28 04:45:11 +01:00
|
|
|
if ($randomStatus) {
|
2020-03-26 22:43:44 +01:00
|
|
|
return response([], 200);
|
2020-03-26 04:23:57 +01:00
|
|
|
}
|
2020-03-26 22:43:44 +01:00
|
|
|
|
|
|
|
return response([], 400);
|
2020-03-26 04:23:57 +01:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:43:44 +01:00
|
|
|
/**
|
|
|
|
* Return status based on check of SMTP connection.
|
|
|
|
*
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function checkMail(): Response
|
2020-03-26 04:23:57 +01:00
|
|
|
{
|
2020-03-28 04:45:11 +01:00
|
|
|
if (Account::count() == 0) {
|
|
|
|
}
|
2020-03-26 22:43:44 +01:00
|
|
|
|
|
|
|
// test db - > /setup/check_db (POST) please send array of DB variables - response 200/success or 400 [message]
|
|
|
|
// test mail -> /setup/check_mail (POST) please send array of MAIL variables - response 200/success or 400 [message]
|
|
|
|
|
|
|
|
$randomStatus = rand(0, 1);
|
|
|
|
|
2020-03-28 04:45:11 +01:00
|
|
|
if ($randomStatus) {
|
2020-03-26 22:43:44 +01:00
|
|
|
return response([], 200);
|
2020-03-26 04:23:57 +01:00
|
|
|
}
|
2020-03-26 22:43:44 +01:00
|
|
|
|
|
|
|
return response([], 400);
|
2020-03-26 04:23:57 +01:00
|
|
|
}
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|