action.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. class action {
  3. public function __construct() {
  4. $this->db = new db();
  5. }
  6. public function getUser() {
  7. $list = array();
  8. $dbAction = $this->db->prepare("SELECT token, role, description FROM clients");
  9. $dbAction->execute();
  10. $dbAction->store_result();
  11. $dbAction->bind_result($token,$role,$description);
  12. while($dbAction->fetch()) {
  13. array_push($list,[$token,$role,$description]);
  14. };
  15. print_r($list);
  16. return $list;
  17. }
  18. public function getWhiteList() {
  19. $list = array();
  20. $dbAction = $this->db->prepare("SELECT ip FROM whitelist ORDER BY ip ASC");
  21. $dbAction->execute();
  22. $dbAction->store_result();
  23. $dbAction->bind_result($ip);
  24. while($dbAction->fetch()) {
  25. array_push($list,$ip);
  26. };
  27. return $list;
  28. }
  29. public function getBlackList() {
  30. $list = array();
  31. $dbAction = $this->db->prepare("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. public function getList() {
  41. $list = array();
  42. $dbAction = $this->db->prepare("SELECT ip FROM list UNION SELECT ip FROM blacklist ORDER BY ip ASC");
  43. $dbAction->execute();
  44. $dbAction->store_result();
  45. $dbAction->bind_result($ip);
  46. while($dbAction->fetch()) {
  47. array_push($list,$ip);
  48. };
  49. return $list;
  50. }
  51. private function isListed($ip) {
  52. $dbAction = $this->db->prepare("SELECT ip FROM list WHERE ip = ?");
  53. $dbAction->bind_param('i',$ip);
  54. $dbAction->execute();
  55. $dbAction->store_result();
  56. if($dbAction->num_rows() == 0) {
  57. return false;
  58. }
  59. return true;
  60. }
  61. private function deListCount($ip) {
  62. $dbAction = $this->db->prepare("SELECT count FROM delist WHERE ip = ?");
  63. $dbAction->bind_param('i',$ip);
  64. $dbAction->execute();
  65. $dbAction->store_result();
  66. $dbAction->bind_result($count);
  67. $dbAction->fetch();
  68. return $count;
  69. }
  70. public function list($ip) {
  71. $dbAction = $this->db->prepare("INSERT IGNORE INTO list VALUES (?)");
  72. $dbAction->bind_param('i',$ip);
  73. return $dbAction->execute();
  74. }
  75. public function adminDeList($ip) {
  76. //delist ip
  77. $dbAction = $this->db->prepare("DELETE FROM list WHERE ip = ?");
  78. $dbAction->bind_param('i',$ip);
  79. $dbAction->execute();
  80. //reset delist count
  81. $dbAction = $this->db->prepare("DELETE FROM delist WHERE ip = ?");
  82. $dbAction->bind_param('i',$ip);
  83. $dbAction->execute();
  84. //remove from blacklist
  85. $dbAction = $this->db->prepare("DELETE FROM blacklist WHERE ip = ?");
  86. $dbAction->bind_param('i',$ip);
  87. $dbAction->execute();
  88. return true;
  89. }
  90. public function deList($ip) {
  91. if(!$this->isListed($ip)) { //set true to avoid discovering
  92. return true;
  93. }
  94. //check delisting count
  95. if ($this->delistCount($ip) > 3){
  96. echo "Fatal: ". long2ip($ip) . " delisted to often!\n";
  97. return false;
  98. }
  99. //delist ip
  100. $dbAction = $this->db->prepare("DELETE FROM list WHERE ip = ?");
  101. $dbAction->bind_param('i',$ip);
  102. $dbAction->execute();
  103. //update delist count
  104. $dbAction = $this->db->prepare("INSERT INTO delist (ip) VALUES (?) ON DUPLICATE KEY UPDATE count = count + 1");
  105. $dbAction->bind_param('i',$ip);
  106. $dbAction->execute();
  107. return true;
  108. }
  109. public function blackList($ip) {
  110. $this->deWhiteList($ip);
  111. $dbAction = $this->db->prepare("INSERT IGNORE INTO blacklist VALUES (?)");
  112. $dbAction->bind_param('i',$ip);
  113. return $dbAction->execute();
  114. }
  115. public function deBlackList($ip) {
  116. $dbAction = $this->db->prepare("DELETE FROM blacklist WHERE ip = (?)");
  117. $dbAction->bind_param('i',$ip);
  118. return $dbAction->execute();
  119. }
  120. public function whiteList($ip) {
  121. $this->deBlackList($ip);
  122. $dbAction = $this->db->prepare("INSERT IGNORE INTO whitelist VALUES (?)");
  123. $dbAction->bind_param('i',$ip);
  124. return $dbAction->execute();
  125. }
  126. public function deWhiteList($ip) {
  127. $dbAction = $this->db->prepare("DELETE FROM whitelist WHERE ip = (?)");
  128. $dbAction->bind_param('i',$ip);
  129. return $dbAction->execute();
  130. }
  131. }