Browse Source

Installer: fixed bugs in postgreSQL database server support

trigger
Stefan Naumann 1 year ago
parent
commit
6d56975bd5
4 changed files with 47 additions and 26 deletions
  1. +1
    -0
      .gitignore
  2. +5
    -2
      core/models.go
  3. +33
    -20
      views/install2.html
  4. +8
    -4
      web/install.go

+ 1
- 0
.gitignore View File

@@ -0,0 +1 @@
mvo.cfg

+ 5
- 2
core/models.go View File

@@ -97,12 +97,13 @@ func connection_settings ( cfg KeyValueStore ) string {
cfg.Get("database_host"),
cfg.Get("database_dbname"))
case "postgres":
x = fmt.Sprintf("user=%s password=%s host=%s dbname=%s port=%s",
x = fmt.Sprintf("user=%s password=%s host=%s dbname=%s port=%s sslmode=%s",
cfg.Get("database_username"),
cfg.Get("database_password"),
cfg.Get("database_host"),
cfg.Get("database_dbname"),
cfg.Get("database_port"))
cfg.Get("database_port"),
cfg.Get("database_postgres_ssl"))
case "mssql":
x = fmt.Sprintf("sqlserver://%s:%s@%s:%s?database=%s",
cfg.Get("database_username"),
@@ -111,6 +112,7 @@ func connection_settings ( cfg KeyValueStore ) string {
cfg.Get("database_port"),
cfg.Get("database_dbname"))
}
fmt.Println (" ::: x - ", x)
return x;
}

@@ -135,6 +137,7 @@ func DBConnect ( cfg KeyValueStore ) *gorm.DB {
}
return db;
} else {
fmt.Println ("Database connection error: ", err)
return nil
}
}

+ 33
- 20
views/install2.html View File

@@ -33,14 +33,27 @@
</div>
</div>
<div class="group" id="postgres_group">
<h3>PostgreSQL Settings</h3>
<div class="field">
<h3>PostgreSQL Settings</h3>
<div class="field required">
<label for="postgres_ssl">Required and Verify SSL</label>
<div class="infobox">
Determines, whether or not a SSL connection to Postgres should be required and even verified?
</div>
<select id="postgres_ssl" name="postgres_ssl" size="1">
<option value="verify-full" selected>Verify completely</option>
<option value="verify-ca">Verify certificate</option>
<option value="require">Require SSL (but skip verification)</option>
<option value="disable">No SSL required and no verification</option>
</select>
</div>

<div class="field required">
<label for="postgres_host">Host</label>
<div class="infobox">
Select the host, the database runs on. You may choose localhost or leave it empty, defaults to UNIX socket, then. Unix
socket is recommended, when the server runs on the same machine.
Select the host, the database runs on. Unix
socket is recommended, when the server runs on the same machine.
</div>
<input id="postgres_host" name="postgres_host" type="text" value="">
<input id="postgres_host" name="postgres_host" type="text" value="localhost">
</div>
<div class="field required">
<label for="postgres_port">Port</label>
@@ -76,7 +89,7 @@
<div class="field">
<label for="mysql_host">Host</label>
<div class="infobox">
Select the host, the database runs on.
Select the host, the database runs on.
</div>
<input id="mysql_host" name="mysql_host" type="text" value="localhost">
</div>
@@ -100,7 +113,7 @@
The password for the connection to Postgres.
</div>
<input id="mysql_password" name="mysql_password" type="password" value="password">
</div>
</div>
<div class="field required">
<label for="mysql_database">Database</label>
<div class="infobox">
@@ -114,7 +127,7 @@
<div class="field">
<label for="mssql_host">Host</label>
<div class="infobox">
Select the host, the database runs on.
Select the host, the database runs on.
</div>
<input id="mssql_host" name="mssql_host" type="text" value="localhost">
</div>
@@ -138,7 +151,7 @@
The password for the connection to Postgres.
</div>
<input id="mssql_password" name="mssql_password" type="password" value="password">
</div>
</div>
<div class="field required">
<label for="mssql_database">Database</label>
<div class="infobox">
@@ -152,30 +165,30 @@

<script language="javascript" type="text/javascript">
$(document).ready( function () {
$("#sqlite_group").hide();
$("#sqlite3_group").hide();
$("#postgres_group").hide();
$("#mysql_group").hide();
$("#mssql_group").hide();
$("#mssql_group").hide();
var v = $("#db_type")[0].value;
console.log(v)
if ( v == "mysql" || v == "sqlite" || v == "postgres" || v == "mssql" )
if ( v == "mysql" || v == "sqlite3" || v == "postgres" || v == "mssql" )
{
$("#" + v + "_group").show();
}
}
else
{
$("#sqlite_group").show();
$("#sqlite3_group").show();
}
$("#db_type").change ( function () {
$("#sqlite_group").hide();
$("#sqlite3_group").hide();
$("#postgres_group").hide();
$("#mysql_group").hide();
$("#mssql_group").hide();
$("#mssql_group").hide();
var v = $("#db_type")[0].value;
if ( v == "mysql" || v == "sqlite" || v == "postgres" || v == "mssql" )
if ( v == "mysql" || v == "sqlite3" || v == "postgres" || v == "mssql" )
{
$("#" + v + "_group").show();
}


+ 8
- 4
web/install.go View File

@@ -20,21 +20,25 @@ func dbConfigurationHandler ( ctx echo.Context ) ([]string,[]string) {
var passwd string;
var port int;
var dbname string;
var sslrequired string;
switch provider {
case "sqlite3":
file = ctx.FormValue ("sqlite3_file")
s.cfg.Set ( "database_provider", provider )
s.cfg.Set ( "database_filename", file )
case "mssql":
fallthrough

case "postgres":
sslrequired = ctx.FormValue ( "postgres_ssl" )
s.cfg.Set ( "database_postgres_ssl", sslrequired )
fallthrough
case "mssql":
fallthrough
case "mysql":
host = ctx.FormValue ( provider + "_host" )
passwd = ctx.FormValue ( provider + "_password" )
user = ctx.FormValue ( provider + "_user" )
port, _ = strconv.Atoi ( ctx.FormValue ( provider + "_port" ))
dbname = ctx.FormValue ( provider + "_dbname" )
dbname = ctx.FormValue ( provider + "_database" )

s.cfg.Set ( "database_provider", provider )
s.cfg.Set ( "database_host", host)
@@ -51,7 +55,7 @@ func dbConfigurationHandler ( ctx echo.Context ) ([]string,[]string) {
s.cfg.Persist ("");
return []string {}, []string{"Database configuration saved"}
} else {
return []string{"Cannot connect to the database - wrong config?"}, []string{}
return []string{"Cannot connect to the database"}, []string{}
}
}



Loading…
Cancel
Save