action.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. class action {
  3. public function __construct() {
  4. $this->db = new db();
  5. }
  6. public function getWhiteList() {
  7. $list = array();
  8. $dbAction = $this->db->prepare("SELECT ip FROM whitelist ORDER BY ip ASC");
  9. $dbAction->execute();
  10. $dbAction->store_result();
  11. $dbAction->bind_result($ip);
  12. while($dbAction->fetch()) {
  13. array_push($list,$ip);
  14. };
  15. return $list;
  16. }
  17. public function getBlackList() {
  18. $list = array();
  19. $dbAction = $this->db->prepare("SELECT ip FROM blacklist ORDER BY ip ASC");
  20. $dbAction->execute();
  21. $dbAction->store_result();
  22. $dbAction->bind_result($ip);
  23. while($dbAction->fetch()) {
  24. array_push($list,$ip);
  25. };
  26. return $list;
  27. }
  28. public function getList() {
  29. $list = array();
  30. $dbAction = $this->db->prepare("SELECT ip FROM list UNION SELECT ip FROM blacklist ORDER BY ip ASC");
  31. $dbAction->execute();
  32. $dbAction->store_result();
  33. $dbAction->bind_result($ip);
  34. /* while($dbAction->fetch()) {
  35. array_push($list,$ip);
  36. };
  37. print_r($list);
  38. return $list;*/
  39. $result = $dbAction->fetch_all();
  40. print_r($result);
  41. return $result;
  42. }
  43. private function isListed($ip) {
  44. $dbAction = $this->db->prepare("SELECT ip FROM list WHERE ip = ?");
  45. $dbAction->bind_param('i',$ip);
  46. $dbAction->execute();
  47. $dbAction->store_result();
  48. if($dbAction->num_rows() == 0) {
  49. return false;
  50. }
  51. return true;
  52. }
  53. private function deListCount($ip) {
  54. $dbAction = $this->db->prepare("SELECT count FROM delist WHERE ip = ?");
  55. $dbAction->bind_param('i',$ip);
  56. $dbAction->execute();
  57. $dbAction->store_result();
  58. $dbAction->bind_result($count);
  59. $dbAction->fetch();
  60. return $count;
  61. }
  62. public function list($ip) {
  63. $dbAction = $this->db->prepare("INSERT IGNORE INTO list VALUES (?)");
  64. $dbAction->bind_param('i',$ip);
  65. return $dbAction->execute();
  66. }
  67. public function deList($ip) {
  68. if(!$this->isListed($ip)) { //set true to avoid discovering
  69. return true;
  70. }
  71. //check delisting count
  72. if ($this->delistCount($ip) > 3){
  73. echo "Fatal: ". long2ip($ip) . " delisted to often!\n";
  74. return false;
  75. }
  76. //delist ip
  77. $dbAction = $this->db->prepare("DELETE FROM list WHERE ip = ?");
  78. $dbAction->bind_param('i',$ip);
  79. $dbAction->execute();
  80. //update delist count
  81. $dbAction = $this->db->prepare("INSERT INTO delist (ip) VALUES (?) ON DUPLICATE KEY UPDATE count = count + 1");
  82. $dbAction->bind_param('i',$ip);
  83. $dbAction->execute();
  84. return true;
  85. }
  86. public function blackList($ip) {
  87. $this->deWhiteList($ip);
  88. $dbAction = $this->db->prepare("INSERT IGNORE INTO blacklist VALUES (?)");
  89. $dbAction->bind_param('i',$ip);
  90. return $dbAction->execute();
  91. }
  92. public function deBlackList($ip) {
  93. $dbAction = $this->db->prepare("DELETE FROM blacklist WHERE ip = (?)");
  94. $dbAction->bind_param('i',$ip);
  95. return $dbAction->execute();
  96. }
  97. public function whiteList($ip) {
  98. $this->deBlackList($ip);
  99. $dbAction = $this->db->prepare("INSERT IGNORE INTO whitelist VALUES (?)");
  100. $dbAction->bind_param('i',$ip);
  101. return $dbAction->execute();
  102. }
  103. public function deWhiteList($ip) {
  104. $dbAction = $this->db->prepare("DELETE FROM whitelist WHERE ip = (?)");
  105. $dbAction->bind_param('i',$ip);
  106. return $dbAction->execute();
  107. }
  108. }