action.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. return $list;
  38. }
  39. private function isListed($ip) {
  40. $dbAction = $this->db->prepare("SELECT ip FROM list WHERE ip = ?");
  41. $dbAction->bind_param('i',$ip);
  42. $dbAction->execute();
  43. $dbAction->store_result();
  44. if($dbAction->num_rows() == 0) {
  45. return false;
  46. }
  47. return true;
  48. }
  49. private function deListCount($ip) {
  50. $dbAction = $this->db->prepare("SELECT count FROM delist WHERE ip = ?");
  51. $dbAction->bind_param('i',$ip);
  52. $dbAction->execute();
  53. $dbAction->store_result();
  54. $dbAction->bind_result($count);
  55. $dbAction->fetch();
  56. return $count;
  57. }
  58. public function list($ip) {
  59. $dbAction = $this->db->prepare("INSERT IGNORE INTO list VALUES (?)");
  60. $dbAction->bind_param('i',$ip);
  61. return $dbAction->execute();
  62. }
  63. public function adminDeList($ip) {
  64. echo "blubb" . $ip;
  65. if(!$this->isListed($ip)) { //set true to avoid discovering
  66. return true;
  67. }
  68. //delist ip
  69. $dbAction = $this->db->prepare("DELETE FROM list WHERE ip = ?");
  70. $dbAction->bind_param('i',$ip);
  71. $dbAction->execute();
  72. //reset delist count
  73. $dbAction = $this->db->prepare("DELETE FROM delist WHERE ip = ?");
  74. $dbAction->bind_param('i',$ip);
  75. $dbAction->execute();
  76. //remove from blacklist
  77. $dbAction = $this->db->prepare("DELETE FROM blacklist WHERE ip = ?");
  78. $dbAction->bind_param('i',$ip);
  79. $dbAction->execute();
  80. return true;
  81. }
  82. public function deList($ip) {
  83. if(!$this->isListed($ip)) { //set true to avoid discovering
  84. return true;
  85. }
  86. //check delisting count
  87. if ($this->delistCount($ip) > 3){
  88. echo "Fatal: ". long2ip($ip) . " delisted to often!\n";
  89. return false;
  90. }
  91. //delist ip
  92. $dbAction = $this->db->prepare("DELETE FROM list WHERE ip = ?");
  93. $dbAction->bind_param('i',$ip);
  94. $dbAction->execute();
  95. //update delist count
  96. $dbAction = $this->db->prepare("INSERT INTO delist (ip) VALUES (?) ON DUPLICATE KEY UPDATE count = count + 1");
  97. $dbAction->bind_param('i',$ip);
  98. $dbAction->execute();
  99. return true;
  100. }
  101. public function blackList($ip) {
  102. $this->deWhiteList($ip);
  103. $dbAction = $this->db->prepare("INSERT IGNORE INTO blacklist VALUES (?)");
  104. $dbAction->bind_param('i',$ip);
  105. return $dbAction->execute();
  106. }
  107. public function deBlackList($ip) {
  108. $dbAction = $this->db->prepare("DELETE FROM blacklist WHERE ip = (?)");
  109. $dbAction->bind_param('i',$ip);
  110. return $dbAction->execute();
  111. }
  112. public function whiteList($ip) {
  113. $this->deBlackList($ip);
  114. $dbAction = $this->db->prepare("INSERT IGNORE INTO whitelist VALUES (?)");
  115. $dbAction->bind_param('i',$ip);
  116. return $dbAction->execute();
  117. }
  118. public function deWhiteList($ip) {
  119. $dbAction = $this->db->prepare("DELETE FROM whitelist WHERE ip = (?)");
  120. $dbAction->bind_param('i',$ip);
  121. return $dbAction->execute();
  122. }
  123. }