diff --git a/app/Config/Schema/schema.php b/app/Config/Schema/schema.php index 6f9d9448..64b4b15c 100755 --- a/app/Config/Schema/schema.php +++ b/app/Config/Schema/schema.php @@ -28,6 +28,7 @@ class AppSchema extends CakeSchema 'id' => ['type' => 'integer', 'null' => false, 'default' => null, 'length' => 20, 'unsigned' => false, 'key' => 'primary'], 'user_id' => ['type' => 'integer', 'null' => false, 'default' => null, 'length' => 20, 'unsigned' => false], 'reason' => ['type' => 'text', 'null' => false, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'], + 'ip' => ['type' => 'string', 'null' => false, 'default' => null, 'length' => 50, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'], 'indexes' => [ 'PRIMARY' => ['column' => 'id', 'unique' => 1] ], diff --git a/app/Controller/AppController.php b/app/Controller/AppController.php index 2c3f8a35..86d037a9 100755 --- a/app/Controller/AppController.php +++ b/app/Controller/AppController.php @@ -56,14 +56,25 @@ public function beforeFilter() $LoginCondition = $this->here != "/login" || !$this->EyPlugin->isInstalled('phpierre.signinup'); - $this->loadModel("Maintenance"); - if ($this->params['controller'] != "user" and $this->params['controller'] != "maintenance" and !$this->Permissions->can("BYPASS_MAINTENANCE") and $maintenance = $this->Maintenance->checkMaintenance($this->here, $this->Util) and $LoginCondition) { - $this->redirect([ - 'controller' => 'maintenance', - 'action' => $maintenance['url'], - 'plugin' => false, - 'admin' => false - ]); + if ($this->params['controller'] != "user" and $LoginCondition) { + if ($this->isIPBan($this->Util->getIP()) and $this->params['controller'] != "ban" and !$this->Permissions->can("BYPASS_BAN")) { + $this->redirect([ + 'controller' => 'ban', + 'action' => 'ip', + 'plugin' => false, + 'admin' => false + ]); + } + + $this->loadModel("Maintenance"); + if ($this->params['controller'] != "maintenance" and !$this->Permissions->can("BYPASS_MAINTENANCE") and $maintenance = $this->Maintenance->checkMaintenance($this->here, $this->Util)) { + $this->redirect([ + 'controller' => 'maintenance', + 'action' => $maintenance['url'], + 'plugin' => false, + 'admin' => false + ]); + } } // Plugin disabled @@ -671,4 +682,16 @@ public function sendJSON($data) $this->autoRender = false; return $this->response->body(json_encode($data)); } + + public function isIPBan($ip) { + $this->loadModel("Ban"); + $ipIsBan = $this->Ban->find('first', ['conditions' => ['ip' => $ip]]); + + if (isset($ipIsBan["Ban"])) { + $this->isBanned = $ipIsBan["Ban"]["reason"]; + return $this->isBanned; + } else { + return false; + } + } } diff --git a/app/Controller/BanController.php b/app/Controller/BanController.php index 3b474ac5..1b611285 100644 --- a/app/Controller/BanController.php +++ b/app/Controller/BanController.php @@ -10,6 +10,14 @@ function index() { $this->set('reason', $this->User->isBanned()); } + function ip() { + if (!$this->isIPBan($this->Util->getIP())) + $this->redirect("/"); + + $this->set('title_for_layout', $this->Lang->get("BAN__BAN")); + $this->set('reason', $this->isBanned); + } + function admin_index() { if (!$this->isConnected || !$this->Permissions->can("MANAGE_BAN")) @@ -42,15 +50,22 @@ function admin_add() if (empty($this->request->data("reason"))) return $this->response->body(json_encode(['statut' => false, 'msg' => $this->Lang->get('ERROR__FILL_ALL_FIELDS')])); + $this->loadModel("User"); foreach ($this->request->data as $key => $v) { - if ($v != "on" || $key == "name") + if ($v != "on" || $key == "name" || strpos($key, "-ip")) continue; $this->Ban->create(); $this->Ban->set([ - "user_id" => $key, - "reason" => $this->request->data("reason") + "user_id" => $key, + "reason" => $this->request->data("reason") ]); + + if ($this->request->data($key . "-ip") == "on") + $this->Ban->set([ + "ip" => $this->User->find("first", ["conditions" => ['id' => $key]])['User']['ip'] + ]); + $this->Ban->save(); } @@ -93,7 +108,7 @@ public function admin_get_users_not_ban() $this->modelClass = 'User'; $this->DataTable->initialize($this); $this->paginate = [ - 'fields' => ['User.id', 'User.pseudo', 'User.rank'], + 'fields' => ['User.id', 'User.pseudo', 'User.rank', 'User.ip'], ]; $this->DataTable->mDataProp = true; $response = $this->DataTable->getResponse(); @@ -113,11 +128,14 @@ public function admin_get_users_not_ban() $rank_name = (isset($available_ranks[$value['User']['rank']])) ? $available_ranks[$value['User']['rank']]['name'] : $available_ranks[0]['name']; $rank = '' . $rank_name . ''; $checkbox = ""; + $banIpCheckbox = ""; $data[] = [ 'User' => [ 'pseudo' => $username, 'ban' => $checkbox, - 'rank' => $rank + 'banIp' => $banIpCheckbox, + 'rank' => $rank, + 'ip' => $value['User']['ip'] ] ]; } diff --git a/app/View/Ban/admin_add.ctp b/app/View/Ban/admin_add.ctp index a54b57cc..bb52cfc6 100644 --- a/app/View/Ban/admin_add.ctp +++ b/app/View/Ban/admin_add.ctp @@ -15,6 +15,8 @@ get('BAN__QUESTION') ?> get('USER__TITLE') ?> get('USER__RANK') ?> + IP + get('BAN__IP_QUESTION') ?> @@ -55,7 +57,9 @@ "aoColumns": [ {mData: "User.ban", "bSearchable": false}, {mData: "User.pseudo", "bSearchable": true}, - {mData: "User.rank", "bSearchable": false} + {mData: "User.rank", "bSearchable": false}, + {mData: "User.ip", "bSearchable": true}, + {mData: "User.banIp", "bSearchable": false} ] }); }); diff --git a/app/View/Ban/admin_index.ctp b/app/View/Ban/admin_index.ctp index e7ea7133..8171f057 100644 --- a/app/View/Ban/admin_index.ctp +++ b/app/View/Ban/admin_index.ctp @@ -13,6 +13,7 @@ get("USER__USERNAME") ?> get("BAN__REASON") ?> + get("BAN__IS_BAN_IP") ?> get("GLOBAL__ACTIONS")?> @@ -27,6 +28,7 @@ } } ?> + get("BAN__NOT_BAN_IP") ?> ')" class="btn btn-danger">get('BAN__UNBAN') ?> diff --git a/app/View/Ban/ip.ctp b/app/View/Ban/ip.ctp new file mode 100644 index 00000000..5d8ef313 --- /dev/null +++ b/app/View/Ban/ip.ctp @@ -0,0 +1,10 @@ +


+
+
+
+
+ get("BAN__IP_EXPLICATION") . $reason ?> +
+
+
+
diff --git a/lang/en_UK.json b/lang/en_UK.json index e3e9adf8..9a5aba5e 100755 --- a/lang/en_UK.json +++ b/lang/en_UK.json @@ -686,6 +686,7 @@ "BAN__MEMBERS": "Banned members", "BAN__HOME": "Bans", "BAN__QUESTION": "Ban?", + "BAN__IP_QUESTION": "IP's ban ?", "BAN__REASON": "Reason for ban", "BAN__ADD": "Ban one or more members", "BAN__SUCCESS": "Banned member(s)", @@ -694,6 +695,9 @@ "BAN__UNBAN_SUCCESS": "Ban revoked", "BAN__BAN": "Banned", "BAN__EXPLICATION": "You have been banned for ", + "BAN__IP_EXPLICATION": "Your IP have been banned for ", + "BAN__IS_BAN_IP" : "The IP have been banned ?", + "BAN__NOT_BAN_IP" : "The IP is not banned", "SOCIAL__TITLE": "Manage social networks", "SOCIAL__HOME": "Social networks", diff --git a/lang/en_US.json b/lang/en_US.json index b98a2b6c..071fd4e3 100755 --- a/lang/en_US.json +++ b/lang/en_US.json @@ -691,6 +691,7 @@ "BAN__MEMBERS": "Banned members", "BAN__HOME": "Bans", "BAN__QUESTION": "Ban?", + "BAN__IP_QUESTION": "IP's ban ?", "BAN__REASON": "Reason for ban", "BAN__ADD": "Ban one or more members", "BAN__SUCCESS": "Banned member(s)", @@ -699,6 +700,9 @@ "BAN__UNBAN_SUCCESS": "Ban revoked", "BAN__BAN": "Banned", "BAN__EXPLICATION": "You have been banned for ", + "BAN__IP_EXPLICATION": "Your IP have been banned for ", + "BAN__IS_BAN_IP" : "The IP have been banned ?", + "BAN__NOT_BAN_IP" : "The IP is not banned", "SOCIAL__TITLE": "Manage social networks", "SOCIAL__HOME": "Social networks", diff --git a/lang/fr_FR.json b/lang/fr_FR.json index 40801d17..72b96e26 100755 --- a/lang/fr_FR.json +++ b/lang/fr_FR.json @@ -684,6 +684,7 @@ "BAN__MEMBERS": "Membres bannis", "BAN__HOME": "Bannissements", "BAN__QUESTION": "Bannir ?", + "BAN__IP_QUESTION": "Bannir l'IP ?", "BAN__REASON": "Raison du bannissement", "BAN__ADD": "Bannir un ou des membres", "BAN__SUCCESS": "Membre(s) banni(s)", @@ -692,6 +693,9 @@ "BAN__UNBAN_SUCCESS": "Bannissement révoqué", "BAN__BAN": "Bannis", "BAN__EXPLICATION": "Vous avez été banni pour ", + "BAN__IP_EXPLICATION": "Votre IP a été bannie pour ", + "BAN__IS_BAN_IP" : "Bannissement d'IP ?", + "BAN__NOT_BAN_IP" : "L'IP n'est pas bannie", "SOCIAL__TITLE": "Gérer les réseaux sociaux", "SOCIAL__HOME": "Réseaux sociaux", diff --git a/lang/ru_RU.json b/lang/ru_RU.json index f6c00ace..54571fcb 100644 --- a/lang/ru_RU.json +++ b/lang/ru_RU.json @@ -694,6 +694,7 @@ "BAN__MEMBERS": "Запрещенные участники", "BAN__HOME": "Баны", "BAN__QUESTION": "Запретить?", + "BAN__IP_QUESTION": "Запретить IP?", "BAN__REASON": "Причина бана", "BAN__ADD": "Забанить одного или нескольких участников", "BAN__SUCCESS": "Забаненный участник(ы)", @@ -702,6 +703,9 @@ "BAN__UNBAN_SUCCESS": "Бан отменен", "BAN__BAN": "Запрещено", "BAN__EXPLICATION": "Вас забанили за ", + "BAN__IP_EXPLICATION": "Ваш IP заблокирован на ", + "BAN__IS_BAN_IP" : "Бан по IP?", + "BAN__NOT_BAN_IP" : "IP не забанен", "SOCIAL__TITLE": "Управление социальными сетями", "SOCIAL__HOME": "Социальные сети",