mirror of https://github.com/statping/statping
config.yml loading
parent
daa74e979c
commit
a332ba5cf0
|
@ -1,3 +1,9 @@
|
|||
# 0.90.32 (04-23-2020)
|
||||
- Modified the saving and loading process config.yml
|
||||
|
||||
# 0.90.31 (04-21-2020)
|
||||
- Version bump for github actions
|
||||
|
||||
# 0.90.30 (04-19-2020)
|
||||
- Attempt to fix Github Actions build process
|
||||
- Fix for empty database connection string, and not starting in setup mode
|
||||
|
|
|
@ -16,7 +16,7 @@ An easy to use Status Page for your websites and applications. Statping will aut
|
|||
<h2>A Future-Proof Status Page</h2>
|
||||
Statping strives to remain future-proof and remain intact if a failure is created. Your Statping service should not be running on the same instance you're trying to monitor. If your server crashes your Status Page should still remaining online to notify your users of downtime.
|
||||
|
||||
<br><a href="https://labs.play-with-docker.com/?stack=https://raw.githubusercontent.com/statping/statping/master/dev/pwd-stack.yml"><img height=25 src="https://assets.statping.com/docker-pwd.png"></a>
|
||||
<br><a href="https://labs.play-with-docker.com/?stack=https://raw.githubusercontent.com/statping/statping/master/dev/pwd-stack.yml"><img height=25 src="https://assets.statping.com/docker-pwd.png"></a> (dashboard login is `admin`, password `admin`)
|
||||
<br><br><br>
|
||||
|
||||
<h2>No Requirements</h2>
|
||||
|
|
|
@ -185,6 +185,7 @@ func apiLoginHandler(w http.ResponseWriter, r *http.Request) {
|
|||
form := parseForm(r)
|
||||
username := form.Get("username")
|
||||
password := form.Get("password")
|
||||
|
||||
user, auth := users.AuthUser(username, password)
|
||||
if auth {
|
||||
utils.Log.Infoln(fmt.Sprintf("User %v logged in from IP %v", user.Username, r.RemoteAddr))
|
||||
|
|
|
@ -82,16 +82,19 @@ func initModels(db database.Database) {
|
|||
}
|
||||
|
||||
func CreateAdminUser(c *DbConfig) error {
|
||||
log.Infoln(fmt.Sprintf("Core database does not exist, creating now!"))
|
||||
log.Infoln(fmt.Sprintf("Default Admininstrator user does not exist, creating now! (admin/admin)"))
|
||||
|
||||
if c.Username == "" || c.Password == "" {
|
||||
c.Username = utils.Params.GetString("ADMIN_USER")
|
||||
c.Password = utils.Params.GetString("ADMIN_PASSWORD")
|
||||
adminUser := utils.Params.GetString("ADMIN_USER")
|
||||
adminPass := utils.Params.GetString("ADMIN_PASSWORD")
|
||||
|
||||
if adminUser == "" || adminPass == "" {
|
||||
adminUser = "admin"
|
||||
adminPass = "admin"
|
||||
}
|
||||
|
||||
admin := &users.User{
|
||||
Username: c.Username,
|
||||
Password: c.Password,
|
||||
Username: adminUser,
|
||||
Password: adminPass,
|
||||
Email: "info@admin.com",
|
||||
Admin: null.NewNullBool(true),
|
||||
}
|
||||
|
|
|
@ -1,40 +1,11 @@
|
|||
package configs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/statping/statping/types/errors"
|
||||
"github.com/statping/statping/utils"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
func (d *DbConfig) ConnectionString() string {
|
||||
var conn string
|
||||
postgresSSL := utils.Params.GetString("POSTGRES_SSLMODE")
|
||||
|
||||
switch d.DbConn {
|
||||
case "memory", ":memory:":
|
||||
conn = "sqlite3"
|
||||
d.DbConn = ":memory:"
|
||||
return d.DbConn
|
||||
case "sqlite", "sqlite3":
|
||||
conn, err := findDbFile(d)
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
}
|
||||
d.SqlFile = conn
|
||||
log.Infof("SQL database file at: %s", d.SqlFile)
|
||||
d.DbConn = "sqlite3"
|
||||
return d.SqlFile
|
||||
case "mysql":
|
||||
host := fmt.Sprintf("%v:%v", d.DbHost, d.DbPort)
|
||||
conn = fmt.Sprintf("%v:%v@tcp(%v)/%v?charset=utf8&parseTime=True&loc=UTC&time_zone=%%27UTC%%27", d.DbUser, d.DbPass, host, d.DbData)
|
||||
return conn
|
||||
case "postgres":
|
||||
conn = fmt.Sprintf("host=%v port=%v user=%v dbname=%v password=%v timezone=UTC sslmode=%v", d.DbHost, d.DbPort, d.DbUser, d.DbData, d.DbPass, postgresSSL)
|
||||
return conn
|
||||
}
|
||||
return conn
|
||||
}
|
||||
|
||||
func LoadConfigFile(directory string) (*DbConfig, error) {
|
||||
p := utils.Params
|
||||
log.Infof("Attempting to read config file at: %s/config.yml ", directory)
|
||||
|
@ -45,6 +16,33 @@ func LoadConfigFile(directory string) (*DbConfig, error) {
|
|||
utils.Params.ReadInConfig()
|
||||
}
|
||||
|
||||
var db *DbConfig
|
||||
content, err := utils.OpenFile(directory + "config.yml")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := yaml.Unmarshal([]byte(content), &db); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if db.DbConn != "" {
|
||||
p.Set("DB_CONN", db.DbConn)
|
||||
}
|
||||
if db.DbHost != "" {
|
||||
p.Set("DB_HOST", db.DbHost)
|
||||
}
|
||||
if db.DbPort != 0 {
|
||||
p.Set("DB_PORT", db.DbPort)
|
||||
}
|
||||
if db.DbPass != "" {
|
||||
p.Set("DB_PASS", db.DbPort)
|
||||
}
|
||||
if db.DbUser != "" {
|
||||
p.Set("DB_USER", db.DbUser)
|
||||
}
|
||||
if db.DbData != "" {
|
||||
p.Set("DB_DATABASE", db.DbData)
|
||||
}
|
||||
|
||||
configs := &DbConfig{
|
||||
DbConn: p.GetString("DB_CONN"),
|
||||
DbHost: p.GetString("DB_HOST"),
|
|
@ -1,11 +1,48 @@
|
|||
package configs
|
||||
|
||||
import "github.com/statping/statping/utils"
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/statping/statping/utils"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// Save will initially create the config.yml file
|
||||
func (d *DbConfig) Save(directory string) error {
|
||||
if err := utils.Params.WriteConfigAs(directory + "/config.yml"); err != nil {
|
||||
c, err := yaml.Marshal(d)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := utils.SaveFile(directory+"/configs.yml", c); err != nil {
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *DbConfig) ConnectionString() string {
|
||||
var conn string
|
||||
postgresSSL := utils.Params.GetString("POSTGRES_SSLMODE")
|
||||
|
||||
switch d.DbConn {
|
||||
case "memory", ":memory:":
|
||||
conn = "sqlite3"
|
||||
d.DbConn = ":memory:"
|
||||
return d.DbConn
|
||||
case "sqlite", "sqlite3":
|
||||
conn, err := findDbFile(d)
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
}
|
||||
d.SqlFile = conn
|
||||
log.Infof("SQL database file at: %s", d.SqlFile)
|
||||
d.DbConn = "sqlite3"
|
||||
return d.SqlFile
|
||||
case "mysql":
|
||||
host := fmt.Sprintf("%v:%v", d.DbHost, d.DbPort)
|
||||
conn = fmt.Sprintf("%v:%v@tcp(%v)/%v?charset=utf8&parseTime=True&loc=UTC&time_zone=%%27UTC%%27", d.DbUser, d.DbPass, host, d.DbData)
|
||||
return conn
|
||||
case "postgres":
|
||||
conn = fmt.Sprintf("host=%v port=%v user=%v dbname=%v password=%v timezone=UTC sslmode=%v", d.DbHost, d.DbPort, d.DbUser, d.DbData, d.DbPass, postgresSSL)
|
||||
return conn
|
||||
}
|
||||
return conn
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ func Samples() error {
|
|||
}
|
||||
|
||||
func createHitsAt(db database.Database, serviceID int64) database.Database {
|
||||
log.Infoln(fmt.Sprintf("Adding Sample records to service #%d", serviceID))
|
||||
log.Infoln(fmt.Sprintf("Adding Sample records to service #%d...", serviceID))
|
||||
|
||||
createdAt := utils.Now().Add(-3 * types.Day)
|
||||
p := utils.NewPerlin(2, 2, 5, utils.Now().UnixNano())
|
||||
|
|
|
@ -1 +1 @@
|
|||
0.90.31
|
||||
0.90.32
|
||||
|
|
Loading…
Reference in New Issue