kyoketsu-web.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. GNU GENERAL PUBLIC LICENSE
  3. Version 3, 29 June 2007
  4. kyoketsu, a Client-To-Client Network Enumeration System
  5. Copyright (C) 2024 Russell Hrubesky, ChiralWorks Software LLC
  6. Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
  7. Everyone is permitted to copy and distribute verbatim copies
  8. of this license document, but changing it is not allowed.
  9. This program is free software: you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation, either version 3 of the License,
  12. or (at your option) any later version.
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. See the GNU General Public License for more details.
  17. You should have received a copy of the GNU General Public License
  18. along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. package main
  21. import (
  22. "database/sql"
  23. "flag"
  24. "log"
  25. "net/http"
  26. "sync"
  27. kyoketsu "git.aetherial.dev/aeth/kyoketsu/pkg"
  28. )
  29. const dbfile = "sqlite.db"
  30. func main() {
  31. port := flag.Int("port", 8080, "Select the port to run the server on")
  32. debug := flag.Bool("debug", false, "Pass this to start the pprof server")
  33. flag.Parse()
  34. db, err := sql.Open("sqlite3", dbfile)
  35. if err != nil {
  36. log.Fatal(err)
  37. }
  38. if *debug {
  39. go func() {
  40. log.Println(http.ListenAndServe("localhost:6060", nil))
  41. }()
  42. }
  43. hostsRepo := kyoketsu.NewSQLiteRepo(db)
  44. var wg sync.WaitGroup
  45. wg.Add(1)
  46. go kyoketsu.RunHttpServer(*port, hostsRepo, kyoketsu.RetrieveScanDirectives())
  47. if err = hostsRepo.Migrate(); err != nil {
  48. log.Fatal(err)
  49. }
  50. log.Println("SUCCESS ::: SQLite database initiated, and open for writing.")
  51. wg.Wait()
  52. }