From 2bcfacc6f8eab710ab1f977285d28cb2e90e04e4 Mon Sep 17 00:00:00 2001
From: William Allen <16820599+williamjallen@users.noreply.github.com>
Date: Tue, 18 Jun 2024 10:40:01 -0400
Subject: [PATCH] Remove install page
---
app/Http/Controllers/AdminController.php | 181 ------------------
app/Http/Kernel.php | 1 -
.../Middleware/CheckDatabaseConnection.php | 43 -----
app/cdash/public/install.xsl | 75 --------
app/cdash/tests/install_test.php | 55 ------
app/cdash/tests/test_install.php | 40 +++-
phpstan-baseline.neon | 44 +----
routes/web.php | 3 -
8 files changed, 44 insertions(+), 398 deletions(-)
delete mode 100644 app/Http/Middleware/CheckDatabaseConnection.php
delete mode 100644 app/cdash/public/install.xsl
delete mode 100644 app/cdash/tests/install_test.php
diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php
index 39b4e7d0fa..881210060d 100644
--- a/app/Http/Controllers/AdminController.php
+++ b/app/Http/Controllers/AdminController.php
@@ -2,16 +2,11 @@
namespace App\Http\Controllers;
use App\Models\User;
-use App\Validators\Password;
use CDash\Model\Project;
-use Exception;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Artisan;
-use Illuminate\Support\Facades\Schema;
-use Illuminate\Support\Facades\Storage;
use Illuminate\View\View;
-use PDO;
require_once 'include/api_common.php';
require_once 'include/ctestparser.php';
@@ -308,182 +303,6 @@ public function upgrade()
->with('xsl_content', generate_XSLT($xml, base_path() . '/app/cdash/public/upgrade', true));
}
- public function install(): View
- {
- @set_time_limit(0);
-
- // This is the installation script for CDash
- if (class_exists('XsltProcessor') === false) {
- return $this->view('cdash', 'Installation')
- ->with('xsl', true)
- ->with('xsl_content', 'Your PHP installation does not support XSL. Please install the XSL extension.');
- }
-
- if (config('app.env') === 'production') {
- return $this->view('cdash', 'Installation')
- ->with('xsl', true)
- ->with('xsl_content', 'CDash is in production mode. Install cannot be accessed. Set APP_ENV=development in your .env file if you want to access the installation.');
- }
-
- $xml = begin_XML_for_XSLT();
-
- if (function_exists('curl_init') === false) {
- $xml .= '0';
- } else {
- $xml .= '1';
- }
-
- if (function_exists('json_encode') === false) {
- $xml .= '0';
- } else {
- $xml .= '1';
- }
-
- if (function_exists('mb_detect_encoding') === false) {
- $xml .= '0';
- } else {
- $xml .= '1';
- }
-
- if (class_exists('PDO') === false) {
- $xml .= '0';
- } else {
- $xml .= '1';
- }
-
- $db_type = config('database.default');
- $database_config = config("database.connections.{$db_type}");
- $db_host = $database_config['host'];
- $db_port = $database_config['port'];
- $db_user = $database_config['username'];
- $db_pass = $database_config['password'];
- $db_name = $database_config['database'];
-
- if (array_key_exists('unix_socket', $database_config) && $database_config['unix_socket']) {
- $db_connection = 'unix_socket';
- } else {
- $db_connection = 'host';
- if ($db_port != '') {
- $db_host = $db_host . ';port=' . $db_port;
- }
- }
-
- $xml .= '' . $db_type . '';
- $xml .= '' . $db_host . '';
- $xml .= '' . $db_user . '';
- $xml .= '' . $db_name . '';
-
- // Step 1: Check if we can connect to the database
- try {
- $pdo = new PDO("{$db_type}:{$db_connection}={$db_host}", $db_user, $db_pass);
- $xml .= '1';
- } catch (Exception) {
- $xml .= '0';
- }
-
- // check if the backup directory is writable
- if (!is_writable(Storage::path('inbox'))) {
- $xml .= '0';
- } else {
- $xml .= '1';
- }
-
- // check if the upload directory is writable
- if (!is_writable(Storage::path('upload'))) {
- $xml .= '0';
- } else {
- $xml .= '1';
- }
-
- $installed = false;
- try {
- if (Schema::hasTable(qid('user'))) {
- $xml .= '1';
- $installed = true;
- } else {
- $xml .= '0';
- }
- } catch (Exception) {
- $xml .= '0';
- }
-
- // If the database already exists and we have all the tables
- if (!$installed) {
- $xml .= '24';
-
- // If we should create the tables
- @$Submit = $_POST['Submit'];
- if ($Submit) {
- $admin_email = $_POST['admin_email'];
- $admin_password = $_POST['admin_password'];
-
- $valid_email = true;
-
- if (strlen($admin_email) < 6 || !str_contains($admin_email, '@')) {
- $xml .= '0';
- $xml .= "* Administrator's email should be a valid email address";
- $valid_email = false;
- }
- $minimum_password_length = config('cdash.password.min');
- if ($valid_email && strlen($admin_password) < $minimum_password_length) {
- $xml .= '0';
- $xml .= "* Administrator's password must be at least $minimum_password_length characters";
- $valid_email = false;
- }
- if ($valid_email) {
- $password_validator = new Password;
- $complexity_count = config('cdash.password.count');
- $complexity = $password_validator->computeComplexity($admin_password, $complexity_count);
- $minimum_complexity = config('cdash.password.complexity');
- if ($complexity < $minimum_complexity) {
- $xml .= "* Administrator's password is not complex enough. ";
- if ($complexity_count > 1) {
- $xml .= "It must contain at least $complexity_count characters from $minimum_complexity of the following types: uppercase, lowercase, numbers, and symbols.";
- } else {
- $xml .= "It must contain at least $minimum_complexity of the following: uppercase, lowercase, numbers, and symbols.";
- }
- $xml .= '';
- $valid_email = false;
- }
- }
-
- if ($valid_email) {
- $db_created = true;
- $sql = $db_type === 'mysql' ? "CREATE DATABASE IF NOT EXISTS `{$db_name}`" : "CREATE DATABASE {$db_name}";
-
- try {
- $pdo->exec($sql);
- } catch (Exception $exception) {
- if ($db_type !== 'pgsql' || !str_contains($exception->getMessage(), 'already exists')) {
- $xml .= '0';
- $xml .= '' . pdo_error() . '';
- $db_created = false;
- }
- }
-
- if ($db_created) {
- Artisan::call('migrate --force');
-
- $user = new \CDash\Model\User();
- $user->Email = $admin_email;
- $user->Password = password_hash($admin_password, PASSWORD_DEFAULT);
- $user->FirstName = 'administrator';
- $user->Institution = 'Kitware Inc.';
- $user->Admin = 1;
- $user->Save();
- $xml .= '1';
- }
- }
- }
- }
-
- $xml .= '';
-
- return $this->view('cdash', 'Installation')
- ->with('xsl', true)
- ->with('xsl_content', generate_XSLT($xml, base_path() . '/app/cdash/public/install', true));
- }
-
public function userStatistics(): \Illuminate\Http\Response
{
return response()->angular_view('userStatistics');
diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php
index 409fe4d17a..e9bf10cda0 100755
--- a/app/Http/Kernel.php
+++ b/app/Http/Kernel.php
@@ -15,7 +15,6 @@ class Kernel extends HttpKernel
*/
protected $middleware = [
\App\Http\Middleware\CheckForMaintenanceMode::class,
- \App\Http\Middleware\CheckDatabaseConnection::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
\App\Http\Middleware\TrustProxies::class,
diff --git a/app/Http/Middleware/CheckDatabaseConnection.php b/app/Http/Middleware/CheckDatabaseConnection.php
deleted file mode 100644
index 62faef1bea..0000000000
--- a/app/Http/Middleware/CheckDatabaseConnection.php
+++ /dev/null
@@ -1,43 +0,0 @@
-fullUrl(), $exempted_endpoint) !== false) {
- $skip_check = true;
- }
- }
-
- if (!$skip_check) {
- try {
- \DB::connection()->getPdo();
- if (!Schema::hasTable('build')) {
- throw new \Exception("build table missing");
- }
- } catch (\Exception $e) {
- if (config('app.env') == 'production') {
- \App::abort(503, 'CDash cannot connect to the database.');
- } else {
- return redirect(url('/install'));
- }
- }
- }
- return $next($request);
- }
-}
diff --git a/app/cdash/public/install.xsl b/app/cdash/public/install.xsl
deleted file mode 100644
index c4698125d6..0000000000
--- a/app/cdash/public/install.xsl
+++ /dev/null
@@ -1,75 +0,0 @@
-
-
-
-
-
-
-
-
-
-Please follow the installation step to make sure your system meets the requirements.
-
-Cannot connect to on using login .
-Make sure you have modified the settings in the config.php file.
-
-
With databases other than mysql, make sure that the database has been created manually before running this installation.
-
-
-
-
-
-The database already exists. Quitting installation script.
-Click here to access the main CDash page
-
-
-
-Your PHP installation does not support cURL. Please install the cURL extension.
-
-
-Your PHP installation does not support JSON. Please install the JSON extension.
-
-
-Your PHP installation does not support multibyte strings. Please install the multibyte string extension.
-
-
-Your PHP installation does not support PDO. Please install the PDO extension.
-
-
-
-Your backup directory is not writable, make sure that the web process can write into the directory.
-
-
-Your upload directory is not writable, make sure that the web process can write into the directory.
-
-
-
-
-The CDash database has been successfully created!
-Click here to create a new project.
-
-
-
-Please review the settings of your config.php file below and click install to install the SQL tables.
-
-
-
-
-
-
-
-
-
-
diff --git a/app/cdash/tests/install_test.php b/app/cdash/tests/install_test.php
deleted file mode 100644
index 70d47ca368..0000000000
--- a/app/cdash/tests/install_test.php
+++ /dev/null
@@ -1,55 +0,0 @@
-databaseName = $db_config['database'];
- }
-
- public function install($start_with_empty_db = false)
- {
- //double check that it's the testing database before doing anything hasty...
- if ($this->databaseName !== 'cdash4simpletest') {
- $this->fail("can only test on a database named 'cdash4simpletest'");
- return 1;
- }
-
- //drop any old testing database before testing install
- $success = $this->db->drop($this->databaseName);
- if (!$success) {
- $this->fail('Error dropping database');
- return 1;
- }
-
- if ($start_with_empty_db) {
- $this->db->create($this->databaseName);
- }
-
- $this->get($this->url . '/install');
- if (!$this->setFieldByName('admin_email', 'simpletest@localhost')) {
- $this->fail('Set admin email returned false');
- return 1;
- }
- if (!$this->setFieldByName('admin_password', 'simpletest')) {
- $this->fail('Set admin password returned false');
- return 1;
- }
- $this->clickSubmitByName('Submit');
- $response = $this->getBrowser()->getContentAsText();
- if (strpos($response, 'successfully created') === false) {
- $this->fail("Unable to create database.");
- return 1;
- }
- $this->pass('Passed');
- }
-}
diff --git a/app/cdash/tests/test_install.php b/app/cdash/tests/test_install.php
index 8775666a37..3ffded3754 100644
--- a/app/cdash/tests/test_install.php
+++ b/app/cdash/tests/test_install.php
@@ -1,16 +1,50 @@
databaseName = $db_config['database'];
}
public function testInstall()
{
- $this->install();
+ //double check that it's the testing database before doing anything hasty...
+ if ($this->databaseName !== 'cdash4simpletest') {
+ $this->fail("can only test on a database named 'cdash4simpletest'");
+ return 1;
+ }
+
+ //drop any old testing database before testing install
+ $success = $this->db->drop($this->databaseName);
+ if (!$success) {
+ $this->fail('Error dropping database');
+ return 1;
+ }
+
+ $this->db->create($this->databaseName);
+
+ Artisan::call('migrate', ['--force' => true]);
+
+ Artisan::call('user:save', [
+ '--email' => 'simpletest@localhost',
+ '--firstname' => 'administrator',
+ '--lastname' => '',
+ '--password' => 'simpletest',
+ '--institution' => 'Kitware Inc.',
+ '--admin' => 1,
+ ]);
+
+ $this->pass('Passed');
}
}
diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
index b5f728abef..f4fcdfe5c9 100644
--- a/phpstan-baseline.neon
+++ b/phpstan-baseline.neon
@@ -231,7 +231,7 @@ parameters:
#^Call to deprecated function pdo_error\\(\\)\\:
04/01/2023$#
"""
- count: 2
+ count: 1
path: app/Http/Controllers/AdminController.php
-
@@ -290,11 +290,6 @@ parameters:
count: 1
path: app/Http/Controllers/AdminController.php
- -
- message: "#^Loose comparison via \"\\!\\=\" is not allowed\\.$#"
- count: 1
- path: app/Http/Controllers/AdminController.php
-
-
message: "#^Method App\\\\Http\\\\Controllers\\\\AdminController\\:\\:removeBuilds\\(\\) never returns Illuminate\\\\Http\\\\RedirectResponse so it can be removed from the return type\\.$#"
count: 1
@@ -312,7 +307,7 @@ parameters:
-
message: "#^Only booleans are allowed in an if condition, mixed given\\.$#"
- count: 10
+ count: 9
path: app/Http/Controllers/AdminController.php
-
@@ -320,11 +315,6 @@ parameters:
count: 3
path: app/Http/Controllers/AdminController.php
- -
- message: "#^Variable \\$pdo might not be defined\\.$#"
- count: 1
- path: app/Http/Controllers/AdminController.php
-
-
message: "#^Access to an undefined property App\\\\Http\\\\Controllers\\\\Auth\\\\LoginController\\:\\:\\$decayMinutes\\.$#"
count: 1
@@ -2509,11 +2499,6 @@ parameters:
count: 1
path: app/Http/Middleware/Admin.php
- -
- message: "#^Loose comparison via \"\\=\\=\" is not allowed\\.$#"
- count: 1
- path: app/Http/Middleware/CheckDatabaseConnection.php
-
-
message: "#^PHPDoc type array of property App\\\\Http\\\\Middleware\\\\CheckForMaintenanceMode\\:\\:\\$except is not the same as PHPDoc type array\\ of overridden property Illuminate\\\\Foundation\\\\Http\\\\Middleware\\\\PreventRequestsDuringMaintenance\\:\\:\\$except\\.$#"
count: 1
@@ -18046,26 +18031,6 @@ parameters:
count: 1
path: app/cdash/tests/data/queue_test_config.php
- -
- message: "#^Access to an undefined property BaseInstallTestCase\\:\\:\\$databaseName\\.$#"
- count: 2
- path: app/cdash/tests/install_test.php
-
- -
- message: "#^Call to deprecated method pass\\(\\) of class SimpleTestCase\\.$#"
- count: 1
- path: app/cdash/tests/install_test.php
-
- -
- message: "#^Method BaseInstallTestCase\\:\\:install\\(\\) has no return type specified\\.$#"
- count: 1
- path: app/cdash/tests/install_test.php
-
- -
- message: "#^Method BaseInstallTestCase\\:\\:install\\(\\) has parameter \\$start_with_empty_db with no type specified\\.$#"
- count: 1
- path: app/cdash/tests/install_test.php
-
-
message: """
#^Call to deprecated function pdo_fetch_array\\(\\)\\:
@@ -21776,6 +21741,11 @@ parameters:
count: 1
path: app/cdash/tests/test_indexnextprevious.php
+ -
+ message: "#^Call to deprecated method pass\\(\\) of class SimpleTestCase\\.$#"
+ count: 1
+ path: app/cdash/tests/test_install.php
+
-
message: "#^Method InstallTestCase\\:\\:testInstall\\(\\) has no return type specified\\.$#"
count: 1
diff --git a/routes/web.php b/routes/web.php
index b40eafc6c1..936c70a6da 100755
--- a/routes/web.php
+++ b/routes/web.php
@@ -24,9 +24,6 @@
}
Auth::routes($routeList);
-Route::match(['get', 'post'], '/install', 'AdminController@install');
-Route::permanentRedirect('/install.php', url('/install'));
-
Route::get('/oauth/{service}', 'OAuthController@socialite');
Route::get('/oauth/callback/{service}', 'OAuthController@callback');