github.com/dzsibi/gophish@v0.7.1-0.20190719042945-1f16c7237d0d/gophish.go (about) 1 package main 2 3 /* 4 gophish - Open-Source Phishing Framework 5 6 The MIT License (MIT) 7 8 Copyright (c) 2013 Jordan Wright 9 10 Permission is hereby granted, free of charge, to any person obtaining a copy 11 of this software and associated documentation files (the "Software"), to deal 12 in the Software without restriction, including without limitation the rights 13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 copies of the Software, and to permit persons to whom the Software is 15 furnished to do so, subject to the following conditions: 16 17 The above copyright notice and this permission notice shall be included in 18 all copies or substantial portions of the Software. 19 20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 26 THE SOFTWARE. 27 */ 28 import ( 29 "io/ioutil" 30 "os" 31 "os/signal" 32 33 "gopkg.in/alecthomas/kingpin.v2" 34 35 "github.com/gophish/gophish/config" 36 "github.com/gophish/gophish/controllers" 37 log "github.com/gophish/gophish/logger" 38 "github.com/gophish/gophish/middleware" 39 "github.com/gophish/gophish/models" 40 ) 41 42 var ( 43 configPath = kingpin.Flag("config", "Location of config.json.").Default("./config.json").String() 44 disableMailer = kingpin.Flag("disable-mailer", "Disable the mailer (for use with multi-system deployments)").Bool() 45 ) 46 47 func main() { 48 // Load the version 49 50 version, err := ioutil.ReadFile("./VERSION") 51 if err != nil { 52 log.Fatal(err) 53 } 54 kingpin.Version(string(version)) 55 56 // Parse the CLI flags and load the config 57 kingpin.CommandLine.HelpFlag.Short('h') 58 kingpin.Parse() 59 60 // Load the config 61 conf, err := config.LoadConfig(*configPath) 62 // Just warn if a contact address hasn't been configured 63 if err != nil { 64 log.Fatal(err) 65 } 66 if conf.ContactAddress == "" { 67 log.Warnf("No contact address has been configured.") 68 log.Warnf("Please consider adding a contact_address entry in your config.json") 69 } 70 config.Version = string(version) 71 72 err = log.Setup(conf) 73 if err != nil { 74 log.Fatal(err) 75 } 76 77 // Provide the option to disable the built-in mailer 78 // Setup the global variables and settings 79 err = models.Setup(conf) 80 if err != nil { 81 log.Fatal(err) 82 } 83 // Unlock any maillogs that may have been locked for processing 84 // when Gophish was last shutdown. 85 err = models.UnlockAllMailLogs() 86 if err != nil { 87 log.Fatal(err) 88 } 89 90 // Create our servers 91 adminOptions := []controllers.AdminServerOption{} 92 if *disableMailer { 93 adminOptions = append(adminOptions, controllers.WithWorker(nil)) 94 } 95 adminConfig := conf.AdminConf 96 adminServer := controllers.NewAdminServer(adminConfig, adminOptions...) 97 middleware.Store.Options.Secure = adminConfig.UseTLS 98 99 phishConfig := conf.PhishConf 100 phishServer := controllers.NewPhishingServer(phishConfig) 101 102 go adminServer.Start() 103 go phishServer.Start() 104 105 // Handle graceful shutdown 106 c := make(chan os.Signal, 1) 107 signal.Notify(c, os.Interrupt) 108 <-c 109 log.Info("CTRL+C Received... Gracefully shutting down servers") 110 adminServer.Shutdown() 111 phishServer.Shutdown() 112 }