Skip to content

Commit b4d0165

Browse files
authored
Add database host selection for app quick install (hestiacp#4503)
1 parent 4878540 commit b4d0165

File tree

10 files changed

+28
-6
lines changed

10 files changed

+28
-6
lines changed

web/src/app/System/HestiaApp.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ public function databaseAdd(
200200
string $dbuser,
201201
string $dbpass,
202202
string $dbtype = "mysql",
203+
string $dbhost = "localhost",
203204
string $charset = "utf8mb4",
204205
) {
205206
$v_password = tempnam("/tmp", "hst");
@@ -211,7 +212,7 @@ public function databaseAdd(
211212
$dbuser,
212213
$v_password,
213214
$dbtype,
214-
"localhost",
215+
$dbhost,
215216
$charset,
216217
]);
217218
if (!$status) {

web/src/app/WebApp/AppWizard.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class AppWizard {
1414

1515
private $database_config = [
1616
"database_create" => ["type" => "boolean", "value" => true],
17+
"database_host" => ["type" => "select"],
1718
"database_name" => ["type" => "text", "placeholder" => "auto"],
1819
"database_user" => ["type" => "text", "placeholder" => "auto"],
1920
"database_password" => ["type" => "password", "placeholder" => "auto"],
@@ -72,6 +73,18 @@ public function getOptions() {
7273
]);
7374

7475
if ($this->appsetup->withDatabase()) {
76+
exec(HESTIA_CMD . "v-list-database-hosts json", $output, $return_var);
77+
$db_hosts_tmp1 = json_decode(implode("", $output), true);
78+
$db_hosts_tmp2 = array_map(function ($host) {
79+
return $host["HOST"];
80+
}, $db_hosts_tmp1);
81+
$db_hosts = array_values(array_unique($db_hosts_tmp2));
82+
unset($output);
83+
unset($db_hosts_tmp1);
84+
unset($db_hosts_tmp2);
85+
86+
$this->database_config["database_host"]["options"] = $db_hosts;
87+
7588
$options = array_merge($options, $this->database_config);
7689
}
7790
return $options;
@@ -119,6 +132,8 @@ public function execute(array $options) {
119132
$options["database_name"],
120133
$options["database_user"],
121134
$options["database_password"],
135+
"mysql",
136+
$options["database_host"],
122137
)
123138
) {
124139
$this->errors[] = "Error adding database";

web/src/app/WebApp/Installers/Drupal/DrupalSetup.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ public function install(array $options = null): bool {
7070
$options["database_user"] .
7171
":" .
7272
$options["database_password"] .
73-
"@localhost:3306/" .
73+
"@" .
74+
$options["database_host"] .
75+
":3306/" .
7476
$this->appcontext->user() .
7577
"_" .
7678
$options["database_name"] .

web/src/app/WebApp/Installers/Flarum/FlarumSetup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function install(array $options = null): bool {
157157
$webDomain = ($sslEnabled ? "https://" : "http://") . $this->domain;
158158
$webPort = $sslEnabled ? "443" : "80";
159159

160-
$mysql_host = "localhost";
160+
$mysql_host = $options["database_host"];
161161
$mysql_database = addcslashes(
162162
$this->appcontext->user() . "_" . $options["database_name"],
163163
"\\'",

web/src/app/WebApp/Installers/Joomla/JoomlaSetup.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public function install(array $options = null): bool {
7171
}
7272

7373
// Database credentials
74+
$dbHost = $options["database_host"];
7475
$dbName = $this->appcontext->user() . "_" . $options["database_name"];
7576
$dbUser = $this->appcontext->user() . "_" . $options["database_user"];
7677
$dbPass = $options["database_password"];
@@ -95,7 +96,7 @@ public function install(array $options = null): bool {
9596
"--db-pass=" . $dbPass,
9697
"--db-name=" . $dbName,
9798
"--db-prefix=" . Util::generate_string(5, false) . "_",
98-
"--db-host=localhost",
99+
"--db-host=" . $dbHost,
99100
"--db-type=mysqli",
100101
];
101102

web/src/app/WebApp/Installers/MediaWiki/MediaWikiSetup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function install(array $options = null) {
6969
[
7070
"/usr/bin/php" . $options["php_version"],
7171
$this->getDocRoot("maintenance/install.php"),
72-
"--dbserver=localhost",
72+
"--dbserver=" . $options["database_host"],
7373
"--dbname=" . $this->appcontext->user() . "_" . $options["database_name"],
7474
"--installdbuser=" . $this->appcontext->user() . "_" . $options["database_user"],
7575
"--installdbpass=" . $options["database_password"],

web/src/app/WebApp/Installers/Nextcloud/NextcloudSetup.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public function install(array $options = null): bool {
5151
"maintenance:install",
5252
"--database mysql",
5353
"--database-name " . $this->appcontext->user() . "_" . $options["database_name"],
54+
"--database-host " . $options["database_host"],
5455
"--database-user " . $this->appcontext->user() . "_" . $options["database_user"],
5556
"--database-pass " . $options["database_password"],
5657
"--admin-user " . $options["username"],

web/src/app/WebApp/Installers/Opencart/OpencartSetup.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public function install(array $options = null): bool {
8282
"/usr/bin/php" . $options["php_version"],
8383
$this->getDocRoot("/install/cli_install.php"),
8484
"install",
85+
"--db_hostname " . $options["database_host"],
8586
"--db_username " . $this->appcontext->user() . "_" . $options["database_user"],
8687
"--db_password " . $options["database_password"],
8788
"--db_database " . $this->appcontext->user() . "_" . $options["database_name"],

web/src/app/WebApp/Installers/Prestashop/PrestashopSetup.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public function install(array $options = null): bool {
7272
[
7373
"/usr/bin/php" . $options["php_version"],
7474
$this->getDocRoot("/install/index_cli.php"),
75+
"--db_server=" . $options["database_host"],
7576
"--db_user=" . $this->appcontext->user() . "_" . $options["database_user"],
7677
"--db_password=" . $options["database_password"],
7778
"--db_name=" . $this->appcontext->user() . "_" . $options["database_name"],

web/src/app/WebApp/Installers/WordPress/WordPressSetup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function install(array $options = null) {
135135
"'," .
136136
$padding .
137137
"'" .
138-
addcslashes("localhost", "\\'") .
138+
addcslashes($options["database_host"], "\\'") .
139139
"' );";
140140
break;
141141
case "DB_CHARSET":

0 commit comments

Comments
 (0)