mirror of https://github.com/gophish/gophish
Added createTableSQL script to better manage table creation
Added creation of Campaigns tablepull/24/head
parent
4272d5a12b
commit
c42ddf3dd7
10
db/db.go
10
db/db.go
|
@ -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()
|
||||
|
|
|
@ -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"`
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue