1package commands 2 3import ( 4 "github.com/inconshreveable/log15" 5 "github.com/mozqnet/go-exploitdb/db" 6 "github.com/mozqnet/go-exploitdb/fetcher" 7 "github.com/mozqnet/go-exploitdb/models" 8 "github.com/spf13/cobra" 9 "github.com/spf13/viper" 10) 11 12var fetchAwesomePocCmd = &cobra.Command{ 13 Use: "awesomepoc", 14 Short: "Fetch the data of Awesome Poc", 15 Long: `Fetch the data of Awesome Poc`, 16 RunE: fetchAwesomePoc, 17} 18 19func init() { 20 fetchCmd.AddCommand(fetchAwesomePocCmd) 21} 22 23func fetchAwesomePoc(cmd *cobra.Command, args []string) (err error) { 24 driver, locked, err := db.NewDB( 25 viper.GetString("dbtype"), 26 viper.GetString("dbpath"), 27 viper.GetBool("debug-sql"), 28 ) 29 if err != nil { 30 if locked { 31 log15.Error("Failed to initialize DB. Close DB connection before fetching", "err", err) 32 } 33 return err 34 } 35 36 log15.Info("Fetching Awesome Poc Exploit") 37 var exploits []*models.Exploit 38 if exploits, err = fetcher.FetchAwesomePoc(viper.GetBool("deep")); err != nil { 39 log15.Error("Failed to fetch AwesomePoc Exploit", "err", err) 40 return err 41 } 42 log15.Info("Awesome Poc Exploit", "count", len(exploits)) 43 44 log15.Info("Insert Exploit into go-exploitdb.", "db", driver.Name()) 45 if err := driver.InsertExploit(exploits); err != nil { 46 log15.Error("Failed to insert.", "dbpath", viper.GetString("dbpath"), "err", err) 47 return err 48 } 49 return nil 50} 51