action.php 3.6 KB

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