The Poor Man's (or Woman's) Intrusion Detection System
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

86 lines
2.5 KiB

  1. //////////////////////////////////////////////////////////////////////
  2. // Base CLI app classes for TrafficMon tools
  3. // Written by Jonathan A. Foster <jon@jfpossibilities.com>
  4. // Started December 29th, 2021
  5. // Copyright JF Possibilities, Inc. All rights reserved.
  6. //
  7. //
  8. //////////////////////////////////////////////////////////////////////
  9. // NOTE: since GNU doesn't discard unused classes these two classes should
  10. // probably get put in separate sets of files. :-/
  11. #ifndef __IDS_MONITOR_BASE_APP_H__
  12. #define __IDS_MONITOR_BASE_APP_H__
  13. #include <cppdb/frontend.h>
  14. #include "../cli.h"
  15. #include "../miniini.h"
  16. //////////////////////////////////////////////////////////////////////
  17. // The core configuration file
  18. //
  19. // This is designed so that all parts can use the same config. Tools
  20. // ignore the parts they aren't interested in.
  21. //////////////////////////////////////////////////////////////////////
  22. struct MonitorBaseConf: public MiniINI {
  23. MiniINIvars traffic_mon; // This app's config variables
  24. MonitorBaseConf() { groups["Traffic Mon"] = &traffic_mon; }
  25. };
  26. //////////////////////////////////////////////////////////////////////
  27. // The base CLI application class used by the tools in this directory.
  28. //
  29. // Essentially this is a CLI app with a DB connection and a place
  30. // holder for a config file.
  31. //////////////////////////////////////////////////////////////////////
  32. struct TrafficMonBaseApp: public cBaseApp {
  33. cppdb::session db;
  34. MonitorBaseConf *config;
  35. // this init() will create a MonitorBaseConf if a config hasn't been assigned.
  36. virtual cBaseApp &init(int argc, char **argv);
  37. // process config file switch and load the file
  38. virtual unsigned do_switch(const char *arg);
  39. virtual void do_switch_arg(const char *sw, const std::string &val);
  40. // process CLI args, test for [traffic mon] and connect to DB.
  41. virtual int main();
  42. // close out and free config object.
  43. virtual ~TrafficMonBaseApp();
  44. };
  45. //////////////////////////////////////////////////////////////////////
  46. // Blacklist report base class
  47. //
  48. // This provides generic switch handling
  49. //////////////////////////////////////////////////////////////////////
  50. struct BlackListBaseApp: public TrafficMonBaseApp {
  51. std::string ipv4, ipv6;
  52. BlackListBaseApp():
  53. ipv4("127.0.0.1"),
  54. ipv6("::1")
  55. {}
  56. // Display generic CLI help text
  57. virtual int help();
  58. // process -4 & -6 switches.
  59. virtual unsigned do_switch(const char *sw);
  60. virtual void do_switch_arg(const char *sw, const std::string &val);
  61. virtual void do_arg(const char *arg);
  62. virtual int main();
  63. };
  64. #endif