Browse Source

MySQL host port added to config

Vova Tkach 6 years ago
parent
commit
7a45202711

+ 14 - 2
engine/actions/action_mysql.go

@@ -3,6 +3,7 @@ package actions
 import (
 	"database/sql"
 	"fmt"
+	"strconv"
 
 	_ "github.com/go-sql-driver/mysql"
 
@@ -11,6 +12,7 @@ import (
 
 func action_mysql(e *Action) {
 	pf_host := e.R.FormValue("host")
+	pf_port := e.R.FormValue("port")
 	pf_name := e.R.FormValue("name")
 	pf_user := e.R.FormValue("user")
 	pf_password := e.R.FormValue("password")
@@ -20,6 +22,16 @@ func action_mysql(e *Action) {
 		return
 	}
 
+	if pf_port == "" {
+		e.msg_error(`Please specify host port for mysql connection`)
+		return
+	}
+
+	if _, err := strconv.Atoi(pf_port); err != nil {
+		e.msg_error(`MySql host port must be integer number`)
+		return
+	}
+
 	if pf_name == "" {
 		e.msg_error(`Please specify mysql database name`)
 		return
@@ -31,7 +43,7 @@ func action_mysql(e *Action) {
 	}
 
 	// Try connect to mysql
-	db, err := sql.Open("mysql", pf_user+":"+pf_password+"@tcp("+pf_host+":3306)/"+pf_name)
+	db, err := sql.Open("mysql", pf_user+":"+pf_password+"@tcp("+pf_host+":"+pf_port+")/"+pf_name)
 	if err != nil {
 		e.msg_error(err.Error())
 		return
@@ -46,7 +58,7 @@ func action_mysql(e *Action) {
 	// Try to install all tables
 
 	// Save mysql config file
-	err = utils.MySqlConfigWrite(e.VHostHome, pf_host, pf_name, pf_user, pf_password)
+	err = utils.MySqlConfigWrite(e.VHostHome, pf_host, pf_port, pf_name, pf_user, pf_password)
 	if err != nil {
 		e.msg_error(err.Error())
 		return

+ 1 - 1
engine/wrapper/resources/templates/cp.mysql.go

@@ -1,3 +1,3 @@
 package templates
 
-var CpMySQL = []byte(`<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="theme-color" content="#205081" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><title>Configure MySQL</title><link rel="stylesheet" href="{{$.System.PathCssBootstrap}}"><link rel="stylesheet" href="{{$.System.PathCssCpStyles}}"><link rel="shortcut icon" href="{{$.System.PathIcoFav}}" type="image/x-icon" /><style type="text/css">html{height:100%;}</style></head><body class="cp-mysql text-center">{{$.System.BlockModalSysMsg}}<form class="form-signin" action="/cp/" method="post"><input type="hidden" name="action" value="mysql"><h1 class="h3 mb-3 font-weight-normal">Configure MySQL</h1><label for="host" class="sr-only">Host</label><input type="text" id="host" name="host" class="form-control mb-3" placeholder="DB Host" value="localhost" required><label for="name" class="sr-only">Name</label><input type="text" id="name" name="name" class="form-control mb-3" placeholder="DB Name" required autofocus><label for="user" class="sr-only">User</label><input type="text" id="user" name="user" class="form-control mb-3" placeholder="DB User" required><label for="password" class="sr-only">Password</label><input type="password" id="password" name="password" class="form-control mb-3" placeholder="DB User Password"><button class="btn btn-lg btn-primary btn-block" type="submit">Configure</button></form><script src="{{$.System.PathJsJquery}}"></script><script src="{{$.System.PathJsPopper}}"></script><script src="{{$.System.PathJsBootstrap}}"></script><script src="{{$.System.PathJsCpScripts}}"></script></body></html>`)
+var CpMySQL = []byte(`<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="theme-color" content="#205081" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><title>Configure MySQL</title><link rel="stylesheet" href="{{$.System.PathCssBootstrap}}"><link rel="stylesheet" href="{{$.System.PathCssCpStyles}}"><link rel="shortcut icon" href="{{$.System.PathIcoFav}}" type="image/x-icon" /><style type="text/css">html{height:100%;}</style></head><body class="cp-mysql text-center">{{$.System.BlockModalSysMsg}}<form class="form-signin" action="/cp/" method="post"><input type="hidden" name="action" value="mysql"><h1 class="h3 mb-3 font-weight-normal">Configure MySQL</h1><label for="host" class="sr-only">Database host</label><input type="text" id="host" name="host" class="form-control mb-3" placeholder="Database host" value="localhost" required><label for="host" class="sr-only">Database host port</label><input type="text" id="host" name="port" class="form-control mb-3" placeholder="Database host port" value="3306" required><label for="name" class="sr-only">Database name</label><input type="text" id="name" name="name" class="form-control mb-3" placeholder="Database name" required autofocus><label for="user" class="sr-only">Database user name</label><input type="text" id="user" name="user" class="form-control mb-3" placeholder="Database user name" required><label for="password" class="sr-only">Database user password</label><input type="password" id="password" name="password" class="form-control mb-3" placeholder="Database user password"><button class="btn btn-lg btn-primary btn-block" type="submit">Configure</button></form><script src="{{$.System.PathJsJquery}}"></script><script src="{{$.System.PathJsPopper}}"></script><script src="{{$.System.PathJsBootstrap}}"></script><script src="{{$.System.PathJsCpScripts}}"></script></body></html>`)

+ 10 - 8
engine/wrapper/resources/templates/cp.mysql.html

@@ -15,14 +15,16 @@
 		<form class="form-signin" action="/cp/" method="post">
 			<input type="hidden" name="action" value="mysql">
 			<h1 class="h3 mb-3 font-weight-normal">Configure MySQL</h1>
-			<label for="host" class="sr-only">Host</label>
-			<input type="text" id="host" name="host" class="form-control mb-3" placeholder="DB Host" value="localhost" required>
-			<label for="name" class="sr-only">Name</label>
-			<input type="text" id="name" name="name" class="form-control mb-3" placeholder="DB Name" required autofocus>
-			<label for="user" class="sr-only">User</label>
-			<input type="text" id="user" name="user" class="form-control mb-3" placeholder="DB User" required>
-			<label for="password" class="sr-only">Password</label>
-			<input type="password" id="password" name="password" class="form-control mb-3" placeholder="DB User Password">
+			<label for="host" class="sr-only">Database host</label>
+			<input type="text" id="host" name="host" class="form-control mb-3" placeholder="Database host" value="localhost" required>
+			<label for="host" class="sr-only">Database host port</label>
+			<input type="text" id="host" name="port" class="form-control mb-3" placeholder="Database host port" value="3306" required>
+			<label for="name" class="sr-only">Database name</label>
+			<input type="text" id="name" name="name" class="form-control mb-3" placeholder="Database name" required autofocus>
+			<label for="user" class="sr-only">Database user name</label>
+			<input type="text" id="user" name="user" class="form-control mb-3" placeholder="Database user name" required>
+			<label for="password" class="sr-only">Database user password</label>
+			<input type="password" id="password" name="password" class="form-control mb-3" placeholder="Database user password">
 			<button class="btn btn-lg btn-primary btn-block" type="submit">Configure</button>
 		</form>
 		<script src="{{$.System.PathJsJquery}}"></script>

+ 3 - 1
engine/wrapper/utils/config_mysql.go

@@ -7,6 +7,7 @@ import (
 
 type ConfigMySql struct {
 	Host     string
+	Port     string
 	Name     string
 	User     string
 	Password string
@@ -40,9 +41,10 @@ func MySqlConfigRead(homedir string) (*ConfigMySql, error) {
 	return nil, err
 }
 
-func MySqlConfigWrite(homedir string, host string, name string, user string, password string) error {
+func MySqlConfigWrite(homedir string, host string, port string, name string, user string, password string) error {
 	r, err := json.Marshal(&ConfigMySql{
 		Host:     host,
+		Port:     port,
 		Name:     name,
 		User:     user,
 		Password: password,