From 87667be90c5158a847b47b2c8479f7616a0bd3aa Mon Sep 17 00:00:00 2001 From: Raish Date: Thu, 24 Jun 2021 07:28:35 +0000 Subject: [PATCH] add domain verify feature --- .../DatabaseConfigurationController.php | 8 - .../V1/Onboarding/RequirementsController.php | 3 +- app/Space/EnvironmentManager.php | 64 +++++ app/Space/RequirementsChecker.php | 112 +++++++- config/crater.php | 22 +- resources/assets/js/plugins/en.json | 3 +- .../js/views/wizard/WizardDatabaseStep.vue | 14 +- .../views/wizard/database/MysqlDatabase.vue | 2 +- .../views/wizard/database/PgsqlDatabase.vue | 2 +- .../views/wizard/database/SqliteDatabase.vue | 2 +- .../views/wizard/database/SqlsrvDatabase.vue | 264 ------------------ 11 files changed, 213 insertions(+), 283 deletions(-) delete mode 100644 resources/assets/js/views/wizard/database/SqlsrvDatabase.vue diff --git a/app/Http/Controllers/V1/Onboarding/DatabaseConfigurationController.php b/app/Http/Controllers/V1/Onboarding/DatabaseConfigurationController.php index 1722ef61..a6ec8954 100644 --- a/app/Http/Controllers/V1/Onboarding/DatabaseConfigurationController.php +++ b/app/Http/Controllers/V1/Onboarding/DatabaseConfigurationController.php @@ -77,14 +77,6 @@ class DatabaseConfigurationController extends Controller break; - case 'sqlsrv': - $databaseData = [ - 'driver' => 'sqlsrv', - 'host' => '127.0.0.1', - 'port' => 1433, - ]; - - break; } diff --git a/app/Http/Controllers/V1/Onboarding/RequirementsController.php b/app/Http/Controllers/V1/Onboarding/RequirementsController.php index c0cd7592..43fdab99 100755 --- a/app/Http/Controllers/V1/Onboarding/RequirementsController.php +++ b/app/Http/Controllers/V1/Onboarding/RequirementsController.php @@ -28,9 +28,10 @@ class RequirementsController extends Controller */ public function requirements() { - $phpSupportInfo = $this->requirements->checkPHPversion( + $phpSupportInfo = $this->requirements->checkPHPVersion( config('installer.core.minPhpVersion') ); + $requirements = $this->requirements->check( config('installer.requirements') ); diff --git a/app/Space/EnvironmentManager.php b/app/Space/EnvironmentManager.php index 345dfb4b..f5a23d70 100755 --- a/app/Space/EnvironmentManager.php +++ b/app/Space/EnvironmentManager.php @@ -78,6 +78,15 @@ class EnvironmentManager try { $this->checkDatabaseConnection($request); + $requirement = $this->checkVersionRequirements($request); + + if ($requirement) { + return [ + 'error' => 'minimum_version_requirement', + 'requirement' => $requirement, + ]; + } + if (\Schema::hasTable('users')) { return [ 'error' => 'database_should_be_empty', @@ -134,6 +143,7 @@ class EnvironmentManager { $connection = $request->database_connection; + $settings = config("database.connections.$connection"); $settings = config("database.connections.$connection"); $connectionArray = array_merge($settings, [ @@ -161,6 +171,60 @@ class EnvironmentManager return DB::connection()->getPdo(); } + /** + * + * @param DatabaseEnvironmentRequest $request + * @return bool + */ + private function checkVersionRequirements(DatabaseEnvironmentRequest $request) + { + $connection = $request->database_connection; + + $checker = new RequirementsChecker(); + + $phpSupportInfo = $checker->checkPHPVersion( + config('crater.min_php_version') + ); + + if (! $phpSupportInfo['supported']) { + return $phpSupportInfo; + } + + $dbSupportInfo = []; + + switch ($connection) { + case 'mysql': + $dbSupportInfo = $checker->checkMysqlVersion( + config('crater.min_mysql_version') + ); + + break; + + case 'pgsql': + $conn = pg_connect("host={$request->database_hostname} port={$request->database_port} dbname={$request->database_name} user={$request->database_username} password={$request->database_password}"); + $dbSupportInfo = $checker->checkPgsqlVersion( + $conn, + config('crater.min_pgsql_version') + ); + + break; + + case 'sqlite': + $dbSupportInfo = $checker->checkSqliteVersion( + config('crater.min_sqlite_version') + ); + + break; + + } + + if (! $dbSupportInfo['supported']) { + return $dbSupportInfo; + } + + return false; + } + /** * Save the mail content to the .env file. * diff --git a/app/Space/RequirementsChecker.php b/app/Space/RequirementsChecker.php index f63992f6..f37c0749 100755 --- a/app/Space/RequirementsChecker.php +++ b/app/Space/RequirementsChecker.php @@ -2,6 +2,8 @@ namespace Crater\Space; +use SQLite3; + class RequirementsChecker { /** @@ -63,7 +65,7 @@ class RequirementsChecker * * @return array */ - public function checkPHPversion(string $minPhpVersion = null) + public function checkPHPVersion(string $minPhpVersion = null) { $minVersionPhp = $minPhpVersion; $currentPhpVersion = $this->getPhpVersionInfo(); @@ -113,4 +115,112 @@ class RequirementsChecker { return $this->_minPhpVersion; } + + /** + * Check PHP version requirement. + * + * @return array + */ + public function checkMysqlVersion(string $minMysqlVersion = null) + { + $minVersionMysql = $minMysqlVersion; + $currentMysqlVersion = $this->getMysqlVersionInfo(); + $supported = false; + + if (version_compare($currentMysqlVersion, $minVersionMysql) >= 0) { + $supported = true; + } + + $phpStatus = [ + 'current' => $currentMysqlVersion, + 'minimum' => $minVersionMysql, + 'supported' => $supported, + ]; + + return $phpStatus; + } + + /** + * Get current Mysql version information. + * + * @return string + */ + private static function getMysqlVersionInfo() + { + $currentVersion = explode(' ', mysqli_get_client_info()); + + return $currentVersion[1]; + } + + /** + * Check Sqlite version requirement. + * + * @return array + */ + public function checkSqliteVersion(string $minSqliteVersion = null) + { + $minVersionSqlite = $minSqliteVersion; + $currentSqliteVersion = $this->getSqliteVersionInfo(); + $supported = false; + + if (version_compare($currentSqliteVersion, $minVersionSqlite) >= 0) { + $supported = true; + } + + $phpStatus = [ + 'current' => $currentSqliteVersion, + 'minimum' => $minVersionSqlite, + 'supported' => $supported, + ]; + + return $phpStatus; + } + + /** + * Get current Sqlite version information. + * + * @return string + */ + private static function getSqliteVersionInfo() + { + $currentVersion = SQLite3::version(); + + return $currentVersion['versionString']; + } + + /** + * Check Pgsql version requirement. + * + * @return array + */ + public function checkPgsqlVersion($conn, string $minPgsqlVersion = null) + { + $minVersionPgsql = $minPgsqlVersion; + $currentPgsqlVersion = $this->getPgsqlVersionInfo($conn); + $supported = false; + + if (version_compare($currentPgsqlVersion, $minVersionPgsql) >= 0) { + $supported = true; + } + + $phpStatus = [ + 'current' => $currentPgsqlVersion, + 'minimum' => $minVersionPgsql, + 'supported' => $supported, + ]; + + return $phpStatus; + } + + /** + * Get current Pgsql version information. + * + * @return string + */ + private static function getPgsqlVersionInfo($conn) + { + $currentVersion = pg_version($conn); + + return $currentVersion['server']; + } } diff --git a/config/crater.php b/config/crater.php index 1a6a9739..72edb960 100644 --- a/config/crater.php +++ b/config/crater.php @@ -3,9 +3,27 @@ return [ /* - * Current version of the application. + * Minimum php version of the application. */ - 'version' => '4.0.0', + 'min_php_version' => '7.4.0', + + /* + * Minimum mysql version of the application. + */ + + 'min_mysql_version' => '5.7.7', + + /* + * Minimum pgsql version of the application. + */ + + 'min_pgsql_version' => '9.2.0', + + /* + * Minimum sqlite version of the application. + */ + + 'min_sqlite_version' => '3.24.0', /* * List of languages supported by Crater. diff --git a/resources/assets/js/plugins/en.json b/resources/assets/js/plugins/en.json index 407aaae5..9b3f0efe 100644 --- a/resources/assets/js/plugins/en.json +++ b/resources/assets/js/plugins/en.json @@ -1109,7 +1109,8 @@ "database_variables_save_error": "Cannot write configuration to .env file. Please check its file permissions", "mail_variables_save_error": "Email configuration failed.", "connection_failed": "Database connection failed", - "database_should_be_empty": "Database should be empty" + "database_should_be_empty": "Database should be empty", + "minimum_version_requirement": "Minimum {name} version {version} required." }, "success": { "mail_variables_save_successfully": "Email configured successfully", diff --git a/resources/assets/js/views/wizard/WizardDatabaseStep.vue b/resources/assets/js/views/wizard/WizardDatabaseStep.vue index 5fd99999..72a1ed80 100644 --- a/resources/assets/js/views/wizard/WizardDatabaseStep.vue +++ b/resources/assets/js/views/wizard/WizardDatabaseStep.vue @@ -19,14 +19,12 @@ import Mysql from './database/MysqlDatabase' import Pgsql from './database/PgsqlDatabase' import Sqlite from './database/SqliteDatabase' -import Sqlsrv from './database/SqlsrvDatabase' import { mapActions } from 'vuex' export default { components: { Mysql, Pgsql, Sqlite, - Sqlsrv, }, data() { return { @@ -36,7 +34,7 @@ export default { isLoading: false, isFetching: false, database_connection: 'mysql', - connections: ['sqlite', 'mysql', 'pgsql', 'sqlsrv'], + connections: ['sqlite', 'mysql', 'pgsql'], } }, created() { @@ -83,6 +81,16 @@ export default { return true } else if (response.data.error) { + if (response.data.requirement) { + this.showNotification({ + type: 'error', + message: this.$t('wizard.errors.' + response.data.error, { + version: response.data.requirement.minimum, + name: this.database_connection, + }), + }) + return + } this.showNotification({ type: 'error', message: this.$t('wizard.errors.' + response.data.error), diff --git a/resources/assets/js/views/wizard/database/MysqlDatabase.vue b/resources/assets/js/views/wizard/database/MysqlDatabase.vue index 4309117c..bfd26683 100644 --- a/resources/assets/js/views/wizard/database/MysqlDatabase.vue +++ b/resources/assets/js/views/wizard/database/MysqlDatabase.vue @@ -150,7 +150,7 @@ export default { database_password: null, app_url: window.location.origin, }, - connections: ['sqlite', 'mysql', 'pgsql', 'sqlsrv'], + connections: ['sqlite', 'mysql', 'pgsql'], } }, validations: { diff --git a/resources/assets/js/views/wizard/database/PgsqlDatabase.vue b/resources/assets/js/views/wizard/database/PgsqlDatabase.vue index fee325f6..2185321d 100644 --- a/resources/assets/js/views/wizard/database/PgsqlDatabase.vue +++ b/resources/assets/js/views/wizard/database/PgsqlDatabase.vue @@ -147,7 +147,7 @@ export default { database_password: null, app_url: window.location.origin, }, - connections: ['sqlite', 'mysql', 'pgsql', 'sqlsrv'], + connections: ['sqlite', 'mysql', 'pgsql'], } }, computed: { diff --git a/resources/assets/js/views/wizard/database/SqliteDatabase.vue b/resources/assets/js/views/wizard/database/SqliteDatabase.vue index 19147d07..6daffe91 100644 --- a/resources/assets/js/views/wizard/database/SqliteDatabase.vue +++ b/resources/assets/js/views/wizard/database/SqliteDatabase.vue @@ -94,7 +94,7 @@ export default { database_name: null, app_url: window.location.origin, }, - connections: ['sqlite', 'mysql', 'pgsql', 'sqlsrv'], + connections: ['sqlite', 'mysql', 'pgsql'], } }, validations: { diff --git a/resources/assets/js/views/wizard/database/SqlsrvDatabase.vue b/resources/assets/js/views/wizard/database/SqlsrvDatabase.vue deleted file mode 100644 index fa529a51..00000000 --- a/resources/assets/js/views/wizard/database/SqlsrvDatabase.vue +++ /dev/null @@ -1,264 +0,0 @@ - - -