Skip to content

Commit f51ea51

Browse files
committed
Make the db setup form readonly when in docker
The database configuration should be immutable in the install.php when using docker, because docker environment variables determine the database configuration parameters.
1 parent 725c142 commit f51ea51

2 files changed

Lines changed: 33 additions & 20 deletions

File tree

docker-entrypoint.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/sh
2-
# Copyright (C) 2020 Julian Merkle <juli.merkle@gmail.com>
2+
# Copyright (C) 2020-2021 Julian Merkle <juli.merkle@gmail.com>
33

44
# This program is free software: you can redistribute it and/or modify
55
# it under the terms of the GNU General Public License as published by
@@ -16,6 +16,8 @@ if [ ! "$(whoami)" = "www-data" ]; then
1616
exit 1
1717
fi
1818

19+
export DOCKER_ENV=1
20+
1921
# Remove the old instance (if existing)
2022
rm -rf "/var/www/html/"
2123

install.php

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,19 @@ function install($type, $host, $user, $pass, $dbname, $lang, $mysqlcon, &$err_ms
415415
$dbuser = "";
416416
$dbpass = "";
417417

418+
$attrReadonly = "";
419+
if (getenv('DOCKER_ENV') === "1") {
420+
$attrReadonly = "readonly";
421+
}
422+
418423
if(isset($show_warning)) {
424+
$dbtype = $_POST['dbtype'];
419425
$dbhost = $_POST['dbhost'];
420426
$dbname = $_POST['dbname'];
421427
$dbuser = $_POST['dbuser'];
422428
$dbpass = $_POST['dbpass'];
423429
} elseif(isset($_GET["dbhost"]) && isset($_GET["dbname"]) && isset($_GET["dbuser"]) && isset($_GET["dbpass"])) {
430+
$dbtype = $_GET['dbtype'];
424431
$dbhost = $_GET["dbhost"];
425432
$dbname = $_GET['dbname'];
426433
$dbuser = $_GET['dbuser'];
@@ -459,33 +466,37 @@ function install($type, $host, $user, $pass, $dbname, $lang, $mysqlcon, &$err_ms
459466
<div class="form-group">
460467
<label class="col-sm-4 control-label" data-toggle="modal" data-target="#isntwidbtypedesc"><?php echo $lang['isntwidbtype']; ?><i class="help-hover fas fa-question-circle"></i></label>
461468
<div class="col-sm-8">
462-
<select class="selectpicker show-tick form-control required" id="basic" name="dbtype" value="<?php echo $dbtype; ?>" required>
463-
<option disabled value=""> -- select database -- </option>
464-
<option data-subtext="Cubrid" value="cubrid">cubrid</option>
465-
<option data-subtext="FreeTDS / Microsoft SQL Server / Sybase" value="dblib">dblib</option>
466-
<option data-subtext="Firebird/Interbase" value="firebird">firebird</option>
467-
<option data-subtext="IBM DB2" value="ibm">ibm</option>
468-
<option data-subtext="IBM Informix Dynamic Server" value="informix">informix</option>
469-
<option data-subtext="MySQL [recommended]" value="mysql" selected>mysql (also mariadb)</option>
470-
<option data-subtext="Oracle Call Interface" value="oci">oci</option>
471-
<option data-subtext="ODBC v3 (IBM DB2, unixODBC und win32 ODBC)" value="odbc">odbc</option>
472-
<option data-subtext="PostgreSQL" value="pgsql">pgsql</option>
473-
<option data-subtext="SQLite 3 und SQLite 2" value="sqlite">sqlite</option>
474-
<option data-subtext="Microsoft SQL Server / SQL Azure" value="sqlsrv">sqlsrv</option>
475-
<option data-subtext="4D" value="4d">4d</option>
476-
</select>
469+
<?php if($attrReadonly === "readonly") { ?>
470+
<input type="text" class="form-control required" name="dbtype" value="<?php echo $dbtype; ?>" readonly>
471+
<?php } else { ?>
472+
<select class="selectpicker show-tick form-control required" id="basic" name="dbtype" required>
473+
<option disabled value=""> -- select database -- </option>
474+
<option data-subtext="Cubrid" value="cubrid">cubrid</option>
475+
<option data-subtext="FreeTDS / Microsoft SQL Server / Sybase" value="dblib">dblib</option>
476+
<option data-subtext="Firebird/Interbase" value="firebird">firebird</option>
477+
<option data-subtext="IBM DB2" value="ibm">ibm</option>
478+
<option data-subtext="IBM Informix Dynamic Server" value="informix">informix</option>
479+
<option data-subtext="MySQL [recommended]" value="mysql" selected>mysql (also mariadb)</option>
480+
<option data-subtext="Oracle Call Interface" value="oci">oci</option>
481+
<option data-subtext="ODBC v3 (IBM DB2, unixODBC und win32 ODBC)" value="odbc">odbc</option>
482+
<option data-subtext="PostgreSQL" value="pgsql">pgsql</option>
483+
<option data-subtext="SQLite 3 und SQLite 2" value="sqlite">sqlite</option>
484+
<option data-subtext="Microsoft SQL Server / SQL Azure" value="sqlsrv">sqlsrv</option>
485+
<option data-subtext="4D" value="4d">4d</option>
486+
</select>
487+
<?php } ?>
477488
</div>
478489
</div>
479490
<div class="form-group">
480491
<label class="col-sm-4 control-label" data-toggle="modal" data-target="#isntwidbhostdesc"><?php echo $lang['isntwidbhost']; ?><i class="help-hover fas fa-question-circle"></i></label>
481492
<div class="col-sm-8 required-field-block">
482-
<input type="text" class="form-control required" name="dbhost" placeholder="localhost" value="<?php echo $dbhost; ?>" required>
493+
<input type="text" class="form-control required" name="dbhost" placeholder="localhost" value="<?php echo $dbhost; ?>" <?php echo $attrReadonly; ?> required>
483494
</div>
484495
</div>
485496
<div class="form-group required-field-block">
486497
<label class="col-sm-4 control-label" data-toggle="modal" data-target="#isntwidbnamedesc"><?php echo $lang['isntwidbname']; ?><i class="help-hover fas fa-question-circle"></i></label>
487498
<div class="col-sm-8 required-field-block">
488-
<input type="text" data-pattern="^([A-Za-z0-9$_]){1,64}$" data-error="Please do not use special characters or more then 64 characters inside the database name!" class="form-control required" name="dbname" placeholder="ts3_ranksystem" value="<?php echo $dbname; ?>" required>
499+
<input type="text" data-pattern="^([A-Za-z0-9$_]){1,64}$" data-error="Please do not use special characters or more then 64 characters inside the database name!" class="form-control required" name="dbname" placeholder="ts3_ranksystem" value="<?php echo $dbname; ?>" <?php echo $attrReadonly; ?> required>
489500
<div class="help-block with-errors"></div>
490501
</div>
491502
</div>
@@ -497,7 +508,7 @@ function install($type, $host, $user, $pass, $dbname, $lang, $mysqlcon, &$err_ms
497508
<div class="form-group required-field-block">
498509
<label class="col-sm-4 control-label" data-toggle="modal" data-target="#isntwidbusrdesc"><?php echo $lang['isntwidbusr']; ?><i class="help-hover fas fa-question-circle"></i></label>
499510
<div class="col-sm-8 required-field-block">
500-
<input type="text" placeholder="<?php echo $lang['user'] ?>" data-pattern="^[^&quot;'\\-\s]+$" data-error="Please do not use one of the following special characters: ' \ &quot; - also no whitespace and do not use more then 64 characters inside the database user!" class="form-control required" name="dbuser" value="<?php echo $dbuser; ?>" maxlength="64" required>
511+
<input type="text" placeholder="<?php echo $lang['user'] ?>" data-pattern="^[^&quot;'\\-\s]+$" data-error="Please do not use one of the following special characters: ' \ &quot; - also no whitespace and do not use more then 64 characters inside the database user!" class="form-control required" name="dbuser" value="<?php echo $dbuser; ?>" maxlength="64" <?php echo $attrReadonly; ?> required>
501512
<div class="help-block with-errors"></div>
502513
</div>
503514
</div>
@@ -507,7 +518,7 @@ function install($type, $host, $user, $pass, $dbname, $lang, $mysqlcon, &$err_ms
507518
<div class="input-group">
508519
<span id="toggle-password2" class="input-group-addon" onclick="togglepwd()" style="cursor: pointer; pointer-events: all;"><svg class="svg-inline--fa fa-eye fa-w-18" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="eye" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512" data-fa-i2svg=""><path fill="currentColor" d="M572.52 241.4C518.29 135.59 410.93 64 288 64S57.68 135.64 3.48 241.41a32.35 32.35 0 0 0 0 29.19C57.71 376.41 165.07 448 288 448s230.32-71.64 284.52-177.41a32.35 32.35 0 0 0 0-29.19zM288 400a144 144 0 1 1 144-144 143.93 143.93 0 0 1-144 144zm0-240a95.31 95.31 0 0 0-25.31 3.79 47.85 47.85 0 0 1-66.9 66.9A95.78 95.78 0 1 0 288 160z"></path></svg></span>
509520
<span id="toggle-password1" class="input-group-addon" onclick="togglepwd()" style="cursor: pointer; pointer-events: all; display: none;"><svg class="svg-inline--fa fa-eye fa-w-18" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="eye" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512" data-fa-i2svg=""><path fill="currentColor" d="M320 400c-75.85 0-137.25-58.71-142.9-133.11L72.2 185.82c-13.79 17.3-26.48 35.59-36.72 55.59a32.35 32.35 0 0 0 0 29.19C89.71 376.41 197.07 448 320 448c26.91 0 52.87-4 77.89-10.46L346 397.39a144.13 144.13 0 0 1-26 2.61zm313.82 58.1l-110.55-85.44a331.25 331.25 0 0 0 81.25-102.07 32.35 32.35 0 0 0 0-29.19C550.29 135.59 442.93 64 320 64a308.15 308.15 0 0 0-147.32 37.7L45.46 3.37A16 16 0 0 0 23 6.18L3.37 31.45A16 16 0 0 0 6.18 53.9l588.36 454.73a16 16 0 0 0 22.46-2.81l19.64-25.27a16 16 0 0 0-2.82-22.45zm-183.72-142l-39.3-30.38A94.75 94.75 0 0 0 416 256a94.76 94.76 0 0 0-121.31-92.21A47.65 47.65 0 0 1 304 192a46.64 46.64 0 0 1-1.54 10l-73.61-56.89A142.31 142.31 0 0 1 320 112a143.92 143.92 0 0 1 144 144c0 21.63-5.29 41.79-13.9 60.11z"></path></svg></span>
510-
<input id="password" placeholder="<?php echo $lang['pass'] ?>" type="password" data-pattern="^[^&quot;'\\-\s]+$" data-error="Please do not use one of the following special characters: ' \ &quot; - also no whitespace and do not use more then 64 characters inside the database password!" class="form-control required" name="dbpass" value="<?php echo $dbpass; ?>" data-toggle="password" data-placement="before" maxlength="64" required>
521+
<input id="password" placeholder="<?php echo $lang['pass'] ?>" type="password" data-pattern="^[^&quot;'\\-\s]+$" data-error="Please do not use one of the following special characters: ' \ &quot; - also no whitespace and do not use more then 64 characters inside the database password!" class="form-control required" name="dbpass" value="<?php echo $dbpass; ?>" data-toggle="password" data-placement="before" maxlength="64" <?php echo $attrReadonly; ?> required>
511522
</div>
512523
<div class="help-block with-errors"></div>
513524
</div>

0 commit comments

Comments
 (0)