added test database command
This commit is contained in:
parent
26a32dca64
commit
98d9fb084c
@ -71,7 +71,7 @@ type responseSQL struct {
|
|||||||
response string
|
response string
|
||||||
}
|
}
|
||||||
|
|
||||||
func getResponseMYSQL(recipient *string) (string, error) {
|
func getDB() (*sql.DB, error) {
|
||||||
db, err := sql.Open(
|
db, err := sql.Open(
|
||||||
"mysql",
|
"mysql",
|
||||||
fmt.Sprintf(
|
fmt.Sprintf(
|
||||||
@ -81,6 +81,11 @@ func getResponseMYSQL(recipient *string) (string, error) {
|
|||||||
config.Section("mysql").Key("host").String(),
|
config.Section("mysql").Key("host").String(),
|
||||||
config.Section("mysql").Key("port").String(),
|
config.Section("mysql").Key("port").String(),
|
||||||
config.Section("mysql").Key("database").String()))
|
config.Section("mysql").Key("database").String()))
|
||||||
|
return db, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func getResponseMYSQL(recipient *string) (string, error) {
|
||||||
|
db, err := getDB()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -151,7 +156,7 @@ func forwardEmailAndAutoresponse(recipient string, sender string, responseRate u
|
|||||||
// If sendResponse is true and sender and recipiend differ, then send response and touch rate log file
|
// If sendResponse is true and sender and recipiend differ, then send response and touch rate log file
|
||||||
if sendResponse && strings.ToLower(recipient) != strings.ToLower(sender) {
|
if sendResponse && strings.ToLower(recipient) != strings.ToLower(sender) {
|
||||||
dlog.Info("Sending Response")
|
dlog.Info("Sending Response")
|
||||||
response = strings.Replace(response, "To: THIS GETS REPLACED", fmt.Sprintf("To: %v", sender), -1)
|
response = strings.Replace(response, "To: THIS GETS REPLACED", fmt.Sprintf("To: %v", recipient), -1)
|
||||||
|
|
||||||
DebugFmtPrintf(response)
|
DebugFmtPrintf(response)
|
||||||
|
|
||||||
@ -197,6 +202,7 @@ func main() {
|
|||||||
responseRatePtr := flag.Uint("t", 18000, "Response rate in seconds (0 - send each time)")
|
responseRatePtr := flag.Uint("t", 18000, "Response rate in seconds (0 - send each time)")
|
||||||
showVersion := flag.Bool("V", false, "Show version and exit")
|
showVersion := flag.Bool("V", false, "Show version and exit")
|
||||||
configPath := flag.String("c", "./config.ini", "Show version and exit")
|
configPath := flag.String("c", "./config.ini", "Show version and exit")
|
||||||
|
testDB := flag.Bool("D", false, "Test database")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
cfg, err := ini.Load(*configPath)
|
cfg, err := ini.Load(*configPath)
|
||||||
@ -214,6 +220,19 @@ func main() {
|
|||||||
dlog.SetLogLevel(dlog.SeverityDebug)
|
dlog.SetLogLevel(dlog.SeverityDebug)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if *testDB {
|
||||||
|
fmt.Printf("Trying to connect to database...\n")
|
||||||
|
db, err := getDB()
|
||||||
|
fmt.Printf("Opening connection...\n")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf(err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
defer db.Close()
|
||||||
|
fmt.Printf("Connected to database!\n")
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
if *showVersion {
|
if *showVersion {
|
||||||
fmt.Printf("autoresponder %v, written by Gurkengewuerz <niklas@mc8051.de> 2019\n", config.Section("").Key("version"))
|
fmt.Printf("autoresponder %v, written by Gurkengewuerz <niklas@mc8051.de> 2019\n", config.Section("").Key("version"))
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
Reference in New Issue
Block a user