Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove install page #2279

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 0 additions & 181 deletions app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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', '<font color="#FF0000">Your PHP installation does not support XSL. Please install the XSL extension.</font>');
}

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 .= '<extcurl>0</extcurl>';
} else {
$xml .= '<extcurl>1</extcurl>';
}

if (function_exists('json_encode') === false) {
$xml .= '<extjson>0</extjson>';
} else {
$xml .= '<extjson>1</extjson>';
}

if (function_exists('mb_detect_encoding') === false) {
$xml .= '<extmbstring>0</extmbstring>';
} else {
$xml .= '<extmbstring>1</extmbstring>';
}

if (class_exists('PDO') === false) {
$xml .= '<extpdo>0</extpdo>';
} else {
$xml .= '<extpdo>1</extpdo>';
}

$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 .= '<connectiondb_type>' . $db_type . '</connectiondb_type>';
$xml .= '<connectiondb_host>' . $db_host . '</connectiondb_host>';
$xml .= '<connectiondb_login>' . $db_user . '</connectiondb_login>';
$xml .= '<connectiondb_name>' . $db_name . '</connectiondb_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 .= '<connectiondb>1</connectiondb>';
} catch (Exception) {
$xml .= '<connectiondb>0</connectiondb>';
}

// check if the backup directory is writable
if (!is_writable(Storage::path('inbox'))) {
$xml .= '<backupwritable>0</backupwritable>';
} else {
$xml .= '<backupwritable>1</backupwritable>';
}

// check if the upload directory is writable
if (!is_writable(Storage::path('upload'))) {
$xml .= '<uploadwritable>0</uploadwritable>';
} else {
$xml .= '<uploadwritable>1</uploadwritable>';
}

$installed = false;
try {
if (Schema::hasTable(qid('user'))) {
$xml .= '<database>1</database>';
$installed = true;
} else {
$xml .= '<database>0</database>';
}
} catch (Exception) {
$xml .= '<database>0</database>';
}

// If the database already exists and we have all the tables
if (!$installed) {
$xml .= '<dashboard_timeframe>24</dashboard_timeframe>';

// 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 .= '<db_created>0</db_created>';
$xml .= "<alert>* Administrator's email should be a valid email address</alert>";
$valid_email = false;
}
$minimum_password_length = config('cdash.password.min');
if ($valid_email && strlen($admin_password) < $minimum_password_length) {
$xml .= '<db_created>0</db_created>';
$xml .= "<alert>* Administrator's password must be at least $minimum_password_length characters</alert>";
$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 .= "<alert>* 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 .= '</alert>';
$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 .= '<db_created>0</db_created>';
$xml .= '<alert>' . pdo_error() . '</alert>';
$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 .= '<db_created>1</db_created>';
}
}
}
}

$xml .= '</cdash>';

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');
Expand Down
1 change: 0 additions & 1 deletion app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
43 changes: 0 additions & 43 deletions app/Http/Middleware/CheckDatabaseConnection.php

This file was deleted.

75 changes: 0 additions & 75 deletions app/cdash/public/install.xsl

This file was deleted.

55 changes: 0 additions & 55 deletions app/cdash/tests/install_test.php

This file was deleted.

Loading