Added createTableSQL script to better manage table creation

Added creation of Campaigns table
pull/24/head
Jordan 2014-01-12 21:46:51 -06:00
parent 4272d5a12b
commit c42ddf3dd7
2 changed files with 11 additions and 5 deletions

View File

@ -14,6 +14,11 @@ var Conn *sql.DB
// Setup initializes the Conn object
// It also populates the Gophish Config object
func Setup() error {
createTablesSQL := []string{
//Create tables
`CREATE TABLE Users (id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT NOT NULL, hash VARCHAR(60) NOT NULL, apikey VARCHAR(32));`,
`CREATE TABLE Campaigns (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, created_date TEXT NOT NULL, completed_date TEXT, status TEXT NOT NULL);`,
}
//If the file already exists, delete it and recreate it
_, err := os.Stat(config.Conf.DBPath)
if err == nil {
@ -25,11 +30,12 @@ func Setup() error {
return err
}
//Create the tables needed
_, err = Conn.Exec(
`CREATE TABLE Users (id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT, hash VARCHAR(60), apikey VARCHAR(32));`)
for _, stmt := range createTablesSQL {
_, err = Conn.Exec(stmt)
if err != nil {
return err
}
}
//Create the default user
stmt, err := Conn.Prepare(`INSERT INTO Users (username, hash, apikey) VALUES (?, ?, ?);`)
defer stmt.Close()

View File

@ -43,6 +43,6 @@ type Campaign struct {
CreatedDate time.Time `json:"created_date"`
CompletedDate time.Time `json:"completed_date"`
Targets []mail.Address `json:"targets"`
Template email.Email `json:"template"`
Template *email.Email `json:"template"` //This may change
Status string `json:"status"`
}