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.
 
 

64 lines
1.5 KiB

  1. //////////////////////////////////////////////////////////////////////
  2. // IP traffic analyzer - configuration file
  3. // Written by Jonathan A. Foster <jon@jfpossibilities.com>
  4. // Started May 14th, 2021
  5. // Copyright JF Possibilities, Inc. All rights reserved.
  6. //////////////////////////////////////////////////////////////////////
  7. #include <fstream>
  8. #include <iostream>
  9. #include "config.h"
  10. #include "strutil.h"
  11. void Config::load(const std::string &fname) {
  12. std::string l;
  13. std::ifstream f(fname.c_str());
  14. TSV tsv;
  15. Conn conn;
  16. int ln=0;
  17. while(std::getline(f, l)) {
  18. ln++;
  19. l = strip(l);
  20. if(l=="" || l[0]=='#') continue;
  21. if(l.size()>2 && l[0]=='[' && l.end()[-1]==']') {
  22. heading:
  23. if(l=="[us]") {
  24. /// Read in "us" list ///
  25. while(std::getline(f, l)) {
  26. ln++;
  27. l=strip(l);
  28. if(l=="" || l[0]=='#') continue;
  29. if(l.size()>2 && l[0]=='[' && l.end()[-1]==']') goto heading;
  30. us.push_back(l);
  31. }
  32. } else if(l=="[ignores]") {
  33. /// Read in ignore list ///
  34. while(std::getline(f, l)) {
  35. ln++;
  36. if(l=="" || l[0]=='#') continue;
  37. if(l.size()>2 && l[0]=='[' && l.end()[-1]==']') goto heading;
  38. tsv = l;
  39. if(tsv.count!=7) {
  40. std::cerr << "Incorrrect column count in config file line " << ln << std::endl;
  41. continue;
  42. }
  43. if(tsv.count>6) {
  44. tsv >> conn;
  45. ignores.push_back(conn);
  46. }
  47. }
  48. }
  49. }
  50. }
  51. }