From 92ce8b74e48c665fb59066ba3de7b86c91dc9281 Mon Sep 17 00:00:00 2001 From: nivcoo Date: Sat, 28 Aug 2021 17:14:09 +0200 Subject: [PATCH] feat. impl. new ban system -> StanByes --- app/Config/Schema/schema.php | 11 ++ app/Controller/AppController.php | 44 +++--- app/Controller/BanController.php | 130 ++++++++++++++++++ .../Component/PermissionsComponent.php | 2 + app/Controller/UserController.php | 13 +- app/Model/Ban.php | 5 + app/Model/User.php | 10 ++ app/View/Ban/admin_add.ctp | 62 +++++++++ app/View/Ban/admin_index.ctp | 45 ++++++ app/View/Ban/index.ctp | 10 ++ lang/en_UK.json | 15 +- lang/en_US.json | 15 +- lang/fr_FR.json | 15 +- lang/ru_RU.json | 15 +- 14 files changed, 364 insertions(+), 28 deletions(-) create mode 100644 app/Controller/BanController.php create mode 100644 app/Model/Ban.php create mode 100644 app/View/Ban/admin_add.ctp create mode 100644 app/View/Ban/admin_index.ctp create mode 100644 app/View/Ban/index.ctp diff --git a/app/Config/Schema/schema.php b/app/Config/Schema/schema.php index d78b9694..03ff0c48 100755 --- a/app/Config/Schema/schema.php +++ b/app/Config/Schema/schema.php @@ -23,6 +23,17 @@ class AppSchema extends CakeSchema ], 'tableParameters' => ['charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'InnoDB'] ]; + + public $bans = [ + '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' => 'string', 'null' => false, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'], + 'indexes' => [ + 'PRIMARY' => ['column' => 'id', 'unique' => 1] + ], + 'tableParameters' => ['charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'InnoDB'] + ]; + public $cake_sessions = [ 'id' => ['type' => 'string', 'null' => false, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1', 'key' => 'primary'], 'data' => ['type' => 'text', 'null' => true, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'], diff --git a/app/Controller/AppController.php b/app/Controller/AppController.php index 71256605..bb5ab39e 100755 --- a/app/Controller/AppController.php +++ b/app/Controller/AppController.php @@ -42,9 +42,14 @@ class AppController extends Controller public $view = 'Theme'; protected $isConnected = false; + protected $isBanned = false; public function beforeFilter() { + + // lowercase to avoid errors when the controller is called with uppercase + $this->params['controller'] = strtolower($this->params['controller']); + $this->params['action'] = strtolower($this->params['action']); // Plugin disabled if ($this->request->params['plugin']) { $plugin = $this->EyPlugin->findPlugin('slugLower', $this->request->params['plugin']); @@ -89,28 +94,17 @@ public function beforeFilter() return $event->result; } $LoginCondition = ($this->here != "/login") || !$this->EyPlugin->isInstalled('phpierre.signinup'); - // Maintenance / Bans - // lowercase to avoid errors when the controller is called with uppercase - $this->params['controller'] = strtolower($this->params['controller']); - $this->params['action'] = strtolower($this->params['action']); - if ($this->isConnected and $this->User->getKey('rank') == 5 and $this->params['controller'] != "maintenance" and $this->params['action'] != "logout" and $this->params['controller'] != "api") { + // Maintenance + if ($this->params['controller'] != "user" && $this->params['controller'] != "maintenance" && $this->Configuration->getKey('maintenance') != '0' && !$this->Permissions->can('BYPASS_MAINTENANCE') && $LoginCondition) { $this->redirect([ 'controller' => 'maintenance', - 'action' => 'index/banned', + 'action' => 'index', 'plugin' => false, 'admin' => false ]); - } else { - if ($this->params['controller'] != "user" && $this->params['controller'] != "maintenance" && $this->Configuration->getKey('maintenance') != '0' && !$this->Permissions->can('BYPASS_MAINTENANCE') && $LoginCondition) { - $this->redirect([ - 'controller' => 'maintenance', - 'action' => 'index', - 'plugin' => false, - 'admin' => false - ]); - } } + } public function __initConfiguration() @@ -212,6 +206,19 @@ private function __initUser() $this->isConnected = $this->User->isConnected(); $this->set('isConnected', $this->isConnected); + if ($this->isConnected) { + $LoginCondition = ($this->here != "/login") || !$this->EyPlugin->isInstalled('phpierre.signinup'); + if ($this->params['controller'] != "user" and $this->params['controller'] != "ban" and $this->User->isBanned() != false and $LoginCondition) { + $this->isBanned = $this->User->isBanned(); + + $this->redirect([ + 'controller' => 'ban', + 'action' => 'index', + 'plugin' => false, + 'admin' => false + ]); + } + } $user = ($this->isConnected) ? $this->User->getAllFromCurrentUser() : []; if (!empty($user)) $user['isAdmin'] = $this->User->isAdmin(); @@ -249,6 +256,11 @@ public function __initAdminNavbar() 'permission' => 'MANAGE_USERS', 'route' => ['controller' => 'user', 'action' => 'index', 'admin' => true, 'plugin' => false] ], + 'BAN__MEMBERS' => [ + 'icon' => 'users', + 'permission' => 'MANAGE_BAN', + 'route' => ['controller' => 'ban', 'action' => 'index', 'admin' => true, 'plugin' => false] + ], 'PERMISSIONS__LABEL' => [ 'icon' => 'user', 'permission' => 'MANAGE_PERMISSIONS', @@ -572,7 +584,7 @@ public function sendGetRequest($url) public function sendMultipleGetRequests($urls) { - if(!is_array($urls)) + if (!is_array($urls)) $urls = [$urls]; $multi = curl_multi_init(); $channels = []; diff --git a/app/Controller/BanController.php b/app/Controller/BanController.php new file mode 100644 index 00000000..d7718f80 --- /dev/null +++ b/app/Controller/BanController.php @@ -0,0 +1,130 @@ +isConnected || $this->User->isBanned() == false) + $this->redirect("/"); + + $this->set('title_for_layout', $this->Lang->get("BAN__BAN")); + $this->set('reason', $this->User->isBanned()); + } + + function admin_index() + { + if (!$this->isConnected || !$this->Permissions->can("MANAGE_BAN")) + throw new ForbiddenException(); + + $this->set('title_for_layout', $this->Lang->get("BAN__HOME")); + $this->layout = 'admin'; + + $this->loadModel("Ban"); + $this->loadModel("User"); + $banned_users = $this->Ban->find("all"); + + $users = $this->User->find("all"); + + $this->set(compact("banned_users", "users")); + } + + function admin_add() + { + if (!$this->isConnected || !$this->Permissions->can("MANAGE_BAN")) + throw new ForbiddenException(); + + $this->set('title_for_layout', $this->Lang->get("BAN__HOME")); + $this->layout = 'admin'; + + if ($this->request->is("post")) { + $this->autoRender = false; + $this->response->type('json'); + + if (empty($this->request->data("reason"))) + return $this->response->body(json_encode(['statut' => false, 'msg' => $this->Lang->get('ERROR__FILL_ALL_FIELDS')])); + + foreach ($this->request->data as $key => $v) { + if ($v != "on" || $key == "name") + continue; + + $this->Ban->create(); + $this->Ban->set([ + "user_id" => $key, + "reason" => $this->request->data("reason") + ]); + $this->Ban->save(); + } + + $this->response->body(json_encode(['statut' => true, 'msg' => $this->Lang->get('BAN__SUCCESS')])); + } + } + + function admin_unban($id = false) + { + if (!$this->isConnected || !$this->Permissions->can("MANAGE_BAN")) + throw new ForbiddenException(); + + $this->loadModel('Ban'); + $this->Ban->delete($id); + $this->Session->setFlash($this->Lang->get('BAN__UNBAN_SUCCESS'), 'default.success'); + $this->redirect(['controller' => 'ban', 'action' => 'index', 'admin' => true]); + } + + public function admin_get_users_not_ban() + { + if ($this->isConnected and $this->Permissions->can('MANAGE_BAN')) { + $this->autoRender = false; + $this->response->type('json'); + if ($this->request->is('ajax')) { + $available_ranks = [ + 0 => ['label' => 'success', 'name' => $this->Lang->get('USER__RANK_MEMBER')], + 2 => ['label' => 'warning', 'name' => $this->Lang->get('USER__RANK_MODERATOR')], + 3 => ['label' => 'danger', 'name' => $this->Lang->get('USER__RANK_ADMINISTRATOR')], + 4 => ['label' => 'danger', 'name' => $this->Lang->get('USER__RANK_ADMINISTRATOR')], + 5 => ['label' => 'primary', 'name' => $this->Lang->get('USER__RANK_BANNED')] + ]; + $this->loadModel('Rank'); + $custom_ranks = $this->Rank->find('all'); + foreach ($custom_ranks as $value) { + $available_ranks[$value['Rank']['rank_id']] = [ + 'label' => 'info', + 'name' => $value['Rank']['name'] + ]; + } + $this->DataTable = $this->Components->load('DataTable'); + $this->modelClass = 'User'; + $this->DataTable->initialize($this); + $this->paginate = [ + 'fields' => ['User.id', 'User.pseudo', 'User.rank'], + ]; + $this->DataTable->mDataProp = true; + $response = $this->DataTable->getResponse(); + $users = $response['aaData']; + $data = []; + foreach ($users as $value) { + $checkIsBan = $this->Ban->find('first', ["conditions" => ['user_id' => $value['User']['id']]]); + + if ($checkIsBan != null) + continue; + + if ($this->Permissions->have($value['User']['rank'], "CAN_BE_BAN")) + continue; + + $username = $value['User']['pseudo']; + $rank_label = (isset($available_ranks[$value['User']['rank']])) ? $available_ranks[$value['User']['rank']]['label'] : $available_ranks[0]['label']; + $rank_name = (isset($available_ranks[$value['User']['rank']])) ? $available_ranks[$value['User']['rank']]['name'] : $available_ranks[0]['name']; + $rank = '' . $rank_name . ''; + $checkbox = ""; + $data[] = [ + 'User' => [ + 'pseudo' => $username, + 'ban' => $checkbox, + 'rank' => $rank + ] + ]; + } + $response['aaData'] = $data; + $this->response->body(json_encode($response)); + } + } + } +} diff --git a/app/Controller/Component/PermissionsComponent.php b/app/Controller/Component/PermissionsComponent.php index a9fb908f..fcc49e2e 100755 --- a/app/Controller/Component/PermissionsComponent.php +++ b/app/Controller/Component/PermissionsComponent.php @@ -18,6 +18,7 @@ class PermissionsComponent extends CakeObject 'MANAGE_NAV', 'MANAGE_SEO', 'BYPASS_MAINTENANCE', + 'BYPASS_BAN', 'MANAGE_MAINTENANCE', 'MANAGE_CONFIGURATION', 'USE_ADMIN_HELP', @@ -29,6 +30,7 @@ class PermissionsComponent extends CakeObject 'VIEW_STATISTICS', 'MANAGE_THEMES', 'MANAGE_USERS', + 'MANAGE_BANS', 'VIEW_WEBSITE_HISTORY' ]; diff --git a/app/Controller/UserController.php b/app/Controller/UserController.php index 9c4147d1..157c4692 100755 --- a/app/Controller/UserController.php +++ b/app/Controller/UserController.php @@ -447,12 +447,11 @@ function profile() 0 => $this->Lang->get('USER__RANK_MEMBER'), 2 => $this->Lang->get('USER__RANK_MODERATOR'), 3 => $this->Lang->get('USER__RANK_ADMINISTRATOR'), - 4 => $this->Lang->get('USER__RANK_ADMINISTRATOR'), - 5 => $this->Lang->get('USER__RANK_BANNED') + 4 => $this->Lang->get('USER__RANK_ADMINISTRATOR') ]; $this->loadModel('Rank'); $custom_ranks = $this->Rank->find('all'); - foreach ($custom_ranks as $key => $value) { + foreach ($custom_ranks as $value) { $available_ranks[$value['Rank']['rank_id']] = $value['Rank']['name']; } $this->set(compact('available_ranks')); @@ -628,7 +627,7 @@ function admin_liveSearch($query = false) if ($query != false) { $result = $this->User->find('all', ['conditions' => ['pseudo LIKE' => $query . '%']]); $users = []; - foreach ($result as $key => $value) { + foreach ($result as $value) { $users[] = ['pseudo' => $value['User']['pseudo'], 'id' => $value['User']['id']]; } $response = (empty($result)) ? ['status' => false] : ['status' => true, 'data' => $users]; @@ -651,8 +650,7 @@ public function admin_get_users() 0 => ['label' => 'success', 'name' => $this->Lang->get('USER__RANK_MEMBER')], 2 => ['label' => 'warning', 'name' => $this->Lang->get('USER__RANK_MODERATOR')], 3 => ['label' => 'danger', 'name' => $this->Lang->get('USER__RANK_ADMINISTRATOR')], - 4 => ['label' => 'danger', 'name' => $this->Lang->get('USER__RANK_ADMINISTRATOR')], - 5 => ['label' => 'primary', 'name' => $this->Lang->get('USER__RANK_BANNED')] + 4 => ['label' => 'danger', 'name' => $this->Lang->get('USER__RANK_ADMINISTRATOR')] ]; $this->loadModel('Rank'); $custom_ranks = $this->Rank->find('all'); @@ -721,8 +719,7 @@ function admin_edit($search = false) 0 => $this->Lang->get('USER__RANK_MEMBER'), 2 => $this->Lang->get('USER__RANK_MODERATOR'), 3 => $this->Lang->get('USER__RANK_ADMINISTRATOR'), - 4 => $this->Lang->get('USER__RANK_SUPER_ADMINISTRATOR'), - 5 => $this->Lang->get('USER__RANK_BANNED') + 4 => $this->Lang->get('USER__RANK_SUPER_ADMINISTRATOR') ]; $this->loadModel('Rank'); $custom_ranks = $this->Rank->find('all'); diff --git a/app/Model/Ban.php b/app/Model/Ban.php new file mode 100644 index 00000000..d7b37bf6 --- /dev/null +++ b/app/Model/Ban.php @@ -0,0 +1,5 @@ +find('first', ["conditions" => ['user_id' => $this->getKey("id")]]); + $this->isBanned = $check ? $check["Ban"]["reason"] : false; + + return $this->isBanned; + + } + private function getDataBySession() { if (empty($this->userData)) diff --git a/app/View/Ban/admin_add.ctp b/app/View/Ban/admin_add.ctp new file mode 100644 index 00000000..ab43a4c5 --- /dev/null +++ b/app/View/Ban/admin_add.ctp @@ -0,0 +1,62 @@ +
+
+
+
+
+

get('BAN__HOME') ?>

+
+
+
+ + + + + + + + +
get('BAN__QUESTION') ?>get('USER__TITLE') ?>get('USER__RANK') ?>
+ +
+
+ + +
+
+ +
+ get('GLOBAL__CANCEL') ?> + +
+
+
+
+
+
+
+ diff --git a/app/View/Ban/admin_index.ctp b/app/View/Ban/admin_index.ctp new file mode 100644 index 00000000..3dc93ebf --- /dev/null +++ b/app/View/Ban/admin_index.ctp @@ -0,0 +1,45 @@ +
+
+
+
+
+

get("BAN__HOME") ?>

+
+
+ + + + + + + + + + + + + + + + + + + + +
get("USER__USERNAME") ?>get("BAN__REASON") ?>get("GLOBAL__ACTIONS")?>
+ ')" + class="btn btn-danger">get('BAN__UNBAN') ?> +
+
+ + +
+
+
+
\ No newline at end of file diff --git a/app/View/Ban/index.ctp b/app/View/Ban/index.ctp new file mode 100644 index 00000000..e4b71a55 --- /dev/null +++ b/app/View/Ban/index.ctp @@ -0,0 +1,10 @@ +


+
+
+
+
+ get("BAN__EXPLICATION") . $reason ?> +
+
+
+
diff --git a/lang/en_UK.json b/lang/en_UK.json index 29c0ec36..b9120da4 100755 --- a/lang/en_UK.json +++ b/lang/en_UK.json @@ -524,6 +524,7 @@ "PERMISSIONS__VIEW_STATISTICS": "See the statistics on the admin panel", "PERMISSIONS__MANAGE_THEMES": "Manage themes of the site (enable, disable, deletion, installation, customisation)", "PERMISSIONS__MANAGE_USERS": "Manage users (delete, edit, see list)", + "PERMISSIONS__MANAGE_BANS":"Manage banned users", "PERMISSIONS__SEND_SERVER_COMMAND_FROM_DASHBOARD": "Send commands to the servers from the admin dashboard", "PERMISSIONS__VIEW_WEBSITE_HISTORY": "View site history", @@ -659,6 +660,18 @@ "API__USE_SKIN_RESTORER": "Use SkinRestorer?", "API__SKIN_RESTORER_SERVER": "SkinRestorer Server", "API__SKIN_RESTORER_SERVER_DESC": "If you are using SkinRestorer you must choose a server where the skin will be put (the server must be linked with the link plugin)", - "API__SKIN_RESTORER_NOT_CONNECTED": "You must be logged in in-game!" + "API__SKIN_RESTORER_NOT_CONNECTED": "You must be logged in in-game!", + + "BAN__MEMBERS": "Banned Members", + "BAN__HOME": "Bans", + "BAN__QUESTION": "Ban?", + "BAN__REASON": "Reason for ban", + "BAN__ADD": "Ban one or more members", + "BAN__SUCCESS": "Banned member(s)", + "BAN__UNBAN": "Revoke the ban", + "BAN__EDIT_REASON": "Change the reason", + "BAN__UNBAN_SUCCESS": "Ban revoked", + "BAN__BAN": "Banned", + "BAN__EXPLICATION": "You have been banned for " } } diff --git a/lang/en_US.json b/lang/en_US.json index 39c52b41..92efa58d 100755 --- a/lang/en_US.json +++ b/lang/en_US.json @@ -528,6 +528,7 @@ "PERMISSIONS__VIEW_STATISTICS": "See the statistics on the admin panel", "PERMISSIONS__MANAGE_THEMES": "Manage themes of the site (activation, deactivation, deletion, installation, customization)", "PERMISSIONS__MANAGE_USERS": "Manage users (delete, edit, see list)", + "PERMISSIONS__MANAGE_BANS":"Manage banned users", "PERMISSIONS__SEND_SERVER_COMMAND_FROM_DASHBOARD": "Send commands to the servers from the admin dashboard", "PERMISSIONS__VIEW_WEBSITE_HISTORY": "View site history", @@ -664,6 +665,18 @@ "API__USE_SKIN_RESTORER": "Use SkinRestorer?", "API__SKIN_RESTORER_SERVER": "SkinRestorer Server", "API__SKIN_RESTORER_SERVER_DESC": "If you are using SkinRestorer you must choose a server where the skin will be put (the server must be linked with the link plugin)", - "API__SKIN_RESTORER_NOT_CONNECTED": "You must be logged in in-game!" + "API__SKIN_RESTORER_NOT_CONNECTED": "You must be logged in in-game!", + + "BAN__MEMBERS": "Banned Members", + "BAN__HOME": "Bans", + "BAN__QUESTION": "Ban?", + "BAN__REASON": "Reason for ban", + "BAN__ADD": "Ban one or more members", + "BAN__SUCCESS": "Banned member(s)", + "BAN__UNBAN": "Revoke the ban", + "BAN__EDIT_REASON": "Change the reason", + "BAN__UNBAN_SUCCESS": "Ban revoked", + "BAN__BAN": "Banned", + "BAN__EXPLICATION": "You have been banned for " } } diff --git a/lang/fr_FR.json b/lang/fr_FR.json index 8fcfed85..4a611e1c 100755 --- a/lang/fr_FR.json +++ b/lang/fr_FR.json @@ -526,6 +526,7 @@ "PERMISSIONS__VIEW_STATISTICS": "Voir les statistiques sur le panel admin", "PERMISSIONS__MANAGE_THEMES":"Gérer les thèmes du site (activation, désactivation, suppression, installation, customisation)", "PERMISSIONS__MANAGE_USERS":"Gérer les utilisateurs (suppression, édition, voir la liste)", + "PERMISSIONS__MANAGE_BANS":"Gérer les utilisateurs bannis", "PERMISSIONS__SEND_SERVER_COMMAND_FROM_DASHBOARD":"Envoyer des commandes aux serveurs depuis le dashboard admin.", "PERMISSIONS__VIEW_WEBSITE_HISTORY": "Voir l'historique du site", @@ -665,6 +666,18 @@ "API__USE_SKIN_RESTORER": "Utiliser SkinRestorer ?", "API__SKIN_RESTORER_SERVER": "Serveur SkinRestorer", "API__SKIN_RESTORER_SERVER_DESC": "Si vous utilisez SkinRestorer vous devez choisir un serveur où le skin sera mis (le serveur doit être lié avec le plugin de liaison)", - "API__SKIN_RESTORER_NOT_CONNECTED": "Vous devez être connecté en jeu !" + "API__SKIN_RESTORER_NOT_CONNECTED": "Vous devez être connecté en jeu !", + + "BAN__MEMBERS": "Membres Bannis", + "BAN__HOME": "Bannissements", + "BAN__QUESTION": "Bannir ?", + "BAN__REASON": "Raison du bannissement", + "BAN__ADD": "Bannir un ou des membres", + "BAN__SUCCESS": "Membre(s) banni(s)", + "BAN__UNBAN": "Révoquer le bannissement", + "BAN__EDIT_REASON": "Modifier la raison", + "BAN__UNBAN_SUCCESS": "Bannissement révoqué", + "BAN__BAN": "Bannis", + "BAN__EXPLICATION": "Vous avez été banni pour " } } diff --git a/lang/ru_RU.json b/lang/ru_RU.json index 5904a6f2..a1465188 100644 --- a/lang/ru_RU.json +++ b/lang/ru_RU.json @@ -528,6 +528,7 @@ "PERMISSIONS__VIEW_STATISTICS": "Посмотреть статистику на панели администратора", "PERMISSIONS__MANAGE_THEMES" : "Управление темами сайта (активация, деактивация, удаление, установка, настройка)" , "PERMISSIONS__MANAGE_USERS": "Управление пользователями (удаление, редактирование, просмотр списка)", + "PERMISSIONS__MANAGE_BANS":"Управление заблокированными пользователями", "PERMISSIONS__SEND_SERVER_COMMAND_FROM_DASHBOARD" : "Отправлять команды на серверы с панели администратора" , "PERMISSIONS__VIEW_WEBSITE_HISTORY": "Просмотр истории сайта", @@ -663,6 +664,18 @@ "API__USE_SKIN_RESTORER": "Использовать SkinRestorer?", "API__SKIN_RESTORER_SERVER": "Сервер SkinRestorer", "API__SKIN_RESTORER_SERVER_DESC": "Если вы используете SkinRestorer, вы должны выбрать сервер, на который будет помещен скин (сервер должен быть связан с плагином ссылки)", - "API__SKIN_RESTORER_NOT_CONNECTED": "Вы должны авторизоваться в игре!" + "API__SKIN_RESTORER_NOT_CONNECTED": "Вы должны авторизоваться в игре!", + + "BAN__MEMBERS": "Запрещенные участники", + "BAN__HOME": "Баны", + "BAN__QUESTION": "Запретить?", + "BAN__REASON": "Причина бана", + "BAN__ADD": "Забанить одного или нескольких участников", + "BAN__SUCCESS": "Забаненный участник(ы)", + "BAN__UNBAN": "Снять запрет", + "BAN__EDIT_REASON": "Измените причину", + "BAN__UNBAN_SUCCESS": "Бан отменен", + "BAN__BAN": "Запрещено", + "BAN__EXPLICATION": "Вас забанили за " } }