diff --git a/gophish.go b/gophish.go index 86a8cfce..d67ed73c 100644 --- a/gophish.go +++ b/gophish.go @@ -38,7 +38,7 @@ var setupFlag = flag.Bool("setup", false, "Starts the initial setup process for func main() { //Setup the global variables and settings - _, err = Setup() + err = Setup() if err != nil { fmt.Println(err) } diff --git a/setup.go b/setup.go index 5c4c124a..60897f7c 100644 --- a/setup.go +++ b/setup.go @@ -16,36 +16,36 @@ var Db sql.DB //init registers the necessary models to be saved in the session later func init() { gob.Register(&models.User{}) - Setup() } // Setup creates and returns the database needed by Gophish. // It also populates the Gophish Config object -func Setup() { +func Setup() error { //If the file already exists, delete it and recreate it if _, err := os.Stat(config.Conf.DBPath); err == nil { os.Remove(Conf.DBPath) } fmt.Println("Creating db at " + config.Conf.DBPath) db, err := sql.Open("sqlite3", config.Conf.DBPath) + defer db.Close() if err != nil { - return nil, err + return err } //Create the tables needed _, err = db.Exec( `CREATE TABLE Users (id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT, hash VARCHAR(32), apikey VARCHAR(32));`) if err != nil { - return nil, err + return err } //Create the default user stmt, err := db.Prepare(`INSERT INTO Users (username, hash, apikey) VALUES (?, ?, ?);`) defer stmt.Close() if err != nil { - return nil, err + return err } _, err = stmt.Exec("jordan", "12345678901234567890123456789012", "12345678901234567890123456789012") if err != nil { - return nil, err + return err } - return db, nil + return nil }