Catch open basedir errors.

This commit is contained in:
James Cole
2018-04-27 12:58:43 +02:00
parent 5d4467a6c0
commit ac419e01d3
2 changed files with 51 additions and 14 deletions

View File

@@ -25,7 +25,9 @@ namespace FireflyIII\Http\Controllers\System;
use Artisan; use Artisan;
use Exception;
use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;
use Laravel\Passport\Passport; use Laravel\Passport\Passport;
use Log; use Log;
use phpseclib\Crypt\RSA; use phpseclib\Crypt\RSA;
@@ -35,8 +37,12 @@ use phpseclib\Crypt\RSA;
*/ */
class InstallController extends Controller class InstallController extends Controller
{ {
/** @var string */
public const FORBIDDEN_ERROR = 'Internal PHP function "proc_close" is disabled for your installation. Auto-migration is not possible.'; public const FORBIDDEN_ERROR = 'Internal PHP function "proc_close" is disabled for your installation. Auto-migration is not possible.';
/** @var string */
public const BASEDIR_ERROR = 'Firefly III cannot execute the upgrade commands. It is not allowed to because of an open_basedir restriction.';
/** @var string */
public const OTHER_ERROR = 'An unknown error prevented Firefly III from executing the upgrade commands. Sorry.';
/** @noinspection MagicMethodsValidityInspection */ /** @noinspection MagicMethodsValidityInspection */
/** @noinspection PhpMissingParentConstructorInspection */ /** @noinspection PhpMissingParentConstructorInspection */
/** /**
@@ -84,17 +90,28 @@ class InstallController extends Controller
} }
/** /**
* @return \Illuminate\Http\JsonResponse * @return JsonResponse
*/ */
public function migrate() public function migrate(): JsonResponse
{ {
if ($this->hasForbiddenFunctions()) { if ($this->hasForbiddenFunctions()) {
return response()->json(['error' => true, 'message' => self::FORBIDDEN_ERROR]); return response()->json(['error' => true, 'message' => self::FORBIDDEN_ERROR]);
} }
Log::debug('Am now calling migrate routine...'); try {
Artisan::call('migrate', ['--seed' => true, '--force' => true]); Log::debug('Am now calling migrate routine...');
Log::debug(Artisan::output()); Artisan::call('migrate', ['--seed' => true, '--force' => true]);
Log::debug(Artisan::output());
} catch (Exception $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
if (strpos($e->getMessage(), 'open_basedir restriction in effect')) {
return response()->json(['error' => true, 'message' => self::BASEDIR_ERROR]);
}
return response()->json(['error' => true, 'message' => self::OTHER_ERROR]);
}
return response()->json(['error' => false, 'message' => 'OK']); return response()->json(['error' => false, 'message' => 'OK']);
} }
@@ -102,14 +119,24 @@ class InstallController extends Controller
/** /**
* @return \Illuminate\Http\JsonResponse * @return \Illuminate\Http\JsonResponse
*/ */
public function upgrade() public function upgrade(): JsonResponse
{ {
if ($this->hasForbiddenFunctions()) { if ($this->hasForbiddenFunctions()) {
return response()->json(['error' => true, 'message' => self::FORBIDDEN_ERROR]); return response()->json(['error' => true, 'message' => self::FORBIDDEN_ERROR]);
} }
Log::debug('Am now calling upgrade database routine...'); try {
Artisan::call('firefly:upgrade-database'); Log::debug('Am now calling upgrade database routine...');
Log::debug(Artisan::output()); Artisan::call('firefly:upgrade-database');
Log::debug(Artisan::output());
} catch (Exception $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
if (strpos($e->getMessage(), 'open_basedir restriction in effect')) {
return response()->json(['error' => true, 'message' => self::BASEDIR_ERROR]);
}
return response()->json(['error' => true, 'message' => self::OTHER_ERROR]);
}
return response()->json(['error' => false, 'message' => 'OK']); return response()->json(['error' => false, 'message' => 'OK']);
} }
@@ -122,9 +149,19 @@ class InstallController extends Controller
if ($this->hasForbiddenFunctions()) { if ($this->hasForbiddenFunctions()) {
return response()->json(['error' => true, 'message' => self::FORBIDDEN_ERROR]); return response()->json(['error' => true, 'message' => self::FORBIDDEN_ERROR]);
} }
Log::debug('Am now calling verify database routine...'); try {
Artisan::call('firefly:verify'); Log::debug('Am now calling verify database routine...');
Log::debug(Artisan::output()); Artisan::call('firefly:verify');
Log::debug(Artisan::output());
} catch (Exception $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
if (strpos($e->getMessage(), 'open_basedir restriction in effect')) {
return response()->json(['error' => true, 'message' => self::BASEDIR_ERROR]);
}
return response()->json(['error' => true, 'message' => self::OTHER_ERROR]);
}
return response()->json(['error' => false, 'message' => 'OK']); return response()->json(['error' => false, 'message' => 'OK']);
} }

View File

@@ -101,6 +101,6 @@ function completeDone() {
function displaySoftFail(message) { function displaySoftFail(message) {
$('#status-box').html('<i class="fa fa-warning"></i> ' + message + '<br /><br />Please read the ' + $('#status-box').html('<i class="fa fa-warning"></i> ' + message + '<br /><br />Please read the ' +
'<a href="http://firefly-iii.readthedocs.io/en/latest/support/faq.html#i-get-an-error-about-proc-close-being-disabled">' + '<a href="http://firefly-iii.readthedocs.io/en/latest/support/faq.html#i-get-an-error-during-the-automatic-installation-and-upgrade">' +
'official documentation</a> about this, and upgrade by hand.'); 'official documentation</a> about this, and upgrade by hand.');
} }