Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

ActionAddHost.cpp 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. //
  2. // Created by robin on 8/9/15.
  3. //
  4. #include <string>
  5. #include <sstream>
  6. #include <vector>
  7. #include "ActionAddHost.h"
  8. #include "../../DataAccess/AbstractSql.h"
  9. std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) {
  10. std::stringstream ss(s);
  11. std::string item;
  12. while (std::getline(ss, item, delim)) {
  13. elems.push_back(item);
  14. }
  15. return elems;
  16. }
  17. std::vector<std::string> split(const std::string &s, char delim) {
  18. std::vector<std::string> elems;
  19. split(s, delim, elems);
  20. return elems;
  21. }
  22. ActionAddHost::ActionAddHost()
  23. {
  24. }
  25. const std::string ActionAddHost::getSql(AbstractSql* sqlDb) const
  26. {
  27. return sqlDb->getAddHostQuery(*this);
  28. }
  29. const std::string &ActionAddHost::getHost() const
  30. {
  31. return _host;
  32. }
  33. void ActionAddHost::setHost(const std::string &host)
  34. {
  35. _host = host;
  36. }
  37. const std::string &ActionAddHost::getRecordValue() const
  38. {
  39. return _recordValue;
  40. }
  41. void ActionAddHost::setRecordValue(const std::string &recordValue)
  42. {
  43. _recordValue = recordValue;
  44. }
  45. const std::string &ActionAddHost::getRecordType() const
  46. {
  47. return _recordType;
  48. }
  49. void ActionAddHost::setRecordType(const std::string &recordType)
  50. {
  51. _recordType = recordType;
  52. }
  53. const std::string &ActionAddHost::getDhcpMac() const
  54. {
  55. return _dhcpMac;
  56. }
  57. void ActionAddHost::setDhcpMac(const std::string &dhcpMac)
  58. {
  59. _dhcpMac = dhcpMac;
  60. }
  61. const std::string &ActionAddHost::getReverseDomain() const
  62. {
  63. return _reverseDomain;
  64. }
  65. void ActionAddHost::setReverseDomain(const std::string &reverseDomain)
  66. {
  67. _reverseDomain = reverseDomain;
  68. }
  69. bool ActionAddHost::isReverseEnabled() const
  70. {
  71. return _reverseEnabled;
  72. }
  73. void ActionAddHost::setReverseEnabled(bool reverseEnabled)
  74. {
  75. _reverseEnabled = reverseEnabled;
  76. }
  77. int ActionAddHost::getTtl() const
  78. {
  79. return _ttl;
  80. }
  81. void ActionAddHost::setTtl(int ttl)
  82. {
  83. _ttl = ttl;
  84. }
  85. const std::string ActionAddHost::getReversedValue() const
  86. {
  87. auto splitValue = split(_recordValue, '.');
  88. int index = 1;
  89. for (; index < splitValue.size(); ++index)
  90. {
  91. std::string reversedValue;
  92. for (int i = (int) splitValue.size() - 1 - index; i >= 0; --i)
  93. reversedValue += splitValue[i] + (i == 0 ? "" : ".");
  94. if (_reverseDomain == reversedValue)
  95. break;
  96. }
  97. std::string reversedValue;
  98. for (int i = (int) splitValue.size() - 1; i >= (int) splitValue.size() - index; --i)
  99. reversedValue += std::string(splitValue[i]) + (i == (int) splitValue.size() - index ? "" : ".");
  100. return reversedValue;
  101. }
  102. const std::string ActionAddHost::getDhcp() const
  103. {
  104. if (!_dhcpMac.empty() && _recordType == "A")
  105. {
  106. return "\thost " + _host + " {\n"
  107. "\t\thardware ethernet " + _dhcpMac + ";\n"
  108. "\t\tfixed-address " + _host + "." + _domain + ";\n"
  109. "\t}\n";
  110. }
  111. else
  112. return "";
  113. }