|
|
@@ -0,0 +1,80 @@
|
|
|
+<?php
|
|
|
+class action {
|
|
|
+
|
|
|
+ public function __construct() {
|
|
|
+ $this->db = new db();
|
|
|
+ }
|
|
|
+
|
|
|
+ private function isListed($ip) {
|
|
|
+ $dbAction = $this->db->prepare("SELECT ip FROM list WHERE ip = ?");
|
|
|
+ $dbAction->bind_param('i',$ip);
|
|
|
+ $dbAction->execute();
|
|
|
+ $dbAction->store_result();
|
|
|
+ if($dbAction->num_rows() == 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function deListCount($ip) {
|
|
|
+ $dbAction = $this->db->prepare("SELECT count FROM delist WHERE ip = ?");
|
|
|
+ $dbAction->bind_param('i',$ip);
|
|
|
+ $dbAction->execute();
|
|
|
+ $dbAction->store_result();
|
|
|
+ $dbAction->bind_result($count);
|
|
|
+ $dbAction->fetch();
|
|
|
+ return $count;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function list($ip) {
|
|
|
+ $dbAction = $this->db->prepare("INSERT IGNORE INTO list VALUES (?)");
|
|
|
+ $dbAction->bind_param('i',$ip);
|
|
|
+ return $dbAction->execute();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function deList($ip) {
|
|
|
+ if(!$this->isListed($ip)) { //set true to avoid discovering
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ //check delisting count
|
|
|
+ if ($this->delistCount($ip) > 3){
|
|
|
+ echo "Fatal: ". long2ip($ip) . " delisted to often!\n";
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ //delist ip
|
|
|
+ $dbAction = $this->db->prepare("DELETE FROM list WHERE ip = ?");
|
|
|
+ $dbAction->bind_param('i',$ip);
|
|
|
+ $dbAction->execute();
|
|
|
+ //update delist count
|
|
|
+ $dbAction = $this->db->prepare("INSERT INTO delist (ip) VALUES (?) ON DUPLICATE KEY UPDATE count = count + 1");
|
|
|
+ $dbAction->bind_param('i',$ip);
|
|
|
+ $dbAction->execute();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function blackList($ip) {
|
|
|
+ $this->deWhiteList($ip);
|
|
|
+ $dbAction = $this->db->prepare("INSERT IGNORE INTO blacklist VALUES (?)");
|
|
|
+ $dbAction->bind_param('i',$ip);
|
|
|
+ return $dbAction->execute();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function deBlackList($ip) {
|
|
|
+ $dbAction = $this->db->prepare("DELETE FROM blacklist WHERE ip = (?)");
|
|
|
+ $dbAction->bind_param('i',$ip);
|
|
|
+ return $dbAction->execute();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function whiteList($ip) {
|
|
|
+ $this->deBlackList($ip);
|
|
|
+ $dbAction = $this->db->prepare("INSERT IGNORE INTO whitelist VALUES (?)");
|
|
|
+ $dbAction->bind_param('i',$ip);
|
|
|
+ return $dbAction->execute();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function deWhiteList($ip) {
|
|
|
+ $dbAction = $this->db->prepare("DELETE FROM whitelist WHERE ip = (?)");
|
|
|
+ $dbAction->bind_param('i',$ip);
|
|
|
+ return $dbAction->execute();
|
|
|
+ }
|
|
|
+}
|