2014-01-09 06:42:05 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"io/ioutil"
|
|
|
|
)
|
|
|
|
|
2016-01-17 16:45:13 +00:00
|
|
|
// AdminServer represents the Admin server configuration details
|
|
|
|
type AdminServer struct {
|
|
|
|
ListenURL string `json:"listen_url"`
|
|
|
|
UseTLS bool `json:"use_tls"`
|
|
|
|
CertPath string `json:"cert_path"`
|
|
|
|
KeyPath string `json:"key_path"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// PhishServer represents the Phish server configuration details
|
|
|
|
type PhishServer struct {
|
|
|
|
ListenURL string `json:"listen_url"`
|
|
|
|
UseTLS bool `json:"use_tls"`
|
|
|
|
CertPath string `json:"cert_path"`
|
|
|
|
KeyPath string `json:"key_path"`
|
|
|
|
}
|
|
|
|
|
2018-10-06 22:51:49 +00:00
|
|
|
// LoggingConfig represents configuration details for Gophish logging.
|
|
|
|
type LoggingConfig struct {
|
|
|
|
Filename string `json:"filename"`
|
|
|
|
}
|
|
|
|
|
2014-03-25 03:31:33 +00:00
|
|
|
// Config represents the configuration information.
|
|
|
|
type Config struct {
|
2018-10-06 22:51:49 +00:00
|
|
|
AdminConf AdminServer `json:"admin_server"`
|
|
|
|
PhishConf PhishServer `json:"phish_server"`
|
|
|
|
DBName string `json:"db_name"`
|
|
|
|
DBPath string `json:"db_path"`
|
|
|
|
MigrationsPath string `json:"migrations_prefix"`
|
|
|
|
TestFlag bool `json:"test_flag"`
|
|
|
|
ContactAddress string `json:"contact_address"`
|
|
|
|
Logging LoggingConfig `json:"logging"`
|
2014-03-25 03:31:33 +00:00
|
|
|
}
|
|
|
|
|
2016-01-25 02:47:16 +00:00
|
|
|
// Conf contains the initialized configuration struct
|
2014-03-25 03:31:33 +00:00
|
|
|
var Conf Config
|
2014-01-09 06:42:05 +00:00
|
|
|
|
2016-08-06 23:58:34 +00:00
|
|
|
// Version contains the current gophish version
|
2017-09-06 02:54:32 +00:00
|
|
|
var Version = ""
|
2016-08-06 23:58:34 +00:00
|
|
|
|
2018-06-19 02:37:59 +00:00
|
|
|
// ServerName is the server type that is returned in the transparency response.
|
|
|
|
const ServerName = "gophish"
|
|
|
|
|
2017-09-06 02:54:32 +00:00
|
|
|
// LoadConfig loads the configuration from the specified filepath
|
2018-10-06 20:47:31 +00:00
|
|
|
func LoadConfig(filepath string) error {
|
2014-01-09 06:42:05 +00:00
|
|
|
// Get the config file
|
2017-09-06 02:54:32 +00:00
|
|
|
configFile, err := ioutil.ReadFile(filepath)
|
2014-01-09 06:42:05 +00:00
|
|
|
if err != nil {
|
2018-10-06 20:47:31 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = json.Unmarshal(configFile, &Conf)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2014-01-09 06:42:05 +00:00
|
|
|
}
|
2016-11-19 16:37:22 +00:00
|
|
|
// Choosing the migrations directory based on the database used.
|
|
|
|
Conf.MigrationsPath = Conf.MigrationsPath + Conf.DBName
|
2017-12-09 21:42:07 +00:00
|
|
|
// Explicitly set the TestFlag to false to prevent config.json overrides
|
|
|
|
Conf.TestFlag = false
|
2018-10-06 20:47:31 +00:00
|
|
|
return nil
|
2014-01-09 06:42:05 +00:00
|
|
|
}
|